Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions src/environment.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,22 +25,22 @@ namespace envlibcpp {
name = newName;
}

void Environment::addEntity(Entity &entity) {
void Environment::addEntity(Entity& entity) {
entity.setEnvironmentId(id);
grid.addEntity(entity);
}

void Environment::addEntityToLocation(Entity &entity, Location &location) {
void Environment::addEntityToLocation(Entity& entity, Location& location) {
entity.setEnvironmentId(id);
grid.addEntityToLocation(entity, location);
}

void Environment::removeEntity(Entity &entity) {
void Environment::removeEntity(Entity& entity) {
entity.setEnvironmentId(-1);
grid.removeEntity(entity);
}

bool Environment::isEntityPresent(Entity &entity) {
bool Environment::isEntityPresent(Entity& entity) {
return grid.isEntityPresent(entity);
}

Expand All @@ -54,7 +54,7 @@ namespace envlibcpp {
}

envlibcpp::Entity& Environment::getFirstEntity() {
for (envlibcpp::Location &location : getGrid().getLocations()) {
for (envlibcpp::Location& location : getGrid().getLocations()) {
if (location.getNumEntities() > 0) {
return location.getEntities()[0];
}
Expand All @@ -63,8 +63,8 @@ namespace envlibcpp {
}

envlibcpp::Entity& Environment::getEntity(int entityId) {
for (envlibcpp::Location &location : getGrid().getLocations()) {
for (envlibcpp::Entity &entity : location.getEntities()) {
for (envlibcpp::Location& location : getGrid().getLocations()) {
for (envlibcpp::Entity& entity : location.getEntities()) {
if (entity.getId() == entityId) {
return entity;
}
Expand Down
20 changes: 10 additions & 10 deletions src/grid.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,34 +54,34 @@ namespace envlibcpp {
size = newSize;
}

void Grid::addLocation(Location &location) {
void Grid::addLocation(Location& location) {
locations.push_back(location);
}

void Grid::removeLocation(Location &location) {
void Grid::removeLocation(Location& location) {
for (auto i = locations.begin(); i != locations.end(); i++) {
if (i->getId() == location.getId()) {
locations.erase(i);
}
}
}

void Grid::addEntity(Entity &entity) {
void Grid::addEntity(Entity& entity) {
entity.setGridId(id);
Location &firstLocation = getRandomLocation();
Location& firstLocation = getRandomLocation();
firstLocation.addEntity(entity);
}

void Grid::addEntityToLocation(Entity &entity, Location &location) {
void Grid::addEntityToLocation(Entity& entity, Location& location) {
for (Location &l : locations) {
if (l.getId() == location.getId()) {
location.addEntity(entity);
}
}
}

void Grid::removeEntity(Entity &entity) {
for (Location &location : locations) {
void Grid::removeEntity(Entity& entity) {
for (Location& location : locations) {
if (location.isEntityPresent(entity)) {
location.removeEntity(entity);
entity.setLocationId(-1);
Expand All @@ -90,8 +90,8 @@ namespace envlibcpp {
entity.setGridId(-1);
}

bool Grid::isEntityPresent(Entity &entity) {
for (Location &location : locations) {
bool Grid::isEntityPresent(Entity& entity) {
for (Location& location : locations) {
if (location.isEntityPresent(entity)) {
return true;
}
Expand All @@ -100,7 +100,7 @@ namespace envlibcpp {
}

Location& Grid::getLocation(int locationId) {
for (Location &location : locations) {
for (Location& location : locations) {
if (location.getId() == locationId) {
return location;
}
Expand Down
8 changes: 4 additions & 4 deletions src/header/environment.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ namespace envlibcpp {
std::string getName();
Grid& getGrid();
void setName(std::string newName);
void addEntity(Entity &entity);
void addEntityToLocation(Entity &entity, Location &location);
void removeEntity(Entity &entity);
bool isEntityPresent(Entity &entity);
void addEntity(Entity& entity);
void addEntityToLocation(Entity& entity, Location& location);
void removeEntity(Entity& entity);
bool isEntityPresent(Entity& entity);
int getNumEntities();
void printInfo();
envlibcpp::Entity& getFirstEntity();
Expand Down
12 changes: 6 additions & 6 deletions src/header/grid.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,12 @@ namespace envlibcpp {
int getNumEntities();
void setId(int newId);
void setSize(int newSize);
void addLocation(Location &location);
void removeLocation(Location &location);
void addEntity(Entity &entity);
void addEntityToLocation(Entity &entity, Location &location);
void removeEntity(Entity &entity);
bool isEntityPresent(Entity &entity);
void addLocation(Location& location);
void removeLocation(Location& location);
void addEntity(Entity& entity);
void addEntityToLocation(Entity& entity, Location& location);
void removeEntity(Entity& entity);
bool isEntityPresent(Entity& entity);
Location& getLocation(int locationId);
Location& getRandomLocation();
private:
Expand Down
6 changes: 3 additions & 3 deletions src/location.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,12 @@ namespace envlibcpp {
return entities.size();
}

void Location::addEntity(Entity &entity) {
void Location::addEntity(Entity& entity) {
entity.setLocationId(getId());
entities.push_back(entity);
}

void Location::removeEntity(Entity &entity) {
void Location::removeEntity(Entity& entity) {
int index = -1;
for (int i = 0; i < getNumEntities(); i++) {
if (entities[i].getId() == entity.getId()) {
Expand All @@ -44,7 +44,7 @@ namespace envlibcpp {
entity.setLocationId(-1);
}

bool Location::isEntityPresent(Entity &entity) {
bool Location::isEntityPresent(Entity& entity) {
for (Entity &e : entities) {
if (e.getId() == entity.getId()) {
return true;
Expand Down