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


C++ Agent::addWeapon方法代码示例

本文整理汇总了C++中Agent::addWeapon方法的典型用法代码示例。如果您正苦于以下问题:C++ Agent::addWeapon方法的具体用法?C++ Agent::addWeapon怎么用?C++ Agent::addWeapon使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Agent的用法示例。


在下文中一共展示了Agent::addWeapon方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: handleMouseUp

void SelectMenu::handleMouseUp(int x, int y, int button, const int modKeys)
{
    if (button == 3) {
        Agent *selected = g_gameCtrl.agents().squadMember(cur_agent_);
        if (selected == NULL)
            weapon_dragged_ = NULL;
        if (weapon_dragged_) {
            int target = -1;
            if (x >= 20 && x <= 140) {
                if (y >= 84 && y <= 150) {
                    if (x >= 82) {
                        target = 1;
                    } else {
                        target = 0;
                    }
                }
                if (y >= 162 && y <= 228) {
                    if (x >= 82) {
                        target = 3;
                    } else {
                        target = 2;
                    }
                }
            }
            Agent *reciever = target != -1
                ? g_gameCtrl.agents().squadMember(target) : NULL;
            if (target != cur_agent_ && reciever
                && reciever->numWeapons() < 8)
            {
                selected->removeWeapon(weapon_dragged_);
                reciever->addWeapon(weapon_dragged_);

                pSelectedWeap_ = NULL;
                selectedWInstId_ = 0;
                showItemList();
            }
            weapon_dragged_ = NULL;
        }
    }
}
开发者ID:spippolatore,项目名称:freesynd,代码行数:40,代码来源:selectmenu.cpp

示例2: handleAction

void SelectMenu::handleAction(const int actionId, void *ctx, const int modKeys)
{
    if (actionId == teamButId_) {
        tab_ = TAB_TEAM;
        showItemList();
    } else if (actionId == modsButId_) {
        tab_ = TAB_MODS;
        showItemList();
    } else if (actionId == equipButId_) {
        tab_ = TAB_EQUIPS;
        showItemList();
    } else if (actionId == pTeamLBox_->getId()) {
        // get the selected agent from the team listbox
        std::pair<int, void *> * pPair = static_cast<std::pair<int, void *> *> (ctx);
        Agent *pNewAgent = static_cast<Agent *> (pPair->second);
        
        bool found = false;
        // check if selected agent is already part of the mission squad
        for (size_t j = 0; j < AgentManager::kMaxSlot; j++) {
            if (g_Session.agents().squadMember(j) == pNewAgent) {
                found = true;
                break;
            }
        }

        // Agent was not part of the squad
        if (!found) {
            // adds him to the squad
            g_Session.agents().setSquadMember(cur_agent_, pNewAgent);
            // Update current agent name
            getStatic(txtAgentId_)->setTextFormated("#SELECT_SUBTITLE", pNewAgent->getName());
            pTeamLBox_->setSquadLine(cur_agent_, pPair->first);
            updateAcceptEnabled();

            // redraw agent display
            addDirtyRect(158, 110, 340, 260);
            // redraw agent buttons
            dirtyAgentSelector();
        }
        
    } else if (actionId == pModsLBox_->getId()) {
        std::pair<int, void *> * pPair = static_cast<std::pair<int, void *> *> (ctx);
        pSelectedMod_ = static_cast<Mod *> (pPair->second);
        showModWeaponPanel();
    } else if (actionId == pWeaponsLBox_->getId()) {
        std::pair<int, void *> * pPair = static_cast<std::pair<int, void *> *> (ctx);
        pSelectedWeap_ = static_cast<Weapon *> (pPair->second);
        showModWeaponPanel();
    } else if (actionId == cancelButId_) {
        showItemList();
    } else if (actionId == reloadButId_) {
        Agent *selected = g_Session.agents().squadMember(cur_agent_);
        WeaponInstance *wi = selected->weapon(selectedWInstId_ - 1);
        int rldCost = (pSelectedWeap_->ammo()
                        - wi->ammoRemaining()) * pSelectedWeap_->ammoCost();

        if (g_Session.getMoney() >= rldCost) {
            g_Session.setMoney(g_Session.getMoney() - rldCost);
            wi->setAmmoRemaining(pSelectedWeap_->ammo());
            getOption(reloadButId_)->setVisible(false);
            getStatic(moneyTxtId_)->setTextFormated("%d", g_Session.getMoney());
        }
    } else if (actionId == purchaseButId_) {
        // Buying weapon
        if (pSelectedWeap_) {
            if (sel_all_) {
                for (int n = 0; n < 4; n++) {
                    Agent *selected = g_Session.agents().squadMember(n);
                    if (selected && selected->numWeapons() < 8
                        && g_Session.getMoney() >= pSelectedWeap_->cost()) {
                        g_Session.setMoney(g_Session.getMoney() - pSelectedWeap_->cost());
                        selected->addWeapon(pSelectedWeap_->createInstance());
                        getStatic(moneyTxtId_)->setTextFormated("%d", g_Session.getMoney());
                    }
                }
            } else {
                Agent *selected = g_Session.agents().squadMember(cur_agent_);
                if (selected && selected->numWeapons() < 8
                    && g_Session.getMoney() >= pSelectedWeap_->cost()) {
                    g_Session.setMoney(g_Session.getMoney() - pSelectedWeap_->cost());
                    selected->addWeapon(pSelectedWeap_->createInstance());
                    getStatic(moneyTxtId_)->setTextFormated("%d", g_Session.getMoney());
                }
            }
            needRendering();
        } else if (pSelectedMod_) {
            if (sel_all_) {
                for (int n = 0; n < 4; n++) {
                    Agent *selected = g_Session.agents().squadMember(n);
                    if (selected && selected->canHaveMod(pSelectedMod_)
                        && g_Session.getMoney() >= pSelectedMod_->cost()) {
                        selected->addMod(pSelectedMod_);
                        g_Session.setMoney(g_Session.getMoney() - pSelectedMod_->cost());
                        getStatic(moneyTxtId_)->setTextFormated("%d", g_Session.getMoney());
                    }
                }
            } else {
                Agent *selected = g_Session.agents().squadMember(cur_agent_);
                if (selected && selected->canHaveMod(pSelectedMod_)
                    && g_Session.getMoney() >= pSelectedMod_->cost()) {
//.........这里部分代码省略.........
开发者ID:spippolatore,项目名称:freesynd,代码行数:101,代码来源:selectmenu.cpp


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