EDCD / EDDI

Companion application for Elite Dangerous
Other
444 stars 81 forks source link

event.population variable in Jumped event incorrect. #118

Closed Darkcyde13 closed 7 years ago

Darkcyde13 commented 7 years ago

Steps to reproduce

Jump into Alpha Caeli system.

Expected

{event.population} in Jumped event gives correct population of the system. In this case, 16796538233.

Observed

{event.population} gave a value of -383330951.

speechresponder.out:- Telemetry obtained. Imperatoria Lanceam is travelling to the Alpha Caeli system. You have visited this system 9 times. Alpha Caeli is a Federation Corporate supporting well over 16 and a half billion people. Blue Natural Holdings is the local power. There are 4 orbital stations and 5 planetary stations in this system. Information: Alpha Caeli is not in any particular state at this time. Fuel level at 94.4%. Population: -383330951

Journal Entry:- { "timestamp":"2017-09-27T20:03:26Z", "event":"FSDJump", "StarSystem":"Alpha Caeli", "StarPos":[45.219,-43.344,-20.125], "SystemAllegiance":"Federation", "SystemEconomy":"$economy_Agri;", "SystemEconomy_Localised":"Agriculture", "SystemGovernment":"$government_Corporate;", "SystemGovernment_Localised":"Corporate", "SystemSecurity":"$SYSTEM_SECURITY_high;", "SystemSecurity_Localised":"High Security", "Population":16796538233, "JumpDist":16.380, "FuelUsed":3.564171, "FuelLevel":60.435829, "Factions":[ { "Name":"Labour of Alpha Caeli", "FactionState":"None", "Government":"Democracy", "Influence":0.051051, "Allegiance":"Independent", "PendingStates":[ { "State":"Famine", "Trend":0 } ], "RecoveringStates":[ { "State":"CivilWar", "Trend":0 } ] }, { "Name":"Pilots Federation Local Branch", "FactionState":"None", "Government":"Democracy", "Influence":0.000000, "Allegiance":"PilotsFederation" }, { "Name":"Dangarla Creative Corp.", "FactionState":"None", "Government":"Corporate", "Influence":0.091091, "Allegiance":"Federation", "PendingStates":[ { "State":"Boom", "Trend":1 } ] }, { "Name":"Alpha Caeli Gold Organisation", "FactionState":"Boom", "Government":"Corporate", "Influence":0.250250, "Allegiance":"Federation" }, { "Name":"Alpha Caeli Freedom Party", "FactionState":"None", "Government":"Dictatorship", "Influence":0.052052, "Allegiance":"Independent", "RecoveringStates":[ { "State":"CivilWar", "Trend":0 } ] }, { "Name":"Blue Natural Holdings", "FactionState":"None", "Government":"Corporate", "Influence":0.446446, "Allegiance":"Federation", "RecoveringStates":[ { "State":"Boom", "Trend":1 } ] }, { "Name":"Alpha Caeli Hand Gang", "FactionState":"None", "Government":"Anarchy", "Influence":0.041041, "Allegiance":"Independent" }, { "Name":"Aurora", "FactionState":"None", "Government":"Corporate", "Influence":0.068068, "Allegiance":"Independent", "RecoveringStates":[ { "State":"Boom", "Trend":0 } ] } ], "SystemFaction":"Blue Natural Holdings" }

Investigation

{event.population} in the Jumped event gave the correct population for Eurybia, of 125000.

Also, the System Report script has it correctly, saying "...well over 16 and a half billion..." (called from the FSDEngaged event).

In VA, the value for {DEC:EDDI jumped population} is also incorrect, giving the same minus number.

My guess would be that the variable can't handle such a large number.

Darkcyde13 commented 7 years ago

Summary as per conversation:

I have added the new variable {event.population} to the end of my Jumped script in order to test it. When this script is triggered by entering the Alpha Caeli system, and the variable is spoken, it is the wrong value for the population of that system.

The value given is -383330951, but the population of that system is 16796538233. The population is correct in the Journal.

The correct value is used in the FSD Engaged event, where the 'System Report' script is called. In the System Report script, system population is obtained from the SystemDetails() function. So SystemDetails() is providing the correct value.

As a further test of the variable (and VoiceAttack functionality) I have made a command in VA called ((EDDI jumped)). In this I have a command the writes the population event to the VA log. This gives the wrong value for population as well, so the value passed to VA from EDDI is wrong.

richardbuckle commented 7 years ago

Here is the full script:

