2013-08-11 22:42:54 +02:00
|
|
|
#pragma once
|
|
|
|
#ifndef _GTAAICONTROLLER_HPP_
|
|
|
|
#define _GTAAICONTROLLER_HPP_
|
|
|
|
#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
|
|
|
|
|
|
|
struct GTACharacter;
|
2014-05-29 12:12:40 +02:00
|
|
|
struct GTAVehicle;
|
|
|
|
|
2013-08-11 22:42:54 +02:00
|
|
|
/**
|
|
|
|
* @class GTAAIController
|
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
|
|
|
*/
|
|
|
|
class GTAAIController
|
|
|
|
{
|
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
|
|
|
|
2014-05-29 12:12:40 +02:00
|
|
|
virtual bool update(GTACharacter* character, GTAAIController* controller) = 0;
|
2014-05-29 10:10:08 +02:00
|
|
|
};
|
|
|
|
|
2013-08-11 22:42:54 +02:00
|
|
|
protected:
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The character being controlled.
|
|
|
|
*/
|
|
|
|
GTACharacter* 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
|
|
|
|
2013-08-11 22:42:54 +02:00
|
|
|
public:
|
|
|
|
|
|
|
|
GTAAIController(GTACharacter* character);
|
2014-05-29 10:10:08 +02:00
|
|
|
|
2014-05-29 12:12:40 +02:00
|
|
|
Activity* getCurrentActivity() { return _currentActivity; }
|
2014-05-29 10:10:08 +02:00
|
|
|
|
2014-05-29 12:12:40 +02:00
|
|
|
Activity* getNextActivity() { return _nextActivity; }
|
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 );
|
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-05-29 12:12:40 +02:00
|
|
|
#define DECL_ACTIVITY( activity_name ) \
|
|
|
|
std::string name() const { return #activity_name; }
|
|
|
|
|
|
|
|
// TODO: Refactor this with an ugly macro to reduce code dup.
|
|
|
|
|
|
|
|
namespace Activities {
|
|
|
|
struct GoTo : public GTAAIController::Activity {
|
|
|
|
DECL_ACTIVITY( GoTo )
|
|
|
|
|
|
|
|
glm::vec3 target;
|
|
|
|
|
|
|
|
GoTo( const glm::vec3& target )
|
|
|
|
: target( target ) {}
|
|
|
|
|
|
|
|
bool update(GTACharacter* character, GTAAIController* controller);
|
|
|
|
};
|
|
|
|
|
|
|
|
struct EnterVehicle : public GTAAIController::Activity {
|
|
|
|
DECL_ACTIVITY( EnterVehicle )
|
|
|
|
|
|
|
|
GTAVehicle* vehicle;
|
|
|
|
unsigned int seat;
|
|
|
|
|
2014-05-31 09:18:50 +02:00
|
|
|
bool entering;
|
|
|
|
|
2014-05-29 12:12:40 +02:00
|
|
|
EnterVehicle( GTAVehicle* vehicle, unsigned 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
|
|
|
|
|
|
|
bool update(GTACharacter *character, GTAAIController *controller);
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2013-09-19 00:16:26 +02:00
|
|
|
#endif
|