| 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/AImain.cpp $ |
| 21 | * $Revision: 479 $ |
| 22 | * $Date: 4/19/00 5:08p $ |
| 23 | * $Author: Matt $ |
| 24 | * |
| 25 | * The Main of the AI code. |
| 26 | * |
| 27 | * $Log: /DescentIII/main/AImain.cpp $ |
| 28 | * |
| 29 | * 479 4/19/00 5:08p Matt |
| 30 | * From Duane for 1.4 |
| 31 | * Added checks, asserts, and fixes for bad return values |
| 32 | * Added error checking and minor optimization |
| 33 | * |
| 34 | * 478 3/20/00 12:00p Matt |
| 35 | * Merge of Duane's post-1.3 changes. |
| 36 | * Bail from anim update if no anim data. |
| 37 | * |
| 38 | * 477 11/02/99 12:17p Chris |
| 39 | * Improved the targetting code (no max dist when in the same room as |
| 40 | * target) |
| 41 | * |
| 42 | * 476 10/24/99 10:46p Chris |
| 43 | * Added the target_died notification |
| 44 | * |
| 45 | * 475 10/23/99 2:43a Chris |
| 46 | * Added the PutObjectOnObject AI Goal |
| 47 | * |
| 48 | * 474 10/22/99 10:43p Jeff |
| 49 | * put in check to handle new code from mac |
| 50 | * |
| 51 | * 473 10/22/99 3:40p Kevin |
| 52 | * Mac merge fixes |
| 53 | * |
| 54 | * 472 10/21/99 2:12p Matt |
| 55 | * Mac merge |
| 56 | * |
| 57 | * 471 10/20/99 5:40p Chris |
| 58 | * Added the Red Guidebot |
| 59 | * |
| 60 | * 470 10/17/99 11:58p Chris |
| 61 | * Improved the hearing/seeing code, Added AIN_FIRED_WEAPON notify, and |
| 62 | * added a *hack* so that the final boss could fire his weapons during a |
| 63 | * cutscene... (usually this is a no-no). |
| 64 | * |
| 65 | * 469 10/08/99 4:53p Nate |
| 66 | * Added ability to disable individual melee attacks |
| 67 | * |
| 68 | * 468 10/08/99 4:14p 3dsmax |
| 69 | * creeper fix (attached objs and FOV) (chris) |
| 70 | * |
| 71 | * 467 7/27/99 6:39p Chris |
| 72 | * Turned off the GB's player weapon dodging when he is in RTYPE mode |
| 73 | * |
| 74 | * 466 7/27/99 4:20p Chris |
| 75 | * Improved GB avoidance code |
| 76 | * |
| 77 | * 465 7/26/99 3:52p Chris |
| 78 | * Wall pulsing for the GB |
| 79 | * |
| 80 | * 464 7/26/99 1:18p Chris |
| 81 | * He now only dodges player shots |
| 82 | * |
| 83 | * 463 7/26/99 1:16p Chris |
| 84 | * GB now dodges player (and targetted robot) shots |
| 85 | * |
| 86 | * 462 5/24/99 3:23p Chris |
| 87 | * Fixed team anarchy bug. |
| 88 | * |
| 89 | * 461 5/23/99 10:39p Chris |
| 90 | * Fixed client gunboys so they not fire at the server |
| 91 | * |
| 92 | * 460 5/23/99 5:37a Chris |
| 93 | * Fixed bugs with non-AIF_DODGE objects dodging. Made stopping |
| 94 | * tolerances bigger |
| 95 | * |
| 96 | * 459 5/23/99 12:35a Chris |
| 97 | * Fixed the stop exactly problems |
| 98 | * |
| 99 | * 458 5/21/99 7:45p Chris |
| 100 | * Tweaked the cdist code... (again) |
| 101 | * |
| 102 | * 457 5/21/99 6:01p Chris |
| 103 | * Fixed turret speed scaling problems |
| 104 | * |
| 105 | * 456 5/21/99 7:29a Chris |
| 106 | * More tweaking... |
| 107 | * |
| 108 | * 455 5/20/99 3:48p Chris |
| 109 | * Rebel stuff isn't usually scaled by diff anymore |
| 110 | * |
| 111 | * 454 5/20/99 1:44a Chris |
| 112 | * Improved scaling of velocity for walkers (I.e. dont scale max speed or |
| 113 | * rotational speed because it make them look slow and dumb) |
| 114 | * |
| 115 | * 453 5/20/99 1:15a Chris |
| 116 | * Improved BNode Path Following for end points on the path. Fixed bugs |
| 117 | * with non-auto targetting |
| 118 | * |
| 119 | * 452 5/19/99 2:16a Chris |
| 120 | * Fixed gunboys in coop (will not fire on teammates now) |
| 121 | * |
| 122 | * 451 5/18/99 10:54p Chris |
| 123 | * Added some ASSERTs |
| 124 | * |
| 125 | * 450 5/18/99 6:58p Chris |
| 126 | * Hmmmm.... Not sure how that crash happened |
| 127 | * |
| 128 | * 449 5/18/99 10:57a Chris |
| 129 | * Various bug fixes |
| 130 | * |
| 131 | * 448 5/17/99 6:06p Chris |
| 132 | * Adding robot debug code |
| 133 | * |
| 134 | * 447 5/12/99 11:15p Chris |
| 135 | * Adjusted fvi_find for vis. |
| 136 | * |
| 137 | * 446 5/12/99 6:18a Chris |
| 138 | * Vastly improved FindObjOfType. Ignores non-rendered objects, if type |
| 139 | * is robot it ignores cameras, dead robots, or robots without any |
| 140 | * gunpoints (like a mine). |
| 141 | * |
| 142 | * 445 5/11/99 5:49p Chris |
| 143 | * Scaled energy drain by diff level... Increased HotShot energy drain, |
| 144 | * Fixed problem with Thief sound getting muffled by melee hit sound |
| 145 | * |
| 146 | * 444 5/10/99 5:11p Chris |
| 147 | * Fixed another hearing/seeing bug |
| 148 | * |
| 149 | * 443 5/10/99 2:59p Chris |
| 150 | * Fixed fov bug |
| 151 | * |
| 152 | * 442 5/10/99 8:21a Chris |
| 153 | * Reduced wall collision size for GB |
| 154 | * |
| 155 | * 441 5/10/99 12:23a Chris |
| 156 | * Fixed another hearing/seeing case. :) Buddy bot now is in the player |
| 157 | * ship at respawn |
| 158 | * |
| 159 | * 440 5/09/99 8:11p Chris |
| 160 | * Made the whole see/hear distintion work (mostly) |
| 161 | * |
| 162 | * 439 5/08/99 10:38p Chris |
| 163 | * Further scaled the game. :) |
| 164 | * |
| 165 | * 438 5/08/99 6:18p Chris |
| 166 | * Fixed up no hearing cases |
| 167 | * |
| 168 | * 437 5/08/99 4:12p Chris |
| 169 | * Added AI hearing noises... version 1 |
| 170 | * |
| 171 | * 436 5/07/99 10:56p Chris |
| 172 | * GB avoids forcefields, lava, and volatile surfaces... If he accidently |
| 173 | * hits one of these, he ignores the collision (i.e. no effects). It make |
| 174 | * him look smarter. |
| 175 | * |
| 176 | * 435 5/07/99 9:33p Chris |
| 177 | * Improve wall avoidance when never volatile, lava, and water surfaces |
| 178 | * |
| 179 | * 434 5/07/99 1:43p Chris |
| 180 | * Made in-game cinematics use the ORIENT_PATH_NODE for player ships |
| 181 | * |
| 182 | * 433 5/07/99 11:51a Chris |
| 183 | * Improve the algorithm for zero awareness firing |
| 184 | * |
| 185 | * 432 5/07/99 11:24a Chris |
| 186 | * Made 0 agresion robots only fire when they have a clear shot |
| 187 | * |
| 188 | * 431 5/04/99 6:49p Jason |
| 189 | * fixed dumb bug with spray weapons |
| 190 | * |
| 191 | * 430 5/02/99 1:59a Jason |
| 192 | * possibly fixed a bug related to spray weapons and dying |
| 193 | * |
| 194 | * 429 5/01/99 3:49a Chris |
| 195 | * Added the "No scale movement properties by diff level" checkbox |
| 196 | * |
| 197 | * 428 5/01/99 2:21a Chris |
| 198 | * Use the GF_SPEED_XXX stuff |
| 199 | * |
| 200 | * 427 4/30/99 2:09a Chris |
| 201 | * Gunboys will not target triggers anymore |
| 202 | * |
| 203 | * 426 4/29/99 3:59p Chris |
| 204 | * Fixed AI_SEE_SOUND playing too often (like all the time...) |
| 205 | * |
| 206 | * 425 4/27/99 4:41a Jeff |
| 207 | * only create guidebots if a single player game, or if its a multiplayer |
| 208 | * game and the correct netflag is set |
| 209 | * |
| 210 | * 424 4/26/99 11:11a Chris |
| 211 | * Updated Bnode system |
| 212 | * |
| 213 | * 423 4/24/99 2:20a Chris |
| 214 | * Added the Neutral_till_hit flag |
| 215 | * |
| 216 | * 422 4/21/99 2:53p Matt |
| 217 | * Added a new type for dying objects that have AI, instead of keeping a |
| 218 | * flag in the dying info. |
| 219 | * |
| 220 | * 421 4/21/99 11:05a Kevin |
| 221 | * new ps_rand and ps_srand to replace rand & srand |
| 222 | * |
| 223 | * 420 4/20/99 8:55p Chris |
| 224 | * Fixed problem with robots not being able to open locked doors that a |
| 225 | * player has the key for. |
| 226 | * |
| 227 | * 419 4/18/99 10:23a Chris |
| 228 | * |
| 229 | * 418 4/18/99 5:38a Chris |
| 230 | * Drastically improved the find_random_room function and added the |
| 231 | * makenextroomlist function |
| 232 | * |
| 233 | * 417 4/15/99 1:32a Jeff |
| 234 | * linux changes to compile /Main0 /Main1 /Main2 /Main3 /Main4 /Main5 |
| 235 | * /Main6 /Main7 /Main8 /Main9 /descent3/Main0 /descent3/Main1 |
| 236 | * /descent3/Main2 /descent3/Main3 /descent3/Main4 /descent3/Main5 |
| 237 | * /descent3/Main6 /descent3/Main7 /descent3/Main8 /descent3/Main9 |
| 238 | * AImain.cpp0 AImain.cpp1 AImain.cpp2 AImain.cpp3 AImain.cpp4 AImain.cpp5 |
| 239 | * AImain.cpp6 AImain.cpp7 AImain.cpp8 AImain.cpp9 linux0 linux1 linux2 |
| 240 | * linux3 linux4 linux5 linux6 linux7 linux8 |
| 241 | * |
| 242 | * 416 4/14/99 10:31p Jeff |
| 243 | * fixed name of ai_info struct to t_ai_info |
| 244 | * |
| 245 | * 415 4/14/99 2:50a Jeff |
| 246 | * fixed some case mismatched #includes |
| 247 | * |
| 248 | * 414 4/12/99 6:15p Samir |
| 249 | * Sound priorities pass 1 |
| 250 | * |
| 251 | * 413 4/12/99 5:45p Chris |
| 252 | * Improved Freud |
| 253 | * |
| 254 | * 412 4/10/99 6:39p Matt |
| 255 | * Only save the designer-editable AI data in the Object_info array, |
| 256 | * instead of the whole ai_frame structure. This saves 3200 bytes per |
| 257 | * Object_info entry, which is about 2 MB overall. |
| 258 | * |
| 259 | * 411 4/09/99 10:33a Chris |
| 260 | * Improvements to Freud |
| 261 | * |
| 262 | * 410 4/08/99 7:46p Chris |
| 263 | * Improving Freud |
| 264 | * |
| 265 | * 409 4/08/99 6:03p Chris |
| 266 | * Improved Freud |
| 267 | * |
| 268 | * 408 4/08/99 3:35p Chris |
| 269 | * Improved the Fear factor in Freud |
| 270 | * |
| 271 | * 407 4/07/99 3:55a Chris |
| 272 | * Independant (non-parented) Rebel robots will now fire on PTMC and |
| 273 | * Hostile robots. :) |
| 274 | * |
| 275 | * 406 4/06/99 11:04p Chris |
| 276 | * Global Unique id's for goals and circle dist stuff can be set when |
| 277 | * aware barely |
| 278 | * |
| 279 | * 405 4/06/99 6:36p Jason |
| 280 | * CHRIS -- Fixed a bug with AIDetermineFovVec() |
| 281 | * |
| 282 | * 404 4/06/99 11:18a Chris |
| 283 | * Fixed a big bug in the attach system where object's properties where |
| 284 | * not correctly reset after the attach |
| 285 | * |
| 286 | * 403 4/05/99 3:18p Chris |
| 287 | * Patching wandering code |
| 288 | * |
| 289 | * 402 4/05/99 11:36a Chris |
| 290 | * |
| 291 | * 401 4/05/99 11:36a Chris |
| 292 | * Fixed a few bugs with Orient to Node |
| 293 | * |
| 294 | * 400 4/02/99 3:55p Chris |
| 295 | * Fixed or at least commented about guidebot bugs |
| 296 | * |
| 297 | * 399 4/02/99 3:49p Chris |
| 298 | * Create GBs in multiplayer |
| 299 | * |
| 300 | * 398 4/02/99 10:18a Chris |
| 301 | * We can now mess with the Object_info anim stuff |
| 302 | * |
| 303 | * 397 3/30/99 4:32p Chris |
| 304 | * Moved subtype to the main goal sturct (from goal_info). Made move |
| 305 | * relative object vec finishable. (Like get behind player) |
| 306 | * |
| 307 | * 396 3/29/99 5:32p Kevin |
| 308 | * Build fixes |
| 309 | * |
| 310 | * 395 3/27/99 1:08p Chris |
| 311 | * AIPowerSwitch now prop's though all objects that are attached to the |
| 312 | * object that is turned on/off |
| 313 | * |
| 314 | * 394 3/26/99 6:57p Chris |
| 315 | * Fixed a bug with the landing code |
| 316 | * |
| 317 | * 393 3/26/99 2:58p Chris |
| 318 | * See sounds play 90% of the time |
| 319 | * |
| 320 | * 392 3/25/99 4:56p Chris |
| 321 | * Added code for the land on object DALLAS goal |
| 322 | * |
| 323 | * 391 3/25/99 12:00p Chris |
| 324 | * |
| 325 | * 390 3/25/99 11:56a Jason |
| 326 | * changed some sequencing bugs |
| 327 | * |
| 328 | * 389 3/23/99 11:51a Matt |
| 329 | * Made wander code not crash if the room selected was an outside room |
| 330 | * (from an inside wander) I.e. two rooms in two different mines with |
| 331 | * terrain between them. |
| 332 | * |
| 333 | * 388 3/22/99 7:10p Chris |
| 334 | * Added path node orientation |
| 335 | * |
| 336 | * 387 3/22/99 3:56p Chris |
| 337 | * |
| 338 | * 386 3/22/99 10:58a Chris |
| 339 | * Awareness code was tweaked. Multisafe stuff added for objects. |
| 340 | * |
| 341 | * 385 3/18/99 12:46p Chris |
| 342 | * Fixed an FOV and awareness conflict |
| 343 | * |
| 344 | * 384 3/17/99 5:23p Chris |
| 345 | * Fixed problems with low-priority paths |
| 346 | * |
| 347 | * 383 3/15/99 2:39p Chris |
| 348 | * Added some terrain avoidance |
| 349 | * |
| 350 | * 382 3/12/99 7:10p Chris |
| 351 | * Avoid avoid walls version 1.0 |
| 352 | * |
| 353 | * 381 3/12/99 12:16p Chris |
| 354 | * Blending primary and blend goals!!!!!! Awesome. |
| 355 | * |
| 356 | * 380 3/10/99 4:15p Chris |
| 357 | * Patches birds for now |
| 358 | * |
| 359 | * 379 3/09/99 2:42p Chris |
| 360 | * Backwards gone |
| 361 | * |
| 362 | * 378 3/09/99 2:13p Chris |
| 363 | * Robots flying backwards |
| 364 | * |
| 365 | * 377 3/05/99 6:07p Chris |
| 366 | * Fixed bug where OSIRIS wasn't informed at the 'level' level that a |
| 367 | * goal_uid was completed (it was and still is fine at the object level) |
| 368 | * |
| 369 | * 376 3/05/99 10:33a Chris |
| 370 | * Fixed the bashed it_handle bug |
| 371 | * |
| 372 | * 375 3/04/99 12:44p Chris |
| 373 | * Commented out Ignore height diff code -- chrishack |
| 374 | * |
| 375 | * 374 3/03/99 5:35p Kevin |
| 376 | * HAck |
| 377 | * |
| 378 | * 373 3/03/99 3:12p Chris |
| 379 | * No AI firing during cinematics |
| 380 | * |
| 381 | * 372 3/03/99 1:18p Chris |
| 382 | * Init'ed the perceived_vec_to_target |
| 383 | * |
| 384 | * 371 3/03/99 7:22a Chris |
| 385 | * Added Napalmed to the list |
| 386 | * |
| 387 | * 370 3/03/99 6:52a Chris |
| 388 | * Fixed headlight |
| 389 | * |
| 390 | * 369 3/03/99 5:47a Chris |
| 391 | * |
| 392 | * 368 3/03/99 5:47a Chris |
| 393 | * Fixed the headlight thing |
| 394 | * |
| 395 | * 367 3/03/99 5:45a Chris |
| 396 | * Further cased out the auto-turn stuff |
| 397 | * |
| 398 | * 366 3/02/99 11:41p Chris |
| 399 | * |
| 400 | * 365 3/02/99 10:53p Chris |
| 401 | * |
| 402 | * 364 3/02/99 10:46p Chris |
| 403 | * Improved the vis code |
| 404 | * |
| 405 | * 363 3/02/99 5:39p Chris |
| 406 | * Fixed the gunboy rotation problem |
| 407 | * |
| 408 | * 362 3/01/99 7:19p Chris |
| 409 | * Fixed dist problems with finding nearby objects |
| 410 | * |
| 411 | * 361 2/28/99 11:30p Chris |
| 412 | * FindObjOfType and OSIRIS controllable deaths |
| 413 | * |
| 414 | * 360 2/25/99 5:43p Chris |
| 415 | * Massive improvement to BOA and AI (again) |
| 416 | * |
| 417 | * 359 2/25/99 10:57a Matt |
| 418 | * Added new explosion system. |
| 419 | * |
| 420 | * 358 2/24/99 12:27p Chris |
| 421 | * Fixed problems with GB finding robots/room he couldn't get to. Fixed |
| 422 | * problems with forcefields(sound prop. and path finding). Fixed |
| 423 | * problems with small portals. |
| 424 | * |
| 425 | * 357 2/18/99 3:50p Chris |
| 426 | * Updated the exact stopping code for paths. Scaled acceleraion by |
| 427 | * max_speed scalar. |
| 428 | * |
| 429 | * 356 2/17/99 8:47p Chris |
| 430 | * See if this fixes Dan's rotating walker problem |
| 431 | * |
| 432 | * 355 2/17/99 1:21a Chris |
| 433 | * Updated the AI movement algorithm, fixed many bugs, added the |
| 434 | * last_dodge_dir vector so that robots can dodge the vauss and the like |
| 435 | * |
| 436 | * 354 2/15/99 9:03p Chris |
| 437 | * Added the base FOV off UVEC code and converted all the turrets |
| 438 | * |
| 439 | * 353 2/15/99 8:59a Chris |
| 440 | * |
| 441 | * 352 2/15/99 8:58a Chris |
| 442 | * |
| 443 | * 351 2/15/99 8:55a Chris |
| 444 | * Fixed a bug with AIF_XZ_DIST (It incorrectly computed the distance from |
| 445 | * a target) |
| 446 | * |
| 447 | * 350 2/12/99 11:19a Chris |
| 448 | * If max_turn_rate is zero, then don't call the orient code |
| 449 | * |
| 450 | * 349 2/10/99 4:02p Chris |
| 451 | * Updated the attach system so that if a robot is idling, the AI will not |
| 452 | * update the attached subobjects (if the object is still moving, physics |
| 453 | * will do it). |
| 454 | * |
| 455 | * 348 2/10/99 2:41p Chris |
| 456 | * Added debug info |
| 457 | * |
| 458 | * 347 2/10/99 1:47p Matt |
| 459 | * Changed object handle symbolic constants |
| 460 | * |
| 461 | * 346 2/09/99 3:52p Chris |
| 462 | * Fixed melee attacks |
| 463 | * |
| 464 | * 345 2/09/99 12:40p Chris |
| 465 | * More aipath stuff has been merged with the new BOA |
| 466 | * |
| 467 | * 344 2/09/99 9:58a Chris |
| 468 | * Massive BOA update :) Terrain happy now. Vis happy now. Sound happy |
| 469 | * now. |
| 470 | * |
| 471 | * 343 2/03/99 11:09a Chris |
| 472 | * Stop at position goals will now get the AIN_GOAL_COMPLETE correctly |
| 473 | * |
| 474 | * 342 2/02/99 12:24p Sean |
| 475 | * CHRIS -- Fixed a bug with dummy turrets. They wehre using a bogus |
| 476 | * index. |
| 477 | * |
| 478 | * 341 2/02/99 11:27a Chris |
| 479 | * Added the AIN_MOVIE_START and AIN_MOVIE_END notifies |
| 480 | * |
| 481 | * 340 2/02/99 9:23a Chris |
| 482 | * Fixed turning problems caused by zero vectors (which return a random |
| 483 | * vector) |
| 484 | * Fixed jitteryness problem caused by having too tight of a need-to-turn |
| 485 | * tolerance on large robots |
| 486 | * |
| 487 | * 339 2/02/99 9:06a Chris |
| 488 | * Fixed a bug where robots where starting in AS_ALERT instead of AS_IDLE |
| 489 | * |
| 490 | * 338 1/31/99 10:43p Chris |
| 491 | * added WBF_AIM_FVEC |
| 492 | * |
| 493 | * 337 1/29/99 5:27p Luke |
| 494 | * CHRIS - Updated the Gaurd goal |
| 495 | * |
| 496 | * 336 1/29/99 5:10p Chris |
| 497 | * Added an optional parent handle check for FindObjOfType |
| 498 | * |
| 499 | * 335 1/26/99 2:51p Chris |
| 500 | * AIG_WANDER improvements |
| 501 | * |
| 502 | * 334 1/25/99 7:43a Chris |
| 503 | * Added the GUID (Goal Unique Id) and added the ability for weapon |
| 504 | * batteries to always fire exactly forward. |
| 505 | * |
| 506 | * 333 1/24/99 10:58p Chris |
| 507 | * Fixed problems with AvoidObj code |
| 508 | * |
| 509 | * 332 1/24/99 8:17p Chris |
| 510 | * Updated AI and OSIRIS. Externalized fireball constants for spew and |
| 511 | * sparks. Added CreateRandomSparks to OSIRIS, renamed a bunch of AI |
| 512 | * Notify names to use underscores. Fixed a memory access leak in the |
| 513 | * matcen effect code. |
| 514 | * |
| 515 | * 331 1/23/99 2:20p Chris |
| 516 | * Removed a walker hack |
| 517 | * |
| 518 | * 330 1/22/99 6:53p Chris |
| 519 | * Fixed LoadandBind Aux notify problems, fixed static path problems, |
| 520 | * fixed AIF_FORCE_AWARE Problems, improved path code |
| 521 | * |
| 522 | * 329 1/21/99 11:15p Jeff |
| 523 | * pulled out some structs and defines from header files and moved them |
| 524 | * into seperate header files so that multiplayer dlls don't require major |
| 525 | * game headers, just those new headers. Side effect is a shorter build |
| 526 | * time. Also cleaned up some header file #includes that weren't needed. |
| 527 | * This affected polymodel.h, object.h, player.h, vecmat.h, room.h, |
| 528 | * manage.h and multi.h |
| 529 | * |
| 530 | * 328 1/20/99 2:13a Chris |
| 531 | * It is now possible for robots to have special immunities, resistances, |
| 532 | * and vunerabilities |
| 533 | * |
| 534 | * 327 1/20/99 1:01a Chris |
| 535 | * Improved AI and OSIRIS intergration |
| 536 | * |
| 537 | * 326 1/18/99 8:07p Chris |
| 538 | * Added the no-collide same flag (for flocks and nests) |
| 539 | * |
| 540 | * 325 1/18/99 10:14a Chris |
| 541 | * |
| 542 | * 324 1/18/99 9:05a Chris |
| 543 | * Improved OSIRIS, AI, and ATTACH system, changed wiggle code, changed |
| 544 | * attach code for rad attaches, and added the AIG_ATTACH_OBJ goal |
| 545 | * |
| 546 | * 323 1/15/99 5:57p Chris |
| 547 | * fixed some awareness bugs |
| 548 | * |
| 549 | * 322 1/13/99 6:37a Jeff |
| 550 | * fixed object.h. There were numerous struct declarations that were the |
| 551 | * same name as the instance of the struct (gcc doesn't like this). |
| 552 | * Changed the struct name. Also added some #ifdef's for linux build, |
| 553 | * along with fixing case-sensitive includes |
| 554 | * |
| 555 | * 321 1/13/99 2:28a Chris |
| 556 | * Massive AI, OSIRIS update |
| 557 | * |
| 558 | * 320 1/11/99 2:14p Chris |
| 559 | * Massive work on OSIRIS and AI |
| 560 | * |
| 561 | * 319 1/06/99 5:06p Chris |
| 562 | * Improving OSIRIS/game intergration - improved support for custom |
| 563 | * animations |
| 564 | * |
| 565 | * 318 1/05/99 6:28p Chris |
| 566 | * Fix OSIRIS AI_Notify problem |
| 567 | * |
| 568 | * 317 12/30/98 3:46p Chris |
| 569 | * Incremental AI changes |
| 570 | * |
| 571 | * 316 12/23/98 6:10p Matt |
| 572 | * Fixed compiler warnings |
| 573 | * |
| 574 | * 315 12/18/98 5:40p Chris |
| 575 | * Fixed a crash bug in the new OSIRIS |
| 576 | * |
| 577 | * 314 12/17/98 12:08p Jeff |
| 578 | * first checkin of new implementation of OSIRIS (old OSIRIS no longer |
| 579 | * works) |
| 580 | * |
| 581 | * 313 12/16/98 3:55p Chris |
| 582 | * Improved the sickles |
| 583 | * |
| 584 | * 312 12/15/98 4:58p Chris |
| 585 | * Improved the path system |
| 586 | * |
| 587 | * 311 12/15/98 4:08p Chris |
| 588 | * Removed the annoying stop mprintf |
| 589 | * |
| 590 | * 310 12/15/98 4:04p Chris |
| 591 | * Wall landers work |
| 592 | * |
| 593 | * 309 12/14/98 2:04p Chris |
| 594 | * Fixed an evader1 blend problem |
| 595 | * |
| 596 | * 308 12/14/98 1:07p Chris |
| 597 | * Allowed OSIRIS to change AI types |
| 598 | * |
| 599 | * 307 12/14/98 12:03a Chris |
| 600 | * Turning and orientation are done in one (minus a few hacks) spot |
| 601 | * |
| 602 | * 306 12/13/98 9:18p Chris |
| 603 | * Improved influence values for in-code goals (10000 to 1.0). Added |
| 604 | * GF_ORIENT stuff. :) |
| 605 | * |
| 606 | * 305 12/12/98 10:11p Chris |
| 607 | * Cleaned up some CT stuff |
| 608 | * |
| 609 | * 304 12/11/98 6:24p Chris |
| 610 | * Additional Comments |
| 611 | * |
| 612 | * 303 12/11/98 1:57p Chris |
| 613 | * Improved wall walking code |
| 614 | * |
| 615 | * 302 12/11/98 12:04p Chris |
| 616 | * Improved the flocking hack. :) |
| 617 | * |
| 618 | * 301 12/08/98 4:27p Chris |
| 619 | * Fixed all avoid code from avoiding attached robots |
| 620 | * |
| 621 | * 300 12/08/98 2:14p Chris |
| 622 | * Fixed bugs when an object is avoiding a robot the is attached to it |
| 623 | * |
| 624 | * 299 12/03/98 5:45p Chris |
| 625 | * I just added full code support for OSIRIS/DLL controlled goals, |
| 626 | * enablers, and influence levels. :) |
| 627 | * |
| 628 | * 298 12/03/98 2:31p Chris |
| 629 | * The auto-avoid friends flag is now cooler now (they avoid at greater |
| 630 | * distances when they are within thier circle distance from a targetted |
| 631 | * enemy) |
| 632 | * |
| 633 | * 297 12/03/98 12:24p Chris |
| 634 | * Improved new anim code for instant updating |
| 635 | * |
| 636 | * 296 12/03/98 12:04p Chris |
| 637 | * Further de-hacked flocking and other major AI systems |
| 638 | * |
| 639 | * 295 12/02/98 5:51p Chris |
| 640 | * Lint cleaning |
| 641 | * |
| 642 | * 294 12/02/98 2:27p Chris |
| 643 | * Algorithm swap stuff for target leading |
| 644 | * |
| 645 | * 293 12/02/98 2:13p Chris |
| 646 | * We now use the target lead accuracy slider |
| 647 | * |
| 648 | * 292 12/01/98 6:17p Chris |
| 649 | * Height bias is only for outside and GoalDetermineTrackDist is closer to |
| 650 | * final |
| 651 | * |
| 652 | * 291 12/01/98 5:09p Chris |
| 653 | * Improved the height bias code |
| 654 | * |
| 655 | * 290 12/01/98 4:31p Chris |
| 656 | * Checked in a massive amount of AI work. Improved flocking code. :) |
| 657 | * (Still hacked lightly). In addition, I am moving toward using the |
| 658 | * composite dir. :) |
| 659 | * |
| 660 | * 289 12/01/98 3:31p Keneta |
| 661 | * Added a temp fix for avoid_obj when there are no objs |
| 662 | * |
| 663 | * 288 11/23/98 3:11p Kevin |
| 664 | * Demo system |
| 665 | * |
| 666 | * 287 11/23/98 11:26a Chris |
| 667 | * More improvements to the AI system |
| 668 | * |
| 669 | * 286 11/23/98 11:09a Chris |
| 670 | * Incremental improvements |
| 671 | * |
| 672 | * 285 11/20/98 11:37a Chris |
| 673 | * Improved avoidance code |
| 674 | * |
| 675 | * 284 11/19/98 8:55p Chris |
| 676 | * |
| 677 | * 283 11/19/98 8:55p Chris |
| 678 | * |
| 679 | * 282 11/19/98 8:55p Chris |
| 680 | * I am being to clean up the structure |
| 681 | * |
| 682 | * 281 11/19/98 8:26p Chris |
| 683 | * Starting to add generic team avoidance code |
| 684 | * |
| 685 | * 280 11/18/98 6:25p Chris |
| 686 | * Dodge->avoid->normal. That is the order. To do it right, dodge will |
| 687 | * get a BIG scalar, avoid will get a smaller scalar, and normal stuff |
| 688 | * will get a tiny scalar. |
| 689 | * |
| 690 | * 279 11/18/98 3:59p Chris |
| 691 | * I added the avoid goal. I also improved the AIs for Evader1 and |
| 692 | * Evader2 by utilizing this goal when the target is well within the |
| 693 | * circle distance. |
| 694 | * |
| 695 | * 278 11/17/98 4:16p Kevin |
| 696 | * Demo recording system |
| 697 | * |
| 698 | * 277 11/11/98 7:18p Jeff |
| 699 | * changes made so that a dedicated server's team is always -1 (team game |
| 700 | * or not) |
| 701 | * |
| 702 | * 276 11/11/98 6:31p Chris |
| 703 | * AIF_DISABLE_FIRING and AIF_DISABLE_MELEE are now functional |
| 704 | * |
| 705 | * 275 11/11/98 2:46p Kevin |
| 706 | * Demo recording system work |
| 707 | * |
| 708 | * 274 11/11/98 12:11p Chris |
| 709 | * The attach system and weapon firing (continous and spray) are now |
| 710 | * network friendly |
| 711 | * |
| 712 | * 273 11/10/98 6:17p Chris |
| 713 | * Improved AI - added support for manual max firing distances |
| 714 | * |
| 715 | * 272 11/09/98 3:08p Kevin |
| 716 | * Turned off AI while playing back a demo |
| 717 | * |
| 718 | * 271 11/06/98 5:34p Chris |
| 719 | * |
| 720 | * 270 11/06/98 11:39a Chris |
| 721 | * Robots with flamethrowers and Omega cannons work in single player |
| 722 | * |
| 723 | * 269 10/29/98 1:45p Chris |
| 724 | * Checked in the better collision response code |
| 725 | * |
| 726 | * 268 10/28/98 4:37p Chris |
| 727 | * Robots who are parented by ghosts still know their team. |
| 728 | * |
| 729 | * 267 10/22/98 5:36p Chris |
| 730 | * Fixed ObjGet bugs |
| 731 | * |
| 732 | * 266 10/22/98 2:58p Chris |
| 733 | * Difficulty levels are in beta |
| 734 | * |
| 735 | * 265 10/21/98 5:35p Chris |
| 736 | * Added friend forgiving to the aggression slider |
| 737 | * |
| 738 | * 264 10/21/98 7:33a Chris |
| 739 | * Dead objects are not-targetable |
| 740 | * |
| 741 | * 263 10/20/98 11:56p Chris |
| 742 | * |
| 743 | * 262 10/20/98 10:52p Chris |
| 744 | * Improved the single player targeting when a player is dead |
| 745 | * (Player->buddy->none) |
| 746 | * |
| 747 | * 261 10/19/98 7:20p Chris |
| 748 | * Added custom fire dot code |
| 749 | * |
| 750 | * 260 10/19/98 7:17p Matt |
| 751 | * Added system to support different types of damage to the player and |
| 752 | * have these different types make different sounds. |
| 753 | * |
| 754 | * 259 10/16/98 3:39p Chris |
| 755 | * Improved the object linking system and AI and physics |
| 756 | * |
| 757 | * 258 10/15/98 3:26p Chris |
| 758 | * Fixed known ground plane issues and used PhysCalcGround everywhere |
| 759 | * |
| 760 | * 257 10/14/98 7:04p Chris |
| 761 | * Update turret sound code |
| 762 | * |
| 763 | * 256 10/14/98 6:54p Chris |
| 764 | * Added turret change direction sounds and level goal ability to toggle |
| 765 | * auto level end |
| 766 | * |
| 767 | * 255 10/14/98 4:45p Chris |
| 768 | * Added support for a endlevel in-game movie |
| 769 | * |
| 770 | * 254 10/14/98 3:39p Chris |
| 771 | * Improved robot dodging and firing |
| 772 | * |
| 773 | * 253 10/13/98 1:08p Chris |
| 774 | * Greatly improved the AI's use of paths. Improved visability checking |
| 775 | * algorithm. Probably needs a second pass for further cleanup. |
| 776 | * |
| 777 | * 252 10/09/98 4:01p Chris |
| 778 | * |
| 779 | * 251 10/09/98 2:24a Chris |
| 780 | * |
| 781 | * 250 10/09/98 2:22a Chris |
| 782 | * Improving vis checking |
| 783 | * |
| 784 | * 249 10/09/98 2:17a Chris |
| 785 | * |
| 786 | * 248 10/09/98 1:39a Chris |
| 787 | * Added very infrequent target updating for robots with an awareness less |
| 788 | * than AWARE_BARELY |
| 789 | * |
| 790 | * 247 10/09/98 1:35a Chris |
| 791 | * Fixed a bug with robots only attacking after they are rendered |
| 792 | * |
| 793 | * 246 10/08/98 8:49p Chris |
| 794 | * Improving AI initialization? |
| 795 | * |
| 796 | * 245 10/07/98 10:06p Chris |
| 797 | * Improved the attach system's updating |
| 798 | * |
| 799 | * 244 10/07/98 3:37p Chris |
| 800 | * Improved the melee attack code |
| 801 | * |
| 802 | * 243 10/07/98 12:39p Chris |
| 803 | * Added support for zero latency attacks |
| 804 | * |
| 805 | * 242 10/07/98 10:54a Chris |
| 806 | * Matcens use the birth animations |
| 807 | * |
| 808 | * 241 10/06/98 6:19p Chris |
| 809 | * Improved OSIRIS/AI intergration |
| 810 | * |
| 811 | * 240 10/06/98 5:45p Kevin |
| 812 | * Added new configuration for demo |
| 813 | * |
| 814 | * 239 9/30/98 4:40p Chris |
| 815 | * |
| 816 | * 238 9/30/98 4:36p Chris |
| 817 | * Fixed a targetting bug |
| 818 | * |
| 819 | * 237 9/30/98 3:49p Chris |
| 820 | * Changed comment |
| 821 | * |
| 822 | * 236 9/29/98 3:11p Chris |
| 823 | * |
| 824 | * 235 9/28/98 7:23p Chris |
| 825 | * same as prev |
| 826 | * |
| 827 | * 234 9/28/98 7:03p Chris |
| 828 | * Improved targetting of objects by AIs |
| 829 | * |
| 830 | * 233 9/28/98 6:23p Chris |
| 831 | * Changed multi_anim to custom_anim |
| 832 | * |
| 833 | * 232 9/28/98 4:09p Chris |
| 834 | * Added birth animations |
| 835 | * |
| 836 | * 231 9/28/98 1:15p Chris |
| 837 | * Fixed the targetting of parents(oops) after parent-collide-timeout |
| 838 | * |
| 839 | * 230 9/28/98 10:34a Chris |
| 840 | * Fixed a semi-colon bug |
| 841 | * |
| 842 | * 229 9/22/98 6:03p Samir |
| 843 | * ifdef out DoAI if not in debug version. |
| 844 | * |
| 845 | * 228 9/17/98 11:11a Chris |
| 846 | * Worked on goal system and improved integration with OSIRIS (better |
| 847 | * EVT_AI_INIT event calling) |
| 848 | * |
| 849 | * 227 9/16/98 4:30p Chris |
| 850 | * Added target by distance |
| 851 | * |
| 852 | * 226 9/15/98 7:29p Chris |
| 853 | * Improved OSIRIS and AI intergration |
| 854 | * |
| 855 | * 225 9/14/98 1:14p Chris |
| 856 | * Improved multiplayer team/non-team support |
| 857 | * |
| 858 | * 224 9/14/98 12:56p Chris |
| 859 | * Automatically put player parented objects as part of AIF_TEAM_REBEL |
| 860 | * |
| 861 | * 223 9/14/98 12:23p Chris |
| 862 | * |
| 863 | * 222 9/14/98 12:16p Chris |
| 864 | * Vastly improved the multiplayer code |
| 865 | * |
| 866 | * 221 9/11/98 5:27p Chris |
| 867 | * Further improved the cooperative multiplayer ai |
| 868 | * |
| 869 | * 220 9/11/98 11:58a Chris |
| 870 | * Fixed too many sounds in cooperative multiplayer |
| 871 | * |
| 872 | * 219 8/25/98 10:44a Chris |
| 873 | * Worked on leading code a bit |
| 874 | * |
| 875 | * 218 8/25/98 10:21a Chris |
| 876 | * Removed 2 annoying mprintfs |
| 877 | * |
| 878 | * 217 8/19/98 6:25p Chris |
| 879 | * Added the infighting sliders |
| 880 | * |
| 881 | * 216 8/17/98 4:55p Chris |
| 882 | * Reduced infighting |
| 883 | * |
| 884 | * 215 8/15/98 6:10p Chris |
| 885 | * Added OSIRIS controlled firing |
| 886 | * |
| 887 | * 214 8/12/98 6:10p Chris |
| 888 | * Added more to the attach code. Added support for OBJ_DUMMY |
| 889 | * |
| 890 | * 213 8/10/98 12:16p Chris |
| 891 | * Added AI_NumHostileAlert |
| 892 | * |
| 893 | * 212 8/06/98 11:49a Chris |
| 894 | * OBJ_NONE objects where getting notified of stuff |
| 895 | * |
| 896 | * 211 8/03/98 3:59p Chris |
| 897 | * Added support for FQ_IGNORE_WEAPONS, added .000001 attach code, fix a |
| 898 | * bug in polymodel collision detection |
| 899 | * |
| 900 | * 210 7/29/98 10:24a Chris |
| 901 | * Improved target updating code for multiplayer |
| 902 | * |
| 903 | * 209 7/28/98 5:48p Chris |
| 904 | * |
| 905 | * 208 7/28/98 5:41p Chris |
| 906 | * |
| 907 | * 207 7/28/98 5:04p Chris |
| 908 | * Added some new multiplayer support (for dodging and targetting) |
| 909 | * |
| 910 | * 206 7/24/98 6:06p Chris |
| 911 | * Initial robot leading code -- needs multiple wb support |
| 912 | * |
| 913 | * 205 7/17/98 6:08p Chris |
| 914 | * Greatly improved homing performance |
| 915 | * |
| 916 | * 204 7/14/98 5:52p Kevin |
| 917 | * Packet loss measurements and auto pps adjusting |
| 918 | * |
| 919 | * 203 7/09/98 3:36p Chris |
| 920 | * |
| 921 | * 201 7/09/98 1:05p Chris |
| 922 | * Added some parenthesis |
| 923 | * |
| 924 | * 200 7/09/98 12:44p Chris |
| 925 | * |
| 926 | * 199 7/09/98 12:34p Chris |
| 927 | * Fixed a problem with the current interp code |
| 928 | * |
| 929 | * 198 7/09/98 12:31p Chris |
| 930 | * Improved the turret interp code |
| 931 | * |
| 932 | * 197 7/09/98 11:34a Chris |
| 933 | * Turrets are interpolated. |
| 934 | * |
| 935 | * 196 7/08/98 1:02p Chris |
| 936 | * |
| 937 | * 195 7/08/98 12:11p Chris |
| 938 | * |
| 939 | * 194 7/08/98 11:38a Chris |
| 940 | * Improved the turret info passing in multiplayer |
| 941 | * |
| 942 | * 193 7/07/98 11:29a Chris |
| 943 | * |
| 944 | * 192 7/07/98 10:10a Kevin |
| 945 | * Added basic turret support for coop |
| 946 | * |
| 947 | * 191 7/06/98 10:27a Chris |
| 948 | * Re-added general awareness |
| 949 | * |
| 950 | * 190 7/02/98 6:08p Chris |
| 951 | * Removed the quick hack way of doing awareness |
| 952 | * |
| 953 | * 189 7/01/98 7:11p Chris |
| 954 | * Added multi blocks |
| 955 | * |
| 956 | * 188 7/01/98 6:36p Chris |
| 957 | * Added more multiplayer support |
| 958 | * |
| 959 | * 187 7/01/98 4:35p Chris |
| 960 | * More multiplayer sync issues |
| 961 | * |
| 962 | * 186 7/01/98 2:02p Chris |
| 963 | * Added the sound for animations |
| 964 | * |
| 965 | * 185 7/01/98 10:58a Chris |
| 966 | * Working on multiplayer AI stuff |
| 967 | * |
| 968 | * 184 6/30/98 6:36p Chris |
| 969 | * Added rev .1 of multiplayer animations - BTW It is totally not done. |
| 970 | * |
| 971 | * 183 6/29/98 1:50p Chris |
| 972 | * Fixed a turning multiplayer bug |
| 973 | * |
| 974 | * 182 6/29/98 1:35p Chris |
| 975 | * Incremental improvements |
| 976 | * |
| 977 | * 181 6/29/98 1:12p Chris |
| 978 | * Dodge updates |
| 979 | * |
| 980 | * 180 6/29/98 12:34p Chris |
| 981 | * Fighting robots get some notification of hostile fire |
| 982 | * |
| 983 | * 179 6/29/98 10:20a Chris |
| 984 | * Someone changed the way ObjGet works. |
| 985 | * |
| 986 | * 178 6/26/98 4:57p Chris |
| 987 | * Less flinching |
| 988 | * |
| 989 | * 177 6/26/98 4:03p Chris |
| 990 | * Added support for AI's changing targets -- VERY NOT DONE |
| 991 | * |
| 992 | * 176 6/26/98 2:52p Chris |
| 993 | * AI now reports when it updates its orientation |
| 994 | * |
| 995 | * 175 6/25/98 3:40p Chris |
| 996 | * Made AINotify work correctly (i.e. not at all) on clients |
| 997 | * |
| 998 | * 174 6/25/98 11:02a Chris |
| 999 | * Made clients bail. |
| 1000 | * |
| 1001 | * 173 6/15/98 6:29p Chris |
| 1002 | * Added FQ_NO_RELINK to the homing code |
| 1003 | * |
| 1004 | * 172 6/15/98 5:45p Chris |
| 1005 | * |
| 1006 | * 171 6/15/98 5:18p Chris |
| 1007 | * Added version 1 of the multiple ground point code |
| 1008 | * |
| 1009 | * 170 6/15/98 3:23p Chris |
| 1010 | * Single point walker update |
| 1011 | * |
| 1012 | * 169 6/03/98 6:42p Chris |
| 1013 | * Added multipoint collision detection an Assert on invalid (infinite |
| 1014 | * endpoint). |
| 1015 | * |
| 1016 | * 168 6/01/98 9:24p Chris |
| 1017 | * Improved the code for AIs that are off |
| 1018 | * |
| 1019 | * 167 5/27/98 5:54p Chris |
| 1020 | * If AI is off, no notifies are received |
| 1021 | * |
| 1022 | * 166 5/27/98 3:19p Chris |
| 1023 | * Made disabled AIs ignore dodge notifications |
| 1024 | * |
| 1025 | * 165 5/26/98 7:57p Chris |
| 1026 | * Worked on the avoid hack |
| 1027 | * |
| 1028 | * 164 5/26/98 7:41p Chris |
| 1029 | * Made hoppers not converge |
| 1030 | * |
| 1031 | * 163 5/26/98 5:04p Chris |
| 1032 | * rev .2 of walking |
| 1033 | * |
| 1034 | * 162 5/26/98 4:39p Chris |
| 1035 | * rev. .1 of walker code |
| 1036 | * |
| 1037 | * 161 5/26/98 4:10p Chris |
| 1038 | * Removed a hack |
| 1039 | * |
| 1040 | * 160 5/26/98 2:49p Chris |
| 1041 | * More fixes |
| 1042 | * |
| 1043 | * 159 5/26/98 2:26p Chris |
| 1044 | * Fixed the circle distance bug in AIGoalMoveRelativeObjectVec |
| 1045 | * |
| 1046 | * 158 5/26/98 10:03a Chris |
| 1047 | * move relative object and orient to vel where causing problems with each |
| 1048 | * other. I found a temp solution |
| 1049 | * |
| 1050 | * 157 5/26/98 9:45a Chris |
| 1051 | * DIstance and vec_to_target are independant |
| 1052 | * |
| 1053 | * 156 5/26/98 9:34a Chris |
| 1054 | * Added XZ distances for circle dist. :) |
| 1055 | * |
| 1056 | * 155 5/22/98 6:50p Chris |
| 1057 | * Improving the melee attacks |
| 1058 | * |
| 1059 | * 154 5/22/98 6:45p Chris |
| 1060 | * Fixed a bug with flinching and melee attacks |
| 1061 | * |
| 1062 | * 153 5/22/98 6:28p Chris |
| 1063 | * Working on melee attacks |
| 1064 | * |
| 1065 | * 152 5/22/98 6:22p Chris |
| 1066 | * Improved Dynamic path allocation |
| 1067 | * |
| 1068 | * 151 5/22/98 4:44p Chris |
| 1069 | * Added better melee hit prediction |
| 1070 | * |
| 1071 | * 150 5/22/98 11:59a Chris |
| 1072 | * Fixed improper uses of FindSoundName and made the proper static sounds |
| 1073 | * |
| 1074 | * 149 5/20/98 5:12p Chris |
| 1075 | * Print the notify number a robot gets when it is invalid |
| 1076 | * |
| 1077 | * 148 5/20/98 10:22a Chris |
| 1078 | * Improved targetting stuff |
| 1079 | * |
| 1080 | * 147 5/20/98 10:19a Chris |
| 1081 | * Fixed some bugs with status_reg's and circle distance |
| 1082 | * |
| 1083 | * 146 5/19/98 2:53p Chris |
| 1084 | * CreateObject in OSIRIS works outside now. |
| 1085 | * |
| 1086 | * 145 5/18/98 8:06p Chris |
| 1087 | * Made melee attacks closer to what I want in terms of functionality |
| 1088 | * |
| 1089 | * 144 5/18/98 12:40p Chris |
| 1090 | * Added a new flag (F_BLINE_IF_SEE_GOAL) |
| 1091 | * |
| 1092 | * 143 5/18/98 11:16a Chris |
| 1093 | * Fixed a problem with the GetToObj goal (an if statement was f*cked up) |
| 1094 | * |
| 1095 | * 142 5/17/98 9:07p Chris |
| 1096 | * Fixed melee attacks. Thanks to Ala. :) |
| 1097 | * |
| 1098 | * 141 5/17/98 8:05p Chris |
| 1099 | * |
| 1100 | * 140 5/17/98 7:54p Chris |
| 1101 | * Correctly integrated the goal system and circle distance stuff. Added |
| 1102 | * support for "target goals". |
| 1103 | * |
| 1104 | * 139 5/15/98 2:58p Chris |
| 1105 | * More on the big AI update |
| 1106 | * |
| 1107 | * 138 5/14/98 3:01p Chris |
| 1108 | * More new AI code |
| 1109 | * |
| 1110 | * 137 5/14/98 12:21p Chris |
| 1111 | * Updating AI system... Incomplete |
| 1112 | * |
| 1113 | * 136 5/12/98 3:46p Chris |
| 1114 | * Added some notify/goal system stuff and orientation to velocity |
| 1115 | * |
| 1116 | * 135 5/11/98 4:39p Chris |
| 1117 | * Improved AI system (goals have notifies and are more flexable). |
| 1118 | * |
| 1119 | * 134 5/04/98 4:20p Chris |
| 1120 | * Energy Drain |
| 1121 | * |
| 1122 | * 133 5/04/98 4:04p Chris |
| 1123 | * Minestone checkin' -- energy effect and more AI functionality |
| 1124 | * |
| 1125 | * 132 5/04/98 12:22p Chris |
| 1126 | * Hacked some buddy bot code |
| 1127 | * |
| 1128 | * 131 5/04/98 11:00a Chris |
| 1129 | * Hacks |
| 1130 | * |
| 1131 | * 130 5/03/98 7:02p Chris |
| 1132 | * Improved sound support for AI system |
| 1133 | * |
| 1134 | * 129 5/03/98 6:03p Chris |
| 1135 | * Added sound support to the animation system |
| 1136 | * |
| 1137 | * 128 5/03/98 5:38p Chris |
| 1138 | * Added sounds to anim page |
| 1139 | * |
| 1140 | * 127 5/01/98 7:53p Chris |
| 1141 | * |
| 1142 | * 126 5/01/98 7:52p Chris |
| 1143 | * Turn toward player - not last see position |
| 1144 | * |
| 1145 | * 125 5/01/98 3:41p Chris |
| 1146 | * |
| 1147 | * 124 5/31/98 3:03p Chris |
| 1148 | * Added death animations |
| 1149 | * |
| 1150 | * 123 4/30/98 2:03p Chris |
| 1151 | * Fixed the robot jiggyness problem. :) |
| 1152 | * |
| 1153 | * 122 4/30/98 11:31a Chris |
| 1154 | * Massive upgrades to the AI system |
| 1155 | * |
| 1156 | * 121 4/22/98 9:43p Chris |
| 1157 | * More AI improvements |
| 1158 | * |
| 1159 | * 120 4/22/98 4:15p Chris |
| 1160 | * Improved DebugBlockPrint |
| 1161 | * |
| 1162 | * 119 4/22/98 3:50p Chris |
| 1163 | * Added DebugBlockPrint |
| 1164 | * |
| 1165 | * 118 4/22/98 1:15p Chris |
| 1166 | * Incremental work on paths and goals |
| 1167 | * |
| 1168 | * 117 4/21/98 11:25a Chris |
| 1169 | * Improving GET_TO_OBJ goal |
| 1170 | * |
| 1171 | * 116 4/20/98 12:27p Chris |
| 1172 | * Made AIG_GET_TO_OBJECT work. |
| 1173 | * |
| 1174 | * 115 4/19/98 9:56p Chris |
| 1175 | * AI system is integrated with OSIRIS. Path system is integrated with |
| 1176 | * the AI system. Bugs will ensue. |
| 1177 | * |
| 1178 | * 114 4/17/98 1:59p Jason |
| 1179 | * added cool object effects |
| 1180 | * |
| 1181 | * 113 4/16/98 2:56p Chris |
| 1182 | * Updated buddy support and intergrated scripting and AI |
| 1183 | * |
| 1184 | * 112 4/15/98 5:56p Chris |
| 1185 | * Made the AI system script friendly |
| 1186 | * |
| 1187 | * 111 4/14/98 3:20p Chris |
| 1188 | * Made quirks happen more often |
| 1189 | * |
| 1190 | * 110 4/14/98 11:42a Chris |
| 1191 | * Added quirks and a better way of getting from idle to alert and from |
| 1192 | * alert to idle. |
| 1193 | * |
| 1194 | * 109 4/13/98 7:38p Chris |
| 1195 | * Added more support for a 'real' AI. |
| 1196 | * |
| 1197 | * 108 4/13/98 6:54p Chris |
| 1198 | * Improved the animation system. |
| 1199 | * |
| 1200 | * 107 4/13/98 2:20p Chris |
| 1201 | * IDLe works (kindof) |
| 1202 | * |
| 1203 | * 106 4/07/98 4:25p Chris |
| 1204 | * Added support for buddy bot |
| 1205 | * |
| 1206 | * 105 3/31/98 4:23p Chris |
| 1207 | * Added a new AIpath system |
| 1208 | * |
| 1209 | * 104 3/25/98 5:51p Chris |
| 1210 | * Added full model/body animations for weapon firing |
| 1211 | * |
| 1212 | * 103 3/25/98 11:02a Chris |
| 1213 | * version 1.0 of the new AI ranged firing code. |
| 1214 | * |
| 1215 | * 102 3/24/98 3:20p Chris |
| 1216 | * Improved local wb anim system |
| 1217 | * |
| 1218 | * 101 3/23/98 6:16p Chris |
| 1219 | * added some soar_helpers and some debug mprintf's |
| 1220 | * |
| 1221 | * 100 3/23/98 10:01a Chris |
| 1222 | * Added independant wb animations |
| 1223 | * |
| 1224 | * 99 3/17/98 11:27a Chris |
| 1225 | * Added object bump notifies for AI |
| 1226 | * |
| 1227 | * 98 3/13/98 5:55p Chris |
| 1228 | * Fixed problems with animations |
| 1229 | * |
| 1230 | * 97 3/12/98 7:30p Chris |
| 1231 | * Added ObjSetOrient |
| 1232 | * |
| 1233 | * 96 3/12/98 5:48p Chris |
| 1234 | * Fixed a bug in the animation cycle times |
| 1235 | * |
| 1236 | * 95 3/10/98 2:15p Chris |
| 1237 | * Made turrets with a zero angle fov usable to join sub-objects (for fire |
| 1238 | * animations) |
| 1239 | * |
| 1240 | * 94 3/10/98 12:51p Chris |
| 1241 | * Added a truely D2 style homing missile |
| 1242 | * |
| 1243 | * 93 3/05/98 11:34a Chris |
| 1244 | * Added the move_behind_object function |
| 1245 | * |
| 1246 | * 92 3/03/98 5:02p Chris |
| 1247 | * Added a status register to the ai_frame. Also, I enabled a bunch of |
| 1248 | * the fields from the AI Dialog. In addiition, I tweaked how melee |
| 1249 | * attacks work and animate. |
| 1250 | * |
| 1251 | * 91 3/02/98 6:52p Chris |
| 1252 | * Changed melee_dist to melee_damage |
| 1253 | * |
| 1254 | * 90 2/27/98 7:22p Chris |
| 1255 | * Started to add new AI fields -- no way near complete |
| 1256 | * |
| 1257 | * 89 2/20/98 3:24p Chris |
| 1258 | * |
| 1259 | * 88 2/19/98 6:16p Chris |
| 1260 | * Working on AI |
| 1261 | * |
| 1262 | * 87 2/18/98 8:42p Chris |
| 1263 | * Improving on the big object problem |
| 1264 | * |
| 1265 | * 86 2/18/98 4:47a Chris |
| 1266 | * |
| 1267 | * 85 2/18/98 4:38a Chris |
| 1268 | * |
| 1269 | * 84 2/18/98 4:37a Chris |
| 1270 | * |
| 1271 | * 83 2/18/98 4:18a Chris |
| 1272 | * |
| 1273 | * 82 2/18/98 4:13a Chris |
| 1274 | * |
| 1275 | * 81 2/18/98 4:05a Chris |
| 1276 | * |
| 1277 | * 80 2/17/98 11:31p Chris |
| 1278 | * |
| 1279 | * 79 2/17/98 4:24p Chris |
| 1280 | * Allow for simple walking robots |
| 1281 | * |
| 1282 | * 78 2/17/98 1:34p Chris |
| 1283 | * Improved timing of tear sound for melee |
| 1284 | * |
| 1285 | * 77 2/17/98 1:17p Chris |
| 1286 | * Improving the melee robots |
| 1287 | * |
| 1288 | * 76 2/17/98 1:05p Chris |
| 1289 | * Added in melee hit sound and effect |
| 1290 | * |
| 1291 | * 75 2/16/98 11:19p Chris |
| 1292 | * Added support for melee robots |
| 1293 | * |
| 1294 | * 74 2/16/98 4:56p Chris |
| 1295 | * Added melee attack support |
| 1296 | * |
| 1297 | * 73 2/16/98 3:50p Chris |
| 1298 | * Robots take melee swipes |
| 1299 | * |
| 1300 | * 72 2/16/98 1:05p Chris |
| 1301 | * Added some Flinch support |
| 1302 | * |
| 1303 | * 71 2/16/98 2:45a Chris |
| 1304 | * Massive improvements to the animation system and the AI |
| 1305 | * |
| 1306 | * 70 2/11/98 11:39a Chris |
| 1307 | * |
| 1308 | * 69 2/11/98 11:38a Chris |
| 1309 | * Added additional support to the beginning points on paths |
| 1310 | * |
| 1311 | * 68 2/11/98 11:06a Chris |
| 1312 | * Fixed the orient to node code. Thanks be to AI. |
| 1313 | * |
| 1314 | * 67 2/10/98 5:48p Chris |
| 1315 | * Improving the heuristic for when we update_next_path nodes. |
| 1316 | * |
| 1317 | * 66 2/10/98 4:45p Chris |
| 1318 | * Incremental changes: Made a new node_orient heuristic. Removed some |
| 1319 | * bad fields from the ai_info struct. |
| 1320 | * |
| 1321 | * 65 2/10/98 12:09a Chris |
| 1322 | * Improving the awareness system. Re-enabled super dodging. Added the |
| 1323 | * auto-fluctuate speed flag (allows some diversity). Enabled FOV |
| 1324 | * information. |
| 1325 | * |
| 1326 | * 64 2/06/98 5:51p Chris |
| 1327 | * Added the ability turn robots on and off |
| 1328 | * |
| 1329 | * 63 2/06/98 4:19p Chris |
| 1330 | * Added a boat load of path stuff |
| 1331 | * |
| 1332 | * 62 2/06/98 2:15a Chris |
| 1333 | * Activated the max_velocity, max_delta_velocity, and max_turn_rate |
| 1334 | * fields for AI objects. |
| 1335 | * |
| 1336 | * 61 2/05/98 6:55p Chris |
| 1337 | * Align orientation to path |
| 1338 | * |
| 1339 | * 60 2/04/98 6:09p Matt |
| 1340 | * Changed object room number to indicate a terrain cell via a flag. Got |
| 1341 | * rid of the object flag which used to indicate terrain. |
| 1342 | * |
| 1343 | * 59 2/03/98 6:33p Chris |
| 1344 | * Improving the path system |
| 1345 | * |
| 1346 | * 58 2/03/98 3:35p Chris |
| 1347 | * Added path support for AI and OSIRIS |
| 1348 | * |
| 1349 | * 57 2/02/98 8:15p Chris |
| 1350 | * Updated the AI system |
| 1351 | * |
| 1352 | * 56 2/02/98 11:06a Chris |
| 1353 | * |
| 1354 | * 55 1/30/98 4:09p Chris |
| 1355 | * |
| 1356 | * 54 1/30/98 4:07p Chris |
| 1357 | * |
| 1358 | * 53 1/30/98 3:42p Chris |
| 1359 | * Removed a bad memset (it zerod out static values) |
| 1360 | * |
| 1361 | * 52 1/30/98 2:19p Chris |
| 1362 | * More improvements (target vis stuff and setting of the AIN_ALWAYS_ON is |
| 1363 | * now done correctly) |
| 1364 | * |
| 1365 | * 51 1/29/98 3:29p Chris |
| 1366 | * Major update to the AI system. |
| 1367 | * |
| 1368 | * 50 1/21/98 3:54p Chris |
| 1369 | * |
| 1370 | * 49 1/20/98 4:40p Chris |
| 1371 | * Fixed some visability stuff. |
| 1372 | * |
| 1373 | * 48 1/20/98 12:21p Chris |
| 1374 | * Removed some printf's |
| 1375 | * |
| 1376 | * 47 1/20/98 11:34a Chris |
| 1377 | * Fixed problems with player visability and thus problems with awareness |
| 1378 | * |
| 1379 | * 46 1/19/98 10:04a Matt |
| 1380 | * Added new object handle system |
| 1381 | * |
| 1382 | * 45 1/14/98 7:58p Chris |
| 1383 | * |
| 1384 | * 44 12/09/97 2:48p Chris |
| 1385 | * Temporary less dodgy bots |
| 1386 | * |
| 1387 | * 43 11/24/97 4:12p Chris |
| 1388 | * Cleaner code |
| 1389 | * |
| 1390 | * 42 11/24/97 10:17a Chris |
| 1391 | * Handles dead, dying, and cloaked players |
| 1392 | * |
| 1393 | * 41 11/21/97 3:05p Chris |
| 1394 | * Robots will not fired at the player after he is dead. |
| 1395 | * |
| 1396 | * 40 11/21/97 1:14p Chris |
| 1397 | * Improved hueristic for robot firing. |
| 1398 | * |
| 1399 | * 39 11/17/97 9:48p Chris |
| 1400 | * Added some guarding |
| 1401 | * |
| 1402 | * 38 11/17/97 6:01p Chris |
| 1403 | * thief update |
| 1404 | * |
| 1405 | * 37 11/17/97 5:59p Chris |
| 1406 | * Allowed some thief stuff |
| 1407 | * |
| 1408 | * 36 11/17/97 5:46p Chris |
| 1409 | * Added some support for a Theif-like robot |
| 1410 | * |
| 1411 | * 35 11/15/97 6:39p Chris |
| 1412 | * Made robot firing signifantly less CPU costly. But, turrets are now |
| 1413 | * more choppy moving. |
| 1414 | * |
| 1415 | * 34 11/14/97 11:55p Chris |
| 1416 | * Dodge goals are semi-functional |
| 1417 | * |
| 1418 | * 33 11/13/97 3:56p Chris |
| 1419 | * Evading a little more random |
| 1420 | * |
| 1421 | * 32 11/13/97 3:34p Chris |
| 1422 | * Improved AI |
| 1423 | * |
| 1424 | * 31 11/12/97 5:47p Chris |
| 1425 | * Incremental improvements |
| 1426 | * |
| 1427 | * 30 11/12/97 10:43a Chris |
| 1428 | * Incremental |
| 1429 | * |
| 1430 | * 29 11/11/97 12:22p Chris |
| 1431 | * Incremental improvements |
| 1432 | * |
| 1433 | * 28 11/06/97 12:47p Chris |
| 1434 | * Some new incremental stuff |
| 1435 | * |
| 1436 | * 27 11/04/97 6:20p Chris |
| 1437 | * Added some incremental improvements |
| 1438 | * |
| 1439 | * 26 10/28/97 12:25p Chris |
| 1440 | * Added support for initial class, type, and movement types. Starting to |
| 1441 | * flush out the AI structure |
| 1442 | * |
| 1443 | * 25 9/23/97 5:47p Jason |
| 1444 | * return if "animation system not done" message is printed |
| 1445 | * |
| 1446 | * 24 9/18/97 1:27p Matt |
| 1447 | * Cleaned up object struct |
| 1448 | * |
| 1449 | * 23 9/17/97 11:31a Chris |
| 1450 | * |
| 1451 | * 22 9/15/97 4:07p Chris |
| 1452 | * AI only fires if you are in the same render as they are. |
| 1453 | * |
| 1454 | * 21 9/10/97 1:24p Chris |
| 1455 | * Fixed a bug with the wb firing masks |
| 1456 | * |
| 1457 | * 20 9/10/97 12:56p Chris |
| 1458 | * Added more support for weapon batteries |
| 1459 | * |
| 1460 | * 19 9/08/97 11:50a Chris |
| 1461 | * Added support for entering seconds-per-cycle animation information |
| 1462 | * |
| 1463 | * 18 9/05/97 8:52p Chris |
| 1464 | * Furthered the weapon bank support |
| 1465 | * |
| 1466 | * 17 9/04/97 3:50p Chris |
| 1467 | * Added new turret support |
| 1468 | * |
| 1469 | * 16 9/03/97 2:12p Chris |
| 1470 | * Added new weapon battery system and made the animation system usable. |
| 1471 | * |
| 1472 | * 15 8/20/97 3:13p Chris |
| 1473 | * |
| 1474 | * 14 8/11/97 1:53p Matt |
| 1475 | * Ripped out robot & powerup pages, and added generic page |
| 1476 | * |
| 1477 | * 13 8/06/97 1:35p Matt |
| 1478 | * Changes for new generic object_info struct which replace robot-specific |
| 1479 | * structure |
| 1480 | * |
| 1481 | * 12 8/05/97 12:29p Chris |
| 1482 | * |
| 1483 | * 11 7/30/97 4:10p Chris |
| 1484 | * Made test bot more interesting. |
| 1485 | * |
| 1486 | * 10 7/30/97 1:31p Chris |
| 1487 | * Made helicopters slightly more interesting. |
| 1488 | * |
| 1489 | * 9 7/29/97 12:20p Chris |
| 1490 | * Incremental improvements. Fixed a memory bug. |
| 1491 | * |
| 1492 | * 8 7/28/97 1:19p Chris |
| 1493 | * Expanding the AI system |
| 1494 | * |
| 1495 | * 7 7/16/97 5:15p Chris |
| 1496 | * Fixed use of updating 3d sounds |
| 1497 | * |
| 1498 | * 6 7/15/97 7:29p Chris |
| 1499 | * Added a sound for helicopter blades. |
| 1500 | * |
| 1501 | * 5 7/15/97 5:35p Chris |
| 1502 | * New AI code |
| 1503 | * |
| 1504 | * 4 7/15/97 4:59p Chris |
| 1505 | * added support for AI and animations |
| 1506 | * |
| 1507 | * $NoKeywords: $ |
| 1508 | */ |
| 1509 | |
| 1510 | #include <stdlib.h> |
| 1511 | #include "AIMain.h" |
| 1512 | #include "mono.h" |
| 1513 | #include "game.h" |
| 1514 | #include "weapon.h" |
| 1515 | #include "findintersection.h" |
| 1516 | #include "vecmat.h" |
| 1517 | #include "AIGoal.h" |
| 1518 | #include "terrain.h" |
| 1519 | #include "hlsoundlib.h" |
| 1520 | #include "sounds.h" |
| 1521 | #include "aiterrain.h" |
| 1522 | #include "weapon.h" |
| 1523 | #include "objinfo.h" |
| 1524 | #include "polymodel.h" |
| 1525 | #include "robotfire.h" |
| 1526 | #include "BOA.h" |
| 1527 | #include "player.h" |
| 1528 | #include "memory.h" |
| 1529 | #include "gamepath.h" |
| 1530 | #include "soundload.h" |
| 1531 | #include "damage.h" |
| 1532 | #include "aipath.h" |
| 1533 | #include "robot.h" |
| 1534 | #include "attach.h" |
| 1535 | #include "demofile.h" |
| 1536 | #include "matcen.h" |
| 1537 | #include "physics.h" |
| 1538 | #include "difficulty.h" |
| 1539 | #include "osiris_dll.h" |
| 1540 | #include "multi.h" |
| 1541 | #include "gamecinematics.h" |
| 1542 | #include "room.h" |
| 1543 | #include "psrand.h" |
| 1544 | #include "gametexture.h" |
| 1545 | #include "difficulty.h" |
| 1546 | |
| 1547 | // Define's |
| 1548 | #define MAX_SEE_TARGET_DIST 500.0f |
| 1549 | #define MAX_TRACK_TARGET_DIST 800.0f |
| 1550 | #define MIN_VIS_RECENT_CHECK_INTERVAL 0.35f |
| 1551 | #define MIN_VIS_CHECK_INTERVAL 0.15f |
| 1552 | #define CHECK_VIS_INFREQUENTLY_TIME 7.0f |
| 1553 | #define CHECK_VIS_INFREQUENTLY_INTERVAL 2.0f |
| 1554 | |
| 1555 | #define MIN_TARGET_UPDATE_INTERVAL 2.0f |
| 1556 | #define MAX_TARGET_UPDATE_INTERVAL 4.5f |
| 1557 | |
| 1558 | float AI_last_time_room_noise_alert_time[MAX_ROOMS + 8]; |
| 1559 | int AI_unique_goal_id = 0; |
| 1560 | |
| 1561 | #ifdef _DEBUG |
| 1562 | bool AI_debug_robot_do = false; |
| 1563 | int AI_debug_robot_index = -2; |
| 1564 | #endif |
| 1565 | |
| 1566 | static bool compute_dodge_dir(/* vector *dodge_dir, */ object *obj, object *dodge_obj); |
| 1567 | static float AIDetermineObjVisLevel(object *obj, object *target); |
| 1568 | static bool move_relative_object_vec(object *obj, vector *vec, object *target, float circle_dist, float scalar, |
| 1569 | bool f_toward, vector *mdir, bool *f_moved); |
| 1570 | static void move_away_from_position(object *obj, vector *pos /*, bool random_evade*/, float scale, vector *mdir, |
| 1571 | bool *f_moved); |
| 1572 | static bool goal_do_dodge(object *obj, int goal_index); |
| 1573 | static bool goal_do_avoid_walls(object *obj, vector *mdir); |
| 1574 | static bool MeleeHitOk(object *obj); |
| 1575 | static bool AiMelee(object *obj); |
| 1576 | static void do_ranged_attack(object *obj); |
| 1577 | static bool AIDetermineAimPoint(object *robot, object *target, vector *aim_pt, float weapon_speed = 0.0f); |
| 1578 | static vector *AIDetermineFovVec(object *obj, vector *fov); |
| 1579 | static void AISeeTarget(object *obj, bool f_see); |
| 1580 | static void ai_do_animation(object *obj, float anim_time); |
| 1581 | static void ObjSetAIInfo(object *objp); |
| 1582 | static void AICheckTargetVis(object *obj); |
| 1583 | static void ai_update_registers(object *obj); |
| 1584 | static bool AiGoalAvoid(vector *adir, object *obj, object *a_obj, float dist); |
| 1585 | static void AIGoalDoRepulse(object *obj, float dist, vector *dir, goal *goal, vector *mdir); |
| 1586 | static void AIGoalDoCohesion(object *obj, object *g_obj, float dist, goal *goal, vector *mdir); |
| 1587 | static void AIGoalDoAlignment(object *obj, float dist, vector *fvec, goal *goal, vector *mdir); |
| 1588 | static void AIDoTrackFrame(object *obj); |
| 1589 | static void AIDoOrientVelocity(object *obj); |
| 1590 | static void AIDoOrientDefault(object *obj); |
| 1591 | static void AIDoOrient(object *obj, int g_index); |
| 1592 | static void AIDetermineSpeed(object *obj, int flags, float *speed); |
| 1593 | static void ai_move(object *obj); |
| 1594 | static void ai_fire(object *obj); |
| 1595 | static int AIGetTeam(object *obj); |
| 1596 | static void AITargetCheck(object *obj, object *target, object **best_obj, float *best_dot, float *best_dist); |
| 1597 | static void AIDetermineTarget(object *obj); |
| 1598 | static void AIDoFreud(object *obj); |
| 1599 | static void AIDoMemFrame(object *obj); |
| 1600 | |
| 1601 | // chrishack -- AI problems |
| 1602 | |
| 1603 | // first frame problems: |
| 1604 | // If a robot has an initial velocity it might fly off because of excessive Frametime of the first frame |
| 1605 | // If a player fires on the first frame, robots will not know |
| 1606 | |
| 1607 | // Inside walkers will suck resources |
| 1608 | |
| 1609 | const char *const Ai_class_strings[MAX_AI_INIT_CLASSES] = {"Static", "Pure Path", "Fully AIS"}; |
| 1610 | |
| 1611 | const char *const Ai_type_strings[MAX_AI_INIT_TYPES] = { |
| 1612 | "Fly Lander", "Stalker", "Evader 1", "Evader 2", "Stationary Turret", "AIS", "Melee1", "Bird Flock 1", "Herd 1"}; |
| 1613 | |
| 1614 | const char *const Ai_movement_type_strings[MAX_AI_INIT_MOVEMENT_TYPES] = {"Standing", "Flying", "Rolling", "Walking"}; |
| 1615 | |
| 1616 | // AI Movement flying types |
| 1617 | const char *const Ai_movement_subtype_flying_strings[MAX_AI_INIT_MOVEMENT_SUBTYPES] = { |
| 1618 | "Normal", "Path", "Helicopter", "Hovercraft", "Jet", "Player", "Buddy"}; |
| 1619 | |
| 1620 | // AI Movement walking types |
| 1621 | |
| 1622 | const char *const Ai_movement_subtype_walking_strings[MAX_AI_INIT_MOVEMENT_SUBTYPES] = { |
| 1623 | "Restricted Flat", "Restricted Low-angle", "Restricted High_angle", "Non-restricted", "Water Only", "", ""}; |
| 1624 | |
| 1625 | #define AI_MAX_MELEE_RANGE 5.0f |
| 1626 | |
| 1627 | int AI_NumRendered; |
| 1628 | int AI_RenderedList[MAX_OBJECTS]; |
| 1629 | |
| 1630 | int AI_NumHostileAlert = 0; |
| 1631 | |
| 1632 | int Buddy_handle[MAX_PLAYERS]; |
| 1633 | |
| 1634 | static int AI_FriendNumNear = 0; // Number of friends found |
| 1635 | static object *AI_FriendObj[2]; // Friend objects |
| 1636 | static float AI_FriendDist[2]; // Distances to the friends |
| 1637 | static vector AI_FriendDir[2]; // Direction to the friends |
| 1638 | static int AI_EnemyNumNear = 0; // Number of enemies found |
| 1639 | static object *AI_EnemyObj[2]; // Enemy objects |
| 1640 | static float AI_EnemyDist[2]; // Distances to the enemies |
| 1641 | static vector AI_EnemyDir[2]; // Direction to the enemies |
| 1642 | |
| 1643 | #define AIVIS_NONE 0.0f |
| 1644 | #define AIVIS_BARELY 1.0f |
| 1645 | #define AIVIS_MOSTLY 2.0f |
| 1646 | #define AIVIS_FULL 3.0f |
| 1647 | |
| 1648 | // Allows the vis sliders to work |
| 1649 | float AIDetermineObjVisLevel(object *obj, object *target) { |
| 1650 | float vis_level = AIVIS_FULL; |
| 1651 | |
| 1652 | if (target == NULL) |
| 1653 | return AIVIS_NONE; |
| 1654 | |
| 1655 | if ((target->effect_info) && (target->effect_info->type_flags & EF_CLOAKED)) { |
| 1656 | vis_level = AIVIS_NONE; |
| 1657 | |
| 1658 | if (target->type == OBJ_PLAYER && (Players[target->id].flags & PLAYER_FLAGS_AFTERBURN_ON)) { |
| 1659 | vis_level += 1.0f; |
| 1660 | } |
| 1661 | |
| 1662 | if (target->type == OBJ_PLAYER && (Players[target->id].flags & PLAYER_FLAGS_HEADLIGHT)) { |
| 1663 | vector from_target = obj->pos - target->pos; |
| 1664 | vm_NormalizeVector(&from_target); |
| 1665 | |
| 1666 | if ((target->orient.fvec) * (from_target) > 0.965f) { |
| 1667 | vis_level += 1.0f; |
| 1668 | } |
| 1669 | } |
| 1670 | } |
| 1671 | |
| 1672 | if ((target->effect_info) && (target->effect_info->type_flags & EF_NAPALMED)) { |
| 1673 | vis_level += 1.75; |
| 1674 | } |
| 1675 | |
| 1676 | if (vis_level < AIVIS_NONE) |
| 1677 | vis_level = AIVIS_NONE; |
| 1678 | else if (vis_level > AIVIS_FULL) |
| 1679 | vis_level = AIVIS_FULL; |
| 1680 | |
| 1681 | return vis_level; |
| 1682 | } |
| 1683 | |
| 1684 | static inline bool ai_target_valid(object *obj) { |
| 1685 | ai_frame *ai_info = obj->ai_info; |
| 1686 | bool f_valid = false; |
| 1687 | |
| 1688 | if (ai_info->target_handle != OBJECT_HANDLE_NONE) { |
| 1689 | if (ObjGet(ai_info->target_handle)) |
| 1690 | f_valid = true; |
| 1691 | else { |
| 1692 | AINotify(obj, AIN_TARGET_DIED, (void *)&ai_info->target_handle); |
| 1693 | ai_info->target_handle = OBJECT_HANDLE_NONE; |
| 1694 | } |
| 1695 | } |
| 1696 | |
| 1697 | return f_valid; |
| 1698 | } |
| 1699 | |
| 1700 | bool AISetTarget(object *obj, int handle) { |
| 1701 | ai_frame *ai_info = obj->ai_info; |
| 1702 | |
| 1703 | ai_info->target_handle = handle; |
| 1704 | if (handle == OBJECT_HANDLE_NONE) |
| 1705 | ai_info->last_see_target_pos = obj->pos; |
| 1706 | |
| 1707 | return ai_target_valid(obj); |
| 1708 | } |
| 1709 | |
| 1710 | // Note ASSUMES that dir is normalized |
| 1711 | void AIMoveTowardsDir(object *obj, vector *dir, float scale) { |
| 1712 | physics_info *phys_info = &obj->mtype.phys_info; |
| 1713 | vector goal_velocity; |
| 1714 | vector vel_diff; |
| 1715 | float delta_vel; |
| 1716 | float max_delta_vel; |
| 1717 | ai_frame *ai_info = obj->ai_info; |
| 1718 | float acc_scale; |
| 1719 | |
| 1720 | if (scale < 1.0f) |
| 1721 | acc_scale = 1.0f; |
| 1722 | else |
| 1723 | acc_scale = scale; |
| 1724 | |
| 1725 | goal_velocity = *dir * ai_info->max_velocity * scale; |
| 1726 | |
| 1727 | vel_diff = goal_velocity - phys_info->velocity; |
| 1728 | delta_vel = vm_NormalizeVector(&vel_diff); |
| 1729 | |
| 1730 | max_delta_vel = Frametime * ai_info->max_delta_velocity * acc_scale; |
| 1731 | |
| 1732 | if (delta_vel > max_delta_vel) { |
| 1733 | phys_info->velocity += (vel_diff * max_delta_vel); |
| 1734 | } else { |
| 1735 | phys_info->velocity = goal_velocity; |
| 1736 | } |
| 1737 | } |
| 1738 | |
| 1739 | bool AIMoveTowardsPosition(object *obj, /*velocity *new_vel,*/ vector *pos, float scale, bool stop_at_end_point, |
| 1740 | vector *mdir, bool *f_moved) { |
| 1741 | vector dir; |
| 1742 | float distance; |
| 1743 | ai_frame *ai_info = obj->ai_info; |
| 1744 | float acc_scale; |
| 1745 | |
| 1746 | if (scale < 1.0f) |
| 1747 | acc_scale = 1.0f; |
| 1748 | else |
| 1749 | acc_scale = scale; |
| 1750 | |
| 1751 | if (stop_at_end_point) { |
| 1752 | if (vm_VectorDistance(pos, &obj->pos) <= .2f) { |
| 1753 | obj->mtype.phys_info.velocity = Zero_vector; |
| 1754 | *f_moved = true; |
| 1755 | return true; |
| 1756 | } |
| 1757 | |
| 1758 | float s_to_stop = (ai_info->max_velocity * scale) / (ai_info->max_delta_velocity * acc_scale); |
| 1759 | float d_to_stop = ai_info->max_velocity * scale * s_to_stop; |
| 1760 | |
| 1761 | dir = *pos - obj->pos; |
| 1762 | float d_to_target = vm_NormalizeVector(&dir); |
| 1763 | if (d_to_target < d_to_stop) { |
| 1764 | float speed = ai_info->max_velocity * scale * (d_to_target / d_to_stop); |
| 1765 | |
| 1766 | if (d_to_target <= speed * Frametime) { |
| 1767 | obj->mtype.phys_info.velocity = ((d_to_target / Frametime) + .09f) * dir; |
| 1768 | } else { |
| 1769 | obj->mtype.phys_info.velocity = dir * (speed + .1f); |
| 1770 | } |
| 1771 | |
| 1772 | *f_moved = true; |
| 1773 | return false; |
| 1774 | } |
| 1775 | } |
| 1776 | |
| 1777 | if (*pos == obj->pos) { |
| 1778 | physics_info *phys_info = &obj->mtype.phys_info; |
| 1779 | |
| 1780 | if (phys_info->velocity != Zero_vector) { |
| 1781 | vector vel_diff = -phys_info->velocity; |
| 1782 | float delta_vel = vm_NormalizeVector(&vel_diff); |
| 1783 | float max_delta_vel = Frametime * ai_info->max_delta_velocity * acc_scale; |
| 1784 | |
| 1785 | if (delta_vel > max_delta_vel) { |
| 1786 | phys_info->velocity += (vel_diff * max_delta_vel); |
| 1787 | } else { |
| 1788 | vm_MakeZero(&phys_info->velocity); |
| 1789 | } |
| 1790 | } |
| 1791 | |
| 1792 | *f_moved = true; |
| 1793 | return false; |
| 1794 | } else { |
| 1795 | dir = *pos - obj->pos; |
| 1796 | distance = vm_NormalizeVector(&dir); |
| 1797 | } |
| 1798 | |
| 1799 | *mdir = dir; |
| 1800 | *f_moved = false; |
| 1801 | |
| 1802 | // AIMoveTowardsDir(obj, &dir); |
| 1803 | return false; |
| 1804 | } |
| 1805 | |
| 1806 | bool move_relative_object_vec(object *obj, vector *vec, object *target, float circle_dist, float scalar, bool f_toward, |
| 1807 | vector *mdir, bool *f_moved) { |
| 1808 | // Getting behind an object is a 2 step process: Get to the side and then get behind. |
| 1809 | vector from_target; |
| 1810 | vector opposite_fvec; |
| 1811 | vector goal_pos; |
| 1812 | ai_frame *ai_info = obj->ai_info; |
| 1813 | bool f_done = false; |
| 1814 | |
| 1815 | from_target = obj->pos - target->pos; |
| 1816 | |
| 1817 | if (f_toward) { |
| 1818 | opposite_fvec = -(*vec); |
| 1819 | } else { |
| 1820 | opposite_fvec = *vec; |
| 1821 | } |
| 1822 | |
| 1823 | if (from_target * opposite_fvec > 0.0f) { |
| 1824 | // I am currently on the side of the object that I do not want to be on |
| 1825 | vector goal_dir; |
| 1826 | vector vec_to_plane; |
| 1827 | vector normal_component; |
| 1828 | vector plane_component; |
| 1829 | |
| 1830 | vec_to_plane = obj->pos - target->pos; |
| 1831 | normal_component = opposite_fvec * (opposite_fvec * vec_to_plane); |
| 1832 | plane_component = vec_to_plane - normal_component; |
| 1833 | |
| 1834 | if (plane_component == Zero_vector) { |
| 1835 | goal_dir = target->orient.rvec; |
| 1836 | } else { |
| 1837 | goal_dir = plane_component; |
| 1838 | vm_NormalizeVector(&goal_dir); |
| 1839 | } |
| 1840 | |
| 1841 | goal_pos = target->pos + goal_dir * (obj->size + target->size + circle_dist); |
| 1842 | } else { |
| 1843 | // else, I am going to get behind/in-front the object |
| 1844 | goal_pos = target->pos - (opposite_fvec * (obj->size + target->size + circle_dist)); |
| 1845 | if (vm_VectorDistance(&goal_pos, &obj->pos) < obj->size) { |
| 1846 | f_done = true; |
| 1847 | } |
| 1848 | } |
| 1849 | |
| 1850 | AIMoveTowardsPosition(obj, &goal_pos, scalar, false, mdir, f_moved); |
| 1851 | return f_done; |
| 1852 | } |
| 1853 | |
| 1854 | void move_away_from_position(object *obj, vector *pos /*, bool random_evade*/, float scale, vector *mdir, |
| 1855 | bool *f_moved) { |
| 1856 | vector dir; |
| 1857 | float distance; |
| 1858 | |
| 1859 | // Reverse of move towards |
| 1860 | dir = obj->pos - *pos; |
| 1861 | distance = vm_NormalizeVector(&dir); |
| 1862 | |
| 1863 | // AIMoveTowardsDir(obj, &dir, scale); |
| 1864 | *mdir = dir; |
| 1865 | *f_moved = false; |
| 1866 | } |
| 1867 | |
| 1868 | #define NO_DODGE_SIZE_MULTIPLIER 2.0f |
| 1869 | #define MIN_DODGE_DIST 5.0f |
| 1870 | |
| 1871 | #define MAX_DODGE_INFLUENCE 10.0f |
| 1872 | #define MIN_DODGE_INFLUENCE 2.5f // Just less than max avoiding fiends |
| 1873 | |
| 1874 | // returns false if no dodge is necessary |
| 1875 | bool compute_dodge_dir(vector *movement_dir, object *obj, object *dodge_obj) { |
| 1876 | vector vec_to_obj = obj->pos - dodge_obj->pos; |
| 1877 | vector dodge_vec; |
| 1878 | vector dobj_motion = dodge_obj->mtype.phys_info.velocity; |
| 1879 | vm_NormalizeVector(&dobj_motion); |
| 1880 | |
| 1881 | float closest_dist; |
| 1882 | |
| 1883 | float p; |
| 1884 | |
| 1885 | float max_dodge_dist = obj->size * NO_DODGE_SIZE_MULTIPLIER + dodge_obj->size; |
| 1886 | if (max_dodge_dist < MIN_DODGE_DIST) { |
| 1887 | max_dodge_dist = MIN_DODGE_DIST; |
| 1888 | } |
| 1889 | |
| 1890 | if (IS_GUIDEBOT(obj)) { |
| 1891 | max_dodge_dist += 10.0f; |
| 1892 | } |
| 1893 | |
| 1894 | vector dpoint; |
| 1895 | |
| 1896 | p = dobj_motion * vec_to_obj; |
| 1897 | |
| 1898 | if (p <= 0.0) |
| 1899 | return false; |
| 1900 | |
| 1901 | dpoint = dodge_obj->pos + (p * dobj_motion); |
| 1902 | |
| 1903 | dodge_vec = obj->pos - dpoint; |
| 1904 | closest_dist = vm_NormalizeVector(&dodge_vec); |
| 1905 | |
| 1906 | if (closest_dist > max_dodge_dist) |
| 1907 | return false; |
| 1908 | if (closest_dist == 0.0) |
| 1909 | dodge_vec = obj->orient.rvec; |
| 1910 | |
| 1911 | // CHRISHACK -- Use the MIN/MAX INFLUENCE and INFLUENCE RAMP |
| 1912 | float scale = MAX_DODGE_INFLUENCE * ((max_dodge_dist - closest_dist) / max_dodge_dist); |
| 1913 | if (scale < MIN_DODGE_INFLUENCE) { |
| 1914 | scale = MIN_DODGE_INFLUENCE; |
| 1915 | } |
| 1916 | |
| 1917 | if (IS_GUIDEBOT(obj)) { |
| 1918 | scale *= 20.0f; |
| 1919 | } |
| 1920 | |
| 1921 | dodge_vec *= scale; |
| 1922 | |
| 1923 | if (dodge_vec != Zero_vector && (obj->ai_info->dodge_till_time < Gametime || |
| 1924 | vm_GetMagnitude(&dodge_vec) > vm_GetMagnitude(&obj->ai_info->last_dodge_dir))) { |
| 1925 | obj->ai_info->last_dodge_dir = dodge_vec; |
| 1926 | } |
| 1927 | |
| 1928 | obj->ai_info->dodge_till_time = |
| 1929 | Gametime + ((float)ps_rand() / (float)D3_RAND_MAX) * (3.0f * obj->ai_info->life_preservation) + 1.0f; |
| 1930 | |
| 1931 | *movement_dir += dodge_vec; |
| 1932 | |
| 1933 | return true; |
| 1934 | } |
| 1935 | |
| 1936 | bool goal_do_dodge(object *obj, int goal_index) { |
| 1937 | ai_frame *ai_info = obj->ai_info; |
| 1938 | object *other_obj = ObjGet(ai_info->goals[goal_index].g_info.handle); |
| 1939 | int reason = AIN_GOAL_COMPLETE; |
| 1940 | |
| 1941 | if (other_obj) { |
| 1942 | if (compute_dodge_dir(&ai_info->movement_dir, obj, other_obj)) { |
| 1943 | return true; |
| 1944 | } |
| 1945 | } else { |
| 1946 | reason = AIN_GOAL_INVALID; |
| 1947 | } |
| 1948 | |
| 1949 | GoalClearGoal(obj, &ai_info->goals[goal_index], reason); |
| 1950 | return false; |
| 1951 | } |
| 1952 | |
| 1953 | #define MAX_WALL_AVOID_INFLUENCE 0.9f |
| 1954 | #define MAX_TERRAIN_AVOID_INFLUENCE 0.9f |
| 1955 | #define GB_WALL_PULSE_INTERVAL 7 |
| 1956 | |
| 1957 | bool goal_do_avoid_walls(object *obj, vector *mdir) { |
| 1958 | fvi_face_room_list facelist[200]; |
| 1959 | int num_faces; |
| 1960 | float rad; |
| 1961 | int i; |
| 1962 | vector awall_dir = Zero_vector; |
| 1963 | float closest_dist; |
| 1964 | vector pos; |
| 1965 | bool f_danger = false; |
| 1966 | |
| 1967 | float wall_size = Poly_models[obj->rtype.pobj_info.model_num].wall_size; |
| 1968 | |
| 1969 | if (IS_GUIDEBOT(obj)) { |
| 1970 | rad = 10.0f; |
| 1971 | } else { |
| 1972 | if (wall_size < 7.0f) |
| 1973 | rad = wall_size + 2.2f; |
| 1974 | else |
| 1975 | rad = wall_size + 1.0f; |
| 1976 | } |
| 1977 | |
| 1978 | pos = obj->pos + obj->wall_sphere_offset; |
| 1979 | |
| 1980 | closest_dist = rad + 1.0f; |
| 1981 | |
| 1982 | if (obj->mtype.phys_info.velocity == Zero_vector) { |
| 1983 | return false; |
| 1984 | } |
| 1985 | |
| 1986 | if (!ROOMNUM_OUTSIDE(obj->roomnum)) { |
| 1987 | num_faces = fvi_QuickDistFaceList(obj->roomnum, &pos, rad, facelist, 200); |
| 1988 | |
| 1989 | for (i = 0; i < num_faces; i++) { |
| 1990 | room *rp = &Rooms[facelist[i].room_index]; |
| 1991 | face *fp = &rp->faces[facelist[i].face_index]; |
| 1992 | |
| 1993 | int face_info = GetFacePhysicsFlags(rp, fp); |
| 1994 | if (!(face_info & FPF_SOLID)) |
| 1995 | continue; |
| 1996 | |
| 1997 | vector fpnt = rp->verts[fp->face_verts[0]]; |
| 1998 | |
| 1999 | // Ignore backfaces |
| 2000 | if ((pos - fpnt) * fp->normal > 0.0f) { |
| 2001 | float dist = vm_DistToPlane(&pos, &fp->normal, &fpnt); |
| 2002 | |
| 2003 | if (dist < rad) { |
| 2004 | vector pnt_on_face = pos - (dist * fp->normal); |
| 2005 | vector *vertex_ptr_list[MAX_VERTS_PER_FACE]; |
| 2006 | int j; |
| 2007 | |
| 2008 | for (j = 0; j < fp->num_verts; j++) { |
| 2009 | vertex_ptr_list[j] = &rp->verts[fp->face_verts[j]]; |
| 2010 | } |
| 2011 | |
| 2012 | int edgemask = check_point_to_face(&pnt_on_face, &fp->normal, fp->num_verts, vertex_ptr_list); |
| 2013 | |
| 2014 | if (edgemask == 0) { |
| 2015 | float scale = 1.0f - ((dist - wall_size * .5f) / (rad - wall_size * .5f)); |
| 2016 | if (scale < 0.0) |
| 2017 | scale = 0.0f; |
| 2018 | else if (scale > 1.0f) |
| 2019 | scale = 1.0f; |
| 2020 | |
| 2021 | awall_dir += (scale * fp->normal); |
| 2022 | |
| 2023 | // mprintf(0, "%d\n", facelist[i].face_index); |
| 2024 | if (GameTextures[fp->tmap].flags & (TF_VOLATILE | TF_FORCEFIELD | TF_LAVA)) { |
| 2025 | if (!(fp->portal_num >= 0 && !(rp->portals[fp->portal_num].flags & PF_RENDER_FACES))) { |
| 2026 | f_danger = true; |
| 2027 | } |
| 2028 | } |
| 2029 | |
| 2030 | // mprintf(0, "Dist %f %f (%d, %d)\n", dist, scale, facelist[i].room_index, facelist[i].face_index)); |
| 2031 | |
| 2032 | if (dist < closest_dist) { |
| 2033 | closest_dist = dist; |
| 2034 | } |
| 2035 | } |
| 2036 | } |
| 2037 | } |
| 2038 | } |
| 2039 | } else { |
| 2040 | int num_cells; |
| 2041 | int cell_list[100]; |
| 2042 | |
| 2043 | num_cells = fvi_QuickDistCellList(CELLNUM(obj->roomnum), &pos, rad, cell_list, 100); |
| 2044 | |
| 2045 | for (i = 0; i < num_cells; i++) { |
| 2046 | const int cur_node = cell_list[i]; |
| 2047 | terrain_segment *tseg = &Terrain_seg[cur_node]; |
| 2048 | |
| 2049 | vector fpnt; |
| 2050 | ComputeTerrainSegmentCenter(&fpnt, cur_node); |
| 2051 | |
| 2052 | vector normal = |
| 2053 | TerrainNormals[MAX_TERRAIN_LOD - 1][cur_node].normal1 + TerrainNormals[MAX_TERRAIN_LOD - 1][cur_node].normal2; |
| 2054 | vm_NormalizeVector(&normal); |
| 2055 | |
| 2056 | if (obj->mtype.phys_info.velocity * normal <= 0.0f) { |
| 2057 | vector no_y_vec = pos - fpnt; |
| 2058 | no_y_vec.y = 0.0f; |
| 2059 | |
| 2060 | float dist; |
| 2061 | |
| 2062 | dist = vm_NormalizeVector(&no_y_vec); |
| 2063 | |
| 2064 | if (dist <= rad) { |
| 2065 | awall_dir += ((1.0f - (dist / rad)) * normal); |
| 2066 | |
| 2067 | if (GameTextures[Terrain_tex_seg[tseg->texseg_index].tex_index].flags & |
| 2068 | (TF_VOLATILE | TF_FORCEFIELD | TF_LAVA)) { |
| 2069 | #ifdef _DEBUG |
| 2070 | if (AI_debug_robot_do && OBJNUM(obj) == AI_debug_robot_index) { |
| 2071 | mprintf(0, "AI Note: Danger - NEAR FORCEFIELD, VOLATILE, OR LAVA\n"); |
| 2072 | } |
| 2073 | #endif |
| 2074 | f_danger = true; |
| 2075 | } |
| 2076 | |
| 2077 | if (dist < closest_dist) { |
| 2078 | closest_dist = dist; |
| 2079 | } |
| 2080 | } |
| 2081 | } |
| 2082 | } |
| 2083 | } |
| 2084 | |
| 2085 | if (closest_dist <= rad) { |
| 2086 | vm_NormalizeVector(&awall_dir); |
| 2087 | |
| 2088 | float max_influence = (ROOMNUM_OUTSIDE(obj->roomnum)) ? MAX_TERRAIN_AVOID_INFLUENCE : MAX_WALL_AVOID_INFLUENCE; |
| 2089 | if (f_danger) { |
| 2090 | max_influence *= 7.1f; |
| 2091 | } |
| 2092 | |
| 2093 | float scale = (1.0f - ((closest_dist - wall_size) / (rad - wall_size))) * max_influence; |
| 2094 | if (scale > max_influence) |
| 2095 | scale = max_influence; |
| 2096 | *mdir += scale * awall_dir; |
| 2097 | |
| 2098 | if (IS_GUIDEBOT(obj) && closest_dist < 8.0f) { |
| 2099 | int test_time = Gametime; |
| 2100 | |
| 2101 | if ((test_time % GB_WALL_PULSE_INTERVAL) == 0) { |
| 2102 | *mdir *= 10.0f; |
| 2103 | } |
| 2104 | } |
| 2105 | |
| 2106 | #ifdef _DEBUG |
| 2107 | if (AI_debug_robot_do && OBJNUM(obj) == AI_debug_robot_index) { |
| 2108 | mprintf(0, "AI Note: Avoid wall %f\n", scale); |
| 2109 | } |
| 2110 | #endif |
| 2111 | |
| 2112 | return true; |
| 2113 | } |
| 2114 | |
| 2115 | return false; |
| 2116 | } |
| 2117 | |
| 2118 | #define ONE_DEGREE_ARC_COS 0.99985f |
| 2119 | #define FIVE_DEGREE_ARC_COS 0.9962f |
| 2120 | |
| 2121 | // NOTE: Assumes that the vector is normalized |
| 2122 | void AITurnTowardsDir(object *obj, /*velocity *new_vel,*/ vector *goal_dir /*, bool remain_level*/, float turn_rate) { |
| 2123 | vector u_axis; |
| 2124 | matrix rot_matrix; |
| 2125 | angle goal_angle; |
| 2126 | float max_angle; |
| 2127 | |
| 2128 | matrix saved_orient = obj->orient; |
| 2129 | vector saved_uvec = obj->orient.uvec; |
| 2130 | |
| 2131 | if (*goal_dir == Zero_vector || (obj->orient.fvec * (*goal_dir)) >= ONE_DEGREE_ARC_COS) |
| 2132 | return; // No goal_dir or less than 1 degree off goal |
| 2133 | |
| 2134 | if (obj->size > 32.0f && (obj->orient.fvec * (*goal_dir)) >= FIVE_DEGREE_ARC_COS) |
| 2135 | return; // Big objects have more play |
| 2136 | |
| 2137 | if (obj->type != OBJ_WEAPON) { |
| 2138 | obj->ai_info->flags |= AIF_REPORT_NEW_ORIENT; |
| 2139 | if (obj->ai_info) |
| 2140 | obj->ai_info->saved_orient = obj->orient; |
| 2141 | } |
| 2142 | |
| 2143 | goal_angle = vm_DeltaAngVecNorm(&obj->orient.fvec, goal_dir, &u_axis); |
| 2144 | |
| 2145 | if (goal_angle == 0) |
| 2146 | return; |
| 2147 | |
| 2148 | max_angle = turn_rate * Frametime; |
| 2149 | |
| 2150 | if ((float)goal_angle > max_angle) { |
| 2151 | matrix turn_matrix; |
| 2152 | |
| 2153 | if (max_angle != 32767 && max_angle != 32768) { |
| 2154 | // Get the up axis |
| 2155 | vm_CrossProduct(&u_axis, &obj->orient.fvec, goal_dir); |
| 2156 | |
| 2157 | // Using the forward(original orient's forward) and the up (computed), get the orientation matrix |
| 2158 | vm_VectorToMatrix(&rot_matrix, &obj->orient.fvec, &u_axis, NULL); |
| 2159 | } else { |
| 2160 | rot_matrix = obj->orient; |
| 2161 | } |
| 2162 | |
| 2163 | vm_AnglesToMatrix(&turn_matrix, 0.0, max_angle, 0.0); |
| 2164 | |
| 2165 | rot_matrix = rot_matrix * turn_matrix; |
| 2166 | |
| 2167 | obj->orient.fvec = rot_matrix.fvec; // ObjSetOrient below |
| 2168 | } else { |
| 2169 | obj->orient.fvec = *goal_dir; // ObjSetOrient below |
| 2170 | } |
| 2171 | |
| 2172 | if (obj->movement_type == MT_WALKING) { |
| 2173 | obj->orient.uvec = saved_uvec; |
| 2174 | |
| 2175 | float f_proj = obj->orient.uvec * obj->orient.fvec; |
| 2176 | float r_proj = obj->orient.uvec * obj->orient.rvec; |
| 2177 | |
| 2178 | if (f_proj <= -1.0f || f_proj >= 1.0f || r_proj >= 1.0f || r_proj <= -1.0f) { |
| 2179 | obj->orient = saved_orient; |
| 2180 | } else { |
| 2181 | obj->orient.fvec -= (obj->orient.uvec * f_proj); |
| 2182 | obj->orient.rvec -= (obj->orient.uvec * r_proj); |
| 2183 | |
| 2184 | vm_NormalizeVector(&obj->orient.fvec); |
| 2185 | vm_NormalizeVector(&obj->orient.rvec); |
| 2186 | } |
| 2187 | } |
| 2188 | |
| 2189 | vm_Orthogonalize(&obj->orient); |
| 2190 | ObjSetOrient(obj, &obj->orient); |
| 2191 | } |
| 2192 | |
| 2193 | bool AITurnTowardsMatrix(object *obj, float turn_rate, matrix *g_orient) { |
| 2194 | float max_angles = turn_rate * Frametime; |
| 2195 | |
| 2196 | matrix t_s_matrix = obj->orient; |
| 2197 | vm_TransposeMatrix(&t_s_matrix); |
| 2198 | |
| 2199 | matrix rot_matrix; |
| 2200 | |
| 2201 | rot_matrix = t_s_matrix * *g_orient; |
| 2202 | |
| 2203 | angvec a; |
| 2204 | vm_ExtractAnglesFromMatrix(&a, &rot_matrix); |
| 2205 | vector dist; |
| 2206 | |
| 2207 | if (a.b > 32768) |
| 2208 | dist.x = 65536 - a.b; |
| 2209 | else |
| 2210 | dist.x = a.b; |
| 2211 | |
| 2212 | if (a.h > 32768) |
| 2213 | dist.y = 65536 - a.h; |
| 2214 | else |
| 2215 | dist.y = a.h; |
| 2216 | |
| 2217 | if (a.p > 32768) |
| 2218 | dist.z = 65536 - a.p; |
| 2219 | else |
| 2220 | dist.z = a.p; |
| 2221 | |
| 2222 | float angles = vm_GetMagnitude(&dist); |
| 2223 | |
| 2224 | if (angles <= max_angles) { |
| 2225 | obj->orient = *g_orient; |
| 2226 | vm_Orthogonalize(&obj->orient); |
| 2227 | ObjSetOrient(obj, &obj->orient); |
| 2228 | return true; |
| 2229 | } |
| 2230 | |
| 2231 | float scale = max_angles / angles; |
| 2232 | dist *= scale; |
| 2233 | |
| 2234 | if (a.b > 32768) |
| 2235 | a.b = 65535 - dist.x; |
| 2236 | else |
| 2237 | a.b = dist.x; |
| 2238 | |
| 2239 | if (a.h > 32768) |
| 2240 | a.h = 65535 - dist.y; |
| 2241 | else |
| 2242 | a.h = dist.y; |
| 2243 | |
| 2244 | if (a.p > 32768) |
| 2245 | a.p = 65535 - dist.z; |
| 2246 | else |
| 2247 | a.p = dist.z; |
| 2248 | |
| 2249 | vm_AnglesToMatrix(&rot_matrix, a.p, a.h, a.b); |
| 2250 | obj->orient *= rot_matrix; |
| 2251 | vm_Orthogonalize(&obj->orient); |
| 2252 | ObjSetOrient(obj, &obj->orient); |
| 2253 | |
| 2254 | return false; |
| 2255 | } |
| 2256 | |
| 2257 | // MTS: Unused? |
| 2258 | void AITurnTowardsPosition(object *obj, /*velocity *new_vel,*/ vector *pos /*, bool remain_level*/) { |
| 2259 | vector goal_dir = *pos - obj->pos; |
| 2260 | ai_frame *ai_info = obj->ai_info; |
| 2261 | |
| 2262 | // If we want to face ourselves, we are done. :) |
| 2263 | float dist = vm_NormalizeVector(&goal_dir); |
| 2264 | if (dist < .1f) |
| 2265 | return; |
| 2266 | |
| 2267 | AITurnTowardsDir(obj, &goal_dir, ai_info->max_turn_rate); |
| 2268 | } |
| 2269 | |
| 2270 | #define AI_AVE_MELEE_TIME .45f |
| 2271 | |
| 2272 | bool MeleeHitOk(object *obj) { |
| 2273 | ai_frame *ai_info = obj->ai_info; |
| 2274 | vector intp; |
| 2275 | float col_dist; |
| 2276 | int num_attacks = 0; |
| 2277 | float delay = 0.0f; |
| 2278 | const int ai_movement = ai_info->movement_type; |
| 2279 | polyobj_info *p_info = &obj->rtype.pobj_info; |
| 2280 | float time_left; |
| 2281 | |
| 2282 | if (p_info->anim_end_frame != p_info->anim_start_frame) { |
| 2283 | float time_per_frame = p_info->anim_time / ((float)p_info->anim_end_frame - (float)p_info->anim_start_frame); |
| 2284 | |
| 2285 | time_left = time_per_frame * (p_info->anim_end_frame - p_info->anim_frame); |
| 2286 | } else { |
| 2287 | time_left = 0.0f; |
| 2288 | } |
| 2289 | |
| 2290 | vector relative_vel; |
| 2291 | vector g_end_pos; |
| 2292 | |
| 2293 | object *target = ObjGet(ai_info->target_handle); |
| 2294 | |
| 2295 | if (target == NULL || ai_info->dist_to_target_perceived > 100.0f) { |
| 2296 | return false; |
| 2297 | } |
| 2298 | |
| 2299 | float dist = vm_VectorDistance(&obj->pos, &target->pos); |
| 2300 | |
| 2301 | if (dist <= AI_MAX_MELEE_RANGE) { |
| 2302 | return true; |
| 2303 | } |
| 2304 | |
| 2305 | if (ai_info->flags & AIF_MELEE1) { |
| 2306 | num_attacks++; |
| 2307 | delay += Object_info[obj->id].anim[ai_movement].elem[AS_MELEE1].spc; |
| 2308 | } |
| 2309 | |
| 2310 | if (ai_info->flags & AIF_MELEE2) { |
| 2311 | num_attacks++; |
| 2312 | delay += Object_info[obj->id].anim[ai_movement].elem[AS_MELEE2].spc; |
| 2313 | } |
| 2314 | |
| 2315 | if (!num_attacks) { |
| 2316 | return false; |
| 2317 | } else if (num_attacks > 1) { |
| 2318 | delay = delay / (float)num_attacks; |
| 2319 | } |
| 2320 | |
| 2321 | delay += time_left + Frametime; |
| 2322 | |
| 2323 | // Determines the relative velocities |
| 2324 | if (obj->movement_type == MT_PHYSICS || obj->movement_type == MT_PHYSICS) { |
| 2325 | if (target->movement_type == MT_PHYSICS || target->movement_type == MT_PHYSICS) { |
| 2326 | relative_vel = obj->mtype.phys_info.velocity - target->mtype.phys_info.velocity; |
| 2327 | } else { |
| 2328 | relative_vel = obj->mtype.phys_info.velocity; |
| 2329 | } |
| 2330 | } else { |
| 2331 | if (target->movement_type == MT_PHYSICS || target->movement_type == MT_PHYSICS) { |
| 2332 | relative_vel = -target->mtype.phys_info.velocity; |
| 2333 | } else { |
| 2334 | relative_vel = Zero_vector; |
| 2335 | } |
| 2336 | } |
| 2337 | |
| 2338 | if (obj->movement_type == MT_PHYSICS || obj->movement_type == MT_PHYSICS) { |
| 2339 | if ((relative_vel * ai_info->vec_to_target_perceived) < 0.0f) { |
| 2340 | return false; |
| 2341 | } |
| 2342 | } |
| 2343 | |
| 2344 | g_end_pos = obj->pos + (delay * relative_vel); |
| 2345 | |
| 2346 | if (check_vector_to_sphere_1(&intp, &col_dist, &obj->pos, &g_end_pos, &target->pos, |
| 2347 | target->size + obj->size + (.9f * AI_MAX_MELEE_RANGE), false, true) != 0) { |
| 2348 | return true; |
| 2349 | } |
| 2350 | |
| 2351 | return false; |
| 2352 | } |
| 2353 | |
| 2354 | bool AiMelee(object *obj) { |
| 2355 | ai_frame *ai_info = obj->ai_info; |
| 2356 | vector f_vec; |
| 2357 | float dot; |
| 2358 | |
| 2359 | object *target = ObjGet(ai_info->target_handle); |
| 2360 | |
| 2361 | if (target == NULL) { |
| 2362 | ai_info->status_reg &= ~AISR_MELEE; |
| 2363 | return false; |
| 2364 | } |
| 2365 | |
| 2366 | if (((Gametime - ai_info->last_see_target_time) > 4.0 && ((Gametime - ai_info->last_hear_target_time) > 4.0)) || |
| 2367 | ai_info->awareness <= AWARE_BARELY) { |
| 2368 | ai_info->status_reg &= ~AISR_MELEE; |
| 2369 | return false; |
| 2370 | } |
| 2371 | |
| 2372 | if (ai_info->next_melee_time > Gametime) { |
| 2373 | ai_info->status_reg &= ~AISR_MELEE; |
| 2374 | return false; |
| 2375 | } |
| 2376 | |
| 2377 | if (ai_info->next_animation_type == AS_MELEE1 || ai_info->next_animation_type == AS_MELEE2) { |
| 2378 | ai_info->status_reg |= AISR_MELEE; |
| 2379 | return false; |
| 2380 | } |
| 2381 | |
| 2382 | if (!(ai_info->flags & (AIF_MELEE1 | AIF_MELEE2))) { |
| 2383 | ai_info->status_reg &= ~AISR_MELEE; |
| 2384 | return false; |
| 2385 | } |
| 2386 | |
| 2387 | // The AI wants to attack!!!!! |
| 2388 | ai_info->status_reg |= AISR_MELEE; |
| 2389 | |
| 2390 | // Determine if we are in melee range |
| 2391 | if (!MeleeHitOk(obj)) { |
| 2392 | return false; |
| 2393 | } |
| 2394 | |
| 2395 | f_vec = obj->orient.fvec; |
| 2396 | vm_NormalizeVector(&f_vec); |
| 2397 | |
| 2398 | dot = f_vec * ai_info->vec_to_target_perceived; |
| 2399 | |
| 2400 | if (dot >= 0.8f) { |
| 2401 | gi_fire attack_info; |
| 2402 | int attack_num; |
| 2403 | |
| 2404 | if (!(ai_info->flags & AIF_MELEE1) || ((ai_info->flags & AIF_MELEE2) && (ps_rand() > (D3_RAND_MAX >> 1)))) { |
| 2405 | attack_num = 1; |
| 2406 | } else { |
| 2407 | attack_num = 0; |
| 2408 | } |
| 2409 | |
| 2410 | // mprintf(0, "Melee attack now!!!!\n"); |
| 2411 | |
| 2412 | attack_info.melee_number = attack_num; |
| 2413 | if (GoalAddGoal(obj, AIG_DO_MELEE_ANIM, (void *)&attack_info, ACTIVATION_BLEND_LEVEL) == 0) |
| 2414 | return true; |
| 2415 | } |
| 2416 | |
| 2417 | return false; |
| 2418 | } |
| 2419 | |
| 2420 | void do_melee_attack(object *obj) { |
| 2421 | ai_frame *ai_info = obj->ai_info; |
| 2422 | float damage; |
| 2423 | notify melee_info; |
| 2424 | int attack_num; |
| 2425 | object *target = ObjGet(ai_info->target_handle); |
| 2426 | |
| 2427 | if (ai_info->animation_type == AS_MELEE1) { |
| 2428 | damage = ai_info->melee_damage[0]; |
| 2429 | ai_info->next_melee_time = Gametime + ai_info->melee_latency[0]; |
| 2430 | attack_num = 0; |
| 2431 | } else { |
| 2432 | damage = ai_info->melee_damage[1]; |
| 2433 | ai_info->next_melee_time = Gametime + ai_info->melee_latency[1]; |
| 2434 | attack_num = 1; |
| 2435 | } |
| 2436 | |
| 2437 | melee_info.obj_handle = ai_info->target_handle; |
| 2438 | melee_info.attack_num = attack_num; |
| 2439 | |
| 2440 | AINotify(obj, AIN_MELEE_ATTACK_FRAME, (void *)&melee_info); |
| 2441 | |
| 2442 | if (target) { |
| 2443 | float dist = ai_info->dist_to_target_actual; |
| 2444 | |
| 2445 | if (dist <= AI_MAX_MELEE_RANGE) { |
| 2446 | AINotify(obj, AIN_MELEE_HIT, (void *)&melee_info); |
| 2447 | |
| 2448 | if (damage >= 1.0f) { |
| 2449 | object *objptr = ObjGet(ai_info->target_handle); |
| 2450 | |
| 2451 | if (objptr) { |
| 2452 | if (ps_rand() > D3_RAND_MAX / 2) { |
| 2453 | Sound_system.Play3dSound(SOUND_MELEE_HIT_0, SND_PRIORITY_HIGHEST, objptr); |
| 2454 | if (Game_mode & GM_MULTI) |
| 2455 | MultiPlay3dSound(SOUND_MELEE_HIT_0, OBJNUM(objptr), SND_PRIORITY_HIGHEST); |
| 2456 | if (Demo_flags == DF_RECORDING) |
| 2457 | DemoWrite3DSound(SOUND_MELEE_HIT_0, OBJNUM(objptr), SND_PRIORITY_HIGHEST); |
| 2458 | } else { |
| 2459 | Sound_system.Play3dSound(SOUND_MELEE_HIT_1, SND_PRIORITY_HIGHEST, objptr); |
| 2460 | if (Game_mode & GM_MULTI) |
| 2461 | MultiPlay3dSound(SOUND_MELEE_HIT_1, OBJNUM(objptr), SND_PRIORITY_HIGHEST); |
| 2462 | if (Demo_flags == DF_RECORDING) |
| 2463 | DemoWrite3DSound(SOUND_MELEE_HIT_1, OBJNUM(objptr), SND_PRIORITY_HIGHEST); |
| 2464 | } |
| 2465 | |
| 2466 | if (objptr->type == OBJ_PLAYER) |
| 2467 | ApplyDamageToPlayer(objptr, obj, PD_MELEE_ATTACK, damage); |
| 2468 | else |
| 2469 | ApplyDamageToGeneric(objptr, obj, GD_MELEE_ATTACK, damage); |
| 2470 | } |
| 2471 | } else if (damage == 0.0f) { |
| 2472 | float energy; |
| 2473 | object *objptr = ObjGet(ai_info->target_handle); |
| 2474 | |
| 2475 | // chrishack - milestone - replace with real code |
| 2476 | if (objptr) { |
| 2477 | Sound_system.Play3dSound(SOUND_ENERGY_DRAIN, SND_PRIORITY_HIGHEST, objptr); |
| 2478 | if (Game_mode & GM_MULTI) |
| 2479 | MultiPlay3dSound(SOUND_ENERGY_DRAIN, OBJNUM(objptr), SND_PRIORITY_HIGHEST); |
| 2480 | if (Demo_flags == DF_RECORDING) |
| 2481 | DemoWrite3DSound(SOUND_ENERGY_DRAIN, OBJNUM(objptr), SND_PRIORITY_HIGHEST); |
| 2482 | |
| 2483 | energy = (14 + ps_rand() % 5) * Diff_general_inv_scalar[DIFF_LEVEL]; |
| 2484 | |
| 2485 | if (objptr->type == OBJ_PLAYER) { |
| 2486 | if (Players[objptr->id].energy < energy) |
| 2487 | energy = Players[objptr->id].energy; |
| 2488 | |
| 2489 | DecreasePlayerEnergy(objptr->id, energy); |
| 2490 | } |
| 2491 | } |
| 2492 | } |
| 2493 | } |
| 2494 | } |
| 2495 | } |
| 2496 | |
| 2497 | void do_ranged_attack(object *obj) { |
| 2498 | ai_frame *ai_info = obj->ai_info; |
| 2499 | int cur_wb = ai_info->current_wb_firing; |
| 2500 | |
| 2501 | // Fire Weapon |
| 2502 | WBFireBattery(obj, &Object_info[obj->id].static_wb[cur_wb], cur_wb); |
| 2503 | ai_info->status_reg &= ~AISR_RANGED_ATTACK; |
| 2504 | } |
| 2505 | |
| 2506 | void AIUpdateAnim(object *obj) { |
| 2507 | ai_frame *ai_info = obj->ai_info; |
| 2508 | polyobj_info *p_info = &obj->rtype.pobj_info; |
| 2509 | int new_anim = ai_info->next_animation_type; |
| 2510 | int ai_movement = ai_info->movement_type; |
| 2511 | |
| 2512 | if (ai_info->anim_sound_handle != 0) |
| 2513 | Sound_system.StopSoundLooping(ai_info->anim_sound_handle); |
| 2514 | |
| 2515 | if (!Object_info[obj->id].anim) |
| 2516 | return; |
| 2517 | |
| 2518 | if ((Demo_flags == DF_PLAYBACK) || ((Game_mode & GM_MULTI) && (Netgame.local_role == LR_CLIENT))) { |
| 2519 | p_info->anim_flags &= ~AIAF_NOTIFY; |
| 2520 | |
| 2521 | if (!(p_info->multi_anim_info.flags & FMA_VALID)) { |
| 2522 | mprintf(0, "Update Anim: Earily bail\n"); |
| 2523 | return; |
| 2524 | } |
| 2525 | |
| 2526 | custom_anim *multi_anim_info = &p_info->multi_anim_info; |
| 2527 | |
| 2528 | multi_anim_info->server_time = Gametime; |
| 2529 | p_info->anim_frame = ((float)multi_anim_info->server_anim_frame) / 256.0f; |
| 2530 | |
| 2531 | p_info->anim_start_frame = multi_anim_info->anim_start_frame; |
| 2532 | p_info->anim_end_frame = multi_anim_info->anim_end_frame; |
| 2533 | p_info->anim_time = multi_anim_info->anim_time; |
| 2534 | p_info->max_speed = multi_anim_info->max_speed; |
| 2535 | |
| 2536 | p_info->anim_flags = 0; |
| 2537 | |
| 2538 | if (multi_anim_info->flags & FMA_LOOPING) |
| 2539 | p_info->anim_flags |= AIAF_LOOPING; |
| 2540 | |
| 2541 | // Make sure we mark it as current and |
| 2542 | p_info->multi_anim_info.flags |= FMA_CURRENT; |
| 2543 | |
| 2544 | if (multi_anim_info->anim_sound_index >= 0) { |
| 2545 | Sound_system.StopSoundLooping(ai_info->anim_sound_handle); |
| 2546 | ai_info->anim_sound_handle = Sound_system.Play3dSound(multi_anim_info->anim_sound_index, SND_PRIORITY_LOW, obj); |
| 2547 | } |
| 2548 | |
| 2549 | return; |
| 2550 | } |
| 2551 | |
| 2552 | if (new_anim == AS_FLINCH) { |
| 2553 | float delta_time = 1.0f + obj->shields / 10.0f; |
| 2554 | if (delta_time > 4.3) { |
| 2555 | delta_time = 4.3f; |
| 2556 | } |
| 2557 | |
| 2558 | ai_info->next_flinch_time = Gametime + delta_time; |
| 2559 | } |
| 2560 | // mprintf(0, "D %d to %d\n", ai_info->animation_type, ai_info->next_animation_type); |
| 2561 | |
| 2562 | // Update the physics and movement class info |
| 2563 | switch (ai_info->animation_type) { |
| 2564 | case AS_GOTO_IDLE_STANDING: |
| 2565 | case AS_GOTO_ALERT_STANDING: |
| 2566 | if (obj->movement_type != MT_NONE) |
| 2567 | obj->movement_type = MT_WALKING; |
| 2568 | ai_movement = ai_info->movement_type = MC_STANDING; |
| 2569 | break; |
| 2570 | |
| 2571 | case AS_GOTO_IDLE_FLYING: |
| 2572 | case AS_GOTO_ALERT_FLYING: |
| 2573 | obj->movement_type = MT_PHYSICS; |
| 2574 | ai_movement = ai_info->movement_type = MC_FLYING; |
| 2575 | break; |
| 2576 | |
| 2577 | case AS_GOTO_IDLE_ROLLING: |
| 2578 | case AS_GOTO_ALERT_ROLLING: |
| 2579 | obj->movement_type = MT_WALKING; |
| 2580 | ai_movement = ai_info->movement_type = MC_ROLLING; |
| 2581 | break; |
| 2582 | |
| 2583 | case AS_GOTO_IDLE_WALKING: |
| 2584 | case AS_GOTO_ALERT_WALKING: |
| 2585 | obj->movement_type = MT_WALKING; |
| 2586 | ai_movement = ai_info->movement_type = MC_WALKING; |
| 2587 | break; |
| 2588 | |
| 2589 | case AS_GOTO_IDLE_JUMPING: |
| 2590 | case AS_GOTO_ALERT_JUMPING: |
| 2591 | obj->movement_type = MT_PHYSICS; |
| 2592 | ai_movement = ai_info->movement_type = MC_JUMPING; |
| 2593 | break; |
| 2594 | } |
| 2595 | |
| 2596 | if (new_anim == AS_RANGED_ATTACK) { |
| 2597 | if (ai_info->sound[AI_ATTACK_SOUND] != SOUND_NONE_INDEX) { |
| 2598 | // Plays the sound and makes absolute sure that it is not looping |
| 2599 | if (Gametime - ai_info->last_sound_time[AI_ATTACK_SOUND] > 5.0f) { |
| 2600 | // A 75% chance of playing it |
| 2601 | if (ps_rand() % 4 != 0) { |
| 2602 | Sound_system.StopSoundLooping( |
| 2603 | Sound_system.Play3dSound(ai_info->sound[AI_ATTACK_SOUND], SND_PRIORITY_NORMAL, obj)); |
| 2604 | if (Game_mode & GM_MULTI) |
| 2605 | MultiPlay3dSound(ai_info->sound[AI_ATTACK_SOUND], OBJNUM(obj), SND_PRIORITY_NORMAL); |
| 2606 | if (Demo_flags == DF_RECORDING) |
| 2607 | DemoWrite3DSound(ai_info->sound[AI_ATTACK_SOUND], OBJNUM(obj), SND_PRIORITY_NORMAL); |
| 2608 | } |
| 2609 | ai_info->last_sound_time[AI_ATTACK_SOUND] = Gametime; |
| 2610 | } |
| 2611 | } |
| 2612 | } else if (new_anim != AI_INVALID_INDEX && new_anim != AS_RANGED_RECOIL) { |
| 2613 | if ((new_anim != AS_CUSTOM && |
| 2614 | Object_info[obj->id].anim[ai_movement].elem[new_anim].anim_sound_index != SOUND_NONE_INDEX) || |
| 2615 | (new_anim == AS_CUSTOM && p_info->custom_anim_info.anim_sound_index != SOUND_NONE_INDEX)) { |
| 2616 | if (new_anim != AS_CUSTOM) |
| 2617 | ai_info->last_played_sound_index = Object_info[obj->id].anim[ai_movement].elem[new_anim].anim_sound_index; |
| 2618 | else |
| 2619 | ai_info->last_played_sound_index = p_info->custom_anim_info.anim_sound_index; |
| 2620 | |
| 2621 | ai_info->anim_sound_handle = Sound_system.Play3dSound(ai_info->last_played_sound_index, SND_PRIORITY_LOW, obj); |
| 2622 | } else { |
| 2623 | ai_info->last_played_sound_index = -1; |
| 2624 | } |
| 2625 | } |
| 2626 | |
| 2627 | new_anim_label: |
| 2628 | |
| 2629 | if (new_anim != AI_INVALID_INDEX) { |
| 2630 | // Melee stuff |
| 2631 | if (ai_info->animation_type == AS_MELEE1 || ai_info->animation_type == AS_MELEE2) { |
| 2632 | do_melee_attack(obj); |
| 2633 | } else if (ai_info->animation_type == AS_RANGED_ATTACK) { |
| 2634 | ASSERT(new_anim == AS_RANGED_RECOIL); |
| 2635 | |
| 2636 | int cur_wb = ai_info->current_wb_firing; |
| 2637 | int cur_mask = obj->dynamic_wb[cur_wb].wb_anim_mask; |
| 2638 | float fire = Object_info[obj->id].static_wb[cur_wb].anim_fire_frame[cur_mask]; |
| 2639 | |
| 2640 | float temp_anim = p_info->anim_frame; |
| 2641 | p_info->anim_frame = fire; |
| 2642 | do_ranged_attack(obj); |
| 2643 | p_info->anim_frame = temp_anim; |
| 2644 | } |
| 2645 | |
| 2646 | // Set the new animation |
| 2647 | ai_info->animation_type = new_anim; |
| 2648 | |
| 2649 | if (new_anim == AS_RANGED_ATTACK) { |
| 2650 | int cur_wb = ai_info->current_wb_firing; |
| 2651 | int cur_mask = obj->dynamic_wb[cur_wb].wb_anim_mask; |
| 2652 | |
| 2653 | float start = Object_info[obj->id].static_wb[cur_wb].anim_start_frame[cur_mask]; |
| 2654 | float fire = Object_info[obj->id].static_wb[cur_wb].anim_fire_frame[cur_mask]; |
| 2655 | float end = Object_info[obj->id].static_wb[cur_wb].anim_end_frame[cur_mask]; |
| 2656 | float total_time = Object_info[obj->id].static_wb[cur_wb].anim_time[cur_mask]; |
| 2657 | |
| 2658 | p_info->anim_start_frame = start; |
| 2659 | p_info->anim_end_frame = fire; |
| 2660 | |
| 2661 | if (start < fire) { |
| 2662 | p_info->anim_time = total_time * ((fire - start) / (end - start)); |
| 2663 | } else { |
| 2664 | new_anim = AS_RANGED_RECOIL; |
| 2665 | goto new_anim_label; |
| 2666 | } |
| 2667 | } else if (new_anim == AS_RANGED_RECOIL) { |
| 2668 | int cur_wb = ai_info->current_wb_firing; |
| 2669 | int cur_mask = obj->dynamic_wb[cur_wb].wb_anim_mask; |
| 2670 | |
| 2671 | float start = Object_info[obj->id].static_wb[cur_wb].anim_start_frame[cur_mask]; |
| 2672 | float fire = Object_info[obj->id].static_wb[cur_wb].anim_fire_frame[cur_mask]; |
| 2673 | float end = Object_info[obj->id].static_wb[cur_wb].anim_end_frame[cur_mask]; |
| 2674 | float total_time = Object_info[obj->id].static_wb[cur_wb].anim_time[cur_mask]; |
| 2675 | |
| 2676 | p_info->anim_start_frame = fire; |
| 2677 | p_info->anim_end_frame = end; |
| 2678 | |
| 2679 | if (fire < end) |
| 2680 | p_info->anim_time = total_time * ((end - fire) / (end - start)); |
| 2681 | else { |
| 2682 | new_anim = AS_ALERT; |
| 2683 | goto new_anim_label; |
| 2684 | } |
| 2685 | } else if (new_anim == AS_CUSTOM) { |
| 2686 | p_info->anim_start_frame = p_info->custom_anim_info.anim_start_frame; |
| 2687 | p_info->anim_end_frame = p_info->custom_anim_info.anim_end_frame; |
| 2688 | p_info->anim_time = p_info->custom_anim_info.anim_time; |
| 2689 | p_info->anim_flags = p_info->custom_anim_info.flags; |
| 2690 | ai_info->next_animation_type = p_info->custom_anim_info.next_anim_type; |
| 2691 | } else { |
| 2692 | p_info->anim_start_frame = Object_info[obj->id].anim[ai_movement].elem[new_anim].from; |
| 2693 | p_info->anim_end_frame = Object_info[obj->id].anim[ai_movement].elem[new_anim].to; |
| 2694 | p_info->anim_time = Object_info[obj->id].anim[ai_movement].elem[new_anim].spc; |
| 2695 | } |
| 2696 | |
| 2697 | p_info->anim_frame = p_info->anim_start_frame; |
| 2698 | |
| 2699 | // Handle the next anim's |
| 2700 | switch (new_anim) { |
| 2701 | case AS_MELEE1: |
| 2702 | case AS_MELEE2: { |
| 2703 | p_info->anim_flags = AIAF_NOTIFY; |
| 2704 | ai_info->next_animation_type = new_anim + 1; /* Recoil */ |
| 2705 | } break; |
| 2706 | |
| 2707 | case AS_RANGED_ATTACK: { |
| 2708 | p_info->anim_flags = AIAF_NOTIFY; |
| 2709 | ai_info->next_animation_type = AS_RANGED_RECOIL; /* Recoil */ |
| 2710 | } break; |
| 2711 | |
| 2712 | case AS_DEATH: { |
| 2713 | p_info->anim_flags = 0; |
| 2714 | ai_info->next_animation_type = AI_INVALID_INDEX; |
| 2715 | } break; |
| 2716 | |
| 2717 | case AS_ALERT: |
| 2718 | case AS_IDLE: { |
| 2719 | p_info->anim_flags = AIAF_LOOPING; |
| 2720 | ai_info->next_animation_type = AI_INVALID_INDEX; |
| 2721 | } break; |
| 2722 | |
| 2723 | case (AS_MELEE1 + 1): |
| 2724 | |
| 2725 | { |
| 2726 | if (!AiMelee(obj)) { |
| 2727 | p_info->anim_flags = AIAF_NOTIFY; |
| 2728 | ai_info->next_animation_type = AS_ALERT; |
| 2729 | } |
| 2730 | } break; |
| 2731 | |
| 2732 | case (AS_MELEE2 + 1): { |
| 2733 | if (!AiMelee(obj)) { |
| 2734 | p_info->anim_flags = AIAF_NOTIFY; |
| 2735 | ai_info->next_animation_type = AS_ALERT; |
| 2736 | } |
| 2737 | } break; |
| 2738 | |
| 2739 | case AS_GOTO_IDLE_STANDING: |
| 2740 | case AS_GOTO_IDLE_FLYING: |
| 2741 | case AS_GOTO_IDLE_ROLLING: |
| 2742 | case AS_GOTO_IDLE_WALKING: |
| 2743 | case AS_GOTO_IDLE_JUMPING: |
| 2744 | case AS_QUIRK: |
| 2745 | case AS_BIRTH: { |
| 2746 | p_info->anim_flags = AIAF_NOTIFY; |
| 2747 | ai_info->next_animation_type = AS_IDLE; |
| 2748 | } break; |
| 2749 | |
| 2750 | case AS_CUSTOM: |
| 2751 | break; |
| 2752 | |
| 2753 | default: { |
| 2754 | p_info->anim_flags = AIAF_NOTIFY; |
| 2755 | ai_info->next_animation_type = AS_ALERT; |
| 2756 | } break; |
| 2757 | } |
| 2758 | } |
| 2759 | |
| 2760 | if ((Game_mode & GM_MULTI) && (Netgame.local_role == LR_SERVER)) { |
| 2761 | MultiAddObjAnimUpdate(OBJNUM(obj)); |
| 2762 | } |
| 2763 | if (Demo_flags == DF_RECORDING) { |
| 2764 | DemoWriteObjAnimChanged(OBJNUM(obj)); |
| 2765 | } |
| 2766 | } |
| 2767 | |
| 2768 | static inline void ApplyConstantForce(object *objp, vector *new_pos, vector *force, float delta_time) { |
| 2769 | const vector velocity = objp->mtype.phys_info.velocity; |
| 2770 | const float drag = objp->mtype.phys_info.drag; |
| 2771 | const float mass = objp->mtype.phys_info.mass; |
| 2772 | |
| 2773 | // Standard motion with a linear air drag (drag is proportional to velocity) |
| 2774 | *new_pos = objp->pos + (*force / drag) * (delta_time) + |
| 2775 | (mass / drag) * (velocity - (*force / drag)) * (1 - exp(-(drag / mass) * delta_time)); |
| 2776 | } |
| 2777 | |
| 2778 | bool AIDetermineAimPoint(object *robot, object *target, vector *aim_pt, float weapon_speed) { |
| 2779 | if (DIFF_LEVEL == DIFFICULTY_TRAINEE && ((robot->ai_info->flags & AIF_TEAM_MASK) != AIF_TEAM_REBEL)) { |
| 2780 | *aim_pt = target->pos; |
| 2781 | return true; |
| 2782 | } |
| 2783 | |
| 2784 | float vl = AIDetermineObjVisLevel(robot, target); |
| 2785 | |
| 2786 | ai_frame *ai_info = robot->ai_info; |
| 2787 | vector to_target = target->pos - robot->pos; |
| 2788 | float dist_to_target = vm_NormalizeVector(&to_target); |
| 2789 | |
| 2790 | if (weapon_speed == 0.0f && ai_info) |
| 2791 | weapon_speed = ai_info->weapon_speed; |
| 2792 | |
| 2793 | if (weapon_speed == 0.0f) { |
| 2794 | *aim_pt = target->pos; |
| 2795 | return false; |
| 2796 | } |
| 2797 | |
| 2798 | float wsp = weapon_speed - (to_target * target->mtype.phys_info.velocity); |
| 2799 | |
| 2800 | if (wsp <= 0.0f || vl < AIVIS_BARELY) { |
| 2801 | *aim_pt = target->pos; |
| 2802 | return false; |
| 2803 | } |
| 2804 | |
| 2805 | float dt = dist_to_target / wsp; |
| 2806 | |
| 2807 | float scale; |
| 2808 | |
| 2809 | if (ai_info) |
| 2810 | scale = ai_info->lead_accuracy; |
| 2811 | else |
| 2812 | scale = 1.0f; |
| 2813 | |
| 2814 | // chrishack -- add stuff so that rebels get better as DIFF lowers and |
| 2815 | // ptmc gets better as DIFF increases |
| 2816 | if (target->type != OBJ_PLAYER || |
| 2817 | (DIFF_LEVEL < DIFFICULTY_HOTSHOT && ((robot->ai_info->flags & AIF_TEAM_MASK) != AIF_TEAM_REBEL)) || |
| 2818 | scale < 0.4f || vl <= AIVIS_MOSTLY) |
| 2819 | *aim_pt = target->pos + (target->mtype.phys_info.velocity * dt) * scale; |
| 2820 | else |
| 2821 | ApplyConstantForce(target, aim_pt, &target->mtype.phys_info.thrust, dt * scale); |
| 2822 | |
| 2823 | return true; |
| 2824 | } |
| 2825 | |
| 2826 | vector *AIDetermineFovVec(object *obj, vector *fov) { |
| 2827 | ai_frame *ai_info = obj->ai_info; |
| 2828 | poly_model *pm = &Poly_models[obj->rtype.pobj_info.model_num]; |
| 2829 | |
| 2830 | if ((ai_info->flags & AIF_AIM_PNT_FOV) && pm->num_wbs > 0) { |
| 2831 | int aiming_gp_index = Object_info[obj->id].static_wb[0].aiming_gp_index; |
| 2832 | WeaponCalcGun(NULL, fov, obj, pm->poly_wb[0].gp_index[aiming_gp_index]); |
| 2833 | } else if (ai_info->flags & AIF_UVEC_FOV) { |
| 2834 | *fov = obj->orient.uvec; |
| 2835 | } else { |
| 2836 | *fov = obj->orient.fvec; |
| 2837 | } |
| 2838 | |
| 2839 | return fov; |
| 2840 | } |
| 2841 | |
| 2842 | #ifdef _DEBUG |
| 2843 | extern int DoAI; |
| 2844 | #else |
| 2845 | #define DoAI 1 |
| 2846 | #endif |
| 2847 | |
| 2848 | void AISeeTarget(object *obj, bool f_see) { |
| 2849 | ai_frame *ai_info = obj->ai_info; |
| 2850 | |
| 2851 | if (f_see) { |
| 2852 | if ((Gametime - ai_info->last_see_target_time > CHECK_VIS_INFREQUENTLY_TIME) || !(ai_info->awareness)) { |
| 2853 | if (ai_info->sound[AI_SEE_SOUND] != SOUND_NONE_INDEX) { |
| 2854 | // Plays the sound and makes absolute sure that it is not looping |
| 2855 | if ((ps_rand() % 10) != 0) // 90% chance of playing it |
| 2856 | { |
| 2857 | if (Gametime - ai_info->last_sound_time[AI_SEE_SOUND] >= CHECK_VIS_INFREQUENTLY_TIME) { |
| 2858 | Sound_system.StopSoundLooping( |
| 2859 | Sound_system.Play3dSound(ai_info->sound[AI_SEE_SOUND], SND_PRIORITY_NORMAL, obj)); |
| 2860 | if (Game_mode & GM_MULTI) |
| 2861 | MultiPlay3dSound(ai_info->sound[AI_SEE_SOUND], OBJNUM(obj), SND_PRIORITY_LOW); |
| 2862 | if (Demo_flags == DF_RECORDING) |
| 2863 | DemoWrite3DSound(ai_info->sound[AI_SEE_SOUND], OBJNUM(obj), SND_PRIORITY_LOW); |
| 2864 | } |
| 2865 | } |
| 2866 | |
| 2867 | ai_info->last_sound_time[AI_SEE_SOUND] = Gametime; |
| 2868 | } |
| 2869 | } |
| 2870 | } |
| 2871 | |
| 2872 | if (ai_info->awareness < AWARE_MOSTLY) |
| 2873 | ai_info->awareness = AWARE_MOSTLY; |
| 2874 | |
| 2875 | // Note: Player position is also updated in the visability test function |
| 2876 | // for MIN_VIS_RECENT_CHECK_INTERVAL seconds |
| 2877 | object *targetptr; |
| 2878 | object *other_obj = targetptr = ObjGet(ai_info->target_handle); |
| 2879 | |
| 2880 | if (targetptr) { |
| 2881 | if (f_see) |
| 2882 | ai_info->last_see_target_time = Gametime; |
| 2883 | else |
| 2884 | ai_info->last_hear_target_time = Gametime; |
| 2885 | |
| 2886 | AIDetermineAimPoint(obj, targetptr, &ai_info->last_see_target_pos); |
| 2887 | } |
| 2888 | } |
| 2889 | |
| 2890 | bool AINotify(object *obj, uint8_t notify_type, void *info) { |
| 2891 | int next_anim; |
| 2892 | ai_frame *ai_info = obj->ai_info; |
| 2893 | //@$-tD3XEventArgs evtargs; |
| 2894 | object *other_obj = NULL; |
| 2895 | object *targetptr; |
| 2896 | int parent; |
| 2897 | object *new_enemy; |
| 2898 | tOSIRISEventInfo ei; |
| 2899 | bool f_it_set = false; |
| 2900 | |
| 2901 | if (Demo_flags == DF_PLAYBACK) { |
| 2902 | return false; |
| 2903 | } |
| 2904 | ASSERT(obj); |
| 2905 | ASSERT(notify_type >= 0 && notify_type < 32); |
| 2906 | |
| 2907 | if (((Game_mode & GM_MULTI) && (Netgame.local_role == LR_CLIENT))) |
| 2908 | return false; |
| 2909 | |
| 2910 | if (!DoAI) |
| 2911 | return false; |
| 2912 | |
| 2913 | if (obj->type == OBJ_DUMMY && notify_type != AIN_USER_DEFINED) |
| 2914 | return false; |
| 2915 | |
| 2916 | if (obj && obj->control_type == CT_AI && ai_info->flags & AIF_DISABLED) |
| 2917 | return false; |
| 2918 | |
| 2919 | // All events use |
| 2920 | //@$-evtargs.args[0] = MAKE_NUM_EVTARG((float)notify_type); |
| 2921 | ei.evt_ai_notify.notify_type = notify_type; |
| 2922 | |
| 2923 | switch (notify_type) { |
| 2924 | case AIN_ANIM_COMPLETE: |
| 2925 | if (ai_info->notify_flags & (0x00000001 << notify_type)) { |
| 2926 | AIUpdateAnim(obj); |
| 2927 | } |
| 2928 | break; // parent robot |
| 2929 | case AIN_SCRIPTED_ENABLER: { |
| 2930 | //@$-evtargs.args[1] = MAKE_NUM_EVTARG(((notify *)info)->goal_num); |
| 2931 | //@$-evtargs.args[2] = MAKE_NUM_EVTARG(((notify *)info)->enabler_num); |
| 2932 | ei.evt_ai_notify.goal_num = ((notify *)info)->goal_num; |
| 2933 | ei.evt_ai_notify.enabler_num = ((notify *)info)->enabler_num; |
| 2934 | } break; |
| 2935 | case AIN_NEW_MOVEMENT: |
| 2936 | break; // parent robot |
| 2937 | case AIN_OBJ_KILLED: |
| 2938 | break; // parent robot |
| 2939 | case AIN_MELEE_HIT: |
| 2940 | case AIN_MELEE_ATTACK_FRAME: { |
| 2941 | notify *melee_info = (notify *)info; |
| 2942 | |
| 2943 | other_obj = ObjGet(melee_info->obj_handle); |
| 2944 | |
| 2945 | //@$-evtargs.args[1] = MAKE_NUM_EVTARG(((notify *)info)->attack_num); |
| 2946 | ei.evt_ai_notify.attack_num = melee_info->attack_num; |
| 2947 | } break; |
| 2948 | case AIN_WHIT_BY_OBJ: |
| 2949 | break; // parent robot |
| 2950 | case AIN_SEE_TARGET: // parent robot (who sees, type, player_obj) |
| 2951 | if (ai_info->notify_flags & (0x00000001 << notify_type)) { |
| 2952 | AISeeTarget(obj, true); |
| 2953 | } |
| 2954 | other_obj = (object *)info; |
| 2955 | break; |
| 2956 | case AIN_PLAYER_SEES_YOU: // parent robot (who got seen, type, player_obj) |
| 2957 | if (ai_info->notify_flags & (0x00000001 << notify_type)) { |
| 2958 | if (ai_info->awareness < AWARE_BARELY) |
| 2959 | ai_info->awareness = AWARE_BARELY; |
| 2960 | ai_info->last_render_time = Gametime; |
| 2961 | } |
| 2962 | break; |
| 2963 | case AIN_WHIT_OBJECT: // A robots (the one being notified, hit something) --chrishack -- if friend, no fire for X |
| 2964 | // seconds |
| 2965 | |
| 2966 | ai_info->memory[0].num_hit_enemy++; |
| 2967 | |
| 2968 | if (ai_info->awareness < AWARE_MOSTLY) { |
| 2969 | ai_info->awareness = AWARE_MOSTLY; |
| 2970 | } |
| 2971 | // chrishack -- if hitobject is target then... But, this is ok for now |
| 2972 | targetptr = ObjGet(ai_info->target_handle); |
| 2973 | |
| 2974 | // chrishack - not really done - quick implementation |
| 2975 | if (targetptr) { |
| 2976 | ai_info->last_see_target_time = Gametime; |
| 2977 | AIDetermineAimPoint(obj, targetptr, &ai_info->last_see_target_pos); |
| 2978 | } |
| 2979 | |
| 2980 | // chrishack! |
| 2981 | other_obj = (object *)info; |
| 2982 | break; |
| 2983 | |
| 2984 | case AIN_MOVIE_START: |
| 2985 | case AIN_MOVIE_END: |
| 2986 | break; |
| 2987 | case AIN_TARGET_DIED: |
| 2988 | ei.evt_ai_notify.it_handle = *(int *)info; |
| 2989 | f_it_set = true; |
| 2990 | break; |
| 2991 | |
| 2992 | case AIN_OBJ_FIRED: // All visable (obj fired, AIN_OBJFIRED, obj who fired) -- all rendered bots |
| 2993 | { |
| 2994 | int i; |
| 2995 | other_obj = (object *)info; |
| 2996 | object *targetptr; |
| 2997 | |
| 2998 | if (other_obj->control_type == CT_AI) { |
| 2999 | tOSIRISEventInfo ei; |
| 3000 | |
| 3001 | ei.evt_ai_notify.notify_type = AIN_FIRED_WEAPON; |
| 3002 | ei.evt_ai_notify.attack_num = obj->ctype.laser_info.src_gun_num; |
| 3003 | ei.evt_ai_notify.it_handle = obj->handle; |
| 3004 | |
| 3005 | Osiris_CallEvent(other_obj, EVT_AI_NOTIFY, &ei); |
| 3006 | } |
| 3007 | |
| 3008 | if (other_obj->type == OBJ_PLAYER) { |
| 3009 | ain_hear hear; |
| 3010 | |
| 3011 | hear.f_directly_player = true; |
| 3012 | hear.hostile_level = 1.0f; |
| 3013 | hear.curiosity_level = 0.0f; |
| 3014 | hear.max_dist = AI_SOUND_SHORT_DIST; |
| 3015 | AINotify(other_obj, AIN_HEAR_NOISE, (void *)&hear); |
| 3016 | } |
| 3017 | |
| 3018 | if (other_obj->control_type == CT_AI) { |
| 3019 | targetptr = ObjGet(other_obj->ai_info->target_handle); |
| 3020 | } else { |
| 3021 | targetptr = NULL; |
| 3022 | } |
| 3023 | |
| 3024 | // CHRISHACK - WTF - What was this actually for???? Hmmm..... |
| 3025 | // if(obj == targetptr) |
| 3026 | // { |
| 3027 | // ei.evt_ai_notify.it_handle = ai_info->target_handle; |
| 3028 | // |
| 3029 | // ai_info->memory[0].num_enemy_shots_fired++; |
| 3030 | // |
| 3031 | // //@$-D3XExecScript(obj, EVT_AI_NOTIFY, obj, REF_OBJTYPE, &evtargs); |
| 3032 | // Osiris_CallEvent(obj,EVT_AI_NOTIFY,&ei); |
| 3033 | // } |
| 3034 | |
| 3035 | if (targetptr && targetptr->control_type == CT_AI) { |
| 3036 | if ((targetptr->ai_info->flags & AIF_DODGE) && !(IS_GUIDEBOT(targetptr))) { |
| 3037 | if (BOA_IsVisible(targetptr->roomnum, other_obj->roomnum)) { |
| 3038 | targetptr->ai_info->memory[0].num_enemy_shots_dodged++; |
| 3039 | GoalAddGoal(targetptr, AIG_DODGE_OBJ, (void *)&obj->handle, ACTIVATION_BLEND_LEVEL); |
| 3040 | |
| 3041 | //@$-D3XExecScript(targetptr, EVT_AI_NOTIFY, obj, REF_OBJTYPE, &evtargs); |
| 3042 | ei.evt_ai_notify.it_handle = obj->handle; |
| 3043 | Osiris_CallEvent(targetptr, EVT_AI_NOTIFY, &ei); |
| 3044 | } |
| 3045 | } |
| 3046 | } else if (other_obj->type == OBJ_PLAYER) // chrishack -- we might be able use the target handle and last see time! |
| 3047 | // use BOA line-of-sight if any player then notify! Damn big improvement. |
| 3048 | { |
| 3049 | if (!(Game_mode & GM_MULTI)) { |
| 3050 | for (i = 0; i < AI_NumRendered; i++) { |
| 3051 | // mprintf(0, "I know that I could dodge, if I was aware, says robot %d.\n", AI_RenderedList[i]); |
| 3052 | |
| 3053 | if (!BOA_IsVisible(Objects[AI_RenderedList[i]].roomnum, other_obj->roomnum)) |
| 3054 | continue; |
| 3055 | |
| 3056 | ai_frame *ai_info = Objects[AI_RenderedList[i]].ai_info; |
| 3057 | if (ai_info->notify_flags & (0x00000001 << notify_type)) { |
| 3058 | if (!(ai_info->flags & AIF_DISABLED)) { |
| 3059 | if (ai_info->flags & AIF_DODGE) { |
| 3060 | if (ai_info->awareness > AWARE_BARELY) { |
| 3061 | if (ps_rand() < ai_info->dodge_percent * D3_RAND_MAX) { |
| 3062 | vector fov_vec; |
| 3063 | |
| 3064 | if (ai_info->vec_to_target_actual * (*AIDetermineFovVec(&Objects[AI_RenderedList[i]], &fov_vec)) >= |
| 3065 | Objects[AI_RenderedList[i]].ai_info->fov) { |
| 3066 | // mprintf(0, "I am fired upon says robot %d\n", AI_RenderedList[i])); |
| 3067 | if (ai_info->notify_flags & (0x00000001 << notify_type)) { |
| 3068 | ai_info->memory[0].num_enemy_shots_dodged++; |
| 3069 | GoalAddGoal(&Objects[AI_RenderedList[i]], AIG_DODGE_OBJ, (void *)&obj->handle, |
| 3070 | ACTIVATION_BLEND_LEVEL, 1.0f, GF_SPEED_DODGE); |
| 3071 | } |
| 3072 | } |
| 3073 | } |
| 3074 | } |
| 3075 | } |
| 3076 | } |
| 3077 | } |
| 3078 | //@$-D3XExecScript(&Objects[AI_RenderedList[i]], EVT_AI_NOTIFY, NULL, REF_OBJTYPE, &evtargs); |
| 3079 | Osiris_CallEvent(&Objects[AI_RenderedList[i]], EVT_AI_NOTIFY, &ei); |
| 3080 | |
| 3081 | // This might be removed |
| 3082 | AISeeTarget(&Objects[AI_RenderedList[i]], false); |
| 3083 | } |
| 3084 | } else { |
| 3085 | for (i = 0; i <= Highest_object_index; i++) { |
| 3086 | // mprintf(0, "I know that I could dodge, if I was aware, says robot %d.\n", AI_RenderedList[i]); |
| 3087 | if (Objects[i].control_type != CT_AI || Objects[i].type == OBJ_NONE) |
| 3088 | continue; |
| 3089 | |
| 3090 | if (!BOA_IsVisible(Objects[i].roomnum, other_obj->roomnum)) |
| 3091 | continue; |
| 3092 | |
| 3093 | ai_frame *ai_info = Objects[i].ai_info; |
| 3094 | |
| 3095 | if (ai_info->notify_flags & (0x00000001 << notify_type)) { |
| 3096 | if (!(ai_info->flags & AIF_DISABLED)) { |
| 3097 | if (ai_info->flags & AIF_DODGE) { |
| 3098 | if (ps_rand() < ai_info->dodge_percent * D3_RAND_MAX) { |
| 3099 | vector to_weapon = other_obj->pos - Objects[i].pos; |
| 3100 | vm_NormalizeVector(&to_weapon); |
| 3101 | |
| 3102 | vector fov_vec; |
| 3103 | AIDetermineFovVec(&Objects[i], &fov_vec); |
| 3104 | |
| 3105 | if (to_weapon * fov_vec >= Objects[i].ai_info->fov) { |
| 3106 | // mprintf(0, "I am fired upon says robot %d\n", AI_RenderedList[i]); |
| 3107 | if (ai_info->notify_flags & (0x00000001 << notify_type)) { |
| 3108 | ai_info->memory[0].num_enemy_shots_dodged++; |
| 3109 | GoalAddGoal(&Objects[i], AIG_DODGE_OBJ, (void *)&obj->handle, ACTIVATION_BLEND_LEVEL, 1.0f, |
| 3110 | GF_SPEED_DODGE); |
| 3111 | } |
| 3112 | } |
| 3113 | } |
| 3114 | } |
| 3115 | } |
| 3116 | } |
| 3117 | //@$-D3XExecScript(&Objects[i], EVT_AI_NOTIFY, NULL, REF_OBJTYPE, &evtargs); |
| 3118 | Osiris_CallEvent(&Objects[i], EVT_AI_NOTIFY, &ei); |
| 3119 | |
| 3120 | // This might be removed |
| 3121 | AISeeTarget(&Objects[i], false); |
| 3122 | } |
| 3123 | } |
| 3124 | } |
| 3125 | } break; |
| 3126 | case AIN_GOAL_COMPLETE: |
| 3127 | case AIN_GOAL_INVALID: |
| 3128 | case AIN_GOAL_FAIL: |
| 3129 | case AIN_GOAL_ERROR: |
| 3130 | case AIN_SCRIPTED_GOAL: |
| 3131 | case AIN_SCRIPTED_INFLUENCE: |
| 3132 | case AIN_SCRIPTED_ORIENT: |
| 3133 | ei.evt_ai_notify.goal_num = *((int *)info); |
| 3134 | ei.evt_ai_notify.goal_uid = ai_info->goals[ei.evt_ai_notify.goal_num].guid; |
| 3135 | ei.evt_ai_notify.it_handle = obj->handle; |
| 3136 | f_it_set = true; |
| 3137 | Osiris_CallLevelEvent(EVT_AI_NOTIFY, &ei); |
| 3138 | break; |
| 3139 | case AIN_HEAR_NOISE: { |
| 3140 | ain_hear *hptr = (ain_hear *)info; |
| 3141 | int i; |
| 3142 | |
| 3143 | if (hptr->f_directly_player) { |
| 3144 | int16_t heard_noise_obj[50]; |
| 3145 | int num_objs = fvi_QuickDistObjectList(&obj->pos, obj->roomnum, hptr->max_dist, heard_noise_obj, 50, false, true, |
| 3146 | false, true); |
| 3147 | |
| 3148 | for (i = 0; i < num_objs; i++) { |
| 3149 | if (Objects[heard_noise_obj[i]].control_type == CT_AI) { |
| 3150 | if (vm_VectorDistance(&obj->pos, &Objects[heard_noise_obj[i]].pos) < |
| 3151 | hptr->max_dist * Objects[heard_noise_obj[i]].ai_info->hearing) { |
| 3152 | AISeeTarget(&Objects[heard_noise_obj[i]], false); |
| 3153 | } |
| 3154 | } |
| 3155 | } |
| 3156 | } |
| 3157 | } break; // parent robot -- chrishack -- Not done |
| 3158 | case AIN_NEAR_TARGET: |
| 3159 | other_obj = (object *)info; |
| 3160 | break; |
| 3161 | case AIN_HIT_BY_WEAPON: { |
| 3162 | ai_info->memory[0].num_times_hit++; |
| 3163 | |
| 3164 | if (ai_info->notify_flags & (0x00000001 << notify_type)) { |
| 3165 | ai_info->awareness = AWARE_FULLY; |
| 3166 | |
| 3167 | // Flinching |
| 3168 | if (Gametime > ai_info->next_flinch_time) { |
| 3169 | if (ps_rand() % 10 > 8) { |
| 3170 | if (ai_info->flags & AIF_FLINCH) { |
| 3171 | next_anim = AS_FLINCH; |
| 3172 | GoalAddGoal(obj, AIG_SET_ANIM, (void *)&next_anim, ACTIVATION_BLEND_LEVEL); |
| 3173 | } |
| 3174 | } |
| 3175 | } |
| 3176 | } |
| 3177 | |
| 3178 | if (ai_info->sound[AI_ANGRY_SOUND] != SOUND_NONE_INDEX) { |
| 3179 | // Plays the sound and makes absolute sure that it is not looping |
| 3180 | if (Gametime - ai_info->last_sound_time[AI_ANGRY_SOUND] > 5.0f) { |
| 3181 | Sound_system.StopSoundLooping( |
| 3182 | Sound_system.Play3dSound(ai_info->sound[AI_ANGRY_SOUND], SND_PRIORITY_NORMAL, obj)); |
| 3183 | if (Game_mode & GM_MULTI) |
| 3184 | MultiPlay3dSound(ai_info->sound[AI_ANGRY_SOUND], OBJNUM(obj), SND_PRIORITY_NORMAL); |
| 3185 | if (Demo_flags == DF_RECORDING) |
| 3186 | DemoWrite3DSound(ai_info->sound[AI_ANGRY_SOUND], OBJNUM(obj), SND_PRIORITY_NORMAL); |
| 3187 | ai_info->last_sound_time[AI_ANGRY_SOUND] = Gametime; |
| 3188 | } |
| 3189 | } |
| 3190 | |
| 3191 | other_obj = (object *)info; |
| 3192 | parent = other_obj->parent_handle; |
| 3193 | new_enemy = ObjGet(parent); |
| 3194 | |
| 3195 | if (ai_info->flags & AIF_ACT_AS_NEUTRAL_UNTIL_SHOT) { |
| 3196 | ai_info->flags &= ~AIF_ACT_AS_NEUTRAL_UNTIL_SHOT; |
| 3197 | if (!AIObjEnemy(obj, new_enemy)) { |
| 3198 | ai_info->flags |= AIF_ACT_AS_NEUTRAL_UNTIL_SHOT; |
| 3199 | } |
| 3200 | } |
| 3201 | |
| 3202 | bool f_enemy = AIObjEnemy(obj, new_enemy); |
| 3203 | |
| 3204 | float rand_val = ps_rand() / (float)D3_RAND_MAX; |
| 3205 | |
| 3206 | if (new_enemy && (new_enemy != obj)) { |
| 3207 | // 20% per hit of switching to hitting player |
| 3208 | if ((new_enemy->control_type == CT_AI && |
| 3209 | ((new_enemy->ai_info->target_handle == obj->handle) || |
| 3210 | (!f_enemy && new_enemy->id == obj->id && new_enemy->type == obj->type && rand_val < ai_info->fight_same) || |
| 3211 | (!f_enemy && !(new_enemy->id == obj->id && new_enemy->type == obj->type) && |
| 3212 | rand_val < ai_info->fight_team))) || |
| 3213 | (f_enemy && new_enemy->type == OBJ_PLAYER && |
| 3214 | (ai_info->awareness <= AWARE_BARELY || rand_val > .8 || ai_info->target_handle == OBJECT_HANDLE_NONE))) { |
| 3215 | // if(obj->ai_info->flags & AIF_DETERMINE_TARGET) |
| 3216 | { |
| 3217 | ai_info->flags |= AIF_DETERMINE_TARGET; |
| 3218 | obj->ai_info->next_target_update_time = |
| 3219 | Gametime + MIN_TARGET_UPDATE_INTERVAL + |
| 3220 | ((float)ps_rand() / (float)D3_RAND_MAX) * (MAX_TARGET_UPDATE_INTERVAL - MIN_TARGET_UPDATE_INTERVAL); |
| 3221 | AISetTarget(obj, new_enemy->handle); |
| 3222 | } |
| 3223 | } |
| 3224 | } |
| 3225 | } break; |
| 3226 | |
| 3227 | case AIN_BUMPED_OBJ: |
| 3228 | other_obj = (object *)info; |
| 3229 | |
| 3230 | // 100% is previously not aware, 50% if already aware |
| 3231 | if (AIObjEnemy(obj, other_obj)) { |
| 3232 | if ((ai_info->awareness <= AWARE_BARELY) || ((ai_info->awareness > AWARE_BARELY) && ((ps_rand() % 100) > 50))) { |
| 3233 | // if(ai_info->flags & AIF_DETERMINE_TARGET) |
| 3234 | { |
| 3235 | ai_info->flags |= AIF_DETERMINE_TARGET; |
| 3236 | ai_info->next_target_update_time = |
| 3237 | Gametime + MIN_TARGET_UPDATE_INTERVAL + |
| 3238 | ((float)ps_rand() / (float)D3_RAND_MAX) * (MAX_TARGET_UPDATE_INTERVAL - MIN_TARGET_UPDATE_INTERVAL); |
| 3239 | AISetTarget(obj, other_obj->handle); |
| 3240 | } |
| 3241 | } |
| 3242 | |
| 3243 | if (ai_info->notify_flags & (0x00000001 << notify_type)) { |
| 3244 | ai_info->awareness = AWARE_FULLY; |
| 3245 | AISeeTarget(obj, false); |
| 3246 | } |
| 3247 | } |
| 3248 | |
| 3249 | if (ai_info->sound[AI_ANGRY_SOUND] != SOUND_NONE_INDEX) { |
| 3250 | // Plays the sound and makes absolute sure that it is not looping |
| 3251 | if (Gametime - ai_info->last_sound_time[AI_ANGRY_SOUND] > 5.0f) { |
| 3252 | Sound_system.StopSoundLooping( |
| 3253 | Sound_system.Play3dSound(ai_info->sound[AI_ANGRY_SOUND], SND_PRIORITY_NORMAL, obj)); |
| 3254 | if (Game_mode & GM_MULTI) |
| 3255 | MultiPlay3dSound(ai_info->sound[AI_ANGRY_SOUND], OBJNUM(obj), SND_PRIORITY_NORMAL); |
| 3256 | if (Demo_flags == DF_RECORDING) |
| 3257 | DemoWrite3DSound(ai_info->sound[AI_ANGRY_SOUND], OBJNUM(obj), SND_PRIORITY_NORMAL); |
| 3258 | ai_info->last_sound_time[AI_ANGRY_SOUND] = Gametime; |
| 3259 | } |
| 3260 | } |
| 3261 | break; |
| 3262 | case AIN_USER_DEFINED: |
| 3263 | //@$-evtargs.args[1] = MAKE_NUM_EVTARG((float)(*((int *)info))); |
| 3264 | ei.extra_info = info; |
| 3265 | break; |
| 3266 | default: |
| 3267 | mprintf(0, "Warning, %d has been notified with an unhandled notification %d\n", OBJNUM(obj), notify_type); |
| 3268 | return true; |
| 3269 | } |
| 3270 | |
| 3271 | if (notify_type != AIN_OBJ_FIRED && notify_type != AIN_HEAR_NOISE) { |
| 3272 | //@$-return (D3XExecScript(obj, EVT_AI_NOTIFY, other_obj, REF_OBJTYPE, &evtargs)); |
| 3273 | if (!f_it_set) { |
| 3274 | ei.evt_ai_notify.it_handle = ((other_obj != NULL) ? other_obj->handle : OBJECT_HANDLE_NONE); |
| 3275 | } |
| 3276 | |
| 3277 | return Osiris_CallEvent(obj, EVT_AI_NOTIFY, &ei); |
| 3278 | } |
| 3279 | |
| 3280 | return true; |
| 3281 | } |
| 3282 | |
| 3283 | // Returns the amount of time left |
| 3284 | void ai_do_animation(object *obj, float anim_time) { |
| 3285 | float *anim_frame = &obj->rtype.pobj_info.anim_frame; |
| 3286 | |
| 3287 | float to; |
| 3288 | float from; |
| 3289 | float delta; |
| 3290 | float spc; |
| 3291 | bool f_looped; |
| 3292 | bool f_notify; |
| 3293 | int i; |
| 3294 | |
| 3295 | poly_model *pm = &Poly_models[obj->rtype.pobj_info.model_num]; |
| 3296 | polyobj_info *p_info = &obj->rtype.pobj_info; |
| 3297 | |
| 3298 | if (!(Object_info[obj->id].anim)) |
| 3299 | return; |
| 3300 | |
| 3301 | if ((Demo_flags == DF_PLAYBACK) || ((Game_mode & GM_MULTI) && (Netgame.local_role == LR_CLIENT))) { |
| 3302 | |
| 3303 | // Update animation keyframe |
| 3304 | if (p_info->multi_anim_info.flags & FMA_VALID) { |
| 3305 | if (!(p_info->multi_anim_info.flags & FMA_CURRENT)) { |
| 3306 | AIUpdateAnim(obj); |
| 3307 | } |
| 3308 | } |
| 3309 | |
| 3310 | if (p_info->multi_turret_info.flags & (FMT_UPDATING | FMT_NEW_DATA)) { |
| 3311 | int count = 0; |
| 3312 | int i, j; |
| 3313 | if (p_info->multi_turret_info.flags & FMT_NEW_DATA) { |
| 3314 | for (i = 0; i < pm->num_wbs; i++) { |
| 3315 | for (j = 0; j < pm->poly_wb[i].num_turrets; j++) { |
| 3316 | p_info->multi_turret_info.last_time = Gametime; |
| 3317 | p_info->multi_turret_info.last_keyframes[count++] = obj->dynamic_wb[i].norm_turret_angle[j]; |
| 3318 | } |
| 3319 | } |
| 3320 | |
| 3321 | p_info->multi_turret_info.flags = FMT_UPDATING; |
| 3322 | } |
| 3323 | |
| 3324 | count = 0; |
| 3325 | |
| 3326 | if ((Demo_flags == DF_PLAYBACK) || |
| 3327 | ((p_info->multi_turret_info.last_time + 1.0 / (float)NetPlayers[Player_num].pps) >= Gametime)) { |
| 3328 | for (i = 0; i < pm->num_wbs; i++) { |
| 3329 | for (j = 0; j < pm->poly_wb[i].num_turrets; j++) { |
| 3330 | obj->dynamic_wb[i].norm_turret_angle[j] = p_info->multi_turret_info.keyframes[count++]; |
| 3331 | } |
| 3332 | } |
| 3333 | |
| 3334 | p_info->multi_turret_info.flags = 0; |
| 3335 | } else { |
| 3336 | for (i = 0; i < pm->num_wbs; i++) { |
| 3337 | for (j = 0; j < pm->poly_wb[i].num_turrets; j++) { |
| 3338 | float pd = (Gametime - p_info->multi_turret_info.last_time) / NetPlayers[Player_num].pps; |
| 3339 | float diff; |
| 3340 | |
| 3341 | diff = p_info->multi_turret_info.keyframes[count] - p_info->multi_turret_info.last_keyframes[count]; |
| 3342 | |
| 3343 | if (fabsf(diff) < 0.5f) { |
| 3344 | obj->dynamic_wb[i].norm_turret_angle[j] = (1.0 - pd) * p_info->multi_turret_info.last_keyframes[count] + |
| 3345 | pd * p_info->multi_turret_info.keyframes[count]; |
| 3346 | } else { |
| 3347 | diff = -(1.0f - diff) * pd; |
| 3348 | obj->dynamic_wb[i].norm_turret_angle[j] = p_info->multi_turret_info.last_keyframes[count] + diff; |
| 3349 | |
| 3350 | if (obj->dynamic_wb[i].norm_turret_angle[j] < 0.0) |
| 3351 | obj->dynamic_wb[i].norm_turret_angle[j] += 1.0f; |
| 3352 | else if (obj->dynamic_wb[i].norm_turret_angle[j] > 1.0) |
| 3353 | obj->dynamic_wb[i].norm_turret_angle[j] -= 1.0f; |
| 3354 | } |
| 3355 | |
| 3356 | count++; |
| 3357 | } |
| 3358 | } |
| 3359 | } |
| 3360 | } |
| 3361 | } else { |
| 3362 | if (obj->ai_info->animation_type == AS_RANGED_ATTACK) { |
| 3363 | char wb = obj->ai_info->last_special_wb_firing; |
| 3364 | |
| 3365 | if (Object_info[obj->id].static_wb[wb].flags & WBF_SPRAY) { |
| 3366 | obj->weapon_fire_flags |= WFF_SPRAY; |
| 3367 | } |
| 3368 | |
| 3369 | if (Object_info[obj->id].static_wb[wb].flags & WBF_ON_OFF) { |
| 3370 | obj->weapon_fire_flags |= WFF_ON_OFF; |
| 3371 | } |
| 3372 | if (Demo_flags == DF_RECORDING) { |
| 3373 | DemoWriteObjWeapFireFlagChanged(OBJNUM(obj)); |
| 3374 | } |
| 3375 | } |
| 3376 | } |
| 3377 | |
| 3378 | for (i = 0; i < pm->num_wbs; i++) { |
| 3379 | if (obj->dynamic_wb[i].flags & DWBF_ANIMATING) { |
| 3380 | object_info *obj_info = &Object_info[obj->id]; |
| 3381 | if (obj_info->static_wb) |
| 3382 | WBFireAnimFrame(obj, &obj_info->static_wb[i], i); |
| 3383 | } |
| 3384 | } |
| 3385 | |
| 3386 | start_loop: |
| 3387 | |
| 3388 | from = obj->rtype.pobj_info.anim_start_frame; |
| 3389 | to = obj->rtype.pobj_info.anim_end_frame; |
| 3390 | spc = obj->rtype.pobj_info.anim_time; |
| 3391 | |
| 3392 | if (obj->movement_type == MT_WALKING && obj->ai_info->movement_type == MC_WALKING) { |
| 3393 | if (obj->ai_info->animation_type == AS_ALERT || obj->ai_info->animation_type == AS_IDLE) { |
| 3394 | float scaler; |
| 3395 | |
| 3396 | float speed = vm_GetMagnitude(&obj->mtype.phys_info.velocity); |
| 3397 | scaler = speed / obj->ai_info->max_velocity; |
| 3398 | |
| 3399 | // If slow, use some rotational vel |
| 3400 | if (scaler < .7f) { |
| 3401 | float speed = vm_GetMagnitude(&obj->mtype.phys_info.rotvel); |
| 3402 | scaler += speed / 40000.0f; |
| 3403 | |
| 3404 | if (scaler > 1.0f) |
| 3405 | scaler = 1.0f; |
| 3406 | } |
| 3407 | |
| 3408 | if ((obj->ai_info->next_animation_type == AS_GOTO_ALERT_STANDING || |
| 3409 | obj->ai_info->next_animation_type == AS_GOTO_IDLE_STANDING) && |
| 3410 | scaler < .15f) { |
| 3411 | scaler = .15f; |
| 3412 | } |
| 3413 | |
| 3414 | if (scaler <= 0.0f) { |
| 3415 | return; |
| 3416 | } |
| 3417 | |
| 3418 | spc /= scaler; |
| 3419 | } |
| 3420 | } |
| 3421 | // mprintf(0, "AI ANIM %d %d\n", from, to); |
| 3422 | |
| 3423 | f_looped = (obj->rtype.pobj_info.anim_flags & AIAF_LOOPING) != 0; |
| 3424 | f_notify = (obj->rtype.pobj_info.anim_flags & AIAF_NOTIFY) != 0; |
| 3425 | |
| 3426 | if (!f_looped && *anim_frame == to) { |
| 3427 | goto done; |
| 3428 | } |
| 3429 | |
| 3430 | if (to == from) { |
| 3431 | anim_time = 0.0f; |
| 3432 | goto done; |
| 3433 | } |
| 3434 | |
| 3435 | if (spc <= 0) { |
| 3436 | *anim_frame = to; |
| 3437 | goto done; |
| 3438 | } |
| 3439 | |
| 3440 | ASSERT(from <= to); |
| 3441 | |
| 3442 | if (*anim_frame < from || *anim_frame > to) { |
| 3443 | mprintf(0, "AI/Animation: Correcting for an incorrect frame number\n"); |
| 3444 | *anim_frame = from; |
| 3445 | } |
| 3446 | |
| 3447 | delta = to - from; |
| 3448 | |
| 3449 | ASSERT(delta >= 0.0f); |
| 3450 | ASSERT(spc > 0.0f); |
| 3451 | |
| 3452 | if (delta > 0.0f) { |
| 3453 | // step is how much we move this frame |
| 3454 | float max_step = anim_time * ((delta) / spc); |
| 3455 | |
| 3456 | if (*anim_frame + max_step >= to) { |
| 3457 | anim_time -= anim_time * (to - *anim_frame) / max_step; |
| 3458 | |
| 3459 | if (f_looped) |
| 3460 | *anim_frame = from; |
| 3461 | else |
| 3462 | *anim_frame = to; |
| 3463 | |
| 3464 | if (f_notify) { |
| 3465 | // mprintf(0, "Animation ended\n"); |
| 3466 | AINotify(obj, AIN_ANIM_COMPLETE, NULL); |
| 3467 | } |
| 3468 | |
| 3469 | goto start_loop; |
| 3470 | } else { |
| 3471 | *anim_frame += max_step; |
| 3472 | } |
| 3473 | } else { |
| 3474 | obj->rtype.pobj_info.anim_frame = from; |
| 3475 | } |
| 3476 | |
| 3477 | if (obj->rtype.pobj_info.anim_frame + 0.001 < from || obj->rtype.pobj_info.anim_frame > to) { |
| 3478 | mprintf(2, "AI ANIM from %0.6f (%0.6f) to %0.6f\n", from, obj->rtype.pobj_info.anim_frame, to); |
| 3479 | } |
| 3480 | if (obj->rtype.pobj_info.anim_frame < from) { |
| 3481 | obj->rtype.pobj_info.anim_frame = from; |
| 3482 | } |
| 3483 | if (obj->rtype.pobj_info.anim_frame > to) { |
| 3484 | obj->rtype.pobj_info.anim_frame = to; |
| 3485 | } |
| 3486 | |
| 3487 | return; |
| 3488 | |
| 3489 | done: |
| 3490 | |
| 3491 | if (f_notify) { |
| 3492 | AINotify(obj, AIN_ANIM_COMPLETE, NULL); |
| 3493 | } |
| 3494 | |
| 3495 | return; |
| 3496 | } |
| 3497 | |
| 3498 | #define FRR_MAX_TRIES 15 |
| 3499 | |
| 3500 | // MTS: Unused? |
| 3501 | int AIGoalGotoRandomRoom() { return -1; } |
| 3502 | |
| 3503 | int AIFindRandomRoom(object *obj, ai_frame *ai_info, goal *goal_ptr, int avoid_room, int min_depth, int max_depth, |
| 3504 | bool f_check_path, bool f_cur_room_ok, int *depth) { |
| 3505 | int random_room = obj->roomnum; |
| 3506 | int n_tries = 0; |
| 3507 | bool valid = false; |
| 3508 | bool f_use_depth = false; |
| 3509 | int cur_depth; |
| 3510 | int cur_room = obj->roomnum; |
| 3511 | int mine_rooms[MAX_ROOMS]; |
| 3512 | int num_mine_rooms = 0; |
| 3513 | int cur_mine = MINE_INDEX(obj->roomnum); |
| 3514 | int i; |
| 3515 | |
| 3516 | for (i = 0; i <= Highest_room_index; i++) { |
| 3517 | if (Rooms[i].used && !(Rooms[i].flags & RF_EXTERNAL) && cur_mine == MINE_INDEX(i)) { |
| 3518 | mine_rooms[num_mine_rooms++] = i; |
| 3519 | ASSERT(Rooms[mine_rooms[num_mine_rooms - 1]].used); |
| 3520 | } |
| 3521 | } |
| 3522 | |
| 3523 | if (max_depth >= 0 && min_depth >= 0) { |
| 3524 | f_use_depth = true; |
| 3525 | cur_depth = min_depth + (float)ps_rand() / (float)D3_RAND_MAX * (max_depth - min_depth); |
| 3526 | } |
| 3527 | |
| 3528 | do { |
| 3529 | random_room = mine_rooms[ps_rand() % num_mine_rooms]; |
| 3530 | valid = true; |
| 3531 | |
| 3532 | if (random_room == avoid_room || ((!f_cur_room_ok) && (random_room == obj->roomnum)) || (!Rooms[random_room].used)) |
| 3533 | valid = false; |
| 3534 | |
| 3535 | if (valid && f_check_path) { |
| 3536 | ASSERT(Rooms[random_room].used); |
| 3537 | ASSERT(Rooms[obj->roomnum].used); |
| 3538 | valid = AIPathAllocPath(obj, ai_info, goal_ptr, &obj->roomnum, &obj->pos, &random_room, |
| 3539 | &Rooms[random_room].path_pnt, 0.0f, 0, obj->handle); |
| 3540 | } |
| 3541 | |
| 3542 | n_tries++; |
| 3543 | } while (!valid && n_tries <= FRR_MAX_TRIES && num_mine_rooms > 1); |
| 3544 | |
| 3545 | if (valid && f_use_depth) { |
| 3546 | while (cur_room != random_room && cur_depth > 0) { |
| 3547 | cur_room = BOA_NEXT_ROOM(cur_room, random_room); |
| 3548 | cur_depth--; |
| 3549 | } |
| 3550 | |
| 3551 | random_room = cur_room; |
| 3552 | } |
| 3553 | |
| 3554 | if (!valid) { |
| 3555 | int next_rooms[100]; |
| 3556 | int i; |
| 3557 | int pick_list[100]; |
| 3558 | int num_pickable = 0; |
| 3559 | |
| 3560 | int num_next_rooms = AIMakeNextRoomList(obj->roomnum, next_rooms, 100); |
| 3561 | for (i = 0; i < num_next_rooms; i++) { |
| 3562 | if (next_rooms[i] <= Highest_room_index && |
| 3563 | BOA_DetermineStartRoomPortal(obj->roomnum, NULL, next_rooms[i], NULL) >= 0) { |
| 3564 | pick_list[num_pickable++] = next_rooms[i]; |
| 3565 | } |
| 3566 | } |
| 3567 | |
| 3568 | if (num_pickable) { |
| 3569 | random_room = pick_list[ps_rand() % num_pickable]; |
| 3570 | valid = true; |
| 3571 | } |
| 3572 | |
| 3573 | if (!valid) { |
| 3574 | mprintf(0, "AI: Wander is generating the same room :(\n"); |
| 3575 | random_room = obj->roomnum; |
| 3576 | } |
| 3577 | } |
| 3578 | |
| 3579 | ASSERT(random_room >= 0 || random_room <= Highest_room_index + BOA_num_terrain_regions); |
| 3580 | if (random_room > Highest_room_index) { |
| 3581 | // This is a temporary chrishack -- we need to select a random cell in the region |
| 3582 | random_room = ps_rand() % (TERRAIN_WIDTH * TERRAIN_DEPTH); |
| 3583 | random_room |= 0x80000000; |
| 3584 | } |
| 3585 | |
| 3586 | return random_room; |
| 3587 | } |
| 3588 | |
| 3589 | // +/- 8% fluctuation in speed parameters |
| 3590 | #define MAX_FLUCTUATION_PERCENT 0.08f |
| 3591 | |
| 3592 | void AIDestroyObj(object *obj) { |
| 3593 | ai_frame *ai_info = obj->ai_info; |
| 3594 | |
| 3595 | #ifdef _DEBUG |
| 3596 | if (AI_debug_robot_do && OBJNUM(obj) == AI_debug_robot_index) { |
| 3597 | mprintf(0, "AI Note: In free path\n"); |
| 3598 | } |
| 3599 | #endif |
| 3600 | AIPathFreePath(&ai_info->path); |
| 3601 | } |
| 3602 | |
| 3603 | // Copies AI settings from the object info struct to the object struct |
| 3604 | void ObjSetAIInfo(object *objp) { |
| 3605 | int i; |
| 3606 | |
| 3607 | ai_frame *dest = objp->ai_info; |
| 3608 | ASSERT(dest != NULL); |
| 3609 | if (!(Object_info[objp->id].ai_info)) |
| 3610 | return; |
| 3611 | |
| 3612 | t_ai_info *src = Object_info[objp->id].ai_info; |
| 3613 | |
| 3614 | dest->ai_class = src->ai_class; |
| 3615 | dest->ai_type = src->ai_type; |
| 3616 | |
| 3617 | dest->max_velocity = src->max_velocity; |
| 3618 | dest->max_delta_velocity = src->max_delta_velocity; |
| 3619 | dest->max_turn_rate = src->max_turn_rate; |
| 3620 | dest->max_delta_turn_rate = src->max_delta_turn_rate; |
| 3621 | |
| 3622 | dest->attack_vel_percent = src->attack_vel_percent; |
| 3623 | dest->flee_vel_percent = src->flee_vel_percent; |
| 3624 | dest->dodge_vel_percent = src->dodge_vel_percent; |
| 3625 | |
| 3626 | dest->circle_distance = src->circle_distance; |
| 3627 | dest->dodge_percent = src->dodge_percent; |
| 3628 | |
| 3629 | // Note: Chris is evil. There should be a symbolic to describe the size of these arrays |
| 3630 | for (i = 0; i < 2; i++) { |
| 3631 | dest->melee_damage[i] = src->melee_damage[i]; |
| 3632 | dest->melee_latency[i] = src->melee_latency[i]; |
| 3633 | } |
| 3634 | |
| 3635 | for (i = 0; i < MAX_AI_SOUNDS; i++) |
| 3636 | dest->sound[i] = src->sound[i]; |
| 3637 | |
| 3638 | dest->movement_type = src->movement_type; |
| 3639 | dest->movement_subtype = src->movement_subtype; |
| 3640 | |
| 3641 | dest->flags = src->flags; |
| 3642 | dest->notify_flags = src->notify_flags; |
| 3643 | |
| 3644 | dest->fov = src->fov; |
| 3645 | |
| 3646 | dest->avoid_friends_distance = src->avoid_friends_distance; |
| 3647 | |
| 3648 | dest->frustration = src->frustration; |
| 3649 | dest->curiousity = src->curiousity; |
| 3650 | dest->life_preservation = src->life_preservation; |
| 3651 | dest->agression = src->agression; |
| 3652 | |
| 3653 | dest->fire_spread = src->fire_spread; |
| 3654 | dest->night_vision = src->night_vision; |
| 3655 | dest->fog_vision = src->fog_vision; |
| 3656 | dest->lead_accuracy = src->lead_accuracy; |
| 3657 | dest->lead_varience = src->lead_varience; |
| 3658 | dest->fight_team = src->fight_team; |
| 3659 | dest->fight_same = src->fight_same; |
| 3660 | dest->hearing = src->hearing; |
| 3661 | dest->roaming = src->roaming; |
| 3662 | dest->biased_flight_importance = src->biased_flight_importance; |
| 3663 | dest->biased_flight_min = src->biased_flight_min; |
| 3664 | dest->biased_flight_max = src->biased_flight_max; |
| 3665 | } |
| 3666 | |
| 3667 | bool AIInit(object *obj, uint8_t ai_class, uint8_t ai_type, uint8_t ai_movement) { |
| 3668 | ai_frame *ai_info = obj->ai_info; |
| 3669 | ASSERT(ai_info); |
| 3670 | ASSERT(obj->control_type == CT_AI && obj->type != OBJ_NONE); |
| 3671 | |
| 3672 | // Get AI data from the object type info |
| 3673 | ASSERT(IS_GENERIC(obj->type)); |
| 3674 | ObjSetAIInfo(obj); |
| 3675 | |
| 3676 | polyobj_info *p_info = &obj->rtype.pobj_info; |
| 3677 | ai_path_info *path = &ai_info->path; |
| 3678 | int i; |
| 3679 | int anim; |
| 3680 | |
| 3681 | AIPathInitPath(path); |
| 3682 | |
| 3683 | bool f_no_scale = (IS_GENERIC(obj->type) && (Object_info[obj->id].flags & OIF_NO_DIFF_SCALE_MOVE)) || |
| 3684 | ((ai_info->flags & AIF_TEAM_MASK) == AIF_TEAM_REBEL); |
| 3685 | |
| 3686 | ai_info->mem_time_till_next_update = 3.0f + (float)ps_rand() / (float)D3_RAND_MAX * 2.0f; |
| 3687 | memset(ai_info->memory, 0, sizeof(ai_mem) * AI_MEM_DEPTH); |
| 3688 | for (i = 0; i < AI_MEM_DEPTH; i++) { |
| 3689 | ai_info->memory[0].shields = obj->shields; |
| 3690 | } |
| 3691 | |
| 3692 | // In case there is none |
| 3693 | obj->rtype.pobj_info.anim_frame = 0.0; |
| 3694 | |
| 3695 | ai_info->ai_class = ai_class; |
| 3696 | ai_info->ai_type = ai_type; |
| 3697 | ai_info->movement_type = ai_movement; |
| 3698 | ai_info->next_movement = AI_INVALID_INDEX; |
| 3699 | ai_info->anim_sound_handle = 0; |
| 3700 | ai_info->status_reg = 0; |
| 3701 | ai_info->last_played_sound_index = -1; |
| 3702 | ai_info->weapon_speed = 0.0f; |
| 3703 | |
| 3704 | ai_info->vec_to_target_perceived = obj->orient.fvec; |
| 3705 | |
| 3706 | ai_info->last_dodge_dir = Zero_vector; |
| 3707 | ai_info->dodge_till_time = Gametime - 1.0f; |
| 3708 | |
| 3709 | if (ObjGet(obj->parent_handle)) { |
| 3710 | object *parent = ObjGet(obj->parent_handle); |
| 3711 | |
| 3712 | if (parent && (parent->type == OBJ_PLAYER || parent->type == OBJ_GHOST)) { |
| 3713 | obj->ai_info->flags &= ~AIF_TEAM_MASK; |
| 3714 | obj->ai_info->flags |= AIF_TEAM_REBEL; |
| 3715 | } |
| 3716 | } |
| 3717 | |
| 3718 | for (i = 0; i < MAX_AI_SOUNDS; i++) { |
| 3719 | ai_info->last_sound_time[i] = Gametime; |
| 3720 | } |
| 3721 | |
| 3722 | // Set up the robot to walk if it is applicable |
| 3723 | if (ai_info->movement_type == MC_WALKING) { |
| 3724 | if (Object_info[obj->id].anim[MC_STANDING].elem[AS_ALERT].to) |
| 3725 | ai_info->movement_type = MC_STANDING; |
| 3726 | |
| 3727 | obj->movement_type = MT_WALKING; |
| 3728 | } |
| 3729 | |
| 3730 | if ((ObjGet(obj->parent_handle) || Matcen_created) && (Object_info[obj->id].anim[ai_movement].elem[AS_BIRTH].to)) { |
| 3731 | anim = AS_BIRTH; |
| 3732 | ai_info->next_animation_type = AS_IDLE; |
| 3733 | p_info->anim_flags = AIAF_NOTIFY; |
| 3734 | |
| 3735 | p_info->anim_start_frame = Object_info[obj->id].anim[ai_movement].elem[anim].from; |
| 3736 | p_info->anim_end_frame = Object_info[obj->id].anim[ai_movement].elem[anim].to; |
| 3737 | p_info->anim_time = Object_info[obj->id].anim[ai_movement].elem[anim].spc; |
| 3738 | p_info->anim_frame = Object_info[obj->id].anim[ai_movement].elem[anim].from; |
| 3739 | } else { |
| 3740 | anim = AS_IDLE; |
| 3741 | |
| 3742 | if (Object_info[obj->id].anim[ai_movement].elem[anim].to == 0.0f) |
| 3743 | anim = AS_ALERT; |
| 3744 | |
| 3745 | ai_info->next_animation_type = AI_INVALID_INDEX; |
| 3746 | p_info->anim_flags = AIAF_LOOPING; |
| 3747 | |
| 3748 | // Setup the initial animation state info |
| 3749 | float rand_offset = ps_rand() / ((float)D3_RAND_MAX); |
| 3750 | p_info->anim_start_frame = Object_info[obj->id].anim[ai_movement].elem[anim].from; |
| 3751 | p_info->anim_end_frame = Object_info[obj->id].anim[ai_movement].elem[anim].to; |
| 3752 | p_info->anim_time = Object_info[obj->id].anim[ai_movement].elem[anim].spc; |
| 3753 | p_info->anim_frame = (rand_offset)*Object_info[obj->id].anim[ai_movement].elem[anim].from + |
| 3754 | (1.0f - rand_offset) * Object_info[obj->id].anim[ai_movement].elem[anim].to; |
| 3755 | } |
| 3756 | |
| 3757 | ai_info->animation_type = anim; |
| 3758 | |
| 3759 | if (Object_info[obj->id].anim[ai_movement].elem[anim].anim_sound_index != SOUND_NONE_INDEX) { |
| 3760 | |
| 3761 | if (!Viewer_object || !Player_object) { |
| 3762 | Player_object = &Objects[0]; |
| 3763 | Viewer_object = Player_object; |
| 3764 | } |
| 3765 | |
| 3766 | // Accounts for sound loading |
| 3767 | if ((obj->handle & HANDLE_COUNT_MASK) != 0) { |
| 3768 | ai_info->last_played_sound_index = Object_info[obj->id].anim[ai_movement].elem[anim].anim_sound_index; |
| 3769 | ai_info->anim_sound_handle = Sound_system.Play3dSound( |
| 3770 | Object_info[obj->id].anim[ai_movement].elem[anim].anim_sound_index, SND_PRIORITY_LOW, obj); |
| 3771 | } else { |
| 3772 | ai_info->last_played_sound_index = -1; |
| 3773 | } |
| 3774 | } else { |
| 3775 | ai_info->last_played_sound_index = -1; |
| 3776 | } |
| 3777 | |
| 3778 | ai_info->next_melee_time = Gametime; |
| 3779 | ai_info->next_flinch_time = Gametime; |
| 3780 | AISetTarget(obj, OBJECT_HANDLE_NONE); |
| 3781 | ai_info->next_check_see_target_time = Gametime + (float)ps_rand() / (float)D3_RAND_MAX; |
| 3782 | ai_info->last_see_target_time = Gametime - CHECK_VIS_INFREQUENTLY_TIME * 2.0f; |
| 3783 | ai_info->last_hear_target_time = Gametime - CHECK_VIS_INFREQUENTLY_TIME * 2.0f; |
| 3784 | ai_info->last_render_time = -1.0f; |
| 3785 | ai_info->next_target_update_time = Gametime; |
| 3786 | |
| 3787 | if (ai_info->flags & AIF_FLUCTUATE_SPEED_PROPERTIES) { |
| 3788 | ai_info->max_velocity *= |
| 3789 | 1.0f + (((float)ps_rand() - D3_RAND_MAX * 0.5f) / (D3_RAND_MAX * 0.5f)) * MAX_FLUCTUATION_PERCENT; |
| 3790 | ai_info->max_delta_velocity *= |
| 3791 | 1.0f + (((float)ps_rand() - D3_RAND_MAX * 0.5f) / (D3_RAND_MAX * 0.5f)) * MAX_FLUCTUATION_PERCENT; |
| 3792 | ai_info->max_turn_rate *= |
| 3793 | 1.0f + (((float)ps_rand() - D3_RAND_MAX * 0.5f) / (D3_RAND_MAX * 0.5f)) * MAX_FLUCTUATION_PERCENT; |
| 3794 | } |
| 3795 | |
| 3796 | ai_info->notify_flags |= AI_NOTIFIES_ALWAYS_ON; |
| 3797 | |
| 3798 | ai_info->awareness = AWARE_NONE; |
| 3799 | |
| 3800 | // Apply difficulty settings |
| 3801 | ai_info->dodge_percent *= (f_no_scale) ? 1.0f : Diff_ai_dodge_percent[DIFF_LEVEL]; |
| 3802 | ai_info->dodge_vel_percent *= (f_no_scale) ? 1.0f : Diff_ai_dodge_speed[DIFF_LEVEL]; |
| 3803 | ai_info->max_velocity *= (f_no_scale || obj->movement_type == MT_WALKING) ? 1.0f : Diff_ai_speed[DIFF_LEVEL]; |
| 3804 | ai_info->max_turn_rate *= (f_no_scale || obj->movement_type == MT_WALKING) ? 1.0f : Diff_ai_rotspeed[DIFF_LEVEL]; |
| 3805 | ai_info->circle_distance *= (f_no_scale) ? 1.0f : Diff_ai_circle_dist[DIFF_LEVEL]; |
| 3806 | |
| 3807 | ai_info->last_see_target_pos = obj->pos; |
| 3808 | |
| 3809 | ai_info->vec_to_target_actual = obj->orient.fvec; |
| 3810 | ai_info->vec_to_target_perceived = obj->orient.fvec; |
| 3811 | |
| 3812 | ai_info->dist_to_target_actual = vm_NormalizeVector(&ai_info->vec_to_target_actual); |
| 3813 | ai_info->dist_to_target_perceived = 10000.0f; |
| 3814 | |
| 3815 | // Clear out the goals |
| 3816 | GoalInitTypeGoals(obj, ai_info->ai_type); |
| 3817 | |
| 3818 | if (IS_GUIDEBOT(obj)) |
| 3819 | ai_info->flags |= AIF_DODGE; |
| 3820 | |
| 3821 | return true; |
| 3822 | } |
| 3823 | |
| 3824 | // chrishack -- fix the problem with the object being needed for AIInit |
| 3825 | void AISetDefault(t_ai_info *ai_info_ptr) {} |
| 3826 | |
| 3827 | void AIInitAll() { |
| 3828 | int i; |
| 3829 | |
| 3830 | mprintf(0, "Initializing AI systems\n"); |
| 3831 | |
| 3832 | // Initialize the terrain AI system |
| 3833 | ait_Init(); |
| 3834 | |
| 3835 | // Make sure that the buddies are located |
| 3836 | for (i = 0; i < MAX_PLAYERS; i++) { |
| 3837 | Buddy_handle[i] = OBJECT_HANDLE_NONE; |
| 3838 | } |
| 3839 | |
| 3840 | // Initialize the room AI system |
| 3841 | |
| 3842 | // Now, initialize each AI object |
| 3843 | for (i = 0; i <= Highest_object_index; i++) |
| 3844 | if (Objects[i].type != OBJ_NONE && Objects[i].control_type == CT_AI) { |
| 3845 | ASSERT(Objects[i].ai_info); |
| 3846 | AIInit(&Objects[i], Objects[i].ai_info->ai_class, Objects[i].ai_info->ai_type, Objects[i].ai_info->movement_type); |
| 3847 | } |
| 3848 | |
| 3849 | AI_NumRendered = 0; |
| 3850 | AI_NumHostileAlert = 0; |
| 3851 | |
| 3852 | if (!(Game_mode & GM_MULTI)) { |
| 3853 | int objnum = |
| 3854 | ObjCreate(OBJ_ROBOT, ROBOT_GUIDEBOT, Player_object->roomnum, &Player_object->pos, NULL, Player_object->handle); |
| 3855 | if (objnum > -1) { // DAJ -1FIX |
| 3856 | Buddy_handle[0] = Objects[objnum].handle; |
| 3857 | ObjGhostObject(objnum); |
| 3858 | } |
| 3859 | } else if (Netgame.flags & NF_ALLOWGUIDEBOT) { |
| 3860 | int i; |
| 3861 | |
| 3862 | for (i = 0; i < MAX_PLAYERS; i++) { |
| 3863 | if (Netgame.local_role == LR_CLIENT) { |
| 3864 | Buddy_handle[i] = OBJECT_HANDLE_NONE; |
| 3865 | } else { |
| 3866 | int parent_handle; |
| 3867 | |
| 3868 | if (Players[i].objnum < 0 || Players[i].objnum > Highest_object_index || |
| 3869 | Objects[Players[i].objnum].type == OBJ_NONE) { |
| 3870 | parent_handle = OBJECT_HANDLE_NONE; |
| 3871 | } else { |
| 3872 | parent_handle = Objects[Players[i].objnum].handle; |
| 3873 | } |
| 3874 | |
| 3875 | // BLACKPYRO |
| 3876 | int objnum = |
| 3877 | ObjCreate(OBJ_ROBOT, ROBOT_GUIDEBOT, Player_object->roomnum, &Player_object->pos, NULL, parent_handle); |
| 3878 | if (objnum > -1) { // DAJ -1FIX |
| 3879 | Buddy_handle[i] = Objects[objnum].handle; |
| 3880 | ObjGhostObject(objnum); |
| 3881 | } |
| 3882 | } |
| 3883 | } |
| 3884 | } |
| 3885 | |
| 3886 | mprintf(0, "Done Initializing AI systems\n"); |
| 3887 | } |
| 3888 | |
| 3889 | void AICheckTargetVis(object *obj) { |
| 3890 | ai_frame *ai_info = obj->ai_info; |
| 3891 | object *target = ObjGet(ai_info->target_handle); |
| 3892 | |
| 3893 | #ifdef _DEBUG |
| 3894 | if (AI_debug_robot_do && OBJNUM(obj) == AI_debug_robot_index) { |
| 3895 | mprintf(0, "AI Note: Vis 1\n"); |
| 3896 | } |
| 3897 | #endif |
| 3898 | |
| 3899 | #ifdef _DEBUG |
| 3900 | if (!Game_do_ai_vis) { |
| 3901 | ai_info->status_reg &= ~AISR_SEES_GOAL; |
| 3902 | ai_info->last_see_target_pos = obj->pos; |
| 3903 | return; |
| 3904 | } |
| 3905 | #endif |
| 3906 | |
| 3907 | if (target == NULL) { |
| 3908 | ai_info->status_reg &= ~AISR_SEES_GOAL; |
| 3909 | ai_info->last_see_target_pos = obj->pos; |
| 3910 | return; |
| 3911 | } |
| 3912 | |
| 3913 | #ifdef _DEBUG |
| 3914 | if (AI_debug_robot_do && OBJNUM(obj) == AI_debug_robot_index) { |
| 3915 | mprintf(0, "AI Note: Vis 2\n"); |
| 3916 | } |
| 3917 | #endif |
| 3918 | |
| 3919 | if (!BOA_IsVisible(obj->roomnum, target->roomnum)) { |
| 3920 | ai_info->status_reg &= ~AISR_SEES_GOAL; |
| 3921 | return; |
| 3922 | } |
| 3923 | |
| 3924 | #ifdef _DEBUG |
| 3925 | if (AI_debug_robot_do && OBJNUM(obj) == AI_debug_robot_index) { |
| 3926 | mprintf(0, "AI Note: Vis 3\n"); |
| 3927 | } |
| 3928 | #endif |
| 3929 | |
| 3930 | vector pos; |
| 3931 | AIDetermineAimPoint(obj, target, &pos); |
| 3932 | ai_info->vec_to_target_actual = pos - obj->pos; |
| 3933 | ai_info->dist_to_target_actual = vm_NormalizeVector(&ai_info->vec_to_target_actual); |
| 3934 | ai_info->dist_to_target_actual -= (obj->size + target->size); |
| 3935 | if (ai_info->dist_to_target_actual < 0.0f) |
| 3936 | ai_info->dist_to_target_actual = 0.0f; |
| 3937 | |
| 3938 | vector fov_vec; |
| 3939 | AIDetermineFovVec(obj, &fov_vec); |
| 3940 | |
| 3941 | if (ai_info->vec_to_target_actual * fov_vec < ai_info->fov) { |
| 3942 | ai_info->status_reg &= ~AISR_SEES_GOAL; |
| 3943 | return; |
| 3944 | } |
| 3945 | |
| 3946 | #ifdef _DEBUG |
| 3947 | if (AI_debug_robot_do && OBJNUM(obj) == AI_debug_robot_index) { |
| 3948 | mprintf(0, "AI Note: Vis 4\n"); |
| 3949 | } |
| 3950 | #endif |
| 3951 | |
| 3952 | if (ai_info->dist_to_target_actual > MAX_TRACK_TARGET_DIST * Diff_ai_vis_dist[DIFF_LEVEL] && |
| 3953 | (!ObjGet(ai_info->target_handle) || (obj->roomnum != ObjGet(ai_info->target_handle)->roomnum))) { |
| 3954 | ai_info->status_reg &= ~AISR_SEES_GOAL; |
| 3955 | return; |
| 3956 | } |
| 3957 | |
| 3958 | #ifdef _DEBUG |
| 3959 | if (AI_debug_robot_do && OBJNUM(obj) == AI_debug_robot_index) { |
| 3960 | mprintf(0, "AI Note: Vis 5\n"); |
| 3961 | } |
| 3962 | #endif |
| 3963 | |
| 3964 | if (ai_info->awareness == AWARE_NONE && (target->roomnum != obj->roomnum) && |
| 3965 | ai_info->dist_to_target_actual > MAX_SEE_TARGET_DIST * Diff_ai_vis_dist[DIFF_LEVEL]) { |
| 3966 | ai_info->status_reg &= ~AISR_SEES_GOAL; |
| 3967 | return; |
| 3968 | } |
| 3969 | |
| 3970 | #ifdef _DEBUG |
| 3971 | if (AI_debug_robot_do && OBJNUM(obj) == AI_debug_robot_index) { |
| 3972 | mprintf(0, "AI Note: Vis 6\n"); |
| 3973 | } |
| 3974 | #endif |
| 3975 | |
| 3976 | if ((ai_info->dist_to_target_actual > MAX_SEE_TARGET_DIST * Diff_ai_vis_dist[DIFF_LEVEL] && |
| 3977 | ai_info->awareness <= AWARE_BARELY && (target->roomnum != obj->roomnum)) || |
| 3978 | (target->type == OBJ_PLAYER && (Players[target->id].flags & (PLAYER_FLAGS_DEAD | PLAYER_FLAGS_DYING))) || |
| 3979 | target->type == OBJ_GHOST || !AIDetermineObjVisLevel(obj, target)) { |
| 3980 | //. mprintf(0, "No check vis\n"); |
| 3981 | ai_info->status_reg &= ~AISR_SEES_GOAL; |
| 3982 | return; |
| 3983 | } |
| 3984 | |
| 3985 | #ifdef _DEBUG |
| 3986 | if (AI_debug_robot_do && OBJNUM(obj) == AI_debug_robot_index) { |
| 3987 | mprintf(0, "AI Note: Vis 7\n"); |
| 3988 | } |
| 3989 | #endif |
| 3990 | |
| 3991 | // Can I see the target? |
| 3992 | if (Gametime - ai_info->last_see_target_time > MIN_VIS_RECENT_CHECK_INTERVAL) { |
| 3993 | if (Gametime >= ai_info->next_check_see_target_time) { |
| 3994 | // float dist; |
| 3995 | fvi_info hit_info; |
| 3996 | fvi_query fq; |
| 3997 | int fate; |
| 3998 | |
| 3999 | // Project a ray and see if target is around. -- We can use a quick room check to see if we should even do it. :) |
| 4000 | // --chrishack (do this later when room structure is in the game) |
| 4001 | // if we are in the same room, see see the target |
| 4002 | // Do FVI_stuff (maybe just a room connection check) |
| 4003 | |
| 4004 | // shoot a ray from the light position to the current vertex |
| 4005 | fq.p0 = &obj->pos; |
| 4006 | fq.p1 = &target->pos; |
| 4007 | fq.startroom = obj->roomnum; |
| 4008 | |
| 4009 | fq.rad = 0.0f; |
| 4010 | fq.flags = FQ_CHECK_OBJS | FQ_IGNORE_POWERUPS | FQ_IGNORE_WEAPONS | FQ_NO_RELINK /* | FQ_IGNORE_MOVING_OBJECTS*/; |
| 4011 | if (ai_info->agression > .7f) { |
| 4012 | fq.flags |= FQ_IGNORE_MOVING_OBJECTS; |
| 4013 | } |
| 4014 | |
| 4015 | fq.thisobjnum = -1; |
| 4016 | |
| 4017 | int ignore_obj_list[100]; |
| 4018 | ignore_obj_list[0] = OBJNUM(obj); |
| 4019 | int num_ignored = 1; |
| 4020 | int i; |
| 4021 | |
| 4022 | // CHRISHACK - ONLY IGNORES FIRST LEVEL OF CHILDREN - DO RECERSIVE |
| 4023 | for (i = 0; i < Poly_models[obj->rtype.pobj_info.model_num].n_attach; i++) { |
| 4024 | object *child; |
| 4025 | |
| 4026 | if ((child = ObjGet(obj->attach_children[i])) != NULL && num_ignored < 99) { |
| 4027 | ignore_obj_list[num_ignored++] = OBJNUM(child); |
| 4028 | } |
| 4029 | } |
| 4030 | |
| 4031 | ignore_obj_list[num_ignored] = -1; |
| 4032 | fq.ignore_obj_list = ignore_obj_list; |
| 4033 | |
| 4034 | fate = fvi_FindIntersection(&fq, &hit_info); |
| 4035 | |
| 4036 | #ifdef _DEBUG |
| 4037 | if (AI_debug_robot_do && OBJNUM(obj) == AI_debug_robot_index) { |
| 4038 | mprintf(0, "AI Note: Vis 8\n"); |
| 4039 | } |
| 4040 | #endif |
| 4041 | |
| 4042 | if (((fate == HIT_OBJECT || fate == HIT_SPHERE_2_POLY_OBJECT) && hit_info.hit_object[0] == OBJNUM(target)) || |
| 4043 | (fate == HIT_NONE)) { |
| 4044 | ai_info->status_reg |= AISR_SEES_GOAL; // chrishack -- need to do this stuff correctly |
| 4045 | // if(ai_info->highest_vis > ) chrishack -- need to do this stuff |
| 4046 | |
| 4047 | AINotify(obj, AIN_SEE_TARGET, target); |
| 4048 | |
| 4049 | #ifdef _DEBUG |
| 4050 | if (AI_debug_robot_do && OBJNUM(obj) == AI_debug_robot_index) { |
| 4051 | mprintf(0, "AI Note: Vis SEE TARGET\n"); |
| 4052 | } |
| 4053 | #endif |
| 4054 | } |
| 4055 | |
| 4056 | if ((ai_info->status_reg & AISR_SEES_GOAL) || |
| 4057 | Gametime - ai_info->last_see_target_time < CHECK_VIS_INFREQUENTLY_TIME) |
| 4058 | ai_info->next_check_see_target_time = |
| 4059 | Gametime + .9 * MIN_VIS_CHECK_INTERVAL + .2 * MIN_VIS_CHECK_INTERVAL * ((float)ps_rand() / (float)D3_RAND_MAX); |
| 4060 | else |
| 4061 | ai_info->next_check_see_target_time = |
| 4062 | Gametime + .9 * CHECK_VIS_INFREQUENTLY_INTERVAL + |
| 4063 | .2 * CHECK_VIS_INFREQUENTLY_INTERVAL * ((float)ps_rand() / (float)D3_RAND_MAX); |
| 4064 | } |
| 4065 | } |
| 4066 | |
| 4067 | if ((ai_info->status_reg & AISR_SEES_GOAL)) { |
| 4068 | ai_info->vec_to_target_perceived = ai_info->vec_to_target_actual; |
| 4069 | ai_info->dist_to_target_perceived = ai_info->dist_to_target_actual; |
| 4070 | |
| 4071 | // Assumes the the AI and the target are on the same XZ plane |
| 4072 | /* if(ai_info->flags & AIF_XZ_DIST) |
| 4073 | { |
| 4074 | vector xz; |
| 4075 | |
| 4076 | xz = ai_info->vec_to_target_perceived * ai_info->dist_to_target_perceived; |
| 4077 | xz.y = 0.0f; // chrishack - E3 - it this a good way to do this? |
| 4078 | |
| 4079 | // vm_NormalizeVector(&ai_info->vec_to_target_perceived); |
| 4080 | ai_info->dist_to_target_perceived = vm_GetMagnitude(&xz); |
| 4081 | }*/ |
| 4082 | } |
| 4083 | } |
| 4084 | |
| 4085 | bool AIStatusCircleFrame(object *obj, object *g_obj, float dist, float c_dist, int *status_reg) { |
| 4086 | if ((*status_reg) & AISR_CIRCLE_DIST) { |
| 4087 | if (dist > c_dist * 1.5f || (obj->ai_info->awareness <= AWARE_BARELY && !(obj->ai_info->flags & AIF_PERSISTANT))) { |
| 4088 | (*status_reg) &= ~AISR_CIRCLE_DIST; |
| 4089 | return false; |
| 4090 | } else { |
| 4091 | return true; |
| 4092 | } |
| 4093 | } else if (dist <= c_dist + .1f && |
| 4094 | (obj->ai_info->awareness >= AWARE_BARELY || (obj->ai_info->flags & AIF_PERSISTANT))) { |
| 4095 | (*status_reg) |= AISR_CIRCLE_DIST; |
| 4096 | |
| 4097 | if (g_obj) { |
| 4098 | AINotify(obj, AIN_NEAR_TARGET, (void *)g_obj); |
| 4099 | } |
| 4100 | |
| 4101 | return true; |
| 4102 | } else { |
| 4103 | return false; |
| 4104 | } |
| 4105 | } |
| 4106 | |
| 4107 | // MTS: Unused? |
| 4108 | bool ai_target_need_path(object *obj) { return true; } |
| 4109 | |
| 4110 | // MTS: Unused? |
| 4111 | bool ai_move_need_path(object *obj, vector *pos, int roomnum) { |
| 4112 | if (obj->roomnum == roomnum) { |
| 4113 | return false; |
| 4114 | } |
| 4115 | |
| 4116 | return true; |
| 4117 | } |
| 4118 | |
| 4119 | void ai_update_registers(object *obj) { |
| 4120 | ai_frame *ai_info = obj->ai_info; |
| 4121 | |
| 4122 | if (ObjGet(ai_info->target_handle)) { |
| 4123 | AIStatusCircleFrame(obj, ObjGet(ai_info->target_handle), ai_info->dist_to_target_perceived, |
| 4124 | ai_info->circle_distance, &ai_info->status_reg); |
| 4125 | } else { |
| 4126 | ai_info->status_reg &= ~AISR_CIRCLE_DIST; |
| 4127 | } |
| 4128 | |
| 4129 | ai_info->status_reg &= ~AISR_MELEE; |
| 4130 | } |
| 4131 | |
| 4132 | bool AiGoalAvoid(vector *adir, object *obj, object *a_obj, float dist) { |
| 4133 | float full_dist = dist; |
| 4134 | vector a_vel; |
| 4135 | |
| 4136 | if (obj->movement_type != MT_PHYSICS && obj->movement_type != MT_WALKING) |
| 4137 | return false; |
| 4138 | |
| 4139 | if (a_obj->movement_type == MT_PHYSICS || a_obj->movement_type == MT_WALKING) |
| 4140 | a_vel = a_obj->mtype.phys_info.velocity; |
| 4141 | else |
| 4142 | a_vel = Zero_vector; |
| 4143 | |
| 4144 | vector to_avoid = a_obj->pos - obj->pos; |
| 4145 | vector mdir; |
| 4146 | mdir = obj->mtype.phys_info.velocity - a_vel; |
| 4147 | |
| 4148 | if (fabsf(mdir.x) < 0.1f && fabsf(mdir.y) < 0.1f && fabsf(mdir.z) < 0.1f) { |
| 4149 | *adir = -to_avoid; |
| 4150 | vm_NormalizeVector(adir); |
| 4151 | |
| 4152 | return true; |
| 4153 | } |
| 4154 | |
| 4155 | vm_NormalizeVector(&mdir); |
| 4156 | float temp = mdir * to_avoid; |
| 4157 | |
| 4158 | if (temp <= 0.0f) { |
| 4159 | *adir = -to_avoid; |
| 4160 | vm_NormalizeVector(adir); |
| 4161 | |
| 4162 | return true; |
| 4163 | } |
| 4164 | |
| 4165 | vector vtemp = -(to_avoid - temp * mdir); |
| 4166 | |
| 4167 | // float cdist = vm_NormalizeVector(&vtemp); |
| 4168 | // if(cdist >= full_dist) |
| 4169 | // return false; |
| 4170 | |
| 4171 | vector apnt = a_obj->pos + full_dist * vtemp; |
| 4172 | |
| 4173 | *adir = apnt - obj->pos; |
| 4174 | vm_NormalizeVector(adir); |
| 4175 | |
| 4176 | return true; |
| 4177 | } |
| 4178 | |
| 4179 | static inline bool IsTargetLocal(object *obj, object *target) { |
| 4180 | int target_room = target->roomnum; |
| 4181 | int cur_room = obj->roomnum; |
| 4182 | int i; |
| 4183 | |
| 4184 | // If they are in the same room |
| 4185 | if ((target_room = obj->roomnum)) { |
| 4186 | return true; |
| 4187 | } |
| 4188 | |
| 4189 | // If the object is outside |
| 4190 | if (OBJECT_OUTSIDE(obj)) { |
| 4191 | return false; |
| 4192 | } |
| 4193 | |
| 4194 | // If they are in directly adjacent rooms |
| 4195 | for (i = 0; i < Rooms[cur_room].num_portals; i++) { |
| 4196 | if (Rooms[cur_room].portals[i].croom == target_room) { |
| 4197 | return true; |
| 4198 | } |
| 4199 | } |
| 4200 | |
| 4201 | return false; |
| 4202 | } |
| 4203 | |
| 4204 | #define AVOID_PLAYER_MAX_SCALAR 3.0f |
| 4205 | #define AVOID_PLAYER_MIN_SCALAR 2.0f |
| 4206 | |
| 4207 | #define ALIGNMENT_OPTI_DIST 16.0f |
| 4208 | #define MAX_ALIGNMENT_DIST 6.0f |
| 4209 | |
| 4210 | #define COHESION_OPTI1_DIST 90.0f |
| 4211 | #define COHESION_OPTI2_DIST 90.0f |
| 4212 | #define COHESION_FALL_OFF 110.0f |
| 4213 | |
| 4214 | // MTS: commented out/returns a bool instead of a float |
| 4215 | float AIGoalIsEnabledForDist(goal *goal, float dist) { |
| 4216 | return true; // chrishack -- test code -- temp |
| 4217 | } |
| 4218 | |
| 4219 | void AIGoalDoRepulse(object *obj, float dist, vector *dir, goal *goal, vector *mdir) { |
| 4220 | float influence = 2.0f; // chrishack - temp - test code |
| 4221 | |
| 4222 | if (/*scale = AIGoalIsEnabledForDist(goal, dist)*/ 1) // chrishack - temp - test code - works like an enabler What |
| 4223 | // about AIDetermineScale???? |
| 4224 | { |
| 4225 | if (dist <= 12.0f) // chrishack - temp - test code |
| 4226 | { |
| 4227 | float scale; |
| 4228 | |
| 4229 | if (dist < 9.0f) |
| 4230 | scale = 1.0f; |
| 4231 | else |
| 4232 | scale = 1.0f - (dist - 9.0f) / 3.0; |
| 4233 | |
| 4234 | *mdir += (*dir * -scale) * influence; |
| 4235 | } |
| 4236 | } |
| 4237 | } |
| 4238 | |
| 4239 | void AIGoalDoCohesion(object *obj, object *g_obj, float dist, goal *goal, vector *mdir) { |
| 4240 | float influence = 2.0f; // chrishack - temp - test code |
| 4241 | |
| 4242 | if (/*scale = AIGoalIsEnabledForDist(goal, dist)*/ 1) // chrishack - temp - test code - works like an enabler What |
| 4243 | // about AIDetermineScale???? |
| 4244 | { |
| 4245 | if (dist >= COHESION_OPTI1_DIST - COHESION_FALL_OFF && dist <= COHESION_OPTI2_DIST + COHESION_FALL_OFF) { |
| 4246 | vector cohesion_pnt; |
| 4247 | float scale; |
| 4248 | |
| 4249 | if (dist < COHESION_OPTI1_DIST) |
| 4250 | scale = 1.0f - (COHESION_OPTI1_DIST - dist) / COHESION_FALL_OFF; |
| 4251 | else if (dist <= COHESION_OPTI2_DIST) |
| 4252 | scale = 1.0f; |
| 4253 | else |
| 4254 | scale = 1.0f - (dist - COHESION_OPTI2_DIST) / COHESION_FALL_OFF; |
| 4255 | |
| 4256 | AIDetermineAimPoint(obj, g_obj, &cohesion_pnt, obj->ai_info->max_velocity); |
| 4257 | |
| 4258 | vector cur_cohesion_dir = cohesion_pnt - obj->pos; |
| 4259 | vm_NormalizeVector(&cur_cohesion_dir); |
| 4260 | *mdir += (cur_cohesion_dir * scale) * influence; |
| 4261 | } |
| 4262 | } |
| 4263 | } |
| 4264 | |
| 4265 | void AIGoalDoAlignment(object *obj, float dist, vector *fvec, goal *goal, vector *mdir) { |
| 4266 | float influence = 3.0f; // chrishack - temp - test code |
| 4267 | |
| 4268 | if (/*scale = AIGoalIsEnabledForDist(goal, dist)*/ 1) // chrishack - temp - test code - works like an enabler What |
| 4269 | // about AIDetermineScale???? |
| 4270 | { |
| 4271 | float align_dist = fabs(dist - ALIGNMENT_OPTI_DIST); |
| 4272 | if (MAX_ALIGNMENT_DIST >= align_dist) { |
| 4273 | float scale = 1.0f - (align_dist / MAX_ALIGNMENT_DIST); |
| 4274 | *mdir += (*fvec * scale) * influence; |
| 4275 | } |
| 4276 | } |
| 4277 | } |
| 4278 | |
| 4279 | void AIDoTrackFrame(object *obj) { |
| 4280 | ai_frame *ai_info = obj->ai_info; |
| 4281 | float track_distance; |
| 4282 | |
| 4283 | AI_FriendNumNear = 0; |
| 4284 | AI_EnemyNumNear = 0; |
| 4285 | |
| 4286 | if (ai_info->ai_type == AIT_BIRD_FLOCK1 || |
| 4287 | ai_info->flags & (AIF_TRACK_CLOSEST_2_FRIENDS | AIF_TRACK_CLOSEST_2_ENEMIES)) { |
| 4288 | |
| 4289 | if (ai_info->ai_type == AIT_BIRD_FLOCK1) |
| 4290 | track_distance = 100.0f; |
| 4291 | else |
| 4292 | track_distance = GoalDetermineTrackDist(obj); |
| 4293 | |
| 4294 | if (track_distance > 0.0f) { |
| 4295 | int16_t near_objs[10]; |
| 4296 | int num_near = fvi_QuickDistObjectList(&obj->pos, obj->roomnum, ai_info->avoid_friends_distance + track_distance, |
| 4297 | near_objs, 10, false, true, false, true); |
| 4298 | float dist; |
| 4299 | vector to; |
| 4300 | |
| 4301 | AI_EnemyDist[0] = AI_EnemyDist[1] = 9999999.0f; |
| 4302 | AI_FriendDist[0] = AI_FriendDist[1] = 9999999.0f; |
| 4303 | |
| 4304 | for (int xxx = 0; xxx < num_near; xxx++) { |
| 4305 | object *g_obj = &Objects[near_objs[xxx]]; |
| 4306 | |
| 4307 | if (g_obj->type == OBJ_POWERUP || (obj == g_obj) || ObjectsAreRelated(OBJNUM(obj), near_objs[xxx])) |
| 4308 | continue; |
| 4309 | |
| 4310 | int *cur_num_near; |
| 4311 | object **cur_obj; |
| 4312 | float *cur_dist; |
| 4313 | vector *cur_dir; |
| 4314 | |
| 4315 | if ((ai_info->flags & AIF_TRACK_CLOSEST_2_ENEMIES) && AIObjEnemy(obj, g_obj)) { |
| 4316 | cur_num_near = &AI_EnemyNumNear; |
| 4317 | cur_obj = AI_EnemyObj; |
| 4318 | cur_dist = AI_EnemyDist; |
| 4319 | cur_dir = AI_EnemyDir; |
| 4320 | } else if ((ai_info->flags & AIF_TRACK_CLOSEST_2_FRIENDS) && AIObjFriend(obj, g_obj)) { |
| 4321 | cur_num_near = &AI_FriendNumNear; |
| 4322 | cur_obj = AI_FriendObj; |
| 4323 | cur_dist = AI_FriendDist; |
| 4324 | cur_dir = AI_FriendDir; |
| 4325 | } else |
| 4326 | continue; |
| 4327 | |
| 4328 | to = g_obj->pos - obj->pos; |
| 4329 | dist = vm_NormalizeVector(&to); |
| 4330 | |
| 4331 | dist -= (obj->size + g_obj->size); |
| 4332 | if (dist < 0.0f) |
| 4333 | dist = 0.0f; |
| 4334 | |
| 4335 | vector fov_vec; |
| 4336 | AIDetermineFovVec(obj, &fov_vec); |
| 4337 | |
| 4338 | if (to * fov_vec < ai_info->fov) |
| 4339 | continue; |
| 4340 | |
| 4341 | if (cur_dist[0] > dist) { |
| 4342 | cur_dist[1] = cur_dist[0]; |
| 4343 | cur_obj[1] = cur_obj[0]; |
| 4344 | cur_dir[1] = cur_dir[0]; |
| 4345 | |
| 4346 | cur_dist[0] = dist; |
| 4347 | cur_obj[0] = g_obj; |
| 4348 | cur_dir[0] = to; |
| 4349 | |
| 4350 | (*cur_num_near)++; |
| 4351 | } else if (cur_dist[1] > dist) { |
| 4352 | cur_dist[1] = dist; |
| 4353 | cur_obj[1] = g_obj; |
| 4354 | cur_dir[1] = to; |
| 4355 | |
| 4356 | (*cur_num_near)++; |
| 4357 | } |
| 4358 | |
| 4359 | if (*cur_num_near > 2) |
| 4360 | *cur_num_near = 2; |
| 4361 | } |
| 4362 | } |
| 4363 | } |
| 4364 | } |
| 4365 | |
| 4366 | // MTS: unused? |
| 4367 | float AIDetermineGoalInfluence(object *obj, goal *goal) { |
| 4368 | float influence = goal->influence; |
| 4369 | int g_index = goal - obj->ai_info->goals; |
| 4370 | |
| 4371 | if (goal->flags & GF_SCRIPTED_INFLUENCE) { |
| 4372 | AINotify(obj, AIN_SCRIPTED_INFLUENCE, &g_index); |
| 4373 | influence = goal->influence; |
| 4374 | } else if (goal->flags & GF_RAMPED_INFLUENCE) { |
| 4375 | float scale; |
| 4376 | const float dist = goal->dist_to_goal; // chrishack -- dist to goal must be properly updated for TRACK goals |
| 4377 | |
| 4378 | if (dist < goal->ramp_influence_dists[1]) { |
| 4379 | float delta = dist - goal->ramp_influence_dists[0]; |
| 4380 | float width = goal->ramp_influence_dists[1] - goal->ramp_influence_dists[0]; |
| 4381 | |
| 4382 | if (width > 0.0f) |
| 4383 | scale = delta / width; |
| 4384 | else |
| 4385 | scale = 0.0f; |
| 4386 | } else if (dist <= goal->ramp_influence_dists[2]) { |
| 4387 | scale = 1.0f; |
| 4388 | } else { |
| 4389 | float delta = goal->ramp_influence_dists[3] - dist; |
| 4390 | float width = goal->ramp_influence_dists[3] - goal->ramp_influence_dists[2]; |
| 4391 | |
| 4392 | if (width > 0.0f) |
| 4393 | scale = delta / width; |
| 4394 | else |
| 4395 | scale = 0.0f; |
| 4396 | } |
| 4397 | |
| 4398 | influence *= scale; |
| 4399 | } |
| 4400 | |
| 4401 | if ((goal->flags & GF_MIN_MAX_INFLUENCE) && influence < goal->min_influence) { |
| 4402 | influence = goal->min_influence; |
| 4403 | } |
| 4404 | |
| 4405 | return influence; |
| 4406 | } |
| 4407 | |
| 4408 | void AIDoOrientVelocity(object *obj) { |
| 4409 | ai_frame *ai_info = obj->ai_info; |
| 4410 | |
| 4411 | vector dir = obj->mtype.phys_info.velocity; |
| 4412 | float mag = vm_NormalizeVector(&dir); |
| 4413 | |
| 4414 | if (mag > 0.1f) { |
| 4415 | AITurnTowardsDir(obj, &dir, ai_info->max_turn_rate); |
| 4416 | } |
| 4417 | } |
| 4418 | |
| 4419 | void AIDoOrientDefault(object *obj) { |
| 4420 | ai_frame *ai_info = obj->ai_info; |
| 4421 | |
| 4422 | if ((obj->movement_type != MT_WALKING && obj->movement_type != MT_PHYSICS) || !(ai_info)) { |
| 4423 | return; |
| 4424 | } |
| 4425 | |
| 4426 | // The aware barely stuff can be improved by using emotional sliders to determine if the robot will |
| 4427 | // 'lose track' of its target -- chrishack -- also use last see target time with the agression slider |
| 4428 | if ((ai_info->flags & AIF_ORIENT_TO_VEL) || (ai_info->awareness <= AWARE_BARELY && ai_info->agression < 0.4f) || |
| 4429 | !ObjGet(ai_info->target_handle)) { |
| 4430 | AIDoOrientVelocity(obj); |
| 4431 | } else { |
| 4432 | vector to = ai_info->last_see_target_pos - obj->pos; |
| 4433 | float dist = vm_NormalizeVector(&to); |
| 4434 | |
| 4435 | if (dist > .1f) |
| 4436 | AITurnTowardsDir(obj, &to, ai_info->max_turn_rate); |
| 4437 | } |
| 4438 | } |
| 4439 | |
| 4440 | void AIDoOrient(object *obj, int g_index) { |
| 4441 | ai_frame *ai_info = obj->ai_info; |
| 4442 | goal *goal_ptr = &ai_info->goals[g_index]; |
| 4443 | |
| 4444 | if ((obj->movement_type != MT_WALKING && obj->movement_type != MT_PHYSICS) || !(ai_info)) { |
| 4445 | return; |
| 4446 | } |
| 4447 | |
| 4448 | if ((g_index >= 0) && ISORIENTGOAL(&ai_info->goals[g_index])) { |
| 4449 | object *g_obj = NULL; |
| 4450 | |
| 4451 | if (goal_ptr->flags & GF_ORIENT_FOR_ATTACH) { |
| 4452 | Int3(); // chrishack -- not done |
| 4453 | } else if (goal_ptr->flags & GF_ORIENT_TARGET) { |
| 4454 | target_goal: |
| 4455 | |
| 4456 | g_obj = ObjGet(ai_info->target_handle); |
| 4457 | if (g_obj) { |
| 4458 | vector to = ai_info->last_see_target_pos - obj->pos; |
| 4459 | float dist = vm_NormalizeVector(&to); |
| 4460 | |
| 4461 | if (dist > .1f) |
| 4462 | AITurnTowardsDir(obj, &to, ai_info->max_turn_rate); |
| 4463 | } else { |
| 4464 | AIDoOrientVelocity(obj); |
| 4465 | } |
| 4466 | } else if (OBJGOAL(goal_ptr) && (goal_ptr->flags & GF_ORIENT_GOAL_OBJ)) { |
| 4467 | object *t_obj = ObjGet(ai_info->target_handle); |
| 4468 | g_obj = ObjGet(goal_ptr->g_info.handle); |
| 4469 | |
| 4470 | if (g_obj && (g_obj == t_obj)) |
| 4471 | goto target_goal; |
| 4472 | |
| 4473 | if (g_obj) { |
| 4474 | vector to = g_obj->pos - obj->pos; |
| 4475 | float dist = vm_NormalizeVector(&to); |
| 4476 | |
| 4477 | if (dist > .1f) |
| 4478 | AITurnTowardsDir(obj, &to, ai_info->max_turn_rate); |
| 4479 | } else { |
| 4480 | AIDoOrientVelocity(obj); |
| 4481 | } |
| 4482 | } else if (goal_ptr->flags & GF_ORIENT_VELOCITY) { |
| 4483 | AIDoOrientVelocity(obj); |
| 4484 | } else if (goal_ptr->flags & GF_ORIENT_SCRIPTED) { |
| 4485 | AINotify(obj, AIN_SCRIPTED_ORIENT, &g_index); |
| 4486 | } else if (goal_ptr->flags & GF_ORIENT_PATH_NODE) { |
| 4487 | vector uvec = obj->orient.uvec; |
| 4488 | vector fvec = obj->orient.fvec; |
| 4489 | |
| 4490 | ai_path_info *aip = &obj->ai_info->path; |
| 4491 | |
| 4492 | int n = aip->cur_node; |
| 4493 | int p = aip->cur_path; |
| 4494 | |
| 4495 | int p_id = aip->path_id[p]; |
| 4496 | |
| 4497 | bool f_reverse = (goal_ptr->flags & GF_PATH_MOVE_REVERSE_DIR) != 0; |
| 4498 | |
| 4499 | if (aip->path_type[p] == AIP_STATIC) { |
| 4500 | game_path *gp = &GamePaths[p_id]; |
| 4501 | vector cur_pos; |
| 4502 | AIPathGetCurrentNodePos(aip, &cur_pos); |
| 4503 | |
| 4504 | if ((f_reverse) && (!AIPathAtEnd(aip))) { |
| 4505 | vector next_pos; |
| 4506 | AIPathGetNextNodePos(aip, &next_pos, NULL); |
| 4507 | |
| 4508 | vector proj = obj->pos - next_pos; |
| 4509 | vector line = cur_pos - next_pos; |
| 4510 | float line_len = vm_NormalizeVector(&line); |
| 4511 | float proj_len = proj * line; |
| 4512 | |
| 4513 | if (proj_len > 0.0) { |
| 4514 | if (proj_len > line_len) |
| 4515 | return; // We should have updated nodes |
| 4516 | |
| 4517 | float scale1 = proj_len / line_len; |
| 4518 | float scale2 = 1.0f - scale1; |
| 4519 | |
| 4520 | fvec = (scale1 * gp->pathnodes[n].fvec + scale2 * gp->pathnodes[n + 1].fvec); |
| 4521 | uvec = (scale1 * gp->pathnodes[n].uvec + scale2 * gp->pathnodes[n + 1].uvec); |
| 4522 | } |
| 4523 | } else if ((!f_reverse) && (!AIPathAtStart(aip))) { |
| 4524 | vector prev_pos; |
| 4525 | AIPathGetPrevNodePos(aip, &prev_pos, NULL); |
| 4526 | |
| 4527 | vector proj = obj->pos - prev_pos; |
| 4528 | vector line = cur_pos - prev_pos; |
| 4529 | float line_len = vm_NormalizeVector(&line); |
| 4530 | float proj_len = proj * line; |
| 4531 | |
| 4532 | if (proj_len > 0.0) { |
| 4533 | if (proj_len > line_len) |
| 4534 | return; // We should have updated nodes |
| 4535 | |
| 4536 | float scale1 = proj_len / line_len; |
| 4537 | float scale2 = 1.0f - scale1; |
| 4538 | |
| 4539 | fvec = (scale1 * gp->pathnodes[n].fvec + scale2 * gp->pathnodes[n - 1].fvec); |
| 4540 | uvec = (scale1 * gp->pathnodes[n].uvec + scale2 * gp->pathnodes[n - 1].uvec); |
| 4541 | } |
| 4542 | } |
| 4543 | |
| 4544 | matrix orient; |
| 4545 | vm_VectorToMatrix(&orient, &fvec, &uvec, NULL); |
| 4546 | |
| 4547 | AITurnTowardsMatrix(obj, ai_info->max_turn_rate, &orient); |
| 4548 | } |
| 4549 | } else if (goal_ptr->flags & GF_ORIENT_SET_FVEC_UVEC) { |
| 4550 | matrix orient; |
| 4551 | vm_VectorToMatrix(&orient, &goal_ptr->set_fvec, &goal_ptr->set_uvec, NULL); |
| 4552 | |
| 4553 | AITurnTowardsMatrix(obj, ai_info->max_turn_rate, &orient); |
| 4554 | } else if (goal_ptr->flags & GF_ORIENT_SET_FVEC) { |
| 4555 | AITurnTowardsDir(obj, &goal_ptr->set_fvec, ai_info->max_turn_rate); |
| 4556 | } else { |
| 4557 | AIDoOrientDefault(obj); |
| 4558 | } |
| 4559 | } else { |
| 4560 | AIDoOrientDefault(obj); |
| 4561 | } |
| 4562 | } |
| 4563 | |
| 4564 | void AIDetermineSpeed(object *obj, int flags, float *speed) { |
| 4565 | float n_speed = 1.0f; |
| 4566 | |
| 4567 | switch (flags & GF_SPEED_MASK) { |
| 4568 | case GF_SPEED_ATTACK: |
| 4569 | n_speed = obj->ai_info->attack_vel_percent; |
| 4570 | break; |
| 4571 | case GF_SPEED_DODGE: |
| 4572 | n_speed = obj->ai_info->dodge_vel_percent; |
| 4573 | break; |
| 4574 | case GF_SPEED_FLEE: |
| 4575 | n_speed = obj->ai_info->flee_vel_percent; |
| 4576 | break; |
| 4577 | } |
| 4578 | |
| 4579 | if (n_speed > *speed) { |
| 4580 | *speed = n_speed; |
| 4581 | } |
| 4582 | } |
| 4583 | |
| 4584 | void ai_move(object *obj) { |
| 4585 | ai_frame *ai_info = obj->ai_info; |
| 4586 | int i; |
| 4587 | bool f_dodge = false; // Are there any dodge goals |
| 4588 | bool f_avoid = false; // Are there any avoid goals |
| 4589 | int highest_influence_goal = -1; |
| 4590 | float highest_influence = 0.0f; |
| 4591 | float highest_speed = 0.0f; |
| 4592 | bool f_turned = true; |
| 4593 | bool f_goal_found = false; |
| 4594 | |
| 4595 | // Post project GB Hacks to make him more combat friendly... |
| 4596 | if (IS_GUIDEBOT(obj)) { |
| 4597 | if (ai_info->flags & AIF_GB_MIMIC_PLAYER_FIRING_HACK) |
| 4598 | ai_info->flags &= ~AIF_DODGE; |
| 4599 | else |
| 4600 | ai_info->flags |= AIF_DODGE; |
| 4601 | } |
| 4602 | // int num_objects; |
| 4603 | // object *g_objs[5]; // 1 target + 2 enemies + 2 freinds |
| 4604 | |
| 4605 | object *targetptr = ObjGet(ai_info->target_handle); // The target of this AI |
| 4606 | ai_info->movement_dir = Zero_vector; |
| 4607 | |
| 4608 | // Hacked flocking code |
| 4609 | if (ai_info->ai_type == AIT_BIRD_FLOCK1) { |
| 4610 | vector composite_dir = Zero_vector; |
| 4611 | |
| 4612 | for (int temp = 0; temp < AI_FriendNumNear; temp++) { |
| 4613 | object *g_obj = AI_FriendObj[temp]; |
| 4614 | |
| 4615 | ASSERT(g_obj->type != OBJ_WEAPON); |
| 4616 | ASSERT(g_obj != obj); |
| 4617 | |
| 4618 | AIGoalDoRepulse(obj, AI_FriendDist[temp], &AI_FriendDir[temp], NULL, &composite_dir); |
| 4619 | AIGoalDoAlignment(obj, AI_FriendDist[temp], &g_obj->orient.fvec, NULL, &composite_dir); |
| 4620 | AIGoalDoCohesion(obj, g_obj, AI_FriendDist[temp], NULL, &composite_dir); |
| 4621 | f_goal_found = true; |
| 4622 | } |
| 4623 | |
| 4624 | // Facing code |
| 4625 | if (composite_dir == Zero_vector) |
| 4626 | composite_dir = obj->orient.fvec; |
| 4627 | |
| 4628 | // FLOCK HEIGHT CODE |
| 4629 | if (ROOMNUM_OUTSIDE(obj->roomnum) && (ai_info->flags & AIF_BIASED_FLIGHT_HEIGHT)) { |
| 4630 | composite_dir.y *= .5f; |
| 4631 | |
| 4632 | float delta = obj->pos.y - GetTerrainGroundPoint(&obj->pos) - obj->size; |
| 4633 | if (delta < ai_info->biased_flight_min) { |
| 4634 | if (composite_dir.y < 0.0) |
| 4635 | composite_dir.y *= .5f; |
| 4636 | else |
| 4637 | composite_dir.y *= 4.0f; |
| 4638 | } else if (delta > ai_info->biased_flight_max) { |
| 4639 | if (composite_dir.y < 0.0) |
| 4640 | composite_dir.y *= 4.0f; |
| 4641 | else |
| 4642 | composite_dir.y *= 0.5f; |
| 4643 | } |
| 4644 | |
| 4645 | float max_fly_upward_height = ai_info->biased_flight_min * ai_info->biased_flight_importance; |
| 4646 | if (delta < max_fly_upward_height) { |
| 4647 | composite_dir.y += (1.0f - (delta / max_fly_upward_height)) * ai_info->biased_flight_importance; |
| 4648 | } |
| 4649 | } |
| 4650 | |
| 4651 | vm_NormalizeVector(&composite_dir); |
| 4652 | |
| 4653 | AIMoveTowardsDir(obj, &composite_dir, 1.0f); |
| 4654 | AITurnTowardsDir(obj, &composite_dir, ai_info->max_turn_rate); |
| 4655 | return; |
| 4656 | } |
| 4657 | |
| 4658 | // Stop objects that have not been active lately |
| 4659 | if (!(ai_info->flags & AIF_PERSISTANT) && Gametime - ai_info->last_see_target_time > CHECK_VIS_INFREQUENTLY_TIME && |
| 4660 | Gametime - ai_info->last_hear_target_time > CHECK_VIS_INFREQUENTLY_TIME && ai_info->awareness == AWARE_NONE) { |
| 4661 | obj->mtype.phys_info.velocity = Zero_vector; |
| 4662 | obj->mtype.phys_info.rotvel = Zero_vector; |
| 4663 | } else { |
| 4664 | // Determine movement stuff |
| 4665 | if (obj->movement_type == MT_PHYSICS || obj->movement_type == MT_WALKING) { |
| 4666 | if (targetptr && IsTargetLocal(obj, targetptr) || (ai_info->awareness >= AWARE_BARELY) || |
| 4667 | (ai_info->flags & AIF_PERSISTANT)) { |
| 4668 | for (i = NUM_ACTIVATION_LEVELS; i < MAX_GOALS; i++) { |
| 4669 | if (ai_info->goals[i].used) { |
| 4670 | if (GoalIsGoalEnabled(obj, i)) { |
| 4671 | if (ai_info->goals[i].type == AIG_DODGE_OBJ) { |
| 4672 | f_goal_found = true; |
| 4673 | if (goal_do_dodge(obj, i)) { |
| 4674 | f_dodge = true; |
| 4675 | AIDetermineSpeed(obj, ai_info->goals[i].flags, &highest_speed); |
| 4676 | |
| 4677 | #ifdef _DEBUG |
| 4678 | if (AI_debug_robot_do && OBJNUM(obj) == AI_debug_robot_index) { |
| 4679 | mprintf(0, "AI Note: Dodging\n"); |
| 4680 | } |
| 4681 | #endif |
| 4682 | } |
| 4683 | } else if (ai_info->goals[i].type == AIG_MELEE_TARGET) { |
| 4684 | f_goal_found = true; |
| 4685 | AiMelee(obj); |
| 4686 | AIDetermineSpeed(obj, ai_info->goals[i].flags, &highest_speed); |
| 4687 | |
| 4688 | #ifdef _DEBUG |
| 4689 | if (AI_debug_robot_do && OBJNUM(obj) == AI_debug_robot_index) { |
| 4690 | mprintf(0, "AI Note: Melee\n"); |
| 4691 | } |
| 4692 | #endif |
| 4693 | } else if (ai_info->goals[i].type == AIG_GET_AROUND_OBJ) { |
| 4694 | f_goal_found = true; |
| 4695 | |
| 4696 | goal *cur_goal = &ai_info->goals[i]; |
| 4697 | object *g_obj = ObjGet(cur_goal->g_info.handle); |
| 4698 | float dist = cur_goal->circle_distance; |
| 4699 | |
| 4700 | vector adir; |
| 4701 | |
| 4702 | if (!g_obj || (g_obj == obj) || ObjectsAreRelated(OBJNUM(obj), OBJNUM(g_obj))) |
| 4703 | continue; |
| 4704 | |
| 4705 | float cur_dist = vm_VectorDistance(&obj->pos, &g_obj->pos) - obj->size - g_obj->size; |
| 4706 | if (cur_dist < 0.0) |
| 4707 | cur_dist = 0.0f; |
| 4708 | |
| 4709 | if (cur_dist > dist) |
| 4710 | continue; |
| 4711 | |
| 4712 | // Scale the life perservation too (if enemy DAMN GOOD IDEA - expand AVOID SIZE too) -- chrishack |
| 4713 | // Linear scale by distance |
| 4714 | float scale = cur_goal->influence * ((dist - cur_dist) / dist); |
| 4715 | |
| 4716 | if (AiGoalAvoid(&adir, obj, g_obj, dist)) { |
| 4717 | #ifdef _DEBUG |
| 4718 | if (AI_debug_robot_do && OBJNUM(obj) == AI_debug_robot_index) { |
| 4719 | mprintf(0, "AI Note: Avoiding object\n"); |
| 4720 | } |
| 4721 | #endif |
| 4722 | |
| 4723 | ai_info->movement_dir += (adir * scale); |
| 4724 | f_avoid = true; |
| 4725 | AIDetermineSpeed(obj, ai_info->goals[i].flags, &highest_speed); |
| 4726 | } |
| 4727 | } |
| 4728 | } |
| 4729 | } |
| 4730 | } |
| 4731 | |
| 4732 | if (ai_info->flags & AIF_AUTO_AVOID_FRIENDS) { |
| 4733 | object *g_obj; |
| 4734 | vector adir; |
| 4735 | |
| 4736 | f_goal_found = true; |
| 4737 | |
| 4738 | int16_t near_objs[10]; |
| 4739 | |
| 4740 | float avoid_dist; |
| 4741 | |
| 4742 | avoid_dist = ai_info->avoid_friends_distance; |
| 4743 | |
| 4744 | // We avoid friends more when we are in close proximity of our target |
| 4745 | if (AIObjEnemy(obj, ObjGet(ai_info->target_handle)) && (ai_info->status_reg & AISR_CIRCLE_DIST)) |
| 4746 | avoid_dist *= 2.3f; |
| 4747 | |
| 4748 | int num_near = fvi_QuickDistObjectList(&obj->pos, obj->roomnum, ai_info->avoid_friends_distance + obj->size, |
| 4749 | near_objs, 10, false, true); |
| 4750 | |
| 4751 | for (int temp = 0; temp < num_near; temp++) { |
| 4752 | g_obj = &Objects[near_objs[temp]]; |
| 4753 | |
| 4754 | if (g_obj->type == OBJ_POWERUP || (g_obj == obj) || ObjectsAreRelated(OBJNUM(obj), near_objs[temp])) |
| 4755 | continue; |
| 4756 | |
| 4757 | if (!AIObjFriend(obj, g_obj)) |
| 4758 | continue; |
| 4759 | |
| 4760 | float cur_dist = vm_VectorDistance(&obj->pos, &g_obj->pos) - obj->size - g_obj->size; |
| 4761 | if (cur_dist < 0.0) |
| 4762 | cur_dist = 0.0f; |
| 4763 | |
| 4764 | if (cur_dist > ai_info->avoid_friends_distance) |
| 4765 | continue; |
| 4766 | |
| 4767 | if (AiGoalAvoid(&adir, obj, g_obj, ai_info->avoid_friends_distance)) { |
| 4768 | float scale = 1.0f - cur_dist / ai_info->avoid_friends_distance; |
| 4769 | if (scale < 0.01f) |
| 4770 | scale = 0.01f; |
| 4771 | |
| 4772 | ai_info->movement_dir += (adir * scale); |
| 4773 | f_avoid = true; |
| 4774 | AIDetermineSpeed(obj, GF_SPEED_NORMAL, &highest_speed); |
| 4775 | |
| 4776 | #ifdef _DEBUG |
| 4777 | if (AI_debug_robot_do && OBJNUM(obj) == AI_debug_robot_index) { |
| 4778 | mprintf(0, "AI Note: Auto avoid friends.\n"); |
| 4779 | } |
| 4780 | #endif |
| 4781 | } |
| 4782 | } |
| 4783 | } |
| 4784 | |
| 4785 | if (ai_info->flags & AIF_AVOID_WALLS) { |
| 4786 | if (goal_do_avoid_walls(obj, &ai_info->movement_dir)) { |
| 4787 | f_avoid = true; |
| 4788 | AIDetermineSpeed(obj, GF_SPEED_NORMAL, &highest_speed); |
| 4789 | |
| 4790 | #ifdef _DEBUG |
| 4791 | if (AI_debug_robot_do && OBJNUM(obj) == AI_debug_robot_index) { |
| 4792 | mprintf(0, "AI Note: Avoiding walls\n"); |
| 4793 | } |
| 4794 | #endif |
| 4795 | } |
| 4796 | } |
| 4797 | |
| 4798 | goal *cur_goal = GoalGetCurrentGoal(obj); |
| 4799 | vector goal_mdir; |
| 4800 | bool goal_f_moved = false; |
| 4801 | bool goal_mset = false; |
| 4802 | |
| 4803 | if (cur_goal) { |
| 4804 | f_goal_found = true; |
| 4805 | highest_influence_goal = cur_goal - ai_info->goals; |
| 4806 | f_turned = false; |
| 4807 | AIDetermineSpeed(obj, cur_goal->flags, &highest_speed); |
| 4808 | |
| 4809 | switch (cur_goal->type) { |
| 4810 | case AIG_SCRIPTED: { |
| 4811 | int g_index = cur_goal - ai_info->goals; |
| 4812 | AINotify(obj, AIN_SCRIPTED_GOAL, &g_index); // Assume that it modifies the movement vec |
| 4813 | |
| 4814 | int goal_mscale = vm_NormalizeVector(&ai_info->movement_dir); |
| 4815 | goal_mdir = ai_info->movement_dir; |
| 4816 | |
| 4817 | if (goal_mscale > highest_speed) { |
| 4818 | highest_speed = goal_mscale; |
| 4819 | } |
| 4820 | |
| 4821 | goal_mset = true; |
| 4822 | } break; |
| 4823 | |
| 4824 | case AIG_GUARD_AREA: // Chrishack -- this goal could probably be removed |
| 4825 | { |
| 4826 | if (!(cur_goal->status_reg & AISR_CIRCLE_DIST)) { |
| 4827 | if (cur_goal->g_info.roomnum != obj->roomnum) { |
| 4828 | cur_goal->g_info.roomnum = obj->roomnum; |
| 4829 | cur_goal->g_info.pos = obj->pos; |
| 4830 | } |
| 4831 | |
| 4832 | AIMoveTowardsPosition(obj, &cur_goal->g_info.pos, 1.0f, false, &goal_mdir, &goal_f_moved); |
| 4833 | goal_mset = true; |
| 4834 | } |
| 4835 | } break; |
| 4836 | |
| 4837 | case AIG_GET_TO_OBJ: |
| 4838 | case AIG_GET_TO_POS: |
| 4839 | case AIG_WANDER_AROUND: |
| 4840 | case AIG_FOLLOW_PATH: |
| 4841 | case AIG_PLACE_OBJ_ON_OBJ: |
| 4842 | case AIG_ATTACH_TO_OBJ: { |
| 4843 | if ((cur_goal->type == AIG_ATTACH_TO_OBJ || cur_goal->type == AIG_PLACE_OBJ_ON_OBJ) && |
| 4844 | (cur_goal->status_reg & AISR_CIRCLE_DIST)) { |
| 4845 | object *g_obj = ObjGet(cur_goal->g_info.handle); |
| 4846 | object *child_obj = NULL; |
| 4847 | |
| 4848 | if (cur_goal->type == AIG_PLACE_OBJ_ON_OBJ) { |
| 4849 | child_obj = ObjGet(obj->attach_children[0]); |
| 4850 | |
| 4851 | if (child_obj == NULL) { |
| 4852 | cur_goal->flags &= ~(GF_NONFLUSHABLE | GF_KEEP_AT_COMPLETION); |
| 4853 | GoalClearGoal(obj, cur_goal, AIN_GOAL_INVALID); |
| 4854 | return; |
| 4855 | } |
| 4856 | } |
| 4857 | |
| 4858 | vector pos; |
| 4859 | matrix orient; |
| 4860 | char p_ap = cur_goal->g_info.attach_info.parent_ap; |
| 4861 | char c_ap = cur_goal->g_info.attach_info.child_ap; |
| 4862 | float rad = cur_goal->g_info.attach_info.rad; |
| 4863 | |
| 4864 | // Investigate a better means of doing this... |
| 4865 | if (!(obj->mtype.phys_info.flags & PF_NO_ROBOT_COLLISIONS)) { |
| 4866 | obj->mtype.phys_info.flags |= PF_NO_ROBOT_COLLISIONS; |
| 4867 | cur_goal->g_info.attach_info.flags |= GAF_TEMP_CLEAR_ROBOT_COLLISIONS; |
| 4868 | } |
| 4869 | if (!(obj->mtype.phys_info.flags & PF_POINT_COLLIDE_WALLS)) { |
| 4870 | obj->mtype.phys_info.flags |= PF_POINT_COLLIDE_WALLS; |
| 4871 | cur_goal->g_info.attach_info.flags |= GAF_TEMP_POINT_COLLIDE_WALLS; |
| 4872 | } |
| 4873 | if ((cur_goal->g_info.attach_info.flags & GAF_ALIGNED) && (obj->mtype.phys_info.flags & PF_LEVELING)) { |
| 4874 | obj->mtype.phys_info.flags &= (~PF_LEVELING); |
| 4875 | cur_goal->g_info.attach_info.flags |= GAF_TEMP_CLEAR_AUTOLEVEL; |
| 4876 | } |
| 4877 | |
| 4878 | // Determine that attach pos and orient |
| 4879 | if ((cur_goal->g_info.attach_info.flags & GAF_ALIGNED) && |
| 4880 | AttachDoPosOrient(obj, p_ap, g_obj, c_ap, true, false, &pos, &orient, |
| 4881 | (cur_goal->type == AIG_PLACE_OBJ_ON_OBJ))) { |
| 4882 | bool f_at_pos = AIMoveTowardsPosition(obj, &pos, 1.0f, true, &goal_mdir, &goal_f_moved); |
| 4883 | goal_mset = true; |
| 4884 | if (!goal_f_moved) { |
| 4885 | AIMoveTowardsDir(obj, &goal_mdir); |
| 4886 | } |
| 4887 | |
| 4888 | bool f_orient = AITurnTowardsMatrix(obj, obj->ai_info->max_turn_rate, &orient); |
| 4889 | |
| 4890 | if (f_at_pos && f_orient) { |
| 4891 | int goal_index = cur_goal - ai_info->goals; |
| 4892 | |
| 4893 | if (cur_goal->type == AIG_PLACE_OBJ_ON_OBJ) { |
| 4894 | UnattachFromParent(child_obj); |
| 4895 | AttachObject(g_obj, c_ap, child_obj, p_ap, true); |
| 4896 | } else { |
| 4897 | if (cur_goal->flags & GF_IS_ATTACH_CHILD) |
| 4898 | AttachObject(g_obj, c_ap, obj, p_ap, true); |
| 4899 | else |
| 4900 | AttachObject(obj, p_ap, g_obj, c_ap, true); |
| 4901 | } |
| 4902 | |
| 4903 | if (cur_goal->g_info.attach_info.flags & GAF_TEMP_CLEAR_ROBOT_COLLISIONS) { |
| 4904 | obj->mtype.phys_info.flags &= (~PF_NO_ROBOT_COLLISIONS); |
| 4905 | } |
| 4906 | if (cur_goal->g_info.attach_info.flags & GAF_TEMP_POINT_COLLIDE_WALLS) { |
| 4907 | obj->mtype.phys_info.flags &= (~PF_POINT_COLLIDE_WALLS); |
| 4908 | } |
| 4909 | if (cur_goal->g_info.attach_info.flags & GAF_TEMP_CLEAR_AUTOLEVEL) { |
| 4910 | obj->mtype.phys_info.flags |= PF_LEVELING; |
| 4911 | } |
| 4912 | cur_goal->g_info.attach_info.flags &= |
| 4913 | ~(GAF_TEMP_CLEAR_AUTOLEVEL | GAF_TEMP_POINT_COLLIDE_WALLS | GAF_TEMP_CLEAR_ROBOT_COLLISIONS); |
| 4914 | |
| 4915 | cur_goal->flags &= ~(GF_NONFLUSHABLE | GF_KEEP_AT_COMPLETION); |
| 4916 | GoalClearGoal(obj, cur_goal, AIN_GOAL_COMPLETE); |
| 4917 | } |
| 4918 | } else if ((cur_goal->g_info.attach_info.flags & GAF_SPHERE) && |
| 4919 | AttachDoPosOrientRad(obj, p_ap, g_obj, rad, &pos)) { |
| 4920 | bool f_at_pos = AIMoveTowardsPosition(obj, &pos, 1.0f, true, &goal_mdir, &goal_f_moved); |
| 4921 | goal_mset = true; |
| 4922 | if (!goal_f_moved) { |
| 4923 | AIMoveTowardsDir(obj, &goal_mdir); |
| 4924 | } |
| 4925 | |
| 4926 | if (f_at_pos) { |
| 4927 | int goal_index = cur_goal - ai_info->goals; |
| 4928 | |
| 4929 | AttachObject(obj, p_ap, g_obj, rad); |
| 4930 | |
| 4931 | if (cur_goal->g_info.attach_info.flags & GAF_TEMP_CLEAR_ROBOT_COLLISIONS) { |
| 4932 | obj->mtype.phys_info.flags &= (~PF_NO_ROBOT_COLLISIONS); |
| 4933 | } |
| 4934 | if (cur_goal->g_info.attach_info.flags & GAF_TEMP_POINT_COLLIDE_WALLS) { |
| 4935 | obj->mtype.phys_info.flags &= (~PF_POINT_COLLIDE_WALLS); |
| 4936 | } |
| 4937 | if (cur_goal->g_info.attach_info.flags & GAF_TEMP_CLEAR_AUTOLEVEL) { |
| 4938 | obj->mtype.phys_info.flags |= PF_LEVELING; |
| 4939 | } |
| 4940 | cur_goal->g_info.attach_info.flags &= |
| 4941 | ~(GAF_TEMP_CLEAR_AUTOLEVEL | GAF_TEMP_POINT_COLLIDE_WALLS | GAF_TEMP_CLEAR_ROBOT_COLLISIONS); |
| 4942 | |
| 4943 | cur_goal->flags &= ~(GF_NONFLUSHABLE | GF_KEEP_AT_COMPLETION); |
| 4944 | GoalClearGoal(obj, cur_goal, AIN_GOAL_COMPLETE); |
| 4945 | } |
| 4946 | } else { |
| 4947 | cur_goal->flags &= ~(GF_NONFLUSHABLE | GF_KEEP_AT_COMPLETION); |
| 4948 | GoalClearGoal(obj, cur_goal, AIN_GOAL_INVALID); |
| 4949 | } |
| 4950 | return; |
| 4951 | } else if (ai_info->path.num_paths && |
| 4952 | !((cur_goal->status_reg & AISR_SEES_GOAL) && (cur_goal->flags & GF_USE_BLINE_IF_SEES_GOAL))) { |
| 4953 | AIPathMoveTurnTowardsNode(obj, &goal_mdir, &goal_f_moved); |
| 4954 | goal_mset = true; |
| 4955 | } else if (cur_goal->type == AIG_GET_TO_POS || cur_goal->type == AIG_WANDER_AROUND) { |
| 4956 | bool result = AIMoveTowardsPosition(obj, &cur_goal->g_info.pos, 1.0f, |
| 4957 | fabs(cur_goal->circle_distance) < .001, &goal_mdir, &goal_f_moved); |
| 4958 | goal_mset = true; |
| 4959 | |
| 4960 | if (result && (fabs(cur_goal->circle_distance) < .001)) |
| 4961 | GoalClearGoal(obj, cur_goal, AIN_GOAL_COMPLETE); |
| 4962 | } else if (OBJGOAL(cur_goal)) { |
| 4963 | object *g_obj = ObjGet(cur_goal->g_info.handle); |
| 4964 | |
| 4965 | if (g_obj) { |
| 4966 | AIMoveTowardsPosition(obj, &g_obj->pos, 1.0f, false, &goal_mdir, &goal_f_moved); |
| 4967 | goal_mset = true; |
| 4968 | } else { |
| 4969 | mprintf(0, "AIG Warning: No obj for GetToObj.\n"); |
| 4970 | } |
| 4971 | } else if (cur_goal->type == AIG_FOLLOW_PATH) { |
| 4972 | mprintf(0, "AIG Warning: Follow path has no path\n"); |
| 4973 | } |
| 4974 | } break; |
| 4975 | |
| 4976 | case AIG_MOVE_RELATIVE_OBJ_VEC: { |
| 4977 | object *goal_obj = ObjGet(cur_goal->g_info.handle); |
| 4978 | float g_circle_dist = cur_goal->circle_distance; |
| 4979 | |
| 4980 | if (goal_obj) { |
| 4981 | int subtype = cur_goal->subtype; |
| 4982 | int vec_id = (subtype & 0xFFFFFFFE); |
| 4983 | bool f_toward = (subtype & 0x00000001); |
| 4984 | vector *vec; |
| 4985 | |
| 4986 | // mprintf(0, "Moving relative a type %d\n", obj->type); |
| 4987 | |
| 4988 | switch (vec_id) { |
| 4989 | case GST_FVEC: |
| 4990 | vec = &goal_obj->orient.fvec; |
| 4991 | break; |
| 4992 | case GST_RVEC: |
| 4993 | vec = &goal_obj->orient.rvec; |
| 4994 | break; |
| 4995 | case GST_UVEC: |
| 4996 | vec = &goal_obj->orient.uvec; |
| 4997 | break; |
| 4998 | default: |
| 4999 | mprintf(0, "Invalid vec in AIG_MOVE_RELATIVE_OBJ_VEC bashing to fvec\n"); |
| 5000 | cur_goal->subtype = GST_FVEC | (int)f_toward; |
| 5001 | vec_id = GST_FVEC; |
| 5002 | } |
| 5003 | |
| 5004 | if (move_relative_object_vec(obj, vec, goal_obj, g_circle_dist, 1.0f, f_toward, &goal_mdir, |
| 5005 | &goal_f_moved)) { |
| 5006 | GoalClearGoal(obj, cur_goal, AIN_GOAL_COMPLETE); |
| 5007 | } |
| 5008 | goal_mset = true; |
| 5009 | } else { |
| 5010 | GoalClearGoal(obj, cur_goal, AIN_GOAL_INVALID); |
| 5011 | } |
| 5012 | } break; |
| 5013 | |
| 5014 | case AIG_MOVE_RELATIVE_OBJ: // chrishack make this out of other goals |
| 5015 | { |
| 5016 | object *goal_obj = ObjGet(cur_goal->g_info.handle); |
| 5017 | float g_circle_dist = cur_goal->circle_distance; |
| 5018 | |
| 5019 | int g_status = cur_goal->status_reg; |
| 5020 | |
| 5021 | // if((ai_info->ai_type == AIT_MELEE1) && |
| 5022 | //(ai_info->status_reg & AISR_MELEE)) |
| 5023 | // { |
| 5024 | // AIMoveTowardsPosition(obj, |
| 5025 | //&ai_info->last_see_target_pos, ai_info->attack_vel_percent); |
| 5026 | // } |
| 5027 | // else |
| 5028 | |
| 5029 | if (ai_info->dist_to_target_perceived < .7f * g_circle_dist) { |
| 5030 | move_away_from_position(obj, &ai_info->last_see_target_pos, ai_info->flee_vel_percent, &goal_mdir, |
| 5031 | &goal_f_moved); |
| 5032 | goal_mset = true; |
| 5033 | |
| 5034 | if (ai_info->sound[AI_FLEE_SOUND] != SOUND_NONE_INDEX) { |
| 5035 | // Plays the sound and makes absolute sure that it is not looping |
| 5036 | if (Gametime - ai_info->last_sound_time[AI_FLEE_SOUND] > 5.0f) { |
| 5037 | // A 25% chance of playing it |
| 5038 | if (ps_rand() % 4 == 0) { |
| 5039 | Sound_system.StopSoundLooping( |
| 5040 | Sound_system.Play3dSound(ai_info->sound[AI_FLEE_SOUND], SND_PRIORITY_NORMAL, obj)); |
| 5041 | if (Game_mode & GM_MULTI) |
| 5042 | MultiPlay3dSound(ai_info->sound[AI_FLEE_SOUND], OBJNUM(obj), SND_PRIORITY_NORMAL); |
| 5043 | if (Demo_flags == DF_RECORDING) |
| 5044 | DemoWrite3DSound(ai_info->sound[AI_FLEE_SOUND], OBJNUM(obj), SND_PRIORITY_NORMAL); |
| 5045 | } |
| 5046 | |
| 5047 | ai_info->last_sound_time[AI_FLEE_SOUND] = Gametime; |
| 5048 | } |
| 5049 | } |
| 5050 | } else if (g_status & AISR_CIRCLE_DIST) { |
| 5051 | vector movement_vec; |
| 5052 | int gtime = Gametime + OBJNUM(obj); |
| 5053 | gtime = gtime % 8; |
| 5054 | |
| 5055 | object *rel_obj; |
| 5056 | |
| 5057 | if (ai_info->flags & AIF_ORIENT_TO_VEL) |
| 5058 | rel_obj = goal_obj; |
| 5059 | else |
| 5060 | rel_obj = obj; |
| 5061 | |
| 5062 | if (rel_obj) { |
| 5063 | if (gtime < 2) |
| 5064 | movement_vec = rel_obj->orient.rvec; |
| 5065 | else if (gtime < 4) |
| 5066 | movement_vec = -rel_obj->orient.rvec; |
| 5067 | else if (gtime < 6) { |
| 5068 | if (obj->movement_type != MT_WALKING) { |
| 5069 | movement_vec = rel_obj->orient.uvec; |
| 5070 | } else { |
| 5071 | movement_vec = -rel_obj->orient.rvec; |
| 5072 | } |
| 5073 | } else { |
| 5074 | if (obj->movement_type != MT_WALKING) { |
| 5075 | movement_vec = -rel_obj->orient.uvec; |
| 5076 | } else { |
| 5077 | movement_vec = rel_obj->orient.rvec; |
| 5078 | } |
| 5079 | } |
| 5080 | } else { |
| 5081 | movement_vec = obj->orient.rvec; |
| 5082 | } |
| 5083 | |
| 5084 | if (obj->movement_type == MT_WALKING) { |
| 5085 | int16_t robots[6]; |
| 5086 | int num_robots = |
| 5087 | fvi_QuickDistObjectList(&obj->pos, obj->roomnum, 30.0f, robots, 6, false, true, false, true); |
| 5088 | vector d = Zero_vector; |
| 5089 | int i; |
| 5090 | float closest = 100000.0f; |
| 5091 | |
| 5092 | if (num_robots > 0) { |
| 5093 | for (i = 0; i < num_robots; i++) { |
| 5094 | if (Objects[robots[i]].type == obj->type && Objects[robots[i]].id == obj->id) { |
| 5095 | vector dir; |
| 5096 | float distance; |
| 5097 | |
| 5098 | // Reverse of move towards |
| 5099 | dir = obj->pos - Objects[robots[i]].pos; |
| 5100 | distance = vm_NormalizeVector(&dir); |
| 5101 | |
| 5102 | if (distance > 0.0) { |
| 5103 | if (distance < closest) { |
| 5104 | closest = distance; |
| 5105 | } |
| 5106 | |
| 5107 | if (distance < 30.0) { |
| 5108 | d += (1.0f - distance / 30.f) * dir; |
| 5109 | } |
| 5110 | } |
| 5111 | } |
| 5112 | } |
| 5113 | } |
| 5114 | |
| 5115 | if (d != Zero_vector) { |
| 5116 | if (closest < 30.0f) { |
| 5117 | float scale = 1.0f - closest / 30.0f; |
| 5118 | vm_NormalizeVector(&d); |
| 5119 | |
| 5120 | movement_vec = (scale * d) + (1.0f - scale) * movement_vec; |
| 5121 | vm_NormalizeVector(&movement_vec); |
| 5122 | } |
| 5123 | } |
| 5124 | |
| 5125 | goal_mdir = movement_vec; |
| 5126 | goal_mset = true; |
| 5127 | // AIMoveTowardsDir(obj, |
| 5128 | //&movement_vec); |
| 5129 | } else { |
| 5130 | goal_mdir = movement_vec; |
| 5131 | goal_mset = true; |
| 5132 | // AIMoveTowardsDir(obj, |
| 5133 | //&movement_vec); |
| 5134 | } |
| 5135 | } else { |
| 5136 | AIMoveTowardsPosition(obj, &ai_info->last_see_target_pos, 1.0f, false, &goal_mdir, &goal_f_moved); |
| 5137 | goal_mset = true; |
| 5138 | } |
| 5139 | } break; |
| 5140 | |
| 5141 | default: { |
| 5142 | mprintf(0, "AI ERROR: Object %d trying a non-implemented goal\n", OBJNUM(obj)); |
| 5143 | AIMoveTowardsPosition(obj, &ai_info->last_see_target_pos, 1.0f, true, &goal_mdir, &goal_f_moved); |
| 5144 | goal_mset = true; |
| 5145 | } |
| 5146 | } |
| 5147 | } else { |
| 5148 | if (!(f_dodge || f_avoid || |
| 5149 | (ai_info->dodge_till_time >= Gametime && ai_info->last_dodge_dir != Zero_vector))) { |
| 5150 | AIMoveTowardsPosition(obj, &obj->pos, 1.0f, false, &goal_mdir, &goal_f_moved); |
| 5151 | goal_mset = true; |
| 5152 | } |
| 5153 | } |
| 5154 | |
| 5155 | // BLEND THIS! |
| 5156 | if ((f_dodge || f_avoid || (ai_info->dodge_till_time >= Gametime && ai_info->last_dodge_dir != Zero_vector)) || |
| 5157 | (!goal_f_moved && goal_mset)) { |
| 5158 | if (!f_dodge && (ai_info->dodge_till_time >= Gametime && ai_info->last_dodge_dir != Zero_vector)) { |
| 5159 | f_dodge = true; |
| 5160 | ai_info->movement_dir += ai_info->last_dodge_dir; |
| 5161 | |
| 5162 | if (ai_info->dodge_vel_percent > highest_speed) { |
| 5163 | highest_speed = ai_info->dodge_vel_percent; |
| 5164 | } |
| 5165 | } |
| 5166 | |
| 5167 | if (!goal_f_moved && goal_mset) { |
| 5168 | ai_info->movement_dir += goal_mdir * cur_goal->influence; |
| 5169 | } |
| 5170 | |
| 5171 | float move_len = vm_NormalizeVector(&ai_info->movement_dir); |
| 5172 | if (move_len == 0.0f) { |
| 5173 | vm_MakeRandomVector(&ai_info->movement_dir); |
| 5174 | vm_NormalizeVector(&ai_info->movement_dir); |
| 5175 | } |
| 5176 | |
| 5177 | AIMoveTowardsDir(obj, &ai_info->movement_dir, highest_speed); |
| 5178 | f_turned = false; |
| 5179 | } |
| 5180 | } |
| 5181 | } |
| 5182 | |
| 5183 | // Handle orientation now |
| 5184 | if ((!f_turned || |
| 5185 | ((!f_goal_found && Gametime - ai_info->last_see_target_time < 5.0f) && |
| 5186 | (!f_goal_found && Gametime - ai_info->last_hear_target_time < 5.0f) && (ai_info->flags & AIF_FIRE))) && |
| 5187 | ai_info->max_turn_rate > 0.0f) |
| 5188 | AIDoOrient(obj, highest_influence_goal); |
| 5189 | } |
| 5190 | } |
| 5191 | |
| 5192 | #define MAX_NOT_SEE_TARGET_FIRE_TIME 2.0f |
| 5193 | #define MIN_TURRET_SOUND_TIME 0.8f |
| 5194 | #define DEFAULT_FIRE_DOT .93f |
| 5195 | |
| 5196 | void ai_fire(object *obj) { |
| 5197 | if (!Object_info[obj->id].static_wb) { |
| 5198 | // something is hosed due to 'Mac memory savings' (c) |
| 5199 | Int3(); |
| 5200 | return; // object can't fire anything... |
| 5201 | } |
| 5202 | |
| 5203 | ai_frame *ai_info = obj->ai_info; |
| 5204 | int i; |
| 5205 | int j; |
| 5206 | poly_model *pm = &Poly_models[obj->rtype.pobj_info.model_num]; |
| 5207 | object_info *obj_info = &Object_info[obj->id]; |
| 5208 | bool f_turret_next_move_still; |
| 5209 | |
| 5210 | //. mprintf(0, "Aiming\n"); |
| 5211 | if (!(ai_info->flags & AIF_FIRE)) { |
| 5212 | if (ai_info->status_reg & AISR_RANGED_ATTACK) { |
| 5213 | for (i = 0; i < pm->num_wbs; i++) { |
| 5214 | if (!(obj->dynamic_wb[i].flags & DWBF_ENABLED)) |
| 5215 | continue; |
| 5216 | |
| 5217 | if (WBIsBatteryReady(obj, &obj_info->static_wb[i], i) && |
| 5218 | !(Cinematic_inuse && !(ai_info->status_reg & AISR_OK_TO_FIRE_DURING_CINEMATICS))) { |
| 5219 | int anim_type = obj_info->static_wb[i].flags & WBF_ANIM_MASKS; |
| 5220 | |
| 5221 | if (anim_type == WBF_ANIM_LOCAL) { |
| 5222 | WBSetupFireAnim(obj, &obj_info->static_wb[i], i); |
| 5223 | } else if (anim_type == WBF_ANIM_FULL) { |
| 5224 | gi_fire attack_info; |
| 5225 | |
| 5226 | attack_info.cur_wb = i; |
| 5227 | attack_info.cur_mask = obj->dynamic_wb[i].cur_firing_mask; |
| 5228 | |
| 5229 | GoalAddGoal(obj, AIG_FIRE_AT_OBJ, (void *)&attack_info, ACTIVATION_BLEND_LEVEL); |
| 5230 | } else { |
| 5231 | WBFireBattery(obj, &obj_info->static_wb[i], i); |
| 5232 | ai_info->status_reg &= ~AISR_RANGED_ATTACK; |
| 5233 | } |
| 5234 | } |
| 5235 | } |
| 5236 | } |
| 5237 | |
| 5238 | return; |
| 5239 | } |
| 5240 | |
| 5241 | if (((Gametime - ai_info->last_see_target_time) > 4.0 && (Gametime - ai_info->last_hear_target_time) > 4.0) || |
| 5242 | ai_info->awareness <= AWARE_BARELY) { |
| 5243 | ai_info->status_reg &= ~AISR_RANGED_ATTACK; |
| 5244 | return; |
| 5245 | } |
| 5246 | |
| 5247 | for (i = 0; i < pm->num_wbs; i++) { |
| 5248 | vector target_dir[3]; |
| 5249 | float dot[3]; |
| 5250 | vector gun_point[3]; |
| 5251 | vector gun_normal[3]; |
| 5252 | float ta[3]; |
| 5253 | int best_dot = WB_MOVE_STILL; |
| 5254 | |
| 5255 | if (!(obj->dynamic_wb[i].flags & DWBF_ENABLED)) |
| 5256 | continue; |
| 5257 | |
| 5258 | if (obj_info->static_wb[i].flags & WBF_USE_CUSTOM_MAX_DIST) { |
| 5259 | float max_dist = obj_info->static_wb[i].aiming_3d_dist; |
| 5260 | |
| 5261 | if (max_dist < ai_info->dist_to_target_actual) |
| 5262 | continue; |
| 5263 | } |
| 5264 | |
| 5265 | int aiming_gp_index = obj_info->static_wb[i].aiming_gp_index; |
| 5266 | |
| 5267 | // The WBF_AIM_FVEC and WBF_FIRE_FVEC stuff will work with a dummy turret or with no turrets |
| 5268 | if (pm->poly_wb[i].num_turrets == 0 || |
| 5269 | (pm->poly_wb[i].num_turrets == 1 && pm->submodel[pm->poly_wb[i].turret_index[0]].fov == 0.0f)) { |
| 5270 | if (WBIsBatteryReady(obj, &obj_info->static_wb[i], i) && |
| 5271 | !(Cinematic_inuse && !(ai_info->status_reg & AISR_OK_TO_FIRE_DURING_CINEMATICS))) { |
| 5272 | if (obj_info->static_wb[i].flags & WBF_AIM_FVEC) { |
| 5273 | gun_point[WB_MOVE_STILL] = obj->pos; |
| 5274 | gun_normal[WB_MOVE_STILL] = obj->orient.fvec; |
| 5275 | |
| 5276 | if (obj_info->static_wb[i].flags & WBF_FIRE_FVEC) { |
| 5277 | gun_normal[WB_MOVE_STILL] = obj->orient.fvec; |
| 5278 | } |
| 5279 | } |
| 5280 | if (obj_info->static_wb[i].flags & WBF_FIRE_FVEC) { |
| 5281 | WeaponCalcGun(&gun_point[WB_MOVE_STILL], NULL, obj, pm->poly_wb[i].gp_index[aiming_gp_index]); |
| 5282 | gun_normal[WB_MOVE_STILL] = obj->orient.fvec; |
| 5283 | } else { |
| 5284 | WeaponCalcGun(&gun_point[WB_MOVE_STILL], &gun_normal[WB_MOVE_STILL], obj, |
| 5285 | pm->poly_wb[i].gp_index[aiming_gp_index]); |
| 5286 | } |
| 5287 | |
| 5288 | target_dir[WB_MOVE_STILL] = ai_info->last_see_target_pos - gun_point[WB_MOVE_STILL]; |
| 5289 | vm_NormalizeVector(&target_dir[WB_MOVE_STILL]); |
| 5290 | dot[WB_MOVE_STILL] = gun_normal[WB_MOVE_STILL] * target_dir[WB_MOVE_STILL]; |
| 5291 | |
| 5292 | best_dot = WB_MOVE_STILL; |
| 5293 | } |
| 5294 | } |
| 5295 | |
| 5296 | for (j = 0; j < pm->poly_wb[i].num_turrets; j++) { |
| 5297 | f_turret_next_move_still = false; |
| 5298 | best_dot = WB_MOVE_STILL; |
| 5299 | float min_invalid_ang; |
| 5300 | float max_invalid_ang; |
| 5301 | bool f_constrain = true; |
| 5302 | |
| 5303 | float s_scale = |
| 5304 | (((obj->ai_info->flags & AIF_TEAM_MASK) != AIF_TEAM_REBEL)) ? Diff_ai_turret_speed[DIFF_LEVEL] : 1.0f; |
| 5305 | const float rps = pm->submodel[pm->poly_wb[i].turret_index[j]].rps * s_scale; |
| 5306 | |
| 5307 | if (pm->submodel[pm->poly_wb[i].turret_index[j]].fov > |
| 5308 | 0.0f) // Gametime >= obj->dynamic_wb[i].turret_next_think_time[j]) |
| 5309 | { |
| 5310 | min_invalid_ang = pm->submodel[pm->poly_wb[i].turret_index[j]].fov; |
| 5311 | max_invalid_ang = 1.0 - min_invalid_ang; |
| 5312 | |
| 5313 | if (min_invalid_ang >= 0.5f) |
| 5314 | f_constrain = false; |
| 5315 | |
| 5316 | ta[WB_MOVE_STILL] = obj->dynamic_wb[i].norm_turret_angle[j]; |
| 5317 | |
| 5318 | ta[WB_MOVE_RIGHT] = obj->dynamic_wb[i].norm_turret_angle[j] - Frametime * rps; |
| 5319 | while (ta[WB_MOVE_RIGHT] < 0.0) |
| 5320 | ta[WB_MOVE_RIGHT] += 1.0f; |
| 5321 | |
| 5322 | if (f_constrain && ta[WB_MOVE_RIGHT] > min_invalid_ang && ta[WB_MOVE_RIGHT] < max_invalid_ang) |
| 5323 | ta[WB_MOVE_RIGHT] = max_invalid_ang; |
| 5324 | |
| 5325 | ta[WB_MOVE_LEFT] = obj->dynamic_wb[i].norm_turret_angle[j] + Frametime * rps; |
| 5326 | while (ta[WB_MOVE_LEFT] > 1.0) |
| 5327 | ta[WB_MOVE_LEFT] -= 1.0f; |
| 5328 | |
| 5329 | if (f_constrain && ta[WB_MOVE_LEFT] > min_invalid_ang && ta[WB_MOVE_LEFT] < max_invalid_ang) |
| 5330 | ta[WB_MOVE_LEFT] = min_invalid_ang; |
| 5331 | |
| 5332 | WeaponCalcGun(&gun_point[WB_MOVE_STILL], &gun_normal[WB_MOVE_STILL], obj, |
| 5333 | pm->poly_wb[i].gp_index[aiming_gp_index]); |
| 5334 | |
| 5335 | obj->dynamic_wb[i].norm_turret_angle[j] = ta[WB_MOVE_RIGHT]; |
| 5336 | WeaponCalcGun(&gun_point[WB_MOVE_RIGHT], &gun_normal[WB_MOVE_RIGHT], obj, |
| 5337 | pm->poly_wb[i].gp_index[aiming_gp_index]); |
| 5338 | |
| 5339 | obj->dynamic_wb[i].norm_turret_angle[j] = ta[WB_MOVE_LEFT]; |
| 5340 | WeaponCalcGun(&gun_point[WB_MOVE_LEFT], &gun_normal[WB_MOVE_LEFT], obj, |
| 5341 | pm->poly_wb[i].gp_index[aiming_gp_index]); |
| 5342 | |
| 5343 | // mprintf(0, "Weapon %f, %f, %f and normal %f, %f, %f\n", XYZ(&gun_point), XYZ(&gun_normal)); |
| 5344 | |
| 5345 | target_dir[WB_MOVE_STILL] = ai_info->last_see_target_pos - gun_point[WB_MOVE_STILL]; |
| 5346 | target_dir[WB_MOVE_RIGHT] = ai_info->last_see_target_pos - gun_point[WB_MOVE_RIGHT]; |
| 5347 | target_dir[WB_MOVE_LEFT] = ai_info->last_see_target_pos - gun_point[WB_MOVE_LEFT]; |
| 5348 | |
| 5349 | vm_NormalizeVector(&target_dir[WB_MOVE_STILL]); |
| 5350 | vm_NormalizeVector(&target_dir[WB_MOVE_RIGHT]); |
| 5351 | vm_NormalizeVector(&target_dir[WB_MOVE_LEFT]); |
| 5352 | |
| 5353 | dot[WB_MOVE_STILL] = gun_normal[WB_MOVE_STILL] * target_dir[WB_MOVE_STILL]; |
| 5354 | dot[WB_MOVE_RIGHT] = gun_normal[WB_MOVE_RIGHT] * target_dir[WB_MOVE_RIGHT]; |
| 5355 | dot[WB_MOVE_LEFT] = gun_normal[WB_MOVE_LEFT] * target_dir[WB_MOVE_LEFT]; |
| 5356 | |
| 5357 | if (dot[WB_MOVE_RIGHT] > dot[WB_MOVE_STILL]) |
| 5358 | best_dot = WB_MOVE_RIGHT; |
| 5359 | if (dot[WB_MOVE_LEFT] > dot[best_dot]) |
| 5360 | best_dot = WB_MOVE_LEFT; |
| 5361 | |
| 5362 | obj->dynamic_wb[i].norm_turret_angle[j] = ta[best_dot]; |
| 5363 | |
| 5364 | uint8_t last_t_d = obj->dynamic_wb[i].turret_direction[j]; |
| 5365 | |
| 5366 | if (dot[WB_MOVE_RIGHT] > dot[WB_MOVE_LEFT]) |
| 5367 | obj->dynamic_wb[i].turret_direction[j] = WB_MOVE_RIGHT; |
| 5368 | else |
| 5369 | obj->dynamic_wb[i].turret_direction[j] = WB_MOVE_LEFT; |
| 5370 | |
| 5371 | if (last_t_d != obj->dynamic_wb[i].turret_direction[j]) { |
| 5372 | if (ai_info->sound[AI_TURRET_SOUND] != SOUND_NONE_INDEX && |
| 5373 | (ai_info->last_sound_time[AI_TURRET_SOUND] + MIN_TURRET_SOUND_TIME <= Gametime)) { |
| 5374 | // Plays the sound and makes absolute sure that it is not looping |
| 5375 | Sound_system.StopSoundLooping( |
| 5376 | Sound_system.Play3dSound(ai_info->sound[AI_TURRET_SOUND], SND_PRIORITY_NORMAL, obj)); |
| 5377 | if (Game_mode & GM_MULTI) |
| 5378 | MultiPlay3dSound(ai_info->sound[AI_TURRET_SOUND], OBJNUM(obj), SND_PRIORITY_NORMAL); |
| 5379 | if (Demo_flags == DF_RECORDING) |
| 5380 | DemoWrite3DSound(ai_info->sound[AI_TURRET_SOUND], OBJNUM(obj), SND_PRIORITY_NORMAL); |
| 5381 | |
| 5382 | ai_info->last_sound_time[AI_TURRET_SOUND] = Gametime; |
| 5383 | } |
| 5384 | } |
| 5385 | |
| 5386 | obj->dynamic_wb[i].turret_next_think_time[j] += pm->submodel[pm->poly_wb[i].turret_index[j]].think_interval; |
| 5387 | if (Demo_flags == DF_RECORDING) { |
| 5388 | DemoWriteTurretChanged(OBJNUM(obj)); |
| 5389 | } |
| 5390 | if (Game_mode & GM_MULTI) { |
| 5391 | MultiAddObjTurretUpdate(OBJNUM(obj)); |
| 5392 | } |
| 5393 | |
| 5394 | } else { |
| 5395 | best_dot = obj->dynamic_wb[i].turret_direction[j]; |
| 5396 | |
| 5397 | if (best_dot != WB_MOVE_STILL) { |
| 5398 | min_invalid_ang = pm->submodel[pm->poly_wb[i].turret_index[j]].fov; |
| 5399 | max_invalid_ang = 1.0 - min_invalid_ang; |
| 5400 | |
| 5401 | if (min_invalid_ang >= 0.5f) |
| 5402 | f_constrain = false; |
| 5403 | } |
| 5404 | |
| 5405 | // chrishack -- make next still |
| 5406 | switch (best_dot) { |
| 5407 | case WB_MOVE_STILL: |
| 5408 | ta[WB_MOVE_STILL] = obj->dynamic_wb[i].norm_turret_angle[j]; |
| 5409 | break; |
| 5410 | |
| 5411 | case WB_MOVE_RIGHT: |
| 5412 | ta[WB_MOVE_RIGHT] = obj->dynamic_wb[i].norm_turret_angle[j] - Frametime * rps; |
| 5413 | while (ta[WB_MOVE_RIGHT] < 0.0) |
| 5414 | ta[WB_MOVE_RIGHT] += 1.0f; |
| 5415 | |
| 5416 | if (f_constrain && ta[WB_MOVE_RIGHT] > min_invalid_ang && ta[WB_MOVE_RIGHT] < max_invalid_ang) { |
| 5417 | ta[WB_MOVE_RIGHT] = max_invalid_ang; |
| 5418 | f_turret_next_move_still = true; |
| 5419 | } |
| 5420 | break; |
| 5421 | |
| 5422 | case WB_MOVE_LEFT: |
| 5423 | ta[WB_MOVE_LEFT] = obj->dynamic_wb[i].norm_turret_angle[j] + Frametime * rps; |
| 5424 | while (ta[WB_MOVE_LEFT] > 1.0) |
| 5425 | ta[WB_MOVE_LEFT] -= 1.0f; |
| 5426 | |
| 5427 | if (f_constrain && ta[WB_MOVE_LEFT] > min_invalid_ang && ta[WB_MOVE_LEFT] < max_invalid_ang) { |
| 5428 | ta[WB_MOVE_LEFT] = min_invalid_ang; |
| 5429 | f_turret_next_move_still = true; |
| 5430 | } |
| 5431 | break; |
| 5432 | } |
| 5433 | |
| 5434 | obj->dynamic_wb[i].norm_turret_angle[j] = ta[best_dot]; |
| 5435 | |
| 5436 | if (WBIsBatteryReady(obj, &obj_info->static_wb[i], i) && |
| 5437 | !(Cinematic_inuse && !(ai_info->status_reg & AISR_OK_TO_FIRE_DURING_CINEMATICS))) { |
| 5438 | WeaponCalcGun(&gun_point[best_dot], &gun_normal[best_dot], obj, pm->poly_wb[i].gp_index[aiming_gp_index]); |
| 5439 | |
| 5440 | target_dir[best_dot] = ai_info->last_see_target_pos - gun_point[best_dot]; |
| 5441 | vm_NormalizeVector(&target_dir[best_dot]); |
| 5442 | dot[best_dot] = gun_normal[best_dot] * target_dir[best_dot]; |
| 5443 | } |
| 5444 | } |
| 5445 | |
| 5446 | // This happens on a non-thinking frame the the turret hits a constrain |
| 5447 | if (f_turret_next_move_still) |
| 5448 | obj->dynamic_wb[i].turret_direction[j] = WB_MOVE_STILL; |
| 5449 | } |
| 5450 | |
| 5451 | if (Gametime - ai_info->last_see_target_time < MAX_NOT_SEE_TARGET_FIRE_TIME || |
| 5452 | Gametime - ai_info->last_hear_target_time < MAX_NOT_SEE_TARGET_FIRE_TIME) { |
| 5453 | if (WBIsBatteryReady(obj, &obj_info->static_wb[i], i) && |
| 5454 | !(Cinematic_inuse && !(ai_info->status_reg & AISR_OK_TO_FIRE_DURING_CINEMATICS))) { |
| 5455 | float fire_dot; |
| 5456 | |
| 5457 | if (obj_info->static_wb[i].flags & WBF_USE_CUSTOM_FOV) |
| 5458 | fire_dot = obj_info->static_wb[i].aiming_3d_dot; |
| 5459 | else |
| 5460 | fire_dot = DEFAULT_FIRE_DOT; |
| 5461 | |
| 5462 | if (dot[best_dot] >= fire_dot) { |
| 5463 | bool f_no_fire = false; |
| 5464 | int anim_type = obj_info->static_wb[i].flags & WBF_ANIM_MASKS; |
| 5465 | |
| 5466 | if (ai_info->agression == 0.0f && ai_info->memory[0].num_times_hit == 0) { |
| 5467 | // Assume no fire |
| 5468 | f_no_fire = true; |
| 5469 | |
| 5470 | object *target = ObjGet(ai_info->target_handle); |
| 5471 | if (target) { |
| 5472 | fvi_query fq; |
| 5473 | fvi_info hit_info; |
| 5474 | int fate; |
| 5475 | int ignore_obj_list[100]; |
| 5476 | ignore_obj_list[0] = OBJNUM(obj); |
| 5477 | int num_ignored = 1; |
| 5478 | int i; |
| 5479 | |
| 5480 | // CHRISHACK - ONLY IGNORES FIRST LEVEL OF CHILDREN - DO RECERSIVE |
| 5481 | for (i = 0; i < Poly_models[obj->rtype.pobj_info.model_num].n_attach; i++) { |
| 5482 | object *child; |
| 5483 | |
| 5484 | if ((child = ObjGet(obj->attach_children[i])) != NULL && num_ignored < 99) { |
| 5485 | ignore_obj_list[num_ignored++] = OBJNUM(child); |
| 5486 | } |
| 5487 | } |
| 5488 | |
| 5489 | ignore_obj_list[num_ignored] = -1; |
| 5490 | |
| 5491 | fq.p0 = &obj->pos; |
| 5492 | fq.p1 = &target->pos; |
| 5493 | fq.startroom = obj->roomnum; |
| 5494 | |
| 5495 | fq.rad = 0.01f; |
| 5496 | fq.flags = FQ_CHECK_OBJS | FQ_IGNORE_WEAPONS | FQ_IGNORE_POWERUPS | FQ_IGNORE_RENDER_THROUGH_PORTALS | |
| 5497 | FQ_NO_RELINK; |
| 5498 | fq.thisobjnum = -1; |
| 5499 | fq.ignore_obj_list = ignore_obj_list; |
| 5500 | |
| 5501 | fate = fvi_FindIntersection(&fq, &hit_info); |
| 5502 | |
| 5503 | if (fate != HIT_TERRAIN && fate != HIT_WALL && |
| 5504 | (((fate == HIT_OBJECT || fate == HIT_SPHERE_2_POLY_OBJECT) && |
| 5505 | hit_info.hit_object[0] == OBJNUM(target)) || |
| 5506 | fate == HIT_NONE)) { |
| 5507 | f_no_fire = false; |
| 5508 | } |
| 5509 | } |
| 5510 | } |
| 5511 | |
| 5512 | if (!f_no_fire) { |
| 5513 | if (anim_type == WBF_ANIM_LOCAL) { |
| 5514 | WBSetupFireAnim(obj, &obj_info->static_wb[i], i); |
| 5515 | } else if (anim_type == WBF_ANIM_FULL) { |
| 5516 | gi_fire attack_info; |
| 5517 | |
| 5518 | attack_info.cur_wb = i; |
| 5519 | attack_info.cur_mask = obj->dynamic_wb[i].cur_firing_mask; |
| 5520 | |
| 5521 | GoalAddGoal(obj, AIG_FIRE_AT_OBJ, (void *)&attack_info, ACTIVATION_BLEND_LEVEL); |
| 5522 | } else { |
| 5523 | WBFireBattery(obj, &obj_info->static_wb[i], i); |
| 5524 | ai_info->status_reg &= ~AISR_RANGED_ATTACK; |
| 5525 | } |
| 5526 | } else { |
| 5527 | ai_info->status_reg &= ~AISR_RANGED_ATTACK; |
| 5528 | obj->dynamic_wb[i].last_fire_time = Gametime + 1.0f + ps_rand() / (float)D3_RAND_MAX; |
| 5529 | } |
| 5530 | } |
| 5531 | } |
| 5532 | } |
| 5533 | } |
| 5534 | } |
| 5535 | |
| 5536 | #define PERCENT_QUIRK_PER_SEC .1 |
| 5537 | #define PERCENT_TAUNT_PER_SEC .1 |
| 5538 | |
| 5539 | static inline void do_awareness_based_anim_stuff(object *obj) { |
| 5540 | int next_anim; |
| 5541 | ai_frame *ai_info = obj->ai_info; |
| 5542 | |
| 5543 | if (ai_info->awareness <= AWARE_BARELY) { |
| 5544 | if (ai_info->animation_type == AS_ALERT && ai_info->next_animation_type != AS_GOTO_ALERT_STANDING) { |
| 5545 | next_anim = AS_IDLE; |
| 5546 | GoalAddGoal(obj, AIG_SET_ANIM, (void *)&next_anim, ACTIVATION_BLEND_LEVEL); |
| 5547 | } else if (ai_info->animation_type == AS_IDLE && ai_info->next_animation_type != AS_GOTO_IDLE_STANDING) { |
| 5548 | float local_seed = OBJNUM(obj) / 32.0f; |
| 5549 | |
| 5550 | int new_time_int = Gametime + local_seed; |
| 5551 | int last_time_int = Gametime - Frametime + local_seed; |
| 5552 | |
| 5553 | // Once a second we have a chance of doing a quirk |
| 5554 | if (new_time_int != last_time_int) { |
| 5555 | if (ps_rand() < D3_RAND_MAX * PERCENT_QUIRK_PER_SEC) { |
| 5556 | next_anim = AS_QUIRK; |
| 5557 | GoalAddGoal(obj, AIG_SET_ANIM, (void *)&next_anim, ACTIVATION_BLEND_LEVEL); |
| 5558 | } |
| 5559 | } |
| 5560 | } |
| 5561 | } else if (ai_info->animation_type == AS_IDLE || ai_info->animation_type == AS_QUIRK || |
| 5562 | ai_info->animation_type == AS_BIRTH) { |
| 5563 | next_anim = AS_ALERT; |
| 5564 | GoalAddGoal(obj, AIG_SET_ANIM, (void *)&next_anim, ACTIVATION_BLEND_LEVEL); |
| 5565 | } else if (ai_info->animation_type == AS_ALERT) { |
| 5566 | if (!(ai_info->flags & AIF_ONLY_TAUNT_AT_DEATH) && |
| 5567 | (Object_info[obj->id].anim[ai_info->movement_type].elem[AS_TAUNT].to != 0.0f)) { |
| 5568 | float local_seed = OBJNUM(obj) / 32.0f; |
| 5569 | |
| 5570 | int new_time_int = Gametime + local_seed; |
| 5571 | int last_time_int = Gametime - Frametime + local_seed; |
| 5572 | |
| 5573 | // Once a second we have a chance of doing a quirk |
| 5574 | if (new_time_int != last_time_int) { |
| 5575 | if (ps_rand() < D3_RAND_MAX * PERCENT_TAUNT_PER_SEC) { |
| 5576 | next_anim = AS_TAUNT; |
| 5577 | GoalAddGoal(obj, AIG_SET_ANIM, (void *)&next_anim, ACTIVATION_BLEND_LEVEL); |
| 5578 | } |
| 5579 | } |
| 5580 | } |
| 5581 | } |
| 5582 | } |
| 5583 | |
| 5584 | static inline void ai_decrease_awareness(object *obj) { |
| 5585 | ai_frame *ai_info = obj->ai_info; |
| 5586 | |
| 5587 | if (ai_info->awareness == AWARE_NONE && !(ai_info->flags & AIF_PERSISTANT)) { |
| 5588 | #ifdef _DEBUG |
| 5589 | if (AI_debug_robot_do && OBJNUM(obj) == AI_debug_robot_index) { |
| 5590 | mprintf(0, "AI Note: In free path\n"); |
| 5591 | } |
| 5592 | #endif |
| 5593 | AIPathFreePath(&ai_info->path); |
| 5594 | } |
| 5595 | |
| 5596 | if (Gametime - ai_info->last_render_time < AWARENESS_RENDER_RECENTLY_INTERVAL || |
| 5597 | Gametime - ai_info->last_see_target_time < AWARENESS_SEE_TARGET_RECENTLY_INTERVAL || |
| 5598 | Gametime - ai_info->last_hear_target_time < AWARENESS_SEE_TARGET_RECENTLY_INTERVAL) |
| 5599 | ai_info->awareness -= (AWARE_RENDER_RECENTLY_FALLOFF * Frametime); |
| 5600 | else |
| 5601 | ai_info->awareness -= (AWARE_FALLOFF * Frametime); |
| 5602 | |
| 5603 | if (ai_info->awareness < AWARE_NONE) { |
| 5604 | ai_info->awareness = AWARE_NONE; |
| 5605 | } |
| 5606 | |
| 5607 | // mprintf(0, "Awareness %f", ai_info->awareness); |
| 5608 | } |
| 5609 | |
| 5610 | static inline bool ai_do_script_stuff(object *obj) { |
| 5611 | tOSIRISEventInfo ei; |
| 5612 | Osiris_CallEvent(obj, EVT_AI_FRAME, &ei); |
| 5613 | //@$-D3XExecScript(obj, EVT_AI_FRAME, NULL, REF_OBJTYPE, NULL); |
| 5614 | |
| 5615 | return true; |
| 5616 | } |
| 5617 | |
| 5618 | static inline void ai_walker_stuff(object *obj) { |
| 5619 | ai_frame *ai_info = obj->ai_info; |
| 5620 | |
| 5621 | // Do standing->walking and walking->standing stuff |
| 5622 | if (ai_info->movement_type == MC_STANDING) { |
| 5623 | int next_anim; |
| 5624 | |
| 5625 | if (vm_GetMagnitude(&obj->mtype.phys_info.velocity) > 0.01f || |
| 5626 | vm_GetMagnitude(&obj->mtype.phys_info.rotvel) > 0.01) { |
| 5627 | if (ai_info->next_animation_type == AI_INVALID_INDEX) { |
| 5628 | if (ai_info->animation_type == AS_ALERT) { |
| 5629 | next_anim = AS_GOTO_ALERT_WALKING; |
| 5630 | GoalAddGoal(obj, AIG_SET_ANIM, (void *)&next_anim, ACTIVATION_BLEND_LEVEL); |
| 5631 | } else if (ai_info->animation_type == AS_IDLE || ai_info->animation_type == AS_QUIRK || |
| 5632 | ai_info->animation_type == AS_BIRTH) { |
| 5633 | next_anim = AS_GOTO_IDLE_WALKING; |
| 5634 | GoalAddGoal(obj, AIG_SET_ANIM, (void *)&next_anim, ACTIVATION_BLEND_LEVEL); |
| 5635 | } |
| 5636 | } |
| 5637 | |
| 5638 | obj->mtype.phys_info.velocity = Zero_vector; |
| 5639 | } |
| 5640 | } else if (ai_info->movement_type == MC_WALKING) { |
| 5641 | int next_anim; |
| 5642 | |
| 5643 | if (vm_GetMagnitude(&obj->mtype.phys_info.velocity) <= 0.01f && |
| 5644 | vm_GetMagnitude(&obj->mtype.phys_info.rotvel) <= 0.01) { |
| 5645 | if (ai_info->animation_type == AS_ALERT) { |
| 5646 | next_anim = AS_GOTO_ALERT_STANDING; |
| 5647 | GoalAddGoal(obj, AIG_SET_ANIM, (void *)&next_anim, ACTIVATION_BLEND_LEVEL); |
| 5648 | } else if (ai_info->animation_type == AS_IDLE) { |
| 5649 | next_anim = AS_GOTO_IDLE_STANDING; |
| 5650 | GoalAddGoal(obj, AIG_SET_ANIM, (void *)&next_anim, ACTIVATION_BLEND_LEVEL); |
| 5651 | } |
| 5652 | } |
| 5653 | } |
| 5654 | } |
| 5655 | |
| 5656 | int AIGetTeam(object *obj) { |
| 5657 | int t_team; |
| 5658 | |
| 5659 | if (obj->type == OBJ_PLAYER) { |
| 5660 | if (Num_teams > 1 || ((Game_mode & GM_MULTI) && Num_teams <= 1 && !(Netgame.flags & NF_DAMAGE_FRIENDLY))) { |
| 5661 | t_team = AIF_TEAM_REBEL + PlayerGetTeam(obj->id) + 1; |
| 5662 | //@@t_team = AIF_TEAM_REBEL + Players[obj->id].team + 1; |
| 5663 | } else { |
| 5664 | t_team = AIF_TEAM_REBEL + obj->id + 1; |
| 5665 | } |
| 5666 | } else { |
| 5667 | if (obj->ai_info->flags & AIF_ACT_AS_NEUTRAL_UNTIL_SHOT) { |
| 5668 | t_team = AIF_TEAM_NEUTRAL; |
| 5669 | } else { |
| 5670 | t_team = obj->ai_info->flags & AIF_TEAM_MASK; |
| 5671 | |
| 5672 | if (t_team == AIF_TEAM_REBEL) { |
| 5673 | object *p = ObjGet(obj->parent_handle); |
| 5674 | |
| 5675 | if (p && (p->type == OBJ_PLAYER || p->type == OBJ_GHOST)) { |
| 5676 | if (Num_teams > 1) { |
| 5677 | t_team += PlayerGetTeam(p->id) + 1; |
| 5678 | //@@t_team += Players[p->id].team + 1; |
| 5679 | } else { |
| 5680 | t_team += p->id + 1; |
| 5681 | } |
| 5682 | } |
| 5683 | } |
| 5684 | } |
| 5685 | } |
| 5686 | |
| 5687 | return t_team; |
| 5688 | } |
| 5689 | |
| 5690 | bool AIObjFriend(object *obj, object *target) { |
| 5691 | bool f_friend = false; |
| 5692 | |
| 5693 | // If an object isn't an AI object, it isn't a friend |
| 5694 | if (!obj || !target || (target->type != OBJ_PLAYER && !target->ai_info) || (obj->type != OBJ_PLAYER && !obj->ai_info)) |
| 5695 | return false; |
| 5696 | |
| 5697 | if (obj->type == OBJ_GHOST || obj->type == OBJ_POWERUP || (obj->flags & OF_DESTROYED)) |
| 5698 | return false; |
| 5699 | |
| 5700 | if ((target->control_type == CT_AI) && (target->movement_type == MT_NONE) && |
| 5701 | Poly_models[target->rtype.pobj_info.model_num].num_wbs == 0) { |
| 5702 | return false; |
| 5703 | } |
| 5704 | |
| 5705 | if (obj->type == OBJ_PLAYER && (Players[obj->id].flags & PLAYER_FLAGS_DEAD)) |
| 5706 | return false; |
| 5707 | |
| 5708 | int team = AIGetTeam(obj); |
| 5709 | int t_team = AIGetTeam(target); |
| 5710 | |
| 5711 | // If this object is targetting you - it is your enemy |
| 5712 | if ((target->control_type == CT_AI) && (target->ai_info->target_handle == obj->handle)) { |
| 5713 | return false; |
| 5714 | } |
| 5715 | |
| 5716 | // If its neutral and not targetting you -- its not an enemy (unless your hostile) |
| 5717 | if (team == AIF_TEAM_HOSTILE) |
| 5718 | return false; |
| 5719 | |
| 5720 | // Related objects shouldn't kill each other |
| 5721 | if (ObjectsAreRelated(OBJNUM(obj), OBJNUM(target))) { |
| 5722 | return true; |
| 5723 | } |
| 5724 | |
| 5725 | if (obj->parent_handle == target->handle || target->parent_handle == obj->handle) { |
| 5726 | return true; |
| 5727 | } |
| 5728 | |
| 5729 | switch (team) { |
| 5730 | case AIF_TEAM_PTMC: |
| 5731 | if (t_team == AIF_TEAM_PTMC) { |
| 5732 | f_friend = true; |
| 5733 | } |
| 5734 | break; |
| 5735 | |
| 5736 | case AIF_TEAM_HOSTILE: |
| 5737 | f_friend = false; |
| 5738 | break; |
| 5739 | |
| 5740 | case AIF_TEAM_NEUTRAL: |
| 5741 | |
| 5742 | if (t_team == AIF_TEAM_NEUTRAL) { |
| 5743 | f_friend = true; |
| 5744 | } |
| 5745 | break; |
| 5746 | |
| 5747 | // A player team |
| 5748 | default: |
| 5749 | // All REBEL sub teams are friends with non player-parented rebels |
| 5750 | if (t_team == AIF_TEAM_REBEL || team == AIF_TEAM_REBEL || t_team == team) { |
| 5751 | f_friend = true; |
| 5752 | } |
| 5753 | break; |
| 5754 | } |
| 5755 | |
| 5756 | return f_friend; |
| 5757 | } |
| 5758 | |
| 5759 | bool AIObjEnemy(object *obj, object *target) { |
| 5760 | bool f_enemy = false; |
| 5761 | |
| 5762 | // If an object isn't an AI object or player, it isn't an enemy |
| 5763 | if (!obj || !target || (target->type != OBJ_PLAYER && !target->ai_info) || (obj->type != OBJ_PLAYER && !obj->ai_info)) |
| 5764 | return false; |
| 5765 | |
| 5766 | if (obj->type == OBJ_GHOST || obj->type == OBJ_POWERUP || (obj->flags & OF_DESTROYED)) |
| 5767 | return false; |
| 5768 | |
| 5769 | if (obj->type == OBJ_PLAYER && (Players[obj->id].flags & PLAYER_FLAGS_DEAD)) |
| 5770 | return false; |
| 5771 | |
| 5772 | int team = AIGetTeam(obj); |
| 5773 | int t_team = AIGetTeam(target); |
| 5774 | |
| 5775 | // If this object is targetting you - it is your enemy |
| 5776 | if ((target->control_type == CT_AI) && (target->ai_info->target_handle == obj->handle)) { |
| 5777 | return true; |
| 5778 | } |
| 5779 | |
| 5780 | if ((target->control_type == CT_AI) && (target->movement_type == MT_NONE) && |
| 5781 | Poly_models[target->rtype.pobj_info.model_num].num_wbs == 0) { |
| 5782 | return false; |
| 5783 | } |
| 5784 | |
| 5785 | // If its neutral and not targetting you -- its not an enemy (unless your hostile) |
| 5786 | if ((team != AIF_TEAM_HOSTILE) && (t_team == AIF_TEAM_NEUTRAL && target->ai_info->target_handle != obj->handle)) { |
| 5787 | return false; |
| 5788 | } |
| 5789 | |
| 5790 | // Related objects shouldn't kill each other |
| 5791 | if (ObjectsAreRelated(OBJNUM(obj), OBJNUM(target))) { |
| 5792 | return false; |
| 5793 | } |
| 5794 | |
| 5795 | if (obj->parent_handle == target->handle || target->parent_handle == obj->handle) { |
| 5796 | return false; |
| 5797 | } |
| 5798 | |
| 5799 | switch (team) { |
| 5800 | case AIF_TEAM_PTMC: |
| 5801 | if (t_team != AIF_TEAM_PTMC) { |
| 5802 | f_enemy = true; |
| 5803 | } |
| 5804 | break; |
| 5805 | |
| 5806 | case AIF_TEAM_HOSTILE: |
| 5807 | f_enemy = true; |
| 5808 | break; |
| 5809 | |
| 5810 | case AIF_TEAM_NEUTRAL: |
| 5811 | |
| 5812 | ASSERT(obj->ai_info); |
| 5813 | |
| 5814 | if (obj->ai_info->target_handle == target->handle) { |
| 5815 | f_enemy = true; |
| 5816 | } |
| 5817 | break; |
| 5818 | |
| 5819 | // A player team |
| 5820 | default: |
| 5821 | // All REBEL sub teams are friends with non player-parented rebels |
| 5822 | if (t_team == AIF_TEAM_PTMC || t_team == AIF_TEAM_HOSTILE || |
| 5823 | (t_team != AIF_TEAM_REBEL && team != AIF_TEAM_REBEL && t_team != team && |
| 5824 | !(((Game_mode & GM_MULTI) && Num_teams <= 1 && !(Netgame.flags & NF_DAMAGE_FRIENDLY))))) { |
| 5825 | f_enemy = true; |
| 5826 | } |
| 5827 | break; |
| 5828 | } |
| 5829 | |
| 5830 | return f_enemy; |
| 5831 | } |
| 5832 | |
| 5833 | #define AI_FORGIVE_AGRESSION_MULTIPLIER 1.2f |
| 5834 | |
| 5835 | void AITargetCheck(object *obj, object *target, object **best_obj, float *best_dot, float *best_dist) { |
| 5836 | bool f_use_dot = (obj->ai_info->flags & AIF_TARGET_BY_DIST) != 0; |
| 5837 | |
| 5838 | if (AIObjEnemy(obj, target)) { |
| 5839 | float dot; |
| 5840 | float dist; |
| 5841 | vector to_obj; |
| 5842 | fvi_query fq; |
| 5843 | fvi_info hit_info; |
| 5844 | int fate; |
| 5845 | |
| 5846 | if (obj == target) |
| 5847 | return; |
| 5848 | |
| 5849 | if (!BOA_IsVisible(obj->roomnum, target->roomnum)) |
| 5850 | return; |
| 5851 | |
| 5852 | if (!AIDetermineObjVisLevel(obj, target)) |
| 5853 | return; |
| 5854 | |
| 5855 | if (target->type == OBJ_PLAYER && (Players[target->id].flags & (PLAYER_FLAGS_DEAD | PLAYER_FLAGS_DYING))) |
| 5856 | return; |
| 5857 | |
| 5858 | to_obj = target->pos - obj->pos; |
| 5859 | |
| 5860 | dist = vm_NormalizeVector(&to_obj); |
| 5861 | |
| 5862 | if (dist > MAX_SEE_TARGET_DIST) |
| 5863 | return; |
| 5864 | |
| 5865 | vector look_dir; |
| 5866 | AIDetermineFovVec(obj, &look_dir); |
| 5867 | |
| 5868 | dot = to_obj * look_dir; |
| 5869 | |
| 5870 | if (f_use_dot && dot <= *best_dot) { |
| 5871 | return; |
| 5872 | } else if (!f_use_dot && dist >= *best_dist) { |
| 5873 | return; |
| 5874 | } |
| 5875 | |
| 5876 | fq.p0 = &obj->pos; |
| 5877 | fq.p1 = &target->pos; |
| 5878 | fq.startroom = obj->roomnum; |
| 5879 | |
| 5880 | fq.rad = 0.0f; |
| 5881 | fq.flags = FQ_CHECK_OBJS | FQ_ONLY_DOOR_OBJ | FQ_NO_RELINK; |
| 5882 | fq.thisobjnum = -1; |
| 5883 | |
| 5884 | int ignore_obj_list[100]; |
| 5885 | ignore_obj_list[0] = OBJNUM(obj); |
| 5886 | int num_ignored = 1; |
| 5887 | int i; |
| 5888 | |
| 5889 | // CHRISHACK - ONLY IGNORES FIRST LEVEL OF CHILDREN - DO RECERSIVE |
| 5890 | for (i = 0; i < Poly_models[obj->rtype.pobj_info.model_num].n_attach; i++) { |
| 5891 | object *child; |
| 5892 | |
| 5893 | if ((child = ObjGet(obj->attach_children[i])) != NULL && num_ignored < 99) { |
| 5894 | ignore_obj_list[num_ignored++] = OBJNUM(child); |
| 5895 | } |
| 5896 | } |
| 5897 | |
| 5898 | ignore_obj_list[num_ignored] = -1; |
| 5899 | fq.ignore_obj_list = ignore_obj_list; |
| 5900 | |
| 5901 | fate = fvi_FindIntersection(&fq, &hit_info); |
| 5902 | |
| 5903 | if (fate != HIT_NONE) |
| 5904 | return; |
| 5905 | |
| 5906 | *best_dot = dot; |
| 5907 | *best_dist = dist; |
| 5908 | *best_obj = target; |
| 5909 | } |
| 5910 | } |
| 5911 | |
| 5912 | void AIDetermineTarget(object *obj) { |
| 5913 | ai_frame *ai_info = obj->ai_info; |
| 5914 | object *best_obj = NULL; |
| 5915 | float best_dot = -1.0f; |
| 5916 | float best_dist = MAX_SEE_TARGET_DIST + 1; |
| 5917 | int i; |
| 5918 | |
| 5919 | if (Gametime < ai_info->next_target_update_time) |
| 5920 | return; |
| 5921 | |
| 5922 | if (ai_info->awareness >= AWARE_BARELY) |
| 5923 | ai_info->next_target_update_time = |
| 5924 | Gametime + MIN_TARGET_UPDATE_INTERVAL + |
| 5925 | ((float)ps_rand() / (float)D3_RAND_MAX) * (MAX_TARGET_UPDATE_INTERVAL - MIN_TARGET_UPDATE_INTERVAL); |
| 5926 | else |
| 5927 | ai_info->next_target_update_time = |
| 5928 | Gametime + 2.0f * MIN_TARGET_UPDATE_INTERVAL + |
| 5929 | ((float)ps_rand() / (float)D3_RAND_MAX) * 2.0f * (MAX_TARGET_UPDATE_INTERVAL - MIN_TARGET_UPDATE_INTERVAL); |
| 5930 | |
| 5931 | // Chrishack -- if agression is over a value, NO switching targets!!!!!!!!! Need to implement |
| 5932 | // Chrishack -- if frustration is over a value, act as hostile -- temp stuff AIF_TEAM_HOSTILE |
| 5933 | |
| 5934 | // They forget their enemies after a few seconds |
| 5935 | if ((ai_info->flags & AIF_TEAM_MASK) == AIF_TEAM_NEUTRAL || (ai_info->flags & AIF_ACT_AS_NEUTRAL_UNTIL_SHOT)) { |
| 5936 | best_obj = NULL; |
| 5937 | } else if ((ai_info->flags & AIF_TEAM_MASK) != AIF_TEAM_PTMC) { |
| 5938 | int16_t list[50]; |
| 5939 | int num = fvi_QuickDistObjectList(&obj->pos, obj->roomnum, MAX_SEE_TARGET_DIST, list, 50, false, true, false, true); |
| 5940 | |
| 5941 | for (i = 0; i < num; i++) { |
| 5942 | AITargetCheck(obj, &Objects[list[i]], &best_obj, &best_dot, &best_dist); |
| 5943 | } |
| 5944 | } else // Team PTMC :) |
| 5945 | { |
| 5946 | if (Game_mode & GM_MULTI) { |
| 5947 | // Multiplayer targetting (Major difference is that robot will ignore players while infighting in single player) |
| 5948 | for (i = 0; i < MAX_PLAYERS; i++) { |
| 5949 | if ((NetPlayers[i].flags & NPF_CONNECTED) && (NetPlayers[i].sequence >= NETSEQ_PLAYING)) { |
| 5950 | object *target = &Objects[Players[i].objnum]; |
| 5951 | |
| 5952 | AITargetCheck(obj, target, &best_obj, &best_dot, &best_dist); |
| 5953 | } |
| 5954 | } |
| 5955 | } else { |
| 5956 | object *t = ObjGet(ai_info->target_handle); |
| 5957 | bool f_forgive_friend = false; |
| 5958 | |
| 5959 | if ((t) && (t->control_type == CT_AI) && ((t->ai_info->flags & AIF_TEAM_MASK) == AIF_TEAM_PTMC)) { |
| 5960 | // Do the divide because we don't want D3_RAND_MAX to go too high |
| 5961 | if (ps_rand() / AI_FORGIVE_AGRESSION_MULTIPLIER > ai_info->agression * D3_RAND_MAX) { |
| 5962 | f_forgive_friend = true; |
| 5963 | } |
| 5964 | } |
| 5965 | |
| 5966 | // chrishack -- FUCK a multi-guidebot bug!!!!!! |
| 5967 | if (f_forgive_friend || !ai_target_valid(obj) || |
| 5968 | (ai_info->target_handle != OBJECT_HANDLE_NONE && ai_info->target_handle == Buddy_handle[0] && |
| 5969 | ObjGet(Buddy_handle[0])->type != OBJ_GHOST)) { |
| 5970 | if (Player_object->type != OBJ_GHOST) |
| 5971 | best_obj = Player_object; |
| 5972 | else if (Buddy_handle[0] != OBJECT_HANDLE_NONE && ObjGet(Buddy_handle[0])->type != OBJ_GHOST) |
| 5973 | best_obj = ObjGet(Buddy_handle[0]); |
| 5974 | else |
| 5975 | best_obj = NULL; |
| 5976 | } else { |
| 5977 | best_obj = ObjGet(obj->ai_info->target_handle); |
| 5978 | } |
| 5979 | } |
| 5980 | } |
| 5981 | |
| 5982 | if (best_obj) { |
| 5983 | AISetTarget(obj, best_obj->handle); |
| 5984 | } else { |
| 5985 | AISetTarget(obj, OBJECT_HANDLE_NONE); |
| 5986 | } |
| 5987 | } |
| 5988 | |
| 5989 | // chrishack -- make sure that some checks are done with a ps_rand() based on the emotion involved |
| 5990 | // also current emotional levels should influence the percent chance of the check being successful |
| 5991 | void AIDoFreud(object *obj) { |
| 5992 | ai_frame *ai_info = obj->ai_info; |
| 5993 | ai_mem *mem = ai_info->memory; |
| 5994 | |
| 5995 | int fear_depth = (ai_info->life_preservation) * (AI_MEM_DEPTH - 1) + 1; |
| 5996 | int anger_depth = (ai_info->agression) * (AI_MEM_DEPTH - 1) + 1; |
| 5997 | int frust_depth = (ai_info->frustration) * (AI_MEM_DEPTH - 1) + 1; |
| 5998 | |
| 5999 | if (fear_depth >= AI_MEM_DEPTH) |
| 6000 | fear_depth = AI_MEM_DEPTH - 1; |
| 6001 | if (anger_depth >= AI_MEM_DEPTH) |
| 6002 | anger_depth = AI_MEM_DEPTH - 1; |
| 6003 | if (frust_depth >= AI_MEM_DEPTH) |
| 6004 | frust_depth = AI_MEM_DEPTH - 1; |
| 6005 | |
| 6006 | if (ai_info->goals[3].used == 0 && ai_info->awareness > AWARE_BARELY) { |
| 6007 | if (IS_GENERIC(obj->type) && mem[0].shields / Object_info[obj->id].hit_points < ai_info->life_preservation && |
| 6008 | mem[0].num_enemy_shots_dodged > 0 && mem[0].num_friends < 2 && |
| 6009 | (float)ps_rand() / (float)D3_RAND_MAX < ai_info->life_preservation) { |
| 6010 | float time = 10.0f * ai_info->life_preservation + 5.0f; |
| 6011 | |
| 6012 | GoalAddGoal(obj, AIG_WANDER_AROUND, NULL, 3, 2.0f, GF_SPEED_FLEE | GF_ORIENT_VELOCITY | GF_NONFLUSHABLE); |
| 6013 | GoalAddEnabler(obj, 3, AIE_CLEAR_TIME, (void *)&time, 1.0, 0.0); |
| 6014 | |
| 6015 | mprintf(0, "Fear!!!!\n"); |
| 6016 | return; |
| 6017 | } |
| 6018 | |
| 6019 | // Accounts for massive loss of shields |
| 6020 | if (IS_GENERIC(obj->type) && |
| 6021 | (mem[fear_depth].shields - mem[0].shields) / mem[fear_depth].shields > |
| 6022 | 0.25f * (1.0f - ai_info->life_preservation) && |
| 6023 | (float)ps_rand() / (float)D3_RAND_MAX < ai_info->life_preservation) { |
| 6024 | float time = 10.0f * ai_info->life_preservation + 5.0f; |
| 6025 | |
| 6026 | GoalAddGoal(obj, AIG_WANDER_AROUND, NULL, 3, 2.0f, GF_SPEED_FLEE | GF_ORIENT_VELOCITY | GF_NONFLUSHABLE); |
| 6027 | GoalAddEnabler(obj, 3, AIE_CLEAR_TIME, (void *)&time, 1.0, 0.0); |
| 6028 | |
| 6029 | mprintf(0, "Fear!!!!\n"); |
| 6030 | return; |
| 6031 | } |
| 6032 | |
| 6033 | // If others have died and/or left... (Me too) |
| 6034 | if (ai_info->life_preservation > 0.5f && mem[fear_depth].num_friends > 0 && mem[0].num_friends == 0 && |
| 6035 | mem[0].num_enemies > 0) { |
| 6036 | float time = 10.0f * ai_info->life_preservation + 5.0f; |
| 6037 | |
| 6038 | GoalAddGoal(obj, AIG_WANDER_AROUND, NULL, 3, 2.0f, GF_SPEED_FLEE | GF_ORIENT_VELOCITY | GF_NONFLUSHABLE); |
| 6039 | GoalAddEnabler(obj, 3, AIE_CLEAR_TIME, (void *)&time, 1.0, 0.0); |
| 6040 | |
| 6041 | mprintf(0, "Fear!!!!\n"); |
| 6042 | return; |
| 6043 | } |
| 6044 | } |
| 6045 | } |
| 6046 | |
| 6047 | void AIDoMemFrame(object *obj) { |
| 6048 | ai_frame *ai_info = obj->ai_info; |
| 6049 | ai_info->mem_time_till_next_update -= Frametime; |
| 6050 | |
| 6051 | if (ai_info->mem_time_till_next_update <= 0.0f) { |
| 6052 | int i; |
| 6053 | |
| 6054 | // Compute next analyze time |
| 6055 | ai_info->mem_time_till_next_update = 3.0f + (float)ps_rand() / (float)D3_RAND_MAX * 2.0f; |
| 6056 | |
| 6057 | // Do the amount of friends/enemies left and the current shields before running Freud |
| 6058 | int16_t near_objs[100]; |
| 6059 | float dist = 100.0f; |
| 6060 | |
| 6061 | // chrishack -- there must be a better way... |
| 6062 | if (ai_info->coop_team * 300.0f > dist) { |
| 6063 | dist = ai_info->coop_team * 300.0f > dist; |
| 6064 | } |
| 6065 | |
| 6066 | int num_near = fvi_QuickDistObjectList(&obj->pos, obj->roomnum, dist, near_objs, 100, false, true, false, true); |
| 6067 | |
| 6068 | ai_info->memory[0].num_enemies = 0; |
| 6069 | ai_info->memory[0].num_friends = 0; |
| 6070 | |
| 6071 | for (i = 0; i < num_near; i++) { |
| 6072 | object *check_obj = &Objects[near_objs[i]]; |
| 6073 | |
| 6074 | if (check_obj == obj) |
| 6075 | continue; |
| 6076 | |
| 6077 | if (AIObjEnemy(obj, check_obj)) |
| 6078 | ai_info->memory[0].num_enemies++; |
| 6079 | else if (AIObjFriend(obj, check_obj)) |
| 6080 | ai_info->memory[0].num_friends++; |
| 6081 | } |
| 6082 | |
| 6083 | ai_info->memory[0].shields = obj->shields; |
| 6084 | |
| 6085 | // Do emotions based on new data |
| 6086 | AIDoFreud(obj); |
| 6087 | |
| 6088 | // Move emotions through the stack |
| 6089 | for (i = AI_MEM_DEPTH - 1; i > 0; i--) { |
| 6090 | ai_info->memory[i] = ai_info->memory[i - 1]; |
| 6091 | } |
| 6092 | |
| 6093 | // Reset the accumulators |
| 6094 | |
| 6095 | // These are imcremented as this memory time slice is active |
| 6096 | ai_info->memory[0].num_enemy_shots_dodged = 0; |
| 6097 | ai_info->memory[0].num_enemy_shots_fired = 0; |
| 6098 | ai_info->memory[0].num_hit_enemy = 0; |
| 6099 | ai_info->memory[0].num_times_hit = 0; |
| 6100 | |
| 6101 | // Dummy values, as these are computed at the end of the time frame (as seen above) |
| 6102 | ai_info->memory[0].shields = obj->shields; |
| 6103 | ai_info->memory[0].num_enemies = ai_info->memory[1].num_enemies; |
| 6104 | ai_info->memory[0].num_friends = ai_info->memory[1].num_friends; |
| 6105 | } |
| 6106 | } |
| 6107 | |
| 6108 | void AIDoFrame(object *obj) { |
| 6109 | |
| 6110 | bool f_attach_done = false; |
| 6111 | int multi_saved_weapon_flags; |
| 6112 | char multi_saved_wb_firing; |
| 6113 | |
| 6114 | // AI objects don't use thrust (in general) |
| 6115 | obj->mtype.phys_info.flags &= ~PF_USES_THRUST; |
| 6116 | obj->mtype.phys_info.rotthrust = Zero_vector; |
| 6117 | obj->mtype.phys_info.thrust = Zero_vector; |
| 6118 | |
| 6119 | if (obj->type == OBJ_DUMMY) |
| 6120 | return; |
| 6121 | |
| 6122 | if ((Game_mode & GM_MULTI) && (Netgame.local_role == LR_SERVER)) { |
| 6123 | multi_saved_wb_firing = obj->ai_info->last_special_wb_firing; |
| 6124 | multi_saved_weapon_flags = obj->weapon_fire_flags; |
| 6125 | } |
| 6126 | |
| 6127 | ai_frame *ai_info = obj->ai_info; |
| 6128 | ASSERT((obj->control_type == CT_AI) || (obj->control_type == CT_DYING_AND_AI)); |
| 6129 | |
| 6130 | if ((ai_info->flags & AIF_DISABLED) || (obj->type == OBJ_DUMMY)) { |
| 6131 | return; |
| 6132 | } |
| 6133 | |
| 6134 | // Animate the object |
| 6135 | ai_do_animation(obj, Frametime); |
| 6136 | if (ai_info->animation_type == AS_IDLE) { |
| 6137 | f_attach_done = true; |
| 6138 | } |
| 6139 | |
| 6140 | if (Demo_flags == DF_PLAYBACK) { |
| 6141 | // All we want is animation |
| 6142 | return; |
| 6143 | } |
| 6144 | // Handle On/off and spray weapons |
| 6145 | { |
| 6146 | if ((obj->weapon_fire_flags & WFF_SPRAY) && !(obj->flags & (OF_DESTROYED | OF_DYING))) { |
| 6147 | char wb_index = ai_info->last_special_wb_firing; |
| 6148 | DoSprayEffect(obj, &Object_info[obj->id].static_wb[wb_index], wb_index); |
| 6149 | if (!((Game_mode & GM_MULTI) && (Netgame.local_role == LR_CLIENT))) { |
| 6150 | if (WBIsBatteryReady(obj, &Object_info[obj->id].static_wb[wb_index], wb_index) && |
| 6151 | !(Cinematic_inuse && !(ai_info->status_reg & AISR_OK_TO_FIRE_DURING_CINEMATICS))) { |
| 6152 | WBFireBattery(obj, &Object_info[obj->id].static_wb[wb_index], wb_index); |
| 6153 | } |
| 6154 | } |
| 6155 | } |
| 6156 | |
| 6157 | if (obj->weapon_fire_flags & WFF_ON_OFF) { |
| 6158 | FireOnOffWeapon(obj); |
| 6159 | } |
| 6160 | } |
| 6161 | |
| 6162 | if ((Game_mode & GM_MULTI) && (Netgame.local_role == LR_CLIENT)) { |
| 6163 | if (!f_attach_done) { |
| 6164 | AttachUpdateSubObjects(obj); |
| 6165 | f_attach_done = true; |
| 6166 | } |
| 6167 | return; |
| 6168 | } |
| 6169 | |
| 6170 | // If awareness if forced, do so |
| 6171 | if ((ai_info->flags & AIF_FORCE_AWARENESS) && (ai_info->awareness < AWARE_MOSTLY)) { |
| 6172 | ai_info->awareness = AWARE_MOSTLY; |
| 6173 | } |
| 6174 | |
| 6175 | // If not multiplayer - these must be set each frame |
| 6176 | obj->weapon_fire_flags = 0; |
| 6177 | |
| 6178 | // If the object is dead, it does not think |
| 6179 | if (obj->flags & OF_DEAD) { |
| 6180 | if (!f_attach_done) { |
| 6181 | AttachUpdateSubObjects(obj); |
| 6182 | f_attach_done = true; |
| 6183 | } |
| 6184 | return; |
| 6185 | } |
| 6186 | |
| 6187 | AIDoMemFrame(obj); |
| 6188 | |
| 6189 | if (ai_info->flags & AIF_DETERMINE_TARGET) |
| 6190 | AIDetermineTarget(obj); |
| 6191 | |
| 6192 | // Update the robot's eyes -- gets player distance -- (only if AI cares about player) |
| 6193 | if (ai_info->notify_flags & (0x00000001 << AIN_SEE_TARGET)) |
| 6194 | AICheckTargetVis(obj); |
| 6195 | |
| 6196 | // Updates some of the AI status registers |
| 6197 | ai_update_registers(obj); |
| 6198 | |
| 6199 | // Have goals result in movement |
| 6200 | // I will think if either the player or me sees anything within 4 seconds |
| 6201 | if ((ai_info->awareness) || (ai_info->flags & AIF_PERSISTANT)) { |
| 6202 | // Does the scripting stuff for an AI |
| 6203 | ai_do_script_stuff(obj); |
| 6204 | |
| 6205 | if (ai_info->ai_type == AIT_BIRD_FLOCK1) |
| 6206 | ai_info->flags |= AIF_TRACK_CLOSEST_2_FRIENDS; // chrishack -- remove -- testing only |
| 6207 | |
| 6208 | // Determines all tracked objects |
| 6209 | AIDoTrackFrame(obj); |
| 6210 | |
| 6211 | // Does goal updating for the frame |
| 6212 | GoalDoFrame(obj); |
| 6213 | |
| 6214 | // Allow the robot to move |
| 6215 | if (obj->control_type == CT_AI) { |
| 6216 | if (ai_info->animation_type != AS_FLINCH) { |
| 6217 | float speed; |
| 6218 | |
| 6219 | #ifdef _DEBUG |
| 6220 | if (!Game_do_ai_movement) { |
| 6221 | goto after_move; |
| 6222 | } |
| 6223 | #endif |
| 6224 | |
| 6225 | ai_move(obj); |
| 6226 | |
| 6227 | speed = vm_GetMagnitude(&obj->mtype.phys_info.velocity); |
| 6228 | |
| 6229 | // Removes the framerate independance from objects moving within 2x of there normal max speed |
| 6230 | if (speed > 0.1f && speed <= ai_info->max_velocity * 2.0) { |
| 6231 | if (obj->mtype.phys_info.drag > 0.0f && obj->mtype.phys_info.mass > 0.0f) { |
| 6232 | obj->mtype.phys_info.flags |= PF_USES_THRUST; |
| 6233 | obj->mtype.phys_info.rotthrust = Zero_vector; |
| 6234 | obj->mtype.phys_info.thrust = obj->mtype.phys_info.velocity * obj->mtype.phys_info.drag; |
| 6235 | } |
| 6236 | } |
| 6237 | |
| 6238 | #ifdef _DEBUG |
| 6239 | after_move:; |
| 6240 | #endif |
| 6241 | } |
| 6242 | |
| 6243 | if (!f_attach_done) { |
| 6244 | AttachUpdateSubObjects(obj); |
| 6245 | f_attach_done = true; |
| 6246 | } |
| 6247 | |
| 6248 | if (!((ai_info->status_reg & AISR_MELEE) || (ai_info->flags & AIF_DISABLE_FIRING))) |
| 6249 | ai_fire(obj); |
| 6250 | } else { |
| 6251 | if (obj->movement_type == MT_WALKING && ai_info->animation_type == AS_DEATH) { |
| 6252 | vector mdir; |
| 6253 | bool f_moved; |
| 6254 | |
| 6255 | AIMoveTowardsPosition(obj, &obj->pos, 1.5f, false, &mdir, &f_moved); |
| 6256 | if (!f_moved) { |
| 6257 | AIMoveTowardsDir(obj, &mdir, 1.0f); |
| 6258 | } |
| 6259 | } |
| 6260 | } |
| 6261 | } |
| 6262 | |
| 6263 | if (!f_attach_done) { |
| 6264 | AttachUpdateSubObjects(obj); |
| 6265 | f_attach_done = true; |
| 6266 | } |
| 6267 | |
| 6268 | if (obj->movement_type == MT_WALKING) |
| 6269 | ai_walker_stuff(obj); |
| 6270 | |
| 6271 | // Animation state changes based on current level of awareness |
| 6272 | if (obj->control_type == CT_AI) |
| 6273 | do_awareness_based_anim_stuff(obj); |
| 6274 | |
| 6275 | // Decrease awareness |
| 6276 | if (obj->control_type == CT_AI) |
| 6277 | ai_decrease_awareness(obj); |
| 6278 | |
| 6279 | if (obj->ai_info->awareness > AWARE_BARELY && obj->ai_info->target_handle == Player_object->handle && |
| 6280 | (obj->ai_info->last_see_target_time + (CHECK_VIS_INFREQUENTLY_INTERVAL * 2.0f)) >= Gametime && |
| 6281 | (obj->ai_info->last_hear_target_time + (CHECK_VIS_INFREQUENTLY_INTERVAL * 2.0f)) >= Gametime && |
| 6282 | obj->parent_handle != Player_object->handle) { |
| 6283 | AI_NumHostileAlert++; |
| 6284 | } |
| 6285 | |
| 6286 | if ((Game_mode & GM_MULTI) && (Netgame.local_role == LR_SERVER)) { |
| 6287 | if ((multi_saved_wb_firing != obj->ai_info->last_special_wb_firing) || |
| 6288 | (multi_saved_weapon_flags != obj->weapon_fire_flags)) { |
| 6289 | MultiSendAiWeaponFlags(obj, obj->weapon_fire_flags, obj->ai_info->last_special_wb_firing); |
| 6290 | } |
| 6291 | } |
| 6292 | |
| 6293 | } |
| 6294 | |
| 6295 | void AIFrameAll(void) { |
| 6296 | int i; |
| 6297 | |
| 6298 | if ((Game_mode & GM_MULTI) && (Netgame.local_role == LR_CLIENT)) |
| 6299 | return; |
| 6300 | |
| 6301 | // Currently, -- chrishack -- In multiplayer, all robots are aware. |
| 6302 | if (Game_mode & GM_MULTI) { |
| 6303 | for (i = 0; i <= Highest_object_index; i++) { |
| 6304 | if (Objects[i].ai_info) { |
| 6305 | AINotify(&Objects[i], AIN_PLAYER_SEES_YOU, NULL); |
| 6306 | } |
| 6307 | } |
| 6308 | } else { |
| 6309 | for (i = 0; i < AI_NumRendered; i++) { |
| 6310 | AINotify(&Objects[AI_RenderedList[i]], AIN_PLAYER_SEES_YOU, NULL); |
| 6311 | } |
| 6312 | } |
| 6313 | } |
| 6314 | |
| 6315 | void AIPowerSwitch(object *obj, bool f_on) { |
| 6316 | ai_frame *ai_info = obj->ai_info; |
| 6317 | if (obj->control_type != CT_AI) |
| 6318 | return; |
| 6319 | |
| 6320 | if (f_on) |
| 6321 | ai_info->flags &= (~AIF_DISABLED); |
| 6322 | else |
| 6323 | ai_info->flags |= AIF_DISABLED; |
| 6324 | |
| 6325 | poly_model *parent_pm = &Poly_models[obj->rtype.pobj_info.model_num]; |
| 6326 | int i; |
| 6327 | |
| 6328 | if (!obj->attach_children) |
| 6329 | return; |
| 6330 | |
| 6331 | for (i = 0; i < parent_pm->n_attach; i++) { |
| 6332 | object *child; |
| 6333 | |
| 6334 | if ((child = ObjGet(obj->attach_children[i])) != NULL) { |
| 6335 | AIPowerSwitch(child, f_on); |
| 6336 | } |
| 6337 | } |
| 6338 | } |
| 6339 | |
| 6340 | int AIFindRoomWithFlag(object *obj, int flag) { |
| 6341 | int cur_room = obj->roomnum; |
| 6342 | float best_dist = 0.0f; |
| 6343 | int best_room = -1; |
| 6344 | int i; |
| 6345 | |
| 6346 | for (i = 0; i <= Highest_room_index; i++) { |
| 6347 | if ((Rooms[i].used) && (Rooms[i].flags & flag)) { |
| 6348 | float cur_dist; |
| 6349 | |
| 6350 | if (BOA_ComputeMinDist(obj->roomnum, i, 0.0f, &cur_dist, NULL)) { |
| 6351 | if (best_room == -1 || cur_dist < best_dist) { |
| 6352 | bool f_path_exists = AIFindAltPath(obj, cur_room, i, &cur_dist); |
| 6353 | |
| 6354 | if (f_path_exists && (best_room == -1 || cur_dist < best_dist)) { |
| 6355 | best_dist = cur_dist; |
| 6356 | best_room = i; |
| 6357 | } |
| 6358 | } |
| 6359 | } |
| 6360 | } |
| 6361 | } |
| 6362 | |
| 6363 | return best_room; |
| 6364 | } |
| 6365 | |
| 6366 | bool AIFindHidePos(object *hide_obj, object *view_obj, vector *hpos, int *hroom, float max_hide_time) { return false; } |
| 6367 | |
| 6368 | object *AIFindObjOfType(object *obj, int type, int id, bool f_ignore_init_room, int parent_handle) { |
| 6369 | int cur_room = obj->roomnum; |
| 6370 | float best_dist = 0.0f; |
| 6371 | object *best_obj = NULL; |
| 6372 | int i; |
| 6373 | int my_obj_index = OBJNUM(obj); |
| 6374 | |
| 6375 | for (i = 0; i <= Highest_object_index; i++) { |
| 6376 | if ((Objects[i].type == type || (type == OBJ_ROBOT && Objects[i].type == OBJ_BUILDING)) && i != my_obj_index) { |
| 6377 | float cur_dist; |
| 6378 | |
| 6379 | if (f_ignore_init_room && (Objects[i].roomnum == obj->roomnum)) |
| 6380 | continue; |
| 6381 | |
| 6382 | if (id != -1 && id != Objects[i].id) |
| 6383 | continue; |
| 6384 | |
| 6385 | // Allow us to find a players powerups |
| 6386 | if (parent_handle != OBJECT_HANDLE_NONE && parent_handle != Objects[i].parent_handle) |
| 6387 | continue; |
| 6388 | |
| 6389 | // Invisible powerups |
| 6390 | if (Objects[i].render_type == RT_NONE) |
| 6391 | continue; |
| 6392 | |
| 6393 | // Dying robots, other non-active robots |
| 6394 | if (Objects[i].type == OBJ_ROBOT && Objects[i].control_type != CT_AI) |
| 6395 | continue; |
| 6396 | |
| 6397 | // Robots that don't shoot |
| 6398 | poly_model *pm = &Poly_models[Objects[i].rtype.pobj_info.model_num]; |
| 6399 | if (Objects[i].type == OBJ_ROBOT && pm->num_wbs == 0) |
| 6400 | continue; |
| 6401 | |
| 6402 | // cameras |
| 6403 | if (Objects[i].type == OBJ_ROBOT && pm->num_wbs == 1 && Object_info[Objects[i].id].static_wb[0].num_masks == 1 && |
| 6404 | Object_info[Objects[i].id].static_wb[0].gp_fire_masks[0] == 0) |
| 6405 | continue; |
| 6406 | |
| 6407 | if (BOA_ComputeMinDist(obj->roomnum, Objects[i].roomnum, 0.0f, &cur_dist, NULL)) { |
| 6408 | if (best_obj == NULL || cur_dist < best_dist) { |
| 6409 | bool f_path_exists = AIFindAltPath(obj, cur_room, Objects[i].roomnum, &cur_dist); |
| 6410 | |
| 6411 | if (f_path_exists && (best_obj == NULL || cur_dist < best_dist)) { |
| 6412 | best_dist = cur_dist; |
| 6413 | best_obj = &Objects[i]; |
| 6414 | } |
| 6415 | } |
| 6416 | } |
| 6417 | } |
| 6418 | } |
| 6419 | |
| 6420 | return best_obj; |
| 6421 | } |
| 6422 | |
| 6423 | int AIMakeNextRoomList(int roomnum, int *next_rooms, int max_rooms) { |
| 6424 | int num_next_rooms = 0; |
| 6425 | int i, j; |
| 6426 | int croom; |
| 6427 | |
| 6428 | if (!ROOMNUM_OUTSIDE(roomnum) && roomnum <= Highest_room_index) { |
| 6429 | for (i = 0; i < Rooms[roomnum].num_portals; i++) { |
| 6430 | bool f_found = false; |
| 6431 | |
| 6432 | if (Rooms[roomnum].portals[i].croom >= 0) { |
| 6433 | if (Rooms[Rooms[roomnum].portals[i].croom].flags & RF_EXTERNAL) { |
| 6434 | croom = Highest_room_index + |
| 6435 | TERRAIN_REGION(GetTerrainRoomFromPos( |
| 6436 | &Rooms[Rooms[roomnum].portals[i].croom].portals[Rooms[roomnum].portals[i].cportal].path_pnt)) + |
| 6437 | 1; |
| 6438 | } else { |
| 6439 | croom = Rooms[roomnum].portals[i].croom; |
| 6440 | } |
| 6441 | |
| 6442 | for (j = 0; j < num_next_rooms; j++) { |
| 6443 | if (next_rooms[j] == croom) { |
| 6444 | f_found = true; |
| 6445 | break; |
| 6446 | } |
| 6447 | } |
| 6448 | |
| 6449 | if (!f_found) { |
| 6450 | // If you hit assert, get chris -- make constant larger |
| 6451 | ASSERT(num_next_rooms < max_rooms); |
| 6452 | |
| 6453 | ASSERT((croom >= 0 && croom <= Highest_room_index + 8) || |
| 6454 | (ROOMNUM_OUTSIDE(croom) && CELLNUM(roomnum) > 0 && CELLNUM(roomnum) < TERRAIN_WIDTH * TERRAIN_DEPTH)); |
| 6455 | |
| 6456 | next_rooms[num_next_rooms] = croom; |
| 6457 | num_next_rooms++; |
| 6458 | } |
| 6459 | } |
| 6460 | } |
| 6461 | } else { |
| 6462 | int t_index; |
| 6463 | |
| 6464 | if (BOA_num_terrain_regions == 0) { |
| 6465 | return 0; |
| 6466 | } |
| 6467 | |
| 6468 | if (roomnum > Highest_room_index && roomnum <= Highest_room_index + 8) { |
| 6469 | t_index = roomnum - Highest_room_index - 1; |
| 6470 | } else { |
| 6471 | t_index = TERRAIN_REGION(roomnum); |
| 6472 | } |
| 6473 | |
| 6474 | ASSERT(t_index >= 0 && t_index < BOA_num_terrain_regions); |
| 6475 | |
| 6476 | for (i = 0; i < BOA_num_connect[t_index]; i++) { |
| 6477 | bool f_found = false; |
| 6478 | croom = BOA_connect[t_index][i].roomnum; |
| 6479 | |
| 6480 | for (j = 0; j < num_next_rooms; j++) { |
| 6481 | if (next_rooms[j] == croom) { |
| 6482 | f_found = true; |
| 6483 | break; |
| 6484 | } |
| 6485 | } |
| 6486 | |
| 6487 | if (!f_found) { |
| 6488 | // If you hit assert, get chris -- make constant larger |
| 6489 | ASSERT(num_next_rooms < max_rooms); |
| 6490 | next_rooms[num_next_rooms++] = croom; |
| 6491 | } |
| 6492 | } |
| 6493 | } |
| 6494 | |
| 6495 | return num_next_rooms; |
| 6496 | } |