Previous Thread
Next Thread
Print Thread
Rate This Thread
Hop To
Page 2 of 3 1 2 3
#3388681 - 09/12/11 11:17 PM Re: Ambulance Station: notes from the Cavern [Re: Ming_EAF19]  
Joined: Feb 2001
Posts: 1,680
ATAG_Snapper Offline
Member
ATAG_Snapper  Offline
Member

Joined: Feb 2001
Posts: 1,680
Kitchener, Ontario, Canada
The technicals are way out of my league, but it's clear that what you chaps are doing can add a lot of immersion to a mission. Good stuff!


-------------------------------------------------------------------------------------------------

HP Omen Laptop 15, AMD Ryzen 5 5600H 16 GB DDR4 RAM, NVIDIA GeForce RTX 3060 Laptop GPU 6 GB VRAM Win 11 64 bit, Nvidia GeForce Driver ver 512.95, TrackIR 5, Gear Falcon Trim Box, Gear Falcon Throttle Quadrant, TM16000 joystick, TM Warthog HOTAS, CH Quadrant, Saitek Pro Combat rudder pedals
Inline advert (2nd and 3rd post)

#3388692 - 09/12/11 11:27 PM Re: Ambulance Station: notes from the Cavern [Re: Ming_EAF19]  
Joined: Jun 2001
Posts: 2,264
No457_Squog Offline
Squadron Leader
No457_Squog  Offline
Squadron Leader
Member

Joined: Jun 2001
Posts: 2,264
Melbourne, Australia
LoL "Queer Kettenkrad for the Straight Opel Blitz"

I just went through the code and translated (almost) all the russian as well as cleaning it up somewhat. I'm going to test it out and will post the english-ised code once it passes the test.

Working (translated & cleaned) code:
Click to reveal..
Code:
using System;
using System.Collections.Generic;
using maddox.game;
using maddox.game.world;
using maddox.GP;

public class Mission : AMission {
    public override void OnBattleStarted() {
        base.OnBattleStarted();
        MissionNumberListener = -1;
    }
    
    Random rnd = new Random();

    [Flags]
    internal enum ServiceType // Serving type machines
    {
        NONE = 0,
        EMERGENCY = 1,
        FIRE = 2,
        FUEL = 4,
        AMMO = 8,
        BOMBS = 16,
        PRISONERCAPTURE = 32
    }
      
    internal class TechCars { 
        internal AiGroundGroup TechCar { get; set; }        
        internal AiAirport BaseAirport { get; set; }
        internal IRecalcPathParams cur_rp { get; set; }
        internal int RouteFlag = 0;
        internal int cartype = 0;
        internal int servPlaneNum = -1;
        internal ServiceType CarType { get { return (ServiceType)cartype; } set { cartype = (int)value; } }
		
        public TechCars(AiGroundGroup car, AiAirport airoport, IRecalcPathParams rp) {
            this.TechCar = car;            
            this.BaseAirport = airoport;
            this.cur_rp = rp;
        }       
    }

    internal class PlanesQueue {
        internal AiAircraft aircraft { get; set; }
        internal AiAirport baseAirport { get; set; } 
        internal int state = 0;        
        internal ServiceType State { get { return (ServiceType)state; } set { state = (int)value; } }
        internal int Lifetime = 0;
        internal float health = 1;
        public PlanesQueue(AiAircraft aircraft, AiAirport baseAirport, int state) {
            this.aircraft = aircraft;
            this.baseAirport = baseAirport;
            this.state = state;            
        }        
    }

    internal List<TechCars> CurTechCars = new List<TechCars>();
    internal List<PlanesQueue> CurPlanesQueue = new List<PlanesQueue>();
    TechCars TmpCar = null;
    bool MissionLoading = false;

    internal double PseudoRnd(double MinValue, double MaxValue) {
        return rnd.NextDouble() * (MaxValue - MinValue) + MinValue;
    }

    public override void OnActorTaskCompleted(int missionNumber, string shortName, AiActor actor) {
        base.OnActorTaskCompleted(missionNumber, shortName, actor);
		AiActor ai_actor = actor as AiActor;
		if (ai_actor != null) {
            if (ai_actor is AiGroundGroup)
                for (int i = 0; i < CurTechCars.Count; i++) { // If serving the technology reached to serviced aircraft, allow it to be free
					if (CurTechCars[i].TechCar == ai_actor as AiGroundGroup)
                        if (CurTechCars[i].RouteFlag == 1)
                            EndPlaneService(i);
                        else
                            CheckNotServicedPlanes(i);
                };
        }
    }

    internal void CheckNotServicedPlanes(int techCarIndex) {
        for (int j = 0; j < CurPlanesQueue.Count; j++) {
            if (CurTechCars[techCarIndex].TechCar.IsAlive() && (CurPlanesQueue[j].baseAirport == CurTechCars[techCarIndex].BaseAirport) && ((CurTechCars[techCarIndex].CarType & CurPlanesQueue[j].State) != 0) && (CurTechCars[techCarIndex].servPlaneNum == -1)) {
                if (SetEmrgCarRoute(j, techCarIndex)) {  // send a machine to service aircraft found
					return;
                }
            }
        }
    }

    internal void EndPlaneService(int techCarIndex) {
        if (CurTechCars[techCarIndex].cur_rp == null) return;
		CurTechCars[techCarIndex].cur_rp = null; // reset the trip
		if (CurTechCars[techCarIndex].servPlaneNum >= 0) {
			CurPlanesQueue[CurTechCars[techCarIndex].servPlaneNum].State &= ~CurTechCars[techCarIndex].CarType; // remove the type of service in the aircraft serviced, if there is
			CurTechCars[techCarIndex].servPlaneNum = -1; // reset the number of serviced aircraft
			Timeout(5f, () => {
				if (!MoveFromRWay(techCarIndex)) { // check to stand there on ?, and leave with her if so.
					CurTechCars[techCarIndex].RouteFlag = 0;
					CheckNotServicedPlanes(techCarIndex);   // and see if there are still unserved aircraft
				}
			});
		} else Timeout(5f, () => {
			CurTechCars[techCarIndex].RouteFlag = 0;
			CheckNotServicedPlanes(techCarIndex);   // and see if there are still unserved aircraft
		});
	}

    internal bool MoveFromRWay(int carNum) {
        bool result = false;
        if ((GamePlay.gpLandType(CurTechCars[carNum].TechCar.Pos().x, CurTechCars[carNum].TechCar.Pos().y) & LandTypes.ROAD) == 0)
            return result;
        Point3d TmpPos = CurTechCars[carNum].TechCar.Pos();
        while (((GamePlay.gpLandType(TmpPos.x, TmpPos.y) & LandTypes.ROAD) != 0)) {
			TmpPos.x +=  10f;
			TmpPos.y +=  10f;
		};
        Point2d EmgCarStart, EmgCarFinish;
        EmgCarStart.x = CurTechCars[carNum].TechCar.Pos().x; EmgCarStart.y = CurTechCars[carNum].TechCar.Pos().y;
        EmgCarFinish.x = TmpPos.x; EmgCarFinish.y = TmpPos.y;
        CurTechCars[carNum].servPlaneNum = -1;
        CurTechCars[carNum].RouteFlag = 0;
        CurTechCars[carNum].cur_rp = null;
        CurTechCars[carNum].cur_rp = GamePlay.gpFindPath(EmgCarStart, 10f, EmgCarFinish, 10f, PathType.GROUND, CurTechCars[carNum].TechCar.Army());

        result = true;
        return result;
    }

    public  bool SetEmrgCarRoute(int aircraftNumber,int carNum) { 
        bool result = false;
        if (CurTechCars[carNum].TechCar != null) {
            CurTechCars[carNum].servPlaneNum = aircraftNumber; // set the number of serviced aircraft
            if (CurTechCars[carNum].cur_rp == null) {
				Point2d EmgCarStart, EmgCarFinish, LandedPos;
				LandedPos.x = CurPlanesQueue[aircraftNumber].aircraft.Pos().x; LandedPos.y = CurPlanesQueue[aircraftNumber].aircraft.Pos().y;
				int Sign = ((carNum % 2) == 0) ? 2 : -2;
				EmgCarStart.x = CurTechCars[carNum].TechCar.Pos().x; EmgCarStart.y = CurTechCars[carNum].TechCar.Pos().y;
				EmgCarFinish.x = LandedPos.x - PseudoRnd(2f, 5f) * ((LandedPos.x - EmgCarStart.x) / (Math.Abs(LandedPos.x - EmgCarStart.x))) - Sign;
				EmgCarFinish.y = LandedPos.y - PseudoRnd(2f, 5f) * ((LandedPos.y - EmgCarStart.y) / (Math.Abs(LandedPos.y - EmgCarStart.y))) - Sign;
				CurTechCars[carNum].cur_rp = GamePlay.gpFindPath(EmgCarStart, 10f, EmgCarFinish, 10f, PathType.GROUND, CurTechCars[carNum].TechCar.Army());
				result = true;
			}    
        }
        return result;
    }

    public override void OnMissionLoaded(int missionNumber) {
        base.OnMissionLoaded(missionNumber);        
        if (missionNumber > 0) {
            List<string> CarTypes = new List<string>();
            CarTypes.Add(":0_Chief_Emrg_");
            CarTypes.Add(":0_Chief_Fire_");
            CarTypes.Add(":0_Chief_Fuel_");
            CarTypes.Add(":0_Chief_Ammo_");
            CarTypes.Add(":0_Chief_Bomb_");
            CarTypes.Add(":0_Chief_Prisoner_");
            
            AiGroundGroup MyCar = null;
            
            for (int i = 0; i < 3; i++) {
                for (int j = 0; j < CarTypes.Count; j++) {
                    MyCar = GamePlay.gpActorByName(missionNumber.ToString() + CarTypes[j] + i.ToString()) as AiGroundGroup;
                    if (MyCar != null) {
                        TmpCar = new TechCars(MyCar, FindNearestAirport(MyCar), null);
                        TmpCar.CarType = (ServiceType)(1 << j);
                        TmpCar.cur_rp = null;
                        if (!CurTechCars.Contains(TmpCar))
                             CurTechCars.Add(TmpCar);
                        MissionLoading = false;
                    };
                }
            }
        }
    }

    public override void OnTickGame() {
		base.OnTickGame();
		try {
			if (Time.tickCounter() % 64 == 0) {
				for (int i = 0; i < CurPlanesQueue.Count; i++) {
					CurPlanesQueue[i].Lifetime++;
					if ((CurPlanesQueue[i].State == ServiceType.NONE) || (CurPlanesQueue[i].aircraft == null)  || (CurPlanesQueue[i].Lifetime > 200)) {
						for (int j = 0; j < CurTechCars.Count; j++)
							if (CurTechCars[j].servPlaneNum == i)
								EndPlaneService(j);
							CurPlanesQueue.RemoveAt(i);
					}
				};
				for (int i = 0; i < CurTechCars.Count; i++) {
					TechCars car = CurTechCars[i];
					if ((car.TechCar != null && car.cur_rp != null) && (car.cur_rp.State == RecalcPathState.SUCCESS) ) {
						if (car.TechCar.IsAlive() && (car.RouteFlag == 0)/* && (car.servPlaneNum != -1)*/) {
							car.RouteFlag = 1;
							car.cur_rp.Path[0].P.x = car.TechCar.Pos().x; car.cur_rp.Path[0].P.y = car.TechCar.Pos().y;
							car.TechCar.SetWay(car.cur_rp.Path);
							//if (car.servPlaneNum != -1) car.RouteFlag = 0;
						}
					double Dist = Math.Sqrt((car.cur_rp.Path[car.cur_rp.Path.Length - 1].P.x - car.TechCar.Pos().x) * (car.cur_rp.Path[car.cur_rp.Path.Length - 1].P.x - car.TechCar.Pos().x) + (car.cur_rp.Path[car.cur_rp.Path.Length - 1].P.y - car.TechCar.Pos().y) * (car.cur_rp.Path[car.cur_rp.Path.Length - 1].P.y - car.TechCar.Pos().y));
					if (car.servPlaneNum != -1) {
						if (Dist < ((CurPlanesQueue[car.servPlaneNum].aircraft.Type() == AircraftType.Bomber) ? 20f : 10f))
							EndPlaneService(i);
						} else if (Dist < 15f) {
							EndPlaneService(i);
						}
					}
					if ((car.cur_rp == null) && (car.RouteFlag == 0) && (car.servPlaneNum != -1)) {
						EndPlaneService(i);
					};
				};
			}
		} catch (Exception e) {}
	}
	
	internal AiAirport FindNearestAirport(AiActor actor) {
		AiAirport aMin = null;
		double d2Min = 0;
		Point3d pd = actor.Pos();
		int n = GamePlay.gpAirports().Length;
		for (int i = 0; i < n; i++) {
			AiAirport a = (AiAirport)GamePlay.gpAirports()[i];
			
			if (!a.IsAlive())
				continue;
			
			Point3d pp;
			pp = a.Pos();
			pd.z = pp.z;
			double d2 = pd.distanceSquared(ref pp);
			if ((aMin == null) || (d2 < d2Min)) {
				aMin = a;
				d2Min = d2;
			}
		}
		if (d2Min > 2250000.0)
			aMin = null;
		
		return aMin;
	}

