Difference between revisions of "Lua-based equipment"
(add a TODO item) |
|||
Line 16: | Line 16: | ||
TODO: A list of all the modifiers used in the C++ code. | TODO: A list of all the modifiers used in the C++ code. | ||
+ | |||
+ | == From the Lua side == | ||
+ | === Accessing the equipment === | ||
+ | The Lua interface to fetch, count, etc, the equipment hasn't changed much, I tried to keep the API changes to a minimum. | ||
+ | The difference is that instead of manipulating constants (well, strings) you will use straight Lua object. | ||
+ | For instance, instead of | ||
+ | <code>Game.player:AddEquip("HYDROGEN", 2)</code> | ||
+ | You'll write | ||
+ | <code>Game.player:AddEquip(cargo.hydrogen, 2)</code> | ||
+ | |||
+ | The canonical equipment is stored in 2 tables, <code>equipment</code> and <code>cargo</code> | ||
+ | The slot names are not in caps anymore, and are the following (with their default size): | ||
+ | * cargo=0, | ||
+ | * engine=1, | ||
+ | * laser_front=1, | ||
+ | * laser_rear=0, | ||
+ | * missile=0, | ||
+ | * ecm=1, | ||
+ | * scanner=1, | ||
+ | * radar=1, | ||
+ | * hypercloud=1, | ||
+ | * hull_autorepair=1, | ||
+ | * energy_booster=1, | ||
+ | * atmo_shield=1, | ||
+ | * cabin=50, | ||
+ | * shield=9999, | ||
+ | * fuel_scoop=1, | ||
+ | * cargo_scoop=1, | ||
+ | * laser_cooler=1, | ||
+ | * cargo_life_support=1, | ||
+ | * autopilot=1 |
Revision as of 16:31, 1 March 2013
As of March 2013, there's been an ongoing effort for about a year to rewrite the equipment system to be able to define and modify random pieces of equipment through Lua. The resulting system is entirely Lua-based, and communicates with C++ only through string->integers pairs called modifiers.
From the C++ side
If you wish to know if there is an ECM installed on ship
, you would just do
int ecm_mod = ship->GetModifier("ecm"); // This gets you the actual value of the modifier, ie the strength of the ECM if (ecm_mod > 0) { BlastAwayThisMissileWithStrength(ecm_mod); }
As the UI is being ported to new-ui and thus is defined in Lua, you shouldn't need to access the equipment directly. If you need more interaction with the equipment than simple modifiers, as it will probably be the case for lasers (not yet implemented at the time of writing), it might be worth it to write specific Lua interfaces that are to be called by the relevant pieces of equipment at install/uninstall time.
TODO: A list of all the modifiers used in the C++ code.
From the Lua side
Accessing the equipment
The Lua interface to fetch, count, etc, the equipment hasn't changed much, I tried to keep the API changes to a minimum.
The difference is that instead of manipulating constants (well, strings) you will use straight Lua object.
For instance, instead of
Game.player:AddEquip("HYDROGEN", 2)
You'll write
Game.player:AddEquip(cargo.hydrogen, 2)
The canonical equipment is stored in 2 tables, equipment
and cargo
The slot names are not in caps anymore, and are the following (with their default size):
* cargo=0, * engine=1, * laser_front=1, * laser_rear=0, * missile=0, * ecm=1, * scanner=1, * radar=1, * hypercloud=1, * hull_autorepair=1, * energy_booster=1, * atmo_shield=1, * cabin=50, * shield=9999, * fuel_scoop=1, * cargo_scoop=1, * laser_cooler=1, * cargo_life_support=1, * autopilot=1