-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathCConditionSet.cpp
102 lines (76 loc) · 2.32 KB
/
CConditionSet.cpp
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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
// CConditionSet.cpp
//
// CConditionSet class
// Copyright (c) 2018 Kronosaur Productions, LLC. All Rights Reserved.
#include "PreComp.h"
static TStaticStringTable<TStaticStringEntry<CConditionSet::ETypes>, CConditionSet::cndCount> CONDITION_TABLE = {
"blind", CConditionSet::cndBlind,
"disarmed", CConditionSet::cndDisarmed,
"dragged", CConditionSet::cndDragged,
"lrsBlind", CConditionSet::cndLRSBlind,
"paralyzed", CConditionSet::cndParalyzed,
"radioactive", CConditionSet::cndRadioactive,
"shipScreenDisabled", CConditionSet::cndShipScreenDisabled,
"spinning", CConditionSet::cndSpinning,
"timeStopped", CConditionSet::cndTimeStopped,
};
bool CConditionSet::Diff (const CConditionSet &OldSet, TArray<ETypes> &Added, TArray<ETypes> &Removed) const
// Diff
//
// Compares all flags against the previous set and returns TRUE if anything
// changed. Added and Removed are initialized with the changes.
{
int i;
if (m_dwSet == OldSet.m_dwSet)
return false;
DWORD dwFlag = 1;
for (i = 0; i < cndCount; i++)
{
// If we have this condition, but the old set does not, then it got
// added.
if ((m_dwSet & dwFlag) && !(OldSet.m_dwSet & dwFlag))
Added.Insert((ETypes)dwFlag);
// If the old set had this condition but we don't, it got removed
else if ((OldSet.m_dwSet & dwFlag) && !(m_dwSet & dwFlag))
Removed.Insert((ETypes)dwFlag);
// Next flag
dwFlag = dwFlag << 1;
}
return true;
}
CConditionSet::ETypes CConditionSet::ParseCondition (const CString &sCondition)
// ParseCondition
//
// Parses a condition.
{
auto pEntry = CONDITION_TABLE.GetAt(sCondition);
if (pEntry == NULL)
return cndNone;
return pEntry->Value;
}
void CConditionSet::Set (const CConditionSet &Conditions)
// Set
//
// Sets all the given conditions.
{
if (Conditions.IsEmpty())
return;
m_dwSet |= Conditions.m_dwSet;
}
ICCItemPtr CConditionSet::WriteAsCCItem (void) const
// WriteAsCCItem
//
// Returns a CC list with all conditions (or Nil if none).
{
CCodeChain &CC = g_pUniverse->GetCC();
ICCItemPtr pResult(CC.CreateLinkedList());
for (int i = 0; i < CONDITION_TABLE.GetCount(); i++)
{
if (m_dwSet & CONDITION_TABLE[i].Value)
pResult->AppendString(CC, CString(CONDITION_TABLE.GetKey(i)));
}
if (pResult->GetCount() == 0)
return ICCItemPtr(CC.CreateNil());
else
return pResult;
}