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

Reply
 
Thread Tools Display Modes
  #1  
Old 04-24-2012, 01:19 PM
David198502's Avatar
David198502 David198502 is offline
Approved Member
 
Join Date: Dec 2009
Location: Austria
Posts: 1,536
Default how to remove AI planes and AI vehicles?

hey guys....im just building a mission, where i try to load submissions randomly into one main mission.

what i dont know how to achieve though is, how i can "destroy" ai planes if they have landed, and also vehicles or trains, when they have reached a certain waypoint....

i have attached the complete mission...
there is one main mission, and 3 submissions which will be loaded randomly every 30seconds.
the problem with it is, that the trains and vehicles will just stay on the map.
i would like them to have destroyed when they reach their last waypoint....

in the script, there is a way to "destroy" planes after a certain time, but i would like to change it, that they will get destroyed after they have landed...
(i know that this will happen automatically, but only after 10 minutes)i want that the planes are destroyed after maybe 30seconds when they have landed.
Attached Files
File Type: zip Blitzkrieg.zip (3.1 KB, 6 views)
__________________

Last edited by David198502; 04-24-2012 at 03:31 PM.
Reply With Quote
  #2  
Old 04-24-2012, 03:27 PM
David198502's Avatar
David198502 David198502 is offline
Approved Member
 
Join Date: Dec 2009
Location: Austria
Posts: 1,536
Default

here is the script only...
Attached Files
File Type: txt Blitzkrieg.txt (10.6 KB, 8 views)
__________________
Reply With Quote
  #3  
Old 04-24-2012, 03:44 PM
FG28_Kodiak FG28_Kodiak is offline
Approved Member
 
Join Date: Dec 2009
Location: Swabia->Bavaria->Germany
Posts: 884
Default

To remove landed, crashlanded AI-Planes or Groundactors after completing their task :
Code:
using System;
using System.Collections;
using System.Collections.Generic;
using maddox.game;
using maddox.game.world;


public class Mission : AMission
{

    public override void OnBattleStarted()
    {
        base.OnBattleStarted();

        MissionNumberListener = -1;
    }


    public override void OnAircraftCrashLanded(int missionNumber, string shortName, AiAircraft aircraft)
    {
        base.OnAircraftCrashLanded(missionNumber, shortName, aircraft);


        if(IsActorDestroyable(aircraft))
            aircraft.Destroy();
    }


    public override void OnAircraftLanded(int missionNumber, string shortName, AiAircraft aircraft)
    {
        base.OnAircraftLanded(missionNumber, shortName, aircraft);

        if (IsActorDestroyable(aircraft))
            aircraft.Destroy();
    }


    private bool IsActorDestroyable(AiActor actor)
    {
        bool actorDestroyable = true;

        //Check if actor is empty (no Player)
        if (actor is AiAircraft)
        {
            if ((actor as AiAircraft).ExistCabin(0))
                for (int i = 0; i < (actor as AiAircraft).Places(); i++)
                {
                    if ((actor as AiAircraft).Player(i) != null)
                    {
                        actorDestroyable = false;
                        break;
                    }
                }
        }
        else if (actor is AiGroundActor)
        {
            if ((actor as AiGroundActor).ExistCabin(0))
                for (int i = 0; i < (actor as AiGroundActor).Places(); i++)
                {
                    if ((actor as AiGroundActor).Player(i) != null)
                    {
                        actorDestroyable = false;
                        break;
                    }
                }
        }

        return actorDestroyable;
    }

// to remove GroundActors after their Task is completed
   public override void OnActorTaskCompleted(int missionNumber, string shortName, AiActor actor)
    {
        base.OnActorTaskCompleted(missionNumber, shortName, actor);

        if (actor is AiGroundActor)
            if (IsActorDestroyable(actor))
                (actor as AiGroundActor).Destroy(); 
    }
}
Reply With Quote
  #4  
Old 04-24-2012, 03:45 PM
David198502's Avatar
David198502 David198502 is offline
Approved Member
 
Join Date: Dec 2009
Location: Austria
Posts: 1,536
Default

thx Kodiak...will try that, though im not sure how to implement that part into my already existing one
__________________
Reply With Quote
  #5  
Old 04-24-2012, 03:58 PM
David198502's Avatar
David198502 David198502 is offline
Approved Member
 
Join Date: Dec 2009
Location: Austria
Posts: 1,536
Default

ok the mission now works, so that the submissions will be loaded and also the planes are destroyed after they have landed.

but ground vehicles and trains just remain on the map after they have reached their last waypoint.how can i make it, that they achieve their "task"?


HTML Code:
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using maddox.game;
using maddox.game.world;


