-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.cpp
368 lines (343 loc) · 11.1 KB
/
main.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
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
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <unistd.h>
#include <set>
#include <sys/wait.h>
#include <stdlib.h>
#include <string>
#include <vector>
#include "fields.h"
#include "entities.h"
using namespace std;
typedef unsigned char byte;
byte cinit();
byte crun();
byte cterm();
bool playerInDungeon(Entity*[]);
bool inBattle(Entity*[]);
void handler(Entity*[]);
void makeMines(Area&);
int spid; // PID of the server, only set to non-zero if this is the client that launched the server
int main(int argc,char** args) {
//IS in = new_inputstruct(NULL);
int i;
IS in = new_inputstruct(NULL);
printf("Welcome to Archery & Arcana, player.\n");
if(cinit()) return 1;
if(crun()) return 1;
if(cterm()) return 1;
Entity* party[7];
int place = 0;
char ans;
string name;
string fileName;
string temp;
string junk;
byte classNum;
ifstream input;
int flag;
srand(time(NULL));
setUpParty(party);
input.open("caveTemplate.txt");
if(input.fail()) {
printf("Failed to find the cave entrance.\n");
} else {
getline(input, temp);
while(!(input.eof())) {
printf("%s\n", temp.c_str());
getline(input, temp);
}
input.close();
}
getline(cin, junk);
handler(party);
jettison_inputstruct(in);
return(0);
for (i = 0; i < 7; i++)
party[i] = NULL;
while (true) {
while (true){
printf("Would you like to create a new character?(y/n) ");
getline(cin, junk);
ans = tolower(junk[0]);
if (ans == 'y' || ans == 'n')
break;
printf("Error, incorrect input. Try Again.");
}
if (ans == 'y'){
party[place] = new Entity;
printf ("Enter the character's name: ");
getline(cin, name);
printf("What class would you like to be? Please choose one of the following.\n");
printf(" ----------------------------\n");
for(int i = 0; i < NUM_JOBS; i++) {
printf("| %5d %-20s |\n", i+1, JOBS[i].c_str());
//print job descriptions?
}
printf(" ----------------------------\n");
while(true) {
flag = 1;
printf(" >> ");
getline(cin, temp);
if(temp[0] >= '1' && temp[0] <= '8') { //note: change second item to however many classes we end up having
temp[1] = '\0';
classNum = atoi(temp.c_str()) - 1;
break;
} else {
for(int i = 0; temp[i] != '\0'; i++) {
temp[i] = tolower(temp[i]);
}
for (classNum = 0; classNum < 6; classNum++) {
if (temp == JOBS[classNum]) {
flag = 0;
break;
}
}
if(flag == 0) {
break;
}
if (classNum == 6){ //bad input
printf("I don't recognize that. Please try again.\n");
}
}
}
party[place]->setUpChar(name, (byte) 0, classNum);
party[place]->listAttributes();
place++;
if(place > 6){
break;
}
continue;
}
while (true) {
printf ("Would you like to load a character?(y/n) ");
getline(cin, junk);
ans = tolower(junk[0]);
if (ans == 'y' || ans == 'n')
break;
printf("Error, incorrect input. Try Again.");
}
if (ans == 'y'){
party[place] = new Entity;
while (true){
fileName = "";
printf("Enter your character's name: ");
getline(cin, name);
for (i = 0; i < name.size(); i++)
if (name[i] != ' ') {
fileName[i] = tolower(name[i]);
} else {
fileName[i] = '_';
}
fileName[i] = '.';
fileName[i+1] = 't';
fileName[i+2] = 'x';
fileName[i+3] = 't';
fileName[i+4] = '\0';
input.open(fileName.c_str());
if (input.fail())
printf("Bad file. Try again.");
else
break;
}
party[place]->load(input);
input.close();
place++;
} else {
printf("Then let's generate a character for you.\n");
party[place] = new Entity;
party[place]->generateChar();
party[place]->listAttributes();
place++;
}
if (place > 6)
break;
}
handler(party);
}
byte cinit() {
return 0;
}
byte crun() {
return 0;
}
byte cterm() {
return 0;
}
void handler (Entity* party[]) {
int running = 1;
Area mines;
makeMines(mines);
for (int i = 0; i < 7; i++){
party[i]->room = mines.mapOfArea[0];
mines.mapOfArea[0]->inRoom.push_back(party[i]);
mines.inDungeon.push_back(party[i]);
}
sort(mines.inDungeon.begin(), mines.inDungeon.end(), comp);
int tFactor;
while(running == 1){
tFactor = 100;
if (playerInDungeon(party)){
if (inBattle(party))
tFactor = 1;
else
tFactor = 10;
for (size_t i = 0; i < mines.inDungeon.size(); i++){
running = mines.inDungeon[i]->tick(tFactor);
if (running == 0)
break;
}
}
}
}
bool playerInDungeon(Entity* party[]) {
for (int i = 0; i < 7; i++){
if (party[i]->room != NULL)
return true;
}
return false;
}
void makeMines (Area& mines) {
Entity* ePtr;
mines.name = "Mines of Michaela";
for (int i = 0; i < 17; i++){
mines.mapOfArea.push_back(new Tile);
mines.mapOfArea[i]->zone = &mines;
}
mines.mapOfArea[0]->door.push_back(make_pair(mines.mapOfArea[1], "West"));
mines.mapOfArea[1]->door.push_back(make_pair(mines.mapOfArea[0], "East"));
mines.mapOfArea[1]->door.push_back(make_pair(mines.mapOfArea[2], "South"));
mines.mapOfArea[2]->door.push_back(make_pair(mines.mapOfArea[1], "North"));
mines.mapOfArea[2]->door.push_back(make_pair(mines.mapOfArea[3], "South by Southeast"));
mines.mapOfArea[2]->door.push_back(make_pair(mines.mapOfArea[4], "Southwest"));
mines.mapOfArea[2]->door.push_back(make_pair(mines.mapOfArea[5], "Northwest"));
mines.mapOfArea[3]->door.push_back(make_pair(mines.mapOfArea[2], "North by Northwest"));
mines.mapOfArea[4]->door.push_back(make_pair(mines.mapOfArea[2], "Northeast"));
mines.mapOfArea[4]->door.push_back(make_pair(mines.mapOfArea[5], "North"));
mines.mapOfArea[4]->door.push_back(make_pair(mines.mapOfArea[6], "Northwest"));
mines.mapOfArea[5]->door.push_back(make_pair(mines.mapOfArea[2], "Southeast"));
mines.mapOfArea[5]->door.push_back(make_pair(mines.mapOfArea[7], "Northeast"));
mines.mapOfArea[5]->door.push_back(make_pair(mines.mapOfArea[6], "South"));
mines.mapOfArea[5]->door.push_back(make_pair(mines.mapOfArea[4], "South by Southeast"));
mines.mapOfArea[6]->door.push_back(make_pair(mines.mapOfArea[4], "Southeast"));
mines.mapOfArea[6]->door.push_back(make_pair(mines.mapOfArea[5], "North"));
mines.mapOfArea[6]->door.push_back(make_pair(mines.mapOfArea[8], "West"));
mines.mapOfArea[6]->door.push_back(make_pair(mines.mapOfArea[10], "North by Northwest"));
mines.mapOfArea[7]->door.push_back(make_pair(mines.mapOfArea[9], "South"));
mines.mapOfArea[7]->door.push_back(make_pair(mines.mapOfArea[5], "Southwest"));
mines.mapOfArea[8]->door.push_back(make_pair(mines.mapOfArea[6], "East"));
mines.mapOfArea[8]->door.push_back(make_pair(mines.mapOfArea[10], "North by Northeast"));
mines.mapOfArea[9]->door.push_back(make_pair(mines.mapOfArea[7], "North"));
mines.mapOfArea[10]->door.push_back(make_pair(mines.mapOfArea[11], "Southwest"));
mines.mapOfArea[10]->door.push_back(make_pair(mines.mapOfArea[8], "South by Southwest"));
mines.mapOfArea[10]->door.push_back(make_pair(mines.mapOfArea[6], "South by Southeast"));
mines.mapOfArea[10]->door.push_back(make_pair(mines.mapOfArea[12], "North by Northwest"));
mines.mapOfArea[10]->door.push_back(make_pair(mines.mapOfArea[13], "Northeast"));
mines.mapOfArea[10]->door.push_back(make_pair(mines.mapOfArea[14], "North"));
mines.mapOfArea[11]->door.push_back(make_pair(mines.mapOfArea[10], "Northest"));
mines.mapOfArea[12]->door.push_back(make_pair(mines.mapOfArea[10], "South by Southeast"));
mines.mapOfArea[12]->door.push_back(make_pair(mines.mapOfArea[13], "Southeast"));
mines.mapOfArea[12]->door.push_back(make_pair(mines.mapOfArea[14], "Southeast"));
mines.mapOfArea[13]->door.push_back(make_pair(mines.mapOfArea[10], "Southwest"));
mines.mapOfArea[13]->door.push_back(make_pair(mines.mapOfArea[12], "Northwest"));
mines.mapOfArea[13]->door.push_back(make_pair(mines.mapOfArea[14], "Northwest"));
mines.mapOfArea[14]->door.push_back(make_pair(mines.mapOfArea[10], "South"));
mines.mapOfArea[14]->door.push_back(make_pair(mines.mapOfArea[12], "Northwest"));
mines.mapOfArea[14]->door.push_back(make_pair(mines.mapOfArea[13], "Southeast"));
mines.mapOfArea[14]->door.push_back(make_pair(mines.mapOfArea[15], "East"));
mines.mapOfArea[14]->door.push_back(make_pair(mines.mapOfArea[16], "East by Northeast"));
mines.mapOfArea[15]->door.push_back(make_pair(mines.mapOfArea[14], "West"));
mines.mapOfArea[16]->door.push_back(make_pair(mines.mapOfArea[14], "West by Southwest"));
for (int i = 0; i < 30; i++){
ePtr = new Entity;
ePtr->name = "Goblin ";
for (int j = 0; j < i%5; j++)
ePtr->name += "I";
ePtr->attributes = (byte*)malloc(6);
ePtr->max_mp = ePtr->cur_mp = 0;
ePtr->attributes[0] = rand()%5000;
ePtr->attributes[1] = 5;
ePtr->attributes[2] = 3;
ePtr->attributes[3] = 5;
ePtr->attributes[4] = 5;
ePtr->attributes[5] = 5;
ePtr->max_hp = ePtr->cur_hp = ePtr->attributes[5]*2;
ePtr->npc = 1;
ePtr->cooldown = 0;
ePtr->illusion = NULL;
ePtr->defense = 0;
mines.inDungeon.push_back(ePtr);
}
ePtr = new Entity;
ePtr->name = "Clay Golem";
ePtr->attributes = (byte*)malloc(6);
ePtr->max_mp = ePtr->cur_mp = 0;
ePtr->attributes[0] = rand()%5000;
ePtr->attributes[1] = 15;
ePtr->attributes[2] = 0;
ePtr->attributes[3] = 3;
ePtr->attributes[4] = 5;
ePtr->attributes[5] = 15;
ePtr->max_hp = ePtr->cur_hp = ePtr->attributes[5]*2;
ePtr->npc = 1;
ePtr->cooldown = 0;
ePtr->illusion = NULL;
ePtr->defense = 0;
mines.inDungeon.push_back(ePtr);
ePtr = new Entity;
ePtr->name = "Alaskan Bull Worm";
ePtr->attributes = (byte*)malloc(6);
ePtr->max_mp = ePtr->cur_mp = 0;
ePtr->attributes[0] = rand()%5000;
ePtr->attributes[1] = 20;
ePtr->attributes[2] = 0;
ePtr->attributes[3] = 11;
ePtr->attributes[4] = 0;
ePtr->attributes[5] = 15;
ePtr->max_hp = ePtr->cur_hp = ePtr->attributes[5]*2;
ePtr->npc = 1;
ePtr->cooldown = 0;
ePtr->illusion = NULL;
ePtr->defense = 0;
mines.inDungeon.push_back(ePtr);
for (int i = 0; i < 30; i++){
if (i < 5){
mines.inDungeon[i]->room = mines.mapOfArea[2];
mines.mapOfArea[2]->inRoom.push_back(mines.inDungeon[i]);
}
else if (i < 10){
mines.inDungeon[i]->room = mines.mapOfArea[6];
mines.mapOfArea[6]->inRoom.push_back(mines.inDungeon[i]);
}
else if (i < 15){
mines.inDungeon[i]->room = mines.mapOfArea[3];
mines.mapOfArea[3]->inRoom.push_back(mines.inDungeon[i]);
}
else if (i < 20){
mines.inDungeon[i]->room = mines.mapOfArea[9];
mines.mapOfArea[9]->inRoom.push_back(mines.inDungeon[i]);
}
else if (i < 25){
mines.inDungeon[i]->room = mines.mapOfArea[12];
mines.mapOfArea[12]->inRoom.push_back(mines.inDungeon[i]);
}
else if (i < 30){
mines.inDungeon[i]->room = mines.mapOfArea[14];
mines.mapOfArea[14]->inRoom.push_back(mines.inDungeon[i]);
}
}
mines.inDungeon[30]->room = mines.mapOfArea[14];
mines.mapOfArea[14]->inRoom.push_back(mines.inDungeon[30]);
mines.inDungeon[31]->room = mines.mapOfArea[16];
mines.mapOfArea[16]->inRoom.push_back(mines.inDungeon[31]);
}
bool inBattle (Entity* party[]) {
for (int i = 0; i < 7; i++){
for (int j = 0; j < party[i]->room->inRoom.size() && party[i]->room->inRoom[j] != NULL; j++){
if (party[i]->room->inRoom[j]->npc == 1 && party[i]->room->inRoom[j]->cur_hp > 0)
return true;
}
}
return false;
}