Add mini-skid for BattleAI when attacking targets

This commit is contained in:
Benau 2016-01-23 10:34:20 +08:00
parent df9dc5ff34
commit 2bc9362ac6
4 changed files with 28 additions and 13 deletions

View File

@ -66,7 +66,7 @@ protected:
float normalizeAngle(float angle); float normalizeAngle(float angle);
virtual void update (float delta) ; virtual void update (float delta) ;
virtual void setSteering (float angle, float dt); virtual void setSteering (float angle, float dt);
virtual bool canSkid(float steer_fraction) { return false; } virtual bool canSkid(float steer_fraction) = 0;
// ------------------------------------------------------------------------ // ------------------------------------------------------------------------
/** This can be called to detect if the kart is stuck (i.e. repeatedly /** This can be called to detect if the kart is stuck (i.e. repeatedly
* hitting part of the track). */ * hitting part of the track). */

View File

@ -75,6 +75,7 @@ void BattleAI::reset()
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
void BattleAI::update(float dt) void BattleAI::update(float dt)
{ {
m_mini_skid = false;
ArenaAI::update(dt); ArenaAI::update(dt);
} // update } // update
@ -129,6 +130,16 @@ void BattleAI::findClosestKart(bool use_difficulty)
{ {
m_closest_kart = m_world->getKart(closest_kart_num); m_closest_kart = m_world->getKart(closest_kart_num);
checkPosition(m_closest_kart_point, &m_closest_kart_pos_data); checkPosition(m_closest_kart_point, &m_closest_kart_pos_data);
// Do a mini-skid to closest kart only when firing target,
// not straight ahead, not too far, in front of it
// and with suitable difficulties.
if (m_closest_kart_pos_data.angle > 0.2f &&
m_closest_kart_pos_data.distance < 20.f &&
!m_closest_kart_pos_data.behind &&
(m_cur_difficulty == RaceManager::DIFFICULTY_HARD ||
m_cur_difficulty == RaceManager::DIFFICULTY_BEST))
m_mini_skid = true;
} }
} // findClosestKart } // findClosestKart

View File

@ -36,10 +36,13 @@ private:
/** Keep a pointer to world. */ /** Keep a pointer to world. */
ThreeStrikesBattle *m_world; ThreeStrikesBattle *m_world;
bool m_mini_skid;
virtual void findClosestKart(bool use_difficulty); virtual void findClosestKart(bool use_difficulty);
virtual void findTarget(); virtual void findTarget();
virtual int getCurrentNode() const; virtual int getCurrentNode() const;
virtual bool isWaiting() const; virtual bool isWaiting() const;
virtual bool canSkid(float steer_fraction) { return m_mini_skid; }
public: public:
BattleAI(AbstractKart *kart, BattleAI(AbstractKart *kart,
StateManager::ActivePlayer *player = NULL); StateManager::ActivePlayer *player = NULL);

View File

@ -74,23 +74,24 @@ private:
*that can be done, and end up setting their respective m_controls *that can be done, and end up setting their respective m_controls
*variable. *variable.
*/ */
void handleSteering(float dt); void handleSteering(float dt);
void handleRescue(const float DELTA); void handleRescue(const float DELTA);
void checkCrashes(const int STEPS, const Vec3& pos); void checkCrashes(const int STEPS, const Vec3& pos);
void findNonCrashingPoint(Vec3 *result); void findNonCrashingPoint(Vec3 *result);
int calcSteps(); int calcSteps();
virtual bool canSkid(float steer_fraction) { return false; }
public: public:
EndController(AbstractKart *kart, EndController(AbstractKart *kart,
StateManager::ActivePlayer* player, StateManager::ActivePlayer* player,
Controller *prev_controller); Controller *prev_controller);
~EndController(); ~EndController();
virtual void update (float delta) ; virtual void update (float delta) ;
virtual void reset (); virtual void reset ();
/** Returns if the original controller of the kart was a player /** Returns if the original controller of the kart was a player
* controller. This way e.g. highscores can still be assigned * controller. This way e.g. highscores can still be assigned
* to the right player. */ * to the right player. */
virtual bool isPlayerController () const {return getPlayer()!=NULL;} virtual bool isPlayerController () const { return getPlayer() != NULL; }
virtual void action (PlayerAction action, int value); virtual void action (PlayerAction action, int value);
virtual void newLap (int lap); virtual void newLap (int lap);