Skip to content

Commit

Permalink
Mars 1.50 (#214)
Browse files Browse the repository at this point in the history
Co-authored-by: Bohdan Smishchenko <bogdan.smishenko@gmail.com>
  • Loading branch information
gkapulis and SmischenkoB authored Feb 7, 2025
1 parent 97b25b9 commit 8980e53
Show file tree
Hide file tree
Showing 34 changed files with 231 additions and 109 deletions.
1 change: 0 additions & 1 deletion Ship_Game/Building.cs
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,6 @@ public sealed class Building
[StarData] public float PlusProdPerColonist;
[StarData] public float PlusFlatProductionAmount;
[StarData] public float SensorRange;
[StarData] public float ProjectorRange;
[StarData] public float ShipRepair; // Note that thee is a multiplier in globals.yamls for this
[StarData] public BuildingCategory Category;
[StarData] public bool IsPlayerAdded;
Expand Down
3 changes: 2 additions & 1 deletion Ship_Game/Data/GameText.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5619,7 +5619,8 @@ public enum GameText
DysonSwarmOverClockSwarm = 6362,
/// <summary>Enable Swarm overclocking which will increase the production boost</summary>
DysonSwarmOverClockSwarmTip = 6363,

/// <summary>Show designs which are still locked due</summary>
ShowEmpireLockedDesignsTip = 6364,



Expand Down
6 changes: 3 additions & 3 deletions Ship_Game/Empire.cs
Original file line number Diff line number Diff line change
Expand Up @@ -601,11 +601,10 @@ public void RemovePlanet(Planet planet)
planet.SetPrioritizedPort(false);
OwnedPlanets.Remove(planet);
planet.SetSpecializedTradeHub(false);
Universe.OnPlanetOwnerRemoved(this, planet);

if (!planet.System.HasPlanetsOwnedBy(this)) // system no more in owned planets?
OwnedSolarSystems.Remove(planet.System);

Universe.OnPlanetOwnerRemoved(this, planet);
if (planet.System.EmpireOwnsDysonSwarm(this) && !planet.System.HasPlanetsOwnedBy(this))
planet.System.KillDysonSwarm();

Expand Down Expand Up @@ -649,6 +648,7 @@ public void AddPlanet(Planet planet)
throw new ArgumentNullException(nameof(planet.System));

OwnedPlanets.Add(planet);
OwnedSolarSystems.AddUniqueRef(planet.System);
planet.RemoveBlueprints();
Universe.OnPlanetOwnerAdded(this, planet);
if (planet.System.GetPotentialOpsOwner(out Empire potentialMiningOpsOwner))
Expand All @@ -657,7 +657,6 @@ public void AddPlanet(Planet planet)
mineable.Mining.ChangeOwnershipIfNeeded(potentialMiningOpsOwner);
}

OwnedSolarSystems.AddUniqueRef(planet.System);
CalcWeightedCenter(calcNow: true);
UpdateRallyPoints(); // update rally points every time OwnedPlanets changes
planet.SetDysonSwarmWeapon(loadWeapon: planet.System.HasDysonSwarm && planet.Owner == planet.System.DysonSwarm.Owner);
Expand Down Expand Up @@ -956,6 +955,7 @@ public void UnlockTech(TechEntry techEntry, TechUnlockType techUnlockType, Empir
case TechUnlockType.Event when techEntry.Unlock(this):
case TechUnlockType.Diplomacy when techEntry.UnlockFromDiplomacy(this, otherEmpire):
case TechUnlockType.Spy when techEntry.UnlockFromSpy(this, otherEmpire):
AddToShipTechLists(techEntry);
UpdateForNewTech();
TriggerRemoveGovernorQueuedBuildingsTechUnlock(techEntry);
break;
Expand Down
2 changes: 2 additions & 0 deletions Ship_Game/EmpireData.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Xml.Serialization;
using SDGraphics;
Expand Down Expand Up @@ -186,6 +187,7 @@ public float TaxRate
[StarData] public bool RebellionLaunched;
[StarData] public string MusicCue;
[StarData] public Array<string> ResearchQueue = new();
[StarData] public HashSet<string> ShipModulesInResearchQueues = new();
[StarData] public Array<Mole> MoleList = new(); // do not interact this with directly. Use PlantMole or RemoveMole methods

// NOTE: This is currently the main unique identifier?
Expand Down
26 changes: 23 additions & 3 deletions Ship_Game/EmpireResearch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ public class EmpireResearch

// The FIRST item (0) is always the Current research topic
Array<string> Queue => Empire.data.ResearchQueue;
HashSet<string> ShipModulesInQueue => Empire.data.ShipModulesInResearchQueues;

// Enumerates items in the back of the queue
// This does not include the Current research topic
Expand Down Expand Up @@ -59,6 +60,7 @@ public void Reset()
MaxResearchPotential = 0;
LeftoverResearch = 0;
Queue.Clear();
ShipModulesInQueue.Clear();
}

