Fulqrum Publishing Home   |   Register   |   Today Posts   |   Members   |   UserCP   |   Calendar   |   Search   |   FAQ

Go Back   Official Fulqrum Publishing forum > Fulqrum Publishing > IL-2 Sturmovik: Cliffs of Dover > FMB, Mission & Campaign builder Discussions

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #1  
Old 11-01-2011, 02:38 AM
hc_wolf hc_wolf is offline
Approved Member
 
Join Date: Jul 2010
Posts: 439
Default Use OnTickTime to re-evaluate AI air group waypoints

Hi,

I have good coding where AI planes on spawn will locate an enemy location and fly to it and attack. The problem is. If the enemy is a plane. By the time the AI reach their waypoint where they are to attack. the enemey planes have of course flowen away.

What is the best code to insert that will have the AI check their current waypoint to reset if the target has moved to new location or if there is a closer enemy they decide to attack?





Code:
    public override void OnTickGame()      
    {
        base.OnTickGame();    
		if (koefDiskr == 0) koefDiskr = 640;     
        if (Time.tickCounter() % koefDiskr == 0)
        AiActor result = null;
        AiAirGroup[] enemyAG = GamePlay.gpAirGroups((myGroup.Army() == 1) ? 2 : 1);
        Point3d attackerPos = myGroup.Pos();
        if (enemyAG != null)
        {
			foreach (AiAirGroup eGroup in enemyAG)
			{
				if (CurTankGroups.Count != 0)
				{ 	
                  int i = (int)(Time.tickCounter() / koefDiskr) % CurTankGroups.Count;  
					{
                    if ((CurTankGroups[i].TankGroup != null) && (CurTankGroups[i].cur_rp != null))   
                        if ((CurTankGroups[i].cur_rp.State == RecalcPathState.SUCCESS) ) 
                        {                            
                            CurTankGroups[i].TankGroup.SetWay((CurTankGroups[i].cur_rp.Path)); 
                            CurTankGroups[i].cur_rp = null;      
                        }
					}
				}
				if (eGroup.isAircraftType(AircraftType.Bomber) || eGroup.isAircraftType(AircraftType.DiveBomber))
                {
                    if (result != null)
                    {
                        if (result.Pos().distance(ref attackerPos) > eGroup.Pos().distance(ref attackerPos))
                            result = eGroup;
                    }
                    else result = eGroup;
                }                
            }
            if (result == null)
            {
                foreach (AiAirGroup eGroup in enemyAG)
                {                    
                    if (result != null)
                    {
                       if (result.Pos().distance(ref attackerPos) > eGroup.Pos().distance(ref attackerPos))
                           result = eGroup;
                    }
                    else result = eGroup;                    
                }
            }
        }
        return result;
    }


Below are the two Waypoints I want the AI to check every minute.


Code:
  public override void OnMissionLoaded(int missionNumber)
    {
        base.OnMissionLoaded(missionNumber);
        MissionsCount++;           
    }

    internal AiActor FindGroundTarget(int army, Point3d attackerPos)
    {
        AiActor result = null;        
        AiGroundGroup[] enemyGG = GamePlay.gpGroundGroups((army == 1) ? 2 : 1);
        if (enemyGG != null)
        {
            result = enemyGG[0];
            for (int i = 1; i < enemyGG.Length; i++)
            {
                if (enemyGG[i] != null)
                    if (result.Pos().distance(ref attackerPos) > enemyGG[i].Pos().distance(ref attackerPos)) 
                        { result = enemyGG[i]; }
            }
        }
        return result;
    }

    internal AiActor FindAirTarget(AiAirGroup myGroup)
    {
        AiActor result = null;
        AiAirGroup[] enemyAG = GamePlay.gpAirGroups((myGroup.Army() == 1) ? 2 : 1);
        Point3d attackerPos = myGroup.Pos();
        if (enemyAG != null)
        {
            foreach (AiAirGroup eGroup in enemyAG)
            {
             	   if (eGroup.isAircraftType(AircraftType.Bomber) || eGroup.isAircraftType(AircraftType.DiveBomber))
                {
                    if (result != null)
                    {
                        if (result.Pos().distance(ref attackerPos) > eGroup.Pos().distance(ref attackerPos))
                            result = eGroup;
                    }
                    else result = eGroup;
                }                
            }
            if (result == null)
            {
                foreach (AiAirGroup eGroup in enemyAG)
                {                    
                    if (result != null)
                    {
                       if (result.Pos().distance(ref attackerPos) > eGroup.Pos().distance(ref attackerPos))
                           result = eGroup;
                    }
                    else result = eGroup;                    
                }
            }
        }
        return result;
    }
__________________
__________________
Win7, 64bit Ultra
Asus P8P67Pro MB
Intel i7-2600K
Coursair 16GB (4x 4GB), DDR3-1600MHz
Gainward Nvidia 580GTX 3GB DDR5
850-Watt Modular Power Supply
WIN7 and COD on Gskill SSD 240GB
40" Panasonic LCD
TrackIR5 +
Thrustmaster Warthog stick, throttle & pedals
Reply With Quote
 

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 05:30 PM.


Powered by vBulletin® Version 3.8.4
Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright © 2007 Fulqrum Publishing. All rights reserved.