1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042
|
/*
===========================================================================
Return to Castle Wolfenstein multiplayer GPL Source Code
Copyright (C) 1999-2010 id Software LLC, a ZeniMax Media company.
This file is part of the Return to Castle Wolfenstein multiplayer GPL Source Code (RTCW MP Source Code).
RTCW MP Source Code is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
RTCW MP Source Code is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with RTCW MP Source Code. If not, see <http://www.gnu.org/licenses/>.
In addition, the RTCW MP Source Code is also subject to certain additional terms. You should have received a copy of these additional terms immediately following the terms and conditions of the GNU General Public License which accompanied the RTCW MP Source Code. If not, please request a copy in writing from id Software at the address below.
If you have questions concerning this license or the applicable additional terms, you may contact in writing id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA.
===========================================================================
*/
//===========================================================================
//
// Name: ai_cast_funcs.c
// Function: Wolfenstein AI Character Decision Making
// Programmer: Ridah
// Tab Size: 4 (real tabs)
//===========================================================================
#include "g_local.h"
#include "../qcommon/q_shared.h"
#include "../botlib/botlib.h" //bot lib interface
#include "../botlib/be_aas.h"
#include "../botlib/be_ea.h"
#include "../botlib/be_ai_gen.h"
#include "../botlib/be_ai_goal.h"
#include "../botlib/be_ai_move.h"
#include "../botlib/botai.h" //bot ai interface
#include "ai_cast.h"
//=================================================================================
//
// ZOMBIE SPECIAL ATTACKS
//
//=================================================================================
/*
============
AIFunc_ZombieFlameAttack()
Zombie "Flaming Bats" attack.
NOTE: this actually uses the EFFECT3 slot for client-side effects (others are taken)
============
*/
#define ZOMBIE_FLAME_DURATION 4000
char *AIFunc_ZombieFlameAttack( cast_state_t *cs ) {
gentity_t *ent;
//
ent = &g_entities[cs->entityNum];
//
ent->s.onFireEnd = level.time + 2000;
//
if ( ent->health < 0 ) {
ent->s.onFireEnd = 0;
return AIFunc_DefaultStart( cs );
}
//
if ( cs->bs->enemy < 0 ) {
ent->s.onFireEnd = level.time + 1500;
ent->client->ps.torsoTimer = 0;
ent->client->ps.legsTimer = 0;
return AIFunc_DefaultStart( cs );
}
// if outside range, move closer
if ( VectorDistance( cs->bs->origin, cs->vislist[cs->bs->enemy].visible_pos ) > ZOMBIE_FLAME_RADIUS ) {
ent->s.onFireEnd = level.time + 1500;
ent->client->ps.torsoTimer = 0;
ent->client->ps.legsTimer = 0;
return AIFunc_DefaultStart( cs );
}
// we are firing this weapon, so record it
cs->weaponFireTimes[WP_MONSTER_ATTACK1] = level.time;
// once an attack has started, only abort once the player leaves our view, or time runs out
if ( cs->thinkFuncChangeTime < level.time - ZOMBIE_FLAME_DURATION ) {
// finish this attack
ent->client->ps.torsoTimer = 0;
ent->client->ps.legsTimer = 0;
return AIFunc_DefaultStart( cs );
} else {
ent->client->ps.torsoTimer = 400;
// draw the client-side effect
ent->client->ps.eFlags |= EF_MONSTER_EFFECT3;
// keep facing them
AICast_AimAtEnemy( cs );
// look slightly downwards since animation is facing upwards slightly
cs->bs->ideal_viewangles[PITCH] += 10;
}
return NULL;
}
char *AIFunc_ZombieFlameAttackStart( cast_state_t *cs ) {
gentity_t *ent;
//
ent = &g_entities[cs->entityNum];
ent->s.otherEntityNum2 = cs->bs->enemy;
ent->s.effect3Time = level.time;
//
// dont turn
cs->bs->ideal_viewangles[YAW] = cs->bs->viewangles[YAW];
cs->bs->ideal_viewangles[PITCH] = -45; // look upwards
// start the flame
ent->s.onFireStart = level.time;
ent->s.onFireEnd = level.time + ZOMBIE_FLAME_DURATION;
//
// set the correct animation
BG_PlayAnimName( &ent->client->ps, "both_attack1", ANIM_BP_BOTH, qtrue, qfalse, qtrue );
//
cs->aifunc = AIFunc_ZombieFlameAttack;
return "AIFunc_ZombieFlameAttack";
}
/*
============
AIFunc_ZombieAttack2()
Zombie "Evil Spirit" attack.
Character draws the light from surrounding walls (expanding negative light) and builds
up to the release of a flying translucent skull with trail effect (and beady eyes).
Spirit should track it's enemy slightly, inflicting lots of damage, removing sprint bar,
and effecting sight temporarily.
Speed of spirit is effected by skill level, higher skill = faster speed
Spirits inflicting AI soldiers should kill instantly, removing all flesh from the
soldier's face (draw skull under head model, then fade head model away over a short period).
============
*/
extern void weapon_zombiespirit( gentity_t *ent, gentity_t *missile );
#define ZOMBIE_SPIRIT_BUILDUP_TIME 10000 // last for this long
#define ZOMBIE_SPIRIT_FADEOUT_TIME 1000
#define ZOMBIE_SPIRIT_DLIGHT_RADIUS_MAX 256
#define ZOMBIE_SPIRIT_FIRE_INTERVAL 1000
int lastZombieSpiritAttack;
char *AIFunc_ZombieAttack2( cast_state_t *cs ) {
gentity_t *ent;
//
ent = &g_entities[cs->entityNum];
//
if ( cs->bs->enemy < 0 ) {
return AIFunc_DefaultStart( cs );
}
// if we can't see them anymore, abort immediately
if ( cs->vislist[cs->bs->enemy].real_visible_timestamp != cs->vislist[cs->bs->enemy].real_update_timestamp ) {
return AIFunc_DefaultStart( cs );
}
//
lastZombieSpiritAttack = level.time;
// we are firing this weapon, so record it
cs->weaponFireTimes[WP_MONSTER_ATTACK2] = level.time;
// once an attack has started, only abort once the player leaves our view, or time runs out
if ( cs->thinkFuncChangeTime < level.time - ZOMBIE_SPIRIT_BUILDUP_TIME ) {
// if enough time has elapsed, finish this attack
if ( level.time > cs->thinkFuncChangeTime + ZOMBIE_SPIRIT_BUILDUP_TIME + ZOMBIE_SPIRIT_FADEOUT_TIME ) {
return AIFunc_DefaultStart( cs );
}
} else {
// draw the client-side effect
ent->client->ps.eFlags |= EF_MONSTER_EFFECT;
// inform the client of our enemies position
VectorCopy( g_entities[cs->bs->enemy].client->ps.origin, ent->s.origin2 );
ent->s.origin2[2] += g_entities[cs->bs->enemy].client->ps.viewheight;
}
return NULL;
}
char *AIFunc_ZombieAttack2Start( cast_state_t *cs ) {
gentity_t *ent;
//
// don't allow 2 consecutive spirit attacks at once
if ( lastZombieSpiritAttack > level.time || lastZombieSpiritAttack > level.time - 300 ) {
return NULL;
}
//
ent = &g_entities[cs->entityNum];
ent->s.otherEntityNum2 = cs->bs->enemy;
ent->s.effect1Time = level.time;
//
// dont turn
cs->bs->ideal_viewangles[YAW] = cs->bs->viewangles[YAW];
// set torso to the correct animation
// TODO
//ent->client->ps.torsoAnim =
// ( ( ent->client->ps.torsoAnim & ANIM_TOGGLEBIT ) ^ ANIM_TOGGLEBIT ) | BOTH_SALUTE; // FIXME: need a specific anim for this
//
cs->aifunc = AIFunc_ZombieAttack2;
return "AIFunc_ZombieAttack2";
}
//=================================================================================
//
// LOPER MELEE ATTACK
//
//=================================================================================
#define LOPER_MELEE_FPS 15
#define LOPER_MELEE_DAMAGE_FRAME 3
#define LOPER_MELEE_DAMAGE_DELAY ( LOPER_MELEE_DAMAGE_FRAME*( 1000 / LOPER_MELEE_FPS ) )
#define LOPER_MELEE_FRAME_COUNT 11
#define LOPER_MELEE_DURATION ( LOPER_MELEE_FRAME_COUNT*( 1000 / LOPER_MELEE_FPS ) )
#define NUM_LOPER_MELEE_ANIMS 2
// TTimo unused
//static int loperMeleeAnims[NUM_LOPER_MELEE_ANIMS] = {LEGS_EXTRA1, LEGS_EXTRA2};
#define LOPER_MELEE_DAMAGE 20
#define LOPER_MELEE_RANGE 48
/*
===============
AIFunc_LoperAttack1()
Loper's close range melee attack
===============
*/
char *AIFunc_LoperAttack1( cast_state_t *cs ) {
trace_t *tr;
gentity_t *ent;
//
ent = &g_entities[cs->entityNum];
//
// draw the client-side lightning effect
//ent->client->ps.eFlags |= EF_MONSTER_EFFECT;
//
// have we inflicted the damage?
if ( cs->weaponFireTimes[WP_MONSTER_ATTACK1] > cs->thinkFuncChangeTime ) {
// has the animation finished?
if ( cs->thinkFuncChangeTime < level.time - LOPER_MELEE_DURATION ) {
return AIFunc_DefaultStart( cs );
}
return NULL; // just wait for anim to finish
}
// ready to inflict damage?
if ( cs->thinkFuncChangeTime < level.time - LOPER_MELEE_DAMAGE_DELAY ) {
// check for damage
if ( ( tr = CheckMeleeAttack( &g_entities[cs->entityNum], LOPER_MELEE_RANGE, qfalse ) ) ) {
G_Damage( &g_entities[tr->entityNum], ent, ent, vec3_origin, tr->endpos,
LOPER_MELEE_DAMAGE, 0, MOD_LOPER_HIT );
}
cs->weaponFireTimes[WP_MONSTER_ATTACK1] = level.time;
}
return NULL;
}
char *AIFunc_LoperAttack1Start( cast_state_t *cs ) {
gentity_t *ent;
//
ent = &g_entities[cs->entityNum];
// face them
AICast_AimAtEnemy( cs );
// start the animation
//ent->client->ps.legsAnim =
// ( ( ent->client->ps.legsAnim & ANIM_TOGGLEBIT ) ^ ANIM_TOGGLEBIT ) | loperMeleeAnims[rand()%NUM_LOPER_MELEE_ANIMS];
//ent->client->ps.legsTimer = LOPER_MELEE_DURATION;
BG_UpdateConditionValue( cs->entityNum, ANIM_COND_WEAPON, cs->bs->weaponnum, qtrue );
BG_AnimScriptEvent( &ent->client->ps, ANIM_ET_FIREWEAPON, qfalse, qtrue );
// play the sound
// TODO
//
cs->aifunc = AIFunc_LoperAttack1;
return "AIFunc_LoperAttack1";
}
//=================================================================================
//
// LOPER LEAP ATTACK
//
//=================================================================================
#define LOPER_LEAP_ANIM LEGS_EXTRA3
#define LOPER_LEAP_FPS 15
// update for a version of the loper new today (6/26)
//#define LOPER_LEAP_FRAME_COUNT 4
#define LOPER_LEAP_FRAME_COUNT 10
#define LOPER_LEAP_DURATION ( LOPER_LEAP_FRAME_COUNT*( 1000 / LOPER_LEAP_FPS ) )
#define LOPER_LAND_ANIM LEGS_EXTRA4
#define LOPER_LAND_FPS 15
// update for a version of the loper new today (6/26)
//#define LOPER_LAND_FRAME_COUNT 17
#define LOPER_LAND_FRAME_COUNT 21
#define LOPER_LAND_DURATION ( LOPER_LAND_FRAME_COUNT*( 1000 / LOPER_LAND_FPS ) )
#define LOPER_LEAP_DAMAGE 8
#define LOPER_LEAP_DELAY 100
#define LOPER_LEAP_RANGE 90
#define LOPER_LEAP_VELOCITY_START 400.0
#define LOPER_LEAP_VELOCITY_END 650.0
#define LOPER_LEAP_VELOCITY_Z 300
#define LOPER_LEAP_LAND_MOMENTUM 250
/*
===============
AIFunc_LoperAttack2()
Loper's leaping long range attack
===============
*/
char *AIFunc_LoperAttack2( cast_state_t *cs ) {
gentity_t *ent;
vec3_t vec;
qboolean onGround = qfalse;
//
ent = &g_entities[cs->entityNum];
//
// are we waiting to inflict damage?
if ( ( cs->weaponFireTimes[WP_MONSTER_ATTACK2] < level.time - 100 ) &&
( cs->bs->cur_ps.groundEntityNum == ENTITYNUM_NONE ) ) {
// ready to inflict damage?
if ( cs->thinkFuncChangeTime < level.time - LOPER_LEAP_DELAY ) {
// check for damage
if ( //(tr = CheckMeleeAttack(&g_entities[cs->entityNum], LOPER_LEAP_RANGE, qtrue)) &&
( G_RadiusDamage( cs->bs->origin, ent, LOPER_LEAP_DAMAGE, LOPER_LEAP_RANGE, ent, MOD_LOPER_LEAP ) ) ) {
// draw the client-side lightning effect
ent->client->ps.eFlags |= EF_MONSTER_EFFECT;
// do the damage
//G_Damage( &g_entities[tr->entityNum], ent, ent, vec3_origin, tr->endpos,
// LOPER_LEAP_DAMAGE, 0, MOD_LOPER_LEAP );
G_Sound( &g_entities[cs->entityNum], level.loperZapSound );
//cs->weaponFireTimes[WP_MONSTER_ATTACK2] = level.time;
}
}
}
//
// landed?
if ( cs->bs->cur_ps.groundEntityNum != ENTITYNUM_NONE ) {
onGround = qtrue;
} else { // predict a landing
aicast_predictmove_t move;
float changeTime;
AICast_PredictMovement( cs, 1, 0.2, &move, &cs->bs->lastucmd, cs->bs->enemy );
if ( move.groundEntityNum != ENTITYNUM_NONE ) {
onGround = qtrue;
}
//
// adjust velocity
VectorCopy( g_entities[cs->entityNum].s.pos.trDelta, vec );
vec[2] = 0;
VectorNormalize( vec );
changeTime = 2.0 * ( 0.001 * ( level.time - cs->thinkFuncChangeTime ) );
if ( changeTime > 1.0 ) {
changeTime = 1.0;
}
VectorScale( vec, LOPER_LEAP_VELOCITY_START + changeTime * ( LOPER_LEAP_VELOCITY_END - LOPER_LEAP_VELOCITY_START ), vec );
g_entities[cs->entityNum].s.pos.trDelta[0] = vec[0];
g_entities[cs->entityNum].s.pos.trDelta[1] = vec[1];
}
//
if ( onGround || ( cs->aiFlags & AIFL_LAND_ANIM_PLAYED ) ) {
// if we just started the attack recently, we probably haven't had a chance to get airborne yet
if ( cs->thinkFuncChangeTime < level.time - LOPER_LEAP_DELAY ) {
// loper is back on ground, wait for animation to play out
if ( !( cs->aiFlags & AIFL_LAND_ANIM_PLAYED ) ) {
ent->client->ps.legsAnim =
( ( ent->client->ps.legsAnim & ANIM_TOGGLEBIT ) ^ ANIM_TOGGLEBIT ) | LOPER_LAND_ANIM;
ent->client->ps.legsTimer = LOPER_LAND_DURATION;
//
cs->aiFlags |= AIFL_LAND_ANIM_PLAYED;
// TODO:play the landing thud
}
//
if ( !ent->client->ps.legsTimer ) { // we're done
return AIFunc_DefaultStart( cs );
}
// keep moving slightly in our facing direction to simulate landing momentum
AngleVectors( cs->bs->viewangles, vec, NULL, NULL );
trap_EA_Move( cs->entityNum, vec, ( (float)ent->client->ps.legsTimer / (float)LOPER_LAND_DURATION ) * (float)LOPER_LEAP_LAND_MOMENTUM );
return NULL;
}
}
return NULL;
}
char *AIFunc_LoperAttack2Start( cast_state_t *cs ) {
gentity_t *ent;
vec3_t vec, avec;
//
ent = &g_entities[cs->entityNum];
//
// face them
AICast_AimAtEnemy( cs );
// if not facing them yet, wait
VectorSubtract( cs->vislist[cs->bs->enemy].real_visible_pos, cs->bs->origin, vec );
VectorNormalize( vec );
AngleVectors( cs->bs->viewangles, avec, NULL, NULL );
if ( DotProduct( vec, avec ) < 0.95 ) {
//cs->aifunc = AIFunc_LoperAttack2Start;
return NULL;
}
// OK, start the animation
ent->client->ps.legsAnim =
( ( ent->client->ps.legsAnim & ANIM_TOGGLEBIT ) ^ ANIM_TOGGLEBIT ) | LOPER_LEAP_ANIM;
ent->client->ps.legsTimer = 20000; // stay on this until landing
// send us hurtling towards our enemy
VectorScale( vec, LOPER_LEAP_VELOCITY_START, vec );
vec[2] = LOPER_LEAP_VELOCITY_Z;
VectorCopy( vec, ent->client->ps.velocity );
//
cs->aiFlags &= ~AIFL_LAND_ANIM_PLAYED;
// play the sound
// TODO
//
cs->aifunc = AIFunc_LoperAttack2;
return "AIFunc_LoperAttack2";
}
//=================================================================================
//
// LOPER GROUND ATTACK
//
//=================================================================================
#define LOPER_GROUND_ANIM LEGS_EXTRA5
#define LOPER_GROUND_FPS 10
#define LOPER_GROUND_FRAME_COUNT 8
#define LOPER_GROUND_DURATION ( LOPER_GROUND_FRAME_COUNT*( 1000 / LOPER_GROUND_FPS ) )
#define LOPER_GROUND_DAMAGE 20
#define LOPER_GROUND_DELAY 5000
/*
===============
AIFunc_LoperAttack3()
Loper's ground electrical attack
===============
*/
char *AIFunc_LoperAttack3( cast_state_t *cs ) {
gentity_t *ent;
qboolean hitClient = qfalse;
//
ent = &g_entities[cs->entityNum];
//
// done with this attack?
if ( cs->thinkFuncChangeTime < level.time - LOPER_GROUND_DELAY ) {
cs->pauseTime = level.time + 600; // don't move until effect is done
ent->client->ps.legsTimer = 600; // stay down until effect is done
return AIFunc_DefaultStart( cs );
}
// ready to inflict damage?
if ( cs->thinkFuncChangeTime < level.time - 900 ) {
//
// draw the client-side lightning effect
ent->client->ps.eFlags |= EF_MONSTER_EFFECT3;
//ent->s.effect3Time = level.time + 500;//cs->thinkFuncChangeTime + LOPER_GROUND_DELAY - 200;
//
// are we waiting to inflict damage?
if ( cs->weaponFireTimes[WP_MONSTER_ATTACK3] < level.time - 100 ) {
// check for damage
hitClient = G_RadiusDamage( cs->bs->origin, ent, LOPER_GROUND_DAMAGE, LOPER_GROUND_RANGE, ent, MOD_LOPER_GROUND );
//
cs->weaponFireTimes[WP_MONSTER_ATTACK3] = level.time;
// TODO: client-side visual effect
// TODO: throw them backwards (away from us)
} else {
hitClient = qtrue; // so we don't abort
}
//
if ( !hitClient && cs->thinkFuncChangeTime < ( level.time - 1500 ) ) { // we're done with this attack
cs->pauseTime = level.time + 600; // don't move until effect is done
ent->client->ps.legsTimer = 600; // stay down until effect is done
return AIFunc_DefaultStart( cs );
}
}
//
if ( ent->client->ps.legsTimer < 1000 ) {
ent->client->ps.legsTimer = 1000; // stay down until effect is done
}
return NULL;
}
char *AIFunc_LoperAttack3Start( cast_state_t *cs ) {
gentity_t *ent;
//
ent = &g_entities[cs->entityNum];
//
// face them
AICast_AimAtEnemy( cs );
// play the animation
ent->client->ps.legsAnim =
( ( ent->client->ps.legsAnim & ANIM_TOGGLEBIT ) ^ ANIM_TOGGLEBIT ) | LOPER_GROUND_ANIM;
ent->client->ps.legsTimer = LOPER_GROUND_DELAY; // stay down until attack is finished
//
// play the buildup sound
// TODO
//
cs->aifunc = AIFunc_LoperAttack3;
return "AIFunc_LoperAttack3";
}
//=================================================================================
//
// STIM SOLDIER FLYING ATTACK
//
//=================================================================================
#define STIMSOLDIER_FLYJUMP_ANIM LEGS_EXTRA1
#define STIMSOLDIER_FLYJUMP_FPS 15
#define STIMSOLDIER_FLYJUMP_FRAME_COUNT 28
#define STIMSOLDIER_FLYJUMP_DURATION ( STIMSOLDIER_FLYJUMP_FRAME_COUNT*( 1000 / STIMSOLDIER_FLYJUMP_FPS ) )
#define STIMSOLDIER_FLYJUMP_DELAY ( STIMSOLDIER_FLYJUMP_DURATION + 3000 )
// hover plays continuously
#define STIMSOLDIER_FLYHOVER_ANIM LEGS_EXTRA2
#define STIMSOLDIER_FLYHOVER_FPS 5
#define STIMSOLDIER_FLYLAND_ANIM LEGS_LAND
#define STIMSOLDIER_FLYLAND_FPS 15
#define STIMSOLDIER_FLYLAND_FRAME_COUNT 14
#define STIMSOLDIER_FLYLAND_DURATION ( STIMSOLDIER_FLYLAND_FRAME_COUNT*( 1000 / STIMSOLDIER_FLYLAND_FPS ) )
#define STIMSOLDIER_STARTJUMP_DELAY ( STIMSOLDIER_FLYJUMP_DURATION*0.5 )
char *AIFunc_StimSoldierAttack1( cast_state_t *cs ) {
gentity_t *ent;
vec3_t vec;
static vec3_t up = {0,0,1};
//
ent = &g_entities[cs->entityNum];
cs->weaponFireTimes[WP_MONSTER_ATTACK1] = level.time;
// face them
AICast_AimAtEnemy( cs );
//
// are we done with this attack?
if ( cs->thinkFuncChangeTime < level.time - STIMSOLDIER_FLYJUMP_DELAY ) {
// have we hit the ground yet?
if ( ent->s.groundEntityNum != ENTITYNUM_NONE ) {
// we are on something, have we started the landing animation?
if ( !( cs->aiFlags & AIFL_LAND_ANIM_PLAYED ) ) {
ent->client->ps.legsAnim =
( ( ent->client->ps.legsAnim & ANIM_TOGGLEBIT ) ^ ANIM_TOGGLEBIT ) | STIMSOLDIER_FLYLAND_ANIM;
ent->client->ps.legsTimer = STIMSOLDIER_FLYLAND_DURATION; // stay down until attack is finished
//
cs->noAttackTime = level.time + STIMSOLDIER_FLYLAND_DURATION;
cs->aiFlags |= AIFL_LAND_ANIM_PLAYED;
} else {
if ( !ent->client->ps.legsTimer ) { // animation has finished, resume AI
return AIFunc_DefaultStart( cs );
}
}
} else {
// still flying
}
return NULL;
}
//
// are we ready to start flying?
if ( cs->thinkFuncChangeTime < ( level.time - STIMSOLDIER_STARTJUMP_DELAY ) ) {
if ( !ent->client->ps.powerups[PW_FLIGHT] ) {
// play a special ignition sound?
}
ent->client->ps.powerups[PW_FLIGHT] = 1; // let them fly
ent->s.loopSound = level.stimSoldierFlySound;
ent->client->ps.eFlags |= EF_MONSTER_EFFECT; // client-side stim engine effect
if ( ent->s.effect1Time != ( cs->thinkFuncChangeTime + STIMSOLDIER_STARTJUMP_DELAY ) ) {
ent->s.effect1Time = ( cs->thinkFuncChangeTime + STIMSOLDIER_STARTJUMP_DELAY );
// start the hovering animation
ent->client->ps.legsAnim =
( ( ent->client->ps.legsAnim & ANIM_TOGGLEBIT ) ^ ANIM_TOGGLEBIT ) | STIMSOLDIER_FLYHOVER_ANIM;
}
// give us some upwards velocity?
if ( cs->thinkFuncChangeTime > level.time - STIMSOLDIER_FLYJUMP_DURATION * 0.9 ) {
trap_EA_Move( cs->entityNum, up, 300 );
//trap_EA_Jump(cs->entityNum);
VectorCopy( cs->bs->origin, cs->stimFlyAttackPos );
} else {
// attack them
//
// if we can't attack, abort
if ( AICast_CheckAttack( cs, cs->bs->enemy, qfalse ) ) {
// apply weapons..
trap_EA_Attack( cs->entityNum );
}
// we're done here
cs->thinkFuncChangeTime = -9999;
}
} else {
// still on ground, so move forward to account for stepping animation
AngleVectors( cs->bs->viewangles, vec, NULL, NULL );
trap_EA_Move( cs->entityNum, vec, 300 );
}
//
if ( ent->client->ps.legsTimer < 1000 ) {
ent->client->ps.legsTimer = 1000; // stay down until effect is done
}
//
return NULL;
}
char *AIFunc_StimSoldierAttack1Start( cast_state_t *cs ) {
gentity_t *ent;
//static vec3_t mins={-96,-96,0}, maxs={96,96,72};
vec3_t pos, dir;
trace_t tr;
//
cs->weaponFireTimes[cs->bs->weaponnum] = level.time;
ent = &g_entities[cs->entityNum];
//
// face them
AICast_AimAtEnemy( cs );
// first, check if this is a good place to start the flying attack
AngleVectors( cs->bs->ideal_viewangles, dir, NULL, NULL );
VectorMA( cs->bs->origin, 300, dir, pos );
pos[2] += 128;
trap_Trace( &tr, cs->bs->origin, cs->bs->cur_ps.mins, cs->bs->cur_ps.maxs, pos, cs->entityNum, MASK_PLAYERSOLID );
if ( tr.startsolid || tr.allsolid ) {
return NULL; // not a good place
}
// check we can attack them from there
// select our special weapon (rocket launcher or tesla)
if ( COM_BitCheck( cs->bs->cur_ps.weapons, WP_ROCKET_LAUNCHER ) ) {
cs->bs->weaponnum = WP_ROCKET_LAUNCHER;
} else if ( COM_BitCheck( cs->bs->cur_ps.weapons, WP_TESLA ) ) {
cs->bs->weaponnum = WP_TESLA;
} else { // no weapon?
G_Error( "stim soldier tried special jump attack without a tesla or rocket launcher\n" );
}
if ( !AICast_CheckAttackAtPos( cs->entityNum, cs->bs->enemy, pos, qfalse, qfalse ) ) {
AICast_ChooseWeapon( cs, qfalse );
return NULL;
}
// play the animation
ent->client->ps.legsAnim =
( ( ent->client->ps.legsAnim & ANIM_TOGGLEBIT ) ^ ANIM_TOGGLEBIT ) | STIMSOLDIER_FLYJUMP_ANIM;
ent->client->ps.legsTimer = STIMSOLDIER_FLYJUMP_DELAY; // stay down until attack is finished
//
cs->aiFlags &= ~AIFL_LAND_ANIM_PLAYED;
// play the buildup sound
// TODO
//
cs->aifunc = AIFunc_StimSoldierAttack1;
return "AIFunc_StimSoldierAttack1";
}
//=================================================================================
//
// STIM SOLDIER DUAL MACHINEGUN ATTACK
//
//=================================================================================
char *AIFunc_StimSoldierAttack2( cast_state_t *cs ) {
return NULL;
}
char *AIFunc_StimSoldierAttack2Start( cast_state_t *cs ) {
cs->weaponFireTimes[cs->bs->weaponnum] = level.time;
//
// face them
AICast_AimAtEnemy( cs );
// TODO!
G_Printf( "TODO: stim dual machinegun attack\n" );
//
cs->aifunc = AIFunc_StimSoldierAttack2;
return "AIFunc_StimSoldierAttack2";
}
//=================================================================================
//
// BLACK GUARD MELEE KICK ATTACK
//
//=================================================================================
char *AIFunc_BlackGuardAttack1( cast_state_t *cs ) {
return NULL;
}
char *AIFunc_BlackGuardAttack1Start( cast_state_t *cs ) {
//
cs->weaponFireTimes[cs->bs->weaponnum] = level.time;
#if 1
// TODO!
G_Printf( "TODO: black guard kick attack\n" );
return NULL;
#else
// face them
AICast_AimAtEnemy( cs );
//
cs->aifunc = AIFunc_BlackGuardAttack1;
return "AIFunc_BlackGuardAttack1";
#endif
}
//=================================================================================
//
// REJECT X-CREATURE
//
// Attacks are: backhand slap, blowtorch (small flamethrower)
//
//=================================================================================
////// Backhand attack (slap)
/*
==============
AIFunc_RejectAttack1
==============
*/
char *AIFunc_RejectAttack1( cast_state_t *cs ) {
return NULL;
}
/*
==============
AIFunc_RejectAttack1Start
==============
*/
char *AIFunc_RejectAttack1Start( cast_state_t *cs ) {
gentity_t *ent;
ent = &g_entities[cs->entityNum];
ent->s.effect1Time = level.time;
cs->bs->ideal_viewangles[YAW] = cs->bs->viewangles[YAW];
cs->aifunc = AIFunc_RejectAttack1;
return "AIFunc_RejectAttack1";
}
//=================================================================================
//
// WARRIOR ZOMBIE
//
// Standing melee attacks
//
//=================================================================================
int warriorHitDamage[5] = {
16,
16,
16,
12,
20
};
#define NUM_WARRIOR_ANIMS 5
int warriorHitTimes[NUM_WARRIOR_ANIMS][3] = { // up to three hits per attack
{ANIMLENGTH( 10,20 ),-1},
{ANIMLENGTH( 15,20 ),-1},
{ANIMLENGTH( 18,20 ),-1},
{ANIMLENGTH( 15,20 ),-1},
{ANIMLENGTH( 14,20 ),-1},
};
/*
================
AIFunc_WarriorZombieMelee
================
*/
char *AIFunc_WarriorZombieMelee( cast_state_t *cs ) {
gentity_t *ent = &g_entities[cs->entityNum];
int hitDelay = -1, anim;
trace_t *tr;
if ( !ent->client->ps.torsoTimer ) {
return AIFunc_DefaultStart( cs );
}
anim = ( ent->client->ps.torsoAnim & ~ANIM_TOGGLEBIT ) - BG_AnimationIndexForString( "attack1", cs->entityNum );
if ( anim < 0 || anim >= NUM_WARRIOR_ANIMS ) {
// animation interupted
return AIFunc_DefaultStart( cs );
//G_Error( "AIFunc_WarriorZombieMelee: warrior using invalid or unknown attack anim" );
}
if ( warriorHitTimes[anim][cs->animHitCount] >= 0 ) {
// face them
AICast_AimAtEnemy( cs );
if ( !cs->animHitCount ) {
hitDelay = warriorHitTimes[anim][cs->animHitCount];
} else {
hitDelay = warriorHitTimes[anim][cs->animHitCount] - warriorHitTimes[anim][cs->animHitCount - 1];
}
// check for inflicting damage
if ( level.time - cs->weaponFireTimes[cs->bs->weaponnum] > hitDelay ) {
// do melee damage
if ( ( tr = CheckMeleeAttack( ent, 48, qfalse ) ) && ( tr->entityNum == cs->bs->enemy ) ) {
G_Damage( &g_entities[tr->entityNum], ent, ent, vec3_origin, tr->endpos,
warriorHitDamage[anim], 0, MOD_GAUNTLET );
}
G_AddEvent( ent, EV_GENERAL_SOUND, G_SoundIndex( aiDefaults[ent->aiCharacter].staySoundScript ) );
cs->weaponFireTimes[cs->bs->weaponnum] = level.time;
cs->animHitCount++;
} else {
// if they are outside range, move forward
if ( anim != 4 && !CheckMeleeAttack( ent, 48, qfalse ) ) {
//ent->client->ps.torsoTimer = 0;
ent->client->ps.legsTimer = 0; // allow legs us to move
//return AIFunc_DefaultStart(cs);
trap_EA_MoveForward( cs->entityNum );
}
}
}
return NULL;
}
/*
================
AIFunc_WarriorZombieMeleeStart
================
*/
char *AIFunc_WarriorZombieMeleeStart( cast_state_t *cs ) {
gentity_t *ent;
ent = &g_entities[cs->entityNum];
ent->s.effect1Time = level.time;
cs->bs->ideal_viewangles[YAW] = cs->bs->viewangles[YAW];
cs->weaponFireTimes[cs->bs->weaponnum] = level.time;
cs->animHitCount = 0;
// face them
AICast_AimAtEnemy( cs );
// play an anim
BG_UpdateConditionValue( cs->entityNum, ANIM_COND_WEAPON, cs->bs->weaponnum, qtrue );
BG_AnimScriptEvent( &ent->client->ps, ANIM_ET_FIREWEAPON, qfalse, qtrue );
// stop charging
BG_UpdateConditionValue( cs->entityNum, ANIM_COND_CHARGING, 0, qfalse );
ent->flags &= ~FL_WARZOMBIECHARGE;
cs->aifunc = AIFunc_WarriorZombieMelee;
return "AIFunc_WarriorZombieMelee";
}
// Warrior "sight" animation
/*
================
AIFunc_WarriorZombieSight
================
*/
char *AIFunc_WarriorZombieSight( cast_state_t *cs ) {
gentity_t *ent = &g_entities[cs->entityNum];
if ( !ent->client->ps.torsoTimer ) {
return AIFunc_DefaultStart( cs );
}
return NULL;
}
/*
================
AIFunc_WarriorZombieSightStart
================
*/
char *AIFunc_WarriorZombieSightStart( cast_state_t *cs ) {
#if 1 // RF, disabled
return NULL;
#else
gentity_t *ent;
ent = &g_entities[cs->entityNum];
cs->bs->ideal_viewangles[YAW] = cs->bs->viewangles[YAW];
cs->weaponFireTimes[cs->bs->weaponnum] = level.time;
// face them
AICast_AimAtEnemy( cs );
// anim
BG_AnimScriptEvent( &ent->client->ps, ANIM_ET_FIRSTSIGHT, qfalse, qtrue );
//BG_PlayAnimName( &ent->client->ps, "first_sight", ANIM_BP_BOTH, qtrue, qfalse, qtrue );
cs->aifunc = AIFunc_WarriorZombieSight;
return "AIFunc_WarriorZombieSight";
#endif
}
/*
================
AIFunc_WarriorZombieDefense
================
*/
char *AIFunc_WarriorZombieDefense( cast_state_t *cs ) {
gentity_t *ent, *enemy;
vec3_t enemyDir, vec;
float dist;
ent = &g_entities[cs->entityNum];
if ( !( ent->flags & FL_DEFENSE_GUARD ) ) {
if ( cs->weaponFireTimes[cs->bs->weaponnum] < level.time - 100 ) {
return AIFunc_DefaultStart( cs );
}
return NULL;
}
if ( cs->bs->enemy < 0 ) {
ent->flags &= ~FL_DEFENSE_GUARD;
ent->client->ps.torsoTimer = 0;
ent->client->ps.legsTimer = 0;
return NULL;
}
enemy = &g_entities[cs->bs->enemy];
if ( cs->thinkFuncChangeTime < level.time - 1500 ) {
// if we cant see them
if ( !AICast_EntityVisible( cs, cs->bs->enemy, qtrue ) ) {
ent->flags &= ~FL_DEFENSE_GUARD;
ent->client->ps.torsoTimer = 0;
ent->client->ps.legsTimer = 0;
return NULL;
}
// if our enemy isn't using a dangerous weapon
if ( enemy->client->ps.weapon < WP_LUGER || enemy->client->ps.weapon > WP_CROSS ) {
ent->flags &= ~FL_DEFENSE_GUARD;
ent->client->ps.torsoTimer = 0;
ent->client->ps.legsTimer = 0;
return NULL;
}
// if our enemy isn't looking right at us, abort
VectorSubtract( ent->client->ps.origin, enemy->client->ps.origin, vec );
dist = VectorNormalize( vec );
if ( dist > 512 ) {
dist = 512;
}
AngleVectors( enemy->client->ps.viewangles, enemyDir, NULL, NULL );
if ( DotProduct( vec, enemyDir ) < ( 0.98 - 0.2 * ( dist / 512 ) ) ) {
ent->flags &= ~FL_DEFENSE_GUARD;
ent->client->ps.torsoTimer = 0;
ent->client->ps.legsTimer = 0;
return NULL;
}
}
cs->weaponFireTimes[cs->bs->weaponnum] = level.time;
if ( !ent->client->ps.torsoTimer ) {
ent->flags &= ~FL_DEFENSE_GUARD;
ent->client->ps.torsoTimer = 0;
ent->client->ps.legsTimer = 0;
return NULL;
}
// face them
AICast_AimAtEnemy( cs );
// crouching position, use smaller bounding box
trap_EA_Crouch( cs->bs->client );
return NULL;
}
/*
================
AIFunc_WarriorZombieDefenseStart
================
*/
char *AIFunc_WarriorZombieDefenseStart( cast_state_t *cs ) {
gentity_t *ent, *enemy;
vec3_t enemyDir, vec;
float dist;
ent = &g_entities[cs->entityNum];
enemy = &g_entities[cs->bs->enemy];
// if our enemy isn't using a dangerous weapon
if ( enemy->client->ps.weapon < WP_LUGER || enemy->client->ps.weapon > WP_CROSS ) {
return NULL;
}
// if our enemy isn't looking right at us, abort
VectorSubtract( ent->client->ps.origin, enemy->client->ps.origin, vec );
dist = VectorNormalize( vec );
if ( dist > 512 ) {
dist = 512;
}
if ( dist < 128 ) {
return NULL;
}
AngleVectors( enemy->client->ps.viewangles, enemyDir, NULL, NULL );
if ( DotProduct( vec, enemyDir ) < ( 0.98 - 0.2 * ( dist / 512 ) ) ) {
return NULL;
}
cs->weaponFireTimes[cs->bs->weaponnum] = level.time;
// face them
AICast_AimAtEnemy( cs );
// anim
BG_UpdateConditionValue( cs->entityNum, ANIM_COND_WEAPON, cs->bs->weaponnum, qtrue );
BG_AnimScriptEvent( &ent->client->ps, ANIM_ET_FIREWEAPON, qfalse, qtrue );
ent->client->ps.torsoTimer = 3000;
ent->client->ps.legsTimer = 3000;
ent->flags |= FL_DEFENSE_GUARD;
// when they come out of defense mode, go into charge mode
BG_UpdateConditionValue( cs->entityNum, ANIM_COND_CHARGING, 1, qfalse );
ent->flags |= FL_WARZOMBIECHARGE;
cs->aifunc = AIFunc_WarriorZombieDefense;
return "AIFunc_WarriorZombieDefense";
}
|