Rigs of Rods 2023.09
Soft-body Physics Simulation
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
Loading...
Searching...
No Matches
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
39namespace RoR {
40
51
60
61class VehicleAI : public RefCountingObject<VehicleAI>
62{
63 // PLEASE maintain the same order as in 'bindings/VehicleAiAngelscript.cpp' and 'doc/../VehicleAIClass.h'
64
65public:
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
131private:
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;
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
Central state/object manager and communications hub.
Self reference-counting objects, as requred by AngelScript garbage collector.
void addEvent(std::string const &id, int ev)
Adds a event.
void setValueAtWaypoint(std::string const &id, int value_id, float value)
Sets a value at a waypoint.
Ogre::Vector3 getTranslation(int offset, unsigned int wp)
Gets offset translation based on vehicle rotation and waypoints.
Definition VehicleAI.cpp:85
int current_waypoint_id
The coordinates of the next waypoint.
Definition VehicleAI.h:146
void addWaypoints(AngelScript::CScriptDictionary &d)
Adds a dictionary with waypoints.
Definition VehicleAI.cpp:74
int free_waypoints
The amount of waypoints.
Definition VehicleAI.h:154
bool is_enabled
True if the AI is driving.
Definition VehicleAI.h:142
Ogre::Vector3 prev_waypoint
Definition VehicleAI.h:144
std::map< int, float > waypoint_wait_time
Map with all waypoint wait times.
Definition VehicleAI.h:153
void update(float dt, int doUpdate)
Updates the AI.
float maxspeed
(KM/H) The max speed the AI is allowed to drive.
Definition VehicleAI.h:140
Ogre::Vector3 current_waypoint
The coordinates of the waypoint that the AI is driving to.
Definition VehicleAI.h:143
float acc_power
The engine power.
Definition VehicleAI.h:155
std::map< int, Ogre::Vector3 > waypoints
Map with all waypoints.
Definition VehicleAI.h:147
void setActive(bool value)
Activates/Deactivates the AI.
Definition VehicleAI.cpp:52
ActorPtr beam
The verhicle the AI is driving.
Definition VehicleAI.h:141
Ogre::Vector3 next_waypoint
The coordinates of the previous waypoint.
Definition VehicleAI.h:145
std::map< int, int > waypoint_events
Map with all waypoint events.
Definition VehicleAI.h:150
std::map< std::string, int > waypoint_ids
Map with all waypoint IDs.
Definition VehicleAI.h:148
void addWaypoint(std::string const &id, Ogre::Vector3 const &point)
Adds one waypoint.
Definition VehicleAI.cpp:63
void updateWaypoint()
Updates the AI waypoint.
std::map< int, std::string > waypoint_names
Map with all waypoint names.
Definition VehicleAI.h:149
std::map< int, float > waypoint_power
Map with all waypoint engine power.
Definition VehicleAI.h:152
bool isActive()
Returns the status of the AI.
Definition VehicleAI.cpp:58
std::map< Ogre::String, float > waypoint_speed
Map with all waypoint speeds.
Definition VehicleAI.h:151
float wait_time
(seconds) The amount of time the AI has to wait.
Definition VehicleAI.h:138
virtual ~VehicleAI() override
Definition VehicleAI.cpp:48
Ai_events
Enum with AI events.
Definition VehicleAI.h:45
@ AI_LIGHTSTOGGLE
Definition VehicleAI.h:47
@ AI_BEACONSTOGGLE
Definition VehicleAI.h:49
@ AI_HORN
Definition VehicleAI.h:46
@ AI_WAIT_SECONDS
Definition VehicleAI.h:48
Ai_values
Enum with AI values that can be set.
Definition VehicleAI.h:56
@ AI_POWER
Definition VehicleAI.h:58
@ AI_SPEED
Definition VehicleAI.h:57