From a8bcacc95045102e67f2feabbdddf79535837554 Mon Sep 17 00:00:00 2001 From: jacopograndi Date: Thu, 19 Aug 2021 18:46:51 +0200 Subject: forgot to make repo until now --- game/playercontrol.h | 87 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 87 insertions(+) create mode 100644 game/playercontrol.h (limited to 'game/playercontrol.h') diff --git a/game/playercontrol.h b/game/playercontrol.h new file mode 100644 index 0000000..4e66e07 --- /dev/null +++ b/game/playercontrol.h @@ -0,0 +1,87 @@ +#ifndef PLAYERCONTROL_H +#define PLAYERCONTROL_H + +#include + +#include "gst.h" +#include "view.h" +#include +#include + +enum pc_state { + select, + move, + attack, + train, + build, + merge, + trade, + age_up, + heal, + power, + move_target, + attack_target, + menu_train, + menu_build, + target_build, + merge_target, + target_heal, + menu_power, + target_power, + menu_unit, + menu_day, + end +}; + +enum pc_action { + sel_unit, + sel_ground, + opt, + back +}; + + +class Fsm; +using lambda = std::function; + + +class Arc { + public: + Arc (pc_state from, pc_action act, int p, lambda f) + : from(from), act(act), p(p), f(f) {}; + pc_state from; + pc_action act; + int p; + + lambda f; +}; + +class Fsm { + public: + Fsm() { state = select; } + + void transition (Gst &gst, View &view, Fsm &fsm, pc_action act, int p) { + std::cout << "> transitioning from " << state << " with " << act << std::endl; + for (Arc a : arcs) { + if (a.from == state && a.act == act && (a.p == p || a.p == -1)) { + state = a.f(gst, view, fsm, p); + break; + } + } + } + std::vector arcs; + + private: + pc_state state; +}; + + +class Player_control { + public: + Player_control (); + void process (Gst &gst, View &view); + + Fsm fsm; +}; + +#endif \ No newline at end of file -- cgit v1.2.3-54-g00ecf