public List <IUnitCommand> GetCommandsForUnit(IUnit unit, InfluenceMaps maps) { var unitLocation = UnitPositionCanon.GetOwnerOfPossession(unit); var reachableCellsByDistance = HexPathfinder.GetAllCellsReachableIn( unitLocation, unit.CurrentMovement, UnitPositionCanon.GetPathfindingCostFunction(unit, false), Grid.Cells ); var validCandidates = reachableCellsByDistance.Keys.Where(cell => UnitPositionCanon.CanPlaceUnitAtLocation(unit, cell, false)); IHexCell bestCandidate = validCandidates.MaxElement(BrainTools.GetFleeWeightFunction(unit, maps)); var retval = new List <IUnitCommand>(); if (bestCandidate != null) { var moveCommand = Container.Instantiate <MoveUnitCommand>(); moveCommand.UnitToMove = unit; moveCommand.DesiredLocation = bestCandidate; retval.Add(moveCommand); } return(retval); }
private void OnCityPointerEntered(ICity city) { if (!IsDragging) { return; } if (CombatExecuter.CanPerformMeleeAttack(SelectedUnit, city.CombatFacade)) { SetCityToAttack(city); return; } var cityLocation = CityLocationCanon.GetOwnerOfPossession(city); if (UnitPositionCanon.CanPlaceUnitAtLocation(SelectedUnit, cityLocation, false)) { var selectedUnitLocation = UnitPositionCanon.GetOwnerOfPossession(SelectedUnit); SetProspectiveTravelGoal(selectedUnitLocation, cityLocation); } else { Clear(); } }
public Func <IHexCell, int> GetWanderWeightFunction(IUnit unit, InfluenceMaps maps) { var unitLocation = UnitPositionCanon.GetOwnerOfPossession(unit); return(delegate(IHexCell cell) { if (cell == unitLocation || !UnitPositionCanon.CanPlaceUnitAtLocation(unit, cell, false)) { return 0; } else { float fromDistance = Grid.GetDistance(cell, unitLocation) * BarbarianConfig.WanderSelectionWeight_Distance; float fromAllies = -maps.AllyPresence [cell.Index] * BarbarianConfig.WanderSelectionWeight_Allies; float fromEnemies = -maps.EnemyPresence[cell.Index] * BarbarianConfig.WanderSelectionWeight_Enemies; return Math.Max(0, Mathf.RoundToInt(fromDistance + fromAllies + fromEnemies)); } }); }