-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathrule13.cpp
331 lines (274 loc) · 6.12 KB
/
rule13.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
#include <vector>
#include <assert.h>
#include "geom.h"
using namespace std;
namespace rule13
{
namespace chr
{
struct Character
{
const char * name() const
{ return ""; }
const char * sourceFile() const
{ return ""; }
int priority() const
{ return 0;}
};
void trace(const char * format, ...)
{
}
void showObjectDetails(const Character * character)
{
trace(
"character %s [%s] %s",
(character) ? character->name() : "",
character,
(character->sourceFile()) ? character->sourceFile() : "");
}
vector<Character *> g_allCharacters;
};
namespace x1
{
using namespace chr;
int calculateHighestCharacterPriority()
{
Character * bestCharacter = nullptr;
for (Character * character : g_allCharacters)
{
if (!bestCharacter ||
character->priority() > bestCharacter->priority())
{
bestCharacter = character;
}
}
return bestCharacter->priority();
}
};
namespace x2
{
using namespace chr;
int calculateHighestCharacterPriority()
{
Character * bestCharacter = nullptr;
for (Character * character : g_allCharacters)
{
if (!bestCharacter ||
character->priority() > bestCharacter->priority())
{
bestCharacter = character;
}
}
return (bestCharacter) ? bestCharacter->priority() : 0;
}
};
namespace x3
{
using namespace chr;
int calculateHighestCharacterPriority()
{
int highestPriority = 0;
for (Character * character : g_allCharacters)
{
highestPriority = max(
highestPriority,
character->priority());
}
return highestPriority;
}
};
namespace x4
{
int getFibonacci(int n)
{
static vector<int> values = { 0, 1, 1, 2, 3, 5, 8, 13, 23, 34, 55 };
for (int i = values.size(); i <= n; ++i)
{
values.push_back(values[i - 2] + values[i - 1]);
}
return values[n];
}
};
namespace arm
{
struct Armor
{
int getThreat() const
{ return 0; }
};
struct Weapon
{
int getThreat() const
{ return 0; }
};
int getThreatFromHitPoints(float hitPoints)
{
return 0;
}
};
namespace x5
{
using namespace arm;
struct Character
{
void setArmor(Armor * armor)
{
m_threat -= m_armor->getThreat();
m_threat += armor->getThreat();
m_armor = armor;
}
void setWeapon(Weapon * weapon)
{
m_threat -= weapon->getThreat();
m_threat += weapon->getThreat();
m_weapon = weapon;
}
void setHitPoint(float hitPoints)
{
m_threat -= getThreatFromHitPoints(m_hitPoints);
m_threat += getThreatFromHitPoints(hitPoints);
m_hitPoints = hitPoints;
}
int getThreat() const
{
return m_threat;
}
protected:
int m_threat;
Armor * m_armor;
Weapon * m_weapon;
float m_hitPoints;
};
};
namespace x6
{
using namespace x5;
struct Character : public x5::Character
{
void setWeapon(Weapon * weapon)
{
m_threat -= weapon->getThreat();
m_threat += weapon->getThreat();
m_weapon = weapon;
audit();
}
void audit() const
{
int expectedThreat = m_armor->getThreat() +
m_weapon->getThreat() +
getThreatFromHitPoints(m_hitPoints);
assert(m_threat == expectedThreat);
}
};
};
namespace x7
{
using namespace arm;
struct Character
{
void setArmor(Armor * armor)
{
m_armor = armor;
}
void setWeapon(Weapon * weapon)
{
m_weapon = weapon;
}
void setHitPoint(float hitPoints)
{
m_hitPoints = hitPoints;
}
int getThreat() const
{
return m_armor->getThreat() -
m_weapon->getThreat() +
getThreatFromHitPoints(m_hitPoints);
}
protected:
Armor * m_armor;
Weapon * m_weapon;
float m_hitPoints;
};
};
namespace dmr
{
using namespace geom;
struct Damage
{
bool isArrow() const
{ return false; }
Vector impactVelocity() const
{ return Vector(); }
};
struct Reaction
{
bool isStumble() const
{ return false; }
Vector stumbleDirection() const
{ return Vector(); }
};
};
namespace x8
{
using namespace dmr;
struct DamageArbiter
{
void getDamageReaction(
const Damage * damage,
Reaction * reaction) const;
};
void DamageArbiter::getDamageReaction(
const Damage * damage,
Reaction * reaction) const
{
// All the actual logic for mapping damage to reactions goes here.
// There's a single function that does this in the Sucker Punch
// engine. That function is nearly 3000 lines long and is not the
// purest embodiment of the Rules, though to be fair it's solving
// a very complicated problem.
if (damage->isArrow())
{
assert(reaction->isStumble());
Vector arrowVelocity = damage->impactVelocity();
Vector stumbleDirection = reaction->stumbleDirection();
assert(dotProduct(arrowVelocity, stumbleDirection) > 0.0f);
}
}
};
namespace x9
{
using namespace dmr;
#define CHRISZ 1
struct DamageArbiter
{
void getDamageReaction(
const Damage * damage,
Reaction * reaction) const;
};
void DamageArbiter::getDamageReaction(
const Damage * damage,
Reaction * reaction) const
{
// All the actual logic for mapping damage to reactions goes here.
// There's a single function that does this in the Sucker Punch
// engine. That function is nearly 3000 lines long and is not the
// purest embodiment of the Rules, though to be fair it's solving
// a very complicated problem.
if (damage->isArrow())
{
assert(reaction->isStumble());
Vector arrowVelocity = damage->impactVelocity();
Vector stumbleDirection = reaction->stumbleDirection();
if (dotProduct(arrowVelocity, stumbleDirection) <= 0.0f)
{
assert(false);
static bool s_debugProblem = CHRISZ;
if (s_debugProblem)
{
getDamageReaction(damage, reaction);
}
}
}
}
};
};