/// <summary> /// Identify the weakest enemy point at the front and send enough units there /// to make a nice dent. /// </summary> private void AttackWeakestFrontPoint() { //First, find the weakest enemy point Building target = GetWeakestPoint(); //Then find the strongest friendly point Building source = GetStrongestFriendlyBuilding(); UnitController.MoveUnits(this, Util.GetTileAt(source.GetPosition(), m_view.world), Util.GetTileAt(target.GetPosition(), m_view.world), source.GetUnits().Count); }
/// <summary> /// /// </summary> /// <param name="previousSelection"></param> private void TileMenu() { MenuIcon moveUnits = new MenuIcon(Language.Instance.GetString("MoveUnits"), null, Color.Black); MenuIcon cancel = new MenuIcon(Language.Instance.GetString("Cancel"), Recellection.textureMap.GetTexture(Globals.TextureTypes.No), Color.Black); List <MenuIcon> menuIcons = new List <MenuIcon>(); if (theWorld.GetMap().GetTile(previousSelection.absPoint).GetUnits(playerInControll).Count > 0) { // Only show this options if there are units. menuIcons.Add(moveUnits); } menuIcons.Add(cancel); Menu buildingMenu = new Menu(Globals.MenuLayout.FourMatrix, menuIcons, Language.Instance.GetString("TileMenu"), Color.Black); MenuController.LoadMenu(buildingMenu); Recellection.CurrentState = MenuView.Instance; MenuIcon choosenMenu = MenuController.GetInput(); Recellection.CurrentState = WorldView.Instance; MenuController.UnloadMenu(); if (choosenMenu == moveUnits) { Selection currSel = retrieveSelection(); if (!(currSel.state == State.TILE || currSel.state == State.BUILDING)) { return; } Tile from = theWorld.GetMap().GetTile(previousSelection.absPoint); SelectTile(theWorld.GetMap().GetTile(currSel.absPoint)); UnitController.MoveUnits(playerInControll, from, selectedTile, from.GetUnits().Count); } }
/// <param name="numberOfUnits">The number of units to move.</param> /// <param name="from">From what fromBuilding to move.</param> /// <param name="to">Destination for the units.</param> private void MoveUnits(int numberOfUnits, Building from, Building to) { UnitController.MoveUnits(from.owner, from.controlZone.First.Value, to.controlZone.First.Value, numberOfUnits); }
/// <summary> /// Loads the Building menu from a selection. /// Must have building on tile. /// </summary> /// <param name="theSelection"></param> private void BuildingMenu() { World.Map map = theWorld.GetMap(); Building building = selectedTile.GetBuilding(); if (building == null || building.owner != playerInControll) { return; } int toHeal = Math.Min(building.maxHealth - building.currentHealth, building.units.Count()); MenuIcon setWeight = new MenuIcon(Language.Instance.GetString("SetWeight")); MenuIcon buildCell = new MenuIcon(Language.Instance.GetString("BuildCell")); MenuIcon removeCell = new MenuIcon(Language.Instance.GetString("RemoveCell")); MenuIcon upgradeUnits = new MenuIcon(Language.Instance.GetString("UpgradeUnits") + " (" + playerInControll.unitAcc.GetUpgradeCost() + ")"); MenuIcon moveUnits = new MenuIcon(Language.Instance.GetString("MoveUnits")); MenuIcon repairCell = new MenuIcon(Language.Instance.GetString("RepairCell") + " (" + toHeal + ")"); MenuIcon setAggro = new MenuIcon(Language.Instance.GetString("SetAggro")); MenuIcon Cancel = new MenuIcon(Language.Instance.GetString("Cancel"), Recellection.textureMap.GetTexture(Globals.TextureTypes.No)); List <MenuIcon> menuIcons = new List <MenuIcon>(); menuIcons.Add(setWeight); menuIcons.Add(buildCell); menuIcons.Add(removeCell); menuIcons.Add(upgradeUnits); menuIcons.Add(moveUnits); menuIcons.Add(repairCell); menuIcons.Add(setAggro); menuIcons.Add(Cancel); Menu buildingMenu = new Menu(Globals.MenuLayout.NineMatrix, menuIcons, Language.Instance.GetString("BuildingMenu"), Color.Black); MenuController.LoadMenu(buildingMenu); Recellection.CurrentState = MenuView.Instance; MenuIcon choosenMenu = MenuController.GetInput(); Recellection.CurrentState = WorldView.Instance; MenuController.UnloadMenu(); if (choosenMenu.Equals(setWeight)) { GraphController.Instance.SetWeight(building); } else if (choosenMenu.Equals(buildCell)) { tobii.SetFeedbackColor(Color.DarkGreen); Selection destsel; do { SetConstructionLines(BuildingController.GetValidBuildingInterval(selectedTile.position, theWorld)); destsel = retrieveSelection(); RemoveconstructionTileLines(BuildingController.GetValidBuildingInterval(selectedTile.position, theWorld)); }while (destsel.state != State.TILE); tobii.SetFeedbackColor(Color.White); SelectTile(map.GetTile(destsel.absPoint)); //TODO Add a check to see if the tile is a correct one. The diffrence between the selected tiles coordinates and the source building shall not exceed 3. if (selectedTile.GetBuilding() == null) { try { BuildingController.ConstructBuilding(playerInControll, selectedTile, building, theWorld); tobii.SetFeedbackColor(Color.White); } catch (BuildingController.BuildingOutOfRangeException) { logger.Debug("Caught BuildingOutOfRangeExcpetion"); } } else { //SoundsController.playSound("Denied"); tobii.SetFeedbackColor(Color.White); return; } } else if (choosenMenu.Equals(removeCell)) { BuildingController.RemoveBuilding(building); } else if (choosenMenu.Equals(upgradeUnits)) { upgradeMenu(); } else if (choosenMenu.Equals(moveUnits)) { tobii.SetFeedbackColor(Color.Red); Selection destsel = retrieveSelection(); if (destsel.state == State.BUILDING || destsel.state == State.TILE) { Tile selTile = map.GetTile(destsel.absPoint); UnitController.MoveUnits(playerInControll, selectedTile, selTile, building.GetUnits().Count); } tobii.SetFeedbackColor(Color.White); } else if (choosenMenu.Equals(repairCell)) { playerInControll.unitAcc.DestroyUnits(building.units, toHeal); building.Repair(toHeal); } else if (choosenMenu.Equals(setAggro)) { building.IsAggressive = !building.IsAggressive; building.UpdateAggressiveness(null, new Event <IEnumerable <Unit> >(building.GetUnits(), EventType.ADD)); } else if (choosenMenu.Equals(Cancel)) { return; } else { return; } }