MCPcopy Create free account
hub / github.com/demoth/jake2 / SV_NewChaseDir

Method SV_NewChaseDir

game/src/main/java/jake2/game/SV.java:984–1066  ·  view source on GitHub ↗
(SubgameEntity actor, SubgameEntity enemy, float dist, GameExportsImpl gameExports)

Source from the content-addressed store, hash-verified

982 }
983
984 static void SV_NewChaseDir(SubgameEntity actor, SubgameEntity enemy, float dist, GameExportsImpl gameExports) {
985 float deltax, deltay;
986 float d[] = { 0, 0, 0 };
987 float tdir, olddir, turnaround;
988
989 //FIXME: how did we get here with no enemy
990 if (enemy == null) {
991 gameExports.gameImports.dprintf("SV_NewChaseDir without enemy!\n");
992 return;
993 }
994 olddir = Math3D.anglemod((int) (actor.ideal_yaw / 45) * 45);
995 turnaround = Math3D.anglemod(olddir - 180);
996
997 deltax = enemy.s.origin[0] - actor.s.origin[0];
998 deltay = enemy.s.origin[1] - actor.s.origin[1];
999 int DI_NODIR = -1;
1000 if (deltax > 10)
1001 d[1] = 0;
1002 else if (deltax < -10)
1003 d[1] = 180;
1004 else
1005 d[1] = DI_NODIR;
1006 if (deltay < -10)
1007 d[2] = 270;
1008 else if (deltay > 10)
1009 d[2] = 90;
1010 else
1011 d[2] = DI_NODIR;
1012
1013 // try direct route
1014 if (d[1] != DI_NODIR && d[2] != DI_NODIR) {
1015 if (d[1] == 0)
1016 tdir = d[2] == 90 ? 45 : 315;
1017 else
1018 tdir = d[2] == 90 ? 135 : 215;
1019
1020 if (tdir != turnaround && SV_StepDirection(actor, tdir, dist, gameExports))
1021 return;
1022 }
1023
1024 // try other directions
1025 if (((Lib.rand() & 3) & 1) != 0 || Math.abs(deltay) > Math.abs(deltax)) {
1026 tdir = d[1];
1027 d[1] = d[2];
1028 d[2] = tdir;
1029 }
1030
1031 if (d[1] != DI_NODIR && d[1] != turnaround
1032 && SV_StepDirection(actor, d[1], dist, gameExports))
1033 return;
1034
1035 if (d[2] != DI_NODIR && d[2] != turnaround
1036 && SV_StepDirection(actor, d[2], dist, gameExports))
1037 return;
1038
1039 /* there is no direct path to the player, so pick another direction */
1040
1041 if (olddir != DI_NODIR

Callers 1

M_MoveToGoalMethod · 0.95

Calls 6

anglemodMethod · 0.95
SV_StepDirectionMethod · 0.95
randMethod · 0.95
M_CheckBottomMethod · 0.95
SV_FixCheckBottomMethod · 0.95
dprintfMethod · 0.65

Tested by

no test coverage detected