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 05-16-2011, 11:06 PM
TheEnlightenedFlorist TheEnlightenedFlorist is offline
Approved Member
 
Join Date: May 2011
Location: SLC, Utah, USA
Posts: 143
Default

Thanks for the help Ataros, I'll start experimenting with that right away.

As for your code, what exactly isn't working? I can tell you right now that case 3 will never run because the Next(int, int) method returns an integer greater than or equal to the smaller number, but only less than the larger number. In other words, it will never return three, just one or two. It should look like this:

switch (RandomIncident.Next(1, 4))

See here: http://msdn.microsoft.com/en-us/library/2dx6wyd4.aspx
Reply With Quote
  #2  
Old 05-17-2011, 06:24 AM
Ataros Ataros is offline
Approved Member
 
Join Date: Jun 2010
Location: USSR
Posts: 2,439
Default

Quote:
Originally Posted by TheEnlightenedFlorist View Post
It should look like this:

switch (RandomIncident.Next(1, 4))

See here: http://msdn.microsoft.com/en-us/library/2dx6wyd4.aspx
Thanks, changed this. Should there be a space between the figures or does not matter?

I am trying to run this script with reduced delays for testing purposes and it does not load any submission or prints any message at all.
Please try to run it if you have time to see. Mission is attached.



Code:
// v.1_17_05. script by oreva, zaltys, small_bee

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

public class Mission : AMission
{
   
 
// loading sub-missions
public override void OnTickGame()
{
    
    if (Time.tickCounter() % 1800 == 1000) // 54000=30 min repeat. 12600=7 min delay. 
  {
        // randomly selects 1 of several submissions

        Random RandomIncident = new Random();

        switch (RandomIncident.Next(1,4))
        {
            case 1:
                GamePlay.gpPostMissionLoad("missions/Multi/Dogfight/BoF1/BoF1_air01.mis");
                GamePlay.gpHUDLogCenter("mission 1 objectives loaded...");

                double initTime = 0.0;
                Timeout(initTime += 600, () =>
                {
                    GamePlay.gpHUDLogCenter("Attention! Enemy activity is expected at E3!");
                });
                Timeout(initTime += 600, () =>
                {
                    GamePlay.gpHUDLogCenter("Attention! Help is needed at E3/D4!");
                });
            break;
            case 2:
                GamePlay.gpPostMissionLoad("missions/Multi/Dogfight/BoF1/BoF1_sea01.mis");
                GamePlay.gpHUDLogCenter("mission 2 objectives loaded..."); 

                double initTime = 0.0;
                Timeout(initTime += 500, () =>
                {
                    GamePlay.gpHUDLogCenter("Attention! Cover your shipping at C4!");
                });
            
                Timeout(initTime += 300, () =>
                {
                    GamePlay.gpHUDLogCenter("Attention! Ships are under attack at C4!");
                });
            break;
            case 3:
                GamePlay.gpPostMissionLoad("missions/Multi/Dogfight/BoF1/BoF1_air02.mis");
                GamePlay.gpHUDLogCenter("mission 3 objectives loaded...");

                double initTime = 0.0;
                Timeout(initTime += 600, () =>
                {
                    GamePlay.gpHUDLogCenter("Attention! Enemy activity is expected at E2!");
                });
                Timeout(initTime += 300, () =>
                {
                    GamePlay.gpHUDLogCenter("Attention! All airgroups please proceed to E2/D3!");
                });
            break;
        }
    }

    ///////////////////////

    //loads small submissions w/o messages
    
     if (Time.tickCounter() % 216000 == 108000) // 216000=120 min repeat. 108000=60 min delay. 
     {
         GamePlay.gpPostMissionLoad("missions/Multi/Dogfight/BoF1/BoF1_small01.mis");
     }

     if (Time.tickCounter() % 216000 == 215999) // 216000=120 min repeat. 215999=120 min delay. 
     {
         GamePlay.gpPostMissionLoad("missions/Multi/Dogfight/BoF1/BoF1_small02.mis");
     }
       
}
////////////////////////////////////////////////////////////////////////////////////////////////////

// destroys aircraft abandoned by a player.
    private bool isAiControlledPlane (AiAircraft aircraft) 
    {
		if (aircraft == null) 
        { 
			return false;
		}

		Player [] players = GamePlay.gpRemotePlayers ();
		foreach (Player p in players) 
        {    
			if (p != null && (p.Place () is AiAircraft) && (p.Place () as AiAircraft) == aircraft)
            { 
				return false;
			}
		}

		return true;
	}

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

