Energy.h 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  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: Energy.h ////////////////////////////////////////////////////////////
  24. //-----------------------------------------------------------------------------
  25. //
  26. // Westwood Studios Pacific.
  27. //
  28. // Confidential Information
  29. // Copyright (C) 2001 - All Rights Reserved
  30. //
  31. //-----------------------------------------------------------------------------
  32. //
  33. // Project: RTS3
  34. //
  35. // File name: Energy.h
  36. //
  37. // Created: Steven Johnson, October 2001
  38. //
  39. // Desc: @todo
  40. //
  41. //-----------------------------------------------------------------------------
  42. #pragma once
  43. #ifndef _ENERGY_H_
  44. #define _ENERGY_H_
  45. // INLCUDES /////////////////////////////////////////////////////////////////////////////////////
  46. #include "Common/Snapshot.h"
  47. // ----------------------------------------------------------------------------------------------
  48. class Player;
  49. class Object;
  50. // ----------------------------------------------------------------------------------------------
  51. /**
  52. This class is used to encapsulate the Player's energy use and production.
  53. for consistent nomenclature, we'll arbitrarily call energy units "kilowatts"
  54. (though that may have no bearing on reality).
  55. */
  56. class Energy : public Snapshot
  57. {
  58. public:
  59. Energy();
  60. // reset energy information to base values.
  61. void init( Player *owner)
  62. {
  63. m_energyProduction = 0;
  64. m_energyConsumption = 0;
  65. m_owner = owner;
  66. }
  67. /// return current energy production in kilowatts
  68. Int getProduction() const;
  69. /// return current energy consumption in kilowatts
  70. Int getConsumption() const { return m_energyConsumption; }
  71. Bool hasSufficientPower(void) const;
  72. // If adding is false, we're supposed to be removing this.
  73. void adjustPower(Int powerDelta, Bool adding);
  74. /// new 'obj' will now add/subtract from this energy construct
  75. void objectEnteringInfluence( Object *obj );
  76. /// 'obj' will now no longer add/subtrack from this energy construct
  77. void objectLeavingInfluence( Object *obj );
  78. /** Adds an energy bonus to the player's pool if the power bonus status bit is set */
  79. void addPowerBonus( Object *obj );
  80. void removePowerBonus( Object *obj );
  81. void setPowerSabotagedTillFrame( UnsignedInt frame ) { m_powerSabotagedTillFrame = frame; }
  82. UnsignedInt getPowerSabotagedTillFrame() const { return m_powerSabotagedTillFrame; }
  83. /**
  84. return the percentage of energy needed that we actually produce, as a 0.0 ... 1.0 fraction.
  85. */
  86. Real getEnergySupplyRatio() const;
  87. protected:
  88. // snapshot methods
  89. virtual void crc( Xfer *xfer );
  90. virtual void xfer( Xfer *xfer );
  91. virtual void loadPostProcess( void );
  92. void addProduction(Int amt);
  93. void addConsumption(Int amt);
  94. private:
  95. Int m_energyProduction; ///< level of energy production, in kw
  96. Int m_energyConsumption; ///< level of energy consumption, in kw
  97. UnsignedInt m_powerSabotagedTillFrame; ///< If power is sabotaged, the frame will be greater than now.
  98. Player *m_owner; ///< Tight pointer to the Player I am intrinsic to.
  99. };
  100. #endif // _ENERGY_H_