diff --git a/dungeon.vcxproj b/dungeon.vcxproj
index 198214e..3c3ba45 100644
--- a/dungeon.vcxproj
+++ b/dungeon.vcxproj
@@ -102,6 +102,7 @@
+
@@ -176,6 +177,7 @@
+
diff --git a/dungeon.vcxproj.filters b/dungeon.vcxproj.filters
index 8a8b84e..7a9e710 100644
--- a/dungeon.vcxproj.filters
+++ b/dungeon.vcxproj.filters
@@ -138,6 +138,9 @@
Source Files
+
+ Source Files
+
@@ -380,5 +383,8 @@
Header Files
+
+ Header Files
+
\ No newline at end of file
diff --git a/src/Actor.cpp b/src/Actor.cpp
index 36cc94d..66655f3 100644
--- a/src/Actor.cpp
+++ b/src/Actor.cpp
@@ -17,7 +17,7 @@ Actor::Actor(Tilemap *map, vec2i pos) : Entity(map, pos) {
void Actor::update() {
if (!alive) return;
- if (bt != nullptr) {
+ if (!player_controlled && bt != nullptr) {
bt->tick(this);
}
if (health < health_max) {
@@ -51,7 +51,7 @@ void Actor::attack(Actor *act) {
void Actor::attack(vec2i dpos) {
if (dpos.dist() <= range) {
vec2i pos = get_position();
- auto acts = get_map()->get_entities(pos.x + dpos.x, pos.y + dpos.y, 0, ENTITY_ACTOR);
+ auto acts = get_map()->get_actors(pos.x + dpos.x, pos.y + dpos.y, 0);
for (Entity* ent : acts) {
auto act = (Actor*)ent;
if (act->is_alive() && act->get_actor_faction() != faction) {
diff --git a/src/Actor.h b/src/Actor.h
index 27eb1f0..3fff4f9 100644
--- a/src/Actor.h
+++ b/src/Actor.h
@@ -35,8 +35,9 @@ protected:
public:
int id;
std::string name;
+ bool player_controlled;
- Actor(Tilemap *map, vec2i pos, std::string datakey);
+ //Actor(Tilemap *map, vec2i pos, std::string datakey);
bool is_alive(){ return alive; };
void attack(vec2i dpos); // basic melee attack
void attack(Actor* act);
diff --git a/src/AttackEnemyNode.cpp b/src/AttackEnemyNode.cpp
index efb59d1..fc84ba5 100644
--- a/src/AttackEnemyNode.cpp
+++ b/src/AttackEnemyNode.cpp
@@ -13,11 +13,10 @@ BehaviourTreeStatus AttackEnemyNode::tick(BTTick * tick) {
bool ishero = tick->target->is_type_of(ACT_HERO);
vec2i targetpos = tick->target->get_position();
- auto actors = tick->target->get_map()->get_entities(targetpos.x, targetpos.y, 6, ENTITY_ACTOR);
+ auto actors = tick->target->get_map()->get_actors(targetpos.x, targetpos.y, 6);
std::vector visibleEnemies;
- for (auto ent : actors) {
- auto actor = (Actor*)ent;
+ for (Actor* actor : actors) {
if (actor == tick->target) continue;
diff --git a/src/FleeNode.cpp b/src/FleeNode.cpp
index f993959..79e1369 100644
--- a/src/FleeNode.cpp
+++ b/src/FleeNode.cpp
@@ -18,9 +18,8 @@ BehaviourTreeStatus FleeNode::tick(BTTick * tick) {
std::vector enemyPos;
bool ishero = tick->target->is_type_of(ACT_HERO);
vec2i targetpos = tick->target->get_position();
- auto actors = tick->target->get_map()->get_entities(targetpos.x, targetpos.y, 6, ENTITY_ACTOR);
- for (auto ent : actors) {
- auto actor = (Actor*)ent;
+ auto actors = tick->target->get_map()->get_actors(targetpos.x, targetpos.y, 6);
+ for (Actor* actor : actors) {
if (actor->is_type_of(ACT_HERO) != ishero) {
vec2i pos = actor->get_position();
if (line_of_sight(tick->target->get_map(), tick->target->get_position(), pos)) {
diff --git a/src/HealFriendNode.cpp b/src/HealFriendNode.cpp
index fdfb2c9..473dcbd 100644
--- a/src/HealFriendNode.cpp
+++ b/src/HealFriendNode.cpp
@@ -13,10 +13,9 @@ BehaviourTreeStatus HealFriendNode::tick(BTTick * tick) {
bool ishero = tick->target->is_type_of(ACT_HERO);
vec2i targetpos = tick->target->get_position();
- auto actors = tick->target->get_map()->get_entities(targetpos.x, targetpos.y, 6, ENTITY_ACTOR);
+ auto actors = tick->target->get_map()->get_actors(targetpos.x, targetpos.y, 6);
std::vector friends;
- for (auto ent : actors) {
- auto actor = (Actor*)ent;
+ for (Actor* actor : actors) {
if (actor == tick->target) continue;
if (actor->is_type_of(ACT_HERO) == ishero && actor->get_health() < actor->get_health_max()) {
diff --git a/src/Hero.cpp b/src/Hero.cpp
index 5600fa9..9d7dd48 100644
--- a/src/Hero.cpp
+++ b/src/Hero.cpp
@@ -11,6 +11,7 @@
Hero::Hero(Tilemap* map, vec2i pos) : Actor(map, pos) {
name = "Hero";
alive = true;
+ player_controlled = true;
health = 6;
health_max = 6;
strength = 2;
diff --git a/src/IfNotSeeEnemyNode.cpp b/src/IfNotSeeEnemyNode.cpp
index dbed801..31a0536 100644
--- a/src/IfNotSeeEnemyNode.cpp
+++ b/src/IfNotSeeEnemyNode.cpp
@@ -16,9 +16,8 @@ BehaviourTreeStatus IfNotSeeEnemyNode::tick(BTTick * tick) {
bool ishero = tick->target->is_type_of(ACT_HERO);
vec2i targetpos = tick->target->get_position();
- auto actors = tick->target->get_map()->get_entities(targetpos.x, targetpos.y, 6, ENTITY_ACTOR);
- for (auto ent : actors) {
- auto actor = (Actor*)ent;
+ auto actors = tick->target->get_map()->get_actors(targetpos.x, targetpos.y, 6);
+ for (Actor* actor : actors) {
if (actor == tick->target) continue;
if (actor->is_type_of(ACT_HERO) != ishero) {
diff --git a/src/IfSeeEnemyNode.cpp b/src/IfSeeEnemyNode.cpp
index 717e1dc..8cdae36 100644
--- a/src/IfSeeEnemyNode.cpp
+++ b/src/IfSeeEnemyNode.cpp
@@ -16,9 +16,8 @@ BehaviourTreeStatus IfSeeEnemyNode::tick(BTTick * tick) {
bool ishero = tick->target->is_type_of(ACT_HERO);
vec2i targetpos = tick->target->get_position();
- auto actors = tick->target->get_map()->get_entities(targetpos.x, targetpos.y, 6, ENTITY_ACTOR);
- for (auto ent : actors) {
- auto actor = (Actor*)ent;
+ auto actors = tick->target->get_map()->get_actors(targetpos.x, targetpos.y, 6);
+ for (Actor* actor : actors) {
if (actor == tick->target) continue;
if (actor->is_type_of(ACT_HERO) != ishero) {
diff --git a/src/IfSeeFriendNode.cpp b/src/IfSeeFriendNode.cpp
index eed39f3..02500ac 100644
--- a/src/IfSeeFriendNode.cpp
+++ b/src/IfSeeFriendNode.cpp
@@ -17,9 +17,8 @@ BehaviourTreeStatus IfSeeFriendNode::tick(BTTick * tick) {
bool ishero = tick->target->is_type_of(ACT_HERO);
vec2i targetpos = tick->target->get_position();
- auto actors = tick->target->get_map()->get_entities(targetpos.x, targetpos.y, 6, ENTITY_ACTOR);
- for (auto ent : actors) {
- auto actor = (Actor*)ent;
+ auto actors = tick->target->get_map()->get_actors(targetpos.x, targetpos.y, 6);
+ for (Actor* actor : actors) {
if (actor == tick->target) continue;
if (actor->is_type_of(ACT_HERO) == ishero) {
diff --git a/src/Mapgen.cpp b/src/Mapgen.cpp
index a4e7aea..db49f9f 100644
--- a/src/Mapgen.cpp
+++ b/src/Mapgen.cpp
@@ -65,7 +65,7 @@ void maze_fill(Tilemap& map, int x, int y, Rng &rng) {
}
Tilemap generate_dungeon(int width, int height) {
- return generate_dungeon(std::random_device()(), width, height);
+ return generate_dungeon(Rng::get_random_seed(), width, height);
}
Tilemap generate_dungeon(unsigned int seed, int width, int height) {
@@ -186,8 +186,8 @@ Tilemap generate_dungeon(unsigned int seed, int width, int height) {
// Clean up dead ends in the maze
std::vector dead_ends;
- for (int y = 0; y < map.get_height(); y++) {
- for (int x = 0; x < map.get_width(); x++) {
+ for (int y = 0; y < height; y++) {
+ for (int x = 0; x < width; x++) {
std::vector neigh{vec2i(x + 1, y), vec2i(x, y + 1), vec2i(x - 1, y), vec2i(x, y - 1) };
int count = 0;
for (vec2i pos : neigh) {
@@ -200,7 +200,7 @@ Tilemap generate_dungeon(unsigned int seed, int width, int height) {
}
}
}
- int pass_amount = 100;
+ int pass_amount = width + height;
for (int pass = 0; pass < pass_amount; pass++) {
if (dead_ends.empty()) break;
std::vector new_dead_ends;
diff --git a/src/PlayState.cpp b/src/PlayState.cpp
index 2bc4cbe..2a629d2 100644
--- a/src/PlayState.cpp
+++ b/src/PlayState.cpp
@@ -18,7 +18,7 @@
const int mapwidth = 32;
-InputAction action;
+InputAction player_action;
void PlayState::load() {
SDL_LogVerbose(SDL_LOG_CATEGORY_SYSTEM, "Creating ascii tileset...\n");
@@ -63,37 +63,45 @@ void PlayState::load() {
}
void PlayState::new_game() {
- action = ACTION_NONE;
+ player_action = ACTION_NONE;
- if (hero != nullptr) {
- delete hero;
- hero = nullptr;
+ if (player_actor != nullptr) {
+ delete player_actor;
+ player_actor = nullptr;
}
SDL_LogVerbose(SDL_LOG_CATEGORY_SYSTEM, "Creating tilemap...\n");
Rng rng;
- tilemap = generate_dungeon(64, 64);
+ tilemap = generate_dungeon(128, 128);
vec2i heropos;
do {
heropos.x = rng.get_int(1, tilemap.get_width() - 1);
heropos.y = rng.get_int(1, tilemap.get_width() - 1);
} while (tilemap.get_tile(heropos.x, heropos.y) == '#');
- hero = new Hero(&tilemap, vec2i(heropos.x,heropos.y));
- tilemap.add_entity(hero);
+ player_actor = new Hero(&tilemap, vec2i(heropos.x,heropos.y));
+ tilemap.add_actor(player_actor);
SDL_LogVerbose(SDL_LOG_CATEGORY_SYSTEM, "Done.\n");
SDL_LogVerbose(SDL_LOG_CATEGORY_SYSTEM, "Calculating initial FOV...\n");
fov = FieldOfView(&tilemap);
- fov.calc(hero->get_position(), 6);
+ fov.calc(player_actor->get_position(), 6);
SDL_LogVerbose(SDL_LOG_CATEGORY_SYSTEM, "Done.\n");
+
+ current_entity_index = 0;
+ Actor* actor = tilemap.get_actor_list()->at(current_entity_index);
+ is_player_turn = actor->player_controlled;
+ if (is_player_turn) camera_pos = actor->get_position();
}
Gamestate *PlayState::update(double delta) {
- if (action != ACTION_NONE) {
+ if (!is_player_turn || player_action != ACTION_NONE) {
SDL_LogVerbose(SDL_LOG_CATEGORY_SYSTEM, "Starting turn...\n");
- if (hero && hero->is_alive()) {
+ std::vector* actors = tilemap.get_actor_list();
+ Actor* actor = actors->at(current_entity_index);
+
+ if (is_player_turn && actor->is_alive()) {
vec2i dir;
- switch (action) {
+ switch (player_action) {
case ACTION_MOVE_NORTH: dir = {0, -1}; break;
case ACTION_MOVE_NORTHWEST: dir = {-1, -1}; break;
case ACTION_MOVE_NORTHEAST: dir = {1, -1}; break;
@@ -103,59 +111,44 @@ Gamestate *PlayState::update(double delta) {
case ACTION_MOVE_SOUTHWEST: dir = {-1, 1}; break;
case ACTION_MOVE_SOUTHEAST: dir = {1, 1}; break;
case ACTION_WAIT: dir = {0, 0}; break;
- default: action = ACTION_NONE; SDL_LogVerbose(SDL_LOG_CATEGORY_SYSTEM, "Turn aborted: no player action.\n"); return nullptr; // abort turn
+ default: player_action = ACTION_NONE; SDL_LogVerbose(SDL_LOG_CATEGORY_SYSTEM, "Turn aborted: no player action.\n"); return nullptr; // abort turn
}
if (dir != vec2i(0,0)) {
- if (!hero->move(dir.x, dir.y)) {
- vec2i heropos = hero->get_position();
- auto acts = tilemap.get_entities(heropos.x + dir.x, heropos.y + dir.y, 0, ENTITY_ACTOR);
+ if (!actor->move(dir.x, dir.y)) {
+ vec2i heropos = actor->get_position();
+ auto acts = tilemap.get_actors(heropos.x + dir.x, heropos.y + dir.y, 0);
if(acts.empty()) {
SDL_LogVerbose(SDL_LOG_CATEGORY_SYSTEM, "Turn aborted: invalid player action.\n");
- action = ACTION_NONE;
+ player_action = ACTION_NONE;
return nullptr; // unable to move and nothing to attack == abort turn
}
for (auto ent : acts) {
auto act = (Actor*)ent;
- if (act->is_alive() && act->get_actor_faction() != hero->get_actor_faction()) {
- hero->attack(act);
+ if (act->is_alive() && act->get_actor_faction() != actor->get_actor_faction()) {
+ actor->attack(act);
break;
}
}
}
}
- hero->update();
- fov.calc(hero->get_position(), 6);
+ fov.calc(actor->get_position(), 6);
}
+ actor->update();
- auto actors = tilemap.get_entity_list();
- for (Entity* var : *actors) {
- if (var == hero) continue;
- if (var->entity_type() == ENTITY_ACTOR) {
- ((Actor*)var)->update();
- }
+ player_action = ACTION_NONE;
+
+ current_entity_index = (current_entity_index + 1) % actors->size(); // Increase the current actor index
+ Actor* next = actors->at(current_entity_index);
+ is_player_turn = next->player_controlled; // Check if next actor is player controlled
+ if (is_player_turn) {
+ camera_pos = next->get_position();
+ player_actor = next;
}
- /* // We got enough memory, we can leave the corpses on the field.
- unsigned int actor_size = actors->size();
- for (unsigned int i = actor_size - 1; i <= actor_size; i--) { // Woo unsigned int underflow abuse!
- if (!actors->at(i)->is_alive()) {
- if (actors->at(i) == hero) {
- hero = nullptr;
- }
- delete actors->at(i);
- actors->erase(actors->begin() + i);
- }
- }
- */
- action = ACTION_NONE;
SDL_LogVerbose(SDL_LOG_CATEGORY_SYSTEM, "Turn finished.\n");
}
return nullptr;
}
-bool debug_actors = false;
-bool debug_settings = false;
-bool debug_disable_fov = false;
-
void PlayState::draw(double delta) {
if (debug) {
{
@@ -186,7 +179,7 @@ void PlayState::draw(double delta) {
if (debug_actors) {
ImGui::Begin("Actors", &debug_actors);
- auto actors = tilemap.get_entity_list();
+ auto actors = tilemap.get_actor_list();
const char* headers[] {
"id", "name", "health", "strength"
};
@@ -207,35 +200,31 @@ void PlayState::draw(double delta) {
}
}
- vec2i asciisize = {
+ const vec2i asciisize = {
ascii->get_tile_width(),
ascii->get_tile_height(),
};
- vec2i tilesize = {
+ const vec2i tilesize = {
app->renderer->get_renderer_width() / ascii->get_tile_width(),
app->renderer->get_renderer_height() / ascii->get_tile_height(),
};
- vec2i margin = {
+ const vec2i margin = {
(app->renderer->get_renderer_width() - tilesize.x * asciisize.x)/2,
(app->renderer->get_renderer_height() - tilesize.y * asciisize.y)/2,
};
- vec2i heropos = {0,0};
- if (hero) {
- heropos = hero->get_position();
- }
- vec2i offset = {
- (tilesize.x/2-heropos.x),
- (tilesize.y/2-heropos.y),
+ const vec2i offset = {
+ (tilesize.x/2-camera_pos.x),
+ (tilesize.y/2- camera_pos.y),
};
tilemap.draw(app->renderer, ascii, margin.x, margin.y, -offset.x, -offset.y, tilesize.x, tilesize.y, debug_disable_fov ? nullptr : &fov);
- auto entities = tilemap.get_entity_list();
+ auto entities = tilemap.get_actor_list();
- Color black = Color(0, 0, 0, 1);
+ const Color black = Color(0, 0, 0, 1);
// Draw dead actors
- for (Entity* var : *entities) {
- if (var->entity_type() == ENTITY_ACTOR && ((Actor*)var)->is_alive()) continue;
+ for (Actor* var : *entities) {
+ if (var->is_alive()) continue;
vec2i pos = var->get_position();
if (debug_disable_fov || fov.can_see(pos)) {
@@ -247,22 +236,20 @@ void PlayState::draw(double delta) {
}
// Draw the rest of the entities
- for (Entity* var : *entities) {
- if (var->entity_type() == ENTITY_ACTOR && !((Actor*)var)->is_alive()) continue;
+ for (Actor* var : *entities) {
+ if (!var->is_alive()) continue;
vec2i pos = var->get_position();
if (debug_disable_fov || fov.can_see(pos)) {
int sprite = var->get_sprite_id();
-
Color fg = var->get_sprite_color();
-
app->renderer->draw_sprite(ascii->get_sprite(sprite), fg, black, margin.x + (offset.x + pos.x) * asciisize.x, margin.y + (offset.y + pos.y) * asciisize.y);
}
}
- if (hero != nullptr) {
+ if (player_actor != nullptr) {
Color fg = Color(1, 0.01, 0.01, 1);
- for (int i = 0; i < hero->get_health(); i++) {
+ for (int i = 0; i < player_actor->get_health(); i++) {
app->renderer->draw_sprite(ascii->get_sprite(3), fg, black, (i+1) * asciisize.x, asciisize.y);
}
}
@@ -278,7 +265,7 @@ void PlayState::inputevent(InputEvent *event) {
case ACTION_RESET: new_game(); break;
case ACTION_ESCAPE_MENU: break; // TODO
case ACTION_NONE: break;
- default: action = event->action; break;
+ default: player_action = event->action; break;
}
}
}
diff --git a/src/PlayState.h b/src/PlayState.h
index 9cfab04..24cdb42 100644
--- a/src/PlayState.h
+++ b/src/PlayState.h
@@ -1,10 +1,4 @@
-//
-// Created by Adrian on 2017-09-21.
-//
-
-#ifndef DUNGEON_PLAYSTATE_H
-#define DUNGEON_PLAYSTATE_H
-
+#pragma once
#include "Gamestate.h"
#include "Tilemap.h"
@@ -16,10 +10,18 @@ class Actor;
class PlayState : public Gamestate {
Tileset* ascii;
Tilemap tilemap;
- Actor * hero;
+ Actor * player_actor;
FieldOfView fov;
+ unsigned int current_entity_index;
+ bool is_player_turn;
+
+ vec2i camera_pos;
bool debug;
+ bool debug_actors = false;
+ bool debug_settings = false;
+ bool debug_disable_fov = false;
+
public:
void new_game();
void load() override;
@@ -28,6 +30,3 @@ public:
void quit() override;
void inputevent(InputEvent* event) override;
};
-
-
-#endif //DUNGEON_PLAYSTATE_H
diff --git a/src/RangedAttackNode.cpp b/src/RangedAttackNode.cpp
index e4e5d6d..af693e9 100644
--- a/src/RangedAttackNode.cpp
+++ b/src/RangedAttackNode.cpp
@@ -14,10 +14,9 @@ BehaviourTreeStatus RangedAttackNode::tick(BTTick * tick) {
bool ishero = tick->target->is_type_of(ACT_HERO);
vec2i targetpos = tick->target->get_position();
- auto actors = tick->target->get_map()->get_entities(targetpos.x, targetpos.y, 6, ENTITY_ACTOR);
+ auto actors = tick->target->get_map()->get_actors(targetpos.x, targetpos.y, 6);
std::vector enemies;
- for (auto ent : actors) {
- auto actor = (Actor*)ent;
+ for (Actor* actor : actors) {
if (actor == tick->target) continue;
if (actor->is_type_of(ACT_HERO) != ishero) {
diff --git a/src/Renderer.cpp b/src/Renderer.cpp
index 4ccb24a..06f73a8 100644
--- a/src/Renderer.cpp
+++ b/src/Renderer.cpp
@@ -40,7 +40,7 @@ GLuint LoadShader(const char* path, GLenum shadertype) {
}
GLboolean result = GL_FALSE;
- int infologlength;
+ int infologlength = 0;
SDL_Log("Compiling shader: %s\n", path);
char const * source = shadersource.c_str();
@@ -66,7 +66,7 @@ GLuint CreateShaderProgram(GLuint vertshader, GLuint fragshader) {
glLinkProgram(programId);
GLboolean result = GL_FALSE;
- int infologlength;
+ int infologlength = 0;
glGetShaderiv(programId, GL_LINK_STATUS, &result);
glGetShaderiv(programId, GL_INFO_LOG_LENGTH, &infologlength);
diff --git a/src/Rng.cpp b/src/Rng.cpp
index 8596f58..4342fc1 100644
--- a/src/Rng.cpp
+++ b/src/Rng.cpp
@@ -2,9 +2,14 @@
#include
#include
+std::random_device rd;
+
+unsigned int Rng::get_random_seed() {
+ return rd();
+}
+
Rng::Rng() {
- std::random_device rd;
- Rng(rd(), 0);
+ Rng(get_random_seed(), 0);
}
@@ -27,3 +32,12 @@ int Rng::get_int(int min, int max) {
step++;
return std::uniform_int_distribution{min, max}(mte);
}
+
+float Rng::get_float(float max) {
+ return get_float(0, max);
+}
+
+float Rng::get_float(float min, float max) {
+ step++;
+ return std::uniform_real_distribution{min, max}(mte);
+}
diff --git a/src/Rng.h b/src/Rng.h
index 67628b8..5475f7f 100644
--- a/src/Rng.h
+++ b/src/Rng.h
@@ -7,11 +7,15 @@ class Rng {
unsigned int step = 0;
std::mt19937 mte;
public:
+ static unsigned int get_random_seed();
+
Rng();
Rng(unsigned int seed, unsigned int step = 0);
~Rng();
- int get_int(int max);
+ int get_int(int max = 100);
int get_int(int min, int max);
+ float get_float(float max = 1);
+ float get_float(float min, float max);
};
diff --git a/src/Tilemap.cpp b/src/Tilemap.cpp
index e1c3e36..cd42a41 100644
--- a/src/Tilemap.cpp
+++ b/src/Tilemap.cpp
@@ -17,7 +17,7 @@ Tilemap::Tilemap(int width, int height) {
}
Tilemap::~Tilemap() {
- for (auto var : entities) {
+ for (auto var : actors) {
delete var;
}
}
@@ -68,7 +68,7 @@ bool Tilemap::is_blocked(int x, int y) {
if (tilemap[get_index(x, y)] == '#') { // TODO: Replace hardcoded tiles
return true;
}
- for (Entity* var : entities) {
+ for (Entity* var : actors) {
vec2i pos = var->get_position();
if (var->has_collision() && pos == vec2i(x, y))
return true;
@@ -78,19 +78,19 @@ bool Tilemap::is_blocked(int x, int y) {
return true;
}
-void Tilemap::add_entity(Entity *actor) {
- for (Entity* var : entities) {
+void Tilemap::add_actor(Actor *actor) {
+ for (Actor* var : actors) {
if (var == actor) {
return;
}
}
- entities.push_back(actor);
+ actors.push_back(actor);
}
-void Tilemap::remove_entity(Entity * actor) {
- for (auto it = entities.begin(); it != entities.end(); it++) {
+void Tilemap::remove_actor(Actor * actor) {
+ for (auto it = actors.begin(); it != actors.end(); it++) {
if ((*it) == actor) {
- entities.erase(it);
+ actors.erase(it);
return;
}
}
@@ -98,7 +98,7 @@ void Tilemap::remove_entity(Entity * actor) {
Entity * Tilemap::get_entity(int x, int y, EntityTypes type) {
vec2i pos = { x,y };
- for (Entity* ent : entities) {
+ for (Entity* ent : actors) {
if (ent->entity_type() == type) {
vec2i apos = ent->get_position();
if (apos == pos) {
@@ -109,25 +109,23 @@ Entity * Tilemap::get_entity(int x, int y, EntityTypes type) {
return nullptr;
}
-std::vector Tilemap::get_entities(int x, int y, int range, EntityTypes type) {
- std::vector found;
+std::vector Tilemap::get_actors(int x, int y, int range) {
+ std::vector found;
std::vector neigh = get_neighbours(x, y, range);
- for (Entity* ent : entities) {
+ for (Actor* ent : actors) {
for (vec2i pos : neigh) {
- if (ent->entity_type() == type) {
- vec2i apos = ent->get_position();
- if (apos == pos) {
- found.emplace_back(ent);
- break;
- }
+ vec2i apos = ent->get_position();
+ if (apos == pos) {
+ found.emplace_back(ent);
+ break;
}
}
}
return found;
}
-std::vector* Tilemap::get_entity_list() {
- return &entities;
+std::vector* Tilemap::get_actor_list() {
+ return &actors;
}
void Tilemap::draw(Renderer *renderer, Tileset* tileset, int x, int y, int tx, int ty, int tw, int th, FieldOfView* view) {
diff --git a/src/Tilemap.h b/src/Tilemap.h
index dca2c14..2efd8dc 100644
--- a/src/Tilemap.h
+++ b/src/Tilemap.h
@@ -2,7 +2,7 @@
#include
#include
#include "Tileset.h"
-#include "Entity.h"
+#include "Actor.h"
struct vec2i;
class Renderer;
@@ -10,7 +10,7 @@ class FieldOfView;
class Tilemap {
std::vector tilemap;
- std::vector entities;
+ std::vector actors;
int width;
int height;
public:
@@ -28,13 +28,13 @@ public:
void draw(Renderer *renderer, Tileset *tileset, int x, int y, int tx, int ty, int tw, int th, FieldOfView* view);
- void add_entity(Entity *actor);
- void remove_entity(Entity *actor);
+ void add_actor(Actor *actor);
+ void remove_actor(Actor *actor);
void debug_print();
Entity* get_entity(int x, int y, EntityTypes type);
- std::vector get_entities(int x, int y, int range, EntityTypes type);
- std::vector* get_entity_list();
+ std::vector get_actors(int x, int y, int range);
+ std::vector* get_actor_list();
};