Skip to content

Commit

Permalink
Merge branch 'mapver-901'
Browse files Browse the repository at this point in the history
  • Loading branch information
sk-zk committed Oct 11, 2024
2 parents c3d6126 + 0bef919 commit 54416fc
Show file tree
Hide file tree
Showing 21 changed files with 148 additions and 109 deletions.
3 changes: 1 addition & 2 deletions TruckLib/Models/Ppd/NavCurve.cs
Original file line number Diff line number Diff line change
Expand Up @@ -104,9 +104,8 @@ public void Deserialize(BinaryReader r, uint? version = null)
Deserialize15(r);
break;
case 0x16:
Deserialize16to18(r);
break;
case 0x17:
case 0x18:
Deserialize16to18(r);
break;
default:
Expand Down
8 changes: 4 additions & 4 deletions TruckLib/Models/Ppd/PrefabDescriptor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ private void Deserialize15(BinaryReader r)
NavCurves = r.ReadObjectList<NavCurve>(navCurveCount, version);
Signs = r.ReadObjectList<Sign>(signCount);
Semaphores = r.ReadObjectList<Semaphore>(semaphoreCount);
SpawnPoints = r.ReadObjectList<SpawnPoint>(spawnPointCount);
SpawnPoints = r.ReadObjectList<SpawnPoint>(spawnPointCount, version);
TerrainPointPositions = r.ReadObjectList<Vector3>(terrainPointCount);
TerrainPointNormals = r.ReadObjectList<Vector3>(terrainPointCount);
TerrainPointVariants = r.ReadObjectList<TerrainPointVariant>(terrainPointVariantCount);
Expand Down Expand Up @@ -152,7 +152,7 @@ private void Deserialize16(BinaryReader r)
NavCurves = r.ReadObjectList<NavCurve>(navCurveCount, version);
Signs = r.ReadObjectList<Sign>(signCount);
Semaphores = r.ReadObjectList<Semaphore>(semaphoreCount);
SpawnPoints = r.ReadObjectList<SpawnPoint>(spawnPointCount);
SpawnPoints = r.ReadObjectList<SpawnPoint>(spawnPointCount, version);
TerrainPointPositions = r.ReadObjectList<Vector3>(terrainPointCount);
TerrainPointNormals = r.ReadObjectList<Vector3>(terrainPointCount);
TerrainPointVariants = r.ReadObjectList<TerrainPointVariant>(terrainPointVariantCount);
Expand Down Expand Up @@ -195,7 +195,7 @@ private void Deserialize17(BinaryReader r)
NavCurves = r.ReadObjectList<NavCurve>(navCurveCount, version);
Signs = r.ReadObjectList<Sign>(signCount);
Semaphores = r.ReadObjectList<Semaphore>(semaphoreCount);
SpawnPoints = r.ReadObjectList<SpawnPoint>(spawnPointCount);
SpawnPoints = r.ReadObjectList<SpawnPoint>(spawnPointCount, version);
TerrainPointPositions = r.ReadObjectList<Vector3>(terrainPointCount);
TerrainPointNormals = r.ReadObjectList<Vector3>(terrainPointCount);
TerrainPointVariants = r.ReadObjectList<TerrainPointVariant>(terrainPointVariantCount);
Expand Down Expand Up @@ -238,7 +238,7 @@ private void Deserialize18(BinaryReader r)
NavCurves = r.ReadObjectList<NavCurve>(navCurveCount, version);
Signs = r.ReadObjectList<Sign>(signCount);
Semaphores = r.ReadObjectList<Semaphore>(semaphoreCount);
SpawnPoints = r.ReadObjectList<SpawnPoint>(spawnPointCount);
SpawnPoints = r.ReadObjectList<SpawnPoint>(spawnPointCount, version);
TerrainPointPositions = r.ReadObjectList<Vector3>(terrainPointCount);
TerrainPointNormals = r.ReadObjectList<Vector3>(terrainPointCount);
TerrainPointVariants = r.ReadObjectList<TerrainPointVariant>(terrainPointVariantCount);
Expand Down
28 changes: 28 additions & 0 deletions TruckLib/Models/Ppd/SpawnPoint.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,46 @@ public class SpawnPoint : IBinarySerializable