public void Initialize()
Expand Down Expand Up @@ -97,6 +99,8 @@ public void UpdateNetResearch()
MaxResearchPotential += researchFromAlliances;
}

public bool IsShipModuleQueuedForResearch(string shipModuleName) => ShipModulesInQueue.Contains(shipModuleName);

float GetResearchFromAllies()
{
float researchFromAlliances = 0;
Expand Down Expand Up @@ -220,15 +224,31 @@ public void SetTopic(string techUID)
// @return TRUE if tech was added to the queue and wasn't already present
public bool AddToQueue(string techUID)
{
if (!Empire.TryGetTechEntry(techUID, out _))
if (!Empire.TryGetTechEntry(techUID, out TechEntry entry))
{
Log.Error($"AddToResearchQueue: Unrecognized tech: {techUID}");
return false;
}

var unlockableModules = entry.GetUnlockableModules(Empire);
foreach (var module in unlockableModules )
ShipModulesInQueue.Add(module.ModuleUID);

return Queue.AddUnique(techUID);
}

public void RemoveFromQueue(string techUID) => Queue.Remove(techUID);
public void RemoveFromQueue(string techUID)
{
if (Empire.TryGetTechEntry(techUID, out TechEntry entry))
{
var unlockableModules = entry.GetUnlockableModules(Empire);
foreach (var module in unlockableModules)
ShipModulesInQueue.Remove(module.ModuleUID);
}

Queue.Remove(techUID);
}

public int IndexInQueue(string techUID) => Queue.IndexOf(techUID);
public bool IsQueued(string tech) => Queue.Contains(tech);

Expand All @@ -246,7 +266,7 @@ public void RemoveTechFromQueue(string techUid)
{
void RemoveLeadsToRecursive(string tech)
{
Queue.Remove(tech);
RemoveFromQueue(tech);
foreach (Technology.LeadsToTech dependent in ResourceManager.Tech(tech).LeadsTo)
RemoveLeadsToRecursive(dependent.UID);
}
Expand Down
58 changes: 26 additions & 32 deletions Ship_Game/Empire_Borders.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ public InfluenceNode(GameObject source, float radius, bool knowToPlayer)
public EmpireFirstContact FirstContact = new();

readonly Array<InfluenceNode> OurBorderSystems = new(); // all of our systems
readonly Array<InfluenceNode> OurBorderPlanets = new(); // all of our planets
readonly Array<InfluenceNode> OurBorderShips = new(); // SSP-s and some Bases

readonly Array<InfluenceNode> OurSensorPlanets = new(); // all of our planets
Expand All @@ -62,7 +61,6 @@ void ClearInfluenceList()
OurSensorShips.Clear();
OurSensorPlanets.Clear();
OurBorderShips.Clear();
OurBorderPlanets.Clear();

BorderNodes = Empty<InfluenceNode>.Array;
SensorNodes = Empty<InfluenceNode>.Array;
Expand Down Expand Up @@ -211,11 +209,18 @@ public void AddBorderNode(Planet planet)
bool empireKnown = IsThisEmpireKnownByPlayer();
bool known = empireKnown || planet.IsExploredBy(Universe.Player);

// NOTE: planets always provide influence
OurBorderPlanets.Add(new(planet, planet.GetProjectorRange(), known));
// NOTE: planets always provide influence and actually project it from system center.
if (!IsSystemInOurBorderSystems(planet.System))
OurBorderSystems.Add(new(planet.System, GetProjectorRadius(), known));

OurSensorPlanets.Add(new(planet, planet.SensorRange, empireKnown));
}


public bool IsSystemInOurBorderSystems(SolarSystem system)
{
return OurBorderSystems.Any(n => n.Source == system);
}

// @return True if source is a border node which provides influence in InfluenceTree
public bool RemoveBorderNode(GameObject source)
{
Expand All @@ -225,9 +230,11 @@ public bool RemoveBorderNode(GameObject source)
RemoveBorderNode(source, OurSensorShips);
return IsBorderNode(s);
}
else if (source is Planet)
else if (source is Planet p)
{
RemoveBorderNode(source, OurBorderPlanets);
if (!p.System.HasPlanetsOwnedBy(this))
RemoveBorderNode(source.System, OurBorderSystems);

RemoveBorderNode(source, OurSensorPlanets);
return true;
}
Expand All @@ -250,17 +257,18 @@ static void RemoveBorderNode(GameObject source, Array<InfluenceNode> nodes)

public bool ForceUpdateSensorRadiuses;

// This is used only when ForceUpdateSensorRadiuses is true, which is rare
void UpdateSensorAndBorderRadiuses()
{
ForceUpdateSensorRadiuses = false;
ForceUpdateSensorRadiuses = false;

bool useSensorRange = WeArePirates || WeAreRemnants;
float projectorRadius = GetProjectorRadius();

Span<InfluenceNode> sensorShips = OurSensorShips.AsSpan();
Span<InfluenceNode> sensorPlanets = OurSensorPlanets.AsSpan();
Span<InfluenceNode> borderShips = OurBorderShips.AsSpan();
Span<InfluenceNode> borderPlanets = OurBorderPlanets.AsSpan();
Span<InfluenceNode> borderSystems = OurBorderSystems.AsSpan();

foreach (ref InfluenceNode n in sensorShips)
{
Expand All @@ -274,9 +282,9 @@ void UpdateSensorAndBorderRadiuses()
{
n.Radius = useSensorRange ? ((Ship)n.Source).SensorRange : projectorRadius;
}
foreach (ref InfluenceNode n in borderPlanets)
foreach (ref InfluenceNode n in borderSystems)
{
n.Radius = ((Planet)n.Source).GetProjectorRange();
n.Radius = projectorRadius;
}
}

Expand All @@ -293,7 +301,7 @@ void UpdateOurSensorNodes()
}
foreach (ref InfluenceNode n in sensorPlanets)
{
n.Position = n.Source.Position;
n.Position = n.Source.System.Position;
n.KnownToPlayer = knownToPlayer;
}
}
Expand All @@ -303,8 +311,6 @@ void UpdateOurBorderNodes()
bool knownToPlayer = IsThisEmpireKnownByPlayer();

