CheckGoal now is just a CheckStructure and not a CheckLine anymore. This fixes bugs due to arrays sized with the number of karts instead of the number of soccer balls
git-svn-id: svn+ssh://svn.code.sf.net/p/supertuxkart/code/main/branches/christmas@12313 178a84e3-b1eb-0310-8ba1-8eac791a3b58
This commit is contained in:
parent
bd70940af9
commit
14f7f080c0
@ -25,14 +25,22 @@
|
||||
#include <stdio.h>
|
||||
|
||||
/** Constructor for a check goal line.
|
||||
* \param node XML node containing the parameters for this checkline.
|
||||
* \param node XML node containing the parameters for this goal line.
|
||||
* \param index Index of this check structure in the check manager.
|
||||
*/
|
||||
CheckGoal::CheckGoal(const XMLNode &node, unsigned int index)
|
||||
: CheckLine(node, index)
|
||||
: CheckStructure(node, index)
|
||||
{
|
||||
// Determine the team for this goal
|
||||
m_first_goal = false;
|
||||
node.get("first_goal", &m_first_goal);
|
||||
|
||||
Vec3 p1, p2;
|
||||
node.get("p1", &p1);
|
||||
node.get("p2", &p2);
|
||||
|
||||
m_line.setLine( core::vector2df(p1.getX(), p1.getZ()),
|
||||
core::vector2df(p2.getX(), p2.getZ()) );
|
||||
} // CheckGoal
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
@ -43,6 +51,46 @@ void CheckGoal::update(float dt) OVERRIDE
|
||||
{
|
||||
World *world = World::getWorld();
|
||||
assert(world);
|
||||
|
||||
Track* track = world->getTrack();
|
||||
assert(track);
|
||||
|
||||
TrackObjectManager* tom = track->getTrackObjectManager();
|
||||
assert(tom);
|
||||
|
||||
PtrVector<TrackObject>& objects = tom->getObjects();
|
||||
int ball_index = 0;
|
||||
for(int i=0; i<objects.size(); i++)
|
||||
{
|
||||
TrackObject* obj = objects.get(i);
|
||||
if(!obj->isSoccerBall())
|
||||
continue;
|
||||
|
||||
const Vec3 &xyz = obj->getNode()->getPosition();
|
||||
if(isTriggered(m_previous_position[ball_index], xyz, ball_index))
|
||||
{
|
||||
if(UserConfigParams::m_check_debug)
|
||||
printf("CHECK: Goal check structure %d triggered for object %s.\n",
|
||||
m_index, obj->getDebugName());
|
||||
trigger(ball_index);
|
||||
}
|
||||
m_previous_position[ball_index] = xyz;
|
||||
ball_index++;
|
||||
}
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
/** Called when the check line is triggered. This function creates a cannon
|
||||
* animation object and attaches it to the kart.
|
||||
* \param kart_index The index of the kart that triggered the check line.
|
||||
*/
|
||||
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();
|
||||
@ -65,14 +113,36 @@ void CheckGoal::update(float dt) OVERRIDE
|
||||
}
|
||||
m_previous_position[i] = xyz;
|
||||
}
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
/** Called when the check line is triggered. This function creates a cannon
|
||||
* animation object and attaches it to the kart.
|
||||
* \param kart_index The index of the kart that triggered the check line.
|
||||
*/
|
||||
void CheckGoal::trigger(unsigned int kart_index)
|
||||
{
|
||||
printf("*** TODO: GOOOOOOOOOAAAAAAALLLLLL!!!! ***\n");
|
||||
*/
|
||||
} // CheckGoal
|
||||
|
||||
bool CheckGoal::isTriggered(const Vec3 &old_pos, const Vec3 &new_pos, int indx)
|
||||
{
|
||||
core::vector2df cross_point;
|
||||
|
||||
// Check if the finite line was actually crossed:
|
||||
return m_line.intersectWith(core::line2df(old_pos.toIrrVector2d(),
|
||||
new_pos.toIrrVector2d()),
|
||||
cross_point);
|
||||
|
||||
} // isTriggered
|
||||
|
||||
void CheckGoal::reset(const Track &track)
|
||||
{
|
||||
const TrackObjectManager* tom = track.getTrackObjectManager();
|
||||
assert(tom);
|
||||
|
||||
m_previous_position.clear();
|
||||
|
||||
const PtrVector<TrackObject>& objects = tom->getObjects();
|
||||
for(int i=0; i<objects.size(); i++)
|
||||
{
|
||||
const TrackObject* obj = objects.get(i);
|
||||
if(!obj->isSoccerBall())
|
||||
continue;
|
||||
|
||||
const Vec3 &xyz = obj->getNode()->getPosition();
|
||||
|
||||
m_previous_position.push_back(xyz);
|
||||
}
|
||||
} // reset
|
||||
|
@ -19,12 +19,14 @@
|
||||
#ifndef HEADER_CHECK_GOAL_HPP
|
||||
#define HEADER_CHECK_GOAL_HPP
|
||||
|
||||
#include "animations/animation_base.hpp"
|
||||
#include "tracks/check_line.hpp"
|
||||
#include "tracks/check_structure.hpp"
|
||||
#include "utils/cpp2011.h"
|
||||
#include <line2d.h>
|
||||
using namespace irr;
|
||||
|
||||
class CheckManager;
|
||||
class XMLNode;
|
||||
class Track;
|
||||
|
||||
/**
|
||||
* \brief Implements a simple checkline that will score a point when the
|
||||
@ -32,15 +34,22 @@ class XMLNode;
|
||||
*
|
||||
* \ingroup tracks
|
||||
*/
|
||||
class CheckGoal : public CheckLine
|
||||
class CheckGoal : public CheckStructure
|
||||
{
|
||||
private:
|
||||
bool m_first_goal;
|
||||
/** Which team is this goal for? */
|
||||
bool m_first_goal;
|
||||
|
||||
/** The line that is tested for being crossed. */
|
||||
core::line2df m_line;
|
||||
|
||||
public:
|
||||
CheckGoal(const XMLNode &node, unsigned int index);
|
||||
virtual ~CheckGoal() {}
|
||||
virtual void update(float dt) OVERRIDE;
|
||||
virtual void trigger(unsigned int kart_index);
|
||||
virtual bool isTriggered(const Vec3 &old_pos, const Vec3 &new_pos, int indx) OVERRIDE;
|
||||
virtual void reset(const Track &track) OVERRIDE;
|
||||
}; // CheckLine
|
||||
|
||||
#endif
|
||||
|
@ -41,6 +41,7 @@ class CheckManager;
|
||||
* CT_TOGGLE: Toggles the specified other check structures (active to
|
||||
* inactive and vice versa.
|
||||
* CT_CANNON: A check line that 'shoots' the kart to a specified location.
|
||||
* CT_GOAL: A goal line in soccer mode.
|
||||
* Each check structure can be active or inactive. Only lap counters are
|
||||
* initialised to be active, all other check structures are inactive.
|
||||
*
|
||||
|
@ -531,7 +531,7 @@ public:
|
||||
/** Returns true if the normals of this track can be smoothed. */
|
||||
bool smoothNormals() const { return m_smooth_normals; }
|
||||
// ------------------------------------------------------------------------
|
||||
TrackObjectManager* getTrackObjectManager() {return m_track_object_manager;}
|
||||
TrackObjectManager* getTrackObjectManager() const {return m_track_object_manager;}
|
||||
|
||||
/** Get list of challenges placed on that world. Works only for overworld. */
|
||||
const std::vector<OverworldChallenge>& getChallengeList() const
|
||||
|
Loading…
Reference in New Issue
Block a user