Peoplemon  0.1.0
Peoplemon 3 game source documentation
Battle.cpp
Go to the documentation of this file.
2 
6 
7 namespace core
8 {
9 namespace battle
10 {
11 namespace
12 {
13 BattleState::Stage typeToStage(Battle::Type type) {
14 #ifdef PEOPLEMON_DEBUG
15  const bool skip = debug::DebugOverrides::get().skipBattles;
16 #else
17  const bool skip = false;
18 #endif
19 
20  switch (type) {
27  default:
28  BL_LOG_ERROR << "Unknown battle type: " << type;
29  return BattleState::Stage::IntroSendInSelf; // try to recover
30  }
31 }
32 } // namespace
33 
34 Battle::Battle(bl::engine::Engine& engine, const std::string& location, system::Player& player,
35  Type type)
36 : location(location)
37 , player(player)
38 , type(type)
39 , state(typeToStage(type))
40 , view(engine, state, type == Type::WildPeoplemon) {}
41 
42 std::unique_ptr<Battle> Battle::create(bl::engine::Engine& engine, const std::string& location,
43  system::Player& player, Type type) {
44  std::unique_ptr<Battle> b(new Battle(engine, location, player, type));
45 
46  std::vector<pplmn::BattlePeoplemon> team;
47  team.reserve(player.state().peoplemon.size());
48  for (auto& ppl : player.state().peoplemon) { team.emplace_back(&ppl); }
49  b->state.localPlayer().init(std::move(team),
50  std::make_unique<PlayerController>(player, b->view.menu()));
51 
52  return b;
53 }
54 
55 void Battle::setController(std::unique_ptr<BattleController>&& c) {
56  controller.swap(c);
57  controller->init(*this, view, state);
58 }
59 
60 } // namespace battle
61 } // namespace core
Type
The type classification of an item. This is used to determine when an item may be used and how to use...
Definition: Type.hpp:17
Core classes and functionality for both the editor and game.
Convenience struct that owns all the components required for a battle and resolves some boilerplate s...
Definition: Battle.hpp:23
Type
Represents the different types of battles. Affects only the intro.
Definition: Battle.hpp:25
Stage
Represents all possible states in a battle.
Definition: BattleState.hpp:24
std::vector< pplmn::OwnedPeoplemon > peoplemon
Definition: State.hpp:46
Primary system for managing the player and their data.
Definition: Player.hpp:35
player::State & state()
Returns the state of the player.
Definition: Player.cpp:154