Span<InfluenceNode> borderShips = OurBorderShips.AsSpan();
Span<InfluenceNode> borderPlanets = OurBorderPlanets.AsSpan();

Span<SolarSystem> systems = OwnedSolarSystems.AsSpan();
OurBorderSystems.Clear();
OurBorderSystems.Resize(systems.Length);
Expand All @@ -314,7 +320,7 @@ void UpdateOurBorderNodes()
SolarSystem system = systems[i];
ref InfluenceNode sn = ref borderSystems[i];
sn.Position = system.Position;
sn.Radius = 5000;
sn.Radius = GetProjectorRadius();
sn.Source = system;
sn.KnownToPlayer = knownToPlayer;
}
Expand All @@ -326,15 +332,6 @@ void UpdateOurBorderNodes()
n.Position = n.Source.Position;
n.KnownToPlayer = true;
}
foreach (ref InfluenceNode n in borderPlanets)
{
n.Position = n.Source.Position;
n.KnownToPlayer = true;

int whichSystem = OwnedSolarSystems.IndexOfRef(((Planet)n.Source).System);
ref InfluenceNode sn = ref borderSystems[whichSystem];
sn.Radius = Math.Max(sn.Radius, n.Radius);
}
}
else
{
Expand All @@ -344,16 +341,13 @@ void UpdateOurBorderNodes()
n.Position = n.Source.Position;
n.KnownToPlayer = ((Ship)n.Source).InPlayerSensorRange;
}
foreach (ref InfluenceNode n in borderPlanets)
{
n.Position = n.Source.Position;
n.KnownToPlayer = ((Planet)n.Source).IsExploredBy(player);

int whichSystem = OwnedSolarSystems.IndexOfRef(((Planet)n.Source).System);
for (int i = 0; i < OwnedPlanets.Count; i++)
{
Planet p = OwnedPlanets[i];
int whichSystem = OwnedSolarSystems.IndexOfRef(p.System);
ref InfluenceNode sn = ref borderSystems[whichSystem];
sn.Radius = Math.Max(sn.Radius, n.Radius);

sn.KnownToPlayer |= n.KnownToPlayer;
sn.KnownToPlayer |= p.IsExploredBy(player);
}
}
}
Expand Down
1 change: 0 additions & 1 deletion Ship_Game/GamePlayGlobals.cs
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,6 @@ public class GamePlayGlobals
[StarData] public bool UseCombatRepair;
[StarData] public bool EnableECM;
[StarData] public bool UseDestroyers;
[StarData] public bool UsePlanetaryProjection;
[StarData] public bool ReconDropDown;
// Research costs will be increased based on map size to balance the increased capacity of larger maps
[StarData] public bool ChangeResearchCostBasedOnSize;
Expand Down
4 changes: 2 additions & 2 deletions Ship_Game/GameScreens/ColonyScreen/ColonyScreen.cs
Original file line number Diff line number Diff line change
Expand Up @@ -233,8 +233,8 @@ public ColonyScreen(GameScreen parent, Planet p, EmpireUIOverlay empUI,
if (p.OwnerIsPlayer || p.Universe.Debug)
BuildableList.OnDragOut = OnBuildableListDrag;

PlayerDesignsToggle = Add(new ToggleButton(new Vector2(BuildableTabs.Right - 270, BuildableTabs.Y-1),
ToggleButtonStyle.Grid, "SelectionBox/icon_grid"));
PlayerDesignsToggle = Add(new ToggleButton(new Vector2(BuildableTabs.Right - 270, BuildableTabs.Y+1),
ToggleButtonStyle.PlayerDesigns, "SelectionBox/icon_PlayerDesigns"));
PlayerDesignsToggle.IsToggled = !Universe.P.ShowAllDesigns;
PlayerDesignsToggle.Tooltip = GameText.ToggleToDisplayOnlyPlayerdesigned;
PlayerDesignsToggle.OnClick = OnPlayerDesignsToggleClicked;
Expand Down
1 change: 0 additions & 1 deletion Ship_Game/GameScreens/ColonyScreen/ColonyScreen_Draw.cs
Original file line number Diff line number Diff line change
Expand Up @@ -785,7 +785,6 @@ public static void DrawBuildingStaticInfo(ref Vector2 bCursor, SpriteBatch batch
DrawBuildingInfo(ref bCursor, batch, font, b.FoodCache, "NewUI/icon_food", GameText.FoodRemainingHereThisBuilding, signs: false, digits: 0);
DrawBuildingInfo(ref bCursor, batch, font, ColonyResource.FoodYieldFormula(fertility, b.PlusFoodPerColonist - 1), "NewUI/icon_food", GameText.FoodPerTurnPerAssigned);
DrawBuildingInfo(ref bCursor, batch, font, b.SensorRange, "NewUI/icon_sensors", GameText.SensorRange, signs: false);
DrawBuildingInfo(ref bCursor, batch, font, b.ProjectorRange, "NewUI/icon_projection", GameText.SubspaceProjectionArea, signs: false);
DrawBuildingInfo(ref bCursor, batch, font, b.PlusFlatProductionAmount, "NewUI/icon_production", GameText.ProductionPerTurn);
DrawBuildingInfo(ref bCursor, batch, font, ColonyResource.ProdYieldFormula(richness, b.PlusProdPerColonist - 1, owner), "NewUI/icon_production", GameText.ProductionPerTurnPerAssigned);
DrawBuildingInfo(ref bCursor, batch, font, b.ProdCache, "NewUI/icon_production", GameText.ProductionRemainingHereThisBuilding, signs: false, digits: 0);
Expand Down
Loading

0 comments on commit 8980e53

Please sign in to comment.