    internal ISectionFile CreateEmrgCarMission(Point3d startPos, double fRadius, int portArmy, int planeArmy, AircraftType type, float health, Point3d aircraftPos) {
		ISectionFile f = GamePlay.gpCreateSectionFile();
        string sect;
        string key;
        string value;
        string ChiefName1 = "0_Chief_" + (health < 1f ? "Fire_" : "Fuel_");
        string ChiefName2 = "0_Chief_" + (health < 1f ? "Emrg_" : "Ammo_");
        string ChiefName3 = "0_Chief_" + (health < 1f ? "Bomb_" : "Bomb_");

        if (portArmy == planeArmy) { // its arrived
			switch (portArmy) {
				case 1:
					if (health < 1f) {
						sect = "CustomChiefs";
                        key = "";
                        value = "Vehicle.custom_chief_emrg_0 $core/icons/tank.mma"; // ???????
                        f.add(sect, key, value);
                        value = "Vehicle.custom_chief_emrg_1 $core/icons/tank.mma"; // ambulance
                        f.add(sect, key, value);
						
                        sect = "Vehicle.custom_chief_emrg_0";
                        key = "Car.Austin_K2_ATV";
                        value = "";
                        f.add(sect, key, value);
                        key = "TrailerUnit.Fire_pump_UK2_Transport";
                        value = "1";
                        f.add(sect, key, value);
                        sect = "Vehicle.custom_chief_emrg_1";
                        key = "Car.Austin_K2_Ambulance";
                        value = "";
                        f.add(sect, key, value);
						
                        sect = "Chiefs";
                        key = "0_Chief_Fire_0";
                        value = "Vehicle.custom_chief_emrg_0 gb /skin0 materialsSummer_RAF";
                        f.add(sect, key, value);
                        key = "0_Chief_Emrg_1";
                        value = "Vehicle.custom_chief_emrg_1 gb /skin0 materialsSummer_RAF";
                        f.add(sect, key, value);
					} else {
						sect = "CustomChiefs";
                        key = "";
                        value = "Vehicle.custom_chief_emrg_0 $core/icons/tank.mma";
                        f.add(sect, key, value);
                        value = "Vehicle.custom_chief_emrg_1 $core/icons/tank.mma";
                        f.add(sect, key, value);
						
                        sect = "Vehicle.custom_chief_emrg_0"; // tankers
                        key = "Car.Albion_AM463";
                        value = "";
                        f.add(sect, key, value);
                        if (type == AircraftType.Bomber) { // more bombers to bomb and picked up goryuchku
							key = "Car.Fordson_N";
                            value = "";
                            f.add(sect, key, value);
                            key = "TrailerUnit.Towed_Bowser_UK1_Transport";
                            value = "1";
                            f.add(sect, key, value);
                        }
						
                        sect = "Vehicle.custom_chief_emrg_1"; // weapon
                        value = "";
                        key = "Car.Bedford_MW_open";
                        f.add(sect, key, value);
						
                        if (type == AircraftType.Bomber) { // bombers to bomb picked up
							sect = "CustomChiefs";
                            key = "";
                            value = "Vehicle.custom_chief_emrg_2 $core/icons/tank.mma";
                            f.add(sect, key, value);
                            sect = "Vehicle.custom_chief_emrg_2";
                            value = "";
                            key = "Car.Fordson_N";
                            value = "";
                            f.add(sect, key, value);
                            key = "TrailerUnit.BombLoadingCart_UK1_Transport";
                            value = "1";
                            f.add(sect, key, value);
                            key = "TrailerUnit.BombLoadingCart_UK1_Transport";
                            f.add(sect, key, value);
                        };
						
                        sect = "Chiefs";
                        key = "0_Chief_Fuel_0";
                        value = "Vehicle.custom_chief_emrg_0 gb /skin0 materialsSummer_RAF";
                        f.add(sect, key, value);
						
                        key = "0_Chief_Ammo_1";
                        value = "Vehicle.custom_chief_emrg_1 gb /skin0 materialsSummer_RAF/tow00_00 1_Static";
                        f.add(sect, key, value);
						
                        if (type == AircraftType.Bomber) {
                            key = "0_Chief_Bomb_2";
                            value = "Vehicle.custom_chief_emrg_2 gb /tow01_00 2_Static/tow01_01 3_Static/tow01_02 4_Static/tow01_03 5_Static/tow02_00 6_Static/tow02_01 7_Static";
                            f.add(sect, key, value);
                        }
                        sect = "Stationary";
                        key = "1_Static";
                        value = "Stationary.Morris_CS8-Bedford_MW_CargoAmmo3 gb 0.00 0.00 0.00";
                        f.add(sect, key, value);
                        if (type == AircraftType.Bomber) { // bomb ship
							key = "2_Static";
                            value = "Stationary.Weapons_.Bomb_B_GP_250lb_MkIV gb 0.00 0.00 0.00";
                            f.add(sect, key, value);
                            key = "3_Static";
                            value = "Stationary.Weapons_.Bomb_B_GP_250lb_MkIV gb 0.00 0.00 0.00";
                            f.add(sect, key, value);
                            key = "4_Static";
                            value = "Stationary.Weapons_.Bomb_B_GP_250lb_MkIV gb 0.00 0.00 0.00";
                            f.add(sect, key, value);
                            key = "5_Static";
                            value = "Stationary.Weapons_.Bomb_B_GP_250lb_MkIV gb 0.00 0.00 0.00";
                            f.add(sect, key, value);
                            key = "6_Static";
                            value = "Stationary.Weapons_.Bomb_B_GP_500lb_MkIV gb 0.00 0.00 0.00";
                            f.add(sect, key, value);
                            key = "7_Static";
                            value = "Stationary.Weapons_.Bomb_B_GP_500lb_MkIV gb 0.00 0.00 0.00";
                            f.add(sect, key, value);
                        };
                    };
                    break;
                case 2:
                    sect = "CustomChiefs"; // Pozharka
                    key = "";
                    value = "Vehicle.custom_chief_emrg_0 $core/icons/tank.mma";
                    f.add(sect, key, value);
                    value = "Vehicle.custom_chief_emrg_1 $core/icons/tank.mma"; // ambulance
                    f.add(sect, key, value);
                    if (health < 1f) {
                        sect = "Vehicle.custom_chief_emrg_0";
                        key = "Car.Renault_UE";
                        value = "";
                        f.add(sect, key, value);
                        key = "TrailerUnit.Foam_Extinguisher_GER1_Transport";
                        value = "1";
                        f.add(sect, key, value);
						
                        sect = "Vehicle.custom_chief_emrg_1";
                        if (PseudoRnd(0f, 1f) < 0.5f) {
							key = "Car.Opel_Blitz_med-tent";
                        } else { key = "Car.Opel_Blitz_cargo_med"; };
                        value = "";
                        f.add(sect, key, value);
                        sect = "Chiefs";
                        key = "0_Chief_Fire_0"; // "0_Chief_emrg";
                        value = "Vehicle.custom_chief_emrg_0 de ";
                        f.add(sect, key, value);
                        key = "0_Chief_Emrg_1"; // "0_Chief_emrg";
                        value = "Vehicle.custom_chief_emrg_1 de ";
                        f.add(sect, key, value);
                    } else {
						sect = "Vehicle.custom_chief_emrg_0";
                        key = "Car.Opel_Blitz_fuel";
                        value = "";
                        f.add(sect, key, value);
						
                        sect = "Vehicle.custom_chief_emrg_1";
                        key = "Car.Renault_UE";
                        f.add(sect, key, value);
                        key = "TrailerUnit.Oil_Cart_GER1_Transport";
                        value = "1";
                        f.add(sect, key, value);
                        key = "Car.Renault_UE";
                        value = "";
                        f.add(sect, key, value);
                        key = "TrailerUnit.Anlasswagen_(starter)_GER1_Transport";
                        value = "1";
                        f.add(sect, key, value);
						
                        if (type == AircraftType.Bomber) { // bomb ship
							sect = "CustomChiefs";
                            key = "";
                            value = "Vehicle.custom_chief_emrg_2 $core/icons/tank.mma";
                            f.add(sect, key, value);
                            sect = "Vehicle.custom_chief_emrg_2";
                            key = "Car.Renault_UE";
                            value = "";
                            f.add(sect, key, value);
                            key = "TrailerUnit.HydraulicBombLoader_GER1_Transport";
                            value = "1";
                            f.add(sect, key, value);
                            key = "Car.Renault_UE";
                            value = "";
                            f.add(sect, key, value);
                            key = "TrailerUnit.BombSled_GER1_Transport";
                            value = "1";
                            f.add(sect, key, value);
                        }
						
                        sect = "Chiefs";
                        key = "0_Chief_Fuel_0";
                        value = "Vehicle.custom_chief_emrg_0 de";
                        f.add(sect, key, value);
                        key = "0_Chief_Ammo_1";
                        value = "Vehicle.custom_chief_emrg_1 de";
                        f.add(sect, key, value);
                        if (type == AircraftType.Bomber) {
							key = "0_Chief_Bomb_2";
                            value = "Vehicle.custom_chief_emrg_2 de /tow01_00 1_Static/tow03_00 2_Static";
                            f.add(sect, key, value);
                            sect = "Stationary";
                            key = "1_Static";
                            value = "Stationary.Weapons_.Bomb_B_SC-250_Type2_J de 0.00 0.00 0.00";
                            f.add(sect, key, value);
                            key = "2_Static";
                            value = "Stationary.Weapons_.Bomb_B_SC-1000_C de 0.00 0.00 0.00";
                            f.add(sect, key, value);
                        };
                    };
                    break;
                default:
                    break;
            }
        } else {
			switch (portArmy) {
				case 1:
					if (health < 1f) {
						sect = "CustomChiefs";
                        key = "";
                        value = "Vehicle.custom_chief_emrg_0 $core/icons/tank.mma"; // pozharka
                        f.add(sect, key, value);
                        value = "Vehicle.custom_chief_emrg_1 $core/icons/tank.mma";// ambulance
                        f.add(sect, key, value);
                        value = "Vehicle.custom_chief_emrg_2 $core/icons/tank.mma";// armored car
                        f.add(sect, key, value);
						
                        sect = "Vehicle.custom_chief_emrg_0";
                        key = "Car.Austin_K2_ATV";
                        value = "";
                        f.add(sect, key, value);
                        key = "TrailerUnit.Fire_pump_UK2_Transport";
                        value = "1";
                        f.add(sect, key, value);
						
                        sect = "Vehicle.custom_chief_emrg_1";
                        key = "Car.Austin_K2_Ambulance";
                        value = "";
                        f.add(sect, key, value);
						
                        sect = "Vehicle.custom_chief_emrg_2";
                        key = "Car.Beaverette_III";
                        value = "";
                        f.add(sect, key, value);
						
                        sect = "Chiefs";
                        key = "0_Chief_Fire_0";
                        value = "Vehicle.custom_chief_emrg_0 gb /skin0 materialsSummer_RAF";
                        f.add(sect, key, value);
                        key = "0_Chief_Emrg_1";
                        value = "Vehicle.custom_chief_emrg_1 gb /skin0 materialsSummer_RAF";
                        f.add(sect, key, value);
                        key = "0_Chief_Prisoner_2";
                        value = "Vehicle.custom_chief_emrg_2 gb ";
                        f.add(sect, key, value);
                        ChiefName3 = "0_Chief_Prisoner_";
						
                    } else {
						sect = "CustomChiefs";
                        key = "";
                        value = "Vehicle.custom_chief_emrg_0 $core/icons/tank.mma"; // pozharka
                        f.add(sect, key, value);
                        sect = "Vehicle.custom_chief_emrg_0";
                        key = "Car.Beaverette_III";
                        value = "";
                        f.add(sect, key, value);
                        sect = "Chiefs";
                        key = "0_Chief_Prisoner_0";
                        value = "Vehicle.custom_chief_emrg_0 gb ";
                        f.add(sect, key, value);
                        ChiefName1 = "0_Chief_Prisoner_";
                    };
                    break;
                case 2:
                    if (health < 1f) {
                        sect = "CustomChiefs";
                        key = "";
                        value = "Vehicle.custom_chief_emrg_0 $core/icons/tank.mma"; // pozharka
                        f.add(sect, key, value);
                        value = "Vehicle.custom_chief_emrg_1 $core/icons/tank.mma"; // ambulance
                        f.add(sect, key, value);
                        value = "Vehicle.custom_chief_emrg_2 $core/icons/tank.mma"; // armoured car
                        f.add(sect, key, value);
						
                        sect = "Vehicle.custom_chief_emrg_0";
                        key = "Car.Renault_UE";
                        value = "";
                        f.add(sect, key, value);
                        key = "TrailerUnit.Foam_Extinguisher_GER1_Transport";
                        value = "1";
                        f.add(sect, key, value);
						
                        sect = "Vehicle.custom_chief_emrg_1";
                        key = "Car.Opel_Blitz_cargo_med";
                        value = "";
                        f.add(sect, key, value);
						
                        sect = "Vehicle.custom_chief_emrg_2";
                        key = "Car.SdKfz_231_6Rad";
                        value = "";
                        f.add(sect, key, value);
						
                        sect = "Chiefs";
                        key = "0_Chief_Fire_0";
                        value = "Vehicle.custom_chief_emrg_0 de";
                        f.add(sect, key, value);
                        key = "0_Chief_Emrg_1";
                        value = "Vehicle.custom_chief_emrg_1 de";
                        f.add(sect, key, value);
                        key = "0_Chief_Prisoner_2";
                        value = "Vehicle.custom_chief_emrg_2 de /marker0 1940-42_var1";
                        f.add(sect, key, value);
                        ChiefName3 = "0_Chief_Prisoner_";
                    } else {
						sect = "CustomChiefs";
                        key = "";
                        value = "Vehicle.custom_chief_emrg_0 $core/icons/tank.mma"; // pozharka
                        f.add(sect, key, value);
                        sect = "Vehicle.custom_chief_emrg_0";
                        key = "Car.SdKfz_231_6Rad";
                        value = "";
                        f.add(sect, key, value);
                        sect = "Chiefs";
                        key = "0_Chief_Prisoner_0";
                        value = "Vehicle.custom_chief_emrg_0 de /marker0 1940-42_var1";
                        f.add(sect, key, value);
                        ChiefName1 = "0_Chief_Prisoner_";
                    };
                    break;
                default:
                    break;
            };
        }
		
        Point3d TmpStartPos = startPos;
        TmpStartPos.x += PseudoRnd(-30f, 30f) + fRadius; TmpStartPos.y += PseudoRnd(-30f, 30f) + fRadius;
        Point3d BirthPos = EmrgVehicleStartPos(TmpStartPos, startPos);
		
        sect = ChiefName1+"0" + "_Road";
        key = "";
        value = BirthPos.x.ToString(System.Globalization.CultureInfo.InvariantCulture.NumberFormat) + " " + BirthPos.y.ToString(System.Globalization.CultureInfo.InvariantCulture.NumberFormat) + " " + BirthPos.z.ToString(System.Globalization.CultureInfo.InvariantCulture.NumberFormat) + "  0 92 5 ";
        f.add(sect, key, value);
        BirthPos.x -= 50f * ((BirthPos.x - aircraftPos.x) / Math.Abs(BirthPos.x - aircraftPos.x)); BirthPos.y -= 50f * ((BirthPos.y - aircraftPos.y) / Math.Abs(BirthPos.y - aircraftPos.y));
        value = BirthPos.x.ToString(System.Globalization.CultureInfo.InvariantCulture.NumberFormat) + " " + BirthPos.y.ToString(System.Globalization.CultureInfo.InvariantCulture.NumberFormat) + " " + BirthPos.z.ToString(System.Globalization.CultureInfo.InvariantCulture.NumberFormat);
        f.add(sect, key, value);
		
        TmpStartPos = startPos;
        TmpStartPos.x += PseudoRnd(-30f, 30f) - fRadius; TmpStartPos.y += PseudoRnd(-30f, 30f) + fRadius;
        BirthPos = EmrgVehicleStartPos(TmpStartPos, startPos);
        //BirthPos = TmpStartPos;
        sect = ChiefName2+"1" + "_Road";
        key = "";
        value = BirthPos.x.ToString(System.Globalization.CultureInfo.InvariantCulture.NumberFormat) + " " + BirthPos.y.ToString(System.Globalization.CultureInfo.InvariantCulture.NumberFormat) + " " + BirthPos.z.ToString(System.Globalization.CultureInfo.InvariantCulture.NumberFormat) + "  0 92 5 ";
        f.add(sect, key, value);
        BirthPos.x -= 50f * ((BirthPos.x - aircraftPos.x) / Math.Abs(BirthPos.x - aircraftPos.x)); BirthPos.y -= 50f * ((BirthPos.y - aircraftPos.y) / Math.Abs(BirthPos.y - aircraftPos.y));
        value = BirthPos.x.ToString(System.Globalization.CultureInfo.InvariantCulture.NumberFormat) + " " + BirthPos.y.ToString(System.Globalization.CultureInfo.InvariantCulture.NumberFormat) + " " + BirthPos.z.ToString(System.Globalization.CultureInfo.InvariantCulture.NumberFormat);
        f.add(sect, key, value);
		
        TmpStartPos = startPos;
        TmpStartPos.x += PseudoRnd(-30f, 30f) + fRadius; TmpStartPos.y += PseudoRnd(-30f, 30f) - fRadius;
        BirthPos = EmrgVehicleStartPos(TmpStartPos, startPos);
		
        sect = ChiefName3 + "2" + "_Road";
        key = "";
        value = BirthPos.x.ToString(System.Globalization.CultureInfo.InvariantCulture.NumberFormat) + " " + BirthPos.y.ToString(System.Globalization.CultureInfo.InvariantCulture.NumberFormat) + " " + BirthPos.z.ToString(System.Globalization.CultureInfo.InvariantCulture.NumberFormat) + "  0 92 5 ";
        f.add(sect, key, value);
        BirthPos.x -= 50f * ((BirthPos.x - aircraftPos.x) / Math.Abs(BirthPos.x - aircraftPos.x)); BirthPos.y -= 50f * ((BirthPos.y - aircraftPos.y) / Math.Abs(BirthPos.y - aircraftPos.y));
        value = BirthPos.x.ToString(System.Globalization.CultureInfo.InvariantCulture.NumberFormat) + " " + BirthPos.y.ToString(System.Globalization.CultureInfo.InvariantCulture.NumberFormat) + " " + BirthPos.z.ToString(System.Globalization.CultureInfo.InvariantCulture.NumberFormat);
        f.add(sect, key, value);
        
        return f;
    }
	
    internal Point3d EmrgVehicleStartPos(Point3d startPos, Point3d endPos) {
		Point3d TmpPos = startPos;
		
        while (((GamePlay.gpLandType(TmpPos.x, TmpPos.y) & LandTypes.WATER) != 0) ) {
			TmpPos.x -= (TmpPos.x - endPos.x) / 10f;
			TmpPos.y -= (TmpPos.y - endPos.y) / 10f;
        };
		return TmpPos;
	}
	
    internal void CheckEmrgCarOnAirport(int aircraftNumber)
    {
        // Check whether there cars at the airport
        AiGroundGroup MyCar = null;
        for (int i = 0; i < CurTechCars.Count; i++) {
			if (CurTechCars[i].TechCar != null ) {
				if (CurTechCars[i].TechCar.IsAlive() && CurTechCars[i].BaseAirport == CurPlanesQueue[aircraftNumber].baseAirport && (CurTechCars[i].CarType & CurPlanesQueue[aircraftNumber].State)!=0) {
					MissionLoading = false;
                    MyCar = CurTechCars[i].TechCar;
                    if ((CurTechCars[i].cur_rp == null) && (CurTechCars[i].RouteFlag == 0) && (CurTechCars[i].servPlaneNum == -1)) // ???? ????? ??? ???? - ???????? ????????
                        SetEmrgCarRoute(aircraftNumber, i);
				}
			}
		};
        if ((MyCar == null) && !MissionLoading) {
			MissionLoading = true;
            int ArmyPos = 0;
            if (GamePlay.gpFrontExist()) {
				ArmyPos = GamePlay.gpFrontArmy(CurPlanesQueue[aircraftNumber].baseAirport.Pos().x, CurPlanesQueue[aircraftNumber].baseAirport.Pos().y);
            } else { ArmyPos = CurPlanesQueue[aircraftNumber].aircraft.Army(); };
            // Create a mission with cars
            GamePlay.gpPostMissionLoad(CreateEmrgCarMission(CurPlanesQueue[aircraftNumber].baseAirport.Pos(), (CurPlanesQueue[aircraftNumber].baseAirport.FieldR() / 4), ArmyPos, CurPlanesQueue[aircraftNumber].aircraft.Army(), CurPlanesQueue[aircraftNumber].aircraft.Type(),CurPlanesQueue[aircraftNumber].health, CurPlanesQueue[aircraftNumber].aircraft.Pos()));
        }        
        return;
	}

	public override void OnAircraftCrashLanded(int missionNumber, string shortName, AiAircraft aircraft) {
		base.OnAircraftCrashLanded(missionNumber, shortName, aircraft);
		Timeout(5, () => {
			aircraft.Destroy();
		});
	}
	
    public override void OnAircraftLanded(int missionNumber, string shortName, AiAircraft aircraft) {
		base.OnAircraftLanded(missionNumber, shortName, aircraft);
        
        AiAirport NearestAirport = FindNearestAirport(aircraft);
        if (NearestAirport != null) {
            PlanesQueue CurPlane = new PlanesQueue(aircraft, NearestAirport, 0);
            int ArmyPos = 0;
            CurPlane.health = (float)aircraft.getParameter(part.ParameterTypes.M_Health, -1);
            if (GamePlay.gpFrontExist()) {
                ArmyPos = GamePlay.gpFrontArmy(NearestAirport.Pos().x, NearestAirport.Pos().y);
            } else { ArmyPos = aircraft.Army(); };
            if (CurPlane.health < 1f) {
				CurPlane.State |= ServiceType.EMERGENCY;
                CurPlane.State |= ServiceType.FIRE;
			} else if (aircraft.Army() == ArmyPos) {
				CurPlane.State |= ServiceType.FUEL;
                CurPlane.State |= ServiceType.AMMO;
                if (aircraft.Type() == AircraftType.Bomber) CurPlane.State |= ServiceType.BOMBS;
            };
            if (!(aircraft.Army() == ArmyPos)) CurPlane.State |= ServiceType.PRISONERCAPTURE;
            if (!CurPlanesQueue.Contains(CurPlane)) {
				CurPlanesQueue.Add(CurPlane);
                CheckEmrgCarOnAirport(CurPlanesQueue.Count - 1);                
            } else {
				for (int i = 0; i < CurPlanesQueue.Count; i++)
                    if (CurPlanesQueue[i] == CurPlane) { 
						CheckEmrgCarOnAirport(i);
						break;
					}
            }
            CurPlane = null;
        };
    }
}


No457_Squog
Squadron Leader

No. 457 Squadron vRAAF
#3388933 - 09/13/11 07:34 AM Re: Ambulance Station: notes from the Cavern [Re: Ming_EAF19]  
Joined: Apr 2011
Posts: 507
JG52Krupi Offline
Member
JG52Krupi  Offline
Member

Joined: Apr 2011
Posts: 507
180
Wow that's brilliant thanks for sharing guys, any luck with the wreck dragging?

#3388985 - 09/13/11 11:23 AM Re: Ambulance Station: notes from the Cavern [Re: Ming_EAF19]  
Joined: Sep 2004
Posts: 10,618
Ming_EAF19 Offline
Babelfish Immune
Ming_EAF19  Offline
Babelfish Immune
Veteran

Joined: Sep 2004
Posts: 10,618
London
wreck dragging?

We land damaged and a tractor comes close. Can a Player's plane object be moved in XYZ. That would be fun for the human pilot

An AI plane lands damaged and a tractor comes close. Can an AI plane model with missing undercarriage/broken gear be moved in XYZ

Moving objects is the general requirement: which FMB objects can be moved (not via waypoints) to new positions?

Or perhaps destroyed first, to spawn some distance (10cm) away to give the appearance of movement (24fps stop-motion) Smile2

Krupi I think the community-contributed scripts above and elsewhere are moving the ambulance/vehicles by setting waypoints, a high-level
operation. The intelligent vehicles take the waypoint positions and move around.
The operation you want to see would use a different method, maybe a MoveTo command, something like that. Shuffling mechanics swarming the wreckage

You're going to need a crane btw Smile2

Ming


'You are either a hater or you are not' Roman Halter
#3390129 - 09/14/11 09:54 PM Re: Ambulance Station: notes from the Cavern [Re: Ming_EAF19]  
Joined: May 2007
Posts: 1,562
Cold_Gambler Offline
Member
Cold_Gambler  Offline
Member

