void setRallyPoint(Vector2 mousePosition) { List<ScheduledStructureTargetedCommand> scheduledActionBatch = new List<ScheduledStructureTargetedCommand>(); //float scheduledTime = gameClock + connection.AverageRoundtripTime; // rally to a resource foreach (Resource resource in Resource.Resources) { if (resource.Touches(mousePosition)) { foreach (RtsObject o in SelectedUnits) { if (o.Team != Player.Me.Team) return; Structure structure = o as Structure; if (structure != null && structure.Rallyable) { //if (!usingShift) // structure.RallyPoints.Clear(); //structure.RallyPoints.Add(new RallyPoint(resource.CenterPoint, resource)); ScheduledStructureTargetedCommand action = new ScheduledStructureTargetedCommand(currentScheduleTime, structure, CommandButtonType.RallyPoint, resource, resource.CenterPoint, usingShift); Player.Me.ScheduledActions.Add(action); scheduledActionBatch.Add(action); } } NetOutgoingMessage msg = netPeer.CreateMessage(); msg.Write(MessageID.RALLY_POINT_COMMAND); msg.Write(currentScheduleTime); msg.Write(Player.Me.Team); msg.Write(usingShift); msg.Write((short)scheduledActionBatch.Count); foreach (ScheduledStructureTargetedCommand action in scheduledActionBatch) { msg.Write(action.Structure.ID); msg.Write(((Resource)action.Target).ID); msg.Write(action.Point.X); msg.Write(action.Point.Y); } netPeer.SendMessage(msg, connection, NetDeliveryMethod.ReliableOrdered); return; } } // rally to a point foreach (RtsObject o in SelectedUnits) { if (o.Team != Player.Me.Team) continue; Structure s = o as Structure; if (s != null && s.Rallyable) { if (s.Contains(mousePosition)) { s.RallyPoints.Clear(); continue; } //if (!usingShift) // s.RallyPoints.Clear(); Vector2 rallyPoint; if (Rts.pathFinder.Tools.IsPointWalkable(mousePosition)) rallyPoint = mousePosition; else rallyPoint = Rts.pathFinder.Tools.FindNearestPathNode((int)(mousePosition.Y / map.TileSize), (int)(mousePosition.X / map.TileSize), s).Tile.CenterPoint; //s.RallyPoints.Add(new RallyPoint(rallyPoint, null)); ScheduledStructureTargetedCommand action = new ScheduledStructureTargetedCommand(currentScheduleTime, s, CommandButtonType.RallyPoint, null, rallyPoint, usingShift); Player.Me.ScheduledActions.Add(action); scheduledActionBatch.Add(action); } } NetOutgoingMessage m = netPeer.CreateMessage(); m.Write(MessageID.RALLY_POINT_COMMAND); m.Write(currentScheduleTime); m.Write(Player.Me.Team); m.Write(usingShift); m.Write((short)scheduledActionBatch.Count); foreach (ScheduledStructureTargetedCommand action in scheduledActionBatch) { m.Write(action.Structure.ID); m.Write((short)-1); m.Write(action.Point.X); m.Write(action.Point.Y); } netPeer.SendMessage(m, connection, NetDeliveryMethod.ReliableOrdered); }
void doScheduledActions() { foreach (Player player in Player.Players) { for (int i = 0; i < player.ScheduledActions.Count;) { ScheduledAction action = player.ScheduledActions[i]; if (action.ScheduledTime <= GameClock) { ScheduledReturnCargoCommand scheduledReturnCargoCommand = action as ScheduledReturnCargoCommand; if (scheduledReturnCargoCommand != null) { ((WorkerNublet)scheduledReturnCargoCommand.ReturnCargoCommand.Unit).ReturnCargoToNearestTownHall(scheduledReturnCargoCommand.ReturnCargoCommand.Source); player.ScheduledActions.Remove(action); continue; } ScheduledUnitCommand scheduledUnitCommand = action as ScheduledUnitCommand; if (scheduledUnitCommand != null) { MoveCommand moveCommand = scheduledUnitCommand.UnitCommand as MoveCommand; if (moveCommand != null) { if (scheduledUnitCommand.Queued) { scheduledUnitCommand.UnitCommand.Unit.QueueCommand(moveCommand); } else { scheduledUnitCommand.UnitCommand.Unit.GiveCommand(moveCommand); } } else { if (scheduledUnitCommand.Queued) { scheduledUnitCommand.UnitCommand.Unit.QueueCommand(scheduledUnitCommand.UnitCommand); } else { scheduledUnitCommand.UnitCommand.Unit.GiveCommand(scheduledUnitCommand.UnitCommand); } } } ScheduledUnitBuildCommand scheduledUnitBuildCommand = action as ScheduledUnitBuildCommand; if (scheduledUnitBuildCommand != null) { } ScheduledStructureCommand scheduledStructureCommand = action as ScheduledStructureCommand; if (scheduledStructureCommand != null) { // shouldnt happen but wtf //if (scheduledStructureCommand.Structure == null) // continue; if (scheduledStructureCommand.CommandType == CommandButtonType.RallyPoint) { ScheduledStructureTargetedCommand rallyPointCommand = action as ScheduledStructureTargetedCommand; if (!rallyPointCommand.Queued) { rallyPointCommand.Structure.RallyPoints.Clear(); } rallyPointCommand.Structure.RallyPoints.Add(new RallyPoint(rallyPointCommand.Point, (Resource)rallyPointCommand.Target)); } else if (scheduledStructureCommand.CommandType == CommandButtonType.Cancel) { if (scheduledStructureCommand.Structure.UnderConstruction) { scheduledStructureCommand.Structure.Cancel(); } else { if (scheduledStructureCommand.Index >= 0) { scheduledStructureCommand.Structure.RemoveFromBuildQueue(scheduledStructureCommand.Index); } else { scheduledStructureCommand.Structure.RemoveLastItemInBuildQueue(); } } } else { scheduledStructureCommand.Structure.AddToBuildQueue((ProductionButtonType)scheduledStructureCommand.CommandType, scheduledStructureCommand.ID); } } player.ScheduledActions.Remove(action); } else { i++; } } } }