{_ Context }
{SetState('eddi_context_last_subject', 'jump')}
{SetState('eddi_context_last_action', 'complete')}
{SetState('eddi_context_system_name', system.name)}
{SetState('eddi_context_system_system', system.name)}
{SetState('eddi_context_fuel_remaining', event.fuelremaining)}

{_ Update Fines & Bounties - Check Timers}
{F("FinesBounties_TimerCheck")}

{set statereport to F("System state report")}
{if statereport:
    {_ Pause(2000)}
    Information: {statereport}
}

{F("JumpFuel")}.
{Pause(100)}

{set system to F("Missions_CheckSystem")}
{if system:
    {system}
|else:
    {F("Missions_CheckNearMost")}
}

{set dist to -1}
{set mission_destination to state.eddi_context_mission_destination}

{if mission_destination && mission_destination != "":
    {if mission_destination = system.name:
        {F("Missions_RouteNext")}
    }

|elif state.destination && state.destination != "":
    {set ds to SystemDetails(state.destination)}
    {if !ds.name:
        Your destination is not in the Pilot's Federation star charts.
    |else:
        {set dist to round(Distance(ds.x, ds.y, ds.z, system.x, system.y, system.z),1)}
        {if dist = 0:
            {ShipName()} has arrived at the {P(ds.name)} system.
            {SetState('destination', '')}
        |else:
            Distance to {P(ds.name)} is {dist} light years.
        }
    }
    {SetState('distance', dist)}
}

Population: {event.population}
Tkael commented 7 years ago

According to this reference (https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/keywords/integral-types-table), long can range from -9,223,372,036,854,775,808 to 9,223,372,036,854,775,807. So the variable type 'long' may not be the source. I'll make a visit to the noted system and see if I can replicate the issue.

Tkael commented 7 years ago

I've been able to replicate this issue, though the cause still escapes me. Verbose logging of the issue reveals no exceptions being thrown, but the population is transformed:

