diff options
Diffstat (limited to 'src/T2DLL/T2Request.cpp')
-rw-r--r-- | src/T2DLL/T2Request.cpp | 834 |
1 files changed, 747 insertions, 87 deletions
diff --git a/src/T2DLL/T2Request.cpp b/src/T2DLL/T2Request.cpp index 7ae0b8e..a1607d0 100644 --- a/src/T2DLL/T2Request.cpp +++ b/src/T2DLL/T2Request.cpp @@ -1,118 +1,778 @@ +#include "T2Archive.h" +#include "T2BitImage.h" +#include "T2FloorInfo.h" +#include "T2Mover.h" +#include "T2People.h" +#include "T2PeopleArrayList.h" +#include "T2PeopleLinkIterator.h" #include "T2Request.h" +#include "T2Tenant.h" +#include "T2TowerDoc.h" +#include "T2TowerMainView.h" +#include "UT2Coordinate.h" +#include <MINMAX.H> T2Request::T2Request() { + mRequestID = 0; + mMoverID = 0; + mIsGoDown = false; + mHeadPosition.y = 0; + mHeadPosition.x = 0; + mModuleIndex = -1; + mDrawWidth = 0; + m2C = 0; + m30 = 0; + mOnPeople = NULL; + mOffPeople = NULL; + mFirst = NULL; + mLast = NULL; + m44 = false; + mPeopleRemoved = false; + mNumOfContent = 0; } /*virtual*/ T2Request::~T2Request() { } void T2Request::InitRequest(unsigned int, int, const RECT&) { -} - -void T2Request::InitRequest(T2FloorInfo*, unsigned int, POINT, ERequestUpDown) { -} - -void T2Request::RemoveRequest(T2TowerDoc*) { -} - -void T2Request::RemoveContents(T2FloorInfo*) { -} - -/*virtual*/ void T2Request::SetUsed(int) { -} - -void T2Request::StopRemoved(T2TowerDoc*, int) { -} - -void T2Request::CalcArea(RECT&) { -} - -void T2Request::CalcOnArea(RECT&) { -} - -void T2Request::CalcOffArea(RECT&) { -} - -void T2Request::CalcPrevArea(RECT&) { -} - -int T2Request::CalcPersonArea(T2People*, RECT&) { -} - -/*virtual*/ int T2Request::Enter(CLink*) { -} - -/*virtual*/ int T2Request::Leave(CLink*) { +#line 34 + _ASSERT(0); +} + +void T2Request::InitRequest(T2FloorInfo* floorInfo, unsigned int moverID, POINT headPosition, ERequestUpDown upDown) { + SetUsed(true); + mMoverID = moverID; + mHeadPosition = headPosition; + mModuleIndex = -1; + m2C = 0; + m30 = 0; + mOnPeople = NULL; + mOffPeople = NULL; + mFirst = NULL; + mLast = NULL; + m44 = false; + mPeopleRemoved = false; + mNumOfContent = 0; + + if (upDown == ERequestUpDown_0) + mIsGoDown = false; + else + mIsGoDown = true; + + mDrawWidth = floorInfo->FillRequestID(mHeadPosition, upDown, mRequestID); +} + +void T2Request::RemoveRequest(T2TowerDoc* towerDoc) { + T2FloorInfo *floorInfo = towerDoc->towerDoc_vf12C(); + T2TowerMainView *mainView = towerDoc->GetTowerMainView(); + + RemoveContents(floorInfo); + + CRect prevArea; + CRect area; + CalcPrevArea(area); + CalcArea(area); + + ERequestUpDown upDown; + if (mIsGoDown) + upDown = ERequestUpDown_1; + else + upDown = ERequestUpDown_0; + + floorInfo->RemoveRequestID(upDown, area); + SetUsed(false); + floorInfo->SetTenantDrawModeByRect(prevArea, DrawMode1); + + if (mainView) + mainView->tmv_vf128(area, false); +} + +void T2Request::RemoveContents(T2FloorInfo* floorInfo) { + T2Tenant *theFloor = floorInfo->GetFloor(mHeadPosition.y, mHeadPosition.x); +#line 102 + _ASSERT(theFloor != NULL); + + if (mOnPeople) { + theFloor->Enter(mOnPeople); + mOnPeople = NULL; + } + if (mOffPeople) { + theFloor->Enter(mOffPeople); + mOffPeople = NULL; + } + + while (mFirst) { + T2People *people = mFirst; + Leave(people); + theFloor->Enter(people); + } +} + +/*virtual*/ void T2Request::SetUsed(BOOL used) { + BOOL oldUsed = mUsed; + T2Object::SetUsed(used); +} + +void T2Request::StopRemoved(T2TowerDoc* towerDoc, int y) { + T2FloorInfo *theFloorInfo = towerDoc->towerDoc_vf12C(); + T2Tenant *theFloor = theFloorInfo->GetFloor(mHeadPosition.y, mHeadPosition.x); +#line 138 + _ASSERT(theFloor != NULL); + + if (mOnPeople && mOnPeople->GetCurrDestPos().y == y) { + theFloor->Enter(mOnPeople); + mOnPeople = NULL; + } + if (mOffPeople && mOffPeople->GetCurrDestPos().y == y) { + theFloor->Enter(mOffPeople); + mOffPeople = NULL; + } + + T2PeopleLinkIterator iterator(mFirst); + T2People *people = NULL; + T2People *nextPeople = NULL; + iterator.Next(&people); + while (people) { + iterator.Next(&nextPeople); + if (people->GetCurrDestPos().y == y) { + Leave(people); + theFloor->Enter(people); + } + people = nextPeople; + nextPeople = NULL; + } +} + +void T2Request::CalcArea(RECT& outRect) { + outRect.top = mHeadPosition.y; + outRect.bottom = outRect.top + 1; + outRect.left = outRect.right = mHeadPosition.x; + + if (mIsGoDown) + outRect.right = outRect.left + mDrawWidth + 2; + else + outRect.left = outRect.right - mDrawWidth - 2; +} + +void T2Request::CalcOnArea(RECT& outRect) { + outRect.top = mHeadPosition.y; + outRect.bottom = outRect.top + 1; + + if (mIsGoDown) { + outRect.left = mHeadPosition.x; + outRect.right = outRect.left + 2; + } else { + outRect.right = mHeadPosition.x; + outRect.left = outRect.right - 2; + } +} + +void T2Request::CalcOffArea(RECT& outRect) { + outRect.top = mHeadPosition.y; + outRect.bottom = outRect.top + 1; + + if (mIsGoDown) { + outRect.left = mHeadPosition.x; + outRect.right = outRect.left + 1; + } else { + outRect.right = mHeadPosition.x; + outRect.left = outRect.right - 1; + } +} + +void T2Request::CalcPrevArea(RECT& outRect) { + outRect.top = mHeadPosition.y; + outRect.bottom = outRect.top + 1; + + short width; + if (m2C < mDrawWidth) + width = m2C; + else + width = mDrawWidth; + + if (mIsGoDown) { + outRect.left = mHeadPosition.x + 2; + outRect.right = outRect.left + width; + } else { + outRect.right = mHeadPosition.x - 2; + outRect.left = outRect.right - width; + } +} + +BOOL T2Request::CalcPersonArea(T2People* inPeople, RECT& outRect) { + BOOL result = false; + + RECT area; + CalcArea(area); + + if (mIsGoDown) { + int h = area.left + 2; + if (mFirst) { + T2PeopleLinkIterator iterator(mFirst); + T2People *iterPeople; + while (iterator.Next(&iterPeople) && h < area.right) { + if (iterPeople == inPeople) { + outRect = area; + outRect.left = h; + outRect.right = h + iterPeople->GetWidth(); + result = true; + } else { + h += iterPeople->GetWidth(); + } + } + } + } else { + int h = area.right - 2; + if (mFirst) { + T2PeopleLinkIterator iterator(mFirst); + T2People *iterPeople; + while (iterator.Next(&iterPeople) && h > area.left) { + if (iterPeople == inPeople) { + outRect = area; + outRect.right = h; + outRect.left = h - iterPeople->GetWidth(); + result = true; + } else { + h -= iterPeople->GetWidth(); + } + } + } + } + + return result; +} + +/*virtual*/ BOOL T2Request::Enter(CLink* link) { + BOOL result = false; + + if (!mFirst) { + mFirst = (T2People *) link; + mLast = (T2People *) link; + link->SetPrev(NULL); + result = true; + } else if (mLast) { + mLast->InsertAt(link); + mLast = (T2People *) link; + result = true; + } + + if (result) { + m30 += ((T2People *) link)->GetWidth(); + mNumOfContent++; + } + + return result; +} + +/*virtual*/ BOOL T2Request::Leave(CLink* link) { + BOOL result = false; + + if (mFirst) { + if (mFirst == link) { + // element was at the start of the list + mFirst = (T2People *) link->GetNext(); + if (!mFirst) { + // list is now empty + mLast = NULL; + } else if (!mFirst->GetNext()) { + // mFirst is the only remaining element + mLast = mFirst; + } + link->Remove(); + } else if (mLast != link) { + // element was in the middle of the list + link->Remove(); + } else { + // element was at the end of the list + mLast = (T2People *) link->GetPrev(); + link->Remove(); + if (!mLast) { + // how can this even happen?? + mFirst = NULL; + } + } + + result = true; + + if (result) { + mNumOfContent--; + m30 -= ((T2People *) link)->GetWidth(); + m44 = true; + } + } + + return result; } T2People* T2Request::LeaveFirst() { -} - -int T2Request::Regist(T2TowerDoc*, T2People*) { -} - -void T2Request::ChangeOffPPLStatus(T2FloorInfo*, T2People*) { -} - -void T2Request::AddOnPeople(T2People*) { + T2People *people = NULL; + if (mFirst) { + people = mFirst; + Leave(people); + } + return people; +} + +BOOL T2Request::Regist(T2TowerDoc* towerDoc, T2People* people) { + BOOL result = false; + T2FloorInfo *theFloorInfo = towerDoc->towerDoc_vf12C(); + POINT position = mHeadPosition; + POINT curPos = people->GetCurPosition(); + + if (mIsGoDown) + position.x += 2; + else + position.x -= 4; + + if (curPos.y == position.y && curPos.x == position.x) { + POINT destPos = people->GetCurrDestPos(); + if (people->IsGoDown() == mIsGoDown) { + T2Mover *theMover = theFloorInfo->GetMover(mMoverID); + if (theMover && theMover->IsStopPosition(theMover->UnitToPosition(destPos.y))) { + T2Tenant *theTenant = theFloorInfo->GetTenant(people->GetCurrEquipID()); + if (theTenant) { + theTenant->Leave(people); + Enter(people); + people->SetCurrEquipID(mRequestID); + + if (mIsGoDown) + people->SetDirection(1); + else + people->SetDirection(0); + + people->ChangeStatus(6); + result = true; + } + } + } + } + + return result; +} + +void T2Request::ChangeOffPPLStatus(T2FloorInfo* floorInfo, T2People* people) { + if (mIsGoDown) + people->MoveHTo(mHeadPosition.x + 2); + else + people->MoveHTo(mHeadPosition.x - 4); + + POINT pt = people->GetCurPosition(); + T2Tenant *floor = floorInfo->GetFloor(pt.y, pt.x); + if (floor) { + floor->Enter(people); + people->ChangeStatus(4); + } else { + MessageBeep(0xFFFFFFFF); + } +} + +void T2Request::AddOnPeople(T2People* people) { + mOnPeople = people; + + if (mIsGoDown) { + people->MoveHTo(mHeadPosition.x); + people->SetDirection(1); + } else { + people->MoveHTo(mHeadPosition.x - 2); + people->SetDirection(0); + } + + people->ChangeStatus(7); } T2People* T2Request::RemoveOnPeople() { + T2People *people = NULL; + if (mOnPeople) { + people = mOnPeople; + mOnPeople = NULL; + mPeopleRemoved = true; + } + return people; } -void T2Request::AddOffPeople(T2People*) { -} - -T2People* T2Request::RemoveOffPeople() { -} - -/*virtual*/ unsigned int T2Request::Idle(T2TowerDoc*) { -} +void T2Request::AddOffPeople(T2People* people) { + mOffPeople = people; + people->mCurPosition.y = mHeadPosition.y; -/*virtual*/ void T2Request::Draw(T2TowerDoc*, const RECT&) { -} + if (mIsGoDown) { + people->MoveHTo(mHeadPosition.x); + people->SetDirection(0); + } else { + people->MoveHTo(mHeadPosition.x - 2); + people->SetDirection(1); + } -void T2Request::DrawUp(T2TowerDoc*, const RECT&) { + people->mCurrEquipID = mRequestID; + people->ChangeStatus(9); } -void T2Request::DrawDown(T2TowerDoc*, const RECT&) { -} - -void* T2Request::GetInfoClick(T2TowerDoc*, POINT) { +T2People* T2Request::RemoveOffPeople() { + T2People *people = NULL; + if (mOffPeople) { + people = mOffPeople; + mOffPeople = NULL; + mPeopleRemoved = true; + } + return people; +} + +/*virtual*/ unsigned int T2Request::Idle(T2TowerDoc* towerDoc) { + unsigned int result = 0; + T2FloorInfo *theFloorInfo = towerDoc->towerDoc_vf12C(); + + if (mNumOfContent > 0 && !IsModuleReserved()) { + T2Mover *theMover = theFloorInfo->GetMover(mMoverID); + if (theMover) + theMover->SetCheckRequest(true); + } + + T2TowerMainView *theView = towerDoc->GetTowerMainView(); +#line 541 + _ASSERT(theView != NULL); + + CRect rect; + + if (mPeopleRemoved) { + CalcOnArea(rect); + theFloorInfo->SetTenantDrawModeByRect(rect, DrawMode1); + theView->tmv_vf128(rect, false); + } else if (mOnPeople || mOffPeople) { + CalcOnArea(rect); + theView->tmv_vf128(rect, false); + } + + if (m44) { + CalcPrevArea(rect); + theFloorInfo->SetTenantDrawModeByRect(rect, DrawMode1); + theView->tmv_vf128(rect, false); + } + + if (CalcIncQueueArea(rect)) + theView->tmv_vf128(rect, false); + + return result; +} + +/*virtual*/ void T2Request::Draw(T2TowerDoc* towerDoc, const RECT& inRect) { + if (mIsGoDown) + DrawDown(towerDoc, inRect); + else + DrawUp(towerDoc, inRect); + DrawFinished(); +} + +void T2Request::DrawUp(T2TowerDoc* towerDoc, const RECT& inRect) { + RECT myRect; + SetRect(&myRect, mHeadPosition.x - 2, mHeadPosition.y, mHeadPosition.x, mHeadPosition.y + 1); + + if (myRect.left < inRect.right) { + if (mOffPeople) + mOffPeople->Draw(towerDoc, inRect); + if (mOnPeople) + mOnPeople->Draw(towerDoc, inRect); + } + + OffsetRect(&myRect, -2, 0); + T2PeopleLinkIterator iterator(mFirst); + T2People *people; + while (iterator.Next(&people) && myRect.right > inRect.left) { + if (myRect.left < inRect.right) + people->Draw(towerDoc, inRect); + OffsetRect(&myRect, -people->GetWidth(), 0); + } +} + +void T2Request::DrawDown(T2TowerDoc* towerDoc, const RECT& inRect) { + RECT myRect; + SetRect(&myRect, mHeadPosition.x, mHeadPosition.y, mHeadPosition.x + 2, mHeadPosition.y + 1); + + if (myRect.right > inRect.left) { + if (mOffPeople) + mOffPeople->Draw(towerDoc, inRect); + if (mOnPeople) + mOnPeople->Draw(towerDoc, inRect); + } + + OffsetRect(&myRect, 2, 0); + T2PeopleLinkIterator iterator(mFirst); + T2People *people; + while (iterator.Next(&people) && myRect.left < inRect.right) { + if (myRect.right > inRect.left) + people->Draw(towerDoc, inRect); + OffsetRect(&myRect, people->GetWidth(), 0); + } +} + +void* T2Request::GetInfoClick(T2TowerDoc* towerDoc, POINT pt) { + void *result; + + if (mIsGoDown) + result = GetInfoClickDown(towerDoc, pt); + else + result = GetInfoClickUp(towerDoc, pt); + + return result; } void* T2Request::GetInfoClickUp(T2TowerDoc*, POINT) { + return NULL; } void* T2Request::GetInfoClickDown(T2TowerDoc*, POINT) { -} - -void T2Request::BreakoutEmergency(T2TowerDoc*) { -} - -/*virtual*/ void T2Request::LoadSelf(T2Archive&, T2TowerDoc*) { -} - -/*virtual*/ void T2Request::SaveSelf(T2Archive&) { -} - -T2People* T2Request::FindPeople(int) const { -} - -int T2Request::CalcIncQueueArea(RECT&) const { + return NULL; +} + +void T2Request::BreakoutEmergency(T2TowerDoc* towerDoc) { + RemoveContents(towerDoc->towerDoc_vf12C()); +} + +/*virtual*/ void T2Request::LoadSelf(T2Archive& archive, T2TowerDoc* towerDoc) { + DWORD code; + archive >> code; +#line 719 + _ASSERT(code == '<RQ>'); + + T2Object::LoadSelf(archive, towerDoc); + if (IsUsed()) { + unsigned int ui; + unsigned short us; + unsigned char uc; + short s; + char c; + + archive >> us; + mRequestID = us; + archive >> us; + mMoverID = us; + + archive >> uc; + mIsGoDown = (uc != 0); + + archive >> s; + mHeadPosition.x = s; + archive >> s; + mHeadPosition.y = s; + + archive >> c; + mModuleIndex = c; + + archive >> s; + mDrawWidth = s; + + archive >> ui; + if (ui) + mOnPeople = towerDoc->mPeopleArrayList->FindPeople(ui); + else + mOnPeople = NULL; + archive >> ui; + if (ui) + mOffPeople = towerDoc->mPeopleArrayList->FindPeople(ui); + else + mOffPeople = NULL; + archive >> ui; + if (ui) + mFirst = towerDoc->mPeopleArrayList->FindPeople(ui); + else + mFirst = NULL; + archive >> ui; + if (ui) + mLast = towerDoc->mPeopleArrayList->FindPeople(ui); + else + mLast = NULL; + + if (mFirst) { + CLinkIterator iterator(mFirst); + CLink *link; + while (iterator.Next(&link)) { + mNumOfContent++; + m30 += ((T2People *) link)->GetWidth(); + } + } + } +} + +/*virtual*/ void T2Request::SaveSelf(T2Archive& archive) { + DWORD code = '<RQ>'; + archive << code; + + T2Object::SaveSelf(archive); + if (IsUsed()) { + unsigned int ui; + unsigned short us; + unsigned char uc; + short s; + char c; + + us = mRequestID; + archive << us; + us = mMoverID; + archive << us; + + uc = mIsGoDown ? 1 : 0; + archive << uc; + + archive << (short) mHeadPosition.x; + archive << (short) mHeadPosition.y; + + c = mModuleIndex; + archive << c; + + s = mDrawWidth; + archive << s; + + if (mOnPeople) + ui = mOnPeople->GetPeopleID(); + else + ui = 0; + archive << ui; + if (mOffPeople) + ui = mOffPeople->GetPeopleID(); + else + ui = 0; + archive << ui; + if (mFirst) + ui = mFirst->GetPeopleID(); + else + ui = 0; + archive << ui; + if (mLast) + ui = mLast->GetPeopleID(); + else + ui = 0; + archive << ui; + } +} + +T2People* T2Request::FindPeople(int inH) const { + T2People *result = NULL; + + if (mIsGoDown) + result = FindDownPeople(inH); + else + result = FindUpPeople(inH); + + return result; +} + +BOOL T2Request::CalcIncQueueArea(RECT& rect) const { + BOOL result = false; + + if (m30 > m2C && m2C < mDrawWidth) { + rect.top = mHeadPosition.y; + rect.bottom = rect.top + 1; + + int width; + if (m30 < mDrawWidth) + width = m30 - m2C; + else + width = mDrawWidth - m2C; + + if (mIsGoDown) { + rect.left = mHeadPosition.x + 2 + m2C; + rect.right = rect.left + width; + } else { + rect.right = mHeadPosition.x - 2 - m2C; + rect.left = rect.right - width; + } + + result = true; + } + + return result; } void T2Request::DrawFinished() { -} - -T2People* T2Request::FindUpPeople(int) const { -} - -T2People* T2Request::FindDownPeople(int) const { -} - -void T2Request::CalcValidArea(RECT&) { -} - -/*virtual*/ void T2Request::DrawHitMask(T2TowerDoc*) { + m2C = m30; + m44 = false; + mPeopleRemoved = false; +} + +T2People* T2Request::FindUpPeople(int inH) const { + T2People *result = NULL; + + int minH = mHeadPosition.x; + int maxH = minH - 2; + + if (inH >= maxH) { + if (mOffPeople) + result = mOffPeople; + else if (mOnPeople) + result = mOnPeople; + } + + if (!result) { + minH = maxH; + T2PeopleLinkIterator iterator(mFirst); + T2People *people; + + while (!result && iterator.Next(&people)) { + maxH -= people->GetWidth(); + if (inH >= maxH && inH < minH) + result = people; + minH = maxH; + } + } + + return result; +} + +T2People* T2Request::FindDownPeople(int inH) const { + T2People *result = NULL; + + int minH = mHeadPosition.x; + int maxH = minH + 2; + + if (inH < maxH) { + if (mOffPeople) + result = mOffPeople; + else if (mOnPeople) + result = mOnPeople; + } + + if (!result) { + minH = maxH; + T2PeopleLinkIterator iterator(mFirst); + T2People *people; + + while (!result && iterator.Next(&people)) { + maxH += people->GetWidth(); + if (inH < maxH && inH >= minH) + result = people; + minH = maxH; + } + } + + return result; +} + +void T2Request::CalcValidArea(RECT& rect) { + rect.top = mHeadPosition.y; + rect.bottom = rect.top + 1; + rect.right = mHeadPosition.x; + rect.left = rect.right; + + RECT area; + CalcArea(area); + + int width = 0; + + if (mFirst) { + width = 2; + T2PeopleLinkIterator iterator(mFirst); + T2People *people; + while (iterator.Next(&people) && width < (area.right - area.left)) + width += people->GetWidth(); + } + + if (mIsGoDown) + rect.right = rect.left + width; + else + rect.left = rect.right - width; +} + +/*virtual*/ void T2Request::DrawHitMask(T2TowerDoc* towerDoc) { + RECT area; + CalcValidArea(area); + UT2Coordinate::UnitToQD(area, towerDoc->towerDoc_vf108()); + towerDoc->towerDoc_vf10C()->FillRect(area, 1); } |