Skip to content

Commit

Permalink
Restore the possibility to improve education after visiting a library
Browse files Browse the repository at this point in the history
  • Loading branch information
dymanoid committed May 21, 2019
1 parent 63f8be7 commit ddd8529
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 3 deletions.
11 changes: 10 additions & 1 deletion src/RealTime/CustomAI/RealTimeResidentAI.Visit.cs
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,16 @@ private bool ProcessCitizenShopping(ref CitizenSchedule schedule, uint citizenId
}

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)
{
Expand Down
6 changes: 5 additions & 1 deletion src/RealTime/GameConnection/Patches/ResidentAIPatch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,9 @@ StartMovingDelegate startMoving
StartMovingWithOfferDelegate startMovingWithOffer
= FastDelegateFactory.Create<StartMovingWithOfferDelegate>(typeof(ResidentAI), "StartMoving", true);

AttemptAutodidactDelegate attemptAutodidact
= FastDelegateFactory.Create<AttemptAutodidactDelegate>(typeof(ResidentAI), "AttemptAutodidact", true);

return new ResidentAIConnection<ResidentAI, Citizen>(
doRandomMove,
findEvacuationPlace,
Expand All @@ -78,7 +81,8 @@ StartMovingWithOfferDelegate startMovingWithOffer
getEvacuationReason,
getShoppingReason,
startMoving,
startMovingWithOffer);
startMovingWithOffer,
attemptAutodidact);
}
catch (Exception e)
{
Expand Down
19 changes: 18 additions & 1 deletion src/RealTime/GameConnection/ResidentAIConnection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,10 @@ internal sealed class ResidentAIConnection<TAI, TCitizen> : HumanAIConnectionBas
/// A method that corresponds to the AI's original <c>StartMoving</c> method specifying a
/// transfer offer.
/// </param>
/// <param name="attemptAutodidact">
/// A method that corresponds to the AI's original <c>AttemptAutodidact</c> method
/// that updates the citizen's education level after visiting a library.
/// </param>
/// <exception cref="ArgumentNullException">Thrown when any argument is null.</exception>
public ResidentAIConnection(
DoRandomMoveDelegate doRandomMove,
Expand All @@ -55,11 +59,13 @@ public ResidentAIConnection(
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));
}

/// <summary>
Expand Down Expand Up @@ -92,10 +98,21 @@ public ResidentAIConnection(
/// </returns>
public delegate bool StartMovingWithOfferDelegate(TAI instance, uint citizenId, ref TCitizen citizen, ushort sourceBuilding, TransferManager.TransferOffer offer);

/// <summary>
/// Represents the method that corresponds to the AI's original <c>AttemptAutodidact</c> method
/// that updates the citizen's education level after visiting a library.
/// </summary>
/// <param name="citizen">The citizen object to process.</param>
/// <param name="visitedBuildingType">The type of the building the citizen leaves.</param>
public delegate void AttemptAutodidactDelegate(ref TCitizen citizen, ItemClass.Service visitedBuildingType);

/// <summary>Gets a method that calls a <see cref="FindHospitalDelegate"/>.</summary>
public FindHospitalDelegate FindHospital { get; }

/// <summary>Gets a method that calls a <see cref="StartMovingWithOfferDelegate"/>.</summary>
public StartMovingWithOfferDelegate StartMovingWithOffer { get; }

/// <summary>Gets a method that calls a <see cref="AttemptAutodidactDelegate"/>.</summary>
public AttemptAutodidactDelegate AttemptAutodidact { get; }
}
}

0 comments on commit ddd8529

Please sign in to comment.