// loads cache file // returns true if cache loaded ok, otherwise false if not found, out-of-date, etc // we check the version and return false if out-of-date bool LoadCache() { string MapName = aicallback.GetMapName(); string cachefilepath = Path.Combine(csai.CacheDirectoryPath, MapName + "_metal.xml"); if (!File.Exists(cachefilepath)) { logfile.WriteLine("cache file doesnt exist -> building"); return(false); } XmlDocument cachedom = XmlHelper.OpenDom(cachefilepath); XmlElement metadata = cachedom.SelectSingleNode("/root/metadata") as XmlElement; string cachemetalclassversion = metadata.GetAttribute("version"); if (cachemetalclassversion != MetalClassVersion) { logfile.WriteLine("cache file out of date ( " + cachemetalclassversion + " vs " + MetalClassVersion + " ) -> rebuilding"); return(false); } logfile.WriteLine(cachedom.InnerXml); isMetalMap = Convert.ToBoolean(metadata.GetAttribute("ismetalmap")); if (isMetalMap) { logfile.WriteLine("metal map"); return(true); } XmlElement metalspots = cachedom.SelectSingleNode("/root/metalspots") as XmlElement; ArrayList metalspotsal = new ArrayList(); foreach (XmlElement metalspot in metalspots.SelectNodes("metalspot")) { int amount = Convert.ToInt32(metalspot.GetAttribute("amount")); Float3 pos = new Float3(); Float3Helper.WriteXmlElementToFloat3(metalspot, pos); //pos.LoadCsv( metalspot.GetAttribute("pos") ); MetalSpot newmetalspot = new MetalSpot(amount, pos); metalspotsal.Add(newmetalspot); // logfile.WriteLine( "metalspot xml: " + metalspot.InnerXml ); logfile.WriteLine("metalspot: " + newmetalspot.ToString()); } MetalSpots = (MetalSpot[])metalspotsal.ToArray(typeof(MetalSpot)); logfile.WriteLine("cache file loaded"); return(true); }
public void InitAI( IAICallback aicallback, int team ) { this.aicallback = aicallback; this.team = team; aicallback.SendTextMsg( "Hello from Mono AbicWrappers", 0 ); aicallback.SendTextMsg( "The map name is: " + aicallback.GetMapName(), 0 ); aicallback.SendTextMsg( "Our ally team is: " + aicallback.GetMyTeam(), 0 ); //int features[10000 + 1]; //int numfeatures = IAICallback_GetFeatures( aicallback, features, 10000 ); //sprintf( buffer, "Num features is: %i", numfeatures ); //IAICallback_SendTextMsg( aicallback, buffer, 0 ); //const FeatureDef *featuredef = IAICallback_GetFeatureDef( aicallback, features[0] ); //sprintf( buffer, "First feature: %s", FeatureDef_get_myName( featuredef ) ); //IAICallback_SendTextMsg( aicallback, buffer, 0 ); IUnitDef unitdef = aicallback.GetUnitDefByTypeId( 34 ); aicallback.SendTextMsg( "gotunitdef", 0 ); aicallback.SendTextMsg( "type id 34 is " + unitdef.name, 0 ); aicallback.SendTextMsg( "human name: " + unitdef.humanName, 0 ); aicallback.SendTextMsg( "id: " + unitdef.id, 0 ); IMoveData movedata = unitdef.movedata; //IAICallback_SendTextMsg( aicallback, "movedata is null? " + ( movedata == 0 ); //IAICallback_SendTextMsg( aicallback, buffer, 0 ); //IAICallback_SendTextMsg( aicallback, "movetype: %i" + MoveData_get_movetype( movedata ) ); //IAICallback_SendTextMsg( aicallback, buffer, 0 ); aicallback.SendTextMsg( "maxslope: " + movedata.maxSlope, 0 ); }
public void InitAI(IAICallback aicallback, int team) { this.aicallback = aicallback; this.team = team; aicallback.SendTextMsg("Hello from Mono AbicWrappers", 0); aicallback.SendTextMsg("The map name is: " + aicallback.GetMapName(), 0); aicallback.SendTextMsg("Our ally team is: " + aicallback.GetMyTeam(), 0); //int features[10000 + 1]; //int numfeatures = IAICallback_GetFeatures( aicallback, features, 10000 ); //sprintf( buffer, "Num features is: %i", numfeatures ); //IAICallback_SendTextMsg( aicallback, buffer, 0 ); //const FeatureDef *featuredef = IAICallback_GetFeatureDef( aicallback, features[0] ); //sprintf( buffer, "First feature: %s", FeatureDef_get_myName( featuredef ) ); //IAICallback_SendTextMsg( aicallback, buffer, 0 ); IUnitDef unitdef = aicallback.GetUnitDefByTypeId(34); aicallback.SendTextMsg("gotunitdef", 0); aicallback.SendTextMsg("type id 34 is " + unitdef.name, 0); aicallback.SendTextMsg("human name: " + unitdef.humanName, 0); aicallback.SendTextMsg("id: " + unitdef.id, 0); IMoveData movedata = unitdef.movedata; //IAICallback_SendTextMsg( aicallback, "movedata is null? " + ( movedata == 0 ); //IAICallback_SendTextMsg( aicallback, buffer, 0 ); //IAICallback_SendTextMsg( aicallback, "movetype: %i" + MoveData_get_movetype( movedata ) ); //IAICallback_SendTextMsg( aicallback, buffer, 0 ); aicallback.SendTextMsg("maxslope: " + movedata.maxSlope, 0); }
//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() ); csaiuserinteraction = CSAIUserInteraction.GetInstance(); 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(); FriendlyUnitPositionObserver.GetInstance(); EnergyController.GetInstance(); MovementMaps.GetInstance(); BuildMap.GetInstance(); LosMap.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 ) { SendTextMsg( "C# AI initialized v" + AIVersion + ", team " + team ); SendTextMsg( "Please say '.csai help' for available commands" ); PlayStyleManager.GetInstance().ListPlayStyles(); //CommanderController.GetInstance().CommanderBuildPower(); } else { SendTextMsg( "Warning: CSAI needs AA2.23 or XTA7 to run correctly at this time" ); 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() ); SendTextMsg( "Exception: " + e.ToString() ); } }
public void InitAI( IAICallback aicallback, int team) { this.aicallback = aicallback; Thread.CurrentThread.CurrentCulture = new CultureInfo("en-GB"); try{ Directory.CreateDirectory(AIDirectoryPath); this.Team = team; logfile = LogFile.GetInstance().Init( Path.Combine( AIDirectoryPath, "csharpai_team" + team + ".log" ) ); logfile.WriteLine( "C# AI started v" + AIVersion+ ", team " + team + " ref " + reference + " map " + aicallback.GetMapName() + " mod " + aicallback.GetModName() ); logfile.WriteLine("RL Date/time: " + DateTime.Now.ToString()); if( File.Exists( AIDirectoryPath + "/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(); /* IUnitDef unitdef = aicallback.GetUnitDefByTypeId(34); aicallback.SendTextMsg(unitdef.name,0); aicallback.SendTextMsg(unitdef.id.ToString(), 0); aicallback.SendTextMsg(unitdef.humanName, 0); aicallback.SendTextMsg(unitdef.movedata.moveType.ToString(), 0); aicallback.SendTextMsg(unitdef.movedata.maxSlope.ToString(), 0); aicallback.GetMetalMap(); aicallback.GetLosMap(); aicallback.GetRadarMap(); aicallback.GetFriendlyUnits(); aicallback.GetFeatures(); aicallback.GetEnemyUnitsInRadarAndLos(); Metal.GetInstance(); */ //aicallback.GetElevation(300,300); //new SlopeMap().GetSlopeMap(); //double[,] _SlopeMap = new double[256, 256]; //LosMap.GetInstance(); //MovementMaps.GetInstance(); //BuildMap.GetInstance().Init(); //return; // -- test stuff here -- logfile.WriteLine("Is game paused? : " + aicallback.IsGamePaused()); // -- end test stuff -- BuildEconomy buildeconomy = new BuildEconomy(); // UnitController.GetInstance().LoadExistingUnits(); // need this if we're being reloaded in middle of a game, to get already existing units SendTextMsg("C# AI initialized v" + AIVersion + ", team " + team); } catch( Exception e ) { logfile.WriteLine( "Exception: " + e.ToString() ); SendTextMsg( "Exception: " + e.ToString() ); } }
//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); } }
//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( Path.Combine( AIDirectoryPath, "csharpai_team" + team + ".log" ) ); logfile.WriteLine( "C# AI started v" + AIVersion+ ", team " + team + " ref " + reference + " map " + aicallback.GetMapName() + " mod " + aicallback.GetModName() ); logfile.WriteLine("RL Date/time: " + DateTime.Now.ToString()); if( File.Exists( AIDirectoryPath + "/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(); BuildEconomy buildeconomy = new BuildEconomy(); // UnitController.GetInstance().LoadExistingUnits(); // need this if we're being reloaded in middle of a game, to get already existing units SendTextMsg("C# AI initialized v" + AIVersion + ", team " + team); } catch( Exception e ) { logfile.WriteLine( "Exception: " + e.ToString() ); SendTextMsg( "Exception: " + e.ToString() ); } }
public void InitAI(IAICallback aicallback, int team) { this.aicallback = aicallback; Thread.CurrentThread.CurrentCulture = new CultureInfo("en-GB"); try{ Directory.CreateDirectory(AIDirectoryPath); this.Team = team; logfile = LogFile.GetInstance().Init(Path.Combine(AIDirectoryPath, "csharpai_team" + team + ".log")); logfile.WriteLine("C# AI started v" + AIVersion + ", team " + team + " ref " + reference + " map " + aicallback.GetMapName() + " mod " + aicallback.GetModName()); logfile.WriteLine("RL Date/time: " + DateTime.Now.ToString()); if (File.Exists(AIDirectoryPath + "/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(); /* * IUnitDef unitdef = aicallback.GetUnitDefByTypeId(34); * aicallback.SendTextMsg(unitdef.name,0); * aicallback.SendTextMsg(unitdef.id.ToString(), 0); * aicallback.SendTextMsg(unitdef.humanName, 0); * aicallback.SendTextMsg(unitdef.movedata.moveType.ToString(), 0); * aicallback.SendTextMsg(unitdef.movedata.maxSlope.ToString(), 0); * aicallback.GetMetalMap(); * aicallback.GetLosMap(); * aicallback.GetRadarMap(); * aicallback.GetFriendlyUnits(); * aicallback.GetFeatures(); * aicallback.GetEnemyUnitsInRadarAndLos(); * * Metal.GetInstance(); */ //aicallback.GetElevation(300,300); //new SlopeMap().GetSlopeMap(); //double[,] _SlopeMap = new double[256, 256]; //LosMap.GetInstance(); //MovementMaps.GetInstance(); //BuildMap.GetInstance().Init(); //return; // -- test stuff here -- logfile.WriteLine("Is game paused? : " + aicallback.IsGamePaused()); // -- end test stuff -- BuildEconomy buildeconomy = new BuildEconomy(); // UnitController.GetInstance().LoadExistingUnits(); // need this if we're being reloaded in middle of a game, to get already existing units SendTextMsg("C# AI initialized v" + AIVersion + ", team " + team); } catch (Exception e) { logfile.WriteLine("Exception: " + e.ToString()); SendTextMsg("Exception: " + e.ToString()); } }
//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(Path.Combine(AIDirectoryPath, "csharpai_team" + team + ".log")); logfile.WriteLine("C# AI started v" + AIVersion + ", team " + team + " ref " + reference + " map " + aicallback.GetMapName() + " mod " + aicallback.GetModName()); logfile.WriteLine("RL Date/time: " + DateTime.Now.ToString()); if (File.Exists(AIDirectoryPath + "/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(); BuildEconomy buildeconomy = new BuildEconomy(); // UnitController.GetInstance().LoadExistingUnits(); // need this if we're being reloaded in middle of a game, to get already existing units SendTextMsg("C# AI initialized v" + AIVersion + ", team " + team); } catch (Exception e) { logfile.WriteLine("Exception: " + e.ToString()); SendTextMsg("Exception: " + e.ToString()); } }