Skip to content

Commit

Permalink
hunter's lodge reworked
Browse files Browse the repository at this point in the history
  • Loading branch information
Mehni committed Jul 26, 2018
1 parent 0a4f70a commit fb6058a
Show file tree
Hide file tree
Showing 15 changed files with 83 additions and 71 deletions.
Binary file modified Assemblies/MoreFactionInteraction.dll
Binary file not shown.
2 changes: 1 addition & 1 deletion Defs/Incidents/Incidents_World_Misc.xml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
<workerClass>MoreFactionInteraction.World_Incidents.IncidentWorker_HuntersLodge</workerClass>
<letterLabel>Hunter's lodge</letterLabel>
<letterDef>PositiveEvent</letterDef>
<letterText>You are invited to {0}'s {1} summer retreat. There's usually a large herd of {2} coming through around this time of year. They have all the required facilities there to make meals, and they've extended their hospitality to you. This offer expires in {3} days.</letterText>
<letterText>You are invited to {0}'s {1} summer retreat. {2}. There is an outpost at the site with all the required facilities to make meals, and they've extended their hospitality to you. This offer expires in {3} days.</letterText>
<baseChance>0.8</baseChance>
<earliestDay>15</earliestDay>
<minRefireDays>30</minRefireDays>
Expand Down
9 changes: 6 additions & 3 deletions Defs/RuleDefs/SymbolResolver_Rules_BasePart_Indoors.xml
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,9 @@
<resolvers>
<li Class="SymbolResolver_BasePart_Indoors_Leaf_Barracks">
<minRectSize>(3, 3)</minRectSize>
<selectionWeight>0.65</selectionWeight>
<selectionWeight>0.45</selectionWeight>
</li>
<li Class="MoreFactionInteraction.World_Incidents.GenStep_SymbolResolver.SymbolResolver_BasePart_Indoors_Leaf_Kitchen">
<selectionWeight>0.5</selectionWeight>
<minRectSize>(5, 5)</minRectSize>
</li>
<li Class="SymbolResolver_BasePart_Indoors_Leaf_Brewery">
Expand All @@ -37,7 +36,11 @@
</li>
<li Class="SymbolResolver_BasePart_Indoors_Leaf_DiningRoom">
<minRectSize>(5, 5)</minRectSize>
<selectionWeight>1.25</selectionWeight>
<selectionWeight>0.45</selectionWeight>
</li>
<li Class="MoreFactionInteraction.World_Incidents.GenStep_SymbolResolver.MFI_SymbolResolver_BasePart_Indoors_Leaf_GloriousPotat">
<minRectSize>(4, 4)</minRectSize>
<selectionWeight>0.3</selectionWeight>
</li>
</resolvers>
</RuleDef>
Expand Down
3 changes: 0 additions & 3 deletions Defs/RuleDefs/SymbolResolver_Rules_BasePart_Outdoors.xml
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,6 @@
<li Class="MoreFactionInteraction.World_Incidents.GenStep_SymbolResolver.MFI_SymbolResolver_BasePart_Outdoors_Leaf_Farm">
<selectionWeight>0.65</selectionWeight>
</li>
<li Class="SymbolResolver_BasePart_Outdoors_Leaf_PowerPlant">
<selectionWeight>0.3</selectionWeight>
</li>
<li Class="MoreFactionInteraction.World_Incidents.GenStep_SymbolResolver.MFI_SymbolResolver_BasePart_Outdoors_Leaf_Building">
<minRectSize>(4, 4)</minRectSize>
</li>
Expand Down
1 change: 1 addition & 0 deletions Defs/Sites/Cores/HuntersLodge.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
<description>A small outpost, used by friendly factions as a hunting base.</description>
<siteTexture>World/WorldObjects/Sites/GenericSite</siteTexture>
<expandingIconTexture>World/WorldObjects/Expanding/Sites/Nothing</expandingIconTexture>
<showFactionInInspectString>true</showFactionInInspectString>
<forceExitAndRemoveMapCountdownDurationDays>10</forceExitAndRemoveMapCountdownDurationDays>
</SiteCoreDef>

