-
Notifications
You must be signed in to change notification settings - Fork 0
/
dialogue.ino
executable file
·167 lines (153 loc) · 9.69 KB
/
dialogue.ino
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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
#include "dialogue.h"
#include "battle.h"
#include "save.h"
const uint8_t huff_tree[][3] PROGMEM = {
{255,1,24,},
{255,2,15,},
{255,3,4,},
{'E',0,0,},
{255,5,14,},
{255,6,7,},
{'Y',0,0,},
{255,8,13,},
{255,9,12,},
{255,10,11,},
{'J',0,0,},
{'?',0,0,},
{'V',0,0,},
{'G',0,0,},
{'I',0,0,},
{255,16,19,},
{255,17,18,},
{'S',0,0,},
{'O',0,0,},
{255,20,23,},
{255,21,22,},
{'D',0,0,},
{'L',0,0,},
{'H',0,0,},
{255,25,46,},
{255,26,33,},
{255,27,28,},
{'A',0,0,},
{255,29,30,},
{'U',0,0,},
{255,31,32,},
{'C',0,0,},
{'F',0,0,},
{255,34,41,},
{255,35,36,},
{'\x00',0,0,},
{255,37,38,},
{'P',0,0,},
{255,39,40,},
{'K',0,0,},
{'B',0,0,},
{255,42,43,},
{'N',0,0,},
{255,44,45,},
{'M',0,0,},
{'W',0,0,},
{255,47,48,},
{' ',0,0,},
{255,49,50,},
{'T',0,0,},
{255,51,52,},
{'\n',0,0,},
{'R',0,0,},
};
const uint8_t dialogue[] PROGMEM = {
0xe7,0x34,0xd3,0x1f,0x13,0x1a,0x7b,0x30,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,0x8e,0xf6,0x5,0x47,0xf3,0x44,0x54,0x99,0x65,0xd4,0xbd,0xc5,0xfe,0xdc,0xea,0x83,0x7e,0x39,0x3d,0x92,0x68,0xf8,0x66,0xb8,0x53,0xe7,0x33,0xe4,0xb2,0xd7,0x4f,0x66,0x99,0x51,0x9c,0x7c,0x50,0xf4,0x5d,0x8a,0x8f,0x93,0x7c,0xe6,0x7a,0x1e,0xe7,0x3b,0x56,0xd7,0x41,0x2b,0x8f,0x6e,0x78,0xed,0x7c,0x26,0x8f,0x6a,0xe7,0xda,0xe9,0x4c,0xf4,0x45,0xb8,0x2d,0x86,0x4e,0x56,0x8f,0x6b,0x89,0xaf,0x8f,0x84,0xa7,0x38,0x26,0x8f,0x8c,0x76,0xf6,0xe7,0x8e,0xd7,0xc7,0xc3,0xac,0x90,0x53,0x9e,0x2d,0x59,0x34,0xeb,0xff,0x62,0xc7,0x71,0xd8,0xbd,0xce,0x2e,0xf6,0xaf,0x13,0x56,0xa0,0x0,
};
uint16_t huff_index = 0;
uint8_t huff_tree_index = 0;
uint8_t huff_mask = 0;
uint8_t huff_tree_get(uint8_t item){
return pgm_read_byte((uint8_t*)&huff_tree[huff_tree_index][item]);
}
void fill_dialogue_buffer(uint16_t seek_index){
uint8_t tmp, offset = 0;
while( true ){
tmp = pgm_read_byte((uint8_t*)&dialogue[huff_index]);
//Read a single bit
if( (tmp & huff_mask) == 0 ){
// If bit was zero, go to left node
huff_tree_index = huff_tree_get(1);
}else{
// If bit was one, go to right node
huff_tree_index = huff_tree_get(2);
}
//If we are at a leaf node, we have a complete code
tmp = huff_tree_get(0);
if( tmp != 255 ){
// If we're still seeking to our desired start location
if( seek_index > 0 ){
seek_index--;
}else{
combat_message[offset++] = tmp;
//If the character we just read was a zero byte, we are done loading the buffer
if( tmp == '\0' ){
return;
}
}
huff_tree_index = 0;// Return to root
}
//Advance to next bit
huff_mask >>= 1; //Shift mask
if( huff_mask == 0 ){
//If mask has read every bit, it's time to shift to the next byte
huff_index++;
huff_mask = 0x80;
}
}
}
void display_dialogue(uint16_t index, uint8_t len, uint8_t who, const char name_list[][8]){
meta_mode = mode;
dialogue_index = index;
dialogue_remaining = len;
copy_to_buffer(who,name_list);
huff_mask = 0x80;
huff_index = 0;
huff_tree_index = 0;
// Seek to index (from start!) and
// fill dialogue buffer with first set of dialogue
fill_dialogue_buffer(dialogue_index);
mode = DIALOGUE;
}
uint16_t dialogue_index;
uint8_t dialogue_remaining;
void step_dialogue(){
//gb.display.setColor(WHITE);
gb.fillRect(0,SCREEN_HEIGHT/2-1,SCREEN_WIDTH,SCREEN_HEIGHT/2+1, BLACK);
gb.setTextColor(WHITE);
gb.setTextBackground(BLACK);
gb.setCursor(1, SCREEN_HEIGHT/2);
//If the first char is a zero, then no character is speaking, so skip this
//so that narration gets four lines to work with
if( combat_buffer[0] != 0 ){
gb.println(combat_buffer);//Display name of speaker, set before this
}
gb.setCursor(6, gb.getCursorY());
gb.print(combat_message);
gb.setTextColor(BLACK);
gb.setTextBackground(WHITE);
//gb.display.setColor(BLACK);
gb.drawRect(0,SCREEN_HEIGHT/2-1,SCREEN_WIDTH,SCREEN_HEIGHT/2+1);
if(gb.justPressed(A_BUTTON)){
//gb.sound.playOK(); // TODO SOUND
if( dialogue_remaining == 0 ){
// If dialogue is done, return to world mode
if( game_status[STATUS_MAIN] == 36 ){
mode = YOU_WIN;
}else{
mode = meta_mode;
}
}else{
// If dialogue is not done, move to next chunk of text
dialogue_remaining--;
// This time we fill the dialogue buffer we will start from the end of the
// previous dialogue
fill_dialogue_buffer(0);
}
}
}