|
| 1 | +/* |
| 2 | +** Command & Conquer Generals(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 | +// // |
| 21 | +// (c) 2001-2003 Electronic Arts Inc. // |
| 22 | +// // |
| 23 | +//////////////////////////////////////////////////////////////////////////////// |
| 24 | + |
| 25 | +// FILE: DamageFX.h ///////////////////////////////////////////////////////////////////////////////// |
| 26 | +// Author: Steven Johnson, November 2001 |
| 27 | +// Desc: Damage Effects Descriptions |
| 28 | +/////////////////////////////////////////////////////////////////////////////////////////////////// |
| 29 | + |
| 30 | +#pragma once |
| 31 | + |
| 32 | +#ifndef _DamageFX_H_ |
| 33 | +#define _DamageFX_H_ |
| 34 | + |
| 35 | +// INCLUDES /////////////////////////////////////////////////////////////////////////////////////// |
| 36 | +#include "Common/GameCommon.h" |
| 37 | +#include "Common/NameKeyGenerator.h" |
| 38 | +#include "Common/STLTypedefs.h" |
| 39 | +#include "GameLogic/Damage.h" |
| 40 | + |
| 41 | +// FORWARD REFERENCES ///////////////////////////////////////////////////////////////////////////// |
| 42 | +class DamageFXStore; |
| 43 | +class FXList; |
| 44 | +class INI; |
| 45 | + |
| 46 | +//------------------------------------------------------------------------------------------------- |
| 47 | +typedef const FXList* ConstFXListPtr; |
| 48 | + |
| 49 | +//------------------------------------------------------------------------------------------------- |
| 50 | +/** |
| 51 | + A DamageFX is an object used to describe how an object reacts to taking a particular type |
| 52 | + of damage. (Note that "reacts" here implies only audio-video effects, not logic effects, |
| 53 | + damage modifiers, etc.) |
| 54 | +
|
| 55 | + Conceptually speaking, every unit with a Body module has a DamageFX object. When it receives damage, |
| 56 | + it asks its DamageFX module to produce an appropriate a/v effect, which can vary by type of damage |
| 57 | + (eg, explosion, armor-piercing, flame, etc) and amount ("minor" or "major"). |
| 58 | +
|
| 59 | + Notes: |
| 60 | +
|
| 61 | + -- Every particular damage-type within a DamageFX can have a "minor" and/or "major" effect; |
| 62 | + basically, if the damage done exceeds a specified threshold (or if there isn't a "minor" |
| 63 | + effect), the major effect is used. |
| 64 | +
|
| 65 | + -- DamageFX is shared between multiple units; there should generally only be one instance |
| 66 | + of any particular class. The implication is that it should not require private data storage |
| 67 | + to do what it needs to do, aside from stuff initialized at object instantiation time. To help |
| 68 | + enforce this, all it's methods are declared 'const'. If you can't implement the damage you |
| 69 | + need within this framework, please *don't* simply de-const things, because it could lead to very |
| 70 | + strange side-effects. Instead, the system will have to be enhanced to allow for multiple instances |
| 71 | + of each DamageFX. |
| 72 | +*/ |
| 73 | +//------------------------------------------------------------------------------------------------- |
| 74 | +class DamageFX |
| 75 | +{ |
| 76 | +public: |
| 77 | + |
| 78 | + DamageFX(); |
| 79 | + |
| 80 | + void clear(); |
| 81 | + |
| 82 | + /** |
| 83 | + This is the main public access point to the system: when you want to execute the |
| 84 | + a/v fx used for a specific damage type, call this method. (It is OK for source and/or |
| 85 | + victim to be null, but you should pass them when available.) |
| 86 | + */ |
| 87 | + void doDamageFX(DamageType t, Real damageAmount, const Object* source, const Object* victim) const; |
| 88 | + |
| 89 | + UnsignedInt getDamageFXThrottleTime(DamageType t, const Object* source) const; |
| 90 | + |
| 91 | + const FieldParse* getFieldParse() const; |
| 92 | + |
| 93 | +private: |
| 94 | + |
| 95 | + ConstFXListPtr getDamageFXList(DamageType t, Real damageAmount, const Object* source) const; |
| 96 | + |
| 97 | + static void parseAmount( INI* ini, void *instance, void*, const void* ); |
| 98 | + static void parseMajorFXList( INI* ini, void *instance, void*, const void* ); |
| 99 | + static void parseMinorFXList( INI* ini, void *instance, void*, const void* ); |
| 100 | + static void parseTime( INI* ini, void *instance, void*, const void* ); |
| 101 | + |
| 102 | + /* |
| 103 | + this isn't terribly efficient since this is pretty sparsely populated |
| 104 | + and with lots of redundancy, but since we allocate very few of these, |
| 105 | + it's not worth more effort at this time... |
| 106 | + */ |
| 107 | + struct DFX |
| 108 | + { |
| 109 | + Real m_amountForMajorFX; ///< if damage done is >= this, use major fx |
| 110 | + ConstFXListPtr m_majorDamageFXList; ///< fx to make |
| 111 | + ConstFXListPtr m_minorDamageFXList; ///< fx to make |
| 112 | + UnsignedInt m_damageFXThrottleTime; |
| 113 | + |
| 114 | + DFX() |
| 115 | + { |
| 116 | + clear(); |
| 117 | + } |
| 118 | + |
| 119 | + void clear() |
| 120 | + { |
| 121 | + m_amountForMajorFX = 0.0f; |
| 122 | + m_majorDamageFXList = NULL; |
| 123 | + m_minorDamageFXList = NULL; |
| 124 | + m_damageFXThrottleTime = 0; |
| 125 | + } |
| 126 | + }; |
| 127 | + |
| 128 | + DFX m_dfx[DAMAGE_NUM_TYPES][LEVEL_COUNT]; |
| 129 | +}; |
| 130 | + |
| 131 | +//------------------------------------------------------------------------------------------------- |
| 132 | +/** |
| 133 | + The "store" used to hold all the DamageFXs in existence. This is usually used when creating |
| 134 | + an Object (actually, a Body module), but can be used at any time after that. (It is explicitly |
| 135 | + OK to swap an Object's DamageFX out at any given time.) |
| 136 | +*/ |
| 137 | +//------------------------------------------------------------------------------------------------- |
| 138 | +class DamageFXStore : public SubsystemInterface |
| 139 | +{ |
| 140 | + |
| 141 | +public: |
| 142 | + |
| 143 | + DamageFXStore(); |
| 144 | + ~DamageFXStore(); |
| 145 | + |
| 146 | + void init(); |
| 147 | + void reset(); |
| 148 | + void update(); |
| 149 | + |
| 150 | + /** |
| 151 | + Find the DamageFX with the given name. If no such DamageFX exists, return null. |
| 152 | + */ |
| 153 | + const DamageFX *findDamageFX( AsciiString name ) const; |
| 154 | + |
| 155 | + static void parseDamageFXDefinition(INI* ini); |
| 156 | + |
| 157 | + |
| 158 | +private: |
| 159 | + |
| 160 | + typedef std::hash_map< NameKeyType, DamageFX, rts::hash<NameKeyType>, rts::equal_to<NameKeyType> > DamageFXMap; |
| 161 | + DamageFXMap m_dfxmap; |
| 162 | + |
| 163 | +}; |
| 164 | + |
| 165 | +// EXTERNALS ////////////////////////////////////////////////////////////////////////////////////// |
| 166 | +extern DamageFXStore *TheDamageFXStore; |
| 167 | + |
| 168 | +#endif // _DamageFX_H_ |
| 169 | + |
0 commit comments