#include "StdAfx.h" #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 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&) { #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 *theFloorInfo = towerDoc->GetFloorInfo(); T2TowerMainView *theView = towerDoc->GetMainView(); RemoveContents(theFloorInfo); CRect thePrevArea, theNextArea; CalcPrevArea(thePrevArea); CalcArea(theNextArea); ERequestUpDown upDown; if (mIsGoDown) upDown = ERequestUpDown_1; else upDown = ERequestUpDown_0; theFloorInfo->RemoveRequestID(upDown, theNextArea); SetUsed(false); theFloorInfo->SetTenantDrawModeByRect(thePrevArea, DrawMode1); if (theView) theView->InvalUnitRect(theNextArea, 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->GetFloorInfo(); 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 *thePeople = NULL; T2People *theNextPeople = NULL; iterator.Next(&thePeople); while (thePeople) { iterator.Next(&theNextPeople); if (thePeople->GetCurrDestPos().y == y) { Leave(thePeople); theFloor->Enter(thePeople); } thePeople = theNextPeople; theNextPeople = 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() { T2People *people = NULL; if (mFirst) { people = mFirst; Leave(people); } return people; } BOOL T2Request::Regist(T2TowerDoc* towerDoc, T2People* people) { BOOL isRegist = false; T2FloorInfo *theFloorInfo = towerDoc->GetFloorInfo(); POINT headPt = mHeadPosition; POINT curPt = people->GetCurPosition(); if (mIsGoDown) headPt.x += 2; else headPt.x -= 4; if (curPt.y == headPt.y && curPt.x == headPt.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); isRegist = true; } } } } return isRegist; } void T2Request::ChangeOffPPLStatus(T2FloorInfo* floorInfo, T2People* people) { if (mIsGoDown) people->MoveHTo(mHeadPosition.x + 2); else people->MoveHTo(mHeadPosition.x - 4); POINT curPos = people->GetCurPosition(); T2Tenant *floor = floorInfo->GetFloor(curPos.y, curPos.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* people) { mOffPeople = people; people->mCurPosition.y = mHeadPosition.y; if (mIsGoDown) { people->MoveHTo(mHeadPosition.x); people->SetDirection(0); } else { people->MoveHTo(mHeadPosition.x - 2); people->SetDirection(1); } people->mCurrEquipID = mRequestID; people->ChangeStatus(9); } 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->GetFloorInfo(); if (mNumOfContent > 0 && !IsModuleReserved()) { T2Mover *theMover = theFloorInfo->GetMover(mMoverID); if (theMover) theMover->SetCheckRequest(true); } T2TowerMainView *theView = towerDoc->GetMainView(); #line 541 _ASSERT(theView != NULL); CRect area; if (mPeopleRemoved) { CalcOnArea(area); theFloorInfo->SetTenantDrawModeByRect(area, DrawMode1); theView->InvalUnitRect(area, false); } else if (mOnPeople || mOffPeople) { CalcOnArea(area); theView->InvalUnitRect(area, false); } if (m44) { CalcPrevArea(area); theFloorInfo->SetTenantDrawModeByRect(area, DrawMode1); theView->InvalUnitRect(area, false); } if (CalcIncQueueArea(area)) theView->InvalUnitRect(area, 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 rect; SetRect(&rect, mHeadPosition.x - 2, mHeadPosition.y, mHeadPosition.x, mHeadPosition.y + 1); if (rect.left < inRect.right) { if (mOffPeople) mOffPeople->Draw(towerDoc, rect); if (mOnPeople) mOnPeople->Draw(towerDoc, rect); } OffsetRect(&rect, -2, 0); T2PeopleLinkIterator iterator(mFirst); T2People *people; while (iterator.Next(&people) && rect.right > inRect.left) { if (rect.left < inRect.right) people->Draw(towerDoc, rect); OffsetRect(&rect, -people->GetWidth(), 0); } } void T2Request::DrawDown(T2TowerDoc* towerDoc, const RECT& inRect) { RECT rect; SetRect(&rect, mHeadPosition.x, mHeadPosition.y, mHeadPosition.x + 2, mHeadPosition.y + 1); if (rect.right > inRect.left) { if (mOffPeople) mOffPeople->Draw(towerDoc, rect); if (mOnPeople) mOnPeople->Draw(towerDoc, rect); } OffsetRect(&rect, 2, 0); T2PeopleLinkIterator iterator(mFirst); T2People *people; while (iterator.Next(&people) && rect.left < inRect.right) { if (rect.right > inRect.left) people->Draw(towerDoc, rect); OffsetRect(&rect, 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) { return NULL; } void T2Request::BreakoutEmergency(T2TowerDoc* towerDoc) { RemoveContents(towerDoc->GetFloorInfo()); } /*virtual*/ void T2Request::LoadSelf(T2Archive& archive, T2TowerDoc* towerDoc) { DWORD code; archive >> code; #line 719 _ASSERT(code == ''); T2Object::LoadSelf(archive, towerDoc); if (IsUsed()) { #pragma var_order(uc, c, s, us, ui) 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 = ''; archive << code; T2Object::SaveSelf(archive); if (IsUsed()) { #pragma var_order(uc, c, s, us, ui) 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() { m2C = m30; m44 = false; mPeopleRemoved = false; } T2People* T2Request::FindUpPeople(int inH) const { T2People *theUpPeople = NULL; int rightH = mHeadPosition.x; int leftH = rightH - 2; if (inH >= leftH) { if (mOffPeople) theUpPeople = mOffPeople; else if (mOnPeople) theUpPeople = mOnPeople; } if (!theUpPeople) { rightH = leftH; T2PeopleLinkIterator iterator(mFirst); T2People *people; while (!theUpPeople && iterator.Next(&people)) { leftH -= people->GetWidth(); if (inH >= leftH && inH < rightH) theUpPeople = people; rightH = leftH; } } return theUpPeople; } T2People* T2Request::FindDownPeople(int inH) const { T2People *theDownPeople = NULL; int leftH = mHeadPosition.x; int rightH = leftH + 2; if (inH < rightH) { if (mOffPeople) theDownPeople = mOffPeople; else if (mOnPeople) theDownPeople = mOnPeople; } if (!theDownPeople) { leftH = rightH; T2PeopleLinkIterator iterator(mFirst); T2People *people; while (!theDownPeople && iterator.Next(&people)) { rightH += people->GetWidth(); if (inH < rightH && inH >= leftH) theDownPeople = people; leftH = rightH; } } return theDownPeople; } 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->GetZoomLevel()); towerDoc->GetImage()->FillRect(area, 1); }