Exemple #1
0
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);
}
Exemple #2
0
int define_missile(lua_State *L)
{
	return _define_ship(L, ShipType::TAG_MISSILE, &ShipType::missile_ships);
}
Exemple #3
0
int define_static_ship(lua_State *L)
{
	return _define_ship(L, ShipType::TAG_STATIC_SHIP, &ShipType::static_ships);
}
Exemple #4
0
int define_ship(lua_State *L)
{
	return _define_ship(L, ShipType::TAG_SHIP, &ShipType::player_ships);
}