2009-07-06 09:35:33 -04:00
|
|
|
// $Id: check_structure.cpp 1681 2008-04-09 13:52:48Z hikerstk $
|
|
|
|
//
|
|
|
|
// SuperTuxKart - a fun racing game with go-kart
|
|
|
|
// Copyright (C) 2009 Joerg Henrichs
|
|
|
|
//
|
|
|
|
// This program is free software; you can redistribute it and/or
|
|
|
|
// modify it under the terms of the GNU General Public License
|
|
|
|
// as published by the Free Software Foundation; either version 3
|
|
|
|
// of the License, or (at your option) any later version.
|
|
|
|
//
|
|
|
|
// This program is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
// GNU General Public License for more details.
|
|
|
|
//
|
|
|
|
// You should have received a copy of the GNU General Public License
|
|
|
|
// along with this program; if not, write to the Free Software
|
|
|
|
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|
|
|
|
|
|
|
#include "karts/kart.hpp"
|
2009-07-07 20:44:55 -04:00
|
|
|
#include "modes/world.hpp"
|
2009-07-06 09:35:33 -04:00
|
|
|
#include "race/race_manager.hpp"
|
2009-07-08 08:33:22 -04:00
|
|
|
#include "tracks/check_manager.hpp"
|
2009-07-06 09:35:33 -04:00
|
|
|
#include "tracks/check_structure.hpp"
|
|
|
|
|
|
|
|
|
2009-07-08 08:33:22 -04:00
|
|
|
CheckStructure::CheckStructure(CheckManager *check_manager,
|
|
|
|
const XMLNode &node)
|
2009-07-06 09:35:33 -04:00
|
|
|
{
|
2009-07-08 08:33:22 -04:00
|
|
|
m_check_manager = check_manager;
|
2009-07-07 20:44:55 -04:00
|
|
|
std::string type;
|
|
|
|
node.get("type", &type);
|
|
|
|
if(type=="new-lap")
|
|
|
|
m_check_type = CT_NEW_LAP;
|
|
|
|
else if(type=="reset-new-lap")
|
|
|
|
m_check_type = CT_RESET_NEW_LAP;
|
2009-09-16 01:32:17 -04:00
|
|
|
else if(type=="ambient-light")
|
|
|
|
m_check_type = CT_AMBIENT_SPHERE;
|
2009-07-07 20:44:55 -04:00
|
|
|
else
|
|
|
|
{
|
|
|
|
printf("Unknown check structure '%s' - ignored.\n", type.c_str());
|
|
|
|
}
|
2009-09-16 01:32:17 -04:00
|
|
|
m_active_at_reset=true;
|
|
|
|
node.get("active", &m_active_at_reset);
|
2009-07-06 09:35:33 -04:00
|
|
|
} // CheckStructure
|
|
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
/** Initialises the 'previous positions' of all karts with the start position
|
|
|
|
* defined for this track.
|
|
|
|
* \param track The track object defining the start positions.
|
|
|
|
*/
|
|
|
|
void CheckStructure::reset(const Track &track)
|
|
|
|
{
|
|
|
|
m_previous_position.clear();
|
2009-07-07 20:44:55 -04:00
|
|
|
m_is_active.clear();
|
2009-07-06 09:35:33 -04:00
|
|
|
for(unsigned int i=0; i<race_manager->getNumKarts(); i++)
|
|
|
|
{
|
|
|
|
const Vec3 &xyz = race_manager->getKart(i)->getXYZ();
|
|
|
|
m_previous_position.push_back(xyz);
|
2009-07-07 20:44:55 -04:00
|
|
|
|
2009-09-09 23:25:42 -04:00
|
|
|
// Activate all checkline
|
2009-09-16 01:32:17 -04:00
|
|
|
m_is_active.push_back(m_active_at_reset);
|
2009-07-06 09:35:33 -04:00
|
|
|
} // for i<getNumKarts
|
|
|
|
} // reset
|
|
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
/** Updates all check structures. Called one per time step.
|
|
|
|
* \param dt Time since last call.
|
|
|
|
*/
|
|
|
|
void CheckStructure::update(float dt)
|
|
|
|
{
|
|
|
|
for(unsigned int i=0; i<race_manager->getNumKarts(); i++)
|
|
|
|
{
|
|
|
|
const Vec3 &xyz = race_manager->getKart(i)->getXYZ();
|
2009-07-13 08:21:12 -04:00
|
|
|
// Only check active checklines.
|
|
|
|
if(m_is_active[i] && isTriggered(m_previous_position[i], xyz, i))
|
2009-07-06 09:35:33 -04:00
|
|
|
{
|
2009-07-07 20:44:55 -04:00
|
|
|
trigger(i);
|
2009-07-06 09:35:33 -04:00
|
|
|
}
|
2009-07-08 08:33:22 -04:00
|
|
|
m_previous_position[i] = xyz;
|
2009-07-06 09:35:33 -04:00
|
|
|
} // for i<getNumKarts
|
|
|
|
} // update
|
2009-07-08 08:33:22 -04:00
|
|
|
|
2009-07-06 09:35:33 -04:00
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
/** Is called when this check structure is triggered. This then can cause
|
|
|
|
* a lap to be counted, animation to be started etc.
|
|
|
|
*/
|
2009-07-07 20:44:55 -04:00
|
|
|
void CheckStructure::trigger(unsigned int kart_index)
|
2009-07-06 09:35:33 -04:00
|
|
|
{
|
2009-07-07 20:44:55 -04:00
|
|
|
switch(m_check_type)
|
|
|
|
{
|
|
|
|
case CT_NEW_LAP : RaceManager::getWorld()->newLap(kart_index);
|
|
|
|
m_is_active[kart_index] = false;
|
|
|
|
break;
|
2009-07-08 08:33:22 -04:00
|
|
|
case CT_RESET_NEW_LAP :
|
|
|
|
m_check_manager->activateNewLapChecks(kart_index);
|
|
|
|
break;
|
2009-07-07 20:44:55 -04:00
|
|
|
default: break;
|
|
|
|
} // switch m_check_type
|
2009-07-08 08:33:22 -04:00
|
|
|
} // 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;
|
2009-07-11 13:32:05 -04:00
|
|
|
} // resetNewLap
|