public bool AssignTroopToTile(Troop t) { List<PlanetGridSquare> list = new List<PlanetGridSquare>(); foreach (PlanetGridSquare planetGridSquare in this.TilesList) { if (planetGridSquare.TroopsHere.Count < planetGridSquare.number_allowed_troops && (planetGridSquare.building == null || planetGridSquare.building != null && planetGridSquare.building.CombatStrength == 0)) list.Add(planetGridSquare); } if (list.Count > 0) { int index = (int)RandomMath.RandomBetween(0.0f, (float)list.Count); PlanetGridSquare planetGridSquare = list[index]; foreach (PlanetGridSquare eventLocation in this.TilesList) { if (eventLocation == planetGridSquare) { eventLocation.TroopsHere.Add(t); this.TroopsHere.Add(t); t.SetPlanet(this); if (eventLocation.building == null || string.IsNullOrEmpty(eventLocation.building.EventTriggerUID) || (eventLocation.TroopsHere.Count <= 0 || eventLocation.TroopsHere[0].GetOwner().isFaction)) return true; ResourceManager.EventsDict[eventLocation.building.EventTriggerUID].TriggerPlanetEvent(this, eventLocation.TroopsHere[0].GetOwner(), eventLocation, EmpireManager.GetEmpireByName(Planet.universeScreen.PlayerLoyalty), Planet.universeScreen); } } } return false; }
public bool AssignTroopToNearestAvailableTile(Troop t, PlanetGridSquare tile) { List<PlanetGridSquare> list = new List<PlanetGridSquare>(); foreach (PlanetGridSquare planetGridSquare in this.TilesList) { if (planetGridSquare.TroopsHere.Count < planetGridSquare.number_allowed_troops && (planetGridSquare.building == null || planetGridSquare.building != null && planetGridSquare.building.CombatStrength == 0) && (Math.Abs(tile.x - planetGridSquare.x) <= 1 && Math.Abs(tile.y - planetGridSquare.y) <= 1)) list.Add(planetGridSquare); } if (list.Count > 0) { int index = (int)RandomMath.RandomBetween(0.0f, (float)list.Count); PlanetGridSquare planetGridSquare1 = list[index]; foreach (PlanetGridSquare planetGridSquare2 in this.TilesList) { if (planetGridSquare2 == planetGridSquare1) { planetGridSquare2.TroopsHere.Add(t); this.TroopsHere.Add(t); t.SetPlanet(this); return true; } } } return false; }