	private void explodeFuelTank (AiAircraft aircraft) 
    {
		if (aircraft != null) 
        { 
			aircraft.hitNamed (part.NamedDamageTypes.FuelTank0Exploded);
		}
	}

	private void destroyAiControlledPlane (AiAircraft aircraft) {
		if (isAiControlledPlane (aircraft)) {
			destroyPlane (aircraft);
		}
	}

	private void damageAiControlledPlane (AiActor actor) {
		if (actor == null || !(actor is AiAircraft)) { 
			return;
		}

		AiAircraft aircraft = (actor as AiAircraft);

		if (!isAiControlledPlane (aircraft)) {
			return;
		}

		if (aircraft == null) { 
			return;
		}

		aircraft.hitNamed (part.NamedDamageTypes.ControlsElevatorDisabled);
		aircraft.hitNamed (part.NamedDamageTypes.ControlsAileronsDisabled);
		aircraft.hitNamed (part.NamedDamageTypes.ControlsRudderDisabled);
		aircraft.hitNamed (part.NamedDamageTypes.FuelPumpFailure);

        int iNumOfEngines = (aircraft.Group() as AiAirGroup).aircraftEnginesNum();
        for (int i = 0; i < iNumOfEngines; i++)
        {
            aircraft.hitNamed((part.NamedDamageTypes)Enum.Parse(typeof(part.NamedDamageTypes), "Eng" + i.ToString() + "TotalFailure"));
        }

        /***Timeout (240, () =>
                {explodeFuelTank (aircraft);}
            );
         * ***/

        Timeout (300, () =>
				{destroyPlane (aircraft);}
			);
	}

    //////////////////////////////////////////

	public override void OnPlaceLeave (Player player, AiActor actor, int placeIndex) 
    {
		base.OnPlaceLeave (player, actor, placeIndex);
		Timeout (1, () =>
				{damageAiControlledPlane (actor);}
			);
	}

	public override void OnAircraftCrashLanded (int missionNumber, string shortName, AiAircraft aircraft) 
    {
		base.OnAircraftCrashLanded (missionNumber, shortName, aircraft);
		Timeout (300, () =>
            { destroyPlane(aircraft); }
			);
	}
    public override void OnAircraftLanded (int missionNumber, string shortName, AiAircraft aircraft) 
    {
        base.OnAircraftLanded(missionNumber, shortName, aircraft);
        Timeout(300, () =>
            { destroyPlane(aircraft); }
            );
    }
    
    
//////////////////////////////////////////////////////////////////////////////////////////////////

    //Listen to events of every mission
    public override void Init(maddox.game.ABattle battle, int missionNumber)
    {
        base.Init(battle, missionNumber);
        MissionNumberListener = -1; //Listen to events of every mission
    }

 //////////////////////////////////////////////////////////////////////////////////////////////////

    //Ground objects (except AA Guns) will die after 55 min when counted from their birth

    public override void OnActorCreated(int missionNumber, string shortName, AiActor actor)
    {
        base.OnActorCreated(missionNumber, shortName, actor);
        //Ground objects (except AA Guns) will die after 55 min when counted from their birth
        if (actor is AiGroundActor)
            if ((actor as AiGroundActor).Type() != maddox.game.world.AiGroundActorType.AAGun)
                Timeout(3300, () =>
                {
                    if (actor != null)
                    { (actor as AiGroundActor).Destroy(); }
                }
                        );
    }

