-
Notifications
You must be signed in to change notification settings - Fork 0
/
controller.h
254 lines (221 loc) · 6.94 KB
/
controller.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
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
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
#pragma once
#include <ncurses.h>
#include <stdlib.h>
static const unsigned int MAX_SPELLS = 512;
static unsigned int NUM_SPELLS = 0;
static const unsigned int MAX_WEAPONS = 16;
static unsigned int NUM_WEAPONS = 0;
void createController(Character* character) {
clear();
char buffer[16];
char *endptr;
printw("Enter STR score\n");
printw(">> ");
getnstr(buffer, sizeof(buffer));
long val = strtol(buffer, &endptr, 10);
if(endptr == buffer || val < 0 || val > 20) {
printw("Invalid input, setting STR to 10. This can be changed later\n\n");
character->Str = 10;
}
else {
character->Str = (int)val;
}
printw("Enter DEX score\n");
printw(">> ");
getnstr(buffer, sizeof(buffer));
val = strtol(buffer, &endptr, 10);
if(endptr == buffer || val < 0 || val > 20) {
printw("Invalid input, setting DEX to 10. This can be changed later\n\n");
character->Dex = 10;
}
else {
character->Dex = (int)val;
}
printw("Enter CON score\n");
printw(">> ");
getnstr(buffer, sizeof(buffer));
val = strtol(buffer, &endptr, 10);
if(endptr == buffer || val < 0 || val > 20) {
printw("Invalid input, setting CON to 10. This can be changed later\n\n");
character->Con = 10;
}
else {
character->Con = (int)val;
}
printw("Enter INT score\n");
printw(">> ");
getnstr(buffer, sizeof(buffer));
val = strtol(buffer, &endptr, 10);
if(endptr == buffer || val < 0 || val > 20) {
printw("Invalid input, setting INT to 10. This can be changed later\n\n");
character->Int = 10;
}
else {
character->Int = (int)val;
}
printw("Enter WIS score\n");
printw(">> ");
getnstr(buffer, sizeof(buffer));
val = strtol(buffer, &endptr, 10);
if(endptr == buffer || val < 0 || val > 20) {
printw("Invalid input, setting WIS to 10. This can be changed later\n\n");
character->Wis = 10;
}
else {
character->Wis = (int)val;
}
printw("Enter CHA score\n");
printw(">> ");
getnstr(buffer, sizeof(buffer));
val = strtol(buffer, &endptr, 10);
if(endptr == buffer || val < 0 || val > 20) {
printw("Invalid input, setting CHA to 10. This can be changed later\n\n");
character->Cha = 10;
}
else {
character->Cha = (int)val;
}
printw("\nEnter Proficiency Bonus\n");
printw(">> ");
getnstr(buffer, sizeof(buffer));
val = strtol(buffer, &endptr, 10);
if(endptr == buffer || val < 2 || val > 6) {
printw("Invalid input, setting Proficiency Bonus to 2. This can be changed later\n\n");
character->proficiency = 2;
}
else {
character->proficiency = (int)val;
}
printw("Press enter to continue...\n>> ");
getch();
clear();
for(int i=0; i<18; i++)
character->skills[i] = 0;
char skills[128];
printw("Enter a space seperated list of all skills with proficiency\n");
printw(">> ");
getnstr(skills, sizeof(skills));
manageSkillString(skills, character, 1);
memset(skills, '\0', 128);
printw("Enter a space seperated list of all saves with expertise\n");
printw(">> ");
getnstr(skills, sizeof(skills));
manageSaveString(skills, character);
printw("\nPress Enter to continue...\n>> ");
getch();
clear();
}
void loadController() {
clear();
printw("load\n");
getch();
}
void addSpellController(Spell spells[MAX_SPELLS]) {
clear();
if(NUM_SPELLS >= MAX_SPELLS) {
printw("No more spells can be added\n");
getch();
return;
}
printw("Add new spell\n");
Spell spell;
char buffer[128];
char *endptr;
printw("Enter the name of the spell\n");
printw(">> ");
getnstr(buffer, sizeof(buffer));
buffer[sizeof(buffer)-1] = '\0';
strncpy(spell.name, buffer, 63);
spell.name[63] = '\0';
memset(buffer, '\0', sizeof(buffer));
printw("Enter the level of the spell (0 for cantrip)\n");
printw(">> ");
getnstr(buffer, sizeof(buffer));
buffer[sizeof(buffer)-1] = '\0';
long val = strtol(buffer, &endptr, 10);
if(endptr == buffer || val < 0 || val > 9) {
printw("Invalid value for spell level, setting to 0");
spell.level = 0;
}
else {
spell.level = (int)val;
}
memset(buffer, '\0', sizeof(buffer));
printw("Enter the components of the spell\n");
printw(">> ");
getnstr(buffer, sizeof(buffer));
buffer[sizeof(buffer)-1] = '\0';
strncpy(spell.components, buffer, 7);
spell.components[7] = '\0';
memset(buffer, '\0', sizeof(buffer));
printw("Enter the range of the spell\n");
printw(">> ");
getnstr(buffer, sizeof(buffer));
buffer[sizeof(buffer)-1] = '\0';
strncpy(spell.range, buffer, 31);
spell.range[31] = '\0';
memset(buffer, '\0', sizeof(buffer));
printw("Enter the description of the spell\n");
printw(">> ");
getnstr(buffer, sizeof(buffer));
buffer[sizeof(buffer)-1] = '\0';
strncpy(spell.description, buffer, 127);
spell.description[127] = '\0';
memset(buffer, '\0', sizeof(buffer));
printw("Does the spell require an attack roll? (Y/n)\n");
printw(">> ");
getnstr(buffer, sizeof(buffer));
buffer[sizeof(buffer)-1] = '\0';
if(strcmp(buffer, "y") == 0 || strcmp(buffer, "Y") == 0 || strcmp(buffer, "yes") == 0 || strcmp(buffer, "Yes") == 0) {
spell.attack = 1;
}
else if(strcmp(buffer, "no") == 0 || strcmp(buffer, "No") == 0 || strcmp(buffer, "no") == 0 || strcmp(buffer, "No") == 0) {
spell.attack = 0;
}
else {
printw("unable to parse selected option, setting option to false.\n");
}
memset(buffer, '\0', sizeof(buffer));
spells[NUM_SPELLS] = spell;
NUM_SPELLS += 1;
clear();
}
void addWeaponController(Weapon weapons[MAX_WEAPONS]) {
clear();
if(NUM_WEAPONS >= MAX_WEAPONS) {
printw("No more spells can be added\n");
getch();
return;
}
printw("Add new weapon\n");
Weapon weapon;
char buffer[64];
printw("Enter the name of the weapon\n");
printw(">> ");
getnstr(buffer, sizeof(buffer));
buffer[sizeof(buffer)-1] = '\0';
strncpy(weapon.name, buffer, 63);
weapon.name[63] = '\0';
memset(buffer, '\0', sizeof(buffer));
printw("Enter the damage type of the weapon\n");
printw(">> ");
getnstr(buffer, sizeof(buffer));
buffer[sizeof(buffer)-1] = '\0';
strncpy(weapon.damageType, buffer, 15);
weapon.damageType[15] = '\0';
memset(buffer, '\0', sizeof(buffer));
printw("Enter the damage of the weapon\n");
printw(">> ");
getnstr(buffer, sizeof(buffer));
buffer[sizeof(buffer)-1] = '\0';
strncpy(weapon.damage, buffer, 7);
weapon.damage[7] = '\0';
memset(buffer, '\0', sizeof(buffer));
weapons[NUM_WEAPONS] = weapon;
NUM_WEAPONS += 1;
clear();
}
void parseCommandController() {
printw("command parsing coming soon\n");
return;
}