public void DumpRadar(string cmd, string[] cmdsplit, int player) { logfile.WriteLine("calling GetRadarMap..."); bool[] LosMap = aicallback.GetRadarMap(); logfile.WriteLine("...done"); int loswidth = aicallback.GetMapWidth() / 8; int losheight = aicallback.GetMapHeight() / 8; logfile.WriteLine("losmap width: " + loswidth + " losheight: " + losheight); ArrayIndexer arrayindexer = new ArrayIndexer(loswidth, losheight); for (int y = 0; y < losheight; y++) { string line = ""; for (int x = 0; x < loswidth; x++) { if (LosMap[arrayindexer.GetIndex(x, y)]) { aicallback.DrawUnit("ARMRAD", new Float3(x * 64, 0, y * 64), 0.0f, 100, aicallback.GetMyAllyTeam(), true, true); line += "*"; } else { line += "-"; } } logfile.WriteLine(line); } aicallback.SendTextMsg("radar dumped to logfile", 0); }
bool DoReclaim(int constructorid) { if (totalticks == 0) // check ticks first, beacuse metal shows as zero at start { return(false); } IUnitDef unitdef = UnitDefByUnitId[constructorid] as IUnitDef; Float3 mypos = aicallback.GetUnitPos(constructorid); MovementMaps movementmaps = MovementMaps.GetInstance(); int currentarea = movementmaps.GetArea(unitdef, mypos); //double nearestreclaimdistancesquared = 1000000; //Float3 nearestreclaimpos = null; double bestmetaldistanceratio = 0; int bestreclaimid = 0; int metalspace = (int)(aicallback.GetMetalStorage() - aicallback.GetMetal()); logfile.WriteLine("available space in metal storage: " + metalspace); int[] nearbyfeatures = aicallback.GetFeatures(mypos, maxreclaimradius); bool reclaimfound = false; foreach (int feature in nearbyfeatures) { IFeatureDef featuredef = aicallback.GetFeatureDef(feature); if (featuredef.metal > 0 && featuredef.metal <= metalspace) { Float3 thisfeaturepos = aicallback.GetFeaturePos(feature); double thisdistance = Math.Sqrt(Float3Helper.GetSquaredDistance(thisfeaturepos, mypos)); double thismetaldistanceratio = featuredef.metal / thisdistance; if (thismetaldistanceratio > bestmetaldistanceratio && movementmaps.GetArea(unitdef, thisfeaturepos) == currentarea) { logfile.WriteLine("Potential reclaim, distance = " + thisdistance + " metal = " + featuredef.metal + " ratio = " + thismetaldistanceratio); bestmetaldistanceratio = thismetaldistanceratio; bestreclaimid = feature; // nearestreclaimpo reclaimfound = true; } } } if (reclaimfound && (bestmetaldistanceratio > (1.0 / (100 * reclaimradiusperonehundredmetal)))) { Float3 reclaimpos = aicallback.GetFeaturePos(bestreclaimid); logfile.WriteLine("Reclaim found, pos " + reclaimpos.ToString()); if (csai.DebugOn) { aicallback.DrawUnit("ARMMEX", reclaimpos, 0.0f, 200, aicallback.GetMyAllyTeam(), true, true); } aicallback.GiveOrder(constructorid, new Command(Command.CMD_RECLAIM, new double[] { reclaimpos.x, reclaimpos.y, reclaimpos.z, 10 })); } else { logfile.WriteLine("No reclaim within parameters"); } return(reclaimfound); }
void ShowEnemies() { foreach (DictionaryEntry de in EnemyStaticPosByDeployedId) { Float3 pos = de.Value as Float3; aicallback.DrawUnit(BuildTable.ArmGroundScout, pos, 0.0f, 50, aicallback.GetMyAllyTeam(), true, true); } foreach (DictionaryEntry de in EnemyUnitDefByDeployedId) { int enemyid = (int)de.Key; //IUnitDef unit = de.Value as Float3; Float3 pos = aicallback.GetUnitPos(enemyid); aicallback.DrawUnit(BuildTable.ArmL1AntiAir, pos, 0.0f, 50, aicallback.GetMyAllyTeam(), true, true); } // logfile.WriteLine( "Number enemies: " + EnemyUnitDefByDeployedId.Count ); }
void ShowEnemies() { foreach (KeyValuePair <int, Float3> kvp in EnemyStaticPosByDeployedId) { Float3 pos = kvp.Value; aicallback.DrawUnit("ARMAMD", pos, 0.0f, 50, aicallback.GetMyAllyTeam(), true, true); } foreach (KeyValuePair <int, IUnitDef> kvp in EnemyUnitDefByDeployedId) { int enemyid = kvp.Key; //IUnitDef unit = de.Value as Float3; Float3 pos = aicallback.GetUnitPos(enemyid); if (pos != null) { aicallback.DrawUnit("ARMSAM", pos, 0.0f, 50, aicallback.GetMyAllyTeam(), true, true); } } // logfile.WriteLine( "Number enemies: " + EnemyUnitDefByDeployedId.Count ); }
void DumpPoints(string cmd, string[] splitcmd, int player) { MapPoint[] mappoints = aicallback.GetMapPoints(); foreach (MapPoint mappoint in mappoints) { aicallback.DrawUnit("ARMSOLAR", mappoint.Pos, 0.0f, 100, aicallback.GetMyAllyTeam(), true, true); logfile.WriteLine("mappoint: " + mappoint.Pos.ToString() + " " + mappoint.Label); } logfile.Flush(); }
// for debugging / convincing oneself spots are in right place void DrawMetalSpots() { if (!isMetalMap) { foreach (object metalspotobject in MetalSpots) { MetalSpot metalspot = metalspotobject as MetalSpot; logfile.WriteLine("drawing spot at " + metalspot.Pos); aicallback.DrawUnit("ARMMEX", metalspot.Pos, 0.0f, 500, aicallback.GetMyAllyTeam(), true, true); } foreach (object metalspotobject in MetalSpotsUsed) { MetalSpot metalspot = metalspotobject as MetalSpot; logfile.WriteLine("drawing usedspot at " + metalspot.Pos); aicallback.DrawUnit("ARMFORT", metalspot.Pos, 0.0f, 500, aicallback.GetMyAllyTeam(), true, true); } } else { aicallback.SendTextMsg("Metal analyzer reports this is a metal map", 0); } }
public void EnemyAdded(int id, IUnitDef unitdef) { Float3 enemypos = aicallback.GetUnitPos(id); for (int i = 0; i < 3; i++) { Float3 randomoffset = new Float3(random.Next(-enemysightedsearchradius, enemysightedsearchradius), 0, random.Next(-enemysightedsearchradius, enemysightedsearchradius)); if (csai.DebugOn) { aicallback.DrawUnit("ARMARAD", enemypos + randomoffset, 0.0f, 500, aicallback.GetMyAllyTeam(), true, true); } PriorityTargets.Enqueue(enemypos + randomoffset); } }
public void UnitCreated(int unit) { aicallback.SendTextMsg("Unit created: " + unit, 0); IUnitDef unitdef = aicallback.GetUnitDef(unit); aicallback.SendTextMsg("Unit created: " + unitdef.name, 0); IMoveData movedata = unitdef.movedata; if (movedata != null) { aicallback.SendTextMsg("Max Slope: " + movedata.maxSlope, 0); } if (unitdef.isCommander) { int numbuildoptions = unitdef.GetNumBuildOptions(); string buildoptionsstring = "Build options: "; for (int i = 0; i < numbuildoptions; i++) { buildoptionsstring += unitdef.GetBuildOption(i); } aicallback.SendTextMsg(buildoptionsstring, 0); Float3 commanderpos = aicallback.GetUnitPos(unit); aicallback.SendTextMsg("Commanderpos: " + commanderpos.ToString(), 0); int numunitdefs = aicallback.GetNumUnitDefs(); aicallback.SendTextMsg("Num unit defs: " + numunitdefs, 0); for (int i = 1; i <= numunitdefs; i++) { IUnitDef thisunitdef = aicallback.GetUnitDefByTypeId(i); if (thisunitdef.name == "ARMSOLAR") { aicallback.SendTextMsg("Found solar collector def: " + thisunitdef.id, 0); Float3 nearestbuildpos = aicallback.ClosestBuildSite(thisunitdef, commanderpos, 1400, 2); aicallback.SendTextMsg("Closest build site: " + nearestbuildpos.ToString(), 0); aicallback.DrawUnit("ARMSOLAR", nearestbuildpos, 0, 200, aicallback.GetMyAllyTeam(), true, true); aicallback.GiveOrder(unit, new Command(-thisunitdef.id, nearestbuildpos.ToDoubleArray())); } } } }
Float3 BuildUnit(int constructorid, string targetunitname) { csai.DebugSay("workflow, building " + targetunitname); IUnitDef targetunitdef = BuildTable.GetInstance().UnitDefByName[targetunitname]; IUnitDef constructordef = UnitController.GetInstance().UnitDefByDeployedId[constructorid]; if (new UnitDefHelp(aicallback).IsMobile(constructordef)) { logfile.WriteLine("constructor is mobile"); Float3 constructorpos = aicallback.GetUnitPos(constructorid); Float3 buildsite = BuildPlanner.GetInstance().ClosestBuildSite(targetunitdef, constructorpos, 3000, 2); buildsite = aicallback.ClosestBuildSite(targetunitdef, buildsite, 1400, 0); logfile.WriteLine("constructor location: " + constructorpos.ToString() + " Buildsite: " + buildsite.ToString() + " target item: " + targetunitdef.humanName); if (!ActiveConstructors.Contains(constructorid)) { ActiveConstructors.Add(constructorid); } aicallback.DrawUnit(targetunitname.ToUpper(), buildsite, 0.0, 200, aicallback.GetMyAllyTeam(), true, true); GiveOrderWrapper.GetInstance().BuildUnit(constructorid, targetunitname, buildsite); return(buildsite); } else { Float3 factorypos = aicallback.GetUnitPos(constructorid); logfile.WriteLine("factory location: " + factorypos.ToString() + " target item: " + targetunitdef.humanName); if (!ActiveConstructors.Contains(constructorid)) { ActiveConstructors.Add(constructorid); } aicallback.DrawUnit(targetunitdef.name.ToUpper(), factorypos, 0.0, 200, aicallback.GetMyAllyTeam(), true, true); GiveOrderWrapper.GetInstance().BuildUnit(constructorid, targetunitname); return(factorypos); } }
void MoveTo(Float3 pos) { // check whether we really need to do anything or if order is roughly same as last one if (csai.DebugOn) { aicallback.DrawUnit("ARMSOLAR", pos, 0.0f, 50, aicallback.GetMyAllyTeam(), true, true); } if (restartedfrompause || Float3Helper.GetSquaredDistance(pos, lasttargetpos) > (movetothreshold * movetothreshold)) { foreach (DictionaryEntry de in UnitDefListByDeployedId) { int deployedid = (int)de.Key; IUnitDef unitdef = de.Value as IUnitDef; aicallback.GiveOrder(deployedid, new Command(Command.CMD_MOVE, pos.ToDoubleArray())); } restartedfrompause = false; lasttargetpos = pos; } }
public void UnitMoveFailed(int unit) { try { if (UnitMoveFailedEvent != null) { UnitMoveFailedEvent(unit); } if (DebugOn) { aicallback.DrawUnit("ARMRAD", aicallback.GetUnitPos(unit), 0.0f, 500, aicallback.GetMyAllyTeam(), true, true); } // note to self: add add map ponits to interface } catch (Exception e) { logfile.WriteLine("Exception: " + e.ToString()); SendTextMsg("Exception: " + e.ToString()); } }
void CommanderBuildAt(IUnitDef unitdef, Float3 buildsite) { logfile.WriteLine("Commander building " + unitdef.name + " at " + buildsite.ToString()); aicallback.DrawUnit(unitdef.name, buildsite, 0.0f, 500, aicallback.GetMyAllyTeam(), true, true); aicallback.GiveOrder(commanderid, new Command(-unitdef.id, buildsite.ToDoubleArray())); }