forked from RimWorldMod/Tech-Advancing
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRules.cs
78 lines (71 loc) · 3.08 KB
/
Rules.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
using RimWorld;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace TechAdvancing
{
/// <summary>
/// Class storing all the Rules and helper methods.
/// </summary>
class Rules
{
public static Dictionary<TechLevel, int> researchProjectStoreTotal = new Dictionary<TechLevel, int>();
public static Dictionary<TechLevel, int> researchProjectStoreFinished = new Dictionary<TechLevel, int>();
public static TechLevel baseFactionLevel = TechLevel.Undefined;
/// <summary>
/// Gets the final techlevel. This includes limits as a maximum and the base faction techlevel as a minimum.
/// </summary>
/// <returns></returns>
internal static TechLevel GetNewTechLevel()
{
if (TechAdvancing_Config_Tab.b_configCheckboxNeedTechColonists)
{
return (TechLevel)(Math.Min((int)GetRuleTechlevel(), (int)GetLowTechTL()));
}
return GetRuleTechlevel();
}
/// <summary>
/// Gets the max techlevel that was generated by any rule. Also takes the faction-min techlevel into account.
/// </summary>
/// <returns></returns>
internal static TechLevel GetRuleTechlevel()
{
LogOutput.WriteLogMessage(Errorlevel.Debug, $"A: {RuleA().ToString()} | B:{RuleB().ToString()}");
return Util.GetHighestTechlevel(TechAdvancing_Config_Tab.baseFactionTechLevel, RuleA(), RuleB());
}
/// <summary>
/// Returns the lowTech colony limit. Only if the limit is applied.
/// </summary>
/// <returns></returns>
internal static TechLevel GetLowTechTL()
{
if (!TechAdvancing_Config_Tab.b_configCheckboxNeedTechColonists) // if the limit is not enabled at all
{
return TechLevel.Archotech;
}
else
{
return (TechAdvancing.MapCompSaveHandler.ColonyPeople.Any(x => x.Value?.def?.techLevel >= TechLevel.Industrial)) ? TechLevel.Archotech : TechAdvancing_Config_Tab.maxTechLevelForTribals;
}
}
internal static TechLevel RuleA()
{
var notResearched = researchProjectStoreTotal.Except(researchProjectStoreFinished);
int min = notResearched.Where(x => x.Value > 0).Select(x => (int)x.Key).DefaultIfEmpty(0).Min();
return (TechLevel)Util.Clamp(0, min - 1 + TechAdvancing_Config_Tab.Conditionvalue_A, (int)TechLevel.Archotech);
}
internal static TechLevel RuleB()
{
int result = 0; //tl undef
foreach (var tl in researchProjectStoreTotal.Where(x => x.Value > 0))
{
if ((float)researchProjectStoreFinished[tl.Key] / (float)tl.Value > (TechAdvancing_Config_Tab.Conditionvalue_B_s / 100f))
{
result = (int)tl.Key;
}
}
return (TechLevel)Util.Clamp(0, result + (int)TechAdvancing_Config_Tab.Conditionvalue_B, (int)TechLevel.Archotech);
}
}
}