forked from Katarn2000x/DiplomacyFixes
-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathFactionMapping.cs
85 lines (74 loc) · 2.3 KB
/
FactionMapping.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
85
using TaleWorlds.CampaignSystem;
using TaleWorlds.SaveSystem;
namespace DiplomacyFixes
{
[SaveableStruct(1000)]
struct FactionMapping
{
[SaveableProperty(1)]
internal IFaction Faction1 { get; private set; }
[SaveableProperty(2)]
internal IFaction Faction2 { get; private set; }
[SaveableField(3)]
private int _hashCode;
internal FactionMapping(IFaction faction1, IFaction faction2)
{
if (string.CompareOrdinal(faction1.StringId, faction2.StringId) < 0)
{
this.Faction1 = faction1;
this.Faction2 = faction2;
}
else
{
this.Faction1 = faction2;
this.Faction2 = faction1;
}
this._hashCode = FactionMapping.CalculateHash(this.Faction1.StringId + this.Faction2.StringId);
}
internal FactionMapping(FactionMapping other)
{
this.Faction1 = other.Faction1;
this.Faction2 = other.Faction2;
this._hashCode = other._hashCode;
}
public override bool Equals(object obj)
{
if (obj == null)
{
return false;
}
if (obj.GetType() != base.GetType())
{
return false;
}
FactionMapping FactionMapping = (FactionMapping)obj;
return this.Faction1 == FactionMapping.Faction1 && this.Faction2 == FactionMapping.Faction2;
}
public bool Equals(FactionMapping p)
{
return this.Faction1 == p.Faction1 && this.Faction2 == p.Faction2;
}
public static bool operator ==(FactionMapping per1, FactionMapping per2)
{
return per1.Equals(per2);
}
public static bool operator !=(FactionMapping per1, FactionMapping per2)
{
return !per1.Equals(per2);
}
private static int CalculateHash(string s)
{
int num = 0;
for (int i = 0; i < s.Length; i++)
{
num *= 17;
num += (int)(char.ToUpper(s[i]) - '0');
}
return num;
}
public override int GetHashCode()
{
return this._hashCode;
}
}
}