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
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717 |
#include "gfCParkGuestViewComponent.h"
#include <cmath>
#include <memory>
#include <fsCore/fsIFile.h>
#include <fsCore/src/fsCResourceName.h>
#include <fsCore/src/debug/fsLog.h>
#include <fsAppCore/src/fsCAppCoreMain.h>
#include <fsAppCore/src/fsCEntity.h>
#include <fsAppCore/src/fsCEntityFactory.h>
#include <fsAppCore/fsIScene.h>
#include <fsRenderer/src/fsCBrushManager.h>
#include <fsRenderer/src/components/fsCAnimatingSpriteComponent.h>
#include <fsRenderer/src/components/fsCSpriteComponent.h>
#include <fsTileMap/fsITileMap.h>
#include <fsTileMap/fsIObject.h>
#include <fsTileMap/fsILayer.h>
#include <fsTileMap/src/fsCView.h>
#include <gfCatalogue/src/gfCCatalogueParserYaml.h>
#include <gfCatalogue/src/gfCCatalogueCatalogue.h>
#include <gfCatalogue/src/gfCCatalogueItem.h>
#include "gfCParkLevelComponent.h"
#include "sim/gfCParkDaySim.h"
#include "sim/gfCGuestAgentSim.h"
const fsCUniqueId gfCParkGuestViewComponent::mTypeId("gfCParkGuestViewComponent");
const fsStr gfCParkGuestViewComponent::mGuestLayerName("guestLayer");
namespace
{
// Placeholder tuning.
const fsF32 gGuestSpeedPxPerMs = 0.12f;
// Spriter characters are far larger than a guest should read on a 32px map.
const fsF32 gGuestScale = 0.25f;
// Parties can be roughly 70px wide, so queue whole parties at that spacing
// rather than packing their lead characters together and overlapping companions.
const fsF32 gQueueSpacingPx = 76.0f;
// A small deterministic walking loop around the park centre. These remain
// presentation-only until maps begin authoring their own trail waypoints.
const fsS32 gWanderPointCount = 8;
const fsF32 gWanderPointX[gWanderPointCount] = {-100.0f, -35.0f, 55.0f, 110.0f,
95.0f, 25.0f, -65.0f, -115.0f};
const fsF32 gWanderPointY[gWanderPointCount] = {-45.0f, -90.0f, -80.0f, -20.0f,
55.0f, 90.0f, 75.0f, 20.0f};
const fsS32 gWanderPauseMs = 1200;
const fsS32 gCharacterVariants = 3;
// Individual timing avoids the mechanical effect of every visitor landing on
// the same walk frame. The range stays deliberately narrow so feet still read
// naturally against the party's shared movement speed.
const fsF32 gAnimationSpeedMin = 0.94f;
const fsF32 gAnimationSpeedStep = 0.015f;
const fsS32 gAnimationSpeedVariants = 9;
const fsS32 gAnimationPhaseSpreadMs = 360;
void guestAnimationTimingSet(fsCAnimatingSpriteComponent* const pAnimation,
fsS32 pPartySeed, fsS32 pMemberIndex)
{
const fsS32 timingSeed = pPartySeed * 7 + pMemberIndex * 11;
const fsF32 speed = gAnimationSpeedMin
+ static_cast<fsF32>(timingSeed % gAnimationSpeedVariants) * gAnimationSpeedStep;
pAnimation->animationSpeedSet(speed);
pAnimation->animationStartOffsetSet((timingSeed * 47) % gAnimationPhaseSpreadMs);
}
// Companion offsets are in the lead character's unscaled local space. They
// form a loose, irregular group after the 0.25 character scale is applied.
// Each party mirrors and nudges this shape from its stable character seed, so
// families and school groups do not all march in an identical block.
const fsS32 gPartyCompanionCount = 4;
const fsS32 gPartyCompanionX[gPartyCompanionCount] = {-110, 80, -170, 145};
const fsS32 gPartyCompanionY[gPartyCompanionCount] = {15, -35, 85, 65};
// The off-screen point (above the crop line, on the gate's centre line) where
// guests appear and, on leaving, finally exit.
const fsStr gSpawnObjectName("guestSpawn");
// The visible gate. A departing guest walks here first, then on to the spawn
// point, so it exits through the gate rather than cutting straight across the
// park to the off-screen point.
const fsStr gGateObjectName("parkGate");
// Feedback marker, in the guest's own 0.25-scaled local space.
const fsS32 gFeedbackIconSize = 200;
const fsS32 gFeedbackIconOffsetY = -260;
const fsStr gHappyIcon("gui/park/guestHappy.png");
const fsStr gUnhappyIcon("gui/park/guestUnhappy.png");
}
fsNTileMap::fsCView* gfCParkGuestViewComponent::viewGet() const
{
return dynamic_cast<fsNTileMap::fsCView*>(
fsCAppCoreMain::instanceGet()->sceneGet()->childFind("tilemapView"));
}
fsVec2d gfCParkGuestViewComponent::parkCentreGet(fsNTileMap::fsCView* const pView) const
{
fsNTileMap::fsITileMap* const map = pView->mMap;
const fsPoint centre = pView->mapPixelToLocal(
fsPoint(map->widthGet() * map->tileWidthGet() / 2,
map->heightGet() * map->tileHeightGet() / 2));
return fsVec2d(static_cast<fsF32>(centre.x), static_cast<fsF32>(centre.y));
}
fsCEntity* gfCParkGuestViewComponent::guestLayerGet(fsNTileMap::fsCView* const pView) const
{
if (fsCEntity* const existing = pView->childFind(mGuestLayerName))
{
return existing;
}
fsCEntity* const layer = pView->entityFactoryGet()->emptyEntityCreate(mGuestLayerName);
pView->childAdd(layer);
return layer;
}
fsBool gfCParkGuestViewComponent::mapPointGet(fsNTileMap::fsCView* const pView, const fsStr& pObjectName,
fsVec2d& pOut) const
{
if (fsCEntity* const levelEnt =
fsCAppCoreMain::instanceGet()->sceneGet()->firstEntityWithComponentsOfFamilyType<gfCParkLevelComponent>())
{
if (gfCParkLevelComponent* const level =<--- Variable 'level' can be declared as pointer to const
levelEnt->firstComponentOfFamilyType<gfCParkLevelComponent>())
{
if (level->runtimeSlotPositionGet(pObjectName, pOut))
{
return true;
}
}
}
fsNTileMap::fsITileMap* const map = pView->mMap;
for (fsS32 layer = 0; layer < map->layerCountGet(); ++layer)
{
if (fsNTileMap::fsILayer::eType::OBJECT != map->layerTypeGet(layer))
{
continue;
}
for (fsNTileMap::fsIObjectRef const& obj : map->triggersGet(layer))
{
if (obj->nameGet() != pObjectName)
{
continue;
}
// Same map-pixel -> view-local transform as everything else.
const fsPoint pos = obj->posGet();
const fsPoint topLeft = pView->mapPixelToLocal(pos);
const fsPoint botRight = pView->mapPixelToLocal(
fsPoint(pos.x + obj->widthGet(), pos.y + obj->heightGet()));
pOut = fsVec2d((topLeft.x + botRight.x) / 2.0f, (topLeft.y + botRight.y) / 2.0f);
return true;
}
}
return false;
}
gfCParkGuestViewComponent::SGuestView* gfCParkGuestViewComponent::viewFind(const fsStr& pGuestName)
{
for (SGuestView& view : mViews)
{
if (view.mName == pGuestName)
{<--- Consider using std::find_if algorithm instead of a raw loop.
return &view;
}
}
return nullptr;
}
const fsStr& gfCParkGuestViewComponent::characterForType(const fsStr& pGuestType)
{
characterTableEnsureLoaded();
for (const std::pair<fsStr, fsStr>& entry : mCharacterByType)
{
if (entry.first == pGuestType)
{<--- Consider using std::find_if algorithm instead of a raw loop.
return entry.second;
}
}
static const fsStr sNone;
return sNone;
}
void gfCParkGuestViewComponent::characterTableEnsureLoaded()
{
if (mCharacterTableLoaded)
{
return;
}
mCharacterTableLoaded = true;
// Same catalogue root gfCParkLevelComponent loads guest templates from -
// read here purely for the per-type "character" art param, so which
// character art a guest wears is authored content, not baked into the SDK.
gfCCatalogueParserYaml parser;
std::unique_ptr<gfCCatalogueCatalogue> catalogue(parser.catalogueLoad("catalogue/guests.yml"));
if (!catalogue)
{
return;
}
for (fsS32 i = 0; i < catalogue->numChildrenGet(); ++i)
{
if (const auto* const item = dynamic_cast<const gfCCatalogueItem*>(catalogue->childGetByIndex(i)))
{
const fsStr& character = item->paramGet("character");
if (!character.emptyGet())
{
mCharacterByType.push_back(std::make_pair(item->nameGet(), character));
}
}
}
}
gfCParkGuestViewComponent::SGuestView& gfCParkGuestViewComponent::viewCreate(
fsNTileMap::fsCView* const pView, const fsStr& pGuestName, const fsStr& pGuestType,
fsS32 pPartySize, const fsVec2d& pAt)
{
SGuestView view;
view.mName = pGuestName;
view.mPos = pAt;
view.mSeen = true;
view.mDeparting = false;
view.mEnteredGate = false;
view.mReachedGate = false;
view.mTravelPaced = false;
view.mWanderSeed = mNextCharacterIndex;
view.mWanderStep = 0;
view.mWanderPauseRemainingMs = 0;
view.mPathTargetCol = -999;
view.mPathTargetRow = -999;
view.mEntity = pView->entityFactoryGet()->emptyEntityCreate(pGuestName);
view.mEntity->posSet(pAt);
view.mEntity->scaleSet(fsVec2d(gGuestScale, gGuestScale));
view.mMemberEntities.push_back(view.mEntity);
// Character art is catalogue-driven per guest type; fall back to cycling the
// guestNN placeholders only for a type that authored no "character" param.
const fsStr& character = characterForType(pGuestType);
const fsStr animFile = !character.emptyGet()
? fsStr("characters/") + character + "/Animations.scml"
: fsStr("characters/guest0") + fsStr(1 + (mNextCharacterIndex % gCharacterVariants)) + "/Animations.scml";
const fsS32 partyCharacterSeed = mNextCharacterIndex++;
const fsCResourceName animRes(animFile, fsCResourceName::eRES_LOCATION_ASSETS);
if (fsIFile::fileExistsGet(animRes))
{
fsCAnimatingSpriteComponent* const animation =
view.mEntity->componentAdd<fsCAnimatingSpriteComponent>();
animation->animationDataSet(animRes, false);
guestAnimationTimingSet(animation, partyCharacterSeed, 0);
}
else
{
// Otherwise the guest silently never appears.
fsLogError("Guest animation not found: %s", animFile.utf8Get());
}
const fsS32 partySize = pPartySize > 1 ? (pPartySize < 5 ? pPartySize : 5) : 1;
const fsS32 formationDirection = (partyCharacterSeed % 2) ? -1 : 1;
const fsS32 formationYNudge = ((partyCharacterSeed % 3) - 1) * 18;
for (fsS32 memberIndex = 1; memberIndex < partySize; ++memberIndex)
{
fsCEntity* const companion = pView->entityFactoryGet()->emptyEntityCreate(
pGuestName + "Member" + fsStr(memberIndex));
companion->posSet(fsPoint(
gPartyCompanionX[memberIndex - 1] * formationDirection,
gPartyCompanionY[memberIndex - 1] + formationYNudge));
const fsS32 variant = 1 + ((partyCharacterSeed + memberIndex) % gCharacterVariants);
const fsStr companionAnimFile =
fsStr("characters/guest0") + fsStr(variant) + "/Animations.scml";
const fsCResourceName companionAnimRes(
companionAnimFile,
fsCResourceName::eRES_LOCATION_ASSETS);
if (fsIFile::fileExistsGet(companionAnimRes))
{
fsCAnimatingSpriteComponent* const animation =
companion->componentAdd<fsCAnimatingSpriteComponent>();
animation->animationDataSet(companionAnimRes, false);
guestAnimationTimingSet(animation, partyCharacterSeed, memberIndex);
}
else
{
fsLogError("Guest companion animation not found: %s",
companionAnimFile.utf8Get());
}
view.mEntity->childAdd(companion);
view.mMemberEntities.push_back(companion);
}
guestLayerGet(pView)->childAdd(view.mEntity);
mViews.push_back(view);
return mViews.back();
}
void gfCParkGuestViewComponent::departureFeedbackAttach(SGuestView& pView, const gfCParkDaySim* const pSim) const
{
// The departure list is cleared each tick, so this hits only on the frame
// the guest left - which is when this is called.
for (fsS32 i = 0; i < pSim->departureCountGet(); ++i)
{
const gfCParkDaySim::SDeparture* const departure = pSim->departureGetByIndex(i);
if (!departure || departure->mName != pView.mName)
{
continue;
}
const fsStr iconFile = departure->mHappy ? gHappyIcon : gUnhappyIcon;
const fsCResourceName iconRes(iconFile, fsCResourceName::eRES_LOCATION_ASSETS);
if (!fsIFile::fileExistsGet(iconRes))
{
fsLogError("Guest feedback icon not found: %s", iconFile.utf8Get());
return;
}
fsCEntity* const icon = pView.mEntity->entityFactoryGet()->emptyEntityCreate(pView.mName + "Feedback");
icon->componentAdd(fsCSpriteComponent::mTypeId);
auto* const sprt = icon->spriteComponentGet();
sprt->brushSet(fsCBrushManager::instanceGet()->get(iconRes, false));
sprt->widthSet(gFeedbackIconSize);
sprt->heightSet(gFeedbackIconSize);
icon->posSet(fsPoint(0, gFeedbackIconOffsetY));
// Parented to the guest so it rides out and dies with them.
pView.mEntity->childAdd(icon);
return;
}
}
void gfCParkGuestViewComponent::animationSet(SGuestView& pView, const fsStr& pAnimation)
{
if (pView.mAnimation == pAnimation)
{
return;
}
pView.mAnimation = pAnimation;
for (fsCEntity* const member : pView.mMemberEntities)
{
if (fsCAnimatingSpriteComponent* const anim =
member->componentGet<fsCAnimatingSpriteComponent>())
{
anim->animationPlay(pAnimation);
}
}
}
fsBool gfCParkGuestViewComponent::moveToward(SGuestView& pView, const fsVec2d& pTarget, fsS32 pDeltaMs,
fsS32 pArriveInMs) const
{
const fsF32 dx = pTarget.x - pView.mPos.x;
const fsF32 dy = pTarget.y - pView.mPos.y;
const fsF32 distance = std::sqrt(dx * dx + dy * dy);
// With a travel deadline, pace the walk to it (recomputed each frame, so it
// lands on time) rather than a fixed speed the sim doesn't know about.
const fsF32 speed = (pArriveInMs > 0)
? distance / static_cast<fsF32>(pArriveInMs)
: gGuestSpeedPxPerMs;
const fsF32 step = speed * static_cast<fsF32>(pDeltaMs);
if (distance <= step || distance < 1.0f)
{
pView.mPos = pTarget;
pView.mEntity->posSet(pView.mPos);
return false;
}
pView.mPos.x += (dx / distance) * step;
pView.mPos.y += (dy / distance) * step;
pView.mEntity->posSet(pView.mPos);
return true;
}
void gfCParkGuestViewComponent::pathEnsure(SGuestView& pView, fsNTileMap::fsCView* const pTileView,
const gfCParkLevelComponent* const pLevel,
const fsVec2d& pTarget) const
{
const fsPoint targetCell = pLevel->cellFromLocal(pTileView, pTarget);
if (targetCell.x == pView.mPathTargetCol && targetCell.y == pView.mPathTargetRow &&
!pView.mPath.empty())
{
return;
}
pView.mPathTargetCol = targetCell.x;
pView.mPathTargetRow = targetCell.y;
pView.mPath.clear();
// A target on forest (a wander point, the park centre before a slot is chosen)
// is pulled to the nearest open cell, and the walk finishes on that cell's
// centre rather than the forest point - so guests never step onto uncleared
// ground even while milling about.
const fsPoint routeCell = pLevel->nearestWalkableCell(pTileView, targetCell);
const fsBool targetWalkable = (routeCell.x == targetCell.x && routeCell.y == targetCell.y);
const fsVec2d finalPoint = targetWalkable
? pTarget
: pLevel->cellCentreLocal(pTileView, routeCell.x, routeCell.y);
const fsPoint fromCell = pLevel->cellFromLocal(pTileView, pView.mPos);
const std::vector<fsPoint> cells = pLevel->pathFindCells(pTileView, fromCell, routeCell);
if (cells.size() >= 2)
{
// Steer through the centre of each intermediate cell, then finish on the
// exact target point (a slot's queue offset, the gate line) rather than a
// cell centre.
for (fsS32 i = 1; i < static_cast<fsS32>(cells.size()) - 1; ++i)
{
pView.mPath.push_back(pLevel->cellCentreLocal(pTileView, cells[i].x, cells[i].y));
}
pView.mPath.push_back(finalPoint);
}
else
{
// Same cell, off-grid, or unreachable: head straight for the target.
pView.mPath.push_back(finalPoint);
}
}
fsF32 gfCParkGuestViewComponent::pathRemainingLength(const SGuestView& pView) const
{
fsF32 length = 0.0f;
fsVec2d prev = pView.mPos;
for (const fsVec2d& waypoint : pView.mPath)
{
const fsF32 dx = waypoint.x - prev.x;
const fsF32 dy = waypoint.y - prev.y;
length += std::sqrt(dx * dx + dy * dy);
prev = waypoint;
}
return length;
}
fsBool gfCParkGuestViewComponent::advanceAlongPath(SGuestView& pView, fsF32 pStep) const
{
while (pStep > 0.0f && !pView.mPath.empty())
{
const fsVec2d next = pView.mPath.front();
const fsF32 dx = next.x - pView.mPos.x;
const fsF32 dy = next.y - pView.mPos.y;
const fsF32 distance = std::sqrt(dx * dx + dy * dy);
if (distance <= pStep || distance < 0.001f)
{
pView.mPos = next;
pView.mPath.erase(pView.mPath.begin());
pStep -= distance;
}
else
{
pView.mPos.x += (dx / distance) * pStep;
pView.mPos.y += (dy / distance) * pStep;
pStep = 0.0f;
}
}
pView.mEntity->posSet(pView.mPos);
return pView.mPath.empty();
}
fsBool gfCParkGuestViewComponent::moveTowardRouted(SGuestView& pView, fsNTileMap::fsCView* const pTileView,
const gfCParkLevelComponent* const pLevel,
const fsVec2d& pTarget, fsS32 pDeltaMs,
fsS32 pArriveInMs) const
{
pathEnsure(pView, pTileView, pLevel, pTarget);
if (pView.mPath.empty())
{
return false;
}
const fsF32 remaining = pathRemainingLength(pView);
const fsF32 speed = (pArriveInMs > 0 && remaining > 0.0f)
? remaining / static_cast<fsF32>(pArriveInMs)
: gGuestSpeedPxPerMs;
const fsBool arrived = advanceAlongPath(pView, speed * static_cast<fsF32>(pDeltaMs));
return !arrived;
}
void gfCParkGuestViewComponent::updateDo(fsS32 pDeltaMs)
{
fsNTileMap::fsCView* const view = viewGet();
if (!view)
{
return;
}
gfCParkLevelComponent* const level = parentGet()->firstComponentOfFamilyType<gfCParkLevelComponent>();
gfCParkDaySim* const sim = level ? level->simGet() : nullptr;
if (!sim)
{
return;
}
fsVec2d spawnPos;
if (!mapPointGet(view, gSpawnObjectName, spawnPos))
{
// No spawn point authored - nowhere sensible to bring guests in from.
return;
}
// Gate is an optional exit waypoint; without it a guest just heads straight
// to the spawn point.
fsVec2d gatePos = spawnPos;
mapPointGet(view, gGateObjectName, gatePos);
const fsVec2d parkCentre = parkCentreGet(view);
for (SGuestView& guestView : mViews)
{
guestView.mSeen = false;
}
// Fans queued guests out sideways instead of overlapping.
std::vector<std::pair<fsStr, fsS32>> slotOccupancy;
for (fsS32 i = 0; i < sim->activeGuestCountGet(); ++i)
{
const gfCGuestAgentSim* const guest = sim->guestGetByIndex(i);
if (!guest)
{
continue;
}
SGuestView* guestView = viewFind(guest->nameGet());
if (!guestView)
{
guestView = &viewCreate(view, guest->nameGet(), guest->typeGet(),
guest->partySizeGet(), spawnPos);
}
guestView->mSeen = true;
// Names can be reused across days while an old view walks out - clear the
// departing flags on a reused view.
guestView->mDeparting = false;
guestView->mReachedGate = false;
// No slot means the visitor is exploring. Each character follows the same
// compact loop from a different starting point, pausing briefly between
// legs so wandering reads as a visit rather than constant marching.
fsVec2d target = parkCentre;
const fsStr& slotName = guest->slotNameGet();
const fsBool wandering = eGuestSimState::eWANDERING == guest->stateGet()
&& slotName.emptyGet() && guestView->mEnteredGate;
const fsBool wanderPaused = wandering && guestView->mWanderPauseRemainingMs > 0;
if (wanderPaused)
{
guestView->mWanderPauseRemainingMs -= pDeltaMs;
if (guestView->mWanderPauseRemainingMs < 0)
{
guestView->mWanderPauseRemainingMs = 0;
}
target = guestView->mPos;
}
else if (wandering)
{
const fsS32 point = (guestView->mWanderSeed + guestView->mWanderStep)
% gWanderPointCount;
target.x += gWanderPointX[point];
target.y += gWanderPointY[point];
}
if (!slotName.emptyGet())
{
guestView->mWanderPauseRemainingMs = 0;
fsVec2d slotPos;
if (mapPointGet(view, slotName, slotPos))
{
fsS32 queueIndex = 0;
fsBool counted = false;
for (std::pair<fsStr, fsS32>& occupancy : slotOccupancy)
{
if (occupancy.first == slotName)
{<--- Consider using std::find_if algorithm instead of a raw loop.
queueIndex = ++occupancy.second;
counted = true;
break;
}
}
if (!counted)
{
slotOccupancy.push_back(std::make_pair(slotName, 0));
}
target = slotPos;
target.x += queueIndex * gQueueSpacingPx;
}
}
// Entry routing: a freshly-spawned guest walks to the gate first, then on
// to its destination (a slot, or the park centre while it decides), so it
// comes in through the gate rather than straight to a building.
const fsVec2d moveTarget = guestView->mEnteredGate ? target : gatePos;
// Distance-pace only once past the gate and heading to a slot. The sim
// gave every walk the same flat travel time (which makes a far slot look
// faster); re-timing the final leg here both fixes that and restarts the
// sim's timer from the gate, so its service start lands on the guest's
// arrival at the slot despite the gate detour.
if (eGuestSimState::eWALKING == guest->stateGet() && guestView->mEnteredGate)
{
if (!guestView->mTravelPaced)
{
// Time the final leg by the actual routed distance, so a slot
// reached the long way around the forest isn't rushed.
pathEnsure(*guestView, view, level, target);
fsF32 distance = pathRemainingLength(*guestView);
if (distance <= 0.0f)
{
const fsF32 dx = target.x - guestView->mPos.x;
const fsF32 dy = target.y - guestView->mPos.y;
distance = std::sqrt(dx * dx + dy * dy);
}
fsS32 travelMs = static_cast<fsS32>(distance / gGuestSpeedPxPerMs);
if (travelMs < 1)
{
travelMs = 1;
}
sim->guestTravelTimeSet(guest->nameGet(), travelMs);
guestView->mTravelPaced = true;
}
}
else
{
// Reset so the final leg re-paces once past the gate (or after a
// re-assigned walk when a slot fills up mid-approach).
guestView->mTravelPaced = false;
}
// Constant speed to the gate; paced to the sim deadline on the final leg.
const fsS32 arriveInMs = (eGuestSimState::eWALKING == guest->stateGet() && guestView->mEnteredGate)
? guest->travelRemainingMsGet()
: 0;
// Every walk - entry, slot approach and idle wandering - routes over
// cleared cells and snaps a forest target to open ground, so characters
// never stand on or cross uncleared forest.
const fsBool moving =
moveTowardRouted(*guestView, view, level, moveTarget, pDeltaMs, arriveInMs);
if (!moving && !guestView->mEnteredGate)
{
// Reached the gate - head inward from next frame.
guestView->mEnteredGate = true;
}
else if (!moving && wandering && !wanderPaused)
{
++guestView->mWanderStep;
guestView->mWanderPauseRemainingMs = gWanderPauseMs;
}
animationSet(*guestView, moving ? "Walking" : "Idle");
}
// Gone from the sim - walk it to the gate, then out through it to the spawn
// point, then drop it.
for (std::vector<SGuestView>::iterator it = mViews.begin(); it != mViews.end(); )
{
if (it->mSeen)
{
++it;
continue;
}
// First frame gone - the only frame the departure reason is readable.
if (!it->mDeparting)
{
it->mDeparting = true;
departureFeedbackAttach(*it, sim);
}
animationSet(*it, "Walking");
const fsVec2d target = it->mReachedGate ? spawnPos : gatePos;
if (moveToward(*it, target, pDeltaMs))
{
++it;
}
else if (!it->mReachedGate)
{
// At the gate - now continue out to the off-screen spawn point.
it->mReachedGate = true;
++it;
}
else
{
it->mEntity->destroy();
it = mViews.erase(it);
}
}
}
void gfCParkGuestViewComponent::reset()
{
for (SGuestView& view : mViews)
{
view.mEntity->destroy();
}
mViews.clear();
}
fsIComponent* const gfCParkGuestViewComponent::create(fsCEntity* const pParent)
{
return new gfCParkGuestViewComponent(pParent);
}
gfCParkGuestViewComponent::gfCParkGuestViewComponent(fsCEntity* const pParent):
fsIComponent(pParent),
mNextCharacterIndex(0),
mCharacterTableLoaded(false)
{
}
gfCParkGuestViewComponent::~gfCParkGuestViewComponent()
{
}
|