repl.it
@noobAtProgram/

final project

C

No description

fork
loading
Files
  • main.c
  • .settings
  • .cproject
  • .gitignore
  • .project
  • .pydevproject
  • a.out
  • dungeon.out
  • dungeon.py
  • README.md
  • seed
main.c
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
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <time.h>
// colors
#define BLACK 30
#define RED 31
#define GREEN 32
#define YELLOW 33
#define BLUE 34
#define MAGENTA 35
#define CYAN 36
#define WHITE 37
#define DEFAULT_COL BLACK

#define VISION_RANGE 5
#define OMNISCIENCE 0
// tile nums
#define T_AIR 0
#define T_WALL 1
#define T_BORDER 2
#define T_LAVA 3
#define T_UPS 4
#define T_DOWNS 5
#define T_LASTPH 6
// other plants continue from here
char *plantName(int id) {
	// leaf twig stem root fruit
	char *s = (char *)malloc(20);
	if (id == 5) s = "grass";
	else {
		char *a;
		int z = (id-6)/5;
		if (z == 0) a = "alpha";
		if (z == 1) a = "beta";
		if (z == 2) a = "gamma";
		if (z == 3) a = "delta";
		if (z == 4) a = "epsilon";
		if (z == 5) a = "zeta";
		if (z == 6) a = "eta";
		if (z == 7) a = "theta";
		if (z == 8) a = "iota";
		if (z == 9) a = "kappa";
		if (z == 10) a = "lambda";
		if (z == 11) a = "mu";
		if (z == 12) a = "nu";
		if (z == 13) a = "xi";
		if (z == 14) a = "omicron";
		if (z == 15) a = "pi";
		if (z == 16) a = "rho";
		if (z == 17) a = "sigma";
		if (z == 18) a = "tau";
		if (z == 19) a = "upsilon";
		if (z == 20) a = "phi";
		if (z == 21) a = "hi";
		if (z == 22) a = "psi";
		if (z == 23) a = "omega";
		z = (id-6)%5;
		strcat(s,a);
		if (z == 0) a = "leaf";
		if (z == 1) a = "twig";
		if (z == 2) a = "stem";
		if (z == 3) a = "root";
		if (z == 4) a = "fruit";
		strcat(s,a);
	} return s;
}
// item nums
#define I_NOTHING 0
// generic (red potion, yew wand)
#define I_POTION_RED 1
#define I_POTION_GREEN 2
#define I_POTION_BLUE 3
#define I_POTION_YELLOW 4
#define I_POTION_ORANGE 5
#define I_POTION_PURPLE 6
#define I_POTION_CYAN 7
#define I_POTION_MAGENTA 8
#define I_POTION_WHITE 9
#define I_POTION_BLACK 10
// specific (healing potion, lightning wand)
// potions are named by BLESSED effect
#define I_POTION_HEAL 11
#define I_POTION_SPEED 12
#define I_POTION_INVIS 13
#define I_POTION_STRENGTH 14
#define I_POTION_MAXHP 15
#define I_POTION_FIREP 16
#define I_POTION_COLDP 17
#define I_POTION_GHOST 18
#define I_POTION_REGEN 19
#define I_POTION_CURE 20
#define I_SCROLL_ENCH 21

#define MAXITEM 23
// neither (armor and weapons)
#define I_ARMOR_1 22
#define I_WEAPON_1 23
#define I_FOOD 669
// conditions
#define COND_NULL 0
#define COND_SPEED 1
#define COND_SLOW 2
#define COND_NOMOVE 3
#define COND_NOSEE 4
#define COND_WEAK 5
#define COND_BLIND 6
int ARMOR_SS[] = {0,10,11,12};
int WEAPON_SS[] = {0,10,11,12};
#define NUM_OF_IDEN_ITEMS 10
#define NUM_CATS 1
// 447135
#define MONSTER_BASIC 1
#define KOBOLD 2
int MONST_STRS[] = {0,10,9};
int MONST_MAX[] = {0,20,20};
#define D_WIDTH 50
#define D_HEIGHT 50

int FIRST_GENERICS[] = {I_POTION_RED,I_POTION_HEAL};

char *times(char *str, int reps) { // repeats a string a certain number of times.
	char *buf = (char *)malloc(1024);
	*buf = 0;
	for (int i = 0; i < reps; i++) {
		buf = strcat(buf,str);
	}
	return buf;
}
void printc(char *str, int color) { // color printing, uses DEFINE macros for colors
	printf("\x1b\x5b%dm",color);
	printf("%s",str);
	printf("\x1b\x5b%dm",DEFAULT_COL);
}
void color_set(int color) { // enables a color
	printf("\x1b\x5b%dm",color);
}
void color_reset() { // back to default
	printf("\x1b\x5b%dm",DEFAULT_COL);
}
void faint(int set) {
	printf("\x1b\x5b%dm",set ? 2 : 0);
}
// some ANSI escape sequences
char *ANSI_up = "\x1b\x5b""A";
char *ANSI_down = "\x1b\x5b""B";
char *ANSI_right = "\x1b\x5b""C";
char *ANSI_left = "\x1b\x5b""D";
char *ANSI_next = "\x1b\x5b""E";
char *ANSI_prev = "\x1b\x5b""F";
char *ANSI_clr = "\x1b\x5b""2J";
char *ANSI_clr_ln = "\x1b\x5b""2K";
char *ANSI_scr_up = "\x1b\x5b""S";
char *ANSI_scr_down = "\x1b\x5b""T";
char *ANSI_home = "\x1b\x5b""H";
// tileset
char TILES[256] = ".##:<>";
int T_COLORS[256] = {WHITE,WHITE,BLUE,RED,BLACK,BLACK};
#define SOLID 1
#define PLANT 2
int T_FLAGS[256] = {0,SOLID,SOLID,0,0,0};
char *T_NAMES[256] = {"air","wall","solid wall","lava","upstairs","downstairs"};
void initPlants() {
	for (int i = T_LASTPH; i<T_LASTPH+119; i++) {
		TILES[i] = '"';
		T_COLORS[i] = GREEN;
		T_FLAGS[i] = PLANT;
		T_NAMES[i] = plantName(i);
	}
}
// itemset and items on map
int items[D_WIDTH][D_HEIGHT];
int enchs[D_WIDTH][D_HEIGHT];
char ITEM_CHARS[256] = " [email protected]/";
int ITEM_COLS[256] = {WHITE,RED,GREEN,BLUE,YELLOW,RED,MAGENTA,BLUE,MAGENTA,WHITE,BLACK,WHITE,WHITE,WHITE,WHITE,WHITE,WHITE,WHITE,WHITE,WHITE,WHITE,GREEN,WHITE,WHITE};
char *ITEM_NAMES[256] = {"nothing","red potion","green potion","blue potion","yellow potion","orange potion","purple potion","cyan potion","magenta potion","white potion","black potion","potion of healing","potion of speed","potion of invisibility","potion of strength","potion of endurance","potion of fire resistance","potion of cold resistance","potion of incorporeality","potion of regeneration","potion of curing","scroll of enchantment","leather armor","dagger"};
// dungeon
int dungeon[D_WIDTH][D_HEIGHT];