public SpawnPointType Type { get; set; }

public uint Unknown { get; set; }

public void Deserialize(BinaryReader r, uint? version = null)
{
switch (version)
{
case 0x15:
case 0x16:
case 0x17:
Deserialize15to17(r);
break;
case 0x18:
Deserialize18(r);
break;
default:
throw new NotSupportedException($"Version {version} is not supported.");
}
}

private void Deserialize15to17(BinaryReader r)
{
Position = r.ReadVector3();
Rotation = r.ReadQuaternion();
Type = (SpawnPointType)r.ReadUInt32();
}

private void Deserialize18(BinaryReader r)
{
Position = r.ReadVector3();
Rotation = r.ReadQuaternion();
Type = (SpawnPointType)r.ReadUInt32();
Unknown = r.ReadUInt32();
}

public void Serialize(BinaryWriter w)
{
w.Write(Position);
w.Write(Rotation);
w.Write((uint)Type);
w.Write(Unknown);
}
}
}
2 changes: 1 addition & 1 deletion TruckLib/ScsMap/CameraPath.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public class CameraPath : PathItem
public override ItemFile DefaultItemFile => ItemFile.Aux;

/// <inheritdoc/>
protected override ushort DefaultViewDistance => KdopItem.ViewDistanceFar;
protected override ushort DefaultViewDistance => KdopItem.ViewDistanceExtremelyFar;

/// <summary>
/// Tags of this item.
Expand Down
2 changes: 1 addition & 1 deletion TruckLib/ScsMap/CityArea.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public class CityArea : SingleNodeItem
public override ItemFile DefaultItemFile => ItemFile.Base;

/// <inheritdoc/>
protected override ushort DefaultViewDistance => KdopItem.ViewDistanceFar;
protected override ushort DefaultViewDistance => KdopItem.ViewDistanceExtremelyFar;

/// <summary>
/// The unit name of the city, as defined in <c>/def/city.sii</c>.
Expand Down
2 changes: 1 addition & 1 deletion TruckLib/ScsMap/Cutscene.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public class Cutscene : SingleNodeItem
public override ItemFile DefaultItemFile => ItemFile.Base;

/// <inheritdoc/>
protected override ushort DefaultViewDistance => KdopItem.ViewDistanceFar;
protected override ushort DefaultViewDistance => KdopItem.ViewDistanceExtremelyFar;

/// <summary>
/// Tags of the item.
Expand Down
4 changes: 2 additions & 2 deletions TruckLib/ScsMap/EdgeOverride.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,14 @@ public struct EdgeOverride : IBinarySerializable

/// <summary>
/// Offset of the section at which the override begins, counted in forward direction.
/// <remarks>One section spans three road quads.</remarks>
/// </summary>
/// <remarks>One section spans three road quads.</remarks>
public ushort Offset { get; set; }

/// <summary>
/// Number of sections for which the override will repeat.
/// <remarks>One section spans three road quads.</remarks>
/// </summary>
/// <remarks>One section spans three road quads.</remarks>
public ushort Length { get; set; }

/// <summary>
Expand Down
31 changes: 2 additions & 29 deletions TruckLib/ScsMap/Enums.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public enum ItemType
Service = 0x07,
CutPlane = 0x08,
Mover = 0x09,
NoWeatherArea = 0x0B,
EnvironmentArea = 0x0B,
CityArea = 0x0C,
Hinge = 0x0D,
AnimatedModel = 0x0F,
Expand Down Expand Up @@ -205,33 +205,6 @@ public enum MapAreaType
Navigation = 1
}

