当前位置: 首页>>代码示例>>C++>>正文


C++ Ship::GetLabel方法代码示例

本文整理汇总了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;
    }
}
开发者ID:zugz,项目名称:pioneer,代码行数:65,代码来源:LuaShip.cpp

示例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;
}
开发者ID:zugz,项目名称:pioneer,代码行数:50,代码来源:LuaShip.cpp

示例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;
}
开发者ID:zugz,项目名称:pioneer,代码行数:46,代码来源:LuaShip.cpp


注:本文中的Ship::GetLabel方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。