summaryrefslogtreecommitdiff
path: root/src/manager/railIntersectionManager.c
blob: 68a16d2e3e116e2251155fb45dfb55916f32aea7 (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
/**
 * @file railIntersectionManager.c
 * @ingroup Managers
 *
 * @brief Change the rail next to the rotating rail so that it connects.
 */
#include "manager/railIntersectionManager.h"
#include "flags.h"
#include "room.h"

void sub_0805B778(RailIntersectionManager*);
void RailIntersectionManager_Init(RailIntersectionManager*);
void RailIntersectionManager_Action1(RailIntersectionManager*);

void RailIntersectionManager_Main(RailIntersectionManager* this) {
    static void (*const RailIntersectionManager_Actions[])(RailIntersectionManager*) = {
        RailIntersectionManager_Init,
        RailIntersectionManager_Action1,
    };
    RailIntersectionManager_Actions[super->action](this);
}

void RailIntersectionManager_Init(RailIntersectionManager* this) {
    if (CheckFlags(this->flags)) {
        super->type2 = 1;
    }
    super->action = 1;
    this->field_0x38 = (this->field_0x38 >> 4 & 0x3fU) | (((this->field_0x3a << 0x10) >> 0x14 & 0x3fU) << 6);
    sub_0805B778(this);
}

void RailIntersectionManager_Action1(RailIntersectionManager* this) {
    if (CheckFlags(this->flags)) {
        if (super->type2 == 0) {
            super->type2 = 1;
            sub_0805B778(this);
        }
    } else {
        if (super->type2 == 1) {
            super->type2 = 0;
            sub_0805B778(this);
        }
    }
}

void sub_0805B778(RailIntersectionManager* this) {
    static const u16 gUnk_08108C9C[] = { 0x358, 0x359, 0x356, 0x35a, 0x35a, 0x357 };
    SetTileType(gUnk_08108C9C[super->type * 2 + super->type2], this->field_0x38, this->field_0x36);
}