⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 item.cpp

📁 this keik game source
💻 CPP
📖 第 1 页 / 共 2 页
字号:
		spawnflags |= DROPPED_PLAYER_ITEM;
		}
	else
		{
		spawnflags |= DROPPED_ITEM;
		}

   // Remove this from the owner's item list
   owner->RemoveItem( this );
	owner = NULL;

	return true;
	}


void Item::ItemTouch
	(
	Event *ev
	)

	{
	Entity	*other;
	Event		*e;

	if ( owner )
		{
		// Don't respond to trigger events after item is picked up.
		gi.dprintf( "%s with targetname of %s was triggered unexpectedly.\n", getClassID(), TargetName() );
		return;
		}

	other = ev->GetEntity( 1 );

	e = new Event( EV_Item_Pickup );
	e->AddEntity( other );
	ProcessEvent( e );
	}

void Item::SetOwner
	(
	Sentient *ent
	)

	{
	assert( ent );
	if ( !ent )
		{
		// return to avoid any buggy behaviour
		return;
		}

   owner = ent;
	setRespawn( false );

   edict->s.renderfx &= ~RF_GLOW;
	setSolidType( SOLID_NOT );
	hideModel();
	CancelEventsOfType( EV_Item_DropToFloor );
	CancelEventsOfType( EV_Remove );
//	ItemPickup( ent );
	}

Item * Item::ItemPickup
	(
	Entity *other
	)

	{
   Sentient * sent;
   Item * item;
	str realname;

   if ( !Pickupable( other ) )
		{
		return NULL;
		}

   sent = ( Sentient * )other;

   item = sent->giveItem( getClassname(), Amount(), icon_index );

   if ( !item )
      return NULL;

	realname = GetRandomAlias( "snd_pickup" );
   if ( realname.length() > 1 )
      sent->sound( realname, 1, CHAN_ITEM, ATTN_NORM );

	if ( !Removable() )
		{
		// leave the item for others to pickup
		return item;
		}

	CancelEventsOfType( EV_Item_DropToFloor );
	CancelEventsOfType( EV_Item_Respawn );
   CancelEventsOfType( EV_FadeOut );

	setSolidType( SOLID_NOT );
	hideModel();


	if ( Respawnable() )
		{
		PostEvent( EV_Item_Respawn, RespawnTime() );
		}
	else
		{
		PostEvent( EV_Remove, 0.1 );
		}

   if ( DM_FLAG( DF_INSTANT_ITEMS ) )
		{
      Event *ev;

      ev = new Event( EV_InventoryItem_Use );
      ev->AddEntity( other );

      item->ProcessEvent( ev );
		}

   return item;
	}

void Item::Respawn
	(
	Event *ev
	)

	{
	showModel();

	// allow it to be touched again
	setSolidType( SOLID_TRIGGER );

	// play respawn sound
   if ( playrespawn )
      {
   	RandomGlobalSound( "snd_itemspawn" );
      }

	setOrigin( origin );
	};

void Item::setRespawn
	( 
	qboolean flag 
	)

	{
	respawnable = flag;
	}

qboolean Item::Respawnable
	( 
	void 
	)

	{
	return respawnable;
	}

void Item::setRespawnTime
	( 
	float time 
	)

	{
	respawntime = time;
	}

float Item::RespawnTime
	( 
	void 
	)

	{
	return respawntime;
	}

int Item::Amount
   (
   void
   )

   {
   return amount;
   }

int Item::MaxAmount
   (
   void
   )

   {
   return maximum_amount;
   }

qboolean Item::Pickupable
   (
   Entity *other
   )

   {
	if ( !other->isSubclassOf( Sentient ) )
		{
		return false;
		}
   else
      {
      Sentient * sent;
      Item * item;

      sent = ( Sentient * )other;
      item = sent->FindItem( getClassname() );

      if ( item && ( item->Amount() >= item->MaxAmount() ) )
         {
         return false;
         }

      // Mutants can't pick up anything but health
      if ( other->flags & (FL_MUTANT|FL_SP_MUTANT) && !( this->isSubclassOf( Health ) ) )
         {
         return false;
         }

      // If deathmatch and already in a powerup, don't pickup anymore when DF_INSTANT_ITEMS is on
      if ( DM_FLAG( DF_INSTANT_ITEMS ) &&
           this->isSubclassOf( InventoryItem ) &&
           sent->PowerupActive()
         )
         {
         return false;
         }
      }
   return true;
   }

void Item::Pickup
	(
   Event * ev
	)

	{
	ItemPickup( ev->GetEntity( 1 ) );
   }

void Item::setIcon
   (
   const char *i
   )

   {
   icon_name = i;
   icon_index = gi.imageindex( i );
   }

void Item::setName
   (
   const char *i
   )

   {
   item_name = i;
   item_index = gi.itemindex( i );
   }

int Item::Icon
   (
   void
   )

   {
   if ( icon_name.length() )
      return icon_index;
   else
      return -1;
   }

void Item::Set
	(
	int startamount
	)

	{
   if ( !amount_override )
      {
      amount = startamount;
      if ( amount >= MaxAmount() )
         SetMax( amount );
      }
   }

void Item::SetMax
	(
	int maxamount
	)

	{
   maximum_amount = maxamount;
   }

void Item::SetAmount
	(
	Event *ev
	)

	{
	Set( ev->GetInteger( 1 ) );
   }

void Item::SetMaxAmount
	(
	Event *ev
	)

	{
	SetMax( ev->GetInteger( 1 ) );
   }

void Item::SetIconName
	(
	Event *ev
	)

	{
   setIcon( ev->GetString( 1 ) );
	}

void Item::SetItemName
	(
	Event *ev
	)

	{
   setName( ev->GetString( 1 ) );
	}

void Item::Add
	(
	int num
	)

	{
	amount += num;
   if ( amount >= MaxAmount() )
      amount = MaxAmount();
	}

void Item::Remove
   (
   int num
   )
   {
   amount -= num;
   if (amount < 0)
      amount = 0;
   }


qboolean Item::Use
	(
	int num
	)

	{
	if ( num > amount )
		{
		return false;
		}

	amount -= num;
	return true;
	}

qboolean Item::Removable
	( 
	void 
	)

	{
   return true;
	}

void Item::RespawnSound
	(
	Event *ev
	)

	{
   playrespawn = true;
   }

void Item::DialogNeeded
	(
	Event *ev
	)

	{
   //
   // if this item is needed for a trigger, play this dialog
   //
   dialog_needed = ev->GetString( 1 );
   }

str Item::GetDialogNeeded
	(
   void
	)

	{
   return dialog_needed;
   }

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -