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
1,102 changes: 752 additions & 350 deletions include/PokeSim.hpp

Large diffs are not rendered by default.

36 changes: 19 additions & 17 deletions src/AnalyzeEffect/AnalyzeEffect.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include <Battle/Clone/Clone.hpp>
#include <Battle/Helpers/Helpers.hpp>
#include <Battle/Pokemon/ManagePokemonState.hpp>
#include <Battle/Setup/EmplaceTagFromEnum.hpp>
#include <CalcDamage/CalcDamage.hpp>
#include <CalcDamage/Helpers.hpp>
#include <Components/AnalyzeEffect/Aliases.hpp>
Expand Down Expand Up @@ -261,34 +262,33 @@ types::entity createAnalyzeEffectMove(
types::entity moveEntity =
createActionMoveForTarget({registry, defenderEntity}, battleEntity, attackerEntity, move, pokedex);
registry.emplace<MoveName>(moveEntity, move);
registry.emplace<pokesim::tags::AnalyzeEffect>(moveEntity);
registry.emplace_or_replace<tags::Attacker>(attackerEntity);
registry.emplace_or_replace<tags::Defender>(defenderEntity);

return moveEntity;
}

void createOneCalculationMovePair(
types::handle inputHandle, Battle battle, EffectMove move, Attacker attacker, const Defenders& defenders,
types::handle inputHandle, Battle battle, EffectMove move, Attacker attacker, Defender defender,
const Pokedex& pokedex) {
entt::entity moveEntity =
createAnalyzeEffectMove(*inputHandle.registry(), move.val, battle.val, attacker.val, defenders.only(), pokedex);
createAnalyzeEffectMove(*inputHandle.registry(), move.val, battle.val, attacker.val, defender.val, pokedex);
inputHandle.emplace<MovePair>(moveEntity, moveEntity);
}

