diff --git a/src/tracks/check_manager.cpp b/src/tracks/check_manager.cpp index 089c2b0af..93defc4d5 100644 --- a/src/tracks/check_manager.cpp +++ b/src/tracks/check_manager.cpp @@ -33,7 +33,7 @@ CheckManager::CheckManager(const XMLNode &node) const std::string &type = check_node->getName(); if(type=="checkline") { - m_all_checks.push_back(new Checkline(*check_node)); + m_all_checks.push_back(new Checkline(this, *check_node)); } } // for iupdate(dt); } // update + +// ---------------------------------------------------------------------------- +/** Called when a reset-new-lap check is triggered. It re-activates all new + * lap checks. + */ +void CheckManager::activateNewLapChecks(int kart_index) +{ + std::vector::iterator i; + for(i=m_all_checks.begin(); i!=m_all_checks.end(); i++) + (*i)->activateNewLapCheck(kart_index); +} // resetNewLaps diff --git a/src/tracks/check_manager.hpp b/src/tracks/check_manager.hpp index 97055a8ed..6ed1b1b23 100644 --- a/src/tracks/check_manager.hpp +++ b/src/tracks/check_manager.hpp @@ -35,6 +35,7 @@ public: CheckManager(const XMLNode &node); void update(float dt); void reset(const Track &track); + void activateNewLapChecks(int kart_index); }; // CheckManager #endif diff --git a/src/tracks/check_structure.cpp b/src/tracks/check_structure.cpp index 045fa6adc..a4f4544fc 100644 --- a/src/tracks/check_structure.cpp +++ b/src/tracks/check_structure.cpp @@ -20,11 +20,14 @@ #include "karts/kart.hpp" #include "modes/world.hpp" #include "race/race_manager.hpp" +#include "tracks/check_manager.hpp" #include "tracks/check_structure.hpp" -CheckStructure::CheckStructure(const XMLNode &node) +CheckStructure::CheckStructure(CheckManager *check_manager, + const XMLNode &node) { + m_check_manager = check_manager; std::string type; node.get("type", &type); if(type=="new-lap") @@ -71,8 +74,10 @@ void CheckStructure::update(float dt) { trigger(i); } + m_previous_position[i] = xyz; } // for inewLap(kart_index); m_is_active[kart_index] = false; break; - case CT_RESET_NEW_LAP : break; + case CT_RESET_NEW_LAP : + m_check_manager->activateNewLapChecks(kart_index); + break; default: break; } // switch m_check_type -} // trigger \ No newline at end of file +} // trigger + +// ---------------------------------------------------------------------------- +/** If this check structure is a new-lap check, activate it again. + * \param kart_index Index of the kart for which the lap check is activated. + */ +void CheckStructure::activateNewLapCheck(int kart_index) +{ + if(m_check_type==CT_NEW_LAP) + m_is_active[kart_index] = true; +} // resetNewLap \ No newline at end of file diff --git a/src/tracks/check_structure.hpp b/src/tracks/check_structure.hpp index 5e93e9c7b..544f464f9 100644 --- a/src/tracks/check_structure.hpp +++ b/src/tracks/check_structure.hpp @@ -26,6 +26,7 @@ class XMLNode; class Track; +class CheckManager; /** Virtual base class for a check structure. A check structure has a certain * type: @@ -62,10 +63,14 @@ protected: /** Stores if this check structure is active (for a given kart). USed e.g. * in lap counting. */ std::vector m_is_active; +private: + /** Stores a pointer to the check manager. */ + CheckManager *m_check_manager; + /** The type of this checkline. */ CheckType m_check_type; public: - CheckStructure(const XMLNode &node); + CheckStructure(CheckManager *check_manager, const XMLNode &node); virtual ~CheckStructure() {}; virtual void update(float dt); /** True if going from old_pos to new_pos crosses this checkline. This function @@ -78,6 +83,7 @@ public: virtual bool isTriggered(const Vec3 &old_pos, const Vec3 &new_pos, int indx)=0; virtual void trigger(unsigned int kart_index); virtual void reset(const Track &track); + virtual void activateNewLapCheck(int kart_index); }; // CheckStructure #endif diff --git a/src/tracks/checkline.cpp b/src/tracks/checkline.cpp index ad9ff1ae4..aef03698e 100644 --- a/src/tracks/checkline.cpp +++ b/src/tracks/checkline.cpp @@ -24,7 +24,13 @@ #include "io/xml_node.hpp" #include "race/race_manager.hpp" -Checkline::Checkline(const XMLNode &node) : CheckStructure(node) +/** Constructor for a checkline. + * \param check_manager Pointer to the check manager, which is needed when + * resetting e.g. new lap counters. + * \param node XML node containing the parameters for this checkline. + */ +Checkline::Checkline(CheckManager *check_manager, const XMLNode &node) + : CheckStructure(check_manager, node) { m_previous_sign.resize(race_manager->getNumKarts()); core::vector2df p1, p2; @@ -77,4 +83,4 @@ bool Checkline::isTriggered(const Vec3 &old_pos, const Vec3 &new_pos, int indx) result = false; m_previous_sign[indx] = sign; return result; -} // update +} // isTriggered diff --git a/src/tracks/checkline.hpp b/src/tracks/checkline.hpp index 99c5eace2..af2defb5e 100644 --- a/src/tracks/checkline.hpp +++ b/src/tracks/checkline.hpp @@ -26,6 +26,7 @@ using namespace irr; #include "tracks/check_structure.hpp" class XMLNode; +class CheckManager; /** Implements a simple checkline. It's a finite line with 2 endpoints in 2d * and a minimum height (i.e. the minimum Y coordinate of the two points). @@ -48,7 +49,7 @@ private: * or to the right of the line. */ std::vector m_previous_sign; public: - Checkline(const XMLNode &node); + Checkline(CheckManager *check_manager, const XMLNode &node); virtual ~Checkline() {}; virtual bool isTriggered(const Vec3 &old_pos, const Vec3 &new_pos, int indx); virtual void reset(const Track &track);