Debian Codegraph @

scripts/AIGame.cpp

raw symbols SCIP
1 /*
2 * Descent 3
3 * Copyright (C) 2024 Parallax Software
4 *
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * 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, see <http://www.gnu.org/licenses/>.
17 */
18
19 // AIGame.cpp
20 //
21 #include <stdio.h>
22 #include <stdlib.h>
23 #include <string.h>
24 #include "osiris_import.h"
25 #include "osiris_common.h"
26 #include "osiris_vector.h"
27 #include "DallasFuncs.cpp"
28
29 #include "module.h"
30
31 #ifdef __cplusplus
32 extern "C" {
33 #endif
34 DLLEXPORT char STDCALL InitializeDLL(tOSIRISModuleInit *func_list);
35 DLLEXPORT void STDCALL ShutdownDLL(void);
36 DLLEXPORT int STDCALL GetGOScriptID(const char *name, uint8_t isdoor);
37 DLLEXPORT void STDCALLPTR CreateInstance(int id);
38 DLLEXPORT void STDCALL DestroyInstance(int id, void *ptr);
39 DLLEXPORT int16_t STDCALL CallInstanceEvent(int id, void *ptr, int event, tOSIRISEventInfo *data);
40 DLLEXPORT int STDCALL SaveRestoreState(void *file_ptr, uint8_t saving_state);
41 #ifdef __cplusplus
42 }
43 #endif
44
45 static int String_table_size = 0;
46 static char **String_table = NULL;
47 static const char *_Error_string = "!!ERROR MISSING STRING!!";
48 static const char *_Empty_string = "";
49 const char *GetStringFromTable(int index) {
50 if ((index < 0) || (index >= String_table_size))
51 return _Error_string;
52 if (!String_table[index])
53 return _Empty_string;
54 return String_table[index];
55 }
56 #define TXT(x) GetStringFromTable(x)
57 #define TXT_GBM_RENAME 0 //"Rename GB Unit"
58 #define TXT_GBM_REPAIR 1 //"Repair GB"
59 #define TXT_GBM_EXITSHIP 2 //"Exit ship"
60 #define TXT_GBM_P0 3 //"P0"
61 #define TXT_GBM_P1 4 //"P1"
62 #define TXT_GBM_P2 5 //"P2"
63 #define TXT_GBM_P3 6 //"P3"
64 #define TXT_GBM_P4 7 //"P4"
65 #define TXT_GBM_P5 8 //"P5"
66 #define TXT_GBM_P6 9 //"P6"
67 #define TXT_GBM_P7 10 //"P7"
68 #define TXT_GBM_S0 11 //"S0"
69 #define TXT_GBM_S1 12 //"S1"
70 #define TXT_GBM_S2 13 //"S2"
71 #define TXT_GBM_S3 14 //"S3"
72 #define TXT_GBM_S4 15 //"S4"
73 #define TXT_GBM_S5 16 //"S5"
74 #define TXT_GBM_S6 17 //"S6"
75 #define TXT_GBM_S7 18 //"S7"
76 #define TXT_GBM_FINDPOWERUPS 19 //"Find my powerups"
77 #define TXT_GBM_FINEPOWERUP 20 //"Find powerup"
78 #define TXT_GBM_FINDENERGY 21 //"Find energy"
79 #define TXT_GBM_FINDROBOT 22 //"Find robot"
80 #define TXT_GBM_FINDTHIEF 23 //"Find Thief"
81 #define TXT_GBM_FINDEXIT 24 //"Find an exit to the mine"
82 #define TXT_GBM_FINDMINE 25 //"Find a mine"
83 #define TXT_GBM_FINDCMARK 26 //"Find closest marker"
84 #define TXT_GBM_M0 27 //"Find Marker 0"
85 #define TXT_GBM_M1 28 //"Find Marker 1"
86 #define TXT_GBM_M2 29 //"Find Marker 2"
87 #define TXT_GBM_M3 30 //"Find Marker 3"
88 #define TXT_GBM_M4 31 //"Find Marker 4"
89 #define TXT_GBM_M5 32 //"Find Marker 5"
90 #define TXT_GBM_M6 33 //"Find Marker 6"
91 #define TXT_GBM_M7 34 //"Find Marker 7"
92 #define TXT_GBM_ESCORT 35 //"Escort ship"
93 #define TXT_GBM_USEEXTIN 36 //"Use fire extinguisher"
94 #define TXT_GBM_WINGNUT 37 //"Use Go Wingnut Powerup"
95 #define TXT_GBM_PILOTPOWER 38 //"Use Manual Pilot Powerup"
96 #define TXT_GBM_GUARDIAN 39 //"Use Guardian Powerup"
97 #define TXT_GBM_ANTIVIRUS 40 //"Use Anti-Virus Powerup"
98 #define TXT_GBM_ALLOWCHAT 41 //"Allow GB chatter"
99 #define TXT_GBM_DISALLOWCHAT 42 //"Disallow GB chatter"
100 #define TXT_GBM_RETURNTOSHIP 43 //"Return to ship
101 #define TXT_GB_ENTERINGSHIP TXT(44) //"Entering ship!"
102 #define TXT_GB_HELPMSG TXT(45) //"HELP! I am about to die..."
103 #define TXT_GB_NOTLOCATION TXT(46) //"This goal is not location based."
104 #define TXT_GB_NONAV TXT(47) //"I do not have nav. data on this goal."
105 #define TXT_GB_ONMYWAY TXT(48) //"On my way!"
106 #define TXT_GB_NOTREACH TXT(49) //"The goal isn't currently reachable."
107 #define TXT_GB_ENTERSHIP TXT(50) //"Returning to ship."
108 #define TXT_GB_ESCORT TXT(51) //"Escorting ship..."
109 #define TXT_GB_FINDROBOT TXT(52) //"Finding a robot."
110 #define TXT_GB_NOROBOT TXT(53) //"No robots are reachable."
111 #define TXT_GB_FINDPOWERUP TXT(54) //"Finding a powerup."
112 #define TXT_GB_NOPOWERUP TXT(55) //"No powerups are reachable."
113 #define TXT_GB_GOMARKER TXT(56) //"Going to the '%s' marker."
114 #define TXT_GB_NOMARKER TXT(57) //"None of your markers are reachable."
115 #define TXT_GB_NOMARK TXT(58) //"The marker is not reachable."
116 #define TXT_GB_FINDTHIEF TXT(59) //"Finding the Thief."
117 #define TXT_GB_FOUNDTHIEF TXT(60) //"Let's get him!"
118 #define TXT_GB_NOTHIEF TXT(61) //"The Thief is not reachable."
119 #define TXT_GB_FINDPOWERUPS TXT(62) //"Finding your powerups."
120 #define TXT_GB_NOMESSAGE TXT(63) //"No spew reachable."
121 #define TXT_GB_CHATOFF TXT(64) //"Message Processor off."
122 #define TXT_GB_CHATON TXT(65) //"Message Processor On."
123 #define TXT_GB_FINDENERGY TXT(66) //"Finding energy."
124 #define TXT_GB_NOENERGY TXT(67) //"No energy centers are reachable."
125 #define TXT_GB_REPAIRED TXT(68) //"Repaired!"
126 #define TXT_GB_NOTENSH TXT(69) //"NOt eNougH shIelDs to do rePAir..."
127 #define TXT_GB_NEWNAME TXT(70) //"Thank you for the new name!"
128 #define TXT_GB_NOWAY TXT(71) //"No way!"
129 #define TXT_GB_STRIKE TXT(72) //"I am on strike! I won't do task %d"
130 #define TXT_GB_MENUTITLE TXT(73) //"GB Command Menu"
131 #define TXT_GB_FINDMARKMENU TXT(74) //"Find marker: '%s'"
132 #define TXT_GB_GETTO TXT(75) //"Get to %s"
133 #define TXT_GB_SHIELDAMOUNT TXT(76) //" (%d shields)"
134 #define TXT_GB_ENTERNAME TXT(77) //"Enter GuideBot name:"
135 #define TXT_GBHIT1 TXT(78) //"Stop shooting me!"
136 #define TXT_GBHIT2 TXT(79) //"You hit me!"
137 #define TXT_GBHIT3 TXT(80) //"Stop it!"
138 #define TXT_GBHIT4 TXT(81) //"Im getting attacked!"
139 #define TXT_GBHIT5 TXT(82) //"Ouch!"
140 #define TXT_GBDAMAGED TXT(83) //"T?o Dama.xgf.ed to exit. NExfvD rEpair."
141 #define TXT_GB_OOPS TXT(84) //"Oops... Sorry about that!"
142 #define TXT_GB_SHOOTROBOT TXT(85) //"Take that!"
143 #define TXT_GB_GOAL1 TXT(86) //"I am at the goal, coming back to get you."
144 #define TXT_GB_GOAL2 TXT(87) //"Come on!"
145 #define TXT_GB_GOAL3 TXT(88) //"Let's go!"
146 #define TXT_GB_COMINGBACK TXT(89) //"I am coming back to get you."
147 #define TXT_THIEFSTEAL TXT(90) //"The thief stole your %s!"
148 #define TXT_THIEFSTEAL1 TXT(91) //"The thief stole a %s!"
149 #define TXT_THIEFSTEAL2 TXT(92) //"The thief stole %d of your %ss!"
150 #define TXT_GB_POWERUP TXT(93) //"This powerup is for the GuideBot."
151 #define TXT_STHIEFSTEAL TXT(94) //"The Super Thief stole a %s!"
152 #define TXT_STHIEFSTEAL2 TXT(95) //"The Super Thief stole %d of your %ss!"
153 #define TXT_GBP_PUTOUTFIRE 96 //"Putting out fires!"
154 #define TXT_GBP_COWABUNGA 97 //"Cowabunga!"
155 #define TXT_GBP_BEGENTAL 98 //"Be gental..."
156 #define TXT_GBP_LETSDOIT 99 //"Let's do it!"
157 #define TXT_GBP_CONVERTEN 100 //"I will convert the infidal!"
158 #define TXT_GBP_ACCELERATOR 101 //"Accelerator!!!!!!!"
159 #define TXT_GBPN_NOFIRE 102 //"No fires to put out!"
160 #define TXT_GBPN_NOFIGHT 103 //"I don't want to fight!"
161 #define TXT_GBPN_GOPLAY 104 //"Go play with yourself..."
162 #define TXT_GBPN_TOODISSY 105 //"Too dissy..."
163 #define TXT_GBPN_NOENEMY 106 //"No enemies are near!"
164 #define TXT_GBPN_NOCOFFEE 107 //"I am sick of coffee..."
165 #define TXT_GBPP_EXTIN 108 //"I got an extinguisher!"
166 #define TXT_GBPP_WINGNUT 109 //"I got the Wingnut Powerup!
167 #define TXT_GBPP_MANCON 110 //"I got the Manual Control Powerup!"
168 #define TXT_GBPP_GUARD 111 //"I got the Guardian Powerup!"
169 #define TXT_GBPP_ANTIV 112 //"I got a temporary Anti-Virus!"
170 #define TXT_GBPP_ACCEL 113 //"I got the Accelerator!!!!!!"
171 #define TXT_WEAP_LASERS 114
172 #define TXT_WEAP_VAUSS 115
173 #define TXT_WEAP_MICROWAVE 116
174 #define TXT_WEAP_PLASMA 117
175 #define TXT_WEAP_FUSION 118
176 #define TXT_WEAP_SUPER 119
177 #define TXT_WEAP_MASS 120
178 #define TXT_WEAP_NAPALM 121
179 #define TXT_WEAP_EMD 122
180 #define TXT_WEAP_OMEGA 123
181 #define TXT_WEAP_CONCUSSION 124
182 #define TXT_WEAP_HOMING 125
183 #define TXT_WEAP_IMPACT 126
184 #define TXT_WEAP_SMART 127
185 #define TXT_WEAP_MEGA 128
186 #define TXT_WEAP_FRAG 129
187 #define TXT_WEAP_GUIDED 130
188 #define TXT_WEAP_NAPALMR 131
189 #define TXT_WEAP_CYCLONE 132
190 #define TXT_WEAP_BLACKSHARK 133
191 #define TXT_WEAP_AUTOMAP 134
192 #define TXT_WEAP_HEADLIGHT 135
193 #define TXT_WEAP_ETSCONVERTER 136
194 #define TXT_WEAP_CLOAK 137
195 #define TXT_WEAP_INVULNERABILITY 138
196 #define TXT_WEAP_RAPIDFIRE 139
197 #define TXT_WEAP_QUADLASERS 140
198 #define TXT_GB_FIFTEEN_SEC_TO_GO TXT(141)
199 #define TXT_GB_POW_DEPLETED TXT(142)
200 #define TXT_GB_POW_ACC_ALMOST_DONE TXT(143)
201 #define TXT_GB_DONT_HAVE_POWERUP TXT(144)
202 #define TXT_GB_I_FOUND_A_GB_POWERUP TXT(145)
203
204 // Returns the new child's handle
205 static int CreateAndAttach(int me, const char *child_name, uint8_t child_type, char parent_ap, char child_ap,
206 bool f_aligned = true, bool f_set_parent = false);
207
208 // Returns the new child's handle
209 int CreateAndAttach(int me, const char *child_name, uint8_t child_type, char parent_ap, char child_ap, bool f_aligned,
210 bool f_set_parent) {
211 int child_handle = OBJECT_HANDLE_NONE;
212 int child_id = Obj_FindID(child_name);
213 msafe_struct m;
214 m.objhandle = me;
215 MSafe_GetValue(MSAFE_OBJECT_POS, &m);
216 MSafe_GetValue(MSAFE_OBJECT_ROOMNUM, &m);
217
218 if (child_id >= 0) {
219 int parent;
220 if (f_set_parent)
221 parent = me;
222 else
223 parent = OBJECT_HANDLE_NONE;
224
225 child_handle = Obj_Create(child_type, child_id, m.roomnum, &m.pos, NULL, parent);
226 if (child_handle != OBJECT_HANDLE_NONE) {
227 if (!Obj_AttachObjectAP(me, parent_ap, child_handle, child_ap, f_aligned)) {
228 // chrishack (we need a way to instantly kill scripted objects)
229 }
230 }
231 }
232
233 return child_handle;
234 }
235
236 // ==========================
237 // Script class definitions//
238 // ==========================
239 #define NUM_IDS 44 // maximum number of IDs
240
241 #define ID_PEST 0 // Pest robot
242 #define ID_STINGER 1 // Stringer robot
243 #define ID_DRAGON 2 // Dragon
244 #define ID_TRACKER 3 // Tracker
245 #define ID_LANCE 4 // Lance
246 #define ID_FLAK 5 // Flak
247 #define ID_SUPERTROOPER 6 // Super Trooper
248 #define ID_REDSUPERTROOPER 7 // Red Super Trooper
249 #define ID_JUGG 8 // Juggernaut
250 #define ID_SIXGUN 9 // Sixgun
251 #define ID_SICKLE 10 // Sickle
252 #define ID_GUIDEBOT 11 // GuideBot
253 #define ID_FIREATDIST 12 // Fire at distance
254 #define ID_TUBBS 13 // Tubbs
255 #define ID_THIEF 14 // Thief :)
256 #define ID_GBPOWERUP 15 // GBPowerup
257 #define ID_BARNSWALLOW 16 // Barn Shallow
258 #define ID_SPARKY 17
259 #define ID_MANTARAY 18
260 #define ID_SPYHUNTER 19
261 #define ID_SNIPER 20
262 #define ID_HUMONCULOUS 21
263 #define ID_SEEKER 22
264 #define ID_BETTY 23
265 #define ID_CHAFF 24
266 #define ID_CHAFFCHUNK 25
267 #define ID_PROXMINE 26
268 #define ID_BETTYBOMB 27 // parent of Bouncing Betty...created to make 3 Bettys
269 #define ID_JOSHBELL 28
270 #define ID_SKIFF 29
271 #define ID_EXPLODEONCONTACT 30
272 #define ID_EXPLODETIMEOUT 31
273 #define ID_GUNBOY 32
274 #define ID_DEATH_TOWER 33
275 #define ID_DEATH_COLLECTOR 34
276 #define ID_CHEMICAL_BALL 35
277 #define ID_HELLION 36
278 #define ID_SUPERTHIEF 37
279 #define ID_EVADERMODA 38
280 #define ID_DESTROYONCONTACT 39
281 #define ID_HATEPTMC 40
282 #define ID_SNIPERNORUN 41
283 #define ID_FLAMERAS 42
284 #define ID_OLDSCRATCH 43
285
286 struct tScriptInfo {
287 int id;
288 const char *name;
289 };
290
291 static tScriptInfo ScriptInfo[NUM_IDS] = {{ID_PEST, "Pest"},
292 {ID_STINGER, "Stinger"},
293 {ID_DRAGON, "Dragontorso"},
294 {ID_TRACKER, "Tracker"},
295 {ID_LANCE, "Lance"},
296 {ID_FLAK, "Flak"},
297 {ID_SUPERTROOPER, "supertrooper"},
298 {ID_REDSUPERTROOPER, "red supertrooper"},
299 {ID_JUGG, "jugg"},
300 {ID_SIXGUN, "Sixgun"},
301 {ID_SICKLE, "Sickle"},
302 {ID_GUIDEBOT, "Guidebot"},
303 {ID_FIREATDIST, "FireAtDist"},
304 {ID_TUBBS, "Tubbs"},
305 {ID_THIEF, "Thief"},
306 {ID_GBPOWERUP, "GBPowerup"},
307 {ID_BARNSWALLOW, "BarnSwallow"},
308 {ID_SPARKY, "Sparky"},
309 {ID_MANTARAY, "Mantaray"},
310 {ID_SPYHUNTER, "Spyhunter"},
311 {ID_SNIPER, "Sniper"},
312 {ID_HUMONCULOUS, "Humonculous"},
313 {ID_SEEKER, "Seeker"},
314 {ID_BETTY, "Betty"},
315 {ID_CHAFF, "ChaffBomb"},
316 {ID_CHAFFCHUNK, "ChaffChunk"},
317 {ID_PROXMINE, "ProxMine"},
318 {ID_BETTYBOMB, "BettyBomb"},
319 {ID_JOSHBELL, "JoshBell"},
320 {ID_SKIFF, "Skiff"},
321 {ID_EXPLODEONCONTACT, "ExplodeOnContact"},
322 {ID_EXPLODETIMEOUT, "ExplodeTimeOut"},
323 {ID_GUNBOY, "Gunboy"},
324 {ID_DEATH_TOWER, "Ltowerbase"},
325 {ID_DEATH_COLLECTOR, "Collectorbase"},
326 {ID_CHEMICAL_BALL, "ChemicalBall"},
327 {ID_HELLION, "Hellion"},
328 {ID_SUPERTHIEF, "superthief"},
329 {ID_EVADERMODA, "EvaderModA"},
330 {ID_DESTROYONCONTACT, "DestroyOnContact"},
331 {ID_HATEPTMC, "HatePTMC"},
332 {ID_SNIPERNORUN, "SniperNoRun"},
333 {ID_FLAMERAS, "FlameRAS"},
334 {ID_OLDSCRATCH, "old scratch"}};
335
336 static int aigame_mod_id;
337 // use this macro to create unique timer IDs
338 #define CREATE_TIMER_ID(id) ((aigame_mod_id << 16) | (id))
339
340 static int GetObjectParent(int object);
341 static int GetObjectType(int object);
342
343 class BaseObjScript {
344 public:
345 BaseObjScript();
346 ~BaseObjScript();
347 virtual int16_t CallEvent(int event, tOSIRISEventInfo *data);
348 };
349
350 struct tShieldOrbInfo {
351 int hitcount;
352 };
353
354 //------------------
355 // Pest class
356 //------------------
357 struct pest_data {
358 int tail_handle;
359 float last_anim_frame;
360 int foot_sounds[3];
361 };
362
363 class Pest : public BaseObjScript {
364 private:
365 pest_data *memory;
366 void DoInit(int me_handle);
367
368 public:
369 Pest() {}
370 int16_t CallEvent(int event, tOSIRISEventInfo *data);
371 };
372
373 //------------------
374 // Stinger class
375 //------------------
376 #define STINGER_RANGED 0
377 #define STINGER_MELEE 1
378
379 struct stinger_data {
380 float next_mode_time;
381 float force_melee_shields;
382 char mode;
383 char f_very_hurt;
384 };
385
386 class Stinger : public BaseObjScript {
387 private:
388 stinger_data *memory;
389
390 void DoInit(int me_handle);
391 void DoInterval(int me_handle);
392
393 public:
394 Stinger() { memory = NULL; }
395 int16_t CallEvent(int event, tOSIRISEventInfo *data);
396 };
397
398 //------------------
399 // SuperThief class
400 //------------------
401
402 #define MAX_STOLEN_WEAPONS 25
403
404 struct weapon_item {
405 char index;
406 int owner;
407 char amount;
408 };
409
410 #define SUPERTHIEF_RANGED 0
411 #define SUPERTHIEF_MELEE 1
412 #define SUPERTHIEF_DEATH 2
413 #define SUPERTHIEF_WAIT 3
414 #define SUPERTHIEF_INTRO 4
415
416 struct superthief_data {
417 float mode_time;
418
419 float next_mode_time;
420 float force_ranged_shields;
421 char mode;
422 char f_very_hurt;
423
424 float last_frame;
425 float time_till_fire_secondary;
426
427 int cur_weapon;
428
429 int num_stolen_weapons;
430 weapon_item stolen_weapons[MAX_STOLEN_WEAPONS];
431
432 char weapon[100];
433 char sound[100];
434 float latency;
435
436 float next_fire_flare_time;
437 int flare_fire_index;
438
439 int camera_obj;
440 int laser_obj;
441
442 bool laser_on;
443 };
444
445 class SuperThief : public BaseObjScript {
446 private:
447 superthief_data *memory;
448
449 bool DoSteal(int me, int it);
450 void SpewEverything(int me);
451 bool DoNotify(int me, tOSIRISEVTAINOTIFY *notify);
452
453 void SetMode(int me, char mode);
454 void CheckAndFireSecondary(int me);
455
456 void FireFlare(int me);
457
458 void DoInit(int me_handle);
459 void DoInterval(int me_handle);
460
461 public:
462 SuperThief() { memory = NULL; }
463 int16_t CallEvent(int event, tOSIRISEventInfo *data);
464 };
465
466 //------------------
467 // Humonculous class
468 //------------------
469
470 struct humonculous_data {
471 float next_wall_hit_check_time;
472 float mode_time;
473
474 float force_mid_damage_shields;
475 float force_wall_hit_shields;
476 float force_melee_shields;
477
478 float last_shields;
479
480 uint16_t mode;
481 uint16_t next_mode;
482
483 vector land_pos;
484 vector land_fvec;
485 // Note: land_uvec is always {0.0, 1.0, 0.0}
486
487 float ground_pnt_offset; // This can be computed at start of level
488
489 float max_speed;
490 float max_delta_speed;
491
492 float next_mode_time;
493
494 int josh[2];
495
496 int rocks[5];
497
498 int16_t flags;
499 };
500
501 class Humonculous : public BaseObjScript {
502 private:
503 humonculous_data *memory;
504
505 void DetermineDeathPos(int me, vector *dpos, int *droom);
506 bool SetMode(int me, uint16_t mode);
507 void DoInit(int me);
508 void DoInterval(int me);
509 bool DoNotify(int me, tOSIRISEventInfo *data);
510
511 public:
512 Humonculous() { memory = NULL; }
513 int16_t CallEvent(int event, tOSIRISEventInfo *data);
514 };
515
516 //------------------
517 // Dragon class
518 //------------------
519 #define DRAGON_ARMOR 0
520 #define DRAGON_SKELETON 1
521
522 struct dragon_data {
523 int mode;
524 int head_object;
525 int tail_object;
526 int green_turret;
527 int t[6];
528 int tentacle[6];
529 };
530
531 class Dragon : public BaseObjScript {
532 private:
533 dragon_data *memory;
534
535 void DoInit(int me_handle);
536
537 public:
538 Dragon() { memory = NULL; }
539 int16_t CallEvent(int event, tOSIRISEventInfo *data);
540 };
541
542 //----------------
543 // Tracker
544 //----------------
545
546 struct tracker_data {
547 int turret_object;
548 int hatch_object;
549 };
550
551 class Tracker : public BaseObjScript {
552 private:
553 tracker_data *memory;
554
555 void DoInit(int me_handle);
556
557 public:
558 Tracker() { memory = NULL; }
559 int16_t CallEvent(int event, tOSIRISEventInfo *data);
560 };
561
562 //------------------
563 // Lance class
564 //------------------
565
566 #define LANCE_PAUSED 0
567 #define LANCE_MOVING 1
568
569 struct lance_data {
570 int mode;
571 };
572
573 class Lance : public BaseObjScript {
574 private:
575 void DoInit(int me_handle);
576 void DoFrame(int me_handle);
577 lance_data *memory;
578
579 public:
580 Lance() {}
581 int16_t CallEvent(int event, tOSIRISEventInfo *data);
582 };
583
584 //------------------
585 // Flak class
586 //------------------
587 struct flak_data {
588 int canopy_handle;
589 bool f_dead;
590 float death_time;
591 };
592
593 class Flak : public BaseObjScript {
594 private:
595 flak_data *memory;
596 void DoInit(int me_handle);
597
598 public:
599 Flak() {}
600 int16_t CallEvent(int event, tOSIRISEventInfo *data);
601 };
602
603 //------------------
604 // Seeker class
605 //------------------
606
607 class Seeker : public BaseObjScript {
608 private:
609 void DoInit(int me);
610 void DoCollide(int me);
611
612 public:
613 Seeker() {}
614 int16_t CallEvent(int event, tOSIRISEventInfo *data);
615 };
616
617 //------------------
618 // SuperTrooper class
619 //------------------
620
621 struct supertrooper_data {
622 int body_handle;
623 };
624
625 class SuperTrooper : public BaseObjScript {
626 private:
627 supertrooper_data *memory;
628 void DoInit(int me_handle);
629
630 public:
631 SuperTrooper() {}
632 int16_t CallEvent(int event, tOSIRISEventInfo *data);
633 };
634
635 //------------------
636 // Sparky class
637 //------------------
638
639 #define MALF_TIME 5.0f
640 #define MIN_MALF_SPEED 6000.0f
641
642 #define DEATH_TIME 5.0f
643 #define DEATH_ROT_ACC 50000.0f
644
645 #define SPARKY_NO_ROT 0
646 #define SPARKY_ROT_LEFT 1
647 #define SPARKY_ROT_RIGHT 2
648
649 #define SPARKY_NORMAL 0
650 #define SPARKY_DYING 1
651
652 struct sparky_data {
653 char mode;
654 float mode_time;
655 bool f_rotation_death_enabled;
656 float drag;
657
658 float last_spark_time;
659
660 int matcen_id;
661
662 matrix orient;
663
664 char spin_dir;
665 float spin_time;
666 };
667
668 class Sparky : public BaseObjScript {
669 private:
670 sparky_data *memory;
671 void DoInit(int me);
672 void DoFrame(int me);
673 bool DoNotify(int me_handle, tOSIRISEventInfo *data);
674 void SetMode(int me, char mode);
675
676 public:
677 Sparky() {}
678 int16_t CallEvent(int event, tOSIRISEventInfo *data);
679 };
680
681 //------------------
682 // Hellion class
683 //------------------
684
685 #define HELLION_WAIT 0
686 #define HELLION_INTRO 1
687 #define HELLION_MATTER 2
688 #define HELLION_ENERGY 3
689 #define HELLION_FIRE 4
690 #define HELLION_SLEEP 5
691 #define HELLION_BIRTHING 6
692 #define HELLION_DEATH 7
693 #define HELLION_BETWEEN_MODE 8
694
695 struct hellion_data {
696 int flags;
697 char mode;
698 char next_mode;
699 float mode_time;
700 int head_object;
701 int turret_object;
702
703 float last_frame;
704
705 int laser_sound;
706
707 // Save and restore information
708 char weapon[100];
709 char sound[100];
710 float start;
711 float fire;
712 float end;
713 float time;
714 float latency;
715 int index;
716 char f_mask;
717
718 float alert_start;
719 float alert_end;
720 float alert_time;
721 // End of save and restore information
722
723 float laser_time_left;
724 int emitter[2];
725 int camera[2];
726 };
727
728 class Hellion : public BaseObjScript {
729 private:
730 hellion_data *memory;
731 void DoInit(int me);
732 void RemapAlert(int me, float start, float end, float time);
733 void RemapWB(int me, float start, float fire, int fire_sound, float end, float time, float latency, int index,
734 uint16_t w_id, char f_mask);
735 void DoFrame(int me);
736 bool DoNotify(int me_handle, tOSIRISEventInfo *data);
737 void SetMode(int me, char mode);
738
739 public:
740 Hellion() {}
741 int16_t CallEvent(int event, tOSIRISEventInfo *data);
742 };
743
744 //------------------
745 // MantaRay class
746 //------------------
747
748 // Modes
749 #define MRM_NORMAL 0
750 #define MRM_ATTACK 1
751 #define MRM_ATTACK_CIRCLE_BACK 2
752
753 // Flags
754 #define MRF_LEADER 0x01
755 #define MRF_SQUADIE 0x02
756 #define MRF_CATCHUP 0x04
757
758 // Squad commands
759 #define MRC_JOIN_ME 11
760 #define MRC_LEAVE_YOU 12
761 #define MRC_GET_GOAL_POS 13
762 #define MRC_GET_GOAL_ROOM 14
763 #define MRC_GET_GOAL_ORIENT 15
764
765 #define MR_MAX_TEAMMATES 4
766
767 // Squad offsets
768 #define MRO_FVEC 10.0f
769 #define MRO_RVEC 20.0f
770 #define MRO_UVEC 5.0f
771
772 // Squad catchup offset
773 #define MRO_CATCHUP_DIST 5.0f
774
775 struct mantaray_data {
776 char mode;
777 float mode_time;
778 float next_mode_time;
779
780 float base_speed; // We alter this when we are in catchup mode
781 float attack_speed;
782
783 int flags;
784
785 uint16_t mantaray_id;
786
787 int leader_handle;
788 int num_teammates;
789 int teammate[MR_MAX_TEAMMATES];
790 float next_update_squad_time;
791
792 vector goal_pos;
793 int goal_room;
794
795 };
796
797 class MantaRay : public BaseObjScript {
798 private:
799 mantaray_data *memory;
800 void DoInit(int me);
801
802 void DoSquadieFrame(int me);
803 void DoFrame(int me);
804 void SetMode(int me, char mode);
805 bool DoNotify(int me, tOSIRISEventInfo *data);
806
807 bool SendCommand(int me, int it, char command, void *ptr);
808 bool ReceiveCommand(int me, int it, char command, void *ptr);
809
810 void UpdateSquadList(int me);
811 void UpdateSquad(int me);
812
813 public:
814 MantaRay() {}
815 int16_t CallEvent(int event, tOSIRISEventInfo *data);
816 };
817
818 //------------------
819 // Skiff class
820 //------------------
821
822 struct skiff_data {
823 char mode;
824 float mode_time;
825 float next_mode_time;
826
827 float base_speed; // We alter this when we are in catchup mode
828 float attack_speed;
829
830 int flags;
831
832 uint16_t skiff_id;
833
834 int leader_handle;
835 int num_teammates;
836 int teammate[MR_MAX_TEAMMATES];
837 float next_update_squad_time;
838
839 vector goal_pos;
840 int goal_room;
841
842 };
843
844 class Skiff : public BaseObjScript {
845 private:
846 skiff_data *memory;
847 void DoInit(int me);
848
849 void DoSquadieFrame(int me);
850 void DoFrame(int me);
851 void SetMode(int me, char mode);
852 bool DoNotify(int me, tOSIRISEventInfo *data);
853
854 bool SendCommand(int me, int it, char command, void *ptr);
855 bool ReceiveCommand(int me, int it, char command, void *ptr);
856
857 void UpdateSquadList(int me);
858 void UpdateSquad(int me);
859
860 public:
861 Skiff() {}
862 int16_t CallEvent(int event, tOSIRISEventInfo *data);
863 };
864
865 //------------------
866 // SpyHunter class
867 //------------------
868
869 #define SHM_NORMAL 0
870 #define SHM_ATTACK 1
871 #define SHM_BOMB_ATTACK 2
872
873 #define SH_MAX_BOMB_TIME 15.0f
874 #define SH_BOMB_ACCELERATION 8.0f
875 #define SH_BOMB_ROT_ACC 4000.0f
876
877 #define SH_BOMB_TICK_RAMP_TIME 5.0
878 #define SH_MAX_TICK_INTERVAL 0.5f
879 #define SH_MIN_TICK_INTERVAL .06f
880
881 struct spyhunter_data {
882 char mode;
883 float next_mode_time;
884 float next_summon_time;
885 bool f_hit_by_emd;
886 float mode_time;
887 char last_attack_mode;
888 uint16_t emd_id;
889 int tick_sound;
890 float last_tick_time;
891
892 };
893
894 class SpyHunter : public BaseObjScript {
895 private:
896 spyhunter_data *memory;
897 void DoInit(int me);
898 void DoFrame(int me);
899 void DoSummon(int me);
900 bool DoNotify(int me, tOSIRISEventInfo *data);
901 void SetMode(int me, char mode);
902
903 public:
904 SpyHunter() {}
905 int16_t CallEvent(int event, tOSIRISEventInfo *data);
906 };
907
908 //------------------
909 // Sniper class
910 //------------------
911
912 #define SNIPER_BASE 0
913 #define SNIPER_SNIPE 1
914
915 struct sniper_data {
916 char mode;
917 float mode_time;
918 float time_till_next_mode;
919
920 float base_speed;
921 float base_acc;
922 };
923
924 class Sniper : public BaseObjScript {
925 sniper_data *memory;
926 void DoInit(int me);
927 void DoFrame(int me);
928 bool DoNotify(int me_handle, tOSIRISEventInfo *data);
929 void SetMode(int me, char mode);
930
931 public:
932 Sniper() {}
933 int16_t CallEvent(int event, tOSIRISEventInfo *data);
934 };
935
936 //------------------
937 // SniperNoRun class
938 //------------------
939
940 #define SNIPER_BASE 0
941 #define SNIPER_SNIPE 1
942
943 struct snipernorun_data {
944 char mode;
945 float mode_time;
946 float time_till_next_mode;
947
948 float base_speed;
949 float base_acc;
950 };
951
952 class SniperNoRun : public BaseObjScript {
953 snipernorun_data *memory;
954 void DoInit(int me);
955 void DoFrame(int me);
956 bool DoNotify(int me_handle, tOSIRISEventInfo *data);
957 void SetMode(int me, char mode);
958
959 public:
960 SniperNoRun() {}
961 int16_t CallEvent(int event, tOSIRISEventInfo *data);
962 };
963
964 //------------------
965 // EvaderModA class
966 //------------------
967
968 struct evadermoda_data {
969 char mode;
970 float mode_time;
971 float time_till_next_mode;
972
973 float base_speed;
974 float base_acc;
975 };
976
977 class EvaderModA : public BaseObjScript {
978 evadermoda_data *memory;
979 void DoInit(int me);
980 void DoFrame(int me);
981 bool DoNotify(int me_handle, tOSIRISEventInfo *data);
982 void SetMode(int me, char mode);
983
984 public:
985 EvaderModA() {}
986 int16_t CallEvent(int event, tOSIRISEventInfo *data);
987 };
988
989 //------------------
990 // FlameRAS class
991 //------------------
992
993 struct flameras_data {
994 char mode;
995 float mode_time;
996 float time_till_next_mode;
997
998 float base_speed;
999 float base_acc;
1000
1001 float time_till_fire_toggle;
1002 bool f_firing_ok;
1003 };
1004
1005 class FlameRAS : public BaseObjScript {
1006 flameras_data *memory;
1007 void DoInit(int me);
1008 void DoFrame(int me);
1009 bool DoNotify(int me_handle, tOSIRISEventInfo *data);
1010 void SetMode(int me, char mode);
1011
1012 public:
1013 FlameRAS() {}
1014 int16_t CallEvent(int event, tOSIRISEventInfo *data);
1015 };
1016
1017 //-----------------
1018 // Jugg
1019 //-----------------
1020
1021 #define JUGG_NORMAL 0
1022 #define JUGG_DYING 1
1023
1024 #define JUGG_F_BELLY_DEAD 0x01
1025 #define JUGG_F_HEAD_DEAD 0x02
1026 #define JUGG_F_BODY_DEAD 0x04
1027
1028 struct jugg_data {
1029 float last_frame;
1030 int foot_sound;
1031
1032 int head_object;
1033 int belly_object;
1034 int turret_object[6];
1035 int head_turret[2];
1036 int flame_turret[3];
1037
1038 float mode_time;
1039 char mode;
1040 char flags;
1041 };
1042
1043 class Jugg : public BaseObjScript {
1044 private:
1045 jugg_data *memory;
1046 void DoInit(int me_handle);
1047 void DoFrame(int me_handle);
1048 void SetMode(int me, char mode);
1049
1050 public:
1051 Jugg() {}
1052 int16_t CallEvent(int event, tOSIRISEventInfo *data);
1053 };
1054
1055 //-----------------
1056 // Death Tower
1057 //-----------------
1058
1059 struct dtower_data {
1060 int gun_handle;
1061 int ball_handle;
1062
1063 float mode_time;
1064
1065 bool f_died;
1066 float last_frame;
1067 };
1068
1069 class DTower : public BaseObjScript {
1070 private:
1071 dtower_data *memory;
1072 void DoInit(int me_handle);
1073 void DoFrame(int me_handle);
1074
1075 public:
1076 DTower() {}
1077 int16_t CallEvent(int event, tOSIRISEventInfo *data);
1078 };
1079
1080 //-----------------
1081 // Death Collector
1082 //-----------------
1083
1084 struct dcollector_data {
1085 int ball_handle;
1086 int rod_handle;
1087 int target_handle;
1088
1089 bool f_dead;
1090 };
1091
1092 class DCollector : public BaseObjScript {
1093 private:
1094 dcollector_data *memory;
1095 void DoInit(int me_handle);
1096 void DoFrame(int me_handle);
1097
1098 public:
1099 DCollector() {}
1100 int16_t CallEvent(int event, tOSIRISEventInfo *data);
1101 };
1102
1103 //-----------------
1104 // Chemical Ball
1105 //-----------------
1106
1107 struct cball_data {
1108 bool f_picked_up;
1109 float mode_time;
1110 };
1111
1112 class CBall : public BaseObjScript {
1113 private:
1114 cball_data *memory;
1115 void DoInit(int me_handle);
1116 void DoFrame(int me_handle);
1117
1118 public:
1119 CBall() {}
1120 int16_t CallEvent(int event, tOSIRISEventInfo *data);
1121 };
1122
1123 //-----------------
1124 // SixGun
1125 //-----------------
1126
1127 struct sixgun_data {
1128 int mode;
1129 float max_speed;
1130 float circle_dist;
1131 };
1132
1133 class SixGun : public BaseObjScript {
1134 private:
1135 sixgun_data *memory;
1136 void DoInit(int me_handle);
1137 bool DoNotify(int me_handle, tOSIRISEVTAINOTIFY *notify);
1138
1139 public:
1140 SixGun() {}
1141 int16_t CallEvent(int event, tOSIRISEventInfo *data);
1142 };
1143
1144 //-----------------
1145 // Explode Time Out
1146 //-----------------
1147
1148 struct explodetimeout_data {
1149 float life_left;
1150 };
1151
1152 class ExplodeTimeOut : public BaseObjScript {
1153 private:
1154 explodetimeout_data *memory;
1155 void DoInit(int me_handle);
1156
1157 public:
1158 int16_t CallEvent(int event, tOSIRISEventInfo *data);
1159 };
1160
1161 //-----------------
1162 // Sickle
1163 //-----------------
1164
1165 #define SICKLE_GOING_HOME 3 // Going home
1166 #define SICKLE_LAND_ON_CEILING 10 // Rotating upsidedown and going to the ceiling
1167 #define SICKLE_LANDED 12 // Stopped on the ceiling
1168 #define SICKLE_MELEE 15 // Melee
1169
1170 struct sickle_data {
1171 int mode;
1172 float mode_time;
1173
1174 vector ceiling_pos;
1175
1176 float last_fvi_check_time;
1177 float rot_speed;
1178 float speed;
1179 float sleep_speed;
1180 float sleep_rot_speed;
1181 bool done_turning;
1182 bool done_moving;
1183 vector home_pos;
1184 int home_room;
1185 vector home_fvec;
1186
1187 };
1188
1189 class Sickle : public BaseObjScript {
1190 private:
1191 sickle_data *memory;
1192 void SetMode(int me, char mode);
1193 void DoInit(int me_handle);
1194 void DoFrame(int me_handle);
1195 bool DoNotify(int me_handle, tOSIRISEVTAINOTIFY *notify);
1196
1197 public:
1198 Sickle() {}
1199 int16_t CallEvent(int event, tOSIRISEventInfo *data);
1200 };
1201
1202 //-----------------
1203 // Bouncing Betty
1204 //-----------------
1205
1206 struct tBettyBombInfo {
1207 bool explode;
1208 };
1209
1210 class BettyBomb : public BaseObjScript {
1211 public:
1212 BettyBomb() { memory = NULL; }
1213 int16_t CallEvent(int event, tOSIRISEventInfo *data);
1214
1215 private:
1216 tBettyBombInfo *memory;
1217 };
1218
1219 struct tBettyInfo {
1220 bool explode;
1221 float lasttime;
1222 };
1223
1224 class BettyScript : public BaseObjScript {
1225 public:
1226 BettyScript() { memory = NULL; }
1227 int16_t CallEvent(int event, tOSIRISEventInfo *data);
1228
1229 protected:
1230 void DoInit(int me);
1231
1232 private:
1233 tBettyInfo *memory;
1234 };
1235
1236 //-----------------
1237 // Chaff
1238 //-----------------
1239
1240 struct tChaffInfo {
1241 bool killme;
1242 };
1243
1244 class ChaffScript : public BaseObjScript {
1245 public:
1246 ChaffScript() { memory = NULL; }
1247 int16_t CallEvent(int event, tOSIRISEventInfo *data);
1248
1249 protected:
1250 void DoInit(int me);
1251 void DoInterval(int handle);
1252
1253 private:
1254 tChaffInfo *memory;
1255 };
1256
1257 struct tChaffChunkInfo {
1258 bool killme;
1259 float lifeleft;
1260 };
1261
1262 class ChaffChunkScript : public BaseObjScript {
1263 public:
1264 ChaffChunkScript() { memory = NULL; }
1265 int16_t CallEvent(int event, tOSIRISEventInfo *data);
1266
1267 protected:
1268 void DoInit(int me);
1269 void DoInterval(int handle, float time);
1270 void DoCollide(tOSIRISEventInfo *data);
1271
1272 private:
1273 tChaffChunkInfo *memory;
1274 };
1275
1276 //------------------
1277 // ProxMine class
1278 //------------------
1279
1280 class ProxMine : public BaseObjScript {
1281 private:
1282 void DoInit(int me);
1283 void DoCollide(int me);
1284
1285 public:
1286 ProxMine() {}
1287 int16_t CallEvent(int event, tOSIRISEventInfo *data);
1288 };
1289
1290 //------------------
1291 // Gunboy class
1292 //------------------
1293
1294 class Gunboy : public BaseObjScript {
1295 public:
1296 Gunboy() {}
1297 int16_t CallEvent(int event, tOSIRISEventInfo *data);
1298 };
1299
1300 //-----------------
1301 // GBPowerup
1302 //-----------------
1303
1304 struct gbpowerup_data {
1305 char type; // 0 - 5 matching up with the gb powerups!
1306 float next_check_time;
1307 float time_till_next_hud_message;
1308 };
1309
1310 class GBPowerup : public BaseObjScript {
1311 private:
1312 gbpowerup_data *memory;
1313 void DoInit(int me);
1314 void DoFrame(int me);
1315
1316 public:
1317 GBPowerup() {}
1318 int16_t CallEvent(int event, tOSIRISEventInfo *data);
1319 };
1320
1321 //-----------------
1322 // Josh Bell
1323 //-----------------
1324
1325 struct joshbell_data {
1326 int me;
1327 int attach_cage;
1328 float last_play_time;
1329 int bell_sound;
1330 };
1331
1332 class JoshBell : public BaseObjScript {
1333 private:
1334 joshbell_data *memory;
1335 void DoInit(int me);
1336 void DoCollide(int me);
1337
1338 public:
1339 JoshBell() {}
1340 int16_t CallEvent(int event, tOSIRISEventInfo *data);
1341 };
1342
1343 //-----------------
1344 // Explode On Contact
1345 //-----------------
1346
1347 class ExplodeOnContact : public BaseObjScript {
1348 private:
1349 void DoCollide(int me, int it_handle);
1350
1351 public:
1352 ExplodeOnContact() {}
1353 int16_t CallEvent(int event, tOSIRISEventInfo *data);
1354 };
1355
1356 //-----------------
1357 // Destroy On Contact
1358 //-----------------
1359
1360 class DestroyOnContact : public BaseObjScript {
1361 private:
1362 void DoCollide(int me, int it_handle);
1363
1364 public:
1365 DestroyOnContact() {}
1366 int16_t CallEvent(int event, tOSIRISEventInfo *data);
1367 };
1368
1369 //-----------------
1370 // GuideBot
1371 //-----------------
1372
1373 // Goal levels:
1374 #define GBL_AMBIENT 0 // Ambient movement and activities
1375 #define GBL_COMMAND 1 // Regular commands (like find powerup)
1376 #define GBL_OVERRIDE 2 // Overriding commands like (return to player) or putting out fires??? --chrishack
1377 #define GBL_MANDITORY 3 // Flying back to ship
1378
1379 #define GB_GUID_RTYPE_SUB_DIR_DONE 0x10010001
1380 #define GB_GUID_RETURNED_TO_PLAYER 0x10010002
1381 #define GB_GUID_AT_GOAL 0x10010003
1382
1383 // Modes
1384 #define GBM_IN_SHIP 0 // In the player ship
1385 #define GBM_AMBIENT 1 // Doing command or idling
1386 #define GBM_DOING_TASK 2 // -- might get rid of this one!!!!!!!!! I will just add a GBSM_ (doing task)
1387 #define GBM_KIDNAPPED 3
1388 #define GBM_TALKING 4
1389 #define GBM_THIEF 5
1390 #define GBM_ON_FIRE 6
1391 #define GBM_MANUAL 7
1392 #define GBM_RTYPE 8
1393 #define GBM_GO_WINGNUT 9
1394 #define GBM_EXTINGUISH 10
1395 #define GBM_BIRTH 11
1396 #define GBM_ENTER_SHIP 12
1397 #define GBM_RESPAWN_ENTER_SHIP 13
1398
1399 // Sub-modes for normal mode
1400 #define GBSM_NONE 0
1401 #define GBSM_OPEN_DOOR 1
1402 #define GBSM_GET_POWERUP 2
1403 #define GBSM_RETURNING 3
1404 #define GBSM_ANTI_VIRUS 4
1405
1406 #define GBF_VERY_DAMAGED 0x0001
1407 #define GBF_THIEF_REPEL 0x0002
1408 #define GBF_POW_SPEED 0x0004
1409 #define GBF_NO_CHATTER 0x0008
1410 #define GBF_SAW_BOSS 0x0010
1411 #define GBF_WANT_TO_EXTINGUISH 0x0020
1412 #define GBF_EXTINGUISHING 0x0040
1413 #define GBF_IN_CUSTOM_ANIM 0x0080
1414 #define GBF_WANT_TO_USE_ANTI_VIRUS 0x0100
1415 #define GBF_USING_ANTI_VIRUS 0x0200
1416 #define GBF_WANTING_TO_ENTER_PDEAD 0x0400
1417
1418 #define NUM_GB_COMMANDS 44
1419
1420 // Commands
1421 #define GBC_EXIT_SHIP 0
1422 #define GBC_REPAIR_GUIDEBOT 1
1423 #define GBC_RENAME 2
1424 #define GBC_FIND_ACTIVE_GOAL_0 3
1425 #define GBC_FIND_ACTIVE_GOAL_1 4
1426 #define GBC_FIND_ACTIVE_GOAL_2 5
1427 #define GBC_FIND_ACTIVE_GOAL_3 6
1428 #define GBC_FIND_ACTIVE_GOAL_4 7
1429 #define GBC_FIND_ACTIVE_GOAL_5 8
1430 #define GBC_FIND_ACTIVE_GOAL_6 9
1431 #define GBC_FIND_ACTIVE_GOAL_7 10
1432 #define GBC_FIND_ACTIVE_SEC_GOAL_0 11
1433 #define GBC_FIND_ACTIVE_SEC_GOAL_1 12
1434 #define GBC_FIND_ACTIVE_SEC_GOAL_2 13
1435 #define GBC_FIND_ACTIVE_SEC_GOAL_3 14
1436 #define GBC_FIND_ACTIVE_SEC_GOAL_4 15
1437 #define GBC_FIND_ACTIVE_SEC_GOAL_5 16
1438 #define GBC_FIND_ACTIVE_SEC_GOAL_6 17
1439 #define GBC_FIND_ACTIVE_SEC_GOAL_7 18
1440 #define GBC_FIND_SPEW 19
1441 #define GBC_FIND_POWERUP 20
1442 #define GBC_FIND_ENERGY_CENTER 21
1443 #define GBC_FIND_ROBOT 22
1444 #define GBC_FIND_THIEF 23
1445 #define GBC_FIND_OUTSIDE 24
1446 #define GBC_FIND_MINE 25
1447 #define GBC_FIND_CLOSEST_MARKER 26
1448 #define GBC_FIND_MARKER_0 27
1449 #define GBC_FIND_MARKER_1 28
1450 #define GBC_FIND_MARKER_2 29
1451 #define GBC_FIND_MARKER_3 30
1452 #define GBC_FIND_MARKER_4 31
1453 #define GBC_FIND_MARKER_5 32
1454 #define GBC_FIND_MARKER_6 33
1455 #define GBC_FIND_MARKER_7 34
1456 #define GBC_ESCORT_SHIP 35
1457 #define GBC_EXTINGUISH 36
1458 #define GBC_GO_WINGNUT 37
1459 #define GBC_TELEPRESENCE 38
1460 #define GBC_RTYPE 39
1461 #define GBC_ANTI_VIRUS 40
1462 #define GBC_ALLOW_CHATTER 41
1463 #define GBC_NO_CHATTER 42
1464 #define GBC_RETURN_TO_SHIP 43
1465 #define GBC_RENAME_SILENT 44
1466
1467 static int gb_command_text[NUM_GB_COMMANDS] = {
1468 TXT_GBM_EXITSHIP, TXT_GBM_REPAIR, TXT_GBM_RENAME, TXT_GBM_P0, TXT_GBM_P1,
1469 TXT_GBM_P2, TXT_GBM_P3, TXT_GBM_P4, TXT_GBM_P5, TXT_GBM_P6,
1470 TXT_GBM_P7, TXT_GBM_S0, TXT_GBM_S1, TXT_GBM_S2, TXT_GBM_S3,
1471 TXT_GBM_S4, TXT_GBM_S5, TXT_GBM_S6, TXT_GBM_S7, TXT_GBM_FINDPOWERUPS,
1472 TXT_GBM_FINEPOWERUP, TXT_GBM_FINDENERGY, TXT_GBM_FINDROBOT, TXT_GBM_FINDTHIEF, TXT_GBM_FINDEXIT,
1473 TXT_GBM_FINDMINE, TXT_GBM_FINDCMARK, TXT_GBM_M0, TXT_GBM_M1, TXT_GBM_M2,
1474 TXT_GBM_M3, TXT_GBM_M4, TXT_GBM_M5, TXT_GBM_M6, TXT_GBM_M7,
1475 TXT_GBM_ESCORT, TXT_GBM_USEEXTIN, TXT_GBM_WINGNUT, TXT_GBM_PILOTPOWER, TXT_GBM_GUARDIAN,
1476 TXT_GBM_ANTIVIRUS, TXT_GBM_ALLOWCHAT, TXT_GBM_DISALLOWCHAT, TXT_GBM_RETURNTOSHIP,
1477 };
1478
1479 // Speed is automatic
1480 #define NUM_GB_USABLE_POWERUPS 5
1481 #define NUM_GB_POWERUPS 6
1482 #define GB_POW_STRING_OFFSET GBC_EXTINGUISH
1483
1484 #define MAX_AV_ROBOTS 100
1485
1486 static int gb_pow_text[NUM_GB_POWERUPS] = {TXT_GBP_PUTOUTFIRE, TXT_GBP_COWABUNGA, TXT_GBP_BEGENTAL,
1487 TXT_GBP_LETSDOIT, TXT_GBP_CONVERTEN, TXT_GBP_ACCELERATOR};
1488
1489 static int gb_pow_not_text[NUM_GB_POWERUPS] = {TXT_GBPN_NOFIRE, TXT_GBPN_NOFIGHT, TXT_GBPN_GOPLAY,
1490 TXT_GBPN_TOODISSY, TXT_GBPN_NOENEMY, TXT_GBPN_NOCOFFEE};
1491
1492 static int gb_pow_pickup_text[NUM_GB_POWERUPS] = {TXT_GBPP_EXTIN, TXT_GBPP_WINGNUT, TXT_GBPP_MANCON,
1493 TXT_GBPP_GUARD, TXT_GBPP_ANTIV, TXT_GBPP_ACCEL};
1494
1495 #define GB_POW_FIRE 0
1496 #define GB_POW_WINGNUT 1
1497 #define GB_POW_MANUAL 2
1498 #define GB_POW_RTYPE 3
1499 #define GB_POW_ANTIVIRUS 4
1500 #define GB_POW_SPEED 5
1501
1502 #define NUM_GB_SOUNDS 5
1503 #define GBS_VERY_DAMAGED 0
1504 #define GBS_AMBIENT 1
1505
1506 // Extensions to the command interface
1507 #define COM_POWERUP_NOTIFY 4
1508 #define COM_POWERUP_PICKUP 5
1509
1510 struct guidebot_data {
1511 char name[8];
1512 char powerups[NUM_GB_USABLE_POWERUPS];
1513
1514 int sounds[NUM_GB_SOUNDS];
1515
1516 float mode_time;
1517
1518 uint16_t mp_slot; // Owner's slot number
1519 int my_player; // Owner's object reference
1520
1521 bool f_parented; // Buddy will not collide with parent until it isn't parented
1522 bool f_pickup; // Marked for pickup by the owner
1523
1524 int mode; // See above
1525 int sub_mode; // See above
1526
1527 char last_rtype_dir;
1528
1529 int g_powerup;
1530 int num_pg;
1531 int num_sg;
1532
1533 int camera_obj;
1534
1535 int last_command; // If negative, there is isn't any command
1536 float last_at_goal_time;
1537 float next_ambient_time; // Next time the ambient goal changes
1538
1539 float last_sound_time;
1540
1541 int flags;
1542
1543 float last_retreat_time;
1544 float return_time;
1545
1546 int me;
1547 float last_anim;
1548
1549 int extinguish_spew_id;
1550 int extinguish_obj_list[5];
1551 int num_extinguish_objs;
1552 float extinguish_obj_time;
1553
1554 float max_acc;
1555 float max_speed;
1556
1557 int num_av_robots;
1558 int av_robot_list[MAX_AV_ROBOTS];
1559 float av_revert_time[MAX_AV_ROBOTS];
1560
1561 float speed_time_left;
1562
1563 float time_till_next_pvis_check;
1564 float time_till_next_flare;
1565
1566 int amb_camera_handle;
1567
1568 float next_powerup_check_time;
1569 uint16_t powerup_ids[6];
1570 };
1571
1572 class GuideBot : public BaseObjScript {
1573 private:
1574 guidebot_data *memory;
1575 void DoMessage(const char *str, bool f_high_priority, const char *sound_name = NULL, bool f_sound_2d = false);
1576 // void InitPowerup(int me, char pow_id);
1577 // void DoPowerupFrame(int me);
1578 void DoPowerupCheck(int me);
1579 void ReInitAmbient(int me);
1580 bool InitExtinguish(bool f_player_on_fire);
1581 bool SetMode(int me, char mode);
1582 bool SetSubMode(int me, char sub_mode, int it = OBJECT_HANDLE_NONE);
1583 bool DoInit(int me_handle, bool f_reinit);
1584 void DoCollide(int me, tOSIRISEVTCOLLIDE *evt_collide);
1585 bool DoUse(int me);
1586 bool DoNotify(int me_handle, tOSIRISEventInfo *data);
1587 void DoFrame(int me_handle);
1588 bool DoExternalCommands(int me, gb_com *command, int it);
1589 int MakeCommandList(int *gbc_list);
1590 void AddGetToGoalCommonGoals(int me);
1591
1592 public:
1593 GuideBot() { memory = NULL; }
1594 int16_t CallEvent(int event, tOSIRISEventInfo *data);
1595 };
1596
1597 //-----------------
1598 // Thief
1599 //-----------------
1600
1601 #define THIEF_AMBIENT 0 // Roaming the mine
1602 #define THIEF_TRACK_PLAYER 1 // Getting to the player
1603 #define THIEF_STEAL 2 // Stealing an item (colliding with player)
1604 #define THIEF_RUN_AWAY 3 // In run-away mode
1605 #define THIEF_SURRENDER 4 // Surrender and then...
1606 #define THIEF_TIME_BOMB 5 // Go into bomb mode
1607 #define THIEF_PLAYER_DEATH_TAUNT 6 // Thief laughing at dead player
1608 #define THIEF_DEATH 7 // Thief dying
1609 #define THIEF_KIDNAP_GB 8 // Kipnapping the GB
1610 #define THIEF_CORNERED 9 // Cornered behavior
1611 #define THIEF_ATTACK 10 // Used by SUPER THIEF
1612
1613 #define THIEF_SUB_NONE 0 // Normal mode of operation
1614 #define THIEF_SUB_SUMMON 1 // Summon other robots
1615 #define THIEF_SUB_CLOAK 2 // Cloak effect
1616 #define THIEF_SUB_THROW_ITEM 3 // Throw an item from your insides(ewww)
1617 #define THIEF_SUB_GET_POWERUP 4 // Pickup a powerup
1618 #define THIEF_SUB_DROP_POWERUP 5 // Quick anim to drop an externally carried item
1619
1620 #define THIEF_F_SURRENDERED 1
1621 #define THIEF_F_GOT_POWERUP 2
1622
1623 // Chrishack make an "occurance" 2D table SUB vs MODE with float for chance per check interval
1624
1625 #define MAX_STOLEN_OBJS 5
1626 #define MAX_STOLEN_INV 10
1627
1628 #define THIEFABLEITEM_PRIMARY 0
1629 #define THIEFABLEITEM_SECONDARY 1
1630 #define THIEFABLEITEM_ACCESSORY 2
1631 struct tThiefItems {
1632 int index, type;
1633 float attempt_one, attempt_two, attempt_two_no_one;
1634 int name_idx;
1635 };
1636
1637 static tThiefItems ThiefableItems[] = {
1638 {0, THIEFABLEITEM_PRIMARY, 0.70f, 0.50f, 0.70f, TXT_WEAP_LASERS}, // Laser
1639 {1, THIEFABLEITEM_PRIMARY, 0.70f, 0.50f, 0.70f, TXT_WEAP_VAUSS}, // Vauss
1640 {2, THIEFABLEITEM_PRIMARY, 0.70f, 0.50f, 0.70f, TXT_WEAP_MICROWAVE}, // Microwave
1641 {3, THIEFABLEITEM_PRIMARY, 0.70f, 0.50f, 0.70f, TXT_WEAP_PLASMA}, // Plasma
1642 {4, THIEFABLEITEM_PRIMARY, 0.70f, 0.50f, 0.70f, TXT_WEAP_FUSION}, // Fusion
1643 {5, THIEFABLEITEM_PRIMARY, 0.70f, 0.50f, 0.70f, TXT_WEAP_SUPER}, // SuperLaser
1644 {6, THIEFABLEITEM_PRIMARY, 0.70f, 0.50f, 0.70f, TXT_WEAP_MASS}, // Mass Driver
1645 {7, THIEFABLEITEM_PRIMARY, 0.70f, 0.50f, 0.70f, TXT_WEAP_NAPALM}, // Napalm
1646 {8, THIEFABLEITEM_PRIMARY, 0.70f, 0.50f, 0.70f, TXT_WEAP_EMD}, // EMD Gun
1647 {9, THIEFABLEITEM_PRIMARY, 0.70f, 0.50f, 0.70f, TXT_WEAP_OMEGA}, // Omega
1648
1649 {10, THIEFABLEITEM_SECONDARY, 0.50f, 0.00f, 0.90f, TXT_WEAP_CONCUSSION}, // Concussion
1650 {11, THIEFABLEITEM_SECONDARY, 0.60f, 0.00f, 0.90f, TXT_WEAP_HOMING}, // Homing
1651 {12, THIEFABLEITEM_SECONDARY, 0.70f, 0.00f, 0.90f, TXT_WEAP_IMPACT}, // Impact Mortar
1652 {13, THIEFABLEITEM_SECONDARY, 0.80f, 0.00f, 0.90f, TXT_WEAP_SMART}, // Smart
1653 {14, THIEFABLEITEM_SECONDARY, 0.90f, 0.00f, 0.90f, TXT_WEAP_MEGA}, // Mega
1654 {15, THIEFABLEITEM_SECONDARY, 0.50f, 0.00f, 0.90f, TXT_WEAP_FRAG}, // Frag
1655 {16, THIEFABLEITEM_SECONDARY, 0.60f, 0.00f, 0.90f, TXT_WEAP_GUIDED}, // Guided
1656 {17, THIEFABLEITEM_SECONDARY, 0.70f, 0.00f, 0.90f, TXT_WEAP_NAPALMR}, // Napalm Rocket
1657 {18, THIEFABLEITEM_SECONDARY, 0.80f, 0.00f, 0.90f, TXT_WEAP_CYCLONE}, // Cyclone
1658 {19, THIEFABLEITEM_SECONDARY, 0.90f, 0.00f, 0.90f, TXT_WEAP_BLACKSHARK}, // Black Shark
1659
1660 {1, THIEFABLEITEM_ACCESSORY, 0.20f, 0.20f, 0.20f, TXT_WEAP_AUTOMAP}, // Automap
1661 {2, THIEFABLEITEM_ACCESSORY, 0.0f, 0.20f, 0.20f, TXT_WEAP_HEADLIGHT}, // Headlight
1662 {3, THIEFABLEITEM_ACCESSORY, 0.80f, 0.40f, 0.80f, TXT_WEAP_ETSCONVERTER}, // E2S Converter
1663 {4, THIEFABLEITEM_ACCESSORY, 1.00f, 0.60f, 1.00f, TXT_WEAP_CLOAK}, // Cloak
1664 {5, THIEFABLEITEM_ACCESSORY, 1.00f, 0.60f, 1.00f, TXT_WEAP_INVULNERABILITY}, // Invuln
1665 {6, THIEFABLEITEM_ACCESSORY, 1.00f, 0.60f, 1.00f, TXT_WEAP_RAPIDFIRE}, // RapidFire
1666 {7, THIEFABLEITEM_ACCESSORY, 1.00f, 0.60f, 1.00f, TXT_WEAP_QUADLASERS}, // Quads
1667 };
1668 static int numThiefableItems = sizeof(ThiefableItems) / sizeof(tThiefItems);
1669
1670 struct inv_item {
1671 uint16_t id;
1672 int owner;
1673 }; // not really inventory items, but items such as quads, automap, headlight, etc (non-weapons)
1674
1675 struct thief_data {
1676 char mode;
1677 char sub_mode;
1678 char last_special_sub_mode;
1679
1680 char flags;
1681
1682 char f_cloaked;
1683 char f_see_player;
1684
1685 float sub_mode_time;
1686 float mode_time;
1687 float next_test_time;
1688 float last_frame;
1689 int bomb_handle;
1690 float last_summon_time;
1691
1692 float last_shields;
1693
1694 int num_stolen_objs;
1695 int stolen_objs[MAX_STOLEN_OBJS];
1696
1697 int num_stolen_weapons;
1698 weapon_item stolen_weapons[MAX_STOLEN_WEAPONS];
1699
1700 int num_stolen_inv;
1701 inv_item stolen_inv[MAX_STOLEN_INV];
1702
1703 float fear;
1704 float agression;
1705
1706 };
1707
1708 class Thief : public BaseObjScript {
1709 private:
1710 thief_data *memory;
1711 void DoMessage(const char *str);
1712
1713 void SetMode(int me, int mode);
1714 void SetSubMode(int me, int submode);
1715
1716 void SpewEverything(int me);
1717 void DoAttack(int me, int it);
1718 bool DoSteal(int me, int it, int attempt_num, bool f_last_success);
1719 void DoKidnap(int me, int it);
1720
1721 void DoInit(int me_handle);
1722 void DoCollide(int me, tOSIRISEVTCOLLIDE *evt_collide);
1723 bool DoNotify(int me, tOSIRISEVTAINOTIFY *notify);
1724 void DoDestroy(int me, tOSIRISEVTDESTROY *evt_destroy);
1725 void DoFrame(int me);
1726 void DoSubModeFrame(int me);
1727
1728 public:
1729 Thief() {}
1730 int16_t CallEvent(int event, tOSIRISEventInfo *data);
1731 };
1732
1733 //-----------------
1734 // SuperThief
1735 //-----------------
1736
1737 struct tSuperThiefItems {
1738 int index, autoselect, type;
1739 float fire_delay;
1740 int name_idx;
1741 const char *weapon_name;
1742 const char *fire_sound;
1743 };
1744
1745 static tSuperThiefItems SuperThiefableItems[] = {
1746 {0, -1, THIEFABLEITEM_PRIMARY, .25, TXT_WEAP_LASERS, "", ""}, // Laser
1747 {1, 4, THIEFABLEITEM_PRIMARY, .1f, TXT_WEAP_VAUSS, "Vauss", "WpnPyroGLVaussSidefire"}, // Vauss
1748 {2, 2, THIEFABLEITEM_PRIMARY, .1f, TXT_WEAP_MICROWAVE, "Raygun", "WpnPyroGLMicrowaveSide"}, // Microwave
1749 {3, 3, THIEFABLEITEM_PRIMARY, .15f, TXT_WEAP_PLASMA, "Plasma", "WpnPyroGLPlasmaFire"}, // Plasma
1750 {4, 5, THIEFABLEITEM_PRIMARY, .8f, TXT_WEAP_FUSION, "Fusion", "WpnPyroGLFusionFire"}, // Fusion
1751 {5, 6, THIEFABLEITEM_PRIMARY, .25f, TXT_WEAP_SUPER, "Laser Level 5 -Yellow", "WpnPyroGLSuperLaser"}, // SuperLaser
1752 {6, 7, THIEFABLEITEM_PRIMARY, 1.0f, TXT_WEAP_MASS, "Mass Driver", "WpnPyroGLMDriverFire"}, // Mass Driver
1753 {7, -1, THIEFABLEITEM_PRIMARY, 1.0f, TXT_WEAP_NAPALM, "", ""}, // Napalm
1754 {8, 1, THIEFABLEITEM_PRIMARY, .2f, TXT_WEAP_EMD, "EMDblob", "WpnPyroGLEMDfire"}, // EMD Gun
1755 {9, -1, THIEFABLEITEM_PRIMARY, 1.0f, TXT_WEAP_OMEGA, "", ""}, // Omega
1756
1757 {10, 1, THIEFABLEITEM_SECONDARY, .2f, TXT_WEAP_CONCUSSION, "Concussion", "concmissilefire71"}, // Concussion
1758 {11, 2, THIEFABLEITEM_SECONDARY, .2f, TXT_WEAP_HOMING, "homing", "HomingfireB1"}, // Homing
1759 {12, -1, THIEFABLEITEM_SECONDARY, .2f, TXT_WEAP_IMPACT, "Impact Mortar", "Drop weapon"}, // Impact Mortar
1760 {13, 3, THIEFABLEITEM_SECONDARY, .2f, TXT_WEAP_SMART, "Smart", "Smartfire1"}, // Smart
1761 {14, 8, THIEFABLEITEM_SECONDARY, .2f, TXT_WEAP_MEGA, "Mega", "Mega missile fire"}, // Mega
1762 {15, 6, THIEFABLEITEM_SECONDARY, .2f, TXT_WEAP_FRAG, "Frag", "WpnFragFire"}, // Frag
1763 {16, 4, THIEFABLEITEM_SECONDARY, .2f, TXT_WEAP_GUIDED, "Guided", "Guided31"}, // Guided
1764 {17, 5, THIEFABLEITEM_SECONDARY, .2f, TXT_WEAP_NAPALMR, "NapalmRocket", "napalmrocket31"}, // Napalm Rocket
1765 {18, 7, THIEFABLEITEM_SECONDARY, .2f, TXT_WEAP_CYCLONE, "Cyclone Pack", "CycloneFire1"}, // Cyclone
1766 {19, -1, THIEFABLEITEM_SECONDARY, .2f, TXT_WEAP_BLACKSHARK, "", ""}, // Black Shark
1767 };
1768
1769 static int numSuperThiefableItems = sizeof(SuperThiefableItems) / sizeof(tSuperThiefItems);
1770
1771 #define SUPERTHIEF_MELEE_DIST 50.0f
1772
1773 void SuperThief::SetMode(int me, char mode) {
1774 AI_SetType(me, AIT_AIS);
1775
1776 switch (mode) {
1777 case SUPERTHIEF_WAIT: {
1778 } break;
1779
1780 case SUPERTHIEF_INTRO: {
1781 } break;
1782 case SUPERTHIEF_RANGED:
1783 AI_SetType(me, AIT_EVADER1);
1784 break;
1785 case SUPERTHIEF_MELEE:
1786 AI_SetType(me, AIT_MELEE1);
1787 break;
1788 case SUPERTHIEF_DEATH: {
1789 int flags = AIF_DODGE;
1790 AI_Value(me, VF_CLEAR_FLAGS, AIV_I_FLAGS, &flags);
1791
1792 flags = AIF_DISABLE_FIRING | AIF_DISABLE_MELEE;
1793 AI_Value(me, VF_SET_FLAGS, AIV_I_FLAGS, &flags);
1794
1795 AI_AddGoal(me, AIG_GET_TO_OBJ, 1, 1.0f, -1, GF_ORIENT_TARGET | GF_KEEP_AT_COMPLETION, me);
1796
1797 float temp = 0.0f;
1798 AI_Value(me, VF_SET, AIV_F_MAX_TURN_RATE, &temp);
1799 Obj_SetCustomAnim(me, 246.0f, 292.0f, 6.0f, 0, Sound_FindId("RbtThiefDeath"), -1);
1800 } break;
1801 }
1802
1803 memory->time_till_fire_secondary = 1.0f + (float)rand() / (float)RAND_MAX;
1804 memory->mode = mode;
1805 memory->mode_time = 0.0f;
1806 }
1807
1808 void SuperThief::SpewEverything(int me) {
1809 int i;
1810 int powerup_handle;
1811 int room;
1812 vector pos;
1813
1814 Obj_Value(me, VF_GET, OBJV_I_ROOMNUM, &room);
1815 Obj_Value(me, VF_GET, OBJV_V_POS, &pos);
1816
1817 for (i = 0; i < memory->num_stolen_weapons; i++) {
1818 uint16_t id;
1819 int j;
1820
1821 for (j = 0; j < memory->stolen_weapons[i].amount; j++) {
1822 float speed = rand() / (float)RAND_MAX * 20.0f + 5.0f;
1823 vector dir;
1824
1825 dir.x = rand() / (float)RAND_MAX - 0.5f;
1826 dir.y = rand() / (float)RAND_MAX - 0.5f;
1827 dir.z = rand() / (float)RAND_MAX - 0.5f;
1828
1829 vm_VectorNormalize(&dir);
1830 dir *= speed;
1831
1832 Player_Value(memory->stolen_weapons[i].owner, VF_GET, PLYSV_US_WEAPON_POWERUP_ID, &id,
1833 memory->stolen_weapons[i].index);
1834 powerup_handle = Obj_Create(OBJ_POWERUP, id, room, &pos, NULL, OBJECT_HANDLE_NONE, &dir);
1835 }
1836
1837 memory->stolen_weapons[i].amount = 0;
1838 }
1839 }
1840
1841 bool SuperThief::DoNotify(int me, tOSIRISEVTAINOTIFY *notify) {
1842 if (notify->notify_type == AIN_MELEE_HIT) {
1843 int target_handle;
1844 int target_type;
1845
1846 AI_Value(me, VF_GET, AIV_I_TARGET_HANDLE, &target_handle);
1847 Obj_Value(target_handle, VF_GET, OBJV_I_TYPE, &target_type);
1848
1849 if (target_type == OBJ_PLAYER) {
1850 bool f_success;
1851
1852 memory->time_till_fire_secondary = 1.0f + (float)rand() / (float)RAND_MAX;
1853 f_success = DoSteal(me, target_handle);
1854 }
1855 }
1856
1857 switch (memory->mode) {
1858 case SUPERTHIEF_WAIT: {
1859 if (notify->notify_type == AIN_MOVIE_START) {
1860 SetMode(me, SUPERTHIEF_INTRO);
1861 }
1862 } break;
1863
1864 case SUPERTHIEF_INTRO: {
1865 if (notify->notify_type == AIN_MOVIE_END) {
1866 SetMode(me, SUPERTHIEF_RANGED);
1867 }
1868 }
1869 }
1870
1871 return true;
1872 }
1873
1874 bool SuperThief::DoSteal(int me, int it) {
1875 int max_tries = numSuperThiefableItems;
1876 float gen_perc, perc_chance;
1877 ;
1878 int i;
1879 int count_max, count_num;
1880 bool *attempted_steals;
1881
1882 attempted_steals = (bool *)malloc(numSuperThiefableItems * sizeof(bool));
1883 if (!attempted_steals)
1884 return false;
1885
1886 float ftime = Game_GetFrameTime();
1887 if (ftime == 0)
1888 ftime = 1.0f;
1889 srand(Game_GetTime() / ftime);
1890
1891 for (i = 0; i < numSuperThiefableItems; i++) {
1892 attempted_steals[i] = false;
1893 }
1894
1895 while (max_tries--) {
1896 i = rand() % numSuperThiefableItems;
1897
1898 if (attempted_steals[i]) {
1899 // we already tried this one, try another
1900 max_tries++;
1901 continue;
1902 }
1903
1904 attempted_steals[i] = true;
1905
1906 {
1907 count_max = MAX_STOLEN_WEAPONS;
1908 count_num = memory->num_stolen_weapons;
1909
1910 if (count_num >= count_max) {
1911 mprintf(0, "SUPER THIEF: no mo' room\n");
1912 continue; // we have no more room
1913 }
1914
1915 // mprintf(0,"THIEF: Checking %s\n",TXT(SuperThiefableItems[i].name_idx));
1916
1917 bool can_take = false;
1918 int amount = 0;
1919 char message[256];
1920
1921 switch (SuperThiefableItems[i].type) {
1922 case THIEFABLEITEM_PRIMARY:
1923 // check to see if we can steal the primary
1924 Player_Value(it, VF_GET, PLYSV_I_WEAPON, &amount, SuperThiefableItems[i].index);
1925 if (SuperThiefableItems[i].index != 0 && amount) {
1926 can_take = true;
1927 snprintf(message, sizeof(message), TXT_THIEFSTEAL, TXT(SuperThiefableItems[i].name_idx));
1928 }
1929 break;
1930
1931 case THIEFABLEITEM_SECONDARY:
1932 // check to see if we can steal the secondary
1933 {
1934 Player_Value(it, VF_GET, PLYSV_I_WEAPON, &amount, SuperThiefableItems[i].index);
1935
1936 if (amount) {
1937 int max;
1938
1939 if (SuperThiefableItems[i].index > 14) {
1940 // 2nd selection group (black shark, etc)
1941 max = (19 - SuperThiefableItems[i].index) / 2.5f + 1;
1942 } else {
1943 // 1st selection group (mega, etc)
1944 max = (14 - SuperThiefableItems[i].index) / 2.5f + 1;
1945 }
1946
1947 int new_amount = (rand() / (float)(RAND_MAX + 1)) * max + 1;
1948
1949 if (new_amount < amount)
1950 amount = new_amount;
1951
1952 can_take = true;
1953
1954 if (amount == 1) {
1955 snprintf(message, sizeof(message), TXT_STHIEFSTEAL, TXT(SuperThiefableItems[i].name_idx));
1956 } else {
1957 snprintf(message, sizeof(message), TXT_STHIEFSTEAL2, amount, TXT(SuperThiefableItems[i].name_idx));
1958 }
1959 }
1960 }
1961 break;
1962 }
1963
1964 if (!can_take)
1965 continue;
1966
1967 mprintf(0, "Super Thief: Nice %s!\n", TXT(SuperThiefableItems[i].name_idx));
1968
1969 Player_AddHudMessage(it, message);
1970 if (rand() % 50) {
1971 Sound_Play3d(me, Sound_FindId("RbtThiefHehHehHeh"));
1972 } else {
1973 Sound_Play3d(me, Sound_FindId("RbtThiefLaugh"));
1974 }
1975
1976 memory->stolen_weapons[memory->num_stolen_weapons].index = SuperThiefableItems[i].index;
1977 memory->stolen_weapons[memory->num_stolen_weapons].owner = it;
1978 memory->stolen_weapons[memory->num_stolen_weapons].amount = amount;
1979 memory->num_stolen_weapons++;
1980
1981 if (SuperThiefableItems[i].type == THIEFABLEITEM_PRIMARY) {
1982 amount = 0;
1983 if (SuperThiefableItems[i].autoselect > memory->cur_weapon) {
1984 uint16_t wpn = Wpn_FindID(SuperThiefableItems[i].weapon_name);
1985 int snd = Sound_FindId(SuperThiefableItems[i].fire_sound);
1986
1987 Obj_WBValue(me, 1, VF_SET, WBSV_I_FIRE_SOUND, &snd, 0);
1988 Obj_WBValue(me, 1, VF_SET, WBSV_F_LATENCY, &SuperThiefableItems[i].fire_delay, 0);
1989 Obj_WBValue(me, 1, VF_SET, WBSV_US_GUNPT_WEAPON_ID, &wpn, 0);
1990
1991 strcpy(memory->weapon, SuperThiefableItems[i].weapon_name);
1992 strcpy(memory->sound, SuperThiefableItems[i].weapon_name);
1993 memory->latency = SuperThiefableItems[i].fire_delay;
1994 }
1995 } else {
1996 amount *= -1;
1997 }
1998
1999 Player_Value(it, VF_SET, PLYSV_I_WEAPON, &amount, SuperThiefableItems[i].index);
2000
2001 free(attempted_steals);
2002 return true;
2003 }
2004 }
2005
2006 mprintf(0, "Super Thief: Not taking anything\n");
2007 free(attempted_steals);
2008 return false; // we didn't take anything this try
2009 }
2010
2011 void SuperThief::DoInit(int me) {
2012 tOSIRISMEMCHUNK ch;
2013 ch.id = 4;
2014 ch.size = sizeof(superthief_data);
2015 ch.my_id.type = OBJECT_SCRIPT;
2016 ch.my_id.objhandle = me;
2017
2018 memory = (superthief_data *)Scrpt_MemAlloc(&ch);
2019
2020 msafe_struct m;
2021 m.objhandle = me;
2022 MSafe_GetValue(MSAFE_OBJECT_SHIELDS, &m);
2023
2024 memory->next_mode_time = Game_GetTime() + ((float)rand() / (float)RAND_MAX) * 3.0f + 3.0f;
2025 memory->force_ranged_shields = m.shields / 15.0f;
2026 memory->mode = SUPERTHIEF_WAIT;
2027 memory->f_very_hurt = 0;
2028
2029 memory->num_stolen_weapons = 0;
2030 memory->cur_weapon = -1;
2031
2032 memory->mode_time = 0.0f;
2033 memory->last_frame = 0.0f;
2034 memory->time_till_fire_secondary = 1.0f + (float)rand() / (float)RAND_MAX;
2035
2036 memory->laser_obj = CreateAndAttach(me, "STEmitter", OBJ_ROBOT, 2, 0, true, true);
2037
2038 uint16_t wpn = Wpn_FindID("Laser Level 1 - Red");
2039 int snd = Sound_FindId("Laser level 1");
2040
2041 strcpy(memory->weapon, "Laser Level 1 - Red");
2042 strcpy(memory->sound, "Laser level 1");
2043
2044 memory->latency = 0.25f;
2045
2046 memory->laser_on = false;
2047
2048 memory->next_fire_flare_time = 0.0f;
2049 memory->flare_fire_index = 0;
2050
2051 Obj_WBValue(me, 1, VF_SET, WBSV_I_FIRE_SOUND, &snd, 0);
2052 Obj_WBValue(me, 1, VF_SET, WBSV_F_LATENCY, &memory->latency, 0);
2053 Obj_WBValue(me, 1, VF_SET, WBSV_US_GUNPT_WEAPON_ID, &wpn, 0);
2054 }
2055
2056 void SuperThief::FireFlare(int me) {
2057 msafe_struct mstruct;
2058
2059 mstruct.objhandle = me;
2060 mstruct.index = Wpn_FindID("Yellow flare");
2061 if (mstruct.index == -1)
2062 return;
2063 mstruct.gunpoint = 1;
2064
2065 Sound_Play3d(me, Sound_FindId("Flare"));
2066
2067 MSafe_CallFunction(MSAFE_OBJECT_FIRE_WEAPON, &mstruct);
2068 }
2069
2070 void SuperThief::CheckAndFireSecondary(int me) {
2071 int i;
2072 const char *wname;
2073 const char *sname;
2074 int best_select = -1;
2075 int best_index;
2076
2077 for (i = 0; i < memory->num_stolen_weapons; i++) {
2078 if (memory->stolen_weapons[i].amount > 0 &&
2079 SuperThiefableItems[memory->stolen_weapons[i].index].type == THIEFABLEITEM_SECONDARY) {
2080 if (best_select < SuperThiefableItems[memory->stolen_weapons[i].index].autoselect) {
2081 wname = SuperThiefableItems[memory->stolen_weapons[i].index].weapon_name;
2082 sname = SuperThiefableItems[memory->stolen_weapons[i].index].fire_sound;
2083 best_select = SuperThiefableItems[memory->stolen_weapons[i].index].autoselect;
2084 best_index = i;
2085 }
2086 }
2087 }
2088
2089 if (best_select >= 0) {
2090 memory->stolen_weapons[best_index].amount--;
2091
2092 msafe_struct mstruct;
2093
2094 mstruct.objhandle = me;
2095 mstruct.index = Wpn_FindID(wname);
2096 if (mstruct.index == -1)
2097 return;
2098 mstruct.gunpoint = 1;
2099
2100 Sound_Play3d(me, Sound_FindId(sname));
2101
2102 MSafe_CallFunction(MSAFE_OBJECT_FIRE_WEAPON, &mstruct);
2103 }
2104 }
2105
2106 void SuperThief::DoInterval(int me) {
2107 bool f_force_ranged = false;
2108 int target_handle;
2109 float anim_frame;
2110 float shields;
2111 int flags;
2112 msafe_struct m;
2113 int room;
2114 vector pos;
2115
2116 Obj_Value(me, VF_GET, OBJV_I_ROOMNUM, &room);
2117 Obj_Value(me, VF_GET, OBJV_V_POS, &pos);
2118 Obj_Value(me, VF_GET, OBJV_F_ANIM_FRAME, &anim_frame);
2119 Obj_Value(me, VF_GET, OBJV_F_SHIELDS, &shields);
2120 Obj_Value(me, VF_GET, OBJV_I_FLAGS, &flags);
2121
2122 if (memory->laser_on) {
2123 ray_info ray;
2124
2125 matrix orient;
2126 Obj_Value(me, VF_GET, OBJV_M_ORIENT, &orient);
2127
2128 // Determine real start pos - room
2129 vector end_pos = pos;
2130 end_pos += orient.fvec * 2000.0f;
2131
2132 int fvi_flags = FQ_CHECK_OBJS | FQ_IGNORE_POWERUPS | FQ_IGNORE_WEAPONS;
2133 int fate = FVI_RayCast(me, &pos, &end_pos, room, 0.0f, fvi_flags, &ray);
2134
2135 Obj_Value(memory->camera_obj, VF_SET, OBJV_I_ROOMNUM, &ray.hit_room);
2136 Obj_Value(memory->camera_obj, VF_SET, OBJV_V_POS, &ray.hit_point);
2137 }
2138
2139 memory->f_very_hurt = f_force_ranged = (shields < memory->force_ranged_shields) != 0;
2140
2141 if ((memory->mode != SUPERTHIEF_DEATH) && (flags & OF_AI_DEATH) && anim_frame >= 0.0f && anim_frame <= 6.0f) {
2142 mprintf(0, "ST: Dying\n");
2143 SetMode(me, SUPERTHIEF_DEATH);
2144 }
2145
2146 if (memory->mode == SUPERTHIEF_DEATH) {
2147 // Do dynamic death
2148 if ((memory->mode_time < 4.0f && memory->mode_time + Game_GetFrameTime() >= 4.0f) ||
2149 (memory->mode_time < 6.0f && memory->mode_time + Game_GetFrameTime() >= 6.0f)) {
2150 int weapon_id;
2151
2152 weapon_id = Wpn_FindID("TubbsHitBlast");
2153 Obj_Create(OBJ_WEAPON, weapon_id, room, &pos, NULL, me);
2154 }
2155
2156 if (memory->mode_time < 3.0f && memory->mode_time + Game_GetFrameTime() >= 3.0f) {
2157 Obj_Burning(me, 1000000.0f, 1.0f);
2158 }
2159
2160 if (memory->mode_time > 6.2f) {
2161 mprintf(0, "ST: Died\n");
2162 Obj_Kill(me, OBJECT_HANDLE_NONE, 1000.0f,
2163 DF_BLAST_RING | DF_LOSES_ANTIGRAV | DF_EXPL_LARGE | DF_FIREBALL | DF_BREAKS_APART | DF_DEBRIS_SMOKES,
2164 0.0f, 0.0f);
2165 }
2166 } else if (memory->mode == SUPERTHIEF_INTRO) {
2167 if (memory->mode_time < 6.0f && memory->mode_time + Game_GetFrameTime() >= 6.0f) {
2168 int flags = AIF_FORCE_AWARENESS | AIF_DETERMINE_TARGET;
2169 AI_Value(me, VF_SET_FLAGS, AIV_I_FLAGS, &flags);
2170
2171 float awareness = AWARE_FULLY;
2172 AI_Value(me, VF_SET, AIV_F_AWARENESS, &awareness);
2173 }
2174
2175 if (memory->last_frame < 234.0f && anim_frame >= 234.0f) {
2176 msafe_struct mstruct;
2177 int type;
2178
2179 memory->laser_on = true;
2180 memory->camera_obj = Obj_Create(OBJ_POWERUP, Obj_FindID("Invisiblepowerup"), room, &pos, NULL, me);
2181 mstruct.objhandle = memory->camera_obj;
2182 MSafe_CallFunction(MSAFE_OBJECT_NO_RENDER, &mstruct);
2183
2184 Obj_Value(me, VF_GET, OBJV_I_ROOMNUM, &mstruct.roomnum);
2185 Obj_Value(me, VF_GET, OBJV_V_POS, &mstruct.pos);
2186 Obj_Value(memory->camera_obj, VF_GET, OBJV_V_POS, &mstruct.pos2);
2187
2188 mstruct.objhandle = memory->laser_obj;
2189 mstruct.ithandle = memory->camera_obj;
2190 mstruct.lifetime = 10000000.0f;
2191 mstruct.size = 1.0f;
2192
2193 mstruct.interval = 1.0f;
2194 mstruct.count = 2;
2195 mstruct.index = 1;
2196 mstruct.texnum = Scrpt_FindTextureName("Stlaser");
2197 mstruct.color = ((128 >> 3) << 10) | ((128 >> 3) << 5) | (128 >> 3);
2198
2199 mstruct.state = 0;
2200 mstruct.flags = 0;
2201
2202 MSafe_CallFunction(MSAFE_WEATHER_LIGHTNING_BOLT, &mstruct);
2203 }
2204 } else if (memory->mode == SUPERTHIEF_WAIT) {
2205 } else {
2206 // Put the mod stuff here!
2207
2208 if (memory->mode == SUPERTHIEF_RANGED) {
2209 memory->time_till_fire_secondary -= Game_GetFrameTime();
2210 float last_see_time;
2211 float last_hear_time;
2212 AI_Value(me, VF_GET, AIV_F_LAST_SEE_TARGET_TIME, &last_see_time);
2213 AI_Value(me, VF_GET, AIV_F_LAST_HEAR_TARGET_TIME, &last_hear_time);
2214
2215 if (memory->next_fire_flare_time < Game_GetTime() && last_see_time + 7.0f >= Game_GetTime() &&
2216 last_hear_time + 7.0f >= Game_GetTime()) {
2217 FireFlare(me);
2218 memory->flare_fire_index++;
2219
2220 if (memory->flare_fire_index >= 3) {
2221 memory->flare_fire_index = 0;
2222 memory->next_fire_flare_time = Game_GetTime() + (rand() / (float)RAND_MAX) * 10.0f + 5.0f;
2223 } else {
2224 memory->next_fire_flare_time = Game_GetTime() + .75f;
2225 }
2226 }
2227
2228 if (memory->time_till_fire_secondary < 0.0f) {
2229 memory->time_till_fire_secondary = 1.0f + (float)rand() / (float)RAND_MAX;
2230 CheckAndFireSecondary(me);
2231 }
2232 }
2233
2234 if ((!f_force_ranged) && (memory->next_mode_time < Game_GetTime())) {
2235 if (memory->mode == SUPERTHIEF_MELEE) {
2236 AI_SetType(me, AIT_EVADER1);
2237 memory->mode = SUPERTHIEF_RANGED;
2238 } else if ((rand() % 150) > 20) {
2239 AI_SetType(me, AIT_MELEE1);
2240 memory->mode = SUPERTHIEF_MELEE;
2241 }
2242
2243 if (memory->mode == SUPERTHIEF_RANGED)
2244 memory->next_mode_time = Game_GetTime() + 5.0f + ((float)rand() / (float)RAND_MAX) * 3.0f;
2245 else
2246 memory->next_mode_time = Game_GetTime() + 3.0f + ((float)rand() / (float)RAND_MAX) * 3.0f;
2247 } else if ((f_force_ranged) && (memory->mode != SUPERTHIEF_RANGED)) {
2248 // PlaySoundObj3d("RbtStingeattack1", me)
2249 AI_SetType(me, AIT_EVADER1);
2250 memory->mode = SUPERTHIEF_RANGED;
2251 }
2252 }
2253
2254 memory->last_frame = anim_frame;
2255 memory->mode_time += Game_GetFrameTime();
2256 }
2257
2258 int16_t SuperThief::CallEvent(int event, tOSIRISEventInfo *data) {
2259 switch (event) {
2260 case EVT_AI_INIT:
2261 DoInit(data->me_handle);
2262 break;
2263 case EVT_AI_FRAME:
2264 DoInterval(data->me_handle);
2265 break;
2266 case EVT_AI_NOTIFY:
2267 return (DoNotify(data->me_handle, &data->evt_ai_notify) != false) ? CONTINUE_CHAIN | CONTINUE_DEFAULT : 0;
2268 break;
2269 case EVT_DESTROY: {
2270 SpewEverything(data->me_handle);
2271 msafe_struct mo;
2272 mo.objhandle = memory->laser_obj;
2273 MSafe_CallFunction(MSAFE_OBJECT_REMOVE, &mo);
2274 mo.objhandle = memory->camera_obj;
2275 MSafe_CallFunction(MSAFE_OBJECT_REMOVE, &mo);
2276 } break;
2277 case EVT_MEMRESTORE: {
2278 memory = (superthief_data *)data->evt_memrestore.memory_ptr;
2279
2280 uint16_t wpn = Wpn_FindID(memory->weapon);
2281 int snd = Sound_FindId(memory->sound);
2282
2283 Obj_WBValue(data->me_handle, 1, VF_SET, WBSV_I_FIRE_SOUND, &snd, 0);
2284 Obj_WBValue(data->me_handle, 1, VF_SET, WBSV_F_LATENCY, &memory->latency, 0);
2285 Obj_WBValue(data->me_handle, 1, VF_SET, WBSV_US_GUNPT_WEAPON_ID, &wpn, 0);
2286 } break;
2287 }
2288 return CONTINUE_CHAIN | CONTINUE_DEFAULT;
2289 }
2290
2291 //-----------------
2292 // FireAtDist
2293 //-----------------
2294
2295 struct fireatdist_data {
2296 int me;
2297 float fire_dist;
2298 float last_test_time;
2299 bool last_f_fire;
2300 };
2301
2302 class FireAtDist : public BaseObjScript {
2303 private:
2304 fireatdist_data *memory;
2305 void DoInit(int me_handle);
2306 void DoFrame(int me_handle);
2307
2308 public:
2309 FireAtDist() {}
2310 int16_t CallEvent(int event, tOSIRISEventInfo *data);
2311 };
2312
2313 //-----------------
2314 // HatePTMC
2315 //-----------------
2316
2317 struct hateptmc_data {
2318 int me;
2319 float time_till_pulse;
2320 };
2321
2322 class HatePTMC : public BaseObjScript {
2323 private:
2324 hateptmc_data *memory;
2325 void DoInit(int me_handle);
2326 void DoFrame(int me_handle);
2327
2328 public:
2329 HatePTMC() {}
2330 int16_t CallEvent(int event, tOSIRISEventInfo *data);
2331 };
2332
2333 //-----------------
2334 // Tubbs
2335 //-----------------
2336
2337 struct tubbs_data {
2338 float base_speed;
2339 float base_acc;
2340 float max_speed;
2341 float max_acc;
2342 float full_anger_time;
2343 };
2344
2345 class Tubbs : public BaseObjScript {
2346 private:
2347 tubbs_data *memory;
2348 void DoInit(int me);
2349 void DoFrame(int me);
2350 bool DoNotify(int me, tOSIRISEVTAINOTIFY *notify);
2351
2352 public:
2353 Tubbs() {}
2354 int16_t CallEvent(int event, tOSIRISEventInfo *data);
2355 };
2356
2357 //-----------------
2358 // Old Scratch
2359 //-----------------
2360
2361 struct oldscratch_data {
2362 float base_speed;
2363 float base_acc;
2364 float max_speed;
2365 float max_acc;
2366 float full_anger_time;
2367 };
2368
2369 class OldScratch : public BaseObjScript {
2370 private:
2371 oldscratch_data *memory;
2372 bool DoSteal(int me, int it);
2373 void DoInit(int me);
2374 void DoFrame(int me);
2375 bool DoNotify(int me, tOSIRISEVTAINOTIFY *notify);
2376
2377 public:
2378 OldScratch() {}
2379 int16_t CallEvent(int event, tOSIRISEventInfo *data);
2380 };
2381
2382 //-----------------
2383 // BarnSwallow
2384 //-----------------
2385
2386 #define BSM_NEST 0
2387 #define BSM_FOLLOW 1
2388 #define BSM_GET_POWERUP 2
2389 #define BSM_ATTACK 3
2390 #define BSM_ATTACK_CIRCLE_BACK 4
2391 #define BSM_FLEE 5
2392 #define BSM_RETURN_TO_NEST 6
2393
2394 #define BSCOMM_FOLLOW_ME 0 // send a percent chance so we can have a line sometimes
2395 #define BSCOMM_FOLLOW_CANCEL_FROM_FOLLOWER 1
2396 #define BSCOMM_FOLLOW_CANCEL_FROM_LEADER 2
2397 #define BSCOMM_ATTACK_MY_TARGET 3
2398 #define BSCOMM_ARE_YOU_IN_MODE 4
2399 #define BSCOMM_ARE_YOU_AFTER_POWERUP 5
2400
2401 #define BSF_HAVE_POWERUP 1
2402 #define BSF_ACCEPT_ORDER 2 // clear it before the call...
2403
2404 #define BS_MAX_FRIENDS 20
2405
2406 struct barnswallow_data {
2407 int home_room;
2408 vector nest_center;
2409 float nest_rad;
2410
2411 int follower;
2412
2413 char num_friends;
2414 int friends[BS_MAX_FRIENDS];
2415 float next_friend_update_time;
2416
2417 char mode;
2418 char last_non_attack_mode;
2419
2420 float mode_time;
2421 float next_mode_time;
2422 float next_attack_time;
2423 float next_powerup_time;
2424 float max_time_on_road;
2425 int powerup_id;
2426
2427 int flags;
2428 };
2429
2430 class BarnSwallow : public BaseObjScript {
2431 private:
2432 barnswallow_data *memory;
2433 void DoInit(int me);
2434 bool SendCommand(int me, int it, char command, int value = 0);
2435 bool ReceiveCommand(int me, int it, gb_com *command);
2436 void ComputeNextNestPnt(int me, vector *pos);
2437 bool DoNotify(int me, tOSIRISEventInfo *data);
2438 void ComputeNest(int me);
2439 void UpdateFriendList(int me);
2440 void DoFrame(int me);
2441 bool SetMode(int me, char mode, int it = OBJECT_HANDLE_NONE);
2442
2443 public:
2444 BarnSwallow() {}
2445 int16_t CallEvent(int event, tOSIRISEventInfo *data);
2446 };
2447
2448 //----------------
2449 // Standard stuff
2450 //----------------
2451
2452 // SaveRestoreState
2453 // Purpose:
2454 // This function is called when Descent 3 is saving or restoring the game state. In this function
2455 // you should save/restore any global data that you want preserved through load/save (which includes
2456 // demos). You must be very careful with this function, corrupting the file (reading or writing too
2457 // much or too little) may be hazardous to the game (possibly making it impossible to restore the
2458 // state). It would be best to use version information to keep older versions of saved states still
2459 // able to be used. IT IS VERY IMPORTANT WHEN SAVING THE STATE TO RETURN THE NUMBER OF _BYTES_ WROTE
2460 // TO THE FILE. When restoring the data, the return value is ignored. saving_state is 1 when you should
2461 // write data to the file_ptr, 0 when you should read in the data.
2462 int STDCALL SaveRestoreState(void *file_ptr, uint8_t saving_state) { return 0; }
2463
2464 char STDCALL InitializeDLL(tOSIRISModuleInit *func_list) {
2465 osicommon_Initialize((tOSIRISModuleInit *)func_list);
2466 if (func_list->game_checksum != CHECKSUM) {
2467 mprintf(0, "Game-Checksum FAIL!!! (%ul!=%ul)\n", func_list->game_checksum, CHECKSUM);
2468 mprintf(0, "RECOMPILE YOUR SCRIPTS!!!\n");
2469 return 0;
2470 }
2471 aigame_mod_id = func_list->module_identifier;
2472 String_table_size = func_list->string_count;
2473 String_table = func_list->string_table;
2474
2475 return 1;
2476 }
2477
2478 void STDCALL ShutdownDLL(void) {}
2479
2480 int STDCALL GetGOScriptID(const char *name, uint8_t isdoor) {
2481 for (int i = 0; i < NUM_IDS; i++) {
2482 if (!stricmp(name, ScriptInfo[i].name)) {
2483 return ScriptInfo[i].id;
2484 }
2485 }
2486 return -1;
2487 }
2488
2489 void STDCALLPTR CreateInstance(int id) {
2490 switch (id) {
2491 case ID_PEST:
2492 return new Pest;
2493 break;
2494 case ID_STINGER:
2495 return new Stinger;
2496 break;
2497 case ID_DRAGON:
2498 return new Dragon;
2499 break;
2500 case ID_TRACKER:
2501 return new Tracker;
2502 break;
2503 case ID_LANCE:
2504 return new Lance;
2505 break;
2506 case ID_FLAK:
2507 return new Flak;
2508 break;
2509 case ID_SUPERTROOPER:
2510 case ID_REDSUPERTROOPER:
2511 return new SuperTrooper;
2512 break;
2513 case ID_JUGG:
2514 return new Jugg;
2515 break;
2516 case ID_SIXGUN:
2517 return new SixGun;
2518 break;
2519 case ID_SICKLE:
2520 return new Sickle;
2521 break;
2522 case ID_GUIDEBOT:
2523 return new GuideBot;
2524 break;
2525 case ID_FIREATDIST:
2526 return new FireAtDist;
2527 break;
2528 case ID_TUBBS:
2529 return new Tubbs;
2530 break;
2531 case ID_THIEF:
2532 return new Thief;
2533 break;
2534 case ID_GBPOWERUP:
2535 return new GBPowerup;
2536 break;
2537 case ID_BARNSWALLOW:
2538 return new BarnSwallow;
2539 break;
2540 case ID_SPARKY:
2541 return new Sparky;
2542 break;
2543 case ID_MANTARAY:
2544 return new MantaRay;
2545 break;
2546 case ID_SPYHUNTER:
2547 return new SpyHunter;
2548 break;
2549 case ID_SNIPER:
2550 return new Sniper;
2551 break;
2552 case ID_HUMONCULOUS:
2553 return new Humonculous;
2554 break;
2555 case ID_SEEKER:
2556 return new Seeker;
2557 break;
2558 case ID_BETTY:
2559 return new BettyScript;
2560 break;
2561 case ID_CHAFF:
2562 return new ChaffScript;
2563 break;
2564 case ID_CHAFFCHUNK:
2565 return new ChaffChunkScript;
2566 break;
2567 case ID_PROXMINE:
2568 return new ProxMine;
2569 break;
2570 case ID_BETTYBOMB:
2571 return new BettyBomb;
2572 break;
2573 case ID_JOSHBELL:
2574 return new JoshBell;
2575 break;
2576 case ID_SKIFF:
2577 return new Skiff;
2578 break;
2579 case ID_EXPLODEONCONTACT:
2580 return new ExplodeOnContact;
2581 break;
2582 case ID_EXPLODETIMEOUT:
2583 return new ExplodeTimeOut;
2584 break;
2585 case ID_GUNBOY:
2586 return new Gunboy;
2587 break;
2588 case ID_DEATH_TOWER:
2589 return new DTower;
2590 break;
2591 case ID_DEATH_COLLECTOR:
2592 return new DCollector;
2593 break;
2594 case ID_CHEMICAL_BALL:
2595 return new CBall;
2596 break;
2597 case ID_HELLION:
2598 return new Hellion;
2599 break;
2600 case ID_SUPERTHIEF:
2601 return new SuperThief;
2602 break;
2603 case ID_EVADERMODA:
2604 return new EvaderModA;
2605 break;
2606 case ID_DESTROYONCONTACT:
2607 return new DestroyOnContact;
2608 break;
2609 case ID_HATEPTMC:
2610 return new HatePTMC;
2611 break;
2612 case ID_SNIPERNORUN:
2613 return new SniperNoRun;
2614 break;
2615 case ID_FLAMERAS:
2616 return new FlameRAS;
2617 break;
2618 case ID_OLDSCRATCH:
2619 return new OldScratch;
2620 break;
2621 default:
2622 mprintf(0, "SCRIPT: Illegal ID (%d)\n", id);
2623 break;
2624 };
2625 return NULL;
2626 }
2627
2628 void STDCALL DestroyInstance(int id, void *ptr) {
2629 switch (id) {
2630 case ID_PEST:
2631 delete ((Pest *)ptr);
2632 break;
2633 case ID_STINGER:
2634 delete ((Stinger *)ptr);
2635 break;
2636 case ID_DRAGON:
2637 delete ((Dragon *)ptr);
2638 break;
2639 case ID_TRACKER:
2640 delete ((Tracker *)ptr);
2641 break;
2642 case ID_LANCE:
2643 delete ((Lance *)ptr);
2644 break;
2645 case ID_FLAK:
2646 delete ((Flak *)ptr);
2647 break;
2648 case ID_SUPERTROOPER:
2649 case ID_REDSUPERTROOPER:
2650 delete ((SuperTrooper *)ptr);
2651 break;
2652 case ID_JUGG:
2653 delete ((Jugg *)ptr);
2654 break;
2655 case ID_SIXGUN:
2656 delete ((SixGun *)ptr);
2657 break;
2658 case ID_SICKLE:
2659 delete ((Sickle *)ptr);
2660 break;
2661 case ID_GUIDEBOT:
2662 delete ((GuideBot *)ptr);
2663 break;
2664 case ID_FIREATDIST:
2665 delete ((FireAtDist *)ptr);
2666 break;
2667 case ID_TUBBS:
2668 delete ((Tubbs *)ptr);
2669 break;
2670 case ID_THIEF:
2671 delete ((Thief *)ptr);
2672 break;
2673 case ID_GBPOWERUP:
2674 delete ((GBPowerup *)ptr);
2675 break;
2676 case ID_BARNSWALLOW:
2677 delete ((BarnSwallow *)ptr);
2678 break;
2679 case ID_SPARKY:
2680 delete ((Sparky *)ptr);
2681 break;
2682 case ID_MANTARAY:
2683 delete ((MantaRay *)ptr);
2684 break;
2685 case ID_SPYHUNTER:
2686 delete ((SpyHunter *)ptr);
2687 break;
2688 case ID_SNIPER:
2689 delete ((Sniper *)ptr);
2690 break;
2691 case ID_HUMONCULOUS:
2692 delete ((Humonculous *)ptr);
2693 break;
2694 case ID_SEEKER:
2695 delete ((Seeker *)ptr);
2696 break;
2697 case ID_BETTY:
2698 delete ((BettyScript *)ptr);
2699 break;
2700 case ID_CHAFF:
2701 delete ((ChaffScript *)ptr);
2702 break;
2703 case ID_CHAFFCHUNK:
2704 delete ((ChaffChunkScript *)ptr);
2705 break;
2706 case ID_PROXMINE:
2707 delete ((ProxMine *)ptr);
2708 break;
2709 case ID_BETTYBOMB:
2710 delete ((BettyBomb *)ptr);
2711 break;
2712 case ID_JOSHBELL:
2713 delete ((JoshBell *)ptr);
2714 break;
2715 case ID_SKIFF:
2716 delete ((Skiff *)ptr);
2717 break;
2718 case ID_EXPLODEONCONTACT:
2719 delete ((ExplodeOnContact *)ptr);
2720 break;
2721 case ID_EXPLODETIMEOUT:
2722 delete ((ExplodeTimeOut *)ptr);
2723 break;
2724 case ID_GUNBOY:
2725 delete ((Gunboy *)ptr);
2726 break;
2727 case ID_DEATH_TOWER:
2728 delete ((DTower *)ptr);
2729 break;
2730 case ID_DEATH_COLLECTOR:
2731 delete ((DCollector *)ptr);
2732 break;
2733 case ID_CHEMICAL_BALL:
2734 delete ((CBall *)ptr);
2735 break;
2736 case ID_HELLION:
2737 delete ((Hellion *)ptr);
2738 break;
2739 case ID_SUPERTHIEF:
2740 delete ((SuperThief *)ptr);
2741 break;
2742 case ID_EVADERMODA:
2743 delete ((EvaderModA *)ptr);
2744 break;
2745 case ID_DESTROYONCONTACT:
2746 delete ((DestroyOnContact *)ptr);
2747 break;
2748 case ID_HATEPTMC:
2749 delete ((HatePTMC *)ptr);
2750 break;
2751 case ID_SNIPERNORUN:
2752 delete ((SniperNoRun *)ptr);
2753 break;
2754 case ID_FLAMERAS:
2755 delete ((FlameRAS *)ptr);
2756 break;
2757 case ID_OLDSCRATCH:
2758 delete ((OldScratch *)ptr);
2759 break;
2760 default:
2761 mprintf(0, "SCRIPT: Illegal ID (%d)\n", id);
2762 break;
2763 }
2764 }
2765
2766 int16_t STDCALL CallInstanceEvent(int id, void *ptr, int event, tOSIRISEventInfo *data) {
2767 return ((BaseObjScript *)ptr)->CallEvent(event, data);
2768 }
2769
2770 //============================================
2771 // Functions
2772 //============================================
2773
2774 static float Obj_GetObjDist(int me, int it, bool f_sub_rads) {
2775 vector me_pos;
2776 vector it_pos;
2777 float dist;
2778
2779 Obj_Value(me, VF_GET, OBJV_V_POS, &me_pos);
2780 Obj_Value(it, VF_GET, OBJV_V_POS, &it_pos);
2781
2782 dist = vm_VectorDistance(&me_pos, &it_pos);
2783
2784 if (f_sub_rads) {
2785 float size;
2786
2787 Obj_Value(me, VF_GET, OBJV_F_SIZE, &size);
2788 dist -= size;
2789 Obj_Value(it, VF_GET, OBJV_F_SIZE, &size);
2790 dist -= size;
2791 }
2792
2793 return dist;
2794 }
2795
2796 static inline void AIClearNonHPGoals(int handle) {
2797 int i;
2798
2799 for (i = 0; i < MAX_GOALS; i++) {
2800 if (i != 3)
2801 AI_ClearGoal(handle, i);
2802 }
2803 }
2804
2805 static inline bool IsGoalFinishedNotify(int index) {
2806 return (index == AIN_GOAL_COMPLETE || index == AIN_GOAL_INVALID || index == AIN_GOAL_FAIL || index == AIN_GOAL_ERROR);
2807 }
2808
2809 //============================================
2810 // Script Implementation
2811 //============================================
2812 BaseObjScript::BaseObjScript() {}
2813
2814 BaseObjScript::~BaseObjScript() {}
2815
2816 int16_t BaseObjScript::CallEvent(int event, tOSIRISEventInfo *data) { return CONTINUE_CHAIN | CONTINUE_DEFAULT; }
2817
2818 //-----------------
2819 // Josh Bell
2820 //-----------------
2821
2822 void JoshBell::DoInit(int me) {
2823 tOSIRISMEMCHUNK ch;
2824 ch.id = 4;
2825 ch.size = sizeof(joshbell_data);
2826 ch.my_id.type = OBJECT_SCRIPT;
2827 ch.my_id.objhandle = me;
2828
2829 memory = (joshbell_data *)Scrpt_MemAlloc(&ch);
2830
2831 memory->attach_cage = CreateAndAttach(me, "Bellbars", OBJ_CLUTTER, 0, 0);
2832 memory->bell_sound = Sound_FindId("Bell");
2833 memory->last_play_time = Game_GetTime();
2834 }
2835
2836 void JoshBell::DoCollide(int me) {
2837 int child_handle = Obj_GetAttachChildHandle(me, 0);
2838
2839 if (child_handle == OBJECT_HANDLE_NONE /* && memory->last_play_time + 2.0f < Game_GetTime()*/) {
2840 memory->last_play_time = Game_GetTime();
2841 Sound_Play3d(me, memory->bell_sound);
2842 }
2843 }
2844
2845 int16_t JoshBell::CallEvent(int event, tOSIRISEventInfo *data) {
2846 switch (event) {
2847 case EVT_CREATED:
2848 DoInit(data->me_handle);
2849 break;
2850 case EVT_COLLIDE:
2851 DoCollide(data->me_handle);
2852 break;
2853 case EVT_MEMRESTORE: {
2854 memory = (joshbell_data *)data->evt_memrestore.memory_ptr;
2855 } break;
2856 }
2857 return CONTINUE_CHAIN | CONTINUE_DEFAULT;
2858 }
2859
2860 //-----------------
2861 // Explode On Contact
2862 //-----------------
2863
2864 void ExplodeOnContact::DoCollide(int me, int it) {
2865 int type;
2866 Obj_Value(it, VF_GET, OBJV_I_TYPE, &type);
2867
2868 if (type == OBJ_PLAYER) {
2869 msafe_struct mstruct;
2870
2871 mstruct.objhandle = me;
2872 mstruct.killer_handle = OBJECT_HANDLE_NONE;
2873 mstruct.damage_type = GD_SCRIPTED;
2874 mstruct.amount = 1000.0f;
2875
2876 MSafe_CallFunction(MSAFE_OBJECT_DAMAGE_OBJECT, &mstruct);
2877 }
2878 }
2879
2880 int16_t ExplodeOnContact::CallEvent(int event, tOSIRISEventInfo *data) {
2881 switch (event) {
2882 case EVT_COLLIDE:
2883 DoCollide(data->me_handle, data->evt_collide.it_handle);
2884 break;
2885 }
2886 return CONTINUE_CHAIN | CONTINUE_DEFAULT;
2887 }
2888
2889 //-----------------
2890 // Destroy On Contact
2891 //-----------------
2892
2893 void DestroyOnContact::DoCollide(int me, int it) {
2894 int type;
2895 Obj_Value(it, VF_GET, OBJV_I_TYPE, &type);
2896
2897 if (type == OBJ_BUILDING || type == OBJ_ROBOT || type == OBJ_CLUTTER || type == OBJ_PLAYER) {
2898 Obj_Kill(it, OBJECT_HANDLE_NONE, 1000.0f,
2899 DF_BLAST_RING | DF_LOSES_ANTIGRAV | DF_EXPL_MEDIUM | DF_FIREBALL | DF_BREAKS_APART | DF_DEBRIS_SMOKES,
2900 0.0f, 0.0f);
2901 }
2902 }
2903
2904 int16_t DestroyOnContact::CallEvent(int event, tOSIRISEventInfo *data) {
2905 switch (event) {
2906 case EVT_COLLIDE:
2907 DoCollide(data->me_handle, data->evt_collide.it_handle);
2908 break;
2909 }
2910 return CONTINUE_CHAIN | CONTINUE_DEFAULT;
2911 }
2912
2913 // --------------
2914 // Pest
2915 // --------------
2916
2917 void Pest::DoInit(int me) {
2918 tOSIRISMEMCHUNK ch;
2919 ch.id = 4;
2920 ch.size = sizeof(pest_data);
2921 ch.my_id.type = OBJECT_SCRIPT;
2922 ch.my_id.objhandle = me;
2923
2924 memory = (pest_data *)Scrpt_MemAlloc(&ch);
2925
2926 memory->tail_handle = CreateAndAttach(me, "Pesttail", OBJ_ROBOT, 0, 0);
2927 memory->last_anim_frame = 0;
2928
2929 memory->foot_sounds[0] = Sound_FindId("RbtPestFoot1");
2930 memory->foot_sounds[1] = Sound_FindId("RbtPestFoot2");
2931 memory->foot_sounds[2] = Sound_FindId("RbtPestFoot3");
2932
2933 AI_SetType(me, AIT_EVADER1);
2934 }
2935
2936 int16_t Pest::CallEvent(int event, tOSIRISEventInfo *data) {
2937 switch (event) {
2938 case EVT_AI_INIT:
2939 DoInit(data->me_handle);
2940 break;
2941 case EVT_AI_FRAME: {
2942 float frame;
2943 Obj_Value(data->me_handle, VF_GET, OBJV_F_ANIM_FRAME, &frame);
2944 if ((frame > 9 && memory->last_anim_frame <= 9) || (frame > 10 && memory->last_anim_frame <= 10) ||
2945 (frame > 13 && memory->last_anim_frame <= 13)) {
2946 int index = rand() % 3;
2947
2948 Sound_Play3d(data->me_handle, memory->foot_sounds[index]);
2949 }
2950
2951 memory->last_anim_frame = frame;
2952 } break;
2953 case EVT_DESTROY: {
2954 msafe_struct mstruct;
2955
2956 mstruct.objhandle = memory->tail_handle;
2957 mstruct.killer_handle = OBJECT_HANDLE_NONE;
2958 mstruct.damage_type = GD_SCRIPTED;
2959 mstruct.amount = 1000.0f;
2960
2961 MSafe_CallFunction(MSAFE_OBJECT_DAMAGE_OBJECT, &mstruct);
2962 } break;
2963 break;
2964 case EVT_MEMRESTORE: {
2965 memory = (pest_data *)data->evt_memrestore.memory_ptr;
2966 } break;
2967 }
2968 return CONTINUE_CHAIN | CONTINUE_DEFAULT;
2969 }
2970
2971 // --------------
2972 // Stinger
2973 // --------------
2974
2975 #define STINGER_MELEE_DIST 50.0f
2976
2977 void Stinger::DoInit(int me) {
2978 tOSIRISMEMCHUNK ch;
2979 ch.id = 4;
2980 ch.size = sizeof(stinger_data);
2981 ch.my_id.type = OBJECT_SCRIPT;
2982 ch.my_id.objhandle = me;
2983
2984 memory = (stinger_data *)Scrpt_MemAlloc(&ch);
2985
2986 msafe_struct m;
2987 m.objhandle = me;
2988 MSafe_GetValue(MSAFE_OBJECT_SHIELDS, &m);
2989
2990 memory->next_mode_time = Game_GetTime() + ((float)rand() / (float)RAND_MAX) * 3.0f + 3.0f;
2991 memory->force_melee_shields = m.shields / 3.0f + ((((float)rand()) / (float)RAND_MAX) * m.shields) / 10.0f;
2992 memory->mode = STINGER_RANGED;
2993 memory->f_very_hurt = 0;
2994
2995 AI_SetType(me, AIT_EVADER1);
2996 }
2997
2998 void Stinger::DoInterval(int me) {
2999 bool f_force_melee = false;
3000 int target_handle;
3001
3002 msafe_struct m;
3003 m.objhandle = me;
3004 MSafe_GetValue(MSAFE_OBJECT_SHIELDS, &m);
3005
3006 memory->f_very_hurt = f_force_melee = (m.shields < memory->force_melee_shields) != 0;
3007
3008 if (!f_force_melee) {
3009 AI_Value(me, VF_GET, AIV_I_TARGET_HANDLE, &target_handle);
3010
3011 if (target_handle != OBJECT_HANDLE_NONE) {
3012 float dist;
3013 AI_Value(me, VF_GET, AIV_F_DIST_TO_TARGET, &dist);
3014
3015 if (dist < STINGER_MELEE_DIST) {
3016 f_force_melee = true;
3017 }
3018 }
3019 }
3020
3021 if ((!f_force_melee) && (memory->next_mode_time < Game_GetTime())) {
3022 memory->next_mode_time = Game_GetTime() + 7.0f + ((float)rand() / (float)RAND_MAX) * 3.0f;
3023
3024 if (rand() % 150 > 10) {
3025 if (memory->mode == STINGER_MELEE) {
3026 AI_SetType(me, AIT_EVADER1);
3027 memory->mode = STINGER_RANGED;
3028 }
3029 } else {
3030 if (memory->mode == STINGER_RANGED) {
3031 AI_SetType(me, AIT_MELEE1);
3032 memory->mode = STINGER_MELEE;
3033 }
3034 }
3035 } else if ((f_force_melee) && (memory->mode != STINGER_MELEE)) {
3036 // PlaySoundObj3d("RbtStingeattack1", me)
3037 AI_SetType(me, AIT_MELEE1);
3038 memory->mode = STINGER_MELEE;
3039 }
3040 }
3041
3042 int16_t Stinger::CallEvent(int event, tOSIRISEventInfo *data) {
3043 switch (event) {
3044 case EVT_AI_INIT:
3045 DoInit(data->me_handle);
3046 break;
3047 case EVT_AI_FRAME:
3048 DoInterval(data->me_handle);
3049 break;
3050 case EVT_MEMRESTORE: {
3051 memory = (stinger_data *)data->evt_memrestore.memory_ptr;
3052 } break;
3053 }
3054 return CONTINUE_CHAIN | CONTINUE_DEFAULT;
3055 }
3056
3057 // --------------
3058 // Humonculous
3059 // --------------
3060
3061 // Humonculous modes are in prescidence order (lowest to highest)
3062 #define HM_IDLE 0x0001
3063 #define HM_INTRO_CUTSCENE 0x0002
3064 #define HM_RANGED 0x0004
3065 #define HM_MELEE 0x0008
3066 #define HM_WALL_HIT 0x0010
3067 #define HM_MID_DAMAGE_TAUNT 0x0020
3068 #define HM_ABOUT_TO_FAKE_DEATH 0x0040
3069 #define HM_FAKE_DEATH 0x0080
3070 #define HM_DEATH_CHARGE 0x0100
3071 #define HM_ABOUT_TO_DIE 0x0200
3072 #define HM_DEAD 0x0400
3073
3074 #define H_WALL_HIT_INTERVAL 15.0f
3075
3076 #define H_DOOR_WAIT_TIME 8.0f
3077
3078 // Valid next modes from each mode (Humonculous Mode Valid Next)
3079 const int16_t hm_valid_next_modes[11] = {
3080 (HM_INTRO_CUTSCENE),
3081 (HM_RANGED | HM_MELEE | HM_WALL_HIT | HM_MID_DAMAGE_TAUNT | HM_ABOUT_TO_FAKE_DEATH),
3082 (HM_RANGED | HM_MELEE | HM_WALL_HIT | HM_MID_DAMAGE_TAUNT | HM_ABOUT_TO_FAKE_DEATH),
3083 (HM_RANGED | HM_MELEE | HM_WALL_HIT | HM_MID_DAMAGE_TAUNT | HM_ABOUT_TO_FAKE_DEATH),
3084 (HM_RANGED | HM_MELEE | HM_MID_DAMAGE_TAUNT | HM_ABOUT_TO_FAKE_DEATH),
3085 (HM_RANGED | HM_MELEE | HM_WALL_HIT | HM_ABOUT_TO_FAKE_DEATH),
3086 (HM_FAKE_DEATH),
3087 (HM_DEATH_CHARGE),
3088 (HM_ABOUT_TO_DIE),
3089 (HM_DEAD),
3090 (0),
3091 };
3092
3093 #define HF_PLAYER_DEAD 0x01
3094 #define HF_VERY_HURT 0x02
3095 #define HF_DID_FINAL_MELEE 0x04
3096 #define HF_LANDED 0x08
3097 #define HF_ORIENTED 0x10
3098 #define HF_HIT_WALL 0x20
3099 #define HF_DID_MID_DAMAGE 0x40
3100 #define HF_HIT_WALL_SHAKED 0x80
3101 #define HF_HIT_WALL_ASSIGNED 0x100
3102 #define HF_MID_DAMAGE_ASSIGNED 0x200
3103 #define HF_AT_FDPOS 0x400
3104 #define HF_AT_RDPOS 0x800
3105
3106 #define H_GUID_LANDED 0x1010002B
3107 #define H_GUID_AT_FDPOS 0x101000BE
3108 #define H_GUID_AT_RDPOS 0x10100022
3109
3110 // chrishack -- NOTE: Give the player an extra powerup if he kills the boss before he can do his
3111 // final melee attack
3112
3113 #define H_MELEE_DIST 50.0f
3114
3115 void Humonculous::DetermineDeathPos(int me, vector *dpos, int *droom) {
3116 float best_dist = 100000000.0f;
3117 int best_dp;
3118 vector dp[6];
3119 int dr[6];
3120 int i;
3121
3122 vector mpos;
3123 Obj_Value(me, VF_GET, OBJV_V_POS, &mpos);
3124
3125 Obj_Value(Scrpt_FindObjectName("SafeDeath01"), VF_GET, OBJV_V_POS, &dp[0]);
3126 Obj_Value(Scrpt_FindObjectName("SafeDeath01"), VF_GET, OBJV_I_ROOMNUM, &dr[0]);
3127 Obj_Value(Scrpt_FindObjectName("SafeDeath02"), VF_GET, OBJV_V_POS, &dp[1]);
3128 Obj_Value(Scrpt_FindObjectName("SafeDeath02"), VF_GET, OBJV_I_ROOMNUM, &dr[1]);
3129 Obj_Value(Scrpt_FindObjectName("SafeDeath03"), VF_GET, OBJV_V_POS, &dp[2]);
3130 Obj_Value(Scrpt_FindObjectName("SafeDeath03"), VF_GET, OBJV_I_ROOMNUM, &dr[2]);
3131 Obj_Value(Scrpt_FindObjectName("SafeDeath04"), VF_GET, OBJV_V_POS, &dp[3]);
3132 Obj_Value(Scrpt_FindObjectName("SafeDeath04"), VF_GET, OBJV_I_ROOMNUM, &dr[3]);
3133 Obj_Value(Scrpt_FindObjectName("SafeDeath05"), VF_GET, OBJV_V_POS, &dp[4]);
3134 Obj_Value(Scrpt_FindObjectName("SafeDeath05"), VF_GET, OBJV_I_ROOMNUM, &dr[4]);
3135 Obj_Value(Scrpt_FindObjectName("SafeDeath06"), VF_GET, OBJV_V_POS, &dp[5]);
3136 Obj_Value(Scrpt_FindObjectName("SafeDeath06"), VF_GET, OBJV_I_ROOMNUM, &dr[5]);
3137
3138 for (i = 0; i < 6; i++) {
3139 dp[i].y = -440.0f;
3140
3141 float cur_dist = vm_VectorDistance(&mpos, &dp[i]);
3142
3143 if (cur_dist < best_dist) {
3144 *dpos = dp[i];
3145 *droom = dr[i];
3146 best_dist = cur_dist;
3147 }
3148 }
3149 }
3150
3151 bool Humonculous::DoNotify(int me, tOSIRISEventInfo *data) {
3152 switch (memory->mode) {
3153 case HM_IDLE: {
3154 if (data->evt_ai_notify.notify_type == AIN_MOVIE_START) {
3155 SetMode(me, HM_INTRO_CUTSCENE);
3156 }
3157 } break;
3158
3159 case HM_INTRO_CUTSCENE: {
3160 if (data->evt_ai_notify.notify_type == AIN_MOVIE_END) {
3161 SetMode(me, HM_MELEE);
3162 }
3163 } break;
3164
3165 case HM_WALL_HIT: {
3166 if (data->evt_ai_notify.notify_type == AIN_GOAL_COMPLETE && data->evt_ai_notify.goal_uid == H_GUID_LANDED) {
3167 Obj_SetCustomAnim(me, 101.0f, 125.0f, 4.0f, AIAF_NOTIFY, Sound_FindId("RbtHmclIWallHit"), AS_ALERT);
3168 }
3169 } break;
3170
3171 case HM_ABOUT_TO_FAKE_DEATH:
3172 case HM_ABOUT_TO_DIE: {
3173 if (data->evt_ai_notify.notify_type == AIN_SCRIPTED_ORIENT) {
3174 vector uvec = Zero_vector;
3175 uvec.y = 1.0f;
3176
3177 if (AI_TurnTowardsVectors(me, &memory->land_fvec, &uvec))
3178 memory->flags |= HF_ORIENTED;
3179 else
3180 memory->flags &= ~HF_ORIENTED;
3181 }
3182
3183 if (data->evt_ai_notify.notify_type == AIN_GOAL_COMPLETE && data->evt_ai_notify.goal_uid == H_GUID_LANDED) {
3184 memory->flags |= HF_LANDED;
3185 }
3186
3187 if (data->evt_ai_notify.notify_type == AIN_GOAL_COMPLETE && data->evt_ai_notify.goal_uid == H_GUID_AT_FDPOS) {
3188 memory->flags |= HF_AT_FDPOS;
3189 memory->mode_time = 0.0f;
3190
3191 vector vel = {0.0f, 0.0f, 0.0f};
3192 Obj_Value(me, VF_SET, OBJV_V_VELOCITY, &vel);
3193
3194 Obj_SetCustomAnim(me, 167.0f, 210.0f, 6.0f, 0, Sound_FindId("RbtHmclFakeDeath"), -1);
3195 }
3196
3197 if (data->evt_ai_notify.notify_type == AIN_GOAL_COMPLETE && data->evt_ai_notify.goal_uid == H_GUID_AT_RDPOS) {
3198 memory->flags |= HF_AT_RDPOS;
3199 memory->mode_time = 0.0f;
3200
3201 vector vel = {0.0f, 0.0f, 0.0f};
3202 Obj_Value(me, VF_SET, OBJV_V_VELOCITY, &vel);
3203
3204 Obj_SetCustomAnim(me, 242.0f, 350.0f, 15.0f, 0, Sound_FindId("RbtHmclDeath"), -1);
3205 }
3206 } break;
3207 }
3208
3209 return true;
3210 }
3211
3212 bool Humonculous::SetMode(int me, uint16_t mode) {
3213 int new_mode_index = -1;
3214 int old_mode_index = -1;
3215
3216 int temp = mode;
3217
3218 // Determine the index (bit position from 0 to 31) of the mode (they are bit flags)
3219 do {
3220 temp >>= 1;
3221 new_mode_index++;
3222 } while (temp != 0);
3223
3224 temp = memory->mode;
3225 do {
3226 temp >>= 1;
3227 old_mode_index++;
3228 } while (temp != 0);
3229
3230 // Reactivates firing and melee attacks
3231 if (memory->mode == HM_WALL_HIT) {
3232 memory->next_wall_hit_check_time = Game_GetTime() + H_WALL_HIT_INTERVAL;
3233 int flags = AIF_DISABLE_FIRING | AIF_DISABLE_MELEE;
3234 AI_Value(me, VF_CLEAR_FLAGS, AIV_I_FLAGS, &flags);
3235 flags = AIF_FIRE;
3236 AI_Value(me, VF_SET_FLAGS, AIV_I_FLAGS, &flags);
3237
3238 flags = PF_POINT_COLLIDE_WALLS;
3239 Obj_Value(me, VF_CLEAR_FLAGS, OBJV_I_PHYSICS_FLAGS, &flags);
3240
3241 memory->flags &= ~(HF_HIT_WALL_SHAKED | HF_HIT_WALL);
3242 } else if (memory->mode == HM_MID_DAMAGE_TAUNT) {
3243 int flags = AIF_DISABLE_FIRING | AIF_DISABLE_MELEE;
3244 AI_Value(me, VF_CLEAR_FLAGS, AIV_I_FLAGS, &flags);
3245 flags = AIF_FIRE;
3246 AI_Value(me, VF_SET_FLAGS, AIV_I_FLAGS, &flags);
3247 }
3248
3249 // Determine if we can goto the next mode
3250 if (!(hm_valid_next_modes[old_mode_index] & mode))
3251 return false;
3252
3253 // Clear out the robot
3254 AI_SetType(me, AIT_AIS);
3255
3256 switch (mode) {
3257 case HM_IDLE: {
3258 } break;
3259 case HM_INTRO_CUTSCENE: {
3260 } break;
3261 case HM_RANGED: {
3262 AI_SetType(me, AIT_EVADER1);
3263 } break;
3264 case HM_MELEE: {
3265 AI_SetType(me, AIT_MELEE1);
3266 } break;
3267 case HM_WALL_HIT: {
3268 memory->flags |= HF_HIT_WALL_ASSIGNED;
3269
3270 int flags = AIF_DISABLE_FIRING | AIF_DISABLE_MELEE;
3271 AI_Value(me, VF_SET_FLAGS, AIV_I_FLAGS, &flags);
3272 flags = AIF_FIRE;
3273 AI_Value(me, VF_CLEAR_FLAGS, AIV_I_FLAGS, &flags);
3274
3275 vector start_pos;
3276 int start_room;
3277 vector end_pos;
3278
3279 ray_info ray;
3280
3281 matrix orient;
3282 Obj_Value(me, VF_GET, OBJV_M_ORIENT, &orient);
3283
3284 memory->land_fvec = orient.fvec;
3285 memory->land_fvec.y = 0.0f;
3286 vm_VectorNormalize(&memory->land_fvec);
3287 orient.fvec = memory->land_fvec;
3288
3289 vm_VectorNormalize(&orient.rvec);
3290
3291 Obj_Value(me, VF_GET, OBJV_V_POS, &start_pos);
3292 Obj_Value(me, VF_GET, OBJV_I_ROOMNUM, &start_room);
3293
3294 // Determine real start pos - room
3295 end_pos = start_pos;
3296 end_pos += orient.rvec * 29.0f;
3297 end_pos += orient.fvec * 33.215f;
3298
3299 flags = FQ_CHECK_OBJS | FQ_IGNORE_POWERUPS | FQ_IGNORE_WEAPONS | FQ_IGNORE_MOVING_OBJECTS |
3300 FQ_IGNORE_NON_LIGHTMAP_OBJECTS;
3301 int fate = FVI_RayCast(me, &start_pos, &end_pos, start_room, 0.0f, flags, &ray);
3302
3303 start_pos = end_pos = ray.hit_point;
3304 start_room = ray.hit_room;
3305
3306 end_pos += 5000.0f * orient.rvec;
3307
3308 flags = FQ_CHECK_OBJS | FQ_IGNORE_POWERUPS | FQ_IGNORE_WEAPONS | FQ_IGNORE_MOVING_OBJECTS |
3309 FQ_IGNORE_NON_LIGHTMAP_OBJECTS;
3310 fate = FVI_RayCast(me, &start_pos, &end_pos, start_room, 0.0f, flags, &ray);
3311
3312 if (ray.hit_wallnorm * orient.rvec > -0.95) {
3313 memory->mode = HM_WALL_HIT;
3314 SetMode(me, HM_MELEE);
3315 return false;
3316 }
3317
3318 memory->land_pos = ray.hit_point - (orient.fvec * 33.215f) - (orient.rvec * 29.0f);
3319
3320 AI_AddGoal(me, AIG_GET_TO_POS, 1, 1.0, H_GUID_LANDED, GF_ORIENT_SCRIPTED | GF_USE_BLINE_IF_SEES_GOAL | GF_NOTIFIES,
3321 &memory->land_pos, ray.hit_room);
3322
3323 float dist = 0.0f;
3324 AI_GoalValue(me, 1, VF_SET, AIGV_F_CIRCLE_DIST, &dist);
3325
3326 flags = PF_POINT_COLLIDE_WALLS;
3327 Obj_Value(me, VF_SET_FLAGS, OBJV_I_PHYSICS_FLAGS, &flags);
3328 } break;
3329 case HM_MID_DAMAGE_TAUNT: {
3330 memory->flags |= HF_MID_DAMAGE_ASSIGNED;
3331
3332 int flags = AIF_DISABLE_FIRING | AIF_DISABLE_MELEE;
3333 AI_Value(me, VF_SET_FLAGS, AIV_I_FLAGS, &flags);
3334 flags = AIF_FIRE;
3335 AI_Value(me, VF_CLEAR_FLAGS, AIV_I_FLAGS, &flags);
3336
3337 Obj_SetCustomAnim(me, 360.0f, 420.0f, 8.0f, AIAF_NOTIFY, Sound_FindId("RbtHmclMidTaunt"), AS_ALERT);
3338 } break;
3339 case HM_ABOUT_TO_FAKE_DEATH: {
3340 int flags = AIF_DISABLE_FIRING | AIF_DISABLE_MELEE;
3341 AI_Value(me, VF_SET_FLAGS, AIV_I_FLAGS, &flags);
3342 flags = AIF_FIRE;
3343 AI_Value(me, VF_CLEAR_FLAGS, AIV_I_FLAGS, &flags);
3344
3345 // Guarentee no wall hits or mid damage stuff after the fake death
3346 memory->flags |= (HF_HIT_WALL_ASSIGNED | HF_MID_DAMAGE_ASSIGNED);
3347
3348 vector dpos;
3349 int droom;
3350 DetermineDeathPos(me, &dpos, &droom);
3351
3352 AI_AddGoal(me, AIG_GET_TO_POS, 3, 1.0, H_GUID_AT_FDPOS, GF_USE_BLINE_IF_SEES_GOAL | GF_NOTIFIES, &dpos, droom);
3353 AI_SetGoalCircleDist(me, 3, 0.0f);
3354 } break;
3355 case HM_FAKE_DEATH: {
3356 Obj_SetCustomAnim(me, 210.0f, 242.0f, 5.0f, AIAF_NOTIFY, Sound_FindId("RbtHmclFakeGetUp"), AS_ALERT);
3357 } break;
3358 case HM_DEATH_CHARGE: {
3359 memory->flags &= ~(HF_LANDED | HF_ORIENTED);
3360
3361 AI_Value(me, VF_SET, AIV_F_MAX_SPEED, &memory->max_speed);
3362 AI_Value(me, VF_SET, AIV_F_MAX_DELTA_SPEED, &memory->max_delta_speed);
3363
3364 int flags = PF_POINT_COLLIDE_WALLS;
3365 Obj_Value(me, VF_CLEAR_FLAGS, OBJV_I_PHYSICS_FLAGS, &flags);
3366 flags = PF_LEVELING;
3367 Obj_Value(me, VF_SET_FLAGS, OBJV_I_PHYSICS_FLAGS, &flags);
3368
3369 flags = AIF_DISABLE_MELEE;
3370 AI_Value(me, VF_CLEAR_FLAGS, AIV_I_FLAGS, &flags);
3371 flags = AIF_FIRE;
3372 AI_Value(me, VF_SET_FLAGS, AIV_I_FLAGS, &flags);
3373
3374 flags = OF_AI_DEATH;
3375 Obj_Value(me, VF_CLEAR_FLAGS, OBJV_I_FLAGS, &flags);
3376
3377 msafe_struct m;
3378 m.objhandle = me;
3379 m.shields = 20.0f;
3380 MSafe_CallFunction(MSAFE_OBJECT_SHIELDS, &m);
3381
3382 AI_SetType(me, AIT_MELEE1);
3383 } break;
3384 case HM_ABOUT_TO_DIE: {
3385 int flags = AIF_DISABLE_FIRING | AIF_DISABLE_MELEE;
3386 AI_Value(me, VF_SET_FLAGS, AIV_I_FLAGS, &flags);
3387 flags = AIF_FIRE;
3388 AI_Value(me, VF_CLEAR_FLAGS, AIV_I_FLAGS, &flags);
3389
3390 float circle_dist = -1.0f;
3391 AI_Value(me, VF_SET, AIV_F_CIRCLE_DIST, &circle_dist);
3392
3393 vector dpos;
3394 int droom;
3395 DetermineDeathPos(me, &dpos, &droom);
3396
3397 AI_AddGoal(me, AIG_GET_TO_POS, 3, 1.0, H_GUID_AT_RDPOS, GF_USE_BLINE_IF_SEES_GOAL | GF_NOTIFIES, &dpos, droom);
3398 AI_SetGoalCircleDist(me, 3, 0.0f);
3399 } break;
3400 case HM_DEAD: {
3401 } break;
3402 default:
3403 mprintf(0, "WHAT ARE YOU DOING!!!!!!!!!!!!!");
3404 }
3405
3406 // Reset the important mode variables
3407 memory->mode = mode;
3408 memory->mode_time = 0.0f;
3409
3410 return true;
3411 }
3412
3413 void Humonculous::DoInit(int me) {
3414 tOSIRISMEMCHUNK ch;
3415 ch.id = 4;
3416 ch.size = sizeof(humonculous_data);
3417 ch.my_id.type = OBJECT_SCRIPT;
3418 ch.my_id.objhandle = me;
3419
3420 memory = (humonculous_data *)Scrpt_MemAlloc(&ch);
3421
3422 char diff = Game_GetDiffLevel();
3423 float shields;
3424 float speed;
3425 int flags;
3426
3427 Obj_Value(me, VF_GET, OBJV_F_SHIELDS, &shields);
3428 AI_Value(me, VF_GET, AIV_F_MAX_SPEED, &speed);
3429
3430 if (diff == DIFFICULTY_TRAINEE) {
3431 shields = shields * 0.7f;
3432 speed = speed * 0.6f;
3433 } else if (diff == DIFFICULTY_ROOKIE) {
3434 shields = shields * 0.85f;
3435 speed = speed * 0.7f;
3436 }
3437
3438 Obj_Value(me, VF_SET, OBJV_F_SHIELDS, &shields);
3439 AI_Value(me, VF_SET, AIV_F_MAX_SPEED, &speed);
3440
3441 memory->last_shields = shields;
3442 memory->next_mode_time = Game_GetTime() + ((float)rand() / (float)RAND_MAX) * 3.0f + 3.0f;
3443 memory->force_melee_shields = shields / 3.0f + ((((float)rand()) / (float)RAND_MAX) * shields) / 10.0f;
3444 memory->force_mid_damage_shields = shields * 0.5f;
3445 memory->force_wall_hit_shields = shields * 0.80f;
3446 memory->mode = HM_IDLE;
3447 memory->flags = 0;
3448 memory->next_wall_hit_check_time = Game_GetTime() + 25.0f;
3449
3450 matrix orient;
3451 vector pos;
3452 vector g_pos;
3453 vector g_norm;
3454
3455 Obj_Value(me, VF_GET, OBJV_M_ORIENT, &orient);
3456 Obj_Value(me, VF_GET, OBJV_V_POS, &pos);
3457 Obj_GetGroundPos(me, 0, &g_pos, &g_norm);
3458
3459 vector from_ground = pos - g_pos;
3460 memory->ground_pnt_offset = fabs(from_ground * orient.uvec);
3461
3462 AI_Value(me, VF_GET, AIV_F_MAX_SPEED, &memory->max_speed);
3463 AI_Value(me, VF_GET, AIV_F_MAX_DELTA_SPEED, &memory->max_delta_speed);
3464
3465 memory->josh[0] = CreateAndAttach(me, "Joshbot", OBJ_ROBOT, 2, 0, true, true);
3466 flags = PF_NO_COLLIDE_PARENT;
3467 Obj_Value(memory->josh[0], VF_SET_FLAGS, OBJV_I_PHYSICS_FLAGS, &flags);
3468 flags = OF_DESTROYABLE;
3469 Obj_Value(memory->josh[0], VF_CLEAR_FLAGS, OBJV_I_FLAGS, &flags);
3470
3471 // CreateAndAttach(me, "Joshbot", OBJ_ROBOT, 3, 0 ,true, false);
3472 memory->josh[1] = CreateAndAttach(me, "Joshbot", OBJ_ROBOT, 4, 0, true, true);
3473 flags = PF_NO_COLLIDE_PARENT;
3474 Obj_Value(memory->josh[1], VF_SET_FLAGS, OBJV_I_PHYSICS_FLAGS, &flags);
3475 flags = OF_DESTROYABLE;
3476 Obj_Value(memory->josh[1], VF_CLEAR_FLAGS, OBJV_I_FLAGS, &flags);
3477
3478 memory->rocks[0] = Scrpt_FindObjectName("BossRock01");
3479 memory->rocks[1] = Scrpt_FindObjectName("BossRock02");
3480 memory->rocks[2] = Scrpt_FindObjectName("BossRock03");
3481 memory->rocks[3] = Scrpt_FindObjectName("BossRock04");
3482 memory->rocks[4] = Scrpt_FindObjectName("BossRock05");
3483
3484 CreateAndAttach(me, "Humonbodyarmor", OBJ_ROBOT, 0, 0, true, false);
3485 CreateAndAttach(me, "Humonwristarmor", OBJ_ROBOT, 1, 0, true, false);
3486
3487 SetMode(me, HM_IDLE);
3488 }
3489
3490 void Humonculous::DoInterval(int me) {
3491 int flags;
3492 Obj_Value(me, VF_GET, OBJV_I_FLAGS, &flags);
3493
3494 // float frame;
3495 // Obj_Value(me, VF_GET, OBJV_F_ANIM_FRAME, &frame);
3496 // mprintf(0, "Anim frame is %f\n", frame);
3497 float shields;
3498 Obj_Value(me, VF_GET, OBJV_F_SHIELDS, &shields);
3499
3500 if (shields < memory->force_mid_damage_shields && !(memory->flags & HF_MID_DAMAGE_ASSIGNED)) {
3501 char anim_type;
3502 AI_Value(me, VF_GET, AIV_C_ANIMATION_TYPE, &anim_type);
3503
3504 if (anim_type != AS_RANGED_ATTACK && anim_type != AS_MELEE1 && anim_type != AS_MELEE2)
3505 SetMode(me, HM_MID_DAMAGE_TAUNT);
3506 }
3507
3508 if (shields < memory->force_wall_hit_shields && !(memory->flags & HF_HIT_WALL_ASSIGNED)) {
3509 char anim_type;
3510 AI_Value(me, VF_GET, AIV_C_ANIMATION_TYPE, &anim_type);
3511
3512 if (anim_type != AS_RANGED_ATTACK && anim_type != AS_MELEE1 && anim_type != AS_MELEE2) {
3513 mprintf(0, "HEHRE HERHERHERHERHEHREHRHERHEHREHR\n");
3514 SetMode(me, HM_WALL_HIT);
3515 }
3516 }
3517
3518 if ((memory->mode < HM_ABOUT_TO_FAKE_DEATH) && (flags & OF_AI_DEATH)) {
3519 char anim_type;
3520 AI_Value(me, VF_GET, AIV_C_ANIMATION_TYPE, &anim_type);
3521
3522 if (anim_type != AS_RANGED_ATTACK && anim_type != AS_MELEE1 && anim_type != AS_MELEE2)
3523 SetMode(me, HM_ABOUT_TO_FAKE_DEATH);
3524 }
3525
3526 if (memory->mode == HM_DEATH_CHARGE && memory->mode_time > 4.0f && (flags & OF_AI_DEATH)) {
3527 char anim_type;
3528 AI_Value(me, VF_GET, AIV_C_ANIMATION_TYPE, &anim_type);
3529
3530 if (anim_type != AS_RANGED_ATTACK && anim_type != AS_MELEE1 && anim_type != AS_MELEE2)
3531 SetMode(me, HM_ABOUT_TO_DIE);
3532 }
3533
3534 switch (memory->mode) {
3535 case HM_INTRO_CUTSCENE: {
3536 if (memory->mode_time < H_DOOR_WAIT_TIME && memory->mode_time + Game_GetFrameTime() >= H_DOOR_WAIT_TIME) {
3537 vector velocity = Zero_vector;
3538 velocity.y = 65.0f;
3539
3540 Obj_Value(me, VF_SET, OBJV_V_VELOCITY, &velocity);
3541
3542 int flags = AIF_FORCE_AWARENESS | AIF_DETERMINE_TARGET;
3543 AI_Value(me, VF_SET_FLAGS, AIV_I_FLAGS, &flags);
3544
3545 float awareness = AWARE_FULLY;
3546 AI_Value(me, VF_SET, AIV_F_AWARENESS, &awareness);
3547 }
3548 } break;
3549 case HM_RANGED:
3550 case HM_MELEE: {
3551 bool f_force_melee;
3552 int target_handle;
3553
3554 msafe_struct m;
3555 m.objhandle = me;
3556 MSafe_GetValue(MSAFE_OBJECT_SHIELDS, &m);
3557
3558 f_force_melee = (m.shields < memory->force_melee_shields);
3559
3560 if (f_force_melee)
3561 memory->flags |= HF_VERY_HURT;
3562 else
3563 memory->flags &= ~HF_VERY_HURT;
3564
3565 if (!f_force_melee) {
3566 AI_Value(me, VF_GET, AIV_I_TARGET_HANDLE, &target_handle);
3567
3568 if (target_handle != OBJECT_HANDLE_NONE) {
3569 float dist;
3570 AI_Value(me, VF_GET, AIV_F_DIST_TO_TARGET, &dist);
3571
3572 if (dist < H_MELEE_DIST) {
3573 f_force_melee = true;
3574 }
3575 }
3576 }
3577
3578 if ((!f_force_melee) && (memory->next_mode_time < Game_GetTime())) {
3579 memory->next_mode_time = Game_GetTime() + 3.0f + ((float)rand() / (float)RAND_MAX) * 2.0f;
3580
3581 if ((rand() % 150) > 10) {
3582 SetMode(me, HM_RANGED);
3583 } else {
3584 SetMode(me, HM_MELEE);
3585 }
3586 } else if ((f_force_melee) && (memory->mode != HM_MELEE)) {
3587 // PlaySoundObj3d("RbtStingeattack1", me)
3588 SetMode(me, HM_MELEE);
3589 }
3590 } break;
3591
3592 case HM_MID_DAMAGE_TAUNT: {
3593 float frame;
3594 Obj_Value(me, VF_GET, OBJV_F_ANIM_FRAME, &frame);
3595
3596 if (frame >= 360.0f && frame <= 420.0f) {
3597 memory->flags |= HF_DID_MID_DAMAGE;
3598
3599 if (memory->mode_time < 4.53f && memory->mode_time + Game_GetFrameTime() >= 4.53f) {
3600 int xxx;
3601 matrix orient;
3602 Obj_Value(me, VF_GET, OBJV_M_ORIENT, &orient);
3603
3604 // Launch joshbots
3605 for (xxx = 0; xxx < 2; xxx++) {
3606 int flags = OF_DESTROYABLE;
3607 vector vel = orient.fvec * 80.0f;
3608
3609 Obj_UnattachFromParent(memory->josh[xxx]);
3610 Obj_Value(memory->josh[xxx], VF_SET, OBJV_V_VELOCITY, &vel);
3611
3612 Obj_Value(memory->josh[xxx], VF_SET_FLAGS, OBJV_I_FLAGS, &flags);
3613 }
3614 }
3615 }
3616
3617 if ((memory->flags & HF_DID_MID_DAMAGE) && !(frame >= 360.0f && frame <= 420.0f)) {
3618 SetMode(me, HM_RANGED);
3619 }
3620 } break;
3621
3622 case HM_WALL_HIT: {
3623 char anim_type;
3624 char next_anim_type;
3625 AI_Value(me, VF_GET, AIV_C_ANIMATION_TYPE, &anim_type);
3626 AI_Value(me, VF_GET, AIV_C_NEXT_ANIMATION_TYPE, &next_anim_type);
3627
3628 float frame;
3629 Obj_Value(me, VF_GET, OBJV_F_ANIM_FRAME, &frame);
3630
3631 if ((memory->flags & HF_HIT_WALL) == 0) {
3632
3633 if (frame >= 101.0f && frame <= 125.0f) {
3634 memory->flags |= HF_HIT_WALL;
3635 }
3636 } else if (frame >= 110.0f && !(memory->flags & HF_HIT_WALL_SHAKED)) {
3637 memory->flags |= HF_HIT_WALL_SHAKED;
3638
3639 // shake players at wall hit
3640 msafe_struct mstruct;
3641 mstruct.amount = 65.0f;
3642 MSafe_CallFunction(MSAFE_OBJECT_VIEWER_SHAKE, &mstruct);
3643
3644 int i;
3645 char mtype = MT_PHYSICS;
3646 for (i = 0; i < 5; i++) {
3647 Obj_Value(memory->rocks[i], VF_SET, OBJV_C_MOVEMENT_TYPE, &mtype);
3648 }
3649 }
3650
3651 if (memory->mode_time > 4.0f && anim_type != AS_CUSTOM && next_anim_type != AS_CUSTOM &&
3652 (memory->flags & HF_HIT_WALL)) {
3653 SetMode(me, HM_RANGED);
3654 } else if (memory->mode_time > 15.0f &&
3655 anim_type != AS_CUSTOM) // Safety case - if there is a messup, return to ranged (worked fine)
3656 {
3657 SetMode(me, HM_RANGED);
3658 }
3659 } break;
3660
3661 case HM_ABOUT_TO_FAKE_DEATH: {
3662 if (memory->flags & HF_AT_FDPOS) {
3663 if (memory->mode_time < 6.0f && memory->mode_time + Game_GetFrameTime() >= 6.0f) {
3664 vector start_pos;
3665 int start_room;
3666 vector end_pos;
3667
3668 ray_info ray;
3669
3670 Obj_Value(me, VF_GET, OBJV_V_POS, &start_pos);
3671 Obj_Value(me, VF_GET, OBJV_I_ROOMNUM, &start_room);
3672 end_pos = start_pos;
3673 end_pos.y -= 2000.0f;
3674
3675 int flags = FQ_CHECK_OBJS | FQ_IGNORE_POWERUPS | FQ_IGNORE_WEAPONS | FQ_IGNORE_MOVING_OBJECTS |
3676 FQ_IGNORE_NON_LIGHTMAP_OBJECTS;
3677 int fate = FVI_RayCast(me, &start_pos, &end_pos, start_room, 0.0f, flags, &ray);
3678
3679 memory->land_pos = ray.hit_point;
3680 memory->land_pos.y += memory->ground_pnt_offset;
3681
3682 float max_speed = 20.0f;
3683 float max_delta_speed = 50.0f;
3684
3685 AI_Value(me, VF_SET, AIV_F_MAX_SPEED, &max_speed);
3686 AI_Value(me, VF_SET, AIV_F_MAX_DELTA_SPEED, &max_delta_speed);
3687
3688 AI_AddGoal(me, AIG_GET_TO_POS, 1, 1.0, H_GUID_LANDED,
3689 GF_ORIENT_SCRIPTED | GF_USE_BLINE_IF_SEES_GOAL | GF_NOTIFIES, &memory->land_pos, ray.hit_room);
3690
3691 float dist = 0.0f;
3692 AI_GoalValue(me, 1, VF_SET, AIGV_F_CIRCLE_DIST, &dist);
3693
3694 flags = PF_POINT_COLLIDE_WALLS;
3695 Obj_Value(me, VF_SET_FLAGS, OBJV_I_PHYSICS_FLAGS, &flags);
3696 flags = PF_LEVELING;
3697 Obj_Value(me, VF_CLEAR_FLAGS, OBJV_I_PHYSICS_FLAGS, &flags);
3698
3699 matrix orient;
3700 Obj_Value(me, VF_GET, OBJV_M_ORIENT, &orient);
3701
3702 memory->land_fvec = orient.fvec;
3703 memory->land_fvec.y = 0.0f;
3704 vm_VectorNormalize(&memory->land_fvec);
3705 }
3706
3707 if (memory->mode_time > 15.0f && (memory->flags & HF_LANDED) && (memory->flags & HF_ORIENTED)) {
3708 SetMode(me, HM_FAKE_DEATH);
3709 }
3710 }
3711
3712 if (memory->mode_time > 60.0f) {
3713 SetMode(me, HM_FAKE_DEATH);
3714 }
3715 } break;
3716
3717 case HM_FAKE_DEATH: {
3718 if (memory->mode_time > 4.0f) {
3719 vector velocity = Zero_vector;
3720 velocity.y = 40.0f;
3721
3722 Obj_Value(me, VF_SET, OBJV_V_VELOCITY, &velocity);
3723 SetMode(me, HM_DEATH_CHARGE);
3724 }
3725 } break;
3726
3727 case HM_ABOUT_TO_DIE: {
3728 if (memory->flags & HF_AT_RDPOS) {
3729 if (memory->mode_time < 10.0f && memory->mode_time + Game_GetFrameTime() >= 10.0f) {
3730 Obj_Burning(me, 1000000.0f, 1.0f);
3731 }
3732
3733 if (memory->mode_time < 12.5f && memory->mode_time + Game_GetFrameTime() >= 12.5f) {
3734 vector start_pos;
3735 int start_room;
3736 vector end_pos;
3737
3738 ray_info ray;
3739
3740 Obj_Value(me, VF_GET, OBJV_V_POS, &start_pos);
3741 Obj_Value(me, VF_GET, OBJV_I_ROOMNUM, &start_room);
3742 end_pos = start_pos;
3743 end_pos.y -= 2000.0f;
3744
3745 int flags = FQ_CHECK_OBJS | FQ_IGNORE_POWERUPS | FQ_IGNORE_WEAPONS | FQ_IGNORE_MOVING_OBJECTS |
3746 FQ_IGNORE_NON_LIGHTMAP_OBJECTS;
3747 int fate = FVI_RayCast(me, &start_pos, &end_pos, start_room, 0.0f, flags, &ray);
3748
3749 memory->land_pos = ray.hit_point;
3750 memory->land_pos.y += memory->ground_pnt_offset;
3751
3752 float max_speed = 20.0f;
3753 float max_delta_speed = 50.0f;
3754
3755 AI_Value(me, VF_SET, AIV_F_MAX_SPEED, &max_speed);
3756 AI_Value(me, VF_SET, AIV_F_MAX_DELTA_SPEED, &max_delta_speed);
3757
3758 AI_AddGoal(me, AIG_GET_TO_POS, 1, 1.0, H_GUID_LANDED,
3759 GF_ORIENT_SCRIPTED | GF_USE_BLINE_IF_SEES_GOAL | GF_NOTIFIES, &memory->land_pos, ray.hit_room);
3760
3761 float dist = 0.0f;
3762 AI_GoalValue(me, 1, VF_SET, AIGV_F_CIRCLE_DIST, &dist);
3763
3764 flags = PF_POINT_COLLIDE_WALLS;
3765 Obj_Value(me, VF_SET_FLAGS, OBJV_I_PHYSICS_FLAGS, &flags);
3766 flags = PF_LEVELING;
3767 Obj_Value(me, VF_CLEAR_FLAGS, OBJV_I_PHYSICS_FLAGS, &flags);
3768
3769 matrix orient;
3770 Obj_Value(me, VF_GET, OBJV_M_ORIENT, &orient);
3771
3772 memory->land_fvec = orient.fvec;
3773 memory->land_fvec.y = 0.0f;
3774 vm_VectorNormalize(&memory->land_fvec);
3775 }
3776 }
3777
3778 if (memory->mode_time > 45.0f && !(memory->flags & HF_AT_RDPOS)) {
3779 memory->flags |= HF_AT_RDPOS;
3780 memory->mode_time = 0.0f;
3781
3782 vector vel = {0.0f, 0.0f, 0.0f};
3783 Obj_Value(me, VF_SET, OBJV_V_VELOCITY, &vel);
3784
3785 Obj_SetCustomAnim(me, 242.0f, 350.0f, 15.0f, 0, Sound_FindId("RbtHmclDeath"), -1);
3786 }
3787 } break;
3788 }
3789
3790 memory->last_shields = shields;
3791 memory->mode_time += Game_GetFrameTime();
3792 }
3793
3794 int16_t Humonculous::CallEvent(int event, tOSIRISEventInfo *data) {
3795 switch (event) {
3796 case EVT_AI_INIT:
3797 DoInit(data->me_handle);
3798 break;
3799 case EVT_AI_FRAME:
3800 DoInterval(data->me_handle);
3801 break;
3802 case EVT_AI_NOTIFY:
3803 return (DoNotify(data->me_handle, data) != false) ? CONTINUE_CHAIN | CONTINUE_DEFAULT : 0;
3804 break;
3805 case EVT_MEMRESTORE: {
3806 memory = (humonculous_data *)data->evt_memrestore.memory_ptr;
3807 } break;
3808 }
3809 return CONTINUE_CHAIN | CONTINUE_DEFAULT;
3810 }
3811
3812 // --------------
3813 // Dragon
3814 // --------------
3815
3816 void Dragon::DoInit(int me) {
3817 int i;
3818
3819 tOSIRISMEMCHUNK ch;
3820 ch.id = 4;
3821 ch.size = sizeof(dragon_data);
3822 ch.my_id.type = OBJECT_SCRIPT;
3823 ch.my_id.objhandle = me;
3824
3825 memory = (dragon_data *)Scrpt_MemAlloc(&ch);
3826
3827 memory->head_object = CreateAndAttach(me, "Dragonhead", OBJ_ROBOT, 1, 0);
3828 memory->tail_object = CreateAndAttach(me, "Dragontail", OBJ_ROBOT, 0, 6);
3829 memory->green_turret = CreateAndAttach(me, "Dragonturret", OBJ_ROBOT, 2, 0);
3830
3831 for (i = 0; i < 6; i++) {
3832 memory->t[i] = CreateAndAttach(memory->tail_object, "Dragontailturret", OBJ_ROBOT, i, 1);
3833 memory->tentacle[i] = CreateAndAttach(memory->t[i], "Dragontentacle", OBJ_ROBOT, 0, 0);
3834 }
3835
3836 memory->mode = DRAGON_ARMOR;
3837
3838 AI_SetType(me, AIT_EVADER1);
3839 }
3840
3841 int16_t Dragon::CallEvent(int event, tOSIRISEventInfo *data) {
3842 switch (event) {
3843 case EVT_AI_INIT:
3844 DoInit(data->me_handle);
3845 break;
3846 case EVT_MEMRESTORE: {
3847 memory = (dragon_data *)data->evt_memrestore.memory_ptr;
3848 } break;
3849 case EVT_DESTROY: {
3850 int i;
3851
3852 Obj_Kill(memory->head_object, OBJECT_HANDLE_NONE, 1000.0f,
3853 DF_BLAST_RING | DF_LOSES_ANTIGRAV | DF_EXPL_MEDIUM | DF_FIREBALL | DF_BREAKS_APART | DF_DEBRIS_SMOKES,
3854 0.0f, 0.0f);
3855 Obj_Kill(memory->tail_object, OBJECT_HANDLE_NONE, 1000.0f,
3856 DF_BLAST_RING | DF_LOSES_ANTIGRAV | DF_EXPL_MEDIUM | DF_FIREBALL | DF_BREAKS_APART | DF_DEBRIS_SMOKES,
3857 0.0f, 0.0f);
3858 Obj_Kill(memory->green_turret, OBJECT_HANDLE_NONE, 1000.0f,
3859 DF_BLAST_RING | DF_LOSES_ANTIGRAV | DF_EXPL_MEDIUM | DF_FIREBALL | DF_BREAKS_APART | DF_DEBRIS_SMOKES,
3860 0.0f, 0.0f);
3861 for (i = 0; i < 6; i++) {
3862 Obj_Kill(memory->t[i], OBJECT_HANDLE_NONE, 1000.0f,
3863 DF_BLAST_RING | DF_LOSES_ANTIGRAV | DF_EXPL_MEDIUM | DF_FIREBALL | DF_BREAKS_APART | DF_DEBRIS_SMOKES,
3864 0.0f, 0.0f);
3865 Obj_Kill(memory->tentacle[i], OBJECT_HANDLE_NONE, 1000.0f,
3866 DF_BLAST_RING | DF_LOSES_ANTIGRAV | DF_EXPL_MEDIUM | DF_FIREBALL | DF_BREAKS_APART | DF_DEBRIS_SMOKES,
3867 0.0f, 0.0f);
3868 }
3869 } break;
3870 }
3871 return CONTINUE_CHAIN | CONTINUE_DEFAULT;
3872 }
3873
3874 //-----------
3875 // Tracker
3876 //-----------
3877
3878 void Tracker::DoInit(int me) {
3879 tOSIRISMEMCHUNK ch;
3880 ch.id = 4;
3881 ch.size = sizeof(tracker_data);
3882 ch.my_id.type = OBJECT_SCRIPT;
3883 ch.my_id.objhandle = me;
3884
3885 memory = (tracker_data *)Scrpt_MemAlloc(&ch);
3886
3887 memory->turret_object = CreateAndAttach(me, "Trackerturret", OBJ_ROBOT, 1, 0);
3888 memory->hatch_object = CreateAndAttach(me, "Trackerhatch", OBJ_ROBOT, 0, 0);
3889
3890 AI_SetType(me, AIT_EVADER1);
3891 }
3892
3893 int16_t Tracker::CallEvent(int event, tOSIRISEventInfo *data) {
3894 switch (event) {
3895 case EVT_AI_INIT:
3896 DoInit(data->me_handle);
3897 break;
3898 case EVT_MEMRESTORE: {
3899 memory = (tracker_data *)data->evt_memrestore.memory_ptr;
3900 } break;
3901 case EVT_DESTROY: {
3902 msafe_struct mstruct;
3903
3904 mstruct.objhandle = memory->hatch_object;
3905 mstruct.killer_handle = OBJECT_HANDLE_NONE;
3906 mstruct.damage_type = GD_SCRIPTED;
3907 mstruct.amount = 1000.0f;
3908
3909 MSafe_CallFunction(MSAFE_OBJECT_DAMAGE_OBJECT, &mstruct);
3910
3911 mstruct.objhandle = memory->turret_object;
3912 mstruct.killer_handle = OBJECT_HANDLE_NONE;
3913 mstruct.damage_type = GD_SCRIPTED;
3914 mstruct.amount = 1000.0f;
3915
3916 MSafe_CallFunction(MSAFE_OBJECT_DAMAGE_OBJECT, &mstruct);
3917 } break;
3918 }
3919 return CONTINUE_CHAIN | CONTINUE_DEFAULT;
3920 }
3921
3922 // --------------
3923 // Lance
3924 // --------------
3925
3926 void Lance::DoInit(int me) {
3927 tOSIRISMEMCHUNK ch;
3928 ch.id = 4;
3929 ch.size = sizeof(lance_data);
3930 ch.my_id.type = OBJECT_SCRIPT;
3931 ch.my_id.objhandle = me;
3932
3933 memory = (lance_data *)Scrpt_MemAlloc(&ch);
3934
3935 memory->mode = LANCE_MOVING;
3936 }
3937
3938 void Lance::DoFrame(int me) {
3939 float frame;
3940
3941 Obj_WBValue(me, 0, VF_GET, WBV_F_ANIM_FRAME, &frame);
3942
3943 if (frame > 2.0f && frame < 6.0f) {
3944 if (memory->mode == LANCE_MOVING) {
3945 int flags = AIF_DISABLE_FIRING;
3946 AI_Value(me, VF_SET_FLAGS, AIV_I_FLAGS, &flags);
3947 memory->mode = LANCE_PAUSED;
3948 }
3949 } else if (memory->mode == LANCE_PAUSED) {
3950 int flags = AIF_DISABLE_FIRING;
3951 AI_Value(me, VF_CLEAR_FLAGS, AIV_I_FLAGS, &flags);
3952 memory->mode = LANCE_MOVING;
3953 }
3954 }
3955
3956 int16_t Lance::CallEvent(int event, tOSIRISEventInfo *data) {
3957 switch (event) {
3958 case EVT_AI_INIT:
3959 DoInit(data->me_handle);
3960 break;
3961 case EVT_AI_FRAME:
3962 DoFrame(data->me_handle);
3963 break;
3964 case EVT_MEMRESTORE: {
3965 memory = (lance_data *)data->evt_memrestore.memory_ptr;
3966 } break;
3967 }
3968 return CONTINUE_CHAIN | CONTINUE_DEFAULT;
3969 }
3970
3971 // --------------
3972 // Flak
3973 // --------------
3974
3975 void Flak::DoInit(int me) {
3976 tOSIRISMEMCHUNK ch;
3977 ch.id = 4;
3978 ch.size = sizeof(flak_data);
3979 ch.my_id.type = OBJECT_SCRIPT;
3980 ch.my_id.objhandle = me;
3981
3982 memory = (flak_data *)Scrpt_MemAlloc(&ch);
3983
3984 memory->canopy_handle = CreateAndAttach(me, "Flakcanopy", OBJ_ROBOT, 0, 0);
3985 memory->f_dead = false;
3986
3987 AI_SetType(me, AIT_EVADER1);
3988 }
3989
3990 int16_t Flak::CallEvent(int event, tOSIRISEventInfo *data) {
3991 switch (event) {
3992 case EVT_AI_INIT:
3993 DoInit(data->me_handle);
3994 break;
3995 case EVT_INTERVAL: {
3996 if (!memory->f_dead) {
3997 int type;
3998 Obj_Value(memory->canopy_handle, VF_GET, OBJV_I_TYPE, &type);
3999 if (type != OBJ_ROBOT) {
4000 char ctype = CT_NONE;
4001 Obj_Value(data->me_handle, VF_SET, OBJV_C_CONTROL_TYPE, &ctype);
4002
4003 vector vel = {0.0f, 0.0f, 0.0f};
4004 Obj_Value(data->me_handle, VF_SET, OBJV_V_VELOCITY, &vel);
4005
4006 msafe_struct mstruct;
4007
4008 mstruct.random = 21;
4009 mstruct.is_real = 0;
4010 mstruct.objhandle = data->me_handle;
4011 mstruct.gunpoint = -2;
4012 mstruct.effect_type = MED_SMOKE_INDEX;
4013 mstruct.phys_info = 0;
4014 mstruct.drag = .001f;
4015 mstruct.mass = .001f;
4016 mstruct.interval = .1f;
4017 mstruct.longevity = 5.0f;
4018 mstruct.lifetime = 1.0;
4019 mstruct.size = 6.0f;
4020 mstruct.speed = 25.0;
4021
4022 MSafe_CallFunction(MSAFE_OBJECT_START_SPEW, &mstruct);
4023
4024 memory->f_dead = true;
4025 memory->death_time = Game_GetTime();
4026 }
4027 } else {
4028 if (Game_GetTime() > memory->death_time + 5.0f) {
4029 Obj_Kill(data->me_handle, OBJECT_HANDLE_NONE, 1000.0f,
4030 DF_BLAST_RING | DF_LOSES_ANTIGRAV | DF_EXPL_MEDIUM | DF_FIREBALL | DF_BREAKS_APART | DF_DEBRIS_SMOKES,
4031 0.0f, 0.0f);
4032 }
4033 }
4034 } break;
4035 case EVT_DESTROY:
4036 Obj_Kill(memory->canopy_handle, OBJECT_HANDLE_NONE, 1000.0f,
4037 DF_BLAST_RING | DF_LOSES_ANTIGRAV | DF_EXPL_MEDIUM | DF_FIREBALL | DF_BREAKS_APART | DF_DEBRIS_SMOKES,
4038 0.0f, 0.0f);
4039 break;
4040 case EVT_MEMRESTORE: {
4041 memory = (flak_data *)data->evt_memrestore.memory_ptr;
4042 } break;
4043 }
4044 return CONTINUE_CHAIN | CONTINUE_DEFAULT;
4045 }
4046
4047 //---------------
4048 // Super Trooper
4049 //---------------
4050
4051 void SuperTrooper::DoInit(int me) {
4052 msafe_struct m;
4053 m.objhandle = me;
4054 MSafe_GetValue(MSAFE_OBJECT_ID, &m);
4055 int st_id = Obj_FindID("supertrooper");
4056
4057 tOSIRISMEMCHUNK ch;
4058 ch.id = 4;
4059 ch.size = sizeof(supertrooper_data);
4060 ch.my_id.type = OBJECT_SCRIPT;
4061 ch.my_id.objhandle = me;
4062
4063 memory = (supertrooper_data *)Scrpt_MemAlloc(&ch);
4064
4065 if (m.id == st_id) {
4066 memory->body_handle = CreateAndAttach(me, "supertorso", OBJ_ROBOT, 0, 0);
4067 } else {
4068 memory->body_handle = CreateAndAttach(me, "red supertorso", OBJ_ROBOT, 0, 0);
4069 }
4070
4071 AI_SetType(me, AIT_EVADER1);
4072 }
4073
4074 int16_t SuperTrooper::CallEvent(int event, tOSIRISEventInfo *data) {
4075 switch (event) {
4076 case EVT_INTERVAL: {
4077 int body_handle = Obj_GetAttachChildHandle(data->me_handle, 0);
4078 if (body_handle != memory->body_handle) {
4079 msafe_struct mstruct;
4080
4081 mstruct.objhandle = data->me_handle;
4082 mstruct.killer_handle = OBJECT_HANDLE_NONE;
4083 mstruct.damage_type = GD_SCRIPTED;
4084 mstruct.amount = 1000.0f;
4085
4086 MSafe_CallFunction(MSAFE_OBJECT_DAMAGE_OBJECT, &mstruct);
4087 }
4088 } break;
4089 case EVT_AI_INIT:
4090 DoInit(data->me_handle);
4091 break;
4092 case EVT_DESTROY: {
4093 msafe_struct mstruct;
4094
4095 mstruct.objhandle = memory->body_handle;
4096 mstruct.killer_handle = OBJECT_HANDLE_NONE;
4097 mstruct.damage_type = GD_SCRIPTED;
4098 mstruct.amount = 1000.0f;
4099
4100 MSafe_CallFunction(MSAFE_OBJECT_DAMAGE_OBJECT, &mstruct);
4101 } break;
4102 case EVT_MEMRESTORE: {
4103 memory = (supertrooper_data *)data->evt_memrestore.memory_ptr;
4104 } break;
4105 }
4106 return CONTINUE_CHAIN | CONTINUE_DEFAULT;
4107 }
4108
4109 //---------------
4110 // Juggernaut
4111 //---------------
4112
4113 void Jugg::SetMode(int me, char mode) {
4114 switch (mode) {
4115 case JUGG_NORMAL:
4116 break;
4117 case JUGG_DYING: {
4118 char type = MT_NONE;
4119 char aimtype = MC_STANDING;
4120 Obj_Value(me, VF_SET, OBJV_C_MOVEMENT_TYPE, &type);
4121 AI_Value(me, VF_SET, AIV_C_MOVEMENT_TYPE, &aimtype);
4122
4123 Obj_SetCustomAnim(me, 8.0f, 20.0f, 4.0f, 0, -1, -1);
4124 } break;
4125 }
4126
4127 memory->mode = mode;
4128 memory->mode_time = 0.0f;
4129 }
4130
4131 void Jugg::DoInit(int me) {
4132 int head_object;
4133 int belly_object;
4134 int turret_object;
4135 int flame_object;
4136 int i;
4137
4138 tOSIRISMEMCHUNK ch;
4139 ch.id = 4;
4140 ch.size = sizeof(jugg_data);
4141 ch.my_id.type = OBJECT_SCRIPT;
4142 ch.my_id.objhandle = me;
4143
4144 memory = (jugg_data *)Scrpt_MemAlloc(&ch);
4145
4146 memory->head_object = CreateAndAttach(me, "Jugghead", OBJ_ROBOT, 0, 0);
4147
4148 // Left
4149 memory->head_turret[0] = CreateAndAttach(memory->head_object, "Juggheadturretright", OBJ_ROBOT, 1, 0);
4150 // Right
4151 memory->head_turret[1] = CreateAndAttach(memory->head_object, "Juggheadturretleft", OBJ_ROBOT, 2, 0);
4152
4153 memory->belly_object = CreateAndAttach(me, "Juggbelly", OBJ_ROBOT, 1, 0);
4154
4155 for (i = 0; i < 6; i++) {
4156 memory->turret_object[i] = CreateAndAttach(me, "Jugg main turret", OBJ_ROBOT, i + 2, 0);
4157 }
4158
4159 memory->flame_turret[0] = CreateAndAttach(memory->belly_object, "Jugg flame turret", OBJ_ROBOT, 1, 0);
4160 memory->flame_turret[1] = CreateAndAttach(memory->belly_object, "Jugg flame turret", OBJ_ROBOT, 2, 0);
4161 memory->flame_turret[2] = CreateAndAttach(me, "Jugg flame turret", OBJ_ROBOT, 8, 0);
4162
4163 memory->flags = 0;
4164
4165 SetMode(me, JUGG_NORMAL);
4166
4167 memory->foot_sound = Sound_FindId("JugFootHit");
4168 Obj_Value(me, VF_GET, OBJV_F_ANIM_FRAME, &memory->last_frame);
4169 }
4170
4171 void Jugg::DoFrame(int me) {
4172 float current_anim_frame;
4173 matrix orient;
4174 int flags;
4175
4176 Obj_Value(me, VF_GET, OBJV_F_ANIM_FRAME, &current_anim_frame);
4177 Obj_Value(me, VF_GET, OBJV_I_FLAGS, &flags);
4178
4179 if (!(memory->flags & JUGG_F_HEAD_DEAD)) {
4180 int h_flags;
4181 Obj_Value(memory->head_object, VF_GET, OBJV_I_FLAGS, &h_flags);
4182
4183 if (h_flags & OF_AI_DEATH) {
4184 memory->flags |= JUGG_F_HEAD_DEAD;
4185 AI_PowerSwitch(memory->head_object, 0);
4186 Obj_Burning(memory->head_object, 10.0f, 3.0f);
4187 }
4188 }
4189
4190 if (!(memory->flags & JUGG_F_BODY_DEAD)) {
4191 if (flags & OF_AI_DEATH) {
4192 memory->flags |= JUGG_F_BODY_DEAD;
4193 Obj_Burning(me, 10.0f, 3.0f);
4194 }
4195 }
4196
4197 if (memory->mode == JUGG_NORMAL && (memory->flags & JUGG_F_BODY_DEAD) && (memory->flags & JUGG_F_HEAD_DEAD)) {
4198 SetMode(me, JUGG_DYING);
4199 }
4200
4201 if (memory->mode == JUGG_DYING && current_anim_frame == 20.0f) {
4202 AI_PowerSwitch(me, 0);
4203 }
4204
4205 if (current_anim_frame > 1.0f && memory->last_frame <= 1.0f) {
4206 Sound_Play3d(me, memory->foot_sound);
4207 }
4208
4209 if (current_anim_frame > 3.0f && memory->last_frame <= 3.0f) {
4210 Sound_Play3d(me, memory->foot_sound);
4211 }
4212
4213 if (current_anim_frame > 4.0f && memory->last_frame <= 4.0f) {
4214 Sound_Play3d(me, memory->foot_sound);
4215 }
4216
4217 if (current_anim_frame > 7.0f && memory->last_frame <= 7.0f) {
4218 Sound_Play3d(me, memory->foot_sound);
4219 }
4220
4221 memory->mode_time += Game_GetFrameTime();
4222 memory->last_frame = current_anim_frame;
4223 }
4224
4225 int16_t Jugg::CallEvent(int event, tOSIRISEventInfo *data) {
4226 switch (event) {
4227 case EVT_AI_INIT:
4228 DoInit(data->me_handle);
4229 break;
4230 case EVT_AI_FRAME:
4231 DoFrame(data->me_handle);
4232 break;
4233 case EVT_INTERVAL: {
4234 if (!(memory->flags & JUGG_F_BELLY_DEAD)) {
4235 int type;
4236 int i;
4237
4238 Obj_Value(memory->belly_object, VF_GET, OBJV_I_TYPE, &type);
4239
4240 if (type == OBJ_NONE) {
4241 memory->flags |= JUGG_F_BELLY_DEAD;
4242
4243 for (i = 0; i < 3; i++) {
4244 Obj_Kill(memory->flame_turret[i], OBJECT_HANDLE_NONE, 1000.0f,
4245 DF_BLAST_RING | DF_LOSES_ANTIGRAV | DF_EXPL_MEDIUM | DF_FIREBALL | DF_BREAKS_APART |
4246 DF_DEBRIS_SMOKES,
4247 0.0f, 0.0f);
4248 }
4249 }
4250 }
4251 }
4252
4253 case EVT_DESTROY:
4254 break;
4255 case EVT_MEMRESTORE: {
4256 memory = (jugg_data *)data->evt_memrestore.memory_ptr;
4257 } break;
4258 }
4259 return CONTINUE_CHAIN | CONTINUE_DEFAULT;
4260 }
4261
4262 //---------------
4263 // Death Tower
4264 //---------------
4265
4266 void DTower::DoInit(int me) {
4267 int head_object;
4268 int belly_object;
4269 int turret_object;
4270 int flame_object;
4271 int i;
4272
4273 tOSIRISMEMCHUNK ch;
4274 ch.id = 4;
4275 ch.size = sizeof(dtower_data);
4276 ch.my_id.type = OBJECT_SCRIPT;
4277 ch.my_id.objhandle = me;
4278
4279 memory = (dtower_data *)Scrpt_MemAlloc(&ch);
4280
4281 memory->gun_handle = CreateAndAttach(me, "Ltowergun", OBJ_CLUTTER, 0, 0);
4282 memory->ball_handle = CreateAndAttach(me, "Ltowerball", OBJ_CLUTTER, 1, 0);
4283
4284 Obj_Value(me, VF_GET, OBJV_F_ANIM_FRAME, &memory->last_frame);
4285 memory->f_died = false;
4286 }
4287
4288 void DTower::DoFrame(int me) {
4289 float current_anim_frame;
4290 Obj_Value(me, VF_GET, OBJV_F_ANIM_FRAME, &current_anim_frame);
4291
4292 if (!memory->f_died) {
4293 int flags;
4294 Obj_Value(me, VF_GET, OBJV_I_FLAGS, &flags);
4295
4296 if (flags & OF_AI_DEATH) {
4297 memory->mode_time = 0.0f;
4298 memory->f_died = true;
4299 }
4300 } else if (memory->mode_time < 3.0f && memory->mode_time + Game_GetFrameTime() >= 3.0f) {
4301 int room;
4302 vector pos;
4303
4304 Obj_Value(me, VF_GET, OBJV_I_ROOMNUM, &room);
4305 Obj_GetGunPos(me, 1, &pos);
4306
4307 int weapon_id = Wpn_FindID("TubbsHitBlast");
4308 Obj_Create(OBJ_WEAPON, weapon_id, room, &pos, NULL, me);
4309
4310 Obj_Kill(memory->gun_handle, OBJECT_HANDLE_NONE, 1000.0f,
4311 DF_BLAST_RING | DF_LOSES_ANTIGRAV | DF_EXPL_LARGE | DF_FIREBALL | DF_BREAKS_APART | DF_DEBRIS_SMOKES, 0.0f,
4312 0.0f);
4313 Obj_Burning(me, 10.0f, 5.0f);
4314
4315 vector vel = {0.0f, 0.0f, 0.0f};
4316 vel.y = (float)rand() / (float)RAND_MAX * 30.0f + 90.0f;
4317 vel.x = (float)rand() / (float)RAND_MAX * 16.0f - 8.0f;
4318 vel.z = (float)rand() / (float)RAND_MAX * 16.0f - 8.0f;
4319
4320 Obj_UnattachFromParent(memory->ball_handle);
4321 Obj_Value(memory->ball_handle, VF_SET, OBJV_V_VELOCITY, &vel);
4322 Obj_Burning(memory->ball_handle, 15.0f, 3.0f);
4323
4324 Obj_SetCustomAnim(me, 0.0f, 10.0f, 2.0f, 0, -1, -1);
4325 }
4326
4327 if (current_anim_frame == 10.0f) {
4328 Obj_Kill(me, OBJECT_HANDLE_NONE, 1000.0f,
4329 DF_BLAST_RING | DF_LOSES_ANTIGRAV | DF_EXPL_LARGE | DF_FIREBALL | DF_BREAKS_APART | DF_DEBRIS_SMOKES, 0.0f,
4330 0.0f);
4331 }
4332
4333 memory->mode_time += Game_GetFrameTime();
4334 memory->last_frame = current_anim_frame;
4335 }
4336
4337 int16_t DTower::CallEvent(int event, tOSIRISEventInfo *data) {
4338 switch (event) {
4339 case EVT_AI_INIT:
4340 DoInit(data->me_handle);
4341 break;
4342 case EVT_AI_FRAME:
4343 DoFrame(data->me_handle);
4344 break;
4345 case EVT_DESTROY:
4346 break;
4347 case EVT_MEMRESTORE: {
4348 memory = (dtower_data *)data->evt_memrestore.memory_ptr;
4349 } break;
4350 }
4351 return CONTINUE_CHAIN | CONTINUE_DEFAULT;
4352 }
4353
4354 //---------------
4355 // Death Collector
4356 //---------------
4357
4358 void DCollector::DoInit(int me) {
4359 tOSIRISMEMCHUNK ch;
4360 ch.id = 4;
4361 ch.size = sizeof(dcollector_data);
4362 ch.my_id.type = OBJECT_SCRIPT;
4363 ch.my_id.objhandle = me;
4364
4365 memory = (dcollector_data *)Scrpt_MemAlloc(&ch);
4366
4367 memory->target_handle = CreateAndAttach(me, "Collectortarget", OBJ_CLUTTER, 0, 1);
4368 memory->rod_handle = CreateAndAttach(memory->target_handle, "Collectorrod", OBJ_CLUTTER, 0, 0);
4369 memory->ball_handle = CreateAndAttach(memory->rod_handle, "Collectorball", OBJ_CLUTTER, 1, 0);
4370
4371 memory->f_dead = false;
4372 }
4373
4374 void DCollector::DoFrame(int me) {
4375 if (!memory->f_dead) {
4376 int type;
4377 Obj_Value(memory->target_handle, VF_GET, OBJV_I_TYPE, &type);
4378
4379 if (type == OBJ_NONE) {
4380 memory->f_dead = true;
4381 Obj_Kill(memory->rod_handle, OBJECT_HANDLE_NONE, 1000.0f,
4382 DF_BLAST_RING | DF_LOSES_ANTIGRAV | DF_EXPL_MEDIUM | DF_FIREBALL | DF_BREAKS_APART | DF_DEBRIS_SMOKES,
4383 0.0f, 0.0f);
4384
4385 Obj_Burning(me, 6.0f, 3.0f);
4386
4387 vector vel = {0.0f, 0.0f, 0.0f};
4388 vel.y = (float)rand() / (float)RAND_MAX * 30.0f + 90.0f;
4389 vel.x = (float)rand() / (float)RAND_MAX * 8.0f - 4.0f;
4390 vel.z = (float)rand() / (float)RAND_MAX * 8.0f - 4.0f;
4391 Obj_Value(memory->ball_handle, VF_SET, OBJV_V_VELOCITY, &vel);
4392 Obj_Burning(memory->ball_handle, 15.0f, 3.0f);
4393 }
4394 }
4395 }
4396
4397 int16_t DCollector::CallEvent(int event, tOSIRISEventInfo *data) {
4398 switch (event) {
4399 case EVT_AI_INIT:
4400 DoInit(data->me_handle);
4401 break;
4402 case EVT_AI_FRAME:
4403 DoFrame(data->me_handle);
4404 break;
4405 case EVT_DESTROY:
4406 break;
4407 case EVT_MEMRESTORE: {
4408 memory = (dcollector_data *)data->evt_memrestore.memory_ptr;
4409 } break;
4410 }
4411 return CONTINUE_CHAIN | CONTINUE_DEFAULT;
4412 }
4413
4414 //---------------
4415 // Chemical Ball
4416 //---------------
4417
4418 void CBall::DoInit(int me) {
4419 tOSIRISMEMCHUNK ch;
4420 ch.id = 4;
4421 ch.size = sizeof(cball_data);
4422 ch.my_id.type = OBJECT_SCRIPT;
4423 ch.my_id.objhandle = me;
4424
4425 memory = (cball_data *)Scrpt_MemAlloc(&ch);
4426
4427 memory->f_picked_up = false;
4428 memory->mode_time = 0.0f;
4429 }
4430
4431 void CBall::DoFrame(int me) {
4432 bool f_picked_up;
4433
4434 f_picked_up = (Obj_GetAttachParent(me) != OBJECT_HANDLE_NONE);
4435
4436 if (!memory->f_picked_up && f_picked_up) {
4437 memory->f_picked_up = true;
4438 } else if (memory->f_picked_up && !f_picked_up) {
4439 memory->mode_time += Game_GetFrameTime();
4440
4441 if (memory->mode_time > 12.0f) {
4442 Obj_Kill(me, OBJECT_HANDLE_NONE, 1000.0f,
4443 DF_BLAST_RING | DF_LOSES_ANTIGRAV | DF_EXPL_MEDIUM | DF_FIREBALL | DF_BREAKS_APART | DF_DEBRIS_SMOKES,
4444 0.0f, 0.0f);
4445 }
4446 }
4447 }
4448
4449 int16_t CBall::CallEvent(int event, tOSIRISEventInfo *data) {
4450 switch (event) {
4451 case EVT_CREATED:
4452 DoInit(data->me_handle);
4453 break;
4454 case EVT_INTERVAL:
4455 DoFrame(data->me_handle);
4456 break;
4457 case EVT_DESTROY:
4458 break;
4459 case EVT_MEMRESTORE: {
4460 memory = (cball_data *)data->evt_memrestore.memory_ptr;
4461 } break;
4462 }
4463 return CONTINUE_CHAIN | CONTINUE_DEFAULT;
4464 }
4465
4466 //---------------
4467 // Sixgun
4468 //---------------
4469
4470 void SixGun::DoInit(int me) {
4471 msafe_struct m;
4472 m.objhandle = me;
4473
4474 tOSIRISMEMCHUNK ch;
4475 ch.id = 4;
4476 ch.size = sizeof(sixgun_data);
4477 ch.my_id.type = OBJECT_SCRIPT;
4478 ch.my_id.objhandle = me;
4479
4480 memory = (sixgun_data *)Scrpt_MemAlloc(&ch);
4481
4482 memory->mode = 0;
4483 int flags = DWBF_ENABLED;
4484 Obj_WBValue(me, 0, VF_CLEAR_FLAGS, WBV_I_DYNAMIC_FLAGS, &flags);
4485
4486 AI_Value(me, VF_GET, AIV_F_MAX_SPEED, &memory->max_speed);
4487 AI_Value(me, VF_GET, AIV_F_CIRCLE_DIST, &memory->circle_dist);
4488
4489 float temp = 0.0f;
4490 AI_Value(me, VF_SET, AIV_F_MAX_SPEED, &temp);
4491 temp = 20.0f;
4492 AI_Value(me, VF_SET, AIV_F_CIRCLE_DIST, &temp);
4493 }
4494
4495 bool SixGun::DoNotify(int me, tOSIRISEVTAINOTIFY *notify) {
4496 if (memory->mode == 0) {
4497 if ((notify->notify_type == AIN_OBJ_FIRED) || (notify->notify_type == AIN_NEAR_TARGET) ||
4498 (notify->notify_type == AIN_HIT_BY_WEAPON) || (notify->notify_type == AIN_BUMPED_OBJ)) {
4499 int flags = DWBF_ENABLED;
4500 Obj_WBValue(me, 0, VF_SET_FLAGS, WBV_I_DYNAMIC_FLAGS, &flags);
4501
4502 AI_Value(me, VF_SET, AIV_F_MAX_SPEED, &memory->max_speed);
4503 AI_Value(me, VF_SET, AIV_F_CIRCLE_DIST, &memory->circle_dist);
4504 AI_AddGoal(me, AIG_MOVE_RELATIVE_OBJ, 0, 1.0f, -1, GF_OBJ_IS_TARGET | GF_KEEP_AT_COMPLETION | GF_NONFLUSHABLE,
4505 OBJECT_HANDLE_NONE);
4506 memory->mode = 1;
4507 }
4508 }
4509
4510 return true;
4511 }
4512
4513 int16_t SixGun::CallEvent(int event, tOSIRISEventInfo *data) {
4514 switch (event) {
4515 case EVT_AI_INIT:
4516 DoInit(data->me_handle);
4517 break;
4518 case EVT_AI_NOTIFY:
4519 return (DoNotify(data->me_handle, &data->evt_ai_notify) != false) ? CONTINUE_CHAIN | CONTINUE_DEFAULT : 0;
4520 break;
4521 case EVT_DESTROY:
4522 break;
4523 case EVT_MEMRESTORE: {
4524 memory = (sixgun_data *)data->evt_memrestore.memory_ptr;
4525 } break;
4526 }
4527 return CONTINUE_CHAIN | CONTINUE_DEFAULT;
4528 }
4529
4530 //---------------
4531 // Explode Time Out
4532 //---------------
4533
4534 void ExplodeTimeOut::DoInit(int me) {
4535 msafe_struct m;
4536 m.objhandle = me;
4537
4538 tOSIRISMEMCHUNK ch;
4539 ch.id = 4;
4540 ch.size = sizeof(explodetimeout_data);
4541 ch.my_id.type = OBJECT_SCRIPT;
4542 ch.my_id.objhandle = me;
4543
4544 memory = (explodetimeout_data *)Scrpt_MemAlloc(&ch);
4545 memory->life_left = 160.0f;
4546 }
4547
4548 int16_t ExplodeTimeOut::CallEvent(int event, tOSIRISEventInfo *data) {
4549 switch (event) {
4550 case EVT_AI_INIT:
4551 DoInit(data->me_handle);
4552 break;
4553 case EVT_INTERVAL: {
4554 memory->life_left -= Game_GetFrameTime();
4555 if (memory->life_left <= 0.0f) {
4556 msafe_struct mstruct;
4557
4558 mstruct.objhandle = data->me_handle;
4559 mstruct.killer_handle = OBJECT_HANDLE_NONE;
4560 mstruct.damage_type = GD_SCRIPTED;
4561 mstruct.amount = 1000.0f;
4562
4563 MSafe_CallFunction(MSAFE_OBJECT_DAMAGE_OBJECT, &mstruct);
4564 }
4565 } break;
4566 case EVT_DESTROY:
4567 break;
4568 case EVT_MEMRESTORE: {
4569 memory = (explodetimeout_data *)data->evt_memrestore.memory_ptr;
4570 } break;
4571 }
4572 return CONTINUE_CHAIN | CONTINUE_DEFAULT;
4573 }
4574
4575 //---------------
4576 // GuideBot
4577 //---------------
4578
4579 void GuideBot::ReInitAmbient(int me) {
4580 memory->next_ambient_time = Game_GetTime() + 1.0f;
4581
4582 // In general, Turn on friend avoidance
4583 if (memory->last_command != GBC_RETURN_TO_SHIP) {
4584 int flags = AIF_AUTO_AVOID_FRIENDS;
4585 AI_Value(me, VF_SET_FLAGS, AIV_I_FLAGS, &flags);
4586 }
4587
4588 int dir_index = rand() % 6;
4589 if (dir_index == GST_NEG_UVEC)
4590 dir_index = GST_NEG_RVEC;
4591 else if (dir_index == GST_UVEC)
4592 dir_index = GST_RVEC;
4593
4594 AI_AddGoal(me, AIG_MOVE_RELATIVE_OBJ_VEC, 0, 1.0f, -1, GF_KEEP_AT_COMPLETION | GF_USE_BLINE_IF_SEES_GOAL,
4595 memory->amb_camera_handle, dir_index);
4596 AI_SetGoalCircleDist(me, 0, 4.0);
4597 // AddGetToGoalCommonGoals(me);
4598 }
4599
4600 void GuideBot::DoMessage(const char *str, bool f_high_priority, const char *sound_name, bool f_sound_2d) {
4601 if ((memory->flags & GBF_NO_CHATTER) && !f_high_priority)
4602 return;
4603
4604 if (memory->last_sound_time + 2.5f < Game_GetTime()) {
4605 if (sound_name) {
4606 int s_id = Sound_FindId(sound_name);
4607 if (f_sound_2d)
4608 Sound_Play2d(memory->me, s_id);
4609 else
4610 Sound_Play3d(memory->me, s_id);
4611 }
4612
4613 memory->last_sound_time = Game_GetTime();
4614 }
4615
4616 char gb_message[256];
4617 snprintf(gb_message, sizeof(gb_message), "\1\255\255\1%s:\1\1\255\1 %s", memory->name, str);
4618 Player_AddHudMessage(memory->my_player, gb_message);
4619 }
4620
4621 bool GuideBot::SetSubMode(int me, char sub_mode, int it) {
4622 switch (sub_mode) {
4623 case GBSM_GET_POWERUP: {
4624 if (memory->sub_mode == GBSM_NONE) {
4625 float dist = -10000.0f;
4626 // chrishack -- need a message!
4627 AI_AddGoal(me, AIG_GET_TO_OBJ, 2, 1.0f, -1, GF_KEEP_AT_COMPLETION | GF_NOTIFIES, it);
4628 AI_GoalValue(me, 2, VF_SET, AIGV_F_CIRCLE_DIST, &dist);
4629
4630 if (memory->sub_mode != GBSM_GET_POWERUP) {
4631 DoMessage(TXT_GB_I_FOUND_A_GB_POWERUP, true, "GBotExcited1");
4632 }
4633 }
4634 } break;
4635 case GBSM_NONE: {
4636 } break;
4637 }
4638
4639 memory->sub_mode = sub_mode;
4640 // mprintf(0, "Sub Mode is %d\n", memory->sub_mode);
4641
4642 return true;
4643 }
4644
4645 bool GuideBot::SetMode(int me, char mode) {
4646 AI_SetType(me, AIT_AIS); // Gets rid of all goal BS
4647 memory->mode_time = 0.0f;
4648
4649 memory->time_till_next_flare = 3.0f + ((float)rand() / (float)RAND_MAX);
4650 memory->time_till_next_pvis_check = 0.5f + (0.5f * ((float)rand() / (float)RAND_MAX));
4651 memory->last_retreat_time = memory->return_time = Game_GetTime();
4652
4653 if (memory->mode == GBM_RTYPE) {
4654 AI_Value(me, VF_SET, AIV_F_MAX_DELTA_SPEED, &memory->max_acc);
4655 AI_Value(me, VF_SET, AIV_F_MAX_SPEED, &memory->max_speed);
4656 }
4657
4658 if (memory->camera_obj != OBJECT_HANDLE_NONE) {
4659 msafe_struct mo;
4660 mo.objhandle = memory->camera_obj;
4661 MSafe_CallFunction(MSAFE_OBJECT_REMOVE, &mo);
4662
4663 memory->camera_obj = OBJECT_HANDLE_NONE;
4664 }
4665
4666 float dist = 4.0f;
4667 int g_index =
4668 AI_AddGoal(me, AIG_GET_AROUND_OBJ, ACTIVATION_BLEND_LEVEL, 1.0f, -1, GF_OBJ_IS_TARGET, OBJECT_HANDLE_NONE);
4669 AI_GoalValue(me, g_index, VF_SET, AIGV_F_CIRCLE_DIST, &dist);
4670
4671 int hack_flags = AIF_GB_MIMIC_PLAYER_FIRING_HACK;
4672 AI_Value(me, VF_CLEAR_FLAGS, AIV_I_FLAGS, &hack_flags);
4673
4674 int wbflags = DWBF_ENABLED;
4675 Obj_WBValue(me, 3, VF_CLEAR_FLAGS, WBV_I_DYNAMIC_FLAGS, &wbflags);
4676
4677 if (memory->mode == GBM_EXTINGUISH && mode != GBM_EXTINGUISH) {
4678 msafe_struct mstruct;
4679
4680 if (memory->flags & GBF_EXTINGUISHING) {
4681 memory->flags &= ~GBF_EXTINGUISHING;
4682 mstruct.id = memory->extinguish_spew_id;
4683 MSafe_CallFunction(MSAFE_OBJECT_STOP_SPEW, &mstruct);
4684 }
4685
4686 mstruct.id = memory->extinguish_spew_id;
4687 MSafe_CallFunction(MSAFE_OBJECT_STOP_SPEW, &mstruct);
4688 Obj_SetCustomAnim(me, 33.0f, 41.0f, 1.2f, AIAF_NOTIFY, -1, AS_ALERT);
4689 }
4690
4691 switch (mode) {
4692 case GBM_IN_SHIP:
4693 break;
4694 case GBM_ENTER_SHIP: {
4695 DoMessage(TXT_GB_ENTERINGSHIP, true);
4696 }
4697 case GBM_RESPAWN_ENTER_SHIP: {
4698 int i;
4699
4700 if (mode == GBM_RESPAWN_ENTER_SHIP) {
4701 float gb_shields = 250;
4702 int flags = OF_AI_DEATH;
4703
4704 Obj_Value(me, VF_CLEAR_FLAGS, OBJV_I_FLAGS, &flags);
4705 Obj_Value(me, VF_SET, OBJV_F_SHIELDS, &gb_shields);
4706
4707 flags = AIF_AUTO_AVOID_FRIENDS;
4708 AI_Value(me, VF_SET_FLAGS, AIV_I_FLAGS, &flags);
4709 Obj_Burning(me, 0.0f, 0.0f);
4710 }
4711
4712 memory->flags &= ~GBF_WANTING_TO_ENTER_PDEAD;
4713
4714 Obj_Burning(me, 0.0f, 0.0f);
4715 for (i = 0; i < NUM_GB_SOUNDS; i++) {
4716 if (memory->sounds[i] != -1) {
4717 Sound_Stop(memory->sounds[i], true);
4718 memory->sounds[i] = -1;
4719 }
4720 }
4721
4722 msafe_struct m;
4723 m.objhandle = memory->my_player;
4724 m.type = OBJ_ROBOT;
4725 m.id = ROBOT_GUIDEBOT;
4726 m.flags = 0;
4727
4728 MSafe_CallFunction(MSAFE_INVEN_ADD_TYPE_ID, &m);
4729
4730 Obj_Ghost(me, true);
4731 mode = GBM_IN_SHIP;
4732 } break;
4733 case GBM_BIRTH: {
4734 int room;
4735 vector pos;
4736 matrix orient;
4737 vector vel;
4738 int flags;
4739
4740 flags = AIF_AUTO_AVOID_FRIENDS;
4741 AI_Value(me, VF_CLEAR_FLAGS, AIV_I_FLAGS, &flags);
4742
4743 memory->f_parented = true;
4744 memory->f_pickup = false;
4745 memory->last_anim = 0.0f;
4746
4747 Obj_SetCustomAnim(me, 6.0f, 12.0f, 1.0f, AIAF_NOTIFY | AIAF_IMMEDIATE, -1, AS_ALERT);
4748
4749 Obj_Value(memory->my_player, VF_GET, OBJV_I_ROOMNUM, &room);
4750 Obj_Value(memory->my_player, VF_GET, OBJV_V_POS, &pos);
4751 Obj_Value(memory->my_player, VF_GET, OBJV_M_ORIENT, &orient);
4752
4753 Obj_Value(me, VF_SET, OBJV_I_ROOMNUM, &room);
4754 Obj_Value(me, VF_SET, OBJV_V_POS, &pos);
4755 Obj_Value(me, VF_SET, OBJV_M_ORIENT, &orient);
4756
4757 Obj_Value(memory->my_player, VF_GET, OBJV_V_VELOCITY, &vel);
4758
4759 vel += orient.fvec * 40.0f;
4760
4761 Obj_Value(me, VF_SET, OBJV_V_VELOCITY, &vel);
4762
4763 Obj_Ghost(me, false);
4764
4765 msafe_struct m;
4766 m.objhandle = memory->my_player;
4767 m.type = OBJ_ROBOT;
4768 m.id = ROBOT_GUIDEBOT;
4769 m.flags = 0;
4770
4771 MSafe_CallFunction(MSAFE_INVEN_REMOVE, &m);
4772
4773 float time = Game_GetTime();
4774 Obj_Value(me, VF_SET, OBJV_F_CREATION_TIME, &time);
4775 Obj_Value(me, VF_SET, OBJV_I_PARENT_HANDLE, &memory->my_player);
4776
4777 memory->next_ambient_time = Game_GetTime() + 1.2f;
4778
4779 // AI_AddGoal(me, AIG_MOVE_RELATIVE_OBJ_VEC, 0, 1.0f, -1, GF_KEEP_AT_COMPLETION, memory->my_player,
4780 // GST_FVEC); AI_SetGoalCircleDist(me, 0, 40.0f);
4781
4782 pos += orient.fvec * 200.0f;
4783
4784 AI_AddGoal(me, AIG_GET_TO_POS, 1, 1.0, -1, GF_USE_BLINE_IF_SEES_GOAL | GF_NOTIFIES, &pos, room);
4785 AI_SetGoalCircleDist(me, 1, 1.0f);
4786
4787 int s_id = Sound_FindId("GBExpulsionA");
4788 Sound_Play3d(memory->my_player, s_id);
4789
4790 memory->last_command = -1;
4791 } break;
4792 case GBM_AMBIENT: {
4793 ReInitAmbient(me);
4794 } break;
4795 case GBM_DOING_TASK:
4796 memory->last_retreat_time = memory->return_time = Game_GetTime();
4797 break;
4798 case GBM_KIDNAPPED:
4799 break;
4800 case GBM_TALKING:
4801 break;
4802 case GBM_THIEF:
4803 break;
4804 case GBM_ON_FIRE: {
4805 int flags;
4806
4807 // In general, Turn on friend avoidance
4808 flags = AIF_AUTO_AVOID_FRIENDS;
4809 AI_Value(me, VF_CLEAR_FLAGS, AIV_I_FLAGS, &flags);
4810
4811 DoMessage(TXT_GB_HELPMSG, true, "GBotConcern1");
4812
4813 int s_index = Sound_FindId("GBotHurt1");
4814 memory->sounds[GBS_VERY_DAMAGED] = Sound_Play3d(me, s_index);
4815
4816 AI_AddGoal(me, AIG_GET_TO_OBJ, 1, 1.0, -1, GF_KEEP_AT_COMPLETION | GF_NOTIFIES, memory->my_player);
4817 AI_SetGoalCircleDist(me, 1, -1.0f);
4818
4819 Obj_Burning(me, 1000000.0f, 1.0f);
4820 memory->flags = GBF_VERY_DAMAGED;
4821
4822 memory->f_pickup = true;
4823 } break;
4824 case GBM_MANUAL:
4825 break;
4826 case GBM_RTYPE: {
4827 // In general, Turn on friend avoidance
4828 int flags = AIF_AUTO_AVOID_FRIENDS;
4829 AI_Value(me, VF_CLEAR_FLAGS, AIV_I_FLAGS, &flags);
4830
4831 float acc = memory->max_acc * 4.0f;
4832 float speed = memory->max_speed * 1.6f;
4833 AI_Value(me, VF_SET, AIV_F_MAX_DELTA_SPEED, &acc);
4834 AI_Value(me, VF_SET, AIV_F_MAX_SPEED, &speed);
4835
4836 int room;
4837 vector pos;
4838 matrix orient;
4839
4840 Obj_Value(memory->my_player, VF_GET, OBJV_V_POS, &pos);
4841 Obj_Value(memory->my_player, VF_GET, OBJV_I_ROOMNUM, &room);
4842 Obj_Value(memory->my_player, VF_GET, OBJV_M_ORIENT, &orient);
4843
4844 pos += orient.fvec * 3.0f;
4845 pos -= orient.uvec * 10.0f;
4846
4847 memory->camera_obj = Obj_Create(OBJ_POWERUP, Obj_FindID("Invisiblepowerup"), room, &pos, &orient, me);
4848 msafe_struct mstruct;
4849 mstruct.objhandle = memory->camera_obj;
4850 MSafe_CallFunction(MSAFE_OBJECT_NO_RENDER, &mstruct);
4851
4852 AI_AddGoal(me, AIG_MOVE_RELATIVE_OBJ_VEC, 3, 1.0f, -1, GF_KEEP_AT_COMPLETION | GF_ORIENT_SCRIPTED,
4853 memory->camera_obj, GST_NEG_FVEC);
4854 // AI_SetGoalCircleDist(me, 3, 4.0f);
4855
4856 int hack_flags = AIF_GB_MIMIC_PLAYER_FIRING_HACK;
4857 AI_Value(me, VF_SET_FLAGS, AIV_I_FLAGS, &hack_flags);
4858 } break;
4859 case GBM_GO_WINGNUT: {
4860 AI_SetType(me, AIT_EVADER1);
4861 int flags = GF_ORIENT_TARGET;
4862 AI_GoalValue(me, 1, VF_SET_FLAGS, AIGV_I_FLAGS, &flags);
4863
4864 memory->next_ambient_time = Game_GetTime() + 1.0f;
4865
4866 // In general, Turn on friend avoidance
4867 flags = AIF_AUTO_AVOID_FRIENDS;
4868 AI_Value(me, VF_SET_FLAGS, AIV_I_FLAGS, &flags);
4869
4870 int dir_index = rand() % 6;
4871 float interval = 2.0f;
4872 AI_AddGoal(me, AIG_MOVE_RELATIVE_OBJ_VEC, 3, 1.0f, -1, GF_KEEP_AT_COMPLETION, memory->my_player, dir_index);
4873 AI_GoalAddEnabler(me, 3, AIE_GT_LAST_SEE_TARGET_INTERVAL, 1.0f, 0.0f, &interval);
4874
4875 Obj_WBValue(me, 3, VF_SET_FLAGS, WBV_I_DYNAMIC_FLAGS, &wbflags);
4876 } break;
4877 case GBM_EXTINGUISH:
4878
4879 AI_AddGoal(me, AIG_MOVE_RELATIVE_OBJ_VEC, 0, 1.0f, -1, GF_KEEP_AT_COMPLETION | GF_ORIENT_GOAL_OBJ,
4880 memory->extinguish_obj_list[0], 0);
4881
4882 AI_SetGoalCircleDist(me, 0, 20.0f);
4883 memory->extinguish_obj_time = 0.0f;
4884 memory->next_ambient_time = Game_GetTime() + 2.0f;
4885 break;
4886 }
4887
4888 memory->mode = mode;
4889 memory->sub_mode = GBSM_NONE;
4890
4891 // mprintf(0, "Mode is %d\n", memory->mode);
4892
4893 return true;
4894 }
4895
4896 bool GuideBot::InitExtinguish(bool f_player_on_fire) {
4897 vector pos;
4898 int room;
4899 int scan_objs[25];
4900 int n_scan;
4901 int i;
4902
4903 memory->num_extinguish_objs = 0;
4904 Obj_Value(memory->me, VF_GET, OBJV_V_POS, &pos);
4905 Obj_Value(memory->me, VF_GET, OBJV_I_ROOMNUM, &room);
4906
4907 n_scan = AI_GetNearbyObjs(&pos, room, 1000.0f, scan_objs, 25, false, false, false, true);
4908
4909 if (f_player_on_fire) {
4910 memory->extinguish_obj_list[memory->num_extinguish_objs++] = memory->my_player;
4911 }
4912
4913 // mprintf(0, "Scanned %d objects\n", n_scan);
4914 for (i = 0; i < n_scan; i++) {
4915 if (memory->num_extinguish_objs >= 5)
4916 break;
4917
4918 if (f_player_on_fire && scan_objs[i] == memory->my_player)
4919 break;
4920
4921 if (Obj_IsEffect(scan_objs[i], EF_NAPALMED)) {
4922 // mprintf(0, "its on fire\n");
4923 if (scan_objs[i] != memory->me) {
4924 if (!AI_IsObjEnemy(memory->me, scan_objs[i])) {
4925 // mprintf(0, "its not a enemy\n");
4926 memory->extinguish_obj_list[memory->num_extinguish_objs++] = scan_objs[i];
4927 }
4928 }
4929 }
4930 }
4931
4932 if (memory->num_extinguish_objs) {
4933 SetMode(memory->me, GBM_EXTINGUISH);
4934 return true;
4935 } else {
4936 return false;
4937 }
4938 }
4939
4940 int GuideBot::MakeCommandList(int *gbc_list) {
4941 int count = 0;
4942 int i;
4943
4944 if (memory->mode == GBM_IN_SHIP) {
4945 for (i = 0; i <= GBC_RENAME; i++) {
4946 if (!(memory->flags & GBF_VERY_DAMAGED) && i == GBC_REPAIR_GUIDEBOT)
4947 continue;
4948
4949 if ((memory->flags & GBF_VERY_DAMAGED) && i == GBC_EXIT_SHIP)
4950 continue;
4951
4952 gbc_list[count++] = i;
4953 }
4954 } else if (memory->mode == GBM_AMBIENT) {
4955 int roomnum;
4956 Obj_Value(memory->me, VF_GET, OBJV_I_ROOMNUM, &roomnum);
4957
4958 LGoal_Value(VF_GET, LGV_I_NUM_ACTIVE_PRIMARIES, &memory->num_pg);
4959 LGoal_Value(VF_GET, LGV_I_NUM_ACTIVE_SECONDARIES, &memory->num_sg);
4960
4961 for (i = GBC_FIND_ACTIVE_GOAL_0; i < NUM_GB_COMMANDS; i++) {
4962 if (i >= GBC_FIND_ACTIVE_GOAL_0 && i <= GBC_FIND_ACTIVE_GOAL_7) {
4963 if (!(i - GBC_FIND_ACTIVE_GOAL_0 < memory->num_pg))
4964 continue;
4965 } else if (i >= GBC_FIND_ACTIVE_SEC_GOAL_0 && i <= GBC_FIND_ACTIVE_SEC_GOAL_7) {
4966 if (!(i - GBC_FIND_ACTIVE_SEC_GOAL_0 < memory->num_sg))
4967 continue;
4968 } else if (i >= GBC_FIND_MARKER_0 && i <= GBC_FIND_MARKER_7) {
4969 if (Obj_MakeListOfType(memory->me, OBJ_MARKER, i - GBC_FIND_MARKER_0, false, OBJECT_HANDLE_NONE, 1,
4970 &memory->g_powerup) == 0)
4971 continue;
4972 } else if (i == GBC_FIND_SPEW) {
4973 int handle;
4974 if (Obj_MakeListOfType(memory->me, OBJ_POWERUP, -1, false, memory->my_player, 1, &handle) == 0)
4975 continue;
4976 } else if (i == GBC_FIND_POWERUP) {
4977 int handle;
4978 if (Obj_MakeListOfType(memory->me, OBJ_POWERUP, -1, false, OBJECT_HANDLE_NONE, 1, &handle) == 0)
4979 continue;
4980 } else if (i == GBC_FIND_ROBOT) {
4981 int handle;
4982 if (Obj_MakeListOfType(memory->me, OBJ_ROBOT, -1, false, OBJECT_HANDLE_NONE, 1, &handle) == 0)
4983 continue;
4984 } else if (i == GBC_FIND_THIEF) {
4985 int id = Obj_FindID("Thief");
4986 int handle;
4987
4988 if (id < 0 || Obj_MakeListOfType(memory->me, OBJ_ROBOT, id, false, OBJECT_HANDLE_NONE, 1, &handle) == 0)
4989 continue;
4990 } else if (i == GBC_FIND_CLOSEST_MARKER) {
4991 int handle;
4992 if (Obj_MakeListOfType(memory->me, OBJ_MARKER, -1, false, memory->my_player, 1, &handle) == 0)
4993 continue;
4994 } else if (i >= GB_POW_STRING_OFFSET && i < GB_POW_STRING_OFFSET + NUM_GB_USABLE_POWERUPS) {
4995 if (memory->powerups[i - GB_POW_STRING_OFFSET] <= 0)
4996 continue;
4997 } else if (i == GBC_FIND_OUTSIDE /*&& (0x80000000 & roomnum)*/)
4998 continue;
4999 else if (i == GBC_FIND_MINE /*&& !(0x80000000 & roomnum)*/)
5000 continue;
5001 else if (i == GBC_NO_CHATTER && (memory->flags & GBF_NO_CHATTER))
5002 continue;
5003 else if (i == GBC_ALLOW_CHATTER && !(memory->flags & GBF_NO_CHATTER))
5004 continue;
5005
5006 gbc_list[count++] = i;
5007 }
5008 }
5009
5010 return count;
5011 }
5012
5013 void GuideBot::AddGetToGoalCommonGoals(int me) {
5014 AI_AddGoal(me, AIG_MOVE_RELATIVE_OBJ_VEC, 2, 1.0f, -1, GF_ORIENT_GOAL_OBJ, memory->my_player, GST_NEG_FVEC);
5015 AI_AddGoal(me, AIG_GET_TO_OBJ, 3, 1.0f, -1, GF_ORIENT_VELOCITY | GF_NOTIFIES, memory->my_player);
5016 AI_SetGoalCircleDist(me, 3, 20.0f);
5017 }
5018
5019 bool GuideBot::DoExternalCommands(int me, gb_com *command, int it) {
5020 int g_robot;
5021 int roomnum;
5022 vector pos;
5023 int flags;
5024
5025 mprintf(0, "Command %d for GB\n", command->action);
5026
5027 // In general, Turn on friend avoidance
5028 flags = AIF_AUTO_AVOID_FRIENDS;
5029 AI_Value(me, VF_SET_FLAGS, AIV_I_FLAGS, &flags);
5030
5031 if (command->action == COM_REINIT) {
5032 return DoInit(me, true);
5033 } else if (command->action == COM_DO_ACTION) {
5034 int param1 = command->index;
5035 // mprintf(0, "P is %d\n", param1);
5036
5037 memory->last_command = param1;
5038
5039 if ((param1 >= GBC_FIND_ACTIVE_GOAL_0 && param1 <= GBC_FIND_ACTIVE_GOAL_7) ||
5040 (param1 >= GBC_FIND_ACTIVE_SEC_GOAL_0 && param1 <= GBC_FIND_ACTIVE_SEC_GOAL_7)) {
5041 int g_id;
5042 int flags;
5043 char type;
5044 int rhandle[32];
5045 bool rdone[32];
5046 int handle[32];
5047 bool done[32];
5048 int i;
5049 int rnum_items;
5050 int num_items;
5051
5052 if (param1 >= GBC_FIND_ACTIVE_GOAL_0 && param1 <= GBC_FIND_ACTIVE_GOAL_7)
5053 LGoal_Value(VF_GET, LGSV_I_ACTIVE_PRIMARY_GOAL, &g_id, param1 - GBC_FIND_ACTIVE_GOAL_0);
5054 else
5055 LGoal_Value(VF_GET, LGSV_I_ACTIVE_SECONDARY_GOAL, &g_id, param1 - GBC_FIND_ACTIVE_SEC_GOAL_0);
5056
5057 LGoal_Value(VF_GET, LGSV_I_STATUS, &flags, g_id);
5058 LGoal_Value(VF_GET, LGSSV_C_ITEM_TYPE, &type, g_id, 0);
5059
5060 LGoal_Value(VF_GET, LGSV_I_NUM_ITEMS, &rnum_items, g_id);
5061
5062 for (i = 0; i < rnum_items; i++) {
5063 LGoal_Value(VF_GET, LGSSV_I_ITEM_HANDLE, &rhandle[i], g_id, i);
5064 LGoal_Value(VF_GET, LGSSV_B_ITEM_DONE, &rdone[i], g_id, i);
5065 }
5066
5067 num_items = 0;
5068 for (i = 0; i < rnum_items; i++) {
5069 if (!rdone[i]) {
5070 handle[num_items++] = rhandle[i];
5071 }
5072 }
5073
5074 if (num_items == 0) {
5075 num_items = 1;
5076 handle[0] = rhandle[0];
5077 }
5078
5079 if (flags & LGF_NOT_LOC_BASED) {
5080 DoMessage(TXT_GB_NOTLOCATION, true, "GBotConcern1");
5081 } else if (flags & LGF_GB_DOESNT_KNOW_LOC) {
5082 DoMessage(TXT_GB_NONAV, true, "GBotConcern1");
5083 } else if (type == LIT_OBJECT) {
5084 bool f_ok = false;
5085
5086 for (i = 0; i < num_items; i++) // chrishack - do distance check (should be trial)
5087 {
5088 int type;
5089 Obj_Value(handle[i], VF_GET, OBJV_I_TYPE, &type);
5090
5091 if (type != OBJ_NONE && AI_IsObjReachable(me, handle[i])) {
5092 DoMessage(TXT_GB_ONMYWAY, false, "GBotAcceptOrder1");
5093 AI_AddGoal(me, AIG_GET_TO_OBJ, 1, 1.0f, -1, GF_KEEP_AT_COMPLETION | GF_NOTIFIES, handle[i]);
5094 AI_SetGoalCircleDist(me, 1, 20.0f);
5095 AddGetToGoalCommonGoals(me);
5096 f_ok = true;
5097 break;
5098 }
5099 }
5100
5101 if (!f_ok) {
5102 DoMessage(TXT_GB_NOTREACH, true, "GBotConcern1");
5103 }
5104 } else if (type == LIT_INTERNAL_ROOM) {
5105 if (AI_IsDestReachable(me, handle[0])) {
5106 vector pnt;
5107 Room_Value(handle[0], VF_GET, RMSV_V_PORTAL_PATH_PNT, &pnt);
5108 AI_AddGoal(me, AIG_GET_TO_POS, 1, 1.0, -1, GF_KEEP_AT_COMPLETION | GF_NOTIFIES, &pnt, handle[0]);
5109 AI_SetGoalCircleDist(me, 1, 20.0f);
5110 AddGetToGoalCommonGoals(me);
5111
5112 DoMessage(TXT_GB_ONMYWAY, false, "GBotAcceptOrder1");
5113 } else {
5114 DoMessage(TXT_GB_NOTREACH, true, "GBotConcern1");
5115 }
5116 } else if (type == LIT_TRIGGER) {
5117
5118 int room = Scrpt_GetTriggerRoom(handle[0]);
5119 int face = Scrpt_GetTriggerFace(handle[0]);
5120
5121 if (AI_IsDestReachable(me, room)) {
5122 vector pnt;
5123 vector normal;
5124 Room_Value(room, VF_GET, RMSV_V_FACE_CENTER_PNT, &pnt, face);
5125 Room_Value(room, VF_GET, RMSV_V_FACE_NORMAL, &normal, face);
5126
5127 pnt += (normal * 5.0f);
5128
5129 AI_AddGoal(me, AIG_GET_TO_POS, 1, 1.0, -1, GF_KEEP_AT_COMPLETION | GF_NOTIFIES, &pnt, room);
5130 AI_SetGoalCircleDist(me, 1, 20.0f);
5131 AddGetToGoalCommonGoals(me);
5132
5133 DoMessage(TXT_GB_ONMYWAY, false, "GBotAcceptOrder1");
5134 } else {
5135 DoMessage(TXT_GB_NOTREACH, true, "GBotConcern1");
5136 }
5137 }
5138 } else if (param1 == GBC_RETURN_TO_SHIP) {
5139 int flags;
5140
5141 // Turn off friend avoidance
5142 flags = AIF_AUTO_AVOID_FRIENDS;
5143 AI_Value(me, VF_CLEAR_FLAGS, AIV_I_FLAGS, &flags);
5144
5145 DoMessage(TXT_GB_ENTERSHIP, false, "GBotAcceptOrder1");
5146 AI_AddGoal(me, AIG_GET_TO_OBJ, 1, 1.0, -1, GF_KEEP_AT_COMPLETION | GF_NOTIFIES, memory->my_player);
5147 AI_SetGoalCircleDist(me, 1, -10.0f);
5148 memory->f_pickup = true;
5149 } else if (param1 == GBC_ESCORT_SHIP) {
5150 DoMessage(TXT_GB_ESCORT, false, "GBotAcceptOrder1");
5151 SetMode(me, GBM_AMBIENT);
5152 } else if (param1 == GBC_FIND_ROBOT) {
5153
5154 g_robot = AI_FindObjOfType(me, OBJ_ROBOT, -1, false);
5155
5156 if (g_robot != OBJECT_HANDLE_NONE) {
5157 DoMessage(TXT_GB_FINDROBOT, false, "GBotAcceptOrder1");
5158 AI_AddGoal(me, AIG_GET_TO_OBJ, 1, 1.0, -1, GF_KEEP_AT_COMPLETION | GF_NOTIFIES, g_robot);
5159 AI_SetGoalCircleDist(me, 1, 30.0f);
5160 AddGetToGoalCommonGoals(me);
5161 } else {
5162 DoMessage(TXT_GB_NOROBOT, true, "GBotConcern1");
5163 }
5164 } else if (param1 == GBC_FIND_POWERUP) {
5165
5166 memory->g_powerup = AI_FindObjOfType(me, OBJ_POWERUP, -1, false);
5167
5168 if (memory->g_powerup != OBJECT_HANDLE_NONE) {
5169 DoMessage(TXT_GB_FINDPOWERUP, false, "GBotAcceptOrder1");
5170 AI_AddGoal(me, AIG_GET_TO_OBJ, 1, 1.0f, -1, GF_KEEP_AT_COMPLETION | GF_NOTIFIES, memory->g_powerup);
5171 AI_SetGoalCircleDist(me, 1, 3.0f);
5172 AddGetToGoalCommonGoals(me);
5173 } else {
5174 DoMessage(TXT_GB_NOPOWERUP, true, "GBotConcern1");
5175 }
5176 } else if (param1 == GBC_FIND_CLOSEST_MARKER) {
5177
5178 memory->g_powerup = AI_FindObjOfType(me, OBJ_MARKER, -1, false, memory->my_player);
5179
5180 if (memory->g_powerup != OBJECT_HANDLE_NONE) {
5181 char message[256];
5182 char marker_message[256];
5183
5184 Obj_Value(memory->g_powerup, VF_GET, OBJV_PC_MARKER_MESSAGE, marker_message);
5185
5186 if (strlen(marker_message) > 20) {
5187 marker_message[17] = '\0';
5188
5189 while (strlen(marker_message) > 0 && marker_message[strlen(marker_message) - 1] == ' ') {
5190 marker_message[strlen(marker_message) - 1] = '\0';
5191 }
5192
5193 strcat(marker_message, "...");
5194 }
5195
5196 snprintf(message, sizeof(message), TXT_GB_GOMARKER, marker_message);
5197 DoMessage(message, false, "GBotAcceptOrder1");
5198
5199 AI_AddGoal(me, AIG_GET_TO_OBJ, 1, 1.0f, -1, GF_KEEP_AT_COMPLETION | GF_NOTIFIES, memory->g_powerup);
5200 AI_SetGoalCircleDist(me, 1, 3.0f);
5201 AddGetToGoalCommonGoals(me);
5202 } else {
5203 DoMessage(TXT_GB_NOMARKER, true, "GBotConcern1");
5204 }
5205 } else if (param1 >= GBC_FIND_MARKER_0 && param1 <= GBC_FIND_MARKER_7) {
5206 memory->g_powerup = AI_FindObjOfType(me, OBJ_MARKER, param1 - GBC_FIND_MARKER_0, false, memory->my_player);
5207
5208 if (memory->g_powerup != OBJECT_HANDLE_NONE) {
5209 char message[256];
5210 char marker_message[256];
5211
5212 Obj_Value(memory->g_powerup, VF_GET, OBJV_PC_MARKER_MESSAGE, marker_message);
5213
5214 if (/*strlen(marker_message) > 20*/ 0) {
5215 marker_message[17] = '\0';
5216
5217 while (strlen(marker_message) > 0 && marker_message[strlen(marker_message) - 1] == ' ') {
5218 marker_message[strlen(marker_message) - 1] = '\0';
5219 }
5220
5221 strcat(marker_message, "...");
5222 }
5223
5224 snprintf(message, sizeof(message), TXT_GB_GOMARKER, marker_message);
5225 DoMessage(message, false, "GBotAcceptOrder1");
5226
5227 AI_AddGoal(me, AIG_GET_TO_OBJ, 1, 1.0f, -1, GF_KEEP_AT_COMPLETION | GF_NOTIFIES, memory->g_powerup);
5228 AI_SetGoalCircleDist(me, 1, 3.0f);
5229 AddGetToGoalCommonGoals(me);
5230 } else {
5231 DoMessage(TXT_GB_NOMARK, true, "GBotConcern1");
5232 }
5233 } else if (param1 == GBC_FIND_THIEF) {
5234 int id = Obj_FindID("Thief");
5235
5236 memory->g_powerup = AI_FindObjOfType(me, OBJ_ROBOT, id, false);
5237
5238 if (memory->g_powerup != OBJECT_HANDLE_NONE) {
5239 if (rand() > RAND_MAX / 2)
5240 DoMessage(TXT_GB_FINDTHIEF, false, "GBotAcceptOrder1");
5241 else
5242 DoMessage(TXT_GB_FOUNDTHIEF, false, "GBotAcceptOrder1");
5243
5244 AI_AddGoal(me, AIG_GET_TO_OBJ, 1, 1.0f, -1, GF_KEEP_AT_COMPLETION | GF_NOTIFIES, memory->g_powerup);
5245 AI_SetGoalCircleDist(me, 1, 3.0f);
5246 AddGetToGoalCommonGoals(me);
5247 } else {
5248 DoMessage(TXT_GB_NOTHIEF, true, "GBotConcern1");
5249 }
5250 } else if (param1 == GBC_FIND_SPEW) {
5251 memory->g_powerup = AI_FindObjOfType(me, OBJ_POWERUP, -1, false, memory->my_player);
5252
5253 if (memory->g_powerup != OBJECT_HANDLE_NONE) {
5254 DoMessage(TXT_GB_FINDPOWERUPS, false, "GBotAcceptOrder1");
5255 AI_AddGoal(me, AIG_GET_TO_OBJ, 1, 1.0f, -1, GF_KEEP_AT_COMPLETION | GF_NOTIFIES, memory->g_powerup);
5256 AI_SetGoalCircleDist(me, 1, 3.0f);
5257 AddGetToGoalCommonGoals(me);
5258 } else {
5259 DoMessage(TXT_GB_NOMESSAGE, true, "GBotConcern1");
5260 }
5261 } else if (param1 == GBC_NO_CHATTER) {
5262 memory->flags |= GBF_NO_CHATTER;
5263 DoMessage(TXT_GB_CHATOFF, true, "GBotConcern1");
5264 } else if (param1 == GBC_ALLOW_CHATTER) {
5265 memory->flags &= (~GBF_NO_CHATTER);
5266 DoMessage(TXT_GB_CHATON, false, "GBotAcceptOrder1");
5267 } else if (param1 == GBC_FIND_ENERGY_CENTER) {
5268 roomnum = AI_FindEnergyCenter(me);
5269 char f_used;
5270 Room_Value(roomnum, VF_GET, RMV_C_USED, &f_used);
5271
5272 if (f_used != 0) {
5273 Room_Value(roomnum, VF_GET, RMSV_V_PATH_PNT, &pos, 1);
5274 AI_AddGoal(me, AIG_GET_TO_POS, 1, 1.0, -1, GF_KEEP_AT_COMPLETION | GF_NOTIFIES, &pos, roomnum);
5275 AI_SetGoalCircleDist(me, 1, 20.0f);
5276 AddGetToGoalCommonGoals(me);
5277
5278 DoMessage(TXT_GB_FINDENERGY, false, "GBotAcceptOrder1");
5279 } else {
5280 DoMessage(TXT_GB_NOENERGY, true, "GBotConcern1");
5281 }
5282 } else if (param1 == GBC_REPAIR_GUIDEBOT) {
5283 float shields;
5284 Obj_Value(memory->my_player, VF_GET, OBJV_F_SHIELDS, &shields);
5285
5286 if (shields >= 5 + 5 * Game_GetDiffLevel()) {
5287 shields -= 5 + 5 * Game_GetDiffLevel();
5288
5289 memory->flags &= (~GBF_VERY_DAMAGED);
5290 Obj_Value(memory->my_player, VF_SET, OBJV_F_SHIELDS, &shields);
5291
5292 DoMessage(TXT_GB_REPAIRED, false, "GBotAcceptOrder1", true);
5293
5294 float gb_shields = 250;
5295 int flags = OF_AI_DEATH;
5296
5297 Obj_Value(me, VF_CLEAR_FLAGS, OBJV_I_FLAGS, &flags);
5298 Obj_Value(me, VF_SET, OBJV_F_SHIELDS, &gb_shields);
5299
5300 flags = AIF_AUTO_AVOID_FRIENDS;
5301 AI_Value(me, VF_SET_FLAGS, AIV_I_FLAGS, &flags);
5302 Obj_Burning(me, 0.0f, 0.0f);
5303 } else {
5304 DoMessage(TXT_GB_NOTENSH, true, "GBotConcern1", true);
5305 }
5306 } else if (param1 == GBC_EXIT_SHIP) {
5307 tOSIRISEventInfo ei;
5308 Obj_CallEvent(me, EVT_USE, &ei);
5309 } else if (param1 >= GB_POW_STRING_OFFSET && param1 < GB_POW_STRING_OFFSET + NUM_GB_USABLE_POWERUPS) {
5310 char pow_message[50];
5311 bool f_do = true;
5312
5313 if (memory->powerups[param1 - GB_POW_STRING_OFFSET] > 0) {
5314 switch (param1 - GB_POW_STRING_OFFSET) {
5315 case GB_POW_FIRE: {
5316 int room;
5317 float damage = 0.0f;
5318 Obj_Value(memory->my_player, VF_GET, OBJV_I_ROOMNUM, &room);
5319 Room_Value(room, VF_GET, RMV_F_DAMAGE, &damage);
5320 if (damage == 0.0f) {
5321 f_do = InitExtinguish(false);
5322 } else {
5323 int s_id = Sound_FindId("GBotConcern1");
5324 Sound_Play2d(memory->my_player, s_id);
5325
5326 return true;
5327 }
5328 } break;
5329
5330 case GB_POW_ANTIVIRUS: {
5331 vector pos;
5332 int room;
5333 int n_scan;
5334 int scan_objs[25];
5335 int n_converted = 0;
5336 int i;
5337
5338 Obj_Value(memory->me, VF_GET, OBJV_V_POS, &pos);
5339 Obj_Value(memory->me, VF_GET, OBJV_I_ROOMNUM, &room);
5340
5341 n_scan = AI_GetNearbyObjs(&pos, room, 500.0f, scan_objs, 25, false, false, false, true);
5342
5343 for (i = 0; i < n_scan; i++) {
5344 if (n_converted > 2)
5345 break;
5346
5347 if (memory->num_av_robots >= MAX_AV_ROBOTS)
5348 break;
5349
5350 if (scan_objs[i] != memory->me) {
5351 if (AI_IsObjEnemy(memory->me, scan_objs[i])) {
5352 ray_info ray;
5353 int flags;
5354 int fate;
5355 vector end_pos;
5356
5357 Obj_Value(scan_objs[i], VF_GET, OBJV_V_POS, &end_pos);
5358
5359 flags = FQ_CHECK_OBJS | FQ_IGNORE_POWERUPS | FQ_IGNORE_WEAPONS | FQ_IGNORE_MOVING_OBJECTS |
5360 FQ_IGNORE_NON_LIGHTMAP_OBJECTS;
5361 fate = FVI_RayCast(me, &pos, &end_pos, room, 1.0f, flags, &ray);
5362
5363 if (fate == HIT_NONE) {
5364 msafe_struct mstruct;
5365 int type;
5366
5367 Obj_Value(memory->me, VF_GET, OBJV_I_ROOMNUM, &mstruct.roomnum);
5368 Obj_Value(memory->me, VF_GET, OBJV_V_POS, &mstruct.pos);
5369 Obj_Value(scan_objs[i], VF_GET, OBJV_V_POS, &mstruct.pos2);
5370
5371 mstruct.objhandle = memory->me;
5372 mstruct.ithandle = scan_objs[i];
5373 mstruct.lifetime = 3.5f;
5374 mstruct.size = 3.0f;
5375
5376 mstruct.interval = 0.2f;
5377 mstruct.count = 2;
5378 mstruct.index = 4;
5379 mstruct.texnum = Scrpt_FindTextureName("FunkyEffectAntiV");
5380 mstruct.color = ((128 >> 3) << 10) | ((128 >> 3) << 5) | (128 >> 3);
5381
5382 mstruct.state = 0;
5383 mstruct.flags = 0;
5384
5385 MSafe_CallFunction(MSAFE_WEATHER_LIGHTNING_BOLT, &mstruct);
5386
5387 Obj_Value(memory->me, VF_GET, OBJV_I_ROOMNUM, &mstruct.roomnum);
5388 Obj_Value(memory->me, VF_GET, OBJV_V_POS, &mstruct.pos);
5389 Obj_Value(scan_objs[i], VF_GET, OBJV_V_POS, &mstruct.pos2);
5390
5391 int flags = AIF_TEAM_MASK;
5392 AI_Value(scan_objs[i], VF_CLEAR_FLAGS, AIV_I_FLAGS, &flags);
5393 flags = AIF_TEAM_REBEL;
5394 AI_Value(scan_objs[i], VF_SET_FLAGS, AIV_I_FLAGS, &flags);
5395
5396 int target_handle = OBJECT_HANDLE_NONE;
5397 AI_Value(scan_objs[i], VF_SET, AIV_I_TARGET_HANDLE, &target_handle);
5398
5399 memory->av_revert_time[memory->num_av_robots] = Game_GetTime() + 30.0f;
5400 memory->av_robot_list[memory->num_av_robots++] = scan_objs[i];
5401
5402 n_converted++;
5403 }
5404 }
5405 }
5406 }
5407
5408 f_do = (n_converted > 0);
5409 } break;
5410
5411 case GB_POW_WINGNUT: {
5412 SetMode(me, GBM_GO_WINGNUT);
5413 f_do = true;
5414 } break;
5415
5416 case GB_POW_RTYPE: {
5417 SetMode(me, GBM_RTYPE);
5418 f_do = true;
5419 } break;
5420
5421 case GB_POW_SPEED: {
5422 float speed;
5423 float acc;
5424 AI_Value(me, VF_GET, AIV_F_MAX_DELTA_SPEED, &acc);
5425 AI_Value(me, VF_GET, AIV_F_MAX_SPEED, &speed);
5426
5427 if (acc == memory->max_acc && speed == memory->max_speed) {
5428 speed *= 3.0f;
5429 acc *= 6.0f;
5430
5431 memory->speed_time_left = 30.0f;
5432
5433 AI_Value(me, VF_SET, AIV_F_MAX_DELTA_SPEED, &acc);
5434 AI_Value(me, VF_SET, AIV_F_MAX_SPEED, &speed);
5435
5436 f_do = true;
5437 } else {
5438 f_do = false;
5439 }
5440
5441 } break;
5442 }
5443
5444 if (f_do) {
5445 snprintf(pow_message, sizeof(pow_message), "%s", TXT(gb_pow_text[param1 - GB_POW_STRING_OFFSET]));
5446 DoMessage(pow_message, false, "GBotAcceptOrder1");
5447 memory->powerups[param1 - GB_POW_STRING_OFFSET]--;
5448 } else {
5449 snprintf(pow_message, sizeof(pow_message), "%s", TXT(gb_pow_not_text[param1 - GB_POW_STRING_OFFSET]));
5450 DoMessage(pow_message, false, "GBotConcern1");
5451 }
5452 } else {
5453 DoMessage(TXT_GB_DONT_HAVE_POWERUP, false, "GBotConcern1");
5454 }
5455 } else if (param1 == GBC_RENAME) {
5456 char str[80];
5457 if (strlen((char *)command->ptr) > 0) {
5458 strncpy(memory->name, (char *)command->ptr, 7);
5459 memory->name[7] = '\0';
5460 Player_Value(memory->my_player, VF_SET, PLYV_CS_GUIDEBOTNAME, memory->name);
5461
5462 snprintf(str, sizeof(str), TXT_GB_NEWNAME, (char *)command->ptr);
5463 DoMessage(str, true, "GBotAcceptOrder1");
5464 } else {
5465 snprintf(str, sizeof(str), TXT_GB_NOWAY, (char *)command->ptr);
5466 DoMessage(str, true, "GBotConcern1");
5467 }
5468 } else if (param1 == GBC_RENAME_SILENT) {
5469 if (strlen((char *)command->ptr) > 0) {
5470 strncpy(memory->name, (char *)command->ptr, 7);
5471 memory->name[7] = '\0';
5472 }
5473 } else {
5474 char str[80];
5475 snprintf(str, sizeof(str), TXT_GB_STRIKE, param1);
5476 DoMessage(str, true, "GBotConern1", true);
5477 }
5478 } else if (command->action == COM_GET_MENU) {
5479 int i;
5480 gb_menu *menu = (gb_menu *)command->ptr;
5481 int cur_command = 0;
5482
5483 strcpy(menu->title, TXT_GB_MENUTITLE);
5484
5485 int gbc_list[NUM_GB_COMMANDS];
5486 menu->num_commands = MakeCommandList(gbc_list);
5487
5488 for (i = 0; i < menu->num_commands; i++) {
5489 int c_index = gbc_list[i];
5490
5491 if (c_index >= GBC_FIND_MARKER_0 && c_index <= GBC_FIND_MARKER_7) {
5492 memory->g_powerup = AI_FindObjOfType(me, OBJ_MARKER, c_index - GBC_FIND_MARKER_0, false, memory->my_player);
5493
5494 char message[256];
5495 char marker_message[256];
5496
5497 Obj_Value(memory->g_powerup, VF_GET, OBJV_PC_MARKER_MESSAGE, marker_message);
5498
5499 if (/*strlen(marker_message) > 12*/ 0) {
5500 marker_message[11] = '\0';
5501
5502 while (strlen(marker_message) > 0 && marker_message[strlen(marker_message) - 1] == ' ') {
5503 marker_message[strlen(marker_message) - 1] = '\0';
5504 }
5505
5506 strcat(marker_message, "...");
5507 }
5508
5509 snprintf(message, sizeof(message), TXT_GB_FINDMARKMENU, marker_message);
5510 strcpy(menu->command_text[i], message);
5511 } else if (c_index >= GBC_FIND_ACTIVE_GOAL_0 && c_index <= GBC_FIND_ACTIVE_GOAL_7) {
5512 int g_id;
5513 char message[256];
5514
5515 LGoal_Value(VF_GET, LGSV_I_ACTIVE_PRIMARY_GOAL, &g_id, c_index - GBC_FIND_ACTIVE_GOAL_0);
5516 LGoal_Value(VF_GET, LGSV_PC_LOCATION_NAME, &message, g_id);
5517
5518 if (/* strlen(message) > 19 */ 0) {
5519 message[18] = '\0';
5520
5521 while (strlen(message) > 0 && message[strlen(message) - 1] == ' ') {
5522 message[strlen(message) - 1] = '\0';
5523 }
5524
5525 strcat(message, "...");
5526 }
5527 snprintf(menu->command_text[i], sizeof(menu->command_text[i]), TXT_GB_GETTO, message);
5528 } else if (c_index >= GBC_FIND_ACTIVE_SEC_GOAL_0 && c_index <= GBC_FIND_ACTIVE_SEC_GOAL_7) {
5529 int g_id;
5530 char message[256];
5531
5532 LGoal_Value(VF_GET, LGSV_I_ACTIVE_SECONDARY_GOAL, &g_id, c_index - GBC_FIND_ACTIVE_SEC_GOAL_0);
5533 LGoal_Value(VF_GET, LGSV_PC_LOCATION_NAME, &message, g_id);
5534
5535 if (/*strlen(message) > 19*/ 0) {
5536 message[18] = '\0';
5537
5538 while (strlen(message) > 0 && message[strlen(message) - 1] == ' ') {
5539 message[strlen(message) - 1] = '\0';
5540 }
5541
5542 strcat(message, "...");
5543 }
5544 snprintf(menu->command_text[i], sizeof(menu->command_text[i]), TXT_GB_GETTO, message);
5545 } else
5546 strcpy(menu->command_text[i], TXT(gb_command_text[gbc_list[i]]));
5547
5548 if (gbc_list[i] == GBC_REPAIR_GUIDEBOT) {
5549 char message[256];
5550 snprintf(message, sizeof(message), TXT_GB_SHIELDAMOUNT, 5 + 5 * Game_GetDiffLevel());
5551 strcat(menu->command_text[i], message);
5552 }
5553
5554 menu->command_id[i] = gbc_list[i];
5555 menu->command_type[i] = GBCT_EXIT_IMMEDIATELY;
5556
5557 if (gbc_list[i] == GBC_RENAME) {
5558 menu->command_type[i] = GBCT_STRING_DIALOG;
5559 strcpy(menu->dialog_text[i], TXT_GB_ENTERNAME);
5560 }
5561 }
5562 } else if (command->action == COM_POWERUP_NOTIFY) {
5563 SetSubMode(me, GBSM_GET_POWERUP, it);
5564 } else if (command->action == COM_POWERUP_PICKUP) {
5565 int type = command->index;
5566
5567 if (type >= 0 && type <= 5) {
5568 int s_id = Sound_FindId("Powerup pickup");
5569 Sound_Play3d(me, s_id);
5570
5571 if (type == GB_POW_SPEED) {
5572 float speed;
5573 float acc;
5574 AI_Value(me, VF_GET, AIV_F_MAX_DELTA_SPEED, &acc);
5575 AI_Value(me, VF_GET, AIV_F_MAX_SPEED, &speed);
5576
5577 if (acc == memory->max_acc && speed == memory->max_speed) {
5578 speed *= 3.0f;
5579 acc *= 6.0f;
5580
5581 memory->speed_time_left = 30.0f;
5582
5583 AI_Value(me, VF_SET, AIV_F_MAX_DELTA_SPEED, &acc);
5584 AI_Value(me, VF_SET, AIV_F_MAX_SPEED, &speed);
5585 }
5586 } else {
5587 memory->powerups[type]++;
5588 }
5589
5590 msafe_struct mo;
5591 mo.objhandle = it;
5592 MSafe_CallFunction(MSAFE_OBJECT_REMOVE, &mo);
5593
5594 DoMessage(TXT(gb_pow_pickup_text[type]), true, "GBotExcited1");
5595 SetSubMode(me, GBSM_NONE);
5596 }
5597 }
5598
5599 return true;
5600 }
5601
5602 void GuideBot::DoCollide(int me, tOSIRISEVTCOLLIDE *evt_collide) {
5603 int obj_type;
5604 int its_parent;
5605 float rand_val;
5606
5607 int it_type;
5608 Obj_Value(evt_collide->it_handle, VF_GET, OBJV_I_TYPE, &it_type);
5609
5610 rand_val = (float)rand() / (float)RAND_MAX;
5611
5612 // Add a buddy bot to you inventory :)
5613 if (memory->f_pickup == true) {
5614 if (it_type == OBJ_PLAYER) {
5615 uint16_t id;
5616 Obj_Value(evt_collide->it_handle, VF_GET, OBJV_US_ID, &id);
5617
5618 if (id == memory->mp_slot) {
5619 SetMode(me, GBM_ENTER_SHIP);
5620 }
5621 }
5622 } else {
5623 // Run back to the player when you get hit
5624 if (it_type == OBJ_WEAPON) {
5625 // 30% of the time - and not within 5 seconds - the buddy will come
5626 // back to the player for protection
5627
5628 Obj_Value(evt_collide->it_handle, VF_GET, OBJV_I_PARENT_HANDLE, &its_parent);
5629
5630 if (its_parent == memory->my_player) {
5631 if (rand_val > 0.8f) {
5632 DoMessage(TXT_GBHIT1, false, "GBotConcern1");
5633 } else if (rand_val > 0.6) {
5634 DoMessage(TXT_GBHIT2, false, "GBotConcern1");
5635 } else if (rand_val > 0.4) {
5636 DoMessage(TXT_GBHIT3, false, "GBotConcern1");
5637 }
5638 } else if (memory->last_retreat_time + 5.0 < Game_GetTime())
5639 ;
5640 {
5641 if (rand_val > 0.7) {
5642 AI_AddGoal(me, AIG_GET_TO_OBJ, 2, 1.0f, -1, 0, memory->my_player);
5643 AI_SetGoalCircleDist(me, 2, 40.0f);
5644
5645 memory->last_retreat_time = Game_GetTime();
5646
5647 DoMessage(TXT_GBHIT4, true, "GBotConcern1");
5648 } else {
5649 DoMessage(TXT_GBHIT5, true, "GBotConcern1");
5650 }
5651 }
5652 }
5653 }
5654 }
5655
5656 bool GuideBot::DoUse(int me) {
5657 int p_handle;
5658 int sad_sound;
5659 int buddy_handle;
5660
5661 // NOTE: Use is done on the inventory item and/or the real guidebot
5662 // don't set and guidebot global variables in here. Do it in the
5663 // EVT_CREATE in the f_valid block
5664
5665 gb_com command;
5666
5667 Obj_Value(me, VF_GET, OBJV_I_PARENT_HANDLE, &p_handle);
5668
5669 if (p_handle == OBJECT_HANDLE_NONE) {
5670 p_handle = memory->my_player;
5671 } else {
5672 memory->my_player = p_handle;
5673 }
5674
5675 mprintf(0, "1 Player %d\n", p_handle);
5676 mprintf(0, "2 Player %d\n", memory->my_player);
5677
5678 Player_Value(p_handle, VF_GET, PLYV_I_BUDDY_HANDLE, &buddy_handle);
5679
5680 command.action = COM_REINIT;
5681 tOSIRISEventInfo ei;
5682 ei.extra_info = (void *)&command;
5683 ei.evt_ai_notify.notify_type = AIN_USER_DEFINED;
5684
5685 return Obj_CallEvent(buddy_handle, EVT_AI_NOTIFY, &ei);
5686 }
5687
5688 bool GuideBot::DoInit(int me, bool f_reinit) {
5689 vector fvec;
5690 vector vel;
5691 bool f_valid;
5692 matrix orient;
5693 vector pos;
5694 int room;
5695 int i;
5696
5697 tOSIRISMEMCHUNK ch;
5698 ch.id = 4;
5699 ch.size = sizeof(guidebot_data);
5700 ch.my_id.type = OBJECT_SCRIPT;
5701 ch.my_id.objhandle = me;
5702
5703 if (!f_reinit) {
5704 memory = (guidebot_data *)Scrpt_MemAlloc(&ch);
5705 memory->flags = 0;
5706
5707 AI_Value(me, VF_GET, AIV_F_MAX_DELTA_SPEED, &memory->max_acc);
5708 AI_Value(me, VF_GET, AIV_F_MAX_SPEED, &memory->max_speed);
5709
5710 Obj_Value(me, VF_GET, OBJV_I_PARENT_HANDLE, &memory->my_player);
5711 Obj_Value(memory->my_player, VF_GET, OBJV_US_ID, &memory->mp_slot);
5712
5713 Player_Value(memory->my_player, VF_GET, PLYV_CS_GUIDEBOTNAME, memory->name);
5714
5715 // Sets up my invisible helper
5716 int proom;
5717 vector ppos;
5718 matrix porient;
5719
5720 Obj_Value(memory->my_player, VF_GET, OBJV_I_ROOMNUM, &proom);
5721 Obj_Value(memory->my_player, VF_GET, OBJV_V_POS, &ppos);
5722 Obj_Value(memory->my_player, VF_GET, OBJV_M_ORIENT, &porient);
5723
5724 ppos += porient.fvec * 10.0f;
5725
5726 memory->amb_camera_handle = Obj_Create(OBJ_POWERUP, Obj_FindID("Invisiblepowerup"), proom, &ppos, &porient, me);
5727 msafe_struct mstruct;
5728 mstruct.objhandle = memory->amb_camera_handle;
5729 MSafe_CallFunction(MSAFE_OBJECT_NO_RENDER, &mstruct);
5730
5731 // Three fire extinguishers per level
5732 memory->powerups[0] = 3;
5733 memory->powerups[1] = 0;
5734 memory->powerups[2] = 0;
5735 memory->powerups[3] = 0;
5736 memory->powerups[4] = 0;
5737
5738 for (i = 0; i < NUM_GB_SOUNDS; i++) {
5739 memory->sounds[i] = -1;
5740 }
5741
5742 memory->me = me;
5743
5744 memory->mode = GBM_IN_SHIP;
5745 AI_SetType(me, AIT_AIS);
5746
5747 memory->powerup_ids[0] = Obj_FindID("Buddyextinguisher");
5748 memory->powerup_ids[1] = Obj_FindID("buddywingnut");
5749 memory->powerup_ids[2] = Obj_FindID("buddycontrol");
5750 memory->powerup_ids[3] = Obj_FindID("buddyassist");
5751 memory->powerup_ids[4] = Obj_FindID("buddyantivirus");
5752 memory->powerup_ids[5] = Obj_FindID("buddyspeed");
5753
5754 memory->num_av_robots = 0;
5755
5756 memory->last_sound_time = Game_GetTime();
5757 memory->last_at_goal_time = Game_GetTime();
5758
5759 memory->camera_obj = OBJECT_HANDLE_NONE;
5760 memory->speed_time_left = 0.0f;
5761 } else {
5762 // If too damaged to exit
5763 if (memory->flags & GBF_VERY_DAMAGED) {
5764 DoMessage(TXT_GBDAMAGED, true, "GBotConcern1", true);
5765 return false;
5766 }
5767
5768 SetMode(me, GBM_BIRTH);
5769 SetSubMode(me, GBSM_NONE);
5770 }
5771
5772 return true;
5773 }
5774
5775 bool GuideBot::DoNotify(int me, tOSIRISEventInfo *data) {
5776 tOSIRISEVTAINOTIFY *notify = &data->evt_ai_notify;
5777
5778 if (notify->notify_type == AIN_USER_DEFINED) {
5779 return DoExternalCommands(me, (gb_com *)data->extra_info, data->evt_ai_notify.it_handle);
5780 } else if (notify->notify_type == AIN_WHIT_OBJECT) {
5781 int type;
5782 Obj_Value(notify->it_handle, VF_GET, OBJV_I_TYPE, &type);
5783
5784 if (type == OBJ_PLAYER) {
5785 if (notify->it_handle == memory->my_player) {
5786 DoMessage(TXT_GB_OOPS, true, "GBotConcern1");
5787 }
5788 } else if (type == OBJ_ROBOT) {
5789 // 35% of the time, the buddy is happy enough to say something when
5790 // he hits a robot
5791 if (rand() > static_cast<float>(RAND_MAX) * 0.65f) {
5792 DoMessage(TXT_GB_SHOOTROBOT, false, "GBotAcceptOrder1");
5793 }
5794 }
5795 } else if (IsGoalFinishedNotify(
5796 notify->notify_type)) // Goal complete -- chrishack -- print something else on error cases
5797 {
5798 mprintf(0, "Goal %d done\n", notify->goal_num);
5799
5800 if (notify->goal_num == 1) {
5801 if (memory->last_at_goal_time + 1.0f > Game_GetTime()) {
5802 gb_com command;
5803
5804 command.action = COM_DO_ACTION;
5805 command.index = GBC_ESCORT_SHIP;
5806 DoExternalCommands(me, &command, memory->my_player);
5807 return true;
5808 }
5809
5810 DoMessage(TXT_GB_GOAL1, false, "GBotAcceptOrder1");
5811 memory->last_at_goal_time = Game_GetTime();
5812
5813 AI_AddGoal(me, AIG_GET_TO_OBJ, 2, 1.0, GB_GUID_RETURNED_TO_PLAYER, GF_NOTIFIES, memory->my_player);
5814 AI_SetGoalCircleDist(me, 2, 30.0f);
5815 } else if (notify->goal_num == 2 && notify->goal_uid == GB_GUID_RETURNED_TO_PLAYER) {
5816 mprintf(0, "HERERWERSEFSDF\n");
5817 bool f_used;
5818 AI_GoalValue(me, 1, VF_GET, AIGV_B_USED, &f_used);
5819 if (f_used) {
5820 mprintf(0, "FUCKME\n");
5821
5822 if ((rand() % 100) > 50)
5823 DoMessage(TXT_GB_GOAL2, false, "GBotGreetB1");
5824 else
5825 DoMessage(TXT_GB_GOAL3, false, "GBotGreetB1");
5826 }
5827
5828 memory->time_till_next_flare = 3.0f + ((float)rand() / (float)RAND_MAX);
5829 memory->return_time = Game_GetTime();
5830 }
5831 } else if (notify->notify_type == AIN_SCRIPTED_ORIENT) {
5832 matrix orient;
5833 Obj_Value(memory->my_player, VF_GET, OBJV_M_ORIENT, &orient);
5834
5835 AI_TurnTowardsVectors(me, &orient.fvec, &orient.uvec);
5836 }
5837
5838 return true;
5839 }
5840
5841 void GuideBot::DoPowerupCheck(int me) {
5842 if (memory->next_powerup_check_time <= Game_GetTime() && memory->sub_mode == GBSM_NONE) {
5843 vector pos;
5844 int room;
5845 int scan_objs[80];
5846 int n_scan;
5847 int i;
5848
5849 memory->next_powerup_check_time = Game_GetTime() + 2.0f + ((float)rand() / (float)RAND_MAX);
5850
5851 Obj_Value(me, VF_GET, OBJV_V_POS, &pos);
5852 Obj_Value(me, VF_GET, OBJV_I_ROOMNUM, &room);
5853
5854 n_scan = AI_GetNearbyObjs(&pos, room, 200.0f, scan_objs, 80, false, true, false, true);
5855
5856 for (i = 0; i < n_scan; i++) {
5857 int type;
5858 int16_t id;
5859 Obj_Value(scan_objs[i], VF_GET, OBJV_I_TYPE, &type);
5860 Obj_Value(scan_objs[i], VF_GET, OBJV_US_ID, &id);
5861
5862 if (type == OBJ_POWERUP) {
5863 bool f_for_me = false;
5864 int j;
5865
5866 for (j = 0; j < 6; j++) {
5867 if (memory->powerup_ids[j] == id) {
5868 f_for_me = true;
5869 break;
5870 }
5871 }
5872
5873 if (f_for_me) {
5874 tOSIRISEventInfo data;
5875 gb_com command;
5876
5877 command.action = COM_POWERUP_NOTIFY;
5878
5879 DoExternalCommands(me, &command, scan_objs[i]);
5880
5881 break;
5882 }
5883 }
5884 }
5885 }
5886 }
5887
5888 void GuideBot::DoFrame(int me) {
5889 int dir_index;
5890 int flags;
5891 float anim;
5892 float last_mode_time;
5893
5894 int proom;
5895 vector ppos;
5896 matrix porient;
5897 Obj_Value(memory->my_player, VF_GET, OBJV_I_ROOMNUM, &proom);
5898 Obj_Value(memory->my_player, VF_GET, OBJV_V_POS, &ppos);
5899 Obj_Value(memory->my_player, VF_GET, OBJV_M_ORIENT, &porient);
5900
5901 ppos += porient.fvec * 40.0f;
5902 ppos -= porient.uvec * 10.0f;
5903
5904 Obj_Value(memory->amb_camera_handle, VF_SET, OBJV_I_ROOMNUM, &proom);
5905 Obj_Value(memory->amb_camera_handle, VF_SET, OBJV_V_POS, &ppos);
5906 Obj_Value(memory->amb_camera_handle, VF_SET, OBJV_M_ORIENT, &porient);
5907
5908 if (memory->mode == GBM_AMBIENT)
5909 DoPowerupCheck(me);
5910
5911 if (memory->flags & GBF_WANTING_TO_ENTER_PDEAD) {
5912 int flags;
5913 Player_Value(memory->my_player, VF_GET, PLYV_I_FLAGS, &flags);
5914 if (!(flags & PLAYER_FLAGS_DEAD)) {
5915 SetMode(me, GBM_RESPAWN_ENTER_SHIP);
5916 }
5917 } else {
5918 int flags;
5919 Player_Value(memory->my_player, VF_GET, PLYV_I_FLAGS, &flags);
5920 if (flags & PLAYER_FLAGS_DEAD) {
5921 Obj_Burning(me, 0.0f, 0.0f);
5922 memory->flags |= GBF_WANTING_TO_ENTER_PDEAD;
5923 }
5924 }
5925
5926 if (memory->speed_time_left > 0.0f) {
5927 if (memory->speed_time_left > 15.0f && memory->speed_time_left - Game_GetFrameTime() <= 15.0f) {
5928 DoMessage(TXT_GB_POW_ACC_ALMOST_DONE, true, "GBotExcited1");
5929 }
5930
5931 memory->speed_time_left -= Game_GetFrameTime();
5932 if (memory->speed_time_left <= 0.0f) {
5933 memory->speed_time_left = 0.0f;
5934
5935 AI_Value(me, VF_SET, AIV_F_MAX_SPEED, &memory->max_speed);
5936 AI_Value(me, VF_SET, AIV_F_MAX_DELTA_SPEED, &memory->max_acc);
5937
5938 DoMessage(TXT_GB_POW_DEPLETED, true, "GBotPlayerKillBot1");
5939 }
5940 }
5941
5942 if (memory->mode == GBM_AMBIENT && Obj_IsEffect(memory->my_player, EF_NAPALMED)) {
5943 int room;
5944 float damage = 0.0f;
5945 Obj_Value(memory->my_player, VF_GET, OBJV_I_ROOMNUM, &room);
5946 Room_Value(room, VF_GET, RMV_F_DAMAGE, &damage);
5947
5948 if (damage == 0.0f) {
5949 InitExtinguish(true);
5950 }
5951 }
5952
5953 Obj_Value(me, VF_GET, OBJV_F_ANIM_FRAME, &anim);
5954 if (anim < 0 || anim > 12) {
5955 memory->flags |= GBF_IN_CUSTOM_ANIM;
5956 } else {
5957 memory->flags &= ~GBF_IN_CUSTOM_ANIM;
5958 }
5959
5960 Obj_Value(me, VF_GET, OBJV_I_FLAGS, &flags);
5961
5962 last_mode_time = memory->mode_time;
5963 memory->mode_time += Game_GetFrameTime();
5964
5965 if (memory->mode == GBM_ON_FIRE) {
5966 } else if ((flags & OF_AI_DEATH)) {
5967 SetMode(me, GBM_ON_FIRE);
5968 } else if (memory->mode == GBM_BIRTH) {
5969 if (memory->mode_time > 1.2f) {
5970 SetMode(me, GBM_AMBIENT);
5971 }
5972
5973 return;
5974 } else if (memory->mode == GBM_EXTINGUISH) {
5975 if (!(memory->flags & GBF_IN_CUSTOM_ANIM) && last_mode_time < 0.5f && memory->mode_time >= 0.5f) {
5976 Obj_SetCustomAnim(me, 12.0f, 23.0f, 1.0f, 0);
5977 }
5978
5979 if (Game_GetTime() > memory->next_ambient_time) {
5980 memory->next_ambient_time = Game_GetTime() + 0.6f;
5981
5982 int dir_index = rand() % 6;
5983 AI_AddGoal(me, AIG_MOVE_RELATIVE_OBJ_VEC, 0, 1.0f, -1, GF_ORIENT_GOAL_OBJ | GF_KEEP_AT_COMPLETION,
5984 memory->extinguish_obj_list[0], dir_index);
5985 AI_SetGoalCircleDist(me, 0, 20.0);
5986 }
5987
5988 if (memory->mode_time < 25.0f) {
5989 if (memory->last_anim <= 18 && anim > 18) {
5990 Obj_SetCustomAnim(me, 23.0f, 33.0f, 1.5f, AIAF_LOOPING);
5991 memory->flags |= GBF_WANT_TO_EXTINGUISH;
5992 }
5993
5994 if ((memory->flags & GBF_WANT_TO_EXTINGUISH) && anim >= 23 && anim <= 33) {
5995 int s_id = Sound_FindId("GBotEuphoria1");
5996 Sound_Play3d(me, s_id);
5997
5998 msafe_struct mstruct;
5999
6000 mstruct.random = 21;
6001 mstruct.is_real = 0;
6002 mstruct.objhandle = me;
6003 mstruct.gunpoint = 1;
6004 mstruct.effect_type = MED_SMOKE_INDEX;
6005 mstruct.phys_info = 0;
6006 mstruct.drag = .001f;
6007 mstruct.mass = .001f;
6008 mstruct.interval = .025f;
6009 mstruct.longevity = 100000.0f;
6010 mstruct.lifetime = 1.0;
6011 mstruct.size = 4.2f;
6012 mstruct.speed = 120.0;
6013
6014 MSafe_CallFunction(MSAFE_OBJECT_START_SPEW, &mstruct);
6015
6016 memory->extinguish_spew_id = mstruct.id;
6017
6018 memory->flags &= ~GBF_WANT_TO_EXTINGUISH;
6019 memory->flags |= GBF_EXTINGUISHING;
6020 }
6021
6022 if (memory->flags | GBF_EXTINGUISHING) {
6023 int flags;
6024 vector me_pos;
6025 vector it_pos;
6026 matrix orient;
6027
6028 AI_GoalValue(me, 0, VF_GET, AIGV_I_STATUS_REG, &flags);
6029 Obj_Value(me, VF_GET, OBJV_V_POS, &me_pos);
6030 Obj_Value(me, VF_GET, OBJV_M_ORIENT, &orient);
6031 Obj_Value(memory->extinguish_obj_list[0], VF_GET, OBJV_V_POS, &it_pos);
6032
6033 vector dir_to_goal = it_pos - me_pos;
6034 vm_VectorNormalize(&dir_to_goal);
6035
6036 if ((flags & AISR_CIRCLE_DIST) && (dir_to_goal * orient.fvec > 0.4717f) && anim >= 23 && anim <= 33)
6037 memory->extinguish_obj_time += Game_GetFrameTime();
6038
6039 if (memory->extinguish_obj_time > 1.5f) {
6040 // Turns off fire if being sprayed for 2.5 seconds
6041 Obj_Burning(memory->extinguish_obj_list[0], 0.0f, 0.0f);
6042
6043 if (memory->num_extinguish_objs > 1) {
6044 int i;
6045 for (i = 0; i < memory->num_extinguish_objs - 1; i++) {
6046 memory->extinguish_obj_list[i] = memory->extinguish_obj_list[i + 1];
6047 }
6048 memory->num_extinguish_objs--;
6049
6050 SetMode(me, GBM_EXTINGUISH);
6051 } else {
6052 SetMode(me, GBM_AMBIENT);
6053 }
6054 }
6055 }
6056 } else {
6057 SetMode(me, GBM_AMBIENT);
6058 }
6059 } else if (memory->mode == GBM_RTYPE) {
6060 int room;
6061 vector pos;
6062 matrix orient;
6063
6064 Obj_Value(memory->my_player, VF_GET, OBJV_V_POS, &pos);
6065 Obj_Value(memory->my_player, VF_GET, OBJV_I_ROOMNUM, &room);
6066 Obj_Value(memory->my_player, VF_GET, OBJV_M_ORIENT, &orient);
6067
6068 pos += orient.fvec * 3.0f;
6069 pos -= orient.uvec * 10.0f;
6070
6071 Obj_Value(memory->camera_obj, VF_SET, OBJV_I_ROOMNUM, &room);
6072 Obj_Value(memory->camera_obj, VF_SET, OBJV_V_POS, &pos);
6073 Obj_Value(memory->camera_obj, VF_SET, OBJV_M_ORIENT, &orient);
6074
6075 if (memory->mode_time < 15.0f && memory->mode_time + Game_GetFrameTime() >= 15.0f) {
6076 DoMessage(TXT_GB_FIFTEEN_SEC_TO_GO, true, "GBotExcited1");
6077 }
6078
6079 if (memory->mode_time > 30.0) {
6080 DoMessage(TXT_GB_POW_DEPLETED, true, "GBotPlayerKillBot1");
6081 SetMode(me, GBM_AMBIENT);
6082 }
6083 } else if (memory->mode == GBM_GO_WINGNUT) {
6084 if (Game_GetTime() > memory->next_ambient_time) {
6085 memory->next_ambient_time = Game_GetTime() + 1.0f;
6086
6087 // In general, Turn on friend avoidance
6088 int flags = AIF_AUTO_AVOID_FRIENDS;
6089 AI_Value(me, VF_SET_FLAGS, AIV_I_FLAGS, &flags);
6090
6091 int dir_index = rand() % 6;
6092 float interval = 2.0f;
6093 AI_AddGoal(me, AIG_MOVE_RELATIVE_OBJ_VEC, 3, 1.0f, -1, GF_KEEP_AT_COMPLETION, memory->my_player, dir_index);
6094 AI_GoalAddEnabler(me, 3, AIE_GT_LAST_SEE_TARGET_INTERVAL, 1.0f, 0.0f, &interval);
6095
6096 AI_SetGoalCircleDist(me, 3, 27.0);
6097 }
6098
6099 if (memory->mode_time < 15.0f && memory->mode_time + Game_GetFrameTime() >= 15.0f) {
6100 DoMessage(TXT_GB_FIFTEEN_SEC_TO_GO, true, "GBotExcited1");
6101 }
6102
6103 if (memory->mode_time > 30.0) {
6104 DoMessage(TXT_GB_POW_DEPLETED, true, "GBotPlayerKillBot1");
6105 SetMode(me, GBM_AMBIENT);
6106 }
6107 } else {
6108 if (memory->sounds[GBS_AMBIENT] == -1) {
6109 int s_index = Sound_FindId("GBotEngineB1");
6110 memory->sounds[GBS_AMBIENT] = Sound_Play3d(me, s_index);
6111 }
6112
6113 if (memory->mode == GBM_AMBIENT) {
6114 if (Game_GetTime() > memory->next_ambient_time) {
6115 ReInitAmbient(me);
6116 }
6117 }
6118
6119 // Allow the buddy to collide with his player after 3 seconds
6120 if (memory->f_parented == true) {
6121 float time;
6122 Obj_Value(me, VF_GET, OBJV_F_CREATION_TIME, &time);
6123
6124 if (Game_GetTime() - time > 3.0f) {
6125 int parent = OBJECT_HANDLE_NONE;
6126
6127 Obj_Value(me, VF_SET, OBJV_I_PARENT_HANDLE, &parent);
6128 memory->f_parented = false;
6129 }
6130 }
6131
6132 memory->time_till_next_pvis_check -= Game_GetFrameTime();
6133 if (memory->time_till_next_pvis_check <= 0.0f) {
6134 vector start_pos;
6135 vector end_pos;
6136
6137 Obj_Value(me, VF_GET, OBJV_V_POS, &start_pos);
6138 Obj_Value(memory->my_player, VF_GET, OBJV_V_POS, &end_pos);
6139
6140 memory->time_till_next_pvis_check = 0.5f + (0.5f * ((float)rand() / (float)RAND_MAX));
6141
6142 if (vm_VectorDistance(&start_pos, &end_pos) < 200.0f) {
6143 int start_room;
6144 ray_info ray;
6145
6146 Obj_Value(me, VF_GET, OBJV_I_ROOMNUM, &start_room);
6147
6148 flags = FQ_CHECK_OBJS | FQ_IGNORE_POWERUPS | FQ_IGNORE_WEAPONS | FQ_IGNORE_MOVING_OBJECTS |
6149 FQ_IGNORE_NON_LIGHTMAP_OBJECTS;
6150 int fate = FVI_RayCast(me, &start_pos, &end_pos, start_room, 0.0f, flags, &ray);
6151
6152 if (fate == HIT_NONE) {
6153 memory->return_time = Game_GetTime();
6154 }
6155 }
6156 // mprintf(0, "Vis check %s\n", (fate==HIT_NONE)?"passed":"failed");
6157 // mprintf(0, "Submode %d\n", memory->sub_mode);
6158 }
6159
6160 if (memory->mode == GBM_AMBIENT) {
6161 memory->time_till_next_flare -= Game_GetFrameTime();
6162
6163 if (memory->time_till_next_flare <= 0.0f) {
6164 memory->time_till_next_flare = 3.0f + ((float)rand() / (float)RAND_MAX);
6165
6166 bool f_used;
6167 AI_GoalValue(me, 1, VF_GET, AIGV_B_USED, &f_used);
6168 if (f_used) {
6169 AI_GoalValue(me, 2, VF_GET, AIGV_B_USED, &f_used);
6170 if (!f_used) {
6171 AI_GoalValue(me, 3, VF_GET, AIGV_B_USED, &f_used);
6172 if (!f_used) {
6173 msafe_struct mstruct;
6174
6175 mstruct.objhandle = me;
6176
6177 uint16_t id;
6178 Obj_Value(me, VF_GET, OBJV_US_ID, &id);
6179
6180 if (Obj_FindID("GuideBot") == id) {
6181 mstruct.index = Wpn_FindID("Yellow flare");
6182 } else {
6183 mstruct.index = Wpn_FindID("GreenFlare");
6184 }
6185
6186 if (mstruct.index != -1) {
6187 mstruct.gunpoint = -1;
6188 Sound_Play3d(me, Sound_FindId("Flare"));
6189
6190 MSafe_CallFunction(MSAFE_OBJECT_FIRE_WEAPON, &mstruct);
6191 }
6192 }
6193 }
6194 }
6195 }
6196 }
6197
6198 // Makes the buddy stay pretty close to his player
6199 if (memory->return_time + 2.5 < Game_GetTime()) {
6200 if (Obj_GetObjDist(me, memory->my_player, true) > 10.0f && memory->sub_mode == GBSM_NONE) {
6201 DoMessage(TXT_GB_COMINGBACK, false, "GBotAcceptOrder1");
6202
6203 AI_AddGoal(me, AIG_GET_TO_OBJ, 2, 1.0f, GB_GUID_RETURNED_TO_PLAYER, GF_NOTIFIES, memory->my_player);
6204 AI_SetGoalCircleDist(me, 2, 30.0f);
6205 }
6206
6207 memory->return_time = Game_GetTime();
6208 }
6209 }
6210
6211 memory->last_anim = anim;
6212 }
6213
6214 int16_t GuideBot::CallEvent(int event, tOSIRISEventInfo *data) {
6215 switch (event) {
6216 case EVT_AI_INIT:
6217 return (DoInit(data->me_handle, false) != false) ? CONTINUE_CHAIN | CONTINUE_DEFAULT : 0;
6218 break;
6219 case EVT_INTERVAL: {
6220 int i;
6221
6222 while (memory->num_av_robots > 0 && memory->av_revert_time[0] <= Game_GetTime()) {
6223
6224 int flags = AIF_TEAM_MASK;
6225 AI_Value(memory->av_robot_list[0], VF_CLEAR_FLAGS, AIV_I_FLAGS, &flags);
6226 flags = AIF_TEAM_PTMC;
6227 AI_Value(memory->av_robot_list[0], VF_SET_FLAGS, AIV_I_FLAGS, &flags);
6228
6229 int target_handle = OBJECT_HANDLE_NONE;
6230 AI_Value(memory->av_robot_list[0], VF_SET, AIV_I_TARGET_HANDLE, &target_handle);
6231
6232 for (i = 1; i < memory->num_av_robots; i++) {
6233 memory->av_robot_list[i - 1] = memory->av_robot_list[i];
6234 }
6235
6236 memory->num_av_robots--;
6237 }
6238 } break;
6239 case EVT_AI_FRAME:
6240 DoFrame(data->me_handle);
6241 break;
6242 case EVT_COLLIDE:
6243 DoCollide(data->me_handle, &data->evt_collide);
6244 break;
6245 case EVT_AI_NOTIFY:
6246 return (DoNotify(data->me_handle, data) != false) ? CONTINUE_CHAIN | CONTINUE_DEFAULT : 0;
6247 break;
6248 case EVT_USE:
6249 return (DoUse(data->me_handle) != 0) ? CONTINUE_CHAIN | CONTINUE_DEFAULT : 0;
6250 break;
6251 case EVT_DESTROY:
6252 if (memory->camera_obj != OBJECT_HANDLE_NONE) {
6253 msafe_struct mo;
6254 mo.objhandle = memory->camera_obj;
6255 MSafe_CallFunction(MSAFE_OBJECT_REMOVE, &mo);
6256
6257 memory->camera_obj = OBJECT_HANDLE_NONE;
6258 }
6259 break;
6260 case EVT_MEMRESTORE: {
6261 memory = (guidebot_data *)data->evt_memrestore.memory_ptr;
6262 } break;
6263 }
6264 return CONTINUE_CHAIN | CONTINUE_DEFAULT;
6265 }
6266
6267 //---------------
6268 // Thief
6269 //---------------
6270
6271 void Thief::DoAttack(int me, int it) {}
6272
6273 bool Thief::DoSteal(int me, int it, int attempt_num, bool f_last_success) {
6274 int max_tries = numThiefableItems;
6275 float gen_perc, perc_chance;
6276 ;
6277 int i;
6278 int count_max, count_num;
6279 bool *attempted_steals;
6280
6281 attempted_steals = (bool *)malloc(numThiefableItems * sizeof(bool));
6282 if (!attempted_steals)
6283 return false;
6284
6285 float ftime = Game_GetFrameTime();
6286 if (ftime == 0)
6287 ftime = 1.0f;
6288 srand(Game_GetTime() / ftime);
6289
6290 for (i = 0; i < numThiefableItems; i++) {
6291 attempted_steals[i] = false;
6292 }
6293
6294 while (max_tries--) {
6295 i = rand() % numThiefableItems;
6296 gen_perc = ((float)rand()) / ((float)(RAND_MAX));
6297
6298 perc_chance = (attempt_num == 1) ? ThiefableItems[i].attempt_one
6299 : (f_last_success) ? ThiefableItems[i].attempt_two
6300 : ThiefableItems[i].attempt_two_no_one;
6301
6302 if (attempted_steals[i]) {
6303 // we already tried this one, try another
6304 max_tries++;
6305 continue;
6306 }
6307
6308 attempted_steals[i] = true;
6309
6310 if (gen_perc <= perc_chance) {
6311 // check to see if we have the index, if so, take it!
6312 switch (ThiefableItems[i].type) {
6313 case THIEFABLEITEM_PRIMARY:
6314 case THIEFABLEITEM_SECONDARY:
6315 count_max = MAX_STOLEN_WEAPONS;
6316 count_num = memory->num_stolen_weapons;
6317 break;
6318 case THIEFABLEITEM_ACCESSORY:
6319 count_max = MAX_STOLEN_INV;
6320 count_num = memory->num_stolen_inv;
6321 break;
6322 default:
6323 mprintf(0, "THIEF: INVALID THIEFABLE TYPE!\n");
6324 count_max = 0;
6325 count_num = 0;
6326 break;
6327 }
6328
6329 if (count_num >= count_max) {
6330 mprintf(0, "THIEF: no mo' room\n");
6331 continue; // we have no more room
6332 }
6333
6334 // mprintf(0,"THIEF: Checking %s\n",TXT(ThiefableItems[i].name_idx));
6335
6336 bool can_take = false;
6337 int amount = 0;
6338 char message[256];
6339
6340 switch (ThiefableItems[i].type) {
6341 case THIEFABLEITEM_PRIMARY:
6342 // check to see if we can steal the primary
6343 Player_Value(it, VF_GET, PLYSV_I_WEAPON, &amount, ThiefableItems[i].index);
6344 if (ThiefableItems[i].index != 0 && amount) {
6345 can_take = true;
6346 snprintf(message, sizeof(message), TXT_THIEFSTEAL, TXT(ThiefableItems[i].name_idx));
6347 }
6348 break;
6349
6350 case THIEFABLEITEM_SECONDARY:
6351 // check to see if we can steal the secondary
6352 if (attempt_num <= 1 || (!f_last_success)) {
6353 Player_Value(it, VF_GET, PLYSV_I_WEAPON, &amount, ThiefableItems[i].index);
6354
6355 if (amount) {
6356 int max;
6357
6358 if (ThiefableItems[i].index > 14) {
6359 // 2nd selection group (black shark, etc)
6360 max = (19 - ThiefableItems[i].index) / 2.5f + 1;
6361 } else {
6362 // 1st selection group (mega, etc)
6363 max = (14 - ThiefableItems[i].index) / 2.5f + 1;
6364 }
6365
6366 int new_amount = (rand() / (float)(RAND_MAX + 1)) * max + 1;
6367
6368 if (new_amount < amount)
6369 amount = new_amount;
6370
6371 can_take = true;
6372
6373 if (amount == 1) {
6374 snprintf(message, sizeof(message), TXT_THIEFSTEAL1, TXT(ThiefableItems[i].name_idx));
6375 } else {
6376 snprintf(message, sizeof(message), TXT_THIEFSTEAL2, amount, TXT(ThiefableItems[i].name_idx));
6377 }
6378 }
6379 }
6380
6381 break;
6382
6383 case THIEFABLEITEM_ACCESSORY:
6384 // check to see if we can steal the accessory
6385 Player_Value(it, VF_GET, PLYV_B_THIEF_PLAYERHASITEM, &can_take, ThiefableItems[i].index);
6386 amount = 1;
6387
6388 if (can_take && ThiefableItems[i].index == THIEFITEM_AUTOMAP) {
6389 // make sure the thief hasn't taken your automap already
6390 for (int k = 0; k < memory->num_stolen_inv; k++) {
6391 if (memory->stolen_inv[k].id == THIEFITEM_AUTOMAP) {
6392 // he has already taken an automap
6393 can_take = false;
6394 break;
6395 }
6396 }
6397 }
6398
6399 if (can_take) {
6400 snprintf(message, sizeof(message), TXT_THIEFSTEAL, TXT(ThiefableItems[i].name_idx));
6401 }
6402 break;
6403 }
6404
6405 if (!can_take)
6406 continue;
6407
6408 mprintf(0, "THIEF: Taking %s\n", TXT(ThiefableItems[i].name_idx));
6409
6410 Player_AddHudMessage(it, message);
6411 if (rand() % 50) {
6412 Sound_Play3d(me, Sound_FindId("RbtThiefHehHehHeh"));
6413 } else {
6414 Sound_Play3d(me, Sound_FindId("RbtThiefLaugh"));
6415 }
6416
6417 switch (ThiefableItems[i].type) {
6418 case THIEFABLEITEM_PRIMARY:
6419 case THIEFABLEITEM_SECONDARY:
6420 memory->stolen_weapons[memory->num_stolen_weapons].index = ThiefableItems[i].index;
6421 memory->stolen_weapons[memory->num_stolen_weapons].owner = it;
6422 memory->stolen_weapons[memory->num_stolen_weapons].amount = amount;
6423 memory->num_stolen_weapons++;
6424
6425 if (ThiefableItems[i].type == THIEFABLEITEM_PRIMARY) {
6426 amount = 0;
6427 } else {
6428 amount *= -1;
6429 }
6430
6431 Player_Value(it, VF_SET, PLYSV_I_WEAPON, &amount, ThiefableItems[i].index);
6432
6433 break;
6434 case THIEFABLEITEM_ACCESSORY:
6435 memory->stolen_inv[memory->num_stolen_inv].id = ThiefableItems[i].index;
6436 memory->stolen_inv[memory->num_stolen_inv].owner = it;
6437 memory->num_stolen_inv++;
6438
6439 Player_Value(it, VF_SET, PLYV_I_THIEF_STEALPLAYERITEM, NULL, ThiefableItems[i].index);
6440 break;
6441 }
6442
6443 free(attempted_steals);
6444 return true;
6445 }
6446 }
6447
6448 mprintf(0, "THIEF: Not taking anything\n");
6449 free(attempted_steals);
6450 return false; // we didn't take anything this try
6451 }
6452
6453 void Thief::DoKidnap(int me, int it) {
6454 if (memory->num_stolen_objs < MAX_STOLEN_OBJS) {
6455 Obj_Ghost(it, true);
6456 memory->stolen_objs[memory->num_stolen_objs++] = it;
6457 }
6458 }
6459
6460 void Thief::SetSubMode(int me, int submode) {
6461 if (submode == memory->last_special_sub_mode)
6462 return;
6463
6464 if (memory->sub_mode == THIEF_SUB_GET_POWERUP) {
6465 // Make sure we reset the Alert animation
6466 Obj_SetCustomAnim(me, 0.0f, 6.0f, 1.0f, AIAF_NOTIFY, -1, AS_ALERT);
6467 }
6468
6469 if (submode == THIEF_SUB_GET_POWERUP && (memory->flags & THIEF_F_GOT_POWERUP))
6470 return;
6471
6472 if (submode == THIEF_SUB_DROP_POWERUP && !(memory->flags & THIEF_F_GOT_POWERUP))
6473 return;
6474
6475 // CHRISHACK - we might want to make sure the thief only does some of stuff during
6476 if (submode != THIEF_SUB_NONE && submode != THIEF_SUB_CLOAK) {
6477 float time;
6478 float last_hear_target_time;
6479 AI_Value(me, VF_GET, AIV_F_LAST_SEE_TARGET_TIME, &time);
6480 AI_Value(me, VF_GET, AIV_F_LAST_HEAR_TARGET_TIME, &last_hear_target_time);
6481
6482 if (Game_GetTime() > time + 2.0f && Game_GetTime() > last_hear_target_time + 2.0f) {
6483 return;
6484 }
6485 }
6486
6487 switch (submode) {
6488 case THIEF_SUB_NONE: {
6489 AI_SetGoalFlags(me, 2, GF_ORIENT_TARGET, false);
6490 memory->next_test_time = Game_GetTime() + 10.0f + (float)rand() * (1.0f / (float)RAND_MAX) * 10.0f;
6491 } break;
6492 case THIEF_SUB_SUMMON: {
6493 AI_SetGoalFlags(me, 2, GF_ORIENT_TARGET, false);
6494 Obj_SetCustomAnim(me, 12.0f, 19.0f, 0.8f, 0, -1, -1);
6495 } break;
6496 case THIEF_SUB_CLOAK: {
6497 AI_SetGoalFlags(me, 2, GF_ORIENT_TARGET, true);
6498 Obj_SetCustomAnim(me, 50.0f, 64.0f, 3.5f, AIAF_NOTIFY, -1, AS_ALERT);
6499 } break;
6500 case THIEF_SUB_THROW_ITEM: {
6501 AI_SetGoalFlags(me, 2, GF_ORIENT_TARGET, true);
6502 Obj_SetCustomAnim(me, 29.0f, 50.0f, 3.5f, AIAF_NOTIFY, -1, AS_ALERT);
6503 } break;
6504 case THIEF_SUB_GET_POWERUP: {
6505 AI_SetGoalFlags(me, 2, GF_ORIENT_TARGET, false);
6506 Obj_SetCustomAnim(me, 29.0f, 29.0f, 0.1f, AIAF_LOOPING);
6507 } break;
6508 case THIEF_SUB_DROP_POWERUP: {
6509 AI_SetGoalFlags(me, 2, GF_ORIENT_TARGET, true);
6510 Obj_SetCustomAnim(me, 145.0f, 160.0f, 2.3f, AIAF_NOTIFY, -1, AS_ALERT);
6511 } break;
6512 }
6513
6514 if (submode != THIEF_SUB_NONE) {
6515 memory->last_special_sub_mode = submode;
6516 }
6517
6518 memory->sub_mode_time = 0.0f;
6519 memory->sub_mode = submode;
6520 }
6521
6522 void Thief::DoSubModeFrame(int me) {
6523 float anim_frame;
6524 Obj_Value(me, VF_GET, OBJV_F_ANIM_FRAME, &anim_frame);
6525
6526 msafe_struct m;
6527 m.objhandle = me;
6528
6529 switch (memory->sub_mode) {
6530 case THIEF_SUB_NONE: {
6531 if (Game_GetTime() > memory->next_test_time) {
6532 int r_val = (rand() % 5) + 1;
6533 SetSubMode(me, r_val);
6534
6535 // In case above failed, make sure there is a time gap between submode checks
6536 memory->next_test_time = Game_GetTime() + 10.0f + (float)rand() * (1.0f / (float)RAND_MAX) * 10.0f;
6537 }
6538 } break;
6539 case THIEF_SUB_SUMMON: {
6540
6541 if (anim_frame >= 12.0f && anim_frame < 19.0f) {
6542 Obj_SetCustomAnim(me, 19.0f, 23.0f, 0.8f, AIAF_LOOPING);
6543 }
6544
6545 if (anim_frame > 19.0f && anim_frame < 23.0f) {
6546 if (memory->last_summon_time + 0.25f <= Game_GetTime()) {
6547 memory->last_summon_time = Game_GetTime();
6548
6549 // Chrishack - do summon stuff here
6550 }
6551 }
6552
6553 if (memory->sub_mode_time > 6.0f && anim_frame >= 19.0f && anim_frame <= 23.0f) {
6554 Obj_SetCustomAnim(me, 23.0f, 29.0f, 0.8f, AIAF_NOTIFY, -1, AS_ALERT);
6555 SetSubMode(me, THIEF_SUB_NONE);
6556 }
6557
6558 } break;
6559 case THIEF_SUB_CLOAK: {
6560 if (anim_frame > 61.0f && memory->last_frame <= 61.0f) {
6561 m.lifetime = 15.0f;
6562 m.state = 1;
6563
6564 MSafe_CallFunction(MSAFE_OBJECT_CLOAK, &m);
6565
6566 AI_SetGoalFlags(me, 2, GF_ORIENT_TARGET, false);
6567 }
6568 } break;
6569 case THIEF_SUB_THROW_ITEM: {
6570 if (anim_frame > 41.0f && memory->last_frame <= 41.0f) {
6571 memory->bomb_handle = CreateAndAttach(me, "PTMCSeeker", OBJ_ROBOT, 1, 0, true, true);
6572 }
6573
6574 if (anim_frame > 45.0f && memory->last_frame <= 45.0f) {
6575 matrix orient;
6576 Obj_Value(me, VF_GET, OBJV_M_ORIENT, &orient);
6577 vector velocity = orient.fvec * 50.0f;
6578
6579 Obj_UnattachFromParent(memory->bomb_handle);
6580
6581 Obj_Value(memory->bomb_handle, VF_SET, OBJV_V_VELOCITY, &velocity);
6582
6583 AI_SetGoalFlags(me, 2, GF_ORIENT_TARGET, false);
6584 }
6585 } break;
6586 case THIEF_SUB_GET_POWERUP: {
6587 } break;
6588 case THIEF_SUB_DROP_POWERUP: {
6589 } break;
6590 default: {
6591 } break;
6592 }
6593
6594 if (memory->sub_mode != THIEF_SUB_NONE && memory->sub_mode_time > 10.0) {
6595 SetSubMode(me, THIEF_SUB_NONE);
6596 }
6597 }
6598
6599 void Thief::SetMode(int me, int new_mode) {
6600 vector pos;
6601 int room = 0;
6602
6603 AI_SetType(me, AIT_AIS);
6604
6605 // Makes sure that the dodge flag is set by default (certain modes turn it off)
6606 int flags = AIF_DODGE; // Don't dodge while surrendering
6607 AI_Value(me, VF_SET_FLAGS, AIV_I_FLAGS, &flags);
6608
6609 switch (new_mode) {
6610 case THIEF_AMBIENT: {
6611 AI_AddGoal(me, AIG_WANDER_AROUND, 2, 1.0f, -1, GF_ORIENT_VELOCITY | GF_NOTIFIES | GF_KEEP_AT_COMPLETION, &pos,
6612 room);
6613 AI_SetGoalFlags(me, 2, GF_ORIENT_TARGET, false);
6614 } break;
6615 case THIEF_STEAL: {
6616 flags = AIF_DODGE; // Don't dodge while stealing
6617 AI_Value(me, VF_CLEAR_FLAGS, AIV_I_FLAGS, &flags);
6618
6619 AI_SetType(me, AIT_MELEE1);
6620 } break;
6621 case THIEF_DEATH: {
6622 flags = AIF_DODGE; // Don't dodge while dying
6623 AI_Value(me, VF_CLEAR_FLAGS, AIV_I_FLAGS, &flags);
6624
6625 float temp = 0.0f;
6626 AI_Value(me, VF_SET, AIV_F_MAX_TURN_RATE, &temp);
6627 Obj_SetCustomAnim(me, 85.0f, 140.0f, 8.0f, 0, Sound_FindId("RbtThiefDeath"), -1);
6628 } break;
6629 case THIEF_SURRENDER: {
6630 flags = AIF_DODGE; // Don't dodge while surrendering
6631 AI_Value(me, VF_CLEAR_FLAGS, AIV_I_FLAGS, &flags);
6632
6633 AI_AddGoal(me, AIG_GET_TO_OBJ, 1, 1.0f, -1, GF_ORIENT_TARGET | GF_KEEP_AT_COMPLETION, me);
6634 Obj_SetCustomAnim(me, 64.0f, 71.0f, 1.0f, 0, -1, -1);
6635 } break;
6636 case THIEF_TRACK_PLAYER: {
6637 } break;
6638 case THIEF_RUN_AWAY: {
6639 } break;
6640 case THIEF_TIME_BOMB: {
6641 } break;
6642 case THIEF_PLAYER_DEATH_TAUNT: {
6643 } break;
6644 case THIEF_KIDNAP_GB: {
6645 } break;
6646 case THIEF_CORNERED: {
6647 } break;
6648 }
6649
6650 memory->mode_time = 0.0f;
6651 memory->mode = new_mode;
6652 }
6653
6654 void Thief::DoInit(int me) {
6655
6656 int room;
6657 vector pos;
6658 tOSIRISMEMCHUNK ch;
6659 ch.id = 4;
6660 ch.size = sizeof(thief_data);
6661 ch.my_id.type = OBJECT_SCRIPT;
6662 ch.my_id.objhandle = me;
6663
6664 memory = (thief_data *)Scrpt_MemAlloc(&ch);
6665 memory->next_test_time = Game_GetTime() + 5.0f;
6666 memory->last_frame = 0;
6667 memory->last_summon_time = Game_GetTime();
6668
6669 memory->num_stolen_objs = 0;
6670 memory->num_stolen_weapons = 0;
6671 memory->num_stolen_inv = 0;
6672 Obj_Value(me, VF_GET, OBJV_F_SHIELDS, &memory->last_shields);
6673
6674 SetMode(me, THIEF_AMBIENT);
6675 SetSubMode(me, THIEF_SUB_NONE);
6676 }
6677
6678 void Thief::DoCollide(int me, tOSIRISEVTCOLLIDE *evt_collide) {}
6679
6680 bool Thief::DoNotify(int me, tOSIRISEVTAINOTIFY *notify) {
6681 switch (notify->notify_type) {
6682 case AIN_MELEE_HIT: {
6683 int target_handle;
6684 int target_type;
6685
6686 AI_Value(me, VF_GET, AIV_I_TARGET_HANDLE, &target_handle);
6687 Obj_Value(target_handle, VF_GET, OBJV_I_TYPE, &target_type);
6688
6689 if (target_type == OBJ_PLAYER) {
6690 bool f_success;
6691
6692 f_success = DoSteal(me, target_handle, 1, false);
6693 DoSteal(me, target_handle, 2, f_success);
6694 } else if (target_type == OBJ_ROBOT) {
6695 uint16_t id;
6696
6697 Obj_Value(target_handle, VF_GET, OBJV_US_ID, &id);
6698 if (id == ROBOT_GUIDEBOT || id == ROBOT_GUIDEBOTRED) {
6699 DoKidnap(me, target_handle);
6700 } else {
6701 DoAttack(me, target_handle);
6702 }
6703 }
6704
6705 // If successful or dot to player greater than threshold then -- chrishack
6706 SetMode(me, THIEF_AMBIENT);
6707 } break;
6708 case AIN_HIT_BY_WEAPON: {
6709 if (memory->mode == THIEF_STEAL) {
6710 SetMode(me, THIEF_AMBIENT);
6711 }
6712 } break;
6713 }
6714
6715 return true;
6716 }
6717
6718 void Thief::DoFrame(int me) {
6719 // Drop bomb:29-50 (4.5 seconds, bomb created at 41 and leaves hand at frame 45)
6720 // Button push: 50-64 (3.5 seconds) button presses: 57,59
6721 // surrender: 64-85 (2.5-3.0 seconds)
6722 // summon: 12-29 (3.0 seconds) 19-23 (summons)
6723
6724 float anim_frame;
6725 float shields;
6726 int flags;
6727 Obj_Value(me, VF_GET, OBJV_F_ANIM_FRAME, &anim_frame);
6728 Obj_Value(me, VF_GET, OBJV_F_SHIELDS, &shields);
6729 Obj_Value(me, VF_GET, OBJV_I_FLAGS, &flags);
6730
6731 bool f_used;
6732 AI_GoalValue(me, 3, VF_GET, AIGV_B_USED, &f_used);
6733 if (f_used) {
6734 return;
6735 }
6736
6737 msafe_struct m;
6738 m.objhandle = me;
6739
6740 MSafe_GetValue(MSAFE_OBJECT_POS, &m);
6741 MSafe_GetValue(MSAFE_OBJECT_ROOMNUM, &m);
6742
6743 if ((flags & OF_AI_DEATH) &&
6744 !((anim_frame >= 0.0f && anim_frame <= 6.0f) || (anim_frame >= 85.0f && anim_frame <= 140.0f))) {
6745 int room;
6746 vector pos;
6747 int weapon_id;
6748
6749 Obj_Value(me, VF_GET, OBJV_I_ROOMNUM, &room);
6750 Obj_Value(me, VF_GET, OBJV_V_POS, &pos);
6751
6752 weapon_id = Wpn_FindID("TubbsHitBlast");
6753 Obj_Create(OBJ_WEAPON, weapon_id, room, &pos, NULL, me);
6754
6755 Obj_Kill(me, OBJECT_HANDLE_NONE, 1000.0f,
6756 DF_BLAST_RING | DF_LOSES_ANTIGRAV | DF_EXPL_MEDIUM | DF_FIREBALL | DF_BREAKS_APART | DF_DEBRIS_SMOKES,
6757 0.0f, 0.0f);
6758 }
6759
6760 if ((memory->mode != THIEF_DEATH) && (flags & OF_AI_DEATH) && anim_frame >= 0.0f && anim_frame <= 6.0f) {
6761 SetMode(me, THIEF_DEATH);
6762 }
6763
6764 if (memory->last_frame >= 50.0f && memory->last_frame <= 64.0f && memory->last_frame < 57.0f && anim_frame >= 57.0f) {
6765 Sound_Play3d(me, Sound_FindId("RbtThiefButtonA"));
6766 }
6767
6768 if (memory->last_frame >= 50.0f && memory->last_frame <= 64.0f && memory->last_frame < 59.0f && anim_frame >= 59.0f) {
6769 Sound_Play3d(me, Sound_FindId("RbtThiefButtonB"));
6770 }
6771
6772 if (memory->mode == THIEF_DEATH) {
6773 if (anim_frame > 86 && memory->last_frame <= 86) {
6774 int room;
6775 vector pos;
6776 int weapon_id;
6777
6778 Obj_Value(me, VF_GET, OBJV_I_ROOMNUM, &room);
6779 Obj_Value(me, VF_GET, OBJV_V_POS, &pos);
6780
6781 weapon_id = Wpn_FindID("TubbsHitBlast");
6782 Obj_Create(OBJ_WEAPON, weapon_id, room, &pos, NULL, me);
6783 }
6784
6785 if (memory->mode_time < 5.0f && memory->mode_time + Game_GetFrameTime() >= 5.0f) {
6786 Obj_Burning(me, 1000000.0f, 1.0f);
6787 }
6788
6789 if (memory->mode_time > 8.0f) {
6790 Obj_Kill(me, OBJECT_HANDLE_NONE, 1000.0f,
6791 DF_BLAST_RING | DF_LOSES_ANTIGRAV | DF_EXPL_MEDIUM | DF_FIREBALL | DF_BREAKS_APART | DF_DEBRIS_SMOKES,
6792 0.0f, 0.0f);
6793 }
6794 } else if (memory->mode == THIEF_SURRENDER) {
6795 if (anim_frame >= 65.0 && anim_frame <= 71.0) {
6796 Obj_SetCustomAnim(me, 71.0f, 79.0f, 1.0f, AIAF_LOOPING, -1, -1);
6797 }
6798
6799 if (memory->mode_time < 2.2f && memory->mode_time + Game_GetFrameTime() >= 2.2f) {
6800 SpewEverything(me);
6801 }
6802
6803 if (memory->mode_time < 3.0f && memory->mode_time + Game_GetFrameTime() >= 3.0f) {
6804 Obj_SetCustomAnim(me, 79.0f, 85.0f, 1.5f, AIAF_NOTIFY, -1, AS_ALERT);
6805 }
6806
6807 if (memory->mode_time > 3.0f && anim_frame >= 0 && anim_frame <= 6) {
6808 SetMode(me, THIEF_AMBIENT);
6809 }
6810 } else if (memory->mode == THIEF_AMBIENT) {
6811 DoSubModeFrame(me);
6812
6813 if (memory->mode_time > 10.0f && memory->sub_mode == THIEF_SUB_NONE) {
6814 SetMode(me, THIEF_STEAL);
6815 }
6816
6817 if (shields < 20.0f && memory->last_shields >= 20.0) {
6818 SetMode(me, THIEF_SURRENDER);
6819 }
6820 } else {
6821 if (memory->mode_time > 10.0 && memory->sub_mode == THIEF_SUB_NONE) {
6822 SetMode(me, THIEF_AMBIENT);
6823 }
6824 }
6825
6826 // Update the last frame
6827 memory->mode_time += Game_GetFrameTime();
6828 memory->sub_mode_time += Game_GetFrameTime();
6829
6830 memory->last_frame = anim_frame;
6831 memory->last_shields = shields;
6832 }
6833
6834 void Thief::SpewEverything(int me) {
6835 int i;
6836 int powerup_handle;
6837 int room;
6838 vector pos;
6839
6840 Obj_Value(me, VF_GET, OBJV_I_ROOMNUM, &room);
6841 Obj_Value(me, VF_GET, OBJV_V_POS, &pos);
6842
6843 for (i = 0; i < memory->num_stolen_weapons; i++) {
6844 uint16_t id;
6845 int j;
6846
6847 for (j = 0; j < memory->stolen_weapons[i].amount; j++) {
6848 float speed = rand() / (float)RAND_MAX * 20.0f + 5.0f;
6849 vector dir;
6850
6851 dir.x = rand() / (float)RAND_MAX - 0.5f;
6852 dir.y = rand() / (float)RAND_MAX - 0.5f;
6853 dir.z = rand() / (float)RAND_MAX - 0.5f;
6854
6855 vm_VectorNormalize(&dir);
6856 dir *= speed;
6857
6858 Player_Value(memory->stolen_weapons[i].owner, VF_GET, PLYSV_US_WEAPON_POWERUP_ID, &id,
6859 memory->stolen_weapons[i].index);
6860 powerup_handle = Obj_Create(OBJ_POWERUP, id, room, &pos, NULL, OBJECT_HANDLE_NONE, &dir);
6861 }
6862
6863 memory->stolen_weapons[i].amount = 0;
6864 }
6865
6866 for (i = 0; i < memory->num_stolen_objs; i++) {
6867 }
6868 memory->num_stolen_objs = 0;
6869
6870 for (i = 0; i < memory->num_stolen_inv; i++) {
6871 static int am_id = -2, hl_id = -2, etos_id = -2, cl_id = -2, iv_id = -2, rf_id = -2, qf_id = -2;
6872 int id;
6873
6874 switch (memory->stolen_inv[i].id) {
6875 case THIEFITEM_AUTOMAP:
6876 if (am_id == -2)
6877 am_id = Obj_FindID("ThiefAutoMap");
6878 id = am_id;
6879 break;
6880 case THIEFITEM_HEADLIGHT:
6881 if (hl_id == -2)
6882 hl_id = Obj_FindID("HeadlightPowerup");
6883 id = hl_id;
6884 break;
6885 case THIEFITEM_ETOSCONV:
6886 if (etos_id == -2)
6887 etos_id = Obj_FindID("Converter");
6888 id = etos_id;
6889 break;
6890 case THIEFITEM_CLOAK:
6891 if (cl_id == -2)
6892 cl_id = Obj_FindID("Cloak");
6893 id = cl_id;
6894 break;
6895 case THIEFITEM_INVULN:
6896 if (iv_id == -2)
6897 iv_id = Obj_FindID("Invulnerability");
6898 id = iv_id;
6899 break;
6900 case THIEFITEM_RAPIDFIRE:
6901 if (rf_id == -2)
6902 rf_id = Obj_FindID("Rapidfire");
6903 id = rf_id;
6904 break;
6905 case THIEFITEM_QUADFIRE:
6906 if (qf_id == -2)
6907 qf_id = Obj_FindID("QuadLaser");
6908 id = qf_id;
6909 break;
6910 default:
6911 id = -1;
6912 break;
6913 }
6914
6915 if (id > -1) {
6916 float speed = rand() / (float)RAND_MAX * 20.0f + 5.0f;
6917 vector dir;
6918
6919 dir.x = rand() / (float)RAND_MAX - 0.5f;
6920 dir.y = rand() / (float)RAND_MAX - 0.5f;
6921 dir.z = rand() / (float)RAND_MAX - 0.5f;
6922
6923 vm_VectorNormalize(&dir);
6924 dir *= speed;
6925
6926 powerup_handle = Obj_Create(OBJ_POWERUP, id, room, &pos, NULL, OBJECT_HANDLE_NONE, &dir);
6927 }
6928 }
6929 memory->num_stolen_inv = 0;
6930 }
6931
6932 void Thief::DoDestroy(int me, tOSIRISEVTDESTROY *evt_destroy) { SpewEverything(me); }
6933
6934 int16_t Thief::CallEvent(int event, tOSIRISEventInfo *data) {
6935 switch (event) {
6936 case EVT_AI_INIT:
6937 DoInit(data->me_handle);
6938 break;
6939 case EVT_AI_FRAME:
6940 DoFrame(data->me_handle);
6941 break;
6942 case EVT_COLLIDE:
6943 DoCollide(data->me_handle, &data->evt_collide);
6944 break;
6945 case EVT_AI_NOTIFY:
6946 return (DoNotify(data->me_handle, &data->evt_ai_notify) != false) ? CONTINUE_CHAIN | CONTINUE_DEFAULT : 0;
6947 break;
6948 case EVT_DESTROY:
6949 DoDestroy(data->me_handle, &data->evt_destroy);
6950 break;
6951 case EVT_MEMRESTORE: {
6952 memory = (thief_data *)data->evt_memrestore.memory_ptr;
6953 } break;
6954 }
6955 return CONTINUE_CHAIN | CONTINUE_DEFAULT;
6956 }
6957
6958 //---------------
6959 // Super Thief
6960 //---------------
6961
6962 //---------------
6963 // Sickle
6964 //---------------
6965
6966 void Sickle::SetMode(int me, char mode) {
6967 if (mode == memory->mode)
6968 return;
6969
6970 float fov = -1.0f;
6971 AI_Value(me, VF_SET, AIV_F_FOV, &fov);
6972
6973 mprintf(0, "Set mode %d\n", (int)mode);
6974 memory->done_moving = false;
6975 memory->done_turning = false;
6976
6977 AI_SetType(me, AIT_AIS);
6978
6979 switch (mode) {
6980 case SICKLE_GOING_HOME: {
6981 int flags;
6982
6983 // Turn off friend avoidance
6984 flags = AIF_AUTO_AVOID_FRIENDS;
6985 AI_Value(me, VF_CLEAR_FLAGS, AIV_I_FLAGS, &flags);
6986
6987 // Orient to vel
6988 AI_AddGoal(me, AIG_GET_TO_POS, 2, 1.0f, -1, GF_ORIENT_VELOCITY | GF_NOTIFIES, &memory->home_pos, memory->home_room);
6989 AI_SetGoalCircleDist(me, 2, 8.0f);
6990 } break;
6991 case SICKLE_LAND_ON_CEILING: {
6992 ray_info ray;
6993 int flags;
6994 int fate;
6995
6996 int start_room;
6997 vector start_pos;
6998 vector end_pos;
6999
7000 int ceiling_room;
7001 // mprintf(0, "In mode 5\n");
7002
7003 // Turn off auto-level
7004 flags = PF_LEVELING;
7005 Obj_Value(me, VF_CLEAR_FLAGS, OBJV_I_PHYSICS_FLAGS, &flags);
7006
7007 Obj_Value(me, VF_GET, OBJV_V_POS, &start_pos);
7008 Obj_Value(me, VF_GET, OBJV_I_ROOMNUM, &start_room);
7009 end_pos = start_pos;
7010 end_pos.y = end_pos.y + 400.0;
7011 flags = FQ_CHECK_OBJS | FQ_IGNORE_POWERUPS | FQ_IGNORE_WEAPONS | FQ_IGNORE_MOVING_OBJECTS |
7012 FQ_IGNORE_NON_LIGHTMAP_OBJECTS;
7013 fate = FVI_RayCast(me, &start_pos, &end_pos, start_room, 0.0f, flags, &ray);
7014
7015 memory->ceiling_pos = ray.hit_point;
7016 memory->ceiling_pos.y -= 3.2f;
7017
7018 fate = FVI_RayCast(me, &start_pos, &memory->ceiling_pos, start_room, 0.0f, flags, &ray);
7019 ceiling_room = ray.hit_room;
7020
7021 AI_AddGoal(me, AIG_GET_TO_POS, 2, 1.0f, -1, /*GF_NONFLUSHABLE | GF_KEEP_AT_COMPLETION |*/ GF_ORIENT_SCRIPTED,
7022 &memory->ceiling_pos, ceiling_room);
7023 AI_SetGoalCircleDist(me, 2, 0.0f);
7024
7025 // Turn on point-collide-walls
7026 flags = PF_POINT_COLLIDE_WALLS;
7027 Obj_Value(me, VF_SET_FLAGS, OBJV_I_PHYSICS_FLAGS, &flags);
7028
7029 flags = PF_LOCK_MASK;
7030 Obj_Value(me, VF_SET_FLAGS, OBJV_I_PHYSICS_FLAGS, &flags);
7031 } break;
7032 case SICKLE_LANDED: {
7033 int flags;
7034 char movement_type;
7035
7036 // Stop on ceiling
7037 flags = AIF_FORCE_AWARENESS | AIF_PERSISTANT;
7038 AI_Value(me, VF_CLEAR_FLAGS, AIV_I_FLAGS, &flags);
7039
7040 float awareness = AWARE_BARELY;
7041 AI_Value(me, VF_SET, AIV_F_AWARENESS, &awareness);
7042
7043 float sleep_fov = 1.0f;
7044 AI_Value(me, VF_SET, AIV_F_FOV, &sleep_fov);
7045
7046 movement_type = MT_NONE;
7047 Obj_Value(me, VF_SET, OBJV_C_MOVEMENT_TYPE, &movement_type);
7048 } break;
7049 case SICKLE_MELEE: {
7050 int flags;
7051 vector vel;
7052 char movement_type;
7053
7054 if (memory->mode == SICKLE_LANDED) {
7055 Obj_Value(me, VF_GET, OBJV_V_VELOCITY, &vel);
7056 vel.y -= (8.0f + ((float)rand() / (float)RAND_MAX) * 15.0f);
7057 Obj_Value(me, VF_SET, OBJV_V_VELOCITY, &vel);
7058 }
7059
7060 // Melee Mode
7061 flags = PF_LOCK_MASK | PF_POINT_COLLIDE_WALLS;
7062 Obj_Value(me, VF_CLEAR_FLAGS, OBJV_I_PHYSICS_FLAGS, &flags);
7063
7064 flags = PF_LEVELING;
7065 Obj_Value(me, VF_SET_FLAGS, OBJV_I_PHYSICS_FLAGS, &flags);
7066
7067 flags = AIF_FORCE_AWARENESS | AIF_AUTO_AVOID_FRIENDS | AIF_PERSISTANT;
7068 AI_Value(me, VF_SET_FLAGS, AIV_I_FLAGS, &flags);
7069
7070 movement_type = MT_PHYSICS;
7071 Obj_Value(me, VF_SET, OBJV_C_MOVEMENT_TYPE, &movement_type);
7072
7073 AI_SetType(me, AIT_MELEE1);
7074 } break;
7075 default:
7076 mprintf(0, "Sickle is all messed up!\n");
7077 }
7078
7079 memory->mode = mode;
7080 memory->mode_time = 0.0f;
7081 }
7082
7083 void Sickle::DoInit(int me) {
7084 int flags;
7085 msafe_struct m;
7086 m.objhandle = me;
7087
7088 tOSIRISMEMCHUNK ch;
7089 ch.id = 4;
7090 ch.size = sizeof(sickle_data);
7091 ch.my_id.type = OBJECT_SCRIPT;
7092 ch.my_id.objhandle = me;
7093
7094 memory = (sickle_data *)Scrpt_MemAlloc(&ch);
7095
7096 AI_SetType(me, AIT_AIS);
7097 flags = AIF_FORCE_AWARENESS | AIF_AUTO_AVOID_FRIENDS | AIF_PERSISTANT;
7098 AI_Value(me, VF_SET_FLAGS, AIV_I_FLAGS, &flags);
7099
7100 Obj_Value(me, VF_GET, OBJV_V_POS, &memory->home_pos);
7101 Obj_Value(me, VF_GET, OBJV_I_ROOMNUM, &memory->home_room);
7102 memory->done_turning = false;
7103 memory->done_moving = false;
7104
7105 flags = PF_LEVELING;
7106 Obj_Value(me, VF_SET_FLAGS, OBJV_I_PHYSICS_FLAGS, &flags);
7107
7108 flags = PF_POINT_COLLIDE_WALLS;
7109 Obj_Value(me, VF_CLEAR_FLAGS, OBJV_I_PHYSICS_FLAGS, &flags);
7110
7111 matrix orient;
7112 Obj_Value(me, VF_GET, OBJV_M_ORIENT, &orient);
7113 memory->home_fvec = orient.fvec;
7114 memory->home_fvec.y = 0.0f;
7115 vm_VectorNormalize(&memory->home_fvec);
7116
7117 memory->mode_time = 0.0f;
7118
7119 SetMode(me, SICKLE_MELEE);
7120 }
7121
7122 void Sickle::DoFrame(int me) {
7123 vector uvec;
7124 vector start_pos;
7125 vector end_pos;
7126 int flags;
7127 int fate;
7128 int start_room;
7129 int ceiling_room;
7130 float anim_frame;
7131 int new_mode;
7132 vector vel;
7133 float last_see_time;
7134 float last_hear_time;
7135 char movement_type;
7136
7137 float temp_time;
7138 float temp_time2;
7139 AI_Value(me, VF_GET, AIV_F_LAST_SEE_TARGET_TIME, &temp_time);
7140 AI_Value(me, VF_GET, AIV_F_LAST_HEAR_TARGET_TIME, &temp_time2);
7141
7142 last_hear_time = Game_GetTime() - temp_time2;
7143 last_see_time = Game_GetTime() - temp_time;
7144
7145 if (last_hear_time < last_see_time || memory->mode == SICKLE_LANDED) {
7146 last_see_time = last_hear_time;
7147 }
7148
7149 memory->mode_time += Game_GetTime();
7150
7151 Obj_Value(me, VF_GET, OBJV_F_ANIM_FRAME, &anim_frame);
7152
7153 new_mode = memory->mode;
7154
7155 if ((anim_frame >= 50 && anim_frame <= 55) || (last_see_time > 7.0)) {
7156 if (memory->mode == SICKLE_MELEE) {
7157 new_mode = SICKLE_GOING_HOME;
7158 }
7159 } else {
7160 new_mode = SICKLE_MELEE;
7161 }
7162
7163 if (memory->mode != new_mode) {
7164 SetMode(me, new_mode);
7165 }
7166
7167 if (memory->mode == SICKLE_GOING_HOME) {
7168 mprintf(0, "Sickle going home\n");
7169
7170 if (memory->done_moving == true) {
7171 SetMode(me, SICKLE_LAND_ON_CEILING);
7172 }
7173 } else if (memory->mode == SICKLE_LAND_ON_CEILING) {
7174 uvec.x = 0.0;
7175 uvec.y = -1.0;
7176 uvec.z = 0.0;
7177
7178 memory->done_turning = AI_TurnTowardsVectors(me, &memory->home_fvec, &uvec) != 0;
7179
7180 // mprintf(0, "Sickle Land on Ceiling %d, %d\n", memory->done_moving?1:0, memory->done_turning?1:0);
7181 vector pos;
7182 Obj_Value(me, VF_GET, OBJV_V_POS, &pos);
7183 bool f_used;
7184 AI_GoalValue(me, 2, VF_GET, AIGV_B_USED, &f_used);
7185
7186 mprintf(0, "%d Sickle Land on Ceiling %f away\n", f_used ? 1 : 0, vm_VectorDistance(&memory->ceiling_pos, &pos));
7187
7188 // mprintf(0, "In mode 10\n");
7189 int flags = PF_LEVELING;
7190 Obj_Value(me, VF_CLEAR_FLAGS, OBJV_I_PHYSICS_FLAGS, &flags);
7191
7192 if (memory->done_turning == true && memory->done_moving == true) {
7193 SetMode(me, SICKLE_LANDED);
7194 }
7195 }
7196 }
7197
7198 bool Sickle::DoNotify(int me_handle, tOSIRISEVTAINOTIFY *notify) {
7199 if ((IsGoalFinishedNotify(notify->notify_type)) &&
7200 (memory->mode == SICKLE_GOING_HOME || memory->mode == SICKLE_LAND_ON_CEILING) && (notify->goal_num == 2)) {
7201
7202 memory->done_moving = true;
7203 }
7204
7205 return true;
7206 }
7207
7208 int16_t Sickle::CallEvent(int event, tOSIRISEventInfo *data) {
7209 switch (event) {
7210 case EVT_AI_INIT:
7211 DoInit(data->me_handle);
7212 break;
7213 case EVT_AI_FRAME:
7214 DoFrame(data->me_handle);
7215 break;
7216 case EVT_AI_NOTIFY:
7217 return (DoNotify(data->me_handle, &data->evt_ai_notify) != false) ? CONTINUE_CHAIN | CONTINUE_DEFAULT : 0;
7218 break;
7219 case EVT_DESTROY:
7220 break;
7221 case EVT_MEMRESTORE: {
7222 memory = (sickle_data *)data->evt_memrestore.memory_ptr;
7223 } break;
7224 }
7225 return CONTINUE_CHAIN | CONTINUE_DEFAULT;
7226 }
7227
7228 //---------------
7229 // FireAtDist
7230 //---------------
7231
7232 void FireAtDist::DoInit(int me) {
7233 msafe_struct m;
7234 m.objhandle = me;
7235
7236 tOSIRISMEMCHUNK ch;
7237 ch.id = 4;
7238 ch.size = sizeof(fireatdist_data);
7239 ch.my_id.type = OBJECT_SCRIPT;
7240 ch.my_id.objhandle = me;
7241
7242 memory = (fireatdist_data *)Scrpt_MemAlloc(&ch);
7243
7244 memory->last_test_time = Game_GetTime();
7245 memory->last_f_fire = false;
7246 memory->me = me;
7247
7248 AI_Value(me, VF_GET, AIV_F_CIRCLE_DIST, &memory->fire_dist);
7249 }
7250
7251 void FireAtDist::DoFrame(int me) {
7252 if (memory->last_test_time + 3.0f < Game_GetTime()) {
7253 vector pos;
7254 int room;
7255 int scan_objs[200];
7256 int n_scan;
7257 int i;
7258
7259 float dist;
7260
7261 memory->last_test_time = Game_GetTime();
7262
7263 Obj_Value(memory->me, VF_GET, OBJV_V_POS, &pos);
7264 Obj_Value(memory->me, VF_GET, OBJV_I_ROOMNUM, &room);
7265
7266 AI_Value(memory->me, VF_GET, AIV_F_CIRCLE_DIST, &dist);
7267
7268 n_scan = AI_GetNearbyObjs(&pos, room, dist, scan_objs, 200, false, true, false, true);
7269
7270 memory->last_f_fire = false;
7271
7272 for (i = 0; i < n_scan; i++) {
7273 int type;
7274
7275 Obj_Value(scan_objs[i], VF_GET, OBJV_I_TYPE, &type);
7276
7277 if (type == OBJ_PLAYER) {
7278 vector p_pos;
7279 float cur_dist;
7280
7281 Obj_Value(scan_objs[i], VF_GET, OBJV_V_POS, &p_pos);
7282
7283 cur_dist = vm_VectorDistance(&pos, &p_pos);
7284
7285 if (cur_dist <= memory->fire_dist) {
7286 memory->last_f_fire = true;
7287 break;
7288 }
7289 }
7290 }
7291 }
7292
7293 int flags = AISR_RANGED_ATTACK;
7294 if (memory->last_f_fire != false) {
7295 AI_Value(me, VF_SET_FLAGS, AIV_I_STATUS_REG, &flags);
7296 } else {
7297 AI_Value(me, VF_CLEAR_FLAGS, AIV_I_STATUS_REG, &flags);
7298 }
7299 }
7300
7301 int16_t FireAtDist::CallEvent(int event, tOSIRISEventInfo *data) {
7302 switch (event) {
7303 case EVT_AI_INIT:
7304 DoInit(data->me_handle);
7305 break;
7306 case EVT_AI_FRAME:
7307 DoFrame(data->me_handle);
7308 break;
7309 case EVT_DESTROY:
7310 break;
7311 case EVT_MEMRESTORE: {
7312 memory = (fireatdist_data *)data->evt_memrestore.memory_ptr;
7313 } break;
7314 }
7315 return CONTINUE_CHAIN | CONTINUE_DEFAULT;
7316 }
7317
7318 //---------------
7319 // HatePTMC
7320 //---------------
7321
7322 void HatePTMC::DoInit(int me) {
7323 msafe_struct m;
7324 m.objhandle = me;
7325
7326 tOSIRISMEMCHUNK ch;
7327 ch.id = 4;
7328 ch.size = sizeof(hateptmc_data);
7329 ch.my_id.type = OBJECT_SCRIPT;
7330 ch.my_id.objhandle = me;
7331
7332 memory = (hateptmc_data *)Scrpt_MemAlloc(&ch);
7333
7334 memory->time_till_pulse = (float)rand() / (float)RAND_MAX + 2.0f;
7335 memory->me = me;
7336 }
7337
7338 void HatePTMC::DoFrame(int me) {
7339 int flags = AIF_TEAM_PTMC;
7340
7341 AI_Value(me, VF_GET, AIV_I_FLAGS, &flags);
7342
7343 if ((flags & AIF_TEAM_MASK) == AIF_TEAM_REBEL) {
7344 memory->time_till_pulse -= Game_GetFrameTime();
7345
7346 if (memory->time_till_pulse <= 0.0f) {
7347 memory->time_till_pulse = (float)rand() / (float)RAND_MAX + 2.0f;
7348
7349 vector pos;
7350 int room;
7351 int scan_objs[50];
7352 int n_scan;
7353 int i;
7354
7355 float dist = 200.0f;
7356
7357 Obj_Value(memory->me, VF_GET, OBJV_V_POS, &pos);
7358 Obj_Value(memory->me, VF_GET, OBJV_I_ROOMNUM, &room);
7359
7360 n_scan = AI_GetNearbyObjs(&pos, room, dist, scan_objs, 50, false, true, false, true);
7361
7362 for (i = 0; i < n_scan; i++) {
7363 char ctype;
7364 int num_wbs;
7365
7366 Obj_Value(scan_objs[i], VF_GET, OBJV_C_CONTROL_TYPE, &ctype);
7367 Obj_WBValue(scan_objs[i], 0, VF_GET, WBV_C_NUM_WBS, &num_wbs);
7368
7369 if (num_wbs > 0 && ctype == CT_AI) {
7370 int flags;
7371 int target;
7372 float last_see_target_time;
7373 int t_type = OBJ_NONE;
7374
7375 AI_Value(scan_objs[i], VF_GET, AIV_I_FLAGS, &flags);
7376 AI_Value(scan_objs[i], VF_GET, AIV_I_TARGET_HANDLE, &target);
7377 AI_Value(scan_objs[i], VF_GET, AIV_F_LAST_SEE_TARGET_TIME, &last_see_target_time);
7378
7379 if (target != OBJECT_HANDLE_NONE) {
7380 Obj_Value(target, VF_GET, OBJV_I_TYPE, &t_type);
7381 }
7382
7383 // If it is a PTMC bot
7384 if (((flags & AIF_TEAM_MASK) == AIF_TEAM_PTMC) &&
7385 !(t_type == OBJ_PLAYER && Game_GetTime() - last_see_target_time < 7.0f)) {
7386 float fov;
7387 AI_Value(scan_objs[i], VF_GET, AIV_F_FOV, &fov);
7388
7389 vector p_pos;
7390 int p_room;
7391 matrix orient;
7392
7393 Obj_Value(scan_objs[i], VF_GET, OBJV_V_POS, &p_pos);
7394 Obj_Value(scan_objs[i], VF_GET, OBJV_I_ROOMNUM, &p_room);
7395
7396 vector dir = p_pos - pos;
7397 float dist = vm_VectorNormalize(&dir);
7398
7399 Obj_Value(me, VF_GET, OBJV_M_ORIENT, &orient);
7400
7401 if (p_room == room || dist < 60.0f || orient.fvec * dir >= fov) {
7402 ray_info ray;
7403 int flags = FQ_CHECK_OBJS | FQ_IGNORE_POWERUPS | FQ_IGNORE_WEAPONS | FQ_IGNORE_MOVING_OBJECTS |
7404 FQ_IGNORE_NON_LIGHTMAP_OBJECTS;
7405 int fate = FVI_RayCast(me, &pos, &p_pos, room, 0.0f, flags, &ray);
7406
7407 if (fate == HIT_NONE) {
7408 float awareness;
7409 AI_Value(scan_objs[i], VF_GET, AIV_F_AWARENESS, &awareness);
7410 if (awareness < AWARE_MOSTLY) {
7411 awareness = AWARE_MOSTLY;
7412 AI_Value(scan_objs[i], VF_SET, AIV_F_AWARENESS, &awareness);
7413 }
7414 AI_Value(scan_objs[i], VF_SET, AIV_I_TARGET_HANDLE, &me);
7415 }
7416 }
7417 }
7418 }
7419 }
7420 }
7421 }
7422 }
7423
7424 int16_t HatePTMC::CallEvent(int event, tOSIRISEventInfo *data) {
7425 switch (event) {
7426 case EVT_AI_INIT:
7427 DoInit(data->me_handle);
7428 break;
7429 case EVT_INTERVAL:
7430 DoFrame(data->me_handle);
7431 break;
7432 case EVT_DESTROY:
7433 break;
7434 case EVT_MEMRESTORE: {
7435 memory = (hateptmc_data *)data->evt_memrestore.memory_ptr;
7436 } break;
7437 }
7438 return CONTINUE_CHAIN | CONTINUE_DEFAULT;
7439 }
7440
7441 //---------------
7442 // Tubbs
7443 //---------------
7444
7445 void Tubbs::DoInit(int me) {
7446 tOSIRISMEMCHUNK ch;
7447 ch.id = 4;
7448 ch.size = sizeof(tubbs_data);
7449 ch.my_id.type = OBJECT_SCRIPT;
7450 ch.my_id.objhandle = me;
7451
7452 memory = (tubbs_data *)Scrpt_MemAlloc(&ch);
7453
7454 int diff = Game_GetDiffLevel();
7455
7456 AI_Value(me, VF_GET, AIV_F_MAX_SPEED, &memory->base_speed);
7457 AI_Value(me, VF_GET, AIV_F_MAX_DELTA_SPEED, &memory->base_acc);
7458
7459 switch (diff) {
7460 case DIFFICULTY_TRAINEE:
7461 memory->max_speed = memory->base_speed * 1.2f;
7462 memory->max_acc = memory->base_acc * 1.1f;
7463 memory->full_anger_time = 22.0f;
7464 break;
7465 case DIFFICULTY_ROOKIE:
7466 memory->max_speed = memory->base_speed * 1.3f;
7467 memory->max_acc = memory->base_acc * 1.5f;
7468 memory->full_anger_time = 20.0f;
7469 break;
7470 case DIFFICULTY_HOTSHOT:
7471 memory->max_speed = memory->base_speed * 1.7f;
7472 memory->max_acc = memory->base_acc * 2.5f;
7473 memory->full_anger_time = 18.0f;
7474 break;
7475 case DIFFICULTY_ACE:
7476 memory->max_speed = memory->base_speed * 1.75f;
7477 memory->max_acc = memory->base_acc * 2.8f;
7478 memory->full_anger_time = 15.0f;
7479 break;
7480 case DIFFICULTY_INSANE:
7481 memory->max_speed = memory->base_speed * 1.8f;
7482 memory->max_acc = memory->base_acc * 3.0f;
7483 memory->full_anger_time = 12.0f;
7484 break;
7485 }
7486 }
7487
7488 void Tubbs::DoFrame(int me) {
7489 float see_time;
7490 AI_Value(me, VF_GET, AIV_F_LAST_SEE_TARGET_TIME, &see_time);
7491
7492 bool used;
7493 AI_GoalValue(me, 3, VF_GET, AIGV_B_USED, &used);
7494
7495 if (see_time + 4.0f > Game_GetTime() && !used) {
7496 float speed;
7497 float acc;
7498 float ft;
7499
7500 ft = Game_GetFrameTime();
7501
7502 AI_Value(me, VF_GET, AIV_F_MAX_SPEED, &speed);
7503 AI_Value(me, VF_GET, AIV_F_MAX_DELTA_SPEED, &acc);
7504
7505 speed += (memory->max_speed - memory->base_speed) * (ft / memory->full_anger_time);
7506 acc += (memory->max_acc - memory->base_acc) * (ft / memory->full_anger_time);
7507
7508 if (speed > memory->max_speed)
7509 speed = memory->max_speed;
7510 if (acc > memory->max_acc)
7511 acc = memory->max_acc;
7512
7513 // mprintf(0, "Max Speed is %f\n", speed);
7514
7515 AI_Value(me, VF_SET, AIV_F_MAX_SPEED, &speed);
7516 AI_Value(me, VF_SET, AIV_F_MAX_DELTA_SPEED, &acc);
7517 } else {
7518 AI_Value(me, VF_SET, AIV_F_MAX_SPEED, &memory->base_speed);
7519 AI_Value(me, VF_SET, AIV_F_MAX_DELTA_SPEED, &memory->base_acc);
7520 }
7521 }
7522
7523 bool Tubbs::DoNotify(int me, tOSIRISEVTAINOTIFY *notify) {
7524 int room;
7525 vector pos;
7526 int weapon_id;
7527
7528 if (notify->notify_type == AIN_MELEE_ATTACK_FRAME) {
7529 if (notify->attack_num == 0) {
7530 Obj_Value(me, VF_GET, OBJV_I_ROOMNUM, &room);
7531 Obj_GetGunPos(me, 0, &pos);
7532
7533 weapon_id = Wpn_FindID("TubbsHitBlast");
7534 Obj_Create(OBJ_WEAPON, weapon_id, room, &pos, NULL, me);
7535 }
7536 }
7537
7538 return true;
7539 }
7540
7541 int16_t Tubbs::CallEvent(int event, tOSIRISEventInfo *data) {
7542 switch (event) {
7543 case EVT_AI_INIT:
7544 DoInit(data->me_handle);
7545 break;
7546 case EVT_AI_NOTIFY:
7547 return (DoNotify(data->me_handle, &data->evt_ai_notify) != false) ? CONTINUE_CHAIN | CONTINUE_DEFAULT : 0;
7548 break;
7549 case EVT_AI_FRAME:
7550 DoFrame(data->me_handle);
7551 break;
7552 case EVT_DESTROY:
7553 break;
7554 case EVT_MEMRESTORE: {
7555 memory = (tubbs_data *)data->evt_memrestore.memory_ptr;
7556 } break;
7557 }
7558 return CONTINUE_CHAIN | CONTINUE_DEFAULT;
7559 }
7560
7561 //---------------
7562 // Old Scratch
7563 //---------------
7564
7565 bool OldScratch::DoSteal(int me, int it) {
7566 int max_tries = numSuperThiefableItems;
7567 float gen_perc, perc_chance;
7568 ;
7569 int i;
7570 int count_max, count_num;
7571 bool *attempted_steals;
7572
7573 attempted_steals = (bool *)malloc(numSuperThiefableItems * sizeof(bool));
7574 if (!attempted_steals)
7575 return false;
7576
7577 float ftime = Game_GetFrameTime();
7578 if (ftime == 0)
7579 ftime = 1.0f;
7580 srand(Game_GetTime() / ftime);
7581
7582 for (i = 0; i < numSuperThiefableItems; i++) {
7583 attempted_steals[i] = false;
7584 }
7585
7586 while (max_tries--) {
7587 i = rand() % numSuperThiefableItems;
7588
7589 if (attempted_steals[i]) {
7590 // we already tried this one, try another
7591 max_tries++;
7592 continue;
7593 }
7594
7595 attempted_steals[i] = true;
7596
7597 {
7598 count_max = MAX_STOLEN_WEAPONS;
7599
7600 // mprintf(0,"THIEF: Checking %s\n",TXT(SuperThiefableItems[i].name_idx));
7601
7602 bool can_take = false;
7603 int amount = 0;
7604 char message[256];
7605
7606 switch (SuperThiefableItems[i].type) {
7607 case THIEFABLEITEM_PRIMARY:
7608 // check to see if we can steal the primary
7609 Player_Value(it, VF_GET, PLYSV_I_WEAPON, &amount, SuperThiefableItems[i].index);
7610 if (SuperThiefableItems[i].index != 0 && amount) {
7611 can_take = true;
7612 snprintf(message, sizeof(message), TXT_THIEFSTEAL, TXT(SuperThiefableItems[i].name_idx));
7613 }
7614 break;
7615
7616 case THIEFABLEITEM_SECONDARY:
7617 // check to see if we can steal the secondary
7618 {
7619 Player_Value(it, VF_GET, PLYSV_I_WEAPON, &amount, SuperThiefableItems[i].index);
7620
7621 if (amount) {
7622 int max;
7623
7624 if (SuperThiefableItems[i].index > 14) {
7625 // 2nd selection group (black shark, etc)
7626 max = (19 - SuperThiefableItems[i].index) / 2.5f + 1;
7627 } else {
7628 // 1st selection group (mega, etc)
7629 max = (14 - SuperThiefableItems[i].index) / 2.5f + 1;
7630 }
7631
7632 int new_amount = (rand() / (float)(RAND_MAX + 1)) * max + 1;
7633
7634 if (new_amount < amount)
7635 amount = new_amount;
7636
7637 can_take = true;
7638
7639 if (amount == 1) {
7640 snprintf(message, sizeof(message), TXT_STHIEFSTEAL, TXT(SuperThiefableItems[i].name_idx));
7641 } else {
7642 snprintf(message, sizeof(message), TXT_STHIEFSTEAL2, amount, TXT(SuperThiefableItems[i].name_idx));
7643 }
7644 }
7645 }
7646 break;
7647 }
7648
7649 if (!can_take)
7650 continue;
7651
7652 {
7653 int powerup_handle;
7654 int room;
7655 vector pos;
7656 int j;
7657 uint16_t id;
7658
7659 Obj_Value(me, VF_GET, OBJV_I_ROOMNUM, &room);
7660 Obj_Value(me, VF_GET, OBJV_V_POS, &pos);
7661
7662 for (j = 0; j < amount; j++) {
7663 float speed = rand() / (float)RAND_MAX * 20.0f + 5.0f;
7664 vector dir;
7665
7666 dir.x = rand() / (float)RAND_MAX - 0.5f;
7667 dir.y = rand() / (float)RAND_MAX - 0.5f;
7668 dir.z = rand() / (float)RAND_MAX - 0.5f;
7669
7670 vm_VectorNormalize(&dir);
7671 dir *= speed;
7672
7673 Player_Value(it, VF_GET, PLYSV_US_WEAPON_POWERUP_ID, &id, SuperThiefableItems[i].index);
7674 powerup_handle = Obj_Create(OBJ_POWERUP, id, room, &pos, NULL, it, &dir);
7675 }
7676 }
7677
7678 if (SuperThiefableItems[i].type == THIEFABLEITEM_PRIMARY) {
7679 amount = 0;
7680 } else {
7681 amount *= -1;
7682 }
7683
7684 Player_Value(it, VF_SET, PLYSV_I_WEAPON, &amount, SuperThiefableItems[i].index);
7685
7686 free(attempted_steals);
7687 return true;
7688 }
7689 }
7690
7691 mprintf(0, "Super Thief: Not taking anything\n");
7692 free(attempted_steals);
7693 return false; // we didn't take anything this try
7694 }
7695
7696 void OldScratch::DoInit(int me) {
7697 tOSIRISMEMCHUNK ch;
7698 ch.id = 4;
7699 ch.size = sizeof(oldscratch_data);
7700 ch.my_id.type = OBJECT_SCRIPT;
7701 ch.my_id.objhandle = me;
7702
7703 memory = (oldscratch_data *)Scrpt_MemAlloc(&ch);
7704
7705 int diff = Game_GetDiffLevel();
7706
7707 AI_Value(me, VF_GET, AIV_F_MAX_SPEED, &memory->base_speed);
7708 AI_Value(me, VF_GET, AIV_F_MAX_DELTA_SPEED, &memory->base_acc);
7709
7710 switch (diff) {
7711 case DIFFICULTY_TRAINEE:
7712 memory->max_speed = memory->base_speed * 1.05f;
7713 memory->max_acc = memory->base_acc * 1.05f;
7714 memory->full_anger_time = 22.0f;
7715 break;
7716 case DIFFICULTY_ROOKIE:
7717 memory->max_speed = memory->base_speed * 1.075f;
7718 memory->max_acc = memory->base_acc * 1.2f;
7719 memory->full_anger_time = 20.0f;
7720 break;
7721 case DIFFICULTY_HOTSHOT:
7722 memory->max_speed = memory->base_speed * 1.1f;
7723 memory->max_acc = memory->base_acc * 1.3f;
7724 memory->full_anger_time = 18.0f;
7725 break;
7726 case DIFFICULTY_ACE:
7727 memory->max_speed = memory->base_speed * 1.125f;
7728 memory->max_acc = memory->base_acc * 1.4f;
7729 memory->full_anger_time = 15.0f;
7730 break;
7731 case DIFFICULTY_INSANE:
7732 memory->max_speed = memory->base_speed * 1.2f;
7733 memory->max_acc = memory->base_acc * 1.5f;
7734 memory->full_anger_time = 12.0f;
7735 break;
7736 }
7737 }
7738
7739 void OldScratch::DoFrame(int me) {
7740 float see_time;
7741 AI_Value(me, VF_GET, AIV_F_LAST_SEE_TARGET_TIME, &see_time);
7742
7743 bool used;
7744 AI_GoalValue(me, 3, VF_GET, AIGV_B_USED, &used);
7745
7746 if (see_time + 4.0f > Game_GetTime() && !used) {
7747 float speed;
7748 float acc;
7749 float ft;
7750
7751 ft = Game_GetFrameTime();
7752
7753 AI_Value(me, VF_GET, AIV_F_MAX_SPEED, &speed);
7754 AI_Value(me, VF_GET, AIV_F_MAX_DELTA_SPEED, &acc);
7755
7756 speed += (memory->max_speed - memory->base_speed) * (ft / memory->full_anger_time);
7757 acc += (memory->max_acc - memory->base_acc) * (ft / memory->full_anger_time);
7758
7759 if (speed > memory->max_speed)
7760 speed = memory->max_speed;
7761 if (acc > memory->max_acc)
7762 acc = memory->max_acc;
7763
7764 // mprintf(0, "Max Speed is %f\n", speed);
7765
7766 AI_Value(me, VF_SET, AIV_F_MAX_SPEED, &speed);
7767 AI_Value(me, VF_SET, AIV_F_MAX_DELTA_SPEED, &acc);
7768 } else {
7769 AI_Value(me, VF_SET, AIV_F_MAX_SPEED, &memory->base_speed);
7770 AI_Value(me, VF_SET, AIV_F_MAX_DELTA_SPEED, &memory->base_acc);
7771 }
7772 }
7773
7774 bool OldScratch::DoNotify(int me, tOSIRISEVTAINOTIFY *notify) {
7775 if (notify->notify_type == AIN_MELEE_HIT) {
7776 int target_handle;
7777 int target_type;
7778 int target_flags;
7779
7780 AI_Value(me, VF_GET, AIV_I_TARGET_HANDLE, &target_handle);
7781 Obj_Value(target_handle, VF_GET, OBJV_I_TYPE, &target_type);
7782 Obj_Value(target_handle, VF_GET, OBJV_I_FLAGS, &target_flags);
7783
7784 int diff = Game_GetDiffLevel();
7785 float chance = (float)rand() / (float)RAND_MAX;
7786
7787 if (diff == 0 && chance < 0.60f)
7788 return true;
7789
7790 if (diff == 1 && chance < 0.40f)
7791 return true;
7792
7793 if (target_type == OBJ_PLAYER && (target_flags & OF_DESTROYABLE)) {
7794 bool f_success;
7795 f_success = DoSteal(me, target_handle);
7796 }
7797 }
7798
7799 return true;
7800 }
7801
7802 int16_t OldScratch::CallEvent(int event, tOSIRISEventInfo *data) {
7803 switch (event) {
7804 case EVT_AI_INIT:
7805 DoInit(data->me_handle);
7806 break;
7807 case EVT_AI_NOTIFY:
7808 return (DoNotify(data->me_handle, &data->evt_ai_notify) != false) ? CONTINUE_CHAIN | CONTINUE_DEFAULT : 0;
7809 break;
7810 case EVT_AI_FRAME:
7811 DoFrame(data->me_handle);
7812 break;
7813 case EVT_DESTROY:
7814 break;
7815 case EVT_MEMRESTORE: {
7816 memory = (oldscratch_data *)data->evt_memrestore.memory_ptr;
7817 } break;
7818 }
7819 return CONTINUE_CHAIN | CONTINUE_DEFAULT;
7820 }
7821
7822 //---------------------
7823 // BarnSwallow
7824 //---------------------
7825
7826 void BarnSwallow::ComputeNextNestPnt(int me, vector *pos) {
7827 pos->x = (0.5f - (float)rand() / (float)RAND_MAX);
7828 pos->y = (0.5f - (float)rand() / (float)RAND_MAX);
7829 pos->z = (0.5f - (float)rand() / (float)RAND_MAX);
7830
7831 pos->y *= 0.3f;
7832
7833 vm_VectorNormalize(pos);
7834
7835 *pos = *pos * memory->nest_rad;
7836 *pos += memory->nest_center;
7837 }
7838
7839 // #define BSCOMM_FOLLOW_ME 0 // send a percent chance so we
7840 // can have a line sometimes #define BSCOMM_FOLLOW_CANCEL_FROM_FOLLOWER 2 #define
7841 // BSCOMM_FOLLOW_CANCEL_FROM_LEADER 3
7842 // #define BSCOMM_ATTACK_MY_TARGET 4
7843 // BSCOMM_ARE_YOU_IN_MODE
7844
7845 bool BarnSwallow::ReceiveCommand(int me, int it, gb_com *command) {
7846 bool f_ok = true;
7847
7848 switch (command->action) {
7849 case BSCOMM_FOLLOW_ME:
7850 SetMode(me, BSM_FOLLOW, it);
7851 break;
7852 case BSCOMM_FOLLOW_CANCEL_FROM_FOLLOWER:
7853 memory->follower = OBJECT_HANDLE_NONE;
7854 break;
7855 case BSCOMM_FOLLOW_CANCEL_FROM_LEADER: {
7856 SetMode(me, BSM_RETURN_TO_NEST);
7857 } break;
7858 case BSCOMM_ATTACK_MY_TARGET: {
7859 int flags;
7860 int room;
7861 int me_room;
7862
7863 Obj_Value(it, VF_GET, OBJV_I_FLAGS, &flags);
7864 Obj_Value(it, VF_GET, OBJV_I_ROOMNUM, &room);
7865 Obj_Value(me, VF_GET, OBJV_I_FLAGS, &me_room);
7866
7867 if ((flags & OF_ATTACHED) && rand() % 10 > 3) {
7868 SetMode(me, BSM_ATTACK, it);
7869 } else if (me_room == room) {
7870 SetMode(me, BSM_ATTACK, it);
7871 } else if (rand() % 10 > 6) {
7872 SetMode(me, BSM_ATTACK, it);
7873 } else {
7874 f_ok = false;
7875 }
7876 } break;
7877 case BSCOMM_ARE_YOU_IN_MODE: {
7878 f_ok = (memory->mode == command->index);
7879 } break;
7880 case BSCOMM_ARE_YOU_AFTER_POWERUP: {
7881 f_ok = (memory->powerup_id == command->index);
7882 }
7883 }
7884
7885 return f_ok;
7886 }
7887
7888 bool BarnSwallow::SendCommand(int me, int it, char action, int value) {
7889 bool f_ok;
7890 tOSIRISEventInfo data;
7891 gb_com command;
7892
7893 data.me_handle = it;
7894 data.evt_ai_notify.it_handle = me;
7895
7896 command.action = action;
7897 command.index = value;
7898
7899 data.extra_info = (void *)&command;
7900 data.evt_ai_notify.notify_type = AIN_USER_DEFINED;
7901
7902 f_ok = Obj_CallEvent(it, EVT_AI_NOTIFY, &data);
7903 if (f_ok || command.action == BSCOMM_FOLLOW_CANCEL_FROM_LEADER) {
7904 switch (command.action) {
7905 case BSCOMM_FOLLOW_ME:
7906 memory->follower = it;
7907 break;
7908 case BSCOMM_FOLLOW_CANCEL_FROM_FOLLOWER:
7909 memory->follower = OBJECT_HANDLE_NONE;
7910 break;
7911 case BSCOMM_FOLLOW_CANCEL_FROM_LEADER:
7912 memory->follower = OBJECT_HANDLE_NONE;
7913 break;
7914 }
7915 }
7916 return f_ok;
7917 }
7918
7919 void BarnSwallow::DoInit(int me) {
7920 int i;
7921 tOSIRISMEMCHUNK ch;
7922 ch.id = 4;
7923 ch.size = sizeof(barnswallow_data);
7924 ch.my_id.type = OBJECT_SCRIPT;
7925 ch.my_id.objhandle = me;
7926
7927 memory = (barnswallow_data *)Scrpt_MemAlloc(&ch);
7928
7929 memory->follower = OBJECT_HANDLE_NONE;
7930
7931 ComputeNest(me);
7932
7933 memory->next_friend_update_time = Game_GetTime() + 5.0f + ((float)rand() / (float)RAND_MAX) * 3.0f;
7934 memory->next_attack_time = Game_GetTime();
7935 memory->next_powerup_time = Game_GetTime() + 5.0f + ((float)rand() / (float)RAND_MAX) * 2.0f;
7936
7937 memory->last_non_attack_mode = memory->mode = BSM_NEST;
7938 memory->mode_time = 0.0f;
7939
7940 memory->flags = 0;
7941
7942 SetMode(me, BSM_NEST);
7943 }
7944
7945 bool BarnSwallow::DoNotify(int me, tOSIRISEventInfo *data) {
7946 if (IsGoalFinishedNotify(data->evt_ai_notify.notify_type)) // chrishack -- handle invalid goal cases if I should
7947 {
7948 switch (memory->mode) {
7949 case BSM_NEST: {
7950 if (data->evt_ai_notify.goal_num == 1) {
7951 SetMode(me, BSM_NEST);
7952 return false;
7953 }
7954 } break;
7955 case BSM_GET_POWERUP: {
7956 if (data->evt_ai_notify.goal_num == 1) {
7957 SetMode(me, BSM_RETURN_TO_NEST);
7958 return false;
7959 }
7960 } break;
7961 case BSM_RETURN_TO_NEST: {
7962 if (data->evt_ai_notify.goal_num == 1) {
7963 SetMode(me, BSM_NEST);
7964 return false;
7965 }
7966 } break;
7967 case BSM_ATTACK:
7968 if (data->evt_ai_notify.goal_num == 1) {
7969 SetMode(me, BSM_ATTACK_CIRCLE_BACK);
7970 return false;
7971 }
7972 break;
7973 }
7974 } else if (data->evt_ai_notify.notify_type == AIN_USER_DEFINED) {
7975 return ReceiveCommand(me, data->evt_ai_notify.it_handle, (gb_com *)data->extra_info);
7976 }
7977
7978 return true;
7979 }
7980
7981 void BarnSwallow::ComputeNest(int me) {
7982 memory->num_friends = 0;
7983 int scan_objs[100];
7984 int n_scan;
7985 int i;
7986 vector pos;
7987 int room;
7988 int type;
7989 uint16_t id;
7990
7991 memory->num_friends = 0;
7992
7993 for (i = 0; i < BS_MAX_FRIENDS; i++)
7994 memory->friends[i] = OBJECT_HANDLE_NONE;
7995
7996 Obj_Value(me, VF_GET, OBJV_V_POS, &pos);
7997 Obj_Value(me, VF_GET, OBJV_I_ROOMNUM, &room);
7998 Obj_Value(me, VF_GET, OBJV_I_TYPE, &type);
7999 Obj_Value(me, VF_GET, OBJV_US_ID, &id);
8000
8001 memory->home_room = room;
8002 memory->nest_center =
8003 pos; // Each robot will have a different center point becuase thier initial positions are weighted twice
8004 memory->nest_rad = 0.0f;
8005
8006 n_scan = AI_GetNearbyObjs(&pos, room, 1000.0f, scan_objs, 100, false, true, false, true);
8007
8008 for (i = 0; i < n_scan; i++) {
8009 if (scan_objs[i] != me) {
8010 int c_type;
8011 uint16_t c_id;
8012 Obj_Value(scan_objs[i], VF_GET, OBJV_I_TYPE, &c_type);
8013 Obj_Value(scan_objs[i], VF_GET, OBJV_US_ID, &c_id);
8014
8015 // See if we are the same species
8016 if (type == c_type && id == c_id) {
8017 vector c_pos;
8018 Obj_Value(scan_objs[i], VF_GET, OBJV_V_POS, &c_pos);
8019
8020 memory->nest_center += c_pos;
8021
8022 memory->friends[memory->num_friends++] = scan_objs[i];
8023 }
8024 }
8025 }
8026
8027 if (memory->num_friends)
8028 memory->nest_center /= memory->num_friends + 1;
8029
8030 // Determine the farthest distance from the center of the nest
8031 for (i = 0; i < memory->num_friends; i++) {
8032 vector c_pos;
8033 float dist;
8034 Obj_Value(memory->friends[i], VF_GET, OBJV_V_POS, &c_pos);
8035 dist = vm_VectorDistance(&memory->nest_center, &c_pos);
8036
8037 if (dist * 0.9f > memory->nest_rad)
8038 memory->nest_rad = dist * 0.9f;
8039 }
8040
8041 if (memory->nest_rad < 5.0f)
8042 memory->nest_rad = 5.0f;
8043 }
8044
8045 void BarnSwallow::UpdateFriendList(int me) {
8046 int i;
8047 int j;
8048
8049 for (i = 0; i < memory->num_friends; i++) {
8050 int type;
8051 Obj_Value(memory->friends[i], VF_GET, OBJV_I_TYPE, &type);
8052
8053 if (type == OBJ_NONE) {
8054 for (j = i; j < memory->num_friends - 1; j++) {
8055 memory->friends[j] = memory->friends[j + 1];
8056 }
8057
8058 i--; // Retest as the slot is now being used by what was the next item
8059 memory->num_friends--;
8060 }
8061 }
8062 }
8063
8064 void BarnSwallow::DoFrame(int me) {
8065 if (memory->next_friend_update_time < Game_GetTime()) {
8066 memory->next_friend_update_time = Game_GetTime() + 5.0f + ((float)rand() / (float)RAND_MAX) * 3.0f;
8067
8068 UpdateFriendList(me);
8069 }
8070
8071 switch (memory->mode) {
8072 case BSM_NEST: {
8073 if (Game_GetTime() > memory->next_mode_time) {
8074 int target;
8075 int room = 0;
8076 int me_room = 0;
8077
8078 AI_Value(me, VF_GET, AIV_I_TARGET_HANDLE, &target);
8079
8080 if (target != OBJECT_HANDLE_NONE) {
8081 Obj_Value(target, VF_GET, OBJV_I_ROOMNUM, &room);
8082 Obj_Value(me, VF_GET, OBJV_I_ROOMNUM, &me_room);
8083 }
8084
8085 if (target != OBJECT_HANDLE_NONE && room == me_room)
8086 SetMode(me, BSM_ATTACK);
8087 else
8088 SetMode(me, BSM_NEST);
8089 }
8090
8091 if (Game_GetTime() > memory->next_powerup_time) {
8092 int rand_val = rand() % 100;
8093
8094 memory->next_powerup_time = Game_GetTime() + 5.0f + ((float)rand() / (float)RAND_MAX) * 2.0f;
8095
8096 if (rand_val < 20) // Play with local powerups
8097 {
8098 int scan_objs[50];
8099 int n_scan;
8100 int i;
8101 int n_powerups = 0;
8102 int powerups[50];
8103 int room;
8104 vector pos;
8105
8106 Obj_Value(me, VF_GET, OBJV_V_POS, &pos);
8107 Obj_Value(me, VF_GET, OBJV_I_ROOMNUM, &room);
8108
8109 n_scan = AI_GetNearbyObjs(&pos, room, 30.0f, scan_objs, 50, false, false, false, true);
8110
8111 for (i = 0; i < n_scan; i++) {
8112 int type;
8113 Obj_Value(scan_objs[i], VF_GET, OBJV_I_TYPE, &type);
8114 if (type == OBJ_POWERUP) {
8115 powerups[n_powerups++] = scan_objs[i];
8116 }
8117 }
8118
8119 if (n_powerups) {
8120 int index = rand() % n_powerups;
8121 SetMode(me, BSM_GET_POWERUP, powerups[index]);
8122 }
8123 }
8124 if (rand_val > 95) // Find a remote powerup and go get it
8125 {
8126 int i;
8127 bool f_ok = true;
8128
8129 // for(i = 0; i < memory->num_friends; i++)
8130 // {
8131 // int room = memory->home_room; // Acounts for dead friends
8132 // }
8133
8134 int p_handle = AI_FindObjOfType(me, OBJ_POWERUP, -1, true);
8135
8136 for (i = 0; i < memory->num_friends; i++) {
8137 if (SendCommand(me, memory->friends[i], BSCOMM_ARE_YOU_AFTER_POWERUP, p_handle)) {
8138 p_handle = OBJECT_HANDLE_NONE;
8139 break;
8140 }
8141 }
8142
8143 if (p_handle != OBJECT_HANDLE_NONE) {
8144 SetMode(me, BSM_GET_POWERUP, p_handle);
8145 }
8146 }
8147 }
8148 } break;
8149 case BSM_FOLLOW: {
8150 } break;
8151 case BSM_GET_POWERUP: {
8152 if (memory->mode_time > memory->max_time_on_road) {
8153 SetMode(me, BSM_RETURN_TO_NEST);
8154 }
8155 } break;
8156 case BSM_ATTACK: {
8157 float last_see_target_time;
8158 float last_hear_target_time;
8159 AI_Value(me, VF_GET, AIV_F_LAST_SEE_TARGET_TIME, &last_see_target_time);
8160 AI_Value(me, VF_GET, AIV_F_LAST_HEAR_TARGET_TIME, &last_hear_target_time);
8161
8162 if (Game_GetTime() > last_see_target_time + 7.0f && Game_GetTime() > last_hear_target_time + 7.0f)
8163 SetMode(me, memory->last_non_attack_mode);
8164 float dist;
8165 AI_GoalValue(me, 1, VF_GET, AIGV_F_DIST_TO_GOAL, &dist);
8166 } break;
8167 case BSM_ATTACK_CIRCLE_BACK: {
8168 float last_see_target_time;
8169 float last_hear_target_time;
8170 AI_Value(me, VF_GET, AIV_F_LAST_SEE_TARGET_TIME, &last_see_target_time);
8171 AI_Value(me, VF_GET, AIV_F_LAST_HEAR_TARGET_TIME, &last_hear_target_time);
8172
8173 if (Game_GetTime() > last_see_target_time + 7.0f && Game_GetTime() > last_hear_target_time + 7.0f)
8174 SetMode(me, memory->last_non_attack_mode);
8175
8176 if (memory->mode_time > 5.0f)
8177 SetMode(me, BSM_ATTACK);
8178 } break;
8179 case BSM_FLEE: {
8180 } break;
8181 case BSM_RETURN_TO_NEST: {
8182
8183 } break;
8184 }
8185
8186 memory->mode_time += Game_GetFrameTime();
8187 }
8188
8189 bool BarnSwallow::SetMode(int me, char mode, int it) {
8190 // if(mode == BSM_ATTACK && memory->next_attack_time < Game_GetTime())
8191 // return false;
8192 int f_attack_flags = (AIF_FIRE | AIF_AUTO_AVOID_FRIENDS);
8193
8194 AI_Value(me, VF_CLEAR_FLAGS, AIV_I_FLAGS, &f_attack_flags);
8195
8196 if (memory->mode != BSM_ATTACK && memory->mode != BSM_ATTACK_CIRCLE_BACK) {
8197 memory->last_non_attack_mode = memory->mode;
8198
8199 if (mode != BSM_ATTACK && mode != BSM_ATTACK_CIRCLE_BACK)
8200 memory->powerup_id = OBJECT_HANDLE_NONE;
8201 } else {
8202 if (mode == BSM_GET_POWERUP)
8203 it = memory->powerup_id;
8204 }
8205
8206 // If we are not just floating around in the nest, then reset the next_powerup_time
8207 if (mode == BSM_NEST && memory->mode != BSM_NEST)
8208 memory->next_powerup_time = Game_GetTime() + 5.0f + ((float)rand() / (float)RAND_MAX) * 2.0f;
8209
8210 if (memory->mode == BSM_RETURN_TO_NEST) {
8211 Obj_UnattachChildren(me);
8212 memory->powerup_id = OBJECT_HANDLE_NONE;
8213 }
8214
8215 AI_SetType(me, AIT_AIS);
8216
8217 switch (mode) {
8218 case BSM_NEST: {
8219 int room;
8220 float max_speed;
8221 vector pos;
8222
8223 AI_Value(me, VF_GET, AIV_F_MAX_SPEED, &max_speed);
8224 float update_time = memory->nest_rad / (max_speed) + 0.3f - ((float)rand() / (float)RAND_MAX);
8225 if (update_time < .6f)
8226 update_time = .6f;
8227
8228 memory->next_mode_time = Game_GetTime() + update_time;
8229
8230 ComputeNextNestPnt(me, &pos);
8231
8232 AI_AddGoal(me, AIG_GET_TO_POS, 1, 1.0, -1, GF_ORIENT_VELOCITY | GF_USE_BLINE_IF_SEES_GOAL, &pos, memory->home_room);
8233 AI_SetGoalCircleDist(me, 1, 10.0f);
8234 } break;
8235 case BSM_FOLLOW: {
8236 } break;
8237 case BSM_GET_POWERUP: {
8238 float dist = 20.0f;
8239
8240 AI_AddGoal(me, AIG_ATTACH_TO_OBJ, 1, 1.0f, -1, GF_ORIENT_VELOCITY, it, 0, 0, 0.9f, 0, 1);
8241 AI_GoalValue(me, 1, VF_SET, AIGV_F_CIRCLE_DIST, &dist);
8242
8243 // Make the barnswallow return home after awhile -- chrishack -- check vis before returning!
8244 memory->max_time_on_road = 12.0f + (float)rand() / (float)RAND_MAX * 20.0f;
8245 memory->powerup_id = it;
8246 } break;
8247 case BSM_ATTACK: {
8248 float dist = 40.0f + ((float)rand() / (float)RAND_MAX) * 10.0f;
8249 AI_Value(me, VF_SET_FLAGS, AIV_I_FLAGS, &f_attack_flags);
8250
8251 memory->next_attack_time = Game_GetTime() + 10.0 * ((float)rand() / (float)RAND_MAX);
8252
8253 AI_AddGoal(me, AIG_GET_TO_OBJ, 1, 1.0f, -1,
8254 GF_SPEED_ATTACK | GF_ORIENT_VELOCITY | GF_OBJ_IS_TARGET | GF_USE_BLINE_IF_SEES_GOAL, OBJECT_HANDLE_NONE);
8255 AI_GoalValue(me, 1, VF_SET, AIGV_F_CIRCLE_DIST, &dist);
8256
8257 dist = 40.0f;
8258 int g_index = AI_AddGoal(me, AIG_GET_AROUND_OBJ, ACTIVATION_BLEND_LEVEL, 1.0f, -1,
8259 GF_ORIENT_VELOCITY | GF_OBJ_IS_TARGET, OBJECT_HANDLE_NONE);
8260 AI_GoalValue(me, g_index, VF_SET, AIGV_F_CIRCLE_DIST, &dist);
8261 } break;
8262 case BSM_ATTACK_CIRCLE_BACK: {
8263 vector pos;
8264 int room;
8265
8266 AI_Value(me, VF_SET_FLAGS, AIV_I_FLAGS, &f_attack_flags);
8267
8268 Obj_Value(me, VF_GET, OBJV_V_POS, &pos);
8269 Obj_Value(me, VF_GET, OBJV_I_ROOMNUM, &room);
8270
8271 AI_AddGoal(me, AIG_WANDER_AROUND, 1, 1.0f, -1,
8272 GF_SPEED_FLEE | GF_ORIENT_VELOCITY | GF_NOTIFIES | GF_KEEP_AT_COMPLETION, &pos, room);
8273
8274 float dist = 40.0f;
8275 int g_index = AI_AddGoal(me, AIG_GET_AROUND_OBJ, ACTIVATION_BLEND_LEVEL, 1.0f, -1,
8276 GF_ORIENT_VELOCITY | GF_OBJ_IS_TARGET, OBJECT_HANDLE_NONE);
8277 AI_GoalValue(me, g_index, VF_SET, AIGV_F_CIRCLE_DIST, &dist);
8278 } break;
8279 case BSM_FLEE: {
8280 } break;
8281 case BSM_RETURN_TO_NEST: {
8282 AI_AddGoal(me, AIG_GET_TO_POS, 1, 1.0, -1, GF_SPEED_FLEE | GF_ORIENT_VELOCITY | GF_USE_BLINE_IF_SEES_GOAL,
8283 &memory->nest_center, memory->home_room);
8284 AI_SetGoalCircleDist(me, 1, 5.0f);
8285 } break;
8286 }
8287
8288 memory->mode = mode;
8289
8290 memory->mode_time = 0.0f;
8291 return true;
8292 }
8293
8294 int16_t BarnSwallow::CallEvent(int event, tOSIRISEventInfo *data) {
8295 switch (event) {
8296 case EVT_AI_FRAME:
8297 DoFrame(data->me_handle);
8298 break;
8299 case EVT_AI_INIT:
8300 DoInit(data->me_handle);
8301 break;
8302 case EVT_AI_NOTIFY:
8303 return (DoNotify(data->me_handle, data) != false) ? CONTINUE_CHAIN | CONTINUE_DEFAULT : 0;
8304 break;
8305 case EVT_DESTROY:
8306 break;
8307 case EVT_MEMRESTORE: {
8308 memory = (barnswallow_data *)data->evt_memrestore.memory_ptr;
8309 } break;
8310 }
8311 return CONTINUE_CHAIN | CONTINUE_DEFAULT;
8312 }
8313
8314 //===================
8315 // GBPowerup
8316 //===================
8317
8318 void GBPowerup::DoInit(int me) {
8319 int i;
8320 tOSIRISMEMCHUNK ch;
8321 ch.id = 4;
8322 ch.size = sizeof(gbpowerup_data);
8323 ch.my_id.type = OBJECT_SCRIPT;
8324 ch.my_id.objhandle = me;
8325
8326 memory = (gbpowerup_data *)Scrpt_MemAlloc(&ch);
8327 memory->next_check_time = Game_GetTime() + (float)rand() / (float)RAND_MAX; // Sead the powerups differently :)
8328 memory->time_till_next_hud_message = 0.0f;
8329
8330 uint16_t short_id[6];
8331
8332 short_id[0] = Obj_FindID("Buddyextinguisher");
8333 short_id[1] = Obj_FindID("buddywingnut");
8334 short_id[2] = Obj_FindID("buddycontrol");
8335 short_id[3] = Obj_FindID("buddyassist");
8336 short_id[4] = Obj_FindID("buddyantivirus");
8337 short_id[5] = Obj_FindID("buddyspeed");
8338
8339 uint16_t id;
8340 Obj_Value(me, VF_GET, OBJV_US_ID, &id);
8341
8342 memory->type = 5; // Forces it to the speed powerup if it didn't know what it was...
8343 for (i = 0; i < 6; i++) {
8344 if (id == short_id[i]) {
8345 memory->type = i;
8346 }
8347 }
8348 }
8349
8350 void GBPowerup::DoFrame(int me) {
8351 if (memory->next_check_time <= Game_GetTime()) {
8352 vector pos;
8353 int room;
8354 int scan_objs[25];
8355 int n_scan;
8356 int i;
8357
8358 memory->next_check_time = Game_GetTime() + .2f + ((float)rand() / (float)RAND_MAX) * .3f;
8359
8360 Obj_Value(me, VF_GET, OBJV_V_POS, &pos);
8361 Obj_Value(me, VF_GET, OBJV_I_ROOMNUM, &room);
8362
8363 n_scan = AI_GetNearbyObjs(&pos, room, 5.0f, scan_objs, 25, false, true, false, true);
8364
8365 for (i = 0; i < n_scan; i++) {
8366 int type;
8367 int16_t id;
8368 Obj_Value(scan_objs[i], VF_GET, OBJV_I_TYPE, &type);
8369 Obj_Value(scan_objs[i], VF_GET, OBJV_US_ID, &id);
8370
8371 if (type == OBJ_ROBOT && (id == ROBOT_GUIDEBOT || id == ROBOT_GUIDEBOTRED)) {
8372 vector g_pos;
8373 Obj_Value(scan_objs[i], VF_GET, OBJV_V_POS, &g_pos);
8374
8375 float dist = vm_VectorDistance(&pos, &g_pos);
8376
8377 if (dist < 5.0f) {
8378 gb_com command;
8379 command.action = COM_POWERUP_PICKUP;
8380 command.index = memory->type;
8381
8382 tOSIRISEventInfo data;
8383 data.me_handle = scan_objs[i];
8384 data.evt_ai_notify.it_handle = me;
8385
8386 data.extra_info = (void *)&command;
8387 data.evt_ai_notify.notify_type = AIN_USER_DEFINED;
8388
8389 Obj_CallEvent(scan_objs[i], EVT_AI_NOTIFY, &data);
8390
8391 break;
8392 }
8393 }
8394 }
8395 }
8396 }
8397
8398 int16_t GBPowerup::CallEvent(int event, tOSIRISEventInfo *data) {
8399 switch (event) {
8400 case EVT_INTERVAL:
8401 memory->time_till_next_hud_message -= Game_GetFrameTime();
8402 break;
8403 case EVT_AI_INIT:
8404 DoInit(data->me_handle);
8405 break;
8406 case EVT_AI_FRAME:
8407 DoFrame(data->me_handle);
8408 break;
8409 case EVT_COLLIDE: {
8410 if (memory->time_till_next_hud_message <= 0.0f) {
8411 int type;
8412
8413 memory->time_till_next_hud_message = 1.0f;
8414 Obj_Value(data->evt_collide.it_handle, VF_GET, OBJV_I_TYPE, &type);
8415
8416 if (type == OBJ_PLAYER) {
8417 Player_AddHudMessage(data->evt_collide.it_handle, TXT_GB_POWERUP);
8418 }
8419 }
8420 } break;
8421 case EVT_MEMRESTORE: {
8422 memory = (gbpowerup_data *)data->evt_memrestore.memory_ptr;
8423 } break;
8424 }
8425 return CONTINUE_CHAIN | CONTINUE_DEFAULT;
8426 }
8427
8428 //------------------
8429 // Sparky class
8430 //------------------
8431
8432 bool Sparky::DoNotify(int me_handle, tOSIRISEventInfo *data) {
8433 // NOTE: I am also doing the rotational stuff here... So, no need to make a seperate AIN_SCRIPTED_ORIENT event
8434 if (data->evt_ai_notify.goal_num == 0 && data->evt_ai_notify.notify_type == AIN_SCRIPTED_GOAL) {
8435 vector rvel;
8436 Obj_Value(me_handle, VF_GET, OBJV_V_ROTVELOCITY, &rvel);
8437
8438 if (memory->spin_dir == SPARKY_ROT_LEFT) {
8439 rvel.y -= DEATH_ROT_ACC * Game_GetFrameTime();
8440 } else {
8441 rvel.y += DEATH_ROT_ACC * Game_GetFrameTime();
8442 }
8443
8444 Obj_Value(me_handle, VF_SET, OBJV_V_ROTVELOCITY, &rvel);
8445
8446 vector dir = Zero_vector;
8447 AI_Value(me_handle, VF_SET, AIV_V_MOVEMENT_DIR, &dir);
8448 }
8449
8450 return true;
8451 }
8452
8453 void Sparky::SetMode(int me, char mode) {
8454 AI_SetType(me, AIT_AIS);
8455
8456 switch (mode) {
8457 case SPARKY_NORMAL: {
8458 Obj_Value(me, VF_SET, OBJV_F_ROTDRAG, &memory->drag);
8459 AI_SetType(me, AIT_MELEE1);
8460 } break;
8461 case SPARKY_DYING: {
8462 AI_AddGoal(me, AIG_SCRIPTED, 0, 1000.0f, -1, GF_NONFLUSHABLE | GF_ORIENT_SCRIPTED, NULL);
8463
8464 float drag = 0.0f;
8465 Obj_Value(me, VF_SET, OBJV_F_ROTDRAG, &drag);
8466 } break;
8467 }
8468
8469 memory->last_spark_time = Game_GetTime();
8470 memory->spin_time = 0.0f;
8471 memory->mode_time = 0.0f;
8472 memory->mode = mode;
8473 }
8474
8475 void Sparky::DoInit(int me) {
8476 tOSIRISMEMCHUNK ch;
8477 ch.id = 4;
8478 ch.size = sizeof(sparky_data);
8479 ch.my_id.type = OBJECT_SCRIPT;
8480 ch.my_id.objhandle = me;
8481
8482 memory = (sparky_data *)Scrpt_MemAlloc(&ch);
8483
8484 memory->f_rotation_death_enabled = true;
8485 memory->matcen_id = -1;
8486 memory->mode = SPARKY_NORMAL;
8487 memory->mode_time = 0.0f;
8488 memory->spin_dir = SPARKY_NO_ROT;
8489 memory->spin_time = 0.0f;
8490
8491 Obj_Value(me, VF_SET, OBJV_F_ROTDRAG, &memory->drag);
8492 Obj_Value(me, VF_GET, OBJV_M_ORIENT, &memory->orient);
8493
8494 msafe_struct mstruct;
8495
8496 mstruct.objhandle = me;
8497 mstruct.g1 = 0;
8498 mstruct.g2 = 1;
8499 mstruct.lifetime = 1000000000.0f;
8500 mstruct.size = 5.1f;
8501
8502 Obj_Value(me, VF_GET, OBJV_I_ROOMNUM, &mstruct.roomnum);
8503 Obj_GetGunPos(me, 0, &mstruct.pos);
8504 Obj_GetGunPos(me, 1, &mstruct.pos2);
8505
8506 mstruct.state = 0;
8507 mstruct.interval = 0.5f;
8508 mstruct.count = 2;
8509 mstruct.index = 2;
8510 mstruct.texnum = Scrpt_FindTextureName("FunkyEffect2");
8511 // rbg
8512 mstruct.color = ((128 >> 3) << 10) | ((128 >> 3) << 5) | (128 >> 3);
8513 mstruct.flags = 1;
8514 MSafe_CallFunction(MSAFE_WEATHER_LIGHTNING_BOLT, &mstruct);
8515
8516 memory->last_spark_time = Game_GetTime();
8517 memory->spin_time = 0.0f;
8518 memory->mode_time = 0.0f;
8519 }
8520
8521 void Sparky::DoFrame(int me) {
8522
8523 if (memory->mode == SPARKY_NORMAL) {
8524 char spin_dir;
8525 matrix orient;
8526 Obj_Value(me, VF_GET, OBJV_M_ORIENT, &orient);
8527
8528 float dot = orient.rvec * memory->orient.rvec;
8529 if (dot < -1.0f)
8530 dot = -1.0f;
8531 else if (dot > 1.0f)
8532 dot = 1.0f;
8533
8534 float ang = acos(dot);
8535
8536 float aps = (ang * 65535.0f) / (Game_GetFrameTime() * (2.0f * PI));
8537
8538 if (aps >= MIN_MALF_SPEED) {
8539 float tdot = memory->orient.rvec * orient.fvec;
8540 if (tdot < 0.0f)
8541 spin_dir = SPARKY_ROT_LEFT;
8542 else if (tdot > 0.0f)
8543 spin_dir = SPARKY_ROT_RIGHT;
8544 else
8545 spin_dir = SPARKY_NO_ROT;
8546 } else {
8547 spin_dir = SPARKY_NO_ROT;
8548 }
8549
8550 if (spin_dir == memory->spin_dir) {
8551 if (spin_dir == SPARKY_NO_ROT)
8552 memory->spin_time = 0.0f;
8553 else
8554 memory->spin_time += Game_GetFrameTime();
8555 } else {
8556 memory->spin_dir = spin_dir;
8557 memory->spin_time = 0.0f;
8558 }
8559
8560 memory->spin_dir = spin_dir;
8561 memory->orient = orient;
8562
8563 // mprintf(0, "spin time %f\n", memory->spin_time);
8564
8565 if (memory->spin_time > MALF_TIME) {
8566 SetMode(me, SPARKY_DYING);
8567 }
8568 } else {
8569 if (memory->last_spark_time + .1f < Game_GetTime()) {
8570 memory->last_spark_time = Game_GetTime();
8571
8572 int room;
8573 vector pos;
8574
8575 Obj_Value(me, VF_GET, OBJV_I_ROOMNUM, &room);
8576 Obj_Value(me, VF_GET, OBJV_V_POS, &pos);
8577
8578 Game_CreateRandomSparks(5, &pos, room);
8579 }
8580
8581 if (memory->mode_time < 2.5 && memory->mode_time + Game_GetFrameTime() >= 2.5) {
8582 msafe_struct mstruct;
8583
8584 mstruct.random = 21;
8585 mstruct.is_real = 0;
8586 mstruct.objhandle = me;
8587 mstruct.gunpoint = 1;
8588 mstruct.effect_type = MED_SMOKE_INDEX;
8589 mstruct.phys_info = 0;
8590 mstruct.drag = .001f;
8591 mstruct.mass = .001f;
8592 mstruct.interval = .05f;
8593 mstruct.longevity = 100000.0f;
8594 mstruct.lifetime = 1.0;
8595 mstruct.size = 8.0f;
8596 mstruct.speed = 120.0;
8597
8598 MSafe_CallFunction(MSAFE_OBJECT_START_SPEW, &mstruct);
8599 }
8600
8601 if (memory->mode_time > DEATH_TIME) {
8602 Obj_Kill(me, OBJECT_HANDLE_NONE, 1000.0f,
8603 DF_BLAST_RING | DF_LOSES_ANTIGRAV | DF_EXPL_MEDIUM | DF_FIREBALL | DF_BREAKS_APART | DF_DEBRIS_SMOKES,
8604 0.0f, 0.0f);
8605 }
8606 }
8607
8608 memory->mode_time += Game_GetFrameTime();
8609 }
8610
8611 int16_t Sparky::CallEvent(int event, tOSIRISEventInfo *data) {
8612 switch (event) {
8613 case EVT_AI_INIT:
8614 DoInit(data->me_handle);
8615 break;
8616 case EVT_AI_FRAME:
8617 DoFrame(data->me_handle);
8618 break;
8619 case EVT_AI_NOTIFY:
8620 return (DoNotify(data->me_handle, data) != false) ? CONTINUE_CHAIN | CONTINUE_DEFAULT : 0;
8621 break;
8622 case EVT_MEMRESTORE: {
8623 memory = (sparky_data *)data->evt_memrestore.memory_ptr;
8624 } break;
8625 }
8626 return CONTINUE_CHAIN | CONTINUE_DEFAULT;
8627 }
8628
8629 //------------------
8630 // Hellion class
8631 //------------------
8632
8633 bool Hellion::DoNotify(int me, tOSIRISEventInfo *data) {
8634 switch (memory->mode) {
8635 case HELLION_WAIT: {
8636 if (data->evt_ai_notify.notify_type == AIN_MOVIE_START) {
8637 SetMode(me, HELLION_INTRO);
8638 }
8639 } break;
8640 case HELLION_INTRO: {
8641 if (data->evt_ai_notify.notify_type == AIN_MOVIE_END) {
8642 SetMode(me, HELLION_MATTER);
8643 }
8644 } break;
8645 }
8646
8647 return true;
8648 }
8649
8650 void Hellion::RemapAlert(int me, float start, float end, float time) {
8651 memory->alert_start = start;
8652 memory->alert_end = end;
8653 memory->alert_time = time;
8654
8655 Obj_Value(me, VF_SET, OBJSV_F_ANIM_START, &start, AS_ALERT);
8656 Obj_Value(me, VF_SET, OBJSV_F_ANIM_END, &end, AS_ALERT);
8657 Obj_Value(me, VF_SET, OBJSV_F_ANIM_TIME, &time, AS_ALERT);
8658 }
8659
8660 void Hellion::RemapWB(int me, float start, float fire, int fire_sound, float end, float time, float latency, int index,
8661 uint16_t w_id, char f_mask) {
8662 memory->start = start;
8663 memory->fire = fire;
8664 memory->end = end;
8665 memory->time = time;
8666 memory->latency = latency;
8667 memory->index = index;
8668 memory->f_mask = f_mask;
8669
8670 Obj_WBValue(me, 0, VF_SET, WBSV_F_ANIM_START, &start, index);
8671 Obj_WBValue(me, 0, VF_SET, WBSV_F_ANIM_FIRE, &fire, index);
8672 Obj_WBValue(me, 0, VF_SET, WBSV_I_FIRE_SOUND, &fire_sound, index);
8673 Obj_WBValue(me, 0, VF_SET, WBSV_F_ANIM_END, &end, index);
8674 Obj_WBValue(me, 0, VF_SET, WBSV_F_ANIM_TIME, &time, index);
8675 Obj_WBValue(me, 0, VF_SET, WBSV_F_LATENCY, &latency, index);
8676 Obj_WBValue(me, 0, VF_SET, WBSV_C_MASK, &f_mask, 0);
8677
8678 char num_gps;
8679 Obj_WBValue(me, 0, VF_GET, WBV_C_NUM_GUNPTS, &num_gps);
8680
8681 int i;
8682 for (i = 0; i < num_gps; i++) {
8683 Obj_WBValue(me, 0, VF_SET, WBSV_US_GUNPT_WEAPON_ID, &w_id, i);
8684 }
8685 }
8686
8687 void Hellion::SetMode(int me, char mode) {
8688 AI_SetType(me, AIT_EVADER1);
8689
8690 switch (memory->mode) {
8691 case HELLION_MATTER:
8692 case HELLION_ENERGY:
8693 case HELLION_FIRE:
8694 case HELLION_SLEEP:
8695 memory->next_mode = mode;
8696 mode = HELLION_BETWEEN_MODE;
8697 break;
8698 }
8699
8700 switch (mode) {
8701 case HELLION_BETWEEN_MODE: {
8702 RemapAlert(me, 1.0f, 10.0f, 1.0f);
8703
8704 int flags = AIF_DISABLE_FIRING;
8705 AI_Value(me, VF_SET_FLAGS, AIV_I_FLAGS, &flags);
8706
8707 switch (memory->mode) {
8708 case HELLION_MATTER:
8709 Obj_SetCustomAnim(me, 120.0f, 140.0f, 2.5f, AIAF_NOTIFY, Sound_FindId("RbtHellionMatterToAlert"), AS_ALERT);
8710 break;
8711 case HELLION_ENERGY:
8712 Obj_SetCustomAnim(me, 200.0f, 240.0f, 5.0f, AIAF_NOTIFY, Sound_FindId("RbtHellionEnergyToAlert"), AS_ALERT);
8713 break;
8714 case HELLION_FIRE:
8715 Obj_SetCustomAnim(me, 62.0f, 80.0f, 2.3f, AIAF_NOTIFY, Sound_FindId("RbtHellionNapalmToAlert"), AS_ALERT);
8716 break;
8717 case HELLION_SLEEP:
8718 Obj_SetCustomAnim(me, 338.0f, 353.0f, 1.7f, AIAF_NOTIFY, -1, AS_ALERT);
8719 break;
8720 }
8721 } break;
8722
8723 case HELLION_MATTER:
8724 RemapAlert(me, 375.0f, 384.0f, 1.0f);
8725 RemapWB(me, 100.0f, 120.0f, Sound_FindId("fragA2"), 120.0f, 2.5f, 0.5f, 0, Wpn_FindID("HellionFrag"),
8726 (1 << 1) | (1 << 2) | (1 << 3) | (1 << 4));
8727 strcpy(memory->sound, "fragA2");
8728 strcpy(memory->weapon, "HellionFrag");
8729 Obj_SetCustomAnim(me, 80.0f, 100.0f, 2.7f, AIAF_NOTIFY, Sound_FindId("RbtHellionAlertToMatter"), AS_ALERT);
8730 break;
8731 case HELLION_FIRE:
8732 RemapAlert(me, 360.0f, 369.0f, 1.0f);
8733 RemapWB(me, 48.0f, 62.0f, -1, 62.0f, 2.0f, 0.1f, 0, -1, 0);
8734 Obj_SetCustomAnim(me, 10.0f, 48.0f, 5.0f, AIAF_NOTIFY, Sound_FindId("RbtHellionAlertToNapalm"), AS_ALERT);
8735 break;
8736 case HELLION_ENERGY:
8737 RemapAlert(me, 390.0f, 400.0f, 1.0f);
8738 RemapWB(me, 179.0f, 200.0f, Sound_FindId("Mega missile fire"), 200.0f, 2.7f, 0.9f, 0, Wpn_FindID("HellionMega"),
8739 (1 << 1) | (1 << 2) | (1 << 3) | (1 << 4));
8740 strcpy(memory->sound, "Mega missile fire");
8741 strcpy(memory->weapon, "HellionMega");
8742 Obj_SetCustomAnim(me, 140.0f, 179.0f, 5.0f, AIAF_NOTIFY, Sound_FindId("RbtHellionAlertToEnergy"), AS_ALERT);
8743 break;
8744 case HELLION_SLEEP:
8745 RemapAlert(me, 271.0f, 289.0f, 2.5);
8746 Obj_SetCustomAnim(me, 240.0f, 271.0f, 4.0f, AIAF_NOTIFY, -1, AS_ALERT);
8747 break;
8748 case HELLION_BIRTHING:
8749 Obj_SetCustomAnim(me, 289.0f, 338.0f, 6.5f, AIAF_NOTIFY, -1, AS_ALERT);
8750 break;
8751 case HELLION_DEATH: {
8752 int flags = AIF_DISABLE_FIRING | AIF_DISABLE_MELEE;
8753 AI_Value(me, VF_SET_FLAGS, AIV_I_FLAGS, &flags);
8754 flags = AIF_FIRE;
8755 AI_Value(me, VF_CLEAR_FLAGS, AIV_I_FLAGS, &flags);
8756
8757 vector vel = {0.0f, 0.0f, 0.0f};
8758 Obj_Value(me, VF_SET, OBJV_V_VELOCITY, &vel);
8759
8760 float circle_dist = -1.0f;
8761 AI_Value(me, VF_SET, AIV_F_CIRCLE_DIST, &circle_dist);
8762
8763 Obj_SetCustomAnim(me, 495.0f, 650.0f, 15.0f, 0, Sound_FindId("RbtHellionDeath"), -1);
8764 } break;
8765 default:
8766 break;
8767 }
8768
8769 memory->mode_time = 0.0f;
8770 memory->mode = mode;
8771 }
8772
8773 void Hellion::DoInit(int me) {
8774 tOSIRISMEMCHUNK ch;
8775 ch.id = 4;
8776 ch.size = sizeof(hellion_data);
8777 ch.my_id.type = OBJECT_SCRIPT;
8778 ch.my_id.objhandle = me;
8779 int i;
8780
8781 memory = (hellion_data *)Scrpt_MemAlloc(&ch);
8782 memory->flags = 0;
8783 memory->mode = HELLION_WAIT;
8784
8785 memory->head_object = CreateAndAttach(me, "Hellionhead", OBJ_ROBOT, 0, 0, true, true);
8786 memory->turret_object = CreateAndAttach(me, "Hellionturret", OBJ_ROBOT, 1, 0, true, true);
8787 RemapAlert(me, 1.0f, 10.0f, 1.0f);
8788
8789 int proom;
8790 vector ppos;
8791 matrix porient;
8792
8793 Obj_Value(me, VF_GET, OBJV_I_ROOMNUM, &proom);
8794 Obj_Value(me, VF_GET, OBJV_V_POS, &ppos);
8795 Obj_Value(me, VF_GET, OBJV_M_ORIENT, &porient);
8796
8797 for (i = 0; i < 2; i++) {
8798 memory->camera[i] = Obj_Create(OBJ_POWERUP, Obj_FindID("Invisiblepowerup"), proom, &ppos, &porient, me);
8799 msafe_struct mstruct;
8800 mstruct.objhandle = memory->camera[i];
8801 MSafe_CallFunction(MSAFE_OBJECT_NO_RENDER, &mstruct);
8802
8803 memory->emitter[i] = CreateAndAttach(me, "STEmitter", OBJ_ROBOT, 2 + i, 0, true, true);
8804 }
8805
8806 memory->laser_sound = -1;
8807 memory->last_frame = 0.0f;
8808 memory->laser_time_left = 0.0f;
8809
8810 // Save and restore information
8811 Obj_Value(me, VF_GET, OBJSV_F_ANIM_START, &memory->alert_start, AS_ALERT);
8812 Obj_Value(me, VF_GET, OBJSV_F_ANIM_END, &memory->alert_end, AS_ALERT);
8813 Obj_Value(me, VF_GET, OBJSV_F_ANIM_TIME, &memory->alert_time, AS_ALERT);
8814
8815 Obj_WBValue(me, 0, VF_GET, WBSV_F_ANIM_START, &memory->start, 0);
8816 Obj_WBValue(me, 0, VF_GET, WBSV_F_ANIM_FIRE, &memory->fire, 0);
8817 Obj_WBValue(me, 0, VF_GET, WBSV_F_ANIM_END, &memory->end, 0);
8818 Obj_WBValue(me, 0, VF_GET, WBSV_F_ANIM_TIME, &memory->time, 0);
8819 Obj_WBValue(me, 0, VF_GET, WBSV_F_LATENCY, &memory->latency, 0);
8820 Obj_WBValue(me, 0, VF_GET, WBSV_C_MASK, &memory->f_mask, 0);
8821 memory->index = 0;
8822
8823 strcpy(memory->sound, "fragA2");
8824 strcpy(memory->weapon, "HellionFrag");
8825 // end of save and restore info
8826
8827 int flags = AIF_DETERMINE_TARGET;
8828 AI_Value(me, VF_CLEAR_FLAGS, AIV_I_FLAGS, &flags);
8829
8830 SetMode(me, HELLION_WAIT);
8831 }
8832
8833 void Hellion::DoFrame(int me) {
8834 int flags;
8835 float frame;
8836 float shields;
8837
8838 char anim_type;
8839 AI_Value(me, VF_GET, AIV_C_ANIMATION_TYPE, &anim_type);
8840
8841 bool f_ok_to_animate = (anim_type != AS_RANGED_ATTACK && anim_type != AS_MELEE1 && anim_type != AS_MELEE2);
8842
8843 Obj_Value(memory->head_object, VF_GET, OBJV_I_FLAGS, &flags);
8844 Obj_Value(me, VF_GET, OBJV_F_ANIM_FRAME, &frame);
8845 Obj_Value(memory->head_object, VF_GET, OBJV_F_SHIELDS, &shields);
8846
8847 // Matter fire animation sound
8848 if ((memory->last_frame < 100.0f || memory->last_frame > 120.0f) && frame >= 100.0f && frame <= 120.0f) {
8849 Sound_Play3d(me, Sound_FindId("RbtHellionMatterAttack"));
8850 }
8851
8852 if (memory->laser_sound != -1 && (frame < 48.0f || frame > 60.0f)) {
8853 memory->laser_sound = -1;
8854 }
8855
8856 // Laser firing sound
8857 if (frame >= 48.0f && frame <= 60.0f && memory->laser_sound == -1) {
8858 memory->laser_sound = Sound_Play3d(me, Sound_FindId("RbtHellionLaser"));
8859 }
8860
8861 int cur_mtype;
8862 Obj_Value(me, VF_GET, OBJV_C_MOVEMENT_TYPE, &cur_mtype);
8863
8864 if (cur_mtype == MT_PHYSICS && frame >= 140.0 && frame <= 179.0f) {
8865 char mtype = MT_NONE;
8866 Obj_Value(me, VF_SET, OBJV_C_MOVEMENT_TYPE, &mtype);
8867 } else if (cur_mtype == MT_NONE) {
8868 char mtype = MT_PHYSICS;
8869 Obj_Value(me, VF_SET, OBJV_C_MOVEMENT_TYPE, &mtype);
8870 }
8871
8872 if (memory->last_frame >= 140.0f && memory->last_frame <= 179.0f && memory->last_frame < 146.0f && frame >= 146.0f) {
8873 matrix orient;
8874 Obj_Value(me, VF_GET, OBJV_M_ORIENT, &orient);
8875
8876 int room;
8877 vector pos;
8878 int weapon_id;
8879
8880 Obj_Value(me, VF_GET, OBJV_I_ROOMNUM, &room);
8881 Obj_Value(me, VF_GET, OBJV_V_POS, &pos);
8882
8883 pos += orient.uvec * 10.0f;
8884
8885 matrix new_orient;
8886
8887 new_orient.fvec = -orient.uvec;
8888 new_orient.rvec = orient.rvec;
8889 new_orient.uvec = orient.fvec;
8890
8891 weapon_id = Wpn_FindID("HellionBShark");
8892 Obj_Create(OBJ_WEAPON, weapon_id, room, &pos, &new_orient, OBJECT_HANDLE_NONE);
8893 }
8894
8895 if (memory->last_frame >= 140.0f && memory->last_frame <= 179.0f && memory->last_frame < 160.0f && frame >= 160.0f) {
8896 // shake players
8897 msafe_struct mstruct;
8898 mstruct.amount = 65.0f;
8899 MSafe_CallFunction(MSAFE_OBJECT_VIEWER_SHAKE, &mstruct);
8900 }
8901
8902 if (memory->laser_time_left > 0.0f) {
8903 int i;
8904 ray_info ray;
8905
8906 memory->laser_time_left -= Game_GetFrameTime();
8907 if (memory->laser_time_left < 0.0f) {
8908 memory->laser_time_left = 0.0f;
8909 }
8910
8911 vector normal;
8912 vector pos;
8913 int room;
8914 vector end_pos;
8915
8916 for (i = 0; i < 2; i++) {
8917 int my_room;
8918 vector my_pos;
8919
8920 Obj_Value(me, VF_GET, OBJV_V_POS, &my_pos);
8921 Obj_Value(me, VF_GET, OBJV_I_ROOMNUM, &my_room);
8922 Obj_GetGunPos(me, i + 1, &pos, &normal);
8923
8924 int rfate = FVI_RayCast(me, &my_pos, &pos, my_room, 0.0f, 0, &ray);
8925 room = ray.hit_room;
8926
8927 matrix orient;
8928 Obj_Value(me, VF_GET, OBJV_M_ORIENT, &orient);
8929
8930 // Determine real start pos - room
8931 vector end_pos = pos;
8932 end_pos += normal * 2000.0f;
8933
8934 int fvi_flags = FQ_CHECK_OBJS | FQ_IGNORE_POWERUPS | FQ_IGNORE_WEAPONS;
8935 int fate = FVI_RayCast(me, &pos, &end_pos, room, 0.0f, fvi_flags, &ray);
8936
8937 Obj_Value(memory->camera[i], VF_SET, OBJV_V_POS, &ray.hit_point);
8938 Obj_Value(memory->camera[i], VF_SET, OBJV_I_ROOMNUM, &ray.hit_room);
8939
8940 msafe_struct mstruct;
8941
8942 mstruct.random = 21;
8943 mstruct.is_real = 0;
8944 mstruct.objhandle = memory->camera[i];
8945 mstruct.gunpoint = -1;
8946 mstruct.effect_type = SNOWFLAKE_INDEX;
8947 mstruct.phys_info = 0;
8948 mstruct.drag = .001f;
8949 mstruct.mass = .001f;
8950 mstruct.interval = .05f;
8951 mstruct.longevity = .1f;
8952 mstruct.lifetime = .1f;
8953 mstruct.size = 5.0f;
8954 mstruct.speed = 80.0;
8955
8956 MSafe_CallFunction(MSAFE_OBJECT_START_SPEW, &mstruct);
8957
8958 if (fate == HIT_OBJECT || fate == HIT_SPHERE_2_POLY_OBJECT) {
8959 int type;
8960
8961 Obj_Value(ray.hit_object, VF_GET, OBJV_I_TYPE, &type);
8962
8963 if (type == OBJ_PLAYER) {
8964 msafe_struct mstruct;
8965
8966 mstruct.objhandle = ray.hit_object;
8967 mstruct.killer_handle = me;
8968 mstruct.damage_type = PD_ENERGY_WEAPON;
8969 mstruct.amount = 30.0f * Game_GetFrameTime();
8970
8971 MSafe_CallFunction(MSAFE_OBJECT_DAMAGE_OBJECT, &mstruct);
8972 }
8973 }
8974 }
8975 }
8976
8977 // Start up the beem!
8978 if (frame >= 49.0f && frame <= 55.0f && memory->laser_time_left == 0.0f) {
8979 memory->laser_time_left = 1.8f;
8980 int i;
8981 msafe_struct mstruct;
8982
8983 for (i = 0; i < 2; i++) {
8984 Obj_Value(memory->emitter[i], VF_GET, OBJV_I_ROOMNUM, &mstruct.roomnum);
8985 Obj_Value(memory->emitter[i], VF_GET, OBJV_V_POS, &mstruct.pos);
8986 Obj_Value(memory->camera[i], VF_GET, OBJV_V_POS, &mstruct.pos2);
8987
8988 mstruct.objhandle = memory->emitter[i];
8989 mstruct.ithandle = memory->camera[i];
8990 mstruct.lifetime = memory->laser_time_left;
8991 mstruct.size = 3.0f;
8992
8993 mstruct.interval = 1.0f;
8994 mstruct.count = 2;
8995 mstruct.index = 1;
8996 mstruct.texnum = Scrpt_FindTextureName("HellionBeam");
8997 mstruct.color = ((128 >> 3) << 10) | ((128 >> 3) << 5) | (128 >> 3);
8998
8999 mstruct.state = 1;
9000 mstruct.flags = 0;
9001
9002 MSafe_CallFunction(MSAFE_WEATHER_LIGHTNING_BOLT, &mstruct);
9003
9004 mstruct.random = 21;
9005 mstruct.is_real = 0;
9006 mstruct.objhandle = me;
9007 mstruct.gunpoint = 1 + i;
9008 mstruct.effect_type = MED_SMOKE_INDEX;
9009 mstruct.phys_info = 0;
9010 mstruct.drag = .001f;
9011 mstruct.mass = .001f;
9012 mstruct.interval = .05f;
9013 mstruct.longevity = memory->laser_time_left;
9014 mstruct.lifetime = 1.0;
9015 mstruct.size = 5.0f;
9016 mstruct.speed = 80.0;
9017
9018 MSafe_CallFunction(MSAFE_OBJECT_START_SPEW, &mstruct);
9019 }
9020 }
9021
9022 if ((memory->mode != HELLION_DEATH) && (flags & OF_AI_DEATH)) {
9023 if (f_ok_to_animate) {
9024 SetMode(me, HELLION_DEATH);
9025 }
9026 }
9027
9028 if (memory->mode == HELLION_WAIT) {
9029 } else if (memory->mode == HELLION_INTRO) {
9030 if (memory->mode_time < 0.5f && memory->mode_time + Game_GetFrameTime() >= 0.5f) {
9031 int flags = AIF_FORCE_AWARENESS;
9032 AI_Value(me, VF_SET_FLAGS, AIV_I_FLAGS, &flags);
9033
9034 float awareness = AWARE_FULLY;
9035 AI_Value(me, VF_SET, AIV_F_AWARENESS, &awareness);
9036
9037 aDestroyAllRobotsInit();
9038 aDestroyAllRobotsSpareHandle(me);
9039 aDestroyAllRobotsSpareHandle(memory->turret_object);
9040 aDestroyAllRobotsSpareHandle(memory->head_object);
9041 aDestroyAllRobotsSpareHandle(memory->emitter[0]);
9042 aDestroyAllRobotsSpareHandle(memory->emitter[1]);
9043 aDestroyAllRobotsEnd();
9044 }
9045 } else if (memory->mode == HELLION_BETWEEN_MODE) {
9046 if (frame >= 0.0f && frame <= 10.0f) {
9047 SetMode(me, memory->next_mode);
9048 }
9049 } else if (memory->mode == HELLION_DEATH) {
9050 if (memory->mode_time < 10.0f && memory->mode_time + Game_GetFrameTime() >= 10.0f) {
9051 Obj_Burning(me, 1000000.0f, 1.0f);
9052 }
9053
9054 if (frame == 650.0f) {
9055 Obj_Kill(me, OBJECT_HANDLE_NONE, 1000.0f,
9056 DF_BREAKS_APART | DF_BLAST_RING | DF_LOSES_ANTIGRAV | DF_EXPL_LARGE | DF_CONTACT_BREAKS_APART |
9057 DF_CONTACT_BLAST_RING | DF_DEBRIS_SMOKES | DF_DEBRIS_FIREBALL | DF_DEBRIS_BLAST_RING,
9058 0.0f, 0.0f);
9059 }
9060 } else if (memory->mode == HELLION_MATTER) {
9061 if (frame >= 375.0f && frame <= 384.0f) {
9062 int flags = AIF_DETERMINE_TARGET;
9063 AI_Value(me, VF_SET_FLAGS, AIV_I_FLAGS, &flags);
9064
9065 flags = AIF_DISABLE_FIRING;
9066 AI_Value(me, VF_CLEAR_FLAGS, AIV_I_FLAGS, &flags);
9067 }
9068
9069 if (shields < 4000.0f) {
9070 if (f_ok_to_animate) {
9071 SetMode(me, HELLION_FIRE);
9072 }
9073 }
9074 } else if (memory->mode == HELLION_FIRE) {
9075 if (frame >= 360.0f && frame <= 369.0f) {
9076 int flags = AIF_DISABLE_FIRING;
9077 AI_Value(me, VF_CLEAR_FLAGS, AIV_I_FLAGS, &flags);
9078 }
9079
9080 if (shields < 2100.0f) {
9081 if (f_ok_to_animate) {
9082 SetMode(me, HELLION_ENERGY);
9083 }
9084 }
9085 } else if (memory->mode == HELLION_ENERGY) {
9086 if (frame >= 390.0f && frame <= 400.0f) {
9087 int test_flags;
9088 AI_Value(me, VF_GET, AIV_I_FLAGS, &test_flags);
9089
9090 if (test_flags & AIF_DISABLE_FIRING) {
9091 int flags = AIF_DISABLE_FIRING;
9092 AI_Value(me, VF_CLEAR_FLAGS, AIV_I_FLAGS, &flags);
9093
9094 /* int room;
9095 vector pos;
9096 int weapon_id;
9097
9098 Obj_Value(me, VF_GET, OBJV_I_ROOMNUM, &room);
9099 Obj_Value(me, VF_GET, OBJV_V_POS, &pos);
9100
9101 weapon_id = Wpn_FindID("HellionBShark");
9102 Obj_Create(OBJ_WEAPON, weapon_id, room, &pos, NULL, NULL);*/
9103 }
9104 }
9105 }
9106 // else if(memory->mode == HELLION_SLEEP)
9107 // {
9108 // int offset = (memory->mode - HELLION_MATTER + 1)%4;
9109 // SetMode(me, HELLION_MATTER + offset);
9110 // }
9111 else if (memory->mode_time > 20.0f) {
9112 if (memory->mode == HELLION_MATTER || memory->mode == HELLION_ENERGY || memory->mode == HELLION_FIRE ||
9113 memory->mode == HELLION_SLEEP) {
9114 int offset = (memory->mode - HELLION_MATTER + 1) % 4;
9115 SetMode(me, HELLION_MATTER + offset);
9116 }
9117 }
9118
9119 memory->mode_time += Game_GetFrameTime();
9120 memory->last_frame = frame;
9121 }
9122
9123 int16_t Hellion::CallEvent(int event, tOSIRISEventInfo *data) {
9124 switch (event) {
9125 case EVT_AI_INIT:
9126 DoInit(data->me_handle);
9127 break;
9128 case EVT_AI_FRAME:
9129 DoFrame(data->me_handle);
9130 break;
9131 case EVT_AI_NOTIFY:
9132 return (DoNotify(data->me_handle, data) != false) ? CONTINUE_CHAIN | CONTINUE_DEFAULT : 0;
9133 break;
9134 case EVT_DESTROY: {
9135 // shake players
9136 msafe_struct mstruct;
9137 mstruct.amount = 90.0f;
9138 MSafe_CallFunction(MSAFE_OBJECT_VIEWER_SHAKE, &mstruct);
9139
9140 Obj_Kill(memory->head_object, OBJECT_HANDLE_NONE, 1000.0f,
9141 DF_BLAST_RING | DF_LOSES_ANTIGRAV | DF_EXPL_LARGE | DF_FIREBALL | DF_BREAKS_APART | DF_DEBRIS_SMOKES, 0.0f,
9142 0.0f);
9143 Obj_Kill(memory->turret_object, OBJECT_HANDLE_NONE, 1000.0f,
9144 DF_BLAST_RING | DF_LOSES_ANTIGRAV | DF_EXPL_LARGE | DF_FIREBALL | DF_BREAKS_APART | DF_DEBRIS_SMOKES, 0.0f,
9145 0.0f);
9146
9147 int i;
9148 msafe_struct mo;
9149
9150 for (i = 0; i < 2; i++) {
9151 mo.objhandle = memory->camera[i];
9152 MSafe_CallFunction(MSAFE_OBJECT_REMOVE, &mo);
9153
9154 mo.objhandle = memory->emitter[i];
9155 MSafe_CallFunction(MSAFE_OBJECT_REMOVE, &mo);
9156 }
9157 } break;
9158 case EVT_MEMRESTORE: {
9159 memory = (hellion_data *)data->evt_memrestore.memory_ptr;
9160
9161 uint16_t wpn = Wpn_FindID(memory->weapon);
9162 int snd = Sound_FindId(memory->sound);
9163
9164 RemapAlert(data->me_handle, memory->alert_start, memory->alert_end, memory->alert_time);
9165 RemapWB(data->me_handle, memory->start, memory->fire, snd, memory->end, memory->time, memory->latency,
9166 memory->index, wpn, memory->f_mask);
9167 } break;
9168 }
9169 return CONTINUE_CHAIN | CONTINUE_DEFAULT;
9170 }
9171
9172 //------------------
9173 // MantaRay class
9174 //------------------
9175
9176 bool MantaRay::SendCommand(int me, int it, char command, void *ptr) {
9177 gb_com com;
9178
9179 com.action = command;
9180 com.ptr = ptr;
9181
9182 tOSIRISEventInfo ei;
9183
9184 ei.me_handle = it;
9185 ei.extra_info = (void *)&com;
9186 ei.evt_ai_notify.notify_type = AIN_USER_DEFINED;
9187 ei.evt_ai_notify.it_handle = me;
9188
9189 return Obj_CallEvent(it, EVT_AI_NOTIFY, &ei);
9190 }
9191
9192 bool MantaRay::ReceiveCommand(int me, int it, char command, void *ptr) {
9193 switch (command) {
9194 case MRC_JOIN_ME: {
9195 if (memory->flags == 0) {
9196 memory->leader_handle = it;
9197 memory->flags |= MRF_SQUADIE;
9198
9199 SetMode(me, memory->mode);
9200
9201 return true;
9202 }
9203 } break;
9204 case MRC_LEAVE_YOU:
9205 break;
9206 case MRC_GET_GOAL_POS: {
9207 int i;
9208 for (i = 0; i < memory->num_teammates; i++) {
9209 if (memory->teammate[i] == it) {
9210 vector goal_pos;
9211 matrix orient;
9212 Obj_Value(me, VF_GET, OBJV_V_POS, &goal_pos);
9213 Obj_Value(me, VF_GET, OBJV_M_ORIENT, &orient);
9214
9215 switch (i) {
9216 case 0:
9217 goal_pos -= orient.fvec * MRO_FVEC;
9218 goal_pos -= orient.rvec * MRO_RVEC;
9219 break;
9220 case 1:
9221 goal_pos -= orient.fvec * MRO_FVEC;
9222 goal_pos += orient.rvec * MRO_RVEC;
9223 break;
9224 case 2:
9225 goal_pos -= orient.fvec * MRO_FVEC * 2.0f;
9226 goal_pos -= orient.rvec * MRO_RVEC * 2.0f;
9227 break;
9228 case 3:
9229 goal_pos -= orient.fvec * MRO_FVEC * 2.0f;
9230 goal_pos += orient.rvec * MRO_RVEC * 2.0f;
9231 break;
9232 }
9233
9234 *(vector *)ptr = goal_pos;
9235 return true;
9236 }
9237 }
9238 } break;
9239 case MRC_GET_GOAL_ROOM: {
9240 Obj_Value(me, VF_GET, OBJV_I_ROOMNUM, (int *)ptr);
9241 return true;
9242 } break;
9243 case MRC_GET_GOAL_ORIENT: {
9244 return true;
9245 } break;
9246 }
9247
9248 // mprintf(0, "MantaRay action %d failed\n");
9249 return false;
9250 }
9251
9252 void MantaRay::UpdateSquadList(int me) {
9253 int i;
9254
9255 for (i = 0; i < memory->num_teammates; i++) {
9256 int type;
9257 int j;
9258
9259 Obj_Value(memory->teammate[i], VF_GET, OBJV_I_TYPE, &type);
9260 if (type == OBJ_NONE) {
9261 for (j = i; j < memory->num_teammates - 1; j++) {
9262 memory->teammate[j] = memory->teammate[j + 1];
9263 }
9264
9265 memory->num_teammates--;
9266 i--;
9267 }
9268 }
9269 }
9270
9271 void MantaRay::UpdateSquad(int me) {
9272 if (memory->flags & MRF_SQUADIE)
9273 return;
9274
9275 if (memory->flags & MRF_LEADER) {
9276 UpdateSquadList(me);
9277
9278 if (memory->num_teammates == 0)
9279 memory->flags &= ~MRF_LEADER;
9280
9281 if (memory->num_teammates >= MR_MAX_TEAMMATES)
9282 return;
9283 }
9284
9285 int scan_objs[25];
9286 int n_scan;
9287 int room;
9288 vector pos;
9289 int i;
9290
9291 Obj_Value(me, VF_GET, OBJV_V_POS, &pos);
9292 Obj_Value(me, VF_GET, OBJV_I_ROOMNUM, &room);
9293
9294 n_scan = AI_GetNearbyObjs(&pos, room, 200.0f, scan_objs, 25, false, true, false, true);
9295
9296 for (i = 0; i < n_scan; i++) {
9297 uint16_t id;
9298 Obj_Value(scan_objs[i], VF_GET, OBJV_US_ID, &id);
9299
9300 // this is more rare than the types matching; so, do it first
9301 if (id == memory->mantaray_id) {
9302 int type;
9303 Obj_Value(scan_objs[i], VF_GET, OBJV_I_TYPE, &type);
9304 if (type == OBJ_ROBOT && scan_objs[i] != me) {
9305 bool f_on_team = false;
9306 if (memory->flags & MRF_LEADER) {
9307 int j;
9308 for (j = 0; j < memory->num_teammates; j++) {
9309 if (scan_objs[i] == memory->teammate[j]) {
9310 f_on_team = true;
9311 break;
9312 }
9313 }
9314 }
9315
9316 if (!f_on_team) {
9317 if (SendCommand(me, scan_objs[i], MRC_JOIN_ME, NULL)) {
9318 memory->flags |= MRF_LEADER;
9319 memory->teammate[memory->num_teammates++] = scan_objs[i];
9320 }
9321 }
9322 }
9323 }
9324
9325 if (memory->num_teammates >= MR_MAX_TEAMMATES)
9326 return;
9327 }
9328 }
9329
9330 void MantaRay::DoInit(int me) {
9331 tOSIRISMEMCHUNK ch;
9332 ch.id = 4;
9333 ch.size = sizeof(mantaray_data);
9334 ch.my_id.type = OBJECT_SCRIPT;
9335 ch.my_id.objhandle = me;
9336
9337 memory = (mantaray_data *)Scrpt_MemAlloc(&ch);
9338
9339 AI_Value(me, VF_GET, AIV_F_MAX_SPEED, &memory->base_speed);
9340 memory->attack_speed = 1.8f * memory->base_speed;
9341
9342 memory->flags = 0;
9343 memory->leader_handle = OBJECT_HANDLE_NONE;
9344 memory->num_teammates = 0;
9345
9346 // .1 to .6 seconds into the level, do the first matching
9347 memory->next_update_squad_time = Game_GetTime() + ((float)rand() / (float)RAND_MAX) * .5f + 0.1f;
9348
9349 memory->mantaray_id = Obj_FindID("Manta Ray");
9350
9351 SetMode(me, MRM_NORMAL);
9352 }
9353
9354 void MantaRay::SetMode(int me, char mode) {
9355 int f_attack_flags = (AIF_FIRE | AIF_AUTO_AVOID_FRIENDS);
9356 AI_SetType(me, AIT_AIS);
9357
9358 if (memory->flags & MRF_SQUADIE) {
9359 // The leader is alive; so, get my new goal pos
9360 SendCommand(me, memory->leader_handle, MRC_GET_GOAL_POS, &memory->goal_pos);
9361 AI_GoalValue(me, 2, VF_SET, AIGV_V_POS, &memory->goal_pos);
9362 SendCommand(me, memory->leader_handle, MRC_GET_GOAL_ROOM, &memory->goal_room);
9363 AI_GoalValue(me, 2, VF_SET, AIGV_I_ROOMNUM, &memory->goal_room);
9364
9365 AI_AddGoal(me, AIG_GET_TO_POS, 2, 1.0f, -1, GF_ORIENT_VELOCITY | GF_KEEP_AT_COMPLETION, &memory->goal_pos,
9366 memory->goal_room);
9367 float cd = .1f;
9368 AI_GoalValue(me, 2, VF_SET, AIGV_F_CIRCLE_DIST, &cd);
9369 } else {
9370 AI_Value(me, VF_SET, AIV_F_MAX_SPEED, &memory->base_speed);
9371 }
9372
9373 switch (mode) {
9374 case MRM_NORMAL: {
9375 vector pos;
9376 int room = 0;
9377 float dist = 15.0f;
9378
9379 AI_Value(me, VF_CLEAR_FLAGS, AIV_I_FLAGS, &f_attack_flags);
9380 AI_AddGoal(me, AIG_WANDER_AROUND, 1, 1.0f, -1, GF_ORIENT_VELOCITY | GF_NOTIFIES | GF_KEEP_AT_COMPLETION, &pos,
9381 room);
9382 AI_GoalValue(me, 1, VF_SET, AIGV_F_CIRCLE_DIST, &dist);
9383 } break;
9384
9385 case MRM_ATTACK: {
9386 AI_Value(me, VF_SET_FLAGS, AIV_I_FLAGS, &f_attack_flags);
9387
9388 // memory->next_attack_time = Game_GetTime() + 10.0 * ((float)rand()/(float)RAND_MAX);
9389
9390 float dist = 60.0f + ((float)rand() / (float)RAND_MAX) * 10.0f;
9391 AI_AddGoal(me, AIG_GET_TO_OBJ, 1, 1.0f, -1,
9392 GF_ORIENT_VELOCITY | GF_OBJ_IS_TARGET | GF_USE_BLINE_IF_SEES_GOAL | GF_KEEP_AT_COMPLETION |
9393 GF_NONFLUSHABLE,
9394 OBJECT_HANDLE_NONE);
9395 AI_GoalValue(me, 1, VF_SET, AIGV_F_CIRCLE_DIST, &dist);
9396
9397 dist = 10.0f;
9398 int g_index =
9399 AI_AddGoal(me, AIG_GET_AROUND_OBJ, ACTIVATION_BLEND_LEVEL, 1.0f, -1,
9400 GF_ORIENT_VELOCITY | GF_OBJ_IS_TARGET | GF_KEEP_AT_COMPLETION | GF_NONFLUSHABLE, OBJECT_HANDLE_NONE);
9401 AI_GoalValue(me, g_index, VF_SET, AIGV_F_CIRCLE_DIST, &dist);
9402 } break;
9403
9404 case MRM_ATTACK_CIRCLE_BACK: {
9405 vector pos;
9406 int room = 0;
9407
9408 AI_Value(me, VF_SET_FLAGS, AIV_I_FLAGS, &f_attack_flags);
9409
9410 if (!(memory->flags & MRF_SQUADIE)) {
9411 AI_Value(me, VF_SET, AIV_F_MAX_SPEED, &memory->attack_speed);
9412 }
9413
9414 Obj_Value(me, VF_GET, OBJV_V_POS, &pos);
9415 Obj_Value(me, VF_GET, OBJV_I_ROOMNUM, &room);
9416
9417 float dist = 10.0f;
9418
9419 AI_AddGoal(me, AIG_WANDER_AROUND, 1, 1.0f, -1,
9420 GF_NOTIFIES | GF_ORIENT_VELOCITY | GF_KEEP_AT_COMPLETION | GF_NONFLUSHABLE, &pos, room);
9421 AI_GoalValue(me, 1, VF_SET, AIGV_F_CIRCLE_DIST, &dist);
9422
9423 int g_index =
9424 AI_AddGoal(me, AIG_GET_AROUND_OBJ, ACTIVATION_BLEND_LEVEL, 1.0f, -1,
9425 GF_ORIENT_VELOCITY | GF_OBJ_IS_TARGET | GF_KEEP_AT_COMPLETION | GF_NONFLUSHABLE, OBJECT_HANDLE_NONE);
9426 AI_GoalValue(me, g_index, VF_SET, AIGV_F_CIRCLE_DIST, &dist);
9427 } break;
9428 }
9429
9430 memory->mode = mode;
9431 memory->mode_time = 0.0f;
9432 }
9433
9434 void MantaRay::DoSquadieFrame(int me) {
9435 int type;
9436 Obj_Value(memory->leader_handle, VF_GET, OBJV_I_TYPE, &type);
9437
9438 // Check if the leader is still alive
9439 if (type == OBJ_NONE) {
9440 // Reset the speed
9441 AI_Value(me, VF_SET, AIV_F_MAX_SPEED, &memory->base_speed);
9442
9443 memory->flags = 0;
9444 memory->leader_handle = OBJECT_HANDLE_NONE;
9445
9446 SetMode(me, MRM_NORMAL);
9447 return;
9448 }
9449
9450 // The leader is alive; so, get my new goal pos
9451 SendCommand(me, memory->leader_handle, MRC_GET_GOAL_POS, &memory->goal_pos);
9452 AI_GoalValue(me, 2, VF_SET, AIGV_V_POS, &memory->goal_pos);
9453 SendCommand(me, memory->leader_handle, MRC_GET_GOAL_ROOM, &memory->goal_room);
9454 AI_GoalValue(me, 2, VF_SET, AIGV_I_ROOMNUM, &memory->goal_room);
9455
9456 AI_AddGoal(me, AIG_GET_TO_POS, 2, 1.0f, -1, GF_ORIENT_VELOCITY | GF_KEEP_AT_COMPLETION, &memory->goal_pos,
9457 memory->goal_room);
9458 float cd = .1f;
9459 AI_GoalValue(me, 2, VF_SET, AIGV_F_CIRCLE_DIST, &cd);
9460
9461 vector my_pos;
9462 Obj_Value(me, VF_GET, OBJV_V_POS, &my_pos);
9463
9464 float dist = vm_VectorDistance(&my_pos, &memory->goal_pos);
9465
9466 if (dist <= MRO_CATCHUP_DIST) {
9467 float catchup_speed;
9468 AI_Value(memory->leader_handle, VF_GET, AIV_F_MAX_SPEED, &catchup_speed);
9469
9470 float scaled_speed = dist / MRO_CATCHUP_DIST * 0.23f * catchup_speed;
9471 catchup_speed += scaled_speed;
9472
9473 AI_Value(me, VF_SET, AIV_F_MAX_SPEED, &catchup_speed);
9474 } else if (dist > MRO_CATCHUP_DIST) {
9475 float catchup_speed;
9476 AI_Value(memory->leader_handle, VF_GET, AIV_F_MAX_SPEED, &catchup_speed);
9477
9478 float scaled_speed = 0.23f * catchup_speed;
9479 catchup_speed += scaled_speed;
9480
9481 AI_Value(me, VF_SET, AIV_F_MAX_SPEED, &catchup_speed);
9482 }
9483
9484 // Get the leaders mode
9485
9486 // Set my mode to the leaders mode... (Modes account for flags)
9487 }
9488
9489 void MantaRay::DoFrame(int me) {
9490 float last_see_target_time;
9491 float last_hear_target_time;
9492 AI_Value(me, VF_GET, AIV_F_LAST_SEE_TARGET_TIME, &last_see_target_time);
9493 AI_Value(me, VF_GET, AIV_F_LAST_HEAR_TARGET_TIME, &last_hear_target_time);
9494
9495 // Periodically update the squad information
9496 if (memory->next_update_squad_time <= Game_GetTime()) {
9497 // 3 to 6 seconds
9498 memory->next_update_squad_time = Game_GetTime() + ((float)rand() / (float)RAND_MAX) * 3.0f + 3.0f;
9499 UpdateSquad(me);
9500 }
9501
9502 // If your a squadie, check for a leader
9503 if (memory->flags & MRF_SQUADIE) {
9504 DoSquadieFrame(me);
9505 }
9506
9507 // if(memory->flags & MRF_LEADER)
9508 // {
9509 // vector pos;
9510 // Obj_Value(me, VF_GET, OBJV_V_POS, &pos);
9511 // vector gpos;
9512 // int groom;
9513
9514 // float cd;
9515 // AI_GoalValue(me, 1, VF_GET, AIGV_I_ROOMNUM, &groom);
9516 // AI_GoalValue(me, 1, VF_GET, AIGV_V_POS, &gpos);
9517 // AI_GoalValue(me, 1, VF_GET, AIGV_F_CIRCLE_DIST, &cd);
9518 // mprintf(0, "%f,%f,%f-%f,%f,%f-%f\n", XYZ(&gpos), XYZ(&pos), cd);
9519 // }
9520
9521 switch (memory->mode) {
9522 case MRM_ATTACK: {
9523 // mprintf(0, "MODE ATTACK\n");
9524 if (Game_GetTime() > last_see_target_time + 7.0f && Game_GetTime() > last_hear_target_time + 7.0f)
9525 SetMode(me, MRM_NORMAL);
9526 //
9527 // float dist;
9528 // AI_GoalValue(me, 1, VF_GET, AIGV_F_DIST_TO_GOAL, &dist);
9529 } break;
9530
9531 case MRM_ATTACK_CIRCLE_BACK: {
9532 // mprintf(0, "MODE CBACK\n");
9533 if (Game_GetTime() > last_see_target_time + 7.0f && Game_GetTime() > last_hear_target_time + 7.0f)
9534 SetMode(me, MRM_NORMAL);
9535
9536 if (memory->mode_time > 5.5f)
9537 SetMode(me, MRM_ATTACK);
9538 } break;
9539
9540 case MRM_NORMAL: {
9541 // mprintf(0, "MODE NORMAL\n");
9542 if (Game_GetTime() < last_see_target_time + 7.0f && Game_GetTime() < last_hear_target_time + 7.0f)
9543 SetMode(me, MRM_ATTACK);
9544 } break;
9545 }
9546
9547 memory->mode_time += Game_GetFrameTime();
9548 }
9549
9550 bool MantaRay::DoNotify(int me, tOSIRISEventInfo *data) {
9551 if (IsGoalFinishedNotify(data->evt_ai_notify.notify_type)) {
9552 switch (memory->mode) {
9553 case MRM_ATTACK:
9554 if (data->evt_ai_notify.goal_num == 1) {
9555 SetMode(me, MRM_ATTACK_CIRCLE_BACK);
9556 return false;
9557 }
9558 break;
9559 case MRM_ATTACK_CIRCLE_BACK:
9560 if (data->evt_ai_notify.goal_num == 1) {
9561 SetMode(me, MRM_ATTACK);
9562 return false;
9563 }
9564 break;
9565 }
9566 } else if (data->evt_ai_notify.notify_type == AIN_USER_DEFINED) {
9567 gb_com *com = (gb_com *)data->extra_info;
9568
9569 return ReceiveCommand(me, data->evt_ai_notify.it_handle, com->action, com->ptr);
9570 }
9571
9572 return true;
9573 }
9574
9575 int16_t MantaRay::CallEvent(int event, tOSIRISEventInfo *data) {
9576 switch (event) {
9577 case EVT_AI_INIT:
9578 DoInit(data->me_handle);
9579 break;
9580 case EVT_AI_FRAME:
9581 DoFrame(data->me_handle);
9582 break;
9583 case EVT_AI_NOTIFY:
9584 return (DoNotify(data->me_handle, data) != false) ? CONTINUE_CHAIN | CONTINUE_DEFAULT : 0;
9585 break;
9586 case EVT_MEMRESTORE: {
9587 memory = (mantaray_data *)data->evt_memrestore.memory_ptr;
9588 } break;
9589 }
9590 return CONTINUE_CHAIN | CONTINUE_DEFAULT;
9591 }
9592
9593 //------------------
9594 // Skiff class
9595 //------------------
9596
9597 bool Skiff::SendCommand(int me, int it, char command, void *ptr) {
9598 gb_com com;
9599
9600 com.action = command;
9601 com.ptr = ptr;
9602
9603 tOSIRISEventInfo ei;
9604
9605 ei.me_handle = it;
9606 ei.extra_info = (void *)&command;
9607 ei.evt_ai_notify.notify_type = AIN_USER_DEFINED;
9608 ei.evt_ai_notify.it_handle = me;
9609
9610 return Obj_CallEvent(it, EVT_AI_NOTIFY, &ei);
9611 }
9612
9613 bool Skiff::ReceiveCommand(int me, int it, char command, void *ptr) {
9614 switch (command) {
9615 case MRC_JOIN_ME: {
9616 if (memory->flags == 0) {
9617 memory->leader_handle = it;
9618 memory->flags |= MRF_SQUADIE;
9619
9620 SetMode(me, memory->mode);
9621
9622 return true;
9623 }
9624 } break;
9625 case MRC_LEAVE_YOU:
9626 break;
9627 case MRC_GET_GOAL_POS: {
9628 int i;
9629 for (i = 0; i < memory->num_teammates; i++) {
9630 if (memory->teammate[i] == it) {
9631 vector goal_pos;
9632 matrix orient;
9633 Obj_Value(me, VF_GET, OBJV_V_POS, &goal_pos);
9634 Obj_Value(me, VF_GET, OBJV_M_ORIENT, &orient);
9635
9636 switch (i) {
9637 case 0:
9638 goal_pos -= orient.fvec * MRO_FVEC;
9639 goal_pos -= orient.rvec * MRO_RVEC;
9640 break;
9641 case 1:
9642 goal_pos -= orient.fvec * MRO_FVEC;
9643 goal_pos += orient.rvec * MRO_RVEC;
9644 break;
9645 case 2:
9646 goal_pos -= orient.fvec * MRO_FVEC * 2.0f;
9647 goal_pos -= orient.rvec * MRO_RVEC * 2.0f;
9648 break;
9649 case 3:
9650 goal_pos -= orient.fvec * MRO_FVEC * 2.0f;
9651 goal_pos += orient.rvec * MRO_RVEC * 2.0f;
9652 break;
9653 }
9654
9655 *(vector *)ptr = goal_pos;
9656 return true;
9657 }
9658 }
9659 } break;
9660 case MRC_GET_GOAL_ROOM: {
9661 Obj_Value(me, VF_GET, OBJV_I_ROOMNUM, (int *)ptr);
9662 return true;
9663 } break;
9664 case MRC_GET_GOAL_ORIENT: {
9665 return true;
9666 } break;
9667 }
9668
9669 // mprintf(0, "Skiff action %d failed\n");
9670 return false;
9671 }
9672
9673 void Skiff::UpdateSquadList(int me) {
9674 int i;
9675
9676 for (i = 0; i < memory->num_teammates; i++) {
9677 int type;
9678 int j;
9679
9680 Obj_Value(memory->teammate[i], VF_GET, OBJV_I_TYPE, &type);
9681 if (type == OBJ_NONE) {
9682 for (j = i; j < memory->num_teammates - 1; j++) {
9683 memory->teammate[j] = memory->teammate[j + 1];
9684 }
9685
9686 memory->num_teammates--;
9687 i--;
9688 }
9689 }
9690 }
9691
9692 void Skiff::UpdateSquad(int me) {
9693 if (memory->flags & MRF_SQUADIE)
9694 return;
9695
9696 if (memory->flags & MRF_LEADER) {
9697 UpdateSquadList(me);
9698
9699 if (memory->num_teammates == 0)
9700 memory->flags &= ~MRF_LEADER;
9701
9702 if (memory->num_teammates >= MR_MAX_TEAMMATES)
9703 return;
9704 }
9705
9706 int scan_objs[25];
9707 int n_scan;
9708 int room;
9709 vector pos;
9710 int i;
9711
9712 Obj_Value(me, VF_GET, OBJV_V_POS, &pos);
9713 Obj_Value(me, VF_GET, OBJV_I_ROOMNUM, &room);
9714
9715 n_scan = AI_GetNearbyObjs(&pos, room, 200.0f, scan_objs, 25, false, true, false, true);
9716
9717 for (i = 0; i < n_scan; i++) {
9718 uint16_t id;
9719 Obj_Value(scan_objs[i], VF_GET, OBJV_US_ID, &id);
9720
9721 // this is more rare than the types matching; so, do it first
9722 if (id == memory->skiff_id) {
9723 int type;
9724 Obj_Value(scan_objs[i], VF_GET, OBJV_I_TYPE, &type);
9725 if (type == OBJ_ROBOT && scan_objs[i] != me) {
9726 bool f_on_team = false;
9727 if (memory->flags & MRF_LEADER) {
9728 int j;
9729 for (j = 0; j < memory->num_teammates; j++) {
9730 if (scan_objs[i] == memory->teammate[j]) {
9731 f_on_team = true;
9732 break;
9733 }
9734 }
9735 }
9736
9737 if (!f_on_team) {
9738 if (SendCommand(me, scan_objs[i], MRC_JOIN_ME, NULL)) {
9739 memory->flags |= MRF_LEADER;
9740 memory->teammate[memory->num_teammates++] = scan_objs[i];
9741 }
9742 }
9743 }
9744 }
9745
9746 if (memory->num_teammates >= MR_MAX_TEAMMATES)
9747 return;
9748 }
9749 }
9750
9751 void Skiff::DoInit(int me) {
9752 tOSIRISMEMCHUNK ch;
9753 ch.id = 4;
9754 ch.size = sizeof(skiff_data);
9755 ch.my_id.type = OBJECT_SCRIPT;
9756 ch.my_id.objhandle = me;
9757
9758 memory = (skiff_data *)Scrpt_MemAlloc(&ch);
9759
9760 AI_Value(me, VF_GET, AIV_F_MAX_SPEED, &memory->base_speed);
9761 memory->attack_speed = 1.6f * memory->base_speed;
9762
9763 memory->flags = 0;
9764 memory->leader_handle = OBJECT_HANDLE_NONE;
9765 memory->num_teammates = 0;
9766
9767 // .1 to .6 seconds into the level, do the first matching
9768 memory->next_update_squad_time = Game_GetTime() + ((float)rand() / (float)RAND_MAX) * .5f + 0.1f;
9769
9770 memory->skiff_id = Obj_FindID("Skiff");
9771
9772 SetMode(me, MRM_NORMAL);
9773 }
9774
9775 void Skiff::SetMode(int me, char mode) {
9776 int f_attack_flags = (AIF_FIRE | AIF_AUTO_AVOID_FRIENDS);
9777 AI_SetType(me, AIT_AIS);
9778
9779 AI_Value(me, VF_SET, AIV_F_MAX_SPEED, &memory->base_speed);
9780
9781 switch (mode) {
9782 case MRM_NORMAL: {
9783 vector pos;
9784 int room = 0;
9785 float dist = 15.0f;
9786
9787 AI_Value(me, VF_CLEAR_FLAGS, AIV_I_FLAGS, &f_attack_flags);
9788 AI_AddGoal(me, AIG_WANDER_AROUND, 1, 1.0f, -1, GF_ORIENT_VELOCITY | GF_NOTIFIES | GF_KEEP_AT_COMPLETION, &pos,
9789 room);
9790 AI_GoalValue(me, 1, VF_SET, AIGV_F_CIRCLE_DIST, &dist);
9791 } break;
9792
9793 case MRM_ATTACK: {
9794 AI_Value(me, VF_SET_FLAGS, AIV_I_FLAGS, &f_attack_flags);
9795
9796 // memory->next_attack_time = Game_GetTime() + 10.0 * ((float)rand()/(float)RAND_MAX);
9797
9798 float dist = 60.0f + ((float)rand() / (float)RAND_MAX) * 10.0f;
9799 AI_AddGoal(me, AIG_GET_TO_OBJ, 1, 1.0f, -1,
9800 GF_ORIENT_VELOCITY | GF_OBJ_IS_TARGET | GF_USE_BLINE_IF_SEES_GOAL | GF_KEEP_AT_COMPLETION |
9801 GF_NONFLUSHABLE,
9802 OBJECT_HANDLE_NONE);
9803 AI_GoalValue(me, 1, VF_SET, AIGV_F_CIRCLE_DIST, &dist);
9804
9805 dist = 10.0f;
9806 int g_index =
9807 AI_AddGoal(me, AIG_GET_AROUND_OBJ, ACTIVATION_BLEND_LEVEL, 1.0f, -1,
9808 GF_ORIENT_VELOCITY | GF_OBJ_IS_TARGET | GF_KEEP_AT_COMPLETION | GF_NONFLUSHABLE, OBJECT_HANDLE_NONE);
9809 AI_GoalValue(me, g_index, VF_SET, AIGV_F_CIRCLE_DIST, &dist);
9810 } break;
9811
9812 case MRM_ATTACK_CIRCLE_BACK: {
9813 vector pos;
9814 int room = 0;
9815
9816 AI_Value(me, VF_SET_FLAGS, AIV_I_FLAGS, &f_attack_flags);
9817
9818 Obj_Value(me, VF_GET, OBJV_V_POS, &pos);
9819 Obj_Value(me, VF_GET, OBJV_I_ROOMNUM, &room);
9820
9821 float dist = 10.0f;
9822
9823 AI_AddGoal(me, AIG_WANDER_AROUND, 1, 1.0f, -1,
9824 GF_NOTIFIES | GF_ORIENT_VELOCITY | GF_KEEP_AT_COMPLETION | GF_NONFLUSHABLE, &pos, room);
9825 AI_GoalValue(me, 1, VF_SET, AIGV_F_CIRCLE_DIST, &dist);
9826
9827 int g_index =
9828 AI_AddGoal(me, AIG_GET_AROUND_OBJ, ACTIVATION_BLEND_LEVEL, 1.0f, -1,
9829 GF_ORIENT_VELOCITY | GF_OBJ_IS_TARGET | GF_KEEP_AT_COMPLETION | GF_NONFLUSHABLE, OBJECT_HANDLE_NONE);
9830 AI_GoalValue(me, g_index, VF_SET, AIGV_F_CIRCLE_DIST, &dist);
9831
9832 AI_Value(me, VF_SET, AIV_F_MAX_SPEED, &memory->attack_speed);
9833 } break;
9834 }
9835
9836 if (memory->flags & MRF_SQUADIE) {
9837 // The leader is alive; so, get my new goal pos
9838 SendCommand(me, memory->leader_handle, MRC_GET_GOAL_POS, &memory->goal_pos);
9839 AI_GoalValue(me, 2, VF_SET, AIGV_V_POS, &memory->goal_pos);
9840 SendCommand(me, memory->leader_handle, MRC_GET_GOAL_ROOM, &memory->goal_room);
9841 AI_GoalValue(me, 2, VF_SET, AIGV_I_ROOMNUM, &memory->goal_room);
9842
9843 AI_AddGoal(me, AIG_GET_TO_POS, 2, 4.0f, -1, GF_ORIENT_VELOCITY | GF_KEEP_AT_COMPLETION | GF_NONFLUSHABLE,
9844 &memory->goal_pos, memory->goal_room);
9845 }
9846
9847 memory->mode = mode;
9848 memory->mode_time = 0.0f;
9849 }
9850
9851 void Skiff::DoSquadieFrame(int me) {
9852 int type;
9853 Obj_Value(memory->leader_handle, VF_GET, OBJV_I_TYPE, &type);
9854
9855 // Check if the leader is still alive
9856 if (type == OBJ_NONE) {
9857 if (memory->flags & MRF_CATCHUP) {
9858 AI_Value(me, VF_SET, AIV_F_MAX_SPEED, &memory->base_speed);
9859 }
9860
9861 memory->flags = 0;
9862 memory->leader_handle = OBJECT_HANDLE_NONE;
9863
9864 SetMode(me, MRM_NORMAL);
9865 return;
9866 }
9867
9868 // The leader is alive; so, get my new goal pos
9869 SendCommand(me, memory->leader_handle, MRC_GET_GOAL_POS, &memory->goal_pos);
9870 AI_GoalValue(me, 2, VF_SET, AIGV_V_POS, &memory->goal_pos);
9871 SendCommand(me, memory->leader_handle, MRC_GET_GOAL_ROOM, &memory->goal_room);
9872 AI_GoalValue(me, 2, VF_SET, AIGV_I_ROOMNUM, &memory->goal_room);
9873
9874 vector my_pos;
9875 Obj_Value(me, VF_GET, OBJV_V_POS, &my_pos);
9876
9877 float dist = vm_VectorDistance(&my_pos, &memory->goal_pos);
9878
9879 if (dist <= MRO_CATCHUP_DIST) {
9880 float scaled_speed = dist / MRO_CATCHUP_DIST * 0.18f * memory->base_speed;
9881 float speed;
9882
9883 AI_Value(memory->leader_handle, VF_GET, AIV_F_MAX_SPEED, &speed);
9884
9885 speed += scaled_speed;
9886
9887 memory->flags &= ~MRF_CATCHUP;
9888 AI_Value(me, VF_SET, AIV_F_MAX_SPEED, &memory->base_speed);
9889 } else if (!(memory->flags & MRF_CATCHUP) && dist > MRO_CATCHUP_DIST) {
9890 // Between 18% and 23% speed up to get into formation
9891 float catchup_speed;
9892 AI_Value(memory->leader_handle, VF_GET, AIV_F_MAX_SPEED, &catchup_speed);
9893 catchup_speed += (catchup_speed * .18f) + (catchup_speed * .05f * ((float)rand() / (float)RAND_MAX));
9894
9895 memory->flags |= MRF_CATCHUP;
9896 AI_Value(me, VF_SET, AIV_F_MAX_SPEED, &catchup_speed);
9897 }
9898
9899 // Get the leaders mode
9900
9901 // Set my mode to the leaders mode... (Modes account for flags)
9902 }
9903
9904 void Skiff::DoFrame(int me) {
9905 float last_see_target_time;
9906 float last_hear_target_time;
9907 AI_Value(me, VF_GET, AIV_F_LAST_SEE_TARGET_TIME, &last_see_target_time);
9908 AI_Value(me, VF_GET, AIV_F_LAST_HEAR_TARGET_TIME, &last_hear_target_time);
9909
9910 // Periodically update the squad information
9911 if (memory->next_update_squad_time <= Game_GetTime()) {
9912 // 3 to 6 seconds
9913 memory->next_update_squad_time = Game_GetTime() + ((float)rand() / (float)RAND_MAX) * 3.0f + 3.0f;
9914 // UpdateSquad(me);
9915 }
9916
9917 // If your a squadie, check for a leader
9918 if (memory->flags & MRF_SQUADIE) {
9919 DoSquadieFrame(me);
9920 }
9921
9922 switch (memory->mode) {
9923 case MRM_ATTACK: {
9924 // mprintf(0, "MODE ATTACK\n");
9925 if (Game_GetTime() > last_see_target_time + 7.0f && Game_GetTime() > last_hear_target_time + 7.0f)
9926 SetMode(me, MRM_NORMAL);
9927 //
9928 // float dist;
9929 // AI_GoalValue(me, 1, VF_GET, AIGV_F_DIST_TO_GOAL, &dist);
9930 } break;
9931
9932 case MRM_ATTACK_CIRCLE_BACK: {
9933 // mprintf(0, "MODE CBACK\n");
9934 if (Game_GetTime() > last_see_target_time + 7.0f && Game_GetTime() > last_hear_target_time + 7.0f)
9935 SetMode(me, MRM_NORMAL);
9936
9937 if (memory->mode_time > 4.0f)
9938 SetMode(me, MRM_ATTACK);
9939 } break;
9940
9941 case MRM_NORMAL: {
9942 // mprintf(0, "MODE NORMAL\n");
9943 if (Game_GetTime() < last_see_target_time + 7.0f && Game_GetTime() < last_see_target_time + 7.0f)
9944 SetMode(me, MRM_ATTACK);
9945 } break;
9946 }
9947
9948 memory->mode_time += Game_GetFrameTime();
9949 }
9950
9951 bool Skiff::DoNotify(int me, tOSIRISEventInfo *data) {
9952 if (IsGoalFinishedNotify(data->evt_ai_notify.notify_type)) {
9953 switch (memory->mode) {
9954 case MRM_ATTACK:
9955 if (data->evt_ai_notify.goal_num == 1) {
9956 SetMode(me, MRM_ATTACK_CIRCLE_BACK);
9957 return false;
9958 }
9959 break;
9960 case MRM_ATTACK_CIRCLE_BACK:
9961 if (data->evt_ai_notify.goal_num == 1) {
9962 SetMode(me, MRM_ATTACK);
9963 return false;
9964 }
9965 break;
9966 }
9967 } else if (data->evt_ai_notify.notify_type == AIN_USER_DEFINED) {
9968 gb_com *com = (gb_com *)data->extra_info;
9969
9970 return ReceiveCommand(me, data->evt_ai_notify.it_handle, com->action, com->ptr);
9971 }
9972
9973 return true;
9974 }
9975
9976 int16_t Skiff::CallEvent(int event, tOSIRISEventInfo *data) {
9977 switch (event) {
9978 case EVT_AI_INIT:
9979 DoInit(data->me_handle);
9980 break;
9981 case EVT_AI_FRAME:
9982 DoFrame(data->me_handle);
9983 break;
9984 case EVT_AI_NOTIFY:
9985 return (DoNotify(data->me_handle, data) != false) ? CONTINUE_CHAIN | CONTINUE_DEFAULT : 0;
9986 break;
9987 case EVT_MEMRESTORE: {
9988 memory = (skiff_data *)data->evt_memrestore.memory_ptr;
9989 } break;
9990 }
9991 return CONTINUE_CHAIN | CONTINUE_DEFAULT;
9992 }
9993
9994 //------------------
9995 // SpyHunter class
9996 //------------------
9997
9998 void SpyHunter::DoInit(int me) {
9999 tOSIRISMEMCHUNK ch;
10000 ch.id = 4;
10001 ch.size = sizeof(spyhunter_data);
10002 ch.my_id.type = OBJECT_SCRIPT;
10003 ch.my_id.objhandle = me;
10004
10005 memory = (spyhunter_data *)Scrpt_MemAlloc(&ch);
10006 memory->last_attack_mode = SHM_ATTACK;
10007 memory->f_hit_by_emd = false;
10008 memory->emd_id = Wpn_FindID("EMDblob");
10009 memory->tick_sound = Sound_FindId("WpnBmbTickElectricalA");
10010 memory->last_tick_time = Game_GetTime();
10011
10012 SetMode(me, SHM_NORMAL);
10013 }
10014
10015 void SpyHunter::SetMode(int me, char mode) {
10016 AI_SetType(me, AIT_AIS);
10017
10018 int f_attack_flags = (AIF_FIRE | AIF_AUTO_AVOID_FRIENDS);
10019
10020 if (memory->mode == SHM_ATTACK || memory->mode == SHM_BOMB_ATTACK) {
10021 memory->last_attack_mode = memory->mode;
10022 }
10023
10024 switch (mode) {
10025 case SHM_NORMAL: {
10026 vector pos;
10027 int room = 0;
10028 float dist = 5.0f;
10029
10030 AI_Value(me, VF_CLEAR_FLAGS, AIV_I_FLAGS, &f_attack_flags);
10031
10032 // If last see target time > 7.0 orient velocity
10033 AI_AddGoal(me, AIG_WANDER_AROUND, 1, 1.0f, -1,
10034 GF_ORIENT_TARGET | GF_KEEP_AT_COMPLETION | GF_FORCE_AWARENESS | GF_NOTIFIES, &pos, room);
10035 AI_GoalValue(me, 1, VF_SET, AIGV_F_CIRCLE_DIST, &dist);
10036 } break;
10037 case SHM_ATTACK: {
10038 AI_Value(me, VF_SET_FLAGS, AIV_I_FLAGS, &f_attack_flags);
10039 AI_SetType(me, AIT_EVADER1);
10040 } break;
10041 case SHM_BOMB_ATTACK: {
10042 float dist = -1000.0f;
10043
10044 f_attack_flags |= AIF_DODGE; // Bombs don't dodge
10045 AI_Value(me, VF_CLEAR_FLAGS, AIV_I_FLAGS, &f_attack_flags);
10046
10047 AI_AddGoal(me, AIG_GET_TO_OBJ, 1, 1.0f, -1,
10048 GF_ORIENT_VELOCITY | GF_KEEP_AT_COMPLETION | GF_OBJ_IS_TARGET | GF_FORCE_AWARENESS, OBJECT_HANDLE_NONE);
10049 AI_GoalValue(me, 1, VF_SET, AIGV_F_CIRCLE_DIST, &dist);
10050 } break;
10051 }
10052
10053 memory->mode = mode;
10054 memory->mode_time = 0.0f;
10055 memory->last_tick_time = Game_GetTime();
10056 memory->next_summon_time = Game_GetTime() + 5.0f + (float)rand() / (float)RAND_MAX;
10057 }
10058
10059 bool SpyHunter::DoNotify(int me, tOSIRISEventInfo *data) {
10060 tOSIRISEVTAINOTIFY *notify = &data->evt_ai_notify;
10061
10062 if ((!memory->f_hit_by_emd) && notify->notify_type == AIN_HIT_BY_WEAPON) {
10063 int type;
10064 Obj_Value(notify->it_handle, VF_GET, OBJV_I_TYPE, &type);
10065
10066 if (type == OBJ_WEAPON) {
10067 uint16_t id;
10068
10069 Obj_Value(notify->it_handle, VF_GET, OBJV_US_ID, &id);
10070 if (id == memory->emd_id) {
10071 memory->f_hit_by_emd = true;
10072 }
10073 }
10074 }
10075
10076 if (memory->mode == SHM_NORMAL || (memory->mode == SHM_ATTACK && memory->mode_time > 10.0f)) {
10077 if ((notify->notify_type == AIN_OBJ_FIRED) || (notify->notify_type == AIN_HIT_BY_WEAPON) ||
10078 (notify->notify_type == AIN_BUMPED_OBJ)) {
10079 if (memory->mode == SHM_NORMAL) {
10080 SetMode(me, SHM_ATTACK);
10081 return true;
10082 } else {
10083 SetMode(me, SHM_BOMB_ATTACK);
10084 return true;
10085 }
10086 }
10087 }
10088
10089 if (memory->mode == SHM_BOMB_ATTACK && notify->notify_type == AIN_BUMPED_OBJ) {
10090 int room;
10091 vector pos;
10092
10093 Obj_Value(me, VF_GET, OBJV_I_ROOMNUM, &room);
10094 Obj_GetGunPos(me, 0, &pos);
10095
10096 if (!memory->f_hit_by_emd) {
10097 vector velocity;
10098 Obj_Value(me, VF_GET, OBJV_V_VELOCITY, &velocity);
10099
10100 int weapon_id = Wpn_FindID("FragBarrel");
10101 Obj_Create(OBJ_WEAPON, weapon_id, room, &pos, NULL, me, &velocity);
10102 }
10103
10104 msafe_struct mstruct;
10105
10106 mstruct.objhandle = me;
10107 mstruct.killer_handle = OBJECT_HANDLE_NONE;
10108 mstruct.damage_type = GD_SCRIPTED;
10109 mstruct.amount = 1000.0f;
10110
10111 MSafe_CallFunction(MSAFE_OBJECT_DAMAGE_OBJECT, &mstruct);
10112 }
10113
10114 return true;
10115 }
10116
10117 void SpyHunter::DoFrame(int me) {
10118 // mprintf(0, "Current goal is %d and the ", AI_GetCurGoalIndex(me));
10119
10120 switch (memory->mode) {
10121 case SHM_NORMAL: {
10122 // int gt = -1;
10123 //
10124 // if(AI_GetCurGoalIndex(me) >= 0)
10125 // AI_GoalValue(me, AI_GetCurGoalIndex(me), VF_GET, AIGV_I_TYPE, &gt);
10126 //
10127 // mprintf(0, "current Mode is Normal and GT %X\n", gt);
10128 } break;
10129 case SHM_ATTACK: {
10130 // mprintf(0, "current Mode is Attack\n");
10131 // if(memory->mode_time > 10.0f)
10132 // {
10133 // SetMode(me, SHM_BOMB_ATTACK);
10134 // }
10135 } break;
10136 case SHM_BOMB_ATTACK: {
10137 float tick_interval;
10138 // mprintf(0, "current Mode is Bomb Attack\n");
10139
10140 if (memory->mode_time < SH_BOMB_TICK_RAMP_TIME) {
10141 float p_explode = (SH_BOMB_TICK_RAMP_TIME - memory->mode_time) / SH_BOMB_TICK_RAMP_TIME;
10142
10143 tick_interval = (SH_MAX_TICK_INTERVAL * p_explode) + (SH_MIN_TICK_INTERVAL * (1.0f - p_explode));
10144 } else {
10145 tick_interval = SH_MIN_TICK_INTERVAL;
10146 }
10147
10148 if (memory->last_tick_time + tick_interval < Game_GetTime()) {
10149 Sound_Play3d(me, memory->tick_sound);
10150 memory->last_tick_time = Game_GetTime();
10151 }
10152
10153 if (memory->mode_time < SH_MAX_BOMB_TIME) {
10154 float max_speed;
10155
10156 AI_Value(me, VF_GET, AIV_F_MAX_SPEED, &max_speed);
10157 max_speed += SH_BOMB_ACCELERATION * Game_GetFrameTime();
10158 AI_Value(me, VF_SET, AIV_F_MAX_SPEED, &max_speed);
10159
10160 AI_Value(me, VF_GET, AIV_F_MAX_TURN_RATE, &max_speed);
10161 max_speed += SH_BOMB_ROT_ACC * Game_GetFrameTime();
10162 AI_Value(me, VF_SET, AIV_F_MAX_TURN_RATE, &max_speed);
10163
10164 AI_Value(me, VF_GET, AIV_F_MAX_DELTA_SPEED, &max_speed);
10165 max_speed += SH_BOMB_ACCELERATION * Game_GetFrameTime();
10166 AI_Value(me, VF_SET, AIV_F_MAX_DELTA_SPEED, &max_speed);
10167 }
10168 } break;
10169 }
10170
10171 memory->mode_time += Game_GetFrameTime();
10172 }
10173
10174 int16_t SpyHunter::CallEvent(int event, tOSIRISEventInfo *data) {
10175 switch (event) {
10176 case EVT_AI_INIT:
10177 DoInit(data->me_handle);
10178 break;
10179 case EVT_AI_FRAME:
10180 DoFrame(data->me_handle);
10181 break;
10182 case EVT_AI_NOTIFY:
10183 return (DoNotify(data->me_handle, data) != false) ? CONTINUE_CHAIN | CONTINUE_DEFAULT : 0;
10184 break;
10185 case EVT_MEMRESTORE: {
10186 memory = (spyhunter_data *)data->evt_memrestore.memory_ptr;
10187 } break;
10188 }
10189 return CONTINUE_CHAIN | CONTINUE_DEFAULT;
10190 }
10191
10192 //------------------
10193 // Sniper class
10194 //------------------
10195
10196 bool Sniper::DoNotify(int me_handle, tOSIRISEventInfo *data) { return true; }
10197
10198 void Sniper::SetMode(int me, char mode) {
10199 switch (mode) {
10200 case SNIPER_SNIPE: {
10201 vector pos;
10202 int room = 0;
10203
10204 int flags = GF_NOTIFIES;
10205
10206 if ((rand() % 100) > 50) {
10207 flags |= GF_ORIENT_TARGET;
10208 AI_AddGoal(me, AIG_MOVE_RELATIVE_OBJ_VEC, 0, 1.0f, -1, GF_SPEED_ATTACK | GF_KEEP_AT_COMPLETION | GF_OBJ_IS_TARGET,
10209 NULL, GST_NEG_FVEC);
10210 memory->time_till_next_mode = 4.0f * (float)rand() / (float)RAND_MAX + 2.0f;
10211 } else {
10212 float timescaler = 1.0f;
10213
10214 if ((rand() % 100) >= 94) {
10215 flags |= GF_ORIENT_VELOCITY | GF_SPEED_FLEE;
10216 timescaler = 2.0f;
10217 } else {
10218 flags |= GF_SPEED_ATTACK;
10219 }
10220
10221 AI_AddGoal(me, AIG_WANDER_AROUND, 3, 1.0f, -1, flags, &pos, room);
10222
10223 float speed = memory->base_speed + memory->base_speed * (float)rand() / (float)RAND_MAX * .5;
10224 float delta_vel = memory->base_acc + memory->base_acc * (float)rand() / (float)RAND_MAX * .5;
10225
10226 AI_Value(me, VF_SET, AIV_F_MAX_SPEED, &speed);
10227 AI_Value(me, VF_SET, AIV_F_MAX_DELTA_SPEED, &delta_vel);
10228
10229 memory->time_till_next_mode = 4.0f * (float)rand() / (float)RAND_MAX + 2.0f;
10230 memory->time_till_next_mode *= timescaler;
10231 }
10232
10233 } break;
10234 case SNIPER_BASE: {
10235 bool used;
10236 AI_GoalValue(me, 3, VF_GET, AIGV_B_USED, &used);
10237
10238 if (used) {
10239 int flags;
10240 AI_GoalValue(me, 3, VF_GET, AIGV_I_FLAGS, &flags);
10241
10242 if (!(flags & GF_NONFLUSHABLE)) {
10243 AI_ClearGoal(me, 3);
10244 }
10245 }
10246
10247 AI_Value(me, VF_SET, AIV_F_MAX_SPEED, &memory->base_speed);
10248 AI_Value(me, VF_SET, AIV_F_MAX_DELTA_SPEED, &memory->base_acc);
10249 memory->time_till_next_mode = 5.0f * (float)rand() / (float)RAND_MAX;
10250 +6.0f;
10251 } break;
10252 }
10253
10254 memory->mode_time = 0.0f;
10255 memory->mode = mode;
10256 }
10257
10258 void Sniper::DoInit(int me) {
10259 tOSIRISMEMCHUNK ch;
10260 ch.id = 4;
10261 ch.size = sizeof(sniper_data);
10262 ch.my_id.type = OBJECT_SCRIPT;
10263 ch.my_id.objhandle = me;
10264
10265 memory = (sniper_data *)Scrpt_MemAlloc(&ch);
10266
10267 AI_Value(me, VF_GET, AIV_F_MAX_SPEED, &memory->base_speed);
10268 AI_Value(me, VF_GET, AIV_F_MAX_DELTA_SPEED, &memory->base_acc);
10269
10270 SetMode(me, SNIPER_BASE);
10271 }
10272
10273 void Sniper::DoFrame(int me) {
10274 msafe_struct m;
10275 m.objhandle = me;
10276 MSafe_GetValue(MSAFE_OBJECT_ID, &m);
10277 int orbot_id = Obj_FindID("d3bot20");
10278
10279 if (m.id != orbot_id) {
10280 bool used;
10281 AI_GoalValue(me, 3, VF_GET, AIGV_B_USED, &used);
10282
10283 if (used) {
10284 return;
10285 }
10286
10287 /* float awareness;
10288 AI_Value(me, VF_GET, AIV_F_AWARENESS, &awareness);
10289
10290 if(awareness <= AWARE_BARELY)
10291 {
10292 if(memory->mode != SNIPER_BASE)
10293 {
10294 SetMode(me, SNIPER_BASE);
10295 }
10296
10297 return;
10298 }*/
10299 }
10300
10301 if (memory->time_till_next_mode < memory->mode_time) {
10302 if (memory->mode == SNIPER_BASE)
10303 SetMode(me, SNIPER_SNIPE);
10304 else
10305 SetMode(me, SNIPER_BASE);
10306 }
10307
10308 memory->mode_time += Game_GetFrameTime();
10309 }
10310
10311 int16_t Sniper::CallEvent(int event, tOSIRISEventInfo *data) {
10312 switch (event) {
10313 case EVT_AI_INIT:
10314 DoInit(data->me_handle);
10315 break;
10316 case EVT_AI_FRAME:
10317 DoFrame(data->me_handle);
10318 break;
10319 case EVT_AI_NOTIFY:
10320 return (DoNotify(data->me_handle, data) != false) ? CONTINUE_CHAIN | CONTINUE_DEFAULT : 0;
10321 break;
10322 case EVT_MEMRESTORE: {
10323 memory = (sniper_data *)data->evt_memrestore.memory_ptr;
10324 } break;
10325 }
10326 return CONTINUE_CHAIN | CONTINUE_DEFAULT;
10327 }
10328
10329 //------------------
10330 // SniperNoRun class
10331 //------------------
10332
10333 bool SniperNoRun::DoNotify(int me_handle, tOSIRISEventInfo *data) { return true; }
10334
10335 void SniperNoRun::SetMode(int me, char mode) {
10336 switch (mode) {
10337 case SNIPER_SNIPE: {
10338 vector pos;
10339 int room = 0;
10340
10341 int flags = GF_NOTIFIES;
10342
10343 if ((rand() % 100) > 50) {
10344 flags |= GF_ORIENT_TARGET;
10345 AI_AddGoal(me, AIG_MOVE_RELATIVE_OBJ_VEC, 0, 1.0f, -1, GF_SPEED_ATTACK | GF_KEEP_AT_COMPLETION | GF_OBJ_IS_TARGET,
10346 NULL, GST_NEG_FVEC);
10347 memory->time_till_next_mode = 4.0f * (float)rand() / (float)RAND_MAX + 2.0f;
10348 } else {
10349 float timescaler = 1.0f;
10350
10351 flags |= GF_SPEED_ATTACK;
10352 AI_AddGoal(me, AIG_WANDER_AROUND, 3, 1.0f, -1, flags, &pos, room);
10353
10354 float speed = memory->base_speed + memory->base_speed * (float)rand() / (float)RAND_MAX * .5;
10355 float delta_vel = memory->base_acc + memory->base_acc * (float)rand() / (float)RAND_MAX * .5;
10356
10357 AI_Value(me, VF_SET, AIV_F_MAX_SPEED, &speed);
10358 AI_Value(me, VF_SET, AIV_F_MAX_DELTA_SPEED, &delta_vel);
10359
10360 memory->time_till_next_mode = 2.0f * (float)rand() / (float)RAND_MAX + 2.0f;
10361 memory->time_till_next_mode *= timescaler;
10362 }
10363
10364 } break;
10365 case SNIPER_BASE: {
10366 bool used;
10367 AI_GoalValue(me, 3, VF_GET, AIGV_B_USED, &used);
10368
10369 if (used) {
10370 int flags;
10371 AI_GoalValue(me, 3, VF_GET, AIGV_I_FLAGS, &flags);
10372
10373 if (!(flags & GF_NONFLUSHABLE)) {
10374 AI_ClearGoal(me, 3);
10375 }
10376 }
10377
10378 AI_Value(me, VF_SET, AIV_F_MAX_SPEED, &memory->base_speed);
10379 AI_Value(me, VF_SET, AIV_F_MAX_DELTA_SPEED, &memory->base_acc);
10380 memory->time_till_next_mode = 5.0f * (float)rand() / (float)RAND_MAX;
10381 +4.0f;
10382 } break;
10383 }
10384
10385 memory->mode_time = 0.0f;
10386 memory->mode = mode;
10387 }
10388
10389 void SniperNoRun::DoInit(int me) {
10390 tOSIRISMEMCHUNK ch;
10391 ch.id = 4;
10392 ch.size = sizeof(snipernorun_data);
10393 ch.my_id.type = OBJECT_SCRIPT;
10394 ch.my_id.objhandle = me;
10395
10396 memory = (snipernorun_data *)Scrpt_MemAlloc(&ch);
10397
10398 AI_Value(me, VF_GET, AIV_F_MAX_SPEED, &memory->base_speed);
10399 AI_Value(me, VF_GET, AIV_F_MAX_DELTA_SPEED, &memory->base_acc);
10400
10401 SetMode(me, SNIPER_BASE);
10402 }
10403
10404 void SniperNoRun::DoFrame(int me) {
10405 msafe_struct m;
10406 m.objhandle = me;
10407 MSafe_GetValue(MSAFE_OBJECT_ID, &m);
10408 int orbot_id = Obj_FindID("d3bot20");
10409
10410 if (m.id != orbot_id) {
10411 bool used;
10412 AI_GoalValue(me, 3, VF_GET, AIGV_B_USED, &used);
10413
10414 if (used) {
10415 return;
10416 }
10417
10418 /* float awareness;
10419 AI_Value(me, VF_GET, AIV_F_AWARENESS, &awareness);
10420
10421 if(awareness <= AWARE_BARELY)
10422 {
10423 if(memory->mode != SNIPER_BASE)
10424 {
10425 SetMode(me, SNIPER_BASE);
10426 }
10427
10428 return;
10429 }*/
10430 }
10431
10432 if (memory->time_till_next_mode < memory->mode_time) {
10433 if (memory->mode == SNIPER_BASE)
10434 SetMode(me, SNIPER_SNIPE);
10435 else
10436 SetMode(me, SNIPER_BASE);
10437 }
10438
10439 memory->mode_time += Game_GetFrameTime();
10440 }
10441
10442 int16_t SniperNoRun::CallEvent(int event, tOSIRISEventInfo *data) {
10443 switch (event) {
10444 case EVT_AI_INIT:
10445 DoInit(data->me_handle);
10446 break;
10447 case EVT_AI_FRAME:
10448 DoFrame(data->me_handle);
10449 break;
10450 case EVT_AI_NOTIFY:
10451 return (DoNotify(data->me_handle, data) != false) ? CONTINUE_CHAIN | CONTINUE_DEFAULT : 0;
10452 break;
10453 case EVT_MEMRESTORE: {
10454 memory = (snipernorun_data *)data->evt_memrestore.memory_ptr;
10455 } break;
10456 }
10457 return CONTINUE_CHAIN | CONTINUE_DEFAULT;
10458 }
10459
10460 //------------------
10461 // Evader Mod A class
10462 //------------------
10463
10464 #define EMA_NORMAL 0
10465 #define EMA_GET_BEHIND 1
10466
10467 bool EvaderModA::DoNotify(int me_handle, tOSIRISEventInfo *data) { return true; }
10468
10469 void EvaderModA::SetMode(int me, char mode) {
10470 switch (mode) {
10471 case EMA_GET_BEHIND: {
10472 vector pos;
10473 int vec;
10474
10475 int flags = GF_NOTIFIES | GF_ORIENT_TARGET;
10476
10477 if ((rand() % 100) > 50) {
10478 vec = GST_NEG_FVEC;
10479 memory->time_till_next_mode = 7.0f * (float)rand() / (float)RAND_MAX + 2.0f;
10480 } else {
10481 if ((rand() % 100) > 50) {
10482 vec = GST_NEG_RVEC;
10483 } else {
10484 vec = GST_RVEC;
10485 }
10486 memory->time_till_next_mode = 4.0f * (float)rand() / (float)RAND_MAX + 2.0f;
10487 }
10488
10489 AI_AddGoal(me, AIG_MOVE_RELATIVE_OBJ_VEC, 0, 1.0f, -1, GF_SPEED_ATTACK | GF_KEEP_AT_COMPLETION | GF_OBJ_IS_TARGET,
10490 NULL, vec);
10491 } break;
10492 case EMA_NORMAL: {
10493 AI_Value(me, VF_SET, AIV_F_MAX_SPEED, &memory->base_speed);
10494 AI_Value(me, VF_SET, AIV_F_MAX_DELTA_SPEED, &memory->base_acc);
10495
10496 bool used;
10497 AI_GoalValue(me, 3, VF_GET, AIGV_B_USED, &used);
10498
10499 if (used) {
10500 int flags;
10501 AI_GoalValue(me, 3, VF_GET, AIGV_I_FLAGS, &flags);
10502
10503 if (!(flags & GF_NONFLUSHABLE)) {
10504 AI_ClearGoal(me, 3);
10505 }
10506 }
10507
10508 memory->time_till_next_mode = 4.0f * (float)rand() / (float)RAND_MAX;
10509 +6.0f;
10510 } break;
10511 }
10512
10513 memory->mode_time = 0.0f;
10514 memory->mode = mode;
10515 }
10516
10517 void EvaderModA::DoInit(int me) {
10518 tOSIRISMEMCHUNK ch;
10519 ch.id = 4;
10520 ch.size = sizeof(evadermoda_data);
10521 ch.my_id.type = OBJECT_SCRIPT;
10522 ch.my_id.objhandle = me;
10523
10524 memory = (evadermoda_data *)Scrpt_MemAlloc(&ch);
10525
10526 AI_Value(me, VF_GET, AIV_F_MAX_SPEED, &memory->base_speed);
10527 AI_Value(me, VF_GET, AIV_F_MAX_DELTA_SPEED, &memory->base_acc);
10528
10529 SetMode(me, EMA_NORMAL);
10530 }
10531
10532 void EvaderModA::DoFrame(int me) {
10533 float awareness;
10534 AI_Value(me, VF_GET, AIV_F_AWARENESS, &awareness);
10535
10536 bool used;
10537 AI_GoalValue(me, 3, VF_GET, AIGV_B_USED, &used);
10538
10539 if (used) {
10540 return;
10541 }
10542
10543 if (awareness <= AWARE_BARELY) {
10544 if (memory->mode != EMA_NORMAL) {
10545 SetMode(me, EMA_NORMAL);
10546 }
10547
10548 return;
10549 }
10550
10551 if (memory->time_till_next_mode < memory->mode_time) {
10552 if (memory->mode == EMA_NORMAL)
10553 SetMode(me, EMA_GET_BEHIND);
10554 else
10555 SetMode(me, EMA_NORMAL);
10556 }
10557
10558 memory->mode_time += Game_GetFrameTime();
10559 }
10560
10561 int16_t EvaderModA::CallEvent(int event, tOSIRISEventInfo *data) {
10562 switch (event) {
10563 case EVT_AI_INIT:
10564 DoInit(data->me_handle);
10565 break;
10566 case EVT_AI_FRAME:
10567 DoFrame(data->me_handle);
10568 break;
10569 case EVT_AI_NOTIFY:
10570 return (DoNotify(data->me_handle, data) != false) ? CONTINUE_CHAIN | CONTINUE_DEFAULT : 0;
10571 break;
10572 case EVT_MEMRESTORE: {
10573 memory = (evadermoda_data *)data->evt_memrestore.memory_ptr;
10574 } break;
10575 }
10576 return CONTINUE_CHAIN | CONTINUE_DEFAULT;
10577 }
10578
10579 //------------------
10580 // FlameRAS
10581 //------------------
10582
10583 // Based off EvaderModA
10584
10585 bool FlameRAS::DoNotify(int me_handle, tOSIRISEventInfo *data) { return true; }
10586
10587 void FlameRAS::SetMode(int me, char mode) {
10588 switch (mode) {
10589 case EMA_GET_BEHIND: {
10590 vector pos;
10591 int vec;
10592
10593 int flags = GF_NOTIFIES | GF_ORIENT_TARGET;
10594
10595 if ((rand() % 100) > 50) {
10596 vec = GST_NEG_FVEC;
10597 memory->time_till_next_mode = 7.0f * (float)rand() / (float)RAND_MAX + 2.0f;
10598 } else {
10599 if ((rand() % 100) > 50) {
10600 vec = GST_NEG_RVEC;
10601 } else {
10602 vec = GST_RVEC;
10603 }
10604 memory->time_till_next_mode = 4.0f * (float)rand() / (float)RAND_MAX + 2.0f;
10605 }
10606
10607 AI_AddGoal(me, AIG_MOVE_RELATIVE_OBJ_VEC, 0, 1.0f, -1, GF_SPEED_ATTACK | GF_KEEP_AT_COMPLETION | GF_OBJ_IS_TARGET,
10608 NULL, vec);
10609 } break;
10610 case EMA_NORMAL: {
10611 AI_Value(me, VF_SET, AIV_F_MAX_SPEED, &memory->base_speed);
10612 AI_Value(me, VF_SET, AIV_F_MAX_DELTA_SPEED, &memory->base_acc);
10613
10614 bool used;
10615 AI_GoalValue(me, 3, VF_GET, AIGV_B_USED, &used);
10616
10617 if (used) {
10618 int flags;
10619 AI_GoalValue(me, 3, VF_GET, AIGV_I_FLAGS, &flags);
10620
10621 if (!(flags & GF_NONFLUSHABLE)) {
10622 AI_ClearGoal(me, 3);
10623 }
10624 }
10625
10626 memory->time_till_next_mode = 4.0f * (float)rand() / (float)RAND_MAX;
10627 +6.0f;
10628 } break;
10629 }
10630
10631 memory->mode_time = 0.0f;
10632 memory->mode = mode;
10633 }
10634
10635 void FlameRAS::DoInit(int me) {
10636 tOSIRISMEMCHUNK ch;
10637 ch.id = 4;
10638 ch.size = sizeof(flameras_data);
10639 ch.my_id.type = OBJECT_SCRIPT;
10640 ch.my_id.objhandle = me;
10641
10642 memory = (flameras_data *)Scrpt_MemAlloc(&ch);
10643
10644 memory->time_till_fire_toggle = 3.0f + (float)rand() / (float)RAND_MAX + (float)Game_GetDiffLevel();
10645 memory->f_firing_ok = true;
10646
10647 AI_Value(me, VF_GET, AIV_F_MAX_SPEED, &memory->base_speed);
10648 AI_Value(me, VF_GET, AIV_F_MAX_DELTA_SPEED, &memory->base_acc);
10649
10650 SetMode(me, EMA_NORMAL);
10651 }
10652
10653 void FlameRAS::DoFrame(int me) {
10654 float awareness;
10655 AI_Value(me, VF_GET, AIV_F_AWARENESS, &awareness);
10656
10657 bool used;
10658 AI_GoalValue(me, 3, VF_GET, AIGV_B_USED, &used);
10659
10660 if (memory->time_till_fire_toggle <= 0.0f) {
10661 if (memory->f_firing_ok) {
10662 int flags = AIF_DISABLE_FIRING;
10663 AI_Value(me, VF_SET_FLAGS, AIV_I_FLAGS, &flags);
10664
10665 memory->time_till_fire_toggle = 5.0f + (float)rand() / (float)RAND_MAX + ((float)Game_GetDiffLevel() - 3.0f);
10666 memory->f_firing_ok = false;
10667 } else {
10668 int flags = AIF_DISABLE_FIRING;
10669 AI_Value(me, VF_CLEAR_FLAGS, AIV_I_FLAGS, &flags);
10670
10671 memory->time_till_fire_toggle = 4.0f + (float)rand() / (float)RAND_MAX + (float)Game_GetDiffLevel();
10672 memory->f_firing_ok = true;
10673 }
10674 }
10675
10676 if (used) {
10677 return;
10678 }
10679
10680 if (awareness <= AWARE_BARELY) {
10681 if (memory->mode != EMA_NORMAL) {
10682 SetMode(me, EMA_NORMAL);
10683 }
10684
10685 return;
10686 }
10687
10688 if (memory->time_till_next_mode < memory->mode_time) {
10689 if (memory->mode == EMA_NORMAL)
10690 SetMode(me, EMA_GET_BEHIND);
10691 else
10692 SetMode(me, EMA_NORMAL);
10693 }
10694
10695 memory->time_till_fire_toggle -= Game_GetFrameTime();
10696 memory->mode_time += Game_GetFrameTime();
10697 }
10698
10699 int16_t FlameRAS::CallEvent(int event, tOSIRISEventInfo *data) {
10700 switch (event) {
10701 case EVT_AI_INIT:
10702 DoInit(data->me_handle);
10703 break;
10704 case EVT_AI_FRAME:
10705 DoFrame(data->me_handle);
10706 break;
10707 case EVT_AI_NOTIFY:
10708 return (DoNotify(data->me_handle, data) != false) ? CONTINUE_CHAIN | CONTINUE_DEFAULT : 0;
10709 break;
10710 case EVT_MEMRESTORE: {
10711 memory = (flameras_data *)data->evt_memrestore.memory_ptr;
10712 } break;
10713 }
10714 return CONTINUE_CHAIN | CONTINUE_DEFAULT;
10715 }
10716
10717 //------------------
10718 // Seeker class
10719 //------------------
10720
10721 void Seeker::DoInit(int me) {
10722 AI_SetType(me, AIT_AIS);
10723 AI_AddGoal(me, AIG_GET_TO_OBJ, 1, 1.0f, -1, GF_OBJ_IS_TARGET | GF_USE_BLINE_IF_SEES_GOAL, OBJECT_HANDLE_NONE);
10724
10725 uint16_t id;
10726 uint16_t humon_seeker_id;
10727
10728 Obj_Value(me, VF_GET, OBJV_US_ID, &id);
10729 humon_seeker_id = Obj_FindID("HumonSeeker");
10730
10731 if (humon_seeker_id == id) {
10732 vector velocity;
10733 matrix orient;
10734 Obj_Value(me, VF_GET, OBJV_V_VELOCITY, &velocity);
10735 Obj_Value(me, VF_GET, OBJV_M_ORIENT, &orient);
10736
10737 velocity += orient.fvec * 50.0f;
10738
10739 Obj_Value(me, VF_SET, OBJV_V_VELOCITY, &velocity);
10740 }
10741
10742 int parent = GetObjectParent(me);
10743 int sound_id = Sound_FindId("Drop bomb");
10744 int p_type = GetObjectType(parent);
10745
10746 if (sound_id >= 0 && p_type == OBJ_PLAYER) {
10747 Sound_Play3d(parent, sound_id);
10748 }
10749 }
10750
10751 void Seeker::DoCollide(int me) {
10752 int room;
10753 vector pos;
10754 int weapon_id;
10755
10756 Obj_Value(me, VF_GET, OBJV_I_ROOMNUM, &room);
10757 Obj_Value(me, VF_GET, OBJV_V_POS, &pos);
10758
10759 weapon_id = Wpn_FindID("SeekerExplosion");
10760 Obj_Create(OBJ_WEAPON, weapon_id, room, &pos, NULL, me);
10761
10762 msafe_struct mo;
10763 mo.objhandle = me;
10764 mo.playsound = 0;
10765
10766 MSafe_CallFunction(MSAFE_OBJECT_REMOVE, &mo);
10767 }
10768
10769 int16_t Seeker::CallEvent(int event, tOSIRISEventInfo *data) {
10770 switch (event) {
10771 case EVT_AI_INIT:
10772 DoInit(data->me_handle);
10773 break;
10774 case EVT_COLLIDE:
10775 DoCollide(data->me_handle);
10776 break;
10777 }
10778 return CONTINUE_CHAIN | CONTINUE_DEFAULT;
10779 }
10780
10781 // Old Osiris functions converted to make porting easier
10782 int GetObjectParent(int object) {
10783 msafe_struct ms;
10784 ms.objhandle = object;
10785
10786 MSafe_GetValue(MSAFE_OBJECT_PARENT, &ms);
10787
10788 return ms.objhandle;
10789 }
10790
10791 int GetObjectType(int object) {
10792 msafe_struct ms;
10793 ms.objhandle = object;
10794 MSafe_GetValue(MSAFE_OBJECT_TYPE, &ms);
10795
10796 return ms.type;
10797 }
10798
10799 void ObjectDamage(int object, float amount, int killer = OBJECT_HANDLE_NONE);
10800 void ObjectDamage(int object, float amount, int killer) {
10801 msafe_struct mstruct;
10802
10803 mstruct.objhandle = object;
10804 mstruct.killer_handle = killer;
10805 mstruct.damage_type = GD_SCRIPTED;
10806 mstruct.amount = amount;
10807
10808 MSafe_CallFunction(MSAFE_OBJECT_DAMAGE_OBJECT, &mstruct);
10809 }
10810
10811 float GetObjectShields(int object) {
10812 msafe_struct mstruct;
10813
10814 mstruct.objhandle = object;
10815 MSafe_GetValue(MSAFE_OBJECT_SHIELDS, &mstruct);
10816
10817 return mstruct.shields;
10818 }
10819
10820 void ObjectRemove(int object) {
10821 msafe_struct ms;
10822 ms.objhandle = object;
10823 ms.playsound = 0;
10824 MSafe_CallFunction(MSAFE_OBJECT_REMOVE, &ms);
10825 }
10826
10827 //------------------
10828 // Bouncing Betty class
10829 //------------------
10830
10831 int16_t BettyBomb::CallEvent(int event, tOSIRISEventInfo *data) {
10832 switch (event) {
10833 case EVT_MEMRESTORE: {
10834 memory = (tBettyBombInfo *)data->evt_memrestore.memory_ptr;
10835 } break;
10836
10837 case EVT_CREATED: {
10838 // create our memory
10839 tOSIRISMEMCHUNK ch;
10840 ch.id = 4;
10841 ch.size = sizeof(tBettyBombInfo);
10842 ch.my_id.type = OBJECT_SCRIPT;
10843 ch.my_id.objhandle = data->me_handle;
10844
10845 memory = (tBettyBombInfo *)Scrpt_MemAlloc(&ch);
10846
10847 memory->explode = false;
10848
10849 // Create and release our Betty children
10850 int parent = GetObjectParent(data->me_handle);
10851 int child_id = Obj_FindID("Betty");
10852
10853 if (parent != OBJECT_HANDLE_NONE && child_id != -1) {
10854 int child_handle;
10855 matrix orient, o, otemp, o1;
10856 vector vel, pos, v, vtemp;
10857 int room;
10858
10859 Obj_Value(parent, VF_GET, OBJV_M_ORIENT, &orient);
10860 Obj_Value(parent, VF_GET, OBJV_V_VELOCITY, &vel);
10861 Obj_Value(parent, VF_GET, OBJV_I_ROOMNUM, &room);
10862 Obj_Value(parent, VF_GET, OBJV_V_POS, &pos);
10863
10864 // v = -vel;
10865 /*
10866 v = vel;
10867 float mag = vm_GetMagnitude(&v);
10868 if(mag < 30.0f )
10869 {
10870 if(mag==0)
10871 mag = 0.001f;
10872
10873 v /= mag;
10874 v *= 30.0f;
10875 }
10876 */
10877
10878 v = -orient.fvec + orient.rvec - orient.uvec;
10879 vm_VectorNormalize(&v);
10880 v *= 30.0f;
10881
10882 // give drop bomb sound
10883 int type = GetObjectType(parent);
10884
10885 if (type == OBJ_PLAYER || type == OBJ_GHOST) {
10886 int sound_id = Sound_FindId("Drop bomb");
10887
10888 if (sound_id >= 0) {
10889 Sound_Play3d(parent, sound_id);
10890 }
10891 }
10892
10893 // First create middle Betty
10894 child_handle = Obj_Create(OBJ_ROBOT, child_id, room, &pos, &orient, parent, &v);
10895
10896 // Now create left Betty
10897 v = -orient.fvec + (0.3f * orient.rvec) - orient.uvec;
10898 vm_VectorNormalize(&v);
10899 v *= 30.0f;
10900 child_handle = Obj_Create(OBJ_ROBOT, child_id, room, &pos, &orient, parent, &v);
10901
10902 // Now create right Betty
10903 v = -orient.fvec - (0.3f * orient.rvec) - orient.uvec;
10904 vm_VectorNormalize(&v);
10905 v *= 30.0f;
10906 child_handle = Obj_Create(OBJ_ROBOT, child_id, room, &pos, &orient, parent, &v);
10907 }
10908
10909 memory->explode = true;
10910
10911 } break;
10912 case EVT_INTERVAL: {
10913 if (memory && memory->explode) {
10914 ObjectRemove(data->me_handle);
10915 }
10916 } break;
10917 }
10918
10919 return CONTINUE_CHAIN | CONTINUE_DEFAULT;
10920 }
10921
10922 void BettyScript::DoInit(int me) {
10923 tOSIRISMEMCHUNK ch;
10924 ch.id = 4;
10925 ch.size = sizeof(tBettyInfo);
10926 ch.my_id.type = OBJECT_SCRIPT;
10927 ch.my_id.objhandle = me;
10928
10929 memory = (tBettyInfo *)Scrpt_MemAlloc(&ch);
10930
10931 memory->explode = false;
10932 memory->lasttime = 0;
10933 }
10934
10935 int16_t BettyScript::CallEvent(int event, tOSIRISEventInfo *data) {
10936 switch (event) {
10937 case EVT_MEMRESTORE: {
10938 memory = (tBettyInfo *)data->evt_memrestore.memory_ptr;
10939 } break;
10940
10941 case EVT_CREATED: {
10942 // create our memory
10943 DoInit(data->me_handle);
10944
10945 int parent, type;
10946 vector vel;
10947
10948 parent = GetObjectParent(data->me_handle);
10949
10950 if (parent != OBJECT_HANDLE_NONE) {
10951 // Give it velocity
10952 Obj_Value(parent, VF_GET, OBJV_V_VELOCITY, &vel);
10953 vel.x = vel.x * -0.5;
10954 vel.y = vel.y * -0.5;
10955 vel.z = vel.z * -0.5;
10956 Obj_Value(data->me_handle, VF_SET, OBJV_V_VELOCITY, &vel);
10957 }
10958
10959 tOSIRISTIMER timer_info;
10960 timer_info.flags = 0;
10961 timer_info.repeat_count = 0;
10962 timer_info.object_handle = data->me_handle;
10963 timer_info.object_handle_detonator = OBJECT_HANDLE_NONE;
10964 timer_info.timer_interval = 15.0f;
10965 timer_info.id = CREATE_TIMER_ID(0x1A);
10966 Scrpt_CreateTimer(&timer_info);
10967
10968 } break;
10969 case EVT_COLLIDE: {
10970 float velmag;
10971 vector vel;
10972
10973 if (GetObjectType(data->evt_collide.it_handle) == OBJ_PLAYER) {
10974
10975 if (!memory->explode) {
10976 memory->explode = true;
10977
10978 matrix orient;
10979 Obj_Value(data->me_handle, VF_GET, OBJV_M_ORIENT, &orient);
10980
10981 Obj_Value(data->me_handle, VF_GET, OBJV_V_VELOCITY, &vel);
10982 velmag = vm_GetMagnitude(&vel);
10983 velmag = velmag / 4;
10984
10985 int room;
10986 vector pos;
10987 int weapon_id;
10988
10989 Obj_Value(data->me_handle, VF_GET, OBJV_I_ROOMNUM, &room);
10990 Obj_Value(data->me_handle, VF_GET, OBJV_V_POS, &pos);
10991
10992 weapon_id = Wpn_FindID("TubbsHitBlast");
10993 Obj_Create(OBJ_WEAPON, weapon_id, room, &pos, &orient, GetObjectParent(data->me_handle));
10994
10995 ObjectDamage(data->evt_collide.it_handle, velmag, data->me_handle);
10996 }
10997 }
10998 } break;
10999 case EVT_INTERVAL: {
11000 float time, velmag, scale;
11001 vector vel;
11002
11003 time = data->evt_interval.game_time;
11004
11005 if (time > memory->lasttime + 0.10) {
11006 // check to see if we need to limit speed
11007 memory->lasttime = time;
11008 Obj_Value(data->me_handle, VF_GET, OBJV_V_VELOCITY, &vel);
11009 velmag = vm_GetMagnitude(&vel);
11010
11011 if (velmag > 120.0f) {
11012 // limit the velocity
11013 scale = 120.0f / velmag;
11014 vel.x = scale * vel.x;
11015 vel.y = scale * vel.y;
11016 vel.z = scale * vel.z;
11017 Obj_Value(data->me_handle, VF_SET, OBJV_V_VELOCITY, &vel);
11018 }
11019 }
11020
11021 if (memory && memory->explode) {
11022 ObjectRemove(data->me_handle);
11023 }
11024 } break;
11025
11026 case EVT_TIMER: {
11027 float amount;
11028 amount = GetObjectShields(data->me_handle) + 10.0f;
11029 ObjectDamage(data->me_handle, amount);
11030 } break;
11031 }
11032
11033 return CONTINUE_CHAIN | CONTINUE_DEFAULT;
11034 }
11035
11036 //------------------
11037 // Chaff class
11038 //------------------
11039
11040 void ChaffScript::DoInit(int handle) {
11041 vector vel, v, pos;
11042
11043 int count, chaffcount;
11044 int chunk_id, room;
11045 int parent, ch, type;
11046
11047 // Allocate the memory for the script
11048 tOSIRISMEMCHUNK mem;
11049 mem.id = 4;
11050 mem.size = sizeof(tChaffInfo);
11051 mem.my_id.type = OBJECT_SCRIPT;
11052 mem.my_id.objhandle = handle;
11053
11054 memory = (tChaffInfo *)Scrpt_MemAlloc(&mem);
11055 memory->killme = false;
11056
11057 parent = GetObjectParent(handle);
11058 chunk_id = Obj_FindID("ChaffChunk");
11059
11060 if (parent != OBJECT_HANDLE_NONE && chunk_id != -1) {
11061 matrix orient;
11062 Obj_Value(handle, VF_GET, OBJV_M_ORIENT, &orient);
11063
11064 Obj_Value(parent, VF_GET, OBJV_V_VELOCITY, &vel);
11065 Obj_Value(handle, VF_GET, OBJV_I_ROOMNUM, &room);
11066 Obj_Value(handle, VF_GET, OBJV_V_POS, &pos);
11067
11068 chaffcount = 10;
11069 for (count = 0; count < chaffcount; count++) {
11070 v = -vel;
11071 v.x += (rand() % 30) - 15;
11072 v.y += (rand() % 30) - 15;
11073 v.z += (rand() % 30) - 15;
11074
11075 ch = Obj_Create(OBJ_ROBOT, chunk_id, room, &pos, &orient, parent, &v);
11076 }
11077
11078 type = GetObjectType(parent);
11079 if (type == OBJ_PLAYER || type == OBJ_GHOST) {
11080 int sound_id = Sound_FindId("Drop bomb");
11081 if (sound_id >= 0) {
11082 Sound_Play3d(parent, sound_id);
11083 }
11084 }
11085 }
11086
11087 memory->killme = true;
11088 }
11089
11090 void ChaffScript::DoInterval(int handle) {
11091 if (memory && memory->killme) {
11092 ObjectRemove(handle);
11093 }
11094 }
11095
11096 int16_t ChaffScript::CallEvent(int event, tOSIRISEventInfo *data) {
11097 switch (event) {
11098 case EVT_MEMRESTORE: {
11099 memory = (tChaffInfo *)data->evt_memrestore.memory_ptr;
11100 } break;
11101 case EVT_CREATED: {
11102 DoInit(data->me_handle);
11103 } break;
11104 case EVT_INTERVAL: {
11105 DoInterval(data->me_handle);
11106 } break;
11107 }
11108 return CONTINUE_CHAIN | CONTINUE_DEFAULT;
11109 }
11110
11111 void ChaffChunkScript::DoInit(int handle) {
11112 // Allocate the memory for the script
11113 tOSIRISMEMCHUNK ch;
11114 ch.id = 4;
11115 ch.size = sizeof(tChaffChunkInfo);
11116 ch.my_id.type = OBJECT_SCRIPT;
11117 ch.my_id.objhandle = handle;
11118
11119 memory = (tChaffChunkInfo *)Scrpt_MemAlloc(&ch);
11120 memory->killme = false;
11121 memory->lifeleft = 30.0f;
11122
11123 int parent;
11124 vector vel;
11125 parent = GetObjectParent(handle);
11126
11127 if (parent != OBJECT_HANDLE_NONE) {
11128 Obj_Value(parent, VF_GET, OBJV_V_VELOCITY, &vel);
11129 Obj_Value(handle, VF_SET, OBJV_V_VELOCITY, &vel);
11130 }
11131 }
11132
11133 void ChaffChunkScript::DoInterval(int handle, float frametime) {
11134 if (!memory)
11135 return;
11136
11137 memory->lifeleft -= frametime;
11138 if (!memory->killme && memory->lifeleft < 0) {
11139 int weapon_id;
11140 matrix orient;
11141
11142 memory->killme = true;
11143
11144 Obj_Value(handle, VF_GET, OBJV_M_ORIENT, &orient);
11145
11146 int room;
11147 vector pos;
11148
11149 Obj_Value(handle, VF_GET, OBJV_I_ROOMNUM, &room);
11150 Obj_Value(handle, VF_GET, OBJV_V_POS, &pos);
11151
11152 weapon_id = Wpn_FindID("ChaffSpark");
11153
11154 int parent = GetObjectParent(handle);
11155
11156 Obj_Create(OBJ_WEAPON, weapon_id, room, &pos, &orient, parent);
11157 }
11158
11159 if (memory->killme) {
11160 ObjectRemove(handle);
11161 }
11162 }
11163
11164 void ChaffChunkScript::DoCollide(tOSIRISEventInfo *data) {
11165 int weapon_id;
11166 matrix orient;
11167
11168 if (!memory->killme) {
11169 memory->killme = true;
11170
11171 Obj_Value(data->me_handle, VF_GET, OBJV_M_ORIENT, &orient);
11172
11173 int room;
11174 vector pos;
11175
11176 Obj_Value(data->me_handle, VF_GET, OBJV_I_ROOMNUM, &room);
11177 Obj_Value(data->me_handle, VF_GET, OBJV_V_POS, &pos);
11178
11179 weapon_id = Wpn_FindID("ChaffSpark");
11180
11181 int parent = GetObjectParent(data->me_handle);
11182
11183 Obj_Create(OBJ_WEAPON, weapon_id, room, &pos, &orient, parent);
11184 }
11185 }
11186
11187 int16_t ChaffChunkScript::CallEvent(int event, tOSIRISEventInfo *data) {
11188 switch (event) {
11189 case EVT_MEMRESTORE: {
11190 memory = (tChaffChunkInfo *)data->evt_memrestore.memory_ptr;
11191 } break;
11192 case EVT_CREATED: {
11193 DoInit(data->me_handle);
11194 } break;
11195 case EVT_INTERVAL: {
11196 DoInterval(data->me_handle, data->evt_interval.frame_time);
11197 } break;
11198 case EVT_COLLIDE: {
11199 DoCollide(data);
11200 } break;
11201 case EVT_AI_INIT: {
11202 Obj_SetCustomAnim(data->me_handle, 0.0f, 4.0f, 1.0f, 0);
11203 } break;
11204 }
11205 return CONTINUE_CHAIN | CONTINUE_DEFAULT;
11206 }
11207
11208 //------------------
11209 // ProxMine class
11210 //------------------
11211
11212 void ProxMine::DoInit(int me) {
11213 int parent = GetObjectParent(me);
11214 int sound_id = Sound_FindId("Drop bomb");
11215 if (sound_id >= 0) {
11216 Sound_Play3d(parent, sound_id);
11217 }
11218 }
11219
11220 void ProxMine::DoCollide(int me) {
11221 int room;
11222 vector pos;
11223 int weapon_id;
11224
11225 Obj_Value(me, VF_GET, OBJV_I_ROOMNUM, &room);
11226 Obj_Value(me, VF_GET, OBJV_V_POS, &pos);
11227
11228 weapon_id = Wpn_FindID("TubbsHitBlast");
11229 Obj_Create(OBJ_WEAPON, weapon_id, room, &pos, NULL, me);
11230
11231 msafe_struct mo;
11232 mo.objhandle = me;
11233
11234 MSafe_CallFunction(MSAFE_OBJECT_REMOVE, &mo);
11235 }
11236
11237 int16_t ProxMine::CallEvent(int event, tOSIRISEventInfo *data) {
11238 switch (event) {
11239 case EVT_AI_INIT:
11240 DoInit(data->me_handle);
11241 break;
11242 case EVT_COLLIDE:
11243 DoCollide(data->me_handle);
11244 break;
11245 }
11246 return CONTINUE_CHAIN | CONTINUE_DEFAULT;
11247 }
11248
11249 //------------------
11250 // Gunboy class
11251 //------------------
11252 int16_t Gunboy::CallEvent(int event, tOSIRISEventInfo *data) {
11253 switch (event) {
11254 case EVT_CREATED: {
11255 int parent = GetObjectParent(data->me_handle);
11256 int sound_id = Sound_FindId("Drop bomb");
11257 if (sound_id >= 0) {
11258 Sound_Play3d(parent, sound_id, 1);
11259 }
11260
11261 tOSIRISTIMER timer_info;
11262 timer_info.flags = 0;
11263 timer_info.repeat_count = 0;
11264 timer_info.object_handle = data->me_handle;
11265 timer_info.object_handle_detonator = OBJECT_HANDLE_NONE;
11266 timer_info.timer_interval = 160.0f;
11267 timer_info.id = CREATE_TIMER_ID(0x2D);
11268 Scrpt_CreateTimer(&timer_info);
11269
11270 } break;
11271
11272 case EVT_TIMER: {
11273 float amount;
11274 amount = GetObjectShields(data->me_handle) + 60.0f;
11275 ObjectDamage(data->me_handle, amount);
11276 } break;
11277 }
11278
11279 return CONTINUE_CHAIN | CONTINUE_DEFAULT;
11280 }