diff options
author | Ash Wolf <ninji@wuffs.org> | 2023-06-28 22:22:32 +0100 |
---|---|---|
committer | Ash Wolf <ninji@wuffs.org> | 2023-06-28 22:22:32 +0100 |
commit | c0c336500955a23e344651e5412c9d9d441ef4ee (patch) | |
tree | 790769c748db307cf3314f6e896e2f61c68561a2 /src/T2DLL/T2TrafficInfo.cpp | |
parent | 37e364b2c6cc7487a1c888d256a73e5337bb7189 (diff) | |
download | t2win-c0c336500955a23e344651e5412c9d9d441ef4ee.tar.gz t2win-c0c336500955a23e344651e5412c9d9d441ef4ee.zip |
first pass of T2DLL
Diffstat (limited to '')
-rw-r--r-- | src/T2DLL/T2TrafficInfo.cpp | 148 |
1 files changed, 138 insertions, 10 deletions
diff --git a/src/T2DLL/T2TrafficInfo.cpp b/src/T2DLL/T2TrafficInfo.cpp index 6390c51..04722a4 100644 --- a/src/T2DLL/T2TrafficInfo.cpp +++ b/src/T2DLL/T2TrafficInfo.cpp @@ -1,34 +1,162 @@ +#include "T2Archive.h" +#include "T2FloorInfo.h" +#include "T2TowerDoc.h" +#include "T2TowerMainView.h" #include "T2TrafficInfo.h" +#include "URect.h" -T2TrafficInfo::T2TrafficInfo(RECT, unsigned int, unsigned int, unsigned int, unsigned int) { +T2TrafficInfo::T2TrafficInfo(RECT inArea, unsigned int inA, unsigned int inB, unsigned int inC, unsigned int inUnitSize) { + mUnitSize = inUnitSize; + if (mUnitSize == 0) + mUnitSize = 4; + + m8 = inA / 4; + mC = inB / 4; + m10 = inC / 4; + + mArea = inArea; + mHeight = URect::Height(inArea); + mWidth = URect::Width(inArea) / mUnitSize; + mUnitData = new T2TrafficUnit[mWidth * mHeight]; + + unsigned int nUnits = mWidth * mHeight; + T2TrafficUnit *unt = mUnitData; + for (unsigned int i = 0; i < nUnits; i++, unt++) { + unt->x0 = 0; + unt->x4 = 0; + } } /*virtual*/ T2TrafficInfo::~T2TrafficInfo() { + if (mUnitData) + delete[] mUnitData; } -void T2TrafficInfo::Pass(POINT, POINT, short) { +void T2TrafficInfo::Pass(POINT inPt1, POINT inPt2, short inCost) { + POINT point1; + POINT point2; + + if (inPt1.x < inPt2.x) { + point1 = inPt1; + point2 = inPt2; + point2.y = inPt1.y; + } else { + point1 = inPt2; + point1.y = inPt1.y; + point2 = inPt1; + } + + T2TrafficUnit *un1 = GetUnit(point1); + T2TrafficUnit *un2 = GetUnit(point2); + + if (un1 && un2) { + for (T2TrafficUnit *unit = un1; unit <= un2; unit++) + unit->x0 += inCost; + } } -void T2TrafficInfo::HourChanged(T2TowerDoc*) { +void T2TrafficInfo::HourChanged(T2TowerDoc* inDoc) { + unsigned int nUnits = mWidth * mHeight; + T2TrafficUnit *unt = mUnitData; + + for (unsigned int i = 0; i < nUnits; i++, unt++) { + unt->x4 *= 0.96875f; + if ((unt->x4 + unt->x0) > 0xFFFF) + unt->x4 = 0xFFFF; + else + unt->x4 += unt->x0; + unt->x0 = 0; + + int range = CalcRange(unt->x4); + if (range != unt->range) { + unt->range = range; + if (inDoc->towerDoc_vf140() == ViewMode_5) { + RECT area; + T2FloorInfo *theFloorInfo = inDoc->towerDoc_vf12C(); + + CalcUnitArea(i, area); + theFloorInfo->SetTenantDrawModeByRect(area, DrawMode3); + inDoc->GetTowerMainView()->tmv_vf128(area); + } + } + } } -unsigned int T2TrafficInfo::CalcRange(unsigned int) const { +unsigned int T2TrafficInfo::CalcRange(unsigned int inValue) const { + short range = 3; + + if (inValue < m8) + range = 0; + else if (inValue < mC) + range = 1; + else if (inValue < m10) + range = 2; + + return range; } -void T2TrafficInfo::CalcUnitArea(unsigned int, RECT&) const { +void T2TrafficInfo::CalcUnitArea(unsigned int inIndex, RECT& outRect) const { + unsigned int h = inIndex / mWidth; + unsigned int v = (inIndex % mWidth) * mUnitSize; + SetRect(&outRect, h, v, h + mUnitSize, v + 1); + OffsetRect(&outRect, mArea.left, mArea.top); } -short T2TrafficInfo::GetRange(POINT) const { +short T2TrafficInfo::GetRange(POINT inPt) const { + short range = 0; + + T2TrafficUnit *theUnit = GetUnit(inPt); + if (theUnit) + range = theUnit->range; + + return range; } -T2TrafficUnit* T2TrafficInfo::GetUnit(POINT) const { +T2TrafficUnit* T2TrafficInfo::GetUnit(POINT inPt) const { + T2TrafficUnit *theUnit = NULL; + + if (mUnitData) { + int index = CalcUnitIndex(inPt); + if (index > 0) + theUnit = mUnitData + index; + } + + return theUnit; } -int T2TrafficInfo::CalcUnitIndex(POINT) const { +int T2TrafficInfo::CalcUnitIndex(POINT inPt) const { + int index = -1; + POINT point = inPt; + + if (PtInRect(&mArea, point)) { + int h = (inPt.x - mArea.left) / mUnitSize; + int v = inPt.y - mArea.top; + index = mWidth * v + h; + } + + return index; } -void T2TrafficInfo::Read(T2Archive&) { +void T2TrafficInfo::Read(T2Archive& inArchive) { + unsigned int nUnits = mWidth * mHeight; + T2TrafficUnit *unt = mUnitData; + for (unsigned int i = 0; i < nUnits; i++, unt++) { + unsigned short v; + + inArchive >> v; + unt->x0 = v; + inArchive >> v; + unt->x4 = v; + + unt->range = CalcRange(unt->x4); + } } -void T2TrafficInfo::Write(T2Archive&) const { +void T2TrafficInfo::Write(T2Archive& inArchive) const { + unsigned int nUnits = mWidth * mHeight; + T2TrafficUnit *unt = mUnitData; + for (unsigned int i = 0; i < nUnits; i++, unt++) { + inArchive << (unsigned short) unt->x0; + inArchive << (unsigned short) unt->x4; + } } |