-
Notifications
You must be signed in to change notification settings - Fork 0
/
dialogcommand.cpp
110 lines (105 loc) · 2.44 KB
/
dialogcommand.cpp
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
#include <TinyScreen.h>
#include <SPI.h>
#include <cstring>
#include "battle.h"
#include "colormonster.h"
#include "dialogcommand.h"
#include "trainer.h"
#include "uiobject.h"
const char *yesNoOption[2] = { "Yes", "No" };
const uint8_t yesNoRow[] = { 70, 48, 94, 63};
void DialogContext::init(const uint8_t *d)
{
dialog = d;
currentCommand = 0;
message = false;
choose = false;
}
bool DialogContext::run(uint8_t c)
{
while (dialog[currentCommand])
{
switch (dialog[currentCommand++])
{
case DIALOG_SAY:
bottomMessage.setText((const char *)(dialog + currentCommand));
currentCommand += std::strlen((const char *)(dialog + currentCommand)) + 1;
message = true;
choose = false;
return true;
break;
case DIALOG_CHOOSE_YESNO:
choice.setRect(yesNoRow);
choice.setOptions(1, 2, yesNoOption);
choose = true;
return true;
break;
case COMMAND_IF:
if (checkCondition(c))
{
currentCommand += 2;
}
else
{
int tmp = (dialog[currentCommand + 1] << 8) + dialog[currentCommand];
currentCommand = tmp;
}
break;
case COMMAND_BATTLE:
choose = false;
message = false;
prevState = state;
state = STATE_BATTLECHOICE;
battle.init();
return true;
break;
case COMMAND_JUMP:
{
int tmp = (dialog[currentCommand + 1] << 8) + dialog[currentCommand];
currentCommand = tmp;
break;
}
case COMMAND_HEALALL:
for (int i = 0; i < MONSTER_PARTYSIZE; i++)
{
party[i].hp = party[i].maxHp;
}
break;
case COMMAND_PAINT:
choose = false;
message = false;
prevState = state;
state = STATE_PAINT;
return true;
break;
case COMMAND_SETSECRET:
pc.setSecret(dialog[currentCommand++]);
break;
default:
return false;
break;
}
}
return false;
}
bool DialogContext::checkCondition(uint8_t c)
{
switch (dialog[currentCommand++])
{
case CONDITION_YES:
if (c == 0)
return true;
break;
case CONDITION_TESTSECRET:
if (pc.testSecret(dialog[currentCommand++]))
return true;
break;
case CONDITION_BATTLEWON:
if (battle.lastBattle == BATTLE_WON)
return true;
break;
default:
break;
}
return false;
}