Expand Down
4 changes: 2 additions & 2 deletions Defs/Sites/Parts/MigratoryHerd.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@
<description>A small outpost, used by friendly factions as a hunting base.</description>
<siteTexture>World/WorldObjects/Sites/GenericSite</siteTexture>
<expandingIconTexture>World/WorldObjects/Expanding/Sites/Nothing</expandingIconTexture>
<descriptionDialogue>there is an outpost at the site you're free to use</descriptionDialogue>
<descriptionDialogue>There's usually a large herd of {0} coming through around this time of year</descriptionDialogue>
<workerClass>MoreFactionInteraction.World_Incidents.SitePartWorker_MigratoryHerd</workerClass>
<showFactionInInspectString>true</showFactionInInspectString>
<requiresFaction>true</requiresFaction>
<showFactionInInspectString>true</showFactionInInspectString>
<approachOrderString>Visit {0}</approachOrderString>
<approachingReportString>Visiting {0}</approachingReportString>
<arrivedLetter>Your caravan has arrived at the hunter's lodge. It seems nobody is here, but they've obviously been expecting you and have made the place hospitable.</arrivedLetter>
Expand Down
1 change: 0 additions & 1 deletion Languages/English/Keyed/Keys.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
<MFI_DesperateTrader>Desperate trader</MFI_DesperateTrader>
<MFI_TraderSent>{0} thanks you. Their trade caravan will arrive in about {1}.</MFI_TraderSent>
<MFI_Trader>trader</MFI_Trader>
<MFI_HuntersLodgeInspectString>{0} invited you to hunt {1} here.</MFI_HuntersLodgeInspectString>

<MFI_CaravanWorking>Caravan is working.</MFI_CaravanWorking>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ protected override bool TryExecuteWorker(IncidentParms parms)
factionWarPeaceTalks.SetFaction(newFaction: faction);
factionWarPeaceTalks.SetWarringFactions(factionOne: faction, factionInstigator: instigatingFaction);
int randomInRange = TimeoutDaysRange.RandomInRange;
factionWarPeaceTalks.GetComponent<TimeoutComp>().StartTimeout(/*ticks: randomInRange **/ GenDate.TicksPerDay);
factionWarPeaceTalks.GetComponent<TimeoutComp>().StartTimeout(ticks: randomInRange * GenDate.TicksPerDay);
Find.WorldObjects.Add(o: factionWarPeaceTalks);

string text = string.Format(format: this.def.letterText.AdjustedFor(p: faction.leader), faction.def.leaderTitle, faction.Name, instigatingFaction.Name, randomInRange).CapitalizeFirst();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ namespace MoreFactionInteraction.World_Incidents
{
public class GenStep_HuntersLodge : GenStep
{
private const int Size = 24;
private const int Size = 36;

private static List<CellRect> possibleRects = new List<CellRect>();

Expand All @@ -29,7 +29,9 @@ public override void Generate(Map map, GenStepParams genStepParams)

ThingSetMakerParams maxFoodAndStuffForHuntersLodge = default;
maxFoodAndStuffForHuntersLodge.totalMarketValueRange = new FloatRange(200, 500);
maxFoodAndStuffForHuntersLodge.totalNutritionRange = new FloatRange(0, 50);
maxFoodAndStuffForHuntersLodge.totalNutritionRange = new FloatRange(20, 50);

//maxFoodAndStuffForHuntersLodge.filter.SetAllow(ThingCategoryDefOf.PlantFoodRaw, true);

resolveParams.thingSetMakerParams = maxFoodAndStuffForHuntersLodge;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using System.Text;
using Verse;
using RimWorld.BaseGen;
using UnityEngine;

namespace MoreFactionInteraction.World_Incidents.GenStep_SymbolResolver
{
Expand Down Expand Up @@ -70,4 +71,28 @@ public override void Resolve(ResolveParams rp)
}
}
}

