using OpenRA.Traits; using OpenRA.FileFormats; using System.IO; using System; using System.Collections.Generic; using System.Reflection; using OpenRA.Mods.RA; using OpenRA; using OpenRA.Widgets; using System.Drawing; namespace SimpleScripts { public class MyScript1 : ScriptingInterface.IScriptMain { int gameTimer; int timer; int count; int wave; int totalWaves; int waveSubTimer; int waveSizeIndex; int totalUnitsPerSubWave; int leftToSpawn; int waveSleep; int waveBetweenEachSubWave; int waveX; int waveY; int waveWidth; int waveHeight; int waveAttackX; int waveAttackY; int[] unitAmount; string[] unitName; int[] waveSize; UseScript scriptEngine; public void RunScript(UseScript scriptEngine) { this.scriptEngine = scriptEngine; } public void Tick(Actor self) { // Check if building are still alive // Actor defBuilding = scriptEngine.world.WorldActor.Trait().Actors["Def1"]; bool dead1 = true; if (defBuilding != null && defBuilding.IsInWorld) { if (defBuilding.Trait() != null) { dead1 = defBuilding.Trait().IsDead; } } int count = scriptEngine.NumberOfActorsForPlayer("Hostile"); if (count <= 0 && timer <= 0 && waveSubTimer <= 0) { scriptEngine.Print("Info", "Wave " + wave.ToString() + " starts in " + waveSleep.ToString() + " seconds."); } // Game keeps running if still alive if (gameTimer > 10) { if (dead1 == false) { if (timer > 0 && count <= 0) { timer = timer - 1; } if (timer <= 0 && count <= 0) { // Spawn wave if (wave < totalWaves) { wave = wave + 1; scriptEngine.Print("Info", "Wave: " + wave); //calculate number of units to spawn leftToSpawn = 0; int i = 0; while (i < waveSize[wave]) { leftToSpawn = leftToSpawn + unitAmount[waveSizeIndex + i]; i = i + 1; } count = leftToSpawn; int temp = 0; int x = waveX; int y = waveY; while (temp < totalUnitsPerSubWave && leftToSpawn > 0) { scriptEngine.CreateUnit(unitName[waveSizeIndex], "Hostile", x, y); Actor unit = scriptEngine.GetActorFromLocation(x, y); scriptEngine.UnitAttackMove(unit, waveAttackX, waveAttackY); //counting temp = temp + 1; leftToSpawn = leftToSpawn - 1; unitAmount[waveSizeIndex] = unitAmount[waveSizeIndex] - 1; if (unitAmount[waveSizeIndex] <= 0) { waveSizeIndex = waveSizeIndex + 1; } //pos x = x + 1; if (x >= waveX + waveWidth) { x = waveX; y = y + 1; } } //increase values timer = waveSleep; waveSubTimer = waveBetweenEachSubWave; } else { // YOU HAVE WON THE GAME!!!! scriptEngine.PlaySound("misnwon1.aud"); scriptEngine.RemoveAllScripts(); leftToSpawn = 0; scriptEngine.PlayerWon("Multi0"); scriptEngine.PlayerWon("Multi1"); scriptEngine.PlayerWon("Multi2"); } } if (leftToSpawn > 0) { waveSubTimer = waveSubTimer - 1; if (waveSubTimer <= 0) { int temp = 0; int x = waveX; int y = waveY; while (temp < totalUnitsPerSubWave && leftToSpawn > 0) { scriptEngine.CreateUnit(unitName[waveSizeIndex], "Hostile", x, y); Actor unit = scriptEngine.GetActorFromLocation(x, y); scriptEngine.UnitAttackMove(unit, waveAttackX, waveAttackY); //counting temp = temp + 1; leftToSpawn = leftToSpawn - 1; unitAmount[waveSizeIndex] = unitAmount[waveSizeIndex] - 1; if (unitAmount[waveSizeIndex] <= 0) { waveSizeIndex = waveSizeIndex + 1; } //pos x = x + 1; if (x >= waveX + waveWidth) { x = waveX; y = y + 1; } } waveSubTimer = waveBetweenEachSubWave; } } } else { // YOU HAVE LOST THE GAME!!! scriptEngine.PlaySound("misnlst1.aud"); scriptEngine.RemoveAllScripts(); scriptEngine.PlayerLost("Multi0"); scriptEngine.PlayerLost("Multi1"); scriptEngine.PlayerLost("Multi2"); } } if (gameTimer == 0) { scriptEngine.CreateWidget("title", "label", "Art of defence", "HugeTitle", 200, 300, 600, 300); } if (gameTimer == 10) { scriptEngine.RemoveWidget("title"); scriptEngine.PlaySound("mtimein1.aud"); } gameTimer = gameTimer + 1; } public void WidgetEvent(string e) { } public void UnitCreated(Actor unit) { } public void WorldLoaded(World w) { scriptEngine.PlaySound("load1.aud"); gameTimer = 0; // is never reset just counts +1 for each tick //temporary variables timer = 1; //timer for sleep count = 0; //number of units left before wave is out wave = 0; //wave to come totalWaves = 1; waveSubTimer = 0; //subwave timer waveSizeIndex = 1; //keeps track of what index we are on in the unitAmount and unitName totalUnitsPerSubWave = 0; leftToSpawn = 0; //sleep time before each wave waveSleep = 20; //time before each subwave spawn waveBetweenEachSubWave = 3; //waves start location and size waveX = 106; waveY = 26; waveWidth = 2; waveHeight = 11; totalUnitsPerSubWave = waveWidth * waveHeight; //wave attack location waveAttackX = 22; waveAttackY = 31; //wave settings unitAmount = new int[500]; unitName = new string[500]; waveSize = new int[500]; //wave 1 int nr = 1; unitAmount[nr] = 20; unitName[nr] = "E1"; nr = nr + 1; unitAmount[nr] = 10; unitName[nr] = "E3"; nr = nr + 1; unitAmount[nr] = 2; unitName[nr] = "JEEP"; waveSize[totalWaves] = 3; //wave 2 totalWaves = totalWaves + 1; nr = nr + 1; unitAmount[nr] = 15; unitName[nr] = "E1"; nr = nr + 1; unitAmount[nr] = 35; unitName[nr] = "1TNK"; waveSize[totalWaves] = 2; //wave 3 totalWaves = totalWaves + 1; nr = nr + 1; unitAmount[nr] = 15; unitName[nr] = "E1"; nr = nr + 1; unitAmount[nr] = 10; unitName[nr] = "E3"; nr = nr + 1; unitAmount[nr] = 7; unitName[nr] = "3TNK"; nr = nr + 1; unitAmount[nr] = 4; unitName[nr] = "ARTY"; waveSize[totalWaves] = 4; //wave 4 totalWaves = totalWaves + 1; nr = nr + 1; unitAmount[nr] = 10; unitName[nr] = "4TNK"; waveSize[totalWaves] = 1; //wave 5 totalWaves = totalWaves + 1; nr = nr + 1; unitAmount[nr] = 25; unitName[nr] = "4TNK"; nr = nr + 1; unitAmount[nr] = 25; unitName[nr] = "4TNK"; waveSize[totalWaves] = 2; //wave 6 totalWaves = totalWaves + 1; nr = nr + 1; unitAmount[nr] = 10; unitName[nr] = "3TNK"; nr = nr + 1; unitAmount[nr] = 10; unitName[nr] = "2TNK"; nr = nr + 1; unitAmount[nr] = 5; unitName[nr] = "ARTY"; nr = nr + 1; unitAmount[nr] = 5; unitName[nr] = "V2RL"; nr = nr + 1; unitAmount[nr] = 5; unitName[nr] = "3TNK"; waveSize[totalWaves] = 5; //wave 7 totalWaves = totalWaves + 1; nr = nr + 1; unitAmount[nr] = 20; unitName[nr] = "3TNK"; nr = nr + 1; unitAmount[nr] = 15; unitName[nr] = "3TNK"; waveSize[totalWaves] = 2; //wave 8 totalWaves = totalWaves + 1; nr = nr + 1; unitAmount[nr] = 40; unitName[nr] = "V2RL"; waveSize[totalWaves] = 1; //wave 9 totalWaves = totalWaves + 1; nr = nr + 1; unitAmount[nr] = 90; unitName[nr] = "3TNK"; waveSize[totalWaves] = 1; //wave 10 totalWaves = totalWaves + 1; nr = nr + 1; unitAmount[nr] = 200; unitName[nr] = "4TNK"; waveSize[totalWaves] = 1; } public void Damaged(Actor self, AttackInfo e) { } public void Killed(Actor self, AttackInfo e) { } public void AppliedDamage(Actor self, Actor damaged, AttackInfo e) { } public void BuildingComplete(Actor self) { } public void UnitProduced(Actor self, Actor other, int2 exit) { } public void OnCapture(Actor self, Actor captor, Player oldOwner, Player newOwner) { } } }