#include "StdAfx.h" #include "T2Archive.h" #include "T2ElevatorModule.h" #include "T2ElvModuleList.h" #include "T2MoverDef.h" #include "../T2TowerDoc.h" #include "UT2Coordinate.h" T2ElvModuleList::T2ElvModuleList() { SetRect(&mModuleInset, 0, 0, 0, 0); } /*virtual*/ T2ElvModuleList::~T2ElvModuleList() { } /*virtual*/ BOOL T2ElvModuleList::Init(T2MoverDef* moverDef, const RECT& baseRect) { BOOL success = T2MoverModuleList::Init(moverDef, baseRect); if (success) { moverDef->GetModuleInset(mModuleInset); for (int i = 0; i < mMaxModule; i++) { T2ElevatorModule *elevatorModule = new T2ElevatorModule(i); if (elevatorModule) success = InsertModuleAt(mItemCount + 1, elevatorModule); else success = false; } } return success; } void T2ElvModuleList::AddModule(T2TowerDoc* towerDoc, int count, int position) { LArrayIterator iterator(*this); T2ElevatorModule *elevatorModule; while (iterator.Next(&elevatorModule)) { if (!elevatorModule->IsUsed()) { elevatorModule->Init(count, position); elevatorModule->SetModuleID(towerDoc); mModuleCount++; break; } } } /*virtual*/ void T2ElvModuleList::Destruct(T2TowerDoc* towerDoc) { LArrayIterator iterator(*this); T2ElevatorModule *elevatorModule = NULL; while (iterator.Next(&elevatorModule)) { if (elevatorModule) RemoveModule(towerDoc, elevatorModule); } } /*virtual*/ T2MoverModule* T2ElvModuleList::ConstructModule() { return new T2ElevatorModule(0); } void T2ElvModuleList::CalcBaseQDRect(RECT& outRect) { UT2Coordinate::UnitToQD(mBaseRect, outRect, 0, true); UT2Coordinate::AddRect(outRect, mModuleInset); } int T2ElvModuleList::DestructModule(T2TowerDoc* towerDoc, T2Mover* mover, POINT inPt) { RECT theBaseQDRect; int theModuleIndex = -1; int theZoomLevel = towerDoc->GetZoomLevel(); POINT pt = inPt; CalcBaseQDRect(theBaseQDRect); T2ElevatorModule *theElevatorModuleToRemove = NULL; LArrayIterator iter(*this, GetCount() + 1); T2ElevatorModule *theModule; while (!theElevatorModuleToRemove && iter.Previous(&theModule)) { if (theModule->IsPtInArea(pt, theBaseQDRect)) theElevatorModuleToRemove = theModule; } if (theElevatorModuleToRemove) { theModuleIndex = theElevatorModuleToRemove->GetIndex(); theElevatorModuleToRemove->Remove(towerDoc, mover); mModuleCount--; } return theModuleIndex; } BOOL T2ElvModuleList::IsHomePosition(int position) { BOOL isHomePosition = false; LArrayIterator iterator(*this); T2ElevatorModule *theModule = NULL; while (iterator.Next(&theModule) && !isHomePosition) { if (theModule && theModule->GetHomePosition() == position) isHomePosition = true; } return isHomePosition; } void T2ElvModuleList::MoverExpanded(T2Mover* mover, EEquipPos pos, int count) { if (pos == EEquipPos_3) OffsetRect(&mBaseRect, 0, count); LArrayIterator iterator(*this); T2ElevatorModule *elevatorModule; while (iterator.Next(&elevatorModule)) { if (elevatorModule->IsUsed()) elevatorModule->MoverExpanded(mover, pos, count); } } /*virtual*/ void T2ElvModuleList::StopAdded(T2TowerDoc* towerDoc, T2Mover* mover, int position) { LArrayIterator iterator(*this); T2ElevatorModule *elevatorModule; while (iterator.Next(&elevatorModule)) { if (elevatorModule->IsUsed()) elevatorModule->StopAdded(towerDoc, mover, position); } } /*virtual*/ void T2ElvModuleList::StopRemoved(T2TowerDoc* towerDoc, T2Mover* mover, int position) { LArrayIterator iterator(*this); T2ElevatorModule *elevatorModule; while (iterator.Next(&elevatorModule)) { if (elevatorModule->IsUsed()) elevatorModule->StopRemoved(towerDoc, mover, position); } } /*virtual*/ void T2ElvModuleList::Read(T2Archive& archive, T2TowerDoc* towerDoc) { T2MoverModuleList::Read(archive, towerDoc); int numOfModules; archive >> numOfModules; mMaxModule = numOfModules; BOOL ok = true; for (int i = 0; i < numOfModules && ok; i++) { T2ElevatorModule *elevatorModule = new T2ElevatorModule(i); if (elevatorModule) { elevatorModule->Load(archive, towerDoc); ok = InsertModuleAt(mItemCount + 1, elevatorModule); } } LArrayIterator iter(*this); T2ElevatorModule *theModule; while (iter.Next(&theModule)) { if (theModule->IsUsed()) mModuleCount++; } archive.ReadSRect(mModuleInset); } /*virtual*/ void T2ElvModuleList::Write(T2Archive& archive) { T2MoverModuleList::Write(archive); archive.WriteSRect(mModuleInset); }