Skip to content

Commit

Permalink
Can now create colonies on suitable bodies that have been geo-surveyed
Browse files Browse the repository at this point in the history
  • Loading branch information
behindcurtain3 committed Mar 29, 2024
1 parent 7ed220a commit 84dd836
Show file tree
Hide file tree
Showing 14 changed files with 139 additions and 82 deletions.
3 changes: 1 addition & 2 deletions .vscode/tasks.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,7 @@
"reveal": "always",
"focus": false,
"panel": "shared"
},
"problemMatcher": []
}
}
]
}
8 changes: 8 additions & 0 deletions Pulsar4X/GameEngine/Datablobs/ColonizeableDB.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
namespace Pulsar4X.Datablobs;

/// <summary>
/// Empty class, used as a tag
/// </summary>
public class ColonizeableDB : BaseDataBlob
{
}
13 changes: 0 additions & 13 deletions Pulsar4X/GameEngine/Datablobs/SystemBodyInfoDB.cs
Original file line number Diff line number Diff line change
Expand Up @@ -92,18 +92,6 @@ public class SystemBodyInfoDB : BaseDataBlob, ISensorCloneMethod
[JsonProperty]
public bool SupportsPopulations { get; internal set; }

/// <summary>
/// List of Colonies that reside on this body.
/// </summary>
/// <remarks>
/// TODO: Entity Review
/// We may want to remove this list and use PositionDB to link colonies to bodies.
/// NOTE: Not currently used?
/// </remarks>
[PublicAPI]
[JsonProperty]
public List<Entity> Colonies { get; internal set; } = new List<Entity>();

/// <summary>
/// Length of day for this body. Mostly fluff.
/// </summary>
Expand Down Expand Up @@ -183,7 +171,6 @@ void UpdateDatablob(SystemBodyInfoDB originalDB, SensorInfoDB sensorInfo)
SupportsPopulations = originalDB.SupportsPopulations;
LengthOfDay = originalDB.LengthOfDay;
Gravity = originalDB.Gravity;
Colonies = new List<Entity>(originalDB.Colonies); //this needs to only have owned colonies and sensor entites of unowned colonies.
}

SystemBodyInfoDB(SystemBodyInfoDB originalDB, SensorInfoDB sensorInfo)
Expand Down
38 changes: 12 additions & 26 deletions Pulsar4X/GameEngine/Engine/Factories/ColonyFactory.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
using System;
using System.Collections.Generic;
using Pulsar4X.Orbital;
using Pulsar4X.Datablobs;
Expand All @@ -10,46 +9,33 @@ public static class ColonyFactory
/// <summary>
/// Creates a new colony with zero population unless specified.
/// </summary>
/// <param name="systemEntityManager"></param>
/// <param name="factionEntity"></param>
/// <returns></returns>
public static Entity CreateColony(Entity factionEntity, Entity speciesEntity, Entity planetEntity, long initialPopulation = 0)
{
List<BaseDataBlob> blobs = new List<BaseDataBlob>();
var blobs = new List<BaseDataBlob>();

string planetName = planetEntity.GetDataBlob<NameDB>().GetName(factionEntity.Id);
NameDB name = new NameDB(planetName + " Colony"); // TODO: Review default name.
name.SetName(factionEntity.Id, name.DefaultName);

blobs.Add(name);
ColonyInfoDB colonyInfoDB = new ColonyInfoDB(speciesEntity, initialPopulation, planetEntity);
blobs.Add(colonyInfoDB);
ColonyBonusesDB colonyBonuses = new ColonyBonusesDB();
blobs.Add(colonyBonuses);
MiningDB colonyMinesDB = new MiningDB();
blobs.Add(colonyMinesDB);
OrderableDB orderableDB = new OrderableDB();
blobs.Add(orderableDB);
MassVolumeDB mvDB = new MassVolumeDB();
blobs.Add(mvDB);
VolumeStorageDB storageDB = new VolumeStorageDB();
blobs.Add(storageDB);
var pos = new Vector3(planetEntity.GetDataBlob<MassVolumeDB>().RadiusInM, 0, 0);
PositionDB posDB = new PositionDB(pos, planetEntity);
blobs.Add(posDB);
TeamsHousedDB th = new TeamsHousedDB();
blobs.Add(th);

//installations get added to the componentInstancesDB
ComponentInstancesDB installations = new ComponentInstancesDB();
blobs.Add(installations);
blobs.Add(name);
blobs.Add(new ColonyInfoDB(speciesEntity, initialPopulation, planetEntity));
blobs.Add(new ColonyBonusesDB());
blobs.Add(new MiningDB());
blobs.Add(new OrderableDB());
blobs.Add(new MassVolumeDB());
blobs.Add(new VolumeStorageDB());
blobs.Add(new PositionDB(pos, planetEntity));
blobs.Add(new TeamsHousedDB());
blobs.Add(new ComponentInstancesDB()); //installations get added to the componentInstancesDB

Entity colonyEntity = Entity.Create();
colonyEntity.FactionOwnerID = factionEntity.Id;
planetEntity.Manager.AddEntity(colonyEntity, blobs);
var factionInfo = factionEntity.GetDataBlob<FactionInfoDB>();
factionInfo.Colonies.Add(colonyEntity);
factionEntity.GetDataBlob<FactionOwnerDB>().SetOwned(colonyEntity);
planetEntity.GetDataBlob<SystemBodyInfoDB>().Colonies.Add(colonyEntity);
return colonyEntity;
}
}
Expand Down
4 changes: 2 additions & 2 deletions Pulsar4X/GameEngine/Engine/Factories/Sol/EarthAndLuna.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public static Entity Earth(Game game, StarSystem sol, Entity sun, DateTime epoch
};