/// <summary>
/// The color of a <see cref="MapArea">Map Area</see>.
/// </summary>
public enum MapAreaColor
{
/// <summary>
/// The map area has the same color as roads.
/// </summary>
Road = 0,

/// <summary>
/// The map area is lighter than roads.
/// </summary>
Light = 1,

/// <summary>
/// The map area is darker than roads.
/// </summary>
Dark = 2,

/// <summary>
/// The map area has the same color as <see cref="MapAreaColor.Light">Light</see>
/// if undiscovered but is green once discovered.
/// </summary>
Green = 3
}

/// <summary>
/// The spawn point type of a <see cref="Service"/> item.
/// </summary>
Expand Down Expand Up @@ -316,7 +289,7 @@ public enum EasingFunction
}

/// <summary>
/// Fog behavior in a <see cref="NoWeatherArea">No Weather Area</see>.
/// Fog behavior in a <see cref="EnvironmentArea">No Weather Area</see>.
/// </summary>
public enum FogMask
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@
namespace TruckLib.ScsMap
{
/// <summary>
/// Defines a rectangular area in which weather effects are disabled.
/// Defines a rectangular area in which
/// </summary>
public class NoWeatherArea : SingleNodeItem
public class EnvironmentArea : SingleNodeItem
{
/// <inheritdoc/>
public override ItemType ItemType => ItemType.NoWeatherArea;
public override ItemType ItemType => ItemType.EnvironmentArea;

/// <inheritdoc/>
public override ItemFile DefaultItemFile => ItemFile.Aux;
Expand All @@ -34,9 +34,25 @@ public class NoWeatherArea : SingleNodeItem

public FogMask FogBehavior { get; set; }

public NoWeatherArea() : base() { }
/// <summary>
/// Unit name of the climate profile, as defined in <c>/def/climate.sii</c>.
/// </summary>
public Token Climate { get; set; }

/// <summary>
/// Unit name of the reflection cube, as defined in <c>/def/relightable_cubemaps.sii</c>(?).
/// </summary>
public Token ReflectionCube { get; set; }

public bool Precipitation
{
get => !Kdop.Flags[0];
set => Kdop.Flags[0] = !value;
}

public EnvironmentArea() : base() { }

internal NoWeatherArea(bool initFields) : base(initFields)
internal EnvironmentArea(bool initFields) : base(initFields)
{
if (initFields) Init();
}
Expand All @@ -45,24 +61,26 @@ internal NoWeatherArea(bool initFields) : base(initFields)
protected override void Init()
{
base.Init();
Width = 200;
Height = 200;
}

/// <summary>
/// Adds a NoWeatherArea to the map.
/// Adds an environment area to the map.
/// </summary>
/// <param name="map">The map.</param>
/// <param name="position">The position of the center of the area.</param>
/// <param name="width">The width of the area.</param>
/// <param name="height">The height of the area.</param>
/// <returns>The newly created NoWeatherArea.</returns>
public static NoWeatherArea Add(IItemContainer map, Vector3 position, float width, float height)
/// <returns>The newly created environment area.</returns>
public static EnvironmentArea Add(IItemContainer map, Vector3 position, float width, float height)
{
var nwa = Add<NoWeatherArea>(map, position);
var ea = Add<EnvironmentArea>(map, position);

nwa.Width = width;
nwa.Height = height;
ea.Width = width;
ea.Height = height;

return nwa;
return ea;
}
}
}
9 changes: 9 additions & 0 deletions TruckLib/ScsMap/FarModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,15 @@ public bool UseMapItems
set => Kdop.Flags[1] = value;
}

/// <summary>
/// Gets or sets whether far shadows will be rendered.
/// </summary>
public bool FarShadows
{
get => Kdop.Flags[2];
set => Kdop.Flags[2] = value;
}

