Peoplemon  0.1.0
Peoplemon 3 game source documentation
AIController.cpp
Go to the documentation of this file.
2 
3 #include <BLIB/Util/Random.hpp>
6 
7 namespace core
8 {
9 namespace battle
10 {
12 : _name(pplmn::Peoplemon::name(wildId)) {}
13 
14 AIController::AIController(const std::string& tn, const std::vector<item::Id>& items)
15 : _name(tn)
16 , items(items) {}
17 
18 const std::string& AIController::name() const { return _name; }
19 
21 
22 void AIController::startChooseAction() {
23  // TODO - battle ai
24  int i = 0;
25  do {
26  i = bl::util::Random::get<int>(0, 3);
28  chooseMove(i);
29 }
30 
31 void AIController::startChoosePeoplemon(bool, bool reviveOnly) {
32  // TODO - battle ai
33  for (unsigned int i = 0; i < owner->peoplemon().size(); ++i) {
34  if (owner->peoplemon()[i].base().currentHp() > 0 && !reviveOnly) {
35  choosePeoplemon(i);
36  return;
37  }
38  else if (owner->peoplemon()[i].base().currentHp() == 0 && reviveOnly) {
39  choosePeoplemon(i);
40  return;
41  }
42  }
43  choosePeoplemon(0);
44 }
45 
46 void AIController::startChooseToContinue() { chooseGiveUp(false); }
47 
49  for (auto it = items.begin(); it != items.end(); ++it) {
50  if (*it == item) {
51  items.erase(it);
52  return true;
53  }
54  }
55  return false;
56 }
57 
58 bool AIController::isHost() const { return false; }
59 
60 } // namespace battle
61 } // namespace core
Id
Represents an item in its simplist form.
Definition: Id.hpp:24
Id
The id of a peoplemon.
Definition: Id.hpp:16
Core classes and functionality for both the editor and game.
core::pplmn::BattlePeoplemon & activePeoplemon()
Returns the peoplemon that is currently out.
Definition: Battler.cpp:59
std::vector< core::pplmn::BattlePeoplemon > & peoplemon()
Returns all the peoplemon held by this battler.
Definition: Battler.cpp:57
AIController(pplmn::Id wildId)
Construct a new AIController for a wild peoplemon.
virtual void refresh() override
Does nothing.
virtual const std::string & name() const override
Returns the name of the battler.
virtual bool removeItem(item::Id item) override
Removes the item from the battler's inventory.
virtual bool isHost() const override
Returns false.
void chooseGiveUp(bool yes)
Choose whether to give up or not.
void chooseMove(int move)
Selects the move to use this turn when fighting.
void choosePeoplemon(std::uint8_t i)
Selects the peoplemon to switch to.
OwnedPeoplemon & base()
Returns the wrapped peoplemon.
MoveId id
The id of the move.
Definition: OwnedMove.hpp:19
const OwnedMove * knownMoves() const
Returns the moves known by this Peoplemon.