/* This file was generated by scramble.py. */
#line 1 "src/render.py"
#include "render.h"
#line 5
    /* s = 1
     * h / s = cos 60° -> h = s * 0.866 (sqrt(0.75))
     * ____
     * /\  /\
     * /__\/__\
     * \  /\  /
     * \/__\/
     */
#line 45
static float hex_height = sqrt(0.75) * 2;
static const float TileScale = 1280 / 33 / 0.75 / 2;
Render render;
static void _tri(float x, float y, float w, float h);
#line 64
Kind* kind_get(int kid) {
    return land_array_get(game->kind_by_id, kid);
}
Kind* render_kind_new(str anim, str anim_attack, str anim_dead, float scale, bool moving) {
    if (! game->kind_by_id) {
        game->kind_by_id = land_array_new();
        land_array_add(game->kind_by_id, NULL);
    }
    Kind * k;
#line 72
    land_alloc(k);
    k->kid = land_array_count(game->kind_by_id);
    land_array_add(game->kind_by_id, k);
#line 76
    k->normal = add_3d_model_frames(anim, scale, moving);
    k->attack = add_3d_model_frames(anim_attack, scale, moving);
    k->dead = add_3d_model_frames(anim_dead, scale, moving);
#line 80
    k->name = land_strdup(anim);
#line 82
    return k;
}
void kind_give_name(Kind * k, str name) {
    land_free(k->name);
    k->name = land_strdup(name);
}
Kind* render_kind_new_static(str name, float scale) {
    return render_kind_new(name, NULL, NULL, scale, 0);
}
Kind* render_kind_new_anim(str name, str name_attack, str name_dead, float scale) {
    return render_kind_new(name, name_attack, name_dead, scale, 1);
}
Kind* render_kind_new_shadow(str name, float scale) {
    return render_kind_new(name, NULL, NULL, scale, 1);
}
void render_clear(void) {
    land_unclip();
    land_clear(0, 0, 0, 1);
    land_clear_depth(1);
    render.stats_triangles = 0;
#line 103
    land_scale_to_fit(1280, 720, 0);
#line 105
    float rw = 1280 * land_get_x_scale();
    float rh = 720 * land_get_y_scale();
    float rx = (land_display_width() - rw) / 2;
    float ry = (land_display_height() - rh) / 2;
    land_clip(rx, ry, rx + rw, ry + rh);
}
void render_3d_projection(void) {
    float sx, sy, sw, sh;
    land_get_scaled_dimensions(& sx, & sy, & sw, & sh);
#line 115
    land_render_state(LAND_DEPTH_TEST, 1);
    glEnable(GL_CULL_FACE);
#line 118
    LandFloat size = TileScale;
    sx /= size;
    sy /= size;
    sw /= size;
    sh /= size;
#line 124
    Land4x4Matrix pm = land_4x4_matrix_orthographic(- sw / 2, - sh / 2, 30, sw / 2, sh / 2, - 30);
    pm = land_4x4_matrix_mul(pm, land_camera_matrix(render.cam));
    land_projection(pm);
    render.projection = pm;
}
void render_2d_projection(void) {
    land_reset_projection();
    land_reset_transform();
    glDisable(GL_CULL_FACE);
    land_render_state(LAND_DEPTH_TEST, 0);
    land_display_set_default_shaders();
    land_scale_to_fit(1280, 720, 0);
}
void hexa(float x, float y, float w, float h) {
    float s = w / 2 * 0.9;
    float t = h / 2 * 0.9;
#line 141
    land_move_to(x + s / 2, y - t);
    land_line_to(x + s, y);
    land_line_to(x + s / 2, y + t);
    land_line_to(x - s / 2, y + t);
    land_line_to(x - s, y);
    land_line_to(x - s / 2, y - t);
    land_line_to(x + s / 2, y - t);
}
static void _tri(float x, float y, float w, float h) {
    land_filled_triangle(x, y, x + w / 2, y + h, x - w / 2, y + h);
}
void hexf(float x, float y, float w, float h) {
    float s = w / 2;
    float t = h / 2;
    _tri(x, y, s, t);
    _tri(x - s / 2, y - t, s, t);
    _tri(x + s / 2, y - t, s, t);
    _tri(x, y, s, - t);
    _tri(x - s / 2, y + t, s, - t);
    _tri(x + s / 2, y + t, s, - t);
}
void get_hexpos(int x, int y, float * sx, float * sz) {
    float x2 = x - (board_w - 1) * 0.5;
    float y2 = y - (board_h - 1) * 0.5;
    if (x % 2 == 1) {
        y2 += 0.5;
    }
    * sx = x2 * 1.5;
    * sz = y2 * hex_height;
}
Object* add_static_object(float x, float y, float z, Kind * k, float angle) {
#line 173
    Object * o;
#line 173
    land_alloc(o);
#line 175
    o->matrix = land_4x4_matrix_translate(x, y, z);
    o->matrix = land_4x4_matrix_mul(o->matrix, land_4x4_matrix_rotate(0, 1, 0, angle));
    float s = k->normal->scale;
    o->matrix = land_4x4_matrix_mul(o->matrix, land_4x4_matrix_scale(s, s, s));
    o->kind = k;
    o->light = 1;
#line 182
    land_array_add(game->objects, o);
#line 184
    o->height = k->normal->height * k->normal->scale;
    return o;
}
Object* render_add_moving_object(Creature * creature) {
#line 189
    Object * o;
#line 189
    land_alloc(o);
    o->creature = creature;
    o->kind = kind_get(creature->kid);
    o->light = 1;
    land_array_add(game->moving, o);
    o->height = o->kind->normal->height * o->kind->normal->scale;
    return o;
}
void object_destroy(Object * o) {
    shadows_maybe_destroy(o->shadows_normal);
    shadows_maybe_destroy(o->shadows_attack);
    land_free(o);
}
Object* render_add_particle_to(Kind * k, int x, int y, int x2, int y2) {
#line 204
    Object * o = NULL;
    {
#line 205
        LandArrayIterator __iter0__ = LandArrayIterator_first(game->particles);
#line 205
        for (Object * dead = LandArrayIterator_item(game->particles, &__iter0__); LandArrayIterator_next(game->particles, &__iter0__); dead = LandArrayIterator_item(game->particles, &__iter0__)) {
            if (dead->dead) {
                o = dead;
                break;
            }
        }
    }
#line 210
    if (! o) {
        land_alloc(o);
        land_array_add(game->particles, o);
    }
#line 212
    else {
#line 214
        memset(o, 0, sizeof (* o));
    }
#line 215
    o->kind = k;
    o->light = 1;
    o->expire_t = game->t + 60;
#line 219
    o->height = o->kind->normal->height * o->kind->normal->scale;
#line 221
    float xp, zp;
    get_hexpos(x, y, & xp, & zp);
    o->matrix = land_4x4_matrix_translate(xp, 0, zp);
    Data3DModel * model = k->normal;
    float s = model->scale;
#line 227
    float a = 0;
    if (x2 != 0 || y2 != 0) {
        float xp2, zp2;
        get_hexpos(x2, y2, & xp2, & zp2);
        a = atan2(xp2 - xp, zp2 - zp);
    }
#line 232
    o->matrix = land_4x4_matrix_mul(o->matrix, land_4x4_matrix_rotate(0, 1, 0, a));
    o->matrix = land_4x4_matrix_mul(o->matrix, land_4x4_matrix_scale(s, s, s));
    return o;
}
Object* render_add_particle(Kind * k, int x, int y) {
    return render_add_particle_to(k, x, y, 0, 0);
}
void object_prepare_creature(Object * self) {
#line 241
    int ti = game->t % 60;
#line 243
    Creature * c = self->creature;
#line 245
    if (self->dead) {
        if (! c->dead) {
            self->dead = 0 /* resurrected! */;
        }
#line 247
        else {
#line 247
            return ;
        }
    }
#line 251
    if (c->dead && ! self->dead) {
        self->dead = 1;
    }
    self->frozen = 1;
#line 256
    float cx, cy, px, py;
    get_hexpos(c->px, c->py, & px, & py);
    get_hexpos(c->x, c->y, & cx, & cy);
#line 260
    float pa = (c->pd + 3) / 6.0 * pi * 2;
    float a = (c->d + 3) / 6.0 * pi * 2;
    if (cx != px || cy != py) {
        a = atan2(- cy + py, cx - px) + pi / 2;
    }
#line 264
    if (ti < 15) {
        float ad = a - pa;
        if (ad != 0) {
            self->frozen = 0;
        }
#line 268
        if (ad < - pi) {
#line 268
            ad += 2 * pi;
        }
#line 269
        if (ad > pi) {
#line 269
            ad -= 2 * pi;
        }
#line 270
        a = pa + ad * (ti / 15.0);
    }
    if (cx != px || cy != py || c->fighting || c->healing) {
        self->frozen = 0;
    }
#line 274
    float x = px + (cx - px) * ti / 60.0;
    float y = py + (cy - py) * ti / 60.0;
#line 277
    self->xpix = x;
    self->ypix = y;
#line 280
    if (self->dead) {
        a = land_rnd(0, 2 * pi);
    }
    self->matrix = land_4x4_matrix_translate(x, 0, y);
    Data3DModel * model = self->kind->normal;
    float s = model->scale;
    self->matrix = land_4x4_matrix_mul(self->matrix, land_4x4_matrix_rotate(0, 1, 0, a));
    self->matrix = land_4x4_matrix_mul(self->matrix, land_4x4_matrix_scale(s, s, s));
#line 289
    Tile * tile = dungeon_tile(game->dungeon, c->x, c->y);
    self->light = tile->light;
#line 292
    bool recalc_shadow = 0;
#line 294
    for (int i = 0; i < 4; i += 1) {
        Kind * ek = NULL;
        if (c->equip [i]) {
#line 296
            ek = kind_get(c->equip [i]);
        }
#line 297
        if (self->equip [i] != ek) {
#line 297
            recalc_shadow = 1;
        }
#line 298
        self->equip [i] = ek;
    }
    if (recalc_shadow) {
        shadows_maybe_destroy(self->shadows_normal);
        shadows_maybe_destroy(self->shadows_attack);
        self->shadows_normal = shadows_new(self->kind->normal, self);
        self->shadows_attack = shadows_new(self->kind->attack, self);
    }
}
#line 306
Data3DModel* object_model(Object * self) {
    Data3DModel * k = self->kind->normal;
    if (self->creature) {
        Creature * c = self->creature;
        if (c->dead) {
            if (self->kind->dead) {
                k = self->kind->dead;
            }
        }
#line 313
        else if (c->fighting || c->healing) {
            if (self->kind->attack) {
                k = self->kind->attack;
            }
        }
    }
#line 316
    return k;
}
void draw_object(Object * ob, Land4x4Matrix tm) {
    if (! ob) {
#line 319
        return ;
    }
#line 320
    land_display_transform_4x4(& tm);
    Data3DModel * model = object_model(ob);
#line 323
    int n = land_array_count(model->frames);
    if (n == 0) {
#line 324
        return ;
    }
#line 327
    int t = 0;
#line 329
    if (! ob->frozen) {
        if (n == 5) {
            t = ((int)(game->t / 4)) % 8;
            if (t >= 5) {
                t = t - 5 /* 0, 1, 2 */;
                t = 3 - t;
            }
        }
    }
#line 336
    draw_model(model, t, ob->light);
    draw_equipment(ob, model, t, ob->light);
}
void draw_equipment(Object * ob, Data3DModel * k, int t, float light) {
    if (ob->dead) {
#line 340
        return ;
    }
#line 343
    Data3DMarkers * markers = land_array_get(k->markers, t);
    Land4x4Matrix matrix [4] = {markers->main, markers->off, markers->head, markers->neck};
    for (int i = 0; i < 4; i += 1) {
        Kind * ek = ob->equip [i];
        if (ek) {
            land_push_transform();
            land_display_compose_transform(matrix [i]);
            draw_model(ek->normal, 0, light);
            land_pop_transform();
        }
    }
}
#line 353
void draw_model(Data3DModel * model, int t, float light) {
    if (land_array_count(model->frames) == 0) {
#line 354
        return ;
    }
    LandArray * f = land_array_get(model->frames, t);
    {
#line 357
        LandArrayIterator __iter0__ = LandArrayIterator_first(f);
#line 357
        for (LandTriangles * tr = LandArrayIterator_item(f, &__iter0__); LandArrayIterator_next(f, &__iter0__); tr = LandArrayIterator_item(f, &__iter0__)) {
            land_triangles_set_light(light);
            land_triangles_draw_more(tr, render.more);
            render.more = 1;
            render.stats_triangles += (int)(tr->n / 3);
        }
    }
}
#line 363
void draw_shadow(Object * ob, Land4x4Matrix tm) {
    if (! ob) {
#line 364
        return ;
    }
#line 365
    Land4x4Matrix tm2 = tm;
    tm2.v [7] = 0;
    land_display_transform_4x4(& tm2);
    Data3DModel * k = object_model(ob);
#line 370
    int n = land_array_count(k->frames);
    if (n == 0) {
#line 371
        return ;
    }
#line 372
    int t = 0;
    if (n == 5) {
        t = ((int)(game->t / 4)) % 8;
        if (t >= 5) {
            t = t - 5 /* 0, 1, 2 */;
            t = 3 - t;
        }
    }
#line 379
    LandTriangles * shadow = NULL;
#line 381
    Data3DModel * model = object_model(ob);
    if (model == ob->kind->normal && ob->shadows_normal) {
        shadow = land_array_get(ob->shadows_normal->frames, t);
    }
#line 384
    if (model == ob->kind->attack && ob->shadows_attack) {
        shadow = land_array_get(ob->shadows_attack->frames, t);
    }
    if (! shadow) {
        shadow = land_array_get(k->shadows->frames, t);
    }
#line 389
    land_triangles_draw_more(shadow, render.more);
    render.more = 1;
}
void draw_object_ui(Object * ob) {
    land_thickness(1);
    draw_healthbar(ob);
    draw_manabar(ob);
}
void draw_healthbar(Object * ob) {
    Creature * c = ob->creature;
    if (c->dead) {
#line 399
        return ;
    }
    if (c->hp == c->hp_max) {
#line 401
        return ;
    }
    float p = c->hp * 1.f / c->hp_max;
    float x1, y1, x2, y2;
    x1 = 640 + ob->xpix * TileScale;
    y1 = 360 + ob->ypix * TileScale / 2 - ob->height * TileScale;
    x1 -= 25;
    x2 = x1 + 50 * p;
    y2 = y1 + 5;
    if (p > 0.8) {
        land_color(0, 0.8, 0, 1);
    }
#line 412
    else if (p > 0.5) {
        land_color(0.7, 0.8, 0, 1);
    }
#line 414
    else if (p > 0.25) {
        land_color(0.7, 0.2, 0, 1);
    }
#line 416
    else if (p > 0.1) {
        land_color(0.9, 0, 0, 1);
    }
#line 417
    else {
#line 419
        int blink = land_get_ticks() / 15;
        if (blink & 1) {
            land_color(1, 1, 1, 1);
        }
#line 421
        else {
#line 423
            land_color(1, 0.1, 0.3, 1);
        }
#line 424
        land_rectangle(x1, y1, x1 + 50, y2);
    }
#line 425
    land_filled_rectangle(x1, y1, x2, y2);
}
void draw_manabar(Object * ob) {
    Creature * c = ob->creature;
    if (c->dead) {
#line 429
        return ;
    }
    if (c->mp == c->mp_max) {
#line 431
        return ;
    }
    float p = c->mp * 1.f / c->mp_max;
    float x1, y1, x2, y2;
    x1 = 640 + ob->xpix * TileScale;
    y1 = 360 + ob->ypix * TileScale / 2 - ob->height * TileScale;
    x1 -= 25;
    x2 = x1 + 50 * p;
    y2 = y1;
    y1 -= 5;
#line 442
    if (p > 0.5) {
        land_color(0.3, 0.3, 1, 1);
    }
#line 444
    else if (p > 0.25) {
        land_color(0.3, 0.9, 1, 1);
    }
#line 445
    else {
#line 447
        land_color(0.5, 1, 1, 1);
        land_rectangle(x1, y1, x1 + 50, y2);
    }
#line 449
    land_filled_rectangle(x1, y1, x2, y2);
}
void render_redo_static_objects(void) {
    if (game->objects) {
        land_array_destroy_with_free(game->objects);
    }
#line 454
    game->objects = land_array_new();
#line 456
    for (int y = 0; y < board_h; y += 1) {
        for (int x = 0; x < board_w; x += 1) {
            Tile * tile = dungeon_tile(game->dungeon, x, y);
#line 460
            float x2, y2;
            get_hexpos(x, y, & x2, & y2);
#line 463
            Object * o = NULL;
            if (tile->kind == 1) {
                Kind * ground = kind_get(tile->kid);
                o = add_static_object(x2, 0, y2, ground, 0);
            }
#line 467
            if (tile->kind == 2 || tile->kind == 0) {
                bool skip = 0;
                if (y > 0) {
                    // Don't draw a wall tile that would block visibility
                    Tile * tile2 = dungeon_tile(game->dungeon, x, y - 1);
                    if (tile2->kind == 1) {
                        tile->kid = game->wall_hidden->kid;
                        skip = 1;
                    }
                }
#line 475
                if (! skip) {
                    Kind * wall = kind_get(tile->kid);
                    o = add_static_object(x2, 0, y2, wall, 0);
                }
            }
#line 479
            if (o) {
                o->light = tile->light;
            }
        }
    }
}
#line 482
void render_create_objects(void) {
    if (game->moving) {
        {
#line 484
            LandArrayIterator __iter0__ = LandArrayIterator_first(game->moving);
#line 484
            for (Object * o = LandArrayIterator_item(game->moving, &__iter0__); LandArrayIterator_next(game->moving, &__iter0__); o = LandArrayIterator_item(game->moving, &__iter0__)) {
                object_destroy(o);
            }
        }
#line 486
        land_array_destroy(game->moving);
    }
#line 487
    game->moving = land_array_new();
#line 489
    if (game->particles) {
        land_array_destroy_with_free(game->particles);
    }
#line 491
    game->particles = land_array_new();
#line 493
    render_redo_static_objects();
#line 495
    {
#line 495
        LandArrayIterator __iter0__ = LandArrayIterator_first(game->dungeon->creatures);
#line 495
        for (Creature * c = LandArrayIterator_item(game->dungeon->creatures, &__iter0__); LandArrayIterator_next(game->dungeon->creatures, &__iter0__); c = LandArrayIterator_item(game->dungeon->creatures, &__iter0__)) {
            if (! c) {
#line 496
                continue;
            }
#line 497
            render_add_moving_object(c);
        }
    }
}
#line 499
void get_hex_under_mouse(float mx, float my, int * hx, int * hy) {
    float ty = sqrt(0.75) * TileScale;
    float tx = TileScale * 2 * 0.75;
#line 503
    float x0 = 1280 / 2 - board_w * 0.5 * tx + tx * 0.5;
    float y0 = 720 / 2 - (board_h - 1) * ty * 0.5;
#line 506
    float x = (mx - x0 + tx / 3) / tx;
    float fx = floor(x);
    * hx = fx;
    if ((* hx & 1) == 0) {
        y0 -= ty / 2;
    }
#line 511
    float y = (my - y0) / ty;
    float fy = floor(y);
    * hy = fy;
#line 515
    if (x - fx > 0.66) {
        if (y - fy < 0.5) {
            float lx = x - fx - 0.66;
            float ly = y - fy;
            if (lx / 0.33 > ly / 0.5) {
                (* hx) += 1;
                if (* hx & 1) {
                    (* hy) -= 1;
                }
            }
        }
#line 522
        else {
#line 524
            float lx = x - fx - 0.66;
            float ly = y - fy - 1;
            if (lx / 0.33 > ly / (- 0.5)) {
                (* hx) += 1;
                if ((* hx & 1) == 0) {
                    (* hy) += 1;
                }
            }
        }
    }
}
#line 531
void get_hex_pixelpos(int x, int y, float * px, float * py) {
    float ty = sqrt(0.75) * TileScale;
    float tx = TileScale * 2 * 0.75;
#line 535
    float x0 = 1280 / 2 - board_w * 0.5 * tx + tx * 0.5;
    float y0 = 720 / 2 - (board_h - 1) * ty * 0.5;
#line 538
    * px = x0 + x * tx;
    * py = y0 + y * ty;
    if (x & 1) {
        * py += ty / 2;
    }
}
#line 543
void render_debug_grid(void) {
    land_font_set(font_small);
#line 546
    float h = sqrt(0.75) * TileScale;
    float s = TileScale * 2;
#line 549
    float x0 = 1280 / 2 - board_w * 0.5 * s * 0.75 + s * 0.375;
    float y0 = 720 / 2 - (board_h - 1) * h * 0.5;
#line 552
    for (int j = 0; j < board_h; j += 1) {
        for (int i = 0; i < board_w; i += 1) {
            float x, y;
            get_hex_pixelpos(i, j, & x, & y);
            land_color(0, 0, 0, 1);
            hexa(x, y, s, h);
            land_text_pos(x, y);
            Tile * tile = dungeon_tile(game->dungeon, i, j);
            if (debug_grid == 1) {
                if (tile->kind == 0) {
                    land_color(.5, 0, .5, 1);
                    land_print_center("X");
                }
#line 564
                if (tile->kind == 2) {
                    land_color(.5, 0, .5, 1);
                    land_print_center("+");
                }
#line 567
                if (tile->far != 0) {
                    land_color(1, 0, 1, 1);
                    land_print_center("%d", tile->far);
                }
            }
#line 570
            if (debug_grid == 2) {
                if (tile->path_step != 0) {
                    land_color(.4, .5, 1, 1);
                    land_print_center("%d", tile->path_step);
                }
            }
#line 574
            if (debug_grid == 3) {
                if (tile->creature != 0) {
                    Creature * c = dungeon_creature(game->dungeon, tile->creature);
                    if (c->fighting) {
                        land_color(1, 0, 0, 1);
                        land_print_center("%d -> %d", tile->creature, c->fighting);
                    }
#line 579
                    else {
#line 581
                        land_color(0, 0.5, 0, 1);
                        land_print_center("%d", tile->creature);
                    }
                    if (c->fighting) {
                        Creature * c2 = dungeon_creature(game->dungeon, c->fighting);
                        int cy = y0 + h * c2->y;
                        int cx = x0 + s * 0.75 * c2->x;
                        if (c2->x & 1) {
                            cy += h / 2;
                        }
#line 590
                        land_line(x, y, cx, cy);
                    }
                    if (c->healing) {
                        land_color(0, 1, 1, 1);
                        Creature * c2 = dungeon_creature(game->dungeon, c->healing);
                        int cy = y0 + h * c2->y;
                        int cx = x0 + s * 0.75 * c2->x;
                        if (c2->x & 1) {
                            cy += h / 2;
                        }
#line 599
                        land_line(x, y, cx, cy);
                    }
                    if (c->leader) {
                        land_color(.3, .3, .3, .3);
                        Creature * c2 = dungeon_creature(game->dungeon, c->leader);
                        int cy = y0 + h * c2->y;
                        int cx = x0 + s * 0.75 * c2->x;
                        if (c2->x & 1) {
                            cy += h / 2;
                        }
#line 608
                        land_line(x, y, cx, cy);
                    }
                }
            }
        }
    }
#line 611
    land_color_set_named("black");
    land_circle(1280 / 2 - 5, 720 / 2 - 5, 1280 / 2 + 5, 720 / 2 + 5);
}
#line 617
static str names [] = {"Village", "The Rat Pit", "The Troll Caverns", "Gnomish Mines", "Halls of the Mountain King", "Demonic Depths", "Abyss Catacombs", "Lizard Caves", "Crypt of Gehennom", "Dragon's Lair"};
#line 619
void box(str name, str format, ...) {
    int y = land_text_y_pos();
    land_font_set(font_small);
    land_print(name);
    int x = land_text_x() + land_text_width();
    land_font_set(font_menu);
#line 626
    va_list args;
    va_start(args, format);
    land_writev(format, args);
    va_end(args);
#line 631
    int x2 = land_text_x_pos();
    if (x2 > x) {
#line 632
        x = x2;
    }
#line 633
    land_text_pos(x + 8, y);
}
void render_infobar(void) {
#line 637
    land_font_set(font_small);
    land_text_pos(4, 4);
    land_color(1, 1, 1, 1);
    box("Gold", "%d", game->gold);
    land_color(.5, .5, 1, 1);
    box("Water", "%d", (game->used [Water] + 99) / 100);
    land_color(.2, .8, 0, 1);
    box("Gas", "%d", (game->used [Gas] + 99) / 100);
    land_color(.8, .7, 0, 1);
    box("Electricity", "%d", (game->used [Electric] + 99) / 100);
    land_color(1, .7, .4, 1);
    box(names [game->level], "%d/9", game->level);
#line 650
    if (game->level_unlocked > game->level_visited) {
        land_color(0, .9, 0, 1);
        box("New Level", "You have unlocked level %d!", game->level_unlocked);
    }
    if (game->have_bill) {
        land_color(1, .2, .1, 0);
        box("Warning", "You have unpaid utility bills, pay them!");
    }
#line 657
    else if (game_outstanding() > game->gold) {
        land_color(1, .2, .1, 0);
        box("Warning", "Your utility bill is higher than your remaining gold!");
    }
    if (! menu.shown) {
#line 661
        return ;
    }
#line 664
    float h = sqrt(0.75) * TileScale;
    float s = TileScale * 2;
    float x, y;
    Tile * tile = dungeon_tile(game->dungeon, game->selx, game->sely);
    get_hex_pixelpos(game->selx, game->sely, & x, & y);
    if (tile->kind == 1) {
        land_color(.6, .6, .6, .6);
        hexf(x, y, s * 1.1, h * 1.1);
    }
#line 672
    else if (tile->kind == 2) {
        land_color(.6, .6, .6, .6);
        hexf(x, y - h, s * 1.1, h * 1.1);
        land_thickness(2);
        land_line(x + s / 4, y - h + h / 2, x + s / 4, y + h / 2);
        land_line(x - s / 4, y - h + h / 2, x - s / 4, y + h / 2);
    }
}
#line 679
Shadows* shadows_new(Data3DModel * model, Object * equip_ob) {
    Shadows * self;
#line 680
    land_alloc(self);
    self->frames = land_array_new();
#line 683
    int n = land_array_count(model->frames);
    for (int t = 0; t < n; t += 1) {
        LandImage * image = data_start_shadow();
        draw_model(model, t, 0);
        if (equip_ob) {
#line 687
            draw_equipment(equip_ob, model, t, 0);
        }
#line 688
        data_complete_shadow(image);
        LandTriangles * mesh = create_shadow_mesh(image);
        land_array_add(self->frames, mesh);
        queue_blur(image, self);
    }
    return self;
}
void shadows_maybe_destroy(Shadows * self) {
    if (! self) {
#line 696
        return ;
    }
#line 697
    self->needed = 0;
    if (self->submitted) {
#line 698
        return ;
    }
    {
#line 700
        LandArrayIterator __iter0__ = LandArrayIterator_first(self->frames);
#line 700
        for (LandTriangles * sh = LandArrayIterator_item(self->frames, &__iter0__); LandArrayIterator_next(self->frames, &__iter0__); sh = LandArrayIterator_item(self->frames, &__iter0__)) {
            land_triangles_destroy_with_image(sh);
        }
    }
#line 703
    land_free(self);
}
/* This file was generated by scramble.py. */
