View Single Post
  #9  
Old 02-27-2012, 12:45 AM
Smokeynz Smokeynz is offline
Approved Member
 
Join Date: Apr 2011
Posts: 106
Default

Complete code

Code:
/**ScrimBase.cs**/
//
//By Smokeynz
//collated collection of parts from 1c, many thanks to credits to all envolved, especially Kodiak,
//Parts modified plus own iterations and random thoughts
//lastmod 25/2/2012
//Dedicated server compatible

using System;
using System.Collections;
using maddox.game;
using maddox.game.world;
using maddox.GP;
using System.Collections.Generic;
using System.Diagnostics;

public class Mission : AMission
{
    /*=========================================*/

    #region Mission paths
        
    string MP = "missions/Multi/Dogfight/ScrimBase/";//simplifying Txt MissionPath
    string MPsub = "missions/Multi/Dogfight/ScrimBase/sub/";//simplifying Txt MissionPath sub missions
    string MPtm = "missions/Multi/Dogfight/ScrimBase/tm/";//simplifying Txt MissionPath triggered missions
    
    #endregion

    /*=========================================*/
    /*=========================================*/

    #region Inputs  for Missions, Triggered Missions & Messages

    //NOTE: place sub missions into "sub" folder
    //NOTE: sub mis 0~99 series nums
    //If you add sub missions to input region, add new lines to list below(index numbering)
    //Mis Input layout: new SubM(Mission, Message all, Message Red, Message Blue)    

    List<SubM> SubMs = new List<SubM>
    {       
        new SubM ("Sub00.mis", "Hurricanes on Patrol", "Hun Patrol !!", "Auctung Hurricanes !"),
        new SubM ("Sub01.mis", "Messers on Patrol", "JG on Patrol", "RAF Search !!"),
        new SubM ("Sub02.mis", "Bomber Command", "Bomber Escort required", "Auctung Englander Bombers"),
        new SubM ("Sub03.mis", "KG Forming up", "Scramble Bombers inbound", "Angels 8"), 
        new SubM ("Subnull.mis", "random null Sub4", null, null),
        new SubM ("Subnull.mis", "random null Sub5", null, null),
        new SubM ("Subnull.mis", "random null Sub6", null, null),
        new SubM ("Subnull.mis", "random null Sub7", null, null),
        new SubM ("Subnull.mis", "random null Sub8", null, null),
        new SubM ("Subnull.mis", "random null Sub9", null, null),
        new SubM ("Subnull.mis", "random null Sub10", null, null) 
    };
  
    /*=========================================*/

    // Triggered Mission inputs and setup
    //NOTE: place triggered missions into "tm" folder

    /*=========================================*/

    //Triggered Mission lists for UK
    //NOTE: UK = 100~149 series num    
    //If you add missions to input region, add new lines to list below(index numbering)

    List<TM100> TM100s = new List<TM100>
    { 
        new TM100 ("t100.mis", "Triggered mission 100", "Intercept the blue hound", "Intercepters are coming Blue"),
        new TM100 ("t101.mis", "Triggered mission 101", "Intercept the blue hound", "Intercepters are coming Blue"),
        new TM100 ("t102.mis", "Triggered mission 102", "Intercept the blue hound", "Intercepters are coming Blue"),
        new TM100 ("t103.mis", "Triggered mission 103", "Intercept the blue hound", "Intercepters are coming Blue"),// add comma for each new line
        new TM100 ("t104.mis", "Triggered mission 104", "Intercept the blue hound", "Intercepters are coming Blue"),
        new TM100 ("tnull.mis", "random null TM5", null, null),
        new TM100 ("tnull.mis", "random null TM6", null, null),
        new TM100 ("tnull.mis", "random null TM7", null, null),
        new TM100 ("tnull.mis", "random null TM8", null, null),
        new TM100 ("tnull.mis", "random null TM9", null, null),
        new TM100 ("tnull.mis", "random null TM10", null, null)
    };

    /*=========================================*/

    //Objective Triggered Mission lists for UK
    //NOTE: UK = 150~199 series num    
    //If you add missions to input region, add new lines to list below(index numbering)

