void Kingdom::ApplyPlayWithStartingHero(void)
{
    if(isPlay() && castles.size())
    {
	// get first castle
	Castle* first = castles.GetFirstCastle();
	if(NULL == first) first = castles.front();

	// check manual set hero (castle position + point(0, 1))?
	const Point & cp = (first)->GetCenter();
	Heroes* hero = world.GetTiles(cp.x, cp.y + 1).GetHeroes();

    	// and move manual set hero to castle
	if(hero && hero->GetColor() == GetColor())
	{
		bool patrol = hero->Modes(Heroes::PATROL);
    		hero->SetFreeman(0);
    		hero->Recruit(*first);

		if(patrol)
		{
		    hero->SetModes(Heroes::PATROL);
		    hero->SetCenterPatrol(cp);
		}
	}
	else
	if(Settings::Get().GameStartWithHeroes())
	{
    	    Heroes* hero = world.GetFreemanHeroes(first->GetRace());
	    if(hero && AllowRecruitHero(false, 0)) hero->Recruit(*first);
	}
    }
}
void CastleRedrawBuilding(const Castle & castle, const Point & dst_pt, u32 build, u32 frame, int alpha)
{
    const Rect max = CastleGetMaxArea(castle, dst_pt);

    // correct build
    switch(build)
    {
	case DWELLING_MONSTER2:
	case DWELLING_MONSTER3:
	case DWELLING_MONSTER4:
	case DWELLING_MONSTER5:
	case DWELLING_MONSTER6: build = castle.GetActualDwelling(build); break;

	default: break;
    }

    const int icn = Castle::GetICNBuilding(build, castle.GetRace());
    u32 index = 0;

    // correct index (mage guild)
    switch(build)
    {
        case BUILD_MAGEGUILD1: index = 0; break;
        case BUILD_MAGEGUILD2: index = Race::NECR == castle.GetRace() ? 6 : 1; break;
        case BUILD_MAGEGUILD3: index = Race::NECR == castle.GetRace() ? 12 : 2; break;
        case BUILD_MAGEGUILD4: index = Race::NECR == castle.GetRace() ? 18 : 3; break;
        case BUILD_MAGEGUILD5: index = Race::NECR == castle.GetRace() ? 24 : 4; break;
        default: break;
    }

    if(icn != ICN::UNKNOWN)
    {
	// simple first sprite
	Sprite sprite1 = AGG::GetICN(icn, index);

	if(alpha)
	{
	    sprite1.SetSurface(sprite1.GetSurface());
	    sprite1.SetAlphaMod(alpha);
	    sprite1.Blit(dst_pt.x + sprite1.x(), dst_pt.y + sprite1.y());
	}
	else
	    CastleDialog::RedrawBuildingSpriteToArea(sprite1, dst_pt.x + sprite1.x(), dst_pt.y + sprite1.y(), max);

	// second anime sprite
	if(const u32 index2 = ICN::AnimationFrame(icn, index, frame))
	{
	    Sprite sprite2 = AGG::GetICN(icn, index2);

	    if(alpha)
	    {
		sprite2.SetSurface(sprite2.GetSurface());
		sprite2.SetAlphaMod(alpha);
		sprite2.Blit(dst_pt.x + sprite2.x(), dst_pt.y + sprite2.y());
	    }
	    else
	        CastleDialog::RedrawBuildingSpriteToArea(sprite2, dst_pt.x + sprite2.x(), dst_pt.y + sprite2.y(), max);
	}
    }
}
Battle2::Tower::Tower(const Castle & castle, u8 twr, Arena & a) : Army::Troop(Monster::ARCHER), arena(a), type(twr), 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;

    BattleInit();
    Stats* b = GetBattleStats();
    b->SetModes(CAP_TOWER);
}
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);
}
    void Init(Castle* ptr)
    {
	castle = ptr;

	Clear();

	armyBarGuard = new ArmyBar(& castle->GetArmy(), true, false);
	armyBarGuard->SetBackground(41, 41, 0x3C);
	armyBarGuard->SetColRows(5, 1);
	armyBarGuard->SetHSpace(-1);

	CastleHeroes heroes = world.GetHeroes(*castle);

        if(heroes.Guest())
	{
	    armyBarGuest = new ArmyBar(& heroes.Guest()->GetArmy(), true, false);
	    armyBarGuest->SetBackground(41, 41, 0x3C);
	    armyBarGuest->SetColRows(5, 1);
	    armyBarGuest->SetHSpace(-1);
	}

	dwellingsBar = new DwellingsBar(*castle, 39, 52, 0x3C);
	dwellingsBar->SetColRows(6, 1);
	dwellingsBar->SetHSpace(2);
    }