// just some bools to make life easier
typedef int bool;
#define true 1;
#define false 0;
bool tile_flag(int tile_x, int tile_y, int test_flag) { // retrieve tile info
	return !!(T_FLAGS[dungeon[tile_y][tile_x]] & test_flag);
}

// monsters
int monsters[D_WIDTH][D_HEIGHT];
int mdamages[D_WIDTH][D_HEIGHT];
char *MONST_CHARS = " Bk";
int MONST_COLS[] = {WHITE,RED,RED};
char *MONST_NAMES[] = {"","random thing","kobold"};

// player
int player_x;
int player_y;
void enforce_borders() { // set the edge tiles to T_BORDER
	for (int y = 0; y < D_HEIGHT; y++) {
		if (y == 0 || y == D_HEIGHT-1) { // top or bottom need all tiles T_BORDER
			for (int x = 0; x < D_WIDTH; x++) {
				dungeon[y][x] = T_BORDER;
			}
		} else {
			dungeon[y][0] = T_BORDER;
			dungeon[y][D_HEIGHT-1] = T_BORDER;
		}
	}
}
int fill_tiles(int left_x, int top_y, int width, int height, int fill_with) { // a rectangle will be filled
	if (left_x < 0 || top_y < 0 || width < 0 || height < 0 || left_x + width > D_WIDTH || top_y + height > D_HEIGHT) {
		return 1; // invalid position
	} else { // valid position
		for (int x = left_x; x < left_x + width; x++) {
			for (int y = top_y; y < top_y + height; y++) {
				dungeon[y][x] = fill_with; // the tile to fill with
			}
		}
		return 0;
	}
}
// seen locations
int seen[D_WIDTH][D_HEIGHT];
void see(int x, int y) {
	seen[y][x] = dungeon[y][x];
}
int visarray[D_WIDTH][D_HEIGHT];
bool isSeen(int x, int y) {
	return seen[y][x] != -1;
}
void display_dungeon(int left_x, int top_y) { 
	// DISPLAYS THE DUNGEON (wow)
	printf("%s%s%s%s", ANSI_home, ANSI_down, times(ANSI_right, left_x), times(ANSI_down, top_y));
	// now we're at the starting position
	for (int i = 0; i < D_HEIGHT; i++) {
		for (int j = 0; j < D_WIDTH; j++) {
			if (visarray[i][j]) {
				color_set(T_COLORS[dungeon[i][j]]);
				printf("%c",TILES[dungeon[i][j]]);
				color_reset();
			} else if (isSeen(j,i)) {
				color_set(T_COLORS[dungeon[i][j]]);
				faint(1);
				printf("%c",TILES[seen[i][j]]);
				color_reset();
				faint(0);
			} else {
				printf(" ");
			}
		}
		printf("\n");
	}
}
void display_player() {
	printf("%s%s", ANSI_home, ANSI_down); // down to skip HP bar
	printf("%s%s", times(ANSI_right, player_x), times(ANSI_down, player_y));
	printf("@");
	printf("%s",times(ANSI_next,D_HEIGHT-player_y));
}
// retrieved from site: https://stackoverflow.com/questions/7469139/what-is-equivalent-to-getch-getche-in-linux
// not written by us
#include <termios.h>

static struct termios old, new;
/* Initialize new terminal i/o settings */
void initTermios(int echo) 
{
  tcgetattr(0, &old); /* grab old terminal i/o settings */
  new = old; /* make new settings same as old settings */
  new.c_lflag &= ~ICANON; /* disable buffered i/o */
  if (echo) {
      new.c_lflag |= ECHO; /* set echo mode */
  } else {
      new.c_lflag &= ~ECHO; /* set no echo mode */
  }
  tcsetattr(0, TCSANOW, &new); /* use these new terminal i/o settings now */
}

/* Restore old terminal i/o settings */
void resetTermios(void) 
{
  tcsetattr(0, TCSANOW, &old);
}

/* Read 1 character - echo defines echo mode */
char getch_(int echo) 
{
  char ch;
  initTermios(echo);
  ch = getchar();
  resetTermios();
  return ch;
}

// back to our stuff

