| 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/ObjInit.cpp $ |
| 21 | * $Revision: 170 $ |
| 22 | * $Date: 4/19/00 5:18p $ |
| 23 | * $Author: Matt $ |
| 24 | * |
| 25 | * Functions to initialize objects |
| 26 | * |
| 27 | * $Log: /DescentIII/main/ObjInit.cpp $ |
| 28 | * |
| 29 | * 170 4/19/00 5:18p Matt |
| 30 | * From Duane for 1.4 |
| 31 | * Added check for ai_info |
| 32 | * |
| 33 | * 169 3/20/00 12:18p Matt |
| 34 | * Merge of Duane's post-1.3 changes. |
| 35 | * msize change (Mac only) |
| 36 | * |
| 37 | * 168 2/22/00 10:00a Matt |
| 38 | * Fixed Jason's typo |
| 39 | * |
| 40 | * 167 2/19/00 6:44p Jason |
| 41 | * Fixed out of bounds weapon problem |
| 42 | * |
| 43 | * 166 10/24/99 9:33a Chris |
| 44 | * Cleaned a little more Mac code |
| 45 | * |
| 46 | * 165 10/22/99 10:59p Matt |
| 47 | * Added check for anim data before renferencing it. |
| 48 | * |
| 49 | * 164 10/22/99 11:30a Matt |
| 50 | * Mac merge |
| 51 | * |
| 52 | * 163 7/28/99 5:18p Kevin |
| 53 | * Mac merge fixes |
| 54 | * |
| 55 | * 162 7/28/99 3:50p Kevin |
| 56 | * Mac! |
| 57 | * |
| 58 | * 161 5/20/99 7:54p 3dsmax |
| 59 | * added better memory support changing ships |
| 60 | * |
| 61 | * 160 5/19/99 3:54p Jeff |
| 62 | * error is scripts are being bound to an object more than once |
| 63 | * |
| 64 | * 159 5/08/99 6:20p Jason |
| 65 | * fixed framerate wiggle problem |
| 66 | * |
| 67 | * 158 4/28/99 5:09p Jason |
| 68 | * fixed some bugs with latest build |
| 69 | * |
| 70 | * 157 4/27/99 4:44p Jason |
| 71 | * fixed moving buildings not getting lit |
| 72 | * |
| 73 | * 156 4/22/99 8:29p Kevin |
| 74 | * made psrand.h come after stdlib.h |
| 75 | * |
| 76 | * 155 4/21/99 1:23p Chris |
| 77 | * Added the check ceiling checkbox for generic objects |
| 78 | * |
| 79 | * 154 4/21/99 11:05a Kevin |
| 80 | * new ps_rand and ps_srand to replace rand & srand |
| 81 | * |
| 82 | * 153 4/20/99 3:33p Matt |
| 83 | * ObjInit() was bashing creation time after setting it. |
| 84 | * |
| 85 | * 152 4/20/99 2:44p Matt |
| 86 | * Deal with initializing a generic object whose ID isn't defined. This |
| 87 | * can happen if an object is deleted and the level in memory uses that |
| 88 | * object. |
| 89 | * |
| 90 | * 151 4/20/99 12:24p Matt |
| 91 | * Re-revised the ObjInit() system. ObjInit() again does all the |
| 92 | * initialization stuff, but now it's passed a lot more information so |
| 93 | * those fields can be set before the rest of the initialization takes |
| 94 | * place. |
| 95 | * |
| 96 | * 150 4/18/99 5:33p Jason |
| 97 | * fixed object multiplayer problem |
| 98 | * |
| 99 | * 149 4/18/99 4:50p Matt |
| 100 | * Took out code that hacked in ammo amounts for weapon powerups, and |
| 101 | * added code to set the counts on the page and read and write to the |
| 102 | * table file. |
| 103 | * |
| 104 | * 148 4/15/99 1:42a Jeff |
| 105 | * changes for linux compile |
| 106 | * |
| 107 | * 147 4/14/99 3:57a Jeff |
| 108 | * fixed case mismatch in #includes |
| 109 | * |
| 110 | * 146 4/12/99 6:11p Jason |
| 111 | * fix clutter objects so that they are volume lit as well |
| 112 | * |
| 113 | * 145 4/12/99 3:53p Matt |
| 114 | * Page in polymodel for markers so model size is right. |
| 115 | * |
| 116 | * 144 4/10/99 5:56p Matt |
| 117 | * Cleaned up object initialization code, including create object & load |
| 118 | * object. |
| 119 | * |
| 120 | * 143 4/08/99 6:38p Matt |
| 121 | * Improved message. |
| 122 | * |
| 123 | * 142 4/08/99 6:15p Matt |
| 124 | * Deal with generic objects that have changed type. |
| 125 | * |
| 126 | * 141 4/05/99 10:54a Matt |
| 127 | * Added auto-waypoint system |
| 128 | * |
| 129 | * 140 3/02/99 4:54p Matt |
| 130 | * Took out assert |
| 131 | * |
| 132 | * 139 3/02/99 12:22p Matt |
| 133 | * Revisions to weapon & ammo powerups. Not fully tested. |
| 134 | * |
| 135 | * 138 2/25/99 11:01a Matt |
| 136 | * Added new explosion system. |
| 137 | * |
| 138 | * 137 2/22/99 2:04p Jason |
| 139 | * added different damages for players and generics |
| 140 | * |
| 141 | * 136 2/21/99 4:20p Matt |
| 142 | * Added SoundSource objects (and reformatted parts of the object header |
| 143 | * files). |
| 144 | * |
| 145 | * 135 2/15/99 6:10p Chris |
| 146 | * |
| 147 | * 134 2/10/99 1:47p Matt |
| 148 | * Changed object handle symbolic constants |
| 149 | * |
| 150 | * 133 2/04/99 2:05p Matt |
| 151 | * Added blastable doors |
| 152 | * |
| 153 | * 132 2/02/99 8:43a Chris |
| 154 | * I made buildings with AI work correctly (ie really big robots should be |
| 155 | * buildings) |
| 156 | * anim to and from states are now shorts instead of bytes |
| 157 | * |
| 158 | * 131 1/28/99 11:32a Jason |
| 159 | * added marker cameras |
| 160 | * |
| 161 | * 130 1/27/99 6:08p Jason |
| 162 | * first pass at markers |
| 163 | * |
| 164 | * 129 1/21/99 11:15p Jeff |
| 165 | * pulled out some structs and defines from header files and moved them |
| 166 | * into seperate header files so that multiplayer dlls don't require major |
| 167 | * game headers, just those new headers. Side effect is a shorter build |
| 168 | * time. Also cleaned up some header file #includes that weren't needed. |
| 169 | * This affected polymodel.h, object.h, player.h, vecmat.h, room.h, |
| 170 | * manage.h and multi.h |
| 171 | * |
| 172 | * 128 1/13/99 6:38a Jeff |
| 173 | * fixed object.h. There were numerous struct declarations that were the |
| 174 | * same name as the instance of the struct (gcc doesn't like this). |
| 175 | * Changed the struct name. Also added some #ifdef's for linux build, |
| 176 | * along with fixing case-sensitive includes |
| 177 | * |
| 178 | * 127 1/13/99 2:29a Chris |
| 179 | * Massive AI, OSIRIS update |
| 180 | * |
| 181 | * 126 1/08/99 2:56p Samir |
| 182 | * Ripped out OSIRIS1. |
| 183 | * |
| 184 | * 125 10/29/98 6:15p Chris |
| 185 | * Made a minimum rotdrag for robots |
| 186 | * |
| 187 | * 124 10/22/98 5:36p Chris |
| 188 | * Fixed ObjGet bugs |
| 189 | * |
| 190 | * 123 10/19/98 7:18p Matt |
| 191 | * Added system to support different types of damage to the player and |
| 192 | * have these different types make different sounds. |
| 193 | * |
| 194 | * 122 10/15/98 6:46p Chris |
| 195 | * Added custom size for weapons |
| 196 | * |
| 197 | * 121 10/13/98 5:48p Jeff |
| 198 | * CHRISHACK -- multiplayer ship hack for attach points -- DEMO SAFE |
| 199 | * |
| 200 | * 120 10/13/98 3:58p Kevin |
| 201 | * changed free to mem_free |
| 202 | * |
| 203 | * 119 10/11/98 10:53p Matt |
| 204 | * Fixed some zero-length malloc()s |
| 205 | * |
| 206 | * 118 10/11/98 2:40p Matt |
| 207 | * Added some error checking to ObjInitGeneric() |
| 208 | * |
| 209 | * 117 10/09/98 3:32p Kevin |
| 210 | * New memory library |
| 211 | * |
| 212 | * 116 10/08/98 4:23p Kevin |
| 213 | * Changed code to comply with memory library usage. Always use mem_malloc |
| 214 | * , mem_free and mem_strdup |
| 215 | * |
| 216 | * 115 10/02/98 1:47p Jason |
| 217 | * added lod player ships |
| 218 | * |
| 219 | * 114 9/28/98 4:09p Chris |
| 220 | * Added birth animations |
| 221 | * |
| 222 | * 113 9/22/98 3:55p Samir |
| 223 | * ifdef out stuff for non-debug version. |
| 224 | * |
| 225 | * 112 8/26/98 12:09p Jason |
| 226 | * made object reinitialization not undo lightmaps |
| 227 | * |
| 228 | * 111 8/25/98 4:40p Samir |
| 229 | * small sequencing prob, |
| 230 | * |
| 231 | * 110 8/25/98 3:44p Sean |
| 232 | * moved control intitalization of player to after polymodel is paged in. |
| 233 | * |
| 234 | * 109 8/18/98 12:48p Jason |
| 235 | * made debris objects have volume lighting |
| 236 | * |
| 237 | * 108 8/12/98 6:37p Jeff |
| 238 | * removed init stuff for OBJ_DUMMY |
| 239 | * |
| 240 | * 107 8/03/98 4:29p Chris |
| 241 | * Added additional support for the attach system |
| 242 | * |
| 243 | * 106 8/03/98 4:29p Jason |
| 244 | * took out presets for ship physics flags |
| 245 | * |
| 246 | * 105 7/28/98 12:29p Jason |
| 247 | * added rotational velocity to multiplayer position packets |
| 248 | * |
| 249 | * 104 7/20/98 2:06p Chris |
| 250 | * Added the precomputation of some weapons (fixed speed weapons). This |
| 251 | * algorithm can be expanded to include some missiles with some minor |
| 252 | * work. |
| 253 | * |
| 254 | * 103 7/07/98 7:34p Jeff |
| 255 | * created object type, OBJ_DUMMY |
| 256 | * |
| 257 | * 102 7/06/98 12:22p Keneta |
| 258 | * Fixed a bug with dynamically allocated weapon batteries |
| 259 | * |
| 260 | * 101 7/02/98 2:47p Chris |
| 261 | * Dynamic weapon info is now dynamically allocated |
| 262 | * |
| 263 | * 100 6/12/98 4:07p Jason |
| 264 | * added dynamic volume lighting to objects |
| 265 | * |
| 266 | * 99 6/11/98 12:48p Jason |
| 267 | * added better spewing weapons |
| 268 | * |
| 269 | * 98 5/21/98 12:34p Jason |
| 270 | * made particles drop differently |
| 271 | * |
| 272 | * 97 5/19/98 4:42a Chris |
| 273 | * Added shockwave's -- enjoy. :) |
| 274 | * |
| 275 | * 96 5/15/98 5:41p Jason |
| 276 | * implemented volume lighting system |
| 277 | * |
| 278 | * 95 5/14/98 12:56p Jason |
| 279 | * changes to help lower memory usage |
| 280 | * |
| 281 | * 94 5/12/98 11:58a Chris |
| 282 | * Offset animation's for generic objects |
| 283 | * |
| 284 | * 93 5/11/98 4:40p Chris |
| 285 | * AI info is now a malloc'ed pointer |
| 286 | * |
| 287 | * 92 5/07/98 2:22p Chris |
| 288 | * Hit die dot |
| 289 | * |
| 290 | * 91 5/04/98 3:51p Matt |
| 291 | * Finished (for now) with breaking glass. |
| 292 | * |
| 293 | * 90 5/04/98 12:28p Matt |
| 294 | * Added shard objects |
| 295 | * |
| 296 | * 89 5/01/98 3:38p Chris |
| 297 | * Leveling defaults off |
| 298 | * |
| 299 | * 88 5/30/98 10:16p Chris |
| 300 | * Fixed some bad spelling |
| 301 | * |
| 302 | * 87 4/30/98 11:32a Chris |
| 303 | * ClearWB to WBClear |
| 304 | * |
| 305 | * 86 4/22/98 3:25p Jason |
| 306 | * changes for multiplayer debugging |
| 307 | * |
| 308 | * 85 4/19/98 5:00p Jason |
| 309 | * added cool napalm effect, plus made object effects dynamically |
| 310 | * allocated |
| 311 | * |
| 312 | * 84 4/17/98 1:59p Jason |
| 313 | * added cool object effects |
| 314 | * |
| 315 | * 83 4/16/98 2:56p Chris |
| 316 | * Updated buddy support and intergrated scripting and AI |
| 317 | * |
| 318 | * 82 4/15/98 8:38p Jason |
| 319 | * fixed some multiplayer issues |
| 320 | * |
| 321 | * 81 4/15/98 12:56p Chris |
| 322 | * Updated parent_handle support and added buddy bot support |
| 323 | * |
| 324 | * 80 4/03/98 11:27a Chris |
| 325 | * Doubled the size of powerups |
| 326 | * |
| 327 | * 79 4/03/98 10:07a Chris |
| 328 | * Added support for objects getting their size computed when the |
| 329 | * polymodel is paged in the first time as an object |
| 330 | * |
| 331 | * 78 4/02/98 6:38p Jason |
| 332 | * page in low-res models with generic objects |
| 333 | * |
| 334 | * 77 4/02/98 3:54p Jason |
| 335 | * first pass in getting polymodel paging to work |
| 336 | * |
| 337 | * 76 3/31/98 6:11p Jason |
| 338 | * took out auto ship selection |
| 339 | * |
| 340 | * 75 3/30/98 6:58p Matt |
| 341 | * When reinitializing an object, don't bash its custom script. |
| 342 | * |
| 343 | * 74 3/30/98 6:20p Matt |
| 344 | * Renamed ResetObject() to be ObjReInitAll() |
| 345 | * |
| 346 | * 73 3/20/98 5:51p Jason |
| 347 | * more changes for multiplayer |
| 348 | * |
| 349 | * 72 3/19/98 7:15p Jason |
| 350 | * more changes for multiplayer |
| 351 | * |
| 352 | * 71 3/13/98 5:55p Chris |
| 353 | * Added the new collision spheres |
| 354 | * |
| 355 | * 70 3/11/98 4:59p Chris |
| 356 | * Changed the ComputeDefualtSize function call |
| 357 | * |
| 358 | * 69 3/09/98 10:49a Chris |
| 359 | * Worked on the homing code |
| 360 | * |
| 361 | * 68 2/25/98 2:06p Jason |
| 362 | * fixed objinit player to give you different ships in the correct order |
| 363 | * |
| 364 | * 67 2/25/98 12:32p Jason |
| 365 | * added a new player ship for multiplayer games |
| 366 | * |
| 367 | * 66 2/23/98 4:52p Chris |
| 368 | * Removed size hack |
| 369 | * |
| 370 | * 65 2/17/98 8:17p Jeff |
| 371 | * hacked a player ship size in for the milestone |
| 372 | * |
| 373 | * 64 2/17/98 8:16p Jeff |
| 374 | * Call compute default size for player ships |
| 375 | * |
| 376 | * 63 2/16/98 4:41p Jason |
| 377 | * took out starhawk ship (again!) |
| 378 | * |
| 379 | * 62 2/16/98 2:47a Chris |
| 380 | * Massive improvements to the animation system and the AI |
| 381 | * |
| 382 | * 61 2/11/98 6:58p Matt |
| 383 | * Changed the way cameras are rendered, so they show up on the terrain as |
| 384 | * well. |
| 385 | * |
| 386 | * 60 2/10/98 7:02p Jason |
| 387 | * fixed lighting render type for rooms |
| 388 | * |
| 389 | * 59 2/09/98 7:28p Matt |
| 390 | * Added a rendering type for external room so we could check against |
| 391 | * render type == RT_NONE |
| 392 | * |
| 393 | * 58 2/03/98 1:06p Jason |
| 394 | * tidied up some multiplayer loose ends |
| 395 | * |
| 396 | * 57 1/30/98 12:13p Jason |
| 397 | * give weapons lifetime |
| 398 | * |
| 399 | * 56 1/29/98 5:49p Matt |
| 400 | * Changed old camera object type to be viewer object (for editor), and |
| 401 | * now camera objects will just be for game cameras. |
| 402 | * |
| 403 | * 55 1/29/98 3:29p Chris |
| 404 | * Major update to the AI system. |
| 405 | * |
| 406 | * 54 1/28/98 12:00p Jason |
| 407 | * more changes for multiplayer |
| 408 | * |
| 409 | * 53 1/23/98 6:25p Jason |
| 410 | * Got spray weapons working |
| 411 | * |
| 412 | * 52 1/23/98 11:21a Jason |
| 413 | * incremental multiplayer checkin |
| 414 | * |
| 415 | * 51 1/20/98 4:12p Samir |
| 416 | * New script housekeeping system. |
| 417 | * |
| 418 | * 50 1/18/98 9:05p Matt |
| 419 | * Changed a comment, and deleted some unused code |
| 420 | * |
| 421 | * 49 1/10/98 2:24p Jason |
| 422 | * better multiplayer code checked in |
| 423 | * |
| 424 | * 48 12/08/97 6:18p Jason |
| 425 | * more tweaks for destroyable buildings |
| 426 | * |
| 427 | * 47 12/05/97 6:38p Chris |
| 428 | * Fixed bug with impact_size initialization |
| 429 | * |
| 430 | * 46 12/01/97 9:54a Chris |
| 431 | * Added support for concussive forces, generalized robot collisions to |
| 432 | * generic collisions |
| 433 | * |
| 434 | * 45 11/04/97 6:18p Chris |
| 435 | * Added support so that the player ship uses the robot's firing dialog. |
| 436 | * |
| 437 | * 44 10/28/97 12:21p Chris |
| 438 | * Unified AIInit |
| 439 | * |
| 440 | * 43 10/23/97 11:34p Chris |
| 441 | * Fixed problems with idle animations |
| 442 | * |
| 443 | * 42 10/23/97 5:36p Jason |
| 444 | * added splinter objects (probably temporary) |
| 445 | * |
| 446 | * 41 10/21/97 11:57a Jason |
| 447 | * added ability to set dying model for player ship |
| 448 | * |
| 449 | * 40 10/20/97 6:10p Jason |
| 450 | * added of_polygon_object flag to debris stuff |
| 451 | * |
| 452 | * 39 10/20/97 6:02p Jason |
| 453 | * fixed dumb objweapon bug |
| 454 | * |
| 455 | * 38 10/20/97 5:54p Jason |
| 456 | * added polygon_object flag |
| 457 | * |
| 458 | * 37 10/20/97 4:59p Jason |
| 459 | * made player ships render with gouraud shading |
| 460 | * |
| 461 | * 36 10/20/97 4:46p Jason |
| 462 | * changes for explosions |
| 463 | * |
| 464 | * 35 10/17/97 5:09p Jason |
| 465 | * added more fireball stuff |
| 466 | * |
| 467 | * 34 10/05/97 5:31a Chris |
| 468 | * Make AI init match ai_init_all in aimain.cpp |
| 469 | * |
| 470 | * 33 10/03/97 5:18p Chris |
| 471 | * Added OBJ_LINE as a new type |
| 472 | * |
| 473 | * 32 10/03/97 4:43p Chris |
| 474 | * added debug fvi call and object type line |
| 475 | * |
| 476 | * 31 10/01/97 7:51p Matt |
| 477 | * Added code for external rooms |
| 478 | * |
| 479 | * 30 10/01/97 12:39p Chris |
| 480 | * Added support for new physics values in generic objects |
| 481 | * |
| 482 | * 29 9/30/97 6:40p Jason |
| 483 | * got lightmap stuff sort of working with objects |
| 484 | * |
| 485 | * 28 9/30/97 1:15p Matt |
| 486 | * Made player objects other than player 0 have physics and control types |
| 487 | * of none |
| 488 | * |
| 489 | * 27 9/24/97 6:18p Samir |
| 490 | * Use script names instead of script id values to identify scripts. |
| 491 | * |
| 492 | * 26 9/22/97 6:18p Matt |
| 493 | * Removed include of stub.h |
| 494 | * |
| 495 | * 25 9/19/97 9:37p Chris |
| 496 | * Attempted to fix door collisions -- almost there, but not quite |
| 497 | * |
| 498 | * 24 9/15/97 5:21a Chris |
| 499 | * Fixed the weapon fixed rotate initialization |
| 500 | * |
| 501 | * 23 9/11/97 5:38p Jason |
| 502 | * initial door coding for room engine |
| 503 | * |
| 504 | * 22 9/10/97 3:58p Samir |
| 505 | * Initialize custom script handle to -1 |
| 506 | * |
| 507 | * 21 9/05/97 1:29p Jason |
| 508 | * revamped generic object lighting |
| 509 | * |
| 510 | * 20 9/04/97 3:21p Jason |
| 511 | * added pulse timing for lit objects |
| 512 | * |
| 513 | * 19 9/03/97 6:17p Jason |
| 514 | * added code to support powerups/robots/etc that cast light |
| 515 | * |
| 516 | * 18 9/03/97 3:54p Jason |
| 517 | * got objects to cast light |
| 518 | * |
| 519 | * 17 9/03/97 2:12p Chris |
| 520 | * Added new weapon battery system and made the animation system usable. |
| 521 | * |
| 522 | * 16 8/21/97 5:56p Samir |
| 523 | * Took out script specific stuff from ObjInit and moved to ObjScript |
| 524 | * |
| 525 | * 15 8/18/97 1:42a Chris |
| 526 | * Fixed the flags = 0 bug. Remove an ASSERT that broke the debris code. |
| 527 | * Until the debris creation is changed, the assert will have to remain |
| 528 | * removed. |
| 529 | * |
| 530 | * 14 8/13/97 4:54p Matt |
| 531 | * Added destroyable flag & hitpoints |
| 532 | * |
| 533 | * 13 8/12/97 5:29p Matt |
| 534 | * Added support for clutter & building types |
| 535 | * |
| 536 | * 12 8/12/97 3:23p Samir |
| 537 | * Added code to initialize scripts for objects. |
| 538 | * |
| 539 | * 11 8/11/97 1:53p Matt |
| 540 | * Ripped out robot & powerup pages, and added generic page |
| 541 | * |
| 542 | * 10 8/07/97 4:47p Chris |
| 543 | * Massively expanded the weapon system. Not done yet. |
| 544 | * |
| 545 | * 9 8/06/97 4:33p Chris |
| 546 | * Expanded the weapons page |
| 547 | * |
| 548 | * 8 8/06/97 1:35p Matt |
| 549 | * Changes for new generic object_info struct which replace robot-specific |
| 550 | * structure |
| 551 | * |
| 552 | * 7 7/28/97 1:14p Chris |
| 553 | * Added support for sub-object visability. Plus, debris. |
| 554 | * |
| 555 | * 6 7/15/97 7:29p Chris |
| 556 | * Added a sound for helicopter blades. |
| 557 | * |
| 558 | * 5 7/15/97 5:35p Chris |
| 559 | * New AI code |
| 560 | * |
| 561 | * 4 7/15/97 4:59p Chris |
| 562 | * added support for AI and animations |
| 563 | * |
| 564 | * 10 6/30/97 5:23p Chris |
| 565 | * |
| 566 | * 9 6/25/97 9:28p Chris |
| 567 | * Added code to allow for robots that are unmovable and/or with/without |
| 568 | * AI. |
| 569 | * |
| 570 | * 8 5/15/97 6:09p Chris |
| 571 | * |
| 572 | * 7 4/24/97 5:42p Jason |
| 573 | * got fireball vclips working |
| 574 | * |
| 575 | * 6 4/16/97 11:50a Jason |
| 576 | * finally got weapons to fire |
| 577 | * |
| 578 | * 5 4/15/97 6:32p Chris |
| 579 | * Added some temporary stuff to get weapons firing. |
| 580 | * |
| 581 | * 4 4/15/97 2:28p Jason |
| 582 | * trying to get weapon firing working...it won't due to a (i think) |
| 583 | * physics bug. Checked in so Chris can have a look. |
| 584 | * |
| 585 | * |
| 586 | * 3 4/08/97 2:00a Chris |
| 587 | * Made powerups always bouncy and have unlimitted |
| 588 | * bounce. This will change as time goes on. |
| 589 | * |
| 590 | * 2 4/04/97 2:57p Matt |
| 591 | * Added code to initialize all the type-specific data for an object from |
| 592 | * the page for that object type. This means that we need to pass less |
| 593 | * info to ObjCreate(), and that we save less info in the level save file. |
| 594 | * It also makes it easy to reset all the objects when an object page has |
| 595 | * changed. |
| 596 | * |
| 597 | * 1 4/04/97 10:01a Matt |
| 598 | * |
| 599 | * $NoKeywords: $ |
| 600 | */ |
| 601 | #include "objinit.h" |
| 602 | #include "player.h" |
| 603 | #include "ship.h" |
| 604 | #include "pserror.h" |
| 605 | #include "physics.h" |
| 606 | #include "weapon.h" |
| 607 | #include "AIMain.h" |
| 608 | #include "fireball.h" |
| 609 | #include "objinfo.h" |
| 610 | #include "Mission.h" |
| 611 | #include "robotfire.h" |
| 612 | #include "door.h" |
| 613 | #include "vclip.h" |
| 614 | #include "polymodel.h" |
| 615 | #include "robot.h" |
| 616 | #include "sounds.h" |
| 617 | #include "mem.h" |
| 618 | #include "marker.h" |
| 619 | // #include <malloc.h> |
| 620 | #include <stdlib.h> |
| 621 | #include "psrand.h" |
| 622 | // Allocate and initialize an effect_info struct for an object |
| 623 | void ObjCreateEffectInfo(object *objp) { |
| 624 | if (objp->effect_info) |
| 625 | mem_free(objp->effect_info); |
| 626 | |
| 627 | objp->effect_info = (effect_info_s *)mem_malloc(sizeof(effect_info_s)); |
| 628 | memset(objp->effect_info, 0, sizeof(effect_info_s)); |
| 629 | ASSERT(objp->effect_info); |
| 630 | objp->effect_info->sound_handle = SOUND_NONE_INDEX; |
| 631 | } |
| 632 | void ObjSetRenderPolyobj(object *objp, int model_num, int dying_model_num = -1); |
| 633 | #define NUM_PLAYER_ATTACH_POINTS 3 |
| 634 | // Initialize the polygon object information for an object |
| 635 | void ObjSetRenderPolyobj(object *objp, int model_num, int dying_model_num) { |
| 636 | objp->render_type = RT_POLYOBJ; |
| 637 | objp->flags |= OF_POLYGON_OBJECT; |
| 638 | polyobj_info *p_info = &objp->rtype.pobj_info; |
| 639 | p_info->model_num = model_num; |
| 640 | p_info->dying_model_num = dying_model_num; |
| 641 | p_info->anim_frame = 0.0f; |
| 642 | p_info->tmap_override = -1; |
| 643 | p_info->subobj_flags = 0xFFFFFFFF; |
| 644 | p_info->multi_turret_info.num_turrets = 0; |
| 645 | p_info->multi_turret_info.keyframes = NULL; |
| 646 | p_info->multi_turret_info.last_keyframes = NULL; |
| 647 | // Initialize attach slots |
| 648 | if (model_num != -1) { |
| 649 | poly_model *pm = GetPolymodelPointer(model_num); // get also pages in |
| 650 | if (objp->attach_children != NULL) { |
| 651 | mem_free(objp->attach_children); |
| 652 | objp->attach_children = NULL; |
| 653 | } |
| 654 | if ((objp->attach_children == NULL) && pm->n_attach) { |
| 655 | objp->attach_children = (int *)mem_malloc(sizeof(int) * pm->n_attach); |
| 656 | if (objp->type == OBJ_PLAYER) |
| 657 | ASSERT(pm->n_attach >= NUM_PLAYER_ATTACH_POINTS); |
| 658 | for (int i = 0; i < pm->n_attach; i++) |
| 659 | objp->attach_children[i] = OBJECT_HANDLE_NONE; |
| 660 | } |
| 661 | } |
| 662 | } |
| 663 | // Initialize a player object |
| 664 | // Returns 1 if ok, 0 if error |
| 665 | int ObjInitPlayer(object *objp) { |
| 666 | ship *ship; |
| 667 | int ret = 1; |
| 668 | ASSERT(objp->type == OBJ_PLAYER); |
| 669 | objp->shields = INITIAL_SHIELDS; |
| 670 | ship = &Ships[Players[objp->id].ship_index]; |
| 671 | if (!ship->used) { // this ship doesn't exist |
| 672 | int new_ship; |
| 673 | Int3(); |
| 674 | ret = 0; |
| 675 | new_ship = GetNextShip(0); |
| 676 | ASSERT(new_ship != -1); |
| 677 | Players[objp->id].ship_index = new_ship; |
| 678 | ship = &Ships[Players[objp->id].ship_index]; |
| 679 | } |
| 680 | // Set up render info |
| 681 | ObjSetRenderPolyobj(objp, ship->model_handle, ship->dying_model_handle); |
| 682 | ASSERT(Poly_models[ship->model_handle].n_attach >= 3); |
| 683 | objp->lighting_render_type = LRT_GOURAUD; |
| 684 | objp->lm_object.used = 0; |
| 685 | // Page in those models |
| 686 | PageInPolymodel(ship->model_handle, OBJ_PLAYER, &ship->size); |
| 687 | if (ship->dying_model_handle >= 0) |
| 688 | PageInPolymodel(ship->dying_model_handle); |
| 689 | if (ship->lo_render_handle >= 0) |
| 690 | PageInPolymodel(ship->lo_render_handle); |
| 691 | if (ship->med_render_handle >= 0) |
| 692 | PageInPolymodel(ship->med_render_handle); |
| 693 | // Set size |
| 694 | objp->size = ship->size; |
| 695 | // Set up control info. The player flies, other players do nothing |
| 696 | // MUST be after paging in polymodel cause SetObjectControlType does some |
| 697 | // stuff with the object's polymodel. |
| 698 | if (objp->id == Player_num) { |
| 699 | SetObjectControlType(objp, CT_FLYING); |
| 700 | objp->movement_type = MT_PHYSICS; |
| 701 | objp->mtype.phys_info = ship->phys_info; |
| 702 | Player_object = objp; |
| 703 | } else { |
| 704 | SetObjectControlType(objp, CT_NONE); |
| 705 | objp->movement_type = MT_NONE; |
| 706 | objp->mtype.phys_info = ship->phys_info; |
| 707 | objp->mtype.phys_info.flags = PF_FIXED_VELOCITY; |
| 708 | } |
| 709 | // Set up physics info |
| 710 | // These are always set for a player |
| 711 | objp->mtype.phys_info.num_bounces = PHYSICS_UNLIMITED_BOUNCE; |
| 712 | if (objp->dynamic_wb == NULL) { |
| 713 | objp->dynamic_wb = (dynamic_wb_info *)mem_malloc(sizeof(dynamic_wb_info) * MAX_WBS_PER_OBJ); |
| 714 | } |
| 715 | WBClearInfo(objp); |
| 716 | // Set a few misc things |
| 717 | Players[objp->id].team = objp->id % 2; |
| 718 | ObjCreateEffectInfo(objp); |
| 719 | objp->effect_info->type_flags = EF_VOLUME_LIT; |
| 720 | |
| 721 | return ret; |
| 722 | } |
| 723 | // Initialize a generic object (robot, powerup, building, etc.) |
| 724 | // Returns 1 if ok, 0 if error |
| 725 | int ObjInitGeneric(object *objp, bool reinit) { |
| 726 | object_info *obj_info; |
| 727 | int ret = 1; |
| 728 | float r_val = (float)ps_rand() / (float)D3_RAND_MAX; |
| 729 | if ((objp->id < 0) || (objp->id >= MAX_OBJECT_IDS)) { |
| 730 | Int3(); |
| 731 | return 0; |
| 732 | } |
| 733 | obj_info = &Object_info[objp->id]; |
| 734 | // Deal with deleted type |
| 735 | if (obj_info->type == OBJ_NONE) { |
| 736 | int i; |
| 737 | for (i = 0, obj_info = Object_info; i < MAX_OBJECT_IDS; i++, obj_info) { // find other object of same type |
| 738 | if (Object_info[i].type == objp->type) |
| 739 | break; |
| 740 | } |
| 741 | ASSERT(i < MAX_OBJECT_IDS); // There should (in real life) always be at least one of each type |
| 742 | #ifdef EDITOR |
| 743 | if (GetFunctionMode() == EDITOR_MODE) |
| 744 | OutrageMessageBox("Object %d (\"%s\") had ID %d which no longer exists. Changing to %d, \"%s\".", OBJNUM(objp), |
| 745 | objp->name ? objp->name : "<no name>", objp->id, i, obj_info->name); |
| 746 | #endif |
| 747 | } |
| 748 | if (obj_info->type != objp->type) { |
| 749 | #ifdef EDITOR |
| 750 | if (GetFunctionMode() == EDITOR_MODE) |
| 751 | OutrageMessageBox("Object %d (\"%s\"), type name \"%s\", changed from type %s to %s", OBJNUM(objp), |
| 752 | objp->name ? objp->name : "<no name>", obj_info->name, Object_type_names[objp->type], |
| 753 | Object_type_names[obj_info->type]); |
| 754 | #endif |
| 755 | objp->type = obj_info->type; |
| 756 | } |
| 757 | // Set size & shields |
| 758 | objp->shields = obj_info->hit_points; |
| 759 | // Set impact stuff for non-weapons |
| 760 | objp->impact_size = obj_info->impact_size; |
| 761 | objp->impact_time = obj_info->impact_time; |
| 762 | objp->impact_player_damage = obj_info->damage; |
| 763 | objp->impact_generic_damage = obj_info->damage; |
| 764 | objp->impact_force = obj_info->damage * 50.0; |
| 765 | // Set flags |
| 766 | if (obj_info->flags & OIF_DESTROYABLE) |
| 767 | objp->flags |= OF_DESTROYABLE; |
| 768 | if (obj_info->flags & OIF_AI_SCRIPTED_DEATH) |
| 769 | objp->flags |= OF_AI_DO_DEATH; |
| 770 | if (obj_info->flags & OIF_DO_CEILING_CHECK) |
| 771 | objp->flags |= OF_FORCE_CEILING_CHECK; |
| 772 | // Set up movement info |
| 773 | if (obj_info->flags & OIF_USES_PHYSICS) { |
| 774 | objp->movement_type = MT_PHYSICS; |
| 775 | // Setup some physics things |
| 776 | objp->mtype.phys_info = obj_info->phys_info; // Set the initial velocity |
| 777 | // Warn about initial velocity & rotvel |
| 778 | if (obj_info->phys_info.velocity.z > 0.0) |
| 779 | Int3(); // Warning: This object has an initial velocity. This is not supported. |
| 780 | // If your object does not need an initial velocity, set it to zero on |
| 781 | // the page. If you do need an initial velocity, someone will have to |
| 782 | // add code to deal with it, perhaps here or perhaps at level start. |
| 783 | } else |
| 784 | objp->movement_type = MT_NONE; |
| 785 | |
| 786 | // Set up render info |
| 787 | ObjSetRenderPolyobj(objp, obj_info->render_handle); |
| 788 | PageInPolymodel(obj_info->render_handle, objp->type, &obj_info->size); |
| 789 | objp->size = obj_info->size; |
| 790 | |
| 791 | // Page in low-res models |
| 792 | if (obj_info->lo_render_handle != -1) |
| 793 | PageInPolymodel(obj_info->lo_render_handle); |
| 794 | if (obj_info->med_render_handle != -1) |
| 795 | PageInPolymodel(obj_info->med_render_handle); |
| 796 | |
| 797 | // Set anim frame |
| 798 | if (Object_info[objp->id].anim) { |
| 799 | objp->rtype.pobj_info.anim_frame = |
| 800 | ((1.0f - r_val) * (float)Object_info[objp->id].anim[MC_STANDING].elem[AS_ALERT].from) + |
| 801 | (r_val * (float)Object_info[objp->id].anim[MC_STANDING].elem[AS_ALERT].to); |
| 802 | } else { |
| 803 | objp->rtype.pobj_info.anim_frame = 0.0f; |
| 804 | } |
| 805 | |
| 806 | // Set up control info (must be after wb stuff) |
| 807 | if (obj_info->ai_info && obj_info->flags & OIF_CONTROL_AI) // DAJ 12/18/99 added check for ai_info |
| 808 | { |
| 809 | SetObjectControlType(objp, CT_AI); |
| 810 | AIInit(objp, obj_info->ai_info->ai_class, obj_info->ai_info->ai_type, obj_info->ai_info->movement_type); |
| 811 | } else |
| 812 | SetObjectControlType(objp, CT_NONE); |
| 813 | if (objp->control_type == CT_AI) { |
| 814 | poly_model *pm = &Poly_models[objp->rtype.pobj_info.model_num]; |
| 815 | int num_wbs = pm->num_wbs; |
| 816 | |
| 817 | if ((objp->dynamic_wb != NULL) && ((uint32_t)num_wbs != mem_size(objp->dynamic_wb) / sizeof(dynamic_wb_info))) |
| 818 | { |
| 819 | mem_free(objp->dynamic_wb); |
| 820 | objp->dynamic_wb = NULL; |
| 821 | } |
| 822 | if ((objp->dynamic_wb == NULL) && num_wbs) { |
| 823 | objp->dynamic_wb = (dynamic_wb_info *)mem_malloc(sizeof(dynamic_wb_info) * num_wbs); |
| 824 | } |
| 825 | // Setup the weapon batteries (must be after polymodel stuff) |
| 826 | WBClearInfo(objp); |
| 827 | } |
| 828 | objp->lighting_render_type = obj_info->lighting_info.lighting_render_type; |
| 829 | if (!reinit) |
| 830 | objp->lm_object.used = 0; |
| 831 | // Allocate effect memory |
| 832 | ObjCreateEffectInfo(objp); |
| 833 | |
| 834 | if (objp->type != OBJ_POWERUP) |
| 835 | objp->effect_info->type_flags = EF_VOLUME_LIT; |
| 836 | if (objp->movement_type == MT_PHYSICS) { |
| 837 | if (objp->mtype.phys_info.rotdrag < 60.0f) |
| 838 | objp->mtype.phys_info.rotdrag = 60.0; // CHRISHACK - MAKES SURE ROBOTS DONT SPIN FOREVER |
| 839 | } |
| 840 | |
| 841 | // Set ammo amounts for powerups |
| 842 | if (objp->type == OBJ_POWERUP) { |
| 843 | if (objp->control_type == CT_NONE) { // some powerups have AI; don't mess with them |
| 844 | SetObjectControlType(objp, CT_POWERUP); |
| 845 | objp->ctype.powerup_info.count = obj_info->ammo_count; |
| 846 | } |
| 847 | } |
| 848 | // Clear wiggle flag to supersede those pesky designer errors! |
| 849 | objp->mtype.phys_info.flags &= ~PF_WIGGLE; |
| 850 | return ret; |
| 851 | } |
| 852 | int ObjInitDebris(object *objp) { |
| 853 | ASSERT(objp->type == OBJ_DEBRIS); |
| 854 | objp->movement_type = MT_PHYSICS; |
| 855 | SetObjectControlType(objp, CT_DEBRIS); |
| 856 | objp->lifeleft = DEBRIS_LIFE; |
| 857 | objp->flags |= OF_USES_LIFELEFT; |
| 858 | objp->ctype.debris_info.death_flags = 0; |
| 859 | // Set up render info |
| 860 | ObjSetRenderPolyobj(objp, -1); |
| 861 | objp->lighting_render_type = LRT_GOURAUD; |
| 862 | objp->lm_object.used = 0; |
| 863 | // Allocate effect memory |
| 864 | ObjCreateEffectInfo(objp); |
| 865 | |
| 866 | objp->effect_info->type_flags = EF_VOLUME_LIT; |
| 867 | |
| 868 | return 1; |
| 869 | } |
| 870 | int ObjInitShard(object *objp) { |
| 871 | ASSERT(objp->type == OBJ_SHARD); |
| 872 | objp->movement_type = MT_PHYSICS; |
| 873 | SetObjectControlType(objp, CT_NONE); |
| 874 | objp->lifeleft = DEBRIS_LIFE * 5; |
| 875 | objp->flags |= OF_USES_LIFELEFT; |
| 876 | // Set physics info |
| 877 | objp->mtype.phys_info.flags = PF_GRAVITY + PF_BOUNCE; |
| 878 | objp->mtype.phys_info.mass = 1.0; |
| 879 | objp->mtype.phys_info.drag = 0.0001f; |
| 880 | objp->mtype.phys_info.coeff_restitution = 0.3f; |
| 881 | objp->mtype.phys_info.num_bounces = 0; |
| 882 | |
| 883 | // Set up render info |
| 884 | objp->render_type = RT_SHARD; |
| 885 | return 1; |
| 886 | } |
| 887 | #ifdef _DEBUG |
| 888 | int ObjInitLine(object *objp) { |
| 889 | ASSERT(objp->type == OBJ_DEBUG_LINE); |
| 890 | objp->movement_type = MT_NONE; |
| 891 | SetObjectControlType(objp, CT_NONE); |
| 892 | objp->render_type = RT_LINE; |
| 893 | return 1; |
| 894 | } |
| 895 | #endif |
| 896 | // Initialize a camera |
| 897 | // Returns 1 if ok, 0 if error |
| 898 | int ObjInitCamera(object *objp) { |
| 899 | // Set size & shields |
| 900 | objp->size = 0.5; |
| 901 | objp->shields = 0; |
| 902 | // Set up various info |
| 903 | SetObjectControlType(objp, CT_NONE); |
| 904 | objp->movement_type = MT_NONE; |
| 905 | objp->lm_object.used = 0; |
| 906 | #ifdef EDITOR |
| 907 | objp->render_type = RT_EDITOR_SPHERE; // draw cameras as spheres in the editor |
| 908 | objp->rtype.sphere_color = GR_RGB(255, 255, 0); |
| 909 | #else |
| 910 | objp->render_type = RT_NONE; |
| 911 | #endif |
| 912 | return 1; |
| 913 | } |
| 914 | // Initialize a sound object |
| 915 | // Returns 1 if ok, 0 if error |
| 916 | int ObjInitSoundSource(object *objp) { |
| 917 | // Set size & shields |
| 918 | objp->size = 0.5; |
| 919 | objp->shields = 0; |
| 920 | // Set up various info |
| 921 | SetObjectControlType(objp, CT_SOUNDSOURCE); |
| 922 | objp->movement_type = MT_NONE; |
| 923 | objp->lm_object.used = 0; |
| 924 | #ifdef EDITOR |
| 925 | objp->render_type = RT_EDITOR_SPHERE; // draw cameras as spheres in the editor |
| 926 | objp->rtype.sphere_color = GR_RGB(0, 255, 0); |
| 927 | #else |
| 928 | objp->render_type = RT_NONE; |
| 929 | #endif |
| 930 | return 1; |
| 931 | } |
| 932 | // Initialize a waypoint object |
| 933 | // Returns 1 if ok, 0 if error |
| 934 | int ObjInitWaypoint(object *objp) { |
| 935 | // Set size & shields |
| 936 | objp->size = 0.5; |
| 937 | objp->shields = 0; |
| 938 | // Set up various info |
| 939 | SetObjectControlType(objp, CT_NONE); |
| 940 | objp->movement_type = MT_NONE; |
| 941 | objp->lm_object.used = 0; |
| 942 | #ifdef EDITOR |
| 943 | objp->render_type = RT_EDITOR_SPHERE; // draw cameras as spheres in the editor |
| 944 | objp->rtype.sphere_color = GR_RGB(255, 130, 33); |
| 945 | #else |
| 946 | objp->render_type = RT_NONE; |
| 947 | #endif |
| 948 | return 1; |
| 949 | } |
| 950 | // Initialize an editor viewer object |
| 951 | // Returns 1 if ok, 0 if error |
| 952 | int ObjInitViewer(object *objp) { |
| 953 | // Set size & shields |
| 954 | objp->size = 5.0; |
| 955 | objp->shields = 0; |
| 956 | // Set up various info |
| 957 | SetObjectControlType(objp, CT_NONE); |
| 958 | objp->movement_type = MT_NONE; |
| 959 | objp->render_type = RT_NONE; |
| 960 | objp->lm_object.used = 0; |
| 961 | return 1; |
| 962 | } |
| 963 | // Initialize a weapon |
| 964 | // Returns 1 if ok, 0 if error |
| 965 | int ObjInitWeapon(object *objp) { |
| 966 | weapon *weap; |
| 967 | int ret = 1; |
| 968 | ASSERT(objp->type == OBJ_WEAPON); |
| 969 | |
| 970 | if (objp->id < 0 || objp->id >= MAX_WEAPONS) |
| 971 | return 0; |
| 972 | |
| 973 | weap = &Weapons[objp->id]; |
| 974 | ASSERT(weap->used > 0); |
| 975 | // Set up shields |
| 976 | objp->shields = 0; |
| 977 | // Set up control info |
| 978 | SetObjectControlType(objp, CT_WEAPON); |
| 979 | // Not tracking anything |
| 980 | objp->ctype.laser_info.track_handle = OBJECT_HANDLE_NONE; |
| 981 | // Set up physics info |
| 982 | objp->movement_type = MT_PHYSICS; |
| 983 | objp->mtype.phys_info.mass = weap->phys_info.mass; |
| 984 | objp->mtype.phys_info.drag = weap->phys_info.drag; |
| 985 | objp->mtype.phys_info.rotdrag = weap->phys_info.rotdrag; |
| 986 | objp->mtype.phys_info.flags = weap->phys_info.flags; |
| 987 | |
| 988 | objp->mtype.phys_info.full_rotthrust = weap->phys_info.full_rotthrust; |
| 989 | objp->mtype.phys_info.full_thrust = weap->phys_info.full_thrust; |
| 990 | objp->mtype.phys_info.rotvel = weap->phys_info.rotvel; |
| 991 | // objp->mtype.phys_info.rot_thrust = weap->phys_info.full_rot_thrust; |
| 992 | objp->mtype.phys_info.wiggle_amplitude = weap->phys_info.wiggle_amplitude; |
| 993 | objp->mtype.phys_info.wiggles_per_sec = weap->phys_info.wiggles_per_sec; |
| 994 | objp->mtype.phys_info.num_bounces = weap->phys_info.num_bounces; |
| 995 | objp->mtype.phys_info.coeff_restitution = weap->phys_info.coeff_restitution; |
| 996 | objp->lifeleft = weap->life_time; |
| 997 | objp->lifetime = weap->life_time; |
| 998 | objp->ctype.laser_info.thrust_left = weap->thrust_time; |
| 999 | objp->ctype.laser_info.last_drop_time = 0; |
| 1000 | objp->mtype.phys_info.hit_die_dot = weap->phys_info.hit_die_dot; |
| 1001 | // Set impact stuff |
| 1002 | objp->impact_size = weap->impact_size; |
| 1003 | objp->impact_time = weap->impact_time; |
| 1004 | objp->impact_player_damage = weap->impact_player_damage; |
| 1005 | objp->impact_generic_damage = weap->impact_generic_damage; |
| 1006 | objp->impact_force = weap->impact_force; |
| 1007 | // Set up a few flags |
| 1008 | objp->mtype.phys_info.flags |= PF_NO_COLLIDE_PARENT; |
| 1009 | objp->flags |= OF_USES_LIFELEFT; |
| 1010 | // Set up rendering info |
| 1011 | objp->render_type = RT_WEAPON; |
| 1012 | |
| 1013 | if (!((weap->flags & WF_IMAGE_BITMAP) || (weap->flags & WF_IMAGE_VCLIP))) { |
| 1014 | objp->rtype.pobj_info.model_num = weap->fire_image_handle; |
| 1015 | objp->rtype.pobj_info.dying_model_num = -1; |
| 1016 | PageInPolymodel(weap->fire_image_handle, OBJ_WEAPON, &weap->size); |
| 1017 | |
| 1018 | objp->rtype.pobj_info.subobj_flags = 0xFFFFFFFF; |
| 1019 | objp->flags |= OF_POLYGON_OBJECT; |
| 1020 | } else if (weap->flags & WF_IMAGE_VCLIP) { |
| 1021 | PageInVClip(weap->fire_image_handle); |
| 1022 | } |
| 1023 | |
| 1024 | objp->size = weap->size; |
| 1025 | objp->ctype.laser_info.hit_status = WPC_NOT_USED; |
| 1026 | if (weap->flags & WF_CUSTOM_SIZE) { |
| 1027 | objp->size = weap->custom_size; |
| 1028 | } |
| 1029 | objp->lighting_render_type = LRT_STATIC; |
| 1030 | objp->lm_object.used = 0; |
| 1031 | |
| 1032 | return ret; |
| 1033 | } |
| 1034 | int ObjInitFireball(object *objp) { |
| 1035 | int ret = 1; |
| 1036 | ASSERT(objp->type == OBJ_FIREBALL); |
| 1037 | // Set size & shields |
| 1038 | objp->shields = 0; |
| 1039 | objp->size = 0; |
| 1040 | // Set up control info |
| 1041 | SetObjectControlType(objp, CT_EXPLOSION); |
| 1042 | // Set up physics info |
| 1043 | objp->movement_type = MT_NONE; |
| 1044 | objp->mtype.phys_info.num_bounces = PHYSICS_UNLIMITED_BOUNCE; |
| 1045 | |
| 1046 | // Set up render info |
| 1047 | objp->render_type = RT_FIREBALL; |
| 1048 | objp->size = Fireballs[objp->id].size; |
| 1049 | objp->flags |= OF_USES_LIFELEFT; |
| 1050 | objp->lifeleft = Fireballs[objp->id].total_life; |
| 1051 | objp->lighting_render_type = LRT_STATIC; |
| 1052 | objp->lm_object.used = 0; |
| 1053 | return ret; |
| 1054 | } |
| 1055 | int ObjInitMarker(object *objp) { |
| 1056 | int ret = 1; |
| 1057 | static int first = 1; |
| 1058 | static int polynum = -1; |
| 1059 | ASSERT(objp->type == OBJ_MARKER); |
| 1060 | // Set size & shields |
| 1061 | objp->shields = 100; |
| 1062 | objp->size = 2.0; |
| 1063 | // Set up control info |
| 1064 | SetObjectControlType(objp, CT_NONE); |
| 1065 | objp->movement_type = MT_NONE; |
| 1066 | ObjSetRenderPolyobj(objp, Marker_polynum); |
| 1067 | PageInPolymodel(Marker_polynum, OBJ_MARKER, &objp->size); |
| 1068 | objp->lm_object.used = 0; |
| 1069 | objp->lighting_render_type = LRT_STATIC; |
| 1070 | return ret; |
| 1071 | } |
| 1072 | int ObjInitDoor(object *objp, bool reinit) { |
| 1073 | // Set up movement info |
| 1074 | objp->movement_type = MT_NONE; |
| 1075 | SetObjectControlType(objp, CT_NONE); |
| 1076 | // Set up render info |
| 1077 | ObjSetRenderPolyobj(objp, GetDoorImage(objp->id)); |
| 1078 | PageInPolymodel(objp->rtype.pobj_info.model_num); |
| 1079 | ComputeDefaultSize(OBJ_DOOR, objp->rtype.pobj_info.model_num, &objp->size); |
| 1080 | objp->lighting_render_type = LRT_LIGHTMAPS; |
| 1081 | // Set shields |
| 1082 | if (Doors[objp->id].flags & DF_BLASTABLE) { |
| 1083 | objp->flags |= OF_DESTROYABLE; |
| 1084 | objp->shields = Doors[objp->id].hit_points; |
| 1085 | } |
| 1086 | if (!reinit) |
| 1087 | objp->lm_object.used = 0; |
| 1088 | |
| 1089 | return 1; |
| 1090 | } |
| 1091 | int ObjInitRoom(object *objp) { |
| 1092 | // Set up movement info |
| 1093 | objp->movement_type = MT_NONE; |
| 1094 | SetObjectControlType(objp, CT_NONE); |
| 1095 | // Set up render info |
| 1096 | objp->render_type = RT_ROOM; // rendering handled as special case |
| 1097 | // I have no idea about this stuff |
| 1098 | objp->lighting_render_type = LRT_STATIC; |
| 1099 | objp->lm_object.used = 0; |
| 1100 | objp->flags |= OF_POLYGON_OBJECT; |
| 1101 | |
| 1102 | return 1; |
| 1103 | } |
| 1104 | // Set all the type-specific info for this object |
| 1105 | // Returns 1 if ok, 0 if error |
| 1106 | int ObjInitTypeSpecific(object *objp, bool reinitializing) { |
| 1107 | switch (objp->type) { |
| 1108 | case OBJ_CLUTTER: |
| 1109 | case OBJ_BUILDING: |
| 1110 | case OBJ_ROBOT: |
| 1111 | case OBJ_POWERUP: |
| 1112 | return ObjInitGeneric(objp, reinitializing); |
| 1113 | break; |
| 1114 | case OBJ_SHOCKWAVE: |
| 1115 | return 1; |
| 1116 | break; |
| 1117 | case OBJ_PLAYER: |
| 1118 | return ObjInitPlayer(objp); |
| 1119 | break; |
| 1120 | case OBJ_CAMERA: |
| 1121 | return ObjInitCamera(objp); |
| 1122 | break; |
| 1123 | case OBJ_MARKER: |
| 1124 | return ObjInitMarker(objp); |
| 1125 | break; |
| 1126 | case OBJ_VIEWER: |
| 1127 | return ObjInitViewer(objp); |
| 1128 | break; |
| 1129 | case OBJ_WEAPON: |
| 1130 | return ObjInitWeapon(objp); |
| 1131 | break; |
| 1132 | case OBJ_FIREBALL: |
| 1133 | return ObjInitFireball(objp); |
| 1134 | break; |
| 1135 | case OBJ_DOOR: |
| 1136 | return ObjInitDoor(objp, reinitializing); |
| 1137 | break; |
| 1138 | case OBJ_ROOM: |
| 1139 | return ObjInitRoom(objp); |
| 1140 | break; |
| 1141 | case OBJ_DEBRIS: |
| 1142 | return ObjInitDebris(objp); |
| 1143 | break; |
| 1144 | case OBJ_SHARD: |
| 1145 | return ObjInitShard(objp); |
| 1146 | break; |
| 1147 | case OBJ_SOUNDSOURCE: |
| 1148 | return ObjInitSoundSource(objp); |
| 1149 | break; |
| 1150 | case OBJ_WAYPOINT: |
| 1151 | return ObjInitWaypoint(objp); |
| 1152 | break; |
| 1153 | case OBJ_SPLINTER: |
| 1154 | return 1; |
| 1155 | break; |
| 1156 | #ifdef _DEBUG |
| 1157 | case OBJ_DEBUG_LINE: |
| 1158 | return ObjInitLine(objp); |
| 1159 | break; |
| 1160 | #endif |
| 1161 | break; |
| 1162 | default: |
| 1163 | Int3(); |
| 1164 | return 0; |
| 1165 | } |
| 1166 | } |
| 1167 | // Initializes a new object. All fields not passed in set to defaults. |
| 1168 | // Returns 1 if ok, 0 if error |
| 1169 | int ObjInit(object *objp, int type, int id, int handle, vector *pos, float creation_time, int parent_handle) { |
| 1170 | // Zero out object structure to keep weird bugs from happening in uninitialized fields. |
| 1171 | // I hate doing this because it seems sloppy, but it's probably better to do it |
| 1172 | memset(objp, 0, sizeof(object)); |
| 1173 | // Set the stuff that's passed in |
| 1174 | objp->type = type; |
| 1175 | objp->id = id; |
| 1176 | objp->handle = handle; |
| 1177 | objp->pos = objp->last_pos = *pos; |
| 1178 | objp->parent_handle = parent_handle; |
| 1179 | objp->creation_time = creation_time; |
| 1180 | objp->osiris_script = NULL; |
| 1181 | // Initialize some general stuff |
| 1182 | objp->roomnum = -1; |
| 1183 | objp->orient = Identity_matrix; |
| 1184 | objp->next = objp->prev = -1; |
| 1185 | objp->dummy_type = OBJ_NONE; |
| 1186 | objp->flags = 0; |
| 1187 | objp->size = 0; |
| 1188 | objp->change_flags = 0; |
| 1189 | objp->generic_nonvis_flags = 0; |
| 1190 | objp->generic_sent_nonvis = 0; |
| 1191 | objp->name = NULL; |
| 1192 | objp->custom_default_script_name = NULL; |
| 1193 | objp->custom_default_module_name = NULL; |
| 1194 | objp->contains_type = -1; |
| 1195 | objp->lifeleft = 0; |
| 1196 | objp->effect_info = NULL; |
| 1197 | objp->ai_info = NULL; |
| 1198 | objp->dynamic_wb = NULL; |
| 1199 | objp->attach_children = NULL; |
| 1200 | // Now initialize the type-specific data |
| 1201 | return ObjInitTypeSpecific(objp, 0); |
| 1202 | } |
| 1203 | // Re-copies data to each object from the appropriate page for that object type. |
| 1204 | // Called after an object page has changed. |
| 1205 | void ObjReInitAll() { |
| 1206 | int objnum; |
| 1207 | object *objp; |
| 1208 | for (objnum = 0, objp = Objects; objnum <= Highest_object_index; objnum++, objp++) |
| 1209 | if (objp->type != OBJ_NONE) |
| 1210 | ObjInitTypeSpecific(objp, 1); |
| 1211 | } |