void AI::CastleRemove(const Castle & castle)
{
    AIKingdom & ai = AIKingdoms::Get(castle.GetColor());

    if(ai.capital == &castle)
    {
        ai.capital->ResetModes(Castle::CAPITAL);
        ai.capital = NULL;
    }
}
void CastleRedrawTownName(const Castle & castle, const Point & dst)
{
    const Sprite & ramka = AGG::GetICN(ICN::TOWNNAME, 0);
    Point dst_pt(dst.x + 320 - ramka.w() / 2, dst.y + 248);
    ramka.Blit(dst_pt);

    Text text(castle.GetName(), Font::SMALL);
    dst_pt.x = dst.x + 320 - text.w() / 2;
    dst_pt.y = dst.y + 248;
    text.Blit(dst_pt);
}
Exemple #8
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;
}
RowSpells::RowSpells(const Point & pos, const Castle & castle, u8 lvl)
{
    const MageGuild & guild = castle.GetMageGuild();
    bool hide = castle.GetLevelMageGuild() < lvl;
    const Sprite & roll_show = AGG::GetICN(ICN::TOWNWIND, 0);
    const Sprite & roll_hide = AGG::GetICN(ICN::TOWNWIND, 1);
    const Sprite & roll = (hide ? roll_hide : roll_show);

    u8 count = 0;

    switch(lvl)
    {
	case 1:
	case 2: count = 3; break;
	case 3:
	case 4: count = 2; break;
	case 5: count = 1; break;
	default: break;
    }

    for(u8 ii = 0; ii < count; ++ii)
	coords.push_back(Rect(pos.x + coords.size() * (Settings::Get().QVGA() ? 72 : 110) - roll.w() / 2, pos.y, roll.w(), roll.h()));

    if(castle.HaveLibraryCapability())
    {
	if(! hide && castle.isLibraryBuild())
	    coords.push_back(Rect(pos.x + coords.size() * (Settings::Get().QVGA() ? 72 : 110) - roll_show.w() / 2, pos.y, roll_show.w(), roll_show.h()));
	else
	    coords.push_back(Rect(pos.x + coords.size() * (Settings::Get().QVGA() ? 72 : 110) - roll_hide.w() / 2, pos.y, roll_hide.w(), roll_hide.h()));
    }

    spells.reserve(6);
    spells = guild.GetSpells(castle.GetLevelMageGuild(), castle.isLibraryBuild(), lvl);
    spells.resize(coords.size(), Spell::NONE);
}
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;
}
Exemple #11
0
GameApp::GameApp()
{	
	load_prefs();
	theSound.SetSoundCallback(this, &GameManager::SoundEnded);
	screen = new AppScreen();
	sample = theSound.LoadSample("Resources/Sounds/click.ogg", false /*no stream*/);
	theWorld.NameLayer("background", 0);
	theWorld.NameLayer("objects", 1);
	theWorld.NameLayer("units", 2);
	theWorld.LoadLevel("level");
	BoundingBox bounds(Vector2(-20, -20), Vector2(20, 20));
	theSpatialGraph.CreateGraph(0.6f, bounds);
	Castle* castle = (Castle*)Actor::GetNamed("Castle");
	castle_health = new TextActor("Console", "Castle health: " + IntToString(castle->getHealth()), TXT_Center);
	castle_health->SetPosition(Vector2(-4.5f, 4.5f));
	theWorld.Add(castle_health);
	castle_cash = new TextActor("Console", "Castle cash: " + IntToString(castle->getCash()), TXT_Center);
	castle_cash->SetPosition(Vector2(-4.5f, 3.5f));
	theWorld.Add(castle_cash);
	std::thread interval(&GameApp::timer, this);
	interval.detach();
	_button = theUI.AddButton("Change tactics", Vec2i(90, 700), ButtonPress, true);
}
CastleDialog::CacheBuildings::CacheBuildings(const Castle & castle, const Point & top)
{
    std::vector<building_t> ordersBuildings;

    ordersBuildings.reserve(25);

    CastlePackOrdersBuildings(castle, ordersBuildings);

    for(std::vector<building_t>::const_iterator
        it = ordersBuildings.begin(); it != ordersBuildings.end(); ++it)
    {
        push_back(builds_t(*it, CastleGetCoordBuilding(castle.GetRace(), *it, top)));
    }
}
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);
	}
    }
}
Rect CastleGetMaxArea(const Castle & castle, const Point & top)
{
    Rect res(top, 0, 0);
    Sprite townbkg;

    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;
    }

    if(townbkg.isValid())
    {
	res.w = townbkg.w();
	res.h = townbkg.h();
    }

    return res;
}
Exemple #15
0
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();
}
Exemple #16
0
void RunTest3(void)
{
    VERBOSE("Run Test3");

    ListFiles maps = GetMapsFiles(".mp2");
    if(maps.empty()) return;

    const std::string & amap = maps.front();
    Settings & conf = Settings::Get();

    Maps::FileInfo fi;
    if(!fi.ReadMP2(amap)) return;
    
    conf.SetCurrentFileInfo(fi);
    world.LoadMapMP2(amap);

    Heroes & hero1 = *world.GetHeroes(Heroes::SANDYSANDY);
    Heroes & hero2 = *world.GetHeroes(Heroes::BAX);

    Players & players = conf.GetPlayers();

    int mycolor = Color::GetFirst(players.GetColors(CONTROL_HUMAN));
    int aicolor = Color::GetFirst(players.GetColors((CONTROL_AI)));

    players.SetPlayerControl(mycolor, CONTROL_HUMAN);
    players.SetPlayerControl(aicolor, CONTROL_HUMAN);

    Kingdom & kingdom1 = world.GetKingdom(mycolor);
    Kingdom & kingdom2 = world.GetKingdom(aicolor);

    conf.SetCurrentColor(mycolor);
    conf.SetGameType(Game::TYPE_BATTLEONLY);

    players.SetStartGame();

    hero1.SetSpellPoints(150);

    int xx = world.w() / 2;
    int yy = world.h() / 2;

    if(kingdom1.GetCastles().size())
    hero1.Recruit(kingdom1.GetColor(), Point(xx, yy));
    hero2.Recruit(kingdom2.GetColor(), Point(xx, yy + 1));

    Army & army1 = hero1.GetArmy();

    Castle* castle = kingdom2.GetCastles().at(0);
    castle->ActionNewDay();
    castle->BuyBuilding(BUILD_MAGEGUILD1);
    castle->ActionNewDay();
    castle->BuyBuilding(BUILD_CAPTAIN);
    castle->ActionNewDay();
    castle->BuyBuilding(BUILD_MOAT);

    //Army army2;
    //Army & army2 = hero2.GetArmy();
    Army & army2 = castle->GetArmy();
    if(army2.GetCommander())
    {
	army2.GetCommander()->SpellBookActivate();
	army2.GetCommander()->AppendSpellToBook(Spell::SHIELD, true);
    }

    army1.Clean();
    //army1.JoinTroop(Monster::PHOENIX, 10);
    //army1.GetTroop(0)->Set(Monster::ARCHER, 30);
    army1.GetTroop(1)->Set(Monster::BOAR, 20);
    army1.GetTroop(2)->Set(Monster::OGRE_LORD, 20);

    //army1.JoinTroop(Monster::Rand(Monster::LEVEL1), 30);
    //army1.JoinTroop(Monster::Rand(Monster::LEVEL2), 20);
    //army1.JoinTroop(Monster::Rand(Monster::LEVEL3), 10);

    army2.Clean();
    army2.GetTroop(0)->Set(Monster::BOAR, 20);
    army2.GetTroop(2)->Set(Monster::OGRE_LORD, 20);
//    army2.at(0) = Troop(Monster::OGRE, 1);
//    army2.at(1) = Troop(Monster::DWARF, 2);
//    army2.at(2) = Troop(Monster::DWARF, 2);
//    army2.at(3) = Troop(Monster::DWARF, 2);
//    army2.at(4) = Troop(Monster::DWARF, 2);
//    army2.JoinTroop(static_cast<Monster::monster_t>(1), 10);
//    army2.JoinTroop(static_cast<Monster::monster_t>(4), 10);
//    army2.JoinTroop(static_cast<Monster::monster_t>(6), 10);
//    army2.JoinTroop(static_cast<Monster::monster_t>(8), 10);

    Battle::Loader(army1, army2, army1.GetCommander()->GetIndex());
}
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;
}
Exemple #18
0
Vector2 GameApp::getCastlePosition(){
	Castle* castle = castle = (Castle*)Actor::GetNamed("Castle");
	Vector2 aim = castle->GetPosition();
	aim.Y -= 1.43;
	return aim;
}
void CastlePackOrdersBuildings(const Castle & castle, std::vector<building_t> & ordersBuildings)
{
    ordersBuildings.reserve(30);

    switch(castle.GetRace())
    {
	case Race::KNGT:
	    ordersBuildings.push_back(BUILD_TENT);
	    ordersBuildings.push_back(BUILD_CASTLE);
	    ordersBuildings.push_back(BUILD_SPEC);
	    ordersBuildings.push_back(BUILD_WEL2);
	    ordersBuildings.push_back(BUILD_CAPTAIN);
	    ordersBuildings.push_back(BUILD_LEFTTURRET);
	    ordersBuildings.push_back(BUILD_RIGHTTURRET);
	    ordersBuildings.push_back(BUILD_MOAT);
	    ordersBuildings.push_back(BUILD_MARKETPLACE);
	    ordersBuildings.push_back(DWELLING_UPGRADE2);
	    ordersBuildings.push_back(DWELLING_MONSTER2);
	    ordersBuildings.push_back(BUILD_THIEVESGUILD);
	    ordersBuildings.push_back(BUILD_TAVERN);
	    ordersBuildings.push_back(BUILD_MAGEGUILD1);
	    ordersBuildings.push_back(BUILD_MAGEGUILD2);
	    ordersBuildings.push_back(BUILD_MAGEGUILD3);
	    ordersBuildings.push_back(BUILD_MAGEGUILD4);
	    ordersBuildings.push_back(BUILD_MAGEGUILD5);
	    ordersBuildings.push_back(DWELLING_UPGRADE5);
	    ordersBuildings.push_back(DWELLING_MONSTER5);
	    ordersBuildings.push_back(DWELLING_UPGRADE6);
	    ordersBuildings.push_back(DWELLING_MONSTER6);
	    ordersBuildings.push_back(DWELLING_MONSTER1);
	    ordersBuildings.push_back(DWELLING_UPGRADE3);
	    ordersBuildings.push_back(DWELLING_MONSTER3);
	    ordersBuildings.push_back(DWELLING_UPGRADE4);
	    ordersBuildings.push_back(DWELLING_MONSTER4);
	    ordersBuildings.push_back(BUILD_WELL);
	    ordersBuildings.push_back(BUILD_STATUE);
	    ordersBuildings.push_back(BUILD_SHIPYARD);
	    break;
	case Race::BARB:
	    ordersBuildings.push_back(BUILD_SPEC);
	    ordersBuildings.push_back(BUILD_WEL2);
	    ordersBuildings.push_back(DWELLING_MONSTER6);
	    ordersBuildings.push_back(BUILD_MAGEGUILD1);
	    ordersBuildings.push_back(BUILD_MAGEGUILD2);
	    ordersBuildings.push_back(BUILD_MAGEGUILD3);
	    ordersBuildings.push_back(BUILD_MAGEGUILD4);
	    ordersBuildings.push_back(BUILD_MAGEGUILD5);
	    ordersBuildings.push_back(BUILD_CAPTAIN);
	    ordersBuildings.push_back(BUILD_TENT);
	    ordersBuildings.push_back(BUILD_CASTLE);
	    ordersBuildings.push_back(BUILD_LEFTTURRET);
	    ordersBuildings.push_back(BUILD_RIGHTTURRET);
	    ordersBuildings.push_back(BUILD_MOAT);
	    ordersBuildings.push_back(DWELLING_MONSTER3);
	    ordersBuildings.push_back(BUILD_THIEVESGUILD);
	    ordersBuildings.push_back(BUILD_TAVERN);
	    ordersBuildings.push_back(DWELLING_MONSTER1);
	    ordersBuildings.push_back(BUILD_MARKETPLACE);
	    ordersBuildings.push_back(DWELLING_UPGRADE2);
	    ordersBuildings.push_back(DWELLING_MONSTER2);
	    ordersBuildings.push_back(DWELLING_UPGRADE4);
	    ordersBuildings.push_back(DWELLING_MONSTER4);
	    ordersBuildings.push_back(DWELLING_UPGRADE5);
	    ordersBuildings.push_back(DWELLING_MONSTER5);
	    ordersBuildings.push_back(BUILD_WELL);
	    ordersBuildings.push_back(BUILD_STATUE);
	    ordersBuildings.push_back(BUILD_SHIPYARD);
	    break;
	case Race::SORC:
	    ordersBuildings.push_back(BUILD_SPEC);
	    ordersBuildings.push_back(DWELLING_MONSTER6);
	    ordersBuildings.push_back(BUILD_MAGEGUILD1);
	    ordersBuildings.push_back(BUILD_MAGEGUILD2);
	    ordersBuildings.push_back(BUILD_MAGEGUILD3);
	    ordersBuildings.push_back(BUILD_MAGEGUILD4);
	    ordersBuildings.push_back(BUILD_MAGEGUILD5);
	    ordersBuildings.push_back(BUILD_CAPTAIN);
	    ordersBuildings.push_back(BUILD_TENT);
	    ordersBuildings.push_back(BUILD_CASTLE);
	    ordersBuildings.push_back(BUILD_LEFTTURRET);
	    ordersBuildings.push_back(BUILD_RIGHTTURRET);
	    ordersBuildings.push_back(BUILD_MOAT);
	    ordersBuildings.push_back(DWELLING_UPGRADE3);
	    ordersBuildings.push_back(DWELLING_MONSTER3);
	    ordersBuildings.push_back(BUILD_SHIPYARD);
	    ordersBuildings.push_back(BUILD_MARKETPLACE);
	    ordersBuildings.push_back(DWELLING_UPGRADE2);
	    ordersBuildings.push_back(DWELLING_MONSTER2);
	    ordersBuildings.push_back(BUILD_THIEVESGUILD);
	    ordersBuildings.push_back(DWELLING_MONSTER1);
	    ordersBuildings.push_back(BUILD_TAVERN);
	    ordersBuildings.push_back(BUILD_STATUE);
	    ordersBuildings.push_back(BUILD_WEL2);
	    ordersBuildings.push_back(DWELLING_UPGRADE4);
	    ordersBuildings.push_back(DWELLING_MONSTER4);
	    ordersBuildings.push_back(BUILD_WELL);
	    ordersBuildings.push_back(DWELLING_MONSTER5);
	    break;
	case Race::WRLK:
	    ordersBuildings.push_back(DWELLING_MONSTER5);
	    ordersBuildings.push_back(DWELLING_MONSTER3);
	    ordersBuildings.push_back(BUILD_TENT);
	    ordersBuildings.push_back(BUILD_CASTLE);
	    ordersBuildings.push_back(BUILD_LEFTTURRET);
	    ordersBuildings.push_back(BUILD_RIGHTTURRET);
	    ordersBuildings.push_back(BUILD_CAPTAIN);
	    ordersBuildings.push_back(BUILD_MOAT);
	    ordersBuildings.push_back(BUILD_SHIPYARD);
	    ordersBuildings.push_back(BUILD_MAGEGUILD1);
	    ordersBuildings.push_back(BUILD_MAGEGUILD2);
	    ordersBuildings.push_back(BUILD_MAGEGUILD3);
	    ordersBuildings.push_back(BUILD_MAGEGUILD4);
	    ordersBuildings.push_back(BUILD_MAGEGUILD5);
	    ordersBuildings.push_back(BUILD_TAVERN);
	    ordersBuildings.push_back(BUILD_THIEVESGUILD);
	    ordersBuildings.push_back(BUILD_MARKETPLACE);
	    ordersBuildings.push_back(BUILD_STATUE);
	    ordersBuildings.push_back(DWELLING_MONSTER1);
	    ordersBuildings.push_back(BUILD_WEL2);
	    ordersBuildings.push_back(BUILD_SPEC);
	    ordersBuildings.push_back(DWELLING_UPGRADE4);
	    ordersBuildings.push_back(DWELLING_MONSTER4);
	    ordersBuildings.push_back(DWELLING_MONSTER2);
	    ordersBuildings.push_back(DWELLING_UPGRADE7);
	    ordersBuildings.push_back(DWELLING_UPGRADE6);
	    ordersBuildings.push_back(DWELLING_MONSTER6);
	    ordersBuildings.push_back(BUILD_WELL);
	    break;
	case Race::WZRD:
	    ordersBuildings.push_back(DWELLING_UPGRADE6);
	    ordersBuildings.push_back(DWELLING_MONSTER6);
	    ordersBuildings.push_back(BUILD_TENT);
	    ordersBuildings.push_back(BUILD_CASTLE);
	    ordersBuildings.push_back(BUILD_LEFTTURRET);
	    ordersBuildings.push_back(BUILD_RIGHTTURRET);
	    ordersBuildings.push_back(BUILD_MOAT);
	    ordersBuildings.push_back(BUILD_CAPTAIN);
	    ordersBuildings.push_back(DWELLING_MONSTER2);
	    ordersBuildings.push_back(BUILD_THIEVESGUILD);
	    ordersBuildings.push_back(BUILD_TAVERN);
	    ordersBuildings.push_back(BUILD_SHIPYARD);
	    ordersBuildings.push_back(BUILD_WELL);
	    ordersBuildings.push_back(BUILD_SPEC);
	    ordersBuildings.push_back(DWELLING_UPGRADE3);
	    ordersBuildings.push_back(DWELLING_MONSTER3);
	    ordersBuildings.push_back(DWELLING_UPGRADE5);
	    ordersBuildings.push_back(DWELLING_MONSTER5);
	    ordersBuildings.push_back(BUILD_MAGEGUILD1);
	    ordersBuildings.push_back(BUILD_MAGEGUILD2);
	    ordersBuildings.push_back(BUILD_MAGEGUILD3);
	    ordersBuildings.push_back(BUILD_MAGEGUILD4);
	    ordersBuildings.push_back(BUILD_MAGEGUILD5);
	    ordersBuildings.push_back(BUILD_STATUE);
	    ordersBuildings.push_back(DWELLING_MONSTER1);
	    ordersBuildings.push_back(DWELLING_MONSTER4);
	    ordersBuildings.push_back(BUILD_MARKETPLACE);
	    ordersBuildings.push_back(BUILD_WEL2);
	    break;
	case Race::NECR:
	    ordersBuildings.push_back(BUILD_SPEC);
	    if(Settings::Get().PriceLoyaltyVersion())
		ordersBuildings.push_back(BUILD_SHRINE);
	    ordersBuildings.push_back(BUILD_TENT);
	    ordersBuildings.push_back(BUILD_CASTLE);
	    ordersBuildings.push_back(BUILD_CAPTAIN);
	    ordersBuildings.push_back(BUILD_LEFTTURRET);
	    ordersBuildings.push_back(BUILD_RIGHTTURRET);
	    ordersBuildings.push_back(DWELLING_MONSTER6);
	    ordersBuildings.push_back(BUILD_MOAT);
	    ordersBuildings.push_back(DWELLING_MONSTER1);
	    ordersBuildings.push_back(BUILD_THIEVESGUILD);
	    ordersBuildings.push_back(DWELLING_UPGRADE3);
	    ordersBuildings.push_back(DWELLING_MONSTER3);
	    ordersBuildings.push_back(DWELLING_UPGRADE5);
	    ordersBuildings.push_back(DWELLING_MONSTER5);
	    ordersBuildings.push_back(DWELLING_UPGRADE2);
	    ordersBuildings.push_back(DWELLING_MONSTER2);
	    ordersBuildings.push_back(DWELLING_UPGRADE4);
	    ordersBuildings.push_back(DWELLING_MONSTER4);
	    ordersBuildings.push_back(BUILD_MAGEGUILD1);
	    ordersBuildings.push_back(BUILD_MAGEGUILD2);
	    ordersBuildings.push_back(BUILD_MAGEGUILD3);
	    ordersBuildings.push_back(BUILD_MAGEGUILD4);
	    ordersBuildings.push_back(BUILD_MAGEGUILD5);
	    ordersBuildings.push_back(BUILD_SHIPYARD);
	    ordersBuildings.push_back(BUILD_WEL2);
	    ordersBuildings.push_back(BUILD_MARKETPLACE);
	    ordersBuildings.push_back(BUILD_STATUE);
	    ordersBuildings.push_back(BUILD_WELL);
	    break;
	default: break;
    }

    ordersBuildings.push_back(BUILD_NOTHING);
}
Exemple #20
0
Captain::Captain(Castle & cstl) : HeroBase(Skill::Primary::CAPTAIN, cstl.GetRace()), home(cstl)
{
    SetCenter(home.GetCenter());
}
void AI::HeroesPreBattle(HeroBase & hero)
{
    Castle* castle = world.GetCastle(hero.GetIndex());
    if(castle && hero.GetType() != Skill::Primary::CAPTAIN)
	hero.GetArmy().JoinTroops(castle->GetArmy());
}
Exemple #22
0
void AI::HeroesPreBattle(HeroBase & hero)
{
    Castle* castle = world.GetCastle(hero.GetCenter());
    if(castle && hero.GetType() != HeroBase::CAPTAIN)
	hero.GetArmy().JoinTroops(castle->GetArmy());
}
Exemple #23
0
void AI::CastlePreBattle(Castle & castle)
{
    Heroes* hero = castle.GetHeroes().GuardFirst();
    if(hero && castle.GetArmy().isValid())
	hero->GetArmy().JoinStrongestFromArmy(castle.GetArmy());
}
Exemple #24
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);
	}
    }
}
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();
}
Exemple #26
0
bool AI::HeroesGetTask(Heroes & hero)
{
    std::vector<s32> results;
    results.reserve(5);

    const Settings & conf = Settings::Get();
    AIHero & ai_hero = AIHeroes::Get(hero);
    AIKingdom & ai_kingdom = AIKingdoms::Get(hero.GetColor());

    Queue & task = ai_hero.sheduled_visit;
    IndexObjectMap & ai_objects = ai_kingdom.scans;

    const u8 objs1[] = { MP2::OBJ_ARTIFACT, MP2::OBJ_RESOURCE, MP2::OBJ_CAMPFIRE, MP2::OBJ_TREASURECHEST, 0 };
    const u8 objs2[] = { MP2::OBJ_SAWMILL, MP2::OBJ_MINES, MP2::OBJ_ALCHEMYLAB, 0 };
    const u8 objs3[] = { MP2::OBJ_CASTLE, MP2::OBJ_HEROES, MP2::OBJ_MONSTER, 0 };

    // rescan path
    hero.RescanPath();

    Castle* castle = hero.inCastle();
    // if hero in castle
    if(castle)
    {
	DEBUG(DBG_AI, DBG_TRACE, hero.GetName() << ", in castle");

	castle->RecruitAllMonster();
	hero.GetArmy().UpgradeTroops(*castle);

	// recruit army
	if(hero.Modes(AI::HEROES_HUNTER))
		hero.GetArmy().JoinStrongestFromArmy(castle->GetArmy());
	else
	if(hero.Modes(AI::HEROES_SCOUTER))
		hero.GetArmy().KeepOnlyWeakestTroops(castle->GetArmy());

	DEBUG(DBG_AI, DBG_TRACE, hero.GetName() << ", " << hero.GetArmy().String());
    }

    // patrol task
    if(hero.Modes(Heroes::PATROL))
    {
	DEBUG(DBG_AI, DBG_TRACE, hero.GetName() << ", is patrol mode");

	// goto patrol center
	if(hero.GetCenterPatrol() != hero.GetCenter() &&
	   hero.GetPath().Calculate(Maps::GetIndexFromAbsPoint(hero.GetCenterPatrol())))
		return true;

	// scan enemy hero
	if(hero.GetSquarePatrol())
	{
	    const Maps::Indexes & results = Maps::ScanAroundObject(Maps::GetIndexFromAbsPoint(hero.GetCenterPatrol()),
									hero.GetSquarePatrol(), MP2::OBJ_HEROES);
	    for(MapsIndexes::const_iterator
		it = results.begin(); it != results.end(); ++it)
	    {
		const Heroes* enemy = world.GetTiles(*it).GetHeroes();
		if(enemy && ! enemy->isFriends(hero.GetColor()))
		{
		    if(hero.GetPath().Calculate(enemy->GetIndex()))
		    {
			DEBUG(DBG_AI, DBG_TRACE, hero.GetName() << ", find enemy");
			return true;
		    }
		}
	    }
	}

	// can pickup objects
	if(conf.ExtHeroPatrolAllowPickup())
	{
	    const Maps::Indexes & results = Maps::ScanAroundObjects(hero.GetIndex(),
								    hero.GetSquarePatrol(), objs1);
	    for(MapsIndexes::const_iterator
		it = results.begin(); it != results.end(); ++it)
    		if(AI::HeroesValidObject(hero, *it) &&
		    hero.GetPath().Calculate(*it))
	    {
		ai_objects.erase(*it);

		DEBUG(DBG_AI, DBG_TRACE, hero.GetName() << ": find object: " <<
			MP2::StringObject(world.GetTiles(*it).GetObject()) << "(" << *it << ")");
		return true;
	    }
	}

	// random move
	/*
	// disable move: https://sourceforge.net/tracker/?func=detail&aid=3157397&group_id=96859&atid=616180
	{
	    Maps::ScanAroundObject(hero.GetIndex(), hero.GetSquarePatrol(), MP2::OBJ_ZERO);
	    if(results.size())
	    {
		std::random_shuffle(results.begin(), results.end());
		std::vector<s32>::const_iterator it = results.begin();
		for(; it != results.end(); ++it)
		    if(world.GetTiles(*it).isPassable(&hero, Direction::CENTER, true) &&
			hero.GetPath().Calculate(*it))
		{
		    DEBUG(DBG_AI, Color::String(hero.GetColor()) <<
			", Patrol " << hero.GetName() << ": move: " << *it);
		    return;
		}
	    }
	}
	*/

	hero.SetModes(AI::HEROES_STUPID);
	return false;
    }

    if(ai_hero.fix_loop > 3)
    {
	DEBUG(DBG_AI, DBG_TRACE, hero.GetName() << ": loop");
	hero.SetModes(hero.Modes(AI::HEROES_WAITING) ? AI::HEROES_STUPID : AI::HEROES_WAITING);
	return false;
    }

    // primary target
    if(Maps::isValidAbsIndex(ai_hero.primary_target))
    {
	if(hero.GetIndex() == ai_hero.primary_target)
	{
	    ai_hero.primary_target = -1;
	    hero.GetPath().Reset();
	    DEBUG(DBG_AI, DBG_TRACE, hero.GetName() << ", reset path");
	}
	else
	{
	    DEBUG(DBG_AI, DBG_TRACE, hero.GetName() << ", primary target: " <<
		    ai_hero.primary_target << ", " << MP2::StringObject(world.GetTiles(ai_hero.primary_target).GetObject()));

	    const Castle* castle = NULL;

	    if(NULL != (castle = world.GetCastle(Maps::GetPoint(ai_hero.primary_target))) &&
		NULL != castle->GetHeroes().Guest() && castle->isFriends(hero.GetColor()))
	    {
		hero.SetModes(AI::HEROES_WAITING);
		DEBUG(DBG_AI, DBG_TRACE, hero.GetName() << ", castle busy..");
	    }

	    // make path
	    if(ai_hero.primary_target != hero.GetPath().GetDestinationIndex() &&
		!hero.GetPath().Calculate(ai_hero.primary_target))
	    {
		DEBUG(DBG_AI, DBG_TRACE, hero.GetName() << ", path unknown, primary target reset");
		ai_hero.primary_target = -1;
	    }
	}

	if(hero.GetPath().isValid()) return true;
    }

    // scan heroes and castle
    const Maps::Indexes & enemies = Maps::ScanAroundObjects(hero.GetIndex(), hero.GetScoute(), objs3);

    for(MapsIndexes::const_iterator
	it = enemies.begin(); it != enemies.end(); ++it)
	if(AIHeroesPriorityObject(hero, *it) &&
		hero.GetPath().Calculate(*it))
    {
	DEBUG(DBG_AI, DBG_TRACE, hero.GetName() << ", set primary target: " <<
	MP2::StringObject(world.GetTiles(*it).GetObject()) << "(" << *it << ")");

	ai_hero.primary_target = *it;
	return true;
    }

    // check destination
    if(hero.GetPath().isValid())
    {
	if(! AI::HeroesValidObject(hero, hero.GetPath().GetDestinationIndex()))
	    hero.GetPath().Reset();
	else
	if(hero.GetPath().size() < 5)
	{
	    DEBUG(DBG_AI, DBG_TRACE, hero.GetName() << ", continue short");
	    ai_hero.fix_loop++;
	    return true;
	}
    }

    // scan 2x2 pickup objects
    Maps::Indexes pickups = Maps::ScanAroundObjects(hero.GetIndex(), 2, objs1);
    // scan 3x3 capture objects
    const Maps::Indexes & captures = Maps::ScanAroundObjects(hero.GetIndex(), 3, objs2);
    if(captures.size()) pickups.insert(pickups.end(), captures.begin(), captures.end());

    if(pickups.size())
    {
	hero.GetPath().Reset();

	for(MapsIndexes::const_iterator
	    it = pickups.begin(); it != pickups.end(); ++it)
    	    if(AI::HeroesValidObject(hero, *it))
	{
	    task.push_front(*it);

	    DEBUG(DBG_AI, DBG_TRACE, hero.GetName() << ", find object: " <<
		MP2::StringObject(world.GetTiles(*it).GetObject()) << "(" << *it << ")");
	}
    }

    if(hero.GetPath().isValid())
    {
	DEBUG(DBG_AI, DBG_TRACE, hero.GetName() << ", continue");
        ai_hero.fix_loop++;
	return true;
    }

    if(task.empty())
    {
	// get task from kingdom
	DEBUG(DBG_AI, DBG_TRACE, hero.GetName() << ", empty task");
	AIHeroesAddedTask(hero);
    }
    else
    // remove invalid task
	task.remove_if(std::not1(std::bind1st(std::ptr_fun(&AIHeroesValidObject2), &hero)));

    // random shuffle
    if(1 < task.size() && Rand::Get(1))
    {
	Queue::iterator it1, it2;
	it2 = it1 = task.begin();
	++it2;

    	std::swap(*it1, *it2);
    }

    // find passable index
    while(task.size())
    {
	const s32 & index = task.front();

	DEBUG(DBG_AI, DBG_TRACE, hero.GetName() << ", look for: " << MP2::StringObject(world.GetTiles(index).GetObject()) << "(" << index << ")");
	if(hero.GetPath().Calculate(index)) break;

	DEBUG(DBG_AI, DBG_TRACE, hero.GetName() << " say: unable get object: " << index << ", remove task...");
	task.pop_front();
    }

    // success
    if(task.size())
    {
	const s32 & index = task.front();
	DEBUG(DBG_AI, DBG_TRACE, hero.GetName() << " go to: " << index);

	ai_objects.erase(index);
	task.pop_front();

	DEBUG(DBG_AI, DBG_TRACE, hero.GetName() << ", route: " << hero.GetPath().String());
	return true;
    }
    else
    if(hero.Modes(AI::HEROES_WAITING))
    {
	hero.GetPath().Reset();
	DEBUG(DBG_AI, DBG_TRACE, hero.GetName() << " say: unknown task., help my please..");

	hero.ResetModes(AI::HEROES_WAITING);
	hero.SetModes(AI::HEROES_STUPID);
    }
    else
    {
	DEBUG(DBG_AI, DBG_TRACE, hero.GetName() << " say: waiting...");
	hero.SetModes(AI::HEROES_WAITING);
    }

    return false;
}
Exemple #27
0
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();
}
DwellingItem::DwellingItem(Castle & castle, u32 dw)
{
    type = castle.GetActualDwelling(dw);
    mons = Monster(castle.GetRace(), type);
}
Exemple #29
0
int WINAPI WinMain (HINSTANCE hThisInstance,
                    HINSTANCE hPrevInstance,
                    LPSTR lpszArgument,
                    int nFunsterStil)

