From ddd8529bd0e595689a78c2099cf018bc2050d3f2 Mon Sep 17 00:00:00 2001 From: dymanoid <9433345+dymanoid@users.noreply.github.com> Date: Tue, 21 May 2019 20:08:09 +0200 Subject: [PATCH] Restore the possibility to improve education after visiting a library --- .../CustomAI/RealTimeResidentAI.Visit.cs | 11 ++++++++++- .../GameConnection/Patches/ResidentAIPatch.cs | 6 +++++- .../GameConnection/ResidentAIConnection.cs | 19 ++++++++++++++++++- 3 files changed, 33 insertions(+), 3 deletions(-) diff --git a/src/RealTime/CustomAI/RealTimeResidentAI.Visit.cs b/src/RealTime/CustomAI/RealTimeResidentAI.Visit.cs index 71dff94..5014cdb 100644 --- a/src/RealTime/CustomAI/RealTimeResidentAI.Visit.cs +++ b/src/RealTime/CustomAI/RealTimeResidentAI.Visit.cs @@ -245,7 +245,16 @@ namespace RealTime.CustomAI } private bool ProcessCitizenVisit(ref CitizenSchedule schedule, uint citizenId, ref TCitizen citizen) - => RescheduleVisit(ref schedule, citizenId, ref citizen, CitizenProxy.GetVisitBuilding(ref citizen)); + { + var currentBuilding = CitizenProxy.GetVisitBuilding(ref citizen); + var currentBuildingService = BuildingMgr.GetBuildingService(currentBuilding); + if (currentBuildingService == ItemClass.Service.Education) + { + residentAI.AttemptAutodidact(ref citizen, currentBuildingService); + } + + return RescheduleVisit(ref schedule, citizenId, ref citizen, currentBuilding); + } private bool RescheduleVisit(ref CitizenSchedule schedule, uint citizenId, ref TCitizen citizen, ushort currentBuilding) { diff --git a/src/RealTime/GameConnection/Patches/ResidentAIPatch.cs b/src/RealTime/GameConnection/Patches/ResidentAIPatch.cs index 403d64a..63ccb5e 100644 --- a/src/RealTime/GameConnection/Patches/ResidentAIPatch.cs +++ b/src/RealTime/GameConnection/Patches/ResidentAIPatch.cs @@ -69,6 +69,9 @@ namespace RealTime.GameConnection.Patches StartMovingWithOfferDelegate startMovingWithOffer = FastDelegateFactory.Create(typeof(ResidentAI), "StartMoving", true); + AttemptAutodidactDelegate attemptAutodidact + = FastDelegateFactory.Create(typeof(ResidentAI), "AttemptAutodidact", true); + return new ResidentAIConnection( doRandomMove, findEvacuationPlace, @@ -78,7 +81,8 @@ namespace RealTime.GameConnection.Patches getEvacuationReason, getShoppingReason, startMoving, - startMovingWithOffer); + startMovingWithOffer, + attemptAutodidact); } catch (Exception e) { diff --git a/src/RealTime/GameConnection/ResidentAIConnection.cs b/src/RealTime/GameConnection/ResidentAIConnection.cs index aeddbc0..2c19cfe 100644 --- a/src/RealTime/GameConnection/ResidentAIConnection.cs +++ b/src/RealTime/GameConnection/ResidentAIConnection.cs @@ -45,6 +45,10 @@ namespace RealTime.GameConnection /// A method that corresponds to the AI's original StartMoving method specifying a /// transfer offer. /// + /// + /// A method that corresponds to the AI's original AttemptAutodidact method + /// that updates the citizen's education level after visiting a library. + /// /// Thrown when any argument is null. public ResidentAIConnection( DoRandomMoveDelegate doRandomMove, @@ -55,11 +59,13 @@ namespace RealTime.GameConnection GetEvacuationReasonDelegate getEvacuationReason, GetShoppingReasonDelegate getShoppingReason, StartMovingDelegate startMoving, - StartMovingWithOfferDelegate startMovingWithOffer) + StartMovingWithOfferDelegate startMovingWithOffer, + AttemptAutodidactDelegate attemptAutodidact) : base(doRandomMove, findEvacuationPlace, findVisitPlace, getEntertainmentReason, getEvacuationReason, getShoppingReason, startMoving) { FindHospital = findHospital ?? throw new ArgumentNullException(nameof(findHospital)); StartMovingWithOffer = startMovingWithOffer ?? throw new ArgumentNullException(nameof(startMovingWithOffer)); + AttemptAutodidact = attemptAutodidact ?? throw new ArgumentNullException(nameof(attemptAutodidact)); } /// @@ -92,10 +98,21 @@ namespace RealTime.GameConnection /// public delegate bool StartMovingWithOfferDelegate(TAI instance, uint citizenId, ref TCitizen citizen, ushort sourceBuilding, TransferManager.TransferOffer offer); + /// + /// Represents the method that corresponds to the AI's original AttemptAutodidact method + /// that updates the citizen's education level after visiting a library. + /// + /// The citizen object to process. + /// The type of the building the citizen leaves. + public delegate void AttemptAutodidactDelegate(ref TCitizen citizen, ItemClass.Service visitedBuildingType); + /// Gets a method that calls a . public FindHospitalDelegate FindHospital { get; } /// Gets a method that calls a . public StartMovingWithOfferDelegate StartMovingWithOffer { get; } + + /// Gets a method that calls a . + public AttemptAutodidactDelegate AttemptAutodidact { get; } } } \ No newline at end of file -- GitLab