1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364 | /********************************************************************
*
* File: gfCParkLevelComponent.h
*
* Purpose: The park "level": loads the map, discovers its slots and
* runs the headless day sim against them until the day
* timer runs out. See gfCParkDaySim.h.
*
* Save/restore covers day index, day time remaining, coins
* and player ownership (buildings bought, staff hired and
* deployed), via fsCUserSavedData (this component is
* constructed explicitly, not through the serialise
* lifecycle). Mid-day guest positions/queues aren't persisted -
* the day resumes with its owned slots but an empty crowd.
*
* 5-day ramp with rising coin goals; dayAdvance() re-runs
* the slot scan against a fresh sim. What the player owns
* (slots, staff) is kept outside that per-day sim so it
* survives the rollover - see the members below.
*
*********************************************************************/
#ifndef gfCParkLevelComponenthdr
#define gfCParkLevelComponenthdr
#include <memory>
#include <vector>
#include <fsCore/fsStr.h>
#include <fsCore/fsVec2d.h>
#include <fsCore/fsPoint.h>
#include <fsAppCore/src/components/fsIMessageListenerComponent.h>
class gfCParkDaySim;
class fsCUserSavedData;
class fsCEntity;
namespace fsNTileMap { class fsCView; }
class gfCParkLevelComponent : public fsIMessageListenerComponent
{
friend class fsCComponentFactory;
public:
static const fsCUniqueId mTypeId;
static const fsS32 mNumDays = 5;
// pResume: restore saved progress (Continue) vs start a fresh day 1 (New
// Game). Either way the resulting state is flushed to disk before returning.
void levelCreate(const fsStr& pLevelName, fsBool pResume);
fsS32 dayRemainingMsGet() const { return mDayRemainingMs; }
fsS32 dayIndexGet() const { return mDayIndex; }
fsBool finalDayGet() const { return mDayIndex >= mNumDays; }
const gfCParkDaySim* simGet() const { return mSim.get(); }
gfCParkDaySim* simGet() { return mSim.get(); }
// End-of-day continue button: same park, fresh sim, higher goal.
void dayAdvance();
// Writes the saved-data keys (day, coins, ownership) into the in-memory
// user-data table. Populate-only - progressPersist() is what reaches disk.
void progressSave() const;
// progressSave() + flush the profile to disk (fsCProfileManager::allDataSave).
// Called at every checkpoint that must survive a quit - the desktop app
// terminates straight out of Application::run() on window close, with no
// applicationDidEnterBackground and no profile-manager teardown, so nothing
// persists unless we flush during play (mirrors how the HOG core saves at
// level boundaries rather than on an exit hook). Without this, Continue read
// an empty mCurrentLocation and loaded a blank level - a black screen.
void progressPersist();
// Ownership kept outside the per-day sim and re-applied each rollover (else
// the park stops working). Called by the purchase actions.
void slotPurchasedRecord(const fsStr& pSlotName, fsS32 pServiceTimeMs, fsS32 pMaxQueueLength,
const fsStr& pBuildingImage, fsS32 pVisitorQuota = 0,
fsS32 pVisitorAppeal = 0);
void staffHiredRecord(const fsStr& pStaffType, fsS32 pWage);
// Grid-placed decorations (tycoon build): no service slot, but their catalogue
// appeal and comfort affect visitors. Recorded here so they survive
// the day rollover and a Continue. pLocalX/Y is the view-local position the
// placement tap resolved to *under today's scroll* - stored zero-scroll
// (pView gives the scroll to subtract), matching serviceBuildingPlace, so
// decorationPositionGet can hand back the correct current screen position
// at any later scroll offset.
void decorationPlacedRecord(fsNTileMap::fsCView* pView, const fsStr& pImage, fsS32 pDrawWidth,
fsS32 pFootprintColumns, fsS32 pFootprintRows,
fsS32 pLocalX, fsS32 pLocalY, fsS32 pVisitorAppeal = 0,
fsS32 pVisitorComfort = 0);
// Current on-screen position + comfort rating for every placed decoration,
// for comfort-by-position coverage (see gfCParkGuestViewComponent). Null
// pView skips the scroll correction (current scroll assumed 0).
struct SDecorationComfortSource
{
fsVec2d mPos;
fsS32 mComfort;
// Catalogue art identity, so walkingSatisfactionNearGet can apply
// diminishing returns per repeated decoration (same art = "duplicate").
fsStr mImage;
};
std::vector<SDecorationComfortSource> decorationComfortSourcesGet(fsNTileMap::fsCView* pView) const;
// Walking satisfaction for a guest/staff member standing at pScreenPos
// right now: the base rate plus comfort from decorations within
// gComfortRadiusPx, capped the same way the old park-wide score always
// was. Called every tick per guest (gfCParkGuestViewComponent) now that
// positions are reliable, rather than one flat value for everyone.
fsS32 walkingSatisfactionNearGet(fsNTileMap::fsCView* pView, const fsVec2d& pScreenPos) const;
// Drops a decoration sprite at a view-local position. Shared by the placement
// tap (gfCParkPlacementComponent) and Continue restore. The position is the
// bottom-centre grid anchor, matching service buildings. Presentation only -
// the level aggregates appeal before updating the sim. Returns the placed entity, or null
// if pView is null.
static fsCEntity* decorationPresentationPlace(fsNTileMap::fsCView* pView,
const fsStr& pImage, fsS32 pDrawWidth,
fsS32 pLocalX, fsS32 pLocalY);
// Creates and owns an asset-defined service slot at an arbitrary view-local
// point. Unlike an authored TMX slot, every purchase gets a unique slot name.
fsBool serviceBuildingPlace(fsNTileMap::fsCView* pView, const fsStr& pImage,
const fsStr& pServiceType, fsS32 pServiceTimeMs,
fsS32 pMaxQueueLength, fsS32 pVisitorQuota,
fsS32 pVisitorAppeal, fsS32 pDrawWidth,
fsS32 pFootprintColumns, fsS32 pFootprintRows,
fsS32 pLocalX, fsS32 pLocalY, fsS32 pPurchaseCost = -1);
// Returns -1 when the cost was not recorded (e.g. an older save).
fsS32 buildingPurchaseCostGet(const fsStr& pSlotName) const;
// Presentation shared by a live purchase and Continue restore. pLocalX/Y is
// the building's ground/contact point; art is bottom-centred on it.
static fsCEntity* serviceBuildingPresentationPlace(fsNTileMap::fsCView* pView,
const fsStr& pSlotName,
const fsStr& pImage, fsS32 pDrawWidth,
fsS32 pLocalX, fsS32 pLocalY);
// Guest presentation resolves runtime slot destinations here before falling
// back to fixed TMX objects.
fsBool runtimeSlotPositionGet(const fsStr& pSlotName, fsVec2d& pOut) const;
// Runtime slot enumeration for presentation systems that formerly discovered
// every staff/repair post by walking the TMX object layer.
fsBool runtimeSlotGetByIndex(fsS32 pIndex, fsStr& pNameOut, fsVec2d& pPositionOut) const;
// Grid occupancy check shared by building and decoration previews. Fixed TMX
// objects plus previously placed runtime buildings and decorations reserve
// their cells.
fsBool parkPlacementValid(fsNTileMap::fsCView* pView,
fsS32 pLocalX, fsS32 pLocalY,
fsS32 pFootprintColumns, fsS32 pFootprintRows) const;
// ---- Forest clearing & walkability -------------------------------------
// The authored "forest" tile layer marks blocked, clearable terrain; a cell
// stays forest until the player clears it (recorded in mClearedCells). Cleared
// and never-forested cells are walkable/buildable ground.
// True if (pCol,pRow) is inside the map, has a forest tile and is not cleared.
fsBool cellForestGet(fsNTileMap::fsCView* pView, fsS32 pCol, fsS32 pRow) const;
// True if (pCol,pRow) is inside the map and not forest (walkable/buildable).
fsBool cellWalkableGet(fsNTileMap::fsCView* pView, fsS32 pCol, fsS32 pRow) const;
// View-local <-> grid-cell helpers, shared by the clear tool and the guest /
// staff routing. cellFromLocal floors to the containing cell; cellCentreLocal
// returns the cell centre in view-local space.
fsPoint cellFromLocal(fsNTileMap::fsCView* pView, const fsVec2d& pLocal) const;
fsVec2d cellCentreLocal(fsNTileMap::fsCView* pView, fsS32 pCol, fsS32 pRow) const;
// Breadth-first shortest path across walkable cells, inclusive of both ends.
// Empty if either end is off-map or the target is unreachable. Diagonals are
// not used, so routes hug the cleared corridors.
std::vector<fsPoint> pathFindCells(fsNTileMap::fsCView* pView,
const fsPoint& pFrom, const fsPoint& pTo) const;
// Nearest walkable cell to pCell (pCell itself if already walkable), by an
// expanding ring search. Used to keep characters off forest when their target
// (a wander point, the park centre) lands on an uncleared tile.
fsPoint nearestWalkableCell(fsNTileMap::fsCView* pView, const fsPoint& pCell) const;
// Nearest walkable cell to pDesired that is actually reachable from pFrom
// (flood over walkable cells, pick the reached cell closest to pDesired).
// Unlike nearestWalkableCell this never returns a cell in a different cleared
// region, so a route to it never has to cut across forest to get there.
fsPoint nearestReachableCell(fsNTileMap::fsCView* pView,
const fsPoint& pFrom, const fsPoint& pDesired) const;
// Coins charged to clear one forest cell (appSettings "forestClearCostCoins").
fsS32 forestClearCostGet() const;
// Brush side length in tiles. Titles can opt into a 2x2 footprint.
fsS32 forestClearBrushSizeGet() const;
// Affordable forest cells reachable from open ground within the brush.
std::vector<fsPoint> forestClearTargetsGet(fsNTileMap::fsCView* pView, fsS32 pCol, fsS32 pRow) const;
// Clear and charge for the entire target set, then persist once.
fsBool forestClearAt(fsNTileMap::fsCView* pView, fsS32 pCol, fsS32 pRow);
// Daily wage bill, and what was charged at the end of the last day.
fsS32 dailyWagesGet() const;
fsS32 lastDayWagesGet() const { return mLastDayWages; }
fsS32 parkReputationGet() const { return mParkReputation; }
// Repair dispatch armed: tapping the office arms it, the next building tap
// sends a repairer instead of deploy/recall. Shared across those components.
fsBool repairArmedGet() const { return mRepairArmed; }
void repairArmedSet(fsBool pArmed) { mRepairArmed = pArmed; }
// Staff deployment is per-sim, so it too must be remembered across the
// rollover or day 2 opens with nothing actually staffed.
void staffDeployedRecord(const fsStr& pSlotName);
void staffRecalledRecord(const fsStr& pSlotName);
// Called by gfCParkLensComponent right after it scrolls, so everything
// moves the same tick as the ground. No-op if pView hasn't scrolled.
void scrollRefresh(fsNTileMap::fsCView* const pView);
// Registers a just-placed sprite to keep it attached to the ground as the
// camera scrolls. Public since some placement flows create their sprite
// directly rather than through a method that could register it itself.
void scrollTrackedAdd(fsCEntity* const pEntity, fsNTileMap::fsCView* const pView);
void scrollTrackedRemove(fsCEntity* const pEntity);
virtual ~gfCParkLevelComponent();
protected:
void updateDo(fsS32 pDeltaMs) override;
// Debug speed keys (1 = 1x, 2 = 4x, 3 = 8x), same as gfCHogLevelComponent -
// the only reason this is a message listener.
void listenersRegisterDo() override;
void listenersDeregisterDo() override;
fsBool messageProcessDo(const fsCUniqueId& pMessageType,
const fsIMessageDispatcher::sMessageParameters& pParam) override;
static fsIComponent* const create(fsCEntity* const pParent);
gfCParkLevelComponent(fsCEntity* const pParent);
private:
void daySimBegin();
void guestTemplatesLoad();
void progressRestore();
fsS32 visitorQuotaHighestOwnedGet() const;
fsS32 visitorDemandFromParkGet() const;
fsS32 walkingSatisfactionFromParkGet() const;
void visitorNumbersRefresh();
void reputationSettle();
// Rebuilds mPurchasedSlots/mHiredStaff/mDeployedSlots from saved data.
// Must run before daySimBegin() re-applies them to a fresh sim.
void ownershipRestore(fsCUserSavedData* const pUserData);
// Translucent greybox markers showing where the authored slots are.
void slotMarkersCreate(fsNTileMap::fsCView* const pView);
// Fixed scenery at a named anchor (staff office, park gate) - not a slot, so
// no catalogue entry and the sim knows nothing about it.
void mapFurnitureCreate(fsNTileMap::fsCView* const pView, const fsStr& pObjectName,
const fsStr& pImagePath, fsF32 pDrawScale, fsBool pRepairDispatchTap = false);
// Locates and caches the "forest" tile layer's map-layer id (-1 if none).
void forestLayerResolve(fsNTileMap::fsCView* const pView);
// Re-hides a cleared cell's forest tile on the view (clear time and Continue).
void clearedCellApply(fsNTileMap::fsCView* const pView, fsS32 pCol, fsS32 pRow);
fsBool cellClearedGet(fsS32 pCol, fsS32 pRow) const;
// Re-applies every scrollTrackedAdd'd entity's position for the view's
// current scroll. Called from scrollRefresh().
void scrollTrackedRefresh(fsNTileMap::fsCView* const pView) const;
struct SScrollTracked
{
fsCEntity* mEntity;<--- Member variable 'SScrollTracked::mEntity' has no initializer. [+]Member variable 'SScrollTracked::mEntity' has no initializer. Member variables of native types, pointers, or references are left uninitialized when the class is instantiated. That may cause bugs or undefined behavior.
fsPoint mZeroScrollPos;
};
static const fsS32 mDayDurationMs;
fsS32 mDayIndex;
fsS32 mDayRemainingMs;
fsBool mDayEndShown;
// Counts up each tick; a periodic autosave flushes progress so a mid-day
// quit (which fires no lifecycle save on desktop) still resumes.
fsS32 mAutosaveTimerMs;
// Player ownership, kept outside the per-day sim so it survives the rollover.
struct SOwnedSlot
{
fsStr mName;
fsS32 mServiceTimeMs;
fsS32 mMaxQueueLength;
// The building's art, kept so its sprite can be re-placed on Continue.
fsStr mBuildingImage;
fsBool mRuntime = false;
fsStr mServiceType;
fsS32 mLocalX = 0;
fsS32 mLocalY = 0;
fsS32 mDrawWidth = 0;
fsS32 mFootprintColumns = 0;
fsS32 mFootprintRows = 0;
// Zero for ordinary service buildings. Entrance quotas do not stack;
// the highest owned value replaces the fixed gate's base quota.
fsS32 mVisitorQuota = 0;
fsS32 mVisitorAppeal = 0;
fsS32 mPurchaseCost = -1;
};
// One entry per hired head, so different roles can carry different wages.
struct SHiredStaff
{
fsStr mType;
fsS32 mWage;
};
// A grid-placed decoration: art, footprint, appeal, comfort and bottom-centre anchor
// in view-local coordinates. It has no guest service type.
struct SOwnedDecoration
{
fsStr mImage;
fsS32 mDrawWidth = 0;
fsS32 mFootprintColumns = 1;
fsS32 mFootprintRows = 1;
fsS32 mLocalX;
fsS32 mLocalY;
fsS32 mVisitorAppeal = 0;
fsS32 mVisitorComfort = 0;
};
std::vector<SOwnedSlot> mPurchasedSlots;
struct SDeployedStaff
{
fsStr mSlotName;
fsStr mType;
};
std::vector<SDeployedStaff> mDeployedSlots;
std::vector<SHiredStaff> mHiredStaff;
std::vector<SOwnedDecoration> mOwnedDecorations;
// Forest cells the player has cleared, in map-grid (col,row). Read as
// walkable/buildable, re-hidden on the view each load. Persisted.
std::vector<fsPoint> mClearedCells;
// Map-layer id of the "forest" tile layer, resolved once at levelCreate.
fsS32 mForestLayerId;
fsS32 mLastDayWages;
fsS32 mParkReputation;
fsS32 mReputationSettledDay;
fsBool mRepairArmed;
fsS32 mRuntimeSlotSequence;
// Not owned - for updateDo()'s fallback scrollRefresh() poll.
fsNTileMap::fsCView* mView;
fsPoint mLastScrollPixel;
std::vector<SScrollTracked> mScrollTracked;
std::unique_ptr<gfCParkDaySim> mSim;
};
#endif
|