1 /*
2 Copyright (C) 1994-1995 Apogee Software, Ltd.
3 
4 This program is free software; you can redistribute it and/or
5 modify it under the terms of the GNU General Public License
6 as published by the Free Software Foundation; either version 2
7 of the License, or (at your option) any later version.
8 
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
12 
13 See the GNU General Public License for more details.
14 
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
18 
19 */
20 #ifndef _rt_actor_public
21 #define _rt_actor_public
22 
23 //***************************************************************************
24 //
25 //                            RT_ACTOR.C (actor functions)
26 //
27 //***************************************************************************
28 
29 #include "states.h"
30 
31 
32 #define FL_SYNCED          0x400
33 #define FL_MASTER          0x800
34 #define FL_SKELETON        0x02
35 #define GASTICS            1050
36 
37 
38 #define M_ISACTOR(x)     ((x!=NULL) && (x->which == ACTOR))
39 
40 #define SF_GUTS          0x20
41 
42 #define NUMENEMIES       16
43 #define NUMCLASSES       51
44 #define MAXTOUCH         10
45 #define MAXPOP           32
46 #define MAXDELETE        512
47 
48 #define InMapBounds(x,y) (((x) >= 0) && ((x) < MAPSIZE) && ((y) >= 0) && ((y) < MAPSIZE))
49 
50 
51 #define ACTIVE(ob)       ((ob == firstactive) || (ob->prevactive) || (ob->nextactive))
52 
53 enum {SHOOT,SIGHT,DIRCHECK,EXPLOSION,MISSILE};
54 
55 
56 typedef enum
57    {
58    gt_sparks,
59    gt_organ,
60    gt_rib,
61    gt_pinkorgan,
62    gt_head,
63    gt_arm,
64    gt_leg,
65    gt_humerus,
66    gt_pelvis,
67    gt_limb,
68    gt_bsoul,
69    gt_lsoul,
70    gt_spit,
71    NumGibTypes
72    }gib_t;
73 
74 #define GUTS         (NumGibTypes)
75 #define RANDOM       (NumGibTypes + 1)
76 #define DISEMBOWEL   (NumGibTypes + 2)
77 
78 
79 #define GASVALUE               192
80 
81 #define PAINOFFSET             2
82 #define PMFOFFSET              50
83 #define REMOTEOFFSET           86
84 
85 #define ACTORSIZE              0x5800
86 #define PWALLRAD               0xa000
87 
88 #ifdef __WATCOMC__
89 int M_ABS(int value);
90 #pragma aux M_ABS =  \
91 		  "test eax,eax",                     \
92 		  "jge done", \
93 		  "neg eax",\
94 		  "done: "         \
95 		  parm    [eax] \
96 		  value   [eax]           \
97 		  modify exact [eax]
98 #else
99 #define M_ABS abs
100 #endif
101 
102 #define M_CheckPlayerKilled(ob) \
103 { if ((ob->obclass == playerobj) && (ob->flags & FL_DYING)) \
104 	 BATTLE_CheckGameStatus(battle_player_killed,ob->dirchoosetime);\
105 }
106 
107 
108 
109 #define SetTilePosition(ob, newtilex, newtiley)    \
110   {                                                \
111   ob->tilex = newtilex;                            \
112   ob->tiley = newtiley;                            \
113   ob->x = (ob->tilex << TILESHIFT) + TILEGLOBAL/2; \
114   ob->y = (ob->tiley << TILESHIFT) + TILEGLOBAL/2; \
115   }
116 
117 
118 #define SetFinePosition(ob, newx, newy)            \
119   {                                                \
120   ob->x = newx;                                    \
121   ob->y = newy;                                    \
122   ob->tilex = (ob->x >> TILESHIFT);                \
123   ob->tiley = (ob->y >> TILESHIFT);                \
124   }
125 
126 #define SetVisiblePosition(ob, x, y)               \
127   {                                                \
128   ob->drawx = x;                                   \
129   ob->drawy = y;                                   \
130   }
131 
132 
133 //***************************************************************************
134 //
135 //    WeaponDamages
136 //
137 //***************************************************************************
138 #define DMG_PISTOL    13
139 #define DMG_MP40      10
140 #define DMG_AHGUN     10
141 #define DMG_ENEMYBULLETWEAPON     10
142 
143 
144 
145 
146 typedef struct bas
147  {
148   short operate,
149         see,
150         fire,
151         hit,
152         die;
153  } basic_actor_sounds;
154 
155 extern basic_actor_sounds  BAS[NUMCLASSES+3];
156 
157 
158 typedef struct
159  {int x,y;
160  }_2Dpoint;
161 
162 typedef enum {
163 		  inertobj,
164 		  playerobj,
165 		  lowguardobj,
166 		  highguardobj,
167 		  overpatrolobj,
168 		  strikeguardobj,
169 		  blitzguardobj,
170 		  triadenforcerobj,
171 		  deathmonkobj,
172 		  dfiremonkobj,
173 		  roboguardobj,
174 
175 		  b_darianobj,
176 		  b_heinrichobj,
177 		  b_robobossobj,
178 		  b_darkmonkobj,
179 		  b_darksnakeobj,
180 		  patrolgunobj,
181 		  wallopobj,
182 
183 
184 		  //specials
185 
186 		  pillarobj,
187 		  firejetobj,
188 		  bladeobj,
189 		  crushcolobj,
190 		  boulderobj,
191 		  spearobj,
192 		  gasgrateobj,
193 		  springobj,
194 
195 		  // Missile weapon types
196 
197 		  shurikenobj,
198 		  wallfireobj,
199 		  netobj,
200 		  h_mineobj,
201 		  grenadeobj,
202 		  fireballobj,
203 		  dmfballobj,
204 		  bigshurikenobj,
205 		  missileobj,
206 		  NMEsaucerobj,
207 		  dm_weaponobj,
208 		  dm_heatseekobj,
209 		  dm_spitobj,
210 		  p_bazookaobj,
211 		  p_firebombobj,
212 		  p_heatseekobj,
213 		  p_drunkmissileobj,
214 		  p_firewallobj,
215 		  p_splitmissileobj,
216 		  p_kesobj,
217 		  p_godballobj,
218 		  collectorobj,
219         diskobj,
220         rainobj
221 
222 
223 		  }classtype;
224 
225 
226 typedef struct objstruct
227 {
228 		  thingtype                     which;
229 		  byte                     tilex,tiley;
230 		  fixed                    x,y,z;
231         int                      shapenum;
232 		  unsigned                 flags;
233 		  short                    ticcount;
234 		  signed short             hitpoints;
235 		  word                     whichactor;
236 
237 		  signed short             dirchoosetime;
238 		  fixed                    drawx,drawy;
239 		  classtype                obclass;
240 		  statetype *              state;
241 		  signed char              door_to_open;
242 		  byte                     areanumber;
243 		  signed short             shapeoffset;
244 		  int                      targettilex,targettiley;
245 
246 
247 		  dirtype                  dir;
248 		  short int                angle;
249 		  short int                yzangle;
250 
251 		  int                      soundhandle;
252 		  int                      speed;
253 		  int                      momentumx, momentumy, momentumz;
254 		  int                      temp1,temp2,temp3;
255 		  void                     *whatever,*target;
256 		  struct objstruct         *next, *prev;
257 		  struct objstruct         *nextactive, *prevactive;
258 		  struct objstruct         *nextinarea, *previnarea;
259 
260 } objtype;
261 
262 
263 
264 
265 typedef struct b_struct
266  {int   NMErotate;
267   int   NMEdirstried;
268   int   NMEqueuesize;
269   int   ESAU_HIDING,ESAU_SHOOTING;
270   int   HRAMMING, HMINING;
271   int   SOUNDTIME;
272   int   redindex,REDTIME;
273   int   monkz;
274   int   monkup;
275   int   firespawned;
276   int   notouch,noholes;
277   int   nexttouch,nextpop;
278   int   popsleft;
279   int   DSTATE;
280   int   doorcount;
281   int   KEYACTORSLEFT;
282   int      GASON;
283   int      gasindex;
284   boolean  NET_IN_FLIGHT;
285   boolean  madenoise;
286   _2Dpoint ETOUCH[MAXTOUCH],EPOP[MAXPOP],TOMLOC;
287   int   NUMWEAPONS;
288   int   BulletHoleNum;
289   int   NUMBEGGINGKEVINS;
290   boolean fulllightgibs;
291   boolean directgibs;
292   int     gibgravity;
293   int     gibspeed;
294   boolean supergibflag;
295   boolean randgibspeed;
296   int     numgibs;
297   boolean elevatormusicon;
298  }misc_stuff;
299 
300 
301 extern  boolean          ludicrousgibs;
302 extern  objtype*         PLAYER0MISSILE;
303 extern  byte             deathshapeoffset[8];
304 extern  byte             RANDOMACTORTYPE[10];
305 extern  objtype*         FIRSTACTOR,*LASTACTOR;
306 extern  objtype          *FIRSTRAIN,*LASTRAIN;
307 extern  objtype*         SCREENEYE;
308 extern  objtype          *firstareaactor[NUMAREAS+1],*lastareaactor[NUMAREAS+1];
309 extern  misc_stuff       mstruct,*MISCVARS;
310 extern  int              actorstart,actorstop;
311 extern  exit_t           playstate;
312 extern  objtype          *lastactive,*firstactive;
313 extern  objtype          *new,**objlist,
314 								 *killerobj;
315 extern  void             *actorat[MAPSIZE][MAPSIZE];
316 extern  int              angletodir[ANGLES];
317 extern _2Dpoint          SNAKEPATH[512];
318 extern  int              STOPSPEED;
319 extern  int              FRICTION;
320 
321 extern  int              objcount;
322 
323 void     SpawnInertActor(int,int,int);
324 objtype* DiskAt(int tilex,int tiley);
325 void     GetRainActors(void);
326 void     DoRain(void);
327 void     SpawnDisk(int,int,int,boolean);
328 void     T_ElevDisk(objtype*);
329 void     Add_To_Delete_Array(void*);
330 void     Remove_Delete_Array_Entries(void);
331 void     MakeInactive(objtype*ob);
332 void     RespawnEluder(void);
333 void     SpawnCollector(int,int);
334 void     MakeLastInArea(objtype*);
335 void     RemoveFromArea(objtype*);
336 void     GetMomenta(objtype*,objtype*,int*,int*,int*,int);
337 int      AngleBetween(objtype*,objtype*);
338 void     TurnActorIntoSprite(objtype*);
339 void     ResolveDoorSpace(int,int);
340 void     RemoveObj(objtype*);
341 void     SpawnParticles(objtype*,int,int);
342 void     MakeActive(objtype*);
343 void     SpawnSpear(int,int,int);
344 void     SpawnBoulder(int,int,int);
345 void     SpawnCrushingColumn(int,int,int);
346 void     SpawnFirejet(int,int,int,int);
347 void     T_Firethink(objtype*);
348 void     SpawnBlade(int,int,int,int,int);
349 void     T_OrobotChase(objtype*);
350 void     SpawnMultiSpriteActor(classtype,int,int,int);
351 boolean  ActorTryMove(objtype*,int,int,int);
352 void     A_Repeat(objtype*);
353 void     T_Heinrich_Defend(objtype*);
354 void     T_Heinrich_Out_of_Control(objtype*);
355 void     A_HeinrichShoot(objtype*);
356 void     T_EsauWait(objtype*);
357 void     T_EsauRise(objtype*);
358 void     A_Drain(objtype*ob);
359 void     T_Explosion(objtype*ob);
360 void     T_MoveColumn(objtype*);
361 void     EnableObject(int object);
362 void     DisableObject(int);
363 
364 void     T_Collide(objtype*);
365 void  Collision(objtype*ob,objtype *attacker,int hitmomentumx,int hitmomentumy);
366 void     ActorMovement (objtype *);
367 void     MoveActor(objtype*);
368 
369 void     InitActorList(void);
370 void     NewState(objtype*,statetype*);
371 void     DoActor(objtype*);
372 
373 void     SpawnPushColumn(int tilex,int tiley,int which,int dir, int linked);
374 void     SpawnGunThingy(classtype which, int tilex, int tiley, int dir);
375 void     SpawnStand (classtype which, int tilex, int tiley, int dir, int ambush);
376 void     SpawnPatrol (classtype which, int tilex, int tiley, int dir);
377 void     SpawnDeadGuard (int tilex, int tiley);
378 void     SpawnWallfire(int tilex, int tiley, int dir);
379 void     SpawnMissile(objtype*,classtype,int,int,statetype*,int);
380 
381 void     InitHitRect (objtype *ob, unsigned radius);
382 void     NewState (objtype *ob, statetype *state);
383 void     SelectPathDir(objtype*);
384 void     SelectChaseDir (objtype *ob);
385 boolean  SightPlayer (objtype *ob);
386 boolean  CheckLine (void*,void *,int);
387 boolean  CheckSight (objtype *ob,void*);
388 void     KillActor (objtype *ob);
389 void     DamageThing (void *, int);
390 void     MissileHit (objtype *,void*);
391 void     GetNewActor(void);
392 
393 void     T_WallPath(objtype*);
394 void     T_Path (objtype *ob);   //done
395 void     T_RoboChase(objtype*ob);
396 void     T_RoboPath(objtype*ob);
397 void     T_Chase (objtype *ob);      //done
398 void     T_EsauChase(objtype*ob); //done
399 void     T_Spears(objtype*);
400 void     T_Projectile (objtype *ob); //done
401 void     T_Stand (objtype *ob);      //done
402 void     T_GunStand(objtype *ob); //done
403 void     T_Use(objtype *ob);         // done
404 void     A_Shoot (objtype *ob);        // done
405 void     A_MissileWeapon(objtype*);    // done
406 void     A_Wallfire(objtype*);
407 
408 void     A_Steal(objtype*);
409 
410 void     T_Roll(objtype*);
411 void     T_BossDied (objtype *ob);
412 boolean  QuickSpaceCheck(objtype*,int,int);
413 void     PushWallMove(int num);
414 void     SpawnNewObj(unsigned,unsigned,statetype*,classtype);
415 void     SpawnSpring(int,int);
416 void     SpawnFourWayGun(int,int);
417 void     SpawnSnake(int tilex,int tiley);
418 void     SpawnSneaky(int,int);
419 boolean  MissileTryMove(objtype*ob,int,int,int);
420 
421 void     SaveActors(byte ** buf, int * size);
422 void     LoadActors(byte * buf, int size);
423 
424 boolean  TurnOffLight0 (int tilex, int tiley);
425 boolean  TurnOffLight1 (int tilex, int tiley, int i, int j);
426 boolean  TurnOffLight2 (int tilex, int tiley, int j);
427 boolean  TurnOffLight3 (int tilex, int tiley, int i);
428 
429 void     ParseMomentum(objtype *ob,int angle);
430 void     SpawnGroundExplosion(int x, int y, int z);
431 void     RayShoot (objtype * shooter, int damage, int accuracy);
432 void FindEmptyTile(int *stilex, int *stiley);
433 void T_Wind( objtype *ob );
434 void StopWind( void );
435 
436 #endif
437