| 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 | // clutter.cpp |
| 20 | // 0.1 |
| 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 | |
| 28 | #include "module.h" |
| 29 | |
| 30 | #ifdef __cplusplus |
| 31 | extern "C" { |
| 32 | #endif |
| 33 | DLLEXPORT char STDCALL InitializeDLL(tOSIRISModuleInit *func_list); |
| 34 | DLLEXPORT void STDCALL ShutdownDLL(void); |
| 35 | DLLEXPORT int STDCALL GetGOScriptID(const char *name, uint8_t isdoor); |
| 36 | DLLEXPORT void STDCALLPTR CreateInstance(int id); |
| 37 | DLLEXPORT void STDCALL DestroyInstance(int id, void *ptr); |
| 38 | DLLEXPORT int16_t STDCALL CallInstanceEvent(int id, void *ptr, int event, tOSIRISEventInfo *data); |
| 39 | DLLEXPORT int STDCALL SaveRestoreState(void *file_ptr, uint8_t saving_state); |
| 40 | #ifdef __cplusplus |
| 41 | } |
| 42 | #endif |
| 43 | |
| 44 | static int String_table_size = 0; |
| 45 | static char **String_table = NULL; |
| 46 | static const char *_Error_string = "!!ERROR MISSING STRING!!"; |
| 47 | static const char *_Empty_string = ""; |
| 48 | static const char *GetStringFromTable(int index) { |
| 49 | if ((index < 0) || (index >= String_table_size)) |
| 50 | return _Error_string; |
| 51 | if (!String_table[index]) |
| 52 | return _Empty_string; |
| 53 | return String_table[index]; |
| 54 | } |
| 55 | #define TXT(x) GetStringFromTable(x) |
| 56 | |
| 57 | #define ID_FRAGCRATE 0 |
| 58 | #define ID_NAPALMBARREL 1 |
| 59 | #define ID_ALIENCUPLINK 2 |
| 60 | #define ID_TNTHIGHYIELD 3 |
| 61 | #define ID_TNTMEDYIELD 4 |
| 62 | #define ID_FALLINGROCK 5 |
| 63 | #define ID_LAVAROCK 6 |
| 64 | |
| 65 | struct tScriptInfo { |
| 66 | int id; |
| 67 | const char *name; |
| 68 | }; |
| 69 | |
| 70 | static tScriptInfo ScriptIDs[] = {{ID_FRAGCRATE, "fragcrate"}, |
| 71 | {ID_NAPALMBARREL, "napalmbarrel"}, |
| 72 | {ID_ALIENCUPLINK, "Aliencuplink"}, |
| 73 | {ID_TNTHIGHYIELD, "TNTCrateHighYield"}, |
| 74 | {ID_TNTMEDYIELD, "TNTCrateMediumYield"}, |
| 75 | {ID_FALLINGROCK, "FallingRock"}, |
| 76 | {ID_LAVAROCK, "LavaRock"}}; |
| 77 | |
| 78 | static int NumScriptIDs = sizeof(ScriptIDs) / sizeof(tScriptInfo); |
| 79 | |
| 80 | class ClutterScript { |
| 81 | public: |
| 82 | virtual int16_t CallEvent(int event, tOSIRISEventInfo *data) { return CONTINUE_CHAIN | CONTINUE_DEFAULT; } |
| 83 | }; |
| 84 | |
| 85 | class FragCrate : public ClutterScript { |
| 86 | public: |
| 87 | int16_t CallEvent(int event, tOSIRISEventInfo *data); |
| 88 | }; |
| 89 | |
| 90 | class NapalmBarrel : public ClutterScript { |
| 91 | public: |
| 92 | int16_t CallEvent(int event, tOSIRISEventInfo *data); |
| 93 | }; |
| 94 | |
| 95 | class AliencuplinkScript : public ClutterScript { |
| 96 | public: |
| 97 | int16_t CallEvent(int event, tOSIRISEventInfo *data); |
| 98 | }; |
| 99 | |
| 100 | struct tTNTHighYield { |
| 101 | vector last_vel; |
| 102 | float lifetime; |
| 103 | }; |
| 104 | class TNTHighYield : public ClutterScript { |
| 105 | public: |
| 106 | TNTHighYield() { memory = NULL; } |
| 107 | int16_t CallEvent(int event, tOSIRISEventInfo *data); |
| 108 | tTNTHighYield *memory; |
| 109 | }; |
| 110 | |
| 111 | class TNTMedYield : public ClutterScript { |
| 112 | public: |
| 113 | TNTMedYield() { memory = NULL; } |
| 114 | int16_t CallEvent(int event, tOSIRISEventInfo *data); |
| 115 | float *memory; |
| 116 | }; |
| 117 | |
| 118 | struct tFallingRock { |
| 119 | float lifeleft; |
| 120 | }; |
| 121 | class FallingRock : public ClutterScript { |
| 122 | public: |
| 123 | FallingRock() { memory = NULL; } |
| 124 | int16_t CallEvent(int event, tOSIRISEventInfo *data); |
| 125 | tFallingRock *memory; |
| 126 | }; |
| 127 | class LavaRock : public ClutterScript { |
| 128 | public: |
| 129 | LavaRock() { memory = NULL; } |
| 130 | int16_t CallEvent(int event, tOSIRISEventInfo *data); |
| 131 | tFallingRock *memory; |
| 132 | }; |
| 133 | |
| 134 | // InitializeDLL |
| 135 | // Purpose: |
| 136 | // This function gets called when the DLL first gets loaded. It will only be called once (until the |
| 137 | // DLL is unloaded). Passed in is a struct of data passed from the game needed for the DLL to interact |
| 138 | // with D3. Usually this function will just call osicommon_Initialize(), which sets up the imported |
| 139 | // functions. However, you can alloc some memory or whatever in this function, and free it in ShutdownDLL(). |
| 140 | // Note: You cannot call any imported functions until osicommon_Initialize() is called. |
| 141 | // Returns 1 if initialization went ok, 0 if there was an error and the DLL should not be loaded. |
| 142 | char STDCALL InitializeDLL(tOSIRISModuleInit *func_list) { |
| 143 | osicommon_Initialize((tOSIRISModuleInit *)func_list); |
| 144 | String_table_size = func_list->string_count; |
| 145 | String_table = func_list->string_table; |
| 146 | if (func_list->game_checksum != CHECKSUM) { |
| 147 | mprintf(0, "Game-Checksum FAIL!!! (%ul!=%ul)\n", func_list->game_checksum, CHECKSUM); |
| 148 | mprintf(0, "RECOMPILE YOUR SCRIPTS!!!\n"); |
| 149 | return 0; |
| 150 | } |
| 151 | return 1; |
| 152 | } |
| 153 | |
| 154 | // ShutdownDLL |
| 155 | // Purpose: |
| 156 | // This function is called right before a DLL is about to be unloaded from memory. You can free |
| 157 | // any unfree'd memory, or anything else you need to do. Don't worry about destroying any instances |
| 158 | // of scripts, as they will all be automatically destroyed before this function is called. The |
| 159 | // same goes for any memory allocated with Scrpt_MemAlloc(), as this will automatically be freed |
| 160 | // when a scripts instance is destroyed. |
| 161 | void STDCALL ShutdownDLL(void) {} |
| 162 | |
| 163 | // GetGOScriptID |
| 164 | // Purpose: |
| 165 | // Given the name of the object (from it's pagename), this function will search through it's |
| 166 | // list of General Object Scripts for a script with a matching name (to see if there is a script |
| 167 | // for that type/id of object within this DLL). If a matching scriptname is found, a UNIQUE ID |
| 168 | // is to be returned back to Descent 3. This ID will be used from here on out for all future |
| 169 | // interaction with the DLL. Since doors are not part of the generic object's, it's possible |
| 170 | // for a door to have the same name as a generic object (OBJ_POWERUP, OBJ_BUILDING, OBJ_CLUTTER |
| 171 | // or OBJ_ROBOT), therefore, a 1 is passed in for isdoor if the given object name refers to a |
| 172 | // door, else it is a 0. The return value is the unique identifier, else -1 if the script |
| 173 | // does not exist in the DLL. |
| 174 | int STDCALL GetGOScriptID(const char *name, uint8_t isdoor) { |
| 175 | if (!isdoor) { |
| 176 | for (int i = 0; i < NumScriptIDs; i++) { |
| 177 | if (!stricmp(name, ScriptIDs[i].name)) |
| 178 | return ScriptIDs[i].id; |
| 179 | } |
| 180 | } |
| 181 | |
| 182 | return -1; |
| 183 | } |
| 184 | |
| 185 | // CreateInstance |
| 186 | // Purpose: |
| 187 | // Given an ID from a call to GetGOScriptID(), this function will create a new instance for that |
| 188 | // particular script (by allocating and initializing memory, etc.). A pointer to this instance |
| 189 | // is to be returned back to Descent 3. This pointer will be passed around, along with the ID |
| 190 | // for CallInstanceEvent() and DestroyInstance(). Return NULL if there was an error. |
| 191 | void STDCALLPTR CreateInstance(int id) { |
| 192 | switch (id) { |
| 193 | case ID_FRAGCRATE: |
| 194 | return new FragCrate; |
| 195 | break; |
| 196 | case ID_NAPALMBARREL: |
| 197 | return new NapalmBarrel; |
| 198 | break; |
| 199 | case ID_ALIENCUPLINK: |
| 200 | return new AliencuplinkScript; |
| 201 | break; |
| 202 | case ID_TNTHIGHYIELD: |
| 203 | return new TNTHighYield; |
| 204 | break; |
| 205 | case ID_TNTMEDYIELD: |
| 206 | return new TNTMedYield; |
| 207 | break; |
| 208 | case ID_FALLINGROCK: |
| 209 | return new FallingRock; |
| 210 | break; |
| 211 | case ID_LAVAROCK: |
| 212 | return new LavaRock; |
| 213 | break; |
| 214 | }; |
| 215 | return NULL; |
| 216 | } |
| 217 | |
| 218 | // DestroyInstance |
| 219 | // Purpose: |
| 220 | // Given an ID, and a pointer to a particular instance of a script, this function will delete and |
| 221 | // destruct all information associated with that script, so it will no longer exist. |
| 222 | void STDCALL DestroyInstance(int id, void *ptr) { |
| 223 | switch (id) { |
| 224 | case ID_FRAGCRATE: |
| 225 | delete ((FragCrate *)ptr); |
| 226 | break; |
| 227 | case ID_NAPALMBARREL: |
| 228 | delete ((NapalmBarrel *)ptr); |
| 229 | break; |
| 230 | case ID_ALIENCUPLINK: |
| 231 | delete ((AliencuplinkScript *)ptr); |
| 232 | break; |
| 233 | case ID_TNTHIGHYIELD: |
| 234 | delete ((TNTHighYield *)ptr); |
| 235 | break; |
| 236 | case ID_TNTMEDYIELD: |
| 237 | delete ((TNTMedYield *)ptr); |
| 238 | break; |
| 239 | case ID_FALLINGROCK: |
| 240 | delete ((FallingRock *)ptr); |
| 241 | break; |
| 242 | case ID_LAVAROCK: |
| 243 | delete ((LavaRock *)ptr); |
| 244 | break; |
| 245 | }; |
| 246 | } |
| 247 | |
| 248 | // CallInstanceEvent |
| 249 | // Purpose: |
| 250 | // Given an ID, a pointer to a script instance, an event and a pointer to the struct of |
| 251 | // information about the event, this function will translate who this event belongs to and |
| 252 | // passes the event to that instance of the script to be handled. Return a combination of |
| 253 | // CONTINUE_CHAIN and CONTINUE_DEFAULT, to give instructions on what to do based on the |
| 254 | // event. CONTINUE_CHAIN means to continue through the chain of scripts (custom script, level |
| 255 | // script, mission script, and finally default script). If CONTINUE_CHAIN is not specified, |
| 256 | // than the chain is broken and those scripts of lower priority will never get the event. Return |
| 257 | // CONTINUE_DEFAULT in order to tell D3 if you want process the normal action that is built into |
| 258 | // the game for that event. This only pertains to certain events. If the chain continues |
| 259 | // after this script, than the CONTINUE_DEFAULT setting will be overridden by lower priority |
| 260 | // scripts return value. |
| 261 | int16_t STDCALL CallInstanceEvent(int id, void *ptr, int event, tOSIRISEventInfo *data) { |
| 262 | return ((ClutterScript *)ptr)->CallEvent(event, data); |
| 263 | } |
| 264 | |
| 265 | // SaveRestoreState |
| 266 | // Purpose: |
| 267 | // This function is called when Descent 3 is saving or restoring the game state. In this function |
| 268 | // you should save/restore any global data that you want preserved through load/save (which includes |
| 269 | // demos). You must be very careful with this function, corrupting the file (reading or writing too |
| 270 | // much or too little) may be hazardous to the game (possibly making it impossible to restore the |
| 271 | // state). It would be best to use version information to keep older versions of saved states still |
| 272 | // able to be used. IT IS VERY IMPORTANT WHEN SAVING THE STATE TO RETURN THE NUMBER OF _BYTES_ WROTE |
| 273 | // TO THE FILE. When restoring the data, the return value is ignored. saving_state is 1 when you should |
| 274 | // write data to the file_ptr, 0 when you should read in the data. |
| 275 | int STDCALL SaveRestoreState(void *file_ptr, uint8_t saving_state) { return 0; } |
| 276 | |
| 277 | int GetObjectType(int object) { |
| 278 | msafe_struct ms; |
| 279 | ms.objhandle = object; |
| 280 | MSafe_GetValue(MSAFE_OBJECT_TYPE, &ms); |
| 281 | |
| 282 | return ms.type; |
| 283 | } |
| 284 | |
| 285 | int GetObjectID(int object) { |
| 286 | msafe_struct ms; |
| 287 | ms.objhandle = object; |
| 288 | MSafe_GetValue(MSAFE_OBJECT_ID, &ms); |
| 289 | |
| 290 | return ms.id; |
| 291 | } |
| 292 | |
| 293 | int16_t FragCrate::CallEvent(int event, tOSIRISEventInfo *data) { |
| 294 | switch (event) { |
| 295 | case EVT_DESTROY: |
| 296 | vector pos; |
| 297 | float mag; |
| 298 | int weapon_id; |
| 299 | int handle; |
| 300 | int i; |
| 301 | int room; |
| 302 | |
| 303 | Obj_Value(data->me_handle, VF_GET, OBJV_I_ROOMNUM, &room); |
| 304 | Obj_Value(data->me_handle, VF_GET, OBJV_V_POS, &pos); |
| 305 | weapon_id = Wpn_FindID("fragbarrel"); |
| 306 | |
| 307 | handle = Obj_Create(OBJ_WEAPON, weapon_id, room, &pos, NULL, data->me_handle); |
| 308 | |
| 309 | break; |
| 310 | } |
| 311 | return CONTINUE_CHAIN | CONTINUE_DEFAULT; |
| 312 | } |
| 313 | |
| 314 | int16_t NapalmBarrel::CallEvent(int event, tOSIRISEventInfo *data) { |
| 315 | switch (event) { |
| 316 | case EVT_DESTROY: |
| 317 | vector pos; |
| 318 | float mag; |
| 319 | int weapon_id; |
| 320 | int handle; |
| 321 | int i; |
| 322 | int room; |
| 323 | matrix o, orient; |
| 324 | |
| 325 | Obj_Value(data->me_handle, VF_GET, OBJV_M_ORIENT, &o); |
| 326 | Obj_Value(data->me_handle, VF_GET, OBJV_I_ROOMNUM, &room); |
| 327 | Obj_Value(data->me_handle, VF_GET, OBJV_V_POS, &pos); |
| 328 | |
| 329 | orient.uvec = o.fvec; |
| 330 | orient.rvec = o.rvec; |
| 331 | orient.fvec = -o.uvec; |
| 332 | |
| 333 | weapon_id = Wpn_FindID("napalmbarrel"); |
| 334 | // weapon_id = Wpn_FindID("napalmrocket"); |
| 335 | |
| 336 | handle = Obj_Create(OBJ_WEAPON, weapon_id, room, &pos, &orient, data->me_handle); |
| 337 | |
| 338 | // Set direction |
| 339 | vector v; |
| 340 | float amount_r, amount_u; |
| 341 | amount_r = (float(rand()) - float(RAND_MAX) / 2.0f) / float(RAND_MAX); |
| 342 | amount_u = (float(rand()) - float(RAND_MAX) / 2.0f) / float(RAND_MAX); |
| 343 | v = amount_r * orient.rvec + amount_u * orient.uvec + orient.fvec; |
| 344 | vm_VectorNormalize(&v); |
| 345 | v *= 30.0f; |
| 346 | // v = orient.fvec*30.0f; |
| 347 | Obj_Value(handle, VF_SET, OBJV_V_VELOCITY, &v); |
| 348 | |
| 349 | break; |
| 350 | } |
| 351 | return CONTINUE_CHAIN | CONTINUE_DEFAULT; |
| 352 | } |
| 353 | |
| 354 | int16_t AliencuplinkScript::CallEvent(int event, tOSIRISEventInfo *data) { |
| 355 | switch (event) { |
| 356 | case EVT_AI_INIT: |
| 357 | int handle, id, room; |
| 358 | vector pos; |
| 359 | id = Obj_FindID("Aliencuplinkhousing"); |
| 360 | |
| 361 | if (id != -1) { |
| 362 | Obj_Value(data->me_handle, VF_GET, OBJV_I_ROOMNUM, &room); |
| 363 | Obj_Value(data->me_handle, VF_GET, OBJV_V_POS, &pos); |
| 364 | |
| 365 | handle = Obj_Create(OBJ_CLUTTER, id, room, &pos, NULL, data->me_handle); |
| 366 | |
| 367 | Obj_AttachObjectAP(data->me_handle, 0, handle, 0, 1); |
| 368 | } |
| 369 | break; |
| 370 | } |
| 371 | return CONTINUE_CHAIN | CONTINUE_DEFAULT; |
| 372 | } |
| 373 | |
| 374 | void ObjectDamage(int object, float amount, int killer = OBJECT_HANDLE_NONE); |
| 375 | void ObjectDamage(int object, float amount, int killer) { |
| 376 | msafe_struct mstruct; |
| 377 | |
| 378 | mstruct.objhandle = object; |
| 379 | mstruct.killer_handle = killer; |
| 380 | mstruct.damage_type = GD_SCRIPTED; |
| 381 | mstruct.amount = amount; |
| 382 | |
| 383 | MSafe_CallFunction(MSAFE_OBJECT_DAMAGE_OBJECT, &mstruct); |
| 384 | } |
| 385 | |
| 386 | float GetObjectShields(int object) { |
| 387 | msafe_struct mstruct; |
| 388 | |
| 389 | mstruct.objhandle = object; |
| 390 | MSafe_GetValue(MSAFE_OBJECT_SHIELDS, &mstruct); |
| 391 | |
| 392 | return mstruct.shields; |
| 393 | } |
| 394 | |
| 395 | int16_t TNTMedYield::CallEvent(int event, tOSIRISEventInfo *data) { |
| 396 | switch (event) { |
| 397 | case EVT_CREATED: { |
| 398 | int i; |
| 399 | tOSIRISMEMCHUNK ch; |
| 400 | ch.id = 4; |
| 401 | ch.size = sizeof(float); |
| 402 | ch.my_id.type = OBJECT_SCRIPT; |
| 403 | ch.my_id.objhandle = data->me_handle; |
| 404 | |
| 405 | memory = (float *)Scrpt_MemAlloc(&ch); |
| 406 | *memory = -1.0f; |
| 407 | } break; |
| 408 | |
| 409 | case EVT_MEMRESTORE: { |
| 410 | memory = (float *)data->evt_memrestore.memory_ptr; |
| 411 | } break; |
| 412 | |
| 413 | case EVT_INTERVAL: { |
| 414 | vector vel; |
| 415 | float vel_val; |
| 416 | float last_vel; |
| 417 | float delta_vel; |
| 418 | float frametime; |
| 419 | float accel; |
| 420 | |
| 421 | Obj_Value(data->me_handle, VF_GET, OBJV_V_VELOCITY, &vel); |
| 422 | vel_val = vm_GetMagnitude(&vel); |
| 423 | |
| 424 | frametime = Game_GetFrameTime(); |
| 425 | last_vel = *memory; |
| 426 | |
| 427 | if (last_vel != -1.0f) { |
| 428 | delta_vel = vel_val - last_vel; |
| 429 | accel = delta_vel / frametime; |
| 430 | |
| 431 | if (accel <= 0.0002f) { |
| 432 | // blow him up |
| 433 | Obj_Kill(data->me_handle, OBJECT_HANDLE_NONE, 1000.0f, |
| 434 | DF_BLAST_RING | DF_LOSES_ANTIGRAV | DF_EXPL_MEDIUM | DF_FIREBALL | DF_BREAKS_APART | DF_DEBRIS_SMOKES, |
| 435 | 0.0f, 0.0f); |
| 436 | } |
| 437 | } |
| 438 | |
| 439 | *memory = vel_val; |
| 440 | } break; |
| 441 | } |
| 442 | |
| 443 | return CONTINUE_CHAIN | CONTINUE_DEFAULT; |
| 444 | } |
| 445 | |
| 446 | int16_t TNTHighYield::CallEvent(int event, tOSIRISEventInfo *data) { |
| 447 | switch (event) { |
| 448 | case EVT_CREATED: { |
| 449 | int i; |
| 450 | tOSIRISMEMCHUNK ch; |
| 451 | ch.id = 4; |
| 452 | ch.size = sizeof(tTNTHighYield); |
| 453 | ch.my_id.type = OBJECT_SCRIPT; |
| 454 | ch.my_id.objhandle = data->me_handle; |
| 455 | |
| 456 | memory = (tTNTHighYield *)Scrpt_MemAlloc(&ch); |
| 457 | vm_MakeZero(&memory->last_vel); |
| 458 | memory->lifetime = 0; |
| 459 | |
| 460 | } break; |
| 461 | |
| 462 | case EVT_MEMRESTORE: { |
| 463 | memory = (tTNTHighYield *)data->evt_memrestore.memory_ptr; |
| 464 | } break; |
| 465 | |
| 466 | case EVT_INTERVAL: { |
| 467 | vector vel; |
| 468 | vector diff_vel; |
| 469 | float vel_val; |
| 470 | float delta_vel; |
| 471 | float frametime; |
| 472 | float accel; |
| 473 | |
| 474 | Obj_Value(data->me_handle, VF_GET, OBJV_V_VELOCITY, &vel); |
| 475 | vel_val = vm_GetMagnitude(&vel); |
| 476 | |
| 477 | frametime = Game_GetFrameTime(); |
| 478 | diff_vel = vel - (memory->last_vel); |
| 479 | memory->lifetime += frametime; |
| 480 | |
| 481 | delta_vel = vm_GetMagnitude(&diff_vel); |
| 482 | |
| 483 | accel = fabs(delta_vel / frametime); |
| 484 | |
| 485 | bool case1 = (accel >= 40.0f && vel_val > 35.0f && memory->last_vel.y < -6.0f) ? true : false; |
| 486 | bool case2 = (accel > 100.0f && vel_val > 50.0f) ? true : false; |
| 487 | bool case3 = (accel > 1500.0f && memory->last_vel.y < -5.0f) ? true : false; |
| 488 | |
| 489 | if (case1 || case2 || case3) { |
| 490 | if (case1) |
| 491 | mprintf(0, "Case 1\n"); |
| 492 | if (case2) |
| 493 | mprintf(0, "Case 2\n"); |
| 494 | if (case3) |
| 495 | mprintf(0, "Case 3\n"); |
| 496 | |
| 497 | // blow him up |
| 498 | mprintf(0, "accel: %.2f vel: %.2f\n", accel, vel_val); |
| 499 | if (memory->lifetime >= 7.0f) { |
| 500 | Obj_Kill(data->me_handle, OBJECT_HANDLE_NONE, 1000.0f, |
| 501 | DF_BLAST_RING | DF_LOSES_ANTIGRAV | DF_EXPL_MEDIUM | DF_FIREBALL | DF_BREAKS_APART | DF_DEBRIS_SMOKES, |
| 502 | 0.0f, 0.0f); |
| 503 | } |
| 504 | } |
| 505 | |
| 506 | memory->last_vel = vel; |
| 507 | } break; |
| 508 | |
| 509 | case EVT_DESTROY: { |
| 510 | // see if we are within distance of the rock pile to destroy |
| 511 | int close_obj_list[32]; |
| 512 | int roomnum; |
| 513 | int rockpile_id; |
| 514 | float amount; |
| 515 | vector pos; |
| 516 | |
| 517 | Obj_Value(data->me_handle, VF_GET, OBJV_I_ROOMNUM, &roomnum); |
| 518 | Obj_Value(data->me_handle, VF_GET, OBJV_V_POS, &pos); |
| 519 | int num_objects = AI_GetNearbyObjs(&pos, roomnum, 30.0f, close_obj_list, 32, false, false, false, true); |
| 520 | |
| 521 | rockpile_id = Obj_FindID("TNTrockwall"); |
| 522 | |
| 523 | for (int i = 0; i < num_objects; i++) { |
| 524 | int type, id; |
| 525 | |
| 526 | type = GetObjectType(close_obj_list[i]); |
| 527 | id = GetObjectID(close_obj_list[i]); |
| 528 | |
| 529 | if (type == OBJ_CLUTTER && id == rockpile_id) { |
| 530 | // destroy the wall |
| 531 | Obj_Kill(close_obj_list[i], data->me_handle, 1000.0f, |
| 532 | DF_BLAST_RING | DF_LOSES_ANTIGRAV | DF_EXPL_MEDIUM | DF_FIREBALL | DF_BREAKS_APART | DF_DEBRIS_SMOKES, |
| 533 | 0.0f, 0.0f); |
| 534 | } |
| 535 | } |
| 536 | |
| 537 | } break; |
| 538 | } |
| 539 | |
| 540 | return CONTINUE_CHAIN | CONTINUE_DEFAULT; |
| 541 | } |
| 542 | |
| 543 | int16_t FallingRock::CallEvent(int event, tOSIRISEventInfo *data) { |
| 544 | switch (event) { |
| 545 | case EVT_CREATED: { |
| 546 | int i; |
| 547 | tOSIRISMEMCHUNK ch; |
| 548 | ch.id = 4; |
| 549 | ch.size = sizeof(tFallingRock); |
| 550 | ch.my_id.type = OBJECT_SCRIPT; |
| 551 | ch.my_id.objhandle = data->me_handle; |
| 552 | |
| 553 | memory = (tFallingRock *)Scrpt_MemAlloc(&ch); |
| 554 | memory->lifeleft = 10.0f; |
| 555 | } break; |
| 556 | |
| 557 | case EVT_MEMRESTORE: { |
| 558 | memory = (tFallingRock *)data->evt_memrestore.memory_ptr; |
| 559 | } break; |
| 560 | |
| 561 | case EVT_INTERVAL: { |
| 562 | if (memory) { |
| 563 | memory->lifeleft -= data->evt_interval.frame_time; |
| 564 | |
| 565 | if (memory->lifeleft <= 0) { |
| 566 | // destroy the wall |
| 567 | Obj_Kill(data->me_handle, OBJECT_HANDLE_NONE, 1000.0f, DF_EXPL_SMALL | DF_FIREBALL | DF_DEBRIS_SMOKES, 0.0f, |
| 568 | 0.0f); |
| 569 | } |
| 570 | } |
| 571 | } break; |
| 572 | } |
| 573 | |
| 574 | return CONTINUE_CHAIN | CONTINUE_DEFAULT; |
| 575 | } |
| 576 | |
| 577 | int16_t LavaRock::CallEvent(int event, tOSIRISEventInfo *data) { |
| 578 | switch (event) { |
| 579 | case EVT_CREATED: { |
| 580 | int i; |
| 581 | tOSIRISMEMCHUNK ch; |
| 582 | ch.id = 4; |
| 583 | ch.size = sizeof(tFallingRock); |
| 584 | ch.my_id.type = OBJECT_SCRIPT; |
| 585 | ch.my_id.objhandle = data->me_handle; |
| 586 | |
| 587 | memory = (tFallingRock *)Scrpt_MemAlloc(&ch); |
| 588 | memory->lifeleft = 20.0f; |
| 589 | |
| 590 | // Set it on fire! |
| 591 | msafe_struct mstruct; |
| 592 | mstruct.objhandle = data->me_handle; |
| 593 | mstruct.longevity = 25.0f; |
| 594 | mstruct.interval = 0.0f; |
| 595 | mstruct.ithandle = OBJECT_HANDLE_NONE; |
| 596 | MSafe_CallFunction(MSAFE_OBJECT_SETONFIRE, &mstruct); |
| 597 | |
| 598 | } break; |
| 599 | |
| 600 | case EVT_MEMRESTORE: { |
| 601 | memory = (tFallingRock *)data->evt_memrestore.memory_ptr; |
| 602 | } break; |
| 603 | |
| 604 | case EVT_COLLIDE: { |
| 605 | // Set it on fire! |
| 606 | msafe_struct mstruct; |
| 607 | mstruct.objhandle = data->evt_collide.it_handle; |
| 608 | mstruct.longevity = 2.0f; |
| 609 | mstruct.interval = 2.0f; |
| 610 | mstruct.ithandle = data->me_handle; |
| 611 | MSafe_CallFunction(MSAFE_OBJECT_SETONFIRE, &mstruct); |
| 612 | |
| 613 | } break; |
| 614 | |
| 615 | case EVT_INTERVAL: { |
| 616 | if (memory) { |
| 617 | memory->lifeleft -= data->evt_interval.frame_time; |
| 618 | |
| 619 | if (memory->lifeleft <= 0) { |
| 620 | // destroy the wall |
| 621 | Obj_Kill(data->me_handle, OBJECT_HANDLE_NONE, 1000.0f, DF_EXPL_SMALL | DF_FIREBALL | DF_DEBRIS_SMOKES, 0.0f, |
| 622 | 0.0f); |
| 623 | } |
| 624 | } |
| 625 | } break; |
| 626 | } |
| 627 | |
| 628 | return CONTINUE_CHAIN | CONTINUE_DEFAULT; |
| 629 | } |