tool.h 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. /*
  2. Minetest
  3. Copyright (C) 2010-2013 celeron55, Perttu Ahola <celeron55@gmail.com>
  4. This program is free software; you can redistribute it and/or modify
  5. it under the terms of the GNU Lesser General Public License as published by
  6. the Free Software Foundation; either version 2.1 of the License, or
  7. (at your option) any later version.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU Lesser General Public License for more details.
  12. You should have received a copy of the GNU Lesser General Public License along
  13. with this program; if not, write to the Free Software Foundation, Inc.,
  14. 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  15. */
  16. #ifndef TOOL_HEADER
  17. #define TOOL_HEADER
  18. #include "irrlichttypes.h"
  19. #include <string>
  20. #include <iostream>
  21. #include <map>
  22. #include "itemgroup.h"
  23. struct ToolGroupCap
  24. {
  25. std::map<int, float> times;
  26. int maxlevel;
  27. int uses;
  28. ToolGroupCap():
  29. maxlevel(1),
  30. uses(20)
  31. {}
  32. bool getTime(int rating, float *time) const
  33. {
  34. std::map<int, float>::const_iterator i = times.find(rating);
  35. if(i == times.end()){
  36. *time = 0;
  37. return false;
  38. }
  39. *time = i->second;
  40. return true;
  41. }
  42. };
  43. // CLANG SUCKS DONKEY BALLS
  44. typedef std::map<std::string, struct ToolGroupCap> ToolGCMap;
  45. typedef std::map<std::string, s16> DamageGroup;
  46. struct ToolCapabilities
  47. {
  48. float full_punch_interval;
  49. int max_drop_level;
  50. // CLANG SUCKS DONKEY BALLS
  51. ToolGCMap groupcaps;
  52. DamageGroup damageGroups;
  53. ToolCapabilities(
  54. float full_punch_interval_=1.4,
  55. int max_drop_level_=1,
  56. // CLANG SUCKS DONKEY BALLS
  57. ToolGCMap groupcaps_=ToolGCMap(),
  58. DamageGroup damageGroups_=DamageGroup()
  59. ):
  60. full_punch_interval(full_punch_interval_),
  61. max_drop_level(max_drop_level_),
  62. groupcaps(groupcaps_),
  63. damageGroups(damageGroups_)
  64. {}
  65. void serialize(std::ostream &os, u16 version) const;
  66. void deSerialize(std::istream &is);
  67. };
  68. struct DigParams
  69. {
  70. bool diggable;
  71. // Digging time in seconds
  72. float time;
  73. // Caused wear
  74. u16 wear;
  75. std::string main_group;
  76. DigParams(bool a_diggable=false, float a_time=0, u16 a_wear=0,
  77. std::string a_main_group=""):
  78. diggable(a_diggable),
  79. time(a_time),
  80. wear(a_wear),
  81. main_group(a_main_group)
  82. {}
  83. };
  84. DigParams getDigParams(const ItemGroupList &groups,
  85. const ToolCapabilities *tp, float time_from_last_punch);
  86. DigParams getDigParams(const ItemGroupList &groups,
  87. const ToolCapabilities *tp);
  88. struct HitParams
  89. {
  90. s16 hp;
  91. s16 wear;
  92. HitParams(s16 hp_=0, s16 wear_=0):
  93. hp(hp_),
  94. wear(wear_)
  95. {}
  96. };
  97. HitParams getHitParams(const ItemGroupList &armor_groups,
  98. const ToolCapabilities *tp, float time_from_last_punch);
  99. HitParams getHitParams(const ItemGroupList &armor_groups,
  100. const ToolCapabilities *tp);
  101. struct PunchDamageResult
  102. {
  103. bool did_punch;
  104. int damage;
  105. int wear;
  106. PunchDamageResult():
  107. did_punch(false),
  108. damage(0),
  109. wear(0)
  110. {}
  111. };
  112. struct ItemStack;
  113. PunchDamageResult getPunchDamage(
  114. const ItemGroupList &armor_groups,
  115. const ToolCapabilities *toolcap,
  116. const ItemStack *punchitem,
  117. float time_from_last_punch
  118. );
  119. #endif