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
  #21  
Old 06-21-2012, 02:42 PM
David198502's Avatar
David198502 David198502 is offline
Approved Member
 
Join Date: Dec 2009
Location: Austria
Posts: 1,536
Default

here is the complete code:

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

using part;


public class Mission : AMission
{
    private bool battleEnded = false;
   
    class BirthPlacePlanes
    {
        public string BirthPlace { get; set; }
        public int NumberOfPlanes { get; set; }
        

        public BirthPlacePlanes(string birthPlaceName, int maxNumber)
        {
            BirthPlace = birthPlaceName;
            NumberOfPlanes = maxNumber;
        }
    }


    List<BirthPlacePlanes> AvailablePlanes = new List<BirthPlacePlanes>
                                                  {
                                                      new BirthPlacePlanes("RAF-5k", 10),
                                                      new BirthPlacePlanes("RAF-3k", 10),
                                                      new BirthPlacePlanes("RAF-500m", 10),
                                                      new BirthPlacePlanes("JG26-5k", 1),
                                                      new BirthPlacePlanes("JG26-3k", 1),
                                                      new BirthPlacePlanes("JG26-500m", 5)
                                                  };

    
    public bool IsActorDown(AiActor actor)
    {
        AiAircraft aircraft = actor as AiAircraft;
        if (aircraft != null && (aircraft.getParameter(ParameterTypes.Z_AltitudeAGL, -1) <= 2.0
                                            && aircraft.getParameter(ParameterTypes.Z_VelocityTAS, -1) <= 1.0))
            return true;
        
            return false;
    }


    public int CountPlayerUsedPlanes(int army)
    {
        int count = 0;

        foreach (Player pl in AllPlayers())
        {
            if (pl.Place() != null && pl.Army() == army && pl.PlacePrimary() == 0)
                count++;
        }

        return count;
    }


    public int CountAvailablePlanes(int army)
    {
        int count = 0;

        foreach (BirthPlacePlanes bpp in AvailablePlanes)
        {
            AiBirthPlace birthPlace = GetBirthPlaceByName(bpp.BirthPlace);

            if (birthPlace != null)
                if (birthPlace.Army() == army)
                    count += bpp.NumberOfPlanes;
        }

        return count;
    }


    public AiBirthPlace GetBirthPlaceByName(string birthPlaceName)
    {
        foreach (AiBirthPlace bp in GamePlay.gpBirthPlaces())
        {
            if (bp.Name() == birthPlaceName)
                return bp;
        }

        return null;
    }


    public AiBirthPlace GetBirthplace(AiActor actor)
    {
        AiBirthPlace nearestBirthplace = null;
        AiBirthPlace[] birthPlaces = GamePlay.gpBirthPlaces();

        Point3d pos = actor.Pos();

        if (birthPlaces != null)
        {
            foreach (AiBirthPlace airport in birthPlaces)
            {
                if (nearestBirthplace != null)
                {
                    if (nearestBirthplace.Pos().distance(ref pos) > airport.Pos().distance(ref pos))
                        nearestBirthplace = airport;
                }
                else nearestBirthplace = airport;
            }
        }
        return nearestBirthplace;
    }


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

