summaryrefslogtreecommitdiff
path: root/src/T2DLL/T2PeopleType.cpp
blob: 7ad3966776e5e7044f3d9be5d5cecf08999afd9a (plain)
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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
#include "StdAfx.h"
#include "T2Archive.h"
#include "T2PeopleType.h"
#include "T2TenantMemberDef.h"
#include "UT2Utils.h"

T2PeopleType::T2PeopleType() {
	mAttribute = 0;
	mSilhouetteType = 0;
	mEconoType = 0;
	mTransportType = 0;
	mLife = 0;
}

T2PeopleType::~T2PeopleType() {
}

void T2PeopleType::SetDemandType(int v) {
	mAttribute &= 0xF8;
	mAttribute |= (v & 7);
}

void T2PeopleType::SetTimeZoneType(int v) {
	mAttribute &= 7;
	mAttribute |= ((v << 3) & 0xF8);
}

int T2PeopleType::GetDemandType() const {
	return mAttribute & 7;
}

int T2PeopleType::GetTimeZoneType() const {
	return (mAttribute & 0xF8) >> 3;
}

void T2PeopleType::RecoverLife() {
	if (!IsImmortal())
		mLife = 12;
}

void T2PeopleType::Duplicate(T2PeopleType& dest) const {
	dest = *this;
	dest.mLife = 1;

	int econoType = mEconoType + UT2Utils::Randomize(3) - 1;
	if (econoType <= 0)
		econoType = 1;
	else if (econoType >= 7)
		econoType = 6;
	dest.mEconoType = econoType;
}

BOOL T2PeopleType::Check(T2TenantMemberDef* def, int inEconoType, unsigned int inRoute) const {
	BOOL result = (inRoute & (1 << mTransportType)) != 0;

	if (result)
		result = CheckSilhouetteType(def);
	if (result)
		result = CheckSilhouetteOptionType(def->GetOptionType());
	if (result && inEconoType > -1) {
		if (mEconoType < inEconoType || mEconoType >= (inEconoType + 3))
			result = false;
	}

	return result;
}

BOOL T2PeopleType::CheckWithDemand(T2TenantMemberDef* def, int econoType) const {
	return (CheckDemandType(def->GetDemandType()) && Check(def, econoType, 0xFF));
}

BOOL T2PeopleType::CheckDemandType(int demandType) const {
	BOOL result = true;

	if (demandType != -1 && GetDemandType() != demandType)
		result = false;

	return result;
}

BOOL T2PeopleType::CheckSilhouetteType(T2TenantMemberDef* def) const {
	BOOL result = true;
	int start = def->GetStartSilhouetteType();

	if (start < -1) {
		switch (start) {
			case -3:
				if (mSilhouetteType < 8 || mSilhouetteType >= 16)
					result = false;
				break;
			case -4:
				if (mSilhouetteType < 16 || mSilhouetteType >= 24)
					result = false;
				break;
			case -5:
				if (mSilhouetteType < 24 || mSilhouetteType >= 56)
					result = false;
				break;
			case -6:
				if (mSilhouetteType < 30 || mSilhouetteType >= 51)
					result = false;
				break;
		}
	} else if (start > -1) {
		if (mSilhouetteType < start) {
			result = false;
		} else {
			int end = def->GetEndSilhouetteType();
			if (mSilhouetteType > end)
				result = false;
		}
	}

	return result;
}

BOOL T2PeopleType::CheckSilhouetteOptionType(int var) const {
	BOOL result = true;

	if (var > -1) {
		if (var & 1) {
			if ((mSilhouetteType % 2) != 0)
				result = false;
		} else if (var & 2) {
			if ((mSilhouetteType % 2) == 0)
				result = false;
		}

		if (var & 4) {
			if (((mSilhouetteType / 4) % 2) != 0)
				result = false;
		} else if (var & 8) {
			if (((mSilhouetteType / 4) % 2) == 0)
				result = false;
		}
	}

	return result;
}

void T2PeopleType::Read(T2Archive& archive) {
	char v;
	archive >> v;
	mAttribute = v;
	archive >> v;
	mSilhouetteType = v;
	archive >> v;
	mEconoType = v;
	archive >> v;
	mTransportType = v;
	archive >> v;
	mLife = v;
}

void T2PeopleType::Write(T2Archive& archive) {
	archive << (char) mAttribute;
	archive << (char) mSilhouetteType;
	archive << (char) mEconoType;
	archive << (char) mTransportType;
	archive << (char) mLife;
}