protected string EvalStatic(string input, out string result)
    {
        result = input;

        // Evaluate Labels
        Regex           labelPattern = new Regex(@"\|(" + P.DATA + @")\|");
        MatchCollection matches      = labelPattern.Matches(input);

        foreach (Match label in matches)
        {
            // Validate label
            string label_lower = label.Groups[1].Value.ToLower();
            double value       = 0;
            if (!player.GetStatic().TryGetValue(label_lower, out value))
            {
                return("Static address '" + label.Value + "' not found");
            }

            // Substitute label
            int pos = input.IndexOf(label.Value);
            input = input.Remove(pos, label.Value.Length);
            input = input.Insert(pos, AlphaNumeral.DblToString(value));
        }

        result = input;
        return(null);
    }
    protected void ConnectCallback(NodeScript node, string input, int sourceInstruction, bool success)
    {
        if (!success)
        {
            player.PrintToConsole("Connection attempt failed to send");
            return;
        }

        Regex pattern = new Regex(@"^(" + P.DATA + @")\s+(" + P.INT + @")");
        Match match   = pattern.Match(input);

        // Format
        // XXX: Add option to force Connect ignoring safe mode
        string address = match.Groups[1].Value;
        double d_address;

        AlphaNumeral.StringToDbl(address, out d_address);

        NodeScript targetNode = NodeManager.GetNode(d_address, true);

        /* XXX:
         * if( targetNode == null ) {
         *      player.connectedNode = null;
         *      PacketGraphicScript packet = PacketGraphicManager.GetPacket();
         *      player.cameraFocus.MoveTo();
         * }*/

        // Connect to new Node
        player.connectedNode = targetNode;

        // Camera pan to new Node
        player.cameraFocus.MoveTo(NodeGraphicManager.GetGraphic(targetNode),
                                  GameManager.gameOptions.packetTravelTime);
    }
    private string ReadConsoleCommand(string input, out bool success)
    {
        success = false;

        string[] cells = input.Split(' ');

        double d_input;

        if (!AlphaNumeral.StringToDbl(cells[1], out d_input))
        {
            return("'" + cells[1] + "' invalid number format");
        }

        // Find player
        PlayerScript player = GameManager.FindPlayerAtNode(d_input, instruction.GetNode());

        if (player == null)
        {
            return("Console '" + cells[1] + "' not found");
        }

        player.timeLastRead = Time.time;
        // Move command into queue
        if (player.commandQueue.Count > 0)
        {
            EnqueuedCommand command = player.commandQueue.Dequeue();
            command.sourceInstruction = instruction.GetSource();
            instruction.GetNode().commandQueue.Enqueue(command);
        }

        // XXX: Unsure if 'readconsole' should be enqueued as a command itself first
        instruction.EnqueueNextInstruction();
        success = true;
        return(null);
    }
Beispiel #4
0
    public string SetContent(int idx, double value)
    {
        if (idx < 0 || idx >= GameManager.gameOptions.memoryCellCount)
        {
            return("subIndex out of bounds");
        }

        // Interpret
        cells[idx].value = value;
        if (value.ToString().Length <= GameManager.gameOptions.dataLength)
        {
            cells[idx].isBase26 = false;
            cells[idx].content  = value.ToString();
        }
        else
        {
            // Number too large = switch to base-26
            cells[idx].isBase26 = true;
            string converted = AlphaNumeral.DblToString(value);
            if (converted.Length > GameManager.gameOptions.dataLength)
            {
                return("'" + converted + "' number larger than data size");
            }
            cells[idx].content = converted;
        }

        return(null);
    }
