Fulqrum Publishing Home   |   Register   |   Today Posts   |   Members   |   UserCP   |   Calendar   |   Search   |   FAQ

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

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #34  
Old 05-22-2016, 07:14 AM
flug32 flug32 is offline
Approved Member
 
Join Date: Feb 2016
Posts: 4
Default

Quote:
Originally Posted by flug32 View Post
FILE: auto-generate-vehicles.cs
CODE CONTINUED IN PART 2!
And, here is part 2/2 of FILE: auto-generate-vehicles.cs
Code:
    ///TODO: This is highly repetitious & could be abstracted to a single simpler
    //method called 3X.  Then it would be easy to add several more types of 
    //cars etc.

    internal ISectionFile CreateEmrgCarMission(Point3d startPos, double fRadius, int portArmy, int planeArmy, AircraftType type, float health, Point3d aircraftPos, bool reverse=false, ServiceType planeState=ServiceType.NONE )
    //Note that planeState isn't actually used below . . . health is, plus
    //a/c type, army, etc.
    {   ISectionFile f = GamePlay.gpCreateSectionFile();
        string sect;
        string key;
        string value, value1, value2;
        string ChiefName1 = "0_Chief_" + (health < 1f ? "Fire_" : "Fuel_");
        string ChiefName2 = "0_Chief_" + (health < 1f ? "Emrg_" : "Ammo_");
        string ChiefName3 = "0_Chief_" + (health < 1f ? "Bomb_" : "Bomb_");

        //startPos=aircraftPos; //bhugh special, we're just going to spawn them in very near the actual a/c
        if (DEBUG) GamePlay.gpLogServer(null, "Ground car group created at " + startPos.ToString () + " for " + aircraftPos.ToString () + " " + FindNearestAirport(aircraftPos).Name(), new object[] { });
        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;
            };
        }

        
        
        //Little cleanup on variables; avoid div by zero later on; route finder doesn't like it if the points are underground
        if (startPos.z == 0 ) startPos.z=1000;
        if (aircraftPos.z == 0 ) aircraftPos.z=1000;
        if ((startPos.x - aircraftPos.x )< 5 ) startPos.x = aircraftPos.x + 75;    
        if ((startPos.y - aircraftPos.y )< 5 ) startPos.y = aircraftPos.y + 75;
            
        //Instead of starting way out of sight, we're going to start
        //in the direction of the startPos, but at distance dis, which
        //is closer in to the a/c
        Point3d closerStartPos=startPos;
        if (!reverse) {      
          double dis=SPAWN_START_DISTANCE_M;
          closerStartPos.x = aircraftPos.x+ dis * ((startPos.x - aircraftPos.x) / Math.Abs(startPos.x - aircraftPos.x)); closerStartPos.y = aircraftPos.y + dis * ((startPos.y - aircraftPos.y) / Math.Abs(startPos.y - aircraftPos.y));                     
        }
        Point3d TmpStartPos = closerStartPos;
        TmpStartPos.x += PseudoRnd(-30f, 30f) + fRadius; TmpStartPos.y += PseudoRnd(-30f, 30f) + fRadius; 
        Point3d BirthPos = EmrgVehicleStartPos(TmpStartPos, startPos);        
        double disx, disy;
        
        sect = ChiefName1+"0" + "_Road";
        key = "";
        value1 = 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 ";
        Console.WriteLine(value1);
        //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));

        double edis=SPAWN_END_DISTANCE_M; //how far away from the plane we stop, when driving in towards it.
        if (reverse) edis= SPAWN_START_DISTANCE_REVERSE_M; //IN CASE OF reverse we call this the 'start' distance because we are starting rather then ending here.  (Thus the name, 'reverse').  This tells where the vehicles start, when starting close & then driving out away from the a/c.  
        disx=Math.Abs(BirthPos.x - aircraftPos.x) - (edis-2);
        if (disx<(edis-2)) disx=(edis-2);
        disy=Math.Abs(BirthPos.y - aircraftPos.y) - edis;
        if (disy<edis) disy=edis;

        BirthPos.x -= disx * ((BirthPos.x - aircraftPos.x) / Math.Abs(BirthPos.x - aircraftPos.x)); BirthPos.y -= disy * ((BirthPos.y - aircraftPos.y) / Math.Abs(BirthPos.y - aircraftPos.y));
        value2 = 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 ";;
        Console.WriteLine(value2);
        
        if (reverse ) {
          f.add(sect, key, value2);
          f.add(sect, key, value1);
        }else {
          f.add(sect, key, value1);
          f.add(sect, key, value2);
        }  

        TmpStartPos = closerStartPos;
        TmpStartPos.x += PseudoRnd(-30f, 30f) - fRadius; TmpStartPos.y += PseudoRnd(-30f, 30f) + fRadius;
        BirthPos = EmrgVehicleStartPos(TmpStartPos, startPos);
        //BirthPos = TmpStartPos;
        sect = ChiefName2+"1" + "_Road";
        key = "";
        value1 = 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 ";        
        Console.WriteLine(value1);
        
        disx=Math.Abs(BirthPos.x - aircraftPos.x) - (edis+1);
        if (disx<10) disx=(edis+1);
        disy=Math.Abs(BirthPos.y - aircraftPos.y) - (edis-2);
        if (disy<(edis-2)) disy=(edis-2);

        BirthPos.x -= disx * ((BirthPos.x - aircraftPos.x) / Math.Abs(BirthPos.x - aircraftPos.x)); BirthPos.y -= disy * ((BirthPos.y - aircraftPos.y) / Math.Abs(BirthPos.y - aircraftPos.y));

        value2 = 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 ";;
        Console.WriteLine(value2);
        
        if (reverse ) {
          f.add(sect, key, value2);
          f.add(sect, key, value1);
        }else {
          f.add(sect, key, value1);
          f.add(sect, key, value2);
        }  


        TmpStartPos = closerStartPos;
        TmpStartPos.x += PseudoRnd(-30f, 30f) + fRadius; TmpStartPos.y += PseudoRnd(-30f, 30f) - fRadius;
        BirthPos = EmrgVehicleStartPos(TmpStartPos, startPos);
        
        sect = ChiefName3 + "2" + "_Road";
        key = "";
        value1 = 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 ";
        Console.WriteLine(value1);
        
        disx=Math.Abs(BirthPos.x - aircraftPos.x) - (edis-1);
        if (disx<(edis-1)) disx=(edis-1);
        disy=Math.Abs(BirthPos.y - aircraftPos.y) - (edis+2);
        if (disy<(edis+2)) disy=(edis+2);

        BirthPos.x -= disx * ((BirthPos.x - aircraftPos.x) / Math.Abs(BirthPos.x - aircraftPos.x)); BirthPos.y -= disy * ((BirthPos.y - aircraftPos.y) / Math.Abs(BirthPos.y - aircraftPos.y));
        value2 = 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 ";;
        Console.WriteLine(value2);
         if (reverse ) {
          f.add(sect, key, value2);
          f.add(sect, key, value1);
        }else {
          f.add(sect, key, value1);
          f.add(sect, key, value2);
        }  
        
        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)
    {
        // ????????? ???? ?? ??????? ? ?????????         
        //MissionLoading=false; //kludgy fix, this seems to be in place to avoid mission load loops or something, but it doesn't work
        AiGroundGroup MyCar = null;   
         
        {           
            if (DEBUG) GamePlay.gpLogServer(null, "Creating a new car group at " + CurPlanesQueue[aircraftNumber].basePos.Name()  + " for " + aircraftNumber, new object[] { }); 
            MissionLoading = true;
            MissionLoadingAircraftNumber=aircraftNumber;
            int ArmyPos = 0;
            if (GamePlay.gpFrontExist())
            {
                ArmyPos = GamePlay.gpFrontArmy(CurPlanesQueue[aircraftNumber].basePos.Pos().x, CurPlanesQueue[aircraftNumber].basePos.Pos().y);
            }
            else { ArmyPos = CurPlanesQueue[aircraftNumber].aircraft.Army(); };            
            // ??????? ?????? ? ?????????
            //In case of spawn-in, we reverse the direction making it away from the plane.  
            
            if (DEBUG) GamePlay.gpLogServer(null, "Creating a new car group at " + ((int)CurPlanesQueue[aircraftNumber].State).ToString()+" " + ((int)ServiceType.SPAWNIN).ToString()+ " " + ( ((int)CurPlanesQueue[aircraftNumber].State & (int)ServiceType.SPAWNIN) ==0  ).ToString(), new object[] { });
                                                 
            bool reverse=true;
            if ( ((int)CurPlanesQueue[aircraftNumber].State & (int)ServiceType.SPAWNIN) ==0  ) reverse=false;
                        
              GamePlay.gpPostMissionLoad(CreateEmrgCarMission(CurPlanesQueue[aircraftNumber].basePos.Pos(), CAR_POS_RADIUS, ArmyPos, CurPlanesQueue[aircraftNumber].aircraft.Army(), CurPlanesQueue[aircraftNumber].aircraft.Type(),CurPlanesQueue[aircraftNumber].health, CurPlanesQueue[aircraftNumber].aircraft.Pos(), reverse, CurPlanesQueue[aircraftNumber].State));
             
            
        }        
        return ;
    }

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


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

