Skip to content

Commit

Permalink
Merge pull request #454 from kremnev8/master
Browse files Browse the repository at this point in the history
Improve compatibility with GigaStations mod
  • Loading branch information
PhantomGamers authored Sep 29, 2021
2 parents 6d5dc41 + 6cd0ab8 commit 7e52caa
Show file tree
Hide file tree
Showing 14 changed files with 172 additions and 135 deletions.
6 changes: 5 additions & 1 deletion NebulaModel/Packets/Logistics/ILSAddStationComponent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,16 @@ public class ILSAddStationComponent
public int PlanetId { get; set; }
public int StationId { get; set; }
public int StationGId { get; set; }

public int MaxShipCount { get; set; }

public ILSAddStationComponent() { }
public ILSAddStationComponent(int planetId, int stationId, int stationGId)
public ILSAddStationComponent(int planetId, int stationId, int stationGId, int maxShipCount)
{
StationGId = stationGId;
PlanetId = planetId;
StationId = stationId;
MaxShipCount = maxShipCount;
}
}
}
4 changes: 4 additions & 0 deletions NebulaModel/Packets/Logistics/ILSArriveStarPlanetResponse.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ namespace NebulaModel.Packets.Logistics
public class ILSArriveStarPlanetResponse
{
public int[] StationGId { get; set; }

public int[] StationMaxShips { get; set; }
public int[] PlanetId { get; set; }
public int Planet { get; set; }
public int[] StorageLength { get; set; }
Expand All @@ -19,6 +21,7 @@ public class ILSArriveStarPlanetResponse
public int[] RemoteLogic { get; set; }
public ILSArriveStarPlanetResponse() { }
public ILSArriveStarPlanetResponse(int[] stationGId,
int[] stationMaxShips,
int[] planetId,
int planet,
int[] storageLength,
Expand All @@ -32,6 +35,7 @@ public ILSArriveStarPlanetResponse(int[] stationGId,
int[] remoteLogic)
{
StationGId = stationGId;
StationMaxShips = stationMaxShips;
PlanetId = planetId;
Planet = planet;
StorageLength = storageLength;
Expand Down
23 changes: 17 additions & 6 deletions NebulaModel/Packets/Logistics/ILSShipData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,24 +8,33 @@ public class ILSShipData
public int itemId { get; set; }
public int itemCount { get; set; }
public int planetAStationGID { get; set; }

public int planetAStationMaxShipCount { get; set; }
public int planetBStationGID { get; set; }

public int planetBStationMaxShipCount { get; set; }
public int origShipIndex { get; set; }
public int warperCnt { get; set; }
public int stationWarperCnt { get; set; }

public ILSShipData() { }
public ILSShipData(bool IdleToWork, int planetA, int planetB, int itemId, int itemCount, int AGID, int BGID, int origShipIndex, int warperCnt, int stationWarperCnt)
public ILSShipData(bool IdleToWork, ShipData ship, int AGID, int aMaxShipCount, int BGID, int bMaxShipCount, int origShipIndex, int stationWarperCnt)
{
idleToWork = IdleToWork;
this.planetA = planetA;
this.planetB = planetB;
this.itemId = itemId;
this.itemCount = itemCount;
planetA = ship.planetA;
planetB = ship.planetB;
itemId = ship.itemId;
itemCount = ship.itemCount;
warperCnt = ship.warperCnt;

planetAStationGID = AGID;
planetBStationGID = BGID;
planetAStationMaxShipCount = aMaxShipCount;
planetBStationMaxShipCount = bMaxShipCount;

this.origShipIndex = origShipIndex;
this.warperCnt = warperCnt;
this.stationWarperCnt = stationWarperCnt;

}
public ILSShipData(bool IdleToWork, int AGID, int origShipIndex)
{
Expand All @@ -36,6 +45,8 @@ public ILSShipData(bool IdleToWork, int AGID, int origShipIndex)
itemCount = 0;
planetAStationGID = AGID;
planetBStationGID = 0;
planetAStationMaxShipCount = 10;
planetBStationMaxShipCount = 10;
this.origShipIndex = origShipIndex;
warperCnt = 0;
}
Expand Down
7 changes: 4 additions & 3 deletions NebulaModel/Packets/Logistics/ILSgStationPoolSync.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ namespace NebulaModel.Packets.Logistics
public class ILSgStationPoolSync
{
public int[] stationGId { get; set; }

public int[] stationMaxShipCount { get; set; }
public int[] stationId { get; set; }
public Float3[] DockPos { get; set; }
public Float4[] DockRot { get; set; }
Expand All @@ -15,7 +17,6 @@ public class ILSgStationPoolSync
public int[] idleShipCount { get; set; }
public ulong[] workShipIndices { get; set; }
public ulong[] idleShipIndices { get; set; }
public int[] shipStationGId { get; set; }
public int[] shipStage { get; set; }
public int[] shipDirection { get; set; }
public float[] shipWarpState { get; set; }
Expand All @@ -37,6 +38,7 @@ public class ILSgStationPoolSync

public ILSgStationPoolSync() { }
public ILSgStationPoolSync(int[] stationGId,
int[] stationMaxShipCount,
int[] stationId,
Float3[] DockPos,
Float4[] DockRot,
Expand All @@ -45,7 +47,6 @@ public ILSgStationPoolSync(int[] stationGId,
int[] idleShipCount,
ulong[] workShipIndices,
ulong[] idleShipIndices,
int[] shipStationGId,
int[] shipStage,
int[] shipDirection,
float[] shipWarpState,
Expand All @@ -66,6 +67,7 @@ public ILSgStationPoolSync(int[] stationGId,
Float4[] shipPRotTemp)
{
this.stationGId = stationGId;
this.stationMaxShipCount = stationMaxShipCount;
this.stationId = stationId;
this.DockPos = DockPos;
this.DockRot = DockRot;
Expand All @@ -74,7 +76,6 @@ public ILSgStationPoolSync(int[] stationGId,
this.idleShipCount = idleShipCount;
this.workShipIndices = workShipIndices;
this.idleShipIndices = idleShipIndices;
this.shipStationGId = shipStationGId;
this.shipStage = shipStage;
this.shipDirection = shipDirection;
this.shipWarpState = shipWarpState;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public override void ProcessPacket(ILSAddStationComponent packet, NebulaConnecti
{
// If we're not on the same planet as the new station was create on, we need to create a
// "fake" station that we can put into the GalacticTransport.stationPool instead of a real on
Multiplayer.Session.Ships.CreateFakeStationComponent(packet.StationGId, packet.PlanetId, true);
Multiplayer.Session.Ships.CreateFakeStationComponent(packet.StationGId, packet.PlanetId, packet.MaxShipCount);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ public override void ProcessPacket(ILSArriveStarPlanetRequest packet, NebulaConn
if (player != null)
{
List<int> stationGId = new List<int>();
List<int> stationMaxShips = new List<int>();
List<int> storageLength = new List<int>();
int arraySize = 0;
int offset = 0;
Expand All @@ -46,6 +47,7 @@ public override void ProcessPacket(ILSArriveStarPlanetRequest packet, NebulaConn
if (stationComponent != null && GameMain.galaxy.PlanetById(stationComponent.planetId)?.star.id == packet.StarId)
{
stationGId.Add(stationComponent.gid);
stationMaxShips.Add(stationComponent.workShipDatas.Length);
storageLength.Add(stationComponent.storage.Length);
}
}
Expand All @@ -60,6 +62,7 @@ public override void ProcessPacket(ILSArriveStarPlanetRequest packet, NebulaConn
if (stationComponent != null)
{
stationGId.Add(stationComponent.gid);
stationMaxShips.Add(stationComponent.workShipDatas.Length);
storageLength.Add(stationComponent.storage.Length);
}
}
Expand Down Expand Up @@ -115,6 +118,7 @@ public override void ProcessPacket(ILSArriveStarPlanetRequest packet, NebulaConn
}

player.SendPacket(new ILSArriveStarPlanetResponse(stationGId.ToArray(),
stationMaxShips.ToArray(),
planetId,
(packet.PlanetId == 0) ? 0 : packet.PlanetId,
storageLength.ToArray(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public override void ProcessPacket(ILSArriveStarPlanetResponse packet, NebulaCon
{
if (packet.StationGId[i] >= gStationPool.Length || gStationPool[packet.StationGId[i]] == null)
{
Multiplayer.Session.Ships.CreateFakeStationComponent(packet.StationGId[i], packet.PlanetId[i]);
Multiplayer.Session.Ships.CreateFakeStationComponent(packet.StationGId[i], packet.PlanetId[i], packet.StationMaxShips[i]);
}

StationComponent stationComponent = gStationPool[packet.StationGId[i]];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,12 @@ public override void ProcessPacket(ILSShipDock packet, NebulaConnection conn)
stationComponent.shipDockPos = packet.shipDockPos.ToVector3();
stationComponent.shipDockRot = packet.shipDockRot.ToQuaternion();

for (int i = 0; i < Multiplayer.Session.Ships.ILSMaxShipCount; i++)
for (int i = 0; i < stationComponent.workShipDatas.Length; i++)
{
stationComponent.shipDiskRot[i] = Quaternion.Euler(0f, 360f / Multiplayer.Session.Ships.ILSMaxShipCount * i, 0f);
stationComponent.shipDiskRot[i] = Quaternion.Euler(0f, 360f / stationComponent.workShipDatas.Length * i, 0f);
stationComponent.shipDiskPos[i] = stationComponent.shipDiskRot[i] * new Vector3(0f, 0f, 11.5f);
}
for (int j = 0; j < Multiplayer.Session.Ships.ILSMaxShipCount; j++)
for (int j = 0; j < stationComponent.workShipDatas.Length; j++)
{
stationComponent.shipDiskRot[j] = stationComponent.shipDockRot * stationComponent.shipDiskRot[j];
stationComponent.shipDiskPos[j] = stationComponent.shipDockPos + stationComponent.shipDockRot * stationComponent.shipDiskPos[j];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,11 @@ public override void ProcessPacket(ILSgStationPoolSync packet, NebulaConnection
GalacticTransport gTransport = GameMain.data.galacticTransport;
StationComponent[] gStationPool = GameMain.data.galacticTransport.stationPool;

int arrayStartPos = 0;

for (int i = 0; i < packet.stationGId.Length; i++)
{
Multiplayer.Session.Ships.CreateFakeStationComponent(packet.stationGId[i], packet.planetId[i], false); // handles array resizing
Multiplayer.Session.Ships.CreateFakeStationComponent(packet.stationGId[i], packet.planetId[i], packet.stationMaxShipCount[i], false); // handles array resizing
gStationPool = GameMain.data.galacticTransport.stationPool; // dont remove or you get an ArrayOutOfBounds

gStationPool[packet.stationGId[i]].shipDockPos = packet.DockPos[i].ToVector3();
Expand All @@ -35,51 +37,52 @@ public override void ProcessPacket(ILSgStationPoolSync packet, NebulaConnection
gStationPool[packet.stationGId[i]].idleShipCount = packet.idleShipCount[i];
gStationPool[packet.stationGId[i]].workShipIndices = packet.workShipIndices[i];
gStationPool[packet.stationGId[i]].idleShipIndices = packet.idleShipIndices[i];
gStationPool[packet.stationGId[i]].shipRenderers = new ShipRenderingData[Multiplayer.Session.Ships.ILSMaxShipCount];
gStationPool[packet.stationGId[i]].shipUIRenderers = new ShipUIRenderingData[Multiplayer.Session.Ships.ILSMaxShipCount];
gStationPool[packet.stationGId[i]].shipRenderers = new ShipRenderingData[packet.stationMaxShipCount[i]];
gStationPool[packet.stationGId[i]].shipUIRenderers = new ShipUIRenderingData[packet.stationMaxShipCount[i]];

gStationPool[packet.stationGId[i]].shipDiskPos = new Vector3[Multiplayer.Session.Ships.ILSMaxShipCount];
gStationPool[packet.stationGId[i]].shipDiskRot = new Quaternion[Multiplayer.Session.Ships.ILSMaxShipCount];
gStationPool[packet.stationGId[i]].shipDiskPos = new Vector3[packet.stationMaxShipCount[i]];
gStationPool[packet.stationGId[i]].shipDiskRot = new Quaternion[packet.stationMaxShipCount[i]];

// theese are the individual landing places for the ships on the station's disk at the top
for (int j = 0; j < Multiplayer.Session.Ships.ILSMaxShipCount; j++)
// these are the individual landing places for the ships on the station's disk at the top
for (int j = 0; j < packet.stationMaxShipCount[i]; j++)
{
gStationPool[packet.stationGId[i]].shipDiskRot[j] = Quaternion.Euler(0f, 360f / Multiplayer.Session.Ships.ILSMaxShipCount * j, 0f);
gStationPool[packet.stationGId[i]].shipDiskRot[j] = Quaternion.Euler(0f, 360f / packet.stationMaxShipCount[i] * j, 0f);
gStationPool[packet.stationGId[i]].shipDiskPos[j] = gStationPool[packet.stationGId[i]].shipDiskRot[j] * new Vector3(0f, 0f, 11.5f);
}
for (int j = 0; j < Multiplayer.Session.Ships.ILSMaxShipCount; j++)
for (int j = 0; j < packet.stationMaxShipCount[i]; j++)
{
gStationPool[packet.stationGId[i]].shipDiskRot[j] = gStationPool[packet.stationGId[i]].shipDockRot * gStationPool[packet.stationGId[i]].shipDiskRot[j];
gStationPool[packet.stationGId[i]].shipDiskPos[j] = gStationPool[packet.stationGId[i]].shipDockPos + gStationPool[packet.stationGId[i]].shipDockRot * gStationPool[packet.stationGId[i]].shipDiskPos[j];
}
}

for (int j = 0; j < packet.stationMaxShipCount[i]; j++)
{
int index = arrayStartPos + j;
ShipData shipData = gStationPool[packet.stationGId[i]].workShipDatas[j];
shipData.stage = packet.shipStage[index];
shipData.direction = packet.shipDirection[index];
shipData.warpState = packet.shipWarpState[index];
shipData.warperCnt = packet.shipWarperCnt[index];
shipData.itemId = packet.shipItemID[index];
shipData.itemCount = packet.shipItemCount[index];
shipData.planetA = packet.shipPlanetA[index];
shipData.planetB = packet.shipPlanetB[index];
shipData.otherGId = packet.shipOtherGId[index];
shipData.t = packet.shipT[index];
shipData.shipIndex = packet.shipIndex[index];

// thanks Baldy for the fix :D
// nearly lost all my hairs because of it
for (int i = 0; i < packet.shipStationGId.Length; i++)
{
ShipData shipData = gStationPool[packet.shipStationGId[i]].workShipDatas[i % Multiplayer.Session.Ships.ILSMaxShipCount];
shipData.stage = packet.shipStage[i];
shipData.direction = packet.shipDirection[i];
shipData.warpState = packet.shipWarpState[i];
shipData.warperCnt = packet.shipWarperCnt[i];
shipData.itemId = packet.shipItemID[i];
shipData.itemCount = packet.shipItemCount[i];
shipData.planetA = packet.shipPlanetA[i];
shipData.planetB = packet.shipPlanetB[i];
shipData.otherGId = packet.shipOtherGId[i];
shipData.t = packet.shipT[i];
shipData.shipIndex = packet.shipIndex[i];
shipData.uPos = packet.shipPos[index].ToVectorLF3();
shipData.uRot = packet.shipRot[index].ToQuaternion();
shipData.uVel = packet.shipVel[index].ToVector3();
shipData.uSpeed = packet.shipSpeed[index];
shipData.uAngularVel = packet.shipAngularVel[index].ToVector3();
shipData.pPosTemp = packet.shipPPosTemp[index].ToVectorLF3();
shipData.pRotTemp = packet.shipRot[index].ToQuaternion();

shipData.uPos = packet.shipPos[i].ToVectorLF3();
shipData.uRot = packet.shipRot[i].ToQuaternion();
shipData.uVel = packet.shipVel[i].ToVector3();
shipData.uSpeed = packet.shipSpeed[i];
shipData.uAngularVel = packet.shipAngularVel[i].ToVector3();
shipData.pPosTemp = packet.shipPPosTemp[i].ToVectorLF3();
shipData.pRotTemp = packet.shipRot[i].ToQuaternion();
gStationPool[packet.stationGId[i]].workShipDatas[j] = shipData;
}

gStationPool[packet.shipStationGId[i]].workShipDatas[i % Multiplayer.Session.Ships.ILSMaxShipCount] = shipData;
arrayStartPos += packet.stationMaxShipCount[i];
}

gTransport.Arragement();
Expand Down
Loading

0 comments on commit 7e52caa

Please sign in to comment.