Skip to content

Commit

Permalink
Permanently immobile objects like planets and bases can no longer be …
Browse files Browse the repository at this point in the history
…issues movement orders. (#341)
  • Loading branch information
ekolis authored Dec 15, 2024
1 parent c9f226a commit 2dafa56
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 5 deletions.
5 changes: 5 additions & 0 deletions FrEee.Core.Domain/Objects/Space/Fleet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -922,4 +922,9 @@ private IEnumerable<string> GetImagePaths(string imagetype)
public IEnumerable<Component> Components => Vehicles.SelectMany(q => q.Components);

public bool FillsCombatTile => Vehicles.Any(q => q.FillsCombatTile);

/// <summary>
/// A fleet can be mobile if all of its constituent vehicles can be mobile.
/// </summary>
public bool CanBeMobile => Vehicles.All(q => q.CanBeMobile);
}
6 changes: 6 additions & 0 deletions FrEee.Core.Domain/Objects/Space/IMobileSpaceObject.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,12 @@ public interface IMobileSpaceObject : ICombatSpaceObject, IOrderable, IContainab
void BurnMovementSupplies();

void SpendTime(double timeElapsed);

/// <summary>
/// Can this object ever be mobile? Not "is it mobile right now", can it EVER be mobile?
/// If so, we want to display movement commands in the UI.
/// </summary>
bool CanBeMobile { get; }
}

// HACK: find a way to get rid of this generic interface, it's stupid...
Expand Down
5 changes: 5 additions & 0 deletions FrEee.Core.Domain/Objects/Space/Planet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1045,4 +1045,9 @@ private int TakePopulationDamage(Hit hit, PRNG dice = null)
public IEnumerable<Component> Components => Cargo.Units.Where(q => q.CanFireIntoSpaceFromPlanetaryCargo).SelectMany(q => q.Components);

public bool FillsCombatTile => true;

/// <summary>
/// Sorry Pinocchio, planets can't move.
/// </summary>
public bool CanBeMobile => false;
}
19 changes: 14 additions & 5 deletions FrEee.UI.WinForms/Forms/MainGameForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -120,15 +120,24 @@ public ISpaceObject SelectedSpaceObject
else
{
// determine what commands are appropriate
btnMove.Visible = value is IMobileSpaceObject;
btnPursue.Visible = value is IMobileSpaceObject;
btnEvade.Visible = value is IMobileSpaceObject;
btnWarp.Visible = value is IMobileSpaceObject && ((IMobileSpaceObject)value).CanWarp;
if (value is IMobileSpaceObject sobj)
{
btnMove.Visible = sobj.CanBeMobile;
btnPursue.Visible = sobj.CanBeMobile;
btnEvade.Visible = sobj.CanBeMobile;
btnWarp.Visible = sobj.CanBeMobile && sobj.CanWarp;
btnColonize.Visible =
value is IMobileSpaceObject sobj && sobj.Abilities().Any(a => a.Rule.Name.StartsWith("Colonize Planet - "))
sobj.Abilities().Any(a => a.Rule.Name.StartsWith("Colonize Planet - "))
|| value is Fleet f && f.LeafVehicles.Any(v => v.Abilities().Any(a => a.Rule.Name.StartsWith("Colonize Planet - ")));
}
else
{
btnMove.Visible = false;
btnPursue.Visible = false;
btnEvade.Visible = false;
btnWarp.Visible = false;
btnColonize.Visible = false;
}
btnSentry.Visible = value is IMobileSpaceObject;
btnConstructionQueue.Visible = value is IConstructor c && c.ConstructionQueue != null;
btnTransferCargo.Visible = value != null && (value is ICargoContainer && ((ICargoContainer)value).CargoStorage > 0 || value.SupplyStorage > 0 || value.HasInfiniteSupplies);
Expand Down
6 changes: 6 additions & 0 deletions FrEee.Vehicles/Types/SpaceVehicle.cs
Original file line number Diff line number Diff line change
Expand Up @@ -385,4 +385,10 @@ public virtual void SpendTime(double timeElapsed)
{
TimeToNextMove += timeElapsed;
}

/// <summary>
/// Space vehicles can be mobile if their design's strategic speed is greater than zero.
/// Not their current strategic speed; they might be temporarily immobilized by, say, engine damage.
/// </summary>
public bool CanBeMobile => Design.StrategicSpeed > 0;
}

0 comments on commit 2dafa56

Please sign in to comment.