string Weapon::equip_title() const { string et = weapontype[getweapontype(itemtypename())]->get_name(); if (ammo_ > 0) et += " (" + tostring(ammo_) + ")"; return et; }
bool Weapon::acceptable_ammo(const Item& c) const { if (c.is_clip()) return weapontype[getweapontype(itemtypename())]->acceptable_ammo(c.get_itemtypename()); else return false; }
bool Shop::ShopItem::legal() const { bool r = true; switch (itemclass_) { case WEAPON: r = weapontype[getweapontype(itemtypename_)]->is_legal(); break; case CLIP: // Decide if clip is legal by looping through all weapons and // testing if there exists a weapon such that it is legal and // it can take this clip. If no legal weapon can take this type // of clip, the clip is implicitly illegal as well. r = false; for(int i=0; i < (int)weapontype.size(); i++) { if(weapontype[i]->acceptable_ammo(itemtypename_) && weapontype[i]->is_legal()) { r = true; break; } } break; case ARMOR: //r = getarmortype(itemtypename_); break; //Can't be illegal. case LOOT: //r = getloottype(itemtypename_); break; break; } return r; }
bool Weapon::sort_compare_special(Item* other) const { bool reorder = false; if (other != NULL) { int thisi = getweapontype(itemtypename()); int otheri = getweapontype(other->get_itemtypename()); if (thisi < otheri || otheri == -1) reorder = false; else if (thisi > otheri && otheri != -1) reorder = true; else if (other->is_weapon()) { Weapon* w = static_cast<Weapon*>(other); //cast -XML reorder = (this->ammo_ < w->ammo_); } } return reorder; }
bool Shop::ShopItem::valid_item() const { int i=-1; switch (itemclass_) { case WEAPON: i = getweapontype(itemtypename_); break; case CLIP: i = getcliptype(itemtypename_); break; case ARMOR: i = getarmortype(itemtypename_); break; case LOOT: i = getloottype(itemtypename_); break; } return (i != -1); }
int Shop::ShopItem::adjusted_price() const { int p = price_; if (increase_price_with_illegality_ && itemclass_ == WEAPON && valid_item()) { for (int i = weapontype[getweapontype(itemtypename_)]->get_legality(); i < law[LAW_GUNCONTROL]; ++i) { p *= 2; } } return p; }
void CreatureType::give_weapon_civilian(Creature& cr) const { if (law[LAW_GUNCONTROL] == -1 && !LCSrandom(30)) { cr.give_weapon(*weapontype[getweapontype("WEAPON_REVOLVER_38")], NULL); cr.take_clips(*cliptype[getcliptype("CLIP_38")], 4); cr.reload(false); } else if (law[LAW_GUNCONTROL] == -2) { if (!LCSrandom(10)) { cr.give_weapon(*weapontype[getweapontype("WEAPON_SEMIPISTOL_9MM")], NULL); cr.take_clips(*cliptype[getcliptype("CLIP_9")], 4); cr.reload(false); } else if (!LCSrandom(9)) { cr.give_weapon(*weapontype[getweapontype("WEAPON_SEMIPISTOL_45")], NULL); cr.take_clips(*cliptype[getcliptype("CLIP_45")], 4); cr.reload(false); } } }
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; } } } }
const std::string& Shop::ShopItem::get_description() const { if (description_defined_) { return description_; } else { switch (itemclass_) { default: return description_; // Will be "UNDEFINED" case WEAPON: return weapontype[getweapontype(itemtypename_)]->get_name(); case CLIP : return cliptype [getcliptype (itemtypename_)]->get_name(); case ARMOR : return armortype [getarmortype (itemtypename_)]->get_name(); case LOOT : return loottype [getloottype (itemtypename_)]->get_name(); } } }
void CreatureType::give_weapon(Creature& cr) const { const WeaponsAndClips& wc = pickrandom(weapons_and_clips_); if (wc.weapontype == "CIVILIAN") give_weapon_civilian(cr); else if (wc.weapontype != "WEAPON_NONE") { Weapon w(*weapontype[getweapontype(wc.weapontype)], wc.number_weapons.roll()); w.set_number(min(w.get_number(),10L)); while(!w.empty()) cr.give_weapon(w,NULL); if (wc.cliptype != "NONE") { int n = wc.number_clips.roll(); cr.take_clips(*cliptype[getcliptype(wc.cliptype)], n); cr.reload(false); } } }
const attackst* Weapon::get_attack(bool force_ranged, bool force_melee, bool force_no_reload) const { const vector<attackst*>& attacks = weapontype[getweapontype(itemtypename())]->get_attacks(); for (unsigned i = 0; i < attacks.size(); ++i) { if (force_ranged && !attacks[i]->ranged) continue; if (force_melee && attacks[i]->ranged) continue; if (force_no_reload && attacks[i]->uses_ammo && ammo_ == 0) continue; if (attacks[i]->uses_ammo && attacks[i]->ammotype != loaded_cliptype_ && ammo_ != 0) continue; return attacks[i]; } return NULL; }
bool Weapon::is_throwable() const { return weapontype[getweapontype(itemtypename())]->is_throwable(); }
bool Weapon::auto_breaks_locks() const { return weapontype[getweapontype(itemtypename())]->auto_breaks_locks(); }
bool Weapon::acceptable_ammo(const ClipType& c) const { return weapontype[getweapontype(itemtypename())]->acceptable_ammo(c); }
bool Weapon::is_ranged() const { return weapontype[getweapontype(itemtypename())]->is_ranged(); }
long Weapon::get_fencevalue() const { return weapontype[getweapontype(itemtypename())]->get_fencevalue(); }
bool Weapon::uses_ammo() const { return weapontype[getweapontype(itemtypename())]->uses_ammo(); }
bool Weapon::can_threaten_hostages() const { return weapontype[getweapontype(itemtypename())]->can_threaten_hostages(); }
bool Weapon::is_threatening() const { return weapontype[getweapontype(itemtypename())]->is_threatening(); }
bool Weapon::is_legal() const { return weapontype[getweapontype(itemtypename())]->is_legal(); }
int Weapon::get_legality() const { return weapontype[getweapontype(itemtypename())]->get_legality(); }
bool Weapon::is_instrument() const { return weapontype[getweapontype(itemtypename())]->is_instrument(); }
bool Weapon::has_musical_attack() const { return weapontype[getweapontype(itemtypename())]->has_musical_attack(); }
bool Weapon::protects_against_kidnapping() const { return weapontype[getweapontype(itemtypename())]->protects_against_kidnapping(); }
bool Weapon::is_suspicious() const { return weapontype[getweapontype(itemtypename())]->is_suspicious(); }
int Weapon::get_size() const { return weapontype[getweapontype(itemtypename())]->get_size(); }
CreatureType::WeaponsAndClips::WeaponsAndClips(CMarkup& xml, const string& owner) : number_weapons(1), cliptype("APPROPRIATE"), number_clips(4) { // The main position of the CMarkup object is expected not to be changed here. weapontype = xml.GetData(); // Read in values. if(!len(weapontype)) { while(xml.FindChildElem()) { std::string element=xml.GetChildTagName(); if(element=="type") weapontype=xml.GetChildData(); else if(element=="number_weapons") assign_interval(number_weapons,xml.GetChildData(),owner,element); else if(element=="cliptype") cliptype=xml.GetChildData(); else if(element=="number_clips") assign_interval(number_clips,xml.GetChildData(),owner,element); else xmllog.log("Unknown element for weapon in "+owner+": "+element); } } // Check values. if (weapontype != "CIVILIAN") { if (getweapontype(weapontype) == -1) { xmllog.log("Invalid weapon type for " + owner + ": " + weapontype); weapontype = "WEAPON_NONE"; cliptype = "NONE"; } else { const vector<attackst*>& attacks = ::weapontype[getweapontype(weapontype)]->get_attacks(); // Find a usable clip type for the weapon. if (cliptype == "APPROPRIATE") { cliptype = "NONE"; for(int i=0; i<len(attacks); i++) { if(attacks[i]->uses_ammo) { cliptype=attacks[i]->ammotype; break; } } } // Check clip is usable by the weapon. else if (getcliptype(cliptype) != -1) //Must be a clip type too. { int i; for(i=0; i<len(attacks)&&cliptype!=attacks[i]->ammotype; i++); if(i==len(attacks)) { xmllog.log("In " + owner + ", " + cliptype + "can not be used by " + weapontype + "."); cliptype = "NONE"; } } // Undefined clip type. else { xmllog.log("Invalid clip type for " + owner + ": " + cliptype); cliptype = "NONE"; } } } }
bool Weapon::can_graffiti() const { return weapontype[getweapontype(itemtypename())]->can_graffiti(); }
float Weapon::get_bashstrengthmod() const { return weapontype[getweapontype(itemtypename())]->get_bashstrengthmod(); }
const string& Weapon::get_shortname(unsigned subtype) const { return weapontype[getweapontype(itemtypename())]->get_shortname(subtype); }