1 /*
2 Copyright (C) 2009-2021 Parallel Realities
3 
4 This program is free software; you can redistribute it and/or
5 modify it under the terms of the GNU General Public License
6 as published by the Free Software Foundation; either version 2
7 of the License, or (at your option) any later version.
8 
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
12 
13 See the GNU General Public License for more details.
14 
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA.
18 */
19 
20 #include "defs.h"
21 
22 typedef struct Texture
23 {
24 	int w, h;
25 	SDL_Texture *texture;
26 } Texture;
27 
28 typedef struct TextureCache
29 {
30 	char name[MAX_MESSAGE_LENGTH];
31 	long expiry;
32 	Texture *texture;
33 	struct TextureCache *next;
34 } TextureCache;
35 
36 typedef struct Colour
37 {
38 	int r, g, b, a;
39 } Colour;
40 
41 typedef struct Label
42 {
43 	int x, y;
44 	int r, g, b;
45 	Texture *text;
46 } Label;
47 
48 typedef struct Widget
49 {
50 	int x, y, disabled, hidden;
51 	int *value, maxValue, minValue;
52 	int r, g, b;
53 	void (*clickAction)(void);
54 	void (*rightAction)(void);
55 	void (*leftAction)(void);
56 	Label *label;
57 	Texture *normalState, *selectedState, *disabledState;
58 } Widget;
59 
60 typedef struct Menu
61 {
62 	int index, x, y, w, h, widgetCount;
63 	int startY, endY;
64 	Texture *background;
65 	Widget **widgets;
66 	Label **labels;
67 	void (*action)(void);
68 	void (*returnAction)(void);
69 } Menu;
70 
71 typedef struct BoundingBox
72 {
73 	int x, y, h, w;
74 } BoundingBox;
75 
76 typedef struct Sprite
77 {
78 	char name[MAX_FILE_LENGTH];
79 	int w, h;
80 	Texture *image;
81 	BoundingBox box;
82 } Sprite;
83 
84 typedef struct Animation
85 {
86 	int frameCount;
87 	int *frameTimer, *frameID;
88 	int *offsetX, *offsetY;
89 } Animation;
90 
91 typedef struct Input
92 {
93 	int left, right, up, down, add, remove;
94 	int previous, next, load, save, jump;
95 	int mouseX, mouseY, toggle;
96 	int activate, attack, snap, cut;
97 	int interact, grabbing, block, inventory;
98 	int lastPressedKey, xAxisMoved, yAxisMoved;
99 } Input;
100 
101 typedef struct CustomAction
102 {
103 	int thinkTime, counter;
104 	float value;
105 	void (*action)(int *, int *, float *);
106 } CustomAction;
107 
108 typedef struct EntityAnimation
109 {
110 	char name[MAX_VALUE_LENGTH];
111 	int id;
112 } EntityAnimation;
113 
114 typedef struct Entity
115 {
116 	int inUse, w, h, offsetX, offsetY;
117 	int thinkTime, face, layer;
118 	int currentFrame;
119 	int type;
120 	int currentAnim, health, alpha;
121 	int maxHealth, damage, active, maxThinkTime;
122 	int targetX, targetY, environment, element;
123 	int mental, spawnTime;
124 	unsigned long flags;
125 	float x, y, dirX, dirY, frameSpeed, frameTimer;
126 	float startX, startY, endX, endY;
127 	float originalSpeed, speed, weight, originalWeight;
128 	char name[MAX_VALUE_LENGTH], objectiveName[MAX_VALUE_LENGTH], requires[MAX_VALUE_LENGTH];
129 	char description[MAX_MESSAGE_LENGTH], animationName[MAX_VALUE_LENGTH];
130 	EntityAnimation animation[MAX_ANIMATION_TYPES];
131 	struct Entity *standingOn, *parent, *target, *head;
132 	BoundingBox box;
133 	CustomAction customAction[MAX_CUSTOM_ACTIONS];
134 	void (*action)(void);
135 	void (*activate)(int);
136 	int (*draw)(void);
137 	void (*fallout)(void);
138 	void (*touch)(struct Entity *);
139 	void (*animationCallback)(void);
140 	void (*takeDamage)(struct Entity *, int);
141 	void (*die)(void);
142 	void (*reactToBlock)(struct Entity *);
143 	void (*pain)(void);
144 	void (*resumeNormalFunction)(void);
145 	void (*creditsAction)(void);
146 } Entity;
147 
148 typedef struct AnimTile
149 {
150 	int tileCount, tileIndex;
151 	int *tile;
152 } AnimTile;
153 
154 typedef struct Map
155 {
156 	char filename[MAX_VALUE_LENGTH], tilesetName[MAX_VALUE_LENGTH], ambienceName[MAX_VALUE_LENGTH];
157 	char musicName[MAX_VALUE_LENGTH], mapName[MAX_VALUE_LENGTH];
158 	int startX, startY;
159 	int maxX, maxY, thinkTime;
160 	int minX, minY, blendTime;
161 	int forceMinY, darkMap;
162 	int animTileTotal, animThinkTime;
163 	int cameraMinX, cameraMinY, cameraMaxX, cameraMaxY;
164 	int playerMinX, playerMaxX;
165 	int tile[MAX_MAP_Y][MAX_MAP_X];
166 	int hasAmbience, backgroundStartX[2], backgroundStartY[2];
167 	int wrapX[2], wrapY[2];
168 	float backgroundSpeed[2], cameraSpeed;
169 	float cameraX, cameraY;
170 	AnimTile *animTile;
171 	Entity *targetEntity;
172 	Texture *background[2];
173 	Mix_Chunk *ambience[MAX_AMBIENT_SOUNDS];
174 } Map;
175 
176 typedef struct Sound
177 {
178 	char name[MAX_VALUE_LENGTH];
179 	Mix_Chunk *effect;
180 } Sound;
181 
182 typedef struct AlphaSurface
183 {
184 	int x, y, w, h;
185 	int r, g, b;
186 } AlphaSurface;
187 
188 typedef struct Game
189 {
190 	int thinkTime, weatherType, weatherThinkTime;
191 	int audio, hasConfig, fullscreen, gameOverX;
192 	int sfxDefaultVolume, musicDefaultVolume;
193 	int showHints, status, fps, audioQuality;
194 	int offsetX, offsetY, shakeThinkTime, shakeStrength;
195 	int gameType, transitionX, transitionY, previousStatus;
196 	int frames, drawScreen, paused, firstRun, audioDisabled;
197 	int kills, batsDrowned, timesEaten, cheating;
198 	int attacksBlocked, timeSpentAsSlime, arrowsFired;
199 	int secretsFound, alphaTime, canContinue, continues;
200 	int disableJoystick, mapExitable, cheatsEnabled;
201 	int infiniteEnergy, infiniteArrows, lavaIsFatal;
202 	int saveOnExit, overrideMusic, showHUD;
203 	int fontSizeSmall, fontSizeLarge;
204 	unsigned int distanceTravelled;
205 	float checkpointX, checkpointY;
206 	long startTicks, endTicks, playTime;
207 	char nextMap[MAX_VALUE_LENGTH], playerStart[MAX_VALUE_LENGTH];
208 	char customFont[MAX_FILE_LENGTH];
209 	void (*drawMenu)(void);
210 	void (*weatherAction)(void);
211 	void (*weatherDraw)(void);
212 	void (*transition)(void);
213 	void (*transitionCallback)(void);
214 	Menu *menu;
215 	AlphaSurface alphaSurface;
216 	SDL_Renderer *renderer;
217 	SDL_Window *window;
218 	Texture *screen, *gameOverSurface, *tempSurface, *pauseSurface;
219 	TTF_Font *font, *largeFont;
220 	SDL_Joystick *joystick;
221 } Game;
222 
223 typedef struct Cursor
224 {
225 	int x, y, tileID, entityType;
226 	int type, snapToGrid;
227 	Entity entity;
228 } Cursor;
229 
230 typedef struct Message
231 {
232 	char text[MAX_MESSAGE_LENGTH];
233 	int thinkTime, r, g, b;
234 	Texture *surface;
235 	struct Message *next;
236 } Message;
237 
238 typedef struct Inventory
239 {
240 	int selectedIndex, x, y, cursorIndex;
241 	int hasBow, hasLightningSword;
242 	Entity item[MAX_INVENTORY_ITEMS];
243 	Texture *background, *cursor, *description, *objectives;
244 } Inventory;
245 
246 typedef struct Droplet
247 {
248 	int active;
249 	float x, y, dirX, dirY;
250 } Droplet;
251 
252 typedef struct Properties
253 {
254 	char name[MAX_VALUE_LENGTH], key[MAX_PROPS_ENTRIES][MAX_VALUE_LENGTH], value[MAX_PROPS_ENTRIES][MAX_VALUE_LENGTH];
255 	EntityAnimation animations[MAX_ANIMATION_TYPES];
256 } Properties;
257 
258 typedef struct Constructor
259 {
260 	char name[MAX_VALUE_LENGTH];
261 	Entity *(*construct)(int, int, char *);
262 } Constructor;
263 
264 typedef struct Target
265 {
266 	int x, y, active;
267 	char name[MAX_VALUE_LENGTH];
268 } Target;
269 
270 typedef struct Type
271 {
272 	int id;
273 	char name[MAX_VALUE_LENGTH];
274 } Type;
275 
276 typedef struct Trigger
277 {
278 	char triggerName[MAX_VALUE_LENGTH], targetName[MAX_VALUE_LENGTH];
279 	int inUse, targetType, count, total;
280 } Trigger;
281 
282 typedef struct Objective
283 {
284 	int inUse, active, completed;
285 	char name[MAX_MESSAGE_LENGTH], completionTrigger[MAX_VALUE_LENGTH];
286 } Objective;
287 
288 typedef struct Script
289 {
290 	int line, lineCount, skipping, thinkTime, counter;
291 	int requiredDepth, currentDepth, yesNoResult;
292 	char **text;
293 	Menu *menu;
294 	void (*draw)(void);
295 } Script;
296 
297 typedef struct Hud
298 {
299 	int thinkTime, *bossHealth, bossHealthIndex, bossMaxHealth, medalThinkTime, quantity;
300 	Texture *itemBox, *heart, *whiteHeart, *emptyHeart, *spotlight, *medalTextSurface, *quantitySurface;
301 	Texture *medalSurface[4], *disabledMedalSurface;
302 	Texture *slimeTimerSurface;
303 	Message infoMessage;
304 } Hud;
305 
306 typedef struct MedalQueue
307 {
308 	int processing, thinkTime;
309 	Message medalMessage;
310 } MedalQueue;
311 
312 typedef struct Medal
313 {
314 	char code[MAX_VALUE_LENGTH], description[MAX_MESSAGE_LENGTH];
315 	int medalType, obtained, hidden;
316 } Medal;
317 
318 typedef struct Control
319 {
320 	int deadZone;
321 	int button[MAX_CONTROLS];
322 } Control;
323 
324 typedef struct EntityList
325 {
326 	Entity *entity;
327 	struct EntityList *next;
328 } EntityList;
329 
330 typedef struct Grid
331 {
332 	int count;
333 	EntityList listHead;
334 	struct Grid *next;
335 } Grid;
336 
337 typedef struct FileData
338 {
339 	char filename[MAX_FILE_LENGTH];
340 	int32_t fileSize, compressedSize, offset;
341 } FileData;
342 
343 typedef struct ContinueData
344 {
345 	char boss[MAX_VALUE_LENGTH];
346 	int cameraMinX, cameraMinY, cameraMaxX, cameraMaxY;
347 	int cameraFollow;
348 	void (*resumeAction)(void);
349 } ContinueData;
350 
351 typedef struct DialogBox
352 {
353 	int thinkTime;
354 	Texture *dialogSurface;
355 } DialogBox;
356 
357 typedef struct CreditLine
358 {
359 	char text[MAX_LINE_LENGTH];
360 	int r, g, b;
361 	float x, y;
362 	Texture *textImage;
363 } CreditLine;
364 
365 typedef struct Credits
366 {
367 	int line, lineCount, entityID, fading, alpha;
368 	int startDelay, nextEntityDelay, status;
369 	float speed;
370 	CreditLine *creditLine;
371 	AlphaSurface fadeSurface;
372 	Texture *edgarLogo, *prLogo;
373 } Credits;
374 
375 typedef struct Title
376 {
377 	int thinkTime, continueSlot;
378 	Texture *edgarLogo, *copyright, *startButton;
379 } Title;
380 
381 typedef struct Bucket
382 {
383 	char *key, *value;
384 	struct Bucket *next;
385 } Bucket;
386 
387 typedef struct HashTable
388 {
389 	Bucket **bucket;
390 	int *bucketCount;
391 } HashTable;
392 
393 typedef struct MOHeader
394 {
395 	int32_t magicNumber, version, stringCount;
396 	int32_t originalOffset, translationOffset;
397 } MOHeader;
398 
399 typedef struct MOEntry
400 {
401 	int32_t length, offset;
402 } MOEntry;
403