|
| 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 | +// // |
| 21 | +// (c) 2001-2003 Electronic Arts Inc. // |
| 22 | +// // |
| 23 | +//////////////////////////////////////////////////////////////////////////////// |
| 24 | + |
| 25 | +// FILE: BuffSystem.h ///////////////////////////////////////////////////////////////////////////// |
| 26 | +// Author: Andi W, October 25 |
| 27 | +// Desc: Buff/Debuff effects |
| 28 | +/////////////////////////////////////////////////////////////////////////////////////////////////// |
| 29 | + |
| 30 | +#pragma once |
| 31 | + |
| 32 | +#ifndef _BuffSystem_H_ |
| 33 | +#define _BuffSystem_H_ |
| 34 | + |
| 35 | +// INCLUDES /////////////////////////////////////////////////////////////////////////////////////// |
| 36 | +#include "Common/GameMemory.h" |
| 37 | +#include "GameLogic/Object.h" |
| 38 | + |
| 39 | +// FORWARD REFERENCES ///////////////////////////////////////////////////////////////////////////// |
| 40 | +class BuffEffectNugget; |
| 41 | +class BuffTemplate; |
| 42 | +class BuffTemplateStore; |
| 43 | + |
| 44 | +struct BuffEffectTracker; |
| 45 | + |
| 46 | +//class Object; |
| 47 | + |
| 48 | + |
| 49 | +class BuffEffectNugget : public MemoryPoolObject |
| 50 | +{ |
| 51 | + MEMORY_POOL_GLUE_ABC(BuffEffectNugget) |
| 52 | + |
| 53 | +public: |
| 54 | + |
| 55 | + BuffEffectNugget() { } |
| 56 | + //virtual ~BuffEffectNugget() { } |
| 57 | + |
| 58 | + virtual void apply(Object* targetObj, const Object* sourceObj, BuffEffectTracker* buffTracker) const = 0; |
| 59 | + |
| 60 | + virtual void remove(Object* targetObj, BuffEffectTracker* buffTracker) const = 0; |
| 61 | + |
| 62 | + |
| 63 | +}; |
| 64 | +EMPTY_DTOR(BuffEffectNugget) |
| 65 | + |
| 66 | +// ----------------------------------------------- |
| 67 | +// ----------------------------------------------- |
| 68 | + |
| 69 | +class BuffTemplate : public MemoryPoolObject |
| 70 | +{ |
| 71 | + MEMORY_POOL_GLUE_WITH_USERLOOKUP_CREATE(BuffTemplate, "BuffTemplate") |
| 72 | + |
| 73 | +public: |
| 74 | + // for lookup |
| 75 | + AsciiString getName(void) const { return m_name; } |
| 76 | + void friend_setName(const AsciiString& n) { m_name = n; } |
| 77 | + |
| 78 | + inline UnsignedInt getMaxStackSize() const { return m_maxStackSize; } |
| 79 | + inline Bool isStackPerSource() const { return m_stackPerSource; } |
| 80 | + inline const std::vector<AsciiString>& getPriorityTemplates() const { return m_priorityTemplates; } |
| 81 | + |
| 82 | + //inline WeaponBonusConditionType getWeaponBonusType() const { return m_bonusType; } |
| 83 | + //inline WeaponBonusConditionType getWeaponBonusTypeAgainst() const { return m_bonusTypeAgainst; } |
| 84 | + //inline WeaponSetType getWeaponSetFlag() const { return m_weaponSetFlag; } |
| 85 | + //inline ArmorSetType getArmorSetFlag() const { return m_armorSetFlag; } |
| 86 | + //inline ObjectStatusMaskType getStatusToSet() const { return m_statusToSet; } |
| 87 | + |
| 88 | + BuffTemplate(); |
| 89 | + |
| 90 | + /** |
| 91 | + Toss the contents. |
| 92 | + */ |
| 93 | + void clear(); |
| 94 | + |
| 95 | + void addBuffEffectNugget(BuffEffectNugget* nugget); |
| 96 | + |
| 97 | + UnsignedInt getNextTickFrame(UnsignedInt startFrame, UnsignedInt endFrame) const; |
| 98 | + |
| 99 | + void applyEffects(Object* targetObj, Object* sourceObj, BuffEffectTracker* buffTracker) const; |
| 100 | + void removeEffects(Object* targetObj, BuffEffectTracker* buffTracker, Bool ignoreFlags = FALSE) const; |
| 101 | + |
| 102 | + Bool hasPriorityOver(AsciiString templateName) const; |
| 103 | + |
| 104 | + void reApplyFlags(Object* targetObj, const BuffTemplate* other) const; |
| 105 | + |
| 106 | + const FieldParse* getFieldParse(void) const { return TheBuffTemplateFieldParse; } |
| 107 | + |
| 108 | + |
| 109 | +protected: |
| 110 | + AsciiString m_name; |
| 111 | + UnsignedInt m_maxStackSize; |
| 112 | + Bool m_stackPerSource; ///< Each sourceObj has its own stack of buffs on the target. |
| 113 | + |
| 114 | + std::vector<AsciiString> m_priorityTemplates; ///< list of buffTemplates this template has priority over. |
| 115 | + |
| 116 | + // Flags are stored directly in BuffTemplate |
| 117 | + WeaponBonusConditionType m_bonusType; ///< weapon bonus granted to the object |
| 118 | + WeaponBonusConditionType m_bonusTypeAgainst; ///< weapon bonus granted when attacking the object |
| 119 | + WeaponSetType m_weaponSetFlag; ///< the weaponset flag to set |
| 120 | + ArmorSetType m_armorSetFlag; ///< the armorset flag to set |
| 121 | + ObjectStatusMaskType m_statusToSet; ///< the status to set (allows multiple) |
| 122 | + |
| 123 | + // -- |
| 124 | + static const FieldParse TheBuffTemplateFieldParse[]; |
| 125 | + //static const FieldParse flagModifierFieldParse[]; |
| 126 | + |
| 127 | + static void parseFlagModifier(INI* ini, void* instance, void* store, const void* userData); |
| 128 | + |
| 129 | +private: |
| 130 | + |
| 131 | + // note, this list doesn't own the nuggets; all nuggets are owned by the Store. |
| 132 | + typedef std::vector<BuffEffectNugget*> BuffEffectNuggetVector; |
| 133 | + BuffEffectNuggetVector m_nuggets; |
| 134 | + |
| 135 | +}; |
| 136 | +EMPTY_DTOR(BuffTemplate) |
| 137 | + |
| 138 | +//------------------------------------------------------------------------------------------------- |
| 139 | +/** |
| 140 | + The "store" used to hold all the Buffs in existence. |
| 141 | +*/ |
| 142 | +class BuffTemplateStore : public SubsystemInterface |
| 143 | +{ |
| 144 | + |
| 145 | +public: |
| 146 | + |
| 147 | + BuffTemplateStore(); |
| 148 | + ~BuffTemplateStore(); |
| 149 | + |
| 150 | + void init() {} |
| 151 | + void reset() {} |
| 152 | + void update() {} |
| 153 | + |
| 154 | + /** |
| 155 | + return the BuffTemplate with the given namekey. |
| 156 | + return NULL if no such BuffTemplate exists. |
| 157 | + */ |
| 158 | + const BuffTemplate* findBuffTemplate(const char* name) const; |
| 159 | + const BuffTemplate* findBuffTemplate(const AsciiString& name) const { return findBuffTemplate(name.str()); } |
| 160 | + |
| 161 | + BuffTemplate* findBuffTemplate(const char* name); |
| 162 | + BuffTemplate* findBuffTemplate(AsciiString& name) { return findBuffTemplate(name.str()); } |
| 163 | + |
| 164 | + //BuffTemplate* newBuffTemplate(AsciiString& name); |
| 165 | + |
| 166 | + static void parseBuffTemplateDefinition(INI* ini); |
| 167 | + |
| 168 | + void addBuffEffectNugget(BuffEffectNugget* nugget); |
| 169 | + |
| 170 | +private: |
| 171 | + |
| 172 | + typedef std::map< NameKeyType, BuffTemplate*, std::less<NameKeyType> > BuffTemplateMap; |
| 173 | + BuffTemplateMap m_buffTemplates; |
| 174 | + |
| 175 | + // note, this list doesn't own the nuggets; all nuggets are owned by the Store. |
| 176 | + typedef std::vector<BuffEffectNugget*> BuffEffectNuggetVector; |
| 177 | + BuffEffectNuggetVector m_nuggets; |
| 178 | + |
| 179 | +}; |
| 180 | + |
| 181 | +// EXTERNALS ////////////////////////////////////////////////////////////////////////////////////// |
| 182 | +extern BuffTemplateStore* TheBuffTemplateStore; |
| 183 | + |
| 184 | +#endif // _Buff_H_ |
| 185 | + |
0 commit comments