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

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

Reply
 
Thread Tools Display Modes
  #1  
Old 02-21-2012, 10:15 AM
FG28_Kodiak FG28_Kodiak is offline
Approved Member
 
Join Date: Dec 2009
Location: Swabia->Bavaria->Germany
Posts: 884
Default

As 41Sqn_Banks says there is no way to set parameters for a plane via script. So the only way to simulate RRR is to create a new plane and place the player in it.

I've made a example, it's not complete (i will never finished it, no fan of "RRR" ) but may be it shows the direction to go.
Code:
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Text.RegularExpressions;
using maddox.game;
using maddox.game.world;
using maddox.GP;


public class Mission : AMission
{
    bool RRRinProgress = false;


    private AiAirport getCurrentAirfield(AiActor actor, double maxdistance)
    {
        AiAirport NearestAirfield = null;
        AiAirport[] airports = GamePlay.gpAirports();

        Point3d actorPos = actor.Pos();

        if (airports != null)
        {
            foreach (AiAirport airport in airports)
            {
                if (NearestAirfield != null)
                {
                    if (NearestAirfield != null)
                        if (NearestAirfield.Pos().distance(ref actorPos) > airport.Pos().distance(ref actorPos))
                            NearestAirfield = airport;
                }
                else NearestAirfield = airport;
            }
        }

        if (NearestAirfield.Pos().distance(ref actorPos) < maxdistance)
            return NearestAirfield;
        else
            return null;
    }


    private bool IsGrounded(AiActor actor)
    {
        if ((actor as AiAircraft).getParameter(part.ParameterTypes.Z_VelocityTAS, -1) <= 1.0)
            return true;
        else
            return false;
    }


    internal bool checkAirfield(AiActor actor, AiAirport airport, double maxdistance)
    {
        Point3d ActorPos = actor.Pos();
        
        if (airport.Pos().distance(ref ActorPos) < maxdistance)
            return true;
        else return false;
    }


    private void CountDown(string Message, string EndMessage, double seconds)
    {
        string tmpMessage = Message + " {0}";
        double count = 0.0;

        while (count < seconds)
        {
            Timeout(count++, () =>
                {
                    GamePlay.gpHUDLogCenter(null, tmpMessage, new object[] { seconds-- });
                });
        }
        Timeout(count, () =>
        {
            GamePlay.gpHUDLogCenter(null, EndMessage, null);
        });
    }

    public void SetMainMenu(Player player)
    {
        GamePlay.gpSetOrderMissionMenu(player, false, 0, new string[] { "RRR" }, new bool[] { true });
    }


    public void SetRRRMenu(Player player)
    {
        if (IsGrounded(player.Place()) && !RRRinProgress )
            GamePlay.gpSetOrderMissionMenu(player, false, 10, new string[] { "Refuel, Rearm, Repair current Plane"}, new bool[] { true });
        else
            GamePlay.gpSetOrderMissionMenu(player, false, 11, new string[] { "Not possible" }, new bool[] { false });
    }


    public override void OnOrderMissionMenuSelected(Player player, int ID, int menuItemIndex)
    {

        if (ID == 0)
        {
            if (menuItemIndex == 1)
            {
                SetRRRMenu(player);
            }
        }
        if (ID == 10)
        {
            if (menuItemIndex == 1)
            {
                changePlayerPlane(player, 10);
                SetMainMenu(player);
            }
        }
        if (ID == 11)
        { //return to main menu
            SetMainMenu(player);
        }
    }

    //not finished yet - a lot of work to do at the moment only Airgroup, AircraftType and Location is handled
    internal ISectionFile CreateNewPlaneAtAirfield(AiAirport airport, AiActor actor)
    {
        if (actor == null) return null;
        if (!(actor is AiAircraft)) return null;
        

        ISectionFile f = GamePlay.gpCreateSectionFile();
        string sect;
        string key;
        string value;

        string[] splittet = (actor as AiAircraft).AirGroup().Name().Split(':');
        string airgroupname = splittet[1];

        sect = "AirGroups";
        key = airgroupname;
        value = "";
        f.add(sect, key, value);

        sect = airgroupname;
        
        f.add(sect, "Flight0", "1");

        key = "Class";
        value = (actor as AiAircraft).InternalTypeName().Replace("bob:", "");
        f.add(sect, key, value);

        f.add(sect, "Formation", "LINEABREAST"); 
        f.add(sect, "CallSign", "26");
        f.add(sect, "Fuel", "100");
        f.add(sect, "Weapons", "1 1");
        f.add(sect, "SetOnPark", "1");
        f.add(sect, "Idle", "1");
        f.add(sect, "Skill", "0.3 0.3 0.3 0.3 0.3 0.3 0.3 0.3");

        sect = airgroupname + "_Way";
        key = "TAKEOFF";
        value = airport.Pos().x.ToString(System.Globalization.CultureInfo.InvariantCulture.NumberFormat) + " " + airport.Pos().y.ToString(System.Globalization.CultureInfo.InvariantCulture.NumberFormat) + "  0 0";

        f.add(sect, key, value);

        return f;
    }


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

        MissionNumberListener = -1;
    }


    private void changePlayerPlane(Player player, double seconds)
    {
        RRRinProgress = true;
        CountDown("Rearming/Refueling finished in:", "Finished", seconds);

        int newMissionNumber = GamePlay.gpNextMissionNumber();

        Timeout(seconds, () =>
            {
                
                GamePlay.gpPostMissionLoad(CreateNewPlaneAtAirfield(getCurrentAirfield(player.Place(), 700), GamePlay.gpPlayer().Place()));
                
            });

        string CurrentName = player.Place().Name();
        string[] tmpString = CurrentName.Split(':');

        string NewActorName = newMissionNumber + ":" + tmpString[1];

        Timeout(seconds+1, () =>
        {
            AiActor NewActor = GamePlay.gpActorByName(NewActorName);

            if (NewActor != null)
                player.PlaceEnter(NewActor, 0);

            AiActor OldActor = GamePlay.gpActorByName(CurrentName);
            if (OldActor != null)
                (OldActor as AiAircraft).Destroy();
            
            RRRinProgress = false;
        });
    }


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

        SetMainMenu(player);
    }
}
The script copy player plane with "CreateNewPlaneAtAirfield" (this part is not complete at the moment it only copy the Airgroup, PlaneType and uses the AirfieldLocation) after a countdown then places the player in the new one and Destroy the old one.

You can start the "RRR-Simulation" with the Mission-Menu
TAB->4
Attached Files
File Type: zip RRRTest.zip (2.2 KB, 12 views)

Last edited by FG28_Kodiak; 02-21-2012 at 10:20 AM.
Reply With Quote
Reply


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 04:07 AM.


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