mirror of
https://github.com/vcmi/vcmi.git
synced 2024-12-24 22:14:36 +02:00
VERY buggy, unusable, but progress is being made...
This commit is contained in:
parent
d0e82caaf3
commit
cfa6f46d62
@ -224,7 +224,13 @@ int main(int argc, char** argv)
|
||||
("oneGoodAI", "puts one default AI and the rest will be EmptyAI")
|
||||
("autoSkip", "automatically skip turns in GUI")
|
||||
("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)
|
||||
{
|
||||
@ -1222,7 +1228,10 @@ void startGame(StartInfo * options, CConnection *serv/* = nullptr*/)
|
||||
case StartInfo::LOAD_GAME:
|
||||
std::string fname = options->mapname;
|
||||
boost::algorithm::erase_last(fname,".vlgm1");
|
||||
client->loadGame(fname);
|
||||
if(!vm.count("loadplayer"))
|
||||
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;
|
||||
}
|
||||
|
||||
|
@ -236,12 +236,15 @@ void CClient::endGame( bool closeConnection /*= true*/ )
|
||||
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!";
|
||||
|
||||
CServerHandler sh;
|
||||
sh.startServer();
|
||||
if(server)
|
||||
sh.startServer();
|
||||
else
|
||||
serv = sh.justConnectToServer(ipaddr,port=="" ? "3030" : port);
|
||||
|
||||
CStopWatch tmh;
|
||||
try
|
||||
@ -286,30 +289,65 @@ void CClient::loadGame( const std::string & fname )
|
||||
throw; //obviously we cannot continue here
|
||||
}
|
||||
|
||||
serv = sh.connectToServer();
|
||||
serv->addStdVecItems(gs);
|
||||
if(server)
|
||||
serv = sh.connectToServer();
|
||||
|
||||
tmh.update();
|
||||
ui8 pom8;
|
||||
*serv << ui8(3) << ui8(1); //load game; one client
|
||||
*serv << fname;
|
||||
*serv >> pom8;
|
||||
if(pom8)
|
||||
throw std::runtime_error("Server cannot open the savegame!");
|
||||
else
|
||||
logNetwork->infoStream() << "Server opened savegame properly.";
|
||||
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();
|
||||
ui8 pom8;
|
||||
*serv << ui8(3) << ui8(loadNumPlayers); //load game; one client if single-player
|
||||
*serv << fname;
|
||||
*serv >> pom8;
|
||||
if(pom8)
|
||||
throw std::runtime_error("Server cannot open the savegame!");
|
||||
else
|
||||
logNetwork->infoStream() << "Server opened savegame properly.";
|
||||
}
|
||||
|
||||
if(server)
|
||||
{
|
||||
*serv << ui32(gs->scenarioOps->playerInfos.size()+2-loadNumPlayers); //number of players + neutral
|
||||
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
|
||||
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());
|
||||
}
|
||||
else
|
||||
{
|
||||
*serv << ui32(1);
|
||||
*serv << ui8(player->getNum());
|
||||
installNewPlayerInterface(make_shared<CPlayerInterface>(*player),*player);
|
||||
}
|
||||
|
||||
*serv << ui32(gs->scenarioOps->playerInfos.size()+1); //number of players + neutral
|
||||
for(auto & elem : gs->scenarioOps->playerInfos)
|
||||
{
|
||||
*serv << ui8(elem.first.getNum()); //players
|
||||
}
|
||||
*serv << ui8(PlayerColor::NEUTRAL.getNum());
|
||||
logNetwork->infoStream() <<"Sent info to server: "<<tmh.getDiff();
|
||||
|
||||
serv->addStdVecItems(gs);
|
||||
serv->enableStackSendingByID();
|
||||
serv->disableSmartPointerSerialization();
|
||||
|
||||
loadNeutralBattleAI();
|
||||
|
||||
// logGlobal->traceStream() << "Objects:";
|
||||
// for(int i = 0; i < gs->map->objects.size(); i++)
|
||||
// {
|
||||
@ -833,6 +871,7 @@ CConnection * CServerHandler::connectToServer()
|
||||
#endif
|
||||
|
||||
th.update(); //put breakpoint here to attach to server before it does something stupid
|
||||
|
||||
CConnection *ret = justConnectToServer(settings["server"]["server"].String(), port);
|
||||
|
||||
if(verbose)
|
||||
|
@ -151,7 +151,7 @@ public:
|
||||
void endGame(bool closeConnection = true);
|
||||
void stopConnection();
|
||||
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 campaignMapFinished( shared_ptr<CCampaignState> camp );
|
||||
void finishCampaign( shared_ptr<CCampaignState> camp );
|
||||
|
@ -387,11 +387,12 @@ CStackInstance * CCreatureSet::detachStack(SlotID slot)
|
||||
CStackInstance *ret = stacks[slot];
|
||||
|
||||
//if(CArmedInstance *armedObj = castToArmyObj())
|
||||
if(ret)
|
||||
{
|
||||
ret->setArmyObj(nullptr); //detaches from current armyobj
|
||||
assert(!ret->armyObj); //we failed detaching?
|
||||
}
|
||||
|
||||
assert(!ret->armyObj); //we failed detaching?
|
||||
stacks.erase(slot);
|
||||
armyChanged();
|
||||
return ret;
|
||||
|
@ -463,7 +463,7 @@ void CVCMIServer::loadGame()
|
||||
boost::system::error_code error;
|
||||
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];
|
||||
|
Loading…
Reference in New Issue
Block a user