        MissionNumberListener = -1;
    }


     public override void OnPlaceEnter(Player player, AiActor actor, int placeIndex)
    {
        base.OnPlaceEnter(player, actor, placeIndex);

        AiBirthPlace birthPlace = GetBirthplace(actor);


        AiCart cart = actor as AiCart;

        if(cart != null)
        AvailablePlanes.ForEach(place =>
                                    {
                                        if (place.BirthPlace == birthPlace.Name())
                                        {
                                            
                                            place.NumberOfPlanes--;

                                            int numberOfAllAvailablePlanes = CountAvailablePlanes(actor.Army());

                                            if (numberOfAllAvailablePlanes == 5)
                                            {
                                                if(actor.Army() == 1)
                                                    GamePlay.gpHUDLogCenter(null, "Attention Reds only {0} Planes are left", new object[] { numberOfAllAvailablePlanes });
                                                if(actor.Army() == 2)
                                                    GamePlay.gpHUDLogCenter(null, "Attention Blues only {0} Planes are left", new object[] { numberOfAllAvailablePlanes });
                                            }

                                            if (place.NumberOfPlanes == 3 )
                                            {
                                               Timeout(5, () => {

                                                GamePlay.gpHUDLogCenter(null, "Attention only {0} Planes are left on {1}", new object[] { place.NumberOfPlanes, place.BirthPlace });
                                            }

                                            if (place.NumberOfPlanes == 0)
                                            {
                                                GamePlay.gpHUDLogCenter(null, "Attention {0} is no longer available", new object[]{place.BirthPlace});
                                                birthPlace.destroy();
                                            }
                                        }
                                    });
    }



    public List<Player> AllPlayers()
    {
        List<Player> allPlayers = new List<Player>();

        if(GamePlay.gpPlayer() != null)
            allPlayers.Add(GamePlay.gpPlayer());
        if(GamePlay.gpRemotePlayers() != null)
            allPlayers.AddRange(GamePlay.gpRemotePlayers());

        return allPlayers;
    }


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

        if (Time.tickCounter() % 300 == 0)
        {
            // check if Player is grounded

            AllPlayers().ForEach(item =>
                                     {
                                         if (item.Place() != null)
                                             if (IsActorDown(item.Place()))
                                             {
                                                 AiCart cart = item.Place() as AiCart;
                                                 if (cart != null) cart.Destroy();
                                             }
                                     });
                                     
                                     

            //TestMessages remove if no longer needed 
            GamePlay.gpLogServer(null, "Army: RED, Available: {0}, In Use: {1}", new object[] { CountAvailablePlanes(1), CountPlayerUsedPlanes(1) });
            GamePlay.gpLogServer(null, "Army: BLUE, Available: {0}, In Use: {1}", new object[] { CountAvailablePlanes(2), CountPlayerUsedPlanes(2) });
        }
    }


    public override void OnActorDestroyed(int missionNumber, string shortName, AiActor actor)
    {
        base.OnActorDestroyed(missionNumber, shortName, actor);

        AiCart cart = actor as AiCart;
        
        if (cart != null)
        {
            if (actor.Army() == 1 && CountAvailablePlanes(1) == 0 && CountPlayerUsedPlanes(1) == 0 && !battleEnded)
            {
                battleEnded = true;
                GamePlay.gpHUDLogCenter(null, "JG26 kicked your butts");
            }
            else if (actor.Army() == 2 && CountAvailablePlanes(2) == 0 && CountPlayerUsedPlanes(2) == 0 && !battleEnded)
            {
                battleEnded = true;
                GamePlay.gpHUDLogCenter(null, "Micky Mouse Team won");
            }
        }
    }

  
}
__________________
Reply With Quote
  #22  
Old 06-21-2012, 03:29 PM
FG28_Kodiak FG28_Kodiak is offline
Approved Member
 
Join Date: Dec 2009
Location: Swabia->Bavaria->Germany
Posts: 884
Default

Ok some bracket mismatch, corrected version:
Code:
using System;
using System.Collections;
using System.Collections.Generic;
using maddox.GP;
using maddox.game;
using maddox.game.world;

using part;


public class Mission : AMission
{
    private bool battleEnded = false;
   
    class BirthPlacePlanes
    {
        public string BirthPlace { get; set; }
        public int NumberOfPlanes { get; set; }
        

        public BirthPlacePlanes(string birthPlaceName, int maxNumber)
        {
            BirthPlace = birthPlaceName;
            NumberOfPlanes = maxNumber;
        }
    }


    List<BirthPlacePlanes> AvailablePlanes = new List<BirthPlacePlanes>
                                                  {
                                                      new BirthPlacePlanes("RAF-5k", 10),
                                                      new BirthPlacePlanes("RAF-3k", 10),
                                                      new BirthPlacePlanes("RAF-500m", 10),
                                                      new BirthPlacePlanes("JG26-5k", 1),
                                                      new BirthPlacePlanes("JG26-3k", 1),
                                                      new BirthPlacePlanes("JG26-500m", 5)
                                                  };

    
    public bool IsActorDown(AiActor actor)
    {
        AiAircraft aircraft = actor as AiAircraft;
        if (aircraft != null && (aircraft.getParameter(ParameterTypes.Z_AltitudeAGL, -1) <= 2.0
                                            && aircraft.getParameter(ParameterTypes.Z_VelocityTAS, -1) <= 1.0))
            return true;
        
            return false;
    }


    public int CountPlayerUsedPlanes(int army)
    {
        int count = 0;

        foreach (Player pl in AllPlayers())
        {
            if (pl.Place() != null && pl.Army() == army && pl.PlacePrimary() == 0)
                count++;
        }

        return count;
    }


    public int CountAvailablePlanes(int army)
    {
        int count = 0;

        foreach (BirthPlacePlanes bpp in AvailablePlanes)
        {
            AiBirthPlace birthPlace = GetBirthPlaceByName(bpp.BirthPlace);

            if (birthPlace != null)
                if (birthPlace.Army() == army)
                    count += bpp.NumberOfPlanes;
        }

        return count;
    }


