コード例 #1
0
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 );
}
コード例 #2
0
ファイル: InventoryItem.cpp プロジェクト: ProfessorKaos64/tdm
CInventoryItem::CInventoryItem(idEntity* itemEntity, idEntity* owner) {
	// Don't allow NULL pointers
	assert(owner && itemEntity);

	// Parse a few common spawnargs
	ParseSpawnargs(itemEntity->spawnArgs);

	m_Category = NULL;
	m_Overlay = OVERLAYS_INVALID_HANDLE;
	m_Hud = false;

	m_Owner = owner;
	m_Item = itemEntity;
	
	// Determine and set the loot type
	m_LootType = GetLootTypeFromSpawnargs(itemEntity->spawnArgs);

	// Read the spawnargs into the member variables
	m_Name = itemEntity->spawnArgs.GetString("inv_name", "");
	// Tels: Replace "\n" with \x0a, otherwise multiline names set inside DR do not work
	m_Name.Replace( "\\n", "\n" );
	m_Value	= itemEntity->spawnArgs.GetInt("inv_loot_value", "-1");
	m_Stackable	= itemEntity->spawnArgs.GetBool("inv_stackable", "0");
	m_UseOnFrob = itemEntity->spawnArgs.GetBool("inv_use_on_frob", "0");

	m_Count = (m_Stackable) ? itemEntity->spawnArgs.GetInt("inv_count", "1") : 1;

	m_Droppable = itemEntity->spawnArgs.GetBool("inv_droppable", "0");
	m_ItemId = itemEntity->spawnArgs.GetString("inv_item_id", "");

	if (m_Icon.IsEmpty() && m_LootType == LOOT_NONE)
	{
		DM_LOG(LC_INVENTORY, LT_INFO)LOGSTRING("Information: non-loot item %s has no icon.\r", itemEntity->name.c_str());
	}

	if (m_LootType != LOOT_NONE && m_Value <= 0)
	{
		DM_LOG(LC_INVENTORY, LT_ERROR)LOGSTRING("Warning: Value for loot item missing on entity %s\r", itemEntity->name.c_str());
	}

	// Set the item type according to the loot property
	m_Type = (m_LootType != LOOT_NONE) ? IT_LOOT : IT_ITEM;

	m_BindMaster = itemEntity->GetBindMaster();
	m_Orientated = itemEntity->fl.bindOrientated;

	idStr hudName;
	// Item could be added to the inventory, check for custom HUD
	if (itemEntity->spawnArgs.GetString("inv_hud", "", hudName) != false)
	{
		int hudLayer;
		itemEntity->spawnArgs.GetInt("inv_hud_layer", "0", hudLayer);
		SetHUD(hudName, hudLayer);
	}

	// Check for a preferred drop orientation, if not, use current orientation
	if( itemEntity->spawnArgs.FindKey("drop_angles") )
	{
		idAngles DropAngles;
		DropAngles = itemEntity->spawnArgs.GetAngles("drop_angles");
		m_DropOrientation = DropAngles.ToMat3();
	}
	else
	{
		idVec3 dummy;
		idMat3 playerView;
		gameLocal.GetLocalPlayer()->GetViewPos(dummy, playerView);
		// drop orientation is relative to the player view yaw only
		idAngles viewYaw = playerView.ToAngles();
		// ignore pitch and roll
		viewYaw[0] = 0;
		viewYaw[2] = 0;
		idMat3 playerViewYaw = viewYaw.ToMat3();

		m_DropOrientation = itemEntity->GetPhysics()->GetAxis() * playerViewYaw.Transpose();
	}
}