-
Notifications
You must be signed in to change notification settings - Fork 0
/
locations.c
executable file
·1485 lines (1398 loc) · 52.2 KB
/
locations.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
/*******************************************************************************
Filename: locations.c
Author: David C. Drake (https://davidcdrake.com)
Description: Functions governing locations, their inhabitants, and movement
between locations for the text-based RPG "Words of Power."
*******************************************************************************/
#include "wop.h"
/*******************************************************************************
Function: InitializeLocation
Description: Initializes a given location struct, along with all of its
inhabitants (a linked list of game character structs), to their
default starting values.
Inputs: location - Pointer to the location struct to be initialized.
id - Integer representing the desired location.
Outputs: SUCCESS or FAILURE.
*******************************************************************************/
int InitializeLocation(location_t *location, int id) {
location->id = id;
location->hidden = false;
location->visits = 0;
location->searches = 0;
location->inhabitants = NULL;
switch (id) {
case ILLARUM_ENTRANCE:
strcpy(location->name, "Illarum, City Gate");
AddInhabitants(location, HUMAN, RandomInt(15, 25));
AddInhabitants(location, SOLDIER, RandomInt(8, 12));
break;
case ILLARUM_MARKET:
strcpy(location->name, "Illarum, Marketplace");
AddInhabitants(location, HUMAN, RandomInt(15, 25));
AddInhabitants(location, MERCHANT, RandomInt(7, 12));
AddInhabitants(location, SOLDIER, RandomInt(3, 6));
break;
case ILLARUM_INN:
strcpy(location->name, "Illarum, Inn");
AddInhabitant(location, INNKEEPER);
AddInhabitants(location, HUMAN, RandomInt(15, 25));
break;
case ILLARUM_SCHOOL:
strcpy(location->name, "Illarum, School of the Elements");
AddInhabitants(location, WIZARD_OF_ELEMENTS, RandomInt(7, 12));
AddInhabitant(location, ARCHWIZARD_OF_ELEMENTS);
AddInhabitants(location, HUMAN, RandomInt(3, 6));
break;
case ILLARUM_TEMPLE:
strcpy(location->name, "Illarum, Temple");
AddInhabitants(location, ILLARUM_PRIEST, RandomInt(7, 12));
AddInhabitant(location, ILLARUM_HIGH_PRIEST);
AddInhabitants(location, HUMAN, RandomInt(3, 6));
break;
case ILLARUM_PALACE:
strcpy(location->name, "Illarum, Palace of the King");
AddInhabitant(location, ILLARUM_KING);
AddInhabitants(location, COURT_WIZARD, RandomInt(1, 2));
AddInhabitants(location, NOBLEMAN, RandomInt(3, 6));
AddInhabitants(location, KNIGHT, RandomInt(1, 2));
AddInhabitants(location, SOLDIER, RandomInt(7, 12));
AddInhabitants(location, SERVANT, RandomInt(3, 6));
break;
case ILLARUM_PRISON:
strcpy(location->name, "Illarum, Prison");
AddInhabitants(location, PRISONER, RandomInt(7, 12));
AddInhabitants(location, SOLDIER, RandomInt(3, 6));
break;
case VENTARRIS_ENTRANCE:
strcpy(location->name, "Ventarris, Main Gate");
AddInhabitants(location, SOLDIER, RandomInt(8, 12));
AddInhabitants(location, HUMAN, RandomInt(15, 25));
break;
case VENTARRIS_MARKET:
strcpy(location->name, "Ventarris, Marketplace");
AddInhabitants(location, HUMAN, RandomInt(15, 25));
AddInhabitants(location, MERCHANT, RandomInt(7, 12));
AddInhabitants(location, SLAVE, RandomInt(3, 6));
AddInhabitants(location, SOLDIER, RandomInt(3, 6));
break;
case VENTARRIS_INN:
strcpy(location->name, "Ventarris, Inn");
AddInhabitant(location, INNKEEPER);
AddInhabitants(location, SAILOR, RandomInt(3, 6));
AddInhabitants(location, HUMAN, RandomInt(7, 12));
break;
case VENTARRIS_SCHOOL:
strcpy(location->name, "Ventarris, School of Mind");
AddInhabitants(location, WIZARD_OF_MIND, RandomInt(7, 12));
AddInhabitant(location, ARCHWIZARD_OF_MIND);
AddInhabitants(location, SLAVE, RandomInt(3, 6));
break;
case VENTARRIS_TEMPLE:
strcpy(location->name, "Ventarris, Temple");
AddInhabitants(location, VENTARRIS_PRIEST, RandomInt(7, 12));
AddInhabitant(location, VENTARRIS_HIGH_PRIEST);
AddInhabitants(location, HUMAN, RandomInt(3, 6));
break;
case VENTARRIS_PALACE:
strcpy(location->name, "Ventarris, Palace of the King");
AddInhabitant(location, VENTARRIS_KING);
AddInhabitants(location, COURT_WIZARD, RandomInt(1, 2));
AddInhabitants(location, NOBLEMAN, RandomInt(7, 12));
AddInhabitants(location, KNIGHT, RandomInt(1, 2));
AddInhabitants(location, SOLDIER, RandomInt(7, 12));
AddInhabitants(location, SERVANT, RandomInt(3, 6));
AddInhabitants(location, SLAVE, RandomInt(7, 12));
break;
case VENTARRIS_PRISON:
strcpy(location->name, "Ventarris, Prison");
AddInhabitants(location, PRISONER, RandomInt(20, 29));
AddInhabitants(location, SOLDIER, RandomInt(3, 6));
AddInhabitant(location, KNIGHT);
break;
case VENTARRIS_DOCKS:
strcpy(location->name, "Ventarris, Docks");
AddInhabitants(location, FISHERMAN, RandomInt(3, 6));
AddInhabitants(location, SAILOR, RandomInt(7, 12));
AddInhabitants(location, SLAVE, RandomInt(3, 6));
AddInhabitants(location, SOLDIER, RandomInt(7, 12));
break;
case PLAINS_NORTH:
strcpy(location->name, "Northern Plains");
break;
case NORTHERN_FARMS:
strcpy(location->name, "Northern Farmlands");
AddInhabitants(location, FARMER, RandomInt(3, 6));
break;
case BRILL_OUTSKIRTS:
strcpy(location->name, "Brill, Outskirts");
AddInhabitants(location, HUMAN, RandomInt(3, 6));
break;
case BRILL_MARKET:
strcpy(location->name, "Brill, Marketplace");
AddInhabitants(location, MERCHANT, RandomInt(3, 5));
AddInhabitants(location, HUMAN, RandomInt(7, 12));
break;
case BRILL_INN:
strcpy(location->name, "Brill, Inn");
AddInhabitant(location, INNKEEPER);
AddInhabitants(location, SAILOR, RandomInt(3, 6));
AddInhabitants(location, HUMAN, RandomInt(7, 12));
break;
case BRILL_DOCKS:
strcpy(location->name, "Brill, Docks");
AddInhabitants(location, SAILOR, RandomInt(13, 19));
AddInhabitants(location, FISHERMAN, RandomInt(7, 12));
AddInhabitant(location, THE_ANGLER);
break;
case PLAINS_SOUTH:
strcpy(location->name, "Southern Plains");
break;
case SOUTHERN_FARMS:
strcpy(location->name, "Southern Farmlands");
AddInhabitants(location, FARMER, RandomInt(7, 12));
AddInhabitants(location, SLAVE, RandomInt(3, 5));
break;
case SILENT_SAGE_HOME:
strcpy(location->name, "Solitary House");
AddInhabitant(location, THE_SILENT_SAGE);
location->hidden = true;
break;
case FOREST:
strcpy(location->name, "Western Woods, Fringe");
break;
case DRUIDS_GROVE:
strcpy(location->name, "Druids' Grove");
AddInhabitant(location, ARCHDRUID);
AddInhabitants(location, DRUID, RandomInt(3, 6));
location->hidden = true;
break;
case HERMIT_HUT:
strcpy(location->name, "Solitary Hut");
AddInhabitant(location, THE_HERMIT);
location->hidden = true;
break;
case WYNNFAER_ENTRANCE:
strcpy(location->name, "Wynnfaer, Main Gate");
AddInhabitants(location, ELF, RandomInt(3, 6));
location->hidden = true;
break;
case WYNNFAER_PLAZA:
strcpy(location->name, "Wynnfaer, Central Plaza");
AddInhabitants(location, ELF, RandomInt(15, 25));
break;
case WYNNFAER_PALACE:
strcpy(location->name, "Wynnfaer, Palace");
AddInhabitants(location, ELF_LOREMASTER, RandomInt(7, 12));
break;
case MOUNTAINS:
strcpy(location->name, "Northern Mountains, Foothills");
break;
case GESHTAL:
strcpy(location->name, "Gesh'tal");
AddInhabitants(location, BARBARIAN, RandomInt(15, 25));
AddInhabitants(location, BARBARIAN_WARRIOR, RandomInt(7, 12));
AddInhabitants(location, BARBARIAN_SHAMAN, RandomInt(3, 6));
AddInhabitant(location, BARBARIAN_CHIEFTAIN);
location->hidden = true;
break;
case TORR_ENTRANCE:
strcpy(location->name, "Torr, Entrance");
AddInhabitants(location, DWARF_GUARDIAN, RandomInt(3, 6));
location->hidden = true;
break;
case TORR_MARKET:
strcpy(location->name, "Torr, Marketplace");
AddInhabitants(location, DWARF, RandomInt(15, 25));
AddInhabitants(location, DWARF_MERCHANT, RandomInt(3, 6));
break;
case TORR_SCHOOL:
strcpy(location->name, "Torr, School");
AddInhabitants(location, DWARF, RandomInt(7, 12));
AddInhabitants(location, DWARF_LOREMASTER, RandomInt(1, 2));
break;
case TORR_TEMPLE:
strcpy(location->name, "Torr, Temple");
AddInhabitant(location, DWARF_HIGH_PRIEST);
AddInhabitants(location, DWARF_PRIEST, RandomInt(3, 6));
break;
case TORR_THRONE_ROOM:
strcpy(location->name, "Torr, Throne Room");
AddInhabitant(location, DWARF_KING);
AddInhabitants(location, DWARF_GUARDIAN, RandomInt(3, 6));
break;
case TORR_MINE:
strcpy(location->name, "Torr, Mine");
AddInhabitants(location, DWARF_MINER, RandomInt(7, 12));
AddInhabitants(location, DWARF_GUARDIAN, RandomInt(1, 2));
break;
case TORR_VAULT:
strcpy(location->name, "Torr, Secret Vault");
AddInhabitants(location, DWARF_LOREMASTER, RandomInt(1, 2));
location->hidden = true;
break;
case TORR_PRISON:
strcpy(location->name, "Torr, Prison");
AddInhabitants(location, PRISONER, RandomInt(3, 6));
AddInhabitants(location, DWARF_GUARDIAN, 2);
break;
case GUGGENHOLM_ENTRANCE:
strcpy(location->name, "Guggenholm, Entrance");
AddInhabitant(location, DRAGON);
location->hidden = true;
break;
case GUGGENHOLM_MAIN:
strcpy(location->name, "Guggenholm, Main Hall");
AddInhabitants(location, GNOME, RandomInt(15, 25));
break;
case GUGGENHOLM_MINE:
strcpy(location->name, "Guggenholm, Mine");
AddInhabitants(location, GNOME_MINER, RandomInt(7, 12));
break;
case SWAMP:
strcpy(location->name, "Southwestern Swamplands, Fringe");
break;
case NECROMANCERS_CIRCLE:
strcpy(location->name, "Southwestern Swamplands, Deep");
AddInhabitants(location, NECROMANCER, RandomInt(7, 12));
AddInhabitant(location, ARCHNECROMANCER);
AddInhabitants(location, SLAVE, 2);
AddInhabitants(location, ZOMBIE, RandomInt(3, 6));
break;
case ISHTARR_ENTRANCE:
strcpy(location->name, "Ishtarr, Main Gate");
AddInhabitants(location, ZOMBIE, RandomInt(3, 6));
AddInhabitants(location, SKELETAL_KNIGHT, 2);
break;
case ISHTARR_EAST_WING:
strcpy(location->name, "Ishtarr, East Wing");
AddInhabitants(location, NECROMANCER, RandomInt(1, 2));
AddInhabitants(location, ZOMBIE, RandomInt(3, 6));
break;
case ISHTARR_WEST_WING:
strcpy(location->name, "Ishtarr, West Wing");
AddInhabitants(location, NECROMANCER, RandomInt(1, 2));
AddInhabitants(location, ZOMBIE, RandomInt(3, 6));
break;
case ISHTARR_CENTRAL_TOWER:
strcpy(location->name, "Ishtarr, Central Tower");
AddInhabitants(location, SKELETAL_KNIGHT, 2);
AddInhabitant(location, LICH);
break;
case ISHTARR_DUNGEON:
strcpy(location->name, "Ishtarr, Dungeon");
AddInhabitants(location, PRISONER, RandomInt(3, 6));
AddInhabitants(location, RAT, RandomInt(1, 2));
break;
case SHORE_NE:
strcpy(location->name, "Northeastern Shoreline");
AddInhabitants(location, FISHERMAN, RandomInt(0, 2));
break;
case SHORE_EAST:
strcpy(location->name, "Eastern Shoreline");
AddInhabitants(location, FISHERMAN, RandomInt(0, 2));
break;
case SHORE_SE:
strcpy(location->name, "Southeastern Shoreline");
AddInhabitants(location, FISHERMAN, RandomInt(0, 2));
break;
case OCEAN_SURFACE:
strcpy(location->name, "Ocean Surface");
break;
case OCEAN_SHALLOW:
strcpy(location->name, "Ocean, Shallow Waters");
break;
case OCEAN_DEEP:
strcpy(location->name, "Ocean, Deep");
break;
case OCEAN_TRENCH:
strcpy(location->name, "Ocean, Trench");
location->hidden = true;
break;
case QUELACENTUS_ENTRANCE:
strcpy(location->name, "Quelacentus, Entrance");
AddInhabitants(location, MERFOLK_SOLDIER, RandomInt(3, 6));
location->hidden = true;
break;
case QUELACENTUS_PLAZA:
strcpy(location->name, "Quelacentus, Central Plaza");
AddInhabitants(location, MERFOLK, RandomInt(7, 12));
AddInhabitants(location, MERFOLK_SOLDIER, RandomInt(3, 6));
break;
case QUELACENTUS_TEMPLE:
strcpy(location->name, "Quelacentus, Temple");
AddInhabitants(location, MERFOLK_PRIESTESS, RandomInt(7, 12));
AddInhabitant(location, MERFOLK_HIGH_PRIESTESS);
break;
case QUELACENTUS_PALACE:
strcpy(location->name, "Quelacentus, Palace");
AddInhabitant(location, MERFOLK_QUEEN);
AddInhabitants(location, MERFOLK_PRIESTESS, RandomInt(1, 2));
AddInhabitants(location, MERFOLK_SOLDIER, RandomInt(3, 6));
break;
default:
PRINT_ERROR_MESSAGE;
return FAILURE;
}
return SUCCESS;
}
/*******************************************************************************
Function: InVentarrisTerritory
Description: Determines whether a given location is within the territory claimed
by the king of Ventarris.
Inputs: location - The location of interest.
Outputs: 'true' or 'false'
*******************************************************************************/
bool InVentarrisTerritory(location_t *location) {
return location->id == VENTARRIS_ENTRANCE ||
location->id == VENTARRIS_MARKET ||
location->id == VENTARRIS_INN ||
location->id == VENTARRIS_SCHOOL ||
location->id == VENTARRIS_TEMPLE ||
location->id == VENTARRIS_PALACE ||
location->id == VENTARRIS_PRISON ||
location->id == VENTARRIS_DOCKS ||
location->id == PLAINS_SOUTH ||
location->id == SOUTHERN_FARMS ||
location->id == SWAMP ||
location->id == NECROMANCERS_CIRCLE ||
location->id == ISHTARR_ENTRANCE ||
location->id == ISHTARR_EAST_WING ||
location->id == ISHTARR_WEST_WING ||
location->id == ISHTARR_CENTRAL_TOWER ||
location->id == ISHTARR_DUNGEON ||
location->id == SHORE_SE;
}
/*******************************************************************************
Function: AddInhabitant
Description: Creates a new game character and adds it to a given location's list
of inhabitants.
Inputs: location - Location into which the new character will be added.
type - Integer representing the desired game character type.
Outputs: Pointer to the new game character (or NULL if it failed).
*******************************************************************************/
game_character_t *AddInhabitant(location_t *location, int type) {
game_character_t *new_gc = NULL, *temp;
if (location == NULL) {
PRINT_ERROR_MESSAGE;
} else {
new_gc = malloc(sizeof(game_character_t));
if (new_gc != NULL) {
InitializeCharacter(new_gc, type, location);
new_gc->location = location->id;
if (location->inhabitants == NULL) {
location->inhabitants = new_gc; // New inhabitant successfully added.
} else {
for (temp = location->inhabitants;
temp->next != NULL;
temp = temp->next)
;
temp->next = new_gc; // New inhabitant successfully added.
}
} else {
PRINT_ERROR_MESSAGE;
exit(1);
}
}
return new_gc;
}
/*******************************************************************************
Function: AddInhabitants
Description: Creates multiple game characters of a single type and adds them to
a given location's list of inhabitants.
Inputs: location - Location into which the new characters will be added.
type - Designates the desired game character type.
amount - Number of game characters to add.
Outputs: Number of game characters successfully added.
*******************************************************************************/
int AddInhabitants(location_t *location, int type, int amount) {
int i, count = 0;
for (i = 0; i < amount; i++) {
if(AddInhabitant(location, type) != NULL) {
count++;
}
}
return count;
}
/*******************************************************************************
Function: FindInhabitant
Description: Returns a pointer to the first inhabitant found (if any) matching
a given type.
Inputs: type - Integer representing the game character type of interest.
Outputs: Pointer to an appropriate inhabitant, or NULL if none is found.
*******************************************************************************/
game_character_t *FindInhabitant(int type) {
game_character_t *p_gc;
for (p_gc = g_world[g_player.location]->inhabitants;
p_gc != NULL;
p_gc = p_gc->next) {
if (p_gc->type == type) {
return p_gc;
}
}
return NULL;
}
/*******************************************************************************
Function: MoveInhabitant
Description: Handles the movement of an NPC from one location to another.
Inputs: inhabitant - Pointer to the game character to be moved.
destination - Integer representing the desired destination.
Outputs: SUCCESS or FAILURE.
*******************************************************************************/
int MoveInhabitant(game_character_t *inhabitant, int destination) {
game_character_t *p_gc1, *p_gc2 = NULL;
if (inhabitant == NULL ||
destination < 0 ||
destination >= NUM_LOCATION_IDS) {
PRINT_ERROR_MESSAGE;
return FAILURE;
}
// Add "inhabitant" to the new location's list of inhabitants:
if (g_world[destination]->inhabitants == NULL) {
g_world[destination]->inhabitants = inhabitant;
} else {
for (p_gc1 = g_world[destination]->inhabitants;
p_gc1->next != NULL;
p_gc1 = p_gc1->next)
;
p_gc1->next = inhabitant;
}
// Remove "inhabitant" from the old location's list of inhabitants:
for (p_gc1 = g_world[inhabitant->location]->inhabitants;
p_gc1 != NULL;
p_gc2 = p_gc1, p_gc1 = p_gc1->next) {
if (p_gc1 == inhabitant && p_gc2 != NULL) {
if (p_gc1->next == NULL) {
p_gc2->next = NULL;
} else {
p_gc2->next = p_gc1->next;
}
break;
}
}
// Update other relevant variables:
inhabitant->location = destination;
inhabitant->next = NULL;
if (inhabitant->summoned_creature != NULL) {
inhabitant->summoned_creature->location = destination;
}
return SUCCESS;
}
/*******************************************************************************
Function: RemoveInhabitant
Description: Removes a game character from a location's list of inhabitants.
Inputs: location - Pointer to the relevant location.
inhabitant - Pointer to the game character to be removed.
Outputs: SUCCESS or FAILURE.
*******************************************************************************/
int RemoveInhabitant(location_t *location, game_character_t *inhabitant) {
game_character_t *p_gc1, *p_gc2 = NULL;
if (location == NULL || inhabitant == NULL) {
PRINT_ERROR_MESSAGE;
return FAILURE;
}
for (p_gc1 = location->inhabitants;
p_gc1 != NULL;
p_gc2 = p_gc1, p_gc1 = p_gc1->next) {
if (p_gc1 == inhabitant && p_gc2 != NULL) {
if (p_gc1->next == NULL) {
p_gc2->next = NULL;
} else {
p_gc2->next = p_gc1->next;
}
return SUCCESS;
}
}
if (p_gc1 == NULL) { // If true, "inhabitant" was not found.
PRINT_ERROR_MESSAGE;
return FAILURE;
}
return SUCCESS;
}
/*******************************************************************************
Function: DeleteInhabitant
Description: Removes a game character from a location's list of inhabitants and
deallocates associated memory.
Inputs: location - Pointer to the relevant location.
inhabitant - Pointer to the game character to be removed.
Outputs: SUCCESS or FAILURE.
*******************************************************************************/
int DeleteInhabitant(location_t *location, game_character_t *inhabitant) {
game_character_t *p_gc1, *p_gc2;
if (location == NULL || inhabitant == NULL) {
PRINT_ERROR_MESSAGE;
return FAILURE;
}
p_gc1 = location->inhabitants;
p_gc2 = NULL;
do {
if (p_gc1 == inhabitant) {
if (p_gc2 == NULL) { // Only one inhabitant in this location.
location->inhabitants = NULL;
} else { // More than one inhabitant in this location.
if (inhabitant->next == NULL) { // "inhabitant" is at end of the list.
p_gc2->next = NULL;
} else { // "inhabitant" is not at the end of the list.
p_gc1 = inhabitant->next;
p_gc2->next = p_gc1;
}
}
if (inhabitant->summoned_creature != NULL) {
DeleteCreatureSummonedBy(inhabitant);
}
free(inhabitant);
return SUCCESS;
} else {
p_gc2 = p_gc1;
p_gc1 = p_gc1->next;
}
}while (p_gc1 != NULL);
// If we reach this point, "inhabitant" was not found.
PRINT_ERROR_MESSAGE;
return FAILURE;
}
/*******************************************************************************
Function: VisibleInhabitants
Description: Returns the number of visible inhabitants in a given location.
Inputs: location - Pointer to the location of interest.
Outputs: The number of visible inhabitants in the specified location.
*******************************************************************************/
int VisibleInhabitants(location_t *location) {
int count = 0;
game_character_t *p_gc;
if (location == NULL) {
PRINT_ERROR_MESSAGE;
} else {
for (p_gc = location->inhabitants;
p_gc != NULL;
p_gc = p_gc->next) {
if (p_gc->status[INVISIBLE] == false) {
count++;
}
}
}
return count;
}
/*******************************************************************************
Function: HandleMovementMenuInput
Description: Displays movement options and handles player input.
Inputs: None.
Outputs: SUCCESS or FAILURE.
*******************************************************************************/
int HandleMovementMenuInput(void) {
int i, input, numDestinations = 0;
location_t *destinations[MAX_DESTINATIONS] = {NULL};
// Determine available destinations and describe their orientation:
switch (g_player.location) {
case ILLARUM_ENTRANCE:
destinations[0] = g_world[ILLARUM_MARKET];
destinations[1] = g_world[ILLARUM_INN];
destinations[2] = g_world[ILLARUM_SCHOOL];
destinations[3] = g_world[ILLARUM_TEMPLE];
destinations[4] = g_world[ILLARUM_PALACE];
destinations[5] = g_world[ILLARUM_PRISON];
destinations[6] = g_world[PLAINS_NORTH];
destinations[7] = g_world[PLAINS_SOUTH];
destinations[8] = g_world[SHORE_EAST];
destinations[9] = g_world[FOREST];
break;
case ILLARUM_MARKET:
destinations[0] = g_world[ILLARUM_ENTRANCE];
destinations[1] = g_world[ILLARUM_INN];
destinations[2] = g_world[ILLARUM_SCHOOL];
destinations[3] = g_world[ILLARUM_TEMPLE];
destinations[4] = g_world[ILLARUM_PALACE];
destinations[5] = g_world[ILLARUM_PRISON];
break;
case ILLARUM_INN:
destinations[0] = g_world[ILLARUM_ENTRANCE];
destinations[1] = g_world[ILLARUM_MARKET];
destinations[2] = g_world[ILLARUM_SCHOOL];
destinations[3] = g_world[ILLARUM_TEMPLE];
destinations[4] = g_world[ILLARUM_PALACE];
destinations[5] = g_world[ILLARUM_PRISON];
break;
case ILLARUM_SCHOOL:
destinations[0] = g_world[ILLARUM_ENTRANCE];
destinations[1] = g_world[ILLARUM_MARKET];
destinations[2] = g_world[ILLARUM_INN];
destinations[3] = g_world[ILLARUM_TEMPLE];
destinations[4] = g_world[ILLARUM_PALACE];
destinations[5] = g_world[ILLARUM_PRISON];
break;
case ILLARUM_TEMPLE:
destinations[0] = g_world[ILLARUM_ENTRANCE];
destinations[1] = g_world[ILLARUM_MARKET];
destinations[2] = g_world[ILLARUM_INN];
destinations[3] = g_world[ILLARUM_SCHOOL];
destinations[4] = g_world[ILLARUM_PALACE];
destinations[5] = g_world[ILLARUM_PRISON];
break;
case ILLARUM_PALACE:
destinations[0] = g_world[ILLARUM_ENTRANCE];
destinations[1] = g_world[ILLARUM_MARKET];
destinations[2] = g_world[ILLARUM_INN];
destinations[3] = g_world[ILLARUM_SCHOOL];
destinations[4] = g_world[ILLARUM_TEMPLE];
destinations[5] = g_world[ILLARUM_PRISON];
break;
case ILLARUM_PRISON:
destinations[0] = g_world[ILLARUM_ENTRANCE];
destinations[1] = g_world[ILLARUM_MARKET];
destinations[2] = g_world[ILLARUM_INN];
destinations[3] = g_world[ILLARUM_SCHOOL];
destinations[4] = g_world[ILLARUM_TEMPLE];
destinations[5] = g_world[ILLARUM_PALACE];
break;
case VENTARRIS_ENTRANCE:
destinations[0] = g_world[VENTARRIS_MARKET];
destinations[1] = g_world[VENTARRIS_INN];
destinations[2] = g_world[VENTARRIS_SCHOOL];
destinations[3] = g_world[VENTARRIS_TEMPLE];
destinations[4] = g_world[VENTARRIS_PALACE];
destinations[5] = g_world[VENTARRIS_PRISON];
destinations[6] = g_world[VENTARRIS_DOCKS];
destinations[7] = g_world[SHORE_EAST];
destinations[8] = g_world[SHORE_SE];
destinations[9] = g_world[PLAINS_SOUTH];
break;
case VENTARRIS_MARKET:
destinations[0] = g_world[VENTARRIS_ENTRANCE];
destinations[1] = g_world[VENTARRIS_INN];
destinations[2] = g_world[VENTARRIS_SCHOOL];
destinations[3] = g_world[VENTARRIS_TEMPLE];
destinations[4] = g_world[VENTARRIS_PALACE];
destinations[5] = g_world[VENTARRIS_PRISON];
destinations[6] = g_world[VENTARRIS_DOCKS];
break;
case VENTARRIS_INN:
destinations[0] = g_world[VENTARRIS_ENTRANCE];
destinations[1] = g_world[VENTARRIS_MARKET];
destinations[2] = g_world[VENTARRIS_SCHOOL];
destinations[3] = g_world[VENTARRIS_TEMPLE];
destinations[4] = g_world[VENTARRIS_PALACE];
destinations[5] = g_world[VENTARRIS_PRISON];
destinations[6] = g_world[VENTARRIS_DOCKS];
break;
case VENTARRIS_SCHOOL:
destinations[0] = g_world[VENTARRIS_ENTRANCE];
destinations[1] = g_world[VENTARRIS_MARKET];
destinations[2] = g_world[VENTARRIS_INN];
destinations[3] = g_world[VENTARRIS_TEMPLE];
destinations[4] = g_world[VENTARRIS_PALACE];
destinations[5] = g_world[VENTARRIS_PRISON];
destinations[6] = g_world[VENTARRIS_DOCKS];
break;
case VENTARRIS_TEMPLE:
destinations[0] = g_world[VENTARRIS_ENTRANCE];
destinations[1] = g_world[VENTARRIS_MARKET];
destinations[2] = g_world[VENTARRIS_INN];
destinations[3] = g_world[VENTARRIS_SCHOOL];
destinations[4] = g_world[VENTARRIS_PALACE];
destinations[5] = g_world[VENTARRIS_PRISON];
destinations[6] = g_world[VENTARRIS_DOCKS];
break;
case VENTARRIS_PALACE:
destinations[0] = g_world[VENTARRIS_ENTRANCE];
destinations[1] = g_world[VENTARRIS_MARKET];
destinations[2] = g_world[VENTARRIS_INN];
destinations[3] = g_world[VENTARRIS_SCHOOL];
destinations[4] = g_world[VENTARRIS_TEMPLE];
destinations[5] = g_world[VENTARRIS_PRISON];
destinations[6] = g_world[VENTARRIS_DOCKS];
break;
case VENTARRIS_PRISON:
destinations[0] = g_world[VENTARRIS_ENTRANCE];
destinations[1] = g_world[VENTARRIS_MARKET];
destinations[2] = g_world[VENTARRIS_INN];
destinations[3] = g_world[VENTARRIS_SCHOOL];
destinations[4] = g_world[VENTARRIS_TEMPLE];
destinations[5] = g_world[VENTARRIS_PALACE];
destinations[6] = g_world[VENTARRIS_DOCKS];
break;
case VENTARRIS_DOCKS:
destinations[0] = g_world[VENTARRIS_ENTRANCE];
destinations[1] = g_world[VENTARRIS_MARKET];
destinations[2] = g_world[VENTARRIS_INN];
destinations[3] = g_world[VENTARRIS_SCHOOL];
destinations[4] = g_world[VENTARRIS_TEMPLE];
destinations[5] = g_world[VENTARRIS_PALACE];
destinations[6] = g_world[VENTARRIS_PRISON];
destinations[7] = g_world[SHORE_EAST];
destinations[8] = g_world[SHORE_SE];
destinations[9] = g_world[OCEAN_SURFACE];
break;
case PLAINS_NORTH:
destinations[0] = g_world[NORTHERN_FARMS];
destinations[1] = g_world[MOUNTAINS];
destinations[2] = g_world[ILLARUM_ENTRANCE];
destinations[3] = g_world[BRILL_OUTSKIRTS];
destinations[4] = g_world[FOREST];
destinations[5] = g_world[VENTARRIS_ENTRANCE];
break;
case NORTHERN_FARMS:
destinations[0] = g_world[PLAINS_NORTH];
destinations[1] = g_world[MOUNTAINS];
destinations[2] = g_world[ILLARUM_ENTRANCE];
destinations[3] = g_world[BRILL_OUTSKIRTS];
destinations[4] = g_world[FOREST];
destinations[5] = g_world[VENTARRIS_ENTRANCE];
break;
case BRILL_OUTSKIRTS:
destinations[0] = g_world[BRILL_MARKET];
destinations[1] = g_world[BRILL_INN];
destinations[2] = g_world[BRILL_DOCKS];
destinations[3] = g_world[MOUNTAINS];
destinations[4] = g_world[SHORE_NE];
destinations[5] = g_world[SHORE_EAST];
destinations[6] = g_world[PLAINS_NORTH];
break;
case BRILL_MARKET:
destinations[0] = g_world[BRILL_OUTSKIRTS];
destinations[1] = g_world[BRILL_INN];
destinations[2] = g_world[BRILL_DOCKS];
break;
case BRILL_INN:
destinations[0] = g_world[BRILL_OUTSKIRTS];
destinations[1] = g_world[BRILL_MARKET];
destinations[2] = g_world[BRILL_DOCKS];
break;
case BRILL_DOCKS:
destinations[0] = g_world[BRILL_OUTSKIRTS];
destinations[1] = g_world[BRILL_MARKET];
destinations[2] = g_world[BRILL_INN];
destinations[3] = g_world[SHORE_NE];
destinations[4] = g_world[SHORE_EAST];
destinations[5] = g_world[OCEAN_SURFACE];
break;
case PLAINS_SOUTH:
destinations[0] = g_world[ILLARUM_ENTRANCE];
destinations[1] = g_world[SOUTHERN_FARMS];
destinations[2] = g_world[SILENT_SAGE_HOME];
destinations[3] = g_world[SHORE_EAST];
destinations[4] = g_world[VENTARRIS_ENTRANCE];
destinations[5] = g_world[SHORE_SE];
destinations[6] = g_world[FOREST];
destinations[7] = g_world[SWAMP];
break;
case SOUTHERN_FARMS:
destinations[0] = g_world[ILLARUM_ENTRANCE];
destinations[1] = g_world[PLAINS_SOUTH];
destinations[2] = g_world[SILENT_SAGE_HOME];
destinations[3] = g_world[SHORE_EAST];
destinations[4] = g_world[VENTARRIS_ENTRANCE];
destinations[5] = g_world[SHORE_SE];
destinations[6] = g_world[FOREST];
destinations[7] = g_world[SWAMP];
break;
case SILENT_SAGE_HOME:
destinations[0] = g_world[ILLARUM_ENTRANCE];
destinations[1] = g_world[PLAINS_SOUTH];
destinations[2] = g_world[SOUTHERN_FARMS];
destinations[3] = g_world[SHORE_EAST];
destinations[4] = g_world[VENTARRIS_ENTRANCE];
destinations[5] = g_world[SHORE_SE];
destinations[6] = g_world[FOREST];
destinations[7] = g_world[SWAMP];
break;
case FOREST:
destinations[0] = g_world[MOUNTAINS];
destinations[1] = g_world[PLAINS_NORTH];
destinations[2] = g_world[SWAMP];
destinations[3] = g_world[ILLARUM_ENTRANCE];
destinations[4] = g_world[PLAINS_SOUTH];
break;
case DRUIDS_GROVE:
destinations[0] = g_world[MOUNTAINS];
destinations[1] = g_world[PLAINS_NORTH];
destinations[2] = g_world[SWAMP];
destinations[3] = g_world[ILLARUM_ENTRANCE];
destinations[4] = g_world[PLAINS_SOUTH];
destinations[5] = g_world[FOREST];
break;
case HERMIT_HUT:
destinations[0] = g_world[FOREST];
break;
case WYNNFAER_ENTRANCE:
destinations[0] = g_world[WYNNFAER_PLAZA];
destinations[1] = g_world[WYNNFAER_PALACE];
destinations[2] = g_world[FOREST];
break;
case WYNNFAER_PLAZA:
destinations[0] = g_world[WYNNFAER_ENTRANCE];
destinations[1] = g_world[WYNNFAER_PALACE];
break;
case WYNNFAER_PALACE:
destinations[0] = g_world[WYNNFAER_ENTRANCE];
destinations[1] = g_world[WYNNFAER_PLAZA];
break;
case MOUNTAINS:
destinations[0] = g_world[GESHTAL];
destinations[1] = g_world[TORR_ENTRANCE];
destinations[2] = g_world[FOREST];
destinations[3] = g_world[PLAINS_NORTH];
destinations[4] = g_world[BRILL_OUTSKIRTS];
destinations[5] = g_world[SHORE_NE];
break;
case GESHTAL:
destinations[0] = g_world[MOUNTAINS];
destinations[1] = g_world[TORR_ENTRANCE];
destinations[3] = g_world[FOREST];
destinations[4] = g_world[PLAINS_NORTH];
destinations[5] = g_world[BRILL_OUTSKIRTS];
destinations[6] = g_world[SHORE_NE];
break;
case TORR_ENTRANCE:
destinations[0] = g_world[TORR_MARKET];
destinations[1] = g_world[TORR_SCHOOL];
destinations[2] = g_world[TORR_TEMPLE];
destinations[3] = g_world[TORR_THRONE_ROOM];
destinations[4] = g_world[TORR_MINE];
destinations[5] = g_world[TORR_PRISON];
destinations[6] = g_world[MOUNTAINS];
destinations[7] = g_world[GESHTAL];
destinations[9] = g_world[FOREST];
destinations[10] = g_world[PLAINS_NORTH];
destinations[11] = g_world[BRILL_OUTSKIRTS];
break;
case TORR_MARKET:
destinations[0] = g_world[TORR_ENTRANCE];
destinations[1] = g_world[TORR_SCHOOL];
destinations[2] = g_world[TORR_TEMPLE];
destinations[3] = g_world[TORR_THRONE_ROOM];
destinations[4] = g_world[TORR_MINE];
destinations[5] = g_world[TORR_PRISON];
break;
case TORR_SCHOOL:
destinations[0] = g_world[TORR_ENTRANCE];
destinations[1] = g_world[TORR_MARKET];
destinations[2] = g_world[TORR_TEMPLE];
destinations[3] = g_world[TORR_THRONE_ROOM];
destinations[4] = g_world[TORR_MINE];
destinations[5] = g_world[TORR_PRISON];
break;
case TORR_TEMPLE:
destinations[0] = g_world[TORR_ENTRANCE];
destinations[1] = g_world[TORR_MARKET];
destinations[2] = g_world[TORR_SCHOOL];
destinations[3] = g_world[TORR_THRONE_ROOM];
destinations[4] = g_world[TORR_MINE];
destinations[5] = g_world[TORR_PRISON];
break;
case TORR_THRONE_ROOM:
destinations[0] = g_world[TORR_ENTRANCE];
destinations[1] = g_world[TORR_MARKET];
destinations[2] = g_world[TORR_SCHOOL];
destinations[3] = g_world[TORR_TEMPLE];
destinations[4] = g_world[TORR_MINE];
destinations[5] = g_world[TORR_PRISON];
break;
case TORR_MINE:
destinations[0] = g_world[TORR_ENTRANCE];
destinations[1] = g_world[TORR_MARKET];
destinations[2] = g_world[TORR_SCHOOL];
destinations[3] = g_world[TORR_TEMPLE];
destinations[4] = g_world[TORR_THRONE_ROOM];
destinations[5] = g_world[TORR_PRISON];
break;
case TORR_VAULT:
destinations[0] = g_world[TORR_SCHOOL];
break;
case TORR_PRISON:
destinations[0] = g_world[TORR_ENTRANCE];
destinations[1] = g_world[TORR_MARKET];
destinations[2] = g_world[TORR_SCHOOL];
destinations[3] = g_world[TORR_TEMPLE];
destinations[4] = g_world[TORR_THRONE_ROOM];
destinations[5] = g_world[TORR_MINE];
break;
case GUGGENHOLM_ENTRANCE:
destinations[0] = g_world[GUGGENHOLM_MAIN];
destinations[1] = g_world[MOUNTAINS];
break;
case GUGGENHOLM_MAIN:
destinations[0] = g_world[GUGGENHOLM_ENTRANCE];
destinations[1] = g_world[GUGGENHOLM_MINE];
break;
case GUGGENHOLM_MINE:
destinations[0] = g_world[GUGGENHOLM_MAIN];
break;
case SWAMP:
destinations[0] = g_world[FOREST];
destinations[1] = g_world[PLAINS_SOUTH];
destinations[2] = g_world[NECROMANCERS_CIRCLE];
break;
case NECROMANCERS_CIRCLE:
destinations[0] = g_world[ISHTARR_ENTRANCE];
destinations[1] = g_world[SWAMP];
break;
case ISHTARR_ENTRANCE:
destinations[0] = g_world[ISHTARR_EAST_WING];
destinations[1] = g_world[ISHTARR_WEST_WING];
destinations[2] = g_world[ISHTARR_CENTRAL_TOWER];
destinations[3] = g_world[ISHTARR_DUNGEON];
destinations[4] = g_world[NECROMANCERS_CIRCLE];
break;
case ISHTARR_EAST_WING:
destinations[0] = g_world[ISHTARR_ENTRANCE];