Beispiel #5
0
 public MemoryBlock()
 {
     cells = new MemoryCell[GameManager.gameOptions.memoryCellCount];
     for (int i = 0; i < cells.Length; i++)
     {
         SetContent(i, AlphaNumeral.RandomDouble());
     }
 }
    // STATIC
    public static double GenerateId()
    {
        double id;

        do
        {
            id = AlphaNumeral.RandomDouble(0, int.MaxValue);
        } while(GameManager.GetConsoles().ContainsKey(id));

        return(id);
    }
    protected string ZoomCommand(string input, out bool success)
    {
        success = false;

        int result;

        if (!AlphaNumeral.StringToInt(input, out result))
        {
            return("'" + input + "' invalid number format");
        }

        player.cameraFocus.SetDistance(result);
        success = true;
        return("Camera Zoom set to " + input);
    }
    protected string SetFocusTimeCommand(string input, out bool success)
    {
        success = false;

        // Evaluate Input
        int result;

        if (!AlphaNumeral.StringToInt(input, out result))
        {
            return("'" + input + "' not a valid number format");
        }

        // Set Speed
        player.cameraFocus.defaultMoveDuration = result;
        success = true;
        return("Focus time set to: " + input);
    }
    public string Interpret(EnqueuedInstruction in_instruction)
    {
        instruction = in_instruction;
        MemoryBlock memoryBlock = instruction.GetNode().GetMemory(instruction.GetSource());
        double      in_command  = memoryBlock.GetCell(0).value;

        // Interpret command
        // XXX: Comparing using values instead of strings to guarantee interpretation
        //		Will require a better setup
        Command cmd = null;

        //Debug.Log("IN: " + in_command);
        foreach (string commandString in commands.Keys)
        {
            double commandValue;
            AlphaNumeral.StringToDbl(commandString, out commandValue);

            //Debug.Log("CMD: " + commandString);
            //Debug.Log("VAL: " + commandValue);

            if (in_command == commandValue)
            {
                cmd = commands[commandString];
                break;
            }
        }
        if (cmd == null)
        {
            return("Commands '" + memoryBlock.GetCell(0).content + "' not found");
        }

        // Gather 'input' string from MemoryBlock contents
        string input = "";

        for (int i = 0; i < GameManager.gameOptions.memoryCellCount; i++)
        {
            input += memoryBlock.GetCell(i).content + " ";
        }

        bool   success;
        string output = cmd(input, out success);

        instruction = null;
        return(output);
    }
    protected string SetFocusSpinCommand(string input, out bool success)
    {
        success = false;

        // Short hand zero rotate
        if (input.Length == 0)
        {
            player.cameraFocus.spin = Vector3.zero;
            return("Camera spin stopped");
        }

        Regex           pattern = new Regex(@"\G(" + P.FLOAT + @")\s*");
        MatchCollection matches = pattern.Matches(input);

        if (matches.Count == 0)
        {
            return("'" + input + "' invalid rotation format");
        }

        float[] values = { 0, 0, 0 };
        int     i      = 0;

        foreach (Match match in matches)
        {
            string number = match.Groups[1].Value;
            int    result;
            if (!AlphaNumeral.StringToInt(number, out result))
            {
                return("'" + result + "' invalid number format");
            }

            values[i++] = result;
            if (i >= 3)
            {
                break;
            }
        }

        Vector3 newSpin = new Vector3(values[1] / 100f, values[0] / 100f, values[2] / 100f);

        player.cameraFocus.spin = newSpin;
        success = true;
        return("Camera spin set to: ( " + values[0] + " " + values[1] + " " + values[2] + " )");
    }
