mirror of
https://github.com/UberGames/rpgxEF.git
synced 2024-11-10 07:11:34 +00:00
Multiple changes (list module related)
- G_RadiusListOfTypes now uses list instead of entity pointer array - added list_clear function
This commit is contained in:
parent
cc5b7d27ce
commit
f6abe0a322
5 changed files with 50 additions and 26 deletions
|
@ -847,7 +847,7 @@ 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_RadiusListOfTypes(char* classname[], int count, vec3_t origin, float radius, gentity_t* ignore, gentity_t* ent_list[MAX_GENTITIES]);
|
||||
int G_RadiusListOfTypes(char* classname[], int count, vec3_t origin, float radius, gentity_t* 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 );
|
||||
|
||||
|
|
|
@ -1083,7 +1083,7 @@ int G_RadiusList ( vec3_t origin, float radius, gentity_t *ignore, qboolean take
|
|||
return(ent_count);
|
||||
}
|
||||
|
||||
int G_RadiusListOfTypes(char *classname[], int count, vec3_t origin, float radius, gentity_t *ignore, gentity_t *ent_list[MAX_GENTITIES]) {
|
||||
int G_RadiusListOfTypes(char *classname[], int count, vec3_t origin, float radius, gentity_t *ignore, list_p ent_list) {
|
||||
float dist;
|
||||
gentity_t *ent;
|
||||
int entityList[MAX_GENTITIES];
|
||||
|
@ -1091,9 +1091,12 @@ int G_RadiusListOfTypes(char *classname[], int count, vec3_t origin, float radiu
|
|||
vec3_t mins, maxs;
|
||||
vec3_t v;
|
||||
int i, e;
|
||||
int ent_count = 0;
|
||||
qboolean valid = qfalse;
|
||||
|
||||
if(ent_list == NULL) {
|
||||
ent_list = create_list();
|
||||
}
|
||||
|
||||
if ( radius < 1 )
|
||||
{
|
||||
radius = 1;
|
||||
|
@ -1146,13 +1149,12 @@ int G_RadiusListOfTypes(char *classname[], int count, vec3_t origin, float radiu
|
|||
}
|
||||
|
||||
/* 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);
|
||||
|
||||
valid = qfalse;
|
||||
}
|
||||
/* we are done, return how many we found */
|
||||
return(ent_count);
|
||||
return ent_list->length;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -111,42 +111,50 @@ void G_Weapon_SnapVectorTowards( vec3_t v, vec3_t to ) {
|
|||
*/
|
||||
static void WP_FireHyperspanner(gentity_t *ent, qboolean alt_fire) {
|
||||
float modifier;
|
||||
gentity_t *validEnts[MAX_GENTITIES];
|
||||
struct list validEnts;
|
||||
list_iter_p iter;
|
||||
container_p cont;
|
||||
gentity_t* e = NULL;
|
||||
gentity_t* nearest = NULL;
|
||||
int count = 0;
|
||||
int i, nearest = -1;
|
||||
float nearestd = 65000;
|
||||
vec3_t dVec, end;
|
||||
vec3_t mins = { -40, -40, 0 }, maxs = { 40, 40, 0 };
|
||||
char* classnames[] = { "func_breakable", "misc_model_breakable" };
|
||||
|
||||
/* find all vlaid entities in range */
|
||||
count = G_RadiusListOfTypes(classnames, 2, ent->r.currentOrigin, 512, NULL, validEnts);
|
||||
memset(&validEnts, 0, sizeof(struct list));
|
||||
count = G_RadiusListOfTypes(classnames, 2, ent->r.currentOrigin, 512, NULL, &validEnts);
|
||||
//G_Printf("Found %d possible candidates\n", count);
|
||||
if(count) {
|
||||
trace_t tr;
|
||||
for(i = 0; i < count; i++) {
|
||||
|
||||
iter = list_iterator(&validEnts, LIST_FRONT);
|
||||
for(cont = list_next(iter); cont != NULL; cont = list_next(iter)) {
|
||||
e = cont->data;
|
||||
|
||||
// TODO: fix problems with small distance
|
||||
if(validEnts[i]->spawnflags & 512) {
|
||||
VectorSubtract(ent->r.currentOrigin, validEnts[i]->s.angles2, dVec);
|
||||
VectorMA(validEnts[i]->s.angles2, 1024, dVec, end);
|
||||
trap_Trace(&tr, validEnts[i]->s.angles2, mins, maxs, end, validEnts[i]->s.number, MASK_SHOT);
|
||||
if(e->spawnflags & 512) {
|
||||
VectorSubtract(ent->r.currentOrigin, e->s.angles2, dVec);
|
||||
VectorMA(e->s.angles2, 1024, dVec, end);
|
||||
trap_Trace(&tr, e->s.angles2, mins, maxs, end, e->s.number, MASK_SHOT);
|
||||
} else {
|
||||
VectorSubtract(ent->r.currentOrigin, validEnts[i]->s.origin, dVec);
|
||||
VectorMA(validEnts[i]->s.origin, 1024, dVec, end);
|
||||
trap_Trace(&tr, validEnts[i]->s.origin, mins, maxs, end, validEnts[i]->s.number, MASK_SHOT);
|
||||
VectorSubtract(ent->r.currentOrigin, e->s.origin, dVec);
|
||||
VectorMA(e->s.origin, 1024, dVec, end);
|
||||
trap_Trace(&tr, e->s.origin, mins, maxs, end, e->s.number, MASK_SHOT);
|
||||
}
|
||||
//G_Printf("Checking entity: %d\n", i);
|
||||
if(tr.entityNum != ent->s.number) {
|
||||
continue;
|
||||
}
|
||||
//G_Printf("Nothing is blocking view ...\n");
|
||||
if(validEnts[i]->spawnflags & 512) {
|
||||
VectorSubtract(ent->r.currentOrigin, validEnts[i]->s.angles2, dVec);
|
||||
if(e->spawnflags & 512) {
|
||||
VectorSubtract(ent->r.currentOrigin, e->s.angles2, dVec);
|
||||
} else {
|
||||
VectorSubtract(ent->r.currentOrigin, validEnts[i]->s.origin, dVec);
|
||||
VectorSubtract(ent->r.currentOrigin, e->s.origin, dVec);
|
||||
}
|
||||
if(VectorLength(dVec) < nearestd) {
|
||||
nearest = validEnts[i]->s.number;
|
||||
nearest = e;
|
||||
nearestd = VectorLength(dVec);
|
||||
//G_Printf("New nearest Entity is %d with a distance of %d\n", nearest, nearestd);
|
||||
}
|
||||
|
@ -155,7 +163,8 @@ static void WP_FireHyperspanner(gentity_t *ent, qboolean alt_fire) {
|
|||
return;
|
||||
}
|
||||
|
||||
if(nearest == -1) {
|
||||
if(nearest == NULL || nearest->inuse == qfalse) {
|
||||
list_clear(&validEnts);
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -168,10 +177,12 @@ static void WP_FireHyperspanner(gentity_t *ent, qboolean alt_fire) {
|
|||
|
||||
/* call G_Repair */
|
||||
if(alt_fire) {
|
||||
G_Repair(ent, &g_entities[nearest], HYPERSPANNER_ALT_RATE * modifier);
|
||||
G_Repair(ent, nearest, HYPERSPANNER_ALT_RATE * modifier);
|
||||
} else {
|
||||
G_Repair(ent, &g_entities[nearest], HYPERSPANNER_RATE * modifier);
|
||||
G_Repair(ent, nearest, HYPERSPANNER_RATE * modifier);
|
||||
}
|
||||
|
||||
list_clear(&validEnts);
|
||||
}
|
||||
|
||||
/*
|
||||
|
|
|
@ -293,7 +293,7 @@ void list_remove(list_p list, char end) {
|
|||
}
|
||||
|
||||
if(cont != NULL) {
|
||||
if(cont->pointer > 0 && cont->data != NULL) {
|
||||
if(cont->pointer == 0 && cont->data != NULL) {
|
||||
destructor(cont->data);
|
||||
}
|
||||
|
||||
|
@ -308,7 +308,7 @@ void destroy_list(list_p list) {
|
|||
while(cur!=NULL){
|
||||
next = cur->next;
|
||||
if(list->destructor != NULL) { // only destroy data if there is a destructor set
|
||||
if(cur->cont->pointer > 0 && cur->cont->data != NULL) {
|
||||
if(cur->cont->pointer == 0 && cur->cont->data != NULL) {
|
||||
list->destructor(cur->cont->data);
|
||||
}
|
||||
free(cur->cont);
|
||||
|
@ -319,6 +319,12 @@ void destroy_list(list_p list) {
|
|||
free(list);
|
||||
}
|
||||
|
||||
void list_clear(list_p list) {
|
||||
while(list->length > 0) {
|
||||
list_remove(list, LIST_BACK);
|
||||
}
|
||||
}
|
||||
|
||||
void destroy_iterator(list_iter_p iter) {
|
||||
if(iter == NULL) {
|
||||
return;
|
||||
|
|
|
@ -235,4 +235,9 @@ container_p list_cycl_next(list_iter_p list);
|
|||
*/
|
||||
container_p list_cycl_prev(list_iter_p list);
|
||||
|
||||
/**
|
||||
* Remove all elements.
|
||||
*/
|
||||
void list_clear(list_p list);
|
||||
|
||||
#endif
|
Loading…
Reference in a new issue