public Worker(Unit u, Commander c) { unitID = u.ID; commander = c; unit = u; unitResources = new Dictionary<int, int>(); currentState = State.IDLE; }
public static IUnitAgent AttachAgent(Unit u, Commander c) { IUnitAgent agent = null; if (u.Type.Worker) { agent = new Worker(u, c); } return agent; }
public void Update(ProxyBot bot, Dictionary<int, IUnitAgent> agents) { //Track units updateUnits(bot); //Assign the center if we haven't done so if (center == null) { center = (from b in buildings where b.Type.Center select b).Single(); } //If we have no barracks, build one buildBarracksIfNeeded(bot, agents); //If we have a barracks, and can affort marines, build some buildMarines(bot); }
private void mineMinerals(Unit resource) { bot.rightClick(unit.ID, resource.ID); unitResources.Add(resource.ID, unit.ID); }
private int sortUnitByDistance(Unit u1, Unit u2) { double distanceToU1 = u1.distance(unit); double distanceToU2 = u2.distance(unit); if (distanceToU1 < distanceToU2) { return -1; } else if (distanceToU2 < distanceToU1) { return 1; } else { return 0; } }
private void mineGas(Unit resource) { if (bot.Player.Minerals > bot.unitTypes[Constants.Terran_Refinery].MineralsCost) { Console.Out.WriteLine("[Worker] Trying to build " + Constants.Terran_Refinery + " at " + resource.X + "," + resource.Y); unitResources.Add(resource.ID, unit.ID); bot.build(unit.ID, resource.X - 2, resource.Y - 1, Constants.Terran_Refinery); } else { List<Unit> resources = new List<Unit>(); foreach (Unit u in bot.Units) { if (u.Type.ID == Constants.Resource_Mineral_Field) { resources.Add(u); } } resources.Sort(sortUnitByDistance); foreach (Unit r in resources) { if (unitResources.Keys.Contains(r.ID)) { //This resource is being mined by a unit continue; } else { mineMinerals(r); break; } } } }
public void Update(ProxyBot pBot) { //Update data bot = pBot; int updatedCount = 0; foreach (Unit u in bot.Units) { if (u.ID == unitID) { unit = u; } if (buildingType > 0 && u.Type.ID == buildingType) { updatedCount++; } } checkIfFinishedBuilding(updatedCount); if (currentState == State.IDLE) { //Figure out what to do, considering where the unit is //what's going on in the game, and what units are near it //For now, hard code it to mine Console.Out.WriteLine("[Worker] Mining"); Mine(); } else if (currentState == State.MOVING) { //If we're moving, we're on our way to build something. updateStateForBuilding(); } }
public void Mine(Unit resource) { currentState = State.MINING; mineMinerals(resource); }
/// <summary> Parses the unit data.</summary> //UPGRADE_TODO: Class 'java.util.HashMap' was converted to 'System.Collections.Hashtable' which has a different behavior. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1073_javautilHashMap'" public static ArrayList getUnits(String unitData, Dictionary<int, UnitType> types ) { ArrayList units = new ArrayList(); String[] unitDatas = unitData.Split(':'); bool first = true; foreach(String data in unitDatas) { if (first) { first = false; continue; } String[] attributes = data.Split(";".ToCharArray()); Unit unit = new Unit { ID = System.Int32.Parse(attributes[0]), PlayerID = System.Int32.Parse(attributes[1]), Type = types[System.Int32.Parse(attributes[2])], X = System.Int32.Parse(attributes[3]), Y = System.Int32.Parse(attributes[4]), HitPoints = System.Int32.Parse(attributes[5]), Shields = System.Int32.Parse(attributes[6]), Energy = System.Int32.Parse(attributes[7]), OrderTimer = System.Int32.Parse(attributes[8]), Order = System.Int32.Parse(attributes[9]), Resources = System.Int32.Parse(attributes[10]) }; units.Add(unit); } return units; }
public virtual double distance(Unit unit) { double dx = unit.X - X; double dy = unit.Y - Y; //Manhattan distance return Math.Sqrt(dx * dx + dy * dy); }