26# include <curl/curl.h>
27# include <curl/easy.h>
31#include "scriptany/scriptany.h"
32#include "scriptarray/scriptarray.h"
33#include "scripthelper/scripthelper.h"
34#include "scriptmath/scriptmath.h"
35#include "scriptstdstring/scriptstdstring.h"
67#include <rapidjson/document.h>
68#include <rapidjson/writer.h>
72using namespace AngelScript;
88 char buffer[4000] = {};
89 sprintf(buffer,
"[RoR|Script] ");
90 char* buffer_pos = buffer + 13;
93 va_start(args, format);
94 vsprintf(buffer_pos, format, args);
130 Vector3 result(Vector3::ZERO);
226 float result = -1.0f;
273 if (!flag ||
static_cast<int>(actor->ar_state) == flag)
358 if (type ==
"airplane")
366 if (type ==
"extension")
372 if (type ==
"trailer")
378 if (type ==
"vehicle")
411 std::string arraydecl = fmt::format(
"array<{}>",
"TerrainEditorObjectClass@");
415 for (AngelScript::asUINT i = 0; i < arr->GetSize(); i++)
419 arr->SetValue(i, &ref);
448void GameScript::spawnObject(
const String& objectName,
const String& instanceName,
const Vector3& pos,
const Vector3& rot,
const String& eventhandler,
bool uniquifyMaterials)
455 this->
logFormat(
"spawnObject(): Cannot spawn object, no terrain loaded!");
461 this->
logFormat(
"spawnObject(): Cannot spawn object, no terrain script loaded!");
467 AngelScript::asIScriptModule*
module = App::GetScriptEngine()->getScriptUnit(App::GetScriptEngine()->getTerrainScriptUnit()).scriptModule;
468 if (module ==
nullptr)
470 this->
logFormat(
"spawnObject(): Failed to fetch/create script module");
474 int handler_func_id = -1;
475 if (!eventhandler.empty())
480 "spawnObject(): Specifying event handler function in `game.spawnObject()` (or .TOBJ file) is obsolete and only works with terrain scripts;"
481 " Use `eventCallbackEx()` with event `SE_EVENTBOX_ENTER` instead, it does the same job and works with any script."
482 " Just pass an empty string to the `game.spawnObject()` parameter.");
489 if (handler_func !=
nullptr)
491 handler_func_id = handler_func->GetId();
495 const String type =
"";
448void GameScript::spawnObject(
const String& objectName,
const String& instanceName,
const Vector3& pos,
const Vector3& rot,
const String& eventhandler,
bool uniquifyMaterials) {
…}
512 ImVec2 screen_size = ImGui::GetIO().DisplaySize;
515 Ogre::Vector3 pos_xyz = world2screen.
Convert(world_pos);
518 out_screen.x = pos_xyz.x;
519 out_screen.y = pos_xyz.y;
527 ImVec2 size = ImGui::GetIO().DisplaySize;
528 return Vector2(size.x, size.y);
533 ImVec2 pos = ImGui::GetIO().MousePos;
534 return Vector2(pos.x, pos.y);
541 MaterialPtr m = MaterialManager::getSingleton().getByName(materialName);
544 m->setAmbient(red, green, blue);
558 MaterialPtr m = MaterialManager::getSingleton().getByName(materialName);
561 m->setDiffuse(red, green, blue, alpha);
575 MaterialPtr m = MaterialManager::getSingleton().getByName(materialName);
578 m->setSpecular(red, green, blue, alpha);
592 MaterialPtr m = MaterialManager::getSingleton().getByName(materialName);
595 m->setSelfIllumination(red, green, blue);
610 MaterialPtr m = MaterialManager::getSingleton().getByName(materialName);
615 if (techniqueNum < 0 || techniqueNum > m->getNumTechniques())
617 Technique* t = m->getTechnique(techniqueNum);
622 if (passNum < 0 || passNum > t->getNumPasses())
624 Pass* p = t->getPass(passNum);
629 if (textureUnitNum < 0 || textureUnitNum > p->getNumTextureUnitStates())
631 TextureUnitState* tut = p->getTextureUnitState(textureUnitNum);
643 TextureUnitState* tu = 0;
645 if (res == 0 && tu != 0)
648 tu->setTextureName(textureName);
663 TextureUnitState* tu = 0;
665 if (res == 0 && tu != 0)
667 tu->setTextureRotate(Degree(rotation));
682 TextureUnitState* tu = 0;
684 if (res == 0 && tu != 0)
686 tu->setTextureScroll(sx, sy);
701 TextureUnitState* tu = 0;
703 if (res == 0 && tu != 0)
705 tu->setTextureScale(u, v);
718 return Math::RangeRandom(from, to);
723 String terrainName =
"";
728 result = terrainName;
731 return !terrainName.empty();
746 this->
logFormat(
"Cannot execute '%s', collisions not ready", __FUNCTION__);
803 Vector3 result(Vector3::ZERO);
811 Vector3 result(Vector3::ZERO);
822 Quaternion result(Quaternion::ZERO);
847 if (player_actor ==
nullptr)
853 std::string token = std::string(
"RoR-Api-User-Token: ") + hashtok;
860 rapidjson::Document j_doc;
863 j_doc.AddMember(
"user-name", rapidjson::StringRef(
App::mp_player_name->getStr().c_str()), j_doc.GetAllocator());
864 j_doc.AddMember(
"user-country", rapidjson::StringRef(
App::app_country->getStr().c_str()), j_doc.GetAllocator());
865 j_doc.AddMember(
"user-token", rapidjson::StringRef(hashtok.c_str()), j_doc.GetAllocator());
867 j_doc.AddMember(
"terrain-name", rapidjson::StringRef(terrain_name.c_str()), j_doc.GetAllocator());
868 j_doc.AddMember(
"terrain-filename", rapidjson::StringRef(
App::sim_terrain_name->getStr().c_str()), j_doc.GetAllocator());
870 j_doc.AddMember(
"script-name", rapidjson::StringRef(script_name.c_str()), j_doc.GetAllocator());
871 j_doc.AddMember(
"script-hash", rapidjson::StringRef(script_hash.c_str()), j_doc.GetAllocator());
873 j_doc.AddMember(
"actor-name", rapidjson::StringRef(player_actor->
ar_design_name.c_str()), j_doc.GetAllocator());
874 j_doc.AddMember(
"actor-filename", rapidjson::StringRef(player_actor->
ar_filename.c_str()), j_doc.GetAllocator());
875 j_doc.AddMember(
"actor-hash", rapidjson::StringRef(player_actor->
ar_filehash.c_str()), j_doc.GetAllocator());
877 rapidjson::Value j_linked_actors(rapidjson::kArrayType);
880 rapidjson::Value j_actor(rapidjson::kObjectType);
881 j_actor.AddMember(
"actor-name", rapidjson::StringRef(actor->ar_design_name.c_str()), j_doc.GetAllocator());
882 j_actor.AddMember(
"actor-filename", rapidjson::StringRef(actor->ar_filename.c_str()), j_doc.GetAllocator());
883 j_actor.AddMember(
"actor-hash", rapidjson::StringRef(actor->ar_filehash.c_str()), j_doc.GetAllocator());
884 j_linked_actors.PushBack(j_actor, j_doc.GetAllocator());
886 j_doc.AddMember(
"linked-actors", j_linked_actors, j_doc.GetAllocator());
888 j_doc.AddMember(
"avg-fps",
getAvgFPS(), j_doc.GetAllocator());
889 j_doc.AddMember(
"ror-version", rapidjson::StringRef(
ROR_VERSION_STRING), j_doc.GetAllocator());
891 for (
auto item : dict)
893 const std::string& key = item.GetKey();
894 const std::string* value = (std::string *)item.GetAddressOfValue();
895 j_doc.AddMember(rapidjson::StringRef(key.c_str()), rapidjson::StringRef(value->c_str()), j_doc.GetAllocator());
898 rapidjson::StringBuffer buffer;
899 rapidjson::Writer<rapidjson::StringBuffer> writer(buffer);
900 j_doc.Accept(writer);
901 std::string json = buffer.GetString();
905 _L(
"using Online API..."),
"information.png");
907 LOG(
"[RoR|GameScript] Submitting race results to '" + url +
"'");
909 std::thread([url, user, token, json]()
911 long response_code = 0;
913 struct curl_slist *slist = NULL;
914 slist = curl_slist_append(slist,
"Accept: application/json");
915 slist = curl_slist_append(slist,
"Content-Type: application/json");
916 slist = curl_slist_append(slist, user.c_str());
917 slist = curl_slist_append(slist, token.c_str());
919 CURL *curl = curl_easy_init();
920 curl_easy_setopt(curl, CURLOPT_URL, url.c_str());
921 curl_easy_setopt(curl, CURLOPT_HTTPHEADER, slist);
922 curl_easy_setopt(curl, CURLOPT_POSTFIELDS, json.c_str());
924 CURLcode curl_result = curl_easy_perform(curl);
925 curl_easy_getinfo(curl, CURLINFO_RESPONSE_CODE, &response_code);
927 if (curl_result != CURLE_OK || response_code != 200)
929 Ogre::LogManager::getSingleton().stream()
930 <<
"[RoR|GameScript] `useOnlineAPI()` failed to submit data;"
931 <<
" Error: '" << curl_easy_strerror(curl_result) <<
"'; HTTP status code: " << response_code;
934 curl_easy_cleanup(curl);
936 curl_slist_free_all(slist);
941 _L(
"Cannot use Online API in this build (CURL not available)"));
964 std::thread(std::move(pktask), task).detach();
974 rpm += 2000.0f * factor;
1029 std::vector<ScriptUnitID_t> ids;
1031 ids.push_back(pair.first);
1043 AngelScript::CScriptDictionary* dict = AngelScript::CScriptDictionary::Create(
App::GetScriptEngine()->getEngine());
1047 dict->Set(
"uniqueId", (asINT64)info.
uniqueId);
1048 dict->Set(
"scriptName",
new std::string(info.
scriptName), stringTypeid);
1049 dict->Set(
"scriptCategory", &info.
scriptCategory, scriptCategoryTypeid);
1050 dict->Set(
"eventMask", (asINT64)info.
eventMask);
1051 dict->Set(
"scriptBuffer",
new std::string(info.
scriptBuffer), stringTypeid);
1079 if (actor !=
nullptr)
1090 rq.
asr_rotation = Quaternion(Degree(rot.x), Vector3::UNIT_X) * Quaternion(Degree(rot.y), Vector3::UNIT_Y) * Quaternion(Degree(rot.z), Vector3::UNIT_Z);
1103 std::vector<Ogre::Vector3> waypoints;
1110 std::reverse(waypoints.begin(), waypoints.end());
1114 Ogre::Vector3 dir = Ogre::Vector3::ZERO;
1115 if (waypoints.size() >= 2)
1116 dir = waypoints[0] - waypoints[1];
1117 else if (waypoints.size() >= 1)
1120 rq.
asr_rotation = Ogre::Vector3::UNIT_X.getRotationTo(dir, Ogre::Vector3::UNIT_Y);
1137 std::vector<Ogre::Vector3> vec;
1144 std::reverse(vec.begin(), vec.end());
1147 AngelScript::CScriptArray* arr = AngelScript::CScriptArray::Create(AngelScript::asGetActiveContext()->GetEngine()->GetTypeInfoByDecl(
"array<vector3>"), vec.size());
1149 for(AngelScript::asUINT i = 0; i < arr->GetSize(); i++)
1152 arr->SetValue(i, &vec[i]);
1161 AngelScript::CScriptArray* arr = AngelScript::CScriptArray::Create(AngelScript::asGetActiveContext()->GetEngine()->GetTypeInfoByDecl(
"array<BeamClass@>"), actors.size());
1163 for (AngelScript::asUINT i = 0; i < arr->GetSize(); i++)
1166 arr->SetValue(i, &actors[i]);
1174 std::vector<Ogre::Vector3> waypoints;
1183 std::vector<int> vec;
1189 AngelScript::CScriptArray* arr = AngelScript::CScriptArray::Create(AngelScript::asGetActiveContext()->GetEngine()->GetTypeInfoByDecl(
"array<int>"), vec.size());
1191 for(AngelScript::asUINT i = 0; i < arr->GetSize(); i++)
1194 arr->SetValue(i, &vec[i]);
1323 this->
log(fmt::format(
"setAIVehicleSectionConfig: ERROR, valid 'x' is 0 or 1, got {}",
x));
1339 this->
log(fmt::format(
"setAIVehicleSkin: ERROR, valid 'x' is 0 or 1, got {}",
x));
1354void GameScript::showMessageBox(Ogre::String& title, Ogre::String& text,
bool use_btn1, Ogre::String& btn1_text,
bool allow_close,
bool use_btn2, Ogre::String& btn2_text)
1357 const char* btn1_cstr =
nullptr;
1358 const char* btn2_cstr =
nullptr;
1362 btn1_cstr = (btn1_text.empty() ?
"~1~" : btn1_text.c_str());
1366 btn2_cstr = (btn2_text.empty() ?
"~2~" : btn2_text.c_str());
1354void GameScript::showMessageBox(Ogre::String& title, Ogre::String& text,
bool use_btn1, Ogre::String& btn1_text,
bool allow_close,
bool use_btn2, Ogre::String& btn2_text) {
…}
1403 out_pos = ray_result.position;
1405 return ray_result.hit;
1416 results_array.push_back(obj);
1420 bool queryResult(SceneQuery::WorldFragment* fragment, Real distance)
override
1420 bool queryResult(SceneQuery::WorldFragment* fragment, Real distance)
override {
…}
1435 query.setSortByDistance(
true);
1438 query.execute(&qlis);
1450 std::string log_msg = fmt::format(
"`pushMessage({})`",
MsgTypeToString(type));
1481 this->
log(fmt::format(
"{} is not allowed.", log_msg));
1493 if (!has_filename && !has_buffer)
1495 this->
log(fmt::format(
"{}: ERROR, either 'filename' or 'buffer' must be set!", log_msg));
1502 int64_t instance_id;
1505 this->
log(fmt::format(
"{}: WARNING, category 'ACTOR' specified but 'associated_actor' not given.", log_msg, rq->
lsr_filename));
1552 this->
log(fmt::format(
"{}: WARNING, vehicle '{}' is not installed.", log_msg, rq->
asr_filename));
1568 this->
log(fmt::format(
"{}: WARNING, configuration '{}' does not exist in '{}'.", log_msg, rq->
asr_config, rq->
asr_filename));
1582 std::string skin_name;
1587 this->
log(fmt::format(
"{}: WARNING, skin '{}' is not installed.", log_msg, skin_name));
1604 int64_t instance_id = -1;
1625 int64_t instance_id = -1;
1635 this->
log(fmt::format(
"{}: Actor with instance ID '{}' not found!", log_msg, instance_id));
1649 int64_t instance_id = -1;
1652 && instance_id > -1)
1662 Ogre::Vector3 position;
1665 m.
payload =
new Ogre::Vector3(position);
1744 this->
log(fmt::format(
"{}: ERROR, invalid 'free force type' value '{}'", log_msg, rq->
ffr_type));
1847 int64_t repo_resource_id = -1;
1848 int64_t repo_file_id = -1;
1849 std::string repo_filename;
1920 std::string resource_name = this->
CheckFileAccess(
"checkResourceExists()", filename, resource_group);
1921 if (resource_name ==
"")
1925 return Ogre::ResourceGroupManager::getSingleton().resourceExists(resource_group, resource_name);
1938 std::string resource_name = this->
CheckFileAccess(
"deleteResource()", filename, resource_group);
1939 if (resource_name ==
"")
1943 Ogre::ResourceGroupManager::getSingleton().deleteResource(resource_name, resource_group);
1957 std::string resource_name = this->
CheckFileAccess(
"loadTextResourceAsString()", filename, resource_group);
1958 if (resource_name ==
"")
1961 Ogre::DataStreamPtr stream = Ogre::ResourceGroupManager::getSingleton().openResource(resource_name, resource_group);
1963 if (!stream || !stream->isReadable())
1966 fmt::format(
"loadTextResourceAsString() could not read resource '{}' in group '{}'",
1967 resource_name, resource_group));
1971#if OGRE_PLATFORM == OGRE_PLATFORM_LINUX
1976 const size_t BUF_LEN = 4000;
1977 char buf[BUF_LEN] = {};
1981 size_t read_len = stream->read(buf, BUF_LEN);
1982 if (read_len < BUF_LEN)
1987 str.append(buf, read_len);
1991 return stream->getAsString();
2005 std::string resource_name = this->
CheckFileAccess(
"createTextResourceFromString()", filename, resource_group);
2006 if (resource_name ==
"")
2009 Ogre::DataStreamPtr stream = Ogre::ResourceGroupManager::getSingleton().createResource(resource_name, resource_group, overwrite);
2011 if (!stream || !stream->isWriteable())
2014 fmt::format(
"createTextResourceFromString() could not create resource '{}' in group '{}'",
2015 resource_name, resource_group));
2019 stream->write(data.data(), data.size());
2034 Ogre::FileInfoListPtr fileInfoList
2035 = Ogre::ResourceGroupManager::getSingleton().findResourceFileInfo(resource_group, pattern, dirs);
2039 AngelScript::CScriptArray* arr = AngelScript::CScriptArray::Create(typeinfo);
2041 for (
const Ogre::FileInfo& fileinfo: *fileInfoList)
2043 AngelScript::CScriptDictionary* dict = AngelScript::CScriptDictionary::Create(
App::GetScriptEngine()->getEngine());
2044 dict->Set(
"filename",
new std::string(fileinfo.filename), stringTypeid);
2045 dict->Set(
"basename",
new std::string(fileinfo.basename), stringTypeid);
2046 dict->Set(
"compressedSize", (asINT64)fileinfo.compressedSize);
2047 dict->Set(
"uncompressedSize", (asINT64)fileinfo.uncompressedSize);
2049 arr->InsertLast(dict);
2064 std::string resource_name = this->
CheckFileAccess(
"loadImageResource()", filename, resource_group);
2065 if (resource_name ==
"")
2066 return Ogre::Image();
2069 return img.load(resource_name, resource_group);
2074 return Ogre::Image();
2082 std::string resource_name = this->
CheckFileAccess(
"serializeMeshResource()", filename, resource_group);
2083 if (resource_name ==
"")
2086 Ogre::MeshSerializer ser;
2087 Ogre::DataStreamPtr stream = Ogre::ResourceGroupManager::getSingleton().createResource(resource_name, resource_group);
2088 ser.exportMesh(mesh.get(), stream);
2105 this->
logFormat(
"Cannot execute '%s', terrain not ready", func_name);
2115 this->
logFormat(
"Cannot execute '%s', player avatar not ready", func_name);
2125 this->
logFormat(
"Cannot execute '%s', main camera not ready", func_name);
2136 std::string basename, extension, path;
2137 Ogre::StringUtil::splitFullFilename(filename, basename, extension, path);
2141 fmt::format(
"{}: access denied to '{}' with group '{}' - file paths are not allowed",
2142 func_name, filename, resource_group));
2147 return basename +
"." + extension;
System integration layer; inspired by OgreBites::ApplicationContext.
void LOG(const char *msg)
Legacy alias - formerly a macro.
A database of user-installed content alias 'mods' (vehicles, terrains...)
Game state manager and message-queue provider.
const char *const ROR_VERSION_STRING
std::string ar_filehash
Attribute; filled at spawn.
Ogre::String ar_design_name
Name of the vehicle/machine/object this actor represents.
ActorInstanceID_t ar_instance_id
Static attr; session-unique ID.
ActorPtrVec ar_linked_actors
BEWARE: Includes indirect links, see DetermineLinkedActors(); Other actors linked using 'hooks/ties/r...
std::string ar_filename
Attribute; filled at spawn.
VehicleAIPtr ar_vehicle_ai
ActorPtrVec & GetActors()
FreeForceID_t GetFreeForceNextId()
Script proxy: game.getFreeForceNextId()
void SetTrucksForcedAwake(bool forced)
float GetTotalTime() const
const ActorPtr & GetActorById(ActorInstanceID_t actor_id)
ActorInstanceID_t GetActorNextInstanceId()
Script proxy: game.getActorNextInstanceId()
void RepairActor(Collisions *collisions, const Ogre::String &inst, const Ogre::String &box, bool keepPosition=false)
Ogre::RenderWindow * GetRenderWindow()
std::string const & getStr() const
std::vector< Ogre::String > sectionconfigs
CacheEntryPtr FindEntryByFilename(RoR::LoaderType type, bool partial, const std::string &_filename_maybe_bundlequalified)
Returns NULL if none found; "Bundle-qualified" format also specifies the ZIP/directory in modcache,...
CacheEntryPtr FetchSkinByName(std::string const &skin_name)
Ogre::SceneNode * GetCameraNode()
Ogre::Camera * GetCamera()
void setPosition(Ogre::Vector3 position)
Ogre::Vector3 getPosition()
void setRotation(Ogre::Radian rotation)
void move(Ogre::Vector3 offset)
Ogre::Radian getRotation() const
@ CONSOLE_MSGTYPE_SCRIPT
Messages sent from scripts.
@ CONSOLE_MSGTYPE_INFO
Generic message.
void putMessage(MessageArea area, MessageType type, std::string const &msg, std::string icon="")
GUI::TopMenubar TopMenubar
void ShowMessageBox(const char *title, const char *text, bool allow_close=true, const char *btn1_text="OK", const char *btn2_text=nullptr)
ActorPtr SpawnActor(ActorSpawnRequest &rq)
ActorPtr FindActorByCollisionBox(std::string const &ev_src_instance_name, std::string const &box_name)
Character * GetPlayerCharacter()
const ActorPtr & GetPlayerActor()
const TerrainPtr & GetTerrain()
void ShowLoaderGUI(int type, const Ogre::String &instance, const Ogre::String &box)
void PushMessage(Message m)
Doesn't guarantee order! Use ChainMessage() if order matters.
const ActorPtr & GetActorRemotelyReceivingCommands()
ActorManager * GetActorManager()
RaceSystem & GetRaceSystem()
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)
int getAIVehicleDistance()
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()
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 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
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....
FreeBeamGfxID_t GetFreeBeamGfxNextId()
Ogre::SceneManager * GetSceneManager()
void AddPacket(int streamid, int type, int len, const char *content)
void UpdateDirectionArrow(char *text, Ogre::Vector3 position)
void SetRaceBestTime(float time)
void StartRaceTimer(int id)
void SetRaceTimeDiff(float diff)
ScriptUnit & getScriptUnit(ScriptUnitID_t unique_id)
ScriptRetCode_t variableExists(const Ogre::String &arg, const ScriptUnitID_t nid=SCRIPTUNITID_DEFAULT)
Adds a global variable to the script.
ScriptRetCode_t deleteVariable(const Ogre::String &arg, const ScriptUnitID_t nid=SCRIPTUNITID_DEFAULT)
Deletes a global variable from the script.
void forwardExceptionAsScriptEvent(const std::string &from)
Forwards useful info from C++ try{}catch{} exceptions to script in the form of game event.
ScriptRetCode_t addVariable(const Ogre::String &arg, const ScriptUnitID_t nid=SCRIPTUNITID_DEFAULT)
Adds a global variable to the script.
ScriptRetCode_t deleteFunction(const Ogre::String &arg, const ScriptUnitID_t nid=SCRIPTUNITID_DEFAULT)
Deletes a global function from the script.
ScriptUnitMap const & getScriptUnits() const
void SLOG(const char *msg)
Replacement of macro.
ScriptRetCode_t getVariable(const Ogre::String &varName, void *ref, int typeID, ScriptUnitID_t nid=SCRIPTUNITID_DEFAULT)
Retrieves a global variable from any running script.
ScriptRetCode_t addFunction(const Ogre::String &arg, const ScriptUnitID_t nid=SCRIPTUNITID_DEFAULT)
Adds a global function to the script.
ScriptUnitID_t getCurrentlyExecutingScriptUnit() const
AngelScript::asIScriptFunction * getFunctionByDeclAndLogCandidates(ScriptUnitID_t nid, GetFuncFlags_t flags, const std::string &funcName, const std::string &fmtFuncDecl)
Finds a function by full declaration, and if not found, finds candidates by name and logs them to Ang...
ScriptRetCode_t functionExists(const Ogre::String &arg, const ScriptUnitID_t nid=SCRIPTUNITID_DEFAULT)
Checks if a global function exists.
AngelScript::asIScriptEngine * getEngine()
void setForwardScriptLogToConsole(bool doForward)
SoundPtr createSound(Ogre::String filename, Ogre::String resource_group_name="")
static const int ACTOR_ID_UNKNOWN
SoundScriptTemplatePtr & getTemplate(Ogre::String name)
SoundManager * getSoundManager()
SoundScriptInstancePtr createInstance(Ogre::String templatename, int actor_id, int soundLinkType=SL_DEFAULT, int soundLinkItemId=-1)
Represents an instance of static terrain object (.ODEF file format)
Ogre::TerrainGroup * getTerrainGroup()
void setGravity(float value)
TerrainObjectManager * getObjectManager()
SkyManager * getSkyManager()
TerrainGeometryManager * getGeometryManager()
std::string getTerrainName() const
float getHeightAt(float x, float z)
Collisions * GetCollisions()
bool LoadTerrainObject(const Ogre::String &name, const Ogre::Vector3 &pos, const Ogre::Vector3 &rot, const Ogre::String &instancename, const Ogre::String &type, float rendering_distance=0, bool enable_collisions=true, int scripthandler=-1, bool uniquifyMaterial=false)
TerrainEditorObjectPtrVec & GetEditorObjects()
void moveObjectVisuals(const Ogre::String &instancename, const Ogre::Vector3 &pos)
void destroyObject(const Ogre::String &instancename)
void SetStaticWaterHeight(float value)
float GetStaticWaterHeight()
Returns static water level configured in 'terrn2'.
< Keeps data close for faster access.
Ogre::Vector3 Convert(Ogre::Vector3 world_pos)
bool queryResult(SceneQuery::WorldFragment *fragment, Real distance) override
std::vector< Ogre::MovableObject * > results_array
bool queryResult(MovableObject *obj, Real distance) override
void OpenUrlInDefaultBrowser(std::string const &url)
const char * MsgTypeToString(MsgType type)
MsgType
Global gameplay message loop, see struct Message in GameContext.h.
@ MSG_GUI_OPEN_MENU_REQUESTED
@ MSG_APP_MODCACHE_LOAD_REQUESTED
@ MSG_SIM_TELEPORT_PLAYER_REQUESTED
Payload = Ogre::Vector3* (owner)
@ MSG_NET_CONNECT_STARTED
@ MSG_NET_FETCH_AI_PRESETS_SUCCESS
Description = JSON string.
@ MSG_NET_DOWNLOAD_REPOFILE_REQUESTED
Payload = RoR::RepoFileInstallRequest* (owner)
@ MSG_EDI_ADD_FREEBEAMGFX_REQUESTED
Payload = RoR::FreeBeamGfxRequest* (owner)
@ MSG_NET_DOWNLOAD_REPOFILE_SUCCESS
Payload = RoR::RepoFileInstallRequest* (owner)
@ MSG_SIM_UNHIDE_NET_ACTOR_REQUESTED
Payload = ActorPtr* (owner)
@ MSG_SIM_HIDE_NET_ACTOR_REQUESTED
Payload = ActorPtr* (owner)
@ MSG_SIM_UNLOAD_TERRN_REQUESTED
@ MSG_EDI_UNLOAD_BUNDLE_REQUESTED
Payload = RoR::CacheEntryPtr* (owner)
@ MSG_NET_CONNECT_FAILURE
@ MSG_NET_FETCH_AI_PRESETS_FAILURE
Description = message.
@ MSG_SIM_SPAWN_ACTOR_REQUESTED
Payload = RoR::ActorSpawnRequest* (owner)
@ MSG_SIM_REMOVE_FREEFORCE_REQUESTED
Payload = RoR::FreeForceID_t* (owner)
@ MSG_GUI_OPEN_SELECTOR_REQUESTED
Payload = LoaderType* (owner), Description = GUID | empty.
@ MSG_APP_UNLOAD_SCRIPT_REQUESTED
Payload = RoR::ScriptUnitId_t* (owner)
@ MSG_SIM_SEAT_PLAYER_REQUESTED
Payload = RoR::ActorPtr (owner) | nullptr.
@ MSG_NET_CONNECT_PROGRESS
@ MSG_EDI_LOAD_BUNDLE_REQUESTED
Payload = RoR::CacheEntryPtr* (owner)
@ MSG_APP_LOAD_SCRIPT_REQUESTED
Payload = RoR::LoadScriptRequest* (owner)
@ MSG_SIM_LOAD_SAVEGAME_REQUESTED
@ MSG_NET_CONNECT_SUCCESS
@ MSG_NET_USER_DISCONNECT
@ MSG_SIM_ADD_FREEFORCE_REQUESTED
Payload = RoR::FreeForceRequest* (owner)
@ MSG_NET_OPEN_RESOURCE_SUCCESS
Payload = GUI::ResourcesCollection* (owner)
@ MSG_APP_SHUTDOWN_REQUESTED
@ MSG_EDI_MODIFY_FREEBEAMGFX_REQUESTED
Payload = RoR::FreeBeamGfxRequest* (owner)
@ MSG_EDI_MODIFY_GROUNDMODEL_REQUESTED
Payload = RoR::ground_model_t* (weak)
@ MSG_EDI_DELETE_FREEBEAMGFX_REQUESTED
Payload = RoR::FreeBeamGfxID_t* (owner)
@ MSG_NET_DOWNLOAD_REPOFILE_PROGRESS
Payload = int* (owner)
@ MSG_GUI_SHOW_MESSAGE_BOX_REQUESTED
Payload = MessageBoxConfig* (owner)
@ MSG_SIM_MODIFY_FREEFORCE_REQUESTED
Payload = RoR::FreeForceRequest* (owner)
@ MSG_NET_REFRESH_SERVERLIST_FAILURE
Payload = RoR::CurlFailInfo* (owner)
@ MSG_NET_REFRESH_REPOLIST_FAILURE
Payload = RoR::CurlFailInfo* (owner)
@ MSG_EDI_CREATE_PROJECT_REQUESTED
Payload = RoR::CreateProjectRequest* (owner)
@ MSG_APP_SCRIPT_THREAD_STATUS
Payload = RoR::ScriptEventArgs* (owner)
@ MSG_SIM_LOAD_TERRN_REQUESTED
@ MSG_NET_REFRESH_REPOLIST_SUCCESS
Payload = GUI::ResourcesCollection* (owner)
@ MSG_NET_DOWNLOAD_REPOFILE_FAILURE
Payload = RoR::RepoFileInstallRequest* (owner)
@ MSG_SIM_DELETE_ACTOR_REQUESTED
Payload = RoR::ActorPtr* (owner)
@ MSG_NET_REFRESH_SERVERLIST_SUCCESS
Payload = GUI::MpServerInfoVec* (owner)
@ MSG_SIM_MODIFY_ACTOR_REQUESTED
Payload = RoR::ActorModifyRequest* (owner)
@ MSG_EDI_RELOAD_BUNDLE_REQUESTED
Payload = RoR::CacheEntryPtr* (owner)
@ TOWARDS_COORDS
Constant force directed towards ffc_target_coords
@ HALFBEAM_ROPE
Like TOWARDS_NODE, but parametrized like a rope-beam in truck fileformat.
@ CONSTANT
Constant force given by direction and magnitude.
@ HALFBEAM_GENERIC
Like TOWARDS_NODE, but parametrized like a beam in truck fileformat.
@ TOWARDS_NODE
Constant force directed towards ffc_target_node
AngelScript::CScriptArray * VectorToScriptArray(const std::vector< T > &vec, const std::string &decl)
AngelScript::CScriptArray * MapToScriptArray(std::map< T, U > &map, const std::string &decl)
const std::string GETFUNC_DEFAULTEVENTCALLBACK_SIGFMT
const GetFuncFlags_t GETFUNCFLAG_REQUIRED
Always logs warning that function was not found.
bool GetValueFromScriptDict(const std::string &log_msg, AngelScript::CScriptDictionary *dict, bool required, std::string const &key, const char *decl, T &out_value)
@ ACTOR
Defined in truck file under 'scripts', contains global variable BeamClass@ thisActor.
AppContext * GetAppContext()
InputEngine * GetInputEngine()
CameraManager * GetCameraManager()
SoundScriptManager * GetSoundScriptManager()
GUIManager * GetGuiManager()
GameContext * GetGameContext()
CVar * app_disable_online_api
ScriptEngine * GetScriptEngine()
CacheSystem * GetCacheSystem()
std::vector< ActorPtr > ActorPtrVec
bool GetUrlAsStringMQ(CurlTaskContext task)
LoaderType
< Search mode for ModCache::Query() & Operation mode for GUI::MainSelector
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 ScriptUnitID_t
Unique sequentially generated ID of a loaded and running scriptin session. Use ScriptEngine::getScrip...
RefCountingObjectPtr< Actor > ActorPtr
static const ScriptUnitID_t SCRIPTUNITID_INVALID
std::string Sha1Hash(std::string const &data)
std::vector< TerrainEditorObjectPtr > TerrainEditorObjectPtrVec
RefCountingObjectPtr< CacheEntry > CacheEntryPtr
int FreeBeamGfxID_t
Index into GfxScene::m_gfx_freebeams, use RoR::FREEBEAMGFXID_INVALID as empty value.
@ MSG2_GAME_CMD
Script message. Can be sent in both directions.
ActorInstanceID_t amr_actor
CacheEntryPtr asr_cache_entry
Optional, overrides 'asr_filename' and 'asr_cache_entry_num'.
Ogre::Vector3 asr_position
CacheEntryPtr asr_skin_entry
ActorInstanceID_t asr_instance_id
Optional; see ActorManager::GetActorNextInstanceID();.
std::string asr_filename
Can be in "Bundle-qualified" format, i.e. "mybundle.zip:myactor.truck".
Ogre::Quaternion asr_rotation
Creates subdirectory in 'My Games\Rigs of Rods\projects', pre-populates it with files and adds modcac...
CacheEntryPtr cpr_source_entry
The original mod to copy files from.
std::string cpr_name
Directory and also the mod file (without extension).
std::string ctc_displayname
MsgType ctc_msg_failure
Sent on failure; Payload: RoR::ScriptEventArgs (see 'gameplay/ScriptEvents.h') with args for RoR::SE_...
Used by MSG_EDI_[ADD/MODIFY]_FREEBEAMGFX_REQUESTED; tailored for use with AngelScript thru GameScript...
std::string fbr_material_name
double fbr_diameter
meters
int64_t fbr_freeforce_primary
Required.
int64_t fbr_id
ID of the freebeam gfx, use GfxScene::GetFreeBeamGfxNextId()
int64_t fbr_freeforce_secondary
Not required for fixed-end beams.
std::string fbr_mesh_name
Common for ADD and MODIFY requests; tailored for use with AngelScript thru GameScript::pushMessage().
double ffr_force_magnitude
double ffr_halfb_strength
Ogre::Vector3 ffr_target_coords
double ffr_halfb_diameter
Ogre::Vector3 ffr_force_const_direction
std::string lsr_filename
Load from resource ('.as' file or '.gadget' file); If buffer is supplied, use this as display name on...
ScriptCategory lsr_category
std::string lsr_buffer
Load from memory buffer.
Unified game event system - all requests and state changes are reported using a message.
Payload for MSG_NET_INSTALL_REPOFILE_REQUEST message - also used for update (overwrites existing)
std::string rfir_filename
Represents a loaded script and all associated resources/handles.
ScriptCategory scriptCategory
unsigned int eventMask
filter mask for script events
Ogre::String scriptBuffer
Ogre::String scriptName
Name of the '.as' file exclusively.