2013-08-11 22:42:54 +02:00
|
|
|
#pragma once
|
2014-06-06 18:04:00 +02:00
|
|
|
#ifndef _CHARACTERCONTROLLER_HPP_
|
|
|
|
#define _CHARACTERCONTROLLER_HPP_
|
2013-08-11 22:42:54 +02:00
|
|
|
#include <glm/glm.hpp>
|
|
|
|
#include <glm/gtc/quaternion.hpp>
|
2014-05-29 12:12:40 +02:00
|
|
|
#include <string>
|
2013-08-11 22:42:54 +02:00
|
|
|
|
2015-02-26 02:15:17 +01:00
|
|
|
struct AIGraphNode;
|
2014-08-11 18:58:43 +02:00
|
|
|
class CharacterObject;
|
|
|
|
class VehicleObject;
|
2014-05-29 12:12:40 +02:00
|
|
|
|
2013-08-11 22:42:54 +02:00
|
|
|
/**
|
2014-06-06 18:04:00 +02:00
|
|
|
* @class CharacterController
|
2013-09-19 00:16:26 +02:00
|
|
|
* Character Controller Interface, translates high-level behaviours into low level actions.
|
2013-08-11 22:42:54 +02:00
|
|
|
*/
|
2014-06-06 18:04:00 +02:00
|
|
|
class CharacterController
|
2013-08-11 22:42:54 +02:00
|
|
|
{
|
2014-05-29 10:10:08 +02:00
|
|
|
public:
|
|
|
|
|
2014-05-29 12:12:40 +02:00
|
|
|
/**
|
|
|
|
* @brief The Activity struct interface
|
|
|
|
*/
|
|
|
|
struct Activity {
|
2014-05-29 10:10:08 +02:00
|
|
|
|
2014-05-29 12:12:40 +02:00
|
|
|
virtual ~Activity() {}
|
2014-05-29 10:10:08 +02:00
|
|
|
|
2014-05-29 12:12:40 +02:00
|
|
|
virtual std::string name() const = 0;
|
2014-05-29 10:10:08 +02:00
|
|
|
|
2016-05-25 00:49:01 +02:00
|
|
|
/**
|
|
|
|
* @brief canSkip
|
|
|
|
* @return true if the activity can be skipped.
|
|
|
|
*/
|
|
|
|
virtual bool canSkip(CharacterObject*, CharacterController*) const { return false; }
|
|
|
|
|
2014-06-06 18:04:00 +02:00
|
|
|
virtual bool update(CharacterObject* character, CharacterController* controller) = 0;
|
2014-05-29 10:10:08 +02:00
|
|
|
};
|
2015-01-22 16:00:30 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Available AI goals.
|
|
|
|
*/
|
|
|
|
enum Goal
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* No goal, will idle or execute external Activities.
|
|
|
|
*/
|
|
|
|
None,
|
|
|
|
/**
|
|
|
|
* Keep close to leader character
|
|
|
|
*/
|
2015-02-26 02:15:17 +01:00
|
|
|
FollowLeader,
|
|
|
|
/**
|
|
|
|
* Wander randomly around the map
|
|
|
|
*/
|
|
|
|
TrafficWander
|
2015-01-22 16:00:30 +01:00
|
|
|
};
|
2014-05-29 10:10:08 +02:00
|
|
|
|
2013-08-11 22:42:54 +02:00
|
|
|
protected:
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The character being controlled.
|
|
|
|
*/
|
2014-06-06 16:22:26 +02:00
|
|
|
CharacterObject* character;
|
2014-05-29 10:10:08 +02:00
|
|
|
|
2014-05-29 12:12:40 +02:00
|
|
|
Activity* _currentActivity;
|
|
|
|
Activity* _nextActivity;
|
2014-05-29 10:10:08 +02:00
|
|
|
|
|
|
|
bool updateActivity();
|
2014-05-29 12:12:40 +02:00
|
|
|
void setActivity(Activity* activity);
|
2014-05-29 10:10:08 +02:00
|
|
|
|
2015-01-23 03:03:21 +01:00
|
|
|
float vehicleIdle;
|
|
|
|
|
2015-01-22 16:00:30 +01:00
|
|
|
// Goal related variables
|
|
|
|
Goal currentGoal;
|
|
|
|
CharacterObject* leader;
|
2015-02-26 02:15:17 +01:00
|
|
|
AIGraphNode* targetNode;
|
2014-08-26 23:54:26 +02:00
|
|
|
|
2013-08-11 22:42:54 +02:00
|
|
|
public:
|
|
|
|
|
2014-06-06 18:04:00 +02:00
|
|
|
CharacterController(CharacterObject* character);
|
2014-05-29 10:10:08 +02:00
|
|
|
|
2014-06-10 18:51:55 +02:00
|
|
|
virtual ~CharacterController() { }
|
|
|
|
|
2016-05-25 00:49:01 +02:00
|
|
|
Activity* getCurrentActivity() const { return _currentActivity; }
|
2014-05-29 10:10:08 +02:00
|
|
|
|
2016-05-25 00:49:01 +02:00
|
|
|
Activity* getNextActivity() const { return _nextActivity; }
|
2014-05-29 10:10:08 +02:00
|
|
|
|
2014-06-01 19:44:43 +02:00
|
|
|
/**
|
2016-05-25 00:49:01 +02:00
|
|
|
* @brief skipActivity Cancel the current activity immediatley, if possible.
|
2014-06-01 19:44:43 +02:00
|
|
|
*/
|
|
|
|
void skipActivity();
|
|
|
|
|
2014-05-29 10:10:08 +02:00
|
|
|
/**
|
|
|
|
* @brief setNextActivity Sets the next Activity with a parameter.
|
|
|
|
* @param activity
|
|
|
|
* @param position
|
|
|
|
*/
|
2014-05-29 12:12:40 +02:00
|
|
|
void setNextActivity( Activity* activity );
|
2016-05-25 00:49:01 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief IsCurrentActivity
|
|
|
|
* @param activity Name of activity to check for
|
|
|
|
* @return if the given activity is the current activity
|
|
|
|
*/
|
|
|
|
bool isCurrentActivity(const std::string& activity) const;
|
2013-08-11 22:42:54 +02:00
|
|
|
|
|
|
|
/**
|
2013-09-19 00:16:26 +02:00
|
|
|
* @brief update Updates the controller.
|
|
|
|
* @param dt
|
2013-08-11 22:42:54 +02:00
|
|
|
*/
|
2014-05-29 10:10:08 +02:00
|
|
|
virtual void update(float dt);
|
2013-09-19 00:16:26 +02:00
|
|
|
|
2013-08-11 22:42:54 +02:00
|
|
|
virtual glm::vec3 getTargetPosition() = 0;
|
2014-06-29 23:14:46 +02:00
|
|
|
|
2014-07-25 04:30:44 +02:00
|
|
|
/**
|
|
|
|
* @brief
|
|
|
|
* @return Returns the Character Object
|
|
|
|
*/
|
|
|
|
CharacterObject* getCharacter() const;
|
2014-08-26 23:54:26 +02:00
|
|
|
|
2016-04-17 05:54:19 +02:00
|
|
|
void setMoveDirection(const glm::vec3& movement);
|
2016-05-23 22:35:49 +02:00
|
|
|
void setLookDirection(const glm::vec2& look);
|
2014-08-26 23:54:26 +02:00
|
|
|
|
|
|
|
void setRunning(bool run);
|
2015-01-22 16:00:30 +01:00
|
|
|
|
|
|
|
void setGoal(Goal goal) { currentGoal = goal; }
|
|
|
|
Goal getGoal() const { return currentGoal; }
|
|
|
|
|
|
|
|
void setTargetCharacter(CharacterObject* c) { leader = c; }
|
|
|
|
CharacterObject* getTargetCharacter() const { return leader; }
|
2013-08-11 22:42:54 +02:00
|
|
|
};
|
|
|
|
|
2014-05-29 12:12:40 +02:00
|
|
|
#define DECL_ACTIVITY( activity_name ) \
|
2016-05-25 00:49:01 +02:00
|
|
|
static constexpr auto ActivityName = #activity_name; \
|
|
|
|
std::string name() const { return ActivityName; }
|
2014-05-29 12:12:40 +02:00
|
|
|
|
|
|
|
// TODO: Refactor this with an ugly macro to reduce code dup.
|
2014-06-29 23:14:46 +02:00
|
|
|
class WeaponItem;
|
2014-05-29 12:12:40 +02:00
|
|
|
|
2014-07-09 06:04:48 +02:00
|
|
|
/**
|
|
|
|
* @brief Activities for CharacterController behaviour
|
|
|
|
*
|
|
|
|
* @todo Move into ControllerActivities.hpp or equivelant
|
|
|
|
*/
|
2014-05-29 12:12:40 +02:00
|
|
|
namespace Activities {
|
2014-06-06 18:04:00 +02:00
|
|
|
struct GoTo : public CharacterController::Activity {
|
2014-05-29 12:12:40 +02:00
|
|
|
DECL_ACTIVITY( GoTo )
|
|
|
|
|
|
|
|
glm::vec3 target;
|
2015-05-09 05:40:41 +02:00
|
|
|
bool sprint;
|
2014-05-29 12:12:40 +02:00
|
|
|
|
2015-05-09 05:40:41 +02:00
|
|
|
GoTo( const glm::vec3& target, bool _sprint = false )
|
|
|
|
: target( target ), sprint(_sprint) {}
|
2014-05-29 12:12:40 +02:00
|
|
|
|
2014-06-06 18:04:00 +02:00
|
|
|
bool update(CharacterObject* character, CharacterController* controller);
|
2016-05-25 00:49:01 +02:00
|
|
|
|
|
|
|
bool canSkip(CharacterObject *, CharacterController *) const { return true; }
|
2014-05-29 12:12:40 +02:00
|
|
|
};
|
2014-12-13 02:24:06 +01:00
|
|
|
|
|
|
|
struct Jump : public CharacterController::Activity
|
|
|
|
{
|
|
|
|
DECL_ACTIVITY( Jump )
|
|
|
|
|
|
|
|
bool jumped;
|
|
|
|
|
|
|
|
Jump() : jumped(false) {}
|
|
|
|
|
|
|
|
bool update(CharacterObject* character, CharacterController* controller);
|
|
|
|
};
|
2014-05-29 12:12:40 +02:00
|
|
|
|
2014-06-06 18:04:00 +02:00
|
|
|
struct EnterVehicle : public CharacterController::Activity {
|
2014-05-29 12:12:40 +02:00
|
|
|
DECL_ACTIVITY( EnterVehicle )
|
|
|
|
|
2014-06-06 16:22:26 +02:00
|
|
|
VehicleObject* vehicle;
|
2015-01-23 18:54:17 +01:00
|
|
|
int seat;
|
|
|
|
|
|
|
|
enum {
|
|
|
|
ANY_SEAT = -1 // Magic number for any seat but the driver's.
|
|
|
|
};
|
2014-05-29 12:12:40 +02:00
|
|
|
|
2014-05-31 09:18:50 +02:00
|
|
|
bool entering;
|
|
|
|
|
2015-01-23 18:54:17 +01:00
|
|
|
EnterVehicle( VehicleObject* vehicle, int seat = 0 )
|
2014-05-31 09:18:50 +02:00
|
|
|
: vehicle( vehicle ), seat( seat ), entering(false) {}
|
2014-05-29 12:12:40 +02:00
|
|
|
|
2016-05-25 00:49:01 +02:00
|
|
|
bool canSkip(CharacterObject* character, CharacterController*) const override;
|
|
|
|
|
2014-06-06 18:04:00 +02:00
|
|
|
bool update(CharacterObject *character, CharacterController *controller);
|
2014-05-29 12:12:40 +02:00
|
|
|
};
|
2014-06-02 23:18:30 +02:00
|
|
|
|
2014-06-06 18:04:00 +02:00
|
|
|
struct ExitVehicle : public CharacterController::Activity {
|
2014-06-02 23:18:30 +02:00
|
|
|
DECL_ACTIVITY( ExitVehicle )
|
|
|
|
|
|
|
|
ExitVehicle( )
|
|
|
|
{}
|
|
|
|
|
2014-06-06 18:04:00 +02:00
|
|
|
bool update(CharacterObject *character, CharacterController *controller);
|
2014-06-02 23:18:30 +02:00
|
|
|
};
|
2014-06-29 23:14:46 +02:00
|
|
|
|
|
|
|
struct ShootWeapon : public CharacterController::Activity {
|
|
|
|
DECL_ACTIVITY( ShootWeapon )
|
|
|
|
|
|
|
|
WeaponItem* _item;
|
2014-06-30 02:56:45 +02:00
|
|
|
bool _fired;
|
2014-06-29 23:14:46 +02:00
|
|
|
|
|
|
|
ShootWeapon( WeaponItem* item )
|
2014-06-30 02:56:45 +02:00
|
|
|
: _item(item), _fired(false) {}
|
2014-06-29 23:14:46 +02:00
|
|
|
|
|
|
|
bool update(CharacterObject *character, CharacterController *controller);
|
|
|
|
};
|
2014-05-29 12:12:40 +02:00
|
|
|
}
|
|
|
|
|
2013-09-19 00:16:26 +02:00
|
|
|
#endif
|