Skip to content

Commit

Permalink
migratoryherd bugfix
Browse files Browse the repository at this point in the history
  • Loading branch information
Mehni committed Oct 18, 2018
1 parent 70521c0 commit e279da4
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 8 deletions.
2 changes: 1 addition & 1 deletion Defs/Incidents/Incidents_CaravanMaps_Misc.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
</targetTags>
<workerClass>MoreFactionInteraction.World_Incidents.IncidentWorker_HerdMigration_Ambush</workerClass>
<pointsScaleable>true</pointsScaleable>
<minRefireDays>0.17</minRefireDays>
<minRefireDays>200</minRefireDays>
<letterText>A group of {0} is passing through the area.\n\nIt's hunting time.</letterText>
<letterLabel>Animal migration: {0}</letterLabel>
<letterDef>NeutralEvent</letterDef>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,13 @@ namespace MoreFactionInteraction.World_Incidents
{
public class IncidentWorker_HerdMigration_Ambush : IncidentWorker_Ambush
{
PawnKindDef pawnKindDef;
PawnKindDef pawnKindDef = PawnKindDefOf.Thrumbo;

public override float AdjustedChance => 0f;

protected override bool CanFireNowSub(IncidentParms parms)
{
return base.CanFireNowSub(parms: parms) && Current.Game.Maps.Any(predicate: x => x.Tile == parms.target.Tile);
return base.CanFireNowSub(parms: parms) && Current.Game.Maps.Any(predicate: x => x.Tile == parms.target.Tile) && parms.forced;
}

protected override LordJob CreateLordJob(List<Pawn> generatedPawns, IncidentParms parms)
Expand All @@ -23,14 +25,13 @@ protected override LordJob CreateLordJob(List<Pawn> generatedPawns, IncidentParm
TryFindEndCell(map: map, generatedPawns: generatedPawns, end: out IntVec3 end);
if (!end.IsValid && CellFinder.TryFindRandomPawnExitCell(searcher: generatedPawns[index: 0], result: out IntVec3 intVec3))
end = intVec3;

return new LordJob_ExitMapNear(near: end, locomotion: LocomotionUrgency.Walk);
}

protected override List<Pawn> GeneratePawns(IncidentParms parms)
{
Map map = parms.target as Map;

if (map == null)
if (!(parms.target is Map map))
this.pawnKindDef = PawnKindDefOf.Thrumbo; //something went really wrong. Let's uh.. brush it under the rug.

else if (Find.WorldObjects.SiteAt(map.Tile) is Site site)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ public override string GetPostProcessedThreatLabel(Site site, SiteCoreOrPartBase
public override void PostMapGenerate(Map map)
{
IncidentParms incidentParms = StorytellerUtility.DefaultParmsNow(incCat: IncidentCategoryDefOf.Misc, target: map);
incidentParms.forced = true;
//this part is forced to bypass CanFireNowSub, to solve issue with scenario-added incident.
QueuedIncident queuedIncident = new QueuedIncident(firingInc: new FiringIncident(def: DefDatabase<IncidentDef>.GetNamed(defName: "MFI_HerdMigration_Ambush"), source: null, parms: incidentParms), fireTick: Find.TickManager.TicksGame + Rand.RangeInclusive(min: GenDate.TicksPerDay / 2, max: GenDate.TicksPerDay));
Find.Storyteller.incidentQueue.Add(qi: queuedIncident);
}
Expand All @@ -31,9 +33,13 @@ public override string GetPostProcessedDescriptionDialogue(Site site, SiteCoreOr

private bool TryFindAnimalKind(int tile, out PawnKindDef animalKind)
{
return (from k in DefDatabase<PawnKindDef>.AllDefs
PawnKindDef fallback = PawnKindDefOf.Thrumbo;

animalKind = (from k in DefDatabase<PawnKindDef>.AllDefs
where k.RaceProps.CanDoHerdMigration && Find.World.tileTemperatures.SeasonAndOutdoorTemperatureAcceptableFor(tile: tile, animalRace: k.race)
select k).TryRandomElementByWeight(weightSelector: (PawnKindDef x) => x.RaceProps.wildness, result: out animalKind);
select k).RandomElementByWeightWithFallback(weightSelector: (PawnKindDef x) => x.RaceProps.wildness, fallback);

return animalKind != fallback;
}

public override SiteCoreOrPartParams GenerateDefaultParams(Site site, float myThreatPoints)
Expand Down

0 comments on commit e279da4

Please sign in to comment.