Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Assets/Tests/EditMode/Simulation/CombatSystemTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -670,7 +670,7 @@ public MatchFingerprint CreateFingerprint()
slots[HumanSlot] = (byte)PlayerSlotOccupancy.Human;
slots[AiSlot] = (byte)PlayerSlotOccupancy.AI;
return MatchFingerprint.CreateCurrent(
MatchFingerprint.ComputeEmptyContentStubHash(MatchContentStub.Rules),
MatchFingerprint.ComputeCurrentRulesHash64(),
MatchFingerprint.ComputeEmptyContentStubHash(MatchContentStub.Definitions),
MatchFingerprint.ComputeEmptyContentStubHash(MatchContentStub.Map),
slots,
Expand Down
46 changes: 43 additions & 3 deletions Assets/Tests/EditMode/Simulation/ConstructionSystemTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -696,7 +696,8 @@ public void PowerSite_ProvidesNothing_UntilCompletion()
public void CancelConstruction_Refunds75Percent_AndFreesFootprint()
{
var f = new Fixture();
Assert.That(f.Construction.PlaceCompletedBuilding(0, 5, 40, 40).IsValid, Is.True, "power provider");
Assert.That(f.Construction.PlaceCompletedBuilding(0, 3, 40, 40).IsValid, Is.True,
"HQ provides power and 2,000 AE capacity");
f.SpawnBuilder(0, 19, 20);
f.Step(1); // commit the balance
Assert.That(f.Construction.TryPlaceBuilding(0, 7, 20, 20), Is.True); // 500 spent
Expand All @@ -719,7 +720,8 @@ public void CancelConstruction_Refunds75Percent_AndFreesFootprint()
public void Sell_CompletedBuilding_Refunds50Percent_SiteIsNotSellable()
{
var f = new Fixture();
Assert.That(f.Construction.PlaceCompletedBuilding(0, 5, 40, 40).IsValid, Is.True, "power provider");
Assert.That(f.Construction.PlaceCompletedBuilding(0, 3, 40, 40).IsValid, Is.True,
"HQ provides power and 2,000 AE capacity");
EntityId barracks = f.Construction.PlaceCompletedBuilding(0, 7, 20, 20);
uint raw = UnitCommandStateView.ToRawEntityId(barracks);

Expand All @@ -730,13 +732,51 @@ public void Sell_CompletedBuilding_Refunds50Percent_SiteIsNotSellable()
Assert.That(f.Construction.IsCellFree(20, 20), Is.True);

f.SpawnBuilder(0, 19, 20);
f.Step(1); // commit the balance (100 provided, 0 required)
f.Step(1); // commit the balance (30 provided, 0 required)
Assert.That(f.Construction.TryPlaceBuilding(0, 7, 20, 20), Is.True);
uint siteRaw = UnitCommandStateView.ToRawEntityId(SiteEntity(f));
Assert.That(f.Construction.ValidateSell(0, siteRaw), Is.EqualTo(CommandResultCode.RejectedInvalidTarget),
"a site is cancelled, not sold");
}

[Test]
public void CancelConstruction_RefundIsCappedAtStorageCeiling()
{
var f = new Fixture(startingCredits: EconomySystem.HqBaseCapacityAE);
Assert.That(f.Construction.PlaceCompletedBuilding(0, 3, 40, 40).IsValid, Is.True,
"HQ provides power and the 2,000 AE ceiling");
f.SpawnBuilder(0, 19, 20);
f.Step(1);
Assert.That(f.Construction.TryPlaceBuilding(0, 7, 20, 20), Is.True); // 2.000 - 500 = 1.500
uint siteRaw = UnitCommandStateView.ToRawEntityId(SiteEntity(f));
f.Economy.GetPlayerEconomy(0).AddCredits(495); // raw fixture setup: 1.995

Assert.That(f.Construction.CancelConstruction(siteRaw), Is.True);
Assert.That(f.Economy.GetPlayerEconomy(0).AetheriumCredits,
Is.EqualTo(EconomySystem.HqBaseCapacityAE),
"only 5 of the 375 AE refund fit; the overflow is forfeit");
}

[Test]
public void SellStorage_CapsRefundThenLoweredCapacityDrivesExcessDecay()
{
var f = new Fixture(startingCredits: 3900);
Assert.That(f.Construction.PlaceCompletedBuilding(0, 3, 40, 40).IsValid, Is.True);
EntityId storage = f.Construction.PlaceCompletedBuilding(0, 6, 20, 20);
Assert.That(f.Economy.CapacityFor(0),
Is.EqualTo(EconomySystem.HqBaseCapacityAE + EconomySystem.StorageCapacityBonusAE));

Assert.That(f.Construction.SellBuilding(UnitCommandStateView.ToRawEntityId(storage)), Is.True);
Assert.That(f.Economy.GetPlayerEconomy(0).AetheriumCredits, Is.EqualTo(4000L),
"only 100 of the 150 AE sale refund fit before the Storage leaves the stock");
Assert.That(f.Economy.CapacityFor(0), Is.EqualTo(EconomySystem.HqBaseCapacityAE),
"selling the Storage immediately lowers the derived ceiling");

f.Step(EconomySystem.ExcessDecayIntervalTicks);
Assert.That(f.Economy.GetPlayerEconomy(0).AetheriumCredits, Is.EqualTo(3500L),
"tick 10 removes 25% of the 2,000 AE excess");
}

[Test]
public void Repair_BuilderRestoresHp_InReachOnly_AndResolvesAtFull()
{
Expand Down
9 changes: 7 additions & 2 deletions Assets/Tests/EditMode/Simulation/EconomyIntegrationTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,11 @@ public void RestoreSessionTick()
new Transform2D(SimFixed.FromInt(11), SimFixed.FromInt(10)),
SimFixed.Zero,
role: UnitRole.Refinery);
Entities.SpawnUnit(
owner,
new Transform2D(SimFixed.FromInt(60), SimFixed.FromInt(60)),
SimFixed.Zero,
role: UnitRole.HQ);
return (UnitCommandStateView.ToRawEntityId(harvester), harvester);
}

Expand Down Expand Up @@ -318,7 +323,7 @@ public void Replay_HarvestAndReturnIntents_PlaybackReproducesEndHash()
slots[0] = (byte)PlayerSlotOccupancy.Human;
slots[1] = (byte)PlayerSlotOccupancy.AI;
MatchFingerprint fingerprint = MatchFingerprint.CreateCurrent(
MatchFingerprint.ComputeEmptyContentStubHash(MatchContentStub.Rules),
MatchFingerprint.ComputeCurrentRulesHash64(),
MatchFingerprint.ComputeEmptyContentStubHash(MatchContentStub.Definitions),
MatchFingerprint.ComputeEmptyContentStubHash(MatchContentStub.Map),
slots,
Expand Down Expand Up @@ -483,7 +488,7 @@ public void Replay_WithHarvestRejections_PlaybackReproducesResultsAndEndHash()
slots[0] = (byte)PlayerSlotOccupancy.Human;
slots[1] = (byte)PlayerSlotOccupancy.AI;
MatchFingerprint fingerprint = MatchFingerprint.CreateCurrent(
MatchFingerprint.ComputeEmptyContentStubHash(MatchContentStub.Rules),
MatchFingerprint.ComputeCurrentRulesHash64(),
MatchFingerprint.ComputeEmptyContentStubHash(MatchContentStub.Definitions),
MatchFingerprint.ComputeEmptyContentStubHash(MatchContentStub.Map),
slots,
Expand Down
Loading
Loading