-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcommand_interp.h
85 lines (70 loc) · 2.6 KB
/
command_interp.h
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
#pragma once
#include "common.h"
#include "engine.h"
#include "commands.h"
#include <queue>
struct CommandInterpreter
: public AccessEvents_Emit<ActionCompleteSignal>
, public AccessEvents_Emit<CommandCompletedSignal>
{
void finish_command(int cost = ACTION_POINTS_PER_TURN)
{
AccessEvents_Emit<CommandCompletedSignal>::emit_event(CommandCompletedSignal{});
AccessEvents_Emit<ActionCompleteSignal>::emit_event(ActionCompleteSignal{ cost });
}
virtual void interpret_command(CommandContext&, CommandSignal&) = 0;
};
struct CommandInterpretationSystem
: public OneOffSystem
, public AccessEvents_Emit<ActionCompleteSignal>
, public AccessEvents_Listen<IssueCommandSignal>
, public AccessEvents_Listen<CommandSignal>
, public AccessEvents_Listen<CommandCompletedSignal>
, public AccessEvents_Listen<CommandCancelledSignal>
, public AccessEvents_Emit<CommandSignal>
, public AccessEvents_Emit<CommandCompletedSignal>
, public AccessEvents_Emit<CommandCancelledSignal>
, public AccessWorld_UseUnique<CommandContext>
{
std::queue<IssueCommandSignal> issued_commands;
IssueCommandSignal* current_command = nullptr;
void start_interpreting(IssueCommandSignal signal);
void react_to_event(IssueCommandSignal& signal) override;
void react_to_event(CommandSignal& signal) override;
void react_to_event(CommandCompletedSignal&) override;
void react_to_event(CommandCancelledSignal&) override;
template<CommandType C>
void add_interpreter(CommandInterpreter* c)
{
interpreters.insert({ C, c });
}
private:
std::unordered_map<CommandType, CommandInterpreter*> interpreters;
};
struct WaitCommandInterpreter
: public CommandInterpreter
{
void interpret_command(CommandContext&, CommandSignal&) override;
};
struct UnlockCommandInterpreter
: public CommandInterpreter
, public AccessWorld_ModifyEntity
{
void interpret_command(CommandContext&, CommandSignal&) override;
};
struct InspectCommandInterpreter
: public CommandInterpreter
{
void interpret_command(CommandContext&, CommandSignal&) override;
};
struct Level;
struct MoveCommandInterpreter
: public CommandInterpreter
, public AccessWorld_QueryComponent<WorldPosition>
, public AccessWorld_QueryComponent<Speed>
, public AccessWorld_QueryComponent<Player>
, public AccessWorld_QueryComponent<Sight>
, public AccessWorld_UseUnique<Level>
{
void interpret_command(CommandContext&, CommandSignal&) override;
};