Ejemplo n.º 1
0
    public void PropulsionUpdate(SubsystemReferences subsystemReferences, ThrusterControls thrusterControls)
    {
        Vector2 direction = subsystemReferences.Navigation.GetDestination() - (Vector2)subsystemReferences.currentShipPositionWithinGalaxyMapNode;

        direction /= direction.magnitude;
        direction *= 10;
        thrusterControls.UFODriveVelocity = direction;



        /*Vector3 target = new Vector3(0, 0, 0);
         * float targetAngle = Vector3.SignedAngle(Vector3.right, target, Vector3.forward);
         * float angle = Vector3.SignedAngle(Vector3.right, subsystemReferences.forward, Vector3.forward);
         * if (turning)
         * {
         *
         *  if ((angle > 25) && (angle < 35))
         *  {
         *      turning = false;
         *
         *  }
         *  thrusterControls.portAftThrust = 3;
         *
         * }
         * else {
         *  thrusterControls.portAftThrust = 0;
         * }
         */
    }
    public void SensorsUpdate(SubsystemReferences subsysRef, ShipSensors Data)
    {
        detectedFarObjects   = new List <DetectedFarObject>();
        detectedCloseObjects = new List <DetectedCloseObject>();

        foreach (GWI_Detection detection in Data.GWInterferometer)
        {
            DetectedFarObject obj = new DetectedFarObject();
            obj.type     = detection.signature;
            obj.position = AngleToPosition(subsysRef.currentShipPositionWithinGalaxyMapNode,
                                           detection.angle, ShipSensors.GConstant / detection.waveAmplitude, true);
            obj.destinationName = detection.warpGateDestination;
            detectedFarObjects.Add(obj);
        }

        foreach (EMS_Detection detection in Data.EMSensor)
        {
            DetectedCloseObject obj = new DetectedCloseObject();
            obj.velocity = detection.velocity;
            obj.radius   = detection.radius;
            obj.position = AngleToPosition(subsysRef.currentShipPositionWithinGalaxyMapNode,
                                           detection.angle, ShipSensors.EMConstant / detection.signalStrength, false);
            obj.materialSignature = detection.materialSignature;
            foreach (SpaceMaterial material in Enum.GetValues(typeof(SpaceMaterial)))
            {
                if (Data.CheckSignatureForSpaceMaterial(detection.materialSignature, material))
                {
                    obj.materials.Add(material);
                }
            }
            detectedCloseObjects.Add(obj);
        }
    }
Ejemplo n.º 3
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 PropulsionUpdate(SubsystemReferences subsystemReferences, ThrusterControls thrusterControls)
 {
     subsystemRefs = subsystemReferences;
     if (engineOn)
     {
         rotateToVector2(targetVector, subsystemReferences.forward, thrusterControls);
         thrusterControls.mainThrust = THRUST_STRENGTH;
     }
 }
Ejemplo n.º 5
0
 public void DefenceUpdate(SubsystemReferences subsystemReferences, TurretControls turretControls)
 {
     //turretControls.aimTo = new Vector3 (0,1,1);
     turretControls.aimTo = Asteroid(subsystemReferences);
     Debug.Log(subsystemReferences.Sensors.EMSData.Count);
     turretControls.FireTube0();
     //turretControls.FireTube2();
     //turretControls.FireTube3();
 }
    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();
    }
Ejemplo n.º 7
0
    public Vector2 Asteroid(SubsystemReferences subsystemReferences)
    {
        int     asteroidCount   = subsystemReferences.Sensors.EMSData.Count;
        Vector2 closestAsteroid = subsystemReferences.Sensors.EMSData[0].pos;

        for (int i = 1; i < asteroidCount; i++)
        {
            float distance = ((subsystemReferences.Sensors.EMSData[i].pos) - (shipPosition)).magnitude;
            if (distance < ((closestAsteroid) - (shipPosition)).magnitude)
            {
                closestAsteroid = subsystemReferences.Sensors.EMSData[i].pos;
            }
        }
        return(closestAsteroid);
    }