    public AiBirthPlace GetBirthPlaceByName(string birthPlaceName)
    {
        foreach (AiBirthPlace bp in GamePlay.gpBirthPlaces())
        {
            if (bp.Name() == birthPlaceName)
                return bp;
        }

        return null;
    }


    public AiBirthPlace GetBirthplace(AiActor actor)
    {
        AiBirthPlace nearestBirthplace = null;
        AiBirthPlace[] birthPlaces = GamePlay.gpBirthPlaces();

        Point3d pos = actor.Pos();

        if (birthPlaces != null)
        {
            foreach (AiBirthPlace airport in birthPlaces)
            {
                if (nearestBirthplace != null)
                {
                    if (nearestBirthplace.Pos().distance(ref pos) > airport.Pos().distance(ref pos))
                        nearestBirthplace = airport;
                }
                else nearestBirthplace = airport;
            }
        }
        return nearestBirthplace;
    }


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

        MissionNumberListener = -1;
    }


    public override void OnPlaceEnter(Player player, AiActor actor, int placeIndex)
    {
        base.OnPlaceEnter(player, actor, placeIndex);

        AiBirthPlace birthPlace = GetBirthplace(actor);


        AiCart cart = actor as AiCart;

        if (cart != null)
            AvailablePlanes.ForEach(place =>
                                        {
                                            if (place.BirthPlace == birthPlace.Name())
                                            {

                                                place.NumberOfPlanes--;

                                                int numberOfAllAvailablePlanes = CountAvailablePlanes(actor.Army());

                                                if (numberOfAllAvailablePlanes == 5)
                                                {
                                                    if (actor.Army() == 1)
                                                        GamePlay.gpHUDLogCenter(null, "Attention Reds only {0} Planes are left", new object[] {numberOfAllAvailablePlanes});
                                                    if (actor.Army() == 2)
                                                        GamePlay.gpHUDLogCenter(null, "Attention Blues only {0} Planes are left", new object[] {numberOfAllAvailablePlanes});
                                                }

                                                if (place.NumberOfPlanes == 3)
                                                {
                                                    Timeout(5, () =>{
                                                                        GamePlay.gpHUDLogCenter(null, "Attention only {0} Planes are left on {1}", new object[] { place.NumberOfPlanes, place.BirthPlace});
                                                                    });
                                                }
                                                if (place.NumberOfPlanes == 0)
                                                {
                                                    GamePlay.gpHUDLogCenter(null, "Attention {0} is no longer available", new object[] {place.BirthPlace});
                                                    birthPlace.destroy();
                                                }
                                            }
                                        });
    }




    public List<Player> AllPlayers()
    {
        List<Player> allPlayers = new List<Player>();

        if(GamePlay.gpPlayer() != null)
            allPlayers.Add(GamePlay.gpPlayer());
        if(GamePlay.gpRemotePlayers() != null)
            allPlayers.AddRange(GamePlay.gpRemotePlayers());

        return allPlayers;
    }


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

        if (Time.tickCounter() % 300 == 0)
        {
            // check if Player is grounded

            AllPlayers().ForEach(item =>
                                     {
                                         if (item.Place() != null)
                                             if (IsActorDown(item.Place()))
                                             {
                                                 AiCart cart = item.Place() as AiCart;
                                                 if (cart != null) cart.Destroy();
                                             }
                                     });
                                     
                                     

            //TestMessages remove if no longer needed 
            GamePlay.gpLogServer(null, "Army: RED, Available: {0}, In Use: {1}", new object[] { CountAvailablePlanes(1), CountPlayerUsedPlanes(1) });
            GamePlay.gpLogServer(null, "Army: BLUE, Available: {0}, In Use: {1}", new object[] { CountAvailablePlanes(2), CountPlayerUsedPlanes(2) });
        }
    }


    public override void OnActorDestroyed(int missionNumber, string shortName, AiActor actor)
    {
        base.OnActorDestroyed(missionNumber, shortName, actor);

        AiCart cart = actor as AiCart;
        
        if (cart != null)
        {
            if (actor.Army() == 1 && CountAvailablePlanes(1) == 0 && CountPlayerUsedPlanes(1) == 0 && !battleEnded)
            {
                battleEnded = true;
                GamePlay.gpHUDLogCenter(null, "JG26 kicked your butts");
            }
            else if (actor.Army() == 2 && CountAvailablePlanes(2) == 0 && CountPlayerUsedPlanes(2) == 0 && !battleEnded)
            {
                battleEnded = true;
                GamePlay.gpHUDLogCenter(null, "Micky Mouse Team won");
            }
        }
    }
}
Reply With Quote
  #23  
