示例#1
0
    public void Setup(GameCore parentGameCore, int galaxySeed)
    {
        gameCore = parentGameCore;

        GalaxyMapNode[] foundNodes = GetComponentsInChildren <GalaxyMapNode>();
        Edges = GetComponentsInChildren <GalaxyMapEdge>();

        //Inform the nodes about their relevant edges
        foreach (var node in foundNodes)
        {
            Nodes.Add(node.name, node);

            foreach (var edge in Edges)
            {
                if (edge.nodeA == node || edge.nodeB == node)
                {
                    node.edges.Add(edge);
                }
            }
        }

        //Randomize edge weights
        if (gameCore.SimMode == GameCore.SimulationMode.C && galaxySeed != 0)
        {
            Random.InitState(galaxySeed);
            foreach (var edge in Edges)
            {
                edge.EdgeCost = Random.Range(1, 21);
            }
        }

        GalaxyMapData = GenerateGalaxyMapData();
    }
示例#2
0
 private void Init()
 {
     playerFleetData = new PlayerFleetData();
     pirates_AI_Data = new AI_Data();
     galaxyMapData = new GalaxyMapData();
     tutorialData = new TutorialData();
 }
示例#3
0
    //Copy Godot-side hierarchy information over into "student safe" data containers
    GalaxyMapData GenerateGalaxyMapData()
    {
        //Data copies for GalaxyMapNodes
        var nodeDataToReturn = new List <GalaxyMapNodeData>();

        foreach (Node2D node in Nodes)
        {
            var newNodeData = new GalaxyMapNodeData();
            newNodeData.systemName       = node.Name;
            newNodeData.galacticPosition = node.Position;
            nodeDataToReturn.Add(newNodeData);
        }

        //Data copies for GalaxyMapEdges
        var edgeDataToReturn = new List <GalaxyMapEdgeData>();

        foreach (GalaxyMapEdge edge in Edges)
        {
            var newEdgeData = new GalaxyMapEdgeData();
            newEdgeData.edgeCost = edge.EdgeCost;

            foreach (var nodeData in nodeDataToReturn)
            {
                if (nodeData.systemName == edge.NodeA.Name)
                {
                    newEdgeData.nodeA = nodeData;
                }

                if (nodeData.systemName == edge.NodeB.Name)
                {
                    newEdgeData.nodeB = nodeData;
                }
            }

            edgeDataToReturn.Add(newEdgeData);
        }

        //Let each NodeData know about relevant EdgeData
        foreach (var node in nodeDataToReturn)
        {
            List <GalaxyMapEdgeData> edges = new List <GalaxyMapEdgeData>();
            foreach (var edge in edgeDataToReturn)
            {
                if (edge.nodeA == node || edge.nodeB == node)
                {
                    edges.Add(edge);
                }
            }
            node.edges = edges.ToArray();
        }

        //Package the data up and return it to the caller
        GalaxyMapData dataToReturn = new GalaxyMapData();

        dataToReturn.nodeData = nodeDataToReturn.ToArray();
        dataToReturn.edgeData = edgeDataToReturn.ToArray();
        return(dataToReturn);
    }
示例#4
0
    private void UpdatePath(SubsystemReferences SystemReferences, GalaxyMapData galaxyMapData)
    {
        string start = SystemReferences.currentGalaxyMapNodeName;

        // TODO Dijkstra
        galaxyPath.Add("Sol");
        galaxyPath.Add("Alpha Centauri");
        galaxyPath.Add("Kepler 438");
    }
 public void DeSerialize(ref GalaxyMapData _galaxyMapData)
 {
     for (int i = 0; i < 10; i++)
     {
         _galaxyMapData.completeStatus[i] = sz_completeStatus[i];
     }
     _galaxyMapData.currentMissionID = sz_currentMissionID;
     _galaxyMapData.position.Set(sz_positionX, sz_positionY, sz_positionZ);
 }
    public void NavigationUpdate(SubsystemReferences SystemReferences, GalaxyMapData galaxyMapData)
    {
        int n = galaxyMapData.nodeData.Length;
        Dictionary <GalaxyMapNodeData, int> nodeToInt = new Dictionary <GalaxyMapNodeData, int>();

        for (int i = 0; i < n; i++)
        {
            nodeToInt[galaxyMapData.nodeData[i]] = i;
        }

        GalaxyMapEdgeData[] edges = galaxyMapData.edgeData;
        int[,] adj = new int[1005, 1005];

        galaxyMapNodeData root = galaxyMapData.nodeData[0];

        foreach (GalaxyMapEdgeData data in edges)
        {
            int A = data.nodeA, B = data.nodeB;
            data.edgeCost = Mathf.Pow((A.galacticPosition.x - B.galacticPosition.x), 2) - Mathf.Pow((A.galacticPosition.y - B.galacticPosition.y), 2);
            adj[nodeToInt[A]][nodeToInt[B]] = data.edgeCost;
        }

        float dist = new float[105];
        bool  vis  = new bool[105];

        for (int i = 0; i < 105; i++)
        {
            dist[i] = 999999;
        }
        List <Tuple <float, int> > edgeList = new List <Tuple <float, int> >(); // cost, id of next node

        edgeList.Add(new Tuple(edges[0].edgeCost, edges[0].nodeB));

        /*while(edgeList.size() > 0)
         * {
         *  float minEdge = edgeList[0];
         *
         *
         *
         *
         * }*/


        if (!visitedGalaxies.Contains(SystemReferences.currentGalaxyMapNodeName))
        {
            visitedGalaxies.Add(SystemReferences.currentGalaxyMapNodeName);
        }

        foreach (SensorSubsystemController.WarpStruct warpStruct in SystemReferences.Sensors.GWIWarpData)
        {
            warpGatesInCurrentGalaxy.Add(warpStruct);
        }

        destinationWarpGate = GetDestinationWarpGate();
    }
