MCPcopy Create free account
hub / github.com/TombEngine/TombEngine / CanCrouchRoll

Function CanCrouchRoll

TombEngine/Game/Lara/PlayerContext.cpp:506–550  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

504 }
505
506 bool CanCrouchRoll(const ItemInfo& item, const CollisionInfo& coll)
507 {
508 constexpr auto FLOOR_BOUND = CRAWL_STEPUP_HEIGHT;
509 constexpr auto FLOOR_TO_CEIL_HEIGHT_MAX = LARA_HEIGHT_CRAWL;
510 constexpr auto WATER_HEIGHT_MAX = -CLICK(1);
511 constexpr auto PROBE_DIST_MAX = BLOCK(1);
512 constexpr auto STEP_DIST = BLOCK(0.25f);
513
514 const auto& player = GetLaraInfo(item);
515
516 // 1) Check if crouch roll is enabled.
517 if (!g_GameFlow->GetSettings()->Animations.CrouchRoll)
518 return false;
519
520 // 2) Test water depth.
521 if (player.Context.WaterSurfaceDist < WATER_HEIGHT_MAX)
522 return false;
523
524 // TODO: Extend point collision struct to also find water depths.
525 float dist = 0.0f;
526 auto pointColl0 = GetPointCollision(item);
527
528 // 3) Test continuity of path.
529 while (dist < PROBE_DIST_MAX)
530 {
531 // Get point collision.
532 dist += STEP_DIST;
533 auto pointColl1 = GetPointCollision(item, item.Pose.Orientation.y, dist, -LARA_HEIGHT_CRAWL);
534
535 int floorHeightDelta = abs(pointColl0.GetFloorHeight() - pointColl1.GetFloorHeight());
536 int floorToCeilHeight = abs(pointColl1.GetCeilingHeight() - pointColl1.GetFloorHeight());
537
538 // Assess point collision.
539 if (floorHeightDelta > FLOOR_BOUND || // Avoid floor height delta beyond crawl stepup threshold.
540 floorToCeilHeight <= FLOOR_TO_CEIL_HEIGHT_MAX || // Avoid narrow spaces.
541 pointColl1.IsSteepFloor()) // Avoid slippery floor slopes.
542 {
543 return false;
544 }
545
546 pointColl0 = std::move(pointColl1);
547 }
548
549 return true;
550 }
551
552 bool CanCrawlForward(const ItemInfo& item, const CollisionInfo& coll)
553 {

Callers 7

lara_as_crouch_idleFunction · 0.85
lara_as_crouch_turn_leftFunction · 0.85
lara_as_crawl_idleFunction · 0.85
lara_as_crawl_forwardFunction · 0.85
lara_as_crawl_turn_leftFunction · 0.85
lara_as_crawl_turn_rightFunction · 0.85

Calls 5

GetPointCollisionFunction · 0.85
GetSettingsMethod · 0.80
GetFloorHeightMethod · 0.45
GetCeilingHeightMethod · 0.45
IsSteepFloorMethod · 0.45

Tested by

no test coverage detected