Beispiel #1
0
	/**
	 * @brief Handles beacon expiration and tag score decay. Called every server frame.
	 */
	void Frame()
	{
		gentity_t *ent = nullptr;
		static int nextframe = 0;

		if( nextframe > level.time )
			return;

		while ( ( ent = G_IterateEntities( ent ) ) )
		{
			switch( ent->s.eType )
			{
				case ET_BUILDABLE:
				case ET_PLAYER:
					if( ent->tagScoreTime + 2000 < level.time )
						ent->tagScore -= 50;
					if( ent->tagScore < 0 )
						ent->tagScore = 0;
					break;

				case ET_BEACON:
					if ( ent->s.bc_etime && level.time > ent->s.bc_etime )
						Delete( ent );
					continue;

				default:
					break;
			}
		}

		nextframe = level.time + 100;
	}
gentity_t *G_PickRandomEntity( const char *classname, size_t fieldofs, const char *match )
{
	gentity_t *foundEntity = nullptr;
	int       totalChoiceCount = 0;
	gentity_t *choices[ MAX_GENTITIES - 2 - MAX_CLIENTS ];

	//collects the targets
	while( ( foundEntity = G_IterateEntities( foundEntity, classname, true, fieldofs, match ) ) != nullptr )
		choices[ totalChoiceCount++ ] = foundEntity;

	if ( !totalChoiceCount )
	{

		if ( g_debugEntities.integer > -1 )
			G_Printf( S_WARNING "Could not find any entity matching \"^5%s%s%s^7\"\n",
					classname ? classname : "",
					classname && match ? "^7 and ^5" :  "",
					match ? match : ""
					);

		return nullptr;
	}

	//return a random one from among the choices
	return choices[ rand() / ( RAND_MAX / totalChoiceCount + 1 ) ];
}
Beispiel #3
0
	/**
	 * @brief Propagates all beacons in the world.
	 *
	 * Should be called everytime someone joins or leaves a team.
	 */
	void PropagateAll()
	{
		for ( gentity_t *ent = nullptr; (ent = G_IterateEntities( ent )); )
		{
			if ( ent->s.eType != ET_BEACON )
				continue;

			Propagate( ent );
		}
	}
Beispiel #4
0
	/**
	 * @brief Remove all per-player beacons that belong to a player.
	 *
	 * Per-team beacons get their ownership cleared.
	 */
	void RemoveOrphaned( int clientNum )
	{
		for ( gentity_t *ent = nullptr; ( ent = G_IterateEntities( ent ) ); )
		{
			if ( ent->s.eType != ET_BEACON )
				continue;

			if ( ent->s.bc_owner != clientNum )
				continue;

			Delete( ent );
		}
	}
Beispiel #5
0
	/**
	 * @brief Find a beacon matching a pattern.
	 * @return An ET_BEACON entity or nullptr.
	 */
	gentity_t *FindSimilar( const vec3_t origin, beaconType_t type, int data, int team, int owner,
	                        float radius, int eFlags, int eFlagsRelevant )
	{
		int flags = BG_Beacon( type )->flags;

		for ( gentity_t *ent = nullptr; (ent = G_IterateEntities(ent)); )
		{
			if ( ent->s.eType != ET_BEACON )
				continue;

			if ( ent->s.bc_type != type )
				continue;

			if ( ( ent->s.eFlags & eFlagsRelevant ) != ( eFlags & eFlagsRelevant ) )
				continue;

			if( ent->s.bc_team != team )
				continue;

			if ( ( flags & BCF_DATA_UNIQUE ) && ent->s.bc_data != data )
				continue;

			if ( ent->s.eFlags & EF_BC_DYING )
				continue;

			if     ( flags & BCF_PER_TEAM )
			{}
			else if( flags & BCF_PER_PLAYER )
			{
				if( ent->s.bc_owner != owner )
					continue;
			}
			else
			{
				if ( Distance( ent->s.origin, origin ) > radius )
					continue;

				if ( !trap_InPVS( ent->s.origin, origin ) )
					continue;
			}

			return ent;
		}

		return nullptr;
	}
/*
=============
G_IterateEntitiesWithField

Searches all active entities for the next one that holds
the matching string at fieldofs (use the FOFS() macro) in the structure.

Searches beginning at the entity after from, or the beginning if nullptr
nullptr will be returned if the end of the list is reached.

if we are not searching for player entities it is recommended to start searching from gentities[MAX_CLIENTS - 1]

=============
*/
gentity_t *G_IterateEntitiesWithField( gentity_t *entity, size_t fieldofs, const char *match )
{
	return G_IterateEntities( entity, nullptr, true, fieldofs, match );
}
gentity_t *G_IterateEntitiesOfClass( gentity_t *entity, const char *classname )
{
	return G_IterateEntities( entity, classname, true, 0, nullptr );
}
gentity_t *G_IterateEntities( gentity_t *entity )
{
	return G_IterateEntities( entity, nullptr, true, 0, nullptr );
}
Beispiel #9
0
gentity_t *G_IterateEntitiesOfClass( gentity_t *entity, const char *classname )
{
	return G_IterateEntities( entity, classname, qtrue, 0, NULL );
}