Fission FSN
Loading...
Searching...
No Matches
gfCParkGuestViewComponent.h
Go to the documentation of this file.
1/********************************************************************
2*
3* File: gfCParkGuestViewComponent.h
4*
5* Purpose: Presentation for the day sim's guests: an animated
6* character per guest, moved between gate, slot and out.
7* The sim is spatial-free, so all positioning lives here
8* (anchors from the TMX, walks interpolated here).
9*
10* The sim erases a guest the tick it enters LEAVING_*, so
11* a view whose guest has vanished is walked out to the gate
12* here before being destroyed.
13*
14*********************************************************************/
15
16#ifndef gfCParkGuestViewComponenthdr
17#define gfCParkGuestViewComponenthdr
18
19#include <utility>
20#include <vector>
21
23#include <fsCore/fsStr.h>
24#include <fsCore/fsVec2d.h>
25
27
28class fsCEntity;
29class gfCParkDaySim;
31
32namespace fsNTileMap
33{
34 class fsCView;
35}
36
38{
39 friend class fsCComponentFactory;
40
41public:
42
43 static const fsCUniqueId mTypeId;
44
45 // Guests live under this one child of the view, so a single
46 // bringToFrontOfSiblings() keeps them above buildings bought mid-day.
47 static const fsStr mGuestLayerName;
48
49 // Clears every guest sprite immediately. Called when a new day starts so the
50 // park doesn't begin with the previous day's guests frozen on screen (they'd
51 // otherwise all walk out at once as the new empty sim reconciles).
52 void reset();
53
55
56protected:
57
58 void updateDo(fsS32 pDeltaMs) override;
59
60 static fsIComponent* const create(fsCEntity* const pParent);
62
63private:
64
65 struct SGuestView
66 {
67 fsStr mName;
68 fsCEntity* mEntity;
69 // The lead entity plus catalogue-sized visual companions. One sim agent
70 // still owns the party's needs, queue place, spending and outcome.
71 std::vector<fsCEntity*> mMemberEntities;
72 fsVec2d mPos;
73 fsStr mAnimation;
74 fsS32 mWanderSeed;
75 fsS32 mWanderStep;
76 fsS32 mWanderPauseRemainingMs;
77 fsBool mSeen;
78 fsBool mDeparting;
79 // On arrival: false until the guest has walked in through the gate, then
80 // true for the rest of its life (it heads to its slot/park only after).
81 fsBool mEnteredGate;
82 // While departing: false = still heading to the gate, true = past the
83 // gate and heading out to the spawn point.
84 fsBool mReachedGate;
85 // Set once per walk, when this view has told the sim the distance-based
86 // travel time for its current slot (so the walk is a constant speed).
87 fsBool mTravelPaced;
88 // Remaining view-local waypoints for the current routed walk (front = next).
89 // Empty means "walk straight". mPathTarget* is the grid cell the current
90 // route heads to, so it is only recomputed when the destination changes.
91 std::vector<fsVec2d> mPath;
92 fsS32 mPathTargetCol;
93 fsS32 mPathTargetRow;
94 };
95
96 // Where a guest with no slot yet mills about (park centre, not the gate).
97 fsVec2d parkCentreGet(fsNTileMap::fsCView* const pView) const;
98
99 fsNTileMap::fsCView* viewGet() const;
100
101 // Find-or-create the guest layer (at the view origin).
102 fsCEntity* guestLayerGet(fsNTileMap::fsCView* const pView) const;
103
104 // Centre of a named TMX object in view-local space. False if not found.
105 fsBool mapPointGet(fsNTileMap::fsCView* const pView, const fsStr& pObjectName, fsVec2d& pOut) const;
106
107 SGuestView* viewFind(const fsStr& pGuestName);
108 SGuestView& viewCreate(fsNTileMap::fsCView* const pView, const fsStr& pGuestName,
109 const fsStr& pGuestType, fsS32 pPartySize, const fsVec2d& pAt);
110
111 // The Spriter character folder authored for a guest type in catalogue/
112 // guests.yml ("character" param). Empty if the type has none - viewCreate
113 // then falls back to cycling the guestNN placeholders. Loaded once, lazily.
114 const fsStr& characterForType(const fsStr& pGuestType);
115 void characterTableEnsureLoaded();
116
117 // Re-issues animationPlay only on change (else the clip restarts each frame).
118 void animationSet(SGuestView& pView, const fsStr& pAnimation);
119
120 // Steps toward pTarget; true while travelling. pArriveInMs is the sim's
121 // remaining travel time (paces the walk to it); 0 = default speed.
122 fsBool moveToward(SGuestView& pView, const fsVec2d& pTarget, fsS32 pDeltaMs,
123 fsS32 pArriveInMs = 0) const;
124
125 // As moveToward, but routes around uncleared forest: follows a BFS cell path
126 // from the guest's current cell to pTarget (recomputed only when the target
127 // cell changes). Falls back to a straight line when no path exists (open map,
128 // off-grid spawn), so behaviour on a fully-cleared park is unchanged.
129 fsBool moveTowardRouted(SGuestView& pView, fsNTileMap::fsCView* const pTileView,
130 const gfCParkLevelComponent* const pLevel,
131 const fsVec2d& pTarget, fsS32 pDeltaMs, fsS32 pArriveInMs) const;
132 void pathEnsure(SGuestView& pView, fsNTileMap::fsCView* const pTileView,
133 const gfCParkLevelComponent* const pLevel, const fsVec2d& pTarget) const;
134 fsF32 pathRemainingLength(const SGuestView& pView) const;
135 fsBool advanceAlongPath(SGuestView& pView, fsF32 pStep) const;
136
137 // Pins a tick/cross above a just-departed guest, from the sim's one-tick
138 // departure list.
139 void departureFeedbackAttach(SGuestView& pView, const gfCParkDaySim* const pSim) const;
140
141 std::vector<SGuestView> mViews;
142 fsS32 mNextCharacterIndex;
143
144 // Guest-type name -> Spriter character folder, from catalogue/guests.yml.
145 std::vector<std::pair<fsStr, fsStr>> mCharacterByType;
146 fsBool mCharacterTableLoaded;
147};
148
149#endif
Definition fsCEntity.h:39
Definition fsCUniqueId.h:21
fsIComponent(fsCEntity *pParent)
Definition fsIComponent.cpp:86
Definition fsCView.h:28
Definition fsStr.h:23
Definition gfCParkDaySim.h:25
friend class fsCComponentFactory
Definition gfCParkGuestViewComponent.h:39
gfCParkGuestViewComponent(fsCEntity *const pParent)
Definition gfCParkGuestViewComponent.cpp:708
static const fsCUniqueId mTypeId
Definition gfCParkGuestViewComponent.h:43
void updateDo(fsS32 pDeltaMs) override
Definition gfCParkGuestViewComponent.cpp:487
void reset()
Definition gfCParkGuestViewComponent.cpp:694
static fsIComponent *const create(fsCEntity *const pParent)
Definition gfCParkGuestViewComponent.cpp:703
virtual ~gfCParkGuestViewComponent()
Definition gfCParkGuestViewComponent.cpp:715
static const fsStr mGuestLayerName
Definition gfCParkGuestViewComponent.h:47
Definition gfCParkLevelComponent.h:41
bool fsBool
Definition fsBaseTypes.h:26
int fsS32
Definition fsBaseTypes.h:20
float fsF32
Definition fsBaseTypes.h:28
Definition fsILayer.h:21
Definition fsVec2d.h:16