Exemplo n.º 1
0
 public void DoOrient(VectorWrapper vw, Vector3 target)
 {
     ResetVector(vw);
     ScaleVector(vw, target);
     RotateAndPositionVector(vw, target);
     SetLabel(vw, target);
     SetCamera(vw, cam);
 }
Exemplo n.º 2
0
        private IasteroidIGCWrapper GetAsteroidClosestToClusterCenter(IclusterIGCWrapper cluster)
        {
            VectorWrapper centerPoint = new VectorWrapper(0, 0, 0);

            return(cluster.GetAsteroids()
                   .Where(p => p.GetName().StartsWith("a") == true)
                   .OrderBy(p => (centerPoint - p.GetPosition()).LengthSquared())
                   .FirstOrDefault());
        }
Exemplo n.º 3
0
    public void Setup(VectorWrapper vw)
    {
        VectorWrapper = vw;
        var vec = vw.Vec;

        label.text     = string.Format("{0}; {1}; {2}", vec.x, vec.y, vec.z);
        magnitude.text = string.Format("|v| = {0}", Vector3.Magnitude(vec));
        SelectState    = SelectionState.None;
        UpdateSelectionMarker();
    }
Exemplo n.º 4
0
    public void Add(VectorWrapper vw)
    {
        var widget = UnityEngine.Object.Instantiate <VectorWidget>(widgetTemplate);

        widget.Setup(vw);
        widget.gameObject.transform.SetParent(scrollRectContents, false);
        widget.gameObject.transform.localScale = Vector3.one;
        widget.OnSelectionToggleRequested     += HandleSelectionToggleRequested;

        _inventory.Add(widget);
    }
Exemplo n.º 5
0
        public void TestVectorRangeBuilt()
        {
            string comparisonMethodName = "Contains";
            Type   rootType             = typeof(VectorRange);
            Type   argType = typeof(Vector2);

            VectorWrapper             wrapper      = new VectorWrapper(new Vector2(1, 1));
            VectorRangeWrapperWrapper rangeWrapper = new VectorRangeWrapperWrapper(new VectorRangeWrapper(VectorRange.Any));

            var     condAtom2        = new ConditionAtom(() => rangeWrapper.wrapper.range.Contains(wrapper.vec), false);
            dynamic rangeWrapper_dyn = rangeWrapper;
            dynamic wrapper_dyn      = wrapper;
            var     condAtom3        = new ConditionAtom(() => rangeWrapper_dyn.wrapper.range.Contains(wrapper_dyn.vec), false);

            Console.WriteLine(typeof(Vector2).Name);
            var schema = GetWrapperConditionSchema();

            Dictionary <string, object> objDictionary = new Dictionary <string, object>();

            objDictionary.Add("wrapper", rangeWrapper);
            objDictionary.Add("vecWrapper", wrapper);

            var condAtom = new ConditionFactory(objDictionary).Build(schema);

            Assert.True(condAtom.Met());
            condAtom2.Met();
            condAtom3.Met();

            Stopwatch watch = new Stopwatch();

            watch.Start();
            for (int i = 0; i < 1000000; i++)
            {
                condAtom.Met();
            }
            watch.Stop();
            Console.WriteLine("Elapsed milliseconds for dynamically compiled method: " + watch.ElapsedMilliseconds);
            watch.Reset();
            watch.Start();
            for (int i = 0; i < 1000000; i++)
            {
                condAtom2.Met();
            }
            watch.Stop();
            Console.WriteLine("Elapsed milliseconds for hard-coded delegate: " + watch.ElapsedMilliseconds);
            watch.Reset();
            watch.Start();
            for (int i = 0; i < 1000000; i++)
            {
                condAtom3.Met();
            }
            watch.Stop();
            Console.WriteLine("Elapsed milliseconds for dynamically-typed, hard-coded delegate: " + watch.ElapsedMilliseconds);
        }
Exemplo n.º 6
0
    /// <summary>
    /// Helper function that draws a field of 3 floats.
    /// </summary>

    static VectorWrapper DrawVector3(Vector3 value, Axes shown, Axes editable)
    {
        GUILayoutOption opt    = GUILayout.MinWidth(30f);
        VectorWrapper   update = new VectorWrapper()
        {
            value = value
        };

        update.SetX(DrawFloatField("X", value.x, ((shown & Axes.X) != Axes.None), ((editable & Axes.X) != Axes.None), opt));
        update.SetY(DrawFloatField("Y", value.y, ((shown & Axes.Y) != Axes.None), ((editable & Axes.Y) != Axes.None), opt));
        update.SetZ(DrawFloatField("Z", value.z, ((shown & Axes.Z) != Axes.None), ((editable & Axes.Z) != Axes.None), opt));

        return(update);
    }
