1 /*
2  * OpenBOR - http://www.LavaLit.com
3  * -
4  ----------------------------------------------------------------------
5  * All rights reserved, see LICENSE in OpenBOR root for details.
6  *
7  * Copyright (c) 2004 - 2011 OpenBOR Team
8  */
9 
10 /////////////////////////////////////////////////////////////////////////////
11 //	Beats of Rage                                                          //
12 //	Side-scrolling beat-'em-up                                             //
13 /////////////////////////////////////////////////////////////////////////////
14 
15 #ifndef OPENBOR_H
16 #define OPENBOR_H
17 
18 
19 /////////////////////////////////////////////////////////////////////////////
20 
21 #include	"types.h"
22 #include	"video.h"
23 #include	"vga.h"
24 #include	"screen.h"
25 #include	"transform.h"
26 #include	"loadimg.h"
27 #include	"bitmap.h"
28 #include	"sprite.h"
29 #include	"spriteq.h"
30 #include	"font.h"
31 #include	"timer.h"
32 #include	"rand32.h"
33 #include	"sblaster.h"
34 #include	"soundmix.h"
35 #include	"control.h"
36 #include	"draw.h"
37 #include	"packfile.h"
38 #include	"palette.h"
39 #include	"anigif.h"
40 #include    "openborscript.h"
41 #include    "globals.h"
42 #include	"triangle.h"
43 #include    "ram.h"
44 #include    "version.h"
45 
46 #ifdef SDL
47 #include    "gfx.h"
48 #endif
49 
50 /////////////////////////////////////////////////////////////////////////////
51 
52 #define		exit				borExit
53 #define		time				borTime
54 #define		kill				borKill
55 #define		pause				borPause
56 #define		shutdown			borShutdown
57 
58 #define		DEFAULT_SHUTDOWN_MESSAGE \
59 			"OpenBOR " VERSION ", Compile Date: " __DATE__ "\n" \
60 			"Presented by Senile Team.\n" \
61 			"This Version is unofficial and based on the Senile source code.\n" \
62 			"\n" \
63 			"Special thanks to SEGA and SNK.\n\n"
64 
65 #define		COMPATIBLEVERSION	0x00030000
66 #define		CV_SAVED_GAME		0x00021276
67 #define		CV_HIGH_SCORE		0x00020048
68 #define     GAME_SPEED          200
69 #define		THINK_SPEED			2
70 #define		COUNTER_SPEED		(GAME_SPEED*2)
71 #define		MAX_ENTS			150
72 #define		MAX_PANELS			52
73 #define		MAX_WEAPONS			10
74 #define		MAX_COLOUR_MAPS		30
75 #define		MAX_NAME_LEN		40
76 #define		LEVEL_MAX_SPAWNS	600
77 #define		LEVEL_MAX_PANELS	100
78 #define		LEVEL_MAX_HOLES		40
79 #define		LEVEL_MAX_WALLS		40
80 #define     LEVEL_MAX_LAYERS  100
81 #define     LEVEL_MAX_TEXTOBJS  50
82 #define     LEVEL_MAX_FILESTREAMS 50
83 #define     LEVEL_MAX_PALETTES  40                  // altered palettes
84 #define		MAX_LEVELS			100
85 #define		MAX_DIFFICULTIES	10
86 #define		MAX_SPECIALS		8					// Added for customizable freespecials
87 #define     MAX_SPECIAL_INPUTS  27                  // max freespecial input steps, MAX_SPECIAL_INPUTS-1 is reserved, MAX_SPECIAL_INPUTS-2 is animation index, MAX_SPECIAL_INPUTS-3 is reserved. OX -4 , -5 , -6 , -7 , -8 , -9 , -10 also for cancels
88 #define		MAX_ATCHAIN			12					// Maximum attack chain length
89 #define     MAX_IDLES           1                   // Idle animations.
90 #define     MAX_WALKS           1                   // Walk animations.
91 #define     MAX_BACKWALKS       1                   // Backwalk animations.
92 #define     MAX_UPS             1                   // Walk up animations.
93 #define     MAX_DOWNS           1                   // Walk down animations.
94 #define		MAX_ATTACKS			4					// Total number of attacks players have
95 #define     MAX_FOLLOWS         4					// For followup animations
96 #define     MAX_PLAYERS         4
97 #define		MAX_ARG_LEN			512
98 #define		MAX_PAL_SIZE		1024
99 #define		MAX_CACHED_BACKGROUNDS 9
100 
101 #define		FLAG_ESC			0x00000001
102 #define		FLAG_START			0x00000002
103 #define		FLAG_MOVELEFT		0x00000004
104 #define		FLAG_MOVERIGHT		0x00000008
105 #define		FLAG_MOVEUP			0x00000010
106 #define		FLAG_MOVEDOWN		0x00000020
107 #define		FLAG_ATTACK			0x00000040
108 #define		FLAG_JUMP			0x00000080
109 #define		FLAG_SPECIAL		0x00000100
110 #define		FLAG_SCREENSHOT		0x00000200
111 #define		FLAG_ATTACK2		0x00000400
112 #define		FLAG_ATTACK3		0x00000800
113 #define		FLAG_ATTACK4		0x00001000
114 #define		FLAG_ANYBUTTON		(FLAG_START|FLAG_SPECIAL|FLAG_ATTACK|FLAG_ATTACK2|FLAG_ATTACK3|FLAG_ATTACK4|FLAG_JUMP)
115 #define		FLAG_CONTROLKEYS	(FLAG_SPECIAL|FLAG_ATTACK|FLAG_ATTACK2|FLAG_ATTACK3|FLAG_ATTACK4|FLAG_JUMP|FLAG_MOVEUP|FLAG_MOVEDOWN|FLAG_MOVELEFT|FLAG_MOVERIGHT)
116 #define		FLAG_FORWARD		0x40000000
117 #define		FLAG_BACKWARD		0x80000000
118 
119 #define		SDID_MOVEUP			0
120 #define		SDID_MOVEDOWN		1
121 #define		SDID_MOVELEFT		2
122 #define		SDID_MOVERIGHT		3
123 #define		SDID_ATTACK 		4
124 #define		SDID_ATTACK2		5
125 #define		SDID_ATTACK3		6
126 #define		SDID_ATTACK4		7
127 #define		SDID_JUMP			8
128 #define		SDID_SPECIAL		9
129 #define		SDID_START			10
130 #define		SDID_SCREENSHOT		11
131 
132 #define		TYPE_NONE			0
133 #define		TYPE_PLAYER			1
134 #define		TYPE_ENEMY			2
135 #define		TYPE_ITEM			4
136 #define		TYPE_OBSTACLE		8
137 #define		TYPE_STEAMER		16
138 #define		TYPE_SHOT			32					// 7-1-2005 type to use for player projectiles
139 #define		TYPE_TRAP			64					// 7-1-2005 lets face it enemies are going to just let you storm in without setting a trap or two!
140 #define		TYPE_TEXTBOX		128					// New textbox type for displaying messages
141 #define		TYPE_ENDLEVEL		256					// New endlevel type that ends the level when touched
142 #define     TYPE_NPC            512                 // A character can be an ally or enemy.
143 #define     TYPE_PANEL          1024                // Fake panel, scroll with screen using model speed
144 #define	    TYPE_RESERVED       0x40000000			// should not use as a type
145 
146 #define		SUBTYPE_NONE		0
147 #define		SUBTYPE_BIKER		1
148 #define		SUBTYPE_NOTGRAB		2					//7-1-2005 new subtype for those ungrabbable enemies
149 #define		SUBTYPE_ARROW		3					//7-1-2005  subtype for an "enemy" that flies across the screen and dies
150 #define		SUBTYPE_TOUCH		4					// ltb 1-18-05  new Item subtype for a more platformer feel.
151 #define		SUBTYPE_WEAPON		5
152 #define		SUBTYPE_NOSKIP		6					// Text type that can't be skipped
153 #define		SUBTYPE_FLYDIE		7					// Now obstacles can be hit and fly like on Simpsons/TMNT
154 #define		SUBTYPE_BOTH		8					// Used with TYPE_ENDLEVEL to force both players to reach the point before ending level
155 #define		SUBTYPE_PROJECTILE	9					// New weapon projectile type that can be picked up by players/enemies
156 #define     SUBTYPE_FOLLOW      10                  // Used by NPC character, if set, they will try to follow players
157 #define     SUBTYPE_CHASE       11                  // Used by enemy always chasing you
158 
159 //------------reserved for A.I. types-------------------------
160 //  A.I. move1, affect movement path
161 #define     AIMOVE1_NORMAL      0                   // Current default style
162 #define     AIMOVE1_CHASE       0x00000001          // alway move towards target, and can run to them if target is farway
163 #define     AIMOVE1_CHASEZ      0x00000002          // only try to get close in z direction
164 #define     AIMOVE1_CHASEX      0x00000004          // only try to get colse in x direction
165 #define     AIMOVE1_AVOID       0x00000008          // try to avoid target
166 #define     AIMOVE1_AVOIDZ      0x00000010          // only try to avoid target in z direction
167 #define     AIMOVE1_AVOIDX      0x00000020          // only try to avoid target in x direction
168 #define     AIMOVE1_WANDER      0x00000040          // ignore the target's position completely, wander everywhere, long idle time
169 #define     AIMOVE1_BIKER       0x00000080          // move like a biker
170 #define     AIMOVE1_ARROW       0x00000100          // fly like an arrow
171 #define     AIMOVE1_STAR        0x00000200          // fly like a star, subject to ground
172 #define     AIMOVE1_BOMB        0x00000400          // fly like a bomb, subject to ground/wall etc
173 #define     AIMOVE1_NOMOVE      0x00000800          // don't move at all
174 #define     AIMOVE1_BOOMRANG    0x00001000          // boomrang
175 #define     MASK_AIMOVE1        0x0000FFFF
176 
177 // A.I move2, affect terrain reflect
178 #define     AIMOVE2_NORMAL      0                   // Current default style
179 #define     AIMOVE2_IGNOREHOLES 0x00010000          // don't avoid holes
180 #define		AIMOVE2_NOTARGETIDLE 0x00020000			// don't move when there's no target
181 #define     MASK_AIMOVE2        0xFFFF0000
182 
183 // A.I. attack1, affect attacking style
184 #define     AIATTACK1_NORMAL      0                   // Current default style
185 #define     AIATTACK1_LONG        0x00000001          // Long range first, not used
186 #define     AIATTACK1_MELEE       0x00000002          // Melee attack first, not used
187 #define     AIATTACK1_NOATTACK    0x00000004          // dont attack at all
188 #define     AIATTACK1_ALWAYS      0x00000008          // more aggression than default, useful for traps who don't think
189 #define     MASK_AIATTACK1        0x0000FFFF
190 
191 //  A.I. attack2, affect Defending style
192 #define     AIATTACK2_NORMAL      0                   // Current default style, don't dodge at all
193 #define     AIATTACK2_DODGE       0x00010000          // Use dodge animation to avoid attack
194 #define     AIATTACK2_DODGEMOVE   0x00020000          // Try to move in z direction if a jump attack is about to hit him
195 													  // and try to step back if a melee attack is about to hit him*/
196 #define     MASK_AIATTACK2        0xFFFF0000
197 
198 
199 // Note: the minimum Z coordinate of the player is important
200 // for several other drawing operations.
201 // movement restirctions are here!
202 //int			PLAYER_MIN_Z		= 160;				// 2-10-05  adjustable walking area
203 //int			PLAYER_MAX_Z		= 232;				// 2-10-05  adjustable walking area
204 //int			BGHEIGHT			= 160;				// 2-10-05  adjustable BGHeight
205 //int         MAX_WALL_HEIGHT     =  1000;            // max wall height that an entity can be spawned on
206 #define		FRONTPANEL_Z		(PLAYER_MAX_Z+50)
207 #define     HUD_Z               (FRONTPANEL_Z+10000)
208 #define		HOLE_Z				(PLAYER_MIN_Z-46)
209 #define		NEONPANEL_Z			(PLAYER_MIN_Z-47)
210 #define		SHADOW_Z			(PLAYER_MIN_Z-48)
211 #define		SCREENPANEL_Z		(PLAYER_MIN_Z-49)
212 #define		PANEL_Z				(PLAYER_MIN_Z-50)
213 #define		MIRROR_Z			(PLAYER_MIN_Z-5)
214 #define		PIT_DEPTH			-250
215 #define		P2_STATS_DIST		180
216 #define		CONTACT_DIST_H		30					// Distance to make contact
217 #define		CONTACT_DIST_V		12
218 #define		GRAB_DIST			36					// Grabbing ents will be placed this far apart.
219 #define		GRAB_STALL			(GAME_SPEED * 8 / 10)
220 
221 
222 
223 #define		ATK_NORMAL			0
224 #define		ATK_NORMAL2			1
225 #define		ATK_NORMAL3			2
226 #define		ATK_NORMAL4			3
227 #define		ATK_BLAST			4
228 #define		ATK_BURN			5
229 #define		ATK_FREEZE			6
230 #define		ATK_SHOCK			7
231 #define		ATK_STEAL			8					// Steal opponents life
232 #define		ATK_NORMAL5			9
233 #define		ATK_NORMAL6			10
234 #define		ATK_NORMAL7			11
235 #define		ATK_NORMAL8			12
236 #define		ATK_NORMAL9			13
237 #define		ATK_NORMAL10		14
238 #define		ATK_ITEM		    15
239 
240 #define     MAX_ATKS            16                // default max attack types
241 #define     STA_ATKS            6                 // default special attack types: blast burn shock freeze steal
242 #define     MAX_DOTS            10                // Max active dot effects.
243 
244 #define		SCROLL_RIGHT		2
245 #define		SCROLL_DOWN			4
246 #define		SCROLL_LEFT			8
247 #define		SCROLL_UP			16
248 #define		SCROLL_BACK			1
249 #define		SCROLL_BOTH			(SCROLL_BACK|SCROLL_RIGHT)
250 #define		SCROLL_RIGHTLEFT	SCROLL_BOTH
251 #define		SCROLL_LEFTRIGHT    (SCROLL_LEFT|SCROLL_BACK)
252 #define		SCROLL_INWARD       32
253 #define     SCROLL_OUTWARD      64
254 #define		SCROLL_OUTIN		(SCROLL_OUTWARD|SCROLL_BACK)
255 #define		SCROLL_INOUT		(SCROLL_INWARD|SCROLL_BACK)
256 #define		SCROLL_UPWARD       128
257 #define     SCROLL_DOWNWARD     256
258 // blah, blah,
259 
260 
261 #define		ANI_IDLE			0
262 #define		ANI_WALK			1
263 #define		ANI_JUMP			2
264 #define		ANI_LAND			3
265 #define		ANI_PAIN			4
266 #define		ANI_FALL			5
267 #define		ANI_RISE			6
268 #define		ANI_ATTACK1			7
269 #define		ANI_ATTACK2			8
270 #define		ANI_ATTACK3			9
271 #define		ANI_ATTACK4			10					// Very important
272 #define		ANI_UPPER			11
273 #define		ANI_BLOCK			12					// New block animation
274 #define		ANI_JUMPATTACK		13
275 #define		ANI_JUMPATTACK2		14
276 #define		ANI_GET				15
277 #define		ANI_GRAB			16
278 #define		ANI_GRABATTACK		17
279 #define		ANI_GRABATTACK2		18
280 #define		ANI_THROW			19
281 #define		ANI_SPECIAL			20
282 #define		ANI_FREESPECIAL		21
283 #define		ANI_SPAWN			22 					// 26-12-2004 new animation added here ani_spawn
284 #define		ANI_DIE				23					// 29-12-2004 new animation added here ani_die
285 #define		ANI_PICK			24					// 7-1-2005 used when players select their character at the select screen
286 #define		ANI_FREESPECIAL2	25
287 #define		ANI_JUMPATTACK3		26
288 #define		ANI_FREESPECIAL3	27
289 #define		ANI_UP				28					// Mar 2, 2005 - Animation for when going up
290 #define		ANI_DOWN			29					// Mar 2, 2005 - Animation for when going down
291 #define		ANI_SHOCK			30					// Animation played when knocked down by shock attack
292 #define		ANI_BURN			31					// Animation played when knocked down by burn attack
293 #define		ANI_SHOCKPAIN		32					// Animation played when not knocked down by shock attack
294 #define		ANI_BURNPAIN		33					// Animation played when not knocked down by shock attack
295 #define		ANI_GRABBED			34					// Animation played when grabbed
296 #define		ANI_SPECIAL2		35					// Animation played for when pressing forward special
297 #define		ANI_RUN				36					// Animation played when a player is running
298 #define		ANI_RUNATTACK		37					// Animation played when a player is running and presses attack
299 #define		ANI_RUNJUMPATTACK	38					// Animation played when a player is running and jumps and presses attack
300 #define		ANI_ATTACKUP		39					// u u animation
301 #define		ANI_ATTACKDOWN		40					// d d animation
302 #define		ANI_ATTACKFORWARD	41					// f f animation
303 #define		ANI_ATTACKBACKWARD	42					// Used for attacking backwards
304 #define		ANI_FREESPECIAL4	43					// More freespecials added
305 #define		ANI_FREESPECIAL5	44					// More freespecials added
306 #define		ANI_FREESPECIAL6	45					// More freespecials added
307 #define		ANI_FREESPECIAL7	46					// More freespecials added
308 #define		ANI_FREESPECIAL8	47					// More freespecials added
309 #define		ANI_RISEATTACK		48					// Attack used for enemies when players are crowding around after knocking them down
310 #define		ANI_DODGE			49					// Used for up up / down down SOR3 dodge moves for players
311 #define		ANI_ATTACKBOTH		50					// Used for when a player holds down attack and presses jump
312 #define		ANI_GRABFORWARD		51					// New grab attack for when a player holds down forward/attack
313 #define		ANI_GRABFORWARD2	52					// New second grab attack for when a player holds down forward/attack
314 #define		ANI_JUMPFORWARD		53					// Attack when a player is moving and jumps
315 #define		ANI_GRABDOWN		54					// Attack when a player has grabbed an opponent and presses down/attack
316 #define		ANI_GRABDOWN2		55					// Attack when a player has grabbed an opponent and presses down/attack
317 #define		ANI_GRABUP			56					// Attack when a player has grabbed an opponent and presses up/attack
318 #define		ANI_GRABUP2			57					// Attack when a player has grabbed an opponent and presses up/attack
319 #define		ANI_SELECT			58					// Animation that is displayed at the select screen
320 #define		ANI_DUCK			59					// Animation that is played when pressing down in "platform" type levels
321 #define		ANI_FAINT			60  				// Faint animations for players/enemys by tails
322 #define		ANI_CANT			61  				// Can't animation for players(animation when mp is less than mpcost) by tails.
323 #define		ANI_THROWATTACK		62					// Added for subtype projectile
324 #define		ANI_CHARGEATTACK	63                  // Plays when player releases attack1 after holding >= chargetime.
325 #define		ANI_VAULT			64  				// Now you can flip over people like in SOR.
326 #define		ANI_JUMPCANT		65
327 #define		ANI_JUMPSPECIAL		66
328 #define		ANI_BURNDIE			67
329 #define		ANI_SHOCKDIE		68
330 #define		ANI_PAIN2			69
331 #define		ANI_PAIN3			70
332 #define		ANI_PAIN4			71
333 #define		ANI_FALL2			72
334 #define		ANI_FALL3			73
335 #define		ANI_FALL4			74
336 #define		ANI_DIE2			75
337 #define		ANI_DIE3			76
338 #define		ANI_DIE4			77
339 #define		ANI_CHARGE			78
340 #define		ANI_BACKWALK		79
341 #define		ANI_SLEEP			80
342 #define		ANI_FOLLOW1			81
343 #define		ANI_FOLLOW2			82
344 #define		ANI_FOLLOW3			83
345 #define		ANI_FOLLOW4			84
346 #define		ANI_PAIN5			85
347 #define		ANI_PAIN6			86
348 #define		ANI_PAIN7			87
349 #define		ANI_PAIN8			88
350 #define		ANI_PAIN9			89
351 #define		ANI_PAIN10			90
352 #define		ANI_FALL5			91
353 #define		ANI_FALL6			92
354 #define		ANI_FALL7			93
355 #define		ANI_FALL8			94
356 #define		ANI_FALL9			95
357 #define		ANI_FALL10			96
358 #define		ANI_DIE5			97
359 #define		ANI_DIE6			98
360 #define		ANI_DIE7			99
361 #define		ANI_DIE8			100
362 #define		ANI_DIE9			101
363 #define		ANI_DIE10			102
364 #define     ANI_TURN            103   // turn back/flip
365 #define     ANI_RESPAWN         104    //now spawn works for players
366 #define     ANI_FORWARDJUMP     105
367 #define     ANI_RUNJUMP         106
368 #define     ANI_JUMPLAND        107
369 #define     ANI_JUMPDELAY       108
370 #define     ANI_HITWALL         109
371 #define     ANI_GRABBACKWARD    110
372 #define     ANI_GRABBACKWARD2   111
373 #define     ANI_GRABWALK        112
374 #define     ANI_GRABBEDWALK     113
375 #define     ANI_GRABWALKUP      114
376 #define     ANI_GRABBEDWALKUP   115
377 #define     ANI_GRABWALKDOWN    116
378 #define     ANI_GRABBEDWALKDOWN 117
379 #define     ANI_GRABTURN        118
380 #define     ANI_GRABBEDTURN     119
381 #define     ANI_GRABBACKWALK    120
382 #define     ANI_GRABBEDBACKWALK 121
383 #define     ANI_SLIDE           122    //Down + Jump animation.
384 #define     ANI_RUNSLIDE        123    //Down + Jump while running.
385 #define     ANI_BLOCKPAIN       124    //If entity has this, it will play in place of "pain" when it's blokcpain is 1 and incomming attack is blocked.
386 #define     ANI_DUCKATTACK      125
387 #define		ANI_RISE2			126
388 #define		ANI_RISE3			127
389 #define		ANI_RISE4			128
390 #define		ANI_RISE5			129
391 #define		ANI_RISE6			130
392 #define		ANI_RISE7			131
393 #define		ANI_RISE8			132
394 #define		ANI_RISE9			133
395 #define		ANI_RISE10			134
396 #define		ANI_RISEB			135
397 #define		ANI_RISES			136
398 #define		ANI_BLOCKPAIN2		137
399 #define		ANI_BLOCKPAIN3		138
400 #define		ANI_BLOCKPAIN4		139
401 #define		ANI_BLOCKPAIN5		140
402 #define		ANI_BLOCKPAIN6		141
403 #define		ANI_BLOCKPAIN7		142
404 #define		ANI_BLOCKPAIN8		143
405 #define		ANI_BLOCKPAIN9		144
406 #define		ANI_BLOCKPAIN10		145
407 #define		ANI_BLOCKPAINB		146
408 #define		ANI_BLOCKPAINS		147
409 #define     ANI_CHIPDEATH       148
410 #define     ANI_GUARDBREAK      149
411 #define		ANI_RISEATTACK2	    150
412 #define		ANI_RISEATTACK3		151
413 #define		ANI_RISEATTACK4		152
414 #define		ANI_RISEATTACK5		153
415 #define		ANI_RISEATTACK6		154
416 #define		ANI_RISEATTACK7		155
417 #define		ANI_RISEATTACK8		156
418 #define		ANI_RISEATTACK9		157
419 #define		ANI_RISEATTACK10	158
420 #define		ANI_RISEATTACKB		159
421 #define		ANI_RISEATTACKS		160
422 #define		ANI_WALKOFF			161
423 
424 #define		MAX_ANIS			162    // max_anis increased for new ANIs
425 
426 #define     ARG_FLOAT            0
427 #define     ARG_STRING           1
428 #define     ARG_INT              2
429 
430 // perhaps outdated, now use separted flags for entity
431 #define     SUBJECT_TO_WALL      1
432 #define     SUBJECT_TO_HOLE      2
433 #define     SUBJECT_TO_OBSTACLE  4
434 #define     SUBJECT_TO_BORDER    8
435 #define     SUBJECT_TO_SCREEN    16
436 #define     SUBJECT_TO_MINZ      32
437 #define     SUBJECT_TO_MAXZ      48
438 
439 #define     MAX(x, y)            ((x>y)?x:y)
440 #define     MIN(x, y)            ((x<y)?x:y)
441 
442 //macros for drawing menu text, fits different font size
443 #ifdef _MSC_VER
444 #define _strmidx(f,s, ...) ((videomodes.hRes-font_string_width((f), s, __VA_ARGS__))/2)
445 #else
446 #define _strmidx(f,s, args...) ((videomodes.hRes-font_string_width((f), s, ##args))/2)
447 #endif
448 #define _colx(f,c) ((int)(videomodes.hRes/2+(c)*(fontmonowidth((f))+1)))
449 #define _liney(f,l) ((int)(videomodes.vRes/2+(l)*(fontheight((f))+1)))
450 #ifdef _MSC_VER
451 #define _menutextm(f, l, shift, s, ...) font_printf(_strmidx(f,s, __VA_ARGS__)+(int)((shift)*(fontmonowidth((f))+1)), _liney(f,l), (f), 0, s, __VA_ARGS__)
452 #define _menutext(f, c, l, s, ...) font_printf(_colx(f,c), _liney(f,l), (f), 0, s, __VA_ARGS__)
453 #else
454 #define _menutextm(f, l, shift, s, args...) font_printf(_strmidx(f,s, ##args)+(int)((shift)*(fontmonowidth((f))+1)), _liney(f,l), (f), 0, s, ##args)
455 #define _menutext(f, c, l, s, args...) font_printf(_colx(f,c), _liney(f,l), (f), 0, s, ##args)
456 #endif
457 
458 /*
459 #define     ICO_NORMAL           0
460 #define     ICO_PAIN             1
461 #define     ICO_DIE              2
462 #define     ICO_GET              3
463 #define     ICO_WEAPON           4*/
464 
465 // model flags
466 #define     MODEL_NO_COPY         0x00000001   //dont copy anything from original model
467 #define     MODEL_NO_WEAPON_COPY  0x00000002   //dont copy weapon list from original model
468 #define		MODEL_NO_SCRIPT_COPY  0x00000004   //don't copy scripts
469 
470 #define lut_mul ((level && current_palette)?(level->blendings[current_palette-1][BLEND_MULTIPLY]):(blendings[BLEND_MULTIPLY]))
471 #define lut_screen ((level && current_palette)?(level->blendings[current_palette-1][BLEND_SCREEN]):(blendings[BLEND_SCREEN]))
472 #define lut_overlay ((level && current_palette)?(level->blendings[current_palette-1][BLEND_OVERLAY]):(blendings[BLEND_OVERLAY]))
473 #define lut_hl ((level && current_palette)?(level->blendings[current_palette-1][BLEND_HARDLIGHT]):(blendings[BLEND_HARDLIGHT]))
474 #define lut_dodge ((level && current_palette)?(level->blendings[current_palette-1][BLEND_DODGE]):(blendings[BLEND_DODGE]))
475 #define lut_half ((level && current_palette)?(level->blendings[current_palette-1][BLEND_HALF]):(blendings[BLEND_HALF]))
476 #define lut ((level && current_palette)?(level->blendings[current_palette-1]):(blendings))
477 
478 #define ABS(x) ((x)>0?(x):(-(x)))
479 
480 #define set_attacking(e) e->attacking = 1;\
481 						 e->idling = 0;
482 
483 #define set_jumping(e)   e->jumping = 1;\
484 						 e->idling = 0;
485 
486 #define set_charging(e)  e->charging = 1;\
487 						 e->idling = 0;
488 
489 #define set_getting(e)   e->getting = 1;\
490 						 e->idling = 0;
491 
492 #define set_blocking(e)  e->blocking = 1;\
493 						 e->idling = 0;
494 
495 #define set_turning(e)  e->turning = 1;\
496 						e->idling = 0;
497 
498 #define is_frozen(e)     ((textbox && e->modeldata.type != TYPE_TEXTBOX) || \
499 						 (smartbomber && e != smartbomber && e->modeldata.type != TYPE_TEXTBOX) ||(self->frozen&&self->freezetime>time))
500 
501 #define expand_time(e)   if(e->stalltime>0) e->stalltime++;\
502 						 if(e->releasetime>0)e->releasetime++;\
503 						 if(e->nextanim>0)e->nextanim++;\
504 						 if(e->nextthink>0)e->nextthink++;\
505 						 if(e->magictime>0)e->magictime++;\
506 						 if(e->guardtime>0)e->guardtime++;\
507 						 if(e->toss_time>0)e->toss_time++;\
508 						 if(e->freezetime>0 && (textbox || smartbomber))e->freezetime++;\
509 						 if(e->mpchargetime>0)e->mpchargetime++;\
510 						 if(e->invinctime>0) e->invinctime++;\
511 						 if(e->turntime>0) e->turntime++;\
512 						 if(e->sealtime>0) e->sealtime++;
513 /*                       if(e->dot_time>0) e->dot_time++;\
514 						 if(e->dot_cnt>0) e->dot_cnt++;
515 */
516 
517 #define freezeall        (smartbomber || textbox)
518 
519 #define is_projectile(e) (e->modeldata.type == TYPE_SHOT || e->model->subtype == SUBTYPE_ARROW || e->owner)
520 
521 #define screeny (level?((level->scrolldir == SCROLL_UP || level->scrolldir == SCROLL_DOWN )? 0:advancey ):0)
522 #define screenx (level?advancex:0)
523 
524 #define check_range(self, target, animnum) \
525 		 ( target && \
526 		  (self->direction ? \
527 		  (int)target->x >= self->x+self->modeldata.animation[animnum]->range.xmin &&\
528 		  (int)target->x <= self->x+self->modeldata.animation[animnum]->range.xmax\
529 		:\
530 		  (int)target->x <= self->x-self->modeldata.animation[animnum]->range.xmin &&\
531 		  (int)target->x >= self->x-self->modeldata.animation[animnum]->range.xmax)\
532 		  && (int)(target->z - self->z) >= self->modeldata.animation[animnum]->range.zmin \
533 		  && (int)(target->z - self->z) <= self->modeldata.animation[animnum]->range.zmax \
534 		  && (int)(target->a - self->a) >= self->modeldata.animation[animnum]->range.amin \
535 		  && (int)(target->a - self->a) <= self->modeldata.animation[animnum]->range.amax \
536 		  && (int)(target->base - self->base) >= self->modeldata.animation[animnum]->range.bmin \
537 		  && (int)(target->base - self->base) <= self->modeldata.animation[animnum]->range.bmax \
538 		  )\
539 
540 #define check_range_both(self, target, animnum) \
541 		 ( target && \
542 		  (((int)target->x >= self->x+self->modeldata.animation[animnum]->range.xmin &&\
543 			(int)target->x <= self->x+self->modeldata.animation[animnum]->range.xmax)\
544 		||\
545 		   ((int)target->x <= self->x-self->modeldata.animation[animnum]->range.xmin &&\
546 			(int)target->x >= self->x-self->modeldata.animation[animnum]->range.xmax))\
547 		  && (int)(target->z - self->z) >= self->modeldata.animation[animnum]->range.zmin \
548 		  && (int)(target->z - self->z) <= self->modeldata.animation[animnum]->range.zmax \
549 		  && (int)(target->a - self->a) >= self->modeldata.animation[animnum]->range.amin \
550 		  && (int)(target->a - self->a) <= self->modeldata.animation[animnum]->range.amax \
551 		  && (int)(target->base - self->base) >= self->modeldata.animation[animnum]->range.bmin \
552 		  && (int)(target->base - self->base) <= self->modeldata.animation[animnum]->range.bmax \
553 		  )\
554 
555 
556 #define tobounce(e) (e->animation->bounce && diff(0, e->tossv) > 1.5 && \
557 					 !((autoland == 1 && e->damage_on_landing == -1) ||e->damage_on_landing == -2))
558 
559 #define getpal ((current_palette&&level)?(level->palettes[current_palette-1]):pal)
560 
561 #define canbegrabbed(self, other) \
562 		(other->animation->vulnerable[other->animpos] && \
563 		 (!self->animation->move || self->animation->move[self->animpos] == 0) && \
564 		 (!self->animation->movez || self->animation->movez[self->animpos] == 0 ) && \
565 		 !(other->nograb || other->invincible || other->link || \
566 		   other->model->animal || inair(other) || \
567 		  (self->modeldata.type == TYPE_PLAYER && other->modeldata.type == TYPE_PLAYER && savedata.mode)))
568 
569 #define cangrab(self, other) \
570 		((other->modeldata.antigrab - self->modeldata.grabforce + \
571 		  (other->modeldata.paingrab?(other->modeldata.paingrab-other->inpain):0)<=0) &&\
572 		 canbegrabbed(self, other) && \
573 		 !inair(self) && \
574 		 diff(other->a, self->a) <= 0.1)
575 
576 #define unfrozen(e) \
577 		ent_set_colourmap(e, e->map);\
578 		e->frozen = 0;\
579 		e->freezetime = 0;
580 
581 #define validanim(e, a) ((e)->modeldata.animation[a]&&(e)->modeldata.animation[a]->numframes)
582 
583 //#define     MAX_MOVES             16
584 //#define     MAX_MOVE_STEPS        16
585 
586 #pragma pack (4)
587 
588 typedef struct
589 {
590 	unsigned int	compatibleversion:32;
591 	short       	gamma:16;
592 	short       	brightness:16;
593 	char			usesound:8;						// Use SB
594 	unsigned short	soundrate:16;					// SB freq
595 	short       	soundvol:16;					// SB volume
596 	char			usemusic:8;						// Play music
597 	short       	musicvol:16;					// Music volume
598 	short       	effectvol:16;					// Sound fx volume
599 	char			soundbits:8;					// SB bits
600 	char			usejoy:8;
601 	char			mode:8;							// Mode now saves
602 	char			windowpos:8;
603 	int				keys[MAX_PLAYERS][12];
604 	char			showtitles:8;
605 	char			videoNTSC:8;
606 	char			screen[7][2];					// Screen Filtering/Scaling Effects
607 	char            logo:8;
608 	char            uselog:8;
609 	char			debuginfo:8;					// FPS, Memory, etc...
610 	int				fullscreen:8;					// Window or Full Screen Mode
611 	char			stretch:8;						// Stretch (1) or preserve aspect ratio (0) in fullscreen mode
612 #if SDL
613 	char			usegl[2];						// 1 if OpenGL is preferred over SDL software blitting
614 	float			glscale;						// Scale factor for OpenGL
615 	char			glfilter[2];					// Simple or bilinear scaling
616 #endif
617 #if PSP
618 	char			pspcpuspeed:8;					// PSP CPU Speed
619 	char            overscan[4];                    // Control TV Overscan
620 	char            usetv:8;						// Initilize TV at bootup
621 #endif
622 
623 }s_savedata;
624 
625 
626 typedef struct
627 {
628 	unsigned int	compatibleversion:32;
629 	char			dName[MAX_NAME_LEN+1];			// Difficulty Name
630 	unsigned short	level:16;						// Level Number
631 	unsigned short	stage:16;						// Stage
632 	unsigned char	pLives[MAX_PLAYERS];			// Player Lives Left
633 	unsigned char	pCredits[MAX_PLAYERS];			// Player Credits Left
634 	unsigned int    pScores[MAX_PLAYERS];			// Player Scores
635 	unsigned char	credits:8;						// Number Of Credits
636 	unsigned short	times_completed:16;
637 	unsigned short	which_set:16;
638 	//-------------------new strict save features-----------------------
639 	char            flag:8;                                 // 0 useless slot 1 only load level number 2 load player info and level
640 	char			pName[MAX_PLAYERS][MAX_NAME_LEN+1];     // player names
641 	int             pSpawnhealth[MAX_PLAYERS];              // hit points left
642 	int             pSpawnmp[MAX_PLAYERS];                  // magic points left
643 	char            pWeapnum[MAX_PLAYERS];                  // weapon
644 	char            pColourmap[MAX_PLAYERS];                // colour map
645 }s_savelevel;
646 
647 
648 typedef struct
649 {
650 	unsigned int	compatibleversion:32;
651 	unsigned int    highsc[10];
652 	char			hscoren[10][MAX_NAME_LEN+1];
653 }s_savescore;
654 
655 typedef struct
656 {
657 	int attack_force;
658 	short attack_coords[5];
659 	int staydown[3];                    // [0] = Add to rise delay. [1] = Add to rise attack delay.
660 	float dropv[3];                       // fly height/x/z if the target is knoced down
661 	int hitsound;					    // Sound effect to be played when attack hits opponent
662 	int hitflash;                       // Custom flash for each animation, model id
663 	int blockflash;                     // Custom bflash for each animation, model id
664 	int blocksound;                     // Custom sound for when an attack is blocked
665 	int no_block;						// If this is greater than defense block power, make the hit
666 	int counterattack;
667 	int no_pain:8;
668 	int no_kill:8;						// this attack won't kill target (leave 1 HP)
669 	int no_flash:8;						// Flag to determine if an attack spawns a flash or not
670 	int grab:8;
671 	int freeze:8;
672 	int steal:8;
673 	int blast:8;
674 	int force_direction:8;              // 0 dont care, 1 same direction as attacker, -1 opposite drection as attacker, 2 right, -2 left
675 	int forcemap:8;
676 	int seal:8;
677 	int freezetime;
678 	int maptime;
679 	int sealtime;
680 	int dot:8;                          //Dot mode.
681 	int dot_index:8;                    //Dot index.
682 	int dot_time;                       //Dot time to expire.
683 	int dot_force;                      //Dot amount per tick.
684 	int dot_rate;                       //Dot tick delay.
685 	int otg:8;                          // Over The Ground. Gives ground projectiles the ability to hit lying ents.
686 	int jugglecost;						// cost for juggling a falling ent
687 	int guardcost;						// cost for blocking an attack
688 	int attack_drop;					// now be a knock-down factor, how many this attack will knock victim down
689 	int attack_type:8;
690 	int damage_on_landing;				// same as throw damage type
691 	float grab_distance;                // suck target near by
692 	int pause_add:16;					// Flag to determine if an attack adds a pause before updating the animation
693 	int pain_time:16;					// pain invincible time
694 }s_attack;
695 
696 typedef struct                                      //2011_04_01, DC: Counterstrike when taking hit.
697 {
698     int frameend:16;                       //Last frame of counter range.
699     int framestart:16;                     //First frame of counter range.
700 	int condition:8;                      //Counter conditions. 1 = Always. 2 = Hostile attacker. 3 = Hostile attacker from front not using freeze attack.
701 	int damaged:8;                        //Receive damage from attack. 0 = No damage. 1 = Normal damage.
702 }s_counterrange;
703 
704 typedef struct                                      //2011_04_01, DC: HP and/or MP cost to perform special/freespecials.
705 {
706     int cost:16;                           //Amount of energy cost.
707     int disable:16;                        //Disable flag. See check_energy function.
708     int mponly:8;                         //MPonly type. 0 = MP while available, then HP. 1 = MP only. 2 = HP only.
709 }s_energycost;
710 
711 typedef struct                                      //2011_04_01, DC: On frame movement (slide, jump, dive, etc.).
712 {
713     int				ent;							//Index of entity to spawn on liftoff of jump action.
714     short int		f;                              //Frame to begin jump action.
715 	float           v;    		                    //Vertical velocity.
716 	float           x;                              //Horizontal velcoty.
717 	float           z;                              //Lateral velocity.
718 }s_jumpframe;
719 
720 typedef struct                                      //2011_04_01, DC: Behavior when reaching base after jump or fall.
721 {
722 	short int       frame;                          //Frame to assume on landing.
723 	int             ent;                            //Index of entity to spawn on landing.
724 }s_landframe;
725 
726 typedef struct                                      //2011_04_01, DC: Animation looping.
727 {
728     int frameend:16;                       //Frame animation reaches before looping.
729     int framestart:16;                     //Frame animation loops back to.
730     int mode:8;                           //0 = No loop, 1 = Loop. Redundant after frame additions, but needed for backward compatibility.
731 }s_loop;
732 
733 typedef struct                                      //2011_04_01, DC: Frame based screen shake functionality.
734 {
735     int     cnt:8;                            //Repetition count.
736     int     framestart:16;                     //Frame to start quake.
737     int     repeat:8;                         //Repetitons.
738     int     v:8;                              //Vertical distance of screen movement (in pixels).
739 }s_quakeframe;
740 
741 typedef struct                                      //2011_04_01, DC: Distance to target verification for AI running, jumping, following parent, and combo chains for all entity types.
742 {
743     short int       xmin;                           //Minimum horizontal range.
744     short int       xmax;                           //Maximum horizontal range.
745     short int       zmin;                           //Minimum lateral range.
746     short int       zmax;                           //Maximum lateral range.
747     short int       amin;                           //Minimum vertical range.
748     short int       amax;                           //Maximum vertical range.
749     short int       bmin;                           //Minumum base range.
750     short int       bmax;                           //Maximum base rnage.
751 }s_range;                                           //2011_04_01, DC: Target range verification for various AI and player functions.
752 
753 typedef struct
754 {
755 	int model_index;
756 	int index; //unique id
757 	int numframes:16;
758 	s_loop loop; // Animation looping. 2011_03_31, DC: Moved to struct.
759 	int height:16; // entity's height during animation
760 	int tossframe:16; // Used to determine which frame will toss a bomb/grenade
761 	int shootframe:16;
762 	int throwframe:16;
763 	int throwa:16; //	Used for setting the "a" at which weapons are spawned
764 	// various entity model id, knife/star/bomb etc
765 	int custknife;
766 	int custstar;
767 	int custbomb;
768 	int custpshotno;
769 	int subentity; // Store the sub-entity's name for further use
770 	s_energycost energycost; // 1-10-05 to adjust the amount of energy used for specials. 2011_03_31, DC: Moved to struct.
771 	float chargetime; // charge time for an animation
772 	s_jumpframe jumpframe; // Jumpframe action. 2011_04_01, DC: moved to struct.
773 	float bounce; // -tossv/bounce = new tossv
774 	int* soundtoplay; // each frame can have a sound
775 	int* sprite; // sprite[set][framenumber]
776 	short* delay;
777 	short* move;
778 	short* movez;
779 	short* movea;
780 	short* seta; // Now characters can have a custom "a" value
781 	short* vulnerable;
782 	short (*bbox_coords)[5];
783 	int* shadow;
784 	unsigned char* idle; // Allow free move
785 	short (*shadow_coords)[2];            // x, z offset of shadow
786 	s_drawmethod **drawmethods;
787 	s_attack** attacks;
788 	float (*platform)[8]; // Now entities can have others land on them
789 	s_range range; // Verify distance to target, jump landings, etc.. 2011_04_01, DC: Moved to struct.
790 	int flipframe:16; // Turns entities around on the desired frame
791 	int followanim:16; // use which FOLLOW anim?
792 	int followcond:8; // conditions under which to use a followup
793 	s_counterrange counterrange; // Auto counter attack. 2011_04_01, DC: Moved to struct.
794 	int cancel:8; // Cancel anims with freespecial
795 	int attackone:8; // stick on the only one victim
796 	int dive:8; // UT: make dive a similar property as antigravity
797 	short* weaponframe; // Specify with a frame when to switch to a weapon model
798 	s_quakeframe quakeframe; // Screen shake effect. 2011_04_01, DC; Moved to struct.
799     float* spawnframe; // Spawn the subentity as its default type. {frame} {x} {z} {a} {relative?}
800     float* summonframe; // Summon the subentity as an ally, only one though {frame} {x} {z} {a} {relative?}
801 	int unsummonframe:16; // Un-summon the entity
802 	s_landframe landframe; // Landing behavior. 2011_04_01, DC: Moved to struct.
803 	int dropframe:16; // if tossv < 0, this frame will be set
804 	int animhits:16; // Does the attack need to hit before cancel is allowed?
805 	int sync:16; // sychronize frame to previous animation if they matches
806 }s_anim;
807 
808 typedef struct
809 {
810 	int     mode;
811 	float   factor;
812 	int     cap_min;
813 	int     cap_max;
814 	int     range_min;
815 	int     range_max;
816 }s_edelay;
817 
818 struct animlist{
819 	s_anim *anim;
820 	struct animlist *next;
821 };
822 typedef struct animlist s_anim_list;
823 s_anim_list *anim_list;
824 
825 typedef enum {
826 	horizontalbar = 0,
827 	verticalbar = 1,
828 } barorient;
829 
830 typedef enum {
831 	valuebar = 0,
832 	percentagebar = 1,
833 } bartype;
834 
835 typedef struct
836 {
837    short        offsetx:16;
838    short        offsety:16;
839    short        sizex:16;
840    short        sizey:16;
841    bartype      type:8;
842    barorient    orientation:8;
843    char         noborder:8;
844    char         direction:8;  //0) left to right or botom to top 1) reversed
845    int          barlayer:32;
846    int          backlayer:32;
847    int          borderlayer:32;
848    int          shadowlayer:32;
849    int          (*colourtable)[11]; //0 default backfill 1-10 foreground colours
850 }s_barstatus;
851 
852 typedef enum {
853 	LSTYPE_NONE = 0,
854 	LSTYPE_BAR = 1,
855 	LSTYPE_BACKGROUND = 2,
856 } loadingScreenType;
857 
858 typedef struct {
859 	loadingScreenType set;
860 	/*set determines how loading screen would be.
861 	- 0 = no loading screen.
862 	- 1 = background and status bar.
863 	- 2 = background only.
864 	- 3 = status bar only.
865 	*/
866 	char tf; //determines used font number for "LOADING" text (last element in command, moved here because of alignment)
867 	/*
868 	- 0 = font.gif
869 	- 1 = font2.gif
870 	- 2 = font3.gif
871 	- 3 = font4.gif */
872 	short bx; //determines x and y coordinates of loading bar top left's location respectively
873 	short by;
874 	short bsize; // length of bar in pixels
875 	short tx; //determines x and y coordinates of "LOADING" text location respectively.
876 	short ty;
877 	short refreshMs; // modder defined number of milliseconds in which the screen is updated while loading
878 } s_loadingbar;
879 
880 typedef struct {
881 	Script*         animation_script;               //system generated script
882 	Script*         update_script;                  //execute when update_ents
883 	Script*         think_script;                   //execute when entity thinks.
884 	Script*         takedamage_script;              //execute when taking damage.
885 	Script*         ondeath_script;                 //execute when killed in game.
886 	Script*         onkill_script;                  //execute when removed from play.
887 	Script*         onpain_script;                  //Execute when put in pain animation.
888 	Script*         onfall_script;                  //execute when falling.
889 	Script*         onblocks_script;                //execute when blocked by screen.
890 	Script*         onblockw_script;                //execute when blocked by wall.
891 	Script*         onblocko_script;                //execute when blocked by obstacle.
892 	Script*         onblockz_script;                //execute when blocked by Z.
893 	Script*         onblocka_script;                //execute when "hit head".
894 	Script*         onmovex_script;                 //execute when moving along X axis.
895 	Script*         onmovez_script;                 //execute when moving along Z axis.
896 	Script*         onmovea_script;                 //execute when moving along A axis.
897 	Script*         didhit_script;                  //execute when attack hits another.
898 	Script*         onspawn_script;                 //execute when spawned.
899 	Script*         key_script;                     //execute when entity's player presses a key
900 	Script*         didblock_script;                //execute when blocking attack.
901 	Script*         ondoattack_script;              //execute when attack passes do_attack checks.
902 } s_scripts;
903 
904 typedef enum  {
905 	MF_NONE = 0,
906 	MF_ANIMLIST = 1,
907 	MF_COLOURMAP = 2,
908 	MF_PALETTE = 4,
909 	MF_WEAPONS = 8,
910 	MF_BRANCH = 16,
911 	MF_ANIMATION = 32,
912 	MF_DEFENSE = 64,
913 	MF_OFF_FACTORS = 128,
914 	MF_SPECIAL = 256,
915 	MF_SMARTBOMB = 512,
916 	MF_SCRIPTS = 1024,
917 } ModelFreetype;
918 #define MF_ALL 0x7ff
919 
920 typedef struct
921 {
922     short int       current;                        //Current guard points remaining.
923     short int       maximum;                        //Maximum guard points.
924 } s_guardpoints;                                    //2011_04_05, DC: Guardpoints feature added by OX.
925 
926 typedef struct
927 {
928     short int		def;                            //Default icon.
929     short int       die;     					    //Health depleted.
930     short int		get;    					    //Retrieving item.
931 	short int       mphigh;                         //MP bar icon; at 66% or more (default if other mp icons not used).
932 	short int       mplow;                          //MP bar icon; at or between 0% and 32%.
933 	short int       mpmed;                          //MP bar icon; at or between 33% and 65%.
934 	short int 		pain;   					    //Taking damage.
935 	short int       weapon;                         //Weapon model.
936 	short int       x;                              //X position.
937 	short int       y;                              //Y position.
938 } s_icon;                                           //2011_04_05, DC: In game icons added 2005_01_20.
939 
940 typedef struct
941 {
942     short int       current;                        //Current juggle points accumulated.
943     short int       maximum;                        //Maximum juggle points possible.
944 } s_jugglepoints;                                   //2011_04_05, DC: Jugglepoints feature added by OX.
945 
946 typedef struct
947 {
948     signed char     frozen;                         //Frozen.
949     signed char     hide_end;                       //End range for maps hidden during character selection.
950     signed char     hide_start;                     //Start range for maps hidden during character selection.
951     signed char     ko;                             //Health depleted.
952     signed char     kotype;                         //KO map application. 0 = Immediately. 1 = At last frame of fall/death animation.
953 } s_maps;                                           //2011_04_07, DC: Pre defined color map selections and behavior.
954 
955 typedef struct
956 {
957     short int       amax;                           //Maximum vertical range.
958     short int       amin;                           //Minimum vertical range.
959     short int       xmax;                           //Maximum horizontal range.
960     short int       xmin;                           //Minimum horizontal range.
961     short int       zmax;                           //Maximum lateral range.
962     short int       zmin;                           //Minimum lateral range.
963 } s_sight;                                          //2011_04_05, DC: Range from self AI can detect other entities.
964 
965 typedef struct
966 {
967     signed char     detect;                         //Invisbility penetration. If self's detect >= target's hide, self can "see" target.
968     signed char     hide;                           //Invisibility to AI.
969 } s_stealth;                                        //2011_04_05, DC: Invisibility to AI feature added by DC.
970 
971 
972 // WIP
973 typedef struct
974 {
975 	int input[MAX_SPECIAL_INPUTS];
976 	int	steps;
977 	int anim;
978 	int	cancel;		//should be fine to have 0 if idle is not a valid choice
979 	int	startframe;
980 	int endframe;
981 	int hits;
982 	int valid;		// should not be global unless nosame is set, but anyway...
983 	//int (*function)(); //reserved
984 } s_com;
985 
986 typedef struct{
987 	float x;
988 	float z;
989 }
990  point2d;
991 
992 typedef struct {
993 	float          factor;                //basic defense factors: damage = damage*defense
994 	float          pain;                   //Pain factor (like nopain) for defense type.
995 	float          knockdown;              //Knockdowncount (like knockdowncount) for attack type.
996 	float          blockpower;             //If > unblockable, this attack type is blocked.
997 	float          blockthreshold;         //Strongest attack from this attack type that can be blocked.
998 	float          blockratio;             //% of damage still taken from this attack type when blocked.
999 	float          blocktype;             //0 = HP, 1=MP, 2=both taken when this attack type is blocked.
1000 }s_defense;
1001 
1002 typedef struct
1003 {
1004 	int             index;
1005 	char*           name;
1006 	char*           path;                           // Path, so scripts can dynamically get files, sprites, sounds, etc.
1007 	unsigned	    score;
1008 	float           stats[20];                      // Parameters that do nothing on their own.
1009 	int  			health;
1010 	float           scroll;                         // Autoscroll like panel entity.
1011 	unsigned        offscreenkill;                  // for biker, arrow, etc
1012 	//unsigned        offscreenkillz;
1013 	//unsigned        offscreeenkila;
1014 	int 			mp;							    // mp's variable for mpbar by tails
1015 	int			counter:16;						// counter of weapons by tails
1016 	unsigned 	shootnum:8; 					// counter of shots by tails
1017 	unsigned 	reload:8; 						// reload max shots by tails
1018 	int			reactive:8;						// Used for setting the "a" at which weapons are spawned
1019 	int			typeshot:8; 					// see if weapon is a gun or knife by tails
1020 	int			animal:8;  						// see is the weapon is a animal by tails
1021 	int 		nolife:8;	 					// Feb 25, 2005 - Variable flag to show life 0 = no, else yes
1022 	int 		makeinv;	 					// Option to spawn player invincible >0 blink <0 noblink
1023 	int         riseinv;                        // how many seconds will the character become invincible after rise >0 blink, <0 noblink
1024 	int			dofreeze:8;						// Flag to freeze all enemies/players while special is executed
1025 	int			noquake:8;						// Flag to make the screen shake when entity lands 1 = no, else yes
1026 	int			ground:8;						// Flag to determine if enemy projectiles only hit the enemy when hitting the ground
1027 	int 		multiple;						// So you can control how many points are given for hitting opponents
1028 	int			bounce:8;						// Flag to determine if bounce/quake is to be used.
1029 	int			type:16;
1030 	int			subtype:8;
1031 	s_icon      icon;                           //In game icons added 2005_01_20. 2011_04_05, DC: Moved to struct.
1032 	int			parrow[MAX_PLAYERS][3];			// Image to be displayed when player spawns invincible
1033 	int			setlayer;						// Used for forcing enities to be displayed behind
1034 	int			thold:16;						// The entities threshold for block
1035 	s_maps      maps;                           //2011_04_07, DC: Pre defined color map selections and behavior.
1036 	int			alpha:8;						// New alpha variable to determine if the entity uses alpha transparency
1037 	int			toflip:8;						// Flag to determine if flashes flip or not
1038 	int			shadow:8;
1039 	int         gfxshadow:8;                    // use current frame to create a shadow
1040 	int			aironly:8;						// Used to determine if shadows will be shown when jumping only
1041 	int			nomove:8;						// Flag for static enemies
1042 	int			noflip:8;						// Flag to determine if static enemies flip or stay facing the same direction
1043 	int			nodrop:8;						// Flag to determine if enemies can be knocked down
1044 	int			nodieblink:8;					// Flag to determine if blinking while playing die animation
1045 	int			holdblock:8;					// Continue the block animation as long as the player holds the button down
1046 	int         nopassiveblock:8;               // Don't auto block randomly
1047 	int			blockback:8;					// Able to block attacks from behind
1048 	int			blockodds:16;					// Odds that an enemy will block an attack (1 : blockodds)
1049 	s_edelay    edelay;                         // Entity level delay adjustment.
1050 	float		runspeed;						// The speed the character runs at
1051 	float		runjumpheight;					// The height the character jumps when running
1052 	float		runjumpdist;					// The distance the character jumps when running
1053 	int			noatflash:8;					// Flag to determine if attacking characters attack spawns a flash
1054 	int			runupdown:8;					// Flag to determine if a player will continue to run while pressing up or down
1055 	int			runhold:8;						// Flag to determine if a player will continue to run if holding down forward when landing
1056 	int			remove:8;						// Flag to remove a projectile on contact or not
1057 	float		throwheight;					// The height at which an opponent can now be adjusted
1058 	float		throwdist;						// The distance an opponent can now be adjusted
1059 	int         throwframewait:16;              // The frame victim is thrown during ANIM_THROW, added by kbandressen 10/20/06
1060 	s_com		*special;						// Stores freespecials
1061 	int			specials_loaded:16;				// Stores how many specials have been loaded
1062 	int         diesound;
1063 	int			weapnum:8;
1064 	int			secret:8;
1065 	int			clearcount:8;
1066 	char		weaploss[2];					// Determines possibility of losing weapon.
1067 	int         ownweapons:8;                   // is the weapon list own or share with others
1068 	int         *weapon;						// weapon model list
1069 	int			numweapons;
1070 
1071 	// these are model id of various stuff
1072 	int             project;
1073 	int             rider;   		                // 7-1-2005 now every "biker" can have a new driver!
1074 	int             knife;   		                // 7-1-2005 now every enemy can have their own "knife" projectile
1075 	int             pshotno;   		                // 7-1-2005 now every enemy can have their own "knife" projectile
1076 	int             star;   			            // 7-1-2005 now every enemy can have their own "ninja star" projectiles
1077 	int             bomb;   			            // New projectile type for exploding bombs/grenades/dynamite
1078 	int             flash;   			            // Now each entity can have their own flash
1079 	int             bflash;                         // Flash that plays when an attack is blocked
1080 	int             dust[3];   			            // Dust spawn (0 = Fall land, 1 = Jumpland, 2 = Jumpstart.)
1081 	int			height:16;						// Used to set height of player in pixels
1082 	float			speed;
1083 	float			grabdistance;					// 30-12-2004	grabdistance varirable adder per character
1084 	float			pathfindstep;					// UT: how long each step if the entity is trying to find a way
1085 	int			grabflip:8;						// Flip target or not, bit0: grabber, bit1: opponent
1086 	float           jumpspeed;                      // normal jump foward speed, default to max(1, speed)
1087 	float			jumpheight;						// 28-12-2004	Jump height variable added per character
1088 	int            jumpmovex:8;                    // low byte: 0 default 1 flip in air, 2 move in air, 3 flip and move
1089 	int            jumpmovez:8;                    // 2nd byte: 0 default 1 zjump with flip(not implemented yet) 2 z jump move in air, 3 1+2
1090 	int            grabfinish:8;                   // wait for grab animation to finish before do other actoins
1091 	int 			antigrab:8;						// anti-grab factor
1092 	int             grabforce;                      // grab factor, antigrab - grabforce <= 0 means can grab
1093 	int            facing:8;                       // 0 no effect, 1 alway right, 2 always left, 3, affected by level dir
1094 	int			grabback:8;						// Flag to determine if entities grab images display behind opponenets
1095 	int            grabturn:8;
1096 	int			paingrab:8;						// Can only be grabbed when in pain
1097 	float           grabwalkspeed;
1098 	int			throwdamage:16;					// 1-14-05  adjust throw damage
1099 	unsigned char*  palette;                        // original palette for 32/16bit mode
1100 	unsigned char*	colourmap[MAX_COLOUR_MAPS];
1101 	int			maps_loaded:8;					// Used for player colourmap selecting
1102 	int			unload:8; 						// Unload model after level completed?
1103 	int			falldie:8; 						// Play die animation?
1104 	int            globalmap:8;                    // use global palette for its colour map in 24bit mode
1105 	int			nopain:8;
1106 	int            summonkill:8;                   // kill it's summoned entity when died;  0. dont kill 1. kill summoned only 2. kill all spawned entity
1107 	int            combostyle:8;
1108 	int			blockpain:8;
1109 	char       atchain[MAX_ATCHAIN];
1110 	int		    chainlength:8;
1111 	s_anim**        animation;
1112 	int				credit:8;
1113 	int				escapehits:8;					// Escape spammers!
1114 	int				chargerate:8;					// For the charge animation
1115 	int	            guardrate:8;                    // Rate for guardpoints recover.
1116 	int				mprate:8;						// For time-based mp recovery.
1117 	int	            mpdroprate:8;                   // Time based MP loss.
1118 	int	            mpstable:8;                     // MP stable type.
1119 	int				mpstableval:16;                 // MP Stable target.
1120 	int				aggression:16;					// For enemy A.I.
1121 	short			risetime[2];					// 0 = Rise delay, 1 = Riseattack delay.
1122 	unsigned		sleepwait:16;
1123 	int				riseattacktype:8;
1124 	s_jugglepoints  jugglepoints;                   // Juggle points feature by OX. 2011_04_05, DC: Moved to struct.
1125 	s_guardpoints   guardpoints;                    // Guard points feature by OX. 2011_04_05, DC: Moved to struct.
1126 	int            mpswitch:8;                     // switch between reduce or gain mp for mpstabletype 4
1127 	int				turndelay:16;                   // turn delay
1128 	float           lifespan;                       // lifespan count down
1129 	float           knockdowncount;                 // the knock down count for this entity
1130 	float			attackthrottle;					// how often the enemy refuse to attack
1131 	float			attackthrottletime;				// how long does the throttle status last
1132 	s_stealth       stealth;						// Invisibility to AI feature added by DC. 2011_04_05, DC: Moved to struct.
1133 
1134 	//---------------new A.I. switches-----------
1135 	int           hostile:16;                     // specify hostile types
1136 	int           candamage:16;                   // specify types that can be damaged by this entity
1137 	int           projectilehit:16;               // specify types that can be hit by this entity if it is thrown
1138 	unsigned		aimove;                      // move style
1139 	s_sight			sight;						    // Sight range. 2011_04_05, DC: Moved to struct.
1140 	unsigned    aiattack;                    // attack/defend style
1141 
1142 	//----------------physical system-------------------
1143 	float           antigravity;                    //antigravity : gravity * (1- antigravity)
1144 
1145 	//--------------new property for endlevel item--------
1146 	char*           branch;                         //level branch name
1147 	char            model_flag:8;                   //used to judge some copy method when setting new model to an entity
1148 
1149 	s_defense*		defense;						//defense related, make a struct to aid copying
1150 	float*          offense_factors;                //basic offense factors: damage = damage*offense
1151 	s_attack*       smartbomb;
1152 
1153 	// e.g., boss
1154 	s_barstatus     hpbarstatus;
1155 	int           hpx:16;
1156 	int           hpy:16;
1157 	int           namex:16;
1158 	int           namey:16;
1159 
1160 	// movement flags
1161 	int            subject_to_wall:8;
1162 	int            subject_to_platform:8;
1163 	int            subject_to_obstacle:8;
1164 	int            subject_to_hole:8;
1165 	int            subject_to_gravity:8;
1166 	int            subject_to_screen:8;
1167 	int            subject_to_minz:8;
1168 	int            subject_to_maxz:8;
1169 	int            no_adjust_base:8;               // dont change base to 0 automatically
1170 	int            instantitemdeath:8;             // no delay before item suicides
1171 	int	hasPlatforms:8;
1172 	int isSubclassed:8;
1173 	ModelFreetype	freetypes;
1174 	s_scripts*	scripts;
1175 }s_model;
1176 
1177 typedef struct
1178 {
1179 	char			*name;
1180 	char			*path;
1181 	s_model*        model;
1182 	char            loadflag;
1183 	char            selectable;
1184 }s_modelcache;
1185 s_modelcache *model_cache;
1186 
1187 typedef struct
1188 {
1189     int             rise;                           //Time modifier before rise.
1190     int             riseattack;                     //Time modifier before riseattack.
1191     int             riseattack_stall;               //Total stalltime before riseattack.
1192 } s_staydown;                                       //2011_04_08, DC: Delay modifiers before rise or riseattack can take place.
1193 
1194 typedef struct entity
1195 {
1196 	int				spawntype:8;                    // Type of spawn. 1 = Level spawn. 0 for all else (subject to change).
1197 	int				exists:8;                       // flag to determine if it is a valid entity.
1198 	int				reactive:8;						// Used for setting the "a" at which weapons are spawned
1199 	int				ptype:8;
1200 	int				playerindex:8;
1201 	float           stats[20];                      // Parameters that do nothing on their own.
1202 	int             health;                         // current hp
1203 	int             mp;                             // current mp
1204 	int  			oldhealth;
1205 	int  			oldmp;							//mp's variable for mp for players by tails
1206 	char			name[MAX_NAME_LEN+1];           // this is display name
1207 	s_model         *defaultmodel;                  // this is the default model
1208 	s_model 		*model;                         // current model
1209 	s_model         modeldata;                      // model data copyied here
1210 	int 			item:16;                        // item model id
1211 	int				itemmap:8;						// Now items spawned can have their properties changed
1212 	int				itemtrans:8;                    // alpha effect of item
1213 	char			itemalias[MAX_NAME_LEN+1];		// Now items spawned can have their properties changed
1214 	int  			itemhealth;						// Now items spawned can have their properties changed
1215 	int				itemplayer_count:8;
1216 	int				boss:8;
1217 	int				dying:8;						// Coresponds with which remap is to be used for the dying flash
1218 	unsigned		per1:16;							// Used to store at what health value the entity begins to flash
1219 	unsigned		per2:16;							// Used to store at what health value the entity flashes more rapidly
1220 	int				direction:8;					// 0=left 1=right
1221 	int				nograb:8;			            // Some enemies cannot be grabbed (bikes) - now used with cantgrab as well
1222 	int				movestep:8;
1223 	float			x;								// X
1224 	float			z;								// Depth
1225 	float			a;								// Altitude
1226 	float			xdir;
1227 	float			zdir;
1228 	float           destx;							// temporary values for ai functions
1229 	float			destz;
1230 	float			base;							// Default altitude
1231 	float           altbase;                        // Altitude affected by movea
1232 	float			tossv;							// Effect of gravity
1233 	float           jumpz;
1234 	float           jumpx;
1235 	float           jumpv;
1236 	int				jumpid:16;
1237 	unsigned char   combostep[MAX_SPECIAL_INPUTS];  // merge into an array to clear up some code
1238 
1239 	// ---------------------- action times -------------------------------
1240 	u32	lastmove;
1241 	u32 lastdir;
1242 	u32 timestamp;
1243 	u32 releasetime;
1244 	u32 toss_time;						// Used by gravity code
1245 	u32 stalltime;
1246 	u32 combotime;						// For multiple-hit combo
1247 	u32 movetime;						// For special move
1248 	u32 freezetime;						// Used to store at what point the a frozen entity becomes unfrozen
1249 	u32 maptime;						// used by forcemap
1250 	u32 sealtime;						// used by seal (stops special moves).
1251 	u32 dot_time[MAX_DOTS]; 			//Dot time to expire.
1252 	int             dot[MAX_DOTS];                  //Dot mode.
1253 	int             dot_atk[MAX_DOTS];              //Dot attack type.
1254 	int             dot_force[MAX_DOTS];            //Dot amount.
1255 	int             dot_rate[MAX_DOTS];             //Dot delay per tick.
1256 	int	            dot_cnt[MAX_DOTS];              //Dot time of next tick.
1257 	struct entity   *dot_owner[MAX_DOTS];           //Dot owner.
1258 	u32 magictime;
1259 	u32 guardtime;
1260 	u32 nextanim;
1261 	u32 nextthink;
1262 	u32 nextattack;
1263 	u32 pain_time;
1264 	u32 pausetime;						// 2012/4/30 UT: Remove lastanimpos and add this. Otherwise hit pause is always bound to frame and attack box.
1265 	u32 mpchargetime;					// For the CHARGE animation
1266 	u32 sleeptime;						// For the SLEEP animation
1267 	u32 rushtime;						// rush combo timer
1268 	u32 knockdowntime;                  // count knock down hit
1269 	u32 invinctime;						// Used to set time for invincibility to expire
1270 	u32 turntime;
1271 	s_staydown      staydown;                       //Delay modifiers before rise or riseattack can take place. 2011_04_08, DC: moved to struct.
1272 	// -------------------------end of times ------------------------------
1273 	int				update_mark:8;
1274 
1275 	//------------------------- a lot of flags ---------------------------
1276 
1277 	int				seal:8;                         //1 = No specials.
1278 	int             dead:8;
1279 	int             jumping:8;						// Stuff useful for AI
1280 	int             idling:8;
1281 	int             drop:8;
1282 	int             attacking:8;
1283 	int             getting:8;
1284 	int             turning:8;
1285 	int             charging:8;
1286 	int             blocking:8;
1287 	int				falling:8;
1288 	int             running:8;						// Flag to determine if a player is running
1289 	int             grabwalking:8;                    // a flag for grabwalk check
1290 	int             inpain:8;                         // playing pain animation
1291 	int          	frozen:8;							// Flag to determine if an entity is frozen
1292 	int				blink:8;
1293 	int				invincible:8;						// Flag used to determine if player is currently invincible
1294 	int				autokill:8;						// Kill on end animation
1295 	int				remove_on_attack:8;
1296 	int				cantfire:8;						// Flag to determine if another shot can be fired that costs energy
1297 	int				tocost:8;							// Flag to determine if special costs life if doesn't hit an enemy
1298 	int				noaicontrol:8;                    // pause A.I. control
1299 	int				projectile:8;
1300 	int				toexplode:8;						// Needed to determine if the projectile is a type that will explode (bombs, dynamite, etc)
1301 	int				animating:8;						// Set by animation code
1302 	int				arrowon:8;						// Flag to display parrow/parrow2 or not
1303 	unsigned		pathblocked:8;
1304 
1305 	point2d * waypoints;
1306 	int numwaypoints;
1307 	int			animpos:16;
1308 	int			animnum:16;                     // animation id
1309 	s_anim			*animation;
1310 	float           knockdowncount;
1311 	int			damage_on_landing:8;
1312 	int            damagetype:8;                   // used for set death animation or pain animation
1313 	int            map:8;							// Stores the colourmap for restoring purposes
1314 	void			(*think)();
1315 	void            (*takeaction)();
1316 	int             (*takedamage)(struct entity*,s_attack*);
1317 	int             (*trymove)(float, float);
1318 	int			attack_id:16;
1319 	int			hit_by_attack_id:16;
1320 	unsigned char	*colourmap;
1321 	//struct entity   *thrower;
1322 	struct entity	*link;							// Used to link 2 entities together.
1323 	struct entity	*owner;							// Added for "hitenemy" flag so projectile recognizes its owner
1324 	struct entity	*grabbing;						// Added for "platform level" layering
1325 	struct entity	*weapent;
1326 	struct entity   *parent;                        //Its spawner
1327 	struct entity   *subentity;                     //store the sub entity
1328 	struct entity   *opponent;
1329 	struct entity   *lasthit;
1330 	struct entity   *hithead;                       // when a player jumps and hits head on the bottom of a platform
1331 	struct entity   *bound;                         // ignore trymove method, follow this entity
1332 	struct entity   *landed_on_platform;
1333 	short           bindoffset[4];                  // x, z, a, dir; int is ok
1334 	int           bindanim:16;                    // keep the bound entities same animation id
1335 	char			escapecount:8;					// For escapehits
1336 	unsigned short	rush[2];						// rush combo and max combo
1337 	float           lifespancountdown;              // life span count down
1338 
1339 	//------------- these factors will be added by basic factors of model-------------
1340 	s_defense*		defense;
1341 	float*          offense_factors;                //offense factors: damage = damage*(1+def)
1342 	float           antigravity;                    // gravity*(1-antigravity)
1343 
1344 	//-------------------A.I. movement factors ----------------------------
1345 	int             sortid;                         // id for sprite queue sort
1346 	ScriptVariant* entvars;
1347 	s_drawmethod    drawmethod;
1348 	s_scripts* scripts;
1349 }entity;
1350 
1351 
1352 typedef struct
1353 {
1354 	char			name[MAX_NAME_LEN+1];
1355 	char			colourmap:8;
1356 	unsigned int    score:32;
1357 	unsigned char	lives:8;
1358 	unsigned char	credits:8;
1359 	entity			*ent;
1360 	u32				keys;
1361 	u32				newkeys;
1362 	u32				playkeys;
1363 	u32				releasekeys;
1364 	u32				combokey[MAX_SPECIAL_INPUTS];
1365 	u32				inputtime[MAX_SPECIAL_INPUTS];
1366 	int				combostep;
1367 	int			    spawnhealth;
1368 	int  			spawnmp;
1369 	char			joining:8;
1370 	char			hasplayed:8;
1371 	char			weapnum:8;
1372 }s_player;
1373 
1374 
1375 typedef struct s_spawn_script_cache_node
1376 {
1377 	char		*filename;
1378 	Script		*cached_spawn_script;
1379 	struct s_spawn_script_cache_node *next;
1380 } s_spawn_script_cache_node;
1381 
1382 typedef struct s_spawn_script_list_node
1383 {
1384 	Script		*spawn_script;
1385 	struct s_spawn_script_list_node *next;
1386 } s_spawn_script_list_node;
1387 
1388 
1389 typedef struct
1390 {
1391 	short			at:16;
1392 	char			wait:8;
1393 	char            nojoin:8;                   // dont allow new hero to join
1394 	char            spawnplayer_count:8;        // spawn this entity according to the amount of players
1395 	char            palette:8;                  //change system palette to ...
1396 	short			groupmin:16;
1397 	short			groupmax:16;
1398 	short           scrollminz:16;              // new scroll limit
1399 	short           scrollmaxz:16;
1400 	short           blockade:16;                //limit how far you can go back
1401 	short           light[2];                   // x, z  light direction, for gfx shadow
1402 	char            shadowcolor:8;              // -1 no shadow
1403 	int             shadowalpha:8;
1404 	char			music[128];
1405 	float           musicfade;
1406 	u32             musicoffset;
1407 	char			*name;                      // must be a name in the model list, so just reference
1408 	int             index;                      // model id
1409 	int             itemindex;                  // item model id
1410 	int             weaponindex;                // the spawned entity with an weapon item, this is the id of the item model
1411 	char			alpha:8;		  		    // Used for alpha effects
1412 	char			boss:8;
1413 	char			flip:8;
1414 	char			itemtrans:8;
1415 	char			itemmap:8;
1416 	char			colourmap:8;
1417 	char			dying:8;					// Used for the dying flash animation
1418 	unsigned short	per1:16;						// Used to store at what health value the entity begins to flash
1419 	unsigned short	per2:16;					    // Used to store at what health value the entity flashes more rapidly
1420 	char			nolife:8;					// So nolife can be overriden for all characters
1421 	char            itemplayer_count:8;         // spawn the item according to the amount of players
1422 	s_model         *itemmodel;
1423 	s_model         *model;
1424 	char			alias[MAX_NAME_LEN+1];
1425 	char			*item;                      // must be a name in the model list, so just reference
1426 	char			itemalias[MAX_NAME_LEN+1];
1427 	int			    itemhealth;
1428 	int			    health[MAX_PLAYERS];
1429 	int			    mp;							// mp's variable for mpbar by tails
1430 	unsigned int	score:32;					// So score can be overridden for enemies/obstacles
1431 	int				multiple;				// So score can be overridden for enemies/obstacles
1432 	// coords
1433 	float			x;
1434 	float			z;
1435 	float			a;
1436 	unsigned char	credit:8;
1437 	short			aggression:16;				// For enemy A.I.
1438 	char            spawntype;                  // Pass 1 when a level spawn.
1439 	char            *weapon;                    // spawn with a weapon, since it should be in the model list, so the model must be loaded, just reference its name
1440 	s_model         *weaponmodel;
1441 	s_spawn_script_list_node*          spawn_script_list_head;
1442 }s_spawn_entry;
1443 
1444 typedef enum
1445 {
1446 	normal_level=0,
1447 	cut_scene = 1,
1448 	select_screen = 2,
1449 }le_type;
1450 
1451 typedef struct
1452 {
1453 	char            *branchname;            // Use a name so we can find this level in branches
1454 	char			*filename;
1455 	le_type         type;                   // see le_type
1456 	int				z_coords[3];			// Used for setting custom "z"
1457 	int				gonext;                 // 0. dont complete this level and display score,
1458 											// 1. complete level and display score,
1459 											// 2. complete game, show hall of fame
1460 }s_level_entry;
1461 
1462 
1463 typedef struct
1464 {
1465 	char* name;
1466 	int maxplayers;
1467 	int numlevels;
1468 	s_level_entry *levelorder;
1469 	int ifcomplete;
1470 	int noshowhof;
1471 	int lives;
1472 	int credits;
1473 	int custfade;
1474 	int musicoverlap; //** shouldn't it be level based?
1475 	int typemp; //** shouldn't it be model based?
1476 	int continuescore;
1477 	char* skipselect[MAX_PLAYERS]; //** better if level based
1478 	int saveflag;
1479 	int nosame;
1480 	int	noselect;
1481 
1482 }s_set_entry;
1483 
1484 
1485 //
1486 typedef enum
1487 {
1488 	bgt_bglayer,
1489 	bgt_fglayer,
1490 	bgt_panel,
1491 	bgt_frontpanel,
1492 	bgt_water,
1493 	bgt_background,
1494 	bgt_generic
1495 
1496 }bgloldtype;
1497 
1498 
1499 typedef struct
1500 {
1501 	bgloldtype     oldtype;
1502 	int            order;	//for panel order
1503 	gfx_entry      gfx;
1504 	int            width;
1505 	int            height;
1506 	float          xratio;
1507 	float          zratio;
1508 	int            xoffset;
1509 	int            zoffset;
1510 	int			   xspacing;
1511 	int			   zspacing;
1512 	s_drawmethod   drawmethod;
1513 	float          bgspeedratio;
1514 	int            enabled;
1515 	int            z;
1516 	int            quake;
1517 	int            neon;
1518 }s_layer;
1519 
1520 
1521 typedef struct
1522 {
1523 	char*			text;
1524 	int				t;		//Time to expire.
1525 	int				x;
1526 	int				y;
1527 	int				font;
1528 	int				z;
1529 }s_textobj;
1530 
1531 typedef struct
1532 {
1533 	int pos;
1534 	char *buf;
1535 	size_t size;
1536 }s_filestream;
1537 
1538 typedef struct
1539 {
1540 	char* name;
1541 	int numspawns;
1542 	s_spawn_entry spawnpoints[LEVEL_MAX_SPAWNS];
1543 	int numlayers;
1544 	s_layer layers[LEVEL_MAX_LAYERS];
1545 	int numlayersref;
1546 	s_layer layersref[LEVEL_MAX_LAYERS];
1547 	////////////////these below are layer reference
1548 	////////////////use them to ease layer finding for script users
1549 	s_layer* background; // the bglayer that contains the default background
1550 	int numpanels;
1551 	s_layer* panels[LEVEL_MAX_PANELS][3]; //normal neon screen
1552 	int numfrontpanels;
1553 	s_layer* frontpanels[LEVEL_MAX_PANELS];
1554 	int numbglayers;
1555 	s_layer* bglayers[LEVEL_MAX_LAYERS];
1556 	int numfglayers;
1557 	s_layer* fglayers[LEVEL_MAX_LAYERS];
1558 	int numgenericlayers;
1559 	s_layer* genericlayers[LEVEL_MAX_LAYERS];
1560 	int numwaters; // LOL what
1561 	s_layer* waters[LEVEL_MAX_LAYERS];
1562 	////////////////layer reference ends here
1563 	///////////////////////////////////////////////////////////////
1564 	s_textobj textobjs[LEVEL_MAX_TEXTOBJS];
1565 	int numfilestreams;
1566 	int cameraxoffset;
1567 	int camerazoffset;
1568 	int numholes;
1569 	int numwalls;						// Stores number of walls loaded
1570 	float holes[LEVEL_MAX_HOLES][7];
1571 	int holesfound[LEVEL_MAX_HOLES];
1572 	float walls[LEVEL_MAX_WALLS][8];		// Now you can have walls for different walkable areas
1573 	int wallsfound[LEVEL_MAX_WALLS];
1574 	int exit_blocked;
1575 	int exit_hole;
1576 	int scrolldir;
1577 	int width;
1578 	int rocking;
1579 	float bgspeed;						// Used to make autoscrolling backgrounds
1580 	float scrollspeed;					// UT: restore this command  2011/7/8
1581 	int bgdir;							// Used to set which direction the backgrounds scroll for autoscrolling backgrounds
1582 	int mirror;
1583 	int bosses;
1584 	char bossmusic[256];
1585 	unsigned int bossmusic_offset;
1586 	int numpalettes;
1587 	unsigned char palettes[LEVEL_MAX_PALETTES][1024];//dynamic palettes
1588 	unsigned char* blendings[LEVEL_MAX_PALETTES][MAX_BLENDINGS];//blending tables
1589 	int settime;						// Set time limit per level
1590 	int notime;							// Used to specify if the time is displayed 1 = no, else yes
1591 	int noreset;						// If set, clock will not reset when players spawn/die
1592 	int type;							// Used to specify which level type (1 = bonus, else regular)
1593 	int nospecial;						// Used to specify if you can use your special during bonus levels
1594 	int nohurt;							// Used to specify if you can hurt the other player during bonus levels
1595 	int noslow;							// Flag so the level doesn't slow down after a boss is defeated
1596 	int nohit;							// Not able to grab / hit other player on a per level basis
1597 	int spawn[MAX_PLAYERS][4];			// Used to determine the spawn position of players
1598 	int setweap;						// Levels can now specified which weapon will be used by default
1599 	int facing;                         // Force the players to face to ... 0 no effects, 1 right, 2 left, 3 affected by level dir
1600 //--------------------gravity system-------------------------
1601 	float maxfallspeed;
1602 	float maxtossspeed;
1603 	float gravity;
1604 //---------------------scripts-------------------------------
1605 	Script update_script;
1606 	Script updated_script;
1607 	Script key_script;
1608 	Script level_script;
1609 	Script endlevel_script;
1610 	s_spawn_script_cache_node* spawn_script_cache_head;
1611 	int pos;
1612 	u32 advancetime;
1613 	u32 quaketime;
1614 	int quake;
1615 	int waiting;
1616 
1617 }s_level;
1618 
1619 #define MAX_ARG_COUNT 64
1620 
1621 typedef struct ArgList {
1622 	size_t count;
1623 	size_t arglen[MAX_ARG_COUNT];
1624 	char* args[MAX_ARG_COUNT];
1625 } ArgList;
1626 
1627 int     buffer_pakfile(char* filename, char** pbuffer, size_t* psize);
1628 int     getsyspropertybyindex(ScriptVariant* var, int index);
1629 int     changesyspropertybyindex(int index, ScriptVariant* value);
1630 int     load_script(Script* script, char* path);
1631 void    init_scripts();
1632 void    load_scripts();
1633 void    execute_animation_script    (entity* ent);
1634 void    execute_takedamage_script   (entity* ent, entity* other, int force, int drop, int type, int noblock, int guardcost, int jugglecost, int pauseadd);
1635 void    execute_ondeath_script      (entity* ent, entity* other, int force, int drop, int type, int noblock, int guardcost, int jugglecost, int pauseadd);
1636 void    execute_onkill_script       (entity* ent);
1637 void    execute_onpain_script       (entity* ent, int iType, int iReset);
1638 void    execute_onfall_script       (entity* ent, entity* other, int force, int drop, int type, int noblock, int guardcost, int jugglecost, int pauseadd);
1639 void    execute_onblocks_script     (entity* ent);
1640 void    execute_onblockw_script     (entity* ent, int plane, float height);
1641 void    execute_onblocko_script     (entity* ent, entity* other);
1642 void    execute_onblockz_script     (entity* ent);
1643 void    execute_onblocka_script     (entity* ent, entity* other);
1644 void    execute_onmovex_script      (entity* ent);
1645 void    execute_onmovez_script      (entity* ent);
1646 void    execute_onmovea_script      (entity* ent);
1647 void    execute_didblock_script     (entity* ent, entity* other, int force, int drop, int type, int noblock, int guardcost, int jugglecost, int pauseadd);
1648 void    execute_ondoattack_script   (entity* ent, entity* other, int force, int drop, int type, int noblock, int guardcost, int jugglecost, int pauseadd, int iWhich, int iAtkID);
1649 void    execute_updateentity_script (entity* ent);
1650 void    execute_think_script        (entity* ent);
1651 void    execute_didhit_script       (entity* ent, entity* other, int force, int drop, int type, int noblock, int guardcost, int jugglecost, int pauseadd, int blocked);
1652 void    execute_onspawn_script      (entity* ent);
1653 void    clearsettings(void);
1654 void    savesettings(void);
1655 void    saveasdefault(void);
1656 void    loadsettings(void);
1657 void    loadfromdefault(void);
1658 void    clearSavedGame(void);
1659 void    clearHighScore(void);
1660 int    saveGameFile(void);
1661 int     loadGameFile(void);
1662 int		saveScriptFile(void);
1663 int		loadScriptFile(void);
1664 int    saveHighScoreFile(void);
1665 int    loadHighScoreFile(void);
1666 int music(char *filename, int loop, long offset);
1667 #if DC
1668 void check_music_opened(void);
1669 #endif
1670 char *findarg(char *command, int which);
1671 float diff(float a, float b);
1672 int inair(entity *e);
1673 float randf(float max);
1674 int _makecolour(int r, int g, int b);
1675 int load_colourmap(s_model * model, char *image1, char *image2);
1676 int load_palette(unsigned char* pal, char* filename);
1677 void standard_palette();
1678 void change_system_palette(int palindex);
1679 void unload_background();
1680 void lifebar_colors();
1681 void load_background(char *filename, int createtables);
1682 void unload_texture();
1683 void load_texture(char *filename);
1684 void freepanels();
1685 s_sprite * loadpanel2(char *filename);
1686 int loadpanel(char *filename_normal, char *filename_neon, char *filename_screen);
1687 int loadfrontpanel(char *filename);
1688 void resourceCleanUp(void);
1689 void freesprites();
1690 s_sprite * loadsprite2(char *filename, int* width, int* height);
1691 int loadsprite(char *filename, int ofsx, int ofsy, int bmpformat);
1692 void load_special_sprites();
1693 int load_special_sounds();
1694 s_model * find_model(char *name);
1695 s_model * nextplayermodel(s_model *current);
1696 s_model * prevplayermodel(s_model *current);
1697 void free_anim(s_anim * anim);
1698 void free_models();
1699 s_anim * alloc_anim();
1700 int addframe(s_anim * a, int spriteindex, int framecount, short delay, unsigned char idle,
1701 			 short *bbox, s_attack* attack, short move, short movez,
1702 			 short movea, short seta, float* platform, int frameshadow,
1703 			 short* shadow_coords, int soundtoplay, s_drawmethod* drawmethod);
1704 void cache_model(char *name, char *path, int flag);
1705 void remove_from_cache(char * name);
1706 void free_modelcache();
1707 int get_cached_model_index(char * name);
1708 char *get_cached_model_path(char * name);
1709 s_model* load_cached_model(char * name, char * owner, char unload);
1710 int is_set(s_model * model, int m);
1711 int load_script_setting();
1712 int load_models();
1713 void unload_levelorder();
1714 void load_levelorder();
1715 void unload_level();
1716 void load_level(char *filename);
1717 void drawlifebar(int x, int y, int h, int maxh);
1718 void drawmpbar(int x, int y, int m, int maxm);
1719 void update_loading(s_loadingbar* s,  int value, int max);
1720 void spawnplayer(int);
1721 void drop_all_enemies();
1722 void kill_all_enemies();
1723 void ent_set_colourmap(entity *ent, unsigned int which);
1724 void predrawstatus();
1725 void drawstatus();
1726 void addscore(int playerindex, int add);
1727 void free_ent(entity* e);
1728 void free_ents();
1729 int alloc_ents();
1730 entity * smartspawn(s_spawn_entry * p);
1731 int adjust_grabposition(entity* ent, entity* other, float dist, int grabin);
1732 int player_trymove(float xdir, float zdir);
1733 void toss(entity *ent, float lift);
1734 void player_think(void);
1735 void subtract_shot(void);
1736 void set_model_ex(entity* ent, char* modelname, int index, s_model* newmodel, int flag);
1737 void dropweapon(int flag);
1738 void biker_drive(void);
1739 void trap_think(void);
1740 void steamer_think(void);
1741 void text_think(void);
1742 void anything_walk(void);
1743 void adjust_walk_animation(entity* other);
1744 void kill(entity*);
1745 int player_takedamage(entity *other, s_attack* attack);
1746 int biker_takedamage(entity *other, s_attack* attack);
1747 int obstacle_takedamage(entity *other, s_attack* attack);
1748 void ent_set_anim(entity*, int, int);
1749 void suicide(void);
1750 void player_blink(void);
1751 void common_prejump();
1752 void common_dot();
1753 void tryjump(float, float, float, int);
1754 void dojump(float, float, float, int);
1755 void biker_drive(void);
1756 void ent_default_init(entity* e);
1757 void ent_spawn_ent(entity* ent);
1758 void ent_summon_ent(entity* ent);
1759 void ent_set_anim(entity *ent, int aninum, int resetable);
1760 void ent_set_colourmap(entity *ent, unsigned int which);
1761 void ent_set_model(entity * ent, char * modelname, int syncAnim);
1762 entity * spawn(float x, float z, float a, int direction, char * name, int index, s_model* model);
1763 void ent_unlink(entity *e);
1764 void ents_link(entity *e1, entity *e2);
1765 void kill(entity *victim);
1766 void kill_all();
1767 int checkhit(entity *attacker, entity *target, int counter);
1768 int checkhole(float x, float z);
1769 int testplatform(entity*, float, float, entity*);
1770 int testhole(int, float, float);
1771 int testwall(int, float, float);
1772 int checkwalls(float x, float z, float a1, float a2);
1773 int checkholes(float, float);
1774 int checkwall_below(float x, float z, float a);
1775 int checkwall(float x, float z);
1776 int testmove(entity*, float, float, float, float);
1777 entity * check_platform_below(float x, float z, float a, entity* exclude);
1778 entity * check_platform(float x, float z, entity* exclude);
1779 void do_attack(entity *e);
1780 void update_ents();
1781 entity * find_ent_here(entity *exclude, float x, float z, int types, int (*test)(entity*,entity*));
1782 void display_ents();
1783 void toss(entity *ent, float lift);
1784 entity * findent(int types);
1785 int count_ents(int types);
1786 int set_idle(entity* ent);
1787 int set_death(entity *iDie, int type, int reset);
1788 int set_fall(entity *iFall, int type, int reset, entity* other, int force, int drop, int noblock, int guardcost, int jugglecost, int pauseadd);
1789 int set_rise(entity *iRise, int type, int reset);
1790 int set_riseattack(entity *iRiseattack, int type, int reset);
1791 int set_blockpain(entity *iBlkpain, int type, int reset);
1792 int set_pain(entity *iPain, int type, int reset);
1793 void set_weapon(entity* ent, int wpnum, int anim_flag);
1794 entity* melee_find_target();
1795 entity* long_find_target();
1796 entity* normal_find_target(int anim, int iDetect);
1797 entity* normal_find_item();
1798 int long_attack();
1799 int melee_attack();
1800 void dothrow();
1801 void doprethrow();
1802 void dograbattack(int);
1803 int check_special();
1804 void normal_prepare();
1805 void common_jump();
1806 void common_spawn(void);
1807 void common_drop(void);
1808 void common_walkoff(void);
1809 void common_jumpattack();
1810 void common_turn();
1811 void common_fall();
1812 void common_lie();
1813 void common_rise();
1814 void common_pain();
1815 void common_vault();
1816 void common_get();
1817 void common_land();
1818 void common_grab(void);
1819 void common_grabattack();
1820 void common_grabbed();
1821 void common_block(void);
1822 int arrow_takedamage(entity *other, s_attack* attack);
1823 int common_takedamage(entity *other, s_attack* attack);
1824 int normal_attack();
1825 void common_throw(void);
1826 void common_throw_wait(void);
1827 void common_prethrow(void);
1828 void npc_warp();
1829 int checkpathblocked();
1830 int common_trymove(float xdir, float zdir);
1831 void normal_runoff();
1832 void common_stuck_underneath();
1833 void common_attack_proc();
1834 void normal_attack_finish();
1835 entity* common_find_target();
1836 int common_attack(void);
1837 int common_try_jump(void);
1838 int common_try_pick(entity* other);
1839 int common_try_chase(entity* target, int dox, int doz);
1840 int common_try_follow(entity* target, int dox, int doz);
1841 int common_try_avoid(entity* target, int dox, int doz);
1842 int common_try_wandercompletely(int dox, int doz);
1843 int common_try_wander(entity* target, int dox, int doz);
1844 void common_pickupitem(entity* other);
1845 int common_walk_anim(entity* ent);
1846 int common_idle_anim(entity* ent);
1847 int common_up_anim(entity* ent);
1848 int common_down_anim(entity* ent);
1849 int common_backwalk_anim(entity* ent);
1850 int bomb_move(void);
1851 int arrow_move(void);
1852 int common_move(void);
1853 void common_think(void);
1854 void suicide(void);
1855 void prethrow(void);
1856 void player_die();
1857 int player_trymove(float xdir, float zdir);
1858 int check_energy(int which, int ani);
1859 int player_preinput();
1860 int player_check_special();
1861 void runanimal(void);
1862 void player_blink(void);
1863 int check_combo();
1864 int check_costmove(int s, int fs, int jumphack);
1865 void didfind_item(entity *other);
1866 void player_think(void);
1867 void subtract_shot();
1868 void dropweapon(int flag);
1869 void drop_all_enemies();
1870 void kill_all_enemies();
1871 void smart_bomb(entity* e, s_attack* attack);
1872 void anything_walk(void);
1873 entity * knife_spawn(char *name, int index, float x, float z, float a, int direction, int type, int map);
1874 entity * bomb_spawn(char *name, int index, float x, float z, float a, int direction, int map);
1875 void bomb_explode(void);
1876 int star_spawn(float x, float z, float a, int direction);
1877 void steam_think(void);
1878 void trap_think(void);
1879 void steam_spawn(float x, float z, float a);
1880 void steamer_think(void);
1881 void text_think(void);
1882 entity * homing_find_target(int type);
1883 void biker_drive(void);
1884 void bike_crash(void);
1885 void obstacle_fall(void);
1886 void obstacle_fly(void);
1887 entity * smartspawn(s_spawn_entry * props);
1888 void spawnplayer(int index);
1889 void time_over();
1890 void update_scroller();
1891 void draw_scrolled_bg();
1892 void update(int ingame, int usevwait);
1893 void fade_out(int type, int speed);
1894 void apply_controls();
1895 void plan();
1896 int ai_check_warp();
1897 int ai_check_lie();
1898 int ai_check_grabbed();
1899 int ai_check_grab();
1900 int ai_check_escape();
1901 int ai_check_busy();
1902 #ifndef PSP
1903 void display_credits(void);
1904 #endif
1905 void shutdown(int status, char *msg, ...);
1906 #ifndef PSP
1907 void guistartup(void);
1908 #endif
1909 void startup(void);
1910 int playgif(char *filename, int x, int y, int noskip);
1911 void playscene(char *filename);
1912 void gameover();
1913 void hallfame(int addtoscore);
1914 void showcomplete(int num);
1915 int playlevel(char *filename);
1916 int selectplayer(int *players, char* filename);
1917 void playgame(int *players,  unsigned which_set, int useSavedGame);
1918 int choose_difficulty();
1919 int load_saved_game();
1920 void term_videomodes();
1921 void init_videomodes(int log);
1922 void safe_set(int *arr, int index, int newkey, int oldkey);
1923 void keyboard_setup(int player);
1924 void input_options();
1925 void inputrefresh();
1926 void soundvol_options();
1927 void config_options();
1928 void cheatoptions();
1929 void system_options();
1930 void video_options();
1931 void options();
1932 void soundcard_options();
1933 void openborMain(int argc, char** argv);
1934 int getValidInt(char* text, char* file, char* cmd);
1935 float getValidFloat(char* text, char* file, char* cmd);
1936 
1937 
1938 s_savelevel* savelevel;
1939 s_savescore savescore;
1940 s_savedata savedata;
1941 
1942 #endif
1943