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

Commit

Permalink
Outposts: Move some stuff to Utils
Browse files Browse the repository at this point in the history
  • Loading branch information
legodude17 committed Dec 12, 2021
1 parent c723a7d commit ed791a0
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 28 deletions.
Binary file modified 1.3/Assemblies/Outposts.dll
Binary file not shown.
31 changes: 5 additions & 26 deletions Source/Outposts/Outpost.cs
Original file line number Diff line number Diff line change
Expand Up @@ -190,26 +190,6 @@ public override bool ShouldRemoveMapNow(out bool alsoRemoveWorldObject)
return false;
}

public static string CheckSkill(IEnumerable<Pawn> pawns, SkillDef skill, int minLevel)
{
return pawns.Sum(p => p.skills.GetSkill(skill).Level) < minLevel ? "Outposts.NotSkilledEnough".Translate(skill.skillLabel, minLevel) : null;
}

public static IEnumerable<Thing> MakeThings(ThingDef thingDef, int count, ThingDef stuff = null)
{
while (count > thingDef.stackLimit)
{
var temp = ThingMaker.MakeThing(thingDef, stuff);
temp.stackCount = thingDef.stackLimit;
yield return temp;
count -= thingDef.stackLimit;
}

var temp2 = ThingMaker.MakeThing(thingDef, stuff);
temp2.stackCount = count;
yield return temp2;
}

public void Deliver(IEnumerable<Thing> items)
{
var map = Find.Maps.Where(m => m.IsPlayerHome).OrderByDescending(m => Find.WorldGrid.ApproxDistanceInTiles(m.Parent.Tile, Tile)).First();
Expand Down Expand Up @@ -526,12 +506,11 @@ public Pawn RemovePawn(Pawn p)

public override string GetInspectString() =>
base.GetInspectString() +
Line(def.LabelCap) +
Line("Outposts.Contains".Translate(occupants.Count)) +
Line(Packing ? "Outposts.Packing".Translate(ticksTillPacked.ToStringTicksToPeriodVerbose().Colorize(ColoredText.DateTimeColor)).RawText : ProductionString()) +
Line(Ext?.RelevantSkills?.Count > 0 ? RelevantSkillDisplay() : "");

public static string Line(string input) => input.NullOrEmpty() ? "" : "\n" + input;
def.LabelCap.Line() +
"Outposts.Contains".Translate(occupants.Count).Line() +
"Outposts.Packing".Translate(ticksTillPacked.ToStringTicksToPeriodVerbose().Colorize(ColoredText.DateTimeColor)).Line(Packing) +
ProductionString().Line(!Packing) +
RelevantSkillDisplay().Line(Ext?.RelevantSkills?.Count > 0);

public virtual string ProductionString()
{
Expand Down
3 changes: 2 additions & 1 deletion Source/Outposts/OutpostExtension.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ public class OutpostExtension : DefModExtension
public List<ResultOption> ResultOptions;
public int TicksPerProduction = 15 * 60000;
public int TicksToPack = 7 * 60000;
public int TicksToSetUp = -1;

public List<SkillDef> RelevantSkills =>
new HashSet<SkillDef>(RequiredSkills.SelectOrEmpty(rq => rq.Skill)
Expand All @@ -40,7 +41,7 @@ public class ResultOption
public int Amount(List<Pawn> pawns) =>
Mathf.RoundToInt((BaseAmount + AmountPerPawn * pawns.Count + (AmountsPerSkills?.Sum(x => x.Amount(pawns)) ?? 0)) * OutpostsMod.Settings.ProductionMultiplier);

public IEnumerable<Thing> Make(List<Pawn> pawns) => Outpost.MakeThings(Thing, Amount(pawns));
public IEnumerable<Thing> Make(List<Pawn> pawns) => Thing.Make(Amount(pawns));
public string Explain(List<Pawn> pawns) => $"{Amount(pawns)}x {Thing.LabelCap}";
}

Expand Down
26 changes: 25 additions & 1 deletion Source/Outposts/Utils.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
using System;
using System.Collections.Generic;
using System.Linq;
using RimWorld;
using RimWorld.Planet;
using UnityEngine;
using Verse;

namespace Outposts
Expand All @@ -20,7 +22,29 @@ public static IEnumerable<TResult> SelectOrEmpty<TSource, TResult>(this IEnumera
public static IEnumerable<TResult> SelectManyOrEmpty<TSource, TResult>(this IEnumerable<TSource> source, Func<TSource, IEnumerable<TResult>> selector) =>
source is null ? Enumerable.Empty<TResult>() : source.SelectMany(selector);

public static string Line(this string input) => input.NullOrEmpty() ? "" : "\n" + input;
public static string Line(this string input, bool show = true) => !show || input.NullOrEmpty() ? "" : "\n" + input;
public static string Line(this TaggedString input, bool show = true) => !show || input.NullOrEmpty() ? "" : "\n" + input.RawText;

public static IEnumerable<Thing> Make(this ThingDef thingDef, int count, ThingDef stuff = null)
{
count = Mathf.RoundToInt(count * OutpostsMod.Settings.ProductionMultiplier);
while (count > thingDef.stackLimit)
{
var temp = ThingMaker.MakeThing(thingDef, stuff);
temp.stackCount = thingDef.stackLimit;
yield return temp;
count -= thingDef.stackLimit;
}

var temp2 = ThingMaker.MakeThing(thingDef, stuff);
temp2.stackCount = count;
yield return temp2;
}

public static string CheckSkill(this IEnumerable<Pawn> pawns, SkillDef skill, int minLevel)
{
return pawns.Sum(p => p.skills.GetSkill(skill).Level) < minLevel ? "Outposts.NotSkilledEnough".Translate(skill.skillLabel, minLevel) : null;
}
}

public class Dialog_RenameOutpost : Dialog_Rename
Expand Down

0 comments on commit ed791a0

Please sign in to comment.