Exemplo n.º 7
0
        public ISolution Run(IMatrix <int> matrix)
        {
            int[] x = new int[M - 1];
            VectorWrapper <int> v = new VectorWrapper <int>(matrix);
            int n = v.N;

            double w = (double)LoadBalancing.Utilities.Sum(v) / M;

            int[] p = new int[n];
            p[0] = v[0];

            for (int i = 1; i < n; i++)
            {
                p[i] = p[i - 1] + v[i];
            }

            for (int i = 0; i < M - 1; i++)
            {
                double point = w * (i + 1);

                if (point < p[0])
                {
                    x[i] = 1;
                }

                if (p[n - 1] <= point)
                {
                    x[i] = n - 1;
                }

                for (int j = 0; j < n - 1; j++)
                {
                    if (p[j] <= point && point < p[j + 1])
                    {
                        if (point - p[j] < p[j + 1] - point)
                        {
                            x[i] = j + 1;
                        }
                        else
                        {
                            x[i] = j + 2;
                        }

                        break;
                    }
                }
            }

            return(new Solution1D(x));
        }
Exemplo n.º 8
0
    /// <summary>
    /// Draw the inspector widget.
    /// </summary>

    public override void OnInspectorGUI()
    {
        Transform trans = target as Transform;

        EditorGUIUtility.LookLikeControls(15f);

        serializedObject.Update();

        // For clarity purposes, if there is a widget, we want to disable rotation around X and Y, and disable scaling on the Z.
        bool isWidget = false;
        bool isStatic = false;

        foreach (Object obj in serializedObject.targetObjects)
        {
            Transform t = obj as Transform;

            if (t != null)
            {
                UIWidget w = t.GetComponent <UIWidget>();

                if (w != null)
                {
                    isWidget = true;

                    if (Application.isPlaying)
                    {
                        PrefabType type = PrefabUtility.GetPrefabType(w.gameObject);
                        if (type != PrefabType.Prefab)
                        {
                            isStatic = (w.panel != null) && w.panel.widgetsAreStatic;
                        }
                    }
                    break;
                }
            }
        }

        // Position
        EditorGUILayout.BeginHorizontal();
        {
            Axes axes = GetMultipleValuesAxes(mPosition);

            if (DrawButton("P", "Reset Position", !isStatic && (axes != Axes.None || IsResetPositionValid(trans)), 20f))
            {
                NGUIEditorTools.RegisterUndo("Reset Position", serializedObject.targetObjects);

                foreach (Object obj in serializedObject.targetObjects)
                {
                    Transform t = obj as Transform;
                    if (t != null)
                    {
                        t.localPosition = Vector3.zero;
                    }
                }
            }

            GUI.changed = false;
            VectorWrapper final = DrawVector3(trans.localPosition, axes, isStatic ? Axes.None : Axes.All);

            if (GUI.changed)
            {
                NGUIEditorTools.RegisterUndo("Reset Position", serializedObject.targetObjects);

                foreach (Object obj in serializedObject.targetObjects)
                {
                    Transform t = obj as Transform;

                    if (t != null)
                    {
                        Vector3 v = t.localPosition;
                        if ((final.axes & Axes.X) != 0)
                        {
                            v.x = final.value.x;
                        }
                        if ((final.axes & Axes.Y) != 0)
                        {
                            v.y = final.value.y;
                        }
                        if ((final.axes & Axes.Z) != 0)
                        {
                            v.z = final.value.z;
                        }
                        t.localPosition = v;
                    }
                }
            }
        }
        EditorGUILayout.EndHorizontal();

        // Rotation
        EditorGUILayout.BeginHorizontal();
        {
            Axes axes = GetMultipleValuesAxes(mRotation);

            if (DrawButton("R", "Reset Rotation", !isStatic && (axes != Axes.None || IsResetRotationValid(trans)), 20f))
            {
                NGUIEditorTools.RegisterUndo("Reset Rotation", serializedObject.targetObjects);

                foreach (Object obj in serializedObject.targetObjects)
                {
                    Transform t = obj as Transform;
                    if (t != null)
                    {
                        t.localRotation = Quaternion.identity;
                    }
                }
            }

            GUI.changed = false;
            VectorWrapper final = DrawVector3(trans.localEulerAngles, axes, isStatic ? Axes.None : (isWidget ? Axes.Z : Axes.All));

            if (GUI.changed)
            {
                NGUIEditorTools.RegisterUndo("Reset Rotation", serializedObject.targetObjects);

                foreach (Object obj in serializedObject.targetObjects)
                {
                    Transform t = obj as Transform;

                    if (t != null)
                    {
                        Vector3 v = t.localEulerAngles;
                        if ((final.axes & Axes.X) != 0)
                        {
                            v.x = final.value.x;
                        }
                        if ((final.axes & Axes.Y) != 0)
                        {
                            v.y = final.value.y;
                        }
                        if ((final.axes & Axes.Z) != 0)
                        {
                            v.z = final.value.z;
                        }
                        t.localEulerAngles = v;
                    }
                }
            }
        }
        EditorGUILayout.EndHorizontal();

        // Scale
        EditorGUILayout.BeginHorizontal();
        {
            Axes axes = GetMultipleValuesAxes(mScale);

            if (DrawButton("S", "Reset Scale", !isStatic && (axes != Axes.None || IsResetScaleValid(trans)), 20f))
            {
                NGUIEditorTools.RegisterUndo("Reset Scale", serializedObject.targetObjects);

                foreach (Object obj in serializedObject.targetObjects)
                {
                    Transform t = obj as Transform;

                    if (t != null)
                    {
                        UIWidget w = t.GetComponent <UIWidget>();
                        if (w != null)
                        {
                            w.MakePixelPerfect();
                        }
                        else
                        {
                            t.localScale = Vector3.one;
                        }
                    }
                }
            }

            GUI.changed = false;
            VectorWrapper final = DrawVector3(trans.localScale, axes, isStatic ? Axes.None : (isWidget ? (Axes.X | Axes.Y) : Axes.All));

            if (GUI.changed)
            {
                NGUIEditorTools.RegisterUndo("Reset Scale", serializedObject.targetObjects);

                foreach (Object obj in serializedObject.targetObjects)
                {
                    Transform t = obj as Transform;

                    if (t != null)
                    {
                        Vector3 v = t.localScale;
                        if ((final.axes & Axes.X) != 0)
                        {
                            v.x = final.value.x;
                        }
                        if ((final.axes & Axes.Y) != 0)
                        {
                            v.y = final.value.y;
                        }
                        if ((final.axes & Axes.Z) != 0)
                        {
                            v.z = final.value.z;
                        }
                        t.localScale = v;
                    }
                }
            }
        }
        EditorGUILayout.EndHorizontal();

        if (isStatic)
        {
            EditorGUILayout.HelpBox("The panel managing this widget has the \"widgets are static\" flag set, so all transform changes will be ignored.", MessageType.Warning);
        }
    }