2017-09-29T07:00:04 Deserializtion:DeserializeData [D] Deserializing { "timestamp":"2017-09-29T07:00:04Z", "event":"FSDJump", "StarSystem":"Alpha Caeli", "StarPos":[45.219,-43.344,-20.125], "SystemAllegiance":"Federation", "SystemEconomy":"$economy_Agri;", "SystemEconomy_Localised":"Agriculture", "SystemGovernment":"$government_Corporate;", "SystemGovernment_Localised":"Corporate", "SystemSecurity":"$SYSTEM_SECURITY_high;", "SystemSecurity_Localised":"High Security", "Population":16796538233, "JumpDist":21.157, "FuelUsed":0.616191, "FuelLevel":31.383808, "Factions":[ { "Name":"Labour of Alpha Caeli", "FactionState":"None", "Government":"Democracy", "Influence":0.050949, "Allegiance":"Independent", "PendingStates":[ { "State":"Famine", "Trend":0 } ] }, { "Name":"Pilots Federation Local Branch", "FactionState":"None", "Government":"Democracy", "Influence":0.000000, "Allegiance":"PilotsFederation" }, { "Name":"Dangarla Creative Corp.", "FactionState":"None", "Government":"Corporate", "Influence":0.087912, "Allegiance":"Federation", "PendingStates":[ { "State":"Boom", "Trend":1 } ] }, { "Name":"Alpha Caeli Gold Organisation", "FactionState":"Boom", "Government":"Corporate", "Influence":0.251748, "Allegiance":"Federation" }, { "Name":"Alpha Caeli Freedom Party", "FactionState":"None", "Government":"Dictatorship", "Influence":0.053946, "Allegiance":"Independent" }, { "Name":"Blue Natural Holdings", "FactionState":"None", "Government":"Corporate", "Influence":0.448551, "Allegiance":"Federation", "RecoveringStates":[ { "State":"Boom", "Trend":0 } ] }, { "Name":"Alpha Caeli Hand Gang", "FactionState":"None", "Government":"Anarchy", "Influence":0.039960, "Allegiance":"Independent" }, { "Name":"Aurora", "FactionState":"None", "Government":"Corporate", "Influence":0.066933, "Allegiance":"Independent" } ], "SystemFaction":"Blue Natural Holdings" } 
2017-09-29T07:00:04 EDDI:eventHandler [D] Handling event {"system":"Alpha Caeli","x":45.21875,"y":-43.34375,"z":-20.125,"distance":21.157,"fuelused":0.616191,"fuelremaining":31.383808,"allegiance":"Federation","faction":"Blue Natural Holdings","factionstate":"None","economy":"Agriculture","government":"Corporate","security":"High","population":-383330951,"raw":"{ \"timestamp\":\"2017-09-29T07:00:04Z\", \"event\":\"FSDJump\", \"StarSystem\":\"Alpha Caeli\", \"StarPos\":[45.219,-43.344,-20.125], \"SystemAllegiance\":\"Federation\", \"SystemEconomy\":\"$economy_Agri;\", \"SystemEconomy_Localised\":\"Agriculture\", \"SystemGovernment\":\"$government_Corporate;\", \"SystemGovernment_Localised\":\"Corporate\", \"SystemSecurity\":\"$SYSTEM_SECURITY_high;\", \"SystemSecurity_Localised\":\"High Security\", \"Population\":16796538233, \"JumpDist\":21.157, \"FuelUsed\":0.616191, \"FuelLevel\":31.383808, \"Factions\":[ { \"Name\":\"Labour of Alpha Caeli\", \"FactionState\":\"None\", \"Government\":\"Democracy\", \"Influence\":0.050949, \"Allegiance\":\"Independent\", \"PendingStates\":[ { \"State\":\"Famine\", \"Trend\":0 } ] }, { \"Name\":\"Pilots Federation Local Branch\", \"FactionState\":\"None\", \"Government\":\"Democracy\", \"Influence\":0.000000, \"Allegiance\":\"PilotsFederation\" }, { \"Name\":\"Dangarla Creative Corp.\", \"FactionState\":\"None\", \"Government\":\"Corporate\", \"Influence\":0.087912, \"Allegiance\":\"Federation\", \"PendingStates\":[ { \"State\":\"Boom\", \"Trend\":1 } ] }, { \"Name\":\"Alpha Caeli Gold Organisation\", \"FactionState\":\"Boom\", \"Government\":\"Corporate\", \"Influence\":0.251748, \"Allegiance\":\"Federation\" }, { \"Name\":\"Alpha Caeli Freedom Party\", \"FactionState\":\"None\", \"Government\":\"Dictatorship\", \"Influence\":0.053946, \"Allegiance\":\"Independent\" }, { \"Name\":\"Blue Natural Holdings\", \"FactionState\":\"None\", \"Government\":\"Corporate\", \"Influence\":0.448551, \"Allegiance\":\"Federation\", \"RecoveringStates\":[ { \"State\":\"Boom\", \"Trend\":0 } ] }, { \"Name\":\"Alpha Caeli Hand Gang\", \"FactionState\":\"None\", \"Government\":\"Anarchy\", \"Influence\":0.039960, \"Allegiance\":\"Independent\" }, { \"Name\":\"Aurora\", \"FactionState\":\"None\", \"Government\":\"Corporate\", \"Influence\":0.066933, \"Allegiance\":\"Independent\" } ], \"SystemFaction\":\"Blue Natural Holdings\" }","timestamp":"2017-09-29T07:00:04Z","type":"Jumped"} 
2017-09-29T07:00:04 EDDI:eventJumped [D] Jumped to Alpha Caeli 
StivlWrith commented 7 years ago

I take a look on my side with yhe Journal Entry give by Darcyde13. On what I see, the problem look to come from the _getOptionalLong(data, "Population") I make a try with adding two different lines: Logging.Info("Population from log ED getlong: " + getLong(data, "Population")); Logging.Info("Population from log ED getOptionalLong: " + getOptionalLong(data, "Population"));

With the getLong the population report is good with the getOptionalLong, the population report is -383330951

2017-09-29T17:04:28 JournalMonitor:ParseJournalEntry [I] Population from log ED getlong: 16796538233 
2017-09-29T17:04:28 JournalMonitor:ParseJournalEntry [I] Population from log ED getOptionalLong: -383330951 

Could it come becaus oof the (int?) presence in:


        private static long? getOptionalLong(string key, object val)
        {
            if (val == null)
            {
                return null;
            }
            else if (val is long)
            {
                return (int?)(long?)val;
            }
            throw new ArgumentException("Unparseable value for " + key);
        }
Darkcyde13 commented 7 years ago

Just a quick heads up. I found another system that had a similar result, HIP 19925. It has a population of 2767855465 according to the system map. EDDI reports population as -1527111831 from the Jumped event.

Additionally, SystemDetails() in the FSD Engaged event says this system is unpopulated.

Tkael commented 7 years ago

The same bug is affecting both 'FSDJumped' and 'Location' events.

Tkael commented 7 years ago

Pull request generated, tested fix, all appears to be working as intended now.