-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathSDamageCtx.cpp
178 lines (134 loc) · 3.8 KB
/
SDamageCtx.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
// SDamageCtx.cpp
//
// SDamageCtx class
// Copyright (c) 2018 Kronosaur Productions, LLC. All Rights Reserved.
#include "PreComp.h"
SDamageCtx::SDamageCtx (CSpaceObject *pObjHitArg,
CWeaponFireDesc *pDescArg,
const CItemEnhancementStack *pEnhancementsArg,
CDamageSource &AttackerArg,
CSpaceObject *pCauseArg,
int iDirectionArg,
const CVector &vHitPosArg,
int iDamageArg) :
pObj(pObjHitArg),
pDesc(pDescArg),
iDirection(iDirectionArg),
vHitPos(vHitPosArg),
pCause(pCauseArg),
Attacker(AttackerArg),
iDamage(iDamageArg)
// SDamageCtx constructor
//
// NOTE: This initializes SDamageCtx in preparation for calling pObjHit->Damage.
// All such calls should go through this constructor.
{
// Initialize damage structure
Damage = pDescArg->GetDamage();
if (pEnhancementsArg)
Damage.AddEnhancements(pEnhancementsArg);
Damage.SetCause(AttackerArg.GetCause());
if (AttackerArg.IsAutomatedWeapon())
Damage.SetAutomatedWeapon();
// Roll damage
if (iDamage == -1)
iDamage = Damage.RollDamage();
// Initialize damage effects
InitDamageEffects(Damage);
}
SDamageCtx::SDamageCtx (const DamageDesc &DamageArg)
// SDamageCtx constructor
{
// Initialize a descriptor
pDesc = new CWeaponFireDesc;
m_bFreeDesc = true;
pDesc->InitFromDamage(DamageArg);
// Roll damage
Damage = DamageArg;
iDamage = Damage.RollDamage();
// Initialize damage effects
InitDamageEffects(Damage);
}
SDamageCtx::~SDamageCtx (void)
// SDamageCtx destructor
{
if (m_bFreeDesc)
delete pDesc;
}
void SDamageCtx::InitDamageEffects (const DamageDesc &DamageArg)
// InitDamageEffects
//
// Initialiazes damage effects. NOTE: Callers will later check immunities, etc.
// and clear out or alter some of these damage effects.
{
// Blinding
int iBlinding = DamageArg.GetBlindingDamage();
if (iBlinding)
{
// The chance of being blinded is dependent
// on the rating.
int iChance = 4 * iBlinding * iBlinding;
m_bBlind = (mathRandom(1, 100) <= iChance);
m_iBlindTime = iDamage * g_TicksPerSecond / 2;
}
else
m_bBlind = false;
// Radiation
m_bRadioactive = (DamageArg.GetRadiationDamage() > 0);
// EMP
int iEMP = DamageArg.GetEMPDamage();
if (iEMP)
{
// The chance of being paralyzed is dependent
// on the EMP rating.
int iChance = 4 * iEMP * iEMP;
m_bParalyze = (mathRandom(1, 100) <= iChance);
m_iParalyzeTime = iDamage * g_TicksPerSecond / 2;
}
else
m_bParalyze = false;
// Device disrupt
int iDeviceDisrupt = DamageArg.GetDeviceDisruptDamage();
if (iDeviceDisrupt)
{
// The chance of damaging a device depends on the rating.
int iChance = 4 * iDeviceDisrupt * iDeviceDisrupt;
m_bDeviceDisrupt = (mathRandom(1, 100) <= iChance);
m_iDisruptTime = 2 * iDamage * g_TicksPerSecond;
}
else
m_bDeviceDisrupt = false;
// Device damage
int iDeviceDamage = DamageArg.GetDeviceDamage();
if (iDeviceDamage)
{
// The chance of damaging a device depends on the rating.
int iChance = 4 * iDeviceDamage * iDeviceDamage;
m_bDeviceDamage = (mathRandom(1, 100) <= iChance);
}
else
m_bDeviceDamage = false;
// Disintegration
int iDisintegration = DamageArg.GetDisintegrationDamage();
if (iDisintegration)
{
// The chance of being disintegrated is dependent on the rating.
// Since disintegration is from 1 to 7, chance is from 4 to 100.
int iChance = (2 * iDisintegration * iDisintegration) + 2;
m_bDisintegrate = (mathRandom(1, 100) <= iChance);
}
else
m_bDisintegrate = false;
// Shatter
int iShatter = DamageArg.GetShatterDamage();
if (iShatter)
{
// Compute the threshold mass. Below this size, we shatter the object
int iMassLimit = 10 * mathPower(5, iShatter);
m_bShatter = (pObj && pObj->GetMass() < iMassLimit);
}
else
m_bShatter = false;
// Time Stop
m_bTimeStop = (DamageArg.GetTimeStopDamageLevel() > 0);
}