1C Home   |   Register   |   Today Posts   |   Members   |   UserCP   |   Calendar   |   Search   |   FAQ

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

Reply
 
Thread Tools Display Modes
  #11  
Old 04-24-2012, 11:41 PM
hc_wolf hc_wolf is offline
Approved Member
 
Join Date: Jul 2010
Posts: 439
Default

They should fly to nearest enemy. If you have their AI level set to ace and maybe dull doen their gunnery and some otheres ... if attacked they will split up. If attack stops or one gunned down the others will form up and continue onto target
__________________
__________________
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
  #12  
Old 04-25-2012, 06:04 AM
David198502's Avatar
David198502 David198502 is offline
Approved Member
 
Join Date: Dec 2009
Location: Austria
Posts: 1,535
Default

ok, but how do they "know" the position of the enemy?will it be updated with every waypoint?or do they have this information only once at their spawnpoint?

well, i copied the script, and used it for a mission, where i spawn one group of 109s on an airfield in france, and spits at manston.....the strange thing is, that the spitfires never take off.
the 109s will fly directly to manston and attack the spits which are still on the ground.
as soon as i delete the script, the spitfires will take off normally.
__________________
Reply With Quote
  #13  
Old 06-14-2012, 01:00 PM
David198502's Avatar
David198502 David198502 is offline
Approved Member
 
Join Date: Dec 2009
Location: Austria
Posts: 1,535
Default

HTML Code:
using System;
using System.Collections;
using maddox.game;
using maddox.game.world;
using maddox.GP;


public class Mission : AMission
{
	int AirStrikeMissNum = -1;
	
    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;
    }


