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

Function StalkBox

TombEngine/Game/control/box.cpp:2071–2108  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2069}
2070
2071bool StalkBox(ItemInfo* item, ItemInfo* enemy, int boxNumber)
2072{
2073 if (enemy == nullptr || boxNumber == NO_VALUE)
2074 return false;
2075
2076 auto* box = &g_Level.PathfindingBoxes[boxNumber];
2077 int stalkDistance = g_GameFlow->GetSettings()->Pathfinding.StalkDistance;
2078
2079 int xRange = stalkDistance + ((box->bottom - box->top) * BLOCK(1));
2080 int zRange = stalkDistance + ((box->right - box->left) * BLOCK(1));
2081
2082 int x = (box->top + box->bottom) * BLOCK(1) / 2 - enemy->Pose.Position.x;
2083 int z = (box->left + box->right) * BLOCK(1) / 2 - enemy->Pose.Position.z;
2084
2085 if (x > xRange || x < -xRange || z > zRange || z < -zRange)
2086 return false;
2087
2088 int enemyQuad = (enemy->Pose.Orientation.y / ANGLE(90.0f)) + 2;
2089 int boxQuad;
2090 if (z > 0)
2091 boxQuad = (x > 0) ? 2 : 1;
2092 else
2093 boxQuad = (x > 0) ? 3 : 0;
2094
2095 if (enemyQuad == boxQuad)
2096 return false;
2097
2098 int baddyQuad = 0;
2099 if (item->Pose.Position.z > enemy->Pose.Position.z)
2100 baddyQuad = (item->Pose.Position.x > enemy->Pose.Position.x) ? 2 : 1;
2101 else
2102 baddyQuad = (item->Pose.Position.x > enemy->Pose.Position.x) ? 3 : 0;
2103
2104 if (enemyQuad == baddyQuad && abs(enemyQuad - boxQuad) == 2)
2105 return false;
2106
2107 return true;
2108}
2109
2110// TODO: Do it via Lua instead. -- TokyoSU 22.12.21
2111bool IsCreatureVaultAvailable(ItemInfo* item, int stepCount)

Callers 1

CreatureMoodFunction · 0.85

Calls 2

ANGLEFunction · 0.85
GetSettingsMethod · 0.80

Tested by

no test coverage detected