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 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(); }
void AI::CastleTurn(Castle & castle) { // skip neutral town if(castle.GetColor() != Color::NONE) { s32 range = Game::GetViewDistance(castle.isCastle() ? Game::VIEW_CASTLE : Game::VIEW_TOWN); const Heroes* enemy = NULL; // find enemy hero for(s32 y = -range; y <= range; ++y) for(s32 x = -range; x <= range; ++x) { if(!y && !x) continue; const Point & center = castle.GetCenter(); if(Maps::isValidAbsPoint(center.x + x, center.y + y)) { const Maps::Tiles & tile = world.GetTiles(Maps::GetIndexFromAbsPoint(center.x + x, center.y + y)); if(MP2::OBJ_HEROES == tile.GetObject()) enemy = tile.GetHeroes(); if(enemy && castle.GetColor() == enemy->GetColor()) enemy = NULL; if(enemy) break; } } enemy ? AICastleDefense(castle) : AICastleDevelopment(castle); Kingdom & kingdom = castle.GetKingdom(); bool can_recruit = castle.isCastle() && kingdom.GetHeroes().size() < Kingdom::GetMaxHeroes(); // part II if(enemy && castle.GetArmy().isValid() && Army::TroopsStrongerEnemyTroops(castle.GetArmy(), enemy->GetArmy())) { if(!castle.GetHeroes().Guest() && can_recruit) { Recruits & rec = kingdom.GetRecruits(); if(rec.GetHero1()) castle.RecruitHero(rec.GetHero1()); else if(rec.GetHero2()) castle.RecruitHero(rec.GetHero2()); } if(castle.GetHeroes().Guest()) castle.GetHeroes().Guest()->SetModes(AI::HEROES_HUNTER); } // part III AIKingdom & ai = AIKingdoms::Get(castle.GetColor()); if(ai.capital != &castle && castle.GetArmy().isValid() && ! castle.GetHeroes().Guest() && 2 < castle.GetArmy().GetCount() && 150 < castle.GetArmy().GetHitPoints() && can_recruit) { Recruits & rec = kingdom.GetRecruits(); if(rec.GetHero1()) castle.RecruitHero(rec.GetHero1()); else if(rec.GetHero2()) castle.RecruitHero(rec.GetHero2()); if(castle.GetHeroes().Guest()) castle.GetHeroes().Guest()->SetModes(AI::HEROES_HUNTER|AI::HEROES_SCOUTER); } } }
void Dialog::QuickInfo(const Castle & castle) { Display & display = Display::Get(); Cursor & cursor = Cursor::Get(); cursor.Hide(); const ICN::icn_t qwiktown = ICN::QWIKTOWN; AGG::PreloadObject(qwiktown); // image box const Sprite &box = AGG::GetICN(qwiktown, 0); const Interface::GameArea & gamearea = Interface::GameArea::Get(); const Rect ar(BORDERWIDTH, BORDERWIDTH, gamearea.GetArea().w, gamearea.GetArea().h); LocalEvent & le = LocalEvent::Get(); const Point & mp = le.GetMouseCursor(); Rect cur_rt; u16 mx = (mp.x - BORDERWIDTH) / TILEWIDTH; mx *= TILEWIDTH; u16 my = (mp.y - BORDERWIDTH) / TILEWIDTH; my *= TILEWIDTH; // top left if(mx <= ar.x + ar.w / 2 && my <= ar.y + ar.h / 2) cur_rt = Rect(mx + TILEWIDTH, my + TILEWIDTH, box.w(), box.h()); else // top right if(mx > ar.x + ar.w / 2 && my <= ar.y + ar.h / 2) cur_rt = Rect(mx - box.w(), my + TILEWIDTH, box.w(), box.h()); else // bottom left if(mx <= ar.x + ar.w / 2 && my > ar.y + ar.h / 2) cur_rt = Rect(mx + TILEWIDTH, my - box.h(), box.w(), box.h()); else // bottom right cur_rt = Rect(mx - box.w(), my - box.h(), box.w(), box.h()); if(Settings::Get().QVGA()) { cur_rt = Rect((display.w() - box.w()) / 2, (display.h() - box.h()) / 2, box.w(), box.h()); } Background back(cur_rt); back.Save(); display.Blit(box, cur_rt.x, cur_rt.y); cur_rt = Rect(back.GetRect().x + 28 , back.GetRect().y + 12, 178, 140); Point dst_pt; Text text; // castle name text.Set(castle.GetName(), Font::SMALL); dst_pt.x = cur_rt.x + (cur_rt.w - text.w()) / 2; dst_pt.y = cur_rt.y + 5; text.Blit(dst_pt); u8 index = 0; switch(castle.GetRace()) { case Race::KNGT: index = (castle.isCastle() ? 9 : 15); break; case Race::BARB: index = (castle.isCastle() ? 10 : 16); break; case Race::SORC: index = (castle.isCastle() ? 11 : 17); break; case Race::WRLK: index = (castle.isCastle() ? 12 : 18); break; case Race::WZRD: index = (castle.isCastle() ? 13 : 19); break; case Race::NECR: index = (castle.isCastle() ? 14 : 20); break; default: DEBUG(DBG_GAME , DBG_WARN, "Dialog::QuickInfo: unknown race."); return; } // castle icon const Sprite & sprite = AGG::GetICN(ICN::LOCATORS, index); dst_pt.x = cur_rt.x + (cur_rt.w - sprite.w()) / 2; dst_pt.y += 18; display.Blit(sprite, dst_pt); // color flags switch(castle.GetColor()) { case Color::BLUE: index = 0; break; case Color::GREEN: index = 2; break; case Color::RED: index = 4; break; case Color::YELLOW: index = 6; break; case Color::ORANGE: index = 8; break; case Color::PURPLE: index = 10; break; case Color::GRAY: index = 12; break; } const Sprite & l_flag = AGG::GetICN(ICN::FLAG32, index); dst_pt.x = cur_rt.x + (cur_rt.w - 60) / 2 - l_flag.w(); display.Blit(l_flag, dst_pt); const Sprite & r_flag = AGG::GetICN(ICN::FLAG32, index + 1); dst_pt.x = cur_rt.x + (cur_rt.w + 60) / 2; display.Blit(r_flag, dst_pt); // info text.Set(_("Defenders:")); dst_pt.x = cur_rt.x + (cur_rt.w - text.w()) / 2; dst_pt.y += sprite.h() + 5; text.Blit(dst_pt); u8 count = castle.GetArmy().GetCount(); if(! count) { text.Set(_("None")); dst_pt.x = cur_rt.x + (cur_rt.w - text.w()) / 2; dst_pt.y += 45; text.Blit(dst_pt); } else castle.GetArmy().DrawMons32Line(cur_rt.x - 5, cur_rt.y + 100, 192, 0, 0, (Settings::Get().MyColor() != castle.GetColor())); cursor.Show(); display.Flip(); // quick info loop while(le.HandleEvents() && le.MousePressRight()); // restore background cursor.Hide(); back.Restore(); cursor.Show(); display.Flip(); }