Joined: May 2007
Posts: 1,562
Fascinating stuff!! Scripts like these will really bring a lot of "life" to airfields!

Is there a human "object" (independent of associated vehicles)?
Could we have pilots at the tea wagon, air raid siren trigger, pilots run to aircraft (disappear), reappear in cockpits and start up engines?
Could we have player returns to home field with 2+ victories, safe landing, engine off, spawn group of 7+ humans to crowd around player's stopped aircraft champagne optional? returns with 4+ victories group of 14+ humans spawn, that kind of thing...


looks very modernishy-phoney-windows eighty-tabletty like

Asus P8P67 Pro Rev. 3.0 // i5 2500k @4.3 GHz with Noctua NH-D14 // nvidia gtx 780 // 8 GB DDR3 1600 //Win7 home 64 bit //450 GB VelociRaptor //Recon3D Champion
#3390148 - 09/14/11 10:13 PM Re: Ambulance Station: notes from the Cavern [Re: Ming_EAF19]  
Joined: Apr 2002
Posts: 13,364
Freycinet Offline
Veteran
Freycinet  Offline
Veteran

Joined: Apr 2002
Posts: 13,364
Cool that these vehicles spawn wherever needed and only if needed. This is just a beginning and 1C should really have released the sim with a ton of scripts for mission designers to use out of the box, but better late than never...


My Il-2 CoD movie web site: www.flightsimvids.com
#3390290 - 09/15/11 01:53 AM Re: Ambulance Station: notes from the Cavern [Re: Ming_EAF19]  
Joined: May 2007
Posts: 1,562
Cold_Gambler Offline
Member
Cold_Gambler  Offline
Member

Joined: May 2007
Posts: 1,562
If/when an SDK explaining the scripts comes out I think we'll have our minds blown. I suspect this ambulance example is just the tip of the iceberg.

That said, I really hope that someone will put together an application that will allow people without programming knowledge (like me) to implement and adapt scripts. That would lead to a real explosion in creative output imo smile


looks very modernishy-phoney-windows eighty-tabletty like

Asus P8P67 Pro Rev. 3.0 // i5 2500k @4.3 GHz with Noctua NH-D14 // nvidia gtx 780 // 8 GB DDR3 1600 //Win7 home 64 bit //450 GB VelociRaptor //Recon3D Champion
#3390412 - 09/15/11 05:25 AM Re: Ambulance Station: notes from the Cavern [Re: Cold_Gambler]  
Joined: Dec 2002
Posts: 19,381
Ajay Offline
newbie
Ajay  Offline
newbie
Veteran

Joined: Dec 2002
Posts: 19,381
Brisbane OZ
Originally Posted By: Cold_Gambler
If/when an SDK explaining the scripts comes out I think we'll have our minds blown. I suspect this ambulance example is just the tip of the iceberg.

That said, I really hope that someone will put together an application that will allow people without programming knowledge (like me) to implement and adapt scripts. That would lead to a real explosion in creative output imo smile


Yes.

Let the brave cavern warriors above venture into the scary unknown with wooden swords and cardboard helmets.We shall sit outside eating fresh fruit of yon maidens fine midriff and await their successful return, hopefully armed with plentiful knowledge of the inner workings and the secrets to building a fine calculating machine with big glossy buttons and preordained scripts..with pretty pictures.And no DOONK ! ™ microsoft error noises.For that is the road to folly and bent swords.


My il2 page
Seelowe Campaign
Cliffs of Dover page
CloD
My Models
Tanks/Planes/Ships


#3390793 - 09/15/11 07:22 PM Re: Ambulance Station: notes from the Cavern [Re: Ming_EAF19]  
Joined: May 2007
Posts: 1,562
Cold_Gambler Offline
Member
Cold_Gambler  Offline
Member

Joined: May 2007
Posts: 1,562
Yep, Ajay biggrin that pretty much sums up my wishes and hopes rofl...

Wouldja pass me some more grapes please?


looks very modernishy-phoney-windows eighty-tabletty like

Asus P8P67 Pro Rev. 3.0 // i5 2500k @4.3 GHz with Noctua NH-D14 // nvidia gtx 780 // 8 GB DDR3 1600 //Win7 home 64 bit //450 GB VelociRaptor //Recon3D Champion
#3390817 - 09/15/11 08:08 PM Re: Ambulance Station: notes from the Cavern [Re: Ming_EAF19]  
Joined: Sep 2001
Posts: 2,890
Warbirds Offline
Senior Member
Warbirds  Offline
Senior Member

Joined: Sep 2001
Posts: 2,890
Is there a trick to getting this to work? I added the script from naryv to a cs file for that mission and went in and landed several times. Only one time did I see two vehicles come close but then they went another direction away from me. I tried many times, landing, crashing but nothing. Do you have to land in a certain area or spot or crash in a specail place on the airfield?

Last edited by Warbirds; 09/15/11 08:09 PM.

"A time when America was great,,when the chrome was thick and the women were straight" - Micheal Savage

"If you really want to experience flight in this life then you have to strap a DC-3 to your ass." - Buffalo Joe McBryan President & Captain Buffalo Airways
#3390832 - 09/15/11 08:20 PM Re: Ambulance Station: notes from the Cavern [Re: Warbirds]  
Joined: Jan 2009
Posts: 4,737
FearlessFrog Offline
Senior Member
FearlessFrog  Offline
Senior Member

Joined: Jan 2009
Posts: 4,737
Originally Posted By: Warbirds
Is there a trick to getting this to work? I added the script from naryv to a cs file for that mission and went in and landed several times. Only one time did I see two vehicles come close but then they went another direction away from me. I tried many times, landing, crashing but nothing. Do you have to land in a certain area or spot or crash in a specail place on the airfield?


I think naryv's script does limit the range, or rather measures the distance from an airport, so you might be too far. I've not had it not work, so guessing I'd try the following:

- Take off from the airport you want to do the test for.

- Do a wheels up landing on the runway as a first test.

- Take off and land a red plane in a blue base as a follow up test.

#3391023 - 09/16/11 01:17 AM Re: Ambulance Station: notes from the Cavern [Re: FearlessFrog]  
Joined: Nov 2002
Posts: 3,984
-Avatar- Offline
Senior Member
-Avatar-  Offline
Senior Member

Joined: Nov 2002
Posts: 3,984
CT, USA
jawdrop
Wow! I've been in computer h$ll for awhile now and just did major surgery on my motherboard to repair a faulty SATA port connection so I haven't been popping on here to look much of late... Can't believe what you guys are discovering!! Cool stuff.


Avatar

Asus P8Z68 Deluxe, i7 2700k @4.7GHz, EVGA GTX570HD 301.42s, 1x120gb SSD, 2x150gb WD Raptors, 2x200gb SATA, 16gb G.Skill DDR3 2130, 1000W PS, HP DVD-RW, Onboard sound, 32" Sony Bravia XBR, Win7 Pro 64bit, Tai Chi watercooled case
#3391072 - 09/16/11 03:00 AM Re: Ambulance Station: notes from the Cavern [Re: Ming_EAF19]  
Joined: Jul 2010
Posts: 638
ATAG_Bliss Offline
Member
ATAG_Bliss  Offline
Member

Joined: Jul 2010
Posts: 638
Awesome stuff fellas! Getting around these scripts are making my head go skyisfalling skyisfalling

Now what if the fire truck sprayed water and the ambulance had flashing lights. I could just see it now, a badly damaged spit with an engine fire coming in for a landing on finals, 3 fire trucks spawn and spray it out of the air biggrin

I do hope that some of the lights get activated soon. I miss my landing/taxi lights from IL2. Makes it soo much easier to form up with a buddy on coms as well. And to stick out like a sore thumb when you forget to shut them off :P

#3391104 - 09/16/11 04:03 AM Re: Ambulance Station: notes from the Cavern [Re: No457_Squog]  
Joined: Sep 2010
Posts: 29
charlo Offline
Junior Member
charlo  Offline
Junior Member

Joined: Sep 2010
Posts: 29
Los Angeles, CA, USA
Originally Posted By: No457_Squog
LoL "Queer Kettenkrad for the Straight Opel Blitz"

I just went through the code and translated (almost) all the russian as well as cleaning it up somewhat. I'm going to test it out and will post the english-ised code once it passes the test.

Working (translated & cleaned) code:
Click to reveal..
Code:
using System;
using System.Collections.Generic;
using maddox.game;
using maddox.game.world;
using maddox.GP;

public class Mission : AMission {
    public override void OnBattleStarted() {
        base.OnBattleStarted();
        MissionNumberListener = -1;
    }
    
    Random rnd = new Random();

    [Flags]
    internal enum ServiceType // Serving type machines
    {
        NONE = 0,
        EMERGENCY = 1,
        FIRE = 2,
        FUEL = 4,
        AMMO = 8,
        BOMBS = 16,
        PRISONERCAPTURE = 32
    }
      
    internal class TechCars { 
        internal AiGroundGroup TechCar { get; set; }        
        internal AiAirport BaseAirport { get; set; }
        internal IRecalcPathParams cur_rp { get; set; }
        internal int RouteFlag = 0;
        internal int cartype = 0;
        internal int servPlaneNum = -1;
        internal ServiceType CarType { get { return (ServiceType)cartype; } set { cartype = (int)value; } }
		
        public TechCars(AiGroundGroup car, AiAirport airoport, IRecalcPathParams rp) {
            this.TechCar = car;            
            this.BaseAirport = airoport;
            this.cur_rp = rp;
        }       
    }

    internal class PlanesQueue {
        internal AiAircraft aircraft { get; set; }
        internal AiAirport baseAirport { get; set; } 
        internal int state = 0;        
        internal ServiceType State { get { return (ServiceType)state; } set { state = (int)value; } }
        internal int Lifetime = 0;
        internal float health = 1;
        public PlanesQueue(AiAircraft aircraft, AiAirport baseAirport, int state) {
            this.aircraft = aircraft;
            this.baseAirport = baseAirport;
            this.state = state;            
        }        
    }

    internal List<TechCars> CurTechCars = new List<TechCars>();
    internal List<PlanesQueue> CurPlanesQueue = new List<PlanesQueue>();
    TechCars TmpCar = null;
    bool MissionLoading = false;

    internal double PseudoRnd(double MinValue, double MaxValue) {
        return rnd.NextDouble() * (MaxValue - MinValue) + MinValue;
    }

    public override void OnActorTaskCompleted(int missionNumber, string shortName, AiActor actor) {
        base.OnActorTaskCompleted(missionNumber, shortName, actor);
		AiActor ai_actor = actor as AiActor;
		if (ai_actor != null) {
            if (ai_actor is AiGroundGroup)
                for (int i = 0; i < CurTechCars.Count; i++) { // If serving the technology reached to serviced aircraft, allow it to be free
					if (CurTechCars[i].TechCar == ai_actor as AiGroundGroup)
                        if (CurTechCars[i].RouteFlag == 1)
                            EndPlaneService(i);
                        else
                            CheckNotServicedPlanes(i);
                };
        }
    }

    internal void CheckNotServicedPlanes(int techCarIndex) {
        for (int j = 0; j < CurPlanesQueue.Count; j++) {
            if (CurTechCars[techCarIndex].TechCar.IsAlive() && (CurPlanesQueue[j].baseAirport == CurTechCars[techCarIndex].BaseAirport) && ((CurTechCars[techCarIndex].CarType & CurPlanesQueue[j].State) != 0) && (CurTechCars[techCarIndex].servPlaneNum == -1)) {
                if (SetEmrgCarRoute(j, techCarIndex)) {  // send a machine to service aircraft found
					return;
                }
            }
        }
    }

    internal void EndPlaneService(int techCarIndex) {
        if (CurTechCars[techCarIndex].cur_rp == null) return;
		CurTechCars[techCarIndex].cur_rp = null; // reset the trip
		if (CurTechCars[techCarIndex].servPlaneNum >= 0) {
			CurPlanesQueue[CurTechCars[techCarIndex].servPlaneNum].State &= ~CurTechCars[techCarIndex].CarType; // remove the type of service in the aircraft serviced, if there is
			CurTechCars[techCarIndex].servPlaneNum = -1; // reset the number of serviced aircraft
			Timeout(5f, () => {
				if (!MoveFromRWay(techCarIndex)) { // check to stand there on ?, and leave with her if so.
					CurTechCars[techCarIndex].RouteFlag = 0;
					CheckNotServicedPlanes(techCarIndex);   // and see if there are still unserved aircraft
				}
			});
		} else Timeout(5f, () => {
			CurTechCars[techCarIndex].RouteFlag = 0;
			CheckNotServicedPlanes(techCarIndex);   // and see if there are still unserved aircraft
		});
	}

    internal bool MoveFromRWay(int carNum) {
        bool result = false;
        if ((GamePlay.gpLandType(CurTechCars[carNum].TechCar.Pos().x, CurTechCars[carNum].TechCar.Pos().y) & LandTypes.ROAD) == 0)
            return result;
        Point3d TmpPos = CurTechCars[carNum].TechCar.Pos();
        while (((GamePlay.gpLandType(TmpPos.x, TmpPos.y) & LandTypes.ROAD) != 0)) {
			TmpPos.x +=  10f;
			TmpPos.y +=  10f;
		};
        Point2d EmgCarStart, EmgCarFinish;
        EmgCarStart.x = CurTechCars[carNum].TechCar.Pos().x; EmgCarStart.y = CurTechCars[carNum].TechCar.Pos().y;
        EmgCarFinish.x = TmpPos.x; EmgCarFinish.y = TmpPos.y;
        CurTechCars[carNum].servPlaneNum = -1;
        CurTechCars[carNum].RouteFlag = 0;
        CurTechCars[carNum].cur_rp = null;
        CurTechCars[carNum].cur_rp = GamePlay.gpFindPath(EmgCarStart, 10f, EmgCarFinish, 10f, PathType.GROUND, CurTechCars[carNum].TechCar.Army());

        result = true;
        return result;
    }

    public  bool SetEmrgCarRoute(int aircraftNumber,int carNum) { 
        bool result = false;
        if (CurTechCars[carNum].TechCar != null) {
            CurTechCars[carNum].servPlaneNum = aircraftNumber; // set the number of serviced aircraft
            if (CurTechCars[carNum].cur_rp == null) {
				Point2d EmgCarStart, EmgCarFinish, LandedPos;
				LandedPos.x = CurPlanesQueue[aircraftNumber].aircraft.Pos().x; LandedPos.y = CurPlanesQueue[aircraftNumber].aircraft.Pos().y;
				int Sign = ((carNum % 2) == 0) ? 2 : -2;
				EmgCarStart.x = CurTechCars[carNum].TechCar.Pos().x; EmgCarStart.y = CurTechCars[carNum].TechCar.Pos().y;
				EmgCarFinish.x = LandedPos.x - PseudoRnd(2f, 5f) * ((LandedPos.x - EmgCarStart.x) / (Math.Abs(LandedPos.x - EmgCarStart.x))) - Sign;
				EmgCarFinish.y = LandedPos.y - PseudoRnd(2f, 5f) * ((LandedPos.y - EmgCarStart.y) / (Math.Abs(LandedPos.y - EmgCarStart.y))) - Sign;
				CurTechCars[carNum].cur_rp = GamePlay.gpFindPath(EmgCarStart, 10f, EmgCarFinish, 10f, PathType.GROUND, CurTechCars[carNum].TechCar.Army());
				result = true;
			}    
        }
        return result;
    }

    public override void OnMissionLoaded(int missionNumber) {
        base.OnMissionLoaded(missionNumber);        
        if (missionNumber > 0) {
            List<string> CarTypes = new List<string>();
            CarTypes.Add(":0_Chief_Emrg_");
            CarTypes.Add(":0_Chief_Fire_");
            CarTypes.Add(":0_Chief_Fuel_");
            CarTypes.Add(":0_Chief_Ammo_");
            CarTypes.Add(":0_Chief_Bomb_");
            CarTypes.Add(":0_Chief_Prisoner_");
            
            AiGroundGroup MyCar = null;
            
            for (int i = 0; i < 3; i++) {
                for (int j = 0; j < CarTypes.Count; j++) {
                    MyCar = GamePlay.gpActorByName(missionNumber.ToString() + CarTypes[j] + i.ToString()) as AiGroundGroup;
                    if (MyCar != null) {
                        TmpCar = new TechCars(MyCar, FindNearestAirport(MyCar), null);
                        TmpCar.CarType = (ServiceType)(1 << j);
                        TmpCar.cur_rp = null;
                        if (!CurTechCars.Contains(TmpCar))
                             CurTechCars.Add(TmpCar);
                        MissionLoading = false;
                    };
                }
            }
        }
    }

    public override void OnTickGame() {
		base.OnTickGame();
		try {
			if (Time.tickCounter() % 64 == 0) {
				for (int i = 0; i < CurPlanesQueue.Count; i++) {
					CurPlanesQueue[i].Lifetime++;
					if ((CurPlanesQueue[i].State == ServiceType.NONE) || (CurPlanesQueue[i].aircraft == null)  || (CurPlanesQueue[i].Lifetime > 200)) {
						for (int j = 0; j < CurTechCars.Count; j++)
							if (CurTechCars[j].servPlaneNum == i)
								EndPlaneService(j);
							CurPlanesQueue.RemoveAt(i);
					}
				};
				for (int i = 0; i < CurTechCars.Count; i++) {
					TechCars car = CurTechCars[i];
					if ((car.TechCar != null && car.cur_rp != null) && (car.cur_rp.State == RecalcPathState.SUCCESS) ) {
						if (car.TechCar.IsAlive() && (car.RouteFlag == 0)/* && (car.servPlaneNum != -1)*/) {
							car.RouteFlag = 1;
							car.cur_rp.Path[0].P.x = car.TechCar.Pos().x; car.cur_rp.Path[0].P.y = car.TechCar.Pos().y;
							car.TechCar.SetWay(car.cur_rp.Path);
							//if (car.servPlaneNum != -1) car.RouteFlag = 0;
						}
					double Dist = Math.Sqrt((car.cur_rp.Path[car.cur_rp.Path.Length - 1].P.x - car.TechCar.Pos().x) * (car.cur_rp.Path[car.cur_rp.Path.Length - 1].P.x - car.TechCar.Pos().x) + (car.cur_rp.Path[car.cur_rp.Path.Length - 1].P.y - car.TechCar.Pos().y) * (car.cur_rp.Path[car.cur_rp.Path.Length - 1].P.y - car.TechCar.Pos().y));
					if (car.servPlaneNum != -1) {
						if (Dist < ((CurPlanesQueue[car.servPlaneNum].aircraft.Type() == AircraftType.Bomber) ? 20f : 10f))
							EndPlaneService(i);
						} else if (Dist < 15f) {
							EndPlaneService(i);
						}
					}
					if ((car.cur_rp == null) && (car.RouteFlag == 0) && (car.servPlaneNum != -1)) {
						EndPlaneService(i);
					};
				};
			}
		} catch (Exception e) {}
	}
	
