RigsofRods
Soft-body Physics Simulation
GameScriptClass.h
Go to the documentation of this file.
1 /*
2 This source file is part of Rigs of Rods
3 
4 For more information, see http://www.rigsofrods.org/
5 
6 Rigs of Rods is free software: you can redistribute it and/or modify
7 it under the terms of the GNU General Public License version 3, as
8 published by the Free Software Foundation.
9 
10 Rigs of Rods is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
14 
15 You should have received a copy of the GNU General Public License
16 along with Rigs of Rods. If not, see <http://www.gnu.org/licenses/>.
17 */
18 // created on 23th May 2011 by neorej16
19 
20 namespace Script2Game {
21 
36 {
37 public:
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  void openUrlInDefaultBrowser(const std::string& url);
137 
141  void fetchUrlAsStringAsync(const std::string& url, const std::string& display_filename);
142 
144 
147 
155  void flashMessage(string message, float time, float charHeight);
156 
164  void message(string txt, string icon, float timeMilliseconds, bool forceVisible);
165 
171  int getChatFontSize();
172 
178  void setChatFontSize(int size);
179 
193  void showMessageBox(string mTitle, stringmText, bool button1, stringmButton1, bool AllowClose, bool button2, stringmButton2);
194 
211  void showChooser(string type, string instance, string box);
212 
219  void updateDirectionArrow(string text, vector3 position);
220 
225  void hideDirectionArrow();
226 
232  bool getScreenPosFromWorldPos(const vector3&in, vector2&out);
233 
237  vector2 getDisplaySize();
238 
240 
243 
248  void registerForEvent(int eventValue);
249 
254  void unRegisterEvent(int eventValue);
255 
261 
267  void setRegisteredEventsMask(ScriptUnitId_t nid, BitMask_t eventMask);
268 
273  int addScriptFunction(const string func);
274 
279  int scriptFunctionExists(const string func);
280 
285  int deleteScriptFunction(const string func);
286 
291  int addScriptVariable(const string var);
292 
297  int deleteScriptVariable(const string var);
298 
302  void clearEventCache();
303 
307  int sendGameCmd(const string& message);
308 
312  array<int> getRunningScripts();
313 
322  dictionary@ getScriptDetails(int nid);
323 
325 
328 
337  void loadTerrain(string terrain);
338 
344  int getLoadedTerrain(string result);
345 
350 
355  bool getCaelumAvailable();
356 
361  string getCaelumTime();
362 
367  void setCaelumTime(float value);
368 
373  float getGravity();
374 
379  void setGravity(float value);
380 
385  float getWaterHeight();
386 
392  float getGroundHeight(vector3 position);
393 
398  void setWaterHeight(float value);
399 
409  void spawnObject(const string objectName, const string instanceName, vector3 pos, vector3 rot, const string eventhandler, bool uniquifyMaterials);
410 
417  void moveObjectVisuals(const string instanceName, const vector3 pos);
418 
424  void destroyObject(const string instanceName);
425 
431  bool getMousePositionOnTerrain(vector3 &out);
432 
434 
437 
442  vector3 getPersonPosition();
443 
448  void setPersonPosition(vector3 vec);
449 
454  void movePerson(vector3 relative_movement);
455 
456  void setPersonRotation(radian &in);
457 
458  radian getPersonRotation();
459 
461 
464 
465  void activateAllVehicles();
466 
467  void setTrucksForcedAwake(bool forceActive);
468 
473  void boostCurrentTruck(float factor);
474 
481 
488  BeamClass@ getTruckByNum(int truck_number);
489 
493  array<BeamClass@> getAllTrucks();
494 
498  int getCurrentTruckNumber();
499 
508  BeamClass @spawnTruck(stringtruckName, vector3 pos, vector3 rot);
509 
513  void repairVehicle(string instance, string box, bool keepPosition);
514 
518  void removeVehicle(string instance, string box);
519 
523  int getNumTrucksByFlag(int flag);
524 
526 
530 
531  BeamClass@ spawnTruckAI(string truckName, vector3 pos, string truckSectionConfig, string truckSkin, int x);
532  array<vector3>@ getWaypoints(int x);
533  void addWaypoint(vector3 pos);
534  int getAIVehicleCount();
535  int getAIVehicleDistance();
537  int getAIVehicleSpeed();
538  Ogre::String getAIVehicleName(int x);
539  Ogre::String getAIVehicleSectionConfig(int x);
540  std::string getAIVehicleSkin(int x);
541  int getAIRepeatTimes();
542  int getAIMode();
545 
546  // AI: set
547  void setAIVehicleCount(int count);
548  void setAIVehicleDistance(int dist);
549  void setAIVehiclePositionScheme(int scheme);
550  void setAIVehicleSpeed(int speed);
551  void setAIVehicleName(int x, string name);
552  void setAIVehicleSectionConfig(int x, string config);
553  void setAIVehicleSkin(int x, string skin);
554  void setAIRepeatTimes(int times);
555  void setAIMode(int mode);
556 
558 
561 
566  void setCameraPosition(vector3 position);
567 
572  void setCameraDirection(vector3 direction);
573 
578  void setCameraRoll(float angle);
579 
584  void setCameraYaw(float angle);
585 
590  void setCameraPitch(float angle);
591 
596  vector3 getCameraPosition();
597 
602  vector3 getCameraDirection();
603 
612  void cameraLookAt(vector3 targetPoint);
613 
615 
618 
624  float stopTimer();
625 
630  void startTimer();
631 
633 
636 
637  int setMaterialAmbient(const string materialName, float red, float green, float blue);
638  int setMaterialDiffuse(const string materialName, float red, float green, float blue, float alpha);
639  int setMaterialSpecular(const string materialName, float red, float green, float blue, float alpha);
640  int setMaterialEmissive(const string materialName, float red, float green, float blue);
641 
642  int setMaterialTextureName(const string materialName, int techniqueNum, int passNum, int textureUnitNum, const string textureName);
643  int setMaterialTextureRotate(const string materialName, int techniqueNum, int passNum, int textureUnitNum, float rotation);
644  int setMaterialTextureScroll(const string materialName, int techniqueNum, int passNum, int textureUnitNum, float sx, float sy);
645  int setMaterialTextureScale(const string materialName, int techniqueNum, int passNum, int textureUnitNum, float u, float v);
646 
648 
651 
652  array<SoundScriptTemplateClass> getAllSoundScriptTemplates();
653 
657  SoundScriptTemplateClass getSoundScriptTemplate(const string &in name);
658 
662  array<SoundScriptInstanceClass> getAllSoundScriptInstances();
663 
668  SoundClass createSoundFromResource(const string &in filename, const string &in resource_group_name = string());
669 
675  SoundScriptInstanceClass createSoundScriptInstance(const string &in template_name, int actor_instance_id = -1);
676 
678 };
679 
682 
683 } //namespace Script2Game
Script2Game::GameScriptClass::getCameraDirection
vector3 getCameraDirection()
Gets the camera's direction.
Script2Game::GameScriptClass::getAIMode
int getAIMode()
Script2Game::GameScriptClass::clearEventCache
void clearEventCache()
Clears the event cache.
Script2Game::GameScriptClass::getWaypoints
array< vector3 > getWaypoints(int x)
Script2Game::GameScriptClass::activateAllVehicles
void activateAllVehicles()
Script2Game::GameScriptClass::loadTerrain
void loadTerrain(string terrain)
Loads a terrain.
Script2Game::GameScriptClass::setMaterialSpecular
int setMaterialSpecular(const string materialName, float red, float green, float blue, float alpha)
Script2Game::SoundClass
Binding of RoR::Sound; a single sound sample positioned in 3D space (spatial audio).
Definition: SoundClass.h:17
Script2Game::GameScriptClass::setCameraDirection
void setCameraDirection(vector3 direction)
Sets the camera's direction vector.
Script2Game::GameScriptClass::getPersonRotation
radian getPersonRotation()
Script2Game::GameScriptClass::quitGame
void quitGame()
Quits the game.
Script2Game::GameScriptClass::addWaypoint
void addWaypoint(vector3 pos)
Script2Game::GameScriptClass::getTruckByNum
BeamClass getTruckByNum(int truck_number)
Get an actor by Instance ID, get one from eventCallbackEx() or manually by BeamClass::getInstanceId()...
Script2Game::GameScriptClass::getCurrentTruckAI
VehicleAIClass getCurrentTruckAI()
Script2Game::GameScriptClass::stopTimer
float stopTimer()
Stops the timer.
Script2Game::GameScriptClass::moveObjectVisuals
void moveObjectVisuals(const string instanceName, const vector3 pos)
This moves an object to a new position.
Script2Game::GameScriptClass::rangeRandom
float rangeRandom(float from, float to)
Generates a random number between from and to.
Script2Game::GameScriptClass::setChatFontSize
void setChatFontSize(int size)
OBSOLETE - does nothing.
Script2Game::GameScriptClass::pushMessage
bool pushMessage(MsgType type, dictionary@ dict)
Pushes a message to internal message queue.
Script2Game::TerrainClass
Binding of RoR::Terrain; represents a loaded terrain.
Definition: TerrainClass.h:16
Script2Game::BeamClass
Binding of RoR::Actor; a softbody-physics gameplay object, can be anything from soda can to space shu...
Definition: BeamClass.h:15
Script2Game::GameScriptClass::getMousePositionOnTerrain
bool getMousePositionOnTerrain(vector3 &out)
Calculates mouse cursor position on terrain.
Script2Game::GameScriptClass::setCameraPitch
void setCameraPitch(float angle)
Pitches the camera up/down anticlockwise around it's local z axis.
Script2Game::GameScriptClass::updateDirectionArrow
void updateDirectionArrow(string text, vector3 position)
set direction arrow
Script2Game::GameScriptClass::startTimer
void startTimer()
Starts a timer (useful for races etc)
Script2Game::GameScriptClass::removeVehicle
void removeVehicle(string instance, string box)
This method removes the vehicle in the box.
Script2Game::GameScriptClass::openUrlInDefaultBrowser
void openUrlInDefaultBrowser(const std::string &url)
Opens URL (must start with 'http://' or 'https://') in system's default web browser.
Script2Game::GameScriptClass::setCameraPosition
void setCameraPosition(vector3 position)
Sets the camera's position.
Script2Game::GameScriptClass::setGravity
void setGravity(float value)
sets the gravity terrain wide.
Script2Game::GameScriptClass::deleteResource
bool deleteResource(const string &in filename, const string &in resource_group)
Deletes a resource from the given group.
Script2Game::GameScriptClass::setAIVehicleName
void setAIVehicleName(int x, string name)
Script2Game::GameScriptClass::getAIVehiclePositionScheme
int getAIVehiclePositionScheme()
Script2Game::GameScriptClass::getAIVehicleDistance
int getAIVehicleDistance()
Script2Game::VehicleAIClass
Binding of RoR::VehicleAI; Vehicle driving AI using waypoints.
Definition: VehicleAIClass.h:63
Script2Game::GameScriptClass::addScriptFunction
int addScriptFunction(const string func)
Adds a global function to the script.
Script2Game::GameScriptClass::fetchUrlAsStringAsync
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...
Script2Game::GameScriptClass::showMessageBox
void showMessageBox(string mTitle, stringmText, bool button1, stringmButton1, bool AllowClose, bool button2, stringmButton2)
Shows a message box.
Script2Game::GameScriptClass::setAIMode
void setAIMode(int mode)
Script2Game
Pseudo-namespace; it doesn't exist in code or script runtime, only in this documentation.
Definition: BeamClass.h:2
Script2Game::GameScriptClass::setAIVehicleDistance
void setAIVehicleDistance(int dist)
Script2Game::GameScriptClass::getTime
double getTime()
returns the time in seconds since the game was started
Script2Game::GameScriptClass::backToMenu
void backToMenu()
Back to menu.
Script2Game::GameScriptClass::checkResourceExists
bool checkResourceExists(const string &in filename, const string &in resource_group)
Checks if the resource file exists in the given group.
Script2Game::GameScriptClass::getAIVehicleSectionConfig
Ogre::String getAIVehicleSectionConfig(int x)
Script2Game::GameScriptClass::setAIVehicleSkin
void setAIVehicleSkin(int x, string skin)
Script2Game::GameScriptClass::spawnObject
void spawnObject(const string objectName, const string instanceName, vector3 pos, vector3 rot, const string eventhandler, bool uniquifyMaterials)
This spawns an object.
Script2Game::GameScriptClass::getCurrentTruckNumber
int getCurrentTruckNumber()
returns the instance ID of current player vehicle, or -1 when in person mode
Script2Game::GameScriptClass::getChatFontSize
int getChatFontSize()
OBSOLETE - returns 0.
Script2Game::GameScriptClass::getWaterHeight
float getWaterHeight()
returns the current base water level (without waves)
Script2Game::GameScriptClass::getLoadedTerrain
int getLoadedTerrain(string result)
Gets the currently loaded terrain name.
Script2Game::GameScriptClass::showChooser
void showChooser(string type, string instance, string box)
This shows a vehicle chooser.
Script2Game::GameScriptClass
Binding of RoR::GameScript; A general class that will provide you with general functions.
Definition: GameScriptClass.h:35
Script2Game::GameScriptClass::deleteScriptVariable
int deleteScriptVariable(const string var)
Removes a global variable from the script.
Script2Game::GameScriptClass::setPersonPosition
void setPersonPosition(vector3 vec)
sets the character position
Script2Game::GameScriptClass::useOnlineAPI
int useOnlineAPI(const string apiquery, const dictionary dict, string result)
Sends or request information from the master server.
Script2Game::GameScriptClass::setAIRepeatTimes
void setAIRepeatTimes(int times)
Script2Game::GameScriptClass::scriptFunctionExists
int scriptFunctionExists(const string func)
Checks if a global function exists.
Script2Game::GameScriptClass::getAllSoundScriptTemplates
array< SoundScriptTemplateClass > getAllSoundScriptTemplates()
Script2Game::GameScriptClass::setWaterHeight
void setWaterHeight(float value)
sets the base water height
Script2Game::GameScriptClass::setMaterialTextureRotate
int setMaterialTextureRotate(const string materialName, int techniqueNum, int passNum, int textureUnitNum, float rotation)
Script2Game::GameScriptClass::getAIRepeatTimes
int getAIRepeatTimes()
Script2Game::GameScriptClass::setRegisteredEventsMask
void setRegisteredEventsMask(ScriptUnitId_t nid, BitMask_t eventMask)
Overwrites event mask for a specific running script.
Script2Game::GameScriptClass::setMaterialDiffuse
int setMaterialDiffuse(const string materialName, float red, float green, float blue, float alpha)
RoR::ScriptUnitId_t
int ScriptUnitId_t
Unique sequentially generated ID of a loaded and running scriptin session. Use ScriptEngine::getScrip...
Definition: ForwardDeclarations.h:40
Script2Game::GameScriptClass::getNumTrucksByFlag
int getNumTrucksByFlag(int flag)
Number of trucks with flag.
Script2Game::GameScriptClass::getScriptDetails
dictionary getScriptDetails(int nid)
Returns all info about running script; obtain the NID from getRunningScripts(), global var thisScript...
Script2Game::GameScriptClass::setPersonRotation
void setPersonRotation(radian &in)
Script2Game::GameScriptClass::getSoundScriptTemplate
SoundScriptTemplateClass getSoundScriptTemplate(const string &in name)
Retrieves one sound script template by name.
Script2Game::GameScriptClass::getDisplaySize
vector2 getDisplaySize()
Gets screen size in pixels.
Script2Game::GameScriptClass::sendGameCmd
int sendGameCmd(const string &message)
Multiplayer only: sends AngelScript snippet to all players.
Script2Game::GameScriptClass::setTrucksForcedAwake
void setTrucksForcedAwake(bool forceActive)
Script2Game::GameScriptClass::flashMessage
void flashMessage(string message, float time, float charHeight)
shows a message to the user
Script2Game::GameScriptClass::createSoundScriptInstance
SoundScriptInstanceClass createSoundScriptInstance(const string &in template_name, int actor_instance_id=-1)
Script2Game::GameScriptClass::getRunningScripts
array< int > getRunningScripts()
Returns active ScriptUnitIDs; check agains global var thisScript or use getScriptDetails() to get nam...
Script2Game::GameScriptClass::getCaelumAvailable
bool getCaelumAvailable()
Checks if Caleum is enabled.
Script2Game::GameScriptClass::getScreenPosFromWorldPos
bool getScreenPosFromWorldPos(const vector3 &in, vector2 &out)
Script2Game::GameScriptClass::getRegisteredEventsMask
BitMask_t getRegisteredEventsMask(ScriptUnitId_t nid)
Gets event mask for a specific running script.
Script2Game::SoundScriptTemplateClass
Binding of RoR::SoundScriptTemplate; a customizable sound effect.
Definition: SoundScriptTemplateClass.h:16
Script2Game::GameScriptClass::destroyObject
void destroyObject(const string instanceName)
This destroys an object.
Script2Game::GameScriptClass::getAvgFPS
void getAvgFPS()
Gets the average frames per second (FPS)
Script2Game::SoundScriptInstanceClass
Binding of RoR::SoundScriptInstance; instance of SoundScriptTemplateClass.
Definition: SoundScriptInstanceClass.h:17
Script2Game::GameScriptClass::setAIVehicleSpeed
void setAIVehicleSpeed(int speed)
Script2Game::GameScriptClass::createTextResourceFromString
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.
Script2Game::GameScriptClass::setMaterialEmissive
int setMaterialEmissive(const string materialName, float red, float green, float blue)
Script2Game::GameScriptClass::hideDirectionArrow
void hideDirectionArrow()
Hides the direction arrow.
Script2Game::GameScriptClass::getCameraPosition
vector3 getCameraPosition()
Retrieves the camera's position.
Script2Game::GameScriptClass::setMaterialTextureScroll
int setMaterialTextureScroll(const string materialName, int techniqueNum, int passNum, int textureUnitNum, float sx, float sy)
Script2Game::GameScriptClass::getAIVehicleSpeed
int getAIVehicleSpeed()
instance
or anywhere else will not be considered a but parsed as regular data ! Each line is treated as values separated by separators Possible i e animators Multiline description Single instance
Definition: ReadMe.txt:53
Script2Game::GameScriptClass::repairVehicle
void repairVehicle(string instance, string box, bool keepPosition)
This method repairs the vehicle in the box.
Script2Game::GameScriptClass::getCaelumTime
string getCaelumTime()
gets the time of the day in seconds
Script2Game::GameScriptClass::getGroundHeight
float getGroundHeight(vector3 position)
returns the ground height for a position
Script2Game::GameScriptClass::getAllTrucks
array< BeamClass@> getAllTrucks()
returns an array of all currently existing actors.
Script2Game::GameScriptClass::setMaterialAmbient
int setMaterialAmbient(const string materialName, float red, float green, float blue)
Script2Game::GameScriptClass::spawnTruck
BeamClass spawnTruck(stringtruckName, vector3 pos, vector3 rot)
Spawns a truck by filename.
Script2Game::GameScriptClass::getGravity
float getGravity()
returns the currently set upo gravity
Script2Game::GameScriptClass::spawnTruckAI
BeamClass spawnTruckAI(string truckName, vector3 pos, string truckSectionConfig, string truckSkin, int x)
Script2Game::GameScriptClass::getAIVehicleSkin
std::string getAIVehicleSkin(int x)
Script2Game::GameScriptClass::deleteScriptFunction
int deleteScriptFunction(const string func)
Removes a global function from the script.
Script2Game::GameScriptClass::setCaelumTime
void setCaelumTime(float value)
sets the time of the day in seconds
Script2Game::GameScriptClass::getTruckAIByNum
VehicleAIClass getTruckAIByNum(int num)
Script2Game::GameScriptClass::setAIVehicleCount
void setAIVehicleCount(int count)
Script2Game::GameScriptClass::createSoundFromResource
SoundClass createSoundFromResource(const string &in filename, const string &in resource_group_name=string())
Script2Game::GameScriptClass::loadTextResourceAsString
std::string loadTextResourceAsString(const string &in filename, const string &in resource_group)
Loads a text file resource as string.
Script2Game::GameScriptClass::setAIVehiclePositionScheme
void setAIVehiclePositionScheme(int scheme)
BitMask_t
uint32_t BitMask_t
Definition: BitFlags.h:7
Script2Game::GameScriptClass::movePerson
void movePerson(vector3 relative_movement)
moves the person relative
Script2Game::GameScriptClass::getFPS
void getFPS()
Gets the Curent frames per second (FPS)
Script2Game::GameScriptClass::setCameraYaw
void setCameraYaw(float angle)
Rotates the camera anticlockwise around it's local y axis.
Script2Game::GameScriptClass::getAIVehicleCount
int getAIVehicleCount()
Script2Game::GameScriptClass::getAIVehicleName
Ogre::String getAIVehicleName(int x)
Script2Game::GameScriptClass::setMaterialTextureScale
int setMaterialTextureScale(const string materialName, int techniqueNum, int passNum, int textureUnitNum, float u, float v)
Script2Game::GameScriptClass::setCameraRoll
void setCameraRoll(float angle)
Rolls the camera anticlockwise, around its local z axis.
Script2Game::GameScriptClass::message
void message(string txt, string icon, float timeMilliseconds, bool forceVisible)
shows a message to the user
Script2Game::GameScriptClass::registerForEvent
void registerForEvent(int eventValue)
registers for a new event to be received by the scripting system
Script2Game::GameScriptClass::getSceneManager
AngelOgre::SceneManager getSceneManager()
Retrieves the OGRE scene manager object.
Script2Game::GameScriptClass::getAllSoundScriptInstances
array< SoundScriptInstanceClass > getAllSoundScriptInstances()
Diagnostic function, returns all existing sound script instances.
AngelOgre::SceneManager
Encapsulates everything renderable by OGRE - use game.getSceneManager() to get it.
Definition: AngelOgre_SceneManager.h:14
Script2Game::GameScriptClass::getPersonPosition
vector3 getPersonPosition()
Returns the current position of the person.
Script2Game::GameScriptClass::boostCurrentTruck
void boostCurrentTruck(float factor)
Gives the currently used truck a boost in RPM.
Script2Game::GameScriptClass::log
void log(string message)
writes a message to the scripting logbook (AngelScript.log)
Script2Game::GameScriptClass::setMaterialTextureName
int setMaterialTextureName(const string materialName, int techniqueNum, int passNum, int textureUnitNum, const string textureName)
Script2Game::GameScriptClass::cameraLookAt
void cameraLookAt(vector3 targetPoint)
Points the camera at a location in worldspace.
x
float x
Definition: (ValueTypes) quaternion.h:5
Script2Game::MsgType
MsgType
Binding of RoR::MsgType; Global gameplay message loop.
Definition: globals.h:602
Script2Game::GameScriptClass::setAIVehicleSectionConfig
void setAIVehicleSectionConfig(int x, string config)
Script2Game::GameScriptClass::addScriptVariable
int addScriptVariable(const string var)
Adds a global variable to the script.
Script2Game::GameScriptClass::getCurrentTruck
BeamClass getCurrentTruck()
returns the current selected truck, null if in person mode
Script2Game::GameScriptClass::unRegisterEvent
void unRegisterEvent(int eventValue)
unregisters from receiving event.
Script2Game::GameScriptClass::getTerrain
TerrainClass getTerrain()
Gets the currently loaded terrain instance.