-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathCOverlayType.cpp
336 lines (252 loc) · 8.12 KB
/
COverlayType.cpp
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
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
// COverlayType.cpp
//
// COverlayType class
#include "PreComp.h"
#define COUNTER_TAG CONSTLIT("Counter")
#define EFFECT_WHEN_HIT_TAG CONSTLIT("EffectWhenHit")
#define EFFECT_TAG CONSTLIT("Effect")
#define HIT_EFFECT_TAG CONSTLIT("HitEffect")
#define SHIP_ENERGY_FIELD_TYPE_TAG CONSTLIT("ShipEnergyFieldType")
#define ABSORB_ADJ_ATTRIB CONSTLIT("absorbAdj")
#define ALT_EFFECT_ATTRIB CONSTLIT("altEffect")
#define COLOR_ATTRIB CONSTLIT("color")
#define DISABLE_SHIP_SCREEN_ATTRIB CONSTLIT("disableShipScreen")
#define DISARM_ATTRIB CONSTLIT("disarm")
#define DRAG_ATTRIB CONSTLIT("drag")
#define IGNORE_SHIP_ROTATION_ATTRIB CONSTLIT("ignoreSourceRotation")
#define LABEL_ATTRIB CONSTLIT("label")
#define MAX_ATTRIB CONSTLIT("max")
#define PARALYZE_ATTRIB CONSTLIT("paralyze")
#define SHIELD_OVERLAY_ATTRIB CONSTLIT("shieldOverlay")
#define SHOW_ON_MAP_ATTRIB CONSTLIT("showOnMap")
#define SPIN_ATTRIB CONSTLIT("spin")
#define STYLE_ATTRIB CONSTLIT("style")
#define TIME_STOP_ATTRIB CONSTLIT("timeStop")
#define UNID_ATTRIB CONSTLIT("UNID")
#define BONUS_ADJ_ATTRIB CONSTLIT("weaponBonusAdj")
#define WEAPON_SUPPRESS_ATTRIB CONSTLIT("weaponSuppress")
#define COUNTER_COMMAND_BAR_PROGRESS CONSTLIT("commandBarProgress")
#define COUNTER_FLAG CONSTLIT("flag")
#define COUNTER_PROGRESS CONSTLIT("progress")
#define COUNTER_RADIUS CONSTLIT("radius")
#define FIELD_WEAPON_SUPPRESS CONSTLIT("weaponSuppress")
#define ON_UPDATE_EVENT CONSTLIT("OnUpdate")
#define SUPPRESS_ALL CONSTLIT("*")
COverlayType::COverlayType (void) :
m_pEffect(NULL),
m_pHitEffect(NULL)
// COverlayType constructor
{
}
COverlayType::~COverlayType (void)
// COverlayType destructor
{
if (m_pEffect)
delete m_pEffect;
if (m_pHitEffect)
delete m_pHitEffect;
}
bool COverlayType::AbsorbsWeaponFire (CInstalledDevice *pWeapon)
// AbsorbsWeaponFire
//
// Absorbs weapon fire from the ship
{
int iType = pWeapon->GetDamageType(CItemCtx(NULL, pWeapon));
if (iType != -1 && m_WeaponSuppress.InSet(iType))
return true;
else
return false;
}
bool COverlayType::FindDataField (const CString &sField, CString *retsValue) const
// FindDataField
//
// Returns meta-data
{
int i;
if (strEquals(sField, FIELD_WEAPON_SUPPRESS))
{
if (m_WeaponSuppress.IsEmpty())
*retsValue = NULL_STR;
else
{
*retsValue = CONSTLIT("=(");
bool bNeedSeparator = false;
for (i = 0; i < damageCount; i++)
if (m_WeaponSuppress.InSet(i))
{
if (bNeedSeparator)
retsValue->Append(CONSTLIT(" "));
retsValue->Append(::GetDamageType((DamageTypes)i));
bNeedSeparator = true;
}
retsValue->Append(CONSTLIT(")"));
}
}
else
return CDesignType::FindDataField(sField, retsValue);
return true;
}
int COverlayType::GetDamageAbsorbed (CSpaceObject *pSource, SDamageCtx &Ctx)
// GetDamageAbsorbed
//
// Returns the amount of damage absorbed
{
int i;
if (Ctx.Damage.GetDamageType() == damageGeneric)
{
// For generic damage, we absorb the min of all other damage types
int iMin = 100;
for (i = 0; i < damageCount; i++)
if (m_AbsorbAdj.GetAbsorbAdj((DamageTypes)i) < iMin)
iMin = m_AbsorbAdj.GetAbsorbAdj((DamageTypes)i);
return (Ctx.iDamage * iMin) / 100;
}
return (Ctx.iDamage * m_AbsorbAdj.GetAbsorbAdj(Ctx.Damage.GetDamageType())) / 100;
}
int COverlayType::GetWeaponBonus (CInstalledDevice *pDevice, CSpaceObject *pSource)
// GetWeaponBonus
//
// Returns the bonus for this weapon
{
DamageTypes iType = (DamageTypes)pDevice->GetDamageType(CItemCtx(pSource, pDevice));
if (iType == damageGeneric)
return 0;
return m_BonusAdj.GetHPBonus(iType);
}
void COverlayType::OnAddTypesUsed (TSortMap<DWORD, bool> *retTypesUsed)
// OnAddTypesUsed
//
// Add types used to the list.
{
// LATER: m_pEffect and m_pHitEffect are always local; we should allow
// them to be an design type.
}
ALERROR COverlayType::OnBindDesign (SDesignLoadCtx &Ctx)
// OnBindDesign
//
// Bind design
{
ALERROR error;
if (m_pEffect)
if (error = m_pEffect->BindDesign(Ctx))
return error;
if (m_pHitEffect)
if (error = m_pHitEffect->BindDesign(Ctx))
return error;
return NOERROR;
}
ALERROR COverlayType::OnCreateFromXML (SDesignLoadCtx &Ctx, CXMLElement *pDesc)
// OnCreateFromXML
//
// Create from XML
{
ALERROR error;
// Effect
CXMLElement *pEffect = pDesc->GetContentElementByTag(EFFECT_TAG);
if (pEffect)
{
if (error = CEffectCreator::CreateFromXML(Ctx,
pEffect,
strPatternSubst(CONSTLIT("%d:e"), GetUNID()),
&m_pEffect))
return ComposeLoadError(Ctx, CONSTLIT("Unable to load effect."));
}
pEffect = pDesc->GetContentElementByTag(HIT_EFFECT_TAG);
if (pEffect == NULL)
pEffect = pDesc->GetContentElementByTag(EFFECT_WHEN_HIT_TAG);
if (pEffect)
{
if (error = CEffectCreator::CreateFromXML(Ctx,
pEffect,
strPatternSubst(CONSTLIT("%d:h"), GetUNID()),
&m_pHitEffect))
return ComposeLoadError(Ctx, CONSTLIT("Unable to load hit effect."));
// For compatibility with previous versions, if we're using the old
// <ShipEnergyFieldType> then altEffect defaults to TRUE. Otherwise, for new
// <OverlayType> altEffect defaults to false.
bool bAltEffect;
if (pEffect->FindAttributeBool(ALT_EFFECT_ATTRIB, &bAltEffect))
m_fAltHitEffect = bAltEffect;
else
m_fAltHitEffect = strEquals(pDesc->GetTag(), SHIP_ENERGY_FIELD_TYPE_TAG);
}
else
m_fAltHitEffect = false;
// Rotation
m_fRotateWithShip = !pDesc->GetAttributeBool(IGNORE_SHIP_ROTATION_ATTRIB);
// Damage adjustment
if (error = m_AbsorbAdj.InitFromDamageAdj(Ctx, pDesc->GetAttribute(ABSORB_ADJ_ATTRIB), false))
return ComposeLoadError(Ctx, Ctx.sError);
// Bonus adjustment
if (error = m_BonusAdj.InitFromHPBonus(Ctx, pDesc->GetAttribute(BONUS_ADJ_ATTRIB)))
return ComposeLoadError(Ctx, Ctx.sError);
// Load the weapon suppress
if (error = m_WeaponSuppress.InitFromXML(pDesc->GetAttribute(WEAPON_SUPPRESS_ATTRIB)))
return ComposeLoadError(Ctx, CONSTLIT("Unable to load weapon suppress attribute"));
// Are we a field/shield overlay (or part of hull)?
// By default, we are a shield overlay if we absorb damage.
bool bValue;
if (pDesc->FindAttributeBool(SHIELD_OVERLAY_ATTRIB, &bValue))
m_fShieldOverlay = bValue;
else
m_fShieldOverlay = !m_AbsorbAdj.IsEmpty();
// Counter
CXMLElement *pCounter = pDesc->GetContentElementByTag(COUNTER_TAG);
if (pCounter)
{
CString sStyle = pCounter->GetAttribute(STYLE_ATTRIB);
if (strEquals(sStyle, COUNTER_COMMAND_BAR_PROGRESS))
m_iCounterType = counterCommandBarProgress;
else if (strEquals(sStyle, COUNTER_FLAG))
m_iCounterType = counterFlag;
else if (strEquals(sStyle, COUNTER_PROGRESS))
m_iCounterType = counterProgress;
else if (strEquals(sStyle, COUNTER_RADIUS))
m_iCounterType = counterRadius;
else
return ComposeLoadError(Ctx, strPatternSubst(CONSTLIT("Unknown counter style: %s"), sStyle));
m_sCounterLabel = pCounter->GetAttribute(LABEL_ATTRIB);
m_iCounterMax = pCounter->GetAttributeIntegerBounded(MAX_ATTRIB, 0, -1, 100);
m_rgbCounterColor = ::LoadRGBColor(pCounter->GetAttribute(COLOR_ATTRIB));
m_fShowOnMap = pCounter->GetAttributeBool(SHOW_ON_MAP_ATTRIB);
}
else
{
m_iCounterType = counterNone;
m_iCounterMax = 0;
m_rgbCounterColor = CG32bitPixel::Null();
m_fShowOnMap = false;
}
// Options
m_fDisarmShip = pDesc->GetAttributeBool(DISARM_ATTRIB);
m_fParalyzeShip = pDesc->GetAttributeBool(PARALYZE_ATTRIB);
m_fDisableShipScreen = pDesc->GetAttributeBool(DISABLE_SHIP_SCREEN_ATTRIB);
m_fSpinShip = pDesc->GetAttributeBool(SPIN_ATTRIB);
m_fTimeStop = pDesc->GetAttributeBool(TIME_STOP_ATTRIB);
int iDrag;
if (pDesc->FindAttributeInteger(DRAG_ATTRIB, &iDrag))
m_rDrag = Min(Max(0, iDrag), 100) / 100.0;
else
m_rDrag = 1.0;
// Done
return NOERROR;
}
CEffectCreator *COverlayType::OnFindEffectCreator (const CString &sUNID)
// OnFindEffectCreator
//
// Load the proper effect creator
{
char *pPos = sUNID.GetASCIIZPointer();
if (*pPos != ':')
return NULL;
pPos++;
switch (*pPos)
{
case 'e':
return m_pEffect;
case 'h':
return m_pHitEffect;
default:
return NULL;
}
}