@@ -311,7 +311,7 @@ bool SceneEditorGUI::TestBrainResidence(bool noBrainIsOK)
311
311
{
312
312
// Got to update the pathfinding graphs so the latest terrain is used for the below tests
313
313
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 ());
315
315
}
316
316
else
317
317
{
@@ -709,7 +709,7 @@ void SceneEditorGUI::Update()
709
709
m_CursorInAir = g_SceneMan.GetTerrMatter (snappedPos.GetFloorIntX (), snappedPos.GetFloorIntY ()) == g_MaterialAir;
710
710
711
711
// 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);
713
713
/*
714
714
// Process the new path we now have, if any
715
715
if (!m_BrainSkyPath.empty())
@@ -784,8 +784,7 @@ void SceneEditorGUI::Update()
784
784
g_FrameMan.SetScreenText (" Release to ADD the new object - Tap other button to cancel" , g_ActivityMan.GetActivity ()->ScreenOfPlayer (m_pController->GetPlayer ()));
785
785
786
786
// 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); }
789
788
790
789
m_DrawCurrentObject = true ;
791
790
@@ -1653,31 +1652,36 @@ void SceneEditorGUI::UpdatePieMenu()
1653
1652
m_pPieMenu->RealignSlices ();
1654
1653
}
1655
1654
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
+ }
1656
1673
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 ;
1683
1687
}
0 commit comments