void processStructureCommand(NetIncomingMessage msg) { float scheduledTime = msg.ReadFloat(); short team = msg.ReadInt16(); short structureID = msg.ReadInt16(); short commandTypeID = msg.ReadInt16(); short unitID = msg.ReadInt16(); short index = msg.ReadInt16(); Structure structure = Player.Players[team].StructureArray[structureID]; CommandButtonType commandType = CommandButtonType.CommandButtonTypes[commandTypeID]; if (structure == null) { int wut = 0; } if (index >= 0) { ScheduledStructureCommand command = new ScheduledStructureCommand(scheduledTime, structure, commandType); command.Index = index; Player.Players[team].ScheduledActions.Add(command); } else { Player.Players[team].ScheduledActions.Add(new ScheduledStructureCommand(scheduledTime, structure, commandType, unitID)); } if (unitID >= 0) { Player.Players[team].UnitArray[unitID] = Unit.Reserved; } }
// ignores targeted commands, which is currently only rally point commands public int CountScheduledStructureCommands(Structure structure) { int count = 0; foreach (ScheduledAction action in ScheduledActions) { ScheduledStructureCommand structureCommand = action as ScheduledStructureCommand; if (structureCommand != null && !(structureCommand is ScheduledStructureTargetedCommand) && structureCommand.Structure == structure) { count++; } } return(count); }
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++; } } } }
void checkForLeftClick(GameTime gameTime) { // check if clicked on unit portrait if (SelectedUnits.Count == 1) { if (mouseState.LeftButton == ButtonState.Pressed && unitPictureRectangle.Contains(mouseState.X, mouseState.Y)) { centerCameraOnSelectedUnits(); return; } } // check if clicked on a unit box foreach (UnitButton box in unitButtons) { if (box.Triggered) { // holding shift if (usingShift) { SelectedUnits.Remove(box.Unit); } // not holding shift else { SelectedUnits.Clear(); SelectedUnits.Add(box.Unit); } selectedUnitsChanged = true; return; } } //check if clicked on structure queue item if (QueuedItems != null) { if (mouseState.LeftButton == ButtonState.Released) { allowRemoveFromQueue = true; } else if (allowRemoveFromQueue) { allowRemoveFromQueue = false; //foreach (SimpleButton item in QueuedItems) for (int i = 0; i < QueuedItems.Length; i++) { Structure s = SelectedUnits[0] as Structure; if (mouseState.LeftButton == ButtonState.Pressed && QueuedItems[i].Contains(mouseState.X, mouseState.Y) && s.BuildQueue.Count > i) //if (QueuedItems[i].Triggered) { //s.BuildQueue.RemoveAt(i); s.RemoveFromBuildQueue(i); ScheduledStructureCommand cancelCommand = new ScheduledStructureCommand(currentScheduleTime, s, CommandButtonType.Cancel); cancelCommand.Index = (short)i; Player.Me.ScheduledActions.Add(cancelCommand); TransmitStructureCommand(s, cancelCommand.CommandType, short.MinValue, (short)i); } } } } if ((usingTargetedCommand && mouseState.LeftButton == ButtonState.Pressed) || selecting) { allowMiniMapClick = false; } else if (mouseState.LeftButton == ButtonState.Released) { allowMiniMapClick = true; } // clicked on bottom ui if (mouseState.Y > worldViewport.Height) { if (!selecting) { SelectBox.Enabled = false; //SelectBox.Clear(); //SelectingUnits.Clear(); } if (mouseState.LeftButton == ButtonState.Pressed) { if (minimap.Contains(mouseState.X, mouseState.Y)) { if (allowMiniMapClick) { //Vector2 mousePosition = Vector2.Transform(new Vector2((mouseState.X - minimapPosX) / minimapToMapRatioX, (mouseState.Y - minimapPosY) / minimapToMapRatioY), camera.get_transformation(worldViewport)); Vector2 mousePosition = new Vector2(mouseState.X, mouseState.Y); Vector2 minimapCenterPoint = new Vector2(minimap.X + minimap.Width / 2f, minimap.Y + minimap.Height / 2f); float distance = Vector2.Distance(mousePosition, minimapCenterPoint); float angle = (float)Math.Atan2(mousePosition.Y - minimapCenterPoint.Y, mousePosition.X - minimapCenterPoint.X); mousePosition = new Vector2(minimapCenterPoint.X + distance * (float)Math.Cos(angle - camera.Rotation), minimapCenterPoint.Y + distance * (float)Math.Sin(angle - camera.Rotation)); camera.Pos = new Vector2((mousePosition.X - minimapPosX) / minimapToMapRatioX, (mousePosition.Y - minimapPosY) / minimapToMapRatioY); //Matrix transform = camera.get_minimap_transformation(minimapViewport); //Vector2 mousePosition = Vector2.Transform(new Vector2(mouseState.X - minimapPosX, mouseState.Y - minimapPosY), transform); //camera.Pos = new Vector2((mouseState.X - minimapPosX) / minimapToMapRatioX, (mouseState.Y - minimapPosY) / minimapToMapRatioY); //float asdf = minimapToMapRatioX - minimapToMapRatioY; //float smallest = minimapToMapRatioY; //camera.Pos = new Vector2(mousePosition.X / minimapToMapRatioX, mousePosition.Y / minimapToMapRatioY); //camera.Pos = mousePosition; stopTargetedCommands(); } } else { stopTargetedCommands(); //SimpleButton.PressingHotkey = false; } } } // clicked somewhere above bottom ui else { if (mouseState.LeftButton == ButtonState.Released) { SelectBox.Enabled = true; } } if (usingTargetedCommand) { if (mouseState.LeftButton == ButtonState.Released) { allowTargetedCommand = true; } else if (allowTargetedCommand && mouseState.LeftButton == ButtonState.Pressed) { allowTargetedCommand = false; allowSelect = false; SelectBox.Enabled = false; Vector2 mousePosition = new Vector2(mouseState.X, mouseState.Y); if (minimap.Contains(mouseState.X, mouseState.Y)) { mousePosition = new Vector2((mousePosition.X - minimapPosX) / minimapToMapRatioX, (mousePosition.Y - minimapPosY) / minimapToMapRatioY); } else { mousePosition = Vector2.Transform(mousePosition, Matrix.Invert(camera.get_transformation(worldViewport))); } if (usingAttackCommand) { giveAttackCommand(mousePosition); } else if (usingRallyPointCommand) { setRallyPoint(mousePosition); } if (usingShift) { queueingTargetedCommand = true; } else { stopTargetedCommands(); } } } else if (placingStructure) { if (mouseState.LeftButton == ButtonState.Released) { allowClickToPlaceStructure = true; } else if (allowClickToPlaceStructure && mouseState.LeftButton == ButtonState.Pressed) { allowClickToPlaceStructure = false; allowSelect = false; SelectBox.Enabled = false; if (allowPlacingStructure) { //new Barracks(placingStructureLocation, myTeam); giveBuildCommand(); if (usingShift) { queueingPlacingStructure = true; } else { placingStructure = false; } } else { playErrorSound(); } } } else { if (mouseState.LeftButton == ButtonState.Released) { allowSelect = true; SelectBox.Enabled = true; } if (allowSelect) { SelectUnits(gameTime); } } }