Esempio n. 1
0
    public void Update_()
    {
        if (target == null | Time.frameCount % 100 == net_id % 100)
        {
            SearchTgt();
        }

        if (turret_aim == null)
        {
            turret_aim = target;
        }

        if (Time.frameCount == 0)
        {
            low_ai.action_list.Add(AIActionCommand.ShootTG(own_ship.TurretGroups[0], turret_aim));
        }

        Execute("ShootFixedOn");
        Execute("ShootFixedOff");
        Execute("ShootMissile");
    }
Esempio n. 2
0
        /// <summary> Takes an input and processes it like a CPU </summary>
        /// <param name="arguments"> The input as a ulong form bytes. For further information see the remarque </param>
        /// <remarks>
        ///		Content of command |	pointers?			\
        ///		[-------------]	 [-----] X V V V			|		X -> float flag : indicates, wheter operations are float operations
        ///		0 0 0 0 0 0 0 0  0 0 0 0 0 0 0 0			|
        ///						 Importance					|
        ///		Content of a								|
        ///		[------------------------------]			|
        ///		0 0 0 0 0 0 0 0  0 0 0 0 0 0 0 0			|
        ///													 >- 64-bit integer (ulong)
        ///		Content of b								|
        ///		[------------------------------]			|
        ///		0 0 0 0 0 0 0 0  0 0 0 0 0 0 0 0			|
        ///													|
        ///		Content of c								|
        ///		[------------------------------]			|
        ///		0 0 0 0 0 0 0 0  0 0 0 0 0 0 0 0			/
        /// </remarks>
        public void Execute(ulong [] code)
        {
            bool running = true;
            var  t0      = DateTime.Now;

            for (int i = 0; running& i < code.Length; i++)
            {
                ulong  arguments = code [i];
                ushort arg3      = (arguments >> 0x30) % 2 == 1 ? ram[(int)((arguments >> 0x00) % 0x10000)] : (ushort)((arguments >> 0x00) % 0x10000);
                ushort arg2      = (arguments >> 0x31) % 2 == 1 ? ram[(int)((arguments >> 0x10) % 0x10000)] : (ushort)((arguments >> 0x10) % 0x10000);
                ushort arg1      = (arguments >> 0x32) % 2 == 1 ? ram[(int)((arguments >> 0x20) % 0x10000)] : (ushort)((arguments >> 0x20) % 0x10000);
                ushort arg0      = (ushort)(arguments >> 0x38);
                //UnityEngine.Debug.LogFormat("{0} -> {1:x}", (OS.AssemblyCommands) arg0, arguments);

                float importance = ((arguments >> 0x34) % 16) / 15f;
                bool  is_float   = (arguments >> 0x33) % 2 == 1;
                switch (arg0)
                {
                // 0x00 - 0x0f: Simple operations
                case 0x00:
                    // NULL - NUL
                    goto ENDCOMMAND;

                case 0x01:
                    // Assign a -> &b || SET
                    ram [arg2] = arg1;
                    goto ENDCOMMAND;

                case 0x02:
                    // End the programm; No arguments || END
                    running = false;
                    goto ENDCOMMAND;

                case 0x03:
                    // Float &a to Integer || F2I
                    ram [arg1] = (ushort)RAM.Short2Float(arg1);
                    goto ENDCOMMAND;

                case 0x04:
                    // Integer &a to float || I2F
                    ram [arg1] = RAM.Float2Short((float)arg1);
                    goto ENDCOMMAND;

                // 0x10 - 0x1f: Simple logic
                case 0x10:
                    // go to line a || JMP
                    i = arg1 - 1;
                    goto ENDCOMMAND;

                case 0x11:
                    // if a == b: go to line c || JEQ
                    if (arg1 == arg2)
                    {
                        i = arg3 - 1;
                    }
                    goto ENDCOMMAND;

                case 0x12:
                    // if a > b: go to line c || JGT
                    if (is_float)
                    {
                        if (arg1 > arg2)
                        {
                            i = arg3 - 1;
                        }
                    }
                    else
                    {
                        if (RAM.Short2Float(arg1) > RAM.Short2Float(arg2))
                        {
                            i = arg3 - 1;
                        }
                    }
                    goto ENDCOMMAND;

                case 0x13:
                    // if a >= b: go to line c || JGE
                    if (is_float)
                    {
                        if (arg1 >= arg2)
                        {
                            i = arg3 - 1;
                        }
                    }
                    else
                    {
                        if (RAM.Short2Float(arg1) >= RAM.Short2Float(arg2))
                        {
                            i = arg3 - 1;
                        }
                    }
                    goto ENDCOMMAND;

                // 0x20 - 0x2f: Mathematical operations
                case 0x20:
                    // Addition a + b -> &c || ADD
                    ram [arg3] = is_float ? RAM.Float2Short(RAM.Short2Float(arg1) + RAM.Short2Float(arg2)) : (ushort)(arg1 + arg2);
                    //UnityEngine.Debug.LogFormat("{0} + {1} = {2}", arg1, arg2, is_float ? RAM.Float2Short(RAM.Short2Float(arg1) + RAM.Short2Float(arg2)) : (ushort) (arg1 + arg2));
                    goto ENDCOMMAND;

                case 0x21:
                    // Substraction a - b -> &c || SUB
                    ram [arg3] = is_float ? RAM.Float2Short(RAM.Short2Float(arg1) - RAM.Short2Float(arg2)) : (ushort)(arg1 - arg2);
                    goto ENDCOMMAND;

                case 0x22:
                    // Multiplication a * b -> &c || MUL
                    ram [arg3] = is_float ? RAM.Float2Short(RAM.Short2Float(arg1) * RAM.Short2Float(arg2)) : (ushort)(arg1 * arg2);
                    goto ENDCOMMAND;

                case 0x23:
                    // Integer Division a / b -> &c || DIV
                    ram [arg3] = is_float ? RAM.Float2Short(RAM.Short2Float(arg1) / RAM.Short2Float(arg2)) : (ushort)(arg1 / arg2);
                    goto ENDCOMMAND;

                // 0x40 - 0x4f: console functions
                case 0x40:
                    // Print from &a, length b on console || PRT
                    if (arg1 + arg2 > ram.size)
                    {
                        Error("Buffer overflow", i);
                    }

                    char[] characters = new char[arg2 * 2];
                    for (uint j = 0u; j < arg2; j++)
                    {
                        ushort nums = ram[arg1 + j];
                        characters [2 * j]     = (char)(nums >> 8);
                        characters [2 * j + 1] = (char)(nums % 0x100);
                    }
                    string word = new string(characters);
                    Output += word;
                    goto ENDCOMMAND;

                case 0x41:
                    // Save Input, beginning from a || INP
                    string word_ = Input;
                    if (arg1 + word_.Length / 2 > ram.size)
                    {
                        Error("Buffer overflow", i);
                    }

                    for (uint j = 0u; j < word_.Length; j += 2)
                    {
                        ram [arg0 + j / 2] = (ushort)(word_ [(int)j] + word_ [(int)j] << 8);
                    }
                    goto ENDCOMMAND;

                case 0x42:
                    // ClearScreen; No arguments || CLS
                    Output = string.Empty;
                    goto ENDCOMMAND;

                // 0x80 - 0x8f : Movement Control
                case 0x80:
                    // Turn with RCS: euler angles: (a / 100, b / 100, c / 100)
                    AI.ApplyTurn(new UnityEngine.Vector3(RAM.Short2Float(arg1), RAM.Short2Float(arg2), RAM.Short2Float(arg3)), importance);
                    goto ENDCOMMAND;

                case 0x81:
                    // Thrust with RCS: Δv-vector: (a / 100, b / 100, c / 100)
                    AI.RCSThrust(new UnityEngine.Vector3(RAM.Short2Float(arg1), RAM.Short2Float(arg2), RAM.Short2Float(arg3)));
                    goto ENDCOMMAND;

                case 0x82:
                    // Engine Acceleration: Δv-vector: (a / 100, b / 100, c / 100)
                    AI.Thrust(new UnityEngine.Vector3(RAM.Short2Float(arg1), RAM.Short2Float(arg2), RAM.Short2Float(arg3)));
                    goto ENDCOMMAND;

                case 0x83:
                    // Hold Orientation: time: a / 10 seconds
                    AI.movement_quack.PushBack(AIMouvementCommand.HoldOrientation(RAM.Short2Float(arg1), ship));
                    goto ENDCOMMAND;

                case 0x84:
                    // Lock target: time: a / 10
                    AI.movement_quack.PushBack(AIMouvementCommand.HoldOrientation(RAM.Short2Float(arg1), ship));
                    goto ENDCOMMAND;

                // 0x90 - 0x9f : Ship actions
                case 0x90:
                    // Shoot turretgroup number a at aim
                    AI.action_list.Add(AIActionCommand.ShootTG(ship.TurretGroups[arg1], ship.TurretAim));
                    goto ENDCOMMAND;

                case 0x91:
                    // Shoot fixed weapon number a at euler_angle rotation (b, c, 0)
                    AI.action_list.Add(AIActionCommand.FireMain(ship.TurretAim));
                    goto ENDCOMMAND;

                case 0x92:
                    // Shoot missile at target_id a
                    goto ENDCOMMAND;

                // 0xa0 - 0x9f : Complex/Ship related general commands
                case 0xa0:
                    // Wait for a / 10 seconds
                    AI.movement_quack.PushBack(AIMouvementCommand.Wait(RAM.Short2Float(arg1)));
                    goto ENDCOMMAND;
                }
ENDCOMMAND:
                if ((DateTime.Now - t0).Seconds > 3)
                {
                    DeveloppmentTools.Log("Simulated CPU processor jumpout");
                    return;
                }
            }
        }