Exemple #1
0
    public void Flee()
    {
        Quaternion turn = Quaternion.FromToRotation(Vector3.forward, own_ship.Position);

        movement_quack.PushFront(new AIMouvementCommand [] {
            AIMouvementCommand.Turn(turn, own_ship, true),
            AIMouvementCommand.EngineAccelerate(own_ship.Position * 100, own_ship)
        });
    }
Exemple #2
0
 public void Thrust(Vector3 delta_v, bool prioritize = false)
 {
     if (prioritize)
     {
         movement_quack.PushFront(AIMouvementCommand.EngineAccelerate(delta_v, own_ship));
     }
     else
     {
         movement_quack.PushBack(AIMouvementCommand.EngineAccelerate(delta_v, own_ship));
     }
 }
Exemple #3
0
    /// <summary> Matches Velocity with target </summary>
    /// <param name="tg"> The concerned target </param>
    public void MatchVelocity(Target tg)
    {
        Vector3 d_v = tg.Velocity - own_ship.Velocity;

        if (d_v.sqrMagnitude > 4)
        {
            Quaternion turn = Quaternion.Inverse(own_ship.Orientation) * Quaternion.FromToRotation(Vector3.forward, d_v);
            movement_quack.PushBack(AIMouvementCommand.Turn(turn, own_ship));
            movement_quack.PushBack(AIMouvementCommand.EngineAccelerate(d_v, own_ship));
        }
        else
        {
            movement_quack.PushBack(AIMouvementCommand.RCSAccelerate(d_v, own_ship));
        }
    }
Exemple #4
0
    public void Point2Command(int code)
    {
        Quaternion turn = Quaternion.identity;

        switch (code)
        {
        case -3:
            //TG vel -
            turn = Quaternion.FromToRotation(own_ship.Transform.forward, own_ship.Velocity - own_ship.Target.Velocity);
            break;

        case -2:
            //TG -
            // In Progress
            movement_quack.PushBack(AIMouvementCommand.StayLocked(double.PositiveInfinity, own_ship, own_ship.Target));
            break;

        case -1:
            //Vel -
            turn = Quaternion.FromToRotation(own_ship.Transform.forward, -SceneGlobals.ReferenceSystem.RelativeVelocity(own_ship.Velocity));
            break;

        case 1:
            //Vel +
            turn = Quaternion.FromToRotation(own_ship.Transform.forward, SceneGlobals.ReferenceSystem.RelativeVelocity(own_ship.Velocity));
            break;

        case 2:
            //TG +
            movement_quack.PushBack(AIMouvementCommand.StayLocked(double.PositiveInfinity, own_ship, own_ship.Target));
            return;

        case 3:
            //TG Vel +
            turn = Quaternion.FromToRotation(own_ship.Transform.forward, own_ship.Target.Velocity - own_ship.Velocity);
            break;

        case 4:
            // Cancel (same as idle)
            Idle();
            return;

        default:
            return;
        }
        movement_quack.PushBack(AIMouvementCommand.Turn(turn, own_ship));
    }
Exemple #5
0
    private void Update()
    {
        if (SceneGlobals.Paused)
        {
            return;
        }

        if ((Time.frameCount + ID) % 120 == 0)
        {
            UpdateEnvironnement();
        }

        if (movement_quack.Count > 0)
        {
            AIMouvementCommand curr_Mcommand = movement_quack.Get();
            if (curr_Mcommand.IsAccomplished(own_ship))
            {
                movement_quack.ClearTop();
            }
            else
            {
                curr_Mcommand.Execute(ref navigator, own_ship);
            }
        }

        action_list.RemoveAll(x => x.IsAccomplished(own_ship));
        foreach (AIActionCommand command in action_list)
        {
            command.Execute(ref navigator, own_ship);
        }

        if (Time.frameCount > 2)
        {
            navigator.Navigate();
        }

        high_level.Update_();
    }
