Repository navigation
Expand file tree
/
Copy pathmain.cpp
More file actions
403 lines (328 loc) · 13.9 KB
/
Copy pathmain.cpp
File metadata and controls
403 lines (328 loc) · 13.9 KB
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
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
#include <iostream>
#include <sstream>
#include "Engine/definitions/Entity.h"
#include <memory>
#include "Engine/definitions/BattleContext.h"
#include "Engine/definitions/Action.h"
#include "Engine/definitions/WorldMap.h"
#include "Engine/compilers/scene_compiler/Scanner.h"
#include "Engine/managers/TurnManager.h"
#include "Engine/managers/SceneRunner.h"
#include "Engine/helpers/ConsoleUI.h"
void printDivider() {
std::cout << "----------------------------------------" << std::endl;
}
void printGrandDivider() {
std::cout << "--<<(<-|[->{<O>}<-]|-->)>>--" << std::endl;
}
void printInitiativeResult(const Entity& first, const Entity& second) {
std::cout << "[INITIATIVE CHECK]" << std::endl;
std::cout << first.getName() << " speed: " << first.getSpeVal() << std::endl;
std::cout << second.getName() << " speed: " << second.getSpeVal() << std::endl;
if (first.getSpeVal() >= second.getSpeVal()) {
std::cout << "Result: " << first.getName() << " would act first." << std::endl;
} else {
std::cout << "Result: " << second.getName() << " would act first." << std::endl;
}
}
void printSpeedTest(Entity& entity) {
printDivider();
std::cout << "[TEMPORARY EFFECT TEST]" << std::endl;
std::cout << "Target entity: " << entity.getName() << std::endl;
std::cout << "Base speed: " << entity.getSpeVal() << std::endl;
entity.addEffect(std::make_unique<Impulse1Effect>());
std::cout << "After applying Impulse1Effect: " << entity.getSpeVal() << std::endl;
entity.onTurnEnd();
std::cout << "After first turn ends: " << entity.getSpeVal() << std::endl;
entity.onTurnEnd();
std::cout << "After second turn ends: " << entity.getSpeVal() << std::endl;
std::cout << "Expected behavior: speed increases temporarily, then returns to base value."
<< std::endl;
}
void printAbilityActivation(Entity& entity) {
std::cout << "[ABILITY ACTIVATION TEST]" << std::endl;
std::cout << "Target entity: " << entity.getName() << std::endl;
std::cout << "Base speed: " << entity.getSpeVal() << std::endl;
std::cout << "Attempting to cast: Impulse1" << std::endl;
Impulse1Ability instance = {"Impulse1", 3};
instance.execute(&entity, &entity);
std::cout << "After applying Impulse1Effect: " << entity.getSpeVal() << std::endl;
entity.onTurnEnd();
std::cout << "After first turn ends: " << entity.getSpeVal() << std::endl;
entity.onTurnEnd();
std::cout << "After second turn ends: " << entity.getSpeVal() << std::endl;
}
void printAbilityActivation_2(Entity& caster, Entity& target, size_t abilityIndex) {
std::cout << "[ABILITY ACTIVATION TEST 2]\n";
std::cout << "Caster: " << caster.getName() << " | HP: " << caster.getCurrentHP()
<< " | Speed: " << caster.getSpeVal() << "\n";
std::cout << "Target: " << target.getName() << " | HP: " << target.getCurrentHP()
<< " | Speed: " << target.getSpeVal() << "\n";
Ability* ab = caster.chooseAbility(abilityIndex);
if (!ab) {
std::cout << "ERROR: caster has no ability at index " << abilityIndex << "\n";
return;
}
auto printAbilityState = [&](const char* label) {
std::cout << label << " '" << ab->getName() << "'"
<< " | ready=" << (ab->isReady() ? "yes" : "no")
<< " | current_cd=" << ab->getCurrentCooldown()
<< " | base_cd=" << ab->getCooldown()
<< "\n";
};
printAbilityState("Before use:");
if (!ab->isReady()) {
std::cout << "Ability not ready; skipping execute.\n";
} else {
std::cout << "Executing...\n";
ab->execute(&caster, &target);
// Start cooldown AFTER a successful use
ab->startCooldown();
printAbilityState("After use:");
}
// Demonstrate cooldown ticking via onTurnEnd()
int steps = ab->getCooldown() + 2; // +2 so you can see it return to ready
for (int turn = 1; turn <= steps; ++turn) {
caster.onTurnEnd(); // this should call ability->tickCooldown() internally
std::cout << "After caster.onTurnEnd() tick " << turn << ": ";
std::cout << "ready=" << (ab->isReady() ? "yes" : "no")
<< " current_cd=" << ab->getCurrentCooldown()
<< "\n";
}
std::cout << "Final HP | Caster: " << caster.getCurrentHP()
<< " | Target: " << target.getCurrentHP() << "\n";
}
void printBattleSimulation(Entity& entity_1, Entity& entity_2) {
std::vector<Entity*> player_party;
std::vector<Entity*> enemy_party;
player_party.push_back(&entity_1);
enemy_party.push_back(&entity_2);
}
void printDeadStateVerification(Entity& suggested_entity) {
if(suggested_entity.isEntityAlive()) {
std::cout << "Entity " << suggested_entity.getName() << " is alive!" << std::endl;
}
else {
std:: cout << "Entity " << suggested_entity.getName() << " is dead!" << std::endl;
}
}
void printBattleContextTest() {
printGrandDivider();
std::cout << "[BATTLE CONTEXT TEST START]" << std::endl;
printDivider();
// Create test entities
Entity hero("Hero", 100, 20, 12, 18);
Entity mage("Mage", 80, 14, 8, 22);
Entity goblin("Goblin", 55, 11, 6, 16);
Entity brute("Brute", 120, 18, 14, 10);
// Give some abilities
hero.addAbility(std::make_unique<BasicAttackAbility>("Basic Attack", 0));
hero.addAbility(std::make_unique<Impulse1Ability>("Impulse1", 3));
mage.addAbility(std::make_unique<BasicAttackAbility>("Basic Attack", 0));
mage.addAbility(std::make_unique<Impulse1Ability>("Impulse1", 3));
goblin.addAbility(std::make_unique<BasicAttackAbility>("Basic Attack", 0));
brute.addAbility(std::make_unique<BasicAttackAbility>("Basic Attack", 0));
// Get battle instance and reset it
BattleContext& battle = BattleContext::getInstance();
battle.resetBattle();
// Register combatants
battle.addAllyActor(&hero);
battle.addAllyActor(&mage);
battle.addEnemyActor(&goblin);
battle.addEnemyActor(&brute);
// Access turn manager
TurnManager& manager = battle.getTurnManager();
// Queue one round of actions
// priority, speed snapshot, tie breaker are assumed to be handled by your Action constructor
manager.queuePlannedAction(Action(
ActionType::Attack,
&hero,
&goblin,
hero.chooseAbility(0),
0,
hero.getSpeVal(),
0
));
manager.queuePlannedAction(Action(
ActionType::Defend,
&mage,
&mage,
nullptr,
0,
mage.getSpeVal(),
1
));
manager.queuePlannedAction(Action(
ActionType::Attack,
&goblin,
&hero,
goblin.chooseAbility(0),
0,
goblin.getSpeVal(),
2
));
manager.queuePlannedAction(Action(
ActionType::Attack,
&brute,
&hero,
brute.chooseAbility(0),
0,
brute.getSpeVal(),
3
));
// Print pre-turn state
std::cout << "[PRE-TURN STATE]" << std::endl;
std::cout << hero.getName() << " HP: " << hero.getCurrentHP() << std::endl;
std::cout << mage.getName() << " HP: " << mage.getCurrentHP() << std::endl;
std::cout << goblin.getName() << " HP: " << goblin.getCurrentHP() << std::endl;
std::cout << brute.getName() << " HP: " << brute.getCurrentHP() << std::endl;
printDivider();
// Process turn
battle.processTurn();
printDivider();
std::cout << "[POST-TURN STATE]" << std::endl;
std::cout << hero.getName() << " HP: " << hero.getCurrentHP() << std::endl;
std::cout << mage.getName() << " HP: " << mage.getCurrentHP() << std::endl;
std::cout << goblin.getName() << " HP: " << goblin.getCurrentHP() << std::endl;
std::cout << brute.getName() << " HP: " << brute.getCurrentHP() << std::endl;
printDivider();
std::cout << "[BATTLE STATUS]" << std::endl;
std::cout << "Turn count: " << battle.getTurnCount() << std::endl;
std::cout << "Battle finished? " << (battle.isBattleFinished() ? "yes" : "no") << std::endl;
std::cout << "Allies win? " << (battle.didAlliesWin() ? "yes" : "no") << std::endl;
std::cout << "Enemies win? " << (battle.didEnemiesWin() ? "yes" : "no") << std::endl;
std::cout << "Escape success? " << (battle.didEscapeSucceed() ? "yes" : "no") << std::endl;
printDivider();
std::cout << "[ENTITY STATE CHECK]" << std::endl;
printDeadStateVerification(hero);
printDeadStateVerification(mage);
printDeadStateVerification(goblin);
printDeadStateVerification(brute);
printGrandDivider();
std::cout << "[BATTLE CONTEXT TEST END]" << std::endl;
}
void printWorldMapTest() {
printGrandDivider();
std::cout << "[WORLD MAP TEST START]" << std::endl;
printDivider();
Node town(NodeType::Safe, "town", "Town", "A quiet settlement near the valley.");
Node forest(NodeType::Wilderness, "forest", "Forest", "A dense forest with unstable paths.");
Node ruins(NodeType::Outlands, "ruins", "Ruins", "Broken stone halls under a cold mist.");
WorldMap world_map({&town, &forest, &ruins}, &town, "Demo World");
world_map.connectNodes(&town, &forest, 8);
world_map.connectNodes(&forest, &ruins, 16);
std::cout << "[WORLD NODE LIST]" << std::endl;
std::cout << world_map.getWorldNodesList();
printDivider();
std::cout << "[CURRENT NODE]" << std::endl;
std::cout << world_map.currentNodeInfo();
printDivider();
std::cout << "[NEIGHBORING NODES]" << std::endl;
std::cout << world_map.currentNeighborList();
printDivider();
std::cout << "[TRAVEL TEST]" << std::endl;
WorldMap::TravelResult result = world_map.travelToNeighbor(0);
std::cout << "Valid path? " << (result.valid_path ? "yes" : "no") << std::endl;
std::cout << "Moved? " << (result.moved ? "yes" : "no") << std::endl;
std::cout << "Travel cost: " << result.travel_cost << std::endl;
std::cout << "Encounter rolls: " << result.encounter_rolls << std::endl;
std::cout << "Encounter triggered? " << (result.encounter_triggered ? "yes" : "no") << std::endl;
std::cout << "Final encounter chance checked: " << result.final_encounter_chance << std::endl;
std::cout << "Current node after travel: "
<< (world_map.getCurrentNode() ? world_map.getCurrentNode()->getNodeName() : "none")
<< std::endl;
printGrandDivider();
std::cout << "[WORLD MAP TEST END]" << std::endl;
}
void printSceneSystemTest() {
printGrandDivider();
std::cout << "[SCENE SYSTEM TEST START]" << std::endl;
printDivider();
std::string scene_source = R"(
# Demo scene script
music play "quiet_ruins"
narrate "The road sinks into a cold valley."
say "Hero" "This place feels wrong."
goto enter_ruins
narrate "This line should be skipped by the goto command."
label enter_ruins
battle "ruin_guardian"
map warp "town"
music stop
end
)";
try {
SceneScript script = Scanner::parse(scene_source);
std::cout << "Parsed commands: " << script.commands.size() << std::endl;
std::cout << "Parsed labels: " << script.labels.size() << std::endl;
printDivider();
std::cout << "[SCENE RUNNER OUTPUT]" << std::endl;
SceneRunner runner(std::cout, false);
runner.run(script);
}
catch (const std::exception& error) {
std::cout << "Scene test failed: " << error.what() << std::endl;
}
printGrandDivider();
std::cout << "[SCENE SYSTEM TEST END]" << std::endl;
}
void printConsoleUITest() {
printGrandDivider();
std::cout << "[CONSOLE UI TEST START]" << std::endl;
printDivider();
std::istringstream scripted_input("2\n1\n");
ConsoleUI ui(scripted_input, std::cout);
Node town(NodeType::Safe, "town", "Town", "A quiet settlement.");
Node forest(NodeType::Wilderness, "forest", "Forest", "A dangerous forest.");
WorldMap world_map({&town, &forest}, &town, "UI Test World");
world_map.connectNodes(&town, &forest, 4);
ui.printCurrentNode(world_map);
ui.printNeighboringNodes(world_map);
MapMenuOption map_choice = ui.promptMapMenu();
std::cout << "Scripted map menu choice: " << static_cast<int>(map_choice) << std::endl;
printDivider();
Entity hero("UI Hero", 100, 20, 10, 12);
Entity enemy("UI Enemy", 60, 14, 6, 8);
BattleContext& battle = BattleContext::getInstance();
battle.resetBattle();
battle.addAllyActor(&hero);
battle.addEnemyActor(&enemy);
ui.printBattleState(battle);
Entity* chosen_participant = ui.promptParticipantChoice(battle);
std::cout << "Scripted participant choice: "
<< (chosen_participant ? chosen_participant->getName() : "none")
<< std::endl;
printGrandDivider();
std::cout << "[CONSOLE UI TEST END]" << std::endl;
}
int main() {
std::cout << "[ENGINE TEST START]" << std::endl;
printDivider();
Entity player("test_player", 100, 18, 14, 20);
Entity enemy("test_enemy", 85, 9, 10, 25);
std::cout << "[ENTITY LOAD]" << std::endl;
std::cout << "Loaded entity: " << player.getName() << std::endl;
std::cout << "Loaded entity: " << enemy.getName() << std::endl;
printDivider();
printInitiativeResult(player, enemy);
printSpeedTest(player);
printDivider();
printAbilityActivation(player);
printDivider();
player.addAbility(std::make_unique<Impulse1Ability>("Impulse1", 3));
player.addAbility(std::make_unique<BasicAttackAbility>("Basic Attack", 0));
printAbilityActivation_2(player, player, 0); // cast Impulse1 on self
printAbilityActivation_2(player, enemy, 1); // basic attack enemy
printDivider();
printDeadStateVerification(enemy);
printDivider();
enemy.takeDamage(99999);
printDeadStateVerification(enemy);
printDivider();
printBattleContextTest();
printWorldMapTest();
printSceneSystemTest();
printConsoleUITest();
std::cout << "[ENGINE TEST END]" << std::endl;
return 0;
}