HackInternetAIUpdate.h 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233
  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. // HackInternetAIUpdate.h ////////////
  24. // Author: Kris Morness, June 2002
  25. // Desc: State machine that allows hacking cash from the internet (free money).
  26. #pragma once
  27. #ifndef __HACK_INTERNET_AI_UPDATE_H
  28. #define __HACK_INTERNET_AI_UPDATE_H
  29. #include "Common/StateMachine.h"
  30. #include "GameLogic/Module/AIUpdate.h"
  31. //-------------------------------------------------------------------------------------------------
  32. class HackInternetStateMachine : public AIStateMachine
  33. {
  34. MEMORY_POOL_GLUE_WITH_USERLOOKUP_CREATE( HackInternetStateMachine, "HackInternetStateMachine" );
  35. public:
  36. HackInternetStateMachine( Object *owner, AsciiString name );
  37. };
  38. //-------------------------------------------------------------------------------------------------
  39. class HackInternetState : public State
  40. {
  41. MEMORY_POOL_GLUE_WITH_USERLOOKUP_CREATE(HackInternetState, "HackInternetState")
  42. public:
  43. HackInternetState( StateMachine *machine ) :State( machine, "HackInternetState" )
  44. {
  45. //Added By Sadullah Nader
  46. //Initializations missing and needed
  47. m_framesRemaining = 0;
  48. //
  49. }
  50. virtual StateReturnType update();
  51. virtual StateReturnType onEnter();
  52. virtual void onExit( StateExitType status );
  53. protected:
  54. // snapshot interface
  55. virtual void crc( Xfer *xfer );
  56. virtual void xfer( Xfer *xfer );
  57. virtual void loadPostProcess();
  58. private:
  59. UnsignedInt m_framesRemaining; //frames till next cash update
  60. };
  61. EMPTY_DTOR(HackInternetState)
  62. //-------------------------------------------------------------------------------------------------
  63. class PackingState : public State
  64. {
  65. MEMORY_POOL_GLUE_WITH_USERLOOKUP_CREATE(PackingState, "PackingState")
  66. public:
  67. PackingState( StateMachine *machine ) : State( machine, "PackingState" )
  68. {
  69. //Added By Sadullah Nader
  70. //Initializations inserted
  71. m_framesRemaining = 0;
  72. //
  73. }
  74. virtual StateReturnType update();
  75. virtual StateReturnType onEnter();
  76. virtual void onExit( StateExitType status );
  77. protected:
  78. // snapshot interface
  79. virtual void crc( Xfer *xfer );
  80. virtual void xfer( Xfer *xfer );
  81. virtual void loadPostProcess();
  82. private:
  83. UnsignedInt m_framesRemaining; //frames till packing animation complete
  84. };
  85. EMPTY_DTOR(PackingState)
  86. //-------------------------------------------------------------------------------------------------
  87. class UnpackingState : public State
  88. {
  89. MEMORY_POOL_GLUE_WITH_USERLOOKUP_CREATE(UnpackingState, "UnpackingState")
  90. public:
  91. UnpackingState( StateMachine *machine ) :State( machine, "UnpackingState" )
  92. {
  93. m_framesRemaining = 0;
  94. }
  95. virtual StateReturnType update();
  96. virtual StateReturnType onEnter();
  97. virtual void onExit( StateExitType status );
  98. protected:
  99. // snapshot interface
  100. virtual void crc( Xfer *xfer );
  101. virtual void xfer( Xfer *xfer );
  102. virtual void loadPostProcess();
  103. private:
  104. UnsignedInt m_framesRemaining; //frames till unpacking animation complete
  105. };
  106. EMPTY_DTOR(UnpackingState)
  107. //-------------------------------------------------------------------------------------------------
  108. enum
  109. {
  110. UNPACKING = 1000, ///< Kneel down and set up internet satellite link
  111. HACK_INTERNET, ///< Once set up, start hacking for cash.
  112. PACKING, ///< Pack up before moving.
  113. };
  114. //-------------------------------------------------------------------------------------------------
  115. class HackInternetAIUpdateModuleData : public AIUpdateModuleData
  116. {
  117. public:
  118. UnsignedInt m_unpackTime;
  119. UnsignedInt m_packTime;
  120. UnsignedInt m_cashUpdateDelay;
  121. UnsignedInt m_cashUpdateDelayFast;
  122. UnsignedInt m_regularCashAmount;
  123. UnsignedInt m_veteranCashAmount;
  124. UnsignedInt m_eliteCashAmount;
  125. UnsignedInt m_heroicCashAmount;
  126. UnsignedInt m_xpPerCashUpdate;
  127. Real m_packUnpackVariationFactor;
  128. HackInternetAIUpdateModuleData()
  129. {
  130. m_unpackTime = 0;
  131. m_packTime = 0;
  132. m_cashUpdateDelay = 0;
  133. m_cashUpdateDelayFast = 0;
  134. m_regularCashAmount = 0;
  135. m_veteranCashAmount = 0;
  136. m_eliteCashAmount = 0;
  137. m_heroicCashAmount = 0;
  138. m_xpPerCashUpdate = 0;
  139. m_packUnpackVariationFactor = 0.0f;
  140. }
  141. static void buildFieldParse(MultiIniFieldParse& p)
  142. {
  143. AIUpdateModuleData::buildFieldParse(p);
  144. static const FieldParse dataFieldParse[] =
  145. {
  146. { "UnpackTime", INI::parseDurationUnsignedInt, NULL, offsetof( HackInternetAIUpdateModuleData, m_unpackTime ) },
  147. { "PackTime", INI::parseDurationUnsignedInt, NULL, offsetof( HackInternetAIUpdateModuleData, m_packTime ) },
  148. { "PackUnpackVariationFactor", INI::parseReal, NULL, offsetof( HackInternetAIUpdateModuleData, m_packUnpackVariationFactor ) },
  149. { "CashUpdateDelay", INI::parseDurationUnsignedInt, NULL, offsetof( HackInternetAIUpdateModuleData, m_cashUpdateDelay ) },
  150. { "CashUpdateDelayFast",INI::parseDurationUnsignedInt, NULL, offsetof( HackInternetAIUpdateModuleData, m_cashUpdateDelayFast ) },
  151. { "RegularCashAmount", INI::parseUnsignedInt, NULL, offsetof( HackInternetAIUpdateModuleData, m_regularCashAmount ) },
  152. { "VeteranCashAmount", INI::parseUnsignedInt, NULL, offsetof( HackInternetAIUpdateModuleData, m_veteranCashAmount ) },
  153. { "EliteCashAmount", INI::parseUnsignedInt, NULL, offsetof( HackInternetAIUpdateModuleData, m_eliteCashAmount ) },
  154. { "HeroicCashAmount", INI::parseUnsignedInt, NULL, offsetof( HackInternetAIUpdateModuleData, m_heroicCashAmount ) },
  155. { "XpPerCashUpdate", INI::parseUnsignedInt, NULL, offsetof( HackInternetAIUpdateModuleData, m_xpPerCashUpdate ) },
  156. { 0, 0, 0, 0 }
  157. };
  158. p.add(dataFieldParse);
  159. }
  160. };
  161. class HackInternetAIInterface
  162. {
  163. public:
  164. virtual Bool isHacking() const = 0;
  165. virtual Bool isHackingPackingOrUnpacking() const = 0;
  166. };
  167. //-------------------------------------------------------------------------------------------------
  168. class HackInternetAIUpdate : public AIUpdateInterface, public HackInternetAIInterface
  169. {
  170. MEMORY_POOL_GLUE_WITH_USERLOOKUP_CREATE( HackInternetAIUpdate, "HackInternetAIUpdate" )
  171. MAKE_STANDARD_MODULE_MACRO_WITH_MODULE_DATA( HackInternetAIUpdate, HackInternetAIUpdateModuleData )
  172. private:
  173. public:
  174. HackInternetAIUpdate( Thing *thing, const ModuleData* moduleData );
  175. // virtual destructor prototype provided by memory pool declaration
  176. virtual void aiDoCommand(const AICommandParms* parms);
  177. Real getPackUnpackVariationFactor() const { return getHackInternetAIUpdateModuleData()->m_packUnpackVariationFactor; }
  178. UnsignedInt getUnpackTime() const;
  179. UnsignedInt getPackTime() const;
  180. UnsignedInt getCashUpdateDelay() const;
  181. UnsignedInt getRegularCashAmount() const { return getHackInternetAIUpdateModuleData()->m_regularCashAmount; }
  182. UnsignedInt getVeteranCashAmount() const { return getHackInternetAIUpdateModuleData()->m_veteranCashAmount; }
  183. UnsignedInt getEliteCashAmount() const { return getHackInternetAIUpdateModuleData()->m_eliteCashAmount; }
  184. UnsignedInt getHeroicCashAmount() const { return getHackInternetAIUpdateModuleData()->m_heroicCashAmount; }
  185. UnsignedInt getXpPerCashUpdate() const { return getHackInternetAIUpdateModuleData()->m_xpPerCashUpdate; }
  186. void hackInternet();
  187. virtual UpdateSleepTime update();
  188. virtual Bool isIdle() const;
  189. virtual HackInternetAIInterface* getHackInternetAIInterface() { return this; }
  190. virtual const HackInternetAIInterface* getHackInternetAIInterface() const { return this; }
  191. virtual Bool isHacking() const;
  192. virtual Bool isHackingPackingOrUnpacking() const;
  193. protected:
  194. virtual AIStateMachine* makeStateMachine();
  195. AICommandParmsStorage m_pendingCommand;
  196. Bool m_hasPendingCommand;
  197. };
  198. #endif