Exemplo n.º 9
0
 private void RotateAndPositionVector(VectorWrapper vw, Vector3 target)
 {
     vw.vecTransform.SetPositionAndRotation(target / 2f, Quaternion.LookRotation(target, Vector3.up));
 }
Exemplo n.º 10
0
    private void ScaleVector(VectorWrapper vw, Vector3 target)
    {
        var length = target.magnitude;

        vw.vecTransform.localScale = new Vector3(1f, 1f, length / 2f);
    }
Exemplo n.º 11
0
 private void ResetVector(VectorWrapper vw)
 {
     vw.vecTransform.SetPositionAndRotation(Vector3.zero, Quaternion.identity);
     vw.vecTransform.localScale = Vector3.one;
 }
Exemplo n.º 12
0
 private void SetLabel(VectorWrapper vw, Vector3 target)
 {
     vw.SetLabel(target);
 }
Exemplo n.º 13
0
    /// <summary>
    /// Draw the inspector widget.
    /// </summary>

    public override void OnInspectorGUI()
    {
        Transform trans = target as Transform;

        EditorGUIUtility.LookLikeControls(15f);

        serializedObject.Update();

        // For clarity purposes, if there is a widget, we want to disable rotation around X and Y, and disable scaling on the Z.
        bool isWidget = false;

        foreach (Object obj in serializedObject.targetObjects)
        {
            Transform t = obj as Transform;

            if (t != null)
            {
                if (t.GetComponent <UIWidget>() != null)
                {
                    isWidget = true;
                    break;
                }
            }
        }

        // Position
        EditorGUILayout.BeginHorizontal();
        {
            Axes axes = GetMultipleValuesAxes(mPosition);

            if (DrawButton("P", "Reset Position", axes != Axes.None || IsResetPositionValid(trans), 20f))
            {
                NGUIEditorTools.RegisterUndo("Reset Position", serializedObject.targetObjects);

                foreach (Object obj in serializedObject.targetObjects)
                {
                    Transform t = obj as Transform;
                    if (t != null)
                    {
                        t.localPosition = Vector3.zero;
                    }
                }
            }

            GUI.changed = false;
            VectorWrapper final = DrawVector3(trans.localPosition, axes, Axes.All);

            if (GUI.changed)
            {
                NGUIEditorTools.RegisterUndo("Reset Position", serializedObject.targetObjects);

                foreach (Object obj in serializedObject.targetObjects)
                {
                    Transform t = obj as Transform;

                    if (t != null)
                    {
                        Vector3 v = t.localPosition;
                        if ((final.axes & Axes.X) != 0)
                        {
                            v.x = final.value.x;
                        }
                        if ((final.axes & Axes.Y) != 0)
                        {
                            v.y = final.value.y;
                        }
                        if ((final.axes & Axes.Z) != 0)
                        {
                            v.z = final.value.z;
                        }
                        t.localPosition = v;
                    }
                }
            }
        }
        EditorGUILayout.EndHorizontal();

        // Rotation
        EditorGUILayout.BeginHorizontal();
        {
            Axes axes = GetMultipleValuesAxes(mRotation);

            if (DrawButton("R", "Reset Rotation", axes != Axes.None || IsResetRotationValid(trans), 20f))
            {
                NGUIEditorTools.RegisterUndo("Reset Rotation", serializedObject.targetObjects);

                foreach (Object obj in serializedObject.targetObjects)
                {
                    Transform t = obj as Transform;
                    if (t != null)
                    {
                        t.localRotation = Quaternion.identity;
                    }
                }
            }

            GUI.changed = false;
            VectorWrapper final = DrawVector3(trans.localEulerAngles, axes, isWidget ? Axes.Z : Axes.All);

            if (GUI.changed)
            {
                NGUIEditorTools.RegisterUndo("Reset Rotation", serializedObject.targetObjects);

                foreach (Object obj in serializedObject.targetObjects)
                {
                    Transform t = obj as Transform;

                    if (t != null)
                    {
                        Vector3 v = t.localEulerAngles;
                        if ((final.axes & Axes.X) != 0)
                        {
                            v.x = final.value.x;
                        }
                        if ((final.axes & Axes.Y) != 0)
                        {
                            v.y = final.value.y;
                        }
                        if ((final.axes & Axes.Z) != 0)
                        {
                            v.z = final.value.z;
                        }
                        t.localEulerAngles = v;
                    }
                }
            }
        }
        EditorGUILayout.EndHorizontal();

        // Scale
        EditorGUILayout.BeginHorizontal();
        {
            Axes axes = GetMultipleValuesAxes(mScale);

            if (DrawButton("S", "Reset Scale", (axes != Axes.None || IsResetScaleValid(trans)), 20f))
            {
                NGUIEditorTools.RegisterUndo("Reset Scale", serializedObject.targetObjects);

                foreach (Object obj in serializedObject.targetObjects)
                {
                    Transform t = obj as Transform;

                    if (t != null)
                    {
                        UIWidget w = t.GetComponent <UIWidget>();
                        if (w != null)
                        {
                            w.MakePixelPerfect();
                        }
                        else
                        {
                            t.localScale = Vector3.one;
                        }
                    }
                }
            }

            GUI.changed = false;
            VectorWrapper final = DrawVector3(trans.localScale, axes, isWidget ? (Axes.X | Axes.Y) : Axes.All);

            if (GUI.changed)
            {
                NGUIEditorTools.RegisterUndo("Reset Scale", serializedObject.targetObjects);

                foreach (Object obj in serializedObject.targetObjects)
                {
                    Transform t = obj as Transform;

                    if (t != null)
                    {
                        Vector3 v = t.localScale;
                        if ((final.axes & Axes.X) != 0)
                        {
                            v.x = final.value.x;
                        }
                        if ((final.axes & Axes.Y) != 0)
                        {
                            v.y = final.value.y;
                        }
                        if ((final.axes & Axes.Z) != 0)
                        {
                            v.z = final.value.z;
                        }
                        t.localScale = v;
                    }
                }
            }
        }
        EditorGUILayout.EndHorizontal();
    }
