Skip to content
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

Resolves issue #381 #387

Merged
merged 3 commits into from
Nov 3, 2023
Merged
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
33 changes: 1 addition & 32 deletions Pulsar4X/GameEngine/Datablobs/AsteroidDamageDB.cs
Original file line number Diff line number Diff line change
@@ -1,15 +1,10 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Runtime.Serialization;
using Newtonsoft.Json;
using Pulsar4X.DataStructures;

namespace Pulsar4X.Datablobs
{
public class AsteroidDamageDB : BaseDataBlob, IEquatable<AsteroidDamageDB>
public class AsteroidDamageDB : BaseDataBlob
{
/// <summary>
/// Asteroids are damageable and need to store their health value.
Expand Down Expand Up @@ -58,31 +53,5 @@ public bool Equals(AsteroidDamageDB? other)
return true;
return _health == other._health && FractureChance.Equals(other.FractureChance);
}

public override bool Equals(object? obj)
{
if (ReferenceEquals(null, obj))
return false;
if (ReferenceEquals(this, obj))
return true;
if (obj.GetType() != this.GetType())
return false;
return Equals((AsteroidDamageDB)obj);
}

public override int GetHashCode()
{
return HashCode.Combine(_health, FractureChance);
}

public static bool operator ==(AsteroidDamageDB? left, AsteroidDamageDB? right)
{
return Equals(left, right);
}

public static bool operator !=(AsteroidDamageDB? left, AsteroidDamageDB? right)
{
return !Equals(left, right);
}
}
}
16 changes: 0 additions & 16 deletions Pulsar4X/GameEngine/Datablobs/AtmosphereDB.cs
Original file line number Diff line number Diff line change
Expand Up @@ -178,21 +178,5 @@ public override object Clone()
{
return new AtmosphereDB(this);
}

public override bool Equals(object? obj)
{
if(!base.Equals(obj)) return false;

AtmosphereDB other = (AtmosphereDB)obj;
if(this.Pressure != other.Pressure) return false;
if(this.Hydrosphere != other.Hydrosphere) return false;
if(this.HydrosphereExtent != other.HydrosphereExtent) return false;
if(this.GreenhouseFactor != other.GreenhouseFactor) return false;
if(this.GreenhousePressure != other.GreenhousePressure) return false;
if(this.SurfaceTemperature != other.SurfaceTemperature) return false;
if(!(this.Composition.Count == other.Composition.Count && !this.Composition.Except(other.Composition).Any())) return false;

return true;
}
}
}
7 changes: 1 addition & 6 deletions Pulsar4X/GameEngine/Datablobs/BaseDataBlob.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
namespace Pulsar4X.Datablobs
{
[JsonObject(MemberSerialization.OptIn)]
public abstract class BaseDataBlob : ICloneable, IEquatable<BaseDataBlob>
public abstract class BaseDataBlob : ICloneable
{
/// <summary>
/// This is the Entity which Owns/Conatains/IsParentOf this datablob
Expand Down Expand Up @@ -36,11 +36,6 @@ public bool Equals(BaseDataBlob? other)
}
}

public interface IGetValuesHash
{
int GetValueCompareHash(int hash = 17);
}

