当前位置: 首页>>代码示例>>C++>>正文


C++ AInventory::AttachToOwner方法代码示例

本文整理汇总了C++中AInventory::AttachToOwner方法的典型用法代码示例。如果您正苦于以下问题:C++ AInventory::AttachToOwner方法的具体用法?C++ AInventory::AttachToOwner怎么用?C++ AInventory::AttachToOwner使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在AInventory的用法示例。


在下文中一共展示了AInventory::AttachToOwner方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: cht_Give

void cht_Give (player_t *player, const char *name, int amount)
{
    enum { ALL_NO, ALL_YES, ALL_YESYES } giveall;
    int i;
    PClassActor *type;

    if (player != &players[consoleplayer])
        Printf ("%s is a cheater: give %s\n", player->userinfo.GetName(), name);

    if (player->mo == NULL || player->health <= 0)
    {
        return;
    }

    giveall = ALL_NO;
    if (stricmp (name, "all") == 0)
    {
        giveall = ALL_YES;
    }
    else if (stricmp (name, "everything") == 0)
    {
        giveall = ALL_YESYES;
    }

    if (stricmp (name, "health") == 0)
    {
        if (amount > 0)
        {
            player->mo->health += amount;
            player->health = player->mo->health;
        }
        else
        {
            player->health = player->mo->health = player->mo->GetMaxHealth();
        }
    }

    if (giveall || stricmp (name, "backpack") == 0)
    {
        // Select the correct type of backpack based on the game
        type = PClass::FindActor(gameinfo.backpacktype);
        if (type != NULL)
        {
            player->mo->GiveInventory(static_cast<PClassInventory *>(type), 1, true);
        }

        if (!giveall)
            return;
    }

    if (giveall || stricmp (name, "ammo") == 0)
    {
        // Find every unique type of ammo. Give it to the player if
        // he doesn't have it already, and set each to its maximum.
        for (unsigned int i = 0; i < PClassActor::AllActorClasses.Size(); ++i)
        {
            PClassActor *type = PClassActor::AllActorClasses[i];

            if (type->ParentClass == RUNTIME_CLASS(AAmmo))
            {
                PClassAmmo *atype = static_cast<PClassAmmo *>(type);
                AInventory *ammo = player->mo->FindInventory(atype);
                if (ammo == NULL)
                {
                    ammo = static_cast<AInventory *>(Spawn (atype));
                    ammo->AttachToOwner (player->mo);
                    ammo->Amount = ammo->MaxAmount;
                }
                else if (ammo->Amount < ammo->MaxAmount)
                {
                    ammo->Amount = ammo->MaxAmount;
                }
            }
        }

        if (!giveall)
            return;
    }

    if (giveall || stricmp (name, "armor") == 0)
    {
        if (gameinfo.gametype != GAME_Hexen)
        {
            ABasicArmorPickup *armor = Spawn<ABasicArmorPickup> ();
            armor->SaveAmount = 100*deh.BlueAC;
            armor->SavePercent = gameinfo.Armor2Percent > 0? gameinfo.Armor2Percent : 0.5;
            if (!armor->CallTryPickup (player->mo))
            {
                armor->Destroy ();
            }
        }
        else
        {
            for (i = 0; i < 4; ++i)
            {
                AHexenArmor *armor = Spawn<AHexenArmor> ();
                armor->health = i;
                armor->Amount = 0;
                if (!armor->CallTryPickup (player->mo))
                {
//.........这里部分代码省略.........
开发者ID:MajorCooke,项目名称:GZDoom,代码行数:101,代码来源:m_cheat.cpp

示例2: TryPickup

bool AInventory::TryPickup (AActor *&toucher)
{
	AActor *newtoucher = toucher; // in case changed by the powerup

	// If HandlePickup() returns true, it will set the IF_PICKUPGOOD flag
	// to indicate that this item has been picked up. If the item cannot be
	// picked up, then it leaves the flag cleared.

	ItemFlags &= ~IF_PICKUPGOOD;
	if (toucher->Inventory != NULL && toucher->Inventory->HandlePickup (this))
	{
		// Let something else the player is holding intercept the pickup.
		if (!(ItemFlags & IF_PICKUPGOOD))
		{
			return false;
		}
		ItemFlags &= ~IF_PICKUPGOOD;
		GoAwayAndDie ();
	}
	else if (MaxAmount == 0 && !IsKindOf(RUNTIME_CLASS(AAmmo)))
	{
		// Special case: If an item's MaxAmount is 0, you can still pick it
		// up if it is autoactivate-able.
		if (!(ItemFlags & IF_AUTOACTIVATE))
		{
			return false;
		}
		// The item is placed in the inventory just long enough to be used.
		toucher->AddInventory (this);
		bool usegood = Use (true);
		toucher->RemoveInventory (this);

		if (usegood)
		{
			GoAwayAndDie ();
		}
		else
		{
			return false;
		}
	}
	else
	{
		// Add the item to the inventory. It is not already there, or HandlePickup
		// would have already taken care of it.
		AInventory *copy = CreateCopy (toucher);
		if (copy == NULL)
		{
			return false;
		}
		// Some powerups cannot activate absolutely, for
		// example, PowerMorph; fail the pickup if so.
		if (copy->ItemFlags & IF_INITEFFECTFAILED)
		{
			if (copy != this) copy->Destroy();
			else ItemFlags &= ~IF_INITEFFECTFAILED;
			return false;
		}
		// Handle owner-changing powerups
		if (copy->ItemFlags & IF_CREATECOPYMOVED)
		{
			newtoucher = copy->Owner;
			copy->Owner = NULL;
			copy->ItemFlags &= ~IF_CREATECOPYMOVED;
		}
		// Continue onwards with the rest
		copy->AttachToOwner (newtoucher);
		if (ItemFlags & IF_AUTOACTIVATE)
		{
			if (copy->Use (true))
			{
				if (--copy->Amount <= 0)
				{
					copy->flags &= ~MF_SPECIAL;
					copy->SetState (copy->FindState("HoldAndDestroy"));
				}
			}
		}
	}
	return true;
}
开发者ID:Accusedbold,项目名称:zdoom,代码行数:81,代码来源:a_pickups.cpp

示例3: cht_Give

void cht_Give (player_t *player, const char *name, int amount)
{
	enum { ALL_NO, ALL_YES, ALL_YESYES } giveall;
	int i;
	const PClass *type;

	if ( NETWORK_GetState( ) == NETSTATE_SERVER )
		SERVER_Printf( PRINT_HIGH, "%s is a cheater: give %s\n", player->userinfo.netname, name );
	else if (player != &players[consoleplayer])
		Printf ("%s is a cheater: give %s\n", player->userinfo.netname, name);

	if (player->mo == NULL || player->health <= 0)
	{
		return;
	}

	giveall = ALL_NO;
	if (stricmp (name, "all") == 0)
	{
		giveall = ALL_YES;
	}
	else if (stricmp (name, "everything") == 0)
	{
		giveall = ALL_YESYES;
	}

	if (stricmp (name, "health") == 0)
	{
		if (amount > 0)
		{
			if (player->mo)
			{
				player->mo->health += amount;
	  			player->health = player->mo->health;
			}
			else
			{
				player->health += amount;
			}
		}
		else
		{
			if (player->mo != NULL)
			{
				player->health = player->mo->health = player->mo->GetMaxHealth();
			}
			else
			{
				player->health = deh.GodHealth;
			}
		}
		// [BB]: The server has to inform the clients that this player's health has changed.
		if ( NETWORK_GetState( ) == NETSTATE_SERVER )
		{
			ULONG playerIdx = static_cast<ULONG> ( player - players );
			SERVERCOMMANDS_SetPlayerHealth( playerIdx );
		}
	}

	if (giveall || stricmp (name, "backpack") == 0)
	{
		// Select the correct type of backpack based on the game
		type = PClass::FindClass(gameinfo.backpacktype);
		if (type != NULL)
		{
			GiveSpawner (player, type, 1);
		}

		if (!giveall)
			return;
	}

	if (giveall || stricmp (name, "ammo") == 0)
	{
		// Find every unique type of ammo. Give it to the player if
		// he doesn't have it already, and set each to its maximum.
		for (unsigned int i = 0; i < PClass::m_Types.Size(); ++i)
		{
			const PClass *type = PClass::m_Types[i];

			if (type->ParentClass == RUNTIME_CLASS(AAmmo))
			{
				AInventory *ammo = player->mo->FindInventory (type);
				if (ammo == NULL)
				{
					ammo = static_cast<AInventory *>(Spawn (type, 0, 0, 0, NO_REPLACE));
					ammo->AttachToOwner (player->mo);
					ammo->Amount = ammo->MaxAmount;
				}
				else if (ammo->Amount < ammo->MaxAmount)
				{
					ammo->Amount = ammo->MaxAmount;
				}
				// [BB] This construction is more or less a hack, but at least the give cheats are now working.
				SERVER_GiveInventoryToPlayer( player, ammo );
			}
		}

		if (!giveall)
			return;
//.........这里部分代码省略.........
开发者ID:WChrisK,项目名称:Zandronum,代码行数:101,代码来源:m_cheat.cpp


注:本文中的AInventory::AttachToOwner方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。