Exemplo n.º 14
0
        private void SweepCluster()
        {
            Log("\tSweepCluster()");

            _isSweeping = true;

            var ship            = ClientConnection.GetShip();
            var otherScoutShips = ship.GetCluster().GetShips().Where(p => p.GetObjectID() != ship.GetObjectID() && p.GetBaseHullType().GetName().Contains("Scout") == true);

            var centerPoint  = new VectorWrapper(0, 0, 0);
            var shipPosition = ship.GetPosition();

            var startingPoint          = shipPosition;
            var startingAngleInRadians = shipPosition.AngleInRadians(centerPoint);

            double nextSliceWidth        = (Math.PI * 2 / SweepHopCount);
            double currentAngleInRadians = startingAngleInRadians;

            Task.Run(() =>
            {
                try
                {
                    int currentSweepingScoutCount = GameInfo.IncrementSweepingScoutCount(ship.GetCluster());

                    //bool sweepLeft = currentSweepingScoutCount > 0;

                    _runningTasks++;

                    bool sweepComplete = true;

                    int hopCount            = SweepHopCount;
                    bool hopCountReduced    = false; // Changes to true when a second scout starts sweeping.
                    bool firstSweepingScout = currentSweepingScoutCount == 1;

                    // This is somewhat specific to hihigher, but we will assume that any cluster has an average of 3 warps and a station cluster has 4.
                    // This lets a scout stop sweeping early if all clusters are assumed to be found.
                    int targetWarpCount = 3 + ship.GetCluster().GetStations().Count;

                    for (int i = 1;
                         i < hopCount - 2 &&  // Skip the first hop and the last 2 hops, aelphs won't be that close together.
                         _cancellationTokenSource.IsCancellationRequested == false &&
                         ship.GetCluster().GetWarps().Count < targetWarpCount;        // If we find enough warps, we will consider this cluster scanned. If there are more warp clusters will be covered when the other cluster is discovered from the other side. Otherwise, it's up to the humans!
                         i++)
                    {
                        // If another scout starts sweeping, then reduce the hop count by half so that we get done quicker. The other scout will start sweeping from the other direction.
                        if (hopCountReduced == false && GameInfo.GetSweepingScoutCount(ship.GetCluster()) >= 2)
                        {
                            Log($"\t\tA second scout is also sweeping, reducing the hop count to half.");
                            hopCount = (SweepHopCount / 2) + 3;     // Go a little farther so that the paths overlap. It's the classic pincer manuver!!
                        }

                        if (firstSweepingScout == true)
                        {
                            currentAngleInRadians += nextSliceWidth;
                        }
                        else
                        {
                            currentAngleInRadians -= nextSliceWidth;
                        }

                        VectorWrapper nextPoint = new VectorWrapper((startingPoint - centerPoint).Length() * (float)Math.Cos(currentAngleInRadians), (startingPoint - centerPoint).Length() * (float)Math.Sin(currentAngleInRadians), 0);

                        Log($"\t\tnextPoint: {nextPoint.GetString()}, currentAngleInRadians: {currentAngleInRadians}, sweepHop: {i}, firstSweepingScout: {firstSweepingScout}, target hopCount: {hopCount - 2}");

                        var buoy    = ClientConnection.CreateBuoy((sbyte)BuoyType.c_buoyWaypoint, nextPoint.X(), nextPoint.Y(), nextPoint.Z(), ship.GetCluster().GetObjectID(), true);
                        var command = ship.GetDefaultOrder(buoy);
                        ship.SetCommand((sbyte)CommandType.c_cmdCurrent, buoy, command);
                        ship.SetAutopilot(true);

                        bool reachedWaypoint = false;
                        for (int j = 0; j < 60 * 100 && _cancellationTokenSource.IsCancellationRequested == false; j++)
                        {
                            VectorWrapper difference = nextPoint - ship.GetPosition();

                            if (j % 500 == 0)
                            {
                                Log($"\t\tCurrent distance: {Math.Abs(difference.Length())}, iterations: {j}, {nextPoint.GetString()}, ship velocity: {ship.GetVelocity().Length()}");
                            }

                            if ((nextPoint - ship.GetPosition()).LengthSquared() < Math.Pow(600, 2))
                            {
                                Log($"\t\tReached waypoint: {nextPoint.GetString()}, ship velocity: {ship.GetVelocity().Length()}");
                                reachedWaypoint = true;
                                break;
                            }

                            Thread.Sleep(100);
                        }

                        // We didn't reach the waypoint in one minute. Something went wrong, let's just move on.
                        if (reachedWaypoint == false)
                        {
                            sweepComplete = false;
                            Log("\t\tNo waypoint was found in 120 seconds.");
                            break;
                        }
                    }

                    if (sweepComplete == true)
                    {
                        currentSweepingScoutCount = GameInfo.GetSweepingScoutCount(ship.GetCluster());

                        // If there is more than one sweeping scout, then the second scout will perform the removal of the scanned cluster.
                        if (firstSweepingScout == false || currentSweepingScoutCount == 1)
                        {
                            var currentUnexploredClusters = GameInfo.GetUnexploredClusters(ClientConnection.GetCore());

                            if (currentUnexploredClusters.ContainsKey(ship.GetCluster().GetObjectID()) == true)
                            {
                                Log("Initial sweep complete, but we didn't find everything. TODO: take a closer look?");
                                DoTargetedSweep(ship);
                            }
                            else
                            {
                                Log($"\t\tCluster exploration complete for {ship.GetCluster().GetName()}, this cluster is no longer in the unexplored list.");
                                //GameInfo.UnexploredClustersByObjectID.Remove(ship.GetCluster().GetObjectID());
                                //UpdateUnexploredWarpsList();
                            }
                        }
                        else
                        {
                            Log($"\t\tCluster exploration complete for {ship.GetCluster().GetName()} for first sweeping scout.");
                        }
                    }

                    SelectNextAelphTarget();
                }
                finally
                {
                    _runningTasks--;
                    _isSweeping = false;
                    GameInfo.DecrementSweepingScoutCount(ship.GetCluster());
                }
            });

            //_startingPoint = shipPosition;
            //_startingAngleInRadians = shipPosition.AngleInRadians(centerPoint);



            //if (_startingAngleInRadians < 0)
            //    _startingAngleInRadians = _startingAngleInRadians + 2 * Math.PI;

            //_currentAngleInRadians = _startingAngleInRadians;

            //// If there are no scouts, sweep left, otherwise if there is already a scount, then sweep right, otherwise, locate a new aleph and go there!
            //if (otherScoutShips.Count() == 0)
            //{
            //    _sweepLeft = true;
            //    NavigateToNextSweepPoint();
            //}
            //else if (otherScoutShips.Count() == 1)
            //{
            //    _sweepRight = true;
            //    NavigateToNextSweepPoint();
            //}
            //else
            //{
            //    _sweepRight = false;
            //    _sweepLeft = false;
            //    SelectNextAelphTarget();
            //}
        }