	internal AiAirport FindNearestAirport(AiActor actor) {
		AiAirport aMin = null;
		double d2Min = 0;
		Point3d pd = actor.Pos();
		int n = GamePlay.gpAirports().Length;
		for (int i = 0; i < n; i++) {
			AiAirport a = (AiAirport)GamePlay.gpAirports()[i];
			
			if (!a.IsAlive())
				continue;
			
			Point3d pp;
			pp = a.Pos();
			pd.z = pp.z;
			double d2 = pd.distanceSquared(ref pp);
			if ((aMin == null) || (d2 < d2Min)) {
				aMin = a;
				d2Min = d2;
			}
		}
		if (d2Min > 2250000.0)
			aMin = null;
		
		return aMin;
	}

    internal ISectionFile CreateEmrgCarMission(Point3d startPos, double fRadius, int portArmy, int planeArmy, AircraftType type, float health, Point3d aircraftPos) {
		ISectionFile f = GamePlay.gpCreateSectionFile();
        string sect;
        string key;
        string value;
        string ChiefName1 = "0_Chief_" + (health < 1f ? "Fire_" : "Fuel_");
        string ChiefName2 = "0_Chief_" + (health < 1f ? "Emrg_" : "Ammo_");
        string ChiefName3 = "0_Chief_" + (health < 1f ? "Bomb_" : "Bomb_");

        if (portArmy == planeArmy) { // its arrived
			switch (portArmy) {
				case 1:
					if (health < 1f) {
						sect = "CustomChiefs";
                        key = "";
                        value = "Vehicle.custom_chief_emrg_0 $core/icons/tank.mma"; // ???????
                        f.add(sect, key, value);
                        value = "Vehicle.custom_chief_emrg_1 $core/icons/tank.mma"; // ambulance
                        f.add(sect, key, value);
						
                        sect = "Vehicle.custom_chief_emrg_0";
                        key = "Car.Austin_K2_ATV";
                        value = "";
                        f.add(sect, key, value);
                        key = "TrailerUnit.Fire_pump_UK2_Transport";
                        value = "1";
                        f.add(sect, key, value);
                        sect = "Vehicle.custom_chief_emrg_1";
                        key = "Car.Austin_K2_Ambulance";
                        value = "";
                        f.add(sect, key, value);
						
                        sect = "Chiefs";
                        key = "0_Chief_Fire_0";
                        value = "Vehicle.custom_chief_emrg_0 gb /skin0 materialsSummer_RAF";
                        f.add(sect, key, value);
                        key = "0_Chief_Emrg_1";
                        value = "Vehicle.custom_chief_emrg_1 gb /skin0 materialsSummer_RAF";
                        f.add(sect, key, value);
					} else {
						sect = "CustomChiefs";
                        key = "";
                        value = "Vehicle.custom_chief_emrg_0 $core/icons/tank.mma";
                        f.add(sect, key, value);
                        value = "Vehicle.custom_chief_emrg_1 $core/icons/tank.mma";
                        f.add(sect, key, value);
						
                        sect = "Vehicle.custom_chief_emrg_0"; // tankers
                        key = "Car.Albion_AM463";
                        value = "";
                        f.add(sect, key, value);
                        if (type == AircraftType.Bomber) { // more bombers to bomb and picked up goryuchku
							key = "Car.Fordson_N";
                            value = "";
                            f.add(sect, key, value);
                            key = "TrailerUnit.Towed_Bowser_UK1_Transport";
                            value = "1";
                            f.add(sect, key, value);
                        }
						
                        sect = "Vehicle.custom_chief_emrg_1"; // weapon
                        value = "";
                        key = "Car.Bedford_MW_open";
                        f.add(sect, key, value);
						
                        if (type == AircraftType.Bomber) { // bombers to bomb picked up
							sect = "CustomChiefs";
                            key = "";
                            value = "Vehicle.custom_chief_emrg_2 $core/icons/tank.mma";
                            f.add(sect, key, value);
                            sect = "Vehicle.custom_chief_emrg_2";
                            value = "";
                            key = "Car.Fordson_N";
                            value = "";
                            f.add(sect, key, value);
                            key = "TrailerUnit.BombLoadingCart_UK1_Transport";
                            value = "1";
                            f.add(sect, key, value);
                            key = "TrailerUnit.BombLoadingCart_UK1_Transport";
                            f.add(sect, key, value);
                        };
						
                        sect = "Chiefs";
                        key = "0_Chief_Fuel_0";
                        value = "Vehicle.custom_chief_emrg_0 gb /skin0 materialsSummer_RAF";
                        f.add(sect, key, value);
						
                        key = "0_Chief_Ammo_1";
                        value = "Vehicle.custom_chief_emrg_1 gb /skin0 materialsSummer_RAF/tow00_00 1_Static";
                        f.add(sect, key, value);
						
                        if (type == AircraftType.Bomber) {
                            key = "0_Chief_Bomb_2";
                            value = "Vehicle.custom_chief_emrg_2 gb /tow01_00 2_Static/tow01_01 3_Static/tow01_02 4_Static/tow01_03 5_Static/tow02_00 6_Static/tow02_01 7_Static";
                            f.add(sect, key, value);
                        }
                        sect = "Stationary";
                        key = "1_Static";
                        value = "Stationary.Morris_CS8-Bedford_MW_CargoAmmo3 gb 0.00 0.00 0.00";
                        f.add(sect, key, value);
                        if (type == AircraftType.Bomber) { // bomb ship
							key = "2_Static";
                            value = "Stationary.Weapons_.Bomb_B_GP_250lb_MkIV gb 0.00 0.00 0.00";
                            f.add(sect, key, value);
                            key = "3_Static";
                            value = "Stationary.Weapons_.Bomb_B_GP_250lb_MkIV gb 0.00 0.00 0.00";
                            f.add(sect, key, value);
                            key = "4_Static";
                            value = "Stationary.Weapons_.Bomb_B_GP_250lb_MkIV gb 0.00 0.00 0.00";
                            f.add(sect, key, value);
                            key = "5_Static";
                            value = "Stationary.Weapons_.Bomb_B_GP_250lb_MkIV gb 0.00 0.00 0.00";
                            f.add(sect, key, value);
                            key = "6_Static";
                            value = "Stationary.Weapons_.Bomb_B_GP_500lb_MkIV gb 0.00 0.00 0.00";
                            f.add(sect, key, value);
                            key = "7_Static";
                            value = "Stationary.Weapons_.Bomb_B_GP_500lb_MkIV gb 0.00 0.00 0.00";
                            f.add(sect, key, value);
                        };
                    };
                    break;
                case 2:
                    sect = "CustomChiefs"; // Pozharka
                    key = "";
                    value = "Vehicle.custom_chief_emrg_0 $core/icons/tank.mma";
                    f.add(sect, key, value);
                    value = "Vehicle.custom_chief_emrg_1 $core/icons/tank.mma"; // ambulance
                    f.add(sect, key, value);
                    if (health < 1f) {
                        sect = "Vehicle.custom_chief_emrg_0";
                        key = "Car.Renault_UE";
                        value = "";
                        f.add(sect, key, value);
                        key = "TrailerUnit.Foam_Extinguisher_GER1_Transport";
                        value = "1";
                        f.add(sect, key, value);
						
                        sect = "Vehicle.custom_chief_emrg_1";
                        if (PseudoRnd(0f, 1f) < 0.5f) {
							key = "Car.Opel_Blitz_med-tent";
                        } else { key = "Car.Opel_Blitz_cargo_med"; };
                        value = "";
                        f.add(sect, key, value);
                        sect = "Chiefs";
                        key = "0_Chief_Fire_0"; // "0_Chief_emrg";
                        value = "Vehicle.custom_chief_emrg_0 de ";
                        f.add(sect, key, value);
                        key = "0_Chief_Emrg_1"; // "0_Chief_emrg";
                        value = "Vehicle.custom_chief_emrg_1 de ";
                        f.add(sect, key, value);
                    } else {
						sect = "Vehicle.custom_chief_emrg_0";
                        key = "Car.Opel_Blitz_fuel";
                        value = "";
                        f.add(sect, key, value);
						
                        sect = "Vehicle.custom_chief_emrg_1";
                        key = "Car.Renault_UE";
                        f.add(sect, key, value);
                        key = "TrailerUnit.Oil_Cart_GER1_Transport";
                        value = "1";
                        f.add(sect, key, value);
                        key = "Car.Renault_UE";
                        value = "";
                        f.add(sect, key, value);
                        key = "TrailerUnit.Anlasswagen_(starter)_GER1_Transport";
                        value = "1";
                        f.add(sect, key, value);
						
                        if (type == AircraftType.Bomber) { // bomb ship
							sect = "CustomChiefs";
                            key = "";
                            value = "Vehicle.custom_chief_emrg_2 $core/icons/tank.mma";
                            f.add(sect, key, value);
                            sect = "Vehicle.custom_chief_emrg_2";
                            key = "Car.Renault_UE";
                            value = "";
                            f.add(sect, key, value);
                            key = "TrailerUnit.HydraulicBombLoader_GER1_Transport";
                            value = "1";
                            f.add(sect, key, value);
                            key = "Car.Renault_UE";
                            value = "";
                            f.add(sect, key, value);
                            key = "TrailerUnit.BombSled_GER1_Transport";
                            value = "1";
                            f.add(sect, key, value);
                        }
						
                        sect = "Chiefs";
                        key = "0_Chief_Fuel_0";
                        value = "Vehicle.custom_chief_emrg_0 de";
                        f.add(sect, key, value);
                        key = "0_Chief_Ammo_1";
                        value = "Vehicle.custom_chief_emrg_1 de";
                        f.add(sect, key, value);
                        if (type == AircraftType.Bomber) {
							key = "0_Chief_Bomb_2";
                            value = "Vehicle.custom_chief_emrg_2 de /tow01_00 1_Static/tow03_00 2_Static";
                            f.add(sect, key, value);
                            sect = "Stationary";
                            key = "1_Static";
                            value = "Stationary.Weapons_.Bomb_B_SC-250_Type2_J de 0.00 0.00 0.00";
                            f.add(sect, key, value);
                            key = "2_Static";
                            value = "Stationary.Weapons_.Bomb_B_SC-1000_C de 0.00 0.00 0.00";
                            f.add(sect, key, value);
                        };
                    };
                    break;
                default:
                    break;
            }
        } else {
			switch (portArmy) {
				case 1:
					if (health < 1f) {
						sect = "CustomChiefs";
                        key = "";
                        value = "Vehicle.custom_chief_emrg_0 $core/icons/tank.mma"; // pozharka
                        f.add(sect, key, value);
                        value = "Vehicle.custom_chief_emrg_1 $core/icons/tank.mma";// ambulance
                        f.add(sect, key, value);
                        value = "Vehicle.custom_chief_emrg_2 $core/icons/tank.mma";// armored car
                        f.add(sect, key, value);
						
                        sect = "Vehicle.custom_chief_emrg_0";
                        key = "Car.Austin_K2_ATV";
                        value = "";
                        f.add(sect, key, value);
                        key = "TrailerUnit.Fire_pump_UK2_Transport";
                        value = "1";
                        f.add(sect, key, value);
						
                        sect = "Vehicle.custom_chief_emrg_1";
                        key = "Car.Austin_K2_Ambulance";
                        value = "";
                        f.add(sect, key, value);
						
                        sect = "Vehicle.custom_chief_emrg_2";
                        key = "Car.Beaverette_III";
                        value = "";
                        f.add(sect, key, value);
						
                        sect = "Chiefs";
                        key = "0_Chief_Fire_0";
                        value = "Vehicle.custom_chief_emrg_0 gb /skin0 materialsSummer_RAF";
                        f.add(sect, key, value);
                        key = "0_Chief_Emrg_1";
                        value = "Vehicle.custom_chief_emrg_1 gb /skin0 materialsSummer_RAF";
                        f.add(sect, key, value);
                        key = "0_Chief_Prisoner_2";
                        value = "Vehicle.custom_chief_emrg_2 gb ";
                        f.add(sect, key, value);
                        ChiefName3 = "0_Chief_Prisoner_";
						
                    } else {
						sect = "CustomChiefs";
                        key = "";
                        value = "Vehicle.custom_chief_emrg_0 $core/icons/tank.mma"; // pozharka
                        f.add(sect, key, value);
                        sect = "Vehicle.custom_chief_emrg_0";
                        key = "Car.Beaverette_III";
                        value = "";
                        f.add(sect, key, value);
                        sect = "Chiefs";
                        key = "0_Chief_Prisoner_0";
                        value = "Vehicle.custom_chief_emrg_0 gb ";
                        f.add(sect, key, value);
                        ChiefName1 = "0_Chief_Prisoner_";
                    };
                    break;
                case 2:
                    if (health < 1f) {
                        sect = "CustomChiefs";
                        key = "";
                        value = "Vehicle.custom_chief_emrg_0 $core/icons/tank.mma"; // pozharka
                        f.add(sect, key, value);
                        value = "Vehicle.custom_chief_emrg_1 $core/icons/tank.mma"; // ambulance
                        f.add(sect, key, value);
                        value = "Vehicle.custom_chief_emrg_2 $core/icons/tank.mma"; // armoured car
                        f.add(sect, key, value);
						
                        sect = "Vehicle.custom_chief_emrg_0";
                        key = "Car.Renault_UE";
                        value = "";
                        f.add(sect, key, value);
                        key = "TrailerUnit.Foam_Extinguisher_GER1_Transport";
                        value = "1";
                        f.add(sect, key, value);
						
                        sect = "Vehicle.custom_chief_emrg_1";
                        key = "Car.Opel_Blitz_cargo_med";
                        value = "";
                        f.add(sect, key, value);
						
                        sect = "Vehicle.custom_chief_emrg_2";
                        key = "Car.SdKfz_231_6Rad";
                        value = "";
                        f.add(sect, key, value);
						
                        sect = "Chiefs";
                        key = "0_Chief_Fire_0";
                        value = "Vehicle.custom_chief_emrg_0 de";
                        f.add(sect, key, value);
                        key = "0_Chief_Emrg_1";
                        value = "Vehicle.custom_chief_emrg_1 de";
                        f.add(sect, key, value);
                        key = "0_Chief_Prisoner_2";
                        value = "Vehicle.custom_chief_emrg_2 de /marker0 1940-42_var1";
                        f.add(sect, key, value);
                        ChiefName3 = "0_Chief_Prisoner_";
                    } else {
						sect = "CustomChiefs";
                        key = "";
                        value = "Vehicle.custom_chief_emrg_0 $core/icons/tank.mma"; // pozharka
                        f.add(sect, key, value);
                        sect = "Vehicle.custom_chief_emrg_0";
                        key = "Car.SdKfz_231_6Rad";
                        value = "";
                        f.add(sect, key, value);
                        sect = "Chiefs";
                        key = "0_Chief_Prisoner_0";
                        value = "Vehicle.custom_chief_emrg_0 de /marker0 1940-42_var1";
                        f.add(sect, key, value);
                        ChiefName1 = "0_Chief_Prisoner_";
                    };
                    break;
                default:
                    break;
            };
        }
		
        Point3d TmpStartPos = startPos;
        TmpStartPos.x += PseudoRnd(-30f, 30f) + fRadius; TmpStartPos.y += PseudoRnd(-30f, 30f) + fRadius;
        Point3d BirthPos = EmrgVehicleStartPos(TmpStartPos, startPos);
		
        sect = ChiefName1+"0" + "_Road";
        key = "";
        value = BirthPos.x.ToString(System.Globalization.CultureInfo.InvariantCulture.NumberFormat) + " " + BirthPos.y.ToString(System.Globalization.CultureInfo.InvariantCulture.NumberFormat) + " " + BirthPos.z.ToString(System.Globalization.CultureInfo.InvariantCulture.NumberFormat) + "  0 92 5 ";
        f.add(sect, key, value);
        BirthPos.x -= 50f * ((BirthPos.x - aircraftPos.x) / Math.Abs(BirthPos.x - aircraftPos.x)); BirthPos.y -= 50f * ((BirthPos.y - aircraftPos.y) / Math.Abs(BirthPos.y - aircraftPos.y));
        value = BirthPos.x.ToString(System.Globalization.CultureInfo.InvariantCulture.NumberFormat) + " " + BirthPos.y.ToString(System.Globalization.CultureInfo.InvariantCulture.NumberFormat) + " " + BirthPos.z.ToString(System.Globalization.CultureInfo.InvariantCulture.NumberFormat);
        f.add(sect, key, value);
		
        TmpStartPos = startPos;
        TmpStartPos.x += PseudoRnd(-30f, 30f) - fRadius; TmpStartPos.y += PseudoRnd(-30f, 30f) + fRadius;
        BirthPos = EmrgVehicleStartPos(TmpStartPos, startPos);
        //BirthPos = TmpStartPos;
        sect = ChiefName2+"1" + "_Road";
        key = "";
        value = BirthPos.x.ToString(System.Globalization.CultureInfo.InvariantCulture.NumberFormat) + " " + BirthPos.y.ToString(System.Globalization.CultureInfo.InvariantCulture.NumberFormat) + " " + BirthPos.z.ToString(System.Globalization.CultureInfo.InvariantCulture.NumberFormat) + "  0 92 5 ";
        f.add(sect, key, value);
        BirthPos.x -= 50f * ((BirthPos.x - aircraftPos.x) / Math.Abs(BirthPos.x - aircraftPos.x)); BirthPos.y -= 50f * ((BirthPos.y - aircraftPos.y) / Math.Abs(BirthPos.y - aircraftPos.y));
        value = BirthPos.x.ToString(System.Globalization.CultureInfo.InvariantCulture.NumberFormat) + " " + BirthPos.y.ToString(System.Globalization.CultureInfo.InvariantCulture.NumberFormat) + " " + BirthPos.z.ToString(System.Globalization.CultureInfo.InvariantCulture.NumberFormat);
        f.add(sect, key, value);
		
        TmpStartPos = startPos;
        TmpStartPos.x += PseudoRnd(-30f, 30f) + fRadius; TmpStartPos.y += PseudoRnd(-30f, 30f) - fRadius;
        BirthPos = EmrgVehicleStartPos(TmpStartPos, startPos);
		
        sect = ChiefName3 + "2" + "_Road";
        key = "";
        value = BirthPos.x.ToString(System.Globalization.CultureInfo.InvariantCulture.NumberFormat) + " " + BirthPos.y.ToString(System.Globalization.CultureInfo.InvariantCulture.NumberFormat) + " " + BirthPos.z.ToString(System.Globalization.CultureInfo.InvariantCulture.NumberFormat) + "  0 92 5 ";
        f.add(sect, key, value);
        BirthPos.x -= 50f * ((BirthPos.x - aircraftPos.x) / Math.Abs(BirthPos.x - aircraftPos.x)); BirthPos.y -= 50f * ((BirthPos.y - aircraftPos.y) / Math.Abs(BirthPos.y - aircraftPos.y));
        value = BirthPos.x.ToString(System.Globalization.CultureInfo.InvariantCulture.NumberFormat) + " " + BirthPos.y.ToString(System.Globalization.CultureInfo.InvariantCulture.NumberFormat) + " " + BirthPos.z.ToString(System.Globalization.CultureInfo.InvariantCulture.NumberFormat);
        f.add(sect, key, value);
        
        return f;
    }
	