public FarModel() : base()
{
}
Expand Down
2 changes: 1 addition & 1 deletion TruckLib/ScsMap/Header.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ namespace TruckLib.ScsMap
/// </summary>
public class Header : IBinarySerializable
{
private const int supportedVersion = 900;
private const int supportedVersion = 901;
/// <summary>
/// Version number of the map format.
/// </summary>
Expand Down
11 changes: 7 additions & 4 deletions TruckLib/ScsMap/KdopItem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ internal class KdopItem : KdopBounds
// The editor only lets you go up to 1500, but there are items in europe.mbd that exceed it.
// Not sure if this is intentional and the game actually renders it like that, or if someone somehow
// set those values by accident and the game caps them to 1500 again when loaded
private const ushort MaxDistance = 2100;
private const ushort MaxDistance = 2120;
private ushort viewDistance = ViewDistanceClose;
/// <summary>
/// Gets or sets the view distance of an item in meters.
Expand All @@ -42,10 +42,13 @@ public ushort ViewDistance
}

// preset vals from the editor
public const ushort ViewDistanceShort = 120;
public const ushort ViewDistanceExtremelyShort = 80;
public const ushort ViewDistanceVeryShort = 120;
public const ushort ViewDistanceShort = 200;
public const ushort ViewDistanceClose = 400;
public const ushort ViewDistanceMiddle = 950;
public const ushort ViewDistanceFar = 1400;
public const ushort ViewDistanceMiddle = 600;
public const ushort ViewDistanceFar = 900;
public const ushort ViewDistanceExtremelyFar = 1400;

public KdopItem() : base() { }

Expand Down
8 changes: 4 additions & 4 deletions TruckLib/ScsMap/MapArea.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
namespace TruckLib.ScsMap
{
/// <summary>
/// Draws a polygon onto the UI map.
/// Defines a polygon which is drawn onto the UI map.
/// </summary>
public class MapArea : PolygonItem
{
Expand All @@ -33,9 +33,10 @@ public MapAreaType Type
}

/// <summary>
/// The color of the map area.
/// The color of the map area, as an index for the <c>map_area_*</c> arrays
/// defined in <c>/def/map_data.sii</c>.
/// </summary>
public MapAreaColor Color { get; set; }
public uint Color { get; set; }

public byte DlcGuard
{
Expand Down Expand Up @@ -81,7 +82,6 @@ internal MapArea(bool initFields) : base(initFields)
protected override void Init()
{
base.Init();
Color = MapAreaColor.Road;
}

/// <summary>
Expand Down
2 changes: 1 addition & 1 deletion TruckLib/ScsMap/Prefab.cs
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,7 @@ public static Prefab Add(IItemContainer map, Vector3 position, Token unitName,

/// <summary>
/// Appends a new road segment to a node of this prefab.
/// <remarks>If the node is the origin node, it will be prepended instead.</remarks>
/// (If the node is the origin node, it will be prepended instead.)
/// </summary>
/// <param name="node">The index of the prefab node
/// (in <see cref="Nodes"/>, not the .ppd file) to attach to.</param>
Expand Down
39 changes: 39 additions & 0 deletions TruckLib/ScsMap/Serialization/EnvironmentAreaSerializer.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Text;

namespace TruckLib.ScsMap.Serialization
{
class EnvironmentAreaSerializer : MapItemSerializer
{
private const float sizeFactor = 2f;

public override MapItem Deserialize(BinaryReader r)
{
var ea = new EnvironmentArea(false);
ReadKdopItem(r, ea);

ea.Width = r.ReadSingle() * sizeFactor;
ea.Height = r.ReadSingle() * sizeFactor;
ea.FogBehavior = (FogMask)r.ReadInt32();
ea.Climate = r.ReadToken();
ea.ReflectionCube = r.ReadToken();
ea.Node = new UnresolvedNode(r.ReadUInt64());

return ea;
}

public override void Serialize(BinaryWriter w, MapItem item)
{
var ea = item as EnvironmentArea;
WriteKdopItem(w, ea);
w.Write(ea.Width / sizeFactor);
w.Write(ea.Height / sizeFactor);
w.Write((int)ea.FogBehavior);
w.Write(ea.Climate);
w.Write(ea.ReflectionCube);
w.Write(ea.Node.Uid);
}
}
}
Loading

0 comments on commit 54416fc

Please sign in to comment.