bool CWeapon_GenericGun07::AddAmmo(int Ammo)
{
	if(m_Ammo < GetMaxAmmo())
	{
		m_Ammo = min(m_Ammo + Ammo, GetMaxAmmo());
		return true;
	}
	else return false;
}
void C_ASW_TeslaTrap::CustomPaint(int ix, int iy, int alpha, vgui::Panel *pUseIcon)
{
	if ( !m_bAssembled )
		return;

	if (C_ASW_Sentry_Base::s_hAmmoFont == vgui::INVALID_FONT)
	{
		vgui::HScheme scheme = vgui::scheme()->LoadSchemeFromFile("resource/SwarmSchemeNew.res", "SwarmSchemeNew");
		vgui::IScheme *pScheme = vgui::scheme()->GetIScheme(scheme);
		if (pScheme)
			C_ASW_Sentry_Base::s_hAmmoFont = vgui::scheme()->GetIScheme(scheme)->GetFont("DefaultSmall", true);
	}

	if (C_ASW_Sentry_Base::s_hAmmoFont == vgui::INVALID_FONT || alpha <= 0)
		return;

	int nAmmo = MAX( 0, GetAmmo() );
	Color textColor( 255, 255, 255, 255 );
	if ( nAmmo < 10 )
	{
		textColor = Color( 255, 255, 0, 255 );
	}

	if ( pUseIcon )
	{
		CASW_HUD_Use_Icon *pUseIconPanel = static_cast<CASW_HUD_Use_Icon*>(pUseIcon);
		float flProgress = (float) nAmmo / (float) GetMaxAmmo();
		char szCountText[64];
		Q_snprintf( szCountText, sizeof( szCountText ), "%d", MAX( nAmmo, 0 ) );
		pUseIconPanel->CustomPaintProgressBar( ix, iy, alpha / 255.0f, flProgress, szCountText, C_ASW_Sentry_Base::s_hAmmoFont, textColor, "#asw_ammo_label" );
	}
}
bool CWeapon_GenericGun07::TickPreFire(bool IsActive)
{
	if(!IsActive)
		return true;
	
	if(m_ReloadTimer > 0) m_ReloadTimer--;
	
	int AmmoRegenTime = g_pData->m_Weapons.m_aId[m_TW07ID].m_Ammoregentime;
	if(AmmoRegenTime && m_Ammo >= 0)
	{
		// If equipped and not active, regen ammo?
		if(m_ReloadTimer <= 0)
		{
			if(m_AmmoRegenStart < 0)
			{
				m_AmmoRegenStart = Server()->Tick();
			}
			
			if((Server()->Tick() - m_AmmoRegenStart) >= AmmoRegenTime * Server()->TickSpeed() / 1000)
			{
				// Add some ammo
				m_Ammo = min(m_Ammo + 1, GetMaxAmmo());
				m_AmmoRegenStart = -1;
			}
		}
		else
		{
			m_AmmoRegenStart = -1;
		}
	}
	
	return true;
}
bool CShop::MergeIntoStartingEquipment( const idStr &itemName, int quantity, bool isWeapon, bool isMeleeWeapon ) {
	CShopItemPtr startingItem = FindStartingItemByID( itemName );
	if( !startingItem ) {
		return false; // item not found
	}
	int oldQuantity = startingItem->GetCount();
	int newQuantity = oldQuantity + quantity;
	// Weapons have ammo limits. Even though you might have
	// adjusted that already in the incoming item,
	// you have to check again when it's added to
	// the existing amount already in the starting items.
	if( isWeapon ) {
		if( isMeleeWeapon ) {
			// Don't stack anything for melee weapons, otherwise we end up with 2 shortswords
			newQuantity = oldQuantity;
		} else {
			// Arrow-based weapons need ammo
			int maxAmmo = GetMaxAmmo( itemName );
			if( newQuantity > maxAmmo ) {
				newQuantity = maxAmmo;
			}
		}
		quantity = newQuantity - oldQuantity; // amount to give
	} else if( !startingItem->GetStackable() ) {
		quantity = 0; // don't adjust item's quantity
	}
	if( quantity > 0 ) {
		startingItem->ChangeCount( quantity ); // add quantity to count
	}
	return true; // item found
}
CInventoryWeaponItem::CInventoryWeaponItem( const idStr &weaponDefName, idEntity *owner ) :
	CInventoryItem( owner ),
	m_WeaponDefName( weaponDefName ),
	m_WeaponIndex( -1 ),
	m_AllowedEmpty( false ),
	m_IsToggleable( false ),
	m_Enabled( true ) {
	SetType( IT_WEAPON );
	const idDict *weaponDict = gameLocal.FindEntityDefDict( m_WeaponDefName );
	m_Name = weaponDict->GetString( "inv_name", "Unknown weapon" );
	m_WeaponName = weaponDict->GetString( "inv_weapon_name" );
	if( m_WeaponName.IsEmpty() ) {
		gameLocal.Warning( "Weapon defined in %s has no 'inv_weapon_name' spawnarg!", m_WeaponDefName.c_str() );
	}
	m_MaxAmmo = GetMaxAmmo();
	m_Ammo = GetStartAmmo();
	// Parse the common spawnargs which apply to both this and the base class
	ParseSpawnargs( *weaponDict );
}
Exemple #6
0
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());
					}
				}
			}
		}
	}
}
Exemple #7
0
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;
}