-
Notifications
You must be signed in to change notification settings - Fork 0
/
wop.h
executable file
·609 lines (569 loc) · 14.7 KB
/
wop.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
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
/*******************************************************************************
Filename: wop.h
Author: David C. Drake (https://davidcdrake.com)
Description: Header file for the text-based fantasy RPG "Words of Power."
*******************************************************************************/
#ifndef WOP_H_
#define WOP_H_
#define _CRT_SECURE_NO_DEPRECATE
#include <stdio.h> // printf, scanf
#include <stdlib.h> // srand, rand
#include <time.h> // time
#include <ctype.h> // toupper, isalnum
#include <string.h> // strlen, strcpy, strcmp
#include <stdbool.h> // bool, true, false
/*******************************************************************************
Constants
*******************************************************************************/
// Error checking:
#define DEBUG false
#define FAILURE false
#define SUCCESS true
#if DEBUG
#define PRINT_ERROR_MESSAGE printf("ERROR: %s, line %d\n", __FILE__, __LINE__); FlushInput()
#else
#define PRINT_ERROR_MESSAGE FlushInput()
#endif
// String lengths and other max. values:
#define SHORT_STR_LEN 50
#define LONG_STR_LEN 500
#define MAX_LINE_LENGTH 80 // including new line character
#define MAX_ENEMIES 100 // per battle
#define MAX_TARGETS (MAX_ENEMIES * 2) // per spell
#define TOTAL_SECRETS 200 // to evaluate player progress
#define MAX_MENU_OPTIONS 100
#define MAX_DESTINATIONS 20
// Default stats, representative of an average adult human:
#define DEFAULT_HP 30
#define DEFAULT_PHYSICAL_POWER 10
#define DEFAULT_PHYSICAL_DEFENSE 10
#define DEFAULT_MENTAL_POWER 10
#define DEFAULT_MENTAL_DEFENSE 10
#define DEFAULT_SPEED 5
#define DEFAULT_EXP 10
// Standard prices and price modifiers for goods and services:
#define STD_LANG_FEE 50
#define STD_WORD_FEE 100
#define FRIEND_MODIFIER 0.8
#define ENEMY_MODIFIER 1.5
// Amount of experience earned for completing the easiest missions:
#define STD_MISSION_EXP 25
// Amount of experience needed to level-up:
#define EXP_PER_LEVEL 100
#define HP_LEVEL_UP_VALUE RandomInt(5, 10)
#define PHYSICAL_LEVEL_UP_VALUE RandomInt(0, 2)
#define MENTAL_LEVEL_UP_VALUE RandomInt(0, 2)
// Values for different kinds of "souls":
#define EXTREMELY_EVIL -30
#define VERY_EVIL -15
#define EVIL -5
#define NEUTRAL 0
#define GOOD 5
#define VERY_GOOD 15
#define EXTREMELY_GOOD 30
// Values for important relationship thresholds:
#define HOSTILE_ENEMY -10
#define BAD_ENEMY -5
#define ENEMY -1
#define INDIFFERENT 0
#define FRIEND 1
#define GOOD_FRIEND 5
#define GREAT_FRIEND 10
// Maximum number of Words allowed in a single spell:
#define MAX_SPELL_LEN 8
/*******************************************************************************
Enumerations
*******************************************************************************/
enum WordType {
WORD_OF_AIR,
WORD_OF_WATER,
WORD_OF_EARTH,
WORD_OF_FIRE,
WORD_OF_BODY,
WORD_OF_MIND,
WORD_OF_FLORA,
WORD_OF_FAUNA,
WORD_OF_LIGHT,
WORD_OF_DARKNESS,
WORD_OF_HEALTH,
WORD_OF_SICKNESS,
WORD_OF_LIFE,
WORD_OF_DEATH,
WORD_OF_HOLINESS,
WORD_OF_EVIL,
WORD_OF_GIVING,
WORD_OF_TAKING,
WORD_OF_INCREASE,
WORD_OF_DECREASE,
WORD_OF_BALANCE,
WORD_OF_SHIELDING,
WORD_OF_WAVES,
WORD_OF_FOCUS,
WORD_OF_TIME,
WORD_OF_VOID,
NUM_WORD_TYPES
};
enum LanguageType {
IMPERIAL,
ANCIENT_IMPERIAL,
ELVISH,
ANCIENT_ELVISH,
DWARVISH,
ANCIENT_DWARVISH,
GNOMISH,
ANCIENT_GNOMISH,
MER,
ANCIENT_MER,
GESH,
VENTARRI,
ANCIENT_VENTARRI,
NUM_LANGUAGE_TYPES
};
enum LocationID {
ILLARUM_ENTRANCE,
ILLARUM_MARKET,
ILLARUM_INN,
ILLARUM_SCHOOL,
ILLARUM_TEMPLE,
ILLARUM_PALACE,
ILLARUM_PRISON,
VENTARRIS_ENTRANCE,
VENTARRIS_MARKET,
VENTARRIS_INN,
VENTARRIS_SCHOOL,
VENTARRIS_TEMPLE,
VENTARRIS_PALACE,
VENTARRIS_PRISON,
VENTARRIS_DOCKS,
PLAINS_NORTH,
NORTHERN_FARMS,
BRILL_OUTSKIRTS,
BRILL_MARKET,
BRILL_INN,
BRILL_DOCKS,
PLAINS_SOUTH,
SOUTHERN_FARMS,
SILENT_SAGE_HOME,
FOREST,
DRUIDS_GROVE,
HERMIT_HUT,
WYNNFAER_ENTRANCE,
WYNNFAER_PLAZA,
WYNNFAER_PALACE,
MOUNTAINS, GESHTAL,
TORR_ENTRANCE,
TORR_MARKET,
TORR_SCHOOL,
TORR_TEMPLE,
TORR_THRONE_ROOM,
TORR_MINE,
TORR_VAULT,
TORR_PRISON,
GUGGENHOLM_ENTRANCE,
GUGGENHOLM_MAIN,
GUGGENHOLM_MINE,
SWAMP,
NECROMANCERS_CIRCLE,
ISHTARR_ENTRANCE,
ISHTARR_EAST_WING,
ISHTARR_WEST_WING,
ISHTARR_CENTRAL_TOWER,
ISHTARR_DUNGEON,
SHORE_NE,
SHORE_EAST,
SHORE_SE,
OCEAN_SURFACE,
OCEAN_SHALLOW,
OCEAN_DEEP,
OCEAN_TRENCH,
QUELACENTUS_ENTRANCE,
QUELACENTUS_PLAZA,
QUELACENTUS_TEMPLE,
QUELACENTUS_PALACE,
NUM_LOCATION_IDS
};
enum GameCharType {
PLAYER,
HUMAN,
SOLDIER,
KNIGHT,
WIZARD,
PEASANT,
MERCHANT,
INNKEEPER,
NOBLEMAN,
FISHERMAN,
SAILOR,
SERVANT,
SLAVE,
THIEF,
PRISONER,
FARMER,
ILLARUM_PRIEST,
ILLARUM_HIGH_PRIEST,
ILLARUM_KING,
COURT_WIZARD,
WIZARD_OF_ELEMENTS,
ARCHWIZARD_OF_ELEMENTS,
DUMMY,
WIZARD_OF_MIND,
ARCHWIZARD_OF_MIND,
VENTARRIS_PRIEST,
VENTARRIS_HIGH_PRIEST,
VENTARRIS_KING,
BARBARIAN,
BARBARIAN_WARRIOR,
BARBARIAN_SHAMAN,
BARBARIAN_CHIEFTAIN,
ELF,
ELF_LOREMASTER,
DWARF,
DWARF_MERCHANT,
DWARF_MINER,
DWARF_GUARDIAN,
DWARF_LOREMASTER,
DWARF_PRIEST,
DWARF_HIGH_PRIEST,
DWARF_KING,
GNOME,
GNOME_MINER,
DRUID,
ARCHDRUID,
RAT,
BAT,
GIANT_SPIDER,
WOLF,
BEAR,
BIRD,
TREANT,
CENTAUR,
FISH,
SHARK,
WHALE,
GIANT_SQUID,
MERFOLK,
MERFOLK_SOLDIER,
MERFOLK_PRIESTESS,
MERFOLK_HIGH_PRIESTESS,
MERFOLK_QUEEN,
NECROMANCER,
ARCHNECROMANCER,
LICH,
ZOMBIE,
SKELETAL_KNIGHT,
GOBLIN,
ORC,
OGRE,
TROLL,
GIANT,
DRAGON,
FIRE_ELEMENTAL,
WATER_ELEMENTAL,
EARTH_ELEMENTAL,
AIR_ELEMENTAL,
THE_DARK_RECLUSE,
THE_HERMIT,
THE_ANGLER,
THE_WANDERING_MONK,
THE_SILENT_SAGE,
NUM_GC_TYPES
};
enum GameCharStatusType {
INVISIBLE,
FLYING,
WATER_BREATHING,
FIRE_FORM,
EARTH_FORM,
WIND_FORM,
WATER_FORM,
ASLEEP,
PARALYZED,
POISONED,
SILENCED,
IN_COMBAT,
SUMMONED,
INANIMATE,
NUM_STATUS_TYPES
};
enum ItemType {
FOOD,
HEALING_POTION,
GLOWING_MUSHROOM,
NUM_ITEM_TYPES
};
enum MissionType {
ELEMENTS1,
ELEMENTS2,
ELEMENTS3,
ELEMENTS4,
ELEMENTS5,
MIND1,
MIND2,
MIND3,
MIND4,
MIND5,
DRUID1,
DRUID2,
DRUID3,
DRUID4,
DRUID5,
ELF1,
ELF2,
ELF3,
ELF4,
ELF5,
DWARF1,
DWARF2,
DWARF3,
DWARF4,
DWARF5,
GNOME1,
GNOME2,
GNOME3,
GNOME4,
GNOME5,
NECROMANCER1,
NECROMANCER2,
NECROMANCER3,
NECROMANCER4,
NECROMANCER5,
LICH1,
LICH2,
LICH3,
LICH4,
LICH5,
ILLARUM_PRIEST1,
ILLARUM_PRIEST2,
ILLARUM_PRIEST3,
ILLARUM_PRIEST4,
ILLARUM_PRIEST5,
VENTARRIS_PRIEST1,
VENTARRIS_PRIEST2,
VENTARRIS_PRIEST3,
VENTARRIS_PRIEST4,
VENTARRIS_PRIEST5,
GESH1,
GESH2,
GESH3,
GESH4,
GESH5,
MERFOLK1,
MERFOLK2,
MERFOLK3,
MERFOLK4,
MERFOLK5,
FARMER1,
FARMER2,
FARMER3,
FARMER4,
FARMER5,
BRILL1,
BRILL2,
BRILL3,
BRILL4,
BRILL5,
ILLARUM_KING1,
ILLARUM_KING2,
ILLARUM_KING3,
ILLARUM_KING4,
ILLARUM_KING5,
VENTARRIS_KING1,
VENTARRIS_KING2,
VENTARRIS_KING3,
VENTARRIS_KING4,
VENTARRIS_KING5,
NUM_MISSION_TYPES
};
enum MissionStatus {
CLOSED,
OPEN,
COMPLETED,
TERMINATED,
FAILED
};
enum GroupType {
ELEMENTS_GUILD,
MIND_GUILD,
THE_DRUIDS,
THE_ELVES,
THE_DWARVES,
THE_GNOMES,
THE_MERFOLK,
THE_BARBARIANS,
PRIESTS_OF_ILLARUM,
PRIESTS_OF_VENTARRIS,
PRIESTS_OF_TORR,
THE_NECROMANCERS,
THE_FARMERS,
NUM_GROUP_TYPES
};
enum Knowledge {
UNKNOWN,
PARTIALLY_KNOWN,
KNOWN
};
/*******************************************************************************
Structures
*******************************************************************************/
typedef struct GameCharacter {
int type;
bool unique; // False for generic NPCs.
char name[SHORT_STR_LEN + 1]; // Capitalized, even for generic NPCs.
char descriptor[SHORT_STR_LEN + 1]; // Brief generic description.
int level;
int experience; // "Total exp." for player, "exp. obtainable" for NPCs.
int max_hp;
int hp;
int physical_power;
int physical_defense;
int speed;
int mental_power;
int mental_defense;
int soul; // Ranges from EXTREMELY_EVIL to EXTREMELY_GOOD.
enum Knowledge words[NUM_WORD_TYPES]; // Records known Words of Power.
enum Knowledge languages[NUM_LANGUAGE_TYPES];
int conversations; // Number of conversations held with player.
bool knows_player;
bool known_to_player;
int relationship; // Relative to player: FRIEND, ENEMY, INDIFFERENT, etc.
int status[NUM_STATUS_TYPES];
int gold;
int inventory[NUM_ITEM_TYPES]; // Includes equipped items.
int equipped_items[NUM_ITEM_TYPES];
int location;
struct GameCharacter *summoned_creature; // Only one allowed at a time.
struct GameCharacter *next; // For forming linked lists.
} game_character_t;
typedef struct Location {
int id;
char name[SHORT_STR_LEN + 1];
bool hidden; // If true, special effort is required to find the location.
int visits; // Number of times player has visited the location.
int searches; // Number of times player has searched the location.
game_character_t *inhabitants; // Linked list of local NPCs.
} location_t;
/*******************************************************************************
Global Variables
*******************************************************************************/
location_t *g_world[NUM_LOCATION_IDS]; // Pointers to all game locations.
bool g_world_exists; // Indicates whether game world exists in memory.
bool g_player_has_quit; // Indicates player's desire to quit the game.
int g_num_secrets_found; // Number of "secrets" discovered by the player.
game_character_t g_player;
game_character_t *g_enemies[MAX_ENEMIES];
int g_missions[NUM_MISSION_TYPES]; // To track player progress.
int g_allegiances[NUM_GROUP_TYPES]; // Player's relationships with groups.
int g_num_kills[NUM_GC_TYPES]; // Number of each GC type killed.
int g_num_visible_of_type[NUM_GC_TYPES]; // Number of each GC type visible.
bool g_character_type_described[NUM_GC_TYPES]; // Helps when describing NPCs.
/*******************************************************************************
Function Prototypes
*******************************************************************************/
// Function prototypes for "main.c":
int main(void);
void HandleMainMenuInput(void);
void HandleStandardOptionsInput(void);
bool SaveGame(const char *filename);
bool LoadGame(const char *filename);
int CreateWorld(void);
int DestroyWorld(void);
bool GetExitConfirmation(void);
int RandomInt(int low, int high);
int RandomBool(void);
char GetCharInput(char *c);
int GetIntInput(int *i, int low, int high);
char *GetStrInput(char *str, int n);
void PrintString(char *str);
char *Capitalize(char *str);
char *AllCaps(char *str);
bool StrContains(char *str, char c);
void FlushInput(void);
// Function prototypes for "locations.c":
int InitializeLocation(location_t *location, int id);
bool InVentarrisTerritory(location_t *location);
game_character_t *AddInhabitant(location_t *location, int type);
int AddInhabitants(location_t *location, int type, int amount);
game_character_t *FindInhabitant(int type);
int MoveInhabitant(game_character_t *inhabitant, int destination);
int RemoveInhabitant(location_t *location, game_character_t *inhabitant);
int DeleteInhabitant(location_t *location, game_character_t *inhabitant);
int VisibleInhabitants(location_t *location);
int HandleMovementMenuInput(void);
int MovePlayer(int destination);
int SearchLocation(location_t *location);
void DescribeSituation(void);
// Function prototypes for "characters.c":
int InitializeCharacter(game_character_t *p_gc, int type,
location_t *location);
int AddCompanion(game_character_t *companion);
int RemoveCompanion(game_character_t *companion);
int DeleteCompanion(game_character_t *companion);
game_character_t *AddSummonedCreature(game_character_t *summoner, int type);
int DeleteCreatureSummonedBy(game_character_t *summoner);
int DisplayCharacterData(game_character_t *p_gc);
int PrintSoulDescription(game_character_t *p_gc);
bool IsGood(game_character_t *p_gc);
bool IsEvil(game_character_t *p_gc);
bool IsNeutral(game_character_t *p_gc);
int NumberOfLanguagesKnown(game_character_t *p_gc);
int NumberOfWordsKnown(game_character_t *p_gc);
char *GetNameDefinite(game_character_t *p_gc);
char *GetNameIndefinite(game_character_t *p_gc);
char *GetNamePlural(game_character_t *p_gc);
bool CheckStatus(void);
void UpdateVisibleGameCharCounter(void);
game_character_t *GetTarget(void);
bool IsTargeted(game_character_t *p_gc, game_character_t *targets[]);
int HealGameCharacter(game_character_t *p_gc, int amount);
int DamageGameCharacter(game_character_t *p_gc, int amount);
int GainExperience(int amount);
void LevelUp(void);
void LearnLanguage(int language);
void LearnWord(int word);
// Function prototypes for "combat.c":
int AddEnemy(game_character_t *p_gc);
int AddRandomEnemy(location_t *location);
int RemoveEnemy(game_character_t *p_gc);
int DeleteEnemy(game_character_t *p_gc);
int NumberOfEnemies(void);
int VisibleEnemies(void);
int Combat(void);
void PrintCombatStatus(game_character_t *p_gc);
int EnemyAI(int index);
int HandleAttackMenuInput(void);
int Attack(game_character_t *attacker, game_character_t *defender);
bool WillingToFight(game_character_t *p_gc);
bool WillingToFlee(game_character_t *p_gc);
bool WillingToHelp(game_character_t *p_gc);
// Function prototypes for "dialogue.c":
int HandleTalkMenuInput(void);
int Dialogue(game_character_t *p_gc);
int LanguageLearningDialogue(game_character_t *p_gc);
int WordLearningDialogue(game_character_t *p_gc);
double GetPriceModifier(game_character_t *merchant);
int Transaction(game_character_t *merchant, int price);
char *LanguageName(int type);
// Function prototypes for "magic.c":
int HandleSpellMenuInput(void);
int CastSpell(game_character_t *spellcaster, char *spell,
game_character_t *targets[]);
bool CanCastBeneficialSpells(game_character_t *p_gc);
int PrintKnownWords(void);
char *GetWord(int type);
char *GetWordStartingWith(char first_letter);
char *GetWordName(int type);
int GetWordTypeFromChar(char first_letter);
bool IsSpellcaster(game_character_t *p_gc);
// Function prototypes for "item.c":
int HandleItemMenuInput(void);
int UseItem(game_character_t *p_gc, int item);
int PrintInventory(game_character_t *p_gc);
char *GetItemName(int item);
char *GetItemNamePlural(int item);
int GiveGold(game_character_t *giver, game_character_t *receiver, int amount);
int AddItem(game_character_t *receiver, int item);
int GiveItem(game_character_t *giver, game_character_t *receiver, int item);
int GiveItems(game_character_t *giver, game_character_t *receiver, int item,
int amount);
int GetItemValue(int type);
#endif // WOP_H_