/** ** Exit the game. ** ** @param err Error code to pass to shell. */ void Exit(int err) { if (GameRunning) { StopGame(GameExit); return; } StopMusic(); QuitSound(); NetworkQuit(); ExitNetwork1(); #ifdef DEBUG CleanModules(); FreeBurningBuildingFrames(); FreeSounds(); FreeGraphics(); FreePlayerColors(); FreeButtonStyles(); for (size_t i = 0; i < Containers.size(); ++i) { delete Containers[i]; } freeGuichan(); DebugPrint("Frames %lu, Slow frames %d = %ld%%\n" _C_ FrameCounter _C_ SlowFrameCounter _C_ (SlowFrameCounter * 100) / (FrameCounter ? FrameCounter : 1)); lua_settop(Lua, 0); lua_close(Lua); DeInitVideo(); #endif fprintf(stdout, "%s", _("Thanks for playing Stratagus.\n")); exit(err); }
/** ** Exit the game. ** ** @param err Error code to pass to shell. */ void Exit(int err) { if (GameRunning) { StopGame(GameExit); return; } StopMusic(); QuitSound(); NetworkQuitGame(); ExitNetwork1(); CleanModules(); FreeBurningBuildingFrames(); FreeSounds(); FreeGraphics(); FreePlayerColors(); FreeButtonStyles(); FreeAllContainers(); freeGuichan(); DebugPrint("Frames %lu, Slow frames %d = %ld%%\n" _C_ FrameCounter _C_ SlowFrameCounter _C_ (SlowFrameCounter * 100) / (FrameCounter ? FrameCounter : 1)); lua_settop(Lua, 0); lua_close(Lua); DeInitVideo(); #ifdef USE_PHYSFS if (PHYSFS_isInit()) { PHYSFS_deinit(); } #endif fprintf(stdout, "%s", _("Thanks for playing Stratagus.\n")); exit(err); }
/** ** Applies settings the game used at the start of the replay */ static void ApplyReplaySettings() { if (CurrentReplay->Type == ReplayMultiPlayer) { ExitNetwork1(); NetPlayers = 2; GameSettings.NetGameType = SettingsMultiPlayerGame; ReplayGameType = ReplayMultiPlayer; NetLocalPlayerNumber = CurrentReplay->LocalPlayer; } else { GameSettings.NetGameType = SettingsSinglePlayerGame; ReplayGameType = ReplaySinglePlayer; } for (int i = 0; i < PlayerMax; ++i) { GameSettings.Presets[i].AIScript = CurrentReplay->Players[i].AIScript; GameSettings.Presets[i].Race = CurrentReplay->Players[i].Race; //Wyrmgus start Players[i].Faction = CurrentReplay->Players[i].Faction; // should use a game settings preset instead //Wyrmgus end GameSettings.Presets[i].Team = CurrentReplay->Players[i].Team; GameSettings.Presets[i].Type = CurrentReplay->Players[i].Type; } if (strcpy_s(CurrentMapPath, sizeof(CurrentMapPath), CurrentReplay->MapPath.c_str()) != 0) { fprintf(stderr, "Replay map path is too long\n"); // FIXME: need to handle errors better Exit(1); } GameSettings.Resources = CurrentReplay->Resource; GameSettings.NumUnits = CurrentReplay->NumUnits; GameSettings.Difficulty = CurrentReplay->Difficulty; Map.NoFogOfWar = GameSettings.NoFogOfWar = CurrentReplay->NoFow; GameSettings.Inside = CurrentReplay->Inside; GameSettings.GameType = CurrentReplay->GameType; FlagRevealMap = GameSettings.RevealMap = CurrentReplay->RevealMap; GameSettings.MapRichness = CurrentReplay->MapRichness; GameSettings.Opponents = CurrentReplay->Opponents; //Wyrmgus start GameSettings.NoRandomness = CurrentReplay->NoRandomness; GameSettings.NoTimeOfDay = CurrentReplay->NoTimeOfDay; //Wyrmgus end // FIXME : check engine version // FIXME : FIXME: check network version // FIXME : check mapid }
/** ** Initialize network port. */ void InitNetwork1() { CNetworkParameter::Instance.FixValues(); NetInit(); // machine dependent setup // Our communication port const int port = CNetworkParameter::Instance.localPort; const char *NetworkAddr = NULL; // FIXME : bad use const CHost host(NetworkAddr, port); NetworkFildes.Open(host); if (NetworkFildes.IsValid() == false) { fprintf(stderr, "NETWORK: No free port %d available, aborting\n", port); NetExit(); // machine dependent network exit return; } #ifdef DEBUG const std::string hostStr = host.toString(); DebugPrint("My host:port %s\n" _C_ hostStr.c_str()); #endif #if 0 // FIXME: need a working interface check unsigned long ips[10]; int networkNumInterfaces = NetSocketAddr(NetworkFildes, ips, 10); if (networkNumInterfaces) { DebugPrint("Num IP: %d\n" _C_ networkNumInterfaces); for (int i = 0; i < networkNumInterfaces; ++i) { DebugPrint("IP: %d.%d.%d.%d\n" _C_ NIPQUAD(ntohl(ips[i]))); } } else { fprintf(stderr, "NETWORK: Not connected to any external IPV4-network, aborting\n"); ExitNetwork1(); return; } #endif }