class MFI_SymbolResolver_BasePart_Indoors_Leaf_GloriousPotat : SymbolResolver
{
public override void Resolve(ResolveParams rp)
{
CellRect rect = new CellRect(rp.rect.maxX - 3, rp.rect.maxZ - 3, 4, 4);
ThingDef gloriousPotat = ThingDefOf.RawPotatoes;
int num = Rand.RangeInclusive(2, 3);
for (int i = 0; i < num; i++)
{
ResolveParams resolveParams = rp;
resolveParams.rect = rect.ContractedBy(1);
resolveParams.singleThingDef = gloriousPotat;
resolveParams.singleThingStackCount = Rand.RangeInclusive(Mathf.Min(10, gloriousPotat.stackLimit), Mathf.Min(50, gloriousPotat.stackLimit));
BaseGen.symbolStack.Push("thing", resolveParams);
}
ResolveParams resolveParams2 = rp;
resolveParams2.rect = rect;
BaseGen.symbolStack.Push("ensureCanReachMapEdge", resolveParams2);
ResolveParams resolveParams3 = rp;
resolveParams3.rect = rect;
BaseGen.symbolStack.Push("emptyRoom", resolveParams3);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,6 @@ public override void Resolve(ResolveParams rp)
BaseGen.symbolStack.Push(symbol: "ensureCanReachMapEdge", resolveParams: resolveParams4);

ResolveParams mainBasePart = rp;
ThingSetMakerParams thingSet = default;
thingSet.totalMarketValueRange = new FloatRange(300, 1000);
thingSet.filter = new ThingFilter();
thingSet.filter.SetAllow(ThingCategoryDefOf.PlantFoodRaw, true);
rp.thingSetMakerParams = thingSet;
mainBasePart.faction = faction;
BaseGen.symbolStack.Push(symbol: "MFI_basePart_outdoors_division", resolveParams: mainBasePart);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,11 @@ public override void Resolve(ResolveParams rp)
Rot4 rot = (!flipACoin) ? Rot4.North : Rot4.West;
if (!GenSpawn.WouldWipeAnythingWith(thingPos: potentialSpot, thingRot: rot, thingDef: thingDef, map: map, predicate: x => x.def.category == ThingCategory.Building))
{
if (!BaseGenUtility.AnyDoorAdjacentCardinalTo(rect: GenAdj.OccupiedRect(center: potentialSpot, rot: rot, size: thingDef.Size + thingDef.interactionCellOffset.ToIntVec2), map: map))
IntVec2 dontTouchMe = new IntVec2(thingDef.Size.x + 1, thingDef.Size.z + 1);
if (!BaseGenUtility.AnyDoorAdjacentCardinalTo(rect: GenAdj.OccupiedRect(center: potentialSpot, rot: rot, size: dontTouchMe), map: map))
{
ResolveParams resolveParams = rp;
resolveParams.rect = GenAdj.OccupiedRect(center: potentialSpot, rot: rot, size: thingDef.size);
resolveParams.rect = GenAdj.OccupiedRect(center: potentialSpot, rot: rot, size: thingDef.Size);
resolveParams.singleThingDef = (Rand.Element(a: thingDef, b: tableButcher));
resolveParams.thingRot = rot;
bool? skipSingleThingIfHasToWipeBuildingOrDoesntFit = rp.skipSingleThingIfHasToWipeBuildingOrDoesntFit;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,12 @@ protected override List<Pawn> GeneratePawns(IncidentParms parms)
{
Map map = parms.target as Map;

this.pawnKindDef = PawnKindDefOf.Thrumbo;
if (Find.WorldObjects.SiteAt(map.Tile) is Site site)
{
SitePartWorker_MigratoryHerd sitePart =
(SitePartWorker_MigratoryHerd) site.parts.First(predicate: x => x.def == MFI_DefOf.MFI_HuntersLodgePart).def.Worker;
this.pawnKindDef = sitePart?.pawnKindDef;
}
if (map == null)
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)
this.pawnKindDef = site.parts.First(predicate: x => x.def == MFI_DefOf.MFI_HuntersLodgePart).parms.animalKind;

int num = new IntRange(min: 30, max: 50).RandomInRange;

List<Pawn> list = new List<Pawn>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
using RimWorld;
using RimWorld.Planet;
using Verse;
//using Kitchen.Sink;

namespace MoreFactionInteraction.World_Incidents
{

public class IncidentWorker_HuntersLodge : IncidentWorker
{
private const int MinDistance = 2;
Expand Down Expand Up @@ -33,32 +33,27 @@ protected override bool TryExecuteWorker(IncidentParms parms)
if (site == null)
return false;

if (!this.TryFindAnimalKind(tile: tile, animalKind: out PawnKindDef pawnKindDef))
return false;

if (pawnKindDef == null) pawnKindDef = PawnKindDefOf.Thrumbo; //mostly for testing.

int randomInRange = TimeoutDaysRange.RandomInRange;

site.Tile = tile;
site.GetComponent<TimeoutComp>().StartTimeout(ticks: randomInRange * GenDate.TicksPerDay);
site.SetFaction(newFaction: faction);

if(site.parts.First(predicate: x => x.def == MFI_DefOf.MFI_HuntersLodgePart).Def.Worker is SitePartWorker_MigratoryHerd sitePart)
sitePart.pawnKindDef = pawnKindDef;
site.customLabel = site.def.LabelCap + site.parts.First(predicate: x => x.def == MFI_DefOf.MFI_HuntersLodgePart).def.Worker
.GetPostProcessedThreatLabel(site, site.parts.FirstOrDefault());

Find.WorldObjects.Add(o: site);
string text = string.Format(format: this.def.letterText, faction, faction.def.leaderTitle, pawnKindDef.GetLabelPlural(), randomInRange).CapitalizeFirst();

string text = string.Format(format: this.def.letterText,
faction,
faction.def.leaderTitle,
SitePartUtility.GetDescriptionDialogue(site, site.parts.FirstOrDefault()),
randomInRange)
.CapitalizeFirst();

Find.LetterStack.ReceiveLetter(label: this.def.letterLabel, text: text, textLetterDef: this.def.letterDef, lookTargets: site);
return true;
}

private bool TryFindAnimalKind(int tile, out PawnKindDef animalKind)
{
return (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);
}

private static bool TryFindTile(out int tile)
{
return TileFinder.TryFindNewSiteTile(tile: out tile, minDist: MinDistance, maxDist: MaxDistance, allowCaravans: true, preferCloserTiles: false);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
using RimWorld;
using RimWorld.Planet;
using Verse;
using System.Linq;
using UnityEngine;

namespace MoreFactionInteraction.World_Incidents
{
public class SitePartWorker_MigratoryHerd : SitePartWorker
{
public PawnKindDef pawnKindDef;

public override string GetPostProcessedThreatLabel(Site site, SiteCoreOrPartBase siteCoreOrPart)
{
return string.Concat(base.GetPostProcessedThreatLabel(site, siteCoreOrPart),
Expand All @@ -17,38 +17,33 @@ public override string GetPostProcessedThreatLabel(Site site, SiteCoreOrPartBase
);
}


//public IncidentParms parmesan;
//public Faction faction;

//public override string CompInspectStringExtra()
//{
// return "MFI_HuntersLodgeInspectString".Translate(new object[] { faction, pawnKindDef.GetLabelPlural() });
//}

public override void PostMapGenerate(Map map)
{
IncidentParms incidentParms = StorytellerUtility.DefaultParmsNow(incCat: IncidentCategoryDefOf.Misc, target: map);
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);
}


public override string GetPostProcessedDescriptionDialogue(Site site, SiteCoreOrPartBase siteCoreOrPart)
{
return string.Format(base.GetPostProcessedDescriptionDialogue(site, siteCoreOrPart), GenLabel.BestKindLabel(siteCoreOrPart.parms.animalKind, Gender.None, true));
}

private bool TryFindAnimalKind(int tile, out PawnKindDef animalKind)
{
return (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);
}

//public override void PostExposeData()
//{
// base.PostExposeData();
// Scribe_Defs.Look(ref pawnKindDef, "MFI_HuntersLodgepawnKindDef");
// Scribe_References.Look(ref faction, "MFI_HuntersLodgeFaction");
// Scribe_Deep.Look<IncidentParms>(ref this.parmesan, "MFI_HuntersLodgeincidentParms", new object[0]);
//}
public override SiteCoreOrPartParams GenerateDefaultParams(Site site, float myThreatPoints)
{
SiteCoreOrPartParams siteCoreOrPartParams = base.GenerateDefaultParams(site, myThreatPoints);
if (TryFindAnimalKind(site.Tile, out siteCoreOrPartParams.animalKind))
{
siteCoreOrPartParams.threatPoints = Mathf.Max(siteCoreOrPartParams.threatPoints, siteCoreOrPartParams.animalKind.combatPower);
}
return siteCoreOrPartParams;
}
}

//class WorldObjectCompProperties_MigratoryHerd : WorldObjectCompProperties
//{
// public WorldObjectCompProperties_MigratoryHerd()
// {
// this.compClass = typeof(SitePartWorker_MigratoryHerd);
// }
//}
}

0 comments on commit fb6058a

Please sign in to comment.