2012-03-25 19:16:53 -04:00
|
|
|
//
|
|
|
|
// SuperTuxKart - a fun racing game with go-kart
|
2013-11-15 06:43:21 -05:00
|
|
|
// Copyright (C) 2012-2013 Joerg Henrichs
|
2012-03-25 19:16:53 -04:00
|
|
|
//
|
|
|
|
// 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.
|
|
|
|
|
2012-04-02 21:46:54 -04:00
|
|
|
#include "tracks/check_cannon.hpp"
|
2012-03-25 19:16:53 -04:00
|
|
|
|
2012-04-03 20:48:05 -04:00
|
|
|
#include "animations/animation_base.hpp"
|
2012-04-18 09:14:18 -04:00
|
|
|
#include "animations/ipo.hpp"
|
2012-05-14 18:26:41 -04:00
|
|
|
#include "graphics/show_curve.hpp"
|
2012-03-25 19:16:53 -04:00
|
|
|
#include "io/xml_node.hpp"
|
|
|
|
#include "karts/abstract_kart.hpp"
|
2012-04-02 21:46:54 -04:00
|
|
|
#include "karts/cannon_animation.hpp"
|
2012-03-25 19:16:53 -04:00
|
|
|
#include "modes/world.hpp"
|
|
|
|
|
2012-04-03 20:48:05 -04:00
|
|
|
|
2013-05-29 18:04:35 -04:00
|
|
|
/** Constructor for a check cannon.
|
2012-03-25 19:16:53 -04:00
|
|
|
* \param node XML node containing the parameters for this checkline.
|
|
|
|
* \param index Index of this check structure in the check manager.
|
|
|
|
*/
|
2013-05-29 18:04:35 -04:00
|
|
|
CheckCannon::CheckCannon(const XMLNode &node, unsigned int index)
|
2012-04-29 19:08:50 -04:00
|
|
|
: CheckLine(node, index)
|
2012-03-25 19:16:53 -04:00
|
|
|
{
|
|
|
|
core::vector3df p1, p2;
|
|
|
|
if(!node.get("target-p1", &p1) ||
|
2012-04-26 18:17:46 -04:00
|
|
|
!node.get("target-p2", &p2) )
|
|
|
|
{
|
|
|
|
printf("CheckCannon has no target line specified.\n");
|
|
|
|
exit(-1);
|
|
|
|
}
|
2012-03-25 19:16:53 -04:00
|
|
|
m_target.setLine(p1, p2);
|
2013-05-29 18:04:35 -04:00
|
|
|
m_curve = new Ipo(*(node.getNode("curve")),
|
|
|
|
/*fps*/25,
|
2012-04-29 19:08:50 -04:00
|
|
|
/*reverse*/race_manager->getReverseTrack());
|
2012-05-14 18:26:41 -04:00
|
|
|
#ifdef DEBUG
|
|
|
|
if(UserConfigParams::m_track_debug)
|
|
|
|
{
|
|
|
|
m_show_curve = new ShowCurve(0.5f, 0.5f);
|
|
|
|
const std::vector<Vec3> &p = m_curve->getPoints();
|
|
|
|
for(unsigned int i=0; i<p.size(); i++)
|
|
|
|
m_show_curve->addPoint(p[i]);
|
|
|
|
}
|
|
|
|
#endif
|
2012-04-02 21:46:54 -04:00
|
|
|
} // CheckCannon
|
2012-03-25 19:16:53 -04:00
|
|
|
|
2012-04-03 20:48:05 -04:00
|
|
|
// ----------------------------------------------------------------------------
|
2012-04-26 18:17:46 -04:00
|
|
|
/** Destructor, frees the curve data (which the cannon animation objects only
|
|
|
|
* have a read-only copy of).
|
|
|
|
*/
|
2012-04-03 20:48:05 -04:00
|
|
|
CheckCannon::~CheckCannon()
|
|
|
|
{
|
|
|
|
delete m_curve;
|
2012-05-14 18:26:41 -04:00
|
|
|
#ifdef DEBUG
|
|
|
|
if(UserConfigParams::m_track_debug)
|
|
|
|
delete m_show_curve;
|
|
|
|
#endif
|
2012-04-03 20:48:05 -04:00
|
|
|
} // ~CheckCannon
|
|
|
|
|
2012-03-25 19:16:53 -04:00
|
|
|
// ----------------------------------------------------------------------------
|
2013-05-29 18:04:35 -04:00
|
|
|
/** Called when the check line is triggered. This function creates a cannon
|
2012-04-26 18:17:46 -04:00
|
|
|
* animation object and attaches it to the kart.
|
|
|
|
* \param kart_index The index of the kart that triggered the check line.
|
|
|
|
*/
|
2012-04-02 21:46:54 -04:00
|
|
|
void CheckCannon::trigger(unsigned int kart_index)
|
2012-03-25 19:16:53 -04:00
|
|
|
{
|
2012-04-26 18:17:46 -04:00
|
|
|
Vec3 target(m_target.getMiddle());
|
|
|
|
AbstractKart *kart = World::getWorld()->getKart(kart_index);
|
2012-04-18 09:14:18 -04:00
|
|
|
if(kart->getKartAnimation()) return;
|
|
|
|
|
2012-04-26 18:17:46 -04:00
|
|
|
new CannonAnimation(kart, m_curve->clone());
|
2012-04-02 21:46:54 -04:00
|
|
|
} // CheckCannon
|