Added missing files ...

This commit is contained in:
Walter Julius Hennecke 2012-07-26 22:48:42 +02:00
parent 85910eb34d
commit af3633db4d
5 changed files with 335 additions and 7 deletions

View file

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

View file

@ -1,6 +1,7 @@
// Copyright (C) 1999-2000 Id Software, Inc.
//
#include "g_local.h"
#include "list.h"
//#include <windows.h> //TiM : WTF?
//==========================================================
@ -2575,6 +2576,51 @@ damage: leveltime of countdowns end
spawnflags: 1 tells ent to free once aborted
*/
list_p selfdestructSafeZones;
static int target_selfdestruct_get_unsafe_players(gentity_t *ents[MAX_GENTITIES]) {
int i, n, num, cur = 0, cur2 = 0;
list_iter_p iter;
safeZone_t* sz;
int entlist[MAX_GENTITIES];
gentity_t *safePlayers[MAX_GENTITIES];
qboolean add = qtrue;
if(selfdestructSafeZones == NULL) {
return 0;
}
iter = list_iterator(selfdestructSafeZones, FRONT);
for(i = 0; i < selfdestructSafeZones->length; i++) {
sz = (safeZone_t *)list_current(iter);
num = trap_EntitiesInBox(sz->mins, sz->maxs, entlist, MAX_GENTITIES);
for(n = 0; n < num; n++) {
if(g_entities[entlist[n]].client) {
safePlayers[cur] = &g_entities[entlist[n]];
cur++;
}
}
list_next(iter);
}
for(i = 0; i < MAX_GENTITIES; i++) {
for(n = 0; n < cur + 1; n++) {
if(&g_entities[i] == safePlayers[n]) {
add = qfalse;
break;
}
}
if(add) {
ents[cur2] = &g_entities[i];
cur2++;
}
}
return cur2 + 1;
}
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...
trap_SendServerCommand( -1, va("servermsg \"Self Destruct sequence aborted.\""));
@ -2657,10 +2703,16 @@ void target_selfdestruct_think(gentity_t *ent) {
} else if (ent->wait == 0) { //bang time ^^
//if we have a target fire that, else kill everyone that is not marked as escaped.
//if (!ent->target) {
if (!ent->target) {
int num;
gentity_t *ents[MAX_GENTITIES];
num = target_selfdestruct_get_unsafe_players(ents);
//Loop trough all clients on the server.
for(i = 0; i < level.numConnectedClients; i++) {
client = &g_entities[i];
for(i = 0; i < num; i++) {
client = ents[i];
//if (!client->ent&= FL_ESCAPEPOD) //anyone knowing how to set up this flag?
G_Damage (client, ent, ent, 0, 0, 999999, 0, MOD_TRIGGER_HURT); //maybe a new message ala "[Charname] did not abandon ship."
}
@ -2674,9 +2726,9 @@ void target_selfdestruct_think(gentity_t *ent) {
ent->wait = -1;
ent->nextthink = level.time + 1000;
return;
// } else {
// G_UseTargets(ent, ent);
// }
} else {
G_UseTargets(ent, ent);
}
} else if (ent->wait < 0) {
//we have aborted and the note should be out or ended and everyone should be dead so let's reset
@ -2818,4 +2870,29 @@ void SP_target_selfdestruct(gentity_t *ent) {
}
trap_LinkEntity(ent);
}
}
/*QUAKED target_safezone (1 0 0) ?
This is a safezone for the self destruct sequence.
*/
void SP_target_safezone(gentity_t *ent) {
safeZone_t* sz = (safeZone_t *)malloc(sizeof(safeZone_s));
if(selfdestructSafeZones == NULL) {
selfdestructSafeZones = create_list();
}
VectorCopy(ent->r.maxs, sz->maxs);
VectorCopy(ent->r.mins, sz->mins);
sz->maxs[0] += ent->s.origin[0];
sz->maxs[1] += ent->s.origin[1];
sz->maxs[2] += ent->s.origin[2];
sz->mins[0] += ent->s.origin[0];
sz->mins[0] += ent->s.origin[0];
sz->mins[0] += ent->s.origin[0];
list_add(selfdestructSafeZones, sz, sizeof(safeZone_s));
free(ent);
}

147
game/list.c Normal file
View file

@ -0,0 +1,147 @@
/*
Copyright (c) 2011 Zhehao Mao
Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
of the Software, and to permit persons to whom the Software is furnished to do
so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#include "list.h"
#include <stdlib.h>
#include <string.h>
list_p create_list(){
list_p list = (list_p) malloc(sizeof(struct list));
list->length = 0;
list->first = NULL;
list->last = NULL;
list->destructor = free;
return list;
}
list_iter_p list_iterator(list_p list, char init){
list_iter_p iter = (list_iter_p)malloc(sizeof(struct list_iter));
if(init==FRONT){
iter->current = list->first;
}
else if(init==BACK){
iter->current = list->last;
}
else return NULL;
iter->started = 0;
return iter;
}
void list_add(list_p list, void* data, int size){
lnode_p node = (lnode_p)malloc(sizeof(struct linked_node));
node->data = malloc(size);
memcpy(node->data, data, size);
if(list->first==NULL){
node->prev = NULL;
node->next = NULL;
list->first = node;
list->last = node;
}
else{
list->last->next = node;
node->prev = list->last;
node->next = NULL;
list->last = node;
}
list->length++;
}
void* list_current(list_iter_p iter){
if(iter->started&&iter->current!=NULL)
return iter->current->data;
return NULL;
}
void* list_next(list_iter_p iter){
if(!iter->started&&iter->current!=NULL){
iter->started=1;
return iter->current->data;
}
if(iter->current!=NULL){
iter->current = iter->current->next;
return list_current(iter);
}
return NULL;
}
void* list_prev(list_iter_p iter){
if(!iter->started&&iter->current!=NULL){
iter->started=1;
return iter->current->data;
}
if(iter->current!=NULL){
iter->current = iter->current->prev;
return list_current(iter);
}
return NULL;
}
void* list_first(list_p list){
return list->first->data;
}
void* list_last(list_p list){
return list->last->data;
}
void* list_pop(list_p list){
lnode_p last = list->last;
if(last == NULL) return NULL;
list->last = last->prev;
void* data = last->data;
last->prev->next = NULL;
free(last);
return data;
}
void* list_poll(list_p list){
lnode_p first = list->first;
if(first == NULL) return NULL;
list->first = first->next;
void* data = first->data;
first->next->prev = NULL;
free(first);
return data;
}
void list_remove(list_p list, char end){
void * data;
if(end == FRONT)
data = list_poll(list);
else if (end == BACK)
data = list_pop(list);
else return;
list->destructor(data);
}
void destroy_list(list_p list){
lnode_p cur = list->first;
lnode_p next;
while(cur!=NULL){
next = cur->next;
list->destructor(cur->data);
free(cur);
cur = next;
}
free(list);
}

98
game/list.h Normal file
View file

@ -0,0 +1,98 @@
/*
Copyright (c) 2011 Zhehao Mao
Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
of the Software, and to permit persons to whom the Software is furnished to do
so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#ifndef __LIBDS_LIST_H__
#define __LIBDS_LIST_H__
/* A C implementation of a doubly-linked list. Contains void pointer values.
Can be used as a LIFO stack of FIFO queue. */
#define FRONT 0
#define BACK 1
struct linked_node{
void* data;
struct linked_node* next;
struct linked_node* prev;
};
typedef struct linked_node* lnode_p;
struct list{
int length;
lnode_p first;
lnode_p last;
void (*destructor)(void*);
};
typedef struct list * list_p;
struct list_iter{
lnode_p current;
char started;
};
typedef struct list_iter * list_iter_p;
/* Create a linked_list object. This pointer is created on the heap and must be
cleared with a call to destroy_list to avoid memory leaks */
list_p create_list();
/* Create a list_iter object for the linked_list list. The flag init can be
either FRONT or BACK and indicates whether to start the iterator from the first
or last item in the list */
list_iter_p list_iterator(list_p list, char init);
/* Add an item with the given value and size to the back of the list.
The data is copied by value, so the original pointer must be freed if it
was allocated on the heap. */
void list_add(list_p list, void* data, int size);
/* Gets the data stored in the first item of the list or NULL if the list is empty */
void* list_first(list_p list);
/* Gets the data stored in the last item of the list or NULL if the list is empty */
void* list_last(list_p list);
/* Removes the last item in the list (LIFO order) and returns the data stored
there. The data returned must be freed later in order to remain memory safe. */
void* list_pop(list_p list);
/* Removes the first item in the list (FIFO order) and returns the data stored
there. The data return must be freed later in order to remain memory safe. */
void* list_poll(list_p list);
/* Convenience function for completely destroying an item in the list. If the end
flag is FRONT, an item will be polled from the front of the list and its data
freed. If the end flag is set to BACK, an item will be popped off the end of
the list and the data freed. */
void list_remove(list_p list, char end);
/* Completely free the data associated with the list. */
void destroy_list(list_p list);
/* Return the data held by the current item pointed to by the iterator */
void* list_current(list_iter_p list);
/* Advances the iterator to the next item in the list and returns the data
stored there. */
void* list_next(list_iter_p list);
/* Advances the iterator to the previous item in the list and returns the data
stored there. */
void* list_prev(list_iter_p list);
#endif

Binary file not shown.