Rituals are now being added a belt on the player in a temp function in LevelManager.

master
Zed A. Shaw 2 days ago
parent a70f11646a
commit 00c28f47eb
  1. 2
      Makefile
  2. 2
      gui_fsm.cpp
  3. 19
      levelmanager.cpp
  4. 2
      levelmanager.hpp
  5. 11
      rituals.cpp
  6. 1
      rituals.hpp
  7. 114
      tests/rituals.cpp
  8. 2
      worldbuilder.cpp

@ -41,7 +41,7 @@ clean:
meson compile --clean -C builddir meson compile --clean -C builddir
debug_test: build debug_test: build
gdb --nx -x .gdbinit --ex run --args builddir/runtests.exe -e gdb --nx -x .gdbinit --ex run --args builddir/runtests.exe -e "[rituals-belt]"
win_installer: win_installer:
powershell 'start "C:\Program Files (x86)\solicus\InstallForge\bin\ifbuilderenvx86.exe" win_installer.ifp' powershell 'start "C:\Program Files (x86)\solicus\InstallForge\bin\ifbuilderenvx86.exe" win_installer.ifp'

@ -24,6 +24,7 @@ namespace gui {
$mini_map($level), $mini_map($level),
$font{FONT_FILE_NAME} $font{FONT_FILE_NAME}
{ {
$levels.temp_create_player_rituals();
} }
void FSM::event(Event ev) { void FSM::event(Event ev) {
@ -41,6 +42,7 @@ namespace gui {
} }
void FSM::START(Event ) { void FSM::START(Event ) {
$main_ui.update_level($level); $main_ui.update_level($level);
$level.world->set_the<Debug>({}); $level.world->set_the<Debug>({});
$main_ui.init(); $main_ui.init();

@ -4,6 +4,7 @@
#include "save.hpp" #include "save.hpp"
#include "systems.hpp" #include "systems.hpp"
#include "components.hpp" #include "components.hpp"
#include "rituals.hpp"
using lighting::LightRender; using lighting::LightRender;
using std::shared_ptr, std::make_shared; using std::shared_ptr, std::make_shared;
@ -21,6 +22,24 @@ LevelScaling LevelManager::scale_level() {
}; };
} }
void LevelManager::temp_create_player_rituals() {
auto& level = current();
auto player = level.player;
auto& the_belt = level.world->get<combat::RitualBelt>(player);
combat::RitualEngine re("assets/rituals.json");
auto blanket = re.start();
re.set_state(blanket, "has_magick", true);
re.plan(blanket);
auto ritual = re.finalize(blanket);
the_belt.equip(0, ritual);
blanket = re.start();
re.set_state(blanket, "has_spikes", true);
re.plan(blanket);
ritual = re.finalize(blanket);
the_belt.equip(1, ritual);
}
inline shared_ptr<DinkyECS::World> clone_load_world(shared_ptr<DinkyECS::World> prev_world) inline shared_ptr<DinkyECS::World> clone_load_world(shared_ptr<DinkyECS::World> prev_world)
{ {

@ -42,5 +42,7 @@ class LevelManager {
GameLevel &get(size_t index); GameLevel &get(size_t index);
LevelScaling scale_level(); LevelScaling scale_level();
void temp_create_player_rituals();
DinkyECS::Entity spawn_enemy(std::string named); DinkyECS::Entity spawn_enemy(std::string named);
}; };

@ -46,6 +46,10 @@ namespace combat {
} }
void RitualEngine::set_state(RitualAI& ritual, std::string name, bool setting) { void RitualEngine::set_state(RitualAI& ritual, std::string name, bool setting) {
dbc::check($profile.contains(name),
fmt::format("ritual action named {} is not in profile, look in {} config",
name, $config.$src_path));
ritual.start.set($profile.at(name), setting); ritual.start.set($profile.at(name), setting);
} }
@ -69,10 +73,17 @@ namespace combat {
return result; return result;
} }
// BUG: maybe this should be called RitualBlanket instead?
void RitualAI::dump() { void RitualAI::dump() {
ai::dump_script(script, start, plan.script); ai::dump_script(script, start, plan.script);
} }
bool RitualAI::is_combined() {
dbc::check(!plan.script.empty(), "you are attempting to check an empty plan");
auto& last = plan.script.back();
return plan.script.size() > 1 && last.name == "combined";
}
RitualAction RitualEngine::finalize(RitualAI& ritual) { RitualAction RitualEngine::finalize(RitualAI& ritual) {
(void)ritual; (void)ritual;

@ -23,6 +23,7 @@ namespace combat {
bool will_do(std::string name); bool will_do(std::string name);
void dump(); void dump();
ai::Action pop(); ai::Action pop();
bool is_combined();
}; };
enum class RitualElement { enum class RitualElement {

@ -3,86 +3,92 @@
#include "rituals.hpp" #include "rituals.hpp"
#include "fsm.hpp" #include "fsm.hpp"
#include "dinkyecs.hpp" #include "dinkyecs.hpp"
#include "levelmanager.hpp"
using namespace combat; using namespace combat;
TEST_CASE("RitualEngine basic tests", "[rituals]") { TEST_CASE("RitualEngine basic tests", "[rituals]") {
RitualEngine re("assets/rituals.json"); RitualEngine re("assets/rituals.json");
auto ritual = re.start(); auto blanket = re.start();
re.set_state(ritual, "has_spikes", true); re.set_state(blanket, "has_spikes", true);
re.plan(ritual); re.plan(blanket);
fmt::println("\n\n------------ TEST WILL DO PIERCE"); fmt::println("\n\n------------ TEST WILL DO PIERCE");
ritual.dump(); blanket.dump();
REQUIRE(ritual.will_do("pierce_type")); REQUIRE(blanket.will_do("pierce_type"));
REQUIRE(ritual.start != ritual.original); REQUIRE(blanket.start != blanket.original);
re.reset(ritual); re.reset(blanket);
REQUIRE(ritual.start == ritual.original); REQUIRE(blanket.start == blanket.original);
re.set_state(ritual, "has_magick", true); re.set_state(blanket, "has_magick", true);
re.set_state(ritual, "has_spikes", true); re.set_state(blanket, "has_spikes", true);
re.plan(ritual); re.plan(blanket);
fmt::println("\n\n------------ TEST WILL DO MAGICK TOO"); fmt::println("\n\n------------ TEST WILL DO MAGICK TOO");
ritual.dump(); blanket.dump();
REQUIRE(ritual.will_do("pierce_type")); REQUIRE(blanket.will_do("pierce_type"));
ritual.pop(); blanket.pop();
REQUIRE(ritual.will_do("magick_type")); REQUIRE(blanket.will_do("magick_type"));
re.reset(ritual); re.reset(blanket);
re.set_state(ritual, "has_magick", true); re.set_state(blanket, "has_magick", true);
re.set_state(ritual, "has_spikes", true); re.set_state(blanket, "has_spikes", true);
re.set_state(ritual, "shiny_bauble", true); re.set_state(blanket, "shiny_bauble", true);
re.plan(ritual); REQUIRE(blanket.is_combined());
re.plan(blanket);
fmt::println("\n\n------------ TEST WILL DO DAMAGE BOOST"); fmt::println("\n\n------------ TEST WILL DO DAMAGE BOOST");
ritual.dump(); blanket.dump();
re.reset(ritual); re.reset(blanket);
re.set_state(ritual, "has_magick", true); re.set_state(blanket, "has_magick", true);
re.set_state(ritual, "cursed_item", true); re.set_state(blanket, "cursed_item", true);
re.set_state(ritual, "shiny_bauble", true); re.set_state(blanket, "shiny_bauble", true);
re.plan(ritual); REQUIRE(blanket.is_combined());
re.plan(blanket);
fmt::println("\n\n------------ TEST WILL DO LARGE DAMAGE BOOST"); fmt::println("\n\n------------ TEST WILL DO LARGE DAMAGE BOOST");
ritual.dump(); blanket.dump();
} }
TEST_CASE("rituals can be finalized for the end result", "[rituals]") { TEST_CASE("blanket can be finalized for the end result", "[rituals]") {
RitualEngine re("assets/rituals.json"); RitualEngine re("assets/rituals.json");
auto plan = re.start(); auto blanket = re.start();
re.set_state(plan, "has_magick", true); re.set_state(blanket, "has_magick", true);
re.set_state(plan, "cursed_item", true); re.set_state(blanket, "cursed_item", true);
re.set_state(plan, "shiny_bauble", true); re.set_state(blanket, "shiny_bauble", true);
re.plan(plan); re.plan(blanket);
REQUIRE(blanket.is_combined());
fmt::println("\n\n------------ CYCLES AVOIDED"); fmt::println("\n\n------------ CYCLES AVOIDED");
plan.dump(); blanket.dump();
auto action = re.finalize(plan); auto ritual = re.finalize(blanket);
action.dump(); ritual.dump();
} }
TEST_CASE("the ritual belt works", "[rituals-belt]") { TEST_CASE("the ritual belt works", "[rituals-belt]") {
RitualBelt the_belt; RitualBelt the_belt;
RitualEngine re("assets/rituals.json"); RitualEngine re("assets/rituals.json");
auto plan = re.start(); auto blanket = re.start();
re.set_state(plan, "has_magick", true); re.set_state(blanket, "has_magick", true);
re.plan(plan); re.plan(blanket);
REQUIRE(blanket.is_combined());
blanket.dump();
{ {
auto action = re.finalize(plan); auto ritual = re.finalize(blanket);
the_belt.equip(0, action); the_belt.equip(0, ritual);
REQUIRE(the_belt.has(0)); REQUIRE(the_belt.has(0));
} }
{ {
auto action = the_belt.get(0); auto ritual = the_belt.get(0);
action.dump(); ritual.dump();
} }
{ {
@ -90,3 +96,19 @@ TEST_CASE("the ritual belt works", "[rituals-belt]") {
REQUIRE(!the_belt.has(0)); REQUIRE(!the_belt.has(0));
} }
} }
TEST_CASE("LevelManager makes a temp belt", "[rituals-belt]") {
LevelManager lm;
lm.temp_create_player_rituals();
auto& level = lm.current();
auto& the_belt = level.world->get<RitualBelt>(level.player);
REQUIRE(the_belt.has(0));
auto& ritual = the_belt.get(0);
REQUIRE(ritual.damage > 0);
REQUIRE(the_belt.has(1));
ritual = the_belt.get(1);
REQUIRE(ritual.damage > 1);
}

@ -4,6 +4,7 @@
#include <iostream> #include <iostream>
#include "components.hpp" #include "components.hpp"
#include "inventory.hpp" #include "inventory.hpp"
#include "rituals.hpp"
using namespace fmt; using namespace fmt;
using namespace components; using namespace components;
@ -257,6 +258,7 @@ void WorldBuilder::place_entities(DinkyECS::World &world) {
// configure player in the world // configure player in the world
Player player{player_ent}; Player player{player_ent};
world.set_the<Player>(player); world.set_the<Player>(player);
world.set<combat::RitualBelt>(player.entity, {});
world.set<Inventory>(player.entity, {5}); world.set<Inventory>(player.entity, {5});
world.make_constant(player.entity); world.make_constant(player.entity);
} }

Loading…
Cancel
Save