Fission FSN
Loading...
Searching...
No Matches
gfCSlotSim.h
Go to the documentation of this file.
1/********************************************************************
2*
3* File: gfCSlotSim.h
4*
5* Purpose: Headless building-slot state machine: serves one guest
6* at a time plus a bounded FIFO queue (one-table Diner-Dash
7* mechanic). Engine-independent (fsCore only) so it's
8* unit-testable - see gameModules/gfTimeCore/tests.
9*
10* Genre guard: a guest can queue at an unstaffed slot, but
11* tick() never progresses service for it - only a staffed
12* slot serves. Staffing is player-driven via gfCParkDaySim.
13*
14*********************************************************************/
15
16#ifndef gfCSlotSimhdr
17#define gfCSlotSimhdr
18
19#include <vector>
20
21#include <fsCore/fsStr.h>
22#include <fsCore/fsBaseTypes.h>
23
24enum class eSlotSimState
25{
28 // Worn out - serves nobody until a repair staff member is sent.
30};
31
33{
34public:
35
36 gfCSlotSim(const fsStr& pName, const fsStr& pSlotType, fsS32 pServiceTimeMs, fsS32 pMaxQueueLength);
37
38 const fsStr& nameGet() const { return mName; }
39 const fsStr& slotTypeGet() const { return mSlotType; }
40 eSlotSimState stateGet() const { return mState; }
41 void unlock() { mState = eSlotSimState::eOPEN; }
42
43 fsBool staffedGet() const { return mStaffed; }
44 void staffedSet(fsBool pStaffed) { mStaffed = pStaffed; }
45
46 // Non-mutating "could a guest commit to walking here?" - they pick a slot
47 // before setting off and only join on arrival.
48 fsBool hasRoomGet() const;
49
50 // Rough wait for a guest joining the back of the queue now (current service
51 // left + a service per queued guest). Only meaningful when staffed; used so a
52 // guest won't commit to a line too long to reach within their patience.
54
55 // Both come from the catalogue entry, applied on purchase - the TMX
56 // registration runs first and doesn't know them yet.
57 void serviceTimeMsSet(fsS32 pServiceTimeMs) { mServiceTimeMs = pServiceTimeMs; }
58 void maxQueueLengthSet(fsS32 pMaxQueueLength) { mMaxQueueLength = pMaxQueueLength; }
59
60 fsBool queueingGet(const fsStr& pGuestName) const;
61 fsBool servingGet(const fsStr& pGuestName) const { return mServingGuestName == pGuestName; }
62 // Removes a waiting guest that abandoned the queue. False if they were not
63 // queued; serving guests are never removed through this path.
64 fsBool queueLeave(const fsStr& pGuestName);
65
66 // Adds to service (if free) or the queue (if room). False if locked or full.
67 fsBool queueJoin(const fsStr& pGuestName);
68
69 // Bumps whoever is mid-service back to the head of the queue, returning their
70 // name (empty if none). Used on staff recall - a served guest left in an
71 // unstaffed slot would be frozen and block everyone behind them.
73
74 // Whichever wear limit is reached first breaks the slot. Either can be 0
75 // ("never breaks that way"); both default to 0 so slots are indestructible
76 // unless a game opts in - keeps the doctests breakdown-free.
77 void wearLimitsSet(fsS32 pServicesBeforeBreak, fsS32 pOpenMsBeforeBreak);
78
79 fsBool brokenGet() const { return eSlotSimState::eBROKEN == mState; }
80
81 // Sends a repairer in: fixes a broken slot, or maintains a still-open one
82 // (preventive - resets wear, keeps serving). False if locked or already being
83 // repaired. gfCParkDaySim owns the staff accounting.
84 fsBool repairBegin(fsS32 pRepairTimeMs);
85 fsBool repairingGet() const { return mRepairRemainingMs > 0; }
86
87 // Removes everyone (serving + queued) and returns their names. Used on break.
88 std::vector<fsStr> occupantsEjectAll();
89
90 // Advances service, wear and any in-progress repair - so a slot can break or
91 // reopen inside this call. Returns the guest finished this tick, or empty.
92 fsStr tick(fsS32 pDeltaMs);
93
94private:
95
96 // Head of the queue into the serving position, timer started.
97 void serveNextBegin();
98
99 // Trips to eBROKEN once either wear limit is passed.
100 void wearCheck();
101
102 fsStr mName;
103 fsStr mSlotType;
104 eSlotSimState mState;
105 fsBool mStaffed;
106 fsS32 mServiceTimeMs;
107 fsS32 mMaxQueueLength;
108
109 std::vector<fsStr> mQueue;
110 fsStr mServingGuestName;
111 fsS32 mServiceRemainingMs;
112
113 // Wear accrues from both use and elapsed open time; a repair clears both.
114 fsS32 mServicesBeforeBreak;
115 fsS32 mOpenMsBeforeBreak;
116 fsS32 mServicesSinceRepair;
117 fsS32 mOpenMsSinceRepair;
118 fsS32 mRepairRemainingMs;
119};
120
121#endif
Definition fsStr.h:23
fsBool staffedGet() const
Definition gfCSlotSim.h:43
void staffedSet(fsBool pStaffed)
Definition gfCSlotSim.h:44
void maxQueueLengthSet(fsS32 pMaxQueueLength)
Definition gfCSlotSim.h:58
eSlotSimState stateGet() const
Definition gfCSlotSim.h:40
fsBool repairingGet() const
Definition gfCSlotSim.h:85
fsStr servingSuspend()
Definition gfCSlotSim.cpp:138
fsS32 estimatedWaitMsGet() const
Definition gfCSlotSim.cpp:83
void serviceTimeMsSet(fsS32 pServiceTimeMs)
Definition gfCSlotSim.h:57
fsBool queueingGet(const fsStr &pGuestName) const
Definition gfCSlotSim.cpp:89
std::vector< fsStr > occupantsEjectAll()
Definition gfCSlotSim.cpp:56
const fsStr & slotTypeGet() const
Definition gfCSlotSim.h:39
fsBool queueLeave(const fsStr &pGuestName)
Definition gfCSlotSim.cpp:94
fsBool servingGet(const fsStr &pGuestName) const
Definition gfCSlotSim.h:61
void wearLimitsSet(fsS32 pServicesBeforeBreak, fsS32 pOpenMsBeforeBreak)
Definition gfCSlotSim.cpp:23
gfCSlotSim(const fsStr &pName, const fsStr &pSlotType, fsS32 pServiceTimeMs, fsS32 pMaxQueueLength)
Definition gfCSlotSim.cpp:6
fsBool brokenGet() const
Definition gfCSlotSim.h:79
fsBool queueJoin(const fsStr &pGuestName)
Definition gfCSlotSim.cpp:105
fsStr tick(fsS32 pDeltaMs)
Definition gfCSlotSim.cpp:154
const fsStr & nameGet() const
Definition gfCSlotSim.h:38
void unlock()
Definition gfCSlotSim.h:41
fsBool hasRoomGet() const
Definition gfCSlotSim.cpp:73
fsBool repairBegin(fsS32 pRepairTimeMs)
Definition gfCSlotSim.cpp:44
eSlotSimState
Definition gfCSlotSim.h:25
@ eBROKEN
Definition gfCSlotSim.h:29
@ eLOCKED
Definition gfCSlotSim.h:26
@ eOPEN
Definition gfCSlotSim.h:27
bool fsBool
Definition fsBaseTypes.h:26
int fsS32
Definition fsBaseTypes.h:20