1
0
mirror of https://github.com/rwengine/openrw.git synced 2024-11-13 22:24:17 +01:00
openrw/rwengine/include/ai/GTAAIController.hpp

101 lines
2.0 KiB
C++
Raw Normal View History

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
* Character Controller Interface, translates high-level behaviours into low level actions.
2013-08-11 22:42:54 +02:00
*/
class GTAAIController
{
public:
2014-05-29 12:12:40 +02:00
/**
* @brief The Activity struct interface
*/
struct Activity {
2014-05-29 12:12:40 +02:00
virtual ~Activity() {}
2014-05-29 12:12:40 +02:00
virtual std::string name() const = 0;
2014-05-29 12:12:40 +02:00
virtual bool update(GTACharacter* character, GTAAIController* controller) = 0;
};
2013-08-11 22:42:54 +02:00
protected:
/**
* The character being controlled.
*/
GTACharacter* character;
2014-05-29 12:12:40 +02:00
Activity* _currentActivity;
Activity* _nextActivity;
bool updateActivity();
2014-05-29 12:12:40 +02:00
void setActivity(Activity* activity);
2013-08-11 22:42:54 +02:00
public:
GTAAIController(GTACharacter* character);
2014-05-29 12:12:40 +02:00
Activity* getCurrentActivity() { return _currentActivity; }
2014-05-29 12:12:40 +02:00
Activity* getNextActivity() { return _nextActivity; }
/**
* @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
/**
* @brief update Updates the controller.
* @param dt
2013-08-11 22:42:54 +02:00
*/
virtual void update(float dt);
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;
bool entering;
2014-05-29 12:12:40 +02:00
EnterVehicle( GTAVehicle* vehicle, unsigned int seat = 0 )
: vehicle( vehicle ), seat( seat ), entering(false) {}
2014-05-29 12:12:40 +02:00
bool update(GTACharacter *character, GTAAIController *controller);
};
}
#endif