WizzardMaker / AirlineTycoon

Source code of Airline Tycoon based on the GOG source code release
https://www.gog.com/game/airline_tycoon_deluxe
Other
27 stars 9 forks source link

Hitec formula parsing #42

Open CrazyOrange opened 1 year ago

CrazyOrange commented 1 year ago

Added FormulaParser which reads pareses formulas from Data/calculations.txt using exprtk Math parser. Backwards compatible by using the default formulas if no file is provided. Compiling with /bigobj is only added in debug mode as it seems to be small enough in release mode.

Available formulas: CalcSpeed, CalcReichweite, EnoughPower Available varibales: power, weight, speed, verbrauch, tank. (speed is always zero when used in CalcSpeed formula) Added dependency to jansson lib

CrazyOrange commented 1 year ago

Eric successfully tested this version.

WizzardMaker commented 1 year ago

Would love to see an example calculations.txt file

CrazyOrange commented 1 year ago

Would love to see an example calculations.txt file

A default file could look like this (used the currently used formulas):

CalcSpeed=power <= 0 ? 0 : (power - 6000) * (1000 - 270) / (50000 - 6000) + 270
CalcReichweite=verbrauch <= 0 ? 0 : tank / verbrauch * speed
EnoughPower=power * 4 >= weight
FlaTEriC1983 commented 1 year ago

Would love to see an example calculations.txt file

Hi, this is my calculations.txt in use with my custom builds.csv and relations.csv, works like a charm, with pretty realistic outcome for Hitec-planes

CalcSpeed=power <= 0 ? 0 : ((power / 60000 - 0.5) * (950 - 600)) + 750
CalcReichweite=verbrauch <= 0 ? 0 : tank / verbrauch * speed
EnoughPower=weight <= 120000 ? speed >= 650 : (weight <= 225000 ? speed >= 740 : speed >= 830)

relation.csv builds.csv

WizzardMaker commented 1 year ago

How does the FormularParser/exprtk handle syntax errors? Does it crash or fallback to default with an error message?

Otherwise lgtm

FlaTEriC1983 commented 1 year ago

lgtm

I didn't test this on purpose, but when I accidentally had 0,5 instead of 0.5 in my formula, the game just ended up not showing anything in the line where the plane's speed should be indicated at Hitec. No crash, but no fallback to default either.