diff --git a/src/modes/soccer_world.cpp b/src/modes/soccer_world.cpp index 0041f054f..43750f6df 100644 --- a/src/modes/soccer_world.cpp +++ b/src/modes/soccer_world.cpp @@ -50,6 +50,8 @@ void SoccerWorld::init() WorldWithRank::init(); m_display_rank = false; + m_check_goals_enabled = true; + // check for possible problems if AI karts were incorrectly added if(getNumKarts() > race_manager->getNumPlayers()) { @@ -98,6 +100,32 @@ void SoccerWorld::update(float dt) // TODO } // update +void SoccerWorld::onCheckGoalTriggered(bool first_goal) +{ + // TODO + if(m_check_goals_enabled) + printf("*** GOOOOOOOOOAAAAAAALLLLLL!!!! (team: %d) ***\n", first_goal ? 0 : 1); + + //m_check_goals_enabled = false; // TODO: remove? + + // Reset original positions for the soccer balls + TrackObjectManager* tom = getTrack()->getTrackObjectManager(); + assert(tom); + + PtrVector& objects = tom->getObjects(); + for(int i=0; iisSoccerBall()) + continue; + + obj->reset(); + } + + // TODO: rescue the karts + // TODO: score a point +} + //----------------------------------------------------------------------------- /** Updates the ranking of the karts. */ @@ -172,6 +200,7 @@ bool SoccerWorld::isRaceOver() */ void SoccerWorld::terminateRace() { + m_check_goals_enabled = false; updateKartRanks(); WorldWithRank::terminateRace(); } // terminateRace @@ -183,6 +212,8 @@ void SoccerWorld::restartRace() { WorldWithRank::restartRace(); + m_check_goals_enabled = true; + const unsigned int kart_amount = m_karts.size(); for(unsigned int n=0; n m_kart_info; + /** Whether or not goals can be scored (they are disabled when a point is scored + and re-enabled when the next game can be played)*/ + bool m_check_goals_enabled; + public: /** Used to show a nice graph when battle is over */ @@ -78,7 +82,7 @@ public: virtual void update(float dt); - + void onCheckGoalTriggered(bool first_goal); void updateKartRanks(); }; // SoccerWorld diff --git a/src/tracks/check_goal.cpp b/src/tracks/check_goal.cpp index 34a560274..6d3cc655c 100644 --- a/src/tracks/check_goal.cpp +++ b/src/tracks/check_goal.cpp @@ -21,7 +21,7 @@ #include "io/xml_node.hpp" #include "tracks/track.hpp" #include "tracks/track_object_manager.hpp" -#include "modes/world.hpp" +#include "modes/soccer_world.hpp" #include /** Constructor for a check goal line. @@ -86,34 +86,14 @@ void CheckGoal::update(float dt) OVERRIDE */ void CheckGoal::trigger(unsigned int kart_index) { - printf("*** TODO: GOOOOOOOOOAAAAAAALLLLLL!!!! ***\n"); - - /* - World *world = World::getWorld(); - assert(world); - Track* track = world->getTrack(); - assert(track); - TrackObjectManager* tom = track->getTrackObjectManager(); - assert(tom); - PtrVector& objects = tom->getObjects(); - for(unsigned int i=0; i(World::getWorld()); + if(!world) { - TrackObject* obj = objects.get(i); - if(!obj->isSoccerBall()) - continue; - - const Vec3 &xyz = obj->getNode()->getPosition(); - // Only check active goal lines. - if(m_is_active[i] && isTriggered(m_previous_position[i], xyz, i)) - { - if(UserConfigParams::m_check_debug) - printf("CHECK: Goal check structure %d triggered for object %s.\n", - m_index, obj->getDebugName()); - trigger(i); - } - m_previous_position[i] = xyz; + fprintf(stderr, "WARNING: no soccer world found, cannot count the points\n"); + return; } - */ + + world->onCheckGoalTriggered(m_first_goal); } // CheckGoal bool CheckGoal::isTriggered(const Vec3 &old_pos, const Vec3 &new_pos, int indx) diff --git a/src/tracks/track_object.hpp b/src/tracks/track_object.hpp index 15f4dffab..8b672ed0c 100644 --- a/src/tracks/track_object.hpp +++ b/src/tracks/track_object.hpp @@ -135,11 +135,12 @@ public: } m_node = node; - if (node->getType() == irr::scene::ESNT_LOD_NODE) + + if (m_node->getType() == irr::scene::ESNT_LOD_NODE) { - ((LODNode*)node)->setNodesPosition(m_init_xyz); - ((LODNode*)node)->setNodesRotation(m_init_hpr); - ((LODNode*)node)->setNodesScale(m_init_scale); + ((LODNode*)m_node)->setNodesPosition(m_init_xyz); + ((LODNode*)m_node)->setNodesRotation(m_init_hpr); + ((LODNode*)m_node)->setNodesScale(m_init_scale); } else {