#ifndef _datatypes_h_ #define _datatypes_h_ /* Copyright (c) 2013-2021 Devine Lu Linvega 2018 web port by rezmason 2021 C89 port by rezmason Permission to use, copy, modify, and distribute this software for any purpose with or without fee is hereby granted, provided that the above copyright notice and this permission notice appear in all copies. THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE. */ /* These enums, structs and unions are used all over the place. */ typedef enum { CHAPTER_ACT1, CHAPTER_ACT2, CHAPTER_ACT3, CHAPTER_ACT4, CHAPTER_ACT5, CHAPTER_END, NumberOfChapters } Chapter; /* A zone symbolizes a region of nodes that share an ambience, but also symbolizes the seal that represents that zone in-game. */ typedef enum { ZONE_NONE, ZONE_FOREST, ZONE_STONES, ZONE_RAINRE, ZONE_METAMONDST, ZONE_ANTECHANNEL, ZONE_CAPSULE, ZONE_CIRCULAR, ZONE_ENTENTE, ZONE_NATANIEV, ZONE_STUDIO, ZONE_NETHER, ZONE_TERMINAL, NumberOfZones } Zone; /* The maze puzzle's pieces perform operations on two axes of its state. */ typedef enum { MAZEAXIS_X, MAZEAXIS_Y, NumberOfMazeAxes } MazeAxis; /* The maze gives three kinds of instructions to the player. */ typedef enum { MAZEINSTRUCTION_LEFT, MAZEINSTRUCTION_STRAIGHT, MAZEINSTRUCTION_RIGHT, NumberOfMazeInstructions } MazeInstruction; /* The player's orientation is the direction in which they're facing. */ typedef enum { ORIENTATION_NORTH, ORIENTATION_EAST, ORIENTATION_SOUTH, ORIENTATION_WEST, NumberOfOrientations, ORIENTATION_NONE } Orientation; /* This is the data we load from and save to the disk. Almost all changes to the game's state are changes to this data. */ typedef struct { int windowW, windowH; int audio; char nodeName[10]; Orientation orientation; Chapter chapter; int usedWalkthrough; int completed; int clock; int energy; char fuseLocationNames[3][40]; Zone seals[2]; int studio; int secret; int time; int mazeCoord[NumberOfMazeAxes]; int loaded; } GameState; typedef struct { char fuseName[40]; int isFilledAtStart; } EnergyTerminalData; /* Different terminals perform different actions. Some actions require this additional context. */ typedef union { Zone seal; EnergyTerminalData energyTerminalData; Zone sealLock[2]; MazeAxis axis; } TerminalData; /* Terminals present part of the game's state, and change or reset it. */ typedef struct { char name[40]; TerminalData data; void (*setup)(TerminalData *data, int *isOpen, GameState *state); int (*change)(TerminalData *data, int *isOpen, GameState *state); void (*reset)(TerminalData *data, GameState *state); } Terminal; /* Different doors unlock according to different requirements. Some doors' locks require this additional context. */ typedef union { int clockLockIndex; int time[2]; Zone sealLocks[2][2]; Terminal *fuseTerminals[2][2]; } DoorData; /* Doors appear closed at first. If they unlock, they appear open, and the player can walk through. A door can have two locks, to lead to two separate places. */ typedef struct { char name[40]; int silent; int opens; double fadeDuration; DoorData data; void (*setup)(DoorData *data, GameState *state); int (*test)(DoorData *data, GameState *state); int (*altTest)(DoorData *data, GameState *state); } Door; struct Node; /* A subject that leads to another node. Because Hiversaires is non-euclidean, we specify each node subject's orientation to ensure the player's direction is locally consistent. */ typedef struct { struct Node *node; Orientation orientation; int mapIgnore; } NodeSubject; /* A subject that is a door, and where it leads. A door can lead to an alternate location. */ typedef struct { NodeSubject node; NodeSubject altNode; Door *door; } DoorSubject; /* A subject that is a terminal. */ typedef struct { Terminal *terminal; } TerminalSubject; /* A subject that is a maze. Like a door, the maze can lead to an alternate location. As you pass through a maze subject, it alters the maze state. */ typedef struct { NodeSubject node; NodeSubject altNode; MazeAxis axis; int changeAmount; int isExit; } MazeSubject; typedef enum { SUBJECTTYPE_NONE, SUBJECTTYPE_NODE, SUBJECTTYPE_DOOR, SUBJECTTYPE_TERMINAL, SUBJECTTYPE_MAZE } SubjectType; typedef union { NodeSubject node; DoorSubject door; TerminalSubject terminal; MazeSubject maze; } SubjectData; typedef struct { SubjectType type; SubjectData data; } Subject; /* A node is a distinct location the player can occupy. Each node can have a subject— an onscreen thing— for each cardinal direction. Each node also occupies a zone. */ typedef struct Node { char name[10]; Zone zone; Subject subjects[4]; } Node; /* A chapter lock is the requirement that must be met for the player's chapter to increment. */ typedef struct ChapterLock { int alt; char name[40]; int (*test)(struct ChapterLock *lock, Subject *subject, GameState *state); } ChapterLock; #endif