/
ai.cpp
1822 lines (1488 loc) · 47.5 KB
/
ai.cpp
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
//-------------------------------------------------------------------------
/*
Copyright (C) 1997, 2005 - 3D Realms Entertainment
This file is part of Shadow Warrior version 1.2
Shadow Warrior 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 2
of the License, or (at your option) any later version.
This program 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 this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
Original Source: 1997 - Frank Maddin and Jim Norwood
Prepared for public release: 03/28/2005 - Charlie Wiederhold, 3D Realms
*/
//-------------------------------------------------------------------------
#include "ns.h"
#include "build.h"
#include "names2.h"
#include "game.h"
#include "tags.h"
#include "sector.h"
#include "sprite.h"
// temp - should be moved
#include "ai.h"
#include "network.h"
BEGIN_SW_NS
ANIMATOR InitActorRunToward;
bool DropAhead(DSWActor* actor, double min_height);
ANIMATOR* ChooseAction(DECISION decision[]);
#define CHOOSE2(value) (RANDOM_P2(1024) < (value))
//---------------------------------------------------------------------------
//
//
//
//---------------------------------------------------------------------------
bool ActorMoveHitReact(DSWActor* actor)
{
// Should only return true if there is a reaction to what was hit that
// would cause the calling function to abort
auto coll = actor->user.coll;
if (coll.type == kHitSprite)
{
auto hitActor = coll.actor();
if (hitActor->hasU() && hitActor->user.PlayerP)
{
// if you ran into a player - call close range functions
DoActorPickClosePlayer(actor);
auto action = ChooseAction(actor->user.__legacyState.Personality->TouchTarget);
if (action)
{
(*action)(actor);
return true;
}
}
}
return false;
}
//---------------------------------------------------------------------------
//
//
//
//---------------------------------------------------------------------------
bool ActorFlaming(DSWActor* actor)
{
auto flame = actor->user.flameActor;
if (flame != nullptr)
{
if (ActorSizeZ(flame) > ActorSizeZ(actor) * 0.75)
return true;
}
return false;
}
//---------------------------------------------------------------------------
//
//
//
//---------------------------------------------------------------------------
void DoActorSetSpeed(DSWActor* actor, uint8_t speed)
{
if (actor->spr.cstat & (CSTAT_SPRITE_RESTORE))
return;
ASSERT(actor->user.__legacyState.Attrib);
actor->user.speed = speed;
int vel;
if (ActorFlaming(actor))
vel = actor->user.__legacyState.Attrib->Speed[speed] + (actor->user.__legacyState.Attrib->Speed[speed] >> 1);
else
vel = actor->user.__legacyState.Attrib->Speed[speed];
actor->vel.X = vel * maptoworld;
}
//---------------------------------------------------------------------------
/*
!AIC - Does a table lookup based on a random value from 0 to 1023.
These tables are defined at the top of all actor files such as ninja.c,
goro.c etc.
*/
//---------------------------------------------------------------------------
ANIMATOR* ChooseAction(DECISION decision[])
{
// !JIM! Here is an opportunity for some AI, instead of randomness!
int random_value = RANDOM_P2(1024<<5)>>5;
for (int i = 0; true; i++)
{
ASSERT(i < 10);
if (random_value <= decision[i].range)
{
return decision[i].action;
}
}
}
//---------------------------------------------------------------------------
/*
!AIC - Sometimes just want the offset of the action
*/
//---------------------------------------------------------------------------
int ChooseActionNumber(int16_t decision[])
{
int random_value = RANDOM_P2(1024<<5)>>5;
for (int i = 0; true; i++)
{
if (random_value <= decision[i])
{
return i;
}
}
}
//---------------------------------------------------------------------------
//
//
//
//---------------------------------------------------------------------------
int DoActorNoise(ANIMATOR* Action, DSWActor* actor)
{
if (Action == InitActorAmbientNoise)
{
PlaySpriteSound(actor, attr_ambient, v3df_follow);
}
else if (Action == InitActorAlertNoise)
{
if (actor->hasU() && !actor->user.DidAlert) // This only allowed once
PlaySpriteSound(actor, attr_alert, v3df_follow);
}
else if (Action == InitActorAttackNoise)
{
PlaySpriteSound(actor, attr_attack, v3df_follow);
}
else if (Action == InitActorPainNoise)
{
PlaySpriteSound(actor, attr_pain, v3df_follow);
}
else if (Action == InitActorDieNoise)
{
PlaySpriteSound(actor, attr_die, v3df_none);
}
else if (Action == InitActorExtra1Noise)
{
PlaySpriteSound(actor, attr_extra1, v3df_follow);
}
else if (Action == InitActorExtra2Noise)
{
PlaySpriteSound(actor, attr_extra2, v3df_follow);
}
else if (Action == InitActorExtra3Noise)
{
PlaySpriteSound(actor, attr_extra3, v3df_follow);
}
else if (Action == InitActorExtra4Noise)
{
PlaySpriteSound(actor, attr_extra4, v3df_follow);
}
else if (Action == InitActorExtra5Noise)
{
PlaySpriteSound(actor, attr_extra5, v3df_follow);
}
else if (Action == InitActorExtra6Noise)
{
PlaySpriteSound(actor, attr_extra6, v3df_follow);
}
return 0;
}
//---------------------------------------------------------------------------
//
//
//
//---------------------------------------------------------------------------
bool CanSeePlayer(DSWActor* actor)
{
return actor->user.targetActor && FAFcansee(ActorVectOfTop(actor), actor->sector(), ActorUpperVect(actor->user.targetActor), actor->user.targetActor->sector());
}
//---------------------------------------------------------------------------
//
//
//
//---------------------------------------------------------------------------
int CanHitPlayer(DSWActor* actor)
{
HitInfo hit{};
DVector3 vect;
// if actor can still see the player
DSWActor* targ = actor->user.targetActor;
DVector3 apos = actor->spr.pos.plusZ(-ActorSizeZ(actor) * 0.5);
DVector3 tpos = targ->spr.pos.plusZ(-ActorSizeZ(targ) * 0.5);
auto vec = (tpos - apos).Unit() * 1024;
FAFhitscan(apos, actor->sector(), vec, hit, CLIPMASK_MISSILE);
if (hit.hitSector == nullptr)
return false;
if (hit.actor() == actor->user.targetActor)
return true;
return false;
}
//---------------------------------------------------------------------------
/*
!AIC - Pick a nearby player to be the actors target
*/
//---------------------------------------------------------------------------
int DoActorPickClosePlayer(DSWActor* actor)
{
int pnum;
PLAYER* pp;
// if actor can still see the player
bool found = false;
int i;
double near_dist = MAX_ACTIVE_RANGE;
double dist;
if (actor->user.ID == ZOMBIE_RUN_R0 && gNet.MultiGameType == MULTI_GAME_COOPERATIVE)
goto TARGETACTOR;
// Set initial target to Player 0
actor->user.targetActor = Player->actor;
if (actor->user.Flags2 & (SPR2_DONT_TARGET_OWNER))
{
TRAVERSE_CONNECT(pnum)
{
pp = &Player[pnum];
if (GetOwner(actor) == pp->actor)
continue;
actor->user.targetActor = pp->actor;
break;
}
}
// Set initial target to the closest player
TRAVERSE_CONNECT(pnum)
{
pp = &Player[pnum];
// Zombies don't target their masters!
if (actor->user.Flags2 & (SPR2_DONT_TARGET_OWNER))
{
if (GetOwner(actor) == pp->actor)
continue;
if (!PlayerTakeDamage(pp, actor))
continue;
// if co-op don't hurt teammate
// if (gNet.MultiGameType == MULTI_GAME_COOPERATIVE && !gNet.HurtTeammate && actor->user.spal == pp->actor->spr.spal)
// continue;
}
dist = (actor->spr.pos - pp->actor->getPosWithOffsetZ()).Length();
if (dist < near_dist)
{
near_dist = dist;
actor->user.targetActor = pp->actor;
}
}
// see if you can find someone close that you can SEE
near_dist = MAX_ACTIVE_RANGE;
found = false;
TRAVERSE_CONNECT(pnum)
{
pp = &Player[pnum];
// Zombies don't target their masters!
if (actor->user.Flags2 & (SPR2_DONT_TARGET_OWNER))
{
if (GetOwner(actor) == pp->actor)
continue;
if (!PlayerTakeDamage(pp, actor))
continue;
}
dist = (actor->spr.pos - pp->actor->getPosWithOffsetZ()).Length();
DSWActor* plActor = pp->actor;
if (dist < near_dist && FAFcansee(ActorVectOfTop(actor), actor->sector(), ActorUpperVect(plActor), plActor->sector()))
{
near_dist = dist;
actor->user.targetActor = pp->actor;
found = true;
}
}
TARGETACTOR:
// this is only for Zombies right now
// zombie target other actors
if (!found && (actor->user.Flags2 & SPR2_DONT_TARGET_OWNER))
{
near_dist = MAX_ACTIVE_RANGE;
SWStatIterator it(STAT_ENEMY);
while (auto itActor = it.Next())
{
if (itActor == actor || !itActor->hasU())
continue;
if ((itActor->user.Flags & (SPR_SUICIDE | SPR_DEAD)))
continue;
dist = (actor->spr.pos - itActor->spr.pos).Length();
if (dist < near_dist && FAFcansee(ActorVectOfTop(actor), actor->sector(), ActorUpperVect(itActor), itActor->sector()))
{
near_dist = dist;
actor->user.targetActor = itActor;
}
}
}
return 0;
}
//---------------------------------------------------------------------------
//
//
//
//---------------------------------------------------------------------------
DSWActor* GetPlayerSpriteNum(DSWActor* actor)
{
int pnum;
PLAYER* pp;
TRAVERSE_CONNECT(pnum)
{
pp = &Player[pnum];
if (pp->actor == actor->user.targetActor)
{
return pp->actor;
}
}
return nullptr;
}
//---------------------------------------------------------------------------
//
//
//
//---------------------------------------------------------------------------
int DoActorOperate(DSWActor* actor)
{
HitInfo near{};
double z[2];
unsigned int i;
if (actor->user.ID == HORNET_RUN_R0 || actor->user.ID == EEL_RUN_R0 || actor->user.ID == BUNNY_RUN_R0)
return false;
if (actor->checkStateGroup(NAME_Sit) || actor->checkStateGroup(NAME_Stand))
return false;
if ((actor->user.WaitTics -= ACTORMOVETICS) > 0)
return false;
z[0] = -ActorSizeZ(actor) + 5;
z[1] = -(ActorSizeZ(actor) * 0.5);
for (i = 0; i < SIZ(z); i++)
{
neartag(actor->spr.pos.plusZ(z[i]), actor->sector(), actor->spr.Angles.Yaw, near, 64., NT_Lotag | NT_Hitag | NT_NoSpriteCheck);
}
if (near.hitSector != nullptr)
{
if (OperateSector(near.hitSector, false))
{
actor->user.WaitTics = 2 * 120;
actor->setStateGroup(NAME_Sit);
}
}
return true;
}
//---------------------------------------------------------------------------
//
//
//
//---------------------------------------------------------------------------
DECISION GenericFlaming[] =
{
{30, InitActorAttack},
{512, InitActorRunToward},
{1024, InitActorRunAway},
};
/*
!AIC KEY - This routine decides what the actor will do next. It is not called
every time through the loop. This would be too slow. It is only called when
the actor needs to know what to do next such as running into something or being
targeted. It makes decisions based on the distance and viewablity of its target
(actor->user.targetActor). When it figures out the situatation with its target it calls
ChooseAction which does a random table lookup to decide what action to initialize.
Once this action is initialized it will be called until it can't figure out what to
do anymore and then this routine is called again.
*/
ANIMATOR* DoActorActionDecide(DSWActor* actor)
{
ANIMATOR* action;
bool ICanSee=false;
// REMINDER: This function is not even called if SpriteControl doesn't let
// it get called
ASSERT(actor->user.__legacyState.Personality);
actor->user.Dist = 0;
action = InitActorDecide;
// target is gone.
if (actor->user.targetActor == nullptr)
{
return action;
}
if (actor->user.Flags & (SPR_JUMPING | SPR_FALLING))
{
//CON_Message("Jumping or falling");
return action;
}
// everybody on fire acts like this
if (ActorFlaming(actor))
{
action = ChooseAction(&GenericFlaming[0]);
//CON_Message("On Fire");
return action;
}
ICanSee = CanSeePlayer(actor); // Only need to call once
// But need the result multiple times
// !AIC KEY - If aware of player - var is changed in SpriteControl
if (actor->user.Flags & (SPR_ACTIVE))
{
// Try to operate stuff
DoActorOperate(actor);
// if far enough away and cannot see the player
double dist = (actor->spr.pos.XY() - actor->user.targetActor->spr.pos.XY()).Length();
if (dist > 1875 && !ICanSee)
{
// Enemy goes inactive - he is still allowed to roam about for about
// 5 seconds trying to find another player before his active_range is
// bumped down
actor->user.Flags &= ~(SPR_ACTIVE);
// You've lost the player - now decide what to do
action = ChooseAction(actor->user.__legacyState.Personality->LostTarget);
//CON_Message("LostTarget");
return action;
}
auto pActor = GetPlayerSpriteNum(actor);
// check for short range attack possibility
if ((dist < CloseRangeDist(actor, actor->user.targetActor) && ICanSee) ||
(pActor && pActor->hasU() && pActor->user.WeaponNum == WPN_FIST && actor->user.ID != RIPPER2_RUN_R0 && actor->user.ID != RIPPER_RUN_R0))
{
if ((actor->user.ID == COOLG_RUN_R0 && (actor->spr.cstat & CSTAT_SPRITE_TRANSLUCENT)) || (actor->spr.cstat & CSTAT_SPRITE_INVISIBLE))
action = ChooseAction(actor->user.__legacyState.Personality->Evasive);
else
action = ChooseAction(actor->user.__legacyState.Personality->CloseRange);
//CON_Message("CloseRange");
return action;
}
// if player is facing me and I'm being attacked
if (Facing(actor, actor->user.targetActor) && (actor->user.Flags & SPR_ATTACKED) && ICanSee)
{
// if I'm a target - at least one missile comming at me
if (actor->user.Flags & (SPR_TARGETED))
{
// not going to evade, reset the target bit
actor->user.Flags &= ~(SPR_TARGETED); // as far as actor
// knows, its not a
// target any more
if (actor->user.__legacyState.ActorActionSet->Duck && RANDOM_P2(1024<<8)>>8 < 100)
action = InitActorDuck;
else
{
if ((actor->user.ID == COOLG_RUN_R0 && (actor->spr.cstat & CSTAT_SPRITE_TRANSLUCENT)) || (actor->spr.cstat & CSTAT_SPRITE_INVISIBLE))
action = ChooseAction(actor->user.__legacyState.Personality->Evasive);
else
action = ChooseAction(actor->user.__legacyState.Personality->Battle);
}
//CON_Message("Battle 1");
return action;
}
// if NOT a target - don't bother with evasive action and start
// fighting
else
{
if ((actor->user.ID == COOLG_RUN_R0 && (actor->spr.cstat & CSTAT_SPRITE_TRANSLUCENT)) || (actor->spr.cstat & CSTAT_SPRITE_INVISIBLE))
action = ChooseAction(actor->user.__legacyState.Personality->Evasive);
else
action = ChooseAction(actor->user.__legacyState.Personality->Battle);
//CON_Message("Battle 2");
return action;
}
}
// if player is NOT facing me he is running or unaware of actor
else if (ICanSee)
{
if ((actor->user.ID == COOLG_RUN_R0 && (actor->spr.cstat & CSTAT_SPRITE_TRANSLUCENT)) || (actor->spr.cstat & CSTAT_SPRITE_INVISIBLE))
action = ChooseAction(actor->user.__legacyState.Personality->Evasive);
else
action = ChooseAction(actor->user.__legacyState.Personality->Offense);
//CON_Message("Offense");
return action;
}
else
{
// You've lost the player - now decide what to do
action = ChooseAction(actor->user.__legacyState.Personality->LostTarget);
//CON_Message("Close but cant see, LostTarget");
return action;
}
}
// Not active - not aware of player and cannot see him
else
{
// try and find another player
// pick a closeby player as the (new) target
if (actor->spr.hitag != TAG_SWARMSPOT)
DoActorPickClosePlayer(actor);
// if close by
double const dist = (actor->spr.pos.XY() - actor->user.targetActor->spr.pos.XY()).Length();
if (dist < 937.5 || ICanSee)
{
if ((Facing(actor, actor->user.targetActor) && dist < 625) || ICanSee)
{
DoActorOperate(actor);
// Don't let player completely sneek up behind you
action = ChooseAction(actor->user.__legacyState.Personality->Surprised);
//CON_Message("Surprised");
if (!actor->user.DidAlert && ICanSee)
{
DoActorNoise(InitActorAlertNoise, actor);
actor->user.DidAlert = true;
}
return action;
}
else
{
// Player has not seen actor, to be fair let him know actor
// are there
DoActorNoise(ChooseAction(actor->user.__legacyState.Personality->Broadcast),actor);
//CON_Message("Actor Noise");
return action;
}
}
}
//CON_Message("Couldn't resolve decide, InitActorDecide");
return action;
}
//---------------------------------------------------------------------------
//
//
//
//---------------------------------------------------------------------------
int InitActorDecide(DSWActor* actor)
{
actor->setActionDecide();
return DoActorDecide(actor);
}
//---------------------------------------------------------------------------
//
//
//
//---------------------------------------------------------------------------
int DoActorDecide(DSWActor* actor)
{
ANIMATOR* actor_action;
// See what to do next
actor_action = DoActorActionDecide(actor);
// Fix for the GenericFlaming bug for actors that don't have attack states
if (actor_action == InitActorAttack && actor->user.WeaponNum == 0)
return 0; // Just let the actor do as it was doing before in this case
// Target is gone.
if (actor->user.targetActor == nullptr)
return 0;
// zombie is attacking a player
if (actor_action == InitActorAttack && actor->user.ID == ZOMBIE_RUN_R0 && actor->user.targetActor->user.PlayerP)
{
// Don't let zombies shoot at master
if (GetOwner(actor) == actor->user.targetActor)
return 0;
// if this player cannot take damage from this zombie(weapon) return out
if (!PlayerTakeDamage(actor->user.targetActor->user.PlayerP, actor))
return 0;
}
ASSERT(actor_action != nullptr);
if (actor_action != InitActorDecide)
{
// NOT staying put
(*actor_action)(actor);
//CON_Message("DoActorDecide: NOT Staying put");
}
else
{
// Actually staying put
actor->setStateGroup(NAME_Stand);
//CON_Message("DoActorDecide: Staying put");
}
return 0;
}
// Important note: The functions below are being checked for as state identifiers.
// But they are all identical content wise which makes MSVC merge them together into one.
// Assigning 'sw_snd_scratch' different values makes them different so that merging does not occur.
int sw_snd_scratch = 0;
//---------------------------------------------------------------------------
//
//
//
//---------------------------------------------------------------------------
int InitActorAlertNoise(DSWActor* actor)
{
sw_snd_scratch = 1;
actor->setActionDecide();
return 0;
}
int InitActorAmbientNoise(DSWActor* actor)
{
sw_snd_scratch = 2;
actor->setActionDecide();
return 0;
}
int InitActorAttackNoise(DSWActor* actor)
{
sw_snd_scratch = 3;
actor->setActionDecide();
return 0;
}
int InitActorPainNoise(DSWActor* actor)
{
sw_snd_scratch = 4;
actor->setActionDecide();
return 0;
}
int InitActorDieNoise(DSWActor* actor)
{
sw_snd_scratch = 5;
actor->setActionDecide();
return 0;
}
int InitActorExtra1Noise(DSWActor* actor)
{
sw_snd_scratch = 6;
actor->setActionDecide();
return 0;
}
int InitActorExtra2Noise(DSWActor* actor)
{
sw_snd_scratch = 7;
actor->setActionDecide();
return 0;
}
int InitActorExtra3Noise(DSWActor* actor)
{
sw_snd_scratch = 8;
actor->setActionDecide();
return 0;
}
int InitActorExtra4Noise(DSWActor* actor)
{
sw_snd_scratch = 9;
actor->setActionDecide();
return 0;
}
int InitActorExtra5Noise(DSWActor* actor)
{
sw_snd_scratch = 10;
actor->setActionDecide();
return 0;
}
int InitActorExtra6Noise(DSWActor* actor)
{
sw_snd_scratch = 11;
actor->setActionDecide();
return 0;
}
//---------------------------------------------------------------------------
/*
!AIC KEY - Routines handle moving toward the player.
*/
//---------------------------------------------------------------------------
int InitActorMoveCloser(DSWActor* actor)
{
actor->user.__legacyState.ActorActionFunc = DoActorMoveCloser;
if (!actor->checkStateGroup(NAME_Run))
actor->setStateGroup(NAME_Run);
(*actor->user.__legacyState.ActorActionFunc)(actor);
return 0;
}
//---------------------------------------------------------------------------
//
//
//
//---------------------------------------------------------------------------
int DoActorCantMoveCloser(DSWActor* actor)
{
actor->user.track = FindTrackToPlayer(actor);
if (actor->user.track >= 0)
{
auto tp = Track[actor->user.track].TrackPoint + actor->user.point;
actor->spr.Angles.Yaw = (tp->pos - actor->spr.pos).Angle();
DoActorSetSpeed(actor, MID_SPEED);
actor->user.Flags |= (SPR_FIND_PLAYER);
actor->setActionDecide();
actor->setStateGroup(NAME_Run);
}
else
{
// Try to move closer
InitActorReposition(actor);
}
return 0;
}
//---------------------------------------------------------------------------
//
//
//
//---------------------------------------------------------------------------
int DoActorMoveCloser(DSWActor* actor)
{
// if cannot move the sprite
if (!move_actor(actor, DVector3(actor->spr.Angles.Yaw.ToVector() * actor->vel.X, 0)))
{
if (ActorMoveHitReact(actor))
return 0;
DoActorCantMoveCloser(actor);
return 0;
}
// Do a noise if ok
DoActorNoise(ChooseAction(actor->user.__legacyState.Personality->Broadcast), actor);
// after moving a ways check to see if player is still in sight
if (actor->user.DistCheck > 34.375)
{
actor->user.DistCheck = 0;
// If player moved out of sight
if (!CanSeePlayer(actor))
{
// stay put and choose another option
InitActorDecide(actor);
return 0;
}
else
{
// turn to face player
actor->spr.Angles.Yaw = (actor->user.targetActor->spr.pos - actor->spr.pos).Angle();
}
}
// Should be a random value test
if (actor->user.Dist > 32 * 3)
{
InitActorDecide(actor);
}
return 0;
}
//---------------------------------------------------------------------------
/*
!AIC - Find tracks of different types. Toward target, away from target, etc.
*/
//---------------------------------------------------------------------------
int FindTrackToPlayer(DSWActor* actor)
{
int point, track_dir, track;
int i, size;
const uint16_t* type;
double zdiff;
static const uint16_t PlayerAbove[] =
{
BIT(TT_LADDER),
BIT(TT_STAIRS),
BIT(TT_JUMP_UP),
BIT(TT_TRAVERSE),
BIT(TT_OPERATE),
BIT(TT_SCAN)
};
static const uint16_t PlayerBelow[] =
{
BIT(TT_JUMP_DOWN),
BIT(TT_STAIRS),
BIT(TT_TRAVERSE),
BIT(TT_OPERATE),
BIT(TT_SCAN)
};
static const uint16_t PlayerOnLevel[] =
{
BIT(TT_DUCK_N_SHOOT),
BIT(TT_HIDE_N_SHOOT),
BIT(TT_TRAVERSE),
BIT(TT_EXIT),
BIT(TT_OPERATE),
BIT(TT_SCAN)
};
zdiff = ActorUpperZ(actor->user.targetActor) - (actor->spr.pos.Z - ActorSizeZ(actor) + 8);
if (abs(zdiff) <= 20)
{
type = PlayerOnLevel;
size = SIZ(PlayerOnLevel);
}
else
{
if (zdiff < 0)
{
type = PlayerAbove;
size = SIZ(PlayerAbove);
}
else
{
type = PlayerBelow;
size = SIZ(PlayerBelow);
}
}
for (i = 0; i < size; i++)
{
track = ActorFindTrack(actor, 1, type[i], &point, &track_dir);
if (track >= 0)
{
actor->user.point = point;
actor->user.track_dir = track_dir;
Track[track].flags |= (TF_TRACK_OCCUPIED);
return track;
}
}
return -1;
}
//---------------------------------------------------------------------------
//
//
//
//---------------------------------------------------------------------------
int FindTrackAwayFromPlayer(DSWActor* actor)
{
int point, track_dir, track;
unsigned int i;
static const int16_t RunAwayTracks[] =
{