{
    HWND hwnd;               /* This is the handle for our window */
    MSG messages;            /* Here messages to the application are saved */
    WNDCLASSEX wincl;        /* Data structure for the windowclass */


    /* The Window structure */
    wincl.hInstance = hThisInstance;
    wincl.lpszClassName = szClassName;
    wincl.lpfnWndProc = WindowProcedure;      /* This function is called by windows */
    wincl.style = CS_DBLCLKS;                 /* Catch double-clicks */
    wincl.cbSize = sizeof (WNDCLASSEX);

    /* Use default icon and mouse-pointer */
    wincl.hIcon = LoadIcon (NULL, IDI_APPLICATION);
    wincl.hIconSm = LoadIcon (NULL, IDI_APPLICATION);
    wincl.hCursor = LoadCursor (NULL, IDC_ARROW);
    wincl.lpszMenuName = NULL;                 /* No menu */
    wincl.cbClsExtra = 0;                      /* No extra bytes after the window class */
    wincl.cbWndExtra = 0;                      /* structure or the window instance */
    /* Use Windows's default color as the background of the window */
    wincl.hbrBackground = (HBRUSH) COLOR_BACKGROUND;

    /* Register the window class, and if it fails quit the program */
    if (!RegisterClassEx (&wincl))
        return 0;

    /* The class is registered, let's create the program*/
    hwnd = CreateWindowEx (
           0,                   /* Extended possibilites for variation */
           szClassName,         /* Classname */
           "Castle Defense",       /* Title Text */
           WS_OVERLAPPEDWINDOW, /* default window */
           CW_USEDEFAULT,       /* Windows decides the position */
           CW_USEDEFAULT,       /* where the window ends up on the screen */
           812,                 /* The programs width */
           730,                 /* and height in pixels */
           HWND_DESKTOP,        /* The window is a child-window to desktop */
           NULL,                /* No menu */
           hThisInstance,       /* Program Instance handler */
           NULL                 /* No Window Creation data */
           );

    /* Make the window visible on the screen */
    ShowWindow (hwnd, nFunsterStil);

    hdc = GetDC(hwnd); //Sakti    
    kuashitam = CreateSolidBrush(RGB(0,0,0));
    kuasputih = CreateSolidBrush(RGB(255,255,255));
    kuashijau = CreateSolidBrush(RGB(0,255,0));
    kuasmerah = CreateSolidBrush(RGB(255,0,0));
    canvasbmp = CreateCompatibleBitmap(hdc,800,700);
    canvasdc = CreateCompatibleDC(hdc);
    SelectObject(canvasdc, canvasbmp);

    /* Run the message loop. It will run until GetMessage() returns 0 */
    while (selesai==0)
    {
        if (PeekMessage (&messages, NULL, 0, 0, PM_REMOVE)) {  
            if (messages.message == WM_QUIT) {
                selesai=1;
            } else {
                TranslateMessage(&messages);
                DispatchMessage(&messages);
            
            };
        } else {
            //Coding saya 
            //clrscr dulu donk
            //kasih kuas hitam ke hdc 
            apaajasebelumnya=SelectObject(canvasdc, kuashitam);
            Rectangle(canvasdc,0,0,800,700);
            //balikin kuas sebelumnya 
            SelectObject(canvasdc, apaajasebelumnya);
            //end of clrscr dulu donk

            
            
            //Gambar semuanya di sini
            backGround = LoadBitmap(hThisInstance,MAKEINTRESOURCE(123));
            HDC bg;
            bg = CreateCompatibleDC(canvasdc);
            SelectObject(bg,backGround);
            BitBlt(canvasdc,0,0,800,640,bg,0,0,SRCCOPY);
            ctl.gambar(canvasdc);
            for(int i=0;i<MAXEN;i++) EN[i].gambar(canvasdc,hThisInstance);
            //for(int i=0;i<MAXARR;i++) ARR[i].gambar(canvasdc);
            //for(int i=0;i<MAXARCH;i++) arch[i].gambar(canvasdc);
            for(int i=0;i<MAXDEF;i++) def[i].gambar(canvasdc,hThisInstance);
            
            sprintf(hehehe,"Score = %d", ctl.score);
            TextOut(canvasdc,0,640,hehehe,strlen(hehehe));

            sprintf(hohoho,"Gold = %d", ctl.gold);
            TextOut(canvasdc,0,660,hohoho,strlen(hohoho));
            
            apaajasebelumnya=SelectObject(canvasdc, kuasmerah);
            Rectangle(canvasdc, 0, 680, 10+(800), 680+10);
            SelectObject(canvasdc, apaajasebelumnya);
            apaajasebelumnya=SelectObject(canvasdc, kuashijau);
            Rectangle(canvasdc, 0, 680, 10+((ctl.life/10)*8), 680+10);
            SelectObject(canvasdc, apaajasebelumnya);

            
            //Copy ke layar donk
            BitBlt(hdc,0,0,800,700,canvasdc,0,0,SRCCOPY);
            //TransparentBlt(hdc,0,0,800,700,canvasdc,0,0, 800,700, RGB(255,255,255) );

            //Perfom AI
            for(int i=0;i<MAXEN;i++) EN[i].gerak();
            //for(int i=0;i<MAXARR;i++) ARR[i].gerak();
            //for(int i=0;i<MAXARCH;i++) arch[i].Stance();
            //arrowAttack();
	        castleAttacked();
            defenderAttack();

            _sleep(33);
        }
    }

    DeleteDC(canvasdc);
    DeleteObject(canvasbmp);
    DeleteObject(kuashitam);
    DeleteObject(kuashijau);
    DeleteObject(kuasmerah);
    ReleaseDC(hwnd, hdc);

    /* The program return-value is 0 - The value that PostQuitMessage() gave */
    return messages.wParam;
}
Exemple #30
-1
void GameApp::ReceiveMessage(Message* message)
{
	if (message->GetMessageName() == "MouseDown")
    {
    	Castle* castle = (Castle*)Actor::GetNamed("Castle");
    	TypedMessage<Vec2i> *m = (TypedMessage<Vec2i>*)message;
        Vec2i screenCoordinates = m->GetValue();
        Vector2 click = MathUtil::ScreenToWorld(screenCoordinates);
        if(tower != 3){
	        ActorSet background = theTagList.GetObjectsTagged("grass");
			ActorSet::iterator it = background.begin();
	        while(it != background.end()){
	        	Vector2 position = (*it)->GetPosition();
	        	Vector2 size = (*it)->GetSize();
	        	if ((click.X < position.X + size.X/2.0) && (click.X > position.X - size.X/2.0) && (click.Y < position.Y + size.Y/2.0) && (click.Y > position.Y - size.Y/2.0)){
	        		if(!(castle->buy_tower(tower))) return;
	        		if(tower == 1){
	        			StandartTower* new_tower = (StandartTower*)Actor::Create("standart_tower");
	        			new_tower->SetPosition(click);
	        			theWorld.Add(new_tower, 2);
	        		}
	        		if(tower == 2){
	        			MagicTower* new_tower = (MagicTower*)Actor::Create("magic_tower");
	        			new_tower->SetPosition(click);
	        			theWorld.Add(new_tower, 2);
	        		}
	        		break;
	        	}
	        	it++;
	        }
	    }
	    else{
	    	ActorSet background = theTagList.GetObjectsTagged("road");
			ActorSet::iterator it = background.begin();
	        while(it != background.end()){
	        	Vector2 position = (*it)->GetPosition();
	        	Vector2 size = (*it)->GetSize();
	        	if ((click.X < position.X + size.X/2.0) && (click.X > position.X - size.X/2.0) && (click.Y < position.Y + size.Y/2.0) && (click.Y > position.Y - size.Y/2.0)){
	        		if(!(castle->buy_tower(tower))) return;
	        		Trap* new_trap = (Trap*)Actor::Create("trap");
	        		new_trap->SetPosition(click);
	        		theWorld.Add(new_trap, 1);
	        		break;
	        	}
	        	it++;
	        }
	    }
        theSwitchboard.UnsubscribeFrom(this, "MouseDown");
    }
}