Hi, first of all the "GamePlay.gpLoadSectionFile(fileName);" doesn't load the mission file into the game engine. It only creates a ISectionFile object that allows to read/write a mission file with the script and do some changes (like you are already do).
To post load a mission file into the running battle you need to call "GamePlay.gpPostMissionLoad(fileName);"
However I don't think it's possible to change the MAIN parameters by a mission file that is post loaded into a running battle.
Anyhow your script should look something like this:
Code:
using System;
using System.Collections.Generic;
using maddox.game;
using maddox.game.world;
using maddox.GP;
using System.Security.Cryptography;
public class Mission : AMission
{
public override void OnBattleInit()
{
RandomiseMission();
}
internal ISectionFile RandomiseMission()
{
//time of day
bool RandomiseTime = true;
int minTime = 6;
int maxTime = 17;
// WeatherIndex
bool RandomiseWeatherIndex = true;
int minWeatherIndex = 0;
int maxWeatherIndex = 1;
// cloud height
bool RandomiseClouds = true;
int minClouds = 1000;
int maxClouds = 2000;
// BreezeActivity
bool RandomiseBreezeActivity = true;
int minBreezeActivity = 0;
int maxBreezeActivity = 3;
// ThermalActivity
bool RandomiseThermalActivity = true;
int minThermalActivity = 0;
int maxThermalActivity = 2;
ISectionFile f = GamePlay.gpCreateSectionFile();
string sect;
string key;
string value;
// time of day
if (RandomiseTime == true)
{
sect = "MAIN";
key = "TIME";
value = NextInt(minTime, maxTime).ToString();
f.add(sect, key, value);
GamePlay.gpHUDLogCenter("Time: " + value); // for testing
}
// WeatherIndex
if (RandomiseWeatherIndex == true)
{
sect = "MAIN";
key = "CloudsHeight";
value = NextInt(minWeatherIndex, maxWeatherIndex).ToString();
f.add(sect, key, value);
}
// clouds
if (RandomiseClouds == true)
{
sect = "MAIN";
key = "CloudsHeight";
value = NextInt(minClouds, maxClouds).ToString();
f.add(sect, key, value);
}
// minBreezeActivity
if (RandomiseBreezeActivity == true)
{
sect = "MAIN";
key = "BreezeActivity";
value = NextInt(minBreezeActivity, maxBreezeActivity).ToString();
f.add(sect, key, value);
}
// ThermalActivity
if (RandomiseThermalActivity == true)
{
sect = "MAIN";
key = "ThermalActivity";
value = NextInt(minThermalActivity, maxThermalActivity).ToString();
f.add(sect, key, value);
}
// This post loads the section file f into the current battle.
// It's also possible to save the section file f first by f.save("filename") and then
// call GamePlay.gpPostMissionLoad("filename"); if you want to save the randomised file
// on your hard disk.
GamePlay.gpPostMissionLoad(f);
return f;
}
private static int NextInt(int min, int max)
{
RNGCryptoServiceProvider rng = new RNGCryptoServiceProvider();
byte[] buffer = new byte[4];
rng.GetBytes(buffer);
int result = BitConverter.ToInt32(buffer, 0);
return new Random(result).Next(min, max);
}
}