+void MapState::LoadBattle(Entity &hero, Entity &monster) {
+ SDL_Surface *bg = map->BattleBackgroundAt(ToInt(monster.Position()));
+ BattleState *battleState(new BattleState(game, bg, monster.PartyLayout()));
+ for (int i(0); i < 4; ++i) {
+ if (game->state->party[i]) {
+ battleState->AddHero(*game->state->party[i]);
+ }
+ }
+ if (game->state->capsule) {
+ battleState->SetCapsule(&game->state->GetCapsule());
+ }
+ for (battle::Monster **m(monster.MonstersBegin()); m != monster.MonstersEnd(); ++m) {
+ battleState->AddMonster(**m);
+ }
+
+ // TODO: pass turn advantage to battle, see #26
+ Entity::Orientation faceDirection;
+ if (monster.Position().Y() < hero.Position().Y()) {
+ faceDirection = Entity::ORIENTATION_NORTH;
+ } else if (monster.Position().X() > hero.Position().X()) {
+ faceDirection = Entity::ORIENTATION_EAST;
+ } else if (monster.Position().Y() > hero.Position().Y()) {
+ faceDirection = Entity::ORIENTATION_SOUTH;
+ } else {
+ faceDirection = Entity::ORIENTATION_WEST;
+ }
+ if (hero.GetOrientation() == monster.GetOrientation()
+ && hero.GetOrientation() == faceDirection) {
+ // advantage hero
+ } else if (hero.GetOrientation() == monster.GetOrientation()
+ && hero.GetOrientation() == ((faceDirection + 2) % 4)) {
+ // advantage monster
+ } else if (((monster.GetOrientation() == faceDirection && (hero.GetOrientation() % 2) != (faceDirection % 2))
+ || (hero.GetOrientation() == faceDirection && (monster.GetOrientation() % 2) != (faceDirection % 2)))
+ && rand() % 2) {
+ // 50% advantage chance hero
+ } else if ((monster.GetOrientation() == (faceDirection + 2) % 4)
+ && ((hero.GetOrientation() % 2) != (faceDirection % 2))
+ && rand() % 2) {
+ // 50% advantage chance monster