    internal Point3d EmrgVehicleStartPos(Point3d startPos, Point3d endPos) {
		Point3d TmpPos = startPos;
		
        while (((GamePlay.gpLandType(TmpPos.x, TmpPos.y) & LandTypes.WATER) != 0) ) {
			TmpPos.x -= (TmpPos.x - endPos.x) / 10f;
			TmpPos.y -= (TmpPos.y - endPos.y) / 10f;
        };
		return TmpPos;
	}
	
    internal void CheckEmrgCarOnAirport(int aircraftNumber)
    {
        // Check whether there cars at the airport
        AiGroundGroup MyCar = null;
        for (int i = 0; i < CurTechCars.Count; i++) {
			if (CurTechCars[i].TechCar != null ) {
				if (CurTechCars[i].TechCar.IsAlive() && CurTechCars[i].BaseAirport == CurPlanesQueue[aircraftNumber].baseAirport && (CurTechCars[i].CarType & CurPlanesQueue[aircraftNumber].State)!=0) {
					MissionLoading = false;
                    MyCar = CurTechCars[i].TechCar;
                    if ((CurTechCars[i].cur_rp == null) && (CurTechCars[i].RouteFlag == 0) && (CurTechCars[i].servPlaneNum == -1)) // ???? ????? ??? ???? - ???????? ????????
                        SetEmrgCarRoute(aircraftNumber, i);
				}
			}
		};
        if ((MyCar == null) && !MissionLoading) {
			MissionLoading = true;
            int ArmyPos = 0;
            if (GamePlay.gpFrontExist()) {
				ArmyPos = GamePlay.gpFrontArmy(CurPlanesQueue[aircraftNumber].baseAirport.Pos().x, CurPlanesQueue[aircraftNumber].baseAirport.Pos().y);
            } else { ArmyPos = CurPlanesQueue[aircraftNumber].aircraft.Army(); };
            // Create a mission with cars
            GamePlay.gpPostMissionLoad(CreateEmrgCarMission(CurPlanesQueue[aircraftNumber].baseAirport.Pos(), (CurPlanesQueue[aircraftNumber].baseAirport.FieldR() / 4), ArmyPos, CurPlanesQueue[aircraftNumber].aircraft.Army(), CurPlanesQueue[aircraftNumber].aircraft.Type(),CurPlanesQueue[aircraftNumber].health, CurPlanesQueue[aircraftNumber].aircraft.Pos()));
        }        
        return;
	}

	public override void OnAircraftCrashLanded(int missionNumber, string shortName, AiAircraft aircraft) {
		base.OnAircraftCrashLanded(missionNumber, shortName, aircraft);
		Timeout(5, () => {
			aircraft.Destroy();
		});
	}
	
    public override void OnAircraftLanded(int missionNumber, string shortName, AiAircraft aircraft) {
		base.OnAircraftLanded(missionNumber, shortName, aircraft);
        
        AiAirport NearestAirport = FindNearestAirport(aircraft);
        if (NearestAirport != null) {
            PlanesQueue CurPlane = new PlanesQueue(aircraft, NearestAirport, 0);
            int ArmyPos = 0;
            CurPlane.health = (float)aircraft.getParameter(part.ParameterTypes.M_Health, -1);
            if (GamePlay.gpFrontExist()) {
                ArmyPos = GamePlay.gpFrontArmy(NearestAirport.Pos().x, NearestAirport.Pos().y);
            } else { ArmyPos = aircraft.Army(); };
            if (CurPlane.health < 1f) {
				CurPlane.State |= ServiceType.EMERGENCY;
                CurPlane.State |= ServiceType.FIRE;
			} else if (aircraft.Army() == ArmyPos) {
				CurPlane.State |= ServiceType.FUEL;
                CurPlane.State |= ServiceType.AMMO;
                if (aircraft.Type() == AircraftType.Bomber) CurPlane.State |= ServiceType.BOMBS;
            };
            if (!(aircraft.Army() == ArmyPos)) CurPlane.State |= ServiceType.PRISONERCAPTURE;
            if (!CurPlanesQueue.Contains(CurPlane)) {
				CurPlanesQueue.Add(CurPlane);
                CheckEmrgCarOnAirport(CurPlanesQueue.Count - 1);                
            } else {
				for (int i = 0; i < CurPlanesQueue.Count; i++)
                    if (CurPlanesQueue[i] == CurPlane) { 
						CheckEmrgCarOnAirport(i);
						break;
					}
            }
            CurPlane = null;
        };
    }
}


This is very cool and works great - thanks, Squog!

I also want to include in the same .cs file this other bit of code for displaying detailed damage:

Click to reveal..
Code:
using System;
using maddox.game;
using maddox.game.world;

public class Mission : maddox.game.AMission
{

    public override void OnAircraftDamaged(int missionNumber, string shortName, AiAircraft Aircraft, AiDamageInitiator DamageFrom, part.NamedDamageTypes WhatDamaged) 
    {
    	base.OnAircraftDamaged(missionNumber, shortName, Aircraft, DamageFrom, WhatDamaged);
    	
    	if (DamageFrom.Player != null )
    	{
    	    GamePlay.gpLogServer (null, "{0} hits {1} : {2} \n", new object [] {DamageFrom.Player, shortName, WhatDamaged});//Test
      }
    	
    }
}


How can I combine both in the same .cs file?

Charlo


i7-950 OC to 4 GHz CPU
Asus P6X58D-E X58 MB
Sapphire HD 7950 OC 3GB GCU
Windows 7 Ult. 64 bit
======
MacBook Pro Core2Duo 2.66 GHz
http://i49.tinypic.com/j8zkzr.png
#3392177 - 09/17/11 09:25 PM Re: Ambulance Station: notes from the Cavern [Re: Ming_EAF19]  
Joined: May 2007
Posts: 159
No601_Swallow Offline
Member
No601_Swallow  Offline
Member

Joined: May 2007
Posts: 159
London
Thanks guys! Works like a charm. As an old FS2004 person, I love this sort of thing. Pity they didn't have airbridges in the 1940s...

A screenshot, if you'll indulge me (thanks Kris, for the bootiful skin!):


#3392204 - 09/17/11 10:02 PM Re: Ambulance Station: notes from the Cavern [Re: charlo]  
Joined: Jan 2009
Posts: 4,737
FearlessFrog Offline
Senior Member
FearlessFrog  Offline
Senior Member

Joined: Jan 2009
Posts: 4,737
Charlo - just add the OnDamage.. lines beneath the mission part (before OnBattle..) - it'll work fine.

#3392406 - 09/18/11 05:59 AM Re: Ambulance Station: notes from the Cavern [Re: FearlessFrog]  
Joined: Sep 2010
Posts: 29
charlo Offline
Junior Member
charlo  Offline
Junior Member

Joined: Sep 2010
Posts: 29
Los Angeles, CA, USA
Originally Posted By: FearlessFrog
Charlo - just add the OnDamage.. lines beneath the mission part (before OnBattle..) - it'll work fine.


Thanks very much for the advice, Frog. I tried what you wrote (with variations, too) but had no luck getting both of those scripts to work together when merged into the same .cs file.

Charlo


i7-950 OC to 4 GHz CPU
Asus P6X58D-E X58 MB
Sapphire HD 7950 OC 3GB GCU
Windows 7 Ult. 64 bit
======
MacBook Pro Core2Duo 2.66 GHz
http://i49.tinypic.com/j8zkzr.png
#3392407 - 09/18/11 06:07 AM Re: Ambulance Station: notes from the Cavern [Re: charlo]  
Joined: Jan 2009
Posts: 4,737
FearlessFrog Offline
Senior Member
FearlessFrog  Offline
Senior Member

Joined: Jan 2009
Posts: 4,737
Originally Posted By: charlo
Originally Posted By: FearlessFrog
Charlo - just add the OnDamage.. lines beneath the mission part (before OnBattle..) - it'll work fine.


Thanks very much for the advice, Frog. I tried what you wrote (with variations, too) but had no luck getting both of those scripts to work together when merged into the same .cs file.

Charlo


It can be fiddly, try this one - it should work:

Click to reveal..


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

public class Mission : AMission
{
public override void OnBattleStarted()
{
base.OnBattleStarted();
MissionNumberListener = -1;
}

Random rnd = new Random();


[Flags]
internal enum ServiceType // ??? ????????????? ???????
{
NONE = 0,
EMERGENCY = 1,
FIRE = 2,
FUEL = 4,
AMMO = 8,
BOMBS = 16,
PRISONERCAPTURE = 32
}

internal class TechCars
{
internal AiGroundGroup TechCar { get; set; }
internal AiAirport BaseAirport { get; set; }
internal IRecalcPathParams cur_rp { get; set; }
internal int RouteFlag = 0;
internal int cartype = 0;
internal int servPlaneNum = -1;
internal ServiceType CarType { get { return (ServiceType)cartype; } set { cartype = (int)value; } }

public TechCars(AiGroundGroup car, AiAirport airoport, IRecalcPathParams rp)
{
this.TechCar = car;
this.BaseAirport = airoport;
this.cur_rp = rp;
}

}

internal class PlanesQueue {
internal AiAircraft aircraft { get; set; }
internal AiAirport baseAirport { get; set; }
internal int state = 0;
internal ServiceType State { get { return (ServiceType)state; } set { state = (int)value; } }
internal int Lifetime = 0;
internal float health = 1;
public PlanesQueue(AiAircraft aircraft, AiAirport baseAirport, int state)
{
this.aircraft = aircraft;
this.baseAirport = baseAirport;
this.state = state;
}
}

internal List<TechCars> CurTechCars = new List<TechCars>();
internal List<PlanesQueue> CurPlanesQueue = new List<PlanesQueue>();
TechCars TmpCar = null;
bool MissionLoading = false;

internal double PseudoRnd(double MinValue, double MaxValue)
{
return rnd.NextDouble() * (MaxValue - MinValue) + MinValue;
}



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


AiActor ai_actor = actor as AiActor;
if (ai_actor != null)
{
if (ai_actor is AiGroundGroup)
for (int i = 0; i < CurTechCars.Count; i++) // ???? ????????????? ??????? ??????? ?? ?????????????? ????????, ????????? ?? ????????????
{
if (CurTechCars[i].TechCar == ai_actor as AiGroundGroup)
if (CurTechCars[i].RouteFlag == 1)
EndPlaneService(i);

else
CheckNotServicedPlanes(i);
};
}
}

internal void CheckNotServicedPlanes(int techCarIndex)
{
for (int j = 0; j < CurPlanesQueue.Count; j++)
{
if (CurTechCars[techCarIndex].TechCar.IsAlive() && (CurPlanesQueue[j].baseAirport == CurTechCars[techCarIndex].BaseAirport) && ((CurTechCars[techCarIndex].CarType & CurPlanesQueue[j].State) != 0) && (CurTechCars[techCarIndex].servPlaneNum == -1))
{
if (SetEmrgCarRoute(j, techCarIndex)) // ?????????? ??????? ??????????? ????????? ???????
{
return;
}
}
}
}

internal void EndPlaneService(int techCarIndex)
{
if (CurTechCars[techCarIndex].cur_rp == null) return;
CurTechCars[techCarIndex].cur_rp = null; // ?????????? ???????
if (CurTechCars[techCarIndex].servPlaneNum >= 0)
{

CurPlanesQueue[CurTechCars[techCarIndex].servPlaneNum].State &= ~CurTechCars[techCarIndex].CarType; // ??????? ??? ???????????? ? ?????????????? ????????, ???? ?? ????

CurTechCars[techCarIndex].servPlaneNum = -1; // ?????????? ????? ?????????????? ????????
Timeout(5f, () =>
{
if (!MoveFromRWay(techCarIndex))// ????????? ?? ????? ?? ?? ???????, ? ??????? ? ??? ???? ???.
{
CurTechCars[techCarIndex].RouteFlag = 0;
CheckNotServicedPlanes(techCarIndex); // ? ???????, ??? ?? ??? ????????????? ?????????
}
});

}
else Timeout(5f, () =>
{
CurTechCars[techCarIndex].RouteFlag = 0;
CheckNotServicedPlanes(techCarIndex); // ? ???????, ??? ?? ??? ????????????? ?????????
});


}

internal bool MoveFromRWay(int carNum)
{
bool result = false;
if ((GamePlay.gpLandType(CurTechCars[carNum].TechCar.Pos().x, CurTechCars[carNum].TechCar.Pos().y) & LandTypes.ROAD) == 0)
return result;

Point3d TmpPos = CurTechCars[carNum].TechCar.Pos();
while (((GamePlay.gpLandType(TmpPos.x, TmpPos.y) & LandTypes.ROAD) != 0))
{
TmpPos.x += 10f;
TmpPos.y += 10f;
};
Point2d EmgCarStart, EmgCarFinish;
EmgCarStart.x = CurTechCars[carNum].TechCar.Pos().x; EmgCarStart.y = CurTechCars[carNum].TechCar.Pos().y;
EmgCarFinish.x = TmpPos.x; EmgCarFinish.y = TmpPos.y;
CurTechCars[carNum].servPlaneNum = -1;
CurTechCars[carNum].RouteFlag = 0;
CurTechCars[carNum].cur_rp = null;
CurTechCars[carNum].cur_rp = GamePlay.gpFindPath(EmgCarStart, 10f, EmgCarFinish, 10f, PathType.GROUND, CurTechCars[carNum].TechCar.Army());

result = true;
return result;
}


public bool SetEmrgCarRoute(int aircraftNumber,int carNum)
{
bool result = false;
if (CurTechCars[carNum].TechCar != null)
{
CurTechCars[carNum].servPlaneNum = aircraftNumber; // ????????????? ????? ?????????????? ????????
if (CurTechCars[carNum].cur_rp == null)
{
Point2d EmgCarStart, EmgCarFinish, LandedPos;
LandedPos.x = CurPlanesQueue[aircraftNumber].aircraft.Pos().x; LandedPos.y = CurPlanesQueue[aircraftNumber].aircraft.Pos().y;
int Sign = ((carNum % 2) == 0) ? 2 : -2;
EmgCarStart.x = CurTechCars[carNum].TechCar.Pos().x; EmgCarStart.y = CurTechCars[carNum].TechCar.Pos().y;
EmgCarFinish.x = LandedPos.x - PseudoRnd(2f, 5f) * ((LandedPos.x - EmgCarStart.x) / (Math.Abs(LandedPos.x - EmgCarStart.x))) - Sign;
EmgCarFinish.y = LandedPos.y - PseudoRnd(2f, 5f) * ((LandedPos.y - EmgCarStart.y) / (Math.Abs(LandedPos.y - EmgCarStart.y))) - Sign;
CurTechCars[carNum].cur_rp = GamePlay.gpFindPath(EmgCarStart, 10f, EmgCarFinish, 10f, PathType.GROUND, CurTechCars[carNum].TechCar.Army());
result = true;
}
}
return result;
}


public override void OnMissionLoaded(int missionNumber)
{
base.OnMissionLoaded(missionNumber);
if (missionNumber > 0)
{
List<string> CarTypes = new List<string>();
CarTypes.Add(":0_Chief_Emrg_");
CarTypes.Add(":0_Chief_Fire_");
CarTypes.Add(":0_Chief_Fuel_");
CarTypes.Add(":0_Chief_Ammo_");
CarTypes.Add(":0_Chief_Bomb_");
CarTypes.Add(":0_Chief_Prisoner_");

AiGroundGroup MyCar = null;

for (int i = 0; i < 3; i++)
{
for (int j = 0; j < CarTypes.Count; j++)
{
MyCar = GamePlay.gpActorByName(missionNumber.ToString() + CarTypes[j] + i.ToString()) as AiGroundGroup;
if (MyCar != null)
{
TmpCar = new TechCars(MyCar, FindNearestAirport(MyCar), null);
TmpCar.CarType = (ServiceType)(1 << j);
TmpCar.cur_rp = null;
if (!CurTechCars.Contains(TmpCar))
CurTechCars.Add(TmpCar);
MissionLoading = false;
};
}
}
}
}


public override void OnTickGame() {
base.OnTickGame();
try {
if (Time.tickCounter() % 64 == 0)
{

for (int i = 0; i < CurPlanesQueue.Count; i++)
{
CurPlanesQueue[i].Lifetime++;
if ((CurPlanesQueue[i].State == ServiceType.NONE) || (CurPlanesQueue[i].aircraft == null) || (CurPlanesQueue[i].Lifetime > 200))
{
for (int j = 0; j < CurTechCars.Count; j++)
if (CurTechCars[j].servPlaneNum == i)
EndPlaneService(j);
CurPlanesQueue.RemoveAt(i);
}
};

for (int i = 0; i < CurTechCars.Count; i++)
{
TechCars car = CurTechCars[i];
if ((car.TechCar != null && car.cur_rp != null) && (car.cur_rp.State == RecalcPathState.SUCCESS) )
{
if (car.TechCar.IsAlive() && (car.RouteFlag == 0)/* && (car.servPlaneNum != -1)*/)
{
car.RouteFlag = 1;
car.cur_rp.Path[0].P.x = car.TechCar.Pos().x; car.cur_rp.Path[0].P.y = car.TechCar.Pos().y;
car.TechCar.SetWay(car.cur_rp.Path);
//if (car.servPlaneNum != -1) car.RouteFlag = 0;
}

double Dist = Math.Sqrt((car.cur_rp.Path[car.cur_rp.Path.Length - 1].P.x - car.TechCar.Pos().x) * (car.cur_rp.Path[car.cur_rp.Path.Length - 1].P.x - car.TechCar.Pos().x) + (car.cur_rp.Path[car.cur_rp.Path.Length - 1].P.y - car.TechCar.Pos().y) * (car.cur_rp.Path[car.cur_rp.Path.Length - 1].P.y - car.TechCar.Pos().y));
if (car.servPlaneNum != -1)
{
if (Dist < ((CurPlanesQueue[car.servPlaneNum].aircraft.Type() == AircraftType.Bomber) ? 20f : 10f))
EndPlaneService(i);
}
else if (Dist < 15f)
{
EndPlaneService(i);
}
}
if ((car.cur_rp == null) && (car.RouteFlag == 0) && (car.servPlaneNum != -1))
{
EndPlaneService(i);
};
};
}

} catch (Exception e) {}
}




internal AiAirport FindNearestAirport(AiActor actor)
{
AiAirport aMin = null;
double d2Min = 0;
Point3d pd = actor.Pos();
int n = GamePlay.gpAirports().Length;
for (int i = 0; i < n; i++)
{
AiAirport a = (AiAirport)GamePlay.gpAirports()[i];

if (!a.IsAlive())
continue;

Point3d pp;
pp = a.Pos();
pd.z = pp.z;
double d2 = pd.distanceSquared(ref pp);
if ((aMin == null) || (d2 < d2Min))
{
aMin = a;
d2Min = d2;
}
}
if (d2Min > 2250000.0)
aMin = null;

return aMin;
}

