Purchased a book called "Introduction (or basic) course to C# programming" by a university professor last Saturday. It is only about 200 pages and makes things way easier.
Below is a sample code I wrote yesterday after just 2 days of reading it. Of cause I was using 2 pieces of code from other people: ZaltysZ and naryv, but the book provided enough understanding to combine them and finetune to my needs. Just 4 weeks ago I thought C# was beyond my comprehension. Now I think the basics of it are easier than basics of the English language. Do not expect developers include such a book into documentation, just go out and buy one.
Code:
string[] activeSector = { "D3", "D4" }; // sectors attacked by ground groups
string[] side = { "хз", "Red", "Blue"}; // army side
int LastMissionLoaded = 0;
double initTime;
string currSide = " ";
string currSector = " ";
int missLoaded = 0; // debugging
public override void Init(maddox.game.ABattle battle, int missionNumber)
{
base.Init(battle, missionNumber);
MissionNumberListener = -1; //Listen to events of every mission
//Planned missions MissionLoader(int offset, int repeat, string mission)
MissionLoader(90, -1, "missions/Multi/Dogfight/BoF1/sub/0_1_gg.mis"); // 10s from main mission start and no repeate every -s
MissionLoader(900, -1, "missions/Multi/Dogfight/BoF1/sub/0_2_gg.mis");
MissionLoader(300, -1, "missions/Multi/Dogfight/BoF1/sub/1_2_gg.mis");
MissionLoader(1200, -1, "missions/Multi/Dogfight/BoF1/sub/1_1_gg.mis");
}
public void MissionLoader(int offset, int repeat, string mission)
{
if (offset > 0)
Timeout(offset, () => { MissionLoader(0, repeat, mission); });
else
{
GamePlay.gpPostMissionLoad(mission);
// debugging
//GamePlay.gpHUDLogCenter( side[j].ToString() + " tanks are attacking sector " + activeSector[i].ToString() + "!");
missLoaded++;
GamePlay.gpHUDLogCenter(String.Format("Mission {0} loaded.", missLoaded));
if (repeat > 300 )
Timeout(repeat, () => { MissionLoader(0, repeat, mission); });
}
}
public override void OnTrigger(int missionNumber, string shortName, bool active)
{
base.OnTrigger(missionNumber, shortName, active);
for (int i = 0; i < activeSector.Length ; i++)
{
for (int j = 1; j < side.Length; j++)
{
string str = i.ToString() + "_" + (j).ToString() + "_gg";
if (str.Equals(shortName)) // checks trigger
{
GamePlay.gpPostMissionLoad("missions\\Multi\\Dogfight\\BoF1\\sub\\" + str + ".mis"); // loads tanks mission
//GamePlay.gpHUDLogCenter(side[j].ToString() + " tanks are attacking sector " + activeSector[i].ToString() + "! ***test***");
currSide = side[j];
currSector = activeSector[i];
repeatGroundMsg(90, currSide, currSector);
//initTime = 0.0;
//Timeout(initTime += 90, () =>
//{
// GamePlay.gpHUDLogCenter(currSide.ToString() + " tanks are attacking sector " + currSector.ToString() + "! ***in cycle***");
// //GamePlay.gpHUDLogCenter(addStr + " tanks are attacking sector " + activeSector[i] + "!");
//});
break;
}
}
}
}
private void repeatGroundMsg(int delay, string currSide, string currSector)
{
initTime = 0.0;
Timeout(initTime += delay, () =>
{
GamePlay.gpHUDLogCenter(currSide.ToString() + " tanks are attacking sector " + currSector.ToString() + "!"); // is .ToString() necessary here??
});
}
upd.
OT, but as I do not want to start a new thread for this. Can Timeout(initTime += 90, () => be used inside a cycle? Does it prevents a cycle from further execution? I had some problems with triggers when Timeout(initTime += 90, () => was inside the onTrigger cycle. However current code is probably not different in essence from having Timeout(initTime += 90, () => inside the cycle but it works somehow ))