Exemplo n.º 1
0
void AI::CastleRemove(const Castle & castle)
{
    AIKingdom & ai = AIKingdoms::Get(castle.GetColor());

    if(ai.capital == &castle)
    {
        ai.capital->ResetModes(Castle::CAPITAL);
        ai.capital = NULL;
    }
}
Exemplo n.º 2
0
Battle::Tower::Tower(const Castle & castle, int twr) : Unit(Troop(Monster::ARCHER, 0), -1, false),
    type(twr), color(castle.GetColor()), bonus(0), valid(true)
{
    count += castle.CountBuildings();
    count += castle.GetLevelMageGuild() - 1;

    if(count > 20) count = 20;
    if(TWR_CENTER != type) count /= 2;
    if(count == 0) count = 1;
    bonus = castle.GetLevelMageGuild();

    SetModes(CAP_TOWER);
}
Exemplo n.º 3
0
u16 HowManyRecruitMonster(const Castle & castle, u32 dw, const Funds & add, Funds & res)
{
    const Monster ms(castle.GetRace(), castle.GetActualDwelling(dw));
    const Kingdom & kingdom = world.GetKingdom(castle.GetColor());

    if(! castle.GetArmy().CanJoinTroop(ms)) return 0;
                                                                                                                         
    u16 count = castle.GetDwellingLivedCount(dw);
    payment_t payment;

    while(count)
    {
        payment = ms.GetCost() * count;
        res = payment;
        payment += add;
        if(kingdom.AllowPayment(payment)) break;
        --count;
    }

    return count;
}
Exemplo n.º 4
0
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);
	}
    }
}
Exemplo n.º 5
0
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();
}