#include "game.hpp" namespace game { size_t selection_cookie = 1; void state_t::start(void) { human_t *human; world.generator = worldgen; human = new human_t; human->place(&world, v2f_t(0.5, 0.5)); units.insert(human); } void state_t::stop(void) { // FIXME /* for (unit_t *unit : units) delete unit; */ } void state_t::select(rectf_t x) { selection_cookie++; selected_units.clear(); for (world::entity_t *ent : world.get_render_entities(x)) { unit_t *unit; if (ent->type != ET_UNIT) continue; unit = (unit_t*)ent; unit->selected = selection_cookie; selected_units.insert(unit); } } void state_t::command(v2f_t x) { v2f_t snap; snap[0] = std::round(x[0] - 0.5f) + 0.5f; snap[1] = std::round(x[1] - 0.5f) + 0.5f; for (unit_t *unit : selected_units) unit->start_moving(snap, now); } void state_t::tick(double now_, double dt_) { now = now_; dt = dt_; for (unit_t *unit : units) unit->keep_moving(now, dt); } bool load_assets(void) { assets::load(); return true; } } //namespace game