Implements marking opponents as seen.
continuous-integration/drone/push Build is passing Details

This commit is contained in:
Deukhoofd 2019-12-14 12:40:50 +01:00
parent c25d7b865e
commit 3baed93597
Signed by: Deukhoofd
GPG Key ID: ADF2E9256009EDCE
5 changed files with 58 additions and 2 deletions

View File

@ -64,6 +64,8 @@ namespace CreatureLib::Battling {
void ValidateBattleState();
inline bool HasEnded() const { return _hasEnded; }
inline uint8_t GetResult() const { return _battleResult; }
const std::vector<BattleSide*>& GetSides() const { return _sides; }
};
}

View File

@ -44,6 +44,18 @@ void BattleSide::SetCreature(Creature* creature, uint8_t index) {
_creatures[index] = creature;
creature->SetBattleData(_battle, this);
creature->SetOnBattleField(true);
if (_battle == nullptr)
return;
for (auto side : _battle->GetSides()) {
if (side == this)
continue;
for (auto c : side->GetCreatures()) {
if (c != nullptr) {
c->MarkOpponentAsSeen(creature);
creature->MarkOpponentAsSeen(c);
}
}
}
}
bool BattleSide::CreatureOnSide(const Creature* creature) const {

View File

@ -47,6 +47,8 @@ namespace CreatureLib::Battling {
void GetActiveScripts(std::vector<ScriptWrapper>& scripts) final;
const std::vector<Creature*>& GetCreatures() { return _creatures; }
uint8_t GetSideIndex() { return _index; }
uint8_t GetCreatureIndex(Creature* c) {
for (size_t i = 0; i < _creatures.size(); i++) {

View File

@ -47,6 +47,7 @@ namespace CreatureLib::Battling {
bool _hasOverridenTalent;
std::string _overridenTalentName = "";
std::unordered_set<Creature*> _seenOpponents = {};
std::vector<LearnedAttack*> _attacks;
@ -83,6 +84,9 @@ namespace CreatureLib::Battling {
void Damage(uint32_t damage, DamageSource source);
void OverrideActiveTalent(const std::string& talent);
void MarkOpponentAsSeen(Creature* creature) { _seenOpponents.insert(creature); }
const std::unordered_set<Creature*>& GetSeenOpponents() const { return _seenOpponents; }
void GetActiveScripts(std::vector<ScriptWrapper>& scripts) override;
void ClearVolatileScripts();

View File

@ -185,4 +185,40 @@ TEST_CASE("Switch Creature in, but have attack aimed at it. Attack should hit ne
REQUIRE(c1->GetCurrentHealth() == c1->GetBoostedStat(Core::Statistic::Health));
}
TEST_CASE("Switch Creature in, mark as seen opponent for opponent", "[Integrations]") {
auto library = TestLibrary::Get();
auto c1 = CreateCreature(library, "testSpecies1", 100).WithAttack("standard", AttackLearnMethod::Unknown)->Create();
auto c2 = CreateCreature(library, "testSpecies1", 1).WithAttack("standard", AttackLearnMethod::Unknown)->Create();
CreatureParty party1{c1, c2};
auto battleParty1 = BattleParty(&party1, {CreatureIndex(0, 0)});
auto c3 = CreateCreature(library, "testSpecies1", 1).WithAttack("standard", AttackLearnMethod::Unknown)->Create();
CreatureParty party2{c3};
auto battleParty2 = BattleParty(&party2, {CreatureIndex(1, 0)});
auto battle = Battle(library, {battleParty1, battleParty2});
battle.SwitchCreature(0, 0, c1);
battle.SwitchCreature(1, 0, c3);
auto seen = c3->GetSeenOpponents();
REQUIRE(seen.size() == 1);
REQUIRE(seen.find(c1) != seen.end());
battle.TrySetChoice(new SwitchTurnChoice(c1, c2));
battle.TrySetChoice(new PassTurnChoice(c3));
seen = c3->GetSeenOpponents();
REQUIRE(seen.size() == 2);
REQUIRE(seen.find(c1) != seen.end());
REQUIRE(seen.find(c2) != seen.end());
battle.TrySetChoice(new SwitchTurnChoice(c2, c1));
battle.TrySetChoice(new PassTurnChoice(c3));
seen = c3->GetSeenOpponents();
REQUIRE(seen.size() == 2);
REQUIRE(seen.find(c1) != seen.end());
REQUIRE(seen.find(c2) != seen.end());
}
#endif