Final clean, put every kart location in three strikes battle world
This commit is contained in:
parent
405d31ecfc
commit
347c608867
@ -95,7 +95,6 @@ BattleAI::~BattleAI()
|
|||||||
*/
|
*/
|
||||||
void BattleAI::reset()
|
void BattleAI::reset()
|
||||||
{
|
{
|
||||||
m_current_node = BattleGraph::UNKNOWN_POLY;
|
|
||||||
m_target_node = BattleGraph::UNKNOWN_POLY;
|
m_target_node = BattleGraph::UNKNOWN_POLY;
|
||||||
m_adjusting_side = false;
|
m_adjusting_side = false;
|
||||||
m_closest_kart = NULL;
|
m_closest_kart = NULL;
|
||||||
@ -201,7 +200,7 @@ void BattleAI::checkIfStuck(const float dt)
|
|||||||
m_time_since_driving = 0.0f;
|
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;
|
m_time_since_driving += dt;
|
||||||
|
|
||||||
if ((m_time_since_driving >=
|
if ((m_time_since_driving >=
|
||||||
@ -294,8 +293,7 @@ void BattleAI::findClosestKart(bool difficulty)
|
|||||||
}
|
}
|
||||||
|
|
||||||
const AbstractKart* closest_kart = m_world->getKart(closest_kart_num);
|
const AbstractKart* closest_kart = m_world->getKart(closest_kart_num);
|
||||||
Controller* controller = (Controller*)(closest_kart->getController());
|
m_closest_kart_node = m_world->getKartNode(closest_kart_num);
|
||||||
m_closest_kart_node = controller->getCurrentNode();
|
|
||||||
m_closest_kart_point = closest_kart->getXYZ();
|
m_closest_kart_point = closest_kart->getXYZ();
|
||||||
|
|
||||||
if (!difficulty)
|
if (!difficulty)
|
||||||
@ -373,7 +371,9 @@ void BattleAI::handleUTurn(const float dt)
|
|||||||
*/
|
*/
|
||||||
void BattleAI::handleSteering(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;
|
m_target_node == BattleGraph::UNKNOWN_POLY) return;
|
||||||
|
|
||||||
if (m_is_steering_overridden)
|
if (m_is_steering_overridden)
|
||||||
@ -393,7 +393,7 @@ void BattleAI::handleSteering(const float dt)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (m_target_node == m_current_node)
|
if (m_target_node == current_node)
|
||||||
{
|
{
|
||||||
// Very close to the item, steer directly
|
// Very close to the item, steer directly
|
||||||
checkPosition(m_target_point, &m_cur_kart_pos_data);
|
checkPosition(m_target_point, &m_cur_kart_pos_data);
|
||||||
@ -413,9 +413,9 @@ void BattleAI::handleSteering(const float dt)
|
|||||||
return;
|
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);
|
stringPull(m_kart->getXYZ(), m_target_point);
|
||||||
if (m_path_corners.size() > 0)
|
if (m_path_corners.size() > 0)
|
||||||
m_target_point = m_path_corners[0];
|
m_target_point = m_path_corners[0];
|
||||||
@ -632,7 +632,8 @@ void BattleAI::handleBraking()
|
|||||||
{
|
{
|
||||||
m_controls->m_brake = false;
|
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_target_node == BattleGraph::UNKNOWN_POLY ||
|
||||||
m_is_steering_overridden) return;
|
m_is_steering_overridden) return;
|
||||||
|
|
||||||
|
@ -29,10 +29,9 @@
|
|||||||
*/
|
*/
|
||||||
Controller::Controller(AbstractKart *kart, StateManager::ActivePlayer *player)
|
Controller::Controller(AbstractKart *kart, StateManager::ActivePlayer *player)
|
||||||
{
|
{
|
||||||
m_controls = &(kart->getControls());
|
m_controls = &(kart->getControls());
|
||||||
m_kart = kart;
|
m_kart = kart;
|
||||||
m_player = player;
|
m_player = player;
|
||||||
m_current_node = -1;
|
|
||||||
setControllerName("Controller");
|
setControllerName("Controller");
|
||||||
} // Controller
|
} // Controller
|
||||||
|
|
||||||
|
@ -58,9 +58,6 @@ protected:
|
|||||||
/** The name of the controller, mainly used for debugging purposes. */
|
/** The name of the controller, mainly used for debugging purposes. */
|
||||||
std::string m_controller_name;
|
std::string m_controller_name;
|
||||||
|
|
||||||
/** This variable is required for used in arena **/
|
|
||||||
int m_current_node;
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
Controller (AbstractKart *kart,
|
Controller (AbstractKart *kart,
|
||||||
StateManager::ActivePlayer *player=NULL);
|
StateManager::ActivePlayer *player=NULL);
|
||||||
@ -108,12 +105,6 @@ public:
|
|||||||
/** Get a pointer on the kart controls. */
|
/** Get a pointer on the kart controls. */
|
||||||
virtual KartControl* getControls() { return m_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
|
}; // Controller
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -95,7 +95,6 @@ void PlayerController::reset()
|
|||||||
m_prev_nitro = false;
|
m_prev_nitro = false;
|
||||||
m_sound_schedule = false;
|
m_sound_schedule = false;
|
||||||
m_penalty_time = 0;
|
m_penalty_time = 0;
|
||||||
m_current_node = BattleGraph::UNKNOWN_POLY;
|
|
||||||
} // reset
|
} // reset
|
||||||
|
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
|
@ -26,7 +26,6 @@
|
|||||||
#include "graphics/irr_driver.hpp"
|
#include "graphics/irr_driver.hpp"
|
||||||
#include "io/file_manager.hpp"
|
#include "io/file_manager.hpp"
|
||||||
#include "karts/abstract_kart.hpp"
|
#include "karts/abstract_kart.hpp"
|
||||||
#include "karts/controller/controller.hpp"
|
|
||||||
#include "karts/kart_model.hpp"
|
#include "karts/kart_model.hpp"
|
||||||
#include "karts/kart_properties.hpp"
|
#include "karts/kart_properties.hpp"
|
||||||
#include "physics/physics.hpp"
|
#include "physics/physics.hpp"
|
||||||
@ -86,7 +85,8 @@ void ThreeStrikesBattle::reset()
|
|||||||
|
|
||||||
for(unsigned int n=0; n<kart_amount; n++)
|
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
|
// no positions in this mode
|
||||||
m_karts[n]->setPosition(-1);
|
m_karts[n]->setPosition(-1);
|
||||||
@ -441,7 +441,7 @@ bool ThreeStrikesBattle::isRaceOver()
|
|||||||
} // 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.
|
* on the navigation mesh.
|
||||||
*/
|
*/
|
||||||
void ThreeStrikesBattle::updateKartNodes()
|
void ThreeStrikesBattle::updateKartNodes()
|
||||||
@ -453,24 +453,22 @@ void ThreeStrikesBattle::updateKartNodes()
|
|||||||
{
|
{
|
||||||
if (m_karts[i]->isEliminated()) continue;
|
if (m_karts[i]->isEliminated()) continue;
|
||||||
|
|
||||||
const AbstractKart* kart = m_karts[i];
|
const int saved_current_node = m_kart_info[i].m_on_node;
|
||||||
Controller* controller = (Controller*)kart->getController();
|
|
||||||
const int saved_current_node = controller->getCurrentNode();
|
|
||||||
|
|
||||||
if (saved_current_node == BattleGraph::UNKNOWN_POLY)
|
if (saved_current_node == BattleGraph::UNKNOWN_POLY)
|
||||||
{
|
{
|
||||||
// Try all nodes in the battle graph
|
// Try all nodes in the battle graph
|
||||||
bool found = false;
|
bool found = false;
|
||||||
unsigned int num = 0;
|
unsigned int node = 0;
|
||||||
while (!found && num < BattleGraph::get()->getNumNodes())
|
while (!found && node < BattleGraph::get()->getNumNodes())
|
||||||
{
|
{
|
||||||
const NavPoly& p_all = BattleGraph::get()->getPolyOfNode(num);
|
const NavPoly& p_all = BattleGraph::get()->getPolyOfNode(node);
|
||||||
if ((p_all.pointInPoly(kart->getXYZ())))
|
if ((p_all.pointInPoly(m_karts[i]->getXYZ())))
|
||||||
{
|
{
|
||||||
controller->setCurrentNode(num);
|
m_kart_info[i].m_on_node = node;
|
||||||
found = true;
|
found = true;
|
||||||
}
|
}
|
||||||
num++;
|
node++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@ -478,7 +476,7 @@ void ThreeStrikesBattle::updateKartNodes()
|
|||||||
// Check if the kart is still on the same node
|
// Check if the kart is still on the same node
|
||||||
const NavPoly& p_cur = BattleGraph::get()
|
const NavPoly& p_cur = BattleGraph::get()
|
||||||
->getPolyOfNode(saved_current_node);
|
->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
|
// If not then check all adjacent polys
|
||||||
const std::vector<int>& adjacents = NavMesh::get()
|
const std::vector<int>& adjacents = NavMesh::get()
|
||||||
@ -488,7 +486,7 @@ void ThreeStrikesBattle::updateKartNodes()
|
|||||||
// we look everywhere the next time updateKartNodes is called.
|
// we look everywhere the next time updateKartNodes is called.
|
||||||
// This is useful in cases when you are "teleported"
|
// This is useful in cases when you are "teleported"
|
||||||
// to some other polygons, ex. rescue
|
// to some other polygons, ex. rescue
|
||||||
controller->setCurrentNode(BattleGraph::UNKNOWN_POLY);
|
m_kart_info[i].m_on_node = BattleGraph::UNKNOWN_POLY;
|
||||||
|
|
||||||
bool found = false;
|
bool found = false;
|
||||||
unsigned int num = 0;
|
unsigned int num = 0;
|
||||||
@ -496,31 +494,39 @@ void ThreeStrikesBattle::updateKartNodes()
|
|||||||
{
|
{
|
||||||
const NavPoly& p_temp =
|
const NavPoly& p_temp =
|
||||||
BattleGraph::get()->getPolyOfNode(adjacents[num]);
|
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;
|
found = true;
|
||||||
}
|
}
|
||||||
num++;
|
num++;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Current node is still unkown
|
// 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,
|
// Calculated distance from saved node to current position,
|
||||||
// if it's close enough than use the saved node anyway, it
|
// if it's close enough than use the saved node anyway, it
|
||||||
// may happen when the kart stays on the edge of obstacles
|
// may happen when the kart stays on the edge of obstacles
|
||||||
const NavPoly& p = BattleGraph::get()
|
const NavPoly& p = BattleGraph::get()
|
||||||
->getPolyOfNode(saved_current_node);
|
->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)
|
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
|
/** 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,
|
* end of race animation. It updates the time for all karts still racing,
|
||||||
|
@ -39,7 +39,8 @@ class ThreeStrikesBattle : public WorldWithRank
|
|||||||
private:
|
private:
|
||||||
struct BattleInfo
|
struct BattleInfo
|
||||||
{
|
{
|
||||||
int m_lives;
|
int m_lives;
|
||||||
|
int m_on_node;
|
||||||
};
|
};
|
||||||
|
|
||||||
/** This vector contains an 'BattleInfo' struct for every kart in the race.
|
/** 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);
|
virtual void kartAdded(AbstractKart* kart, scene::ISceneNode* node);
|
||||||
|
|
||||||
|
int getKartNode(unsigned int kart_id) const;
|
||||||
|
|
||||||
void updateKartRanks();
|
void updateKartRanks();
|
||||||
}; // ThreeStrikesBattles
|
}; // ThreeStrikesBattles
|
||||||
|
Loading…
x
Reference in New Issue
Block a user