diff options
Diffstat (limited to '')
-rw-r--r-- | src/T2DLL/T2Matter.cpp | 232 |
1 files changed, 232 insertions, 0 deletions
diff --git a/src/T2DLL/T2Matter.cpp b/src/T2DLL/T2Matter.cpp new file mode 100644 index 0000000..4af52e5 --- /dev/null +++ b/src/T2DLL/T2Matter.cpp @@ -0,0 +1,232 @@ +#include "T2Archive.h" +#include "T2Matter.h" +#include "T2ReturnStack.h" + +T2Matter::T2Matter() { + Initialize(); + mReturnStack = new T2ReturnStack; +} + +void T2Matter::Initialize() { + mMatterID = 0; + mMatterDef = NULL; + m18 = 0; + mWorkTenant = 0; + mHomeTenant = 0; + mCurrEquipID = 0; + mDstTenant = 0; + mCurPosition.y = 0; + mCurPosition.x = 0; + mCurrDestPos.y = 0; + mCurrDestPos.x = 0; + mStartTime = -1; + mReturnStack = NULL; + m44 = 0; + m48 = 0; + mDirection = -1; + mWalkStyle = 0; +} + +/*virtual*/ T2Matter::~T2Matter() { + delete mReturnStack; +} + +/*virtual*/ void T2Matter::SetUsed(BOOL used) { + T2Object::SetUsed(used); + if (used && mReturnStack) + mReturnStack->Init(); +} + +void T2Matter::Initialize(T2MatterDef* matterDef) { + mMatterDef = matterDef; + m18 = 0; + mWorkTenant = 0; + mHomeTenant = 0; + mCurrEquipID = 0; + mDstTenant = 0; + mCurPosition.y = 0; + mCurPosition.x = 0; + mCurrDestPos.y = 0; + mCurrDestPos.x = 0; + mStartTime = -1; + m44 = 0; + m48 = 0; + mDirection = -1; + mWalkStyle = 0; +} + +void T2Matter::FlipDirection() { + if (mDirection == 0) + mDirection = 1; + else if (mDirection == 1) + mDirection = 0; +} + +void T2Matter::SetDestination(unsigned int dstTenant, unsigned int startTime) { + mDstTenant = dstTenant; + mStartTime = startTime; +} + +void T2Matter::ClearDestination() { + mDstTenant = 0; + mStartTime = -1; +} + +BOOL T2Matter::IsStartTime(unsigned int time) const { + BOOL result = false; + if (IsSetStartTime() && mStartTime <= (int) time) + result = true; + return result; +} + +BOOL T2Matter::IsSetReturn() const { + return mReturnStack->IsSet(); +} + +BOOL T2Matter::IsSetReturnTime() const { + return mReturnStack->IsSetTime(); +} + +unsigned int T2Matter::GetReturnTime() const { + return mReturnStack->GetTime(); +} + +unsigned int T2Matter::GetReturn() const { + return mReturnStack->GetTenant(); +} + +BOOL T2Matter::SetReturn(unsigned int tenant, unsigned int time) { + return mReturnStack->Push(tenant, time); +} + +void T2Matter::SetReturnTime(unsigned int time) { + mReturnStack->SetTime(time); +} + +BOOL T2Matter::PopReturn(unsigned int& outTenant, unsigned int& outTime) { + return mReturnStack->Pop(outTenant, outTime); +} + +BOOL T2Matter::SetReturnToDestination() { + BOOL result = false; + unsigned int tenant, time; + if (mReturnStack->Pop(tenant, time)) { + SetDestination(tenant, time); + result = true; + } + return result; +} + +BOOL T2Matter::SetDestinationToReturn() { + return SetReturn(mDstTenant, mStartTime); +} + +void T2Matter::DayChanged() { + if (mStartTime >= 1440) + mStartTime -= 1440; + else if (mStartTime > 1438) + mStartTime = 0; + + if (mReturnStack) + mReturnStack->DayChanged(); +} + +BOOL T2Matter::RemoveReturn(unsigned int tenant) { + BOOL result = false; + if (mReturnStack) + result = mReturnStack->Remove(tenant); + return result; +} + +/*virtual*/ void T2Matter::LoadSelf(T2Archive& archive, T2TowerDoc* towerDoc) { + T2Object::LoadSelf(archive, towerDoc); + + if (IsUsed()) { + unsigned short us; + short s; + char c; + DWORD code; + + archive >> mMatterID; + + archive >> us; + mWorkTenant = us; + archive >> us; + mHomeTenant = us; + archive >> us; + mCurrEquipID = us; + archive >> us; + mDstTenant = us; + + archive >> s; + mCurPosition.x = s; + archive >> s; + mCurPosition.y = s; + archive >> s; + mCurrDestPos.x = s; + archive >> s; + mCurrDestPos.y = s; + + archive >> s; + mStartTime = s; + + archive >> c; + mDirection = c; + archive >> c; + mWalkStyle = c; + + archive >> code; + if (code == 'RSTK') { + if (!mReturnStack) + mReturnStack = new T2ReturnStack; + mReturnStack->Read(archive, towerDoc); + } + } +} + +/*virtual*/ void T2Matter::SaveSelf(T2Archive& archive) { + T2Object::SaveSelf(archive); + + if (IsUsed()) { + unsigned short us; + short s; + char c; + DWORD code; + + archive << mMatterID; + + us = mWorkTenant; + archive << us; + us = mHomeTenant; + archive << us; + us = mCurrEquipID; + archive << us; + us = mDstTenant; + archive << us; + + s = mCurPosition.x; + archive << s; + s = mCurPosition.y; + archive << s; + s = mCurrDestPos.x; + archive << s; + s = mCurrDestPos.y; + archive << s; + + s = mStartTime; + archive << s; + + c = mDirection; + archive << c; + c = mWalkStyle; + archive << c; + + if (mReturnStack) + code = 'RSTK'; + else + code = 'xRSK'; + archive << code; + if (code == 'RSTK') + mReturnStack->Write(archive); + } +} |