/* This file is part of Minitrem. Minitrem is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 2 of the License, or (at your option) any later version. Minitrem is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with Minitrem. If not, see . */ #include "../common.hpp" namespace game { enum { ET_UNIT, ET_EFFECT, ET_DECO, ET_ROCKET }; enum { TILE_NONE, TILE_DIRT, TILE_DIRT_RED, TILE_STONE, TILE_STONE_RED, TILE_WATER, TILE_GRAVEL }; enum { CF_SURFACE = 1, CF_BACKGROUND = 2, CF_SOLID = 4, CF_BODY = 8, CF_BODY_SMALL = 16, CF_WATER = 32, CF_DECOS = 64 }; enum { AMBIENT_NEXUS, AMBIENT_CHASM, AMBIENT_WIND, AMBIENT_WATER, AMBIENT_COUNT }; extern size_t selection_cookie; void worldgen(world::world_t *world, world::sector_index_t index, world::sector_t *sector, bool gen_tiles, bool gen_decos, void *data); namespace assets { typedef struct { render::oriented_sprite_4M_t head_idle, body_idle; render::oriented_sprite_4M_t body_aiming, body_firing; render::oriented_sprite_4M2_t legs_idle, legs_walking; render::animated_texture_t dead, gibbing; render::animated_texture_t rocket; audio::sound_t fire, step_stone, step_dirt, pain, death, gib_sound; } soldier_assets_t; typedef struct { render::oriented_sprite_4M_t idle, walking; render::animated_texture_t dead; audio::sound_t sounds, bite; } spider_assets_t; typedef struct { render::animated_texture_t idle, dead; audio::sound_t spawn, pain, death; } nest_assets_t; typedef struct { render::animated_texture_t idle, dead; audio::sound_t sound, damage; } repl_assets_t; typedef struct { render::animated_texture_t blood, flash, explosion, ricochet, water_splash; audio::sound_t explosion_sound, ricochet_sound, water_splash_sound; } fx_assets_t; typedef struct { render::animated_texture_t stone, stone_cracked; render::animated_texture_t eyething, eyething_dead; render::animated_texture_t spike, spike_broken, spike_small; render::animated_texture_t wart; render::animated_texture_t crystal, crystal_broken; } deco_assets_t; extern soldier_assets_t soldier; extern spider_assets_t spider; extern nest_assets_t nest; extern repl_assets_t repl; extern fx_assets_t fx; extern deco_assets_t deco; extern audio::ambient_t ambients[AMBIENT_COUNT]; extern render::animated_texture_t unit_selected; extern render::animated_texture_t unit_selected_halo; extern render::animated_texture_t move_marker, aim_marker; void load(void); } namespace text { typedef enum { LANG_ENGLISH } language_t; extern language_t language; typedef enum { PAUSED, UNPAUSED, FOLLOWING_ON, FOLLOWING_OFF, SAY_NO_PATH, SAY_READY, SAY_MOVING, SAY_STOPPING, SAY_FIRING, SAY_NO_ROCKETS, UNIT_NAME_SPIDER, UNIT_NAME_SOLDIER, UNIT_NAME_NEST, UNIT_NAME_REPL, UNIT_DEATH, UNIT_DESTRUCTION } index_t; std::string get(index_t index); } class entity_t : public world::entity_t { public: game::state_t *game = 0; v2f_t x; rectf_t size, render_size; entity_t(game::state_t *game, int type_); virtual ~entity_t(void) = 0; void place(world::world_t *world); void place(world::world_t *world, v2f_t x_); bool ignore_waking = true; // Most entities won't need this mechanism. bool awake = false; double wake_time = -INFINITY; void wake(void); void sleep(void); virtual void damage(int points, unit_t *attacker) = 0; virtual void on_think(void) = 0; virtual void on_spawn(void) = 0; virtual void on_wake(void) = 0; }; class fx_move_marker_t; class fx_aim_marker_t; unit_t *find_target(world::world_t *world, v2f_t x, float r, bool friendly); class unit_t : public entity_t { protected: double next_targetting = -INFINITY; double last_attack = -INFINITY; public: size_t selected = 0; typedef enum { UNIT_SOLDIER, UNIT_SPIDER, UNIT_NEST, UNIT_REPL } type_t; game::state_t *game; type_t type; std::string name; unit_t(game::state_t *game_, type_t type_); bool friendly = false; bool controllable = false; struct { world::cflags_t cflags; bool moving = false; bool blocked; v2f_t dst; float angle = 0.0f; std::list path; v2f_t last_step; ntime_t random_walk_time = 0; } move; bool keep_moving(double speed); bool start_moving(v2f_t dst); void stop_moving(void); void random_walk(void); bool dead = false; double death_time = -INFINITY; int health = 1, max_health = 1; void damage(int points, unit_t *attacker); void try_attack(unit_t *target); void die(unit_t *killer); virtual void on_damage(unit_t *attacker) = 0; virtual void on_death(void) = 0; bool have_target = false; std::string say_text; double say_time = -INFINITY; void say(std::string str); void render_to(render::state_t *render); }; class unit_soldier_t : public unit_t { public: double last_target_time = -INFINITY; v2f_t last_target_x; std::unique_ptr move_marker; std::unique_ptr aim_marker; sf::Color selection_color; bool manual_firing = false; v2f_t manual_firing_target; bool rocket_fired = false; void check_area(void); void shoot(v2f_t from, v2f_t at, int damage); void fire_shotgun(v2f_t aim); void target_and_attack(void); unit_soldier_t(game::state_t *game_); ~unit_soldier_t(void) {}; void render_to(render::state_t *render); void render_late_to(render::state_t *render); void on_think(void); void on_spawn(void) {}; void on_wake(void) {}; void on_damage(unit_t *attacker); void on_death(void); }; class unit_spider_t : public unit_t { public: unit_spider_t(game::state_t *game_); ~unit_spider_t(void) {}; void render_to(render::state_t *render); void render_late_to(render::state_t *render) {}; void target_and_attack(void); void on_think(void); void on_spawn(void) {}; void on_wake(void); void on_damage(unit_t *attacker); void on_death(void); }; class unit_nest_t : public unit_t { double next_spawning = -INFINITY; public: unit_nest_t(game::state_t *game_); ~unit_nest_t(void) {}; void render_to(render::state_t *render); void render_late_to(render::state_t *render) {}; void on_think(void); void on_spawn(void); void on_wake(void) {}; void on_damage(unit_t *attacker); void on_death(void); }; class unit_repl_t : public unit_t { public: unit_repl_t(game::state_t *game_); ~unit_repl_t(void) {}; void render_to(render::state_t *render); void render_late_to(render::state_t *render) {}; void on_think(void) {}; void on_spawn(void) {}; void on_wake(void) {}; void on_damage(unit_t *attacker); void on_death(void); void activate(void); }; class effect_t : public game::entity_t { public: double ttl = +INFINITY; effect_t(game::state_t *game_); virtual ~effect_t() {}; void on_think(void); void on_spawn(void) {}; void on_wake(void) {}; void damage(int points, unit_t *attacker) {}; void render_late_to(render::state_t *render) {}; }; class fx_tracer_t : public effect_t { v2f_t x0, x1; public: fx_tracer_t(game::state_t *game_, v2f_t x0_, v2f_t x1_); ~fx_tracer_t(void) {}; void render_to(render::state_t *render); }; class fx_flash_t : public effect_t { v2f_t x; float radius; sf::Color color; public: fx_flash_t(game::state_t *game_, v2f_t x_, float radius_, sf::Color color_); ~fx_flash_t(void) {}; void render_to(render::state_t *render); }; class fx_blood_t : public effect_t { bool alien; v2f_t x; public: fx_blood_t(game::state_t *game_, v2f_t x_, bool alien_); ~fx_blood_t(void) {}; void render_to(render::state_t *render); }; class fx_move_marker_t : public effect_t { v2f_t x; public: fx_move_marker_t(game::state_t *game_, v2f_t x_); ~fx_move_marker_t(void) {}; void render_to(render::state_t *render); }; class fx_aim_marker_t : public effect_t { v2f_t x; public: fx_aim_marker_t(game::state_t *game_, v2f_t x_); ~fx_aim_marker_t(void) {}; void render_to(render::state_t *render); }; class fx_explosion_t : public effect_t { v2f_t x; public: fx_explosion_t(game::state_t *game_, v2f_t x_); ~fx_explosion_t(void) {}; void render_to(render::state_t *render); }; class fx_bullet_miss_t : public effect_t { v2f_t x; bool water; public: fx_bullet_miss_t(game::state_t *game_, v2f_t x_, bool water_); ~fx_bullet_miss_t(void) {}; void render_to(render::state_t *render); }; class fx_debug_hivemind_t : public effect_t { v2f_t x, move_to; float r; bool do_move; public: fx_debug_hivemind_t(game::state_t *game_, v2f_t x_, float r_, bool do_move_, v2f_t move_to_); ~fx_debug_hivemind_t(void) {}; void render_to(render::state_t *render); }; typedef enum { DECO_STONE, DECO_STONE_CRACKED, DECO_STONE_SMALL, DECO_EYETHING, DECO_EYETHING_DEAD, DECO_SPIKE, DECO_SPIKE_BROKEN, DECO_SPIKE_SMALL, DECO_WART, DECO_CRYSTAL, DECO_CRYSTAL_BROKEN } deco_type_t; class deco_t : public game::entity_t { deco_type_t type; public: double phase_shift; deco_t(game::state_t *game, deco_type_t type_); void render_to(render::state_t *render); void render_late_to(render::state_t *render) {}; void on_think(void) {}; void on_spawn(void) {}; void on_wake(void) {}; void damage(int points, unit_t *attacker); }; class rocket_t : public game::entity_t { unit_t *shooter; v2f_t target, v; std::unique_ptr aim_marker; public: rocket_t(game::state_t *game, v2f_t x_, v2f_t target_, unit_t *shooter_); void render_to(render::state_t *render); void render_late_to(render::state_t *render) {}; void on_think(void); void on_spawn(void); void on_wake(void) {}; void damage(int points, unit_t *attacker) {}; }; };