    /****
    //Ground objects will die after 55 min when counted from their birth
    
    public override void OnActorCreated(int missionNumber, string shortName, AiActor actor)
    {
        base.OnActorCreated(missionNumber, shortName, actor);

        //Ground objects will die after 55 min when counted from their birth
        if (actor is AiGroundActor)
            Timeout(3300, () =>
            {
                if (actor != null)
                { (actor as AiGroundActor).Destroy(); }
            }
                    );
    }
    ****/
}
Attached Files
File Type: zip BoF1.zip (17.4 KB, 11 views)
Reply With Quote
  #3  
Old 05-17-2011, 09:54 AM
TheEnlightenedFlorist TheEnlightenedFlorist is offline
Approved Member
 
Join Date: May 2011
Location: SLC, Utah, USA
Posts: 143
Default

Quote:
Originally Posted by Ataros View Post
Thanks, changed this. Should there be a space between the figures or does not matter?

I am trying to run this script with reduced delays for testing purposes and it does not load any submission or prints any message at all.
Please try to run it if you have time to see. Mission is attached.
The space does not matter. "Whitespace is ignored", as they say.

I'm not at my desktop so I can't run your mission, but I can't see why that code wouldn't work.
Reply With Quote
  #4  
Old 05-17-2011, 12:51 PM
FG28_Kodiak FG28_Kodiak is offline
Approved Member
 
Join Date: Dec 2009
Location: Swabia->Bavaria->Germany
Posts: 884
Default

@Ataros