    List<TM150> TM150s = new List<TM150>
    { 
        new TM150 ("t150.mis", "Objective mission 150 KILL BILL", "Bill has fled the building fire, get him!", "Save Bill!"),
        new TM150 ("t151.mis", "Objective mission 151 KILL BILL", "Bill has fled the building fire, get him!", "Save Bill!"),
        new TM150 ("t152.mis", "Objective mission 152 KILL BILL", "Bill has fled the building fire, get him!", "Save Bill!"),
        new TM150 ("t153.mis", "Objective mission 153 KILL BILL", "Bill has fled the building fire, get him!", "Save Bill!"),// add comma for each new line
        new TM150 ("t154.mis", "Objective mission 154 KILL BILL", "Bill has fled the building fire, get him!", "Save Bill!")        
    };

    /*=========================================*/
    
    // Triggered Mission lists for DE
    //NOTE: DE = 200~249 series num 
    //If you add missions to input region, add new lines to list below(index numbering)
    
    List<TM200> TM200s = new List<TM200>
    { 
        new TM200 ("t200.mis", "Triggered mission 200", "Interceptors coming RED", "Intercept the Red devil"),
        new TM200 ("t201.mis", "Triggered mission 201", "Interceptors coming RED", "Intercept the Red devil"),
        new TM200 ("t202.mis", "Triggered mission 202", "Interceptors coming RED", "Intercept the Red devil"),
        new TM200 ("t203.mis", "Triggered mission 203", "Interceptors coming RED", "Intercept the Red devil"),// add comma for each new line
        new TM200 ("t204.mis", "Triggered mission 204", "Interceptors coming RED", "Intercept the Red devil"),
        new TM200 ("tnull.mis", "random null TM5", null, null),
        new TM200 ("tnull.mis", "random null TM6", null, null),
        new TM200 ("tnull.mis", "random null TM7", null, null),
        new TM200 ("tnull.mis", "random null TM8", null, null),
        new TM200 ("tnull.mis", "random null TM9", null, null),
        new TM200 ("tnull.mis", "random null TM10", null, null)

    };

    /*=========================================*/

    // Triggered Objective missions lists for DE uk
    //NOTE: DE = 250~299 series num 
    //If you add missions to input region, add new lines to list below(index numbering)

    List<TM250> TM250s = new List<TM250>
    { 
        new TM250 ("t250.mis", "Objective mission 250 KILL BOB", "Save BOB!", "BOB has fled the building fire, get him!"),
        new TM250 ("t251.mis", "Objective mission 251 KILL BOB", "Save BOB!", "BOB has fled the building fire, get him!"),
        new TM250 ("t252.mis", "Objective mission 252 KILL BOB", "Save BOB!", "BOB has fled the building fire, get him!"),
        new TM250 ("t253.mis", "Objective mission 253 KILL BOB", "Save BOB!", "BOB has fled the building fire, get him!"),// add comma for each new line
        new TM250 ("t254.mis", "Objective mission 254 KILL BOB", "Save BOB!", "BOB has fled the building fire, get him!")
    };

    #endregion

    /*=========================================*/
    /*=========================================*/

    #region Repeats and delays & Random selection varibles

    //tick time can alter length due to processing damands, however assume 30/sec 
    //1 sec = 30 ticks
    //1 min = 1800 ticks
    //1hour = 108000 ticks

    //note, r value must be bigger than d value

    private int rt0 = 9000;//5 min repeat
    private int dt0 = 1800;//1 min delay 

    private int rt1 = 9000;//5 min repeat
    private int dt1 = 3600;//2 min delay

    private int rt2 = 18000;//10 min repeat
    private int dt2 = 5400;//3 min delay  

    private int rt3 = 27000;//15 min repeat
    private int dt3 = 7200;//4 min delay 

    //timer reset(start value, gets randomised 100~900 in map selection,)
    //auto reset switch delay stops multible trigger loading, this version resets by random time period(100~900 secs)
    //for fixed value unrem the pvt double below, rem out random version in map selection
    //private double rsukS1 = 300;   

