static void _define_ships(const char *tag, ShipType::Tag stag, std::vector<ShipType::Type> &list) { std::vector<LmrModel*> ship_models; LmrGetModelsWithTag(tag, ship_models); lua_State *L = LmrGetLuaState(); int num = 0; for (std::vector<LmrModel*>::iterator i = ship_models.begin(); i != ship_models.end(); ++i) { LmrModel *model = *i; model->PushAttributeToLuaStack("ship_defs"); if (lua_isnil(L, -1)) { Error("Model %s is tagged as ship but has no ship_defs.", model->GetName()); } else if (lua_istable(L, -1)) { // multiple ship-defs for 1 model for (unsigned int j=0; j<lua_objlen(L,-1); j++) { lua_pushinteger(L, j+1); lua_gettable(L, -2); _define_ship(L, model->GetName(), list, stag); num++; lua_pop(L, 1); } } else { Error("Model %s: ships_def is malformed", model->GetName()); } lua_pop(L, 1); } printf("ShipType: %d ships with tag '%s'\n", num, tag); }
void ShipType::Init() { static bool isInitted = false; if (isInitted) return; isInitted = true; std::vector<LmrModel*> ship_models; LmrGetModelsWithTag("ship", ship_models); lua_State *L = LmrGetLuaState(); int num = 0; for (std::vector<LmrModel*>::iterator i = ship_models.begin(); i != ship_models.end(); ++i) { LmrModel *model = *i; model->PushAttributeToLuaStack("ship_defs"); if (lua_isnil(L, -1)) { Error("Model %s is tagged as ship but has no ship_defs.", model->GetName()); } else if (lua_istable(L, -1)) { // multiple ship-defs for 1 model for (unsigned int i=0; i<lua_objlen(L,-1); i++) { lua_pushinteger(L, i+1); lua_gettable(L, -2); define_ship(L, model->GetName()); num++; lua_pop(L, 1); } } else { Error("Model %s: ships_def is malformed", model->GetName()); } lua_pop(L, 1); } printf("%d ship types.\n", num); }