コード例 #1
0
ファイル: g_items.cpp プロジェクト: Clever-Boy/qfusion
/*
* Touch_Item
*/
void Touch_Item( edict_t *ent, edict_t *other, cplane_t *plane, int surfFlags )
{
	bool taken;
	const gsitem_t *item = ent->item;

	if( !other->r.client || G_ISGHOSTING( other ) )
		return;

	if( !( other->r.client->ps.pmove.stats[PM_STAT_FEATURES] & PMFEAT_ITEMPICK ) )
		return;

	if( !item || !( item->flags & ITFLAG_PICKABLE ) )
		return; // not a grabbable item

	if( !G_Gametype_CanPickUpItem( item ) )
		return;

	taken = G_PickupItem( other, item, ent->spawnflags, ent->count, ent->invpak );

	if( !( ent->spawnflags & ITEM_TARGETS_USED ) )
	{
		G_UseTargets( ent, other );
		ent->spawnflags |= ITEM_TARGETS_USED;
	}

	if( !taken )
		return;

	if( ent->spawnflags & ITEM_TIMED )
		ent->r.owner = other;

	// flash the screen
	G_AddPlayerStateEvent( other->r.client, PSEV_PICKUP, ( item->flags & IT_WEAPON ? item->tag : 0 ) );

	G_AwardPlayerPickup( other, ent );

	// for messages
	other->r.client->teamstate.last_pickup = ent;

	// show icon and name on status bar
	other->r.client->ps.stats[STAT_PICKUP_ITEM] = item->tag;
	other->r.client->resp.pickup_msg_time = level.time + 3000;

	if( ent->attenuation )
		Touch_ItemSound( other, item );

	if( !( ent->spawnflags & DROPPED_ITEM ) && G_Gametype_CanRespawnItem( item ) )
	{
		if( (item->type & IT_WEAPON ) && GS_RaceGametype() )
			return; // weapons stay in race
		SetRespawn( ent, G_Gametype_RespawnTimeForItem( item ) );
		return;
	}
	G_FreeEdict( ent );
}
コード例 #2
0
ファイル: g_items.c プロジェクト: hettoo/racesow
/*
* Touch_Item
*/
void Touch_Item( edict_t *ent, edict_t *other, cplane_t *plane, int surfFlags )
{
	qboolean taken;

	if( !other->r.client || G_ISGHOSTING( other ) )
		return;

	if( !( other->r.client->ps.pmove.stats[PM_STAT_FEATURES] & PMFEAT_ITEMPICK ) )
		return;

	if( !ent->item || !( ent->item->flags & ITFLAG_PICKABLE ) )
		return; // not a grabbable item

	if( !G_Gametype_CanPickUpItem( ent->item ) )
		return;

	taken = G_PickupItem( ent, other );

	if( !( ent->spawnflags & ITEM_TARGETS_USED ) )
	{
		G_UseTargets( ent, other );
		ent->spawnflags |= ITEM_TARGETS_USED;
	}

	if( !taken )
		return;

	// flash the screen
	G_AddPlayerStateEvent( other->r.client, PSEV_PICKUP, ( ent->item->flags & IT_WEAPON ? ent->item->tag : 0 ) );

	G_AwardPlayerPickup( other, ent );

	// for messages
	other->r.client->teamstate.last_pickup = ent;

	// show icon and name on status bar
	other->r.client->ps.stats[STAT_PICKUP_ITEM] = ent->item->tag;
	other->r.client->resp.pickup_msg_time = level.time + 3000;

	if( ent->attenuation )
		Touch_ItemSound( other, ent->item );

	if( !( ent->spawnflags & ( DROPPED_ITEM | DROPPED_PLAYER_ITEM ) ) && G_Gametype_CanRespawnItem( ent->item ) )
		SetRespawn( ent, G_Gametype_RespawnTimeForItem( ent->item ) );
	else
		G_FreeEdict( ent );
}
コード例 #3
0
//target_give wait classname weapon_xxx
static void target_give_use( edict_t *self, edict_t *other, edict_t *activator )
{
	edict_t *give;
	const gsitem_t *item;
	int i, numsounds;
	float attenuation;
	const char *pickup_sound;
	int prev_pickup = -1;
	gclient_t *aclient = activator && activator->r.client ? activator->r.client : NULL;
	const gsitem_t *sounds[MAX_GIVE_SOUNDS];

	give = NULL;
	numsounds = 0;

	// more than one item can be given
	while( ( give = G_Find( give, FOFS( targetname ), self->target ) ) != NULL )
	{
		// sanity
		item = give->item;
		if( !item )
			continue;

		if( !( item->flags & ITFLAG_PICKABLE ) )
			continue;

		if( aclient ) {
			prev_pickup = aclient->ps.stats[STAT_PICKUP_ITEM];
		}
		pickup_sound = item->pickup_sound;

		// disable pickup sound, we'll play it later
		attenuation = give->attenuation;
		give->attenuation = 0;

		Touch_Item( give, activator, NULL, 0 );

		if( give->r.inuse ) {
			give->nextThink = 0;
			give->think = 0;
			give->attenuation = attenuation;
			GClip_UnlinkEntity( give );
		}

		// a hacky way to check for successful item pickup
		if( aclient && aclient->ps.stats[STAT_PICKUP_ITEM] == item->tag && prev_pickup != item->tag )
		{
			prev_pickup = item->tag;

			// see if we don't know this pickup sound yet
			if( pickup_sound ) {
				for( i = 0; i < numsounds; i++ ) {
					if( !Q_stricmp( sounds[i]->pickup_sound, pickup_sound ) )
						break;
				}

				if( i == numsounds && numsounds < MAX_GIVE_SOUNDS ) {
					sounds[numsounds++] = item;
				}
			}
		}
	}

	// play unique pickup sounds
	for( i = 0; i < numsounds; i++ ) {
		Touch_ItemSound( activator, sounds[i] );
	}
}