MCPcopy Create free account
hub / github.com/JACoders/OpenJK / NPC_StartFlee

Function NPC_StartFlee

code/game/NPC_behavior.cpp:1908–1986  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1906}
1907
1908void NPC_StartFlee( gentity_t *enemy, vec3_t dangerPoint, int dangerLevel, int fleeTimeMin, int fleeTimeMax )
1909{
1910 if ( Q3_TaskIDPending( NPC, TID_MOVE_NAV ) )
1911 {//running somewhere that a script requires us to go, don't interrupt that!
1912 return;
1913 }
1914
1915 if (NPCInfo->scriptFlags & SCF_DONT_FLEE ) // no flee for you
1916 {
1917 return;
1918 }
1919
1920
1921 //if have a fleescript, run that instead
1922 if ( G_ActivateBehavior( NPC, BSET_FLEE ) )
1923 {
1924 return;
1925 }
1926
1927 //FIXME: play a flee sound? Appropriate to situation?
1928 if ( enemy )
1929 {
1930 NPC_JawaFleeSound();
1931 G_SetEnemy( NPC, enemy );
1932 }
1933
1934
1935 //FIXME: if don't have a weapon, find nearest one we have a route to and run for it?
1936 int cp = -1;
1937 if ( dangerLevel > AEL_DANGER || NPC->s.weapon == WP_NONE || ((!NPCInfo->group || NPCInfo->group->numGroup <= 1) && NPC->health <= 10 ) )
1938 {//IF either great danger OR I have no weapon OR I'm alone and low on health, THEN try to find a combat point out of PVS
1939 cp = NPC_FindCombatPoint( NPC->currentOrigin, dangerPoint, NPC->currentOrigin, CP_COVER|CP_AVOID|CP_HAS_ROUTE|CP_NO_PVS, 128 );
1940 }
1941 //FIXME: still happens too often...
1942 if ( cp == -1 )
1943 {//okay give up on the no PVS thing
1944 cp = NPC_FindCombatPoint( NPC->currentOrigin, dangerPoint, NPC->currentOrigin, CP_COVER|CP_AVOID|CP_HAS_ROUTE, 128 );
1945 if ( cp == -1 )
1946 {//okay give up on the avoid
1947 cp = NPC_FindCombatPoint( NPC->currentOrigin, dangerPoint, NPC->currentOrigin, CP_COVER|CP_HAS_ROUTE, 128 );
1948 if ( cp == -1 )
1949 {//okay give up on the cover
1950 cp = NPC_FindCombatPoint( NPC->currentOrigin, dangerPoint, NPC->currentOrigin, CP_HAS_ROUTE, 128 );
1951 }
1952 }
1953 }
1954
1955 //see if we got a valid one
1956 if ( cp != -1 )
1957 {//found a combat point
1958 NPC_SetCombatPoint( cp );
1959 NPC_SetMoveGoal( NPC, level.combatPoints[cp].origin, 8, qtrue, cp );
1960 }
1961 else
1962 {//couldn't find a place to hide
1963 //FIXME: re-implement the old BS_FLEE behavior of following any the waypoint edge
1964 // that leads away from the danger point.
1965 NPC_SetMoveGoal( NPC, NPC->currentOrigin, 0/*goalRadius*/, qtrue, cp );

Callers 5

NPC_BSCivilian_DefaultFunction · 0.70
G_CheckForDangerFunction · 0.70
G_StartFleeFunction · 0.70
NPC_RunBehaviorFunction · 0.70
ST_CommanderFunction · 0.70

Calls 9

NPC_JawaFleeSoundFunction · 0.85
Q_irandFunction · 0.85
Q3_TaskIDPendingFunction · 0.70
G_ActivateBehaviorFunction · 0.70
G_SetEnemyFunction · 0.70
NPC_FindCombatPointFunction · 0.70
NPC_SetCombatPointFunction · 0.70
NPC_SetMoveGoalFunction · 0.70
TIMER_SetFunction · 0.70

Tested by

no test coverage detected