Entity planet = Entity.Create();
sol.AddEntity(planet, new List<BaseDataBlob> { planetNameDB, sensorProfile, planetPositionDB, planetBodyDB, planetMVDB, planetOrbitDB, planetAtmosphereDB, geoSurveyable });
sol.AddEntity(planet, new List<BaseDataBlob> { planetNameDB, sensorProfile, planetPositionDB, planetBodyDB, planetMVDB, planetOrbitDB, planetAtmosphereDB, geoSurveyable, new ColonizeableDB() });
SensorTools.PlanetEmmisionSig(sensorProfile, planetBodyDB, planetMVDB);
return planet;
}
Expand Down Expand Up @@ -91,7 +91,7 @@ public static Entity Luna(Game game, StarSystem sol, Entity sun, Entity parentPl
};

Entity moon = Entity.Create();
sol.AddEntity(moon, new List<BaseDataBlob> { moonNameDB, sensorProfile, moonPositionDB, moonBodyDB, moonMVDB, moonOrbitDB, geoSurveyable });
sol.AddEntity(moon, new List<BaseDataBlob> { moonNameDB, sensorProfile, moonPositionDB, moonBodyDB, moonMVDB, moonOrbitDB, geoSurveyable, new ColonizeableDB() });
SensorTools.PlanetEmmisionSig(sensorProfile, moonBodyDB, moonMVDB);
return moon;
}
Expand Down
2 changes: 1 addition & 1 deletion Pulsar4X/GameEngine/Engine/Factories/Sol/Mars.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public static Entity Mars(Game game, StarSystem sol, Entity sun, DateTime epoch,
};

Entity planet = Entity.Create();
sol.AddEntity(planet, new List<BaseDataBlob> { planetNameDB, sensorProfile, planetPositionDB, planetBodyDB, planetMVDB, planetOrbitDB, planetAtmosphereDB, geoSurveyable });
sol.AddEntity(planet, new List<BaseDataBlob> { planetNameDB, sensorProfile, planetPositionDB, planetBodyDB, planetMVDB, planetOrbitDB, planetAtmosphereDB, geoSurveyable, new ColonizeableDB() });
SensorTools.PlanetEmmisionSig(sensorProfile, planetBodyDB, planetMVDB);
return planet;
}
Expand Down
2 changes: 1 addition & 1 deletion Pulsar4X/GameEngine/Engine/Factories/Sol/Mercury.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public static Entity Mercury(Game game, StarSystem sol, Entity sun, DateTime epo
};

Entity planet = Entity.Create();
sol.AddEntity(planet, new List<BaseDataBlob> { planetNameDB, sensorProfile, planetPositionDB, planetBodyDB, planetMVDB, planetOrbitDB, geoSurveyable });
sol.AddEntity(planet, new List<BaseDataBlob> { planetNameDB, sensorProfile, planetPositionDB, planetBodyDB, planetMVDB, planetOrbitDB, geoSurveyable, new ColonizeableDB() });
SensorTools.PlanetEmmisionSig(sensorProfile, planetBodyDB, planetMVDB);
return planet;
}
Expand Down
2 changes: 1 addition & 1 deletion Pulsar4X/GameEngine/Engine/Factories/Sol/Venus.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public static Entity Venus(Game game, StarSystem sol, Entity sun, DateTime epoch
};

Entity planet = Entity.Create();
sol.AddEntity(planet, new List<BaseDataBlob> { planetNameDB, sensorProfile, planetPositionDB, planetBodyDB, planetMVDB, planetOrbitDB, planetAtmosphereDB, geoSurveyable });
sol.AddEntity(planet, new List<BaseDataBlob> { planetNameDB, sensorProfile, planetPositionDB, planetBodyDB, planetMVDB, planetOrbitDB, planetAtmosphereDB, geoSurveyable, new ColonizeableDB() });
SensorTools.PlanetEmmisionSig(sensorProfile, planetBodyDB, planetMVDB);
return planet;
}
Expand Down
65 changes: 65 additions & 0 deletions Pulsar4X/GameEngine/Engine/Orders/Actions/CreateColonyOrder.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
using System;
using Pulsar4X.Events;
using Pulsar4X.Extensions;