Code:
        switch (RandomIncident.Next(1,4))
        {
            case 1:
                GamePlay.gpPostMissionLoad("missions/Multi/Dogfight/BoF1/BoF1_air01.mis");
                GamePlay.gpHUDLogCenter("mission 1 objectives loaded...");

                double initTime = 0.0;
                Timeout(initTime += 600, () =>
                {
                    GamePlay.gpHUDLogCenter("Attention! Enemy activity is expected at E3!");
                });
                Timeout(initTime += 600, () =>
                {
                    GamePlay.gpHUDLogCenter("Attention! Help is needed at E3/D4!");
                });
            break;
            case 2:
                GamePlay.gpPostMissionLoad("missions/Multi/Dogfight/BoF1/BoF1_sea01.mis");
                GamePlay.gpHUDLogCenter("mission 2 objectives loaded..."); 

                double initTime = 0.0;
                Timeout(initTime += 500, () =>
                {
                    GamePlay.gpHUDLogCenter("Attention! Cover your shipping at C4!");
                });
            
                Timeout(initTime += 300, () =>
                {
                    GamePlay.gpHUDLogCenter("Attention! Ships are under attack at C4!");
                });
            break;
            case 3:
                GamePlay.gpPostMissionLoad("missions/Multi/Dogfight/BoF1/BoF1_air02.mis");
                GamePlay.gpHUDLogCenter("mission 3 objectives loaded...");

                double initTime = 0.0;
                Timeout(initTime += 600, () =>
                {
                    GamePlay.gpHUDLogCenter("Attention! Enemy activity is expected at E2!");
                });
                Timeout(initTime += 300, () =>
                {
                    GamePlay.gpHUDLogCenter("Attention! All airgroups please proceed to E2/D3!");
                });
            break;
Made the declaration double initTime = 0.0 before the switch case and only onetimes. Then your script should work.

It should look like:
Code:
public override void OnTickGame()
{

   double initTime;    

    if (Time.tickCounter() % 1800 == 1000) // 54000=30 min repeat. 12600=7 min delay. 
  {
        // randomly selects 1 of several submissions

        Random RandomIncident = new Random();
        
        switch (RandomIncident.Next(1,4))
        {
            case 1:
                GamePlay.gpPostMissionLoad("missions/Multi/Dogfight/BoF1/BoF1_air01.mis");
                GamePlay.gpHUDLogCenter("mission 1 objectives loaded...");

               initTime = 0.0;
                Timeout(initTime += 600, () =>
                {
                    GamePlay.gpHUDLogCenter("Attention! Enemy activity is expected at E3!");
                });
                Timeout(initTime += 600, () =>
                {
                    GamePlay.gpHUDLogCenter("Attention! Help is needed at E3/D4!");
                });
            break;
            case 2:
                GamePlay.gpPostMissionLoad("missions/Multi/Dogfight/BoF1/BoF1_sea01.mis");
                GamePlay.gpHUDLogCenter("mission 2 objectives loaded..."); 

               initTime = 0.0;
                Timeout(initTime += 500, () =>
                {
                    GamePlay.gpHUDLogCenter("Attention! Cover your shipping at C4!");
                });
            
                Timeout(initTime += 300, () =>
                {
                    GamePlay.gpHUDLogCenter("Attention! Ships are under attack at C4!");
                });
            break;
            case 3:
                GamePlay.gpPostMissionLoad("missions/Multi/Dogfight/BoF1/BoF1_air02.mis");
                GamePlay.gpHUDLogCenter("mission 3 objectives loaded...");

                initTime = 0.0;
                Timeout(initTime += 600, () =>
                {
                    GamePlay.gpHUDLogCenter("Attention! Enemy activity is expected at E2!");
                });
                Timeout(initTime += 300, () =>
                {
                    GamePlay.gpHUDLogCenter("Attention! All airgroups please proceed to E2/D3!");
                });
            break;
        }
    }

Last edited by FG28_Kodiak; 05-17-2011 at 01:03 PM.
Reply With Quote
  #5  
Old 05-17-2011, 01:50 PM
Ataros Ataros is offline
Approved Member
 
Join Date: Jun 2010
Location: USSR
Posts: 2,439
Default

Quote:
Originally Posted by FG28_Kodiak View Post
Made the declaration double initTime = 0.0 before the switch case and only onetimes. Then your script should work.

It should look like:
Thank you very much!! Works great!

Would it be hard to exclude the last mission flown from random selection for the next round? As I am getting case #3 like 4 times in a row, than case 2 2 times. It can become boring for players. (I am planning to add more various missions to it in the future.)

We will test the script on Repka 2 for some time and then move it to Repka 1.

Welcome to our servers!
Reply With Quote
  #6  
Old 05-17-2011, 03:39 PM
FG28_Kodiak FG28_Kodiak is offline
Approved Member
 
Join Date: Dec 2009
Location: Swabia->Bavaria->Germany
Posts: 884
Default

It's possible to avoid repeating of last mission:

Code:
public class Mission : AMission
{
    int LastMissionLoaded=0;
 
    // loading sub-missions
    public override void OnTickGame()
    {
    
        if (Time.tickCounter() % 1800 == 1000) // 54000=30 min repeat. 12600=7 min delay. 
        {
            // randomly selects 1 of several submissions

	    Random RandomIncident = new Random();
	    int CurrentMissionSelected;

	    do
            {
                 CurrentMissionSelected = RandomIncident.Next(1,4);
            }		
	    while (LastMissionLoaded == CurrentMissionSelected);
				
	    LastMissionLoaded = CurrentMissionSelected;

            switch (CurrentMissionSelected)
            {

Last edited by FG28_Kodiak; 05-17-2011 at 03:44 PM.
Reply With Quote
  #7  
Old 05-17-2011, 04:47 PM
bigchump's Avatar
bigchump bigchump is offline
Approved Member
 
Join Date: Jan 2008
Location: Oregon, USA
Posts: 29
Default

I use C# everyday and I can't imagine using any of the .NET stuff to code a flight sim.
Reply With Quote
  #8  
Old 05-17-2011, 06:04 PM
Ataros Ataros is offline
Approved Member
 
Join Date: Jun 2010
Location: USSR
Posts: 2,439
Default

Quote:
Originally Posted by FG28_Kodiak View Post
It's possible to avoid repeating of last mission:
Thank you so much again! I love this beautiful C# language. I had only some very limited acquaintance with Basiс long time ago (

Tested offline and now put up on Repka 2 for online test. Randomization will give us possibility to add more missions and overlap them randomly in time to make the airwar environment absolutely unpredictable.

I consider Repka server as a sandbox or a demo for the game-engine possibilities hoping that more people from community would be involved in mission-building and even in creation of online wars like ADW, Bellum or AFW as soon as they see how far the engine allows them to go compared to limited IL-2 COOPs or Dogfights. Unfortunately I do not have enough knowledge in C# myself.

Your help is highly appreciated.

Complete code as of today for Repka 2.
Code:
// v.1_17_05. script by FG28_Kodiak, ZaltysZ, oreva, small_bee

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

public class Mission : AMission
{

    int LastMissionLoaded = 0;

    double initTime;

    // loading sub-missions
    public override void OnTickGame()
    {
        if (Time.tickCounter() % 45000 == 9000) // 45000=25 min repeat. 9000=5 min delay. 
        {
            // randomly selects 1 of several submissions excluding the recent one

            Random RandomIncident = new Random();
            int CurrentMissionSelected;

            do
                {
                CurrentMissionSelected = RandomIncident.Next(1, 4);
                }
            while (LastMissionLoaded == CurrentMissionSelected);

            LastMissionLoaded = CurrentMissionSelected;

            switch (CurrentMissionSelected)

            {
            case 1:
                GamePlay.gpPostMissionLoad("missions/Multi/Dogfight/BoF1/BoF1_air01.mis");
                GamePlay.gpHUDLogCenter("mission objectives updated.");
                    //600
                initTime = 0.0;
                Timeout(initTime += 600, () =>
                {
                    GamePlay.gpHUDLogCenter("Attention! Enemy activity is expected at E3!");
                });
                Timeout(initTime += 600, () =>
                {
                    GamePlay.gpHUDLogCenter("Attention! Help is needed at E3/D4!");
                });
                break;
            case 2:
                GamePlay.gpPostMissionLoad("missions/Multi/Dogfight/BoF1/BoF1_sea01.mis");
                GamePlay.gpHUDLogCenter("mission objectives updated..");
                    //500
                initTime = 0.0;
                Timeout(initTime += 500, () =>
                {
                    GamePlay.gpHUDLogCenter("Attention! Cover your shipping at C4!");
                });

                Timeout(initTime += 300, () =>
                {
                    GamePlay.gpHUDLogCenter("Attention! Ships are under attack at C4!");
                });
                break;
            case 3:
                GamePlay.gpPostMissionLoad("missions/Multi/Dogfight/BoF1/BoF1_air02.mis");
                GamePlay.gpHUDLogCenter("mission objectives updated...");
                    //600
                initTime = 0.0;
                Timeout(initTime += 600, () =>
                {
                    GamePlay.gpHUDLogCenter("Attention! Enemy activity is expected at E2!");
                });
                Timeout(initTime += 300, () =>
                {
                    GamePlay.gpHUDLogCenter("Attention! All airgroups please proceed to E2/D3!");
                });
                break;
        }
    }

    ///////////////////////

    //loads small submissions w/o messages
    
     if (Time.tickCounter() % 216000 == 108000) // 216000=120 min repeat. 108000=60 min delay. 
     {
         GamePlay.gpPostMissionLoad("missions/Multi/Dogfight/BoF1/BoF1_small01.mis");
     }

     if (Time.tickCounter() % 216000 == 215999) // 216000=120 min repeat. 215999=120 min delay. 
     {
         GamePlay.gpPostMissionLoad("missions/Multi/Dogfight/BoF1/BoF1_small02.mis");
     }
       
}
////////////////////////////////////////////////////////////////////////////////////////////////////

// destroys aircraft abandoned by a player.
    private bool isAiControlledPlane (AiAircraft aircraft) 
    {
		if (aircraft == null) 
        { 
			return false;
		}

		Player [] players = GamePlay.gpRemotePlayers ();
		foreach (Player p in players) 
        {    
			if (p != null && (p.Place () is AiAircraft) && (p.Place () as AiAircraft) == aircraft)
            { 
				return false;
			}
		}

		return true;
	}

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

	private void explodeFuelTank (AiAircraft aircraft) 
    {
		if (aircraft != null) 
        { 
			aircraft.hitNamed (part.NamedDamageTypes.FuelTank0Exploded);
		}
	}

	private void destroyAiControlledPlane (AiAircraft aircraft) {
		if (isAiControlledPlane (aircraft)) {
			destroyPlane (aircraft);
		}
	}

	private void damageAiControlledPlane (AiActor actor) {
		if (actor == null || !(actor is AiAircraft)) { 
			return;
		}

		AiAircraft aircraft = (actor as AiAircraft);

		if (!isAiControlledPlane (aircraft)) {
			return;
		}

		if (aircraft == null) { 
			return;
		}

		aircraft.hitNamed (part.NamedDamageTypes.ControlsElevatorDisabled);
		aircraft.hitNamed (part.NamedDamageTypes.ControlsAileronsDisabled);
		aircraft.hitNamed (part.NamedDamageTypes.ControlsRudderDisabled);
		aircraft.hitNamed (part.NamedDamageTypes.FuelPumpFailure);

        int iNumOfEngines = (aircraft.Group() as AiAirGroup).aircraftEnginesNum();
        for (int i = 0; i < iNumOfEngines; i++)
        {
            aircraft.hitNamed((part.NamedDamageTypes)Enum.Parse(typeof(part.NamedDamageTypes), "Eng" + i.ToString() + "TotalFailure"));
        }

        /***Timeout (240, () =>
                {explodeFuelTank (aircraft);}
            );
         * ***/

        Timeout (300, () =>
				{destroyPlane (aircraft);}
			);
	}

    //////////////////////////////////////////

	public override void OnPlaceLeave (Player player, AiActor actor, int placeIndex) 
    {
		base.OnPlaceLeave (player, actor, placeIndex);
		Timeout (1, () =>
				{damageAiControlledPlane (actor);}
			);
	}

	public override void OnAircraftCrashLanded (int missionNumber, string shortName, AiAircraft aircraft) 
    {
		base.OnAircraftCrashLanded (missionNumber, shortName, aircraft);
		Timeout (300, () =>
            { destroyPlane(aircraft); }
			);
	}
    public override void OnAircraftLanded (int missionNumber, string shortName, AiAircraft aircraft) 
    {
        base.OnAircraftLanded(missionNumber, shortName, aircraft);
        Timeout(300, () =>
            { destroyPlane(aircraft); }
            );
    }
    
    
//////////////////////////////////////////////////////////////////////////////////////////////////

    //Listen to events of every mission
    public override void Init(maddox.game.ABattle battle, int missionNumber)
    {
        base.Init(battle, missionNumber);
        MissionNumberListener = -1; //Listen to events of every mission
    }

 //////////////////////////////////////////////////////////////////////////////////////////////////

    //Ground objects (except AA Guns) will die after 55 min when counted from their birth

    public override void OnActorCreated(int missionNumber, string shortName, AiActor actor)
    {
        base.OnActorCreated(missionNumber, shortName, actor);
        //Ground objects (except AA Guns) will die after 55 min when counted from their birth
        if (actor is AiGroundActor)
            if ((actor as AiGroundActor).Type() != maddox.game.world.AiGroundActorType.AAGun)
                Timeout(3300, () =>
                {
                    if (actor != null)
                    { (actor as AiGroundActor).Destroy(); }
                }
                        );
    }

    /****
    //Ground objects will die after 55 min when counted from their birth
    
    public override void OnActorCreated(int missionNumber, string shortName, AiActor actor)
    {
        base.OnActorCreated(missionNumber, shortName, actor);

        //Ground objects will die after 55 min when counted from their birth
        if (actor is AiGroundActor)
            Timeout(3300, () =>
            {
                if (actor != null)
                { (actor as AiGroundActor).Destroy(); }
            }
                    );
    }
    ****/
}
Reply With Quote
Reply

Thread Tools
Display Modes

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

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

Forum Jump


All times are GMT. The time now is 10:31 AM.


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