Skip to content

Fixed a bunch of Bugs #11

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

Open
wants to merge 11 commits into
base: master
Choose a base branch
from
Open
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
1 change: 1 addition & 0 deletions SEToolbox/Interop/ClassType.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
public enum ClassType
{
Unknown,
SafeZone,
Character,
FloatingObject,
LargeShip,
Expand Down
93 changes: 87 additions & 6 deletions SEToolbox/Models/ExplorerModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
using System.Windows.Shell;
using System.Windows.Threading;
using Microsoft.VisualBasic.FileIO;
using ObjectBuilders.SafeZone;
using Sandbox.Common.ObjectBuilders;
using SEToolbox.Interfaces;
using SEToolbox.Interop;
Expand All @@ -18,6 +19,7 @@
using VRage.Game;
using VRage.ObjectBuilders;
using VRageMath;
using VRage.Game.ObjectBuilders.Components.Beacon; //Apparently the safeZoneComponent is in the namespace Beacon
using IDType = VRage.MyEntityIdentifier.ID_OBJECT_TYPE;

public class ExplorerModel : BaseModel
Expand Down Expand Up @@ -803,6 +805,17 @@ public void MergeData(IList<IStructureBase> data)
var entity = AddEntity(inventoryBag.EntityBase);
entity.EntityId = MergeId(inventoryBag.EntityId, ref idReplacementTable);
}
else if (item is StructureSafeZoneModel)
{
var safeZone = item as StructureSafeZoneModel;
var entity = AddEntity(safeZone.EntityBase);
entity.EntityId = MergeId(safeZone.EntityId, ref idReplacementTable);

var safeZonetmp = entity as StructureSafeZoneModel;
if(safeZonetmp != null && safeZonetmp.SafeZoneBlockId != 0) {
safeZonetmp.SafeZoneBlockId = MergeId(safeZonetmp.SafeZoneBlockId, ref idReplacementTable);
}
}
else if (item is StructureUnknownModel)
{
var unknown = item as StructureUnknownModel;
Expand Down Expand Up @@ -831,12 +844,39 @@ private void MergeData(MyObjectBuilder_CubeGrid cubeGridObject, ref Dictionary<I
{
cockpit.RemoveHierarchyCharacter();
}
/* TODO: Could we combine Pistons and Rotors into MyObjectBuilder_MechanicalConnectionBlock? That would increase robustness in case SE adds more mechanical connection types.
* var connectionBase = cubeGrid as MyObjectBuilder_MechanicalConnectionBlock;
* if (connectionBase != null) {
* connectionBase.TopBlockId = MergeId(pistonBase.TopBlockId.Value, ref idReplacementTable);
* }
* var motorBase = cubeGrid as MyObjectBuilder_MotorBase;
* if (motorBase != null) {
* if (motorBase.RotorEntityId.HasValue) {
* motorBase.RotorEntityId = MergeId(motorBase.RotorEntityId.Value, ref idReplacementTable);
* }
* if (motorBase.WeldedEntityId.HasValue) {
* MotorBase.WeldedEntityId = MergeId(motorBase.WeldedEntityId.Value, ref idReplacementTable);
* }
* }
*/

var motorBase = cubeGrid as MyObjectBuilder_MotorBase;
if (motorBase != null && motorBase.RotorEntityId.HasValue)
/* Old version of code, which led to Wheels/Suspensions, Rotors and Hinges getting seperated
* (motorBase != null && motorBase.RotorEntityId.HasValue)
* {
* // reattach motor/rotor to correct entity.
* motorBase.RotorEntityId = MergeId(motorBase.RotorEntityId.Value, ref idReplacementTable);
* }
*/
if (motorBase != null)
{
// reattach motor/rotor to correct entity.
motorBase.RotorEntityId = MergeId(motorBase.RotorEntityId.Value, ref idReplacementTable);
if (motorBase.TopBlockId.HasValue)
motorBase.TopBlockId = MergeId(motorBase.TopBlockId.Value, ref idReplacementTable);
if (motorBase.RotorEntityId.HasValue)
motorBase.RotorEntityId = MergeId(motorBase.RotorEntityId.Value, ref idReplacementTable);
// Not sure whether this is necessary
if (motorBase.WeldedEntityId.HasValue)
motorBase.WeldedEntityId = MergeId(motorBase.WeldedEntityId.Value, ref idReplacementTable);
}

var pistonBase = cubeGrid as MyObjectBuilder_PistonBase;
Expand Down Expand Up @@ -880,11 +920,45 @@ private void MergeData(MyObjectBuilder_CubeGrid cubeGridObject, ref Dictionary<I
// reattach Ship Controller actions to correct entity.
RenumberToolbar(shipController.Toolbar, ref idReplacementTable);
}

var safeZoneBlock = cubeGrid as MyObjectBuilder_SafeZoneBlock;
if (safeZoneBlock != null)
{
// Also merge the component SafeZone of the Block
adjustSafeZoneBlock(safeZoneBlock, ref idReplacementTable);
}
}

AddEntity(cubeGridObject);
}