namespace Pulsar4X.Engine.Orders;

public class CreateColonyOrder : EntityCommand
{
public Entity TargetSystemBody { get; private set; }
public Entity Species { get; private set; }

public override ActionLaneTypes ActionLanes => ActionLaneTypes.InstantOrder;

public override bool IsBlocking => false;

public override string Name => "Create Colony";

public override string Details => $"Create Colony on {TargetSystemBody.ToString()}";

private Entity _entityCommanding;
internal override Entity EntityCommanding => _entityCommanding;

public static CreateColonyOrder CreateCommand(Entity faction, Entity species, Entity targetBody)
{
var command = new CreateColonyOrder()
{
_entityCommanding = faction,
EntityCommandingGuid = faction.Id,
RequestingFactionGuid= faction.Id,
TargetSystemBody = targetBody,
Species = species
};

return command;
}

public override EntityCommand Clone()
{
throw new NotImplementedException();
}

public override bool IsFinished()
{
return TargetSystemBody.IsOrHasColony().Item1;
}

internal override void Execute(DateTime atDateTime)
{
var colony = ColonyFactory.CreateColony(_entityCommanding, Species, TargetSystemBody);
var colonyName = colony.GetName(RequestingFactionGuid);
EventManager.Instance.Publish(
Event.Create(
EventType.ColonyCreated,
atDateTime,
$"{colonyName} has been created",
RequestingFactionGuid,
_entityCommanding.Manager.ManagerGuid,
colony.Id));
}

internal override bool IsValidCommand(Game game)
{
return true;
}
}
2 changes: 2 additions & 0 deletions Pulsar4X/GameEngine/Events/EventTypes.cs
Original file line number Diff line number Diff line change
Expand Up @@ -416,6 +416,8 @@ public enum EventType
ItsLifeJim, // Easter Egg Event?

#endregion

ColonyCreated,
}

}
26 changes: 20 additions & 6 deletions Pulsar4X/Pulsar4X.Client/GalaxyManagement/SystemTreeViewer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using System.Collections.Generic;
using System.Linq;
using Pulsar4X.Extensions;
using Pulsar4X.Engine.Orders;

namespace Pulsar4X.SDL2UI;
public class SystemTreeViewer : PulsarGuiWindow
Expand Down Expand Up @@ -96,6 +97,9 @@ private void PrintEntity(Entity entity, int depth = 0)
entity.GetDataBlob<SystemBodyInfoDB>().BodyType.ToDescription() :
"Star";

entity.TryGetDatablob<GeoSurveyableDB>(out var geoSurveyableDB);
bool isSurveyComplete = geoSurveyableDB == null ? false : geoSurveyableDB.IsSurveyComplete(_uiState.Faction.Id);