public class Mission : AMission
{
    Stopwatch MissionTimer = new Stopwatch();

    public override void OnBattleStarted()
    {
        base.OnBattleStarted();
        MissionTimer.Start();
        MissionNumberListener = -1;
    }


    public override void OnAircraftCrashLanded(int missionNumber, string shortName, AiAircraft aircraft)
    {
        base.OnAircraftCrashLanded(missionNumber, shortName, aircraft);


        if(IsActorDestroyable(aircraft))
            aircraft.Destroy();
    }


    public override void OnAircraftLanded(int missionNumber, string shortName, AiAircraft aircraft)
    {
        base.OnAircraftLanded(missionNumber, shortName, aircraft);

        if (IsActorDestroyable(aircraft))
            aircraft.Destroy();
    }


    private bool IsActorDestroyable(AiActor actor)
    {
        bool actorDestroyable = true;

        //Check if actor is empty (no Player)
        if (actor is AiAircraft)
        {
            if ((actor as AiAircraft).ExistCabin(0))
                for (int i = 0; i < (actor as AiAircraft).Places(); i++)
                {
                    if ((actor as AiAircraft).Player(i) != null)
                    {
                        actorDestroyable = false;
                        break;
                    }
                }
        }
        else if (actor is AiGroundActor)
        {
            if ((actor as AiGroundActor).ExistCabin(0))
                for (int i = 0; i < (actor as AiGroundActor).Places(); i++)
                {
                    if ((actor as AiGroundActor).Player(i) != null)
                    {
                        actorDestroyable = false;
                        break;
                    }
                }
        }

        return actorDestroyable;
    }

// to remove GroundActors after their Task is completed
   public override void OnActorTaskCompleted(int missionNumber, string shortName, AiActor actor)
    {
        base.OnActorTaskCompleted(missionNumber, shortName, actor);

        if (actor is AiGroundActor)
            if (IsActorDestroyable(actor))
                (actor as AiGroundActor).Destroy(); 
    }
    public override void OnTickGame()
    {
    
        if(MissionTimer.Elapsed.TotalSeconds >= 30)  //Loads a mission every 120s
        {
            Random ZufaelligeMission = new Random();

            MissionTimer.Restart(); // Sets timer to 0 and start again
    
            switch (ZufaelligeMission.Next(1,4))
            {
                case 1:
                    GamePlay.gpPostMissionLoad("missions\\Blitzkrieg\\mission1.mis");
                    break;
                case 2:
                    GamePlay.gpPostMissionLoad("missions\\Blitzkrieg\\mission2.mis");
                    break;
                case 3:
                    GamePlay.gpPostMissionLoad("missions\\Blitzkrieg\\mission3.mis");
                    break;

            }
        }
    }
}

Last edited by David198502; 04-24-2012 at 04:56 PM.
Reply With Quote
  #6  
Old 04-24-2012, 04:51 PM
FG28_Kodiak FG28_Kodiak is offline
Approved Member
 
Join Date: Dec 2009
Location: Swabia->Bavaria->Germany
Posts: 884
Default

Removing Ai-Planes after landing, should work (have tested it), but OnActorTaskCompleted seems to work not correctly. Must make more tests, but in next Patch it should be possible to get the current waypoint from an Actor so should be no problem to remove an Actor if it reached the last waypoint. But we must wait for the patch.

Code:
using System;
using System.Collections.Generic;
using System.Diagnostics;
using maddox.game;
using maddox.game.world;


public class Mission : AMission
{
    Stopwatch MissionTimer = new Stopwatch();

    public override void OnBattleStarted()
    {
        base.OnBattleStarted();
        MissionTimer.Start();
        MissionNumberListener = -1;
    }


    public override void OnAircraftCrashLanded(int missionNumber, string shortName, AiAircraft aircraft)
    {
        base.OnAircraftCrashLanded(missionNumber, shortName, aircraft);


        if(IsActorDestroyable(aircraft))
            aircraft.Destroy();
    }


    public override void OnAircraftLanded(int missionNumber, string shortName, AiAircraft aircraft)
    {
        base.OnAircraftLanded(missionNumber, shortName, aircraft);

        if (IsActorDestroyable(aircraft))
            aircraft.Destroy();
    }


