1 
2 #ifndef _GAME_H
3 #define _GAME_H
4 
5 #include "ObjManager.h"
6 #include "TextBox/TextBox.h"
7 #include "i18n/translate.h"
8 #include "sound/SoundManager.h"
9 #include "stageboss.h"
10 #include "statusbar.h"
11 #include "tsc.h"
12 
13 #define GAME_FPS 50
14 
15 // for UpdateBlockedStates
16 #define RIGHTMASK 0x01
17 #define LEFTMASK 0x02
18 #define UPMASK 0x04
19 #define DOWNMASK 0x08
20 #define ALLDIRMASK (LEFTMASK | RIGHTMASK | UPMASK | DOWNMASK)
21 
22 // highest addressable flag by tsc scripts etc
23 #define NUM_GAMEFLAGS 8000
24 
25 // switchstage.mapno is set to this to load a game
26 #define MAPNO_SPECIALS 1000
27 #define LOAD_GAME 1000
28 #define NEW_GAME 1001
29 #define NEW_GAME_FROM_MENU 1002  // new game (include Kazuma cutscene)
30 #define LOAD_GAME_FROM_MENU 1003 // load game (from title screen, include weapon slide)
31 #define START_REPLAY 1004
32 #define TITLE_SCREEN 1005
33 
34 // game modes (changes *tickfunction)
35 enum GameModes
36 {
37   GM_NONE,       // default mode at startup & shutdown
38   GM_NORMAL,     // playing the game
39   GM_INVENTORY,  // in inventory screen
40   GM_MAP_SYSTEM, // viewing Map System
41   GM_ISLAND,     // XX1 good-ending island-crash cutscene
42   GM_CREDITS,    // <CRE credits
43   GM_INTRO,      // intro
44   GM_TITLE,      // title screen
45 
46   GP_PAUSED,  // pausemode: Pause (use game.pause())
47   GP_OPTIONS, // pausemode: Options (use game.pause())
48   GP_MODS, // pausemode: Options (use game.pause())
49 
50   NUM_GAMEMODES
51 };
52 
53 // note: this structure is memsetted at 0 at startup.
54 // ensure it doesn't contain any non-POD types that would be harmed by this.
55 struct Game
56 {
57   bool running;
58   bool frozen;
59 
60   int mode;
61   int paused;
62 
63   int curmap;
64   int showmapnametime;
65   int mapname_x;
66 
67   uint32_t counter; // Nikumaru counter value
68 
69   TSC *tsc;
70   I18N *lang;
71 
72   struct
73   {
74     bool god;
75     // bool debugmode;
76     bool infinite_damage;
77     bool DrawBoundingBoxes;
78   } debug;
79 
80   // if mapno becomes >= 0 the stage ends and we switch to the new stage
81   struct
82   {
83     int mapno;
84     int playerx, playery;
85     int eventonentry;
86     int param;
87   } switchstage;
88 
89   // game flags and skipflags as set by scripts
90   bool flags[NUM_GAMEFLAGS];
91   bool skipflags[NUM_GAMEFLAGS];
92 
93   // earthquake effect; <QUA command
94   int quaketime;
95   int megaquaketime;
96 
97   // stuff for boss bar
98   struct
99   {
100     Object *object;  // if != NULL, a boss bar is shown displaying this object's remaining health
101     int starting_hp; // HP boss had when <BSL was called
102     bool defeated;   // set to true when boss is defeated
103     PercentBar bar;
104   } bossbar;
105 
106   StageBossManager stageboss;
107 
108   // set by enemies in Labyrinth M and by Almond Core to tell
109   // curly where to shoot at (it's like a hint)
110   struct
111   {
112     int x, y, timeleft;
113   } curlytarget;
114 
115   int fullscreen;
116   int ffwdtime; // debug option: disables speed-limiting for ffwdtime ticks
117 
118   // ---------------------------------------
119 
120   // static member functions--not private (Game is an object, not a namespace)
121   bool init();
122   bool initlevel();
123   bool createplayer();
124 
125   void switchmap(int mapno, int scriptno = 0, int px = 0, int py = 0);
126   void reset();
127 
128   bool setmode(int newmode, int param = 0, bool force = false);
129   bool pause(int pausemode, int param = 0);
130   void tick();
131 
132   void close();
133 };
134 
135 // NPC flags definitions
136 #define FLAG_SOLID_MUSHY 0x0001 // object blocks player but is a little "mushy" (normal solid state for enemies)
137 #define FLAG_IGNORETILE44 0x0002
138 #define FLAG_INVULNERABLE 0x0004
139 #define FLAG_IGNORE_SOLID 0x0008
140 #define FLAG_BOUNCY 0x0010 // when SOLID_BRICK also set, acts like a mini trampoline
141 #define FLAG_SHOOTABLE 0x0020
142 #define FLAG_SOLID_BRICK 0x0040 // object's entire bbox is rock-solid, just like a solid tile
143 #define FLAG_NOREARTOPATTACK 0x0080
144 #define FLAG_SCRIPTONTOUCH 0x0100
145 #define FLAG_SCRIPTONDEATH 0x0200
146 #define FLAG_DROP_POWERUPS_DONTUSE                                                                                     \
147   0x0400 // not used here because it doesn't seem to be set on some npc.tbl entries which DO in fact spawn powerups; see
148          // the nxflag which replaces it
149 #define FLAG_APPEAR_ON_FLAGID 0x0800
150 #define FLAG_FACES_RIGHT 0x1000
151 #define FLAG_SCRIPTONACTIVATE 0x2000
152 #define FLAG_DISAPPEAR_ON_FLAGID 0x4000
153 #define FLAG_SHOW_FLOATTEXT 0x8000
154 
155 // NXEngine flag definitions
156 #define NXFLAG_FOLLOW_SLOPE 0x0001      // enable moving up/down slopes when moving horizontally
157 #define NXFLAG_SLOW_X_WHEN_HURT 0x0002  // move at half X speed when shaking from damage
158 #define NXFLAG_SLOW_Y_WHEN_HURT 0x0004  // move at half Y speed when shaking from damage
159 #define NXFLAG_THUD_ON_RIDING 0x0008    // if set there is a "thud" sound when player lands on it
160 #define NXFLAG_NO_RESET_YINERTIA 0x0010 // don't zero yinertia on blocku/blockd
161 #define NXFLAG_CONSOLE_ANIMATE 0x0020   // spawned at console and is implicit target of subsequent animate commands
162 
163 #define NXFLAG_SLOW_WHEN_HURT (NXFLAG_SLOW_X_WHEN_HURT | NXFLAG_SLOW_Y_WHEN_HURT)
164 
165 extern Game game;
166 #define _(x) game.lang->translate(x)
167 #define rtl() game.lang->isRTL()
168 extern TextBox textbox;
169 
170 extern Object *onscreen_objects[MAX_OBJECTS];
171 extern int nOnscreenObjects;
172 
173 void debug(const char *fmt, ...);
174 void quake(int quaketime, NXE::Sound::SFX snd = NXE::Sound::SFX::SND_QUAKE);
175 void megaquake(int quaketime, NXE::Sound::SFX snd = NXE::Sound::SFX::SND_QUAKE);
176 
177 struct Profile;
178 bool game_load(int num);
179 bool game_load(Profile *p);
180 bool game_save(int num);
181 bool game_save(Profile *p);
182 void DrawScene(void);
183 
184 void game_tick_normal(void);
185 void AssignExtraSprites(void);
186 
187 #endif
188