Ejemplo n.º 8
0
 public bool WillCrashIntoShip(SubsystemReferences subsystemReferences)
 {
     shipVelocityNorm     = (subsystemReferences.forward).magnitude;
     shipVelocity         = subsystemReferences.velocity;
     shipPosition         = subsystemReferences.currentShipPositionWithinGalaxyMapNode;
     asteroidVelocityNorm = (subsystemReferences.Sensors.EMSData[0].vel).magnitude;
     time = ((shipPosition - subsystemReferences.Sensors.EMSData[0].pos) / (subsystemReferences.Sensors.EMSData[0].vel - shipVelocity)).magnitude;
     if (time < 0)
     {
         return(false);
     }
     else
     {
         return(true);
     }
 }
    public void DefenceUpdate(SubsystemReferences subsystemReferences, TurretControls turretControls)
    {
        Vector2 ship = subsystemReferences.currentShipPositionWithinGalaxyMapNode;

        List <DetectedCloseObject> objs = subsystemReferences.Sensors.detectedCloseObjects;

        objs.Sort((a, b) => (int)((a.position - ship).sqrMagnitude - (b.position - ship).sqrMagnitude) * 1000);
        objs = objs.Where(a => shouldShot(a)).ToList();

        if (objs.Count < 1)
        {
            return;
        }
        turretControls.aimTo = getAimTo(objs[0], ship);
        turretControls.FireTube0();

        if (objs.Count < 2)
        {
            return;
        }
        turretControls.aimTo = getAimTo(objs[1], ship);
        turretControls.FireTube1();

        if (objs.Count < 3)
        {
            return;
        }
        turretControls.aimTo = getAimTo(objs[2], ship);
        turretControls.FireTube2();

        if (objs.Count < 4)
        {
            return;
        }
        turretControls.aimTo = getAimTo(objs[3], ship);
        turretControls.FireTube3();
    }
Ejemplo n.º 10
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;
                     }
                 }
             }
         }
     }
 }
 public void DefenceUpdate(SubsystemReferences subsystemReferences, TurretControls turretControls)
 {
 }
 public void SensorsUpdate(SubsystemReferences subsysRef, ShipSensors Data)
 {
 }
    public void SensorsUpdate(SubsystemReferences subsysRef, ShipSensors Data)
    {
        double EMSangle;
        float  signalStrength;
        int    EMSsignature;

        float  EMSdistance;
        double EMSposX, EMSposY;

        Vector2 pos;
        Vector2 vel;

        bool water  = false;
        bool common = false;
        bool metal  = false;

        //empty lists
        GWIWarpData.RemoveAll();
        EMSData.RemoveAll();

        for (int i = 0; i < Data.EMSensor.Count; i++)
        {
            EMSangle       = (double)Data.EMSensor[i].angle;
            signalStrength = Data.EMSensor[i].signalStrength;
            EMSsignature   = Data.EMSensor[i].materialSignature;

            EMSdistance = ShipSensors.EMConstant / signalStrength;

            EMSposX = EMSdistance * Math.Cos(EMSangle);
            EMSposY = EMSdistance * Math.Sin(EMSangle);

            vel = Data.EMSensor[i].velocity;

            pos = new Vector2((float)EMSposX, (float)EMSposY);

            if (Data.CheckSignatureForSpaceMaterial(EMSsignature, SpaceMaterial.Water))
            {
                water = true;
            }
            if (Data.CheckSignatureForSpaceMaterial(EMSsignature, SpaceMaterial.Common))
            {
                common = true;
            }
            if (Data.CheckSignatureForSpaceMaterial(EMSsignature, SpaceMaterial.Metal))
            {
                metal = true;
            }

            EMSData.Add(new EMSDetection(pos, vel, EMSsignature, water, common, metal));
        }


        String           warpgateDest;
        double           angle;
        float            waveAmplitude;
        GravitySignature signature;

        SpaceMaterial[] material = { };

        //Good data
        float   distance;
        double  distX, distY;
        Vector2 vector;


        for (int i = 0; i < Data.GWInterferometer.Count; i++)
        {
            //get data
            warpgateDest  = Data.GWInterferometer[i].warpGateDestination;
            angle         = (double)Data.GWInterferometer[i].angle;
            waveAmplitude = Data.GWInterferometer[i].waveAmplitude;
            signature     = Data.GWInterferometer[i].signature;

            //distance = G / waveAmp
            distance = ShipSensors.GConstant / waveAmplitude;

            //distance for vectors
            distX = distance * Math.Cos(angle);
            distY = distance * Math.Sin(angle);

            vector = new Vector2((float)distX, (float)distY);

            if (signature == GravitySignature.WarpGate)
            {
                GWIWarpData.Add(new WarpStruct(vector, signature, warpgateDest));
            }
        }
    }
Ejemplo n.º 14
0
 public void PropulsionUpdate(SubsystemReferences subsystemReferences, ThrusterControls thrusterControls)
 {
 }
Ejemplo n.º 15
0
    public void Setup(GameCore parentGameCore)
    {
        this.parentGameCore = parentGameCore;

        subsystems = new SubsystemReferences(this);
    }
Ejemplo n.º 16
0
 public void NavigationUpdate(SubsystemReferences SystemReferences, GalaxyMapData galaxyMapData)
 {
 }