Skip to content

Commit

Permalink
Add component and tech for gravitational surveys
Browse files Browse the repository at this point in the history
Update JPSurveyableDB to use the same format as GeoSurveyableDB
  • Loading branch information
behindcurtain3 committed Mar 28, 2024
1 parent 43bfabf commit b1898cc
Show file tree
Hide file tree
Showing 8 changed files with 151 additions and 12 deletions.
7 changes: 5 additions & 2 deletions Pulsar4X/GameEngine/Atb/GeoSurveyAtb.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,14 @@ public void OnComponentUninstallation(Entity parentEntity, ComponentInstance com
{
if(parentEntity.TryGetDatablob<GeoSurveyAbilityDB>(out var geoSurveyAbilityDB))
{
geoSurveyAbilityDB.Speed -= Speed;
if(geoSurveyAbilityDB.Speed <= 0)
if(Speed >= geoSurveyAbilityDB.Speed)
{
parentEntity.RemoveDataBlob<GeoSurveyAbilityDB>();
}
else
{
geoSurveyAbilityDB.Speed -= Speed;
}
}
}

Expand Down
55 changes: 55 additions & 0 deletions Pulsar4X/GameEngine/Atb/GravSurveyAtb.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
using Newtonsoft.Json;
using Pulsar4X.Components;
using Pulsar4X.Datablobs;
using Pulsar4X.Engine;
using Pulsar4X.Interfaces;

namespace Pulsar4X.Atb;

public class GravSurveyAtb : IComponentDesignAttribute
{
[JsonProperty]
public uint Speed { get; set; } = 1;

public GravSurveyAtb(int speed)
{
Speed = (uint)speed;
}

public void OnComponentInstallation(Entity parentEntity, ComponentInstance componentInstance)
{
if(parentEntity.TryGetDatablob<GravSurveyAbilityDB>(out var gravSurveyAbilityDB))
{
gravSurveyAbilityDB.Speed += Speed;
}
else
{
parentEntity.SetDataBlob<GravSurveyAbilityDB>(new GravSurveyAbilityDB() { Speed = Speed });
}
}

public void OnComponentUninstallation(Entity parentEntity, ComponentInstance componentInstance)
{
if(parentEntity.TryGetDatablob<GravSurveyAbilityDB>(out var gravSurveyAbilityDB))
{
if(Speed >= gravSurveyAbilityDB.Speed)
{
parentEntity.RemoveDataBlob<GravSurveyAbilityDB>();
}
else
{
gravSurveyAbilityDB.Speed -= Speed;
}
}
}

public string AtbName()
{
return "Gravitational Surveyor";
}

public string AtbDescription()
{
return $"Speed {Speed}";
}
}
1 change: 1 addition & 0 deletions Pulsar4X/GameEngine/Data/basemod/defaultItems.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
"tech-modern-technology",
"tech-conventional-engine",
"tech-geo-surveyor",
"tech-gravitational-surveyor",
"stainless-steel-armor",
"plastic-armor",
"aluminium-armor",
Expand Down
53 changes: 53 additions & 0 deletions Pulsar4X/GameEngine/Data/basemod/electronics.json
Original file line number Diff line number Diff line change
Expand Up @@ -251,5 +251,58 @@
}
]
}
},
{
"Type": "ComponentTemplate",
"Payload": {
"UniqueID": "gravitational-surveyor",
"Name": "Gravitational Surveyor",
"Formulas": {
"Description": "Surveys gravatational anomalies",
"Mass": "Ability('Mass')",
"Volume": "Max(1, [Mass] * 0.1)",
"HTK": "[Mass]",
"CrewReq": "Pow(Ability('Survey Speed') * 2, 3)",
"ResearchCost": "Pow(Ability('Survey Speed'), 2)",
"CreditCost": "[Mass]",
"BuildPointCost": "[Mass]"
},
"ResourceCost": {
"iron": "[Mass]",
"copper": "[Mass]",
"aluminium": "[Mass]"
},
"ComponentType": "Science",
"MountType": "ShipComponent, ShipCargo",
"CargoTypeID": "general-storage",
"IndustryTypeID": "component-construction",
"Attributes":[
{
"Name": "Survey Speed",
"Units": "survey points per day",
"DescriptionFormula": "'Each point in speed provides one survey point per day'",
"GuiHint": "GuiSelectionMaxMinInt",
"GuidDictionary": {},
"MaxFormula": "10",
"MinFormula": "1",
"StepFormula": "1",
"AttributeFormula": "1"
},
{
"Name": "Mass",
"Units": "kg",
"DescriptionFormula": "'Mass Calculation'",
"GuiHint": "None",
"AttributeFormula": "Pow(10 * Ability('Survey Speed'), 2)"
},
{
"Name": "DBargs",
"GuiHint": "None",
"GuidDictionary": {},
"AttributeFormula": "AtbConstrArgs(Ability('Survey Speed'))",
"AttributeType": "Pulsar4X.Atb.GravSurveyAtb"
}
]
}
}
]
19 changes: 18 additions & 1 deletion Pulsar4X/GameEngine/Data/basemod/techs.json
Original file line number Diff line number Diff line change
Expand Up @@ -464,7 +464,7 @@
"UniqueID": "tech-geo-surveyor",
"Name": "Geological Surveyor",
"Description": "Research into geological surveys of system bodies",
"Category": "tech-category-biology-genetics",
"Category": "tech-category-designs",
"MaxLevel": 1,
"DataFormula": "(1 + [Level]) * 5000",
"CostFormula":"(1 + [Level]) * 500",
Expand All @@ -474,5 +474,22 @@
]
}
}
},
{
"Type": "Tech",
"Payload": {
"UniqueID": "tech-gravitational-surveyor",
"Name": "Gravitational Surveyor",
"Description": "Research into surveying gravitational anomalies",
"Category": "tech-category-designs",
"MaxLevel": 1,
"DataFormula": "(1 + [Level]) * 5000",
"CostFormula":"(1 + [Level]) * 500",
"Unlocks": {
"1": [
"gravitational-surveyor"
]
}
}
}
]
9 changes: 9 additions & 0 deletions Pulsar4X/GameEngine/Datablobs/GravSurveyAbilityDB.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
using Newtonsoft.Json;

