From f2eef89460ddb4ff7b18c0fe98950c27f5af6b28 Mon Sep 17 00:00:00 2001 From: UnknownShadow200 Date: Fri, 9 Sep 2016 19:27:31 +1000 Subject: [PATCH] Praise be to our robot overloads. Start refactoring bot instructions to be more extensible. --- Bots/Instructions/BasicInstructions.cs | 23 ++++++++++++ Bots/Instructions/ComplexInstructions.cs | 23 ++++++++++++ Bots/Instructions/Instruction.cs | 45 ++++++++++++++++++++++++ Bots/PlayerBot.cs | 5 ++- Bots/ScriptFile.cs | 2 +- MCGalaxy_.csproj | 4 +++ 6 files changed, 98 insertions(+), 4 deletions(-) create mode 100644 Bots/Instructions/BasicInstructions.cs create mode 100644 Bots/Instructions/ComplexInstructions.cs create mode 100644 Bots/Instructions/Instruction.cs diff --git a/Bots/Instructions/BasicInstructions.cs b/Bots/Instructions/BasicInstructions.cs new file mode 100644 index 000000000..b33efcd1e --- /dev/null +++ b/Bots/Instructions/BasicInstructions.cs @@ -0,0 +1,23 @@ +/* + Copyright 2010 MCSharp team (Modified for use with MCZall/MCLawl/MCGalaxy) + + Dual-licensed under the Educational Community License, Version 2.0 and + the GNU General Public License, Version 3 (the "Licenses"); you may + not use this file except in compliance with the Licenses. You may + obtain a copy of the Licenses at + + http://www.opensource.org/licenses/ecl2.php + http://www.gnu.org/licenses/gpl-3.0.html + + Unless required by applicable law or agreed to in writing, + software distributed under the Licenses are distributed on an "AS IS" + BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express + or implied. See the Licenses for the specific language governing + permissions and limitations under the Licenses. + */ +using System; +using System.Collections.Generic; +using System.IO; + +namespace MCGalaxy.Bots { +} diff --git a/Bots/Instructions/ComplexInstructions.cs b/Bots/Instructions/ComplexInstructions.cs new file mode 100644 index 000000000..b33efcd1e --- /dev/null +++ b/Bots/Instructions/ComplexInstructions.cs @@ -0,0 +1,23 @@ +/* + Copyright 2010 MCSharp team (Modified for use with MCZall/MCLawl/MCGalaxy) + + Dual-licensed under the Educational Community License, Version 2.0 and + the GNU General Public License, Version 3 (the "Licenses"); you may + not use this file except in compliance with the Licenses. You may + obtain a copy of the Licenses at + + http://www.opensource.org/licenses/ecl2.php + http://www.gnu.org/licenses/gpl-3.0.html + + Unless required by applicable law or agreed to in writing, + software distributed under the Licenses are distributed on an "AS IS" + BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express + or implied. See the Licenses for the specific language governing + permissions and limitations under the Licenses. + */ +using System; +using System.Collections.Generic; +using System.IO; + +namespace MCGalaxy.Bots { +} diff --git a/Bots/Instructions/Instruction.cs b/Bots/Instructions/Instruction.cs new file mode 100644 index 000000000..cf2b8a0a9 --- /dev/null +++ b/Bots/Instructions/Instruction.cs @@ -0,0 +1,45 @@ +/* + Copyright 2010 MCSharp team (Modified for use with MCZall/MCLawl/MCGalaxy) + + Dual-licensed under the Educational Community License, Version 2.0 and + the GNU General Public License, Version 3 (the "Licenses"); you may + not use this file except in compliance with the Licenses. You may + obtain a copy of the Licenses at + + http://www.opensource.org/licenses/ecl2.php + http://www.gnu.org/licenses/gpl-3.0.html + + Unless required by applicable law or agreed to in writing, + software distributed under the Licenses are distributed on an "AS IS" + BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express + or implied. See the Licenses for the specific language governing + permissions and limitations under the Licenses. + */ +using System; +using System.Collections.Generic; +using System.IO; + +namespace MCGalaxy.Bots { + + /// Represents an action that a bot will perform + public abstract class Instruction { + + /// Gets the identifying name for this instruction. + public abstract string Name { get; } + + /// Performs a step for this instruction. + /// true if the instruction has finished, and that the + /// bot should proceed to execute the next instruction. + public abstract bool Execute(PlayerBot bot, InstructionData data); + + /// Parses the given line which contains the metadata for this instruction. + public abstract InstructionData Parse(string[] args); + } + + public struct InstructionData { + public string type, newscript; + public int seconds, rotspeed; + public ushort x, y, z; + public byte rotx, roty; + } +} diff --git a/Bots/PlayerBot.cs b/Bots/PlayerBot.cs index 9a6a5c233..6686bb86f 100644 --- a/Bots/PlayerBot.cs +++ b/Bots/PlayerBot.cs @@ -41,9 +41,8 @@ namespace MCGalaxy { public int cur = 0; public int countdown = 0; public bool nodUp = false; - public List Waypoints = new List(); - public struct Pos { public string type, newscript; public int seconds, rotspeed; public ushort x, y, z; public byte rotx, roty; } - + public List Waypoints = new List(); + public ushort[] pos = new ushort[3], oldpos = new ushort[3], foundPos = new ushort[3]; public byte[] rot = new byte[2], oldrot = new byte[2]; public bool movement = false; diff --git a/Bots/ScriptFile.cs b/Bots/ScriptFile.cs index be5917ccf..da3b1e601 100644 --- a/Bots/ScriptFile.cs +++ b/Bots/ScriptFile.cs @@ -27,7 +27,7 @@ namespace MCGalaxy.Bots { string[] codes = File.ReadAllLines(file); if (codes[0] != "#Version 2") { Player.Message(p, "Invalid file version. Remake"); return false; } - PlayerBot.Pos newPos = new PlayerBot.Pos(); + PlayerBot.InstructionData newPos = new PlayerBot.InstructionData(); try { bot.Waypoints.Clear(); } catch { } bot.cur = 0; bot.countdown = 0; bot.movementSpeed = 3; diff --git a/MCGalaxy_.csproj b/MCGalaxy_.csproj index ef910318f..d4e721ce2 100644 --- a/MCGalaxy_.csproj +++ b/MCGalaxy_.csproj @@ -112,6 +112,9 @@ + + + @@ -690,6 +693,7 @@ +