target_safezone can now be toggled on and off

- target_safezone can now be toggled on and off
- added STARTON spawnflag
This commit is contained in:
Walter Julius Hennecke 2012-07-27 00:50:55 +02:00
parent a0b1d4fc9e
commit 872f3326e0
3 changed files with 76 additions and 13 deletions

View file

@ -2055,10 +2055,10 @@ struct luaAlertState_s {
luaAlertState_t *luaAlertState;
typedef struct safeZone_s safeZone_t;
/*typedef struct safeZone_s safeZone_t;
struct safeZone_s {
vec3_t maxs;
vec3_t mins;
} safeZone_s;
} safeZone_s;*/
#endif //_G_LOCAL_H_

View file

@ -2188,7 +2188,6 @@ void G_InitGame( int levelTime, int randomSeed, int restart ) {
}
/*
=================
G_ShutdownGame

View file

@ -1,7 +1,7 @@
// Copyright (C) 1999-2000 Id Software, Inc.
//
#include "g_local.h"
#include "list.h"
//#include "list.h"
//#include <windows.h> //TiM : WTF?
//==========================================================
@ -2576,8 +2576,9 @@ damage: leveltime of countdowns end
spawnflags: 1 tells ent to free once aborted
*/
list_p selfdestructSafeZones;
//list_p selfdestructSafeZones;
#if 0
static int target_selfdestruct_get_unsafe_players(gentity_t *ents[MAX_GENTITIES]) {
int i, n, num, cur = 0, cur2 = 0;
list_iter_p iter;
@ -2595,7 +2596,7 @@ static int target_selfdestruct_get_unsafe_players(gentity_t *ents[MAX_GENTITIES]
for(sz = (safeZone_t *)list_next(iter); sz != NULL; sz = (safeZone_t *)list_next(iter)) {
num = trap_EntitiesInBox(sz->mins, sz->maxs, entlist, MAX_GENTITIES);
for(n = 0; n < num; n++) {
if(entlist[n] < g_maxclients.integer) {
if(entlist[n] < g_maxclients.integer && g_entities[entlist[n]].client) {
safePlayers[cur] = &g_entities[entlist[n]];
cur++;
}
@ -2604,6 +2605,54 @@ static int target_selfdestruct_get_unsafe_players(gentity_t *ents[MAX_GENTITIES]
// now use that information to determines all unsafe players
for(i = 0; i < MAX_CLIENTS; i++) {
for(n = 0; n < cur; n++) {
if(&g_entities[i] == safePlayers[n]) {
add = qfalse;
break;
}
}
if(add) {
if(&g_entities[i].client) {
ents[cur2] = &g_entities[i];
cur2++;
}
}
}
return cur2;
}
#else
static int target_selfdestruct_get_unsafe_players(gentity_t *ents[MAX_GENTITIES]) {
int i, n, num, cur = 0, cur2 = 0;
int entlist[MAX_GENTITIES];
gentity_t *safePlayers[MAX_GENTITIES];
qboolean add = qtrue;
vec3_t maxs, mins;
gentity_t *ent;
// go through all safe zones and compose a list of sade players
for(i = 0; i < MAX_GENTITIES; i++) {
ent = &g_entities[i];
if(!ent || !ent->inuse) {
continue;
}
if(Q_stricmp(ent->classname, "target_safezone") || !ent->count) {
continue;
}
VectorAdd(ent->s.origin, ent->r.maxs, maxs);
VectorAdd(ent->s.origin, ent->r.mins, mins);
num = trap_EntitiesInBox(mins, maxs, entlist, MAX_GENTITIES);
for(n = 0; n < num; n++) {
if(entlist[n] < g_maxclients.integer) {
safePlayers[cur] = &g_entities[entlist[n]];
cur++;
}
}
}
// now use that information to determines all unsafe players
for(i = 0; i < g_maxclients.integer; i++) {
for(n = 0; n < cur; n++) {
if(&g_entities[i] == safePlayers[n]) {
add = qfalse;
@ -2618,6 +2667,7 @@ static int target_selfdestruct_get_unsafe_players(gentity_t *ents[MAX_GENTITIES]
return cur2;
}
#endif
void target_selfdestruct_use(gentity_t *ent, gentity_t *other, gentity_t *activator) {
//with the use-function we're going to init aborts in a fairly simple manner: Fire warning notes...
@ -2870,28 +2920,42 @@ void SP_target_selfdestruct(gentity_t *ent) {
trap_LinkEntity(ent);
}
/*QUAKED target_safezone (1 0 0) ?
/*QUAKED target_safezone (1 0 0) ? STARTON
This is a safezone for the self destruct sequence.
*/
void target_safezone_use(gentity_t *ent, gentity_t *other, gentity_t *activator) {
ent->count = !ent->count;
}
void SP_target_safezone(gentity_t *ent) {
safeZone_t* sz = (safeZone_t *)malloc(sizeof(safeZone_s));
/*safeZone_t* sz = (safeZone_t *)malloc(sizeof(safeZone_s));
if(selfdestructSafeZones == NULL) {
selfdestructSafeZones = create_list();
}
}*/
if(!ent->luaEntity) {
trap_SetBrushModel(ent, ent->model);
}
VectorCopy(ent->r.maxs, sz->maxs);
/*VectorCopy(ent->r.maxs, sz->maxs);
VectorCopy(ent->r.mins, sz->mins);
VectorAdd(ent->s.origin, ent->r.mins, sz->mins);
VectorAdd(ent->s.origin, ent->r.maxs, sz->maxs);
VectorAdd(ent->s.origin, ent->r.maxs, sz->maxs);*/
ent->r.contents = CONTENTS_NONE;
ent->r.svFlags |= SVF_NOCLIENT;
if(ent->spawnflags & 1) {
ent->count = 1;
} else {
ent->count = 0;
}
ent->use = target_safezone_use;
trap_LinkEntity(ent);
list_add(selfdestructSafeZones, sz, sizeof(safeZone_s));
/*list_add(selfdestructSafeZones, sz, sizeof(safeZone_s));*/
G_FreeEntity(ent);
//G_FreeEntity(ent);
}