-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathCCyberDeckClass.cpp
253 lines (181 loc) · 5.31 KB
/
CCyberDeckClass.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
// CCyberDeckClass.cpp
//
// CCyberDeckClass class
// Copyright (c) 2004 by George Moromisato. All Rights Reserved.
#include "PreComp.h"
#define RANGE_ATTRIB CONSTLIT("range")
#define ATTACK_CHANCE_ATTRIB CONSTLIT("attackChance")
#define AI_LEVEL_ATTRIB CONSTLIT("aiLevel")
#define PROGRAM_ATTRIB CONSTLIT("program")
#define PROGRAM_NAME_ATTRIB CONSTLIT("programName")
#define SHIELDS_DOWN_PROGRAM CONSTLIT("ShieldsDown")
#define REBOOT_PROGRAM CONSTLIT("Reboot")
#define DISARM_PROGRAM CONSTLIT("Disarm")
CCyberDeckClass::CCyberDeckClass (void)
// CCyberDeckClass constructor
{
}
bool CCyberDeckClass::Activate (CInstalledDevice *pDevice,
CSpaceObject *pSource,
CSpaceObject *pTarget,
bool *retbSourceDestroyed,
bool *retbConsumedItems)
// Activate
//
// Activate device
{
DEBUG_TRY
// Init
if (retbConsumedItems)
*retbConsumedItems = false;
// Won't work if not enabled
if (!pDevice->IsWorking())
return false;
// We better have a target
if (pTarget == NULL)
return false;
// The attack has a random chance of succeeding. If it did not
// succeed, we're done.
if (mathRandom(1, 100) > m_iAttackChance)
{
// There is a chance that the target gets to find out about the
// attempted attack.
// Counts as an attempt (meaning we consume power)
return true;
}
// See if the attack is blocked by defenses
if (m_Program.iAILevel < pTarget->GetCyberDefenseLevel())
{
// There is a chance that the attacker will need to reboot
// Counts as an attempt
return true;
}
// Run the program
pTarget->ProgramDamage(pSource, m_Program);
// Identify when program is run
if (pSource->IsPlayer())
GetItemType()->SetKnown();
return true;
DEBUG_CATCH
}
ALERROR CCyberDeckClass::CreateFromXML (SDesignLoadCtx &Ctx, CXMLElement *pDesc, CItemType *pType, CDeviceClass **retpDevice)
// CreateFromXML
//
// Load the class
{
ALERROR error;
CCyberDeckClass *pDevice;
pDevice = new CCyberDeckClass;
if (pDevice == NULL)
return ERR_MEMORY;
if (error = pDevice->InitDeviceFromXML(Ctx, pDesc, pType))
return error;
pDevice->m_iRange = pDesc->GetAttributeInteger(RANGE_ATTRIB);
pDevice->m_iAttackChance = pDesc->GetAttributeInteger(ATTACK_CHANCE_ATTRIB);
// Program
CString sProgram = pDesc->GetAttribute(PROGRAM_ATTRIB);
if (strEquals(sProgram, SHIELDS_DOWN_PROGRAM))
pDevice->m_Program.iProgram = progShieldsDown;
else if (strEquals(sProgram, REBOOT_PROGRAM))
pDevice->m_Program.iProgram = progReboot;
else if (strEquals(sProgram, DISARM_PROGRAM))
pDevice->m_Program.iProgram = progDisarm;
else
return ERR_FAIL;
pDevice->m_Program.sProgramName = pDesc->GetAttribute(PROGRAM_NAME_ATTRIB);
pDevice->m_Program.iAILevel = pDesc->GetAttributeInteger(AI_LEVEL_ATTRIB);
// Done
*retpDevice = pDevice;
return NOERROR;
}
Metric CCyberDeckClass::GetMaxEffectiveRange (CSpaceObject *pSource, CInstalledDevice *pDevice, CSpaceObject *pTarget)
// GetMaxEffectiveRange
//
// Returns the maximum effective range of the weapon
{
return m_iRange * LIGHT_SECOND;
}
Metric CCyberDeckClass::GetMaxRange (CItemCtx &ItemCtx)
// GetMaxEffectiveRange
//
// Returns the maximum effective range of the weapon
{
return m_iRange * LIGHT_SECOND;
}
void CCyberDeckClass::GetSelectedVariantInfo (CSpaceObject *pSource,
CInstalledDevice *pDevice,
CString *retsLabel,
int *retiAmmoLeft,
CItemType **retpType)
// GetSelectedVariantInfo
//
// Returns weapons info
{
if (retsLabel)
*retsLabel = CString();
if (retiAmmoLeft)
*retiAmmoLeft = -1;
if (retpType)
*retpType = GetItemType();
}
int CCyberDeckClass::GetWeaponEffectiveness (CSpaceObject *pSource, CInstalledDevice *pDevice, CSpaceObject *pTarget)
// GetWeaponEffectiveness
//
// Returns:
//
// < 0 If the weapon is ineffective against the target
// 0 If the weapon has normal effect on target
// 1-100 If the weapon is particularly effective against the target
//
// This call is used to figure out whether we should use an EMP or blinder
// cannon against the target.
{
if (pTarget == NULL)
return 0;
switch (m_Program.iProgram)
{
case progShieldsDown:
{
// If the target's shields are down then this weapon is not
// very effective
int iLevel = pTarget->GetShieldLevel();
if (iLevel <= 0)
return -100;
else
return iLevel;
}
case progDisarm:
return ((pTarget->IsDisarmed() || pTarget->IsParalyzed()) ? -100 : 100);
default:
return 0;
}
}
bool CCyberDeckClass::IsWeaponAligned (CSpaceObject *pShip,
CInstalledDevice *pDevice,
CSpaceObject *pTarget,
int *retiAimAngle,
int *retiFireAngle)
// IsWeaponAligned
//
// Return TRUE if weapon is aligned on target.
//
// Note: If the weapon is invalid, we return an aim angle of -1
{
// We must return an aim angle, if we are asked for it.
int iAim = VectorToPolar(pTarget->GetPos() - pDevice->GetPos(pShip));
if (retiAimAngle)
*retiAimAngle = iAim;
if (retiFireAngle)
*retiFireAngle = iAim;
// CyberDecks are always aligned
return true;
}
CString CCyberDeckClass::OnGetReference (CItemCtx &Ctx, const CItem &Ammo, DWORD dwFlags)
// GetReference
//
// Returns reference information
{
return strPatternSubst("%s (%d)",
m_Program.sProgramName,
m_Program.iAILevel);
}