Skip to content
This repository was archived by the owner on Jan 5, 2024. It is now read-only.

Commit d1cfe58

Browse files
committed
Fix not being able to place brains anywhere under a blocked ceiling in bunker editing phase
1 parent 1ae81e1 commit d1cfe58

File tree

2 files changed

+45
-40
lines changed

2 files changed

+45
-40
lines changed

Menus/SceneEditorGUI.cpp

Lines changed: 34 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -311,7 +311,7 @@ bool SceneEditorGUI::TestBrainResidence(bool noBrainIsOK)
311311
{
312312
// Got to update the pathfinding graphs so the latest terrain is used for the below tests
313313
g_SceneMan.GetScene()->UpdatePathFinding();
314-
m_BrainSkyPathCost = g_SceneMan.GetScene()->CalculatePath(pBrain->GetPos(), Vector(pBrain->GetPos().m_X, 0), m_BrainSkyPath);
314+
UpdateBrainSkyPathAndCost(pBrain->GetPos());
315315
}
316316
else
317317
{
@@ -709,7 +709,7 @@ void SceneEditorGUI::Update()
709709
m_CursorInAir = g_SceneMan.GetTerrMatter(snappedPos.GetFloorIntX(), snappedPos.GetFloorIntY()) == g_MaterialAir;
710710

711711
// Check brain position validity with pathfinding and show a path to the sky
712-
m_BrainSkyPathCost = g_SceneMan.GetScene()->CalculatePath(m_CursorPos, Vector(m_CursorPos.m_X, 0), m_BrainSkyPath);
712+
UpdateBrainSkyPathAndCost(m_CursorPos);
713713
/*
714714
// Process the new path we now have, if any
715715
if (!m_BrainSkyPath.empty())
@@ -784,8 +784,7 @@ void SceneEditorGUI::Update()
784784
g_FrameMan.SetScreenText("Release to ADD the new object - Tap other button to cancel", g_ActivityMan.GetActivity()->ScreenOfPlayer(m_pController->GetPlayer()));
785785

786786
// Check brain position validity with pathfinding and show a path to the sky
787-
if (m_PreviousMode == INSTALLINGBRAIN)
788-
m_BrainSkyPathCost = g_SceneMan.GetScene()->CalculatePath(m_CursorPos, Vector(m_CursorPos.m_X, 0), m_BrainSkyPath);
787+
if (m_PreviousMode == INSTALLINGBRAIN) { UpdateBrainSkyPathAndCost(m_CursorPos); }
789788

790789
m_DrawCurrentObject = true;
791790

@@ -1653,31 +1652,36 @@ void SceneEditorGUI::UpdatePieMenu()
16531652
m_pPieMenu->RealignSlices();
16541653
}
16551654

1655+
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
1656+
1657+
void SceneEditorGUI::UpdateBrainSkyPathAndCost(Vector brainPos) {
1658+
int offsetX = 0;
1659+
int spacing = 20;
1660+
int orbitPosX;
1661+
// If the ceiling directly above is blocked, search the surroundings for gaps.
1662+
for (int i = 0; i < g_SceneMan.GetSceneWidth() / spacing; i++) {
1663+
orbitPosX = brainPos.GetFloorIntX() + offsetX;
1664+
if (g_SceneMan.GetTerrMatter(orbitPosX, 0) == g_MaterialAir) {
1665+
break;
1666+
} else {
1667+
offsetX = i * (i % 2 == 0 ? spacing : -spacing);
1668+
}
1669+
if (!g_SceneMan.IsWithinBounds(orbitPosX, 0)) { offsetX *= -1; }
1670+
}
1671+
m_BrainSkyPathCost = g_SceneMan.GetScene()->CalculatePath(brainPos, Vector(orbitPosX, 0), m_BrainSkyPath, 5.0F);
1672+
}
16561673

1657-
//////////////////////////////////////////////////////////////////////////////////////////
1658-
// Method: UpdateBrainPath
1659-
//////////////////////////////////////////////////////////////////////////////////////////
1660-
// Description: Updates the brain path to the current resident brain, if any. If
1661-
// there's none, the path is cleared.
1662-
1663-
bool SceneEditorGUI::UpdateBrainPath()
1664-
{
1665-
// First see if we have a brain in hand
1666-
if (m_pCurrentObject && m_pCurrentObject->IsInGroup("Brains"))
1667-
{
1668-
m_BrainSkyPathCost = g_SceneMan.GetScene()->CalculatePath(m_CursorPos, Vector(m_CursorPos.m_X, 0), m_BrainSkyPath);
1669-
return true;
1670-
}
1671-
1672-
// If not, then do we have a resident?
1673-
SceneObject *pBrain = g_SceneMan.GetScene()->GetResidentBrain(m_pController->GetPlayer());
1674-
if (pBrain)
1675-
m_BrainSkyPathCost = g_SceneMan.GetScene()->CalculatePath(pBrain->GetPos(), Vector(pBrain->GetPos().m_X, 0), m_BrainSkyPath);
1676-
else
1677-
{
1678-
m_BrainSkyPath.clear();
1679-
m_BrainSkyPathCost = 0;
1680-
return false;
1681-
}
1682-
return true;
1674+
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
1675+
1676+
bool SceneEditorGUI::UpdateBrainPath() {
1677+
if (m_pCurrentObject && m_pCurrentObject->IsInGroup("Brains")) {
1678+
UpdateBrainSkyPathAndCost(m_CursorPos);
1679+
} else if (SceneObject *residentBrain = g_SceneMan.GetScene()->GetResidentBrain(m_pController->GetPlayer())) {
1680+
UpdateBrainSkyPathAndCost(residentBrain->GetPos());
1681+
} else {
1682+
m_BrainSkyPath.clear();
1683+
m_BrainSkyPathCost = 0;
1684+
return false;
1685+
}
1686+
return true;
16831687
}

Menus/SceneEditorGUI.h

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -308,16 +308,17 @@ class SceneEditorGUI {
308308

309309
void UpdatePieMenu();
310310

311-
312-
//////////////////////////////////////////////////////////////////////////////////////////
313-
// Method: UpdateBrainPath
314-
//////////////////////////////////////////////////////////////////////////////////////////
315-
// Description: Updates the brain path to the current brain in cursor or resident
316-
// in the scene, if any. If there's none, the path is cleared.
317-
// Arguments: None.
318-
// Return value: Whether a resident brain was found in the scene.
319-
320-
bool UpdateBrainPath();
311+
/// <summary>
312+
/// Updates the path to the current brain in the cursor or resident in the scene, if any. If there's none, the path is cleared.
313+
/// </summary>
314+
/// <returns>Whether a brain was found in the cursor or the scene.</returns>
315+
bool UpdateBrainPath();
316+
317+
/// <summary>
318+
/// Updates the path from the designated position to orbit, and its cost.
319+
/// </summary>
320+
/// <param name="brainPos">The designated position of the brain.</param>
321+
void UpdateBrainSkyPathAndCost(Vector brainPos);
321322

322323

323324
enum BlinkMode

0 commit comments

Comments
 (0)