internal AiAirport FindOurAirfield(int army, AiActor actor)
    {
        AiAirport result = null;
        Point3d attackerPos = actor.Pos();
        AiAirport[] airports = GamePlay.gpAirports();

        if (airports != null)
        {
            foreach (AiAirport airport in airports) 
            {
                if (GamePlay.gpFrontArmy(airport.Pos().x, airport.Pos().y) == army)
                {
                    if (result != null)
                    {
                        if (result.Pos().distance(ref attackerPos) > airport.Pos().distance(ref attackerPos))
                            result = airport;
                    }
                    else result = airport;                    
                }
            }
        }
        return result;
    }


    internal AiWayPoint[] LandingWay(AiAirGroup airGroup)
    {
        AiWayPoint[] result = new AiWayPoint[1];

        if (airGroup.GetWay().Length != 1)
        {
            Point3d curPos = airGroup.Pos();
            double speed = (airGroup.GetItems()[0] as AiAircraft).getParameter(part.ParameterTypes.Z_VelocityTAS, -1);

            AiAirport findOurAirfield = FindOurAirfield(airGroup.Army(), airGroup);
            if (findOurAirfield != null)
            {
                curPos = findOurAirfield.Pos();
                AiAirWayPoint aaWP = new AiAirWayPoint(ref curPos, speed);
                aaWP.Action = AiAirWayPointType.LANDING;
                aaWP.Target = findOurAirfield;
                result[0] = aaWP;
            }
            else
            {
                result = WaitingTargetWay(airGroup);
            }
        }
        else result = airGroup.GetWay();

        return result;
    }

    internal AiWayPoint[] WaitingTargetWay(AiAirGroup airGroup)
    {
        AiWayPoint[] result = new AiWayPoint[3];
        double speed = (airGroup.GetItems()[0] as AiAircraft).getParameter(part.ParameterTypes.Z_VelocityTAS, -1);
        Point3d addPoint = airGroup.Pos();
        addPoint.add(2000, 2000, 0);
        AiAirWayPoint aaWP = new AiAirWayPoint(ref addPoint, speed);
        if (airGroup.isAircraftType(AircraftType.Fighter) || airGroup.isAircraftType(AircraftType.HeavyFighter))
        { aaWP.Action = AiAirWayPointType.HUNTING; }
        else aaWP.Action = AiAirWayPointType.NORMFLY;
        result[0] = aaWP;
        addPoint.add(-1500, -1500, 0);
        aaWP.P = addPoint;
        result[1] = aaWP;
        addPoint.add(1000, 1000, 0);
        aaWP.P = addPoint;
        aaWP.Action = AiAirWayPointType.LANDING;
        result[2] = aaWP;
        return result;
    }

    internal void SetNewTask(AiAirGroup airGroup)
    {
        AiWayPoint[] chkWP = airGroup.GetWay();      
            
        Point3d curPos = airGroup.Pos();
        AiWayPoint[] airGroupWay = new AiWayPoint[2];
        if ((chkWP.Length == 1) && ((chkWP[0] as AiAirWayPoint).Action == AiAirWayPointType.LANDING))
        {
            return;
            /*if (((chkWP[0] as AiAirWayPoint).Target as AiAirport) != null)
                if (GamePlay.gpFrontArmy(((chkWP[0] as AiAirWayPoint).Target as AiAirport).Pos().x, ((chkWP[0] as AiAirWayPoint).Target as AiAirport).Pos().y) == airGroup.Army())
                { return; }
                else 
                {
                    airGroupWay = WaitingTargetWay(airGroup);
                    airGroup.SetWay(airGroupWay);
                    return;
                } */
        }
        double speed = (airGroup.GetItems()[0] as AiAircraft).getParameter(part.ParameterTypes.Z_VelocityTAS, -1);
        Point3d addPoint = curPos;
        AiAirWayPoint aaWP = new AiAirWayPoint(ref addPoint, speed);
        aaWP.Action = AiAirWayPointType.NORMFLY;
        airGroupWay[0] = aaWP;

        if (airGroup.isAircraftType(AircraftType.Bomber) || airGroup.isAircraftType(AircraftType.DiveBomber))
        {
            AiActor nearestGT = FindGroundTarget(airGroup.Army(), airGroup.Pos());
            if (airGroup.hasBombs())
            {
                if (nearestGT != null)
                {
                    aaWP.P = nearestGT.Pos();
                    aaWP.P.z = curPos.z;
                    aaWP.Target = nearestGT;
                    aaWP.GAttackType = AiAirWayPointGAttackType.LEVEL;
                    aaWP.Action = AiAirWayPointType.GATTACK_TARG;
                    airGroupWay[1] = aaWP;                    
                }
                else
                {
                    airGroupWay = WaitingTargetWay(airGroup);
                }
            }
            else airGroupWay = LandingWay(airGroup);
        }

        if (airGroup.isAircraftType(AircraftType.Fighter) || airGroup.isAircraftType(AircraftType.HeavyFighter))
        {
            AiAirGroup enemyGroup = FindAirTarget(airGroup) as AiAirGroup;

            if (enemyGroup == null)
                return;

            if (airGroup.hasCourseWeapon())
            {                       
                    aaWP.P = enemyGroup.Pos();
                    aaWP.Target = enemyGroup;
                    if (enemyGroup.isAircraftType(AircraftType.Bomber) || enemyGroup.isAircraftType(AircraftType.DiveBomber))
                        aaWP.Action = AiAirWayPointType.AATTACK_BOMBERS;
                    else aaWP.Action = AiAirWayPointType.AATTACK_FIGHTERS;
                    airGroupWay[1] = aaWP;                                            
            }
            else
            {
                airGroupWay = LandingWay(airGroup);
            }
        }
        if (airGroupWay != null)
        {
            foreach (AiWayPoint aWP in airGroupWay)
            {
                if (aWP == null)
                    return;
            }
            airGroup.SetWay(airGroupWay);
        }
    }

    internal void SetNewFighterTask(AiAirGroup airGroup, AiAirGroup enemyGroup)
    {
        AiWayPoint[] chkWP = airGroup.GetWay();

        Point3d curPos = airGroup.Pos();
        AiWayPoint[] airGroupWay = new AiWayPoint[2];
        
        double speed = (airGroup.GetItems()[0] as AiAircraft).getParameter(part.ParameterTypes.Z_VelocityTAS, -1);
        Point3d addPoint = curPos;
        AiAirWayPoint aaWP = new AiAirWayPoint(ref addPoint, speed);
        aaWP.Action = AiAirWayPointType.NORMFLY;
        airGroupWay[0] = aaWP;
        
        if (airGroup.isAircraftType(AircraftType.Fighter) || airGroup.isAircraftType(AircraftType.HeavyFighter))
        {         
            if (enemyGroup == null)
                return;
                aaWP.P = enemyGroup.Pos();
                aaWP.Target = enemyGroup;
                if (enemyGroup.isAircraftType(AircraftType.Bomber) || enemyGroup.isAircraftType(AircraftType.DiveBomber))
                    aaWP.Action = AiAirWayPointType.AATTACK_BOMBERS;
                else aaWP.Action = AiAirWayPointType.AATTACK_FIGHTERS;
                airGroupWay[1] = aaWP;            
        }
        if (airGroupWay != null) airGroup.SetWay(airGroupWay);        
    }

    public override void OnActorTaskCompleted(int missionNumber, string shortName, AiActor actor)
    {
        base.OnActorTaskCompleted(missionNumber, shortName, actor);
        AiAirGroup airGroup = actor as AiAirGroup;
        if ((airGroup != null) && (missionNumber != AirStrikeMissNum))
        {
            SetNewTask(airGroup);            
        }
    }

    public override void OnActorCreated(int missionNumber, string shortName, AiActor actor)
    {
        base.OnActorCreated(missionNumber, shortName, actor);
        if (missionNumber != AirStrikeMissNum)
        {
            AiAirGroup airGroup = actor as AiAirGroup;
            if (airGroup != null)
            {
                SetNewTask(airGroup);
                AiAirGroup[] eGroups = GamePlay.gpAirGroups((airGroup.Army() == 1) ? 2 : 1);
                if (eGroups != null)
                    foreach (AiAirGroup eGroup in eGroups)
                    {
                        if (eGroup != null)
                        {
                            if ((eGroup.hasCourseWeapon()) && ((airGroup.isAircraftType(AircraftType.Fighter)) || (airGroup.isAircraftType(AircraftType.HeavyFighter))))
                            {
                                AiWayPoint[] chkWP = eGroup.GetWay();
                                bool res = true;
                                foreach (AiWayPoint eWP in chkWP)
                                {
                                    AiAirWayPoint aAWP = (eWP as AiAirWayPoint);
                                    if ((aAWP.Action != AiAirWayPointType.HUNTING) || (aAWP.Action != AiAirWayPointType.NORMFLY) || ((aAWP.Action == AiAirWayPointType.AATTACK_BOMBERS) && (aAWP.Target != null) && (aAWP.Target.IsValid())) || ((aAWP.Action == AiAirWayPointType.AATTACK_BOMBERS) && (aAWP.Target != null) && (aAWP.Target.IsValid())))
                                    {
                                        res = false;
                                        break;
                                    }
                                }
                                if (res)
                                {
                                    SetNewFighterTask(eGroup, airGroup);
                                }
                            }
                        }
                    }
            }
        }
    }
///////////////ENDE
}
is this really working for you guys?
as soon as i insert the script, all my RAF planes will not take off anymore for some dubious reason...
the 109s though, will take off, fly all over the channel,ignoring their waypoints, and strave the spits on the airfield, who still sit on the ground.
it seems to work fine with 109s, but raf planes, at least spits and hurris, just wont take off....
__________________
Reply With Quote
Reply

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:35 PM.


Powered by vBulletin® Version 3.8.4
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright © 2007 1C Company. All rights reserved.