Fix for ticket 450: use a largest accumulated distance to separate kart respawns in 3sb

git-svn-id: svn+ssh://svn.code.sf.net/p/supertuxkart/code/main/trunk@10335 178a84e3-b1eb-0310-8ba1-8eac791a3b58
This commit is contained in:
termina1
2011-12-04 15:10:59 +00:00
parent 852420306e
commit 1d6953bcb3
2 changed files with 32 additions and 11 deletions

View File

@@ -20,7 +20,6 @@
#include <string>
#include <IMeshSceneNode.h>
#include "audio/music_manager.hpp"
#include "io/file_manager.hpp"
#include "states_screens/race_gui_base.hpp"
@@ -478,29 +477,49 @@ void ThreeStrikesBattle::moveKartAfterRescue(Kart* kart)
const int start_spots_amount = world->getTrack()->getNumberOfStartPositions();
assert(start_spots_amount > 0);
float smallest_distance_found = -1;
int closest_id_found = -1;
float largest_accumulated_distance_found = -1;
int furthest_id_found = -1;
const float kart_x = kart->getXYZ().getX();
const float kart_z = kart->getXYZ().getZ();
for(int n=0; n<start_spots_amount; n++)
{
// no need for the overhead to compute exact distance with sqrt(),
// so using the 'manhattan' heuristic which will do fine enough.
const btTransform &s = world->getTrack()->getStartTransform(n);
const Vec3 &v=s.getOrigin();
const float dist_n= fabs(kart_x - v.getX()) +
fabs(kart_z - v.getZ());
if(dist_n < smallest_distance_found || closest_id_found == -1)
float accumulatedDistance = .0f;
bool spawnPointClear = true;
for(unsigned int k=0; k<getCurrentNumKarts(); k++)
{
closest_id_found = n;
smallest_distance_found = dist_n;
const Kart *currentKart = World::getWorld()->getKart(k);
const float currentKart_x = currentKart->getXYZ().getX();
const float currentKartk_z = currentKart->getXYZ().getZ();
if(kart_x!=currentKart_x && kart_z !=currentKartk_z)
{
float absDistance = fabs(currentKart_x - v.getX()) +
fabs(currentKartk_z - v.getZ());
if(absDistance < CLEAR_SPAWN_RANGE)
{
spawnPointClear = false;
break;
}
accumulatedDistance += absDistance;
}
}
if(largest_accumulated_distance_found < accumulatedDistance && spawnPointClear)
{
furthest_id_found = n;
largest_accumulated_distance_found = accumulatedDistance;
}
}
assert(closest_id_found != -1);
const btTransform &s = world->getTrack()->getStartTransform(closest_id_found);
assert(furthest_id_found != -1);
const btTransform &s = world->getTrack()->getStartTransform(furthest_id_found);
const Vec3 &xyz = s.getOrigin();
kart->setXYZ(xyz);
kart->setRotation(s.getRotation());

View File

@@ -25,6 +25,8 @@
#include "modes/world_with_rank.hpp"
#include "states_screens/race_gui_base.hpp"
#define CLEAR_SPAWN_RANGE 5
class PhysicalObject;
/**