| 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 | int String_table_size = 0; |
| 46 | 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 | |
| 58 | static void PortalBreakGlass(int portalnum, int roomnum); |
| 59 | // Returns the new child's handle |
| 60 | static int CreateAndAttach(int me, const char *child_name, uint8_t child_type, char parent_ap, char child_ap, |
| 61 | bool f_aligned = true, bool f_set_parent = false); |
| 62 | static float Obj_GetObjDist(int me, int it, bool f_sub_rads); |
| 63 | |
| 64 | void PortalBreakGlass(int portalnum, int roomnum) { |
| 65 | msafe_struct mstruct; |
| 66 | |
| 67 | mstruct.roomnum = roomnum; |
| 68 | mstruct.portalnum = portalnum; |
| 69 | |
| 70 | MSafe_CallFunction(MSAFE_ROOM_BREAK_GLASS, &mstruct); |
| 71 | } |
| 72 | |
| 73 | // Returns the new child's handle |
| 74 | int CreateAndAttach(int me, const char *child_name, uint8_t child_type, char parent_ap, char child_ap, bool f_aligned, |
| 75 | bool f_set_parent) { |
| 76 | int child_handle = OBJECT_HANDLE_NONE; |
| 77 | int child_id = Obj_FindID(child_name); |
| 78 | msafe_struct m; |
| 79 | m.objhandle = me; |
| 80 | MSafe_GetValue(MSAFE_OBJECT_POS, &m); |
| 81 | MSafe_GetValue(MSAFE_OBJECT_ROOMNUM, &m); |
| 82 | |
| 83 | if (child_id >= 0) { |
| 84 | int parent; |
| 85 | if (f_set_parent) |
| 86 | parent = me; |
| 87 | else |
| 88 | parent = OBJECT_HANDLE_NONE; |
| 89 | |
| 90 | child_handle = Obj_Create(child_type, child_id, m.roomnum, &m.pos, NULL, parent); |
| 91 | if (child_handle != OBJECT_HANDLE_NONE) { |
| 92 | if (!Obj_AttachObjectAP(me, parent_ap, child_handle, child_ap, f_aligned)) { |
| 93 | // chrishack (we need a way to instantly kill scripted objects) |
| 94 | } |
| 95 | } |
| 96 | } |
| 97 | |
| 98 | return child_handle; |
| 99 | } |
| 100 | |
| 101 | // ========================== |
| 102 | // Script class definitions// |
| 103 | // ========================== |
| 104 | #define NUM_IDS 6 // maximum number of IDs |
| 105 | |
| 106 | #define ID_MERCENDBOSS 0 // Mercenary End Boss |
| 107 | #define ID_GUN 1 // Mercenary Mino Boss for level 6 |
| 108 | #define ID_CASING 2 |
| 109 | #define ID_HANGLIGHT 3 // Mercenary Hanging Light |
| 110 | #define ID_COMBWALLHIT 4 // Wall hit for purple big ass gun |
| 111 | #define ID_DROPTARGET 5 |
| 112 | |
| 113 | struct tScriptInfo { |
| 114 | int id; |
| 115 | const char *name; |
| 116 | }; |
| 117 | |
| 118 | tScriptInfo ScriptInfo[NUM_IDS] = {{ID_MERCENDBOSS, "MercEndBoss"}, {ID_GUN, "Gun"}, |
| 119 | {ID_CASING, "Casing"}, {ID_HANGLIGHT, "HangLight"}, |
| 120 | {ID_COMBWALLHIT, "CombWallHit"}, {ID_DROPTARGET, "DropTarget"}}; |
| 121 | |
| 122 | static int aigame_mod_id; |
| 123 | // use this macro to create unique timer IDs |
| 124 | #define CREATE_TIMER_ID(id) ((aigame_mod_id << 16) | (id)) |
| 125 | |
| 126 | class BaseObjScript { |
| 127 | public: |
| 128 | BaseObjScript(); |
| 129 | ~BaseObjScript(); |
| 130 | virtual int16_t CallEvent(int event, tOSIRISEventInfo *data); |
| 131 | }; |
| 132 | |
| 133 | struct tShieldOrbInfo { |
| 134 | int hitcount; |
| 135 | }; |
| 136 | |
| 137 | //------------------ |
| 138 | // CombWallHit class |
| 139 | //------------------ |
| 140 | |
| 141 | struct combwallhit_data { |
| 142 | float time_left; |
| 143 | }; |
| 144 | |
| 145 | class CombWallHit : public BaseObjScript { |
| 146 | private: |
| 147 | combwallhit_data *memory; |
| 148 | |
| 149 | public: |
| 150 | CombWallHit() {} |
| 151 | int16_t CallEvent(int event, tOSIRISEventInfo *data); |
| 152 | }; |
| 153 | |
| 154 | //------------------ |
| 155 | // DropTarget class |
| 156 | //------------------ |
| 157 | |
| 158 | struct droptarget_data { |
| 159 | float time_left; |
| 160 | float last_set_time; |
| 161 | }; |
| 162 | |
| 163 | class DropTarget : public BaseObjScript { |
| 164 | private: |
| 165 | droptarget_data *memory; |
| 166 | |
| 167 | public: |
| 168 | DropTarget() {} |
| 169 | int16_t CallEvent(int event, tOSIRISEventInfo *data); |
| 170 | }; |
| 171 | |
| 172 | //------------------ |
| 173 | // Gun class |
| 174 | //------------------ |
| 175 | |
| 176 | struct gun_data { |
| 177 | int shell_id; |
| 178 | bool f_fire; |
| 179 | }; |
| 180 | |
| 181 | class Gun : public BaseObjScript { |
| 182 | gun_data *memory; |
| 183 | |
| 184 | public: |
| 185 | Gun() {} |
| 186 | int16_t CallEvent(int event, tOSIRISEventInfo *data); |
| 187 | }; |
| 188 | |
| 189 | //------------------ |
| 190 | // Casing class |
| 191 | //------------------ |
| 192 | |
| 193 | struct casing_data { |
| 194 | float time_left; |
| 195 | }; |
| 196 | |
| 197 | class Casing : public BaseObjScript { |
| 198 | private: |
| 199 | casing_data *memory; |
| 200 | |
| 201 | public: |
| 202 | Casing() {} |
| 203 | int16_t CallEvent(int event, tOSIRISEventInfo *data); |
| 204 | }; |
| 205 | |
| 206 | //------------------ |
| 207 | // MercEndBoss class |
| 208 | //------------------ |
| 209 | |
| 210 | #define MERCENDBOSS_WAIT 0 |
| 211 | #define MERCENDBOSS_INTRO 1 |
| 212 | #define MERCENDBOSS_MATTER 2 |
| 213 | #define MERCENDBOSS_ENERGY 3 |
| 214 | #define MERCENDBOSS_DEATH_BLOSSUM 4 |
| 215 | #define MERCENDBOSS_DEATH 5 |
| 216 | |
| 217 | // Mercenary End Boss Unique Goal IDs |
| 218 | #define MEB_TURN_TOWARDS_CAMERA 0x00010001 |
| 219 | |
| 220 | struct mercendboss_data { |
| 221 | int flags; |
| 222 | char mode; |
| 223 | char next_mode; |
| 224 | int turret_object; |
| 225 | |
| 226 | bool f_target_ghost; |
| 227 | float time_till_fire; |
| 228 | |
| 229 | int wallhit_id; |
| 230 | |
| 231 | bool f_oriented; |
| 232 | |
| 233 | float last_frame; |
| 234 | |
| 235 | int laser_sound; |
| 236 | float laser_time_left; |
| 237 | |
| 238 | bool f_sub_super; |
| 239 | float mode_time; |
| 240 | float sub_mode_time_left; |
| 241 | |
| 242 | float last_spark_time; |
| 243 | |
| 244 | float time_to_next_random_sound; |
| 245 | |
| 246 | int emitter[2]; |
| 247 | int camera; |
| 248 | int combine_object; |
| 249 | }; |
| 250 | |
| 251 | class MercEndBoss : public BaseObjScript { |
| 252 | private: |
| 253 | mercendboss_data *memory; |
| 254 | void DoInit(int me); |
| 255 | void DoFrame(int me); |
| 256 | bool DoNotify(int me_handle, tOSIRISEventInfo *data); |
| 257 | void SetMode(int me, char mode); |
| 258 | void SetSuper(int obj, bool f_super); |
| 259 | float GetSubModeTime(void); |
| 260 | void PlayRandomSound(int me); |
| 261 | |
| 262 | public: |
| 263 | MercEndBoss() {} |
| 264 | int16_t CallEvent(int event, tOSIRISEventInfo *data); |
| 265 | }; |
| 266 | |
| 267 | //------------------ |
| 268 | // HangLight class |
| 269 | //------------------ |
| 270 | |
| 271 | class HangLight : public BaseObjScript { |
| 272 | private: |
| 273 | void DoInit(int me); |
| 274 | |
| 275 | public: |
| 276 | HangLight() {} |
| 277 | int16_t CallEvent(int event, tOSIRISEventInfo *data); |
| 278 | }; |
| 279 | |
| 280 | //---------------- |
| 281 | // Standard stuff |
| 282 | //---------------- |
| 283 | |
| 284 | // SaveRestoreState |
| 285 | // Purpose: |
| 286 | // This function is called when Descent 3 is saving or restoring the game state. In this function |
| 287 | // you should save/restore any global data that you want preserved through load/save (which includes |
| 288 | // demos). You must be very careful with this function, corrupting the file (reading or writing too |
| 289 | // much or too little) may be hazardous to the game (possibly making it impossible to restore the |
| 290 | // state). It would be best to use version information to keep older versions of saved states still |
| 291 | // able to be used. IT IS VERY IMPORTANT WHEN SAVING THE STATE TO RETURN THE NUMBER OF _BYTES_ WROTE |
| 292 | // TO THE FILE. When restoring the data, the return value is ignored. saving_state is 1 when you should |
| 293 | // write data to the file_ptr, 0 when you should read in the data. |
| 294 | int STDCALL SaveRestoreState(void *file_ptr, uint8_t saving_state) { return 0; } |
| 295 | |
| 296 | char STDCALL InitializeDLL(tOSIRISModuleInit *func_list) { |
| 297 | osicommon_Initialize((tOSIRISModuleInit *)func_list); |
| 298 | if (func_list->game_checksum != CHECKSUM) { |
| 299 | mprintf(0, "Game-Checksum FAIL!!! (%ul!=%ul)\n", func_list->game_checksum, CHECKSUM); |
| 300 | mprintf(0, "RECOMPILE YOUR SCRIPTS!!!\n"); |
| 301 | return 0; |
| 302 | } |
| 303 | aigame_mod_id = func_list->module_identifier; |
| 304 | String_table_size = func_list->string_count; |
| 305 | String_table = func_list->string_table; |
| 306 | |
| 307 | return 1; |
| 308 | } |
| 309 | |
| 310 | void STDCALL ShutdownDLL(void) {} |
| 311 | |
| 312 | int STDCALL GetGOScriptID(const char *name, uint8_t isdoor) { |
| 313 | for (int i = 0; i < NUM_IDS; i++) { |
| 314 | if (!stricmp(name, ScriptInfo[i].name)) { |
| 315 | return ScriptInfo[i].id; |
| 316 | } |
| 317 | } |
| 318 | return -1; |
| 319 | } |
| 320 | |
| 321 | void STDCALLPTR CreateInstance(int id) { |
| 322 | switch (id) { |
| 323 | case ID_MERCENDBOSS: |
| 324 | return new MercEndBoss; |
| 325 | break; |
| 326 | case ID_GUN: |
| 327 | return new Gun; |
| 328 | break; |
| 329 | case ID_CASING: |
| 330 | return new Casing; |
| 331 | break; |
| 332 | case ID_HANGLIGHT: |
| 333 | return new HangLight; |
| 334 | break; |
| 335 | case ID_COMBWALLHIT: |
| 336 | return new CombWallHit; |
| 337 | break; |
| 338 | case ID_DROPTARGET: |
| 339 | return new DropTarget; |
| 340 | break; |
| 341 | default: |
| 342 | mprintf(0, "SCRIPT: Illegal ID (%d)\n", id); |
| 343 | break; |
| 344 | }; |
| 345 | return NULL; |
| 346 | } |
| 347 | |
| 348 | void STDCALL DestroyInstance(int id, void *ptr) { |
| 349 | switch (id) { |
| 350 | case ID_MERCENDBOSS: |
| 351 | delete ((MercEndBoss *)ptr); |
| 352 | break; |
| 353 | case ID_GUN: |
| 354 | delete ((Gun *)ptr); |
| 355 | break; |
| 356 | case ID_CASING: |
| 357 | delete ((Casing *)ptr); |
| 358 | break; |
| 359 | case ID_HANGLIGHT: |
| 360 | delete ((HangLight *)ptr); |
| 361 | break; |
| 362 | case ID_COMBWALLHIT: |
| 363 | delete ((CombWallHit *)ptr); |
| 364 | break; |
| 365 | case ID_DROPTARGET: |
| 366 | delete ((DropTarget *)ptr); |
| 367 | break; |
| 368 | default: |
| 369 | mprintf(0, "SCRIPT: Illegal ID (%d)\n", id); |
| 370 | break; |
| 371 | } |
| 372 | } |
| 373 | |
| 374 | int16_t STDCALL CallInstanceEvent(int id, void *ptr, int event, tOSIRISEventInfo *data) { |
| 375 | return ((BaseObjScript *)ptr)->CallEvent(event, data); |
| 376 | } |
| 377 | |
| 378 | //============================================ |
| 379 | // Functions |
| 380 | //============================================ |
| 381 | |
| 382 | float Obj_GetObjDist(int me, int it, bool f_sub_rads) { |
| 383 | vector me_pos; |
| 384 | vector it_pos; |
| 385 | float dist; |
| 386 | |
| 387 | Obj_Value(me, VF_GET, OBJV_V_POS, &me_pos); |
| 388 | Obj_Value(it, VF_GET, OBJV_V_POS, &it_pos); |
| 389 | |
| 390 | dist = vm_VectorDistance(&me_pos, &it_pos); |
| 391 | |
| 392 | if (f_sub_rads) { |
| 393 | float size; |
| 394 | |
| 395 | Obj_Value(me, VF_GET, OBJV_F_SIZE, &size); |
| 396 | dist -= size; |
| 397 | Obj_Value(it, VF_GET, OBJV_F_SIZE, &size); |
| 398 | dist -= size; |
| 399 | } |
| 400 | |
| 401 | return dist; |
| 402 | } |
| 403 | |
| 404 | static inline void AIClearNonHPGoals(int handle) { |
| 405 | int i; |
| 406 | |
| 407 | for (i = 0; i < MAX_GOALS; i++) { |
| 408 | if (i != 3) |
| 409 | AI_ClearGoal(handle, i); |
| 410 | } |
| 411 | } |
| 412 | |
| 413 | static inline bool IsGoalFinishedNotify(int index) { |
| 414 | return (index == AIN_GOAL_COMPLETE || index == AIN_GOAL_INVALID || index == AIN_GOAL_FAIL || index == AIN_GOAL_ERROR); |
| 415 | } |
| 416 | |
| 417 | //============================================ |
| 418 | // Script Implementation |
| 419 | //============================================ |
| 420 | BaseObjScript::BaseObjScript() {} |
| 421 | |
| 422 | BaseObjScript::~BaseObjScript() {} |
| 423 | |
| 424 | int16_t BaseObjScript::CallEvent(int event, tOSIRISEventInfo *data) { return CONTINUE_CHAIN | CONTINUE_DEFAULT; } |
| 425 | |
| 426 | //------------------ |
| 427 | // MercEndBoss class |
| 428 | //------------------ |
| 429 | |
| 430 | #define MATTER_TIME 10.0f |
| 431 | #define MATTER_SUPER_TIME 10.0f |
| 432 | #define ENERGY_TIME 20.0f |
| 433 | #define ENERGY_SUPER_TIME 10.0f |
| 434 | |
| 435 | float MercEndBoss::GetSubModeTime(void) { |
| 436 | if (memory->mode == MERCENDBOSS_MATTER) { |
| 437 | if (memory->f_sub_super) { |
| 438 | return MATTER_TIME; |
| 439 | } else { |
| 440 | return MATTER_SUPER_TIME; |
| 441 | } |
| 442 | } else { |
| 443 | if (memory->f_sub_super) { |
| 444 | return ENERGY_SUPER_TIME; |
| 445 | } else { |
| 446 | return ENERGY_TIME; |
| 447 | } |
| 448 | } |
| 449 | } |
| 450 | |
| 451 | void MercEndBoss::SetSuper(int obj, bool f_super) { |
| 452 | int me = obj; |
| 453 | memory->f_sub_super = f_super; |
| 454 | |
| 455 | if (memory->mode == MERCENDBOSS_MATTER) { |
| 456 | if (f_super) { |
| 457 | Obj_SetCustomAnim(memory->turret_object, 0.0f, 5.0f, 0.5f, AIAF_LOOPING, Sound_FindId("MercFBWinding"), AS_ALERT); |
| 458 | |
| 459 | int flags = AIF_FIRE; |
| 460 | AI_Value(me, VF_CLEAR_FLAGS, AIV_I_FLAGS, &flags); |
| 461 | AI_Value(memory->turret_object, VF_SET_FLAGS, AIV_I_FLAGS, &flags); |
| 462 | |
| 463 | // flags = DWBF_ENABLED; |
| 464 | // Obj_WBValue(me, 0, VF_CLEAR_FLAGS, WBV_I_DYNAMIC_FLAGS, &flags); |
| 465 | // Obj_WBValue(me, 4, VF_CLEAR_FLAGS, WBV_I_DYNAMIC_FLAGS, &flags); |
| 466 | } else { |
| 467 | Obj_SetCustomAnim(memory->turret_object, 0.0f, 0.0f, 0.5f, AIAF_NOTIFY, -1, AS_ALERT); |
| 468 | |
| 469 | int flags = AIF_FIRE; |
| 470 | AI_Value(me, VF_SET_FLAGS, AIV_I_FLAGS, &flags); |
| 471 | AI_Value(memory->turret_object, VF_CLEAR_FLAGS, AIV_I_FLAGS, &flags); |
| 472 | |
| 473 | // flags = DWBF_ENABLED; |
| 474 | // Obj_WBValue(me, 0, VF_SET_FLAGS, WBV_I_DYNAMIC_FLAGS, &flags); |
| 475 | // Obj_WBValue(me, 4, VF_SET_FLAGS, WBV_I_DYNAMIC_FLAGS, &flags); |
| 476 | } |
| 477 | } else if (memory->mode == MERCENDBOSS_ENERGY) { |
| 478 | // int flags = DWBF_ENABLED; |
| 479 | // |
| 480 | // Obj_WBValue(me, 0, VF_CLEAR_FLAGS, WBV_I_DYNAMIC_FLAGS, &flags); |
| 481 | // Obj_WBValue(me, 4, VF_CLEAR_FLAGS, WBV_I_DYNAMIC_FLAGS, &flags); |
| 482 | |
| 483 | int flags = AIF_FIRE; |
| 484 | AI_Value(me, VF_CLEAR_FLAGS, AIV_I_FLAGS, &flags); |
| 485 | |
| 486 | if (f_super) { |
| 487 | aObjGhostSet(0, memory->combine_object); |
| 488 | aObjGhostSet(0, memory->emitter[0]); |
| 489 | aObjGhostSet(0, memory->emitter[1]); |
| 490 | |
| 491 | Sound_Play3d(me, Sound_FindId("MercFBBeamCanon")); |
| 492 | |
| 493 | aLightningCreate(memory->emitter[0], memory->combine_object, ENERGY_SUPER_TIME, 3.0f, 1, |
| 494 | Scrpt_FindTextureName("endbossbeamweapon2"), 1.0f, 1, 255, 255, 255, true); |
| 495 | aLightningCreate(memory->emitter[0], memory->combine_object, ENERGY_SUPER_TIME, 2.8f, 1, |
| 496 | Scrpt_FindTextureName("endbossbeamweapon2"), 1.95f, 1, 255, 255, 255, true); |
| 497 | |
| 498 | aLightningCreate(memory->emitter[1], memory->combine_object, ENERGY_SUPER_TIME, 3.0f, 1, |
| 499 | Scrpt_FindTextureName("endbossbeamweapon2"), 1.0f, 1, 255, 255, 255, true); |
| 500 | aLightningCreate(memory->emitter[1], memory->combine_object, ENERGY_SUPER_TIME, 2.8f, 1, |
| 501 | Scrpt_FindTextureName("endbossbeamweapon2"), 1.96f, 1, 255, 255, 255, true); |
| 502 | |
| 503 | aLightningCreate(memory->turret_object, memory->combine_object, ENERGY_SUPER_TIME, 3.0f, 1, |
| 504 | Scrpt_FindTextureName("endbossbeamweapon2"), 1.0f, 1, 255, 255, 255, true); |
| 505 | aLightningCreate(memory->turret_object, memory->combine_object, ENERGY_SUPER_TIME, 2.8f, 1, |
| 506 | Scrpt_FindTextureName("endbossbeamweapon2"), 1.96f, 1, 255, 255, 255, true); |
| 507 | |
| 508 | float max_speed = 8500.0f; |
| 509 | AI_Value(me, VF_SET, AIV_F_MAX_TURN_RATE, &max_speed); |
| 510 | |
| 511 | int flags = AIF_FIRE; |
| 512 | AI_Value(memory->turret_object, VF_CLEAR_FLAGS, AIV_I_FLAGS, &flags); |
| 513 | } else { |
| 514 | aObjGhostSet(1, memory->combine_object); |
| 515 | aObjGhostSet(1, memory->emitter[0]); |
| 516 | aObjGhostSet(1, memory->emitter[1]); |
| 517 | |
| 518 | int flags = AIF_FIRE; |
| 519 | AI_Value(memory->turret_object, VF_SET_FLAGS, AIV_I_FLAGS, &flags); |
| 520 | |
| 521 | float max_speed = 10100.0f; |
| 522 | AI_Value(me, VF_SET, AIV_F_MAX_TURN_RATE, &max_speed); |
| 523 | } |
| 524 | } |
| 525 | |
| 526 | memory->sub_mode_time_left = GetSubModeTime(); |
| 527 | } |
| 528 | |
| 529 | #define DEATH_ROT_ACC 5000.0f |
| 530 | |
| 531 | bool MercEndBoss::DoNotify(int me, tOSIRISEventInfo *data) { |
| 532 | switch (memory->mode) { |
| 533 | case MERCENDBOSS_WAIT: { |
| 534 | if (data->evt_ai_notify.notify_type == AIN_MOVIE_START) { |
| 535 | SetMode(me, MERCENDBOSS_INTRO); |
| 536 | } |
| 537 | } break; |
| 538 | case MERCENDBOSS_INTRO: { |
| 539 | switch (data->evt_ai_notify.notify_type) { |
| 540 | case AIN_MOVIE_END: |
| 541 | SetMode(me, MERCENDBOSS_MATTER); |
| 542 | break; |
| 543 | case AIN_SCRIPTED_ORIENT: { |
| 544 | vector uvec = {0.0f, 1.0f, 0.0f}; |
| 545 | vector fvec = {-1.0f, 0.0f, 0.0f}; |
| 546 | if (AI_TurnTowardsVectors(me, &fvec, &uvec)) { |
| 547 | memory->f_oriented = true; |
| 548 | } |
| 549 | } break; |
| 550 | case AIN_SCRIPTED_GOAL: |
| 551 | vector zv = {0.0f, 0.0f, 0.0f}; |
| 552 | AI_Value(me, VF_SET, AIV_V_MOVEMENT_DIR, &zv); |
| 553 | break; |
| 554 | } |
| 555 | } break; |
| 556 | case MERCENDBOSS_DEATH: { |
| 557 | // NOTE: I am also doing the rotational stuff here... So, no need to make a seperate AIN_SCRIPTED_ORIENT event |
| 558 | if (data->evt_ai_notify.goal_num == 0 && data->evt_ai_notify.notify_type == AIN_SCRIPTED_GOAL) { |
| 559 | vector rvel; |
| 560 | Obj_Value(me, VF_GET, OBJV_V_ROTVELOCITY, &rvel); |
| 561 | |
| 562 | rvel.x -= 0.1f * DEATH_ROT_ACC * Game_GetFrameTime(); |
| 563 | rvel.y -= DEATH_ROT_ACC * Game_GetFrameTime(); |
| 564 | rvel.z += 0.3f * DEATH_ROT_ACC * Game_GetFrameTime(); |
| 565 | |
| 566 | Obj_Value(me, VF_SET, OBJV_V_ROTVELOCITY, &rvel); |
| 567 | |
| 568 | vector dir = Zero_vector; |
| 569 | AI_Value(me, VF_SET, AIV_V_MOVEMENT_DIR, &dir); |
| 570 | } |
| 571 | } |
| 572 | } |
| 573 | |
| 574 | return true; |
| 575 | } |
| 576 | |
| 577 | void MercEndBoss::SetMode(int me, char mode) { |
| 578 | AI_SetType(me, AIT_EVADER1); |
| 579 | memory->mode_time = 0.0f; |
| 580 | |
| 581 | if (memory->mode == MERCENDBOSS_INTRO) { |
| 582 | mprintf(0, "Here end of intro\n"); |
| 583 | int flags = DWBF_ENABLED; |
| 584 | Obj_WBValue(me, 0, VF_SET_FLAGS, WBV_I_DYNAMIC_FLAGS, &flags); |
| 585 | Obj_WBValue(me, 4, VF_SET_FLAGS, WBV_I_DYNAMIC_FLAGS, &flags); |
| 586 | |
| 587 | // The (AIF_DETERMINE_TARGET | AIF_AIM) flags get set here to make absolute sure that no timing issues mess things |
| 588 | // up |
| 589 | flags = AIF_FIRE | AIF_DODGE | AIF_DETERMINE_TARGET | AIF_AIM; |
| 590 | AI_Value(me, VF_SET_FLAGS, AIV_I_FLAGS, &flags); |
| 591 | |
| 592 | int i; |
| 593 | |
| 594 | for (i = 0; i < 16; i++) { |
| 595 | PortalBreakGlass(i, 167); |
| 596 | } |
| 597 | } |
| 598 | |
| 599 | switch (mode) { |
| 600 | case MERCENDBOSS_INTRO: { |
| 601 | mprintf(0, "Here intro begin\n"); |
| 602 | |
| 603 | // Make him fire during the cinematics :) |
| 604 | int flags = AISR_OK_TO_FIRE_DURING_CINEMATICS; |
| 605 | AI_Value(me, VF_SET_FLAGS, AIV_I_STATUS_REG, &flags); |
| 606 | |
| 607 | // Make sure he doesn't sleep |
| 608 | flags = AIF_FORCE_AWARENESS; |
| 609 | AI_Value(me, VF_SET_FLAGS, AIV_I_FLAGS, &flags); |
| 610 | |
| 611 | float awareness = AWARE_FULLY; |
| 612 | AI_Value(me, VF_SET, AIV_F_AWARENESS, &awareness); |
| 613 | |
| 614 | // Destroy all non-boss robots |
| 615 | aDestroyAllRobotsInit(); |
| 616 | aDestroyAllRobotsSpareHandle(me); |
| 617 | aDestroyAllRobotsSpareHandle(memory->turret_object); |
| 618 | aDestroyAllRobotsSpareHandle(memory->emitter[0]); |
| 619 | aDestroyAllRobotsSpareHandle(memory->emitter[1]); |
| 620 | aDestroyAllRobotsSpareHandle(memory->combine_object); |
| 621 | aDestroyAllRobotsEnd(); |
| 622 | |
| 623 | // flags = AIF_FIRE; |
| 624 | // AI_Value(me, VF_SET_FLAGS, AIV_I_FLAGS, &flags); |
| 625 | // AI_Value(memory->turret_object, VF_CLEAR_FLAGS, AIV_I_FLAGS, &flags); |
| 626 | |
| 627 | flags = DWBF_ENABLED; |
| 628 | Obj_WBValue(me, 0, VF_SET_FLAGS, WBV_I_DYNAMIC_FLAGS, &flags); |
| 629 | Obj_WBValue(me, 4, VF_SET_FLAGS, WBV_I_DYNAMIC_FLAGS, &flags); |
| 630 | } break; |
| 631 | case MERCENDBOSS_MATTER: { |
| 632 | aShowHUDMessage("GUIDEBOT: We should stay as far away from him as we can."); |
| 633 | |
| 634 | int flags = AIF_DETERMINE_TARGET | AIF_AIM; |
| 635 | AI_Value(me, VF_SET_FLAGS, AIV_I_FLAGS, &flags); |
| 636 | |
| 637 | flags = AISR_RANGED_ATTACK; |
| 638 | AI_Value(me, VF_CLEAR_FLAGS, AIV_I_STATUS_REG, &flags); |
| 639 | mprintf(0, "Here matter\n"); |
| 640 | } break; |
| 641 | case MERCENDBOSS_ENERGY: { |
| 642 | aShowHUDMessage("GUIDEBOT: Wow! We better get behind him."); |
| 643 | |
| 644 | Obj_SetCustomAnim(me, 1.0f, 5.0f, 2.0f, 0, Sound_FindId("MercFBServo"), -1); |
| 645 | Obj_Kill(memory->turret_object, OBJECT_HANDLE_NONE, 1000.0f, |
| 646 | DF_BREAKS_APART | DF_BLAST_RING | DF_LOSES_ANTIGRAV | DF_EXPL_LARGE | DF_CONTACT_BREAKS_APART | |
| 647 | DF_CONTACT_BLAST_RING | DF_DEBRIS_SMOKES | DF_DEBRIS_FIREBALL | DF_DEBRIS_BLAST_RING, |
| 648 | 0.0f, 0.0f); |
| 649 | memory->turret_object = CreateAndAttach(me, "FinalbossLITTLETIT", OBJ_BUILDING, 0, 0, true, true); |
| 650 | |
| 651 | aObjSpark(memory->turret_object, 15, 1000000.0f); |
| 652 | |
| 653 | float tl; |
| 654 | AI_Value(me, VF_GET, AIV_F_LEAD_ACCURACY, &tl); |
| 655 | tl *= 0.8f; |
| 656 | AI_Value(me, VF_SET, AIV_F_LEAD_ACCURACY, &tl); |
| 657 | |
| 658 | aTurnOnSpew(memory->turret_object, 0, MED_SMOKE_INDEX, 10.0f, .001f, PF_REVERSE_GRAVITY, 0, 1.0f, .05f, 100000.0f, |
| 659 | 2.0f, 0.0, -1, -1); |
| 660 | } break; |
| 661 | case MERCENDBOSS_DEATH_BLOSSUM: |
| 662 | break; |
| 663 | case MERCENDBOSS_DEATH: { |
| 664 | AI_SetType(me, AIT_AIS); |
| 665 | |
| 666 | int flags = AIF_FIRE; |
| 667 | AI_Value(me, VF_CLEAR_FLAGS, AIV_I_FLAGS, &flags); |
| 668 | AI_Value(memory->turret_object, VF_CLEAR_FLAGS, AIV_I_FLAGS, &flags); |
| 669 | |
| 670 | vector vel = {0.0f, 0.0f, 0.0f}; |
| 671 | Obj_Value(me, VF_SET, OBJV_V_VELOCITY, &vel); |
| 672 | |
| 673 | AI_AddGoal(me, AIG_SCRIPTED, 0, 1000.0f, -1, GF_NONFLUSHABLE | GF_ORIENT_SCRIPTED, NULL); |
| 674 | |
| 675 | float drag = 0.0f; |
| 676 | Obj_Value(me, VF_SET, OBJV_F_ROTDRAG, &drag); |
| 677 | |
| 678 | flags = PF_LEVELING; |
| 679 | Obj_Value(me, VF_CLEAR_FLAGS, OBJV_I_PHYSICS_FLAGS, &flags); |
| 680 | // float circle_dist = -1.0f; |
| 681 | // AI_Value(me, VF_SET, AIV_F_CIRCLE_DIST, &circle_dist); |
| 682 | |
| 683 | // Obj_SetCustomAnim(me, 495.0f, 650.0f, 15.0f, 0, Sound_FindId("RbtMercEndBossDeath"), -1); |
| 684 | } break; |
| 685 | default: |
| 686 | break; |
| 687 | } |
| 688 | |
| 689 | memory->mode = mode; |
| 690 | SetSuper(me, false); |
| 691 | } |
| 692 | |
| 693 | void MercEndBoss::DoInit(int me) { |
| 694 | tOSIRISMEMCHUNK ch; |
| 695 | ch.id = 4; |
| 696 | ch.size = sizeof(mercendboss_data); |
| 697 | ch.my_id.type = OBJECT_SCRIPT; |
| 698 | ch.my_id.objhandle = me; |
| 699 | int i; |
| 700 | |
| 701 | memory = (mercendboss_data *)Scrpt_MemAlloc(&ch); |
| 702 | memory->flags = 0; |
| 703 | memory->mode = MERCENDBOSS_WAIT; |
| 704 | |
| 705 | memory->turret_object = CreateAndAttach(me, "FinalbossBIGGUN", OBJ_BUILDING, 0, 0, true, true); |
| 706 | |
| 707 | int proom; |
| 708 | vector ppos; |
| 709 | matrix porient; |
| 710 | msafe_struct mstruct; |
| 711 | |
| 712 | Obj_Value(me, VF_GET, OBJV_I_ROOMNUM, &proom); |
| 713 | Obj_Value(me, VF_GET, OBJV_V_POS, &ppos); |
| 714 | Obj_Value(me, VF_GET, OBJV_M_ORIENT, &porient); |
| 715 | |
| 716 | memory->wallhit_id = Obj_FindID("Finalbosswallhit"); |
| 717 | |
| 718 | memory->combine_object = Obj_Create(OBJ_POWERUP, Obj_FindID("FinalbossBEAMCOMBINE"), proom, &ppos, &porient, me); |
| 719 | mprintf(0, "OBJECT COMB is %d\n", memory->combine_object); |
| 720 | aObjGhostSet(1, memory->combine_object); |
| 721 | |
| 722 | memory->camera = Obj_Create(OBJ_POWERUP, Obj_FindID("Invisiblepowerup"), proom, &ppos, &porient, me); |
| 723 | mstruct.objhandle = memory->camera; |
| 724 | MSafe_CallFunction(MSAFE_OBJECT_NO_RENDER, &mstruct); |
| 725 | |
| 726 | for (i = 0; i < 2; i++) { |
| 727 | if (i == 0) |
| 728 | memory->emitter[i] = CreateAndAttach(me, "Finalbossemitter", OBJ_BUILDING, 1 + i, 0, true, true); |
| 729 | else |
| 730 | memory->emitter[i] = CreateAndAttach(me, "Finalbossemitterleft", OBJ_BUILDING, 1 + i, 0, true, true); |
| 731 | |
| 732 | aObjGhostSet(1, memory->emitter[i]); |
| 733 | } |
| 734 | |
| 735 | memory->laser_sound = -1; |
| 736 | memory->last_frame = 0.0f; |
| 737 | memory->laser_time_left = 0.0f; |
| 738 | |
| 739 | memory->f_oriented = false; |
| 740 | |
| 741 | memory->f_target_ghost = false; |
| 742 | memory->time_till_fire = 0.0f; |
| 743 | |
| 744 | int flags = AIF_DETERMINE_TARGET; |
| 745 | AI_Value(me, VF_CLEAR_FLAGS, AIV_I_FLAGS, &flags); |
| 746 | |
| 747 | memory->last_spark_time = Game_GetTime(); |
| 748 | memory->time_to_next_random_sound = 0.0f; |
| 749 | |
| 750 | SetMode(me, MERCENDBOSS_WAIT); |
| 751 | } |
| 752 | |
| 753 | void MercEndBoss::PlayRandomSound(int me) { |
| 754 | memory->time_to_next_random_sound -= Game_GetFrameTime(); |
| 755 | if (memory->time_to_next_random_sound < 0.0f) { |
| 756 | switch (rand() % 9) { |
| 757 | case 0: |
| 758 | Sound_Play3d(me, Sound_FindId("MercFBDanger1")); |
| 759 | break; |
| 760 | case 1: |
| 761 | Sound_Play3d(me, Sound_FindId("MercFBDanger2")); |
| 762 | break; |
| 763 | case 2: |
| 764 | Sound_Play3d(me, Sound_FindId("MercFBDanger3")); |
| 765 | break; |
| 766 | case 3: |
| 767 | Sound_Play3d(me, Sound_FindId("MercFBDanger4")); |
| 768 | break; |
| 769 | case 4: |
| 770 | Sound_Play3d(me, Sound_FindId("MercFBIntruder1")); |
| 771 | break; |
| 772 | case 5: |
| 773 | Sound_Play3d(me, Sound_FindId("MercFBIntruder2")); |
| 774 | break; |
| 775 | case 6: |
| 776 | Sound_Play3d(me, Sound_FindId("MercFBIntruder3")); |
| 777 | break; |
| 778 | case 7: |
| 779 | Sound_Play3d(me, Sound_FindId("MercFBIntruder4")); |
| 780 | break; |
| 781 | case 8: |
| 782 | Sound_Play3d(me, Sound_FindId("MercFBIntruder5")); |
| 783 | break; |
| 784 | } |
| 785 | |
| 786 | memory->time_to_next_random_sound = (((float)rand() / (float)RAND_MAX) * 3.0f) + 3.0f; |
| 787 | } |
| 788 | } |
| 789 | |
| 790 | void MercEndBoss::DoFrame(int me) { |
| 791 | float frame; |
| 792 | float shields; |
| 793 | |
| 794 | Obj_Value(me, VF_GET, OBJV_F_ANIM_FRAME, &frame); |
| 795 | Obj_Value(memory->turret_object, VF_GET, OBJV_F_SHIELDS, &shields); |
| 796 | |
| 797 | if (memory->mode == MERCENDBOSS_MATTER || memory->mode == MERCENDBOSS_ENERGY) { |
| 798 | int target; |
| 799 | int type; |
| 800 | AI_Value(me, VF_GET, AIV_I_TARGET_HANDLE, &target); |
| 801 | Obj_Value(target, VF_GET, OBJV_I_TYPE, &type); |
| 802 | int flags = 0; |
| 803 | |
| 804 | if (type == OBJ_PLAYER) { |
| 805 | Player_Value(target, VF_GET, PLYV_I_FLAGS, &flags); |
| 806 | } |
| 807 | |
| 808 | if (type == OBJ_PLAYER && (flags & PLAYER_FLAGS_DEAD)) { |
| 809 | memory->f_target_ghost = true; |
| 810 | memory->time_till_fire = 3.0f; |
| 811 | |
| 812 | int flags = DWBF_ENABLED; |
| 813 | Obj_WBValue(me, 0, VF_CLEAR_FLAGS, WBV_I_DYNAMIC_FLAGS, &flags); |
| 814 | Obj_WBValue(me, 4, VF_CLEAR_FLAGS, WBV_I_DYNAMIC_FLAGS, &flags); |
| 815 | Obj_WBValue(memory->turret_object, 0, VF_CLEAR_FLAGS, WBV_I_DYNAMIC_FLAGS, &flags); |
| 816 | Obj_WBValue(memory->turret_object, 1, VF_CLEAR_FLAGS, WBV_I_DYNAMIC_FLAGS, &flags); |
| 817 | } else if (memory->f_target_ghost) { |
| 818 | memory->time_till_fire -= Game_GetFrameTime(); |
| 819 | if (memory->time_till_fire <= 0.0f) { |
| 820 | memory->time_till_fire = 0.0f; |
| 821 | memory->f_target_ghost = false; |
| 822 | |
| 823 | int flags = DWBF_ENABLED; |
| 824 | Obj_WBValue(me, 0, VF_SET_FLAGS, WBV_I_DYNAMIC_FLAGS, &flags); |
| 825 | Obj_WBValue(me, 4, VF_SET_FLAGS, WBV_I_DYNAMIC_FLAGS, &flags); |
| 826 | Obj_WBValue(memory->turret_object, 0, VF_SET_FLAGS, WBV_I_DYNAMIC_FLAGS, &flags); |
| 827 | Obj_WBValue(memory->turret_object, 1, VF_SET_FLAGS, WBV_I_DYNAMIC_FLAGS, &flags); |
| 828 | } |
| 829 | } |
| 830 | } else if (memory->f_target_ghost) { |
| 831 | memory->time_till_fire = 0.0f; |
| 832 | memory->f_target_ghost = false; |
| 833 | |
| 834 | int flags = DWBF_ENABLED; |
| 835 | Obj_WBValue(me, 0, VF_SET_FLAGS, WBV_I_DYNAMIC_FLAGS, &flags); |
| 836 | Obj_WBValue(me, 4, VF_SET_FLAGS, WBV_I_DYNAMIC_FLAGS, &flags); |
| 837 | Obj_WBValue(memory->turret_object, 0, VF_SET_FLAGS, WBV_I_DYNAMIC_FLAGS, &flags); |
| 838 | Obj_WBValue(memory->turret_object, 1, VF_SET_FLAGS, WBV_I_DYNAMIC_FLAGS, &flags); |
| 839 | } |
| 840 | |
| 841 | if (memory->mode == MERCENDBOSS_WAIT) { |
| 842 | } else if (memory->mode == MERCENDBOSS_INTRO) { |
| 843 | if (memory->mode_time > 4.0f && memory->mode_time < 9.0f) { |
| 844 | if (!memory->f_oriented) { |
| 845 | int flags = AISR_RANGED_ATTACK; |
| 846 | AI_Value(me, VF_SET_FLAGS, AIV_I_STATUS_REG, &flags); |
| 847 | } else { |
| 848 | int flags = AIF_DETERMINE_TARGET | AIF_AIM; |
| 849 | AI_Value(me, VF_SET_FLAGS, AIV_I_FLAGS, &flags); |
| 850 | |
| 851 | flags = AISR_RANGED_ATTACK; |
| 852 | AI_Value(me, VF_CLEAR_FLAGS, AIV_I_STATUS_REG, &flags); |
| 853 | } |
| 854 | } else if (memory->mode_time < 5.0f && memory->mode_time + Game_GetFrameTime() >= 4.0f) { |
| 855 | AI_AddGoal(me, AIG_SCRIPTED, 3, 1.0f, MEB_TURN_TOWARDS_CAMERA, GF_ORIENT_SCRIPTED, NULL); |
| 856 | } |
| 857 | |
| 858 | } else if (memory->mode == MERCENDBOSS_DEATH) { |
| 859 | int flags = AISR_RANGED_ATTACK; |
| 860 | AI_Value(me, VF_SET_FLAGS, AIV_I_STATUS_REG, &flags); |
| 861 | AI_Value(memory->turret_object, VF_SET_FLAGS, AIV_I_STATUS_REG, &flags); |
| 862 | |
| 863 | if (memory->last_spark_time + .1f < Game_GetTime()) { |
| 864 | memory->last_spark_time = Game_GetTime(); |
| 865 | |
| 866 | int room; |
| 867 | vector pos; |
| 868 | |
| 869 | Obj_Value(me, VF_GET, OBJV_I_ROOMNUM, &room); |
| 870 | Obj_Value(me, VF_GET, OBJV_V_POS, &pos); |
| 871 | |
| 872 | Game_CreateRandomSparks(15, &pos, room); |
| 873 | } |
| 874 | |
| 875 | if (memory->mode_time < 5.0f && memory->mode_time + Game_GetFrameTime() >= 5.0f) { |
| 876 | Sound_Play3d(me, Sound_FindId("MercFBError1")); |
| 877 | } |
| 878 | if (memory->mode_time < 10.0f && memory->mode_time + Game_GetFrameTime() >= 10.0f) { |
| 879 | Sound_Play3d(me, Sound_FindId("MercFBError2")); |
| 880 | } |
| 881 | if (memory->mode_time < 15.0f && memory->mode_time + Game_GetFrameTime() >= 15.0f) { |
| 882 | Sound_Play3d(me, Sound_FindId("MercFBError3")); |
| 883 | } |
| 884 | |
| 885 | if (memory->mode_time < 3.0f && memory->mode_time + Game_GetFrameTime() >= 3.0f) { |
| 886 | Obj_Burning(me, 1000000.0f, 1.0f); |
| 887 | } |
| 888 | |
| 889 | if (memory->mode_time > 20.0f) { |
| 890 | Obj_Kill(me, OBJECT_HANDLE_NONE, 1000.0f, |
| 891 | DF_BLAST_RING | DF_LOSES_ANTIGRAV | DF_EXPL_LARGE | DF_FIREBALL | DF_BREAKS_APART | DF_DEBRIS_SMOKES, |
| 892 | 0.0f, 0.0f); |
| 893 | // Obj_Kill(me, OBJECT_HANDLE_NONE, 1000.0f, |
| 894 | // DF_BREAKS_APART|DF_BLAST_RING|DF_LOSES_ANTIGRAV|DF_EXPL_LARGE|DF_CONTACT_BREAKS_APART|DF_CONTACT_BLAST_RING|DF_DEBRIS_SMOKES|DF_DEBRIS_FIREBALL|DF_DEBRIS_BLAST_RING, |
| 895 | // 0.0f, 0.0f); |
| 896 | Obj_Kill(memory->turret_object, OBJECT_HANDLE_NONE, 1000.0f, |
| 897 | DF_BREAKS_APART | DF_BLAST_RING | DF_LOSES_ANTIGRAV | DF_EXPL_LARGE | DF_CONTACT_BREAKS_APART | |
| 898 | DF_CONTACT_BLAST_RING | DF_DEBRIS_SMOKES | DF_DEBRIS_FIREBALL | DF_DEBRIS_BLAST_RING, |
| 899 | 0.0f, 0.0f); |
| 900 | |
| 901 | aShowHUDMessage("GUIDEBOT: I love this job."); |
| 902 | } |
| 903 | } else if (memory->mode == MERCENDBOSS_MATTER) { |
| 904 | int flags; |
| 905 | Obj_Value(memory->turret_object, VF_GET, OBJV_I_FLAGS, &flags); |
| 906 | |
| 907 | if (flags & OF_AI_DEATH) { |
| 908 | SetMode(me, MERCENDBOSS_ENERGY); |
| 909 | } |
| 910 | |
| 911 | PlayRandomSound(me); |
| 912 | } else if (memory->mode == MERCENDBOSS_ENERGY) { |
| 913 | if (memory->f_sub_super) { |
| 914 | if (memory->sub_mode_time_left > ENERGY_SUPER_TIME - 1.5f && |
| 915 | memory->sub_mode_time_left - Game_GetFrameTime() <= ENERGY_SUPER_TIME - 1.5f) { |
| 916 | aLightningCreate(memory->combine_object, memory->camera, ENERGY_SUPER_TIME - 1.5f, 6.0f, 1, |
| 917 | Scrpt_FindTextureName("endbossbeamweapon2"), 1.0f, 1, 255, 255, 255, true); |
| 918 | aLightningCreate(memory->combine_object, memory->camera, ENERGY_SUPER_TIME - 1.5f, 6.0f, 1, |
| 919 | Scrpt_FindTextureName("endbossbeamweapon2"), 3.1111f, 1, 255, 255, 255, true); |
| 920 | } |
| 921 | |
| 922 | vector pos; |
| 923 | matrix orient; |
| 924 | vector start_pos; |
| 925 | vector end_pos; |
| 926 | vector collision_pos; |
| 927 | vector collision_normal; |
| 928 | int num_iterations = 0; |
| 929 | int num_ignore = 0; |
| 930 | int ignore_list[100]; |
| 931 | int fate; |
| 932 | ray_info ray; |
| 933 | |
| 934 | int room = 76; |
| 935 | Obj_Value(me, VF_GET, OBJV_M_ORIENT, &orient); |
| 936 | Obj_Value(me, VF_GET, OBJV_V_POS, &pos); |
| 937 | |
| 938 | pos += (orient.fvec * 50.0f) + (orient.uvec * 2.0f); |
| 939 | Obj_Value(memory->combine_object, VF_SET, OBJV_V_POS, &pos); |
| 940 | Obj_Value(memory->combine_object, VF_SET, OBJV_I_ROOMNUM, &room); |
| 941 | start_pos = pos; |
| 942 | |
| 943 | pos += (orient.fvec * 1200.0f); |
| 944 | Obj_Value(memory->camera, VF_SET, OBJV_V_POS, &pos); |
| 945 | Obj_Value(memory->camera, VF_SET, OBJV_I_ROOMNUM, &room); |
| 946 | end_pos = pos; |
| 947 | |
| 948 | if (memory->sub_mode_time_left <= 8.5f) { |
| 949 | ignore_list[num_ignore++] = memory->camera; |
| 950 | ignore_list[num_ignore++] = memory->emitter[0]; |
| 951 | ignore_list[num_ignore++] = memory->emitter[1]; |
| 952 | ignore_list[num_ignore++] = me; |
| 953 | ignore_list[num_ignore++] = memory->turret_object; |
| 954 | ignore_list[num_ignore++] = memory->combine_object; |
| 955 | ignore_list[num_ignore++] = -1; |
| 956 | |
| 957 | vector saved_start = start_pos; |
| 958 | |
| 959 | do { |
| 960 | Obj_Value(me, VF_SET, OBJV_PI_HACK_FVI_IGNORE_LIST, ignore_list); |
| 961 | fate = FVI_RayCast(OBJECT_HANDLE_NONE, &start_pos, &end_pos, 76, 13.0f, |
| 962 | (FQ_CHECK_OBJS | FQ_IGNORE_POWERUPS | FQ_IGNORE_WEAPONS | FQ_OBJ_BACKFACE | FQ_BACKFACE | |
| 963 | FQ_PLAYERS_AS_SPHERE | FQ_IGNORE_WALLS | FQ_NO_RELINK), |
| 964 | &ray); |
| 965 | Obj_Value(me, VF_SET, OBJV_PI_HACK_FVI_IGNORE_LIST, NULL); |
| 966 | |
| 967 | if (fate != HIT_NONE) { |
| 968 | start_pos = ray.hit_point + (orient.fvec * 13.0f); |
| 969 | } |
| 970 | |
| 971 | if (fate == HIT_OBJECT || fate == HIT_SPHERE_2_POLY_OBJECT) { |
| 972 | int type; |
| 973 | |
| 974 | Obj_Value(ray.hit_object, VF_GET, OBJV_I_TYPE, &type); |
| 975 | |
| 976 | if (type == OBJ_PLAYER || type == OBJ_ROBOT) { |
| 977 | msafe_struct mstruct; |
| 978 | |
| 979 | mstruct.objhandle = ray.hit_object; |
| 980 | mstruct.killer_handle = me; |
| 981 | mstruct.damage_type = PD_ENERGY_WEAPON; |
| 982 | mstruct.amount = 10.0f * Game_GetFrameTime(); |
| 983 | |
| 984 | MSafe_CallFunction(MSAFE_OBJECT_DAMAGE_OBJECT, &mstruct); |
| 985 | |
| 986 | // if(ray.hit_wallnorm * orient.fvec <= 0.0f) |
| 987 | // { |
| 988 | vector bf_pos = ray.hit_point + (orient.fvec * 3.0f); |
| 989 | // vector bf_pos = ray.hit_point + (orient.fvec * |
| 990 | //-9.0f); |
| 991 | Obj_Create(OBJ_POWERUP, memory->wallhit_id, 76, &bf_pos); |
| 992 | // //mprintf(0, "HERE X\n"); |
| 993 | // } |
| 994 | // else |
| 995 | // { |
| 996 | // vector bf_pos = ray.hit_point + (orient.fvec |
| 997 | //* 9.0f); Obj_Create(OBJ_POWERUP, |
| 998 | // memory->wallhit_id, 76, &bf_pos); |
| 999 | /// //mprintf(0, "HERE X\n"); |
| 1000 | // } |
| 1001 | } |
| 1002 | |
| 1003 | ignore_list[num_ignore++] = ray.hit_object; |
| 1004 | } |
| 1005 | ignore_list[num_ignore] = -1; |
| 1006 | |
| 1007 | num_iterations++; |
| 1008 | } while (fate != HIT_NONE && num_iterations < 10); |
| 1009 | |
| 1010 | start_pos = saved_start; |
| 1011 | num_iterations = 0; |
| 1012 | |
| 1013 | // CHECK THE WALLS |
| 1014 | do { |
| 1015 | fate = FVI_RayCast(OBJECT_HANDLE_NONE, &start_pos, &end_pos, 76, 0.0f, FQ_NO_RELINK, &ray); |
| 1016 | |
| 1017 | if (fate != HIT_NONE) { |
| 1018 | start_pos = ray.hit_point + (orient.fvec * 5.0f); |
| 1019 | |
| 1020 | if (ray.hit_wallnorm * orient.fvec <= 0.0f) { |
| 1021 | vector bf_pos = ray.hit_point + (orient.fvec * -9.0f); |
| 1022 | Obj_Create(OBJ_POWERUP, memory->wallhit_id, 76, &bf_pos); |
| 1023 | // mprintf(0, "HERE X\n"); |
| 1024 | } else { |
| 1025 | vector bf_pos = ray.hit_point + (orient.fvec * 9.0f); |
| 1026 | Obj_Create(OBJ_POWERUP, memory->wallhit_id, 76, &bf_pos); |
| 1027 | // mprintf(0, "HERE X\n"); |
| 1028 | } |
| 1029 | } |
| 1030 | |
| 1031 | num_iterations++; |
| 1032 | } while (fate != HIT_NONE && num_iterations < 10); |
| 1033 | |
| 1034 | start_pos = saved_start; |
| 1035 | num_iterations = 0; |
| 1036 | |
| 1037 | // CHECK THE WALLS |
| 1038 | do { |
| 1039 | fate = FVI_RayCast(OBJECT_HANDLE_NONE, &end_pos, &start_pos, 76, 0.0f, FQ_NO_RELINK, &ray); |
| 1040 | |
| 1041 | if (fate != HIT_NONE) { |
| 1042 | end_pos = ray.hit_point - (orient.fvec * 5.0f); |
| 1043 | |
| 1044 | if (ray.hit_wallnorm * orient.fvec <= 0.0f) { |
| 1045 | vector bf_pos = ray.hit_point + (orient.fvec * -9.0f); |
| 1046 | Obj_Create(OBJ_POWERUP, memory->wallhit_id, 76, &bf_pos); |
| 1047 | // mprintf(0, "HERE X\n"); |
| 1048 | } else { |
| 1049 | vector bf_pos = ray.hit_point + (orient.fvec * 9.0f); |
| 1050 | Obj_Create(OBJ_POWERUP, memory->wallhit_id, 76, &bf_pos); |
| 1051 | // mprintf(0, "HERE X\n"); |
| 1052 | } |
| 1053 | } |
| 1054 | |
| 1055 | num_iterations++; |
| 1056 | } while (fate != HIT_NONE && num_iterations < 10); |
| 1057 | |
| 1058 | float last_see_game_time = Game_GetTime(); |
| 1059 | AI_Value(me, VF_SET, AIV_F_LAST_SEE_TARGET_TIME, &last_see_game_time); |
| 1060 | AI_Value(memory->turret_object, VF_SET, AIV_F_LAST_SEE_TARGET_TIME, &last_see_game_time); |
| 1061 | } |
| 1062 | } else { |
| 1063 | int flags; |
| 1064 | Obj_Value(memory->turret_object, VF_GET, OBJV_I_FLAGS, &flags); |
| 1065 | |
| 1066 | if (flags & OF_AI_DEATH) { |
| 1067 | SetMode(me, MERCENDBOSS_DEATH); |
| 1068 | } |
| 1069 | } |
| 1070 | |
| 1071 | PlayRandomSound(me); |
| 1072 | } |
| 1073 | |
| 1074 | memory->sub_mode_time_left -= Game_GetFrameTime(); |
| 1075 | if (memory->sub_mode_time_left <= 0.0f) { |
| 1076 | SetSuper(me, !memory->f_sub_super); |
| 1077 | } |
| 1078 | |
| 1079 | memory->mode_time += Game_GetFrameTime(); |
| 1080 | memory->last_frame = frame; |
| 1081 | } |
| 1082 | |
| 1083 | int16_t MercEndBoss::CallEvent(int event, tOSIRISEventInfo *data) { |
| 1084 | switch (event) { |
| 1085 | case EVT_COLLIDE: { |
| 1086 | int type; |
| 1087 | Obj_Value(data->evt_collide.it_handle, VF_GET, OBJV_I_TYPE, &type); |
| 1088 | |
| 1089 | if (type == OBJ_PLAYER || type == OBJ_ROBOT) { |
| 1090 | msafe_struct mstruct; |
| 1091 | |
| 1092 | mstruct.objhandle = data->evt_collide.it_handle; |
| 1093 | mstruct.killer_handle = data->me_handle; |
| 1094 | mstruct.damage_type = PD_ENERGY_WEAPON; |
| 1095 | mstruct.amount = 50.0f * Game_GetFrameTime(); |
| 1096 | |
| 1097 | MSafe_CallFunction(MSAFE_OBJECT_DAMAGE_OBJECT, &mstruct); |
| 1098 | } |
| 1099 | } break; |
| 1100 | case EVT_AI_INIT: |
| 1101 | DoInit(data->me_handle); |
| 1102 | break; |
| 1103 | case EVT_AI_FRAME: |
| 1104 | DoFrame(data->me_handle); |
| 1105 | break; |
| 1106 | case EVT_AI_NOTIFY: |
| 1107 | return (DoNotify(data->me_handle, data) != false) ? CONTINUE_CHAIN | CONTINUE_DEFAULT : 0; |
| 1108 | break; |
| 1109 | case EVT_DESTROY: { |
| 1110 | // shake players |
| 1111 | msafe_struct mstruct; |
| 1112 | mstruct.amount = 90.0f; |
| 1113 | MSafe_CallFunction(MSAFE_OBJECT_VIEWER_SHAKE, &mstruct); |
| 1114 | |
| 1115 | Obj_Kill(memory->turret_object, OBJECT_HANDLE_NONE, 1000.0f, |
| 1116 | DF_BLAST_RING | DF_LOSES_ANTIGRAV | DF_EXPL_LARGE | DF_FIREBALL | DF_BREAKS_APART | DF_DEBRIS_SMOKES, 0.0f, |
| 1117 | 0.0f); |
| 1118 | |
| 1119 | int i; |
| 1120 | msafe_struct mo; |
| 1121 | |
| 1122 | mo.objhandle = memory->camera; |
| 1123 | mo.playsound = 0; |
| 1124 | MSafe_CallFunction(MSAFE_OBJECT_REMOVE, &mo); |
| 1125 | |
| 1126 | for (i = 0; i < 2; i++) { |
| 1127 | mo.objhandle = memory->emitter[i]; |
| 1128 | mo.playsound = 0; |
| 1129 | MSafe_CallFunction(MSAFE_OBJECT_REMOVE, &mo); |
| 1130 | } |
| 1131 | |
| 1132 | mo.objhandle = memory->combine_object; |
| 1133 | mo.playsound = 0; |
| 1134 | MSafe_CallFunction(MSAFE_OBJECT_REMOVE, &mo); |
| 1135 | } break; |
| 1136 | case EVT_MEMRESTORE: { |
| 1137 | memory = (mercendboss_data *)data->evt_memrestore.memory_ptr; |
| 1138 | } break; |
| 1139 | } |
| 1140 | return CONTINUE_CHAIN | CONTINUE_DEFAULT; |
| 1141 | } |
| 1142 | |
| 1143 | //------------------ |
| 1144 | // Gun class |
| 1145 | //------------------ |
| 1146 | |
| 1147 | int16_t Gun::CallEvent(int event, tOSIRISEventInfo *data) { |
| 1148 | switch (event) { |
| 1149 | case EVT_AI_INIT: { |
| 1150 | tOSIRISMEMCHUNK ch; |
| 1151 | ch.id = 4; |
| 1152 | ch.size = sizeof(gun_data); |
| 1153 | ch.my_id.type = OBJECT_SCRIPT; |
| 1154 | ch.my_id.objhandle = data->me_handle; |
| 1155 | |
| 1156 | memory = (gun_data *)Scrpt_MemAlloc(&ch); |
| 1157 | memory->shell_id = Obj_FindID("finalbossshellcasing"); |
| 1158 | memory->f_fire = true; |
| 1159 | } break; |
| 1160 | case EVT_COLLIDE: { |
| 1161 | int type; |
| 1162 | Obj_Value(data->evt_collide.it_handle, VF_GET, OBJV_I_TYPE, &type); |
| 1163 | |
| 1164 | if (type == OBJ_PLAYER || type == OBJ_ROBOT) { |
| 1165 | msafe_struct mstruct; |
| 1166 | |
| 1167 | mstruct.objhandle = data->evt_collide.it_handle; |
| 1168 | mstruct.killer_handle = data->me_handle; |
| 1169 | mstruct.damage_type = PD_ENERGY_WEAPON; |
| 1170 | mstruct.amount = 50.0f * Game_GetFrameTime(); |
| 1171 | |
| 1172 | MSafe_CallFunction(MSAFE_OBJECT_DAMAGE_OBJECT, &mstruct); |
| 1173 | } |
| 1174 | } break; |
| 1175 | case EVT_AI_NOTIFY: |
| 1176 | if (data->evt_ai_notify.notify_type == AIN_FIRED_WEAPON) { |
| 1177 | memory->f_fire = !memory->f_fire; |
| 1178 | |
| 1179 | if (memory->f_fire) |
| 1180 | ; |
| 1181 | { |
| 1182 | int room; |
| 1183 | vector pos; |
| 1184 | vector dir; |
| 1185 | matrix orient; |
| 1186 | vector velocity; |
| 1187 | |
| 1188 | Obj_Value(data->me_handle, VF_GET, OBJV_I_ROOMNUM, &room); |
| 1189 | |
| 1190 | Obj_GetGunPos(data->me_handle, 5, &pos, &dir); |
| 1191 | dir *= -1.0f; |
| 1192 | vm_VectorToMatrix(&orient, &dir, NULL, NULL); |
| 1193 | |
| 1194 | velocity = dir * qRandomValue(30.0f, 35.0f); |
| 1195 | |
| 1196 | Obj_Create(OBJ_BUILDING, memory->shell_id, room, &pos, &orient, data->me_handle, &velocity); |
| 1197 | } |
| 1198 | } |
| 1199 | return CONTINUE_CHAIN; |
| 1200 | break; |
| 1201 | case EVT_DESTROY: { |
| 1202 | } break; |
| 1203 | case EVT_MEMRESTORE: { |
| 1204 | memory = (gun_data *)data->evt_memrestore.memory_ptr; |
| 1205 | } break; |
| 1206 | } |
| 1207 | return CONTINUE_CHAIN | CONTINUE_DEFAULT; |
| 1208 | } |
| 1209 | |
| 1210 | //------------------ |
| 1211 | // Casing class |
| 1212 | //------------------ |
| 1213 | |
| 1214 | int16_t Casing::CallEvent(int event, tOSIRISEventInfo *data) { |
| 1215 | switch (event) { |
| 1216 | case EVT_CREATED: { |
| 1217 | tOSIRISMEMCHUNK ch; |
| 1218 | ch.id = 4; |
| 1219 | ch.size = sizeof(casing_data); |
| 1220 | ch.my_id.type = OBJECT_SCRIPT; |
| 1221 | ch.my_id.objhandle = data->me_handle; |
| 1222 | |
| 1223 | memory = (casing_data *)Scrpt_MemAlloc(&ch); |
| 1224 | memory->time_left = qRandomValue(5.0f, 10.0f); |
| 1225 | } break; |
| 1226 | case EVT_INTERVAL: |
| 1227 | memory->time_left -= Game_GetFrameTime(); |
| 1228 | if (memory->time_left < 0.0f) { |
| 1229 | msafe_struct mo; |
| 1230 | mo.objhandle = data->me_handle; |
| 1231 | mo.playsound = 0; |
| 1232 | MSafe_CallFunction(MSAFE_OBJECT_REMOVE, &mo); |
| 1233 | } |
| 1234 | break; |
| 1235 | case EVT_AI_NOTIFY: |
| 1236 | return CONTINUE_CHAIN; |
| 1237 | break; |
| 1238 | case EVT_DESTROY: { |
| 1239 | } break; |
| 1240 | case EVT_MEMRESTORE: { |
| 1241 | memory = (casing_data *)data->evt_memrestore.memory_ptr; |
| 1242 | } break; |
| 1243 | } |
| 1244 | return CONTINUE_CHAIN | CONTINUE_DEFAULT; |
| 1245 | } |
| 1246 | |
| 1247 | //------------------ |
| 1248 | // CombWallHit class |
| 1249 | //------------------ |
| 1250 | |
| 1251 | int16_t CombWallHit::CallEvent(int event, tOSIRISEventInfo *data) { |
| 1252 | switch (event) { |
| 1253 | case EVT_CREATED: { |
| 1254 | tOSIRISMEMCHUNK ch; |
| 1255 | ch.id = 4; |
| 1256 | ch.size = sizeof(combwallhit_data); |
| 1257 | ch.my_id.type = OBJECT_SCRIPT; |
| 1258 | ch.my_id.objhandle = data->me_handle; |
| 1259 | |
| 1260 | memory = (combwallhit_data *)Scrpt_MemAlloc(&ch); |
| 1261 | memory->time_left = Game_GetFrameTime() * 1.05f; |
| 1262 | // mprintf(0, "HERE\n"); |
| 1263 | } break; |
| 1264 | case EVT_INTERVAL: |
| 1265 | memory->time_left -= Game_GetFrameTime(); |
| 1266 | if (memory->time_left < 0.0f) { |
| 1267 | msafe_struct mo; |
| 1268 | mo.objhandle = data->me_handle; |
| 1269 | mo.playsound = 0; |
| 1270 | MSafe_CallFunction(MSAFE_OBJECT_REMOVE, &mo); |
| 1271 | } |
| 1272 | break; |
| 1273 | case EVT_AI_NOTIFY: |
| 1274 | return CONTINUE_CHAIN; |
| 1275 | break; |
| 1276 | case EVT_DESTROY: { |
| 1277 | } break; |
| 1278 | case EVT_MEMRESTORE: { |
| 1279 | memory = (combwallhit_data *)data->evt_memrestore.memory_ptr; |
| 1280 | } break; |
| 1281 | } |
| 1282 | return CONTINUE_CHAIN | CONTINUE_DEFAULT; |
| 1283 | } |
| 1284 | |
| 1285 | //------------------ |
| 1286 | // DropTarget class |
| 1287 | //------------------ |
| 1288 | |
| 1289 | int16_t DropTarget::CallEvent(int event, tOSIRISEventInfo *data) { |
| 1290 | switch (event) { |
| 1291 | case EVT_CREATED: { |
| 1292 | tOSIRISMEMCHUNK ch; |
| 1293 | ch.id = 4; |
| 1294 | ch.size = sizeof(droptarget_data); |
| 1295 | ch.my_id.type = OBJECT_SCRIPT; |
| 1296 | ch.my_id.objhandle = data->me_handle; |
| 1297 | |
| 1298 | memory = (droptarget_data *)Scrpt_MemAlloc(&ch); |
| 1299 | memory->time_left = 5.0f; |
| 1300 | memory->last_set_time = Game_GetTime(); |
| 1301 | // mprintf(0, "HERE\n"); |
| 1302 | } break; |
| 1303 | case EVT_INTERVAL: { |
| 1304 | float frame; |
| 1305 | Obj_Value(data->me_handle, VF_GET, OBJV_F_ANIM_FRAME, &frame); |
| 1306 | |
| 1307 | if (frame == 5.0f) { |
| 1308 | memory->time_left -= Game_GetFrameTime(); |
| 1309 | if (memory->time_left < 0.0f) { |
| 1310 | memory->time_left = 5.0f; |
| 1311 | Obj_SetCustomAnim(data->me_handle, 5.0f, 10.0f, 0.5f, 0, Sound_FindId("DorPTMCCovertDOpenB"), -1); |
| 1312 | } |
| 1313 | } |
| 1314 | } break; |
| 1315 | case EVT_COLLIDE: { |
| 1316 | float frame; |
| 1317 | char type; |
| 1318 | |
| 1319 | Obj_Value(data->me_handle, VF_GET, OBJV_F_ANIM_FRAME, &frame); |
| 1320 | AI_Value(data->me_handle, VF_GET, AIV_C_NEXT_ANIMATION_TYPE, &type); |
| 1321 | |
| 1322 | if ((frame == 0.0f || frame == 10.0f) && type != AS_CUSTOM && memory->last_set_time + 5.0f < Game_GetTime()) { |
| 1323 | memory->last_set_time = Game_GetTime(); |
| 1324 | Obj_SetCustomAnim(data->me_handle, 0.0f, 5.0f, 0.5f, 0, Sound_FindId("DorPTMCCovertDOpenB"), -1); |
| 1325 | } |
| 1326 | } break; |
| 1327 | case EVT_DESTROY: { |
| 1328 | } break; |
| 1329 | case EVT_MEMRESTORE: { |
| 1330 | memory = (droptarget_data *)data->evt_memrestore.memory_ptr; |
| 1331 | } break; |
| 1332 | } |
| 1333 | return CONTINUE_CHAIN | CONTINUE_DEFAULT; |
| 1334 | } |
| 1335 | |
| 1336 | //------------------ |
| 1337 | // Hanging Light |
| 1338 | //------------------ |
| 1339 | |
| 1340 | void HangLight::DoInit(int me) { CreateAndAttach(me, "MERC3_danglinglightbulb", OBJ_CLUTTER, 0, 0, true, true); } |
| 1341 | |
| 1342 | int16_t HangLight::CallEvent(int event, tOSIRISEventInfo *data) { |
| 1343 | switch (event) { |
| 1344 | case EVT_CREATED: |
| 1345 | DoInit(data->me_handle); |
| 1346 | break; |
| 1347 | } |
| 1348 | return CONTINUE_CHAIN | CONTINUE_DEFAULT; |
| 1349 | } |