// info messages
char *infos[5] = {"-","-","-","-","-"};
void pr_info(char *msg) {
	char *s1 = (char *)malloc(128); // temp strings
	char *s2 = (char *)malloc(128); // use malloc so they don't go out of scope
	char *s3 = (char *)malloc(128);
	char *s4 = (char *)malloc(128);
	char *s5 = (char *)malloc(128);
	strcpy(s1,infos[1]); // shift one place back
	strcpy(s2,infos[2]);
	strcpy(s3,infos[3]);
	strcpy(s4,infos[4]);
	strcpy(s5,msg); // message is last place
	infos[0] = s1; // put back in infos[]
	infos[1] = s2;
	infos[2] = s3;
	infos[3] = s4;
	infos[4] = s5;
}
int death = 0;
bool important_msg = false;
char *death_reason;
int iden_generics[NUM_OF_IDEN_ITEMS];
int iden_specifics[NUM_OF_IDEN_ITEMS];
bool near(int ax, int ay, int bx, int by) {
	return (ax == bx && abs(ay-by)==1) || (ay == by && abs(ax-bx)==1);
}
bool is_contained_in(int arr[], int size, int val) { // is the val contained in the arr?
	for (int idx = 0; idx < size; idx++) {
		if (arr[idx] == val) {
			return idx+1;
		}
	}
	return 0;
}
void shuffle_rand_items() { // generates identifiable items
	for(int i = 0; i < NUM_OF_IDEN_ITEMS; i++) {
		int cat_num = 0;
		while (i+FIRST_GENERICS[0] >= FIRST_GENERICS[cat_num]) {
			cat_num++; // find which category generic is in
		}
		cat_num--;
		int min_val = FIRST_GENERICS[cat_num]; // first item of category
		int max_val = cat_num+1 == NUM_CATS ? NUM_OF_IDEN_ITEMS : FIRST_GENERICS[cat_num+1]-1; // last item of category
		int rand_val;
		do {
			rand_val = rand()%(max_val-min_val+1)+min_val;
		} while (is_contained_in(iden_specifics, NUM_OF_IDEN_ITEMS, rand_val+NUM_OF_IDEN_ITEMS)); // while value is already used
		iden_generics[i] = i+FIRST_GENERICS[0]; // whichever item operating on
		iden_specifics[i] = rand_val+NUM_OF_IDEN_ITEMS; // corresponding specific
	}
}
void display_generic_specific() { // solely debug
	for (int i = 0; i < NUM_OF_IDEN_ITEMS; i++) {
		color_set(MAGENTA);
		printf("GENERIC: %d, SPECIFIC: %d\n",iden_generics[i],iden_specifics[i]);
		color_reset();
	}
}
// identification
int known_things[200];
int num_known = 0;
void learn(int thing) {
	known_things[num_known++] = thing;
}
char *str_format(char *str_pl, int article, int quantity); // forward declaration
//inventory
int pack_items[20];
int pack_counts[20];
int pack_enchs[20];
int num_pack_slots = 0;
void del_item(int item, int quantity) { // delete items from the pack
	// THIS FUNCTION DOESN'T WORK, WILL BE FIXED
	// i think it works now (?)
	char buffer[255];
	if (!is_contained_in(pack_items,num_pack_slots,item)) {
		pr_info("You don't have that.");
	} else {
		if (pack_counts[is_contained_in(pack_items,num_pack_slots,item)-1] < quantity) { // not enough to remove that many
			pr_info("You don't have enough of that to remove that many!");
		} else {
			sprintf(buffer,"You now have %s.",str_format(ITEM_NAMES[item],1,pack_counts[is_contained_in(pack_items,num_pack_slots,item)-1]-quantity));
			pr_info(buffer);
			if (pack_counts[is_contained_in(pack_items,num_pack_slots,item)-1] == quantity) {
				int idx_of = is_contained_in(pack_items,num_pack_slots,item);
				for (int i = idx_of; i < num_pack_slots; i++) {
					pack_items[i-1] = pack_items[i];
					pack_counts[i-1] = pack_counts[i];
				}
				num_pack_slots--;
			} else {
				pack_counts[is_contained_in(pack_items,num_pack_slots,item)-1] -= quantity; // take some from the stack
			}
		}
	}
}
void add_item(int item, int quantity, int ench) { // add an item to your pack
	char buffer[255];
	if (is_contained_in(pack_items,num_pack_slots,item)) { // already exists
    int prev_amt = pack_counts[is_contained_in(pack_items,num_pack_slots,item)-1];
		pack_counts[is_contained_in(pack_items,num_pack_slots,item)-1] += quantity; // add some more to the stack
		sprintf(buffer,"You now have %s.",str_format(ITEM_NAMES[item],0,prev_amt+quantity));
		pr_info(buffer);
	} else { // new item
		if (num_pack_slots == 20) {
			pr_info("You don't have enough space in your pack.");
		} else {
			pack_items[num_pack_slots] = item;
			pack_counts[num_pack_slots] = quantity;
			pack_enchs[num_pack_slots] = ench;
			num_pack_slots++;
			sprintf(buffer,"Item #%d: %s.",num_pack_slots,str_format(ITEM_NAMES[item],1,quantity));
			pr_info(buffer);
		}
	}
}
void take_inventory(int empty_lines) {
	printf("%s%sInventory: %d items\n",times(ANSI_down, empty_lines), ANSI_home,num_pack_slots);
	for (int i = 0; i < num_pack_slots; i++) {
		printf("Item %d: %s\n",i+1, str_format(ITEM_NAMES[pack_items[i]],1,pack_counts[i]));
	}
}
void display_items(int itemlist[D_HEIGHT][D_WIDTH]) {
	for (int y = 0; y < D_HEIGHT; y++) {
		for (int x = 0; x < D_WIDTH; x++) {
			if (itemlist[y][x]) { // an item exists there
				// scan for iden items
				if (is_contained_in(known_things, num_known, itemlist[y][x])) {
					itemlist[y][x] = iden_specifics[is_contained_in(iden_generics, NUM_OF_IDEN_ITEMS, itemlist[y][x])-1];
				}
				char ic = ITEM_CHARS[itemlist[y][x]];
				printf("%s%s", ANSI_home, ANSI_down); // skip HP bar
				printf("%s%s", times(ANSI_right, x), times(ANSI_down, y));
				color_set(ITEM_COLS[itemlist[y][x]]);
				if (visarray[y][x]) {
					printf("%c",ic);
				} else {
					printf(" ");
				}
				color_reset();
				printf("%s",times(ANSI_next,D_HEIGHT-player_y));
			}
		}
	}
	// also scan for pack iden items
	for (int i = 0; i < num_pack_slots; i++) {
		if (is_contained_in(known_things, num_known, pack_items[i]) && pack_items[i] <= NUM_OF_IDEN_ITEMS) {
			pack_items[i] = iden_specifics[is_contained_in(iden_generics, NUM_OF_IDEN_ITEMS, pack_items[i])-1];
		}
	}
}
void display_monsts(int monstlist[D_HEIGHT][D_WIDTH]) { // copy of items pretty much
	for (int y = 0; y < D_HEIGHT; y++) {
		for (int x = 0; x < D_WIDTH; x++) {
			if (monstlist[y][x]) { // a monster exists there
				// scan for dead monsters also
				if (mdamages[y][x] >= MONST_MAX[monstlist[y][x]]) {
					char buf[256];
					sprintf(buf,"The %s dies!",MONST_NAMES[monstlist[y][x]]);
					pr_info(buf);
					monstlist[y][x] = 0;
				}
				char mc = MONST_CHARS[monstlist[y][x]];
				printf("%s%s", ANSI_home, ANSI_down); // skip HP bar
				printf("%s%s", times(ANSI_right, x), times(ANSI_down, y));
				color_set(MONST_COLS[monstlist[y][x]]);
				if (visarray[y][x]) {
					printf("%c",mc);
				} else {
					printf(" ");
				}
				color_reset();
				printf("%s",times(ANSI_next,D_HEIGHT-player_y));
			}
		}
	}
}
int armor_on = 0;
int weapon_on = 0;
int weapon_en = 0;
int armor_en = 0;
int playerStr = 10;
int maxhp = 100;

