SpyVisionUpdate.h 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  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: SpyVisionUpdate.h /////////////////////////////////////////////////////////////////
  24. // Author: Graham Smallwood, September 2002
  25. // Desc: Special Power will spy on the vision of all enemy players.
  26. // Putting a SpecialPower in a behavior takes a big huge amount of code duplication and
  27. // has no precedent.
  28. ///////////////////////////////////////////////////////////////////////////////////////////////////
  29. #pragma once
  30. #ifndef _SPY_VISION_UPDATE_H
  31. #define _SPY_VISION_UPDATE_H
  32. // INCLUDES ///////////////////////////////////////////////////////////////////////////////////////
  33. #include "GameLogic/Module/UpdateModule.h"
  34. #include "GameLogic/Module/UpgradeModule.h"
  35. class Player;
  36. //-------------------------------------------------------------------------------------------------
  37. class SpyVisionUpdateModuleData : public UpdateModuleData
  38. {
  39. public:
  40. UpgradeMuxData m_upgradeMuxData;
  41. Bool m_needsUpgrade;
  42. Bool m_selfPowered;
  43. UnsignedInt m_selfPoweredDuration;
  44. UnsignedInt m_selfPoweredInterval;
  45. KindOfMaskType m_spyOnKindof;
  46. SpyVisionUpdateModuleData()
  47. {
  48. m_needsUpgrade = FALSE;
  49. m_selfPowered = FALSE;
  50. m_selfPoweredDuration = 0;
  51. m_selfPoweredInterval = 0;
  52. m_spyOnKindof = KINDOFMASK_NONE;
  53. m_spyOnKindof.flip();
  54. }
  55. static void buildFieldParse(MultiIniFieldParse& p)
  56. {
  57. static const FieldParse dataFieldParse[] =
  58. {
  59. { "NeedsUpgrade", INI::parseBool, NULL, offsetof( SpyVisionUpdateModuleData, m_needsUpgrade ) },
  60. { "SelfPowered", INI::parseBool, NULL, offsetof( SpyVisionUpdateModuleData, m_selfPowered ) },
  61. { "SelfPoweredDuration", INI::parseDurationUnsignedInt, NULL, offsetof( SpyVisionUpdateModuleData, m_selfPoweredDuration ) },
  62. { "SelfPoweredInterval", INI::parseDurationUnsignedInt, NULL, offsetof( SpyVisionUpdateModuleData, m_selfPoweredInterval ) },
  63. { "SpyOnKindof", KindOfMaskType::parseFromINI, NULL, offsetof( SpyVisionUpdateModuleData, m_spyOnKindof ) },
  64. { 0, 0, 0, 0 }
  65. };
  66. UpdateModuleData::buildFieldParse(p);
  67. p.add(dataFieldParse);
  68. p.add(UpgradeMuxData::getFieldParse(), offsetof( SpyVisionUpdateModuleData, m_upgradeMuxData ));
  69. }
  70. };
  71. //-------------------------------------------------------------------------------------------------
  72. //-------------------------------------------------------------------------------------------------
  73. class SpyVisionUpdate : public UpdateModule, public UpgradeMux
  74. {
  75. MEMORY_POOL_GLUE_WITH_USERLOOKUP_CREATE( SpyVisionUpdate, "SpyVisionUpdate" )
  76. MAKE_STANDARD_MODULE_MACRO_WITH_MODULE_DATA( SpyVisionUpdate, SpyVisionUpdateModuleData )
  77. public:
  78. SpyVisionUpdate( Thing *thing, const ModuleData* moduleData );
  79. // virtual destructor prototype provided by memory pool declaration
  80. virtual SpyVisionUpdate* getSpyVisionUpdate() { return this; }
  81. // module methods
  82. static Int getInterfaceMask() { return UpdateModule::getInterfaceMask() | MODULEINTERFACE_UPGRADE; }
  83. virtual void onDelete( void );
  84. virtual void onCapture( Player *oldOwner, Player *newOwner );
  85. virtual void onDisabledEdge( Bool nowDisabled );
  86. // BehaviorModule
  87. virtual UpgradeModuleInterface* getUpgrade() { return this; }
  88. //Update module
  89. virtual UpdateSleepTime update( void );
  90. void activateSpyVision( UnsignedInt duration );
  91. void setDisabledUntilFrame( UnsignedInt frame );
  92. UnsignedInt getDisabledUntilFrame() const { return m_disabledUntilFrame; }
  93. protected:
  94. // UpgradeMux functions. Mux standing, of course, for Majorly Ugly Xhitcode
  95. virtual void upgradeImplementation();
  96. virtual void getUpgradeActivationMasks(UpgradeMaskType& activation, UpgradeMaskType& conflicting) const
  97. {
  98. getSpyVisionUpdateModuleData()->m_upgradeMuxData.getUpgradeActivationMasks(activation, conflicting);
  99. }
  100. virtual void performUpgradeFX()
  101. {
  102. getSpyVisionUpdateModuleData()->m_upgradeMuxData.performUpgradeFX(getObject());
  103. }
  104. virtual void processUpgradeRemoval()
  105. {
  106. // I can't take it any more. Let the record show that I think the UpgradeMux multiple inheritence is CRAP.
  107. getSpyVisionUpdateModuleData()->m_upgradeMuxData.muxDataProcessUpgradeRemoval(getObject());
  108. }
  109. virtual Bool requiresAllActivationUpgrades() const
  110. {
  111. return getSpyVisionUpdateModuleData()->m_upgradeMuxData.m_requiresAllTriggers;
  112. }
  113. inline Bool isUpgradeActive() const { return isAlreadyUpgraded(); }
  114. virtual Bool isSubObjectsUpgrade() { return false; }
  115. private:
  116. void doActivationWork( Player *playerToSetFor, Bool setting );
  117. UnsignedInt m_deactivateFrame;
  118. UnsignedInt m_disabledUntilFrame; //sabotaged, emp'd, etc.
  119. Bool m_currentlyActive;
  120. Bool m_resetTimersNextUpdate;
  121. };
  122. #endif