forked from electronicarts/CnC_Generals_Zero_Hour
-
Notifications
You must be signed in to change notification settings - Fork 188
Expand file tree
/
Copy pathPoisonedBehavior.cpp
More file actions
261 lines (216 loc) · 9.75 KB
/
PoisonedBehavior.cpp
File metadata and controls
261 lines (216 loc) · 9.75 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
/*
** Command & Conquer Generals Zero Hour(tm)
** Copyright 2025 Electronic Arts Inc.
**
** This program is free software: you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
** the Free Software Foundation, either version 3 of the License, or
** (at your option) any later version.
**
** This program is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
** GNU General Public License for more details.
**
** You should have received a copy of the GNU General Public License
** along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
////////////////////////////////////////////////////////////////////////////////
// //
// (c) 2001-2003 Electronic Arts Inc. //
// //
////////////////////////////////////////////////////////////////////////////////
// FILE: PoisonedBehavior.cpp /////////////////////////////////////////////////////////////////////////
// Author: Graham Smallwood, July 2002
// Desc: Behavior that reacts to poison Damage by continuously damaging us further in an Update
///////////////////////////////////////////////////////////////////////////////////////////////////
// INCLUDES ///////////////////////////////////////////////////////////////////////////////////////
#include "PreRTS.h" // This must go first in EVERY cpp file in the GameEngine
#include "Common/Xfer.h"
#include "GameClient/Drawable.h"
#include "GameLogic/Module/PoisonedBehavior.h"
#include "GameLogic/Damage.h"
#include "GameLogic/GameLogic.h"
#include "GameLogic/Object.h"
// tinting is all handled in drawable, now, Graham look near the bottom of Drawable::UpdateDrawable()
//static const RGBColor poisonedTint = {0.0f, 1.0f, 0.0f};
//-------------------------------------------------------------------------------------------------
PoisonedBehaviorModuleData::PoisonedBehaviorModuleData()
{
m_poisonDamageIntervalData = 0; // How often I retake poison damage dealt me
m_poisonDurationData = 0; // And how long after the last poison dose I am poisoned
}
//-------------------------------------------------------------------------------------------------
/*static*/ void PoisonedBehaviorModuleData::buildFieldParse(MultiIniFieldParse& p)
{
static const FieldParse dataFieldParse[] =
{
{ "PoisonDamageInterval", INI::parseDurationUnsignedInt, nullptr, offsetof(PoisonedBehaviorModuleData, m_poisonDamageIntervalData) },
{ "PoisonDuration", INI::parseDurationUnsignedInt, nullptr, offsetof(PoisonedBehaviorModuleData, m_poisonDurationData) },
{ nullptr, nullptr, nullptr, 0 }
};
UpdateModuleData::buildFieldParse(p);
p.add(dataFieldParse);
}
//-------------------------------------------------------------------------------------------------
//-------------------------------------------------------------------------------------------------
PoisonedBehavior::PoisonedBehavior( Thing *thing, const ModuleData* moduleData ) : UpdateModule( thing, moduleData )
{
m_poisonDamageFrame = 0;
m_poisonOverallStopFrame = 0;
m_poisonDamageAmount = 0.0f;
m_poisonSource = INVALID_ID;
m_deathType = DEATH_POISONED;
setWakeFrame(getObject(), UPDATE_SLEEP_FOREVER);
}
//-------------------------------------------------------------------------------------------------
//-------------------------------------------------------------------------------------------------
PoisonedBehavior::~PoisonedBehavior( void )
{
}
//-------------------------------------------------------------------------------------------------
/** Damage has been dealt, this is an opportunity to react to that damage */
//-------------------------------------------------------------------------------------------------
void PoisonedBehavior::onDamage( DamageInfo *damageInfo )
{
if( damageInfo->in.m_damageType == DAMAGE_POISON )
startPoisonedEffects( damageInfo );
}
// ------------------------------------------------------------------------------------------------
// ------------------------------------------------------------------------------------------------
void PoisonedBehavior::onHealing( DamageInfo *damageInfo )
{
stopPoisonedEffects();
setWakeFrame(getObject(), UPDATE_SLEEP_FOREVER);
}
// ------------------------------------------------------------------------------------------------
// ------------------------------------------------------------------------------------------------
UpdateSleepTime PoisonedBehavior::update()
{
const PoisonedBehaviorModuleData* d = getPoisonedBehaviorModuleData();
UnsignedInt now = TheGameLogic->getFrame();
if( m_poisonOverallStopFrame == 0 )
{
DEBUG_CRASH(("hmm, this should not happen"));
return UPDATE_SLEEP_FOREVER;
//we aren't poisoned, so nevermind
}
if (m_poisonDamageFrame != 0 && now >= m_poisonDamageFrame)
{
// If it is time to do damage, then do it and reset the damage timer
DamageInfo damage;
damage.in.m_amount = m_poisonDamageAmount;
damage.in.m_sourceID = m_poisonSource;
damage.in.m_damageType = DAMAGE_UNRESISTABLE; // Not poison, as that will infect us again
damage.in.m_damageFXOverride = DAMAGE_POISON; // but this will ensure that the right effect is played
damage.in.m_deathType = m_deathType;
getObject()->attemptDamage( &damage );
m_poisonDamageFrame = now + d->m_poisonDamageIntervalData;
}
// If we are now at zero we need to turn off our special effects...
// unless the poison killed us, then we continue to be a pulsating toxic pus ball
if( m_poisonOverallStopFrame != 0 &&
now >= m_poisonOverallStopFrame &&
!getObject()->isEffectivelyDead())
{
stopPoisonedEffects();
}
return calcSleepTime();
}
// ------------------------------------------------------------------------------------------------
// ------------------------------------------------------------------------------------------------
UpdateSleepTime PoisonedBehavior::calcSleepTime()
{
// UPDATE_SLEEP requires a count-of-frames, not an absolute-frame, so subtract 'now'
UnsignedInt now = TheGameLogic->getFrame();
if (m_poisonOverallStopFrame == 0 || m_poisonOverallStopFrame == now)
return UPDATE_SLEEP_FOREVER;
return frameToSleepTime(m_poisonDamageFrame, m_poisonOverallStopFrame);
}
// ------------------------------------------------------------------------------------------------
// ------------------------------------------------------------------------------------------------
void PoisonedBehavior::startPoisonedEffects( const DamageInfo *damageInfo )
{
const PoisonedBehaviorModuleData* d = getPoisonedBehaviorModuleData();
UnsignedInt now = TheGameLogic->getFrame();
// We are going to take the damage dealt by the original poisoner every so often for a while.
m_poisonDamageAmount = damageInfo->out.m_actualDamageDealt;
#if !RETAIL_COMPATIBLE_CRC && !PRESERVE_RETAIL_BEHAVIOR
// TheSuperHackers @bugfix Stubbjax 03/09/2025 Allow poison damage to award xp to the poison source.
m_poisonSource = damageInfo->in.m_sourceID;
#endif
m_poisonOverallStopFrame = now + d->m_poisonDurationData;
// If we are getting re-poisoned, don't reset the damage counter if running, but do set it if unset
if( m_poisonDamageFrame != 0 )
m_poisonDamageFrame = min( m_poisonDamageFrame, now + d->m_poisonDamageIntervalData );
else
m_poisonDamageFrame = now + d->m_poisonDamageIntervalData;
m_deathType = damageInfo->in.m_deathType;
Drawable *myDrawable = getObject()->getDrawable();
if( myDrawable )
myDrawable->setTintStatus( TINT_STATUS_POISONED );// Graham, It has changed, see UpdateDrawable()
setWakeFrame(getObject(), calcSleepTime());
}
// ------------------------------------------------------------------------------------------------
// ------------------------------------------------------------------------------------------------
void PoisonedBehavior::stopPoisonedEffects()
{
m_poisonDamageFrame = 0;
m_poisonOverallStopFrame = 0;
m_poisonDamageAmount = 0.0f;
m_poisonSource = INVALID_ID;
Drawable *myDrawable = getObject()->getDrawable();
if( myDrawable )
myDrawable->clearTintStatus( TINT_STATUS_POISONED );// Graham, It has changed, see UpdateDrawable()
}
// ------------------------------------------------------------------------------------------------
/** CRC */
// ------------------------------------------------------------------------------------------------
void PoisonedBehavior::crc( Xfer *xfer )
{
// extend base class
UpdateModule::crc( xfer );
}
// ------------------------------------------------------------------------------------------------
/** Xfer method
* Version Info:
* 1: Initial version
* 2: Serialize death type
* 3: TheSuperHackers @tweak Serialize poison source
*/
// ------------------------------------------------------------------------------------------------
void PoisonedBehavior::xfer( Xfer *xfer )
{
// version
#if RETAIL_COMPATIBLE_XFER_SAVE
const XferVersion currentVersion = 2;
#else
const XferVersion currentVersion = 3;
#endif
XferVersion version = currentVersion;
xfer->xferVersion( &version, currentVersion );
// extend base class
UpdateModule::xfer( xfer );
// poisoned damage frame
xfer->xferUnsignedInt( &m_poisonDamageFrame );
// poison overall stop frame
xfer->xferUnsignedInt( &m_poisonOverallStopFrame );
// poison damage amount
xfer->xferReal( &m_poisonDamageAmount );
if (version >= 2)
{
xfer->xferUser(&m_deathType, sizeof(m_deathType));
}
if (version >= 3)
{
xfer->xferObjectID(&m_poisonSource);
}
}
// ------------------------------------------------------------------------------------------------
/** Load post process */
// ------------------------------------------------------------------------------------------------
void PoisonedBehavior::loadPostProcess( void )
{
// extend base class
UpdateModule::loadPostProcess();
}