int hp = 100; // hit points
int conds[10];
int numconds = 0;
int condDur[10];
void applyCond(int cond, int dur) {
	conds[numconds] = cond;
	condDur[numconds] = dur;
	numconds++;
}
void remCond(int cond) {
	int loc = is_contained_in(conds, numconds, cond)-1;
	conds[loc] = COND_NULL;
	while (conds[numconds] == COND_NULL && numconds)
	{
		numconds--;
	}
}
int attack(int strengthAtk, int strengthDef, char *monstName, bool you) {
	int sval, mod, ench;
	if (you) {
		sval = WEAPON_SS[weapon_on]-playerStr-weapon_en;
		mod = weapon_on - ((sval>0)?sval:0);
		ench = weapon_en*2;
		strengthAtk += mod+ench;
	} else {
		sval = ARMOR_SS[armor_on]-playerStr-armor_en;
		mod = armor_on - ((sval>0)?sval:0);
		ench = armor_en*2;
		strengthDef += mod+ench;
	}
	if (you && is_contained_in(conds, numconds, COND_WEAK)) {
		strengthAtk /= 3;
		strengthAtk *= 2;
	} else if (!you && is_contained_in(conds, numconds, COND_WEAK)) {
		strengthDef /= 3;
		strengthDef *= 2;
	}
	if (strengthDef < 4) {
		strengthDef = 4;
	}
	if (strengthAtk < 1) {
		strengthAtk = 1;
	}
	strengthAtk += 6;
	int missChance = (strengthAtk-((!you && is_contained_in(conds, numconds, COND_NOSEE)) ? (strengthDef*2) : strengthDef))/2;
	if (missChance < 1) missChance = 1;
	int val = rand()%missChance;
	char theName[100];
	sprintf(theName,"The %s",monstName);
	if (val) { // hit
		sprintf(theName,"%s hit%s for %d damage!",you?"You":theName,you?"":"s",val*strengthAtk/(strengthDef/4));
		pr_info(theName);
		return val*strengthAtk/(strengthDef/4);
	} else { // miss
		sprintf(theName,"%s miss%s!",you?"You":theName,you?"":"es");
		pr_info(theName);
		return 0;
	}
}
// useful function, this is
// for example:
// str_format("hello",0,1) => "hello"
// str_format("hello",1,1) => "a hello"
// str_format("ohio",1,1) => "an ohio"
// str_format("hello",2,1) => "the hello"
// str_format("hello",0,10) => "10 hellos"
// str_format("hello",1,10) => "10 hellos"
// str_format("hello",2,10) => "the 10 hellos"
// str_format("hello world",0,10) => "10 hello worlds"
// str_format("hello of world",0,10) => "10 hellos of world"
// str_format("foo bar of baz",0,10) => "10 foo bars of baz"
char *str_format(char *str_pl, int article, int quantity) {
	char str[256];
	strcpy(str,str_pl); // incase we used a literal so we cant edit
	char *buffer = (char *)malloc(256); // malloc so it doesn't go out of scope
	if (quantity == 1) {
		// singular
		// the ternary expressions are really long and hard to understand
		sprintf(buffer,"%s %s",(article?(article==2?"the":((str[0] == 'a' || str[0] == 'e' || str[0] == 'i' || str[0] == 'o' || str[0] == 'u')?"an":"a")):""),str);
	} else {
		// pluralize
		char *plural = (char *)malloc(256);
		char *of_sep = strstr(str," of ");
		strcpy(plural,"");
    if (!of_sep) { // no "of", null ptr
      strcat(plural,str);
      strcat(plural,"s");
    } else {
		  *of_sep = '\0'; // cut off
		  strcat(plural,str); // put everything before the of
		  strcat(plural,"s of "); // pluralize it
		  *of_sep = ' '; // don't overall change str
		  of_sep += 4; // rest of str
		  strcat(plural,of_sep); // append rest of string
    }
		if (quantity == 0) {
			sprintf(buffer,"%sno %s",article==2?"the ":"",plural);
		} else {
			sprintf(buffer,"%s%d %s",article==2?"the ":"",quantity,plural);
		}
	}
	return buffer;
}

