1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-01-14 02:33:51 +02:00

VERY buggy, unusable, but progress is being made...

This commit is contained in:
Patrick Simmons 2014-10-19 07:47:09 -04:00
parent d0e82caaf3
commit cfa6f46d62
5 changed files with 73 additions and 24 deletions

View File

@ -224,7 +224,13 @@ int main(int argc, char** argv)
("oneGoodAI", "puts one default AI and the rest will be EmptyAI") ("oneGoodAI", "puts one default AI and the rest will be EmptyAI")
("autoSkip", "automatically skip turns in GUI") ("autoSkip", "automatically skip turns in GUI")
("disable-video", "disable video player") ("disable-video", "disable video player")
("nointro,i", "skips intro movies"); ("nointro,i", "skips intro movies")
("loadserver","specifies we are the multiplayer server for loaded games")
("loadnumplayers",po::value<int>(),"specifies the number of players connecting to a multiplayer game")
("loadhumanplayerindices",po::value<std::vector<int>>(),"Indexes of human players (0=Red, etc.)")
("loadplayer", po::value<int>(),"specifies which player we are in multiplayer loaded games (0=Red, etc.)")
("loadserverip",po::value<std::string>(),"IP for loaded game server")
("loadserverport",po::value<std::string>(),"port for loaded game server");
if(argc > 1) if(argc > 1)
{ {
@ -1222,7 +1228,10 @@ void startGame(StartInfo * options, CConnection *serv/* = nullptr*/)
case StartInfo::LOAD_GAME: case StartInfo::LOAD_GAME:
std::string fname = options->mapname; std::string fname = options->mapname;
boost::algorithm::erase_last(fname,".vlgm1"); boost::algorithm::erase_last(fname,".vlgm1");
if(!vm.count("loadplayer"))
client->loadGame(fname); client->loadGame(fname);
else
client->loadGame(fname,vm.count("loadserver"),vm.count("loadhumanplayerindices") ? vm["loadhumanplayerindices"].as<std::vector<int>>() : std::vector<int>(),vm.count("loadnumplayers") ? vm["loadnumplayers"].as<int>() : 1,vm["loadplayer"].as<int>(),vm.count("loadserverip") ? vm["loadserverip"].as<std::string>() : "", vm.count("loadserverport") ? vm["loadserverport"].as<std::string>() : "3030");
break; break;
} }

View File

