//other metrics calculated every tick (week? month?)
    public void Tick()
    {
        //happiness = food surplus + baseline + employment + stability + debt + tax rate
        //	spending power (earning/costs)
        //  costs = food/population
        //  earning = gdp / population
        //  special events: win a war; land on another planet; colonize new moon
        happiness = food / population + employment / population - taxRate;
        foreach (var hap in happinessEvents.Values)
        {
            happiness += hap;
        }

        //production = rate of making things at the nation level
        production = employment * (happiness + productivity);
        //	population, happiness level, research boosts, policy boosts
        float revenue = taxRate * GetGDP();

        treasury   += revenue;
        population += population * .2f * (food / population - .9f) * (1 - taxRate) * (employment / population);
        Debug.Log("Happiness: " + happiness);
        Debug.Log("Production: " + OVTools.FormatNumber(production));
        Debug.Log("Revenue: " + OVTools.FormatMoney(revenue));
        Debug.Log("Population: " + OVTools.FormatNumber(population));
    }
    public void Init()
    {
        eventManager = GameObject.Find("EventManager").GetComponent<EventManager>();
        rv = new VectorD();
        rv.Resize(6);

        Debug.Log("position " + transform.localPosition);
        rv[0] = transform.localPosition.x * HoloManager.SolScale;
        rv[1] = transform.localPosition.y * HoloManager.SolScale;
        rv[2] = transform.localPosition.z * HoloManager.SolScale;
        Debug.Log(name + " real dist: " + OVTools.FormatDistance(getRFloat().magnitude));
        //comput velocity assuming pos is in the origin
        //TODO use double operations?
        var vel = Vector3.Cross(transform.localPosition, Vector3.up).normalized;
        vel *= Mathf.Sqrt((float)parentGM / (HoloManager.SolScale * transform.localPosition.magnitude));
        rv[3] = vel.x;
        rv[4] = vel.y;
        rv[5] = vel.z;

        //set oe
        var tempoe = Util.rv2oe(parentGM, rv);
        SetOE(tempoe);

        params_ = new VectorD();
        params_.Resize(7);
        params_[0] = 0;
        params_[1] = 0;
        params_[2] = 0;
        params_[3] = parentGM;
        params_[4] = 0;
        params_[5] = 0;
        params_[6] = 0;
    }
Exemple #3
0
    void UpdateFundsText(float funds)
    {
        Debug.Log("Updating funds text");
        var tooltip = AvailableFundsObj.GetComponent <Tooltip>();

        tooltip.displayText = "Funds: " + OVTools.FormatMoney(funds);
        tooltip.Reset();
    }
Exemple #4
0
 public void print()
 {
     Debug.Log("sma: " + OVTools.FormatDistance((float)sma));
     Debug.Log("ecc: " + ecc);
     Debug.Log("inc: " + inc);
     Debug.Log("lan: " + lan);
     Debug.Log("aop: " + aop);
     Debug.Log("tra: " + tra);
     Debug.Log("compTime: " + OVTools.FormatDistance((float)computeTime));
 }
 public void EnablePorkChop(bool enableIntercept)
 {
     Debug.Log("Enabled porkchop");
     gameObject.SetActive(true);
     triggerPork = true;
     availDV     = GetAvailableDV();
     Debug.Log("availDV: " + availDV);
     intercept = enableIntercept;
     Debug.Log("Enable porkchop, simtime: " + OVTools.FormatTime((float)eventManager.GetSimTime()));
 }
    void testMarker(string markername, double startTime)
    {
        //return;// don't show extra markers of start path
        Vector3d r1, v1;

        FindRV(oe1, startTime, out r1, out v1);

        var marker = GameObject.Find(markername);

        marker.transform.localPosition = r1.ToFloat() * HoloManager.SimZoomScale;
        Debug.Log(markername + " " + OVTools.FormatTime((float)startTime));
    }
    // Update is called once per frame
    void Update()
    {
        var go = UXStateManager.GetSource();

        if (go == null)
        {
            return;
        }
        var speed    = go.GetComponent <OrbitData>().getVel().magnitude;
        var strSpeed = OVTools.FormatDistance(speed) + "/s";

        indicator.displayText = go.name + ": " + strSpeed;
        indicator.Reset();
    }