int ai_data[D_HEIGHT][D_WIDTH]; // can edit stuff
void basic_monst_ai(int x, int y) {
	if (!tile_flag(x-1,y,SOLID)) {
	monsters[y][x-1] = MONSTER_BASIC;
	monsters[y][x] = 0;
	}
	if (near(x, y, player_x, player_y)) {
		hp -= attack(10, playerStr, "random thing", 0);
		death_reason = "a random thing";
	}
}
void kobold_ai(int x, int y) {
	if (near(x,y,player_x,player_y)) {
		hp -= attack(10, playerStr, "kobold", 0);
		death_reason = "a kobold";
		return;
	}
	if (!ai_data[y][x]) { // has not seen you
		if (rand()%2) {
			switch (rand()%4) {
			case 0:
				if (!tile_flag(x-1,y,SOLID)) {
					monsters[y][x-1] = KOBOLD;
					monsters[y][x] = 0;
					mdamages[y][x-1] = mdamages[y][x];
				}
				break;
			case 1:
				if (!tile_flag(x+1,y,SOLID)) {
					monsters[y][x+1] = KOBOLD;
					monsters[y][x] = 0;
					mdamages[y][x+1] = mdamages[y][x];
				}
				break;
			case 2:
				if (!tile_flag(x,y+1,SOLID)) {
					monsters[y+1][x] = KOBOLD;
					monsters[y][x] = 0;
					mdamages[y+1][x] = mdamages[y][x];
				}
				break;
			case 3:
				if (!tile_flag(x,y-1,SOLID)) {
					monsters[y-1][x] = KOBOLD;
					monsters[y][x] = 0;
					mdamages[y-1][x] = mdamages[y][x];
				}
				break;
			}
		}
		if (visarray[y][x] && !(rand()%4)) {
			pr_info("The kobold sees you!");
			ai_data[y][x] = 1;
		}
	} else {
		bool justupd[D_HEIGHT][D_WIDTH];
		for (int moves = 0; moves < 1; moves++) {
			for (int i = 0; i < D_HEIGHT; i++) {
				for (int j = 0; j < D_WIDTH; j++) {
					visarray[i][j] = 0;
					justupd[i][j] = false;
				}
			}
			visarray[player_y][player_x] = 1;
			for (int iter = 0; iter < VISION_RANGE*2-2; iter++) {
				for (int i = 0; i < D_HEIGHT; i++) {
					for (int j = 0; j < D_WIDTH; j++) {
						justupd[i][j] = false;
					}
				}
				for (int i = 0; i < D_HEIGHT; i++) {
					for (int j = 0; j < D_WIDTH; j++) {
						if (visarray[i][j] ) continue;
						if (visarray[i-1][j] && !justupd[i-1][j] && !tile_flag(j,i-1,SOLID)) {
							visarray[i][j] = visarray[i-1][j]+1;
							justupd[i][j] = true;
						} else if (visarray[i+1][j] && !justupd[i+1][j] && !tile_flag(j,i+1,SOLID)) {
							visarray[i][j] = visarray[i+1][j]+1;
							justupd[i][j] = true;
						} else if (visarray[i][j-1] && !justupd[i][j-1] && !tile_flag(j-1,i,SOLID)) {
							visarray[i][j] = visarray[i][j-1]+1;
							justupd[i][j] = true;
						} else if (visarray[i][j+1] && !justupd[i][j+1] && !tile_flag(j+1,i,SOLID)) {
							visarray[i][j] = visarray[i][j+1]+1;
							justupd[i][j] = true;
						}
					}
				}
				/*
				for (int i = 0; i < D_HEIGHT; i++) {
					for (int j = 0; j < D_WIDTH; j++) {
						printf("%d ",visarray[i][j]);
					}
					printf("\n");
				}
				getch_(0);
				*/
			}
			/*
			for (int i = 0; i < D_HEIGHT; i++) {
				for (int j = 0; j < D_WIDTH; j++) {
					if (i == y && j == x) printf("K ");
					else printf("%d ",visarray[i][j]);
				}
				printf("\n");
			}
			getch_(0);
			*/
			int poss_dx[4];
			int poss_dy[4];
			int num_poss = 0;
			if (visarray[y][x] > visarray[y-1][x]) {
				poss_dx[num_poss] = 0;
				poss_dy[num_poss] = -1;
				num_poss++;
			}
			if (visarray[y][x] > visarray[y+1][x]) {
				poss_dx[num_poss] = 0;
				poss_dy[num_poss] = 1;
				num_poss++;
			}
			if (visarray[y][x] > visarray[y][x-1]) {
				poss_dx[num_poss] = -1;
				poss_dy[num_poss] = 0;
				num_poss++;
			}
			if (visarray[y][x] > visarray[y][x+1]) {
				poss_dx[num_poss] = 1;
				poss_dy[num_poss] = 0;
				num_poss++;
			}
			if (num_poss) {
				int choice = rand()%num_poss;
				int dx = poss_dx[choice];
				int dy = poss_dy[choice];
				if (visarray[y+dy][x+dx] == 1) {
					hp -= attack(9, playerStr, "kobold", 0);
					death_reason = "a kobold";
			    } else if (!tile_flag(x+dx,y+dy,SOLID)) {
					monsters[y+dy][x+dx] = KOBOLD;
					monsters[y][x] = 0;
					mdamages[y+dy][x+dx] = mdamages[y][x];
				}
			}
		}
	}
}
// monster ais
void (*MONST_AIS[])(int x, int y) = {basic_monst_ai,basic_monst_ai,kobold_ai};
bool speed_toggle;
int main() {
	FILE *sfile = fopen("seed","r");
	int curseed;
	fscanf(sfile,"%d",&curseed);
	fclose(sfile);
	srand(curseed);
	shuffle_rand_items();
	display_generic_specific();
	printf("%s",ANSI_clr);
	printc("Welcome to YACrogue!\nMade by Vijay Shanmugam and Joshua Piety\nCollect the mighty Amulet of John Doe from the 26th floor of the dungeon!\nPress ? for help at any time.\nHave fun! (press a key to start)",GREEN);
	getch_(0);
	fill_tiles(0,0,D_WIDTH,D_HEIGHT,T_AIR);
	for (int i = 0; i < D_HEIGHT; i++) {
		for (int j = 0; j < D_WIDTH; j++) {
			seen[i][j] = -1;
		}
	}
	initPlants();
	printf("%s\n",T_NAMES[6]);
	system("python dungeon.py"); // yes, i know, this is a dumb way to do it
	FILE *dungFile = fopen("dungeon.out","r");
	for (int i = 0; i < D_HEIGHT; i++) {
		for (int j = 0; j < D_WIDTH; j++) {
			fscanf(dungFile,"%d",&(dungeon[i][j]));
			fgetc(dungFile);
			if (dungeon[i][j] == T_UPS) {
				player_x = j;
				player_y = i;
			}
		}
	}
	// no monsters will spawn here
	visarray[player_y][player_x] = 1;
	for (int iter = 0; iter < VISION_RANGE; iter++) {
		for (int i = 0; i < D_HEIGHT; i++) {
			for (int j = 0; j < D_WIDTH; j++) {
				if (visarray[i][j] != 1 && ((visarray[i+1][j] == 1 && !tile_flag(j,i+1,SOLID)) || (visarray[i-1][j] == 1 && !tile_flag(j,i-1,SOLID)) || (visarray[i][j+1] == 1 && !tile_flag(j+1,i,SOLID))|| (visarray[i][j-1] == 1 && !tile_flag(j-1,i,SOLID)))) {
					visarray[i][j] = 2;
				}
			}
		}
		for (int i = 0; i < D_HEIGHT; i++) {
			for (int j = 0; j < D_WIDTH; j++) {
				if (visarray[i][j] == 2) {
					visarray[i][j] = 1;
				}
			}
		}
	}
	// gen monsters
	for (int i = 0; i < D_HEIGHT; i++) {
		for (int j = 0; j < D_WIDTH; j++) {
			mdamages[i][j] = 0;
			if (!dungeon[i][j] && !visarray[i][j] && !(rand()%40)) {
				monsters[i][j] = KOBOLD;
			}
		}
	}
	// gen items
	for (int i = 0; i < D_HEIGHT; i++) {
		for (int j = 0; j < D_WIDTH; j++) {
			if (!dungeon[i][j] && !(rand()%30)) {
				items[i][j] = (rand()%MAXITEM)+1;
				enchs[i][j] = (rand()%3)-1;
			} else if (!dungeon[i][j] && !(rand()%120)) {
				items[i][j] = I_POTION_HEAL;
				enchs[i][j] = 1;
			}
		}
	}
	// placeholder for dungeon gen
	/*
	player_x = 1;
	player_y = 1;
	dungeon[6][6] = T_LAVA;
	items[7][8] = I_POTION_GREEN;
	items[8][8] = I_POTION_RED;
	items[9][8] = I_POTION_SPEED;
	items[10][9] = I_POTION_INVIS;
	enchs[9][8] = 2;
	enchs[10][9] = 2;
	monsters[8][9] = MONSTER_BASIC;
	learn(I_POTION_RED);
	*/
	bool game_running = true;
	pr_info("Welcome to INROGUE!");
	int dlevel = 0;
	while (game_running) {
		enforce_borders();
		printf("%s",ANSI_clr);
		// display health bar
		for (int c = 0; c < numconds; c++) {
			if (!(condDur[c]--)) {
				remCond(conds[c]);
			}
		}
		int num_dash = 10*((double)hp/(double)maxhp);
		int barcol;
		switch (num_dash) {
		case 0:
		case 1:
		case 2:
			barcol = MAGENTA;
			break;
		case 3:
		case 4:
		case 5:
			barcol = RED;
			break;
		case 6:
		case 7:
		case 8:
			barcol = YELLOW;
			break;
		case 9:
		case 10:
			barcol = GREEN;
		}
		printf("%s", ANSI_home);
		printf("HP: |");
		color_set(barcol);
		printf("%s%s",times("-",num_dash),times(" ",10-num_dash));
		color_reset();
		printf("| ");
		for (int c = 0; c < numconds; c++) {
			switch (conds[c]) {
			 case COND_SPEED:
				 color_set(GREEN);
				 printf("SPEED ");
				 break;
			 case COND_SLOW:
				 color_set(RED);
				 printf("SLOW ");
				 break;
			 case COND_NOSEE:
				 color_set(GREEN);
				 printf("INVIS ");
				 break;
			 case COND_WEAK:
				 color_set(RED);
				 printf("WEAK ");
				 break;
			 case COND_BLIND:
				 color_set(RED);
				 printf("BLIND ");
				 break;
			}
		}
		color_reset();
		printf("\n");
		// calculate vision
		for (int i = 0; i < D_HEIGHT; i++) {
			for (int j = 0; j < D_WIDTH; j++) {
				visarray[i][j] = 0;
			}
		}
		visarray[player_y][player_x] = 1;
		for (int iter = 0; iter < VISION_RANGE && !is_contained_in(conds, numconds, COND_BLIND); iter++) {
			for (int i = 0; i < D_HEIGHT; i++) {
				for (int j = 0; j < D_WIDTH; j++) {
					if (visarray[i][j] != 1 && ((visarray[i+1][j] == 1 && !tile_flag(j,i+1,SOLID)) || (visarray[i-1][j] == 1 && !tile_flag(j,i-1,SOLID)) || (visarray[i][j+1] == 1 && !tile_flag(j+1,i,SOLID))|| (visarray[i][j-1] == 1 && !tile_flag(j-1,i,SOLID)))) {
						visarray[i][j] = 2;
					}
				}
			}
			for (int i = 0; i < D_HEIGHT; i++) {
				for (int j = 0; j < D_WIDTH; j++) {
					if (visarray[i][j] == 2) {
						visarray[i][j] = 1;
					}
				}
			}
		}
		for (int i = 0; i < D_HEIGHT; i++) {
			for (int j = 0; j < D_WIDTH; j++) {
				if (visarray[i][j] || OMNISCIENCE) {
					see(j,i);
				}
			}
		}
		display_dungeon(0,0);
		display_items(items);
		display_monsts(monsters);
		display_player(); // display player AFTER items, so it shows as @ when you're on an item
		// print messages
		for (int i = 0; i < 5; i++) {
			printf("%s\n",infos[i]);
		}
		if (important_msg) {
			getch_(0);
			important_msg = false;
		}
		char keypress = getch_(0);
		if (death) {
			;
		} else if (keypress == 'p') { // pick up items
			if (items[player_y][player_x]) {
				add_item(items[player_y][player_x],1,enchs[player_y][player_x]);
				items[player_y][player_x] = I_NOTHING;
			} else {
				pr_info("You see nothing to pick up.");
			}
		} else if (keypress == 'r') { // remove armor and weapons
			if (armor_on) {
				if (armor_en < 0) pr_info("You can't remove the cursed armor you're wearing..."); else {

				add_item(I_ARMOR_1-1+armor_on,1,armor_en);
				armor_on = 0;
				armor_en = 0;
				}
			}
			if (weapon_on) {
				if (weapon_en < 0) pr_info("You can't put down the cursed weapon you're wielding..."); else {
				add_item(I_WEAPON_1-1+weapon_on,1,weapon_en);
				weapon_on = 0;
				weapon_en = 0;
				}
			}
		} else if (keypress == 'u') { // use items
			take_inventory(1);
			printf("%sWhich item number? ",ANSI_home);
			int inum;
			scanf("%d",&inum);
			if (inum > num_pack_slots || inum < 1) {
				pr_info("You don't have that many items.");
			} else {
				inum--;
				int item = pack_items[inum];
				if (item >= FIRST_GENERICS[0] && item < FIRST_GENERICS[0]+NUM_OF_IDEN_ITEMS) { // it is a generic
					item = iden_specifics[is_contained_in(iden_generics,NUM_OF_IDEN_ITEMS,item)-1]; // make it a specific just this once
				}
				if (item == I_POTION_HEAL) {
					if (pack_enchs[inum] == 0) { // uncursed
						pr_info("You feel... nothing.");
					} else if (pack_enchs[inum] > 0) {
						pr_info("You feel healthier!");
						hp = maxhp;
						learn(pack_items[inum]);
					} else {
						pr_info("Acid spills from the bottle!");
						hp /= 2;
						learn(pack_items[inum]);
					}
					del_item(pack_items[inum],1);
				} else if (item == I_POTION_SPEED) {
					if (pack_enchs[inum] == 0) { // uncursed
						pr_info("You feel... nothing.");
					} else if (pack_enchs[inum] > 0) {
						pr_info("You feel faster!");
						applyCond(COND_SPEED,10);
						learn(pack_items[inum]);
					} else {
						pr_info("You feel slower...");
						applyCond(COND_SLOW,10);
						learn(pack_items[inum]);
					}
					del_item(pack_items[inum],1);
				} else if (item == I_POTION_INVIS) {
					if (pack_enchs[inum] == 0) { // uncursed
						pr_info("You feel... nothing.");
					} else if (pack_enchs[inum] > 0) {
						pr_info("You feel invisible!");
						applyCond(COND_NOSEE,20);
						learn(pack_items[inum]);
					} else {
						pr_info("You feel... something. You just can't remember what..."); // amnesia
						num_known--;
						learn(pack_items[inum]);
					}
					del_item(pack_items[inum],1);
				} else if (item == I_POTION_STRENGTH) {
					if (pack_enchs[inum] == 0) { // uncursed
						pr_info("You feel... nothing.");
					} else if (pack_enchs[inum] > 0) {
						pr_info("You feel stronger!");
						playerStr++;
						learn(pack_items[inum]);
					} else {
						pr_info("You feel weaker...");
						applyCond(COND_WEAK,20);
						learn(pack_items[inum]);
					}
					del_item(pack_items[inum],1);
				} else if (item == I_POTION_MAXHP) {
					if (pack_enchs[inum] == 0) { // uncursed
						pr_info("You feel... nothing.");
					} else if (pack_enchs[inum] > 0) {
						pr_info("Your maximum HP increases!");
						hp += maxhp/3;
						maxhp += maxhp/3;
						learn(pack_items[inum]);
					} else {
						pr_info("You can't see!");
						applyCond(COND_BLIND,20);
						learn(pack_items[inum]);
					}
					del_item(pack_items[inum],1);
				} else if (item >= I_ARMOR_1 && item < I_WEAPON_1) {
					if (armor_on) {
						if (armor_en < 0) pr_info("You can't remove the cursed armor you're wearing..."); else
						add_item(I_ARMOR_1-1+armor_on,1,armor_en);
					}
					armor_on = pack_items[inum]-I_ARMOR_1+1;
					armor_en = pack_enchs[inum];
					del_item(pack_items[inum],1);
				} else if (item >= I_WEAPON_1 && item < I_FOOD) {
					if (weapon_on) {
						if (weapon_en < 0) pr_info("You can't put down the cursed weapon you're wielding..."); else
						add_item(I_WEAPON_1-1+weapon_on,1,weapon_en);
					}
					weapon_on = pack_items[inum]-I_WEAPON_1+1;
					weapon_en = pack_enchs[inum];
					del_item(pack_items[inum],1);
				} else if (item == I_SCROLL_ENCH) {
					pr_info("You recite the words on this old scroll...");
					take_inventory(1);
					int scrench = pack_enchs[inum];
					del_item(pack_items[inum],1);
					printf("%sThis is a scroll of enchantment. What to enchant?",ANSI_home);
					scanf("%d",&inum);
					inum--;
					if (scrench < 0) {
						pr_info("The scroll, being cursed, disintegrates in your hands and has no effect.");
					} else {
						pack_enchs[inum]++;
						if (!pack_enchs[inum]) {
							pr_info("You feel an evil energy dissipate with the use of this scroll.");
						}
						if (scrench) {
							pr_info("The scroll, being blessed, adds its magical energy to the item being enchanted.");
							pack_enchs[inum]++;
							if (!pack_enchs[inum]) {
								pr_info("You feel an evil energy dissipate with the use of this scroll.");
							}
						}
					}
				} else {
					char buffer[255];
					sprintf(buffer,"%s? You can't use that!",str_format(ITEM_NAMES[pack_items[inum]],1,pack_counts[inum])); // use pack_items[inum] to avoid disclosing information
					pr_info(buffer);
				}
			}
		} else if (keypress == 'w') { // view wielding and wearing
			printf("%sWearing:\n%s%s\nWearing:\n%s%s\n",ANSI_home,armor_on?ITEM_NAMES[I_ARMOR_1+armor_on-1]:"nothing",(playerStr>=ARMOR_SS[armor_on])?"":" (heavy)",weapon_on?ITEM_NAMES[I_WEAPON_1+weapon_on-1]:"nothing",(playerStr>=WEAPON_SS[weapon_on])?"":" (heavy)");
			getch_(0);
		} else if (keypress == 'i') { // take inventory
			take_inventory(0);
			printf("(press any key)");
			getch_(0);
		} else if (keypress == '\x1b') { // appears to be an ANSI escape sequence
			keypress = getch_(0);
			if (keypress == '\x5b') { // which it is!
				keypress = getch_(0); // meat of the escape sequence
				switch (keypress) {
					case 'A': // up arrow
					if (is_contained_in(conds,numconds,COND_NOMOVE))
						pr_info("You can't move!");
					else if (monsters[player_y-1][player_x])
						mdamages[player_y-1][player_x] += attack(playerStr, MONST_STRS[monsters[player_y-1][player_x]], "YOU SHOULD NEVER SEE THIS. IF YOU DO THERE IS A GLITCH IN THE GAME",1);
					else if (!tile_flag(player_x, player_y - 1, SOLID))
						player_y--;
					break;
					case 'B': // down arrow
					if (is_contained_in(conds,numconds,COND_NOMOVE))
						pr_info("You can't move!");
					else if (monsters[player_y+1][player_x])
						mdamages[player_y+1][player_x] += attack(playerStr, MONST_STRS[monsters[player_y+1][player_x]], "YOU SHOULD NEVER SEE THIS. IF YOU DO THERE IS A GLITCH IN THE GAME",1);
					else if (!tile_flag(player_x, player_y + 1, SOLID))
						player_y++;
					break;
					case 'C': // right arrow
					if (is_contained_in(conds,numconds,COND_NOMOVE))
						pr_info("You can't move!");
					else if (monsters[player_y][player_x+1])
						mdamages[player_y][player_x+1] += attack(playerStr, MONST_STRS[monsters[player_y][player_x+1]], "YOU SHOULD NEVER SEE THIS. IF YOU DO THERE IS A GLITCH IN THE GAME",1);
					else if (!tile_flag(player_x + 1, player_y, SOLID))
						player_x++;
					break;
					case 'D': // left arrow
					if (is_contained_in(conds,numconds,COND_NOMOVE))
						pr_info("You can't move!");
					else if (monsters[player_y][player_x-1])
						mdamages[player_y][player_x-1] += attack(playerStr, MONST_STRS[monsters[player_y][player_x-1]], "YOU SHOULD NEVER SEE THIS. IF YOU DO THERE IS A GLITCH IN THE GAME",1);
					else if (!tile_flag(player_x - 1, player_y, SOLID))
						player_x--;
					break;
				}
			} else if (keypress == '\x1b') { // ...or the user pressed ESC
				printc("\nWould you like to quit? type @ to confirm: ",RED);
				keypress = getch_(1);
				if (keypress == '@') {
					game_running = false;
					printc("\nOh, well. Bye!\n",RED);
				} else {
					printc("\nReally? NO? Wimp!\n",RED);
				}
				getch_(0);
			}
		} else if (keypress == '?') {
			printf("%s%sWelcome to YACROGUE! In this game, you must adventure through the dungeon! Note that this is a VERY early version of the game.\nCommands:\narrows - move, or attack a monster by moving into it\ni - view your items\nw - view armor and weapons\nu - use an item\np - pick up an item on the floor\n? - view help\nshift-d - activate DEBUG MODE (if you are testing this game, this mode is highly suggested!)\nPress any key to go to next page...\n",ANSI_clr,ANSI_home);
			getch_(0);
			printf("%s%sPotions are magical elixirs that one can drink to have varying effects. Some do nothing, some have positive effects and some have negative effects. In this early version, some potions cannot be used. \nYou will not immediately know what a potion does upon finding it always. Some potions will simply be identified by a color. Negative potions are always found disguised as positive potions. \nNOTE: It is RANDOM what colors correspond to what potions. DO NOT ASK ME \"what the red potion does\". I DO NOT KNOW.\nThe following potions exist:\nHealing - heals you.\nAcid - hurts you.\nSpeed - speeds your movement and attack.\nSlow - slows your movement and attack.\nStrength - permanently increases your strength.\nWeakness - decreases your strength for some time.\nInvisibility - makes you invisible.\nBlindness - causes you to go blind temporarily.\nEndurance - increases your maximum health.\nPress any key to go to the next page...\n",ANSI_clr,ANSI_home);
			getch_(0);
			printf("%s%sYou will encounter monsters in the dungeon. Only one currently exists: the kobold. It will attempt to move towards you and attack when it is near. Defeat them by any means!\nLava also exists in the dungeon. If you touch it, you die.\nPress any key to exit help...",ANSI_clr,ANSI_home);
			getch_(0);
		} else if (keypress == 'D') {
			printf("%s\n1. Give item\n2. Identify item\n3. Give condition\n4. Exit",ANSI_home);
			printf("%sSelect choice: ",ANSI_home);
			int dchoice;
			scanf("%d",&dchoice);
			if (dchoice == 1) {
				printf("%s%s\n",ANSI_home,ANSI_clr);
				for (int i = 1; i <= MAXITEM; i++) {
					printf("%d. %s\n",i,ITEM_NAMES[i]);
				}
				int qchoice, echoice;
				printf("%sSelect choice: ",ANSI_home);
				scanf("%d",&dchoice);
				printf("%sSelect quantity: ",ANSI_home);
				scanf("%d",&qchoice);
				printf("%sSelect enchantment (negative = bad, positive = good, zero = not magical): ",ANSI_home);
				scanf("%d",&echoice);
				add_item(dchoice,qchoice,echoice);
			} else if (dchoice == 2) {
				printf("%s",ANSI_clr);
				take_inventory(1);
				printf("%sWhich item number? ",ANSI_home);
				scanf("%d",&dchoice);
				learn(pack_items[dchoice-1]);
			}
		}
		// check what you're standing on
		int tile_on = dungeon[player_y][player_x];
		if (!death) {
			if (tile_on == T_LAVA) {
				// burn to death
				death = 1;
				pr_info("You burned in lava.");
				death_reason = "burning in lava";
			} else if (tile_on >= T_LASTPH) {
				char buf[64];
				sprintf(buf,"You walk through a field of %s.",T_NAMES[tile_on]);
				pr_info(buf);
			} else if (tile_on == T_DOWNS) {
				dlevel++;
				char buf[32];
				sprintf(buf,"You descend to level %d.",dlevel+1);
				pr_info(buf);
				curseed++;
				for (int i = 0; i < D_HEIGHT; i++) {
					for (int j = 0; j < D_WIDTH; j++) {
						seen[i][j] = -1;
					}
				}
				FILE *sfile = fopen("seed","w");
				fprintf(sfile,"%d",curseed);
				fclose(sfile);
				srand(curseed);
				system("python dungeon.py"); // yes, i know, this is a dumb way to do it
				FILE *dungFile = fopen("dungeon.out","r");
				for (int i = 0; i < D_HEIGHT; i++) {
					for (int j = 0; j < D_WIDTH; j++) {
						fscanf(dungFile,"%d",&(dungeon[i][j]));
						fgetc(dungFile);
						if (dungeon[i][j] == T_UPS) {
							player_x = j;
							player_y = i;
						}
					}
				}
				// no monsters will spawn here
				visarray[player_y][player_x] = 1;
				for (int iter = 0; iter < VISION_RANGE; iter++) {
					for (int i = 0; i < D_HEIGHT; i++) {
						for (int j = 0; j < D_WIDTH; j++) {
							if (visarray[i][j] != 1 && ((visarray[i+1][j] == 1 && !tile_flag(j,i+1,SOLID)) || (visarray[i-1][j] == 1 && !tile_flag(j,i-1,SOLID)) || (visarray[i][j+1] == 1 && !tile_flag(j+1,i,SOLID))|| (visarray[i][j-1] == 1 && !tile_flag(j-1,i,SOLID)))) {
								visarray[i][j] = 2;
							}
						}
					}
					for (int i = 0; i < D_HEIGHT; i++) {
						for (int j = 0; j < D_WIDTH; j++) {
							if (visarray[i][j] == 2) {
								visarray[i][j] = 1;
							}
						}
					}
				}
				// gen monsters
				for (int i = 0; i < D_HEIGHT; i++) {
					for (int j = 0; j < D_WIDTH; j++) {
						mdamages[i][j] = 0;
						if (!dungeon[i][j] && !visarray[i][j] && !(rand()%(40-dlevel*3))) {
							monsters[i][j] = KOBOLD;
						}
					}
				}
				// gen items
				for (int i = 0; i < D_HEIGHT; i++) {
					for (int j = 0; j < D_WIDTH; j++) {
						if (!dungeon[i][j] && !(rand()%30)) {
							items[i][j] = (rand()%MAXITEM)+1;
							enchs[i][j] = (rand()%3)-1;
						} else if (!dungeon[i][j] && !(rand()%(120+dlevel*10))) {
							items[i][j] = I_POTION_HEAL;
							enchs[i][j] = 1;
						}
					}
				}
			}
		}	

		// check if there's an item below you
		if (items[player_y][player_x]) {
			char *iname = ITEM_NAMES[items[player_y][player_x]];
			char tmp_s[50];
			sprintf(tmp_s,"There is %s below you.",str_format(iname,1,1));
			pr_info(tmp_s);
		}
		// check if you've died
		if (death == 3 ) {
			game_running = false;
		} else if (death == 2) {
			death = 3;
			pr_info("You died.");
			important_msg = true;
		} else if (death == 1 || hp <= 0) { // death is for abnormal deaths
			death = 2;
		}
		// update monster ais
		speed_toggle = !speed_toggle;
		if (speed_toggle || !is_contained_in(conds, numconds, COND_SPEED)) {
			for (int i = 0; (is_contained_in(conds, numconds, COND_SLOW) ? i-1 : i)<=0; i++) {
				for (int i = 0; i < D_HEIGHT; i++) {
					for (int j = 0; j < D_WIDTH; j++) {
						int x = monsters[i][j];
						if (x) {
							(*MONST_AIS[x])(j,i); // function pointers are weird
						}
					}
				}
			}
		}
	}
	if (death) { // did you die, or did the user quit?
		printf("%s",ANSI_clr);
		color_set(RED);
		printf("GAME OVER\nYou died on level %d of the dungeon.\nYou were killed by %s.\nPress any key to exit the game\n",dlevel+1,death_reason);
		color_reset();
		getch_(0);
	}
}
Fetching token
?