Skip to content

Commit

Permalink
Enabling/disabling custom school population counts no longer requires…
Browse files Browse the repository at this point in the history
… a restart.
  • Loading branch information
algernon-A committed Feb 27, 2022
1 parent e310a9e commit 5db170f
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 11 deletions.
1 change: 1 addition & 0 deletions Changelog.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
Version 2.0.1 -

- Add option to display units in US customary measures (does not apply to legacy calculations)
- Enabling/disabling custom school population counts no longer requires a restart
- Implement caching of visitor count calculations
- Automatically refresh options panel on language or measurement unit change

Expand Down
3 changes: 3 additions & 0 deletions Code/GUI/UIModCalcs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -316,6 +316,9 @@ internal void SelectionChanged(BuildingInfo building)
// Yes - school building. Set current pack.
currentSchoolPack = (SchoolDataPack)SchoolData.instance.ActivePack(building);

// Hide vanilla panel.
vanillaPanel.Hide();

// Are we using custom school settings?
if (ModSettings.enableSchoolProperties)
{
Expand Down
21 changes: 14 additions & 7 deletions Code/Patches/StudentCount.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,22 @@ public static class StudentCountPatch
/// <returns></returns>
public static bool Prefix(SchoolAI __instance, ref int __result)
{
// Check to see if we're using realistic school populations, and school level is elementary or high school.
if (ModSettings.EnableSchoolPop && __instance.m_info.GetClassLevel() <= ItemClass.Level.Level2)
// Check to see if school level is elementary or high school.
BuildingInfo thisInfo = __instance.m_info;
if (thisInfo.GetClassLevel() <= ItemClass.Level.Level2)
{
// We are - set the result to our realistic population lookup.
BuildingInfo thisInfo = __instance.m_info;
__result = PopData.instance.Students(thisInfo);
// It's a school - check to see if we're using custom school calculations.
if (ModSettings.EnableSchoolPop)
{
// Custom calcs enabled - set the result to our realistic population lookup.
__result = PopData.instance.Students(thisInfo);

// Don't continue on to original method.
return false;
// Don't continue on to original method.
return false;
}

// Not using custom calcs - ensure default is set.
__instance.m_studentCount = SchoolData.instance.OriginalStudentCount(thisInfo);
}

// Not using realistic school populations - continue on to original method.
Expand Down
24 changes: 21 additions & 3 deletions Code/VolumetricData/CalcPacks.cs
Original file line number Diff line number Diff line change
Expand Up @@ -81,15 +81,33 @@ public class PopDataPack : DataPack
/// <param name="buildingPrefab">Building prefab record</param>
/// <param name="level">Building level</param>
/// <returns>Workplace breakdowns and visitor count </returns>
public virtual WorkplaceLevels Workplaces(BuildingInfo buildingPrefab, int level) => new WorkplaceLevels { level0 = 1, level1 = 0, level2 = 0, level3 = 0};
public virtual WorkplaceLevels Workplaces(BuildingInfo buildingPrefab, int level) => new WorkplaceLevels { level0 = 1, level1 = 0, level2 = 0, level3 = 0 };


/// <summary>
/// Returns the student count for the given building prefab and level.
/// Returns the student count for the given building prefab.
/// </summary>
/// <param name="buildingPrefab">Building prefab record</param>
/// <returns>Student count (0 if not a school building)</returns>
public virtual int Students(BuildingInfo buildingPrefab) => buildingPrefab.m_buildingAI is SchoolAI ? Population(buildingPrefab, (int)buildingPrefab.m_class.m_level, Multipliers.instance.ActiveMultiplier(buildingPrefab)) : 0;
public virtual int Students(BuildingInfo buildingPrefab)
{
// Check for school.
if (buildingPrefab.m_buildingAI is SchoolAI)
{
// It's a school; are custom school calcs enabled?
if (ModSettings.EnableSchoolPop)
{
// Custom calcs enabled - use pack.
return Population(buildingPrefab, (int)buildingPrefab.m_class.m_level, Multipliers.instance.ActiveMultiplier(buildingPrefab));
}

// Custom school settings not enabled; use default.
return SchoolData.instance.OriginalStudentCount(buildingPrefab);
}

// If we got here, it's not a school building; return 0.
return 0;
}
}


Expand Down
2 changes: 1 addition & 1 deletion Translations/en.csv
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ RPR_OPT_RTD,Reset to defaults
RPR_OPT_RTS,Revert to saved
RPR_OPT_SAA,Save and apply
RPR_OPT_SCH,Schools
RPR_OPT_SEN,Enable realistic school student capacities - requires restart
RPR_OPT_SEN,Enable realistic school student capacities
RPR_OPT_SEJ,"Enable realistic school properties (jobs, costs) - requires restart"
RPR_OPT_SDM,Default school capacity multiplier
RPR_OPT_JB0,Uneducated jobs
Expand Down

0 comments on commit 5db170f

Please sign in to comment.