Handicap.cpp 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  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.cpp /////////////////////////////////////////////////////////
  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.cpp
  36. //
  37. // Created: Steven Johnson, October 2001
  38. //
  39. // Desc: @todo
  40. //
  41. //-----------------------------------------------------------------------------
  42. #include "PreRTS.h" // This must go first in EVERY cpp file int the GameEngine
  43. #include "Common/Handicap.h"
  44. #include "Common/Player.h"
  45. #include "Common/Dict.h"
  46. #include "Common/ThingTemplate.h"
  47. //-----------------------------------------------------------------------------
  48. Handicap::Handicap()
  49. {
  50. init();
  51. }
  52. //-----------------------------------------------------------------------------
  53. void Handicap::init()
  54. {
  55. for (Int i = 0; i < HANDICAP_TYPE_COUNT; ++i)
  56. for (Int j = 0; j < THING_TYPE_COUNT; ++j)
  57. m_handicaps[i][j] = 1.0f;
  58. }
  59. //-----------------------------------------------------------------------------
  60. void Handicap::readFromDict(const Dict* d)
  61. {
  62. // this isn't very efficient, but is only called at load times,
  63. // so it probably doesn't really matter.
  64. const char* htNames[HANDICAP_TYPE_COUNT] =
  65. {
  66. "BUILDCOST",
  67. "BUILDTIME",
  68. // "FIREPOWER",
  69. // "ARMOR",
  70. // "GROUNDSPEED",
  71. // "AIRSPEED",
  72. // "INCOME"
  73. };
  74. const char* ttNames[THING_TYPE_COUNT] =
  75. {
  76. "GENERIC",
  77. "BUILDINGS",
  78. };
  79. // no, you should NOT call init() here.
  80. //init();
  81. AsciiString c;
  82. for (Int i = 0; i < HANDICAP_TYPE_COUNT; ++i)
  83. {
  84. for (Int j = 0; j < THING_TYPE_COUNT; ++j)
  85. {
  86. c.clear();
  87. c.set("HANDICAP_");
  88. c.concat(htNames[i]);
  89. c.concat("_");
  90. c.concat(ttNames[j]);
  91. NameKeyType k = TheNameKeyGenerator->nameToKey(c);
  92. Bool exists;
  93. Real r = d->getReal(k, &exists);
  94. if (exists)
  95. m_handicaps[i][j] = r;
  96. }
  97. }
  98. }
  99. //-----------------------------------------------------------------------------
  100. /*static*/ Handicap::ThingType Handicap::getBestThingType(const ThingTemplate *tmpl)
  101. {
  102. /// if this ends up being too slow, cache the information in the object
  103. if (tmpl->isKindOf(KINDOF_STRUCTURE))
  104. return BUILDINGS;
  105. return GENERIC;
  106. }
  107. //-----------------------------------------------------------------------------
  108. Real Handicap::getHandicap(HandicapType ht, const ThingTemplate *tmpl) const
  109. {
  110. ThingType tt = getBestThingType(tmpl);
  111. return m_handicaps[ht][tt];
  112. }