RigsofRods
Soft-body Physics Simulation
VehicleAI.h
Go to the documentation of this file.
1 /*
2  This source file is part of Rigs of Rods
3 
4  Copyright 2005-2012 Pierre-Michel Ricordel
5  Copyright 2007-2012 Thomas Fischer
6  Copyright 2013-2016 Petr Ohlidal
7 
8  For more information, see http://www.rigsofrods.org/
9 
10  Rigs of Rods is free software: you can redistribute it and/or modify
11  it under the terms of the GNU General Public License version 3, as
12  published by the Free Software Foundation.
13 
14  Rigs of Rods is distributed in the hope that it will be useful,
15  but WITHOUT ANY WARRANTY; without even the implied warranty of
16  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17  GNU General Public License for more details.
18 
19  You should have received a copy of the GNU General Public License
20  along with Rigs of Rods. If not, see <http://www.gnu.org/licenses/>.
21 */
22 
27 
28 #pragma once
29 
30 #ifdef USE_ANGELSCRIPT
31 
32 #include "Application.h"
33 #include "RefCountingObject.h"
34 
35 #include "scriptdictionary/scriptdictionary.h"
36 
37 #include <string>
38 
39 namespace RoR {
40 
45 {
50 };
51 
56 {
59 };
60 
61 class VehicleAI : public RefCountingObject<VehicleAI>
62 {
63  // PLEASE maintain the same order as in 'bindings/VehicleAiAngelscript.cpp' and 'doc/../VehicleAIClass.h'
64 
65 public:
67  virtual ~VehicleAI() override;
68 
73  void setActive(bool value);
74 
79  bool isActive();
80 
87  void addWaypoint(std::string const& id, Ogre::Vector3 const& point);
88 
93  void addWaypoints(AngelScript::CScriptDictionary& d);
94 
103  void addEvent(std::string const& id, int ev);
104 
114  void setValueAtWaypoint(std::string const& id, int value_id, float value);
115 
122  Ogre::Vector3 getTranslation(int offset, unsigned int wp);
123 
124  // Not exported to script:
125 
129  void update(float dt, int doUpdate);
130 
131 private:
135  void updateWaypoint();
136 
137  bool is_waiting=false;
138  float wait_time=0.f;
139 
140  float maxspeed = 50;
142  bool is_enabled = false;
143  Ogre::Vector3 current_waypoint = Ogre::Vector3::ZERO;
144  Ogre::Vector3 prev_waypoint = Ogre::Vector3::ZERO;;
145  Ogre::Vector3 next_waypoint = Ogre::Vector3::ZERO;;
147  std::map<int, Ogre::Vector3> waypoints;
148  std::map<std::string, int> waypoint_ids;
149  std::map<int, std::string> waypoint_names;
150  std::map<int, int> waypoint_events;
151  std::map<Ogre::String, float> waypoint_speed;
152  std::map<int, float> waypoint_power;
153  std::map<int, float> waypoint_wait_time;
154  int free_waypoints = 0;
155  float acc_power = 0.8;
156  float init_y = 0;
157  bool last_waypoint = false;
158  bool hold = false;
159 };
160 
161 } // namespace RoR
162 
163 #endif // USE_ANGELSCRIPT
RoR::VehicleAI::addEvent
void addEvent(std::string const &id, int ev)
Adds a event.
Definition: VehicleAI.cpp:127
RoR::VehicleAI::acc_power
float acc_power
The engine power.
Definition: VehicleAI.h:155
RoR::VehicleAI::addWaypoint
void addWaypoint(std::string const &id, Ogre::Vector3 const &point)
Adds one waypoint.
Definition: VehicleAI.cpp:63
RoR::VehicleAI::current_waypoint
Ogre::Vector3 current_waypoint
The coordinates of the waypoint that the AI is driving to.
Definition: VehicleAI.h:143
RoR::VehicleAI::next_waypoint
Ogre::Vector3 next_waypoint
The coordinates of the previous waypoint.
Definition: VehicleAI.h:145
RoR::AI_WAIT_SECONDS
@ AI_WAIT_SECONDS
Definition: VehicleAI.h:48
RoR::Ai_values
Ai_values
Enum with AI values that can be set.
Definition: VehicleAI.h:55
RoR::VehicleAI::current_waypoint_id
int current_waypoint_id
The coordinates of the next waypoint.
Definition: VehicleAI.h:146
RoR::AI_BEACONSTOGGLE
@ AI_BEACONSTOGGLE
Definition: VehicleAI.h:49
RoR::VehicleAI::is_waiting
bool is_waiting
Definition: VehicleAI.h:137
RoR::VehicleAI::prev_waypoint
Ogre::Vector3 prev_waypoint
Definition: VehicleAI.h:144
RefCountingObjectPtr< Actor >
RoR::VehicleAI
Definition: VehicleAI.h:61
RoR::VehicleAI::last_waypoint
bool last_waypoint
Definition: VehicleAI.h:157
RoR::VehicleAI::is_enabled
bool is_enabled
True if the AI is driving.
Definition: VehicleAI.h:142
RoR::VehicleAI::isActive
bool isActive()
Returns the status of the AI.
Definition: VehicleAI.cpp:58
RoR::VehicleAI::waypoint_names
std::map< int, std::string > waypoint_names
Map with all waypoint names.
Definition: VehicleAI.h:149
RoR::VehicleAI::setValueAtWaypoint
void setValueAtWaypoint(std::string const &id, int value_id, float value)
Sets a value at a waypoint.
Definition: VehicleAI.cpp:134
RoR::VehicleAI::getTranslation
Ogre::Vector3 getTranslation(int offset, unsigned int wp)
Gets offset translation based on vehicle rotation and waypoints.
Definition: VehicleAI.cpp:85
RoR::VehicleAI::waypoint_wait_time
std::map< int, float > waypoint_wait_time
Map with all waypoint wait times.
Definition: VehicleAI.h:153
RoR::VehicleAI::init_y
float init_y
Definition: VehicleAI.h:156
RefCountingObject.h
RoR::AI_HORN
@ AI_HORN
Definition: VehicleAI.h:46
Application.h
Central state/object manager and communications hub.
RoR::AI_POWER
@ AI_POWER
Definition: VehicleAI.h:58
RoR::VehicleAI::free_waypoints
int free_waypoints
The amount of waypoints.
Definition: VehicleAI.h:154
RoR::Ai_events
Ai_events
Enum with AI events.
Definition: VehicleAI.h:44
RoR::VehicleAI::updateWaypoint
void updateWaypoint()
Updates the AI waypoint.
Definition: VehicleAI.cpp:153
RoR::VehicleAI::wait_time
float wait_time
(seconds) The amount of time the AI has to wait.
Definition: VehicleAI.h:138
RoR::VehicleAI::maxspeed
float maxspeed
(KM/H) The max speed the AI is allowed to drive.
Definition: VehicleAI.h:140
RoR::VehicleAI::beam
ActorPtr beam
The verhicle the AI is driving.
Definition: VehicleAI.h:141
RoR::VehicleAI::waypoint_events
std::map< int, int > waypoint_events
Map with all waypoint events.
Definition: VehicleAI.h:150
RoR::VehicleAI::VehicleAI
VehicleAI(ActorPtr b)
Definition: VehicleAI.cpp:41
RoR::AI_SPEED
@ AI_SPEED
Definition: VehicleAI.h:57
RoR::VehicleAI::addWaypoints
void addWaypoints(AngelScript::CScriptDictionary &d)
Adds a dictionary with waypoints.
Definition: VehicleAI.cpp:74
RefCountingObject
Self reference-counting objects, as requred by AngelScript garbage collector.
Definition: RefCountingObject.h:26
RoR::VehicleAI::~VehicleAI
virtual ~VehicleAI() override
Definition: VehicleAI.cpp:48
RoR::VehicleAI::waypoint_speed
std::map< Ogre::String, float > waypoint_speed
Map with all waypoint speeds.
Definition: VehicleAI.h:151
RoR::VehicleAI::waypoint_ids
std::map< std::string, int > waypoint_ids
Map with all waypoint IDs.
Definition: VehicleAI.h:148
RoR
Definition: AppContext.h:36
RoR::VehicleAI::update
void update(float dt, int doUpdate)
Updates the AI.
Definition: VehicleAI.cpp:216
RoR::VehicleAI::setActive
void setActive(bool value)
Activates/Deactivates the AI.
Definition: VehicleAI.cpp:52
RoR::VehicleAI::hold
bool hold
Definition: VehicleAI.h:158
RoR::AI_LIGHTSTOGGLE
@ AI_LIGHTSTOGGLE
Definition: VehicleAI.h:47
RoR::VehicleAI::waypoints
std::map< int, Ogre::Vector3 > waypoints
Map with all waypoints.
Definition: VehicleAI.h:147
RoR::VehicleAI::waypoint_power
std::map< int, float > waypoint_power
Map with all waypoint engine power.
Definition: VehicleAI.h:152