// get all buildings from selectionbox public List <IGameActionHolder> SelectBuildings() { List <IGameActionHolder> selected; if (DistanceCalculator.DiagonalDistance(topLeft, bottomRight) < 0.5) { selected = new List <IGameActionHolder>(); WorldCellModel cell = Game.GameModel.World.GetCellFromCoords((Coords)topLeft).worldCellModel; if (cell.BuildingOnTop != null) { selected.Add(cell.BuildingOnTop); } } else { // TODO optimise selected = (from item in Game.PlayerFaction.FactionModel.Buildings where topLeft.x <= item.StartCoords.x + (item.Width / 2) && topLeft.y <= item.StartCoords.y + (item.Height / 2) && bottomRight.x >= item.StartCoords.x + (item.Width / 2) && bottomRight.y >= item.StartCoords.y + (item.Height / 2) select item).Cast <IGameActionHolder>().ToList(); } return(selected); }
public void Update(object sender, OnTickEventArgs eventArgs) { if (!Waypoints.Any()) { return; } float speed = LocationModel.Parent.UnitModel.Speed; if (DistanceCalculator.DiagonalDistance(Waypoints.Peek(), LocationModel.FloatCoords) < speed) { // Arrived near destination LocationModel.FloatCoords = Waypoints.Dequeue(); if (!Waypoints.Any()) { MoveComplete?.Invoke(this, new EventArgsWithPayload <FloatCoords>(LocationModel.FloatCoords)); } return; } float xDifference = (float)DistanceCalculator.CalcDistance(LocationModel.FloatCoords.x, Waypoints.Peek().x); float yDifference = (float)DistanceCalculator.CalcDistance(LocationModel.FloatCoords.y, Waypoints.Peek().y); // calculate new coords float diagonalDifference = (float)DistanceCalculator.Pythagoras(xDifference, yDifference); float v = diagonalDifference / speed; FloatCoords difference = new FloatCoords { x = xDifference / v, y = yDifference / v }; difference.x = Waypoints.Peek().x < LocationModel.FloatCoords.x ? -difference.x : difference.x; difference.y = Waypoints.Peek().y < LocationModel.FloatCoords.y ? -difference.y : difference.y; LocationModel.FloatCoords = new FloatCoords() { x = LocationModel.FloatCoords.x + difference.x, y = LocationModel.FloatCoords.y + difference.y }; }
/// <summary> /// sets everything within viewrange from the coords to the specified viewmode /// </summary> /// <param name="mode"></param> /// <param name="viewrange"></param> /// <param name="coords"></param> public void UpdateViewMode(ViewMode mode, int viewrange, FloatCoords coords) { // loop from -viewrange to + viewrange for (int x = (viewrange) * -1; x <= viewrange; x++) { for (int y = (viewrange) * -1; y <= viewrange; y++) { // set coords relative to the given coords Coords tempcoords = (Coords) new FloatCoords { x = x + coords.x, y = y + coords.y }; // check if the coords are within viewrange if (!(DistanceCalculator.DiagonalDistance((FloatCoords)tempcoords, coords) < viewrange)) { continue; } // get the cell from the tempcoords WorldCellController cellController = worldController.GetCellFromCoords(tempcoords); // check if the cellcontroller exists if (cellController == null) { continue; } // set the viewmode cellController.ChangeViewMode(mode); // check if there is a building in the cell if (cellController.worldCellModel.BuildingOnTop == null) { continue; } // set viewmode of the building on the cell if (cellController.worldCellModel.BuildingOnTop.GetType() == typeof(BuildingController)) { ((BuildingController)cellController.worldCellModel.BuildingOnTop).BuildingView.ViewMode = mode; } // set viewmode of the ConstructingBuilding on the cell if (cellController.worldCellModel.BuildingOnTop.GetType() == typeof(ConstructingBuildingController)) { ((ConstructingBuildingController)cellController.worldCellModel.BuildingOnTop).ConstructingBuildingView.ViewMode = mode; } } } }
// selects units in selectionbox public List <IGameActionHolder> SelectUnits() { List <UnitController> selected; if (DistanceCalculator.DiagonalDistance(topLeft, bottomRight) < 0.5) { selected = (from Item in Game.PlayerFaction.FactionModel.Units where DistanceCalculator.DiagonalDistance(topLeft, Item.LocationController.LocationModel.FloatCoords) < 0.5 || DistanceCalculator.DiagonalDistance(topLeft, Item.LocationController.LocationModel.FloatCoords) < Item.UnitView.Height select Item).ToList(); } else { selected = (from Item in Game.PlayerFaction.FactionModel.Units where topLeft.x <= Item.LocationController.LocationModel.Coords.x + (Item.UnitView.Width / 2) && topLeft.y <= Item.LocationController.LocationModel.Coords.y + (Item.UnitView.Height / 2) && bottomRight.x >= Item.LocationController.LocationModel.Coords.x + (Item.UnitView.Width / 2) && bottomRight.y >= Item.LocationController.LocationModel.Coords.y + (Item.UnitView.Height / 2) select Item).ToList(); } return(selected.Cast <IGameActionHolder>().ToList()); }