28
28
#include " BunkerAssemblyScheme.h"
29
29
#include " BunkerAssembly.h"
30
30
#include " SLBackground.h"
31
+ #include " EditorActivity.h"
31
32
32
33
#include " AEmitter.h"
33
34
#include " ADoor.h"
@@ -1333,6 +1334,9 @@ int Scene::ReadProperty(const std::string_view &propName, Reader &reader)
1333
1334
1334
1335
int Scene::Save (Writer &writer) const {
1335
1336
Entity::Save (writer);
1337
+
1338
+ bool doFullGameSave = !dynamic_cast <EditorActivity *>(g_ActivityMan.GetActivity ());
1339
+
1336
1340
writer.NewPropertyWithValue (" LocationOnPlanet" , m_Location);
1337
1341
writer.NewPropertyWithValue (" MetagamePlayable" , m_MetagamePlayable);
1338
1342
// Do not save preview if it's path is empty, for example in metagame
@@ -1354,9 +1358,10 @@ int Scene::Save(Writer &writer) const {
1354
1358
writer.NewPropertyWithValue (playerNumberString + " BuildBudgetRatio" , m_BuildBudgetRatio[player]);
1355
1359
if (m_ResidentBrains[player]) {
1356
1360
writer.NewProperty (playerNumberString + " ResidentBrain" );
1357
- SaveSceneObject (writer, m_ResidentBrains[player], false );
1361
+ SaveSceneObject (writer, m_ResidentBrains[player], false , doFullGameSave );
1358
1362
}
1359
1363
}
1364
+
1360
1365
writer.NewPropertyWithValue (" AutoDesigned" , m_AutoDesigned);
1361
1366
writer.NewPropertyWithValue (" TotalInvestment" , m_TotalInvestment);
1362
1367
writer.NewPropertyWithValue (" Terrain" , m_pTerrain);
@@ -1379,7 +1384,7 @@ int Scene::Save(Writer &writer) const {
1379
1384
}
1380
1385
1381
1386
// writer << placedObject;
1382
- SaveSceneObject (writer, placedObject, false );
1387
+ SaveSceneObject (writer, placedObject, false , doFullGameSave );
1383
1388
}
1384
1389
}
1385
1390
@@ -1465,11 +1470,11 @@ int Scene::Save(Writer &writer) const {
1465
1470
1466
1471
// ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
1467
1472
1468
- void Scene::SaveSceneObject (Writer &writer, const SceneObject *sceneObjectToSave, bool isChildAttachable) const {
1469
- auto WriteHardcodedAttachableOrNone = [this , &writer](const std::string &propertyName, const Attachable *harcodedAttachable) {
1473
+ void Scene::SaveSceneObject (Writer &writer, const SceneObject *sceneObjectToSave, bool isChildAttachable, bool saveFullData ) const {
1474
+ auto WriteHardcodedAttachableOrNone = [this , &writer, &saveFullData ](const std::string &propertyName, const Attachable *harcodedAttachable) {
1470
1475
if (harcodedAttachable) {
1471
1476
writer.NewProperty (propertyName);
1472
- SaveSceneObject (writer, harcodedAttachable, true );
1477
+ SaveSceneObject (writer, harcodedAttachable, true , saveFullData );
1473
1478
} else {
1474
1479
writer.NewPropertyWithValue (propertyName, " None" );
1475
1480
}
@@ -1478,22 +1483,26 @@ void Scene::SaveSceneObject(Writer &writer, const SceneObject *sceneObjectToSave
1478
1483
writer.ObjectStart (sceneObjectToSave->GetClassName ());
1479
1484
writer.NewPropertyWithValue (" CopyOf" , sceneObjectToSave->GetModuleAndPresetName ());
1480
1485
1481
- for (const std::string &group : *sceneObjectToSave->GetGroups ()) {
1482
- writer.NewPropertyWithValue (" AddToGroup" , group);
1486
+ if (saveFullData) {
1487
+ for (const std::string &group : *sceneObjectToSave->GetGroups ()) {
1488
+ writer.NewPropertyWithValue (" AddToGroup" , group);
1489
+ }
1483
1490
}
1484
1491
1485
1492
writer.NewPropertyWithValue (" Position" , sceneObjectToSave->GetPos ());
1486
1493
writer.NewPropertyWithValue (" Team" , sceneObjectToSave->GetTeam ());
1487
1494
if (!isChildAttachable) {
1488
1495
writer.NewPropertyWithValue (" PlacedByPlayer" , sceneObjectToSave->GetPlacedByPlayer ());
1489
1496
}
1490
- writer.NewPropertyWithValue (" GoldValue" , sceneObjectToSave->GetGoldValue ());
1497
+ if (saveFullData) {
1498
+ writer.NewPropertyWithValue (" GoldValue" , sceneObjectToSave->GetGoldValue ());
1499
+ }
1491
1500
1492
1501
if (const Deployment *deploymentToSave = dynamic_cast <const Deployment *>(sceneObjectToSave); deploymentToSave && deploymentToSave->GetID () != 0 ) {
1493
1502
writer.NewPropertyWithValue (" ID" , deploymentToSave->GetID ());
1494
1503
}
1495
1504
1496
- if (const MovableObject *movableObjectToSave = dynamic_cast <const MovableObject *>(sceneObjectToSave)) {
1505
+ if (const MovableObject *movableObjectToSave = dynamic_cast <const MovableObject *>(sceneObjectToSave); movableObjectToSave && saveFullData ) {
1497
1506
writer.NewPropertyWithValue (" HUDVisible" , movableObjectToSave->GetHUDVisible ());
1498
1507
writer.NewPropertyWithValue (" Velocity" , movableObjectToSave->GetVel ());
1499
1508
writer.NewPropertyWithValue (" LifeTime" , movableObjectToSave->GetLifetime ());
@@ -1503,30 +1512,37 @@ void Scene::SaveSceneObject(Writer &writer, const SceneObject *sceneObjectToSave
1503
1512
1504
1513
if (const MOSprite *moSpriteToSave = dynamic_cast <const MOSprite *>(sceneObjectToSave)) {
1505
1514
writer.NewPropertyWithValue (" HFlipped" , moSpriteToSave->IsHFlipped ());
1506
- writer.NewPropertyWithValue (" Rotation" , moSpriteToSave->GetRotMatrix ());
1507
- writer.NewPropertyWithValue (" AngularVel" , moSpriteToSave->GetAngularVel ());
1515
+ if (saveFullData || dynamic_cast <const ADoor *>(moSpriteToSave)) {
1516
+ writer.NewPropertyWithValue (" Rotation" , moSpriteToSave->GetRotMatrix ());
1517
+ }
1518
+ if (saveFullData) {
1519
+ writer.NewPropertyWithValue (" AngularVel" , moSpriteToSave->GetAngularVel ());
1520
+ }
1508
1521
}
1509
1522
1510
1523
if (const MOSRotating *mosRotatingToSave = dynamic_cast <const MOSRotating *>(sceneObjectToSave)) {
1511
- const std::list<Attachable *> &attachablesToSave = mosRotatingToSave->GetAttachableList ();
1512
-
1513
- // If this MOSRotating has any Attachables, we have to add a special behaviour property that'll delete them all so they can be re-read. This will allow us to handle Attachables with our limited serialization.
1514
- // Alternatively, if the MOSRotating has no Attachables but its preset does, we need to set the flag, because that means this is missing Attachables, and we don't want to magically regenerate them when a game is loaded.
1515
- if (!attachablesToSave.empty ()) {
1516
- writer.NewPropertyWithValue (" SpecialBehaviour_ClearAllAttachables" , true );
1517
- } else if (const MOSRotating *presetOfMOSRotatingToSave = dynamic_cast <const MOSRotating *>(g_PresetMan.GetEntityPreset (mosRotatingToSave->GetClassName (), mosRotatingToSave->GetPresetName (), mosRotatingToSave->GetModuleID ())); presetOfMOSRotatingToSave && !presetOfMOSRotatingToSave->GetAttachableList ().empty ()) {
1518
- writer.NewPropertyWithValue (" SpecialBehaviour_ClearAllAttachables" , true );
1519
- }
1524
+ if (saveFullData) {
1525
+ const std::list<Attachable *> &attachablesToSave = mosRotatingToSave->GetAttachableList ();
1520
1526
1521
- for (const Attachable *attachable : attachablesToSave) {
1522
- if (!mosRotatingToSave->AttachableIsHardcoded (attachable)) {
1523
- writer.NewProperty (" AddAttachable" );
1524
- SaveSceneObject (writer, attachable, true );
1527
+ // If this MOSRotating has any Attachables, we have to add a special behaviour property that'll delete them all so they can be re-read. This will allow us to handle Attachables with our limited serialization.
1528
+ // Alternatively, if the MOSRotating has no Attachables but its preset does, we need to set the flag, because that means this is missing Attachables, and we don't want to magically regenerate them when a game is loaded.
1529
+ if (!attachablesToSave.empty ()) {
1530
+ writer.NewPropertyWithValue (" SpecialBehaviour_ClearAllAttachables" , true );
1531
+ }
1532
+ else if (const MOSRotating *presetOfMOSRotatingToSave = dynamic_cast <const MOSRotating *>(g_PresetMan.GetEntityPreset (mosRotatingToSave->GetClassName (), mosRotatingToSave->GetPresetName (), mosRotatingToSave->GetModuleID ())); presetOfMOSRotatingToSave && !presetOfMOSRotatingToSave->GetAttachableList ().empty ()) {
1533
+ writer.NewPropertyWithValue (" SpecialBehaviour_ClearAllAttachables" , true );
1534
+ }
1535
+
1536
+ for (const Attachable *attachable : attachablesToSave) {
1537
+ if (!mosRotatingToSave->AttachableIsHardcoded (attachable)) {
1538
+ writer.NewProperty (" AddAttachable" );
1539
+ SaveSceneObject (writer, attachable, true , saveFullData);
1540
+ }
1541
+ }
1542
+ for (const AEmitter *wound : mosRotatingToSave->GetWoundList ()) {
1543
+ writer.NewProperty (" SpecialBehaviour_AddWound" );
1544
+ SaveSceneObject (writer, wound, true , saveFullData);
1525
1545
}
1526
- }
1527
- for (const AEmitter *wound : mosRotatingToSave->GetWoundList ()) {
1528
- writer.NewProperty (" SpecialBehaviour_AddWound" );
1529
- SaveSceneObject (writer, wound, true );
1530
1546
}
1531
1547
1532
1548
for (auto &[key, value] : mosRotatingToSave->GetStringValueMap ()) {
@@ -1544,7 +1560,7 @@ void Scene::SaveSceneObject(Writer &writer, const SceneObject *sceneObjectToSave
1544
1560
}
1545
1561
}
1546
1562
1547
- if (const Attachable *attachableToSave = dynamic_cast <const Attachable *>(sceneObjectToSave)) {
1563
+ if (const Attachable *attachableToSave = dynamic_cast <const Attachable *>(sceneObjectToSave); attachableToSave && saveFullData ) {
1548
1564
writer.NewPropertyWithValue (" ParentOffset" , attachableToSave->GetParentOffset ());
1549
1565
writer.NewPropertyWithValue (" DrawAfterParent" , attachableToSave->IsDrawnAfterParent ());
1550
1566
writer.NewPropertyWithValue (" DeleteWhenRemovedFromParent" , attachableToSave->GetDeleteWhenRemovedFromParent ());
@@ -1606,23 +1622,26 @@ void Scene::SaveSceneObject(Writer &writer, const SceneObject *sceneObjectToSave
1606
1622
}
1607
1623
1608
1624
if (const Actor *actorToSave = dynamic_cast <const Actor *>(sceneObjectToSave)) {
1609
- writer.NewPropertyWithValue (" Status" , actorToSave->GetStatus ());
1610
1625
writer.NewPropertyWithValue (" Health" , actorToSave->GetHealth ());
1611
1626
writer.NewPropertyWithValue (" MaxHealth" , actorToSave->GetMaxHealth ());
1612
- writer.NewPropertyWithValue (" PlayerControllable" , actorToSave->IsPlayerControllable ());
1613
- int aiModeToSave = actorToSave->GetAIMode () == Actor::AIMode::AIMODE_SQUAD ? Actor::AIMode::AIMODE_GOTO : actorToSave->GetAIMode ();
1614
- if (aiModeToSave == Actor::AIMode::AIMODE_GOTO && (!actorToSave->GetMOMoveTarget () && g_SceneMan.ShortestDistance (actorToSave->GetMovePathEnd (), actorToSave->GetPos (), g_SceneMan.SceneWrapsX ()).MagnitudeIsLessThan (1 .0F ))) {
1615
- aiModeToSave = Actor::AIMode::AIMODE_SENTRY;
1616
- }
1617
- writer.NewPropertyWithValue (" AIMode" , aiModeToSave);
1618
- if (aiModeToSave == Actor::AIMode::AIMODE_GOTO) {
1619
- const std::string addWaypointPropertyName = " SpecialBehaviour_AddAISceneWaypoint" ;
1620
- if (const MovableObject *actorToSaveMOMoveTarget = actorToSave->GetMOMoveTarget ()) {
1621
- writer.NewPropertyWithValue (addWaypointPropertyName, actorToSaveMOMoveTarget->GetPos ());
1622
- } else {
1623
- writer.NewPropertyWithValue (addWaypointPropertyName, actorToSave->GetMovePathEnd ());
1624
- for (auto &[waypointPosition, waypointObject] : actorToSave->GetWaypointList ()) {
1625
- writer.NewPropertyWithValue (addWaypointPropertyName, waypointPosition);
1627
+ if (saveFullData) {
1628
+ writer.NewPropertyWithValue (" Status" , actorToSave->GetStatus ());
1629
+ writer.NewPropertyWithValue (" PlayerControllable" , actorToSave->IsPlayerControllable ());
1630
+
1631
+ int aiModeToSave = actorToSave->GetAIMode () == Actor::AIMode::AIMODE_SQUAD ? Actor::AIMode::AIMODE_GOTO : actorToSave->GetAIMode ();
1632
+ if (aiModeToSave == Actor::AIMode::AIMODE_GOTO && (!actorToSave->GetMOMoveTarget () && g_SceneMan.ShortestDistance (actorToSave->GetMovePathEnd (), actorToSave->GetPos (), g_SceneMan.SceneWrapsX ()).MagnitudeIsLessThan (1 .0F ))) {
1633
+ aiModeToSave = Actor::AIMode::AIMODE_SENTRY;
1634
+ }
1635
+ writer.NewPropertyWithValue (" AIMode" , aiModeToSave);
1636
+ if (aiModeToSave == Actor::AIMode::AIMODE_GOTO) {
1637
+ const std::string addWaypointPropertyName = " SpecialBehaviour_AddAISceneWaypoint" ;
1638
+ if (const MovableObject *actorToSaveMOMoveTarget = actorToSave->GetMOMoveTarget ()) {
1639
+ writer.NewPropertyWithValue (addWaypointPropertyName, actorToSaveMOMoveTarget->GetPos ());
1640
+ } else {
1641
+ writer.NewPropertyWithValue (addWaypointPropertyName, actorToSave->GetMovePathEnd ());
1642
+ for (auto &[waypointPosition, waypointObject] : actorToSave->GetWaypointList ()) {
1643
+ writer.NewPropertyWithValue (addWaypointPropertyName, waypointPosition);
1644
+ }
1626
1645
}
1627
1646
}
1628
1647
}
@@ -1633,40 +1652,51 @@ void Scene::SaveSceneObject(Writer &writer, const SceneObject *sceneObjectToSave
1633
1652
1634
1653
for (const MovableObject *inventoryItem : *actorToSave->GetInventory ()) {
1635
1654
writer.NewProperty (" AddInventory" );
1636
- SaveSceneObject (writer, inventoryItem, true );
1655
+ SaveSceneObject (writer, inventoryItem, true , saveFullData );
1637
1656
}
1638
1657
1639
- if (const ADoor *aDoorToSave = dynamic_cast <const ADoor *>(sceneObjectToSave)) {
1640
- WriteHardcodedAttachableOrNone (" Door" , aDoorToSave->GetDoor ());
1658
+ if (saveFullData) {
1659
+ if (const ADoor *aDoorToSave = dynamic_cast <const ADoor *>(sceneObjectToSave)) {
1660
+ WriteHardcodedAttachableOrNone (" Door" , aDoorToSave->GetDoor ());
1661
+ } else if (const AHuman *aHumanToSave = dynamic_cast <const AHuman *>(sceneObjectToSave)) {
1662
+ WriteHardcodedAttachableOrNone (" Head" , aHumanToSave->GetHead ());
1663
+ WriteHardcodedAttachableOrNone (" Jetpack" , aHumanToSave->GetJetpack ());
1664
+ WriteHardcodedAttachableOrNone (" FGArm" , aHumanToSave->GetFGArm ());
1665
+ WriteHardcodedAttachableOrNone (" BGArm" , aHumanToSave->GetBGArm ());
1666
+ WriteHardcodedAttachableOrNone (" FGLeg" , aHumanToSave->GetFGLeg ());
1667
+ WriteHardcodedAttachableOrNone (" BGLeg" , aHumanToSave->GetBGLeg ());
1668
+ } else if (const ACrab *aCrabToSave = dynamic_cast <const ACrab *>(sceneObjectToSave)) {
1669
+ WriteHardcodedAttachableOrNone (" Turret" , aCrabToSave->GetTurret ());
1670
+ WriteHardcodedAttachableOrNone (" Jetpack" , aCrabToSave->GetJetpack ());
1671
+ WriteHardcodedAttachableOrNone (" LeftFGLeg" , aCrabToSave->GetLeftFGLeg ());
1672
+ WriteHardcodedAttachableOrNone (" LeftBGLeg" , aCrabToSave->GetLeftBGLeg ());
1673
+ WriteHardcodedAttachableOrNone (" RightFGLeg" , aCrabToSave->GetRightFGLeg ());
1674
+ WriteHardcodedAttachableOrNone (" RightBGLeg" , aCrabToSave->GetRightBGLeg ());
1675
+ } else if (const ACRocket *acRocketToSave = dynamic_cast <const ACRocket *>(sceneObjectToSave)) {
1676
+ WriteHardcodedAttachableOrNone (" RightLeg" , acRocketToSave->GetRightLeg ());
1677
+ WriteHardcodedAttachableOrNone (" LeftLeg" , acRocketToSave->GetLeftLeg ());
1678
+ WriteHardcodedAttachableOrNone (" MainThruster" , acRocketToSave->GetMainThruster ());
1679
+ WriteHardcodedAttachableOrNone (" RightThruster" , acRocketToSave->GetRightThruster ());
1680
+ WriteHardcodedAttachableOrNone (" LeftThruster" , acRocketToSave->GetLeftThruster ());
1681
+ WriteHardcodedAttachableOrNone (" UpRightThruster" , acRocketToSave->GetURightThruster ());
1682
+ WriteHardcodedAttachableOrNone (" UpRightThruster" , acRocketToSave->GetULeftThruster ());
1683
+ } else if (const ACDropShip *acDropShipToSave = dynamic_cast <const ACDropShip *>(sceneObjectToSave)) {
1684
+ WriteHardcodedAttachableOrNone (" RightThruster" , acDropShipToSave->GetRightThruster ());
1685
+ WriteHardcodedAttachableOrNone (" LeftThruster" , acDropShipToSave->GetLeftThruster ());
1686
+ WriteHardcodedAttachableOrNone (" UpRightThruster" , acDropShipToSave->GetURightThruster ());
1687
+ WriteHardcodedAttachableOrNone (" UpLeftThruster" , acDropShipToSave->GetULeftThruster ());
1688
+ WriteHardcodedAttachableOrNone (" RightHatchDoor" , acDropShipToSave->GetRightHatch ());
1689
+ WriteHardcodedAttachableOrNone (" LeftHatchDoor" , acDropShipToSave->GetLeftHatch ());
1690
+ }
1641
1691
} else if (const AHuman *aHumanToSave = dynamic_cast <const AHuman *>(sceneObjectToSave)) {
1642
- WriteHardcodedAttachableOrNone (" Head" , aHumanToSave->GetHead ());
1643
- WriteHardcodedAttachableOrNone (" Jetpack" , aHumanToSave->GetJetpack ());
1644
- WriteHardcodedAttachableOrNone (" FGArm" , aHumanToSave->GetFGArm ());
1645
- WriteHardcodedAttachableOrNone (" BGArm" , aHumanToSave->GetBGArm ());
1646
- WriteHardcodedAttachableOrNone (" FGLeg" , aHumanToSave->GetFGLeg ());
1647
- WriteHardcodedAttachableOrNone (" BGLeg" , aHumanToSave->GetBGLeg ());
1648
- } else if (const ACrab *aCrabToSave = dynamic_cast <const ACrab *>(sceneObjectToSave)) {
1649
- WriteHardcodedAttachableOrNone (" Turret" , aCrabToSave->GetTurret ());
1650
- WriteHardcodedAttachableOrNone (" Jetpack" , aCrabToSave->GetJetpack ());
1651
- WriteHardcodedAttachableOrNone (" LeftFGLeg" , aCrabToSave->GetLeftFGLeg ());
1652
- WriteHardcodedAttachableOrNone (" LeftBGLeg" , aCrabToSave->GetLeftBGLeg ());
1653
- WriteHardcodedAttachableOrNone (" RightFGLeg" , aCrabToSave->GetRightFGLeg ());
1654
- WriteHardcodedAttachableOrNone (" RightBGLeg" , aCrabToSave->GetRightBGLeg ());
1655
- } else if (const ACRocket *acRocketToSave = dynamic_cast <const ACRocket *>(sceneObjectToSave)) {
1656
- WriteHardcodedAttachableOrNone (" RightLeg" , acRocketToSave->GetRightLeg ());
1657
- WriteHardcodedAttachableOrNone (" LeftLeg" , acRocketToSave->GetLeftLeg ());
1658
- WriteHardcodedAttachableOrNone (" MainThruster" , acRocketToSave->GetMainThruster ());
1659
- WriteHardcodedAttachableOrNone (" RightThruster" , acRocketToSave->GetRightThruster ());
1660
- WriteHardcodedAttachableOrNone (" LeftThruster" , acRocketToSave->GetLeftThruster ());
1661
- WriteHardcodedAttachableOrNone (" UpRightThruster" , acRocketToSave->GetURightThruster ());
1662
- WriteHardcodedAttachableOrNone (" UpRightThruster" , acRocketToSave->GetULeftThruster ());
1663
- } else if (const ACDropShip *acDropShipToSave = dynamic_cast <const ACDropShip *>(sceneObjectToSave)) {
1664
- WriteHardcodedAttachableOrNone (" RightThruster" , acDropShipToSave->GetRightThruster ());
1665
- WriteHardcodedAttachableOrNone (" LeftThruster" , acDropShipToSave->GetLeftThruster ());
1666
- WriteHardcodedAttachableOrNone (" UpRightThruster" , acDropShipToSave->GetURightThruster ());
1667
- WriteHardcodedAttachableOrNone (" UpLeftThruster" , acDropShipToSave->GetULeftThruster ());
1668
- WriteHardcodedAttachableOrNone (" RightHatchDoor" , acDropShipToSave->GetRightHatch ());
1669
- WriteHardcodedAttachableOrNone (" LeftHatchDoor" , acDropShipToSave->GetLeftHatch ());
1692
+ if (const HeldDevice *equippedItem = aHumanToSave->GetEquippedItem ()) {
1693
+ writer.NewProperty (" AddInventory" );
1694
+ SaveSceneObject (writer, equippedItem, true , saveFullData);
1695
+ }
1696
+ if (const HeldDevice *bgEquippedItem = aHumanToSave->GetEquippedBGItem ()) {
1697
+ writer.NewProperty (" AddInventory" );
1698
+ SaveSceneObject (writer, bgEquippedItem, true , saveFullData);
1699
+ }
1670
1700
}
1671
1701
}
1672
1702
writer.ObjectEnd ();
0 commit comments