public void Activate() { UnitController.GetInstance(); EnemyController.GetInstance(); FriendlyUnitPositionObserver.GetInstance(); MovementMaps.GetInstance(); BuildMap.GetInstance(); Metal.GetInstance().Init(); LosMap.GetInstance(); BuildPlanner.GetInstance(); BuildTable.GetInstance(); CommanderList.GetInstance(); Level1ConstructorList.GetInstance(); Level1FactoryList.GetInstance(); tankcontroller = new TankController(TankList.GetInstance().defbyid, BuildTable.GetInstance().UnitDefByName["armstump"]); tankcontroller.Activate(); helicoptercontroller = new TankController(HelicopterList.GetInstance().defbyid, BuildTable.GetInstance().UnitDefByName["armbrawl"]); helicoptercontroller.Activate(); new ScoutControllerRaider().Activate(); UnitController.GetInstance().LoadExistingUnits(); EnemyController.GetInstance().LoadExistingUnits(); CheckIdleUnits(); //BuildSolarCell(CommanderList.GetInstance().defbyid.Keys.GetEnumerator().Current); csai.UnitIdleEvent += new CSAI.UnitIdleHandler(csai_UnitIdleEvent); csai.TickEvent += new CSAI.TickHandler(csai_TickEvent); }
// int BuildOffsetDistance = 25; // protected constructor to enforce Singleton pattern CommanderController() { random = new Random(); csai = CSAI.GetInstance(); aicallback = csai.aicallback; logfile = LogFile.GetInstance(); unitcontroller = UnitController.GetInstance(); buildtable = BuildTable.GetInstance(); metal = Metal.GetInstance(); // factorycontroller = PlayStyleManager.GetInstance().GetCurrentPlayStyle().GetFirstControllerOfType( typeof( IFactoryController ) ) as FactoryController; //csai.UnitFinishedEvent += new CSAI.UnitFinishedHandler( UnitFinished ); //csai.UnitDestroyedEvent += new CSAI.UnitDestroyedHandler( UnitDestroyed ); csai.UnitIdleEvent += new CSAI.UnitIdleHandler(UnitIdle); //csai.UnitDamagedEvent += new CSAI.UnitDamagedHandler( UnitDamaged ); csai.TickEvent += new CSAI.TickHandler(Tick); unitcontroller.UnitAddedEvent += new UnitController.UnitAddedHandler(UnitAdded); unitcontroller.UnitRemovedEvent += new UnitController.UnitRemovedHandler(UnitRemoved); csai.RegisterVoiceCommand("commandermove", new CSAI.VoiceCommandHandler(VoiceCommandMoveCommander)); csai.RegisterVoiceCommand("commandergetpos", new CSAI.VoiceCommandHandler(VoiceCommandCommanderGetPos)); csai.RegisterVoiceCommand("commanderbuildat", new CSAI.VoiceCommandHandler(VoiceCommandCommanderBuildAt)); csai.RegisterVoiceCommand("commanderbuild", new CSAI.VoiceCommandHandler(VoiceCommandCommanderBuild)); csai.RegisterVoiceCommand("commanderbuildpower", new CSAI.VoiceCommandHandler(VoiceCommandCommanderBuildPower)); csai.RegisterVoiceCommand("commanderbuildextractor", new CSAI.VoiceCommandHandler(VoiceCommandCommanderBuildExtractor)); csai.RegisterVoiceCommand("commanderisactive", new CSAI.VoiceCommandHandler(VoiceCommandCommanderIsActive)); }
public ConstructorController(IPlayStyle playstyle) { this.playstyle = playstyle; csai = CSAI.GetInstance(); aicallback = csai.aicallback; logfile = LogFile.GetInstance(); ShowNextBuildSite = csai.DebugOn; unitcontroller = UnitController.GetInstance(); // factorycontroller = FactoryController.GetInstance(); buildtable = BuildTable.GetInstance(); metal = Metal.GetInstance(); ShowNextBuildSite = csai.DebugOn; logfile.WriteLine("ConstructorController::ConstructorController() finished"); }
bool BuildMex(int constructorid) { if (!BuildTree.GetInstance().CanBuild(UnitController.GetInstance().UnitDefByDeployedId[constructorid].name.ToLower(), "armmex")) { return(false); } IUnitDef unitdef = BuildTable.GetInstance().UnitDefByName["armmex"]; Float3 buildsite = Metal.GetInstance().GetNearestMetalSpot(aicallback.GetUnitPos(constructorid)); buildsite = aicallback.ClosestBuildSite(unitdef, buildsite, 100, 0); if (!ActiveConstructors.Contains(constructorid)) { ActiveConstructors.Add(constructorid); } //aicallback.GiveOrder(constructorid, new Command(-unitdef.id, buildsite.ToDoubleArray())); GiveOrderWrapper.GetInstance().BuildUnit(constructorid, unitdef.name, buildsite); return(true); }
//int numOfUnits = 0; //IUnitDef[] unitList; //IUnitDef solarcollectordef; public void InitAI(IAICallback aicallback, int team) { Thread.CurrentThread.CurrentCulture = new CultureInfo("en-GB"); this.aicallback = aicallback; try{ this.Team = team; logfile = LogFile.GetInstance().Init(team); logfile.WriteLine("C# AI started v" + AIVersion + ", team " + team + " ref " + reference + " map " + aicallback.GetMapName() + " mod " + aicallback.GetModName()); if (File.Exists("AI/CSAI/debug.flg")) // if this file exists, activate debug mode; saves manually changing this for releases { logfile.WriteLine("Toggling debug on"); DebugOn = true; } if (DebugOn) { new Testing.RunTests().Go(); } InitCache(); PlayStyleManager.GetInstance(); LoadPlayStyles.Go(); metal = Metal.GetInstance(); CommanderController.GetInstance(); BuildTable.GetInstance(); UnitController.GetInstance(); EnemyController.GetInstance(); EnergyController.GetInstance(); MovementMaps.GetInstance(); BuildMap.GetInstance(); //FactoryController.GetInstance(); //RadarController.GetInstance(); //TankController.GetInstance(); //ScoutController.GetInstance(); //ConstructorController.GetInstance(); metal.Init(); BuildPlanner.GetInstance(); UnitController.GetInstance().LoadExistingUnits(); // need this if we're being reloaded in middle of a game, to get already existing units EnemyController.GetInstance().LoadExistingUnits(); StrategyController.GetInstance(); LoadStrategies.Go(); PlayStyleManager.GetInstance().ChoosePlayStyle("tankrush"); if (aicallback.GetModName().ToLower().IndexOf("aass") == 0 || aicallback.GetModName().ToLower().IndexOf("xtape") == 0) { aicallback.SendTextMsg("C# AI initialized v" + AIVersion + ", team " + team, 0); aicallback.SendTextMsg("Please say '.csai help' for available commands", 0); PlayStyleManager.GetInstance().ListPlayStyles(); //CommanderController.GetInstance().CommanderBuildPower(); } else { aicallback.SendTextMsg("Warning: CSAI needs AA2.23 or XTA7 to run correctly at this time", 0); logfile.WriteLine("*********************************************************"); logfile.WriteLine("*********************************************************"); logfile.WriteLine("**** ****"); logfile.WriteLine("**** Warning: CSAI needs AA2.23 or XTA7 to run correctly at this time ****"); logfile.WriteLine("**** ****"); logfile.WriteLine("*********************************************************"); logfile.WriteLine("*********************************************************"); } } catch (Exception e) { logfile.WriteLine("Exception: " + e.ToString()); aicallback.SendTextMsg("Exception: " + e.ToString(), 0); } }