forked from RimWorldMod/Tech-Advancing
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathUtil.cs
84 lines (77 loc) · 3.01 KB
/
Util.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
using RimWorld;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace TechAdvancing
{
class Util
{
/// <summary>
/// Helper method for clamping an int value.
/// </summary>
/// <param name="min">Lower limit.</param>
/// <param name="val">The value.</param>
/// <param name="max">Upper limit.</param>
/// <returns>The value or the border that was exceeded.</returns>
internal static int Clamp(int min, int val, int max) //helper method
{
if (val < min)
{
return min;
}
else if (max < val)
{
return max;
}
else
{
return val;
}
}
/// <summary>
/// Helper method for clamping a Techlevel.
/// </summary>
/// <param name="min">Lower limit.</param>
/// <param name="val">The value.</param>
/// <param name="max">Upper limit.</param>
/// <returns>The value or the border that was exceeded.</returns>
internal static TechLevel Clamp(TechLevel min, TechLevel val, TechLevel max) //helper method
{
if (val < min)
{
return min;
}
else if (max < val)
{
return max;
}
else
{
return val;
}
}
internal static bool ColonyHasHiTechPeople()
{
FactionDef[] hitechfactions = new FactionDef[] { FactionDefOf.Mechanoid, FactionDefOf.Ancients, FactionDefOf.PlayerColony };
string[] hightechkinds = new string[] { "colonist" };
//Debug
// foreach (var pawn in RimWorld.PawnsFinder.AllMaps_FreeColonists)
// {
// string techlvl = null;
// if (MapComponent_TA_Expose.TA_Expose_People?.ContainsKey(pawn)==true)
// {
// techlvl = ((int?)(MapComponent_TA_Expose.TA_Expose_People[pawn])?.def?.techLevel ?? -1).ToString();
// }
// LogOutput.writeLogMessage(Errorlevel.Warning, "Pawn: " + pawn?.Name + " |Faction: " + pawn?.Faction?.Name + " |DefName: " + pawn?.kindDef?.defaultFactionType?.defName + "|Tech lvl: "+ techlvl + " |High Tech (whitelist): " + (hitechfactions.Contains(pawn?.Faction?.def) ? "yes" : "no"));
//}
// LogOutput.writeLogMessage(Errorlevel.Warning,"done");
return MapCompSaveHandler.ColonyPeople.Any(x => x.Value?.def?.techLevel >= TechLevel.Industrial) || RimWorld.PawnsFinder.AllMaps_FreeColonists.Any(x => hightechkinds.Contains(x.kindDef.defName.ToLowerInvariant()));
}
internal static TechLevel GetHighestTechlevel(params TechLevel[] t)
{
var max = t.Select(x => (int)x).Max();
return (max > (int)TechLevel.Archotech) ? TechLevel.Archotech : (TechLevel)max;
}
}
}