mirror of
https://github.com/UberGames/rpgxEF.git
synced 2025-03-13 22:23:04 +00:00
See extented description ...
- modified G_RadiusList to use lists - modified G_GetNearestEnt to use lists - modified G_GetNearestPlayer to use lists
This commit is contained in:
parent
d4c5758fd1
commit
5d0273fbec
4 changed files with 158 additions and 70 deletions
|
@ -7362,8 +7362,11 @@ static void Cmd_findEntitiesInRadius(gentity_t *ent) {
|
|||
char *classname = NULL;
|
||||
qboolean all = qfalse;
|
||||
qboolean takeDamage = qfalse;
|
||||
gentity_t *entities[MAX_GENTITIES];
|
||||
int numEntities;
|
||||
struct list entities;
|
||||
struct list ignore;
|
||||
list_iter_p iter;
|
||||
container_p c;
|
||||
gentity_t* t;
|
||||
|
||||
#ifndef SQL
|
||||
if ( !IsAdmin( ent ) ) {
|
||||
|
@ -7393,16 +7396,30 @@ static void Cmd_findEntitiesInRadius(gentity_t *ent) {
|
|||
trap_Argv(3, arg, sizeof(arg));
|
||||
takeDamage = (qboolean)atoi(arg);
|
||||
|
||||
numEntities = G_RadiusList(ent->r.currentOrigin, radius, ent, takeDamage, entities);
|
||||
list_init(&entities, free);
|
||||
list_init(&ignore, free);
|
||||
list_append_ptr(&ignore, ent, LT_DATA);
|
||||
G_RadiusList(ent->r.currentOrigin, radius, &ignore, takeDamage, &entities);
|
||||
list_clear(&ignore);
|
||||
|
||||
for(radius = 0; radius < numEntities; radius++) {
|
||||
if(all)
|
||||
G_PrintfClient(ent, "Entity: %i, Classname: %s", entities[radius]-g_entities, entities[radius]->classname);
|
||||
else {
|
||||
if(!Q_stricmpn(entities[radius]->classname, classname, strlen(classname)))
|
||||
G_PrintfClient(ent, "Entity: %i Classname: %s", entities[radius]-g_entities, 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(all) {
|
||||
G_PrintfClient(ent, "Entity: %i, Classname: %s", t-g_entities, t->classname);
|
||||
} else {
|
||||
if(!Q_stricmpn(t->classname, classname, strlen(classname))) {
|
||||
G_PrintfClient(ent, "Entity: %i Classname: %s", t-g_entities, classname);
|
||||
}
|
||||
}
|
||||
}
|
||||
destroy_iterator(iter);
|
||||
list_clear(&entities);
|
||||
}
|
||||
|
||||
// CCAM
|
||||
|
|
|
@ -847,7 +847,9 @@ void G_AddPredictableEvent( gentity_t* ent, int event, int eventParm );
|
|||
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
|
||||
int G_RadiusList ( vec3_t origin, float radius, gentity_t* ignore, qboolean takeDamage, gentity_t* ent_list[MAX_GENTITIES]);
|
||||
|
||||
|
||||
int G_RadiusList ( vec3_t origin, float radius, list_p ignore, qboolean takeDamage, list_p ent_list);
|
||||
|
||||
/**
|
||||
* Get a list of specified entity classes in a specified radius.
|
||||
|
@ -863,8 +865,8 @@ int G_RadiusList ( vec3_t origin, float radius, gentity_t* ignore, qboolean ta
|
|||
* \return count of found entities
|
||||
*/
|
||||
int G_RadiusListOfTypes(list_p classnames, vec3_t origin, float radius, list_p ignore, list_p ent_list);
|
||||
gentity_t* G_GetNearestEnt(char* classname, vec3_t origin, float radius, gentity_t* ignore, qboolean takeDamage);
|
||||
gentity_t* G_GetNearestPlayer(vec3_t origin, float radius, gentity_t* ignore );
|
||||
gentity_t* G_GetNearestEnt(char* classname, vec3_t origin, float radius, list_p ignore, qboolean takeDamage);
|
||||
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]);
|
||||
|
|
|
@ -537,9 +537,12 @@ void turret_base_think (gentity_t *self)
|
|||
|
||||
if ( !self->enemy )
|
||||
{/* Find one */
|
||||
gentity_t *entity_list[MAX_GENTITIES], *target;
|
||||
int count, i;
|
||||
gentity_t *target;
|
||||
float bestDist = self->random * self->random;
|
||||
struct list entity_list;
|
||||
struct list ignore;
|
||||
list_iter_p iter;
|
||||
container_p c;
|
||||
|
||||
if ( self->last_move_time > level.time )
|
||||
{/* We're active and alert, had an enemy in the last 5 secs */
|
||||
|
@ -550,13 +553,25 @@ void turret_base_think (gentity_t *self)
|
|||
}
|
||||
}
|
||||
|
||||
if(lastEnemy && lastEnemy->lastEnemy)
|
||||
count = G_RadiusList( self->r.currentOrigin, self->random, lastEnemy->lastEnemy, qtrue, entity_list );
|
||||
else
|
||||
count = G_RadiusList( self->r.currentOrigin, self->random, NULL, qtrue, entity_list );
|
||||
for ( i = 0; i < count; i++ )
|
||||
{
|
||||
target = entity_list[i];
|
||||
list_init(&entity_list, free);
|
||||
list_init(&ignore, free);
|
||||
|
||||
if(lastEnemy && lastEnemy->lastEnemy) {
|
||||
list_append_ptr(&ignore, lastEnemy->lastEnemy, LT_DATA);
|
||||
G_RadiusList( self->r.currentOrigin, self->random, &ignore, qtrue, &entity_list );
|
||||
} else {
|
||||
G_RadiusList( self->r.currentOrigin, self->random, NULL, qtrue, &entity_list );
|
||||
}
|
||||
list_clear(&ignore);
|
||||
|
||||
iter = list_iterator(&entity_list, LIST_FRONT);
|
||||
for(c = list_next(iter); c != NULL; c = list_next(iter)) {
|
||||
target = c->data;
|
||||
|
||||
if(target == NULL) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if ( target == self )
|
||||
{
|
||||
continue;
|
||||
|
@ -600,6 +615,8 @@ void turret_base_think (gentity_t *self)
|
|||
}
|
||||
}
|
||||
}
|
||||
destroy_iterator(iter);
|
||||
list_clear(&entity_list);
|
||||
}
|
||||
|
||||
if ( self->enemy )
|
||||
|
|
|
@ -1022,16 +1022,23 @@ void G_SetAngles(gentity_t *ent, vec3_t angles) {
|
|||
*
|
||||
* @return the number of found entities in the list
|
||||
*/
|
||||
int G_RadiusList ( vec3_t origin, float radius, gentity_t *ignore, qboolean takeDamage, gentity_t *ent_list[MAX_GENTITIES])
|
||||
int G_RadiusList ( vec3_t origin, float radius, list_p ignore, qboolean takeDamage, list_p ent_list)
|
||||
{
|
||||
float dist;
|
||||
gentity_t *ent;
|
||||
gentity_t* ent;
|
||||
gentity_t* t = NULL;
|
||||
int entityList[MAX_GENTITIES];
|
||||
int numListedEntities;
|
||||
int i, e;
|
||||
vec3_t mins, maxs;
|
||||
vec3_t v;
|
||||
int i, e;
|
||||
int ent_count = 0;
|
||||
list_iter_p iter;
|
||||
container_p c;
|
||||
qboolean n = qfalse;
|
||||
|
||||
if(ent_list == NULL) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
if ( radius < 1 )
|
||||
{
|
||||
|
@ -1048,10 +1055,33 @@ int G_RadiusList ( vec3_t origin, float radius, gentity_t *ignore, qboolean take
|
|||
|
||||
for ( e = 0 ; e < numListedEntities ; e++ )
|
||||
{
|
||||
n = qfalse;
|
||||
ent = &g_entities[entityList[e]];
|
||||
|
||||
if ((ent == ignore) || !(ent->inuse) || ent->takedamage != takeDamage)
|
||||
if (!(ent->inuse) || ent->takedamage != takeDamage) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if(ignore != NULL) {
|
||||
iter = list_iterator(ignore, LIST_FRONT);
|
||||
for(c = list_next(iter); c != NULL; c = list_next(iter)) {
|
||||
t = c->data;
|
||||
|
||||
if(t == NULL) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if(t == ent) {
|
||||
n = qtrue;
|
||||
break;
|
||||
}
|
||||
}
|
||||
destroy_iterator(iter);
|
||||
}
|
||||
|
||||
if(n == qtrue) {
|
||||
continue;
|
||||
}
|
||||
|
||||
/* find the distance from the edge of the bounding box */
|
||||
for ( i = 0 ; i < 3 ; i++ )
|
||||
|
@ -1075,18 +1105,16 @@ int G_RadiusList ( vec3_t origin, float radius, gentity_t *ignore, qboolean take
|
|||
}
|
||||
|
||||
/* ok, we are within the radius, add us to the incoming list */
|
||||
ent_list[ent_count] = ent;
|
||||
ent_count++;
|
||||
|
||||
list_append_ptr(ent_list, ent, LT_DATA);
|
||||
}
|
||||
/* we are done, return how many we found */
|
||||
return(ent_count);
|
||||
return ent_list->length;
|
||||
}
|
||||
|
||||
int G_RadiusListOfTypes(list_p classnames, vec3_t origin, float radius, list_p ignore, list_p ent_list) {
|
||||
float dist;
|
||||
gentity_t *ent;
|
||||
gentity_t *t;
|
||||
gentity_t *t = NULL;
|
||||
int entityList[MAX_GENTITIES];
|
||||
int numListedEntities;
|
||||
vec3_t mins, maxs;
|
||||
|
@ -1098,7 +1126,7 @@ int G_RadiusListOfTypes(list_p classnames, vec3_t origin, float radius, list_p i
|
|||
qboolean n = qfalse;
|
||||
|
||||
if(ent_list == NULL) {
|
||||
ent_list = create_list();
|
||||
return 0;
|
||||
}
|
||||
|
||||
if(classnames == NULL || classnames->length == 0) {
|
||||
|
@ -1120,6 +1148,7 @@ int G_RadiusListOfTypes(list_p classnames, vec3_t origin, float radius, list_p i
|
|||
|
||||
for ( e = 0 ; e < numListedEntities ; e++ )
|
||||
{
|
||||
n = qfalse;
|
||||
ent = &g_entities[entityList[e]];
|
||||
|
||||
if(!(ent->inuse)) {
|
||||
|
@ -1203,46 +1232,56 @@ int G_RadiusListOfTypes(list_p classnames, vec3_t origin, float radius, list_p i
|
|||
*
|
||||
* @return the nearest entity
|
||||
*/
|
||||
gentity_t *G_GetNearestEnt(char *classname, vec3_t origin, float radius, gentity_t *ignore, qboolean takeDamage) {
|
||||
gentity_t *entList[MAX_GENTITIES], *nearest = NULL;
|
||||
int count, i;
|
||||
gentity_t *G_GetNearestEnt(char *classname, vec3_t origin, float radius, list_p ignore, qboolean takeDamage) {
|
||||
gentity_t* nearest = NULL;
|
||||
gentity_t* t = NULL;
|
||||
float distance, minDist;
|
||||
vec3_t dist;
|
||||
struct list entList;
|
||||
list_iter_p iter;
|
||||
container_p c;
|
||||
|
||||
if(!radius) { /* we don't care how far it is away */
|
||||
radius = 9999999;
|
||||
}
|
||||
|
||||
minDist = radius;
|
||||
|
||||
count = G_RadiusList(origin, radius, ignore, takeDamage, entList);
|
||||
list_init(&entList, free);
|
||||
G_RadiusList(origin, radius, ignore, takeDamage, &entList);
|
||||
|
||||
for(i = 0; i < count; i++) {
|
||||
if(entList[i] != ignore) {
|
||||
if(entList[i]->s.origin[0] || entList[i]->s.origin[1] || entList[i]->s.origin[2]) {
|
||||
VectorSubtract(origin, entList[i]->s.origin, dist);
|
||||
} else if(entList[i]->r.currentOrigin[0] || entList[i]->r.currentOrigin[1] || entList[i]->r.currentOrigin[2]) {
|
||||
VectorSubtract(origin, entList[i]->r.currentOrigin, dist);
|
||||
} else if(entList[i]->s.pos.trBase[0] || entList[i]->s.pos.trBase[1] || entList[i]->s.pos.trBase[2]) {
|
||||
VectorSubtract(origin, entList[i]->s.pos.trBase, dist);
|
||||
} else { /* wow none of above ... well then assume it's origin is 0 0 0*/
|
||||
VectorCopy(origin, dist);
|
||||
}
|
||||
distance = VectorLength(dist);
|
||||
if(distance < 0) {
|
||||
distance *= -1;
|
||||
}
|
||||
if(distance < minDist) {
|
||||
if(classname && !Q_stricmp(classname, entList[i]->classname)) {
|
||||
minDist = distance;
|
||||
nearest = entList[i];
|
||||
} else if(!classname) {
|
||||
minDist = distance;
|
||||
nearest = entList[i];
|
||||
}
|
||||
iter = list_iterator(&entList, LIST_FRONT);
|
||||
for(c = list_next(iter); c != NULL; c = list_next(iter)) {
|
||||
t = c->data;
|
||||
|
||||
if(t == NULL) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if(t->s.origin[0] || t->s.origin[1] || t->s.origin[2]) {
|
||||
VectorSubtract(origin, t->s.origin, dist);
|
||||
} else if(t->r.currentOrigin[0] || t->r.currentOrigin[1] || t->r.currentOrigin[2]) {
|
||||
VectorSubtract(origin, t->r.currentOrigin, dist);
|
||||
} else if(t->s.pos.trBase[0] || t->s.pos.trBase[1] || t->s.pos.trBase[2]) {
|
||||
VectorSubtract(origin, t->s.pos.trBase, dist);
|
||||
} else { /* wow none of above ... well then assume it's origin is 0 0 0*/
|
||||
VectorCopy(origin, dist);
|
||||
}
|
||||
distance = VectorLength(dist);
|
||||
if(distance < 0) {
|
||||
distance *= -1;
|
||||
}
|
||||
if(distance < minDist) {
|
||||
if(classname && !Q_stricmp(classname, t->classname)) {
|
||||
minDist = distance;
|
||||
nearest = t;
|
||||
} else if(!classname) {
|
||||
minDist = distance;
|
||||
nearest = t;
|
||||
}
|
||||
}
|
||||
}
|
||||
destroy_iterator(iter);
|
||||
list_clear(&entList);
|
||||
|
||||
return nearest;
|
||||
}
|
||||
|
@ -1258,31 +1297,44 @@ gentity_t *G_GetNearestEnt(char *classname, vec3_t origin, float radius, gentity
|
|||
*
|
||||
* @return the nearest player
|
||||
*/
|
||||
gentity_t *G_GetNearestPlayer(vec3_t origin, float radius, gentity_t *ignore ) {
|
||||
gentity_t *entList[MAX_GENTITIES], *nearest = NULL;
|
||||
int i;
|
||||
gentity_t *G_GetNearestPlayer(vec3_t origin, float radius, list_p ignore ) {
|
||||
gentity_t* nearest = NULL;
|
||||
gentity_t* t;
|
||||
float distance, minDist;
|
||||
vec3_t dist;
|
||||
struct list entList;
|
||||
list_iter_p iter;
|
||||
container_p c;
|
||||
|
||||
if(!radius)
|
||||
if(!radius) {
|
||||
radius = 999999;
|
||||
|
||||
}
|
||||
minDist = radius;
|
||||
|
||||
G_RadiusList(origin, radius, ignore, qtrue, entList);
|
||||
list_init(&entList, free);
|
||||
G_RadiusList(origin, radius, ignore, qtrue, &entList);
|
||||
|
||||
for(i = 0; i < MAX_CLIENTS; i++) {
|
||||
if(entList[i]->client) {
|
||||
VectorSubtract(origin, entList[i]->r.currentOrigin, dist);
|
||||
iter = list_iterator(&entList, LIST_FRONT);
|
||||
for(c = list_next(iter); c != NULL; c = list_next(iter)) {
|
||||
t = c->data;
|
||||
|
||||
if(t == NULL) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if(t->client) {
|
||||
VectorSubtract(origin, t->r.currentOrigin, dist);
|
||||
distance = VectorLength(dist);
|
||||
if(distance < 0)
|
||||
distance *= -1;
|
||||
if(distance < minDist) {
|
||||
minDist = distance;
|
||||
nearest = entList[i];
|
||||
nearest = t;
|
||||
}
|
||||
}
|
||||
}
|
||||
destroy_iterator(iter);
|
||||
list_clear(&entList);
|
||||
|
||||
return nearest;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue