Skip to content

Commit

Permalink
Shipwrecked patch 02 (Nyanotrasen#1684)
Browse files Browse the repository at this point in the history
* Lower max player count to 7

* Adjust spawn chances of shipwreck factions

* Adjust shipwreck destination structure count

* Make destination temperatures more extreme

* Update ruined shops dungeon map

Adds new shop: Hippies

Removes the gun safe in the gun shop in favor of just pre-spawned ammo
and shotgun. StorageFill on the safe was not functioning.

* Start with full SMES for ruined buildings

* Expand random structure spot distance

* Tweak how the generator objective is determined

It now functions off of the initial load of the shuttle, rather than the
maximum supply of the generators. This should make things a little
easier on the players.

* Stop burning thrusters when they decouple

* Cleanup a section of code

* Damage the generator(s) more intelligently

* Update changelog
  • Loading branch information
Vordenburg authored Jul 3, 2023
1 parent 6cff616 commit c37d58c
Show file tree
Hide file tree
Showing 10 changed files with 642 additions and 80 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -127,10 +127,10 @@ public sealed class ShipwreckedRuleComponent : Component
public int OriginalThrusterCount;

/// <summary>
/// The original power supply of the generator on the shuttle.
/// The original power demand on the shuttle's generator(s).
/// </summary>
[ViewVariables]
public float OriginalPowerSupply;
public float OriginalPowerDemand;

/// <summary>
/// A dictionary of vital shuttle pieces and their eventual destinations once the shuttle decouples the engine.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -557,18 +557,27 @@ private void DamageShuttleMidflight(ShipwreckedRuleComponent component)
}

// Ensure that all generators on the shuttle will decay.
// Get the total power supply so we know how much to damage the generators by.
var totalPowerSupply = 0f;
var generatorQuery = EntityQueryEnumerator<PowerSupplierComponent, TransformComponent>();
while (generatorQuery.MoveNext(out var uid, out var powerSupplier, out var xform))
while (generatorQuery.MoveNext(out _, out var powerSupplier, out var xform))
{
if (xform.GridUid != component.Shuttle)
continue;

component.OriginalPowerSupply += powerSupplier.MaxSupply;
totalPowerSupply += powerSupplier.MaxSupply;
}

generatorQuery = EntityQueryEnumerator<PowerSupplierComponent, TransformComponent>();
while (generatorQuery.MoveNext(out var uid, out var powerSupplier, out var xform))
{
if (xform.GridUid != component.Shuttle)
continue;

EnsureComp<FinitePowerSupplierComponent>(uid);

// Hit it right away.
powerSupplier.MaxSupply *= 0.8f;
powerSupplier.MaxSupply *= (component.OriginalPowerDemand / totalPowerSupply) * 0.96f;
}
}

Expand Down Expand Up @@ -628,7 +637,7 @@ private bool TryGetRandomStructureSpot(ShipwreckedRuleComponent component,
// of sorts.

structure = _random.Pick(component.Structures);
var offset = _random.NextVector2(-11, 11);
var offset = _random.NextVector2(-13, 13);
var xy = _random.Pick(structure.Rooms).Center + offset;

coordinates = new EntityCoordinates(component.PlanetMap.Value, xy);
Expand Down Expand Up @@ -668,37 +677,60 @@ private void PrepareVitalShuttlePieces(ShipwreckedRuleComponent component)
component.VitalPieces.Add(uid, (spot, structure));
}

// Part of the escape objective requires the shuttle to have enough
// power for liftoff, but due to luck of the draw with dungeon generation,
// it's possible that not enough generators are spawned in.
var planetGeneratorCount = 0;
var planetGeneratorPower = 0f;
var generatorQuery = EntityQueryEnumerator<PowerSupplierComponent, TransformComponent>();
while (generatorQuery.MoveNext(out var uid, out var powerSupplier, out var xform))
while (generatorQuery.MoveNext(out _, out var powerSupplier, out var xform))
{
if (xform.GridUid == component.PlanetMap)
++planetGeneratorCount;
if (xform.GridUid != component.PlanetMap)
continue;

planetGeneratorPower += powerSupplier.MaxSupply;
++planetGeneratorCount;
}

if (planetGeneratorCount < 2)
_sawmill.Info($"Shipwreck destination has {planetGeneratorPower} W worth of {planetGeneratorCount} scavengeable generators.");

if (planetGeneratorPower < component.OriginalPowerDemand)
{
// Yes, it's possible. There's a very slim chance, but it's possible.
// Give the survivors a free generator, because they're going to need it.
// It's impossible to find enough generators to supply the shuttle's
// original power demand, assuming the players let the generator
// completely fail, therefore, we must spawn some generators,
// Deus Ex Machina.

var somewhere = new EntityCoordinates(component.PlanetMap.Value, 200f, 200f);
var uid = Spawn("GeneratorUranium", somewhere);
// This is all very cheesy that there would be generators just lying around,
// but I'd rather players be able to win than be hard-locked into losing.

TryGetRandomStructureSpot(component, out var spot, out var structure);
_sawmill.Info($"Heaven generator! {ToPrettyString(uid)} will go to {spot}");
// How many will we need?
const float UraniumPower = 15000f;
var generatorsNeeded = Math.Max(1, component.OriginalPowerDemand / UraniumPower);

MakeCrater(component.PlanetGrid, spot);
for (int i = 0; i < generatorsNeeded; ++i)
{
// Just need a temporary spawn point away from everything.
var somewhere = new EntityCoordinates(component.PlanetMap.Value, 200f + i, 200f + i);
var uid = Spawn("GeneratorUranium", somewhere);

component.VitalPieces.Add(uid, (spot, structure));
}
else
{
_sawmill.Info($"Planet has {planetGeneratorCount} scavengeable generators.");
TryGetRandomStructureSpot(component, out var spot, out var structure);
_sawmill.Info($"Heaven generator! {ToPrettyString(uid)} will go to {spot}");

MakeCrater(component.PlanetGrid, spot);
component.VitalPieces.Add(uid, (spot, structure));
}
}
}

private void DecoupleShuttleEngine(ShipwreckedRuleComponent component)
{
if (component.Shuttle == null)
return;

// Stop thrusters from burning anyone when re-anchored.
_thrusterSystem.DisableLinearThrusters(Comp<ShuttleComponent>(component.Shuttle.Value));

// Move the vital pieces of the shuttle down to the planet.
foreach (var (uid, (destination, _)) in component.VitalPieces)
{
Expand Down Expand Up @@ -764,10 +796,10 @@ private void SpawnFaction(ShipwreckedRuleComponent component, string id, IEnumer
}

foreach (var room in structure.Rooms)
{
SpawnFactionMobs(component, faction.Active, room);

foreach (var room in structure.Rooms)
SpawnFactionMobs(component, faction.Inactive, room);
}
}
}

Expand Down Expand Up @@ -1144,7 +1176,17 @@ protected override void Started(EntityUid uid, ShipwreckedRuleComponent componen
return;

_mapManager.SetMapPaused(component.PlanetMapId.Value, false);
/* EntityManager.InitializeAndStartEntity(component.PlanetMap.Value); */

var loadQuery = EntityQueryEnumerator<ApcPowerReceiverComponent, TransformComponent>();
while (loadQuery.MoveNext(out _, out var apcPowerReceiver, out var xform))
{
if (xform.GridUid != component.Shuttle)
continue;

component.OriginalPowerDemand += apcPowerReceiver.Load;
}

_sawmill.Info($"The original power demand for the shuttle is {component.OriginalPowerDemand} W");

var shuttle = component.Shuttle.Value;

Expand Down Expand Up @@ -1455,7 +1497,7 @@ private bool GetLaunchConditionGenerator(ShipwreckedRuleComponent component)
totalSupply += powerSupplier.MaxSupply;
}

return totalSupply >= component.OriginalPowerSupply;
return totalSupply >= component.OriginalPowerDemand;
}

private bool GetLaunchConditionThrusters(ShipwreckedRuleComponent component, out int goodThrusters)
Expand Down
2 changes: 1 addition & 1 deletion Content.Shared/CCVar/CCVars.cs
Original file line number Diff line number Diff line change
Expand Up @@ -428,7 +428,7 @@ public static readonly CVarDef<int>
*/

public static readonly CVarDef<int> ShipwreckedMaxPlayers =
CVarDef.Create("shipwrecked.max_players", 8);
CVarDef.Create("shipwrecked.max_players", 7);

/*
* Tips
Expand Down
22 changes: 7 additions & 15 deletions Resources/Changelog/Changelog.yml
Original file line number Diff line number Diff line change
@@ -1,18 +1,4 @@
Entries:
- author: Rane
changes:
- message: Reenabled the non-social objective groups. Woops.
type: Fix
- message: All animals are now eligible for awakening.
type: Tweak
id: 65
time: '2022-11-01T23:24:09.0000000+00:00'
- author: Kromabae
changes:
- message: additional pebble fixes and qol
type: Add
id: 66
time: '2022-11-03T02:27:53.0000000+00:00'
- author: Rane
changes:
- message: Doubled glimmer production from probers and drains (per advice of one
Expand Down Expand Up @@ -3800,7 +3786,13 @@ Entries:
time: '2023-06-25T22:16:26.668452+00:00'
- author: Rane
changes:
- message: 'There is something in the vents...'
- message: There is something in the vents...
type: Add
id: 563
time: '2023-06-26T22:16:26.668452+00:00'
- author: Vordenburg
changes:
- message: Adjusted a few things for Shipwrecked.
type: Tweak
id: 564
time: '2023-07-02T23:21:31.772767+00:00'
2 changes: 1 addition & 1 deletion Resources/Maps/Dungeon/ruined_dwellings.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2126,7 +2126,7 @@ entities:
- pos: 12.5,13.5
parent: 1
type: Transform
- proto: SMESBasicEmpty
- proto: SMESBasic
entities:
- uid: 151
components:
Expand Down
2 changes: 1 addition & 1 deletion Resources/Maps/Dungeon/ruined_hospital.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5036,7 +5036,7 @@ entities:
pos: 10.5,21.5
parent: 1
type: Transform
- proto: SMESBasicEmpty
- proto: SMESBasic
entities:
- uid: 648
components:
Expand Down
Loading

0 comments on commit c37d58c

Please sign in to comment.