Beispiel #11
0
    public string SetContent(int idx, string content)
    {
        if (idx < 0 || idx >= GameManager.gameOptions.memoryCellCount)
        {
            return("subIndex out of bounds");
        }

        // XXX: The used symbols for modifiers should be stored somewhere else
        if (content[0] == '*')
        {
            cells[idx].indirect = true;
            content             = content.Substring(1);
        }
        else
        {
            cells[idx].indirect = false;
        }

        // Set new value of cell
        double value;

        if (!AlphaNumeral.StringToDbl(content, out value))
        {
            return("'" + content + "' invalid number format");
        }

        // Set content
        if (content.Length <= GameManager.gameOptions.dataLength)
        {
            // Content fits = explicit
            cells[idx].value = value;
            cells[idx].ExplicitSetContent(content);
        }
        else
        {
            // Content does not fit = convert
            return(SetContent(idx, value));
        }

        return(null);
    }
    /*protected string DownloadCommand( string input, out bool success )
     * {
     *      success = false;
     *
     *      // Parse
     *      Regex pattern = new Regex(@"^(" + P.INT + @")\s+(" + P.INT + @")\s+(.*)");
     *      Match match = pattern.Match(input);
     *      if( !match.Success ) {
     *              return "'" + input + "' invalid Download command format";
     *      }
     *
     *      // Validate
     *      string index = match.Groups[1].Value;
     *      int i_index;
     *      int subIndex;
     *      string error = localNode.ParseMemoryIndex(index, out i_index, out subIndex);
     *      if( error != null ) {
     *              return error;
     *      }
     *
     *      string count = match.Groups[2].Value;
     *      int i_count;
     *      bool b = AlphaNumeral.StringToInt(count, out i_count);
     *      if( !b ) {
     *              return "'" + count + "' in '" + input + "' invalid number format";
     *      }
     *
     *      string fileName = match.Groups[3].Value;
     *
     *      // Gather Data
     *      string[] data = new string[i_count];
     *      for( int i=0; i < i_count; i++ ) {
     *              int idx = (i_index + i) % GameManager.gameOptions.nodeMemoryLength;
     *              Memory memory = localNode.GetMemory(idx);
     *              data[i] = "[" + localNode.GetLabel(idx) + "]" + " " + (memory.isData?"d":"i") + " " + memory.contents;
     *      }
     *
     *      // Write to file
     *      error = ClusterManager.SaveProgram(fileName, data);
     *      if( error != null ) {
     *              return error;
     *      }
     *
     *      success = true;
     *      return "Downloading program...";
     * }
     * protected string UploadCommand( string input, out bool success )
     * {
     *      success = false;
     *
     *      // Parse
     *      Regex pattern = new Regex(@"^(" + P.INDEX + @")\s+(.*)");
     *      Match match = pattern.Match(input);
     *      if( !match.Success ) {
     *              return "'" + input + "' invalid Upload command format";
     *      }
     *
     *      // Validate
     *      string index = match.Groups[1].Value;
     *      int i_index;
     *      string error = localNode.ParseMemoryIndex(index, out i_index);
     *      if( error != null ) {
     *              return error;
     *      }
     *
     *      string fileName = match.Groups[2].Value;
     *
     *      // Gather Data
     *      string[] data;
     *      error = ClusterManager.LoadProgram(fileName, out data);
     *      if( error != null ) {
     *              return error;
     *      }
     *
     *      // Parse data lines
     *      Regex dataPattern = new Regex(@"^[(" + P.LABEL + @")]\s+(" + P.INDEX + @")\s+(.*)");
     *      for( int i=0; i < data.Length; i++ ) {
     *              Match dataMatch = dataPattern.Match(data[i]);
     *              if( !dataMatch.Success ) {
     *                      return "'" + data[i] + "' invalid data format";
     *              }
     *              string dataLabel = dataMatch.Groups[1].Value;
     *              string dataIndex = dataMatch.Groups[2].Value;
     *              string dataContent = dataMatch.Groups[3].Value;
     *
     *              // Calc index
     *              int i_dataIndex;
     *              if( !int.TryParse(dataIndex, out i_dataIndex) ) {
     *                      return "'" + dataIndex + "' in '" + data[i] + "' invalid number format";
     *              }
     *              int idx = (i_index + i_dataIndex) % GameManager.gameOptions.nodeMemoryLength;
     *
     *              // Apply data to node memory
     *              localNode.SetMemory(idx, dataContent);
     *              localNode.AddLabel(idx, dataLabel);
     *      }
     *
     *      success = true;
     *      return "Uploading program...";
     * }
     * protected string SaveKitCommand( string input, out bool success )
     * {
     *      success = false;
     *
     *      // Collect all Memory
     *      string[] data = new string[GameManager.gameOptions.nodeMemoryLength];
     *      for( int i=0; i < data.Length; i++ ) {
     *              Memory memory = localNode.GetMemory(i);
     *              data[i] = "[" + localNode.GetLabel(i) + "]" + " " + (memory.isData?"d":"i") + " " + memory.contents;
     *      }
     *
     *      // Write to file
     *      string error = ClusterManager.SaveProgram(input, data);
     *      if( error != null ) {
     *              return error;
     *      }
     *
     *      success = true;
     *      return "Saving kit...";
     * }*/

    protected string Connect(string input, bool safe, out bool success)
    {
        success = false;

        // Parse
        Regex pattern = new Regex(@"^(" + P.DATA + @")\s+(" + P.INT + @")");
        Match match   = pattern.Match(input);

        if (!match.Success)
        {
            return("'" + input + "' invalid connect format");
        }

        // Format
        // XXX: Add option to force Connect ignoring safe mode
        string address = match.Groups[1].Value;
        double d_address;

        if (!AlphaNumeral.StringToDbl(address, out d_address))
        {
            return("'" + address + "' in '" + input + "' invalid number format");
        }

        if (safe)
        {
            if (!NodeGraphicManager.NodeIsVisible(d_address))
            {
                return("Safe Mode: Unknown Node. Use connectforce to force.");
            }
        }

        string index = match.Groups[2].Value;

        // Enqueue send exec command to new node to activate the new readconsole
        string sendInput = address + " exec " + index;

        player.commandQueue.Enqueue(new EnqueuedCommand(SendAction, sendInput, 0, ConnectCallback));

        success = true;
        return("Connecting...");
    }
