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
/********************************************************************
*
*	File:		gfCParkStaffViewComponent.h
*
*	Purpose:	Draws the park's staff: kiosk staff at their building,
*				repair staff out at a breakdown or idling at the
*				staffOffice. Positioning lives here (the sim is
*				spatial-free) and needs no new sim API - staff are
*				anonymous pools, so one entity per hired head is
*				reconciled to jobs derived from the slots. Keyed by
*				person, not job, so the same figure walks out and back
*				(see SStaffView).
*
*********************************************************************/

#ifndef gfCParkStaffViewComponenthdr
#define gfCParkStaffViewComponenthdr

#include <vector>

#include <fsCore/src/fsCUniqueId.h>
#include <fsCore/fsStr.h>
#include <fsCore/fsVec2d.h>

#include <fsAppCore/src/components/fsIComponent.h>

class fsCEntity;
class gfCParkDaySim;
class gfCParkLevelComponent;

namespace fsNTileMap
{
	class fsCView;
}

class gfCParkStaffViewComponent : public fsIComponent
{
	friend class fsCComponentFactory;

public:

	static const fsCUniqueId mTypeId;

	virtual ~gfCParkStaffViewComponent();

protected:

	void updateDo(fsS32 pDeltaMs) override;

	static fsIComponent* const create(fsCEntity* const pParent);
	gfCParkStaffViewComponent(fsCEntity* const pParent);

private:

	struct SStaffView
	{
		// A person, not a job: "<type>:<index>", stable while hired. Keying by
		// job made counts drift (a walking-out repairer plus their replacement).
		fsStr mKey;
		fsStr mType;
		fsS32 mIndex;
		// Slot posted to (empty off duty). Kept so they don't swap buildings
		// when the post list is rebuilt in a different order.
		fsStr mAssignedSlot;
		fsCEntity* mEntity;
		fsVec2d mPos;
		fsVec2d mTarget;
		fsStr mAnimation;
		// Remaining view-local waypoints of the current routed walk (front = next);
		// mPathTarget* is the destination cell, so the route only recomputes when
		// the target changes. Empty means walk straight.
		std::vector<fsVec2d> mPath;
		fsS32 mPathTargetCol = -999;
		fsS32 mPathTargetRow = -999;
	};

	struct SStaffPost
	{
		fsStr mSlotName;
		fsVec2d mPos;
	};

	fsNTileMap::fsCView* viewGet() const;
	fsBool mapPointGet(fsNTileMap::fsCView* const pView, const fsStr& pObjectName, fsVec2d& pOut) const;

	SStaffView* viewFind(const fsStr& pKey);
	SStaffView& viewCreate(fsNTileMap::fsCView* const pView, const fsStr& pKey, const fsStr& pType,
	                       fsS32 pIndex, const fsStr& pCharacterFolder, const fsVec2d& pAt);

	void animationSet(SStaffView& pView, const fsStr& pAnimation);
	fsBool moveToward(SStaffView& pView, const fsVec2d& pTarget, fsS32 pDeltaMs) const;

	// Constant-speed walk that routes around uncleared forest via a BFS cell path
	// (recomputed only when the destination cell changes), falling back to a
	// straight line when no route exists. pView (the tile view) and pLevel supply
	// the walkability grid.
	fsBool moveTowardRouted(SStaffView& pStaff, fsNTileMap::fsCView* const pTileView,
	                        const gfCParkLevelComponent* const pLevel,
	                        const fsVec2d& pTarget, fsS32 pDeltaMs) const;

	// Reconciles one staff type: exactly staffTotalGet(pType) entities exist,
	// each keeps its post, spare posts go to the off-duty, the rest idle.
	void staffTypeUpdate(fsNTileMap::fsCView* const pView, const gfCParkDaySim* const pSim,
	                     const fsStr& pType, const fsStr& pCharacterFolder,
	                     const std::vector<SStaffPost>& pPosts, const fsVec2d& pOfficePos,
	                     fsBool pReWander);

	std::vector<SStaffView> mViews;
	fsS32 mIdleWanderMs;
	fsS32 mWanderSeed;
};

#endif