void player::use(int index){ //WEAPON,ARMOR,CONSUMABLE,ETC Item tmp = load::getItemData(getItemList()->at(index).getID()); if(tmp.getItemType() == "WEAPON"){ getStat()->addAll(0-getWeapon().getiAtk(),0-getWeapon().getiDef(),0-getWeapon().getiMaxHp()); getItemList()->at(index) = load::getItemData(getWeapon().getID()); if(getItemList()->at(index).getID() == 1)delItem(index); setWeapon(tmp.getID()); getStat()->addAll(tmp.getiAtk(),tmp.getiDef(),tmp.getiMaxHp()); cout << "\n\tEquipe "<<tmp.getName()<<endl; }else if(tmp.getItemType() == "ARMOR"){ getStat()->addAll(0-getArmor().getiAtk(),0-getArmor().getiDef(),0-getArmor().getiMaxHp()); getItemList()->at(index) = load::getItemData(getArmor().getID()); if(getItemList()->at(index).getID() == 2)delItem(index); setArmor(tmp.getID()); getStat()->addAll(tmp.getiAtk(),tmp.getiDef(),tmp.getiMaxHp()); cout << "\n\tEquipe "<<tmp.getName()<<endl; }else if(tmp.getItemType() == "CONSUMABLE"){ getStat()->addAll(tmp.getiAtk(),tmp.getiDef(),tmp.getiMaxHp()); getStat()->addHp(tmp.getiHp()); delItem(index); cout << "\tUse "<<tmp.getName()<<endl; }else{ cout << "\n\tCannot use "<<tmp.getName()<<endl; } getch(); }
void GameObj::damage(int amount, SoundManager &sm) { // Process incoming damage if(getArmor() > amount) return; // armor negates all damage else amount -= getArmor(); setHP(getHP() - amount); // SFX t_damaged.Calculate_Ellapsed_Time(); if(t_damaged.TotalTime() >= TIMER_SOUND_DAMAGED) { SoundManager::Sounds soundID; switch(goSettings.getTypeID()) { case Settings::OBJ_ID_ARCHER: soundID = sm.SND_ARCHER_DAMAGED; break; case Settings::OBJ_ID_STONEWALL: soundID = sm.SND_STONEWALL_DAMAGED; break; // case settings.OBJ_T_DOG: soundID = sm.SND_DOG_MELEE; break; // case settings.OBJ_T_SPEARMAN: soundID = sm.SND_SPEARMAN_MELEE; break; // case settings.OBJ_ID_ARCHER: soundID = sm.SND_ARCHER_MELEE; break; default: soundID = sm.SND_ARCHER_DAMAGED; break; } sm.playSound(soundSourceID, soundID, body->GetPosition()); t_damaged.Reset(0.0); } // Special Behavior (defined in derived classes) damageSpecial(amount, sm); // Death sequence if(getHP() < 0) { death(sm); } }
//end void player_init(){ int i = 0; Tile start = tile_start(); Vec2d pos = {start.mBox.x,start.mBox.y}; SDL_Rect bound = {PLAYER_FRAMEW*.2f,PLAYER_FRAMEW*.2f,PLAYER_FRAMEW*.6f, PLAYER_FRAMEH*.6f}; Sprite *player_sprite = sprite_load(player_char_file,PLAYERW, PLAYERH, PLAYER_FRAMEW, PLAYER_FRAMEH); player_sprite->fpl = 9; animCurrent = WALK; player = entity_load(player_sprite,pos, 100, 100, 0 ); slog("Player: X: %i Y: %i", player->position.x, player->position.y); playerBody.image = player->sprite; playerBody.image_slash = sprite_load("images/player/slash/body slash.png",PLAYERW, PLAYERH, PLAYER_FRAMEW, PLAYER_FRAMEH); playerBody.image_slash->fpl = 5; player->boundBox = bound; player->frame_horizontal = 1; player->frame_vertical = 2; player->think = player_think; player->update = player_update; player->player = true; player->team = TEAM_PLAYER; player->p_em = particle_em_new(); weapon_load_all(); armor_load_all(); PlayerEquip.weapon = getWeapon("longsword"); player->weapon = PlayerEquip.weapon; PlayerEquip.head = getArmor("head chain hood"); PlayerEquip.chest = getArmor("chest chain"); }
void ServerPlayer::throwAllEquips(){ room->throwCard(getWeapon(), true); room->throwCard(getArmor(), true); room->throwCard(getDefensiveHorse(), true); room->throwCard(getOffensiveHorse(), true); }
BlockType_t Creature::blockHit(Creature* attacker, CombatType_t combatType, int32_t& damage, bool checkDefense /* = false */, bool checkArmor /* = false */, bool /* field = false */) { BlockType_t blockType = BLOCK_NONE; if (isImmune(combatType)) { damage = 0; blockType = BLOCK_IMMUNITY; } else if (checkDefense || checkArmor) { bool hasDefense = false; if (blockCount > 0) { --blockCount; hasDefense = true; } if (checkDefense && hasDefense) { int32_t defense = getDefense(); damage -= uniform_random(defense / 2, defense); if (damage <= 0) { damage = 0; blockType = BLOCK_DEFENSE; checkArmor = false; } } if (checkArmor) { int32_t armorValue = getArmor(); if (armorValue > 1) { double armorFormula = armorValue * 0.475; int32_t armorReduction = static_cast<int32_t>(std::ceil(armorFormula)); damage -= uniform_random( armorReduction, armorReduction + static_cast<int32_t>(std::floor(armorFormula)) ); } else if (armorValue == 1) { --damage; } if (damage <= 0) { damage = 0; blockType = BLOCK_ARMOR; } } if (hasDefense && blockType != BLOCK_NONE) { onBlockHit(); } } if (attacker) { attacker->onAttackedCreature(this); attacker->onAttackedCreatureBlockHit(blockType); } onAttacked(); return blockType; }
/** * Generates a brand new saved game with starting data. * @return A new saved game. */ SavedGame *Ruleset::newSave() const { SavedGame *save = new SavedGame(); // Add countries for (std::vector<std::string>::const_iterator i = _countriesIndex.begin(); i != _countriesIndex.end(); ++i) { save->getCountries()->push_back(new Country(getCountry(*i))); } // Adjust funding to total $6M int missing = ((6000 - save->getCountryFunding()/1000) / (int)save->getCountries()->size()) * 1000; for (std::vector<Country*>::iterator i = save->getCountries()->begin(); i != save->getCountries()->end(); ++i) { (*i)->setFunding((*i)->getFunding().back() + missing); } save->setFunds(save->getCountryFunding()); // Add regions for (std::vector<std::string>::const_iterator i = _regionsIndex.begin(); i != _regionsIndex.end(); ++i) { save->getRegions()->push_back(new Region(getRegion(*i))); } // Set up IDs std::map<std::string, int> ids; for (std::vector<std::string>::const_iterator i = _craftsIndex.begin(); i != _craftsIndex.end(); ++i) { ids[*i] = 1; } save->initIds(ids); // Set up starting base Base *base = new Base(this); base->load(_startingBase, save, true); // Correct IDs for (std::vector<Craft*>::const_iterator i = base->getCrafts()->begin(); i != base->getCrafts()->end(); ++i) { save->getId((*i)->getRules()->getType()); } // Generate soldiers int soldiers = _startingBase["randomSoldiers"].as<int>(0); for (int i = 0; i < soldiers; ++i) { Soldier *soldier = new Soldier(getSoldier("XCOM"), getArmor("STR_NONE_UC"), &_names, save->getId("STR_SOLDIER")); soldier->setCraft(base->getCrafts()->front()); base->getSoldiers()->push_back(soldier); } save->getBases()->push_back(base); // Setup alien strategy save->getAlienStrategy().init(this); save->setTime(_startingTime); return save; }
int characterShell::getArmor(lua_State* pLua) { auto pCharacter = worldShell::CWorldSingleton::instance()->getPlayer()->getCharacter(); if(pCharacter != nullptr) lua_pushinteger(pLua, pCharacter->getArmor()); return 1; }
BlockType_t Creature::blockHit(Creature* attacker, CombatType_t combatType, int32_t& damage, bool checkDefense /* = false */, bool checkArmor /* = false */, bool /* field = false */) { BlockType_t blockType = BLOCK_NONE; if (isImmune(combatType)) { damage = 0; blockType = BLOCK_IMMUNITY; } else if (checkDefense || checkArmor) { bool hasDefense = false; if (blockCount > 0) { --blockCount; hasDefense = true; } if (checkDefense && hasDefense && canUseDefense) { int32_t defense = getDefense(); damage -= uniform_random(defense / 2, defense); if (damage <= 0) { damage = 0; blockType = BLOCK_DEFENSE; checkArmor = false; } } if (checkArmor) { int32_t armor = getArmor(); if (armor > 3) { damage -= uniform_random(armor / 2, armor - (armor % 2 + 1)); } else if (armor > 0) { --damage; } if (damage <= 0) { damage = 0; blockType = BLOCK_ARMOR; } } if (hasDefense && blockType != BLOCK_NONE) { onBlockHit(); } } if (attacker) { attacker->onAttackedCreature(this); attacker->onAttackedCreatureBlockHit(blockType); } onAttacked(); return blockType; }
//Constructor from the code of AI and the level of the different capacities Unit::Unit(std::string iaCode, int speedLevel, int lifeLevel, int armorLevel, int regenLevel, int damageLevel, int rangeLevel, int firerateLevel) { init_(); this->iaCode_ = iaCode; tree = std::shared_ptr<TreeElement>((TreeElement*)NodeConstructor::create(&iaCode)); getSpeed().upgrade(speedLevel); getLife().upgrade(lifeLevel); getArmor().upgrade(armorLevel); getRegen().upgrade(regenLevel); getDamage().upgrade(damageLevel); getRange().upgrade(rangeLevel); getFirerate().upgrade(firerateLevel); }
void Arrow::removeBullet() { bool isMissed = true; auto instance = GameManager::getInstance(); auto bulletRect = Rect(this->getPositionX() +this->getParent()->getPositionX() - this->getContentSize().width /2, this->getPositionY() +this->getParent()->getPositionY() - this->getContentSize().height/2, this->sprite->getContentSize().width, this->sprite->getContentSize().height ); auto monsterVector = instance->monsterVector; for (int j = 0; j < monsterVector.size(); j++) { auto monster = monsterVector.at(j); auto monsterRect = monster->baseSprite->getBoundingBox(); if (monsterRect.intersectsRect(bulletRect) && monster->getAttackBySoldier()) { auto currHp = monster->getCurrHp(); currHp = currHp - this->getMaxForce() + monster->getArmor(); if(currHp <= 0){ currHp = 0; } monster->setCurrHp( currHp ); monster->getHpBar()->setPercentage((currHp/monster->getMaxHp())*100); monster->getHurt(); isMissed = false; if(currHp == 0){ monster->death(); } break; } } if(isMissed){ sprite->setSpriteFrame(SpriteFrameCache::getInstance()->getSpriteFrameByName("decal_arrow.png")); sprite->runAction(Sequence::create(FadeOut::create(1.0f) ,CallFuncN::create(CC_CALLBACK_0(Bullet::removeFromParent, this)) , NULL)); }else{ this->removeFromParent(); } }
/// <summary> /// When this fighter died, he will give some item and some gold to the fighter who killed him. /// </summary> void Enemy::onDeath(Fighter &player) { m_drop->addGold(Randomiser(1,10).getRandomNumber() * getLevel()); if (Randomiser(1, 15).getRandomNumber() == Randomiser(1, 15).getRandomNumber()) { m_drop->addWeapon(getWeapons()); } if (Randomiser(1, 15).getRandomNumber() == Randomiser(1, 15).getRandomNumber()) { m_drop->addArmor(getArmor()); } player.setDrop(*m_drop); player.setExperiencePoints(m_experiencePoints + player.getExperiencePoints()); }
/*********************************************************************** * Character * damage ***********************************************************************/ void fired::Character::damage(int damage, sf::Vector2f shot, float knockback, fired::Character *owner) { char dmg[8]; int taken = damage * (1.0f - armorReduction(getArmor())); if (taken <= 0) return; HP -= taken; if (HP <= 0) { dead = true; model->explode(shot - phys.pos, knockback); inventory->dropAll(world); if (owner) if (world->isCharExists(owner)) owner->gainXP(stats.maxHP); } snprintf(dmg, sizeof(dmg), "-%u", taken); world->addText(phys.pos, sf::Color(255, 0, 0, 255), 16, dmg); }
void player::levelUp() { //Assigns to a random value at this point int currentAttribute; int randomAttribute = rand() % 3; switch(randomAttribute) { //Increases Damage case 0: currentAttribute = getBaseDamage() + 1; setBaseDamage(currentAttribute); break; //Increases Armor case 1: currentAttribute = getArmor() + 1; setArmor(currentAttribute); break; //Increase Health case 2: currentAttribute = getMaxHealth() + 1; setHealth(currentAttribute); setMaxHealth(currentAttribute); break; } experience=xpToLevel%experience; if((xpToLevel%2)>0) { xpToLevel=xpToLevel*1.5; xpToLevel++; } else { xpToLevel=xpToLevel*1.5; } int levelHolder=getLevel(); levelHolder++; setLevel(levelHolder); return; }
/************************************************************ ** Henchman::defense ** Description: Generates a dice roll from DefenseDice and ** DefenseSides values and returns a final damage value ** after subtracting defense values. If achilles attack ** is successful, damage is halved. ** Parameters: int attkValue ************************************************************/ int Henchman::defense(int attkValue) { if (getAchilles()) // Achilles attack is succesful { attkValue = (attkValue / 2); std::cout << "Damage is halved!\n"; } int defenseTotal = 0, // Reset accumulator attkFinal = 0; for (int d = 0; d < getDefenseDice(); d++) { defenseTotal += rollDice(getDefenseSides()); } attkFinal = attkValue - defenseTotal - getArmor(); if (attkFinal < 0) // Don't allow negative attack values return 0; else return attkFinal; }
/** * Do an amount of damage. * @param position The position defines which part of armor and/or bodypart is hit. * @param power * @param type */ void BattleUnit::damage(Position position, int power, ItemDamageType type) { int damage; UnitSide side; int impactheight; UnitBodyPart bodypart; if (power <= 0) { return; } power *= _unit->getArmor()->getDamageModifier(type); if (type == DT_STUN) { _stunlevel += power; return; } if (position == Position(0, 0, 0)) { side = SIDE_UNDER; } else { // normalize x and y towards north int x = 8, y = 8; switch(_direction) { case 0: // heading north x = position.x; y = 15 - position.y; break; case 1: // somewhere in between 0 and 2 x = (position.x + position.y)/2; y = ((15 - position.y) + position.x)/2; break; case 2: // heading east x = 15 - position.y; y = 15 - position.x; break; case 3: x = (position.y + (15 - position.x))/2; y = (position.x + position.y)/2; break; case 4: // heading south x = 15 - position.x; y = position.y; break; case 5: x = ((15 - position.x) + (15 - position.y))/2; y = (position.y + (15 - position.x))/2; break; case 6: // heading west x = 15 - position.y; y = 15 - position.x; break; case 7: x = ((15 - position.y) + position.x)/2; y = ((15 - position.x) + (15 - position.y))/2; break; } // determine side if (y > 9) side = SIDE_FRONT; else if (y < 6) side = SIDE_REAR; else if (x < 6) side = SIDE_LEFT; else if (x > 9) side = SIDE_RIGHT; else side = SIDE_FRONT; } impactheight = 10*position.z/getHeight(); if (impactheight > 4 && impactheight < 7) // torso { if (side == SIDE_LEFT) { bodypart = BODYPART_LEFTARM; }else if (side == SIDE_RIGHT) { bodypart = BODYPART_RIGHTARM; }else { bodypart = BODYPART_TORSO; } }else if (impactheight >= 7) //head { bodypart = BODYPART_HEAD; }else if (impactheight <=4) //legs { if (side == SIDE_LEFT || side == SIDE_FRONT) { bodypart = BODYPART_LEFTLEG; }else { bodypart = BODYPART_RIGHTLEG; } } damage = (power - getArmor(side)); if (damage > 0) { if (_unit->isWoundable()) { // fatal wounds if (RNG::generate(0,damage) > 2) _fatalWounds[bodypart] += RNG::generate(1,3); if (_fatalWounds[bodypart]) moraleChange(-_fatalWounds[bodypart]); } // armor damage setArmor(getArmor(side) - (damage/10) - 1, side); // health damage _health -= damage; if (_health < 0) _health = 0; } _needPainKiller = true; }
// if you pass in -1's for x and y, we'll figure out where it can go, and return where it went int LogisticsVariant::canAddComponent( LogisticsComponent* pComponent, long& x, long& y ) const { /* weight no longer matters int weight = getWeight(); if ( weight + pComponent->getWeight() > chassis->maxWeight ) return COMPONENT_TOO_HEAVY;*/ if ( getHeat() + pComponent->getHeat() > getMaxHeat() ) return COMPONENT_TOO_HOT; if ( pComponent->getType() == COMPONENT_FORM_JUMPJET ) { if ( !chassis->canHaveJumpJets ) return JUMPJETS_NOT_ALLOWED; else if ( hasJumpJets() ) return ONLY_ONE_JUMPJET_ALLOWED; else if ( ( x!= -1 && x != -2) || ( y != -1 && y != -2 ) ) return COMPONENT_SLOT_FULL; return 0; } else if ( x == -2 && y == -2 ) // trying to put something illegal in jump jet slot return COMPONENT_SLOT_FULL; if ( x!= -1 && y != -1 ) { for ( int i = 0; i < pComponent->getComponentWidth(); i++ ) { for ( int j = 0; j < pComponent->getComponentHeight(); j++ ) { if ( getComponentAtLocation( x + i, y + j) || x + i >= chassis->componentAreaWidth || j + y >= chassis->componentAreaHeight ) return COMPONENT_SLOT_FULL; } } } else { for ( int j = 0; j < chassis->componentAreaHeight && x == -1; j++ ) { for ( int i = 0; i < chassis->componentAreaWidth && x == -1; i++ ) { if ( !getComponentAtLocation( i, j ) ) { bool bAdd = true; for ( int l = 0; l < pComponent->getComponentHeight(); ++l ) { for ( int k =0; k < pComponent->getComponentWidth(); ++k ) { if ( getComponentAtLocation( i +k, j + l ) || ( i + k >= chassis->componentAreaWidth ) || ( j +l >= chassis->componentAreaHeight ) ) { bAdd = false; break; break; } } } if ( bAdd ) { x = i; y = j; } } } } if ( x == -1 || y == -1 ) { return ADD_COMPONENT_FAILED; } } if ( pComponent->getType() == COMPONENT_FORM_BULK ) { if ( getArmor() + 32 > getMaxArmor() ) return NO_MORE_ARMOR; } if ( pComponent->getType() == COMPONENT_FORM_SENSOR ) { if ( !chassis->canHaveAdvSensor ) return SENSORS_NOT_ALLOWED; else if ( hasSensor() ) return ONLY_ONE_SENSOR_ALLOWED; } if ( pComponent->getType() == COMPONENT_FORM_ECM ) { if ( !chassis->canHaveECM ) return ECM_NOT_ALLOWED; else if ( hasECM() ) return ONLY_ONE_ECM_ALLOWED; } return 0; }
BlockType_t Creature::blockHit(Creature* attacker, CombatType_t combatType, int32_t& damage, bool checkDefense /* = false */, bool checkArmor /* = false */) { BlockType_t blockType = BLOCK_NONE; if (isImmune(combatType)) { damage = 0; blockType = BLOCK_IMMUNITY; } else if (checkDefense || checkArmor) { bool hasDefense = false; if (blockCount > 0) { --blockCount; hasDefense = true; } if (checkDefense && hasDefense) { int32_t maxDefense = getDefense(); int32_t minDefense = maxDefense / 2; damage -= random_range(minDefense, maxDefense); if (damage <= 0) { damage = 0; blockType = BLOCK_DEFENSE; checkArmor = false; } } if (checkArmor) { int32_t armorValue = getArmor(); int32_t minArmorReduction = 0; int32_t maxArmorReduction = 0; if (armorValue > 1) { minArmorReduction = (int32_t)std::ceil(armorValue * 0.475); maxArmorReduction = (int32_t)std::ceil(((armorValue * 0.475) - 1) + minArmorReduction); } else if (armorValue == 1) { minArmorReduction = 1; maxArmorReduction = 1; } damage -= random_range(minArmorReduction, maxArmorReduction); if (damage <= 0) { damage = 0; blockType = BLOCK_ARMOR; } } if (hasDefense && blockType != BLOCK_NONE) { onBlockHit(blockType); } } if (attacker) { attacker->onAttackedCreature(this); attacker->onAttackedCreatureBlockHit(this, blockType); } onAttacked(); return blockType; }
/** * Sorts all our lists according to their weight. */ void Ruleset::sortLists() { std::map<int, std::string> list; int offset = 0; for (std::vector<std::string>::const_iterator i = _itemsIndex.begin(); i != _itemsIndex.end(); ++i) { while (list.find(getItem(*i)->getListOrder() + offset) != list.end()) { ++offset; } list[getItem(*i)->getListOrder() + offset] = *i; } _itemsIndex.clear(); for (std::map<int, std::string>::const_iterator i = list.begin(); i != list.end(); ++i) { _itemsIndex.push_back(i->second); } list.clear(); offset = 0; for (std::vector<std::string>::const_iterator i = _craftsIndex.begin(); i != _craftsIndex.end(); ++i) { while (list.find(getCraft(*i)->getListOrder() + offset) != list.end()) { ++offset; } list[getCraft(*i)->getListOrder() + offset] = *i; } _craftsIndex.clear(); for (std::map<int, std::string>::const_iterator i = list.begin(); i != list.end(); ++i) { _craftsIndex.push_back(i->second); } list.clear(); offset = 0; for (std::vector<std::string>::const_iterator i = _facilitiesIndex.begin(); i != _facilitiesIndex.end(); ++i) { while (list.find(getBaseFacility(*i)->getListOrder() + offset) != list.end()) { ++offset; } list[getBaseFacility(*i)->getListOrder() + offset] = *i; } _facilitiesIndex.clear(); for (std::map<int, std::string>::const_iterator i = list.begin(); i != list.end(); ++i) { _facilitiesIndex.push_back(i->second); } list.clear(); offset = 0; for (std::vector<std::string>::const_iterator i = _craftWeaponsIndex.begin(); i != _craftWeaponsIndex.end(); ++i) { while (list.find(getItem(getCraftWeapon(*i)->getLauncherItem())->getListOrder() + offset) != list.end()) { ++offset; } list[getItem(getCraftWeapon(*i)->getLauncherItem())->getListOrder() + offset] = *i; } _craftWeaponsIndex.clear(); for (std::map<int, std::string>::const_iterator i = list.begin(); i != list.end(); ++i) { _craftWeaponsIndex.push_back(i->second); } list.clear(); offset = 0; int alternateEntry = 0; for (std::vector<std::string>::const_iterator i = _armorsIndex.begin(); i != _armorsIndex.end(); ++i) { if (getItem(getArmor(*i)->getStoreItem())) { while (list.find(getItem(getArmor(*i)->getStoreItem())->getListOrder() + offset) != list.end()) { ++offset; } list[getItem(getArmor(*i)->getStoreItem())->getListOrder() + offset] = *i; } else { list[alternateEntry] = *i; alternateEntry += 1; } } _armorsIndex.clear(); for (std::map<int, std::string>::const_iterator i = list.begin(); i != list.end(); ++i) { _armorsIndex.push_back(i->second); } list.clear(); offset = 0; for (std::vector<std::string>::const_iterator i = _ufopaediaIndex.begin(); i != _ufopaediaIndex.end(); ++i) { while (list.find(getUfopaediaArticle(*i)->getListOrder() + offset) != list.end()) { ++offset; } list[getUfopaediaArticle(*i)->getListOrder() + offset] = *i; } _ufopaediaIndex.clear(); for (std::map<int, std::string>::const_iterator i = list.begin(); i != list.end(); ++i) { _ufopaediaIndex.push_back(i->second); } list.clear(); offset = 0; for (std::vector<std::string>::const_iterator i = _researchIndex.begin(); i != _researchIndex.end(); ++i) { while (list.find(getResearch(*i)->getListOrder() + offset) != list.end()) { ++offset; } list[getResearch(*i)->getListOrder() + offset] = *i; } _researchIndex.clear(); for (std::map<int, std::string>::const_iterator i = list.begin(); i != list.end(); ++i) { _researchIndex.push_back(i->second); } list.clear(); offset = 0; for (std::vector<std::string>::const_iterator i = _manufactureIndex.begin(); i != _manufactureIndex.end(); ++i) { while (list.find(getManufacture(*i)->getListOrder() + offset) != list.end()) { ++offset; } list[getManufacture(*i)->getListOrder() + offset] = *i; } _manufactureIndex.clear(); for (std::map<int, std::string>::const_iterator i = list.begin(); i != list.end(); ++i) { _manufactureIndex.push_back(i->second); } list.clear(); offset = 0; }
/** * Do an amount of damage. * @param position The position defines which part of armor and/or bodypart is hit. * @param power */ void BattleUnit::damage(Position position, int power) { int damage; UnitSide side; int impactheight; UnitBodyPart bodypart; if (power <= 0) { return; } if (position == Position(0, 0, 0)) { side = SIDE_UNDER; } else { // normalize x and y int x = 8, y = 8; switch(_direction) { case 0: // heading north, all is the same x = position.x; y = position.y; break; case 1: // somewhere in between 0 and 2 x = (position.x + (15 - position.y))/2; y = (position.y + position.x)/2; break; case 2: // heading east x = 15 - position.y; y = position.x; break; case 3: x = ((15 - position.y) + (15 - position.x))/2; y = (position.x + (15 - position.y))/2; break; case 4: // heading south, both axis inversed x = 15 - position.x; y = 15 - position.y; break; case 5: x = ((15 - position.x) + position.y)/2; y = ((15 - position.y) + (15 - position.x))/2; break; case 6: // heading west x = position.y; y = 15 - position.x; break; case 7: x = (position.y + position.x)/2; y = ((15 - position.x) + position.y)/2; break; } // determine side if (y > 9) side = SIDE_FRONT; else if (y < 6) side = SIDE_REAR; else if (x < 6) side = SIDE_LEFT; else if (x > 9) side = SIDE_RIGHT; else side = SIDE_FRONT; } impactheight = 10*position.z/getHeight(); if (impactheight > 4 && impactheight < 7) // torso { if (side == SIDE_LEFT) { bodypart = BODYPART_LEFTARM; }else if (side == SIDE_RIGHT) { bodypart = BODYPART_RIGHTARM; }else { bodypart = BODYPART_TORSO; } }else if (impactheight >= 7) //head { bodypart = BODYPART_HEAD; }else if (impactheight <=4) //legs { if (side == SIDE_LEFT || side == SIDE_FRONT) { bodypart = BODYPART_LEFTLEG; }else { bodypart = BODYPART_RIGHTLEG; } } damage = (power - getArmor(side)); if (damage > 0) { // fatal wounds if (RNG::generate(0,damage) > 2) _fatalWounds[bodypart] += RNG::generate(1,3); if (_fatalWounds[bodypart]) moraleChange(-_fatalWounds[bodypart]); // armor damage setArmor(getArmor(side) - (damage+5)/10, side); // health damage _health -= damage; if (_health < 0) _health = 0; } }
void VEquipScreen::Render() { this->equippedItems.clear(); this->inventoryItems.clear(); fw().Stage_GetPrevious(this->shared_from_this())->Render(); fw().renderer->setPalette(this->pal); fw().renderer->drawFilledRect({0, 0}, fw().Display_GetSize(), Colour{0, 0, 0, 128}); // The labels/values in the stats column are used for lots of different things, so keep them // around clear them and keep them around in a vector so we don't have 5 copies of the same // "reset unused entries" code around std::vector<sp<Label>> statsLabels; std::vector<sp<Label>> statsValues; for (int i = 0; i < 9; i++) { auto labelName = UString::format("LABEL_%d", i + 1); auto label = form->FindControlTyped<Label>(labelName); if (!label) { LogError("Failed to find UI control matching \"%s\"", labelName.c_str()); } label->SetText(""); statsLabels.push_back(label); auto valueName = UString::format("VALUE_%d", i + 1); auto value = form->FindControlTyped<Label>(valueName); if (!value) { LogError("Failed to find UI control matching \"%s\"", valueName.c_str()); } value->SetText(""); statsValues.push_back(value); } auto nameLabel = form->FindControlTyped<Label>("NAME"); auto iconGraphic = form->FindControlTyped<Graphic>("SELECTED_ICON"); // If no vehicle/equipment is highlighted (mouse-over), or if we're dragging equipment around // show the currently selected vehicle stats. // // Otherwise we show the stats of the vehicle/equipment highlighted. if (highlightedEquipment) { iconGraphic->SetImage(highlightedEquipment->equipscreen_sprite); nameLabel->SetText(tr(highlightedEquipment->name)); int statsCount = 0; // All equipment has a weight statsLabels[statsCount]->SetText(tr("Weight")); statsValues[statsCount]->SetText(UString::format("%d", highlightedEquipment->weight)); statsCount++; // Draw equipment stats switch (highlightedEquipment->type) { case VEquipmentType::Type::Engine: { auto &engineType = static_cast<const VEngineType &>(*highlightedEquipment); statsLabels[statsCount]->SetText(tr("Top Speed")); statsValues[statsCount]->SetText(UString::format("%d", engineType.top_speed)); statsCount++; statsLabels[statsCount]->SetText(tr("Power")); statsValues[statsCount]->SetText(UString::format("%d", engineType.power)); break; } case VEquipmentType::Type::Weapon: { auto &weaponType = static_cast<const VWeaponType &>(*highlightedEquipment); statsLabels[statsCount]->SetText(tr("Damage")); statsValues[statsCount]->SetText(UString::format("%d", weaponType.damage)); statsCount++; statsLabels[statsCount]->SetText(tr("Range")); statsValues[statsCount]->SetText(UString::format("%d", weaponType.range)); statsCount++; statsLabels[statsCount]->SetText(tr("Accuracy")); statsValues[statsCount]->SetText(UString::format("%d", weaponType.accuracy)); statsCount++; // Only show rounds if non-zero (IE not infinite ammo) if (highlightedEquipment->max_ammo) { statsLabels[statsCount]->SetText(tr("Rounds")); statsValues[statsCount]->SetText( UString::format("%d", highlightedEquipment->max_ammo)); statsCount++; } break; } case VEquipmentType::Type::General: { auto &generalType = static_cast<const VGeneralEquipmentType &>(*highlightedEquipment); if (generalType.accuracy_modifier) { statsLabels[statsCount]->SetText(tr("Accuracy")); statsValues[statsCount]->SetText( UString::format("%d", generalType.accuracy_modifier)); statsCount++; } if (generalType.cargo_space) { statsLabels[statsCount]->SetText(tr("Cargo")); statsValues[statsCount]->SetText( UString::format("%d", generalType.cargo_space)); statsCount++; } if (generalType.passengers) { statsLabels[statsCount]->SetText(tr("Passengers")); statsValues[statsCount]->SetText(UString::format("%d", generalType.passengers)); statsCount++; } if (generalType.alien_space) { statsLabels[statsCount]->SetText(tr("Aliens Held")); statsValues[statsCount]->SetText( UString::format("%d", generalType.alien_space)); statsCount++; } if (generalType.missile_jamming) { statsLabels[statsCount]->SetText(tr("Jamming")); statsValues[statsCount]->SetText( UString::format("%d", generalType.missile_jamming)); statsCount++; } if (generalType.shielding) { statsLabels[statsCount]->SetText(tr("Shielding")); statsValues[statsCount]->SetText(UString::format("%d", generalType.shielding)); statsCount++; } if (generalType.cloaking) { statsLabels[statsCount]->SetText(tr("Cloaks Craft")); statsCount++; } if (generalType.teleporting) { statsLabels[statsCount]->SetText(tr("Teleports")); statsCount++; } break; } } } else { auto vehicle = this->highlightedVehicle; if (!vehicle) vehicle = this->selected; nameLabel->SetText(vehicle->name); // FIXME: These stats would be great to have a generic (string?) referenced list statsLabels[0]->SetText(tr("Constitution")); if (vehicle->getConstitution() == vehicle->getMaxConstitution()) { statsValues[0]->SetText(UString::format("%d", vehicle->getConstitution())); } else { statsValues[0]->SetText(UString::format("%d/%d", vehicle->getConstitution(), vehicle->getMaxConstitution())); } statsLabels[1]->SetText(tr("Armor")); statsValues[1]->SetText(UString::format("%d", vehicle->getArmor())); // FIXME: This value doesn't seem to be the same as the %age shown in the ui? statsLabels[2]->SetText(tr("Accuracy")); statsValues[2]->SetText(UString::format("%d", vehicle->getAccuracy())); statsLabels[3]->SetText(tr("Top Speed")); statsValues[3]->SetText(UString::format("%d", vehicle->getTopSpeed())); statsLabels[4]->SetText(tr("Acceleration")); statsValues[4]->SetText(UString::format("%d", vehicle->getAcceleration())); statsLabels[5]->SetText(tr("Weight")); statsValues[5]->SetText(UString::format("%d", vehicle->getWeight())); statsLabels[6]->SetText(tr("Fuel")); statsValues[6]->SetText(UString::format("%d", vehicle->getFuel())); statsLabels[7]->SetText(tr("Passengers")); statsValues[7]->SetText( UString::format("%d/%d", vehicle->getPassengers(), vehicle->getMaxPassengers())); statsLabels[8]->SetText(tr("Cargo")); statsValues[8]->SetText( UString::format("%d/%d", vehicle->getCargo(), vehicle->getMaxCargo())); iconGraphic->SetImage(vehicle->type.equip_icon_small); } // Now draw the form, the actual equipment is then drawn on top form->Render(); auto paperDollControl = form->FindControlTyped<Graphic>("PAPER_DOLL"); Vec2<int> equipOffset = paperDollControl->Location + form->Location; // Draw the equipment grid { for (auto &slot : selected->type.equipment_layout_slots) { Vec2<int> p00 = (slot.bounds.p0 * EQUIP_GRID_SLOT_SIZE) + equipOffset; Vec2<int> p11 = (slot.bounds.p1 * EQUIP_GRID_SLOT_SIZE) + equipOffset; Vec2<int> p01 = {p00.x, p11.y}; Vec2<int> p10 = {p11.x, p00.y}; if (slot.type == selectionType) { // Scale the sin curve from (-1, 1) to (0, 1) float glowFactor = (sin(this->glowCounter) + 1.0f) / 2.0f; Colour equipColour; switch (selectionType) { case VEquipmentType::Type::Engine: equipColour = EQUIP_GRID_COLOUR_ENGINE; break; case VEquipmentType::Type::Weapon: equipColour = EQUIP_GRID_COLOUR_WEAPON; break; case VEquipmentType::Type::General: equipColour = EQUIP_GRID_COLOUR_GENERAL; break; } Colour selectedColour; selectedColour.r = mix(equipColour.r, EQUIP_GRID_COLOUR.r, glowFactor); selectedColour.g = mix(equipColour.g, EQUIP_GRID_COLOUR.g, glowFactor); selectedColour.b = mix(equipColour.b, EQUIP_GRID_COLOUR.b, glowFactor); selectedColour.a = 255; fw().renderer->drawLine(p00, p01, selectedColour, 2); fw().renderer->drawLine(p01, p11, selectedColour, 2); fw().renderer->drawLine(p11, p10, selectedColour, 2); fw().renderer->drawLine(p10, p00, selectedColour, 2); } else { fw().renderer->drawLine(p00, p01, EQUIP_GRID_COLOUR, 2); fw().renderer->drawLine(p01, p11, EQUIP_GRID_COLOUR, 2); fw().renderer->drawLine(p11, p10, EQUIP_GRID_COLOUR, 2); fw().renderer->drawLine(p10, p00, EQUIP_GRID_COLOUR, 2); } } } // Draw the equipped stuff for (auto &e : selected->equipment) { auto pos = e->equippedPosition; VehicleType::AlignmentX alignX = VehicleType::AlignmentX::Left; VehicleType::AlignmentY alignY = VehicleType::AlignmentY::Top; Rect<int> slotBounds; bool slotFound = false; for (auto &slot : this->selected->type.equipment_layout_slots) { if (slot.bounds.p0 == pos) { alignX = slot.align_x; alignY = slot.align_y; slotBounds = slot.bounds; slotFound = true; break; } } if (!slotFound) { LogError("No matching slot for equipment at {%d,%d}", pos.x, pos.y); } if (pos.x >= EQUIP_GRID_SLOTS.x || pos.y >= EQUIP_GRID_SLOTS.y) { LogError("Equipment at {%d,%d} outside grid", pos.x, pos.y); } pos *= EQUIP_GRID_SLOT_SIZE; pos += equipOffset; int diffX = slotBounds.getWidth() - e->type.equipscreen_size.x; int diffY = slotBounds.getHeight() - e->type.equipscreen_size.y; switch (alignX) { case VehicleType::AlignmentX::Left: pos.x += 0; break; case VehicleType::AlignmentX::Right: pos.x += diffX * EQUIP_GRID_SLOT_SIZE.x; break; case VehicleType::AlignmentX::Centre: pos.x += (diffX * EQUIP_GRID_SLOT_SIZE.x) / 2; break; } switch (alignY) { case VehicleType::AlignmentY::Top: pos.y += 0; break; case VehicleType::AlignmentY::Bottom: pos.y += diffY * EQUIP_GRID_SLOT_SIZE.y; break; case VehicleType::AlignmentY::Centre: pos.y += (diffY * EQUIP_GRID_SLOT_SIZE.y) / 2; break; } fw().renderer->draw(e->type.equipscreen_sprite, pos); Vec2<int> endPos = pos; endPos.x += e->type.equipscreen_sprite->size.x; endPos.y += e->type.equipscreen_sprite->size.y; this->equippedItems.emplace_back(std::make_pair(Rect<int>{pos, endPos}, e)); } // Only draw inventory that can be used by this type of craft VEquipmentType::User allowedEquipmentUser; switch (this->selected->type.type) { case VehicleType::Type::Flying: allowedEquipmentUser = VEquipmentType::User::Air; break; case VehicleType::Type::Ground: allowedEquipmentUser = VEquipmentType::User::Ground; break; default: LogError( "Trying to draw equipment screen of unsupported vehicle type for vehicle \"%s\"", this->selected->name.c_str()); allowedEquipmentUser = VEquipmentType::User::Air; } // Draw the inventory if the selected is in a building, and that is a base auto bld = this->selected->building.lock(); sp<Base> base; if (bld) { base = bld->base; } if (base) { auto inventoryControl = form->FindControlTyped<Graphic>("INVENTORY"); Vec2<int> inventoryPosition = inventoryControl->Location + form->Location; for (auto &invPair : base->inventory) { // The gap between the bottom of the inventory image and the count label static const int INVENTORY_COUNT_Y_GAP = 4; // The gap between the end of one inventory image and the start of the next static const int INVENTORY_IMAGE_X_GAP = 4; auto equipIt = state->getRules().getVehicleEquipmentTypes().find(invPair.first); if (equipIt == state->getRules().getVehicleEquipmentTypes().end()) { // It's not vehicle equipment, skip continue; } auto &equipmentType = *equipIt->second; if (equipmentType.type != this->selectionType) { // Skip equipment of different types continue; } if (!equipmentType.users.count(allowedEquipmentUser)) { // The selected vehicle is not a valid user of the equipment, don't draw continue; } int count = invPair.second; if (count == 0) { // Not in stock continue; } auto countImage = labelFont->getString(UString::format("%d", count)); auto &equipmentImage = equipmentType.equipscreen_sprite; fw().renderer->draw(equipmentImage, inventoryPosition); Vec2<int> countLabelPosition = inventoryPosition; countLabelPosition.y += INVENTORY_COUNT_Y_GAP + equipmentImage->size.y; // FIXME: Center in X? fw().renderer->draw(countImage, countLabelPosition); Vec2<int> inventoryEndPosition = inventoryPosition; inventoryEndPosition.x += equipmentImage->size.x; inventoryEndPosition.y += equipmentImage->size.y; this->inventoryItems.emplace_back(Rect<int>{inventoryPosition, inventoryEndPosition}, equipmentType); // Progress inventory offset by width of image + gap inventoryPosition.x += INVENTORY_IMAGE_X_GAP + equipmentImage->size.x; } } if (this->drawHighlightBox) { Vec2<int> p00 = highlightBox.p0; Vec2<int> p11 = highlightBox.p1; Vec2<int> p01 = {p00.x, p11.y}; Vec2<int> p10 = {p11.x, p00.y}; fw().renderer->drawLine(p00, p01, highlightBoxColour, 1); fw().renderer->drawLine(p01, p11, highlightBoxColour, 1); fw().renderer->drawLine(p11, p10, highlightBoxColour, 1); fw().renderer->drawLine(p10, p00, highlightBoxColour, 1); } if (this->draggedEquipment) { // Draw equipment we're currently dragging (snapping to the grid if possible) Vec2<int> equipmentPos = fw().gamecore->MouseCursor->getPosition() + this->draggedEquipmentOffset; // If this is within the grid try to snap it Vec2<int> equipmentGridPos = equipmentPos - equipOffset; equipmentGridPos /= EQUIP_GRID_SLOT_SIZE; if (equipmentGridPos.x < 0 || equipmentGridPos.x >= EQUIP_GRID_SLOTS.x || equipmentGridPos.y < 0 || equipmentGridPos.y >= EQUIP_GRID_SLOTS.y) { // This is outside thge grid } else { // Inside the grid, snap equipmentPos = equipmentGridPos * EQUIP_GRID_SLOT_SIZE; equipmentPos += equipOffset; } fw().renderer->draw(this->draggedEquipment->equipscreen_sprite, equipmentPos); } fw().gamecore->MouseCursor->Render(); }
std::string Item::getDescription(int32_t lookDistance) const { std::stringstream s; const ItemType& it = items[id]; if (it.name.length()) { if(isStackable() && count > 1){ s << (int)count << " " << it.name << "s."; if(lookDistance <= 1) { s << std::endl << "They weight " << std::fixed << std::setprecision(2) << ((double) count * it.weight) << " oz."; } } else{ if(items[id].runeMagLevel != -1) { s << "a spell rune for level " << it.runeMagLevel << "." << std::endl; s << "It's an \"" << it.name << "\" spell ("; if(getItemCharge()) s << (int)getItemCharge(); else s << "1"; s << "x)."; } else if(isWeapon() && (getAttack() || getDefense())) { if(getAttack()){ s << "a " << it.name << " (Atk:" << (int)getAttack() << " Def:" << (int)getDefense() << ")."; } else{ s << "a " << it.name << " (Def:" << (int)getDefense() << ")."; } } else if(getArmor()){ s << "a " << it.name << " (Arm:" << (int)getArmor() << ")."; } else if(isFluidContainer()){ s << "a " << it.name; if(fluid == 0){ s << ". It is empty."; } else{ s << " of " << items[fluid].name << "."; } } else if(isSplash()){ s << "a " << it.name << " of "; if(fluid == 0){ s << items[1].name << "."; } else{ s << items[fluid].name << "."; } } else if(it.isKey()){ s << "a " << it.name << " (Key:" << actionId << ")."; } else if(it.isGroundTile()){ s << it.name << "."; } else if(it.isContainer()){ s << "a " << it.name << " (Vol:" << getContainer()->capacity() << ")."; } else if(it.allowDistRead){ s << it.name << "." << std::endl; if(lookDistance <= 4){ if(text && text->length() > 0){ s << "You read: " << *text; } else s << "Nothing is written on it."; } else s << "You are too far away to read it."; } else{ s << "a " << it.name << "."; } if(lookDistance <= 1){ double weight = getWeight(); if(weight > 0) s << std::endl << "It weighs " << std::fixed << std::setprecision(2) << weight << " oz."; } if(specialDescription) s << std::endl << specialDescription->c_str(); else if(lookDistance <= 1 && it.description.length()){ s << std::endl << it.description; } } } else s << "an item of type " << id <<"."; return s.str(); }
bool Player::isNude() const{ return getHandcardNum() == 0 && getWeapon() == NULL && getArmor() == NULL && getDefensiveHorse() == NULL && getOffensiveHorse() == NULL; }
uint16_t Player::getModifiedArmor() const { return getModifiedAttribute( inventory, this, getArmor(), &getItemArmorHelper, &getSpellArmorHelper, NULLABLE_ATTRIBUTE_MIN ) + StatsSystem::getStatsSystem()->calculateDamageReductionPoints( this ); }