internal ISectionFile CreateEmrgCarMission(Point3d startPos, double fRadius, int portArmy, int planeArmy, AircraftType type, float health, Point3d aircraftPos)
{ ISectionFile f = GamePlay.gpCreateSectionFile();
string sect;
string key;
string value;
string ChiefName1 = "0_Chief_" + (health < 1f ? "Fire_" : "Fuel_");
string ChiefName2 = "0_Chief_" + (health < 1f ? "Emrg_" : "Ammo_");
string ChiefName3 = "0_Chief_" + (health < 1f ? "Bomb_" : "Bomb_");


if (portArmy == planeArmy) //???? ????????
{
switch (portArmy)
{
case 1:
if (health < 1f)
{
sect = "CustomChiefs";
key = "";
value = "Vehicle.custom_chief_emrg_0 $core/icons/tank.mma"; //???????
f.add(sect, key, value);
value = "Vehicle.custom_chief_emrg_1 $core/icons/tank.mma";//??????
f.add(sect, key, value);

sect = "Vehicle.custom_chief_emrg_0";
key = "Car.Austin_K2_ATV";
value = "";
f.add(sect, key, value);
key = "TrailerUnit.Fire_pump_UK2_Transport";
value = "1";
f.add(sect, key, value);
sect = "Vehicle.custom_chief_emrg_1";
key = "Car.Austin_K2_Ambulance";
value = "";
f.add(sect, key, value);

sect = "Chiefs";
key = "0_Chief_Fire_0";
value = "Vehicle.custom_chief_emrg_0 gb /skin0 materialsSummer_RAF";
f.add(sect, key, value);
key = "0_Chief_Emrg_1";
value = "Vehicle.custom_chief_emrg_1 gb /skin0 materialsSummer_RAF";
f.add(sect, key, value);
}
else
{
sect = "CustomChiefs";
key = "";
value = "Vehicle.custom_chief_emrg_0 $core/icons/tank.mma";
f.add(sect, key, value);
value = "Vehicle.custom_chief_emrg_1 $core/icons/tank.mma";
f.add(sect, key, value);

sect = "Vehicle.custom_chief_emrg_0"; // ??????????
key = "Car.Albion_AM463";
value = "";
f.add(sect, key, value);
if (type == AircraftType.Bomber) // ??? ???????? ?????? ??????? ? ????? ????????
{
key = "Car.Fordson_N";
value = "";
f.add(sect, key, value);
key = "TrailerUnit.Towed_Bowser_UK1_Transport";
value = "1";
f.add(sect, key, value);
}

sect = "Vehicle.custom_chief_emrg_1"; // ??????
value = "";
key = "Car.Bedford_MW_open";
f.add(sect, key, value);


if (type == AircraftType.Bomber) // ??? ???????? ????? ????????
{
sect = "CustomChiefs";
key = "";
value = "Vehicle.custom_chief_emrg_2 $core/icons/tank.mma";
f.add(sect, key, value);
sect = "Vehicle.custom_chief_emrg_2";
value = "";
key = "Car.Fordson_N";
value = "";
f.add(sect, key, value);
key = "TrailerUnit.BombLoadingCart_UK1_Transport";
value = "1";
f.add(sect, key, value);
key = "TrailerUnit.BombLoadingCart_UK1_Transport";
f.add(sect, key, value);
};

sect = "Chiefs";
key = "0_Chief_Fuel_0";
value = "Vehicle.custom_chief_emrg_0 gb /skin0 materialsSummer_RAF";
f.add(sect, key, value);

key = "0_Chief_Ammo_1";
value = "Vehicle.custom_chief_emrg_1 gb /skin0 materialsSummer_RAF/tow00_00 1_Static";
f.add(sect, key, value);

if (type == AircraftType.Bomber)
{
key = "0_Chief_Bomb_2";
value = "Vehicle.custom_chief_emrg_2 gb /tow01_00 2_Static/tow01_01 3_Static/tow01_02 4_Static/tow01_03 5_Static/tow02_00 6_Static/tow02_01 7_Static";
f.add(sect, key, value);
}
sect = "Stationary";
key = "1_Static";
value = "Stationary.Morris_CS8-Bedford_MW_CargoAmmo3 gb 0.00 0.00 0.00";
f.add(sect, key, value);
if (type == AircraftType.Bomber) // ????? ??????
{
key = "2_Static";
value = "Stationary.Weapons_.Bomb_B_GP_250lb_MkIV gb 0.00 0.00 0.00";
f.add(sect, key, value);
key = "3_Static";
value = "Stationary.Weapons_.Bomb_B_GP_250lb_MkIV gb 0.00 0.00 0.00";
f.add(sect, key, value);
key = "4_Static";
value = "Stationary.Weapons_.Bomb_B_GP_250lb_MkIV gb 0.00 0.00 0.00";
f.add(sect, key, value);
key = "5_Static";
value = "Stationary.Weapons_.Bomb_B_GP_250lb_MkIV gb 0.00 0.00 0.00";
f.add(sect, key, value);
key = "6_Static";
value = "Stationary.Weapons_.Bomb_B_GP_500lb_MkIV gb 0.00 0.00 0.00";
f.add(sect, key, value);
key = "7_Static";
value = "Stationary.Weapons_.Bomb_B_GP_500lb_MkIV gb 0.00 0.00 0.00";
f.add(sect, key, value);
};
};
break;
case 2:
sect = "CustomChiefs"; //???????
key = "";
value = "Vehicle.custom_chief_emrg_0 $core/icons/tank.mma";
f.add(sect, key, value);
value = "Vehicle.custom_chief_emrg_1 $core/icons/tank.mma";//??????
f.add(sect, key, value);
if (health < 1f)
{
sect = "Vehicle.custom_chief_emrg_0";
key = "Car.Renault_UE";
value = "";
f.add(sect, key, value);
key = "TrailerUnit.Foam_Extinguisher_GER1_Transport";
value = "1";
f.add(sect, key, value);

sect = "Vehicle.custom_chief_emrg_1";
if (PseudoRnd(0f, 1f) < 0.5f)
{
key = "Car.Opel_Blitz_med-tent";
}
else { key = "Car.Opel_Blitz_cargo_med"; };
value = "";
f.add(sect, key, value);
sect = "Chiefs";
key = "0_Chief_Fire_0";// "0_Chief_emrg";
value = "Vehicle.custom_chief_emrg_0 de ";
f.add(sect, key, value);
key = "0_Chief_Emrg_1";// "0_Chief_emrg";
value = "Vehicle.custom_chief_emrg_1 de ";
f.add(sect, key, value);
}
else
{
sect = "Vehicle.custom_chief_emrg_0";
key = "Car.Opel_Blitz_fuel";
value = "";
f.add(sect, key, value);

sect = "Vehicle.custom_chief_emrg_1";
key = "Car.Renault_UE";
f.add(sect, key, value);
key = "TrailerUnit.Oil_Cart_GER1_Transport";
value = "1";
f.add(sect, key, value);
key = "Car.Renault_UE";
value = "";
f.add(sect, key, value);
key = "TrailerUnit.Anlasswagen_(starter)_GER1_Transport";
value = "1";
f.add(sect, key, value);

if (type == AircraftType.Bomber) // ????? ??????
{
sect = "CustomChiefs";
key = "";
value = "Vehicle.custom_chief_emrg_2 $core/icons/tank.mma";
f.add(sect, key, value);
sect = "Vehicle.custom_chief_emrg_2";
key = "Car.Renault_UE";
value = "";
f.add(sect, key, value);
key = "TrailerUnit.HydraulicBombLoader_GER1_Transport";
value = "1";
f.add(sect, key, value);
key = "Car.Renault_UE";
value = "";
f.add(sect, key, value);
key = "TrailerUnit.BombSled_GER1_Transport";
value = "1";
f.add(sect, key, value);
}

sect = "Chiefs";
key = "0_Chief_Fuel_0";
value = "Vehicle.custom_chief_emrg_0 de";
f.add(sect, key, value);
key = "0_Chief_Ammo_1";
value = "Vehicle.custom_chief_emrg_1 de";
f.add(sect, key, value);
if (type == AircraftType.Bomber)
{
key = "0_Chief_Bomb_2";
value = "Vehicle.custom_chief_emrg_2 de /tow01_00 1_Static/tow03_00 2_Static";
f.add(sect, key, value);
sect = "Stationary";
key = "1_Static";
value = "Stationary.Weapons_.Bomb_B_SC-250_Type2_J de 0.00 0.00 0.00";
f.add(sect, key, value);
key = "2_Static";
value = "Stationary.Weapons_.Bomb_B_SC-1000_C de 0.00 0.00 0.00";
f.add(sect, key, value);
};
};
break;
default:
break;

}
}
else
{
switch (portArmy)
{
case 1:
if (health < 1f)
{
sect = "CustomChiefs";
key = "";
value = "Vehicle.custom_chief_emrg_0 $core/icons/tank.mma"; //???????
f.add(sect, key, value);
value = "Vehicle.custom_chief_emrg_1 $core/icons/tank.mma";//??????
f.add(sect, key, value);
value = "Vehicle.custom_chief_emrg_2 $core/icons/tank.mma";//????????
f.add(sect, key, value);

sect = "Vehicle.custom_chief_emrg_0";
key = "Car.Austin_K2_ATV";
value = "";
f.add(sect, key, value);
key = "TrailerUnit.Fire_pump_UK2_Transport";
value = "1";
f.add(sect, key, value);

sect = "Vehicle.custom_chief_emrg_1";
key = "Car.Austin_K2_Ambulance";
value = "";
f.add(sect, key, value);

sect = "Vehicle.custom_chief_emrg_2";
key = "Car.Beaverette_III";
value = "";
f.add(sect, key, value);

sect = "Chiefs";
key = "0_Chief_Fire_0";
value = "Vehicle.custom_chief_emrg_0 gb /skin0 materialsSummer_RAF";
f.add(sect, key, value);
key = "0_Chief_Emrg_1";
value = "Vehicle.custom_chief_emrg_1 gb /skin0 materialsSummer_RAF";
f.add(sect, key, value);
key = "0_Chief_Prisoner_2";
value = "Vehicle.custom_chief_emrg_2 gb ";
f.add(sect, key, value);
ChiefName3 = "0_Chief_Prisoner_";

}
else
{
sect = "CustomChiefs";
key = "";
value = "Vehicle.custom_chief_emrg_0 $core/icons/tank.mma"; //???????
f.add(sect, key, value);
sect = "Vehicle.custom_chief_emrg_0";
key = "Car.Beaverette_III";
value = "";
f.add(sect, key, value);
sect = "Chiefs";
key = "0_Chief_Prisoner_0";
value = "Vehicle.custom_chief_emrg_0 gb ";
f.add(sect, key, value);
ChiefName1 = "0_Chief_Prisoner_";
};
break;
case 2:
if (health < 1f)
{
sect = "CustomChiefs";
key = "";
value = "Vehicle.custom_chief_emrg_0 $core/icons/tank.mma"; //???????
f.add(sect, key, value);
value = "Vehicle.custom_chief_emrg_1 $core/icons/tank.mma";//??????
f.add(sect, key, value);
value = "Vehicle.custom_chief_emrg_2 $core/icons/tank.mma";//????????
f.add(sect, key, value);

sect = "Vehicle.custom_chief_emrg_0";
key = "Car.Renault_UE";
value = "";
f.add(sect, key, value);
key = "TrailerUnit.Foam_Extinguisher_GER1_Transport";
value = "1";
f.add(sect, key, value);

sect = "Vehicle.custom_chief_emrg_1";
key = "Car.Opel_Blitz_cargo_med";
value = "";
f.add(sect, key, value);

sect = "Vehicle.custom_chief_emrg_2";
key = "Car.SdKfz_231_6Rad";
value = "";
f.add(sect, key, value);

sect = "Chiefs";
key = "0_Chief_Fire_0";
value = "Vehicle.custom_chief_emrg_0 de";
f.add(sect, key, value);
key = "0_Chief_Emrg_1";
value = "Vehicle.custom_chief_emrg_1 de";
f.add(sect, key, value);
key = "0_Chief_Prisoner_2";
value = "Vehicle.custom_chief_emrg_2 de /marker0 1940-42_var1";
f.add(sect, key, value);
ChiefName3 = "0_Chief_Prisoner_";

}
else
{
sect = "CustomChiefs";
key = "";
value = "Vehicle.custom_chief_emrg_0 $core/icons/tank.mma"; //???????
f.add(sect, key, value);
sect = "Vehicle.custom_chief_emrg_0";
key = "Car.SdKfz_231_6Rad";
value = "";
f.add(sect, key, value);
sect = "Chiefs";
key = "0_Chief_Prisoner_0";
value = "Vehicle.custom_chief_emrg_0 de /marker0 1940-42_var1";
f.add(sect, key, value);
ChiefName1 = "0_Chief_Prisoner_";
};
break;
default:
break;
};
}


Point3d TmpStartPos = startPos;
TmpStartPos.x += PseudoRnd(-30f, 30f) + fRadius; TmpStartPos.y += PseudoRnd(-30f, 30f) + fRadius;
Point3d BirthPos = EmrgVehicleStartPos(TmpStartPos, startPos);

sect = ChiefName1+"0" + "_Road";
key = "";
value = BirthPos.x.ToString(System.Globalization.CultureInfo.InvariantCulture.NumberFormat) + " " + BirthPos.y.ToString(System.Globalization.CultureInfo.InvariantCulture.NumberFormat) + " " + BirthPos.z.ToString(System.Globalization.CultureInfo.InvariantCulture.NumberFormat) + " 0 92 5 ";
f.add(sect, key, value);
BirthPos.x -= 50f * ((BirthPos.x - aircraftPos.x) / Math.Abs(BirthPos.x - aircraftPos.x)); BirthPos.y -= 50f * ((BirthPos.y - aircraftPos.y) / Math.Abs(BirthPos.y - aircraftPos.y));
value = BirthPos.x.ToString(System.Globalization.CultureInfo.InvariantCulture.NumberFormat) + " " + BirthPos.y.ToString(System.Globalization.CultureInfo.InvariantCulture.NumberFormat) + " " + BirthPos.z.ToString(System.Globalization.CultureInfo.InvariantCulture.NumberFormat);
f.add(sect, key, value);

TmpStartPos = startPos;
TmpStartPos.x += PseudoRnd(-30f, 30f) - fRadius; TmpStartPos.y += PseudoRnd(-30f, 30f) + fRadius;
BirthPos = EmrgVehicleStartPos(TmpStartPos, startPos);
//BirthPos = TmpStartPos;
sect = ChiefName2+"1" + "_Road";
key = "";
value = BirthPos.x.ToString(System.Globalization.CultureInfo.InvariantCulture.NumberFormat) + " " + BirthPos.y.ToString(System.Globalization.CultureInfo.InvariantCulture.NumberFormat) + " " + BirthPos.z.ToString(System.Globalization.CultureInfo.InvariantCulture.NumberFormat) + " 0 92 5 ";
f.add(sect, key, value);
BirthPos.x -= 50f * ((BirthPos.x - aircraftPos.x) / Math.Abs(BirthPos.x - aircraftPos.x)); BirthPos.y -= 50f * ((BirthPos.y - aircraftPos.y) / Math.Abs(BirthPos.y - aircraftPos.y));
value = BirthPos.x.ToString(System.Globalization.CultureInfo.InvariantCulture.NumberFormat) + " " + BirthPos.y.ToString(System.Globalization.CultureInfo.InvariantCulture.NumberFormat) + " " + BirthPos.z.ToString(System.Globalization.CultureInfo.InvariantCulture.NumberFormat);
f.add(sect, key, value);

TmpStartPos = startPos;
TmpStartPos.x += PseudoRnd(-30f, 30f) + fRadius; TmpStartPos.y += PseudoRnd(-30f, 30f) - fRadius;
BirthPos = EmrgVehicleStartPos(TmpStartPos, startPos);

sect = ChiefName3 + "2" + "_Road";
key = "";
value = BirthPos.x.ToString(System.Globalization.CultureInfo.InvariantCulture.NumberFormat) + " " + BirthPos.y.ToString(System.Globalization.CultureInfo.InvariantCulture.NumberFormat) + " " + BirthPos.z.ToString(System.Globalization.CultureInfo.InvariantCulture.NumberFormat) + " 0 92 5 ";
f.add(sect, key, value);
BirthPos.x -= 50f * ((BirthPos.x - aircraftPos.x) / Math.Abs(BirthPos.x - aircraftPos.x)); BirthPos.y -= 50f * ((BirthPos.y - aircraftPos.y) / Math.Abs(BirthPos.y - aircraftPos.y));
value = BirthPos.x.ToString(System.Globalization.CultureInfo.InvariantCulture.NumberFormat) + " " + BirthPos.y.ToString(System.Globalization.CultureInfo.InvariantCulture.NumberFormat) + " " + BirthPos.z.ToString(System.Globalization.CultureInfo.InvariantCulture.NumberFormat);
f.add(sect, key, value);

return f;
}


internal Point3d EmrgVehicleStartPos(Point3d startPos, Point3d endPos)
{
Point3d TmpPos = startPos;

while (((GamePlay.gpLandType(TmpPos.x, TmpPos.y) & LandTypes.WATER) != 0) )
{
TmpPos.x -= (TmpPos.x - endPos.x) / 10f;
TmpPos.y -= (TmpPos.y - endPos.y) / 10f;
};

return TmpPos;
}

internal void CheckEmrgCarOnAirport(int aircraftNumber)
{
// ????????? ???? ?? ??????? ? ?????????
AiGroundGroup MyCar = null;
for (int i = 0; i < CurTechCars.Count; i++)
{
if (CurTechCars[i].TechCar != null )
{
if (CurTechCars[i].TechCar.IsAlive() && CurTechCars[i].BaseAirport == CurPlanesQueue[aircraftNumber].baseAirport && (CurTechCars[i].CarType & CurPlanesQueue[aircraftNumber].State)!=0)
{
MissionLoading = false;
MyCar = CurTechCars[i].TechCar;
if ((CurTechCars[i].cur_rp == null) && (CurTechCars[i].RouteFlag == 0) && (CurTechCars[i].servPlaneNum == -1)) // ???? ????? ??? ???? - ???????? ????????
SetEmrgCarRoute(aircraftNumber, i);
}
}
};
if ((MyCar == null) && !MissionLoading)
{
MissionLoading = true;
int ArmyPos = 0;
if (GamePlay.gpFrontExist())
{
ArmyPos = GamePlay.gpFrontArmy(CurPlanesQueue[aircraftNumber].baseAirport.Pos().x, CurPlanesQueue[aircraftNumber].baseAirport.Pos().y);
}
else { ArmyPos = CurPlanesQueue[aircraftNumber].aircraft.Army(); };
// ??????? ?????? ? ?????????
GamePlay.gpPostMissionLoad(CreateEmrgCarMission(CurPlanesQueue[aircraftNumber].baseAirport.Pos(), (CurPlanesQueue[aircraftNumber].baseAirport.FieldR() / 4), ArmyPos, CurPlanesQueue[aircraftNumber].aircraft.Army(), CurPlanesQueue[aircraftNumber].aircraft.Type(),CurPlanesQueue[aircraftNumber].health, CurPlanesQueue[aircraftNumber].aircraft.Pos()));
}
return ;
}


