bool PrepareMapsFileInfoList(MapsFileInfoList & lists, bool multi) { const Settings & conf = Settings::Get(); ListFiles maps = conf.GetListFiles("maps", ".mp2"); // check loyality version if(conf.PriceLoyaltyVersion()) maps.Append(conf.GetListFiles("maps", ".mx2")); const ListDirs & list = conf.GetMapsParams(); if(! list.empty()) { for(ListDirs::const_iterator it = list.begin(); it != list.end(); ++it) if(*it != "maps") { maps.Append(conf.GetListFiles(*it, ".mp2")); if(conf.PriceLoyaltyVersion()) maps.Append(conf.GetListFiles(*it, ".mx2")); } } if(maps.empty()) return false; lists.reserve(maps.size()); for(ListFiles::const_iterator it = maps.begin(); it != maps.end(); ++it) { Maps::FileInfo fi; if(fi.ReadMP2(*it)) lists.push_back(fi); } std::sort(lists.begin(), lists.end(), Maps::FileInfo::NameSorting); lists.resize(std::unique(lists.begin(), lists.end(), Maps::FileInfo::NameCompare) - lists.begin()); if(multi == false) { MapsFileInfoList::iterator it = std::remove_if(lists.begin(), lists.end(), std::mem_fun_ref(&Maps::FileInfo::isMultiPlayerMap)); if(it != lists.begin()) lists.resize(std::distance(lists.begin(), it)); } // set preferably count filter if(conf.PreferablyCountPlayers()) { MapsFileInfoList::iterator it = std::remove_if(lists.begin(), lists.end(), std::not1(std::bind2nd(std::mem_fun_ref(&Maps::FileInfo::isAllowCountPlayers), conf.PreferablyCountPlayers()))); if(it != lists.begin()) lists.resize(std::distance(lists.begin(), it)); } return lists.size(); }
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()); }