1 /**
2  * Header for code common to FreeDink and FreeDinkedit
3 
4  * Copyright (C) 1997, 1998, 1999, 2002, 2003  Seth A. Robinson
5  * Copyright (C) 2008, 2009, 2012  Sylvain Beucler
6 
7  * This file is part of GNU FreeDink
8 
9  * GNU FreeDink is free software; you can redistribute it and/or
10  * modify it under the terms of the GNU General Public License as
11  * published by the Free Software Foundation; either version 3 of the
12  * License, or (at your option) any later version.
13 
14  * GNU FreeDink is distributed in the hope that it will be useful, but
15  * WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
17  * General Public License for more details.
18 
19  * You should have received a copy of the GNU General Public License
20  * along with this program.  If not, see
21  * <http://www.gnu.org/licenses/>.
22  */
23 
24 #ifndef _GAME_ENGINE_H
25 #define _GAME_ENGINE_H
26 
27 #include <time.h>
28 
29 #include "SDL.h"
30 #include "rect.h"
31 #include "io_util.h"
32 #include "dinkc.h"
33 #include "gfx_tiles.h"
34 #include "dinkc_sp_custom.h"
35 
36 #define FPS 60
37 #define MAX_SPRITES_AT_ONCE 300
38 
39 
40 struct sp
41 {
42   int x,moveman;
43   int y;
44   int mx,my;
45   int lpx[51],lpy[51];
46   int speed;
47   int brain;
48   int seq_orig,dir;
49   int seq;
50   int frame;
51   unsigned long delay;
52   int pseq;
53   int pframe;
54 
55   /*BOOL*/int active;
56   int attrib;
57   unsigned long wait;
58   int timer;
59   int skip;
60   int skiptimer;
61   int size;
62   int que;
63   int base_walk;
64   int base_idle;
65   int base_attack;
66 
67   int base_hit;
68   int last_sound;
69   int hard;
70   rect alt;
71   int althard;
72   int sp_index;  /* editor_sprite */
73   /*BOOL*/int nocontrol;
74   int idle;
75   int strength;
76   int damage;
77   int defense;
78   int hitpoints;
79   int exp;
80   int gold;
81   int base_die;
82   int kill;
83   Uint32 kill_timer;
84   int script_num;
85   char text[200];
86   int owner;
87   int script;
88   int sound;
89   int callback;
90   int freeze;
91   /*bool*/int move_active;
92   int move_script;
93   int move_dir;
94   int move_num;
95   /*BOOL*/int move_nohard;
96   int follow;
97   int nohit;
98   /*BOOL*/int notouch;
99   unsigned long notouch_timer;
100   /*BOOL*/int flying;
101   int touch_damage;
102   int brain_parm;
103   int brain_parm2;
104   /*BOOL*/int noclip;
105   /*BOOL*/int reverse;
106   /*BOOL*/int disabled;
107   int target;
108   int attack_wait;
109   int move_wait;
110   int distance;
111   int last_hit;
112   /*BOOL*/int live;
113   int range;
114   int attack_hit_sound;
115   int attack_hit_sound_speed;
116   int action;
117   int nodraw;
118   int frame_delay;
119   int picfreeze;
120   /* v1.08 */
121   int bloodseq;
122   int bloodnum;
123   dinkc_sp_custom custom;
124 };
125 
126 struct item_struct
127 {
128   BOOL_1BYTE active;
129   char name[10+1];
130   int seq;
131   int frame;
132 };
133 
134 struct mydata
135 {
136   unsigned char type[100];  // DinkC's editor_type(i)
137   unsigned short seq[100];  // DinkC's editor_seq(i)
138   unsigned char frame[100]; // DinkC's editor_frame(i)
139   int last_time; // ticks when type 6, 7 or 8 was set
140 };
141 
142 /* Game state. Saved games are generated by dumping this structure in
143    to SAVEx.DAT, so DON'T DON'T DON'T change anything here ;)
144    otherwise you'll change the saved games format. */
145 // for storing current tiles in save game
146 struct player_info_tile
147 {
148   char file[50];
149 };
150 #define NB_MITEMS 8
151 #define NB_ITEMS 16
152 struct player_info
153 {
154   int minutes;
155 
156   struct item_struct mitem[NB_MITEMS];
157   struct item_struct item[NB_ITEMS];
158 
159   int curitem; // highlighted item in the inventory
160   BOOL_1BYTE item_magic; // 1 if it's a magic item, 0 if regular
161 
162   struct mydata spmap[769];
163   struct varman var[MAX_VARS];
164 
165 
166   BOOL_1BYTE push_active;
167   int push_dir;
168   unsigned int push_timer;
169   int last_talk;
170   int mouse; /* vertical position of the mouse when selecting a dialog
171 		option */
172   int last_map;
173 
174   /* v1.08: use wasted space for storing file location of map.dat,
175      dink.dat, palette, and tiles */
176   /* char cbuff[6000];*/
177   char mapdat[50];
178   char dinkdat[50];
179   char palette[50];
180   struct player_info_tile tile[GFX_TILES_NB_SETS+1];
181   struct global_function func[100];
182 };
183 
184 extern struct sp spr[];
185 extern struct player_info play;
186 extern int last_sprite_created;
187 
188 /* Engine variables directly mapped with DinkC variables */
189 extern int *pvision, *plife, *presult, *pspeed, *ptiming, *plifemax,
190   *pexper, *pmap, *pstrength, *pcur_weapon,*pcur_magic, *pdefense,
191   *pgold, *pmagic, *plevel, *plast_text, *pmagic_level;
192 extern int *pupdate_status, *pmissile_target, *penemy_sprite,
193   *pmagic_cost, *pmissle_source;
194 
195 
196 extern int flife, fexp, fstrength, fdefense, fgold, fmagic,
197   fmagic_level, flifemax, fraise, last_magic_draw;
198 
199 
200 
201 /* Sound - BGM */
202 extern /*bool*/int midi_active;
203 extern /*bool*/int sound_on;
204 extern /*bool*/int cd_inserted;
205 
206 
207 /* dink.dat */
208 struct map_info
209 {
210   int loc[769];
211   int music[769];
212   int indoor[769];
213 };
214 extern struct map_info map;
215 
216 
217 
218 /* Joystick */
219 extern /*BOOL*/int joystick;
220 /* extern JOYINFOEX jinfo; */
221 extern SDL_Joystick *jinfo;
222 struct wait_for_button
223 {
224 	int script;
225 	int button;
226 	/*bool*/int active;
227 };
228 extern struct wait_for_button wait4b;
229 
230 
231 extern int last_saved_game;
232 
233 extern char *dversion_string;
234 extern int dversion;
235 #define LEN_SAVE_GAME_INFO 200
236 extern char save_game_info[LEN_SAVE_GAME_INFO];
237 extern char current_map[50];
238 extern char current_dat[50];
239 
240 extern time_t time_start;
241 
242 extern int smooth_follow;
243 
244 extern int get_pan(int h);
245 extern int get_vol(int h);
246 
247 
248 /* Editor sprite containing the current warp (teleporter), 0 if no active warp: */
249 extern int process_warp;
250 extern int process_downcycle;
251 extern int process_upcycle;
252 extern unsigned long cycle_clock;
253 extern int cycle_script;
254 
255 extern unsigned int dink_base_push;
256 
257 extern void game_init(void);
258 extern void game_quit(void);
259 
260 extern Uint32 game_GetTicks(void);
261 extern void game_set_high_speed(void);
262 extern void game_set_normal_speed(void);
263 
264 #endif
265