ItemType::ItemType(const ItemType &other) { id = other.getId(); name = other.getName(); priority = other.getPriority(); position = other.getPosition(); }
void Start::addItemToPlace(Coord c, Zone* z, Item item) { z->getLocationAt(c)->addItem(item); ItemType* itemType = item.getType(); int light = itemType->getStatValue(Stat::LIGHT); if (light > 0) { myFovCirclePerm(z, c, light, 1); if (z == player->getZone()) { playerFieldOfView(false); } } }
Item Start::removeItemFromPlace(Coord c, Zone* z, int index) { Item item = z->getLocationAt(c)->removeItem(index); ItemType* itemType = item.getType(); int light = itemType->getStatValue(Stat::LIGHT); if (light > 0) { myFovCirclePerm(z, c, light, -1); if (z == player->getZone()) { playerFieldOfView(false); } } return item; }
int main() { ifstream inFile; // file containing operations ofstream outFile; // file containing output string inFileName; // input file external name string outFileName; // output file external name string outputLabel; string command; // operation to be executed int number; ItemType item; UnsortedType list; bool found; int numCommands; // Prompt for file names, read file names, and prepare files cout << "Enter name of input command file; press return." << endl; cin >> inFileName; inFile.open(inFileName.c_str()); cout << "Enter name of output file; press return." << endl; cin >> outFileName; outFile.open(outFileName.c_str()); cout << "Enter name of test run; press return." << endl; cin >> outputLabel; outFile << outputLabel << endl; if (!inFile) { cout << "file not found" << endl; exit(2); } inFile >> command; numCommands = 0; while (command != "Quit") { if (command == "PutItem") { inFile >> number; item.Initialize(number); list.PutItem(item); item.Print(outFile); outFile << " is in list" << endl; } else if (command == "DeleteItem")
RefPtr<_Ty> CelestialObject::_LoadCelestialObject(ItemFactory &factory, uint32 celestialID, // InventoryItem stuff: const ItemType &type, const ItemData &data, // CelestialObject stuff: const CelestialObjectData &cData) { // Our category is celestial; what to do next: switch( type.groupID() ) { /////////////////////////////////////// // Solar system: /////////////////////////////////////// case EVEDB::invGroups::Solar_System: { return SolarSystem::_LoadCelestialObject<SolarSystem>( factory, celestialID, type, data, cData ); } /////////////////////////////////////// // Station: /////////////////////////////////////// case EVEDB::invGroups::Station: { return Station::_LoadCelestialObject<Station>( factory, celestialID, type, data, cData ); } } // Create a generic one: return CelestialObjectRef( new CelestialObject( factory, celestialID, type, data, cData ) ); }
/* * BlueprintType */ BlueprintType::BlueprintType( uint32 _id, const ItemGroup &_group, const TypeData &_data, const BlueprintType *_parentBlueprintType, const ItemType &_productType, const BlueprintTypeData &_bpData) : ItemType(_id, _group, _data), m_parentBlueprintType(_parentBlueprintType), m_productType(_productType), m_productionTime(_bpData.productionTime), m_techLevel(_bpData.techLevel), m_researchProductivityTime(_bpData.researchProductivityTime), m_researchMaterialTime(_bpData.researchMaterialTime), m_researchCopyTime(_bpData.researchCopyTime), m_researchTechTime(_bpData.researchTechTime), m_productivityModifier(_bpData.productivityModifier), m_wasteFactor(_bpData.wasteFactor), m_chanceOfReverseEngineering(_bpData.chanceOfReverseEngineering), m_maxProductionLimit(_bpData.maxProductionLimit) { // asserts for data consistency assert(_bpData.productTypeID == _productType.id()); if(_parentBlueprintType != NULL) assert(_bpData.parentBlueprintTypeID == _parentBlueprintType->id()); }
/* * SolarSystem */ SolarSystem::SolarSystem( ItemFactory &_factory, uint32 _solarSystemID, // InventoryItem stuff: const ItemType &_type, const ItemData &_data, // CelestialObject stuff: const CelestialObjectData &_cData, // SolarSystem stuff: const ItemType &_sunType, const SolarSystemData &_ssData) : CelestialObject(_factory, _solarSystemID, _type, _data, _cData), m_minPosition(_ssData.minPosition), m_maxPosition(_ssData.maxPosition), m_luminosity(_ssData.luminosity), m_border(_ssData.border), m_fringe(_ssData.fringe), m_corridor(_ssData.corridor), m_hub(_ssData.hub), m_international(_ssData.international), m_regional(_ssData.regional), m_constellation(_ssData.constellation), m_security(_ssData.security), m_factionID(_ssData.factionID), m_radius(_ssData.radius), m_sunType(_sunType), m_securityClass(_ssData.securityClass) { // consistency check assert(_sunType.id() == _ssData.sunTypeID); }
std::string Item::getNameDescription(const ItemType& it, const Item* item /*= NULL*/, int32_t subType /*= -1*/, bool addArticle /*= true*/) { if (item) { subType = item->getSubType(); } std::ostringstream s; if (it.name.length()) { if (it.stackable && subType > 1) { if (it.showCount) { s << subType << " "; } s << it.getPluralName(); } else { if (addArticle && !it.article.empty()) { s << it.article << " "; } s << it.name; } } else { s << "an item of type " << it.id; } return s.str(); }
/* * CharacterType */ CharacterType::CharacterType( uint32 _id, uint8 _bloodlineID, // ItemType stuff: const ItemGroup &_group, const TypeData &_data, // CharacterType stuff: const ItemType &_shipType, const CharacterTypeData &_charData) : ItemType(_id, _group, _data), m_bloodlineID(_bloodlineID), m_bloodlineName(_charData.bloodlineName), m_description(_charData.description), m_maleDescription(_charData.maleDescription), m_femaleDescription(_charData.femaleDescription), m_shipType(_shipType), m_corporationID(_charData.corporationID), m_perception(_charData.perception), m_willpower(_charData.willpower), m_charisma(_charData.charisma), m_memory(_charData.memory), m_intelligence(_charData.intelligence), m_shortDescription(_charData.shortDescription), m_shortMaleDescription(_charData.shortMaleDescription), m_shortFemaleDescription(_charData.shortFemaleDescription) { // check for consistency assert(_data.race == _charData.race); assert(_charData.shipTypeID == _shipType.id()); }
void SortedType::RetreiveItem(ItemType& item, bool& found) { int midPoint, first = 0, last = length - 1; bool moreToSearch = (first <= last); found = false; while(moreToSearch && !found) { midPoint = (first + last) / 2; switch(item.ComparedTo(info[midPoint])) { case LESS: last = midPoint - 1; moreToSearch = (first <= last); break; case GREATER: first = midPoint + 1; moreToSearch = (first <= last); break; case EQUAL: found = true; item = info[midPoint]; break; } } }
ItemType SortedType::GetItem(ItemType item, bool& found) { bool moreToSearch; NodeType* location; location = listData; found = false; moreToSearch = (location != NULL); while (moreToSearch && !found) { switch (item.ComparedTo(location->info)) { case LESS : moreToSearch = false; break; case GREATER : location = location->next; moreToSearch = (location != NULL); break; case EQUAL : found = true; item = location->info; break; } } return item; }
/* * InventoryItem */ InventoryItem::InventoryItem( ItemFactory &_factory, uint32 _itemID, const ItemType &_type, const ItemData &_data) : RefObject( 0 ), //attributes(_factory, *this, true, true), mAttributeMap(*this), mDefaultAttributeMap(*this,true), m_saveTimer(0,true), m_factory(_factory), m_itemID(_itemID), m_itemName(_data.name), m_type(_type), m_ownerID(_data.ownerID), m_locationID(_data.locationID), m_flag(_data.flag), m_contraband(_data.contraband), m_singleton(_data.singleton), m_quantity(_data.quantity), m_position(_data.position), m_customInfo(_data.customInfo) { // assert for data consistency assert(_data.typeID == _type.id()); //m_saveTimerExpiryTime = ITEM_DB_SAVE_TIMER_EXPIRY * 60 * 1000; // 10 minutes in milliseconds //m_saveTimer.SetTimer(m_saveTimerExpiryTime); // set timer in milliseconds m_saveTimer.Disable(); // disable timer by default _log(ITEM__TRACE, "Created object %p for item %s (%u).", this, itemName().c_str(), itemID()); }
void SortedType::InsertItem(ItemType item) { int location = 0; bool moreToSearch = (location < length); while(moreToSearch) { switch(item.ComparedTo(info[location])) { case LESS: moreToSearch = false; break; case GREATER: location++; moreToSearch = (location < length); break; } } for(int index = length; index > location; index--) { info[index] = info[index - 1]; } info[location] = item; length++; }
Item* Item::CreateItem(PropStream& propStream) { unsigned short _id; if(!propStream.GET_USHORT(_id)){ return NULL; } ItemType iType = Item::items[_id]; unsigned char _count = 1; if(iType.stackable || iType.isSplash() || iType.isFluidContainer()){ if(!propStream.GET_UCHAR(_count)){ return NULL; } } return Item::CreateItem(_id, _count); }
bool ItemManager::AddItemType(FCULONG id, const string& name, const string& dbTable) { ItemType* pIT = GetItemType(id); bool bResult = false; if ( !pIT ) { pIT = new ItemType; pIT->SetID(id); pIT->SetName(name); pIT->SetDBTable(dbTable); m_lockItemTypes.LockForWrite(); m_mapItemTypes[id] = pIT; m_lockItemTypes.Unlock(); bResult = true; } return bResult; }
void Creature::onRemoveTileItem(const Tile* tile, const Position& pos, const ItemType& iType, const Item* item) { if(isMapLoaded){ if(iType.blockSolid || iType.blockPathFind || iType.isGroundTile()){ if(pos.z == getPosition().z){ updateTileCache(tile, pos); } } } }
void LinkList::Delete (/* in */ ItemType item) { NodeType * prev = NULL; NodeType * current = head; while (current!=NULL && current->info.getLetter() != item.getLetter()) { prev = current; current = current->link; } if (current!=NULL && current->info.getLetter() == item.getLetter()) { if (prev!=NULL) { prev->link = current->link; current->link=NULL; delete current; } else { head = current->link; current->link=NULL; delete current; } } }
void SortedType::DeleteItem(ItemType item) { NodeType* location = listData; NodeType* tempLocation; if(item.ComparedTo(listData->info) == EQUAL) { tempLocation = location; listData = listData->next; } else { while(item.ComparedTo((location->next)->info) != EQUAL) { location = location->next; } tempLocation = location->next; location->next = (location->next)->next; } delete tempLocation; length--; }
void ItemTypeFactory::buildItemTypeTree() { // Set childs for(int i = 0; i < this->mItemTypeList.size(); i++) { if(this->mItemTypeList[i]->getParentId() != -1) { ItemType* currentParent = this->getItemType(this->mItemTypeList[i]->getParentId()); currentParent->addChild(this->mItemTypeList[i]); } } // Set roots this->mItemTypeTree = new TreeData(); for(int i = 0; i < this->mItemTypeList.size(); i++) { if(this->mItemTypeList[i]->isRoot()) this->mItemTypeTree->addRoot(this->mItemTypeList[i]); } return; }
void SortedType::DeleteItem(ItemType item) { int location = 0; while(item.ComparedTo(info[location]) != EQUAL) { location++; } for(int index = location + 1; index< length; index++) { info[index - 1] = info[index]; } length--; }
void SortedType::PutItem(ItemType item) { NodeType* newNode; NodeType* predLoc; NodeType* location; bool moreToSearch; location = listData; predLoc = NULL; moreToSearch = (location != NULL); while(moreToSearch) { switch(item.ComparedTo(location->info)) { case GREATER : predLoc = location; location = location->next; moreToSearch = (location != NULL); //std::cout << "We are in greater\n"; break; case EQUAL : predLoc = location; location = location->next; moreToSearch = false; break; case LESS : moreToSearch = false; break; } } newNode = new NodeType; newNode->info = item; if(predLoc == NULL) { newNode->next = listData; listData = newNode; } else { newNode->next = location; predLoc->next = newNode; } length++; }
RefPtr<_Ty> Owner::_LoadOwner(ItemFactory &factory, uint32 ownerID, // InventoryItem stuff: const ItemType &type, const ItemData &data ) { // decide what to do next: switch( type.groupID() ) { /////////////////////////////////////// // Character: /////////////////////////////////////// case EVEDB::invGroups::Character: { // create character return Character::_LoadOwner<Character>( factory, ownerID, type, data ); } } // fallback to default: return OwnerRef( new Owner( factory, ownerID, type, data ) ); }
RefPtr<_Ty> InventoryItem::_LoadItem(ItemFactory &factory, uint32 itemID, // InventoryItem stuff: const ItemType &type, const ItemData &data) { // See what to do next: switch( type.categoryID() ) { //! TODO not handled. case EVEDB::invCategories::_System: case EVEDB::invCategories::Station: case EVEDB::invCategories::Material: case EVEDB::invCategories::Accessories: case EVEDB::invCategories::Module: case EVEDB::invCategories::Charge: case EVEDB::invCategories::Trading: case EVEDB::invCategories::Bonus: case EVEDB::invCategories::Commodity: case EVEDB::invCategories::Drone: case EVEDB::invCategories::Implant: case EVEDB::invCategories::Deployable: case EVEDB::invCategories::Structure: case EVEDB::invCategories::Reaction: case EVEDB::invCategories::Asteroid: break; /////////////////////////////////////// // Blueprint: /////////////////////////////////////// case EVEDB::invCategories::Blueprint: { return Blueprint::_LoadItem<Blueprint>( factory, itemID, type, data ); } /////////////////////////////////////// // Entity: /////////////////////////////////////// case EVEDB::invCategories::Entity: { if( (type.groupID() == EVEDB::invGroups::Spawn_Container) ) return CargoContainerRef( new CargoContainer( factory, itemID, type, data ) ); else if( (type.groupID() >= EVEDB::invGroups::Asteroid_Angel_Cartel_Frigate && type.groupID() <= EVEDB::invGroups::Deadspace_Serpentis_Frigate) || (type.groupID() >= 755 /* Asteroid Rogue Drone BattleCruiser */ && type.groupID() <= 761 /* Asteroid Rogue Drone Swarm */) || (type.groupID() >= 789 /* Asteroid Angel Cartel Commander Frigate */ && type.groupID() <= 814 /* Asteroid Serpentis Commander Frigate */) || (type.groupID() >= 843 /* Asteroid Rogue Drone Commander BattleCruiser */ && type.groupID() <= 852 /* Asteroid Serpentis Commander Battleship */) || (type.groupID() >= 959 /* Deadspace Sleeper Sleepless Sentinel */ && type.groupID() <= 987 /* Deadspace Sleeper Emergent Patroller */) ) return InventoryItemRef( new InventoryItem(factory, itemID, type, data) ); else return CelestialObjectRef( new CelestialObject( factory, itemID, type, data ) ); } /////////////////////////////////////// // Celestial: /////////////////////////////////////// case EVEDB::invCategories::Celestial: { if( (type.groupID() == EVEDB::invGroups::Secure_Cargo_Container) || (type.groupID() == EVEDB::invGroups::Audit_Log_Secure_Container) || (type.groupID() == EVEDB::invGroups::Freight_Container) || (type.groupID() == EVEDB::invGroups::Cargo_Container) || (type.groupID() == EVEDB::invGroups::Wreck) ) return CargoContainerRef( new CargoContainer( factory, itemID, type, data ) ); else return CelestialObjectRef( new CelestialObject( factory, itemID, type, data ) ); } /////////////////////////////////////// // Ship: /////////////////////////////////////// case EVEDB::invCategories::Ship: { return Ship::_LoadItem<Ship>( factory, itemID, type, data ); } /////////////////////////////////////// // Skill: /////////////////////////////////////// case EVEDB::invCategories::Skill: { return Skill::_LoadItem<Skill>( factory, itemID, type, data ); } /////////////////////////////////////// // Owner: /////////////////////////////////////// case EVEDB::invCategories::Owner: { return Owner::_LoadItem<Owner>( factory, itemID, type, data ); } } // ItemCategory didn't do it, try ItemGroup: switch( type.groupID() ) { /////////////////////////////////////// // Station: /////////////////////////////////////// case EVEDB::invGroups::Station: { return Station::_LoadItem<Station>( factory, itemID, type, data ); } } // Generic item, create one: return InventoryItemRef( new InventoryItem( factory, itemID, type, data ) ); }
std::string Item::getDescription(const ItemType& it, int32_t lookDistance, const Item* item/* = NULL*/, int32_t subType/* = -1*/, bool addArticle/* = true*/) { std::stringstream s; s << getNameDescription(it, item, subType, addArticle); if(item) subType = item->getSubType(); bool dot = true; if(it.isRune()) { s << "("; if(!it.runeSpellName.empty()) s << "\"" << it.runeSpellName << "\", "; s << "Charges:" << subType << ")"; if(it.runeLevel > 0 || it.runeMagLevel > 0 || (it.vocationString != "" && it.wieldInfo == 0)) { s << "." << std::endl << "It can only be used"; if(it.vocationString != "" && it.wieldInfo == 0) s << " by " << it.vocationString; bool begin = true; if(it.runeLevel > 0) { begin = false; s << " with level " << it.runeLevel; } if(it.runeMagLevel > 0) { begin = false; s << " " << (begin ? "with" : "and") << " magic level " << it.runeMagLevel; } if(!begin) s << " or higher"; } } else if(it.weaponType != WEAPON_NONE) { bool begin = true; if(it.weaponType == WEAPON_DIST && it.ammoType != AMMO_NONE) { begin = false; s << " (Range:" << int32_t(item ? item->getShootRange() : it.shootRange); if(it.attack || it.extraAttack || (item && (item->getAttack() || item->getExtraAttack()))) { s << ", Atk " << std::showpos << int32_t(item ? item->getAttack() : it.attack); if(it.extraAttack || (item && item->getExtraAttack())) s << " " << std::showpos << int32_t(item ? item->getExtraAttack() : it.extraAttack) << std::noshowpos; } if(it.hitChance != -1 || (item && item->getHitChance() != -1)) s << ", Hit% " << std::showpos << (item ? item->getHitChance() : it.hitChance) << std::noshowpos; } else if(it.weaponType != WEAPON_AMMO && it.weaponType != WEAPON_WAND) { if(it.attack || it.extraAttack || (item && (item->getAttack() || item->getExtraAttack()))) { begin = false; s << " (Atk:"; if(it.abilities.elementType != COMBAT_NONE && it.decayTo < 1) { s << std::max((int32_t)0, int32_t((item ? item->getAttack() : it.attack) - it.abilities.elementDamage)); if(it.extraAttack || (item && item->getExtraAttack())) s << " " << std::showpos << int32_t(item ? item->getExtraAttack() : it.extraAttack) << std::noshowpos; s << " physical + " << it.abilities.elementDamage << " " << getCombatName(it.abilities.elementType); } else { s << int32_t(item ? item->getAttack() : it.attack); if(it.extraAttack || (item && item->getExtraAttack())) s << " " << std::showpos << int32_t(item ? item->getExtraAttack() : it.extraAttack) << std::noshowpos; } } if(it.defense || it.extraDefense || (item && (item->getDefense() || item->getExtraDefense()))) { if(begin) { begin = false; s << " ("; } else s << ", "; s << "Def:" << int32_t(item ? item->getDefense() : it.defense); if(it.extraDefense || (item && item->getExtraDefense())) s << " " << std::showpos << int32_t(item ? item->getExtraDefense() : it.extraDefense) << std::noshowpos; } } for(uint16_t i = SKILL_FIRST; i <= SKILL_LAST; i++) { if(!it.abilities.skills[i]) continue; if(begin) { begin = false; s << " ("; } else s << ", "; s << getSkillName(i) << " " << std::showpos << (int32_t)it.abilities.skills[i] << std::noshowpos; } if(it.abilities.stats[STAT_MAGICLEVEL]) { if(begin) { begin = false; s << " ("; } else s << ", "; s << "magic level " << std::showpos << (int32_t)it.abilities.stats[STAT_MAGICLEVEL] << std::noshowpos; } int32_t show = it.abilities.absorb[COMBAT_FIRST]; for(uint32_t i = (COMBAT_FIRST + 1); i <= COMBAT_LAST; i++) { if(it.abilities.absorb[i] == show) continue; show = 0; break; } // TODO: update to the latest (from below) if(!show) { bool tmp = true; for(uint32_t i = COMBAT_FIRST; i <= COMBAT_LAST; i++) { if(!it.abilities.absorb[i]) continue; if(tmp) { if(begin) { begin = false; s << " ("; } else s << ", "; tmp = false; s << "protection "; } else s << ", "; s << getCombatName((CombatType_t)i) << " " << std::showpos << it.abilities.absorb[i] << std::noshowpos << "%"; } } else { if(begin) { begin = false; s << " ("; } else s << ", "; s << "protection all " << std::showpos << show << std::noshowpos << "%"; } if(it.abilities.speed) { if(begin) { begin = false; s << " ("; } else s << ", "; s << "speed " << std::showpos << (int32_t)(it.abilities.speed / 2) << std::noshowpos; } if(it.dualWield || (item && item->isDualWield())) { if(begin) { begin = false; s << " ("; } else s << ", "; s << "dual wielding"; } if(!begin) s << ")"; } else if(it.armor || (item && item->getArmor()) || it.showAttributes) { int32_t tmp = it.armor; if(item) tmp = item->getArmor(); bool begin = true; if(tmp) { s << " (Arm:" << tmp; begin = false; } for(uint16_t i = SKILL_FIRST; i <= SKILL_LAST; i++) { if(!it.abilities.skills[i]) continue; if(begin) { begin = false; s << " ("; } else s << ", "; s << getSkillName(i) << " " << std::showpos << (int32_t)it.abilities.skills[i] << std::noshowpos; } if(it.abilities.stats[STAT_MAGICLEVEL]) { if(begin) { begin = false; s << " ("; } else s << ", "; s << "magic level " << std::showpos << (int32_t)it.abilities.stats[STAT_MAGICLEVEL] << std::noshowpos; } // TODO: we should find some better way of completing this int32_t show = it.abilities.absorb[COMBAT_FIRST]; for(int32_t i = (COMBAT_FIRST + 1); i <= COMBAT_LAST; i++) { if(it.abilities.absorb[i] == show) continue; show = 0; break; } if(!show) { bool tmp = true; for(int32_t i = COMBAT_FIRST; i <= COMBAT_LAST; i++) { if(!it.abilities.absorb[i]) continue; if(tmp) { tmp = false; if(begin) { begin = false; s << " ("; } else s << ", "; s << "protection "; } else s << ", "; s << getCombatName((CombatType_t)i) << " " << std::showpos << it.abilities.absorb[i] << std::noshowpos << "%"; } } else { if(begin) { begin = false; s << " ("; } else s << ", "; s << "protection all " << std::showpos << show << std::noshowpos << "%"; } // TODO: same case as absorbs... show = it.abilities.reflect[REFLECT_CHANCE][COMBAT_FIRST]; for(int32_t i = (COMBAT_FIRST + 1); i <= COMBAT_LAST; i++) { if(it.abilities.reflect[REFLECT_CHANCE][i] == show) continue; show = 0; break; } if(!show) { bool tmp = true; for(int32_t i = COMBAT_FIRST; i <= COMBAT_LAST; i++) { if(!it.abilities.reflect[REFLECT_CHANCE][i] || !it.abilities.reflect[REFLECT_PERCENT][i]) continue; if(tmp) { tmp = false; if(begin) { begin = false; s << " ("; } else s << ", "; s << "reflect: "; } else s << ", "; s << it.abilities.reflect[REFLECT_CHANCE][i] << "% for "; if(it.abilities.reflect[REFLECT_PERCENT][i] > 99) s << "whole"; else if(it.abilities.reflect[REFLECT_PERCENT][i] >= 75) s << "huge"; else if(it.abilities.reflect[REFLECT_PERCENT][i] >= 50) s << "medium"; else if(it.abilities.reflect[REFLECT_PERCENT][i] >= 25) s << "small"; else s << "tiny"; s << getCombatName((CombatType_t)i); } if(!tmp) s << " damage"; } else { if(begin) { begin = false; s << " ("; } else s << ", "; int32_t tmp = it.abilities.reflect[REFLECT_PERCENT][COMBAT_FIRST]; for(int32_t i = (COMBAT_FIRST + 1); i <= COMBAT_LAST; i++) { if(it.abilities.reflect[REFLECT_PERCENT][i] == tmp) continue; tmp = 0; break; } s << "reflect: " << show << "% for "; if(tmp) { if(tmp > 99) s << "whole"; else if(tmp >= 75) s << "huge"; else if(tmp >= 50) s << "medium"; else if(tmp >= 25) s << "small"; else s << "tiny"; } else s << "mixed"; s << " damage"; } if(it.abilities.speed) { if(begin) { begin = false; s << " ("; } else s << ", "; s << "speed " << std::showpos << (int32_t)(it.abilities.speed / 2) << std::noshowpos; } if(!begin) s << ")"; } else if(it.isContainer()) s << " (Vol:" << (int32_t)it.maxItems << ")"; else if(it.isKey()) s << " (Key:" << (item ? (int32_t)item->getActionId() : 0) << ")"; else if(it.isFluidContainer()) { if(subType > 0) s << " of " << (items[subType].name.length() ? items[subType].name : "unknown"); else s << ". It is empty"; } else if(it.isSplash()) { s << " of "; if(subType > 0 && items[subType].name.length()) s << items[subType].name; else s << "unknown"; } else if(it.allowDistRead) { s << std::endl; if(item && !item->getText().empty()) { if(lookDistance <= 4) { if(!item->getWriter().empty()) { s << item->getWriter() << " wrote"; time_t date = item->getDate(); if(date > 0) s << " on " << formatDate(date); s << ": "; } else s << "You read: "; std::string text = item->getText(); s << text; if(!text.empty()) { char end = *text.rbegin(); if(end == '?' || end == '!' || end == '.') dot = false; } } else s << "You are too far away to read it"; } else s << "Nothing is written on it"; } else if(it.levelDoor && item && item->getActionId() >= (int32_t)it.levelDoor && item->getActionId() <= ((int32_t)it.levelDoor + g_config.getNumber(ConfigManager::MAXIMUM_DOOR_LEVEL))) s << " for level " << item->getActionId() - it.levelDoor; if(it.showCharges) s << " that has " << subType << " charge" << (subType != 1 ? "s" : "") << " left"; if(it.showDuration) { if(item && item->hasIntegerAttribute("duration")) { int32_t duration = item->getDuration() / 1000; s << " that has energy for "; if(duration >= 120) s << duration / 60 << " minutes left"; else if(duration > 60) s << "1 minute left"; else s << " less than a minute left"; } else s << " that is brand-new"; } if(dot) s << "."; if(it.wieldInfo) { s << std::endl << "It can only be wielded properly by "; if(it.wieldInfo & WIELDINFO_PREMIUM) s << "premium "; if(it.wieldInfo & WIELDINFO_VOCREQ) s << it.vocationString; else s << "players"; if(it.wieldInfo & WIELDINFO_LEVEL) s << " of level " << (int32_t)it.minReqLevel << " or higher"; if(it.wieldInfo & WIELDINFO_MAGLV) { if(it.wieldInfo & WIELDINFO_LEVEL) s << " and"; else s << " of"; s << " magic level " << (int32_t)it.minReqMagicLevel << " or higher"; } s << "."; } if(lookDistance <= 1 && it.pickupable) { std::string tmp; if(!item) tmp = getWeightDescription(it.weight, it.stackable, subType); else tmp = item->getWeightDescription(); if(!tmp.empty()) s << std::endl << tmp; } if(it.abilities.elementType != COMBAT_NONE && it.decayTo > 0) { s << std::endl << "It is temporarily enchanted with " << getCombatName(it.abilities.elementType) << " ("; s << std::max((int32_t)0, int32_t((item ? item->getAttack() : it.attack) - it.abilities.elementDamage)); if(it.extraAttack || (item && item->getExtraAttack())) s << " " << std::showpos << int32_t(item ? item->getExtraAttack() : it.extraAttack) << std::noshowpos; s << " physical + " << it.abilities.elementDamage << " " << getCombatName(it.abilities.elementType) << " damage)."; } std::string str; if(item && !item->getSpecialDescription().empty()) str = item->getSpecialDescription(); else if(!it.description.empty() && lookDistance <= 1) str = it.description; if(str.empty()) return s.str(); if(str.find("|PLAYERNAME|") != std::string::npos) { std::string tmp = "You"; if(item) { if(const Player* player = item->getHoldingPlayer()) tmp = player->getName(); } replaceString(str, "|PLAYERNAME|", tmp); } if(str.find("|TIME|") != std::string::npos || str.find("|DATE|") != std::string::npos || str.find( "|DAY|") != std::string::npos || str.find("|MONTH|") != std::string::npos || str.find( "|YEAR|") != std::string::npos || str.find("|HOUR|") != std::string::npos || str.find( "|MINUTES|") != std::string::npos || str.find("|SECONDS|") != std::string::npos || str.find("|WEEKDAY|") != std::string::npos || str.find("|YEARDAY|") != std::string::npos) { time_t now = time(NULL); tm* ts = localtime(&now); std::stringstream ss; ss << ts->tm_sec; replaceString(str, "|SECONDS|", ss.str()); ss.str(""); ss << ts->tm_min; replaceString(str, "|MINUTES|", ss.str()); ss.str(""); ss << ts->tm_hour; replaceString(str, "|HOUR|", ss.str()); ss.str(""); ss << ts->tm_mday; replaceString(str, "|DAY|", ss.str()); ss.str(""); ss << (ts->tm_mon + 1); replaceString(str, "|MONTH|", ss.str()); ss.str(""); ss << (ts->tm_year + 1900); replaceString(str, "|YEAR|", ss.str()); ss.str(""); ss << ts->tm_wday; replaceString(str, "|WEEKDAY|", ss.str()); ss.str(""); ss << ts->tm_yday; replaceString(str, "|YEARDAY|", ss.str()); ss.str(""); ss << ts->tm_hour << ":" << ts->tm_min << ":" << ts->tm_sec; replaceString(str, "|TIME|", ss.str()); ss.str(""); replaceString(str, "|DATE|", formatDateEx(now)); } s << std::endl << str; return s.str(); }
bool LocalNameTest::operator==(const ItemType &other) const { return other.instanceOf() == ClassLocalNameTest && static_cast<const LocalNameTest &>(other).m_ncName == m_ncName; }
bool QNameTest::operator==(const ItemType &other) const { return other.instanceOf() == ClassQNameTest && static_cast<const QNameTest &>(other).m_qName == m_qName; }
bool NamespaceNameTest::operator==(const ItemType &other) const { return other.instanceOf() == ClassNamespaceNameTest && static_cast<const NamespaceNameTest &>(other).m_namespaceURI == m_namespaceURI; }
int main() { clock_t start = clock(); int const DELETE_CT = 2; int const PRINTSIZE = 5; int const HOWMANY = 20; // How many values to read from each file. If HOWMANY = 0, read all values. // SkewHeap pq1("SkewHeap PQ1"); // LeftistHeap pq1("Leftist PQ1"); /*PQHeap pq1("Heap PQ1", 6000); PQHeap pq2("Heap PQ2", 6000); PQHeap pq3("Heap PQ3", 6000); PQHeap pq4("Heap PQ4", 6000); PQHeap pq5("Heap PQ5", 6000); PQHeap pq6("Heap PQ6", 6000);*/ SkewHeap pq1("SkewHeap PQ1"); SkewHeap pq2("SkewHeap PQ2"); SkewHeap pq3("SkewHeap PQ3"); SkewHeap pq4("SkewHeap PQ4"); SkewHeap pq5("SkewHeap PQ5"); SkewHeap pq6("SkewHeap PQ6"); /*Leftist pq1("LeftistHeap PQ1"); Leftist pq2("LeftistHeap PQ2"); Leftist pq3("LeftistHeap PQ3"); Leftist pq4("LeftistHeap PQ4"); Leftist pq5("LeftistHeapPQ5"); Leftist pq6("LeftistHeapPQ6");/**/ ifstream fin; fin.open("Prog5In.txt"); assert(fin); insertNext(pq1, fin, HOWMANY); insertNext(pq2, fin, HOWMANY); insertNext(pq3, fin, HOWMANY); insertNext(pq4, fin, HOWMANY); insertNext(pq5, fin, HOWMANY); insertNext(pq6, fin); cout << pq1.toString(PRINTSIZE); ofstream fout; fout.open("prog5out.txt"); cout << pq1.toString(PRINTSIZE); for (int ct = 0; ct < DELETE_CT && !pq1.isEmpty(); ct++){ ItemType big = pq1.deleteMax(); fout << " ** DELETED " << big.toString() << endl; cout << " ** DELETED " << big.toString() << endl; cout << pq1.toString(PRINTSIZE); }; for (int ct = 0; ct < DELETE_CT && !pq2.isEmpty(); ct++) { ItemType big = pq2.deleteMax(); fout << " ** DELETED " << big.toString() << endl; cout << " ** DELETED " << big.toString() << endl; }; cout << "Before merge \n" << pq1.toString(PRINTSIZE) << endl; fout << "Before merge \n" << pq1.toString(PRINTSIZE) << endl; cout << "Before merge \n" << pq2.toString(PRINTSIZE) << endl; fout << "Before merge \n" << pq2.toString(PRINTSIZE) << endl; pq1.merge(&pq2); cout << "After merge \n" << pq1.toString(PRINTSIZE) << endl; fout << "After merge \n" << pq1.toString(PRINTSIZE) << endl; cout << "After merge \n" << pq2.toString(PRINTSIZE) << endl; fout << "After merge \n" << pq2.toString(PRINTSIZE) << endl; pq3.merge(&pq4); cout << "After merge 3 and 4 \n" << pq3.toString(PRINTSIZE) << endl; pq5.merge(&pq6); cout << "After merge 5 and 6 \n" << pq5.toString(PRINTSIZE) << endl; pq1.merge(&pq3); cout << "After merge 1 and 3\n" << pq1.toString(PRINTSIZE) << endl; pq1.merge(&pq5); cout << "After merge 1 and 5\n" << pq1.toString(PRINTSIZE) << endl; clock_t time = clock() - start; cout << "Elapsed time = " << ((float)time) / CLOCKS_PER_SEC << endl; fout << "Elapsed time = " << ((float)time) / CLOCKS_PER_SEC << endl; fout.close(); }
std::string Item::getDescription(const ItemType& it, int32_t lookDistance, const Item* item/* = NULL*/, int32_t subType/* = -1*/, bool addArticle/* = true*/) { std::stringstream s; s << getNameDescription(it, item, subType, addArticle); if(item) subType = item->getSubType(); bool dot = true; if(it.isRune()) { if(!it.runeSpellName.empty()) s << "(\"" << it.runeSpellName << "\")"; if(it.runeLevel > 0 || it.runeMagLevel > 0 || (it.vocationString != "" && it.wieldInfo == 0)) { s << "." << std::endl << "It can only be used"; if(it.vocationString != "" && it.wieldInfo == 0) s << " by " << it.vocationString; bool begin = true; if(g_config.getBool(ConfigManager::USE_RUNE_REQUIREMENTS) && it.runeLevel > 0) { begin = false; s << " with level " << it.runeLevel; } if(g_config.getBool(ConfigManager::USE_RUNE_REQUIREMENTS) && it.runeMagLevel > 0) { begin = false; s << " " << (begin ? "with" : "and") << " magic level " << it.runeMagLevel; } if(g_config.getBool(ConfigManager::USE_RUNE_REQUIREMENTS) && !begin) s << " or higher"; } } else if(it.weaponType != WEAPON_NONE) { bool begin = true; if(it.weaponType == WEAPON_DIST && it.ammoType != AMMO_NONE) { begin = false; s << " (Range:" << int32_t(item ? item->getShootRange() : it.shootRange); if(it.attack || it.extraAttack || (item && (item->getAttack() || item->getExtraAttack()))) { s << ", Atk " << std::showpos << int32_t(item ? item->getAttack() : it.attack); if(it.extraAttack || (item && item->getExtraAttack())) s << " " << std::showpos << int32_t(item ? item->getExtraAttack() : it.extraAttack) << std::noshowpos; } if(it.hitChance != -1 || (item && item->getHitChance() != -1)) s << ", Hit% " << std::showpos << (item ? item->getHitChance() : it.hitChance) << std::noshowpos; if(it.attackSpeed || (item && item->getAttackSpeed())) s << ", AS: " << (item ? item->getAttackSpeed() : it.attackSpeed); } else if(it.weaponType != WEAPON_AMMO && it.weaponType != WEAPON_WAND) { if(it.attack || it.extraAttack || (item && (item->getAttack() || item->getExtraAttack()))) { begin = false; s << " (Atk:"; if(it.hasAbilities() && it.abilities->elementType != COMBAT_NONE) { s << std::max((int32_t)0, int32_t((item ? item->getAttack() : it.attack) - it.abilities->elementDamage)); if(it.extraAttack || (item && item->getExtraAttack())) s << " " << std::showpos << int32_t(item ? item->getExtraAttack() : it.extraAttack) << std::noshowpos; s << " physical + " << it.abilities->elementDamage << " " << getCombatName(it.abilities->elementType); } else { s << int32_t(item ? item->getAttack() : it.attack); if(it.extraAttack || (item && item->getExtraAttack())) s << " " << std::showpos << int32_t(item ? item->getExtraAttack() : it.extraAttack) << std::noshowpos; } } if(it.defense || it.extraDefense || (item && (item->getDefense() || item->getExtraDefense()))) { if(begin) { begin = false; s << " ("; } else s << ", "; s << "Def:" << int32_t(item ? item->getDefense() : it.defense); if(it.extraDefense || (item && item->getExtraDefense())) s << " " << std::showpos << int32_t(item ? item->getExtraDefense() : it.extraDefense) << std::noshowpos; } } if(it.attackSpeed || (item && item->getAttackSpeed())) { if(begin) { begin = false; s << " ("; } else s << ", "; s << "AS: " << (item ? item->getAttackSpeed() : it.attackSpeed); } if(it.hasAbilities()) { for(uint16_t i = SKILL_FIRST; i <= SKILL_LAST; ++i) { if(!it.abilities->skills[i]) continue; if(begin) { begin = false; s << " ("; } else s << ", "; s << getSkillName(i) << " " << std::showpos << (int32_t)it.abilities->skills[i] << std::noshowpos; } if(it.abilities->stats[STAT_MAGICLEVEL]) { if(begin) { begin = false; s << " ("; } else s << ", "; s << "magic level " << std::showpos << (int32_t)it.abilities->stats[STAT_MAGICLEVEL] << std::noshowpos; } int32_t show = it.abilities->absorb[COMBAT_ALL]; if(!show) { bool tmp = true; for(uint32_t i = (COMBAT_FIRST + 1); i <= COMBAT_LAST; i <<= 1) { if(!it.abilities->absorb[i]) continue; if(tmp) { tmp = false; if(begin) { begin = false; s << " ("; } else s << ", "; s << "protection "; } else s << ", "; s << getCombatName((CombatType_t)i) << " " << std::showpos << it.abilities->absorb[i] << std::noshowpos << "%"; } } else { if(begin) { begin = false; s << " ("; } else s << ", "; s << "protection all " << std::showpos << show << std::noshowpos << "%"; } show = it.abilities->fieldAbsorb[COMBAT_ALL]; if(!show) { bool tmp = true; for(uint32_t i = (COMBAT_FIRST + 1); i <= COMBAT_LAST; i <<= 1) { if(!it.abilities->fieldAbsorb[i]) continue; if(tmp) { tmp = false; if(begin) { begin = false; s << " ("; } else s << ", "; s << "protection "; } else s << ", "; s << getCombatName((CombatType_t)i) << " field " << std::showpos << it.abilities->absorb[i] << std::noshowpos << "%"; } } else { if(begin) { begin = false; s << " ("; } else s << ", "; s << "protection all fields " << std::showpos << show << std::noshowpos << "%"; } show = it.abilities->reflect[REFLECT_CHANCE][COMBAT_ALL]; if(!show) { bool tmp = true; for(uint32_t i = (COMBAT_FIRST + 1); i <= COMBAT_LAST; i <<= 1) { if(!it.abilities->reflect[REFLECT_CHANCE][i] || !it.abilities->reflect[REFLECT_PERCENT][i]) continue; if(tmp) { tmp = false; if(begin) { begin = false; s << " ("; } else s << ", "; s << "reflect: "; } else s << ", "; s << it.abilities->reflect[REFLECT_CHANCE][i] << "% for "; if(it.abilities->reflect[REFLECT_PERCENT][i] > 99) s << "whole"; else if(it.abilities->reflect[REFLECT_PERCENT][i] >= 75) s << "huge"; else if(it.abilities->reflect[REFLECT_PERCENT][i] >= 50) s << "medium"; else if(it.abilities->reflect[REFLECT_PERCENT][i] >= 25) s << "small"; else s << "tiny"; s << getCombatName((CombatType_t)i); } if(!tmp) s << " damage"; } else { if(begin) { begin = false; s << " ("; } else s << ", "; int32_t tmp = it.abilities->reflect[REFLECT_PERCENT][COMBAT_ALL]; s << "reflect: " << show << "% for "; if(tmp) { if(tmp > 99) s << "whole"; else if(tmp >= 75) s << "huge"; else if(tmp >= 50) s << "medium"; else if(tmp >= 25) s << "small"; else s << "tiny"; } else s << "mixed"; s << " damage"; } if(it.abilities->speed) { if(begin) { begin = false; s << " ("; } else s << ", "; s << "speed " << std::showpos << (int32_t)(it.abilities->speed / 2) << std::noshowpos; } if(it.abilities->invisible) { if(begin) { begin = false; s << " ("; } else s << ", "; s << "invisibility"; } if(it.abilities->regeneration) { if(begin) { begin = false; s << " ("; } else s << ", "; s << "faster regeneration"; } if(it.abilities->manaShield) { if(begin) { begin = false; s << " ("; } else s << ", "; s << "mana shield"; } if(hasBitSet(CONDITION_DRUNK, it.abilities->conditionSuppressions)) { if(begin) { begin = false; s << " ("; } else s << ", "; s << "hard drinking"; } } if(it.dualWield || (item && item->isDualWield())) { if(begin) { begin = false; s << " ("; } else s << ", "; s << "dual wielding"; } if(!begin) s << ")"; } else if(it.armor || (item && item->getArmor()) || it.showAttributes) { int32_t tmp = it.armor; if(item) tmp = item->getArmor(); bool begin = true; if(tmp) { s << " (Arm:" << tmp; begin = false; } if(it.hasAbilities()) { for(uint16_t i = SKILL_FIRST; i <= SKILL_LAST; ++i) { if(!it.abilities->skills[i]) continue; if(begin) { begin = false; s << " ("; } else s << ", "; s << getSkillName(i) << " " << std::showpos << (int32_t)it.abilities->skills[i] << std::noshowpos; } if(it.abilities->stats[STAT_MAGICLEVEL]) { if(begin) { begin = false; s << " ("; } else s << ", "; s << "magic level " << std::showpos << (int32_t)it.abilities->stats[STAT_MAGICLEVEL] << std::noshowpos; } int32_t show = it.abilities->absorb[COMBAT_ALL]; if(!show) { bool tmp = true; for(uint32_t i = (COMBAT_FIRST + 1); i <= COMBAT_LAST; i <<= 1) { if(!it.abilities->absorb[i]) continue; if(tmp) { tmp = false; if(begin) { begin = false; s << " ("; } else s << ", "; s << "protection "; } else s << ", "; s << getCombatName((CombatType_t)i) << " " << std::showpos << it.abilities->absorb[i] << std::noshowpos << "%"; } } else { if(begin) { begin = false; s << " ("; } else s << ", "; s << "protection all " << std::showpos << show << std::noshowpos << "%"; } show = it.abilities->reflect[REFLECT_CHANCE][COMBAT_ALL]; if(!show) { bool tmp = true; for(uint32_t i = (COMBAT_FIRST + 1); i <= COMBAT_LAST; i <<= 1) { if(!it.abilities->reflect[REFLECT_CHANCE][i] || !it.abilities->reflect[REFLECT_PERCENT][i]) continue; if(tmp) { tmp = false; if(begin) { begin = false; s << " ("; } else s << ", "; s << "reflect: "; } else s << ", "; s << it.abilities->reflect[REFLECT_CHANCE][i] << "% for "; if(it.abilities->reflect[REFLECT_PERCENT][i] > 99) s << "whole"; else if(it.abilities->reflect[REFLECT_PERCENT][i] >= 75) s << "huge"; else if(it.abilities->reflect[REFLECT_PERCENT][i] >= 50) s << "medium"; else if(it.abilities->reflect[REFLECT_PERCENT][i] >= 25) s << "small"; else s << "tiny"; s << getCombatName((CombatType_t)i); } if(!tmp) s << " damage"; } else { if(begin) { begin = false; s << " ("; } else s << ", "; int32_t tmp = it.abilities->reflect[REFLECT_PERCENT][COMBAT_ALL]; s << "reflect: " << show << "% for "; if(tmp) { if(tmp > 99) s << "whole"; else if(tmp >= 75) s << "huge"; else if(tmp >= 50) s << "medium"; else if(tmp >= 25) s << "small"; else s << "tiny"; } else s << "mixed"; s << " damage"; } if(it.abilities->speed) { if(begin) { begin = false; s << " ("; } else s << ", "; s << "speed " << std::showpos << (int32_t)(it.abilities->speed / 2) << std::noshowpos; } if(it.abilities->invisible) { if(begin) { begin = false; s << " ("; } else s << ", "; s << "invisibility"; } if(it.abilities->regeneration) { if(begin) { begin = false; s << " ("; } else s << ", "; s << "faster regeneration"; } if(it.abilities->manaShield) { if(begin) { begin = false; s << " ("; } else s << ", "; s << "mana shield"; } if(hasBitSet(CONDITION_DRUNK, it.abilities->conditionSuppressions)) { if(begin) { begin = false; s << " ("; } else s << ", "; s << "hard drinking"; } if(!begin) s << ")"; } } else if(it.isContainer()) s << " (Vol:" << (int32_t)it.maxItems << ")"; else if(it.isKey()) s << " (Key:" << (item ? (int32_t)item->getActionId() : 0) << ")"; else if(it.isFluidContainer()) { if(subType > 0) s << " of " << (items[subType].name.length() ? items[subType].name : "unknown"); else s << ". It is empty"; } else if(it.isSplash()) { s << " of "; if(subType > 0 && items[subType].name.length()) s << items[subType].name; else s << "unknown"; } else if(it.allowDistRead) { s << "." << std::endl; if(item && !item->getText().empty()) { if(lookDistance <= 4) { if(!item->getWriter().empty()) { s << item->getWriter() << " wrote"; time_t date = item->getDate(); if(date > 0) s << " on " << formatDate(date); s << ": "; } else s << "You read: "; std::string text = item->getText(); s << text; char end = *text.rbegin(); if(end == '?' || end == '!' || end == '.') dot = false; } else s << "You are too far away to read it"; } else s << "Nothing is written on it"; } else if(it.levelDoor && item && item->getActionId() >= (int32_t)it.levelDoor && item->getActionId() <= ((int32_t)it.levelDoor + g_config.getNumber(ConfigManager::MAXIMUM_DOOR_LEVEL))) s << " for level " << item->getActionId() - it.levelDoor; if(it.showCharges) s << " that has " << subType << " charge" << (subType != 1 ? "s" : "") << " left"; if(it.showDuration) { if(item && item->hasIntegerAttribute("duration")) { int32_t duration = item->getDuration() / 1000; s << " that will expire in "; if(duration >= 86400) { uint16_t days = duration / 86400; uint16_t hours = (duration % 86400) / 3600; s << days << " day" << (days > 1 ? "s" : ""); if(hours > 0) s << " and " << hours << " hour" << (hours > 1 ? "s" : ""); } else if(duration >= 3600) { uint16_t hours = duration / 3600; uint16_t minutes = (duration % 3600) / 60; s << hours << " hour" << (hours > 1 ? "s" : ""); if(hours > 0) s << " and " << minutes << " minute" << (minutes > 1 ? "s" : ""); } else if(duration >= 60) { uint16_t minutes = duration / 60; uint16_t seconds = duration % 60; s << minutes << " minute" << (minutes > 1 ? "s" : ""); if(seconds > 0) s << " and " << seconds << " second" << (seconds > 1 ? "s" : ""); } else s << duration << " second" << (duration > 1 ? "s" : ""); } else s << " that is brand-new"; } if(dot) s << "."; if(it.wieldInfo) { s << std::endl << "It can only be wielded properly by "; if(it.wieldInfo & WIELDINFO_PREMIUM) s << "premium "; if(it.wieldInfo & WIELDINFO_VOCREQ) s << it.vocationString; else s << "players"; if(it.wieldInfo & WIELDINFO_LEVEL) s << " of level " << (int32_t)it.minReqLevel << " or higher"; if(it.wieldInfo & WIELDINFO_MAGLV) { if(it.wieldInfo & WIELDINFO_LEVEL) s << " and"; else s << " of"; s << " magic level " << (int32_t)it.minReqMagicLevel << " or higher"; } s << "."; } if(lookDistance <= 1 && it.pickupable) { std::string tmp; if(!item) tmp = getWeightDescription(it.weight, it.stackable && it.showCount, subType); else tmp = item->getWeightDescription(); if(!tmp.empty()) s << std::endl << tmp; } if(item && !item->getSpecialDescription().empty()) s << std::endl << item->getSpecialDescription(); else if(!it.description.empty() && lookDistance <= 1) s << std::endl << it.description; std::string str = s.str(); if(str.find("|PLAYERNAME|") != std::string::npos) { std::string tmp = "You"; if(item) { if(const Player* player = item->getHoldingPlayer()) tmp = player->getName(); } replaceString(str, "|PLAYERNAME|", tmp); } if(str.find("|TIME|") != std::string::npos || str.find("|DATE|") != std::string::npos || str.find( "|DAY|") != std::string::npos || str.find("|MONTH|") != std::string::npos || str.find( "|YEAR|") != std::string::npos || str.find("|HOUR|") != std::string::npos || str.find( "|MINUTES|") != std::string::npos || str.find("|SECONDS|") != std::string::npos || str.find("|WEEKDAY|") != std::string::npos || str.find("|YEARDAY|") != std::string::npos) { time_t now = time(NULL); tm* ts = localtime(&now); std::stringstream ss; ss << ts->tm_sec; replaceString(str, "|SECONDS|", ss.str()); ss.str(""); ss << ts->tm_min; replaceString(str, "|MINUTES|", ss.str()); ss.str(""); ss << ts->tm_hour; replaceString(str, "|HOUR|", ss.str()); ss.str(""); ss << ts->tm_mday; replaceString(str, "|DAY|", ss.str()); ss.str(""); ss << (ts->tm_mon + 1); replaceString(str, "|MONTH|", ss.str()); ss.str(""); ss << (ts->tm_year + 1900); replaceString(str, "|YEAR|", ss.str()); ss.str(""); ss << ts->tm_wday; replaceString(str, "|WEEKDAY|", ss.str()); ss.str(""); ss << ts->tm_yday; replaceString(str, "|YEARDAY|", ss.str()); ss.str(""); ss << ts->tm_hour << ":" << ts->tm_min << ":" << ts->tm_sec; replaceString(str, "|TIME|", ss.str()); ss.str(""); replaceString(str, "|DATE|", formatDateEx(now)); } return str; }
std::string Item::getDescription(const ItemType& it, int32_t lookDistance, const Item* item /*= NULL*/, int32_t subType /*= -1*/, bool addArticle /*= true*/) { std::ostringstream s; s << getNameDescription(it, item, subType, addArticle); if (item) { subType = item->getSubType(); } if (it.isRune()) { if (!it.runeSpellName.empty()) { s << " (\"" << it.runeSpellName << "\")"; } if (it.runeLevel > 0 || it.runeMagLevel > 0) { int32_t tmpSubType = subType; if (item) { tmpSubType = item->getSubType(); } s << ". " << (it.stackable && tmpSubType > 1 ? "They" : "It") << " can only be used with"; if (it.runeLevel > 0) { s << " level " << it.runeLevel; } if (it.runeMagLevel > 0) { if (it.runeLevel > 0) { s << " and"; } s << " magic level " << it.runeMagLevel; } s << " or higher"; } } else if (it.weaponType != WEAPON_NONE) { if (it.weaponType == WEAPON_DIST && it.ammoType != AMMO_NONE) { s << " (Range:" << it.shootRange; if (it.attack != 0) { s << ", Atk " << std::showpos << it.attack << std::noshowpos; } if (it.hitChance != 0) { s << ", Hit% " << std::showpos << it.hitChance << std::noshowpos; } s << ")"; } else if (it.weaponType != WEAPON_AMMO) { bool begin = true; if (it.attack != 0) { begin = false; s << " (Atk:" << it.attack; if (it.abilities && it.abilities->elementType != COMBAT_NONE && it.abilities->elementDamage != 0) { s << " physical + " << it.abilities->elementDamage << " " << getCombatName(it.abilities->elementType); } } if (it.defense != 0 || it.extraDefense != 0) { if (begin) { begin = false; s << " ("; } else { s << ", "; } s << "Def:" << it.defense; if (it.extraDefense != 0 || (item && item->getExtraDefense() != 0)) { s << " " << std::showpos << it.extraDefense << std::noshowpos; } } if (it.abilities) { for (uint16_t i = SKILL_FIRST; i <= SKILL_LAST; i++) { if (!it.abilities->skills[i]) { continue; } if (begin) { begin = false; s << " ("; } else { s << ", "; } s << getSkillName(i) << " " << std::showpos << it.abilities->skills[i] << std::noshowpos; } if (it.abilities->stats[STAT_MAGICPOINTS]) { if (begin) { begin = false; s << " ("; } else { s << ", "; } s << "magic level " << std::showpos << it.abilities->stats[STAT_MAGICPOINTS] << std::noshowpos; } int32_t show = it.abilities->absorbPercent[COMBAT_FIRST]; for (uint32_t i = (COMBAT_FIRST + 1); i <= COMBAT_COUNT; ++i) { if (it.abilities->absorbPercent[i] == show) { continue; } show = 0; break; } if (!show) { bool tmp = true; for (uint32_t i = COMBAT_FIRST; i <= COMBAT_COUNT; i++) { if (!it.abilities->absorbPercent[i]) { continue; } if (tmp) { tmp = false; if (begin) { begin = false; s << " ("; } else { s << ", "; } s << "protection "; } else { s << ", "; } s << getCombatName(indexToCombatType(i)) << " " << std::showpos << it.abilities->absorbPercent[i] << std::noshowpos << "%"; } } else { if (begin) { begin = false; s << " ("; } else { s << ", "; } s << "protection all " << std::showpos << show << std::noshowpos << "%"; } if (it.abilities->speed) { if (begin) { begin = false; s << " ("; } else { s << ", "; } s << "speed " << std::showpos << (int32_t)(it.abilities->speed / 2) << std::noshowpos; } } if (!begin) { s << ")"; } } } else if (it.armor || (item && item->getArmor()) || it.showAttributes) { int32_t tmp = it.armor; if (item) { tmp = item->getArmor(); } bool begin = true; if (tmp != 0) { s << " (Arm:" << tmp; begin = false; } if (it.abilities) { for (uint16_t i = SKILL_FIRST; i <= SKILL_LAST; i++) { if (!it.abilities->skills[i]) { continue; } if (begin) { begin = false; s << " ("; } else { s << ", "; } s << getSkillName(i) << " " << std::showpos << it.abilities->skills[i] << std::noshowpos; } if (it.abilities->stats[STAT_MAGICPOINTS]) { if (begin) { begin = false; s << " ("; } else { s << ", "; } s << "magic level " << std::showpos << it.abilities->stats[STAT_MAGICPOINTS] << std::noshowpos; } int32_t show = it.abilities->absorbPercent[COMBAT_FIRST]; for (uint32_t i = (COMBAT_FIRST + 1); i <= COMBAT_COUNT; ++i) { if (it.abilities->absorbPercent[i] == show) { continue; } show = 0; break; } if (!show) { bool protectionBegin = true; for (uint32_t i = COMBAT_FIRST; i <= COMBAT_COUNT; i++) { if (!it.abilities->absorbPercent[i]) { continue; } if (protectionBegin) { protectionBegin = false; if (begin) { begin = false; s << " ("; } else { s << ", "; } s << "protection "; } else { s << ", "; } s << getCombatName(indexToCombatType(i)) << " " << std::showpos << it.abilities->absorbPercent[i] << std::noshowpos << "%"; } } else { if (begin) { begin = false; s << " ("; } else { s << ", "; } s << "protection all " << std::showpos << show << std::noshowpos << "%"; } if (it.abilities->speed) { if (begin) { begin = false; s << " ("; } else { s << ", "; } s << "speed " << std::showpos << (int32_t)(it.abilities->speed / 2) << std::noshowpos; } } if (!begin) { s << ")"; } } else if (it.isContainer()) { s << " (Vol:" << (int32_t)it.maxItems << ")"; } else { bool found = true; if (it.abilities) { if (it.abilities->speed > 0) { s << " (speed " << std::showpos << (it.abilities->speed / 2) << std::noshowpos << ")"; } else if (it.abilities && hasBitSet(CONDITION_DRUNK, it.abilities->conditionSuppressions)) { s << " (hard drinking)"; } else if (it.abilities->invisible) { s << " (invisibility)"; } else if (it.abilities->regeneration) { s << " (faster regeneration)"; } else if (it.abilities->manaShield) { s << " (mana shield)"; } else { found = false; } } else { found = false; } if (!found) { if (it.isKey()) { s << " (Key:" << (item ? (int32_t)item->getActionId() : 0) << ")"; } else if (it.isFluidContainer()) { if (subType > 0) { const std::string& itemName = items[subType].name; s << " of " << (itemName.length() ? itemName : "unknown"); } else { s << ". It is empty"; } } else if (it.isSplash()) { s << " of "; if (subType > 0 && items[subType].name.length()) { s << items[subType].name; } else { s << "unknown"; } } else if (it.allowDistRead && it.id != 7369 && it.id != 7370 && it.id != 7371) { s << "." << std::endl; if (lookDistance <= 4) { if (item && !item->getText().empty()) { if (item->getWriter().length()) { s << item->getWriter() << " wrote"; time_t date = item->getDate(); if (date > 0) { s << " on " << formatDateShort(date); } s << ": "; } else { s << "You read: "; } std::string outtext; if (utf8ToLatin1(item->getText().c_str(), outtext)) { s << outtext; } else { s << item->getText(); } } else { s << "Nothing is written on it"; } } else { s << "You are too far away to read it"; } } else if (it.levelDoor && item && item->getActionId() >= (int32_t)it.levelDoor) { s << " for level " << item->getActionId() - it.levelDoor; } } } if (it.showCharges) { s << " that has " << subType << " charge" << (subType != 1 ? "s" : "") << " left"; } if (it.showDuration) { if (item && item->hasAttribute(ATTR_ITEM_DURATION)) { int32_t duration = item->getDuration() / 1000; s << " that will expire in "; if (duration >= 86400) { uint16_t days = duration / 86400; uint16_t hours = (duration % 86400) / 3600; s << days << " day" << (days != 1 ? "s" : ""); if (hours > 0) { s << " and " << hours << " hour" << (hours != 1 ? "s" : ""); } } else if (duration >= 3600) { uint16_t hours = duration / 3600; uint16_t minutes = (duration % 3600) / 60; s << hours << " hour" << (hours != 1 ? "s" : ""); if (minutes > 0) { s << " and " << minutes << " minute" << (minutes != 1 ? "s" : ""); } } else if (duration >= 60) { uint16_t minutes = duration / 60; s << minutes << " minute" << (minutes != 1 ? "s" : ""); uint16_t seconds = duration % 60; if (seconds > 0) { s << " and " << seconds << " second" << (seconds != 1 ? "s" : ""); } } else { s << duration << " second" << (duration != 1 ? "s" : ""); } } else { s << " that is brand-new"; } } if (!it.allowDistRead || item->getText().empty() || (it.id >= 7369 && it.id <= 7371)) { s << "."; } if (it.wieldInfo != 0) { s << std::endl << "It can only be wielded properly by "; if (it.wieldInfo & WIELDINFO_PREMIUM) { s << "premium "; } if (it.wieldInfo & WIELDINFO_VOCREQ) { s << it.vocationString; } else { s << "players"; } if (it.wieldInfo & WIELDINFO_LEVEL) { s << " of level " << (int32_t)it.minReqLevel << " or higher"; } if (it.wieldInfo & WIELDINFO_MAGLV) { if (it.wieldInfo & WIELDINFO_LEVEL) { s << " and"; } else { s << " of"; } s << " magic level " << (int32_t)it.minReqMagicLevel << " or higher"; } s << "."; } if (lookDistance <= 1) { double weight = (item == NULL ? it.weight : item->getWeight()); if (weight > 0 && it.pickupable) { int32_t count = weight / it.weight; s << std::endl << getWeightDescription(it, weight, count); } } if (item && !item->getSpecialDescription().empty()) { s << std::endl << item->getSpecialDescription(); } else if (it.description.length() && lookDistance <= 1) { s << std::endl << it.description; } if (it.allowDistRead && it.id >= 7369 && it.id <= 7371 && !item->getText().empty()) { s << std::endl << item->getText(); } return s.str(); }