namespace Pulsar4X.Datablobs;

public class GravSurveyAbilityDB : BaseDataBlob
{
[JsonProperty]
public uint Speed { get; set; }
}
16 changes: 8 additions & 8 deletions Pulsar4X/GameEngine/Datablobs/JPSurveyableDB.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using Newtonsoft.Json;
using System.Collections.Generic;
using System;
using Pulsar4X.Engine;
using Pulsar4X.DataStructures;

namespace Pulsar4X.Datablobs
{
Expand All @@ -20,9 +20,9 @@ namespace Pulsar4X.Datablobs
public class JPSurveyableDB : BaseDataBlob
{
[JsonProperty]
public int SurveyPointsRequired;
public uint PointsRequired;
[JsonProperty]
public Dictionary<Entity, int> SurveyPointsAccumulated;
public SafeDictionary<int, uint> SurveyPointsRemaining;
[JsonProperty]
public Entity? JumpPointTo;
[JsonProperty]
Expand All @@ -36,17 +36,17 @@ public class JPSurveyableDB : BaseDataBlob
public JPSurveyableDB() { }


public JPSurveyableDB(int pointsRequired, IDictionary<Entity, int> pointsAccumulated, double minimumDistanceToJump_m): this(pointsRequired, pointsAccumulated, null, String.Empty, minimumDistanceToJump_m){
public JPSurveyableDB(uint pointsRequired, SafeDictionary<int, uint> pointsAccumulated, double minimumDistanceToJump_m): this(pointsRequired, pointsAccumulated, null, String.Empty, minimumDistanceToJump_m){

}

/// <summary>
/// Copy constructor
/// </summary>
public JPSurveyableDB(int pointsRequired, IDictionary<Entity, int> pointsAccumulated, Entity? jumpPointTo, string systemToGuid, double minimumDistanceToJump_m)
public JPSurveyableDB(uint pointsRequired, SafeDictionary<int, uint> pointsAccumulated, Entity? jumpPointTo, string systemToGuid, double minimumDistanceToJump_m)
{
SurveyPointsRequired = pointsRequired;
SurveyPointsAccumulated = new Dictionary<Entity, int>(pointsAccumulated);
PointsRequired = pointsRequired;
SurveyPointsRemaining = new (pointsAccumulated);
JumpPointTo = jumpPointTo;
SystemToGuid = systemToGuid;
MinimumDistanceToJump_m = minimumDistanceToJump_m;
Expand All @@ -58,7 +58,7 @@ public JPSurveyableDB(int pointsRequired, IDictionary<Entity, int> pointsAccumul
/// <returns></returns>
public override object Clone()
{
return new JPSurveyableDB(SurveyPointsRequired, SurveyPointsAccumulated, JumpPointTo, SystemToGuid, MinimumDistanceToJump_m);
return new JPSurveyableDB(PointsRequired, SurveyPointsRemaining, JumpPointTo, SystemToGuid, MinimumDistanceToJump_m);
}
}
}
3 changes: 2 additions & 1 deletion Pulsar4X/GameEngine/Engine/Factories/JPSurveyFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using System.Collections.Generic;
using Pulsar4X.Orbital;
using Pulsar4X.Datablobs;
using Pulsar4X.DataStructures;

namespace Pulsar4X.Engine
{
Expand Down Expand Up @@ -57,7 +58,7 @@ private static ProtoEntity CreateSurveyPoint(double x, double y, int nameNumber)
// TODO: Load "pointsRequired" from GalaxyGen settings
const int pointsRequired = 400;

var surveyDB = new JPSurveyableDB(pointsRequired, new Dictionary<Entity, int>(), 10000000);
var surveyDB = new JPSurveyableDB(pointsRequired, new SafeDictionary<int, uint>(), 10000000);
var posDB = new PositionDB(x, y, 0, String.Empty);
var nameDB = new NameDB($"Survey Point #{nameNumber}");
//for testing purposes
Expand Down

0 comments on commit b1898cc

Please sign in to comment.