Exemple #6
0
    public string Execute(string command)
    {
        string [] arguments = command.Split(' ');
        switch (arguments [0])
        {
        case "turn":
            Vector3 vec = new Vector3(float.Parse(arguments[1]),
                                      float.Parse(arguments[2]),
                                      float.Parse(arguments[3]));
            if (arguments.Length >= 5 && arguments [4] == "F")
            {
                movement_quack.PushFront(AIMouvementCommand.Turn(Quaternion.Euler(vec), own_ship));
            }
            else
            {
                movement_quack.PushBack(AIMouvementCommand.Turn(Quaternion.Euler(vec), own_ship));
            }
            return(string.Format("Turn planned sucessfully ({0:0.00}, {1:0.00}, {2:0.00})", vec.x, vec.y, vec.z));

        case "rcs":
            Vector3 vec1 = new Vector3(float.Parse(arguments[1]),
                                       float.Parse(arguments[2]),
                                       float.Parse(arguments[3]));
            RCSThrust(vec1, arguments.Length >= 5 && arguments [4] == "F");
            return(string.Format("RCS Acceleration planned sucessfully ({0:0.00}, {1:0.00}, {2:0.00})", vec1.x, vec1.y, vec1.z));

        case "main":
            Vector3 vec2 = new Vector3(float.Parse(arguments[1]),
                                       float.Parse(arguments[2]),
                                       float.Parse(arguments[3]));
            Thrust(vec2, arguments.Length >= 5 && arguments [4] == "F");
            return(string.Format("Engine Acceleration planned sucessfully ({0:0.00}, {1:0.00}, {2:0.00})", vec2.x, vec2.y, vec2.z));

        default:
            return(string.Format("Command {0} not known (nms intern)", arguments [0]));
        }
    }
Exemple #7
0
    /// <summary> Matches velocities with target the closest to target as possible </summary>
    /// <param name="tg"> The concerned target </param>
    public void MatchVelocityNearTarget(Target tg)
    {
        Vector3 d_v = tg.Velocity - own_ship.Velocity;

        if (Vector3.Dot(own_ship.Position - tg.Position, d_v) < 0)
        {
            MatchVelocity(tg);  //				->	 ->
            return;             // has to be catching up -> Δx · Δv > 0
        }
        float relative_velocity = d_v.magnitude;
        float acceleration      = own_ship.MaxAcceleration;

        if (relative_velocity > 4)
        {
            float breaking_distance = .5f * d_v.sqrMagnitude / acceleration;
            float full_distance     = Vector3.Project(tg.Position - own_ship.Position, d_v).magnitude;

            float plus_dist = 0;
            if (!tg.virt_ship)
            {
                plus_dist = tg.Ship.radius;
            }

            Quaternion turn = Quaternion.FromToRotation(Vector3.forward, d_v);
            movement_quack.PushBack(AIMouvementCommand.Turn(turn, own_ship, true));
            movement_quack.PushBack(AIMouvementCommand.HoldOrientation((full_distance - breaking_distance - plus_dist) / relative_velocity, own_ship));
            movement_quack.PushBack(AIMouvementCommand.EngineAccelerate(d_v, own_ship));
        }
        else
        {
            float breaking_time     = relative_velocity / acceleration;
            float breaking_distance = .5f * d_v.sqrMagnitude / acceleration;
            float full_distance     = Vector3.Project(tg.Position - own_ship.Position, d_v).magnitude;

            movement_quack.PushBack(AIMouvementCommand.RCSAccelerate(d_v, own_ship));
        }
    }
Exemple #8
0
 public void Point2(Vector3 direction)
 {
     movement_quack.PushBack(AIMouvementCommand.Turn(Quaternion.FromToRotation(own_ship.Transform.forward, direction), own_ship, true));
 }
Exemple #9
0
 /// <summary> Attacks a given target, giving the Ai full autonomy over movement </summary>
 /// <param name="tg"> The concerned target </param>
 public void Attack(Target tg)
 {
     movement_quack.PushBack(AIMouvementCommand.StayLocked(double.PositiveInfinity, own_ship, tg));
     action_list.Add(AIActionCommand.FireMain(tg));
 }
Exemple #10
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;
                }
            }
        }