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
  #11  
Old 05-18-2012, 12:09 PM
Smokeynz Smokeynz is offline
Approved Member
 
Join Date: Apr 2011
Posts: 106
Default

Moggel, I can sort that code out, Ill do it over weekend.
I have a script in development where I read data like this from mis files all over the place, a simple mod to a section I should be able to gather what you want.(doesn't help me though) But will help you.

Ataros, I have includded a modified version of the missionloader(because it works well) into my current script, going to post it soon once I sort out some stuff...stuff is of course never finished
Reply With Quote
  #12  
Old 05-19-2012, 05:12 AM
Smokeynz Smokeynz is offline
Approved Member
 
Join Date: Apr 2011
Posts: 106
Default

Ok here is a mission timer (Attached)

Reports Mission design TIME value by reading mis data directly.
Reports Ingame run timer, Mins, Seconds,Ticks
Reports Time from Mission TIME + run time(in decimal mins)

Note Config in system folder,
Config:
"timeIO", "ON"
"timevalue", "15"

set "timeIO", "ON" = runs timer,
set "timeIO", "OFF" = turns off timer,
set "timevalue", "15" = seconds between count and screen reporting.

Rerun mission to activate new time values

note download the attached Mistimer.zip, as it contains correct setup
Note: drop MisTimer into missions folder and run from there.

here is the script for those interested,

Please report bugs if found. seems to work though.
enjoy.

Code:
/**MisTimer.cs**/
//
//C# script for CLOD missions,
//Features:
//Configlist: for easy setup "ON" runs timer, "OFF" turns off timer, timevalue = seconds between count and screen reporting.
//
//By Smokeynz
//
//lastmod 19/5/2012
//Dedicated server compatible

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

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

    #region Mission paths 
  
    /*=========================================*/

    static string userdocpath = Environment.GetFolderPath(Environment.SpecialFolder.Personal);

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

    // the following 2 items are for main mission folder path and mis name, edit for preference
    static string MISname = "MisTimer.mis"; //alter this to your mission name
    static string FILEname = "MisTimer"; //alter this to your mission folder name  

    /*=========================================*/  
    
    static string filepackpath = userdocpath + @"\1C SoftClub\il-2 sturmovik cliffs of dover\missions\"; //path to mission file pack
    static string mainmissionpath = filepackpath + FILEname + @"\"; // main mission
    //configs
    static string syspath = mainmissionpath + @"system\"; // data path for system config
    static string configfile = syspath + "config.txt";
    
    //loading mission path data 
    static string timefile = mainmissionpath + MISname;
   
    
    /*=========================================*/

    #endregion   

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

    #region Declarations, ints, doubles, bools

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

    //Msgs To
    private const int All = -1;
    private const int Allies = 1;
    private const int Axis = 2;

    bool timeIO;// = true; //time indicator switch on/off
    double timevalue;
    double timeindicator;
    double MisHour;
    double MisMin;

    //config file indexing
    int idxIO;
    int idxTV;
    
    // Internal file creation
    public int idxlist;

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

    #endregion 
 
    /*=========================================*/

    #region Mission Parse & Class

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

    // mission config settings(Allows external configuration)
    List<Config> ConfigList = new List<Config>();
    internal class Config 
    {
        public string ConfigName { get; set; }//item name
        public string ConfigValue { get; set; }//item value        
        public Config(string configName, string configValue)
        {
            this.ConfigName = configName;
            this.ConfigValue = configValue;
        }
    }
    public void ParseConfigFile(string confile)
    {
        if (!File.Exists(confile))
        {
            GamePlay.gpLogServer(null, "File {0} not found!", new object[] { confile });
            return;
        }

        using (StreamReader reader = new StreamReader(confile))
        {
            string conline;
            int conlineNr = 0;
            while ((conline = reader.ReadLine()) != null)
            {
                conlineNr++;
                if (conline != "")
                {
                    string[] tmpconPart;
                    conline = conline.TrimStart('"'); // remove first "
                    conline = conline.TrimEnd('"');  // remove last "
                    tmpconPart = conline.Split(new string[] { "\", \"", "\",\"" }, StringSplitOptions.None); // split string on ", " or ","
                    if (tmpconPart.Length < 2)
                    {
                        GamePlay.gpLogServer(null, "Error reading configlist file: {0} : {1}", new object[] { conlineNr, conline });
                    }
                    else
                    {
                        if (tmpconPart[0].Equals("null"))
                            tmpconPart[0] = null;
                        if (tmpconPart[1].Equals("null"))
                            tmpconPart[1] = null;
                        ConfigList.Add(new Config(tmpconPart[0], tmpconPart[1]));
                    }
                }
            }
        }       
        idxIO = ConfigList.FindIndex(r => r.ConfigName.Equals("timeIO"));
        idxTV = ConfigList.FindIndex(s => s.ConfigName.Equals("timevalue"));
        double.TryParse(ConfigList[idxTV].ConfigValue, out timevalue);         
    }    
  
   public void ParseTimeDataFile(string Tfile)
   { 
       if (!File.Exists(Tfile))
       {
           GamePlay.gpLogServer(null, "File {0} not found!", new object[] { Tfile });
           return;
       }

       using (StreamReader reader = new StreamReader(Tfile))
       {
            
           string line;
           int lineNr = 0;
           while ((line = reader.ReadLine()) != null)
           {
               lineNr++;
               if (line != "")
               {
                   if (line.Contains("TIME"))
                   {
                       string[] tmptime = line.Split(new string[] { " " }, StringSplitOptions.None); // split string                        
                       if (tmptime.Length < 3)
                       {
                           GamePlay.gpLogServer(null, "Error reading Time object line : {0} : {1}", new object[] { lineNr, line });
                       }
                       else
                       {
                           GamePlay.gpLogServer(null, "Time Line Split 0:{0} 1:{1} 2:{2} 3:{3}", new object[] { tmptime[0], tmptime[1], tmptime[2], tmptime[3] });//test reading
                           string[] tmptime2 = tmptime[3].Split(new string[] { "." }, StringSplitOptions.None); // split string 
                           if (tmptime2.Length < 2)
                           {
                               double.TryParse(tmptime2[3], out MisHour);
                           }
                           else
                           {
                               GamePlay.gpLogServer(null, "Time Line Split 0:{0} 1:{1}", new object[] { tmptime2[0], tmptime2[1] });
                               double.TryParse(tmptime2[0], out MisHour);
                               double.TryParse(tmptime2[1], out MisMin);
                               if (MisMin < 10) { MisMin = MisMin / 10; }
                               if (MisMin > 9) { MisMin = MisMin / 100; }                                        
                           }                          
                       }
                   }
               }
           }
       }
   }
       
   /*=========================================*/

    #endregion

   /*=========================================*/   
    
    #region Main mission operation

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

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

        ParseConfigFile(configfile);
        ParseTimeDataFile(timefile);        
    }
    
    public override void OnTickGame()
    {
        base.OnTickGame();       

        // Time.current() in seconds from Battle Start     
        timeIO = (ConfigList[idxIO].ConfigValue == "ON" ? true : false);        
        if (timeIO == true)
        {
            if (Time.current() >= timeindicator)
            {
                double MisTime = MisHour + MisMin;
                ScreenMsg(-1, "MisStart:: " + MisTime + " decimalhours");
                Timeout(2.0, () => { ScreenMsg(-1, "Elapsed Time:Min:" + timeindicator / 60 + " Secs:" + timeindicator + " Ticks:" + timeindicator * 30); }); 
                MisTime = Math.Round((MisHour + ((MisMin*60) + (timeindicator / 60)) / 60), 2);
                Timeout(4.0, () => { ScreenMsg(-1, "MisTime:: " + MisTime + " decimalhours"); });
            }                
        }

        if (Time.current() >= timeindicator)
        {            
            timeindicator = timeindicator + timevalue;            
        } 
    }

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

    #endregion 

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

    #region ScreenMsg screen message

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

        if (army == -1)
        {
            GamePlay.gpHUDLogCenter(null, msg, args);
            GamePlay.gpLogServer(null, msg, args);
        }
        else if (Consignees.Exists(item => item.Army() == army))
        {
            GamePlay.gpHUDLogCenter(Consignees.FindAll(item => item.Army() == army).ToArray(), msg, args);
            GamePlay.gpLogServer(Consignees.FindAll(item => item.Army() == army).ToArray(), msg, args);
        }
    }
