Skip to content

Commit

Permalink
Fix code style according to new rule set
Browse files Browse the repository at this point in the history
  • Loading branch information
dymanoid committed May 3, 2019
1 parent 62233e8 commit 57d7627
Show file tree
Hide file tree
Showing 39 changed files with 139 additions and 349 deletions.
6 changes: 2 additions & 4 deletions src/RealTime/Core/Compatibility.cs
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,7 @@ public bool AreAnyIncompatibleModsActive(out string message)
/// <returns><c>true</c> if a mod with any of the specified Workshop ID is currently installed and enabled;
/// otherwise, <c>false</c>.</returns>
public bool IsAnyModActive(ulong modId, params ulong[] furtherModIds)
{
return activeMods.ContainsKey(modId) || furtherModIds?.Any(activeMods.ContainsKey) == true;
}
=> activeMods.ContainsKey(modId) || furtherModIds?.Any(activeMods.ContainsKey) == true;

private List<string> GetIncompatibleModNames()
{
Expand All @@ -103,7 +101,7 @@ private List<string> GetIncompatibleModNames()
private void Initialize()
{
activeMods.Clear();
foreach (PluginManager.PluginInfo plugin in PluginManager.instance.GetPluginsInfo().Where(m => m.isEnabled))
foreach (var plugin in PluginManager.instance.GetPluginsInfo().Where(m => m.isEnabled))
{
activeMods[plugin.publishedFileID.AsUInt64] = plugin;
}
Expand Down
15 changes: 5 additions & 10 deletions src/RealTime/Core/RealTimeCore.cs
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ public void Stop()
ParkPatches.SpareTimeBehavior = null;
OutsideConnectionAIPatch.SpareTimeBehavior = null;

Log.Info($"The 'Real Time' mod reverts method patches.");
Log.Info("The 'Real Time' mod reverts method patches.");
patcher.Revert();

vanillaEvents.Revert();
Expand Down Expand Up @@ -422,28 +422,23 @@ private static bool SetupCustomAI(
}

private static void CustomTimeBarCityEventClick(object sender, CustomTimeBarClickEventArgs e)
{
CameraHelper.NavigateToBuilding(e.CityEventBuildingId, true);
}
=> CameraHelper.NavigateToBuilding(e.CityEventBuildingId, true);

private static void LoadStorageData(IEnumerable<IStorageData> storageData, StorageBase storage)
{
foreach (IStorageData item in storageData)
foreach (var item in storageData)
{
storage.Deserialize(item);
Log.Debug(LogCategory.Generic, "The 'Real Time' mod loaded its data from container " + item.StorageDataId);
}
}

private void CityEventsChanged(object sender, EventArgs e)
{
timeBar.UpdateEventsDisplay(eventManager.CityEvents);
}
private void CityEventsChanged(object sender, EventArgs e) => timeBar.UpdateEventsDisplay(eventManager.CityEvents);

private void GameSaving(object sender, EventArgs e)
{
var storage = (StorageBase)sender;
foreach (IStorageData item in storageData)
foreach (var item in storageData)
{
storage.Serialize(item);
Log.Debug(LogCategory.Generic, "The 'Real Time' mod stored its data in the current game for container " + item.StorageDataId);
Expand Down
2 changes: 1 addition & 1 deletion src/RealTime/Core/RealTimeMod.cs
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ public override void OnLevelUnloading()

if (core != null)
{
Log.Info($"The 'Real Time' mod stops.");
Log.Info("The 'Real Time' mod stops.");
core.Stop();
core = null;
}
Expand Down
2 changes: 1 addition & 1 deletion src/RealTime/CustomAI/CitizenSchedule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ public void Read(byte[] source, long referenceTime)
int minutes = source[2] + (source[3] << 8);
ScheduledStateTime = minutes == 0
? default
: new DateTime((minutes * TimeSpan.TicksPerMinute) + referenceTime);
: new DateTime(minutes * TimeSpan.TicksPerMinute + referenceTime);

int travelTime = source[4] + (source[5] << 8);
TravelTimeToWork = travelTime / TravelTimeMultiplier;
Expand Down
27 changes: 8 additions & 19 deletions src/RealTime/CustomAI/RealTimeBuildingAI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -279,10 +279,7 @@ public void ProcessFrame(uint frameIndex)
/// <returns>
/// <c>true</c> if the lights should be switched off in the specified building; otherwise, <c>false</c>.
/// </returns>
public bool ShouldSwitchBuildingLightsOff(ushort buildingId)
{
return config.SwitchOffLightsAtNight && !lightStates[buildingId];
}
public bool ShouldSwitchBuildingLightsOff(ushort buildingId) => config.SwitchOffLightsAtNight && !lightStates[buildingId];

/// <summary>
/// Determines whether the building with the specified ID is an entertainment target.
Expand Down Expand Up @@ -327,10 +324,7 @@ public bool IsEntertainmentTarget(ushort buildingId)
/// <returns>
/// <c>true</c> if the building with specified ID is currently active; otherwise, <c>false</c>.
/// </returns>
public bool IsBuildingActive(ushort buildingId)
{
return buildingManager.BuildingHasFlags(buildingId, Building.Flags.Active);
}
public bool IsBuildingActive(ushort buildingId) => buildingManager.BuildingHasFlags(buildingId, Building.Flags.Active);

/// <summary>
/// Determines whether the building with the specified <paramref name="buildingId"/> is noise restricted
Expand Down Expand Up @@ -392,10 +386,7 @@ public void RegisterReachingTrouble(ushort buildingId)
/// <param name="buildingId">The ID of the building to get the reaching trouble factor of.</param>
/// <returns>A value in range 0 to 1 that describes how many troubles have citizens while trying to reach
/// the building.</returns>
public float GetBuildingReachingTroubleFactor(ushort buildingId)
{
return reachingTroubles[buildingId] / 255f;
}
public float GetBuildingReachingTroubleFactor(ushort buildingId) => reachingTroubles[buildingId] / 255f;

private static int GetAllowedConstructingUpradingCount(int currentBuildingCount)
{
Expand All @@ -406,21 +397,19 @@ private static int GetAllowedConstructingUpradingCount(int currentBuildingCount)

if (currentBuildingCount < ConstructionRestrictionThreshold2)
{
return ConstructionRestrictionStep1 + (currentBuildingCount / ConstructionRestrictionScale2);
return ConstructionRestrictionStep1 + currentBuildingCount / ConstructionRestrictionScale2;
}

if (currentBuildingCount < ConstructionRestrictionThreshold3)
{
return ConstructionRestrictionStep2 + (currentBuildingCount / ConstructionRestrictionScale3);
return ConstructionRestrictionStep2 + currentBuildingCount / ConstructionRestrictionScale3;
}

return MaximumBuildingsInConstruction;
}

private bool IsBuildingCompletedOrMissing(ushort buildingId)
{
return buildingManager.BuildingHasFlags(buildingId, Building.Flags.Completed | Building.Flags.Deleted, includeZero: true);
}
=> buildingManager.BuildingHasFlags(buildingId, Building.Flags.Completed | Building.Flags.Deleted, includeZero: true);

private void UpdateLightState()
{
Expand All @@ -440,7 +429,7 @@ private void UpdateLightState()
private void UpdateReachingTroubles(uint step)
{
ushort first = (ushort)(step * BuildingStepSize);
ushort last = (ushort)(((step + 1) * BuildingStepSize) - 1);
ushort last = (ushort)((step + 1) * BuildingStepSize - 1);

for (ushort i = first; i <= last; ++i)
{
Expand All @@ -456,7 +445,7 @@ private void UpdateReachingTroubles(uint step)
private void UpdateLightState(ushort step, bool updateBuilding)
{
ushort first = (ushort)(step * BuildingStepSize);
ushort last = (ushort)(((step + 1) * BuildingStepSize) - 1);
ushort last = (ushort)((step + 1) * BuildingStepSize - 1);

for (ushort i = first; i <= last; ++i)
{
Expand Down
6 changes: 2 additions & 4 deletions src/RealTime/CustomAI/RealTimeHumanAIBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ protected RealTimeHumanAIBase(RealTimeConfig config, GameConnections<TCitizen> c
protected bool EnsureCitizenCanBeProcessed(uint citizenId, ref TCitizen citizen)
{
if (CitizenProxy.IsEmpty(ref citizen)
|| (CitizenProxy.HasFlags(ref citizen, Citizen.Flags.MovingIn) && CitizenProxy.GetLocation(ref citizen) == Citizen.Location.Home))
|| CitizenProxy.HasFlags(ref citizen, Citizen.Flags.MovingIn) && CitizenProxy.GetLocation(ref citizen) == Citizen.Location.Home)
{
CitizenMgr.ReleaseCitizen(citizenId);
return false;
Expand Down Expand Up @@ -169,9 +169,7 @@ protected ICityEvent GetUpcomingEventToAttend(uint citizenId, ref TCitizen citiz
///
/// <param name="reason">The evacuation reason.</param>
protected void FindEvacuationPlace(uint citizenId, TransferManager.TransferReason reason)
{
TransferMgr.AddOutgoingOfferFromCurrentPosition(citizenId, reason);
}
=> TransferMgr.AddOutgoingOfferFromCurrentPosition(citizenId, reason);

/// <summary>
/// Gets a string that describes the specified citizen.
Expand Down
13 changes: 5 additions & 8 deletions src/RealTime/CustomAI/RealTimeResidentAI.Common.cs
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ private bool UpdateCitizenSchedule(ref CitizenSchedule schedule, uint citizenId,
{
// If the game changed the work building, we have to update the work shifts first
ushort workBuilding = CitizenProxy.GetWorkBuilding(ref citizen);
if (schedule.WorkBuilding != workBuilding || (workBuilding == 0 && schedule.WorkShift != WorkShift.Unemployed))
if (schedule.WorkBuilding != workBuilding || workBuilding == 0 && schedule.WorkShift != WorkShift.Unemployed)
{
schedule.WorkBuilding = workBuilding;
workBehavior.UpdateWorkShift(ref schedule, CitizenProxy.GetAge(ref citizen));
Expand Down Expand Up @@ -306,13 +306,13 @@ private bool UpdateCitizenSchedule(ref CitizenSchedule schedule, uint citizenId,

if (ScheduleShopping(ref schedule, ref citizen, localOnly: false))
{
Log.Debug(LogCategory.Schedule, $" - Schedule shopping");
Log.Debug(LogCategory.Schedule, " - Schedule shopping");
return true;
}

if (ScheduleRelaxing(ref schedule, citizenId, ref citizen))
{
Log.Debug(LogCategory.Schedule, $" - Schedule relaxing");
Log.Debug(LogCategory.Schedule, " - Schedule relaxing");
return true;
}

Expand Down Expand Up @@ -344,7 +344,7 @@ private bool UpdateCitizenSchedule(ref CitizenSchedule schedule, uint citizenId,
}
else
{
Log.Debug(LogCategory.Schedule, $" - Schedule moving home");
Log.Debug(LogCategory.Schedule, " - Schedule moving home");
schedule.Schedule(ResidentState.AtHome);
}

Expand Down Expand Up @@ -438,9 +438,6 @@ private bool ProcessCurrentState(ref CitizenSchedule schedule, uint citizenId, r
return false;
}

private bool ShouldRealizeCitizen(TAI ai)
{
return residentAI.DoRandomMove(ai);
}
private bool ShouldRealizeCitizen(TAI ai) => residentAI.DoRandomMove(ai);
}
}
4 changes: 1 addition & 3 deletions src/RealTime/CustomAI/RealTimeResidentAI.Visit.cs
Original file line number Diff line number Diff line change
Expand Up @@ -245,9 +245,7 @@ private bool ProcessCitizenShopping(ref CitizenSchedule schedule, uint citizenId
}

private bool ProcessCitizenVisit(ref CitizenSchedule schedule, uint citizenId, ref TCitizen citizen)
{
return RescheduleVisit(ref schedule, citizenId, ref citizen, CitizenProxy.GetVisitBuilding(ref citizen));
}
=> RescheduleVisit(ref schedule, citizenId, ref citizen, CitizenProxy.GetVisitBuilding(ref citizen));

private bool RescheduleVisit(ref CitizenSchedule schedule, uint citizenId, ref TCitizen citizen, ushort currentBuilding)
{
Expand Down
4 changes: 2 additions & 2 deletions src/RealTime/CustomAI/RealTimeResidentAI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,8 @@ public void UpdateLocation(TAI instance, uint citizenId, ref TCitizen citizen)
return;
}

if ((CitizenProxy.IsSick(ref citizen) && ProcessCitizenSick(instance, citizenId, ref citizen))
|| (CitizenProxy.IsArrested(ref citizen) && ProcessCitizenArrested(ref citizen)))
if (CitizenProxy.IsSick(ref citizen) && ProcessCitizenSick(instance, citizenId, ref citizen)
|| CitizenProxy.IsArrested(ref citizen) && ProcessCitizenArrested(ref citizen))
{
schedule.Schedule(ResidentState.Unknown);
return;
Expand Down
10 changes: 1 addition & 9 deletions src/RealTime/CustomAI/RealTimeTouristAI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -379,14 +379,6 @@ private bool StartMovingToVisitBuilding(TAI instance, uint citizenId, ref TCitiz
return true;
}

private uint GetHotelLeaveChance()
{
if (TimeInfo.IsNightTime)
{
return 0u;
}

return (uint)((TimeInfo.CurrentHour - Config.WakeUpHour) / 0.03f);
}
private uint GetHotelLeaveChance() => TimeInfo.IsNightTime ? 0u : (uint)((TimeInfo.CurrentHour - Config.WakeUpHour) / 0.03f);
}
}
19 changes: 5 additions & 14 deletions src/RealTime/CustomAI/SpareTimeBehavior.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,7 @@ public SpareTimeBehavior(RealTimeConfig config, ITimeInfo timeInfo)
/// <summary>Sets the duration (in hours) of a full simulation cycle for all citizens.
/// The game calls the simulation methods for a particular citizen with this period.</summary>
/// <param name="cyclePeriod">The citizens simulation cycle period, in game hours.</param>
public void SetSimulationCyclePeriod(float cyclePeriod)
{
simulationCycle = cyclePeriod;
}
public void SetSimulationCyclePeriod(float cyclePeriod) => simulationCycle = cyclePeriod;

/// <summary>Calculates the chances for the citizens to go out based on the current game time.</summary>
public void RefreshChances()
Expand Down Expand Up @@ -102,10 +99,7 @@ public void RefreshChances()
///
/// <returns>A percentage value in range of 0..100 that describes the probability whether
/// a citizen with specified age would go shopping on current time.</returns>
public uint GetShoppingChance(Citizen.AgeGroup citizenAge)
{
return shoppingChances[(int)citizenAge];
}
public uint GetShoppingChance(Citizen.AgeGroup citizenAge) => shoppingChances[(int)citizenAge];

/// <summary>
/// Gets the probability whether a citizen with specified age would go relaxing on current time.
Expand Down Expand Up @@ -151,10 +145,7 @@ public uint GetRelaxingChance(Citizen.AgeGroup citizenAge, WorkShift workShift =
/// <param name="wealth">The citizen's wealth.</param>
/// <returns>The precise probability (in percent multiplied by 100) for the citizen to go on vacation
/// on current day.</returns>
public uint GetPreciseVacationChance(Citizen.Wealth wealth)
{
return vacationChances[(int)wealth];
}
public uint GetPreciseVacationChance(Citizen.Wealth wealth) => vacationChances[(int)wealth];

private void CalculateDefaultChances(float currentHour, uint weekdayModifier)
{
Expand Down Expand Up @@ -275,7 +266,7 @@ private void CalculateShoppingChance(float currentHour)
{
isNight = true;
chance = NightShoppingChance
+ ((100u - NightShoppingChance) * (currentHour - minShoppingChanceEndHour) / (maxShoppingChanceStartHour - minShoppingChanceEndHour));
+ (100u - NightShoppingChance) * (currentHour - minShoppingChanceEndHour) / (maxShoppingChanceStartHour - minShoppingChanceEndHour);
}
else if (currentHour < maxShoppingChanceEndHour)
{
Expand All @@ -286,7 +277,7 @@ private void CalculateShoppingChance(float currentHour)
{
isNight = true;
chance = NightShoppingChance
+ ((100u - NightShoppingChance) * (24f - currentHour) / (24f - maxShoppingChanceEndHour));
+ (100u - NightShoppingChance) * (24f - currentHour) / (24f - maxShoppingChanceEndHour);
}

uint roundedChance = (uint)Math.Round(chance);
Expand Down
4 changes: 2 additions & 2 deletions src/RealTime/CustomAI/WeatherInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,12 @@ public WeatherInfo(IWeatherManagerConnection weatherManager, IRandomizer randomi
/// <summary>
/// Gets a value indicating whether current weather conditions cause citizens not to stay outside.
/// </summary>
bool IWeatherInfo.IsBadWeather => isDisasterHazardActive || (stayInsideChance != 0 && randomizer.ShouldOccur(stayInsideChance));
bool IWeatherInfo.IsBadWeather => isDisasterHazardActive || stayInsideChance != 0 && randomizer.ShouldOccur(stayInsideChance);

/// <summary>Updates this object's state using the current game state.</summary>
public void Update()
{
float weatherFactor = weatherManager.GetRainIntensity() + (weatherManager.GetSnowIntensity() / 2f);
float weatherFactor = weatherManager.GetRainIntensity() + weatherManager.GetSnowIntensity() / 2f;

if (weatherFactor < BadWeatherPrecipitationThreshold)
{
Expand Down
5 changes: 1 addition & 4 deletions src/RealTime/Events/CityEventBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,7 @@ public virtual bool TryAcceptAttendee(
Citizen.Wealth wealth,
Citizen.Wellbeing wellbeing,
Citizen.Happiness happiness,
IRandomizer randomizer)
{
return true;
}
IRandomizer randomizer) => true;

/// <summary>
/// Configures this event to take place in the specified building and at the specified start time.
Expand Down
6 changes: 1 addition & 5 deletions src/RealTime/Events/RealTimeCityEvent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
namespace RealTime.Events
{
using System;
using System.Linq;
using RealTime.Events.Storage;
using RealTime.Simulation;

Expand Down Expand Up @@ -129,10 +128,7 @@ public RealTimeEventStorage GetStorageData()

/// <summary>Calculates the city event duration.</summary>
/// <returns>This city event duration in hours.</returns>
protected override float GetDuration()
{
return (float)eventTemplate.Duration;
}
protected override float GetDuration() => (float)eventTemplate.Duration;

private static bool CheckAge(Citizen.AgeGroup age, CityEventAttendees attendees, float randomPercentage)
{
Expand Down
Loading

0 comments on commit 57d7627

Please sign in to comment.