    private bool IsActorDestroyable(AiActor actor)
    {
        bool actorDestroyable = true;

        //Check if actor is empty (no Player)
        if (actor is AiAircraft)
        {
            if ((actor as AiAircraft).ExistCabin(0))
                for (int i = 0; i < (actor as AiAircraft).Places(); i++)
                {
                    if ((actor as AiAircraft).Player(i) != null)
                    {
                        actorDestroyable = false;
                        break;
                    }
                }
        }
        else if (actor is AiGroundActor)
        {
            if ((actor as AiGroundActor).ExistCabin(0))
                for (int i = 0; i < (actor as AiGroundActor).Places(); i++)
                {
                    if ((actor as AiGroundActor).Player(i) != null)
                    {
                        actorDestroyable = false;
                        break;
                    }
                }
        }

        return actorDestroyable;
    }

    
    public override void OnTickGame()
    {
    
        if(MissionTimer.Elapsed.TotalSeconds >= 30)  //Loads a mission every 120s
        {
            Random ZufaelligeMission = new Random();

            MissionTimer.Restart(); // Sets timer to 0 and start again
    
            switch (ZufaelligeMission.Next(1,4))
            {
                case 1:
                    GamePlay.gpPostMissionLoad("missions\\Blitzkrieg\\mission1.mis");
                    break;
                case 2:
                    GamePlay.gpPostMissionLoad("missions\\Blitzkrieg\\mission2.mis");
                    break;
                case 3:
                    GamePlay.gpPostMissionLoad("missions\\Blitzkrieg\\mission3.mis");
                    break;
            }
        }
    }

}
Reply With Quote
  #7  
Old 04-24-2012, 04:59 PM
David198502's Avatar
David198502 David198502 is offline
Approved Member
 
Join Date: Dec 2009
Location: Austria
Posts: 1,536
Default

thx Kodiak,..see my above post which i have edited just now...
this time i was able to adjust the script by myself that it worked in the end,...except the ground vehicles of course
__________________

Last edited by David198502; 04-24-2012 at 05:02 PM.
Reply With Quote
  #8  
Old 04-24-2012, 09:37 PM
David198502's Avatar
David198502 David198502 is offline
Approved Member
 
Join Date: Dec 2009
Location: Austria
Posts: 1,536
Default

btw,...is there a way, to limit the number of planes with scripting?
cause at it is now, the mission will soon have plenty of planes and the numbers will increase continually.
of course its possible to adjust the the script, that the missions will not be loaded that often, or the missions, that the planes will land(destroyed) sooner.

but this approach requires much time adjusting the missions, espesially when one has 60+ submissions.

so i thought it would be really comfortable, if it would be possible to limit the numbers with the script. if the maximum amount of planes is reached, then the script will not load a new submission, until some planes get shot down, or land(destroyed)...
__________________
Reply With Quote
  #9  
Old 04-25-2012, 06:06 AM
FG28_Kodiak FG28_Kodiak is offline
Approved Member
 
Join Date: Dec 2009
Location: Swabia->Bavaria->Germany
Posts: 884
Default

yes its possible.


Code:
    public int GetSumAllPlanes()
    {
        int planeCount = 0;
        List<AiAirGroup> allAirgroups = new List<AiAirGroup>();

        if (GamePlay.gpAirGroups(1) != null)
            allAirgroups.AddRange(GamePlay.gpAirGroups(1));

        if (GamePlay.gpAirGroups(2) != null)
            allAirgroups.AddRange(GamePlay.gpAirGroups(2));


        allAirgroups.ForEach(item =>
            {
                foreach (AiAircraft ac in item.GetItems())
                {
                    planeCount++;
                }
            });

        return planeCount;
    }
before loading a new mission you can check for example
Code:
if(GetSumAllPlanes() < maxPlanes)
You can also use AiAirgroup 's NOfAirc but it seems buggy in the current Clod Version, it sometimes not show the correct Numbers of Airplanes in a group. So it's better to add the Aircrafts like above.

Last edited by FG28_Kodiak; 04-25-2012 at 06:11 AM.
Reply With Quote
  #10  
Old 04-25-2012, 06:14 AM
David198502's Avatar
David198502 David198502 is offline
Approved Member
 
Join Date: Dec 2009
Location: Austria
Posts: 1,536
Default

thank you Kodiak, without you i would give up on that thing i think,cause for me its like reading chinese....

but if i can implement that "planecounter" in my script above, then i could build a mission, which gets more and more unpredictable with every submission i add...
that would be really neat.
but i fear i will again have trouble to implement that part correctly into my script...
but will try out immediately..
btw, what do you mean with:"before loading a new mission you can check for example"?
and where and how do i implement this last line of code?


PS: now in my script i have the possibility to "destroy" planes when they land, or after a certain amount of time, but i would like to have the possibility that some planes (bombers) get destroyed when they reach a certain waypoint behind the frontlines....im sure thats possible, but couldnt find it yesterday.
__________________

Last edited by David198502; 04-25-2012 at 06:19 AM.
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 01:14 PM.


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