s16 Battle::AIAreaSpellDst(const HeroBase & hero) { std::map<s16, u8> dstcount; Arena* arena = GetArena(); Units enemies(arena->GetForce(hero.GetColor(), true), true); for(Units::const_iterator it1 = enemies.begin(); it1 != enemies.end(); ++it1) { const Indexes around = Board::GetAroundIndexes(**it1); for(Indexes::const_iterator it2 = around.begin(); it2 != around.end(); ++it2) dstcount[*it2] += 1; } // find max std::map<s16, u8>::const_iterator max = std::max_element(dstcount.begin(), dstcount.end(), MaxDstCount); return max != dstcount.end() ? (*max).first : -1; }
u8 Battle2::Arena::DialogBattleHero(const HeroBase & hero) const { Display & display = Display::Get(); Cursor & cursor = Cursor::Get(); LocalEvent & le = LocalEvent::Get(); Settings & conf = Settings::Get(); cursor.Hide(); cursor.SetThemes(Cursor::POINTER); const bool readonly = conf.MyColor() != hero.GetColor(); const Sprite & dialog = AGG::GetICN((conf.EvilInterface() ? ICN::VGENBKGE : ICN::VGENBKG), 0); Rect pos_rt; pos_rt.x = (display.w() - dialog.w()) / 2; pos_rt.y = (display.h() - dialog.h()) / 2; pos_rt.w = dialog.w(); pos_rt.h = dialog.h(); Background back(pos_rt); back.Save(); display.Blit(dialog, pos_rt.x, pos_rt.y); display.Blit(Portrait::Get(hero, Portrait::BIG), pos_rt.x + 27, pos_rt.y + 42); u8 col = (Color::GRAY == hero.GetColor() ? 1 : Color::GetIndex(hero.GetColor()) + 1); display.Blit(AGG::GetICN(ICN::VIEWGEN, col), pos_rt.x + 148, pos_rt.y + 36); Point tp(pos_rt); std::string str; Text text; text.Set(Font::SMALL); str = _("%{name} the %{race}"); String::Replace(str, "%{name}", hero.GetName()); String::Replace(str, "%{race}", Race::String(hero.GetRace())); text.Set(str); tp.x = pos_rt.x + (pos_rt.w - text.w()) / 2; tp.y += 10; text.Blit(tp); str = _("Attack") + std::string(": "); String::AddInt(str, hero.GetAttack()); text.Set(str); tp.x = pos_rt.x + 205 - text.w() / 2; tp.y = pos_rt.y + 40; text.Blit(tp); str = _("Defense") + std::string(": "); String::AddInt(str, hero.GetDefense()); text.Set(str); tp.x = pos_rt.x + 205 - text.w() / 2; tp.y = pos_rt.y + 51; text.Blit(tp); str = _("Spell Power") + std::string(": "); String::AddInt(str, hero.GetPower()); text.Set(str); tp.x = pos_rt.x + 205 - text.w() / 2; tp.y = pos_rt.y + 62; text.Blit(tp); str = _("Knowledge") + std::string(": "); String::AddInt(str, hero.GetKnowledge()); text.Set(str); tp.x = pos_rt.x + 205 - text.w() / 2; tp.y = pos_rt.y + 73; text.Blit(tp); str = _("Morale") + std::string(": ") + Morale::String(hero.GetMorale()); text.Set(str); tp.x = pos_rt.x + 205 - text.w() / 2; tp.y = pos_rt.y + 84; text.Blit(tp); str = _("Luck") + std::string(": ") + Luck::String(hero.GetLuck()); text.Set(str); tp.x = pos_rt.x + 205 - text.w() / 2; tp.y = pos_rt.y + 95; text.Blit(tp); str = _("Spell Points") + std::string(": "); String::AddInt(str, hero.GetSpellPoints()); str += "/"; String::AddInt(str, hero.GetMaxSpellPoints()); text.Set(str); tp.x = pos_rt.x + 205 - text.w() / 2; tp.y = pos_rt.y + 117; text.Blit(tp); Button btnCast(pos_rt.x + 30, pos_rt.y + 148, ICN::VIEWGEN, 9, 10); Button btnRetreat(pos_rt.x + 89, pos_rt.y + 148, ICN::VIEWGEN, 11, 12); Button btnSurrender(pos_rt.x + 148, pos_rt.y + 148, ICN::VIEWGEN, 13, 14); Button btnClose(pos_rt.x + 207, pos_rt.y + 148, ICN::VIEWGEN, 15, 16); btnCast.SetDisable(readonly || !hero.HaveSpellBook() || hero.Modes(Heroes::SPELLCASTED)); btnRetreat.SetDisable(readonly || !CanRetreatOpponent(hero.GetColor())); btnSurrender.SetDisable(readonly || !CanSurrenderOpponent(hero.GetColor())); btnCast.Draw(); btnRetreat.Draw(); btnSurrender.Draw(); btnClose.Draw(); if(!conf.QVGA()) { Surface shadow(btnCast.w, btnCast.h); shadow.Fill(0, 0, 0); shadow.SetAlpha(80); if(btnCast.isDisable()) display.Blit(shadow, btnCast); if(btnRetreat.isDisable()) display.Blit(shadow, btnRetreat); if(btnSurrender.isDisable()) display.Blit(shadow, btnSurrender); } u8 result = 0; cursor.Show(); display.Flip(); while(le.HandleEvents() && !result) { btnCast.isEnable() && le.MousePressLeft(btnCast) ? btnCast.PressDraw() : btnCast.ReleaseDraw(); btnRetreat.isEnable() && le.MousePressLeft(btnRetreat) ? btnRetreat.PressDraw() : btnRetreat.ReleaseDraw(); btnSurrender.isEnable() && le.MousePressLeft(btnSurrender) ? btnSurrender.PressDraw() : btnSurrender.ReleaseDraw(); le.MousePressLeft(btnClose) ? btnClose.PressDraw() : btnClose.ReleaseDraw(); if(le.KeyPress(KEY_c) || (btnCast.isEnable() && le.MouseClickLeft(btnCast))) result = 1; if(le.KeyPress(KEY_r) || (btnRetreat.isEnable() && le.MouseClickLeft(btnRetreat))) result = 2; if(le.KeyPress(KEY_s) || (btnSurrender.isEnable() && le.MouseClickLeft(btnSurrender))) result = 3; if(le.MousePressRight(btnCast)) Dialog::Message(_("Cast Spell"), _("Cast a magical spell. You may only cast one spell per combat round. The round is reset when every creature has had a turn"), Font::BIG); else if(le.MousePressRight(btnRetreat)) Dialog::Message(_("Retreat"), _("Retreat your hero, abandoning your creatures. Your hero will be available for you to recruit again, however, the hero will have only a novice hero's forces."), Font::BIG); else if(le.MousePressRight(btnSurrender)) Dialog::Message(_("Surrender"), _("Surrendering costs gold. However if you pay the ransom, the hero and all of his or her surviving creatures will be available to recruit again."), Font::BIG); else if(le.MousePressRight(btnClose)) Dialog::Message(_("Cancel"), _("Return to the battle."), Font::BIG); // exit if(le.KeyPress(KEY_ESCAPE) || le.KeyPress(KEY_RETURN) || le.MouseClickLeft(btnClose)) break; } cursor.Hide(); back.Restore(); cursor.Show(); display.Flip(); return result; }