    Random rsukS1 = new Random();
    private int ukS1 = 1;
    Random rsukS2 = new Random();
    private int ukS2 = 1;
    Random rsukS3 = new Random();
    private int ukS3 = 1;

    private double rsukS4 = 3600;
    private int ukS4 = 1;
    
    Random rsdeS1 = new Random();
    private int deS1 = 1;
    Random rsdeS2 = new Random();
    private int deS2 = 1;
    Random rsdeS3 = new Random();
    private int deS3 = 1;

    private double rsdeS4 = 3600;    
    private int deS4 = 1; 

    Random rand = new Random();//random mis selection

    #endregion

    /*=========================================*/
    /*=========================================*/

    #region Mission classes

    internal class SubM //SubMission
    {
        public string MN { get; set; }//MissionName
        public string MM { get; set; }//MissionMessage
        public string MMR { get; set; }//MissionMessageRed
        public string MMB { get; set; }//MissionMessageBlue

        public SubM(string mn, string mm, string mmr, string mmb)
        {
            this.MN = mn;
            this.MM = mm;
            this.MMR = mmr;
            this.MMB = mmb;
        }
    }

    internal class TM100 //Triggered missions
    {
        public string TN { get; set; }//MissionName
        public string TM { get; set; }//MissionMessage
        public string TMR { get; set; }//MissionMessageRed
        public string TMB { get; set; }//MissionMessageBlue

        public TM100(string tn, string tm, string tmr, string tmb)
        {
            this.TN = tn;
            this.TM = tm;
            this.TMR = tmr;
            this.TMB = tmb;
        }
    }

    internal class TM150 //Triggered missions
    {
        public string TN { get; set; }//MissionName
        public string TM { get; set; }//MissionMessage
        public string TMR { get; set; }//MissionMessageRed
        public string TMB { get; set; }//MissionMessageBlue

        public TM150(string tn, string tm, string tmr, string tmb)
        {
            this.TN = tn;
            this.TM = tm;
            this.TMR = tmr;
            this.TMB = tmb;
        }
    }

    internal class TM200 //Triggered missions
    {
        public string TN { get; set; }//MissionName
        public string TM { get; set; }//MissionMessage
        public string TMR { get; set; }//MissionMessageRed
        public string TMB { get; set; }//MissionMessageBlue

        public TM200(string tn, string tm, string tmr, string tmb)
        {
            this.TN = tn;
            this.TM = tm;
            this.TMR = tmr;
            this.TMB = tmb;
        }
    }

    internal class TM250 //Triggered missions
    {
        public string TN { get; set; }//MissionName
        public string TM { get; set; }//MissionMessage
        public string TMR { get; set; }//MissionMessageRed
        public string TMB { get; set; }//MissionMessageBlue

        public TM250(string tn, string tm, string tmr, string tmb)
        {
            this.TN = tn;
            this.TM = tm;
            this.TMR = tmr;
            this.TMB = tmb;
        }
    }

    #endregion

    /*=========================================*/
    /*=========================================*/

    #region const's and params

    //Tx's To
    private const int All = -1;
    private const int Allies = 1;
    private const int Axis = 2;    

    //Despawner time varible
    //To times 5min=300 10min=600 15min=900 30min=1800 45min=2700 60min=3600
    private double despawntime = 2700;//ai aircraft despawn
    private double despawntime2 = 300;//secondary ai aircraft despawn
    private double despawntime3 = 2700;//ground ai despawn

    //Goes with time indicator, set period for cycle repeat period: value = seconds 
    //1mins=60sec=1800ticks 
    private double ts = 60;

    //trigger boolean start point condition
    bool pDE1 = false;
    bool pDE2 = false;
    bool pDE3 = false;
    bool pDE4 = false;
    bool pUK1 = false;
    bool pUK2 = false;
    bool pUK3 = false;
    bool pUK4 = false;
    private int rm;
    private int bm;
/*        
     [Trigger]
  uk1 TPassThrough 5 2 12025 10315 15000
  uk2 TPassThrough 5 2 12025 10315 10000
  uk3 TPassThrough 5 2 12025 10315 5000  
  de1 TPassThrough 5 1 30440 31260 15000
  de2 TPassThrough 5 1 30440 31260 10000
  de3 TPassThrough 5 1 30440 31260 5000  
*/

