summaryrefslogtreecommitdiff
path: root/src/T2DLL/T2StopInfoArray.cpp
blob: e814c216c5ae0adbbedef0cad8fcbe32dbfb345f (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
#include "StdAfx.h"
#include "T2Archive.h"
#include "T2StopInfoArray.h"

T2StopInfoArray::T2StopInfoArray()
    : LArray(1)
{
}

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

void T2StopInfoArray::Init(int count) {
    Expand(EEquipPos_2, count);
}

void T2StopInfoArray::AllClear() {
    RemoveItemsAt(mItemCount, 1);
}

void T2StopInfoArray::Expand(EEquipPos pos, int count) {
    int where;
    if (pos == EEquipPos_2)
        where = mItemCount + 1;
    else if (pos == EEquipPos_3)
        where = 1;
    else
        return;

    if (count > 0) {
        int actualCount = count * 2;
        unsigned char nullVal = 0;
        for (int i = 0; i < actualCount; i++)
            InsertItemsAt(1, where, &nullVal);
    } else {
        int actualCount = -count * 2;
        for (int i = 0; i < actualCount; i++)
            RemoveItemsAt(1, where);
    }
}

BOOL T2StopInfoArray::IsStopPos(int i, ERequestUpDown upDown) {
    return GetStopAt(i, upDown) > 0;
}

BOOL T2StopInfoArray::IsOnStopPos(int i, ERequestUpDown upDown) {
    return (GetStopAt(i, upDown) & 2) > 0;
}

BOOL T2StopInfoArray::IsOffStopPos(int i, ERequestUpDown upDown) {
    return (GetStopAt(i, upDown) & 1) > 0;
}

void T2StopInfoArray::SetOnStop(int i, ERequestUpDown upDown) {
    char v = GetStopAt(i, upDown) | 2;
    SetStopAt(i, upDown, v);
}

void T2StopInfoArray::SetOffStop(int i, ERequestUpDown upDown) {
    char v = GetStopAt(i, upDown) | 1;
    SetStopAt(i, upDown, v);
}

void T2StopInfoArray::ClearOnStop(int i, ERequestUpDown upDown) {
    char v = GetStopAt(i, upDown) & 1;
    SetStopAt(i, upDown, v);
}

void T2StopInfoArray::ClearOffStop(int i, ERequestUpDown upDown) {
    char v = GetStopAt(i, upDown) & 2;
    SetStopAt(i, upDown, v);
}

char T2StopInfoArray::GetStopAt(int i, ERequestUpDown upDown) {
    char v;
    FetchItemAt(GetIndex(i, upDown), &v);
    return v;
}

void T2StopInfoArray::SetStopAt(int i, ERequestUpDown upDown, char v) {
    AssignItemsAt(1, GetIndex(i, upDown), &v);
}

int T2StopInfoArray::GetIndex(int i, ERequestUpDown upDown) const {
    int index = 1;
    index += i * 2;
    if (upDown == ERequestUpDown_1)
        index++;
    return index;
}

/*static*/ T2StopInfoArray* T2StopInfoArray::ReadStopInfoArray(T2Archive& archive) {
    T2StopInfoArray *array = NULL;

    DWORD code;
    archive >> code;

    if (code == 'SIfA')
        array = new T2StopInfoArray;

    if (array)
        array->ReadAsChar(archive);

    return array;
}

/*static*/ void T2StopInfoArray::WriteStopInfoArray(T2StopInfoArray* array, T2Archive& archive) {
    DWORD code;

    if (!array) {
        code = 'xSIA';
        archive << code;
    } else {
        code = 'SIfA';
        archive << code;
        array->WriteAsChar(archive);
    }
}