public override void OnAircraftCrashLanded(int missionNumber, string shortName, AiAircraft aircraft)
{
base.OnAircraftCrashLanded(missionNumber, shortName, aircraft);
Timeout(5, () =>
{
aircraft.Destroy();
});
}

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

AiAirport NearestAirport = FindNearestAirport(aircraft);
if (NearestAirport != null)
{
PlanesQueue CurPlane = new PlanesQueue(aircraft, NearestAirport, 0);
int ArmyPos = 0;
CurPlane.health = (float)aircraft.getParameter(part.ParameterTypes.M_Health, -1);
if (GamePlay.gpFrontExist())
{
ArmyPos = GamePlay.gpFrontArmy(NearestAirport.Pos().x, NearestAirport.Pos().y);
}
else { ArmyPos = aircraft.Army(); };
if (CurPlane.health < 1f)
{
CurPlane.State |= ServiceType.EMERGENCY;
CurPlane.State |= ServiceType.FIRE;
}
else if (aircraft.Army() == ArmyPos)
{
CurPlane.State |= ServiceType.FUEL;
CurPlane.State |= ServiceType.AMMO;
if (aircraft.Type() == AircraftType.Bomber) CurPlane.State |= ServiceType.BOMBS;
};
if (!(aircraft.Army() == ArmyPos)) CurPlane.State |= ServiceType.PRISONERCAPTURE;
if (!CurPlanesQueue.Contains(CurPlane))
{
CurPlanesQueue.Add(CurPlane);
CheckEmrgCarOnAirport(CurPlanesQueue.Count - 1);
}
else
{
for (int i = 0; i < CurPlanesQueue.Count; i++)
if (CurPlanesQueue[i] == CurPlane)
{
CheckEmrgCarOnAirport(i);
break;
}
}
CurPlane = null;
};
}

public override void OnAircraftDamaged(int missionNumber, string shortName, AiAircraft Aircraft, AiDamageInitiator DamageFrom, part.NamedDamageTypes WhatDamaged)
{
base.OnAircraftDamaged(missionNumber, shortName, Aircraft, DamageFrom, WhatDamaged);

if (DamageFrom.Player != null)
{
GamePlay.gpLogServer(null, "{0} hits {1} : {2} \n", new object[] { DamageFrom.Player, shortName, WhatDamaged });
}

}

}

#3392420 - 09/18/11 07:22 AM Re: Ambulance Station: notes from the Cavern [Re: FearlessFrog]  
Joined: Sep 2010
Posts: 29
charlo Offline
Junior Member
charlo  Offline
Junior Member

Joined: Sep 2010
Posts: 29
Los Angeles, CA, USA
Originally Posted By: FearlessFrog
Originally Posted By: charlo
Originally Posted By: FearlessFrog
Charlo - just add the OnDamage.. lines beneath the mission part (before OnBattle..) - it'll work fine.


Thanks very much for the advice, Frog. I tried what you wrote (with variations, too) but had no luck getting both of those scripts to work together when merged into the same .cs file.

Charlo


It can be fiddly, try this one - it should work:

Click to reveal..


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

public class Mission : AMission
{
public override void OnBattleStarted()
{
base.OnBattleStarted();
MissionNumberListener = -1;
}

Random rnd = new Random();


[Flags]
internal enum ServiceType // ??? ????????????? ???????
{
NONE = 0,
EMERGENCY = 1,
FIRE = 2,
FUEL = 4,
AMMO = 8,
BOMBS = 16,
PRISONERCAPTURE = 32
}

internal class TechCars
{
internal AiGroundGroup TechCar { get; set; }
internal AiAirport BaseAirport { get; set; }
internal IRecalcPathParams cur_rp { get; set; }
internal int RouteFlag = 0;
internal int cartype = 0;
internal int servPlaneNum = -1;
internal ServiceType CarType { get { return (ServiceType)cartype; } set { cartype = (int)value; } }

public TechCars(AiGroundGroup car, AiAirport airoport, IRecalcPathParams rp)
{
this.TechCar = car;
this.BaseAirport = airoport;
this.cur_rp = rp;
}

}

internal class PlanesQueue {
internal AiAircraft aircraft { get; set; }
internal AiAirport baseAirport { get; set; }
internal int state = 0;
internal ServiceType State { get { return (ServiceType)state; } set { state = (int)value; } }
internal int Lifetime = 0;
internal float health = 1;
public PlanesQueue(AiAircraft aircraft, AiAirport baseAirport, int state)
{
this.aircraft = aircraft;
this.baseAirport = baseAirport;
this.state = state;
}
}

internal List<TechCars> CurTechCars = new List<TechCars>();
internal List<PlanesQueue> CurPlanesQueue = new List<PlanesQueue>();
TechCars TmpCar = null;
bool MissionLoading = false;

internal double PseudoRnd(double MinValue, double MaxValue)
{
return rnd.NextDouble() * (MaxValue - MinValue) + MinValue;
}



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


AiActor ai_actor = actor as AiActor;
if (ai_actor != null)
{
if (ai_actor is AiGroundGroup)
for (int i = 0; i < CurTechCars.Count; i++) // ???? ????????????? ??????? ??????? ?? ?????????????? ????????, ????????? ?? ????????????
{
if (CurTechCars[i].TechCar == ai_actor as AiGroundGroup)
if (CurTechCars[i].RouteFlag == 1)
EndPlaneService(i);

else
CheckNotServicedPlanes(i);
};
}
}

internal void CheckNotServicedPlanes(int techCarIndex)
{
for (int j = 0; j < CurPlanesQueue.Count; j++)
{
if (CurTechCars[techCarIndex].TechCar.IsAlive() && (CurPlanesQueue[j].baseAirport == CurTechCars[techCarIndex].BaseAirport) && ((CurTechCars[techCarIndex].CarType & CurPlanesQueue[j].State) != 0) && (CurTechCars[techCarIndex].servPlaneNum == -1))
{
if (SetEmrgCarRoute(j, techCarIndex)) // ?????????? ??????? ??????????? ????????? ???????
{
return;
}
}
}
}

internal void EndPlaneService(int techCarIndex)
{
if (CurTechCars[techCarIndex].cur_rp == null) return;
CurTechCars[techCarIndex].cur_rp = null; // ?????????? ???????
if (CurTechCars[techCarIndex].servPlaneNum >= 0)
{

CurPlanesQueue[CurTechCars[techCarIndex].servPlaneNum].State &= ~CurTechCars[techCarIndex].CarType; // ??????? ??? ???????????? ? ?????????????? ????????, ???? ?? ????

CurTechCars[techCarIndex].servPlaneNum = -1; // ?????????? ????? ?????????????? ????????
Timeout(5f, () =>
{
if (!MoveFromRWay(techCarIndex))// ????????? ?? ????? ?? ?? ???????, ? ??????? ? ??? ???? ???.
{
CurTechCars[techCarIndex].RouteFlag = 0;
CheckNotServicedPlanes(techCarIndex); // ? ???????, ??? ?? ??? ????????????? ?????????
}
});

}
else Timeout(5f, () =>
{
CurTechCars[techCarIndex].RouteFlag = 0;
CheckNotServicedPlanes(techCarIndex); // ? ???????, ??? ?? ??? ????????????? ?????????
});


}

internal bool MoveFromRWay(int carNum)
{
bool result = false;
if ((GamePlay.gpLandType(CurTechCars[carNum].TechCar.Pos().x, CurTechCars[carNum].TechCar.Pos().y) & LandTypes.ROAD) == 0)
return result;

Point3d TmpPos = CurTechCars[carNum].TechCar.Pos();
while (((GamePlay.gpLandType(TmpPos.x, TmpPos.y) & LandTypes.ROAD) != 0))
{
TmpPos.x += 10f;
TmpPos.y += 10f;
};
Point2d EmgCarStart, EmgCarFinish;
EmgCarStart.x = CurTechCars[carNum].TechCar.Pos().x; EmgCarStart.y = CurTechCars[carNum].TechCar.Pos().y;
EmgCarFinish.x = TmpPos.x; EmgCarFinish.y = TmpPos.y;
CurTechCars[carNum].servPlaneNum = -1;
CurTechCars[carNum].RouteFlag = 0;
CurTechCars[carNum].cur_rp = null;
CurTechCars[carNum].cur_rp = GamePlay.gpFindPath(EmgCarStart, 10f, EmgCarFinish, 10f, PathType.GROUND, CurTechCars[carNum].TechCar.Army());

result = true;
return result;
}


public bool SetEmrgCarRoute(int aircraftNumber,int carNum)
{
bool result = false;
if (CurTechCars[carNum].TechCar != null)
{
CurTechCars[carNum].servPlaneNum = aircraftNumber; // ????????????? ????? ?????????????? ????????
if (CurTechCars[carNum].cur_rp == null)
{
Point2d EmgCarStart, EmgCarFinish, LandedPos;
LandedPos.x = CurPlanesQueue[aircraftNumber].aircraft.Pos().x; LandedPos.y = CurPlanesQueue[aircraftNumber].aircraft.Pos().y;
int Sign = ((carNum % 2) == 0) ? 2 : -2;
EmgCarStart.x = CurTechCars[carNum].TechCar.Pos().x; EmgCarStart.y = CurTechCars[carNum].TechCar.Pos().y;
EmgCarFinish.x = LandedPos.x - PseudoRnd(2f, 5f) * ((LandedPos.x - EmgCarStart.x) / (Math.Abs(LandedPos.x - EmgCarStart.x))) - Sign;
EmgCarFinish.y = LandedPos.y - PseudoRnd(2f, 5f) * ((LandedPos.y - EmgCarStart.y) / (Math.Abs(LandedPos.y - EmgCarStart.y))) - Sign;
CurTechCars[carNum].cur_rp = GamePlay.gpFindPath(EmgCarStart, 10f, EmgCarFinish, 10f, PathType.GROUND, CurTechCars[carNum].TechCar.Army());
result = true;
}
}
return result;
}


public override void OnMissionLoaded(int missionNumber)
{
base.OnMissionLoaded(missionNumber);
if (missionNumber > 0)
{
List<string> CarTypes = new List<string>();
CarTypes.Add(":0_Chief_Emrg_");
CarTypes.Add(":0_Chief_Fire_");
CarTypes.Add(":0_Chief_Fuel_");
CarTypes.Add(":0_Chief_Ammo_");
CarTypes.Add(":0_Chief_Bomb_");
CarTypes.Add(":0_Chief_Prisoner_");

AiGroundGroup MyCar = null;

for (int i = 0; i < 3; i++)
{
for (int j = 0; j < CarTypes.Count; j++)
{
MyCar = GamePlay.gpActorByName(missionNumber.ToString() + CarTypes[j] + i.ToString()) as AiGroundGroup;
if (MyCar != null)
{
TmpCar = new TechCars(MyCar, FindNearestAirport(MyCar), null);
TmpCar.CarType = (ServiceType)(1 << j);
TmpCar.cur_rp = null;
if (!CurTechCars.Contains(TmpCar))
CurTechCars.Add(TmpCar);
MissionLoading = false;
};
}
}
}
}


public override void OnTickGame() {
base.OnTickGame();
try {
if (Time.tickCounter() % 64 == 0)
{

for (int i = 0; i < CurPlanesQueue.Count; i++)
{
CurPlanesQueue[i].Lifetime++;
if ((CurPlanesQueue[i].State == ServiceType.NONE) || (CurPlanesQueue[i].aircraft == null) || (CurPlanesQueue[i].Lifetime > 200))
{
for (int j = 0; j < CurTechCars.Count; j++)
if (CurTechCars[j].servPlaneNum == i)
EndPlaneService(j);
CurPlanesQueue.RemoveAt(i);
}
};

for (int i = 0; i < CurTechCars.Count; i++)
{
TechCars car = CurTechCars[i];
if ((car.TechCar != null && car.cur_rp != null) && (car.cur_rp.State == RecalcPathState.SUCCESS) )
{
if (car.TechCar.IsAlive() && (car.RouteFlag == 0)/* && (car.servPlaneNum != -1)*/)
{
car.RouteFlag = 1;
car.cur_rp.Path[0].P.x = car.TechCar.Pos().x; car.cur_rp.Path[0].P.y = car.TechCar.Pos().y;
car.TechCar.SetWay(car.cur_rp.Path);
//if (car.servPlaneNum != -1) car.RouteFlag = 0;
}

double Dist = Math.Sqrt((car.cur_rp.Path[car.cur_rp.Path.Length - 1].P.x - car.TechCar.Pos().x) * (car.cur_rp.Path[car.cur_rp.Path.Length - 1].P.x - car.TechCar.Pos().x) + (car.cur_rp.Path[car.cur_rp.Path.Length - 1].P.y - car.TechCar.Pos().y) * (car.cur_rp.Path[car.cur_rp.Path.Length - 1].P.y - car.TechCar.Pos().y));
if (car.servPlaneNum != -1)
{
if (Dist < ((CurPlanesQueue[car.servPlaneNum].aircraft.Type() == AircraftType.Bomber) ? 20f : 10f))
EndPlaneService(i);
}
else if (Dist < 15f)
{
EndPlaneService(i);
}
}
if ((car.cur_rp == null) && (car.RouteFlag == 0) && (car.servPlaneNum != -1))
{
EndPlaneService(i);
};
};
}

} catch (Exception e) {}
}




internal AiAirport FindNearestAirport(AiActor actor)
{
AiAirport aMin = null;
double d2Min = 0;
Point3d pd = actor.Pos();
int n = GamePlay.gpAirports().Length;
for (int i = 0; i < n; i++)
{
AiAirport a = (AiAirport)GamePlay.gpAirports()[i];

if (!a.IsAlive())
continue;

Point3d pp;
pp = a.Pos();
pd.z = pp.z;
double d2 = pd.distanceSquared(ref pp);
if ((aMin == null) || (d2 < d2Min))
{
aMin = a;
d2Min = d2;
}
}
if (d2Min > 2250000.0)
aMin = null;

return aMin;
}

