Armor.h 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. /*
  2. ** Command & Conquer Generals Zero Hour(tm)
  3. ** Copyright 2025 Electronic Arts Inc.
  4. **
  5. ** This program is free software: you can redistribute it and/or modify
  6. ** it under the terms of the GNU General Public License as published by
  7. ** the Free Software Foundation, either version 3 of the License, or
  8. ** (at your option) any later version.
  9. **
  10. ** This program is distributed in the hope that it will be useful,
  11. ** but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. ** GNU General Public License for more details.
  14. **
  15. ** You should have received a copy of the GNU General Public License
  16. ** along with this program. If not, see <http://www.gnu.org/licenses/>.
  17. */
  18. ////////////////////////////////////////////////////////////////////////////////
  19. // //
  20. // (c) 2001-2003 Electronic Arts Inc. //
  21. // //
  22. ////////////////////////////////////////////////////////////////////////////////
  23. // FILE: Armor.h /////////////////////////////////////////////////////////////////////////////////
  24. // Author: Steven Johnson, March 2002
  25. // Desc: Damage Multiplier Descriptions
  26. ///////////////////////////////////////////////////////////////////////////////////////////////////
  27. #pragma once
  28. #ifndef _Armor_H_
  29. #define _Armor_H_
  30. // INCLUDES ///////////////////////////////////////////////////////////////////////////////////////
  31. #include "Common/NameKeyGenerator.h"
  32. #include "Common/STLTypedefs.h"
  33. #include "GameLogic/Damage.h"
  34. // FORWARD REFERENCES /////////////////////////////////////////////////////////////////////////////
  35. class ArmorStore;
  36. //-------------------------------------------------------------------------------------------------
  37. /**
  38. An Armor encapsulates the a particular type of actual modifier to damage taken, in order
  39. to simulate different materials, and to help make game balance easier to adjust.
  40. */
  41. //-------------------------------------------------------------------------------------------------
  42. class ArmorTemplate
  43. {
  44. public:
  45. ArmorTemplate();
  46. void clear();
  47. /**
  48. This is the real "meat" of the class: given a damage type and amount, adjust the damage
  49. and return the amount that should be dealt.
  50. */
  51. Real adjustDamage(DamageType t, Real damage) const;
  52. static void parseArmorCoefficients( INI* ini, void *instance, void* /* store */, const void* userData );
  53. protected:
  54. private:
  55. Real m_damageCoefficient[DAMAGE_NUM_TYPES]; ///< modifiers to damage
  56. };
  57. //-------------------------------------------------------------------------------------------------
  58. class Armor
  59. {
  60. public:
  61. inline Armor(const ArmorTemplate* tmpl = NULL) : m_template(tmpl)
  62. {
  63. }
  64. inline Real adjustDamage(DamageType t, Real damage) const
  65. {
  66. return m_template ? m_template->adjustDamage(t, damage) : damage;
  67. }
  68. inline void clear()
  69. {
  70. m_template = NULL;
  71. }
  72. private:
  73. const ArmorTemplate* m_template; ///< the kind of armor this is
  74. };
  75. //------------------------------------------------------------------------------------------------
  76. /** Interface class for TheArmorStore, which is just a convenient place for us to
  77. * store each Armor we read from INI together in a list, with some access
  78. * methods for finding Armors */
  79. //-------------------------------------------------------------------------------------------------
  80. class ArmorStore : public SubsystemInterface
  81. {
  82. public:
  83. ArmorStore();
  84. ~ArmorStore();
  85. void init() { }
  86. void reset() { }
  87. void update() { }
  88. /**
  89. Find the Armor with the given name. If no such Armor exists, return null.
  90. */
  91. const ArmorTemplate* findArmorTemplate(AsciiString name) const;
  92. inline Armor makeArmor(const ArmorTemplate *tmpl) const
  93. {
  94. return Armor(tmpl); // my, that was easy
  95. }
  96. static void parseArmorDefinition(INI* ini);
  97. private:
  98. typedef std::hash_map< NameKeyType, ArmorTemplate, rts::hash<NameKeyType>, rts::equal_to<NameKeyType> > ArmorTemplateMap;
  99. ArmorTemplateMap m_armorTemplates;
  100. };
  101. // EXTERNALS //////////////////////////////////////////////////////////////////////////////////////
  102. extern ArmorStore *TheArmorStore;
  103. #endif // _Armor_H_