@ -236,12 +236,15 @@ void CClient::endGame( bool closeConnection /*= true*/ )
logNetwork->infoStream() << "Client stopped."; logNetwork->infoStream() << "Client stopped.";
} }
void CClient::loadGame( const std::string & fname ) void CClient::loadGame(const std::string & fname, const bool server, const std::vector<int>& humanplayerindices, const int loadNumPlayers, int player_, const std::string & ipaddr, const std::string & port)
{ {
logNetwork->infoStream() <<"Loading procedure started!"; logNetwork->infoStream() <<"Loading procedure started!";
CServerHandler sh; CServerHandler sh;
if(server)
sh.startServer(); sh.startServer();
else
serv = sh.justConnectToServer(ipaddr,port=="" ? "3030" : port);
CStopWatch tmh; CStopWatch tmh;
try try
@ -286,30 +289,65 @@ void CClient::loadGame( const std::string & fname )
throw; //obviously we cannot continue here throw; //obviously we cannot continue here
} }
if(server)
serv = sh.connectToServer(); serv = sh.connectToServer();
serv->addStdVecItems(gs);
if(player_==-1)
player_ = player->getNum();
else
player = PlayerColor(player_);
serv->addStdVecItems(gs); /*why is this here?*/
std::cout << player << std::endl;
if(server)
{
tmh.update(); tmh.update();
ui8 pom8; ui8 pom8;
*serv << ui8(3) << ui8(1); //load game; one client *serv << ui8(3) << ui8(loadNumPlayers); //load game; one client if single-player
*serv << fname; *serv << fname;
*serv >> pom8; *serv >> pom8;
if(pom8) if(pom8)
throw std::runtime_error("Server cannot open the savegame!"); throw std::runtime_error("Server cannot open the savegame!");
else else
logNetwork->infoStream() << "Server opened savegame properly."; logNetwork->infoStream() << "Server opened savegame properly.";
}
*serv << ui32(gs->scenarioOps->playerInfos.size()+1); //number of players + neutral if(server)
{
*serv << ui32(gs->scenarioOps->playerInfos.size()+2-loadNumPlayers); //number of players + neutral
for(auto & elem : gs->scenarioOps->playerInfos) for(auto & elem : gs->scenarioOps->playerInfos)
if(!std::count(humanplayerindices.begin(),humanplayerindices.end(),elem.first.getNum()) || elem.first==player)
{ {
*serv << ui8(elem.first.getNum()); //players *serv << ui8(elem.first.getNum()); //players
if(elem.first!=player)
{
auto AiToGive = aiNameForPlayer(elem.second, false);
logNetwork->infoStream() << boost::format("Player %s will be lead by %s") % elem.first % AiToGive;
installNewPlayerInterface(CDynLibHandler::getNewAI(AiToGive), elem.first);
}
else
{
installNewPlayerInterface(make_shared<CPlayerInterface>(*player),*player);
}
} }
*serv << ui8(PlayerColor::NEUTRAL.getNum()); *serv << ui8(PlayerColor::NEUTRAL.getNum());
}
else
{
*serv << ui32(1);
*serv << ui8(player->getNum());
installNewPlayerInterface(make_shared<CPlayerInterface>(*player),*player);
}
logNetwork->infoStream() <<"Sent info to server: "<<tmh.getDiff(); logNetwork->infoStream() <<"Sent info to server: "<<tmh.getDiff();
serv->addStdVecItems(gs);
serv->enableStackSendingByID(); serv->enableStackSendingByID();
serv->disableSmartPointerSerialization(); serv->disableSmartPointerSerialization();
loadNeutralBattleAI();
// logGlobal->traceStream() << "Objects:"; // logGlobal->traceStream() << "Objects:";
// for(int i = 0; i < gs->map->objects.size(); i++) // for(int i = 0; i < gs->map->objects.size(); i++)
// { // {
@ -833,6 +871,7 @@ CConnection * CServerHandler::connectToServer()
#endif #endif
th.update(); //put breakpoint here to attach to server before it does something stupid th.update(); //put breakpoint here to attach to server before it does something stupid
CConnection *ret = justConnectToServer(settings["server"]["server"].String(), port); CConnection *ret = justConnectToServer(settings["server"]["server"].String(), port);
if(verbose) if(verbose)

View File

@ -151,7 +151,7 @@ public:
void endGame(bool closeConnection = true); void endGame(bool closeConnection = true);
void stopConnection(); void stopConnection();
void save(const std::string & fname); void save(const std::string & fname);
void loadGame(const std::string & fname); void loadGame(const std::string & fname, const bool server = true, const std::vector<int>& humanplayerindices = std::vector<int>(), const int loadnumplayers = 1, int player_ = -1, const std::string & ipaddr = "", const std::string & port = "");
void run(); void run();
void campaignMapFinished( shared_ptr<CCampaignState> camp ); void campaignMapFinished( shared_ptr<CCampaignState> camp );
void finishCampaign( shared_ptr<CCampaignState> camp ); void finishCampaign( shared_ptr<CCampaignState> camp );

View File

@ -387,11 +387,12 @@ CStackInstance * CCreatureSet::detachStack(SlotID slot)
CStackInstance *ret = stacks[slot]; CStackInstance *ret = stacks[slot];
//if(CArmedInstance *armedObj = castToArmyObj()) //if(CArmedInstance *armedObj = castToArmyObj())
if(ret)
{ {
ret->setArmyObj(nullptr); //detaches from current armyobj ret->setArmyObj(nullptr); //detaches from current armyobj
assert(!ret->armyObj); //we failed detaching?
} }
assert(!ret->armyObj); //we failed detaching?
stacks.erase(slot); stacks.erase(slot);
armyChanged(); armyChanged();
return ret; return ret;

View File

@ -463,7 +463,7 @@ void CVCMIServer::loadGame()
boost::system::error_code error; boost::system::error_code error;
ui8 clients; ui8 clients;
c >> clients >> fname; //how many clients should be connected - TODO: support more than one c >> clients >> fname; //how many clients should be connected
// { // {
// char sig[8]; // char sig[8];