public interface IAbilityDescription
{
string AbilityName();
Expand Down
18 changes: 1 addition & 17 deletions Pulsar4X/GameEngine/Datablobs/FactionAbilitiesDB.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

namespace Pulsar4X.Datablobs
{
public class FactionAbilitiesDB : BaseDataBlob, IGetValuesHash
public class FactionAbilitiesDB : BaseDataBlob
{
public int BasePlanetarySensorStrength { get; set; }

Expand Down Expand Up @@ -72,21 +72,5 @@ public override object Clone()
{
return new FactionAbilitiesDB(this);
}

public int GetValueCompareHash(int hash = 17)
{

foreach (var item in AbilityBonuses)
{
hash = ObjectExtensions.ValueHash(item.Key, hash);
hash = ObjectExtensions.ValueHash(item.Value, hash);
}

hash = ObjectExtensions.ValueHash(BasePlanetarySensorStrength, hash);
hash = ObjectExtensions.ValueHash(BaseGroundUnitStrengthBonus, hash);
hash = ObjectExtensions.ValueHash(ColonyCostMultiplier, hash);
return hash;
}

}
}
48 changes: 1 addition & 47 deletions Pulsar4X/GameEngine/Datablobs/FactionInfoDB.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

namespace Pulsar4X.Datablobs
{
public class FactionInfoDB : BaseDataBlob, IGetValuesHash
public class FactionInfoDB : BaseDataBlob
{
[JsonProperty]
public FactionDataStore Data { get; internal set; } = new FactionDataStore();
Expand Down Expand Up @@ -149,51 +149,5 @@ void SetIndustryDesigns(
IndustryDesigns[design.Key] = design.Value;
}
}

[OnDeserialized]
public void OnDeserialized(StreamingContext context)
{
//((Game)context.Context).PostLoad += (sender, args) => { };
}

public int GetValueCompareHash(int hash = 17)
{
foreach (var item in Species)
{
hash = ObjectExtensions.ValueHash(item.Id, hash);
}
foreach (var item in KnownSystems)
{
hash = ObjectExtensions.ValueHash(item, hash);
}
foreach (var item in KnownFactions)
{
hash = ObjectExtensions.ValueHash(item.Id, hash);
}
foreach (var item in Colonies)
{
hash = ObjectExtensions.ValueHash(item.Id, hash);
}
foreach (var item in ShipDesigns.Keys)
{
hash = ObjectExtensions.ValueHash(item, hash);
}
foreach (var item in InternalComponentDesigns)
{
hash = ObjectExtensions.ValueHash(item.Key, hash);
hash = ObjectExtensions.ValueHash(item.Value.UniqueID, hash);
}
foreach (var system in InternalKnownJumpPoints)
{
hash = ObjectExtensions.ValueHash(system.Key, hash);
foreach (var jp in system.Value)
{
hash = ObjectExtensions.ValueHash(jp.Id, hash);
}

}

return hash;
}
}
}
12 changes: 1 addition & 11 deletions Pulsar4X/GameEngine/Datablobs/FactionOwnerDB.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

namespace Pulsar4X.Datablobs
{
public class FactionOwnerDB : BaseDataBlob, IGetValuesHash
public class FactionOwnerDB : BaseDataBlob
{
[JsonProperty]
internal Dictionary<int, Entity> OwnedEntities { get; set; } = new ();
Expand Down Expand Up @@ -45,15 +45,5 @@ public override object Clone()
{
return new FactionOwnerDB(this);
}

public int GetValueCompareHash(int hash = 17)
{
foreach (var item in OwnedEntities)
{
hash = ObjectExtensions.ValueHash(item.Key, hash);
}

return hash;
}
}
}
8 changes: 1 addition & 7 deletions Pulsar4X/GameEngine/Datablobs/FactionTechDB.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

namespace Pulsar4X.Datablobs
{
public class FactionTechDB : BaseDataBlob, IGetValuesHash
public class FactionTechDB : BaseDataBlob
{
[PublicAPI]
[JsonProperty]
Expand All @@ -25,11 +25,5 @@ public override object Clone()
{
return new FactionTechDB(this);
}

public int GetValueCompareHash(int hash = 17)
{
hash = ObjectExtensions.ValueHash(ResearchPoints, hash);
return hash;
}
}
}
8 changes: 1 addition & 7 deletions Pulsar4X/GameEngine/Datablobs/MassVolumeDB.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

