$"slave already branded by {other.Name}: Recipe_BrandSlave.CompletableEver={completable}, Bill_Medical.CompletableEver={billCompletable} (expected both false). "+
$"Finishing the stale brand bill left owner={comp?.OwnerName ?? "nobrand"}, brand hediffs={count}, brand severity {severityBefore}->{severityAfter}; "+
"expected the brand untouched (taking over someone else's brand is the rebrand surgery)");
}
[BlaxTest("rebrand: offered only for another owner's brand, and only once")]
publicstaticvoidRebrandAvailability()
{
RecipeDefrecipe=RebrandRecipe;
T.Check(recipe.AvailableNow,"BlaxSlaves_RebrandSlave.AvailableNow is false, so the operations tab never lists it");
varworker=recipe.WorkerasRecipe_RebrandSlave;
T.NotNull(worker,"BlaxSlaves_RebrandSlave worker as Recipe_RebrandSlave (got "+recipe.Worker?.GetType().Name+")");
Pawnforeign=Fixtures.ColonySlave();
Factionother=OtherFaction(foreign.SlaveFaction);
if(other==null)T.Skip("no second non-player faction to brand the slave with");
BrandUtility.Brand(foreign,other);
T.Check(Offered(recipe,foreign),"rebrand not offered for a colony slave branded by "+other.Name);
T.Check(worker.CompletableEver(foreign),"Recipe_RebrandSlave.CompletableEver is false for a colony slave branded by "+other.Name);
Pawnours=Fixtures.ColonySlave();
BrandUtility.Brand(ours,Faction.OfPlayer);
T.Check(!Offered(recipe,ours),"rebrand offered for a slave that already carries our brand");
T.Check(!worker.CompletableEver(ours),"Recipe_RebrandSlave.CompletableEver is true for a slave with our brand");
Pawnplain=Fixtures.ColonySlave();
T.Check(!Offered(recipe,plain),"rebrand offered for an unbranded slave");
T.Check(!worker.CompletableEver(plain),"Recipe_RebrandSlave.CompletableEver is true for an unbranded slave");
PawnfreeBranded=Fixtures.Colonist();
BrandUtility.Brand(freeBranded,other);
T.Check(!Offered(recipe,freeBranded),"rebrand offered for a free colonist carrying "+other.Name+"'s brand");
T.Check(!worker.CompletableEver(freeBranded),"Recipe_RebrandSlave.CompletableEver is true for a free colonist");
// Owner faction gone: after a reload the reference is null and only the name is cached.
Pawnorphan=Fixtures.ColonySlave();
BrandUtility.Brand(orphan,other);
BrandUtility.BrandOf(orphan).owner=null;
T.Check(Offered(recipe,orphan),"rebrand not offered for a slave whose brand owner faction is gone (owner null)");
T.Check(worker.CompletableEver(orphan),"Recipe_RebrandSlave.CompletableEver is false for a slave whose brand owner faction is gone (owner null)");
QueueBill(foreign,recipe);
T.Check(!Offered(recipe,foreign),"rebrand offered a second time while a rebrand bill is already queued");
}
// ---- performing the surgeries ----------------------------------------------------
[BlaxTest("brand: surgery marks a colony slave as ours with a clean fresh burn")]
publicstaticvoidBrandSurgeryOutcome()
{
RecipeDefrecipe=BrandRecipe;
T.Check(recipe.surgeryOutcomeEffect==null,
"BlaxSlaves_BrandSlave.surgeryOutcomeEffect is "+recipe.surgeryOutcomeEffect+
"; Recipe_Surgery.CheckSurgeryFail only skips the failure roll when it is null, so branding can fail");
Pawndoctor=Fixtures.Colonist();
Pawnslave=Fixtures.ColonySlave();
ClearInjuries(slave);
T.Check(!BrandUtility.IsBranded(slave),"fresh fixture slave is already branded");
PerformSurgery(slave,recipe,doctor,51001);
Hediffbrand=BrandHediff(slave);
T.NotNull(brand,"hediff BlaxSlaves_SlaveBrand after the brand bill finished");
T.Equal(1,BrandCount(slave),"brand hediffs on the slave");
T.NotNull(comp,"HediffComp_BrandOwner on the brand");
T.Check(comp.owner==Faction.OfPlayer,"brand owner after the surgery: expected the player faction, got "+(comp.owner?.Name??"null"));
T.Equal(Faction.OfPlayer.Name,comp.ownerName,"cached owner name after the surgery");
T.Check(BrandUtility.IsBrandedByPlayer(slave),"BrandUtility.IsBrandedByPlayer is false right after our surgery");
T.Check(slave.IsSlaveOfColony,"slave lost slave status during the surgery");
CheckFreshBurn(slave,"after branding");
}
[BlaxTest("rebrand: finishing the bill makes another owner's brand ours")]
publicstaticvoidRebrandSurgeryOutcome()
{
RecipeDefrecipe=RebrandRecipe;
T.Check(recipe.surgeryOutcomeEffect==null,"BlaxSlaves_RebrandSlave.surgeryOutcomeEffect is "+recipe.surgeryOutcomeEffect+" (should be cleared like the brand's)");
Pawndoctor=Fixtures.Colonist();
Pawnslave=Fixtures.ColonySlave();
Factionother=OtherFaction(slave.SlaveFaction);
if(other==null)T.Skip("no second non-player faction to brand the slave with");
ClearInjuries(slave);
BrandUtility.Brand(slave,other);
T.Check(BrandUtility.BrandOf(slave)?.owner==other,"setup: brand owner is not "+other.Name);
T.NotNull(comp,"brand owner comp after the rebrand");
T.Check(comp.owner==Faction.OfPlayer,$"brand owner after the rebrand: expected the player faction, got {comp.owner?.Name ?? "null"} (was {other.Name})");
T.Equal(Faction.OfPlayer.Name,comp.ownerName,"cached owner name after the rebrand");
T.Equal(1,BrandCount(slave),"brand hediffs after the rebrand (it should reuse the existing brand)");
CheckFreshBurn(slave,"after rebranding");
T.Check(!Offered(recipe,slave),"rebrand still offered once the brand is ours");
}
// ---- mood and suppression --------------------------------------------------------
[BlaxTest("brand: Branded mood while a slave, gone once emancipated")]
T.Check(slave.IsSlaveOfColony,"setup: enslaved colonist is not a slave of the colony");
T.Check(!thought.Worker.CurrentState(slave).Active,"unbranded slave already has the Branded thought");
PerformSurgery(slave,BrandRecipe,doctor,51004);
T.Check(BrandUtility.IsBranded(slave),"slave not branded after the brand bill finished");
T.Check(thought.Worker.CurrentState(slave).Active,"BlaxSlaves_Branded inactive for a branded slave");
T.Check(HasMoodThought(slave,thought),"BlaxSlaves_Branded worker is active but the thought is not among the slave's mood thoughts");
GenGuest.EmancipateSlave(doctor,slave);
if(slave.IsSlave)
T.Skip("vanilla GenGuest.EmancipateSlave left the pawn a slave (home faction "+slave.HomeFaction?.Name+"); can't check the freed state");
T.Check(BrandUtility.IsBranded(slave),"the brand disappeared on emancipation; the scar should stay");
// Control: a plain ThoughtWorker_Hediff for the same def must still fire for the freed pawn.
// Otherwise the thought is off for another reason (CanGetThought, missing hediff) and the
// check below would pass without the slave gate doing anything.
varplain=newThoughtWorker_Hediff{def=thought};
if(!plain.CurrentState(slave).Active)
T.Skip("control: a plain ThoughtWorker_Hediff for BlaxSlaves_Branded is inactive for the freed, still branded pawn; can't attribute the freed state to ThoughtWorker_Branded");
T.Check(!thought.Worker.CurrentState(slave).Active,"BlaxSlaves_Branded still active after the slave was emancipated");
T.Check(!HasMoodThought(slave,thought),"BlaxSlaves_Branded still among the mood thoughts after emancipation");
}
[BlaxTest("brand: slave suppression falls slower with the brand")]
T.Skip($"suppression did not fall in Need_Suppression.NeedInterval without the brand (drop {dropRemoved}; need frozen or fall rate 0); nothing for the brand to slow");
T.Check(dropBranded<dropRemoved-1e-6f,
$"suppression fell by {dropBranded:F6} per NeedInterval with the brand and by {dropRemoved:F6} without it "+
$"(SlaveSuppressionFallRate {statBranded} vs {statRemoved}); expected the brand stage's x0.85 to slow it. "+
"StatWorker_SuppressionFallRate overrides GetValueUnfinalized without applying hediff statFactors");
}
/// <summary>Suppression lost in one vanilla Need_Suppression.NeedInterval call, starting from 50%.</summary>
T.Check(ticks<=0,$"reloaded brand burn (severity {burn.Severity:F1}) has an infection timer of {ticks} ticks; it should never get infected");
}
}
[BlaxTest("brand (reload): another faction's brand and owner survive save and load", phase: 2)]
publicstaticvoidReloadKeepsForeignBrand()
{
Pawnpawn=CarriedPawn("brand.foreign");
stringfactionId=T.Carry["brand.foreign.faction"];
stringname=T.Carry["brand.foreign.name"];
HediffComp_BrandOwnercomp=ReloadedBrand(pawn);
T.NotNull(comp.owner,"brand owner after reload (expected "+name+", "+factionId+")");
T.Equal(factionId,comp.owner.GetUniqueLoadID(),"brand owner faction id after reload");
T.Check(Find.FactionManager.AllFactionsListForReading.Contains(comp.owner),"reloaded brand owner "+comp.owner.Name+" is not a faction of the loaded world");
T.Equal(name,comp.owner.Name,"brand owner name after reload");
T.Equal(name,comp.ownerName,"cached owner name after reload");
T.Check(!BrandUtility.IsBrandedByPlayer(pawn),"a slave branded by "+name+" counts as branded by the player after reload");
CheckNameShown(pawn,name,name+"'s brand after reload");
}
[BlaxTest("brand (reload): cached owner name kept when the owner faction is gone", phase: 2)]
publicstaticvoidReloadKeepsGoneOwnerName()
{
Pawnpawn=CarriedPawn("brand.gone");
stringname=T.Carry["brand.gone.name"];
HediffComp_BrandOwnercomp=ReloadedBrand(pawn);
T.Check(comp.owner==null,
$"brand owner after reload: expected null (the faction was never in the world), got {comp.owner?.Name} ({comp.owner?.GetUniqueLoadID()})");
T.Equal(name,comp.ownerName,"cached owner name after reload");
T.Equal(name,comp.OwnerName,"OwnerName after reload");
CheckNameShown(pawn,name,"brand with a gone owner after reload");
// owner == null alone doesn't prove the save guard: without it the reference is still
// written, and loading fails to resolve it to null too, just with a warning. Vanilla
// warns "Could not resolve reference to object with loadID Faction_N" on load (always)
// and "Object with load ID Faction_N is referenced ... but is not deep-saved" on save (dev mode).
T.Check(!burn.IsPermanent(),when+": the brand burn is already a permanent scar, expected a fresh injury");
T.Check(burn.ageTicks<60,$"{when}: burn is {burn.ageTicks} ticks old, expected a fresh one");
T.Check(burn.TryGetComp<HediffComp_Infecter>()==null,when+": the brand burn has an infection comp (HediffComp_Infecter); it should never get infected");