Example #1
0
void ammo_touch(gentity_t *self, gentity_t *other, trace_t *trace) {
	int       i, clientcount = 0;
	gentity_t *touchClients[MAX_CLIENTS];

	// Nico, silent GCC
	(void)trace;

	memset(touchClients, 0, sizeof (touchClients));

	if (other->client == NULL) {
		return;
	}

	// flags is for the last entity number that got ammo
	if (self->timestamp > level.time) {
		return;
	}
	self->timestamp = level.time + 1000;

	for (i = 0; i < level.numConnectedClients; i++) {
		int j = level.sortedClients[i];

		if (trap_EntityContactCapsule(g_entities[j].r.absmin, g_entities[j].r.absmax, self) && G_IsAllowedAmmo(&g_entities[j])) {
			touchClients[clientcount] = &g_entities[j];
			clientcount++;
		}
	}

	if (clientcount == 0) {
		return;
	}
}
Example #2
0
void heal_touch(gentity_t * self, gentity_t * other, trace_t * trace)
{
	int             i, clientcount = 0;
	gentity_t      *touchClients[MAX_CLIENTS];
	int             healvalue;

	memset(touchClients, 0, sizeof(touchClients));

	if(!other->client)
	{
		return;
	}

	if(self->timestamp > level.time)
	{
		return;
	}
	self->timestamp = level.time + 1000;

	for(i = 0; i < level.numConnectedClients; i++)
	{
		int             j = level.sortedClients[i];

		if(level.clients[j].ps.stats[STAT_MAX_HEALTH] > g_entities[j].health &&
		   trap_EntityContactCapsule(g_entities[j].r.absmin, g_entities[j].r.absmax, self) && G_IsAllowedHeal(&g_entities[j]))
		{
			touchClients[clientcount] = &g_entities[j];
			clientcount++;
		}
	}

	if(clientcount == 0)
	{
		return;
	}

	for(i = 0; i < clientcount; i++)
	{
		healvalue = min(touchClients[i]->client->ps.stats[STAT_MAX_HEALTH] - touchClients[i]->health, self->damage);
		if(self->health != -9999)
		{
			healvalue = min(healvalue, self->health);
		}
		if(healvalue <= 0)
		{
			continue;
		}

		touchClients[i]->health += healvalue;
		// add the medicheal event (to get sound, etc.)
		G_AddPredictableEvent(other, EV_ITEM_PICKUP, BG_FindItemForClassName("item_health_cabinet") - bg_itemlist);

		if(self->health != -9999)
		{
			self->health -= healvalue;
		}
	}
}
Example #3
0
void ammo_touch( gentity_t *self, gentity_t *other, trace_t *trace ) {
	int i, clientcount = 0, count;
	gentity_t* touchClients[MAX_CLIENTS];

	memset(touchClients, 0, sizeof(touchClients));

	if( other->client == NULL ) {
		return;
	}

	// flags is for the last entity number that got ammo
	if ( self->timestamp > level.time ) {
		return;
	}
	self->timestamp = level.time + 1000;

	for( i = 0; i < level.numConnectedClients; i++ ) {
		int j = level.sortedClients[i];

		if( trap_EntityContactCapsule( g_entities[j].r.absmin, g_entities[j].r.absmax, self ) && G_IsAllowedAmmo( &g_entities[j] ) ) {
			touchClients[clientcount] = &g_entities[j];
			clientcount++;
		}
	}
	
	if(clientcount == 0) {
		return;
	}

	// Gordon: if low, just give out what's left
	if(self->health == -9999) {
		count = clientcount;
	} else {
		count = min(clientcount, self->health / (float)self->damage );
	}

	for( i = 0; i < count; i++) {
		int ammoAdded = qfalse;

		// self->damage contains the amount of ammo to add
		ammoAdded = AddMagicAmmo(touchClients[i], self->damage);

		if (ammoAdded) {
			// add the ammo pack event (to get sound, etc.)
			G_AddPredictableEvent( touchClients[i], EV_ITEM_PICKUP, BG_FindItem("Ammo Pack")-bg_itemlist );
			if (self->health != -9999) {
				// reduce the ammount of available ammo by the added clip number
				self->health -= self->damage;
//				G_Printf("%i clips left\n", self->health );
			}
		}
	}
}
Example #4
0
/*
============
G_TouchTriggers

Find all trigger entities that ent's current position touches.
Spectators will only interact with teleporters.
============
*/
void G_TouchTriggers(gentity_t *ent) {
	int           i, num, triggerMultiples, pushTriggers;
	int           touch[MAX_GENTITIES];
	gentity_t     *hit;
	trace_t       trace;
	vec3_t        mins, maxs;
	static vec3_t range = { 40, 40, 52 };

	if (!ent->client) {
		return;
	}

	// Arnout: reset the pointer that keeps track of trigger_objective_info tracking
	ent->client->touchingTOI = NULL;

	// dead clients don't activate triggers!
	if (ent->client->ps.stats[STAT_HEALTH] <= 0) {
		return;
	}

	VectorSubtract(ent->client->ps.origin, range, mins);
	VectorAdd(ent->client->ps.origin, range, maxs);

	num = trap_EntitiesInBox(mins, maxs, touch, MAX_GENTITIES);

	// can't use ent->absmin, because that has a one unit pad
	VectorAdd(ent->client->ps.origin, ent->r.mins, mins);
	VectorAdd(ent->client->ps.origin, ent->r.maxs, maxs);

	triggerMultiples = 0;
	pushTriggers     = 0;
	for (i = 0 ; i < num ; ++i) {
		hit = &g_entities[touch[i]];

		if (!hit->touch && !ent->touch) {
			continue;
		}
		if (!(hit->r.contents & CONTENTS_TRIGGER)) {
			continue;
		}

		// Arnout: invisible entities can't be touched
		// Gordon: radiant tabs arnout! ;)
		if (hit->entstate == STATE_INVISIBLE ||
		    hit->entstate == STATE_UNDERCONSTRUCTION) {
			continue;
		}

		// ignore most entities if a spectator
		if (ent->client->sess.sessionTeam == TEAM_SPECTATOR && hit->s.eType != ET_TELEPORT_TRIGGER) {
			continue;
		}

		// use seperate code for determining if an item is picked up
		// so you don't have to actually contact its bounding box
		if (hit->s.eType == ET_ITEM) {
			if (!BG_PlayerTouchesItem(&ent->client->ps, &hit->s, level.time)) {
				continue;
			}
		} else {
			// MrE: always use capsule for player
			if (!trap_EntityContactCapsule(mins, maxs, hit)) {
				continue;
			}
		}

		// suburb, check which triggers we hit
		if (hit->s.eType == ET_TRIGGER_MULTIPLE) {
			triggerMultiples++;
		}

		if (hit->s.eType == ET_PUSH_TRIGGER) {
			pushTriggers++;
		}

		memset(&trace, 0, sizeof (trace));

		if (hit->touch) {
			hit->touch(hit, ent, &trace);
		}
	}

	if (triggerMultiples == 0) {
		ent->client->pers.isTouchingTrigger = qfalse;
	} else {
		ent->client->pers.isTouchingTrigger = qtrue;
	}

	if (pushTriggers == 0) {
		ent->client->pers.isTouchingJumppad = qfalse;
	} else {
		ent->client->pers.isTouchingJumppad = qtrue;
	}
}
Example #5
0
void heal_touch(gentity_t *self, gentity_t *other, trace_t *trace)
{
	int       i, j, clientcount = 0;
	gentity_t *touchClients[MAX_CLIENTS];
	int       healvalue;

	memset(touchClients, 0, sizeof(gentity_t *) * MAX_CLIENTS);

	if (!other->client)
	{
		return;
	}

	if (self->timestamp > level.time)
	{
		return;
	}
	self->timestamp = level.time + 1000;

	for (i = 0; i < level.numConnectedClients; i++)
	{
		j = level.sortedClients[i];

		if (trap_EntityContactCapsule(g_entities[j].r.absmin, g_entities[j].r.absmax, self) && G_IsAllowedHeal(&g_entities[j]))
		{
			touchClients[clientcount] = &g_entities[j];
			clientcount++;
		}
	}

	if (clientcount == 0)
	{
		return;
	}

	for (i = 0; i < clientcount; i++)
	{
		if (touchClients[i]->client->sess.playerType == PC_MEDIC)
		{
			healvalue = MIN((int)(touchClients[i]->client->ps.stats[STAT_MAX_HEALTH] * 1.12) - touchClients[i]->health, self->damage);
		}
		else
		{
			healvalue = MIN(touchClients[i]->client->ps.stats[STAT_MAX_HEALTH] - touchClients[i]->health, self->damage);
		}

		if (self->health != -9999)
		{
			healvalue = MIN(healvalue, self->health);
		}
		if (healvalue <= 0)
		{
			continue;
		}

		touchClients[i]->health += healvalue;
		// add the medicheal event (to get sound, etc.)
		G_AddPredictableEvent(other, EV_ITEM_PICKUP, BG_GetItem(ITEM_HEALTH_CABINET) - bg_itemlist);

		if (self->health != -9999)
		{
			self->health -= healvalue;
		}
	}
}