extern Gfx obj_s_shop1_window_model[];
extern Gfx obj_w_shop1_window_model[];

static int aSHOP_actor_draw_before(GAME* game, cKF_SkeletonInfo_R_c* keyframe, int joint_idx, Gfx** joint_shape,
                                   u8* joint_flags, void* arg, s_xyz* joint_rot, xyz_t* joint_pos) {
    STRUCTURE_ACTOR* shop;
    GRAPH* graph;
    f32 inter;
    int angle;
    int r;
    int g;
    int b;
    Gfx* gfx;

    shop = (STRUCTURE_ACTOR*)arg;
    graph = game->graph;

    if (joint_idx == 5) {
        angle = shop->arg0;
        if (angle == DEG2SHORT_ANGLE(90.0f) - 1) { // 0x3FFF
            r = 255;
            g = 255;
            b = 150;
        } else if (angle == DEG2SHORT_ANGLE(0.0f)) {
            r = 0;
            g = 0;
            b = 0;
        } else {
            inter = (1.0f / (DEG2SHORT_ANGLE(90.0f) - 1)) * angle;
            r = (255.0f * inter);
            g = (255.0f * inter);
            b = (150.0f * inter);
        }

        OPEN_DISP(graph);
        gfx = NOW_POLY_OPA_DISP;

        gDPSetEnvColor(gfx++, r, g, b, 0);

        SET_POLY_OPA_DISP(gfx);
        CLOSE_DISP(graph);

    } else if (joint_idx == 6) {
        *joint_shape = NULL;
    }

    return TRUE;
}

static int aSHOP_actor_draw_after(GAME* game, cKF_SkeletonInfo_R_c* keyframe, int joint_idx, Gfx** joint_shape,
                                  u8* joint_flags, void* arg, s_xyz* joint_rot, xyz_t* joint_pos) {
    static Gfx* mdl[] = { obj_s_shop1_window_model, obj_w_shop1_window_model };

    STRUCTURE_ACTOR* office;
    GRAPH* graph;
    Mtx* mtx;
    int angle;
    int winter;
    int l;
    int r;
    int g;
    int b;
    int a;
    Gfx* gfx;

    office = (STRUCTURE_ACTOR*)arg;
    graph = game->graph;

    if (joint_idx == 6) {
        mtx = _Matrix_to_Mtx_new(graph);
        if (mtx != NULL) {
            angle = office->arg0;
            if (angle == DEG2SHORT_ANGLE(90.0f) - 1) { // 0x3FFF
                l = 120;
                r = 255;
                g = 255;
                b = 150;
                a = 255;
            } else if (angle == DEG2SHORT_ANGLE(0.0f)) {
                l = 0;
                r = 0;
                g = 0;
                b = 0;
                a = 255;
            } else {
                r = 255;
                g = 255;
                b = 150;
                a = 255;
                l = (1.0f / (DEG2SHORT_ANGLE(90.0f) - 1)) * angle * 120.0f;
            }

            winter = office->season == mTM_SEASON_WINTER;

            _texture_z_light_fog_prim_shadow(graph);

            OPEN_DISP(graph);
            gfx = NOW_SHADOW_DISP;

            gDPSetPrimColor(gfx++, 0, l, r, g, b, a);
            gSPMatrix(gfx++, mtx, G_MTX_NOPUSH | G_MTX_LOAD | G_MTX_MODELVIEW);
            gSPDisplayList(gfx++, mdl[winter]);

            SET_SHADOW_DISP(gfx);
            CLOSE_DISP(graph);
        }
    }

    return TRUE;
}

static void aSHOP_actor_draw(ACTOR* actor, GAME* game) {
    GRAPH* graph;
    cKF_SkeletonInfo_R_c* keyframe;
    Mtx* mtx;
    Gfx* gfx;
    u16* pal;
    GAME_PLAY* play;
    STRUCTURE_ACTOR* shop;

    graph = game->graph;
    play = (GAME_PLAY*)game;
    shop = (STRUCTURE_ACTOR*)actor;
    keyframe = &shop->keyframe;

    mtx = GRAPH_ALLOC_TYPE(graph, Mtx, (u32)keyframe->skeleton->num_shown_joints);
    if (mtx == NULL) {
        return;
    }

    pal = Common_Get(clip).structure_clip->get_pal_segment_proc(aSTR_PAL_SHOP1);

    _texture_z_light_fog_prim_npc(graph);

    OPEN_DISP(graph);
    gfx = NOW_POLY_OPA_DISP;

    gSPSegment(gfx++, 8, pal);

    SET_POLY_OPA_DISP(gfx);
    CLOSE_DISP(graph);

    cKF_Si3_draw_R_SV(game, keyframe, mtx, &aSHOP_actor_draw_before, &aSHOP_actor_draw_after, actor);
    (*Common_Get(clip).bg_item_clip->draw_shadow_proc)(game, &aSHOP_shadow_data, FALSE);
}