Exemple #8
0
    void AdjustOrbit(ManeuverEvent e)
    {
        /*
         * float time = (float)e.GetTime();
         *
         * while (time > 5)
         * {
         *  Debug.Log("Waiting for " + time + " seconds");
         *  yield return new WaitForSeconds(5);
         *  time -= 5;
         * }
         * Debug.Log("Waiting for " + time + " seconds");
         * yield return new WaitForSeconds(time);
         */
        Debug.Log("Name of source: " + e.GetSource().name);
        Debug.Log("Firing! " + OVTools.FormatDistance((float)e.velocity.magnitude) + "/s");
        Debug.Log("injection vector: " + e.velocity.ToString());
        Debug.Log("Injection time: " + eventManager.GetSimTime());

        var odata = e.GetSource().GetComponent <OrbitData>();

#if false
        //recompute firing solution
        Vector3d r1, r2, v1, v2, initVel, finalVel;
        //var oe1 = e.GetSource().GetComponent<OrbitData>().getOE();
        var oe2 = e.GetTarget().GetComponent <OrbitData>().getOE();
        //FindRV(oe1, eventManager.GetSimTime(), out r1, out v1);
        r1 = e.GetSource().GetComponent <OrbitData>().getR();
        FindRV(oe2, e.relTravelTime, out r2, out v2);
        MuMech.LambertSolver.Solve(r1, r2, e.relTravelTime, OrbitData.parentGM, true, out initVel, out finalVel);

        Debug.Log("Injection pos: " + odata.getR().ToString());
        var diff = (float)(odata.getR() - OVDebug.projectedR1).magnitude;
        Debug.Log("Difference: " + OVTools.FormatDistance(diff));

        Debug.Log("New injection vector: " + initVel.ToString());
        var diff2 = (float)(e.velocity - initVel).magnitude;
        Debug.Log("Diff: " + OVTools.FormatDistance(diff2));
#endif

        if (odata == null)
        {
            Debug.Log("no orbital data from ship!!");
        }

        odata.rv[3] = e.velocity.x;
        odata.rv[4] = e.velocity.y;
        odata.rv[5] = e.velocity.z;

        //update oe
        var oe = Util.rv2oe(OrbitData.parentGM, odata.rv);
        odata.SetOE(oe);

        Debug.Log("InjVec: " + e.velocity);
        //disable intercept line render
        interceptLine.enabled = false;
        var marker1 = GameObject.Find("Marker1");
        marker1.transform.localPosition = Vector3.zero;
        var marker2 = GameObject.Find("Marker2");
        marker2.transform.localPosition = Vector3.zero;
    }
Exemple #9
0
    public void findInterceptPoints(OrbitalElements oe1, OrbitalElements oe2)
    {
        int     steps = 0;
        double  time = 0;
        float   prevDiff = float.MaxValue;
        double  tra1, tra2, minTra1, minTra2;
        Vector3 minpos1     = Vector3.zero;
        Vector3 minpos2     = Vector3.zero;
        bool    first       = true;
        bool    forwardMode = true;

        if (steps >= 360)
        {
            if (writeOnce)
            {
                //Savecsv();
                writeOnce = false;
            }
            return;
        }

        double gm = OrbitData.parentGM;
        //period of the search (shrinks w/ each iteration)
        double period            = Math.Max(oe1.GetPeriod(), oe2.GetPeriod());
        double maxSearchInterval = period + eventManager.GetSimTime();
        double timeStep          = period / 360;

        var    debugLine = transform.Find("debug").GetComponent <LineRenderer>();
        double minTime = 0, max = period;
        int    itCount = 0;

        //get approx closest approach
        while (timeStep >= .0001d)
        {
            while (time < maxSearchInterval)// && steps < 360)
            {
                var   pos1     = oe1.GetRAtTime(time);
                var   pos2     = oe2.GetRAtTime(time);
                float thisDiff = (float)(pos1 - pos2).magnitude;
                //Debug.Log(thisDiff);
                if (thisDiff < prevDiff && forwardMode)
                {
                    prevDiff = thisDiff;
                    minpos1  = pos1;
                    minpos2  = pos2;
                    minTime  = time;
                }
                time += timeStep;
            }
            period           /= 10;
            time              = (minTime - period < 0) ? 0 : minTime - period;
            maxSearchInterval = time + period;
            timeStep         /= 10;
            itCount++;
        }
        Debug.Log("Found closed approach is : "
                  + OVTools.FormatDistance(prevDiff)
                  + " after " + itCount + " iterations");

        debugLine.SetPosition(0, minpos1 * HoloManager.SimZoomScale);
        debugLine.SetPosition(1, minpos2 * HoloManager.SimZoomScale);
        //intMarker1.transform.localPosition = minpos1;// Util.oe2r(OrbitData.parentGM, oe1);
        //intMarker2.transform.localPosition = minpos2;// Util.oe2r(OrbitData.parentGM, oe2);
    }
