summaryrefslogtreecommitdiff
path: root/src/T2DLL/T2FInfoAreaIterator.cpp
blob: e8c4d8d94123127d2f11f64632aaf107fce3419f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
#include "StdAfx.h"
#include "GlobalFunc.h"
#include "T2FInfoAreaIterator.h"
#include "T2FloorInfo.h"
#include "T2MoverArrayList.h"
#include "T2RequestArrayList.h"
#include "T2TenantArrayList.h"
#include "T2UnitInfo.h"

T2FInfoAreaIterator::T2FInfoAreaIterator(const T2FloorInfo& inFloorInfo, const RECT& inRect)
    : mFloorInfo(inFloorInfo)
{
    mRect = mFloorInfo.mBuildArea;
    InsetRect(&mRect, -1, 0);

    if (mRect.left < 0)
        mRect.left = 0;
    if (mRect.right > inFloorInfo.mHRange)
        mRect.right = inFloorInfo.mHRange;

    IntersectRect(&mRect, &inRect, &mRect);

    mSkipAmount = mFloorInfo.mHRange - (mRect.right - mRect.left) + 1;
    Reset();
}

/*virtual*/ T2FInfoAreaIterator::~T2FInfoAreaIterator() {
}

void T2FInfoAreaIterator::Reset() {
    mCurrV = mRect.top;

    if (!IsRectEmpty(&mRect)) {
        mCurrH = -1;
        mCurrUnitInfo = mFloorInfo.GetUnitInfo(mCurrV, mRect.left);
#line 68
        _ASSERT(mCurrUnitInfo != NULL);
    } else {
        mCurrH = -2;
    }

    mLastIDSeen = 0;
}

BOOL T2FInfoAreaIterator::CalcNextUnitInfo() {
    BOOL result = true;

    if (mCurrH != -2) {
        if (mCurrH != -1) {
            mCurrH++;
            if (mCurrH < mRect.right) {
                mCurrUnitInfo++;
            } else {
                mCurrH = mRect.left;
                mCurrV++;
                if (mCurrV < mRect.bottom) {
                    mCurrUnitInfo += mSkipAmount;
                } else {
                    mCurrH = -2;
                    result = false;
                }
            }
        } else {
            mCurrH = mRect.left;
        }
    } else {
        result = false;
    }

    return result;
}

BOOL T2FInfoAreaIterator::CurrentV(int& outV) const {
    BOOL result = true;

    if (IsValidPosition())
        outV = mCurrV;
    else
        result = false;

    return result;
}

BOOL T2FInfoAreaIterator::Current(T2UnitInfo*& outUnitInfo) {
    BOOL result = true;

    if (IsValidPosition())
        outUnitInfo = mCurrUnitInfo;
    else
        result = false;

    return result;
}

BOOL T2FInfoAreaIterator::Next(T2UnitInfo*& outUnitInfo) {
    BOOL result = true;

    if (CalcNextUnitInfo())
        outUnitInfo = mCurrUnitInfo;
    else
        result = false;

    return result;
}

BOOL T2FInfoAreaIterator::NextTenant(T2Tenant*& outTenant) {
    BOOL found;
    T2UnitInfo *unitInfo;

    for (found = Next(unitInfo); found; found = Next(unitInfo)) {
        unsigned int tenantID = unitInfo->GetTenantID();
        if (tenantID != mLastIDSeen) {
            mLastIDSeen = tenantID;
            if (tenantID != 0) {
                outTenant = mFloorInfo.mTenantArrayList->GetTenantByID(tenantID);
                break;
            }
        }
    }

    return found;
}

void T2FInfoAreaIterator::GetTenantRect(RECT& outRect) {
    outRect.left = mCurrH;
    outRect.right = outRect.left;

    if (IsValidPosition()) {
        outRect.right++;
        T2UnitInfo *unitInfo = mCurrUnitInfo + 1;
        while (mLastIDSeen == unitInfo->GetTenantID()) {
            outRect.right++;
            unitInfo++;
        }
    }
}

BOOL T2FInfoAreaIterator::NextRequest(T2Request*& outRequest) {
    BOOL found;
    T2UnitInfo *unitInfo;

    for (found = Next(unitInfo); found; found = Next(unitInfo)) {
        unsigned int requestID = unitInfo->GetRequestID();
        if (requestID != mLastIDSeen) {
            mLastIDSeen = requestID;
            if (requestID != 0) {
                outRequest = mFloorInfo.mRequestArrayList->GetRequestByID(requestID);
                break;
            }
        }
    }

    return found;
}

BOOL T2FInfoAreaIterator::NextMover(T2Mover*& outMover) {
    BOOL found;
    T2UnitInfo *unitInfo;

    for (found = Next(unitInfo); found; found = Next(unitInfo)) {
        unsigned int moverID = unitInfo->GetMoverID();
        if (moverID != mLastIDSeen) {
            mLastIDSeen = moverID;
            if (moverID != 0) {
                outMover = mFloorInfo.mMoverArrayList->GetMoverByID(moverID);
                break;
            }
        }
    }

    return found;
}