Ejemplo n.º 1
0
/*-------------------------------------------------------------------
    Procedure   :   Exogenon Sweep
    Input       :   ENEMY * Enemy
    Output      :   Nothing
-------------------------------------------------------------------*/
void    ExogenonFireLeftRight( ENEMY * Enemy )
{
    VECTOR  FireDir;
    VECTOR  TempUpVector;
    VECTOR  TempOffset;

    ApplyMatrix( &Enemy->Object.Mat, &SlideUp, &TempUpVector );

    ApplyMatrix( &Enemy->Object.Mat, &SlideLeft, &FireDir );
    // Fire a homing missile left
    TempOffset.x = FireDir.x * ( 1200.0F * GLOBAL_SCALE );
    TempOffset.y = FireDir.y * ( 1200.0F * GLOBAL_SCALE );
    TempOffset.z = FireDir.z * ( 1200.0F * GLOBAL_SCALE );

    InitOneSecBull( OWNER_ENEMY, Enemy->Index, ++Enemy->BulletID, Enemy->Object.Group,
        &Enemy->Object.Pos, &TempOffset, &FireDir, &TempUpVector,
        &TempOffset, ENEMYBLUEHOMINGMISSILE, FALSE );

    ApplyMatrix( &Enemy->Object.Mat, &SlideRight, &FireDir );
    TempOffset.x = FireDir.x * ( 1200.0F * GLOBAL_SCALE );
    TempOffset.y = FireDir.y * ( 1200.0F * GLOBAL_SCALE );
    TempOffset.z = FireDir.z * ( 1200.0F * GLOBAL_SCALE );
    // Fire a homing missile right
    InitOneSecBull( OWNER_ENEMY, Enemy->Index, ++Enemy->BulletID, Enemy->Object.Group,
        &Enemy->Object.Pos, &TempOffset, &FireDir, &TempUpVector,
        &TempOffset, ENEMYBLUEHOMINGMISSILE, FALSE );
}
Ejemplo n.º 2
0
/*-------------------------------------------------------------------
    Procedure   :   Exogenon Move Down
    Input       :   ENEMY * Enemy
    Output      :   Nothing
-------------------------------------------------------------------*/
void AI_EXOGENON_MOVEDOWN( register ENEMY * Enemy )
{
    VECTOR  TempUpVector;
    VECTOR  FireDir;

    BOOL    ClearLos = TRUE;
    VECTOR  TempOffset = { 0.0F, 0.0F, 180.0F };
    ExogenonAim( Enemy );

    Enemy->Object.AnimSpeed = 1.5F;
    if( Enemy->Object.Animating )
    {
        return;
    }

    if( !(ClearLos = AI_ClearLOSNonZeroNonObject( &Enemy->Object.Pos,Enemy->Object.Group, &Ships[WhoIAm].Object.Pos , SHIP_RADIUS))
        || (Random_Range(10) > 5 ) )
    {
        Enemy->Object.AI_Mode = AIMODE_EXOGENON_MOVEUP;
        SetCurAnimSeq( EXOGENONSEQ_Move_Up, &Enemy->Object );

        if( ClearLos )
        {
            ApplyMatrix( &Enemy->Object.Mat, &SlideUp, &TempUpVector );
            ApplyMatrix( &Enemy->Object.Mat, &Forward, &FireDir );
            // Fire a homing missile Forward...
            InitOneSecBull( OWNER_ENEMY, Enemy->Index, ++Enemy->BulletID, Enemy->Object.Group,
                &Enemy->Object.Pos, &TempOffset, &FireDir, &TempUpVector,
                &TempOffset, ENEMYBLUEHOMINGMISSILE, FALSE );
        }
        ExogenonFireLeftRight( Enemy );
    }else{
        Enemy->Object.AI_Mode = AIMODE_EXOGENON_SCAN;
        SetCurAnimSeq( EXOGENONSEQ_Idle, &Enemy->Object );
    }
}
Ejemplo n.º 3
0
/*===================================================================
	Procedure	:	Update an Enemies Guns...
	Input		:	ENEMY * Enemy
	Output		:	Nothing
===================================================================*/
void AI_UPDATEGUNS( register ENEMY * Enemy )
{
	OBJECT * TObject;
	GUNOBJECT * GObject;
	VECTOR		TempVector;
	VECTOR		TempUpVector;
	VECTOR		TempOffset = { 0.0F, 0.0F, 0.0F };
	VECTOR		NewPos;
	VECTOR		FireOffset;
	FIREPOS *	FirePosPnt;
	VECTOR		AimOffset;
	u_int16_t		i;
	BYTE		Weapon;

	TObject = (OBJECT*) Enemy->TShip;

	if( !TObject || TObject->Mode != NORMAL_MODE )
		return;
	
	GObject = Enemy->Object.FirstGun;

	
	while( GObject )
	{
		
//		if( TObject && ( (Enemy->AIFlags & AI_ICANSEEPLAYER) || (Enemy->Object.ControlType == ENEMY_CONTROLTYPE_TURRET_AI) || (Enemy->Object.ControlType == ENEMY_CONTROLTYPE_SPLINE) ) )
		if( TObject && ( (Enemy->AIFlags & AI_ICANSEEPLAYER) || (Enemy->Object.ControlType == ENEMY_CONTROLTYPE_SPLINE) ) )
		{
			FirePosPnt = EnemyTypes[Enemy->Type].GunFirePoints[GObject->GunNum>>1];
			ApplyMatrix( &GObject->Mat , &FirePosPnt->Points[GObject->FirePosCount] , &FireOffset );
			FireOffset.x += GObject->FirePos.x;
			FireOffset.y += GObject->FirePos.y;
			FireOffset.z += GObject->FirePos.z;
			FireOffset.x -= Enemy->Object.Pos.x;
			FireOffset.y -= Enemy->Object.Pos.y;
			FireOffset.z -= Enemy->Object.Pos.z;
			
			ApplyMatrix( &GObject->Mat, EnemyTypes[ Enemy->Type ].GunAimPos[GObject->GunNum>>1], &AimOffset );
			AimOffset.x += Enemy->Object.Pos.x;
			AimOffset.y += Enemy->Object.Pos.y;
			AimOffset.z += Enemy->Object.Pos.z;
			
			if( !GunTypes[GObject->Type].BurstMasterCount )
			{
				// Normal gun that just fires when it can..
				
				if( GunTypes[GObject->Type].PrimarySecondary )
				{
					AI_LookAhead( EnemyTypes[Enemy->Type].Behave.Anticipate_Move ,&AimOffset, TObject , &NewPos , SecondaryWeaponAttribs[GunTypes[GObject->Type].WeaponType].Speed);
				}else{
					AI_LookAhead( EnemyTypes[Enemy->Type].Behave.Anticipate_Move ,&AimOffset, TObject , &NewPos , PrimaryWeaponAttribs[GunTypes[GObject->Type].WeaponType].Speed[GunTypes[GObject->Type].PowerLevel]);
				}
				
				
				AI_AimAtTarget( &GObject->InvMat , &AimOffset, &NewPos );
				GObject->AIMoveFlags |= AimData.Flags;
				GObject->AI_Angle = AimData.Angle;

				if( GObject->Type == GUN_MetaTankMain )
				{
					if( (GObject->ReloadTime <= (0.5F*60.0F) ) && !Enemy->Object.Animating )
					{
						SetCurAnimSeq( 0, &Enemy->Object );
					}
				}
				if( GObject->ReloadTime <= 0.0F && ( (( ( GObject->AI_Angle.x < GunTypes[GObject->Type].BurstAngle && GObject->AI_Angle.x > -GunTypes[GObject->Type].BurstAngle )
					&& ( GObject->AI_Angle.y < GunTypes[GObject->Type].BurstAngle && GObject->AI_Angle.y > -GunTypes[GObject->Type].BurstAngle ) )  ) || GObject->Type == GUN_MetaTankMain ) )
				{
					ApplyMatrix( &GObject->Mat, &Forward, &TempVector );
					ApplyMatrix( &GObject->Mat, &SlideUp, &TempUpVector );
					
					if( !(Enemy->Object.Flags & SHIP_Scattered ) && (!GunTypes[GObject->Type].Range || ( DistanceVector2Vector( &TObject->Pos , &Enemy->Object.Pos) < GunTypes[GObject->Type].Range ) ))
					{

						if(Enemy->Object.ControlType == ENEMY_CONTROLTYPE_TURRET_AI)
						{
							if( !Enemy->Object.Animating && (Enemy->Type != ENEMY_MissileTurret) )
							{
								SetCurAnimSeq( TURRETSEQ_Fire, &Enemy->Object );
							}
						}
						
						if( GunTypes[GObject->Type].PrimarySecondary )
						{
							InitOneSecBull( OWNER_ENEMY, Enemy->Index, ++Enemy->BulletID, Enemy->Object.Group,
								&Enemy->Object.Pos, &FireOffset, &TempVector, &TempUpVector,
								&TempOffset, GunTypes[GObject->Type].WeaponType, false );
							
						}else{
							Weapon = BodgePrimaryWeapon( GunTypes[GObject->Type].WeaponType, Enemy->PickupHeld );

							i = EnemyFirePrimary( OWNER_ENEMY, Enemy->Index, ++Enemy->BulletID, Weapon,
										Enemy->Object.Group, &Enemy->Object.Pos, &FireOffset, &TempVector, &TempUpVector,
										GunTypes[GObject->Type].PowerLevel, (GunTypes[GObject->Type].PowerLevel +1) * 33.0F, false, GObject );
							if( i != (u_int16_t) -1 )
							{
								PrimBulls[i].FirePoint = GObject->FirePosCount;
							}
						}
						GObject->FirePosCount++;
						if( GObject->FirePosCount >= FirePosPnt->NumPoints )
							GObject->FirePosCount = 0;
						
						
						GObject->ReloadTime =GunTypes[GObject->Type].ReloadTime;
					}
				}
			}else{
				// A Gun That Does a Burst...
				if( GObject->BurstCount )
				{
					
					if( GunTypes[GObject->Type].PrimarySecondary )
					{
						AI_LookAhead( EnemyTypes[Enemy->Type].Behave.Anticipate_Move ,&AimOffset, TObject , &NewPos , SecondaryWeaponAttribs[GunTypes[GObject->Type].WeaponType].Speed);
					}else{
						AI_LookAhead( EnemyTypes[Enemy->Type].Behave.Anticipate_Move ,&AimOffset, TObject , &NewPos , PrimaryWeaponAttribs[GunTypes[GObject->Type].WeaponType].Speed[GunTypes[GObject->Type].PowerLevel]);
					}
					AI_AimAtTarget( &GObject->InvMat , &AimOffset, &NewPos );
					GObject->AIMoveFlags |= AimData.Flags;
					GObject->AIMoveFlags &= ~(AI_CONTROL_TURNLEFT + AI_CONTROL_TURNRIGHT );
					GObject->AI_Angle = AimData.Angle;
					if( GObject->BurstStartSign	< 0.0F )
					{
						GObject->AIMoveFlags |= AI_CONTROL_TURNLEFT;
					}else{
						GObject->AIMoveFlags |= AI_CONTROL_TURNRIGHT;
					}
					if( !(Enemy->Object.Flags & SHIP_Scattered ) &&GObject->ReloadTime <= 0.0F )
					{
						ApplyMatrix( &GObject->Mat, &Forward, &TempVector );
						ApplyMatrix( &GObject->Mat, &SlideUp, &TempUpVector );
						
						if(Enemy->Object.ControlType == ENEMY_CONTROLTYPE_TURRET_AI)
						{
							if( !Enemy->Object.Animating && (Enemy->Type != ENEMY_MissileTurret) )
							{
								SetCurAnimSeq( TURRETSEQ_Fire, &Enemy->Object );
							}
						}

						if( GunTypes[GObject->Type].PrimarySecondary )
						{
							InitOneSecBull( OWNER_ENEMY, Enemy->Index, ++Enemy->BulletID, Enemy->Object.Group,
								&Enemy->Object.Pos, &FireOffset, &TempVector, &TempUpVector,
								&TempOffset, GunTypes[GObject->Type].WeaponType, false );
							
						}else{
							Weapon = BodgePrimaryWeapon( GunTypes[GObject->Type].WeaponType, Enemy->PickupHeld );

							i = EnemyFirePrimary( OWNER_ENEMY, Enemy->Index, ++Enemy->BulletID, Weapon,
										Enemy->Object.Group, &Enemy->Object.Pos, &FireOffset, &TempVector, &TempUpVector,
										GunTypes[GObject->Type].PowerLevel, (GunTypes[GObject->Type].PowerLevel +1) * 33.0F, false, GObject );
							if( i != (u_int16_t) -1 )
							{
								PrimBulls[i].FirePoint = GObject->FirePosCount;
							}
						}
						
						GObject->FirePosCount++;
						if( GObject->FirePosCount >= FirePosPnt->NumPoints )
							GObject->FirePosCount = 0;
						
						GObject->ReloadTime = GunTypes[GObject->Type].ReloadTime;
						GObject->BurstCount--;
					}
				}
				
				if( !GObject->BurstCount && GunTypes[GObject->Type].BurstMasterCount )
				{
					
					if( GunTypes[GObject->Type].PrimarySecondary )
					{
						AI_LookAhead( EnemyTypes[Enemy->Type].Behave.Anticipate_Move ,&AimOffset, TObject , &NewPos , SecondaryWeaponAttribs[GunTypes[GObject->Type].WeaponType].Speed);
					}else{
						AI_LookAhead( EnemyTypes[Enemy->Type].Behave.Anticipate_Move ,&AimOffset, TObject , &NewPos , PrimaryWeaponAttribs[GunTypes[GObject->Type].WeaponType].Speed[GunTypes[GObject->Type].PowerLevel]);
					}
					
					AI_AimAtTarget( &GObject->InvMat , &AimOffset, &NewPos );
					GObject->AIMoveFlags |= AimData.Flags;
					GObject->AI_Angle = AimData.Angle;
					if( GObject->BurstTime == 0.0F )
					{
						if( (GObject->AI_Angle.y <= GunTypes[GObject->Type].BurstAngle) && (GObject->AI_Angle.y >= -GunTypes[GObject->Type].BurstAngle) )
						{
							GObject->BurstCount = GunTypes[GObject->Type].BurstMasterCount;
							GObject->BurstTime = GunTypes[GObject->Type].BurstMasterTime;
							GObject->BurstStartSign = GObject->AI_Angle.y;
						}
					}
				}
				
			}
		}
		GObject = GObject->Next;
	}
Ejemplo n.º 4
0
/*===================================================================
	Procedure	:	AIR Follow Path
	Input		:	ENEMY * Enemy
	Output		:	Nothing
===================================================================*/
void AI_AIR_FOLLOWPATH( register ENEMY * Enemy )
{
	OBJECT * SObject;
	NODE * TNode;
	VECTOR	TempVector = { 0.0F , 0.0F , 0.0F };
	VECTOR	TempUpVector;
	VECTOR	TempForwardVector;
	u_int16_t	MineIndex;

	SObject = &Enemy->Object;

	AI_THINK( Enemy , false , false );

	if( !(Enemy->AIFlags & AI_ANYPLAYERINRANGE) )
		return;

	if( EnemyTypes[Enemy->Type].Behave.Flags & AI_BEHAVIOUR_ATTACK_ONSITE )
	{
		Tinfo->Flags = 0;
		SET_TARGET_PLAYERS;
		AI_GetDistToNearestTarget( Enemy );
		Enemy->TShip = Tinfo->TObject;
	}

	if( Enemy->TShip && ( EnemyTypes[Enemy->Type].Behave.Flags & AI_BEHAVIOUR_ATTACK_ONSITE ) )
	{
		if( Enemy->AIFlags&AI_ICANSEEPLAYER )
		{
			AI_SetDOGFIGHT( Enemy );
			return;
		}else if( Enemy->AIFlags&AI_ICANHEARPLAYER )
		{
			AI_SetMOVETOTARGET( Enemy );
			return;
		}
	}


	if( (Enemy->AIFlags&AI_MINEAVOID) && (EnemyTypes[Enemy->Type].Behave.Flags&AI_BEHAVIOUR_ATTACKMINES) )
	{
		Enemy->AvoidTimer = 0.0F;
		Enemy->AvoidType = 0;
		AI_SetKILLMINE( Enemy );
		return;
	}
	
	
	if( TNode = (NODE*) Enemy->TNode )
	{
		if( !(Enemy->Object.NodeNetwork&TNode->NetMask) )
		{
			// The node Im Targetting is not on my network...Better try and find one...
			if( Enemy->Object.LastNearestNode )
			{
				TNode = (NODE*) ( Enemy->TNode = WhichNode( 1 , Enemy->Object.NearestNode , Enemy->Object.LastNearestNode ) );
				
				if( !TNode )
				{
					AI_SetSCAN( Enemy );
					return;
				}
				
				if( !AI_ClearLOSNonZero( &Enemy->Object, &TNode->Pos , EnemyTypes[Enemy->Type].Radius  ) )
				{
					// couldnt find a node that will take me to my target so go back to my nearest...
					TNode = (NODE*) ( Enemy->TNode = Enemy->Object.NearestNode );
				}
			}
		}

		AI_AimAtTarget( &Enemy->Object.InvMat , &Enemy->Object.Pos, &TNode->Pos );
		Enemy->AI_Angle = AimData.Angle;

		if( !( EnemyTypes[Enemy->Type].Behave.Flags & AI_BEHAVIOUR_ICANTPITCH ) )
		{
			Enemy->AIMoveFlags |= AimData.Flags;
			if( ( EnemyTypes[Enemy->Type].Behave.Flags & AI_BEHAVIOUR_DONTSTOPANDTURN ) || ( (AimData.Angle.x < 15.0F) && (AimData.Angle.x > -15.0F) &&	(AimData.Angle.y < 15.0F) && (AimData.Angle.y > -15.0F) ) )
				Enemy->AIMoveFlags |= AI_CONTROL_FORWARD;
		}else{
			//This enemy cant look up or down so it has to move up and down to compensate....
			if( ( EnemyTypes[Enemy->Type].Behave.Flags & AI_BEHAVIOUR_DONTSTOPANDTURN ) || ( (AimData.Angle.x < 15.0F) && (AimData.Angle.x > -15.0F) &&	(AimData.Angle.y < 15.0F) && (AimData.Angle.y > -15.0F) && (AimData.Angle.y < 3.0F) && (AimData.Angle.y > -3.0F)) )
				Enemy->AIMoveFlags |= AI_CONTROL_FORWARD;
			Enemy->AIMoveFlags |= ( AimData.Flags & ( AI_CONTROL_TURNLEFT + AI_CONTROL_TURNRIGHT ) );
			if( AimData.Flags & AI_CONTROL_TURNUP )
			{
				Enemy->AIMoveFlags |=  AI_CONTROL_UP;
			}else if( AimData.Flags & AI_CONTROL_TURNDOWN )
			{
				Enemy->AIMoveFlags |=  AI_CONTROL_DOWN;
			}

		}

		
		if( DistanceVector2Vector( &Enemy->Object.Pos , &TNode->Pos ) < 64.0F )
		{
			Tinfo->Flags = 0;
			SET_TARGET_NODES;
			AI_GetDistToNearestTarget( Enemy );
			Enemy->TNode = Tinfo->TObject;
		}
		// MINES........
		if(	(Enemy->AIFlags&AI_MINEAVOID) && (EnemyTypes[Enemy->Type].Behave.Flags&AI_BEHAVIOUR_AVOIDMINES) )
		{
			// A Mine is close....And I can See it...
			TNode = ChooseAlternateNode( Enemy->Object.NodeNetwork , Enemy->Object.NearestNode , Enemy->TNode );
			Enemy->TNode = TNode;
			Enemy->AIFlags &= ~AI_MINEAVOID;
			Enemy->AIMoveFlags &= ~AI_CONTROL_FORWARD;
		}

		if( !Enemy->AvoidTimer)
		{
			TNode = Enemy->Object.NearestNode;
			if( (TNode->Flags&NODE_DROPMINES) && (EnemyTypes[Enemy->Type].Behave.Flags&AI_BEHAVIOUR_DROPMINES) ) 
			{
				Enemy->SecondaryFireTimer -= framelag;
				if( Enemy->SecondaryFireTimer < 0.0F )
					Enemy->SecondaryFireTimer = 0.0F;
				
				if( (Enemy->SecondaryFireTimer == 0.0F) )
				{
					Enemy->SecondaryFireTimer = EnemyTypes[Enemy->Type].SecondaryFireRate + (float) Random_Range( (u_int16_t) EnemyTypes[Enemy->Type].SecondaryFireRate );
					//This is where we Lay Mines....
					
					ApplyMatrix( &Enemy->Object.Mat, &Forward, &TempForwardVector );
					ApplyMatrix( &Enemy->Object.Mat, &SlideUp, &TempUpVector );
					
					MineIndex = InitOneSecBull( OWNER_ENEMY, Enemy->Index, ++Enemy->BulletID, Enemy->Object.Group,
								&Enemy->Object.Pos, &TempVector, &TempForwardVector, &TempUpVector,
								&TempVector, EnemyTypes[Enemy->Type].SecondaryWeaponType, false );

					if( MineIndex != (u_int16_t) -1 )
					{
						SecBulls[MineIndex].LifeSpan = 10.0F * 60.0F;
					}
				}
			}
		}
	}else{
		// If no target node has been found yet go to the nearest one...
		Enemy->TNode = Enemy->Object.NearestNode;
	}
}