private void adjustSafeZoneBlock(MyObjectBuilder_SafeZoneBlock safeZoneBlock, ref Dictionary<Int64, Int64> idReplacementTable)
{
// re assign the ID which points to the seperate Safe-Zone Object.
safeZoneBlock.SafeZoneId = MergeId(safeZoneBlock.SafeZoneId, ref idReplacementTable);

if (safeZoneBlock.ComponentContainer?.Components != null)
{
foreach (var component in safeZoneBlock.ComponentContainer.Components)
{
//System.Diagnostics.Debug.WriteLine(component.Component.GetType().FullName);

var safeZoneComponent = component.Component as MyObjectBuilder_SafeZoneComponent;

if (safeZoneComponent != null && safeZoneComponent.SafeZoneOb != null)
{
MyObjectBuilder_SafeZone safeZoneUninitialzed = safeZoneComponent.SafeZoneOb as MyObjectBuilder_SafeZone;
if (safeZoneUninitialzed != null)
{
// We are still INSIDE the safeZone Block, it stores a copy of the seperate SafeZoneObject to later turn on/off the SafeZone.
safeZoneUninitialzed.EntityId = MergeId(safeZoneUninitialzed.EntityId, ref idReplacementTable);
safeZoneUninitialzed.SafeZoneBlockId = MergeId(safeZoneUninitialzed.SafeZoneBlockId, ref idReplacementTable);
}
}
}
}
}

private void RenumberToolbar(MyObjectBuilder_Toolbar toolbar, ref Dictionary<Int64, Int64> idReplacementTable)
{
if (toolbar == null)
Expand Down Expand Up @@ -1293,7 +1367,14 @@ public void BuildGridEntityNodes()
MyObjectBuilder_MechanicalConnectionBlock mechanicalConnection = block as MyObjectBuilder_MechanicalConnectionBlock;
if (mechanicalConnection != null)
{
gridEntityNode.CubeEntityNodes.Add(block.EntityId, new CubeEntityNode { GridConnectionType = GridConnectionType.Mechanical, EntityId = block.EntityId, Entity = block, RemoteEntityId = mechanicalConnection?.TopBlockId.Value ?? 0 });
gridEntityNode.CubeEntityNodes.Add(
block.EntityId,
new CubeEntityNode {
GridConnectionType = GridConnectionType.Mechanical,
EntityId = block.EntityId, Entity = block,
//RemoteEntityId = mechanicalConnection?.TopBlockId.Value ?? 0 // Fixed: This crashed if any Rotor had no attached TopBlock
RemoteEntityId = mechanicalConnection.TopBlockId.HasValue ? mechanicalConnection.TopBlockId.Value : 0
});
continue;
}

Expand Down Expand Up @@ -1358,8 +1439,8 @@ public void BuildGridEntityNodes()
MyObjectBuilder_MechanicalConnectionBlock mechanicalConnection = block as MyObjectBuilder_MechanicalConnectionBlock;
if (mechanicalConnection != null)
{
long topBlockId = mechanicalConnection?.TopBlockId.Value ?? 0;

//long topBlockId = mechanicalConnection?.TopBlockId?.Value ?? 0; // Fixed: This crashed if any Rotor had no attached TopBlock
long topBlockId = mechanicalConnection.TopBlockId.HasValue ? mechanicalConnection.TopBlockId.Value : 0;
foreach (var kvp in GridEntityNodes)
{
KeyValuePair<long, CubeEntityNode> node;
Expand Down
5 changes: 4 additions & 1 deletion SEToolbox/Models/StructureBaseModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -414,7 +414,10 @@ public static IStructureBase Create(MyObjectBuilder_EntityBase entityBase, strin
{
return new StructureInventoryBagModel(entityBase);
}

if (entityBase is MyObjectBuilder_SafeZone)
{
return new StructureSafeZoneModel(entityBase);
}
return new StructureUnknownModel(entityBase);
//throw new NotImplementedException(string.Format("A new object has not been catered for in the StructureBase, of type '{0}'.", entityBase.GetType()));
}
Expand Down
Loading