コード例 #1
0
ファイル: StPlayList.cpp プロジェクト: KindDragon/sview
void StPlayList::clear() {
    StMutexAuto anAutoLock(myMutex);
    if(myFirst != NULL) {
        myWasCleared = true;
        mySerial.increment();
    }

    if(!myPlsFile.isNull()
    && myCurrent != NULL) {
        if(myPlsFile->File->isEmpty()) {
            myPlsFile->File->add(new StFileNode(myCurrent->getPath(), myPlsFile->File.access()));
        } else {
            myPlsFile->File->changeValue(0)->setSubPath(myCurrent->getPath());
        }
    }
    myPlsFile.nullify();

    // destroy double-linked list content
    for(StPlayItem *anItem(myFirst), *anItemToDel(NULL); anItem != NULL;) {
        anItemToDel = anItem;
        anItem = anItem->getNext();
        delete anItemToDel;
    }
    myStackPrev.clear();
    myStackNext.clear();
    myFirst = myLast = myCurrent = NULL;
    myItemsCount = myPlayedCount = 0;

    anAutoLock.unlock();
    signals.onPlaylistChange();
}
コード例 #2
0
/**
A helper function of CopyObjectL.
@param aNewFileName the new full filename after copy.
@return objectHandle of new copy of object.
*/
TUint32 CMTPImageDpCopyObject::CopyFileL(const TDesC& aOldFileName, const TDesC& aNewFileName)
    {
    OstTraceFunctionEntry0( CMTPIMAGEDPCOPYOBJECT_COPYFILEL_ENTRY );
    TCleanupItem anItem(FailRecover, reinterpret_cast<TAny*>(this));
    CleanupStack::PushL(anItem);
    
    GetPreviousPropertiesL(aOldFileName);
    LEAVEIFERROR(iFileMan->Copy(aOldFileName, *iDest),
            OstTraceExt3( TRACE_ERROR, CMTPIMAGEDPCOPYOBJECT_COPYFILEL, 
                    "Copy %S to %S failed! error code %d", aOldFileName, *iDest, munged_err));
            
    iRollbackActionL.AppendL(RollBackFromFsL);
    SetPreviousPropertiesL(aNewFileName);
    
    iFramework.ObjectMgr().InsertObjectL(*iTargetObjectInfo);
    //check object whether it is a new image object
    if (MTPImageDpUtilits::IsNewPicture(*iTargetObjectInfo))
        {
        //increate new pictures count
        iDataProvider.IncreaseNewPictures(1);
        }    
    
    CleanupStack::Pop(this);
    OstTraceFunctionExit0( CMTPIMAGEDPCOPYOBJECT_COPYFILEL_EXIT );
    return iTargetObjectInfo->Uint(CMTPObjectMetaData::EHandle);
    }
