1 /*-------------------------------------------------------------------------------
2 
3 	BARONY
4 	File: main.hpp
5 	Desc: contains some prototypes as well as various type definitions
6 
7 	Copyright 2013-2016 (c) Turning Wheel LLC, all rights reserved.
8 	See LICENSE for details.
9 
10 -------------------------------------------------------------------------------*/
11 
12 #pragma once
13 
14 #ifdef __arm__
15 typedef float real_t;
16 #else
17 typedef double real_t;
18 #endif
19 
20 #include <algorithm> //For min and max, because the #define breaks everything in c++.
21 #include <iostream>
22 #include <list>
23 #include <string>
24 #include <vector>
25 //using namespace std; //For C++ strings //This breaks messages on certain systems, due to template<class _CharT> class std::__cxx11::messages
26 using std::string; //Instead of including an entire namespace, please explicitly include only the parts you need, and check for conflicts as reasonably possible.
27 #include <map>
28 #include <unordered_map>
29 #include <unordered_set>
30 #include <set>
31 #include <functional>
32 #include "Config.hpp"
33 #include "physfs.h"
34 
35 #ifdef STEAMWORKS
36 #define STEAM_APPID 371970
37 #endif
38 
39 enum ESteamStatTypes
40 {
41 	STEAM_STAT_INT = 0,
42 	STEAM_STAT_FLOAT = 1,
43 	STEAM_STAT_AVGRATE = 2,
44 };
45 
46 struct SteamStat_t
47 {
48 	int m_ID;
49 	ESteamStatTypes m_eStatType;
50 	const char *m_pchStatName;
51 	int m_iValue;
52 	float m_flValue;
53 	float m_flAvgNumerator;
54 	float m_flAvgDenominator;
55 };
56 
57 struct SteamGlobalStat_t
58 {
59 	int m_ID;
60 	ESteamStatTypes m_eStatType;
61 	const char *m_pchStatName;
62 	int64_t m_iValue;
63 	float m_flValue;
64 	float m_flAvgNumerator;
65 	float m_flAvgDenominator;
66 };
67 
68 extern bool spamming;
69 extern bool showfirst;
70 extern bool logCheckObstacle;
71 extern int logCheckObstacleCount;
72 extern bool logCheckMainLoopTimers;
73 extern bool autoLimbReload;
74 
75 #include <dirent.h>
76 #include <stdlib.h>
77 #include <stdio.h>
78 #include <math.h>
79 #include <time.h>
80 #include <fcntl.h>
81 #ifndef WINDOWS
82 #include <unistd.h>
83 #include <limits.h>
84 #endif
85 #include <string.h>
86 #include <ctype.h>
87 #ifdef WINDOWS
88 #define GL_GLEXT_PROTOTYPES
89 #define PATH_MAX 1024
90 #include <windows.h>
91 #include <Dbghelp.h>
92 #undef min
93 #undef max
94 #endif
95 #ifdef APPLE
96 #include <Cocoa/Cocoa.h>
97 //#include <OpenGL/OpenGL.h>
98 #define GL_GLEXT_PROTOTYPES
99 #include <GLUT/glut.h>
100 #include <OpenGL/gl3ext.h>
101 #include <OpenGL/gl3.h>
102 #include <SDL2/SDL_opengl.h>
103 #else
104 #define GL_GLEXT_PROTOTYPES
105 #include <GL/gl.h>
106 #include <GL/glu.h>
107 #include <GL/glext.h>
108 #include "SDL_opengl.h"
109 #endif
110 #ifdef APPLE
111 #include <SDL2/SDL.h>
112 #else
113 #include "SDL.h"
114 #endif
115 #ifdef WINDOWS
116 #include "SDL_syswm.h"
117 #endif
118 #ifdef APPLE
119 #include <SDL2_image/SDL_image.h>
120 #else
121 #include "SDL_image.h"
122 #endif
123 //#include "SDL_mixer.h"
124 #ifdef APPLE
125 #include <SDL2_net/SDL_net.h>
126 #else
127 #include "SDL_net.h"
128 #endif
129 #ifdef APPLE
130 #include <SDL2_ttf/SDL_ttf.h>
131 #else
132 #include "SDL_ttf.h"
133 #endif
134 //#include "sprig.h"
135 #include "savepng.hpp"
136 
137 //Ifdef steam or something?
138 #ifdef STEAMWORKS
139 //#include <steamworks_cwrapper/steam_wrapper.h>
140 #endif
141 
142 #ifdef _MSC_VER
143 #include <io.h>
144 #define F_OK 0	// check for existence
145 #define X_OK 1	// check for execute permission
146 #define W_OK 2	// check for write permission
147 #define R_OK 4	// check for read permission
148 
149 #if _MSC_VER != 1900 //Don't need this if running visual studio 2015.
150 #define snprintf _snprintf
151 #endif
152 #define access _access
153 #endif
154 
155 #define PI 3.14159265358979323846
156 
157 extern FILE* logfile;
158 static const int MESSAGE_LIST_SIZE_CAP = 100; //Cap off the message in-game log to 100 messages. Otherwise, game will eat up more RAM and more CPU the longer it goes on.
159 
160 class Item;
161 //enum Item;
162 //enum Status;
163 
164 #ifdef WINDOWS
165 extern PFNGLGENBUFFERSPROC SDL_glGenBuffers;
166 extern PFNGLBINDBUFFERPROC SDL_glBindBuffer;
167 extern PFNGLBUFFERDATAPROC SDL_glBufferData;
168 extern PFNGLDELETEBUFFERSPROC SDL_glDeleteBuffers;
169 extern PFNGLGENVERTEXARRAYSPROC SDL_glGenVertexArrays;
170 extern PFNGLBINDVERTEXARRAYPROC SDL_glBindVertexArray;
171 extern PFNGLDELETEVERTEXARRAYSPROC SDL_glDeleteVertexArrays;
172 extern PFNGLENABLEVERTEXATTRIBARRAYPROC SDL_glEnableVertexAttribArray;
173 extern PFNGLVERTEXATTRIBPOINTERPROC SDL_glVertexAttribPointer;
174 #else
175 #define SDL_glGenBuffers glGenBuffers
176 #define SDL_glBindBuffer glBindBuffer
177 #define SDL_glBufferData glBufferData
178 #define SDL_glDeleteBuffers glDeleteBuffers
179 #define SDL_glGenVertexArrays glGenVertexArrays
180 #define SDL_glBindVertexArray glBindVertexArray
181 #define SDL_glDeleteVertexArrays glDeleteVertexArrays
182 #define SDL_glEnableVertexAttribArray glEnableVertexAttribArray
183 #define SDL_glVertexAttribPointer glVertexAttribPointer
184 #endif
185 
186 #define AVERAGEFRAMES 32
187 
188 extern bool stop;
189 
190 // impulses
191 #define IN_FORWARD 0
192 #define IN_LEFT 1
193 #define IN_BACK 2
194 #define IN_RIGHT 3
195 #define IN_TURNL 4
196 #define IN_TURNR 5
197 #define IN_UP 6
198 #define IN_DOWN 7
199 #define IN_CHAT 8
200 #define IN_COMMAND 9
201 #define IN_STATUS 10
202 #define IN_SPELL_LIST 11
203 #define IN_CAST_SPELL 12
204 #define IN_DEFEND 13
205 #define IN_ATTACK 14
206 #define IN_USE 15
207 #define IN_AUTOSORT 16
208 #define IN_MINIMAPSCALE 17
209 #define IN_TOGGLECHATLOG 18
210 #define IN_FOLLOWERMENU 19
211 #define IN_FOLLOWERMENU_LASTCMD 20
212 #define IN_FOLLOWERMENU_CYCLENEXT 21
213 #define IN_HOTBAR_SCROLL_LEFT 22
214 #define IN_HOTBAR_SCROLL_RIGHT 23
215 #define IN_HOTBAR_SCROLL_SELECT 24
216 #define NUMIMPULSES 25
217 static const std::vector<std::string> impulseStrings =
218 {
219 	"IN_FORWARD",
220 	"IN_LEFT",
221 	"IN_BACK",
222 	"IN_RIGHT",
223 	"IN_TURNL",
224 	"IN_TURNR",
225 	"IN_UP",
226 	"IN_DOWN",
227 	"IN_CHAT",
228 	"IN_COMMAND",
229 	"IN_STATUS",
230 	"IN_SPELL_LIST",
231 	"IN_CAST_SPELL",
232 	"IN_DEFEND",
233 	"IN_ATTACK",
234 	"IN_USE",
235 	"IN_AUTOSORT",
236 	"IN_MINIMAPSCALE",
237 	"IN_TOGGLECHATLOG",
238 	"IN_FOLLOWERMENU",
239 	"IN_FOLLOWERMENU_LASTCMD",
240 	"IN_FOLLOWERMENU_CYCLENEXT",
241 	"IN_HOTBAR_SCROLL_LEFT",
242 	"IN_HOTBAR_SCROLL_RIGHT",
243 	"IN_HOTBAR_SCROLL_SELECT"
244 };
245 
246 //Joystick/gamepad impulses
247 //TODO: Split bindings into three subcategories: Bifunctional, Game Exclusive, Menu Exclusive.
248 
249 //Bifunctional:
250 static const unsigned INJOY_STATUS = 0;
251 static const unsigned INJOY_SPELL_LIST = 1;
252 static const unsigned INJOY_PAUSE_MENU = 2; //Also acts as the back key/escape key in limited situations.
253 static const unsigned INJOY_DPAD_LEFT = 3;
254 static const unsigned INJOY_DPAD_RIGHT = 4;
255 static const unsigned INJOY_DPAD_UP = 5;
256 static const unsigned INJOY_DPAD_DOWN = 6;
257 
258 //Menu Exclusive:
259 static const unsigned INJOY_MENU_LEFT_CLICK = 7;
260 static const unsigned INJOY_MENU_NEXT = 8;
261 static const unsigned INJOY_MENU_CANCEL = 9; //Basically the "b" button. Go back, cancel things, close dialogues...etc.
262 static const unsigned INJOY_MENU_SETTINGS_NEXT = 10;
263 static const unsigned INJOY_MENU_SETTINGS_PREV = 11; //TODO: Only one "cycle tabs" binding?
264 static const unsigned INJOY_MENU_REFRESH_LOBBY = 12;
265 static const unsigned INJOY_MENU_DONT_LOAD_SAVE = 13;
266 static const unsigned INJOY_MENU_RANDOM_NAME = 14;
267 static const unsigned INJOY_MENU_RANDOM_CHAR = 15; //Clears hotbar slot in-inventory.
268 static const unsigned INJOY_MENU_INVENTORY_TAB = 16; //Optimally, I'd like to just use one trigger to toggle between the two, but there's some issues with analog triggers.
269 static const unsigned INJOY_MENU_MAGIC_TAB = 17;
270 static const unsigned INJOY_MENU_USE = 18; //Opens the context menu in the inventory. Also grabs the highlighted item from a chest.
271 static const unsigned INJOY_MENU_HOTBAR_CLEAR = 19; //Clears hotbar slot in-inventory.
272 static const unsigned INJOY_MENU_DROP_ITEM = 20;
273 static const unsigned INJOY_MENU_CHEST_GRAB_ALL = 21;
274 static const unsigned INJOY_MENU_CYCLE_SHOP_LEFT = 22;
275 static const unsigned INJOY_MENU_CYCLE_SHOP_RIGHT = 23;
276 static const unsigned INJOY_MENU_BOOK_PREV = 24;
277 static const unsigned INJOY_MENU_BOOK_NEXT = 25;
278 
279 static const unsigned INDEX_JOYBINDINGS_START_MENU = 7;
280 
281 //Game Exclusive:
282 //These should not trigger if the in-game interfaces are brought up (!shootmode). Inventory, books, shops, chests, etc.
283 static const unsigned INJOY_GAME_USE = 26; //Used in-game for right click. NOTE: Not used in-inventory for in-world identification. Because clicking is disabled and whatnot. (Or can be done?)
284 static const unsigned INJOY_GAME_DEFEND = 27;
285 static const unsigned INJOY_GAME_ATTACK = 28;
286 static const unsigned INJOY_GAME_CAST_SPELL = 29;
287 static const unsigned INJOY_GAME_HOTBAR_ACTIVATE = 30; //Activates hotbar slot in-game.
288 static const unsigned INJOY_GAME_HOTBAR_PREV = 31;
289 static const unsigned INJOY_GAME_HOTBAR_NEXT = 32;
290 static const unsigned INJOY_GAME_MINIMAPSCALE = 33;
291 static const unsigned INJOY_GAME_TOGGLECHATLOG = 34;
292 static const unsigned INJOY_GAME_FOLLOWERMENU = 35;
293 static const unsigned INJOY_GAME_FOLLOWERMENU_LASTCMD = 36;
294 static const unsigned INJOY_GAME_FOLLOWERMENU_CYCLE = 37;
295 
296 static const unsigned INDEX_JOYBINDINGS_START_GAME = 26;
297 
298 static const unsigned NUM_JOY_IMPULSES = 38;
299 
300 static const unsigned UNBOUND_JOYBINDING = 399;
301 
302 static const int NUM_HOTBAR_CATEGORIES = 12; // number of filters for auto add hotbar items
303 
304 static const int NUM_AUTOSORT_CATEGORIES = 12; // number of categories for autosort
305 
306 static const int RIGHT_CLICK_IMPULSE = 285; // right click
307 
308 // since SDL2 gets rid of these and we're too lazy to fix them...
309 #define SDL_BUTTON_WHEELUP 4
310 #define SDL_BUTTON_WHEELDOWN 5
311 
312 //Time in seconds before the in_dev warning disappears.
313 #define indev_displaytime 7000
314 
315 // view structure
316 typedef struct view_t
317 {
318 	real_t x, y, z;
319 	real_t ang;
320 	real_t vang;
321 	Sint32 winx, winy, winw, winh;
322 } view_t;
323 
324 class Entity; //TODO: Bugger?
325 
326 // node structure
327 typedef struct node_t
328 {
329 	struct node_t* next;
330 	struct node_t* prev;
331 	struct list_t* list;
332 	void* element;
333 	void (*deconstructor)(void* data);
334 	Uint32 size;
335 } node_t;
336 
337 // list structure
338 typedef struct list_t
339 {
340 	node_t* first;
341 	node_t* last;
342 } list_t;
343 extern list_t button_l;
344 extern list_t light_l;
345 
346 // game world structure
347 typedef struct map_t
348 {
349 	char name[32];   // name of the map
350 	char author[32]; // author of the map
351 	unsigned int width, height, skybox;  // size of the map + skybox
352 	Sint32 flags[16];
353 	Sint32* tiles;
354 	std::unordered_map<Sint32, node_t*> entities_map;
355 	list_t* entities;
356 	list_t* creatures; //A list of Entity* pointers.
357 } map_t;
358 
359 #define MAPLAYERS 3 // number of layers contained in a single map
360 #define OBSTACLELAYER 1 // obstacle layer in map
361 #define MAPFLAGS 16 // map flags for custom properties
362 #define MAPFLAGTEXTS 19 // map flags for custom properties
363 // names for the flag indices
364 static const int MAP_FLAG_CEILINGTILE = 0;
365 static const int MAP_FLAG_DISABLETRAPS = 1;
366 static const int MAP_FLAG_DISABLEMONSTERS = 2;
367 static const int MAP_FLAG_DISABLELOOT = 3;
368 static const int MAP_FLAG_GENBYTES1 = 4;
369 static const int MAP_FLAG_GENBYTES2 = 5;
370 static const int MAP_FLAG_GENBYTES3 = 6;
371 static const int MAP_FLAG_GENBYTES4 = 7;
372 static const int MAP_FLAG_GENBYTES5 = 8;
373 static const int MAP_FLAG_GENBYTES6 = 9;
374 // indices for mapflagtext, 4 of these are stored as bytes within the above GENBYTES
375 static const int MAP_FLAG_GENTOTALMIN = 4;
376 static const int MAP_FLAG_GENTOTALMAX = 5;
377 static const int MAP_FLAG_GENMONSTERMIN = 6;
378 static const int MAP_FLAG_GENMONSTERMAX = 7;
379 static const int MAP_FLAG_GENLOOTMIN = 8;
380 static const int MAP_FLAG_GENLOOTMAX = 9;
381 static const int MAP_FLAG_GENDECORATIONMIN = 10;
382 static const int MAP_FLAG_GENDECORATIONMAX = 11;
383 static const int MAP_FLAG_DISABLEDIGGING = 12;
384 static const int MAP_FLAG_DISABLETELEPORT = 13;
385 static const int MAP_FLAG_DISABLELEVITATION = 14;
386 static const int MAP_FLAG_GENADJACENTROOMS = 15;
387 static const int MAP_FLAG_DISABLEOPENING = 16;
388 static const int MAP_FLAG_DISABLEMESSAGES = 17;
389 static const int MAP_FLAG_DISABLEHUNGER = 18;
390 
391 #define MFLAG_DISABLEDIGGING ((map.flags[MAP_FLAG_GENBYTES3] >> 24) & 0xFF) // first leftmost byte
392 #define MFLAG_DISABLETELEPORT ((map.flags[MAP_FLAG_GENBYTES3] >> 16) & 0xFF) // second leftmost byte
393 #define MFLAG_DISABLELEVITATION ((map.flags[MAP_FLAG_GENBYTES3] >> 8) & 0xFF) // third leftmost byte
394 #define MFLAG_GENADJACENTROOMS ((map.flags[MAP_FLAG_GENBYTES3] >> 0) & 0xFF) // fourth leftmost byte
395 #define MFLAG_DISABLEOPENING ((map.flags[MAP_FLAG_GENBYTES4] >> 24) & 0xFF) // first leftmost byte
396 #define MFLAG_DISABLEMESSAGES ((map.flags[MAP_FLAG_GENBYTES4] >> 16) & 0xFF) // second leftmost byte
397 #define MFLAG_DISABLEHUNGER ((map.flags[MAP_FLAG_GENBYTES4] >> 8) & 0xFF) // third leftmost byte
398 
399 // delete entity structure
400 typedef struct deleteent_t
401 {
402 	Uint32 uid;
403 	Uint32 tries;
404 } deleteent_t;
405 #define MAXTRIES 6 // max number of attempts on a packet
406 #define MAXDELETES 2 // max number of packets resent in a frame
407 
408 // pathnode struct
409 typedef struct pathnode_t
410 {
411 	struct pathnode_t* parent;
412 	Sint32 x, y;
413 	Uint32 g, h;
414 	node_t* node;
415 } pathnode_t;
416 
417 // hit structure
418 #define HORIZONTAL 1
419 #define VERTICAL 2
420 typedef struct hit_t
421 {
422 	real_t x, y;
423 	int mapx, mapy;
424 	Entity* entity;
425 	int side;
426 } hit_t;
427 extern hit_t hit;
428 
429 // button structure
430 typedef struct button_t
431 {
432 	char label[32];      // button label
433 	Sint32 x, y;         // onscreen position
434 	Uint32 sizex, sizey; // size of the button
435 	Uint8 visible;       // invisible buttons are ignored by the handler
436 	Uint8 focused;       // allows this button to function when a subwindow is open
437 	SDL_Keycode key;     // key shortcut to activate button
438 	int joykey;          // gamepad button used to activate this button.
439 	bool pressed;        // whether the button is being pressed or not
440 	bool needclick;      // involved in triggering buttons
441 	bool outline;        // draw golden border if true. For such things as indicated which settings tab gamepad has selected.
442 
443 	// a pointer to the button's location in a list
444 	node_t* node;
445 
446 	void (*action)(struct button_t* my);
447 } button_t;
448 
449 // voxel structure
450 typedef struct voxel_t
451 {
452 	Sint32 sizex, sizey, sizez;
453 	Uint8* data;
454 	Uint8 palette[256][3];
455 } voxel_t;
456 
457 // vertex structure
458 typedef struct vertex_t
459 {
460 	real_t x, y, z;
461 } vertex_t;
462 
463 // quad structure
464 typedef struct polyquad_t
465 {
466 	vertex_t vertex[4];
467 	Uint8 r, g, b;
468 	int side;
469 } polyquad_t;
470 
471 // triangle structure
472 typedef struct polytriangle_t
473 {
474 	vertex_t vertex[3];
475 	Uint8 r, g, b;
476 } polytriangle_t;
477 
478 // polymodel structure
479 typedef struct polymodel_t
480 {
481 	polytriangle_t* faces;
482 	Uint32 numfaces;
483 	GLuint vbo;
484 	GLuint colors;
485 	GLuint colors_shifted;
486 	GLuint va;
487 } polymodel_t;
488 
489 // string structure
490 typedef struct string_t
491 {
492 	Uint32 lines;
493 	char* data;
494 	node_t* node;
495 	Uint32 color;
496 } string_t;
497 
498 // door structure (used for map generation)
499 typedef struct door_t
500 {
501 	Sint32 x, y;
502 	Sint32 dir; // 0: east, 1: south, 2: west, 3: north
503 } door_t;
504 
505 #define CLIPNEAR 2
506 #define CLIPFAR 1024
507 #define TEXTURESIZE 32
508 #define TEXTUREPOWER 5 // power of 2 that texture size is, ie pow(2,TEXTUREPOWER) = TEXTURESIZE
509 #define MAXPLAYERS 4
510 #ifdef BARONY_SUPER_MULTIPLAYER
511 #define MAXPLAYERS 16
512 #endif
513 
514 // shaking/bobbing, that sort of thing
515 struct cameravars_t {
516 	real_t shakex;
517 	real_t shakex2;
518 	int shakey;
519 	int shakey2;
520 };
521 extern cameravars_t cameravars[MAXPLAYERS];
522 
523 extern int game;
524 extern bool loading;
525 extern SDL_TimerID timer;
526 extern SDL_Window* screen;
527 #ifdef APPLE
528 extern SDL_Renderer* renderer;
529 #else
530 extern SDL_GLContext renderer;
531 #endif
532 extern SDL_Surface* mainsurface;
533 extern SDL_Event event;
534 extern bool firstmouseevent;
535 extern char const * window_title;
536 extern Sint32 fullscreen;
537 extern bool borderless;
538 extern bool smoothlighting;
539 extern Sint32 xres;
540 extern Sint32 yres;
541 extern int mainloop;
542 extern Uint32 ticks;
543 extern Uint32 lastkeypressed;
544 extern Sint8 keystatus[512];
545 extern char* inputstr;
546 extern int inputlen;
547 extern string lastname;
548 extern int lastCreatedCharacterClass;
549 extern int lastCreatedCharacterAppearance;
550 extern int lastCreatedCharacterSex;
551 extern int lastCreatedCharacterRace;
552 static const unsigned NUM_MOUSE_STATUS = 6;
553 extern Sint8 mousestatus[NUM_MOUSE_STATUS];
554 //extern Sint8 omousestatus[NUM_MOUSE_STATUS];
555 const int NUM_JOY_STATUS = 32;
556 extern Sint8 joystatus[NUM_JOY_STATUS];
557 const int NUM_JOY_TRIGGER_STATUS = 2;
558 extern Sint8 joy_trigger_status[NUM_JOY_TRIGGER_STATUS]; //0 = left, 1 = right.
559 extern Uint32 cursorflash;
560 extern Sint32 camx, camy;
561 extern Sint32 newcamx, newcamy;
562 extern int subwindow;
563 extern int subx1, subx2, suby1, suby2;
564 extern char subtext[1024];
565 extern int rscale;
566 extern real_t vidgamma;
567 extern bool verticalSync;
568 extern bool showStatusEffectIcons;
569 extern bool minimapPingMute;
570 extern bool mute_audio_on_focus_lost;
571 extern bool mute_player_monster_sounds;
572 extern int minimapTransparencyForeground;
573 extern int minimapTransparencyBackground;
574 extern int minimapScale;
575 extern int minimapObjectZoom;
576 extern int minimapScaleQuickToggle;
577 extern bool softwaremode;
578 extern real_t* zbuffer;
579 extern Sint32* lightmap;
580 extern Sint32* lightmapSmoothed;
581 extern bool* vismap;
582 extern Entity** clickmap;
583 extern list_t entitiesdeleted;
584 extern Sint32 multiplayer;
585 extern bool directConnect;
586 extern bool client_disconnected[MAXPLAYERS];
587 extern view_t cameras[MAXPLAYERS];
588 extern view_t menucam;
589 extern int minotaurlevel;
590 #define SINGLE 0
591 #define SERVER 1
592 #define CLIENT 2
593 #define DIRECTSERVER 3
594 #define DIRECTCLIENT 4
595 #define SERVERCROSSPLAY 5
596 
597 // language stuff
598 #define NUMLANGENTRIES 4000
599 extern char languageCode[32];
600 extern char** language;
601 
602 // random game defines
603 extern bool movie;
604 extern bool genmap;
605 extern char classtoquickstart[256];
606 
607 // commands
608 extern list_t messages;
609 extern list_t command_history;
610 extern node_t* chosen_command;
611 extern bool command;
612 extern char command_str[128];
613 
614 // network definitions
615 extern IPaddress net_server;
616 extern IPaddress* net_clients;
617 extern UDPsocket net_sock;
618 extern UDPpacket* net_packet;
619 extern TCPsocket net_tcpsock;
620 extern TCPsocket* net_tcpclients;
621 extern SDLNet_SocketSet tcpset;
622 
623 #define MAXTEXTURES 10240
624 #define MAXBUFFERS 256
625 
626 #include "hash.hpp"
627 
628 // various definitions
629 extern map_t map;
630 extern list_t ttfTextHash[HASH_SIZE];
631 extern TTF_Font* ttf8;
632 #define TTF8_WIDTH 7
633 #define TTF8_HEIGHT 12
634 extern TTF_Font* ttf12;
635 #define TTF12_WIDTH 9
636 #define TTF12_HEIGHT 16
637 extern TTF_Font* ttf16;
638 #define TTF16_WIDTH 12
639 #define TTF16_HEIGHT 22
640 extern SDL_Surface* font8x8_bmp;
641 extern SDL_Surface* font12x12_bmp;
642 extern SDL_Surface* font16x16_bmp;
643 extern SDL_Surface* fancyWindow_bmp;
644 extern SDL_Surface** sprites;
645 extern SDL_Surface** tiles;
646 extern std::unordered_map<std::string, SDL_Surface*> achievementImages;
647 extern std::unordered_map<std::string, std::string> achievementNames;
648 extern std::unordered_map<std::string, std::string> achievementDesc;
649 extern std::unordered_set<std::string> achievementHidden;
650 typedef std::function<bool(std::pair<std::string, std::string>, std::pair<std::string, std::string>)> Comparator;
651 extern std::set<std::pair<std::string, std::string>, Comparator> achievementNamesSorted;
652 extern std::unordered_map<std::string, int> achievementProgress;
653 extern std::unordered_map<std::string, int64_t> achievementUnlockTime;
654 extern std::unordered_set<std::string> achievementUnlockedLookup;
655 extern voxel_t** models;
656 extern polymodel_t* polymodels;
657 extern bool useModelCache;
658 extern Uint32 imgref, vboref;
659 extern const Uint32 ttfTextCacheLimit;
660 extern GLuint* texid;
661 extern bool disablevbos;
662 extern Uint32 fov;
663 extern Uint32 fpsLimit;
664 //extern GLuint *vboid, *vaoid;
665 extern SDL_Surface** allsurfaces;
666 extern Uint32 numsprites;
667 extern Uint32 numtiles;
668 extern Uint32 nummodels;
669 extern Sint32 audio_rate, audio_channels, audio_buffers;
670 extern Uint16 audio_format;
671 extern int sfxvolume;
672 extern int sfxAmbientVolume;
673 extern int sfxEnvironmentVolume;
674 extern bool *animatedtiles, *swimmingtiles, *lavatiles;
675 extern char tempstr[1024];
676 static const int MINIMAP_MAX_DIMENSION = 512;
677 extern Sint8 minimap[MINIMAP_MAX_DIMENSION][MINIMAP_MAX_DIMENSION];
678 extern Uint32 mapseed;
679 extern bool* shoparea;
680 extern real_t globalLightModifier;
681 extern real_t globalLightTelepathyModifier;
682 extern int globalLightModifierActive;
683 extern int globalLightSmoothingRate;
684 enum LightModifierValues : int
685 {
686 	GLOBAL_LIGHT_MODIFIER_STOPPED,
687 	GLOBAL_LIGHT_MODIFIER_INUSE,
688 	GLOBAL_LIGHT_MODIFIER_DISSIPATING
689 };
690 
691 // function prototypes for main.c:
692 int sgn(real_t x);
693 int numdigits_sint16(Sint16 x);
694 int longestline(char const * const str);
695 int concatedStringLength(char* str, ...);
696 void printlog(const char* str, ...);
697 
698 // function prototypes for list.c:
699 void list_FreeAll(list_t* list);
700 void list_RemoveNode(node_t* node);
701 template <typename T>
list_RemoveNodeWithElement(list_t & list,T element)702 void list_RemoveNodeWithElement(list_t &list, T element)
703 {
704 	for ( node_t *node = list.first; node != nullptr; node = node->next )
705 	{
706 		if ( *static_cast<T*>(node->element) == element )
707 		{
708 			list_RemoveNode(node);
709 			return;
710 		}
711 	}
712 }
713 node_t* list_AddNodeFirst(list_t* list);
714 node_t* list_AddNodeLast(list_t* list);
715 node_t* list_AddNode(list_t* list, int index);
716 Uint32 list_Size(list_t* list);
717 list_t* list_Copy(list_t* destlist, list_t* srclist);
718 list_t* list_CopyNew(list_t* srclist);
719 Uint32 list_Index(node_t* node);
720 node_t* list_Node(list_t* list, int index);
721 
722 // function prototypes for objects.c:
723 void defaultDeconstructor(void* data);
724 void emptyDeconstructor(void* data);
725 void entityDeconstructor(void* data);
726 void lightDeconstructor(void* data);
727 void mapDeconstructor(void* data);
728 void stringDeconstructor(void* data);
729 void listDeconstructor(void* data);
730 Entity* newEntity(Sint32 sprite, Uint32 pos, list_t* entlist, list_t* creaturelist);
731 button_t* newButton(void);
732 string_t* newString(list_t* list, Uint32 color, char const * const content, ...);
733 pathnode_t* newPathnode(list_t* list, Sint32 x, Sint32 y, pathnode_t* parent, Sint8 pos);
734 
735 // function prototypes for opengl.c:
736 #define REALCOLORS 0
737 #define ENTITYUIDS 1
738 real_t getLightForEntity(real_t x, real_t y);
739 void glDrawVoxel(view_t* camera, Entity* entity, int mode);
740 void glDrawSprite(view_t* camera, Entity* entity, int mode);
741 void glDrawSpriteFromImage(view_t* camera, Entity* entity, std::string text, int mode);
742 real_t getLightAt(int x, int y);
743 void glDrawWorld(view_t* camera, int mode);
744 
745 // function prototypes for cursors.c:
746 SDL_Cursor* newCursor(char const * const image[]);
747 
748 // function prototypes for maps.c:
749 int generateDungeon(char* levelset, Uint32 seed, std::tuple<int, int, int, int> mapParameters = std::make_tuple(-1, -1, -1, 0)); // secretLevelChance of -1 is default Barony generation.
750 void assignActions(map_t* map);
751 
752 // Cursor bitmap definitions
753 extern char const *cursor_pencil[];
754 extern char const *cursor_point[];
755 extern char const *cursor_brush[];
756 extern char const *cursor_fill[];
757 
758 GLuint create_shader(const char* filename, GLenum type);
759 
760 extern bool no_sound; //False means sound initialized properly. True means sound failed to initialize.
761 extern bool initialized; //So that messagePlayer doesn't explode before the game is initialized. //TODO: Does the editor need this set too and stuff?
762 
763 #ifdef PANDORA
764 // Pandora: FBO variables
765 extern GLuint fbo_fbo;
766 extern GLuint fbo_tex;
767 extern GLuint fbo_ren;
768 #endif
769 void GO_SwapBuffers(SDL_Window* screen);
770 unsigned int GO_GetPixelU32(int x, int y, view_t& camera);
771 
772 static const int NUM_STEAM_STATISTICS = 49;
773 extern SteamStat_t g_SteamStats[NUM_STEAM_STATISTICS];
774 static const int NUM_GLOBAL_STEAM_STATISTICS = 66;
775 extern SteamStat_t g_SteamGlobalStats[NUM_GLOBAL_STEAM_STATISTICS];
776 
777 #ifdef STEAMWORKS
778 #include <steam/steam_api.h>
779 #include "steam.hpp"
780 extern CSteamLeaderboards* g_SteamLeaderboards;
781 extern CSteamWorkshop* g_SteamWorkshop;
782 extern CSteamStatistics* g_SteamStatistics;
783 #endif // STEAMWORKS
784 
785 #ifdef USE_EOS
786 #include "eos.hpp"
787 #endif
788