public void OperateDepot(bool raise) { if ((unitType != Units.SUPPLY_DEPOT) && (unitType != Units.SUPPLY_DEPOT_LOWERED)) { throw new Exception("Cannot operate depot with: {0}" + this); } if (raise) { if (unitType != Units.SUPPLY_DEPOT_LOWERED) { return; } } else { if (unitType != Units.SUPPLY_DEPOT) { return; } } Action action = Controller.CreateRawUnitCommand(raise ? Abilities.DEPOT_RAISE : Abilities.DEPOT_LOWER); action.ActionRaw.UnitCommand.UnitTags.Add(tag); action.ActionRaw.UnitCommand.QueueCommand = false; Controller.AddAction(action); }
public bool TryGetAction(out Action action) { action = null; if (ProbablyToFastOrders()) { return(false); } if (HighLevelOrder.Goal == Goal.Idle) { return(false); } if (HighLevelOrder.Goal == Goal.Scout) { //MoveAt(latestGameInfo.StartRaw.StartLocations[0]); } if (CurrentAction != null) { action = CurrentAction; lastOrderTime = Environment.TickCount; return(true); } return(false); }
private void MoveAt(Point2D position) { var action = CreateRawUnitCommand(Abilities.Move); action.ActionRaw.UnitCommand.TargetWorldSpacePos = position; CurrentAction = action; }
public static Action CreateRawUnitCommand(int ability) { var action = new Action(); action.ActionRaw = new ActionRaw(); action.ActionRaw.UnitCommand = new ActionRawUnitCommand(); action.ActionRaw.UnitCommand.AbilityId = ability; return action; }
public SC2APIProtocol.Action BuildSupply(Unit cc) { if (!coolDownCommand.IsDelayed("BuildSupply")) { coolDownCommand.Add(new CoolDownCommandData() { key = "BuildSupply", finishStep = gameLoop + 10 }); SC2APIProtocol.Action answer = CreateAction(cc, ABILITY_ID.BUILD_SUPPLYDEPOT); List <Point2D> poses = FindPlaceables((int)cc.Pos.X, (int)cc.Pos.Y, 10, UNIT_TYPEID.TERRAN_SUPPLYDEPOT, true); if (poses.Count > 0) { ScoreDatas scores = new ScoreDatas(); foreach (Point2D p in poses) { float dist = cc.Pos.Dist(p.X, p.Y); scores.Add(new ScoreData { data = p, score = dist }); } scores.Sort(); scores.Reverse(); //Point2D pos = FindPlaceable((int)cc.Pos.X, (int)cc.Pos.Y, 10,UNIT_TYPEID.TERRAN_SUPPLYDEPOT,true); Point2D pos = (Point2D)scores[0].data; if (pos != null) { logDebug("BuildSupply at " + pos.ToString()); answer.ActionRaw.UnitCommand.TargetWorldSpacePos = pos; return(answer); } } } return(null); }
private static void AddUnitTagsToAction(List <Unit> units, Action action) { foreach (var unit in units) { action.ActionRaw.UnitCommand.UnitTags.Add(unit.Tag); } }
public SC2APIProtocol.Action NewAction() { SC2APIProtocol.Action answer = new SC2APIProtocol.Action(); answer.ActionRaw = new ActionRaw(); answer.ActionRaw.ClearAction(); return(answer); }
public static IEnumerable <SC2APIProtocol.Action> MasterAgent_MainLoop(GameState gameState) { SC2GameState gs = new SC2GameState(gameState); SC2APIProtocol.Action answer = bot.Update(gs); yield return(answer); }
public virtual SC2APIProtocol.Action CreateAction(Unit u, ABILITY_ID ability) { SC2APIProtocol.Action answer = NewAction(); answer.ActionRaw.UnitCommand = new ActionRawUnitCommand(); answer.ActionRaw.UnitCommand.AbilityId = (int)ability; answer.ActionRaw.UnitCommand.UnitTags.Add(u.Tag); return(answer); }
private SC2APIProtocol.Action CreateRawUnitCommand(int ability) { SC2APIProtocol.Action action = new SC2APIProtocol.Action(); action.ActionRaw = new ActionRaw(); action.ActionRaw.UnitCommand = new ActionRawUnitCommand(); action.ActionRaw.UnitCommand.AbilityId = ability; return(action); }
public override IEnumerable <SC2APIProtocol.Action> PerformActions(int frame) { var actions = new List <SC2APIProtocol.Action>(); if (WallPoints != null) { var buildings = ActiveUnitData.Commanders.Where(u => u.Value.UnitCalculation.Attributes.Contains(Attribute.Structure) && WallPoints.Any(point => Vector2.DistanceSquared(new Vector2(point.X, point.Y), u.Value.UnitCalculation.Position) < 1)).Select(b => b.Value); if (buildings.Count() == 0) { Ended = true; Disable(); } var attacked = false; foreach (var building in buildings) { if (building != null) { if (building.UnitCalculation.Unit.BuildProgress < 1) { var action = building.Order(frame, Abilities.CANCEL); if (action != null) { actions.AddRange(action); } } else { if (!attacked) { var command = new ActionRawUnitCommand(); foreach (var commander in UnitCommanders) { command.UnitTags.Add(commander.UnitCalculation.Unit.Tag); } command.AbilityId = (int)Abilities.ATTACK; command.TargetUnitTag = building.UnitCalculation.Unit.Tag; var action = new SC2APIProtocol.Action { ActionRaw = new ActionRaw { UnitCommand = command } }; actions.Add(action); attacked = true; } } } } } return(actions); }
public static void Chat(string message, bool team = false) { var actionChat = new ActionChat(); actionChat.Channel = team ? ActionChat.Types.Channel.Team : ActionChat.Types.Channel.Broadcast; actionChat.Message = message; var action = new Action(); action.ActionChat = actionChat; AddAction(action); }
private async Task SendBuildRequest(Unit worker, int unitType, Point2D point) { var requestDebug = new RequestDebug(); DebugDraw debugDraw = new DebugDraw(); debugDraw.Boxes.Add(new DebugBox { Min = new Point { X = point.X - 1, Y = point.Y - 1, Z = 14 }, // Z?? Max = new Point { X = point.X + 1, Y = point.Y + 1, Z = 11 }, Color = new Color { R = 180, G = 255, B = 255 } }); requestDebug.Debug.Add(new DebugCommand { Draw = debugDraw }); await _connectionService.SendRequestAsync(new Request { Debug = requestDebug }); // move there first var action2 = new Action(); action2.ActionRaw = new ActionRaw(); action2.ActionRaw.UnitCommand = new ActionRawUnitCommand(); action2.ActionRaw.UnitCommand.AbilityId = 19; // Move abilitiy action2.ActionRaw.UnitCommand.UnitTags.Add(worker.Tag); action2.ActionRaw.UnitCommand.TargetWorldSpacePos = point; var action = new Action(); action.ActionRaw = new ActionRaw(); action.ActionRaw.UnitCommand = new ActionRawUnitCommand(); action.ActionRaw.UnitCommand.AbilityId = _gameDataService.GetAbilityId(unitType); action.ActionRaw.UnitCommand.UnitTags.Add(worker.Tag); action.ActionRaw.UnitCommand.TargetWorldSpacePos = point; // move back to mining var backToMining = new Action(); backToMining.ActionRaw = new ActionRaw(); backToMining.ActionRaw.UnitCommand = new ActionRawUnitCommand(); backToMining.ActionRaw.UnitCommand.QueueCommand = true; backToMining.ActionRaw.UnitCommand.AbilityId = 295; // Gather ability TODO: (scv specific!) backToMining.ActionRaw.UnitCommand.UnitTags.Add(worker.Tag); backToMining.ActionRaw.UnitCommand.TargetUnitTag = Game.MapManager.GetMineralInMainBase(); var requestAction = new RequestAction(); //requestAction.Actions.Add(action2); requestAction.Actions.Add(action); requestAction.Actions.Add(backToMining); await _connectionService.SendRequestAsync(new Request { Action = requestAction }); }
public virtual SC2APIProtocol.Action Process() { SC2APIProtocol.Action answer = NewAction(); Observation obs = newObservation.Observation; logPrintf("Game loop {0}", obs.GameLoop); DumpUnits(); return(answer); }
public SC2GameState(GameState gameState) { NewObservation = gameState.NewObservation; GameInfo = gameState.GameInfo; LastActions = gameState.LastActions.ToList(); if (gameState.LastObservation != null) { LastObservation = gameState.LastObservation.Value; } CurrentAction = new SC2APIProtocol.Action(); }
public SC2APIProtocol.Action Stimpack(List <Unit> units) { SC2APIProtocol.Action answer = NewAction(); answer.ActionRaw.UnitCommand = new ActionRawUnitCommand(); answer.ActionRaw.UnitCommand.AbilityId = (int)ABILITY_ID.EFFECT_STIM; foreach (Unit cc in units) { answer.ActionRaw.UnitCommand.UnitTags.Add(cc.Tag); } return(answer); }
public static String ToStringEx(this SC2APIProtocol.Action self) { if (self.HasCommand() && (self.ActionRaw.UnitCommand.AbilityId != 0)) { return(Enum.GetName(typeof(ABILITY_ID), self.ActionRaw.UnitCommand.AbilityId) + " " + self.ToString()); } else { return(self.ToString()); } }
public SC2APIProtocol.Action GatherMineral(Unit cc) { Unit target = FindNearest(cc, UNIT_TYPEID.NEUTRAL_MINERALFIELD); if (target != null) { SC2APIProtocol.Action answer = CreateAction(cc, ABILITY_ID.HARVEST_GATHER_SCV); answer.ActionRaw.UnitCommand.TargetUnitTag = target.Tag; return(answer); } return(null); }
public SC2APIProtocol.Action BuildGas(Unit cc) { Unit target = FindNearest(cc, UNIT_TYPEID.NEUTRAL_VESPENEGEYSER); if (target != null) { SC2APIProtocol.Action answer = CreateAction(cc, ABILITY_ID.BUILD_REFINERY); answer.ActionRaw.UnitCommand.TargetUnitTag = target.Tag; return(answer); } return(null); }
public SC2APIProtocol.Action GatherGas(Unit cc) { Unit target = FindNearest(cc, UNIT_TYPEID.TERRAN_REFINERY, true); if (target != null) { SC2APIProtocol.Action answer = CreateAction(cc, ABILITY_ID.HARVEST_GATHER_SCV); answer.ActionRaw.UnitCommand.TargetUnitTag = target.Tag; return(answer); } return(null); }
public static void FocusCamera(Vector3 Position) { var action = new Action(); action.ActionRaw = new ActionRaw(); action.ActionRaw.CameraMove = new ActionRawCameraMove(); action.ActionRaw.CameraMove.CenterWorldSpace = new Point(); action.ActionRaw.CameraMove.CenterWorldSpace.X = Position.X; action.ActionRaw.CameraMove.CenterWorldSpace.Y = Position.Y; action.ActionRaw.CameraMove.CenterWorldSpace.Z = Position.Z; Controller.AddAction(action); }
public SC2APIProtocol.Action BuildEngineering(Unit cc) { SC2APIProtocol.Action answer = CreateAction(cc, ABILITY_ID.BUILD_ENGINEERINGBAY); Point2D pos = FindPlaceable((int)cc.Pos.X, (int)cc.Pos.Y, 15, UNIT_TYPEID.TERRAN_ENGINEERINGBAY, true); if (pos != null) { logDebug("BuildEngineering at " + pos.ToString()); answer.ActionRaw.UnitCommand.TargetWorldSpacePos = pos; return(answer); } return(null); }
private void FocusCamera(Unit unit) { if (unit == null) { return; } SC2APIProtocol.Action action = new SC2APIProtocol.Action(); action.ActionRaw = new ActionRaw(); action.ActionRaw.CameraMove = new ActionRawCameraMove(); action.ActionRaw.CameraMove.CenterWorldSpace = new Point(); action.ActionRaw.CameraMove.CenterWorldSpace.X = unit.Pos.X; action.ActionRaw.CameraMove.CenterWorldSpace.Y = unit.Pos.Y; action.ActionRaw.CameraMove.CenterWorldSpace.Z = unit.Pos.Z; actions.Add(action); }
public void SetCamera(Point location) { var action = new SC2APIProtocol.Action { ActionRaw = new ActionRaw { CameraMove = new ActionRawCameraMove() { CenterWorldSpace = location } } }; SpawnRequest.Action = new RequestAction(); SpawnRequest.Action.Actions.Add(action); }
public SC2APIProtocol.Action TrainSCV(Unit cc) { if (!coolDownCommand.IsDelayed("TrainSCV")) { if (!cc.HasOrder(ABILITY_ID.TRAIN_SCV)) { coolDownCommand.Add(new CoolDownCommandData() { key = "TrainSCV", finishStep = gameLoop + 250 }); SC2APIProtocol.Action answer = CreateAction(cc, ABILITY_ID.TRAIN_SCV); return(answer); } } return(null); }
protected Action CreateRawUnitCommand(uint ability) { var action = new Action { ActionRaw = new ActionRaw { UnitCommand = new ActionRawUnitCommand { AbilityId = (int)ability, UnitTags = { UniqueId } }, } }; return(action); }
private async Task SendAttackRequest(Unit unit, Point2D point) { var action2 = new Action(); action2.ActionRaw = new ActionRaw(); action2.ActionRaw.UnitCommand = new ActionRawUnitCommand(); action2.ActionRaw.UnitCommand.AbilityId = 23; // Attack abilitiy action2.ActionRaw.UnitCommand.UnitTags.Add(unit.Tag); action2.ActionRaw.UnitCommand.TargetWorldSpacePos = point; var requestAction = new RequestAction(); requestAction.Actions.Add(action2); await _connectionService.SendRequestAsync(new Request { Action = requestAction }); }
public List <SC2APIProtocol.Action> UnloadSpecificUnit(int frame, Abilities ability, ulong targetTag, bool allowSpam = false) { if (!allowSpam && ability == LastAbility && targetTag == LastTargetTag && AbilityOrderTimes[ability] > frame - SpamFrames) { return(null); // if new action is exactly the same, don't do anything to prevent apm spam } var passenger = UnitCalculation.Unit.Passengers.Where(p => p.Tag == targetTag).FirstOrDefault(); if (passenger == null) { return(null); } var selectionCommand = new ActionRawUnitCommand(); selectionCommand.UnitTags.Add(UnitCalculation.Unit.Tag); selectionCommand.AbilityId = 0; var selectAction = new SC2APIProtocol.Action { ActionRaw = new ActionRaw { UnitCommand = selectionCommand }, }; var unloadAction = new SC2APIProtocol.Action { ActionUi = new ActionUI { CargoPanel = new ActionCargoPanelUnload { UnitIndex = UnitCalculation.Unit.Passengers.IndexOf(passenger) } }, }; LastAbility = ability; LastTargetLocation = null; LastTargetTag = targetTag; AbilityOrderTimes[ability] = frame; LastOrderFrame = frame; return(new List <SC2APIProtocol.Action> { selectAction, unloadAction }); }
public void Chat(string message, bool team = false) { ActionChat actionChat = new ActionChat(); if (team) { actionChat.Channel = ActionChat.Types.Channel.Team; } else { actionChat.Channel = ActionChat.Types.Channel.Broadcast; } actionChat.Message = message; SC2APIProtocol.Action action = new SC2APIProtocol.Action(); action.ActionChat = actionChat; AddAction(action); }
public SC2APIProtocol.Action Merge(ulong targetTag) { var command = new ActionRawUnitCommand(); command.AbilityId = (int)Abilities.MORPH_ARCHON; command.UnitTags.Add(UnitCalculation.Unit.Tag); command.UnitTags.Add(targetTag); var action = new SC2APIProtocol.Action { ActionRaw = new ActionRaw { UnitCommand = command } }; return(action); }