ImGui.TableNextColumn();
if(depth > 0) ImGui.Indent(16 * depth);
ImGui.Text(entity.GetName(_uiState.Faction.Id));
Expand All @@ -108,26 +112,36 @@ private void PrintEntity(Entity entity, int depth = 0)
if(result.Item1)
{
var colony = _uiState.StarSystemStates[_uiState.SelectedStarSysGuid].EntityStatesColonies[result.Item2];
if(colony.Entity.FactionOwnerID == _uiState.Faction.Id && ImGui.SmallButton("Colony###" + result.Item2))
if(colony.Entity.FactionOwnerID == _uiState.Faction.Id && ImGui.SmallButton(colony.Entity.GetOwnersName() + "###" + result.Item2))
{
EconomicsWindow.GetInstance().SetActive(true);
EconomicsWindow.GetInstance().SelectEntity(colony);
}
}
else
{
ImGui.Text("");
if(isSurveyComplete && entity.HasDataBlob<ColonizeableDB>())
{
if(ImGui.SmallButton("Colonize"))
{
var species = _uiState.Faction.GetDataBlob<FactionInfoDB>().Species[0];
var command = CreateColonyOrder.CreateCommand(_uiState.Faction, species, entity);
_uiState.Game.OrderHandler.HandleOrder(command);
}
}
else
{
ImGui.Text("");
}
}
ImGui.TableNextColumn();
bool isSurveyComplete = false;
if(entity.TryGetDatablob<GeoSurveyableDB>(out var geoSurveyableDB))
if(geoSurveyableDB != null)
{
if(geoSurveyableDB.HasSurveyStarted(_uiState.Faction.Id))
{
if(geoSurveyableDB.IsSurveyComplete(_uiState.Faction.Id))
if(isSurveyComplete)
{
ImGui.Text("Complete");
isSurveyComplete = true;
}
else
{
Expand Down
20 changes: 8 additions & 12 deletions Pulsar4X/Pulsar4X.Client/MapRendering/Icons/SysBodyIcon.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ void Setup(Entity entity)
_bodyType = _systemBodyInfoDB.BodyType;
_massVolDB = entity.GetDataBlob<MassVolumeDB>();
_bodyRadiusAU = _massVolDB.RadiusInAU;
_rng = new Random(entity.Id); //use entity guid as a seed for psudoRandomness.
_rng = new Random(entity.Id); //use entity guid as a seed for psudoRandomness.

switch (_bodyType)
{
Expand All @@ -47,10 +47,6 @@ void Setup(Entity entity)
if (entity.HasDataBlob<AtmosphereDB>())
{

}
if (_systemBodyInfoDB.Colonies.Count > 0)
{

}
}

Expand All @@ -61,8 +57,8 @@ void Terestrial()
var points = CreatePrimitiveShapes.Circle(0, 0, 100, segments);


//colors picked out of my ass for a blue/green look.
//TODO: use minerals for this? but migth not have that info. going to have to work in with sensor stuff.
//colors picked out of my ass for a blue/green look.
//TODO: use minerals for this? but migth not have that info. going to have to work in with sensor stuff.
byte r = 0;
byte g = 100;
byte b = 100;
Expand All @@ -83,13 +79,13 @@ void Asteroid()
var points = CreatePrimitiveShapes.CreateArc(0, 0, horDiameter, vertDiameter, 0, Math.PI * 2, segments);
for (int i = 0; i < segments; i = i + 2)
{
//this is not right, need to pull the points in towards the center, not just pull them left.
//this is not right, need to pull the points in towards the center, not just pull them left.
double x = points[i].X - _rng.Next(jagMin, jagMax);
double y = points[i].Y - _rng.Next(jagMin, jagMax);
points[i] = new Vector2() { X = x, Y = y };
}
//colors picked out of my ass for a brown look.
//TODO: use minerals for this? but migth not have that info. going to have to work in with sensor stuff.
//colors picked out of my ass for a brown look.
//TODO: use minerals for this? but migth not have that info. going to have to work in with sensor stuff.
byte r = 150;
byte g = 100;
byte b = 50;
Expand All @@ -103,8 +99,8 @@ void Unknown()

short segments = 24;
var points = CreatePrimitiveShapes.Circle(0, 0, 100, segments);
//colors picked out of my ass .
//TODO: use minerals for this? but migth not have that info. going to have to work in with sensor stuff.
//colors picked out of my ass .
//TODO: use minerals for this? but migth not have that info. going to have to work in with sensor stuff.
byte r = 100;
byte g = 100;
byte b = 100;
Expand Down
34 changes: 17 additions & 17 deletions Pulsar4X/Pulsar4X.Client/PlanetaryManagement/PlanetaryWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -230,23 +230,23 @@ private void RenderMineralDeposits()

MineralsDB mineralsDB = _lookedAtEntity.Entity.GetDataBlob<MineralsDB>();
SystemBodyInfoDB systemBodyInfo = _lookedAtEntity.Entity.GetDataBlob<SystemBodyInfoDB>();
if (systemBodyInfo.Colonies.Any())
{
// if colonies exists then
headerRow.Add(new KeyValuePair<string, TextAlign>("Mining Rate", TextAlign.Right));
foreach (Entity colonyEntity in systemBodyInfo.Colonies)
{
var colonyRates = MiningHelper.CalculateActualMiningRates(colonyEntity);
foreach (var rate in colonyRates)
{
if (!mineRates.ContainsKey(rate.Key))
{
mineRates.Add(rate.Key, 0);
}
mineRates[rate.Key] += rate.Value;
}
}
}
// if (systemBodyInfo.Colonies.Any())
// {
// // if colonies exists then
// headerRow.Add(new KeyValuePair<string, TextAlign>("Mining Rate", TextAlign.Right));
// foreach (Entity colonyEntity in systemBodyInfo.Colonies)
// {
// var colonyRates = MiningHelper.CalculateActualMiningRates(colonyEntity);
// foreach (var rate in colonyRates)
// {
// if (!mineRates.ContainsKey(rate.Key))
// {
// mineRates.Add(rate.Key, 0);
// }
// mineRates[rate.Key] += rate.Value;
// }
// }
// }

var deposits = mineralsDB.Minerals.Where(x => x.Value.Amount > 0);
if (deposits.Any())
Expand Down
Loading

0 comments on commit 84dd836

Please sign in to comment.