Refactored Local- and NetworkPlayerController to use a common base
class PlayerController.
This commit is contained in:
parent
dbd210d08c
commit
5c2f78b176
@ -1,5 +1,5 @@
|
||||
# Modify this file to change the last-modified date when you add/remove a file.
|
||||
# This will then trigger a new cmake run automatically.
|
||||
# This will then trigger a new cmake run automatically.
|
||||
file(GLOB_RECURSE STK_HEADERS RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} "src/*.hpp")
|
||||
file(GLOB_RECURSE STK_SOURCES RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} "src/*.cpp")
|
||||
file(GLOB_RECURSE STK_SHADERS RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} "data/shaders/*")
|
||||
|
@ -1,5 +1,3 @@
|
||||
|
||||
//
|
||||
// SuperTuxKart - a fun racing game with go-kart
|
||||
// Copyright (C) 2010-2015 Joerg Henrichs
|
||||
//
|
||||
|
@ -30,6 +30,7 @@
|
||||
#include "items/item.hpp"
|
||||
#include "items/powerup.hpp"
|
||||
#include "karts/abstract_kart.hpp"
|
||||
#include "karts/controller/player_controller.hpp"
|
||||
#include "karts/kart_properties.hpp"
|
||||
#include "karts/skidding.hpp"
|
||||
#include "karts/rescue_animation.hpp"
|
||||
@ -52,22 +53,16 @@
|
||||
LocalPlayerController::LocalPlayerController(AbstractKart *kart,
|
||||
StateManager::ActivePlayer *player,
|
||||
unsigned int player_index)
|
||||
: Controller(kart)
|
||||
: PlayerController(kart, player)
|
||||
{
|
||||
assert(player != NULL);
|
||||
m_player = player;
|
||||
m_player->setKart(kart);
|
||||
m_penalty_time = 0.0f;
|
||||
// Keep a pointer to the camera to remove the need to search for
|
||||
// the right camera once per frame later.
|
||||
m_camera = Camera::createCamera(kart);
|
||||
m_bzzt_sound = SFXManager::get()->createSoundSource( "bzzt" );
|
||||
m_wee_sound = SFXManager::get()->createSoundSource( "wee" );
|
||||
m_ugh_sound = SFXManager::get()->createSoundSource( "ugh" );
|
||||
m_grab_sound = SFXManager::get()->createSoundSource( "grab_collectable" );
|
||||
m_full_sound = SFXManager::get()->createSoundSource( "energy_bar_full" );
|
||||
|
||||
reset();
|
||||
m_bzzt_sound = SFXManager::get()->createSoundSource("bzzt");
|
||||
m_wee_sound = SFXManager::get()->createSoundSource("wee");
|
||||
m_ugh_sound = SFXManager::get()->createSoundSource("ugh");
|
||||
m_grab_sound = SFXManager::get()->createSoundSource("grab_collectable");
|
||||
m_full_sound = SFXManager::get()->createSoundSource("energy_bar_full");
|
||||
} // LocalPlayerController
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
@ -87,14 +82,8 @@ LocalPlayerController::~LocalPlayerController()
|
||||
*/
|
||||
void LocalPlayerController::reset()
|
||||
{
|
||||
m_steer_val_l = 0;
|
||||
m_steer_val_r = 0;
|
||||
m_steer_val = 0;
|
||||
m_prev_brake = 0;
|
||||
m_prev_accel = 0;
|
||||
m_prev_nitro = false;
|
||||
PlayerController::reset();
|
||||
m_sound_schedule = false;
|
||||
m_penalty_time = 0;
|
||||
} // reset
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
@ -104,14 +93,8 @@ void LocalPlayerController::reset()
|
||||
*/
|
||||
void LocalPlayerController::resetInputState()
|
||||
{
|
||||
m_steer_val_l = 0;
|
||||
m_steer_val_r = 0;
|
||||
m_steer_val = 0;
|
||||
m_prev_brake = 0;
|
||||
m_prev_accel = 0;
|
||||
m_prev_nitro = false;
|
||||
m_sound_schedule = false;
|
||||
m_controls->reset();
|
||||
PlayerController::resetInputState();
|
||||
m_sound_schedule = false;
|
||||
} // resetInputState
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
@ -129,98 +112,7 @@ void LocalPlayerController::resetInputState()
|
||||
*/
|
||||
void LocalPlayerController::action(PlayerAction action, int value)
|
||||
{
|
||||
switch (action)
|
||||
{
|
||||
case PA_STEER_LEFT:
|
||||
m_steer_val_l = value;
|
||||
if (value)
|
||||
{
|
||||
m_steer_val = value;
|
||||
if(m_controls->m_skid==KartControl::SC_NO_DIRECTION)
|
||||
m_controls->m_skid = KartControl::SC_LEFT;
|
||||
}
|
||||
else
|
||||
m_steer_val = m_steer_val_r;
|
||||
|
||||
break;
|
||||
case PA_STEER_RIGHT:
|
||||
m_steer_val_r = -value;
|
||||
if (value)
|
||||
{
|
||||
m_steer_val = -value;
|
||||
if(m_controls->m_skid==KartControl::SC_NO_DIRECTION)
|
||||
m_controls->m_skid = KartControl::SC_RIGHT;
|
||||
}
|
||||
else
|
||||
m_steer_val = m_steer_val_l;
|
||||
|
||||
break;
|
||||
case PA_ACCEL:
|
||||
m_prev_accel = value;
|
||||
if (value && !(m_penalty_time > 0.0f))
|
||||
{
|
||||
m_controls->m_accel = value/32768.0f;
|
||||
m_controls->m_brake = false;
|
||||
m_controls->m_nitro = m_prev_nitro;
|
||||
}
|
||||
else
|
||||
{
|
||||
m_controls->m_accel = 0.0f;
|
||||
m_controls->m_brake = m_prev_brake;
|
||||
m_controls->m_nitro = false;
|
||||
}
|
||||
break;
|
||||
case PA_BRAKE:
|
||||
m_prev_brake = value!=0;
|
||||
// let's consider below that to be a deadzone
|
||||
if(value > 32768/2)
|
||||
{
|
||||
m_controls->m_brake = true;
|
||||
m_controls->m_accel = 0.0f;
|
||||
m_controls->m_nitro = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
m_controls->m_brake = false;
|
||||
m_controls->m_accel = m_prev_accel/32768.0f;
|
||||
// Nitro still depends on whether we're accelerating
|
||||
m_controls->m_nitro = (m_prev_nitro && m_prev_accel);
|
||||
}
|
||||
break;
|
||||
case PA_NITRO:
|
||||
// This basically keeps track whether the button still is being pressed
|
||||
m_prev_nitro = (value != 0);
|
||||
// Enable nitro only when also accelerating
|
||||
m_controls->m_nitro = ((value!=0) && m_controls->m_accel);
|
||||
break;
|
||||
case PA_RESCUE:
|
||||
m_controls->m_rescue = (value!=0);
|
||||
break;
|
||||
case PA_FIRE:
|
||||
m_controls->m_fire = (value!=0);
|
||||
break;
|
||||
case PA_LOOK_BACK:
|
||||
m_controls->m_look_back = (value!=0);
|
||||
break;
|
||||
case PA_DRIFT:
|
||||
if(value==0)
|
||||
m_controls->m_skid = KartControl::SC_NONE;
|
||||
else
|
||||
{
|
||||
if(m_steer_val==0)
|
||||
m_controls->m_skid = KartControl::SC_NO_DIRECTION;
|
||||
else
|
||||
m_controls->m_skid = m_steer_val<0
|
||||
? KartControl::SC_RIGHT
|
||||
: KartControl::SC_LEFT;
|
||||
}
|
||||
break;
|
||||
case PA_PAUSE_RACE:
|
||||
if (value != 0) StateManager::get()->escapePressed();
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
PlayerController::action(action, value);
|
||||
|
||||
// If this is a client, send the action to the server
|
||||
if (World::getWorld()->isNetworkWorld() &&
|
||||
@ -242,72 +134,18 @@ void LocalPlayerController::steer(float dt, int steer_val)
|
||||
Log::debug("LocalPlayerController", "steering: steer_val %d ", steer_val);
|
||||
RaceGUIBase* gui_base = World::getWorld()->getRaceGUI();
|
||||
gui_base->clearAllMessages();
|
||||
gui_base->addMessage(StringUtils::insertValues(L"steer_val %i", steer_val), m_kart, 1.0f,
|
||||
gui_base->addMessage(StringUtils::insertValues(L"steer_val %i", steer_val),
|
||||
m_kart, 1.0f,
|
||||
video::SColor(255, 255, 0, 255), false);
|
||||
}
|
||||
|
||||
if(stk_config->m_disable_steer_while_unskid &&
|
||||
m_controls->m_skid==KartControl::SC_NONE &&
|
||||
m_kart->getSkidding()->getVisualSkidRotation()!=0)
|
||||
{
|
||||
m_controls->m_steer = 0;
|
||||
}
|
||||
|
||||
|
||||
// Amount the steering is changed for digital devices.
|
||||
// If the steering is 'back to straight', a different steering
|
||||
// change speed is used.
|
||||
const float STEER_CHANGE = ( (steer_val<=0 && m_controls->m_steer<0) ||
|
||||
(steer_val>=0 && m_controls->m_steer>0) )
|
||||
? dt/m_kart->getKartProperties()->getTimeResetSteer()
|
||||
: dt/m_kart->getTimeFullSteer(fabsf(m_controls->m_steer));
|
||||
if (steer_val < 0)
|
||||
{
|
||||
// If we got analog values do not cumulate.
|
||||
if (steer_val > -32767)
|
||||
m_controls->m_steer = -steer_val/32767.0f;
|
||||
else
|
||||
m_controls->m_steer += STEER_CHANGE;
|
||||
}
|
||||
else if(steer_val > 0)
|
||||
{
|
||||
// If we got analog values do not cumulate.
|
||||
if (steer_val < 32767)
|
||||
m_controls->m_steer = -steer_val/32767.0f;
|
||||
else
|
||||
m_controls->m_steer -= STEER_CHANGE;
|
||||
}
|
||||
else
|
||||
{ // no key is pressed
|
||||
if(m_controls->m_steer>0.0f)
|
||||
{
|
||||
m_controls->m_steer -= STEER_CHANGE;
|
||||
if(m_controls->m_steer<0.0f) m_controls->m_steer=0.0f;
|
||||
}
|
||||
else
|
||||
{ // m_controls->m_steer<=0.0f;
|
||||
m_controls->m_steer += STEER_CHANGE;
|
||||
if(m_controls->m_steer>0.0f) m_controls->m_steer=0.0f;
|
||||
} // if m_controls->m_steer<=0.0f
|
||||
} // no key is pressed
|
||||
PlayerController::steer(dt, steer_val);
|
||||
|
||||
if(UserConfigParams::m_gamepad_debug)
|
||||
{
|
||||
Log::debug("LocalPlayerController", " set to: %f\n", m_controls->m_steer);
|
||||
}
|
||||
|
||||
m_controls->m_steer = std::min(1.0f, std::max(-1.0f, m_controls->m_steer));
|
||||
|
||||
} // steer
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
/** Callback when the skidding bonus is triggered. The player controller
|
||||
* resets the current steering to 0, which makes the kart easier to control.
|
||||
*/
|
||||
void LocalPlayerController::skidBonusTriggered()
|
||||
{
|
||||
m_controls->m_steer = 0;
|
||||
} // skidBonusTriggered
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
/** Updates the player kart, called once each timestep.
|
||||
*/
|
||||
@ -320,12 +158,7 @@ void LocalPlayerController::update(float dt)
|
||||
Log::debug("LocalPlayerController", "irr_driver", "-------------------------------------");
|
||||
}
|
||||
|
||||
// Don't do steering if it's replay. In position only replay it doesn't
|
||||
// matter, but if it's physics replay the gradual steering causes
|
||||
// incorrect results, since the stored values are already adjusted.
|
||||
if (!history->replayHistory())
|
||||
steer(dt, m_steer_val);
|
||||
|
||||
PlayerController::update(dt);
|
||||
|
||||
// look backward when the player requests or
|
||||
// if automatic reverse camera is active
|
||||
@ -343,58 +176,6 @@ void LocalPlayerController::update(float dt)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (World::getWorld()->isStartPhase())
|
||||
{
|
||||
if (m_controls->m_accel || m_controls->m_brake ||
|
||||
m_controls->m_fire || m_controls->m_nitro)
|
||||
{
|
||||
// Only give penalty time in SET_PHASE.
|
||||
// Penalty time check makes sure it doesn't get rendered on every
|
||||
// update.
|
||||
if (m_penalty_time == 0.0 &&
|
||||
World::getWorld()->getPhase() == WorldStatus::SET_PHASE)
|
||||
{
|
||||
RaceGUIBase* m=World::getWorld()->getRaceGUI();
|
||||
if (m)
|
||||
{
|
||||
m->addMessage(_("Penalty time!!"), m_kart, 2.0f,
|
||||
video::SColor(255, 255, 128, 0));
|
||||
m->addMessage(_("Don't accelerate before go"), m_kart, 2.0f,
|
||||
video::SColor(255, 210, 100, 50));
|
||||
}
|
||||
m_bzzt_sound->play();
|
||||
|
||||
m_penalty_time = stk_config->m_penalty_time;
|
||||
} // if penalty_time = 0
|
||||
|
||||
m_controls->m_brake = false;
|
||||
m_controls->m_accel = 0.0f;
|
||||
} // if key pressed
|
||||
|
||||
return;
|
||||
} // if isStartPhase
|
||||
|
||||
if (m_penalty_time>0.0)
|
||||
{
|
||||
m_penalty_time-=dt;
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
|
||||
// We can't restrict rescue to fulfil isOnGround() (which would be more like
|
||||
// MK), since e.g. in the City track it is possible for the kart to end
|
||||
// up sitting on a brick wall, with all wheels in the air :((
|
||||
// Only accept rescue if there is no kart animation is already playing
|
||||
// (e.g. if an explosion happens, wait till the explosion is over before
|
||||
// starting any other animation).
|
||||
if (m_controls->m_rescue && !m_kart->getKartAnimation())
|
||||
{
|
||||
new RescueAnimation(m_kart);
|
||||
m_controls->m_rescue=false;
|
||||
}
|
||||
|
||||
if (m_kart->getKartAnimation() && m_sound_schedule == false &&
|
||||
m_kart->getAttachment()->getType() != Attachment::ATTACH_TINYTUX)
|
||||
{
|
||||
@ -408,10 +189,31 @@ void LocalPlayerController::update(float dt)
|
||||
} // update
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
/** Checks if the kart was overtaken, and if so plays a sound
|
||||
*/
|
||||
/** Displays a penalty warning for player controlled karts. Called from
|
||||
* LocalPlayerKart::update() if necessary.
|
||||
*/
|
||||
void LocalPlayerController::displayPenaltyWarning()
|
||||
{
|
||||
RaceGUIBase* m=World::getWorld()->getRaceGUI();
|
||||
if (m)
|
||||
{
|
||||
m->addMessage(_("Penalty time!!"), m_kart, 2.0f,
|
||||
video::SColor(255, 255, 128, 0));
|
||||
m->addMessage(_("Don't accelerate before go"), m_kart, 2.0f,
|
||||
video::SColor(255, 210, 100, 50));
|
||||
}
|
||||
m_bzzt_sound->play();
|
||||
} // displayPenaltyWarning
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
/** Called just before the kart position is changed. It checks if the kart was
|
||||
* overtaken, and if so plays a sound from the overtaking kart.
|
||||
*/
|
||||
void LocalPlayerController::setPosition(int p)
|
||||
{
|
||||
PlayerController::setPosition(p);
|
||||
|
||||
|
||||
if(m_kart->getPosition()<p)
|
||||
{
|
||||
World *world = World::getWorld();
|
||||
@ -445,6 +247,8 @@ void LocalPlayerController::finishedRace(float time)
|
||||
*/
|
||||
void LocalPlayerController::handleZipper(bool play_sound)
|
||||
{
|
||||
PlayerController::handleZipper(play_sound);
|
||||
|
||||
// Only play a zipper sound if it's not already playing, and
|
||||
// if the material has changed (to avoid machine gun effect
|
||||
// on conveyor belt zippers).
|
||||
@ -457,12 +261,11 @@ void LocalPlayerController::handleZipper(bool play_sound)
|
||||
// Apply the motion blur according to the speed of the kart
|
||||
irr_driver->getPostProcessing()->giveBoost(m_camera->getIndex());
|
||||
|
||||
m_kart->showZipperFire();
|
||||
|
||||
} // handleZipper
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
/** Called when a kart hits an item.
|
||||
/** Called when a kart hits an item. It plays certain sfx (e.g. nitro full,
|
||||
* or item specific sounds).
|
||||
* \param item Item that was collected.
|
||||
* \param add_info Additional info to be used then handling the item. If
|
||||
* this is -1 (default), the item type is selected
|
||||
@ -470,8 +273,10 @@ void LocalPlayerController::handleZipper(bool play_sound)
|
||||
* attachment for the kart. This is used in network mode to
|
||||
* let the server determine the powerup/attachment for
|
||||
* the clients.
|
||||
* \param old_energy The previous energy value
|
||||
*/
|
||||
void LocalPlayerController::collectedItem(const Item &item, int add_info, float old_energy)
|
||||
void LocalPlayerController::collectedItem(const Item &item, int add_info,
|
||||
float old_energy)
|
||||
{
|
||||
if (old_energy < m_kart->getKartProperties()->getNitroMax() &&
|
||||
m_kart->getEnergy() == m_kart->getKartProperties()->getNitroMax())
|
||||
|
@ -21,7 +21,7 @@
|
||||
#ifndef HEADER_LOCAL_PLAYER_CONTROLLER_HPP
|
||||
#define HEADER_LOCAL_PLAYER_CONTROLLER_HPP
|
||||
|
||||
#include "karts/controller/controller.hpp"
|
||||
#include "karts/controller/player_controller.hpp"
|
||||
|
||||
class AbstractKart;
|
||||
class Camera;
|
||||
@ -33,16 +33,11 @@ class SFXBase;
|
||||
*
|
||||
* \ingroup controller
|
||||
*/
|
||||
class LocalPlayerController : public Controller
|
||||
class LocalPlayerController : public PlayerController
|
||||
{
|
||||
private:
|
||||
int m_steer_val, m_steer_val_l, m_steer_val_r;
|
||||
int m_prev_accel;
|
||||
bool m_prev_brake;
|
||||
bool m_prev_nitro;
|
||||
bool m_sound_schedule;
|
||||
|
||||
float m_penalty_time;
|
||||
bool m_sound_schedule;
|
||||
|
||||
/** The camera attached to the kart for this controller. The camera
|
||||
* object is managed in the Camera class, so no need to free it. */
|
||||
@ -54,33 +49,26 @@ private:
|
||||
SFXBase *m_grab_sound;
|
||||
SFXBase *m_full_sound;
|
||||
|
||||
void steer(float, int);
|
||||
virtual void steer(float, int) OVERRIDE;
|
||||
virtual void displayPenaltyWarning() OVERRIDE;
|
||||
public:
|
||||
LocalPlayerController (AbstractKart *kart,
|
||||
StateManager::ActivePlayer *_player,
|
||||
unsigned int player_index);
|
||||
~LocalPlayerController ();
|
||||
void update (float);
|
||||
void action (PlayerAction action, int value);
|
||||
void handleZipper (bool play_sound);
|
||||
void collectedItem (const Item &item, int add_info=-1,
|
||||
float previous_energy=0);
|
||||
virtual void skidBonusTriggered();
|
||||
virtual void setPosition (int p);
|
||||
virtual bool isPlayerController() const {return true;}
|
||||
virtual bool isLocalPlayerController() const {return true;}
|
||||
virtual void reset ();
|
||||
void resetInputState ();
|
||||
virtual void finishedRace (float time);
|
||||
virtual void crashed (const AbstractKart *k) {}
|
||||
virtual void crashed (const Material *m) {}
|
||||
LocalPlayerController(AbstractKart *kart,
|
||||
StateManager::ActivePlayer *_player,
|
||||
unsigned int player_index);
|
||||
~LocalPlayerController();
|
||||
void update (float) OVERRIDE;
|
||||
void action (PlayerAction action, int value) OVERRIDE;
|
||||
virtual void handleZipper (bool play_sound) OVERRIDE;
|
||||
void collectedItem (const Item &item, int add_info=-1,
|
||||
float previous_energy=0) OVERRIDE;
|
||||
virtual void setPosition (int p) OVERRIDE;
|
||||
virtual void reset () OVERRIDE;
|
||||
virtual void finishedRace (float time) OVERRIDE;
|
||||
virtual void resetInputState () OVERRIDE;
|
||||
// ------------------------------------------------------------------------
|
||||
/** Callback whenever a new lap is triggered. Used by the AI
|
||||
* to trigger a recomputation of the way to use, not used for players. */
|
||||
virtual void newLap(int lap) {}
|
||||
virtual bool isPlayerController() const OVERRIDE {return true;}
|
||||
// ------------------------------------------------------------------------
|
||||
/** Player will always be able to get a slipstream bonus. */
|
||||
virtual bool disableSlipstreamBonus() const { return false; }
|
||||
virtual bool isLocalPlayerController() const OVERRIDE {return true;}
|
||||
|
||||
}; // LocalPlayerController
|
||||
|
||||
|
@ -1,48 +1,49 @@
|
||||
#ifndef NETWORK_PLAYER_CONTROLLER_HPP
|
||||
#define NETWORK_PLAYER_CONTROLLER_HPP
|
||||
// SuperTuxKart - a fun racing game with go-kart
|
||||
// Copyright (C) 2015 Joerg Henrichs
|
||||
// This program is free software; you can redistribute it and/or
|
||||
// modify it under the terms of the GNU General Public License
|
||||
// as published by the Free Software Foundation; either version 3
|
||||
// of the License, or (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program; if not, write to the Free Software
|
||||
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
|
||||
#include "karts/controller/controller.hpp"
|
||||
#ifndef HEADER_NETWORK_PLAYER_CONTROLLER_HPP
|
||||
#define HEADER_NETWORK_PLAYER_CONTROLLER_HPP
|
||||
|
||||
#include "karts/controller/player_controller.hpp"
|
||||
|
||||
class AbstractKart;
|
||||
class Player;
|
||||
|
||||
class NetworkPlayerController : public Controller
|
||||
class NetworkPlayerController : public PlayerController
|
||||
{
|
||||
protected:
|
||||
int m_steer_val, m_steer_val_l, m_steer_val_r;
|
||||
int m_prev_accel;
|
||||
bool m_prev_brake;
|
||||
bool m_prev_nitro;
|
||||
|
||||
float m_penalty_time;
|
||||
|
||||
void steer(float, int);
|
||||
public:
|
||||
NetworkPlayerController (AbstractKart *kart,
|
||||
StateManager::ActivePlayer *_player);
|
||||
virtual ~NetworkPlayerController ();
|
||||
void update (float);
|
||||
void action (PlayerAction action, int value);
|
||||
void handleZipper (bool play_sound);
|
||||
void collectedItem (const Item &item, int add_info=-1,
|
||||
float previous_energy=0);
|
||||
virtual void skidBonusTriggered();
|
||||
virtual void setPosition (int p);
|
||||
virtual bool isPlayerController() const { return true; }
|
||||
virtual bool isLocalPlayerController() const { return false; }
|
||||
virtual void reset ();
|
||||
void resetInputState ();
|
||||
virtual void finishedRace (float time);
|
||||
virtual void crashed (const AbstractKart *k) {}
|
||||
virtual void crashed (const Material *m) {}
|
||||
NetworkPlayerController(AbstractKart *kart,
|
||||
StateManager::ActivePlayer *player)
|
||||
: PlayerController(kart, player)
|
||||
{
|
||||
Log::info("NetworkPlayerController",
|
||||
"New network player controller.");
|
||||
} // NetworkPlayerController
|
||||
// ------------------------------------------------------------------------
|
||||
/** Callback whenever a new lap is triggered. Used by the AI
|
||||
* to trigger a recomputation of the way to use, not used for players. */
|
||||
virtual void newLap(int lap) {}
|
||||
virtual ~NetworkPlayerController()
|
||||
{
|
||||
} // ~NetworkPlayerController
|
||||
// ------------------------------------------------------------------------
|
||||
/** Player will always be able to get a slipstream bonus. */
|
||||
virtual bool disableSlipstreamBonus() const { return false; }
|
||||
|
||||
};
|
||||
/** This player is not a local player. This affect e.g. special sfx and
|
||||
* camera effects to be triggered. */
|
||||
virtual bool isLocalPlayerController() const OVERRIDE
|
||||
{
|
||||
return false;
|
||||
} // isLocal
|
||||
// ------------------------------------------------------------------------
|
||||
}; // NetworkPlayerController
|
||||
|
||||
#endif // NETWORK_PLAYER_CONTROLLER_HPP
|
||||
|
@ -1,4 +1,23 @@
|
||||
#include "karts/controller/network_player_controller.hpp"
|
||||
//
|
||||
// SuperTuxKart - a fun racing game with go-kart
|
||||
// Copyright (C) 2004-2015 Steve Baker <sjbaker1@airmail.net>
|
||||
// Copyright (C) 2006-2015 Joerg Henrichs, Steve Baker
|
||||
//
|
||||
// This program is free software; you can redistribute it and/or
|
||||
// modify it under the terms of the GNU General Public License
|
||||
// as published by the Free Software Foundation; either version 3
|
||||
// of the License, or (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program; if not, write to the Free Software
|
||||
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
|
||||
#include "karts/controller/player_controller.hpp"
|
||||
|
||||
#include "config/user_config.hpp"
|
||||
#include "graphics/irr_driver.hpp"
|
||||
@ -18,7 +37,7 @@
|
||||
#include "utils/log.hpp"
|
||||
#include "utils/translation.hpp"
|
||||
|
||||
NetworkPlayerController::NetworkPlayerController(AbstractKart *kart,
|
||||
PlayerController::PlayerController(AbstractKart *kart,
|
||||
StateManager::ActivePlayer *player)
|
||||
: Controller(kart)
|
||||
{
|
||||
@ -26,23 +45,19 @@ NetworkPlayerController::NetworkPlayerController(AbstractKart *kart,
|
||||
m_player = player;
|
||||
m_player->setKart(kart);
|
||||
m_penalty_time = 0.0f;
|
||||
|
||||
reset();
|
||||
|
||||
Log::info("NetworkPlayerController", "New network player controller.");
|
||||
} // NetworkPlayerController
|
||||
} // PlayerController
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
/** Destructor for a player kart.
|
||||
*/
|
||||
NetworkPlayerController::~NetworkPlayerController()
|
||||
PlayerController::~PlayerController()
|
||||
{
|
||||
} // ~NetworkPlayerController
|
||||
} // ~PlayerController
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
/** Resets the player kart for a new or restarted race.
|
||||
*/
|
||||
void NetworkPlayerController::reset()
|
||||
void PlayerController::reset()
|
||||
{
|
||||
m_steer_val_l = 0;
|
||||
m_steer_val_r = 0;
|
||||
@ -58,7 +73,7 @@ void NetworkPlayerController::reset()
|
||||
* avoid that any keys pressed at the time the menu is opened are still
|
||||
* considered to be pressed.
|
||||
*/
|
||||
void NetworkPlayerController::resetInputState()
|
||||
void PlayerController::resetInputState()
|
||||
{
|
||||
m_steer_val_l = 0;
|
||||
m_steer_val_r = 0;
|
||||
@ -82,7 +97,7 @@ void NetworkPlayerController::resetInputState()
|
||||
* and if it's 0 it indicates that the corresponding button
|
||||
* was released.
|
||||
*/
|
||||
void NetworkPlayerController::action(PlayerAction action, int value)
|
||||
void PlayerController::action(PlayerAction action, int value)
|
||||
{
|
||||
switch (action)
|
||||
{
|
||||
@ -152,10 +167,8 @@ void NetworkPlayerController::action(PlayerAction action, int value)
|
||||
m_controls->m_rescue = (value!=0);
|
||||
break;
|
||||
case PA_FIRE:
|
||||
{
|
||||
m_controls->m_fire = (value!=0);
|
||||
break;
|
||||
}
|
||||
case PA_LOOK_BACK:
|
||||
m_controls->m_look_back = (value!=0);
|
||||
break;
|
||||
@ -163,12 +176,14 @@ void NetworkPlayerController::action(PlayerAction action, int value)
|
||||
if(value==0)
|
||||
m_controls->m_skid = KartControl::SC_NONE;
|
||||
else
|
||||
{
|
||||
if(m_steer_val==0)
|
||||
m_controls->m_skid = KartControl::SC_NO_DIRECTION;
|
||||
else
|
||||
m_controls->m_skid = m_steer_val<0
|
||||
? KartControl::SC_RIGHT
|
||||
: KartControl::SC_LEFT;
|
||||
}
|
||||
break;
|
||||
case PA_PAUSE_RACE:
|
||||
if (value != 0) StateManager::get()->escapePressed();
|
||||
@ -182,7 +197,7 @@ void NetworkPlayerController::action(PlayerAction action, int value)
|
||||
//-----------------------------------------------------------------------------
|
||||
/** Handles steering for a player kart.
|
||||
*/
|
||||
void NetworkPlayerController::steer(float dt, int steer_val)
|
||||
void PlayerController::steer(float dt, int steer_val)
|
||||
{
|
||||
if(stk_config->m_disable_steer_while_unskid &&
|
||||
m_controls->m_skid==KartControl::SC_NONE &&
|
||||
@ -228,10 +243,6 @@ void NetworkPlayerController::steer(float dt, int steer_val)
|
||||
if(m_controls->m_steer>0.0f) m_controls->m_steer=0.0f;
|
||||
} // if m_controls->m_steer<=0.0f
|
||||
} // no key is pressed
|
||||
if(UserConfigParams::m_gamepad_debug)
|
||||
{
|
||||
Log::debug("PlayerController", " set to: %f\n", m_controls->m_steer);
|
||||
}
|
||||
|
||||
m_controls->m_steer = std::min(1.0f, std::max(-1.0f, m_controls->m_steer));
|
||||
|
||||
@ -241,7 +252,7 @@ void NetworkPlayerController::steer(float dt, int steer_val)
|
||||
/** Callback when the skidding bonus is triggered. The player controller
|
||||
* resets the current steering to 0, which makes the kart easier to control.
|
||||
*/
|
||||
void NetworkPlayerController::skidBonusTriggered()
|
||||
void PlayerController::skidBonusTriggered()
|
||||
{
|
||||
m_controls->m_steer = 0;
|
||||
} // skidBonusTriggered
|
||||
@ -249,15 +260,8 @@ void NetworkPlayerController::skidBonusTriggered()
|
||||
//-----------------------------------------------------------------------------
|
||||
/** Updates the player kart, called once each timestep.
|
||||
*/
|
||||
void NetworkPlayerController::update(float dt)
|
||||
void PlayerController::update(float dt)
|
||||
{
|
||||
if (UserConfigParams::m_gamepad_debug)
|
||||
{
|
||||
// Print a dividing line so that it's easier to see which events
|
||||
// get received in which order in the one frame.
|
||||
Log::debug("PlayerController", "irr_driver", "-------------------------------------");
|
||||
}
|
||||
|
||||
// Don't do steering if it's replay. In position only replay it doesn't
|
||||
// matter, but if it's physics replay the gradual steering causes
|
||||
// incorrect results, since the stored values are already adjusted.
|
||||
@ -275,15 +279,7 @@ void NetworkPlayerController::update(float dt)
|
||||
if (m_penalty_time == 0.0 &&
|
||||
World::getWorld()->getPhase() == WorldStatus::SET_PHASE)
|
||||
{
|
||||
RaceGUIBase* m=World::getWorld()->getRaceGUI();
|
||||
if (m)
|
||||
{
|
||||
m->addMessage(_("Penalty time!!"), m_kart, 2.0f,
|
||||
video::SColor(255, 255, 128, 0));
|
||||
m->addMessage(_("Don't accelerate before go"), m_kart, 2.0f,
|
||||
video::SColor(255, 210, 100, 50));
|
||||
}
|
||||
|
||||
displayPenaltyWarning();
|
||||
m_penalty_time = stk_config->m_penalty_time;
|
||||
} // if penalty_time = 0
|
||||
|
||||
@ -300,9 +296,6 @@ void NetworkPlayerController::update(float dt)
|
||||
return;
|
||||
}
|
||||
|
||||
// We can't restrict rescue to fulfil isOnGround() (which would be more like
|
||||
// MK), since e.g. in the City track it is possible for the kart to end
|
||||
// up sitting on a brick wall, with all wheels in the air :((
|
||||
// Only accept rescue if there is no kart animation is already playing
|
||||
// (e.g. if an explosion happens, wait till the explosion is over before
|
||||
// starting any other animation).
|
||||
@ -313,56 +306,10 @@ void NetworkPlayerController::update(float dt)
|
||||
}
|
||||
} // update
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
/** Checks if the kart was overtaken, and if so plays a sound
|
||||
*/
|
||||
void NetworkPlayerController::setPosition(int p)
|
||||
{
|
||||
if(m_kart->getPosition()<p)
|
||||
{
|
||||
World *world = World::getWorld();
|
||||
//have the kart that did the passing beep.
|
||||
//I'm not sure if this method of finding the passing kart is fail-safe.
|
||||
for(unsigned int i = 0 ; i < world->getNumKarts(); i++ )
|
||||
{
|
||||
AbstractKart *kart = world->getKart(i);
|
||||
if(kart->getPosition() == p + 1)
|
||||
{
|
||||
kart->beep();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
} // setPosition
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
/** Called when a kart finishes race.
|
||||
* /param time Finishing time for this kart.
|
||||
d*/
|
||||
void NetworkPlayerController::finishedRace(float time)
|
||||
{
|
||||
|
||||
} // finishedRace
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
/** Called when a kart hits or uses a zipper.
|
||||
*/
|
||||
void NetworkPlayerController::handleZipper(bool play_sound)
|
||||
void PlayerController::handleZipper(bool play_sound)
|
||||
{
|
||||
m_kart->showZipperFire();
|
||||
} // handleZipper
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
/** Called when a kart hits an item.
|
||||
* \param item Item that was collected.
|
||||
* \param add_info Additional info to be used then handling the item. If
|
||||
* this is -1 (default), the item type is selected
|
||||
* randomly. Otherwise it contains the powerup or
|
||||
* attachment for the kart. This is used in network mode to
|
||||
* let the server determine the powerup/attachment for
|
||||
* the clients.
|
||||
*/
|
||||
void NetworkPlayerController::collectedItem(const Item &item, int add_info, float old_energy)
|
||||
{
|
||||
|
||||
} // collectedItem
|
95
src/karts/controller/player_controller.hpp
Normal file
95
src/karts/controller/player_controller.hpp
Normal file
@ -0,0 +1,95 @@
|
||||
// SuperTuxKart - a fun racing game with go-kart
|
||||
// Copyright (C) 2004-2015 Steve Baker <sjbaker1@airmail.net>
|
||||
// Copyright (C) 2006-2015 Joerg Henrichs, Steve Baker
|
||||
//
|
||||
// This program is free software; you can redistribute it and/or
|
||||
// modify it under the terms of the GNU General Public License
|
||||
// as published by the Free Software Foundation; either version 3
|
||||
// of the License, or (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program; if not, write to the Free Software
|
||||
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
|
||||
#ifndef HEADER_PLAYER_CONTROLLER_HPP
|
||||
#define HEADER_PLAYER_CONTROLLER_HPP
|
||||
|
||||
#include "karts/controller/controller.hpp"
|
||||
|
||||
class AbstractKart;
|
||||
class Player;
|
||||
|
||||
class PlayerController : public Controller
|
||||
{
|
||||
protected:
|
||||
int m_steer_val, m_steer_val_l, m_steer_val_r;
|
||||
int m_prev_accel;
|
||||
bool m_prev_brake;
|
||||
bool m_prev_nitro;
|
||||
|
||||
float m_penalty_time;
|
||||
|
||||
virtual void steer(float, int);
|
||||
// ------------------------------------------------------------------------
|
||||
/** Called when this kart started too early and got a start penalty. */
|
||||
virtual void displayPenaltyWarning() {}
|
||||
// ------------------------------------------------------------------------
|
||||
|
||||
public:
|
||||
PlayerController(AbstractKart *kart,
|
||||
StateManager::ActivePlayer *_player);
|
||||
virtual ~PlayerController ();
|
||||
virtual void update (float) OVERRIDE;
|
||||
virtual void action (PlayerAction action, int value) OVERRIDE;
|
||||
virtual void skidBonusTriggered() OVERRIDE;
|
||||
virtual void reset () OVERRIDE;
|
||||
virtual void handleZipper(bool play_sound) OVERRIDE;
|
||||
virtual void resetInputState();
|
||||
// ------------------------------------------------------------------------
|
||||
virtual void collectedItem(const Item &item, int add_info=-1,
|
||||
float previous_energy=0 ) OVERRIDE
|
||||
{
|
||||
};
|
||||
// ------------------------------------------------------------------------
|
||||
virtual bool isPlayerController() const OVERRIDE { return true; }
|
||||
// ------------------------------------------------------------------------
|
||||
virtual bool isLocalPlayerController() const OVERRIDE { return true; }
|
||||
// ------------------------------------------------------------------------
|
||||
/** Called just before the position of the kart is changed. */
|
||||
virtual void setPosition(int p) OVERRIDE
|
||||
{
|
||||
} // setPosition
|
||||
// ------------------------------------------------------------------------
|
||||
virtual void crashed(const AbstractKart *k)
|
||||
{
|
||||
} // crashed(AbstractKart)
|
||||
// ------------------------------------------------------------------------
|
||||
virtual void crashed(const Material *m)
|
||||
{
|
||||
} // crashed(Material)
|
||||
// ------------------------------------------------------------------------
|
||||
/** Callback whenever a new lap is triggered. Used by the AI
|
||||
* to trigger a recomputation of the way to use, not used for players. */
|
||||
virtual void newLap(int lap)
|
||||
{
|
||||
}
|
||||
// ------------------------------------------------------------------------
|
||||
/** Player will always be able to get a slipstream bonus. */
|
||||
virtual bool disableSlipstreamBonus() const
|
||||
{
|
||||
return false;
|
||||
}
|
||||
// ------------------------------------------------------------------------
|
||||
/** Called when a race is finished. */
|
||||
virtual void finishedRace(float time) OVERRIDE
|
||||
{
|
||||
} // finishedRace
|
||||
|
||||
}; // class PlayerController
|
||||
|
||||
#endif // HEADER_PLAYER_CONTROLLER_HPP
|
@ -1197,7 +1197,7 @@ void Kart::update(float dt)
|
||||
// automatic rescue
|
||||
// But only do this if auto-rescue is enabled (i.e. it will be disabled in
|
||||
// battle mode), and the material the kart is driving on does not have
|
||||
// gravity (which can
|
||||
// gravity (which atm affects the roll angle).
|
||||
if(World::getWorld()->getTrack()->isAutoRescueEnabled() &&
|
||||
(!m_terrain_info->getMaterial() ||
|
||||
!m_terrain_info->getMaterial()->hasGravity()) &&
|
||||
|
Loading…
Reference in New Issue
Block a user