diff --git a/MCGalaxy/Blocks/BlockDefinitions.cs b/MCGalaxy/Blocks/BlockDefinitions.cs index d4af52a0d..695756dd1 100644 --- a/MCGalaxy/Blocks/BlockDefinitions.cs +++ b/MCGalaxy/Blocks/BlockDefinitions.cs @@ -329,7 +329,7 @@ namespace MCGalaxy { // if custom block is replacing core block, need to always reload for fallback if (block >= Block.CpeCount && !pl.level.MayHaveCustomBlocks) continue; - LevelActions.ReloadMap(pl, pl, false); + LevelActions.ReloadFor(pl, pl, false); } } } diff --git a/MCGalaxy/Commands/World/CmdReload.cs b/MCGalaxy/Commands/World/CmdReload.cs index 46c081db5..f630326ea 100644 --- a/MCGalaxy/Commands/World/CmdReload.cs +++ b/MCGalaxy/Commands/World/CmdReload.cs @@ -38,7 +38,7 @@ namespace MCGalaxy.Commands.World { if (parts[0].CaselessEq("all")) { if (!ReloadAll(p, parts)) return; } else { - LevelActions.ReloadMap(p, p, true); + LevelActions.ReloadFor(p, p, true); } Server.DoGC(); } @@ -55,11 +55,7 @@ namespace MCGalaxy.Commands.World { } if (!CheckExtraPerm(p, 1)) return false; - Player[] players = PlayerInfo.Online.Items; - foreach (Player who in players) { - if (who.level == lvl) - LevelActions.ReloadMap(p, who, true); - } + LevelActions.ReloadAll(lvl, p, true); return true; } diff --git a/MCGalaxy/Drawing/DrawOps/DrawOpPerformer.cs b/MCGalaxy/Drawing/DrawOps/DrawOpPerformer.cs index e1917ae13..5a51a1c9c 100644 --- a/MCGalaxy/Drawing/DrawOps/DrawOpPerformer.cs +++ b/MCGalaxy/Drawing/DrawOps/DrawOpPerformer.cs @@ -152,7 +152,7 @@ namespace MCGalaxy.Drawing.Ops { Player[] players = PlayerInfo.Online.Items; foreach (Player pl in players) { if (pl.level.name.CaselessEq(lvl.name)) - LevelActions.ReloadMap(p, pl, true); + LevelActions.ReloadFor(p, pl, true); } Server.DoGC(); } diff --git a/MCGalaxy/Games/RoundsGame/RoundsGame.cs b/MCGalaxy/Games/RoundsGame/RoundsGame.cs index ab1b0eacf..cacb86294 100644 --- a/MCGalaxy/Games/RoundsGame/RoundsGame.cs +++ b/MCGalaxy/Games/RoundsGame/RoundsGame.cs @@ -51,7 +51,7 @@ namespace MCGalaxy.Games { Chat.MessageGlobal("A game of {0} is starting on {1}%S!", GameName, Map.ColoredName); Logger.Log(LogType.GameActivity, "[{0}] Game started", GameName); - StartGame(); + StartGame(); RoundsLeft = rounds; Running = true; @@ -143,23 +143,43 @@ namespace MCGalaxy.Games { protected virtual void VoteAndMoveToNextMap() { Picker.AddRecentMap(Map.MapName); if (RoundsLeft == 0) return; + string map = Picker.ChooseNextLevel(this); - if (map == null) return; + if (map == null) { ContinueOnSameMap(); return; } Map.Message("The next map has been chosen - &c" + map.ToLower()); - Map.Message("Please wait while you are transfered."); - LastMap = Map.MapName; + Map.Message("Please wait while you are transfered."); + Level lastMap = Map; LastMap = Map.MapName; if (!SetMap(map)) { Map.Message("%WFailed to change map to " + map); - Map.Message("Continuing " + GameName + " on the same map"); + ContinueOnSameMap(); } else { - TransferPlayers(LastMap); - Command.Find("Unload").Use(null, LastMap); + TransferPlayers(lastMap); + lastMap.Unload(); } } - void TransferPlayers(string lastMap) { + void ContinueOnSameMap() { + Map.Message("Continuing " + GameName + " on the same map"); + Level old = Level.Load(Map.MapName); + + if (old == null) { + Map.Message("%WCannot reset changes to map"); return; + } + if (old.Width != Map.Width || old.Height != Map.Height || old.Length != Map.Length) { + Map.Message("%WCannot reset changes to map"); return; + } + + // Try to reset changes made to this map, if possible + // TODO: do this in a nicer way + Map.blocks = old.blocks; + Map.CustomBlocks = old.CustomBlocks; + LevelActions.ReloadAll(Map, null, false); + Map.Message("Reset map to latest backup"); + } + + void TransferPlayers(Level lastMap) { Random rnd = new Random(); Player[] online = PlayerInfo.Online.Items; List transfers = new List(online.Length); @@ -167,7 +187,7 @@ namespace MCGalaxy.Games { foreach (Player pl in online) { pl.Game.RatedMap = false; pl.Game.PledgeSurvive = false; - if (pl.level != Map && pl.level.name.CaselessEq(lastMap)) { transfers.Add(pl); } + if (pl.level != Map && pl.level == lastMap) transfers.Add(pl); } while (transfers.Count > 0) { @@ -221,6 +241,6 @@ namespace MCGalaxy.Games { LastMap = ""; if (Map != null) Map.AutoUnload(); Map = null; - } + } } } diff --git a/MCGalaxy/Games/TntWars/TWConfig.cs b/MCGalaxy/Games/TntWars/TWConfig.cs index 31473e94e..8b009e485 100644 --- a/MCGalaxy/Games/TntWars/TWConfig.cs +++ b/MCGalaxy/Games/TntWars/TWConfig.cs @@ -91,7 +91,7 @@ namespace MCGalaxy.Games { public void SetDefaults(Level lvl) { ushort midX = (ushort)(lvl.Width / 2); - ushort midY = (ushort)(lvl.Height / 2); + ushort midY = (ushort)(lvl.Height / 2 + 1); ushort maxZ = (ushort)(lvl.Length - 1); RedSpawn = new Vec3U16(midX, midY, 0); diff --git a/MCGalaxy/Games/TntWars/TWGame.Round.cs b/MCGalaxy/Games/TntWars/TWGame.Round.cs index bb550a486..7b1c7a13c 100644 --- a/MCGalaxy/Games/TntWars/TWGame.Round.cs +++ b/MCGalaxy/Games/TntWars/TWGame.Round.cs @@ -35,18 +35,7 @@ namespace MCGalaxy.Games { public sealed partial class TWGame : RoundsGame { - int backupNum; protected override void DoRound() { - backupNum = Map.Backup(true); - if (backupNum <= 0) { - Map.Message("%WBacking up Level for TNT Wars failed, stopping game"); - EndGame(); - return; - } - - Logger.Log(LogType.SystemActivity, "Backed up {0} ({1}) for TNT Wars", Map.name, backupNum); - - Player[] all = allPlayers.Items; foreach (Player p in all) { Get(p).Reset(Config.Difficulty); @@ -185,9 +174,6 @@ namespace MCGalaxy.Games { foreach (Player p in all) { Player.Message(p, "TNT Wars: You scored &f" + Get(p).Score + " points"); } - - // TODO: does this even work right - Command.Find("Restore").Use(null, backupNum + " " + Map.name); } bool buildable = true, deletable = true; diff --git a/MCGalaxy/Levels/LevelActions.cs b/MCGalaxy/Levels/LevelActions.cs index 1ecb57887..b0170e53f 100644 --- a/MCGalaxy/Levels/LevelActions.cs +++ b/MCGalaxy/Levels/LevelActions.cs @@ -165,7 +165,7 @@ namespace MCGalaxy { foreach (Player pl in players) { if (pl.level != old) continue; pl.level = lvl; - ReloadMap(null, pl, false); + ReloadFor(null, pl, false); } old.Unload(true, false); @@ -201,21 +201,29 @@ namespace MCGalaxy { } - public static void ReloadMap(Player p, Player who, bool announce) { - who.Loading = true; - Entities.DespawnEntities(who); - who.SendMap(who.level); - Entities.SpawnEntities(who); - who.Loading = false; + public static void ReloadAll(Level lvl, Player src, bool announce) { + Player[] players = PlayerInfo.Online.Items; + foreach (Player p in players) { + if (p.level != lvl) continue; + LevelActions.ReloadFor(src, p, true); + } + } + + public static void ReloadFor(Player src, Player p, bool announce) { + p.Loading = true; + Entities.DespawnEntities(p); + p.SendMap(p.level); + Entities.SpawnEntities(p); + p.Loading = false; if (!announce) return; - if (p == null || !Entities.CanSee(who, p)) { - who.SendMessage("&bMap reloaded"); + if (src == null || !Entities.CanSee(p, src)) { + p.SendMessage("&bMap reloaded"); } else { - who.SendMessage("&bMap reloaded by " + p.ColoredName); + p.SendMessage("&bMap reloaded by " + src.ColoredName); } - if (Entities.CanSee(p, who)) { - Player.Message(p, "&4Finished reloading for " + who.ColoredName); + if (Entities.CanSee(src, p)) { + Player.Message(src, "&4Finished reloading for " + p.ColoredName); } } diff --git a/MCGalaxy/Levels/LevelOptions.cs b/MCGalaxy/Levels/LevelOptions.cs index ce1dd9843..dcbaf8c70 100644 --- a/MCGalaxy/Levels/LevelOptions.cs +++ b/MCGalaxy/Levels/LevelOptions.cs @@ -96,7 +96,7 @@ namespace MCGalaxy { if (motdOnly) { pl.SendMapMotd(); } else { - LevelActions.ReloadMap(p, pl, false); + LevelActions.ReloadFor(p, pl, false); } } }