CBattleResultWindow::CBattleResultWindow(const BattleResult &br, const SDL_Rect & pos, CBattleInterface * _owner) : owner(_owner) { OBJ_CONSTRUCTION_CAPTURING_ALL; this->pos = pos; CPicture * bg = new CPicture("CPRESULT"); bg->colorize(owner->curInt->playerID); exit = new CAdventureMapButton ("", "", boost::bind(&CBattleResultWindow::bExitf,this), 384, 505, "iok6432.def", SDLK_RETURN); exit->borderColor = Colors::METALLIC_GOLD; exit->borderEnabled = true; if(br.winner==0) //attacker won { new CLabel( 59, 124, FONT_SMALL, CENTER, Colors::WHITE, CGI->generaltexth->allTexts[410]); new CLabel(408, 124, FONT_SMALL, CENTER, Colors::WHITE, CGI->generaltexth->allTexts[411]); } else //if(br.winner==1) { new CLabel( 59, 124, FONT_SMALL, CENTER, Colors::WHITE, CGI->generaltexth->allTexts[411]); new CLabel(412, 124, FONT_SMALL, CENTER, Colors::WHITE, CGI->generaltexth->allTexts[410]); } new CLabel(232, 302, FONT_BIG, CENTER, Colors::YELLOW, CGI->generaltexth->allTexts[407]); new CLabel(232, 332, FONT_SMALL, CENTER, Colors::WHITE, CGI->generaltexth->allTexts[408]); new CLabel(232, 428, FONT_SMALL, CENTER, Colors::WHITE, CGI->generaltexth->allTexts[409]); std::string attackerName, defenderName; if(owner->attackingHeroInstance) //a hero attacked { new CAnimImage("PortraitsLarge", owner->attackingHeroInstance->portrait, 0, 21, 38); //setting attackerName attackerName = owner->attackingHeroInstance->name; } else //a monster attacked { int bestMonsterID = -1; ui32 bestPower = 0; for(TSlots::const_iterator it = owner->army1->Slots().begin(); it!=owner->army1->Slots().end(); ++it) { if(it->second->type->AIValue > bestPower) { bestPower = it->second->type->AIValue; bestMonsterID = it->second->type->idNumber; } } new CAnimImage("TWCRPORT", bestMonsterID+2, 0, 21, 38); //setting attackerName attackerName = CGI->creh->creatures[bestMonsterID]->namePl; } if(owner->defendingHeroInstance) //a hero defended { new CAnimImage("PortraitsLarge", owner->defendingHeroInstance->portrait, 0, 392, 38); //setting defenderName defenderName = owner->defendingHeroInstance->name; } else //a monster defended { int bestMonsterID = -1; ui32 bestPower = 0; for(TSlots::const_iterator it = owner->army2->Slots().begin(); it!=owner->army2->Slots().end(); ++it) { if( it->second->type->AIValue > bestPower) { bestPower = it->second->type->AIValue; bestMonsterID = it->second->type->idNumber; } } new CAnimImage("TWCRPORT", CGI->creh->creatures[bestMonsterID]->iconIndex, 0, 392, 38); //setting defenderName defenderName = CGI->creh->creatures[bestMonsterID]->namePl; } //printing attacker and defender's names new CLabel( 89, 37, FONT_SMALL, TOPLEFT, Colors::WHITE, attackerName); new CLabel( 381, 53, FONT_SMALL, BOTTOMRIGHT, Colors::WHITE, defenderName); //printing casualities for(int step = 0; step < 2; ++step) { if(br.casualties[step].size()==0) { new CLabel( 235, 360 + 97*step, FONT_SMALL, CENTER, Colors::WHITE, CGI->generaltexth->allTexts[523]); } else { int xPos = 235 - (br.casualties[step].size()*32 + (br.casualties[step].size() - 1)*10)/2; //increment by 42 with each picture int yPos = 344 + step*97; for(std::map<ui32,si32>::const_iterator it=br.casualties[step].begin(); it!=br.casualties[step].end(); ++it) { new CAnimImage("CPRSMALL", CGI->creh->creatures[it->first]->iconIndex, 0, xPos, yPos); std::ostringstream amount; amount<<it->second; new CLabel( xPos+16, yPos + 42, FONT_SMALL, CENTER, Colors::WHITE, amount.str()); xPos += 42; } } } //printing result description bool weAreAttacker = (owner->curInt->playerID == owner->attackingHeroInstance->tempOwner); if((br.winner == 0 && weAreAttacker) || (br.winner == 1 && !weAreAttacker)) //we've won { int text=-1; switch(br.result) { case BattleResult::NORMAL: text = 304; break; case BattleResult::ESCAPE: text = 303; break; case BattleResult::SURRENDER: text = 302; break; } CCS->musich->playMusic("Music/Win Battle", false); CCS->videoh->open("WIN3.BIK"); std::string str = CGI->generaltexth->allTexts[text]; const CGHeroInstance * ourHero = weAreAttacker? owner->attackingHeroInstance : owner->defendingHeroInstance; if (ourHero) { str += CGI->generaltexth->allTexts[305]; boost::algorithm::replace_first(str,"%s",ourHero->name); boost::algorithm::replace_first(str,"%d",boost::lexical_cast<std::string>(br.exp[weAreAttacker?0:1])); } new CTextBox(str, Rect(69, 203, 330, 68), 0, FONT_SMALL, CENTER, Colors::WHITE); } else // we lose { switch(br.result) { case BattleResult::NORMAL: { CCS->musich->playMusic("Music/LoseCombat", false); CCS->videoh->open("LBSTART.BIK"); new CLabel(235, 235, FONT_SMALL, CENTER, Colors::WHITE, CGI->generaltexth->allTexts[311]); break; } case BattleResult::ESCAPE: //flee { CCS->musich->playMusic("Music/Retreat Battle", false); CCS->videoh->open("RTSTART.BIK"); new CLabel(235, 235, FONT_SMALL, CENTER, Colors::WHITE, CGI->generaltexth->allTexts[310]); break; } case BattleResult::SURRENDER: { CCS->musich->playMusic("Music/Surrender Battle", false); CCS->videoh->open("SURRENDER.BIK"); new CLabel(235, 235, FONT_SMALL, CENTER, Colors::WHITE, CGI->generaltexth->allTexts[309]); break; } } } }
CBattleResultWindow::CBattleResultWindow(const BattleResult &br, const SDL_Rect & pos, CPlayerInterface &_owner) : owner(_owner) { OBJ_CONSTRUCTION_CAPTURING_ALL; this->pos = pos; CPicture * bg = new CPicture("CPRESULT"); bg->colorize(owner.playerID); exit = new CButton (Point(384, 505), "iok6432.def", std::make_pair("", ""), [&]{ bExitf();}, SDLK_RETURN); exit->borderColor = Colors::METALLIC_GOLD; if(br.winner==0) //attacker won { new CLabel( 59, 124, FONT_SMALL, CENTER, Colors::WHITE, CGI->generaltexth->allTexts[410]); new CLabel(408, 124, FONT_SMALL, CENTER, Colors::WHITE, CGI->generaltexth->allTexts[411]); } else //if(br.winner==1) { new CLabel( 59, 124, FONT_SMALL, CENTER, Colors::WHITE, CGI->generaltexth->allTexts[411]); new CLabel(412, 124, FONT_SMALL, CENTER, Colors::WHITE, CGI->generaltexth->allTexts[410]); } new CLabel(232, 302, FONT_BIG, CENTER, Colors::YELLOW, CGI->generaltexth->allTexts[407]); new CLabel(232, 332, FONT_SMALL, CENTER, Colors::WHITE, CGI->generaltexth->allTexts[408]); new CLabel(232, 428, FONT_SMALL, CENTER, Colors::WHITE, CGI->generaltexth->allTexts[409]); std::string sideNames[2] = {"N/A", "N/A"}; for(int i = 0; i < 2; i++) { auto heroInfo = owner.cb->battleGetHeroInfo(i); const int xs[] = {21, 392}; if(heroInfo.portrait >= 0) //attacking hero { new CAnimImage("PortraitsLarge", heroInfo.portrait, 0, xs[i], 38); sideNames[i] = heroInfo.name; } else { auto stacks = owner.cb->battleGetAllStacks(); vstd::erase_if(stacks, [i](const CStack *stack) //erase stack of other side and not coming from garrison { return stack->attackerOwned == i || !stack->base; }); auto best = vstd::maxElementByFun(stacks, [](const CStack *stack){ return stack->type->AIValue; }); if(best != stacks.end()) //should be always but to be safe... { new CAnimImage("TWCRPORT", (*best)->type->idNumber+2, 0, xs[i], 38); sideNames[i] = CGI->creh->creatures[(*best)->type->idNumber]->namePl; } } } //printing attacker and defender's names new CLabel( 89, 37, FONT_SMALL, TOPLEFT, Colors::WHITE, sideNames[0]); new CLabel( 381, 53, FONT_SMALL, BOTTOMRIGHT, Colors::WHITE, sideNames[1]); //printing casualties for(int step = 0; step < 2; ++step) { if(br.casualties[step].size()==0) { new CLabel( 235, 360 + 97*step, FONT_SMALL, CENTER, Colors::WHITE, CGI->generaltexth->allTexts[523]); } else { int xPos = 235 - (br.casualties[step].size()*32 + (br.casualties[step].size() - 1)*10)/2; //increment by 42 with each picture int yPos = 344 + step*97; for(auto & elem : br.casualties[step]) { new CAnimImage("CPRSMALL", CGI->creh->creatures[elem.first]->iconIndex, 0, xPos, yPos); std::ostringstream amount; amount<<elem.second; new CLabel( xPos+16, yPos + 42, FONT_SMALL, CENTER, Colors::WHITE, amount.str()); xPos += 42; } } } //printing result description bool weAreAttacker = !(owner.cb->battleGetMySide()); if((br.winner == 0 && weAreAttacker) || (br.winner == 1 && !weAreAttacker)) //we've won { int text=-1; switch(br.result) { case BattleResult::NORMAL: text = 304; break; case BattleResult::ESCAPE: text = 303; break; case BattleResult::SURRENDER: text = 302; break; } CCS->musich->playMusic("Music/Win Battle", false); CCS->videoh->open("WIN3.BIK"); std::string str = CGI->generaltexth->allTexts[text]; const CGHeroInstance * ourHero = owner.cb->battleGetMyHero(); if (ourHero) { str += CGI->generaltexth->allTexts[305]; boost::algorithm::replace_first(str,"%s",ourHero->name); boost::algorithm::replace_first(str,"%d",boost::lexical_cast<std::string>(br.exp[weAreAttacker?0:1])); } new CTextBox(str, Rect(69, 203, 330, 68), 0, FONT_SMALL, CENTER, Colors::WHITE); } else // we lose { switch(br.result) { case BattleResult::NORMAL: { CCS->musich->playMusic("Music/LoseCombat", false); CCS->videoh->open("LBSTART.BIK"); new CLabel(235, 235, FONT_SMALL, CENTER, Colors::WHITE, CGI->generaltexth->allTexts[311]); break; } case BattleResult::ESCAPE: //flee { CCS->musich->playMusic("Music/Retreat Battle", false); CCS->videoh->open("RTSTART.BIK"); new CLabel(235, 235, FONT_SMALL, CENTER, Colors::WHITE, CGI->generaltexth->allTexts[310]); break; } case BattleResult::SURRENDER: { CCS->musich->playMusic("Music/Surrender Battle", false); CCS->videoh->open("SURRENDER.BIK"); new CLabel(235, 235, FONT_SMALL, CENTER, Colors::WHITE, CGI->generaltexth->allTexts[309]); break; } } } }