openrw/rwengine/include/ai/CharacterController.hpp

141 lines
2.9 KiB
C++
Raw Normal View History

2013-08-11 20:42:54 +00:00
#pragma once
2014-06-06 17:04:00 +01:00
#ifndef _CHARACTERCONTROLLER_HPP_
#define _CHARACTERCONTROLLER_HPP_
2013-08-11 20:42:54 +00:00
#include <glm/glm.hpp>
#include <glm/gtc/quaternion.hpp>
2014-05-29 11:12:40 +01:00
#include <string>
2013-08-11 20:42:54 +00:00
2014-06-06 15:22:26 +01:00
struct CharacterObject;
struct VehicleObject;
2014-05-29 11:12:40 +01:00
2013-08-11 20:42:54 +00:00
/**
2014-06-06 17:04:00 +01:00
* @class CharacterController
* Character Controller Interface, translates high-level behaviours into low level actions.
2013-08-11 20:42:54 +00:00
*/
2014-06-06 17:04:00 +01:00
class CharacterController
2013-08-11 20:42:54 +00:00
{
public:
2014-05-29 11:12:40 +01:00
/**
* @brief The Activity struct interface
*/
struct Activity {
2014-05-29 11:12:40 +01:00
virtual ~Activity() {}
2014-05-29 11:12:40 +01:00
virtual std::string name() const = 0;
2014-06-06 17:04:00 +01:00
virtual bool update(CharacterObject* character, CharacterController* controller) = 0;
};
2013-08-11 20:42:54 +00:00
protected:
/**
* The character being controlled.
*/
2014-06-06 15:22:26 +01:00
CharacterObject* character;
2014-05-29 11:12:40 +01:00
Activity* _currentActivity;
Activity* _nextActivity;
bool updateActivity();
2014-05-29 11:12:40 +01:00
void setActivity(Activity* activity);
2013-08-11 20:42:54 +00:00
public:
2014-06-06 17:04:00 +01:00
CharacterController(CharacterObject* character);
2014-06-10 17:51:55 +01:00
virtual ~CharacterController() { }
2014-05-29 11:12:40 +01:00
Activity* getCurrentActivity() { return _currentActivity; }
2014-05-29 11:12:40 +01:00
Activity* getNextActivity() { return _nextActivity; }
/**
* @brief skipActivity Cancel the current activity, immediatley.
*/
void skipActivity();
/**
* @brief setNextActivity Sets the next Activity with a parameter.
* @param activity
* @param position
*/
2014-05-29 11:12:40 +01:00
void setNextActivity( Activity* activity );
2013-08-11 20:42:54 +00:00
/**
* @brief update Updates the controller.
* @param dt
2013-08-11 20:42:54 +00:00
*/
virtual void update(float dt);
2013-08-11 20:42:54 +00:00
virtual glm::vec3 getTargetPosition() = 0;
/**
* Uses the character's active item.
* @param primary use the primary action.
*/
void useItem(bool active, bool primary = true);
2013-08-11 20:42:54 +00:00
};
2014-05-29 11:12:40 +01:00
#define DECL_ACTIVITY( activity_name ) \
std::string name() const { return #activity_name; }
// TODO: Refactor this with an ugly macro to reduce code dup.
class WeaponItem;
2014-05-29 11:12:40 +01:00
/**
* @brief Activities for CharacterController behaviour
*
* @todo Move into ControllerActivities.hpp or equivelant
*/
2014-05-29 11:12:40 +01:00
namespace Activities {
2014-06-06 17:04:00 +01:00
struct GoTo : public CharacterController::Activity {
2014-05-29 11:12:40 +01:00
DECL_ACTIVITY( GoTo )
glm::vec3 target;
GoTo( const glm::vec3& target )
: target( target ) {}
2014-06-06 17:04:00 +01:00
bool update(CharacterObject* character, CharacterController* controller);
2014-05-29 11:12:40 +01:00
};
2014-06-06 17:04:00 +01:00
struct EnterVehicle : public CharacterController::Activity {
2014-05-29 11:12:40 +01:00
DECL_ACTIVITY( EnterVehicle )
2014-06-06 15:22:26 +01:00
VehicleObject* vehicle;
2014-05-29 11:12:40 +01:00
unsigned int seat;
bool entering;
2014-06-06 15:22:26 +01:00
EnterVehicle( VehicleObject* vehicle, unsigned int seat = 0 )
: vehicle( vehicle ), seat( seat ), entering(false) {}
2014-05-29 11:12:40 +01:00
2014-06-06 17:04:00 +01:00
bool update(CharacterObject *character, CharacterController *controller);
2014-05-29 11:12:40 +01:00
};
2014-06-02 22:18:30 +01:00
2014-06-06 17:04:00 +01:00
struct ExitVehicle : public CharacterController::Activity {
2014-06-02 22:18:30 +01:00
DECL_ACTIVITY( ExitVehicle )
ExitVehicle( )
{}
2014-06-06 17:04:00 +01:00
bool update(CharacterObject *character, CharacterController *controller);
2014-06-02 22:18:30 +01:00
};
struct ShootWeapon : public CharacterController::Activity {
DECL_ACTIVITY( ShootWeapon )
WeaponItem* _item;
2014-06-30 01:56:45 +01:00
bool _fired;
ShootWeapon( WeaponItem* item )
2014-06-30 01:56:45 +01:00
: _item(item), _fired(false) {}
bool update(CharacterObject *character, CharacterController *controller);
};
2014-05-29 11:12:40 +01:00
}
#endif