Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mission system (.missionzip) #3018

Closed
wants to merge 7 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions doc/angelscript/Script2Game/BeamClass.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,10 @@ class BeamClass
/**
* Orientation on all axes packed to single quaternion. Use `getYaw()`, `getPitch()` and `getRoll()` for individual rotations in radians.
*/
quaternion getOrientation()
quaternion getOrientation();

/**
* Meters per second.
* Returns average node speed in meters/second.
*/
float getSpeed();

Expand Down
25 changes: 20 additions & 5 deletions doc/angelscript/Script2Game/GameScriptClass.h
Original file line number Diff line number Diff line change
Expand Up @@ -338,11 +338,6 @@ class GameScriptClass
*/
int getLoadedTerrain(string result);

/**
* Gets the currently loaded terrain instance
*/
TerrainClass@ getTerrain();

/**
* Checks if Caleum is enabled.
* @return true if Caleum is available
Expand Down Expand Up @@ -424,6 +419,17 @@ class GameScriptClass
* @return true if mouse points to the terrain and output coordinates are valid.
*/
bool getMousePositionOnTerrain(vector3 &out);

/**
* Gets the currently loaded terrain instance
*/
TerrainClass@ getTerrain();

/**
* Erases collision elements marked `pending_delete` and rebuilds lookup grid.
* Call this once after you've unloaded a mission or moved/removed things using editor.
*/
void pruneCollisionElements();

/// @}

Expand Down Expand Up @@ -623,6 +629,15 @@ class GameScriptClass
* @see stopTimer
*/
void startTimer();

/**
* @return The time that passed since the timer started
*/
float getElapsedTime();

void setTimeDiff(float diff);

void setBestLapTime(float time);

///@}

Expand Down
10 changes: 9 additions & 1 deletion doc/angelscript/Script2Game/globals.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ void print(const string message);
SE_TRUCK_TELEPORT //!< triggered when the user teleports the truck, the argument refers to the Actor Instance ID (use `game.getTruckByNum()`)
SE_TRUCK_MOUSE_GRAB //!< triggered when the user uses the mouse to interact with the actor, the argument refers to the Actor Instance ID (use `game.getTruckByNum()`)

SE_ANGELSCRIPT_MANIPULATIONS //!< triggered when the user tries to dynamically use the scripting capabilities (prevent cheating)
SE_ANGELSCRIPT_MANIPULATIONS //!< triggered when the user tries to dynamically use the scripting capabilities (prevent cheating) args: #1 angelScriptManipulationType, #2 ScriptUnitId_t, #3 RoR::ScriptCategory, #4 unused, #5 script file name (*.as), #6 associated file name (i.e. *.mission), #7 associated file resource group (i.e. *.mission).
SE_ANGELSCRIPT_MSGCALLBACK //!< The diagnostic info directly from AngelScript engine (see `asSMessageInfo`), args: #1 ScriptUnitID, #2 asEMsgType, #3 row, #4 col, #5 sectionName, #6 message
SE_ANGELSCRIPT_LINECALLBACK //!< The diagnostic info directly from AngelScript engine (see `SetLineCallback()`), args: #1 ScriptUnitID, #2 LineNumber, #3 CallstackSize, #4 unused, #5 FunctionName, #6 FunctionObjectTypeName #7 ObjectName
SE_ANGELSCRIPT_EXCEPTIONCALLBACK //!< The diagnostic info directly from AngelScript engine (see `SetExceptionCallback()`), args: #1 ScriptUnitID, #2 unused, #3 row (`GetExceptionLineNumber()`), #4 unused, #5 funcName, #6 message (`GetExceptionString()`)
Expand All @@ -79,6 +79,14 @@ void print(const string message);

};

/// Argument #2 of script event `SE_ANGELSCRIPT_MANIPULATIONS`
enum angelScriptManipulationType
{
ASMANIP_CONSOLE_SNIPPET_EXECUTED = 0, // 0 for Backwards compatibility.
ASMANIP_SCRIPT_LOADED, //!< Triggered after the script's `main()` completed; may trigger additional processing (for example, it delivers the *.mission file to mission system script).
ASMANIP_SCRIPT_UNLOADING //!< Triggered before unloading the script to let it clean up (important for missions).
};

enum angelScriptManipulationType
{
MANIP_CONSOLE_SNIPPET_EXECUTED = 0, // Backwards compat
Expand Down
46 changes: 46 additions & 0 deletions resources/scripts/mission_default.as
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/*
* Rigs of Rods mission system
* https://forum.rigsofrods.org/threads/mission-system-prototype.3846/
*
* This is a mission handler script. It's responsible for:
* 1) Loading the scenario from "*.mission" file and setting up
* the terrain objects and/or graphics as defined in the file.
* 2) Monitoring all necessary events while the scenario is loaded.
* 3) Unloading the scenario, undoing all changes on the terrain.
*/

#include "missions.as"

MissionManager g_missions();

/* A mandatory startup function */
void main()
{
game.registerForEvent(SE_ANGELSCRIPT_MANIPULATIONS); // Necessary to receive mission setup info
game.log("default mission script loaded");
}

/* Event handler callback */
void eventCallbackEx(scriptEvents ev, int arg1, int arg2ex, int arg3ex, int arg4ex, string arg5ex, string arg6ex, string arg7ex, string arg8ex)
{
if (ev == SE_ANGELSCRIPT_MANIPULATIONS)
{
// args: #1 angelScriptManipulationType, #2 ScriptUnitId_t, #3 RoR::ScriptCategory, #4 unused, #5 script file name (*.as), #6 associated file name (i.e. *.mission), #7 associated file resource group (i.e. *.mission).
angelScriptManipulationType manip = angelScriptManipulationType(arg1);
int nid = arg2ex;

if (manip == ASMANIP_SCRIPT_LOADED && nid == thisScript)
{
bool result = g_missions.loadMission(arg6ex, arg7ex);
//game.log("DBG mission_default.as: finished loading mission file '"+arg6ex+"' (resource group '"+arg7ex+"'), result: " + result);
}
else if (manip == ASMANIP_SCRIPT_UNLOADING && nid == thisScript)
{
g_missions.unloadMission();
//game.log("DBG mission_default.as: finished unloading mission");
}
}
}



Loading