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
GameScript.h
Go to the documentation of this file.
1/*
2 This source file is part of Rigs of Rods
3 Copyright 2005-2012 Pierre-Michel Ricordel
4 Copyright 2007-2012 Thomas Fischer
5 Copyright 2013-2020 Petr Ohlidal
6
7 For more information, see http://www.rigsofrods.org/
8
9 Rigs of Rods is free software: you can redistribute it and/or modify
10 it under the terms of the GNU General Public License version 3, as
11 published by the Free Software Foundation.
12
13 Rigs of Rods is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
17
18 You should have received a copy of the GNU General Public License
19 along with Rigs of Rods. If not, see <http://www.gnu.org/licenses/>.
20*/
21
25
26#pragma once
27
28#include "Application.h"
29
30#include <angelscript.h>
31#include <scriptdictionary/scriptdictionary.h>
32
33namespace RoR {
34
37
42{
43public:
44 // PLEASE maintain the same order as in GameScriptAngelscript.cpp!
45
48
53 void log(const Ogre::String& msg);
54
59 float getTime();
60
61 void backToMenu();
62 void quitGame();
63 float getFPS();
64 float getAvgFPS();
65 float rangeRandom(float from, float to);
66
67 int useOnlineAPI(const Ogre::String& apiquery, const AngelScript::CScriptDictionary& dict, Ogre::String& result);
68
72 void openUrlInDefaultBrowser(const std::string& url);
73
77 void fetchUrlAsStringAsync(const std::string& url, const std::string& display_filename);
78
83 bool pushMessage(MsgType type, AngelScript::CScriptDictionary* dict);
84
90 bool checkResourceExists(const std::string& filename, const std::string& resource_group);
91
96 bool deleteResource(const std::string& filename, const std::string& resource_group);
97
104 std::string loadTextResourceAsString(const std::string& filename, const std::string& resource_group);
105
115 bool createTextResourceFromString(const std::string& data, const std::string& filename, const std::string& resource_group, bool overwrite=false);
116
117 Ogre::SceneManager* getSceneManager();
118
122 AngelScript::CScriptArray* findResourceFileInfo(const std::string& resource_group, const std::string& pattern, bool dirs = false);
123
127 Ogre::Image loadImageResource(const std::string& filename, const std::string& resource_group);
128
132 bool serializeMeshResource(const std::string& filename, const std::string& resource_group, const Ogre::MeshPtr& mesh);
133
135
138
143 void flashMessage(Ogre::String& txt, float time, float charHeight);
144
148 void message(Ogre::String& txt, Ogre::String& icon);
149
153 int getChatFontSize();
154
158 void setChatFontSize(int size);
159
160 void showMessageBox(Ogre::String& title, Ogre::String& text, bool use_btn1, Ogre::String& btn1_text, bool allow_close, bool use_btn2, Ogre::String& btn2_text);
161
162 void showChooser(const Ogre::String& type, const Ogre::String& instance, const Ogre::String& box);
163
168 void updateDirectionArrow(Ogre::String& text, Ogre::Vector3& vec);
169
170 void hideDirectionArrow();
171
177 bool getScreenPosFromWorldPos(Ogre::Vector3 const& world_pos, Ogre::Vector2& out_screen_pos);
178
182 Ogre::Vector2 getDisplaySize();
183
187 Ogre::Vector2 getMouseScreenPosition();
188
190
193
198 void registerForEvent(int eventValue);
199
204 void unRegisterEvent(int eventValue);
205
211
218
224 ScriptRetCode_t addScriptFunction(const Ogre::String& arg, ScriptUnitID_t nid);
225
231 ScriptRetCode_t scriptFunctionExists(const Ogre::String& arg, ScriptUnitID_t nid);
232
238 ScriptRetCode_t deleteScriptFunction(const Ogre::String& arg, ScriptUnitID_t nid);
239
245 ScriptRetCode_t addScriptVariable(const Ogre::String& arg, ScriptUnitID_t nid);
246
252 ScriptRetCode_t scriptVariableExists(const Ogre::String& arg, ScriptUnitID_t nid);
253
259 ScriptRetCode_t deleteScriptVariable(const Ogre::String& arg, ScriptUnitID_t nid);
260
269 ScriptRetCode_t getScriptVariable(const Ogre::String& varName, void *ref, int refTypeId, ScriptUnitID_t nid);
270
271 void clearEventCache();
272
276 int sendGameCmd(const Ogre::String& message);
277
281 AngelScript::CScriptArray* getRunningScripts();
282
291 AngelScript::CScriptDictionary* getScriptDetails(ScriptUnitID_t nid);
292
294
297
298 void loadTerrain(const Ogre::String& terrain);
299
304 int getLoadedTerrain(Ogre::String& result);
305
306 bool getCaelumAvailable();
307
312 Ogre::String getCaelumTime();
313
318 void setCaelumTime(float value);
319
324 float getGravity();
325
330 void setGravity(float value);
331
335 float getGroundHeight(Ogre::Vector3& v);
336
341 float getWaterHeight();
342
347 void setWaterHeight(float value);
348
358 void spawnObject(const Ogre::String& objectName, const Ogre::String& instanceName, const Ogre::Vector3& pos, const Ogre::Vector3& rot, const Ogre::String& eventhandler, bool uniquifyMaterials);
359
366 void moveObjectVisuals(const Ogre::String& instanceName, const Ogre::Vector3& pos);
367
373 void destroyObject(const Ogre::String& instanceName);
374
378 AngelScript::CScriptArray* getEditorObjects();
379
385 bool getMousePositionOnTerrain(Ogre::Vector3& out_pos);
386
390 AngelScript::CScriptArray* getMousePointedMovableObjects();
391
393
395
398
399 Ogre::Vector3 getPersonPosition();
400
405 void setPersonPosition(const Ogre::Vector3& vec);
406
411 void movePerson(const Ogre::Vector3& vec);
412
417 void setPersonRotation(const Ogre::Radian& rot);
418
423 Ogre::Radian getPersonRotation();
424
426
429
430 void activateAllVehicles();
431
432 void setTrucksForcedAwake(bool forceActive);
433
434 //anglescript test
435 void boostCurrentTruck(float factor);
436
442
447 ActorPtr getTruckByNum(int num);
448
453 AngelScript::CScriptArray* getAllTrucks();
454
460
461 ActorPtr spawnTruck(Ogre::String& truckName, Ogre::Vector3& pos, Ogre::Vector3& rot);
462
463 void repairVehicle(const Ogre::String& instance, const Ogre::String& box, bool keepPosition);
464
465 void removeVehicle(const Ogre::String& instance, const Ogre::String& box);
466
467 int getNumTrucksByFlag(int flag);
468
474
479
481
484
489
494
496
499
500 ActorPtr spawnTruckAI(Ogre::String& truckName, Ogre::Vector3& pos, Ogre::String& truckSectionConfig, std::string& truckSkin, int x);
501 AngelScript::CScriptArray* getWaypoints(int x);
502 AngelScript::CScriptArray* getWaypointsSpeed();
503 void addWaypoint(const Ogre::Vector3& pos);
504 int getAIVehicleCount();
507 int getAIVehicleSpeed();
508 Ogre::String getAIVehicleName(int x);
509 Ogre::String getAIVehicleSectionConfig(int x);
510 std::string getAIVehicleSkin(int x);
511 int getAIRepeatTimes();
512 int getAIMode();
515 // AI: set
516 void setAIVehicleCount(int count);
517 void setAIVehicleDistance(int dist);
518 void setAIVehiclePositionScheme(int scheme);
519 void setAIVehicleSpeed(int speed);
520 void setAIVehicleName(int x, std::string name);
521 void setAIVehicleSectionConfig(int x, std::string config);
522 void setAIVehicleSkin(int x, std::string skin);
523 void setAIRepeatTimes(int times);
524 void setAIMode(int mode);
525
527
530
535 void setCameraPosition(const Ogre::Vector3& pos);
536
541 void setCameraDirection(const Ogre::Vector3& vec);
542
547 void setCameraOrientation(const Ogre::Quaternion& q);
548
553 void setCameraRoll(float angle);
554
559 void setCameraYaw(float angle);
560
565 void setCameraPitch(float angle);
566
571 Ogre::Vector3 getCameraPosition();
572
577 Ogre::Vector3 getCameraDirection();
578
583 Ogre::Quaternion getCameraOrientation();
584
593 void cameraLookAt(const Ogre::Vector3& targetPoint);
594
596
599
600 void stopTimer();
601 void startTimer(int id);
602 void setTimeDiff(float diff);
603 void setBestLapTime(float time);
604
606
609
610 int setMaterialAmbient(const Ogre::String& materialName, float red, float green, float blue);
611 int setMaterialDiffuse(const Ogre::String& materialName, float red, float green, float blue, float alpha);
612 int setMaterialSpecular(const Ogre::String& materialName, float red, float green, float blue, float alpha);
613 int setMaterialEmissive(const Ogre::String& materialName, float red, float green, float blue);
614 int setMaterialTextureName(const Ogre::String& materialName, int techniqueNum, int passNum, int textureUnitNum, const Ogre::String& textureName);
615 int setMaterialTextureRotate(const Ogre::String& materialName, int techniqueNum, int passNum, int textureUnitNum, float rotation);
616 int setMaterialTextureScroll(const Ogre::String& materialName, int techniqueNum, int passNum, int textureUnitNum, float sx, float sy);
617 int setMaterialTextureScale(const Ogre::String& materialName, int techniqueNum, int passNum, int textureUnitNum, float u, float v);
618
620
623
624 AngelScript::CScriptArray* getAllSoundScriptTemplates();
625 SoundScriptTemplatePtr getSoundScriptTemplate(const std::string& name);
626 AngelScript::CScriptArray* getAllSoundScriptInstances();
627
632 SoundPtr createSoundFromResource(const std::string& filename, const std::string& resource_group_name);
633
634 SoundScriptInstancePtr createSoundScriptInstance(const std::string& template_name, int actor_instance_id /*= SoundScriptInstance::ACTOR_ID_UNKNOWN*/);
635
637
638private:
639
640 bool HaveSimTerrain(const char* func_name);
641 bool HavePlayerAvatar(const char* func_name);
642 bool HaveMainCamera(const char* func_name);
643 std::string CheckFileAccess(const char* func_name, const std::string& filename, const std::string& resource_group);
644 int getTextureUnitState(Ogre::TextureUnitState** tu, const Ogre::String materialName, int techniqueNum, int passNum, int textureUnitNum);
645
650 void logFormat(const char* fmt, ...);
651};
652
654
655} // namespace RoR
Central state/object manager and communications hub.
uint32_t BitMask_t
Definition BitFlags.h:7
Proxy class that can be called by script functions.
Definition GameScript.h:42
FreeBeamGfxID_t getFreeBeamGfxNextId()
Returns an unused (not reused) ID to use with MSG_SIM_ADD_FREEBEAMGFX_REQUESTED; see game....
AngelScript::CScriptArray * getRunningScripts()
Returns array<int> with active ScriptUnitIDs; check agains global var thisScript or use getScriptDeta...
Ogre::String getAIVehicleSectionConfig(int x)
bool checkResourceExists(const std::string &filename, const std::string &resource_group)
Checks if the resource file exists in the given group.
void showMessageBox(Ogre::String &title, Ogre::String &text, bool use_btn1, Ogre::String &btn1_text, bool allow_close, bool use_btn2, Ogre::String &btn2_text)
void registerForEvent(int eventValue)
registers for a new event to be received by the scripting system
int setMaterialTextureScroll(const Ogre::String &materialName, int techniqueNum, int passNum, int textureUnitNum, float sx, float sy)
int setMaterialTextureRotate(const Ogre::String &materialName, int techniqueNum, int passNum, int textureUnitNum, float rotation)
void movePerson(const Ogre::Vector3 &vec)
moves the person relative
void logFormat(const char *fmt,...)
writes a message to the games log (RoR.log)
void setAIVehicleCount(int count)
void log(const Ogre::String &msg)
writes a message to the games log (RoR.log)
void fetchUrlAsStringAsync(const std::string &url, const std::string &display_filename)
Invokes a background thread to fetch data using CURL; when finished, sends MSG_APP_SCRIPT_THREAD_STAT...
void setGravity(float value)
sets the gravity terrain wide.
float getGroundHeight(Ogre::Vector3 &v)
Gets terrain height at given coordinates.
void cameraLookAt(const Ogre::Vector3 &targetPoint)
Points the camera at a location in worldspace.
std::string CheckFileAccess(const char *func_name, const std::string &filename, const std::string &resource_group)
Extract filename and extension from the input, because OGRE allows absolute paths in resource system.
bool getCaelumAvailable()
ScriptRetCode_t getScriptVariable(const Ogre::String &varName, void *ref, int refTypeId, ScriptUnitID_t nid)
Retrieves a memory address of a global variable in any script.
AngelScript::CScriptArray * getAllTrucks()
returns an array of all currently existing actors.
AngelScript::CScriptArray * getMousePointedMovableObjects()
Returns array<Ogre::MovableObjects@> in no particular order.
void setTimeDiff(float diff)
int getChatFontSize()
OBSOLETE, returns 0;.
int sendGameCmd(const Ogre::String &message)
Multiplayer only: sends AngelScript snippet to all players.
int getLoadedTerrain(Ogre::String &result)
gets the name of current terrain.
bool getScreenPosFromWorldPos(Ogre::Vector3 const &world_pos, Ogre::Vector2 &out_screen_pos)
Ogre::String getCaelumTime()
gets the time of the day in seconds
bool HaveSimTerrain(const char *func_name)
Helper; Check if SimController instance exists, log warning if not.
Ogre::String getAIVehicleName(int x)
void setAIVehicleSpeed(int speed)
int getCurrentTruckNumber()
returns the current truck number.
void setAIVehicleSectionConfig(int x, std::string config)
AngelScript::CScriptArray * getEditorObjects()
Returns array<TerrainEditorObjectClassPtr@> with all static objects on map (from any source).
ActorPtr spawnTruck(Ogre::String &truckName, Ogre::Vector3 &pos, Ogre::Vector3 &rot)
void setCaelumTime(float value)
sets the time of the day in seconds
void activateAllVehicles()
std::string getAIVehicleSkin(int x)
void unRegisterEvent(int eventValue)
unregisters from receiving event.
AngelScript::CScriptArray * getWaypoints(int x)
void setBestLapTime(float time)
void setChatFontSize(int size)
OBSOLETE, does nothing.
int useOnlineAPI(const Ogre::String &apiquery, const AngelScript::CScriptDictionary &dict, Ogre::String &result)
Ogre::Vector3 getPersonPosition()
ActorPtr getCurrentTruck()
returns the current selected truck, 0 if in person mode
AngelScript::CScriptDictionary * getScriptDetails(ScriptUnitID_t nid)
Returns all info about running script; obtain the NID from getRunningScripts(), global var thisScript...
bool serializeMeshResource(const std::string &filename, const std::string &resource_group, const Ogre::MeshPtr &mesh)
Uses Ogre::MeshSerializer to save binary .mesh file (latest format, native endianness).
SoundPtr createSoundFromResource(const std::string &filename, const std::string &resource_group_name)
int getAIVehiclePositionScheme()
void setPersonPosition(const Ogre::Vector3 &vec)
sets the character position
ScriptRetCode_t deleteScriptVariable(const Ogre::String &arg, ScriptUnitID_t nid)
Deletes a global variable from the script (Wrapper for ScriptEngine::deleteVariable)
ScriptRetCode_t deleteScriptFunction(const Ogre::String &arg, ScriptUnitID_t nid)
Deletes a global function from the script (Wrapper for ScriptEngine::deleteFunction)
Ogre::Vector2 getMouseScreenPosition()
Gets mouse position in pixels.
void setWaterHeight(float value)
sets the base water height
Ogre::Quaternion getCameraOrientation()
Gets the camera's orientation.
int setMaterialAmbient(const Ogre::String &materialName, float red, float green, float blue)
bool getMousePositionOnTerrain(Ogre::Vector3 &out_pos)
Calculates mouse cursor position on terrain.
void setCameraOrientation(const Ogre::Quaternion &q)
Sets the camera's orientation.
void setCameraRoll(float angle)
Rolls the camera anticlockwise, around its local z axis.
float getTime()
returns the time in seconds since the game was started
int setMaterialDiffuse(const Ogre::String &materialName, float red, float green, float blue, float alpha)
AngelScript::CScriptArray * getAllSoundScriptTemplates()
Ogre::Vector3 getCameraDirection()
Gets the camera's direction.
void flashMessage(Ogre::String &txt, float time, float charHeight)
DEPRECATED: use message() shows a message to the user.
ScriptRetCode_t scriptFunctionExists(const Ogre::String &arg, ScriptUnitID_t nid)
Checks if a global function exists in the script (Wrapper for ScriptEngine::functionExists)
void setAIVehicleSkin(int x, std::string skin)
void updateDirectionArrow(Ogre::String &text, Ogre::Vector3 &vec)
set direction arrow
void setAIVehiclePositionScheme(int scheme)
ActorInstanceID_t getActorNextInstanceId()
Returns an unused (not reused) ID to use with MSG_SIM_SPAWN_ACTOR_REQUESTED; see game....
bool pushMessage(MsgType type, AngelScript::CScriptDictionary *dict)
Pushes a message to internal message queue.
Ogre::Vector2 getDisplaySize()
Gets screen size in pixels.
void moveObjectVisuals(const Ogre::String &instanceName, const Ogre::Vector3 &pos)
This moves an object to a new position.
Ogre::SceneManager * getSceneManager()
AngelScript::CScriptArray * getAllSoundScriptInstances()
TerrainPtr getTerrain()
void setCameraPosition(const Ogre::Vector3 &pos)
Sets the camera's position.
Ogre::Vector3 getCameraPosition()
Retrieves the camera's position.
bool createTextResourceFromString(const std::string &data, const std::string &filename, const std::string &resource_group, bool overwrite=false)
Saves a string as a text file resource.
FreeForceID_t getFreeForceNextId()
Returns an unused (not reused) ID to use with MSG_SIM_ADD_FREEFORCE_REQUESTED; see game....
void removeVehicle(const Ogre::String &instance, const Ogre::String &box)
int getNumTrucksByFlag(int flag)
Ogre::Image loadImageResource(const std::string &filename, const std::string &resource_group)
Loads an image in any format recognized by OGRE.
void hideDirectionArrow()
void setAIVehicleName(int x, std::string name)
VehicleAIPtr getCurrentTruckAI()
void setPersonRotation(const Ogre::Radian &rot)
sets the character rotation
float getWaterHeight()
returns the current base water level (without waves)
void showChooser(const Ogre::String &type, const Ogre::String &instance, const Ogre::String &box)
void setCameraDirection(const Ogre::Vector3 &vec)
Sets the camera's direction vector.
int getTextureUnitState(Ogre::TextureUnitState **tu, const Ogre::String materialName, int techniqueNum, int passNum, int textureUnitNum)
int setMaterialEmissive(const Ogre::String &materialName, float red, float green, float blue)
ActorPtr getTruckByNum(int num)
returns a truck by index, get max index by calling getNumTrucks
void message(Ogre::String &txt, Ogre::String &icon)
shows a message to the user over the console system
ActorPtr getTruckRemotelyReceivingCommands()
Actors with 'importcommands' flag will remotely respond to command keys when the player is close enou...
ScriptRetCode_t scriptVariableExists(const Ogre::String &arg, ScriptUnitID_t nid)
Adds a global variable to the script (Wrapper for ScriptEngine::variableExists)
void loadTerrain(const Ogre::String &terrain)
std::string loadTextResourceAsString(const std::string &filename, const std::string &resource_group)
Loads a text file resource as string.
Ogre::Radian getPersonRotation()
gets the character rotation
void setAIVehicleDistance(int dist)
ScriptRetCode_t addScriptFunction(const Ogre::String &arg, ScriptUnitID_t nid)
Adds a global function to the script (Wrapper for ScriptEngine::addFunction)
BitMask_t getRegisteredEventsMask(ScriptUnitID_t nid)
Gets event mask for a specific running script.
ScriptRetCode_t addScriptVariable(const Ogre::String &arg, ScriptUnitID_t nid)
Adds a global variable to the script (Wrapper for ScriptEngine::addVariable)
AngelScript::CScriptArray * getWaypointsSpeed()
void openUrlInDefaultBrowser(const std::string &url)
Opens URL (must start with 'http://' or 'https://') in system's default web browser.
void destroyObject(const Ogre::String &instanceName)
This destroys an object.
void startTimer(int id)
void setRegisteredEventsMask(ScriptUnitID_t nid, BitMask_t eventMask)
Overwrites event mask for a specific running script.
int setMaterialTextureName(const Ogre::String &materialName, int techniqueNum, int passNum, int textureUnitNum, const Ogre::String &textureName)
SoundScriptTemplatePtr getSoundScriptTemplate(const std::string &name)
void setCameraYaw(float angle)
Rotates the camera anticlockwise around it's local y axis.
void setAIRepeatTimes(int times)
bool HavePlayerAvatar(const char *func_name)
Helper; Check if local Character instance exists, log warning if not.
float rangeRandom(float from, float to)
void spawnObject(const Ogre::String &objectName, const Ogre::String &instanceName, const Ogre::Vector3 &pos, const Ogre::Vector3 &rot, const Ogre::String &eventhandler, bool uniquifyMaterials)
This spawns a static terrain object (.ODEF file)
bool HaveMainCamera(const char *func_name)
Helper; Check if main camera exists, log warning if not.
void boostCurrentTruck(float factor)
void repairVehicle(const Ogre::String &instance, const Ogre::String &box, bool keepPosition)
int setMaterialSpecular(const Ogre::String &materialName, float red, float green, float blue, float alpha)
SoundScriptInstancePtr createSoundScriptInstance(const std::string &template_name, int actor_instance_id)
bool deleteResource(const std::string &filename, const std::string &resource_group)
Deletes a resource from the given group.
void addWaypoint(const Ogre::Vector3 &pos)
VehicleAIPtr getTruckAIByNum(int num)
void setCameraPitch(float angle)
Pitches the camera up/down anticlockwise around it's local z axis.
float getGravity()
returns the currently set upo gravity
void setAIMode(int mode)
int setMaterialTextureScale(const Ogre::String &materialName, int techniqueNum, int passNum, int textureUnitNum, float u, float v)
ActorPtr spawnTruckAI(Ogre::String &truckName, Ogre::Vector3 &pos, Ogre::String &truckSectionConfig, std::string &truckSkin, int x)
void setTrucksForcedAwake(bool forceActive)
AngelScript::CScriptArray * findResourceFileInfo(const std::string &resource_group, const std::string &pattern, bool dirs=false)
Proxy to Ogre::ResourceGroupManager::findResourceFileInfo(), see https://ogrecave....
MsgType
Global gameplay message loop, see struct Message in GameContext.h.
Definition Application.h:76
int ActorInstanceID_t
Unique sequentially generated ID of an actor in session. Use ActorManager::GetActorById()
int FreeForceID_t
Unique sequentially generated ID of FreeForce; use ActorManager::GetFreeForceNextId().
int ScriptRetCode_t
see enum RoR::ScriptRetCode - combines AngelScript codes and RoR internal codes.
int ScriptUnitID_t
Unique sequentially generated ID of a loaded and running scriptin session. Use ScriptEngine::getScrip...
int FreeBeamGfxID_t
Index into GfxScene::m_gfx_freebeams, use RoR::FREEBEAMGFXID_INVALID as empty value.