1 //-------------------------------------------------------------------------
2 /*
3 Copyright (C) 1997, 2005 - 3D Realms Entertainment
4 
5 This file is part of Shadow Warrior version 1.2
6 
7 Shadow Warrior is free software; you can redistribute it and/or
8 modify it under the terms of the GNU General Public License
9 as published by the Free Software Foundation; either version 2
10 of the License, or (at your option) any later version.
11 
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
15 
16 See the GNU General Public License for more details.
17 
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
21 
22 Original Source: 1997 - Frank Maddin and Jim Norwood
23 Prepared for public release: 03/28/2005 - Charlie Wiederhold, 3D Realms
24 */
25 //-------------------------------------------------------------------------
26 #include "build.h"
27 
28 #include "keys.h"
29 #include "names2.h"
30 #include "game.h"
31 #include "tags.h"
32 #include "ai.h"
33 #include "actor.h"
34 #include "track.h"
35 
36 DECISION SkelBattle[] =
37     {
38     {600,   InitActorMoveCloser         },
39     {602,   InitActorAlertNoise         },
40     {700,   InitActorRunAway            },
41     {1024,  InitActorAttack             }
42     };
43 
44 DECISION SkelOffense[] =
45     {
46     {700,   InitActorMoveCloser         },
47     {702,   InitActorAlertNoise         },
48     {1024,  InitActorAttack             }
49     };
50 
51 DECISION SkelBroadcast[] =
52     {
53     {3,    InitActorAlertNoise        },
54     {6,    InitActorAmbientNoise      },
55     {1024,  InitActorDecide            }
56     };
57 
58 DECISION SkelSurprised[] =
59     {
60     {701,   InitActorMoveCloser         },
61     {1024,  InitActorDecide            }
62     };
63 
64 DECISION SkelEvasive[] =
65     {
66     {22,     InitActorDuck             },
67     {30,     InitActorEvade            },
68     {1024,   NULL                      },
69     };
70 
71 DECISION SkelLostTarget[] =
72     {
73     {900,   InitActorFindPlayer         },
74     {1024,  InitActorWanderAround       }
75     };
76 
77 DECISION SkelCloseRange[] =
78     {
79     {800,   InitActorAttack             },
80     {1024,  InitActorReposition            }
81     };
82 
83 PERSONALITY SkelPersonality =
84     {
85     SkelBattle,
86     SkelOffense,
87     SkelBroadcast,
88     SkelSurprised,
89     SkelEvasive,
90     SkelLostTarget,
91     SkelCloseRange,
92     SkelCloseRange
93     };
94 
95 ATTRIBUTE SkelAttrib =
96     {
97     {60, 80, 100, 130},                 // Speeds
98     {3, 0, -2, -3},                     // Tic Adjusts
99      3,                                 // MaxWeapons;
100     {DIGI_SPAMBIENT, DIGI_SPALERT, 0,
101      DIGI_SPPAIN, DIGI_SPSCREAM, DIGI_SPBLADE,
102      DIGI_SPELEC,DIGI_SPTELEPORT,0,0}
103     };
104 
105 //////////////////////
106 //
107 // SKEL RUN
108 //
109 //////////////////////
110 
111 #define SKEL_RUN_RATE 12
112 
113 ANIMATOR DoSkelMove,NullSkel,DoActorDebris,NullSkel,DoSuicide,InitSkelSpell;
114 
115 // +4 on frame #3 to add character
116 
117 STATE s_SkelRun[5][6] =
118     {
119     {
120     {SKEL_RUN_R0 + 0, SKEL_RUN_RATE+4, DoSkelMove, &s_SkelRun[0][1]},
121     {SKEL_RUN_R0 + 1, SKEL_RUN_RATE, DoSkelMove, &s_SkelRun[0][2]},
122     {SKEL_RUN_R0 + 2, SKEL_RUN_RATE, DoSkelMove, &s_SkelRun[0][3]},
123     {SKEL_RUN_R0 + 3, SKEL_RUN_RATE+4, DoSkelMove, &s_SkelRun[0][4]},
124     {SKEL_RUN_R0 + 4, SKEL_RUN_RATE, DoSkelMove, &s_SkelRun[0][5]},
125     {SKEL_RUN_R0 + 5, SKEL_RUN_RATE, DoSkelMove, &s_SkelRun[0][0]},
126     },
127     {
128     {SKEL_RUN_R1 + 0, SKEL_RUN_RATE+4, DoSkelMove, &s_SkelRun[1][1]},
129     {SKEL_RUN_R1 + 1, SKEL_RUN_RATE, DoSkelMove, &s_SkelRun[1][2]},
130     {SKEL_RUN_R1 + 2, SKEL_RUN_RATE, DoSkelMove, &s_SkelRun[1][3]},
131     {SKEL_RUN_R1 + 3, SKEL_RUN_RATE+4, DoSkelMove, &s_SkelRun[1][4]},
132     {SKEL_RUN_R1 + 4, SKEL_RUN_RATE, DoSkelMove, &s_SkelRun[1][5]},
133     {SKEL_RUN_R1 + 5, SKEL_RUN_RATE, DoSkelMove, &s_SkelRun[1][0]},
134     },
135     {
136     {SKEL_RUN_R2 + 0, SKEL_RUN_RATE+4, DoSkelMove, &s_SkelRun[2][1]},
137     {SKEL_RUN_R2 + 1, SKEL_RUN_RATE, DoSkelMove, &s_SkelRun[2][2]},
138     {SKEL_RUN_R2 + 2, SKEL_RUN_RATE, DoSkelMove, &s_SkelRun[2][3]},
139     {SKEL_RUN_R2 + 3, SKEL_RUN_RATE+4, DoSkelMove, &s_SkelRun[2][4]},
140     {SKEL_RUN_R2 + 4, SKEL_RUN_RATE, DoSkelMove, &s_SkelRun[2][5]},
141     {SKEL_RUN_R2 + 5, SKEL_RUN_RATE, DoSkelMove, &s_SkelRun[2][0]},
142     },
143     {
144     {SKEL_RUN_R3 + 0, SKEL_RUN_RATE+4, DoSkelMove, &s_SkelRun[3][1]},
145     {SKEL_RUN_R3 + 1, SKEL_RUN_RATE, DoSkelMove, &s_SkelRun[3][2]},
146     {SKEL_RUN_R3 + 2, SKEL_RUN_RATE, DoSkelMove, &s_SkelRun[3][3]},
147     {SKEL_RUN_R3 + 3, SKEL_RUN_RATE+4, DoSkelMove, &s_SkelRun[3][4]},
148     {SKEL_RUN_R3 + 4, SKEL_RUN_RATE, DoSkelMove, &s_SkelRun[3][5]},
149     {SKEL_RUN_R3 + 5, SKEL_RUN_RATE, DoSkelMove, &s_SkelRun[3][0]},
150     },
151     {
152     {SKEL_RUN_R4 + 0, SKEL_RUN_RATE+4, DoSkelMove, &s_SkelRun[4][1]},
153     {SKEL_RUN_R4 + 1, SKEL_RUN_RATE, DoSkelMove, &s_SkelRun[4][2]},
154     {SKEL_RUN_R4 + 2, SKEL_RUN_RATE, DoSkelMove, &s_SkelRun[4][3]},
155     {SKEL_RUN_R4 + 3, SKEL_RUN_RATE+4, DoSkelMove, &s_SkelRun[4][4]},
156     {SKEL_RUN_R4 + 4, SKEL_RUN_RATE, DoSkelMove, &s_SkelRun[4][5]},
157     {SKEL_RUN_R4 + 5, SKEL_RUN_RATE, DoSkelMove, &s_SkelRun[4][0]},
158     }
159     };
160 
161 
162 STATEp sg_SkelRun[] =
163     {
164     &s_SkelRun[0][0],
165     &s_SkelRun[1][0],
166     &s_SkelRun[2][0],
167     &s_SkelRun[3][0],
168     &s_SkelRun[4][0]
169     };
170 
171 //////////////////////
172 //
173 // SKEL SLASH
174 //
175 //////////////////////
176 
177 #define SKEL_SLASH_RATE 20
178 ANIMATOR InitActorDecide;
179 ANIMATOR InitSkelSlash;
180 
181 STATE s_SkelSlash[5][7] =
182     {
183     {
184     {SKEL_SLASH_R0 + 0, SKEL_SLASH_RATE, NullSkel, &s_SkelSlash[0][1]},
185     {SKEL_SLASH_R0 + 1, SKEL_SLASH_RATE, NullSkel, &s_SkelSlash[0][2]},
186     {SKEL_SLASH_R0 + 2, 0|SF_QUICK_CALL, InitSkelSlash, &s_SkelSlash[0][3]},
187     {SKEL_SLASH_R0 + 2, SKEL_SLASH_RATE*2, NullSkel, &s_SkelSlash[0][4]},
188     {SKEL_SLASH_R0 + 1, SKEL_SLASH_RATE, NullSkel, &s_SkelSlash[0][5]},
189     {SKEL_SLASH_R0 + 1, 0|SF_QUICK_CALL, InitActorDecide, &s_SkelSlash[0][6]},
190     {SKEL_SLASH_R0 + 1, SKEL_SLASH_RATE, DoSkelMove, &s_SkelSlash[0][6]},
191     },
192     {
193     {SKEL_SLASH_R1 + 0, SKEL_SLASH_RATE, NullSkel, &s_SkelSlash[1][1]},
194     {SKEL_SLASH_R1 + 1, SKEL_SLASH_RATE, NullSkel, &s_SkelSlash[1][2]},
195     {SKEL_SLASH_R1 + 2, 0|SF_QUICK_CALL, InitSkelSlash, &s_SkelSlash[1][3]},
196     {SKEL_SLASH_R1 + 2, SKEL_SLASH_RATE*2, NullSkel, &s_SkelSlash[1][4]},
197     {SKEL_SLASH_R1 + 1, SKEL_SLASH_RATE, NullSkel, &s_SkelSlash[1][5]},
198     {SKEL_SLASH_R1 + 1, 0|SF_QUICK_CALL, InitActorDecide, &s_SkelSlash[1][6]},
199     {SKEL_SLASH_R1 + 1, SKEL_SLASH_RATE, DoSkelMove, &s_SkelSlash[1][6]},
200     },
201     {
202     {SKEL_SLASH_R2 + 0, SKEL_SLASH_RATE, NullSkel, &s_SkelSlash[2][1]},
203     {SKEL_SLASH_R2 + 1, SKEL_SLASH_RATE, NullSkel, &s_SkelSlash[2][2]},
204     {SKEL_SLASH_R2 + 2, 0|SF_QUICK_CALL, InitSkelSlash, &s_SkelSlash[2][3]},
205     {SKEL_SLASH_R2 + 2, SKEL_SLASH_RATE*2, NullSkel, &s_SkelSlash[2][4]},
206     {SKEL_SLASH_R2 + 1, SKEL_SLASH_RATE, NullSkel, &s_SkelSlash[2][5]},
207     {SKEL_SLASH_R2 + 1, 0|SF_QUICK_CALL, InitActorDecide, &s_SkelSlash[2][6]},
208     {SKEL_SLASH_R2 + 1, SKEL_SLASH_RATE, DoSkelMove, &s_SkelSlash[2][6]},
209     },
210     {
211     {SKEL_SLASH_R3 + 0, SKEL_SLASH_RATE, NullSkel, &s_SkelSlash[3][1]},
212     {SKEL_SLASH_R3 + 1, SKEL_SLASH_RATE, NullSkel, &s_SkelSlash[3][2]},
213     {SKEL_SLASH_R3 + 2, 0|SF_QUICK_CALL, InitSkelSlash, &s_SkelSlash[3][3]},
214     {SKEL_SLASH_R3 + 2, SKEL_SLASH_RATE*2, NullSkel, &s_SkelSlash[3][4]},
215     {SKEL_SLASH_R3 + 1, SKEL_SLASH_RATE, NullSkel, &s_SkelSlash[3][5]},
216     {SKEL_SLASH_R3 + 1, 0|SF_QUICK_CALL, InitActorDecide, &s_SkelSlash[3][6]},
217     {SKEL_SLASH_R3 + 1, SKEL_SLASH_RATE, DoSkelMove, &s_SkelSlash[3][6]},
218     },
219     {
220     {SKEL_SLASH_R4 + 0, SKEL_SLASH_RATE, NullSkel, &s_SkelSlash[4][1]},
221     {SKEL_SLASH_R4 + 1, SKEL_SLASH_RATE, NullSkel, &s_SkelSlash[4][2]},
222     {SKEL_SLASH_R4 + 2, 0|SF_QUICK_CALL, InitSkelSlash, &s_SkelSlash[4][3]},
223     {SKEL_SLASH_R4 + 2, SKEL_SLASH_RATE*2, NullSkel, &s_SkelSlash[4][4]},
224     {SKEL_SLASH_R4 + 1, SKEL_SLASH_RATE, NullSkel, &s_SkelSlash[4][5]},
225     {SKEL_SLASH_R4 + 1, 0|SF_QUICK_CALL, InitActorDecide, &s_SkelSlash[4][6]},
226     {SKEL_SLASH_R4 + 1, SKEL_SLASH_RATE, DoSkelMove, &s_SkelSlash[4][6]},
227     }
228     };
229 
230 
231 STATEp sg_SkelSlash[] =
232     {
233     &s_SkelSlash[0][0],
234     &s_SkelSlash[1][0],
235     &s_SkelSlash[2][0],
236     &s_SkelSlash[3][0],
237     &s_SkelSlash[4][0]
238     };
239 
240 
241 //////////////////////
242 //
243 // SKEL SPELL
244 //
245 //////////////////////
246 
247 #define SKEL_SPELL_RATE 20
248 
249 STATE s_SkelSpell[5][7] =
250     {
251     {
252     {SKEL_SPELL_R0 + 0, SKEL_SPELL_RATE+9, NullSkel, &s_SkelSpell[0][1]},
253     {SKEL_SPELL_R0 + 1, SKEL_SPELL_RATE, NullSkel, &s_SkelSpell[0][2]},
254     {SKEL_SPELL_R0 + 2, SKEL_SPELL_RATE, NullSkel, &s_SkelSpell[0][3]},
255     {SKEL_SPELL_R0 + 3, SKEL_SPELL_RATE*2, NullSkel, &s_SkelSpell[0][4]},
256     {SKEL_SPELL_R0 + 3, 0|SF_QUICK_CALL, InitSkelSpell, &s_SkelSpell[0][5]},
257     {SKEL_SPELL_R0 + 3, 0|SF_QUICK_CALL, InitActorDecide, &s_SkelSpell[0][6]},
258     {SKEL_SPELL_R0 + 3, SKEL_SPELL_RATE, DoSkelMove, &s_SkelSpell[0][6]},
259     },
260     {
261     {SKEL_SPELL_R1 + 0, SKEL_SPELL_RATE+9, NullSkel, &s_SkelSpell[1][1]},
262     {SKEL_SPELL_R1 + 1, SKEL_SPELL_RATE, NullSkel, &s_SkelSpell[1][2]},
263     {SKEL_SPELL_R1 + 2, SKEL_SPELL_RATE, NullSkel, &s_SkelSpell[1][3]},
264     {SKEL_SPELL_R1 + 3, SKEL_SPELL_RATE*2, NullSkel, &s_SkelSpell[1][4]},
265     {SKEL_SPELL_R1 + 3, 0|SF_QUICK_CALL, InitSkelSpell, &s_SkelSpell[1][5]},
266     {SKEL_SPELL_R1 + 3, 0|SF_QUICK_CALL, InitActorDecide, &s_SkelSpell[1][6]},
267     {SKEL_SPELL_R1 + 3, SKEL_SPELL_RATE, DoSkelMove, &s_SkelSpell[1][6]},
268     },
269     {
270     {SKEL_SPELL_R2 + 0, SKEL_SPELL_RATE+9, NullSkel, &s_SkelSpell[2][1]},
271     {SKEL_SPELL_R2 + 1, SKEL_SPELL_RATE, NullSkel, &s_SkelSpell[2][2]},
272     {SKEL_SPELL_R2 + 2, SKEL_SPELL_RATE, NullSkel, &s_SkelSpell[2][3]},
273     {SKEL_SPELL_R2 + 3, SKEL_SPELL_RATE*2, NullSkel, &s_SkelSpell[2][4]},
274     {SKEL_SPELL_R2 + 3, 0|SF_QUICK_CALL, InitSkelSpell, &s_SkelSpell[2][5]},
275     {SKEL_SPELL_R2 + 3, 0|SF_QUICK_CALL, InitActorDecide, &s_SkelSpell[2][6]},
276     {SKEL_SPELL_R2 + 3, SKEL_SPELL_RATE, DoSkelMove, &s_SkelSpell[2][6]},
277     },
278     {
279     {SKEL_SPELL_R3 + 0, SKEL_SPELL_RATE+9, NullSkel, &s_SkelSpell[3][1]},
280     {SKEL_SPELL_R3 + 1, SKEL_SPELL_RATE, NullSkel, &s_SkelSpell[3][2]},
281     {SKEL_SPELL_R3 + 2, SKEL_SPELL_RATE, NullSkel, &s_SkelSpell[3][3]},
282     {SKEL_SPELL_R3 + 3, SKEL_SPELL_RATE*2, NullSkel, &s_SkelSpell[3][4]},
283     {SKEL_SPELL_R3 + 3, 0|SF_QUICK_CALL, InitSkelSpell, &s_SkelSpell[3][5]},
284     {SKEL_SPELL_R3 + 3, 0|SF_QUICK_CALL, InitActorDecide, &s_SkelSpell[3][6]},
285     {SKEL_SPELL_R3 + 3, SKEL_SPELL_RATE, DoSkelMove, &s_SkelSpell[3][6]},
286     },
287     {
288     {SKEL_SPELL_R4 + 0, SKEL_SPELL_RATE+9, NullSkel, &s_SkelSpell[4][1]},
289     {SKEL_SPELL_R4 + 1, SKEL_SPELL_RATE, NullSkel, &s_SkelSpell[4][2]},
290     {SKEL_SPELL_R4 + 2, SKEL_SPELL_RATE, NullSkel, &s_SkelSpell[4][3]},
291     {SKEL_SPELL_R4 + 3, SKEL_SPELL_RATE*2, NullSkel, &s_SkelSpell[4][4]},
292     {SKEL_SPELL_R4 + 3, 0|SF_QUICK_CALL, InitSkelSpell, &s_SkelSpell[4][5]},
293     {SKEL_SPELL_R4 + 3, 0|SF_QUICK_CALL, InitActorDecide, &s_SkelSpell[4][6]},
294     {SKEL_SPELL_R4 + 3, SKEL_SPELL_RATE, DoSkelMove, &s_SkelSpell[4][6]},
295     }
296     };
297 
298 
299 STATEp sg_SkelSpell[] =
300     {
301     &s_SkelSpell[0][0],
302     &s_SkelSpell[1][0],
303     &s_SkelSpell[2][0],
304     &s_SkelSpell[3][0],
305     &s_SkelSpell[4][0]
306     };
307 
308 //////////////////////
309 //
310 // SKEL PAIN
311 //
312 //////////////////////
313 
314 #define SKEL_PAIN_RATE 38
315 ANIMATOR DoSkelPain;
316 
317 STATE s_SkelPain[5][1] =
318     {
319     {
320     {SKEL_PAIN_R0 + 0, SKEL_PAIN_RATE, DoSkelPain, &s_SkelPain[0][0]},
321     },
322     {
323     {SKEL_PAIN_R1 + 0, SKEL_PAIN_RATE, DoSkelPain, &s_SkelPain[1][0]},
324     },
325     {
326     {SKEL_PAIN_R2 + 0, SKEL_PAIN_RATE, DoSkelPain, &s_SkelPain[2][0]},
327     },
328     {
329     {SKEL_PAIN_R3 + 0, SKEL_PAIN_RATE, DoSkelPain, &s_SkelPain[3][0]},
330     },
331     {
332     {SKEL_PAIN_R4 + 0, SKEL_PAIN_RATE, DoSkelPain, &s_SkelPain[4][0]},
333     }
334     };
335 
336 STATEp sg_SkelPain[] =
337     {
338     &s_SkelPain[0][0],
339     &s_SkelPain[1][0],
340     &s_SkelPain[2][0],
341     &s_SkelPain[3][0],
342     &s_SkelPain[4][0]
343     };
344 
345 
346 
347 //////////////////////
348 //
349 // SKEL TELEPORT
350 //
351 //////////////////////
352 
353 ANIMATOR DoSkelInitTeleport, DoSkelTeleport, DoSkelTermTeleport;
354 
355 #define SKEL_TELEPORT_RATE 20
356 
357 STATE s_SkelTeleport[] =
358     {
359     {SKEL_TELEPORT + 0,  1,                  NullAnimator, &s_SkelTeleport[1]},
360     {SKEL_TELEPORT + 0,  0|SF_QUICK_CALL,    DoSkelInitTeleport, &s_SkelTeleport[2]},
361     {SKEL_TELEPORT + 0,  SKEL_TELEPORT_RATE, NullAnimator, &s_SkelTeleport[3]},
362     {SKEL_TELEPORT + 1,  SKEL_TELEPORT_RATE, NullAnimator, &s_SkelTeleport[4]},
363     {SKEL_TELEPORT + 2,  SKEL_TELEPORT_RATE, NullAnimator, &s_SkelTeleport[5]},
364     {SKEL_TELEPORT + 3,  SKEL_TELEPORT_RATE, NullAnimator, &s_SkelTeleport[6]},
365     {SKEL_TELEPORT + 4,  SKEL_TELEPORT_RATE, NullAnimator, &s_SkelTeleport[7]},
366     {SKEL_TELEPORT + 5,  SKEL_TELEPORT_RATE, NullAnimator, &s_SkelTeleport[8]},
367 
368     {SKEL_TELEPORT + 5,  0|SF_QUICK_CALL,    DoSkelTeleport, &s_SkelTeleport[9]},
369 
370     {SKEL_TELEPORT + 5,  SKEL_TELEPORT_RATE, NullAnimator, &s_SkelTeleport[10]},
371     {SKEL_TELEPORT + 4,  SKEL_TELEPORT_RATE, NullAnimator, &s_SkelTeleport[11]},
372     {SKEL_TELEPORT + 3,  SKEL_TELEPORT_RATE, NullAnimator, &s_SkelTeleport[12]},
373     {SKEL_TELEPORT + 2,  SKEL_TELEPORT_RATE, NullAnimator, &s_SkelTeleport[13]},
374     {SKEL_TELEPORT + 1,  SKEL_TELEPORT_RATE, NullAnimator, &s_SkelTeleport[14]},
375     {SKEL_TELEPORT + 0,  SKEL_TELEPORT_RATE, DoSkelTermTeleport, &s_SkelTeleport[15]},
376     {SKEL_TELEPORT + 0,  0|SF_QUICK_CALL, InitActorDecide, &s_SkelTeleport[16]},
377     {SKEL_TELEPORT + 0,  SKEL_TELEPORT_RATE, DoSkelMove, &s_SkelTeleport[16]},
378     };
379 
380 STATEp sg_SkelTeleport[] =
381     {
382     s_SkelTeleport,
383     s_SkelTeleport,
384     s_SkelTeleport,
385     s_SkelTeleport,
386     s_SkelTeleport
387     };
388 
389 //////////////////////
390 //
391 // SKEL STAND
392 //
393 //////////////////////
394 
395 #define SKEL_STAND_RATE 12
396 
397 STATE s_SkelStand[5][1] =
398     {
399     {
400     {SKEL_RUN_R0 + 0, SKEL_STAND_RATE, DoSkelMove, &s_SkelStand[0][0]},
401     },
402     {
403     {SKEL_RUN_R1 + 0, SKEL_STAND_RATE, DoSkelMove, &s_SkelStand[1][0]},
404     },
405     {
406     {SKEL_RUN_R2 + 0, SKEL_STAND_RATE, DoSkelMove, &s_SkelStand[2][0]},
407     },
408     {
409     {SKEL_RUN_R3 + 0, SKEL_STAND_RATE, DoSkelMove, &s_SkelStand[3][0]},
410     },
411     {
412     {SKEL_RUN_R4 + 0, SKEL_STAND_RATE, DoSkelMove, &s_SkelStand[4][0]},
413     },
414     };
415 
416 
417 STATEp sg_SkelStand[] =
418     {
419     s_SkelStand[0],
420     s_SkelStand[1],
421     s_SkelStand[2],
422     s_SkelStand[3],
423     s_SkelStand[4]
424     };
425 
426 //////////////////////
427 //
428 // SKEL DIE
429 //
430 //////////////////////
431 
432 #define SKEL_DIE_RATE 25
433 
434 STATE s_SkelDie[] =
435     {
436     {SKEL_DIE + 0, SKEL_DIE_RATE, NullAnimator, &s_SkelDie[1]},
437     {SKEL_DIE + 1, SKEL_DIE_RATE, NullAnimator, &s_SkelDie[2]},
438     {SKEL_DIE + 2, SKEL_DIE_RATE, NullAnimator, &s_SkelDie[3]},
439     {SKEL_DIE + 3, SKEL_DIE_RATE, NullAnimator, &s_SkelDie[4]},
440     {SKEL_DIE + 4, SKEL_DIE_RATE, NullAnimator, &s_SkelDie[5]},
441     {SKEL_DIE + 5, SKEL_DIE_RATE, DoSuicide,   &s_SkelDie[5]},
442     };
443 
444 STATEp sg_SkelDie[] =
445     {
446     s_SkelDie
447     };
448 
449 /*
450 STATEp *Stand[MAX_WEAPONS];
451 STATEp *Run;
452 STATEp *Jump;
453 STATEp *Fall;
454 STATEp *Crawl;
455 STATEp *Swim;
456 STATEp *Fly;
457 STATEp *Rise;
458 STATEp *Sit;
459 STATEp *Look;
460 STATEp *Climb;
461 STATEp *Pain;
462 STATEp *Death1;
463 STATEp *Death2;
464 STATEp *Dead;
465 STATEp *DeathJump;
466 STATEp *DeathFall;
467 STATEp *CloseAttack[2];
468 STATEp *Attack[6];
469 STATEp *Special[2];
470 */
471 
472 ACTOR_ACTION_SET SkelActionSet =
473   {
474   sg_SkelStand,
475   sg_SkelRun,
476   NULL,//sg_SkelJump,
477   NULL,//sg_SkelFall,
478   NULL,//sg_SkelCrawl,
479   NULL,//sg_SkelSwim,
480   NULL,//sg_SkelFly,
481   NULL,//sg_SkelRise,
482   NULL,//sg_SkelSit,
483   NULL,//sg_SkelLook,
484   NULL,//climb
485   sg_SkelPain,//pain
486   sg_SkelDie,
487   NULL,//sg_SkelHariKari,
488   NULL,//sg_SkelDead,
489   NULL,//sg_SkelDeathJump,
490   NULL,//sg_SkelDeathFall,
491   {sg_SkelSlash},
492   {1024},
493   {sg_SkelSpell},
494   {1024},
495   {NULL},
496   sg_SkelTeleport,
497   NULL
498   };
499 
500 int
SetupSkel(short SpriteNum)501 SetupSkel(short SpriteNum)
502 {
503     SPRITEp sp = &sprite[SpriteNum];
504     USERp u;
505     ANIMATOR DoActorDecide;
506 
507     if (TEST(sp->cstat, CSTAT_SPRITE_RESTORE))
508         {
509         u = User[SpriteNum];
510         ASSERT(u);
511         }
512     else
513         {
514         User[SpriteNum] = u = SpawnUser(SpriteNum,SKEL_RUN_R0,s_SkelRun[0]);
515         u->Health = HEALTH_SKEL_PRIEST;
516         }
517 
518     ChangeState(SpriteNum, s_SkelRun[0]);
519     u->Attrib = &SkelAttrib;
520     DoActorSetSpeed(SpriteNum, NORM_SPEED);
521     u->StateEnd = s_SkelDie;
522     u->Rot = sg_SkelRun;
523 
524     EnemyDefaults(SpriteNum, &SkelActionSet, &SkelPersonality);
525 
526     // 256 is default
527     //sp->clipdist = 256 >> 2;
528     SET(u->Flags, SPR_XFLIP_TOGGLE);
529 
530     return(0);
531 }
532 
DoSkelInitTeleport(short SpriteNum)533 int DoSkelInitTeleport(short SpriteNum)
534 {
535     SPRITEp sp = &sprite[SpriteNum];
536     USERp u = User[SpriteNum];
537 
538     RESET(sp->cstat, CSTAT_SPRITE_BLOCK|CSTAT_SPRITE_BLOCK_HITSCAN);
539 
540     PlaySpriteSound(SpriteNum,attr_extra3,v3df_follow);
541 
542     return(0);
543 }
544 
DoSkelTeleport(short SpriteNum)545 int DoSkelTeleport(short SpriteNum)
546 {
547     SPRITEp sp = &sprite[SpriteNum];
548     USERp u = User[SpriteNum];
549     int x,y;
550 
551     x = sp->x;
552     y = sp->y;
553 
554     while (TRUE)
555         {
556         sp->x = x;
557         sp->y = y;
558 
559         if (RANDOM_P2(1024) < 512)
560             sp->x += 512 + RANDOM_P2(1024);
561         else
562             sp->x -= 512 + RANDOM_P2(1024);
563 
564         if (RANDOM_P2(1024) < 512)
565             sp->y += 512 + RANDOM_P2(1024);
566         else
567             sp->y -= 512 + RANDOM_P2(1024);
568 
569         setspritez(SpriteNum, sp->x, sp->y, sp->z);
570         //COVERupdatesector(sp->x, sp->y, &sp->sectnum);
571 
572         if (sp->sectnum != -1)
573             break;
574         }
575 
576     return(0);
577 }
578 
DoSkelTermTeleport(short SpriteNum)579 int DoSkelTermTeleport(short SpriteNum)
580 {
581     SPRITEp sp = &sprite[SpriteNum];
582     USERp u = User[SpriteNum];
583 
584     SET(sp->cstat, CSTAT_SPRITE_BLOCK|CSTAT_SPRITE_BLOCK_HITSCAN);
585 
586     return(0);
587 }
588 
NullSkel(short SpriteNum)589 int NullSkel(short SpriteNum)
590 {
591     SPRITEp sp = &sprite[SpriteNum];
592     USERp u = User[SpriteNum];
593 
594     if (TEST(u->Flags,SPR_SLIDING))
595         DoActorSlide(SpriteNum);
596 
597     KeepActorOnFloor(SpriteNum);
598     DoActorSectorDamage(SpriteNum);
599 
600     return(0);
601 }
602 
DoSkelPain(short SpriteNum)603 int DoSkelPain(short SpriteNum)
604 {
605     SPRITEp sp = &sprite[SpriteNum];
606     USERp u = User[SpriteNum];
607 
608     NullSkel(SpriteNum);
609 
610     if ((u->WaitTics -= ACTORMOVETICS) <= 0)
611         InitActorDecide(SpriteNum);
612 
613     return(0);
614 }
615 
DoSkelMove(short SpriteNum)616 int DoSkelMove(short SpriteNum)
617 {
618     SPRITEp sp = &sprite[SpriteNum];
619     USERp u = User[SpriteNum];
620 
621     if (TEST(u->Flags,SPR_SLIDING))
622         DoActorSlide(SpriteNum);
623 
624     if (u->track >= 0)
625         ActorFollowTrack(SpriteNum, ACTORMOVETICS);
626     else
627         (*u->ActorActionFunc)(SpriteNum);
628 
629     KeepActorOnFloor(SpriteNum);
630 
631     DoActorSectorDamage(SpriteNum);
632 
633     return(0);
634 }
635 
636 
637 #include "saveable.h"
638 
639 static saveable_code saveable_skel_code[] = {
640 	SAVE_CODE(SetupSkel),
641 	SAVE_CODE(DoSkelInitTeleport),
642 	SAVE_CODE(DoSkelTeleport),
643 	SAVE_CODE(DoSkelTermTeleport),
644 	SAVE_CODE(NullSkel),
645 	SAVE_CODE(DoSkelPain),
646 	SAVE_CODE(DoSkelMove),
647 };
648 
649 static saveable_data saveable_skel_data[] = {
650 	SAVE_DATA(SkelBattle),
651 	SAVE_DATA(SkelOffense),
652 	SAVE_DATA(SkelBroadcast),
653 	SAVE_DATA(SkelSurprised),
654 	SAVE_DATA(SkelEvasive),
655 	SAVE_DATA(SkelLostTarget),
656 	SAVE_DATA(SkelCloseRange),
657 
658 	SAVE_DATA(SkelPersonality),
659 
660 	SAVE_DATA(SkelAttrib),
661 
662 	SAVE_DATA(s_SkelRun),
663 	SAVE_DATA(sg_SkelRun),
664 	SAVE_DATA(s_SkelSlash),
665 	SAVE_DATA(sg_SkelSlash),
666 	SAVE_DATA(s_SkelSpell),
667 	SAVE_DATA(sg_SkelSpell),
668 	SAVE_DATA(s_SkelPain),
669 	SAVE_DATA(sg_SkelPain),
670 	SAVE_DATA(s_SkelTeleport),
671 	SAVE_DATA(sg_SkelTeleport),
672 	SAVE_DATA(s_SkelStand),
673 	SAVE_DATA(sg_SkelStand),
674 	SAVE_DATA(s_SkelDie),
675 	SAVE_DATA(sg_SkelDie),
676 
677 	SAVE_DATA(SkelActionSet),
678 };
679 
680 saveable_module saveable_skel = {
681 	// code
682 	saveable_skel_code,
683 	SIZ(saveable_skel_code),
684 
685 	// data
686 	saveable_skel_data,
687 	SIZ(saveable_skel_data)
688 };
689