std::string Battle::Tower::GetInfo(const Castle & cstl) { const char* tmpl = _("The %{name} fires with the strength of %{count} Archers"); const char* addn = _("each with a +%{attack} bonus to their attack skill."); std::vector<int> towers; std::string msg; if(cstl.isBuild(BUILD_CASTLE)) { towers.push_back(TWR_CENTER); if(cstl.isBuild(BUILD_LEFTTURRET)) towers.push_back(TWR_LEFT); if(cstl.isBuild(BUILD_RIGHTTURRET)) towers.push_back(TWR_RIGHT); for(std::vector<int>::const_iterator it = towers.begin(); it != towers.end(); ++it) { Tower twr = Tower(cstl, *it); msg.append(tmpl); StringReplace(msg, "%{name}", twr.GetName()); StringReplace(msg, "%{count}", twr.GetCount()); if(twr.GetBonus()) { msg.append(", "); msg.append(addn); StringReplace(msg, "%{attack}", twr.GetBonus()); } else msg.append("."); if((it + 1) != towers.end()) msg.append("\n \n"); } } return msg; }
void CastleRedrawBuildingExtended(const Castle & castle, const Point & dst_pt, u32 build, u32 frame) { const Rect max = CastleGetMaxArea(castle, dst_pt); int icn = Castle::GetICNBuilding(build, castle.GetRace()); // shipyard if(BUILD_SHIPYARD == build) { // boat if(castle.PresentBoat()) { const int icn2 = castle.GetICNBoat(castle.GetRace()); const Sprite & sprite40 = AGG::GetICN(icn2, 0); CastleDialog::RedrawBuildingSpriteToArea(sprite40, dst_pt.x + sprite40.x(), dst_pt.y + sprite40.y(), max); if(const u32 index2 = ICN::AnimationFrame(icn2, 0, frame)) { const Sprite & sprite41 = AGG::GetICN(icn2, index2); CastleDialog::RedrawBuildingSpriteToArea(sprite41, dst_pt.x + sprite41.x(), dst_pt.y + sprite41.y(), max); } } else { if(const u32 index2 = ICN::AnimationFrame(icn, 0, frame)) { const Sprite & sprite3 = AGG::GetICN(icn, index2); CastleDialog::RedrawBuildingSpriteToArea(sprite3, dst_pt.x + sprite3.x(), dst_pt.y + sprite3.y(), max); } } } else // sorc and anime wel2 or statue if(Race::SORC == castle.GetRace() && BUILD_WEL2 == build) { const int icn2 = castle.isBuild(BUILD_STATUE) ? ICN::TWNSEXT1 : icn; const Sprite & sprite20 = AGG::GetICN(icn2, 0); CastleDialog::RedrawBuildingSpriteToArea(sprite20, dst_pt.x + sprite20.x(), dst_pt.y + sprite20.y(), max); if(const u32 index2 = ICN::AnimationFrame(icn2, 0, frame)) { const Sprite & sprite21 = AGG::GetICN(icn2, index2); CastleDialog::RedrawBuildingSpriteToArea(sprite21, dst_pt.x + sprite21.x(), dst_pt.y + sprite21.y(), max); } } }
void AICastleDefense(Castle & c) { if(c.isCastle()) { if(!c.isBuild(BUILD_LEFTTURRET)) c.BuyBuilding(BUILD_LEFTTURRET); if(!c.isBuild(BUILD_RIGHTTURRET)) c.BuyBuilding(BUILD_RIGHTTURRET); if(!c.isBuild(BUILD_MOAT)) c.BuyBuilding(BUILD_MOAT); if(!c.isBuild(BUILD_CAPTAIN) && NULL == c.GetHeroes().Guest()) c.BuyBuilding(BUILD_CAPTAIN); if(!c.isBuild(BUILD_TAVERN) && Race::KNGT == c.GetRace()) c.BuyBuilding(BUILD_TAVERN); if(!c.isBuild(BUILD_SPEC)) c.BuyBuilding(BUILD_SPEC); } c.RecruitAllMonster(); }
void CastleRedrawCurrentBuilding(const Castle & castle, const Point & dst_pt, const CastleDialog::CacheBuildings & orders, u32 build, u32 flash) { u32 & frame = Game::CastleAnimationFrame(); Display & display = Display::Get(); Cursor & cursor = Cursor::Get(); Sprite townbkg; // before redraw switch(castle.GetRace()) { case Race::KNGT: townbkg = AGG::GetICN(ICN::TOWNBKG0, 0); break; case Race::BARB: townbkg = AGG::GetICN(ICN::TOWNBKG1, 0); break; case Race::SORC: townbkg = AGG::GetICN(ICN::TOWNBKG2, 0); break; case Race::WRLK: townbkg = AGG::GetICN(ICN::TOWNBKG3, 0); break; case Race::WZRD: townbkg = AGG::GetICN(ICN::TOWNBKG4, 0); break; case Race::NECR: townbkg = AGG::GetICN(ICN::TOWNBKG5, 0); break; default: break; } const Rect max = CastleGetMaxArea(castle, dst_pt); if(townbkg.isValid()) townbkg.Blit(dst_pt.x, dst_pt.y); if(Race::BARB == castle.GetRace()) { const Sprite & sprite0 = AGG::GetICN(ICN::TWNBEXT1, 1 + frame % 5); sprite0.Blit(dst_pt.x + sprite0.x(), dst_pt.y + sprite0.y()); } // sea anime if(Race::WZRD == castle.GetRace() || (!castle.isBuild(BUILD_SHIPYARD) && castle.HaveNearlySea())) { Sprite sprite50, sprite51; switch(castle.GetRace()) { case Race::KNGT: sprite50 = AGG::GetICN(ICN::TWNKEXT0, 0); sprite51 = AGG::GetICN(ICN::TWNKEXT0, 1 + frame % 5); break; case Race::BARB: sprite50 = AGG::GetICN(ICN::TWNBEXT0, 0); sprite51 = AGG::GetICN(ICN::TWNBEXT0, 1 + frame % 5); break; case Race::SORC: sprite50 = AGG::GetICN(ICN::TWNSEXT0, 0); sprite51 = AGG::GetICN(ICN::TWNSEXT0, 1 + frame % 5); break; case Race::NECR: sprite50 = AGG::GetICN(ICN::TWNNEXT0, 0); sprite51 = AGG::GetICN(ICN::TWNNEXT0, 1 + frame % 5); break; case Race::WRLK: sprite50 = AGG::GetICN(ICN::TWNWEXT0, 0); sprite51 = AGG::GetICN(ICN::TWNWEXT0, 1 + frame % 5); break; case Race::WZRD: sprite50 = AGG::GetICN(ICN::TWNZEXT0, 0); sprite51 = AGG::GetICN(ICN::TWNZEXT0, 1 + frame % 5); break; default: break; } if(sprite50.isValid()) CastleDialog::RedrawBuildingSpriteToArea(sprite50, dst_pt.x + sprite50.x(), dst_pt.y + sprite50.y(), max); if(sprite51.isValid()) CastleDialog::RedrawBuildingSpriteToArea(sprite51, dst_pt.x + sprite51.x(), dst_pt.y + sprite51.y(), max); } // redraw all builds if(BUILD_NOTHING == build) { for(CastleDialog::CacheBuildings::const_iterator it = orders.begin(); it != orders.end(); ++it) { if(castle.isBuild((*it).id)) { CastleRedrawBuilding(castle, dst_pt, (*it).id, frame, 0); if(flash == (*it).id) { CastleDialog::RedrawBuildingSpriteToArea((*it).contour, dst_pt.x + (*it).contour.x(), dst_pt.y + (*it).contour.y(), max); } CastleRedrawBuildingExtended(castle, dst_pt, (*it).id, frame); } } } // redraw build with alpha else if(orders.end() != std::find(orders.begin(), orders.end(), build)) { LocalEvent & le = LocalEvent::Get(); int alpha = 1; while(le.HandleEvents() && alpha < 250) { if(Game::AnimateInfrequentDelay(Game::CASTLE_BUILD_DELAY)) { cursor.Hide(); for(CastleDialog::CacheBuildings::const_iterator it = orders.begin(); it != orders.end(); ++it) { const u32 & build2 = (*it).id; if(castle.isBuild(build2)) { CastleRedrawBuilding(castle, dst_pt, build2, frame, 0); CastleRedrawBuildingExtended(castle, dst_pt, build2, frame); } else if(build2 == build) { CastleRedrawBuilding(castle, dst_pt, build2, frame, alpha); CastleRedrawTownName(castle, dst_pt); alpha += 10; } } CastleRedrawTownName(castle, dst_pt); cursor.Show(); display.Flip(); } ++frame; } cursor.Hide(); } ++frame; }
void AICastleDevelopment(Castle & c) { const Kingdom & kingdom = c.GetKingdom(); if(c.isCastle()) { // build for capital or large golds if(c.isCapital() || kingdom.GetFunds().Get(Resource::GOLD) > 8000) { if(!c.isBuild(BUILD_STATUE)) c.BuyBuilding(BUILD_STATUE); if(!c.isBuild(BUILD_SPEC) && Race::WRLK == c.GetRace()) c.BuyBuilding(BUILD_SPEC); if(!c.isBuild(BUILD_TAVERN) && Race::KNGT == c.GetRace()) c.BuyBuilding(BUILD_TAVERN); if(!c.isBuild(BUILD_MAGEGUILD1) && ((Race::SORC | Race::WZRD | Race::WRLK | Race::NECR) & c.GetRace())) c.BuyBuilding(BUILD_MAGEGUILD1); if(!c.isBuild(BUILD_WELL)) c.BuyBuilding(BUILD_WELL); if(!c.isBuild(DWELLING_MONSTER1)) c.BuyBuilding(DWELLING_MONSTER1); if(!c.isBuild(DWELLING_MONSTER2)) c.BuyBuilding(DWELLING_MONSTER2); if(!c.isBuild(DWELLING_MONSTER3)) c.BuyBuilding(DWELLING_MONSTER3); if(!c.isBuild(DWELLING_MONSTER4)) c.BuyBuilding(DWELLING_MONSTER4); if(!c.isBuild(BUILD_THIEVESGUILD) && ((Race::NECR) & c.GetRace())) c.BuyBuilding(BUILD_THIEVESGUILD); if(!c.isBuild(BUILD_MARKETPLACE)) c.BuyBuilding(BUILD_MARKETPLACE); if(!c.isBuild(BUILD_MAGEGUILD1)) c.BuyBuilding(BUILD_MAGEGUILD1); if(!c.isBuild(BUILD_MAGEGUILD2) && ((Race::SORC | Race::WZRD | Race::WRLK | Race::NECR) & c.GetRace())) c.BuyBuilding(BUILD_MAGEGUILD2); if(!c.isBuild(DWELLING_UPGRADE2)) c.BuyBuilding(DWELLING_UPGRADE2); if(!c.isBuild(DWELLING_UPGRADE3)) c.BuyBuilding(DWELLING_UPGRADE3); if(!c.isBuild(DWELLING_UPGRADE4)) c.BuyBuilding(DWELLING_UPGRADE4); if(!c.isBuild(BUILD_LEFTTURRET)) c.BuyBuilding(BUILD_LEFTTURRET); if(!c.isBuild(BUILD_RIGHTTURRET)) c.BuyBuilding(BUILD_RIGHTTURRET); if(!c.isBuild(BUILD_MOAT)) c.BuyBuilding(BUILD_MOAT); if(!c.isBuild(BUILD_CAPTAIN)) c.BuyBuilding(BUILD_CAPTAIN); if(!c.isBuild(BUILD_MAGEGUILD2)) c.BuyBuilding(BUILD_MAGEGUILD2); if(!c.isBuild(DWELLING_MONSTER5)) c.BuyBuilding(DWELLING_MONSTER5); if(!c.isBuild(DWELLING_MONSTER6)) c.BuyBuilding(DWELLING_MONSTER6); if(!c.isBuild(BUILD_MAGEGUILD3)) c.BuyBuilding(BUILD_MAGEGUILD3); if(!c.isBuild(DWELLING_UPGRADE5)) c.BuyBuilding(DWELLING_UPGRADE5); if(!c.isBuild(DWELLING_UPGRADE6)) c.BuyBuilding(DWELLING_UPGRADE6); } } else { // build castle only monday or tuesday or for capital if(c.isCapital() || 3 > world.GetDay()) c.BuyBuilding(BUILD_CASTLE); } // last day and buy monster if(world.LastDay()) c.RecruitAllMonster(); }