diff options
Diffstat (limited to 'src/T2DLL/T2Transport.cpp')
-rw-r--r-- | src/T2DLL/T2Transport.cpp | 286 |
1 files changed, 269 insertions, 17 deletions
diff --git a/src/T2DLL/T2Transport.cpp b/src/T2DLL/T2Transport.cpp index 176c1d7..a3e1ac3 100644 --- a/src/T2DLL/T2Transport.cpp +++ b/src/T2DLL/T2Transport.cpp @@ -1,70 +1,322 @@ +#include "CResFile.h" +#include "LArray.h" +#include "T2Archive.h" +#include "T2DateTime.h" +#include "T2People.h" +#include "T2PeopleArrayList.h" +#include "T2Pool.h" +#include "T2TowerDoc.h" #include "T2Transport.h" +#include "T2WorldDef.h" T2Transport::T2Transport() { + Initialize(); + mCapacity = 60; } /*virtual*/ T2Transport::~T2Transport() { + delete mArray; } void T2Transport::Initialize() { + mParent = NULL; + mArray = NULL; + + _C = 0; + mWidth = 0; + _14 = 0; + mStation = 0; + mGrade = 0; + mTrainType = 0; + _24 = 0; + mArriveTime = 0; + _2C = 0; + mFlag = false; + + mCapacity = 0; + mNumOfContents = 0; + + mFirstLink = NULL; + mLastLink = NULL; } -void T2Transport::Init(T2Transport*, CResFile*) { +void T2Transport::Init(T2Transport* inParent, CResFile* inResFile) { + mWidth = DoGetWorldDef()->GetWidth(); + mStation = mWidth / 2; + + mParent = inParent; + + int v; + *inResFile >> v; + mArriveTime = v; + + *inResFile >> mTrainType; + + mArray = (mParent == this) ? new LArray : NULL; } -void T2Transport::Init(T2Transport*, int) { +void T2Transport::Init(T2Transport* inParent, int inArriveTime) { + mParent = inParent; + mArriveTime = inArriveTime; + mArray = (mParent == this) ? new LArray : NULL; } -void T2Transport::AddTransport(T2Transport*) { +void T2Transport::AddTransport(T2Transport* inTransport) { + if (mParent == this) { + if (mArray) + mArray->Add(&inTransport); + } else { + mParent->AddTransport(inTransport); + } } int T2Transport::GetNofTimeTable() { + int result = 12; + + if (mParent == this) { + if (mArray) + result = mArray->GetCount(); + } else { + result = mParent->GetNofTimeTable(); + } + + return result; } -void T2Transport::SetStation(unsigned int) { +void T2Transport::SetStation(unsigned int inStation) { + if (mParent == this) { + T2Transport *obj; + for (int i = 0; (obj = GetIndObject(i)); i++) + obj->mStation = inStation; + } else { + mParent->SetStation(inStation); + } } -void T2Transport::UpGrade(int) { +void T2Transport::UpGrade(int inGrade) { + if (mParent == this) { + T2Transport *obj; + for (int i = 0; (obj = GetIndObject(i)); i++) { + obj->mGrade = inGrade; + if (obj->mTrainType < obj->mGrade) + obj->mFlag = true; + } + } else { + mParent->UpGrade(inGrade); + } } -int T2Transport::GetTrainType(int) const { +int T2Transport::GetTrainType(int inIndex) const { + return GetIndObject(inIndex)->mTrainType; } -unsigned int T2Transport::GetArriveTime(int) const { +unsigned int T2Transport::GetArriveTime(int inIndex) const { + return GetIndObject(inIndex)->mArriveTime; } T2Transport* T2Transport::GetStoppage() const { + T2Transport *result = NULL; + + if (mParent == this) { + LArrayIterator iterator(*mArray); + T2Transport *obj; + while (!result && iterator.Next(&obj)) { + if (obj->ChkStoppage()) + result = obj; + } + } else { + result = mParent->GetStoppage(); + } + + return result; } -int T2Transport::WasStoppage() const { +BOOL T2Transport::WasStoppage() const { + if (mParent == this) { + T2Transport *obj; + for (int i = 0; (obj = GetIndObject(i)); i++) { + if (obj->ChkStoppage()) + return true; + } + + return false; + } else { + return mParent->WasStoppage(); + } } -int T2Transport::ChkStoppage() const { +BOOL T2Transport::ChkStoppage() const { + BOOL result = false; + + if (mFlag) { + T2DateTime *theNow = DoGetTowerDoc()->towerDoc_vf120(); + int nowMinutes = theNow->GetRawMinutes(); + int diff = nowMinutes - mArriveTime; + result = (diff >= 0 && diff < (_2C + 1)); + } + + return result; } -T2Transport* T2Transport::GetIndObject(int) const { +T2Transport* T2Transport::GetIndObject(int inIndex) const { + T2Transport *result = NULL; + + if (mParent == this) { + if (mArray) { + inIndex = (inIndex >= 0) ? (inIndex + 1) : mArray->GetCount(); + mArray->FetchItemAt(inIndex, &result); + } + } else { + result = mParent->GetIndObject(inIndex); + } + + return result; } -T2Transport* T2Transport::GetAvailable(T2DateTime*) const { +T2Transport* T2Transport::GetAvailable(T2DateTime* inDateTime) const { + T2Transport *result = NULL; + + if (mParent == this) { + LArrayIterator iterator(*mArray); + T2Transport *obj; + while (!result && iterator.Next(&obj)) { + if (obj->IsAvailable(inDateTime)) + result = obj; + } + } else { + result = mParent->GetAvailable(inDateTime); + } + + return result; } -int T2Transport::IsAvailable(T2DateTime*) { +BOOL T2Transport::IsAvailable(T2DateTime* inDateTime) { + BOOL result = false; + + if (mFlag && !IsFull()) { + int beginTime = DoGetBeginTime(); + result = inDateTime->WithinMinutes(beginTime - 60, beginTime); + } + + return result; } -int T2Transport::Enter(CLink*) { +BOOL T2Transport::Enter(CLink* inLink) { + mNumOfContents++; + + T2People *thePeople = (T2People *) inLink; + thePeople->ChangeStatus(kStatus16); + thePeople->SetCurrEquipID(0); + + if (!mFirstLink) { + mFirstLink = inLink; + mLastLink = inLink; + inLink->SetPrev(NULL); + return true; + } + + if (mLastLink) { + mLastLink->InsertAt(inLink); + mLastLink = inLink; + return true; + } + + return false; } -int T2Transport::Leave(CLink*) { +BOOL T2Transport::Leave(CLink* inLink) { + mNumOfContents--; + + if (mFirstLink) { + if (mFirstLink == inLink) { + mFirstLink = inLink->GetNext(); + if (mFirstLink == NULL) + mLastLink = NULL; + else if (mFirstLink->GetNext() == NULL) + mLastLink = mFirstLink; + + inLink->Remove(); + return true; + } else if (mLastLink != inLink) { + inLink->Remove(); + } else if (mLastLink == inLink) { + mLastLink = inLink->GetPrev(); + inLink->Remove(); + if (mLastLink == NULL) + mFirstLink = NULL; + + return true; + } + } + + return false; } CLink* T2Transport::LeaveFirst() { + CLink *result = NULL; + + if (mFirstLink) { + result = mFirstLink; + Leave(result); + } + + return result; } -/*virtual*/ int T2Transport::Stop(T2TowerDoc*) { +/*virtual*/ int T2Transport::Stop(T2TowerDoc* inDoc) { + T2People *thePeople = NULL; + + do { + thePeople = (T2People *) LeaveFirst(); + if (thePeople) + inDoc->towerDoc_vf130()->Enter(thePeople); + } + while (thePeople); + + DoSetStatus(0); + return 0; } -/*virtual*/ void T2Transport::Read(T2Archive&) { +/*virtual*/ void T2Transport::Read(T2Archive& inArchive) { + unsigned int theLinkData; + + inArchive >> theLinkData; + if (theLinkData) { + T2TowerDoc *theDoc = DoGetTowerDoc(); +#line 513 + _ASSERT(theDoc != NULL); + + T2PeopleArrayList *theList = theDoc->mPeopleArrayList; +#line 515 + _ASSERT(theList != NULL); + + mFirstLink = theList->FindPeople(theLinkData); +#line 517 + _ASSERT(mFirstLink != NULL); + + inArchive >> theLinkData; +#line 520 + _ASSERT(theLinkData != 0); + + mLastLink = theList->FindPeople(theLinkData); +#line 522 + _ASSERT(mLastLink != NULL); + + mNumOfContents = mFirstLink->Count(); + } } -/*virtual*/ void T2Transport::Write(T2Archive&) { +/*virtual*/ void T2Transport::Write(T2Archive& inArchive) { + unsigned int theLinkData = 0; + + if (mFirstLink) { + inArchive << ((T2People *) mFirstLink)->GetPeopleID(); + +#line 544 + _ASSERT(mLastLink != NULL); + + inArchive << ((T2People *) mLastLink)->GetPeopleID(); + } else { + inArchive << theLinkData; + } } |