SalvageCrateCollide.h 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  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: SalvageCrateCollide.h /////////////////////////////////////////////////////////////////////////
  24. // Author: Graham Smallwood, March 2002
  25. // Desc: The Savlage system can give a Weaponset bonus, a level, or money. Salvagers create them
  26. // by killing marked units, and only WeaponSalvagers can get the WeaponSet bonus
  27. ///////////////////////////////////////////////////////////////////////////////////////////////////
  28. #pragma once
  29. #ifndef SALVAGE_CRATE_COLLIDE_H_
  30. #define SALVAGE_CRATE_COLLIDE_H_
  31. // INCLUDES ///////////////////////////////////////////////////////////////////////////////////////
  32. #include "Common/Module.h"
  33. #include "Common/STLTypedefs.h"
  34. #include "GameLogic/Module/CrateCollide.h"
  35. // FORWARD REFERENCES /////////////////////////////////////////////////////////////////////////////
  36. class Thing;
  37. //-------------------------------------------------------------------------------------------------
  38. class SalvageCrateCollideModuleData : public CrateCollideModuleData
  39. {
  40. public:
  41. Real m_weaponChance; ///< Chance to get a weapon upgrade, if possible
  42. Real m_levelChance; ///< Chance to get a level, if weaponChance fails
  43. Real m_moneyChance; ///< Chance to get money, if weaponChance fails
  44. Int m_minimumMoney; ///< How much, if we get money
  45. Int m_maximumMoney; ///< How much, if we get money
  46. SalvageCrateCollideModuleData()
  47. {
  48. m_weaponChance = 1.0f;
  49. m_levelChance = .25f;
  50. m_moneyChance = .75f;
  51. m_minimumMoney = 25;
  52. m_maximumMoney = 75;
  53. }
  54. static void buildFieldParse(MultiIniFieldParse& p)
  55. {
  56. CrateCollideModuleData::buildFieldParse(p);
  57. static const FieldParse dataFieldParse[] =
  58. {
  59. { "WeaponChance", INI::parsePercentToReal, NULL, offsetof( SalvageCrateCollideModuleData, m_weaponChance ) },
  60. { "LevelChance", INI::parsePercentToReal, NULL, offsetof( SalvageCrateCollideModuleData, m_levelChance ) },
  61. { "MoneyChance", INI::parsePercentToReal, NULL, offsetof( SalvageCrateCollideModuleData, m_moneyChance ) },
  62. { "MinMoney", INI::parseInt, NULL, offsetof( SalvageCrateCollideModuleData, m_minimumMoney ) },
  63. { "MaxMoney", INI::parseInt, NULL, offsetof( SalvageCrateCollideModuleData, m_maximumMoney ) },
  64. { 0, 0, 0, 0 }
  65. };
  66. p.add(dataFieldParse);
  67. }
  68. };
  69. //-------------------------------------------------------------------------------------------------
  70. class SalvageCrateCollide : public CrateCollide
  71. {
  72. MEMORY_POOL_GLUE_WITH_USERLOOKUP_CREATE( SalvageCrateCollide, "SalvageCrateCollide" )
  73. MAKE_STANDARD_MODULE_MACRO_WITH_MODULE_DATA( SalvageCrateCollide, SalvageCrateCollideModuleData );
  74. public:
  75. SalvageCrateCollide( Thing *thing, const ModuleData* moduleData );
  76. // virtual destructor prototype provided by memory pool declaration
  77. virtual Bool isSalvageCrateCollide() const { return true; }
  78. protected:
  79. /// This allows specific vetoes to certain types of crates and their data
  80. virtual Bool isValidToExecute( const Object *other ) const;
  81. /// This is the game logic execution function that all real CrateCollides will implement
  82. virtual Bool executeCrateBehavior( Object *other );
  83. private:
  84. Bool eligibleForWeaponSet( Object *other );
  85. Bool eligibleForArmorSet( Object *other );
  86. Bool eligibleForLevel( Object *other );
  87. Bool testWeaponChance();
  88. Bool testLevelChance();
  89. void doWeaponSet( Object *other );
  90. void doArmorSet( Object *other );
  91. void doLevelGain( Object *other );
  92. void doMoney( Object *other );
  93. };
  94. #endif