#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; }