MCPcopy Create free account
hub / github.com/bfbbdecomp/bfbb / CalcNewDir

Method CalcNewDir

src/SB/Game/zNPCGoalStd.cpp:847–903  ·  view source on GitHub ↗

Equivalent: regalloc

Source from the content-addressed store, hash-verified

845
846// Equivalent: regalloc
847void zNPCGoalWander::CalcNewDir()
848{
849 zNPCCommon* npc = (zNPCCommon*)psyche->clt_owner;
850 xVec3 direction;
851 xVec3* player_pos;
852 xVec3* npc_pos;
853
854 F32 dVar4 = NPCC_aimVary(&dir_cur, xEntGetPos(npc), &pos_home, rad_wand, 0, NULL);
855 if (npc->flg_move & (1 << 1))
856 {
857 dir_cur.y = 0.0f;
858 }
859 if (dVar4 < rad_wand)
860 {
861 npc_pos = xEntGetPos(npc);
862 player_pos = xEntGetPos(&globals.player.ent);
863 xVec3Sub(&direction, player_pos, npc_pos);
864
865 F32 length = xVec3Length(&direction);
866 if (length < 1.0f)
867 {
868 xVec3Copy(&direction, NPCC_rightDir(&globals.player.ent));
869 if ((xrand() & 0x800000) != 0)
870 {
871 xVec3SMulBy(&direction, -1.0f);
872 }
873 }
874 else if (length < 10.0f)
875 {
876 xVec3SMulBy(&direction, -1.0f / length);
877 }
878 else
879 {
880 xVec3Copy(&direction, &g_O3);
881 }
882 }
883 else
884 {
885 xVec3Copy(&direction, &g_O3);
886 }
887
888 xVec3AddTo(&dir_cur, &direction);
889 xVec3Normalize(&dir_cur, &dir_cur);
890 dVar4 = MAX(0.5f, dVar4);
891 F32 dVar6 = npc->cfg_npc->spd_moveMax;
892 F32 dVar5 = rad_wand * xurand() + dVar4;
893 if (dVar6 < 0.5f)
894 {
895 tmr_minwalk = 0.25f * dVar4;
896 tmr_newdir = 0.25f * dVar5;
897 }
898 else
899 {
900 tmr_minwalk = dVar4 / dVar6;
901 tmr_newdir = dVar5 / dVar6;
902 }
903}
904

Callers

nothing calls this directly

Calls 11

xEntGetPosFunction · 0.85
xVec3SubFunction · 0.85
xVec3LengthFunction · 0.85
xVec3CopyFunction · 0.85
NPCC_rightDirFunction · 0.85
xrandFunction · 0.85
xVec3SMulByFunction · 0.85
xVec3AddToFunction · 0.85
xurandFunction · 0.85
NPCC_aimVaryFunction · 0.70
xVec3NormalizeFunction · 0.50

Tested by

no test coverage detected