Peoplemon  0.1.0
Peoplemon 3 game source documentation
BattleWrapperState.cpp
Go to the documentation of this file.
2 
4 #include "Battle/WildIntro.hpp"
5 
6 #include <BLIB/Util/Random.hpp>
7 #include <Core/Properties.hpp>
8 #include <Core/Resources.hpp>
11 #include <array>
12 
13 namespace game
14 {
15 namespace state
16 {
17 bl::engine::State::Ptr BattleWrapperState::create(core::system::Systems& systems,
18  std::unique_ptr<core::battle::Battle>&& battle) {
19  std::unique_ptr<intros::SequenceBase> seq;
20  if (battle->type == core::battle::Battle::Type::WildPeoplemon) {
21  seq = std::make_unique<intros::WildSequence>();
22  }
23  else { seq = std::make_unique<intros::TrainerSequence>(); }
24  return Ptr{new BattleWrapperState(
25  systems, std::forward<std::unique_ptr<core::battle::Battle>>(battle), std::move(seq))};
26 }
27 
28 BattleWrapperState::BattleWrapperState(core::system::Systems& systems,
29  std::unique_ptr<core::battle::Battle>&& battle,
30  std::unique_ptr<intros::SequenceBase>&& sequence)
31 : State(systems, bl::engine::StateMask::Menu)
32 , state(Substate::BattleIntro)
33 , battle(std::forward<std::unique_ptr<core::battle::Battle>>(battle))
34 , sequence(std::forward<std::unique_ptr<intros::SequenceBase>>(sequence))
35 , evolveIndex(0) {}
36 
37 const char* BattleWrapperState::name() const { return "BattleWrapperState"; }
38 
39 void BattleWrapperState::activate(bl::engine::Engine& engine) {
40  engine.inputSystem().getActor().addListener(*this);
41 
42  switch (state) {
43  case Substate::Battling:
45  state = Substate::Evolving;
46  evolveIndex = 0;
47  incEvolveIndex();
48  startEvolve();
49  }
50  else { engine.popState(); }
51  break;
52  case Substate::Evolving:
54  incEvolveIndex();
55  startEvolve();
56  }
57  else { engine.popState(); }
58  break;
59  case Substate::BattleIntro:
60  default:
61  sequence->start(systems.engine());
62  break;
63  }
64 }
65 
66 void BattleWrapperState::deactivate(bl::engine::Engine& engine) {
67  engine.inputSystem().getActor().removeListener(*this);
68 }
69 
70 void BattleWrapperState::update(bl::engine::Engine& engine, float dt, float) {
71  sequence->update(dt);
72  if (sequence->finished()) {
73  state = Substate::Battling;
74  engine.pushState(BattleState::create(systems, std::move(battle)));
75  }
76 }
77 
78 bool BattleWrapperState::observe(const bl::input::Actor&, unsigned int, bl::input::DispatchType,
79  bool) {
80  return true;
81 }
82 
83 void BattleWrapperState::incEvolveIndex() {
84  const auto& team = systems.player().state().peoplemon;
85  while (evolveIndex < team.size() && !team[evolveIndex].pendingEvolution()) { ++evolveIndex; }
86 }
87 
88 void BattleWrapperState::startEvolve() {
89  auto& ppl = systems.player().state().peoplemon[evolveIndex];
90  ppl.pendingEvolution() = false;
91  systems.engine().pushState(Evolution::create(systems, ppl));
92 }
93 
94 } // namespace state
95 } // namespace game
Core classes and functionality for both the editor and game.
Parent namespace for all functionality unique to the game.
std::vector< pplmn::OwnedPeoplemon > peoplemon
Definition: State.hpp:46
bool evolutionPending() const
Returns whether or not any peoplemon have a pending evolution.
Definition: State.cpp:20
player::State & state()
Returns the state of the player.
Definition: Player.cpp:154
Owns all primary systems and a reference to the engine.
Definition: Systems.hpp:47
const bl::engine::Engine & engine() const
Const accessor for the Engine.
Definition: Systems.cpp:35
Player & player()
Returns the player system.
Definition: Systems.cpp:59
static bl::engine::State::Ptr create(core::system::Systems &systems, std::unique_ptr< core::battle::Battle > &&battle)
Creates a new BattleState.
Definition: BattleState.cpp:34
Wrapper state that manages battle intro transitions as well as post-battle evolutions.
const char * name() const override
Returns "BattleWrapperState".
virtual void activate(bl::engine::Engine &engine) override
Initiates the battle transition or evolution if applicable, otherwise pops this state.
static bl::engine::State::Ptr create(core::system::Systems &systems, std::unique_ptr< core::battle::Battle > &&battle)
Creates a new BattleState.
virtual void deactivate(bl::engine::Engine &engine) override
Does nothing.
virtual void update(bl::engine::Engine &engine, float dt, float) override
Updates the intro sequence.
static bl::engine::State::Ptr create(core::system::Systems &systems, core::pplmn::OwnedPeoplemon &ppl)
Definition: Evolution.cpp:68
Parent to all game states. Provides some commonly required data like core game systems.
Definition: State.hpp:29
core::system::Systems & systems
Definition: State.hpp:66