CaveContain.h 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  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: CaveContain.h ////////////////////////////////////////////////////////////////////////////
  24. // Author: Graham Smallwood, July 2002
  25. // Desc: A version of OpenContain that overrides where the passengers are stored: one of CaveManager's
  26. // entries. Changing entry is a script or ini command. All queries about capacity and
  27. // contents are also redirected.
  28. ///////////////////////////////////////////////////////////////////////////////////////////////////
  29. #pragma once
  30. #ifndef __CAVE_CONTAIN_H_
  31. #define __CAVE_CONTAIN_H_
  32. // INCLUDES ///////////////////////////////////////////////////////////////////////////////////////
  33. #include "GameLogic/Module/CreateModule.h"
  34. #include "GameLogic/Module/OpenContain.h"
  35. struct Sound;
  36. class Team;
  37. //-------------------------------------------------------------------------------------------------
  38. class CaveContainModuleData : public OpenContainModuleData
  39. {
  40. public:
  41. Int m_caveIndexData;
  42. CaveContainModuleData()
  43. {
  44. m_caveIndexData = 0;// By default, all Caves will be grouped together as number 0
  45. }
  46. static void buildFieldParse(MultiIniFieldParse& p)
  47. {
  48. OpenContainModuleData::buildFieldParse(p);
  49. static const FieldParse dataFieldParse[] =
  50. {
  51. { "CaveIndex", INI::parseInt, NULL, offsetof( CaveContainModuleData, m_caveIndexData ) },
  52. { 0, 0, 0, 0 }
  53. };
  54. p.add(dataFieldParse);
  55. }
  56. };
  57. //-------------------------------------------------------------------------------------------------
  58. class CaveContain : public OpenContain, public CreateModuleInterface, public CaveInterface
  59. {
  60. MEMORY_POOL_GLUE_WITH_USERLOOKUP_CREATE( CaveContain, "CaveContain" )
  61. MAKE_STANDARD_MODULE_MACRO_WITH_MODULE_DATA( CaveContain, CaveContainModuleData )
  62. public:
  63. CaveContain( Thing *thing, const ModuleData* moduleData );
  64. // virtual destructor prototype provided by memory pool declaration
  65. virtual CreateModuleInterface* getCreate() { return this; }
  66. virtual CaveInterface* getCaveInterface() { return this; }
  67. static Int getInterfaceMask() { return OpenContain::getInterfaceMask() | (MODULEINTERFACE_CREATE); }
  68. virtual OpenContain *asOpenContain() { return this; } ///< treat as open container
  69. virtual Bool isGarrisonable() const { return false; } ///< can this unit be Garrisoned? (ick)
  70. virtual Bool isBustable() const { return TRUE; } ///< can this container get busted by a bunkerbuster
  71. virtual Bool isHealContain() const { return false; } ///< true when container only contains units while healing (not a transport!)
  72. virtual void onContaining( Object *obj, Bool wasSelected ); ///< object now contains 'obj'
  73. virtual void onRemoving( Object *obj ); ///< object no longer contains 'obj'
  74. virtual Bool isValidContainerFor(const Object* obj, Bool checkCapacity) const;
  75. virtual void addToContainList( Object *obj ); ///< The part of AddToContain that inheritors can override (Can't do whole thing because of all the private stuff involved)
  76. virtual void removeFromContain( Object *obj, Bool exposeStealthUnits = FALSE ); ///< remove 'obj' from contain list
  77. virtual void removeAllContained( Bool exposeStealthUnits = FALSE ); ///< remove all objects on contain list
  78. /**
  79. return the player that *appears* to control this unit. if null, use getObject()->getControllingPlayer() instead.
  80. */
  81. virtual void recalcApparentControllingPlayer( void );
  82. // contain list access
  83. virtual void iterateContained( ContainIterateFunc func, void *userData, Bool reverse );
  84. virtual UnsignedInt getContainCount() const;
  85. virtual Int getContainMax( void ) const;
  86. virtual const ContainedItemsList* getContainedItemsList() const;
  87. virtual Bool isKickOutOnCapture(){ return FALSE; }///< Caves and Tunnels don't kick out on capture.
  88. // override the onDie we inherit from OpenContain
  89. virtual void onDie( const DamageInfo *damageInfo ); ///< the die callback
  90. virtual void onCreate( void );
  91. virtual void onBuildComplete(); ///< This is called when you are a finished game object
  92. virtual Bool shouldDoOnBuildComplete() const { return m_needToRunOnBuildComplete; }
  93. // Unique to Cave Contain
  94. virtual void tryToSetCaveIndex( Int newIndex ); ///< Called by script as an alternative to instancing separate objects. 'Try', because can fail.
  95. virtual void setOriginalTeam( Team *oldTeam ); ///< This is a distributed Garrison in terms of capturing, so when one node triggers the change, he needs to tell everyone, so anyone can do the un-change.
  96. protected:
  97. void changeTeamOnAllConnectedCaves( Team *newTeam, Bool setOriginalTeams ); ///< When one gets captured, all connected ones get captured. DistributedGarrison.
  98. Bool m_needToRunOnBuildComplete;
  99. Int m_caveIndex;
  100. Team *m_originalTeam; ///< our original team before we were garrisoned
  101. };
  102. #endif // end __CAVE_CONTAIN_H_