Beispiel #1
0
void NPC_BSSearch (void)
{
	NPC_CheckEnemy(qtrue, qfalse);
	//Look for enemies, if find one:
	if ( NPC->enemy )
	{
		if( NPCInfo->tempBehavior == BS_SEARCH )
		{//if tempbehavior, set tempbehavior to default
			NPCInfo->tempBehavior = BS_DEFAULT;
		}
		else
		{//if bState, change to run and shoot
			NPCInfo->behaviorState = BS_HUNT_AND_KILL;
			NPC_BSRunAndShoot();
		}
		return;
	}

	//FIXME: what if our goalEntity is not NULL and NOT our tempGoal - they must
	//want us to do something else?  If tempBehavior, just default, else set
	//to run and shoot...?

	//FIXME: Reimplement

	if ( !NPCInfo->investigateDebounceTime )
	{//On our way to a tempGoal
		float	minGoalReachedDistSquared = 32*32;
		vec3_t	vec;

		//Keep moving toward our tempGoal
		NPCInfo->goalEntity = NPCInfo->tempGoal;

		VectorSubtract ( NPCInfo->tempGoal->currentOrigin, NPC->currentOrigin, vec);
		if ( vec[2] < 24 )
		{
			vec[2] = 0;
		}

		if ( NPCInfo->tempGoal->waypoint != WAYPOINT_NONE )
		{
			/*
			//FIXME: can't get the radius...
			float	wpRadSq = waypoints[NPCInfo->tempGoal->waypoint].radius * waypoints[NPCInfo->tempGoal->waypoint].radius;
			if ( minGoalReachedDistSquared > wpRadSq )
			{
				minGoalReachedDistSquared = wpRadSq;
			}
			*/

			minGoalReachedDistSquared = 32*32;//12*12;
		}

		if ( VectorLengthSquared( vec ) < minGoalReachedDistSquared )
		{
			//Close enough, just got there
			NPC->waypoint = NAV_FindClosestWaypointForEnt( NPC, WAYPOINT_NONE );

			if ( ( NPCInfo->homeWp == WAYPOINT_NONE ) || ( NPC->waypoint == WAYPOINT_NONE ) )
			{
				//Heading for or at an invalid waypoint, get out of this bState
				if( NPCInfo->tempBehavior == BS_SEARCH )
				{//if tempbehavior, set tempbehavior to default
					NPCInfo->tempBehavior = BS_DEFAULT;
				}
				else
				{//if bState, change to stand guard
					NPCInfo->behaviorState = BS_STAND_GUARD;
					NPC_BSRunAndShoot();
				}
				return;
			}

			if ( NPC->waypoint == NPCInfo->homeWp )
			{
				//Just Reached our homeWp, if this is the first time, run your lostenemyscript
				if ( NPCInfo->aiFlags & NPCAI_ENROUTE_TO_HOMEWP )
				{
					NPCInfo->aiFlags &= ~NPCAI_ENROUTE_TO_HOMEWP;
					G_ActivateBehavior( NPC, BSET_LOSTENEMY );
				}

			}

			//gi.Printf("Got there.\n");
			//gi.Printf("Looking...");
			if( !Q_irand(0, 1) )
			{
				NPC_SetAnim(NPC, SETANIM_BOTH, BOTH_GUARD_LOOKAROUND1, SETANIM_FLAG_NORMAL);
			}
			else
			{
				NPC_SetAnim(NPC, SETANIM_BOTH, BOTH_GUARD_IDLE1, SETANIM_FLAG_NORMAL);
			}
			NPCInfo->investigateDebounceTime = level.time + Q_irand(3000, 10000);
		}
		else
		{
			NPC_MoveToGoal( qtrue );
		}
	}
	else
	{
		//We're there
		if ( NPCInfo->investigateDebounceTime > level.time )
		{
			//Still waiting around for a bit
			//Turn angles every now and then to look around
			if ( NPCInfo->tempGoal->waypoint != WAYPOINT_NONE )
			{
				if ( !Q_irand( 0, 30 ) )
				{
					int	numEdges = navigator.GetNodeNumEdges( NPCInfo->tempGoal->waypoint );

					if ( numEdges != WAYPOINT_NONE )
					{
						int branchNum = Q_irand( 0, numEdges - 1 );

						vec3_t	branchPos, lookDir;

						int nextWp = navigator.GetNodeEdge( NPCInfo->tempGoal->waypoint, branchNum );
						navigator.GetNodePosition( nextWp, branchPos );

						VectorSubtract( branchPos, NPCInfo->tempGoal->currentOrigin, lookDir );
						NPCInfo->desiredYaw = AngleNormalize360( vectoyaw( lookDir ) + Q_flrand( -45, 45 ) );
					}

					//pick an angle +-45 degrees off of the dir of a random branch
					//from NPCInfo->tempGoal->waypoint
					//int branch = Q_irand( 0, (waypoints[NPCInfo->tempGoal->waypoint].numNeighbors - 1) );
					//int	nextWp = waypoints[NPCInfo->tempGoal->waypoint].nextWaypoint[branch][NPCInfo->stats.moveType];
					//vec3_t	lookDir;

					//VectorSubtract( waypoints[nextWp].origin, NPCInfo->tempGoal->currentOrigin, lookDir );
					//Look in that direction +- 45 degrees
					//NPCInfo->desiredYaw = AngleNormalize360( vectoyaw( lookDir ) + Q_flrand( -45, 45 ) );
				}
			}
			//gi.Printf(".");
		}
		else
		{//Just finished waiting
			NPC->waypoint = NAV_FindClosestWaypointForEnt( NPC, WAYPOINT_NONE );
			
			if ( NPC->waypoint == NPCInfo->homeWp )
			{
				int	numEdges = navigator.GetNodeNumEdges( NPCInfo->tempGoal->waypoint );

				if ( numEdges != WAYPOINT_NONE )
				{
					int branchNum = Q_irand( 0, numEdges - 1 );

					int nextWp = navigator.GetNodeEdge( NPCInfo->homeWp, branchNum );
					navigator.GetNodePosition( nextWp, NPCInfo->tempGoal->currentOrigin );
					NPCInfo->tempGoal->waypoint = nextWp;
				}

				/*
				//Pick a random branch
				int branch = Q_irand( 0, (waypoints[NPCInfo->homeWp].numNeighbors - 1) );
				int	nextWp = waypoints[NPCInfo->homeWp].nextWaypoint[branch][NPCInfo->stats.moveType];

				VectorCopy( waypoints[nextWp].origin, NPCInfo->tempGoal->currentOrigin );
				NPCInfo->tempGoal->waypoint = nextWp;
				//gi.Printf("\nHeading for wp %d...\n", waypoints[NPCInfo->homeWp].nextWaypoint[branch][NPCInfo->stats.moveType]);
				*/
			}
			else
			{//At a branch, so return home
				navigator.GetNodePosition( NPCInfo->homeWp, NPCInfo->tempGoal->currentOrigin );
				NPCInfo->tempGoal->waypoint = NPCInfo->homeWp;
				/*
				VectorCopy( waypoints[NPCInfo->homeWp].origin, NPCInfo->tempGoal->currentOrigin );
				NPCInfo->tempGoal->waypoint = NPCInfo->homeWp;
				//gi.Printf("\nHeading for wp %d...\n", NPCInfo->homeWp);
				*/
			}

			NPCInfo->investigateDebounceTime = 0;
			//Start moving toward our tempGoal
			NPCInfo->goalEntity = NPCInfo->tempGoal;
			NPC_MoveToGoal( qtrue );
		}
	}

	NPC_UpdateAngles( qtrue, qtrue );
}
Beispiel #2
0
void NPC_BehaviorSet_Default( int bState )
{
	switch( bState )
	{
	case BS_WAIT://Do abolutely nothing
		NPC_BSWait ();
		break;

	case BS_IDLE://Stand around, move if have a goal, update angles
		NPC_BSIdle ();
		break;
	
	case BS_ROAM://Roam around, collect stuff
		NPC_BSRoam ();
		break;
	
	case BS_WALK://Walk toward their goals
		NPC_BSWalk ();
		break;

	case BS_CROUCH://Crouch-Walk toward their goals
		NPC_BSCrouch ();
		break;

	case BS_RUN://Run toward their goals
		NPC_BSRun ();
		break;

	case BS_STAND_AND_SHOOT://Stay in one spot and shoot- duck when neccesary
		NPC_BSStandAndShoot ();
		break;

	case BS_STAND_GUARD://Wait around for an enemy
		NPC_BSStandGuard ();
		break;
	
	case BS_PATROL://Follow a path, looking for enemies
		NPC_BSPatrol ();
		break;
	
	case BS_HUNT_AND_KILL://Track down enemies and kill them
		NPC_BSHuntAndKill ();
		break;
	
	case BS_EVADE://Run from enemies
		NPC_BSEvade ();
		break;
	
	case BS_EVADE_AND_SHOOT://Run from enemies, shoot them if they hit you
		NPC_BSEvadeAndShoot ();
		break;
	
	case BS_RUN_AND_SHOOT://Run to your goal and shoot enemy when possible
		NPC_BSRunAndShoot ();
		break;
	
	case BS_DEFEND://Defend an entity or spot?
		NPC_BSDefend ();
		break;
	
	case BS_COMBAT://Attack, evade, use cover, move about, etc.  Full combat AI - id Bot code
		NPC_BSCombat ();
		break;

	case BS_MEDIC://Go for lowest health buddy, hide and heal him.
		NPC_BSMedic ();
		break;

	case BS_MEDIC_COMBAT:	//27: Run to and heal people to a certain level then go back to hiding spot
		NPC_BSMedicCombat ();
		break;
	
	case BS_MEDIC_HIDE:		//28: Stay in hiding spot and wait for others to come to you
		NPC_BSMedicHide ();
		break;

	case BS_TAKECOVER://Find nearest cover from enemies
		NPC_BSTakeCover ();
		break;

	case BS_GET_AMMO://Go get some ammo
		NPC_BSGetAmmo ();
		break;

	case BS_ADVANCE_FIGHT://head toward captureGoal, shoot anything that gets in the way
		NPC_BSAdvanceFight ();
		break;

	case BS_FACE://Face a direction
		NPC_BSFace ();
		break;

	case BS_FORMATION://Maintain a formation
		NPC_BSFormation ();
		break;

	case BS_MOVE:
		NPC_BSMove();
		break;

	case BS_WAITHEAL:		//24: Do nothing until health > 75
		NPC_BSWaitHeal();
		break;

	case BS_SHOOT:			//25: shoot straight ahead
		NPC_BSShoot();
		break;

	case BS_SNIPER:			//26: wait for a good shot
		NPC_BSSniper();
		break;

	case BS_POINT_AND_SHOOT:
		NPC_BSPointShoot(qtrue);
		break;

	case BS_FACE_ENEMY:
		NPC_BSPointShoot(qfalse);
		break;

	case BS_INVESTIGATE:	//29:
		NPC_BSInvestigate();
		break;

	case BS_SLEEP://Follow a path, looking for enemies
		NPC_BSSleep ();
		break;

	case BS_SAY://36: Turn to sayTarg, use talk anim, say your sayString (look up string in your sounds table), exit tempBState when sound finished (anim of mouth should be timed to length of sound as well)
		NPC_BSSay ();
		break;

	case BS_AIM://37: Turn head and torso to facing, keep feet in place if you can
		NPC_BSFace ();
		break;

	case BS_LOOK://38: Turn head only to facing, keep torso and head in place if you can
		NPC_BSFace ();
		break;

	case BS_POINT_COMBAT://39: Head toward closest empty point_combat and shoot from there
		NPC_BSPointCombat ();
		break;

	case BS_FOLLOW_LEADER://# 40: Follow your leader and shoot any enemies you come across
		NPC_BSFollowLeader();
		break;

	case BS_JUMP:			//41: Face navgoal and jump to it.
		NPC_BSJump();
		break;

	case BS_REMOVE:
		NPC_BSRemove();
		break;

	case BS_SEARCH:			//# 43: Using current waypoint as a base, search the immediate branches of waypoints for enemies
		NPC_BSSearch();
		break;

	case BS_FLY:			//# 44: Moves around without gravity
		NPC_BSFly();
		break;

	case BS_NOCLIP:
		NPC_BSNoClip();
		break;

	case BS_WANDER:			//# 46: Wander down random waypoint paths
		NPC_BSWander();
		break;

	case BS_FACE_LEADER://# 47: Keep facing the leader
		NPC_BSFaceLeader();
		break;

	default:
	case BS_DEFAULT://whatever
		NPC_BSIdle ();
		break;
	}
}