tool.h 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  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 3.0 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 "util/cpp11_container.h"
  22. #include "itemgroup.h"
  23. struct ToolGroupCap
  24. {
  25. UNORDERED_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. UNORDERED_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. typedef UNORDERED_MAP<std::string, struct ToolGroupCap> ToolGCMap;
  44. typedef UNORDERED_MAP<std::string, s16> DamageGroup;
  45. struct ToolCapabilities
  46. {
  47. float full_punch_interval;
  48. int max_drop_level;
  49. ToolGCMap groupcaps;
  50. DamageGroup damageGroups;
  51. ToolCapabilities(
  52. float full_punch_interval_=1.4,
  53. int max_drop_level_=1,
  54. const ToolGCMap &groupcaps_ = ToolGCMap(),
  55. const DamageGroup &damageGroups_ = DamageGroup()
  56. ):
  57. full_punch_interval(full_punch_interval_),
  58. max_drop_level(max_drop_level_),
  59. groupcaps(groupcaps_),
  60. damageGroups(damageGroups_)
  61. {}
  62. void serialize(std::ostream &os, u16 version) const;
  63. void deSerialize(std::istream &is);
  64. };
  65. struct DigParams
  66. {
  67. bool diggable;
  68. // Digging time in seconds
  69. float time;
  70. // Caused wear
  71. u16 wear;
  72. std::string main_group;
  73. DigParams(bool a_diggable = false, float a_time = 0.0f, u16 a_wear = 0,
  74. const std::string &a_main_group = ""):
  75. diggable(a_diggable),
  76. time(a_time),
  77. wear(a_wear),
  78. main_group(a_main_group)
  79. {}
  80. };
  81. DigParams getDigParams(const ItemGroupList &groups,
  82. const ToolCapabilities *tp, float time_from_last_punch);
  83. DigParams getDigParams(const ItemGroupList &groups,
  84. const ToolCapabilities *tp);
  85. struct HitParams
  86. {
  87. s16 hp;
  88. s16 wear;
  89. HitParams(s16 hp_=0, s16 wear_=0):
  90. hp(hp_),
  91. wear(wear_)
  92. {}
  93. };
  94. HitParams getHitParams(const ItemGroupList &armor_groups,
  95. const ToolCapabilities *tp, float time_from_last_punch);
  96. HitParams getHitParams(const ItemGroupList &armor_groups,
  97. const ToolCapabilities *tp);
  98. struct PunchDamageResult
  99. {
  100. bool did_punch;
  101. int damage;
  102. int wear;
  103. PunchDamageResult():
  104. did_punch(false),
  105. damage(0),
  106. wear(0)
  107. {}
  108. };
  109. struct ItemStack;
  110. PunchDamageResult getPunchDamage(
  111. const ItemGroupList &armor_groups,
  112. const ToolCapabilities *toolcap,
  113. const ItemStack *punchitem,
  114. float time_from_last_punch
  115. );
  116. #endif