add --log-level option, improve Config/Logger documentation, fix NETWORK_EANBLED typos in Engine
#ifndef PLAYER_HH
#define PLAYER_HH
class Player;
class LocalPlayer;
class RemotePlayer;
#include "Weapon.hh"
#include "Projectile.hh"
#include "GameState.hh"
#include "PhysicsObject.hh"
#include "Rope.hh"
#include "Types.hh"
#include "Input.hh"
#include "Graphics/Drawable.hh"
#include <vector>
/**
* A Player is a PhysicsObject that represents a player - a remote client on the server, a local singleplayer player, a
* local network-client player, a remote network-client player, etc.
*/
class Player : public PhysicsObject {
friend class Rope;
public:
GameState &state;
protected:
// XXX: not used
bool visible;
// our weapons
std::vector<Weapon*> weapons;
// the index of the currently selected weapon
unsigned int selectedWeapon;
// we have a rope
Rope rope;
/** Our current health */
Health health;
/** Our respawn-timer */
Timer respawn_timer;
CL_Slot respawn_slot;
// XXX: updated where?
int animation_step;
//Player stats
uint16_t kills;
uint16_t deaths;
/**
* Default constructor for use with virtual inheritance... it's not defined, and must not be called
*/
Player (void);
/**
* Initialize params, and add ourselves to GameState
*/
Player (GameState &state, Vector position, bool visible);
/**
* Remove player from state players list
*/
~Player (void);
/**
* Move the worm to the given position, removeGround to dig a hole there, and enable ourselves
*/
virtual void spawn (Vector position);
/**
* We die. Disable and prepare respawn_timer
*/
virtual void die (bool start_timer = true);
/**
* Calculate a new position for the worm, and respawn there. Also set health back to 100%
*/
virtual void respawn (TimeMS dt);
/**
* Used by the network code to execute various actions
*/
virtual void handleDig (Vector position, float radius);
virtual void handleFireWeapon (Weapon *weapon, Vector position, Vector velocity);
virtual void handleChangeWeapon (unsigned int weaponIndex);
// Called by rope to handle state changes, these don't do anything by default
virtual void handleRopeState (RopeState state);
virtual void handleRopeLength (float length);
public:
/**
* Called when a weapon is fired, this should apply recoil and reload the weapon
*/
void weaponFired (Weapon *weapon);
/**
* Get the currently selected weapon
*
* @return A pointer to the Weapon object
*/
Weapon* getCurrentWeapon();
/**
* Get the weapon with the given index
*
* @return A pointer to a Weapon object if found, NULL otherwise
*/
Weapon* getWeapon (WeaponID id);
/**
* Prints random things via Engine::log
*/
void printDebugInfo ();
/**
* Overrides PhysicsObject::tick to also advance game state
*/
virtual void tick (TimeMS dt);
/**
* This is called when the player collides with the terrain or with some other object.
*/
void onCollision (Vector collisionPoint, PhysicsObject *other);
/**
* We have been hit by something, and therefore take some damage.
*
* XXX: should this take the Projectile instead or somesuch?
*/
void takeDamage (Projectile *source);
/**
* If the player has a pivot calculate the force it causes.
*/
Vector getPivotForce (void);
/**
* Gives player's health in percents from maximum
*/
float getHealthPercent() const;
/**
* Increment player killcounter by one.
*/
void addKill ();
#if GRAPHICS_ENABLED
/*
* Drawing requires the skin texture, which is loaded on-demand when draw is called
*/
static bool skin_loaded;
static CL_Surface skin_surface;
/**
* Draw this player
*/
virtual void draw (graphics::Display &display, PixelCoordinate camera);
#endif
/**
* Returns statistics on the number of kills for this player
*/
uint16_t getKills() { return kills; }
/**
* Returns statistics on the number of deaths for this player
*/
uint16_t getDeaths() { return deaths; }
};
/**
* A LocalPlayer is a Player that we handle input for - so this is our own player on the client/singleplayer, or all
* the remote clients on a server - the name is a bit misleading.
*
* This inherits virtually from Player so that subclasses can also define custom behaviour for the base Player class.
*/
class LocalPlayer : public virtual Player {
private:
/**
* Calculates projectil position/velocity and calls handleCreateProjectile
*/
void fireWeapon (Weapon *weapon);
/**
* Change weapon index, should be negative or positive 1
*/
void changeWeapon (int delta);
public:
/**
* Called to invoke some action on this player that we control, either by Graphics or NetworkServer.
*
* NetworkClientLocalPlayer overrides this to send the input to the server, which then handles it
*/
virtual void handleInput (PlayerInput input, TimeMS dt);
#if GRAPHICS_ENABLED
/**
* As Player, but also draws the current weapon name if displayWeapon
*/
virtual void draw (graphics::Display &display, bool displayWeapon, PixelCoordinate camera);
#endif
};
/**
* A RemotePlayer is a Player that we don't handle input for - they are a remote client connected to a remote server.
*
* This inherits virtually from Player so that subclasses can also define custom behaviour for the base Player class.
*/
class RemotePlayer : public virtual Player {
protected:
};
#endif