示例#7
0
    // Called when the node enters the scene tree for the first time.
    public override void _Ready()
    {
        if (startingNodePath != null)
        {
            var startNode = GetNode(startingNodePath);
            StartingNode = startNode as GalaxyMapNode;
        }

        Nodes = GetNode("Nodes").GetChildren();
        Edges = GetNode("Edges").GetChildren();

        GalaxyMapData = GenerateGalaxyMapData();
    }
 public override void NavigationUpdate(ShipStatusInfo shipStatusInfo, GalaxyMapData galaxyMapData, float deltaTime)
 {
     //Student code goes here
 }
示例#9
0
 public void NavigationUpdate(SubsystemReferences SystemReferences, GalaxyMapData galaxyMapData)
 {
     if (!firstTime)
     {
         // If havn't, run Dijkstra and find the shortest path
         UpdatePath(SystemReferences, galaxyMapData);
         firstTime = true;
     }
     // Update the destination within the current galaxy
     // (Kepler 438b if in Kepler 438, the next wrap gate along the path if otherwise)
     // Traverse all galaxy
     for (int i = 0; i < galaxyPath.Count; i++)
     {
         // Find the current galaxy
         if (galaxyPath[i] == SystemReferences.currentGalaxyMapNodeName)
         {
             if (i == galaxyPath.Count - 1)
             {
                 // This is the final galaxy, return the planet position
                 // Check if the planet is close
                 foreach (SensorSubsystemController.DetectedCloseObject closeObject
                          in SystemReferences.Sensors.detectedCloseObjects)
                 {
                     if (closeObject.materials.Contains(SpaceMaterial.Common) &&
                         closeObject.materials.Contains(SpaceMaterial.Metal) &&
                         closeObject.materials.Contains(SpaceMaterial.Water))
                     {
                         // Planet found
                         destinationPosition = closeObject.position;
                         return;
                     }
                 }
                 // If the planet is not close, go to the planetoid
                 foreach (SensorSubsystemController.DetectedFarObject farObject
                          in SystemReferences.Sensors.detectedFarObjects)
                 {
                     if (farObject.type == GravitySignature.Planetoid)
                     {
                         destinationPosition = farObject.position;
                         return;
                     }
                 }
             }
             else
             {
                 // This is NOT the final galaxy, return the wrap gate position
                 nextGalaxyName = galaxyPath[i + 1];
                 foreach (SensorSubsystemController.DetectedFarObject wrapgate
                          in SystemReferences.Sensors.getWarpGates())
                 {
                     if (wrapgate.destinationName == nextGalaxyName)
                     {
                         //Debug.Log("(" + wrapgate.position.x + ",(" + wrapgate.position.y + ")");
                         destinationPosition = wrapgate.position;
                         return;
                     }
                 }
             }
         }
     }
 }
    /*
     * bool sensorsControllerEnabled = true;
     * public event Action<bool> OnSensorsControllerEnabledChanged;
     * public bool IsSensorsControllerEnabled {get{return sensorsControllerEnabled;} set{sensorsControllerEnabled = value; OnSensorsControllerEnabledChanged?.Invoke(sensorsControllerEnabled);}}
     *
     *
     * bool navigationControllerEnabled = true;
     * public event Action<bool> OnNavigationControllerEnabledChanged;
     * public bool IsNavigationControllerEnabled {get{return navigationControllerEnabled;} set{navigationControllerEnabled = value; OnNavigationControllerEnabledChanged?.Invoke(navigationControllerEnabled);}}
     *
     * bool propulsionControllerEnabled = true;
     * public event Action<bool> OnPropulsionControllerEnabledChanged;
     * public bool IsPropulsionControllerEnabled {get{return propulsionControllerEnabled;} set{propulsionControllerEnabled = value; OnPropulsionControllerEnabledChanged?.Invoke(propulsionControllerEnabled);}}
     *
     * bool defenceControllerEnabled = true;
     * public event Action<bool> OnDefenceControllerEnabledChanged;
     * public bool IsDefenceControllerEnabled {get{return defenceControllerEnabled;} set{defenceControllerEnabled = value; OnDefenceControllerEnabledChanged?.Invoke(defenceControllerEnabled);}}
     */
    /*
     * //Subsystems
     * public AbstractSensorsController Sensors { get; private set; }
     * public AbstractNavigationController Navigation { get; private set; }
     * public AbstractDefenceController Defence { get; private set; }
     * public AbstractPropulsionController Propulsion { get; private set; }
     *
     * public SubsystemReferences(AbstractSensorsController sensors, AbstractNavigationController navigation, AbstractDefenceController defence, AbstractPropulsionController propulsion)
     * {
     *
     *  Sensors = sensors;
     *  Defence = defence;
     *  Navigation = navigation;
     *  Propulsion = propulsion;
     * }
     */

    public abstract void ProcessPhysics(ShipStatusInfo shipStatusInfo, float deltaTime, ActiveSensors ActiveSensors, PassiveSensors passiveSensors, GalaxyMapData galaxyMapData, ThrusterControls thrusterControls, TurretControls turretControls);
示例#11
0
 public void NavigationUpdate(SubsystemReferences SystemReferences, GalaxyMapData galaxyMapData)
 {
 }
 public abstract void NavigationUpdate(ShipStatusInfo shipStatusInfo, GalaxyMapData galaxyMapData, float deltaTime);