#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) { int result = -1; int zoomLevel = towerDoc->towerDoc_vf108(); POINT pt = inPt; RECT baseQDRect; CalcBaseQDRect(baseQDRect); T2ElevatorModule *foundModule = NULL; LArrayIterator iterator(*this, GetCount() + 1); T2ElevatorModule *elevatorModule; while (!foundModule && iterator.Previous(&elevatorModule)) { if (elevatorModule->IsPtInArea(pt, baseQDRect)) foundModule = elevatorModule; } if (foundModule) { result = foundModule->GetIndex(); foundModule->Remove(towerDoc, mover); mModuleCount--; } return result; } BOOL T2ElvModuleList::IsHomePosition(int position) { BOOL result = false; LArrayIterator iterator(*this); T2ElevatorModule *elevatorModule = NULL; while (iterator.Next(&elevatorModule) && !result) { if (elevatorModule && elevatorModule->GetHomePosition() == position) result = true; } return result; } 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 count; archive >> count; mMaxModule = count; BOOL ok = true; for (int i = 0; i < count && ok; i++) { T2ElevatorModule *elevatorModule = new T2ElevatorModule(i); if (elevatorModule) { elevatorModule->Load(archive, towerDoc); ok = InsertModuleAt(mItemCount + 1, elevatorModule); } } LArrayIterator iterator(*this); T2ElevatorModule *elevatorModule; while (iterator.Next(&elevatorModule)) { if (elevatorModule->IsUsed()) mModuleCount++; } archive.ReadSRect(mModuleInset); } /*virtual*/ void T2ElvModuleList::Write(T2Archive& archive) { T2MoverModuleList::Write(archive); archive.WriteSRect(mModuleInset); }