Exemplo n.º 15
0
	/// <summary>
	/// Helper function that draws a field of 3 floats.
	/// </summary>

	static VectorWrapper DrawVector3 (Vector3 value, Axes shown, Axes editable)
	{
		GUILayoutOption opt = GUILayout.MinWidth(30f);
		VectorWrapper update = new VectorWrapper() { value = value };

		update.SetX(DrawFloatField("X", value.x, ((shown & Axes.X) != Axes.None), ((editable & Axes.X) != Axes.None), opt));
		update.SetY(DrawFloatField("Y", value.y, ((shown & Axes.Y) != Axes.None), ((editable & Axes.Y) != Axes.None), opt));
		update.SetZ(DrawFloatField("Z", value.z, ((shown & Axes.Z) != Axes.None), ((editable & Axes.Z) != Axes.None), opt));

		return update;
	}
Exemplo n.º 16
0
        private void FlyToStationPointAndWaitForAelphs()
        {
            Log("FlyToStationPointAndWaitForAelphs");

            var ship         = _client.GetShip();
            var centerPoint  = new VectorWrapper(0, 0, 0);
            var shipPosition = ship.GetPosition();

            var startingPoint          = shipPosition;
            var startingAngleInRadians = shipPosition.AngleInRadians(centerPoint);

            // 1/3 of 360 degrees in radians.
            double oneThirdAngle = Math.PI * 2 / 3;

            // Move to a new point 1/3 or 2/3 of the total angle and the same distance as the entry aleph.
            double newAngle = startingAngleInRadians + (oneThirdAngle * _random.Next(1, 3));

            VectorWrapper nextPoint = new VectorWrapper((startingPoint - centerPoint).Length() * (float)Math.Cos(newAngle), (startingPoint - centerPoint).Length() * (float)Math.Sin(newAngle), 0);

            var buoy    = _client.CreateBuoy((sbyte)BuoyType.c_buoyWaypoint, nextPoint.X(), nextPoint.Y(), nextPoint.Z(), ship.GetCluster().GetObjectID(), true);
            var command = ship.GetDefaultOrder(buoy);

            ship.SetCommand((sbyte)CommandType.c_cmdCurrent, buoy, command);
            ship.SetAutopilot(true);

            List <int> consideredWarpObjectIDs = new List <int>();

            // Wait for Aelphs to appear.
            Task.Run(() =>
            {
                try
                {
                    _runningTasks++;

                    bool foundNewWarp = false;
                    bool updatedUnexploredClusterListAfterMove = false;
                    for (int i = 0; i < 120 * 100 && _cancellationTokenSource.IsCancellationRequested == false; i++)
                    {
                        var otherScoutShips         = ship.GetCluster().GetShips().Where(p => p.GetObjectID() != ship.GetObjectID() && p.GetBaseHullType().GetName().Contains("Scout") == true);
                        var otherSweepingScoutShips = otherScoutShips.Where(p => p.GetCommandTarget((sbyte)CommandType.c_cmdCurrent)?.GetObjectType() == (short)ObjectType.OT_buoy);

                        if (i % 500 == 0)
                        {
                            Log($"Waiting for Alephs to be found: {i}.");

                            // Once we get within 400 of the waypoint, update the unexplored clusters list in case we happen to have found a new unexplored cluster.
                            if (updatedUnexploredClusterListAfterMove == false && (nextPoint - ship.GetPosition()).LengthSquared() < Math.Pow(400, 2))
                            {
                                Log("Updating unexplored cluster list after ship move.");
                                UpdateUnexploredWarpsList();
                                updatedUnexploredClusterListAfterMove = true;
                            }
                        }

                        var newWarps = ship.GetCluster().GetWarps().Where(p => GameInfo.UnexploredClustersByObjectID.ContainsKey(p.GetDestination().GetCluster().GetObjectID()) == true && consideredWarpObjectIDs.Contains(p.GetObjectID()) == false);
                        if (newWarps.Count() > 0)
                        {
                            foreach (var newWarp in newWarps)
                            {
                                // If there are other non-sweeping ships in the sector, then only 33% of those ships should go to the newly visible aelph.
                                if (otherScoutShips.Count() - otherSweepingScoutShips.Count() > 0)
                                {
                                    if (_random.Next(0, 100) < 33)
                                    {
                                        Log($"Warp found, 33% chance success, heading to {newWarp.GetName()}");

                                        ship.SetCommand((sbyte)CommandType.c_cmdCurrent, newWarp, (sbyte)CommandID.c_cidGoto);
                                        ship.SetAutopilot(true);
                                        foundNewWarp = true;
                                        break;
                                    }
                                }
                                else // We are the only non-sweeping scout in the cluster, go to the new warp.
                                {
                                    Log($"Warp found, heading to {newWarp.GetName()}");

                                    ship.SetCommand((sbyte)CommandType.c_cmdCurrent, newWarp, (sbyte)CommandID.c_cidGoto);
                                    ship.SetAutopilot(true);
                                    foundNewWarp = true;
                                    break;
                                }
                            }
                        }

                        Thread.Sleep(100);
                    }

                    if (foundNewWarp == false)
                    {
                        Log("No aelph was found, heading to next available warp.");
                        SelectNextAelphTarget();
                    }
                }
                finally
                {
                    _runningTasks--;
                }
            });
        }
