| 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/WeaponFire.cpp $ |
| 21 | * $Revision: 279 $ |
| 22 | * $Date: 9/20/01 5:33p $ |
| 23 | * $Author: Matt $ |
| 24 | * |
| 25 | * Weapon firing functions |
| 26 | * |
| 27 | * $Log: /DescentIII/Main/WeaponFire.cpp $ |
| 28 | * |
| 29 | * 279 9/20/01 5:33p Matt |
| 30 | * Fixed weird omega cannon bugs (I hope) by only letting the omega |
| 31 | * particles collide from inside AquireElectricalTarget(). |
| 32 | * |
| 33 | * 278 9/10/01 5:18p Matt |
| 34 | * For continuous-fire energy weapons (the omega cannon) use energy at a |
| 35 | * continuous (i.e., not frame-rate dependent) way. |
| 36 | * |
| 37 | * 277 9/05/01 4:14p Matt |
| 38 | * Only call StopWeapon() when dealing with a primary weapon. This change |
| 39 | * fixes odd primary weapon behavior when holding down the secondary fire |
| 40 | * button when out of secondaries. |
| 41 | * |
| 42 | * 276 8/29/01 4:26p Matt |
| 43 | * Add command-line switch to turn off suturation for omega cannon. |
| 44 | * |
| 45 | * 275 2/01/00 3:48a Jason |
| 46 | * Made lock image not display if the homing weapon is no longer locked on |
| 47 | * |
| 48 | * 274 1/26/00 9:20p Jeff |
| 49 | * added support for IntelliVIBE DLL |
| 50 | * |
| 51 | * 273 11/02/99 4:22p Chris |
| 52 | * Fixed problem with being able to fire dual fire secondaries when you |
| 53 | * only have one missle left |
| 54 | * |
| 55 | * 272 10/22/99 2:39p Jay |
| 56 | * Update for the FinalBoss Laser Effect |
| 57 | * |
| 58 | * 271 10/21/99 9:30p Jeff |
| 59 | * B.A. Macintosh code merge |
| 60 | * |
| 61 | * 270 10/20/99 5:40p Chris |
| 62 | * Added the Red Guidebot |
| 63 | * |
| 64 | * 269 9/01/99 6:57p Jason |
| 65 | * fixed guided missiles and timeout missiles so they work in multiplayer |
| 66 | * |
| 67 | * 268 7/27/99 12:17p Chris |
| 68 | * Only play the homing sound if there is a direct line of sight between |
| 69 | * the player and the homing object |
| 70 | * |
| 71 | * 267 7/20/99 6:51p Chris |
| 72 | * The Omega Cannon no longer locks on the GB |
| 73 | * |
| 74 | * 266 5/22/99 10:38p Jason |
| 75 | * fixed dumb bug with last rev |
| 76 | * |
| 77 | * 265 5/22/99 10:27p Jason |
| 78 | * changes for multiplayer and buildings, ai |
| 79 | * |
| 80 | * 264 5/21/99 10:35p Jason |
| 81 | * fixed 3rd person firing spray effects through walls |
| 82 | * |
| 83 | * 263 5/21/99 5:08a Chris |
| 84 | * Fixed the weapon speed scaling for TEAM_REBEL robots |
| 85 | * |
| 86 | * 262 5/20/99 3:48p Chris |
| 87 | * Rebel stuff isn't usually scaled by diff anymore |
| 88 | * |
| 89 | * 261 5/20/99 3:10p Jason |
| 90 | * fixed omega homing on invisible objects |
| 91 | * |
| 92 | * 260 5/19/99 3:25p Jason |
| 93 | * fixed wrong ordering of InitObjectScripts and MultiSendObject |
| 94 | * |
| 95 | * 259 5/17/99 6:07p Chris |
| 96 | * Tweaked min fire spread for diff levels |
| 97 | * |
| 98 | * 258 5/10/99 11:57p Chris |
| 99 | * Now related objects are not targetted by an omega cannon (I.e. things |
| 100 | * like a flag or something attached) |
| 101 | * |
| 102 | * 257 5/09/99 11:57p Jason |
| 103 | * fixed electrical weapon bug |
| 104 | * |
| 105 | * 256 5/09/99 1:24p Jason |
| 106 | * made chaff multiplayer friendly |
| 107 | * |
| 108 | * 255 5/09/99 1:13p Matt |
| 109 | * Three things: (1) Made players & chaff related, so they don't collide; |
| 110 | * (2) Made homing missiles prefer chaff; (3) Fixed a fire spread bug. |
| 111 | * |
| 112 | * 254 5/08/99 10:38p Chris |
| 113 | * Further scaled the game. :) |
| 114 | * |
| 115 | * 253 5/08/99 3:30p Jason |
| 116 | * fixed MassDriver zoom bug |
| 117 | * |
| 118 | * 252 5/07/99 4:56p Chris |
| 119 | * Doing boa vis around a bunch of code. :) |
| 120 | * |
| 121 | * 251 5/05/99 6:30p Jason |
| 122 | * toned down mass driver effect |
| 123 | * |
| 124 | * 250 5/05/99 1:20a Chris |
| 125 | * Fixed homers. |
| 126 | * |
| 127 | * 249 5/02/99 2:00a Jason |
| 128 | * added assert to help track down DoSprayEffect crash |
| 129 | * |
| 130 | * 248 5/01/99 2:34p Jason |
| 131 | * fixed omega problems |
| 132 | * |
| 133 | * 247 4/28/99 11:28a Jason |
| 134 | * made real viseffects not cast light |
| 135 | * |
| 136 | * 246 4/24/99 4:33p Jason |
| 137 | * made fusion damage sound not be irritating |
| 138 | * |
| 139 | * 245 4/23/99 3:33p Jason |
| 140 | * fixed napalm going through walls |
| 141 | * |
| 142 | * 244 4/23/99 1:00p Chris |
| 143 | * Improved conditions for LARGE objects - i.e. buildings |
| 144 | * |
| 145 | * 243 4/23/99 11:56a Jason |
| 146 | * fixed mass driver mess up on robots |
| 147 | * |
| 148 | * 242 4/21/99 11:05a Kevin |
| 149 | * new ps_rand and ps_srand to replace rand & srand |
| 150 | * |
| 151 | * 241 4/20/99 8:15p Chris |
| 152 | * Fixed bug with firing directly at objects(if vec is NULL, don't use the |
| 153 | * flag) |
| 154 | * |
| 155 | * 240 4/18/99 5:49p Chris |
| 156 | * Fixed smart missles |
| 157 | * |
| 158 | * 239 4/16/99 3:48p Jason |
| 159 | * made vauss streamers a little cooler |
| 160 | * |
| 161 | * 238 4/14/99 3:57a Jeff |
| 162 | * fixed case mismatch in #includes |
| 163 | * |
| 164 | * 237 4/13/99 12:16p Jason |
| 165 | * mass driver...again! |
| 166 | * |
| 167 | * 236 4/12/99 7:05p Jason |
| 168 | * fixed omega lighting |
| 169 | * |
| 170 | * 235 4/12/99 3:03p Jason |
| 171 | * added recoil to player objects when firing weapons |
| 172 | * |
| 173 | * 234 4/12/99 8:30a Chris |
| 174 | * Moving building don't collide with powerups |
| 175 | * |
| 176 | * 233 4/10/99 5:09p Samir |
| 177 | * prioritize sounds, pass 1 |
| 178 | * |
| 179 | * 232 4/09/99 7:27p Jason |
| 180 | * added better mass driver effect |
| 181 | * |
| 182 | * 231 4/09/99 12:06p Jason |
| 183 | * made model setup code faster |
| 184 | * |
| 185 | * 230 4/08/99 6:00p Jason |
| 186 | * more tweaks for mass driver |
| 187 | * |
| 188 | * 229 4/06/99 2:45p Jason |
| 189 | * don't play cuttoff sound if in permissable netgame |
| 190 | * |
| 191 | * 228 4/06/99 1:51p Jason |
| 192 | * added new mass driver effect |
| 193 | * |
| 194 | * 227 4/05/99 4:40p Jason |
| 195 | * added groovy new smoke trails |
| 196 | * |
| 197 | * 226 4/01/99 1:11p Jason |
| 198 | * made vis effects better for the lighting system |
| 199 | * |
| 200 | * 225 3/08/99 5:24p Jason |
| 201 | * fixed mass driver visual |
| 202 | * |
| 203 | * 224 3/08/99 11:37a Chris |
| 204 | * Fixed mod_pos problems |
| 205 | * |
| 206 | * 223 3/08/99 11:13a Jason |
| 207 | * made omegas homing cone a little more restricted |
| 208 | * |
| 209 | * 222 3/03/99 11:04a Chris |
| 210 | * |
| 211 | * 221 3/03/99 10:51a Chris |
| 212 | * Robots dont collide with openned doors |
| 213 | * |
| 214 | * 220 3/03/99 3:56a Chris |
| 215 | * Improve diff level stuff |
| 216 | * |
| 217 | * 219 3/03/99 3:36a Matt |
| 218 | * Fixed ammo usage problem |
| 219 | * |
| 220 | * 218 3/02/99 7:22p Chris |
| 221 | * Add the 'fire at target' check box for weapon batteries |
| 222 | * |
| 223 | * 217 3/02/99 3:39p Jason |
| 224 | * made quaded weapons use double energy/ammo |
| 225 | * |
| 226 | * 216 3/02/99 2:20p Jason |
| 227 | * doh! Fixed bug with my last rev |
| 228 | * |
| 229 | * 215 3/02/99 2:19p Jason |
| 230 | * fixed energy/ammo usage bug |
| 231 | * |
| 232 | * 214 2/10/99 4:02p Chris |
| 233 | * Updated the attach system so that if a robot is idling, the AI will not |
| 234 | * update the attached subobjects (if the object is still moving, physics |
| 235 | * will do it). |
| 236 | * |
| 237 | * 213 2/10/99 1:47p Matt |
| 238 | * Changed object handle symbolic constants |
| 239 | * |
| 240 | * 212 2/08/99 5:29p Jason |
| 241 | * added weapon options |
| 242 | * |
| 243 | * 211 2/08/99 11:05a Jason |
| 244 | * took off impact mortar blobbly explosion |
| 245 | * |
| 246 | * 210 2/02/99 8:43a Chris |
| 247 | * I made buildings with AI work correctly (ie really big robots should be |
| 248 | * buildings) |
| 249 | * anim to and from states are now shorts instead of bytes |
| 250 | * |
| 251 | * 209 1/31/99 7:26p Matt |
| 252 | * Renamed a bunch of functions to have HUD capitalized |
| 253 | * |
| 254 | * 208 1/29/99 4:59p Chris |
| 255 | * Fixed a bug where the omega cannon would mess up weapons |
| 256 | * |
| 257 | * 207 1/25/99 7:43a Chris |
| 258 | * Added the GUID (Goal Unique Id) and added the ability for weapon |
| 259 | * batteries to always fire exactly forward. |
| 260 | * |
| 261 | * 206 1/24/99 8:18p Chris |
| 262 | * Updated AI and OSIRIS. Externalized fireball constants for spew and |
| 263 | * sparks. Added CreateRandomSparks to OSIRIS, renamed a bunch of AI |
| 264 | * Notify names to use underscores. Fixed a memory access leak in the |
| 265 | * matcen effect code. |
| 266 | * |
| 267 | * 205 1/24/99 3:11a Jason |
| 268 | * fixed weapon fire no glow bug |
| 269 | * |
| 270 | * 204 1/21/99 11:29p Jason |
| 271 | * made no_glow flag work correctly with weapons |
| 272 | * |
| 273 | * 203 1/21/99 11:15p Jeff |
| 274 | * pulled out some structs and defines from header files and moved them |
| 275 | * into seperate header files so that multiplayer dlls don't require major |
| 276 | * game headers, just those new headers. Side effect is a shorter build |
| 277 | * time. Also cleaned up some header file #includes that weren't needed. |
| 278 | * This affected polymodel.h, object.h, player.h, vecmat.h, room.h, |
| 279 | * manage.h and multi.h |
| 280 | * |
| 281 | * 202 1/21/99 7:02p Jason |
| 282 | * weapon effect changes |
| 283 | * |
| 284 | * 201 1/21/99 6:50p Jason |
| 285 | * added test impact mortar |
| 286 | * |
| 287 | * 200 1/14/99 12:21p Jason |
| 288 | * fixed up on/off weapons in multiplayer |
| 289 | * |
| 290 | * 199 1/13/99 12:43p Jason |
| 291 | * added some more detail settings |
| 292 | * |
| 293 | * 198 1/08/99 2:56p Samir |
| 294 | * Ripped out OSIRIS1. |
| 295 | * |
| 296 | * 197 1/07/99 11:43a Jason |
| 297 | * made zoom weapons shake your ship more |
| 298 | * |
| 299 | * 196 1/05/99 5:09p Jason |
| 300 | * added permissable server networking (ala Quake/Unreal) to Descent3 |
| 301 | * |
| 302 | * 195 1/05/99 12:24p Chris |
| 303 | * More OSIRIS improvements |
| 304 | * |
| 305 | * 194 12/11/98 5:08p Jason |
| 306 | * changed mass driver effect |
| 307 | * |
| 308 | * 193 12/09/98 2:06p Jason |
| 309 | * changed mass driver tracers |
| 310 | * |
| 311 | * 192 12/08/98 4:28p Chris |
| 312 | * Improved ObjRelated code. Attach objects are correctly functional with |
| 313 | * weapons and other attached objects |
| 314 | * |
| 315 | * 191 12/02/98 5:52p Chris |
| 316 | * Fire spread is now partially scaled by difficulty level |
| 317 | * |
| 318 | * 190 12/02/98 10:30a Jason |
| 319 | * added additional damage types for client-side multiplayer |
| 320 | * |
| 321 | * 189 11/30/98 5:48p Jason |
| 322 | * toned down fusion screen color |
| 323 | * |
| 324 | * 188 11/23/98 3:11p Kevin |
| 325 | * Demo system |
| 326 | * |
| 327 | * 187 11/18/98 5:50p Jeff |
| 328 | * added some cheap recoil effects for ForceFeedback...not fully |
| 329 | * implemented |
| 330 | * |
| 331 | * 186 11/17/98 4:17p Kevin |
| 332 | * Demo recording system |
| 333 | * |
| 334 | * 185 11/16/98 10:30a Jason |
| 335 | * fixed user timeout missile |
| 336 | * |
| 337 | * 184 11/13/98 4:46p Jason |
| 338 | * fixed smart missile |
| 339 | * |
| 340 | * 183 11/13/98 4:25p Jason |
| 341 | * changes for better weapon effects |
| 342 | * |
| 343 | * 182 11/13/98 12:30p Jason |
| 344 | * changes for weapons |
| 345 | * |
| 346 | * 181 11/03/98 6:16p Chris |
| 347 | * Starting to make on/off and spray weapons accessable to robots |
| 348 | * |
| 349 | * 180 10/28/98 7:05p Jason |
| 350 | * made napalm work better |
| 351 | * |
| 352 | * 179 10/22/98 5:35p Chris |
| 353 | * |
| 354 | * 178 10/22/98 2:58p Chris |
| 355 | * Difficulty levels are in beta |
| 356 | * |
| 357 | * 177 10/21/98 10:33a Matt |
| 358 | * Fixed a problem where the napalm kept firing & making sound even when |
| 359 | * out of fuel. |
| 360 | * |
| 361 | * 176 10/21/98 7:33a Chris |
| 362 | * Dead objects are not-targetable |
| 363 | * |
| 364 | * 175 10/20/98 12:34p Chris |
| 365 | * Robots can now fire when players are right on them |
| 366 | * |
| 367 | * 174 10/19/98 11:46p Jason |
| 368 | * changes for multiplayer debug layer |
| 369 | * |
| 370 | * 173 10/19/98 7:18p Matt |
| 371 | * Added system to support different types of damage to the player and |
| 372 | * have these different types make different sounds. |
| 373 | * |
| 374 | * 172 10/17/98 6:14p Chris |
| 375 | * Facing explosings happen from the object position - Planar explosions |
| 376 | * happen at the wall |
| 377 | * |
| 378 | * 171 10/17/98 2:35p Jason |
| 379 | * changed some potential RT_POLYOBJ problems to OF_POLYGON_OBJECT |
| 380 | * |
| 381 | * 170 10/16/98 4:18p Chris |
| 382 | * Fixed the 'flare thing' |
| 383 | * |
| 384 | * 169 10/16/98 3:42p Chris |
| 385 | * |
| 386 | * 168 10/16/98 3:39p Chris |
| 387 | * Improved the object linking system and AI and physics |
| 388 | * |
| 389 | * 167 10/13/98 12:58p Matt |
| 390 | * Allow a weapon to fire if it has non-zero ammo, even if it doesn't have |
| 391 | * as much as the weapon requires. This assures that the ammo will go all |
| 392 | * the way to zero. |
| 393 | * |
| 394 | * 166 10/12/98 10:20a Chris |
| 395 | * Weapon hits happen at the collision point |
| 396 | * |
| 397 | * 165 10/09/98 8:13p Craig |
| 398 | * Fixed a bad merge |
| 399 | * |
| 400 | * 164 10/09/98 7:47p Chris |
| 401 | * Added ObjSetDeadFlag |
| 402 | * |
| 403 | * 163 10/07/98 12:40p Jason |
| 404 | * fixed remaining weapon firing problems |
| 405 | * |
| 406 | * 162 10/06/98 5:46p Kevin |
| 407 | * Added new configuration for demo |
| 408 | * |
| 409 | * 161 10/05/98 4:31p Chris |
| 410 | * Homers should only track a firer's enemy |
| 411 | * |
| 412 | * 160 10/01/98 6:56p Jason |
| 413 | * turned off energy weapon hit effects if the object getting hit is the |
| 414 | * viewer - this helps cut down on the general clutter in heavy combat |
| 415 | * |
| 416 | * 159 9/30/98 4:05p Jason |
| 417 | * more parenting fun |
| 418 | * |
| 419 | * 158 9/28/98 10:54a Jason |
| 420 | * tidied up some napalm stuff |
| 421 | * |
| 422 | * 157 9/28/98 10:40a Chris |
| 423 | * Fixed a homing bug with cloaked |
| 424 | * |
| 425 | * 156 9/24/98 2:36p Jason |
| 426 | * took out gaps from first person napalm |
| 427 | * |
| 428 | * 155 9/22/98 1:02p Chris |
| 429 | * Improved which weapons can use the precomputed wall collisions |
| 430 | * |
| 431 | * 154 9/17/98 3:32p Jason |
| 432 | * tweaked omega effect |
| 433 | * |
| 434 | * 153 9/11/98 12:26p Jason |
| 435 | * got energy to shield and fusion damage working in multiplayer |
| 436 | * |
| 437 | * 152 9/10/98 5:56p Chris |
| 438 | * Added more shit to the matcen code :) |
| 439 | * |
| 440 | * 151 9/09/98 4:28p Jason |
| 441 | * added better weapon effects |
| 442 | * |
| 443 | * 150 9/08/98 5:35p Jason |
| 444 | * added WF_NO_ROTATE flag to weapons |
| 445 | * |
| 446 | * 149 8/26/98 1:39p Jason |
| 447 | * added weapon fired event |
| 448 | * |
| 449 | * 148 8/25/98 6:45p Chris |
| 450 | * |
| 451 | * 147 8/25/98 4:21p Chris |
| 452 | * Fixed an attached related problem |
| 453 | * |
| 454 | * 146 8/21/98 2:06p Jason |
| 455 | * fixed a slew of weapons bugs |
| 456 | * |
| 457 | * 145 8/19/98 2:48p Jason |
| 458 | * fixed some weapon firing and weapon exploding bugs |
| 459 | * |
| 460 | * 144 8/17/98 2:59p Chris |
| 461 | * Improved parented of fired weapons from attached objects - they now use |
| 462 | * the ultimate parent |
| 463 | * |
| 464 | * 143 8/17/98 12:10p Chris |
| 465 | * Fixed MAJOR bug in getting gunpoint positions |
| 466 | * |
| 467 | * 142 8/15/98 6:11p Chris |
| 468 | * Added 13 new fields. AI fire spread works. |
| 469 | * |
| 470 | * 141 8/12/98 3:33p Jason |
| 471 | * fixed omega cannon |
| 472 | * |
| 473 | * 140 8/06/98 1:00p Chris |
| 474 | * Added new homing flags |
| 475 | * |
| 476 | * 139 8/06/98 10:59a Jason |
| 477 | * added zoom weapons |
| 478 | * |
| 479 | * 138 8/03/98 5:56p Jason |
| 480 | * got fusion cannon working correctly |
| 481 | * |
| 482 | * 137 8/03/98 3:59p Chris |
| 483 | * Added support for FQ_IGNORE_WEAPONS, added .000001 attach code, fix a |
| 484 | * bug in polymodel collision detection |
| 485 | * |
| 486 | * 136 8/03/98 1:09p Jason |
| 487 | * added some more weapons flags |
| 488 | * |
| 489 | * 135 7/31/98 11:52a Chris |
| 490 | * Weapons can be persistent. Added ability for objects to be manually |
| 491 | * set for no object collisions. |
| 492 | * |
| 493 | * 134 7/30/98 11:09a Jason |
| 494 | * added weapons that freeze and deform terrain |
| 495 | * |
| 496 | * 133 7/28/98 12:44p Jason |
| 497 | * fixed robot spawning weapon bug |
| 498 | * |
| 499 | * 132 7/23/98 12:29p Chris |
| 500 | * |
| 501 | * 131 7/22/98 6:42p Chris |
| 502 | * A relink fix for points on a wall |
| 503 | * |
| 504 | * 130 7/22/98 6:31p Chris |
| 505 | * Fixed a relink bug |
| 506 | * |
| 507 | * 129 7/20/98 4:05p Chris |
| 508 | * Fixed a bug with not being able to fire while in powerups |
| 509 | * |
| 510 | * 128 7/20/98 2:48p Chris |
| 511 | * Removed hit_time (not neccessary) |
| 512 | * |
| 513 | * 127 7/20/98 2:26p Chris |
| 514 | * |
| 515 | * 126 7/20/98 2:06p Chris |
| 516 | * Added the precomputation of some weapons (fixed speed weapons). This |
| 517 | * algorithm can be expanded to include some missiles with some minor |
| 518 | * work. |
| 519 | * |
| 520 | * 125 7/20/98 12:48p Jason |
| 521 | * fixed bug with my last rev |
| 522 | * |
| 523 | * 124 7/20/98 10:43a Jason |
| 524 | * added more player scalars, plus afterburner changes |
| 525 | * |
| 526 | * 123 7/19/98 10:38p Chris |
| 527 | * |
| 528 | * 122 7/19/98 9:44p Chris |
| 529 | * Greatly improved homing performance |
| 530 | * |
| 531 | * 121 7/17/98 5:57p Jason |
| 532 | * misc multiplayer changes |
| 533 | * |
| 534 | * 120 7/15/98 12:48p Jeff |
| 535 | * put in calls to handle new multiplayer event...when an object's shields |
| 536 | * change |
| 537 | * |
| 538 | * 119 7/07/98 6:51p Jason |
| 539 | * fixed countermeasures for Jeffs multiplay |
| 540 | * |
| 541 | * 118 7/06/98 6:57p Chris |
| 542 | * Added some parenting limits |
| 543 | * |
| 544 | * 117 7/06/98 11:51a Jason |
| 545 | * added accessor function for countermeasures |
| 546 | * |
| 547 | * 116 7/01/98 12:55p Jason |
| 548 | * more changes for countermeasures |
| 549 | * |
| 550 | * 115 7/01/98 12:12p Jason |
| 551 | * added countermeasures |
| 552 | * |
| 553 | * 114 6/30/98 11:39a Jason |
| 554 | * added AdditionalDamage packet type for multiplayer |
| 555 | * |
| 556 | * 113 6/29/98 3:08p Jason |
| 557 | * added on/off weapons |
| 558 | * |
| 559 | * 112 6/29/98 12:34p Chris |
| 560 | * Fighting robots get some notification of hostile fire |
| 561 | * |
| 562 | * 111 6/26/98 6:53p Kevin |
| 563 | * Coop mode |
| 564 | * |
| 565 | * 110 6/26/98 2:04p Jason |
| 566 | * fixed some graphical problems with the omega |
| 567 | * |
| 568 | * 109 6/24/98 4:16p Jason |
| 569 | * adjusted omega effect |
| 570 | * |
| 571 | * 108 6/24/98 3:56p Jason |
| 572 | * added code for new omega cannon |
| 573 | * |
| 574 | * 107 6/22/98 6:26p Jason |
| 575 | * added gravity field effect for weapons |
| 576 | * |
| 577 | * 106 6/19/98 12:04p Jason |
| 578 | * |
| 579 | * 105 6/16/98 10:54a Jeff |
| 580 | * |
| 581 | * 104 6/15/98 6:29p Chris |
| 582 | * Added FQ_NO_RELINK to the homing code |
| 583 | * |
| 584 | * 103 6/15/98 6:08p Chris |
| 585 | * Hit_type to hit_type[0] |
| 586 | * |
| 587 | * 102 6/15/98 4:00p Jason |
| 588 | * replaced monochromatic polymodel lighting with rgb lighting |
| 589 | * |
| 590 | * 101 5/26/98 11:36a Matt |
| 591 | * Changed small view system to allow the popup window in any of the three |
| 592 | * positions, to allow any window to be the "bigger" size, and to restore |
| 593 | * the old view when a popup view goes away. |
| 594 | * |
| 595 | * 100 5/22/98 11:59a Chris |
| 596 | * Fixed improper uses of FindSoundName and made the proper static sounds |
| 597 | * |
| 598 | * 99 5/21/98 12:34p Jason |
| 599 | * made particles drop differently |
| 600 | * |
| 601 | * 98 5/19/98 4:42a Chris |
| 602 | * Added shockwave's -- enjoy. :) |
| 603 | * |
| 604 | * 97 5/18/98 8:05p Chris |
| 605 | * Matter weapons without spawn explode on no lifeleft -- we probably |
| 606 | * could use a flag for this |
| 607 | * |
| 608 | * 96 5/18/98 3:52p Chris |
| 609 | * More error checking for invalid gun numbers. :) |
| 610 | * |
| 611 | * 95 5/04/98 11:32a Chris |
| 612 | * Made it ok for non-polyobjs to fire things |
| 613 | * |
| 614 | * 94 5/04/98 1:12a Chris |
| 615 | * Added parenting bug checking |
| 616 | * |
| 617 | * 93 4/30/98 12:22p Jason |
| 618 | * did some lo-res model optimizations |
| 619 | * |
| 620 | * 92 4/24/98 3:20p Jason |
| 621 | * took redundant out smoke trails |
| 622 | * |
| 623 | * 91 4/19/98 5:00p Jason |
| 624 | * added cool napalm effect, plus made object effects dynamically |
| 625 | * allocated |
| 626 | * |
| 627 | * 90 4/17/98 4:58p Jason |
| 628 | * fixed weapon impact spawning to spread out from the normal of the wall |
| 629 | * it hits |
| 630 | * |
| 631 | * 89 4/17/98 1:59p Jason |
| 632 | * added cool object effects |
| 633 | * |
| 634 | * 88 4/15/98 2:33p Jason |
| 635 | * changed some smoke trail stuff |
| 636 | * |
| 637 | * 87 4/15/98 12:22p Jason |
| 638 | * lots of miscellaneous stuff pertaining to lighting and vis effects |
| 639 | * |
| 640 | * 86 4/10/98 6:56p Chris |
| 641 | * Fixed problem with missiles after they are done thrusting |
| 642 | * |
| 643 | * 85 4/10/98 2:16p Jason |
| 644 | * fixed guided missile problems |
| 645 | * |
| 646 | * 84 4/10/98 12:39p Jason |
| 647 | * added expanding explosion bitmaps |
| 648 | * |
| 649 | * 83 4/09/98 4:53p Jason |
| 650 | * fixed particle bug |
| 651 | * |
| 652 | * 82 4/09/98 3:16p Chris |
| 653 | * Updated the ObjectsRelated code. |
| 654 | * |
| 655 | * 81 4/09/98 2:23p Jason |
| 656 | * added guided/afterburner stuff |
| 657 | * |
| 658 | * 80 4/09/98 12:05p Chris |
| 659 | * Added parenting for all object types. :) |
| 660 | * |
| 661 | * 79 4/07/98 3:31p Jason |
| 662 | * got particle effects working with weapons |
| 663 | * |
| 664 | * 78 4/06/98 1:07p Chris |
| 665 | * Fixed bug with cloaked players |
| 666 | * |
| 667 | * 77 3/20/98 4:47p Chris |
| 668 | * Made homing sound play faster |
| 669 | * |
| 670 | * 76 3/20/98 3:54p Chris |
| 671 | * Working on adding sounds to the game. :) |
| 672 | * |
| 673 | * 75 3/19/98 12:53p Chris |
| 674 | * Fixed problem with not being able to home on the Highest_object_index |
| 675 | * |
| 676 | * 74 3/10/98 1:00p Chris |
| 677 | * |
| 678 | * 73 3/10/98 12:51p Chris |
| 679 | * Added a truely D2 style homing missile |
| 680 | * |
| 681 | * 72 3/09/98 1:18p Chris |
| 682 | * Made the lock hueristic totally dot based. It makes the most sense. |
| 683 | * |
| 684 | * 71 3/09/98 10:49a Chris |
| 685 | * Worked on the homing code |
| 686 | * |
| 687 | * 70 3/09/98 8:12a Chris |
| 688 | * Added the start of the homing code |
| 689 | * |
| 690 | * 69 3/06/98 3:11p Chris |
| 691 | * Fixed a bug I added with the last checkin |
| 692 | * |
| 693 | * 68 3/06/98 2:15p Chris |
| 694 | * Changed target_object to target_handle |
| 695 | * |
| 696 | * 67 3/05/98 2:50p Chris |
| 697 | * A bunch of SOAR updates |
| 698 | * |
| 699 | * 66 3/02/98 4:29p Jason |
| 700 | * fixed bitmap weapon spinning |
| 701 | * |
| 702 | * 65 2/18/98 1:34a Jason |
| 703 | * fixed foolhardy assertions |
| 704 | * |
| 705 | * 64 2/17/98 11:32p Matt |
| 706 | * Fixed player wepon fire problem when down_count != 0 && down_time == 0 |
| 707 | * Add function to clear out player firing activity for when die or switch |
| 708 | * weapons |
| 709 | * |
| 710 | * 63 2/17/98 8:19p Matt |
| 711 | * Added looping & release sounds for player weapons |
| 712 | * |
| 713 | * 62 2/17/98 4:06p Jason |
| 714 | * Only explode timedout weapons if they have spawn |
| 715 | * |
| 716 | * 61 2/17/98 3:47p Matt |
| 717 | * Revamped weapon system and got sounds for spray and fusion weapons |
| 718 | * working. Still need to implements getting continuous & cutoff sounds |
| 719 | * from player ship. |
| 720 | * |
| 721 | * 60 2/16/98 3:02p Matt |
| 722 | * Changed normalized_time literal to a symbolic constant, as per ChrisP's |
| 723 | * instructions. |
| 724 | * |
| 725 | * 59 2/12/98 8:48p Matt |
| 726 | * Changed controls system to keep the reading of the controls seperate |
| 727 | * from using the results. Got rid of the Controls global. |
| 728 | * |
| 729 | * 58 2/11/98 4:10p Jason |
| 730 | * got spawning impact weapons working |
| 731 | * |
| 732 | * 57 2/11/98 2:04p Jason |
| 733 | * got spawning weapons working |
| 734 | * |
| 735 | * 56 2/09/98 3:20p Matt |
| 736 | * Added missile camera system |
| 737 | * |
| 738 | * 55 2/05/98 6:29p Jason |
| 739 | * added user settable explode time/size |
| 740 | * |
| 741 | * 54 2/05/98 12:37p Jason |
| 742 | * added more weapon effects |
| 743 | * |
| 744 | * 53 2/04/98 9:28p Jason |
| 745 | * added some new weapons effects |
| 746 | * |
| 747 | * 52 2/04/98 6:09p Matt |
| 748 | * Changed object room number to indicate a terrain cell via a flag. Got |
| 749 | * rid of the object flag which used to indicate terrain. |
| 750 | * |
| 751 | * 51 2/04/98 11:16a Jason |
| 752 | * added muzzle flash |
| 753 | * |
| 754 | * 50 2/03/98 12:03p Chris |
| 755 | * Updated how PF_USES_PARENT_VELOCITY works |
| 756 | * |
| 757 | * 49 2/02/98 4:07p Jason |
| 758 | * added a couple of weapons |
| 759 | * |
| 760 | * 48 1/29/98 6:06p Jason |
| 761 | * added new weapons |
| 762 | * |
| 763 | * 47 1/28/98 5:37p Jason |
| 764 | * added streamer weapons |
| 765 | * |
| 766 | * 46 1/28/98 12:00p Jason |
| 767 | * more changes for multiplayer |
| 768 | * |
| 769 | * 45 1/26/98 11:02a Jason |
| 770 | * fixed auto-fire bug |
| 771 | * |
| 772 | * 44 1/26/98 11:01a Jason |
| 773 | * incremental checkin for multiplayer |
| 774 | * |
| 775 | * 43 1/23/98 6:25p Jason |
| 776 | * Got spray weapons working |
| 777 | * |
| 778 | * 42 1/23/98 11:21a Jason |
| 779 | * incremental multiplayer checkin |
| 780 | * |
| 781 | * 41 1/20/98 12:10p Jason |
| 782 | * implemented vis effect system |
| 783 | * |
| 784 | * 40 1/19/98 10:04a Matt |
| 785 | * Added new object handle system |
| 786 | * |
| 787 | * 39 1/13/98 3:09p Jason |
| 788 | * added glow effect for engines |
| 789 | * |
| 790 | * 38 1/13/98 1:57p Chris |
| 791 | * Reduced parent relative velocity to 10% of the parent's velocity |
| 792 | * |
| 793 | * 37 1/10/98 2:24p Jason |
| 794 | * better multiplayer code checked in |
| 795 | * |
| 796 | * 36 12/22/97 6:19p Chris |
| 797 | * Moved weapon battery firing sound off the projectile (weapon) and into |
| 798 | * the weapon battery. |
| 799 | * |
| 800 | * 35 12/08/97 3:28p Jason |
| 801 | * tweaked explosions |
| 802 | * |
| 803 | * 34 12/03/97 11:54a Jason |
| 804 | * added designer-settable smoketrails |
| 805 | * |
| 806 | * 33 11/28/97 3:37p Jason |
| 807 | * fixed bug with alpha rendering |
| 808 | * |
| 809 | * 32 11/20/97 4:59p Jason |
| 810 | * tweaked some explosion stuff |
| 811 | * |
| 812 | * 31 11/18/97 4:37p Jason |
| 813 | * implemented some more changes to event system |
| 814 | * |
| 815 | * 30 11/13/97 5:20p Jason |
| 816 | * made bitmap weapons spin faster |
| 817 | * |
| 818 | * 29 11/12/97 5:35p Jason |
| 819 | * made energy/ammo usage work with weapon batteries |
| 820 | * |
| 821 | * 28 11/12/97 1:13p Jason |
| 822 | * added weapons that can ramp up |
| 823 | * |
| 824 | * 27 11/12/97 10:42a Chris |
| 825 | * Added an AI notify |
| 826 | * |
| 827 | * 26 11/07/97 5:33p Jason |
| 828 | * improved omega cannon effect |
| 829 | * |
| 830 | * 25 11/06/97 12:48p Chris |
| 831 | * Fixed a bug with the multi-configuration for a single wb. Actually, it |
| 832 | * will allow us to do some interesting things (like a weapon battery |
| 833 | * page). |
| 834 | * |
| 835 | * 24 11/06/97 6:17p Jason |
| 836 | * added support for electrical weapons |
| 837 | * |
| 838 | * 23 11/04/97 6:18p Chris |
| 839 | * Added support so that the player ship uses the robot's firing dialog. |
| 840 | * |
| 841 | * 22 11/03/97 4:31p Jason |
| 842 | * fixed bug when drawing bitmap weapons |
| 843 | * |
| 844 | * 21 10/30/97 4:02p Matt |
| 845 | * Added the flare |
| 846 | * |
| 847 | * 20 10/23/97 11:14a Jason |
| 848 | * changed some fireball DEFINEs |
| 849 | * |
| 850 | * 19 10/22/97 4:19p Jason |
| 851 | * added smoke trail effects |
| 852 | * |
| 853 | * 18 10/03/97 11:59a Samir |
| 854 | * Take care of setting player weapon usage stats. |
| 855 | * |
| 856 | * 17 9/17/97 11:02a Chris |
| 857 | * Fixed FindGunPoint's object transversal code (handles multiple base |
| 858 | * subobjects). Removed dependance on segment.h. |
| 859 | * |
| 860 | * 16 9/16/97 4:51p Matt |
| 861 | * Changed conditional for debug code |
| 862 | * |
| 863 | * 15 9/12/97 6:37p Chris |
| 864 | * |
| 865 | * 14 9/12/97 6:34p Chris |
| 866 | * My lasers collided with robot's lasers -- no more. |
| 867 | * |
| 868 | * 13 9/11/97 3:13p Samir |
| 869 | * Fixed missile autoeselection |
| 870 | * |
| 871 | * 12 9/05/97 12:25p Samir |
| 872 | * Added autoselection of weapons. |
| 873 | * |
| 874 | * 11 9/03/97 6:17p Jason |
| 875 | * added code to support powerups/robots/etc that cast light |
| 876 | * |
| 877 | * 10 9/03/97 3:54p Jason |
| 878 | * got objects to cast light |
| 879 | * |
| 880 | * 9 9/03/97 2:12p Chris |
| 881 | * Added new weapon battery system and made the animation system usable. |
| 882 | * |
| 883 | * 8 8/22/97 3:03a Chris |
| 884 | * |
| 885 | * 7 8/18/97 1:43a Chris |
| 886 | * Used new fvi_FindIntersection hit_seg format. FVIF_OUTSIDE bit. |
| 887 | * |
| 888 | * 6 8/07/97 5:19p Chris |
| 889 | * Expanded the weapon system |
| 890 | * |
| 891 | * 5 8/06/97 4:33p Chris |
| 892 | * Expanded the weapons page |
| 893 | * |
| 894 | * 4 8/04/97 5:35p Chris |
| 895 | * |
| 896 | * 3 7/28/97 1:12p Chris |
| 897 | * Fixed multiple bugs in the weapon system. Added fvi checking for |
| 898 | * weapon firing. Added a correct method of parenting weapons |
| 899 | * and for sibling collisions. |
| 900 | * |
| 901 | * $NoKeywords: $ |
| 902 | */ |
| 903 | |
| 904 | #include "weapon.h" |
| 905 | #include "descent.h" |
| 906 | #include "weapon.h" |
| 907 | #include "polymodel.h" |
| 908 | #include "room.h" |
| 909 | #include "object.h" |
| 910 | #include "terrain.h" |
| 911 | #include "player.h" |
| 912 | #include "hud.h" |
| 913 | #include "hlsoundlib.h" |
| 914 | #include "gameevent.h" |
| 915 | #include "polymodel.h" |
| 916 | #include "lighting.h" |
| 917 | #include "fireball.h" |
| 918 | #include <string.h> |
| 919 | #include <stdlib.h> |
| 920 | #include "findintersection.h" |
| 921 | #include "robotfire.h" |
| 922 | #include "AIMain.h" |
| 923 | #include "controls.h" |
| 924 | #include "damage.h" |
| 925 | #include "sounds.h" |
| 926 | #include "viseffect.h" |
| 927 | #include "vclip.h" |
| 928 | #include "SmallViews.h" |
| 929 | #include "hlsoundlib.h" |
| 930 | #include "soundload.h" |
| 931 | #include "stringtable.h" |
| 932 | #include "multi.h" |
| 933 | #include "game2dll.h" |
| 934 | #include "gameloop.h" |
| 935 | #include "collide.h" |
| 936 | #include "demofile.h" |
| 937 | #include "difficulty.h" |
| 938 | #include "D3ForceFeedback.h" |
| 939 | #include "config.h" |
| 940 | #include "ObjScript.h" |
| 941 | #include "doorway.h" |
| 942 | #include "psrand.h" |
| 943 | #include "BOA.h" |
| 944 | |
| 945 | #include <algorithm> |
| 946 | |
| 947 | static bool AreObjectsAttached(const object *obj1, const object *obj2) { |
| 948 | const bool f_o1_a = (obj1->flags & OF_ATTACHED) != 0; |
| 949 | const bool f_o2_a = (obj2->flags & OF_ATTACHED) != 0; |
| 950 | |
| 951 | if (f_o1_a || f_o2_a) { |
| 952 | const int o1_uh = obj1->attach_ultimate_handle; |
| 953 | const int o2_uh = obj2->attach_ultimate_handle; |
| 954 | |
| 955 | if ((f_o1_a) && ((o1_uh == obj2->handle) || (f_o2_a && (o1_uh == o2_uh)))) |
| 956 | return true; |
| 957 | |
| 958 | if ((f_o2_a) && (o2_uh == obj1->handle)) |
| 959 | return true; |
| 960 | } |
| 961 | |
| 962 | return false; |
| 963 | } |
| 964 | |
| 965 | bool ObjectsAreRelated(int o1, int o2) { |
| 966 | if ((o1 < 0) || (o2 < 0)) |
| 967 | return false; |
| 968 | |
| 969 | const object *obj1 = &Objects[o1]; |
| 970 | const object *obj2 = &Objects[o2]; |
| 971 | |
| 972 | ASSERT(obj1->handle != OBJECT_HANDLE_NONE); |
| 973 | ASSERT(obj2->handle != OBJECT_HANDLE_NONE); |
| 974 | |
| 975 | if (obj1->movement_type == MT_OBJ_LINKED || obj2->movement_type == MT_OBJ_LINKED) |
| 976 | return true; |
| 977 | |
| 978 | if (obj1->type != OBJ_SHOCKWAVE && (obj1->mtype.phys_info.flags & PF_NO_COLLIDE)) { |
| 979 | return true; |
| 980 | } |
| 981 | |
| 982 | if (obj2->type != OBJ_SHOCKWAVE && (obj2->mtype.phys_info.flags & PF_NO_COLLIDE)) { |
| 983 | return true; |
| 984 | } |
| 985 | |
| 986 | if (((obj1->type == OBJ_PLAYER) && ((obj2->type == OBJ_ROBOT) && (obj2->id == GENOBJ_CHAFFCHUNK))) || |
| 987 | ((obj2->type == OBJ_PLAYER) && ((obj1->type == OBJ_ROBOT) && (obj1->id == GENOBJ_CHAFFCHUNK)))) |
| 988 | return true; |
| 989 | |
| 990 | if (((obj1->type == OBJ_BUILDING) && (obj1->movement_type != MT_NONE) && (obj2->type == OBJ_POWERUP)) || |
| 991 | ((obj2->type == OBJ_BUILDING) && (obj2->movement_type != MT_NONE) && (obj1->type == OBJ_POWERUP))) { |
| 992 | return true; |
| 993 | } |
| 994 | |
| 995 | if (obj1->type == OBJ_DOOR && DoorwayGetPosition(&Rooms[obj1->roomnum]) == 1.0f && obj2->type == OBJ_ROBOT) |
| 996 | return true; |
| 997 | |
| 998 | if (obj2->type == OBJ_DOOR && DoorwayGetPosition(&Rooms[obj2->roomnum]) == 1.0f && obj1->type == OBJ_ROBOT) |
| 999 | return true; |
| 1000 | |
| 1001 | if (AreObjectsAttached(obj1, obj2)) |
| 1002 | return true; |
| 1003 | |
| 1004 | if (obj1->type != OBJ_WEAPON && obj2->type != OBJ_WEAPON) { |
| 1005 | if (((Gametime < obj1->creation_time + 3.0f) && obj1->parent_handle == obj2->handle) || |
| 1006 | ((Gametime < obj2->creation_time + 3.0f) && obj2->parent_handle == obj1->handle)) |
| 1007 | return true; |
| 1008 | else |
| 1009 | return false; |
| 1010 | } |
| 1011 | |
| 1012 | if (obj1->type == OBJ_WEAPON && obj1->movement_type == MT_PHYSICS && (obj1->mtype.phys_info.flags & PF_PERSISTENT) && |
| 1013 | obj1->ctype.laser_info.last_hit_handle == obj2->handle) |
| 1014 | return true; |
| 1015 | |
| 1016 | if (obj2->type == OBJ_WEAPON && obj2->movement_type == MT_PHYSICS && (obj2->mtype.phys_info.flags & PF_PERSISTENT) && |
| 1017 | obj2->ctype.laser_info.last_hit_handle == obj1->handle) |
| 1018 | return true; |
| 1019 | |
| 1020 | // See if o2 is the parent of o1 |
| 1021 | if (obj1->type == OBJ_WEAPON && (obj1->mtype.phys_info.flags & PF_NO_COLLIDE_PARENT)) { |
| 1022 | if (obj1->parent_handle == obj2->handle) |
| 1023 | return true; |
| 1024 | |
| 1025 | object *t1 = ObjGet(obj1->parent_handle); |
| 1026 | |
| 1027 | if (t1) { |
| 1028 | if (AreObjectsAttached(obj2, t1)) |
| 1029 | return true; |
| 1030 | } |
| 1031 | } |
| 1032 | |
| 1033 | // See if o1 is the parent of o2 |
| 1034 | if (obj2->type == OBJ_WEAPON && (obj2->mtype.phys_info.flags & PF_NO_COLLIDE_PARENT)) { |
| 1035 | if (obj2->parent_handle == obj1->handle) |
| 1036 | return true; |
| 1037 | |
| 1038 | object *t2 = ObjGet(obj2->parent_handle); |
| 1039 | |
| 1040 | if (t2) { |
| 1041 | if (AreObjectsAttached(obj1, t2)) |
| 1042 | return true; |
| 1043 | } |
| 1044 | } |
| 1045 | |
| 1046 | // They must both be weapons |
| 1047 | if (obj1->type != OBJ_WEAPON || obj2->type != OBJ_WEAPON) { |
| 1048 | return false; |
| 1049 | } |
| 1050 | |
| 1051 | // Here is the 09/07/94 change -- Siblings must be identical, others can hurt each other |
| 1052 | // See if they're siblings... |
| 1053 | if (obj1->parent_handle == obj2->parent_handle) { |
| 1054 | if ((obj1->mtype.phys_info.flags & PF_HITS_SIBLINGS) || (obj2->mtype.phys_info.flags & PF_HITS_SIBLINGS)) { |
| 1055 | return false; // if either is proximity, then can blow up, so say not related |
| 1056 | } else { |
| 1057 | return true; |
| 1058 | } |
| 1059 | } |
| 1060 | |
| 1061 | // Otherwise, it is two weapons and by default, they should not collide |
| 1062 | return true; |
| 1063 | } |
| 1064 | |
| 1065 | bool Enable_omega_collions = false; |
| 1066 | |
| 1067 | // Picks out a target for an elecrical weapon to fire on |
| 1068 | void AquireElectricalTarget(object *obj) { |
| 1069 | int i; |
| 1070 | float closest_dist = 99999, dist; |
| 1071 | object *closest_obj = NULL, *hit_obj_ptr; |
| 1072 | |
| 1073 | if (obj->mtype.phys_info.flags & PF_HOMING) { |
| 1074 | for (i = 0; i <= Highest_object_index; i++) { |
| 1075 | hit_obj_ptr = &Objects[i]; |
| 1076 | |
| 1077 | if ((hit_obj_ptr->render_type == RT_NONE) || |
| 1078 | !(hit_obj_ptr->type == OBJ_PLAYER || hit_obj_ptr->type == OBJ_ROBOT || |
| 1079 | (hit_obj_ptr->type == OBJ_BUILDING && hit_obj_ptr->ai_info))) |
| 1080 | continue; |
| 1081 | |
| 1082 | if (ObjectsAreRelated(OBJNUM(obj), i)) |
| 1083 | continue; |
| 1084 | |
| 1085 | if (obj == hit_obj_ptr) |
| 1086 | continue; |
| 1087 | |
| 1088 | if (hit_obj_ptr->flags & OF_DEAD) |
| 1089 | continue; |
| 1090 | |
| 1091 | // The GB has an "electric shield" that works kind of like a Faraday's Cage (it also |
| 1092 | // make him less annoying as a player's own Omega will not track his GB) |
| 1093 | if (IS_GUIDEBOT(hit_obj_ptr)) |
| 1094 | continue; |
| 1095 | |
| 1096 | // Make sure this target is within our view cone |
| 1097 | vector subvec = hit_obj_ptr->pos - obj->pos; |
| 1098 | vm_NormalizeVectorFast(&subvec); |
| 1099 | if (vm_DotProduct(&subvec, &obj->orient.fvec) < .8) |
| 1100 | continue; |
| 1101 | |
| 1102 | // The distance is actually the objects' centers minus some of the hit object's radius (I set it to 80%) |
| 1103 | if ((hit_obj_ptr->flags & OF_POLYGON_OBJECT) && hit_obj_ptr->type != OBJ_WEAPON && |
| 1104 | hit_obj_ptr->type != OBJ_POWERUP && hit_obj_ptr->type != OBJ_DEBRIS) { |
| 1105 | vector pos; |
| 1106 | pos = hit_obj_ptr->pos + hit_obj_ptr->wall_sphere_offset; |
| 1107 | |
| 1108 | dist = vm_VectorDistanceQuick(&pos, &obj->pos) - Poly_models[hit_obj_ptr->rtype.pobj_info.model_num].wall_size; |
| 1109 | } else { |
| 1110 | dist = vm_VectorDistanceQuick(&hit_obj_ptr->pos, &obj->pos) - hit_obj_ptr->size; |
| 1111 | } |
| 1112 | |
| 1113 | if (dist < 0.0f) |
| 1114 | dist = 0.0f; |
| 1115 | if (dist > 50) |
| 1116 | continue; |
| 1117 | |
| 1118 | if (dist <= closest_dist) { |
| 1119 | closest_dist = dist; |
| 1120 | closest_obj = hit_obj_ptr; |
| 1121 | } |
| 1122 | } |
| 1123 | } |
| 1124 | |
| 1125 | if (closest_obj != NULL) { |
| 1126 | float old_shield, new_shield; |
| 1127 | if (closest_obj->effect_info && closest_obj != Viewer_object) { |
| 1128 | closest_obj->effect_info->type_flags |= EF_DEFORM; |
| 1129 | closest_obj->effect_info->deform_time = 1.0; |
| 1130 | closest_obj->effect_info->deform_range = .03f; |
| 1131 | } |
| 1132 | |
| 1133 | obj->ctype.laser_info.track_handle = closest_obj->handle; |
| 1134 | |
| 1135 | vector subvec = obj->pos - closest_obj->pos; |
| 1136 | vm_NormalizeVectorFast(&subvec); |
| 1137 | |
| 1138 | old_shield = closest_obj->shields; |
| 1139 | |
| 1140 | vector save_pos = obj->pos; |
| 1141 | vector col_norm = {0, 1, 0}; |
| 1142 | obj->pos = closest_obj->pos; |
| 1143 | |
| 1144 | Enable_omega_collions = true; |
| 1145 | collide_two_objects(obj, closest_obj, &closest_obj->pos, &col_norm); |
| 1146 | Enable_omega_collions = false; |
| 1147 | |
| 1148 | obj->pos = save_pos; |
| 1149 | new_shield = closest_obj->shields; |
| 1150 | |
| 1151 | object *parent_obj = ObjGet(obj->parent_handle); |
| 1152 | |
| 1153 | if (parent_obj->shields < 100) { |
| 1154 | float shields_to_add = (old_shield - new_shield) * .1; |
| 1155 | if (parent_obj->shields + shields_to_add > 100) |
| 1156 | shields_to_add = 100 - parent_obj->shields; |
| 1157 | |
| 1158 | if (Game_mode & GM_MULTI) { |
| 1159 | if (Netgame.local_role == LR_SERVER) { |
| 1160 | parent_obj->shields += shields_to_add; |
| 1161 | Multi_additional_damage[parent_obj->id] -= shields_to_add; |
| 1162 | Multi_additional_damage_type[parent_obj->id] = PD_ENERGY_WEAPON; |
| 1163 | |
| 1164 | DLLInfo.it_handle = -1; |
| 1165 | DLLInfo.me_handle = parent_obj->handle; |
| 1166 | DLLInfo.fParam = shields_to_add; |
| 1167 | CallGameDLL(EVT_GAMEOBJECTSHIELDSCHANGED, &DLLInfo); |
| 1168 | } |
| 1169 | } else |
| 1170 | parent_obj->shields += shields_to_add; |
| 1171 | } |
| 1172 | } else { |
| 1173 | obj->ctype.laser_info.track_handle = OBJECT_HANDLE_NONE; |
| 1174 | |
| 1175 | // Cast a ray to see what we've hit |
| 1176 | int fate; // Collision type for response code |
| 1177 | fvi_info hit_info; // Hit information |
| 1178 | fvi_query fq; // Movement query |
| 1179 | vector dest = obj->pos + (obj->orient.fvec * 50.0); |
| 1180 | |
| 1181 | fq.p0 = &obj->pos; |
| 1182 | fq.startroom = obj->roomnum; |
| 1183 | fq.p1 = &dest; |
| 1184 | fq.rad = .0001f; |
| 1185 | fq.thisobjnum = Objects - obj; |
| 1186 | fq.ignore_obj_list = NULL; |
| 1187 | fq.flags = FQ_CHECK_OBJS | FQ_IGNORE_POWERUPS | FQ_IGNORE_WEAPONS; |
| 1188 | |
| 1189 | fate = fvi_FindIntersection(&fq, &hit_info); |
| 1190 | |
| 1191 | vector save_pos = obj->pos; |
| 1192 | |
| 1193 | if (fate == HIT_WALL || fate == HIT_TERRAIN) { |
| 1194 | obj->pos = hit_info.hit_pnt; |
| 1195 | collide_object_with_wall(obj, 0, hit_info.hit_face_room[0], hit_info.hit_face[0], &hit_info.hit_face_pnt[0], |
| 1196 | &hit_info.hit_wallnorm[0], 0); |
| 1197 | } else if (fate == HIT_OBJECT || fate == HIT_SPHERE_2_POLY_OBJECT) { |
| 1198 | if (CollisionResult[obj->type][Objects[hit_info.hit_object[0]].type] != RESULT_NOTHING) { |
| 1199 | obj->pos = hit_info.hit_pnt; |
| 1200 | Enable_omega_collions = true; |
| 1201 | collide_two_objects(obj, &Objects[hit_info.hit_object[0]], &hit_info.hit_face_pnt[0], |
| 1202 | &hit_info.hit_wallnorm[0]); |
| 1203 | Enable_omega_collions = false; |
| 1204 | } |
| 1205 | } |
| 1206 | |
| 1207 | obj->pos = save_pos; |
| 1208 | obj->flags &= ~OF_DEAD; // Bring it back from the dead in case the collide code killed it! |
| 1209 | } |
| 1210 | } |
| 1211 | |
| 1212 | // Creates an weapon and sends it speeding on its way |
| 1213 | int CreateAndFireWeapon(vector *pos, vector *dir, object *parent, int weapon_num) { |
| 1214 | int objnum; |
| 1215 | object *obj; |
| 1216 | int parentnum = parent - Objects; |
| 1217 | uint8_t terrain = 0; |
| 1218 | |
| 1219 | ASSERT(Weapons[weapon_num].used); |
| 1220 | |
| 1221 | // This can happen in multiplayer -- not single player |
| 1222 | if (parent->flags & OF_DEAD) |
| 1223 | return -1; |
| 1224 | |
| 1225 | // Find out if it is o.k. to create a weapon here. |
| 1226 | fvi_query fq; |
| 1227 | fvi_info hit_data; |
| 1228 | int fate; |
| 1229 | |
| 1230 | fq.p0 = &parent->pos; |
| 1231 | fq.startroom = parent->roomnum; |
| 1232 | fq.p1 = pos; |
| 1233 | fq.rad = 0; |
| 1234 | fq.thisobjnum = OBJNUM(parent); |
| 1235 | fq.ignore_obj_list = NULL; |
| 1236 | fq.flags = FQ_CHECK_OBJS | FQ_IGNORE_WEAPONS | FQ_IGNORE_POWERUPS | |
| 1237 | FQ_IGNORE_NON_LIGHTMAP_OBJECTS; // what about trans walls??? |
| 1238 | |
| 1239 | if (parent->type == OBJ_BUILDING) { |
| 1240 | fq.flags &= ~FQ_CHECK_OBJS; |
| 1241 | } |
| 1242 | |
| 1243 | fate = fvi_FindIntersection(&fq, &hit_data); |
| 1244 | if (fate != HIT_NONE) { |
| 1245 | mprintf(0, "Warning: Laser from parent=%d weapon point is in a wall or object, didn't fire!\n", OBJNUM(parent)); |
| 1246 | return -1; |
| 1247 | } |
| 1248 | |
| 1249 | objnum = ObjCreate(OBJ_WEAPON, weapon_num, hit_data.hit_room, pos, NULL, parent->handle); |
| 1250 | |
| 1251 | if (objnum < 0) { |
| 1252 | mprintf(1, "Can't create laser - Out of objects!\n"); |
| 1253 | return -1; |
| 1254 | } |
| 1255 | |
| 1256 | obj = &Objects[objnum]; |
| 1257 | |
| 1258 | // Fill in laser-specific data |
| 1259 | obj->ctype.laser_info.multiplier = 1.0; |
| 1260 | obj->ctype.laser_info.parent_type = parent->type; |
| 1261 | |
| 1262 | if (parent->flags & OF_ATTACHED) |
| 1263 | obj->parent_handle = parent->attach_ultimate_handle; |
| 1264 | else |
| 1265 | obj->parent_handle = parent->handle; |
| 1266 | |
| 1267 | // Assign parent type to highest level creator. This propagates parent type down from |
| 1268 | // the original creator through weapons which create children of their own (ie, smart missile) |
| 1269 | object *p = parent; |
| 1270 | while (p && (p->type == OBJ_WEAPON)) { |
| 1271 | p = ObjGet(p->parent_handle); |
| 1272 | if (p) { |
| 1273 | obj->ctype.laser_info.parent_type = p->type; |
| 1274 | obj->parent_handle = p->handle; |
| 1275 | } |
| 1276 | } |
| 1277 | |
| 1278 | // Set direction |
| 1279 | vm_VectorToMatrix(&obj->orient, dir, &parent->orient.uvec, NULL); |
| 1280 | |
| 1281 | float scalar = 1.0f; |
| 1282 | if (!ObjGet(obj->parent_handle) || ObjGet(obj->parent_handle)->type != OBJ_PLAYER) |
| 1283 | scalar = (ObjGet(obj->parent_handle)->control_type == CT_AI && |
| 1284 | ((ObjGet(obj->parent_handle)->ai_info->flags & AIF_TEAM_MASK) == AIF_TEAM_REBEL)) |
| 1285 | ? 1.0f |
| 1286 | : Diff_ai_weapon_speed[DIFF_LEVEL]; |
| 1287 | |
| 1288 | // Set thrust |
| 1289 | if (obj->mtype.phys_info.flags & PF_USES_THRUST) { |
| 1290 | vm_ScaleVector(&obj->mtype.phys_info.thrust, dir, obj->mtype.phys_info.full_thrust * scalar); |
| 1291 | // If this is a player, scale the thrust based on the players weapon_speed scalar |
| 1292 | if (parent->type == OBJ_PLAYER) |
| 1293 | obj->mtype.phys_info.thrust *= Players[parent->id].weapon_speed_scalar; |
| 1294 | } else { |
| 1295 | vm_MakeZero(&obj->mtype.phys_info.thrust); |
| 1296 | vm_MakeZero(&obj->mtype.phys_info.rotthrust); |
| 1297 | } |
| 1298 | // vm_MakeZero(&obj->mtype.phys_info.rotvel); |
| 1299 | |
| 1300 | // Set the initial velocity |
| 1301 | vm_ScaleVector(&obj->mtype.phys_info.velocity, dir, Weapons[weapon_num].phys_info.velocity.z * scalar); |
| 1302 | |
| 1303 | // If this is a player, scale the velocity based on the players weapon_speed scalar |
| 1304 | if (parent->type == OBJ_PLAYER) |
| 1305 | obj->mtype.phys_info.velocity *= Players[parent->id].weapon_speed_scalar; |
| 1306 | |
| 1307 | // Set initial velocity to that of the firing object |
| 1308 | // Don't do it though if its a spawned weapon |
| 1309 | if ((obj->mtype.phys_info.flags & PF_USES_PARENT_VELOCITY) && parent->type != OBJ_WEAPON) { |
| 1310 | |
| 1311 | float fdot = (parent->mtype.phys_info.velocity * parent->orient.fvec); |
| 1312 | vector fvel; |
| 1313 | |
| 1314 | if (fdot > 0.0) |
| 1315 | fvel = parent->orient.fvec * fdot; |
| 1316 | else |
| 1317 | fvel = Zero_vector; |
| 1318 | |
| 1319 | vector rvel = 0.1f * parent->orient.rvec * (parent->mtype.phys_info.velocity * parent->orient.rvec); |
| 1320 | vector uvel = 0.1f * parent->orient.uvec * (parent->mtype.phys_info.velocity * parent->orient.uvec); |
| 1321 | |
| 1322 | obj->mtype.phys_info.velocity += fvel + rvel + uvel; |
| 1323 | } |
| 1324 | |
| 1325 | if (Weapons[obj->id].flags & WF_ELECTRICAL) { |
| 1326 | AquireElectricalTarget(obj); |
| 1327 | } else if (obj->movement_type == MT_PHYSICS) { |
| 1328 | if (!((obj->mtype.phys_info.flags & PF_USES_PARENT_VELOCITY) && (obj->mtype.phys_info.flags & PF_USES_THRUST))) { |
| 1329 | // For now, it only works on fixed velocity weapons |
| 1330 | if ((obj->mtype.phys_info.flags & PF_FIXED_VELOCITY) && |
| 1331 | !(obj->mtype.phys_info.flags & (PF_GRAVITY_MASK | PF_HOMING | PF_WIGGLE | PF_GUIDED))) { |
| 1332 | fvi_query fq; |
| 1333 | fvi_info hit_info; |
| 1334 | vector end_pos = obj->pos + obj->mtype.phys_info.velocity * obj->lifeleft; |
| 1335 | |
| 1336 | fq.p0 = &obj->pos; |
| 1337 | fq.startroom = obj->roomnum; |
| 1338 | fq.p1 = &end_pos; |
| 1339 | fq.rad = obj->size; |
| 1340 | fq.thisobjnum = OBJNUM(obj); |
| 1341 | fq.ignore_obj_list = NULL; |
| 1342 | fq.flags = 0; |
| 1343 | |
| 1344 | fq.flags |= FQ_TRANSPOINT; |
| 1345 | |
| 1346 | fate = fvi_FindIntersection(&fq, &hit_info); |
| 1347 | |
| 1348 | if (fate != HIT_NONE && fate != HIT_OUT_OF_TERRAIN_BOUNDS) { |
| 1349 | float try_dist = vm_VectorDistance(&obj->pos, &end_pos); |
| 1350 | float got_dist = vm_VectorDistance(&obj->pos, &hit_info.hit_pnt); |
| 1351 | |
| 1352 | obj->ctype.laser_info.hit_pnt = hit_info.hit_pnt; |
| 1353 | obj->ctype.laser_info.hit_wall_pnt = hit_info.hit_face_pnt[0]; |
| 1354 | obj->ctype.laser_info.hit_room = hit_info.hit_room; |
| 1355 | obj->ctype.laser_info.hit_pnt_room = hit_info.hit_face_room[0]; |
| 1356 | obj->ctype.laser_info.hit_wall_normal = hit_info.hit_wallnorm[0]; |
| 1357 | obj->ctype.laser_info.hit_face = hit_info.hit_face[0]; |
| 1358 | |
| 1359 | obj->ctype.laser_info.hit_status = WPC_HIT_WALL; |
| 1360 | // mprintf(0, "WPC: Hit r%d rw%d w%d (%f,%f,%f)\n", hit_info.hit_room, |
| 1361 | // hit_info.hit_face_room[0], hit_info.hit_face[0], XYZ(&hit_info.hit_wallnorm[0])); |
| 1362 | } else { |
| 1363 | obj->ctype.laser_info.hit_status = WPC_NO_COLLISIONS; |
| 1364 | // mprintf(0, "WPC: No collisions\n"); |
| 1365 | } |
| 1366 | } |
| 1367 | } |
| 1368 | } |
| 1369 | |
| 1370 | if (parent && (parent->type == OBJ_PLAYER || parent->type == OBJ_GHOST) && (parent->id == Player_num)) { |
| 1371 | // Do ForceFeeback for recoil |
| 1372 | DoForceForRecoil(parent, obj); |
| 1373 | } |
| 1374 | |
| 1375 | // For smoke effects |
| 1376 | obj->ctype.laser_info.last_smoke_pos = obj->pos - (obj->orient.fvec * (obj->size / 2)); |
| 1377 | obj->ctype.laser_info.casts_light = true; |
| 1378 | return objnum; |
| 1379 | } |
| 1380 | |
| 1381 | // Steers a homing missile |
| 1382 | void HomingTurnTowardObj(object *weapon, object *target) { |
| 1383 | vector dir_to_target; |
| 1384 | vector movement = Zero_vector; |
| 1385 | |
| 1386 | if (target == NULL) |
| 1387 | return; |
| 1388 | |
| 1389 | if (target->movement_type == MT_PHYSICS || target->movement_type == MT_WALKING) { |
| 1390 | movement = 0.1f * (target->mtype.phys_info.velocity); |
| 1391 | } |
| 1392 | |
| 1393 | dir_to_target = target->pos + movement - weapon->pos; |
| 1394 | |
| 1395 | if (weapon->mtype.phys_info.rotdrag > 0.0f) { |
| 1396 | if (dir_to_target * weapon->orient.rvec > 0.0) { |
| 1397 | weapon->mtype.phys_info.rotthrust.y = weapon->mtype.phys_info.full_rotthrust; |
| 1398 | } else { |
| 1399 | weapon->mtype.phys_info.rotthrust.y = -weapon->mtype.phys_info.full_rotthrust; |
| 1400 | } |
| 1401 | |
| 1402 | if (dir_to_target * weapon->orient.uvec > 0.0) { |
| 1403 | weapon->mtype.phys_info.rotthrust.x = -weapon->mtype.phys_info.full_rotthrust; |
| 1404 | } else { |
| 1405 | weapon->mtype.phys_info.rotthrust.x = weapon->mtype.phys_info.full_rotthrust; |
| 1406 | } |
| 1407 | |
| 1408 | weapon->mtype.phys_info.rotthrust.z = 0.0; |
| 1409 | |
| 1410 | if (!ObjGet(weapon->parent_handle) || ObjGet(weapon->parent_handle)->type != OBJ_PLAYER) |
| 1411 | weapon->mtype.phys_info.rotthrust *= Diff_homing_strength[DIFF_LEVEL]; |
| 1412 | } else { |
| 1413 | float scalar; |
| 1414 | vm_NormalizeVector(&dir_to_target); |
| 1415 | |
| 1416 | if (!ObjGet(weapon->parent_handle) || ObjGet(weapon->parent_handle)->type != OBJ_PLAYER) |
| 1417 | scalar = Diff_homing_strength[DIFF_LEVEL]; |
| 1418 | else |
| 1419 | scalar = 1.0f; |
| 1420 | |
| 1421 | AITurnTowardsDir(weapon, &dir_to_target, weapon->mtype.phys_info.full_rotthrust * scalar); |
| 1422 | weapon->mtype.phys_info.velocity = |
| 1423 | weapon->orient.fvec * weapon->mtype.phys_info.full_thrust / weapon->mtype.phys_info.drag; |
| 1424 | weapon->mtype.phys_info.thrust = weapon->orient.fvec * weapon->mtype.phys_info.full_thrust; |
| 1425 | } |
| 1426 | } |
| 1427 | |
| 1428 | #define MAX_HOMING_DIST 500.0f |
| 1429 | #define CLOSE_HOMING_DIST 15.0 |
| 1430 | |
| 1431 | #define MAX_HOMING_SOUND_TIME_DIST 250.00f |
| 1432 | #define MAX_HOMING_SOUND_TIME 1.00f |
| 1433 | #define MIN_HOMING_SOUND_TIME 0.05f |
| 1434 | #define HOMING_CHECK_VIS_INTERVAL 0.25f |
| 1435 | #define HOMING_FIND_LOC_INTERVAL 0.20f |
| 1436 | |
| 1437 | object *HomingAquireTarget(object *obj) { |
| 1438 | object *track_goal = ObjGet(obj->ctype.laser_info.track_handle); |
| 1439 | object *weapon_parent = ObjGet(obj->parent_handle); |
| 1440 | |
| 1441 | // Forces its parent to itself if there is no parent |
| 1442 | if (weapon_parent == NULL) { |
| 1443 | weapon_parent = obj; |
| 1444 | } |
| 1445 | |
| 1446 | // Determine if the current track_goal is valid |
| 1447 | if (track_goal) { |
| 1448 | bool f_locked = false; |
| 1449 | |
| 1450 | vector to_target = track_goal->pos - obj->pos; |
| 1451 | float dist_to_target = vm_NormalizeVector(&to_target) - track_goal->size - obj->size; |
| 1452 | |
| 1453 | if (obj->type == OBJ_GHOST || obj->type == OBJ_DUMMY || |
| 1454 | (obj->type == OBJ_PLAYER && (Players[obj->id].flags & PLAYER_FLAGS_DEAD))) { |
| 1455 | f_locked = false; |
| 1456 | } else if (obj->effect_info && (obj->effect_info->type_flags & EF_CLOAKED)) { |
| 1457 | f_locked = false; |
| 1458 | } else if (to_target * obj->orient.fvec > Weapons[obj->id].homing_fov) { |
| 1459 | if (track_goal == Player_object && Player_object->type == OBJ_PLAYER) { |
| 1460 | float sound_delta; |
| 1461 | float volume; |
| 1462 | |
| 1463 | if (dist_to_target > MAX_HOMING_SOUND_TIME_DIST) { |
| 1464 | sound_delta = MAX_HOMING_SOUND_TIME; |
| 1465 | volume = MAX_GAME_VOLUME / 2.0f; |
| 1466 | } else { |
| 1467 | float percent_near = dist_to_target / (float)MAX_HOMING_SOUND_TIME_DIST; |
| 1468 | |
| 1469 | sound_delta = MAX_HOMING_SOUND_TIME * percent_near; |
| 1470 | volume = MAX_GAME_VOLUME / 2.0f + MAX_GAME_VOLUME / 2.0 * (1.0f - percent_near); |
| 1471 | |
| 1472 | if (sound_delta < MIN_HOMING_SOUND_TIME) { |
| 1473 | sound_delta = MIN_HOMING_SOUND_TIME; |
| 1474 | volume = MAX_GAME_VOLUME; |
| 1475 | } |
| 1476 | } |
| 1477 | |
| 1478 | if (!(obj->type == OBJ_WEAPON && Weapons[obj->id].flags & WF_SILENT_HOMING) && |
| 1479 | !(obj->mtype.phys_info.flags & PF_GUIDED) && |
| 1480 | Players[Player_object->id].last_homing_warning_sound_time + sound_delta < Gametime) { |
| 1481 | fvi_query fq; |
| 1482 | fvi_info hit_info; |
| 1483 | |
| 1484 | fq.p0 = &obj->pos; |
| 1485 | fq.startroom = obj->roomnum; |
| 1486 | fq.p1 = &track_goal->pos; |
| 1487 | fq.rad = 0.0f; |
| 1488 | fq.thisobjnum = OBJNUM(obj); |
| 1489 | fq.ignore_obj_list = NULL; |
| 1490 | fq.flags = /*FQ_TRANSPOINT | */ FQ_CHECK_OBJS | FQ_ONLY_DOOR_OBJ | FQ_NO_RELINK; |
| 1491 | |
| 1492 | fvi_FindIntersection(&fq, &hit_info); |
| 1493 | |
| 1494 | // Only plays sound if there is a LOS between the player and the homing weapon |
| 1495 | if (hit_info.hit_type[0] == HIT_NONE) { |
| 1496 | Sound_system.Play2dSound(SOUND_MISSLE_LOCK, SND_PRIORITY_HIGHEST, volume); |
| 1497 | Players[Player_object->id].last_homing_warning_sound_time = Gametime; |
| 1498 | } |
| 1499 | } |
| 1500 | } |
| 1501 | |
| 1502 | if (dist_to_target < CLOSE_HOMING_DIST) { |
| 1503 | f_locked = true; |
| 1504 | } else if (dist_to_target < MAX_HOMING_DIST) { |
| 1505 | if (BOA_IsVisible(obj->roomnum, track_goal->roomnum)) { |
| 1506 | if (Gametime > obj->ctype.laser_info.last_track_time + HOMING_CHECK_VIS_INTERVAL) { |
| 1507 | obj->ctype.laser_info.last_track_time = Gametime; |
| 1508 | fvi_query fq; |
| 1509 | fvi_info hit_info; |
| 1510 | |
| 1511 | fq.p0 = &obj->pos; |
| 1512 | fq.startroom = obj->roomnum; |
| 1513 | fq.p1 = &track_goal->pos; |
| 1514 | fq.rad = 0.0f; |
| 1515 | fq.thisobjnum = OBJNUM(obj); |
| 1516 | fq.ignore_obj_list = NULL; |
| 1517 | fq.flags = /*FQ_TRANSPOINT | */ FQ_CHECK_OBJS | FQ_ONLY_DOOR_OBJ | FQ_NO_RELINK; |
| 1518 | |
| 1519 | fvi_FindIntersection(&fq, &hit_info); |
| 1520 | if (hit_info.hit_type[0] == HIT_NONE) { |
| 1521 | f_locked = true; |
| 1522 | } |
| 1523 | } else { |
| 1524 | f_locked = true; |
| 1525 | } |
| 1526 | } |
| 1527 | } |
| 1528 | } |
| 1529 | |
| 1530 | if (!f_locked) { |
| 1531 | track_goal = NULL; |
| 1532 | obj->ctype.laser_info.track_handle = OBJECT_HANDLE_NONE; |
| 1533 | } |
| 1534 | } |
| 1535 | |
| 1536 | // Determine a track_goal if there is not one |
| 1537 | if (!track_goal) { |
| 1538 | int i; |
| 1539 | int best_index = -1; |
| 1540 | int best_dist = MAX_HOMING_DIST + 1; |
| 1541 | float best_dot = -1.0f; |
| 1542 | |
| 1543 | if (Gametime > obj->ctype.laser_info.last_track_time + HOMING_FIND_LOC_INTERVAL) { |
| 1544 | obj->ctype.laser_info.last_track_time = Gametime; |
| 1545 | |
| 1546 | for (i = 0; i <= Highest_object_index; i++) { |
| 1547 | if (BOA_IsVisible(obj->roomnum, Objects[i].roomnum)) { |
| 1548 | if ((i != OBJNUM(weapon_parent)) && ((Objects[i].type == OBJ_BUILDING && Objects[i].ai_info) || |
| 1549 | (Objects[i].type == OBJ_ROBOT) || (Objects[i].type == OBJ_PLAYER))) { |
| 1550 | vector to_target = Objects[i].pos - obj->pos; |
| 1551 | |
| 1552 | if (Objects[i].effect_info && Objects[i].effect_info->type_flags & EF_CLOAKED) |
| 1553 | continue; |
| 1554 | |
| 1555 | if (weapon_parent && !AIObjEnemy(ObjGetUltimateParent(weapon_parent), ObjGetUltimateParent(&Objects[i]))) |
| 1556 | continue; |
| 1557 | |
| 1558 | float dist_to_target = vm_NormalizeVector(&to_target) - obj->size - Objects[i].size; |
| 1559 | float cur_dot = to_target * obj->orient.fvec; |
| 1560 | |
| 1561 | if (cur_dot > Weapons[obj->id].homing_fov) { |
| 1562 | // Pick chaff over other objects |
| 1563 | if ((Objects[i].type == OBJ_ROBOT) && (Objects[i].id == GENOBJ_CHAFFCHUNK)) { |
| 1564 | // Make multiplayer safe! |
| 1565 | if (Game_mode & GM_MULTI) { |
| 1566 | if (Netgame.local_role == LR_CLIENT) { |
| 1567 | if (!(Local_object_list[i] & 0x3)) { |
| 1568 | best_index = i; |
| 1569 | break; |
| 1570 | } |
| 1571 | } else { |
| 1572 | if (!(i & 0x3)) { |
| 1573 | best_index = i; |
| 1574 | break; |
| 1575 | } |
| 1576 | } |
| 1577 | } else { |
| 1578 | if (ps_rand() < D3_RAND_MAX / 4) { // 1/4 chance of picking chaff |
| 1579 | best_index = i; |
| 1580 | break; |
| 1581 | } |
| 1582 | } |
| 1583 | } else if (dist_to_target < CLOSE_HOMING_DIST) { |
| 1584 | best_index = i; |
| 1585 | break; |
| 1586 | } else if (dist_to_target < MAX_HOMING_DIST) { |
| 1587 | if (cur_dot > best_dot) { |
| 1588 | |
| 1589 | fvi_query fq; |
| 1590 | fvi_info hit_info; |
| 1591 | |
| 1592 | fq.p0 = &obj->pos; |
| 1593 | fq.startroom = obj->roomnum; |
| 1594 | fq.p1 = &Objects[i].pos; |
| 1595 | fq.rad = 0.0f; |
| 1596 | fq.thisobjnum = OBJNUM(obj); |
| 1597 | fq.ignore_obj_list = NULL; |
| 1598 | fq.flags = FQ_TRANSPOINT | FQ_CHECK_OBJS | FQ_ONLY_DOOR_OBJ | FQ_NO_RELINK; |
| 1599 | |
| 1600 | fvi_FindIntersection(&fq, &hit_info); |
| 1601 | if (hit_info.hit_type[0] == HIT_NONE) { |
| 1602 | best_index = i; |
| 1603 | best_dist = dist_to_target; |
| 1604 | best_dot = cur_dot; |
| 1605 | } |
| 1606 | } |
| 1607 | } |
| 1608 | } |
| 1609 | } |
| 1610 | } |
| 1611 | } |
| 1612 | if (best_index >= 0) { |
| 1613 | track_goal = &Objects[best_index]; |
| 1614 | obj->ctype.laser_info.track_handle = Objects[best_index].handle; |
| 1615 | } |
| 1616 | } |
| 1617 | } |
| 1618 | |
| 1619 | return track_goal; |
| 1620 | } |
| 1621 | |
| 1622 | // Does homing code |
| 1623 | void HomingDoFrame(object *obj) { |
| 1624 | obj->mtype.phys_info.rotthrust = Zero_vector; |
| 1625 | |
| 1626 | HomingTurnTowardObj(obj, HomingAquireTarget(obj)); |
| 1627 | } |
| 1628 | |
| 1629 | void WeaponDoFrame(object *obj) { |
| 1630 | bool draw_effects = 1; |
| 1631 | |
| 1632 | if (!Detail_settings.Weapon_coronas_enabled) |
| 1633 | draw_effects = 0; |
| 1634 | |
| 1635 | if (MAX_WEAPON_NOT_HIT_PARENT_TIME + obj->creation_time < Gametime) |
| 1636 | obj->mtype.phys_info.flags &= (~PF_NO_COLLIDE_PARENT); |
| 1637 | |
| 1638 | if ((obj->mtype.phys_info.flags & PF_USES_THRUST) && (obj->ctype.laser_info.thrust_left >= 0.0)) { |
| 1639 | obj->ctype.laser_info.thrust_left -= Frametime; |
| 1640 | |
| 1641 | if ((obj->creation_time + 0.1f < Gametime) && (obj->mtype.phys_info.flags & PF_HOMING) && |
| 1642 | !(obj->mtype.phys_info.flags & PF_GUIDED)) { |
| 1643 | obj->ctype.laser_info.last_track_time = Gametime - HOMING_CHECK_VIS_INTERVAL; |
| 1644 | HomingDoFrame(obj); |
| 1645 | } |
| 1646 | |
| 1647 | if (obj->ctype.laser_info.thrust_left <= 0.0) { |
| 1648 | obj->mtype.phys_info.flags &= (~PF_USES_THRUST); |
| 1649 | vm_MakeZero(&obj->mtype.phys_info.thrust); |
| 1650 | vm_MakeZero(&obj->mtype.phys_info.rotthrust); |
| 1651 | |
| 1652 | obj->mtype.phys_info.drag = 0.005f; |
| 1653 | obj->mtype.phys_info.rotdrag = 0.005f; |
| 1654 | |
| 1655 | obj->mtype.phys_info.flags |= PF_GRAVITY; |
| 1656 | } |
| 1657 | } |
| 1658 | |
| 1659 | if ((Weapons[obj->id].flags & WF_SMOKE) && draw_effects) { |
| 1660 | if (Weapons[obj->id].flags & WF_PLANAR_SMOKE) { |
| 1661 | vector newpos = obj->pos - (obj->orient.fvec * (obj->size / 2)); |
| 1662 | int visnum = VisEffectCreate(VIS_FIREBALL, BILLBOARD_SMOKETRAIL_INDEX, obj->roomnum, &newpos); |
| 1663 | if (visnum >= 0) { |
| 1664 | vis_effect *vis = &VisEffects[visnum]; |
| 1665 | vis->custom_handle = Weapons[obj->id].smoke_handle; |
| 1666 | vis->lifeleft = 1.0; |
| 1667 | vis->lifetime = 1.0; |
| 1668 | |
| 1669 | vis->end_pos = obj->ctype.laser_info.last_smoke_pos; |
| 1670 | vis->billboard_info.width = 4; |
| 1671 | vis->lighting_color = GR_RGB16(Weapons[obj->id].lighting_info.red_light1 * 255.0, |
| 1672 | Weapons[obj->id].lighting_info.green_light1 * 255.0, |
| 1673 | Weapons[obj->id].lighting_info.blue_light1 * 255.0); |
| 1674 | obj->ctype.laser_info.last_smoke_pos = vis->pos; |
| 1675 | } |
| 1676 | } else { |
| 1677 | // Create blobby smoke |
| 1678 | // Create extras |
| 1679 | vector blobpos = obj->pos - (obj->orient.fvec * obj->size); |
| 1680 | |
| 1681 | float delta_time = Frametime; |
| 1682 | vector delta_vec = obj->mtype.phys_info.velocity * delta_time; |
| 1683 | |
| 1684 | float mag = vm_GetMagnitudeFast(&delta_vec); |
| 1685 | float extras = (mag * 4) + .5; |
| 1686 | int int_extras = extras + 1; |
| 1687 | |
| 1688 | int_extras = std::min(int_extras, 2); |
| 1689 | |
| 1690 | delta_vec /= int_extras; |
| 1691 | delta_time /= int_extras; |
| 1692 | |
| 1693 | vector new_blobpos = blobpos; |
| 1694 | |
| 1695 | for (int i = 0; i < int_extras; i++) { |
| 1696 | int visnum = CreateFireball(&new_blobpos, SMOKE_TRAIL_INDEX, obj->roomnum, VISUAL_FIREBALL); |
| 1697 | |
| 1698 | if (visnum >= 0) { |
| 1699 | vis_effect *vis = &VisEffects[visnum]; |
| 1700 | |
| 1701 | vis->custom_handle = Weapons[obj->id].smoke_handle; |
| 1702 | vis->lifeleft -= (i * delta_time); |
| 1703 | vis->creation_time -= (i * delta_time); |
| 1704 | |
| 1705 | if (Weapons[obj->id].flags & WF_REVERSE_SMOKE) |
| 1706 | vis->flags |= VF_REVERSE; |
| 1707 | } |
| 1708 | |
| 1709 | new_blobpos -= delta_vec; |
| 1710 | } |
| 1711 | } |
| 1712 | } |
| 1713 | |
| 1714 | if (Weapons[obj->id].particle_count > 0 && Weapons[obj->id].particle_handle != -1 && draw_effects) { |
| 1715 | vector pos = obj->pos - (obj->orient.fvec * obj->size); |
| 1716 | weapon *weap = &Weapons[obj->id]; |
| 1717 | float particle_interval = (1.0 / (float)weap->particle_count); |
| 1718 | |
| 1719 | if (Gametime - obj->ctype.laser_info.last_drop_time > particle_interval) { |
| 1720 | CreateRandomParticles(1, &pos, obj->roomnum, weap->particle_handle, weap->particle_size, weap->particle_life); |
| 1721 | obj->ctype.laser_info.last_drop_time = Gametime; |
| 1722 | } |
| 1723 | } |
| 1724 | |
| 1725 | if (Weapons[obj->id].flags & WF_RING) { |
| 1726 | float norm = ((Gametime - obj->creation_time) / obj->lifetime); |
| 1727 | obj->size = Weapons[obj->id].size + (norm * Weapons[obj->id].size * 8); |
| 1728 | } |
| 1729 | } |
| 1730 | |
| 1731 | bool WeaponCalcGun(vector *gun_point, vector *gun_normal, object *obj, int gun_num) { |
| 1732 | poly_model *pm; |
| 1733 | vector pnt; |
| 1734 | vector normal; |
| 1735 | matrix m; |
| 1736 | int mn; // submodel number |
| 1737 | float normalized_time[MAX_SUBOBJECTS]; |
| 1738 | bool f_good_gp = true; |
| 1739 | |
| 1740 | if (!(obj->flags & OF_POLYGON_OBJECT)) { |
| 1741 | // mprintf(0,"Object type %d is not a polyobj!\n",obj->type); |
| 1742 | |
| 1743 | if (gun_point) |
| 1744 | *gun_point = obj->pos; |
| 1745 | if (gun_normal) |
| 1746 | *gun_normal = obj->orient.fvec; |
| 1747 | |
| 1748 | return false; |
| 1749 | } |
| 1750 | |
| 1751 | pm = &Poly_models[obj->rtype.pobj_info.model_num]; |
| 1752 | |
| 1753 | if (pm->n_guns == 0) { |
| 1754 | mprintf(0, "WARNING: Object with no weapons is firing.\n", gun_num); |
| 1755 | |
| 1756 | if (gun_point) |
| 1757 | *gun_point = obj->pos; |
| 1758 | if (gun_normal) |
| 1759 | *gun_normal = obj->orient.fvec; |
| 1760 | |
| 1761 | return false; |
| 1762 | } |
| 1763 | |
| 1764 | SetNormalizedTimeObj(obj, normalized_time); |
| 1765 | SetModelAnglesAndPos(pm, normalized_time); |
| 1766 | |
| 1767 | if (gun_num < 0 || gun_num >= pm->n_guns) { |
| 1768 | mprintf(0, "WARNING: Bashing gun num %d to 0.\n", gun_num); |
| 1769 | if (gun_point) |
| 1770 | *gun_point = obj->pos; |
| 1771 | if (gun_normal) |
| 1772 | *gun_normal = obj->orient.fvec; |
| 1773 | return false; |
| 1774 | } |
| 1775 | |
| 1776 | pnt = pm->gun_slots[gun_num].pnt; |
| 1777 | normal = pm->gun_slots[gun_num].norm; |
| 1778 | mn = pm->gun_slots[gun_num].parent; |
| 1779 | |
| 1780 | // Instance up the tree for this gun |
| 1781 | while (mn != -1) { |
| 1782 | vector tpnt; |
| 1783 | |
| 1784 | vm_AnglesToMatrix(&m, pm->submodel[mn].angs.p, pm->submodel[mn].angs.h, pm->submodel[mn].angs.b); |
| 1785 | vm_TransposeMatrix(&m); |
| 1786 | |
| 1787 | if (gun_point) |
| 1788 | tpnt = pnt * m; |
| 1789 | |
| 1790 | if (gun_normal) |
| 1791 | normal = normal * m; |
| 1792 | |
| 1793 | if (gun_point) |
| 1794 | pnt = tpnt + pm->submodel[mn].offset + pm->submodel[mn].mod_pos; |
| 1795 | |
| 1796 | mn = pm->submodel[mn].parent; |
| 1797 | } |
| 1798 | |
| 1799 | m = obj->orient; |
| 1800 | vm_TransposeMatrix(&m); |
| 1801 | |
| 1802 | if (gun_point) |
| 1803 | *gun_point = pnt * m; |
| 1804 | if (gun_normal) |
| 1805 | *gun_normal = normal * m; |
| 1806 | |
| 1807 | if (gun_point) |
| 1808 | *gun_point += obj->pos; |
| 1809 | |
| 1810 | return f_good_gp; |
| 1811 | } |
| 1812 | |
| 1813 | #define MIN_FIRE_SPREAD 5000 |
| 1814 | #define MAX_FIRE_SPREAD 16768 // We vary by difficulty level!!!!!!!! Its the total fire cone (half each way) |
| 1815 | |
| 1816 | // Given an object and a weapon, fires a shot from that object |
| 1817 | int FireWeaponFromObject(object *obj, int weapon_num, int gun_num, bool f_force_forward, bool f_force_target) { |
| 1818 | ASSERT(Weapons[weapon_num].used); |
| 1819 | |
| 1820 | // Mass driver is hack |
| 1821 | static int mass_driver_id = -2; |
| 1822 | static int mass_driver_ring = -2; |
| 1823 | |
| 1824 | if (mass_driver_id == -2) { |
| 1825 | mass_driver_id = FindWeaponName("Mass Driver"); |
| 1826 | mass_driver_ring = FindTextureName("CloakRing.tga1"); |
| 1827 | } |
| 1828 | |
| 1829 | vector laser_pos, laser_dir; |
| 1830 | int objnum; |
| 1831 | |
| 1832 | if (gun_num == -1) { |
| 1833 | laser_pos = obj->pos; |
| 1834 | laser_dir = obj->orient.fvec; |
| 1835 | } else { |
| 1836 | // Find the initial position of the laser |
| 1837 | poly_model *pm = &Poly_models[obj->rtype.pobj_info.model_num]; |
| 1838 | // vector *pnt = &pm->gun_slots[gun_num].pnt; |
| 1839 | // vector gun_point; |
| 1840 | // matrix m; |
| 1841 | |
| 1842 | if (gun_num >= pm->n_guns) { |
| 1843 | // We don't have a gun point for this gun! |
| 1844 | mprintf(0, "Trying to fire from gun %d...we don't have that gun!\n", gun_num); |
| 1845 | laser_pos = obj->pos; |
| 1846 | laser_dir = obj->orient.fvec; |
| 1847 | } else { |
| 1848 | if (f_force_forward) { |
| 1849 | WeaponCalcGun(&laser_pos, NULL, obj, gun_num); |
| 1850 | laser_dir = obj->orient.fvec; |
| 1851 | } else if (f_force_target && obj->ai_info && obj->ai_info->vec_to_target_perceived != Zero_vector) { |
| 1852 | WeaponCalcGun(&laser_pos, NULL, obj, gun_num); |
| 1853 | laser_dir = obj->ai_info->vec_to_target_perceived; |
| 1854 | } else { |
| 1855 | WeaponCalcGun(&laser_pos, &laser_dir, obj, gun_num); |
| 1856 | } |
| 1857 | } |
| 1858 | } |
| 1859 | |
| 1860 | if ((obj->control_type == CT_AI) && (obj->ai_info->fire_spread || (Diff_ai_min_fire_spread[DIFF_LEVEL]))) { |
| 1861 | matrix rot_mat; |
| 1862 | angle p, h, b; |
| 1863 | |
| 1864 | float diff_scale = DIFF_LEVEL / (MAX_DIFFICULTY_LEVELS - 1); |
| 1865 | float fs = (MAX_FIRE_SPREAD * (1.0f - diff_scale)) + (MIN_FIRE_SPREAD * diff_scale); |
| 1866 | |
| 1867 | int16_t fire_spread = obj->ai_info->fire_spread * fs; |
| 1868 | |
| 1869 | if ((obj->control_type == CT_AI && ((obj->ai_info->flags & AIF_TEAM_MASK) != AIF_TEAM_REBEL)) && |
| 1870 | fire_spread < Diff_ai_min_fire_spread[DIFF_LEVEL] * fs) { |
| 1871 | fire_spread = Diff_ai_min_fire_spread[DIFF_LEVEL] * fs; |
| 1872 | } |
| 1873 | |
| 1874 | int16_t half_fire_spread = fire_spread >> 1; |
| 1875 | |
| 1876 | if (fire_spread > 0) { |
| 1877 | p = (ps_rand() % fire_spread) - half_fire_spread; |
| 1878 | h = (ps_rand() % fire_spread) - half_fire_spread; |
| 1879 | b = (ps_rand() % fire_spread) - half_fire_spread; |
| 1880 | |
| 1881 | vm_AnglesToMatrix(&rot_mat, p, h, b); |
| 1882 | |
| 1883 | laser_dir = laser_dir * rot_mat; |
| 1884 | } |
| 1885 | } |
| 1886 | |
| 1887 | objnum = CreateAndFireWeapon(&laser_pos, &laser_dir, obj, weapon_num); |
| 1888 | if (Game_mode & GM_MULTI) { |
| 1889 | if (Netgame.local_role == LR_SERVER) { |
| 1890 | if (obj->control_type == CT_AI) { |
| 1891 | MultiSendRobotFireWeapon(obj->handle & HANDLE_OBJNUM_MASK, &laser_pos, &laser_dir, (uint16_t)weapon_num); |
| 1892 | } |
| 1893 | } |
| 1894 | } |
| 1895 | if (Demo_flags == DF_RECORDING) { |
| 1896 | DemoWriteWeaponFire(obj->handle & HANDLE_OBJNUM_MASK, &laser_pos, &laser_dir, (uint16_t)weapon_num, objnum, |
| 1897 | gun_num); |
| 1898 | } |
| 1899 | |
| 1900 | // bail out of their was an error creating this weapon object |
| 1901 | if (objnum == -1) |
| 1902 | return -1; |
| 1903 | |
| 1904 | // Record gun number |
| 1905 | Objects[objnum].ctype.laser_info.src_gun_num = gun_num; |
| 1906 | |
| 1907 | AINotify(&Objects[objnum], AIN_OBJ_FIRED, obj); |
| 1908 | |
| 1909 | if (obj->type == OBJ_PLAYER && obj == Player_object) { |
| 1910 | // Check if missile camera enabled, and if this weapon allows it |
| 1911 | if ((Missile_camera_window != -1) && (Weapons[weapon_num].flags & WF_ENABLE_CAMERA)) { |
| 1912 | |
| 1913 | // Check if there's already a missile camera |
| 1914 | object *viewer_obj = ObjGet(GetSmallViewer(Missile_camera_window)); |
| 1915 | if ((viewer_obj == NULL) || (viewer_obj->type != OBJ_WEAPON)) |
| 1916 | CreateSmallView(Missile_camera_window, Objects[objnum].handle, SVF_POPUP + SVF_BIGGER); |
| 1917 | } |
| 1918 | } |
| 1919 | |
| 1920 | // if (Weapons[weapon_num].sounds[WSI_FIRE]!=SOUND_NONE_INDEX) |
| 1921 | // Sound_system.Play3dSound(Weapons[weapon_num].sounds[WSI_FIRE], &Objects[objnum]); |
| 1922 | |
| 1923 | if (Weapons[weapon_num].sounds[WSI_FLYING] != SOUND_NONE_INDEX) |
| 1924 | Sound_system.Play3dSound(Weapons[weapon_num].sounds[WSI_FLYING], SND_PRIORITY_HIGHEST, &Objects[objnum]); |
| 1925 | |
| 1926 | // Do a muzzle flash from this gun |
| 1927 | if (Weapons[weapon_num].flags & WF_MUZZLE) { |
| 1928 | int visnum; |
| 1929 | vector newpos; |
| 1930 | |
| 1931 | if (obj == &Objects[Players[Player_num].objnum]) { |
| 1932 | newpos = laser_pos + (laser_dir); |
| 1933 | visnum = VisEffectCreate(VIS_FIREBALL, MUZZLE_FLASH_INDEX, obj->roomnum, &newpos); |
| 1934 | } else { |
| 1935 | newpos = laser_pos + (laser_dir / 2); |
| 1936 | visnum = VisEffectCreate(VIS_FIREBALL, MUZZLE_FLASH_INDEX, obj->roomnum, &newpos); |
| 1937 | } |
| 1938 | |
| 1939 | // Make this guy live for a very short time |
| 1940 | if (visnum >= 0) { |
| 1941 | vis_effect *vis = &VisEffects[visnum]; |
| 1942 | |
| 1943 | vis->lifetime = .08f; |
| 1944 | vis->lifeleft = .08f; |
| 1945 | vis->size = 1.0f; |
| 1946 | |
| 1947 | vis->movement_type = MT_PHYSICS; |
| 1948 | vis->velocity = obj->mtype.phys_info.velocity; |
| 1949 | |
| 1950 | // Make some smoke! |
| 1951 | visnum = VisEffectCreate(VIS_FIREBALL, MED_SMOKE_INDEX, obj->roomnum, &newpos); |
| 1952 | if (visnum >= 0) { |
| 1953 | vis_effect *vis = &VisEffects[visnum]; |
| 1954 | |
| 1955 | vis->lifetime = .3f; |
| 1956 | vis->lifeleft = .3f; |
| 1957 | |
| 1958 | vis->movement_type = MT_PHYSICS; |
| 1959 | vis->velocity = obj->mtype.phys_info.velocity; |
| 1960 | vis->velocity.y += 10; |
| 1961 | } |
| 1962 | } |
| 1963 | } |
| 1964 | |
| 1965 | // Check for mass driver |
| 1966 | if (weapon_num == mass_driver_id) { |
| 1967 | // Create a fire trail for this weapon |
| 1968 | // find out where this weapon hits |
| 1969 | fvi_query fq; |
| 1970 | fvi_info hit_data; |
| 1971 | |
| 1972 | vector dest_vec = laser_pos + (laser_dir * 5000); |
| 1973 | |
| 1974 | fq.p0 = &laser_pos; |
| 1975 | fq.startroom = obj->roomnum; |
| 1976 | fq.p1 = &dest_vec; |
| 1977 | fq.rad = 0; |
| 1978 | fq.thisobjnum = -1; |
| 1979 | fq.ignore_obj_list = NULL; |
| 1980 | fq.flags = FQ_CHECK_OBJS | FQ_IGNORE_POWERUPS | FQ_IGNORE_WEAPONS; |
| 1981 | |
| 1982 | fvi_FindIntersection(&fq, &hit_data); |
| 1983 | |
| 1984 | float mag = vm_VectorDistanceQuick(&hit_data.hit_pnt, &obj->pos); |
| 1985 | |
| 1986 | int visnum; |
| 1987 | |
| 1988 | if (obj == NULL || obj->type != OBJ_BUILDING || stricmp(Object_info[obj->id].name, "FinalbossLITTLETIT") != 0) |
| 1989 | visnum = VisEffectCreate(VIS_FIREBALL, MASSDRIVER_EFFECT_INDEX, obj->roomnum, &laser_pos); |
| 1990 | else |
| 1991 | visnum = VisEffectCreate(VIS_FIREBALL, MERCBOSS_MASSDRIVER_EFFECT_INDEX, obj->roomnum, &laser_pos); |
| 1992 | |
| 1993 | if (visnum >= 0) { |
| 1994 | vis_effect *vis = &VisEffects[visnum]; |
| 1995 | vis->custom_handle = mass_driver_ring; |
| 1996 | vis->lifeleft = 1.5; |
| 1997 | vis->lifetime = 1.5; |
| 1998 | |
| 1999 | vis->end_pos = hit_data.hit_pnt; |
| 2000 | vis->billboard_info.width = 1; |
| 2001 | if (obj == NULL || obj->type != OBJ_BUILDING || stricmp(Object_info[obj->id].name, "FinalbossLITTLETIT") != 0) |
| 2002 | vis->lighting_color = GR_RGB16(100, 100, 170); |
| 2003 | else |
| 2004 | vis->lighting_color = GR_RGB16(240, 10, 10); |
| 2005 | vis->flags |= VF_LINK_TO_VIEWER | VF_EXPAND; |
| 2006 | vis->size = mag; |
| 2007 | } |
| 2008 | } |
| 2009 | |
| 2010 | if (Game_mode & GM_MULTI) { |
| 2011 | DLLInfo.me_handle = Objects[objnum].handle; |
| 2012 | DLLInfo.it_handle = obj->handle; |
| 2013 | CallGameDLL(EVT_WEAPONFIRED, &DLLInfo); |
| 2014 | } |
| 2015 | |
| 2016 | return objnum; |
| 2017 | } |
| 2018 | |
| 2019 | // This define determines how wide this arc is |
| 2020 | #define ELECTRICAL_WIDTH .3f |
| 2021 | #define ELECTRICAL_ALPHA .2 |
| 2022 | |
| 2023 | #include "args.h" |
| 2024 | |
| 2025 | // Draws a lighting like chain of electricity |
| 2026 | void DrawElectricalWeapon(object *obj) { |
| 2027 | int i, t; |
| 2028 | vector center_vecs[20]; |
| 2029 | vector arc_vec; |
| 2030 | g3Point arc_points[100]; |
| 2031 | vector dest_vector, src_vector, line_norm; |
| 2032 | float line_mag; |
| 2033 | g3Point *pntlist[20]; |
| 2034 | vector dir; |
| 2035 | object *parent_obj = ObjGet(obj->parent_handle); |
| 2036 | float view_dp = 0; |
| 2037 | |
| 2038 | if (!parent_obj) |
| 2039 | return; |
| 2040 | |
| 2041 | if (parent_obj->type == OBJ_PLAYER) { |
| 2042 | if (Players[parent_obj->id].flags & (PLAYER_FLAGS_DYING | PLAYER_FLAGS_DEAD)) |
| 2043 | return; |
| 2044 | } else { |
| 2045 | if (parent_obj->flags & OF_DYING) |
| 2046 | return; |
| 2047 | } |
| 2048 | |
| 2049 | int bm_handle = GetWeaponFireImage(obj->id, 0); |
| 2050 | ASSERT(bm_handle >= 0); |
| 2051 | |
| 2052 | WeaponCalcGun(&src_vector, &dir, parent_obj, obj->ctype.laser_info.src_gun_num); |
| 2053 | |
| 2054 | if (obj->ctype.laser_info.track_handle == OBJECT_HANDLE_NONE || ObjGet(obj->ctype.laser_info.track_handle) == NULL) { |
| 2055 | dest_vector = src_vector + (obj->orient.fvec * 50); |
| 2056 | } else { |
| 2057 | object *obj_to_track = ObjGet(obj->ctype.laser_info.track_handle); |
| 2058 | dest_vector = obj_to_track->pos; |
| 2059 | if (obj_to_track == Player_object) { |
| 2060 | vector subvec = src_vector - dest_vector; |
| 2061 | float mag = vm_GetMagnitudeFast(&subvec); |
| 2062 | |
| 2063 | if (mag < .5) { |
| 2064 | obj->lifeleft = 0; |
| 2065 | return; |
| 2066 | } |
| 2067 | |
| 2068 | subvec /= mag; |
| 2069 | |
| 2070 | dest_vector += subvec; // This prevents rendering errors |
| 2071 | } |
| 2072 | } |
| 2073 | |
| 2074 | // Find out if it is o.k. to create a weapon here. |
| 2075 | fvi_query fq; |
| 2076 | fvi_info hit_data; |
| 2077 | int fate; |
| 2078 | |
| 2079 | fq.p0 = &src_vector; |
| 2080 | fq.startroom = obj->roomnum; |
| 2081 | fq.p1 = &dest_vector; |
| 2082 | fq.rad = 0; |
| 2083 | fq.thisobjnum = -1; |
| 2084 | fq.ignore_obj_list = NULL; |
| 2085 | fq.flags = 0; // what about trans walls??? |
| 2086 | |
| 2087 | fate = fvi_FindIntersection(&fq, &hit_data); |
| 2088 | |
| 2089 | if (fate == HIT_WALL || fate == HIT_TERRAIN) { |
| 2090 | dest_vector = hit_data.hit_pnt; |
| 2091 | CreateRandomSparks((ps_rand() % 4), &dest_vector, obj->roomnum, COOL_SPARK_INDEX); |
| 2092 | } |
| 2093 | |
| 2094 | line_norm = dest_vector - src_vector; |
| 2095 | line_mag = vm_GetMagnitudeFast(&line_norm); |
| 2096 | |
| 2097 | if (line_mag < .5) { |
| 2098 | obj->lifeleft = 0; |
| 2099 | return; |
| 2100 | } |
| 2101 | |
| 2102 | line_norm /= line_mag; |
| 2103 | |
| 2104 | // Get view dot product for drawing blobs |
| 2105 | |
| 2106 | if (parent_obj != Viewer_object) { |
| 2107 | vector temp_line_norm = -line_norm; |
| 2108 | view_dp = Viewer_object->orient.fvec * temp_line_norm; |
| 2109 | } |
| 2110 | |
| 2111 | matrix mat; |
| 2112 | |
| 2113 | vm_VectorToMatrix(&mat, &line_norm, NULL, NULL); |
| 2114 | |
| 2115 | // Create the center points of our chain |
| 2116 | int num_segments = 20; |
| 2117 | int circle_pieces = 5; |
| 2118 | |
| 2119 | if (!Detail_settings.Weapon_coronas_enabled) |
| 2120 | num_segments = 10; |
| 2121 | |
| 2122 | float line_scalar = (line_mag / (float)num_segments); |
| 2123 | line_norm *= line_scalar; |
| 2124 | |
| 2125 | // Get the src and dest vectors in view space so we know how to compute z |
| 2126 | |
| 2127 | center_vecs[0] = src_vector; // Set first one equal to our origin |
| 2128 | center_vecs[num_segments - 1] = dest_vector; |
| 2129 | vector from = src_vector; |
| 2130 | int cur_sin = FrameCount * 5000; |
| 2131 | |
| 2132 | for (i = 1; i < num_segments - 1; i++, from += line_norm, cur_sin += 8000) { |
| 2133 | center_vecs[i] = from; |
| 2134 | center_vecs[i] += (mat.uvec * FixSin(cur_sin % 65536) * .4f); |
| 2135 | center_vecs[i] += (mat.rvec * FixCos(cur_sin % 65536) * .4f); |
| 2136 | } |
| 2137 | |
| 2138 | // Now that we have our center points, create a tube |
| 2139 | for (i = 0; i < num_segments; i++) { |
| 2140 | float size = ELECTRICAL_WIDTH; |
| 2141 | |
| 2142 | for (t = 0; t < circle_pieces; t++) { |
| 2143 | float norm = (float)t / (float)circle_pieces; |
| 2144 | arc_vec = center_vecs[i]; |
| 2145 | |
| 2146 | if (i != num_segments - 1) { |
| 2147 | arc_vec += (obj->orient.uvec * size * FixSin(norm * 65536)); |
| 2148 | arc_vec -= (obj->orient.rvec * size * FixCos(norm * 65536)); |
| 2149 | } |
| 2150 | |
| 2151 | g3_RotatePoint(&arc_points[i * circle_pieces + t], &arc_vec); |
| 2152 | arc_points[i * circle_pieces + t].p3_flags |= PF_UV; |
| 2153 | } |
| 2154 | } |
| 2155 | |
| 2156 | rend_SetAlphaType(AT_SATURATE_TEXTURE); |
| 2157 | rend_SetAlphaValue(ELECTRICAL_ALPHA * 255); |
| 2158 | rend_SetOverlayType(OT_NONE); |
| 2159 | rend_SetLighting(LS_NONE); |
| 2160 | rend_SetZBufferWriteMask(0); |
| 2161 | |
| 2162 | float float_time = (Gametime * 300); |
| 2163 | int int_time = float_time; |
| 2164 | int_time %= 100; |
| 2165 | float vchange = int_time / 100.0; |
| 2166 | |
| 2167 | // Check for no sat flag |
| 2168 | bool sat = true; |
| 2169 | if (FindArg("-nosatomega")) |
| 2170 | sat = false; |
| 2171 | |
| 2172 | // Form our vectors into points and draw! |
| 2173 | for (t = (num_segments - 1) * circle_pieces, i = num_segments - 1; i >= 1; i--, t -= circle_pieces) { |
| 2174 | rend_SetTextureType(TT_LINEAR); |
| 2175 | rend_SetAlphaType(sat ? AT_SATURATE_TEXTURE : AT_CONSTANT); |
| 2176 | rend_SetZBufferWriteMask(0); |
| 2177 | rend_SetLighting(LS_NONE); |
| 2178 | rend_SetAlphaValue(ELECTRICAL_ALPHA * 255); |
| 2179 | |
| 2180 | for (int k = 0; k < circle_pieces; k++) { |
| 2181 | int next = (k + 1) % circle_pieces; |
| 2182 | |
| 2183 | arc_points[t + k].p3_u = 0; |
| 2184 | arc_points[t + k].p3_v = 1; |
| 2185 | |
| 2186 | arc_points[t + k - circle_pieces].p3_u = 0; |
| 2187 | arc_points[t + k - circle_pieces].p3_v = 0; |
| 2188 | |
| 2189 | arc_points[t + next - circle_pieces].p3_u = 1; |
| 2190 | arc_points[t + next - circle_pieces].p3_v = 1; |
| 2191 | |
| 2192 | arc_points[t + next].p3_u = 1; |
| 2193 | arc_points[t + next].p3_v = 0; |
| 2194 | |
| 2195 | pntlist[0] = &arc_points[t + k]; |
| 2196 | pntlist[1] = &arc_points[t + k - circle_pieces]; |
| 2197 | pntlist[2] = &arc_points[t + next - circle_pieces]; |
| 2198 | pntlist[3] = &arc_points[t + next]; |
| 2199 | |
| 2200 | g3_DrawPoly(4, pntlist, bm_handle); |
| 2201 | } |
| 2202 | |
| 2203 | if (i != num_segments - 1) { |
| 2204 | vector subvec = center_vecs[i + 1] - center_vecs[i]; |
| 2205 | subvec = center_vecs[i] + (subvec * vchange); |
| 2206 | |
| 2207 | if (parent_obj == Viewer_object) { |
| 2208 | DrawColoredDisk(&subvec, .2f, .5f, 1, .6f, 0, ELECTRICAL_WIDTH * 4, sat, 2); |
| 2209 | } else { |
| 2210 | DrawColoredDisk(&subvec, .2f, .5f, 1, .6f * fabs(view_dp), 0, ELECTRICAL_WIDTH * 4, sat, 2); |
| 2211 | } |
| 2212 | } |
| 2213 | } |
| 2214 | |
| 2215 | rend_SetZBufferWriteMask(1); |
| 2216 | |
| 2217 | // Kill it! |
| 2218 | obj->lifeleft = 0; |
| 2219 | } |
| 2220 | |
| 2221 | #define FUSION_RAMP_TIME 3.0 |
| 2222 | #define FUSION_DAMAGE_SOUND_INTERVAL .5 |
| 2223 | |
| 2224 | float Last_fusion_damage_time = 0; |
| 2225 | |
| 2226 | // Does that crazy fusion effect, including damaging/shaking your ship |
| 2227 | void DoFusionEffect(object *objp, int weapon_type) { |
| 2228 | float norm; |
| 2229 | int move = 0; |
| 2230 | |
| 2231 | ASSERT(objp->type == OBJ_PLAYER); |
| 2232 | ASSERT((weapon_type == PW_PRIMARY) || (weapon_type == PW_SECONDARY)); |
| 2233 | |
| 2234 | norm = (Players[objp->id].weapon[weapon_type].firing_time / FUSION_RAMP_TIME); |
| 2235 | |
| 2236 | if (norm > .1) { |
| 2237 | float over = norm; |
| 2238 | |
| 2239 | if (over > 1.0) |
| 2240 | over = 1.0; |
| 2241 | |
| 2242 | over = (over - .1) / .9; |
| 2243 | |
| 2244 | move = (ps_rand() % 5) - 2; |
| 2245 | |
| 2246 | objp->mtype.phys_info.velocity += (objp->orient.rvec) * ((float)move * over * Frametime * 175.0); |
| 2247 | |
| 2248 | move = (ps_rand() % 5) - 2; |
| 2249 | |
| 2250 | objp->mtype.phys_info.velocity += (objp->orient.uvec) * ((float)move * over * Frametime * 175.0); |
| 2251 | } |
| 2252 | |
| 2253 | if (norm > 1.0) { |
| 2254 | norm = 1.0; |
| 2255 | |
| 2256 | if ((!(Game_mode & GM_MULTI)) || Netgame.local_role == LR_SERVER) { |
| 2257 | if ((Gametime - Last_fusion_damage_time) < FUSION_DAMAGE_SOUND_INTERVAL) { |
| 2258 | ApplyDamageToPlayer(objp, objp, PD_ENERGY_WEAPON, (.125 * abs(move)), 0, 255, 0); |
| 2259 | } else { |
| 2260 | ApplyDamageToPlayer(objp, objp, PD_ENERGY_WEAPON, (.125 * abs(move))); |
| 2261 | Last_fusion_damage_time = Gametime; |
| 2262 | } |
| 2263 | } else { |
| 2264 | Multi_requested_damage_type = PD_ENERGY_WEAPON; |
| 2265 | Multi_requested_damage_amount += (.125 * abs(move)); |
| 2266 | } |
| 2267 | } |
| 2268 | |
| 2269 | float vals[4]; |
| 2270 | vals[0] = 1.0; |
| 2271 | vals[1] = 0.0; |
| 2272 | vals[2] = 1.0; |
| 2273 | vals[3] = .25 * norm; |
| 2274 | |
| 2275 | CreateNewEvent(RENDER_EVENT, FUSION_EFFECT, 0, &vals, sizeof(float) * 4, DrawAlphaEvent); |
| 2276 | } |
| 2277 | |
| 2278 | // Do the spray effect |
| 2279 | void DoSprayEffect(object *obj, otype_wb_info *static_wb, uint8_t wb_index) { |
| 2280 | vector laser_pos, laser_dir; |
| 2281 | int cur_m_bit; |
| 2282 | |
| 2283 | ASSERT(!(obj->flags & OF_DYING)); |
| 2284 | |
| 2285 | poly_model *pm = &Poly_models[obj->rtype.pobj_info.model_num]; |
| 2286 | |
| 2287 | // Go through each gun point |
| 2288 | for (cur_m_bit = 0; cur_m_bit < pm->poly_wb[0].num_gps; cur_m_bit++) { |
| 2289 | // Figure out out if this weapon fires from this gunpoint |
| 2290 | if (static_wb->gp_fire_masks[obj->dynamic_wb[wb_index].cur_firing_mask] & (0x01 << cur_m_bit)) { |
| 2291 | int weapon_num = static_wb->gp_weapon_index[cur_m_bit]; |
| 2292 | |
| 2293 | WeaponCalcGun(&laser_pos, &laser_dir, obj, pm->poly_wb[0].gp_index[cur_m_bit]); |
| 2294 | int visnum = VisEffectCreate(VIS_FIREBALL, SPRAY_INDEX, obj->roomnum, &laser_pos); |
| 2295 | |
| 2296 | if (visnum < 0) |
| 2297 | return; |
| 2298 | |
| 2299 | vis_effect *vis = &VisEffects[visnum]; |
| 2300 | |
| 2301 | // Set the initial velocity |
| 2302 | vm_ScaleVector(&vis->velocity, &laser_dir, Weapons[weapon_num].phys_info.velocity.z); |
| 2303 | |
| 2304 | // Set initial velocity to that of the firing object |
| 2305 | if (Weapons[weapon_num].phys_info.flags & PF_USES_PARENT_VELOCITY) { |
| 2306 | float fdot = (obj->mtype.phys_info.velocity * obj->orient.fvec); |
| 2307 | vector fvel; |
| 2308 | |
| 2309 | if (fdot > 0.0) |
| 2310 | fvel = obj->orient.fvec * fdot; |
| 2311 | else |
| 2312 | fvel = Zero_vector; |
| 2313 | |
| 2314 | vector rvel = 0.1f * obj->orient.rvec * (obj->mtype.phys_info.velocity * obj->orient.rvec); |
| 2315 | vector uvel = 0.1f * obj->orient.uvec * (obj->mtype.phys_info.velocity * obj->orient.uvec); |
| 2316 | |
| 2317 | vis->velocity += fvel + rvel + uvel; |
| 2318 | } |
| 2319 | |
| 2320 | vis->movement_type = MT_PHYSICS; |
| 2321 | vis->custom_handle = Weapons[weapon_num].fire_image_handle; |
| 2322 | vis->drag = Weapons[weapon_num].phys_info.drag; |
| 2323 | vis->phys_flags = Weapons[weapon_num].phys_info.flags; |
| 2324 | vis->mass = Weapons[weapon_num].phys_info.mass; |
| 2325 | vis->size = Weapons[weapon_num].size; |
| 2326 | vis->lifetime = Weapons[weapon_num].life_time; |
| 2327 | vis->lifeleft = vis->lifetime; |
| 2328 | |
| 2329 | // Now create extras so that there are no gaps |
| 2330 | |
| 2331 | if (obj != Viewer_object) { |
| 2332 | // Find hit point so we know when to stop |
| 2333 | float life_scalar = 1.0; |
| 2334 | fvi_query fq; |
| 2335 | fvi_info hit_data; |
| 2336 | int fate; |
| 2337 | vector dest_vector = laser_pos + (vis->velocity * vis->lifetime); |
| 2338 | |
| 2339 | fq.p0 = &laser_pos; |
| 2340 | fq.startroom = obj->roomnum; |
| 2341 | fq.p1 = &dest_vector; |
| 2342 | fq.rad = vis->size; |
| 2343 | fq.thisobjnum = -1; |
| 2344 | fq.ignore_obj_list = NULL; |
| 2345 | fq.flags = FQ_CHECK_OBJS | FQ_IGNORE_NON_LIGHTMAP_OBJECTS; |
| 2346 | |
| 2347 | fate = fvi_FindIntersection(&fq, &hit_data); |
| 2348 | |
| 2349 | if (fate != HIT_NONE) { |
| 2350 | vector subvec = hit_data.hit_pnt - laser_pos; |
| 2351 | vis->lifetime = vm_GetMagnitudeFast(&subvec) / vm_GetMagnitudeFast(&vis->velocity); |
| 2352 | life_scalar = vis->lifetime / vis->lifeleft; |
| 2353 | vis->lifeleft = vis->lifetime; |
| 2354 | } |
| 2355 | |
| 2356 | float velmag = vm_GetMagnitudeFast(&vis->velocity); |
| 2357 | vector velnorm = vis->velocity / velmag; |
| 2358 | float len = Frametime * velmag; |
| 2359 | float fextras = len * 2; |
| 2360 | float fps = 1.0 / Frametime; |
| 2361 | |
| 2362 | int extras = fextras; |
| 2363 | |
| 2364 | extras = std::min(extras, 8); |
| 2365 | |
| 2366 | for (int t = 0; t < extras; t++) { |
| 2367 | |
| 2368 | vector newpos = vis->pos + (((velnorm * len) / extras) * (t + 1)); |
| 2369 | |
| 2370 | int extranum = VisEffectCreate(VIS_FIREBALL, SPRAY_INDEX, obj->roomnum, &newpos); |
| 2371 | if (extranum >= 0) { |
| 2372 | vis_effect *extravis = &VisEffects[extranum]; |
| 2373 | extravis->mass = vis->mass; |
| 2374 | extravis->drag = vis->drag; |
| 2375 | extravis->velocity = vis->velocity; |
| 2376 | extravis->size = vis->size; |
| 2377 | extravis->phys_flags = vis->phys_flags; |
| 2378 | extravis->movement_type = MT_PHYSICS; |
| 2379 | extravis->custom_handle = vis->custom_handle; |
| 2380 | extravis->lifetime = vis->lifetime; |
| 2381 | |
| 2382 | float life_adjust = ((Frametime / (float)extras) * (t + 1)); |
| 2383 | |
| 2384 | extravis->lifeleft = Frametime * (fps / 2); |
| 2385 | extravis->lifeleft *= life_scalar; |
| 2386 | life_adjust *= life_scalar; |
| 2387 | |
| 2388 | if (extravis->lifeleft > 0) |
| 2389 | extravis->creation_time = vis->creation_time - life_adjust; |
| 2390 | else { |
| 2391 | VisEffectDelete(extranum); |
| 2392 | } |
| 2393 | } |
| 2394 | } |
| 2395 | } else { |
| 2396 | // Find hit point so we know when to stop |
| 2397 | fvi_query fq; |
| 2398 | fvi_info hit_data; |
| 2399 | int fate; |
| 2400 | vector dest_vector = laser_pos + (vis->velocity * vis->lifetime); |
| 2401 | |
| 2402 | fq.p0 = &laser_pos; |
| 2403 | fq.startroom = obj->roomnum; |
| 2404 | fq.p1 = &dest_vector; |
| 2405 | fq.rad = vis->size; |
| 2406 | fq.thisobjnum = -1; |
| 2407 | fq.ignore_obj_list = NULL; |
| 2408 | fq.flags = FQ_CHECK_OBJS | FQ_IGNORE_NON_LIGHTMAP_OBJECTS; |
| 2409 | |
| 2410 | fate = fvi_FindIntersection(&fq, &hit_data); |
| 2411 | |
| 2412 | if (fate != HIT_NONE) { |
| 2413 | vector subvec = hit_data.hit_pnt - laser_pos; |
| 2414 | vis->lifetime = vm_GetMagnitudeFast(&subvec) / vm_GetMagnitudeFast(&vis->velocity); |
| 2415 | vis->lifeleft = vis->lifetime; |
| 2416 | } |
| 2417 | } |
| 2418 | } |
| 2419 | } |
| 2420 | } |
| 2421 | |
| 2422 | // Draws a streamer behind a weapon |
| 2423 | void DrawWeaponStreamer(object *obj) { |
| 2424 | float time_live = Gametime - obj->creation_time; |
| 2425 | float len; |
| 2426 | float norm_time = time_live / obj->lifetime; |
| 2427 | |
| 2428 | if (norm_time >= 1) |
| 2429 | norm_time = .99999f; // don't go over! |
| 2430 | |
| 2431 | // Get length |
| 2432 | object *parent_obj = ObjGet(obj->parent_handle); |
| 2433 | |
| 2434 | if (!parent_obj) |
| 2435 | return; |
| 2436 | |
| 2437 | len = vm_VectorDistance(&parent_obj->pos, &obj->pos); |
| 2438 | |
| 2439 | rend_SetAlphaType(AT_VERTEX); |
| 2440 | rend_SetTextureType(TT_FLAT); |
| 2441 | rend_SetLighting(LS_GOURAUD); |
| 2442 | rend_SetColorModel(CM_RGB); |
| 2443 | |
| 2444 | vector vecs[2]; |
| 2445 | g3Point pnts[2]; |
| 2446 | int i; |
| 2447 | |
| 2448 | vecs[0] = obj->pos; |
| 2449 | vecs[1] = obj->pos - (obj->orient.fvec * len); |
| 2450 | |
| 2451 | for (i = 0; i < 2; i++) { |
| 2452 | g3_RotatePoint(&pnts[i], &vecs[i]); |
| 2453 | pnts[i].p3_flags |= PF_RGBA; |
| 2454 | pnts[i].p3_r = Weapons[obj->id].lighting_info.red_light1; |
| 2455 | pnts[i].p3_g = Weapons[obj->id].lighting_info.green_light1; |
| 2456 | pnts[i].p3_b = Weapons[obj->id].lighting_info.blue_light1; |
| 2457 | } |
| 2458 | |
| 2459 | pnts[0].p3_a = (1.0 - norm_time) * .3f; |
| 2460 | pnts[1].p3_a = 0; |
| 2461 | |
| 2462 | g3_DrawSpecialLine(&pnts[0], &pnts[1]); |
| 2463 | } |
| 2464 | |
| 2465 | void DrawBlobbyWeaponRing(object *obj) { |
| 2466 | vector vecs[30]; |
| 2467 | float lifenorm = (obj->lifetime - obj->lifeleft) / obj->lifetime; |
| 2468 | int i; |
| 2469 | |
| 2470 | int bm_handle; |
| 2471 | int num_segments = 20; |
| 2472 | |
| 2473 | int ring_increment = 65536 / num_segments; |
| 2474 | int ring_angle = 0; |
| 2475 | |
| 2476 | if (lifenorm >= 1.0) |
| 2477 | lifenorm = .999f; |
| 2478 | |
| 2479 | if (Weapons[obj->id].flags & WF_IMAGE_BITMAP) |
| 2480 | bm_handle = GetWeaponFireImage(obj->id, 0); |
| 2481 | else { |
| 2482 | vclip *vc = &GameVClips[Weapons[obj->id].fire_image_handle]; |
| 2483 | int int_frame = vc->num_frames * lifenorm; |
| 2484 | bm_handle = vc->frames[int_frame]; |
| 2485 | } |
| 2486 | |
| 2487 | rend_SetLighting(LS_NONE); |
| 2488 | rend_SetTextureType(TT_LINEAR); |
| 2489 | rend_SetAlphaType(AT_CONSTANT_TEXTURE); |
| 2490 | rend_SetAlphaValue((1.0 - lifenorm) * 255.0); |
| 2491 | |
| 2492 | // Now draw a ring of blobs |
| 2493 | ring_angle = 0; |
| 2494 | float blob_size = (obj->size / 4); |
| 2495 | |
| 2496 | for (i = 0; i < num_segments; i++, ring_angle += ring_increment) { |
| 2497 | float ring_sin = FixSin(ring_angle); |
| 2498 | float ring_cos = FixCos(ring_angle); |
| 2499 | |
| 2500 | vecs[i] = obj->orient.rvec * (ring_cos * obj->size); |
| 2501 | vecs[i] += obj->orient.uvec * (ring_sin * obj->size); |
| 2502 | vecs[i] += obj->pos; |
| 2503 | |
| 2504 | g3_DrawRotatedBitmap(&vecs[i], ring_angle, blob_size, (blob_size * bm_h(bm_handle, 0)) / bm_w(bm_handle, 0), |
| 2505 | bm_handle); |
| 2506 | } |
| 2507 | } |
| 2508 | |
| 2509 | void DrawPolygonalWeaponRing(object *obj) { |
| 2510 | vector inner_vecs[30], outer_vecs[30]; |
| 2511 | g3Point inner_points[30], outer_points[30]; |
| 2512 | float lifenorm = (obj->lifetime - obj->lifeleft) / obj->lifetime; |
| 2513 | int i; |
| 2514 | g3Point *pntlist[4]; |
| 2515 | float inner_size = (obj->size * .8); |
| 2516 | int objnum = obj - Objects; |
| 2517 | int odd = objnum % 2; |
| 2518 | |
| 2519 | int num_segments = 20; |
| 2520 | |
| 2521 | int ring_increment = 65536 / num_segments; |
| 2522 | int ring_angle = 0; |
| 2523 | |
| 2524 | if (lifenorm > 1.0) |
| 2525 | lifenorm = 1.0; |
| 2526 | |
| 2527 | rend_SetTextureType(TT_FLAT); |
| 2528 | rend_SetColorModel(CM_RGB); |
| 2529 | rend_SetLighting(LS_GOURAUD); |
| 2530 | rend_SetAlphaType(AT_SATURATE_VERTEX); |
| 2531 | |
| 2532 | for (i = 0; i < num_segments; i++, ring_angle += ring_increment) { |
| 2533 | float ring_sin = FixSin(ring_angle); |
| 2534 | float ring_cos = FixCos(ring_angle); |
| 2535 | |
| 2536 | inner_vecs[i] = obj->orient.rvec * (ring_cos * inner_size); |
| 2537 | inner_vecs[i] += obj->orient.uvec * (ring_sin * inner_size); |
| 2538 | inner_vecs[i] += obj->pos; |
| 2539 | |
| 2540 | outer_vecs[i] = obj->orient.rvec * (ring_cos * obj->size); |
| 2541 | outer_vecs[i] += obj->orient.uvec * (ring_sin * obj->size); |
| 2542 | outer_vecs[i] += obj->pos; |
| 2543 | |
| 2544 | g3_RotatePoint(&inner_points[i], &inner_vecs[i]); |
| 2545 | g3_RotatePoint(&outer_points[i], &outer_vecs[i]); |
| 2546 | |
| 2547 | outer_points[i].p3_flags |= PF_RGBA | PF_UV; |
| 2548 | inner_points[i].p3_flags |= PF_RGBA | PF_UV; |
| 2549 | |
| 2550 | outer_points[i].p3_a = (1.0 - lifenorm) * .3; |
| 2551 | inner_points[i].p3_a = (1.0 - lifenorm) * .1; |
| 2552 | |
| 2553 | outer_points[i].p3_r = Weapons[obj->id].lighting_info.red_light1; |
| 2554 | outer_points[i].p3_g = Weapons[obj->id].lighting_info.green_light1; |
| 2555 | outer_points[i].p3_b = Weapons[obj->id].lighting_info.blue_light1; |
| 2556 | |
| 2557 | inner_points[i].p3_r = Weapons[obj->id].lighting_info.red_light1; |
| 2558 | inner_points[i].p3_g = Weapons[obj->id].lighting_info.green_light1; |
| 2559 | inner_points[i].p3_b = Weapons[obj->id].lighting_info.blue_light1; |
| 2560 | } |
| 2561 | |
| 2562 | for (i = 0; i < num_segments; i++) { |
| 2563 | if (i % 2 && !odd) |
| 2564 | continue; |
| 2565 | if ((i % 2 == 0) && odd) |
| 2566 | continue; |
| 2567 | |
| 2568 | int next = (i + 1) % num_segments; |
| 2569 | |
| 2570 | pntlist[0] = &outer_points[i]; |
| 2571 | pntlist[1] = &outer_points[next]; |
| 2572 | pntlist[2] = &inner_points[next]; |
| 2573 | pntlist[3] = &inner_points[i]; |
| 2574 | |
| 2575 | g3_DrawPoly(4, pntlist, 0); |
| 2576 | } |
| 2577 | } |
| 2578 | |
| 2579 | // Draws a ring for the weapon |
| 2580 | void DrawWeaponRing(object *obj) { |
| 2581 | if ((Weapons[obj->id].flags & WF_IMAGE_BITMAP) || (Weapons[obj->id].flags & WF_IMAGE_VCLIP)) { |
| 2582 | DrawBlobbyWeaponRing(obj); |
| 2583 | return; |
| 2584 | } else |
| 2585 | DrawPolygonalWeaponRing(obj); |
| 2586 | } |
| 2587 | |
| 2588 | // Draws a weapon |
| 2589 | void DrawWeaponObject(object *obj) { |
| 2590 | ASSERT(obj->type == OBJ_WEAPON || obj->type == OBJ_POWERUP); |
| 2591 | ASSERT(Weapons[obj->id].used > 0); |
| 2592 | |
| 2593 | // Don't draw if spray |
| 2594 | if (!(Weapons[obj->id].flags & WF_INVISIBLE)) { |
| 2595 | if (Weapons[obj->id].flags & WF_ELECTRICAL) { |
| 2596 | DrawElectricalWeapon(obj); |
| 2597 | } else if ((Weapons[obj->id].flags & WF_IMAGE_BITMAP) || (Weapons[obj->id].flags & WF_IMAGE_VCLIP)) { |
| 2598 | int bm_handle; |
| 2599 | int objnum = obj - Objects; |
| 2600 | float rot_temp = Weapons[obj->id].phys_info.rotvel.z / 65536.0; |
| 2601 | int int_game = Gametime / rot_temp; |
| 2602 | float diff = Gametime - (int_game * rot_temp); |
| 2603 | int rot_angle = diff * 65536; |
| 2604 | |
| 2605 | if (Weapons[obj->id].flags & WF_NO_ROTATE) |
| 2606 | rot_angle = (objnum * 1000) % 65536; |
| 2607 | |
| 2608 | bm_handle = GetWeaponFireImage(obj->id, 0); |
| 2609 | ASSERT(bm_handle >= 0); |
| 2610 | |
| 2611 | if (Weapons[obj->id].flags & WF_SATURATE) |
| 2612 | rend_SetAlphaType(AT_SATURATE_TEXTURE); |
| 2613 | else |
| 2614 | rend_SetAlphaType(AT_CONSTANT + AT_TEXTURE); |
| 2615 | |
| 2616 | rend_SetAlphaValue(Weapons[obj->id].alpha * 255); |
| 2617 | rend_SetOverlayType(OT_NONE); |
| 2618 | rend_SetLighting(LS_NONE); |
| 2619 | |
| 2620 | if (Weapons[obj->id].flags & WF_PLANAR) { |
| 2621 | vector norm = obj->mtype.phys_info.velocity; |
| 2622 | vm_NormalizeVectorFast(&norm); |
| 2623 | g3_DrawPlanarRotatedBitmap(&obj->pos, &norm, rot_angle, obj->size, |
| 2624 | (obj->size * bm_h(bm_handle, 0)) / bm_w(bm_handle, 0), bm_handle); |
| 2625 | } else |
| 2626 | g3_DrawRotatedBitmap(&obj->pos, rot_angle, obj->size, (obj->size * bm_h(bm_handle, 0)) / bm_w(bm_handle, 0), |
| 2627 | bm_handle); |
| 2628 | } else { |
| 2629 | |
| 2630 | polymodel_effect pe = {0}; |
| 2631 | int use_effect = 0; |
| 2632 | |
| 2633 | if (obj->type == OBJ_WEAPON && !Detail_settings.Weapon_coronas_enabled) { |
| 2634 | pe.type |= PEF_NO_GLOWS; |
| 2635 | use_effect = 1; |
| 2636 | } |
| 2637 | |
| 2638 | if (use_effect) |
| 2639 | SetPolymodelEffect(&pe); |
| 2640 | |
| 2641 | DrawPolygonModel(&obj->pos, &obj->orient, obj->rtype.pobj_info.model_num, NULL, 0, 1.0, 1.0, 1.0, 0xFFFFFFFF, |
| 2642 | use_effect); |
| 2643 | } |
| 2644 | } |
| 2645 | |
| 2646 | if (Weapons[obj->id].flags & WF_STREAMER) { |
| 2647 | DrawWeaponStreamer(obj); |
| 2648 | } |
| 2649 | |
| 2650 | if (Weapons[obj->id].flags & WF_RING) { |
| 2651 | DrawWeaponRing(obj); |
| 2652 | } |
| 2653 | } |
| 2654 | |
| 2655 | // Stops any on/off weapons that are firing |
| 2656 | void StopOnOffWeapon(object *obj) { |
| 2657 | // mprintf(0,"Stopping on/off weapon!\n"); |
| 2658 | obj->weapon_fire_flags &= ~WFF_ON_OFF; |
| 2659 | |
| 2660 | if (Demo_flags == DF_RECORDING) { |
| 2661 | DemoWriteObjWeapFireFlagChanged(OBJNUM(obj)); |
| 2662 | } |
| 2663 | } |
| 2664 | |
| 2665 | // Starts an on/off weapon firing |
| 2666 | void StartOnOffWeapon(object *obj, uint8_t wb_index) { |
| 2667 | // mprintf(0,"Starting on/off weapon!\n"); |
| 2668 | obj->weapon_fire_flags |= WFF_ON_OFF; |
| 2669 | |
| 2670 | dynamic_wb_info *p_dwb = &obj->dynamic_wb[wb_index]; |
| 2671 | p_dwb->cur_firing_mask = 0; |
| 2672 | |
| 2673 | if (Demo_flags == DF_RECORDING) { |
| 2674 | DemoWriteObjWeapFireFlagChanged(OBJNUM(obj)); |
| 2675 | } |
| 2676 | } |
| 2677 | |
| 2678 | float Zoom_fov_time = 0; |
| 2679 | |
| 2680 | #define ZOOM_STAY_TIME .25 |
| 2681 | #define ZOOM_FOV_TARGET 18 |
| 2682 | |
| 2683 | void DoZoomStay() { |
| 2684 | if (Zoom_fov_time > 0) { |
| 2685 | Render_FOV = ZOOM_FOV_TARGET; |
| 2686 | Zoom_fov_time -= Frametime; |
| 2687 | if (Zoom_fov_time < 0) { |
| 2688 | Zoom_fov_time = 0; |
| 2689 | Players[Player_num].flags &= ~PLAYER_FLAGS_ZOOMED; |
| 2690 | Render_FOV = D3_DEFAULT_FOV; |
| 2691 | } |
| 2692 | } |
| 2693 | } |
| 2694 | |
| 2695 | // Zooms in for this weapon |
| 2696 | void DoZoomEffect(player_weapon *pw, uint8_t clear) { |
| 2697 | if (pw->firing_time < .5) { |
| 2698 | Players[Player_num].turn_scalar = 1.0; |
| 2699 | Render_FOV = D3_DEFAULT_FOV; |
| 2700 | |
| 2701 | if (!clear) |
| 2702 | DoZoomStay(); |
| 2703 | return; |
| 2704 | } |
| 2705 | |
| 2706 | Players[Player_num].turn_scalar = .3f; |
| 2707 | |
| 2708 | if (pw->firing_time > 1.0) { |
| 2709 | // We are fully zoomed in |
| 2710 | |
| 2711 | Players[Player_num].flags |= PLAYER_FLAGS_ZOOMED; |
| 2712 | Render_FOV = ZOOM_FOV_TARGET; |
| 2713 | Zoom_fov_time = ZOOM_STAY_TIME; |
| 2714 | |
| 2715 | // See if we hit anything |
| 2716 | // Cast a ray to see what we've hit |
| 2717 | Players[Player_num].flags &= ~PLAYER_FLAGS_BULLSEYE; |
| 2718 | object *obj = &Objects[Players[Player_num].objnum]; |
| 2719 | int fate; // Collision type for response code |
| 2720 | fvi_info hit_info; // Hit information |
| 2721 | fvi_query fq; // Movement query |
| 2722 | vector dest = obj->pos + (obj->orient.fvec * 5000.0); |
| 2723 | |
| 2724 | fq.p0 = &obj->pos; |
| 2725 | fq.startroom = obj->roomnum; |
| 2726 | fq.p1 = &dest; |
| 2727 | fq.rad = .0001f; |
| 2728 | fq.thisobjnum = Objects - obj; |
| 2729 | fq.ignore_obj_list = NULL; |
| 2730 | fq.flags = FQ_CHECK_OBJS | FQ_IGNORE_POWERUPS | FQ_IGNORE_WEAPONS; |
| 2731 | |
| 2732 | fate = fvi_FindIntersection(&fq, &hit_info); |
| 2733 | |
| 2734 | Players[Player_num].zoom_distance = vm_VectorDistance(&obj->pos, &hit_info.hit_pnt); |
| 2735 | |
| 2736 | if (fate == HIT_SPHERE_2_POLY_OBJECT || fate == HIT_OBJECT) { |
| 2737 | object *hit_obj = &Objects[hit_info.hit_object[0]]; |
| 2738 | if (hit_obj->type == OBJ_ROBOT || hit_obj->type == OBJ_PLAYER || |
| 2739 | (hit_obj->type == OBJ_BUILDING && hit_obj->ai_info)) |
| 2740 | Players[Player_num].flags |= PLAYER_FLAGS_BULLSEYE; |
| 2741 | } |
| 2742 | return; |
| 2743 | } |
| 2744 | |
| 2745 | // calculate zoom effect |
| 2746 | float norm = (pw->firing_time - .5) * 2; |
| 2747 | |
| 2748 | Render_FOV = (ZOOM_FOV_TARGET * norm) + ((1.0 - norm) * D3_DEFAULT_FOV); |
| 2749 | |
| 2750 | return; |
| 2751 | } |
| 2752 | |
| 2753 | // Called when a player dies or switches weapons to clear out any active weapon stuff |
| 2754 | void ClearPlayerFiring(object *objp, int weapon_type) { |
| 2755 | // Check parms |
| 2756 | ASSERT(objp->type == OBJ_PLAYER); |
| 2757 | // ASSERT(objp->id == Player_num); |
| 2758 | |
| 2759 | // Set up various vars |
| 2760 | player *player = &Players[objp->id]; |
| 2761 | player_weapon *pw = &player->weapon[weapon_type]; |
| 2762 | |
| 2763 | // Clear firing flags |
| 2764 | if (objp->weapon_fire_flags & WFF_ON_OFF) |
| 2765 | StopOnOffWeapon(objp); |
| 2766 | |
| 2767 | // Clear firing time |
| 2768 | pw->firing_time = 0.0; |
| 2769 | objp->weapon_fire_flags = 0; |
| 2770 | if (Demo_flags == DF_RECORDING) { |
| 2771 | DemoWriteObjWeapFireFlagChanged(OBJNUM(objp)); |
| 2772 | } |
| 2773 | |
| 2774 | // Clear zoom if there is one |
| 2775 | if (objp->id == Player_num) { |
| 2776 | player_weapon *pw = &player->weapon[weapon_type]; |
| 2777 | int weapon_battery_index = pw->index; |
| 2778 | ship *ship = &Ships[player->ship_index]; |
| 2779 | |
| 2780 | if (ship->fire_flags[weapon_battery_index] & SFF_ZOOM) { |
| 2781 | DoZoomEffect(pw, 1); |
| 2782 | Players[Player_num].flags &= ~PLAYER_FLAGS_ZOOMED; |
| 2783 | Zoom_fov_time = 0; |
| 2784 | } |
| 2785 | } |
| 2786 | |
| 2787 | // Stop firing sound if one playing |
| 2788 | if (pw->sound_handle != -1) { |
| 2789 | Sound_system.StopSoundImmediate(pw->sound_handle); |
| 2790 | pw->sound_handle = -1; |
| 2791 | } |
| 2792 | } |
| 2793 | |
| 2794 | // Stops weapon sound & visual effects |
| 2795 | void StopWeapon(object *obj, player_weapon *pw, otype_wb_info *wb) { |
| 2796 | // Stop any on/off weapons |
| 2797 | if (obj->weapon_fire_flags & WFF_ON_OFF) |
| 2798 | StopOnOffWeapon(obj); |
| 2799 | |
| 2800 | // Stop spray weapons |
| 2801 | if (wb->flags & WBF_SPRAY) |
| 2802 | obj->weapon_fire_flags &= ~WFF_SPRAY; |
| 2803 | |
| 2804 | // Stop firing sound if one playing |
| 2805 | if (pw && pw->sound_handle != -1) { |
| 2806 | Sound_system.StopSoundImmediate(pw->sound_handle); |
| 2807 | pw->sound_handle = -1; |
| 2808 | } |
| 2809 | |
| 2810 | // Clear firing time |
| 2811 | if (pw) { |
| 2812 | pw->firing_time = 0.0; |
| 2813 | } |
| 2814 | if (Demo_flags == DF_RECORDING) { |
| 2815 | DemoWriteObjWeapFireFlagChanged(OBJNUM(obj)); |
| 2816 | } |
| 2817 | } |
| 2818 | |
| 2819 | // Does weapon battery stuff for the permissable network architecture |
| 2820 | void DoPermissableWeaponMask(int weapon_battery_index) { |
| 2821 | player *player = &Players[Player_num]; |
| 2822 | object *objp = &Objects[player->objnum]; |
| 2823 | ship *ship = &Ships[player->ship_index]; |
| 2824 | otype_wb_info *wb = &ship->static_wb[weapon_battery_index]; |
| 2825 | dynamic_wb_info *p_dwb = &objp->dynamic_wb[weapon_battery_index]; |
| 2826 | |
| 2827 | player->last_fire_weapon_time = Gametime; |
| 2828 | |
| 2829 | p_dwb->cur_firing_mask++; |
| 2830 | p_dwb->last_fire_time = Gametime; |
| 2831 | |
| 2832 | if (p_dwb->cur_firing_mask >= wb->num_masks) |
| 2833 | p_dwb->cur_firing_mask = 0; |
| 2834 | } |
| 2835 | |
| 2836 | // Fires a weapon from our player. Won't fire if ammo/energy requirements aren't met. |
| 2837 | // Parameters: weapon_type - either PW_PRIMARY or PW_SECONDARY |
| 2838 | void FireWeaponFromPlayer(object *objp, int weapon_type, int down_count, bool down_state, float down_time) { |
| 2839 | // Check parms |
| 2840 | ASSERT(objp->type == OBJ_PLAYER); |
| 2841 | // ASSERT(objp->id == Player_num); |
| 2842 | ASSERT((weapon_type == PW_PRIMARY) || (weapon_type == PW_SECONDARY)); |
| 2843 | |
| 2844 | // Set up various vars |
| 2845 | player *player = &Players[objp->id]; |
| 2846 | player_weapon *pw = &player->weapon[weapon_type]; |
| 2847 | int weapon_battery_index = pw->index; |
| 2848 | ship *ship = &Ships[player->ship_index]; |
| 2849 | otype_wb_info *wb = &ship->static_wb[weapon_battery_index]; |
| 2850 | int fire_on_release = (ship->fire_flags[weapon_battery_index] & (SFF_FUSION | SFF_ZOOM)); |
| 2851 | bool can_fire_now = WBIsBatteryReady(objp, wb, weapon_battery_index); |
| 2852 | dynamic_wb_info *p_dwb = &objp->dynamic_wb[weapon_battery_index]; |
| 2853 | float ammo_scalar = 1.0; |
| 2854 | |
| 2855 | if (p_dwb->flags & DWBF_QUAD) |
| 2856 | ammo_scalar = 2.0; |
| 2857 | |
| 2858 | // Don't allow down_time to be zero if we have a down count |
| 2859 | if (down_count && (down_time == 0.0)) |
| 2860 | down_time = 1.0f / 100.0f; |
| 2861 | |
| 2862 | // Check to see if we can release a guided |
| 2863 | if (down_count && down_time != 0.0 && Players[objp->id].guided_obj != NULL && weapon_type == PW_SECONDARY && |
| 2864 | can_fire_now) { |
| 2865 | ReleaseGuidedMissile(objp->id); |
| 2866 | p_dwb->last_fire_time = Gametime; |
| 2867 | return; |
| 2868 | } |
| 2869 | |
| 2870 | // Check to see if we can release a user timeout weapon |
| 2871 | if (down_count && down_time != 0.0 && Players[objp->id].user_timeout_obj != NULL && weapon_type == PW_SECONDARY && |
| 2872 | can_fire_now) { |
| 2873 | if (Game_mode & GM_MULTI) |
| 2874 | MultiSendReleaseTimeoutMissile(); |
| 2875 | |
| 2876 | ReleaseUserTimeoutMissile(objp->id); |
| 2877 | p_dwb->last_fire_time = Gametime; |
| 2878 | return; |
| 2879 | } |
| 2880 | |
| 2881 | // Check for weapon stopped firing |
| 2882 | if ((down_count == 0) && (down_time == 0)) { |
| 2883 | if (ship->fire_flags[weapon_battery_index] & SFF_ZOOM) |
| 2884 | DoZoomEffect(pw, 0); |
| 2885 | |
| 2886 | // Abort if we weren't firing last frame either |
| 2887 | if (pw->firing_time == 0.0) |
| 2888 | return; |
| 2889 | |
| 2890 | // Check for fire-on-release weapon |
| 2891 | if (fire_on_release) { |
| 2892 | if (can_fire_now) { |
| 2893 | float scalar = 1.0; |
| 2894 | |
| 2895 | // Ready? |
| 2896 | if (ship->fire_flags[weapon_battery_index] & SFF_FUSION) { |
| 2897 | scalar = 1.0 + ((pw->firing_time / FUSION_RAMP_TIME) * 3.0); |
| 2898 | } |
| 2899 | |
| 2900 | if ((Game_mode & GM_MULTI) && (Netgame.flags & NF_PERMISSABLE)) { |
| 2901 | MultiSendRequestToFire(weapon_battery_index, p_dwb->cur_firing_mask, scalar); |
| 2902 | DoPermissableWeaponMask(weapon_battery_index); |
| 2903 | } else |
| 2904 | WBFireBattery(objp, wb, 0, weapon_battery_index, scalar); |
| 2905 | |
| 2906 | player->energy -= wb->energy_usage * ammo_scalar; |
| 2907 | if (player->energy < 0) |
| 2908 | player->energy = 0; |
| 2909 | |
| 2910 | if (player->weapon_ammo[weapon_battery_index] < (wb->ammo_usage * ammo_scalar)) |
| 2911 | player->weapon_ammo[weapon_battery_index] = 0; |
| 2912 | else |
| 2913 | player->weapon_ammo[weapon_battery_index] -= (wb->ammo_usage * ammo_scalar); |
| 2914 | |
| 2915 | player->num_discharges_level++; |
| 2916 | |
| 2917 | if (ship->fire_flags[weapon_battery_index] & SFF_ZOOM) { |
| 2918 | AddToShakeMagnitude(ship->phys_info.mass * 2); |
| 2919 | } |
| 2920 | } |
| 2921 | } |
| 2922 | |
| 2923 | // Play cut-off sound if one (but not if in permissable game) |
| 2924 | if (!(Game_mode & GM_MULTI) || !(Netgame.flags & NF_PERMISSABLE)) { |
| 2925 | int cutoff_sound = ship->firing_release_sound[weapon_battery_index]; |
| 2926 | if (cutoff_sound != -1) |
| 2927 | Sound_system.Play2dSound(cutoff_sound, SND_PRIORITY_HIGHEST); |
| 2928 | } |
| 2929 | |
| 2930 | // Stop the weapon sound & visual effects |
| 2931 | if (weapon_type == PW_PRIMARY) |
| 2932 | StopWeapon(objp, pw, wb); |
| 2933 | |
| 2934 | // We're done |
| 2935 | return; |
| 2936 | } |
| 2937 | |
| 2938 | // Check for adequate energy |
| 2939 | if ((wb->energy_usage * ammo_scalar) && (player->energy <= 0)) { |
| 2940 | AddHUDMessage(TXT_WPNNONRG); |
| 2941 | if (weapon_type == PW_PRIMARY) |
| 2942 | StopWeapon(objp, pw, wb); |
| 2943 | AutoSelectWeapon(weapon_type); |
| 2944 | return; |
| 2945 | } |
| 2946 | |
| 2947 | // Check for adequate ammo |
| 2948 | if ((wb->ammo_usage * ammo_scalar) && (player->weapon_ammo[weapon_battery_index] <= 0)) { |
| 2949 | if (weapon_type == PW_PRIMARY) |
| 2950 | AddHUDMessage(TXT_WPNNOAMMO); |
| 2951 | else |
| 2952 | AddHUDMessage(TXT_WPNNOPROJ); |
| 2953 | |
| 2954 | if (weapon_type == PW_PRIMARY) |
| 2955 | StopWeapon(objp, pw, wb); |
| 2956 | AutoSelectWeapon(weapon_type); |
| 2957 | return; |
| 2958 | } |
| 2959 | |
| 2960 | // Check for adequate ammo for secondaries... |
| 2961 | if (weapon_battery_index >= 10 && (wb->ammo_usage * ammo_scalar > player->weapon_ammo[weapon_battery_index])) { |
| 2962 | if (weapon_type == PW_PRIMARY) |
| 2963 | AddHUDMessage(TXT_WPNNOAMMO); |
| 2964 | else |
| 2965 | AddHUDMessage(TXT_WPNNOPROJ); |
| 2966 | |
| 2967 | if (weapon_type == PW_PRIMARY) |
| 2968 | StopWeapon(objp, pw, wb); |
| 2969 | AutoSelectWeapon(weapon_type); |
| 2970 | return; |
| 2971 | } |
| 2972 | |
| 2973 | if (!can_fire_now) |
| 2974 | return; |
| 2975 | |
| 2976 | // If continous sound weapon, start the sound if wasn't firing last frame |
| 2977 | int firing_sound = ship->firing_sound[weapon_battery_index]; |
| 2978 | |
| 2979 | if (can_fire_now && (firing_sound != -1) && (pw->firing_time == 0.0)) |
| 2980 | pw->sound_handle = Sound_system.Play2dSound(firing_sound, SND_PRIORITY_HIGHEST); |
| 2981 | |
| 2982 | // Set spray flag if spray weapon |
| 2983 | if (wb->flags & WBF_SPRAY) |
| 2984 | objp->weapon_fire_flags |= WFF_SPRAY; |
| 2985 | |
| 2986 | if (ship->fire_flags[weapon_battery_index] & SFF_ZOOM) |
| 2987 | DoZoomEffect(pw, 0); |
| 2988 | |
| 2989 | // Do fusion effect if fusion weapon |
| 2990 | if (can_fire_now && ship->fire_flags[weapon_battery_index] & SFF_FUSION) |
| 2991 | DoFusionEffect(objp, weapon_type); |
| 2992 | |
| 2993 | // Start any on/off weapons |
| 2994 | if ((wb->flags & WBF_ON_OFF) && !(objp->weapon_fire_flags & WFF_ON_OFF)) |
| 2995 | StartOnOffWeapon(objp, weapon_battery_index); |
| 2996 | |
| 2997 | // If not a fire-on-release weapon, then fire if ready |
| 2998 | if (!fire_on_release && can_fire_now) { |
| 2999 | |
| 3000 | if ((Game_mode & GM_MULTI) && (Netgame.flags & NF_PERMISSABLE)) { |
| 3001 | MultiSendRequestToFire(weapon_battery_index, p_dwb->cur_firing_mask); |
| 3002 | DoPermissableWeaponMask(weapon_battery_index); |
| 3003 | } else |
| 3004 | WBFireBattery(objp, wb, 0, weapon_battery_index); |
| 3005 | |
| 3006 | // If on/off weapon, scale energy by framerate based on "reference" rate of 20 fps. |
| 3007 | if (wb->flags & WBF_ON_OFF) |
| 3008 | player->energy -= (wb->energy_usage * ammo_scalar * Frametime / (1.0 / 20.0)); |
| 3009 | else |
| 3010 | player->energy -= (wb->energy_usage * ammo_scalar); |
| 3011 | if (player->energy < 0) |
| 3012 | player->energy = 0; |
| 3013 | |
| 3014 | if (player->weapon_ammo[weapon_battery_index] < (wb->ammo_usage * ammo_scalar)) |
| 3015 | player->weapon_ammo[weapon_battery_index] = 0; |
| 3016 | else |
| 3017 | player->weapon_ammo[weapon_battery_index] -= (wb->ammo_usage * ammo_scalar); |
| 3018 | |
| 3019 | player->num_discharges_level++; |
| 3020 | } |
| 3021 | |
| 3022 | // Update the firing time |
| 3023 | pw->firing_time += down_time; |
| 3024 | if (Demo_flags == DF_RECORDING) { |
| 3025 | DemoWriteObjWeapFireFlagChanged(OBJNUM(objp)); |
| 3026 | } |
| 3027 | } |
| 3028 | |
| 3029 | // Fires a flare from our player. |
| 3030 | // It might make sense to combine this with FireWeaponFromPlayer(), or maybe not |
| 3031 | void FireFlareFromPlayer(object *objp) { |
| 3032 | // Check parms |
| 3033 | ASSERT(objp->type == OBJ_PLAYER); |
| 3034 | // ASSERT(objp->id == Player_num || objp->control_type == CT_SOAR); |
| 3035 | |
| 3036 | // Set up various vars |
| 3037 | int weapon_battery_index = FLARE_INDEX; |
| 3038 | ship *ship = &Ships[Players[objp->id].ship_index]; |
| 3039 | otype_wb_info *wb = &ship->static_wb[weapon_battery_index]; |
| 3040 | player *player = &Players[objp->id]; |
| 3041 | dynamic_wb_info *p_dwb = &objp->dynamic_wb[weapon_battery_index]; |
| 3042 | |
| 3043 | if (player->energy < wb->energy_usage) { |
| 3044 | AddHUDMessage(TXT_WPNFLARENONRG); |
| 3045 | return; |
| 3046 | } |
| 3047 | |
| 3048 | if (WBIsBatteryReady(Player_object, wb, weapon_battery_index)) { |
| 3049 | if ((Game_mode & GM_MULTI) && (Netgame.flags & NF_PERMISSABLE)) { |
| 3050 | MultiSendRequestToFire(weapon_battery_index, p_dwb->cur_firing_mask); |
| 3051 | DoPermissableWeaponMask(weapon_battery_index); |
| 3052 | } else |
| 3053 | WBFireBattery(Player_object, wb, 0, weapon_battery_index); |
| 3054 | |
| 3055 | player->energy -= wb->energy_usage; |
| 3056 | if (player->energy < 0) |
| 3057 | player->energy = 0; |
| 3058 | |
| 3059 | // Samir & I think that firing a flare should not count as discharge, even though |
| 3060 | // it would allow people push up their kill effiency by killing things with flares. -MT, 10/29/97 |
| 3061 | // Players[Player_num].num_discharges_level++; |
| 3062 | } |
| 3063 | } |
| 3064 | |
| 3065 | // Plays the animation that accompanies a weapon death |
| 3066 | void DoWeaponExploded(object *obj, vector *norm, vector *collision_point, object *hit_object) { |
| 3067 | weapon *w = &Weapons[obj->id]; |
| 3068 | light_info *li = &w->lighting_info; |
| 3069 | vector col_point, normal; |
| 3070 | |
| 3071 | if (w->flags & WF_ELECTRICAL) |
| 3072 | return; |
| 3073 | |
| 3074 | MakeShockwave(obj, obj->parent_handle); |
| 3075 | |
| 3076 | if (collision_point == NULL || !(Weapons[obj->id].flags & WF_PLANAR_BLAST)) |
| 3077 | col_point = obj->pos; |
| 3078 | else |
| 3079 | col_point = *collision_point; |
| 3080 | |
| 3081 | if (norm == NULL) |
| 3082 | normal = obj->orient.fvec; |
| 3083 | else |
| 3084 | normal = *norm; |
| 3085 | |
| 3086 | if (Weapons[obj->id].flags & WF_GRAVITY_FIELD) |
| 3087 | CreateGravityField(&obj->pos, obj->roomnum, Weapons[obj->id].gravity_size, Weapons[obj->id].gravity_time, |
| 3088 | obj->parent_handle); |
| 3089 | |
| 3090 | if (hit_object == Viewer_object && !(Weapons[obj->id].flags & WF_MATTER_WEAPON)) |
| 3091 | return; // Don't draw if its viewer who is getting hit |
| 3092 | |
| 3093 | if (Weapons[obj->id].flags & WF_PLANAR_BLAST) { |
| 3094 | if (Weapons[obj->id].flags & WF_BLAST_RING) { |
| 3095 | // Create a planar ring |
| 3096 | int visnum = VisEffectCreate(VIS_FIREBALL, BLAST_RING_INDEX, obj->roomnum, &col_point); |
| 3097 | if (visnum >= 0) { |
| 3098 | vis_effect *vis = &VisEffects[visnum]; |
| 3099 | vis->size = Weapons[obj->id].explode_size; |
| 3100 | vis->lifetime = Weapons[obj->id].explode_time; |
| 3101 | vis->lifeleft = Weapons[obj->id].explode_time; |
| 3102 | vis->custom_handle = GetTextureBitmap(Weapons[obj->id].explode_image_handle, 0); |
| 3103 | vis->flags |= VF_PLANAR; |
| 3104 | vis->end_pos = normal; |
| 3105 | vis->lighting_color = |
| 3106 | OPAQUE_FLAG | GR_RGB16(li->red_light2 * 255, li->green_light2 * 255, li->blue_light2 * 255); |
| 3107 | } |
| 3108 | } else { |
| 3109 | // Create a planar explosion |
| 3110 | int visnum; |
| 3111 | |
| 3112 | if (Weapons[obj->id].explode_image_handle > 0) { |
| 3113 | visnum = VisEffectCreate(VIS_FIREBALL, CUSTOM_EXPLOSION_INDEX, obj->roomnum, &col_point); |
| 3114 | if (visnum >= 0) { |
| 3115 | vis_effect *vis = &VisEffects[visnum]; |
| 3116 | vis->size = Weapons[obj->id].explode_size; |
| 3117 | vis->lifetime = Weapons[obj->id].explode_time; |
| 3118 | vis->lifeleft = Weapons[obj->id].explode_time; |
| 3119 | vis->custom_handle = Weapons[obj->id].explode_image_handle; |
| 3120 | vis->lighting_color = |
| 3121 | OPAQUE_FLAG | GR_RGB16(li->red_light2 * 255, li->green_light2 * 255, li->blue_light2 * 255); |
| 3122 | } |
| 3123 | } else |
| 3124 | visnum = VisEffectCreate(VIS_FIREBALL, GetRandomSmallExplosion(), obj->roomnum, &col_point); |
| 3125 | |
| 3126 | if (visnum >= 0) { |
| 3127 | VisEffects[visnum].flags |= VF_PLANAR; |
| 3128 | VisEffects[visnum].end_pos = normal; |
| 3129 | |
| 3130 | if (Weapons[obj->id].flags & WF_EXPAND) |
| 3131 | VisEffects[visnum].flags |= VF_EXPAND; |
| 3132 | } |
| 3133 | } |
| 3134 | } else { |
| 3135 | if (Weapons[obj->id].flags & WF_BLAST_RING) { |
| 3136 | // Create a non-planar ring |
| 3137 | int visnum = VisEffectCreate(VIS_FIREBALL, BLAST_RING_INDEX, obj->roomnum, &col_point); |
| 3138 | if (visnum >= 0) { |
| 3139 | vis_effect *vis = &VisEffects[visnum]; |
| 3140 | vis->size = Weapons[obj->id].explode_size; |
| 3141 | vis->lifetime = Weapons[obj->id].explode_time; |
| 3142 | vis->lifeleft = Weapons[obj->id].explode_time; |
| 3143 | vis->custom_handle = GetTextureBitmap(Weapons[obj->id].explode_image_handle, 0); |
| 3144 | vis->lighting_color = |
| 3145 | OPAQUE_FLAG | GR_RGB16(li->red_light2 * 255, li->green_light2 * 255, li->blue_light2 * 255); |
| 3146 | } |
| 3147 | } else { |
| 3148 | // Create a normal "always facing you" explosion |
| 3149 | if (Weapons[obj->id].explode_image_handle > 0) { |
| 3150 | int visnum = VisEffectCreate(VIS_FIREBALL, CUSTOM_EXPLOSION_INDEX, obj->roomnum, &col_point); |
| 3151 | if (visnum >= 0) { |
| 3152 | vis_effect *vis = &VisEffects[visnum]; |
| 3153 | vis->size = Weapons[obj->id].explode_size; |
| 3154 | vis->lifetime = Weapons[obj->id].explode_time; |
| 3155 | vis->lifeleft = Weapons[obj->id].explode_time; |
| 3156 | vis->custom_handle = Weapons[obj->id].explode_image_handle; |
| 3157 | vis->lighting_color = |
| 3158 | OPAQUE_FLAG | GR_RGB16(li->red_light2 * 255, li->green_light2 * 255, li->blue_light2 * 255); |
| 3159 | |
| 3160 | if (Weapons[obj->id].flags & WF_EXPAND) |
| 3161 | VisEffects[visnum].flags |= VF_EXPAND; |
| 3162 | } |
| 3163 | } else |
| 3164 | VisEffectCreate(VIS_FIREBALL, GetRandomSmallExplosion(), obj->roomnum, &col_point); |
| 3165 | } |
| 3166 | } |
| 3167 | } |
| 3168 | |
| 3169 | // Creates chidren from a dying weapon |
| 3170 | void CreateTimeoutSpawnFromWeapon(object *obj) { |
| 3171 | int n = obj->id; |
| 3172 | |
| 3173 | ASSERT(Weapons[n].spawn_count > 0 && Weapons[n].spawn_handle >= 0); |
| 3174 | |
| 3175 | int num = Weapons[n].spawn_count; |
| 3176 | int spawn_index = Weapons[n].spawn_handle; |
| 3177 | vector pos; |
| 3178 | matrix orient; |
| 3179 | |
| 3180 | // See if we should spawn the alternate |
| 3181 | if (Weapons[n].alternate_spawn_handle >= 0 && Weapons[n].alternate_chance > 0) { |
| 3182 | if ((ps_rand() % 100) < Weapons[n].alternate_chance) |
| 3183 | spawn_index = Weapons[n].alternate_spawn_handle; |
| 3184 | } |
| 3185 | |
| 3186 | for (int i = 0; i < num; i++) { |
| 3187 | if (i == 0) // Make first one fire from the center of the ring |
| 3188 | { |
| 3189 | pos = obj->pos + (obj->orient.fvec * obj->size / 2); |
| 3190 | |
| 3191 | CreateAndFireWeapon(&pos, &obj->orient.fvec, obj, spawn_index); |
| 3192 | } else { |
| 3193 | matrix temp_mat; |
| 3194 | pos = obj->pos + (obj->orient.fvec * obj->size / 2); |
| 3195 | |
| 3196 | float norm = ((float)(i - 1)) / ((float)num - 1); |
| 3197 | |
| 3198 | float mysin = FixSin(norm * 65536); |
| 3199 | float mycos = FixCos(norm * 65536); |
| 3200 | |
| 3201 | int x_twist = mycos * 4096; |
| 3202 | int y_twist = mysin * 4096; |
| 3203 | |
| 3204 | vm_AnglesToMatrix(&temp_mat, x_twist, y_twist, 0); |
| 3205 | vm_TransposeMatrix(&temp_mat); |
| 3206 | |
| 3207 | orient = obj->orient * temp_mat; |
| 3208 | |
| 3209 | CreateAndFireWeapon(&pos, &orient.fvec, obj, spawn_index); |
| 3210 | } |
| 3211 | } |
| 3212 | } |
| 3213 | |
| 3214 | // Creates a robot as a countermeasure |
| 3215 | void CreateRobotSpawnFromWeapon(object *obj) { |
| 3216 | int index = obj->id; |
| 3217 | weapon *wp = &Weapons[index]; |
| 3218 | |
| 3219 | if ((Game_mode & GM_MULTI) && Netgame.local_role != LR_SERVER) |
| 3220 | return; // clients do not create robots without the servers permission |
| 3221 | |
| 3222 | if (wp->robot_spawn_handle == -1) { |
| 3223 | mprintf(0, "Trying to create an invalid robot spawn!\n"); |
| 3224 | return; |
| 3225 | } |
| 3226 | object *parent_obj = ObjGetUltimateParent(obj); |
| 3227 | |
| 3228 | int objnum = ObjCreate(OBJ_ROBOT, wp->robot_spawn_handle, obj->roomnum, &obj->pos, &obj->orient, parent_obj->handle); |
| 3229 | |
| 3230 | if (objnum < 0) |
| 3231 | return; |
| 3232 | |
| 3233 | if ((Game_mode & GM_MULTI) && Netgame.local_role == LR_SERVER) { |
| 3234 | MultiSendObject(&Objects[objnum], 0); |
| 3235 | } |
| 3236 | |
| 3237 | // Create the scripts for it |
| 3238 | InitObjectScripts(&Objects[objnum]); |
| 3239 | } |
| 3240 | |
| 3241 | // Returns a object to home on for spawned weapons |
| 3242 | object *FindSpawnHomingTarget(object *obj) { |
| 3243 | int i; |
| 3244 | float best_dist = MAX_HOMING_DIST / 2; |
| 3245 | int best_index = -1; |
| 3246 | object *weapon_parent = ObjGet(obj->parent_handle); |
| 3247 | |
| 3248 | for (i = 0; i <= Highest_object_index; i++) { |
| 3249 | if ((i != OBJNUM(weapon_parent)) && ((Objects[i].type == OBJ_ROBOT) || (Objects[i].type == OBJ_PLAYER) || |
| 3250 | (Objects[i].type == OBJ_BUILDING && Objects[i].ai_info))) { |
| 3251 | if (BOA_IsVisible(obj->roomnum, Objects[i].roomnum)) { |
| 3252 | vector to_target = Objects[i].pos - obj->pos; |
| 3253 | |
| 3254 | if (Objects[i].effect_info && Objects[i].effect_info->type_flags & EF_CLOAKED) |
| 3255 | continue; |
| 3256 | |
| 3257 | if (ObjGet(obj->parent_handle) && |
| 3258 | !AIObjEnemy(ObjGetUltimateParent(ObjGet(obj->parent_handle)), ObjGetUltimateParent(&Objects[i]))) |
| 3259 | continue; |
| 3260 | |
| 3261 | float dist_to_target = vm_NormalizeVector(&to_target) - obj->size - Objects[i].size; |
| 3262 | |
| 3263 | if (dist_to_target < best_dist) { |
| 3264 | fvi_query fq; |
| 3265 | fvi_info hit_info; |
| 3266 | |
| 3267 | fq.p0 = &obj->pos; |
| 3268 | fq.startroom = obj->roomnum; |
| 3269 | fq.p1 = &Objects[i].pos; |
| 3270 | fq.rad = 0.0f; |
| 3271 | fq.thisobjnum = OBJNUM(obj); |
| 3272 | fq.ignore_obj_list = NULL; |
| 3273 | fq.flags = FQ_TRANSPOINT | FQ_CHECK_OBJS | FQ_ONLY_DOOR_OBJ | FQ_NO_RELINK; |
| 3274 | |
| 3275 | fvi_FindIntersection(&fq, &hit_info); |
| 3276 | if (hit_info.hit_type[0] == HIT_NONE) { |
| 3277 | best_index = i; |
| 3278 | best_dist = dist_to_target; |
| 3279 | } |
| 3280 | } |
| 3281 | } |
| 3282 | } |
| 3283 | } |
| 3284 | if (best_index >= 0) |
| 3285 | return &Objects[best_index]; |
| 3286 | |
| 3287 | return NULL; |
| 3288 | } |
| 3289 | |
| 3290 | // Creates chidren from a dying weapon |
| 3291 | void CreateImpactSpawnFromWeapon(object *obj, vector *normal) { |
| 3292 | int n = obj->id; |
| 3293 | object *home_target = NULL; |
| 3294 | |
| 3295 | ASSERT(Weapons[n].spawn_count > 0 && Weapons[n].spawn_handle >= 0); |
| 3296 | |
| 3297 | int num = Weapons[n].spawn_count; |
| 3298 | int spawn_index = Weapons[n].spawn_handle; |
| 3299 | |
| 3300 | // See if we should spawn the alternate |
| 3301 | if (Weapons[n].alternate_spawn_handle >= 0 && Weapons[n].alternate_chance > 0) { |
| 3302 | if ((ps_rand() % 100) < Weapons[n].alternate_chance) |
| 3303 | spawn_index = Weapons[n].alternate_spawn_handle; |
| 3304 | } |
| 3305 | |
| 3306 | if (Game_mode & GM_MULTI) |
| 3307 | ps_srand(num); |
| 3308 | |
| 3309 | if (Weapons[n].flags & WF_HOMING_SPLIT) { |
| 3310 | home_target = FindSpawnHomingTarget(obj); |
| 3311 | } |
| 3312 | |
| 3313 | for (int i = 0; i < num; i++) { |
| 3314 | if (home_target != NULL) { |
| 3315 | vector subvec = home_target->pos - obj->pos; |
| 3316 | float mag = vm_GetMagnitudeFast(&subvec); |
| 3317 | subvec /= mag; |
| 3318 | |
| 3319 | int objnum = CreateAndFireWeapon(&obj->pos, &subvec, obj, spawn_index); |
| 3320 | |
| 3321 | // Stagger the weapons a bit |
| 3322 | if (objnum > -1) { |
| 3323 | object *created_obj = &Objects[objnum]; |
| 3324 | |
| 3325 | float scalar = .2 + ((float)(ps_rand() % 1000) / 1000.0); |
| 3326 | |
| 3327 | created_obj->mtype.phys_info.velocity *= scalar; |
| 3328 | } |
| 3329 | } else { |
| 3330 | matrix temp_mat; |
| 3331 | matrix rot_mat; |
| 3332 | vector new_norm; |
| 3333 | |
| 3334 | float norm = ((float)(ps_rand() % 1000)) / 1000.0; |
| 3335 | int x_twist = 16384 - (norm * 32768); |
| 3336 | if (x_twist < 0) |
| 3337 | x_twist = 65536 + x_twist; |
| 3338 | |
| 3339 | norm = ((float)(ps_rand() % 1000)) / 1000.0; |
| 3340 | int y_twist = 16384 - (norm * 32768); |
| 3341 | if (y_twist < 0) |
| 3342 | y_twist = 65536 + y_twist; |
| 3343 | |
| 3344 | vm_VectorToMatrix(&rot_mat, normal, NULL, NULL); |
| 3345 | vm_TransposeMatrix(&rot_mat); |
| 3346 | vm_AnglesToMatrix(&temp_mat, x_twist, y_twist, 0); |
| 3347 | |
| 3348 | new_norm = temp_mat.fvec * rot_mat; |
| 3349 | |
| 3350 | CreateAndFireWeapon(&obj->pos, &new_norm, obj, spawn_index); |
| 3351 | } |
| 3352 | } |
| 3353 | } |
| 3354 | |
| 3355 | // Does whatever to be done when a weapon times out |
| 3356 | void TimeoutWeapon(object *obj) { |
| 3357 | int n = obj->id; |
| 3358 | |
| 3359 | if ((Weapons[n].flags & WF_SPAWNS_TIMEOUT) && Weapons[n].spawn_count > 0 && Weapons[n].spawn_handle >= 0) { |
| 3360 | DoWeaponExploded(obj, &obj->orient.fvec); |
| 3361 | CreateTimeoutSpawnFromWeapon(obj); |
| 3362 | } |
| 3363 | |
| 3364 | if ((Weapons[n].flags & WF_MATTER_WEAPON) && !(Weapons[n].flags & WF_SPAWNS_TIMEOUT) && |
| 3365 | (Weapons[n].spawn_count <= 0)) { |
| 3366 | vector temp = Zero_vector; |
| 3367 | |
| 3368 | if (Weapons[obj->id].sounds[WSI_IMPACT_WALL] != SOUND_NONE_INDEX) |
| 3369 | Sound_system.Play3dSound(Weapons[obj->id].sounds[WSI_IMPACT_WALL], SND_PRIORITY_HIGH, obj); |
| 3370 | |
| 3371 | temp.y = 1.0; |
| 3372 | |
| 3373 | DoWeaponExploded(obj, &temp); |
| 3374 | } |
| 3375 | |
| 3376 | if (Weapons[n].flags & WF_TIMEOUT_WALL) { |
| 3377 | if (Weapons[obj->id].sounds[WSI_IMPACT_WALL] != SOUND_NONE_INDEX) |
| 3378 | Sound_system.Play3dSound(Weapons[obj->id].sounds[WSI_IMPACT_WALL], SND_PRIORITY_HIGH, obj); |
| 3379 | |
| 3380 | DoWeaponExploded(obj); |
| 3381 | } |
| 3382 | |
| 3383 | if ((Weapons[obj->id].flags & WF_SPAWNS_ROBOT) && (Weapons[obj->id].flags & WF_COUNTERMEASURE) && |
| 3384 | Weapons[obj->id].robot_spawn_handle >= 0) |
| 3385 | CreateRobotSpawnFromWeapon(obj); |
| 3386 | } |
| 3387 | |
| 3388 | // Given a parent object and a weapon id, creates that countermeasure |
| 3389 | void CreateCountermeasureFromObject(object *parent, int weapon_id) { |
| 3390 | ASSERT(parent != NULL); |
| 3391 | ASSERT(Weapons[weapon_id].used); |
| 3392 | |
| 3393 | if (Game_mode & GM_MULTI) |
| 3394 | MultiSendRequestCountermeasure(parent - Objects, weapon_id); |
| 3395 | else |
| 3396 | FireWeaponFromObject(parent, weapon_id, 5); |
| 3397 | } |
| 3398 | |
| 3399 | // Releases the guided missile of a passed in player |
| 3400 | void ReleaseGuidedMissile(int slot) { |
| 3401 | ASSERT(Players[slot].guided_obj); |
| 3402 | if (!Players[slot].guided_obj) |
| 3403 | return; |
| 3404 | |
| 3405 | if ((Game_mode & GM_MULTI) && (slot == Player_num)) { |
| 3406 | MultiSendMissileRelease(slot, true); |
| 3407 | } |
| 3408 | |
| 3409 | Players[slot].guided_obj->mtype.phys_info.flags &= ~PF_GUIDED; |
| 3410 | Players[slot].guided_obj = NULL; |
| 3411 | } |
| 3412 | |
| 3413 | // Releases the timeout missile of a passed in player |
| 3414 | void ReleaseUserTimeoutMissile(int slot) { |
| 3415 | ASSERT(Players[slot].user_timeout_obj); |
| 3416 | if (!Players[slot].user_timeout_obj) |
| 3417 | return; |
| 3418 | |
| 3419 | if ((Game_mode & GM_MULTI) && (slot == Player_num)) { |
| 3420 | MultiSendMissileRelease(slot, false); |
| 3421 | } |
| 3422 | |
| 3423 | TimeoutWeapon(Players[slot].user_timeout_obj); |
| 3424 | SetObjectDeadFlag(Players[slot].user_timeout_obj); |
| 3425 | |
| 3426 | Players[slot].user_timeout_obj = NULL; |
| 3427 | } |