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

Function DrawItemPathfinding

TombEngine/Game/control/box.cpp:200–343  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

198}
199
200void DrawItemPathfinding(int itemNumber)
201{
202 constexpr auto MAX_DRAW_STEPS = 100;
203 constexpr auto ROOT_NODE_RADIUS = 64.0f;
204 constexpr auto INTERMEDIATE_NODE_RADIUS = 32.0f;
205
206 if (itemNumber < 0 || itemNumber >= g_Level.Items.size())
207 return;
208
209 auto& item = g_Level.Items[itemNumber];
210 if (!item.IsCreature())
211 return;
212
213 auto* creature = GetCreatureInfo(&item);
214 const auto& LOT = creature->LOT;
215
216 // Green box: current box (where creature is).
217 if (item.BoxNumber != NO_VALUE)
218 DrawBox(item.BoxNumber, Vector3(0, 1, 0));
219
220 // Blue box: TargetBox (pathfinding destination).
221 if (LOT.TargetBox != NO_VALUE)
222 DrawBox(LOT.TargetBox, Vector3(0, 0, 1));
223
224 // Cyan box: RequiredBox (if different from TargetBox).
225 if (LOT.RequiredBox != NO_VALUE && LOT.RequiredBox != LOT.TargetBox)
226 DrawBox(LOT.RequiredBox, Vector3(0, 1, 1));
227
228 if (item.BoxNumber == NO_VALUE || LOT.TargetBox == NO_VALUE)
229 return;
230
231 // Draw creature's own node.
232 auto source = item.Pose.Position.ToVector3();
233 source.y -= CLICK(1);
234 DrawDebugSphere(source, ROOT_NODE_RADIUS, Vector4::One, RendererDebugPage::PathfindingStats, false);
235 DrawDebugString(item.Name, source, Vector4::One, RendererDebugPage::PathfindingStats);
236
237 // If target is not bound to enemy, indicate it.
238 auto target = LOT.Target.ToVector3();
239 bool drawName = creature->Enemy != nullptr && Vector3i::Distance(creature->Enemy->Pose.Position, LOT.Target) <= BLOCK(1);
240 target.y -= ROOT_NODE_RADIUS;
241
242 // Draw target node.
243 DrawDebugSphere(target, ROOT_NODE_RADIUS, Vector4::One, RendererDebugPage::PathfindingStats, false);
244 DrawDebugString(drawName ? creature->Enemy->Name : "< PENDING >", target, Vector4::One, RendererDebugPage::PathfindingStats);
245
246 // If creature got a penalty for accessing bad box, remember it for further indication.
247 int blinkingBox = NO_VALUE;
248 for (auto& badBox : LOT.BadBoxes)
249 {
250 int cooldownLimit = g_GameFlow->GetSettings()->Pathfinding.CollisionPenaltyCooldown * FPS;
251 if (badBox.BoxNumber != NO_VALUE && badBox.Count < -(cooldownLimit / 2))
252 {
253 blinkingBox = badBox.BoxNumber;
254 break;
255 }
256 }
257

Callers 1

DrawPathfindingDebugFunction · 0.85

Calls 14

GetCreatureInfoFunction · 0.85
DrawBoxFunction · 0.85
DrawDebugSphereFunction · 0.85
DrawDebugStringFunction · 0.85
GetBoxCenterFunction · 0.85
DrawDebugLineFunction · 0.85
PrintDebugMessageFunction · 0.85
IsCreatureMethod · 0.80
GetSettingsMethod · 0.80
Vector3Function · 0.50
Vector4Function · 0.50
formatFunction · 0.50

Tested by

no test coverage detected