Rigs of Rods 2023.09
Soft-body Physics Simulation
Loading...
Searching...
No Matches
GameScriptClass.h
Go to the documentation of this file.
1/*
2This source file is part of Rigs of Rods
3
4For more information, see http://www.rigsofrods.org/
5
6Rigs of Rods is free software: you can redistribute it and/or modify
7it under the terms of the GNU General Public License version 3, as
8published by the Free Software Foundation.
9
10Rigs of Rods is distributed in the hope that it will be useful,
11but WITHOUT ANY WARRANTY; without even the implied warranty of
12MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13GNU General Public License for more details.
14
15You should have received a copy of the GNU General Public License
16along with Rigs of Rods. If not, see <http://www.gnu.org/licenses/>.
17*/
18// created on 23th May 2011 by neorej16
19
20namespace Script2Game {
21
36{
37public:
38 // PLEASE maintain the same order as in GameScript.h and GameScriptAngelscript.cpp!
39
42
47 void log(string message);
48
53 double getTime();
54
61 float rangeRandom(float from, float to);
62
66 int useOnlineAPI(const string apiquery, const dictionary dict, string result);
67
72 void getFPS();
73
78 void getAvgFPS();
79
83 void backToMenu();
84
88 void quitGame();
89
94 bool pushMessage(MsgType type, dictionary@ dict);
95
101 bool checkResourceExists(const string &in filename, const string &in resource_group);
102
107 bool deleteResource(const string &in filename, const string &in resource_group);
108
115 std::string loadTextResourceAsString(const string &in filename, const string &in resource_group);
116
126 bool createTextResourceFromString(const string &in, const string &in filename, const string &in resource_group, bool overwrite=false);
127
132
136 AngelScript::CScriptArray* findResourceFileInfo(const std::string& resource_group, const std::string& pattern, bool dirs = false);
137
138
142 void openUrlInDefaultBrowser(const std::string& url);
143
147 void fetchUrlAsStringAsync(const std::string& url, const std::string& display_filename);
148
150
153
161 void flashMessage(string message, float time, float charHeight);
162
170 void message(string txt, string icon, float timeMilliseconds, bool forceVisible);
171
178
184 void setChatFontSize(int size);
185
199 void showMessageBox(string mTitle, stringmText, bool button1, stringmButton1, bool AllowClose, bool button2, stringmButton2);
200
217 void showChooser(string type, string instance, string box);
218
225 void updateDirectionArrow(string text, vector3 position);
226
232
238 bool getScreenPosFromWorldPos(const vector3&in, vector2&out);
239
243 vector2 getDisplaySize();
244
248 Ogre::Vector2 getMouseScreenPosition();
249
251
254
259 void registerForEvent(int eventValue);
260
265 void unRegisterEvent(int eventValue);
266
272
278 void setRegisteredEventsMask(ScriptUnitId_t nid, BitMask_t eventMask);
279
286 ScriptRetCode addScriptFunction(const string func, ScriptUnitId_t nid = -2);
287
294 ScriptRetCode scriptFunctionExists(const string func, ScriptUnitId_t nid = -2);
295
302 ScriptRetCode deleteScriptFunction(const string func, ScriptUnitId_t nid = -2);
303
310 ScriptRetCode addScriptVariable(const string var, ScriptUnitId_t nid = -2);
311
318 ScriptRetCode scriptVariableExists(const string var, ScriptUnitId_t nid = -2);
319
326 ScriptRetCode deleteScriptVariable(const string var, ScriptUnitId_t nid = -2);
327
335 ScriptRetCode getScriptVariable(const string&in varName, ?&ref, ScriptUnitId_t nid = -2);
336
341
345 int sendGameCmd(const string& message);
346
350 array<int> getRunningScripts();
351
360 dictionary@ getScriptDetails(int nid);
361
363
366
375 void loadTerrain(string terrain);
376
382 int getLoadedTerrain(string result);
383
388
394
400
405 void setCaelumTime(float value);
406
411 float getGravity();
412
417 void setGravity(float value);
418
424
430 float getGroundHeight(vector3 position);
431
436 void setWaterHeight(float value);
437
447 void spawnObject(const string objectName, const string instanceName, vector3 pos, vector3 rot, const string eventhandler, bool uniquifyMaterials);
448
455 void moveObjectVisuals(const string instanceName, const vector3 pos);
456
462 void destroyObject(const string instanceName);
463
467 array<TerrainEditorObjectClassPtr@>@ getEditorObjects();
468
469
475 bool getMousePositionOnTerrain(vector3 &out);
476
480 array<Ogre::MovableObjects@> getMousePointedMovableObjects();
481
483
486
492
497 void setPersonPosition(vector3 vec);
498
503 void movePerson(vector3 relative_movement);
504
505 void setPersonRotation(radian &in);
506
508
510
513
515
516 void setTrucksForcedAwake(bool forceActive);
517
522 void boostCurrentTruck(float factor);
523
530
537 BeamClass@ getTruckByNum(int truck_number);
538
542 array<BeamClass@> getAllTrucks();
543
548
557 BeamClass @spawnTruck(stringtruckName, vector3 pos, vector3 rot);
558
562 void repairVehicle(string instance, string box, bool keepPosition);
563
567 void removeVehicle(string instance, string box);
568
572 int getNumTrucksByFlag(int flag);
573
578
584
586
589
593 FreeForceID_t getFreeForceNextId();
594
598 FreeBeamGfxID_t getFreeBeamGfxNextId();
599
601
605
606 BeamClass@ spawnTruckAI(string truckName, vector3 pos, string truckSectionConfig, string truckSkin, int x);
607 array<vector3>@ getWaypoints(int x);
608 void addWaypoint(vector3 pos);
613 Ogre::String getAIVehicleName(int x);
614 Ogre::String getAIVehicleSectionConfig(int x);
615 std::string getAIVehicleSkin(int x);
620
621 // AI: set
622 void setAIVehicleCount(int count);
623 void setAIVehicleDistance(int dist);
625 void setAIVehicleSpeed(int speed);
626 void setAIVehicleName(int x, string name);
627 void setAIVehicleSectionConfig(int x, string config);
628 void setAIVehicleSkin(int x, string skin);
629 void setAIRepeatTimes(int times);
630 void setAIMode(int mode);
631
633
636
641 void setCameraPosition(vector3 position);
642
647 void setCameraDirection(vector3 direction);
648
653 void setCameraRoll(float angle);
654
659 void setCameraYaw(float angle);
660
665 void setCameraPitch(float angle);
666
672
678
687 void cameraLookAt(vector3 targetPoint);
688
690
693
699 float stopTimer();
700
706
708
711
712 int setMaterialAmbient(const string materialName, float red, float green, float blue);
713 int setMaterialDiffuse(const string materialName, float red, float green, float blue, float alpha);
714 int setMaterialSpecular(const string materialName, float red, float green, float blue, float alpha);
715 int setMaterialEmissive(const string materialName, float red, float green, float blue);
716
717 int setMaterialTextureName(const string materialName, int techniqueNum, int passNum, int textureUnitNum, const string textureName);
718 int setMaterialTextureRotate(const string materialName, int techniqueNum, int passNum, int textureUnitNum, float rotation);
719 int setMaterialTextureScroll(const string materialName, int techniqueNum, int passNum, int textureUnitNum, float sx, float sy);
720 int setMaterialTextureScale(const string materialName, int techniqueNum, int passNum, int textureUnitNum, float u, float v);
721
723
726
727 array<SoundScriptTemplateClass> getAllSoundScriptTemplates();
728
733
737 array<SoundScriptInstanceClass> getAllSoundScriptInstances();
738
743 SoundClass createSoundFromResource(const string &in filename, const string &in resource_group_name = string());
744
750 SoundScriptInstanceClass createSoundScriptInstance(const string &in template_name, int actor_instance_id = -1);
751
753};
754
757
758} //namespace Script2Game
uint32_t BitMask_t
Definition BitFlags.h:7
Encapsulates everything renderable by OGRE - use game.getSceneManager() to get it.
Binding of RoR::Actor; a softbody-physics gameplay object, can be anything from soda can to space shu...
Definition BeamClass.h:16
Binding of RoR::GameScript; A general class that will provide you with general functions.
void setAIVehicleName(int x, string name)
bool createTextResourceFromString(const string &in, const string &in filename, const string &in resource_group, bool overwrite=false)
Saves a string as a text file resource.
void movePerson(vector3 relative_movement)
moves the person relative
void setAIVehicleDistance(int dist)
AngelOgre::SceneManager getSceneManager()
Retrieves the OGRE scene manager object.
void hideDirectionArrow()
Hides the direction arrow.
void setGravity(float value)
sets the gravity terrain wide.
array< Ogre::MovableObjects@> getMousePointedMovableObjects()
Returns array<Ogre::MovableObjects@> in no particular order; works using bounding boxes so large/gene...
SoundScriptInstanceClass createSoundScriptInstance(const string &in template_name, int actor_instance_id=-1)
FreeBeamGfxID_t getFreeBeamGfxNextId()
Returns an unused (not reused) ID to use with MSG_SIM_ADD_FREEBEAMGFX_REQUESTED; see game....
ScriptRetCode scriptFunctionExists(const string func, ScriptUnitId_t nid=-2)
Checks if a global function exists.
array< int > getRunningScripts()
Returns active ScriptUnitIDs; check agains global var thisScript or use getScriptDetails() to get nam...
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 setCameraRoll(float angle)
Rolls the camera anticlockwise, around its local z axis.
int setMaterialTextureScroll(const string materialName, int techniqueNum, int passNum, int textureUnitNum, float sx, float sy)
void loadTerrain(string terrain)
Loads a terrain.
float rangeRandom(float from, float to)
Generates a random number between from and to.
void cameraLookAt(vector3 targetPoint)
Points the camera at a location in worldspace.
void setAIVehiclePositionScheme(int scheme)
int getNumTrucksByFlag(int flag)
Number of trucks with flag.
ScriptRetCode addScriptFunction(const string func, ScriptUnitId_t nid=-2)
Adds a global function to the script.
dictionary getScriptDetails(int nid)
Returns all info about running script; obtain the NID from getRunningScripts(), global var thisScript...
VehicleAIClass getTruckAIByNum(int num)
int setMaterialTextureRotate(const string materialName, int techniqueNum, int passNum, int textureUnitNum, float rotation)
SoundScriptTemplateClass getSoundScriptTemplate(const string &in name)
Retrieves one sound script template by name.
int setMaterialTextureName(const string materialName, int techniqueNum, int passNum, int textureUnitNum, const string textureName)
int getCurrentTruckNumber()
returns the instance ID of current player vehicle, or -1 when in person mode
array< SoundScriptInstanceClass > getAllSoundScriptInstances()
Diagnostic function, returns all existing sound script instances.
void getAvgFPS()
Gets the average frames per second (FPS)
vector3 getCameraDirection()
Gets the camera's direction.
void openUrlInDefaultBrowser(const std::string &url)
Opens URL (must start with 'http://' or 'https://') in system's default web browser.
int setMaterialSpecular(const string materialName, float red, float green, float blue, float alpha)
void setCameraYaw(float angle)
Rotates the camera anticlockwise around it's local y axis.
BitMask_t getRegisteredEventsMask(ScriptUnitId_t nid)
Gets event mask for a specific running script.
int setMaterialEmissive(const string materialName, float red, float green, float blue)
void setCameraPosition(vector3 position)
Sets the camera's position.
ScriptRetCode deleteScriptVariable(const string var, ScriptUnitId_t nid=-2)
Removes a global variable from the script.
bool checkResourceExists(const string &in filename, const string &in resource_group)
Checks if the resource file exists in the given group.
void setRegisteredEventsMask(ScriptUnitId_t nid, BitMask_t eventMask)
Overwrites event mask for a specific running script.
bool deleteResource(const string &in filename, const string &in resource_group)
Deletes a resource from the given group.
AngelScript::CScriptArray * findResourceFileInfo(const std::string &resource_group, const std::string &pattern, bool dirs=false)
Proxy to Ogre::ResourceGroupManager::findResourceFileInfo(), see https://ogrecave....
array< SoundScriptTemplateClass > getAllSoundScriptTemplates()
bool pushMessage(MsgType type, dictionary@ dict)
Pushes a message to internal message queue.
float getWaterHeight()
returns the current base water level (without waves)
void setWaterHeight(float value)
sets the base water height
void setAIVehicleSpeed(int speed)
TerrainClass getTerrain()
Gets the currently loaded terrain instance.
void quitGame()
Quits the game.
ScriptRetCode deleteScriptFunction(const string func, ScriptUnitId_t nid=-2)
Removes a global function from the script.
void setAIVehicleSkin(int x, string skin)
void registerForEvent(int eventValue)
registers for a new event to be received by the scripting system
int setMaterialTextureScale(const string materialName, int techniqueNum, int passNum, int textureUnitNum, float u, float v)
float getGravity()
returns the currently set upo gravity
float stopTimer()
Stops the timer.
void setPersonRotation(radian &in)
vector2 getDisplaySize()
Gets screen size in pixels.
int getChatFontSize()
OBSOLETE - returns 0.
float getGroundHeight(vector3 position)
returns the ground height for a position
void spawnObject(const string objectName, const string instanceName, vector3 pos, vector3 rot, const string eventhandler, bool uniquifyMaterials)
This spawns an object.
VehicleAIClass getCurrentTruckAI()
Ogre::String getAIVehicleSectionConfig(int x)
string getCaelumTime()
gets the time of the day in seconds
double getTime()
returns the time in seconds since the game was started
int useOnlineAPI(const string apiquery, const dictionary dict, string result)
Sends or request information from the master server.
BeamClass getTruckRemotelyReceivingCommands()
Actors with 'importcommands' flag will remotely respond to command keys when the player is close enou...
void getFPS()
Gets the Curent frames per second (FPS)
void setCameraPitch(float angle)
Pitches the camera up/down anticlockwise around it's local z axis.
ScriptRetCode addScriptVariable(const string var, ScriptUnitId_t nid=-2)
Adds a global variable to the script.
void updateDirectionArrow(string text, vector3 position)
set direction arrow
void setAIVehicleSectionConfig(int x, string config)
std::string getAIVehicleSkin(int x)
vector3 getCameraPosition()
Retrieves the camera's position.
int setMaterialAmbient(const string materialName, float red, float green, float blue)
void destroyObject(const string instanceName)
This destroys an object.
void boostCurrentTruck(float factor)
Gives the currently used truck a boost in RPM.
Ogre::Vector2 getMouseScreenPosition()
Gets mouse position in pixels.
void setCaelumTime(float value)
sets the time of the day in seconds
array< BeamClass@> getAllTrucks()
returns an array of all currently existing actors.
void setAIVehicleCount(int count)
SoundClass createSoundFromResource(const string &in filename, const string &in resource_group_name=string())
void showChooser(string type, string instance, string box)
This shows a vehicle chooser.
void log(string message)
writes a message to the scripting logbook (AngelScript.log)
int sendGameCmd(const string &message)
Multiplayer only: sends AngelScript snippet to all players.
int setMaterialDiffuse(const string materialName, float red, float green, float blue, float alpha)
bool getMousePositionOnTerrain(vector3 &out)
Calculates mouse cursor position on terrain.
void backToMenu()
Back to menu.
void unRegisterEvent(int eventValue)
unregisters from receiving event.
int getLoadedTerrain(string result)
Gets the currently loaded terrain name.
vector3 getPersonPosition()
Returns the current position of the person.
void setTrucksForcedAwake(bool forceActive)
ScriptRetCode scriptVariableExists(const string var, ScriptUnitId_t nid=-2)
Checks if a global variable exists in the script.
void message(string txt, string icon, float timeMilliseconds, bool forceVisible)
shows a message to the user
void showMessageBox(string mTitle, stringmText, bool button1, stringmButton1, bool AllowClose, bool button2, stringmButton2)
Shows a message box.
Ogre::String getAIVehicleName(int x)
void setChatFontSize(int size)
OBSOLETE - does nothing.
void repairVehicle(string instance, string box, bool keepPosition)
This method repairs the vehicle in the box.
bool getScreenPosFromWorldPos(const vector3 &in, vector2 &out)
ScriptRetCode getScriptVariable(const string &in varName, ?&ref, ScriptUnitId_t nid=-2)
Retrieves a memory address of a global variable in any script.
void flashMessage(string message, float time, float charHeight)
shows a message to the user
array< TerrainEditorObjectClassPtr@> getEditorObjects()
Returns all static objects on map (from any source).
array< vector3 > getWaypoints(int x)
void clearEventCache()
Clears the event cache.
FreeForceID_t getFreeForceNextId()
Returns an unused (not reused) ID to use with MSG_SIM_ADD_FREEFORCE_REQUESTED; see game....
bool getCaelumAvailable()
Checks if Caleum is enabled.
void moveObjectVisuals(const string instanceName, const vector3 pos)
This moves an object to a new position.
int getActorNextInstanceId()
Returns an unused (not reused) ID to use with MSG_SIM_SPAWN_ACTOR_REQUESTED; see game....
BeamClass getCurrentTruck()
returns the current selected truck, null if in person mode
BeamClass spawnTruck(stringtruckName, vector3 pos, vector3 rot)
Spawns a truck by filename.
void startTimer()
Starts a timer (useful for races etc)
BeamClass getTruckByNum(int truck_number)
Get an actor by Instance ID, get one from eventCallbackEx() or manually by BeamClass::getInstanceId()...
BeamClass spawnTruckAI(string truckName, vector3 pos, string truckSectionConfig, string truckSkin, int x)
void addWaypoint(vector3 pos)
void setAIRepeatTimes(int times)
void setPersonPosition(vector3 vec)
sets the character position
void removeVehicle(string instance, string box)
This method removes the vehicle in the box.
void setCameraDirection(vector3 direction)
Sets the camera's direction vector.
std::string loadTextResourceAsString(const string &in filename, const string &in resource_group)
Loads a text file resource as string.
Binding of RoR::Sound; a single sound sample positioned in 3D space (spatial audio).
Definition SoundClass.h:18
Binding of RoR::SoundScriptInstance; instance of SoundScriptTemplateClass.
Binding of RoR::SoundScriptTemplate; a customizable sound effect.
Binding of RoR::Terrain; represents a loaded terrain.
Binding of RoR::VehicleAI; Vehicle driving AI using waypoints.
Pseudo-namespace; it doesn't exist in code or script runtime, only in this documentation.
ScriptRetCode
Binding of RoR::ScriptRetCode; Common return codes for script manipulation funcs (add/get/delete | fu...
MsgType
Binding of RoR::MsgType; Global gameplay message loop; used with `game.pushMessage()`.
Definition MsgType.h:20