Fission FSN
Loading...
Searching...
No Matches
gfCParkDaySim.h
Go to the documentation of this file.
1/********************************************************************
2*
3* File: gfCParkDaySim.h
4*
5* Purpose: Headless day-loop orchestrator: arrival director, visitors,
6* service slots and economy. Exploring is primary; authored
7* service needs are optional diversions during a park visit.
8*
9*********************************************************************/
10
11#ifndef gfCParkDaySimhdr
12#define gfCParkDaySimhdr
13
14#include <vector>
15
16#include <fsCore/fsStr.h>
17#include <fsCore/fsBaseTypes.h>
18
19#include "gfCSlotSim.h"
20#include "gfCGuestAgentSim.h"
22#include "gfCDayEconomySim.h"
23
25{
26public:
27
28 gfCParkDaySim(fsS32 pSpawnIntervalMs, fsS32 pMaxGuests, fsS32 pCoinGoal);
29
30 void slotAdd(const fsStr& pName, const fsStr& pSlotType, fsS32 pServiceTimeMs, fsS32 pMaxQueueLength,
31 fsBool pUnlocked);
32
33 // Unlocks a registered slot when its building is purchased. False if no
34 // such slot exists.
35 fsBool slotUnlock(const fsStr& pName);
36
37 // Staff types (kiosk mans a building, repair fixes broken ones). Keyed by
38 // string so staff.yml stays the source of truth for roles.
39 static const fsStr mStaffTypeKiosk;
40 static const fsStr mStaffTypeFood;
41 static const fsStr mStaffTypeRepair;
42
43 // Genre guard: staff are a scarce, player-deployed resource. Growing the
44 // pool doesn't staff anything - only deploy/recall does.
45 void staffPoolGrow(const fsStr& pStaffType, fsS32 pBy = 1);
46 fsS32 staffTotalGet(const fsStr& pStaffType) const;
47 fsS32 staffAvailableGet(const fsStr& pStaffType) const;
48
49 // Untyped overloads mean "kiosk" (keeps the doctests unchanged).
53
54 // False (no-op) if there's no such slot, it's already staffed, or the
55 // pool has nobody available.
56 fsBool staffDeploy(const fsStr& pSlotName, const fsStr& pStaffType = fsStr());
57
58 // False (no-op) if there's no such slot or it isn't staffed.
59 fsBool staffRecall(const fsStr& pSlotName);
60
61 fsBool slotStaffedGet(const fsStr& pSlotName) const;
62 fsStr slotStaffTypeGet(const fsStr& pSlotName) const;
63 fsBool slotBrokenGet(const fsStr& pSlotName) const;
64 fsBool slotRepairingGet(const fsStr& pSlotName) const;
65
66 // Applied to every slot; 0 for a limit means "never breaks that way". Both
67 // default to 0, so slots are indestructible unless a game opts in.
68 void slotWearLimitsSetAll(fsS32 pServicesBeforeBreak, fsS32 pOpenMsBeforeBreak);
69 void repairTimeMsSet(fsS32 pRepairTimeMs) { mRepairTimeMs = pRepairTimeMs; }
70
71 // Sends an idle repairer to a slot (fix or preventive), tying them up until
72 // done. False if none free or one is already on it.
73 fsBool slotRepairBegin(const fsStr& pSlotName);
74
75 // Registers a visitor type selected by smooth catalogue-authored weighting.
76 // The single-need overload keeps small callers concise; catalogue content
77 // uses the vector overload to author a sequence of secondary needs.
78 void guestTemplateAdd(const fsStr& pNamePrefix, const fsStr& pNeedSlotType,
79 fsS32 pSpend, fsS32 pPatienceMs, fsS32 pVisitMs = 5000,
80 fsS32 pNeedIntervalMs = 0, fsS32 pArrivalWeight = 1,
81 fsS32 pPartySize = 1);
82 void guestTemplateAdd(const fsStr& pNamePrefix, const std::vector<fsStr>& pNeedSlotTypes,
83 fsS32 pSpend, fsS32 pPatienceMs, fsS32 pVisitMs,
84 fsS32 pNeedIntervalMs, fsS32 pArrivalWeight = 1,
85 fsS32 pPartySize = 1);
86
87 // Walk time to a slot before service can start. Defaults to 0 (keeps the
88 // doctests' timings); the game sets a real value.
89 void guestTravelMsSet(fsS32 pTravelMs) { mGuestTravelMs = pTravelMs; }
90 // Environmental comfort changes the value of the wandering portion of every
91 // visit. Sets the park-wide default applied to current guests and used to
92 // seed future arrivals before the view can place them (see
93 // guestWalkingSatisfactionPercentSet for the per-guest, position-aware
94 // override - the sim itself is spatial-free).
96 fsS32 walkingSatisfactionPercentGet() const { return mWalkingSatisfactionPercent; }
97
98 // Per-guest override once the presentation layer knows their actual
99 // position and nearby decoration coverage - mirrors guestTravelTimeSet.
100 // No-op if there's no such guest.
101 void guestWalkingSatisfactionPercentSet(const fsStr& pGuestName, fsS32 pPercent);
102
103 // Daily admissions cap supplied by the best owned entrance. It can increase
104 // mid-day when an entrance is built without resetting the spawn timer.
105 void visitorQuotaSet(fsS32 pVisitorQuota);
106 fsS32 visitorQuotaGet() const { return mVisitorQuota; }
107 void visitorDemandSet(fsS32 pVisitorDemand);
108 fsS32 visitorDemandGet() const { return mVisitorDemand; }
109 fsS32 visitorArrivalTargetGet() const { return mArrivalDirector.maxGuestsGet(); }
110
111 // Chance that a guest who reaches an unstaffed matching building completes a
112 // self-guided visit and leaves happy. Zero preserves the strict staffed-only
113 // simulation; the park game opts into a content-tuned percentage.
114 void unstaffedVisitHappyChancePercentSet(fsS32 pChancePercent);
115
116 // Overrides one walking guest's remaining travel time. The sim is
117 // spatial-free, so it can only apply a flat guestTravelMs to every walk -
118 // which makes distant slots look faster (same time, more distance). The
119 // presentation layer, which knows the real distance, calls this so travel
120 // time tracks distance and the sprite walks at a constant speed. No-op if
121 // there's no such guest. See gfCParkGuestViewComponent.
122 // The park view confirms counter arrival. Headless callers serve immediately.
123 void waitForServiceArrivalSet(fsBool pWait) { mWaitForServiceArrival = pWait; }
124 void servingGuestArrived(const fsStr& pSlotName, const fsStr& pGuestName);
125 const std::vector<gfCSlotSim>& slotsGet() const { return mSlots; }
126
127 void guestTravelTimeSet(const fsStr& pGuestName, fsS32 pTravelMs);
128
129 // Applied when a building is purchased into the slot. False if no such slot.
130 fsBool slotServiceTimeMsSet(const fsStr& pSlotName, fsS32 pServiceTimeMs);
131 fsBool slotMaxQueueLengthSet(const fsStr& pSlotName, fsS32 pMaxQueueLength);
132
133 void tick(fsS32 pDeltaMs);
134
135 fsS32 activeGuestCountGet() const { return static_cast<fsS32>(mGuests.size()); }
136 fsS32 guestsSpawnedGet() const { return mGuestsSpawnedCount; }
137
138 // Read-only guest enumeration for presentation, paired with
139 // activeGuestCountGet(). Null if out of range. Guests are erased the tick
140 // they enter LEAVING_*, so a caller wanting to animate departures must hold
141 // its own copy (see gfCParkGuestViewComponent).
142 const gfCGuestAgentSim* guestGetByIndex(fsS32 pIndex) const;
143
144 // Departures from the most recent tick (name + why), cleared at the start of
145 // the next - the only place to see *why* a guest left, since they're erased
146 // the same tick. A caller running after each tick sees each one once.
153
154 fsS32 departureCountGet() const { return static_cast<fsS32>(mDepartures.size()); }
155 const SDeparture* departureGetByIndex(fsS32 pIndex) const;
156 const gfCDayEconomySim& economyGet() const { return mEconomy; }
157 gfCDayEconomySim& economyGet() { return mEconomy; }
158
159 // Running, per-service-type tally of what hurt visits today, for the
160 // end-of-day "what hurt satisfaction" feedback (gfCParkEndOfDayGui).
161 // mCongestionCount: patience ran out waiting in that service's queue.
162 // mBreakdownCount: that service broke down while the guest was in it.
163 // mMissedCount: the guest wanted that service but none had room, so the
164 // need was deferred rather than ending the visit - a near-miss, not
165 // necessarily an unhappy one.
173 fsS32 serviceIssueCountGet() const { return static_cast<fsS32>(mServiceIssues.size()); }
174 const SServiceIssueTally* serviceIssueGetByIndex(fsS32 pIndex) const;
175
176private:
177
178 SServiceIssueTally& serviceIssueFind(const fsStr& pServiceType);
179
180 struct SGuestTemplate
181 {
182 fsStr mNamePrefix;
183 std::vector<fsStr> mNeedSlotTypes;
184 fsS32 mSpend;
185 fsS32 mPatienceMs;
186 fsS32 mVisitMs;
187 fsS32 mNeedIntervalMs;
188 fsS32 mArrivalWeight;
189 fsS32 mPartySize;
190 fsS32 mSelectionCredit;
191 };
192
193 void guestSpawn();
194 gfCGuestAgentSim* guestFind(const fsStr& pName);
195
196 // Prefer a staffed matching slot whose wait fits this guest's patience;
197 // otherwise fall back to an unstaffed matching building with room.
198 gfCSlotSim* slotWithRoomFind(const fsStr& pSlotType, fsS32 pPatienceRemainingMs);
199 fsBool unstaffedVisitHappyRoll();
200
201 // Joins the guest's assigned slot, setting state. False if it filled up
202 // while they walked over.
203 fsBool guestSlotJoin(gfCGuestAgentSim& pGuest);
204 void guestServiceComplete(gfCGuestAgentSim& pGuest);
205
206 std::vector<gfCSlotSim> mSlots;
207 std::vector<gfCGuestAgentSim> mGuests;
208 std::vector<SDeparture> mDepartures;
209 std::vector<SServiceIssueTally> mServiceIssues;
210 std::vector<SGuestTemplate> mGuestTemplates;
211
212 gfCArrivalDirectorSim mArrivalDirector;
213 gfCDayEconomySim mEconomy;
214
215 fsS32 mGuestsSpawnedCount;
216 fsS32 mVisitorQuota;
217 fsS32 mVisitorDemand;
218
219 struct SStaffPool
220 {
221 fsStr mType;
222 fsS32 mTotal;
223 fsS32 mDeployed;
224 };
225
226 SStaffPool* staffPoolFind(const fsStr& pStaffType);
227 const SStaffPool* staffPoolFind(const fsStr& pStaffType) const;
228
229 std::vector<SStaffPool> mStaffPools;
230 fsS32 mGuestTravelMs;
231 fsBool mWaitForServiceArrival = false;
232 fsS32 mWalkingSatisfactionPercent;
233 fsS32 mRepairTimeMs;
234 fsS32 mUnstaffedVisitHappyChancePercent;
235 fsU32 mUnstaffedVisitRandomState;
236
237 // Slots being repaired, so the repairer is handed back on completion.
238 std::vector<fsStr> mSlotsUnderRepair;
239
240 gfCSlotSim* slotFind(const fsStr& pName);
241 const gfCSlotSim* slotFind(const fsStr& pName) const;
242};
243
244#endif
Definition fsStr.h:23
Definition gfCDayEconomySim.h:19
Definition gfCGuestAgentSim.h:35
fsS32 staffAvailableGet() const
Definition gfCParkDaySim.h:52
fsBool slotBrokenGet(const fsStr &pSlotName) const
Definition gfCParkDaySim.cpp:236
gfCDayEconomySim & economyGet()
Definition gfCParkDaySim.h:157
void staffPoolGrow(const fsStr &pStaffType, fsS32 pBy=1)
Definition gfCParkDaySim.cpp:137
fsBool slotUnlock(const fsStr &pName)
Definition gfCParkDaySim.cpp:70
fsBool slotServiceTimeMsSet(const fsStr &pSlotName, fsS32 pServiceTimeMs)
Definition gfCParkDaySim.cpp:462
const std::vector< gfCSlotSim > & slotsGet() const
Definition gfCParkDaySim.h:125
void unstaffedVisitHappyChancePercentSet(fsS32 pChancePercent)
Definition gfCParkDaySim.cpp:364
void visitorQuotaSet(fsS32 pVisitorQuota)
Definition gfCParkDaySim.cpp:46
fsStr slotStaffTypeGet(const fsStr &pSlotName) const
Definition gfCParkDaySim.cpp:222
const gfCDayEconomySim & economyGet() const
Definition gfCParkDaySim.h:156
void slotAdd(const fsStr &pName, const fsStr &pSlotType, fsS32 pServiceTimeMs, fsS32 pMaxQueueLength, fsBool pUnlocked)
Definition gfCParkDaySim.cpp:60
fsS32 serviceIssueCountGet() const
Definition gfCParkDaySim.h:173
fsS32 visitorQuotaGet() const
Definition gfCParkDaySim.h:106
fsS32 guestsSpawnedGet() const
Definition gfCParkDaySim.h:136
fsBool staffDeploy(const fsStr &pSlotName, const fsStr &pStaffType=fsStr())
Definition gfCParkDaySim.cpp:164
fsBool staffRecall(const fsStr &pSlotName)
Definition gfCParkDaySim.cpp:194
void servingGuestArrived(const fsStr &pSlotName, const fsStr &pGuestName)
Definition gfCParkDaySim.cpp:484
fsS32 staffTotalGet() const
Definition gfCParkDaySim.h:51
const SDeparture * departureGetByIndex(fsS32 pIndex) const
Definition gfCParkDaySim.cpp:317
void guestTravelTimeSet(const fsStr &pGuestName, fsS32 pTravelMs)
Definition gfCParkDaySim.cpp:492
static const fsStr mStaffTypeRepair
Definition gfCParkDaySim.h:41
fsS32 walkingSatisfactionPercentGet() const
Definition gfCParkDaySim.h:96
void visitorDemandSet(fsS32 pVisitorDemand)
Definition gfCParkDaySim.cpp:53
gfCParkDaySim(fsS32 pSpawnIntervalMs, fsS32 pMaxGuests, fsS32 pCoinGoal)
Definition gfCParkDaySim.cpp:11
void guestWalkingSatisfactionPercentSet(const fsStr &pGuestName, fsS32 pPercent)
Definition gfCParkDaySim.cpp:36
void repairTimeMsSet(fsS32 pRepairTimeMs)
Definition gfCParkDaySim.h:69
fsBool slotRepairingGet(const fsStr &pSlotName) const
Definition gfCParkDaySim.cpp:242
static const fsStr mStaffTypeFood
Definition gfCParkDaySim.h:40
fsBool slotStaffedGet(const fsStr &pSlotName) const
Definition gfCParkDaySim.cpp:270
void guestTemplateAdd(const fsStr &pNamePrefix, const fsStr &pNeedSlotType, fsS32 pSpend, fsS32 pPatienceMs, fsS32 pVisitMs=5000, fsS32 pNeedIntervalMs=0, fsS32 pArrivalWeight=1, fsS32 pPartySize=1)
Definition gfCParkDaySim.cpp:276
void staffPoolGrow(fsS32 pBy=1)
Definition gfCParkDaySim.h:50
static const fsStr mStaffTypeKiosk
Definition gfCParkDaySim.h:39
void tick(fsS32 pDeltaMs)
Definition gfCParkDaySim.cpp:536
const gfCGuestAgentSim * guestGetByIndex(fsS32 pIndex) const
Definition gfCParkDaySim.cpp:308
fsS32 activeGuestCountGet() const
Definition gfCParkDaySim.h:135
void slotWearLimitsSetAll(fsS32 pServicesBeforeBreak, fsS32 pOpenMsBeforeBreak)
Definition gfCParkDaySim.cpp:228
void guestTravelMsSet(fsS32 pTravelMs)
Definition gfCParkDaySim.h:89
fsS32 departureCountGet() const
Definition gfCParkDaySim.h:154
fsBool slotRepairBegin(const fsStr &pSlotName)
Definition gfCParkDaySim.cpp:248
const SServiceIssueTally * serviceIssueGetByIndex(fsS32 pIndex) const
Definition gfCParkDaySim.cpp:341
fsS32 visitorDemandGet() const
Definition gfCParkDaySim.h:108
void walkingSatisfactionPercentSet(fsS32 pPercent)
Definition gfCParkDaySim.cpp:25
fsS32 visitorArrivalTargetGet() const
Definition gfCParkDaySim.h:109
fsBool slotMaxQueueLengthSet(const fsStr &pSlotName, fsS32 pMaxQueueLength)
Definition gfCParkDaySim.cpp:473
void waitForServiceArrivalSet(fsBool pWait)
Definition gfCParkDaySim.h:123
unsigned int fsU32
Definition fsBaseTypes.h:21
bool fsBool
Definition fsBaseTypes.h:26
int fsS32
Definition fsBaseTypes.h:20
Definition gfCParkDaySim.h:148
fsS32 mSatisfactionPercent
Definition gfCParkDaySim.h:151
fsBool mHappy
Definition gfCParkDaySim.h:150
fsStr mName
Definition gfCParkDaySim.h:149
Definition gfCParkDaySim.h:167
fsS32 mMissedCount
Definition gfCParkDaySim.h:171
fsStr mServiceType
Definition gfCParkDaySim.h:168
fsS32 mCongestionCount
Definition gfCParkDaySim.h:169
fsS32 mBreakdownCount
Definition gfCParkDaySim.h:170