Battle::Battle(Hero &heroIn, int battleType, int monsterType)
{
    hero = &heroIn;
    timeCount = 0;

    switch (battleType)
    {
        case 0:
            monster = Monster(hero->getLevel(), monsterType);
            break;
        case 1:
            monster = Monster(hero->getLevel() + MED_MOD, monsterType);
            break;
        case 2:
            monster = Monster(hero->getLevel() + HARD_MOD, monsterType);
            break;
        default:
            monster = Monster(hero->getLevel(), monsterType);
            break;
    }

    //speed modulo(modulos?)(moduli?)(modulo?)(modulen?) to be used in turn allocation
    hMod = (1.0 / hero->getSpeed()) * (hero->getLevel() * 100);
    mMod = (1.0 / monster.getSpeed()) * (hero->getLevel() * 100);

}
void spawnMonster(){
	bool type = true;
	bool dir = true;
	if(rand()%3 == 0)type = false;
	if(rand()%2 == 0)dir = false;
	
	int startFrame = 32;
	if(type)startFrame = 16;
	
	int i = 0;
	
	if(enemies.size() < MAX_ENEMIES){
		enemies.push_back(Monster(116,0,type));
		i = enemies.size()-1;
	}else{
		for(int k = 0; k < MAX_ENEMIES; k++){
			if(enemies.at(k).isDead()){
				enemies[k] = Monster(116,0,type);
				i = k;
				break;
			}
		}
	}
	
	SetObject(i+3,
			ATTR0_SHAPE(0) | ATTR0_8BPP | ATTR0_REG | ATTR0_Y(enemies.at(i).getY()),
			ATTR1_SIZE(!type) | ATTR1_X(enemies.at(i).getX()),
			ATTR2_ID8(startFrame));
			
	enemies.at(i).setDir(dir);
}
Monster Dialog::SelectMonster(u8 id)
{
    Display & display = Display::Get();
    Cursor & cursor = Cursor::Get();
    LocalEvent & le = LocalEvent::Get();

    std::vector<int> monsters(static_cast<int>(Monster::WATER_ELEMENT), Monster::UNKNOWN);

    cursor.Hide();
    cursor.SetThemes(cursor.POINTER);


    for(size_t ii = 0; ii < monsters.size(); ++ii) monsters[ii] = ii + 1; // skip Monser::UNKNOWN

    const u16 window_w = 260;
    const u16 window_h = 280;

    Dialog::FrameBorder frameborder;
    frameborder.SetPosition((display.w() - window_w) / 2 - BORDERWIDTH,
			    (display.h() - window_h) / 2 - BORDERWIDTH, window_w, window_h);
    frameborder.Redraw(AGG::GetICN(ICN::TEXTBAK2, 0));

    const Rect & area = frameborder.GetArea();

    SelectEnumMonster listbox(area);

    listbox.SetListContent(monsters);
    if(id != Monster::UNKNOWN)
	listbox.SetCurrent(static_cast<int>(id));
    listbox.Redraw();

    ButtonGroups btnGroups(area, Dialog::OK|Dialog::CANCEL);
    btnGroups.Draw();

    cursor.Show();
    display.Flip();

    u16 result = Dialog::ZERO;

    while(result == Dialog::ZERO && ! listbox.ok && le.HandleEvents())
    {
        result = btnGroups.QueueEventProcessing();
        listbox.QueueEventProcessing();

        if(!cursor.isVisible())
        {
            listbox.Redraw();
            cursor.Show();
            display.Flip();
        }
    }

    return result == Dialog::OK || listbox.ok ?
	Monster(listbox.GetCurrent()) : Monster(Monster::UNKNOWN);
}
void StatsCastlesList::RedrawItem(const CASTLEPTR & cstl, s16 dstx, s16 dsty, bool current)
{
    if(cstl)
    {
	Text text("", Font::SMALL);
	const Sprite & back = AGG::GetICN(ICN::OVERVIEW, 11);
	back.Blit(dstx, dsty);

	// base info
	Interface::RedrawCastleIcon(*cstl, dstx + 17, dsty + 19);

	const Heroes* hero = cstl->GetHeroes().GuardFirst();

	if(hero)
	    Interface::RedrawHeroesIcon(*hero, dstx + 82, dsty + 19);

	text.Set(cstl->GetName());
	text.Blit(dstx + 72 - text.w() / 2, dsty + 62);

	// army info
	Army::DrawMons32Line(cstl->GetArmy(), dstx + 155, dsty + 30, 180);

	// available
	Troops troops;
	const u32 dwellings[] = { DWELLING_MONSTER1, DWELLING_MONSTER2, DWELLING_MONSTER3, DWELLING_MONSTER4, DWELLING_MONSTER5, DWELLING_MONSTER6 };

	for(u8 ii = 0; ii < ARRAY_COUNT(dwellings); ++ii)
	{
    	    u16 count = cstl->GetDwellingLivedCount(dwellings[ii]);
    	    if(count) troops.PushBack(Monster(cstl->GetRace(), cstl->GetActualDwelling(dwellings[ii])), count);
	}

	Army::DrawMons32Line(troops, dstx + 360, dsty + 30, 220);
    }
}
bool ActionSpellSetGuardian(Heroes & hero, const Spell & spell, u8 id)
{
    Maps::Tiles & tile = world.GetTiles(hero.GetIndex());

    if(MP2::OBJ_MINES != tile.GetObject(false))
    {
        Dialog::Message("", _("You must be standing on the entrance to a mine (sawmills and alchemists don't count) to cast this spell."), Font::BIG, Dialog::OK);
        return false;
    }

    const u16 count = hero.GetPower() * spell.ExtraValue();

    if(count)
    {
        Maps::TilesAddon* addon = tile.FindObject(MP2::OBJ_MINES);

        if(addon)
            addon->tmp = spell();

        if(spell == Spell::HAUNT)
        {
            world.CaptureObject(tile.GetIndex(), Color::UNUSED);
            tile.SetObject(MP2::OBJ_ABANDONEDMINE);
        }

        Army::Troop troop = world.GetCapturedObject(tile.GetIndex()).GetTroop();
        troop.Set(Monster(spell), count);
    }

    return false;
}
BuildingInfo::BuildingInfo(const Castle & c, building_t b) : castle(c), building(b), area(0, 0, 135, 57), bcond(ALLOW_BUILD)
{
    if(IsDwelling()) building = castle.GetActualDwelling(b);

    building = castle.isBuild(b) ? castle.GetUpgradeBuilding(b) : b;

    if(BUILD_TAVERN == building && Race::NECR == castle.GetRace())
	building = Settings::Get().PriceLoyaltyVersion() ? BUILD_SHRINE : BUILD_TAVERN;

    bcond = castle.CheckBuyBuilding(building);

    // generate description
    if(BUILD_DISABLE == bcond)
	description = GetConditionDescription();
    else
    if(IsDwelling())
    {
	description = _("The %{building} produces %{monster}.");
        StringReplace(description, "%{building}", Castle::GetStringBuilding(building, castle.GetRace()));
        StringReplace(description, "%{monster}", StringLower(Monster(castle.GetRace(), building).GetMultiName()));
    }
    else
    	description = Castle::GetDescriptionBuilding(building, castle.GetRace());

    switch(building)
    {
	case BUILD_WELL:
    	    StringReplace(description, "%{count}", Castle::GetGrownWell());
	    break;

	case BUILD_WEL2:
    	    StringReplace(description, "%{count}", Castle::GetGrownWel2());
	    break;

	case BUILD_CASTLE:
	case BUILD_STATUE:
	case BUILD_SPEC:
	{
	    const payment_t profit = ProfitConditions::FromBuilding(building, castle.GetRace());
	    StringReplace(description, "%{count}", profit.gold);
	    break;
	}

	default: break;
    }

    // fix area for capratin
    if(b == BUILD_CAPTAIN)
    {
	const Sprite & sprite = AGG::GetICN(ICN::Get4Captain(castle.GetRace()),
						(building & BUILD_CAPTAIN ? 1 : 0));
	area.w = sprite.w();
	area.h = sprite.h();
    }
}
Exemple #7
0
void LocationPhase::Load()
{
	LocationPhase::fileLoader.Open(locationsPathC + LocationPhase::location.GetPath());

	LocationPhase::width = LocationPhase::fileLoader.GetSizeT();
	LocationPhase::numberOfMonsters = LocationPhase::fileLoader.GetSizeT();
	
	for (size_t i = 0; i < LocationPhase::numberOfMonsters; i++)
	{
		LocationPhase::fileLoader.GetLine();
		string monsterLocation = LocationPhase::fileLoader.GetLine();
		bool isDefeated = LocationPhase::fileLoader.GetLine() == "yes";
		size_t monsterOffset = LocationPhase::fileLoader.GetSizeT();

		
		LocationPhase::monsterLoader.Open(monstersPathC + monsterLocation);

		size_t monsterDifficulty = LocationPhase::monsterLoader.GetSizeT();

		size_t monsterWidth = 5 * monsterDifficulty;

		string line = LocationPhase::monsterLoader.GetLine();
		

		vector<vector<bool>> shape;
		vector<bool> rowShape;
		for (int i = 0; i < monsterWidth; i++)
		{
			line = LocationPhase::monsterLoader.GetLine();
			for (int j = 0; j < monsterWidth; j++)
			{
				rowShape.push_back(line[j] == '0' ? false : true);
			}
			shape.push_back(rowShape);
			rowShape.clear();
		}
		LocationPhase::monsterLoader.GetLine();

		bool isGood = LocationPhase::monsterLoader.GetLine() == "good";

		LocationPhase::monsters.push_back(Monster(monsterLocation, monsterOffset, isGood, monsterDifficulty, isDefeated, LocationPhase::monsterLoader.GetLine(), LocationPhase::monsterLoader.GetLine(), LocationPhase::monsterLoader.GetLine(), shape));

		LocationPhase::monsterLoader.Close();
	}


	LocationPhase::fileLoader.Close();
}
/*战女神米涅瓦*/
GodnessMinerva::GodnessMinerva(bool enemy, int level) :Monster(){
	Monster();
	name = "GodnessMinerva";
	spiral_burst_effect_png = "sb_GodnessMinerva";
	bisha_effect_png = "bisha_GodnessMinerva";
	this->level = 100;
	monster_type = 1;
	energy = 0;
	spiral_burst_light = 0;
	energy_limit = 2;
	spiral_burst_limit = 4;
	race_property = 5;
	hp_point = 50;
	hp_now = (hp_point * 2 + level)*level / 10 + 1000;
	if (enemy){
		hp_now = hp_now * enemy_enhance;
	}
	hp_total = hp_now;
	power_point = 60;
	power = (power_point * 2 + 5)*level / 10;
}
DwellingItem::DwellingItem(Castle & castle, u32 dw)
{
    type = castle.GetActualDwelling(dw);
    mons = Monster(castle.GetRace(), type);
}
Exemple #10
0
void Castle::OpenWell(void)
{
    const Settings & conf = Settings::Get();
    Display & display = Display::Get();
    // cursor
    Cursor & cursor = Cursor::Get();

    cursor.Hide();

    Dialog::FrameBorder frameborder;
    frameborder.SetPosition((display.w() - 640 - BORDERWIDTH * 2) / 2, (display.h() - 480 - BORDERWIDTH * 2) / 2, 640, 480);
    frameborder.Redraw();
    
    const Point cur_pt(frameborder.GetArea().x, frameborder.GetArea().y);

    Point dst_pt(cur_pt);

    // button exit
    dst_pt.x = cur_pt.x + 578;
    dst_pt.y = cur_pt.y + 461;
    Button buttonExit(dst_pt, ICN::WELLXTRA, 0, 1);

    dst_pt.x = cur_pt.x;
    dst_pt.y = cur_pt.y + 461;
    Button buttonMax(dst_pt, ICN::BUYMAX, 0, 1);
    
    const Rect rectMonster1(cur_pt.x + 20, cur_pt.y + 18, 288, 124);
    const Rect rectMonster2(cur_pt.x + 20, cur_pt.y + 168, 288, 124);
    const Rect rectMonster3(cur_pt.x + 20, cur_pt.y + 318, 288, 124);
    const Rect rectMonster4(cur_pt.x + 334, cur_pt.y + 18, 288, 124);
    const Rect rectMonster5(cur_pt.x + 334, cur_pt.y + 168, 288, 124);
    const Rect rectMonster6(cur_pt.x + 334, cur_pt.y + 318, 288, 124);
    
    buttonExit.Draw();

    WellRedrawInfoArea(cur_pt);

    if(! conf.ExtCastleAllowBuyFromWell())
	buttonMax.SetDisable(true);
    else
    {
	buttonMax.Draw();
    }

    std::vector<u32> alldwellings;
    alldwellings.reserve(6);
    alldwellings.push_back(DWELLING_MONSTER6);
    alldwellings.push_back(DWELLING_MONSTER5);
    alldwellings.push_back(DWELLING_MONSTER4);
    alldwellings.push_back(DWELLING_MONSTER3);
    alldwellings.push_back(DWELLING_MONSTER2);
    alldwellings.push_back(DWELLING_MONSTER1);

    cursor.Show();
    display.Flip();

    bool redraw = false;
    LocalEvent & le = LocalEvent::Get();

    // loop
    while(le.HandleEvents())
    {
        le.MousePressLeft(buttonExit) ? buttonExit.PressDraw() : buttonExit.ReleaseDraw();

	buttonMax.isEnable() &&
        le.MousePressLeft(buttonMax) ? buttonMax.PressDraw() : buttonMax.ReleaseDraw();

        if(le.MouseClickLeft(buttonExit) || HotKeyCloseWindow) break;

        // extended version (click - buy dialog monster)
        if(conf.ExtCastleAllowBuyFromWell())
        {
	    if(buttonMax.isEnable() && le.MouseClickLeft(buttonMax))
	    {
		dwellings_t results;
		Funds cur, total;
		u16 can_recruit;
		std::string str;

		for(std::vector<u32>::const_iterator
		    it = alldwellings.begin(); it != alldwellings.end(); ++it)
		if(0 != (can_recruit = HowManyRecruitMonster(*this, *it, total, cur)))
		{
		    results.push_back(dwelling_t(*it, can_recruit));
		    total += cur;
		    const Monster ms(race, GetActualDwelling(*it));
		    str.append(ms.GetPluralName(can_recruit));
		    str.append(" - ");
		    str.append(GetString(can_recruit));
		    str.append("\n");
		}

		if(str.empty()) str = "None";

		if(Dialog::YES ==
		    Dialog::ResourceInfo(_("Buy Monsters:"), str, total, Dialog::YES|Dialog::NO))
		{
		    for(dwellings_t::const_iterator
			it = results.begin(); it != results.end(); ++it)
		    {
			const dwelling_t & dw = *it;
			RecruitMonster(dw.first, dw.second);
		    }
		    redraw = true;
		}
	    }

    	    if(building & DWELLING_MONSTER1 && dwelling[0] && le.MouseClickLeft(rectMonster1) &&
    		RecruitMonster(DWELLING_MONSTER1, Dialog::RecruitMonster(
            	    Monster(race, DWELLING_MONSTER1), dwelling[0]))) redraw = true;
    	    else
    	    if(building & DWELLING_MONSTER2 && dwelling[1] && le.MouseClickLeft(rectMonster2) &&
    		RecruitMonster(DWELLING_MONSTER2, Dialog::RecruitMonster(
            	    Monster(race, GetActualDwelling(DWELLING_MONSTER2)), dwelling[1]))) redraw = true;
    	    else
    	    if(building & DWELLING_MONSTER3 && dwelling[2] && le.MouseClickLeft(rectMonster3) &&
    		RecruitMonster(DWELLING_MONSTER3, Dialog::RecruitMonster(
            	    Monster(race, GetActualDwelling(DWELLING_MONSTER3)), dwelling[2]))) redraw = true;
    	    else
    	    if(building & DWELLING_MONSTER4 && dwelling[3] && le.MouseClickLeft(rectMonster4) &&
    		RecruitMonster(DWELLING_MONSTER4, Dialog::RecruitMonster(
            	    Monster(race, GetActualDwelling(DWELLING_MONSTER4)), dwelling[3]))) redraw = true;
    	    else
    	    if(building & DWELLING_MONSTER5 && dwelling[4] && le.MouseClickLeft(rectMonster5) &&
    		RecruitMonster(DWELLING_MONSTER5, Dialog::RecruitMonster(
            	    Monster(race, GetActualDwelling(DWELLING_MONSTER5)), dwelling[4]))) redraw = true;
    	    else
    	    if(building & DWELLING_MONSTER6 && dwelling[5] && le.MouseClickLeft(rectMonster6) &&
                RecruitMonster(DWELLING_MONSTER6, Dialog::RecruitMonster(
                    Monster(race, GetActualDwelling(DWELLING_MONSTER6)), dwelling[5]))) redraw = true;

	    if(redraw)
	    {
        	cursor.Hide();
		WellRedrawInfoArea(cur_pt);
		buttonMax.Draw();
		cursor.Show();
        	display.Flip();
		redraw = false;
	    }
	}
    }
}
 void ActionListPressRight(int & index)
 {
   Troop troop(Monster(index), 1);
   Dialog::ArmyInfo(troop, 0);
 };
