Improved kart reverse when stuck. Fixed a bug in ThreeStrikesBattle::updateKartNodes().
git-svn-id: svn+ssh://svn.code.sf.net/p/supertuxkart/code/main/branches/battleAI@14673 178a84e3-b1eb-0310-8ba1-8eac791a3b58
This commit is contained in:
@@ -25,8 +25,10 @@
|
||||
#ifdef AI_DEBUG
|
||||
# include "graphics/irr_driver.hpp"
|
||||
#endif
|
||||
|
||||
#include "karts/abstract_kart.hpp"
|
||||
#include "karts/controller/kart_control.hpp"
|
||||
#include "karts/controller/player_controller.hpp"
|
||||
#include "karts/controller/ai_properties.hpp"
|
||||
#include "karts/kart_properties.hpp"
|
||||
#include "karts/max_speed.hpp"
|
||||
@@ -119,18 +121,24 @@ void BattleAI::handleGetUnstuck(const float dt)
|
||||
std::cout<<"GOT STUCK\n";
|
||||
m_time_since_stuck = 0.0f;
|
||||
m_currently_reversing = true;
|
||||
m_controls->reset();
|
||||
}
|
||||
if(m_currently_reversing == true)
|
||||
{
|
||||
setSteering(-2.0f*m_target_angle,dt);
|
||||
m_controls->m_accel = -0.34f;
|
||||
/*
|
||||
if(m_target_angle > 0)
|
||||
setSteering(M_PI,dt);
|
||||
else setSteering(-M_PI,dt);
|
||||
*/
|
||||
m_time_since_stuck += dt;
|
||||
|
||||
if(m_time_since_stuck >= 0.6f)
|
||||
|
||||
if(m_time_since_stuck >= 0.7f)
|
||||
{
|
||||
m_currently_reversing = false;
|
||||
std::cout<<"GOT UNSTUCK\n";
|
||||
m_time_since_stuck = 0.0f;
|
||||
}
|
||||
}
|
||||
@@ -143,19 +151,15 @@ void BattleAI::handleSteering(const float dt)
|
||||
{
|
||||
Vec3 target_point;
|
||||
const AbstractKart* kart = m_world->getPlayerKart(0);
|
||||
int player_node = -1;
|
||||
for(unsigned int i =0; i<BattleGraph::get()->getNumNodes(); i++)
|
||||
{
|
||||
const NavPoly& p = BattleGraph::get()->getPolyOfNode(i);
|
||||
if(p.pointInPoly(kart->getXYZ()))
|
||||
player_node = i;
|
||||
}
|
||||
PlayerController* pcontroller = (PlayerController*)kart->getController();
|
||||
|
||||
int player_node = pcontroller->getCurrentNode();
|
||||
// std::cout<<"PLayer node " << player_node<<" This cpu kart node" << m_current_node<<std::endl;
|
||||
if(player_node == BattleGraph::UNKNOWN_POLY || m_current_node == BattleGraph::UNKNOWN_POLY) return;
|
||||
if(player_node == m_current_node)
|
||||
{
|
||||
target_point=kart->getXYZ();
|
||||
std::cout<<"Aiming at sire nixt\n";
|
||||
// std::cout<<"Aiming at sire nixt\n";
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -166,6 +170,7 @@ void BattleAI::handleSteering(const float dt)
|
||||
target_point = NavMesh::get()->getCenterOfPoly(next_node);
|
||||
}
|
||||
m_target_angle = steerToPoint(target_point);
|
||||
// std::cout<<"Target nalge: "<<m_target_angle << " normalized:"<<normalizeAngle(m_target_angle)<<std::endl;
|
||||
setSteering(m_target_angle,dt);
|
||||
|
||||
#ifdef AI_DEBUG
|
||||
|
||||
@@ -429,7 +429,7 @@ bool ThreeStrikesBattle::isRaceOver()
|
||||
|
||||
return getCurrentNumKarts()==1 || getCurrentNumPlayers()==0;
|
||||
} // isRaceOver
|
||||
|
||||
#include <iostream>
|
||||
//-----------------------------------------------------------------------------
|
||||
/** Updates the m_current_node value of each kart controller to localize it
|
||||
* on the navigation mesh.
|
||||
@@ -441,7 +441,7 @@ void ThreeStrikesBattle::updateKartNodes()
|
||||
for(unsigned int i=0; i<n; i++)
|
||||
{
|
||||
if(m_karts[i]->isEliminated()) continue;
|
||||
|
||||
|
||||
const AbstractKart* kart = m_karts[i];
|
||||
|
||||
if(!kart->getController()->isPlayerController())
|
||||
@@ -454,7 +454,7 @@ void ThreeStrikesBattle::updateKartNodes()
|
||||
{
|
||||
//check if the kart is still on the same node
|
||||
const NavPoly& p = BattleGraph::get()->getPolyOfNode(controller->getCurrentNode());
|
||||
if(p.pointInPoly(kart->getXYZ())) return;
|
||||
if(p.pointInPoly(kart->getXYZ())) continue;
|
||||
|
||||
//if not then check all adjacent polys
|
||||
const std::vector<int>& adjacents =
|
||||
@@ -506,7 +506,7 @@ void ThreeStrikesBattle::updateKartNodes()
|
||||
{
|
||||
//check if the kart is still on the same node
|
||||
const NavPoly& p = BattleGraph::get()->getPolyOfNode(controller->getCurrentNode());
|
||||
if(p.pointInPoly(kart->getXYZ())) return;
|
||||
if(p.pointInPoly(kart->getXYZ())) continue;
|
||||
|
||||
//if not then check all adjacent polys
|
||||
const std::vector<int>& adjacents =
|
||||
|
||||
@@ -7,7 +7,6 @@
|
||||
#include "items/powerup.hpp"
|
||||
#include "modes/world.hpp"
|
||||
#include "network/network_manager.hpp"
|
||||
#include <stdint.h>
|
||||
|
||||
GameEventsProtocol::GameEventsProtocol() : Protocol(NULL, PROTOCOL_GAME_EVENTS)
|
||||
{
|
||||
|
||||
@@ -21,6 +21,7 @@
|
||||
|
||||
#if defined(_MSC_VER) && _MSC_VER < 1800
|
||||
typedef unsigned char uint8_t;
|
||||
typedef char int8_t;
|
||||
typedef unsigned short uint16_t;
|
||||
typedef __int32 int32_t;
|
||||
typedef unsigned __int32 uint32_t;
|
||||
@@ -35,3 +36,4 @@
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
Reference in New Issue
Block a user