1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681
|
/*
* Descent 3
* Copyright (C) 2024 Parallax Software
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
// generic.cpp
// 0.1
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cstdarg>
#include "osiris_import.h"
#include "osiris_common.h"
#include "module.h"
#ifdef __cplusplus
extern "C" {
#endif
DLLEXPORT char STDCALL InitializeDLL(tOSIRISModuleInit *func_list);
DLLEXPORT void STDCALL ShutdownDLL(void);
DLLEXPORT int STDCALL GetGOScriptID(const char *name, uint8_t isdoor);
DLLEXPORT void STDCALLPTR CreateInstance(int id);
DLLEXPORT void STDCALL DestroyInstance(int id, void *ptr);
DLLEXPORT int16_t STDCALL CallInstanceEvent(int id, void *ptr, int event, tOSIRISEventInfo *data);
DLLEXPORT int STDCALL SaveRestoreState(void *file_ptr, uint8_t saving_state);
#ifdef __cplusplus
}
#endif
int String_table_size = 0;
char **String_table = NULL;
static const char *_Error_string = "!!ERROR MISSING STRING!!";
static const char *_Empty_string = "";
const char *GetStringFromTable(int index) {
if ((index < 0) || (index >= String_table_size))
return _Error_string;
if (!String_table[index])
return _Empty_string;
return String_table[index];
}
#define TXT(x) GetStringFromTable(x)
#define TXT_DOORLOCKED TXT(0) //"Door Locked!"
#define TXT_RAPIDFIRE TXT(1) //"Rapid Fire!"
#define TXT_FORCEWALL TXT(2) //"Force Wall!"
#define TXT_FORCEWALLEJECT TXT(3) //"Force Wall Ejected!"
#define TXT_FORCEWALLDONE TXT(4) //"Force Wall Done!"
#define TXT_WINGNUT TXT(5) //"WingNut!"
#define TXT_RAPIDFIREOFF TXT(6) //"Rapid Fire Off!"
// ================
// Helper Functions
// ================
void AddHudMessage(int player_objhandle, int color, const char *format, ...);
#define ID_RAPIDFIRE 0
#define ID_FORCEWALL 1
#define ID_WINGNUT 2
#define NUM_IDS 3
// Common Powerups
// Weapon Powerups
// Ammo Powerups
#define GENERIC_POWERUP_SCRIPTID NUM_IDS
// Generic Door Script
#define GENERIC_DOOR_SCRIPTID NUM_IDS + 1
struct tScriptIDInfo {
int id;
const char *name;
};
tScriptIDInfo ScriptIDInfo[NUM_IDS] = {
{ID_RAPIDFIRE, "RapidFire"}, {ID_FORCEWALL, "Forcewall"}, {ID_WINGNUT, "GoWingNut"}};
class GenericScript {
public:
GenericScript() {}
virtual int16_t CallEvent(int event, tOSIRISEventInfo *data);
protected:
};
class GenericDoor : public GenericScript {
public:
GenericDoor() {}
int16_t CallEvent(int event, tOSIRISEventInfo *data);
};
struct forcewallmemory {
int object_handle;
};
class ForceWallScript : public GenericScript {
public:
ForceWallScript();
int16_t CallEvent(int event, tOSIRISEventInfo *data);
forcewallmemory *memory;
};
class WingNutScript : public GenericScript {
public:
WingNutScript() {}
int16_t CallEvent(int event, tOSIRISEventInfo *data);
};
struct tPlayerTimerInfo {
int timer_handle;
};
tPlayerTimerInfo RapidFirePlayerTimers[MAX_PLAYERS];
struct rapidfirememory {
int collided_object;
uint8_t collided_pnum;
};
class RapidFireScript : public GenericScript {
public:
RapidFireScript();
int16_t CallEvent(int event, tOSIRISEventInfo *data);
rapidfirememory *memory;
};
// InitializeDLL
// Purpose:
// This function gets called when the DLL first gets loaded. It will only be called once (until the
// DLL is unloaded). Passed in is a struct of data passed from the game needed for the DLL to interact
// with D3. Usually this function will just call osicommon_Initialize(), which sets up the imported
// functions. However, you can alloc some memory or whatever in this function, and free it in ShutdownDLL().
// Note: You cannot call any imported functions until osicommon_Initialize() is called.
// Returns 1 if initialization went ok, 0 if there was an error and the DLL should not be loaded.
char STDCALL InitializeDLL(tOSIRISModuleInit *func_list) {
osicommon_Initialize((tOSIRISModuleInit *)func_list);
if (func_list->game_checksum != CHECKSUM) {
mprintf(0, "Game-Checksum FAIL!!! (%ul!=%ul)\n", func_list->game_checksum, CHECKSUM);
mprintf(0, "RECOMPILE YOUR SCRIPTS!!!\n");
return 0;
}
String_table_size = func_list->string_count;
String_table = func_list->string_table;
int i;
// initialize rapid fire script data
for (i = 0; i < MAX_PLAYERS; i++) {
RapidFirePlayerTimers[i].timer_handle = -1;
}
return 1;
}
// ShutdownDLL
// Purpose:
// This function is called right before a DLL is about to be unloaded from memory. You can free
// any unfree'd memory, or anything else you need to do. Don't worry about destroying any instances
// of scripts, as they will all be automatically destroyed before this function is called. The
// same goes for any memory allocated with Scrpt_MemAlloc(), as this will automatically be freed
// when a scripts instance is destroyed.
void STDCALL ShutdownDLL(void) {}
// GetGOScriptID
// Purpose:
// Given the name of the object (from it's pagename), this function will search through it's
// list of General Object Scripts for a script with a matching name (to see if there is a script
// for that type/id of object within this DLL). If a matching scriptname is found, a UNIQUE ID
// is to be returned back to Descent 3. This ID will be used from here on out for all future
// interaction with the DLL. Since doors are not part of the generic object's, it's possible
// for a door to have the same name as a generic object (OBJ_POWERUP, OBJ_BUILDING, OBJ_CLUTTER
// or OBJ_ROBOT), therefore, a 1 is passed in for isdoor if the given object name refers to a
// door, else it is a 0. The return value is the unique identifier, else -1 if the script
// does not exist in the DLL.
int STDCALL GetGOScriptID(const char *name, uint8_t isdoor) {
if (!isdoor) {
for (int i = 0; i < NUM_IDS; i++) {
if (!stricmp(ScriptIDInfo[i].name, name))
return ScriptIDInfo[i].id;
}
}
return (isdoor) ? GENERIC_DOOR_SCRIPTID : GENERIC_POWERUP_SCRIPTID;
}
// CreateInstance
// Purpose:
// Given an ID from a call to GetGOScriptID(), this function will create a new instance for that
// particular script (by allocating and initializing memory, etc.). A pointer to this instance
// is to be returned back to Descent 3. This pointer will be passed around, along with the ID
// for CallInstanceEvent() and DestroyInstance(). Return NULL if there was an error.
void STDCALLPTR CreateInstance(int id) {
switch (id) {
case GENERIC_POWERUP_SCRIPTID:
return new GenericScript;
break;
case GENERIC_DOOR_SCRIPTID:
return new GenericDoor;
break;
case ID_RAPIDFIRE:
return new RapidFireScript;
break;
case ID_WINGNUT:
return new WingNutScript;
break;
case ID_FORCEWALL:
return new ForceWallScript;
break;
};
return NULL;
}
// DestroyInstance
// Purpose:
// Given an ID, and a pointer to a particular instance of a script, this function will delete and
// destruct all information associated with that script, so it will no longer exist.
void STDCALL DestroyInstance(int id, void *ptr) {
switch (id) {
case GENERIC_POWERUP_SCRIPTID:
delete ((GenericScript *)ptr);
break;
case GENERIC_DOOR_SCRIPTID:
delete ((GenericDoor *)ptr);
break;
case ID_RAPIDFIRE:
delete ((RapidFireScript *)ptr);
break;
case ID_WINGNUT:
delete ((WingNutScript *)ptr);
break;
case ID_FORCEWALL:
delete ((ForceWallScript *)ptr);
break;
};
}
// CallInstanceEvent
// Purpose:
// Given an ID, a pointer to a script instance, an event and a pointer to the struct of
// information about the event, this function will translate who this event belongs to and
// passes the event to that instance of the script to be handled. Return a combination of
// CONTINUE_CHAIN and CONTINUE_DEFAULT, to give instructions on what to do based on the
// event. CONTINUE_CHAIN means to continue through the chain of scripts (custom script, level
// script, mission script, and finally default script). If CONTINUE_CHAIN is not specified,
// than the chain is broken and those scripts of lower priority will never get the event. Return
// CONTINUE_DEFAULT in order to tell D3 if you want process the normal action that is built into
// the game for that event. This only pertains to certain events. If the chain continues
// after this script, than the CONTINUE_DEFAULT setting will be overridden by lower priority
// scripts return value.
int16_t STDCALL CallInstanceEvent(int id, void *ptr, int event, tOSIRISEventInfo *data) {
switch (id) {
case GENERIC_POWERUP_SCRIPTID:
case GENERIC_DOOR_SCRIPTID:
case ID_RAPIDFIRE:
case ID_FORCEWALL:
case ID_WINGNUT:
return ((GenericScript *)ptr)->CallEvent(event, data);
break;
};
return CONTINUE_CHAIN | CONTINUE_DEFAULT;
}
// SaveRestoreState
// Purpose:
// This function is called when Descent 3 is saving or restoring the game state. In this function
// you should save/restore any global data that you want preserved through load/save (which includes
// demos). You must be very careful with this function, corrupting the file (reading or writing too
// much or too little) may be hazardous to the game (possibly making it impossible to restore the
// state). It would be best to use version information to keep older versions of saved states still
// able to be used. IT IS VERY IMPORTANT WHEN SAVING THE STATE TO RETURN THE NUMBER OF _BYTES_ WROTE
// TO THE FILE. When restoring the data, the return value is ignored. saving_state is 1 when you should
// write data to the file_ptr, 0 when you should read in the data.
#define VERSION 0x01
int STDCALL SaveRestoreState(void *file_ptr, uint8_t saving_state) {
int size = 0;
int i;
int version = VERSION;
if (saving_state) {
File_WriteByte(VERSION, file_ptr);
size++;
// save out rapid fire data
for (i = 0; i < MAX_PLAYERS; i++) {
File_WriteInt(RapidFirePlayerTimers[i].timer_handle, file_ptr);
size += sizeof(int);
}
} else {
version = File_ReadByte(file_ptr);
size++;
// restore rapid fire data
for (i = 0; i < MAX_PLAYERS; i++) {
RapidFirePlayerTimers[i].timer_handle = File_ReadInt(file_ptr);
size += sizeof(int);
}
}
return size;
}
int16_t GenericScript::CallEvent(int event, tOSIRISEventInfo *data) {
switch (event) {
case EVT_COLLIDE: {
msafe_struct ms;
ms.objhandle = data->evt_collide.it_handle;
MSafe_GetValue(MSAFE_OBJECT_TYPE, &ms);
if (ms.type == OBJ_PLAYER) {
ms.objhandle = data->me_handle;
ms.ithandle = data->evt_collide.it_handle;
ms.playsound = 1;
MSafe_DoPowerup(&ms);
return CONTINUE_CHAIN | CONTINUE_DEFAULT;
}
} break;
}
return CONTINUE_CHAIN | CONTINUE_DEFAULT;
}
int16_t GenericDoor::CallEvent(int event, tOSIRISEventInfo *data) {
switch (event) {
case EVT_COLLIDE: {
msafe_struct ms;
ms.objhandle = data->me_handle;
MSafe_GetValue(MSAFE_OBJECT_TYPE, &ms);
if (ms.type == OBJ_DOOR) {
msafe_struct mit;
mit.objhandle = data->evt_collide.it_handle;
MSafe_GetValue(MSAFE_OBJECT_TYPE, &mit);
if (mit.type == OBJ_CLUTTER) {
break;
}
// See if door is openable
ms.ithandle = data->evt_collide.it_handle;
MSafe_GetValue(MSAFE_DOOR_OPENABLE, &ms);
if (ms.state) {
// openable door
MSafe_CallFunction(MSAFE_DOOR_ACTIVATE, &ms);
} else {
// non-openable door. If locked, give a message
MSafe_GetValue(MSAFE_DOOR_LOCK_STATE, &ms);
if (ms.state) { // locked!
ms.objhandle = data->evt_collide.it_handle;
MSafe_GetValue(MSAFE_OBJECT_PARENT, &ms);
MSafe_GetValue(MSAFE_OBJECT_TYPE, &ms);
if (ms.type == OBJ_PLAYER) {
strcpy(ms.message, TXT_DOORLOCKED);
ms.color = GR_RGB(0, 255, 0);
MSafe_CallFunction(MSAFE_MISC_FILTERED_HUD_MESSAGE, &ms);
ms.state = 1; // specific player
ms.index = Scrpt_FindSoundName("DoorIsLocked");
ms.volume = 0.80f;
if (ms.index != -1)
MSafe_CallFunction(MSAFE_SOUND_2D, &ms);
}
}
}
}
} break;
}
return CONTINUE_CHAIN | CONTINUE_DEFAULT;
}
RapidFireScript::RapidFireScript() { memory = NULL; }
#define RAPIDFIRE_RECHARGE 0.7f
int16_t RapidFireScript::CallEvent(int event, tOSIRISEventInfo *data) {
switch (event) {
case EVT_CREATED: {
tOSIRISMEMCHUNK ch;
ch.id = 4;
ch.size = sizeof(rapidfirememory);
ch.my_id.type = OBJECT_SCRIPT;
ch.my_id.objhandle = data->me_handle;
memory = (rapidfirememory *)Scrpt_MemAlloc(&ch);
memory->collided_pnum = 255;
memory->collided_object = OBJECT_HANDLE_NONE;
} break;
case EVT_MEMRESTORE: {
memory = (rapidfirememory *)data->evt_memrestore.memory_ptr;
} break;
case EVT_COLLIDE: {
if (!memory)
break;
msafe_struct ms;
ms.objhandle = data->evt_collide.it_handle;
MSafe_GetValue(MSAFE_OBJECT_TYPE, &ms);
if (ms.type == OBJ_PLAYER) {
AddHudMessage(data->evt_collide.it_handle, GR_RGB(0, 255, 0), TXT_RAPIDFIRE);
int sound_id = Sound_FindId("RapidFireOn");
Sound_Play3d(data->me_handle, sound_id);
MSafe_GetValue(MSAFE_OBJECT_ID, &ms);
memory->collided_pnum = ms.id;
memory->collided_object = data->evt_collide.it_handle;
if (RapidFirePlayerTimers[memory->collided_pnum].timer_handle != -1) {
// check to see if the player currently has rapid fire
MSafe_GetValue(MSAFE_OBJECT_RECHARGE_SCALAR, &ms);
if (ms.scalar == RAPIDFIRE_RECHARGE) {
// the player currently has rapid fire
// the player possibly has rapid fire set, check to make sure
if (Scrpt_TimerExists(RapidFirePlayerTimers[memory->collided_pnum].timer_handle)) {
// cancel the old timer so we can create a new timer (give them more time)
Scrpt_CancelTimer(RapidFirePlayerTimers[memory->collided_pnum].timer_handle);
}
RapidFirePlayerTimers[memory->collided_pnum].timer_handle = -1;
} else {
// rapid fire was stolen from the player
}
}
memory->collided_pnum = ms.id;
tOSIRISTIMER ti;
ti.flags = OTF_CANCELONDEAD;
ti.id = 31;
ti.object_handle = data->me_handle;
ti.object_handle_detonator = data->evt_collide.it_handle;
ti.timer_interval = 30;
RapidFirePlayerTimers[memory->collided_pnum].timer_handle = Scrpt_CreateTimer(&ti);
// ghost the object
ms.objhandle = data->me_handle;
MSafe_CallFunction(MSAFE_OBJECT_GHOST, &ms);
// set player scalar
ms.objhandle = data->evt_collide.it_handle;
ms.scalar = RAPIDFIRE_RECHARGE;
MSafe_CallFunction(MSAFE_OBJECT_RECHARGE_SCALAR, &ms);
}
} break;
case EVT_TIMER: {
if (!memory)
break;
msafe_struct ms;
ms.objhandle = memory->collided_object;
MSafe_GetValue(MSAFE_OBJECT_RECHARGE_SCALAR, &ms);
if (ms.scalar == RAPIDFIRE_RECHARGE) {
// reset recharge scalar
ms.objhandle = memory->collided_object;
ms.scalar = 1.0f;
MSafe_CallFunction(MSAFE_OBJECT_RECHARGE_SCALAR, &ms);
RapidFirePlayerTimers[memory->collided_pnum].timer_handle = -1;
}
AddHudMessage(memory->collided_object, GR_RGB(0, 255, 0), TXT_RAPIDFIREOFF);
int sound_id = Sound_FindId("RapidFireOff");
Sound_Play3d(memory->collided_object, sound_id);
// destroy the powerup
ms.objhandle = data->me_handle;
ms.playsound = 0;
MSafe_CallFunction(MSAFE_OBJECT_REMOVE, &ms);
} break;
case EVT_TIMERCANCEL: {
msafe_struct ms;
// destroy the powerup
ms.playsound = 0;
ms.objhandle = data->me_handle;
MSafe_CallFunction(MSAFE_OBJECT_REMOVE, &ms);
} break;
case EVT_INTERVAL: {
// check (if we are ghosted...meaning picked up) if the player
// that picked us up still has rapid fire
if (memory && memory->collided_pnum != 255) {
// check the player to make sure he is still charged up
msafe_struct ms;
ms.objhandle = memory->collided_object;
MSafe_GetValue(MSAFE_OBJECT_RECHARGE_SCALAR, &ms);
if (ms.scalar != RAPIDFIRE_RECHARGE) {
// player no longer recharged! cancel timer
if (Scrpt_TimerExists(RapidFirePlayerTimers[memory->collided_pnum].timer_handle)) {
// cancel the timer
mprintf(0, "CANCELING RAPID FIRE TIMER FOR PLAYER %d\n", memory->collided_pnum);
Scrpt_CancelTimer(RapidFirePlayerTimers[memory->collided_pnum].timer_handle);
AddHudMessage(memory->collided_object, GR_RGB(0, 255, 0), TXT_RAPIDFIREOFF);
int sound_id = Sound_FindId("RapidFireOff");
Sound_Play3d(memory->collided_object, sound_id);
}
RapidFirePlayerTimers[memory->collided_pnum].timer_handle = -1;
memory->collided_pnum = 255;
memory->collided_object = OBJECT_HANDLE_NONE;
}
}
} break;
}
return CONTINUE_CHAIN | CONTINUE_DEFAULT;
}
ForceWallScript::ForceWallScript() { memory = NULL; }
int16_t ForceWallScript::CallEvent(int event, tOSIRISEventInfo *data) {
switch (event) {
case EVT_CREATED: {
tOSIRISMEMCHUNK ch;
ch.id = 4;
ch.size = sizeof(forcewallmemory);
ch.my_id.type = OBJECT_SCRIPT;
ch.my_id.objhandle = data->me_handle;
memory = (forcewallmemory *)Scrpt_MemAlloc(&ch);
memory->object_handle = OBJECT_HANDLE_NONE;
} break;
case EVT_MEMRESTORE: {
memory = (forcewallmemory *)data->evt_memrestore.memory_ptr;
} break;
case EVT_COLLIDE: {
if (!memory)
break;
msafe_struct ms;
ms.objhandle = data->evt_collide.it_handle;
MSafe_GetValue(MSAFE_OBJECT_TYPE, &ms);
int pnum;
if (ms.type == OBJ_PLAYER) {
MSafe_GetValue(MSAFE_OBJECT_ID, &ms);
pnum = ms.id;
AddHudMessage(data->evt_collide.it_handle, GR_RGB(0, 255, 0), TXT_FORCEWALL);
// add a force wall to the inventory
ms.objhandle = data->me_handle;
MSafe_GetValue(MSAFE_OBJECT_ID, &ms);
ms.slot = pnum;
ms.type = OBJ_POWERUP;
ms.flags = INVAF_TIMEOUTONSPEW;
MSafe_CallFunction(MSAFE_INVEN_ADD_TYPE_ID, &ms);
// pickit up
ms.playsound = 1;
MSafe_CallFunction(MSAFE_OBJECT_REMOVE, &ms);
}
} break;
case EVT_USE: {
if (!memory)
break;
msafe_struct ms;
// Eject a ForceWall and make it last for 60 seconds
memory->object_handle = data->evt_use.it_handle; // save the player for when the timer is up
AddHudMessage(memory->object_handle, GR_RGB(0, 255, 0), TXT_FORCEWALLEJECT);
// ghost the object and set a timer
tOSIRISTIMER ti;
ti.flags = 0; // not a volatile object when dropped
ti.id = 32;
ti.object_handle = data->me_handle;
ti.timer_interval = 60;
Scrpt_CreateTimer(&ti);
// ghost the object
ms.objhandle = data->me_handle;
MSafe_CallFunction(MSAFE_OBJECT_GHOST, &ms);
// Do the Force Wall stuff here
} break;
case EVT_TIMER: {
if (!memory)
break;
msafe_struct ms;
// End Force Wall stuff here
AddHudMessage(memory->object_handle, GR_RGB(0, 255, 0), TXT_FORCEWALLDONE);
// UnGhost the object
ms.objhandle = data->me_handle;
//@@MSafe_CallFunction(MSAFE_OBJECT_UNGHOST,&ms);
// destroy the powerup
ms.playsound = 0;
MSafe_CallFunction(MSAFE_OBJECT_REMOVE, &ms);
} break;
}
return CONTINUE_CHAIN | CONTINUE_DEFAULT;
}
int16_t WingNutScript::CallEvent(int event, tOSIRISEventInfo *data) {
switch (event) {
case EVT_COLLIDE: {
msafe_struct ms;
ms.objhandle = data->evt_collide.it_handle;
MSafe_GetValue(MSAFE_OBJECT_TYPE, &ms);
int pnum;
if (ms.type == OBJ_PLAYER) {
MSafe_GetValue(MSAFE_OBJECT_ID, &ms);
pnum = ms.id;
AddHudMessage(data->evt_collide.it_handle, GR_RGB(0, 255, 0), TXT_WINGNUT);
// add a wing nut to the inventory
ms.objhandle = data->me_handle;
MSafe_GetValue(MSAFE_OBJECT_ID, &ms);
ms.slot = pnum;
ms.type = OBJ_POWERUP;
ms.flags = INVAF_TIMEOUTONSPEW;
MSafe_CallFunction(MSAFE_INVEN_ADD_TYPE_ID, &ms);
// pickit up
ms.playsound = 1;
MSafe_CallFunction(MSAFE_OBJECT_REMOVE, &ms);
}
} break;
case EVT_USE: {
} break;
}
return CONTINUE_CHAIN | CONTINUE_DEFAULT;
}
void AddHudMessage(int player_objhandle, int color, const char *format, ...) {
msafe_struct ms;
ms.objhandle = player_objhandle;
MSafe_GetValue(MSAFE_OBJECT_TYPE, &ms);
if (ms.type == OBJ_PLAYER) {
MSafe_GetValue(MSAFE_OBJECT_ID, &ms);
ms.slot = ms.id;
ms.color = color;
char big_buffer[1024];
va_list marker;
va_start(marker, format);
std::vsnprintf(big_buffer, sizeof(big_buffer), format, marker);
va_end(marker);
strncpy(ms.message, big_buffer, MSAFE_MESSAGE_LENGTH - 1);
ms.message[MSAFE_MESSAGE_LENGTH - 1] = '\0';
MSafe_CallFunction(MSAFE_MISC_FILTERED_HUD_MESSAGE, &ms);
}
}
|