| 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/object.cpp $ |
| 21 | * $Revision: 315 $ |
| 22 | * $Date: 3/20/00 12:18p $ |
| 23 | * $Author: Matt $ |
| 24 | * |
| 25 | * Object management functions |
| 26 | * |
| 27 | * $Log: /DescentIII/main/object.cpp $ |
| 28 | * |
| 29 | * 315 3/20/00 12:18p Matt |
| 30 | * Merge of Duane's post-1.3 changes. |
| 31 | * Memset ai_frame to zeros after malloc. |
| 32 | * |
| 33 | * 314 1/26/00 9:20p Jeff |
| 34 | * added support for IntelliVIBE DLL |
| 35 | * |
| 36 | * 313 10/25/99 9:52a Matt |
| 37 | * Undid a Mac change (Duane says it's ok) |
| 38 | * |
| 39 | * 312 10/23/99 12:51a Matt |
| 40 | * Fixed compile warning |
| 41 | * |
| 42 | * 311 10/22/99 10:44p Jeff |
| 43 | * mac merge bug fix |
| 44 | * |
| 45 | * 310 10/22/99 3:43p Matt |
| 46 | * Mac merge |
| 47 | * |
| 48 | * 309 10/20/99 5:40p Chris |
| 49 | * Added the Red Guidebot |
| 50 | * |
| 51 | * 308 10/08/99 4:24p 3dsmax |
| 52 | * some ambient sound fix done by MattT |
| 53 | * |
| 54 | * 307 9/18/99 9:24p Jeff |
| 55 | * object position history code (needed for motion blur effect) |
| 56 | * |
| 57 | * 306 5/22/99 1:54a Matt |
| 58 | * Got rid of debug code mistakenly checked in. |
| 59 | * |
| 60 | * 305 5/21/99 3:43a Matt |
| 61 | * |
| 62 | * 304 5/20/99 9:03p Matt |
| 63 | * Changed trigger system so that collisions with rendered portals don't |
| 64 | * set off triggers on the portals. |
| 65 | * |
| 66 | * 303 5/20/99 3:00p Jason |
| 67 | * added support for negative respawn scalars |
| 68 | * |
| 69 | * 302 5/13/99 7:18p Jeff |
| 70 | * fixed unattach bug in delete dead |
| 71 | * |
| 72 | * 301 5/10/99 8:29p Jason |
| 73 | * robots no longer burn on terrain that causes damage |
| 74 | * |
| 75 | * 300 5/08/99 4:12p Chris |
| 76 | * Added AI hearing noises... version 1 |
| 77 | * |
| 78 | * 299 5/06/99 12:52p Jason |
| 79 | * fixed set on fire bug |
| 80 | * |
| 81 | * 298 5/05/99 5:18p Jason |
| 82 | * Invul generic objects don't burn on damaging terrain |
| 83 | * |
| 84 | * 297 5/05/99 5:10a Matt |
| 85 | * Fixed a bug with dying & animating objects. |
| 86 | * |
| 87 | * 296 4/29/99 4:50p Chris |
| 88 | * Fixed matcen and Osiris created objects so thier ambient sounds play |
| 89 | * |
| 90 | * 295 4/29/99 3:09p Jason |
| 91 | * fixed a potential bug with object deaths |
| 92 | * |
| 93 | * 294 4/27/99 10:25p Jason |
| 94 | * slowed down afterburner outside just a bit |
| 95 | * |
| 96 | * 293 4/27/99 9:13a Matt |
| 97 | * When clearing a room's secret flag, clear the flag from all the |
| 98 | * connected rooms. |
| 99 | * |
| 100 | * 292 4/26/99 2:30p Jason |
| 101 | * fixed bug with secret messages |
| 102 | * |
| 103 | * 291 4/26/99 2:28p Jason |
| 104 | * added persistant hud messages |
| 105 | * |
| 106 | * 290 4/25/99 5:20p Jason |
| 107 | * fixed some more coop bugs |
| 108 | * |
| 109 | * 289 4/24/99 2:00p Chris |
| 110 | * Removed the slow terrain cell verify check from ObjMoveOne when Del+Y |
| 111 | * is in effect |
| 112 | * |
| 113 | * 288 4/23/99 7:18p Jason |
| 114 | * fixed some multiplayer issues with observer mode |
| 115 | * |
| 116 | * 287 4/22/99 7:13p Jeff |
| 117 | * fixed bug deleting ghost object in multiplayer |
| 118 | * |
| 119 | * 286 4/22/99 4:19p Chris |
| 120 | * Checked in with the extended DEL+Y terrain node check stuff |
| 121 | * |
| 122 | * 285 4/21/99 3:01p Matt |
| 123 | * Added a new type for dying objects that have AI, instead of keeping a |
| 124 | * flag in the dying info. |
| 125 | * |
| 126 | * 284 4/21/99 11:05a Kevin |
| 127 | * new ps_rand and ps_srand to replace rand & srand |
| 128 | * |
| 129 | * 283 4/20/99 12:24p Matt |
| 130 | * Re-revised the ObjInit() system. ObjInit() again does all the |
| 131 | * initialization stuff, but now it's passed a lot more information so |
| 132 | * those fields can be set before the rest of the initialization takes |
| 133 | * place. |
| 134 | * |
| 135 | * 282 4/18/99 8:13p Chris |
| 136 | * Fixed the floating flare problems (where windows where broken out and |
| 137 | * the flare remained) |
| 138 | * |
| 139 | * 281 4/18/99 5:33p Jason |
| 140 | * fixed object multiplayer problem |
| 141 | * |
| 142 | * 280 4/16/99 12:33a Matt |
| 143 | * Disable Soar on non-Windows systems. |
| 144 | * |
| 145 | * 279 4/15/99 1:41a Jeff |
| 146 | * changes for linux compile |
| 147 | * |
| 148 | * 278 4/14/99 3:56a Jeff |
| 149 | * fixed case mismatch in #includes |
| 150 | * |
| 151 | * 277 4/12/99 6:15p Samir |
| 152 | * Sound priorities pass 1 |
| 153 | * |
| 154 | * 276 4/12/99 8:18a Chris |
| 155 | * |
| 156 | * 275 4/12/99 8:12a Chris |
| 157 | * |
| 158 | * 274 4/12/99 8:06a Chris |
| 159 | * Added an ASSERT to check init code that doesn't call |
| 160 | * ComputeDefaultSize() for polygon objects |
| 161 | * |
| 162 | * 273 4/10/99 5:56p Matt |
| 163 | * Cleaned up object initialization code, including create object & load |
| 164 | * object. |
| 165 | * |
| 166 | * 272 4/09/99 12:06p Jason |
| 167 | * made model setup code faster |
| 168 | * |
| 169 | * 271 4/05/99 10:54a Matt |
| 170 | * Added auto-waypoint system |
| 171 | * |
| 172 | * 270 4/03/99 4:24p Jason |
| 173 | * sped up attached vis effects by a large amount |
| 174 | * |
| 175 | * 269 3/28/99 5:56p Matt |
| 176 | * Added sparking effect for objects |
| 177 | * |
| 178 | * 268 3/16/99 9:01a Kevin |
| 179 | * Fixed generic check to also check for doors. |
| 180 | * |
| 181 | * 267 3/12/99 7:47p Jeff |
| 182 | * only call applydamagetogeneric for generic objects |
| 183 | * |
| 184 | * 266 3/04/99 6:12p Jason |
| 185 | * fixed bug with terrain LOD |
| 186 | * |
| 187 | * 265 3/01/99 8:34p Matt |
| 188 | * Made room damage system set the player on fire instead of applying |
| 189 | * damage directly. This system still needs work, but is ok for now. |
| 190 | * |
| 191 | * 264 3/01/99 6:27p Matt |
| 192 | * Cleaned up handling of the outside-mine flag |
| 193 | * |
| 194 | * 263 3/01/99 3:15p Jason |
| 195 | * fixed multiplayer object deletion bug |
| 196 | * |
| 197 | * 262 2/28/99 6:36p Kevin |
| 198 | * More progress on load/save |
| 199 | * |
| 200 | * 261 2/27/99 5:40p Jason |
| 201 | * fixed bug where clients weren't getting remove messages for timed out |
| 202 | * powerups |
| 203 | * |
| 204 | * 260 2/25/99 11:01a Matt |
| 205 | * Added new explosion system. |
| 206 | * |
| 207 | * 259 2/25/99 10:29a Jason |
| 208 | * fixed powerup stalling bug in netgames |
| 209 | * |
| 210 | * 258 2/24/99 1:02p Jason |
| 211 | * various fixes for multiplayer |
| 212 | * |
| 213 | * 257 2/23/99 7:35p Jeff |
| 214 | * removed assert/return in unghost if the item is in a player's inventory |
| 215 | * (needs to be called when sending over objects in a multiplayer game, |
| 216 | * causes an assert) |
| 217 | * |
| 218 | * 256 2/23/99 5:13p Kevin |
| 219 | * Fixed it so objects with lightmaps will retain their lightmaps when a |
| 220 | * game is saved & loaded. |
| 221 | * |
| 222 | * 255 2/23/99 12:39p Jason |
| 223 | * added more options for generic objects |
| 224 | * |
| 225 | * 254 2/22/99 3:26a Matt |
| 226 | * Deleted obsolete code |
| 227 | * |
| 228 | * 253 2/22/99 1:20a Jeff |
| 229 | * added support for inventory (simple) in dallas. Moved end-level |
| 230 | * sequence to use IGC. Add position clipboard stuff for dallas. Fixed |
| 231 | * some inventory bug with storing object handles |
| 232 | * |
| 233 | * 252 2/21/99 4:31p Chris |
| 234 | * Improving the level goal system... Not done. |
| 235 | * |
| 236 | * 251 2/21/99 4:20p Matt |
| 237 | * Added SoundSource objects (and reformatted parts of the object header |
| 238 | * files). |
| 239 | * |
| 240 | * 250 2/19/99 5:16p Chris |
| 241 | * Added the child died event |
| 242 | * |
| 243 | * 249 2/15/99 11:22a Jason |
| 244 | * took out client-side prediction |
| 245 | * |
| 246 | * 248 2/13/99 12:36a Jeff |
| 247 | * new object flag. set for when an object is currently in a player's |
| 248 | * inventory |
| 249 | * |
| 250 | * 247 2/12/99 5:59p Jason |
| 251 | * more permissable server stuff |
| 252 | * |
| 253 | * 246 2/12/99 3:38p Jason |
| 254 | * added client side interpolation |
| 255 | * |
| 256 | * 245 2/10/99 2:49p Matt |
| 257 | * Renamed OBJECT_HANDLE_INVALID to OBJECT_HANDLE_BAD |
| 258 | * |
| 259 | * 244 2/10/99 1:47p Matt |
| 260 | * Changed object handle symbolic constants |
| 261 | * |
| 262 | * 243 2/08/99 5:25p Jeff |
| 263 | * removed all calls to MultiSendRemoveObject, incorportated into |
| 264 | * SetObjectDeadFlag. Fixes sequencing issues in multiplayer |
| 265 | * |
| 266 | * 242 2/07/99 1:20a Jeff |
| 267 | * added new multiplayer game events EVT_GAMEOBJKILLED and |
| 268 | * EVT_GAMEOBJDESTROYED |
| 269 | * |
| 270 | * 241 2/05/99 1:27p Matt |
| 271 | * Only do cycled animations for generic objects |
| 272 | * |
| 273 | * 240 2/03/99 6:32p Jason |
| 274 | * more changes for world states |
| 275 | * |
| 276 | * 239 2/03/99 5:49p Matt |
| 277 | * Added room damage system |
| 278 | * |
| 279 | * 238 2/02/99 8:43a Chris |
| 280 | * I made buildings with AI work correctly (ie really big robots should be |
| 281 | * buildings) |
| 282 | * anim to and from states are now shorts instead of bytes |
| 283 | * |
| 284 | * 237 2/01/99 4:17p Jason |
| 285 | * more changes for multisafe |
| 286 | * |
| 287 | * 236 1/31/99 7:26p Matt |
| 288 | * Renamed a bunch of functions to have HUD capitalized |
| 289 | * |
| 290 | * 235 1/29/99 5:22p Jeff |
| 291 | * localization |
| 292 | * |
| 293 | * 234 1/27/99 6:48p Jeff |
| 294 | * better error handling for ghost/unghost (release build) |
| 295 | * |
| 296 | * 233 1/24/99 1:24a Jason |
| 297 | * fixed chase camera being deleted wrong |
| 298 | * |
| 299 | * 232 1/23/99 2:49p Kevin |
| 300 | * Fixed player movement masking |
| 301 | * |
| 302 | * 231 1/22/99 8:53p Jeff |
| 303 | * added custom-default script overrides |
| 304 | * |
| 305 | * 230 1/22/99 7:12p Jason |
| 306 | * changed terrain speed |
| 307 | * |
| 308 | * 229 1/22/99 4:23p Jason |
| 309 | * sped up afterburner temporarily |
| 310 | * |
| 311 | * 228 1/21/99 11:15p Jeff |
| 312 | * pulled out some structs and defines from header files and moved them |
| 313 | * into seperate header files so that multiplayer dlls don't require major |
| 314 | * game headers, just those new headers. Side effect is a shorter build |
| 315 | * time. Also cleaned up some header file #includes that weren't needed. |
| 316 | * This affected polymodel.h, object.h, player.h, vecmat.h, room.h, |
| 317 | * manage.h and multi.h |
| 318 | * |
| 319 | * 227 1/21/99 6:50p Jason |
| 320 | * added test impact mortar |
| 321 | * |
| 322 | * 226 1/21/99 3:34p Jason |
| 323 | * added liquid code |
| 324 | * |
| 325 | * 225 1/20/99 8:06p Jeff |
| 326 | * added members into DLLinfo struct for game change segment events, pass |
| 327 | * them over on execute dll packets |
| 328 | * |
| 329 | * 224 1/20/99 2:13a Chris |
| 330 | * It is now possible for robots to have special immunities, resistances, |
| 331 | * and vunerabilities |
| 332 | * |
| 333 | * 223 1/19/99 4:22p Matt |
| 334 | * Added the ability for objects to have their own lighting info, |
| 335 | * different from the default lighting for that type of object. |
| 336 | * |
| 337 | * 222 1/19/99 9:20a Kevin |
| 338 | * Added afterburner masking |
| 339 | * |
| 340 | * 221 1/18/99 6:18p Kevin |
| 341 | * Added controller masking to DALLAS |
| 342 | * |
| 343 | * 220 1/18/99 2:46p Matt |
| 344 | * Combined flags & flags2 fields in object struct |
| 345 | * |
| 346 | * 219 1/18/99 12:01a Jeff |
| 347 | * fixed EVT_GAMEPLAYERCHANGESEG event (would only get called if the |
| 348 | * server changed seg) and added EVT_GAMEOBJCHANGESEG |
| 349 | * |
| 350 | * 218 1/15/99 7:52p Chris |
| 351 | * Updated ObjSetPos() to include a f_update_attach_children flag |
| 352 | * |
| 353 | * 217 1/15/99 2:53p Jason |
| 354 | * fixed multiplayer ping bug |
| 355 | * |
| 356 | * 216 1/13/99 6:31p Jason |
| 357 | * added punch to the afterburner |
| 358 | * |
| 359 | * 215 1/13/99 2:27p Jeff |
| 360 | * added an is_dying flag for evt_destroy to determine whether the event |
| 361 | * is due to level end or because it really is dying |
| 362 | * |
| 363 | * 214 1/12/99 11:44p Jason |
| 364 | * Fixed bug with accelerated ping objects |
| 365 | * |
| 366 | * 213 1/08/99 2:56p Samir |
| 367 | * Ripped out OSIRIS1. |
| 368 | * |
| 369 | * 212 1/06/99 7:02p Jeff |
| 370 | * added a multiplayer event for game controls |
| 371 | * |
| 372 | * 211 1/05/99 5:09p Jason |
| 373 | * added permissable server networking (ala Quake/Unreal) to Descent3 |
| 374 | * |
| 375 | * 210 12/31/98 7:35p Jeff |
| 376 | * don't allow players to be Ghosted (turned into OBJ_DUMMY). Also, for |
| 377 | * ObjDelete[Dead] unghost a ghosted object before killing it |
| 378 | * |
| 379 | * 209 12/30/98 12:31p Jeff |
| 380 | * when freeing object scripts, the type is changed before it's freed in |
| 381 | * ObjDelete. Also, when destroyed, OBJ_ROBOT becomes OBJ_DEBRIS and |
| 382 | * Osiris was not handling this. |
| 383 | * |
| 384 | * 208 12/28/98 10:16a Jason |
| 385 | * fixed code that was causing some weapons to disappear |
| 386 | * |
| 387 | * 207 12/21/98 11:30p Matt |
| 388 | * Added names for objects |
| 389 | * |
| 390 | * 206 12/17/98 12:08p Jeff |
| 391 | * first checkin of new implementation of OSIRIS (old OSIRIS no longer |
| 392 | * works) |
| 393 | * |
| 394 | * 205 12/10/98 7:09p Jason |
| 395 | * added cloak fade |
| 396 | * |
| 397 | * 204 12/08/98 4:27p Chris |
| 398 | * Removed MT_WALKING hack |
| 399 | * |
| 400 | * 203 12/01/98 3:35p Matt |
| 401 | * Got rear view working. |
| 402 | * |
| 403 | * 202 12/01/98 3:15p Jason |
| 404 | * play refueling sound in 3d for multiplayer |
| 405 | * |
| 406 | * 201 11/17/98 4:16p Kevin |
| 407 | * Demo recording system |
| 408 | * |
| 409 | * 200 11/13/98 4:25p Jason |
| 410 | * changes for better weapon effects |
| 411 | * |
| 412 | * 199 11/13/98 2:27p Samir |
| 413 | * took out music code. |
| 414 | * |
| 415 | * 198 11/11/98 2:46p Kevin |
| 416 | * Demo recording system work |
| 417 | * |
| 418 | * 197 11/10/98 4:48p Jason |
| 419 | * sped up afterburner recharge time |
| 420 | * |
| 421 | * 196 11/10/98 11:16a Jason |
| 422 | * fixed some multiplayer bugs with powerups disappearing |
| 423 | * |
| 424 | * |
| 425 | * 195 11/06/98 11:05a Kevin |
| 426 | * Added code for demo play back |
| 427 | * |
| 428 | * 194 11/02/98 6:49p Jason |
| 429 | * fixed ifdef release problem |
| 430 | * |
| 431 | * 193 11/02/98 4:04p Luke |
| 432 | * Temp. disabled walkers inside |
| 433 | * |
| 434 | * 192 10/30/98 4:24p Jason |
| 435 | * changes for multiplayer |
| 436 | * |
| 437 | * 191 10/29/98 5:20p Chris |
| 438 | * Player ships collide smaller now |
| 439 | * |
| 440 | * 190 10/28/98 11:51a Jason |
| 441 | * fixed some multiplayer problems, plus redid coop a bit to make it |
| 442 | * cleaner |
| 443 | * |
| 444 | * 189 10/21/98 12:13p Jason |
| 445 | * took out guided in multi |
| 446 | * |
| 447 | * 188 10/20/98 5:47p Kevin |
| 448 | * Gunboy and other fixes |
| 449 | * |
| 450 | * 187 10/20/98 1:19p Jason |
| 451 | * fixed afterburner and Of2_SERVER_OBJECT bug |
| 452 | * |
| 453 | * 186 10/20/98 10:50a Sean |
| 454 | * |
| 455 | * 185 10/19/98 11:46p Jason |
| 456 | * changes for multiplayer debug layer |
| 457 | * |
| 458 | * 184 10/19/98 10:45p Jason |
| 459 | * toned down afterburner outside |
| 460 | * |
| 461 | * 183 10/19/98 7:51p Kevin |
| 462 | * performance testing |
| 463 | * |
| 464 | * 182 10/19/98 7:18p Matt |
| 465 | * Added system to support different types of damage to the player and |
| 466 | * have these different types make different sounds. |
| 467 | * |
| 468 | * 181 10/19/98 1:21p Jason |
| 469 | * made afterburner faster |
| 470 | * |
| 471 | * 180 10/18/98 11:07p Matt |
| 472 | * Made ClearTransientObjects() work. |
| 473 | * |
| 474 | * 179 10/17/98 5:50p Jeff |
| 475 | * hooked in rtperformance (run time performance) library |
| 476 | * |
| 477 | * 178 10/16/98 4:18p Chris |
| 478 | * Fixed the 'flare thing' |
| 479 | * |
| 480 | * 177 10/16/98 3:39p Chris |
| 481 | * Improved the object linking system and AI and physics |
| 482 | * |
| 483 | * 176 10/15/98 8:47a Matt |
| 484 | * Changed _DEBUG/RELEASE inconsistancy with slew |
| 485 | * |
| 486 | * 175 10/14/98 1:02p Jason |
| 487 | * fixed FindSoundName issues |
| 488 | * |
| 489 | * 174 10/14/98 12:43a Matt |
| 490 | * Fixed error handling for when an object can't be initialized. |
| 491 | * |
| 492 | * 173 10/13/98 1:08p Chris |
| 493 | * Greatly improved the AI's use of paths. Improved visability checking |
| 494 | * algorithm. Probably needs a second pass for further cleanup. |
| 495 | * |
| 496 | * 172 10/11/98 10:53p Matt |
| 497 | * Fixed some zero-length malloc()s |
| 498 | * |
| 499 | * 171 10/11/98 2:39p Matt |
| 500 | * If ObjInit() fails, ObjCreate() now returns an error. |
| 501 | * |
| 502 | * 170 10/08/98 4:23p Kevin |
| 503 | * Changed code to comply with memory library usage. Always use mem_malloc |
| 504 | * , mem_free and mem_strdup |
| 505 | * |
| 506 | * 169 10/06/98 5:46p Kevin |
| 507 | * Added new configuration for demo |
| 508 | * |
| 509 | * 168 10/06/98 2:59p Jason |
| 510 | * added timedemo function |
| 511 | * |
| 512 | * 167 10/06/98 11:27a Jason |
| 513 | * added new death type for robots |
| 514 | * |
| 515 | * 166 10/03/98 8:05p Matt |
| 516 | * Added asserts |
| 517 | * |
| 518 | * 165 9/28/98 6:23p Chris |
| 519 | * Changed multi_anim to custom_anim |
| 520 | * |
| 521 | * 164 9/23/98 2:55p Chris |
| 522 | * Improved auto-leveling and added newbie leveling |
| 523 | * |
| 524 | * 163 9/22/98 6:48p Jason |
| 525 | * fixed dedicated server problems |
| 526 | * |
| 527 | * 162 9/22/98 6:04p Samir |
| 528 | * ifdef DoAI to 1 if in release version. |
| 529 | * |
| 530 | * 161 9/22/98 1:02p Matt |
| 531 | * Don't set previous room info for an object if the object was moved in |
| 532 | * the editor. |
| 533 | * |
| 534 | * 160 9/22/98 12:40p Matt |
| 535 | * Cleaned up the object per-frame processing code. |
| 536 | * |
| 537 | * 159 9/17/98 3:03p Jason |
| 538 | * added lightning and invul hit effects |
| 539 | * |
| 540 | * 158 9/10/98 12:18p Jason |
| 541 | * more changes to afterburner/thrust effect |
| 542 | * |
| 543 | * 157 9/09/98 7:09p Jason |
| 544 | * changed afterburner effect for ships |
| 545 | * |
| 546 | * 156 9/09/98 4:30p Jason |
| 547 | * fixed a remaining (and insidious) bug with gunpoint instancing |
| 548 | * |
| 549 | * 155 8/31/98 6:12p Luke |
| 550 | * Moved the multi turret deletion code to somewhere where I can debug |
| 551 | * things |
| 552 | * |
| 553 | * 154 8/24/98 4:48p Jason |
| 554 | * undid my last rev |
| 555 | * |
| 556 | * 153 8/24/98 2:52p Jason |
| 557 | * fixed instance problem |
| 558 | * |
| 559 | * 152 8/19/98 11:30a Jason |
| 560 | * fixed afterburner problem with low framerates |
| 561 | * |
| 562 | * 151 8/17/98 12:10p Chris |
| 563 | * Fixed MAJOR bug in getting gunpoint positions |
| 564 | * |
| 565 | * 150 8/14/98 6:21p Chris |
| 566 | * Added another safety check for docycledanim |
| 567 | * |
| 568 | * 149 8/12/98 6:37p Jeff |
| 569 | * added functions to ghost an object (make it's type to OBJ_DUMMY) and |
| 570 | * unghost |
| 571 | * |
| 572 | * 148 8/12/98 12:04p Chris |
| 573 | * Attach system version .5 (still needs more work to be multiplayer |
| 574 | * friendly) |
| 575 | * |
| 576 | * 147 8/07/98 8:25p Chris |
| 577 | * Improved the attach system |
| 578 | * |
| 579 | * 146 8/07/98 6:54p Jeff |
| 580 | * afterburner powerup effect added |
| 581 | * |
| 582 | * 145 8/03/98 4:29p Chris |
| 583 | * Added additional support for the attach system |
| 584 | * |
| 585 | * 144 7/30/98 11:09a Jason |
| 586 | * added weapons that freeze and deform terrain |
| 587 | * |
| 588 | * 143 7/28/98 5:43p Samir |
| 589 | * added room change hook for music system, |
| 590 | * |
| 591 | * 142 7/22/98 3:16p Jason |
| 592 | * added observer mode |
| 593 | * |
| 594 | * 141 7/20/98 10:42a Jason |
| 595 | * added more player scalars, plus afterburner changes |
| 596 | * |
| 597 | * 140 7/16/98 12:51p Mark |
| 598 | * Fixed a potential bug |
| 599 | * |
| 600 | * 139 7/15/98 2:33p Jason |
| 601 | * added scalar variables for various player skills |
| 602 | * |
| 603 | * 138 7/15/98 12:48p Jeff |
| 604 | * put in calls to handle new multiplayer event...when an object's shields |
| 605 | * change |
| 606 | * |
| 607 | * 137 7/14/98 5:52p Kevin |
| 608 | * Packet loss measurements and auto pps adjusting |
| 609 | * |
| 610 | * 136 7/14/98 3:54p Sean |
| 611 | * CHRIS -- Fixed a bug in free'ing multi_turret_info on objects that are |
| 612 | * not polygon models (i.e. they don't have that info and it is union'ed |
| 613 | * to something else so it is not NULL) |
| 614 | * |
| 615 | * 135 7/09/98 7:50p Jeff |
| 616 | * added ObjGetUltimateParent to find out the original parent of an |
| 617 | * object, traces the family tree |
| 618 | * |
| 619 | * 134 7/09/98 3:30p Chris |
| 620 | * Fixed communication problem between systems |
| 621 | * |
| 622 | * 133 7/09/98 11:34a Chris |
| 623 | * Turrets are interpolated. |
| 624 | * |
| 625 | * 132 7/08/98 11:38a Chris |
| 626 | * Improved the turret info passing in multiplayer |
| 627 | * |
| 628 | * 131 7/07/98 3:26p Chris |
| 629 | * Added changes for turret updates |
| 630 | * |
| 631 | * 130 7/02/98 2:47p Chris |
| 632 | * Dynamic weapon info is now dynamically allocated |
| 633 | * |
| 634 | * 129 7/01/98 4:35p Chris |
| 635 | * More multiplayer sync issues |
| 636 | * |
| 637 | * 128 7/01/98 2:02p Chris |
| 638 | * Added the sound for animations |
| 639 | * |
| 640 | * 127 6/30/98 6:36p Chris |
| 641 | * Added rev .1 of multiplayer animations - BTW It is totally not done. |
| 642 | * |
| 643 | * 126 6/30/98 4:28p Chris |
| 644 | * Checked in some missing commas |
| 645 | * |
| 646 | * 125 5/26/98 7:07p Samir |
| 647 | * reset script.is_custom to 1 when calling ObjCreate. |
| 648 | * |
| 649 | * 124 5/22/98 4:45p Chris |
| 650 | * Powerups us the correct anim time |
| 651 | * |
| 652 | * 123 5/19/98 4:42a Chris |
| 653 | * Added shockwave's -- enjoy. :) |
| 654 | * |
| 655 | * 122 5/15/98 5:41p Jason |
| 656 | * implemented volume lighting system |
| 657 | * |
| 658 | * 121 5/11/98 4:40p Chris |
| 659 | * AI info is now a malloc'ed pointer |
| 660 | * |
| 661 | * 120 5/04/98 6:47p Craig |
| 662 | * Rooms cannot cycle through anims |
| 663 | * |
| 664 | * 119 5/04/98 12:30p Matt |
| 665 | * ObjCreate() now takes object id as a uint16_t |
| 666 | * |
| 667 | * 118 5/04/98 12:28p Matt |
| 668 | * Added shard objects |
| 669 | * |
| 670 | * 117 5/01/98 3:41p Chris |
| 671 | * |
| 672 | * 116 5/31/98 3:08p Chris |
| 673 | * Allowed for death animations |
| 674 | * |
| 675 | * 115 4/27/98 1:14p Jason |
| 676 | * cleaned up afterburner stuff |
| 677 | * |
| 678 | * 114 4/23/98 12:44p Jason |
| 679 | * made AI toggleable to test framerate - this is temporary |
| 680 | * |
| 681 | * 113 4/22/98 4:15p Chris |
| 682 | * Improved DebugBlockPrint |
| 683 | * |
| 684 | * 112 4/22/98 3:50p Chris |
| 685 | * Added DebugBlockPrint |
| 686 | * |
| 687 | * 111 4/22/98 2:10p Matt |
| 688 | * Made FreeAllObjects() free the player object (object 0), since objects |
| 689 | * now contain malloc'd data and must be freed. |
| 690 | * |
| 691 | * 110 4/20/98 6:24p Chris |
| 692 | * Bulletproofing collision code |
| 693 | * |
| 694 | * 109 4/19/98 5:00p Jason |
| 695 | * added cool napalm effect, plus made object effects dynamically |
| 696 | * allocated |
| 697 | * |
| 698 | * 108 4/17/98 1:59p Jason |
| 699 | * added cool object effects |
| 700 | * |
| 701 | * 107 4/16/98 2:56p Chris |
| 702 | * Updated buddy support and intergrated scripting and AI |
| 703 | * |
| 704 | * 106 4/15/98 8:38p Jason |
| 705 | * fixed some multiplayer issues |
| 706 | * |
| 707 | * 105 4/15/98 12:56p Chris |
| 708 | * Updated parent_handle support and added buddy bot support |
| 709 | * |
| 710 | * 104 4/13/98 2:21p Chris |
| 711 | * Fixed some collision problems dealing with AABBs and Polymodel paging |
| 712 | * in. |
| 713 | * |
| 714 | * 103 4/13/98 12:42p Jason |
| 715 | * changed afterburner effect |
| 716 | * |
| 717 | * 102 4/10/98 2:42p Jason |
| 718 | * fixed afterburner blobs to be a stream |
| 719 | * |
| 720 | * 101 4/10/98 2:16p Jason |
| 721 | * fixed guided missile problems |
| 722 | * |
| 723 | * 100 4/09/98 5:18p Jason |
| 724 | * got guided working in multiplayer |
| 725 | * |
| 726 | * 99 4/09/98 3:04p Jason |
| 727 | * temp fix for afterburner running out of fuel |
| 728 | * |
| 729 | * 98 4/09/98 2:23p Jason |
| 730 | * added guided/afterburner stuff |
| 731 | * |
| 732 | * 97 4/07/98 1:12p Jason |
| 733 | * make powerup respawn a variable in multiplayer games |
| 734 | * |
| 735 | * 96 4/03/98 11:04a Jason |
| 736 | * added a multplayer dll hook for when a player changes a room |
| 737 | * |
| 738 | * 95 4/01/98 6:23p Jason |
| 739 | * added a slew of stuff for multiplayer |
| 740 | * |
| 741 | * 94 3/31/98 5:56p Jason |
| 742 | * changes for multiplay |
| 743 | * |
| 744 | * 93 3/31/98 4:23p Chris |
| 745 | * Added a new AIpath system |
| 746 | * |
| 747 | * 92 3/20/98 9:34p Jason |
| 748 | * added SetObjectDeadFlag inlined function |
| 749 | * |
| 750 | * 91 3/13/98 5:55p Chris |
| 751 | * Added the new collision spheres |
| 752 | * |
| 753 | * 90 3/12/98 7:30p Chris |
| 754 | * Added ObjSetOrient |
| 755 | * |
| 756 | * 89 2/25/98 3:01p Jason |
| 757 | * added splinter objects to FreeObjects |
| 758 | * |
| 759 | * 88 2/25/98 2:05p Jason |
| 760 | * did FOV and object visibility changes |
| 761 | * |
| 762 | * 87 2/20/98 1:46p Chris |
| 763 | * JASON: Made dynamic lighting only occur if the object is rendered |
| 764 | * |
| 765 | * 86 2/19/98 11:17a Chris |
| 766 | * Tweaked the BIG_OBJECT system |
| 767 | * |
| 768 | * 85 2/17/98 3:46p Matt |
| 769 | * Revamped weapon system and got sounds for spray and fusion weapons |
| 770 | * working. Still need to implements getting continuous & cutoff sounds |
| 771 | * from player ship. |
| 772 | * |
| 773 | * 84 2/16/98 2:49p Chris |
| 774 | * Made the MAX_SUBOBJECTS determine the number of normalized_time values |
| 775 | * to be processed. No longer a 'literal' problem. |
| 776 | * |
| 777 | * 83 2/13/98 6:59p Chris |
| 778 | * FIxed the normalized_time array from being smaller than the number of |
| 779 | * subobjects. Also update newstyle_fi.cpp |
| 780 | * |
| 781 | * 82 2/12/98 8:48p Matt |
| 782 | * Changed controls system to keep the reading of the controls seperate |
| 783 | * from using the results. Got rid of the Controls global. |
| 784 | * |
| 785 | * 81 2/11/98 2:04p Jason |
| 786 | * got spawning weapons working |
| 787 | * |
| 788 | * 80 2/09/98 3:20p Matt |
| 789 | * Changed assert to allow OBJECT_HANDLE_INVALID to be pased to ObjGet() |
| 790 | * |
| 791 | * 79 2/05/98 3:00p Matt |
| 792 | * Made ObjSetPos() take optional orienation. Got rid of unlink & relink |
| 793 | * funcs from header. |
| 794 | * |
| 795 | * 78 2/04/98 6:09p Matt |
| 796 | * Changed object room number to indicate a terrain cell via a flag. Got |
| 797 | * rid of the object flag which used to indicate terrain. |
| 798 | * |
| 799 | * 77 2/03/98 1:06p Jason |
| 800 | * tidied up some multiplayer loose ends |
| 801 | * |
| 802 | * 76 1/30/98 5:26p Chris |
| 803 | * Allow all non-AI objects to animate |
| 804 | * |
| 805 | * 75 1/29/98 5:49p Matt |
| 806 | * Changed old camera object type to be viewer object (for editor), and |
| 807 | * now camera objects will just be for game cameras. |
| 808 | * |
| 809 | * 74 1/27/98 12:26p Samir |
| 810 | * Added GetObjectPointInWorld. |
| 811 | * |
| 812 | * 73 1/23/98 11:21a Jason |
| 813 | * incremental multiplayer checkin |
| 814 | * |
| 815 | * 72 1/21/98 1:11p Jason |
| 816 | * incremental checkin for multiplayer |
| 817 | * |
| 818 | * 71 1/20/98 6:01p Jason |
| 819 | * first pass at getting multiplayer deaths working |
| 820 | * |
| 821 | * 70 1/20/98 4:12p Samir |
| 822 | * New script housekeeping system. |
| 823 | * |
| 824 | * 69 1/20/98 12:27p Luke |
| 825 | * Added an assert to make sure that we are not linking to an external |
| 826 | * room |
| 827 | * |
| 828 | * 68 1/20/98 12:10p Jason |
| 829 | * implemented vis effect system |
| 830 | * |
| 831 | * 67 1/19/98 2:44p Samir |
| 832 | * Use one script per object and started parameter passing support. |
| 833 | * |
| 834 | * 66 1/19/98 12:38p Jason |
| 835 | * took out mprintf in ObjCreate |
| 836 | * |
| 837 | * 65 1/19/98 10:04a Matt |
| 838 | * Added new object handle system |
| 839 | * |
| 840 | * 64 1/15/98 6:49p Jason |
| 841 | * incremental checkin for multiplayer |
| 842 | * |
| 843 | * 63 12/30/97 5:45p Jason |
| 844 | * added toggleable fog |
| 845 | * |
| 846 | * 62 12/19/97 2:46p Jason |
| 847 | * implemented bitmap paging routines |
| 848 | * |
| 849 | * 61 12/12/97 3:42p Jason |
| 850 | * free all objects on shutdown |
| 851 | * |
| 852 | * 60 12/01/97 9:56a Chris |
| 853 | * Removed FLARE and CNTRL_CENTER types |
| 854 | * |
| 855 | * 59 11/10/97 12:27p Jason |
| 856 | * added objects live mprintf |
| 857 | * |
| 858 | * 58 10/28/97 12:22p Chris |
| 859 | * Added a movement type of walking |
| 860 | * |
| 861 | * 57 10/23/97 5:36p Jason |
| 862 | * added splinter objects (probably temporary) |
| 863 | * |
| 864 | * 56 10/22/97 5:14p Chris |
| 865 | * Allow for non-AI objects to animate |
| 866 | * |
| 867 | * 55 10/20/97 4:46p Jason |
| 868 | * changes for explosions |
| 869 | * |
| 870 | * 54 10/14/97 6:53p Chris |
| 871 | * Added the initial SOAR support |
| 872 | * |
| 873 | * 53 10/08/97 6:35p Samir |
| 874 | * Dying player ships get marked as destroyed. When death sequence is |
| 875 | * over, they are marked as dead. This is needed to better control |
| 876 | * movement of the dying ship. |
| 877 | * |
| 878 | * 52 10/03/97 5:18p Chris |
| 879 | * Added OBJ_LINE as a new type |
| 880 | * |
| 881 | * 51 10/02/97 1:04p Jason |
| 882 | * implemented FreeAllObjects |
| 883 | * |
| 884 | * 50 10/01/97 7:51p Matt |
| 885 | * Added code for external rooms |
| 886 | * |
| 887 | * 49 9/30/97 6:40p Jason |
| 888 | * got lightmap stuff sort of working with objects |
| 889 | * |
| 890 | * 48 9/22/97 6:20p Matt |
| 891 | * Killed include of stub.h, and removed references to stuff that had been |
| 892 | * in stub.h |
| 893 | * |
| 894 | * 47 9/19/97 6:58p Chris |
| 895 | * Fixed some bugs with the big object system and removed some annoying |
| 896 | * mprintf's |
| 897 | * |
| 898 | * 46 9/19/97 1:01p Chris |
| 899 | * Better big object support |
| 900 | * |
| 901 | * 45 9/18/97 1:25p Matt |
| 902 | * Cleaned up code, added the text name for door objects, and other small |
| 903 | * changes. |
| 904 | * |
| 905 | * 44 9/17/97 11:16a Matt |
| 906 | * Ripped out segment code |
| 907 | * |
| 908 | * 43 9/16/97 5:04p Matt |
| 909 | * Changed conditional for debug code |
| 910 | * |
| 911 | * 42 9/15/97 12:42p Samir |
| 912 | * Added include of stdlib. |
| 913 | * |
| 914 | * 41 9/15/97 5:21a Chris |
| 915 | * Added sphere2poly support |
| 916 | * |
| 917 | * 40 9/12/97 6:36p Chris |
| 918 | * Added collision terrain segment support |
| 919 | * Added some LARGE OBJECT collision support |
| 920 | * |
| 921 | * 39 9/12/97 10:12a Matt |
| 922 | * Added trigger check |
| 923 | * |
| 924 | * 38 9/05/97 3:22p Jason |
| 925 | * changes for lit objects |
| 926 | * |
| 927 | * 37 9/05/97 1:29p Jason |
| 928 | * revamped generic object lighting |
| 929 | * |
| 930 | * 36 9/05/97 12:26p Samir |
| 931 | * Player initiates death sequence if killed. |
| 932 | * |
| 933 | * 35 9/04/97 5:26p Jason |
| 934 | * got pulsing objects to work |
| 935 | * |
| 936 | * 34 9/04/97 12:11p Jason |
| 937 | * added flickering generic objects |
| 938 | * |
| 939 | * 33 9/03/97 6:17p Jason |
| 940 | * added code to support powerups/robots/etc that cast light |
| 941 | * |
| 942 | * 32 9/03/97 3:53p Jason |
| 943 | * got objects to cast light |
| 944 | * |
| 945 | * 31 8/25/97 7:32p Chris |
| 946 | * |
| 947 | * 30 8/25/97 6:18p Chris |
| 948 | * |
| 949 | * 29 8/25/97 5:14p Craig |
| 950 | * |
| 951 | * 28 8/25/97 12:41p Chris |
| 952 | * Made sure that all object movements and mine changes result in AABB |
| 953 | * updates. |
| 954 | * |
| 955 | * 27 8/22/97 10:51a Samir |
| 956 | * call destroy script if object is being killed. |
| 957 | * |
| 958 | * 26 8/21/97 7:47p Matt |
| 959 | * ObjSetPos() wasn't relinking the object when the room changed |
| 960 | * |
| 961 | * 25 8/21/97 5:57p Samir |
| 962 | * Added code that kills scripts when object is being deleted. |
| 963 | * |
| 964 | * 24 8/20/97 5:04p Samir |
| 965 | * Added frame interval scripting. |
| 966 | * |
| 967 | * 23 8/18/97 1:45a Chris |
| 968 | * Fix some bugs. |
| 969 | * |
| 970 | * 22 8/12/97 3:56p Matt |
| 971 | * Added new object type: OBJ_BUILDING |
| 972 | * |
| 973 | * 21 8/12/97 1:13p Chris |
| 974 | * Added AABBs. |
| 975 | * |
| 976 | * 20 8/11/97 6:48p Matt |
| 977 | * Rewrote static object remap system |
| 978 | * |
| 979 | * 19 8/11/97 1:53p Matt |
| 980 | * Ripped out robot & powerup pages, and added generic page |
| 981 | * |
| 982 | * 18 8/04/97 5:29p Matt |
| 983 | * Removed some not-to-be-used room code |
| 984 | * |
| 985 | * 17 8/04/97 4:08p Matt |
| 986 | * Added ObjSetPos() that takes the new room number |
| 987 | * |
| 988 | * 16 8/04/97 12:37p Chris |
| 989 | * We now support fvi in Rooms :) |
| 990 | * |
| 991 | * 15 7/29/97 10:27a Jason |
| 992 | * added RenderOBject abstraction layer |
| 993 | * |
| 994 | * 14 7/28/97 1:14p Chris |
| 995 | * Added support for sub-object visability. Plus, debris. |
| 996 | * |
| 997 | * 13 7/16/97 4:09p Jason |
| 998 | * ripped out temporary object lighting |
| 999 | * |
| 1000 | * |
| 1001 | * 12 7/16/97 3:43p Jason |
| 1002 | * took off lighting of objects |
| 1003 | * |
| 1004 | * 11 7/15/97 5:32p Jason |
| 1005 | * got simple static lighting working with objects |
| 1006 | * |
| 1007 | * 10 7/15/97 4:59p Chris |
| 1008 | * |
| 1009 | * 9 7/15/97 4:59p Chris |
| 1010 | * added support for AI and animations |
| 1011 | * |
| 1012 | * 50 6/24/97 6:54p Mark |
| 1013 | * |
| 1014 | * 49 6/24/97 6:07p Matt |
| 1015 | * Use DrawPolygonModel() directly, instead of DrawPolygonObject() |
| 1016 | * |
| 1017 | * 48 6/06/97 4:07p Jason |
| 1018 | * verify tmap2 textures if in editor mode |
| 1019 | * |
| 1020 | * 47 5/16/97 2:17p Samir |
| 1021 | * ResetPlayerObject added. |
| 1022 | * |
| 1023 | * 46 5/15/97 6:09p Chris |
| 1024 | * |
| 1025 | * 45 5/14/97 3:41p Chris |
| 1026 | * |
| 1027 | * 44 5/14/97 12:32p Matt |
| 1028 | * Took out timer stuff for refuel sound; instead, we set the execlusive |
| 1029 | * flag for the sound itself. |
| 1030 | * |
| 1031 | * 43 5/13/97 10:31p Matt |
| 1032 | * Added code for refueling centers. |
| 1033 | * Dead objects now get deleted right after the simulation is done. |
| 1034 | * |
| 1035 | * 42 4/30/97 5:43p Jason |
| 1036 | * remap polymodels when pagefile is done loading |
| 1037 | * |
| 1038 | * 41 4/24/97 5:42p Jason |
| 1039 | * got fireball vclips working |
| 1040 | * |
| 1041 | * 40 4/17/97 2:48p Samir |
| 1042 | * ReadFlyingControls renamed from read_flying_controls to match naming |
| 1043 | * convention rules. |
| 1044 | * |
| 1045 | * 39 4/14/97 4:23p Jason |
| 1046 | * made objects work with DrawWeaponObject |
| 1047 | * |
| 1048 | * 38 4/14/97 3:48p Jason |
| 1049 | * changed RT_LASER to RT_WEAPON |
| 1050 | * |
| 1051 | * 37 4/04/97 4:33p Chris |
| 1052 | * |
| 1053 | * 36 4/04/97 2:45p Matt |
| 1054 | * Removed prototypes for deleted functions |
| 1055 | * |
| 1056 | * 35 4/02/97 3:44p Matt |
| 1057 | * Find a valid Ships[] entry, instead of assuming that Ships[0] is valid. |
| 1058 | * |
| 1059 | * 34 4/02/97 2:26p Jason |
| 1060 | * made RemapEverything actually call every remap function |
| 1061 | * |
| 1062 | * 33 4/01/97 10:49p Matt |
| 1063 | * Get player ship model num from Ship page |
| 1064 | * |
| 1065 | * 32 3/27/97 10:45a Chris |
| 1066 | * Set player mass and drag info |
| 1067 | * |
| 1068 | * 31 3/26/97 3:29p Jason |
| 1069 | * made robots work/render |
| 1070 | * |
| 1071 | * 30 3/26/97 3:02p Chris |
| 1072 | * Fixed a bug in ObjMoveAll... It only moved every other object. |
| 1073 | * |
| 1074 | * 29 3/24/97 4:11p Chris |
| 1075 | * Fixed a bug by the TerrainMaster... It seems that !obj->flags & |
| 1076 | * OF_OVER_TERRAIN is not the same as !(obj->flags & OF_OVER_TERRAIN) and |
| 1077 | * it isn't and shouldn't be. :) |
| 1078 | * |
| 1079 | * 28 3/21/97 5:01p Jason |
| 1080 | * incremental terrain improvments |
| 1081 | * |
| 1082 | * |
| 1083 | * 27 3/20/97 5:45p Jason |
| 1084 | * made object work with and render on terrain |
| 1085 | * |
| 1086 | * 26 3/17/97 12:11p Chris |
| 1087 | * |
| 1088 | * 25 3/17/97 11:56a Chris |
| 1089 | * Forced player object to have valid mass and drag. Will fix this |
| 1090 | * correctly at a later date. |
| 1091 | * |
| 1092 | * 24 3/14/97 12:18p Chris |
| 1093 | * Tweak physics and remove braking for now. |
| 1094 | * |
| 1095 | * 23 3/12/97 6:31p Chris |
| 1096 | * Added player flight controls while in game |
| 1097 | * |
| 1098 | * 22 3/05/97 3:09p Jason |
| 1099 | * added RemapDoors to RemapEverything |
| 1100 | * |
| 1101 | * 21 3/5/97 1:40 PM Jeremy |
| 1102 | * only #include editor headers when EDITOR is defined |
| 1103 | * |
| 1104 | * 20 2/28/97 2:37p Matt |
| 1105 | * Draw wireframe box around editor's current object |
| 1106 | * |
| 1107 | * 19 2/27/97 5:10p Samir |
| 1108 | * Added crude trigger checking while flying. |
| 1109 | * |
| 1110 | * 18 2/18/97 6:31p Matt |
| 1111 | * Changed Frame_time to Frametime, & added Gametime |
| 1112 | * |
| 1113 | * 17 2/13/97 12:16p Jason |
| 1114 | * changes for powerup remapping |
| 1115 | * |
| 1116 | * 16 2/12/97 5:37p Jason |
| 1117 | * changed GamePowerups to Powerups to keep from |
| 1118 | * getting lynched |
| 1119 | * |
| 1120 | * 15 2/11/97 6:51p Matt |
| 1121 | * Ripped out some old stuff & renamed a function |
| 1122 | * |
| 1123 | * 14 2/10/97 5:39p Matt |
| 1124 | * Fixed to compile with EDITOR defined |
| 1125 | * |
| 1126 | * 13 2/07/97 5:48p Matt |
| 1127 | * Renamed vector.h to vecmat.h to fix DevStudio problem |
| 1128 | * |
| 1129 | * $NoKeywords: $ |
| 1130 | */ |
| 1131 | |
| 1132 | #include <stdlib.h> |
| 1133 | #include <string.h> // for memset |
| 1134 | #include <stdio.h> |
| 1135 | |
| 1136 | #include "object.h" |
| 1137 | |
| 1138 | #include "pserror.h" |
| 1139 | #include "vecmat.h" |
| 1140 | #include "mono.h" |
| 1141 | |
| 1142 | #include "descent.h" |
| 1143 | #include "player.h" |
| 1144 | #include "slew.h" |
| 1145 | #include "game.h" |
| 1146 | #include "trigger.h" |
| 1147 | #include "physics.h" |
| 1148 | #include "collide.h" |
| 1149 | #include "door.h" |
| 1150 | #include "controls.h" |
| 1151 | #include "terrain.h" |
| 1152 | #include "polymodel.h" |
| 1153 | #include "gametexture.h" |
| 1154 | #include "ship.h" |
| 1155 | #include "soundload.h" |
| 1156 | #include "weapon.h" |
| 1157 | #include "objinit.h" |
| 1158 | #include "fireball.h" |
| 1159 | #include "hlsoundlib.h" |
| 1160 | #include "sounds.h" |
| 1161 | #include "AIMain.h" |
| 1162 | #include "room.h" |
| 1163 | #include "objinfo.h" |
| 1164 | #include "lighting.h" |
| 1165 | #include "findintersection.h" |
| 1166 | #include "lightmap_info.h" |
| 1167 | #include "object_lighting.h" |
| 1168 | #include "soar.h" |
| 1169 | #include "splinter.h" |
| 1170 | #include "ObjScript.h" |
| 1171 | #include "viseffect.h" |
| 1172 | #include "multi.h" |
| 1173 | #include "game2dll.h" |
| 1174 | #include "robot.h" |
| 1175 | #include "damage.h" |
| 1176 | #include "attach.h" |
| 1177 | #include "dedicated_server.h" |
| 1178 | #include "hud.h" |
| 1179 | #include "demofile.h" |
| 1180 | #include "rtperformance.h" |
| 1181 | #include "osiris_dll.h" |
| 1182 | #include "gameloop.h" |
| 1183 | #include "mem.h" |
| 1184 | #include "stringtable.h" |
| 1185 | #include "levelgoal.h" |
| 1186 | #include "psrand.h" |
| 1187 | |
| 1188 | #ifdef EDITOR |
| 1189 | #include "editor\d3edit.h" |
| 1190 | #endif |
| 1191 | |
| 1192 | #include <algorithm> |
| 1193 | |
| 1194 | /* |
| 1195 | * Global variables |
| 1196 | */ |
| 1197 | |
| 1198 | object *Player_object = NULL; // the object that is the player |
| 1199 | object *Viewer_object = NULL; // which object we are seeing from |
| 1200 | |
| 1201 | static int16_t free_obj_list[MAX_OBJECTS]; |
| 1202 | |
| 1203 | // Data for objects |
| 1204 | |
| 1205 | // -- Object stuff |
| 1206 | |
| 1207 | // info on the various types of objects |
| 1208 | |
| 1209 | object Objects[MAX_OBJECTS]; |
| 1210 | |
| 1211 | tPosHistory Object_position_samples[MAX_OBJECT_POS_HISTORY]; |
| 1212 | uint8_t Object_position_head; |
| 1213 | int16_t Object_map_position_history[MAX_OBJECTS]; |
| 1214 | int16_t Object_map_position_free_slots[MAX_OBJECT_POS_HISTORY]; |
| 1215 | uint16_t Num_free_object_position_history; |
| 1216 | |
| 1217 | int Num_objects = 0; |
| 1218 | int Highest_object_index = 0; |
| 1219 | int Highest_ever_object_index = 0; |
| 1220 | |
| 1221 | int print_object_info = 0; |
| 1222 | |
| 1223 | #ifdef EDITOR |
| 1224 | // This array matches the object types in object.h |
| 1225 | char *Object_type_names[MAX_OBJECT_TYPES] = { |
| 1226 | "WALL", // OBJ_WALL 0 |
| 1227 | "FIREBALL", // OBJ_FIREBALL 1 |
| 1228 | "ROBOT", // OBJ_ROBOT 2 |
| 1229 | "SHARD", // OBJ_SHARD 3 |
| 1230 | "PLAYER", // OBJ_PLAYER 4 |
| 1231 | "WEAPON", // OBJ_WEAPON 5 |
| 1232 | "VIEWER", // OBJ_VIEWER 6 |
| 1233 | "POWERUP", // OBJ_POWERUP 7 |
| 1234 | "DEBRIS", // OBJ_DEBRIS 8 |
| 1235 | "CAMERA", // OBJ_CAMERA 9 |
| 1236 | "SHOCKWV", // OBJ_SHOCKWAVE 10 |
| 1237 | "CLUTTER", // OBJ_CLUTTER 11 |
| 1238 | "GHOST", // OBJ_GHOST 12 |
| 1239 | "LIGHT", // OBJ_LIGHT 13 |
| 1240 | "COOP", // OBJ_COOP 14 |
| 1241 | "UNUSED", // OBJ_MARKER 15 |
| 1242 | "BUILDING", // OBJ_BUILDING 16 |
| 1243 | "DOOR", // OBJ_DOOR 17 |
| 1244 | "ROOM", // OBJ_ROOM 18 |
| 1245 | "LINE", // OBJ_PARTICLE 19 |
| 1246 | "SPLINTER", // OBJ_SPLINTER 20 |
| 1247 | "DUMMY", // OBJ_DUMMY 21 |
| 1248 | "OBSERVER", // OBJ_OBSERVER 22 |
| 1249 | "DEBUG LINE", // OBJ_DEBUG_LINE 23 |
| 1250 | "SOUNDSOURCE", // OBJ_SOUNDSOURCE 24 |
| 1251 | "WAYPOINT", // OBJ_WAYPOINT 25 |
| 1252 | }; |
| 1253 | #endif |
| 1254 | |
| 1255 | int Num_big_objects = 0; |
| 1256 | int16_t BigObjectList[MAX_BIG_OBJECTS]; // DAJ_MR utb int |
| 1257 | |
| 1258 | /* |
| 1259 | * Local Function Prototypes |
| 1260 | */ |
| 1261 | |
| 1262 | // Do refueling centers & damage rooms |
| 1263 | void DoSpecialPlayerStuff(object *obj); |
| 1264 | |
| 1265 | /* |
| 1266 | * Functions |
| 1267 | */ |
| 1268 | |
| 1269 | #ifndef RELEASE |
| 1270 | // set viewer object to next object in array |
| 1271 | void ObjGotoNextViewer() { |
| 1272 | int i, start_obj = 0; |
| 1273 | |
| 1274 | start_obj = Viewer_object - Objects; // get viewer object number |
| 1275 | |
| 1276 | for (i = 0; i <= Highest_object_index; i++) { |
| 1277 | |
| 1278 | start_obj++; |
| 1279 | if (start_obj > Highest_object_index) |
| 1280 | start_obj = 0; |
| 1281 | |
| 1282 | if (Objects[start_obj].type != OBJ_NONE) { |
| 1283 | Viewer_object = &Objects[start_obj]; |
| 1284 | return; |
| 1285 | } |
| 1286 | } |
| 1287 | |
| 1288 | Error("Couldn't find a viewer object!"); |
| 1289 | } |
| 1290 | |
| 1291 | // set viewer object to next object in array |
| 1292 | void obj_goto_prev_viewer() { |
| 1293 | int i, start_obj = 0; |
| 1294 | |
| 1295 | start_obj = Viewer_object - Objects; // get viewer object number |
| 1296 | |
| 1297 | for (i = 0; i <= Highest_object_index; i++) { |
| 1298 | |
| 1299 | start_obj--; |
| 1300 | if (start_obj < 0) |
| 1301 | start_obj = Highest_object_index; |
| 1302 | |
| 1303 | if (Objects[start_obj].type != OBJ_NONE) { |
| 1304 | Viewer_object = &Objects[start_obj]; |
| 1305 | return; |
| 1306 | } |
| 1307 | } |
| 1308 | |
| 1309 | Error("Couldn't find a viewer object!"); |
| 1310 | } |
| 1311 | #endif |
| 1312 | |
| 1313 | object *obj_find_first_of_type(int type) { |
| 1314 | int i; |
| 1315 | |
| 1316 | for (i = 0; i <= Highest_object_index; i++) |
| 1317 | if (Objects[i].type == type) |
| 1318 | return (&Objects[i]); |
| 1319 | |
| 1320 | return NULL; |
| 1321 | } |
| 1322 | |
| 1323 | int obj_return_num_of_type(int type) { |
| 1324 | int i, count = 0; |
| 1325 | |
| 1326 | for (i = 0; i <= Highest_object_index; i++) |
| 1327 | if (Objects[i].type == type) |
| 1328 | count++; |
| 1329 | |
| 1330 | return (count); |
| 1331 | } |
| 1332 | |
| 1333 | int obj_return_num_of_typeid(int type, int id) { |
| 1334 | int i, count = 0; |
| 1335 | |
| 1336 | for (i = 0; i <= Highest_object_index; i++) |
| 1337 | if (Objects[i].type == type && Objects[i].id == id) |
| 1338 | count++; |
| 1339 | |
| 1340 | return (count); |
| 1341 | } |
| 1342 | |
| 1343 | int ObjAllocate(void); |
| 1344 | |
| 1345 | // Creates the player object in the center of the given room |
| 1346 | void CreatePlayerObject(int roomnum) { |
| 1347 | int objnum; |
| 1348 | vector pos; |
| 1349 | |
| 1350 | ComputeRoomCenter(&pos, &Rooms[roomnum]); |
| 1351 | |
| 1352 | objnum = ObjCreate(OBJ_PLAYER, 0, roomnum, &pos, NULL); |
| 1353 | |
| 1354 | ASSERT(objnum == 0); // player must be object 0 |
| 1355 | |
| 1356 | Player_object = Viewer_object = &Objects[objnum]; |
| 1357 | } |
| 1358 | |
| 1359 | void InitBigObjects() { Num_big_objects = 0; } |
| 1360 | |
| 1361 | void BigObjAdd(int objnum) { |
| 1362 | ASSERT(Num_big_objects < MAX_BIG_OBJECTS); |
| 1363 | if (Num_big_objects >= MAX_BIG_OBJECTS) { |
| 1364 | Int3(); |
| 1365 | return; |
| 1366 | } |
| 1367 | |
| 1368 | Objects[objnum].flags |= OF_BIG_OBJECT; |
| 1369 | BigObjectList[Num_big_objects++] = objnum; |
| 1370 | } |
| 1371 | |
| 1372 | void BigObjRemove(int objnum) { |
| 1373 | int i; |
| 1374 | |
| 1375 | Objects[objnum].flags &= (~OF_BIG_OBJECT); |
| 1376 | |
| 1377 | for (i = 0; i < Num_big_objects; i++) { |
| 1378 | if (BigObjectList[i] == objnum) { |
| 1379 | Num_big_objects--; |
| 1380 | break; |
| 1381 | } |
| 1382 | } |
| 1383 | |
| 1384 | while (i < Num_big_objects) { |
| 1385 | BigObjectList[i] = BigObjectList[i + 1]; |
| 1386 | i++; |
| 1387 | } |
| 1388 | |
| 1389 | ASSERT(Num_big_objects < MAX_BIG_OBJECTS); |
| 1390 | ASSERT(Num_big_objects >= 0); |
| 1391 | } |
| 1392 | |
| 1393 | // Resets the object list: sets all objects to unused, intializes handles, & sets roomnums to -1 |
| 1394 | // Called by the editor to init a new level. |
| 1395 | void ResetObjectList() { |
| 1396 | int i; |
| 1397 | |
| 1398 | // Init data for each object |
| 1399 | for (i = 0; i < MAX_OBJECTS; i++) { |
| 1400 | Objects[i].handle = i; |
| 1401 | Objects[i].type = OBJ_NONE; |
| 1402 | Objects[i].roomnum = -1; |
| 1403 | } |
| 1404 | |
| 1405 | // Build the free object list |
| 1406 | ResetFreeObjects(); |
| 1407 | |
| 1408 | // Say no big objects |
| 1409 | InitBigObjects(); |
| 1410 | |
| 1411 | ObjResetPositionHistory(); |
| 1412 | } |
| 1413 | |
| 1414 | // sets up the free list & init player & whatever else |
| 1415 | void InitObjects() { |
| 1416 | int i; |
| 1417 | |
| 1418 | // Initialize the collision system |
| 1419 | CollideInit(); |
| 1420 | |
| 1421 | // Mark all the objects as unused |
| 1422 | ResetObjectList(); |
| 1423 | |
| 1424 | // Make sure no rooms are using any objects |
| 1425 | for (i = 0; i < MAX_ROOMS; i++) { |
| 1426 | Rooms[i].objects = -1; |
| 1427 | Rooms[i].vis_effects = -1; |
| 1428 | } |
| 1429 | |
| 1430 | InitVisEffects(); |
| 1431 | |
| 1432 | atexit(FreeAllObjects); |
| 1433 | } |
| 1434 | |
| 1435 | // link the object into the list for its room |
| 1436 | void ObjLink(int objnum, int roomnum) { |
| 1437 | object *obj = &Objects[objnum]; |
| 1438 | |
| 1439 | ASSERT(objnum != -1); |
| 1440 | |
| 1441 | ASSERT(obj->roomnum == -1); |
| 1442 | ASSERT(!(obj->flags & OF_BIG_OBJECT)); |
| 1443 | |
| 1444 | if ((obj->size >= MIN_BIG_OBJ_RAD) && (!ROOMNUM_OUTSIDE(roomnum))) { |
| 1445 | BigObjAdd(objnum); |
| 1446 | } |
| 1447 | |
| 1448 | obj->roomnum = roomnum; |
| 1449 | |
| 1450 | if (ROOMNUM_OUTSIDE(roomnum)) { |
| 1451 | int cellnum = CELLNUM(roomnum); |
| 1452 | |
| 1453 | obj->next = Terrain_seg[cellnum].objects; |
| 1454 | Terrain_seg[cellnum].objects = objnum; |
| 1455 | |
| 1456 | ASSERT(obj->next != objnum); |
| 1457 | } else { |
| 1458 | ASSERT(roomnum >= 0 && roomnum <= Highest_room_index); |
| 1459 | ASSERT(!(Rooms[roomnum].flags & RF_EXTERNAL)); |
| 1460 | |
| 1461 | obj->next = Rooms[roomnum].objects; |
| 1462 | Rooms[roomnum].objects = objnum; |
| 1463 | ASSERT(obj->next != objnum); |
| 1464 | } |
| 1465 | |
| 1466 | obj->prev = -1; |
| 1467 | |
| 1468 | if (obj->next != -1) |
| 1469 | Objects[obj->next].prev = objnum; |
| 1470 | |
| 1471 | ASSERT(Objects[0].next != 0); |
| 1472 | if (Objects[0].next == 0) |
| 1473 | Objects[0].next = -1; |
| 1474 | |
| 1475 | ASSERT(Objects[0].prev != 0); |
| 1476 | if (Objects[0].prev == 0) |
| 1477 | Objects[0].prev = -1; |
| 1478 | } |
| 1479 | |
| 1480 | void ObjUnlink(int objnum) { |
| 1481 | object *obj = &Objects[objnum]; |
| 1482 | |
| 1483 | ASSERT(objnum != -1); |
| 1484 | |
| 1485 | // If object is already unlinked, do nothing |
| 1486 | if (obj->roomnum == -1) { |
| 1487 | return; |
| 1488 | } |
| 1489 | |
| 1490 | if (obj->flags & OF_BIG_OBJECT) { |
| 1491 | BigObjRemove(objnum); |
| 1492 | } |
| 1493 | |
| 1494 | if (OBJECT_OUTSIDE(obj)) { |
| 1495 | int cellnum = CELLNUM(obj->roomnum); |
| 1496 | |
| 1497 | terrain_segment *seg = &Terrain_seg[cellnum]; |
| 1498 | |
| 1499 | if (obj->prev == -1) |
| 1500 | seg->objects = obj->next; |
| 1501 | else |
| 1502 | Objects[obj->prev].next = obj->next; |
| 1503 | |
| 1504 | if (obj->next != -1) |
| 1505 | Objects[obj->next].prev = obj->prev; |
| 1506 | } else { |
| 1507 | room *rp = &Rooms[obj->roomnum]; |
| 1508 | |
| 1509 | if (obj->prev == -1) |
| 1510 | rp->objects = obj->next; |
| 1511 | else |
| 1512 | Objects[obj->prev].next = obj->next; |
| 1513 | |
| 1514 | if (obj->next != -1) |
| 1515 | Objects[obj->next].prev = obj->prev; |
| 1516 | } |
| 1517 | |
| 1518 | // Mark as not linked |
| 1519 | obj->roomnum = -1; |
| 1520 | |
| 1521 | ASSERT(Objects[0].next != 0); |
| 1522 | ASSERT(Objects[0].prev != 0); |
| 1523 | } |
| 1524 | |
| 1525 | //----------------------------------------------------------------------------- |
| 1526 | // Scan the object list, freeing down to num_used objects |
| 1527 | // Returns number of slots freed. |
| 1528 | int FreeObjectSlots(int num_used) { |
| 1529 | int i, olind; |
| 1530 | int obj_list[MAX_OBJECTS]; |
| 1531 | int num_already_free, num_to_free, original_num_to_free; |
| 1532 | |
| 1533 | olind = 0; |
| 1534 | num_already_free = MAX_OBJECTS - Highest_object_index - 1; |
| 1535 | |
| 1536 | if (MAX_OBJECTS - num_already_free < num_used) { |
| 1537 | return 0; |
| 1538 | } |
| 1539 | |
| 1540 | for (i = 0; i <= Highest_object_index; i++) { |
| 1541 | if (Objects[i].flags & OF_DEAD) { |
| 1542 | num_already_free++; |
| 1543 | if (MAX_OBJECTS - num_already_free < num_used) |
| 1544 | return num_already_free; |
| 1545 | } else { |
| 1546 | switch (Objects[i].type) { |
| 1547 | case OBJ_NONE: |
| 1548 | num_already_free++; |
| 1549 | if (MAX_OBJECTS - num_already_free < num_used) |
| 1550 | return 0; |
| 1551 | break; |
| 1552 | case OBJ_WALL: |
| 1553 | Int3(); // This is curious. What is an object that is a wall? |
| 1554 | break; |
| 1555 | case OBJ_FIREBALL: |
| 1556 | case OBJ_WEAPON: |
| 1557 | case OBJ_DEBRIS: |
| 1558 | case OBJ_SPLINTER: |
| 1559 | obj_list[olind++] = i; |
| 1560 | break; |
| 1561 | default: |
| 1562 | break; |
| 1563 | } |
| 1564 | } |
| 1565 | } |
| 1566 | |
| 1567 | num_to_free = MAX_OBJECTS - num_used - num_already_free; |
| 1568 | original_num_to_free = num_to_free; |
| 1569 | |
| 1570 | if (num_to_free > olind) { |
| 1571 | mprintf(1, "Warning: Asked to free %i objects, but can only free %i.\n", num_to_free, olind); |
| 1572 | num_to_free = olind; |
| 1573 | } |
| 1574 | |
| 1575 | for (i = 0; i < num_to_free; i++) |
| 1576 | if (Objects[obj_list[i]].type == OBJ_DEBRIS) { |
| 1577 | num_to_free--; |
| 1578 | mprintf(0, "Freeing DEBRIS object %3i\n", obj_list[i]); |
| 1579 | SetObjectDeadFlag(&Objects[obj_list[i]]); |
| 1580 | } |
| 1581 | |
| 1582 | if (!num_to_free) |
| 1583 | return original_num_to_free; |
| 1584 | |
| 1585 | if (!num_to_free) |
| 1586 | return original_num_to_free; |
| 1587 | |
| 1588 | //@@for (i=0; i<num_to_free; i++) |
| 1589 | //@@ if ((Objects[obj_list[i]].type == OBJ_WEAPON)&& (Objects[obj_list[i]].id == FLARE_ID)) { |
| 1590 | //@@ num_to_free--; |
| 1591 | //@@ Objects[obj_list[i]].flags |= OF_DEAD; |
| 1592 | //@@ } |
| 1593 | |
| 1594 | if (!num_to_free) |
| 1595 | return original_num_to_free; |
| 1596 | |
| 1597 | for (i = 0; i < num_to_free; i++) |
| 1598 | if (Objects[obj_list[i]].type == OBJ_WEAPON) { |
| 1599 | num_to_free--; |
| 1600 | mprintf(0, "Freeing WEAPON object %3i\n", obj_list[i]); |
| 1601 | SetObjectDeadFlag(&Objects[obj_list[i]]); |
| 1602 | } |
| 1603 | |
| 1604 | return original_num_to_free - num_to_free; |
| 1605 | } |
| 1606 | |
| 1607 | // returns the number of a free object, updating Highest_object_index. |
| 1608 | // Generally, ObjCreate() should be called to get an object, since it |
| 1609 | // fills in important fields and does the linking. |
| 1610 | // returns -1 if no free objects |
| 1611 | int ObjAllocate(void) { |
| 1612 | int objnum; |
| 1613 | |
| 1614 | if (Num_objects >= MAX_OBJECTS - 2) { |
| 1615 | int num_freed; |
| 1616 | |
| 1617 | num_freed = FreeObjectSlots(MAX_OBJECTS - 10); |
| 1618 | mprintf(0, " *** Freed %i objects in frame %i\n", num_freed, FrameCount); |
| 1619 | } |
| 1620 | |
| 1621 | if (Num_objects >= MAX_OBJECTS) { |
| 1622 | mprintf(1, "Object creation failed - too many objects!\n"); |
| 1623 | return -1; |
| 1624 | } |
| 1625 | |
| 1626 | objnum = free_obj_list[Num_objects++]; |
| 1627 | |
| 1628 | if (objnum > Highest_object_index) { |
| 1629 | Highest_object_index = objnum; |
| 1630 | if (Highest_object_index > Highest_ever_object_index) { |
| 1631 | Highest_ever_object_index = Highest_object_index; |
| 1632 | mprintf(0, "Highest ever Object %d\n", Highest_ever_object_index); |
| 1633 | } |
| 1634 | } |
| 1635 | |
| 1636 | return objnum; |
| 1637 | } |
| 1638 | |
| 1639 | // frees up an object. Generally, ObjDelete() should be called to get |
| 1640 | // rid of an object. This function deallocates the object entry after |
| 1641 | // the object has been unlinked |
| 1642 | void ObjFree(int objnum) { |
| 1643 | ObjFreePositionHistory(&Objects[objnum]); |
| 1644 | |
| 1645 | free_obj_list[--Num_objects] = objnum; |
| 1646 | ASSERT(Num_objects >= 0); |
| 1647 | |
| 1648 | if (objnum == Highest_object_index) |
| 1649 | while (Objects[--Highest_object_index].type == OBJ_NONE) |
| 1650 | ; |
| 1651 | } |
| 1652 | |
| 1653 | void ObjSetAABB(object *obj) { |
| 1654 | vector object_rad; |
| 1655 | |
| 1656 | if (obj->type == OBJ_ROOM) { |
| 1657 | obj->min_xyz = Rooms[obj->id].min_xyz; |
| 1658 | obj->max_xyz = Rooms[obj->id].max_xyz; |
| 1659 | } else if (obj->flags & OF_POLYGON_OBJECT && obj->type != OBJ_WEAPON && obj->type != OBJ_DEBRIS && |
| 1660 | obj->type != OBJ_POWERUP && obj->type != OBJ_PLAYER) { |
| 1661 | vector offset_pos; |
| 1662 | |
| 1663 | object_rad.x = object_rad.y = object_rad.z = Poly_models[obj->rtype.pobj_info.model_num].anim_size; |
| 1664 | offset_pos = obj->pos + obj->anim_sphere_offset; |
| 1665 | |
| 1666 | obj->min_xyz = offset_pos - object_rad; |
| 1667 | obj->max_xyz = offset_pos + object_rad; |
| 1668 | } else { |
| 1669 | object_rad.x = obj->size; |
| 1670 | object_rad.y = obj->size; |
| 1671 | object_rad.z = obj->size; |
| 1672 | |
| 1673 | obj->min_xyz = obj->pos - object_rad; |
| 1674 | |
| 1675 | obj->max_xyz = obj->pos + object_rad; |
| 1676 | } |
| 1677 | } |
| 1678 | |
| 1679 | //----------------------------------------------------------------------------- |
| 1680 | // initialize a new object. adds to the list for the given room |
| 1681 | // returns the object number |
| 1682 | int ObjCreate(uint8_t type, uint16_t id, int roomnum, vector *pos, const matrix *orient, int parent_handle) { |
| 1683 | int objnum; |
| 1684 | object *obj; |
| 1685 | int handle; |
| 1686 | |
| 1687 | ASSERT(type != OBJ_NONE); |
| 1688 | |
| 1689 | if (ROOMNUM_OUTSIDE(roomnum)) { |
| 1690 | ASSERT(CELLNUM(roomnum) <= TERRAIN_WIDTH * TERRAIN_DEPTH); |
| 1691 | ASSERT(CELLNUM(roomnum) >= 0); |
| 1692 | |
| 1693 | roomnum = GetTerrainRoomFromPos(pos); |
| 1694 | |
| 1695 | if (roomnum == -1) |
| 1696 | return -1; |
| 1697 | } |
| 1698 | |
| 1699 | // Get next free object |
| 1700 | objnum = ObjAllocate(); |
| 1701 | if (objnum == -1) // no free objects |
| 1702 | return -1; |
| 1703 | obj = &Objects[objnum]; |
| 1704 | |
| 1705 | // Make sure the object is ok |
| 1706 | ASSERT(obj->type == OBJ_NONE); // make sure unused |
| 1707 | ASSERT(obj->roomnum == -1); // make sure unlinked |
| 1708 | |
| 1709 | // Compute the new handle |
| 1710 | handle = obj->handle + HANDLE_COUNT_INCREMENT; |
| 1711 | |
| 1712 | // Check for handle wrap |
| 1713 | if ((handle & HANDLE_COUNT_MASK) == HANDLE_COUNT_MASK) // Going to wrap! |
| 1714 | Int3(); // Show this to Matt, or email him if he's not here |
| 1715 | |
| 1716 | // Initialize the object |
| 1717 | if (!ObjInit(obj, type, id, handle, pos, Gametime, parent_handle)) { // Couldn't init! |
| 1718 | obj->type = OBJ_NONE; // mark as unused |
| 1719 | ObjFree(objnum); // de-allocate object |
| 1720 | return -1; |
| 1721 | } |
| 1722 | |
| 1723 | #ifdef _DEBUG |
| 1724 | if (print_object_info) { |
| 1725 | mprintf(0, "Created object %d of type %d\n", objnum, obj->type); |
| 1726 | } |
| 1727 | #endif |
| 1728 | |
| 1729 | // Set the object's orietation |
| 1730 | // THIS MUST BE DONE AFTER ObjInit (as ObjInit could load in a polymodel and set the anim and wall offsets) |
| 1731 | ObjSetOrient(obj, orient ? orient : &Identity_matrix); |
| 1732 | |
| 1733 | // Link object into room or terrain cell |
| 1734 | ObjLink(objnum, roomnum); |
| 1735 | |
| 1736 | // Type specific should have set up the size, so now we can compute the bounding box. |
| 1737 | ObjSetAABB(obj); |
| 1738 | |
| 1739 | // Let the demo system know about this object |
| 1740 | DemoWriteObjCreate(type, id, roomnum, pos, orient, parent_handle, obj); |
| 1741 | |
| 1742 | ObjInitPositionHistory(obj); |
| 1743 | |
| 1744 | // Check bad init code that doesn't call ComputeDefaultSize() |
| 1745 | ASSERT(!(obj->type != OBJ_ROOM && obj->type != OBJ_DEBRIS && (obj->flags & OF_POLYGON_OBJECT) && |
| 1746 | !(Poly_models[obj->rtype.pobj_info.model_num].flags & PMF_SIZE_COMPUTED))); |
| 1747 | |
| 1748 | // Done! |
| 1749 | return objnum; |
| 1750 | } |
| 1751 | |
| 1752 | void ObjInitPositionHistory(object *obj) { |
| 1753 | ASSERT(Object_map_position_history[OBJNUM(obj)] == -1); |
| 1754 | |
| 1755 | // If it is one of the types of object's that we have to sample positions for |
| 1756 | // Initialize that |
| 1757 | switch (obj->type) { |
| 1758 | case OBJ_ROBOT: |
| 1759 | case OBJ_WEAPON: |
| 1760 | case OBJ_DEBRIS: |
| 1761 | if (Num_free_object_position_history > 0) { |
| 1762 | // we have a free slot |
| 1763 | Num_free_object_position_history--; |
| 1764 | int free_slot = Object_map_position_free_slots[Num_free_object_position_history]; |
| 1765 | Object_map_position_history[OBJNUM(obj)] = free_slot; |
| 1766 | int i; |
| 1767 | for (i = 0; i < MAX_POSITION_HISTORY; i++) { |
| 1768 | Object_position_samples[free_slot].pos[i] = obj->pos; |
| 1769 | } |
| 1770 | } else { |
| 1771 | // out of slots! |
| 1772 | Object_map_position_history[OBJNUM(obj)] = -1; |
| 1773 | } |
| 1774 | break; |
| 1775 | default: |
| 1776 | // not saving positions |
| 1777 | Object_map_position_history[OBJNUM(obj)] = -1; |
| 1778 | break; |
| 1779 | } |
| 1780 | } |
| 1781 | |
| 1782 | void ObjFreePositionHistory(object *obj) { |
| 1783 | int objnum = OBJNUM(obj); |
| 1784 | |
| 1785 | if (Object_map_position_history[objnum] != -1) { |
| 1786 | int slot_to_free = Object_map_position_history[objnum]; |
| 1787 | Object_map_position_history[objnum] = -1; |
| 1788 | |
| 1789 | Object_map_position_free_slots[Num_free_object_position_history] = slot_to_free; |
| 1790 | Num_free_object_position_history++; |
| 1791 | ASSERT(Num_free_object_position_history <= MAX_OBJECT_POS_HISTORY); |
| 1792 | } |
| 1793 | } |
| 1794 | |
| 1795 | void ObjResetPositionHistory(void) { |
| 1796 | Num_free_object_position_history = MAX_OBJECT_POS_HISTORY; |
| 1797 | Object_position_head = 0; |
| 1798 | |
| 1799 | int i; |
| 1800 | |
| 1801 | for (i = 0; i < MAX_OBJECTS; i++) { |
| 1802 | Object_map_position_history[i] = -1; |
| 1803 | |
| 1804 | if (i < MAX_OBJECT_POS_HISTORY) { |
| 1805 | // this array is guaranteed smaller than Objects[] |
| 1806 | // so instead of looping through an array again just for |
| 1807 | // this, I'll stick it in this loop. |
| 1808 | Object_map_position_free_slots[i] = i; |
| 1809 | } |
| 1810 | } |
| 1811 | |
| 1812 | for (i = 0; i < MAX_POSITION_HISTORY; i++) { |
| 1813 | Last_position_history_update[i] = 0 - (0.1f * i); |
| 1814 | } |
| 1815 | } |
| 1816 | |
| 1817 | void ObjReInitPositionHistory(void) { |
| 1818 | ObjResetPositionHistory(); |
| 1819 | |
| 1820 | int i; |
| 1821 | for (i = 0; i <= Highest_object_index; i++) { |
| 1822 | if (Objects[i].type != OBJ_NONE) { |
| 1823 | ObjInitPositionHistory(&Objects[i]); |
| 1824 | } |
| 1825 | } |
| 1826 | } |
| 1827 | |
| 1828 | extern void newdemo_record_guided_end(); |
| 1829 | |
| 1830 | // remove object from the world |
| 1831 | void ObjDelete(int objnum) { |
| 1832 | object *obj = &Objects[objnum]; |
| 1833 | |
| 1834 | if (obj->type == OBJ_DUMMY) { |
| 1835 | // unghost the object before destroying it |
| 1836 | ObjUnGhostObject(objnum); |
| 1837 | } |
| 1838 | |
| 1839 | /* if ((Game_mode & GM_MULTI) && Netgame.local_role==LR_CLIENT && Objects[objnum].type==OBJ_POWERUP) |
| 1840 | { |
| 1841 | mprintf(0,"Deleting object number %d type=%d id=%d\n",objnum,obj->type,obj->id); |
| 1842 | }*/ |
| 1843 | |
| 1844 | if ((Game_mode & GM_MULTI) && (obj->flags & OF_SERVER_OBJECT)) { |
| 1845 | if (Netgame.local_role == LR_CLIENT && NetPlayers[Player_num].sequence > NETSEQ_OBJECTS && |
| 1846 | NetPlayers[Player_num].sequence != NETSEQ_LEVEL_END) { |
| 1847 | if (!(obj->flags & OF_SERVER_SAYS_DELETE)) { |
| 1848 | mprintf(0, "Illegally deleting server object! Objnum=%d type=%d id=%d\n", objnum, obj->type, obj->id); |
| 1849 | Int3(); |
| 1850 | return; |
| 1851 | } |
| 1852 | } |
| 1853 | } |
| 1854 | |
| 1855 | if (obj->flags & OF_POLYGON_OBJECT) { |
| 1856 | polyobj_info *p_info = &obj->rtype.pobj_info; |
| 1857 | if (p_info->multi_turret_info.keyframes != NULL) { |
| 1858 | mem_free(p_info->multi_turret_info.keyframes); |
| 1859 | mem_free(p_info->multi_turret_info.last_keyframes); |
| 1860 | |
| 1861 | p_info->multi_turret_info.keyframes = NULL; |
| 1862 | p_info->multi_turret_info.last_keyframes = NULL; |
| 1863 | } |
| 1864 | } |
| 1865 | |
| 1866 | ASSERT(objnum != -1); |
| 1867 | // ASSERT(objnum != 0 ); |
| 1868 | ASSERT(obj->type != OBJ_NONE); |
| 1869 | // ASSERT(obj != Player_object); |
| 1870 | |
| 1871 | //?? if (obj->type==OBJ_WEAPON && obj->id==GUIDEDMISS_ID) { |
| 1872 | //?? int pnum=Objects[obj->ctype.laser_info.parent_num].id; |
| 1873 | //?? mprintf(0,"Deleting a guided missile! Player %d\n\n",pnum); |
| 1874 | //?? |
| 1875 | //?? if (pnum!=Player_num) { |
| 1876 | //?? mprintf(0,"deleting missile that belongs to %d (%s)!\n",pnum,Players[pnum].callsign); |
| 1877 | //?? Guided_missile[pnum]=NULL; |
| 1878 | //?? } |
| 1879 | //?? else if (Newdemo_state==ND_STATE_RECORDING) |
| 1880 | //?? newdemo_record_guided_end(); |
| 1881 | //?? |
| 1882 | //?? } |
| 1883 | |
| 1884 | if (obj == Viewer_object) // deleting the viewer? |
| 1885 | Viewer_object = Player_object; //..make the player the viewer |
| 1886 | |
| 1887 | // Delete this chase camera if needed |
| 1888 | if (Player_camera_objnum == objnum) |
| 1889 | Player_camera_objnum = -1; |
| 1890 | |
| 1891 | //?? if (obj->flags & OF_ATTACHED) //detach this from object |
| 1892 | //?? obj_detach_one(obj); |
| 1893 | //?? |
| 1894 | //?? if (obj->attached_obj != -1) //detach all objects from this |
| 1895 | //?? obj_detach_all(obj); |
| 1896 | |
| 1897 | #ifdef _DEBUG |
| 1898 | if (print_object_info) { |
| 1899 | mprintf(0, "Deleting object %d of type %d\n", objnum, Objects[objnum].type); |
| 1900 | } |
| 1901 | #endif |
| 1902 | |
| 1903 | if (obj->type == OBJ_WEAPON && obj->ctype.laser_info.parent_type == OBJ_PLAYER) { |
| 1904 | int pnum = Objects[(obj->parent_handle & HANDLE_OBJNUM_MASK)].id; |
| 1905 | |
| 1906 | if (Players[pnum].guided_obj == obj) { |
| 1907 | mprintf(0, "Deleting a guided missile!"); |
| 1908 | Players[pnum].guided_obj = NULL; |
| 1909 | } |
| 1910 | } |
| 1911 | |
| 1912 | if (obj->type == OBJ_WEAPON && obj->ctype.laser_info.parent_type == OBJ_PLAYER) { |
| 1913 | int pnum = Objects[(obj->parent_handle & HANDLE_OBJNUM_MASK)].id; |
| 1914 | |
| 1915 | if (Players[pnum].user_timeout_obj == obj) { |
| 1916 | mprintf(0, "Deleting a timeout missile!"); |
| 1917 | Players[pnum].user_timeout_obj = NULL; |
| 1918 | } |
| 1919 | } |
| 1920 | |
| 1921 | ObjUnlink(objnum); |
| 1922 | |
| 1923 | ASSERT(Objects[0].next != 0); |
| 1924 | |
| 1925 | // Update powerup respawn point |
| 1926 | if ((Game_mode & GM_MULTI) && Netgame.local_role == LR_SERVER) { |
| 1927 | if (obj->type == OBJ_POWERUP && Object_info[obj->id].respawn_scalar > 0) { |
| 1928 | for (int i = 0; i < Num_powerup_respawn; i++) { |
| 1929 | if (Powerup_respawn[i].used && Powerup_respawn[i].objnum == objnum) { |
| 1930 | Powerup_respawn[i].used = 0; |
| 1931 | Powerup_respawn[i].objnum = -1; |
| 1932 | Powerup_timer[Num_powerup_timer].respawn_time = |
| 1933 | Gametime + (Netgame.respawn_time * Object_info[obj->id].respawn_scalar); |
| 1934 | Powerup_timer[Num_powerup_timer].id = obj->id; |
| 1935 | Num_powerup_timer++; |
| 1936 | mprintf(0, "Adding powerup id %d to respawn list! count=%d\n", obj->id, Num_powerup_timer); |
| 1937 | } |
| 1938 | } |
| 1939 | } |
| 1940 | } |
| 1941 | |
| 1942 | // Kill any script thread associated with this object. |
| 1943 | FreeObjectScripts(obj, false); |
| 1944 | |
| 1945 | if (obj->custom_default_script_name) { |
| 1946 | mem_free(obj->custom_default_script_name); |
| 1947 | obj->custom_default_script_name = NULL; |
| 1948 | } |
| 1949 | |
| 1950 | if (obj->custom_default_module_name) { |
| 1951 | mem_free(obj->custom_default_module_name); |
| 1952 | obj->custom_default_module_name = NULL; |
| 1953 | } |
| 1954 | |
| 1955 | obj->type = OBJ_NONE; // unused! |
| 1956 | obj->roomnum = -1; // zero it! |
| 1957 | |
| 1958 | // Free lightmap memory |
| 1959 | if (obj->lm_object.used) |
| 1960 | ClearObjectLightmaps(obj); |
| 1961 | |
| 1962 | // Free up effects memory |
| 1963 | if (obj->effect_info) { |
| 1964 | mem_free(obj->effect_info); |
| 1965 | obj->effect_info = NULL; |
| 1966 | } |
| 1967 | |
| 1968 | if (obj->ai_info != NULL) { |
| 1969 | AIDestroyObj(obj); |
| 1970 | mem_free(obj->ai_info); |
| 1971 | obj->ai_info = NULL; |
| 1972 | } |
| 1973 | |
| 1974 | if (obj->dynamic_wb != NULL) { |
| 1975 | mem_free(obj->dynamic_wb); |
| 1976 | obj->dynamic_wb = NULL; |
| 1977 | } |
| 1978 | |
| 1979 | if (obj->attach_children != NULL) { |
| 1980 | mem_free(obj->attach_children); |
| 1981 | obj->attach_children = NULL; |
| 1982 | } |
| 1983 | |
| 1984 | if (obj->name) { |
| 1985 | mem_free(obj->name); |
| 1986 | obj->name = NULL; |
| 1987 | } |
| 1988 | |
| 1989 | if (obj->lighting_info) { |
| 1990 | mem_free(obj->lighting_info); |
| 1991 | obj->lighting_info = NULL; |
| 1992 | } |
| 1993 | |
| 1994 | ObjFree(objnum); |
| 1995 | } |
| 1996 | |
| 1997 | // Frees all the objects that are currently in use |
| 1998 | void FreeAllObjects() { |
| 1999 | int objnum; |
| 2000 | |
| 2001 | for (objnum = 0; objnum <= Highest_object_index; objnum++) |
| 2002 | if (Objects[objnum].type != OBJ_NONE) { |
| 2003 | Objects[objnum].flags |= OF_SERVER_SAYS_DELETE; |
| 2004 | Objects[objnum].flags &= ~OF_INPLAYERINVENTORY; |
| 2005 | ObjDelete(objnum); |
| 2006 | } |
| 2007 | |
| 2008 | FreeAllVisEffects(); |
| 2009 | } |
| 2010 | |
| 2011 | // ------------------------------------------------------------------------------------------------------------------ |
| 2012 | void ObjDeleteDead() { |
| 2013 | int i; |
| 2014 | object *objp; |
| 2015 | int local_dead_player_object = -1; |
| 2016 | |
| 2017 | // Move all objects |
| 2018 | objp = Objects; |
| 2019 | |
| 2020 | for (i = 0; i <= Highest_object_index; i++) { |
| 2021 | if ((objp->type != OBJ_NONE) && (objp->flags & OF_DEAD)) { |
| 2022 | if (objp->flags & OF_INFORM_DESTROY_TO_LG) { |
| 2023 | Level_goals.Inform(LIT_OBJECT, LGF_COMP_DESTROY, objp->handle); |
| 2024 | } |
| 2025 | |
| 2026 | if (objp->flags & OF_INPLAYERINVENTORY) { |
| 2027 | // this object is in a player inventory somewhere...remove it first! |
| 2028 | InventoryRemoveObject(objp->handle); |
| 2029 | } |
| 2030 | |
| 2031 | if (objp->type == OBJ_DUMMY) { |
| 2032 | // unghost the object before deleting it |
| 2033 | ObjUnGhostObject(i); |
| 2034 | |
| 2035 | // tell clients to unghost |
| 2036 | if ((Game_mode & GM_MULTI) && (Netgame.local_role != LR_CLIENT)) { |
| 2037 | MultiSendGhostObject(&Objects[i], false); |
| 2038 | } |
| 2039 | } |
| 2040 | |
| 2041 | if (objp->flags & OF_POLYGON_OBJECT) { |
| 2042 | if (objp->flags & OF_ATTACHED) { |
| 2043 | tOSIRISEventInfo ei; |
| 2044 | ei.evt_child_died.it_handle = objp->handle; |
| 2045 | |
| 2046 | Osiris_CallEvent(ObjGet(objp->attach_ultimate_handle), EVT_CHILD_DIED, &ei); |
| 2047 | } |
| 2048 | |
| 2049 | UnattachFromParent(objp); |
| 2050 | UnattachChildren(objp); |
| 2051 | } |
| 2052 | |
| 2053 | // Execute script for death |
| 2054 | tOSIRISEventInfo ei; |
| 2055 | ei.evt_destroy.is_dying = 1; |
| 2056 | Osiris_CallEvent(objp, EVT_DESTROY, &ei); |
| 2057 | |
| 2058 | if (Game_mode & GM_MULTI) { |
| 2059 | DLLInfo.me_handle = DLLInfo.it_handle = objp->handle; |
| 2060 | CallGameDLL(EVT_GAMEOBJDESTROYED, &DLLInfo); |
| 2061 | } |
| 2062 | |
| 2063 | // detach any scripts attached |
| 2064 | Osiris_DetachScriptsFromObject(objp); |
| 2065 | |
| 2066 | // if it's flag to tell the clients to remove is set, tell them now |
| 2067 | if ((Game_mode & GM_MULTI) && (Netgame.local_role != LR_CLIENT)) { |
| 2068 | bool removed = false; |
| 2069 | |
| 2070 | if (objp->flags & OF_SEND_MULTI_REMOVE_ON_DEATH) { |
| 2071 | // Tell all clients to remove this object |
| 2072 | MultiSendRemoveObject(objp, 0); |
| 2073 | removed = true; |
| 2074 | } |
| 2075 | if (!removed && objp->flags & OF_SEND_MULTI_REMOVE_ON_DEATHWS) { |
| 2076 | // Tell all clients to remove this object with sound |
| 2077 | MultiSendRemoveObject(objp, 1); |
| 2078 | removed = true; |
| 2079 | } |
| 2080 | } |
| 2081 | |
| 2082 | if (IS_GUIDEBOT(objp)) { |
| 2083 | int i; |
| 2084 | int handle = objp->handle; |
| 2085 | |
| 2086 | for (i = 0; i < MAX_PLAYERS; i++) { |
| 2087 | if (objp->handle == Buddy_handle[i]) { |
| 2088 | Buddy_handle[i] = OBJECT_HANDLE_NONE; |
| 2089 | break; |
| 2090 | } |
| 2091 | } |
| 2092 | } |
| 2093 | |
| 2094 | // check if player being killed. |
| 2095 | if (objp->type != OBJ_PLAYER) { |
| 2096 | ObjDelete(i); |
| 2097 | } |
| 2098 | } |
| 2099 | objp++; |
| 2100 | } |
| 2101 | |
| 2102 | // Delete our visual effects |
| 2103 | VisEffectDeleteDead(); |
| 2104 | } |
| 2105 | |
| 2106 | // when an object has moved into a new room, this function unlinks it |
| 2107 | // from its old room and links it into the new room |
| 2108 | void ObjRelink(int objnum, int newroomnum) { |
| 2109 | ASSERT((objnum >= 0) && (objnum <= Highest_object_index)); |
| 2110 | |
| 2111 | if (!ROOMNUM_OUTSIDE(newroomnum)) { |
| 2112 | ASSERT((newroomnum <= Highest_room_index) && (newroomnum >= 0)); |
| 2113 | ASSERT(Rooms[newroomnum].used); |
| 2114 | } else |
| 2115 | ASSERT(CELLNUM(newroomnum) >= 0 && CELLNUM(newroomnum) <= (TERRAIN_WIDTH * TERRAIN_DEPTH)); |
| 2116 | |
| 2117 | ObjUnlink(objnum); |
| 2118 | ObjLink(objnum, newroomnum); |
| 2119 | } |
| 2120 | |
| 2121 | void DoCycledAnim(object *obj) { |
| 2122 | float from; |
| 2123 | float to; |
| 2124 | float delta; |
| 2125 | float spc; |
| 2126 | |
| 2127 | float anim_time = Frametime; |
| 2128 | |
| 2129 | if (!(obj->flags & OF_POLYGON_OBJECT)) |
| 2130 | return; |
| 2131 | |
| 2132 | from = Object_info[obj->id].anim[MC_STANDING].elem[AS_ALERT].from; |
| 2133 | to = Object_info[obj->id].anim[MC_STANDING].elem[AS_ALERT].to; |
| 2134 | spc = Object_info[obj->id].anim[MC_STANDING].elem[AS_ALERT].spc; |
| 2135 | |
| 2136 | if (spc <= 0.0) |
| 2137 | return; |
| 2138 | ASSERT(from <= to); |
| 2139 | |
| 2140 | if (obj->rtype.pobj_info.anim_frame < from || obj->rtype.pobj_info.anim_frame > to) { |
| 2141 | mprintf(0, "NonAI-Animation: Correcting for an incorrect frame number\n"); |
| 2142 | obj->rtype.pobj_info.anim_frame = from; |
| 2143 | } |
| 2144 | |
| 2145 | delta = to - from; |
| 2146 | |
| 2147 | ASSERT(delta >= 0.0f); |
| 2148 | |
| 2149 | if (delta > 0.0f) { |
| 2150 | // Frames per second will be on the animation page |
| 2151 | float step = (1.0f / (spc / (delta))) * anim_time; |
| 2152 | |
| 2153 | while (step > delta) { |
| 2154 | step -= delta; |
| 2155 | } |
| 2156 | |
| 2157 | ASSERT(step >= 0.0f); |
| 2158 | |
| 2159 | obj->rtype.pobj_info.anim_frame += step; |
| 2160 | |
| 2161 | if (obj->rtype.pobj_info.anim_frame >= to) { |
| 2162 | |
| 2163 | // We are guarenteed that this is between 'to' and 'from' from the above asserts() :) |
| 2164 | obj->rtype.pobj_info.anim_frame -= delta; |
| 2165 | } |
| 2166 | } else { |
| 2167 | obj->rtype.pobj_info.anim_frame = from; |
| 2168 | } |
| 2169 | |
| 2170 | ASSERT(obj->rtype.pobj_info.anim_frame >= from && obj->rtype.pobj_info.anim_frame <= to); |
| 2171 | } |
| 2172 | |
| 2173 | void TimeoutObject(object *obj) { |
| 2174 | switch (obj->type) { |
| 2175 | case OBJ_WEAPON: |
| 2176 | TimeoutWeapon(obj); |
| 2177 | break; |
| 2178 | case OBJ_SHOCKWAVE: |
| 2179 | DoConcussiveForce(obj, obj->parent_handle); |
| 2180 | break; |
| 2181 | default: |
| 2182 | break; |
| 2183 | } |
| 2184 | } |
| 2185 | |
| 2186 | // Does afterburn effects to a player ship |
| 2187 | void DoPlayerAfterburnControl(game_controls *controls, object *objp) { |
| 2188 | static int afterburner_id = -1; |
| 2189 | int slot = objp->id; |
| 2190 | |
| 2191 | if (controls->afterburn_thrust > 0) { |
| 2192 | Players[slot].last_afterburner_time = Gametime; |
| 2193 | |
| 2194 | if (Players[slot].afterburn_time_left > 0) { |
| 2195 | float punch_scalar = 1.0; |
| 2196 | |
| 2197 | if (Players[slot].afterburn_time_left == (AFTERBURN_TIME)) |
| 2198 | AddToShakeMagnitude(objp->mtype.phys_info.mass / 2); |
| 2199 | |
| 2200 | if (Players[slot].afterburn_time_left > (AFTERBURN_TIME * .90)) |
| 2201 | punch_scalar = 1.8f; |
| 2202 | else if (Players[slot].afterburn_time_left > (AFTERBURN_TIME * .80) && |
| 2203 | Players[slot].afterburn_time_left < (AFTERBURN_TIME * .90)) { |
| 2204 | float norm = Players[slot].afterburn_time_left - (AFTERBURN_TIME * .80); |
| 2205 | norm /= (AFTERBURN_TIME * .1); |
| 2206 | punch_scalar = 1.0 + (norm * .8); |
| 2207 | } |
| 2208 | |
| 2209 | if (OBJECT_OUTSIDE(objp)) |
| 2210 | controls->forward_thrust = controls->afterburn_thrust * 1.6 * punch_scalar; |
| 2211 | else |
| 2212 | controls->forward_thrust = controls->afterburn_thrust * 1.6 * punch_scalar; |
| 2213 | |
| 2214 | Players[slot].flags |= PLAYER_FLAGS_AFTERBURN_ON | PLAYER_FLAGS_THRUSTED; |
| 2215 | Players[slot].afterburn_time_left -= Frametime; |
| 2216 | if (Players[slot].afterburn_time_left < 0) |
| 2217 | Players[slot].afterburn_time_left = 0; |
| 2218 | } else { |
| 2219 | Players[slot].afterburn_time_left = 0; |
| 2220 | Players[slot].flags &= ~PLAYER_FLAGS_AFTERBURN_ON; |
| 2221 | } |
| 2222 | } else { |
| 2223 | Players[slot].flags &= ~PLAYER_FLAGS_AFTERBURN_ON; |
| 2224 | |
| 2225 | if (Players[slot].afterburn_time_left < AFTERBURN_TIME) { |
| 2226 | if (Players[slot].energy > 5.0) { |
| 2227 | float useage; |
| 2228 | if (afterburner_id == -1) |
| 2229 | afterburner_id = FindObjectIDName("Afterburner"); |
| 2230 | |
| 2231 | if (afterburner_id != -1 && Players[slot].inventory.CheckItem(OBJ_POWERUP, afterburner_id)) |
| 2232 | useage = Frametime * 2; |
| 2233 | else |
| 2234 | useage = Frametime; |
| 2235 | |
| 2236 | Players[slot].afterburn_time_left += useage; |
| 2237 | Players[slot].afterburn_time_left = std::min<float>(AFTERBURN_TIME, Players[slot].afterburn_time_left); |
| 2238 | |
| 2239 | Players[slot].energy -= (useage); |
| 2240 | } |
| 2241 | } |
| 2242 | } |
| 2243 | } |
| 2244 | |
| 2245 | // Deal with the player's rear view |
| 2246 | void CheckRearView(int down_count, bool down_state) { |
| 2247 | player *player = &Players[Player_num]; |
| 2248 | |
| 2249 | #define LEAVE_TIME (1.0 / 16) // How long until we decide key is down |
| 2250 | |
| 2251 | static bool leave_mode; |
| 2252 | static float entry_time; |
| 2253 | |
| 2254 | if (down_count) { // key/button has gone down |
| 2255 | |
| 2256 | if (player->flags & PLAYER_FLAGS_REARVIEW) { // rear view was active, so turn it off |
| 2257 | player->flags &= ~PLAYER_FLAGS_REARVIEW; |
| 2258 | } else { // rear view wasn't active, so turn it on |
| 2259 | player->flags |= PLAYER_FLAGS_REARVIEW; |
| 2260 | leave_mode = 0; // means wait for another key |
| 2261 | entry_time = Gametime; |
| 2262 | } |
| 2263 | } else { // key didn't go down this frame; check if it used to be down |
| 2264 | |
| 2265 | if (down_state) { // key is still down |
| 2266 | |
| 2267 | if (!leave_mode && ((Gametime - entry_time) > LEAVE_TIME)) |
| 2268 | leave_mode = 1; |
| 2269 | } else { |
| 2270 | |
| 2271 | if (leave_mode && (player->flags & PLAYER_FLAGS_REARVIEW)) { |
| 2272 | player->flags &= ~PLAYER_FLAGS_REARVIEW; |
| 2273 | } |
| 2274 | } |
| 2275 | } |
| 2276 | } |
| 2277 | |
| 2278 | extern int Timedemo_frame; |
| 2279 | float Timedemo_timecount; |
| 2280 | |
| 2281 | // Do the controls for a player-type object |
| 2282 | void DoFlyingControl(object *objp) { |
| 2283 | game_controls controls; |
| 2284 | |
| 2285 | if (Dedicated_server) |
| 2286 | return; |
| 2287 | |
| 2288 | ASSERT(objp->control_type == CT_FLYING); |
| 2289 | |
| 2290 | if ((objp->type != OBJ_PLAYER && objp->type != OBJ_OBSERVER) || objp->id != Player_num) |
| 2291 | return; |
| 2292 | |
| 2293 | if (Timedemo_frame != -1) { |
| 2294 | matrix temp_mat, rot_mat; |
| 2295 | |
| 2296 | if (Timedemo_frame == 0) { |
| 2297 | Timedemo_timecount = 0; |
| 2298 | } else { |
| 2299 | Timedemo_timecount += Frametime; |
| 2300 | } |
| 2301 | |
| 2302 | vm_AnglesToMatrix(&temp_mat, 0, 65536 / 360, 0); |
| 2303 | |
| 2304 | rot_mat = objp->orient * temp_mat; |
| 2305 | |
| 2306 | ObjSetOrient(objp, &rot_mat); |
| 2307 | |
| 2308 | Timedemo_frame++; |
| 2309 | if (Timedemo_frame == 360) { |
| 2310 | // Calculate timedemo framerate |
| 2311 | |
| 2312 | float fps = 1.0 / (Timedemo_timecount / 360.0); |
| 2313 | AddHUDMessage(TXT_TIMEDEMO, fps); |
| 2314 | Timedemo_frame = -1; |
| 2315 | } |
| 2316 | |
| 2317 | return; |
| 2318 | } |
| 2319 | if (Demo_flags == DF_PLAYBACK) { |
| 2320 | // If we are playing back a demo, bail early and don't process controls |
| 2321 | return; |
| 2322 | } |
| 2323 | |
| 2324 | // Read the controllers |
| 2325 | ReadPlayerControls(&controls); |
| 2326 | |
| 2327 | if ((objp->type == OBJ_PLAYER) && (Players[objp->id].controller_bitflags != 0xffffffff)) { |
| 2328 | player *pp = &Players[objp->id]; |
| 2329 | if (!(pp->controller_bitflags & PCBF_FORWARD)) { |
| 2330 | if (controls.forward_thrust > 0.0f) |
| 2331 | controls.forward_thrust = 0.0f; |
| 2332 | } |
| 2333 | if (!(pp->controller_bitflags & PCBF_REVERSE)) { |
| 2334 | if (controls.forward_thrust < 0.0f) |
| 2335 | controls.forward_thrust = 0.0f; |
| 2336 | } |
| 2337 | if (!(pp->controller_bitflags & PCBF_LEFT)) { |
| 2338 | if (controls.sideways_thrust < 0.0f) |
| 2339 | controls.sideways_thrust = 0.0f; |
| 2340 | } |
| 2341 | if (!(pp->controller_bitflags & PCBF_RIGHT)) { |
| 2342 | if (controls.sideways_thrust > 0.0f) |
| 2343 | controls.sideways_thrust = 0.0f; |
| 2344 | } |
| 2345 | if (!(pp->controller_bitflags & PCBF_UP)) { |
| 2346 | if (controls.vertical_thrust > 0.0f) |
| 2347 | controls.vertical_thrust = 0.0f; |
| 2348 | } |
| 2349 | if (!(pp->controller_bitflags & PCBF_DOWN)) { |
| 2350 | if (controls.vertical_thrust < 0.0f) |
| 2351 | controls.vertical_thrust = 0.0f; |
| 2352 | } |
| 2353 | if (!(pp->controller_bitflags & PCBF_PITCHUP)) { |
| 2354 | if (controls.pitch_thrust > 0.0f) |
| 2355 | controls.pitch_thrust = 0.0f; |
| 2356 | } |
| 2357 | if (!(pp->controller_bitflags & PCBF_PITCHDOWN)) { |
| 2358 | if (controls.pitch_thrust < 0.0f) |
| 2359 | controls.pitch_thrust = 0.0f; |
| 2360 | } |
| 2361 | if (!(pp->controller_bitflags & PCBF_HEADINGLEFT)) { |
| 2362 | if (controls.heading_thrust < 0.0f) |
| 2363 | controls.heading_thrust = 0.0f; |
| 2364 | } |
| 2365 | if (!(pp->controller_bitflags & PCBF_HEADINGRIGHT)) { |
| 2366 | if (controls.heading_thrust > 0.0f) |
| 2367 | controls.heading_thrust = 0.0f; |
| 2368 | } |
| 2369 | if (!(pp->controller_bitflags & PCBF_BANKLEFT)) { |
| 2370 | if (controls.bank_thrust < 0.0f) |
| 2371 | controls.bank_thrust = 0.0f; |
| 2372 | } |
| 2373 | if (!(pp->controller_bitflags & PCBF_BANKRIGHT)) { |
| 2374 | if (controls.bank_thrust > 0.0f) |
| 2375 | controls.bank_thrust = 0.0f; |
| 2376 | } |
| 2377 | if (!(pp->controller_bitflags & PCBF_PRIMARY)) { |
| 2378 | controls.fire_primary_down_count = 0; |
| 2379 | controls.fire_primary_down_time = 0; |
| 2380 | controls.fire_primary_down_state = false; |
| 2381 | } |
| 2382 | if (!(pp->controller_bitflags & PCBF_SECONDARY)) { |
| 2383 | controls.fire_secondary_down_count = 0; |
| 2384 | controls.fire_secondary_down_time = 0; |
| 2385 | controls.fire_secondary_down_state = false; |
| 2386 | } |
| 2387 | if (!(pp->controller_bitflags & PCBF_AFTERBURNER)) { |
| 2388 | controls.afterburn_thrust = 0.0f; |
| 2389 | } |
| 2390 | } |
| 2391 | |
| 2392 | // Send an event to the Game DLLs so they can do any processing of game controls |
| 2393 | if (Game_mode & GM_MULTI) { |
| 2394 | DLLInfo.me_handle = DLLInfo.it_handle = objp->handle; |
| 2395 | DLLInfo.special_data = (uint8_t *)&controls; |
| 2396 | CallGameDLL(EVT_GAMEDOCONTROLS, &DLLInfo); |
| 2397 | } |
| 2398 | |
| 2399 | // Deal with afterburner |
| 2400 | if (objp->type == OBJ_PLAYER) { |
| 2401 | ASSERT(Player_num == objp->id); |
| 2402 | |
| 2403 | // Reset thrusting |
| 2404 | Players[objp->id].flags &= ~PLAYER_FLAGS_THRUSTED; |
| 2405 | |
| 2406 | DoPlayerAfterburnControl(&controls, objp); |
| 2407 | } |
| 2408 | |
| 2409 | // Update object's physics |
| 2410 | if (objp->movement_type == MT_PHYSICS) { |
| 2411 | if (objp->type == OBJ_PLAYER && Players[objp->id].guided_obj != NULL) { |
| 2412 | ASSERT(objp->id == Player_num); |
| 2413 | object *g_obj = Players[objp->id].guided_obj; |
| 2414 | |
| 2415 | g_obj->mtype.phys_info.rotthrust.x = controls.pitch_thrust * g_obj->mtype.phys_info.full_rotthrust; |
| 2416 | g_obj->mtype.phys_info.rotthrust.z = controls.bank_thrust * g_obj->mtype.phys_info.full_rotthrust; |
| 2417 | g_obj->mtype.phys_info.rotthrust.y = controls.heading_thrust * g_obj->mtype.phys_info.full_rotthrust; |
| 2418 | } else { |
| 2419 | player *playp = &Players[objp->id]; |
| 2420 | |
| 2421 | objp->mtype.phys_info.rotthrust.x = |
| 2422 | controls.pitch_thrust * objp->mtype.phys_info.full_rotthrust * playp->turn_scalar; |
| 2423 | objp->mtype.phys_info.rotthrust.z = |
| 2424 | controls.bank_thrust * objp->mtype.phys_info.full_rotthrust * playp->turn_scalar; |
| 2425 | objp->mtype.phys_info.rotthrust.y = |
| 2426 | controls.heading_thrust * objp->mtype.phys_info.full_rotthrust * playp->turn_scalar; |
| 2427 | } |
| 2428 | |
| 2429 | float speed_scalar = 1.0; |
| 2430 | |
| 2431 | // If thrusting foward, show glow |
| 2432 | if (objp->type == OBJ_PLAYER && controls.forward_thrust > 0) |
| 2433 | Players[objp->id].flags |= PLAYER_FLAGS_THRUSTED; |
| 2434 | |
| 2435 | if (objp->effect_info && objp->effect_info->type_flags & EF_FREEZE) |
| 2436 | speed_scalar = objp->effect_info->freeze_scalar; |
| 2437 | |
| 2438 | if (OBJECT_OUTSIDE(objp)) |
| 2439 | speed_scalar *= 1.3f; |
| 2440 | |
| 2441 | objp->mtype.phys_info.thrust = speed_scalar * Players[objp->id].movement_scalar * |
| 2442 | ((objp->orient.fvec * controls.forward_thrust * objp->mtype.phys_info.full_thrust) + |
| 2443 | (objp->orient.uvec * controls.vertical_thrust * objp->mtype.phys_info.full_thrust) + |
| 2444 | (objp->orient.rvec * controls.sideways_thrust * objp->mtype.phys_info.full_thrust)); |
| 2445 | } |
| 2446 | |
| 2447 | // Process player-specific stuff |
| 2448 | if (objp->type == OBJ_PLAYER) { |
| 2449 | // Process weapon firing |
| 2450 | FireWeaponFromPlayer(objp, PW_PRIMARY, controls.fire_primary_down_count, controls.fire_primary_down_state, |
| 2451 | controls.fire_primary_down_time); |
| 2452 | FireWeaponFromPlayer(objp, PW_SECONDARY, controls.fire_secondary_down_count, controls.fire_secondary_down_state, |
| 2453 | controls.fire_secondary_down_time); |
| 2454 | |
| 2455 | // Deal with the flare |
| 2456 | for (int i = 0; i < controls.fire_flare_down_count; i++) |
| 2457 | FireFlareFromPlayer(objp); |
| 2458 | |
| 2459 | // Do rear view |
| 2460 | CheckRearView(controls.rearview_down_count, controls.rearview_down_state); |
| 2461 | } |
| 2462 | } |
| 2463 | |
| 2464 | // Do any special effects processing for this object |
| 2465 | void ObjDoEffects(object *obj) { |
| 2466 | if (!obj->effect_info) |
| 2467 | return; |
| 2468 | |
| 2469 | static int napalm_id = -1; |
| 2470 | |
| 2471 | if (napalm_id == -1) |
| 2472 | napalm_id = FindWeaponName("Napalm"); |
| 2473 | |
| 2474 | if (obj->effect_info->type_flags & EF_VOLUME_CHANGING) { |
| 2475 | obj->effect_info->volume_change_time -= Frametime; |
| 2476 | if (obj->effect_info->volume_change_time <= 0.0f) { |
| 2477 | obj->effect_info->type_flags &= ~EF_VOLUME_CHANGING; |
| 2478 | } |
| 2479 | } |
| 2480 | |
| 2481 | if (obj->effect_info->type_flags & EF_FADING_IN) { |
| 2482 | obj->effect_info->fade_time -= Frametime; |
| 2483 | if (obj->effect_info->fade_time <= 0.0f) { |
| 2484 | obj->effect_info->type_flags &= ~EF_FADING_IN; |
| 2485 | } |
| 2486 | } |
| 2487 | |
| 2488 | if (obj->effect_info->type_flags & EF_CLOAKED) { |
| 2489 | obj->effect_info->cloak_time -= Frametime; |
| 2490 | if (obj->effect_info->cloak_time <= 0.0f) { |
| 2491 | // reappear the object |
| 2492 | MakeObjectVisible(obj); |
| 2493 | } |
| 2494 | } |
| 2495 | |
| 2496 | if (obj->effect_info->type_flags & EF_FADING_OUT) { |
| 2497 | obj->effect_info->fade_time -= Frametime; |
| 2498 | if (obj->effect_info->fade_time <= 0.0f) { |
| 2499 | obj->effect_info->type_flags &= ~EF_FADING_OUT; |
| 2500 | obj->effect_info->type_flags |= EF_CLOAKED; |
| 2501 | } |
| 2502 | } |
| 2503 | |
| 2504 | if (obj->effect_info->type_flags & EF_LIQUID) { |
| 2505 | obj->effect_info->liquid_time_left -= Frametime; |
| 2506 | if (obj->effect_info->liquid_time_left <= 0.0f) { |
| 2507 | // Stop doing liquid effect |
| 2508 | obj->effect_info->type_flags &= ~EF_LIQUID; |
| 2509 | if (obj == Viewer_object) |
| 2510 | Render_FOV = D3_DEFAULT_FOV; |
| 2511 | } else { |
| 2512 | if (obj == Viewer_object) { |
| 2513 | int inttime = Gametime; |
| 2514 | float normtime = Gametime - inttime; |
| 2515 | |
| 2516 | float scalar = FixSin(normtime * 65535 * 4); |
| 2517 | |
| 2518 | scalar *= ((float)obj->effect_info->liquid_mag); |
| 2519 | if (obj->effect_info->liquid_time_left < 1) |
| 2520 | scalar *= (obj->effect_info->liquid_time_left); |
| 2521 | |
| 2522 | Render_FOV = D3_DEFAULT_FOV + scalar; |
| 2523 | } |
| 2524 | } |
| 2525 | } |
| 2526 | |
| 2527 | if (obj->effect_info->type_flags & EF_DEFORM) { |
| 2528 | obj->effect_info->deform_time -= Frametime; |
| 2529 | if (obj->effect_info->deform_time <= 0.0f) { |
| 2530 | // Stop deforming |
| 2531 | obj->effect_info->type_flags &= ~EF_DEFORM; |
| 2532 | } |
| 2533 | } |
| 2534 | |
| 2535 | if (obj->effect_info->type_flags & EF_FREEZE) { |
| 2536 | obj->effect_info->freeze_scalar += (Frametime / 3); |
| 2537 | if (obj->effect_info->freeze_scalar >= 1.0f) { |
| 2538 | // Stop freezing |
| 2539 | obj->effect_info->type_flags &= ~EF_FREEZE; |
| 2540 | } |
| 2541 | } |
| 2542 | |
| 2543 | if (obj->effect_info->type_flags & EF_NAPALMED) { |
| 2544 | if ((Gametime - obj->effect_info->last_damage_time) > 1.0) { |
| 2545 | obj->effect_info->last_damage_time = Gametime; |
| 2546 | |
| 2547 | // Apply damage to this napalmed object |
| 2548 | object *killer; |
| 2549 | |
| 2550 | if (obj->effect_info->damage_handle != OBJECT_HANDLE_NONE) { |
| 2551 | uint32_t sig = obj->effect_info->damage_handle & HANDLE_COUNT_MASK; |
| 2552 | int objnum = obj->effect_info->damage_handle & HANDLE_OBJNUM_MASK; |
| 2553 | |
| 2554 | if ((Objects[objnum].handle & HANDLE_COUNT_MASK) != sig) |
| 2555 | killer = NULL; |
| 2556 | else |
| 2557 | killer = &Objects[objnum]; |
| 2558 | } else |
| 2559 | killer = NULL; |
| 2560 | |
| 2561 | if (obj->type == OBJ_PLAYER) { |
| 2562 | ApplyDamageToPlayer(obj, killer, PD_NONE, obj->effect_info->damage_per_second); |
| 2563 | } else if (IS_GENERIC(obj->type) || (obj->type == OBJ_DOOR)) { |
| 2564 | ApplyDamageToGeneric(obj, killer, GD_FIRE, obj->effect_info->damage_per_second); |
| 2565 | } |
| 2566 | } |
| 2567 | |
| 2568 | obj->effect_info->damage_time -= Frametime; |
| 2569 | if (obj->effect_info->damage_time <= 0) { |
| 2570 | obj->effect_info->type_flags &= ~EF_NAPALMED; |
| 2571 | obj->effect_info->last_damage_time = 0; |
| 2572 | Sound_system.StopSoundLooping(obj->effect_info->sound_handle); |
| 2573 | obj->effect_info->sound_handle = SOUND_NONE_INDEX; |
| 2574 | } |
| 2575 | |
| 2576 | // Drop some smoke/fire and stuff |
| 2577 | AttachRandomNapalmEffectsToObject(obj); |
| 2578 | } |
| 2579 | |
| 2580 | // Do sparking stuff |
| 2581 | if (obj->effect_info->type_flags & EF_SPARKING) { |
| 2582 | int num_bolts = 0; |
| 2583 | |
| 2584 | // Create spark effects |
| 2585 | obj->effect_info->spark_timer -= Frametime; |
| 2586 | while (obj->effect_info->spark_timer < 0.0) { |
| 2587 | obj->effect_info->spark_timer += obj->effect_info->spark_delay; |
| 2588 | num_bolts++; |
| 2589 | } |
| 2590 | CreateElectricalBolts(obj, num_bolts); |
| 2591 | |
| 2592 | // Update timer |
| 2593 | obj->effect_info->spark_time_left -= Frametime; |
| 2594 | if (obj->effect_info->spark_time_left <= 0.0f) { |
| 2595 | obj->effect_info->type_flags &= ~EF_SPARKING; |
| 2596 | } |
| 2597 | } |
| 2598 | } |
| 2599 | |
| 2600 | // Check passed-through faces for triggers, etc. |
| 2601 | void ObjCheckTriggers(object *objp) { |
| 2602 | for (int i = 0; i < Fvi_num_recorded_faces; i++) { |
| 2603 | int roomnum = Fvi_recorded_faces[i].room_index; |
| 2604 | int facenum = Fvi_recorded_faces[i].face_index; |
| 2605 | |
| 2606 | CheckTrigger(roomnum, facenum, objp, TT_PASS_THROUGH); |
| 2607 | } |
| 2608 | } |
| 2609 | |
| 2610 | #ifdef _DEBUG |
| 2611 | void debug_check_terrain_objects() { |
| 2612 | int i; |
| 2613 | int j; |
| 2614 | |
| 2615 | for (i = 0; i < TERRAIN_WIDTH * TERRAIN_DEPTH; i++) { |
| 2616 | j = Terrain_seg[i].objects; |
| 2617 | while (j != -1) { |
| 2618 | ASSERT(j >= 0 && j <= Highest_object_index); |
| 2619 | j = Objects[j].next; |
| 2620 | } |
| 2621 | } |
| 2622 | } |
| 2623 | #endif |
| 2624 | |
| 2625 | #ifdef _DEBUG |
| 2626 | extern int DoAI; |
| 2627 | #else |
| 2628 | #define DoAI 1 |
| 2629 | #endif |
| 2630 | //-------------------------------------------------------------------- |
| 2631 | // Process an object for the current frame |
| 2632 | void ObjDoFrame(object *obj) { |
| 2633 | int previous_room = obj->roomnum; |
| 2634 | float save_frametime = Frametime; |
| 2635 | |
| 2636 | ASSERT(obj->type != OBJ_NONE); |
| 2637 | |
| 2638 | // Clear attached vis for this frame |
| 2639 | obj->lowest_attached_vis = -1; |
| 2640 | |
| 2641 | // If this is a permissable netgame, accelerate this object if need by |
| 2642 | if ((Game_mode & GM_MULTI) && Netgame.local_role == LR_CLIENT && (obj->flags & OF_PING_ACCELERATE)) { |
| 2643 | Frametime += (NetPlayers[Player_num].ping_time / 2.0); |
| 2644 | obj->flags &= ~OF_PING_ACCELERATE; |
| 2645 | } |
| 2646 | // Update previous position before moving |
| 2647 | obj->last_pos = obj->pos; |
| 2648 | |
| 2649 | // Inevitable countdown towards death |
| 2650 | if (obj->flags & OF_USES_LIFELEFT) |
| 2651 | obj->lifeleft -= Frametime; |
| 2652 | |
| 2653 | // #ifdef _DEBUG |
| 2654 | // if(Physics_player_verbose) |
| 2655 | // { |
| 2656 | // debug_check_terrain_objects(); |
| 2657 | // } |
| 2658 | // #endif _DEBUG |
| 2659 | |
| 2660 | // Process the control for this object |
| 2661 | switch (obj->control_type) { |
| 2662 | |
| 2663 | case CT_POWERUP: |
| 2664 | case CT_NONE: |
| 2665 | break; |
| 2666 | case CT_FLYING: { |
| 2667 | RTP_STARTINCTIME(ct_flying_time); |
| 2668 | DoFlyingControl(obj); |
| 2669 | RTP_ENDINCTIME(ct_flying_time); |
| 2670 | } break; |
| 2671 | case CT_AI: |
| 2672 | if (DoAI) { |
| 2673 | RTP_STARTINCTIME(ct_aidoframe_time); |
| 2674 | AIDoFrame(obj); |
| 2675 | RTP_ENDINCTIME(ct_aidoframe_time); |
| 2676 | } |
| 2677 | break; |
| 2678 | case CT_WEAPON: { |
| 2679 | RTP_STARTINCTIME(ct_weaponframe_time); |
| 2680 | WeaponDoFrame(obj); |
| 2681 | RTP_ENDINCTIME(ct_weaponframe_time); |
| 2682 | } break; |
| 2683 | case CT_EXPLOSION: { |
| 2684 | RTP_STARTINCTIME(ct_explosionframe_time); |
| 2685 | DoExplosionFrame(obj); |
| 2686 | RTP_ENDINCTIME(ct_explosionframe_time); |
| 2687 | } break; |
| 2688 | case CT_DEBRIS: { |
| 2689 | RTP_STARTINCTIME(ct_debrisframe_time); |
| 2690 | DoDebrisFrame(obj); |
| 2691 | RTP_ENDINCTIME(ct_debrisframe_time); |
| 2692 | } break; |
| 2693 | case CT_SPLINTER: { |
| 2694 | RTP_STARTINCTIME(ct_splinterframe_time); |
| 2695 | DoSplinterFrame(obj); |
| 2696 | RTP_ENDINCTIME(ct_splinterframe_time); |
| 2697 | } break; |
| 2698 | case CT_DYING: |
| 2699 | DoDyingFrame(obj); |
| 2700 | break; |
| 2701 | case CT_DYING_AND_AI: |
| 2702 | if (DoAI) |
| 2703 | AIDoFrame(obj); |
| 2704 | DoDyingFrame(obj); |
| 2705 | break; |
| 2706 | case CT_SOUNDSOURCE: |
| 2707 | break; // do nothing |
| 2708 | case CT_SOAR: |
| 2709 | break; |
| 2710 | |
| 2711 | #ifdef _DEBUG |
| 2712 | case CT_SLEW: |
| 2713 | SlewFrame(obj); |
| 2714 | break; |
| 2715 | #endif |
| 2716 | |
| 2717 | default: |
| 2718 | Error("Unknown control type %d in object %i, handle/type/id = %i/%i/%i", obj->control_type, obj - Objects, |
| 2719 | obj->handle, obj->type, obj->id); |
| 2720 | break; |
| 2721 | } |
| 2722 | |
| 2723 | // #ifdef _DEBUG |
| 2724 | // if(Physics_player_verbose) |
| 2725 | // { |
| 2726 | // debug_check_terrain_objects(); |
| 2727 | // } |
| 2728 | // #endif _DEBUG |
| 2729 | |
| 2730 | // Update cycled animation |
| 2731 | if ((obj->control_type != CT_AI) && (obj->control_type != CT_DYING_AND_AI) && (obj->control_type != CT_DEBRIS) && |
| 2732 | IS_GENERIC(obj->type) && (obj->type != OBJ_ROOM)) { |
| 2733 | if (Object_info[obj->id].anim && Object_info[obj->id].anim[MC_STANDING].elem[AS_ALERT].to) { |
| 2734 | RTP_STARTINCTIME(cycle_anim); |
| 2735 | DoCycledAnim(obj); |
| 2736 | RTP_ENDINCTIME(cycle_anim); |
| 2737 | } |
| 2738 | } |
| 2739 | |
| 2740 | // #ifdef _DEBUG |
| 2741 | // if(Physics_player_verbose) |
| 2742 | // { |
| 2743 | // debug_check_terrain_objects(); |
| 2744 | // } |
| 2745 | // #endif _DEBUG |
| 2746 | |
| 2747 | // Do freeze stuff on AI controlled robots |
| 2748 | if ((obj->type == OBJ_ROBOT || obj->type == OBJ_BUILDING) && obj->control_type == CT_AI && obj->effect_info && |
| 2749 | (obj->effect_info->type_flags & EF_FREEZE)) |
| 2750 | obj->mtype.phys_info.velocity *= obj->effect_info->freeze_scalar; |
| 2751 | |
| 2752 | // #ifdef _DEBUG |
| 2753 | // if(Physics_player_verbose) |
| 2754 | // { |
| 2755 | // debug_check_terrain_objects(); |
| 2756 | // } |
| 2757 | // #endif _DEBUG |
| 2758 | |
| 2759 | // Check for object dead of old age |
| 2760 | if ((obj->flags & OF_USES_LIFELEFT) && (obj->lifeleft < 0)) { |
| 2761 | bool kill_it = true; |
| 2762 | bool tell_clients = false; |
| 2763 | |
| 2764 | ASSERT(obj->type != OBJ_PLAYER); |
| 2765 | |
| 2766 | if (Game_mode & GM_MULTI) { |
| 2767 | if (Netgame.local_role == LR_CLIENT) { |
| 2768 | if (obj->type == OBJ_POWERUP || obj->type == OBJ_ROBOT || obj->type == OBJ_CLUTTER || |
| 2769 | obj->type == OBJ_BUILDING) { |
| 2770 | ASSERT(obj->flags & OF_SERVER_OBJECT); |
| 2771 | |
| 2772 | if (!(obj->flags & OF_SERVER_SAYS_DELETE)) { |
| 2773 | kill_it = false; |
| 2774 | obj->lifeleft = .001f; |
| 2775 | } |
| 2776 | } |
| 2777 | } else { |
| 2778 | if (obj->type == OBJ_POWERUP || obj->type == OBJ_ROBOT || obj->type == OBJ_CLUTTER || obj->type == OBJ_BUILDING) |
| 2779 | tell_clients = true; |
| 2780 | } |
| 2781 | } |
| 2782 | |
| 2783 | if (kill_it) { |
| 2784 | TimeoutObject(obj); |
| 2785 | SetObjectDeadFlag(obj, tell_clients); |
| 2786 | } |
| 2787 | } |
| 2788 | |
| 2789 | // #ifdef _DEBUG |
| 2790 | // if(Physics_player_verbose) |
| 2791 | // { |
| 2792 | // debug_check_terrain_objects(); |
| 2793 | // } |
| 2794 | // #endif _DEBUG |
| 2795 | |
| 2796 | // If object is dead, don't do any more processing on it |
| 2797 | if (obj->flags & OF_DEAD) { |
| 2798 | Frametime = save_frametime; |
| 2799 | return; |
| 2800 | } |
| 2801 | |
| 2802 | // #ifdef _DEBUG |
| 2803 | // if(Physics_player_verbose) |
| 2804 | // { |
| 2805 | // debug_check_terrain_objects(); |
| 2806 | // } |
| 2807 | // #endif _DEBUG |
| 2808 | |
| 2809 | // Do the movement for this object |
| 2810 | switch (obj->movement_type) { |
| 2811 | case MT_NONE: |
| 2812 | if ((obj->flags & OF_STUCK_ON_PORTAL) && |
| 2813 | !(Rooms[obj->mtype.phys_info.stuck_room].portals[obj->mtype.phys_info.stuck_portal].flags & PF_RENDER_FACES)) { |
| 2814 | if (IS_GENERIC(obj->type) && (obj->flags & OF_CLIENT_KNOWS)) |
| 2815 | SetObjectDeadFlag(obj, true); |
| 2816 | else |
| 2817 | SetObjectDeadFlag(obj, false); |
| 2818 | } |
| 2819 | break; // this doesn't move |
| 2820 | |
| 2821 | case MT_PHYSICS: { |
| 2822 | RTP_STARTINCTIME(mt_physicsframe_time); |
| 2823 | |
| 2824 | do_physics_sim(obj); |
| 2825 | ObjCheckTriggers(obj); |
| 2826 | |
| 2827 | RTP_ENDINCTIME(mt_physicsframe_time); |
| 2828 | } break; |
| 2829 | |
| 2830 | case MT_WALKING: { |
| 2831 | RTP_STARTINCTIME(mt_walkingframe_time); |
| 2832 | do_walking_sim(obj); |
| 2833 | ObjCheckTriggers(obj); |
| 2834 | RTP_ENDINCTIME(mt_walkingframe_time); |
| 2835 | } break; |
| 2836 | |
| 2837 | case MT_SHOCKWAVE: { |
| 2838 | RTP_STARTINCTIME(mt_shockwave_time); |
| 2839 | DoConcussiveForce(obj, obj->parent_handle); |
| 2840 | RTP_ENDINCTIME(mt_shockwave_time); |
| 2841 | } break; |
| 2842 | |
| 2843 | case MT_OBJ_LINKED: |
| 2844 | PhysicsLinkList[Physics_NumLinked++] = OBJNUM(obj); |
| 2845 | break; |
| 2846 | |
| 2847 | default: |
| 2848 | Int3(); // unknown movement type |
| 2849 | } |
| 2850 | |
| 2851 | // #ifdef _DEBUG |
| 2852 | // if(Physics_player_verbose) |
| 2853 | // { |
| 2854 | // debug_check_terrain_objects(); |
| 2855 | // } |
| 2856 | // #endif _DEBUG |
| 2857 | |
| 2858 | // Do special effects stuff to object |
| 2859 | if (obj->effect_info) { |
| 2860 | RTP_STARTINCTIME(obj_doeffect_time); |
| 2861 | ObjDoEffects(obj); |
| 2862 | RTP_ENDINCTIME(obj_doeffect_time); |
| 2863 | } |
| 2864 | |
| 2865 | // #ifdef _DEBUG |
| 2866 | // if(Physics_player_verbose) |
| 2867 | // { |
| 2868 | // debug_check_terrain_objects(); |
| 2869 | // } |
| 2870 | // #endif _DEBUG |
| 2871 | |
| 2872 | // Deal with special player movement stuff |
| 2873 | if (obj->type == OBJ_PLAYER) { |
| 2874 | RTP_STARTINCTIME(obj_move_player_time); |
| 2875 | DoSpecialPlayerStuff(obj); |
| 2876 | RTP_ENDINCTIME(obj_move_player_time); |
| 2877 | } |
| 2878 | |
| 2879 | // #ifdef _DEBUG |
| 2880 | // if(Physics_player_verbose) |
| 2881 | // { |
| 2882 | // debug_check_terrain_objects(); |
| 2883 | // } |
| 2884 | // #endif _DEBUG |
| 2885 | |
| 2886 | // Handle interval event for script. |
| 2887 | do { |
| 2888 | RTP_STARTINCTIME(obj_d3xint_time); |
| 2889 | //@$-D3XExecScript(obj, EVT_INTERVAL, obj); |
| 2890 | tOSIRISEventInfo ei; |
| 2891 | ei.evt_interval.frame_time = Frametime; |
| 2892 | ei.evt_interval.game_time = Gametime; |
| 2893 | Osiris_CallEvent(obj, EVT_INTERVAL, &ei); |
| 2894 | RTP_ENDINCTIME(obj_d3xint_time); |
| 2895 | } while (0); // this do{}while(0) is here because the RTP_STARTINCTIME/RTP_ENDINCTIME must be in the same scope |
| 2896 | // and not share scope with another RTP_STARTINCTIME |
| 2897 | |
| 2898 | // #ifdef _DEBUG |
| 2899 | // if(Physics_player_verbose) |
| 2900 | // { |
| 2901 | // debug_check_terrain_objects(); |
| 2902 | // } |
| 2903 | // #endif _DEBUG |
| 2904 | |
| 2905 | // Cast light |
| 2906 | do { |
| 2907 | RTP_STARTINCTIME(obj_objlight_time); |
| 2908 | DoObjectLight(obj); |
| 2909 | RTP_ENDINCTIME(obj_objlight_time); |
| 2910 | } while (0); // this do{}while(0) is here because the RTP_STARTINCTIME/RTP_ENDINCTIME must be in the same scope |
| 2911 | // and not share scope with another RTP_STARTINCTIME |
| 2912 | |
| 2913 | // #ifdef _DEBUG |
| 2914 | // if(Physics_player_verbose) |
| 2915 | // { |
| 2916 | // debug_check_terrain_objects(); |
| 2917 | // } |
| 2918 | // #endif _DEBUG |
| 2919 | |
| 2920 | // if this object is walking/rolling on the terrain, make it not LOD at that point |
| 2921 | if (obj->movement_type == MT_WALKING && (obj->flags & OF_RENDERED) && OBJECT_OUTSIDE(obj)) |
| 2922 | TurnOffLODForCell(CELLNUM(obj->roomnum)); |
| 2923 | |
| 2924 | // #ifdef _DEBUG |
| 2925 | // if(Physics_player_verbose) |
| 2926 | // { |
| 2927 | // debug_check_terrain_objects(); |
| 2928 | // } |
| 2929 | // #endif _DEBUG |
| 2930 | |
| 2931 | // Mark object as not rendered for this frame |
| 2932 | obj->flags &= ~OF_RENDERED; |
| 2933 | |
| 2934 | Frametime = save_frametime; |
| 2935 | } |
| 2936 | |
| 2937 | int Max_used_objects = MAX_OBJECTS - 20; |
| 2938 | float Last_position_history_update[MAX_POSITION_HISTORY]; // gametime of the last position history update of the object |
| 2939 | float Last_position_history_update_time = 0.0f; |
| 2940 | |
| 2941 | //-------------------------------------------------------------------- |
| 2942 | // Process all objects for the current frame |
| 2943 | #define OBJ_POS_SAMPLE_TIME (1.0f / (((float)MAX_POSITION_HISTORY) * 20.0f)) // super sample at 20 fps |
| 2944 | void ObjDoFrameAll() { |
| 2945 | int i; |
| 2946 | object *objp; |
| 2947 | int objs_live = 0; |
| 2948 | bool update_position_history = false; |
| 2949 | |
| 2950 | if (Last_position_history_update_time > Gametime) { |
| 2951 | // the Gametime rolled over (new level) |
| 2952 | update_position_history = true; |
| 2953 | } |
| 2954 | |
| 2955 | if (Gametime >= Last_position_history_update_time + OBJ_POS_SAMPLE_TIME) { |
| 2956 | update_position_history = true; |
| 2957 | } |
| 2958 | |
| 2959 | if (update_position_history) { |
| 2960 | Object_position_head--; |
| 2961 | if (Object_position_head == 255) |
| 2962 | Object_position_head = MAX_POSITION_HISTORY - 1; |
| 2963 | |
| 2964 | Last_position_history_update[Object_position_head] = Gametime; |
| 2965 | Last_position_history_update_time = Gametime; |
| 2966 | } |
| 2967 | |
| 2968 | // MT: seed code removed 9/20/99 because it breaks the randomness of the |
| 2969 | // ambient sound patterns. |
| 2970 | // IMPORTANT NOTE: Because this code could have far-reaching consequences, |
| 2971 | // please DO NOT check this in until after the regular patches for D3 are |
| 2972 | // done. This code should only go in for the Mercenary patch, which will |
| 2973 | // get adequate testing to make sure nothing serious has broken. |
| 2974 | //@@ // Seed timer for this frame |
| 2975 | //@@ int seed=Gametime*1000; |
| 2976 | //@@ ps_srand (seed); |
| 2977 | |
| 2978 | // Does control for soar objects |
| 2979 | if (Soar_active) |
| 2980 | SoarTick(Frametime); |
| 2981 | |
| 2982 | Physics_NumLinked = 0; |
| 2983 | |
| 2984 | // Process each object |
| 2985 | for (i = 0, objp = Objects; i <= Highest_object_index; i++, objp++) { |
| 2986 | if ((objp->type != OBJ_NONE) && (!(objp->flags & OF_DEAD))) { |
| 2987 | RTP_STARTINCTIME(obj_do_frm); |
| 2988 | ObjDoFrame(objp); |
| 2989 | |
| 2990 | if (update_position_history) { |
| 2991 | int slot = Object_map_position_history[OBJNUM(objp)]; |
| 2992 | if (slot != -1) { |
| 2993 | Object_position_samples[slot].pos[Object_position_head] = objp->pos; |
| 2994 | } |
| 2995 | } |
| 2996 | |
| 2997 | RTP_ENDINCTIME(obj_do_frm); |
| 2998 | objs_live++; |
| 2999 | } |
| 3000 | } |
| 3001 | |
| 3002 | // Account for linked objects |
| 3003 | for (i = 0; i < Physics_NumLinked; i++) { |
| 3004 | RTP_STARTINCTIME(phys_link); |
| 3005 | DoPhysLinkedFrame(&Objects[PhysicsLinkList[i]]); |
| 3006 | RTP_ENDINCTIME(phys_link); |
| 3007 | } |
| 3008 | |
| 3009 | // Move vis effects |
| 3010 | { |
| 3011 | RTP_STARTINCTIME(vis_eff_move); |
| 3012 | VisEffectMoveAll(); |
| 3013 | RTP_ENDINCTIME(vis_eff_move); |
| 3014 | } |
| 3015 | |
| 3016 | // Blend all lights that are needed |
| 3017 | BlendAllLightingEdges(); |
| 3018 | |
| 3019 | mprintf_at(1, 5, 40, "Objs=%d ", objs_live); |
| 3020 | |
| 3021 | // Delete everything that died |
| 3022 | ObjDeleteDead(); |
| 3023 | } |
| 3024 | |
| 3025 | #define FUELCEN_SOUND_DELAY 0.25 // play every quarter second |
| 3026 | #define FUELCEN_GIVE_RATE 25 // give 25 units per second |
| 3027 | |
| 3028 | // Give the player fuel. Called when the player is in an energy center |
| 3029 | void RefuelPlayer(object *objp) { |
| 3030 | float max, amount; |
| 3031 | |
| 3032 | ASSERT(objp->type == OBJ_PLAYER); |
| 3033 | ASSERT(Rooms[objp->roomnum].flags & RF_FUELCEN); |
| 3034 | |
| 3035 | max = INITIAL_ENERGY - Players[objp->id].energy; |
| 3036 | amount = FUELCEN_GIVE_RATE * Frametime; |
| 3037 | |
| 3038 | if (amount > max) |
| 3039 | amount = max; |
| 3040 | |
| 3041 | if ((amount > 0)) { |
| 3042 | Players[objp->id].energy += amount; |
| 3043 | |
| 3044 | Sound_system.Play3dSound(SOUND_REFUELING, SND_PRIORITY_HIGH, objp); |
| 3045 | |
| 3046 | ain_hear hear; |
| 3047 | hear.f_directly_player = true; |
| 3048 | hear.hostile_level = 0.01f; |
| 3049 | hear.curiosity_level = 1.0f; |
| 3050 | hear.max_dist = Sounds[SOUND_REFUELING].max_distance; |
| 3051 | AINotify(objp, AIN_HEAR_NOISE, (void *)&hear); |
| 3052 | |
| 3053 | // if (Game_mode & GM_MULTI) |
| 3054 | // multi_send_play_sound(SOUND_REFUEL_STATION_GIVING_FUEL, F1_0/2); |
| 3055 | } |
| 3056 | } |
| 3057 | |
| 3058 | // Clears the secret flag in the specified room, and recursively, all connected rooms |
| 3059 | void ClearSecretFlags(room *rp) { |
| 3060 | int p; |
| 3061 | portal *pp; |
| 3062 | |
| 3063 | rp->flags &= ~RF_SECRET; |
| 3064 | |
| 3065 | for (p = 0, pp = rp->portals; p < rp->num_portals; p++, pp++) { |
| 3066 | room *rp2 = &Rooms[pp->croom]; |
| 3067 | if (rp2->flags & RF_SECRET) |
| 3068 | ClearSecretFlags(rp2); |
| 3069 | } |
| 3070 | } |
| 3071 | // Prints out a message when you've found a secret |
| 3072 | #define SECRET_COLOR GR_RGB(0, 128, 255) |
| 3073 | void DoSecretForPlayer(room *rp, object *objp) { |
| 3074 | int y = Game_window_h / 4; |
| 3075 | AddPersistentHUDMessage(SECRET_COLOR, HUD_MSG_PERSISTENT_CENTER, y, 5, HPF_FADEOUT + HPF_FREESPACE_DRAW, |
| 3076 | SOUND_GAME_MESSAGE, TXT_FOUND_SECRET); |
| 3077 | |
| 3078 | ClearSecretFlags(rp); |
| 3079 | } |
| 3080 | |
| 3081 | // -------------------------------------------------------------------- |
| 3082 | |
| 3083 | // Do refueling centers & damage rooms |
| 3084 | void DoSpecialPlayerStuff(object *objp) { |
| 3085 | if (!OBJECT_OUTSIDE(objp)) { |
| 3086 | room *rp = &Rooms[objp->roomnum]; |
| 3087 | |
| 3088 | // Check for refueling |
| 3089 | if (rp->flags & RF_FUELCEN) |
| 3090 | RefuelPlayer(objp); |
| 3091 | |
| 3092 | if (objp->id == Player_num && (rp->flags & RF_SECRET)) |
| 3093 | DoSecretForPlayer(rp, objp); |
| 3094 | |
| 3095 | // Check for damage room |
| 3096 | if (rp->damage > 0.0) { |
| 3097 | if (!(objp->effect_info->type_flags & EF_NAPALMED)) { |
| 3098 | |
| 3099 | // Set the player on fire |
| 3100 | ASSERT(objp->effect_info); |
| 3101 | objp->effect_info->type_flags |= EF_NAPALMED; |
| 3102 | objp->effect_info->damage_time = 1.0; |
| 3103 | objp->effect_info->damage_per_second = rp->damage; |
| 3104 | if (Gametime - objp->effect_info->last_damage_time > 1.0f) |
| 3105 | objp->effect_info->last_damage_time = 0; |
| 3106 | objp->effect_info->damage_handle = OBJECT_HANDLE_NONE; |
| 3107 | if (objp->effect_info->sound_handle == SOUND_NONE_INDEX) |
| 3108 | objp->effect_info->sound_handle = Sound_system.Play3dSound(SOUND_PLAYER_BURNING, SND_PRIORITY_HIGHEST, objp); |
| 3109 | } |
| 3110 | } |
| 3111 | |
| 3112 | // Check for & set waypoint |
| 3113 | if (rp->flags & RF_WAYPOINT) |
| 3114 | SetAutoWaypoint(objp); |
| 3115 | } else { // outside |
| 3116 | |
| 3117 | // Check for & set waypoint |
| 3118 | // if (Terrain_seg[CELLNUM(objp->roomnum)].flags & TF_WAYPOINT) |
| 3119 | // SetAutoWaypoint(objp); |
| 3120 | } |
| 3121 | } |
| 3122 | |
| 3123 | // Builds the free object list by scanning the list of free objects & adding unused ones to the list |
| 3124 | // Also sets Highest_object_index |
| 3125 | void ResetFreeObjects() { |
| 3126 | int i; |
| 3127 | |
| 3128 | Highest_object_index = -1; |
| 3129 | |
| 3130 | for (i = Num_objects = MAX_OBJECTS; --i >= 0;) |
| 3131 | if (Objects[i].type == OBJ_NONE) |
| 3132 | free_obj_list[--Num_objects] = i; |
| 3133 | else if (Highest_object_index == -1) |
| 3134 | Highest_object_index = i; |
| 3135 | } |
| 3136 | |
| 3137 | // sets the orientation of an object. This should be called to orient an object |
| 3138 | void ObjSetOrient(object *obj, const matrix *orient) { |
| 3139 | // Accounts for if the orientation was set and then this function is being used |
| 3140 | // to update the other stuff |
| 3141 | if (&obj->orient != orient) |
| 3142 | obj->orient = *orient; |
| 3143 | |
| 3144 | // Recompute the orientation dependant information |
| 3145 | if (obj->flags & OF_POLYGON_OBJECT) { |
| 3146 | if (obj->type != OBJ_WEAPON && obj->type != OBJ_DEBRIS && obj->type != OBJ_POWERUP && obj->type != OBJ_ROOM) { |
| 3147 | matrix m; |
| 3148 | |
| 3149 | m = obj->orient; |
| 3150 | vm_TransposeMatrix(&m); |
| 3151 | |
| 3152 | obj->wall_sphere_offset = Poly_models[obj->rtype.pobj_info.model_num].wall_size_offset * m; |
| 3153 | obj->anim_sphere_offset = Poly_models[obj->rtype.pobj_info.model_num].anim_size_offset * m; |
| 3154 | } else { |
| 3155 | obj->wall_sphere_offset = Zero_vector; |
| 3156 | obj->anim_sphere_offset = Zero_vector; |
| 3157 | } |
| 3158 | } |
| 3159 | } |
| 3160 | |
| 3161 | // sets the position of an object. This should be called to move an object |
| 3162 | void ObjSetPos(object *obj, vector *pos, int roomnum, matrix *orient, bool f_update_attached_children) { |
| 3163 | int oldroomnum = obj->roomnum; |
| 3164 | vector old_pos = obj->pos; |
| 3165 | |
| 3166 | // Reset the position & recalculate the AABB |
| 3167 | obj->pos = *pos; |
| 3168 | ObjSetAABB(obj); |
| 3169 | |
| 3170 | // Reset the orientation if changed |
| 3171 | if (orient != NULL) |
| 3172 | ObjSetOrient(obj, orient); |
| 3173 | |
| 3174 | // Clear the outside-mine flag |
| 3175 | obj->flags &= ~OF_OUTSIDE_MINE; |
| 3176 | |
| 3177 | // If changed rooms, do a bunch of stuff |
| 3178 | if (obj->roomnum != roomnum) { |
| 3179 | |
| 3180 | // Let the script know |
| 3181 | tOSIRISEventInfo ei; |
| 3182 | ei.evt_changeseg.room_num = roomnum; |
| 3183 | Osiris_CallEvent(obj, EVT_CHANGESEG, &ei); |
| 3184 | |
| 3185 | if (obj->type == OBJ_PLAYER && !ROOMNUM_OUTSIDE(roomnum) && (Rooms[roomnum].flags & RF_INFORM_RELINK_TO_LG)) { |
| 3186 | Level_goals.Inform(LIT_INTERNAL_ROOM, LGF_COMP_ENTER, roomnum); |
| 3187 | } |
| 3188 | |
| 3189 | // Relink the object |
| 3190 | ObjRelink(OBJNUM(obj), roomnum); |
| 3191 | |
| 3192 | // Call DLL function if the server player changed rooms |
| 3193 | if ((Game_mode & GM_MULTI) && (Netgame.local_role == LR_SERVER)) { |
| 3194 | DLLInfo.me_handle = obj->handle; |
| 3195 | DLLInfo.it_handle = obj->handle; |
| 3196 | DLLInfo.oldseg = oldroomnum; |
| 3197 | DLLInfo.newseg = obj->roomnum; |
| 3198 | |
| 3199 | if (obj->type == OBJ_PLAYER) { |
| 3200 | CallGameDLL(EVT_GAMEPLAYERCHANGESEG, &DLLInfo); |
| 3201 | } else { |
| 3202 | CallGameDLL(EVT_GAMEOBJCHANGESEG, &DLLInfo); |
| 3203 | } |
| 3204 | } |
| 3205 | |
| 3206 | // Slowly change volume lighting if going between rooms, if not in the editor |
| 3207 | if (GetFunctionMode() != EDITOR_MODE) { |
| 3208 | if ((obj->effect_info != NULL) && (obj->effect_info->type_flags & EF_VOLUME_LIT)) { |
| 3209 | if (!ROOMNUM_OUTSIDE(oldroomnum) && !ROOMNUM_OUTSIDE(roomnum)) { |
| 3210 | if (!(obj->effect_info->type_flags & EF_VOLUME_CHANGING)) { |
| 3211 | obj->effect_info->type_flags |= EF_VOLUME_CHANGING; |
| 3212 | obj->effect_info->volume_change_time = 1.0; |
| 3213 | obj->effect_info->volume_old_room = oldroomnum; |
| 3214 | obj->effect_info->volume_old_pos = old_pos; |
| 3215 | } |
| 3216 | } else // either old or new room was outside, so don't do volume changing |
| 3217 | obj->effect_info->type_flags &= ~EF_VOLUME_CHANGING; |
| 3218 | } |
| 3219 | } |
| 3220 | } |
| 3221 | } |
| 3222 | |
| 3223 | // Delete objects, such as weapons & explosions, that shouldn't stay between levels |
| 3224 | // if clear_all is set, clear even proximity bombs |
| 3225 | void ClearTransientObjects(int clear_all) { |
| 3226 | int objnum; |
| 3227 | object *objp; |
| 3228 | |
| 3229 | for (objnum = 0, objp = Objects; objnum <= Highest_object_index; objnum++, objp++) { |
| 3230 | if (((objp->type == OBJ_WEAPON) && !(Weapons[objp->id].flags & WF_COUNTERMEASURE)) || |
| 3231 | (objp->type == OBJ_FIREBALL) || (objp->type == OBJ_DEBRIS) || (objp->type == OBJ_SHARD) || |
| 3232 | (objp->type == OBJ_SHOCKWAVE) || (objp->type == OBJ_PARTICLE) || (objp->type == OBJ_SPLINTER) || |
| 3233 | ((objp->type != OBJ_NONE) && (objp->flags & OF_DYING))) { |
| 3234 | mprintf(0, "Clearing object %d type = %d\n", objnum, objp->type); |
| 3235 | ObjDelete(objnum); |
| 3236 | } |
| 3237 | } |
| 3238 | } |
| 3239 | |
| 3240 | // Remaps all static powerups,sounds,etc to their appropriate indices |
| 3241 | void RemapEverything() { |
| 3242 | RemapStaticIDs(); |
| 3243 | RemapDoors(); |
| 3244 | RemapShips(); |
| 3245 | RemapWeapons(); |
| 3246 | RemapSounds(); |
| 3247 | RemapPolyModels(); |
| 3248 | } |
| 3249 | |
| 3250 | // Retruns a pointer to an object given its handle. Returns NULL if object no longer exists. |
| 3251 | object *ObjGet(int handle) { |
| 3252 | if (handle == OBJECT_HANDLE_NONE) |
| 3253 | return NULL; |
| 3254 | |
| 3255 | if (handle == OBJECT_HANDLE_BAD) { |
| 3256 | Int3(); |
| 3257 | return NULL; |
| 3258 | } |
| 3259 | |
| 3260 | int objnum = handle & HANDLE_OBJNUM_MASK; |
| 3261 | object *objp; |
| 3262 | |
| 3263 | ASSERT((handle & HANDLE_COUNT_MASK) != 0); // count == 0 means never-used object |
| 3264 | ASSERT(objnum < MAX_OBJECTS); |
| 3265 | |
| 3266 | objp = &Objects[objnum]; |
| 3267 | |
| 3268 | if ((objp->type != OBJ_NONE) && (objp->handle == handle)) |
| 3269 | return objp; |
| 3270 | else |
| 3271 | return NULL; |
| 3272 | } |
| 3273 | |
| 3274 | void GetObjectPointInWorld(vector *dest, object *obj, int subnum, int vertnum) { |
| 3275 | poly_model *pm = &Poly_models[obj->rtype.pobj_info.model_num]; |
| 3276 | bsp_info *sm = &pm->submodel[subnum]; |
| 3277 | float normalized_time[MAX_SUBOBJECTS]; |
| 3278 | int i; |
| 3279 | |
| 3280 | if (!pm->new_style) |
| 3281 | return; |
| 3282 | |
| 3283 | for (i = 0; i < MAX_SUBOBJECTS; i++) |
| 3284 | normalized_time[i] = 0.0; |
| 3285 | |
| 3286 | SetModelAnglesAndPos(pm, normalized_time); |
| 3287 | |
| 3288 | vector pnt = sm->verts[vertnum]; |
| 3289 | int mn = subnum; |
| 3290 | matrix m; |
| 3291 | |
| 3292 | // Instance up the tree for this gun |
| 3293 | while (mn != -1) { |
| 3294 | vector tpnt; |
| 3295 | |
| 3296 | vm_AnglesToMatrix(&m, pm->submodel[mn].angs.p, pm->submodel[mn].angs.h, pm->submodel[mn].angs.b); |
| 3297 | vm_TransposeMatrix(&m); |
| 3298 | |
| 3299 | tpnt = pnt * m; |
| 3300 | |
| 3301 | pnt = tpnt + pm->submodel[mn].offset + pm->submodel[mn].mod_pos; |
| 3302 | |
| 3303 | mn = pm->submodel[mn].parent; |
| 3304 | } |
| 3305 | |
| 3306 | // now instance for the entire object |
| 3307 | m = obj->orient; |
| 3308 | vm_TransposeMatrix(&m); |
| 3309 | |
| 3310 | *dest = pnt * m; |
| 3311 | *dest += obj->pos; |
| 3312 | } |
| 3313 | |
| 3314 | bool ObjGetAnimUpdate(uint16_t objnum, custom_anim *multi_anim_info) { |
| 3315 | object *obj = &Objects[objnum]; |
| 3316 | |
| 3317 | if ((objnum >= 0) && (obj->type != OBJ_NONE) && (obj->type != OBJ_WEAPON) && (obj->flags & OF_POLYGON_OBJECT)) { |
| 3318 | polyobj_info *pm = &obj->rtype.pobj_info; |
| 3319 | ai_frame *ai_info = obj->ai_info; |
| 3320 | |
| 3321 | multi_anim_info->server_time = Gametime; |
| 3322 | multi_anim_info->server_anim_frame = (uint16_t)(pm->anim_frame * 256.0f); |
| 3323 | |
| 3324 | multi_anim_info->anim_start_frame = pm->anim_start_frame; |
| 3325 | multi_anim_info->anim_end_frame = pm->anim_end_frame; |
| 3326 | multi_anim_info->anim_time = pm->anim_time; |
| 3327 | multi_anim_info->max_speed = pm->max_speed; |
| 3328 | |
| 3329 | multi_anim_info->flags = 0; |
| 3330 | |
| 3331 | if (pm->anim_flags & AIAF_LOOPING) |
| 3332 | multi_anim_info->flags |= FMA_LOOPING; |
| 3333 | |
| 3334 | if (obj->ai_info != NULL) { |
| 3335 | multi_anim_info->anim_sound_index = obj->ai_info->last_played_sound_index; |
| 3336 | multi_anim_info->flags |= FMA_HAS_AI; |
| 3337 | } else { |
| 3338 | multi_anim_info->anim_sound_index = -1; |
| 3339 | } |
| 3340 | |
| 3341 | return true; |
| 3342 | } |
| 3343 | |
| 3344 | return false; |
| 3345 | } |
| 3346 | |
| 3347 | void SetObjectControlType(object *obj, int control_type) { |
| 3348 | ASSERT(obj); |
| 3349 | ASSERT(OBJNUM(obj) >= 0 && OBJNUM(obj) < MAX_OBJECTS); |
| 3350 | |
| 3351 | if ((control_type == CT_AI) && (obj->ai_info == NULL)) { |
| 3352 | poly_model *pm = &Poly_models[obj->rtype.pobj_info.model_num]; |
| 3353 | polyobj_info *p_info = &obj->rtype.pobj_info; |
| 3354 | int num_wbs = pm->num_wbs; |
| 3355 | int count = 0; |
| 3356 | int i; |
| 3357 | |
| 3358 | obj->ai_info = (ai_frame *)mem_malloc(sizeof(ai_frame)); |
| 3359 | memset(obj->ai_info, 0x00, sizeof(ai_frame)); // DAJ clear the baby |
| 3360 | |
| 3361 | for (i = 0; i < num_wbs; i++) { |
| 3362 | ASSERT(pm->poly_wb[i].num_turrets >= 0 && pm->poly_wb[i].num_turrets <= 6400); |
| 3363 | count += pm->poly_wb[i].num_turrets; |
| 3364 | } |
| 3365 | |
| 3366 | p_info->multi_turret_info.num_turrets = count; |
| 3367 | |
| 3368 | if ((count > 0) && (p_info->multi_turret_info.keyframes == NULL)) { |
| 3369 | int cur = 0; |
| 3370 | |
| 3371 | p_info->multi_turret_info.time = 0; |
| 3372 | p_info->multi_turret_info.keyframes = (float *)mem_malloc(sizeof(float) * count); |
| 3373 | p_info->multi_turret_info.last_keyframes = (float *)mem_malloc(sizeof(float) * count); |
| 3374 | p_info->multi_turret_info.flags = 0; |
| 3375 | } |
| 3376 | } |
| 3377 | |
| 3378 | obj->control_type = control_type; |
| 3379 | |
| 3380 | if (obj->control_type == CT_AI || obj->type == OBJ_PLAYER) { |
| 3381 | poly_model *pm = &Poly_models[obj->rtype.pobj_info.model_num]; |
| 3382 | int num_wbs = pm->num_wbs; |
| 3383 | |
| 3384 | if (obj->dynamic_wb == NULL) { |
| 3385 | if (obj->type == OBJ_PLAYER) { |
| 3386 | obj->dynamic_wb = (dynamic_wb_info *)mem_malloc(sizeof(dynamic_wb_info) * MAX_WBS_PER_OBJ); |
| 3387 | } else { |
| 3388 | if (num_wbs) |
| 3389 | obj->dynamic_wb = (dynamic_wb_info *)mem_malloc(sizeof(dynamic_wb_info) * num_wbs); |
| 3390 | } |
| 3391 | } |
| 3392 | } |
| 3393 | } |
| 3394 | |
| 3395 | void ObjSetAnimUpdate(uint16_t objnum, custom_anim *multi_anim_info) { |
| 3396 | object *obj = &Objects[objnum]; |
| 3397 | polyobj_info *pm; |
| 3398 | |
| 3399 | if ((objnum >= 0) && (obj->type != OBJ_NONE) && (obj->type != OBJ_WEAPON) && (obj->flags & OF_POLYGON_OBJECT)) { |
| 3400 | pm = &obj->rtype.pobj_info; |
| 3401 | pm->multi_anim_info = *multi_anim_info; |
| 3402 | |
| 3403 | // Make sure we mark it as current and |
| 3404 | pm->multi_anim_info.flags |= FMA_VALID; |
| 3405 | pm->multi_anim_info.flags &= ~FMA_CURRENT; |
| 3406 | } |
| 3407 | } |
| 3408 | |
| 3409 | void ObjGetTurretUpdate(uint16_t objnum, multi_turret *multi_turret_info) { |
| 3410 | object *obj = &Objects[objnum]; |
| 3411 | poly_model *pm = &Poly_models[obj->rtype.pobj_info.model_num]; |
| 3412 | polyobj_info *p_info = &obj->rtype.pobj_info; |
| 3413 | |
| 3414 | if ((objnum >= 0) && (obj->type != OBJ_NONE) && (obj->type != OBJ_WEAPON) && (obj->flags & OF_POLYGON_OBJECT) && |
| 3415 | (p_info->multi_turret_info.num_turrets)) { |
| 3416 | int i; |
| 3417 | int j; |
| 3418 | int count = 0; |
| 3419 | |
| 3420 | multi_turret_info->time = Gametime; |
| 3421 | multi_turret_info->num_turrets = p_info->multi_turret_info.num_turrets; |
| 3422 | |
| 3423 | for (i = 0; i < pm->num_wbs; i++) { |
| 3424 | for (j = 0; j < pm->poly_wb[i].num_turrets; j++) { |
| 3425 | multi_turret_info->keyframes[count++] = obj->dynamic_wb[i].norm_turret_angle[j]; |
| 3426 | } |
| 3427 | } |
| 3428 | } |
| 3429 | } |
| 3430 | |
| 3431 | void ObjSetTurretUpdate(uint16_t objnum, multi_turret *multi_turret_info) { |
| 3432 | object *obj = &Objects[objnum]; |
| 3433 | poly_model *pm = &Poly_models[obj->rtype.pobj_info.model_num]; |
| 3434 | polyobj_info *p_info = &obj->rtype.pobj_info; |
| 3435 | |
| 3436 | if ((objnum >= 0) && (obj->type != OBJ_NONE) && (obj->type != OBJ_WEAPON) && (obj->flags & OF_POLYGON_OBJECT) && |
| 3437 | (p_info->multi_turret_info.num_turrets)) { |
| 3438 | int i; |
| 3439 | |
| 3440 | p_info->multi_turret_info.time = multi_turret_info->time; |
| 3441 | |
| 3442 | for (i = 0; i < p_info->multi_turret_info.num_turrets; i++) { |
| 3443 | p_info->multi_turret_info.keyframes[i] = multi_turret_info->keyframes[i]; |
| 3444 | } |
| 3445 | |
| 3446 | p_info->multi_turret_info.flags = FMT_NEW_DATA; |
| 3447 | } else { |
| 3448 | mprintf(0, "Woops, no turret here to update!\n"); |
| 3449 | } |
| 3450 | } |
| 3451 | |
| 3452 | // Returns the original parent for the given object. Returns self if it has no parent |
| 3453 | object *ObjGetUltimateParent(object *child) { |
| 3454 | ASSERT(child); |
| 3455 | |
| 3456 | object *ret = child; |
| 3457 | int handle; |
| 3458 | |
| 3459 | handle = child->parent_handle; |
| 3460 | |
| 3461 | while (ObjGet(handle)) { |
| 3462 | ret = ObjGet(handle); |
| 3463 | handle = ret->parent_handle; |
| 3464 | } |
| 3465 | return ret; |
| 3466 | } |
| 3467 | |
| 3468 | // Sets an object to a type OBJ_DUMMY (saves it's old type) so it won't be renderered, etc, but still alive |
| 3469 | void ObjGhostObject(int objnum) { |
| 3470 | ASSERT(objnum >= 0 && objnum < MAX_OBJECTS); |
| 3471 | if (objnum < 0 || objnum >= MAX_OBJECTS) |
| 3472 | return; |
| 3473 | |
| 3474 | object *obj = &Objects[objnum]; |
| 3475 | |
| 3476 | ASSERT(obj->type != OBJ_NONE); |
| 3477 | ASSERT(obj->type != OBJ_DUMMY); // Don't ghost a ghosted object!! |
| 3478 | ASSERT(obj->type != OBJ_PLAYER); |
| 3479 | ASSERT(obj->type != OBJ_GHOST); |
| 3480 | |
| 3481 | if (obj->type == OBJ_NONE || obj->type == OBJ_DUMMY || obj->type == OBJ_PLAYER || obj->type == OBJ_GHOST) |
| 3482 | return; |
| 3483 | |
| 3484 | obj->dummy_type = obj->type; |
| 3485 | obj->type = OBJ_DUMMY; |
| 3486 | } |
| 3487 | |
| 3488 | // Restores a ghosted object back to it's old type |
| 3489 | void ObjUnGhostObject(int objnum) { |
| 3490 | ASSERT(objnum >= 0 && objnum < MAX_OBJECTS); |
| 3491 | if (objnum < 0 || objnum >= MAX_OBJECTS) |
| 3492 | return; |
| 3493 | |
| 3494 | object *obj = &Objects[objnum]; |
| 3495 | |
| 3496 | ASSERT(obj->type == OBJ_DUMMY); |
| 3497 | |
| 3498 | if (obj->type != OBJ_DUMMY) |
| 3499 | return; |
| 3500 | |
| 3501 | //@@ASSERT (!(obj->flags&OF_INPLAYERINVENTORY)); |
| 3502 | //@@if(obj->flags&OF_INPLAYERINVENTORY) |
| 3503 | //@@ return; |
| 3504 | if (obj->flags & OF_INPLAYERINVENTORY) { |
| 3505 | mprintf(0, "UnGhosting Object in that is currently in a player's inventory!\n"); |
| 3506 | } |
| 3507 | |
| 3508 | obj->type = obj->dummy_type; |
| 3509 | obj->dummy_type = OBJ_NONE; |
| 3510 | } |