Final clean, put every kart location in three strikes battle world

This commit is contained in:
Benau 2016-01-05 13:15:50 +08:00
parent 405d31ecfc
commit 347c608867
6 changed files with 41 additions and 43 deletions

View File

@ -95,7 +95,6 @@ BattleAI::~BattleAI()
*/
void BattleAI::reset()
{
m_current_node = BattleGraph::UNKNOWN_POLY;
m_target_node = BattleGraph::UNKNOWN_POLY;
m_adjusting_side = false;
m_closest_kart = NULL;
@ -201,7 +200,7 @@ void BattleAI::checkIfStuck(const float dt)
m_time_since_driving = 0.0f;
}
m_on_node.insert(m_current_node);
m_on_node.insert(m_world->getKartNode(m_kart->getWorldKartId()));
m_time_since_driving += dt;
if ((m_time_since_driving >=
@ -294,8 +293,7 @@ void BattleAI::findClosestKart(bool difficulty)
}
const AbstractKart* closest_kart = m_world->getKart(closest_kart_num);
Controller* controller = (Controller*)(closest_kart->getController());
m_closest_kart_node = controller->getCurrentNode();
m_closest_kart_node = m_world->getKartNode(closest_kart_num);
m_closest_kart_point = closest_kart->getXYZ();
if (!difficulty)
@ -373,7 +371,9 @@ void BattleAI::handleUTurn(const float dt)
*/
void BattleAI::handleSteering(const float dt)
{
if (m_current_node == BattleGraph::UNKNOWN_POLY ||
const int current_node = m_world->getKartNode(m_kart->getWorldKartId());
if (current_node == BattleGraph::UNKNOWN_POLY ||
m_target_node == BattleGraph::UNKNOWN_POLY) return;
if (m_is_steering_overridden)
@ -393,7 +393,7 @@ void BattleAI::handleSteering(const float dt)
return;
}
if (m_target_node == m_current_node)
if (m_target_node == current_node)
{
// Very close to the item, steer directly
checkPosition(m_target_point, &m_cur_kart_pos_data);
@ -413,9 +413,9 @@ void BattleAI::handleSteering(const float dt)
return;
}
else if (m_target_node != m_current_node)
else if (m_target_node != current_node)
{
findPortals(m_current_node, m_target_node);
findPortals(current_node, m_target_node);
stringPull(m_kart->getXYZ(), m_target_point);
if (m_path_corners.size() > 0)
m_target_point = m_path_corners[0];
@ -632,7 +632,8 @@ void BattleAI::handleBraking()
{
m_controls->m_brake = false;
if (m_current_node == BattleGraph::UNKNOWN_POLY ||
if (m_world->getKartNode(m_kart->getWorldKartId())
== BattleGraph::UNKNOWN_POLY ||
m_target_node == BattleGraph::UNKNOWN_POLY ||
m_is_steering_overridden) return;

View File

@ -29,10 +29,9 @@
*/
Controller::Controller(AbstractKart *kart, StateManager::ActivePlayer *player)
{
m_controls = &(kart->getControls());
m_kart = kart;
m_player = player;
m_current_node = -1;
m_controls = &(kart->getControls());
m_kart = kart;
m_player = player;
setControllerName("Controller");
} // Controller

View File

@ -58,9 +58,6 @@ protected:
/** The name of the controller, mainly used for debugging purposes. */
std::string m_controller_name;
/** This variable is required for used in arena **/
int m_current_node;
public:
Controller (AbstractKart *kart,
StateManager::ActivePlayer *player=NULL);
@ -108,12 +105,6 @@ public:
/** Get a pointer on the kart controls. */
virtual KartControl* getControls() { return m_controls; }
// ------------------------------------------------------------------------
/** For arena only, get the current node in arena. */
int getCurrentNode() const { return m_current_node; }
// ------------------------------------------------------------------------
/** For arena only, set the current node in arena. */
void setCurrentNode(int i) { m_current_node = i; }
// ------------------------------------------------------------------------
}; // Controller
#endif

View File

@ -95,7 +95,6 @@ void PlayerController::reset()
m_prev_nitro = false;
m_sound_schedule = false;
m_penalty_time = 0;
m_current_node = BattleGraph::UNKNOWN_POLY;
} // reset
// ----------------------------------------------------------------------------

View File

@ -26,7 +26,6 @@
#include "graphics/irr_driver.hpp"
#include "io/file_manager.hpp"
#include "karts/abstract_kart.hpp"
#include "karts/controller/controller.hpp"
#include "karts/kart_model.hpp"
#include "karts/kart_properties.hpp"
#include "physics/physics.hpp"
@ -86,7 +85,8 @@ void ThreeStrikesBattle::reset()
for(unsigned int n=0; n<kart_amount; n++)
{
m_kart_info[n].m_lives = 3;
m_kart_info[n].m_lives = 3;
m_kart_info[n].m_on_node = BattleGraph::UNKNOWN_POLY;
// no positions in this mode
m_karts[n]->setPosition(-1);
@ -441,7 +441,7 @@ bool ThreeStrikesBattle::isRaceOver()
} // isRaceOver
//-----------------------------------------------------------------------------
/** Updates the m_current_node value of each kart controller to localize it
/** Updates the m_on_node value of each kart to localize it
* on the navigation mesh.
*/
void ThreeStrikesBattle::updateKartNodes()
@ -453,24 +453,22 @@ void ThreeStrikesBattle::updateKartNodes()
{
if (m_karts[i]->isEliminated()) continue;
const AbstractKart* kart = m_karts[i];
Controller* controller = (Controller*)kart->getController();
const int saved_current_node = controller->getCurrentNode();
const int saved_current_node = m_kart_info[i].m_on_node;
if (saved_current_node == BattleGraph::UNKNOWN_POLY)
{
// Try all nodes in the battle graph
bool found = false;
unsigned int num = 0;
while (!found && num < BattleGraph::get()->getNumNodes())
unsigned int node = 0;
while (!found && node < BattleGraph::get()->getNumNodes())
{
const NavPoly& p_all = BattleGraph::get()->getPolyOfNode(num);
if ((p_all.pointInPoly(kart->getXYZ())))
const NavPoly& p_all = BattleGraph::get()->getPolyOfNode(node);
if ((p_all.pointInPoly(m_karts[i]->getXYZ())))
{
controller->setCurrentNode(num);
m_kart_info[i].m_on_node = node;
found = true;
}
num++;
node++;
}
}
else
@ -478,7 +476,7 @@ void ThreeStrikesBattle::updateKartNodes()
// Check if the kart is still on the same node
const NavPoly& p_cur = BattleGraph::get()
->getPolyOfNode(saved_current_node);
if (p_cur.pointInPoly(kart->getXYZ())) continue;
if (p_cur.pointInPoly(m_karts[i]->getXYZ())) continue;
// If not then check all adjacent polys
const std::vector<int>& adjacents = NavMesh::get()
@ -488,7 +486,7 @@ void ThreeStrikesBattle::updateKartNodes()
// we look everywhere the next time updateKartNodes is called.
// This is useful in cases when you are "teleported"
// to some other polygons, ex. rescue
controller->setCurrentNode(BattleGraph::UNKNOWN_POLY);
m_kart_info[i].m_on_node = BattleGraph::UNKNOWN_POLY;
bool found = false;
unsigned int num = 0;
@ -496,31 +494,39 @@ void ThreeStrikesBattle::updateKartNodes()
{
const NavPoly& p_temp =
BattleGraph::get()->getPolyOfNode(adjacents[num]);
if (p_temp.pointInPoly(kart->getXYZ()))
if (p_temp.pointInPoly(m_karts[i]->getXYZ()))
{
controller->setCurrentNode(adjacents[num]);
m_kart_info[i].m_on_node = adjacents[num];
found = true;
}
num++;
}
// Current node is still unkown
if (controller->getCurrentNode() == BattleGraph::UNKNOWN_POLY)
if (m_kart_info[i].m_on_node == BattleGraph::UNKNOWN_POLY)
{
// Calculated distance from saved node to current position,
// if it's close enough than use the saved node anyway, it
// may happen when the kart stays on the edge of obstacles
const NavPoly& p = BattleGraph::get()
->getPolyOfNode(saved_current_node);
const float dist = (p.getCenter() - kart->getXYZ()).length_2d();
const float dist = (p.getCenter() - m_karts[i]->getXYZ()).length_2d();
if (dist < 3.0f)
controller->setCurrentNode(saved_current_node);
m_kart_info[i].m_on_node = saved_current_node;
}
}
}
}
//-----------------------------------------------------------------------------
/** Get the which node the kart located in navigation mesh.
*/
int ThreeStrikesBattle::getKartNode(unsigned int kart_id) const
{
return m_kart_info[kart_id].m_on_node;
} // getKartNode
//-----------------------------------------------------------------------------
/** Called when the race finishes, i.e. after playing (if necessary) an
* end of race animation. It updates the time for all karts still racing,

View File

@ -39,7 +39,8 @@ class ThreeStrikesBattle : public WorldWithRank
private:
struct BattleInfo
{
int m_lives;
int m_lives;
int m_on_node;
};
/** This vector contains an 'BattleInfo' struct for every kart in the race.
@ -108,6 +109,7 @@ public:
virtual void kartAdded(AbstractKart* kart, scene::ISceneNode* node);
int getKartNode(unsigned int kart_id) const;
void updateKartRanks();
}; // ThreeStrikesBattles