/*
    private void sendChatMessage(int army, string msg, params object[] args)
    {        
        List<Player> Consignees = new List<Player>();
        if (GamePlay.gpPlayer() != null)
            Consignees.Add(GamePlay.gpPlayer());
        if (GamePlay.gpRemotePlayers() != null)
            Consignees.AddRange(GamePlay.gpRemotePlayers());

        if (army == -1)
            GamePlay.gpLogServer(null, msg, args);
        else if (Consignees.Exists(item => item.Army() == army))
            GamePlay.gpLogServer(Consignees.FindAll(item => item.Army() == army).ToArray(), msg, args);
    }
*/
    /*=========================================*/

    #endregion

    /*=========================================*/    
}
//note the last bracket wraps Amission
Attached Files
File Type: zip MisTimer.zip (4.5 KB, 2 views)
Reply With Quote
  #13  
Old 05-21-2012, 01:58 PM
moggel moggel is offline
Approved Member
 
Join Date: Mar 2011
Posts: 70
Default

Quote:
Originally Posted by Ataros View Post
C# should be able to read file names from a given folder I think but I may be wrong.

There was a mission posted here called Mission Loader that can read mission filenames. Banks' COOP lobby can do this too IIRC.
Yes, reading files from a specified folder is quite easy. Just call System.IO.Directory.GetFiles(<user's IL-2 missions folder>, "*.mis") and you'll get a nice array of strings representing all missions found.

But since I don't know which file is the one containing the current main mission I don't have much use for it. Hard coding the name of the mission into every mission file is not the way I want it to work since that would force the server operator to open up the mission .cs files and fiddle with its content. That, in turn, requires coding skills and presents a big risk he/she will corrupt the mission.

Instead, I'm aiming for a solution where all "extensions" (like "Fighter Command") can be installed from installation packages using a graphical installer, just like we're used to install normal desktop applications.

I wrote the coding framework for this (and the installer) a few week back and "Fighter Command" will be the first extension for it followed by "Live Map" (which automatically populates the landscape with traffic, livestock etc as the player flies over the map). The "framework", which I call "IL2X" right now seems to be stable and allows the coder to write code like he/she is used to, splitting up all code into libraries which can be reused and distributes automatically. Also, you can use normal runtime debugging in Visual Studio, setting up breakpoints or tracepoints to figure out how the sim works and for hunting down bugs in the code if need be. It works fine right now but needs more testing before I present it to the forums (hopefully within a week or two )

So (sorry for the digression), what I'm really looking for here would be something like: "myMission.GamePlay.gpCurentFileName()" or something similar to it. I have not been able to find it though...
__________________
Core i7 3930K @ 4.8GHz; 16Gb DDR3 (Vengeance); nVidia GTX580; OS disk: 150Gb 10000rpm; SIM disk: 300Gb 10000rpm; Windows 7 x64 Ultimate
Reply With Quote
  #14  
Old 05-21-2012, 04:47 PM
FG28_Kodiak FG28_Kodiak is offline
Approved Member
 
Join Date: Dec 2009
Location: Swabia->Bavaria->Germany
Posts: 884
Default

There is no way to get the MissionfileName from a script (i am looking for it too), via CloDo - API
It would be possible (i think) if we can create Addins for Multiplayer, to get the current directory.
IGame:
gameInterface.ToFileSystemPath(..)
Reply With Quote
  #15  
Old 05-21-2012, 05:02 PM
moggel moggel is offline
Approved Member
 
Join Date: Mar 2011
Posts: 70
Default

Quote:
Originally Posted by FG28_Kodiak View Post
There is no way to get the MissionfileName from a script (i am looking for it too), via CloDo - API
It would be possible (i think) if we can create Addins for Multiplayer, to get the current directory.
IGame:
gameInterface.ToFileSystemPath(..)
What is CloDo - API? Linky?
__________________
Core i7 3930K @ 4.8GHz; 16Gb DDR3 (Vengeance); nVidia GTX580; OS disk: 150Gb 10000rpm; SIM disk: 300Gb 10000rpm; Windows 7 x64 Ultimate
Reply With Quote
  #16  
Old 05-21-2012, 05:10 PM
FG28_Kodiak FG28_Kodiak is offline
Approved Member
 
Join Date: Dec 2009
Location: Swabia->Bavaria->Germany
Posts: 884
Default

I call the managed Dlls CloDo-API. Cliffs of Dover Application Programming Interface
Reply With Quote
  #17  
Old 05-21-2012, 05:42 PM
moggel moggel is offline
Approved Member
 
Join Date: Mar 2011
Posts: 70
Default

Quote:
Originally Posted by FG28_Kodiak View Post
I call the managed Dlls CloDo-API. Cliffs of Dover Application Programming Interface
Silly me!
__________________
Core i7 3930K @ 4.8GHz; 16Gb DDR3 (Vengeance); nVidia GTX580; OS disk: 150Gb 10000rpm; SIM disk: 300Gb 10000rpm; Windows 7 x64 Ultimate
Reply With Quote
  #18  
Old 05-21-2012, 06:08 PM
moggel moggel is offline
Approved Member
 
Join Date: Mar 2011
Posts: 70
Default

Quote:
Originally Posted by FG28_Kodiak View Post
There is no way to get the MissionfileName from a script (i am looking for it too), via CloDo - API
It would be possible (i think) if we can create Addins for Multiplayer, to get the current directory.
IGame:
gameInterface.ToFileSystemPath(..)
Sounds interesting. Where can I obtain IGame objects? I've found the type and apparently it inherits from IGamePlay. If I set a breakpoint in OnTickGame and cast it to IGame I do get an object but the IGame.BattleScriptFileName property is always null. I performed the test in SP mode. I then tried doing the same from OnBattleStarted() and OnBattleInit() but those never gets called.

I then performed the exact same test running a server thinking that maybe a "battle" is what gets started when you type "battle start" in the server console but ... no.

When are those methods called anyway?

By the way: I think we should set up a scripting WIKI...
__________________
Core i7 3930K @ 4.8GHz; 16Gb DDR3 (Vengeance); nVidia GTX580; OS disk: 150Gb 10000rpm; SIM disk: 300Gb 10000rpm; Windows 7 x64 Ultimate
Reply With Quote
  #19  
Old 05-21-2012, 06:54 PM
Ataros Ataros is offline
Approved Member
 
Join Date: Jun 2010
Location: USSR
Posts: 2,439
Default

If a server owner starts his mission via script (TAB-4) or a Server Commander, the script or the commander will 'know' which file the server owner started I guess.
Reply With Quote
  #20  
Old 05-21-2012, 07:02 PM
FG28_Kodiak FG28_Kodiak is offline
Approved Member
 
Join Date: Dec 2009
Location: Swabia->Bavaria->Germany
Posts: 884
Default

Quote:
Originally Posted by moggel View Post
When are those methods called anyway?
Thats the problem in the GUI (gamePages, take a look at the tstcampaign). So wie need a addin to get access to it, or the devs creates a methods so it would be easier for us.
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:36 PM.


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