ContainModule.h 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214
  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: ContainModule.h /////////////////////////////////////////////////////////////////////////////////
  24. // Author: Colin Day, September 2001
  25. // Desc:
  26. ///////////////////////////////////////////////////////////////////////////////////////////////////
  27. #pragma once
  28. #ifndef __ContainModule_H_
  29. #define __ContainModule_H_
  30. #include "Common/Module.h"
  31. #include "GameLogic/WeaponBonusConditionFlags.h" // Can't forward a typedef. This should me made a BitFlags class.
  32. #include "GameLogic/Damage.h"
  33. //-------------------------------------------------------------------------------------------------
  34. class OpenContain;
  35. class Player;
  36. class ExitInterface;
  37. class Matrix3D;
  38. class Weapon;
  39. enum CommandSourceType;
  40. //-------------------------------------------------------------------------------------------------
  41. enum ObjectEnterExitType
  42. {
  43. WANTS_TO_ENTER,
  44. WANTS_TO_EXIT,
  45. WANTS_NEITHER
  46. };
  47. enum EvacDisposition
  48. {
  49. EVAC_INVALID = 0,
  50. EVAC_TO_LEFT,
  51. EVAC_TO_RIGHT,
  52. EVAC_BURST_FROM_CENTER,
  53. };
  54. //-------------------------------------------------------------------------------------------------
  55. typedef std::list<Object*> ContainedItemsList;
  56. //-------------------------------------------------------------------------------------------------
  57. typedef ModuleData ContainModuleData;
  58. //-------------------------------------------------------------------------------------------------
  59. typedef void (*ContainIterateFunc)( Object *obj, void *userData ); ///< callback type for contain iterate
  60. //-------------------------------------------------------------------------------------------------
  61. //-------------------------------------------------------------------------------------------------
  62. //-------------------------------------------------------------------------------------------------
  63. class ContainModuleInterface
  64. {
  65. public:
  66. // we have a two basic container types that it is convenient to query and use
  67. virtual OpenContain *asOpenContain() = 0;
  68. // our object changed position... react as appropriate.
  69. virtual void containReactToTransformChange() = 0;
  70. // containment is the basis for many complex systems, it helps us to have a formal
  71. // place where we can monitor the outside world if we need to
  72. //===============================================================================================
  73. // Containment ==================================================================================
  74. //===============================================================================================
  75. virtual Bool isGarrisonable() const = 0;
  76. virtual Bool isBustable() const = 0;
  77. virtual Bool isSpecialZeroSlotContainer() const = 0;
  78. virtual Bool isHealContain() const = 0;
  79. virtual Bool isTunnelContain() const = 0;
  80. virtual Bool isRiderChangeContain() const = 0;
  81. virtual Bool isImmuneToClearBuildingAttacks() const = 0;
  82. virtual Bool isSpecialOverlordStyleContainer() const = 0;
  83. virtual Bool isAnyRiderAttacking() const = 0;
  84. ///< if my object gets selected, then my visible passengers should, too
  85. ///< this gets called from
  86. virtual void clientVisibleContainedFlashAsSelected() = 0;
  87. /**
  88. this is used for containers that must do something to allow people to enter or exit...
  89. eg, land (for Chinook), open door (whatever)... it's called with wants=WANTS_TO_ENTER
  90. when something is in the enter state, and wants=ENTS_NOTHING when the unit has
  91. either entered, or given up...
  92. */
  93. virtual void onObjectWantsToEnterOrExit(Object* obj, ObjectEnterExitType wants) = 0;
  94. // returns true iff there are objects currently waiting to enter.
  95. virtual Bool hasObjectsWantingToEnterOrExit() const = 0;
  96. /**
  97. return the player that *appears* to control this unit, given an observing player.
  98. if null, use getObject()->getControllingPlayer() instead.
  99. */
  100. virtual const Player* getApparentControllingPlayer(const Player* observingPlayer) const = 0;
  101. virtual void recalcApparentControllingPlayer() = 0;
  102. //
  103. // you will want to override onContaining() and onRemoving() if you need to
  104. // do special actions at those event times for your module
  105. //
  106. virtual void onContaining( Object *obj, Bool wasSelected ) = 0; ///< object now contains 'obj'
  107. virtual void onRemoving( Object *obj ) = 0; ///< object no longer contains 'obj'
  108. virtual void onCapture( Player *oldOwner, Player *newOwner ) = 0; // Very important to handle capture of container, don't want to differ in teams from passenger to us.
  109. virtual void onSelling() = 0;///< Container is being sold. Most people respond by kicking everyone out, but not all.
  110. virtual Int getContainMax() const = 0; ///< The max needs to be virtual, but only two inheritors care. -1 means "I don't care".
  111. virtual ExitInterface* getContainExitInterface() = 0;
  112. virtual void orderAllPassengersToExit( CommandSourceType, Bool instantly ) = 0; ///< All of the smarts of exiting are in the passenger's AIExit. removeAllFrommContain is a last ditch system call, this is the game Evacuate
  113. virtual void orderAllPassengersToIdle( CommandSourceType ) = 0; ///< Just like it sounds
  114. virtual void orderAllPassengersToHackInternet( CommandSourceType ) = 0; ///< Just like it sounds
  115. virtual void markAllPassengersDetected() = 0; ///< Cool game stuff got added to the system calls since this layer didn't exist, so this regains that functionality
  116. //
  117. // interface for containing objects inside of objects. Objects that are
  118. // contained remove their drawable representations entirely from the client
  119. //
  120. /**
  121. can this container contain this kind of object?
  122. and, if checkCapacity is TRUE, does this container have enough space left to hold the given unit?
  123. */
  124. virtual Bool isValidContainerFor(const Object* obj, Bool checkCapacity) const = 0;
  125. virtual void addToContain( Object *obj ) = 0; ///< add 'obj' to contain list
  126. virtual void addToContainList( Object *obj ) = 0; ///< The part of AddToContain that inheritors can override (Can't do whole thing because of all the private stuff involved)
  127. virtual void removeFromContain( Object *obj, Bool exposeStealthUnits = FALSE ) = 0; ///< remove 'obj' from contain list
  128. virtual void removeAllContained( Bool exposeStealthUnits = FALSE ) = 0; ///< remove all objects on contain list
  129. virtual void killAllContained( void ) = 0; ///< kill all objects on contain list
  130. virtual void harmAndForceExitAllContained( DamageInfo *info ) = 0; // apply canned damage against those containes
  131. virtual Bool isEnclosingContainerFor( const Object *obj ) const = 0; ///< Does this type of Contain Visibly enclose its contents?
  132. virtual Bool isPassengerAllowedToFire( ObjectID id = INVALID_ID ) const = 0; ///< Hey, can I shoot out of this container?
  133. virtual void setPassengerAllowedToFire( Bool permission = TRUE ) = 0; ///< Hey, can I shoot out of this container?
  134. virtual void setOverrideDestination( const Coord3D * ) = 0; ///< Instead of falling peacefully towards a clear spot, I will now aim here
  135. virtual Bool isDisplayedOnControlBar() const = 0;///< Does this container display its contents on the ControlBar?
  136. virtual Int getExtraSlotsInUse( void ) = 0;
  137. virtual Bool isKickOutOnCapture() = 0;///< Does this contain module kick people out when captured?
  138. // list access
  139. virtual void iterateContained( ContainIterateFunc func, void *userData, Bool reverse ) = 0; ///< iterate the contain list
  140. virtual UnsignedInt getContainCount() const = 0; ///< contained count
  141. virtual const ContainedItemsList* getContainedItemsList() const = 0;
  142. virtual const Object *friend_getRider() const = 0; ///< Damn. The draw order dependency bug for riders means that our draw module needs to cheat to get around it.
  143. virtual Real getContainedItemsMass() const = 0;
  144. virtual UnsignedInt getStealthUnitsContained() const = 0;
  145. virtual Bool calcBestGarrisonPosition( Coord3D *sourcePos, const Coord3D *targetPos ) = 0;
  146. virtual Bool attemptBestFirePointPosition( Object *source, Weapon *weapon, Object *victim ) = 0;
  147. virtual Bool attemptBestFirePointPosition( Object *source, Weapon *weapon, const Coord3D *targetPos ) = 0;
  148. // Player Occupancy.
  149. virtual PlayerMaskType getPlayerWhoEntered(void) const = 0;
  150. virtual void processDamageToContained(Real percentDamage) = 0; ///< Do our % damage to units now.
  151. virtual Object* getClosestRider ( const Coord3D *pos ) = 0;
  152. virtual void enableLoadSounds( Bool enable ) = 0;
  153. virtual void setEvacDisposition( EvacDisposition disp ) = 0;
  154. virtual Bool isWeaponBonusPassedToPassengers() const = 0;
  155. virtual WeaponBonusConditionFlags getWeaponBonusPassedToPassengers() const = 0;
  156. // this exists really just so someone can override it to prevent pip showings...
  157. virtual Bool getContainerPipsToShow(Int& numTotal, Int& numFull)
  158. {
  159. numTotal = getContainMax();
  160. numFull = getContainCount() + getExtraSlotsInUse();
  161. // srj sez: this makes the pips display in the same manner as the inventory control bar...
  162. // numTotal = getContainMax() - getExtraSlotsInUse();
  163. // numFull = getContainCount();
  164. return true;
  165. }
  166. };
  167. //-------------------------------------------------------------------------------------------------
  168. #endif