コード例 #3
0
void CShop::AddPersistentStartingEquipment() {
	const CInventory &sourceInventory = *gameLocal.persistentPlayerInventory;
	// Cycle through all categories to add them
	for( int c = 0; c < sourceInventory.GetNumCategories(); ++c ) {
		const CInventoryCategoryPtr &category = sourceInventory.GetCategory( c );
		for( int itemIdx = 0; itemIdx < category->GetNumItems(); ++itemIdx ) {
			const CInventoryItemPtr &item = category->GetItem( itemIdx );
			if( item->GetPersistentCount() <= 0 ) {
				DM_LOG( LC_MAINMENU, LT_DEBUG )LOGSTRING(
					"Item %s is not marked as persistent, won't add to shop.\r",
					item->GetName().c_str() );
				continue; // not marked as persistent
			}
			const idDict *itemDict = item->GetSavedItemEntityDict();
			if( itemDict == NULL ) {
				DM_LOG( LC_MAINMENU, LT_WARNING )LOGSTRING(
					"Item %s is marked as persistent, but has no saved item dictionary.\r",
					item->GetName().c_str() );
				continue;
			}
			idStr className = itemDict->GetString( "classname" );
			// Try to look up the corresponding shop item definition for this item's classname
			CShopItemPtr found = FindShopItemDefByClassName( className );
			if( found == NULL ) {
				DM_LOG( LC_MAINMENU, LT_DEBUG )LOGSTRING(
					"Can't find shopitem definition for classname %s, skipping.\r", className.c_str() );
				continue;
			}
			int quantity = GetQuantityForItem( item );
			// Don't attempt to merge if we don't have anything to merge in the first place
			if( quantity == 0 ) {
				DM_LOG( LC_MAINMENU, LT_DEBUG )LOGSTRING(
					"Persistent weapon doesn't have ammo, skipping.\r", className.c_str() );
				continue;
			}
			// Check if this is a weapon
			CInventoryWeaponItemPtr weaponItem = boost::dynamic_pointer_cast<CInventoryWeaponItem>( item );
			bool isWeapon = ( weaponItem != NULL );
			bool weaponIsAllowedEmpty = weaponItem ? weaponItem->IsAllowedEmpty() : false;
			bool itemMerged = MergeIntoStartingEquipment( className, quantity, isWeapon, weaponIsAllowedEmpty );
			// Append the item to the list if it didn't contribute quantity to
			// an existing list item.
			if( !itemMerged ) {
				CShopItemPtr anItem( new CShopItem( *found, quantity, 0, false ) );
				bool canDrop = itemDict->GetBool( "inv_droppable", "1" );
				anItem->SetCanDrop( canDrop );
				_startingItems.Append( anItem );
			}
		}
	}
}
コード例 #4
0
ファイル: Shop.cpp プロジェクト: dolanor/TheDarkMod
void CShop::AddMapItems(idMapFile* mapFile)
{
	// get the difficulty level

	idStr diffString = "diff_" + idStr(gameLocal.m_DifficultyManager.GetDifficultyLevel()) + "_nospawn";

	// Cycle through map entities. Since the number of entities can change in the loop,
	// always refresh the entity count used to terminate the loop.

	// Skip entity 0, which is the world.

	for (int i = 1; i < mapFile->GetNumEntities(); i++)
	{
		idMapEntity* mapEnt = mapFile->GetEntity(i);

		// does this entity have an inv_map_start spawnflag set to 1?

		if (mapEnt->epairs.GetBool("inv_map_start", "0"))
		{
			// does this entity exist in the chosen difficulty level?

			if (idStr::Icmp(mapEnt->epairs.GetString(diffString, "0"), "0") == 0)
			{
				idStr className = mapEnt->epairs.GetString("classname");
				int quantity;
				bool isWeapon = false;	// is this an arrow?
				int max_ammo = 1;	// in case this is a weapon

				// Special handling for arrows. The shop definitions allow for
				// atdm:weapon_*, but not atdm:ammo_*. The latter form is used on
				// map entities. If this is an atdm:ammo_* entity, change its ID (itemName)
				// to the allowable atdm:weapon_* form.

				if (className.Find("atdm:ammo_") >= 0)
				{
					isWeapon = true;
					className.Replace( "atdm:ammo_", "atdm:weapon_" );

					// An arrow's quantity is defined by "inv_ammo_amount" instead
					// of "inv_count". Look for that.

					quantity = mapEnt->epairs.GetInt("inv_ammo_amount", "0");

					// Arrow quantities have limits. See if you can find the limit
					// for this weapon.

					if (quantity > 0)
					{
						max_ammo = GetMaxAmmo(className);
						quantity = (quantity > max_ammo) ? max_ammo : quantity;
					}
				}
				else
				{
					quantity = mapEnt->epairs.GetInt("inv_count", "1");
				}

				if (quantity > 0)
				{
					CShopItemPtr found = FindShopItemDefByClassName(className);

					if (found != NULL)
					{
						// We don't have much info about the weapon item at this point and FindEntityDefDict() is lagging
						// so let's assume there is only a shortsword and blackjack as possible melee items for now
						bool isMeleeWeapon = (className.Cmp("atdm:weapon_shortsword") == 0 || className.Cmp("atdm:weapon_blackjack") == 0);

						// If this item is stackable, and already exists in the _startingItems list,
						// bump up the quantity there instead of appending the item to the list.
						// If the item is not stackable, and we already have it, ignore it.
						bool itemMerged = MergeIntoStartingEquipment(className, quantity, isWeapon, isMeleeWeapon);

						// Append the item to the list if it didn't contribute quantity to
						// an existing list item.

						if (!itemMerged)
						{
							CShopItemPtr anItem(new CShopItem(*found, quantity, 0, false));

							bool canDrop = mapEnt->epairs.GetBool("inv_droppable", "1");
							anItem->SetCanDrop(canDrop);

							_startingItems.Append(anItem);
						}
					}
					else
					{
						gameLocal.Warning("Map entity is not a valid shop item: %s", className.c_str());
					}
				}
			}
		}
	}
}
コード例 #5
0
ファイル: Shop.cpp プロジェクト: dolanor/TheDarkMod
int CShop::AddItems(const idDict& mapDict, const idStr& itemKey, ShopItemList& list)
{
	int diffLevel = gameLocal.m_DifficultyManager.GetDifficultyLevel();
	
	int itemsAdded = 0;

	// grayman (#2376)
	// Convert itemKey to lowercase. mapDict methods ignore case, but
	// StripLeadingOnce() doesn't. This change allows recognition of shop items defined as
	// "startingItem_*", "startingitem_*", "shopItem_*", and "shopitem_*.

	idStr itemKeyLower = itemKey;
	itemKeyLower.ToLower();

	bool isShopList = (itemKeyLower.Find("shop") >= 0); // for lockpick checking

	for (const idKeyValue* kv = mapDict.MatchPrefix(itemKeyLower); kv != NULL; kv = mapDict.MatchPrefix(itemKeyLower, kv))
	{
		// Inspect the matching prefix, check whether the difficulty level applies
		idStr postfix = kv->GetKey();
		postfix.ToLower(); // grayman (#2376) convert postfix to lowercase so StripLeadingOnce()
						   // matches lowercase against lowercase

		// Cut off the prefix including the following underscore _
		postfix.StripLeadingOnce(itemKeyLower + "_");
		
		int pos = postfix.Find("_item");
		
		if (pos == -1 || pos != postfix.Length() - 5)
		{
			continue; // no suitable "_item" found
		}

		// This is the number portion, like "1_2" or merely "2"
		idStr indexStr = postfix.Mid(0, pos);

		// Check if we have still an underscore in the index string, this implies
		// that there is a difficulty number included
		int underScorePos = indexStr.Find('_');

		// Extract the item index
		int itemIndex = (underScorePos != -1) ? atoi(indexStr.Mid(0, underScorePos)) : atoi(indexStr);

		if (underScorePos != -1)
		{
			// Check out the second number, this is the difficulty level
			idStr diffStr = indexStr.Mid(underScorePos + 1, indexStr.Length() - underScorePos);

			// Check if the difficulty level matches
			if (atoi(diffStr) != diffLevel)
			{
				// Ignore this spawnarg
				continue;
			}
		}

		idStr itemName = kv->GetValue();

		if (itemName.IsEmpty())
		{
			continue; // Empty names are not considered
		}

		// greebo: Assemble the item prefix (e.g. "shopItem_1_") to look up the rest of the spawnargs
		idStr itemPrefix = itemKey + "_" + idStr(itemIndex);
		idStr diffLevelStr = "_" + idStr(diffLevel);

		// look for quantity, but let a difficulty-specific setting override the general one
		int quantity = mapDict.GetInt(itemPrefix + "_qty");

		if (mapDict.FindKey(itemPrefix + diffLevelStr + "_qty") != NULL)
		{
			quantity = mapDict.GetInt(itemPrefix + diffLevelStr + "_qty");
		}

		// put the item in the shop
		if (quantity > 0)
		{
			// grayman (#2376) - Special handling for weapon quantities.

			int index = itemName.Find("weapon_");
			if (index >= 0)
			{
				// A shop entity should use atdm:weapon_*, but there's at least one
				// that uses weapon_*, so convert the latter to the former.

				idStr weaponName;
				if (index == 0)
				{
					weaponName = "atdm:" + itemName;
				}
				else
				{
					weaponName = itemName;
				}

				// Weapon quantities have limits. (Arrows in particular.)

				int max_ammo = GetMaxAmmo(weaponName);
				quantity = (quantity > max_ammo) ? max_ammo : quantity;
			}

			/* grayman (#2376) - Since a lockpick_set comprises individual picks, putting one
								 on either the shopItems or startingItems list means we don't
								 have to put individual picks on the same list.
								 For now, just register whether a lockpick_set is being added
								 to either list. We'll post-process after the lists are built.
			 */

			if (isShopList)
			{
				if (!_pickSetShop && (itemName.Find("lockpick_set") >= 0))
				{
					_pickSetShop = true;
				}
			}
			else
			{
				if (!_pickSetStarting && (itemName.Find("lockpick_set") >= 0))
				{
					_pickSetStarting = true;
				}
			}

			// look for price
			int price = mapDict.GetInt(itemPrefix + "_price");

			if (mapDict.FindKey(itemPrefix + diffLevelStr + "_price") != NULL)
			{
				price = mapDict.GetInt(itemPrefix + diffLevelStr + "_price");
			}

			// look for persistency
			bool persistent = mapDict.GetBool(itemPrefix + "_persistent");

			if (mapDict.FindKey(itemPrefix + diffLevelStr + "_persistent") != NULL)
			{
				persistent = mapDict.GetBool(itemPrefix + diffLevelStr + "_persistent");
			}

			// look for canDrop flag 
			bool canDrop = mapDict.GetBool(itemPrefix + "_canDrop", "1"); // items can be dropped by default

			if (mapDict.FindKey(itemPrefix + diffLevelStr + "_canDrop") != NULL)
			{
				canDrop = mapDict.GetBool(itemPrefix + diffLevelStr + "_canDrop", "1");
			}

			CShopItemPtr found = FindShopItemDefByClassName(itemName);

			if (found != NULL) 
			{
				// grayman - TODO: If there are multiple shops, you can get multiple
				// entries for the same item. You need to group them into a single item.

				CShopItemPtr anItem(new CShopItem(*found, quantity, price, persistent));
				anItem->SetCanDrop(canDrop);
				list.Append(anItem);

				itemsAdded++;
			}
			else
			{
				gameLocal.Warning("Could not add item to shop: %s", itemName.c_str());
			}
		}
	}

	return itemsAdded;
}