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
54 // Shifts every guest's position and path waypoints to stay attached to
55 // the ground as the camera scrolls (see gfCParkLevelComponent::scrollRefresh).
56 void scrollShift(const fsVec2d& pDelta);
57
59
60protected:
61
62 void updateDo(fsS32 pDeltaMs) override;
63
64 static fsIComponent* const create(fsCEntity* const pParent);
66
67private:
68
69 struct SGuestView
70 {
71 fsStr mName;
72 fsCEntity* mEntity;
73 // The lead entity plus catalogue-sized visual companions. One sim agent
74 // still owns the party's needs, queue place, spending and outcome.
75 std::vector<fsCEntity*> mMemberEntities;
76 fsVec2d mPos;
77 fsF32 mFormationMinX = 0.0f;
78 fsF32 mFormationMaxX = 0.0f;
79 fsF32 mQueueOffsetX = 0.0f;
80 fsStr mAnimation;
81 fsS32 mWanderSeed;
82 fsS32 mWanderStep;
83 fsS32 mWanderPauseRemainingMs;
84 fsBool mSeen;
85 fsBool mDeparting;
86 // On arrival: false until the guest has walked in through the gate, then
87 // true for the rest of its life (it heads to its slot/park only after).
88 fsBool mEnteredGate;
89 // While departing: false = still heading to the gate, true = past the
90 // gate and heading out to the spawn point.
91 fsBool mReachedGate;
92 // Set once per walk, when this view has told the sim the distance-based
93 // travel time for its current slot (so the walk is a constant speed).
94 fsBool mTravelPaced;
95 // Remaining view-local waypoints for the current routed walk (front = next).
96 // Empty means "walk straight". mPathTarget* is the grid cell the current
97 // route heads to, so it is only recomputed when the destination changes.
98 std::vector<fsVec2d> mPath;
99 fsVec2d mPathTarget;
100 fsS32 mPathTargetCol;
101 fsS32 mPathTargetRow;
102 };
103
104 // Where a guest with no slot yet mills about (park centre, not the gate).
105 fsVec2d parkCentreGet(fsNTileMap::fsCView* const pView) const;
106
107 fsNTileMap::fsCView* viewGet() const;
108
109 // Find-or-create the guest layer (at the view origin).
110 fsCEntity* guestLayerGet(fsNTileMap::fsCView* const pView) const;
111
112 // Centre of a named TMX object in view-local space. False if not found.
113 fsBool mapPointGet(fsNTileMap::fsCView* const pView, const fsStr& pObjectName, fsVec2d& pOut) const;
114
115 SGuestView* viewFind(const fsStr& pGuestName);
116 SGuestView& viewCreate(fsNTileMap::fsCView* const pView, const fsStr& pGuestName,
117 const fsStr& pGuestType, fsS32 pPartySize, const fsVec2d& pAt);
118
119 // The Spriter character folder authored for a guest type in catalogue/
120 // guests.yml ("character" param). Empty if the type has none - viewCreate
121 // then falls back to cycling the guestNN placeholders. Loaded once, lazily.
122 const fsStr& characterForType(const fsStr& pGuestType);
123 void characterTableEnsureLoaded();
124
125 // Re-issues animationPlay only on change (else the clip restarts each frame).
126 void animationSet(SGuestView& pView, const fsStr& pAnimation);
127
128 // Follows a grid route around uncleared forest. Returns true while travelling.
129 // pArriveInMs sets the travel pace when positive; otherwise use walking speed.
130 fsBool moveTowardRouted(SGuestView& pView, fsNTileMap::fsCView* const pTileView,
131 const gfCParkLevelComponent* const pLevel,
132 const fsVec2d& pTarget, fsS32 pDeltaMs, fsS32 pArriveInMs) const;
133 void pathEnsure(SGuestView& pView, fsNTileMap::fsCView* const pTileView,
134 const gfCParkLevelComponent* const pLevel, const fsVec2d& pTarget) const;
135 fsF32 pathRemainingLength(const SGuestView& pView) const;
136 fsBool advanceAlongPath(SGuestView& pView, fsF32 pStep) const;
137
138 // Pins a tick/cross above a just-departed guest, from the sim's one-tick
139 // departure list.
140 void departureFeedbackAttach(SGuestView& pView, const gfCParkDaySim* const pSim) const;
141
142 std::vector<SGuestView> mViews;
143 fsS32 mNextCharacterIndex;
144
145 // Guest-type name -> Spriter character folder, from catalogue/guests.yml.
146 std::vector<std::pair<fsStr, fsStr>> mCharacterByType;
147 fsBool mCharacterTableLoaded;
148};
149
150#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:745
static const fsCUniqueId mTypeId
Definition gfCParkGuestViewComponent.h:43
void updateDo(fsS32 pDeltaMs) override
Definition gfCParkGuestViewComponent.cpp:469
void reset()
Definition gfCParkGuestViewComponent.cpp:714
static fsIComponent *const create(fsCEntity *const pParent)
Definition gfCParkGuestViewComponent.cpp:740
void scrollShift(const fsVec2d &pDelta)
Definition gfCParkGuestViewComponent.cpp:723
virtual ~gfCParkGuestViewComponent()
Definition gfCParkGuestViewComponent.cpp:752
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