Skip to content
This repository was archived by the owner on Jan 5, 2024. It is now read-only.

Commit 2bcaa9f

Browse files
committed
Added OnGameSave method and hardcoded lua function that get run when a GAScripted is saved
Note that this isn't run when the metagame or an editor activity is saved
1 parent 66b362c commit 2bcaa9f

File tree

5 files changed

+30
-1
lines changed

5 files changed

+30
-1
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -392,6 +392,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
392392
A new `GlobalScript` has been added that will automatically save the game every three minutes. To turn it on, enable the Autosaving `GlobalScript` in the main menu mod manager's Global Scripts section.
393393
To load games saved by this script, open the console and enter the command `ActivityMan:LoadGame("Autosave")`, or use the `Ctrl + F9` shortcut.
394394

395+
- New hardcoded `MovableObject` function `OnGameSave(self)` that gets run for each `MovableObject` with it when the game is saved. This can be used in tandem with custom values (for `MOSRotatings` and child classes) to store data, which can be read during `Create` when the game is loaded.
396+
395397
- New Lua `AEmitter` properties:
396398
**TotalParticlesPerMinute** (R/O) - The rate at which all of the `Emission`s of this `AEmitter` combined, emit their particles.
397399
**TotalBurstSize** (R/O) - The number of particles that will be emitted by all the `Emission`s of this `AEmitter` combined, in one shot when a burst is triggered.

Entities/MOSRotating.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2042,6 +2042,18 @@ void MOSRotating::CorrectAttachableAndWoundPositionsAndRotations() const {
20422042

20432043
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
20442044

2045+
void MOSRotating::OnGameSave() {
2046+
MovableObject::OnGameSave();
2047+
for (AEmitter *wound : m_Wounds) {
2048+
wound->OnGameSave();
2049+
}
2050+
for (Attachable *attachable : m_Attachables) {
2051+
attachable->OnGameSave();
2052+
}
2053+
}
2054+
2055+
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
2056+
20452057
bool MOSRotating::TransferForcesFromAttachable(Attachable *attachable) {
20462058
bool intact = false;
20472059
Vector forces;

Entities/MOSRotating.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -937,6 +937,11 @@ ClassInfoGetters;
937937
/// </summary>
938938
virtual void CorrectAttachableAndWoundPositionsAndRotations() const;
939939

940+
/// <summary>
941+
/// Method to be run when the game is saved via ActivityMan::SaveCurrentGame. Not currently used in metagame or editor saving.
942+
/// </summary>
943+
void OnGameSave() override;
944+
940945

941946
//////////////////////////////////////////////////////////////////////////////////////////
942947
// Protected member variable and method declarations

Entities/MovableObject.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ friend struct EntityLuaBindings;
6363

6464
public:
6565

66-
ScriptFunctionNames("Create", "Destroy", "Update", "OnScriptDisable", "OnScriptEnable", "OnCollideWithTerrain", "OnCollideWithMO", "WhilePieMenuOpen");
66+
ScriptFunctionNames("Create", "Destroy", "Update", "OnScriptDisable", "OnScriptEnable", "OnCollideWithTerrain", "OnCollideWithMO", "WhilePieMenuOpen", "OnGameSave");
6767
SerializableOverrideMethods;
6868
ClassInfoGetters;
6969

@@ -1805,6 +1805,11 @@ enum MOType
18051805
/// <returns>Whether the object was successfully drawn to the terrain.</returns>
18061806
bool DrawToTerrain(SLTerrain *terrain);
18071807

1808+
/// <summary>
1809+
/// Method to be run when the game is saved via ActivityMan::SaveCurrentGame. Not currently used in metagame or editor saving.
1810+
/// </summary>
1811+
virtual void OnGameSave() { RunScriptedFunctionInAppropriateScripts("OnGameSave"); }
1812+
18081813
//////////////////////////////////////////////////////////////////////////////////////////
18091814
// Protected member variable and method declarations
18101815

Managers/ActivityMan.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,11 @@ namespace RTE {
110110
// Pull all stuff from MovableMan into the Scene for saving, so existing Actors/ADoors are saved, without transferring ownership, so the game can continue.
111111
// This is done after the activity is saved, in case the activity wants to add anything to the scene while saving.
112112
modifiableScene->RetrieveSceneObjects(false);
113+
for (SceneObject *objectToSave : *modifiableScene->GetPlacedObjects(Scene::PlacedObjectSets::PLACEONLOAD)) {
114+
if (MovableObject *objectToSaveAsMovableObject = dynamic_cast<MovableObject *>(objectToSave)) {
115+
objectToSaveAsMovableObject->OnGameSave();
116+
}
117+
}
113118

114119
writer->NewPropertyWithValue("OriginalScenePresetName", scene->GetPresetName());
115120
writer->NewPropertyWithValue("PlaceObjectsIfSceneIsRestarted", g_SceneMan.GetPlaceObjectsOnLoad());

0 commit comments

Comments
 (0)