Exemple #10
0
    void FixedUpdate()
    {
        //FIXME depends on ship tag
        return;

        float scale = lineScale * holo.GetComponent <RenderScale>().realScale;

        foreach (var line in lines)
        {
            line.SetWidth(scale, scale);
        }
        int count = 0;

        foreach (GameObject ship in GameObject.FindGameObjectsWithTag("ship"))
        {
            if (count >= lines.Count)
            {
                Debug.Log("More ships than there are orbit renderers!");
                AddOrbitRenderer(ship);
            }
            if (ship == null)
            {
                Debug.Log("ship is null!");
            }
            var odata = ship.GetComponent <OrbitData>();

            if (odata == null)
            {
                Debug.Log("no orbital data from ship!!");
            }
            //calculate next step
            if (odata.params_[4] != 0)
            {
                Debug.Log("acceleration detected!");
            }

            var  simdeltatime = HoloManager.SimTimeScale * Time.fixedDeltaTime;
            bool integration  = false;
            if (integration)
            {
                odata.rv = Util.rungeKutta4(0, simdeltatime, odata.rv, odata.params_);

                odata.params_[4] = 0;
                odata.params_[5] = 0;
                odata.params_[6] = 0;

                odata.SetOE(Util.rv2oe(OrbitData.parentGM, odata.rv));
            }
            else
            {
                Vector3d r1, v1;
                //var newOE = Util.rv2oe(OrbitData.parentGM, odata.rv);
                FindRV(odata.GetOE(), eventManager.GetSimTime() - odata.GetOETime(), out r1, out v1);
                odata.rv = Util.convertToRv(ref r1, ref v1);
            }

            var oe = odata.GetOE();
            DrawOrbit(lines[count], ref oe);

            if (first)
            {
                var period = oe.GetPeriod();
                oe.print();
                Debug.Log("alt: " + OVTools.FormatDistance((float)odata.getR().magnitude)
                          + " Period: " + OVTools.FormatTime((float)period));
            }

            //draw icons for selected orbits
            if (ship == UXStateManager.GetSource())
            {
                var iconApo = GameObject.Find("iconApo");
                iconApo.transform.localPosition = apo;
                var iconPeri = GameObject.Find("iconPeri");
                iconPeri.transform.localPosition = peri;
            }
            count++;
        }
        first = false;
    }
    /**
     * Creates a 2D matrix of dV, relative to start time and travel time
     * start time relative to current sim time
     * travel time relative to start time
     * HOWEVER: time given to FindVel must be in relative time
     *
     */
    void GeneratePorkChop()
    {
        Debug.Log("Running GeneratePorkChop()");
        float maxHue = 1.0f;
        float minHue = 360.0f;
        //find longest period
        var period1 = oe1.GetPeriod();
        var period2 = oe2.GetPeriod();

        Debug.Log("Period1: " + OVTools.FormatTime((float)period1));
        Debug.Log("Period2: " + OVTools.FormatTime((float)period2));
        period = System.Math.Max(period1, period2);

        //plot is always 1 period across and 1/2 period tall
        double startTimeInc  = period / imgWidth;
        double travelTimeInc = (period) / imgHeight;

        mComputeTime = eventManager.GetSimTime();
        Debug.Log("Compute time: " + mComputeTime);
        //starting time
        for (double x = 0; x < imgWidth; x++)
        {
            //travel time
            for (double y = 1; y <= imgHeight; y++)
            {
                var startTime  = x * startTimeInc;
                var travelTime = y * travelTimeInc;

                Vector3d r1, r2, v1, v2;
                Vector3d injectionVector, rendezvousVector;
                FindVel(startTime + mComputeTime, travelTime, out injectionVector, out rendezvousVector, out r1, out r2, out v1, out v2);
                injectionVector  -= v1;
                rendezvousVector -= v2;

                int   index   = (int)(y - 1) * (int)imgWidth + (int)x;
                float diffMag = 0;
                if (intercept)
                {
                    diffMag = (float)injectionVector.magnitude;
                }
                else //rendezvous
                {
                    diffMag = (float)injectionVector.magnitude + (float)rendezvousVector.magnitude;
                }
                porkChopValues[index] = diffMag;
                maxHue = Mathf.Max(maxHue, diffMag);
                minHue = Mathf.Min(minHue, diffMag);
                if (diffMag < mindv)
                {
                    mindv = diffMag;
                    //Debug.Log("new minimum dv found!");
                    //minDV.dv = diffMag;
                    //minDV.startTime = startTime;
                    //minDV.travelTime = travelTime;
                    mMinDVStartTime  = startTime;
                    mMinDVTravelTime = travelTime;
                    if (!intercept)
                    {
                        //record velocity match burn
                        //burn = target.velocity - current.velocity
                        mMinRendezvousVector = rendezvousVector;
                    }
                }
            } //per row
        }     //per column

        //convert to colors
        //mMinDVStartTime += mComputeTime;
        Debug.Log("Max hue: " + maxHue + " availDV: " + availDV);
        Debug.Log("MinDV StartTime (abs): " + OVTools.FormatTime((float)(mComputeTime + mMinDVStartTime)));

        for (int index = 0; index < imgWidth * imgHeight; index++)
        {
            if (false)//porkChopValues[index] > availDV)
            {
                porkChopColors[index] = Color.black;
            }
            else
            {
                float value = (porkChopValues[index] - mindv) / (maxHue - mindv); //black/white
                porkChopColors[index] = new Color(value, value, value);
                porkChopColors[index] = MuMech.MuUtils.HSVtoRGB((360f / maxHue) * (porkChopValues[index]), 1f, 1.0f, 1f);
            }
        }
    }
    //times are relative
    bool PlotTrajectory(double relStartTime, double relTravelTime)
    {
        //if (!GetOEs()) { return false; } //now OEs are at current time

        var curStartTime = 0; //relStartTime + mComputeTime - eventManager.GetSimTime(); //relative to now

        Debug.Log(            //"curStartTime: " + OVTools.FormatTime((float)curStartTime)
            " startTime: " + OVTools.FormatTime((float)relStartTime)
            + " travelTime: " + OVTools.FormatTime((float)relTravelTime));
        Debug.Log("injection time: " + (relStartTime + mComputeTime).ToString());
        //recompute trajectory w/ those times
        Vector3d initVel, finalVel;
        Vector3d r1, v1;
        Vector3d r2, v2;

        FindVel(relStartTime + mComputeTime, relTravelTime, out initVel, out finalVel,
                out r1, out r2, out v1, out v2);

        OVDebug.projectedR1 = r1;
        Debug.Log("Injection pos: " + r1.ToString());
        mInjectionVector = initVel;// - v1;
        var rendezvousVector = finalVel - v2;

        //convert initial velocity to oe
        VectorD rv          = Util.convertToRv(ref r1, ref initVel);
        var     interceptOE = Util.rv2oe(OrbitData.parentGM, rv);
        //initialize/update maneuver node/orbit w/ oe
        ////tests/////////////////////////
        //testMarker("Marker1-2", startTime);
        //testMarker("Marker1-3", curStartTime + mComputeTime);
        // testMarker("Marker1-4", eventManager.GetSimTime());
        // testMarker("Marker1-5", startTime - eventManager.GetSimTime());

        var marker1 = GameObject.Find("Marker1");

        marker1.transform.localPosition = r1.ToFloat() * HoloManager.SimZoomScale;
        var marker2 = GameObject.Find("Marker2");

        marker2.transform.localPosition = r2.ToFloat() * HoloManager.SimZoomScale;
        var orbitManager = GameObject.Find("OrbitManager").GetComponent <Orbit>();

        orbitManager.updateInterceptLine(ref interceptOE, true);


        //display required deltaV for intercept
        //TODO based on mode: display required deltaV for rendezvous
        var tooltip = trajectoryDeltaVTooltip.GetComponent <Tooltip>();

        tooltip.displayText = "Req dV: " + OVTools.FormatDistance((float)(initVel - v1).magnitude);//.ToString("G2");
        tooltip.Reset();
        tooltip             = shipDeltaVTooltip.GetComponent <Tooltip>();
        tooltip.displayText = "Ship dV: " + OVTools.FormatDistance(UXStateManager.GetSource().GetComponent <OrbitData>().GetDV());//.ToString("G4");
        tooltip.Reset();

        //display start time/travel time
        tooltip             = startTimeTooltip.GetComponent <Tooltip>();
        tooltip.displayText = "Start Time: " + OVTools.FormatTime((float)(relStartTime + mComputeTime));//.ToString("G4");
        //tooltip.displayText = "Start Time: " + OVTools.FormatTime((float)curStartTime);//.ToString("G4");
        tooltip.Reset();
        tooltip             = durationTooltip.GetComponent <Tooltip>();
        tooltip.displayText = "Duration: " + OVTools.FormatTime((float)relTravelTime);//.ToString("G4");
        tooltip.Reset();

        //set scrollers
        var localPos = startTimeIndicator.transform.localPosition;

        localPos.x = time2coord(relStartTime);
        startTimeIndicator.transform.localPosition = localPos;
        //
        localPos   = travelTimeIndicator.transform.localPosition;
        localPos.y = time2coord(relTravelTime);
        travelTimeIndicator.transform.localPosition = localPos;
        //display time of arrival at intersect point
        //display start time at injection point
        return(true);
    }
 public string GetRevenueString()
 {
     return(OVTools.FormatMoney(GetRevenue()));
 }
    // Update is called once per frame
    void Update()
    {
        SimTime += HoloManager.SimTimeScale * Time.fixedDeltaTime;

        if (EventFired)
        {
            EventFired = false;
            Debug.Log("EventManger got an event fired!");
        }
        //get simulation time
        //check if top of queue is time
        if (Events.instance == null)
        {
            Debug.Log("Events not set??");
            return;
        }
        else if (Events.instance.eventQueue == null)
        {
            Debug.Log("Events.instance.eventQueue not set??");
            return;
        }
        Text tt = simTimeObj.GetComponent <Text>();

        tt.text = "SimTime: " + OVTools.FormatTime((float)SimTime);
        if (Events.instance.eventQueue.isNotEmpty())
        {
            while (Events.instance.eventQueue.isNotEmpty() &&
                   Events.instance.eventQueue.GetNextTime() <= SimTime)
            {
                //raise event and get
                var e = Events.instance.eventQueue.Dequeue();
                Debug.Log("Raising event now: " + OVTools.FormatTime(e.GetTime()));
                Events.instance.Raise(e);
                var egui = Events.instance.GUIEventQueue.Dequeue();
                egui.SetActive(false);
            }

            //update time in each event
            var eEvent = Events.instance.eventQueue.GetEnumerator();
            var eGui   = Events.instance.GUIEventQueue.GetEnumerator();
            int index  = 1;
            while (eEvent.MoveNext() && eGui.MoveNext())
            {
                var e         = eEvent.Current.Value;
                var eventText = eGui.Current.Value;

                //update tooltip position
                var eventObjects = Events.instance.eventQueue;
                eventText.transform.localPosition = new Vector3(0, -0.06f * index, 0);
                eventText.transform.localRotation = Quaternion.identity;

                //update tooltip text
                //float time = eGui.Current.Key - (float)SimTime;
                float time    = e.GetTime() - (float)SimTime;
                var   timeStr = OVTools.FormatTime(time);
                var   tooltip = eventText.GetComponent <Tooltip>();
                tooltip.displayText = e.GetSource().name + " " + e.GetAction() + " " + e.GetTarget().name + " @ " + timeStr;
                tooltip.Reset();
                //trigger when next to update text
                index++;
            }
        }
    }