forked from CleverRaven/Cataclysm-DDA
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdamage.cpp
217 lines (191 loc) · 5.74 KB
/
damage.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
#include "item.h"
#include "monster.h"
#include "game.h"
#include "damage.h"
damage_instance::damage_instance() { }
damage_instance damage_instance::physical(float bash, float cut, float stab, int arpen)
{
damage_instance d;
d.add_damage(DT_BASH, bash, arpen);
d.add_damage(DT_CUT, cut, arpen);
d.add_damage(DT_STAB, stab, arpen);
return d;
}
void damage_instance::add_damage(damage_type dt, float a, int rp, float rm)
{
damage_unit du(dt, a, rp, rm);
damage_units.push_back(du);
}
void damage_instance::add_effect( std::string effect )
{
effects.insert( effect );
}
void damage_instance::mult_damage(double multiplier)
{
for (std::vector<damage_unit>::iterator it = damage_units.begin();
it != damage_units.end(); ++it) {
it->amount *= multiplier;
}
}
float damage_instance::type_damage(damage_type dt) const
{
float ret = 0;
for (std::vector<damage_unit>::const_iterator it = damage_units.begin();
it != damage_units.end(); ++it) {
if (it->type == dt) {
ret += it->amount;
}
}
return ret;
}
float damage_instance::total_damage() const
{
float ret = 0;
for (std::vector<damage_unit>::const_iterator it = damage_units.begin();
it != damage_units.end(); ++it) {
ret += it->amount;
}
return ret;
}
dealt_damage_instance::dealt_damage_instance() : dealt_dams(NUM_DT, 0) { }
//TODO: add check to ensure length
dealt_damage_instance::dealt_damage_instance(std::vector<int> &dealt) : dealt_dams(dealt) { }
void dealt_damage_instance::set_damage(damage_type dt, int amount)
{
dealt_dams[dt] = amount;
}
int dealt_damage_instance::type_damage(damage_type dt) const
{
return dealt_dams[dt];
}
int dealt_damage_instance::total_damage() const
{
return std::accumulate(dealt_dams.begin(), dealt_dams.end(), 0);
}
resistances::resistances() : resist_vals(NUM_DT, 0) { }
resistances::resistances(item &armor) : resist_vals(NUM_DT, 0)
{
if (armor.is_armor()) {
set_resist(DT_BASH, armor.bash_resist());
set_resist(DT_CUT, armor.cut_resist());
set_resist(DT_STAB, 0.8 * armor.cut_resist()); // stab dam cares less bout armor
}
}
resistances::resistances(monster &monster) : resist_vals(NUM_DT, 0)
{
set_resist(DT_BASH, monster.type->armor_bash);
set_resist(DT_CUT, monster.type->armor_cut);
set_resist(DT_STAB, 0.8 * monster.type->armor_cut); // stab dam cares less bout armor
}
void resistances::set_resist(damage_type dt, int amount)
{
resist_vals[dt] = amount;
}
int resistances::type_resist(damage_type dt) const
{
return resist_vals[dt];
}
float resistances::get_effective_resist(const damage_unit &du)
{
float effective_resist = 0.f;
switch (du.type) {
case DT_BASH:
effective_resist = std::max(type_resist(DT_BASH) - du.res_pen, 0) * du.res_mult;
break;
case DT_CUT:
effective_resist = std::max(type_resist(DT_CUT) - du.res_pen, 0) * du.res_mult;
break;
case DT_STAB:
effective_resist = std::max(type_resist(DT_STAB) - du.res_pen, 0) * du.res_mult;
break;
default: // TODO: DT_ACID/HEAT vs env protection, DT_COLD vs warmth
effective_resist = 0;
}
return effective_resist;
}
void ammo_effects(int x, int y, const std::set<std::string> &effects)
{
if (effects.count("EXPLOSIVE")) {
g->explosion(x, y, 24, 0, false);
}
if (effects.count("FRAG")) {
g->explosion(x, y, 12, 28, false);
}
if (effects.count("NAPALM")) {
g->explosion(x, y, 18, 0, true);
}
if (effects.count("NAPALM_BIG")) {
g->explosion(x, y, 72, 0, true);
}
if (effects.count("MININUKE_MOD")) {
g->explosion(x, y, 200, 0, false);
int junk;
for (int i = -4; i <= 4; i++) {
for (int j = -4; j <= 4; j++) {
if (g->m.sees(x, y, x + i, y + j, 3, junk) &&
g->m.move_cost(x + i, y + j) > 0) {
g->m.add_field(x + i, y + j, fd_nuke_gas, 3);
}
}
}
}
if (effects.count("ACIDBOMB")) {
for (int i = x - 1; i <= x + 1; i++) {
for (int j = y - 1; j <= y + 1; j++) {
g->m.add_field(i, j, fd_acid, 3);
}
}
}
if (effects.count("EXPLOSIVE_BIG")) {
g->explosion(x, y, 40, 0, false);
}
if (effects.count("EXPLOSIVE_HUGE")) {
g->explosion(x, y, 80, 0, false);
}
if (effects.count("TEARGAS")) {
for (int i = -2; i <= 2; i++) {
for (int j = -2; j <= 2; j++) {
g->m.add_field(x + i, y + j, fd_tear_gas, 3);
}
}
}
if (effects.count("SMOKE")) {
for (int i = -1; i <= 1; i++) {
for (int j = -1; j <= 1; j++) {
g->m.add_field(x + i, y + j, fd_smoke, 3);
}
}
}
if (effects.count("SMOKE_BIG")) {
for (int i = -6; i <= 6; i++) {
for (int j = -6; j <= 6; j++) {
g->m.add_field(x + i, y + j, fd_smoke, 18);
}
}
}
if (effects.count("FLASHBANG")) {
g->flashbang(x, y);
}
if (effects.count("FLAME")) {
g->explosion(x, y, 4, 0, true);
}
if (effects.count("FLARE")) {
g->m.add_field(x, y, fd_fire, 1);
}
if (effects.count("LIGHTNING")) {
for (int i = x - 1; i <= x + 1; i++) {
for (int j = y - 1; j <= y + 1; j++) {
g->m.add_field(i, j, fd_electricity, 3);
}
}
}
if (effects.count("PLASMA")) {
for (int i = x - 1; i <= x + 1; i++) {
for (int j = y - 1; j <= y + 1; j++) {
if (one_in(2)) {
g->m.add_field(i, j, fd_plasma, rng(2, 3));
}
}
}
}
}