aboutsummaryrefslogtreecommitdiff
path: root/game/playercontrol.cpp
blob: 15b1b86fa5447e0782c3ce8f60c9a03b2e9a4aef (plain)
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
#include <iostream>
#include <string>

#include "playercontrol.h"
#include "entity.h"

Player_control::Player_control () {   
    fsm.arcs.emplace_back(
        select, sel_ground, -1,
        [](Gst &gst, View &view, Fsm &fsm, int p) { 
            view.selected_ground = p;
            std::cout << "selected ground " << p << "\n";
            view.menu_day.options.clear();
            view.menu_day.options.emplace_back("End Day", Menu_day::Opts::end_day);
            view.menu_day.options.emplace_back("Research", Menu_day::Opts::tech);
            view.menu_day.options.emplace_back("Empire Review", Menu_day::Opts::empire_review);
            view.menu_day.options.emplace_back("Scoring", Menu_day::Opts::scoring);
            view.menu_day.open(view.res);
            return menu_day;
        }
    ); 
    fsm.arcs.emplace_back(
        menu_day, opt, Menu_day::Opts::end_day,
        [](Gst &gst, View &view, Fsm &fsm, int p) { 
            view.menu_day.close();
            view.selected_ground = -1;
            // end turn calcs
            for (Entity &e : gst.entities) {
                e.done = false;
            }
            gst.end_day();
            std::cout << "end day " << p << "\n";
            return select;
        }
    ); 
    fsm.arcs.emplace_back(
        menu_day, back, -1,
        [](Gst &gst, View &view, Fsm &fsm, int p) {
            view.menu_day.close();
            view.selected_ground = -1; 
            return select;
        }
    );   
    fsm.arcs.emplace_back(
        select, sel_unit, -1,
        [](Gst &gst, View &view, Fsm &fsm, int p) { 
            view.selected_entity = p;
            view.menu_unit.options.clear();
            view.menu_unit.options.emplace_back("Move", Menu_unit::Opts::move);
            view.menu_unit.options.emplace_back("Attack", Menu_unit::Opts::attack);
            view.menu_unit.options.emplace_back("Done", Menu_unit::Opts::done);
            view.menu_unit.open(view.res);
            std::cout << "selected unit " << p << "\n";
            return menu_unit;
        }
    );  
    fsm.arcs.emplace_back(
        menu_unit, back, -1,
        [](Gst &gst, View &view, Fsm &fsm, int p) { 
            view.selected_entity = -1;
            view.menu_unit.close();
            return select;
        }
    ); 
    fsm.arcs.emplace_back(
        menu_unit, opt, Menu_unit::Opts::move,
        [](Gst &gst, View &view, Fsm &fsm, int p) { 
            view.menu_unit.close();
            std::cout << "move " << p << "\n";
            Entity &ent = gst.entities[view.selected_entity];
            view.moves = gst.ground.move_area(gst, ent);
            return move;
        }
    ); 
    fsm.arcs.emplace_back(
        move, sel_ground, -1,
        [](Gst &gst, View &view, Fsm &fsm, int p) { 
            std::cout << "moved to " << p << "\n";
            Entity &ent = gst.entities[view.selected_entity];
            view.moves.clear();
            ent.x = p % gst.ground.sizex;
            ent.y = p / gst.ground.sizex;
            // remove move points
            view.menu_unit.options.clear();
            view.menu_unit.options.emplace_back("Attack", Menu_unit::Opts::attack);
            view.menu_unit.options.emplace_back("Done", Menu_unit::Opts::done);
            view.menu_unit.open(view.res);
            return menu_unit;
        }
    ); 
    fsm.arcs.emplace_back(
        menu_unit, opt, Menu_unit::Opts::done,
        [](Gst &gst, View &view, Fsm &fsm, int p) { 
            view.menu_unit.close();
            gst.entities[view.selected_entity].done = true;
            view.selected_entity = -1;
            std::cout << "done " << p << "\n";
            return select;
        }
    ); 
}

void Player_control::process (Gst &gst, View &view) {
    if (view.cursor_entity != -1) {
        fsm.transition(gst, view, fsm, sel_unit, view.cursor_entity);
    }
    if (view.cursor_ground != -1) {
        fsm.transition(gst, view, fsm, sel_ground, view.cursor_ground);
    }
    if (view.back != -1) {
        fsm.transition(gst, view, fsm, back, 0);
    }
    if (view.opt != -1) {
        fsm.transition(gst, view, fsm, opt, view.opt);
    }
}