Exemple #12
0
void FileParser::createGameElement(char source, Pos pos)
{
	switch (source) {
		case ' ':
		case 'x':
		case 'X':
			// WALL
			story->set(pos, source);
			break;

		case 'h':
		case 'H':
			// HERO
			{
				elements->player = Player(pos);
			}
			break;

		case 'a':
		case 'A':
			// WEAPON
			{
				elements->weapon_vec.push_back(Weapon(pos));
			}
			break;

		case 's':
		case 'S':
			// MONSTER
			{
				elements->monster_vec.push_back(Monster(pos));
			}
			break;

		case 'k':
		case 'K':
			// TREASURE
			{
				elements->treasure_vec.push_back(Treasure(pos));
			}
			break;

		case 'i':
		case 'I':
			// POTION
			{
				elements->potion_vec.push_back(Potion(pos));
			}
			break;

		case 'c':
		case 'C':
			// TRAP
			{
				elements->trap_vec.push_back(Trap(pos));
			}
			break;

		case 'j':
		case 'J':
			// EXIT
			{
				elements->exit_vec.push_back(Exit(pos));
			}
			break;

		default:
			break;
	}
}
void TestMonsterSprite(void)
{
    // cursor
    Cursor & cursor = Cursor::Get();
    cursor.Hide();
    cursor.SetThemes(Cursor::POINTER);

    //Monster monster(Monster::PEASANT);
    Army::Troop troop(Monster::PEASANT, 1);
    troop.BattleInit();
    const Battle2::Stats & b = *troop.GetBattleStats();
    Background back;
    Rect pos;

    Display & display = Display::Get();
    LocalEvent & le = LocalEvent::Get();

    //std::string str;

    StatusBar speed_bar;
    StatusBar count_bar;
    StatusBar start_bar;
    StatusBar frame_bar;
    StatusBar info_bar;

    start_bar.SetCenter(100, display.h() - 15);
    count_bar.SetCenter(200, display.h() - 15);
    speed_bar.SetCenter(300, display.h() - 15);
    frame_bar.SetCenter(400, display.h() - 15);
    info_bar.SetCenter(550, display.h() - 15);

    u32 ticket = 0;

    u8 start = 0;
    u8 count = AGG::GetICNCount(b.ICNFile());
    u8 frame = 0;
    u8 speed = 100;

    frame_bar.ShowMessage("frame: " + GetString(frame));
    speed_bar.ShowMessage("speed: " + GetString(speed));
    start_bar.ShowMessage("start: " + GetString(start));
    count_bar.ShowMessage("count: " + GetString(count));

    cursor.Show();
    display.Flip();

    // mainmenu loop
    while(le.HandleEvents())
    {
	if(Game::HotKeyPress(Game::EVENT_DEFAULT_EXIT)) break;

	if(le.MouseClickLeft(pos))
	{
            u32 mons = troop().GetID();
            if(Dialog::SelectCount("Monster", Monster::PEASANT, Monster::WATER_ELEMENT, mons))
	    {
        	cursor.Hide();
		troop.SetMonster(Monster(mons));
		start = 0;
		count = AGG::GetICNCount(b.ICNFile());
		frame = 0;
        	cursor.Show();
        	display.Flip();
	    }
	}

	if(le.MouseClickLeft(start_bar.GetRect()))
	{
	    u32 start2 = start;
	    if(Dialog::SelectCount("Start", 0, AGG::GetICNCount(b.ICNFile()) - 1, start2))
	    {
        	cursor.Hide();
		start = start2;
		if(start + count > AGG::GetICNCount(b.ICNFile())) count = AGG::GetICNCount(b.ICNFile()) - start;
		start_bar.ShowMessage("start: " + GetString(start));
        	cursor.Show();
        	display.Flip();
    	    }
	}

	if(le.MouseClickLeft(count_bar.GetRect()))
	{
	    u32 count2 = count;
	    if(Dialog::SelectCount("Count", 1, AGG::GetICNCount(b.ICNFile()), count2))
	    {
        	cursor.Hide();
		count = count2;
		frame = start;
		count_bar.ShowMessage("count: " + GetString(count));
        	cursor.Show();
        	display.Flip();
	    }
	}

	if(le.MouseClickLeft(speed_bar.GetRect()))
	{
	    u32 speed2 = speed;
	    if(Dialog::SelectCount("Speed", 1, 50, speed2))
	    {
        	cursor.Hide();
		speed = speed2;
		frame = start;
		speed_bar.ShowMessage("speed: " + GetString(speed));
        	cursor.Show();
        	display.Flip();
	    }
	}

        if(0 == (ticket % speed))
        {
            cursor.Hide();
            const Sprite & sprite = AGG::GetICN(b.ICNFile(), frame);
	    pos.x = 320 + sprite.x();
	    pos.y = 240 + sprite.y();
	    pos.w = sprite.w();
	    pos.h = sprite.h();
	    back.Restore();
	    back.Save(pos);
            sprite.Blit(pos);

	    frame_bar.ShowMessage("frame: " + GetString(frame));
	    info_bar.ShowMessage("ox: " + GetString(sprite.x()) + ", oy: " + GetString(sprite.y()));

            cursor.Show();
            display.Flip();

	    ++frame;
	    if(frame >= start + count) frame = start;
        }

        ++ticket;
    }
}