Multiple changes

- added additonal documentation
- modified G_GetEntityByTargetname to use list
- modified G_GetEntityByTarget to use list
- modified G_GetEntityByBmodel to use list
This commit is contained in:
Walter Julius Hennecke 2013-04-11 22:10:45 +02:00
parent 4e08198ead
commit f144ae5f11
3 changed files with 76 additions and 28 deletions

View file

@ -689,7 +689,7 @@ SetTeam
qboolean SetTeam( gentity_t *ent, char *s ) {
int team, oldTeam;
gclient_t *client;
int clientNum, clNum;
int clientNum;
spectatorState_t specState;
int specClient;
int isBot;
@ -708,7 +708,6 @@ qboolean SetTeam( gentity_t *ent, char *s ) {
specState = SPECTATOR_NOT;
clNum = client->ps.clientNum;
sess = &client->sess;
if ( g_gametype.integer >= GT_TEAM && !isBot )
@ -6349,9 +6348,10 @@ Cmd_getEntByTarget_f
*/
static void Cmd_getEntByTarget_f(gentity_t *ent) {
char arg[MAX_STRING_TOKENS];
int cnt;
int i;
gentity_t *entities[MAX_GENTITIES];
struct list entities;
list_iter_p iter;
container_p c;
gentity_t* t;
#ifndef SQL
if ( !IsAdmin( ent ) ) {
@ -6367,12 +6367,25 @@ static void Cmd_getEntByTarget_f(gentity_t *ent) {
trap_Argv(1, arg, sizeof(arg));
cnt = G_GetEntityByTarget(arg, entities);
list_init(&entities, free);
G_GetEntityByTarget(arg, &entities);
for(i = 0; i < cnt; i++) {
if(!entities[i] || !entities[i]->classname) continue;
G_PrintfClient(ent, "ENT %i: %s\n\"", entities[i]->s.number, entities[i]->classname);
iter = list_iterator(&entities, LIST_FRONT);
for(c = list_next(iter); c != NULL; c = list_next(iter)) {
t = c->data;
if(t == NULL) {
continue;
}
if(!t->classname) {
continue;
}
G_PrintfClient(ent, "ENT %i: %s\n\"", t->s.number, t->classname);
}
destroy_iterator(iter);
list_clear(&entities);
}
/*

View file

@ -815,7 +815,16 @@ void G_AddEvent( gentity_t* ent, int event, int eventParm );
void G_SetOrigin( gentity_t* ent, vec3_t origin );
void G_SetAngles( gentity_t* ent, vec3_t anlges ); //RPG-X | GSIO01 | 24.08.2009
/**
* Get a list of entities in a specified radous around an origin.
*
* \param origin Origin to search around.
* \param radius Radius to serach in.
* \param ignore List of entities to ignore.
* \param takeDamage Only return entities matching this value for takeDamage.
* \param ent_list List to store found entities in.
* \return Count of entities found.
*/
int G_RadiusList ( vec3_t origin, float radius, list_p ignore, qboolean takeDamage, list_p ent_list);
/**
@ -832,13 +841,33 @@ int G_RadiusList ( vec3_t origin, float radius, list_p ignore, qboolean takeDa
* \return count of found entities
*/
int G_RadiusListOfTypes(list_p classnames, vec3_t origin, float radius, list_p ignore, list_p ent_list);
/**
* Get the neares entity to an origin.
*
* \param classname Filter by this classname.
* \param origin Origin to search around.
* \param radius Radius to search in.
* \param ignore List of entities to ignore.
* \param takeDamage Only return entities that match this value for takeDamage.
* \return Nearest entity found.
*/
gentity_t* G_GetNearestEnt(char* classname, vec3_t origin, float radius, list_p ignore, qboolean takeDamage);
/**
* Get the nearest player orund an origin.
*
* \param origin Origin to search around.
* \param radius Radius to search in.
* \param ignore List of entities to ignore.
* \return Nearest player.
*/
gentity_t* G_GetNearestPlayer(vec3_t origin, float radius, list_p ignore );
// GSIO - additional util funcs to make life easier with spawnfile
int G_GetEntityByTargetname(const char* targetname, gentity_t* entities[MAX_GENTITIES]);
int G_GetEntityByTarget(const char* target, gentity_t* entities[MAX_GENTITIES]);
int G_GetEntityByBmodel(char* bmodel, gentity_t* entities[MAX_GENTITIES]);
int G_GetEntityByTargetname(const char* targetname, list_p entities);
int G_GetEntityByTarget(const char* target, list_p entities);
int G_GetEntityByBmodel(char* bmodel,list_p entities);
/* shader remapping */
void AddRemap(const char* oldShader, const char* newShader, float timeOffset);

View file

@ -1350,21 +1350,23 @@ gentity_t *G_GetNearestPlayer(vec3_t origin, float radius, list_p ignore ) {
*
* @return number of entities found
*/
int G_GetEntityByTargetname(const char *targetname, gentity_t *entities[MAX_GENTITIES]) {
int G_GetEntityByTargetname(const char *targetname, list_p entities) {
int i;
int cnt = 0;
gentity_t *t;
if(entities == NULL) {
return 0;
}
for(i = MAX_GENTITIES - 1; i > -1; i--) {
if(!&g_entities[i]) continue;
t = &g_entities[i];
if(t->targetname && !Q_strncmp(t->targetname, targetname, strlen(targetname))) {
entities[cnt] = t;
cnt++;
list_append_ptr(entities, t, LT_DATA);
}
}
return cnt;
return entities->length;
}
/**
@ -1378,21 +1380,23 @@ int G_GetEntityByTargetname(const char *targetname, gentity_t *entities[MAX_GENT
*
* @return number of matches found
*/
int G_GetEntityByTarget(const char *target, gentity_t *entities[MAX_GENTITIES]) {
int G_GetEntityByTarget(const char *target, list_p entities) {
int i;
int cnt = 0;
gentity_t *t;
if(entities == NULL) {
return 0;
}
for(i = MAX_GENTITIES - 1; i > -1; i--) {
if(!&g_entities[i]) continue;
t = &g_entities[i];
if(t->target && !Q_strncmp(t->target, target, strlen(target))) {
entities[cnt] = t;
cnt++;
list_append_ptr(entities, t, LT_DATA);
}
}
return cnt;
return entities->length;
}
/**
@ -1407,21 +1411,23 @@ int G_GetEntityByTarget(const char *target, gentity_t *entities[MAX_GENTITIES])
*
* @return number of matches found
*/
int G_GetEntityByBmodel(char *bmodel, gentity_t *entities[MAX_GENTITIES]) {
int G_GetEntityByBmodel(char *bmodel, list_p entities) {
int i;
int cnt = 0;
gentity_t *t;
if(entities == NULL) {
return 0;
}
for(i = MAX_GENTITIES - 1; i > -1; i--) {
if(!&g_entities[i]) continue;
t = &g_entities[i];
if(t->model && !Q_strncmp(t->model, bmodel, strlen(bmodel))) {
entities[cnt] = t;
cnt++;
list_append_ptr(entities, t, LT_DATA);
}
}
return cnt;
return entities->length;
}
/**