本文整理汇总了C++中Craft::getWeapons方法的典型用法代码示例。如果您正苦于以下问题:C++ Craft::getWeapons方法的具体用法?C++ Craft::getWeapons怎么用?C++ Craft::getWeapons使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Craft
的用法示例。
在下文中一共展示了Craft::getWeapons方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: changeByValue
/**
* Increases or decreases the quantity of the selected item to sell.
* @param change How much we want to add or remove.
* @param dir Direction to change, +1 to increase or -1 to decrease.
*/
void SellState::changeByValue(int change, int dir)
{
if (dir > 0)
{
if (0 >= change || getRow().qtySrc <= getRow().amount) return;
change = std::min(getRow().qtySrc - getRow().amount, change);
}
else
{
if (0 >= change || 0 >= getRow().amount) return;
change = std::min(getRow().amount, change);
}
getRow().amount += dir * change;
_total += dir * getRow().cost * change;
// Calculate the change in storage space.
Craft *craft;
Soldier *soldier;
RuleItem *armor, *item, *weapon, *ammo;
double total = 0.0;
switch (getRow().type)
{
case TRANSFER_SOLDIER:
soldier = (Soldier*)getRow().rule;
if (soldier->getArmor()->getStoreItem() != Armor::NONE)
{
armor = _game->getMod()->getItem(soldier->getArmor()->getStoreItem(), true);
_spaceChange += dir * armor->getSize();
}
break;
case TRANSFER_CRAFT:
craft = (Craft*)getRow().rule;
for (std::vector<CraftWeapon*>::iterator w = craft->getWeapons()->begin(); w != craft->getWeapons()->end(); ++w)
{
if (*w)
{
weapon = _game->getMod()->getItem((*w)->getRules()->getLauncherItem(), true);
total += weapon->getSize();
ammo = _game->getMod()->getItem((*w)->getRules()->getClipItem());
if (ammo)
total += ammo->getSize() * (*w)->getClipsLoaded(_game->getMod());
}
}
_spaceChange += dir * total;
break;
case TRANSFER_ITEM:
item = (RuleItem*)getRow().rule;
_spaceChange -= dir * change * item->getSize();
break;
default:
//TRANSFER_SCIENTIST and TRANSFER_ENGINEER do not own anything that takes storage
break;
}
updateItemStrings();
}
示例2: changeByValue
/**
* Increases or decreases the quantity of the selected item to sell.
* @param change How much we want to add or remove.
* @param dir Direction to change, +1 to increase or -1 to decrease.
*/
void SellState::changeByValue(int change, int dir)
{
if (dir > 0)
{
if (0 >= change || getQuantity() <=_qtys[_sel]) return;
change = std::min(getQuantity() - _qtys[_sel], change);
}
else
{
if (0 >= change || 0 >= _qtys[_sel]) return;
change = std::min(_qtys[_sel], change);
}
_qtys[_sel] += dir * change;
_total += dir * getPrice() * change;
// Calculate the change in storage space.
Craft *craft;
RuleItem *armor, *item, *weapon, *ammo;
double total = 0.0;
switch (getType(_sel))
{
case SELL_SOLDIER:
if (_soldiers[_sel]->getArmor()->getStoreItem() != "STR_NONE")
{
armor = _game->getRuleset()->getItem(_soldiers[_sel]->getArmor()->getStoreItem());
_spaceChange += dir * armor->getSize();
}
break;
case SELL_CRAFT:
craft = _crafts[getCraftIndex(_sel)];
for (std::vector<CraftWeapon*>::iterator w = craft->getWeapons()->begin(); w != craft->getWeapons()->end(); ++w)
{
if (*w)
{
weapon = _game->getRuleset()->getItem((*w)->getRules()->getLauncherItem());
total += weapon->getSize();
ammo = _game->getRuleset()->getItem((*w)->getRules()->getClipItem());
if (ammo)
total += ammo->getSize() * (*w)->getClipsLoaded(_game->getRuleset());
}
}
_spaceChange += dir * total;
break;
case SELL_ITEM:
item = _game->getRuleset()->getItem(_items[getItemIndex(_sel)]);
_spaceChange -= dir * change * item->getSize();
break;
default:
break;
}
updateItemStrings();
}
示例3: init
/**
* The craft info can change
* after going into other screens.
*/
void CraftInfoState::init()
{
// Set palette
_game->setPalette(_game->getResourcePack()->getPalette("BACKPALS.DAT")->getColors(Palette::blockOffset(3)), Palette::backPos, 16);
Craft *c = _base->getCrafts()->at(_craft);
_edtCraft->setText(c->getName(_game->getLanguage()));
SurfaceSet *texture = _game->getResourcePack()->getSurfaceSet("BASEBITS.PCK");
texture->getFrame(c->getRules()->getSprite() + 33)->setX(0);
texture->getFrame(c->getRules()->getSprite() + 33)->setY(0);
texture->getFrame(c->getRules()->getSprite() + 33)->blit(_sprite);
std::wstringstream ss;
ss << tr("STR_DAMAGE_UC_").arg(Text::formatPercentage(c->getDamagePercentage()));
if (c->getStatus() == "STR_REPAIRS")
{
int damageDays = (int)ceil((float)c->getDamage() / c->getRules()->getRepairRate() / 24.0f);
ss << L"\n(" << tr("STR_DAY", damageDays) << ")";
}
_txtDamage->setText(ss.str());
std::wstringstream ss2;
ss2 << tr("STR_FUEL").arg(Text::formatPercentage(c->getFuelPercentage()));
if (c->getStatus() == "STR_REFUELLING")
{
int fuelDays = (int) ceil((float)(c->getRules()->getMaxFuel() - c->getFuel()) / c->getRules()->getRefuelRate() / 48.0f);
ss2 << L"\n(" << tr("STR_DAY", fuelDays) << ")";
}
_txtFuel->setText(ss2.str());
if (c->getRules()->getSoldiers() > 0)
{
_crew->clear();
_equip->clear();
Surface *frame1 = texture->getFrame(38);
frame1->setY(0);
for (int i = 0, x = 0; i < c->getNumSoldiers(); ++i, x += 10)
{
frame1->setX(x);
frame1->blit(_crew);
}
Surface *frame2 = texture->getFrame(40);
frame2->setY(0);
int x = 0;
for (int i = 0; i < c->getNumVehicles(); ++i, x += 10)
{
frame2->setX(x);
frame2->blit(_equip);
}
Surface *frame3 = texture->getFrame(39);
for (int i = 0; i < c->getNumEquipment(); i += 4, x += 10)
{
frame3->setX(x);
frame3->blit(_equip);
}
}
else
{
_crew->setVisible(false);
_equip->setVisible(false);
_btnCrew->setVisible(false);
_btnEquip->setVisible(false);
_btnArmor->setVisible(false);
}
if (c->getRules()->getWeapons() > 0)
{
CraftWeapon *w1 = c->getWeapons()->at(0);
if (w1 != 0)
{
Surface *frame = texture->getFrame(w1->getRules()->getSprite() + 48);
frame->setX(0);
frame->setY(0);
frame->blit(_weapon1);
_txtW1Name->setText(tr(w1->getRules()->getType()));
_txtW1Ammo->setText(tr("STR_AMMO_").arg(w1->getAmmo()));
_txtW1Max->setText(tr("STR_MAX").arg(w1->getRules()->getAmmoMax()));
}
else
{
_weapon1->clear();
_txtW1Name->setText(L"");
_txtW1Ammo->setText(L"");
_txtW1Max->setText(L"");
}
}
else
{
_weapon1->setVisible(false);
_btnW1->setVisible(false);
//.........这里部分代码省略.........
示例4: btnOkClick
/**
* Sells the selected items.
* @param action Pointer to an action.
*/
void SellState::btnOkClick(Action *action)
{
_game->getSavedGame()->setFunds(_game->getSavedGame()->getFunds() + _total);
for (unsigned int i = 0; i < _qtys.size(); ++i)
{
if (_qtys[i] > 0)
{
// Sell soldiers
if (i < _soldiers.size())
{
for (std::vector<Soldier*>::iterator s = _base->getSoldiers()->begin(); s != _base->getSoldiers()->end(); ++s)
{
if (*s == _soldiers[i])
{
_base->getSoldiers()->erase(s);
break;
}
}
delete _soldiers[i];
}
// Sell crafts
else if (i >= _soldiers.size() && i < _soldiers.size() + _crafts.size())
{
Craft *craft = _crafts[i - _soldiers.size()];
// Remove weapons from craft
for (std::vector<CraftWeapon*>::iterator w = craft->getWeapons()->begin(); w != craft->getWeapons()->end(); ++w)
{
if ((*w) != 0)
{
_base->getItems()->addItem((*w)->getRules()->getLauncherItem());
_base->getItems()->addItem((*w)->getRules()->getClipItem(), (int)floor((double)(*w)->getAmmo() / (*w)->getRules()->getRearmRate()));
}
}
// Remove items from craft
for (std::map<std::string, int>::iterator it = craft->getItems()->getContents()->begin(); it != craft->getItems()->getContents()->end(); ++it)
{
_base->getItems()->addItem(it->first, it->second);
}
// Remove soldiers from craft
for (std::vector<Soldier*>::iterator s = _base->getSoldiers()->begin(); s != _base->getSoldiers()->end(); ++s)
{
if ((*s)->getCraft() == craft)
{
(*s)->setCraft(0);
}
}
// Remove craft
for (std::vector<Craft*>::iterator c = _base->getCrafts()->begin(); c != _base->getCrafts()->end(); ++c)
{
if (*c == craft)
{
_base->getCrafts()->erase(c);
break;
}
}
delete craft;
}
// Sell scientists
else if (_base->getAvailableScientists() > 0 && i == _soldiers.size() + _crafts.size())
{
_base->setScientists(_base->getScientists() - _qtys[i]);
}
// Sell engineers
else if (_base->getAvailableEngineers() > 0 && i == _soldiers.size() + _crafts.size() + _sOffset)
{
_base->setEngineers(_base->getEngineers() - _qtys[i]);
}
// Sell items
else
{
_base->getItems()->removeItem(_items[i - _soldiers.size() - _crafts.size() - _sOffset - _eOffset], _qtys[i]);
}
}
}
_game->popState();
}
示例5: btnOkClick
/**
* Sells the selected items.
* @param action Pointer to an action.
*/
void SellState::btnOkClick(Action *)
{
_game->getSavedGame()->setFunds(_game->getSavedGame()->getFunds() + _total);
for (size_t i = 0; i < _qtys.size(); ++i)
{
if (_qtys[i] > 0)
{
switch (getType(i))
{
case SELL_SOLDIER:
for (std::vector<Soldier*>::iterator s = _base->getSoldiers()->begin(); s != _base->getSoldiers()->end(); ++s)
{
if (*s == _soldiers[i])
{
if ((*s)->getArmor()->getStoreItem() != "STR_NONE")
{
_base->getItems()->addItem((*s)->getArmor()->getStoreItem());
}
_base->getSoldiers()->erase(s);
break;
}
}
delete _soldiers[i];
break;
case SELL_CRAFT:
{
Craft *craft = _crafts[getCraftIndex(i)];
// Remove weapons from craft
for (std::vector<CraftWeapon*>::iterator w = craft->getWeapons()->begin(); w != craft->getWeapons()->end(); ++w)
{
if ((*w) != 0)
{
_base->getItems()->addItem((*w)->getRules()->getLauncherItem());
_base->getItems()->addItem((*w)->getRules()->getClipItem(), (*w)->getClipsLoaded(_game->getRuleset()));
}
}
// Remove items from craft
for (std::map<std::string, int>::iterator it = craft->getItems()->getContents()->begin(); it != craft->getItems()->getContents()->end(); ++it)
{
_base->getItems()->addItem(it->first, it->second);
}
// Remove vehicles from craft
for (std::vector<Vehicle*>::iterator v = craft->getVehicles()->begin(); v != craft->getVehicles()->end(); ++v)
{
_base->getItems()->addItem((*v)->getRules()->getType());
_base->getItems()->addItem((*v)->getRules()->getCompatibleAmmo()->front(), (*v)->getAmmo());
}
// Remove soldiers from craft
for (std::vector<Soldier*>::iterator s = _base->getSoldiers()->begin(); s != _base->getSoldiers()->end(); ++s)
{
if ((*s)->getCraft() == craft)
{
(*s)->setCraft(0);
}
}
// Clear Hangar
for (std::vector<BaseFacility*>::iterator f = _base->getFacilities()->begin(); f != _base->getFacilities()->end(); ++f)
{
if ((*f)->getCraft() == craft)
{
(*f)->setCraft(0);
break;
}
}
// Remove craft
for (std::vector<Craft*>::iterator c = _base->getCrafts()->begin(); c != _base->getCrafts()->end(); ++c)
{
if (*c == craft)
{
_base->getCrafts()->erase(c);
break;
}
}
delete craft;
}
break;
case SELL_SCIENTIST:
_base->setScientists(_base->getScientists() - _qtys[i]);
break;
case SELL_ENGINEER:
_base->setEngineers(_base->getEngineers() - _qtys[i]);
break;
case SELL_ITEM:
if (_base->getItems()->getItem(_items[getItemIndex(i)]) < _qtys[i])
{
const std::string itemName = _items[getItemIndex(i)];
//.........这里部分代码省略.........
示例6: init
/**
* The craft info can change
* after going into other screens.
*/
void CraftInfoState::init()
{
// Set palette
_game->setPalette(_game->getResourcePack()->getPalette("BACKPALS.DAT")->getColors(Palette::blockOffset(3)), Palette::backPos, 16);
Craft *c = _base->getCrafts()->at(_craft);
_edtCraft->setText(c->getName(_game->getLanguage()));
SurfaceSet *texture = _game->getResourcePack()->getSurfaceSet("BASEBITS.PCK");
texture->getFrame(c->getRules()->getSprite() + 33)->setX(0);
texture->getFrame(c->getRules()->getSprite() + 33)->setY(0);
texture->getFrame(c->getRules()->getSprite() + 33)->blit(_sprite);
std::wstringstream ss;
ss << _game->getLanguage()->getString("STR_DAMAGE_UC_") << L'\x01' << c->getDamagePercentage() << "%";
_txtDamage->setText(ss.str());
std::wstringstream ss2;
ss2 << _game->getLanguage()->getString("STR_FUEL") << L'\x01' << c->getFuelPercentage() << "%";
_txtFuel->setText(ss2.str());
if (c->getRules()->getSoldiers() > 0)
{
_crew->clear();
_equip->clear();
Surface *frame1 = texture->getFrame(38);
frame1->setY(0);
for (int i = 0, x = 0; i < c->getNumSoldiers(); ++i, x += 10)
{
frame1->setX(x);
frame1->blit(_crew);
}
Surface *frame2 = texture->getFrame(39);
frame2->setY(0);
int x = 0;
for (int i = 0; i < c->getNumEquipment(); i += 4, x += 10)
{
frame2->setX(x);
frame2->blit(_equip);
}
Surface *frame3 = texture->getFrame(40);
for (int i = 0; i < c->getNumVehicles(); ++i, x += 10)
{
frame3->setX(x);
frame3->blit(_equip);
}
}
else
{
_crew->setVisible(false);
_equip->setVisible(false);
_btnCrew->setVisible(false);
_btnEquip->setVisible(false);
_btnArmor->setVisible(false);
}
if (c->getRules()->getWeapons() > 0)
{
CraftWeapon *w1 = c->getWeapons()->at(0);
if (w1 != 0)
{
Surface *frame = texture->getFrame(w1->getRules()->getSprite() + 48);
frame->setX(0);
frame->setY(0);
frame->blit(_weapon1);
_txtW1Name->setText(_game->getLanguage()->getString(w1->getRules()->getType()));
std::wstringstream ss3;
ss3 << _game->getLanguage()->getString("STR_AMMO_") << L'\x01' << w1->getAmmo();
_txtW1Ammo->setText(ss3.str());
std::wstringstream ss4;
ss4 << _game->getLanguage()->getString("STR_MAX") << L'\x01' << w1->getRules()->getAmmoMax();
_txtW1Max->setText(ss4.str());
}
else
{
_weapon1->clear();
_txtW1Name->setText(L"");
_txtW1Ammo->setText(L"");
_txtW1Max->setText(L"");
}
}
else
{
_weapon1->setVisible(false);
_btnW1->setVisible(false);
_txtW1Name->setVisible(false);
_txtW1Ammo->setVisible(false);
_txtW1Max->setVisible(false);
}
//.........这里部分代码省略.........