void G_notify_sensor_start()
{
	gentity_t *sensor = NULL;

	if( g_debugEntities.integer >= 2 )
		G_Printf( S_DEBUG "Notification of match start.\n");

	while ((sensor = G_IterateEntitiesOfClass(sensor, S_SENSOR_START)) != NULL )
	{
		sensor_start_fireAndForget(sensor);
	}
}
void G_notify_sensor_end( team_t winningTeam )
{
	gentity_t *entity = NULL;

	if( g_debugEntities.integer >= 2 )
		G_Printf( S_DEBUG "Notification of game end. Winning team %i.\n", winningTeam );

	while ((entity = G_IterateEntitiesOfClass(entity, S_SENSOR_END)) != NULL )
	{
		if ((winningTeam == entity->conditions.team) == !entity->conditions.negated)
			G_FireEntity(entity, entity);
	}
}
Example #3
0
/*
================
G_SelectSpawnBuildable

find the nearest buildable of the right type that is
spawned/healthy/unblocked etc.
================
*/
static gentity_t *G_SelectSpawnBuildable( vec3_t preference, buildable_t buildable )
{
	gentity_t *search = nullptr;
	gentity_t *spot = nullptr;

	while ( ( search = G_IterateEntitiesOfClass( search, BG_Buildable( buildable )->entityName ) ) != nullptr )
	{
		if ( !search->spawned )
		{
			continue;
		}

		if ( G_Dead( search ) )
		{
			continue;
		}

		if ( search->s.groundEntityNum == ENTITYNUM_NONE )
		{
			continue;
		}

		if ( search->clientSpawnTime > 0 )
		{
			continue;
		}

		Entity* blocker = nullptr;
		Vec3    spawnPoint;

		search->entity->CheckSpawnPoint(blocker, spawnPoint);

		if (blocker)
		{
			continue;
		}

		if ( !spot || DistanceSquared( preference, search->s.origin ) <
		     DistanceSquared( preference, spot->s.origin ) )
		{
			spot = search;
		}
	}

	return spot;
}
Example #4
0
/*
================
G_SelectSpawnBuildable

find the nearest buildable of the right type that is
spawned/healthy/unblocked etc.
================
*/
static gentity_t *G_SelectSpawnBuildable( vec3_t preference, buildable_t buildable )
{
	gentity_t *search = NULL;
	gentity_t *spot = NULL;

	while ( ( search = G_IterateEntitiesOfClass( search, BG_Buildable( buildable )->entityName ) ) != NULL )
	{
		if ( !search->spawned )
		{
			continue;
		}

		if ( search->health <= 0 )
		{
			continue;
		}

		if ( search->s.groundEntityNum == ENTITYNUM_NONE )
		{
			continue;
		}

		if ( search->clientSpawnTime > 0 )
		{
			continue;
		}

		if ( G_CheckSpawnPoint( search->s.number, search->s.origin,
		                        search->s.origin2, buildable, NULL ) != NULL )
		{
			continue;
		}

		if ( !spot || DistanceSquared( preference, search->s.origin ) <
		     DistanceSquared( preference, spot->s.origin ) )
		{
			spot = search;
		}
	}

	return spot;
}
/*
===============
G_notify_sensor_stage

Called when stages change
===============
*/
void G_notify_sensor_stage( team_t team, stage_t previousStage, stage_t newStage )
{
	gentity_t *entities = NULL;

	if( g_debugEntities.integer >= 2 )
		G_Printf( S_DEBUG "Notification of team %i changing stage from %i to %i (0-2).\n", team, previousStage, newStage );

	if(newStage <= previousStage) //not supporting stage down yet, also no need to fire if stage didn't change at all
		return;

	while ((entities = G_IterateEntitiesOfClass(entities, S_SENSOR_STAGE)) != NULL )
	{
		if (((!entities->conditions.stage || newStage == entities->conditions.stage)
				&& (!entities->conditions.team || team == entities->conditions.team))
				== !entities->conditions.negated)
		{
			G_FireEntity(entities, entities);
		}
	}
}
Example #6
0
/*
===========
G_SelectRandomFurthestSpawnPoint

Chooses a player start, deathmatch start, etc
============
*/
gentity_t *G_SelectRandomFurthestSpawnPoint( vec3_t avoidPoint, vec3_t origin, vec3_t angles )
{
	gentity_t *spot = nullptr;
	vec3_t    delta;
	float     dist;
	float     list_dist[ 64 ];
	gentity_t *list_spot[ 64 ];
	int       numSpots, rnd, i, j;

	numSpots = 0;

	while ( ( spot = G_IterateEntitiesOfClass( spot, S_POS_PLAYER_SPAWN ) ) != nullptr )
	{
		if ( SpotWouldTelefrag( spot ) )
		{
			continue;
		}

		VectorSubtract( spot->s.origin, avoidPoint, delta );
		dist = VectorLength( delta );

		for ( i = 0; i < numSpots; i++ )
		{
			if ( dist > list_dist[ i ] )
			{
				if ( numSpots >= 64 )
				{
					numSpots = 64 - 1;
				}

				for ( j = numSpots; j > i; j-- )
				{
					list_dist[ j ] = list_dist[ j - 1 ];
					list_spot[ j ] = list_spot[ j - 1 ];
				}

				list_dist[ i ] = dist;
				list_spot[ i ] = spot;
				numSpots++;

				if ( numSpots > 64 )
				{
					numSpots = 64;
				}

				break;
			}
		}

		if ( i >= numSpots && numSpots < 64 )
		{
			list_dist[ numSpots ] = dist;
			list_spot[ numSpots ] = spot;
			numSpots++;
		}
	}

	if ( !numSpots )
	{
		spot = G_IterateEntitiesOfClass( nullptr, S_POS_PLAYER_SPAWN );

		if ( !spot )
		{
			Com_Error(errorParm_t::ERR_DROP,  "Couldn't find a spawn point" );
		}

		VectorCopy( spot->s.origin, origin );
		origin[ 2 ] += 9;
		VectorCopy( spot->s.angles, angles );
		return spot;
	}

	// select a random spot from the spawn points furthest away
	rnd = random() * ( numSpots / 2 );

	VectorCopy( list_spot[ rnd ]->s.origin, origin );
	origin[ 2 ] += 9;
	VectorCopy( list_spot[ rnd ]->s.angles, angles );

	return list_spot[ rnd ];
}