    Point2d DEr1 = new Point2d(30440, 31260);// radar trigger(Red active)
    Point2d UKr1 = new Point2d(12025, 10315);// radar trigger(Blue active)    

    //listen to events from all missions.
    public override void OnBattleStarted()
    {
        base.OnBattleStarted();
        MissionNumberListener = -1; 
    }

    #endregion

    /*=========================================*/
    /*=========================================*/

    #region Main mission operation

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

        /*=========================================*/
        /*    Server timer for mis time testing    */
        /*         rem out when not in use         */
        /*=========================================*/

        // Time. current() in seconds from Battle Start
        if (Time.current() >= ts)
        {
            GamePlay.gpHUDLogCenter("Elapsed Time:Min:" + ts / 60 + " Secs:" + ts + " Ticks:" + ts * 30);
            ts = ts + ts;
        }

        /*=========================================*/

        //tick counter mission random loader
       
        if (Time.tickCounter() % rt0 == dt0)
        {            
            int i = 0;
            if (SubMs.Count > 0)
                i = rand.Next(0, SubMs.Count);
            GamePlay.gpPostMissionLoad(MPsub + SubMs[i].MN);
            STxA(-1, SubMs[i].MM);  
            Timeout(2.0, () => { STxA(1, SubMs[i].MMR); STxA(2, SubMs[i].MMB); });
        }
        if (Time.tickCounter() % rt1 == dt1)
        {
            int i = 0;
            if (SubMs.Count > 0)
                i = rand.Next(0, SubMs.Count);
            GamePlay.gpPostMissionLoad(MPsub + SubMs[i].MN);
            STxA(-1, SubMs[i].MM);
            Timeout(2.0, () => { STxA(1, SubMs[i].MMR); STxA(2, SubMs[i].MMB); });
        }
        if (Time.tickCounter() % rt2 == dt2)
        {
            int i = 0;
            if (SubMs.Count > 0)
                i = rand.Next(0, SubMs.Count);
            GamePlay.gpPostMissionLoad(MPsub + SubMs[i].MN);
            STxA(-1, SubMs[i].MM);
            Timeout(2.0, () => { STxA(1, SubMs[i].MMR); STxA(2, SubMs[i].MMB); });
        }
        if (Time.tickCounter() % rt3 == dt3)
        {
            int i = 0;
            if (SubMs.Count > 0)
                i = rand.Next(0, SubMs.Count);
            GamePlay.gpPostMissionLoad(MPsub + SubMs[i].MN);
            STxA(-1, SubMs[i].MM);
            Timeout(2.0, () => { STxA(1, SubMs[i].MMR); STxA(2, SubMs[i].MMB); });
        }
    }
  
    #endregion

    /*=========================================*/
    /*=========================================*/
    
    #region Mission triggers

    internal double getDistanceFromTo(Point2d startPoint, Point2d endPoint)
    {
        return startPoint.distance(ref endPoint);
    }
          
    public override void OnTrigger(int missionNumber, string shortName, bool active)
    {
        base.OnTrigger(missionNumber, shortName, active);        
            
        List<Player> plebs = new List<Player>();
        if (GamePlay.gpPlayer() != null)            
            plebs.Add(GamePlay.gpPlayer());
        if (GamePlay.gpRemotePlayers() != null)            
            plebs.AddRange(GamePlay.gpRemotePlayers());

        plebs.ForEach(item =>
        {
            if (item.Place() != null)
            {
                Point2d ActorPos = new Point2d(item.Place().Pos().x, item.Place().Pos().y);
                //radar circles
                if (item.Army() == 1)
                {
                    if (getDistanceFromTo(ActorPos, DEr1) > 15000.1)
                    {
                        pDE1 = false;
                        pDE2 = false;
                        pDE3 = false;
                    }

                    if (getDistanceFromTo(ActorPos, DEr1) < 15000)
                        if (getDistanceFromTo(ActorPos, DEr1) > 10000.1)
                        {
                            pDE1 = true;
                            pDE2 = false;
                            pDE3 = false;
                        }

                    if (getDistanceFromTo(ActorPos, DEr1) < 10000)
                        if (getDistanceFromTo(ActorPos, DEr1) > 5000.1)
                        {
                            pDE1 = false;
                            pDE2 = true;
                            pDE3 = false;
                        }
                    if (getDistanceFromTo(ActorPos, DEr1) < 5000)
                    {
                        pDE1 = false;
                        pDE2 = false;
                        pDE3 = true;
                    }                    
                }
                                                                                
                if (item.Army() == 2)
                {
                    if (getDistanceFromTo(ActorPos, UKr1) > 15000.1)
                    {
                        pUK1 = false;
                        pUK2 = false;
                        pUK3 = false;
                    }
                    if (getDistanceFromTo(ActorPos, UKr1) < 15000)
                        if (getDistanceFromTo(ActorPos, UKr1) > 10000.1)
                        {
                            pUK1 = true;
                            pUK2 = false;
                            pUK3 = false;

                        }
                    if (getDistanceFromTo(ActorPos, UKr1) < 10000)
                        if (getDistanceFromTo(ActorPos, UKr1) > 5000.1)
                        {
                            pUK1 = false;
                            pUK2 = true;
                            pUK3 = false;
                        }
                    if (getDistanceFromTo(ActorPos, UKr1) < 5000)
                    {
                        pUK1 = false;
                        pUK2 = false;
                        pUK3 = true;
                    }
                }               
            }
        });

        if ((pDE1 | pDE2 | pDE3 | pUK1 | pUK2 | pUK3) == true)
            TrigMis();
                
          
        // ai as triggers (AI can be treated separately here)
        if (shortName.Equals("de1") && active)        
        {
            STxA(-1, shortName + " ai trigger check(red in blue)");// rem out once checks complete 
        }
        if (shortName.Equals("de2") && active)
        {
            STxA(-1, shortName + " ai trigger check(red in blue)");// rem out once checks complete 
        }
        if (shortName.Equals("de3") && active)
        {
            STxA(-1, shortName + " ai trigger check(red in blue)");// rem out once checks complete 
        }
        //if (shortName.Equals("de4") && active)
        //{
            //STxA(-1, shortName + " ai trigger check(blue bomber)");// rem out once checks complete 
        //}
        if (shortName.Equals("uk1") && active)
        {
            STxA(-1, shortName + " ai trigger check(blue in red)");// rem out once checks complete 
        }
        if (shortName.Equals("uk2") && active)
        {
            STxA(-1, shortName + " ai trigger check(blue in red)");// rem out once checks complete 
        }
        if (shortName.Equals("uk3") && active)
        {
            STxA(-1, shortName + " ai trigger check(blue in red)");// rem out once checks complete 
        }
        //if (shortName.Equals("uk4") && active)
        //{
            //STxA(-1, shortName + " ai trigger check(red bomber)");// rem out once checks complete 
        //}

        if (shortName.Equals("killkubel") && active)
        {
            Timeout(8.0, () => { STxA(-1, shortName + " YOU KILLED BILL"); });
            ukS4 = 1;
        }
        if (shortName.Equals("safekubel") && active)
        {
            Timeout(8.0, () => { STxA(-1, shortName + "BILL IS SAFE"); });            
        }

        if (shortName.Equals("killbob") && active)
        {
            Timeout(8.0, () => { STxA(-1, shortName + " YOU KILLED BOB"); });
            deS4 = 1;
        }
        if (shortName.Equals("safebob") && active)
        {
            Timeout(8.0, () => { STxA(-1, shortName + "BOB IS SAFE"); });            

        }
    }


    private void TrigMis()
    {
        /*===================de triggered mis=====================*/
        if (pDE1 == true)
        {
            switch (deS1)
            {
                case 1:
                    deS1 = 2;//on off switch for trigger operation
                    Timeout(rsdeS1.Next(100, 901), () => { deS1 = 1; });//random timer reset function
                    int i = 0;
                    if (TM200s.Count > 0)
                        i = rand.Next(0, TM200s.Count);
                    GamePlay.gpPostMissionLoad(MPtm + TM200s[i].TN);
                    Timeout(4.0, () => { STxA(-1, TM200s[i].TM); });
                    Timeout(6.0, () => { STxA(1, TM200s[i].TMR); STxA(2, TM200s[i].TMB); });
                    break;
                case 2:
                    Timeout(6.0, () => { STxA(-1, "de1 trigger already in action"); });// rem out once checks complete
                    break;
            }
            pDE1 = false;
        }

        if (pDE2 == true)
        {
            switch (deS2)
            {
                case 1:
                    deS2 = 2;//on off switch for trigger operation
                    Timeout(rsdeS2.Next(100, 901), () => { deS2 = 1; });//random timer reset function
                    int i = 0;
                    if (TM200s.Count > 0)
                        i = rand.Next(0, TM200s.Count);
                    GamePlay.gpPostMissionLoad(MPtm + TM200s[i].TN);
                    Timeout(4.0, () => { STxA(-1, TM200s[i].TM); });
                    Timeout(6.0, () => { STxA(1, TM200s[i].TMR); STxA(2, TM200s[i].TMB); });
                    break;
                case 2:
                    Timeout(6.0, () => { STxA(-1, "de2 trigger already in action"); });// rem out once checks complete
                    break;
            }
            pDE2 = false;
        }

        if (pDE3 == true)
        {
            switch (deS3)
            {
                case 1:
                    deS3 = 2;//on off switch for trigger operation
                    Timeout(rsdeS3.Next(100, 901), () => { deS3 = 1; });//random timer reset function
                    int i = 0;
                    if (TM200s.Count > 0)
                        i = rand.Next(0, TM200s.Count);
                    GamePlay.gpPostMissionLoad(MPtm + TM200s[i].TN);
                    Timeout(4.0, () => { STxA(-1, TM200s[i].TM); });
                    Timeout(6.0, () => { STxA(1, TM200s[i].TMR); STxA(2, TM200s[i].TMB); });
                    break;
                case 2:
                    Timeout(6.0, () => { STxA(-1, "de3 trigger already in action"); });// rem out once checks complete
                    break;
            }
            pDE3 = false;
        }
                
        /*===================uk triggered mis======================*/

        if (pUK1 == true)
        {
            switch (ukS1)
            {
                case 1:
                    ukS1 = 2;//on off switch for trigger operation
                    Timeout(rsukS1.Next(100, 901), () => { ukS1 = 1; });//random timer reset function
                    int i = 0;
                    if (TM100s.Count > 0)
                        i = rand.Next(0, TM100s.Count);
                    GamePlay.gpPostMissionLoad(MPtm + TM100s[i].TN);
                    Timeout(4.0, () => { STxA(-1, TM100s[i].TM); });
                    Timeout(6.0, () => { STxA(1, TM100s[i].TMR); STxA(2, TM100s[i].TMB); });
                    break;
                case 2:
                    Timeout(6.0, () => { STxA(-1, "uk1 trigger already in action"); });// rem out once checks complete
                    break;
            }
            pUK1 = false;
        }

        if (pUK2 == true)
        {
            switch (ukS2)
            {
                case 1:
                    ukS2 = 2;//on off switch for trigger operation
                    Timeout(rsukS2.Next(100, 901), () => { ukS2 = 1; });//random timer reset function
                    int i = 0;
                    if (TM100s.Count > 0)
                        i = rand.Next(0, TM100s.Count);
                    GamePlay.gpPostMissionLoad(MPtm + TM100s[i].TN);
                    Timeout(4.0, () => { STxA(-1, TM100s[i].TM); });
                    Timeout(6.0, () => { STxA(1, TM100s[i].TMR); STxA(2, TM100s[i].TMB); });
                    break;
                case 2:
                    Timeout(6.0, () => { STxA(-1, "uk2 trigger already in action"); });// rem out once checks complete
                    break;
            }
            pUK2 = false;
        }

        if (pUK3 == true)
        {
            switch (ukS3)
            {
                case 1:
                    ukS3 = 2;//on off switch for trigger operation
                    Timeout(rsukS3.Next(100, 901), () => { ukS3 = 1; });//random timer reset function
                    int i = 0;
                    if (TM100s.Count > 0)
                        i = rand.Next(0, TM100s.Count);
                    GamePlay.gpPostMissionLoad(MPtm + TM100s[i].TN);
                    Timeout(4.0, () => { STxA(-1, TM100s[i].TM); });
                    Timeout(6.0, () => { STxA(1, TM100s[i].TMR); STxA(2, TM100s[i].TMB); });
                    break;
                case 2:
                    Timeout(6.0, () => { STxA(-1, "uk3 trigger already in action"); });// rem out once checks complete
                    break;
            }
            pUK3 = false;
        }

        /*===================de objective mis======================*/

        if (pDE4 == true)
        {
            switch (deS4)
            {
                case 1:
                    deS4 = 2;//on off switch for trigger operation
                    Timeout(rsdeS4, () => { deS4 = 1; });//timer reset function
                    //int bm = 0;
                    if (TM250s.Count > 0)
                        bm = rand.Next(0, TM250s.Count);
                    GamePlay.gpPostMissionLoad(MPtm + TM250s[bm].TN);
                    Timeout(4.0, () => { STxA(-1, TM250s[bm].TM); });
                    Timeout(6.0, () => { STxA(1, TM250s[bm].TMR); STxA(2, TM250s[bm].TMB); });
                    break;
                case 2:
                    //Timeout(6.0, () => { STxA(-1, "Objective trigger already in action"); });// rem out once checks complete
                    Timeout(6.0, () => { STxA(1, TM250s[bm].TMR); STxA(2, TM250s[bm].TMB); });// repeat mission objective tx
                    break;
            }
            pDE4 = false;
        }

        /*===================uk objective mis======================*/

        if (pUK4 == true)
        {
            switch (ukS4)
            {
                case 1:
                    ukS4 = 2;//on off switch for trigger operation
                    Timeout(rsukS4, () => { ukS4 = 1; });// timer reset function
                    //int rm = 0;
                    if (TM150s.Count > 0)
                        rm = rand.Next(0, TM150s.Count);
                    GamePlay.gpPostMissionLoad(MPtm + TM150s[rm].TN);
                    Timeout(4.0, () => { STxA(-1, TM150s[rm].TM); });
                    Timeout(6.0, () => { STxA(1, TM150s[rm].TMR); STxA(2, TM150s[rm].TMB); });
                    break;
                case 2:
                    //Timeout(6.0, () => { STxA(-1, "Objective trigger already in action"); });// rem out once checks complete
                    Timeout(6.0, () => { STxA(1, TM150s[rm].TMR); STxA(2, TM150s[rm].TMB); });// repeat mission objective tx
                    break;
            }
            pUK4 = false;
        }
    }

    #endregion

    /*=========================================*/
    /*=========================================*/

    #region Despawner  

    /*
    despawner timer added to original code, sets overall time period for actors,
    Advantage is, if delayed, say trying to land behind masses of planes, actors despawn at timer period set anyway.
    allows for players to fly groups of planes, 
    Player can re eneter flights or groups, as bombers take them to target, use each at target then fly group home
    despawn only triggers once player leaves whole group
*/
    public override void OnActorCreated(int missionNumber, string shortName, AiActor actor)
    {
        base.OnActorCreated(missionNumber, shortName, actor);

        // note despawntime (set as varible at start of cs) 
        if (actor is AiGroundActor && missionNumber > 0)//main mission is left alone
            //if ((actor as AiGroundActor).Type() != maddox.game.world.AiGroundActorType.AAGun)//all ai ground except aa guns
            Timeout(despawntime3, () =>
            {
                if (actor != null)
                { (actor as AiGroundActor).Destroy(); }
            });

        if (actor is AiAircraft)        
            Timeout(despawntime, () => { damageAiControlledPlane(actor); });     
    }
 
    public override void OnPlaceLeave(Player player, AiActor actor, int placeIndex)
    {
        base.OnPlaceLeave(player, actor, placeIndex);
        Timeout(despawntime, () => { damageAiControlledPlane(actor); });        
    }
    
    // Path completion despawner, when flight path ends despawner action triggered
    // note:final despawner detects players in group    

    public override void OnActorTaskCompleted(int missionNumber, string shortName, AiActor actor)
    {
        base.OnActorTaskCompleted(missionNumber, shortName, actor);
        if (actor is AiGroundActor) 
            if (actor != null)
                Timeout(despawntime2, () => { (actor as AiGroundActor).Destroy(); });
            
        Timeout(despawntime2, () => { damageAiControlledPlane(actor); });
    }

    //check if a player is in any of the "places"
    private bool isAiControlledPlane(AiAircraft aircraft)
    {
        if (aircraft == null) return false;        
        for (int i = 0; i < aircraft.Places(); i++)
            if (aircraft.Player(i) != null)
                return false;
        return true;
    }

    private void destroyPlane(AiAircraft aircraft)
    {
        if (aircraft != null)
            aircraft.Destroy();
    }

    //actual Aiaircraft despawner, note it polls player detection
    private void damageAiControlledPlane(AiActor actorMain)
    {
        //Timeout(1, () => { STxA(-1, "Despawn time completes for Actor, Despawning"); });//indicates action about to happen, rem out after mission checks complete
        foreach (AiActor actor in actorMain.Group().GetItems())
        {
            if (actor == null || !(actor is AiAircraft))
                return;
            AiAircraft aircraft = (actor as AiAircraft);
            if (!isAiControlledPlane(aircraft))
                return;
            if (aircraft == null)
                return;
            (actor as AiAircraft).Destroy();
        }
    }

    #endregion

    /*=========================================*/
    /*=========================================*/

    #region OnPlaceEnter Welcome Tx, objective creation

    public override void OnPlaceEnter(Player player, AiActor actor, int placeIndex)
    {
        base.OnPlaceEnter(player, actor, placeIndex);
        AiAircraft aircraft = actor as AiAircraft;
        if (aircraft != null)            
            switch (aircraft.Army())
            {
                case 1:
                    if (aircraft.Type() == AircraftType.Bomber)
                    {
                        { GamePlay.gpHUDLogCenter(new Player[] { player }, "Bombers, Check your maps for targets!"); }                        
                    }
                    else { GamePlay.gpHUDLogCenter(new Player[] { player }, "Fighters, Escort Bombers or Patrol the lines!"); }                    
                    pUK4 = true;// set main mission objective group activation true/false
                    TrigMis();// apply the truth
                    break;
                case 2:
                    if (aircraft.Type() == AircraftType.Bomber)
                    {
                        { GamePlay.gpHUDLogCenter(new Player[] { player }, "Bombers, uberprüfen Sie Ihre Karten fur Ziele!"); }                        
                    }
                    else { GamePlay.gpHUDLogCenter(new Player[] { player }, "Fighters, Escort Bombers oder Patrol den Zeilen!"); }                    
                    pDE4 = true;
                    TrigMis();
                break;
            }           
    }

    #endregion

    /*=========================================*/
    /*=========================================*/

    #region STxA Screen Text to Armies

    private void STxA(int army, string Tx, params object[] args)
    { 
        List<Player> Consignees = new List<Player>();
        if (GamePlay.gpPlayer() != null)
            Consignees.Add(GamePlay.gpPlayer());
        if (GamePlay.gpRemotePlayers() != null)
            Consignees.AddRange(GamePlay.gpRemotePlayers());

        if (army == -1)
            GamePlay.gpHUDLogCenter(null, Tx);
        else if (Consignees.Exists(item => item.Army() == army))
            GamePlay.gpHUDLogCenter(Consignees.FindAll(item => item.Army() == army).ToArray(), Tx);        
    }

    #endregion

    /*=========================================*/    
}
//note the last bracket wraps Amission

Last edited by Smokeynz; 03-01-2012 at 07:53 PM.
Reply With Quote