void createTwoCalculationsMovePair(
types::handle inputHandle, Battle battle, EffectMove move, Attacker attacker, const Defenders& defenders,
types::handle inputHandle, Battle battle, EffectMove move, Attacker attacker, Defender defender,
const OriginalInputEntities& originals, const Pokedex& pokedex) {
types::registry& registry = *inputHandle.registry();

entt::entity originalEntity =
createAnalyzeEffectMove(registry, move.val, originals.battle, originals.attacker, originals.defender, pokedex);
entt::entity copyEntity =
createAnalyzeEffectMove(registry, move.val, battle.val, attacker.val, defenders.only(), pokedex);
createAnalyzeEffectMove(registry, move.val, battle.val, attacker.val, defender.val, pokedex);

// All active pokemon in should have their stats refreshed in doubles for moves like Beat Up which rely on the stats
// of Pokemon outside of the attacker and defender
for (types::entity pokemon : {attacker.val, defenders.only()}) {
for (types::entity pokemon : {attacker.val, defender.val}) {
registry.emplace_or_replace<pokesim::tags::AtkStatUpdateRequired>(pokemon);
registry.emplace_or_replace<pokesim::tags::DefStatUpdateRequired>(pokemon);
registry.emplace_or_replace<pokesim::tags::SpaStatUpdateRequired>(pokemon);
Expand Down Expand Up @@ -334,19 +334,19 @@ void assignInputsToClones(

const GroupedInputs& groupedInputs = registry.get<GroupedInputs>(input);
for (types::entity originalInput : groupedInputs.val) {
const auto& [battle, move, attacker, defenders, effectTarget] =
registry.get<Battle, EffectMove, Attacker, Defenders, EffectTarget>(originalInput);
const auto& [battle, move, attacker, defender, effectTarget] =
registry.get<Battle, EffectMove, Attacker, Defender, EffectTarget>(originalInput);

registry.emplace<OriginalInputEntities>(
originalInput,
OriginalInputEntities{battle.val, attacker.val, defenders.only(), effectTarget.val});
OriginalInputEntities{battle.val, attacker.val, defender.val, effectTarget.val});

const auto& clonedAttackers = clonedEntityMap.at(attacker.val);
POKESIM_REQUIRE(
battleClones.size() == clonedAttackers.size(),
"Each attacker must have a clone and no more clones than inputs should be made.");

const auto& clonedDefenders = clonedEntityMap.at(defenders.only());
const auto& clonedDefenders = clonedEntityMap.at(defender.val);
POKESIM_REQUIRE(
battleClones.size() == clonedDefenders.size(),
"Each defender must have a clone and no more clones than inputs should be made.");
Expand All @@ -358,7 +358,7 @@ void assignInputsToClones(

battle.val = battleClones[cloneIndex];
attacker.val = clonedAttackers[cloneIndex];
defenders.val[0] = clonedDefenders[cloneIndex];
defender.val = clonedDefenders[cloneIndex];
effectTarget.val = clonedEffectTarget[cloneIndex];
}

Expand Down Expand Up @@ -414,12 +414,14 @@ void applyStatusEffect(types::handle inputHandle, EffectTarget effectTarget, Sta
types::registry& registry = *inputHandle.registry();

EffectPresentCheck statusCheck = hasStatusEffect(registry, effectTarget, effect);
types::handle pokemonHandle{registry, effectTarget.val};
clearStatus(pokemonHandle);
if (statusCheck == EffectPresentCheck::PRESENT_AND_APPLIED) {
clearStatus({registry, effectTarget.val});
setInvertFinalAnswer(inputHandle);
}
else {
setStatus({registry, effectTarget.val}, effect.name);
pokemonHandle.emplace<StatusName>(effect.name);
status::tags::emplaceTagFromEnum(effect.name, pokemonHandle);
}
}

Expand Down Expand Up @@ -478,11 +480,11 @@ void createOutput(types::handle inputHandle, const MovePair& movePairs) {
}

void restoreInputs(
const OriginalInputEntities& originalEntities, Battle& battle, Attacker& attacker, Defenders& defenders,
const OriginalInputEntities& originalEntities, Battle& battle, Attacker& attacker, Defender& defender,
EffectTarget& effectTarget) {
battle.val = originalEntities.battle;
attacker.val = originalEntities.attacker;
defenders.val[0] = originalEntities.defender;
defender.val = originalEntities.defender;
effectTarget.val = originalEntities.effectTarget;
}

Expand Down Expand Up @@ -511,10 +513,10 @@ void removeUsedMoves(types::registry& registry, const MovePair& movePair, types:
}
}

void removeMovePairs(types::handle inputHandle, MovePair& movePair, Attacker& attacker, Defenders& defenders) {
void removeMovePairs(types::handle inputHandle, MovePair& movePair, Attacker& attacker, Defender& defender) {
types::registry& registry = *inputHandle.registry();
removeUsedMoves<UsedMovesAsAttacker>(registry, movePair, attacker.val);
removeUsedMoves<UsedMovesAsDefender>(registry, movePair, defenders.only());
removeUsedMoves<UsedMovesAsDefender>(registry, movePair, defender.val);

const OriginalInputEntities* original = inputHandle.try_get<OriginalInputEntities>();
if (original) {
Expand Down
4 changes: 2 additions & 2 deletions src/AnalyzeEffect/AnalyzeEffectDebugChecks.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,8 @@ struct Checks : pokesim::debug::Checks {
}

DamageRollKind getDamageRollKind(types::entity input, DamageRollOptions damageRollOptions) const {
const Defenders& defenders = registry->get<Defenders>(input);
const Side& side = registry->get<Side>(defenders.only());
Defender defender = registry->get<Defender>(input);
const Side& side = registry->get<Side>(defender.val);
PlayerSideId playerSide = registry->get<PlayerSide>(side.val).val;
switch (playerSide) {
case PlayerSideId::P1: {
Expand Down
5 changes: 1 addition & 4 deletions src/AnalyzeEffect/Setup/AnalyzeEffectInputSetup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,7 @@ void InputSetup::setEffectTarget(types::entity entity) {
}

void InputSetup::setDefender(types::entity entity) {
POKESIM_REQUIRE(
!handle.try_get<Defenders>(),
"Calc damage only supports one defender per move. Make a new move instead.");
handle.emplace<Defenders>().val.push_back(entity);
handle.emplace<Defender>(entity);
}

void InputSetup::setEffectMove(dex::Move move) {
Expand Down
6 changes: 5 additions & 1 deletion src/Battle/Clone/Clone.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -297,10 +297,14 @@ types::ClonedEntityMap clone(types::registry& registry, std::optional<types::ent
remapComponentEntities<CurrentActionMovesAsTarget>(registry, entityMap);
remapComponentEntities<CurrentActionMoveSlot>(registry, entityMap);
remapComponentEntities<CurrentActionSource>(registry, entityMap);
remapComponentEntities<CurrentActionTarget>(registry, entityMap);
remapComponentEntities<CurrentActionTargets>(registry, entityMap);
remapComponentEntities<CurrentEffectsAsSource>(registry, entityMap);
remapComponentEntities<CurrentEffectsAsTarget>(registry, entityMap);
remapComponentEntities<CurrentEffectSource>(registry, entityMap);
remapComponentEntities<CurrentEffectTarget>(registry, entityMap);
remapComponentEntities<FoeSide>(registry, entityMap);
remapComponentEntities<LastUsedMove>(registry, entityMap);
remapComponentEntities<MoveEffect>(registry, entityMap);
remapComponentEntities<MoveSlots>(registry, entityMap);
remapComponentEntities<NextAction>(registry, entityMap);
remapComponentEntities<Pokemon>(registry, entityMap);
Expand Down
13 changes: 12 additions & 1 deletion src/Battle/Helpers/Helpers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include <Components/Names/MoveNames.hpp>
#include <Components/Tags/Current.hpp>
#include <Components/Tags/PokemonTags.hpp>
#include <Components/Tags/SimulationTags.hpp>
#include <Config/Require.hpp>
#include <Pokedex/Pokedex.hpp>
#include <Types/Entity.hpp>
Expand Down Expand Up @@ -109,11 +110,21 @@ types::entity createActionMoveForTarget(
registry.emplace<tags::CurrentActionMove>(moveEntity);
registry.emplace<Battle>(moveEntity, battleEntity);
registry.emplace<CurrentActionSource>(moveEntity, sourceEntity);
registry.emplace<CurrentActionTargets>(moveEntity).val.push_back(targetHandle.entity());
registry.emplace<CurrentActionTarget>(moveEntity, targetHandle.entity());

targetHandle.get_or_emplace<CurrentActionMovesAsTarget>().val.push_back(moveEntity);
registry.get_or_emplace<CurrentActionMovesAsSource>(sourceEntity).val.push_back(moveEntity);

if (registry.all_of<tags::SimulateTurn>(battleEntity)) {
registry.emplace<tags::SimulateTurn>(moveEntity);
}
if (registry.all_of<tags::CalculateDamage>(battleEntity)) {
registry.emplace<tags::CalculateDamage>(moveEntity);
}
if (registry.all_of<tags::AnalyzeEffect>(battleEntity)) {
registry.emplace<tags::AnalyzeEffect>(moveEntity);
}

return moveEntity;
}
} // namespace pokesim
19 changes: 8 additions & 11 deletions src/Battle/ManageBattleState.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ void collectTurnOutcomeBattles(types::handle leafBattleHandle, const RootBattle&
leafBattleHandle.entity());
}

void setCurrentActionSource(types::handle battleHandle, const Sides& sides, const CurrentAction& action) {
void setCurrentActionSource(types::handle battleHandle, const Sides& sides, CurrentAction action) {
types::registry& registry = *battleHandle.registry();
const SourceSlotName& sourceSlotName = registry.get<SourceSlotName>(action.val);
types::entity sourceEntity = slotToPokemonEntity(registry, sides, sourceSlotName.name);
Expand All @@ -43,7 +43,7 @@ void setCurrentActionSource(types::handle battleHandle, const Sides& sides, cons
}

void setCurrentActionTarget(
types::handle battleHandle, const Sides& sides, const CurrentAction& action, const CurrentActionSource& source) {
types::handle battleHandle, const Sides& sides, CurrentAction action, CurrentActionSource source) {
types::registry& registry = *battleHandle.registry();
const TargetSlotName& targetSlotName = registry.get<TargetSlotName>(action.val);
types::entity targetEntity = slotToPokemonEntity(registry, sides, targetSlotName.name);
Expand All @@ -59,21 +59,17 @@ void setCurrentActionTarget(
}

void setCurrentActionMove(
types::handle battleHandle, const CurrentActionSource& source, const CurrentActionTargets& targets,
const CurrentAction& action, const Pokedex& pokedex) {
types::handle battleHandle, CurrentActionSource source, const CurrentActionTargets& targets, CurrentAction action,
const Pokedex& pokedex) {
types::registry& registry = *battleHandle.registry();
const action::Move& move = registry.get<action::Move>(action.val);
const MoveSlots& moveSlots = registry.get<MoveSlots>(source.val);

types::entity moveSlotEntity = moveToEntity(registry, moveSlots, move.name);

types::entity moveEntity =
createActionMoveForTarget({registry, targets.only()}, battleHandle.entity(), source.val, move.name, pokedex);

if (battleHandle.all_of<tags::SimulateTurn>()) {
registry.emplace<tags::SimulateTurn>(moveEntity);
for (types::entity target : targets.val) {
createActionMoveForTarget({registry, target}, battleHandle.entity(), source.val, move.name, pokedex);
}

types::entity moveSlotEntity = moveToEntity(registry, moveSlots, move.name);
battleHandle.emplace<CurrentActionMoveSlot>(moveSlotEntity);
registry.emplace<tags::CurrentActionMoveSlot>(moveSlotEntity);
}
Expand All @@ -82,6 +78,7 @@ void clearCurrentAction(Simulation& simulation) {
types::registry& registry = simulation.registry;
registry.clear<CurrentAction>();
registry.clear<CurrentActionTargets>();
registry.clear<CurrentActionTarget>();
registry.clear<CurrentActionSource>();
registry.clear<CurrentActionMovesAsSource>();
registry.clear<CurrentActionMovesAsTarget>();
Expand Down
8 changes: 4 additions & 4 deletions src/Battle/ManageBattleState.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@ struct RootBattle;
void assignRootBattle(types::handle battleHandle);
void collectTurnOutcomeBattles(types::handle leafBattleHandle, const RootBattle& root);

void setCurrentActionSource(types::handle battleHandle, const Sides& sides, const CurrentAction& action);
void setCurrentActionSource(types::handle battleHandle, const Sides& sides, CurrentAction action);
void setCurrentActionTarget(
types::handle battleHandle, const Sides& sides, const CurrentAction& action, const CurrentActionSource& source);
types::handle battleHandle, const Sides& sides, CurrentAction action, CurrentActionSource source);
void setCurrentActionMove(
types::handle battleHandle, const CurrentActionSource& source, const CurrentActionTargets& targets,
const CurrentAction& action, const Pokedex& pokedex);
types::handle battleHandle, CurrentActionSource source, const CurrentActionTargets& targets, CurrentAction action,
const Pokedex& pokedex);
void clearCurrentAction(Simulation& simulation);
} // namespace pokesim
Loading