Beispiel #13
0
    public static double GenerateAddress()
    {
        // Randomize address string based on AddressFormat
        string s_address = GameManager.GetAddressFormat();

        for (int i = 0; i < s_address.Length; i++)
        {
            if (s_address[i] == '*')
            {
                int rand = UnityEngine.Random.Range(0, CharSets.ALPHA_LOWER.Length);
                s_address = s_address.Remove(i, 1);
                s_address = s_address.Insert(i, CharSets.ALPHA_LOWER[rand].ToString());
            }
        }
        // Convert to number
        double address = 0;

        AlphaNumeral.StringToDbl(s_address, out address);

        return(address);
    }
Beispiel #14
0
    string GetActiveCommand(string input, out bool success)
    {
        success = true;
        // XXX: consider moving logic to NodeManager
        Dictionary <double, NodeScript> nodes = NodeManager.GetNodes();

        double address = 0;

        int rand = UnityEngine.Random.Range(0, nodes.Count);
        int i    = 0;

        foreach (KeyValuePair <double, NodeScript> nodePair in nodes)
        {
            address = nodePair.Key;
            if (i == rand)
            {
                break;
            }
            i++;
        }

        return(AlphaNumeral.DblToString(address));
    }
    protected string SetFocusRotateCommand(string input, out bool success)
    {
        success = false;

        Regex           pattern = new Regex(@"\G(" + P.FLOAT + @")\s*");
        MatchCollection matches = pattern.Matches(input);

        if (matches.Count == 0)
        {
            return("'" + input + "' invalid rotation format");
        }

        float[] values = { 0, 0, 0 };
        int     i      = 0;

        foreach (Match match in matches)
        {
            string number = match.Groups[1].Value;
            int    result;
            if (!AlphaNumeral.StringToInt(number, out result))
            {
                return("'" + result + "' invalid number format");
            }

            values[i++] = result;
            if (i >= 3)
            {
                break;
            }
        }

        Vector3 rotate = new Vector3(values[1], values[0], values[2]);

        player.cameraFocus.SetRotation(rotate);
        success = true;
        return("Rotating camera...");
    }
 public string GetIdString()
 {
     return(AlphaNumeral.DblToString(id));
 }
Beispiel #17
0
 string GetAnyCommand(string input, out bool success)
 {
     success = true;
     return(AlphaNumeral.DblToString(NodeManager.GetRandomAddress()));
 }