diff --git a/src/RealTime/CustomAI/RealTimeResidentAI.Visit.cs b/src/RealTime/CustomAI/RealTimeResidentAI.Visit.cs index 71dff9468215e59d887f02f7fe889009a8ffbd6d..5014cdb8979e725e44e39954d6c1abb421677756 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 403d64a35c71208493791a37cc8c743f5277ff85..63ccb5e90f9bce395f8b9b78be73c62cf0c4bccc 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 aeddbc04794ddfe3581806d525029f039043665d..2c19cfe9006f86e7ed7ebb043e35e3379ee44257 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