//TODO: For bombers, this will re-spawn vehicles whenever they change places

public override void OnPlaceEnter (Player player, AiActor actor, int placeIndex) 
  {
        base.OnPlaceEnter(player, actor, placeIndex);
    
        AiAircraft aircraft= actor as AiAircraft;
        
        if (DEBUG) GamePlay.gpLogServer(null, "Place Enter: " + 
          player.Name() + " " + 
          actor.Name() + " " + 
          placeIndex.ToString() + " " , new object[] { });
          
        //do this only once per actor (avoids many multiple vehicle spawn-ins whwenever bomber players move between positions, triggering this OnplaceEnter repeatedly)
        if (!actorPlaceEnterList.Contains(actor)) {
           StartVehiclesForAircraft (aircraft, true ); //this is spawn-in, so we reverse vehicle direction
           actorPlaceEnterList.Add(actor);
        }   
        
    }  
    

    public override void OnCarter(AiActor actor, int placeIndex)
    {
        base.OnCarter(actor, placeIndex);
    
        AiAircraft aircraft= actor as AiAircraft;
        
        if (DEBUG) GamePlay.gpLogServer(null, "OnCarter: " +            
          actor.Name() + " " + 
          placeIndex.ToString() + " " , new object[] { });
        
    }

    public override void OnPersonMoved(AiPerson person, AiActor fromCart, int fromPlaceIndex)
    {
        base.OnPersonMoved(person, fromCart, fromPlaceIndex);
    
        AiAircraft aircraft= fromCart as AiAircraft;
        
        if (DEBUG) GamePlay.gpLogServer(null, "OnPersonMoved: " +            
          fromCart.Name() + " " +
          person.Name() + " " + 
          fromPlaceIndex.ToString() + " " , new object[] { });
        
    }
       
    
    public override void OnAircraftTookOff(int missionNumber, string shortName, AiAircraft aircraft)
    {
        base.OnAircraftTookOff(missionNumber, shortName, aircraft);
        try
        {
        //AiAircraft aircraft= actor as AiAircraft;
        
           if (DEBUG) GamePlay.gpLogServer(null, "Starting vehicle/took off", new object[] { });
           
           if ( !isAiControlledPlane2(aircraft) && !aircraftActiveList.Contains(aircraft)) aircraftActiveList.Add(aircraft);
        }
        catch (Exception e) {System.Console.WriteLine (e.ToString());}
        
    } 
    
    
    public override void OnAircraftDamaged(int missionNumber, string shortName, AiAircraft aircraft, AiDamageInitiator initiator, NamedDamageTypes damageType)
    {
        
        base.OnAircraftDamaged(missionNumber, shortName, aircraft, initiator, damageType);
        try
        {
            //just keep a list of all damaged aircraft
            if (!aircraftDamagedList.Contains(aircraft)) aircraftDamagedList.Add(aircraft);
            if ( !isAiControlledPlane2(aircraft) && !aircraftActiveList.Contains(aircraft)) aircraftActiveList.Add(aircraft);                             

        }
        catch (Exception e) {System.Console.WriteLine (e.ToString());}
        
        //add your code here
    }

    public override void OnAircraftCutLimb(int missionNumber, string shortName, AiAircraft aircraft, AiDamageInitiator initiator, LimbNames limbName)    
    {
        
        base.OnAircraftCutLimb(missionNumber, shortName, aircraft, initiator, limbName);
        try
        {
            //just keep a list of all damaged aircraft
            if (!aircraftDamagedList.Contains(aircraft)) aircraftDamagedList.Add(aircraft);
            if ( !isAiControlledPlane2(aircraft) && !aircraftActiveList.Contains(aircraft)) aircraftActiveList.Add(aircraft);
        }
        catch (Exception e) {System.Console.WriteLine (e.ToString());}
            
    }
    
    public void OnAircraftStopped (AiAircraft aircraft)
    {        
        try
        {   
           if (aircraft != null ) {
           
                      if (DEBUG) GamePlay.gpLogServer(null, "Aircraft detected as stopped/landed: " + 
                      aircraft.Player(0).Name() + " " + 
                      aircraft.Name() + " ", new object[] { });

              StartVehiclesForAircraft (aircraft );
              aircraftActiveList.Remove(aircraft);  //The only way they can get back on the list is by taking off again.  Given the way CloD works, this might not be possible if they just landed in a field or whatever.  But them's the breaks . . . 
           }   
               
        }
        catch (Exception e) {System.Console.WriteLine (e.ToString());}     
        
    }         
    
    public override void OnActorDead(int missionNumber, string shortName, AiActor actor, List<DamagerScore> damages)
    {
        #region stb
        base.OnActorDead(missionNumber, shortName, actor, damages);
        try
        {   
           if (actor as AiAircraft != null ) {
              StartVehiclesForAircraft (actor as AiAircraft );
              aircraftActiveList.Remove(actor as AiAircraft);
           }      
               
        }
        catch (Exception e) {System.Console.WriteLine (e.ToString());}
        #endregion
        //add your code here
    }
  

     public void StartVehiclesForAircraft (AiAircraft aircraft, bool spawnIn=false ) {
          try 
          {   
            if (aircraft==null ||  isAiControlledPlane2(aircraft) ) return;
            if (DEBUG) GamePlay.gpLogServer(null, "Getting Airports for startvehicles", new object[] { });
            BasePos NearestAirport = new BasePos();
            NearestAirport = FindNearestAirport(aircraft);          
    
            if (DEBUG) GamePlay.gpLogServer(null, "Starting vehicles at " + NearestAirport.Name(), new object[] { });
            
            if (NearestAirport != null)
            {
                
                PlanesQueue CurPlane = new PlanesQueue(aircraft, NearestAirport, 0);
                int ArmyPos = 0;
                CurPlane.health = (float)aircraft.getParameter(part.ParameterTypes.M_Health, -1);
                
                if (aircraftDamagedList.Contains(aircraft)) CurPlane.health /=2;
                //CurPlane.health=0; //testing                                
                
                float cdam = (float)aircraft.getParameter(part.ParameterTypes.M_CabinDamage, 1);
                float ndam = (float)aircraft.getParameter(part.ParameterTypes.M_NamedDamage, 1);
               
                //note that MANY of the CurPlane.States set below do not do anything
                //because the actual type of ai vehicle spawned is determined
                //in the createemrgcarmission method via various criteria including
                //army, health, type of plane etc but not really using the states
                //set here AT ALL. FYI. 
                if (DEBUG) GamePlay.gpLogServer(null, "Health = " + CurPlane.health.ToString() + " " + cdam.ToString() + " " + ndam.ToString(), new object[] { });  
                
                if (spawnIn) CurPlane.State |= ServiceType.SPAWNIN;
                if (GamePlay.gpFrontExist())
                {
                    ArmyPos = GamePlay.gpFrontArmy(NearestAirport.Pos().x, NearestAirport.Pos().y);
                }
                else { ArmyPos = aircraft.Army(); };
                //if (true || CurPlane.health < 1f) //testing
                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;
                    CurPlane.State |= ServiceType.BOMBS;
                };
                //if (true || !(aircraft.Army() == ArmyPos)) CurPlane.State |= ServiceType.PRISONERCAPTURE; //testing
                if (!(aircraft.Army() == ArmyPos)) CurPlane.State |= ServiceType.PRISONERCAPTURE;
                if (!CurPlanesQueue.Contains(CurPlane))
                {
                    if (DEBUG) GamePlay.gpLogServer(null, "Starting vehicles at " + NearestAirport.Name()+ " Type: " + CurPlane.State, new object[] { });
                    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;
            }
          } 
          catch (Exception e) {System.Console.WriteLine (e.ToString());} 
     }

     private void checkForStoppedAircraft (List <AiAircraft> aircraftList){
       int a_count=0;
       double Z_VelocityTAS;
       
       foreach (AiAircraft a in aircraftList ) {
       
         Z_VelocityTAS = a.getParameter(part.ParameterTypes.Z_VelocityTAS, -1);
         
         //If true airspeed is 0 now, check again in 5 seconds.  If still 0 we're assuming crashed and/or landed somehow.
         if (Z_VelocityTAS == 0) {
         
            Timeout (5, () => { 
               Z_VelocityTAS = a.getParameter(part.ParameterTypes.Z_VelocityTAS, -1);
               if (Z_VelocityTAS == 0) OnAircraftStopped(a);
            
            });
         
         
         }
       
       }
     
     
     }    
    
     //Returns whether aircraft is an Ai plane (no humans in any seats)
     private bool isAiControlledPlane2(AiAircraft aircraft)  
     { // returns true if specified aircraft is AI controlled with no humans aboard, otherwise false
        if (aircraft == null) return false;
        //check if a player is in any of the "places"
        for (int i = 0; i < aircraft.Places(); i++)
        {
           if (aircraft.Player(i) != null) return false;
        }
        return true;
     }
     

     
        
     private string Left(string Original, int Count)
     {      
        if (Original == null || Original == string.Empty || Original.Length <
        Count) {
          return Original;
        } else {
          // Return a sub-string of the original string, starting at index 0.
          return Original.Substring(0, Count);
        }
     }       
}
ZIP file with script & mission files, sample code, instructions all in one

Last edited by flug32; 05-22-2016 at 07:39 AM.
Reply With Quote
 

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 10:41 PM.


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