internal ISectionFile CreateEmrgCarMission(Point3d startPos, double fRadius, int portArmy, int planeArmy, AircraftType type, float health, Point3d aircraftPos)
{ ISectionFile f = GamePlay.gpCreateSectionFile();
string sect;
string key;
string value;
string ChiefName1 = "0_Chief_" + (health < 1f ? "Fire_" : "Fuel_");
string ChiefName2 = "0_Chief_" + (health < 1f ? "Emrg_" : "Ammo_");
string ChiefName3 = "0_Chief_" + (health < 1f ? "Bomb_" : "Bomb_");


if (portArmy == planeArmy) //???? ????????
{
switch (portArmy)
{
case 1:
if (health < 1f)
{
sect = "CustomChiefs";
key = "";
value = "Vehicle.custom_chief_emrg_0 $core/icons/tank.mma"; //???????
f.add(sect, key, value);
value = "Vehicle.custom_chief_emrg_1 $core/icons/tank.mma";//??????
f.add(sect, key, value);

sect = "Vehicle.custom_chief_emrg_0";
key = "Car.Austin_K2_ATV";
value = "";
f.add(sect, key, value);
key = "TrailerUnit.Fire_pump_UK2_Transport";
value = "1";
f.add(sect, key, value);
sect = "Vehicle.custom_chief_emrg_1";
key = "Car.Austin_K2_Ambulance";
value = "";
f.add(sect, key, value);

sect = "Chiefs";
key = "0_Chief_Fire_0";
value = "Vehicle.custom_chief_emrg_0 gb /skin0 materialsSummer_RAF";
f.add(sect, key, value);
key = "0_Chief_Emrg_1";
value = "Vehicle.custom_chief_emrg_1 gb /skin0 materialsSummer_RAF";
f.add(sect, key, value);
}
else
{
sect = "CustomChiefs";
key = "";
value = "Vehicle.custom_chief_emrg_0 $core/icons/tank.mma";
f.add(sect, key, value);
value = "Vehicle.custom_chief_emrg_1 $core/icons/tank.mma";
f.add(sect, key, value);

sect = "Vehicle.custom_chief_emrg_0"; // ??????????
key = "Car.Albion_AM463";
value = "";
f.add(sect, key, value);
if (type == AircraftType.Bomber) // ??? ???????? ?????? ??????? ? ????? ????????
{
key = "Car.Fordson_N";
value = "";
f.add(sect, key, value);
key = "TrailerUnit.Towed_Bowser_UK1_Transport";
value = "1";
f.add(sect, key, value);
}

sect = "Vehicle.custom_chief_emrg_1"; // ??????
value = "";
key = "Car.Bedford_MW_open";
f.add(sect, key, value);


if (type == AircraftType.Bomber) // ??? ???????? ????? ????????
{
sect = "CustomChiefs";
key = "";
value = "Vehicle.custom_chief_emrg_2 $core/icons/tank.mma";
f.add(sect, key, value);
sect = "Vehicle.custom_chief_emrg_2";
value = "";
key = "Car.Fordson_N";
value = "";
f.add(sect, key, value);
key = "TrailerUnit.BombLoadingCart_UK1_Transport";
value = "1";
f.add(sect, key, value);
key = "TrailerUnit.BombLoadingCart_UK1_Transport";
f.add(sect, key, value);
};

sect = "Chiefs";
key = "0_Chief_Fuel_0";
value = "Vehicle.custom_chief_emrg_0 gb /skin0 materialsSummer_RAF";
f.add(sect, key, value);

key = "0_Chief_Ammo_1";
value = "Vehicle.custom_chief_emrg_1 gb /skin0 materialsSummer_RAF/tow00_00 1_Static";
f.add(sect, key, value);

if (type == AircraftType.Bomber)
{
key = "0_Chief_Bomb_2";
value = "Vehicle.custom_chief_emrg_2 gb /tow01_00 2_Static/tow01_01 3_Static/tow01_02 4_Static/tow01_03 5_Static/tow02_00 6_Static/tow02_01 7_Static";
f.add(sect, key, value);
}
sect = "Stationary";
key = "1_Static";
value = "Stationary.Morris_CS8-Bedford_MW_CargoAmmo3 gb 0.00 0.00 0.00";
f.add(sect, key, value);
if (type == AircraftType.Bomber) // ????? ??????
{
key = "2_Static";
value = "Stationary.Weapons_.Bomb_B_GP_250lb_MkIV gb 0.00 0.00 0.00";
f.add(sect, key, value);
key = "3_Static";
value = "Stationary.Weapons_.Bomb_B_GP_250lb_MkIV gb 0.00 0.00 0.00";
f.add(sect, key, value);
key = "4_Static";
value = "Stationary.Weapons_.Bomb_B_GP_250lb_MkIV gb 0.00 0.00 0.00";
f.add(sect, key, value);
key = "5_Static";
value = "Stationary.Weapons_.Bomb_B_GP_250lb_MkIV gb 0.00 0.00 0.00";
f.add(sect, key, value);
key = "6_Static";
value = "Stationary.Weapons_.Bomb_B_GP_500lb_MkIV gb 0.00 0.00 0.00";
f.add(sect, key, value);
key = "7_Static";
value = "Stationary.Weapons_.Bomb_B_GP_500lb_MkIV gb 0.00 0.00 0.00";
f.add(sect, key, value);
};
};
break;
case 2:
sect = "CustomChiefs"; //???????
key = "";
value = "Vehicle.custom_chief_emrg_0 $core/icons/tank.mma";
f.add(sect, key, value);
value = "Vehicle.custom_chief_emrg_1 $core/icons/tank.mma";//??????
f.add(sect, key, value);
if (health < 1f)
{
sect = "Vehicle.custom_chief_emrg_0";
key = "Car.Renault_UE";
value = "";
f.add(sect, key, value);
key = "TrailerUnit.Foam_Extinguisher_GER1_Transport";
value = "1";
f.add(sect, key, value);

sect = "Vehicle.custom_chief_emrg_1";
if (PseudoRnd(0f, 1f) < 0.5f)
{
key = "Car.Opel_Blitz_med-tent";
}
else { key = "Car.Opel_Blitz_cargo_med"; };
value = "";
f.add(sect, key, value);
sect = "Chiefs";
key = "0_Chief_Fire_0";// "0_Chief_emrg";
value = "Vehicle.custom_chief_emrg_0 de ";
f.add(sect, key, value);
key = "0_Chief_Emrg_1";// "0_Chief_emrg";
value = "Vehicle.custom_chief_emrg_1 de ";
f.add(sect, key, value);
}
else
{
sect = "Vehicle.custom_chief_emrg_0";
key = "Car.Opel_Blitz_fuel";
value = "";
f.add(sect, key, value);

sect = "Vehicle.custom_chief_emrg_1";
key = "Car.Renault_UE";
f.add(sect, key, value);
key = "TrailerUnit.Oil_Cart_GER1_Transport";
value = "1";
f.add(sect, key, value);
key = "Car.Renault_UE";
value = "";
f.add(sect, key, value);
key = "TrailerUnit.Anlasswagen_(starter)_GER1_Transport";
value = "1";
f.add(sect, key, value);

if (type == AircraftType.Bomber) // ????? ??????
{
sect = "CustomChiefs";
key = "";
value = "Vehicle.custom_chief_emrg_2 $core/icons/tank.mma";
f.add(sect, key, value);
sect = "Vehicle.custom_chief_emrg_2";
key = "Car.Renault_UE";
value = "";
f.add(sect, key, value);
key = "TrailerUnit.HydraulicBombLoader_GER1_Transport";
value = "1";
f.add(sect, key, value);
key = "Car.Renault_UE";
value = "";
f.add(sect, key, value);
key = "TrailerUnit.BombSled_GER1_Transport";
value = "1";
f.add(sect, key, value);
}

sect = "Chiefs";
key = "0_Chief_Fuel_0";
value = "Vehicle.custom_chief_emrg_0 de";
f.add(sect, key, value);
key = "0_Chief_Ammo_1";
value = "Vehicle.custom_chief_emrg_1 de";
f.add(sect, key, value);
if (type == AircraftType.Bomber)
{
key = "0_Chief_Bomb_2";
value = "Vehicle.custom_chief_emrg_2 de /tow01_00 1_Static/tow03_00 2_Static";
f.add(sect, key, value);
sect = "Stationary";
key = "1_Static";
value = "Stationary.Weapons_.Bomb_B_SC-250_Type2_J de 0.00 0.00 0.00";
f.add(sect, key, value);
key = "2_Static";
value = "Stationary.Weapons_.Bomb_B_SC-1000_C de 0.00 0.00 0.00";
f.add(sect, key, value);
};
};
break;
default:
break;

}
}
else
{
switch (portArmy)
{
case 1:
if (health < 1f)
{
sect = "CustomChiefs";
key = "";
value = "Vehicle.custom_chief_emrg_0 $core/icons/tank.mma"; //???????
f.add(sect, key, value);
value = "Vehicle.custom_chief_emrg_1 $core/icons/tank.mma";//??????
f.add(sect, key, value);
value = "Vehicle.custom_chief_emrg_2 $core/icons/tank.mma";//????????
f.add(sect, key, value);

sect = "Vehicle.custom_chief_emrg_0";
key = "Car.Austin_K2_ATV";
value = "";
f.add(sect, key, value);
key = "TrailerUnit.Fire_pump_UK2_Transport";
value = "1";
f.add(sect, key, value);

sect = "Vehicle.custom_chief_emrg_1";
key = "Car.Austin_K2_Ambulance";
value = "";
f.add(sect, key, value);

sect = "Vehicle.custom_chief_emrg_2";
key = "Car.Beaverette_III";
value = "";
f.add(sect, key, value);

sect = "Chiefs";
key = "0_Chief_Fire_0";
value = "Vehicle.custom_chief_emrg_0 gb /skin0 materialsSummer_RAF";
f.add(sect, key, value);
key = "0_Chief_Emrg_1";
value = "Vehicle.custom_chief_emrg_1 gb /skin0 materialsSummer_RAF";
f.add(sect, key, value);
key = "0_Chief_Prisoner_2";
value = "Vehicle.custom_chief_emrg_2 gb ";
f.add(sect, key, value);
ChiefName3 = "0_Chief_Prisoner_";

}
else
{
sect = "CustomChiefs";
key = "";
value = "Vehicle.custom_chief_emrg_0 $core/icons/tank.mma"; //???????
f.add(sect, key, value);
sect = "Vehicle.custom_chief_emrg_0";
key = "Car.Beaverette_III";
value = "";
f.add(sect, key, value);
sect = "Chiefs";
key = "0_Chief_Prisoner_0";
value = "Vehicle.custom_chief_emrg_0 gb ";
f.add(sect, key, value);
ChiefName1 = "0_Chief_Prisoner_";
};
break;
case 2:
if (health < 1f)
{
sect = "CustomChiefs";
key = "";
value = "Vehicle.custom_chief_emrg_0 $core/icons/tank.mma"; //???????
f.add(sect, key, value);
value = "Vehicle.custom_chief_emrg_1 $core/icons/tank.mma";//??????
f.add(sect, key, value);
value = "Vehicle.custom_chief_emrg_2 $core/icons/tank.mma";//????????
f.add(sect, key, value);

sect = "Vehicle.custom_chief_emrg_0";
key = "Car.Renault_UE";
value = "";
f.add(sect, key, value);
key = "TrailerUnit.Foam_Extinguisher_GER1_Transport";
value = "1";
f.add(sect, key, value);

sect = "Vehicle.custom_chief_emrg_1";
key = "Car.Opel_Blitz_cargo_med";
value = "";
f.add(sect, key, value);

sect = "Vehicle.custom_chief_emrg_2";
key = "Car.SdKfz_231_6Rad";
value = "";
f.add(sect, key, value);

sect = "Chiefs";
key = "0_Chief_Fire_0";
value = "Vehicle.custom_chief_emrg_0 de";
f.add(sect, key, value);
key = "0_Chief_Emrg_1";
value = "Vehicle.custom_chief_emrg_1 de";
f.add(sect, key, value);
key = "0_Chief_Prisoner_2";
value = "Vehicle.custom_chief_emrg_2 de /marker0 1940-42_var1";
f.add(sect, key, value);
ChiefName3 = "0_Chief_Prisoner_";

}
else
{
sect = "CustomChiefs";
key = "";
value = "Vehicle.custom_chief_emrg_0 $core/icons/tank.mma"; //???????
f.add(sect, key, value);
sect = "Vehicle.custom_chief_emrg_0";
key = "Car.SdKfz_231_6Rad";
value = "";
f.add(sect, key, value);
sect = "Chiefs";
key = "0_Chief_Prisoner_0";
value = "Vehicle.custom_chief_emrg_0 de /marker0 1940-42_var1";
f.add(sect, key, value);
ChiefName1 = "0_Chief_Prisoner_";
};
break;
default:
break;
};
}


Point3d TmpStartPos = startPos;
TmpStartPos.x += PseudoRnd(-30f, 30f) + fRadius; TmpStartPos.y += PseudoRnd(-30f, 30f) + fRadius;
Point3d BirthPos = EmrgVehicleStartPos(TmpStartPos, startPos);

sect = ChiefName1+"0" + "_Road";
key = "";
value = BirthPos.x.ToString(System.Globalization.CultureInfo.InvariantCulture.NumberFormat) + " " + BirthPos.y.ToString(System.Globalization.CultureInfo.InvariantCulture.NumberFormat) + " " + BirthPos.z.ToString(System.Globalization.CultureInfo.InvariantCulture.NumberFormat) + " 0 92 5 ";
f.add(sect, key, value);
BirthPos.x -= 50f * ((BirthPos.x - aircraftPos.x) / Math.Abs(BirthPos.x - aircraftPos.x)); BirthPos.y -= 50f * ((BirthPos.y - aircraftPos.y) / Math.Abs(BirthPos.y - aircraftPos.y));
value = BirthPos.x.ToString(System.Globalization.CultureInfo.InvariantCulture.NumberFormat) + " " + BirthPos.y.ToString(System.Globalization.CultureInfo.InvariantCulture.NumberFormat) + " " + BirthPos.z.ToString(System.Globalization.CultureInfo.InvariantCulture.NumberFormat);
f.add(sect, key, value);

TmpStartPos = startPos;
TmpStartPos.x += PseudoRnd(-30f, 30f) - fRadius; TmpStartPos.y += PseudoRnd(-30f, 30f) + fRadius;
BirthPos = EmrgVehicleStartPos(TmpStartPos, startPos);
//BirthPos = TmpStartPos;
sect = ChiefName2+"1" + "_Road";
key = "";
value = BirthPos.x.ToString(System.Globalization.CultureInfo.InvariantCulture.NumberFormat) + " " + BirthPos.y.ToString(System.Globalization.CultureInfo.InvariantCulture.NumberFormat) + " " + BirthPos.z.ToString(System.Globalization.CultureInfo.InvariantCulture.NumberFormat) + " 0 92 5 ";
f.add(sect, key, value);
BirthPos.x -= 50f * ((BirthPos.x - aircraftPos.x) / Math.Abs(BirthPos.x - aircraftPos.x)); BirthPos.y -= 50f * ((BirthPos.y - aircraftPos.y) / Math.Abs(BirthPos.y - aircraftPos.y));
value = BirthPos.x.ToString(System.Globalization.CultureInfo.InvariantCulture.NumberFormat) + " " + BirthPos.y.ToString(System.Globalization.CultureInfo.InvariantCulture.NumberFormat) + " " + BirthPos.z.ToString(System.Globalization.CultureInfo.InvariantCulture.NumberFormat);
f.add(sect, key, value);

TmpStartPos = startPos;
TmpStartPos.x += PseudoRnd(-30f, 30f) + fRadius; TmpStartPos.y += PseudoRnd(-30f, 30f) - fRadius;
BirthPos = EmrgVehicleStartPos(TmpStartPos, startPos);

sect = ChiefName3 + "2" + "_Road";
key = "";
value = BirthPos.x.ToString(System.Globalization.CultureInfo.InvariantCulture.NumberFormat) + " " + BirthPos.y.ToString(System.Globalization.CultureInfo.InvariantCulture.NumberFormat) + " " + BirthPos.z.ToString(System.Globalization.CultureInfo.InvariantCulture.NumberFormat) + " 0 92 5 ";
f.add(sect, key, value);
BirthPos.x -= 50f * ((BirthPos.x - aircraftPos.x) / Math.Abs(BirthPos.x - aircraftPos.x)); BirthPos.y -= 50f * ((BirthPos.y - aircraftPos.y) / Math.Abs(BirthPos.y - aircraftPos.y));
value = BirthPos.x.ToString(System.Globalization.CultureInfo.InvariantCulture.NumberFormat) + " " + BirthPos.y.ToString(System.Globalization.CultureInfo.InvariantCulture.NumberFormat) + " " + BirthPos.z.ToString(System.Globalization.CultureInfo.InvariantCulture.NumberFormat);
f.add(sect, key, value);

return f;
}


internal Point3d EmrgVehicleStartPos(Point3d startPos, Point3d endPos)
{
Point3d TmpPos = startPos;

while (((GamePlay.gpLandType(TmpPos.x, TmpPos.y) & LandTypes.WATER) != 0) )
{
TmpPos.x -= (TmpPos.x - endPos.x) / 10f;
TmpPos.y -= (TmpPos.y - endPos.y) / 10f;
};

return TmpPos;
}

internal void CheckEmrgCarOnAirport(int aircraftNumber)
{
// ????????? ???? ?? ??????? ? ?????????
AiGroundGroup MyCar = null;
for (int i = 0; i < CurTechCars.Count; i++)
{
if (CurTechCars[i].TechCar != null )
{
if (CurTechCars[i].TechCar.IsAlive() && CurTechCars[i].BaseAirport == CurPlanesQueue[aircraftNumber].baseAirport && (CurTechCars[i].CarType & CurPlanesQueue[aircraftNumber].State)!=0)
{
MissionLoading = false;
MyCar = CurTechCars[i].TechCar;
if ((CurTechCars[i].cur_rp == null) && (CurTechCars[i].RouteFlag == 0) && (CurTechCars[i].servPlaneNum == -1)) // ???? ????? ??? ???? - ???????? ????????
SetEmrgCarRoute(aircraftNumber, i);
}
}
};
if ((MyCar == null) && !MissionLoading)
{
MissionLoading = true;
int ArmyPos = 0;
if (GamePlay.gpFrontExist())
{
ArmyPos = GamePlay.gpFrontArmy(CurPlanesQueue[aircraftNumber].baseAirport.Pos().x, CurPlanesQueue[aircraftNumber].baseAirport.Pos().y);
}
else { ArmyPos = CurPlanesQueue[aircraftNumber].aircraft.Army(); };
// ??????? ?????? ? ?????????
GamePlay.gpPostMissionLoad(CreateEmrgCarMission(CurPlanesQueue[aircraftNumber].baseAirport.Pos(), (CurPlanesQueue[aircraftNumber].baseAirport.FieldR() / 4), ArmyPos, CurPlanesQueue[aircraftNumber].aircraft.Army(), CurPlanesQueue[aircraftNumber].aircraft.Type(),CurPlanesQueue[aircraftNumber].health, CurPlanesQueue[aircraftNumber].aircraft.Pos()));
}
return ;
}


public override void OnAircraftCrashLanded(int missionNumber, string shortName, AiAircraft aircraft)
{
base.OnAircraftCrashLanded(missionNumber, shortName, aircraft);
Timeout(5, () =>
{
aircraft.Destroy();
});
}

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

AiAirport NearestAirport = FindNearestAirport(aircraft);
if (NearestAirport != null)
{
PlanesQueue CurPlane = new PlanesQueue(aircraft, NearestAirport, 0);
int ArmyPos = 0;
CurPlane.health = (float)aircraft.getParameter(part.ParameterTypes.M_Health, -1);
if (GamePlay.gpFrontExist())
{
ArmyPos = GamePlay.gpFrontArmy(NearestAirport.Pos().x, NearestAirport.Pos().y);
}
else { ArmyPos = aircraft.Army(); };
if (CurPlane.health < 1f)
{
CurPlane.State |= ServiceType.EMERGENCY;
CurPlane.State |= ServiceType.FIRE;
}
else if (aircraft.Army() == ArmyPos)
{
CurPlane.State |= ServiceType.FUEL;
CurPlane.State |= ServiceType.AMMO;
if (aircraft.Type() == AircraftType.Bomber) CurPlane.State |= ServiceType.BOMBS;
};
if (!(aircraft.Army() == ArmyPos)) CurPlane.State |= ServiceType.PRISONERCAPTURE;
if (!CurPlanesQueue.Contains(CurPlane))
{
CurPlanesQueue.Add(CurPlane);
CheckEmrgCarOnAirport(CurPlanesQueue.Count - 1);
}
else
{
for (int i = 0; i < CurPlanesQueue.Count; i++)
if (CurPlanesQueue[i] == CurPlane)
{
CheckEmrgCarOnAirport(i);
break;
}
}
CurPlane = null;
};
}

public override void OnAircraftDamaged(int missionNumber, string shortName, AiAircraft Aircraft, AiDamageInitiator DamageFrom, part.NamedDamageTypes WhatDamaged)
{
base.OnAircraftDamaged(missionNumber, shortName, Aircraft, DamageFrom, WhatDamaged);

if (DamageFrom.Player != null)
{
GamePlay.gpLogServer(null, "{0} hits {1} : {2} \n", new object[] { DamageFrom.Player, shortName, WhatDamaged });
}

}

}


Yep, that works great - thank you very much (and such a quick reply from you, too)!

Charlo


i7-950 OC to 4 GHz CPU
Asus P6X58D-E X58 MB
Sapphire HD 7950 OC 3GB GCU
Windows 7 Ult. 64 bit
======
MacBook Pro Core2Duo 2.66 GHz
http://i49.tinypic.com/j8zkzr.png
#3394285 - 09/20/11 10:15 PM Re: Ambulance Station: notes from the Cavern [Re: Ming_EAF19]  
Joined: Jun 2001
Posts: 2,264
No457_Squog Offline
Squadron Leader
No457_Squog  Offline
Squadron Leader
Member

Joined: Jun 2001
Posts: 2,264
Melbourne, Australia
The fire is still burning on this...

I've made some (untested) changes to the script and added an 'engineer' vehicle (and understood more about the code in the process, too...) which acts the same way as the others at the moment. Will post my code once I get it working smile


No457_Squog
Squadron Leader

No. 457 Squadron vRAAF
Page 2 of 3 1 2 3

Moderated by  RacerGT 

Quick Search
Recent Articles
Support SimHQ

If you shop on Amazon use this Amazon link to support SimHQ
.
Social


Recent Topics
CD WOFF
by Britisheh. 03/28/24 08:05 PM
Carnival Cruise Ship Fire....... Again
by F4UDash4. 03/26/24 05:58 PM
Baltimore Bridge Collapse
by F4UDash4. 03/26/24 05:51 PM
The Oldest WWII Veterans
by F4UDash4. 03/24/24 09:21 PM
They got fired after this.
by Wigean. 03/20/24 08:19 PM
Grown ups joke time
by NoFlyBoy. 03/18/24 10:34 PM
Anyone Heard from Nimits?
by F4UDash4. 03/18/24 10:01 PM
RIP Gemini/Apollo astronaut Tom Stafford
by semmern. 03/18/24 02:14 PM
Copyright 1997-2016, SimHQ Inc. All Rights Reserved.

Powered by UBB.threads™ PHP Forum Software 7.6.0