| 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 | --- HISTORICAL COMMENTS FOLLOW --- |
| 19 | |
| 20 | * $Logfile: /DescentIII/main/osiris_predefs.cpp $ |
| 21 | * $Revision: 128 $ |
| 22 | * $Date: 4/13/00 2:31p $ |
| 23 | * $Author: Matt $ |
| 24 | * |
| 25 | * implementation code for osiris predefined functions |
| 26 | * |
| 27 | * $Log: /DescentIII/main/osiris_predefs.cpp $ |
| 28 | * |
| 29 | * 128 4/13/00 2:31p Matt |
| 30 | * Don't allow scripts to kill the guidebot. |
| 31 | * |
| 32 | * 127 11/05/99 4:28p Jay |
| 33 | * Made sure the wb is a valid index |
| 34 | * |
| 35 | * 126 11/04/99 3:08p Jeff |
| 36 | * fixed uint16_t check with -1 bug |
| 37 | * |
| 38 | * 125 11/03/99 10:20a Chris |
| 39 | * Added the ability to find out if a room is volatile |
| 40 | * |
| 41 | * 124 11/02/99 12:16p Chris |
| 42 | * More Merc code - added support for ignore_obj_lists for the Osiris |
| 43 | * RayCast function |
| 44 | * |
| 45 | * 123 10/27/99 4:19p 3dsmax |
| 46 | * added cloak flag for object value get |
| 47 | * |
| 48 | * 122 10/23/99 2:43a Chris |
| 49 | * Added the PutObjectOnObject AI Goal |
| 50 | * |
| 51 | * 121 10/22/99 11:31a Matt |
| 52 | * Mac merge |
| 53 | * |
| 54 | * 120 10/20/99 5:40p Chris |
| 55 | * Added the Red Guidebot |
| 56 | * |
| 57 | * 119 10/19/99 10:18p 3dsmax |
| 58 | * error check object name retreival. |
| 59 | * |
| 60 | * 118 10/16/99 9:56p Jeff |
| 61 | * added a way to strip all players of all weapons and energy |
| 62 | * |
| 63 | * 117 10/16/99 8:46p Jeff |
| 64 | * player value function to strip a player of weapons and energy |
| 65 | * |
| 66 | * 116 10/12/99 12:44p Jeff |
| 67 | * added obj_value things for negative light and virus infection |
| 68 | * |
| 69 | * 115 9/13/99 12:26p Samir |
| 70 | * added AIG_GUARD_AREA to add goal, since it exits in AIGoal.cpp already. |
| 71 | * |
| 72 | * 114 9/10/99 11:03a Samir |
| 73 | * added command to get object's name from Obj_Value. |
| 74 | * |
| 75 | * 113 5/23/99 5:50p Chris |
| 76 | * Fixed problems with msafe send on over non-changed information |
| 77 | * |
| 78 | * 112 5/23/99 12:33a Chris |
| 79 | * Cannot change the control type of dying objects |
| 80 | * |
| 81 | * 111 5/21/99 7:29a Chris |
| 82 | * More tweaking... |
| 83 | * |
| 84 | * 110 5/20/99 1:16a Chris |
| 85 | * Fixed the AIV_I_TARGET_HANDLE set function |
| 86 | * |
| 87 | * 109 5/19/99 3:25p Jason |
| 88 | * fixed wrong ordering of InitObjectScripts and MultiSendObject |
| 89 | * |
| 90 | * 108 5/12/99 8:03p Jason |
| 91 | * fixed bug where multiplayer and demo code was playing a sound before an |
| 92 | * object was even created |
| 93 | * |
| 94 | * 107 5/12/99 6:18a Chris |
| 95 | * GetNearby objects doesn't return dead or RT_NONE objects |
| 96 | * |
| 97 | * 106 5/10/99 8:21a Chris |
| 98 | * FindNearby... ignores dead objects (OF_DEAD) |
| 99 | * |
| 100 | * 105 5/10/99 12:23a Chris |
| 101 | * Fixed another hearing/seeing case. :) Buddy bot now is in the player |
| 102 | * ship at respawn |
| 103 | * |
| 104 | * 104 5/07/99 1:32p Jeff |
| 105 | * made osipf for sounds multisafe |
| 106 | * |
| 107 | * 103 5/06/99 4:54p Matt |
| 108 | * Fixed array bounds error. |
| 109 | * |
| 110 | * 102 5/05/99 4:56p Chris |
| 111 | * Added the RType powerup for the GB |
| 112 | * |
| 113 | * 101 5/04/99 2:51a Chris |
| 114 | * Fixed bug with fire sounds in Obj_WBValue |
| 115 | * |
| 116 | * 100 4/29/99 7:15p Jeff |
| 117 | * added initial velocity parameter to Obj_Create |
| 118 | * |
| 119 | * 99 4/29/99 4:50p Chris |
| 120 | * Fixed matcen and Osiris created objects so thier ambient sounds play |
| 121 | * |
| 122 | * 98 4/29/99 3:25p Chris |
| 123 | * Added support to find out if an object has wbs |
| 124 | * |
| 125 | * 97 4/28/99 2:26a Jeff |
| 126 | * fixed places in code where only checking OBJ_PLAYER, added OBJ_GHOST |
| 127 | * and OBJ_OBSERVER where applicable |
| 128 | * |
| 129 | * 96 4/27/99 4:43a Jeff |
| 130 | * changed to call msafe functions for guidebot name commands |
| 131 | * |
| 132 | * 95 4/26/99 5:53p Jason |
| 133 | * make sure no objects are being created from script that are flagged |
| 134 | * with lightmaps |
| 135 | * |
| 136 | * 94 4/26/99 4:28a Jeff |
| 137 | * added multisafe functions to check a player's weapons, and add/remove |
| 138 | * weapons from a player |
| 139 | * |
| 140 | * 93 4/25/99 10:38p Matt |
| 141 | * Made the Osiris kill object function work on players. |
| 142 | * |
| 143 | * 92 4/25/99 10:19p Matt |
| 144 | * Fixed multiplayer and demo problems will killing an object from script, |
| 145 | * and cleaned up the death code a bit in the process. |
| 146 | * |
| 147 | * 91 4/24/99 6:46p Jeff |
| 148 | * added functions for theif so he can steal things other than weapons |
| 149 | * |
| 150 | * 90 4/24/99 2:19a Chris |
| 151 | * Added another parameter to FollowPathSimple |
| 152 | * |
| 153 | * 89 4/24/99 12:09a Jeff |
| 154 | * added path value functions |
| 155 | * |
| 156 | * 88 4/22/99 10:25p Chris |
| 157 | * Corrected the mprintf for Player_Value |
| 158 | * |
| 159 | * 87 4/22/99 5:46p Jason |
| 160 | * made weapons work in multiplayer |
| 161 | * |
| 162 | * 86 4/21/99 3:01p Matt |
| 163 | * Added a new type for dying objects that have AI, instead of keeping a |
| 164 | * flag in the dying info. |
| 165 | * |
| 166 | * 85 4/21/99 11:05a Kevin |
| 167 | * new ps_rand and ps_srand to replace rand & srand |
| 168 | * |
| 169 | * 84 4/20/99 8:56p Chris |
| 170 | * Fixed problem with robots not being able to open locked doors that a |
| 171 | * player has the key for. |
| 172 | * |
| 173 | * 83 4/20/99 7:29p Jeff |
| 174 | * handle set/get guidebot name |
| 175 | * |
| 176 | * 82 4/18/99 7:27a Chris |
| 177 | * Added AIAF_IMMEDIATE to force non-tiling and instant anim loop changes |
| 178 | * |
| 179 | * 81 4/14/99 3:57a Jeff |
| 180 | * fixed case mismatch in #includes |
| 181 | * |
| 182 | * 80 4/12/99 6:15p Samir |
| 183 | * Sound priorities pass 1 |
| 184 | * |
| 185 | * 79 4/03/99 1:13a Jeff |
| 186 | * added multisafe/dallas actions to set an object on fire |
| 187 | * |
| 188 | * 78 4/02/99 10:13p Jeff |
| 189 | * made ship permissions multi safe |
| 190 | * |
| 191 | * 77 4/02/99 11:23a Matt |
| 192 | * Made KillObject not take a death_info struct, but rather the death info |
| 193 | * as individual parameters. Moved death_info into objinfo.h, since it's |
| 194 | * only used for generic objects. Took out fade-away death hack, now that |
| 195 | * fade-away deaths can be explicitely set. |
| 196 | * |
| 197 | * 76 4/02/99 10:18a Chris |
| 198 | * We can now mess with the Object_info anim stuff |
| 199 | * |
| 200 | * 75 3/30/99 7:25p Chris |
| 201 | * Fixed the bug where dead objects would get a valid type |
| 202 | * |
| 203 | * 74 3/30/99 4:32p Chris |
| 204 | * Moved subtype to the main goal sturct (from goal_info). Made move |
| 205 | * relative object vec finishable. (Like get behind player) |
| 206 | * |
| 207 | * 73 3/29/99 11:53a Chris |
| 208 | * Corrected a objnum to obj ref problem in RayCast() |
| 209 | * |
| 210 | * 72 3/27/99 12:53p Chris |
| 211 | * Added new enabler types |
| 212 | * |
| 213 | * 71 3/23/99 5:53p Matt |
| 214 | * Fixed bug in physics set flags code |
| 215 | * |
| 216 | * 70 3/22/99 10:59a Chris |
| 217 | * Awareness code was tweaked. Multisafe stuff added for objects. |
| 218 | * |
| 219 | * 69 3/17/99 11:47a Jeff |
| 220 | * exported function to get what language we are using |
| 221 | * |
| 222 | * 68 3/16/99 11:26a Chris |
| 223 | * Buddy is now smarter -- gets to trigger level goals |
| 224 | * |
| 225 | * 67 3/10/99 1:33p Chris |
| 226 | * Fixes for multi-line gb messages |
| 227 | * |
| 228 | * 66 3/03/99 3:01a Chris |
| 229 | * Exported the difficulty stuff to OSIRIS |
| 230 | * |
| 231 | * 65 3/03/99 12:49a Chris |
| 232 | * |
| 233 | * 64 3/03/99 12:13a Chris |
| 234 | * |
| 235 | * 63 3/03/99 12:12a Chris |
| 236 | * |
| 237 | * 62 3/03/99 12:11a Chris |
| 238 | * one more AI path check function |
| 239 | * |
| 240 | * 61 3/03/99 12:07a Chris |
| 241 | * Added the two new OSIRIS predefs for AI path finding |
| 242 | * |
| 243 | * 60 3/01/99 8:13p Chris |
| 244 | * major hack so that goal text can be displayed |
| 245 | * |
| 246 | * 59 3/01/99 8:05p Chris |
| 247 | * Fixed bugs with the Level goal value functions |
| 248 | * |
| 249 | * 58 3/01/99 7:20p Chris |
| 250 | * Fixed dist problems with finding nearby objects |
| 251 | * |
| 252 | * 57 2/28/99 11:30p Chris |
| 253 | * FindObjOfType and OSIRIS controllable deaths |
| 254 | * |
| 255 | * 56 2/25/99 5:43p Chris |
| 256 | * Massive improvement to BOA and AI (again) |
| 257 | * |
| 258 | * 55 2/22/99 8:21p Chris |
| 259 | * |
| 260 | * 54 2/22/99 5:59p Chris |
| 261 | * Level Goals are now in OSIRIS. :) |
| 262 | * |
| 263 | * 53 2/21/99 5:51p Chris |
| 264 | * FIxed a bug with OBJV_C_TYPE (It should have been OBJV_I_TYPE). Added |
| 265 | * Obj_FindType() |
| 266 | * |
| 267 | * 52 2/20/99 5:08p Chris |
| 268 | * |
| 269 | * 51 2/18/99 4:27p Jeff |
| 270 | * added lookup functions for matcen, paths, level goals |
| 271 | * |
| 272 | * 50 2/13/99 3:14p Dan |
| 273 | * Check for no AI info for object in osipf_ObjectCustomAnim() |
| 274 | * |
| 275 | * 49 2/12/99 6:56p Chris |
| 276 | * |
| 277 | * 48 2/12/99 6:44p Chris |
| 278 | * |
| 279 | * 47 2/11/99 2:56a Jeff |
| 280 | * improvements to introcam |
| 281 | * |
| 282 | * 45 2/10/99 4:45p Jeff |
| 283 | * table file parser stuff |
| 284 | * |
| 285 | * 44 2/10/99 1:47p Matt |
| 286 | * Changed object handle symbolic constants |
| 287 | * |
| 288 | * 43 2/09/99 9:58a Chris |
| 289 | * Massive BOA update :) Terrain happy now. Vis happy now. Sound happy |
| 290 | * now. |
| 291 | * |
| 292 | * 42 2/08/99 3:06a Jeff |
| 293 | * created a function to switch a player between ai and flying control |
| 294 | * types (not exported to osiris...instead used in multisafe) |
| 295 | * |
| 296 | * 41 2/06/99 12:55p Chris |
| 297 | * Converted the path stuff to base-1 |
| 298 | * |
| 299 | * 40 2/03/99 1:51a Jeff |
| 300 | * added predefs for ship permissions |
| 301 | * |
| 302 | * 39 2/03/99 12:43a Chris |
| 303 | * Added Obj_GetGroundPos |
| 304 | * |
| 305 | * 38 1/29/99 5:10p Chris |
| 306 | * Added an optional parent handle check for FindObjOfType |
| 307 | * |
| 308 | * 37 1/26/99 2:51p Chris |
| 309 | * AIG_WANDER improvements |
| 310 | * |
| 311 | * 36 1/26/99 9:31a Chris |
| 312 | * Obj_Value now correctly return OBJ_NONE when doing a TYPE check on an |
| 313 | * invalid objref |
| 314 | * |
| 315 | * 35 1/25/99 6:13p Matt |
| 316 | * When doing a radius attach to a powerup, cut the radius ratio in half, |
| 317 | * since powerups use double their actual radius. |
| 318 | * |
| 319 | * 34 1/25/99 8:38a Chris |
| 320 | * The the GUID to AI_FollowPathSimple |
| 321 | * |
| 322 | * 33 1/25/99 7:43a Chris |
| 323 | * Added the GUID (Goal Unique Id) and added the ability for weapon |
| 324 | * batteries to always fire exactly forward. |
| 325 | * |
| 326 | * 32 1/24/99 11:39p Chris |
| 327 | * Added AIG_FOLLOW_PATH to AI_AddGoal for OSIRIS |
| 328 | * |
| 329 | * 31 1/24/99 8:17p Chris |
| 330 | * Updated AI and OSIRIS. Externalized fireball constants for spew and |
| 331 | * sparks. Added CreateRandomSparks to OSIRIS, renamed a bunch of AI |
| 332 | * Notify names to use underscores. Fixed a memory access leak in the |
| 333 | * matcen effect code. |
| 334 | * |
| 335 | * 30 1/24/99 6:36p Matt |
| 336 | * Made AIGoalFollowPathSimple() use slot 3 instead of slot 0 (with |
| 337 | * ChrisP) |
| 338 | * |
| 339 | * 29 1/23/99 4:48p Matt |
| 340 | * Fixed a pair of small bugs |
| 341 | * |
| 342 | * 28 1/22/99 6:53p Chris |
| 343 | * Fixed LoadandBind Aux notify problems, fixed static path problems, |
| 344 | * fixed AIF_FORCE_AWARE Problems, improved path code |
| 345 | * |
| 346 | * 27 1/22/99 4:47p Jeff |
| 347 | * |
| 348 | * 26 1/21/99 11:15p Jeff |
| 349 | * pulled out some structs and defines from header files and moved them |
| 350 | * into seperate header files so that multiplayer dlls don't require major |
| 351 | * game headers, just those new headers. Side effect is a shorter build |
| 352 | * time. Also cleaned up some header file #includes that weren't needed. |
| 353 | * This affected polymodel.h, object.h, player.h, vecmat.h, room.h, |
| 354 | * manage.h and multi.h |
| 355 | * |
| 356 | * 25 1/21/99 3:56p Nate |
| 357 | * Changed osipf_FindObjectName() so that it returns a handle |
| 358 | * |
| 359 | * 24 1/20/99 4:16p Jeff |
| 360 | * added ai notify child events and predefs to get ids of sound, room, |
| 361 | * trigger, object names |
| 362 | * |
| 363 | * 23 1/20/99 1:01a Chris |
| 364 | * Improved AI and OSIRIS intergration |
| 365 | * |
| 366 | * 22 1/18/99 2:46p Matt |
| 367 | * Combined flags & flags2 fields in object struct |
| 368 | * |
| 369 | * 21 1/18/99 9:05a Chris |
| 370 | * Improved OSIRIS, AI, and ATTACH system, changed wiggle code, changed |
| 371 | * attach code for rad attaches, and added the AIG_ATTACH_OBJ goal |
| 372 | * |
| 373 | * 20 1/15/99 5:59p Chris |
| 374 | * |
| 375 | * 19 1/13/99 5:20p Jeff |
| 376 | * added 4 new file operation predefs |
| 377 | * |
| 378 | * 18 1/13/99 3:29a Chris |
| 379 | * oops, forgot to include sounds.h |
| 380 | * |
| 381 | * 17 1/13/99 3:25a Chris |
| 382 | * Added Obj_Burning and Obj_IsEffect to OSIRIS |
| 383 | * |
| 384 | * 16 1/13/99 2:29a Chris |
| 385 | * Massive AI, OSIRIS update |
| 386 | * |
| 387 | * 15 1/11/99 2:14p Chris |
| 388 | * Massive work on OSIRIS and AI |
| 389 | * |
| 390 | * 14 1/05/99 12:24p Chris |
| 391 | * More OSIRIS improvements |
| 392 | * |
| 393 | * 13 1/05/99 11:34a Jeff |
| 394 | * fixed bugs in mission_flagget/set (needed to decrement flag before |
| 395 | * using) |
| 396 | * |
| 397 | * 12 1/04/99 6:43p Jeff |
| 398 | * added support to get/set mission flag values |
| 399 | * |
| 400 | * 11 1/04/99 12:42p Chris |
| 401 | * Updated OSIRIS with "xxxx_external.h" files and Obj_Value, and |
| 402 | * Matcen_XXX functions |
| 403 | * |
| 404 | * 10 12/30/98 3:46p Chris |
| 405 | * Incremental AI changes |
| 406 | * |
| 407 | * 9 12/23/98 12:10p Chris |
| 408 | * Added Gametime and Frametime to OSIRIS |
| 409 | * |
| 410 | * 8 12/22/98 4:51p Chris |
| 411 | * Added a ObjCreate predefined function |
| 412 | * |
| 413 | * 7 12/22/98 2:46p Chris |
| 414 | * Added the AIValue predefined function |
| 415 | * |
| 416 | * 6 12/21/98 5:30p Samir |
| 417 | * predef for determining if object is being rendered. |
| 418 | * |
| 419 | * 5 12/18/98 4:01p Samir |
| 420 | * implemented controls functions. |
| 421 | * |
| 422 | * 4 12/17/98 6:44p Samir |
| 423 | * added control manipulation predefs. |
| 424 | * |
| 425 | * 3 12/17/98 5:43p Jeff |
| 426 | * created timer system for osiris and save restore events |
| 427 | * |
| 428 | * 2 12/16/98 10:14p Jeff |
| 429 | * created osiris predefined function file |
| 430 | * |
| 431 | * $NoKeywords: $ |
| 432 | */ |
| 433 | #include <stdarg.h> |
| 434 | #include "osiris_predefs.h" |
| 435 | #include "object.h" |
| 436 | #include "mono.h" |
| 437 | #include "trigger.h" |
| 438 | #include "pstypes.h" |
| 439 | #include "pserror.h" |
| 440 | #include "hlsoundlib.h" |
| 441 | #include "gamepath.h" |
| 442 | #include "AIGoal.h" |
| 443 | #include "AIMain.h" |
| 444 | #include "soundload.h" |
| 445 | #include "room.h" |
| 446 | #include "objinfo.h" |
| 447 | #include "weapon.h" |
| 448 | #include "game.h" |
| 449 | #include "terrain.h" |
| 450 | #include "attach.h" |
| 451 | #include "matcen.h" |
| 452 | #include "findintersection.h" |
| 453 | #include "controls.h" |
| 454 | #include "Controller.h" |
| 455 | #include "ship.h" |
| 456 | #include "Mission.h" |
| 457 | #include "osiris_share.h" |
| 458 | #include "multisafe.h" |
| 459 | #include "sounds.h" |
| 460 | #include "polymodel.h" |
| 461 | #include "multi.h" |
| 462 | #include "viseffect.h" |
| 463 | #include "physics.h" |
| 464 | #include "levelgoal.h" |
| 465 | #include "BOA.h" |
| 466 | #include "marker.h" |
| 467 | #include "damage.h" |
| 468 | #include "aipath.h" |
| 469 | #include "difficulty.h" |
| 470 | #include "localization.h" |
| 471 | #include "psrand.h" |
| 472 | #include "demofile.h" |
| 473 | |
| 474 | int *hack_ilist = NULL; |
| 475 | int hack_list[100]; |
| 476 | |
| 477 | // osipf_CallObjectEvent |
| 478 | // Sends an event to an object. Returns true if the default action should |
| 479 | // continue to process. |
| 480 | bool osipf_CallObjectEvent(int objhandle, int event, tOSIRISEventInfo *ei) { |
| 481 | object *objp = ObjGet(objhandle); |
| 482 | if (!objp) |
| 483 | return false; |
| 484 | |
| 485 | return Osiris_CallEvent(objp, event, ei); |
| 486 | } |
| 487 | |
| 488 | // osipf_CallTriggerEvent |
| 489 | // Sends an event to a trigger. Returns true if the default action should |
| 490 | // continue to process. |
| 491 | bool osipf_CallTriggerEvent(int trignum, int event, tOSIRISEventInfo *ei) { |
| 492 | if (trignum < 0 || trignum >= Num_triggers) |
| 493 | return false; |
| 494 | |
| 495 | return Osiris_CallTriggerEvent(trignum, event, ei); |
| 496 | } |
| 497 | |
| 498 | /* |
| 499 | |
| 500 | *Get/Set Object Position |
| 501 | *Kill object |
| 502 | *Get Object max shields |
| 503 | *Get Object energy max |
| 504 | *Check to see if player has weapon |
| 505 | *Add weapon to a player |
| 506 | *Add weapon ammo |
| 507 | *Get weapon ammo |
| 508 | *Get/Set Player flags |
| 509 | *Is doorway openable |
| 510 | *play sound 2d/3d |
| 511 | *stop sound |
| 512 | *adjust 2d sound |
| 513 | *pickup powerup? |
| 514 | *end level |
| 515 | *timer events |
| 516 | *explode object |
| 517 | *start/stop spew |
| 518 | *get object type |
| 519 | *get object radius |
| 520 | *is object alive |
| 521 | *create pop-up view |
| 522 | *start end level sequence |
| 523 | *add type/id to inventory |
| 524 | *remove from inventory |
| 525 | *get inventory count |
| 526 | *use inventory item |
| 527 | *check for inventory item |
| 528 | *get player room |
| 529 | *set/get lighting effect distance |
| 530 | *set/get room wind |
| 531 | *get object fvec,rvec,uvec |
| 532 | *get/set object velocity |
| 533 | *get/set object parent |
| 534 | *enable WB |
| 535 | *get object anim frame |
| 536 | *play voice/stream |
| 537 | *add counter measure |
| 538 | *get counter measure count |
| 539 | *set portal render |
| 540 | *change face texture |
| 541 | *set object lighting effect parms |
| 542 | *ghost/unghost object |
| 543 | *set/get quad firing |
| 544 | *add player way point |
| 545 | */ |
| 546 | |
| 547 | // searches through GamePath index and returns index of path matching name |
| 548 | // returns -1 if not found |
| 549 | int osipf_AIGetPathID(char *string) { |
| 550 | // extract string reference |
| 551 | return FindGamePathName(string); |
| 552 | } |
| 553 | |
| 554 | int osipf_AIGoalFollowPathSimple(int objhandle, int path_id, int guid, int flags, int slot) { |
| 555 | object *obj = ObjGet(objhandle); |
| 556 | path_information path_info; |
| 557 | |
| 558 | if (!obj) { |
| 559 | mprintf(0, "Illegal object passed to AIGoalFollowPathSimple\n"); |
| 560 | return -1; |
| 561 | } |
| 562 | |
| 563 | if (path_id == -1) { |
| 564 | mprintf(0, "Illegal Path Id Passed To AIGoalFollowPathSimple\n"); |
| 565 | Int3(); |
| 566 | return -1; |
| 567 | } |
| 568 | |
| 569 | if (obj->control_type != CT_AI) { |
| 570 | mprintf(0, "Illegal Object CT Passed To AIGoalFollowPathSimple\n"); |
| 571 | Int3(); |
| 572 | return -1; |
| 573 | } |
| 574 | |
| 575 | path_info.path_id = path_id; |
| 576 | |
| 577 | if (flags & GF_PATH_MOVE_REVERSE_DIR) |
| 578 | path_info.next_node = GamePaths[path_id].num_nodes - 1; |
| 579 | else |
| 580 | path_info.next_node = 0; |
| 581 | |
| 582 | path_info.start_node = 0; |
| 583 | path_info.end_node = GamePaths[path_id].num_nodes - 1; |
| 584 | |
| 585 | return GoalAddGoal(obj, AIG_FOLLOW_PATH, (void *)&path_info, slot, 1.0f, flags, guid); |
| 586 | } |
| 587 | |
| 588 | int osipf_AIPowerSwitch(int objhandle, uint8_t f_power_on) { |
| 589 | object *obj = ObjGet(objhandle); |
| 590 | if (!obj) { |
| 591 | mprintf(0, "Illegal Object passed to AIPowerSwitch\n"); |
| 592 | return -1; |
| 593 | } |
| 594 | |
| 595 | if (f_power_on) |
| 596 | AIPowerSwitch(obj, true); |
| 597 | else |
| 598 | AIPowerSwitch(obj, false); |
| 599 | |
| 600 | return 0; |
| 601 | } |
| 602 | |
| 603 | // Touches a sound file so it loads into memory |
| 604 | void osipf_SoundTouch(char *str) { |
| 605 | int id = FindSoundName(IGNORE_TABLE(str)); |
| 606 | |
| 607 | if (id == -1) { |
| 608 | mprintf(0, "Sound %s was not found. Unable to touch.\n", str); |
| 609 | Int3(); |
| 610 | } else |
| 611 | Sound_system.CheckAndForceSoundDataAlloc(id); |
| 612 | } |
| 613 | |
| 614 | // Gets room values |
| 615 | void osipf_RoomValue(int roomnum, char op, char vtype, void *ptr, int index) { |
| 616 | if (roomnum < 0 || roomnum > Highest_room_index || !Rooms[roomnum].used) { |
| 617 | if (vtype == RMV_C_USED) |
| 618 | *(char *)ptr = 0; |
| 619 | else |
| 620 | mprintf(0, "RoomValue: Illegal Room Passed\n"); |
| 621 | |
| 622 | return; |
| 623 | } |
| 624 | |
| 625 | room *rp = &Rooms[roomnum]; |
| 626 | |
| 627 | switch (vtype) { |
| 628 | case RMV_I_FLAGS: |
| 629 | if (op == VF_GET) |
| 630 | *(int *)ptr = rp->flags; |
| 631 | else if (op == VF_SET) |
| 632 | rp->flags = *(int *)ptr; |
| 633 | else if (op == VF_SET_FLAGS) |
| 634 | rp->flags |= *(int *)ptr; |
| 635 | else if (op == VF_CLEAR_FLAGS) |
| 636 | rp->flags &= ~(*(int *)ptr); |
| 637 | break; |
| 638 | case RMV_V_WIND: |
| 639 | if (op == VF_SET) |
| 640 | rp->wind = *(vector *)ptr; |
| 641 | else if (op == VF_GET) |
| 642 | *(vector *)ptr = rp->wind; |
| 643 | break; |
| 644 | case RMV_C_USED: |
| 645 | if (op == VF_GET) |
| 646 | *(char *)ptr = (rp->used != 0); |
| 647 | break; |
| 648 | |
| 649 | case RMV_I_NUM_PATH_PNTS: |
| 650 | if (op == VF_GET) |
| 651 | *(int *)ptr = 1; // chrishack -- might change if the multi point intraroom points are added |
| 652 | break; |
| 653 | case RMSV_V_PATH_PNT: |
| 654 | if (op == VF_SET) |
| 655 | rp->path_pnt = *(vector *)ptr; |
| 656 | else if (op == VF_GET) |
| 657 | *(vector *)ptr = rp->path_pnt; |
| 658 | break; |
| 659 | |
| 660 | case RMV_I_NUM_FACES: |
| 661 | if (op == VF_GET) |
| 662 | *(int *)ptr = rp->num_faces; |
| 663 | break; |
| 664 | case RMSV_I_FACE_TEXTURE_ID: |
| 665 | if (op == VF_SET) |
| 666 | rp->faces[index].tmap = *(int *)ptr; |
| 667 | else if (op == VF_GET) |
| 668 | *(int *)ptr = rp->faces[index].tmap; |
| 669 | break; |
| 670 | case RMSV_I_FACE_FLAGS: |
| 671 | if (op == VF_GET) |
| 672 | *(int *)ptr = rp->faces[index].flags; |
| 673 | else if (op == VF_SET) |
| 674 | rp->faces[index].flags = *(int *)ptr; |
| 675 | else if (op == VF_SET_FLAGS) |
| 676 | rp->faces[index].flags |= *(int *)ptr; |
| 677 | else if (op == VF_CLEAR_FLAGS) |
| 678 | rp->faces[index].flags &= ~(*(int *)ptr); |
| 679 | break; |
| 680 | case RMSV_V_FACE_NORMAL: |
| 681 | if (op == VF_GET) |
| 682 | *(vector *)ptr = rp->faces[index].normal; |
| 683 | break; |
| 684 | case RMSV_V_FACE_CENTER_PNT: |
| 685 | if (op == VF_GET) { |
| 686 | int i; |
| 687 | |
| 688 | if (index < 0 || index >= rp->num_faces || rp->faces[index].num_verts <= 0) { |
| 689 | *(vector *)ptr = rp->path_pnt; |
| 690 | } else { |
| 691 | *(vector *)ptr = Zero_vector; |
| 692 | |
| 693 | for (i = 0; i < rp->faces[index].num_verts; i++) { |
| 694 | *(vector *)ptr += rp->verts[rp->faces[index].face_verts[i]]; |
| 695 | } |
| 696 | |
| 697 | *(vector *)ptr /= rp->faces[index].num_verts; |
| 698 | } |
| 699 | } |
| 700 | break; |
| 701 | case RMV_I_NUM_PORTALS: |
| 702 | if (op == VF_GET) |
| 703 | *(int *)ptr = rp->num_portals; |
| 704 | break; |
| 705 | case RMSV_V_PORTAL_PATH_PNT: |
| 706 | if (op == VF_SET) |
| 707 | rp->portals[index].path_pnt = *(vector *)ptr; // chrishack -- make sure save game accounts for this |
| 708 | else if (op == VF_GET) |
| 709 | *(vector *)ptr = rp->portals[index].path_pnt; |
| 710 | break; |
| 711 | case RMSV_I_PORTAL_CONNECT_ROOM: |
| 712 | if (op == VF_GET) |
| 713 | *(int *)ptr = rp->portals[index].croom; |
| 714 | break; |
| 715 | case RMSV_I_PORTAL_CONNECT_PORTAL: |
| 716 | if (op == VF_GET) |
| 717 | *(int *)ptr = rp->portals[index].cportal; |
| 718 | break; |
| 719 | case RMSV_I_PORTAL_FACE: |
| 720 | if (op == VF_GET) |
| 721 | *(int *)ptr = rp->portals[index].portal_face; |
| 722 | break; |
| 723 | case RMV_F_DAMAGE: |
| 724 | if (op == VF_GET) |
| 725 | *(float *)ptr = rp->damage; |
| 726 | break; |
| 727 | } |
| 728 | } |
| 729 | |
| 730 | void osipf_PlayerValue(int obj_handle, char op, char vhandle, void *ptr, int index) { |
| 731 | object *objp; |
| 732 | int id; |
| 733 | bool extract_info = true; |
| 734 | |
| 735 | if (vhandle == PLYV_I_STRIP_WEAPONS) { |
| 736 | // check to see if ptr is a -1, if so, don't extract info |
| 737 | if ((*(int *)ptr) == -1) |
| 738 | extract_info = false; |
| 739 | } |
| 740 | |
| 741 | if (extract_info) { |
| 742 | objp = ObjGet(obj_handle); |
| 743 | |
| 744 | if (!objp || (!(objp->type == OBJ_PLAYER || objp->type == OBJ_GHOST || objp->type == OBJ_OBSERVER))) { |
| 745 | mprintf(0, "Player Value: Illegal Object Passed\n"); |
| 746 | return; |
| 747 | } |
| 748 | |
| 749 | id = objp->id; |
| 750 | } |
| 751 | |
| 752 | switch (vhandle) { |
| 753 | case PLYV_I_FLAGS: { |
| 754 | if (op == VF_GET) { |
| 755 | *(int *)ptr = Players[id].flags; |
| 756 | } |
| 757 | } break; |
| 758 | case PLYV_F_ENERGY: |
| 759 | if (op == VF_GET) |
| 760 | *(float *)ptr = Players[id].energy; |
| 761 | else if (op == VF_SET) |
| 762 | Players[id].energy = *(float *)ptr; |
| 763 | break; |
| 764 | case PLYV_F_MOVEMENT_SCALAR: |
| 765 | if (op == VF_GET) |
| 766 | *(float *)ptr = Players[id].movement_scalar; |
| 767 | else if (op == VF_SET) |
| 768 | Players[id].movement_scalar = *(float *)ptr; |
| 769 | break; |
| 770 | case PLYV_F_RECHARGE_SCALAR: |
| 771 | if (op == VF_GET) |
| 772 | *(float *)ptr = Players[id].weapon_recharge_scalar; |
| 773 | else if (op == VF_SET) |
| 774 | Players[id].weapon_recharge_scalar = *(float *)ptr; |
| 775 | break; |
| 776 | case PLYV_F_WSPEED_SCALAR: |
| 777 | if (op == VF_GET) |
| 778 | *(float *)ptr = Players[id].weapon_speed_scalar; |
| 779 | else if (op == VF_SET) |
| 780 | Players[id].weapon_speed_scalar = *(float *)ptr; |
| 781 | break; |
| 782 | case PLYV_F_DAMAGE_SCALAR: |
| 783 | if (op == VF_GET) |
| 784 | *(float *)ptr = Players[id].damage_scalar; |
| 785 | else if (op == VF_SET) |
| 786 | Players[id].damage_scalar = *(float *)ptr; |
| 787 | break; |
| 788 | case PLYV_F_ARMOR_SCALAR: |
| 789 | if (op == VF_GET) |
| 790 | *(float *)ptr = Players[id].armor_scalar; |
| 791 | else if (op == VF_SET) |
| 792 | Players[id].armor_scalar = *(float *)ptr; |
| 793 | break; |
| 794 | case PLYV_I_BUDDY_HANDLE: |
| 795 | if (op == VF_GET) |
| 796 | *(int *)ptr = Buddy_handle[id]; |
| 797 | break; |
| 798 | case PLYSV_I_WEAPON: |
| 799 | if (op == VF_GET) { |
| 800 | msafe_struct mstruct; |
| 801 | mstruct.objhandle = obj_handle; |
| 802 | mstruct.index = index; |
| 803 | msafe_GetValue(MSAFE_WEAPON_CHECK, &mstruct); |
| 804 | |
| 805 | if (!mstruct.state) { |
| 806 | *(int *)ptr = 0; |
| 807 | } else { |
| 808 | if (index >= SECONDARY_INDEX) |
| 809 | *(int *)ptr = mstruct.count; |
| 810 | else |
| 811 | *(int *)ptr = 1; |
| 812 | } |
| 813 | } else if (op == VF_SET) { |
| 814 | int amount = *(int *)ptr; |
| 815 | msafe_struct mstruct; |
| 816 | mstruct.objhandle = obj_handle; |
| 817 | mstruct.index = index; |
| 818 | mstruct.state = (index >= SECONDARY_INDEX) ? 0 : 1; |
| 819 | mstruct.count = amount; |
| 820 | msafe_CallFunction(MSAFE_WEAPON_ADD, &mstruct); |
| 821 | } |
| 822 | break; |
| 823 | |
| 824 | case PLYV_CS_GUIDEBOTNAME: { |
| 825 | if (op == VF_GET) { |
| 826 | char *dest = (char *)ptr; |
| 827 | ASSERT(dest); |
| 828 | msafe_struct mstruct; |
| 829 | mstruct.objhandle = obj_handle; |
| 830 | msafe_GetValue(MSAFE_MISC_GUIDEBOT_NAME, &mstruct); |
| 831 | strcpy(dest, mstruct.name); |
| 832 | } else { |
| 833 | char *src = (char *)ptr; |
| 834 | ASSERT(src); |
| 835 | msafe_struct mstruct; |
| 836 | mstruct.objhandle = obj_handle; |
| 837 | strcpy(mstruct.name, src); |
| 838 | msafe_CallFunction(MSAFE_MISC_GUIDEBOT_NAME, &mstruct); |
| 839 | } |
| 840 | |
| 841 | } break; |
| 842 | |
| 843 | case PLYSV_US_WEAPON_POWERUP_ID: { |
| 844 | if (op == VF_GET) |
| 845 | *(uint16_t *)ptr = Ships[Players[id].ship_index].spew_powerup[index]; |
| 846 | } break; |
| 847 | case PLYSV_I_WEAPON_AMMO: |
| 848 | if (op == VF_GET) |
| 849 | if (index >= 0 && index < 10) { |
| 850 | *(int *)ptr = Players[id].weapon_ammo[index]; |
| 851 | } |
| 852 | break; |
| 853 | case PLYV_B_THIEF_PLAYERHASITEM: |
| 854 | // note this is multiplayer friendly |
| 855 | if (op == VF_GET) { |
| 856 | bool ret = ThiefPlayerHasItem(obj_handle, index); |
| 857 | *((bool *)ptr) = ret; |
| 858 | } else { |
| 859 | Int3(); |
| 860 | } |
| 861 | break; |
| 862 | case PLYV_I_THIEF_STEALPLAYERITEM: |
| 863 | // note this is multiplayer friendly |
| 864 | if (op == VF_SET) { |
| 865 | ThiefStealItem(obj_handle, index); |
| 866 | } else { |
| 867 | Int3(); |
| 868 | } |
| 869 | break; |
| 870 | case PLYV_I_STRIP_WEAPONS: |
| 871 | if (op == VF_SET) { |
| 872 | if ((*(int *)ptr) == -1) { |
| 873 | MultiSendStripPlayer(-1); |
| 874 | } else { |
| 875 | MultiSendStripPlayer(id); |
| 876 | } |
| 877 | } |
| 878 | break; |
| 879 | // case PLYSV_F_ACCESSORY: |
| 880 | // if(op == VF_GET) |
| 881 | // *(float *)ptr = Players[id] |
| 882 | // else if(op == VF_SET) |
| 883 | // break; |
| 884 | } |
| 885 | } |
| 886 | |
| 887 | extern void AIUpdateAnim(object *obj); |
| 888 | |
| 889 | void osipf_ObjectCustomAnim(int handle, float start, float end, float time, char flags, int sound_handle, |
| 890 | char next_anim_type) { |
| 891 | object *objp = ObjGet(handle); |
| 892 | |
| 893 | if (!objp) { |
| 894 | mprintf(0, "AIValue: Illegal Object Passed\n"); |
| 895 | return; |
| 896 | } |
| 897 | |
| 898 | objp->rtype.pobj_info.anim_flags |= AIAF_NOTIFY; |
| 899 | |
| 900 | objp->rtype.pobj_info.custom_anim_info.anim_start_frame = start; |
| 901 | objp->rtype.pobj_info.custom_anim_info.anim_end_frame = end; |
| 902 | objp->rtype.pobj_info.custom_anim_info.anim_time = time; |
| 903 | objp->rtype.pobj_info.custom_anim_info.flags = flags; |
| 904 | objp->rtype.pobj_info.custom_anim_info.anim_sound_index = sound_handle; |
| 905 | objp->rtype.pobj_info.custom_anim_info.next_anim_type = next_anim_type; |
| 906 | |
| 907 | if (objp->ai_info) |
| 908 | objp->ai_info->next_animation_type = AS_CUSTOM; |
| 909 | else |
| 910 | mprintf(0, "ERROR: Changing animation for non-AI object.\n"); |
| 911 | |
| 912 | if (flags & AIAF_IMMEDIATE) { |
| 913 | AIUpdateAnim(objp); |
| 914 | } |
| 915 | } |
| 916 | |
| 917 | // searches for an object id given it's name |
| 918 | int osipf_ObjectFindID(const char *name) { return FindObjectIDName(IGNORE_TABLE(name)); } |
| 919 | |
| 920 | // searches for an object id given it's name |
| 921 | int osipf_ObjectFindType(const char *name) { |
| 922 | int id = FindObjectIDName(IGNORE_TABLE(name)); |
| 923 | |
| 924 | if (id >= 0) { |
| 925 | return Object_info[id].type; |
| 926 | } |
| 927 | |
| 928 | return OBJ_NONE; |
| 929 | } |
| 930 | |
| 931 | // searches through the weapons for a name and returns the id |
| 932 | int osipf_WeaponFindID(const char *name) { return FindWeaponName(IGNORE_TABLE(name)); } |
| 933 | |
| 934 | // returns how long an object has lived |
| 935 | float osipf_ObjectGetTimeLived(int objhandle) { |
| 936 | object *objp = ObjGet(objhandle); |
| 937 | |
| 938 | if (!objp) { |
| 939 | mprintf(0, "Illegal object passed to ObjectGetTimeLived\n"); |
| 940 | return 0; |
| 941 | } |
| 942 | |
| 943 | return (Gametime - objp->creation_time); |
| 944 | } |
| 945 | |
| 946 | void osipf_AIValue(int objhandle, char op, char vtype, void *ptr) { |
| 947 | object *objp = ObjGet(objhandle); |
| 948 | |
| 949 | if (!objp) { |
| 950 | mprintf(0, "AIValue: Illegal Object Passed\n"); |
| 951 | return; |
| 952 | } |
| 953 | |
| 954 | if ((objp->control_type != CT_AI) && (objp->control_type != CT_DYING_AND_AI)) { |
| 955 | mprintf(0, "AIValue: Illegal Object CT Passed\n"); |
| 956 | return; |
| 957 | } |
| 958 | |
| 959 | ai_frame *ai_info = objp->ai_info; |
| 960 | |
| 961 | switch (vtype) { |
| 962 | case AIV_F_MAX_SPEED: |
| 963 | if (op == VF_SET) { |
| 964 | ai_info->max_velocity = *((float *)ptr); |
| 965 | } else { |
| 966 | *((float *)ptr) = ai_info->max_velocity; |
| 967 | } |
| 968 | break; |
| 969 | case AIV_F_MAX_DELTA_SPEED: |
| 970 | if (op == VF_SET) { |
| 971 | ai_info->max_delta_velocity = *((float *)ptr); |
| 972 | } else { |
| 973 | *((float *)ptr) = ai_info->max_delta_velocity; |
| 974 | } |
| 975 | break; |
| 976 | case AIV_F_MAX_TURN_RATE: |
| 977 | if (op == VF_SET) { |
| 978 | ai_info->max_turn_rate = *((float *)ptr); |
| 979 | } else { |
| 980 | *((float *)ptr) = ai_info->max_turn_rate; |
| 981 | } |
| 982 | break; |
| 983 | case AIV_F_MAX_DELTA_TURN_RATE: |
| 984 | if (op == VF_SET) { |
| 985 | ai_info->max_delta_turn_rate = *((float *)ptr); |
| 986 | } else { |
| 987 | *((float *)ptr) = ai_info->max_delta_turn_rate; |
| 988 | } |
| 989 | break; |
| 990 | case AIV_F_ATTACK_VEL_PERCENT: |
| 991 | if (op == VF_SET) { |
| 992 | ai_info->attack_vel_percent = *((float *)ptr); |
| 993 | } else { |
| 994 | *((float *)ptr) = ai_info->attack_vel_percent; |
| 995 | } |
| 996 | break; |
| 997 | case AIV_F_FLEE_VEL_PERCENT: |
| 998 | if (op == VF_SET) { |
| 999 | ai_info->flee_vel_percent = *((float *)ptr); |
| 1000 | } else { |
| 1001 | *((float *)ptr) = ai_info->flee_vel_percent; |
| 1002 | } |
| 1003 | break; |
| 1004 | case AIV_F_DODGE_VEL_PERCENT: |
| 1005 | if (op == VF_SET) { |
| 1006 | ai_info->dodge_vel_percent = *((float *)ptr); |
| 1007 | } else { |
| 1008 | *((float *)ptr) = ai_info->dodge_vel_percent; |
| 1009 | } |
| 1010 | break; |
| 1011 | case AIV_F_CIRCLE_DIST: |
| 1012 | if (op == VF_SET) { |
| 1013 | ai_info->circle_distance = *((float *)ptr); |
| 1014 | } else { |
| 1015 | *((float *)ptr) = ai_info->circle_distance; |
| 1016 | } |
| 1017 | break; |
| 1018 | case AIV_F_DODGE_PERCENT: |
| 1019 | if (op == VF_SET) { |
| 1020 | ai_info->dodge_percent = *((float *)ptr); |
| 1021 | } else { |
| 1022 | *((float *)ptr) = ai_info->dodge_percent; |
| 1023 | } |
| 1024 | break; |
| 1025 | case AIV_F_MELEE_DAMAGE1: |
| 1026 | if (op == VF_SET) { |
| 1027 | ai_info->melee_damage[0] = *((float *)ptr); |
| 1028 | } else { |
| 1029 | *((float *)ptr) = ai_info->melee_damage[0]; |
| 1030 | } |
| 1031 | break; |
| 1032 | case AIV_F_MELEE_DAMAGE2: |
| 1033 | if (op == VF_SET) { |
| 1034 | ai_info->melee_damage[1] = *((float *)ptr); |
| 1035 | } else { |
| 1036 | *((float *)ptr) = ai_info->melee_damage[1]; |
| 1037 | } |
| 1038 | break; |
| 1039 | case AIV_F_MELEE_LATENCY1: |
| 1040 | if (op == VF_SET) { |
| 1041 | ai_info->melee_latency[0] = *((float *)ptr); |
| 1042 | } else { |
| 1043 | *((float *)ptr) = ai_info->melee_latency[0]; |
| 1044 | } |
| 1045 | break; |
| 1046 | case AIV_F_MELEE_LATENCY2: |
| 1047 | if (op == VF_SET) { |
| 1048 | ai_info->melee_latency[1] = *((float *)ptr); |
| 1049 | } else { |
| 1050 | *((float *)ptr) = ai_info->melee_latency[1]; |
| 1051 | } |
| 1052 | break; |
| 1053 | case AIV_C_MOVEMENT_TYPE: |
| 1054 | if (op == VF_SET) { |
| 1055 | ai_info->movement_type = *((char *)ptr); |
| 1056 | } else { |
| 1057 | *((char *)ptr) = ai_info->movement_type; |
| 1058 | } |
| 1059 | break; |
| 1060 | case AIV_C_MOVEMENT_SUBTYPE: |
| 1061 | if (op == VF_SET) { |
| 1062 | ai_info->movement_subtype = *((char *)ptr); |
| 1063 | } else { |
| 1064 | *((char *)ptr) = ai_info->movement_subtype; |
| 1065 | } |
| 1066 | break; |
| 1067 | case AIV_C_ANIMATION_TYPE: |
| 1068 | if (op == VF_SET) { |
| 1069 | ai_info->animation_type = *((char *)ptr); |
| 1070 | } else { |
| 1071 | *((char *)ptr) = ai_info->animation_type; |
| 1072 | } |
| 1073 | break; |
| 1074 | case AIV_C_NEXT_ANIMATION_TYPE: |
| 1075 | if (op == VF_SET) { |
| 1076 | ai_info->next_animation_type = *((char *)ptr); |
| 1077 | } else { |
| 1078 | *((char *)ptr) = ai_info->next_animation_type; |
| 1079 | } |
| 1080 | break; |
| 1081 | case AIV_C_NEXT_MOVEMENT: |
| 1082 | if (op == VF_SET) { |
| 1083 | ai_info->next_movement = *((char *)ptr); |
| 1084 | } else { |
| 1085 | *((char *)ptr) = ai_info->next_movement; |
| 1086 | } |
| 1087 | break; |
| 1088 | case AIV_C_CURRENT_WB_FIRING: |
| 1089 | if (op == VF_SET) { |
| 1090 | ai_info->current_wb_firing = *((char *)ptr); |
| 1091 | } else { |
| 1092 | *((char *)ptr) = ai_info->current_wb_firing; |
| 1093 | } |
| 1094 | break; |
| 1095 | case AIV_I_TARGET_HANDLE: |
| 1096 | if (op == VF_SET) { |
| 1097 | AISetTarget(objp, *((int *)ptr)); |
| 1098 | } else { |
| 1099 | *((int *)ptr) = ai_info->target_handle; |
| 1100 | } |
| 1101 | break; |
| 1102 | case AIV_F_NEXT_TARGET_UPDATE_TIME: |
| 1103 | if (op == VF_SET) { |
| 1104 | ai_info->next_target_update_time = *((float *)ptr); |
| 1105 | } else { |
| 1106 | *((float *)ptr) = ai_info->next_target_update_time; |
| 1107 | } |
| 1108 | break; |
| 1109 | case AIV_F_DIST_TO_TARGET: |
| 1110 | if (op == VF_SET) { |
| 1111 | ai_info->dist_to_target_actual = ai_info->dist_to_target_perceived = *((float *)ptr); |
| 1112 | } else { |
| 1113 | *((float *)ptr) = ai_info->dist_to_target_perceived; |
| 1114 | } |
| 1115 | break; |
| 1116 | case AIV_V_VEC_TO_TARGET: |
| 1117 | if (op == VF_SET) { |
| 1118 | ai_info->vec_to_target_actual = ai_info->vec_to_target_perceived = *((vector *)ptr); |
| 1119 | } else { |
| 1120 | *((vector *)ptr) = ai_info->vec_to_target_perceived; |
| 1121 | } |
| 1122 | break; |
| 1123 | case AIV_F_NEXT_CHECK_SEE_TARGET_TIME: |
| 1124 | if (op == VF_SET) { |
| 1125 | ai_info->next_check_see_target_time = *((float *)ptr); |
| 1126 | } else { |
| 1127 | *((float *)ptr) = ai_info->next_check_see_target_time; |
| 1128 | } |
| 1129 | break; |
| 1130 | case AIV_V_LAST_SEE_TARGET_POS: |
| 1131 | if (op == VF_SET) { |
| 1132 | ai_info->last_see_target_pos = *((vector *)ptr); |
| 1133 | } else { |
| 1134 | *((vector *)ptr) = ai_info->last_see_target_pos; |
| 1135 | } |
| 1136 | break; |
| 1137 | case AIV_F_LAST_SEE_TARGET_TIME: |
| 1138 | if (op == VF_SET) { |
| 1139 | ai_info->last_see_target_time = *((float *)ptr); |
| 1140 | if (ai_info->last_see_target_time == Gametime) { |
| 1141 | AINotify(objp, AIN_SEE_TARGET, ObjGet(ai_info->target_handle)); |
| 1142 | } |
| 1143 | } else { |
| 1144 | *((float *)ptr) = ai_info->last_see_target_time; |
| 1145 | } |
| 1146 | break; |
| 1147 | case AIV_F_LAST_HEAR_TARGET_TIME: |
| 1148 | if (op == VF_SET) { |
| 1149 | ai_info->last_hear_target_time = *((float *)ptr); |
| 1150 | } else { |
| 1151 | *((float *)ptr) = ai_info->last_hear_target_time; |
| 1152 | } |
| 1153 | break; |
| 1154 | case AIV_F_WEAPON_SPEED: |
| 1155 | if (op == VF_SET) { |
| 1156 | ai_info->weapon_speed = *((float *)ptr); |
| 1157 | } else { |
| 1158 | *((float *)ptr) = ai_info->weapon_speed; |
| 1159 | } |
| 1160 | break; |
| 1161 | case AIV_F_NEXT_MELEE_TIME: |
| 1162 | if (op == VF_SET) { |
| 1163 | ai_info->next_melee_time = *((float *)ptr); |
| 1164 | } else { |
| 1165 | *((float *)ptr) = ai_info->next_melee_time; |
| 1166 | } |
| 1167 | break; |
| 1168 | case AIV_F_LAST_RENDER_TIME: |
| 1169 | if (op == VF_SET) { |
| 1170 | ai_info->last_render_time = *((float *)ptr); |
| 1171 | } else { |
| 1172 | *((float *)ptr) = ai_info->last_render_time; |
| 1173 | } |
| 1174 | break; |
| 1175 | case AIV_F_NEXT_FLINCH_TIME: |
| 1176 | if (op == VF_SET) { |
| 1177 | ai_info->next_flinch_time = *((float *)ptr); |
| 1178 | } else { |
| 1179 | *((float *)ptr) = ai_info->next_flinch_time; |
| 1180 | } |
| 1181 | break; |
| 1182 | case AIV_V_MOVEMENT_DIR: |
| 1183 | if (op == VF_SET) { |
| 1184 | ai_info->movement_dir = *((vector *)ptr); |
| 1185 | } else { |
| 1186 | *((vector *)ptr) = ai_info->movement_dir; |
| 1187 | } |
| 1188 | break; |
| 1189 | case AIV_V_ROT_THRUST_VECTOR: |
| 1190 | if (op == VF_SET) { |
| 1191 | ai_info->rot_thrust_vector = *((vector *)ptr); |
| 1192 | } else { |
| 1193 | *((vector *)ptr) = ai_info->rot_thrust_vector; |
| 1194 | } |
| 1195 | break; |
| 1196 | case AIV_F_FOV: |
| 1197 | if (op == VF_SET) { |
| 1198 | ai_info->fov = *((float *)ptr); |
| 1199 | } else { |
| 1200 | *((float *)ptr) = ai_info->fov; |
| 1201 | } |
| 1202 | break; |
| 1203 | case AIV_F_AVOID_FRIENDS_DIST: |
| 1204 | if (op == VF_SET) { |
| 1205 | ai_info->avoid_friends_distance = *((float *)ptr); |
| 1206 | } else { |
| 1207 | *((float *)ptr) = ai_info->avoid_friends_distance; |
| 1208 | } |
| 1209 | break; |
| 1210 | case AIV_F_FRUSTRATION: |
| 1211 | if (op == VF_SET) { |
| 1212 | ai_info->frustration = *((float *)ptr); |
| 1213 | } else { |
| 1214 | *((float *)ptr) = ai_info->frustration; |
| 1215 | } |
| 1216 | break; |
| 1217 | case AIV_F_CURIOUSITY: |
| 1218 | if (op == VF_SET) { |
| 1219 | ai_info->curiousity = *((float *)ptr); |
| 1220 | } else { |
| 1221 | *((float *)ptr) = ai_info->curiousity; |
| 1222 | } |
| 1223 | break; |
| 1224 | case AIV_F_FIRE_SPREAD: |
| 1225 | if (op == VF_SET) { |
| 1226 | ai_info->fire_spread = *((float *)ptr); |
| 1227 | } else { |
| 1228 | *((float *)ptr) = ai_info->fire_spread; |
| 1229 | } |
| 1230 | break; |
| 1231 | case AIV_F_AGRESSION: |
| 1232 | if (op == VF_SET) { |
| 1233 | ai_info->agression = *((float *)ptr); |
| 1234 | } else { |
| 1235 | *((float *)ptr) = ai_info->agression; |
| 1236 | } |
| 1237 | break; |
| 1238 | case AIV_F_NIGHT_VISION: |
| 1239 | if (op == VF_SET) { |
| 1240 | ai_info->night_vision = *((float *)ptr); |
| 1241 | } else { |
| 1242 | *((float *)ptr) = ai_info->night_vision; |
| 1243 | } |
| 1244 | break; |
| 1245 | case AIV_F_FOG_VISION: |
| 1246 | if (op == VF_SET) { |
| 1247 | ai_info->fog_vision = *((float *)ptr); |
| 1248 | } else { |
| 1249 | *((float *)ptr) = ai_info->fog_vision; |
| 1250 | } |
| 1251 | break; |
| 1252 | case AIV_F_LEAD_ACCURACY: |
| 1253 | if (op == VF_SET) { |
| 1254 | ai_info->lead_accuracy = *((float *)ptr); |
| 1255 | } else { |
| 1256 | *((float *)ptr) = ai_info->lead_accuracy; |
| 1257 | } |
| 1258 | break; |
| 1259 | case AIV_F_LEAD_VARIENCE: |
| 1260 | if (op == VF_SET) { |
| 1261 | ai_info->lead_varience = *((float *)ptr); |
| 1262 | } else { |
| 1263 | *((float *)ptr) = ai_info->lead_varience; |
| 1264 | } |
| 1265 | break; |
| 1266 | case AIV_F_FIGHT_TEAM: |
| 1267 | if (op == VF_SET) { |
| 1268 | ai_info->fight_team = *((float *)ptr); |
| 1269 | } else { |
| 1270 | *((float *)ptr) = ai_info->fight_team; |
| 1271 | } |
| 1272 | break; |
| 1273 | case AIV_F_FIGHT_SAME: |
| 1274 | if (op == VF_SET) { |
| 1275 | ai_info->fight_same = *((float *)ptr); |
| 1276 | } else { |
| 1277 | *((float *)ptr) = ai_info->fight_same; |
| 1278 | } |
| 1279 | break; |
| 1280 | case AIV_F_HEARING: |
| 1281 | if (op == VF_SET) { |
| 1282 | ai_info->hearing = *((float *)ptr); |
| 1283 | } else { |
| 1284 | *((float *)ptr) = ai_info->hearing; |
| 1285 | } |
| 1286 | break; |
| 1287 | case AIV_F_ROAMING: |
| 1288 | if (op == VF_SET) { |
| 1289 | ai_info->roaming = *((float *)ptr); |
| 1290 | } else { |
| 1291 | *((float *)ptr) = ai_info->roaming; |
| 1292 | } |
| 1293 | break; |
| 1294 | case AIV_F_LIFE_PRESERVATION: |
| 1295 | if (op == VF_SET) { |
| 1296 | ai_info->life_preservation = *((float *)ptr); |
| 1297 | } else { |
| 1298 | *((float *)ptr) = ai_info->life_preservation; |
| 1299 | } |
| 1300 | break; |
| 1301 | case AIV_F_BIASED_FLIGHT_IMPORTANCE: |
| 1302 | if (op == VF_SET) { |
| 1303 | ai_info->biased_flight_importance = *((float *)ptr); |
| 1304 | } else { |
| 1305 | *((float *)ptr) = ai_info->biased_flight_importance; |
| 1306 | } |
| 1307 | break; |
| 1308 | case AIV_F_BIASED_FLIGHT_MIN: |
| 1309 | if (op == VF_SET) { |
| 1310 | ai_info->biased_flight_min = *((float *)ptr); |
| 1311 | } else { |
| 1312 | *((float *)ptr) = ai_info->biased_flight_min; |
| 1313 | } |
| 1314 | break; |
| 1315 | case AIV_F_BIASED_FLIGHT_MAX: |
| 1316 | if (op == VF_SET) { |
| 1317 | ai_info->biased_flight_max = *((float *)ptr); |
| 1318 | } else { |
| 1319 | *((float *)ptr) = ai_info->biased_flight_max; |
| 1320 | } |
| 1321 | break; |
| 1322 | case AIV_F_AWARENESS: |
| 1323 | if (op == VF_SET) { |
| 1324 | ai_info->awareness = *((float *)ptr); |
| 1325 | } else { |
| 1326 | *((float *)ptr) = ai_info->awareness; |
| 1327 | } |
| 1328 | break; |
| 1329 | case AIV_I_FLAGS: |
| 1330 | if (op == VF_GET) { |
| 1331 | *((int *)ptr) = ai_info->flags; |
| 1332 | } else if (op == VF_SET) { |
| 1333 | ai_info->flags = *((int *)ptr); |
| 1334 | } else if (op == VF_SET_FLAGS) { |
| 1335 | ai_info->flags |= *((int *)ptr); |
| 1336 | } else if (op == VF_CLEAR_FLAGS) { |
| 1337 | ai_info->flags &= ~(*((int *)ptr)); |
| 1338 | } |
| 1339 | break; |
| 1340 | case AIV_I_STATUS_REG: |
| 1341 | if (op == VF_GET) { |
| 1342 | *((int *)ptr) = ai_info->status_reg; |
| 1343 | } else if (op == VF_SET) { |
| 1344 | ai_info->status_reg = *((int *)ptr); |
| 1345 | } else if (op == VF_SET_FLAGS) { |
| 1346 | ai_info->status_reg |= *((int *)ptr); |
| 1347 | } else if (op == VF_CLEAR_FLAGS) { |
| 1348 | ai_info->status_reg &= ~(*((int *)ptr)); |
| 1349 | } |
| 1350 | break; |
| 1351 | } |
| 1352 | } |
| 1353 | |
| 1354 | void osipf_ObjectValue(int handle, char op, char var_handle, void *ptr, int index) { |
| 1355 | object *obj = ObjGet(handle); |
| 1356 | if (!obj) { |
| 1357 | if (op == VF_GET && var_handle == OBJV_I_TYPE) |
| 1358 | *(int *)ptr = (int)OBJ_NONE; |
| 1359 | |
| 1360 | return; |
| 1361 | } |
| 1362 | |
| 1363 | msafe_struct m; |
| 1364 | m.objhandle = obj->handle; |
| 1365 | |
| 1366 | switch (var_handle) { |
| 1367 | case OBJV_PI_HACK_FVI_IGNORE_LIST: { |
| 1368 | if (op == VF_SET) { |
| 1369 | if (ptr != NULL) { |
| 1370 | int count = 0; |
| 1371 | |
| 1372 | do { |
| 1373 | hack_list[count] = ((int *)ptr)[count]; |
| 1374 | count++; |
| 1375 | } while (hack_list[count - 1] != -1); |
| 1376 | |
| 1377 | hack_ilist = hack_list; |
| 1378 | } else { |
| 1379 | hack_ilist = NULL; |
| 1380 | } |
| 1381 | } |
| 1382 | } break; |
| 1383 | case OBJV_F_ROTDRAG: |
| 1384 | if (op == VF_SET) { |
| 1385 | m.rot_drag = *(float *)ptr; |
| 1386 | msafe_CallFunction(MSAFE_OBJECT_ROTDRAG, &m); |
| 1387 | } else if (op == VF_GET) |
| 1388 | *(float *)ptr = obj->mtype.phys_info.rotdrag; |
| 1389 | break; |
| 1390 | case OBJV_F_SHIELDS: |
| 1391 | if (op == VF_SET) { |
| 1392 | m.shields = *(float *)ptr; |
| 1393 | msafe_CallFunction(MSAFE_OBJECT_SHIELDS, &m); |
| 1394 | } else if (op == VF_GET) |
| 1395 | *(float *)ptr = obj->shields; |
| 1396 | break; |
| 1397 | case OBJV_I_TYPE: |
| 1398 | if (op == VF_SET) { |
| 1399 | m.type = *(int *)ptr; |
| 1400 | msafe_CallFunction(MSAFE_OBJECT_TYPE, &m); |
| 1401 | } else if (op == VF_GET) |
| 1402 | (*(int *)ptr) = obj->type; |
| 1403 | break; |
| 1404 | case OBJV_US_ID: |
| 1405 | if (op == VF_SET) { |
| 1406 | m.id = *(uint16_t *)ptr; |
| 1407 | msafe_CallFunction(MSAFE_OBJECT_ID, &m); |
| 1408 | } else if (op == VF_GET) |
| 1409 | (*(uint16_t *)ptr) = obj->id; |
| 1410 | break; |
| 1411 | case OBJV_V_POS: |
| 1412 | if (op == VF_SET) { |
| 1413 | ObjSetPos(obj, (vector *)ptr, obj->roomnum, NULL, true); |
| 1414 | obj->flags |= OF_MOVED_THIS_FRAME; |
| 1415 | obj->flags &= ~OF_STOPPED_THIS_FRAME; |
| 1416 | } else if (op == VF_GET) |
| 1417 | *(vector *)ptr = obj->pos; |
| 1418 | break; |
| 1419 | case OBJV_M_ORIENT: |
| 1420 | if (op == VF_SET) { |
| 1421 | ObjSetPos(obj, &obj->pos, obj->roomnum, (matrix *)ptr, true); |
| 1422 | obj->flags |= OF_MOVED_THIS_FRAME; |
| 1423 | obj->flags &= ~OF_STOPPED_THIS_FRAME; |
| 1424 | } else if (op == VF_GET) |
| 1425 | *(matrix *)ptr = obj->orient; |
| 1426 | break; |
| 1427 | case OBJV_I_ROOMNUM: |
| 1428 | if (op == VF_SET) { |
| 1429 | ObjSetPos(obj, &obj->pos, *(int *)ptr, NULL, false); |
| 1430 | obj->flags |= OF_MOVED_THIS_FRAME; |
| 1431 | obj->flags &= ~OF_STOPPED_THIS_FRAME; |
| 1432 | } else if (op == VF_GET) |
| 1433 | *(int *)ptr = obj->roomnum; |
| 1434 | break; |
| 1435 | case OBJV_V_VELOCITY: |
| 1436 | if (op == VF_SET) |
| 1437 | obj->mtype.phys_info.velocity = *(vector *)ptr; |
| 1438 | else if (op == VF_GET) |
| 1439 | *(vector *)ptr = obj->mtype.phys_info.velocity; |
| 1440 | break; |
| 1441 | case OBJV_V_ROTVELOCITY: |
| 1442 | if (op == VF_SET) |
| 1443 | obj->mtype.phys_info.rotvel = *(vector *)ptr; |
| 1444 | else if (op == VF_GET) |
| 1445 | *(vector *)ptr = obj->mtype.phys_info.rotvel; |
| 1446 | break; |
| 1447 | break; |
| 1448 | case OBJV_V_THRUST: |
| 1449 | if (op == VF_SET) |
| 1450 | obj->mtype.phys_info.thrust = *(vector *)ptr; |
| 1451 | else if (op == VF_GET) |
| 1452 | *(vector *)ptr = obj->mtype.phys_info.thrust; |
| 1453 | break; |
| 1454 | break; |
| 1455 | case OBJV_V_ROTTHRUST: |
| 1456 | if (op == VF_SET) |
| 1457 | obj->mtype.phys_info.rotthrust = *(vector *)ptr; |
| 1458 | else if (op == VF_GET) |
| 1459 | (*(vector *)ptr) = obj->mtype.phys_info.rotthrust; |
| 1460 | break; |
| 1461 | break; |
| 1462 | case OBJV_I_FLAGS: { |
| 1463 | int result = obj->flags; |
| 1464 | |
| 1465 | if (op == VF_GET) |
| 1466 | (*(int *)ptr) = obj->flags; |
| 1467 | else if (op == VF_SET) |
| 1468 | result = (*(int *)ptr); |
| 1469 | else if (op == VF_SET_FLAGS) |
| 1470 | result |= (*(int *)ptr); |
| 1471 | else if (op == VF_CLEAR_FLAGS) |
| 1472 | result &= ~(*(int *)ptr); |
| 1473 | |
| 1474 | if (op != VF_GET) { |
| 1475 | m.flags = result; |
| 1476 | msafe_CallFunction(MSAFE_OBJECT_FLAGS, &m); |
| 1477 | } |
| 1478 | } break; |
| 1479 | case OBJV_F_SIZE: |
| 1480 | if (op == VF_GET) |
| 1481 | *(float *)ptr = obj->size; |
| 1482 | break; |
| 1483 | case OBJV_S_NAME: |
| 1484 | if (op == VF_GET) { |
| 1485 | if (obj->name) { |
| 1486 | strcpy((char *)ptr, obj->name); |
| 1487 | } else { |
| 1488 | *((char *)ptr) = 0; |
| 1489 | } |
| 1490 | } |
| 1491 | break; |
| 1492 | case OBJV_C_CONTROL_TYPE: |
| 1493 | if (op == VF_SET) { |
| 1494 | m.control_type = *(char *)ptr; |
| 1495 | msafe_CallFunction(MSAFE_OBJECT_CONTROL_TYPE, &m); |
| 1496 | } else if (op == VF_GET) |
| 1497 | *(char *)ptr = obj->control_type; |
| 1498 | break; |
| 1499 | case OBJV_C_MOVEMENT_TYPE: |
| 1500 | if (op == VF_SET) { |
| 1501 | m.movement_type = *(char *)ptr; |
| 1502 | msafe_CallFunction(MSAFE_OBJECT_MOVEMENT_TYPE, &m); |
| 1503 | } else if (op == VF_GET) |
| 1504 | *(char *)ptr = obj->movement_type; |
| 1505 | break; |
| 1506 | case OBJV_F_CREATION_TIME: |
| 1507 | if (op == VF_SET) { |
| 1508 | m.creation_time = *(float *)ptr; |
| 1509 | msafe_CallFunction(MSAFE_OBJECT_CREATION_TIME, &m); |
| 1510 | } else if (op == VF_GET) |
| 1511 | *(float *)ptr = obj->creation_time; |
| 1512 | break; |
| 1513 | case OBJV_I_PHYSICS_FLAGS: { |
| 1514 | int result = obj->mtype.phys_info.flags; |
| 1515 | |
| 1516 | if (op == VF_GET) |
| 1517 | (*(int *)ptr) = obj->mtype.phys_info.flags; |
| 1518 | else if (op == VF_SET) |
| 1519 | result = (*(int *)ptr); |
| 1520 | else if (op == VF_SET_FLAGS) |
| 1521 | result |= (*(int *)ptr); |
| 1522 | else if (op == VF_CLEAR_FLAGS) |
| 1523 | result &= ~(*(int *)ptr); |
| 1524 | |
| 1525 | if (op != VF_GET) { |
| 1526 | m.physics_flags = result; |
| 1527 | msafe_CallFunction(MSAFE_OBJECT_PHYSICS_FLAGS, &m); |
| 1528 | } |
| 1529 | } break; |
| 1530 | case OBJV_I_PARENT_HANDLE: |
| 1531 | if (op == VF_SET) { |
| 1532 | m.ithandle = *(int *)ptr; |
| 1533 | msafe_CallFunction(MSAFE_OBJECT_PARENT, &m); |
| 1534 | } else if (op == VF_GET) |
| 1535 | (*(int *)ptr) = obj->parent_handle; |
| 1536 | break; |
| 1537 | case OBJV_F_ANIM_FRAME: |
| 1538 | if (op == VF_GET) |
| 1539 | *(float *)ptr = obj->rtype.pobj_info.anim_frame; |
| 1540 | break; |
| 1541 | case OBJV_F_MAX_SHIELDS: |
| 1542 | if (op == VF_GET) { |
| 1543 | if (obj->type == OBJ_PLAYER || obj->type == OBJ_GHOST || obj->type == OBJ_OBSERVER) |
| 1544 | *(float *)ptr = 200.0f; |
| 1545 | else // chrishack -- make sure it is a generic object |
| 1546 | *(float *)ptr = Object_info[obj->id].hit_points; |
| 1547 | } |
| 1548 | break; |
| 1549 | case OBJV_PC_MARKER_MESSAGE: |
| 1550 | if (op == VF_GET) { |
| 1551 | if (obj->type == OBJ_MARKER) { |
| 1552 | strcpy((char *)ptr, MarkerMessages[obj->id]); |
| 1553 | } else { |
| 1554 | ((char *)ptr)[0] = '\0'; |
| 1555 | } |
| 1556 | } |
| 1557 | break; |
| 1558 | case OBJSV_F_ANIM_START: |
| 1559 | if (obj->control_type != CT_AI) |
| 1560 | return; |
| 1561 | |
| 1562 | if (op == VF_GET) |
| 1563 | (*(float *)ptr) = Object_info[obj->id].anim[obj->ai_info->movement_type].elem[index].from; |
| 1564 | else if (op == VF_SET) |
| 1565 | Object_info[obj->id].anim[obj->ai_info->movement_type].elem[index].from = (*(float *)ptr); |
| 1566 | break; |
| 1567 | case OBJSV_F_ANIM_END: |
| 1568 | if (obj->control_type != CT_AI) |
| 1569 | return; |
| 1570 | |
| 1571 | if (op == VF_GET) |
| 1572 | (*(float *)ptr) = Object_info[obj->id].anim[obj->ai_info->movement_type].elem[index].to; |
| 1573 | else if (op == VF_SET) |
| 1574 | Object_info[obj->id].anim[obj->ai_info->movement_type].elem[index].to = (*(float *)ptr); |
| 1575 | break; |
| 1576 | case OBJSV_F_ANIM_TIME: |
| 1577 | if (obj->control_type != CT_AI) |
| 1578 | return; |
| 1579 | |
| 1580 | if (op == VF_GET) |
| 1581 | (*(float *)ptr) = Object_info[obj->id].anim[obj->ai_info->movement_type].elem[index].spc; |
| 1582 | else if (op == VF_SET) |
| 1583 | Object_info[obj->id].anim[obj->ai_info->movement_type].elem[index].spc = (*(float *)ptr); |
| 1584 | break; |
| 1585 | |
| 1586 | case OBJV_C_VIRUS_INFECTED: { |
| 1587 | // the object show signs of virus infection |
| 1588 | if (!obj->effect_info) |
| 1589 | return; |
| 1590 | |
| 1591 | if (op == VF_GET) { |
| 1592 | (*(char *)ptr) = (obj->effect_info->type_flags & EF_VIRUS_INFECTED) ? 1 : 0; |
| 1593 | } else if (op == VF_SET) { |
| 1594 | bool enable = (*(char *)ptr) ? true : false; |
| 1595 | |
| 1596 | if (enable) { |
| 1597 | obj->effect_info->type_flags |= EF_VIRUS_INFECTED; |
| 1598 | } else { |
| 1599 | obj->effect_info->type_flags &= ~EF_VIRUS_INFECTED; |
| 1600 | } |
| 1601 | } |
| 1602 | } break; |
| 1603 | |
| 1604 | case OBJV_C_IS_CLOAKED: |
| 1605 | if (op == VF_GET) { |
| 1606 | if (!obj->effect_info) { |
| 1607 | (*(char *)ptr) = 0; |
| 1608 | } else { |
| 1609 | (*(char *)ptr) = (obj->effect_info->type_flags & EF_CLOAKED) ? 1 : 0; |
| 1610 | } |
| 1611 | } |
| 1612 | break; |
| 1613 | |
| 1614 | case OBJV_C_NEGATIVE_LIGHT: { |
| 1615 | // the object casts negative light |
| 1616 | if (!obj->effect_info) |
| 1617 | return; |
| 1618 | |
| 1619 | if (op == VF_GET) { |
| 1620 | (*(char *)ptr) = (obj->effect_info->type_flags & EF_NEGATIVE_LIGHT) ? 1 : 0; |
| 1621 | } else if (op == VF_SET) { |
| 1622 | bool enable = (*(char *)ptr) ? true : false; |
| 1623 | |
| 1624 | if (enable) { |
| 1625 | obj->effect_info->type_flags |= EF_NEGATIVE_LIGHT; |
| 1626 | } else { |
| 1627 | obj->effect_info->type_flags &= ~EF_NEGATIVE_LIGHT; |
| 1628 | } |
| 1629 | } |
| 1630 | |
| 1631 | } break; |
| 1632 | } |
| 1633 | } |
| 1634 | |
| 1635 | uint8_t osipf_AITurnTowardsVectors(int objhandle, vector *fvec, vector *uvec) { |
| 1636 | object *objp = ObjGet(objhandle); |
| 1637 | |
| 1638 | if (!objp) { |
| 1639 | mprintf(0, "AITurnTowardsVectors: Illegal Object Passed\n"); |
| 1640 | return 0; |
| 1641 | } |
| 1642 | |
| 1643 | if (objp->control_type != CT_AI) { |
| 1644 | mprintf(0, "AITurnTowardsVectors: Illegal Object CT Passed\n"); |
| 1645 | return 0; |
| 1646 | } |
| 1647 | |
| 1648 | matrix g_orient; |
| 1649 | vm_VectorToMatrix(&g_orient, fvec, uvec, NULL); |
| 1650 | |
| 1651 | return AITurnTowardsMatrix(objp, objp->ai_info->max_turn_rate, &g_orient); |
| 1652 | } |
| 1653 | |
| 1654 | void osipf_AISetType(int objhandle, int type) { |
| 1655 | object *objp = ObjGet(objhandle); |
| 1656 | |
| 1657 | if (!objp) { |
| 1658 | mprintf(0, "AISetType: Illegal Object Passed\n"); |
| 1659 | return; |
| 1660 | } |
| 1661 | |
| 1662 | if (objp->control_type != CT_AI) { |
| 1663 | mprintf(0, "AISetType: Illegal Object CT Passed\n"); |
| 1664 | return; |
| 1665 | } |
| 1666 | |
| 1667 | if (type < 0 || type >= MAX_AI_INIT_TYPES) |
| 1668 | return; |
| 1669 | |
| 1670 | GoalInitTypeGoals(objp, type); |
| 1671 | } |
| 1672 | |
| 1673 | vector osipf_AIFindHidePos(int hideobjhandle, int viewobjhandle, float time, int *hide_room) { |
| 1674 | object *hide_obj = ObjGet(hideobjhandle); |
| 1675 | object *view_obj = ObjGet(viewobjhandle); |
| 1676 | |
| 1677 | vector hpos; |
| 1678 | int hroom; |
| 1679 | |
| 1680 | if (hide_obj == NULL) { |
| 1681 | mprintf(0, "Illegal Hide Object Passed To AIFindHidePos\n"); |
| 1682 | *hide_room = -1; |
| 1683 | return Zero_vector; |
| 1684 | } |
| 1685 | |
| 1686 | if (hide_obj->control_type != CT_AI) { |
| 1687 | mprintf(0, "Illegal Object CT Passed To AIFindHidePos\n"); |
| 1688 | *hide_room = -1; |
| 1689 | return Zero_vector; |
| 1690 | } |
| 1691 | |
| 1692 | if (view_obj == NULL) { |
| 1693 | mprintf(0, "Illegal View Object Passed To AIFindHidePos\n"); |
| 1694 | *hide_room = hide_obj->roomnum; |
| 1695 | return hide_obj->pos; |
| 1696 | } |
| 1697 | |
| 1698 | if (time <= 0.0) { |
| 1699 | mprintf(0, "AIFindHidePos: Illegal Time Passed bashing to 1sec\n"); |
| 1700 | time = 1.0f; |
| 1701 | } else if (time > 15.0) { |
| 1702 | mprintf(0, "AIFindHidePos: Illegal Time Passed bashing to 15sec\n"); |
| 1703 | time = 15.0f; |
| 1704 | } |
| 1705 | |
| 1706 | // Returns the hide object's pos/room if it cannot find a valid hide position |
| 1707 | AIFindHidePos(hide_obj, view_obj, &hpos, &hroom, time); |
| 1708 | |
| 1709 | *hide_room = hroom; |
| 1710 | return hpos; |
| 1711 | } |
| 1712 | |
| 1713 | int osipf_AIGoalAddEnabler(int objhandle, int goal_index, int enabler_type, float percent, float interval, void *ptr) { |
| 1714 | object *obj; |
| 1715 | |
| 1716 | obj = ObjGet(objhandle); |
| 1717 | |
| 1718 | if (obj == NULL || obj->ai_info == NULL) { |
| 1719 | mprintf(0, "Illegal object passed to AIGoalAddEnabler\n"); |
| 1720 | return -1; |
| 1721 | } |
| 1722 | |
| 1723 | if (!ptr) |
| 1724 | return -1; |
| 1725 | |
| 1726 | return GoalAddEnabler(obj, goal_index, enabler_type, ptr, percent, interval); |
| 1727 | } |
| 1728 | |
| 1729 | int osipf_AIGoalAdd(int objhandle, int goal_type, int level, float influence, int guid, int flags, ...) { |
| 1730 | object *obj; |
| 1731 | goal_info g_info; |
| 1732 | va_list marker; |
| 1733 | |
| 1734 | obj = ObjGet(objhandle); |
| 1735 | if (obj == NULL || obj->ai_info == NULL) { |
| 1736 | mprintf(0, "Illegal object passed to AIGoalAdd\n"); |
| 1737 | return -1; |
| 1738 | } |
| 1739 | |
| 1740 | switch (goal_type) { |
| 1741 | case AIG_GET_AWAY_FROM_OBJ: |
| 1742 | case AIG_GET_TO_OBJ: |
| 1743 | case AIG_GUARD_OBJ: |
| 1744 | case AIG_DODGE_OBJ: |
| 1745 | case AIG_MOVE_AROUND_OBJ: |
| 1746 | case AIG_MOVE_RELATIVE_OBJ: |
| 1747 | case AIG_GET_AROUND_OBJ: { |
| 1748 | // Pop Goal Local Variables |
| 1749 | va_start(marker, flags); |
| 1750 | int objref = va_arg(marker, int); |
| 1751 | va_end(marker); |
| 1752 | |
| 1753 | // Do the actual goal and return; |
| 1754 | return GoalAddGoal(obj, goal_type, (void *)&objref, level, influence, flags, guid); |
| 1755 | } break; |
| 1756 | |
| 1757 | case AIG_FOLLOW_PATH: { |
| 1758 | path_information path_info; |
| 1759 | |
| 1760 | va_start(marker, flags); |
| 1761 | path_info.path_id = va_arg(marker, int); |
| 1762 | path_info.start_node = va_arg(marker, int) - 1; |
| 1763 | path_info.end_node = va_arg(marker, int) - 1; |
| 1764 | path_info.next_node = va_arg(marker, int) - 1; |
| 1765 | va_end(marker); |
| 1766 | |
| 1767 | if (path_info.path_id >= 0 && path_info.end_node < 0) { |
| 1768 | path_info.end_node = GamePaths[path_info.path_id].num_nodes - 1; |
| 1769 | } |
| 1770 | |
| 1771 | return GoalAddGoal(obj, AIG_FOLLOW_PATH, (void *)&path_info, level, influence, flags, guid); |
| 1772 | } break; |
| 1773 | |
| 1774 | case AIG_ATTACH_TO_OBJ: |
| 1775 | case AIG_PLACE_OBJ_ON_OBJ: { |
| 1776 | goal_info g_info; |
| 1777 | g_info.attach_info.flags = 0; |
| 1778 | |
| 1779 | // Pop Goal Local Variables |
| 1780 | va_start(marker, flags); |
| 1781 | g_info.handle = va_arg(marker, int); |
| 1782 | g_info.attach_info.parent_ap = va_arg(marker, int); |
| 1783 | g_info.attach_info.child_ap = va_arg(marker, int); |
| 1784 | g_info.attach_info.rad = va_arg(marker, double); |
| 1785 | |
| 1786 | object *objp = ObjGet(g_info.handle); |
| 1787 | if (objp && (objp->type == OBJ_POWERUP)) |
| 1788 | g_info.attach_info.rad /= 2; |
| 1789 | |
| 1790 | if (va_arg(marker, int) != 0) |
| 1791 | g_info.attach_info.flags = GAF_ALIGNED; |
| 1792 | if (va_arg(marker, int) != 0) |
| 1793 | g_info.attach_info.flags |= GAF_SPHERE; |
| 1794 | va_end(marker); |
| 1795 | |
| 1796 | // Do the actual goal and return; |
| 1797 | return GoalAddGoal(obj, goal_type, (void *)&g_info, level, influence, flags, guid); |
| 1798 | } break; |
| 1799 | |
| 1800 | case AIG_FIRE_AT_OBJ: { |
| 1801 | // Pop Goal Local Variables |
| 1802 | va_start(marker, flags); |
| 1803 | int i = va_arg(marker, int); |
| 1804 | va_end(marker); |
| 1805 | |
| 1806 | gi_fire attack_info; |
| 1807 | |
| 1808 | attack_info.cur_wb = i; |
| 1809 | attack_info.cur_mask = obj->dynamic_wb[i].cur_firing_mask; |
| 1810 | |
| 1811 | // Do the actual goal and return; |
| 1812 | return GoalAddGoal(obj, goal_type, (void *)&attack_info, level, influence, flags, guid); |
| 1813 | } break; |
| 1814 | |
| 1815 | case AIG_MOVE_RELATIVE_OBJ_VEC: { |
| 1816 | va_start(marker, flags); |
| 1817 | // Pop Goal Local Variables |
| 1818 | int objref = va_arg(marker, int); |
| 1819 | int i_value = va_arg(marker, int); |
| 1820 | va_end(marker); |
| 1821 | |
| 1822 | g_info.handle = objref; |
| 1823 | |
| 1824 | // Do the actual goal and return; |
| 1825 | return GoalAddGoal(obj, goal_type, (void *)&g_info, level, influence, flags, guid, i_value); |
| 1826 | } break; |
| 1827 | |
| 1828 | case AIG_HIDE_FROM_OBJ: { |
| 1829 | // Pop Goal Local Variables |
| 1830 | va_start(marker, flags); |
| 1831 | int objref = va_arg(marker, int); |
| 1832 | int f_value = va_arg(marker, int); |
| 1833 | va_end(marker); |
| 1834 | |
| 1835 | g_info.handle = objref; |
| 1836 | g_info.time = f_value; |
| 1837 | |
| 1838 | // Do the actual goal and return; |
| 1839 | return GoalAddGoal(obj, goal_type, (void *)&g_info, level, influence, flags, guid); |
| 1840 | } break; |
| 1841 | |
| 1842 | case AIG_GUARD_AREA: |
| 1843 | case AIG_GET_TO_POS: { |
| 1844 | // Pop Goal Local Variables |
| 1845 | va_start(marker, flags); |
| 1846 | vector *pos = va_arg(marker, vector *); |
| 1847 | int roomnum = va_arg(marker, int); |
| 1848 | va_end(marker); |
| 1849 | |
| 1850 | g_info.pos = (*pos); |
| 1851 | g_info.roomnum = roomnum; |
| 1852 | |
| 1853 | // Do the actual goal and return; |
| 1854 | return GoalAddGoal(obj, goal_type, (void *)&g_info, level, influence, flags, guid); |
| 1855 | } break; |
| 1856 | |
| 1857 | case AIG_MELEE_TARGET: { |
| 1858 | // Do the actual goal and return; |
| 1859 | return GoalAddGoal(obj, goal_type, (void *)NULL, level, influence, flags, guid); |
| 1860 | } break; |
| 1861 | |
| 1862 | case AIG_SET_ANIM: // Animation index |
| 1863 | case AIG_DO_MELEE_ANIM: // Which melee attack |
| 1864 | case AIG_USE_MOVEMENT_TYPE: // MT_INDEX |
| 1865 | case AIG_SCRIPTED: { |
| 1866 | // Pop Goal Local Variables |
| 1867 | va_start(marker, flags); |
| 1868 | int i_value = va_arg(marker, int); |
| 1869 | va_end(marker); |
| 1870 | |
| 1871 | // Do the actual goal and return; |
| 1872 | return GoalAddGoal(obj, goal_type, (void *)&i_value, level, influence, flags, guid); |
| 1873 | } break; |
| 1874 | |
| 1875 | case AIG_WANDER_AROUND: // Initial room |
| 1876 | { |
| 1877 | // Pop Goal Local Variables |
| 1878 | va_start(marker, flags); |
| 1879 | int i_value = va_arg(marker, int); |
| 1880 | int j_value = va_arg(marker, int); |
| 1881 | va_end(marker); |
| 1882 | |
| 1883 | // Do the actual goal and return; |
| 1884 | return GoalAddGoal(obj, goal_type, (void *)&i_value, level, influence, flags, guid); |
| 1885 | } break; |
| 1886 | |
| 1887 | case AIG_FACE_DIR: // MT_INDEX |
| 1888 | { |
| 1889 | // Pop Goal Local Variables |
| 1890 | va_start(marker, flags); |
| 1891 | vector *v_value = va_arg(marker, vector *); |
| 1892 | va_end(marker); |
| 1893 | |
| 1894 | // Do the actual goal and return; |
| 1895 | return GoalAddGoal(obj, goal_type, (void *)v_value, level, influence, flags, guid); |
| 1896 | } break; |
| 1897 | |
| 1898 | default: |
| 1899 | mprintf(0, "AIGoalAdd Error: Get chris - goal %d is not available of scripting\n", goal_type); |
| 1900 | } |
| 1901 | |
| 1902 | return -1; |
| 1903 | } |
| 1904 | |
| 1905 | void osipf_AIGoalClear(int objhandle, int goal_index) { |
| 1906 | object *obj = ObjGet(objhandle); |
| 1907 | |
| 1908 | if (obj == NULL) { |
| 1909 | mprintf(0, "Invalid Object Passed To AIGoalClear\n"); |
| 1910 | return; |
| 1911 | } |
| 1912 | |
| 1913 | if (obj->control_type != CT_AI) { |
| 1914 | mprintf(0, "AIGoalClear: Illegal Object CT Passed\n"); |
| 1915 | return; |
| 1916 | } |
| 1917 | |
| 1918 | if (goal_index < 0) { |
| 1919 | GoalClearAll(obj); |
| 1920 | } else if (goal_index < MAX_GOALS) { |
| 1921 | GoalClearGoal(obj, &obj->ai_info->goals[goal_index]); |
| 1922 | } |
| 1923 | } |
| 1924 | |
| 1925 | int osipf_AIFindObjOfType(int objhandle, int type, int id, bool f_ignore_init_room, int parent_handle) { |
| 1926 | object *obj = ObjGet(objhandle); |
| 1927 | object *f_obj; |
| 1928 | |
| 1929 | if (obj == NULL) { |
| 1930 | mprintf(0, "Illegal Object Passed To AIFindObjOfType\n"); |
| 1931 | return OBJECT_HANDLE_NONE; |
| 1932 | } |
| 1933 | |
| 1934 | if ((f_obj = AIFindObjOfType(obj, type, id, f_ignore_init_room, parent_handle))) |
| 1935 | return f_obj->handle; |
| 1936 | |
| 1937 | return OBJECT_HANDLE_NONE; |
| 1938 | } |
| 1939 | |
| 1940 | int osipf_ObjMakeListOfType(int objhandle, int type, int id, bool f_ignore_init_room, int parent_handle, |
| 1941 | int max_recorded, int *handles) { |
| 1942 | object *obj = ObjGet(objhandle); |
| 1943 | |
| 1944 | int num_recorded = 0; |
| 1945 | int i; |
| 1946 | |
| 1947 | if (obj == NULL) { |
| 1948 | mprintf(0, "Illegal Object Passed To Obj_MakeListOfType\n"); |
| 1949 | return OBJECT_HANDLE_NONE; |
| 1950 | } |
| 1951 | |
| 1952 | for (i = 0; i <= Highest_object_index; i++) { |
| 1953 | if (Objects[i].type == type) { |
| 1954 | if (Objects[i].type == OBJ_NONE) |
| 1955 | continue; |
| 1956 | |
| 1957 | if (&Objects[i] == obj) |
| 1958 | continue; |
| 1959 | |
| 1960 | if (f_ignore_init_room && Objects[i].roomnum == obj->roomnum) |
| 1961 | continue; |
| 1962 | |
| 1963 | if (parent_handle != OBJECT_HANDLE_NONE && Objects[i].parent_handle != parent_handle) |
| 1964 | continue; |
| 1965 | |
| 1966 | if (id != -1 && Objects[i].id != id) |
| 1967 | continue; |
| 1968 | |
| 1969 | handles[num_recorded++] = Objects[i].handle; |
| 1970 | |
| 1971 | if (num_recorded >= max_recorded) |
| 1972 | break; |
| 1973 | } |
| 1974 | } |
| 1975 | |
| 1976 | return num_recorded; |
| 1977 | } |
| 1978 | |
| 1979 | vector osipf_AIGetRoomPathPoint(int roomnum) { |
| 1980 | if (ROOMNUM_OUTSIDE(roomnum)) { |
| 1981 | int cell = CELLNUM(roomnum); |
| 1982 | |
| 1983 | if (cell >= TERRAIN_DEPTH * TERRAIN_WIDTH) { |
| 1984 | return Zero_vector; |
| 1985 | } else { |
| 1986 | vector pos; |
| 1987 | |
| 1988 | ComputeTerrainSegmentCenter(&pos, cell); |
| 1989 | pos.y += 15.0f + ((float)ps_rand() / (float)D3_RAND_MAX) * 20; // between 15 and 35 |
| 1990 | |
| 1991 | return pos; |
| 1992 | } |
| 1993 | } else if (roomnum <= Highest_room_index && Rooms[roomnum].used) { |
| 1994 | return Rooms[roomnum].path_pnt; |
| 1995 | } |
| 1996 | |
| 1997 | return Zero_vector; |
| 1998 | } |
| 1999 | |
| 2000 | int osipf_AIFindEnergyCenter(int objhandle) { |
| 2001 | object *obj = ObjGet(objhandle); |
| 2002 | |
| 2003 | if (obj == NULL) { |
| 2004 | mprintf(0, "Illegal Object Passed To AIFindEnergyCenter\n"); |
| 2005 | return -1; |
| 2006 | } |
| 2007 | |
| 2008 | // returns the roomnum of the closest room with that flag |
| 2009 | return AIFindRoomWithFlag(obj, RF_FUELCEN); |
| 2010 | } |
| 2011 | |
| 2012 | float osipf_AIGetDistToObj(int objhandle, int otherobjhandle) { |
| 2013 | object *obj = ObjGet(objhandle); |
| 2014 | object *fobj = ObjGet(otherobjhandle); |
| 2015 | |
| 2016 | float dist; |
| 2017 | |
| 2018 | if (obj == NULL) { |
| 2019 | mprintf(0, "Illegal Object Passed To AIGetDistToObj\n"); |
| 2020 | return 0; |
| 2021 | } |
| 2022 | |
| 2023 | if (fobj == NULL) { |
| 2024 | mprintf(0, "Illegal Find Object Passed To AIGetDistToObj\n"); |
| 2025 | return 0; |
| 2026 | } |
| 2027 | |
| 2028 | BOA_ComputeMinDist(obj->roomnum, fobj->roomnum, 0.0f, &dist, NULL); |
| 2029 | |
| 2030 | return dist; |
| 2031 | } |
| 2032 | |
| 2033 | int osipf_AISetGoalFlags(int objhandle, int goal_handle, int flags, uint8_t f_enable) { |
| 2034 | object *obj = ObjGet(objhandle); |
| 2035 | |
| 2036 | if (obj == NULL) { |
| 2037 | mprintf(0, "Illegal Object Passed To AISetGoalFlags\n"); |
| 2038 | return 0; |
| 2039 | } |
| 2040 | |
| 2041 | if (obj->control_type != CT_AI) { |
| 2042 | mprintf(0, "Non-AI Object Passed To AISetGoalFlags\n"); |
| 2043 | return 0; |
| 2044 | } |
| 2045 | |
| 2046 | ai_frame *ai_info = obj->ai_info; |
| 2047 | |
| 2048 | if (goal_handle >= 0 && goal_handle < MAX_GOALS && ai_info->goals[goal_handle].used != 0) { |
| 2049 | if (f_enable) |
| 2050 | ai_info->goals[goal_handle].flags |= flags; |
| 2051 | else |
| 2052 | ai_info->goals[goal_handle].flags &= ~flags; |
| 2053 | } |
| 2054 | |
| 2055 | return (ai_info->goals[goal_handle].flags); |
| 2056 | } |
| 2057 | |
| 2058 | void osipf_AISetGoalCircleDist(int objhandle, int goal_handle, float dist) { |
| 2059 | object *obj = ObjGet(objhandle); |
| 2060 | |
| 2061 | if (obj == NULL) { |
| 2062 | mprintf(0, "Illegal Object Passed To AISetGoalCircleDist\n"); |
| 2063 | return; |
| 2064 | } |
| 2065 | |
| 2066 | if (obj->control_type != CT_AI) { |
| 2067 | mprintf(0, "Non-AI Object Passed To AISetGoalCircleDist\n"); |
| 2068 | return; |
| 2069 | } |
| 2070 | |
| 2071 | ai_frame *ai_info = obj->ai_info; |
| 2072 | |
| 2073 | if (goal_handle >= 0 && goal_handle < MAX_GOALS && ai_info->goals[goal_handle].used != 0) { |
| 2074 | ai_info->goals[goal_handle].circle_distance = dist; |
| 2075 | } |
| 2076 | } |
| 2077 | |
| 2078 | void osipf_GetGunPos(int objhandle, int gun_number, vector *gun_pnt, vector *gun_normal) { |
| 2079 | object *obj = ObjGet(objhandle); |
| 2080 | |
| 2081 | if (obj == NULL) { |
| 2082 | mprintf(0, "Illegal Object Passed To AIGetGunPosition\n"); |
| 2083 | *gun_pnt = Zero_vector; |
| 2084 | *gun_normal = Zero_vector; |
| 2085 | return; |
| 2086 | } |
| 2087 | |
| 2088 | WeaponCalcGun(gun_pnt, gun_normal, obj, gun_number); |
| 2089 | } |
| 2090 | |
| 2091 | void osipf_GetGroundPos(int objhandle, int ground_number, vector *ground_pnt, vector *ground_normal) { |
| 2092 | object *obj = ObjGet(objhandle); |
| 2093 | |
| 2094 | if (obj == NULL) { |
| 2095 | mprintf(0, "Illegal Object Passed To Obj_GetGroundPos\n"); |
| 2096 | *ground_pnt = Zero_vector; |
| 2097 | *ground_normal = Zero_vector; |
| 2098 | return; |
| 2099 | } |
| 2100 | |
| 2101 | PhysCalcGround(ground_pnt, ground_normal, obj, ground_number); |
| 2102 | } |
| 2103 | |
| 2104 | uint8_t osipf_IsRoomValid(int roomnum) { |
| 2105 | if (roomnum == -1.0) { |
| 2106 | return 0; |
| 2107 | } else if (ROOMNUM_OUTSIDE(roomnum)) { |
| 2108 | int cell = CELLNUM(roomnum); |
| 2109 | |
| 2110 | if ((CELLNUM(cell) < 0) || (cell >= TERRAIN_WIDTH * TERRAIN_DEPTH)) { |
| 2111 | return 0; |
| 2112 | } else { |
| 2113 | return 1; |
| 2114 | } |
| 2115 | } else { |
| 2116 | if (roomnum < 0 || roomnum > Highest_room_index || Rooms[roomnum].used == 0) { |
| 2117 | return 0; |
| 2118 | } else { |
| 2119 | return 2; |
| 2120 | } |
| 2121 | } |
| 2122 | |
| 2123 | return 0; |
| 2124 | } |
| 2125 | |
| 2126 | int osipf_GetAttachParent(int childhandle) { |
| 2127 | object *child = ObjGet(childhandle); |
| 2128 | |
| 2129 | if ((child) && (child->flags & OF_ATTACHED)) { |
| 2130 | return (child->attach_parent_handle); |
| 2131 | } |
| 2132 | |
| 2133 | return (OBJECT_HANDLE_NONE); |
| 2134 | } |
| 2135 | |
| 2136 | int osipf_GetNumAttachSlots(int objhandle) { |
| 2137 | object *parent = ObjGet(objhandle); |
| 2138 | |
| 2139 | if ((parent) && (parent->flags & OF_POLYGON_OBJECT)) { |
| 2140 | poly_model *parent_pm = &Poly_models[parent->rtype.pobj_info.model_num]; |
| 2141 | return (parent_pm->n_attach); |
| 2142 | } |
| 2143 | |
| 2144 | return 0; |
| 2145 | } |
| 2146 | |
| 2147 | int osipf_GetAttachChildHandle(int objhandle, char attachpoint) { |
| 2148 | object *parent = ObjGet(objhandle); |
| 2149 | char parent_ap = attachpoint; |
| 2150 | |
| 2151 | if ((parent) && (parent->flags & OF_POLYGON_OBJECT)) { |
| 2152 | poly_model *parent_pm = &Poly_models[parent->rtype.pobj_info.model_num]; |
| 2153 | if (parent_ap >= 0 && parent_ap < parent_pm->n_attach) { |
| 2154 | return (parent->attach_children[parent_ap]); |
| 2155 | } |
| 2156 | } |
| 2157 | |
| 2158 | return (OBJECT_HANDLE_NONE); |
| 2159 | } |
| 2160 | |
| 2161 | int osipf_AttachObjectAP(int parenthandle, char parent_ap, int childhandle, char child_ap, uint8_t f_use_aligned) { |
| 2162 | object *parent = ObjGet(parenthandle); |
| 2163 | object *child = ObjGet(childhandle); |
| 2164 | |
| 2165 | if ((parent) && (parent->flags & OF_POLYGON_OBJECT) && (child) && (child->flags & OF_POLYGON_OBJECT)) { |
| 2166 | return AttachObject(parent, parent_ap, child, child_ap, (bool)(f_use_aligned != 0)); |
| 2167 | } |
| 2168 | |
| 2169 | return 0; |
| 2170 | } |
| 2171 | |
| 2172 | int osipf_AttachObjectRad(int parenthandle, char parent_ap, int childhandle, float percent_rad) { |
| 2173 | object *parent = ObjGet(parenthandle); |
| 2174 | object *child = ObjGet(childhandle); |
| 2175 | |
| 2176 | if ((parent) && (parent->flags & OF_POLYGON_OBJECT) && (child) && (child->flags & OF_POLYGON_OBJECT)) { |
| 2177 | return AttachObject(parent, parent_ap, child, percent_rad); |
| 2178 | } |
| 2179 | |
| 2180 | return 0; |
| 2181 | } |
| 2182 | |
| 2183 | void osipf_UnattachFromParent(int objhandle) { |
| 2184 | object *child = ObjGet(objhandle); |
| 2185 | |
| 2186 | if ((child) && (child->flags & OF_POLYGON_OBJECT)) { |
| 2187 | UnattachFromParent(child); |
| 2188 | } |
| 2189 | } |
| 2190 | |
| 2191 | void osipf_UnattachChild(int objhandle, char parent_ap) { |
| 2192 | object *parent = ObjGet(objhandle); |
| 2193 | |
| 2194 | if ((parent) && (parent->flags & OF_POLYGON_OBJECT)) { |
| 2195 | UnattachChild(parent, parent_ap); |
| 2196 | } |
| 2197 | } |
| 2198 | |
| 2199 | void osipf_UnattachChildren(int objhandle) { |
| 2200 | object *parent = ObjGet(objhandle); |
| 2201 | |
| 2202 | if ((parent) && (parent->flags & OF_POLYGON_OBJECT)) { |
| 2203 | UnattachChildren(parent); |
| 2204 | } |
| 2205 | } |
| 2206 | |
| 2207 | void osipf_MatcenValue(int matcen_id, char op, char var_handle, void *ptr, int index) { |
| 2208 | if (matcen_id < 0 || matcen_id >= Num_matcens || !Matcen[matcen_id]) |
| 2209 | return; |
| 2210 | switch (var_handle) { |
| 2211 | case MTNV_C_ATTACH_TYPE: |
| 2212 | if (op == VF_GET) |
| 2213 | (*(char *)ptr) = Matcen[matcen_id]->GetAttachType(); |
| 2214 | else if (op == VF_SET) |
| 2215 | Matcen[matcen_id]->SetAttachType(*(char *)ptr); |
| 2216 | break; |
| 2217 | case MTNV_C_CONTROL_TYPE: |
| 2218 | if (op == VF_GET) |
| 2219 | (*(char *)ptr) = Matcen[matcen_id]->GetControlType(); |
| 2220 | else if (op == VF_SET) |
| 2221 | Matcen[matcen_id]->SetControlType(*(char *)ptr); |
| 2222 | break; |
| 2223 | case MTNV_I_ATTACH: |
| 2224 | if (op == VF_GET) |
| 2225 | (*(int *)ptr) = Matcen[matcen_id]->GetAttach(); |
| 2226 | else if (op == VF_SET) |
| 2227 | Matcen[matcen_id]->SetAttach(*(int *)ptr); |
| 2228 | break; |
| 2229 | case MTNV_V_CREATE_POINT: |
| 2230 | if (op == VF_GET) |
| 2231 | Matcen[matcen_id]->GetCreatePnt((vector *)ptr); |
| 2232 | else if (op == VF_SET) |
| 2233 | Matcen[matcen_id]->SetCreatePnt((vector *)ptr); |
| 2234 | break; |
| 2235 | case MTNV_I_CREATE_ROOM: |
| 2236 | if (op == VF_GET) |
| 2237 | (*(int *)ptr) = Matcen[matcen_id]->GetCreateRoom(); |
| 2238 | else if (op == VF_SET) |
| 2239 | Matcen[matcen_id]->SetCreateRoom(*(int *)ptr); |
| 2240 | break; |
| 2241 | case MTNV_PC_NAME: |
| 2242 | if (op == VF_GET) |
| 2243 | Matcen[matcen_id]->GetName((char *)ptr); |
| 2244 | else if (op == VF_SET) |
| 2245 | Matcen[matcen_id]->SetName((char *)ptr); |
| 2246 | break; |
| 2247 | case MTNV_I_MAX_PROD: |
| 2248 | if (op == VF_GET) |
| 2249 | (*(int *)ptr) = Matcen[matcen_id]->GetMaxProd(); |
| 2250 | else if (op == VF_SET) |
| 2251 | Matcen[matcen_id]->SetMaxProd(*(int *)ptr); |
| 2252 | break; |
| 2253 | case MTNV_F_PROD_MULTIPLIER: |
| 2254 | if (op == VF_GET) |
| 2255 | (*(float *)ptr) = Matcen[matcen_id]->GetProdMultiplier(); |
| 2256 | else if (op == VF_SET) |
| 2257 | Matcen[matcen_id]->SetProdMultiplier(*(float *)ptr); |
| 2258 | break; |
| 2259 | case MTNV_I_STATUS: |
| 2260 | if (op == VF_GET) |
| 2261 | (*(int *)ptr) = Matcen[matcen_id]->GetStatus(); |
| 2262 | else if (op == VF_SET_FLAGS) |
| 2263 | Matcen[matcen_id]->SetStatus(*(int *)ptr, true); |
| 2264 | else if (op == VF_CLEAR_FLAGS) |
| 2265 | Matcen[matcen_id]->SetStatus(*(int *)ptr, false); |
| 2266 | else if (op == VF_SET) { |
| 2267 | int status = Matcen[matcen_id]->GetStatus(); |
| 2268 | int diff_flags = (*(int *)ptr) ^ status; |
| 2269 | int clear_flags = status & diff_flags; |
| 2270 | int set_flags = (~(status)) & diff_flags; |
| 2271 | |
| 2272 | if (set_flags) |
| 2273 | Matcen[matcen_id]->SetStatus(set_flags, true); |
| 2274 | if (clear_flags) |
| 2275 | Matcen[matcen_id]->SetStatus(clear_flags, false); |
| 2276 | } |
| 2277 | break; |
| 2278 | case MTNV_C_CREATION_EFFECT: |
| 2279 | if (op == VF_GET) |
| 2280 | (*(char *)ptr) = Matcen[matcen_id]->GetCreationEffect(); |
| 2281 | else if (op == VF_SET) |
| 2282 | Matcen[matcen_id]->SetCreationEffect(*(char *)ptr); |
| 2283 | break; |
| 2284 | case MTNV_I_MAX_ALIVE_CHILDREN: |
| 2285 | if (op == VF_GET) |
| 2286 | (*(int *)ptr) = Matcen[matcen_id]->GetMaxAliveChildren(); |
| 2287 | else if (op == VF_SET) |
| 2288 | Matcen[matcen_id]->SetMaxAliveChildren(*(int *)ptr); |
| 2289 | break; |
| 2290 | case MTNV_F_PRE_PROD_TIME: |
| 2291 | if (op == VF_GET) |
| 2292 | (*(float *)ptr) = Matcen[matcen_id]->GetPreProdTime(); |
| 2293 | else if (op == VF_SET) |
| 2294 | Matcen[matcen_id]->SetPreProdTime(*(float *)ptr); |
| 2295 | break; |
| 2296 | case MTNV_F_POST_PROD_TIME: |
| 2297 | if (op == VF_GET) |
| 2298 | (*(float *)ptr) = Matcen[matcen_id]->GetPostProdTime(); |
| 2299 | else if (op == VF_SET) |
| 2300 | Matcen[matcen_id]->SetPostProdTime(*(float *)ptr); |
| 2301 | break; |
| 2302 | case MTNSV_I_SOUND: |
| 2303 | if (op == VF_GET) |
| 2304 | (*(int *)ptr) = Matcen[matcen_id]->GetSound(index); |
| 2305 | else if (op == VF_SET) |
| 2306 | Matcen[matcen_id]->SetSound(index, (*(int *)ptr)); |
| 2307 | break; |
| 2308 | case MTNV_S_CREATION_TEXTURE: |
| 2309 | if (op == VF_GET) |
| 2310 | (*(int16_t *)ptr) = Matcen[matcen_id]->GetCreationTexture(); |
| 2311 | else if (op == VF_SET) |
| 2312 | Matcen[matcen_id]->SetCreationTexture(*(int16_t *)ptr); |
| 2313 | break; |
| 2314 | |
| 2315 | case MTNV_C_NUM_SPAWN_PTS: |
| 2316 | if (op == VF_GET) |
| 2317 | (*(char *)ptr) = Matcen[matcen_id]->GetNumSpawnPnts(); |
| 2318 | else if (op == VF_SET) |
| 2319 | Matcen[matcen_id]->SetNumSpawnPnts(*(char *)ptr); |
| 2320 | break; |
| 2321 | case MTNSV_I_SPAWN_POINT: |
| 2322 | if (op == VF_GET) |
| 2323 | Matcen[matcen_id]->SetSpawnPnt(index, *(int *)ptr); |
| 2324 | else if (op == VF_SET) |
| 2325 | (*(int *)ptr) = Matcen[matcen_id]->GetSpawnPnt(index); |
| 2326 | break; |
| 2327 | |
| 2328 | case MTNV_C_NUM_PROD_TYPES: |
| 2329 | if (op == VF_GET) |
| 2330 | (*(char *)ptr) = Matcen[matcen_id]->GetNumProdTypes(); |
| 2331 | else if (op == VF_SET) |
| 2332 | Matcen[matcen_id]->SetNumSpawnPnts(*(char *)ptr); |
| 2333 | break; |
| 2334 | case MTNSV_I_PROD_ITEM_ID: |
| 2335 | if (op == VF_GET) |
| 2336 | Matcen[matcen_id]->GetProdInfo(index, (int *)ptr, NULL, NULL, NULL); |
| 2337 | else if (op == VF_SET) |
| 2338 | Matcen[matcen_id]->SetProdInfo(index, (int *)ptr, NULL, NULL, NULL); |
| 2339 | break; |
| 2340 | case MTNSV_I_PROD_ITEM_PRIORITY: |
| 2341 | if (op == VF_GET) |
| 2342 | Matcen[matcen_id]->GetProdInfo(index, NULL, (int *)ptr, NULL, NULL); |
| 2343 | else if (op == VF_SET) |
| 2344 | Matcen[matcen_id]->SetProdInfo(index, NULL, (int *)ptr, NULL, NULL); |
| 2345 | break; |
| 2346 | case MTNSV_F_PROD_ITEM_TIME: |
| 2347 | if (op == VF_GET) |
| 2348 | Matcen[matcen_id]->GetProdInfo(index, NULL, NULL, (float *)ptr, NULL); |
| 2349 | else if (op == VF_SET) |
| 2350 | Matcen[matcen_id]->SetProdInfo(index, NULL, NULL, (float *)ptr, NULL); |
| 2351 | break; |
| 2352 | case MTNSV_I_PROD_ITEM_MAX_PROD: |
| 2353 | if (op == VF_GET) |
| 2354 | Matcen[matcen_id]->GetProdInfo(index, NULL, NULL, NULL, (int *)ptr); |
| 2355 | else if (op == VF_SET) |
| 2356 | Matcen[matcen_id]->SetProdInfo(index, NULL, NULL, NULL, (int *)ptr); |
| 2357 | break; |
| 2358 | } |
| 2359 | } |
| 2360 | |
| 2361 | void osipf_MatcenReset(int matcen_id) { |
| 2362 | if (matcen_id >= 0 && matcen_id < Num_matcens && Matcen[matcen_id]) { |
| 2363 | Matcen[matcen_id]->Reset(); |
| 2364 | } |
| 2365 | } |
| 2366 | |
| 2367 | int osipf_MatcenCreate(char *str) { |
| 2368 | bool name_changed; |
| 2369 | |
| 2370 | char name[MAX_MATCEN_NAME_LEN]; |
| 2371 | strncpy(name, str, MAX_MATCEN_NAME_LEN - 1); |
| 2372 | name[MAX_MATCEN_NAME_LEN - 1] = '\0'; |
| 2373 | |
| 2374 | return CreateMatcen(name, &name_changed); |
| 2375 | } |
| 2376 | |
| 2377 | void osipf_MatcenCopy(int md_id, int ms_id) { |
| 2378 | if (md_id >= 0 && md_id < Num_matcens && Matcen[md_id]) { |
| 2379 | if (ms_id >= 0 && ms_id < Num_matcens && Matcen[ms_id]) { |
| 2380 | char name[MAX_MATCEN_NAME_LEN]; |
| 2381 | Matcen[md_id]->GetName(name); |
| 2382 | |
| 2383 | *Matcen[md_id] = *Matcen[ms_id]; |
| 2384 | Matcen[md_id]->SetName(name); |
| 2385 | Matcen[md_id]->Reset(); |
| 2386 | } |
| 2387 | } |
| 2388 | } |
| 2389 | |
| 2390 | int osipf_MatcenFindId(char *str) { |
| 2391 | char name[MAX_MATCEN_NAME_LEN]; |
| 2392 | strncpy(name, str, MAX_MATCEN_NAME_LEN - 1); |
| 2393 | name[MAX_MATCEN_NAME_LEN - 1] = '\0'; |
| 2394 | |
| 2395 | return FindMatcenIndex(name); |
| 2396 | } |
| 2397 | |
| 2398 | int osipf_RayCast(int objhandle, vector *p0, vector *p1, int start_roomnum, float rad, int flags, ray_info *ri) { |
| 2399 | int fate; |
| 2400 | int ignore_obj_list[100]; |
| 2401 | |
| 2402 | int *ilist = hack_ilist; |
| 2403 | object *obj = ObjGet(objhandle); |
| 2404 | if (!obj && objhandle != OBJECT_HANDLE_NONE) { |
| 2405 | mprintf(0, "Invalid object passed to RayCast\n"); |
| 2406 | return 0; |
| 2407 | } |
| 2408 | |
| 2409 | fvi_info hit_info; |
| 2410 | fvi_query fq; |
| 2411 | |
| 2412 | fq.p0 = p0; |
| 2413 | fq.p1 = p1; |
| 2414 | |
| 2415 | fq.startroom = start_roomnum; |
| 2416 | |
| 2417 | fq.rad = rad; |
| 2418 | fq.flags = flags; |
| 2419 | |
| 2420 | if (obj) |
| 2421 | fq.thisobjnum = OBJNUM(obj); |
| 2422 | else |
| 2423 | fq.thisobjnum = -1; |
| 2424 | |
| 2425 | if (ilist) { |
| 2426 | int num_items = 0; |
| 2427 | int count = 0; |
| 2428 | |
| 2429 | while (ilist[count] != -1) { |
| 2430 | object *iobj = ObjGet(ilist[count]); |
| 2431 | if (iobj) { |
| 2432 | ignore_obj_list[num_items++] = OBJNUM(iobj); |
| 2433 | } |
| 2434 | |
| 2435 | count++; |
| 2436 | } |
| 2437 | |
| 2438 | ignore_obj_list[num_items] = -1; |
| 2439 | fq.ignore_obj_list = ignore_obj_list; |
| 2440 | } else { |
| 2441 | fq.ignore_obj_list = NULL; |
| 2442 | } |
| 2443 | |
| 2444 | fate = fvi_FindIntersection(&fq, &hit_info); |
| 2445 | |
| 2446 | ri->hit_point = hit_info.hit_pnt; |
| 2447 | ri->hit_room = hit_info.hit_room; |
| 2448 | ri->fate = fate; |
| 2449 | |
| 2450 | if (fate == HIT_SPHERE_2_POLY_OBJECT || fate == HIT_OBJECT) { |
| 2451 | ri->hit_object = Objects[hit_info.hit_object[0]].handle; |
| 2452 | } |
| 2453 | ri->hit_subobject = hit_info.hit_subobject[0]; |
| 2454 | |
| 2455 | ri->hit_face = hit_info.hit_face[0]; |
| 2456 | ri->hit_face_pnt = hit_info.hit_face_pnt[0]; |
| 2457 | ri->hit_face_room = hit_info.hit_face_room[0]; |
| 2458 | ri->hit_wallnorm = hit_info.hit_wallnorm[0]; |
| 2459 | |
| 2460 | return fate; |
| 2461 | } |
| 2462 | |
| 2463 | // Reads the specified number of bytes from a file into the buffer |
| 2464 | // DO NOT USE THIS TO READ STRUCTURES. This function is for byte |
| 2465 | // data, such as a string or a bitmap of 8-bit pixels. |
| 2466 | // Returns the number of bytes read. |
| 2467 | // Throws an exception of type (cfile_error *) if the OS returns an error on read |
| 2468 | int osipf_CFReadBytes(uint8_t *buffer, int count, CFILE *cfp) { return cf_ReadBytes(buffer, count, cfp); } |
| 2469 | |
| 2470 | // The following functions read numeric vales from a CFILE. All values are |
| 2471 | // stored in the file in Intel (little-endian) format. These functions |
| 2472 | // will convert to big-endian if required. |
| 2473 | // These funtions will throw an exception of if the value cannot be read, |
| 2474 | // so do not call these if you don't require the data to be present. |
| 2475 | |
| 2476 | // Read and return an integer (32 bits) |
| 2477 | // Throws an exception of type (cfile_error *) if the OS returns an error on read |
| 2478 | int osipf_CFReadInt(CFILE *cfp) { return cf_ReadInt(cfp); } |
| 2479 | |
| 2480 | // Read and return a int16_t (16 bits) |
| 2481 | // Throws an exception of type (cfile_error *) if the OS returns an error on read |
| 2482 | int16_t osipf_CFReadShort(CFILE *cfp) { return cf_ReadShort(cfp); } |
| 2483 | |
| 2484 | // Read and return a byte (8 bits) |
| 2485 | // Throws an exception of type (cfile_error *) if the OS returns an error on read |
| 2486 | int8_t osipf_CFReadByte(CFILE *cfp) { return cf_ReadByte(cfp); } |
| 2487 | |
| 2488 | // Read and return a float (32 bits) |
| 2489 | // Throws an exception of type (cfile_error *) if the OS returns an error on read |
| 2490 | float osipf_CFReadFloat(CFILE *cfp) { return cf_ReadFloat(cfp); } |
| 2491 | |
| 2492 | // Read and return a double (64 bits) |
| 2493 | // Throws an exception of type (cfile_error *) if the OS returns an error on read |
| 2494 | double osipf_CFReadDouble(CFILE *cfp) { return cf_ReadDouble(cfp); } |
| 2495 | |
| 2496 | // Reads a string from a CFILE. If the file is type binary, this |
| 2497 | // function reads until a NULL or EOF is found. If the file is text, |
| 2498 | // the function reads until a newline or EOF is found. The string is always |
| 2499 | // written to the destination buffer null-terminated, without the newline. |
| 2500 | // Parameters: buf - where the string is written |
| 2501 | // n - the maximum string length, including the terminating 0 |
| 2502 | // cfp - the CFILE pointer |
| 2503 | // Returns the number of bytes in the string, before the terminator |
| 2504 | // Does not generate an exception on EOF |
| 2505 | int osipf_CFReadString(char *buf, size_t n, CFILE *cfp) { return cf_ReadString(buf, n, cfp); } |
| 2506 | |
| 2507 | // Writes the specified number of bytes from a file into the buffer |
| 2508 | // DO NOT USE THIS TO WRITE STRUCTURES. This function is for byte |
| 2509 | // data, such as a string or a bitmap of 8-bit pixels. |
| 2510 | // Returns the number of bytes written. |
| 2511 | // Throws an exception of type (cfile_error *) if the OS returns an error on write |
| 2512 | int osipf_CFWriteBytes(const uint8_t *buf, int count, CFILE *cfp) { return cf_WriteBytes(buf, count, cfp); } |
| 2513 | |
| 2514 | // Writes a null-terminated string to a file. If the file is type binary, |
| 2515 | // the string is terminated in the file with a null. If the file is type |
| 2516 | // text, the string is terminated with a newline. |
| 2517 | // Parameters: buf - pointer to the string |
| 2518 | // cfp = the CFILE pointer |
| 2519 | // Returns the number of bytes written |
| 2520 | // Throws an exception of type (cfile_error *) if the OS returns an error on write |
| 2521 | int osipf_CFWriteString(const char *buf, CFILE *cfp) { return cf_WriteString(cfp, buf); } |
| 2522 | |
| 2523 | // The following functions write numeric vales to a CFILE. All values are |
| 2524 | // stored to the file in Intel (little-endian) format. |
| 2525 | // All these throw an exception if there's an error on write. |
| 2526 | |
| 2527 | // Write an integer (32 bits) |
| 2528 | // Throws an exception of type (cfile_error *) if the OS returns an error on write |
| 2529 | void osipf_CFWriteInt(int i, CFILE *cfp) { cf_WriteInt(cfp, i); } |
| 2530 | |
| 2531 | // Write a int16_t (16 bits) |
| 2532 | // Throws an exception of type (cfile_error *) if the OS returns an error on write |
| 2533 | void osipf_CFWriteShort(int16_t s, CFILE *cfp) { cf_WriteShort(cfp, s); } |
| 2534 | |
| 2535 | // Write a byte (8 bits). If the byte is a newline & the file is a text file, writes a CR/LF pair. |
| 2536 | // Throws an exception of type (cfile_error *) if the OS returns an error on write |
| 2537 | void osipf_CFWriteByte(int8_t b, CFILE *cfp) { cf_WriteByte(cfp, b); } |
| 2538 | |
| 2539 | // Write a float (32 bits) |
| 2540 | // Throws an exception of type (cfile_error *) if the OS returns an error on write |
| 2541 | void osipf_CFWriteFloat(float f, CFILE *cfp) { cf_WriteFloat(cfp, f); } |
| 2542 | |
| 2543 | // Write a double (64 bits) |
| 2544 | // Throws an exception of type (cfile_error *) if the OS returns an error on write |
| 2545 | void osipf_CFWriteDouble(double d, CFILE *cfp) { cf_WriteDouble(cfp, d); } |
| 2546 | |
| 2547 | // CONTROLLER predefs |
| 2548 | |
| 2549 | // enables or disables controls specified. |
| 2550 | void osipf_SetAllControls(bool enabled) { |
| 2551 | int i; |
| 2552 | |
| 2553 | for (i = 0; i < NUM_CONTROLLER_FUNCTIONS; i++) { |
| 2554 | Controller->enable_function(i, enabled); |
| 2555 | } |
| 2556 | } |
| 2557 | |
| 2558 | // enable or disable specified function |
| 2559 | void osipf_SetControls(int fn, bool enabled) { |
| 2560 | if (Controller) { |
| 2561 | Controller->enable_function(fn, enabled); |
| 2562 | } |
| 2563 | } |
| 2564 | |
| 2565 | // display messages using a primative dialog |
| 2566 | void osipf_OpenMessageWindow(const char *title, ...) { |
| 2567 | Int3(); // ummm, this is a blank function, should we ever be calling it? |
| 2568 | } |
| 2569 | |
| 2570 | int osipf_ObjCreate(uint8_t type, uint16_t id, int roomnum, vector *pos, const matrix *orient, int parent_handle, |
| 2571 | vector *initial_velocity) { |
| 2572 | object *obj; |
| 2573 | int objnum; |
| 2574 | |
| 2575 | if (id == 65535) // since it is a uint16_t, this is == -1 |
| 2576 | return OBJECT_HANDLE_NONE; |
| 2577 | |
| 2578 | if (((roomnum >= 0) && (roomnum <= Highest_room_index) && (Rooms[roomnum].used)) || (ROOMNUM_OUTSIDE(roomnum))) { |
| 2579 | if (IS_GENERIC(type)) { |
| 2580 | // Make sure the scripts aren't creating objects that have lightmaps! |
| 2581 | ASSERT(Object_info[id].lighting_info.lighting_render_type != LRT_LIGHTMAPS); |
| 2582 | } |
| 2583 | |
| 2584 | objnum = ObjCreate(type, id, roomnum, pos, orient, parent_handle); |
| 2585 | |
| 2586 | if (objnum == -1) { |
| 2587 | return OBJECT_HANDLE_NONE; |
| 2588 | } |
| 2589 | |
| 2590 | obj = &Objects[objnum]; |
| 2591 | |
| 2592 | // if there was an initial velocity, set it |
| 2593 | if (initial_velocity) { |
| 2594 | ASSERT(obj->movement_type == MT_PHYSICS); |
| 2595 | obj->mtype.phys_info.velocity = *initial_velocity; |
| 2596 | } |
| 2597 | |
| 2598 | if (Game_mode & GM_MULTI) { |
| 2599 | // ASSERT (Netgame.local_role==LR_SERVER); |
| 2600 | if (Netgame.local_role == LR_SERVER) { |
| 2601 | MultiSendObject(obj, 0); |
| 2602 | } |
| 2603 | } |
| 2604 | |
| 2605 | InitObjectScripts(obj); |
| 2606 | |
| 2607 | if (IS_GENERIC(obj->type)) { |
| 2608 | int ambient_sound = Object_info[obj->id].sounds[GSI_AMBIENT]; |
| 2609 | if (ambient_sound != SOUND_NONE_INDEX) { |
| 2610 | Sound_system.Play3dSound(ambient_sound, SND_PRIORITY_LOWEST, obj); |
| 2611 | if (Game_mode & GM_MULTI) |
| 2612 | MultiPlay3dSound(ambient_sound, objnum, SND_PRIORITY_LOW); |
| 2613 | if (Demo_flags == DF_RECORDING) |
| 2614 | DemoWrite3DSound(ambient_sound, objnum, SND_PRIORITY_LOW); |
| 2615 | } |
| 2616 | } |
| 2617 | } else { |
| 2618 | return OBJECT_HANDLE_NONE; |
| 2619 | } |
| 2620 | |
| 2621 | return obj->handle; |
| 2622 | } |
| 2623 | |
| 2624 | // OBJECT Properties. |
| 2625 | bool osipf_IsObjectVisible(object *obj) { |
| 2626 | if (obj->renderframe != ((FrameCount - 1) % 65536)) { |
| 2627 | return false; |
| 2628 | } |
| 2629 | |
| 2630 | return true; |
| 2631 | } |
| 2632 | |
| 2633 | float osipf_GameTime(void) { return Gametime; } |
| 2634 | |
| 2635 | float osipf_FrameTime(void) { return Frametime; } |
| 2636 | |
| 2637 | void osipf_ObjWBValue(int obj_handle, char wb_index, char op, char vtype, void *ptr, char g_index) { |
| 2638 | object *objp = ObjGet(obj_handle); |
| 2639 | |
| 2640 | if (!objp) { |
| 2641 | mprintf(0, "Obj_WBValue: Illegal Object Passed\n"); |
| 2642 | return; |
| 2643 | } |
| 2644 | |
| 2645 | if (objp->control_type != CT_AI && objp->type != OBJ_PLAYER && objp->type != OBJ_OBSERVER) { |
| 2646 | mprintf(0, "Obj_WBValue: Illegal Object CT Passed\n"); |
| 2647 | return; |
| 2648 | } |
| 2649 | |
| 2650 | dynamic_wb_info *p_dwb = &objp->dynamic_wb[wb_index]; |
| 2651 | otype_wb_info *static_wb; |
| 2652 | poly_model *pm = &Poly_models[objp->rtype.pobj_info.model_num]; |
| 2653 | |
| 2654 | if (objp->type == OBJ_PLAYER || objp->type == OBJ_OBSERVER) { |
| 2655 | ship *ship = &Ships[Players[objp->id].ship_index]; |
| 2656 | static_wb = &ship->static_wb[wb_index]; |
| 2657 | } else { |
| 2658 | object_info *obj_info = &Object_info[objp->id]; |
| 2659 | static_wb = &obj_info->static_wb[wb_index]; |
| 2660 | } |
| 2661 | |
| 2662 | if (objp->type == OBJ_BUILDING && (wb_index < 0 || wb_index > pm->num_wbs)) { |
| 2663 | return; |
| 2664 | } |
| 2665 | |
| 2666 | switch (vtype) { |
| 2667 | case WBV_C_NUM_WBS: { |
| 2668 | if (op == VF_GET) { |
| 2669 | *(char *)ptr = pm->num_wbs; |
| 2670 | } |
| 2671 | } break; |
| 2672 | case WBV_F_ANIM_FRAME: |
| 2673 | if (op == VF_GET) { |
| 2674 | int anim_type = static_wb->flags & WBF_ANIM_MASKS; |
| 2675 | |
| 2676 | if (anim_type == WBF_ANIM_LOCAL) { |
| 2677 | *((float *)ptr) = p_dwb->wb_anim_frame; |
| 2678 | } else { |
| 2679 | *((float *)ptr) = objp->rtype.pobj_info.anim_frame; |
| 2680 | } |
| 2681 | } |
| 2682 | break; |
| 2683 | |
| 2684 | case WBV_F_LAST_FIRE_TIME: |
| 2685 | if (op == VF_SET) { |
| 2686 | p_dwb->last_fire_time = *((float *)ptr); |
| 2687 | } else if (op == VF_GET) { |
| 2688 | *((float *)ptr) = p_dwb->last_fire_time; |
| 2689 | } |
| 2690 | break; |
| 2691 | |
| 2692 | case WBV_I_DYNAMIC_FLAGS: |
| 2693 | if (op == VF_SET) { |
| 2694 | p_dwb->flags = *((int *)ptr); |
| 2695 | } else if (op == VF_GET) { |
| 2696 | *((int *)ptr) = p_dwb->flags; |
| 2697 | } else if (op == VF_SET_FLAGS) { |
| 2698 | p_dwb->flags |= *((int *)ptr); |
| 2699 | } else if (op == VF_CLEAR_FLAGS) { |
| 2700 | p_dwb->flags &= ~(*((int *)ptr)); |
| 2701 | } |
| 2702 | break; |
| 2703 | |
| 2704 | case WBV_C_NUM_GUNPTS: |
| 2705 | if (op == VF_GET) { |
| 2706 | if (objp->type == OBJ_PLAYER || objp->type == OBJ_OBSERVER) { |
| 2707 | *((char *)ptr) = 8; |
| 2708 | } else { |
| 2709 | *((char *)ptr) = pm->poly_wb[wb_index].num_gps; |
| 2710 | } |
| 2711 | } |
| 2712 | break; |
| 2713 | case WBSV_US_GUNPT_WEAPON_ID: |
| 2714 | if (op == VF_SET) { |
| 2715 | static_wb->gp_weapon_index[g_index] = *((uint16_t *)ptr); |
| 2716 | } else if (op == VF_GET) { |
| 2717 | *((uint16_t *)ptr) = static_wb->gp_weapon_index[g_index]; |
| 2718 | } |
| 2719 | break; |
| 2720 | case WBSV_V_GUNPT_POS: |
| 2721 | if (op == VF_GET) { |
| 2722 | if (objp->type == OBJ_PLAYER || objp->type == OBJ_OBSERVER) |
| 2723 | WeaponCalcGun(((vector *)ptr), NULL, objp, pm->poly_wb[0].gp_index[g_index]); |
| 2724 | else |
| 2725 | WeaponCalcGun(((vector *)ptr), NULL, objp, pm->poly_wb[wb_index].gp_index[g_index]); |
| 2726 | } |
| 2727 | break; |
| 2728 | |
| 2729 | case WBV_C_NUM_MASKS: |
| 2730 | if (op == VF_SET) { |
| 2731 | static_wb->num_masks = *((char *)ptr); |
| 2732 | } else if (op == VF_GET) { |
| 2733 | *((char *)ptr) = static_wb->num_masks; |
| 2734 | } |
| 2735 | break; |
| 2736 | case WBSV_C_MASK: |
| 2737 | if (op == VF_SET) { |
| 2738 | static_wb->gp_fire_masks[g_index] = *((char *)ptr); |
| 2739 | } else if (op == VF_GET) { |
| 2740 | *((char *)ptr) = static_wb->gp_fire_masks[g_index]; |
| 2741 | } else if (op == VF_SET_FLAGS) { |
| 2742 | static_wb->gp_fire_masks[g_index] |= *((char *)ptr); |
| 2743 | } else if (op == VF_CLEAR_FLAGS) { |
| 2744 | static_wb->gp_fire_masks[g_index] &= ~(*((char *)ptr)); |
| 2745 | } |
| 2746 | break; |
| 2747 | case WBSV_I_FIRE_SOUND: |
| 2748 | if (op == VF_SET) { |
| 2749 | static_wb->fm_fire_sound_index[g_index] = (*((int *)ptr)); |
| 2750 | } else if (op == VF_GET) { |
| 2751 | (*((int *)ptr)) = static_wb->fm_fire_sound_index[g_index]; |
| 2752 | } |
| 2753 | break; |
| 2754 | case WBSV_F_LATENCY: |
| 2755 | if (op == VF_SET) { |
| 2756 | static_wb->gp_fire_wait[g_index] = (*((float *)ptr)); |
| 2757 | } else if (op == VF_GET) { |
| 2758 | (*((float *)ptr)) = static_wb->gp_fire_wait[g_index]; |
| 2759 | } |
| 2760 | break; |
| 2761 | case WBSV_F_ANIM_TIME: |
| 2762 | if (op == VF_SET) { |
| 2763 | static_wb->anim_time[g_index] = (*((float *)ptr)); |
| 2764 | } else if (op == VF_GET) { |
| 2765 | (*((float *)ptr)) = static_wb->anim_time[g_index]; |
| 2766 | } |
| 2767 | break; |
| 2768 | case WBSV_F_ANIM_START: |
| 2769 | if (op == VF_SET) { |
| 2770 | static_wb->anim_start_frame[g_index] = (*((float *)ptr)); |
| 2771 | } else if (op == VF_GET) { |
| 2772 | (*((float *)ptr)) = static_wb->anim_start_frame[g_index]; |
| 2773 | } |
| 2774 | break; |
| 2775 | case WBSV_F_ANIM_FIRE: |
| 2776 | if (op == VF_SET) { |
| 2777 | static_wb->anim_fire_frame[g_index] = (*((float *)ptr)); |
| 2778 | } else if (op == VF_GET) { |
| 2779 | (*((float *)ptr)) = static_wb->anim_fire_frame[g_index]; |
| 2780 | } |
| 2781 | break; |
| 2782 | case WBSV_F_ANIM_END: |
| 2783 | if (op == VF_SET) { |
| 2784 | static_wb->anim_end_frame[g_index] = (*((float *)ptr)); |
| 2785 | } else if (op == VF_GET) { |
| 2786 | (*((float *)ptr)) = static_wb->anim_end_frame[g_index]; |
| 2787 | } |
| 2788 | break; |
| 2789 | } |
| 2790 | } |
| 2791 | |
| 2792 | // Sets/Clears mission flags |
| 2793 | // flag is which mission flag to set/clear (1-32) |
| 2794 | // value is 0 to clear, or 1 to set |
| 2795 | void osipf_MissionFlagSet(int flag, uint8_t value) { |
| 2796 | if (flag < 1 && flag > 32) { |
| 2797 | mprintf(0, "Invalid flag passed to osipf_MissionFlagSet(%d)\n", flag); |
| 2798 | return; |
| 2799 | } |
| 2800 | |
| 2801 | flag--; |
| 2802 | uint32_t bit = 0x01; |
| 2803 | bit = bit << flag; |
| 2804 | |
| 2805 | if (!value) { |
| 2806 | Current_mission.game_state_flags &= ~bit; |
| 2807 | } else { |
| 2808 | Current_mission.game_state_flags |= bit; |
| 2809 | } |
| 2810 | } |
| 2811 | |
| 2812 | // Gets a mission flag |
| 2813 | // flag is what mission flag to get. Returns 1 if set, 0 if not. |
| 2814 | int osipf_MissionFlagGet(int flag) { |
| 2815 | if (flag < 1 && flag > 32) { |
| 2816 | mprintf(0, "Invalid flag passed to osipf_MissionFlagGet(%d)\n", flag); |
| 2817 | return 0; |
| 2818 | } |
| 2819 | |
| 2820 | flag--; |
| 2821 | uint32_t bit = 0x01; |
| 2822 | bit = bit << flag; |
| 2823 | |
| 2824 | if (Current_mission.game_state_flags & bit) |
| 2825 | return 1; |
| 2826 | |
| 2827 | return 0; |
| 2828 | } |
| 2829 | |
| 2830 | void osipf_PlayerAddHudMessage(int handle, const char *str) { |
| 2831 | msafe_struct mo; |
| 2832 | |
| 2833 | mo.objhandle = mo.id = handle; |
| 2834 | mo.color = GR_RGB(0, 255, 0); |
| 2835 | strncpy(mo.message, str, MSAFE_MESSAGE_LENGTH - 1); |
| 2836 | mo.message[MSAFE_MESSAGE_LENGTH - 1] = '\0'; |
| 2837 | |
| 2838 | msafe_CallFunction(MSAFE_MISC_HUD_MESSAGE, &mo); |
| 2839 | } |
| 2840 | |
| 2841 | void osipf_ObjGhost(int handle, bool f_ghost) { |
| 2842 | object *obj = ObjGet(handle); |
| 2843 | if (obj) { |
| 2844 | // BLACKPYROHACK - Chrishack for Mercenary |
| 2845 | if (!(Game_mode & GM_MULTI)) { |
| 2846 | if (obj->handle == Buddy_handle[0]) { |
| 2847 | if (stricmp(Ships[Players[Player_object->id].ship_index].name, "Black Pyro") == 0) { |
| 2848 | obj->id = ROBOT_GUIDEBOTRED; |
| 2849 | PageInPolymodel(Object_info[ROBOT_GUIDEBOTRED].render_handle, Object_info[ROBOT_GUIDEBOTRED].type, |
| 2850 | &Object_info[ROBOT_GUIDEBOTRED].size); |
| 2851 | obj->rtype.pobj_info.model_num = Object_info[ROBOT_GUIDEBOTRED].render_handle; |
| 2852 | } else { |
| 2853 | obj->id = ROBOT_GUIDEBOT; |
| 2854 | obj->rtype.pobj_info.model_num = Object_info[ROBOT_GUIDEBOT].render_handle; |
| 2855 | } |
| 2856 | } |
| 2857 | } |
| 2858 | |
| 2859 | msafe_struct mo; |
| 2860 | mo.objhandle = obj->handle; |
| 2861 | |
| 2862 | if (f_ghost) |
| 2863 | msafe_CallFunction(MSAFE_OBJECT_GHOST, &mo); |
| 2864 | else |
| 2865 | msafe_CallFunction(MSAFE_OBJECT_UNGHOST, &mo); |
| 2866 | } |
| 2867 | } |
| 2868 | |
| 2869 | void osipf_ObjBurning(int handle, float time, float damage_per_second) { |
| 2870 | object *obj = ObjGet(handle); |
| 2871 | if (obj && obj->effect_info) { |
| 2872 | if (time > 0.0) { |
| 2873 | obj->effect_info->type_flags |= EF_NAPALMED; |
| 2874 | |
| 2875 | obj->effect_info->damage_time = time; |
| 2876 | obj->effect_info->damage_per_second = damage_per_second; |
| 2877 | |
| 2878 | obj->effect_info->last_damage_time = 0; |
| 2879 | |
| 2880 | obj->effect_info->damage_handle = obj->handle; |
| 2881 | |
| 2882 | if (obj->effect_info->sound_handle == SOUND_NONE_INDEX) |
| 2883 | obj->effect_info->sound_handle = Sound_system.Play3dSound(SOUND_PLAYER_BURNING, SND_PRIORITY_HIGHEST, obj); |
| 2884 | } else { |
| 2885 | obj->effect_info->type_flags &= (~EF_NAPALMED); |
| 2886 | obj->effect_info->last_damage_time = 0; |
| 2887 | Sound_system.StopSoundLooping(obj->effect_info->sound_handle); |
| 2888 | obj->effect_info->sound_handle = SOUND_NONE_INDEX; |
| 2889 | } |
| 2890 | } |
| 2891 | } |
| 2892 | |
| 2893 | bool osipf_ObjIsEffect(int handle, int type_flag) { |
| 2894 | object *obj = ObjGet(handle); |
| 2895 | return (obj && obj->effect_info && (obj->effect_info->type_flags & type_flag)); |
| 2896 | } |
| 2897 | |
| 2898 | void *osipf_CFopen(const char *filename, const char *mode) { return cfopen(filename, mode); } |
| 2899 | |
| 2900 | void osipf_CFclose(CFILE *file) { cfclose(file); } |
| 2901 | |
| 2902 | int osipf_CFtell(CFILE *file) { return cftell(file); } |
| 2903 | |
| 2904 | uint8_t osipf_CFeof(CFILE *file) { return (cfeof(file) != 0) ? 1 : 0; } |
| 2905 | |
| 2906 | void osipf_SoundStop(int s_handle, bool f_immediately) { |
| 2907 | // JEFF - sorry, this can't be made multiplayer friendly |
| 2908 | /* |
| 2909 | if(f_immediately) |
| 2910 | Sound_system.StopSoundImmediate(s_handle); |
| 2911 | else |
| 2912 | Sound_system.StopSoundLooping(s_handle); |
| 2913 | */ |
| 2914 | } |
| 2915 | |
| 2916 | int osipf_SoundPlay2d(int obj_handle, int s_id, float volume) { |
| 2917 | msafe_struct mstruct; |
| 2918 | mstruct.index = s_id; |
| 2919 | |
| 2920 | if (obj_handle != OBJECT_HANDLE_NONE) { |
| 2921 | mstruct.state = 1; |
| 2922 | mstruct.objhandle = obj_handle; |
| 2923 | } else { |
| 2924 | mstruct.state = 0; |
| 2925 | } |
| 2926 | |
| 2927 | mstruct.volume = volume; |
| 2928 | |
| 2929 | msafe_CallFunction(MSAFE_SOUND_2D, &mstruct); |
| 2930 | return mstruct.sound_handle; |
| 2931 | /* |
| 2932 | //chrishack -- use handle for who hears the sound |
| 2933 | return Sound_system.Play2dSound(s_id, SND_PRIORITY_HIGHEST, volume); |
| 2934 | */ |
| 2935 | } |
| 2936 | |
| 2937 | int osipf_SoundPlay3d(int obj_handle, int s_id, float volume) { |
| 2938 | msafe_struct mstruct; |
| 2939 | mstruct.objhandle = obj_handle; |
| 2940 | mstruct.index = s_id; |
| 2941 | |
| 2942 | msafe_CallFunction(MSAFE_SOUND_OBJECT, &mstruct); |
| 2943 | return mstruct.sound_handle; |
| 2944 | /* |
| 2945 | object *obj = ObjGet(obj_handle); |
| 2946 | |
| 2947 | if(obj) |
| 2948 | { |
| 2949 | return Sound_system.Play3dSound(s_id, SND_PRIORITY_HIGHEST,obj, volume); |
| 2950 | } |
| 2951 | |
| 2952 | return -1; |
| 2953 | */ |
| 2954 | } |
| 2955 | |
| 2956 | int osipf_SoundFindId(const char *s_name) { return FindSoundName(IGNORE_TABLE(s_name)); } |
| 2957 | |
| 2958 | bool osipf_AIIsObjFriend(int obj_handle, int it_handle) { |
| 2959 | object *me = ObjGet(obj_handle); |
| 2960 | object *it = ObjGet(it_handle); |
| 2961 | |
| 2962 | if (me && it) |
| 2963 | return AIObjFriend(me, it); |
| 2964 | |
| 2965 | return false; |
| 2966 | } |
| 2967 | |
| 2968 | bool osipf_AIIsObjEnemy(int obj_handle, int it_handle) { |
| 2969 | object *me = ObjGet(obj_handle); |
| 2970 | object *it = ObjGet(it_handle); |
| 2971 | |
| 2972 | if (me && it) |
| 2973 | return AIObjEnemy(me, it); |
| 2974 | |
| 2975 | return false; |
| 2976 | } |
| 2977 | |
| 2978 | void osipf_AIGoalValue(int obj_handle, char g_index, char op, char vtype, void *ptr, char index) { |
| 2979 | object *obj = ObjGet(obj_handle); |
| 2980 | if (!obj) |
| 2981 | return; |
| 2982 | |
| 2983 | ai_frame *ai_info = obj->ai_info; |
| 2984 | if (!ai_info) |
| 2985 | return; |
| 2986 | |
| 2987 | if (g_index < 0 || g_index >= MAX_GOALS) |
| 2988 | return; |
| 2989 | |
| 2990 | goal *g_ptr = &ai_info->goals[g_index]; |
| 2991 | |
| 2992 | if (!g_ptr->used || vtype == AIGV_B_USED) { |
| 2993 | if (vtype == AIGV_B_USED && op == VF_GET) |
| 2994 | *(bool *)ptr = g_ptr->used; |
| 2995 | |
| 2996 | return; |
| 2997 | } |
| 2998 | |
| 2999 | switch (vtype) { |
| 3000 | case AIGV_I_TYPE: { |
| 3001 | if (op == VF_GET) |
| 3002 | *(int *)ptr = g_ptr->type; |
| 3003 | else if (op == VF_SET) |
| 3004 | g_ptr->type = *(int *)ptr; |
| 3005 | } break; |
| 3006 | case AIGV_C_ACTIVATION_LEVEL: { |
| 3007 | if (op == VF_GET) |
| 3008 | *(char *)ptr = g_ptr->activation_level; |
| 3009 | else if (op == VF_SET) |
| 3010 | g_ptr->activation_level = *(char *)ptr; |
| 3011 | } break; |
| 3012 | case AIGV_F_MIN_INFLUENCE: { |
| 3013 | if (op == VF_GET) |
| 3014 | *(float *)ptr = g_ptr->min_influence; |
| 3015 | else if (op == VF_SET) |
| 3016 | g_ptr->min_influence = *(float *)ptr; |
| 3017 | } break; |
| 3018 | case AIGV_F_MAX_INFLUENCE: { |
| 3019 | if (op == VF_GET) |
| 3020 | *(float *)ptr = g_ptr->max_influence; |
| 3021 | else if (op == VF_SET) |
| 3022 | g_ptr->max_influence = *(float *)ptr; |
| 3023 | } break; |
| 3024 | |
| 3025 | case AIGSV_F_INFLUENCE_DIST: // 0 - 3 |
| 3026 | { |
| 3027 | if (op == VF_GET) |
| 3028 | *(float *)ptr = g_ptr->ramp_influence_dists[index]; |
| 3029 | else if (op == VF_SET) |
| 3030 | g_ptr->ramp_influence_dists[index] = *(float *)ptr; |
| 3031 | } break; |
| 3032 | |
| 3033 | case AIGV_I_HANDLE: { |
| 3034 | if (op == VF_GET) |
| 3035 | *(int *)ptr = g_ptr->g_info.handle; |
| 3036 | else if (op == VF_SET) |
| 3037 | g_ptr->g_info.handle = *(int *)ptr; |
| 3038 | } break; |
| 3039 | case AIGV_I_ROOMNUM: { |
| 3040 | if (op == VF_GET) |
| 3041 | *(int *)ptr = g_ptr->g_info.roomnum; |
| 3042 | else if (op == VF_SET) |
| 3043 | g_ptr->g_info.roomnum = *(int *)ptr; |
| 3044 | } break; |
| 3045 | case AIGV_I_F_ACTIONS: { |
| 3046 | if (op == VF_GET) |
| 3047 | *(int *)ptr = g_ptr->g_info.f_actions; |
| 3048 | else if (op == VF_SET) |
| 3049 | g_ptr->g_info.f_actions = *(int *)ptr; |
| 3050 | } break; |
| 3051 | case AIGV_I_ID: { |
| 3052 | if (op == VF_GET) |
| 3053 | *(int *)ptr = g_ptr->g_info.id; |
| 3054 | else if (op == VF_SET) |
| 3055 | g_ptr->g_info.id = *(int *)ptr; |
| 3056 | } break; |
| 3057 | case AIGV_C_SUBTYPE: { |
| 3058 | if (op == VF_GET) |
| 3059 | *(char *)ptr = g_ptr->subtype; |
| 3060 | else if (op == VF_SET) |
| 3061 | g_ptr->subtype = *(char *)ptr; |
| 3062 | } break; |
| 3063 | case AIGV_F_TIME: { |
| 3064 | if (op == VF_GET) |
| 3065 | *(float *)ptr = g_ptr->g_info.time; |
| 3066 | else if (op == VF_SET) |
| 3067 | g_ptr->g_info.time = *(float *)ptr; |
| 3068 | } break; |
| 3069 | case AIGV_V_VEC: { |
| 3070 | if (op == VF_GET) |
| 3071 | *(vector *)ptr = g_ptr->g_info.vec; |
| 3072 | else if (op == VF_SET) |
| 3073 | g_ptr->g_info.vec = *(vector *)ptr; |
| 3074 | } break; |
| 3075 | case AIGV_V_POS: { |
| 3076 | if (op == VF_GET) |
| 3077 | *(vector *)ptr = g_ptr->g_info.pos; |
| 3078 | else if (op == VF_SET) |
| 3079 | g_ptr->g_info.pos = *(vector *)ptr; |
| 3080 | } break; |
| 3081 | case AIGV_F_STEER_MIN_DIST: { |
| 3082 | if (op == VF_GET) |
| 3083 | *(float *)ptr = g_ptr->g_info.dist_info.min_dist; |
| 3084 | else if (op == VF_SET) |
| 3085 | g_ptr->g_info.dist_info.min_dist = *(float *)ptr; |
| 3086 | } break; |
| 3087 | case AIGV_F_STEER_MAX_DIST: { |
| 3088 | if (op == VF_GET) |
| 3089 | *(float *)ptr = g_ptr->g_info.dist_info.max_dist; |
| 3090 | else if (op == VF_SET) |
| 3091 | g_ptr->g_info.dist_info.max_dist = *(float *)ptr; |
| 3092 | } break; |
| 3093 | case AIGV_F_STEER_MAX_STRENGTH: { |
| 3094 | if (op == VF_GET) |
| 3095 | *(float *)ptr = g_ptr->g_info.dist_info.max_strength; |
| 3096 | else if (op == VF_SET) |
| 3097 | g_ptr->g_info.dist_info.max_strength = *(float *)ptr; |
| 3098 | } break; |
| 3099 | case AIGV_B_ATTACH_F_ALIGNED: { |
| 3100 | if (op == VF_GET) |
| 3101 | *(bool *)ptr = (g_ptr->g_info.attach_info.flags & GAF_ALIGNED) != 0; |
| 3102 | } break; |
| 3103 | case AIGV_B_ATTACH_F_SPHERE: { |
| 3104 | if (op == VF_GET) |
| 3105 | *(bool *)ptr = (g_ptr->g_info.attach_info.flags & GAF_SPHERE) != 0; |
| 3106 | } break; |
| 3107 | case AIGV_F_ATTACH_RAD: { |
| 3108 | if (op == VF_GET) |
| 3109 | *(float *)ptr = g_ptr->g_info.attach_info.rad; |
| 3110 | } break; |
| 3111 | case AIGV_C_ATTACH_CHILD_AP: { |
| 3112 | if (op == VF_GET) |
| 3113 | *(char *)ptr = g_ptr->g_info.attach_info.child_ap; |
| 3114 | } break; |
| 3115 | case AIGV_C_ATTACH_PARENT_AP: { |
| 3116 | if (op == VF_GET) |
| 3117 | *(char *)ptr = g_ptr->g_info.attach_info.parent_ap; |
| 3118 | } break; |
| 3119 | case AIGV_I_WANDER_AVOID_HANDLE: { |
| 3120 | if (op == VF_GET) |
| 3121 | *(int *)ptr = g_ptr->g_info.wander_extra_info.avoid_handle; |
| 3122 | else if (op == VF_SET) |
| 3123 | g_ptr->g_info.wander_extra_info.avoid_handle = *(int *)ptr; |
| 3124 | } break; |
| 3125 | case AIGV_C_WANDER_MIN_ROOMS: { |
| 3126 | if (op == VF_GET) |
| 3127 | *(char *)ptr = g_ptr->g_info.wander_extra_info.min_rooms; |
| 3128 | else if (op == VF_SET) |
| 3129 | g_ptr->g_info.wander_extra_info.min_rooms = *(char *)ptr; |
| 3130 | } break; |
| 3131 | case AIGV_C_WANDER_MAX_ROOMS: { |
| 3132 | if (op == VF_GET) |
| 3133 | *(char *)ptr = g_ptr->g_info.wander_extra_info.max_rooms; |
| 3134 | else if (op == VF_SET) |
| 3135 | g_ptr->g_info.wander_extra_info.max_rooms = *(char *)ptr; |
| 3136 | } break; |
| 3137 | case AIGV_C_WANDER_FLAGS: { |
| 3138 | if (op == VF_GET) |
| 3139 | *(char *)ptr = g_ptr->g_info.wander_extra_info.flags; |
| 3140 | else if (op == VF_SET) |
| 3141 | g_ptr->g_info.wander_extra_info.flags = *(char *)ptr; |
| 3142 | else if (op == VF_SET_FLAGS) |
| 3143 | g_ptr->g_info.wander_extra_info.flags |= *(char *)ptr; |
| 3144 | else if (op == VF_CLEAR_FLAGS) |
| 3145 | g_ptr->g_info.wander_extra_info.flags &= ~(*(char *)ptr); |
| 3146 | } break; |
| 3147 | case AIGV_C_WANDER_MINE_INDEX: { |
| 3148 | if (op == VF_GET) |
| 3149 | *(char *)ptr = g_ptr->g_info.wander_extra_info.mine_index; |
| 3150 | else if (op == VF_SET) |
| 3151 | g_ptr->g_info.wander_extra_info.mine_index = *(char *)ptr; |
| 3152 | } break; |
| 3153 | case AIGV_F_CIRCLE_DIST: { |
| 3154 | if (op == VF_GET) |
| 3155 | *(float *)ptr = g_ptr->circle_distance; |
| 3156 | else if (op == VF_SET) |
| 3157 | g_ptr->circle_distance = *(float *)ptr; |
| 3158 | } break; |
| 3159 | case AIGV_I_STATUS_REG: { |
| 3160 | if (op == VF_GET) |
| 3161 | *(int *)ptr = g_ptr->status_reg; |
| 3162 | else if (op == VF_SET) |
| 3163 | g_ptr->status_reg = *(int *)ptr; |
| 3164 | else if (op == VF_SET_FLAGS) |
| 3165 | g_ptr->status_reg |= *(int *)ptr; |
| 3166 | else if (op == VF_CLEAR_FLAGS) |
| 3167 | g_ptr->status_reg &= ~(*(int *)ptr); |
| 3168 | } break; |
| 3169 | case AIGV_F_START_TIME: { |
| 3170 | if (op == VF_GET) |
| 3171 | *(float *)ptr = g_ptr->start_time; |
| 3172 | else if (op == VF_SET) |
| 3173 | g_ptr->start_time = *(float *)ptr; |
| 3174 | } break; |
| 3175 | case AIGV_F_NEXT_PATH_TIME: { |
| 3176 | if (op == VF_GET) |
| 3177 | *(float *)ptr = g_ptr->next_path_time; |
| 3178 | else if (op == VF_SET) |
| 3179 | g_ptr->next_path_time = *(float *)ptr; |
| 3180 | } break; |
| 3181 | case AIGV_F_DIST_TO_GOAL: { |
| 3182 | if (op == VF_GET) |
| 3183 | *(float *)ptr = g_ptr->dist_to_goal; |
| 3184 | else if (op == VF_SET) |
| 3185 | g_ptr->dist_to_goal = *(float *)ptr; |
| 3186 | } break; |
| 3187 | case AIGV_I_SCRIPTED_DATA_PTR: { |
| 3188 | if(op == VF_GET) |
| 3189 | *(void **)ptr = g_ptr->g_info.scripted_data_ptr; |
| 3190 | else if(op == VF_SET) |
| 3191 | g_ptr->g_info.scripted_data_ptr = *((void **)ptr); |
| 3192 | } break; |
| 3193 | case AIGV_V_VEC_TO_TARGET: { |
| 3194 | if (op == VF_GET) |
| 3195 | *(vector *)ptr = g_ptr->vec_to_target; |
| 3196 | else if (op == VF_SET) |
| 3197 | g_ptr->vec_to_target = *(vector *)ptr; |
| 3198 | } break; |
| 3199 | case AIGV_F_NEXT_CHECK_SEE_TARGET_TIME: { |
| 3200 | if (op == VF_GET) |
| 3201 | *(float *)ptr = g_ptr->next_check_see_target_time; |
| 3202 | else if (op == VF_SET) |
| 3203 | g_ptr->next_check_see_target_time = *(float *)ptr; |
| 3204 | } break; |
| 3205 | case AIGV_V_LAST_SEE_TARGET_POS: { |
| 3206 | if (op == VF_GET) |
| 3207 | *(vector *)ptr = g_ptr->last_see_target_pos; |
| 3208 | else if (op == VF_SET) |
| 3209 | g_ptr->last_see_target_pos = *(vector *)ptr; |
| 3210 | } break; |
| 3211 | case AIGV_F_LAST_SEE_TARGET_TIME: { |
| 3212 | if (op == VF_GET) |
| 3213 | *(float *)ptr = g_ptr->last_see_target_time; |
| 3214 | else if (op == VF_SET) |
| 3215 | g_ptr->last_see_target_time = *(float *)ptr; |
| 3216 | } break; |
| 3217 | case AIGV_F_NEXT_TARGET_UPDATE_TIME: { |
| 3218 | if (op == VF_GET) |
| 3219 | *(float *)ptr = g_ptr->next_target_update_time; |
| 3220 | else if (op == VF_SET) |
| 3221 | g_ptr->next_target_update_time = *(float *)ptr; |
| 3222 | } break; |
| 3223 | case AIGV_I_FLAGS: { |
| 3224 | if (op == VF_GET) |
| 3225 | *(int *)ptr = g_ptr->flags; |
| 3226 | else if (op == VF_SET) |
| 3227 | g_ptr->flags = *(int *)ptr; |
| 3228 | else if (op == VF_SET_FLAGS) |
| 3229 | g_ptr->flags |= *(int *)ptr; |
| 3230 | else if (op == VF_CLEAR_FLAGS) |
| 3231 | g_ptr->flags &= ~(*(int *)ptr); |
| 3232 | } break; |
| 3233 | |
| 3234 | case AIGV_C_NUM_ENABLERS: { |
| 3235 | if (op == VF_GET) |
| 3236 | *(char *)ptr = g_ptr->num_enablers; |
| 3237 | else if (op == VF_SET) |
| 3238 | g_ptr->num_enablers = *(char *)ptr; |
| 3239 | } break; |
| 3240 | case AIGV_V_ORIENT_FVEC: { |
| 3241 | if (op == VF_GET) |
| 3242 | *(vector *)ptr = g_ptr->set_fvec; |
| 3243 | else if (op == VF_SET) |
| 3244 | g_ptr->set_fvec = *(vector *)ptr; |
| 3245 | } break; |
| 3246 | case AIGV_V_ORIENT_UVEC: { |
| 3247 | if (op == VF_GET) |
| 3248 | *(vector *)ptr = g_ptr->set_uvec; |
| 3249 | else if (op == VF_SET) |
| 3250 | g_ptr->set_uvec = *(vector *)ptr; |
| 3251 | } break; |
| 3252 | case AIGSV_C_ENABLER_TYPE: { |
| 3253 | if (op == VF_GET) |
| 3254 | *(char *)ptr = g_ptr->enabler[index].enabler_type; |
| 3255 | else if (op == VF_SET) |
| 3256 | g_ptr->enabler[index].enabler_type = *(char *)ptr; |
| 3257 | } break; |
| 3258 | case AIGSV_F_ENABLER_TIME: { |
| 3259 | if (op == VF_GET) |
| 3260 | *(float *)ptr = g_ptr->enabler[index].time; |
| 3261 | else if (op == VF_SET) |
| 3262 | g_ptr->enabler[index].time = *(float *)ptr; |
| 3263 | } break; |
| 3264 | case AIGSV_C_ENABLER_MTYPE: { |
| 3265 | if (op == VF_GET) |
| 3266 | *(char *)ptr = g_ptr->enabler[index].movement_type; |
| 3267 | else if (op == VF_SET) |
| 3268 | g_ptr->enabler[index].movement_type = *(char *)ptr; |
| 3269 | } break; |
| 3270 | case AIGSV_F_ENABLER_FLOAT_VALUE: { |
| 3271 | if (op == VF_GET) |
| 3272 | *(float *)ptr = g_ptr->enabler[index].float_value; |
| 3273 | else if (op == VF_SET) |
| 3274 | g_ptr->enabler[index].float_value = *(float *)ptr; |
| 3275 | } break; |
| 3276 | case AIGSV_I_ENABLER_FLAGS: { |
| 3277 | if (op == VF_GET) |
| 3278 | *(int *)ptr = g_ptr->enabler[index].flags; |
| 3279 | else if (op == VF_SET) |
| 3280 | g_ptr->enabler[index].flags = *(int *)ptr; |
| 3281 | else if (op == VF_SET_FLAGS) |
| 3282 | g_ptr->enabler[index].flags |= *(int *)ptr; |
| 3283 | else if (op == VF_CLEAR_FLAGS) |
| 3284 | g_ptr->enabler[index].flags &= ~(*(int *)ptr); |
| 3285 | } break; |
| 3286 | case AIGSV_F_ENABLER_DIST: { |
| 3287 | if (op == VF_GET) |
| 3288 | *(float *)ptr = g_ptr->enabler[index].dist; |
| 3289 | else if (op == VF_SET) |
| 3290 | g_ptr->enabler[index].dist = *(float *)ptr; |
| 3291 | } break; |
| 3292 | case AIGSV_F_ENABLER_PERCENT: { |
| 3293 | if (op == VF_GET) |
| 3294 | *(float *)ptr = g_ptr->enabler[index].percent_enable; |
| 3295 | else if (op == VF_SET) |
| 3296 | g_ptr->enabler[index].percent_enable = *(float *)ptr; |
| 3297 | } break; |
| 3298 | case AIGSV_F_ENABLER_CHECK_INTERVAL: { |
| 3299 | if (op == VF_GET) |
| 3300 | *(float *)ptr = g_ptr->enabler[index].check_interval; |
| 3301 | else if (op == VF_SET) |
| 3302 | g_ptr->enabler[index].check_interval = *(float *)ptr; |
| 3303 | } break; |
| 3304 | case AIGSV_F_ENABLER_LAST_CHECK_TIME: { |
| 3305 | if (op == VF_GET) |
| 3306 | *(float *)ptr = g_ptr->enabler[index].last_check_time; |
| 3307 | else if (op == VF_SET) |
| 3308 | g_ptr->enabler[index].last_check_time = *(float *)ptr; |
| 3309 | } break; |
| 3310 | case AIGSV_C_ENABLER_NEXT_ENABLER_OP: { |
| 3311 | if (op == VF_GET) |
| 3312 | *(char *)ptr = g_ptr->enabler[index].bool_next_enabler_op; |
| 3313 | else if (op == VF_SET) |
| 3314 | g_ptr->enabler[index].bool_next_enabler_op = *(char *)ptr; |
| 3315 | } break; |
| 3316 | } |
| 3317 | } |
| 3318 | |
| 3319 | int osipf_AIGetNearbyObjs(vector *pos, int init_roomnum, float rad, int *object_handle_list, int max_elements, |
| 3320 | bool f_lightmap_only, bool f_only_players_and_ais, bool f_include_non_collide_objects, |
| 3321 | bool f_stop_at_closed_doors) { |
| 3322 | int16_t *s_list; |
| 3323 | int num_close; |
| 3324 | int i; |
| 3325 | int count = 0; |
| 3326 | |
| 3327 | s_list = (int16_t *)mem_malloc(sizeof(int16_t) * max_elements); |
| 3328 | |
| 3329 | num_close = fvi_QuickDistObjectList(pos, init_roomnum, rad, s_list, max_elements, f_lightmap_only, |
| 3330 | f_only_players_and_ais, f_include_non_collide_objects, f_stop_at_closed_doors); |
| 3331 | ASSERT(num_close <= max_elements); |
| 3332 | for (i = 0; i < num_close; i++) { |
| 3333 | if (!(Objects[s_list[i]].flags & OF_DEAD) && Objects[s_list[i]].render_type != RT_NONE) { |
| 3334 | object_handle_list[count++] = Objects[s_list[i]].handle; |
| 3335 | } |
| 3336 | } |
| 3337 | |
| 3338 | mem_free(s_list); |
| 3339 | |
| 3340 | return count; |
| 3341 | } |
| 3342 | |
| 3343 | char osipf_AIGetCurGoalIndex(int obj_handle) { |
| 3344 | object *obj = ObjGet(obj_handle); |
| 3345 | |
| 3346 | if (obj && obj->ai_info) { |
| 3347 | goal *cur_goal = GoalGetCurrentGoal(obj); |
| 3348 | if (cur_goal) { |
| 3349 | return (cur_goal - obj->ai_info->goals); |
| 3350 | } |
| 3351 | } |
| 3352 | |
| 3353 | return -1; |
| 3354 | } |
| 3355 | |
| 3356 | int osipf_FindSoundName(const char *name) { return FindSoundName(IGNORE_TABLE(name)); } |
| 3357 | |
| 3358 | int osipf_FindRoomName(const char *name) { |
| 3359 | for (int i = 0; i <= Highest_room_index; i++) { |
| 3360 | if (Rooms[i].used && Rooms[i].name) { |
| 3361 | if (!stricmp(name, Rooms[i].name)) |
| 3362 | return i; |
| 3363 | } |
| 3364 | } |
| 3365 | return -1; |
| 3366 | } |
| 3367 | |
| 3368 | int osipf_FindTriggerName(const char *name) { |
| 3369 | for (int i = 0; i < Num_triggers; i++) { |
| 3370 | if (Triggers[i].name) { |
| 3371 | if (!stricmp(name, Triggers[i].name)) |
| 3372 | return i; |
| 3373 | } |
| 3374 | } |
| 3375 | return -1; |
| 3376 | } |
| 3377 | |
| 3378 | int osipf_FindObjectName(const char *name) { |
| 3379 | for (int i = 0; i < MAX_OBJECTS; i++) { |
| 3380 | if (Objects[i].type != OBJ_NONE && Objects[i].name != NULL) { |
| 3381 | if (!stricmp(name, Objects[i].name)) |
| 3382 | return Objects[i].handle; |
| 3383 | } |
| 3384 | } |
| 3385 | return OBJECT_HANDLE_NONE; |
| 3386 | } |
| 3387 | |
| 3388 | int osipf_GetTriggerRoom(int trigger_id) { |
| 3389 | if (trigger_id < 0 || trigger_id >= Num_triggers) |
| 3390 | return -1; |
| 3391 | |
| 3392 | return Triggers[trigger_id].roomnum; |
| 3393 | } |
| 3394 | |
| 3395 | int osipf_GetTriggerFace(int trigger_id) { |
| 3396 | if (trigger_id < 0 || trigger_id >= Num_triggers) |
| 3397 | return -1; |
| 3398 | |
| 3399 | return Triggers[trigger_id].facenum; |
| 3400 | } |
| 3401 | |
| 3402 | int osipf_FindDoorName(const char *name) { |
| 3403 | for (int i = 0; i <= MAX_OBJECTS; i++) { |
| 3404 | if (Objects[i].type == OBJ_DOOR && Objects[i].name && !stricmp(Objects[i].name, name)) { |
| 3405 | return Objects[i].handle; |
| 3406 | } |
| 3407 | } |
| 3408 | return OBJECT_HANDLE_NONE; |
| 3409 | } |
| 3410 | |
| 3411 | int osipf_FindTextureName(const char *name) { return FindTextureName(IGNORE_TABLE(name)); } |
| 3412 | |
| 3413 | int osipf_FindMatcenName(const char *name) { return FindMatcenIndex(name); } |
| 3414 | |
| 3415 | int osipf_FindPathName(const char *name) { return FindGamePathName(name); } |
| 3416 | |
| 3417 | int osipf_FindLevelGoalName(const char *name) { return Level_goals.GoalFindId(name); } |
| 3418 | |
| 3419 | void osipf_CreateRandomSparks(int num_sparks, vector *pos, int roomnum, int which_index, float force_scalar) { |
| 3420 | CreateRandomSparks(num_sparks, pos, roomnum, which_index, force_scalar); |
| 3421 | } |
| 3422 | |
| 3423 | // disable/enable ship |
| 3424 | void osipf_EnableShip(char *ship_name, bool enable) { |
| 3425 | msafe_struct ms; |
| 3426 | strcpy(ms.name, ship_name); |
| 3427 | ms.state = enable; |
| 3428 | msafe_CallFunction(MSAFE_MISC_ENABLE_SHIP, &ms); |
| 3429 | } |
| 3430 | |
| 3431 | // is ship enabled |
| 3432 | bool osipf_IsShipEnabled(char *ship_name) { |
| 3433 | msafe_struct ms; |
| 3434 | strcpy(ms.name, ship_name); |
| 3435 | msafe_GetValue(MSAFE_MISC_ENABLE_SHIP, &ms); |
| 3436 | return (bool)(ms.state != 0); |
| 3437 | } |
| 3438 | |
| 3439 | // turns the given player into AI mode or back to regular control mode |
| 3440 | void osipf_SetPlayerControlMode(int pnum, bool set_to_ai) { |
| 3441 | ASSERT(pnum >= 0 && pnum < MAX_PLAYERS); |
| 3442 | if (pnum < 0 || pnum >= MAX_PLAYERS) |
| 3443 | return; |
| 3444 | |
| 3445 | if (set_to_ai) { |
| 3446 | if (pnum != Player_num) |
| 3447 | return; // only change it for ourselves |
| 3448 | |
| 3449 | PlayerSetControlToAI(pnum); |
| 3450 | } else { |
| 3451 | ResetPlayerControlType(pnum); |
| 3452 | } |
| 3453 | } |
| 3454 | |
| 3455 | // gets information about a path point |
| 3456 | // pass NULL for parameters not needed. |
| 3457 | // pathid: path number |
| 3458 | // point: which path point |
| 3459 | // returns true if operation was successful |
| 3460 | bool osipf_PathGetInformation(int pathid, int point, vector *pos, int *room, matrix *orient) { |
| 3461 | if (pathid < 0 || pathid >= MAX_GAME_PATHS) |
| 3462 | return false; |
| 3463 | |
| 3464 | if (!GamePaths[pathid].used) |
| 3465 | return false; |
| 3466 | |
| 3467 | if (point < 0 || point >= GamePaths[pathid].num_nodes) |
| 3468 | return false; |
| 3469 | |
| 3470 | if (pos) { |
| 3471 | pos->x = GamePaths[pathid].pathnodes[point].pos.x; |
| 3472 | pos->y = GamePaths[pathid].pathnodes[point].pos.y; |
| 3473 | pos->z = GamePaths[pathid].pathnodes[point].pos.z; |
| 3474 | } |
| 3475 | |
| 3476 | if (room) { |
| 3477 | *room = GamePaths[pathid].pathnodes[point].roomnum; |
| 3478 | } |
| 3479 | |
| 3480 | if (orient) { |
| 3481 | vm_VectorToMatrix(orient, &GamePaths[pathid].pathnodes[point].fvec, &GamePaths[pathid].pathnodes[point].uvec, NULL); |
| 3482 | } |
| 3483 | |
| 3484 | return true; |
| 3485 | } |
| 3486 | |
| 3487 | void osipf_LGoalValue(char op, char vtype, void *ptr, int g_index, int i_index) { |
| 3488 | switch (vtype) { |
| 3489 | case LGV_I_STATUS: { |
| 3490 | if (op == VF_GET) |
| 3491 | Level_goals.LGStatus(LO_GET_SPECIFIED, (int *)ptr); |
| 3492 | else if (op == VF_SET_FLAGS) |
| 3493 | Level_goals.LGStatus(LO_SET_SPECIFIED, (int *)ptr); |
| 3494 | else if (op == VF_CLEAR_FLAGS) |
| 3495 | Level_goals.LGStatus(LO_CLEAR_SPECIFIED, (int *)ptr); |
| 3496 | else if (op == VF_SET) { |
| 3497 | int status; |
| 3498 | Level_goals.LGStatus(LO_GET_SPECIFIED, &status); |
| 3499 | |
| 3500 | int diff_flags = (*(int *)ptr) ^ status; |
| 3501 | int clear_flags = status & diff_flags; |
| 3502 | int set_flags = (~(status)) & diff_flags; |
| 3503 | |
| 3504 | if (clear_flags) |
| 3505 | Level_goals.LGStatus(LO_CLEAR_SPECIFIED, &clear_flags); |
| 3506 | if (set_flags) |
| 3507 | Level_goals.LGStatus(LO_SET_SPECIFIED, &set_flags); |
| 3508 | } |
| 3509 | } break; |
| 3510 | case LGV_I_NUM_ACTIVE_PRIMARIES: { |
| 3511 | if (op == VF_GET) |
| 3512 | *((int *)ptr) = Level_goals.GetNumActivePrimaryGoals(); |
| 3513 | } break; |
| 3514 | case LGSV_I_ACTIVE_PRIMARY_GOAL: { |
| 3515 | if (op == VF_GET) |
| 3516 | *((int *)ptr) = Level_goals.GetActivePrimaryGoal(g_index); |
| 3517 | } break; |
| 3518 | case LGV_I_NUM_ACTIVE_SECONDARIES: { |
| 3519 | if (op == VF_GET) |
| 3520 | *((int *)ptr) = Level_goals.GetNumActiveSecondaryGoals(); |
| 3521 | } break; |
| 3522 | case LGSV_I_ACTIVE_SECONDARY_GOAL: { |
| 3523 | if (op == VF_GET) |
| 3524 | *((int *)ptr) = Level_goals.GetActiveSecondaryGoal(g_index); |
| 3525 | } break; |
| 3526 | case LGV_I_NUM_GOALS: { |
| 3527 | if (op == VF_GET) |
| 3528 | *((int *)ptr) = Level_goals.GetNumGoals(); |
| 3529 | } break; |
| 3530 | case LGSV_PC_GOAL_NAME: { |
| 3531 | if (op == VF_GET) { |
| 3532 | Level_goals.GoalGetName(g_index, (char *)ptr, 256); // chrishack - major demo hack |
| 3533 | } else if (op == VF_SET) { |
| 3534 | Level_goals.GoalSetName(g_index, (char *)ptr); |
| 3535 | } |
| 3536 | } break; |
| 3537 | case LGSV_PC_LOCATION_NAME: { |
| 3538 | if (op == VF_GET) { |
| 3539 | Level_goals.GoalGetItemName(g_index, (char *)ptr, 256); // chrishack - major demo hack |
| 3540 | } else if (op == VF_SET) { |
| 3541 | Level_goals.GoalSetItemName(g_index, (char *)ptr); |
| 3542 | } |
| 3543 | } break; |
| 3544 | case LGSV_PC_DESCRIPTION: { |
| 3545 | if (op == VF_GET) { |
| 3546 | Level_goals.GoalGetDesc(g_index, (char *)ptr, 256); // chrishack - major demo hack |
| 3547 | } else if (op == VF_SET) { |
| 3548 | Level_goals.GoalSetDesc(g_index, (char *)ptr); |
| 3549 | } |
| 3550 | } break; |
| 3551 | case LGSV_PC_COMPLETION_MESSAGE: { |
| 3552 | if (op == VF_GET) { |
| 3553 | Level_goals.GoalGetCompletionMessage(g_index, (char *)ptr, 256); |
| 3554 | } else if (op == VF_SET) { |
| 3555 | Level_goals.GoalSetCompletionMessage(g_index, (char *)ptr); |
| 3556 | } |
| 3557 | } break; |
| 3558 | case LGSV_I_PRIORITY: { |
| 3559 | if (op == VF_GET) { |
| 3560 | Level_goals.GoalPriority(g_index, LO_GET_SPECIFIED, (int *)&ptr); |
| 3561 | } else if (op == VF_SET) { |
| 3562 | Level_goals.GoalPriority(g_index, LO_SET_SPECIFIED, (int *)&ptr); |
| 3563 | } |
| 3564 | } break; |
| 3565 | case LGSV_C_GOAL_LIST: { |
| 3566 | if (op == VF_GET) { |
| 3567 | Level_goals.GoalGoalList(g_index, LO_GET_SPECIFIED, (char *)ptr); |
| 3568 | } else if (op == VF_SET) { |
| 3569 | Level_goals.GoalGoalList(g_index, LO_SET_SPECIFIED, (char *)ptr); |
| 3570 | } |
| 3571 | } break; |
| 3572 | case LGSV_I_STATUS: { |
| 3573 | if (op == VF_GET) |
| 3574 | Level_goals.GoalStatus(g_index, LO_GET_SPECIFIED, (int *)ptr); |
| 3575 | else if (op == VF_SET_FLAGS) |
| 3576 | Level_goals.GoalStatus(g_index, LO_SET_SPECIFIED, (int *)ptr); |
| 3577 | else if (op == VF_CLEAR_FLAGS) |
| 3578 | Level_goals.GoalStatus(g_index, LO_CLEAR_SPECIFIED, (int *)ptr); |
| 3579 | else if (op == VF_SET) { |
| 3580 | int status; |
| 3581 | Level_goals.GoalStatus(g_index, LO_GET_SPECIFIED, &status); |
| 3582 | |
| 3583 | int diff_flags = (*(int *)ptr) ^ status; |
| 3584 | int clear_flags = status & diff_flags; |
| 3585 | int set_flags = (~(status)) & diff_flags; |
| 3586 | |
| 3587 | if (clear_flags) |
| 3588 | Level_goals.GoalStatus(g_index, LO_CLEAR_SPECIFIED, &clear_flags); |
| 3589 | if (set_flags) |
| 3590 | Level_goals.GoalStatus(g_index, LO_SET_SPECIFIED, &set_flags); |
| 3591 | } |
| 3592 | } break; |
| 3593 | case LGSV_I_NUM_ITEMS: { |
| 3594 | if (op == VF_GET) { |
| 3595 | *((int *)ptr) = Level_goals.GoalGetNumItems(g_index); |
| 3596 | } |
| 3597 | } break; |
| 3598 | case LGSSV_C_ITEM_TYPE: { |
| 3599 | if (op == VF_GET) { |
| 3600 | Level_goals.GoalItemInfo(g_index, i_index, LO_GET_SPECIFIED, (char *)ptr, NULL, NULL); |
| 3601 | } else if (op == VF_SET) { |
| 3602 | Level_goals.GoalItemInfo(g_index, i_index, LO_SET_SPECIFIED, (char *)ptr, NULL, NULL); |
| 3603 | } |
| 3604 | } break; |
| 3605 | case LGSSV_I_ITEM_HANDLE: { |
| 3606 | if (op == VF_GET) { |
| 3607 | Level_goals.GoalItemInfo(g_index, i_index, LO_GET_SPECIFIED, NULL, (int *)ptr, NULL); |
| 3608 | } else if (op == VF_SET) { |
| 3609 | Level_goals.GoalItemInfo(g_index, i_index, LO_SET_SPECIFIED, NULL, (int *)ptr, NULL); |
| 3610 | } |
| 3611 | } break; |
| 3612 | case LGSSV_B_ITEM_DONE: { |
| 3613 | if (op == VF_GET) { |
| 3614 | Level_goals.GoalItemInfo(g_index, i_index, LO_GET_SPECIFIED, NULL, NULL, (bool *)ptr); |
| 3615 | } else if (op == VF_SET) { |
| 3616 | Level_goals.GoalItemInfo(g_index, i_index, LO_SET_SPECIFIED, NULL, NULL, (bool *)ptr); |
| 3617 | } |
| 3618 | } break; |
| 3619 | } |
| 3620 | } |
| 3621 | |
| 3622 | void osipf_ObjKill(int handle, int killer_handle, float damage, int flags, float min_time, float max_time) { |
| 3623 | object *obj = ObjGet(handle); |
| 3624 | object *killer = ObjGet(killer_handle); |
| 3625 | |
| 3626 | if (obj == NULL) |
| 3627 | return; |
| 3628 | |
| 3629 | if (obj->type == OBJ_PLAYER || obj->type == OBJ_GHOST || obj->type == OBJ_OBSERVER) { |
| 3630 | if (obj->type != OBJ_PLAYER) { |
| 3631 | Int3(); |
| 3632 | } |
| 3633 | |
| 3634 | KillPlayer(obj, killer, damage, -1); |
| 3635 | } else if (IS_GENERIC(obj->type) || (obj->type == OBJ_DOOR)) { |
| 3636 | |
| 3637 | if (IS_GUIDEBOT(obj)) // Don't allow killing of the guidebot |
| 3638 | return; |
| 3639 | |
| 3640 | if (flags == -1) // no flags, so use default death |
| 3641 | KillObject(obj, killer, damage); |
| 3642 | else { |
| 3643 | float delay_time = min_time + (max_time - min_time) * ps_rand() / D3_RAND_MAX; |
| 3644 | KillObject(obj, killer, damage, flags, delay_time); |
| 3645 | } |
| 3646 | } |
| 3647 | } |
| 3648 | |
| 3649 | bool osipf_AIIsDestReachable(int handle, int room) { |
| 3650 | object *obj = ObjGet(handle); |
| 3651 | |
| 3652 | if (!obj) |
| 3653 | return false; |
| 3654 | |
| 3655 | return AIFindAltPath(obj, obj->roomnum, room); |
| 3656 | } |
| 3657 | |
| 3658 | bool osipf_AIIsObjReachable(int handle, int target_handle) { |
| 3659 | object *obj = ObjGet(handle); |
| 3660 | object *target = ObjGet(target_handle); |
| 3661 | |
| 3662 | if (!obj) |
| 3663 | return false; |
| 3664 | |
| 3665 | if (!target) |
| 3666 | return false; |
| 3667 | |
| 3668 | return AIFindAltPath(obj, obj->roomnum, target->roomnum); |
| 3669 | } |
| 3670 | |
| 3671 | char osipf_GameGetDiffLevel(void) { return DIFF_LEVEL; } |
| 3672 | |
| 3673 | int osipf_GetLanguageSetting(void) { |
| 3674 | /* |
| 3675 | 0:LANGUAGE_ENGLISH |
| 3676 | 1:LANGUAGE_GERMAN |
| 3677 | 2:LANGUAGE_SPANISH |
| 3678 | 3:LANGUAGE_ITALIAN |
| 3679 | 4:LANGUAGE_FRENCH |
| 3680 | */ |
| 3681 | return Localization_GetLanguage(); |
| 3682 | } |
| 3683 | |
| 3684 | // Sets/Gets information about a path. |
| 3685 | // If you change is PV_ALL (or any of it's individual components), pass in a pointer to an |
| 3686 | // osiris_path_node_info struct. For the others, you must pass in an appropriate pointer |
| 3687 | // (i.e. an int* for PV_I_NUMNODES). You can only set PV_ALL components. |
| 3688 | // for PV_I_NUMNODES, path_id MUST be specified, node_id is ignored |
| 3689 | // for PV_I_NUMPATHS, path_id and node_id are ignored |
| 3690 | // for PV_CS_NAME, path_id MUST be specified, node_id is ignored |
| 3691 | // for PV_ALL components, path_id and node_id MUST be valid. |
| 3692 | void osipf_PathValue(int path_id, int node_id, char op, int changes, void *ptr) { |
| 3693 | if (changes & PV_I_NUMPATHS) { |
| 3694 | *((int *)ptr) = Num_game_paths; |
| 3695 | return; |
| 3696 | } |
| 3697 | |
| 3698 | if (path_id < 0 || path_id >= Num_game_paths) { |
| 3699 | mprintf(0, "Invalid Path\n"); |
| 3700 | Int3(); |
| 3701 | return; |
| 3702 | } |
| 3703 | |
| 3704 | game_path *cpath = &GamePaths[path_id]; |
| 3705 | |
| 3706 | ASSERT(cpath->used); |
| 3707 | if (!cpath->used) |
| 3708 | return; |
| 3709 | |
| 3710 | if (op == VF_GET) { |
| 3711 | if (changes & PV_ALL) { |
| 3712 | if (node_id < 0 || node_id >= cpath->num_nodes) { |
| 3713 | mprintf(0, "Invalid node on path\n"); |
| 3714 | Int3(); |
| 3715 | return; |
| 3716 | } |
| 3717 | |
| 3718 | node *cnode = &cpath->pathnodes[node_id]; |
| 3719 | osiris_path_node_info *pni = (osiris_path_node_info *)ptr; |
| 3720 | |
| 3721 | if (changes & PV_POS) { |
| 3722 | pni->pos = cnode->pos; |
| 3723 | } |
| 3724 | if (changes & PV_ROOMNUM) { |
| 3725 | pni->roomnum = cnode->roomnum; |
| 3726 | } |
| 3727 | if (changes & PV_FLAGS) { |
| 3728 | pni->flags = cnode->flags; |
| 3729 | } |
| 3730 | if (changes & PV_FVEC) { |
| 3731 | pni->fvec = cnode->fvec; |
| 3732 | } |
| 3733 | if (changes & PV_UVEC) { |
| 3734 | pni->uvec = cnode->uvec; |
| 3735 | } |
| 3736 | |
| 3737 | changes &= ~PV_ALL; |
| 3738 | ASSERT(changes == 0); // no other changes allowed!!!! |
| 3739 | return; |
| 3740 | } |
| 3741 | |
| 3742 | if (changes == PV_I_NUMNODES) { |
| 3743 | *((int *)ptr) = cpath->num_nodes; |
| 3744 | return; |
| 3745 | } |
| 3746 | |
| 3747 | if (changes == PV_CS_NAME) { |
| 3748 | strcpy((char *)ptr, cpath->name); |
| 3749 | return; |
| 3750 | } |
| 3751 | |
| 3752 | } else if (op == VF_SET) { |
| 3753 | if (changes & PV_ALL) { |
| 3754 | if (node_id < 0 || node_id >= cpath->num_nodes) { |
| 3755 | mprintf(0, "Invalid node on path\n"); |
| 3756 | Int3(); |
| 3757 | return; |
| 3758 | } |
| 3759 | |
| 3760 | node *cnode = &cpath->pathnodes[node_id]; |
| 3761 | osiris_path_node_info *pni = (osiris_path_node_info *)ptr; |
| 3762 | |
| 3763 | if (changes & PV_POS) { |
| 3764 | cnode->pos = pni->pos; |
| 3765 | } |
| 3766 | if (changes & PV_ROOMNUM) { |
| 3767 | cnode->roomnum = pni->roomnum; |
| 3768 | } |
| 3769 | if (changes & PV_FLAGS) { |
| 3770 | cnode->flags = pni->flags; |
| 3771 | } |
| 3772 | if (changes & PV_FVEC) { |
| 3773 | cnode->fvec = pni->fvec; |
| 3774 | } |
| 3775 | if (changes & PV_UVEC) { |
| 3776 | cnode->uvec = pni->uvec; |
| 3777 | } |
| 3778 | |
| 3779 | changes &= ~PV_ALL; |
| 3780 | ASSERT(changes == 0); // no other changes allowed!!!! |
| 3781 | return; |
| 3782 | } |
| 3783 | |
| 3784 | } else { |
| 3785 | Int3(); |
| 3786 | } |
| 3787 | } |