Skip to content

Commit

Permalink
implemented #146
Browse files Browse the repository at this point in the history
  • Loading branch information
csacro committed May 4, 2020
1 parent adf9e43 commit 5b025b5
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 3 deletions.
8 changes: 5 additions & 3 deletions src/gameLogic/generation/ActionGenerator_Server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

#include <datatypes/gameplay/CatAction.hpp>
#include <util/GameLogicUtils.hpp>
#include <datatypes/gameplay/JanitorAction.hpp>
#include "ActionGenerator.hpp"

namespace spy::gameplay {
Expand All @@ -20,9 +21,10 @@ namespace spy::gameplay {
return action;
}

std::shared_ptr<BaseOperation> ActionGenerator::generateJanitorAction(const State &/*s*/) {
// TODO implement
return std::shared_ptr<BaseOperation>();
std::shared_ptr<BaseOperation> ActionGenerator::generateJanitorAction(const State &s) {
auto target = util::GameLogicUtils::getRandomCharacterNeighbouringField(s, s.getJanitorCoordinates().value());
auto action = std::make_shared<JanitorAction>(spy::gameplay::JanitorAction(target));
return action;
}

std::shared_ptr<BaseOperation> ActionGenerator::generateNPCAction(const State &/*s*/, const util::UUID &/*activeNPC*/) {
Expand Down
7 changes: 7 additions & 0 deletions src/util/GameLogicUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -126,4 +126,11 @@ namespace spy::util {
}
return result;
}

const util::Point &GameLogicUtils::getRandomCharacterNeighbouringField(const gameplay::State &s, const Point &p) {
return getRandomNeighbouringField(s, p, [&s](util::Point currentPoint) {
// check if character is on point
return isPersonOnField(s, currentPoint);
});
}
}
9 changes: 9 additions & 0 deletions src/util/GameLogicUtils.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,15 @@ namespace spy::util {
static std::optional<util::Point>
getRandomCharacterFreeNeighbourField(const spy::gameplay::State &s, const util::Point &p);

/**
* @brief get point of of a neighbouring field with a character on it. If there are more fields randomize
* @param s current state
* @param p Point where character is at the moment
* @return point where closest character is standing
*/
static const util::Point &
getRandomCharacterNeighbouringField(const spy::gameplay::State &s, const util::Point &p);

/**
* @brief get point of random neighbouring field which fulfils certain condition
* @tparam t function
Expand Down

0 comments on commit 5b025b5

Please sign in to comment.