Old 06-21-2012, 04:01 PM
David198502's Avatar
David198502 David198502 is offline
Approved Member
 
Join Date: Dec 2009
Location: Austria
Posts: 1,536
Default

this works now

ok great,....now last question,...are you willing to write such a script for me, which includes the homecoming planes in the script???
i know im probably a bit annoying, with constantly asking for new things, but my main problem with all the scripts is, that i dont have a clue whats possible and not...then i ask if something is possible, and if the answer is yes, then im really excited, and want to try out the script....and most of the time, while trying such new scripts, improvements or other possibilities come to my mind...then i ask again if its possible and so on...

anyway thx for that script i already have.
__________________

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

oh before i forget it, if you really write it, please include, that planes who land back safely, will get despawned after the player leaves the plane...thx in advance
__________________
Reply With Quote
  #25  
Old 06-21-2012, 06:01 PM
FG28_Kodiak FG28_Kodiak is offline
Approved Member
 
Join Date: Dec 2009
Location: Swabia->Bavaria->Germany
Posts: 884
Default

To despawn the plane after grounding, was simple for this people who crashed and then sit a half an hour in their planes and waiting. So they must select a new plane. But it's no problem to despawn a plane after correct landing after Pilot leaves plane.
Reply With Quote
  #26  
Old 06-21-2012, 06:05 PM
David198502's Avatar
David198502 David198502 is offline
Approved Member
 
Join Date: Dec 2009
Location: Austria
Posts: 1,536
Default

yeah thats what i mean
if a player would come back to the home airfield, and lands safely, then leaves the plane, the plane should despawn, but the script should then know that it "puts that plane back into the spawnpoint"

that would be a great script for my purpose
__________________
Reply With Quote
  #27  
Old 06-24-2012, 07:36 AM
FG28_Kodiak FG28_Kodiak is offline
Approved Member
 
Join Date: Dec 2009
Location: Swabia->Bavaria->Germany
Posts: 884
Default

So enhanced Version, Planes landing on their HomeBases are returned into the "Pool". If no plane is available on the Base the SpawnPlace will be removed, and recreated if a plane returns into the pool.
Planes that are landed or crashlanded are "force"-removed after 60 sec. You can change the Time (in seconds) in
ActorObservation.ForceActorDestroyNotPosChangeAfte r(60);
or if you dont like it remove the line.

If you use SpawnPlaces with Airstart, place it over an existing Airstrip, if a Plane lands on this strip, it returns into the pool.

You can use more than one planetype on a Birthplace, but there is only one counter per Birthplace at the moment, so the script does not differ the types.
Maybe i add this feature in the future, also thinking about a transfer feature.

Script:
http://forum.1cpublishing.eu/showpos...2&postcount=40

Last edited by FG28_Kodiak; 06-26-2012 at 04:20 PM.
Reply With Quote
  #28  
Old 06-24-2012, 08:01 AM
David198502's Avatar
David198502 David198502 is offline
Approved Member
 
Join Date: Dec 2009
Location: Austria
Posts: 1,536
Default

thank you sooo much Kodiak!!!

will try that out immediately after i got my morning coffee....
what do you mean with "...the script does not differ the types.."?
would it be theoretically possible, that one airfield/spawnarea has a certain amount of different planetypes?for example 20E1s and 10E4s?is that what you mean with not differing in planetypes?
__________________

Last edited by David198502; 06-24-2012 at 08:14 AM.
Reply With Quote
  #29  
Old 06-24-2012, 08:41 AM
FG28_Kodiak FG28_Kodiak is offline
Approved Member
 
Join Date: Dec 2009
Location: Swabia->Bavaria->Germany
Posts: 884
Default

Quote:
Originally Posted by David198502 View Post
for example 20E1s and 10E4s?is that what you mean..
Yes thats what i mean , it should be possible.
Reply With Quote
  #30  
Old 06-24-2012, 08:44 AM
David198502's Avatar
David198502 David198502 is offline
Approved Member
 
Join Date: Dec 2009
Location: Austria
Posts: 1,536
Default

ah ok,thats a neat possibility....and the transfer feature is probably, that if a plane spawns at one airfield, but lands at a different one, that it than will be transfered to the other "plane pool"...i guess.
those two features would be great!....but no worries,...im more than happy with the current script.but if you decide to add those features, please let me know...
i will try it out now, and report back...
__________________
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 11:44 PM.


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