Exemplo n.º 17
0
        private void SweepCluster()
        {
            Log("SweepCluster()");

            _isSweeping = true;

            var ship            = _client.GetShip();
            var otherScoutShips = ship.GetCluster().GetShips().Where(p => p.GetObjectID() != ship.GetObjectID() && p.GetBaseHullType().GetName().Contains("Scout") == true);

            var centerPoint  = new VectorWrapper(0, 0, 0);
            var shipPosition = ship.GetPosition();

            var startingPoint          = shipPosition;
            var startingAngleInRadians = shipPosition.AngleInRadians(centerPoint);

            double nextSliceWidth        = (Math.PI * 2 / SweepHopCount);
            double currentAngleInRadians = startingAngleInRadians;

            bool sweepLeft = otherScoutShips.Count() > 0;

            Task.Run(() =>
            {
                try
                {
                    _runningTasks++;

                    bool sweepComplete = true;

                    // Skip the first hop and the last 2 hops, aelphs won't be that close together.
                    for (int i = 1; i < SweepHopCount - 2 && _cancellationTokenSource.IsCancellationRequested == false; i++)
                    {
                        if (sweepLeft == true)
                        {
                            currentAngleInRadians += nextSliceWidth;
                        }
                        else
                        {
                            currentAngleInRadians -= nextSliceWidth;
                        }

                        VectorWrapper nextPoint = new VectorWrapper((startingPoint - centerPoint).Length() * (float)Math.Cos(currentAngleInRadians), (startingPoint - centerPoint).Length() * (float)Math.Sin(currentAngleInRadians), 0);

                        Log($"nextPoint: {nextPoint.GetString()}, currentAngleInRadians: {currentAngleInRadians}, sweepHop: {i}");

                        var buoy    = _client.CreateBuoy((sbyte)BuoyType.c_buoyWaypoint, nextPoint.X(), nextPoint.Y(), nextPoint.Z(), ship.GetCluster().GetObjectID(), true);
                        var command = ship.GetDefaultOrder(buoy);
                        ship.SetCommand((sbyte)CommandType.c_cmdCurrent, buoy, command);
                        ship.SetAutopilot(true);

                        bool reachedWaypoint = false;
                        for (int j = 0; j < 120 * 100 && _cancellationTokenSource.IsCancellationRequested == false; j++)
                        {
                            VectorWrapper difference = nextPoint - ship.GetPosition();

                            if (j % 500 == 0)
                            {
                                Log($"Current distance: {Math.Abs(difference.Length())}, iterations: {j}, {nextPoint.GetString()}");
                            }

                            if ((nextPoint - ship.GetPosition()).LengthSquared() < Math.Pow(400, 2))
                            {
                                Log($"Reached waypoint: {nextPoint.GetString()}");
                                reachedWaypoint = true;
                                break;
                            }

                            Thread.Sleep(100);
                        }

                        // We didn't reach the waypoint in two minutes. Something went wrong, let's just move on.
                        if (reachedWaypoint == false)
                        {
                            sweepComplete = false;
                            Log("No waypoint was found in 120 seconds.");
                            break;
                        }
                    }

                    if (sweepComplete == true)
                    {
                        Log($"Cluster exploration complete for ship.GetCluster().GetName(), removing from GameInfo.UnexploredClustersByObjectID");
                        GameInfo.UnexploredClustersByObjectID.Remove(ship.GetCluster().GetObjectID());
                        UpdateUnexploredWarpsList();
                    }

                    SelectNextAelphTarget();
                }
                finally
                {
                    _runningTasks--;
                    _isSweeping = false;
                }
            });

            //_startingPoint = shipPosition;
            //_startingAngleInRadians = shipPosition.AngleInRadians(centerPoint);



            //if (_startingAngleInRadians < 0)
            //    _startingAngleInRadians = _startingAngleInRadians + 2 * Math.PI;

            //_currentAngleInRadians = _startingAngleInRadians;

            //// If there are no scouts, sweep left, otherwise if there is already a scount, then sweep right, otherwise, locate a new aleph and go there!
            //if (otherScoutShips.Count() == 0)
            //{
            //    _sweepLeft = true;
            //    NavigateToNextSweepPoint();
            //}
            //else if (otherScoutShips.Count() == 1)
            //{
            //    _sweepRight = true;
            //    NavigateToNextSweepPoint();
            //}
            //else
            //{
            //    _sweepRight = false;
            //    _sweepLeft = false;
            //    SelectNextAelphTarget();
            //}
        }
Exemplo n.º 18
0
 private void SetCamera(VectorWrapper vw, Camera camera)
 {
     vw.SetCamera(camera);
 }