本文整理汇总了C++中Ship::GetLabel方法的典型用法代码示例。如果您正苦于以下问题:C++ Ship::GetLabel方法的具体用法?C++ Ship::GetLabel怎么用?C++ Ship::GetLabel使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Ship
的用法示例。
在下文中一共展示了Ship::GetLabel方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: l_ship_get_equip
/*
* Method: GetEquip
*
* Get a list of equipment in a given equipment slot
*
* > equip = ship:GetEquip(slot, index)
* > equiplist = ship:GetEquip(slot)
*
* Parameters:
*
* slot - a <Constants.EquipSlot> string for the wanted equipment type
*
* index - optional. The equipment position in the slot to fetch. If
* specified the item at that position in the slot will be returned,
* otherwise a table containing all items in the slot will be
* returned instead.
*
* Return:
*
* equip - when index is specified, a <Constants.EquipType> string for the
* item
*
* equiplist - when index is not specified, a table of zero or more
* <Constants.EquipType> strings for all the items in the slot
*
* Availability:
*
* alpha 10
*
* Status:
*
* experimental
*/
static int l_ship_get_equip(lua_State *l)
{
Ship *s = LuaObject<Ship>::CheckFromLua(1);
const char *slotName = luaL_checkstring(l, 2);
Equip::Slot slot = static_cast<Equip::Slot>(LuaConstants::GetConstant(l, "EquipSlot", slotName));
int size = s->m_equipment.GetSlotSize(slot);
if (lua_isnumber(l, 3)) {
// 2-argument version; returns the item in the specified slot index
int idx = lua_tointeger(l, 3) - 1;
if (idx >= size || idx < 0) {
pi_lua_warn(l,
"argument out of range: Ship{%s}:GetEquip('%s', %d)",
s->GetLabel().c_str(), slotName, idx+1);
}
Equip::Type e = (idx >= 0) ? s->m_equipment.Get(slot, idx) : Equip::NONE;
lua_pushstring(l, EnumStrings::GetString("EquipType", e));
return 1;
} else {
// 1-argument version; returns table of equipment items
lua_newtable(l);
for (int idx = 0; idx < size; idx++) {
lua_pushinteger(l, idx+1);
lua_pushstring(l, EnumStrings::GetString("EquipType", s->m_equipment.Get(slot, idx)));
lua_rawset(l, -3);
}
return 1;
}
}
示例2: l_ship_set_equip
/*
* Method: SetEquip
*
* Overwrite a single item of equipment in a given equipment slot
*
* > ship:SetEquip(slot, index, equip)
*
* Parameters:
*
* slot - a <Constants.EquipSlot> string for the equipment slot
*
* index - the position to store the item in
*
* equip - a <Constants.EquipType> string for the item
*
* Example:
*
* > -- add a laser to the rear laser mount
* > ship:SetEquip("LASER", 1, "PULSECANNON_1MW")
*
* Availability:
*
* alpha 10
*
* Status:
*
* experimental
*/
static int l_ship_set_equip(lua_State *l)
{
Ship *s = LuaObject<Ship>::CheckFromLua(1);
const char *slotName = luaL_checkstring(l, 2);
Equip::Slot slot = static_cast<Equip::Slot>(LuaConstants::GetConstant(l, "EquipSlot", slotName));
int idx = luaL_checkinteger(l, 3) - 1;
const char *typeName = luaL_checkstring(l, 4);
Equip::Type e = static_cast<Equip::Type>(LuaConstants::GetConstant(l, "EquipType", typeName));
// XXX should go through a Ship::SetEquip() wrapper method that checks mass constraints
if (idx < 0 || idx >= s->m_equipment.GetSlotSize(slot)) {
pi_lua_warn(l,
"argument out of range: Ship{%s}:SetEquip('%s', %d, '%s')",
s->GetLabel().c_str(), slotName, idx+1, typeName);
return 0;
}
s->m_equipment.Set(slot, idx, e);
s->UpdateEquipStats();
return 0;
}
示例3: l_ship_set_fuel_percent
/*
* Method: SetFuelPercent
*
* Sets the thruster fuel tank of the ship to the given precentage of its maximum.
*
* > ship:SetFuelPercent(percent)
*
* Parameters:
*
* percent - optional. A number from 0 to 100. Less then 0 will use 0 and
* greater than 100 will use 100. Defaults to 100.
*
* Example:
*
* > ship:SetFuelPercent(50)
*
* Availability:
*
* alpha 20
*
* Status:
*
* experimental
*/
static int l_ship_set_fuel_percent(lua_State *l)
{
LUA_DEBUG_START(l);
Ship *s = LuaObject<Ship>::CheckFromLua(1);
float percent = 100;
if (lua_isnumber(l, 2)) {
percent = float(luaL_checknumber(l, 2));
if (percent < 0.0f || percent > 100.0f) {
pi_lua_warn(l,
"argument out of range: Ship{%s}:SetFuelPercent(%g)",
s->GetLabel().c_str(), percent);
}
}
s->SetFuel(percent/100.f);
LUA_DEBUG_END(l, 0);
return 0;
}