Handicap.h 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  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: Handicap.h ////////////////////////////////////////////////////////////
  24. //-----------------------------------------------------------------------------
  25. //
  26. // Westwood Studios Pacific.
  27. //
  28. // Confidential Information
  29. // Copyright (C) 2001 - All Rights Reserved
  30. //
  31. //-----------------------------------------------------------------------------
  32. //
  33. // Project: RTS3
  34. //
  35. // File name: Handicap.h
  36. //
  37. // Created: Steven Johnson, October 2001
  38. //
  39. // Desc: @todo
  40. //
  41. //-----------------------------------------------------------------------------
  42. #pragma once
  43. #ifndef _HANDICAP_H_
  44. #define _HANDICAP_H_
  45. #include "Lib/BaseType.h"
  46. // ----------------------------------------------------------------------------------------------
  47. class Object;
  48. class Dict;
  49. class ThingTemplate;
  50. // ----------------------------------------------------------------------------------------------
  51. /**
  52. Handicap encapsulates the sets of modifiers to abilities used to balance
  53. the game and give different abilities to different Players.
  54. Conceptually, it's a large set of coefficients (typically, but not necessarily,
  55. in the range of 0.0...1.0).
  56. Usage example (conceptual):
  57. Real armorCoef = this->m_handicap->getHandicap(ARMOR, this);
  58. Real actualArmor = this->getArmorValue() * armorCoef;
  59. */
  60. class Handicap
  61. {
  62. public:
  63. // NOTE: if you ever add/remove/change the enums in HandicapType,
  64. // you must also modify initFromDict()!
  65. enum HandicapType
  66. {
  67. BUILDCOST,
  68. BUILDTIME,
  69. HANDICAP_TYPE_COUNT
  70. };
  71. Handicap();
  72. /// reset all handicaps to a default value.
  73. void init();
  74. /**
  75. initialize from the fields in the Dict. Note that this does NOT call init()
  76. internally, so only those fields that are present in the dict will be set.
  77. if you want to ensure all fields are something reasonable, you should call init()
  78. prior to calling this.
  79. */
  80. void readFromDict(const Dict* d);
  81. /**
  82. return the multiplier for the given Handicap type on the given Object.
  83. The Object's type (unit, building, etc.) will generally be examined
  84. to determine what value to return.
  85. */
  86. Real getHandicap(HandicapType t, const ThingTemplate *tmpl) const;
  87. protected:
  88. private:
  89. // NOTE: if you ever add/remove/change the enums in ThingType,
  90. // you must also modify initFromDict()!
  91. enum ThingType
  92. {
  93. GENERIC, // if a thing is nothing else, it's generic.
  94. BUILDINGS,
  95. THING_TYPE_COUNT
  96. };
  97. Real m_handicaps[HANDICAP_TYPE_COUNT][THING_TYPE_COUNT];
  98. static ThingType getBestThingType(const ThingTemplate *tmpl);
  99. };
  100. #endif // _HANDICAP_H_