本文整理汇总了C++中Armor类的典型用法代码示例。如果您正苦于以下问题:C++ Armor类的具体用法?C++ Armor怎么用?C++ Armor使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Armor类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: switch
void BattleCharacterEquipment::removeEquipment(EquipmentPiece *equipment) {
switch (equipment->getType()) {
case EquipmentPiece::WEAPON:
{
Weapon *weapon = dynamic_cast<Weapon*>(equipment);
switch (weapon->getSubtype()) {
case Weapon::MAINHAND:
setMainhand(0);
break;
case Weapon::OFFHAND:
setOffhand(0);
break;
case Weapon::TWOHANDED:
setTwohanded(0);
break;
}
}
break;
case EquipmentPiece::ARMOR:
{
Armor *armor = dynamic_cast<Armor*>(equipment);
switch (armor->getSubtype()) {
case Armor::HELMET:
setHelmet(0);
break;
case Armor::TORSO:
setTorso(0);
break;
case Armor::LEGGINGS:
setLeggings(0);
break;
case Armor::GLOVES:
setGloves(0);
break;
case Armor::BOOTS:
setBoots(0);
break;
}
}
break;
case EquipmentPiece::ACCESSORY:
{
Accessory *accessory = dynamic_cast<Accessory*>(equipment);
switch (accessory->getSubtype()) {
case Accessory::EARRING:
setEarring(0);
break;
case Accessory::NECKLACE:
setNecklace(0);
break;
case Accessory::RING:
setRing(0);
break;
}
}
break;
}
}
示例2: EquipArmor
void EquipArmor(Hero* aHero) {
// Inventory empty?
if (aHero->Inventory.Items() == 0) {
cout << "Empty inventory. Must buy some weapons first." << endl;
return;
}
// Armors on inventory?
if (aHero->Inventory.Armors() == 0) {
cout << "You are not carring any armor." << endl;
return;
}
int choise;
while (true) { // Choose armor from inventory loop
// Display inventory to choose
cout << aHero->GetName() << endl;
aHero->Inventory.DisplayArmors();
cout << "Give the item position of armor to use (0 to exit): ";
cin >> choise;
cin.ignore(); // Ignore new line character
if (choise == 0)
return; // Exit function
// Our list of armors isn't in continues numbers,
// so we examine if the choise is realy an armor
if (aHero->Inventory.GetItemType(choise) != Item::Armor)
cout << "Bad choise. Try again." << endl;
else
break; // Choise made
}
Armor* choosedArmor = (Armor*) aHero->Inventory.Remove(choise);
// Check level
if (choosedArmor->GetLevel() > aHero->GetLevel()) {
cout << "You don't have the right level to wear " << choosedArmor->GetName() << endl;
// Put armor back
aHero->Inventory.Add(choosedArmor);
delete choosedArmor;
return;
}
// If hero doesn't wear any armor
if (aHero->GetArmor() == 0) {
aHero->SetArmor(choosedArmor);
cout << "Now you are wearing " << choosedArmor->GetName() << endl;
}
else {
cout << "You put " << aHero->GetArmor()->GetName() << " into inventory "
<< "and wear " << choosedArmor->GetName() << endl;
aHero->Inventory.Add(aHero->GetArmor()); // Put wearing armor on inventory
aHero->SetArmor(choosedArmor);
}
delete choosedArmor;
return;
}
示例3: computeDamages
float CardboardArmor::computeDamages(const Armor& a){
if(a.getSolidity() > solidity*2){
state -= 30.f;
return 30.f;
}
else if(a.getSolidity() > solidity){
state -= 10.f;
return 10.f;
}
else{
return 0.f;
}
}
示例4: removeArmor
Armor Inventory::removeArmor(string itemName, int xCord, int yCord){
Armor newArmor;
for (int i = 0; i < armorSets.size(); ++i){
if (armorSets[i].getName() == itemName) {
//Invoke new Weapon
newArmor = armorSets[i];
newArmor.setCord(xCord, yCord);
//Delete old weapon
armorSets.erase(armorSets.begin() + i);
}
}
return newArmor;
}
示例5: switch
void Shop::ShopItem::choose(squadst& customers, int& buyer) const
{
if (is_available())
{
ledger.subtract_funds(adjusted_price(), EXPENSE_SHOPPING);
switch (itemclass_)
{
case WEAPON:
{
Weapon* i = new Weapon(*weapontype[getweapontype(itemtypename_)]);
customers.squad[buyer]->give_weapon(*i, &location[customers.squad[0]->base]->loot);
if (i->empty())
delete i;
else
location[customers.squad[0]->base]->loot.push_back(i);
break;
}
case CLIP:
{
Clip* i = new Clip(*cliptype[getcliptype(itemtypename_)]);
customers.squad[buyer]->take_clips(*i, 1);
if (i->empty())
delete i;
else
location[customers.squad[0]->base]->loot.push_back(i);
break;
}
case ARMOR:
{
Armor* i = new Armor(*armortype[getarmortype(itemtypename_)]);
customers.squad[buyer]->give_armor(*i, &location[customers.squad[0]->base]->loot);
if (i->empty())
delete i;
else
location[customers.squad[0]->base]->loot.push_back(i);
break;
}
case LOOT:
{
Loot* i = new Loot(*loottype[getloottype(itemtypename_)]);
location[customers.squad[0]->base]->loot.push_back(i);
break;
}
}
}
}
示例6: equip
void Player::equip(Equipment * eq)
{
Armor * pArm = dynamic_cast<Armor*>(eq);
if (pArm != NULL)
{
vInventory.push_back(armor);
armor = pArm;
cout << "You have equipped a " << pArm->getName() << "!" << endl;
}
Weapon * pWeap = dynamic_cast<Weapon *>(eq);
if (pWeap != NULL)
{
vInventory.push_back(weapon);
weapon = pWeap;
cout << "You have equipped a " << pWeap->getName() << "!" << endl;
}
}
示例7: if
bool MenuEquipmentScreen::equipmentFilter(EquipmentPiece *equipment) {
// Filter by type (Weapon, Armor or Accessory)
EquipmentPiece::Type typeFilter;
if (_equippedEquipmentItems.indexOf(_currentEquippedEquipmentItem) < 2)
typeFilter = EquipmentPiece::WEAPON;
else if (_equippedEquipmentItems.indexOf(_currentEquippedEquipmentItem) < 7)
typeFilter = EquipmentPiece::ARMOR;
else
typeFilter = EquipmentPiece::ACCESSORY;
if (equipment->getType() != typeFilter)
return false;
// Filter by subtype
if (typeFilter == EquipmentPiece::WEAPON) {
Weapon *weapon = dynamic_cast<Weapon*>(equipment);
int subTypeFilter = _equippedEquipmentItems.indexOf(_currentEquippedEquipmentItem);
if ((weapon->getSubtype() != Weapon::TWOHANDED) && (subTypeFilter != weapon->getSubtype()))
return false;
} else if (typeFilter == EquipmentPiece::ARMOR) {
Armor *armor = dynamic_cast<Armor*>(equipment);
int subTypeFilter = _equippedEquipmentItems.indexOf(_currentEquippedEquipmentItem);
if (subTypeFilter != armor->getSubtype())
return false;
} else if (typeFilter == EquipmentPiece::ACCESSORY) {
Accessory *accessory = dynamic_cast<Accessory*>(equipment);
int subTypeFilter = _equippedEquipmentItems.indexOf(_currentEquippedEquipmentItem);
if (subTypeFilter != accessory->getSubtype())
return false;
}
QVector<QPair<Class*, int>> classes = equipment->getClasses();
for (int i = 0; i < classes.size(); i++) {
QPair<Class*, int> it = classes.at(i);
if ((it.first == _character->getClass()) && (it.second <= _character->getLevel()))
return true;
}
return false;
}
示例8: costDisplay
void Shop::buy(Human& human, Armor armor)
{
display->showAttributes(armor);
costDisplay(armor.getPrice(), human.getGold());
display->ask("\n| Would you like to buy this item? [y/n]: ");
if (strncmp("y", display->getInputBuffer(), 1) == 0)
{
if (armor.getPrice() <= human.getGold())
{
human.setArmor(armor);
human.decreaseGoldBy(armor.getPrice());
}
else
{
display->text("\n[!]You cannot afford this item\n");
}
}
}
示例9: SoldierArmorState
/**
* Shows the Select Armor window.
* @param action Pointer to an action.
*/
void CraftArmorState::lstSoldiersClick(Action *action)
{
Soldier *s = _base->getSoldiers()->at(_lstSoldiers->getSelectedRow());
if (!(s->getCraft() && s->getCraft()->getStatus() == "STR_OUT"))
{
if (action->getDetails()->button.button == SDL_BUTTON_LEFT)
{
_game->pushState(new SoldierArmorState(_base, _lstSoldiers->getSelectedRow()));
}
else if (action->getDetails()->button.button == SDL_BUTTON_RIGHT)
{
SavedGame *save;
save = _game->getSavedGame();
Armor *a = _game->getMod()->getArmor(save->getLastSelectedArmor());
if (a && (a->getUnits().empty() || std::find(a->getUnits().begin(), a->getUnits().end(), s->getRules()->getType()) != a->getUnits().end()))
{
if (save->getMonthsPassed() != -1)
{
if (_base->getStorageItems()->getItem(a->getStoreItem()) > 0 || a->getStoreItem() == Armor::NONE)
{
if (s->getArmor()->getStoreItem() != Armor::NONE)
{
_base->getStorageItems()->addItem(s->getArmor()->getStoreItem());
}
if (a->getStoreItem() != Armor::NONE)
{
_base->getStorageItems()->removeItem(a->getStoreItem());
}
s->setArmor(a);
_lstSoldiers->setCellText(_lstSoldiers->getSelectedRow(), 2, tr(a->getType()));
}
}
else
{
s->setArmor(a);
_lstSoldiers->setCellText(_lstSoldiers->getSelectedRow(), 2, tr(a->getType()));
}
}
}
}
}
示例10: SoldierArmorState
/**
* Shows the Select Armor window.
* @param action Pointer to an action.
*/
void CraftArmorState::lstSoldiersClick(Action *action)
{
Soldier *s = _base->getSoldiers()->at(_lstSoldiers->getSelectedRow());
if (!(s->getCraft() && s->getCraft()->getStatus() == "STR_OUT"))
{
if (action->getDetails()->button.button == SDL_BUTTON_LEFT)
{
_game->pushState(new SoldierArmorState(_base, _lstSoldiers->getSelectedRow()));
}
else
{
if (_game->getSavedGame()->getMonthsPassed() != -1)
{
SavedGame *_save;
_save = _game->getSavedGame();
Armor *a = _game->getRuleset()->getArmor(_save->getLastSelectedArmor());
if (_base->getItems()->getItem(a->getStoreItem()) > 0 || a->getStoreItem() == "STR_NONE")
{
if (s->getArmor()->getStoreItem() != "STR_NONE")
{
_base->getItems()->addItem(s->getArmor()->getStoreItem());
}
if (a->getStoreItem() != "STR_NONE")
{
_base->getItems()->removeItem(a->getStoreItem());
}
s->setArmor(a);
_lstSoldiers->setCellText(_lstSoldiers->getSelectedRow(), 2, tr(a->getType()));
}
}
}
}
}
示例11: if
Armor* Armor::translateFromXML(QDomElement &armorElement) {
QString name = armorElement.attributeNode("name").value();
Armor::Subtype type;
QString typeString = armorElement.attributeNode("type").value();
if (typeString == "helmet")
type = Armor::HELMET;
else if (typeString == "torso")
type = Armor::TORSO;
else if (typeString == "leggings")
type = Armor::LEGGINGS;
else if (typeString == "gloves")
type = Armor::GLOVES;
else if (typeString == "boots")
type = Armor::BOOTS;
else
throw ProjectException("No type " + typeString + " exist for armor.");
Armor *armor = Armor::create(name, type);
armor->setDescription(armorElement.firstChildElement("description").text());
return armor;
}
示例12: monsterHit
bool Actor::hit(int dmg, const DamageTypes_t damageType) {
tracer << "Actor::hit()..." << endl;
tracer << "Actor: Damage from parameter: " << dmg << endl;
monsterHit(dmg);
tracer << "Actor: Damage after monsterHit(): " << dmg << endl;
dmg = max(1, dmg);
//Filter damage through worn armor
if(isHumanoid()) {
Armor* armor = dynamic_cast<Armor*>(inventory_->getItemInSlot(slot_armorBody));
if(armor != NULL) {
tracer << "Actor: Has armor, running hit on armor" << endl;
dmg = armor->takeDurabilityHitAndGetReducedDamage(dmg, damageType);
if(armor->isDestroyed()) {
tracer << "Actor: Armor was destroyed" << endl;
if(this == eng->player) {
eng->log->addMessage("My " + eng->itemData->getItemRef(armor, itemRef_plain) + " is torn apart!");
}
delete armor;
armor = NULL;
inventory_->getSlot(slot_armorBody)->item = NULL;
}
}
}
// Filter damage through intrinsic armor
// TODO Stuff goes here
statusEffectsHandler_->isHit();
actorSpecific_hit(dmg);
//Damage to corpses
if(deadState != actorDeadState_alive) {
if(dmg >= getHpMax(true) / 2) {
deadState = actorDeadState_mangled;
glyph_ = ' ';
if(isHumanoid()) {
eng->gore->makeGore(pos);
}
}
tracer << "Actor::hit() [DONE]" << endl;
return false;
}
if(this != eng->player || eng->config->BOT_PLAYING == false) {
hp_ -= dmg;
}
const bool IS_ON_BOTTOMLESS = eng->map->featuresStatic[pos.x][pos.y]->isBottomless();
const bool IS_MANGLED = IS_ON_BOTTOMLESS == true ? true : (dmg > ((getHpMax(true) * 5) / 4) ? true : false);
if(getHp() <= 0) {
die(IS_MANGLED, !IS_ON_BOTTOMLESS, !IS_ON_BOTTOMLESS);
actorSpecificDie();
tracer << "Actor::hit() [DONE]" << endl;
return true;
} else {
tracer << "Actor::hit() [DONE]" << endl;
return false;
}
}
示例13: main
int main(int argc, char** argv){
int num_objects = 10;
int num_moving = 5;
string name;
int x, y;
char command;
int t=1;
Player player("player");
Player player2("player2");
//If at least one command-line argument was provided, use it as the number of objects to create.
if (argc > 1) {
num_objects = atoi(argv[1]);
}
if (argc > 2) {
num_moving = atoi(argv[2]);
}
//Create all the non-moving objects
for (int i = 0; i < num_objects - num_moving; i++) {
x = random() % 11;
y = random() % 11;
name = "random object";
if (i < 7) {
name = names[i];
}
collection.push_back(new Object(name, x, y));
}
for (int i = 0; i < num_moving; i++) {
x = random() % 11;
y = random() % 11;
name = "random moving object";
if (i < 5) {
name = moving_names[i];
}
collection.push_back(new Monster(name,x,y));
}
//Create weapons.
for (int i = 0; i < 3; i++) {
x = random() % 11;
y = random() % 11;
name = "weapon";
if (i < 3) {
name = weapon_names[i];
}
collection.push_back(new Weapon(name,x,y));
}
//Create armor.
for (int i = 0; i < 3; i++) {
x = random() % 11;
y = random() % 11;
name = "armor";
if (i < 3) {
name = armor_names[i];
}
collection.push_back(new Armor(name,x,y));
}
do{
while(t==1){
cout << "__________________________________________________"<<endl;
cout << "Player 1" << endl;
cout << "[" << player.x() << ", " << player.y() << "]" << endl;
cout << "Your score is: " << player.score() << endl;
cout << "________________________________________"<<endl;
cout << "Enter a command:" << endl;
cout << " 'i' to move up." << endl;
cout << " 'm' to move down." << endl;
cout << " 'j' to move left." << endl;
cout << " 'k' to move right." << endl;
cout << " 't' to take an item from this room." << endl;
cout << " 'a' to attack a monster in this room." << endl;
cout << " 'q' to quit." << endl;
cout << "__________________________________________________"<<endl;
//Process command and move player.
cin >> command;
switch (command) {
case 'i':
player.move_up();
break;
case 'm':
player.move_down();
//.........这里部分代码省略.........
示例14: State
/**
* Initializes all the elements in the Soldier Armor window.
* @param game Pointer to the core game.
* @param base Pointer to the base to get info from.
* @param soldier ID of the selected soldier.
*/
SoldierArmorState::SoldierArmorState(Game *game, Base *base, size_t soldier) : State(game), _base(base), _soldier(soldier)
{
_screen = false;
// Create objects
_window = new Window(this, 192, 120, 64, 40, POPUP_BOTH);
_btnCancel = new TextButton(140, 16, 90, 136);
_txtTitle = new Text(182, 9, 69, 48);
_txtSoldier = new Text(182, 9, 69, 56);
_txtType = new Text(90, 9, 80, 72);
_txtQuantity = new Text(70, 9, 177, 72);
_lstArmor = new TextList(160, 48, 73, 88);
// Set palette
_game->setPalette(_game->getResourcePack()->getPalette("BACKPALS.DAT")->getColors(Palette::blockOffset(4)), Palette::backPos, 16);
add(_window);
add(_btnCancel);
add(_txtTitle);
add(_txtSoldier);
add(_txtType);
add(_txtQuantity);
add(_lstArmor);
centerAllSurfaces();
// Set up objects
_window->setColor(Palette::blockOffset(13)+10);
_window->setBackground(_game->getResourcePack()->getSurface("BACK14.SCR"));
_btnCancel->setColor(Palette::blockOffset(13)+5);
_btnCancel->setText(_game->getLanguage()->getString("STR_CANCEL_UC"));
_btnCancel->onMouseClick((ActionHandler)&SoldierArmorState::btnCancelClick);
_btnCancel->onKeyboardPress((ActionHandler)&SoldierArmorState::btnCancelClick, (SDLKey)Options::getInt("keyCancel"));
_txtTitle->setColor(Palette::blockOffset(13)+5);
_txtTitle->setAlign(ALIGN_CENTER);
_txtTitle->setText(_game->getLanguage()->getString("STR_SELECT_ARMOR_FOR"));
_txtSoldier->setColor(Palette::blockOffset(13)+5);
_txtSoldier->setAlign(ALIGN_CENTER);
Soldier *s = _base->getSoldiers()->at(_soldier);
_txtSoldier->setText(s->getName());
_txtType->setColor(Palette::blockOffset(13)+5);
_txtType->setText(_game->getLanguage()->getString("STR_TYPE"));
_txtQuantity->setColor(Palette::blockOffset(13)+5);
_txtQuantity->setText(_game->getLanguage()->getString("STR_QUANTITY_UC"));
_lstArmor->setColor(Palette::blockOffset(13));
_lstArmor->setArrowColor(Palette::blockOffset(13)+5);
_lstArmor->setColumns(2, 112, 41);
_lstArmor->setSelectable(true);
_lstArmor->setBackground(_window);
_lstArmor->setMargin(8);
const std::vector<std::string> &armors = _game->getRuleset()->getArmorsList();
for (std::vector<std::string>::const_iterator i = armors.begin(); i != armors.end(); ++i)
{
Armor *a = _game->getRuleset()->getArmor(*i);
if (_base->getItems()->getItem(a->getStoreItem()) > 0)
{
_armors.push_back(a);
std::wstringstream ss;
ss << _base->getItems()->getItem(a->getStoreItem());
_lstArmor->addRow(2, _game->getLanguage()->getString(a->getType()).c_str(), ss.str().c_str());
}
else if (a->getStoreItem() == "STR_NONE")
{
_armors.push_back(a);
_lstArmor->addRow(1, _game->getLanguage()->getString(a->getType()).c_str());
}
}
_lstArmor->onMouseClick((ActionHandler)&SoldierArmorState::lstArmorClick);
}
示例15: ArticleStateTFTD
ArticleStateTFTDArmor::ArticleStateTFTDArmor(ArticleDefinitionTFTD *defs) : ArticleStateTFTD(defs), _row(0)
{
Armor *armor = _game->getMod()->getArmor(defs->id, true);
_lstInfo = new TextList(150, 64, 168, 110);
add(_lstInfo);
_lstInfo->setColor(Palette::blockOffset(0)+2);
_lstInfo->setColumns(2, 125, 25);
_lstInfo->setDot(true);
// Add armor values
addStat("STR_FRONT_ARMOR", armor->getFrontArmor());
addStat("STR_LEFT_ARMOR", armor->getLeftSideArmor());
addStat("STR_RIGHT_ARMOR", armor->getRightSideArmor());
addStat("STR_REAR_ARMOR", armor->getRearArmor());
addStat("STR_UNDER_ARMOR", armor->getUnderArmor());
_lstInfo->addRow(0);
++_row;
// Add damage modifiers
for (int i = 0; i < DAMAGE_TYPES; ++i)
{
ItemDamageType dt = (ItemDamageType)i;
int percentage = (int)Round(armor->getDamageModifier(dt) * 100.0f);
std::string damage = getDamageTypeText(dt);
if (percentage != 100 && damage != "STR_UNKNOWN")
{
addStat(damage, Text::formatPercentage(percentage));
}
}
_lstInfo->addRow(0);
++_row;
// Add unit stats
addStat("STR_TIME_UNITS", armor->getStats()->tu, true);
addStat("STR_STAMINA", armor->getStats()->stamina, true);
addStat("STR_HEALTH", armor->getStats()->health, true);
addStat("STR_BRAVERY", armor->getStats()->bravery, true);
addStat("STR_REACTIONS", armor->getStats()->reactions, true);
addStat("STR_FIRING_ACCURACY", armor->getStats()->firing, true);
addStat("STR_THROWING_ACCURACY", armor->getStats()->throwing, true);
addStat("STR_MELEE_ACCURACY", armor->getStats()->melee, true);
addStat("STR_STRENGTH", armor->getStats()->strength, true);
addStat("STR_PSIONIC_STRENGTH", armor->getStats()->psiStrength, true);
addStat("STR_PSIONIC_SKILL", armor->getStats()->psiSkill, true);
centerAllSurfaces();
}