/* This file was generated by scramble.py. */
#line 1 "src/game.py"
#include "game.h"
#line 95
int debug_grid = 0;
int debug_dungeon = 0;
int debug_no_models = 0;
int debug_bill = 0;
int debug_no_restrict = 0;
static int load_fonts_t;
Game * game;
static int _vol = 4;
#line 104
Game* game_global(void) {
    return game;
}
void game_new(void) {
    game->level = 1;
    game->level_unlocked = 1;
    game->level_visited = 1;
    game_reset();
    game->welcome = 1;
    game->paused = 1;
}
void game_reset(void) {
    game->gold = 100;
    game->used [Water] = 0;
    game->used [Gas] = 0;
    game->used [Electric] = 0;
    game_pay_bills();
#line 122
    kind_give_name(game->quest1, "Quest Giver 1");
    game->quest1->cost = 30;
    game->quest1->upkeep [Electric] = 5;
    kind_give_name(game->quest2, "Quest Giver 2");
    game->quest2->cost = 60;
    game->quest2->upkeep [Electric] = 10;
    kind_give_name(game->quest3, "Quest Giver 3");
    game->quest3->cost = 90;
    game->quest3->upkeep [Electric] = 15;
    kind_give_name(game->quest4, "Quest Giver 4");
    game->quest4->cost = 120;
    game->quest4->upkeep [Electric] = 20;
    kind_give_name(game->vendor_head, "Headwear Vendor");
    game->vendor_head->cost = 30;
    game->vendor_head->upkeep [Electric] = 5;
    kind_give_name(game->vendor_potion, "Potion Vendor");
    game->vendor_potion->cost = 30;
    game->vendor_potion->upkeep [Electric] = 5;
    game->vendor_potion->upkeep [Water] = 5;
    kind_give_name(game->vendor_shield, "Apparel Vendor");
    game->vendor_shield->cost = 50;
    game->vendor_shield->upkeep [Electric] = 10;
    kind_give_name(game->vendor_smith, "Weapon Vendor");
    game->vendor_smith->cost = 30;
    game->vendor_smith->upkeep [Electric] = 5;
    game->vendor_smith->upkeep [Gas] = 5;
#line 149
    game->trap_box->cost = 10;
    game->trap_poison->cost = 10;
    game->trap_poison->upkeep [Water] = 5;
    game->trap_fire->cost = 10;
    game->trap_fire->upkeep [Gas] = 5;
    game->trap_lightning->cost = 10;
    game->trap_lightning->upkeep [Electric] = 5;
#line 157
    game->potion_hp->cost = 10;
    game->potion_mp->cost = 10;
    game->potion_res->cost = 20;
#line 161
    game->shield->cost = 20;
    game->quiver->cost = 20;
    game->book->cost = 20;
#line 165
    game->sword->cost = 10;
    game->bow->cost = 10;
    game->wand->cost = 10;
#line 169
    game->chest->cost = 15;
#line 171
    game->helmet->cost = 10;
    game->helmet2->cost = 10;
    game->hat->cost = 10;
#line 175
    game->rat->is_creature = 1;
    game->rat->upkeep [Water] = 2;
    game->troll->is_creature = 1;
    game->troll->upkeep [Water] = 2;
    game->troll->upkeep [Gas] = 5;
    game->troll2->is_creature = 1;
    game->troll2->upkeep [Water] = 4;
    game->troll2->upkeep [Gas] = 10;
    game->priest->is_creature = 1;
    game->priest->upkeep [Water] = 5;
    game->priest->upkeep [Electric] = 15;
    game->dragon->is_creature = 1;
    game->dragon->upkeep [Electric] = 30;
    game->dragon->upkeep [Gas] = 30;
#line 190
    kind_give_name(game->rat, "Giant Rat");
    kind_give_name(game->troll, "Troll");
    kind_give_name(game->troll2, "Cave Troll");
    kind_give_name(game->priest, "Demonic Maniac");
    kind_give_name(game->dragon, "Dragon");
#line 196
    kind_give_name(game->knight, "Knight");
    kind_give_name(game->archer, "Archer");
    kind_give_name(game->elf, "Healer");
    kind_give_name(game->mage, "Magician");
#line 201
    if (game->dungeon) {
        for (int i = 1; i < 10; i += 1) {
            dungeon_destroy(game->levels [i]);
            game->levels [i] = dungeon_new();
        }
    }
#line 205
    dungeon_create(game->levels);
#line 207
    game_change_level(0);
    game->bill_due_t = game->t + 60 * 60;
#line 210
    game->welcome = 0;
    game->paused = 0;
    game->over = 0;
#line 214
    if (debug_bill) {
        game->paused = 1;
        game->show_bill = 1;
        dungeon_use(game->rat->kid);
        dungeon_use(game->troll->kid);
        dungeon_use(game->priest->kid);
        dungeon_use(game->dragon->kid);
        dungeon_use(game->vendor_potion->kid);
        dungeon_use(game->vendor_shield->kid);
        dungeon_use(game->vendor_head->kid);
        dungeon_use(game->vendor_smith->kid);
        dungeon_use(game->quest1->kid);
        dungeon_use(game->quest2->kid);
        dungeon_use(game->quest3->kid);
        dungeon_use(game->quest4->kid);
    }
}
#line 230
char* kind_create_name(Kind * k) {
    if (k == game->rat) {
#line 231
        return names_generate_rat();
    }
#line 232
    if (k == game->troll) {
#line 232
        return names_generate_troll();
    }
#line 233
    if (k == game->troll2) {
#line 233
        return names_generate_troll();
    }
#line 234
    if (k == game->priest) {
#line 234
        return names_generate_demon();
    }
#line 235
    if (k == game->dragon) {
#line 235
        return names_generate_dragon();
    }
    if (k == game->knight) {
#line 237
        return names_generate_knight();
    }
#line 238
    if (k == game->archer) {
#line 238
        return names_generate_ranger();
    }
#line 239
    if (k == game->elf) {
#line 239
        return names_generate_elf();
    }
#line 240
    if (k == game->mage) {
#line 240
        return names_generate_mage();
    }
#line 241
    return land_strdup("Nameless");
}
void game_change_level(int d) {
    game->level += d;
#line 246
    if (game->level < 1) {
        game->level = 1;
#line 247
        return ;
    }
    if (game->level > 9) {
        game->level = 9;
#line 250
        return ;
    }
#line 253
    if (game->level > game->level_visited) {
        game->level_visited = game->level;
    }
    game->dungeon = game->levels [game->level];
#line 258
    render_create_objects();
}
void game_music_volume(int v) {
    _vol = v;
    if (_vol == 0) {
        land_stream_set_playing(land_stream_default(), 0);
    }
#line 263
    else {
#line 265
        land_stream_set_playing(land_stream_default(), 1);
        land_stream_volume(land_stream_default(), _vol / 3.0);
    }
}
#line 268
void game_init(void) {
    land_display_title("Dungeon Simulator");
#line 271
    land_find_data_prefix("data/");
#line 273
    data_init();
    data_reload_fonts();
#line 276
    render.vertex_shader = land_read_text("dungeonsim.vert");
    render.fragment_shader = land_read_text("dungeonsim.frag");
#line 279
    land_alloc(game);
    game->start_t = land_get_ticks();
    game->kinds = land_array_new();
#line 283
    land_alloc(game->wall_hidden) /* 0 kind */;
    land_array_add(game->kinds, game->wall_hidden);
#line 286
    data_status("Creating dungeon... Please wait!");
#line 288
    game->model_by_name = land_hash_new();
    game->ground [0] = render_kind_new_static("hex_ground", 1);
    game->ground [1] = render_kind_new_static("hex_ground2", 1);
    game->ground [2] = render_kind_new_static("hex_ground3", 1);
    game->ground [3] = render_kind_new_static("hex_ground4", 1);
    game->ground [4] = render_kind_new_static("hex_ground5", 1);
    game->wall = render_kind_new_static("hex_wall", 1);
    game->wall2 = render_kind_new_static("hex_wall2", 1);
    game->wall3 = render_kind_new_static("hex_wall3", 1);
    game->wall4 = render_kind_new_static("hex_wall4", 1);
    game->wall5 = render_kind_new_static("hex_wall5", 1);
    game->wall_torch = render_kind_new_static("hex_wall_torch", 1);
    game->vendor_head = render_kind_new_static("hex_vendor_head", 1);
    game->vendor_potion = render_kind_new_static("hex_vendor_potion", 1);
    game->vendor_shield = render_kind_new_static("hex_vendor_shield", 1);
    game->vendor_smith = render_kind_new_static("hex_vendor_smith", 1);
    game->quest1 = render_kind_new_static("hex_quest1", 1);
    game->quest2 = render_kind_new_static("hex_quest2", 1);
    game->quest3 = render_kind_new_static("hex_quest3", 1);
    game->quest4 = render_kind_new_static("hex_quest4", 1);
#line 309
    data_status("Releasing monsters... Please wait!");
#line 311
    game->trap_box = render_kind_new_static("hex_trap_box", 1);
    game->trap_fire = render_kind_new_static("hex_trap_fire", 1);
    game->trap_poison = render_kind_new_static("hex_trap_poison", 1);
    game->trap_lightning = render_kind_new_static("hex_trap_lightning", 1);
    game->troll = render_kind_new_anim("troll", "troll_attack", "troll_dead", .4);
    game->troll2 = render_kind_new_anim("troll", "troll_attack", "troll_dead", .5);
    game->rat = render_kind_new_anim("rat", "rat_attack", "rat_dead", .25);
    game->knight = render_kind_new_anim("knight", "knight_attack", "knight_dead", .33);
    game->archer = render_kind_new_anim("archer", "archer_attack", "archer_dead", .33);
    game->mage = render_kind_new_anim("purple_mage", "purple_mage_fire", "purple_mage_dead", .33);
    game->elf = render_kind_new_anim("elf", "elf_attack", "elf_dead", .33);
    game->priest = render_kind_new_anim("priest", "priest_attack", "priest_dead", .33);
    game->dragon = render_kind_new_anim("dragon", "dragon_attack", "dragon_dead", .5);
#line 325
    data_status("Unlocking the gates... Please wait!");
#line 327
    game->arrow = render_kind_new_shadow("arrow", 0.33);
    game->fireball = render_kind_new_shadow("hex_fireball", .33);
    game->missile = render_kind_new_shadow("hex_missile", .33);
    game->potion_hp = render_kind_new_shadow("potion_hp", .33);
    game->potion_mp = render_kind_new_shadow("potion_mp", .33);
    game->potion_res = render_kind_new_shadow("potion_res", .33);
    game->helmet = render_kind_new_shadow("helmet_held", .33);
    game->sword = render_kind_new_shadow("sword_held", .33);
    game->shield = render_kind_new_shadow("shield3_held", .33);
    game->book = render_kind_new_shadow("book_held", .33);
    game->wand = render_kind_new_shadow("wand_held", .33);
    game->helmet2 = render_kind_new_shadow("helmet2_held", .33);
    game->hat = render_kind_new_shadow("purple_pointy_hat", .33);
    game->quiver = render_kind_new_shadow("quiver", .33);
    game->bow = render_kind_new_shadow("bow_held", .33);
    game->chest = render_kind_new_shadow("chest", 1);
#line 344
    game->troll->sound_fight = DataTroll;
    game->troll->sound_down = DataTrollDie;
    game->troll2->sound_fight = DataTroll;
    game->troll2->sound_down = DataTrollDie;
#line 349
    game->knight->sound_attack = DataUnsheath;
    game->knight->sound_fight = DataSword;
    game->knight->sound_down = DataDeath;
#line 353
    game->rat->sound_attack = DataRat;
    game->rat->sound_fight = DataSqueak;
    game->rat->sound_down = DataRatGone;
#line 357
    game->archer->sound_fight = DataArrow;
    game->archer->sound_down = DataDeath;
#line 360
    game->priest->sound_attack = DataDemon;
    game->priest->sound_fight = DataMagicMissile;
    game->priest->sound_down = DataDemon;
    game->priest->sound_special = DataEvil;
#line 365
    game->mage->sound_attack = DataBook;
    game->mage->sound_fight = DataFireball;
    game->mage->sound_down = DataYell;
#line 369
    game->dragon->sound_attack = DataDragon;
    game->dragon->sound_fight = DataRoar;
#line 372
    game->elf->sound_fight = DataSpell;
    game->elf->sound_special = DataHeal;
    game->elf->sound_down = DataNo;
#line 376
    game_new();
    //unit_tests()
    //game_new()
#line 381
    game->title = 1;
    render.cam = land_camera_new();
    land_camera_change_freely(render.cam, pi / 2 - pi / 3, 0, 0);
#line 385
    game_music_volume(1);
}
void cheat_health(void) {
    print("CHEATER!");
    {
#line 389
        LandArrayIterator __iter0__ = LandArrayIterator_first(game->dungeon->creatures);
#line 389
        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 390
                continue;
            }
#line 391
            c->hp = c->hp_max;
            if (c->dead && ! c->hidden) {
                c->hidden = 1;
                c->dead = 0;
            }
        }
    }
}
#line 396
void cheat_equip(void) {
    print("CHEATER!");
    {
#line 398
        LandArrayIterator __iter0__ = LandArrayIterator_first(game->dungeon->creatures);
#line 398
        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 399
                continue;
            }
#line 400
            buy_equipment(c, game->knight, Off, game->shield);
            buy_equipment(c, game->archer, Neck, game->quiver);
            buy_equipment(c, game->mage, Off, game->book);
#line 404
            buy_equipment(c, game->knight, Head, game->helmet);
            buy_equipment(c, game->archer, Head, game->helmet2);
            buy_equipment(c, game->mage, Head, game->hat);
#line 408
            buy_equipment(c, game->knight, Main, game->sword);
            buy_equipment(c, game->archer, Main, game->bow);
            buy_equipment(c, game->mage, Main, game->wand);
        }
    }
}
#line 412
void cheat(void) {
    if (land_get_ticks() > game->cheat_timeout_t) {
        game->cheat_pos = 0;
    }
    while (! land_keybuffer_empty()) {
        int k, u;
        land_keybuffer_next(& k, & u);
        if (u >= 'a' && u <= 'z') {
            if (game->cheat_pos < 10) {
                game->cheat [game->cheat_pos++] = u;
                game->cheat [game->cheat_pos] = 0;
                game->cheat_timeout_t = land_get_ticks() + 60;
#line 425
                if (land_equals(game->cheat, "iddqd")) {
                    cheat_health();
                }
#line 427
                if (land_equals(game->cheat, "idkfa")) {
                    cheat_equip();
                }
            }
        }
    }
}
#line 430
void game_tick(void) {
#line 432
    land_scale_to_fit(1280, 720, 256);
#line 434
    int speed = 1;
    if (land_closebutton()) {
#line 435
        land_quit();
    }
#line 436
    if (land_key_pressed(LandKeyEscape)) {
#line 436
        land_quit();
    }
#line 437
    if (land_key_pressed('n')) {
        game_reset();
    }
#line 439
    if (land_key_pressed('d') && land_key(LandKeyLeftShift)) {
        debug_grid++;
        debug_grid %= 4;
    }
#line 442
    if (debug_no_restrict && land_key_pressed('s')) {
        int s = game->t % 60;
        if (game->paused) {
            if (s == 0) {
                game->t += 30;
            }
#line 446
            else {
#line 448
                game->t += 60 - s;
                dungeon_step(game->dungeon);
            }
        }
#line 449
        else {
#line 451
            game->t += 59 - s;
        }
    }
#line 452
    if (land_key(' ')) {
        speed = 4;
    }
#line 454
    if (land_key_pressed('p')) {
        game->paused = ! game->paused;
    }
#line 456
    if (land_key_pressed(LandKeyPageUp)) {
        game_change_level(- 1);
    }
#line 458
    if (land_key_pressed(LandKeyPageDown)) {
        if (debug_no_restrict || game->level < game->level_unlocked) {
            game_change_level(1);
        }
    }
#line 461
    if (land_key_pressed('m')) {
        _vol++;
        _vol %= 4;
        game_music_volume(_vol);
    }
    cheat();
#line 468
    if (game->speed) {
        speed = 4;
    }
    if (! game->paused && ! menu.shown) {
        for (int i = 0; i < speed; i += 1) {
            game->t++;
            int t = game->t % 60;
            if (t == 0) {
                dungeon_step(game->dungeon);
            }
            play_queued_sounds(t);
        }
    }
#line 480
    LandFloat mx = land_mouse_x();
    LandFloat my = land_mouse_y();
    LandFloat mz = 0;
    land_transform(& mx, & my, & mz);
    game->mx = mx;
    game->my = my;
    int x, y;
    get_hex_under_mouse(mx, my, & x, & y);
#line 489
    Tile * tile = dungeon_tile(game->dungeon, x, y);
    if (tile->kind == 1) {
        game->hover_x = x;
        game->hover_y = y;
    }
#line 492
    else {
#line 494
        if (tile->kid == game->wall_hidden->kid) {
            for (int s = 0; s < 5; s += 1) {
                Tile * tile2 = dungeon_tile(game->dungeon, x, y - s);
                if (tile2->kind == 1) {
                    game->hover_x = x;
                    game->hover_y = y - s;
                    break;
                }
            }
        }
#line 500
        else {
#line 502
            game->hover_x = x;
            game->hover_y = y;
            Tile * tile2 = dungeon_tile(game->dungeon, x, y + 1);
            if (tile2->kind == 2) {
                game->hover_y += 1;
            }
        }
    }
#line 508
    Tile * htile = dungeon_tile(game->dungeon, game->hover_x, game->hover_y);
    if (htile->creature) {
        game->hover_cid = htile->creature;
    }
#line 511
    else if (game->hover_cid) {
        Creature * c = dungeon_creature(game->dungeon, game->hover_cid);
        if (dungeon_distance(c->x, c->y, game->hover_x, game->hover_y) > 2) {
            game->hover_cid = 0;
        }
    }
#line 516
    if (land_mouse_button_clicked(0)) {
#line 518
        if (menu_click_button(mx, my)) {
#line 518
            ;
        }
#line 518
        else {
#line 521
            if (! menu.shown) {
                game->selx = game->hover_x;
                game->sely = game->hover_y;
            }
            float px, py;
            get_hex_pixelpos(x, y, & px, & py);
            menu_click(px, py);
        }
    }
#line 529
    if (land_mouse_button_released(0)) {
        game->speed = 0;
    }
    if (land_was_resized()) {
        load_fonts_t = 12;
    }
    {
#line 535
        LandArrayIterator __iter0__ = LandArrayIterator_first(game->particles);
#line 535
        for (Object * ob = LandArrayIterator_item(game->particles, &__iter0__); LandArrayIterator_next(game->particles, &__iter0__); ob = LandArrayIterator_item(game->particles, &__iter0__)) {
            if (! ob || ob->dead) {
                continue;
            }
#line 538
            particle_tick(ob);
        }
    }
#line 540
    if (game->t >= game->bill_due_t) {
        if (game->have_bill) {
            // from last due date
#line 542
            game_pay_bills();
            data_play(DataCoin);
            if (game->have_bill) {
                game->over = 1;
                game->paused = 1;
            }
        }
#line 546
        else {
#line 548
            game->have_bill = 1;
        }
#line 549
        game->bill_due_t += 60 * 60;
    }
}
#line 551
void particle_tick(Object * ob) {
    ob->light = 1;
    if (ob->kind == game->fireball || ob->kind == game->arrow || ob->kind == game->missile) {
        float xp, zp, xp2, zp2;
        get_hexpos(ob->creature->x, ob->creature->y, & xp, & zp);
        get_hexpos(ob->home->x, ob->home->y, & xp2, & zp2);
        int ti = 60 - (ob->expire_t - game->t);
        xp = xp + (xp2 - xp) * ti / 60.0;
        zp = zp + (zp2 - zp) * ti / 60.0;
        float y = 0.75;
        if (ob->kind == game->fireball || ob->kind == game->missile) {
            y = 1.5;
        }
#line 563
        ob->matrix = land_4x4_matrix_translate(xp, y, zp);
        Data3DModel * model = ob->kind->normal;
        float s = model->scale;
        float a = atan2(xp2 - xp, zp2 - zp);
        ob->matrix = land_4x4_matrix_mul(ob->matrix, land_4x4_matrix_rotate(0, 1, 0, a));
        ob->matrix = land_4x4_matrix_mul(ob->matrix, land_4x4_matrix_scale(s, s, s));
        if (game->t >= ob->expire_t) {
            ob->dead = 1;
        }
    }
#line 570
    else {
#line 572
        Land4x4Matrix t = land_4x4_matrix_translate(0, 1, 0);
        ob->matrix = land_4x4_matrix_mul(ob->matrix, t);
        LandVector pos = land_4x4_matrix_get_position(& ob->matrix);
        if (pos.y > 10) {
            ob->dead = 1;
        }
    }
}
#line 578
void game_draw(void) {
    if (load_fonts_t) {
        load_fonts_t--;
        if (load_fonts_t == 0) {
            data_reload_fonts();
        }
    }
#line 584
    data_check_blur();
#line 586
    if (game->dungeon->modified) {
        game->dungeon->modified = 0;
        render_redo_static_objects();
    }
    {
#line 590
        LandArrayIterator __iter0__ = LandArrayIterator_first(game->moving);
#line 590
        for (Object * ob = LandArrayIterator_item(game->moving, &__iter0__); LandArrayIterator_next(game->moving, &__iter0__); ob = LandArrayIterator_item(game->moving, &__iter0__)) {
            if (! ob) {
                continue;
            }
#line 593
            if (ob->creature->hidden) {
                continue;
            }
#line 595
            object_prepare_creature(ob);
        }
    }
#line 597
    render_clear();
    render_3d_projection();
#line 600
    render.light = land_vector_normalize(land_vector(0.25, 1, 1.25));
    land_triangles_set_light_direction(render.light);
#line 603
    render.more = 0;
#line 605
    {
#line 605
        LandArrayIterator __iter0__ = LandArrayIterator_first(game->objects);
#line 605
        for (Object * ob = LandArrayIterator_item(game->objects, &__iter0__); LandArrayIterator_next(game->objects, &__iter0__); ob = LandArrayIterator_item(game->objects, &__iter0__)) {
            draw_object(ob, ob->matrix);
        }
    }
#line 608
    land_render_state(LAND_WRITE_MASK, LAND_RGBA_MASK);
#line 610
    {
#line 610
        LandArrayIterator __iter0__ = LandArrayIterator_first(game->moving);
#line 610
        for (Object * ob = LandArrayIterator_item(game->moving, &__iter0__); LandArrayIterator_next(game->moving, &__iter0__); ob = LandArrayIterator_item(game->moving, &__iter0__)) {
            if (! ob) {
                continue;
            }
#line 613
            if (ob->creature->hidden) {
                continue;
            }
#line 615
            draw_shadow(ob, ob->matrix);
        }
    }
#line 617
    {
#line 617
        LandArrayIterator __iter0__ = LandArrayIterator_first(game->particles);
#line 617
        for (Object * ob = LandArrayIterator_item(game->particles, &__iter0__); LandArrayIterator_next(game->particles, &__iter0__); ob = LandArrayIterator_item(game->particles, &__iter0__)) {
            if (! ob || ob->dead) {
                continue;
            }
#line 620
            draw_shadow(ob, ob->matrix);
        }
    }
#line 622
    land_render_state(LAND_WRITE_MASK, LAND_RGBA_MASK + LAND_DEPTH_MASK);
#line 624
    {
#line 624
        LandArrayIterator __iter0__ = LandArrayIterator_first(game->moving);
#line 624
        for (Object * ob = LandArrayIterator_item(game->moving, &__iter0__); LandArrayIterator_next(game->moving, &__iter0__); ob = LandArrayIterator_item(game->moving, &__iter0__)) {
            if (! ob) {
                continue;
            }
#line 627
            if (ob->creature->hidden) {
                continue;
            }
#line 629
            draw_object(ob, ob->matrix);
        }
    }
#line 631
    {
#line 631
        LandArrayIterator __iter0__ = LandArrayIterator_first(game->particles);
#line 631
        for (Object * ob = LandArrayIterator_item(game->particles, &__iter0__); LandArrayIterator_next(game->particles, &__iter0__); ob = LandArrayIterator_item(game->particles, &__iter0__)) {
            if (! ob || ob->dead) {
                continue;
            }
#line 634
            draw_object(ob, ob->matrix);
        }
    }
#line 636
    render_2d_projection();
#line 638
    if (debug_grid) {
        render_debug_grid();
    }
    {
#line 641
        LandArrayIterator __iter0__ = LandArrayIterator_first(game->moving);
#line 641
        for (Object * ob = LandArrayIterator_item(game->moving, &__iter0__); LandArrayIterator_next(game->moving, &__iter0__); ob = LandArrayIterator_item(game->moving, &__iter0__)) {
            if (! ob) {
                continue;
            }
#line 644
            if (ob->creature->hidden) {
                continue;
            }
#line 646
            draw_object_ui(ob);
        }
    }
#line 648
    render_infobar();
    menu_draw();
}
void game_done(void) {
#line 651
    ;
}
#line 654
void game_place_selected_kind(int kid) {
    Tile * tile = dungeon_tile(game->dungeon, game->selx, game->sely);
    tile->kid = kid;
    game->dungeon->modified = 1;
}
void game_spawn_selected_monster(Kind * k) {
    Creature * c = dungeon_creature_new(game->dungeon, k, game->selx, game->sely);
    render_add_moving_object(c);
}
Creature* game_spawn_hero(Dungeon * dungeon, Kind * k, bool spawn) {
    Creature * c = dungeon_creature_new(dungeon, k, dungeon->sx, dungeon->sy);
    if (spawn) {
        render_add_moving_object(c);
    }
#line 667
    return c;
}
void game_buy(Kind * k, int x, int y) {
    game->gold += k->cost;
    render_add_particle(k, x, y);
    data_play(DataPay);
}
void game_use(Kind * k, int x, int y) {
    render_add_particle(k, x, y);
}
void game_projectile(Kind * k, int c1, int c2) {
    Creature * cr1 = dungeon_creature(game->dungeon, c1);
    Creature * cr2 = dungeon_creature(game->dungeon, c2);
    Object * o = render_add_particle_to(k, cr1->x, cr1->y, cr2->x, cr2->y);
    o->creature = cr1;
    o->home = cr2;
}
void game_unlock_level(void) {
    if (game->level == game->level_unlocked) {
        if (game->level_unlocked < 9) {
            game->level_unlocked += 1;
            game->gold += game->level_unlocked * 10;
        }
    }
}
#line 690
bool game_reset_used(int uid) {
    int pay = (99 + game->used [uid]) / 100;
    if (pay > game->gold) {
        return 0;
    }
#line 694
    game->gold -= pay;
    game->used [uid] -= pay * 100;
    for (int i = 0; i < 100; i += 1) {
        game->used_stats [uid] [i] = 0;
    }
#line 698
    return 1;
}
void game_pay_bills(void) {
    int x = game_outstanding();
    if (x <= game->gold) {
        bool a = game_reset_used(Water);
        bool b = game_reset_used(Gas);
        bool c = game_reset_used(Electric);
        if (a && b && c) {
            game->have_bill = 0;
        }
    }
}
#line 709
int game_outstanding(void) {
    int a = (99 + game->used [Water]) / 100;
    int b = (99 + game->used [Gas]) / 100;
    int c = (99 + game->used [Electric]) / 100;
    return a + b + c;
}
/* This file was generated by scramble.py. */
