Make roles available to lua

master
Armin Kretschmer 2017-01-09 20:32:39 +01:00
parent ef3dd99228
commit 8f0604b266
3 changed files with 14 additions and 0 deletions

View File

@ -276,6 +276,14 @@ void LuaShipDef::Register()
lua_setfield(l, -3, "equipSlotCapacity");
lua_pop(l, 1);
lua_newtable(l);
for (auto it = st.roles.cbegin(); it != st.roles.cend(); ++it) {
pi_lua_settable(l, it->first.c_str(), it->second);
}
pi_lua_readonly_table_proxy(l, -1);
lua_setfield(l, -3, "roles");
lua_pop(l, 1);
pi_lua_readonly_table_proxy(l, -1);
lua_setfield(l, -3, iter.first.c_str());
lua_pop(l, 1);

View File

@ -103,6 +103,11 @@ ShipType::ShipType(const Id &_id, const std::string &path)
slots[slotname] = data["slots"].get(slotname, 0).asInt();
}
for( Json::Value::iterator role = data["roles"].begin(); role != data["roles"].end(); ++role ) {
const std::string rolename = role.key().asString();
roles[rolename] = data["roles"].get(rolename, 0).asBool();
}
for(int it=0;it<4;it++) thrusterUpgrades[it] = 1.0 + (double(it)/10.0);
for( Json::Value::iterator slot = data["thrust_upgrades"].begin() ; slot != data["thrust_upgrades"].end() ; ++slot ) {
const std::string slotname = slot.key().asString();

View File

@ -52,6 +52,7 @@ struct ShipType {
float linThrust[THRUSTER_MAX];
float angThrust;
std::map<std::string, int> slots;
std::map<std::string, bool> roles;
double thrusterUpgrades[4];
int capacity; // tonnes
int hullMass;