diff options
Diffstat (limited to 'src/T2DLL/T2OutsideInfo.cpp')
-rw-r--r-- | src/T2DLL/T2OutsideInfo.cpp | 146 |
1 files changed, 134 insertions, 12 deletions
diff --git a/src/T2DLL/T2OutsideInfo.cpp b/src/T2DLL/T2OutsideInfo.cpp index e90fb10..cf1f5c0 100644 --- a/src/T2DLL/T2OutsideInfo.cpp +++ b/src/T2DLL/T2OutsideInfo.cpp @@ -1,46 +1,168 @@ +#include "LArray.h" +#include "T2Archive.h" +#include "T2FloorInfo.h" +#include "T2OutObjArrayList.h" #include "T2OutsideInfo.h" -T2OutsideInfo::T2OutsideInfo(const T2FloorInfo&) { +T2OutsideInfo::T2OutsideInfo(const T2FloorInfo& inFloorInfo) + : mFloorInfo(inFloorInfo) +{ + UINT zero = 0; + mUnitInfo = new LArray(sizeof(UINT)); + mUnitInfo->InsertItemsAt(mFloorInfo.mHRange * mFloorInfo.mVRange, 1, &zero); + + mNextUnitInfo = -1; + SetRect(&mArea, 0, 0, 0, 0); } /*virtual*/ T2OutsideInfo::~T2OutsideInfo() { + if (mUnitInfo) + delete mUnitInfo; } void T2OutsideInfo::Reset() { + if (IsRectEmpty(&mArea)) { + mNextUnitInfo = -1; + } else { + mCurrentPt.x = mArea.left; + mCurrentPt.y = mArea.top; + + mCurrentPt.x--; + mNextUnitInfo = mFloorInfo.mHRange * mCurrentPt.y + mCurrentPt.x; + mCurrentOutObjID = 0; + } } -void T2OutsideInfo::SetArea(const RECT&) { +void T2OutsideInfo::SetArea(const RECT& inRect) { + IntersectRect(&mArea, &inRect, &mFloorInfo.mBuildArea); + Reset(); } POINT T2OutsideInfo::CurrentPt() const { + return mCurrentPt; } -unsigned int T2OutsideInfo::GetUnitInfo(int, int) const { +unsigned int T2OutsideInfo::GetUnitInfo(int inV, int inH) const { + unsigned int unitInfo = 0; + +#line 111 + _ASSERT((inV >= 0) && (inV < mFloorInfo.mVRange)); + _ASSERT((inH >= 0) && (inH < mFloorInfo.mHRange)); + + if (inV >= 0 && inV < mFloorInfo.mVRange && inH >= 0 && inH < mFloorInfo.mHRange) { + int index = mFloorInfo.mHRange * inV + inH; + mUnitInfo->FetchItemAt(index, &unitInfo); + } + + return unitInfo; } -T2OutObj* T2OutsideInfo::GetOutObj(int, int) const { +T2OutObj* T2OutsideInfo::GetOutObj(int inV, int inH) const { + unsigned int unitInfo = GetUnitInfo(inV, inH); + if (unitInfo) + return mFloorInfo.mOutObjArrayList->GetOutObjByID(unitInfo); + else + return NULL; } -void T2OutsideInfo::FillOutObjID(const RECT&, unsigned int) { +void T2OutsideInfo::FillOutObjID(const RECT& inRect, unsigned int inID) { + SetArea(inRect); + + int index; + while (NextIndex(index)) + mUnitInfo->AssignItemsAt(1, index, &inID); } -unsigned int T2OutsideInfo::GetOutObjID(int, int) const { +unsigned int T2OutsideInfo::GetOutObjID(int inV, int inH) const { + return GetUnitInfo(inV, inH); } -int T2OutsideInfo::CalcNextUnitInfo() { +BOOL T2OutsideInfo::CalcNextUnitInfo() { + BOOL result = true; + + if (!IsRectEmpty(&mArea)) { + if (mCurrentPt.y < mArea.bottom) { + mCurrentPt.x++; + if (mCurrentPt.x < mArea.right) { + mNextUnitInfo++; + } else { + mCurrentPt.x = mArea.left; + mCurrentPt.y++; + mNextUnitInfo += mFloorInfo.mHRange - (mArea.right - mArea.left) + 1; + + if (mCurrentPt.y >= mArea.bottom) + result = false; + } + } else { + result = false; + } + } else { + result = false; + } + + return result; } -int T2OutsideInfo::NextValue(unsigned int&) { +BOOL T2OutsideInfo::NextValue(unsigned int& outValue) { + BOOL result = true; + + if (CalcNextUnitInfo()) + mUnitInfo->FetchItemAt(mNextUnitInfo, &outValue); + else + result = false; + + return result; } -int T2OutsideInfo::NextIndex(int&) { +BOOL T2OutsideInfo::NextIndex(int& outIndex) { + BOOL result = true; + + if (CalcNextUnitInfo()) + outIndex = mNextUnitInfo; + else + result = false; + + return result; } -int T2OutsideInfo::NextOutObj(T2OutObj*&) { +BOOL T2OutsideInfo::NextOutObj(T2OutObj*& outOutObj) { + unsigned int id; + BOOL result; + + for (result = NextValue(id); result; result = NextValue(id)) { + if (id != mCurrentOutObjID) { + mCurrentOutObjID = id; + if (id != 0) { + outOutObj = mFloorInfo.mOutObjArrayList->GetOutObjByID(id); + break; + } + } + } + + return result; } -void T2OutsideInfo::Read(T2Archive&) { +void T2OutsideInfo::Read(T2Archive& inArchive) { + unsigned int count; + inArchive >> count; + + for (unsigned int i = 1; i <= count; i++) { + unsigned short v; + inArchive >> v; + + unsigned int unitInfo = v; + mUnitInfo->AssignItemsAt(1, i, &unitInfo); + } } -void T2OutsideInfo::Write(T2Archive&) { +void T2OutsideInfo::Write(T2Archive& inArchive) { + unsigned int count = mFloorInfo.mHRange * mFloorInfo.mVRange; + inArchive << count; + + for (unsigned int i = 1; i <= count; i++) { + unsigned int unitInfo; + mUnitInfo->FetchItemAt(i, &unitInfo); + + inArchive << (unsigned short) unitInfo; + } } |