Skip to content

Commit 1f7f64f

Browse files
committed
Prevent rescuing in soccer mode to go back to self goal immediately
1 parent 4872276 commit 1f7f64f

File tree

4 files changed

+32
-12
lines changed

4 files changed

+32
-12
lines changed

src/modes/soccer_world.cpp

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@
3838
#include "network/stk_host.hpp"
3939
#include "physics/physics.hpp"
4040
#include "states_screens/race_gui_base.hpp"
41+
#include "tracks/graph.hpp"
42+
#include "tracks/quad.hpp"
4143
#include "tracks/track.hpp"
4244
#include "tracks/track_object_manager.hpp"
4345
#include "tracks/track_sector.hpp"
@@ -211,10 +213,10 @@ const std::string& SoccerWorld::getIdent() const
211213
void SoccerWorld::update(int ticks)
212214
{
213215
updateBallPosition(ticks);
216+
updateSectorForKarts();
214217
if (Track::getCurrentTrack()->hasNavMesh() &&
215218
!NetworkConfig::get()->isNetworking())
216219
{
217-
updateSectorForKarts();
218220
updateAIData();
219221
}
220222

@@ -808,13 +810,26 @@ int SoccerWorld::getTeamNum(SoccerTeam team) const
808810
//-----------------------------------------------------------------------------
809811
unsigned int SoccerWorld::getRescuePositionIndex(AbstractKart *kart)
810812
{
811-
std::map<int, unsigned int>::const_iterator n =
812-
m_kart_position_map.find(kart->getWorldKartId());
813-
814-
assert (n != m_kart_position_map.end());
815-
return n->second;
813+
int last_valid_node =
814+
getTrackSector(kart->getWorldKartId())->getLastValidGraphNode();
815+
if (last_valid_node >= 0)
816+
return last_valid_node;
817+
Log::warn("SoccerWorld", "Missing last valid node for rescuing");
818+
return 0;
816819
} // getRescuePositionIndex
817820

821+
//-----------------------------------------------------------------------------
822+
btTransform SoccerWorld::getRescueTransform(unsigned int rescue_pos) const
823+
{
824+
const Vec3 &xyz = Graph::get()->getQuad(rescue_pos)->getCenter();
825+
const Vec3 &normal = Graph::get()->getQuad(rescue_pos)->getNormal();
826+
btTransform pos;
827+
pos.setOrigin(xyz);
828+
btQuaternion q1 = shortestArcQuat(Vec3(0.0f, 1.0f, 0.0f), normal);
829+
pos.setRotation(q1);
830+
return pos;
831+
} // getRescueTransform
832+
818833
//-----------------------------------------------------------------------------
819834
void SoccerWorld::enterRaceOverState()
820835
{

src/modes/soccer_world.hpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -329,7 +329,8 @@ class SoccerWorld : public WorldWithRank
329329
virtual void reset() OVERRIDE;
330330

331331
virtual unsigned int getRescuePositionIndex(AbstractKart *kart) OVERRIDE;
332-
332+
virtual btTransform getRescueTransform(unsigned int rescue_pos) const
333+
OVERRIDE;
333334
virtual bool useFastMusicNearEnd() const OVERRIDE { return false; }
334335
virtual void getKartsDisplayInfo(
335336
std::vector<RaceGUIBase::KartIconDisplayInfo> *info) OVERRIDE {}

src/tracks/track_sector.cpp

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -74,18 +74,21 @@ void TrackSector::update(const Vec3 &xyz, bool ignore_vertical)
7474
prev_sector, test_nodes, ignore_vertical);
7575
}
7676

77-
// ArenaGraph (battle and soccer mode) doesn't need the code below
78-
if (ag) return;
77+
// Keep the last valid graph node for arena mode
78+
if (ag)
79+
{
80+
if (prev_sector != Graph::UNKNOWN_SECTOR)
81+
m_last_valid_graph_node = prev_sector;
82+
return;
83+
}
7984

8085
// keep the current quad as the latest valid one IF the player has one
8186
// of the required checklines
8287
const DriveNode* dn = DriveGraph::get()->getNode(m_current_graph_node);
8388
const std::vector<int>& checkline_requirements = dn->getChecklineRequirements();
8489

85-
bool isValidQuad = false;
8690
if (checkline_requirements.size() == 0)
8791
{
88-
isValidQuad = true;
8992
if (m_on_road)
9093
m_last_valid_graph_node = m_current_graph_node;
9194
}
@@ -98,7 +101,6 @@ void TrackSector::update(const Vec3 &xyz, bool ignore_vertical)
98101
//has_prerequisite = true;
99102
if (m_on_road)
100103
m_last_valid_graph_node = m_current_graph_node;
101-
isValidQuad = true;
102104
break;
103105
}
104106
}

src/tracks/track_sector.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,8 @@ class TrackSector
8181
bool isOnRoad() const { return m_on_road; }
8282
// ------------------------------------------------------------------------
8383
void setLastTriggeredCheckline(int i) { m_last_triggered_checkline = i; }
84+
// ------------------------------------------------------------------------
85+
int getLastValidGraphNode() const { return m_last_valid_graph_node; }
8486

8587
}; // TrackSector
8688

0 commit comments

Comments
 (0)