From 6bf431cf157e2b3ba1095cca6c5fb02a3773f372 Mon Sep 17 00:00:00 2001
From: dymanoid <9433345+dymanoid@users.noreply.github.com>
Date: Thu, 30 May 2019 21:22:20 +0200
Subject: [PATCH] Use 'Better aging' option for custom age and education
distribution #220
---
src/RealTime/Core/RealTimeCore.cs | 2 +-
src/RealTime/CustomAI/INewCitizenBehavior.cs | 3 ++-
src/RealTime/CustomAI/NewCitizenBehavior.cs | 20 +++++++++++++++----
.../Patches/CitizenManagerPatch.cs | 2 +-
4 files changed, 20 insertions(+), 7 deletions(-)
diff --git a/src/RealTime/Core/RealTimeCore.cs b/src/RealTime/Core/RealTimeCore.cs
index f9d0395..b4a2073 100644
--- a/src/RealTime/Core/RealTimeCore.cs
+++ b/src/RealTime/Core/RealTimeCore.cs
@@ -187,7 +187,7 @@ namespace RealTime.Core
if (appliedPatches.Contains(CitizenManagerPatch.CreateCitizenPatch1))
{
- CitizenManagerPatch.NewCitizenBehavior = new NewCitizenBehavior(randomizer);
+ CitizenManagerPatch.NewCitizenBehavior = new NewCitizenBehavior(randomizer, configProvider.Configuration);
}
if (appliedPatches.Contains(BuildingAIPatches.GetColor))
diff --git a/src/RealTime/CustomAI/INewCitizenBehavior.cs b/src/RealTime/CustomAI/INewCitizenBehavior.cs
index 637b968..ac12a41 100644
--- a/src/RealTime/CustomAI/INewCitizenBehavior.cs
+++ b/src/RealTime/CustomAI/INewCitizenBehavior.cs
@@ -14,9 +14,10 @@ namespace RealTime.CustomAI
///
///
/// The citizen's age as raw value (0-255).
+ /// The current value of the citizen's education.
///
/// The education level of the new citizen with the specified age.
- Citizen.Education GetEducation(int age);
+ Citizen.Education GetEducation(int age, Citizen.Education currentEducation);
///
/// Adjusts the age of the new citizen based on their current .
diff --git a/src/RealTime/CustomAI/NewCitizenBehavior.cs b/src/RealTime/CustomAI/NewCitizenBehavior.cs
index f84fd27..d097925 100644
--- a/src/RealTime/CustomAI/NewCitizenBehavior.cs
+++ b/src/RealTime/CustomAI/NewCitizenBehavior.cs
@@ -4,6 +4,8 @@
namespace RealTime.CustomAI
{
+ using System;
+ using RealTime.Config;
using RealTime.Simulation;
///
@@ -12,23 +14,33 @@ namespace RealTime.CustomAI
internal sealed class NewCitizenBehavior : INewCitizenBehavior
{
private readonly IRandomizer randomizer;
+ private readonly RealTimeConfig config;
///
/// Initializes a new instance of the class.
///
/// The randomizer to use for random decisions.
- public NewCitizenBehavior(IRandomizer randomizer)
+ /// The configuration to run with.
+ /// Thrown when any argument is null.
+ public NewCitizenBehavior(IRandomizer randomizer, RealTimeConfig config)
{
- this.randomizer = randomizer;
+ this.randomizer = randomizer ?? throw new ArgumentNullException(nameof(randomizer));
+ this.config = config ?? throw new ArgumentNullException(nameof(config));
}
///
/// Gets the education level of the new citizen based on their .
///
/// The citizen's age as raw value (0-255).
+ /// The current value of the citizen's education.
/// The education level of the new citizen with the specified age.
- public Citizen.Education GetEducation(int age)
+ public Citizen.Education GetEducation(int age, Citizen.Education currentEducation)
{
+ if (!config.UseSlowAging)
+ {
+ return currentEducation;
+ }
+
var randomValue = randomizer.GetRandomValue(100u);
// Age:
@@ -118,7 +130,7 @@ namespace RealTime.CustomAI
// 45-89 -> young
// 90-179 -> adult
// 180-255 -> senior
- if (age <= 1)
+ if (!config.UseSlowAging || age <= 1)
{
return age;
}
diff --git a/src/RealTime/GameConnection/Patches/CitizenManagerPatch.cs b/src/RealTime/GameConnection/Patches/CitizenManagerPatch.cs
index e8d9a96..93d87b1 100644
--- a/src/RealTime/GameConnection/Patches/CitizenManagerPatch.cs
+++ b/src/RealTime/GameConnection/Patches/CitizenManagerPatch.cs
@@ -34,7 +34,7 @@ namespace RealTime.GameConnection.Patches
private static void UpdateCitizenEducation(uint citizenId)
{
ref var citizen = ref CitizenManager.instance.m_citizens.m_buffer[citizenId];
- var newEducation = NewCitizenBehavior.GetEducation(citizen.Age);
+ var newEducation = NewCitizenBehavior.GetEducation(citizen.Age, citizen.EducationLevel);
citizen.Education3 = newEducation == Citizen.Education.ThreeSchools;
citizen.Education2 = newEducation == Citizen.Education.TwoSchools || newEducation == Citizen.Education.ThreeSchools;
citizen.Education1 = newEducation != Citizen.Education.Uneducated;
--
GitLab