namespace Pulsar4X.Datablobs
{
public class MassVolumeDB : BaseDataBlob, ISensorCloneMethod, IGetValuesHash
public class MassVolumeDB : BaseDataBlob, ISensorCloneMethod
{

/// <summary>
Expand Down Expand Up @@ -263,11 +263,5 @@ void Update(MassVolumeDB originalDB, SensorInfoDB sensorInfo)
RadiusInAU = originalDB.RadiusInAU;
Volume_km3 = originalDB.Volume_km3;
}

public int GetValueCompareHash(int hash = 17)
{
hash = ObjectExtensions.ValueHash(DensityDry_gcm, hash);
return hash;
}
}
}
12 changes: 1 addition & 11 deletions Pulsar4X/GameEngine/Datablobs/NameDB.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
namespace Pulsar4X.Datablobs
{
[DebuggerDisplay("{" + nameof(OwnersName) + "}")]
public class NameDB : BaseDataBlob, ISensorCloneMethod, IGetValuesHash
public class NameDB : BaseDataBlob, ISensorCloneMethod
{

/// <summary>
Expand Down Expand Up @@ -87,16 +87,6 @@ public BaseDataBlob SensorClone(SensorInfoDB sensorInfo)
return new NameDB(this, sensorInfo);
}

public int GetValueCompareHash(int hash = 17)
{
foreach (var item in _names)
{
hash = ObjectExtensions.ValueHash(item.Key, hash);
hash = ObjectExtensions.ValueHash(item.Value, hash);
}
return hash;
}

public void SensorUpdate(SensorInfoDB sensorInfo)
{
//do nothing for this.
Expand Down
12 changes: 1 addition & 11 deletions Pulsar4X/GameEngine/Datablobs/OrbitDB.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

namespace Pulsar4X.Datablobs
{
public class OrbitDB : TreeHierarchyDB, IGetValuesHash
public class OrbitDB : TreeHierarchyDB
{
public new static List<Type> GetDependencies() => new List<Type>() { typeof(PositionDB) };

Expand Down Expand Up @@ -548,16 +548,6 @@ void UpdateFromSensorInfo(OrbitDB actualDB, SensorInfoDB sensorInfo)
_myMass = actualDB._myMass;
CalculateExtendedParameters();
}

public int GetValueCompareHash(int hash = 17)
{
hash = ObjectExtensions.ValueHash(SemiMajorAxis, hash);
hash = ObjectExtensions.ValueHash(Eccentricity, hash);


return hash;
}

#endregion
}

Expand Down
8 changes: 1 addition & 7 deletions Pulsar4X/GameEngine/Datablobs/PositionDB.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ namespace Pulsar4X.Datablobs
{

//TODO: get rid of AU, why are we using AU.
public class PositionDB : TreeHierarchyDB, IGetValuesHash, IPosition
public class PositionDB : TreeHierarchyDB, IPosition
{

[JsonProperty]
Expand Down Expand Up @@ -154,11 +154,5 @@ public override object Clone()
{
return new PositionDB(this);
}

public int GetValueCompareHash(int hash = 17)
{
hash = ObjectExtensions.ValueHash(AbsolutePosition, hash);
return hash;
}
}
}
14 changes: 1 addition & 13 deletions Pulsar4X/GameEngine/Datablobs/SensorInfoDB.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ namespace Pulsar4X.Datablobs
/// This datablob goes into the sensor contact.
/// TODO: I can't see this actualy getting added to an entity anywhere, maybe it does not need to be a datablob.
/// </summary>
public class SensorInfoDB : BaseDataBlob, IGetValuesHash
public class SensorInfoDB : BaseDataBlob
{
[JsonProperty]
internal Entity Faction;
Expand Down Expand Up @@ -44,18 +44,6 @@ public override object Clone()
return new SensorInfoDB(this);
}

public int GetValueCompareHash(int hash = 17)
{
hash = ObjectExtensions.ValueHash(Faction, hash);
hash = ObjectExtensions.ValueHash(DetectedEntityID, hash);
hash = ObjectExtensions.ValueHash(SensorContact, hash);
hash = ObjectExtensions.ValueHash(LastDetection, hash);
hash = ObjectExtensions.ValueHash(LatestDetectionQuality, hash);
hash = ObjectExtensions.ValueHash(HighestDetectionQuality, hash);

return hash;
}

internal SensorInfoDB(SensorInfoDB db)
{
Faction = db.Faction;
Expand Down
18 changes: 1 addition & 17 deletions Pulsar4X/GameEngine/Datablobs/SystemBodyInfoDB.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ namespace Pulsar4X.Datablobs
/// <remarks>
/// Specifically, Minerals, body info, atmosphere info, and gravity.
/// </remarks>
public class SystemBodyInfoDB : BaseDataBlob, ISensorCloneMethod, IGetValuesHash
public class SystemBodyInfoDB : BaseDataBlob, ISensorCloneMethod
{
public new static List<Type> GetDependencies() => new List<Type>() { typeof(NameDB) };
/// <summary>
Expand Down Expand Up @@ -186,22 +186,6 @@ void UpdateDatablob(SystemBodyInfoDB originalDB, SensorInfoDB sensorInfo)
Colonies = new List<Entity>(originalDB.Colonies); //this needs to only have owned colonies and sensor entites of unowned colonies.
}

public int GetValueCompareHash(int hash = 17)
{
hash = ObjectExtensions.ValueHash(BodyType, hash);
hash = ObjectExtensions.ValueHash(Tectonics, hash);
hash = ObjectExtensions.ValueHash(AxialTilt, hash);
hash = ObjectExtensions.ValueHash(MagneticField, hash);
hash = ObjectExtensions.ValueHash(BaseTemperature, hash);
hash = ObjectExtensions.ValueHash(RadiationLevel, hash);
hash = ObjectExtensions.ValueHash(AtmosphericDust, hash);
hash = ObjectExtensions.ValueHash(SupportsPopulations, hash);
hash = ObjectExtensions.ValueHash(LengthOfDay, hash);
hash = ObjectExtensions.ValueHash(Gravity, hash);
//hash = ObjectExtensions.ValueHash(Minerals, hash); for some reason minerals were not hashing the same.
return hash;
}

SystemBodyInfoDB(SystemBodyInfoDB originalDB, SensorInfoDB sensorInfo)
{
UpdateDatablob(originalDB, sensorInfo);
Expand Down
Loading