Skip to content
This repository has been archived by the owner on Nov 3, 2022. It is now read-only.

Commit

Permalink
KCSG - Genstep fix
Browse files Browse the repository at this point in the history
  • Loading branch information
KylianB committed Nov 15, 2021
1 parent 32ba53f commit 2745bf3
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 24 deletions.
Binary file modified 1.3/Assemblies/KCSG.dll
Binary file not shown.
3 changes: 1 addition & 2 deletions 1.3/Defs/Sites/DefaultEnnemyPresence.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
<defName>KCSG_EnnemiesPresence</defName>
<label>enemies present</label>
<description>Enemies are present in this place.</description>
<workerClass>SitePartWorker_Ambush</workerClass>
<siteTexture>World/WorldObjects/Sites/GenericSite</siteTexture>
<expandingIconTexture>World/WorldObjects/Expanding/Sites/Ambush</expandingIconTexture>
<handlesWorldObjectTimeoutInspectString>true</handlesWorldObjectTimeoutInspectString>
Expand All @@ -17,7 +16,7 @@
<GenStepDef>
<defName>KCSG_EnnemiesPresence</defName>
<linkWithSite>KCSG_EnnemiesPresence</linkWithSite>
<order>460</order>
<order>900</order>
<genStep Class="KCSG.GenStep_EnnemiesPresence" />
</GenStepDef>
</Defs>
42 changes: 20 additions & 22 deletions Source/KCSG/GenStep/GenStep_EnnemiesPresence.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ public class GenStep_EnnemiesPresence : GenStep
public FactionDef forcedfaction;
public float pointMultiplier = 1f;
public bool spawnOnEdge = false;
public FloatRange defaultPointsRange = new FloatRange(300f, 500f);

public override int SeedPart
{
Expand All @@ -26,57 +27,54 @@ public override int SeedPart
}
}


public override void Generate(Map map, GenStepParams parms)
{
Faction fac = this.forcedfaction != null ? Find.FactionManager.FirstFactionOfDef(this.forcedfaction) : Find.FactionManager.RandomEnemyFaction(minTechLevel: TechLevel.Neolithic);
parms.sitePart.site.SetFaction(fac);

int h = 10, w = 10;

List<Pawn> list = new List<Pawn>();
foreach (Pawn pawn in this.GeneratePawns(map, fac))
IEnumerable<Pawn> pawns = this.GeneratePawns(map, fac, parms);
Log.Message($"{pawns.Count()}");
foreach (Pawn pawn in pawns)
{
IntVec3 loc;
if (this.spawnOnEdge)
if (spawnOnEdge)
{
if (!CellFinder.TryFindRandomEdgeCellWith((IntVec3 x) => x.Standable(map) && !x.Fogged(map) && map.reachability.CanReachColony(x), map, CellFinder.EdgeRoadChance_Ignore, out loc))
{
Find.WorldPawns.PassToWorld(pawn, PawnDiscardDecideMode.Decide);
pawn.Discard();
break;
}
}
else if (!SiteGenStepUtility.TryFindSpawnCellAroundOrNear(CellRect.CenteredOn(map.Center, w, h), map.Center, map, out loc))
else if (!CellFinder.TryFindRandomSpawnCellForPawnNear(map.Center, map, out loc, 2))
{
Find.WorldPawns.PassToWorld(pawn, PawnDiscardDecideMode.Decide);
pawn.Discard();
break;
}
GenSpawn.Spawn(pawn, loc, map, WipeMode.Vanish);
list.Add(pawn);
GenSpawn.Spawn(pawn, loc, map);
}
if (!list.Any<Pawn>())
{

if (!pawns.Any())
return;
}
Faction faction = list[0].Faction;
LordMaker.MakeNewLord(faction, new LordJob_DefendBase(faction, map.Center), map, list);

if (!this.spawnOnEdge)
{
for (int k = 0; k < list.Count; k++)
{
list[k].jobs.StartJob(JobMaker.MakeJob(JobDefOf.Wait, 120, false), JobCondition.None, null, false, true, null, null, false, false);
list[k].Rotation = Rot4.Random;
}
LordMaker.MakeNewLord(fac, new LordJob_DefendBase(fac, map.Center), map, pawns);
}
else
{
LordMaker.MakeNewLord(fac, new LordJob_AssaultColony(fac, canTimeoutOrFlee: true, canPickUpOpportunisticWeapons: true), map, pawns);
}
}

private IEnumerable<Pawn> GeneratePawns(Map map, Faction faction)
private IEnumerable<Pawn> GeneratePawns(Map map, Faction faction, GenStepParams parms)
{
return PawnGroupMakerUtility.GeneratePawns(new PawnGroupMakerParms
{
groupKind = PawnGroupKindDefOf.Combat,
tile = map.Tile,
faction = faction,
points = StorytellerUtility.DefaultSiteThreatPointsNow() * this.pointMultiplier
points = (parms.sitePart != null ? parms.sitePart.parms.threatPoints : this.defaultPointsRange.RandomInRange) * this.pointMultiplier
}, true);
}
}
Expand Down

0 comments on commit 2745bf3

Please sign in to comment.