/// <summary> /// Tries to get the most productive [productivity / commerce / food] vacant location on the city radius; /// doesn't include the city itself. /// </summary> /// <returns>The <see cref="MapSquarePivot"/> location; <c>Null</c> if no location available.</returns> internal MapSquarePivot BestVacantMapSquareLocation() { return(Player.ComputeCityAvailableMapSquares(this) .Where(x => !AreaWithoutCityMapSquares.Any(ams => ams.MapSquare == x)) .OrderByDescending(x => x.TotalValue) .FirstOrDefault()); }
/// <summary> /// Removes any citizen, starting with specialists if any. /// </summary> /// <param name="recheck">Optionnal; proceeds to <see cref="ResetCitizens()"/> after removing.</param> internal void RemoveAnyCitizen(bool recheck = false) { if (_specialistCitizens.Count > 0) { _specialistCitizens.RemoveAt(0); } else { _areaMapSquares.Remove(AreaWithoutCityMapSquares.First()); } if (recheck) { ResetCitizens(); } }
/// <summary> /// Recomputes the happiness of every citizens. /// </summary> internal void CheckCitizensHappiness() { var nonSpecialistFaces = CitizensCount - _specialistCitizens.Count; var unhappyFaces = nonSpecialistFaces - CONTENT_CITIZENS_COUNT; if (Player.WonderIsActive(WonderPivot.ShakespeareTheatre) && _wonders.Contains(WonderPivot.ShakespeareTheatre)) { unhappyFaces *= SHAKESPEARE_THEATRE_HAPPINESS_RATE; } if (Player.WonderIsActive(WonderPivot.JsBachsCathedral, MapSquareLocation)) { unhappyFaces -= JSBACHS_WONDER_HAPPINESS_EFFECT; } var cathedralEffect = _improvements.Contains(CityImprovementPivot.Cathedral) ? CATHEDRAL_HAPPINESS_EFFECT : 0; if (Player.WonderIsActive(WonderPivot.MichelangeloChapel)) { cathedralEffect = (int)(cathedralEffect * MICHELANGELO_CHAPEL_HAPPINESS_EFFECT); } var templeEffect = _improvements.Contains(CityImprovementPivot.Temple) ? TEMPLE_HAPPINESS_EFFECT : 0; if (Player.Advances.Contains(AdvancePivot.Mysticism)) { templeEffect *= MYSTICISM_ADVANCE_HAPPINESS_RATE; } if (Player.WonderIsActive(WonderPivot.Oracle)) { templeEffect *= ORACLE_WONDER_HAPPINESS_RATE; } // transforms unhappy in content. var contentEffects = new List <int> { templeEffect, cathedralEffect, _improvements.Contains(CityImprovementPivot.Colosseum) ? COLOSSEUM_HAPPINESS_EFFECT : 0, _garrison.Where(u => u.IsMilitary).Take(Player.Regime.MartialLawUnitCount).Count() }; // transforms content into happy. var happinessEffects = new List <int> { Luxury *LUXURY_TO_HAPPY_CITIZEN_RATE, Player.WonderIsActive(WonderPivot.CureForCancer) ? CUREFORCANCER_WONDER_HAPPINESS_EFFECT : 0, Player.WonderIsActive(WonderPivot.HangingGardens) ? HANGING_GARDENS_WONDER_HAPPINESS_EFFECT : 0 }; var happyFaces = happinessEffects.Sum(); if (happyFaces < nonSpecialistFaces) { // Not full happy : count of content OR unhappy. var remaniningFaces = nonSpecialistFaces - happyFaces; // Count of unhappy after content effects. unhappyFaces -= contentEffects.Sum(); if (unhappyFaces < 0) { // Overflow of content effect. unhappyFaces = 0; } else if (unhappyFaces > remaniningFaces) { // Just in case... unhappyFaces = remaniningFaces; } } else { // Full happy (0 unhappy, 0 content). unhappyFaces = 0; } var citizensToCheck = AreaWithoutCityMapSquares.Select(ams => ams.Citizen); foreach (var citizen in citizensToCheck) { if (happyFaces > 0) { citizen.Happiness = HappinessPivot.Happy; happyFaces--; } else if (unhappyFaces > 0) { citizen.Happiness = HappinessPivot.Unhappy; unhappyFaces--; } else { citizen.Happiness = HappinessPivot.Content; } } }