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 !mStaffType.emptyGet(); }
44 const fsStr& staffTypeGet() const { return mStaffType; }
45 void staffTypeSet(const fsStr& pStaffType) { mStaffType = pStaffType; }
46
47 // Non-mutating "could a guest commit to walking here?" - they pick a slot
48 // before setting off and only join on arrival.
49 fsBool hasRoomGet() const;
50
51 // Rough wait for a guest joining the back of the queue now (current service
52 // left + a service per queued guest). Only meaningful when staffed; used so a
53 // guest won't commit to a line too long to reach within their patience.
55
56 // Both come from the catalogue entry, applied on purchase - the TMX
57 // registration runs first and doesn't know them yet.
58 void serviceTimeMsSet(fsS32 pServiceTimeMs) { mServiceTimeMs = pServiceTimeMs; }
59 void maxQueueLengthSet(fsS32 pMaxQueueLength) { mMaxQueueLength = pMaxQueueLength; }
60
61 const std::vector<fsStr>& queueGet() const { return mQueue; }
62 const fsStr& servingGuestNameGet() const { return mServingGuestName; }
63 void servingGuestArrived(const fsStr& pGuestName);
64
65 fsBool queueingGet(const fsStr& pGuestName) const;
66 fsBool servingGet(const fsStr& pGuestName) const { return mServingGuestName == pGuestName; }
67 // Removes a waiting guest that abandoned the queue. False if they were not
68 // queued; serving guests are never removed through this path.
69 fsBool queueLeave(const fsStr& pGuestName);
70
71 // Adds to service (if free) or the queue (if room). False if locked or full.
72 fsBool queueJoin(const fsStr& pGuestName);
73
74 // Bumps whoever is mid-service back to the head of the queue, returning their
75 // name (empty if none). Used on staff recall - a served guest left in an
76 // unstaffed slot would be frozen and block everyone behind them.
78
79 // Whichever wear limit is reached first breaks the slot. Either can be 0
80 // ("never breaks that way"); both default to 0 so slots are indestructible
81 // unless a game opts in - keeps the doctests breakdown-free.
82 void wearLimitsSet(fsS32 pServicesBeforeBreak, fsS32 pOpenMsBeforeBreak);
83 // Remaining condition before the first enabled wear limit.
85
86 fsBool brokenGet() const { return eSlotSimState::eBROKEN == mState; }
87
88 // Sends a repairer in: fixes a broken slot, or maintains a still-open one
89 // (preventive - resets wear, keeps serving). False if locked or already being
90 // repaired. gfCParkDaySim owns the staff accounting.
91 fsBool repairBegin(fsS32 pRepairTimeMs);
92 fsBool repairingGet() const { return mRepairRemainingMs > 0; }
93
94 // Removes everyone (serving + queued) and returns their names. Used on break.
95 std::vector<fsStr> occupantsEjectAll();
96
97 // Advances service, wear and any in-progress repair - so a slot can break or
98 // reopen inside this call. Returns the guest finished this tick, or empty.
99 fsStr tick(fsS32 pDeltaMs, fsBool pWaitForServiceArrival = false);
100
101private:
102
103 // Reserve the serving position for the head of the queue.
104 void serveNextBegin();
105
106 // Trips to eBROKEN once either wear limit is passed.
107 void wearCheck();
108
109 fsStr mName;
110 fsStr mSlotType;
111 eSlotSimState mState;
112 fsStr mStaffType;
113 fsS32 mServiceTimeMs;
114 fsS32 mMaxQueueLength;
115
116 std::vector<fsStr> mQueue;
117 fsStr mServingGuestName;
118 fsS32 mServiceRemainingMs;
119 fsBool mServingGuestArrived = false;
120
121 // Wear accrues from both use and elapsed open time; a repair clears both.
122 fsS32 mServicesBeforeBreak;
123 fsS32 mOpenMsBeforeBreak;
124 fsS32 mServicesSinceRepair;
125 fsS32 mOpenMsSinceRepair;
126 fsS32 mRepairRemainingMs;
127};
128
129#endif
Definition fsStr.h:23
fsBool staffedGet() const
Definition gfCSlotSim.h:43
void maxQueueLengthSet(fsS32 pMaxQueueLength)
Definition gfCSlotSim.h:59
const std::vector< fsStr > & queueGet() const
Definition gfCSlotSim.h:61
eSlotSimState stateGet() const
Definition gfCSlotSim.h:40
fsBool repairingGet() const
Definition gfCSlotSim.h:92
fsStr servingSuspend()
Definition gfCSlotSim.cpp:152
fsS32 estimatedWaitMsGet() const
Definition gfCSlotSim.cpp:95
void servingGuestArrived(const fsStr &pGuestName)
Definition gfCSlotSim.cpp:168
void serviceTimeMsSet(fsS32 pServiceTimeMs)
Definition gfCSlotSim.h:58
fsBool queueingGet(const fsStr &pGuestName) const
Definition gfCSlotSim.cpp:101
const fsStr & staffTypeGet() const
Definition gfCSlotSim.h:44
std::vector< fsStr > occupantsEjectAll()
Definition gfCSlotSim.cpp:70
const fsStr & slotTypeGet() const
Definition gfCSlotSim.h:39
const fsStr & servingGuestNameGet() const
Definition gfCSlotSim.h:62
fsBool queueLeave(const fsStr &pGuestName)
Definition gfCSlotSim.cpp:106
fsBool servingGet(const fsStr &pGuestName) const
Definition gfCSlotSim.h:66
void wearLimitsSet(fsS32 pServicesBeforeBreak, fsS32 pOpenMsBeforeBreak)
Definition gfCSlotSim.cpp:24
fsS32 conditionPercentGet() const
Definition gfCSlotSim.cpp:30
gfCSlotSim(const fsStr &pName, const fsStr &pSlotType, fsS32 pServiceTimeMs, fsS32 pMaxQueueLength)
Definition gfCSlotSim.cpp:8
fsBool brokenGet() const
Definition gfCSlotSim.h:86
fsBool queueJoin(const fsStr &pGuestName)
Definition gfCSlotSim.cpp:117
const fsStr & nameGet() const
Definition gfCSlotSim.h:38
void unlock()
Definition gfCSlotSim.h:41
fsBool hasRoomGet() const
Definition gfCSlotSim.cpp:84
fsStr tick(fsS32 pDeltaMs, fsBool pWaitForServiceArrival=false)
Definition gfCSlotSim.cpp:176
void staffTypeSet(const fsStr &pStaffType)
Definition gfCSlotSim.h:45
fsBool repairBegin(fsS32 pRepairTimeMs)
Definition gfCSlotSim.cpp:58
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