g_edicts.c
Go to the documentation of this file.00001
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029 #include "g_local.h"
00030
00032 static edict_t *g_edicts;
00033
00038 edict_t* G_EdictsInit (void)
00039 {
00040 g_edicts = (edict_t *)G_TagMalloc(game.sv_maxentities * sizeof(g_edicts[0]), TAG_GAME);
00041 return g_edicts;
00042 }
00043
00047 void G_EdictsReset (void)
00048 {
00049 memset(g_edicts, 0, game.sv_maxentities * sizeof(g_edicts[0]));
00050 }
00051
00058 int G_EdictsGetNumber (const edict_t* ent)
00059 {
00060 int idx = ent - g_edicts;
00061 assert(idx >= 0 && idx < globals.num_edicts);
00062 return idx;
00063 }
00064
00070 qboolean G_EdictsIsValidNum (const int num)
00071 {
00072 if (num >= 0 && num < globals.num_edicts)
00073 return qtrue;
00074 return qfalse;
00075 }
00076
00081 edict_t* G_EdictsGetByNum (const int num)
00082 {
00083 if (!G_EdictsIsValidNum(num)) {
00084 gi.DPrintf("Invalid edict num %i\n", num);
00085 return NULL;
00086 }
00087
00088 return g_edicts + num;
00089 }
00090
00096 edict_t* G_EdictsGetFirst (void)
00097 {
00098 return &g_edicts[0];
00099 }
00100
00105 edict_t* G_EdictsGetNext (edict_t* lastEnt)
00106 {
00107 edict_t* endOfEnts = &g_edicts[globals.num_edicts];
00108 edict_t* ent;
00109
00110 if (!globals.num_edicts)
00111 return NULL;
00112
00113 if (!lastEnt)
00114 return g_edicts;
00115 assert(lastEnt >= g_edicts);
00116 assert(lastEnt < endOfEnts);
00117
00118 ent = lastEnt;
00119
00120 ent++;
00121 if (ent >= endOfEnts)
00122 return NULL;
00123 else
00124 return ent;
00125 }
00126
00130 edict_t* G_EdictsGetNewEdict (void)
00131 {
00132 edict_t* ent = NULL;
00133
00134
00135 while ((ent = G_EdictsGetNext(ent))) {
00136 if (!ent->inuse)
00137 return ent;
00138 }
00139
00140
00141 ent = &g_edicts[globals.num_edicts];
00142 globals.num_edicts++;
00143 if (globals.num_edicts > game.sv_maxentities)
00144 return NULL;
00145 else
00146 return ent;
00147 }
00148
00155 edict_t* G_EdictsGetNextInUse (edict_t* lastEnt)
00156 {
00157 edict_t* ent = lastEnt;
00158
00159 while ((ent = G_EdictsGetNext(ent))) {
00160 if (ent->inuse)
00161 break;
00162 }
00163 return ent;
00164 }
00165
00170 edict_t* G_EdictsGetNextLivingActor (edict_t* lastEnt)
00171 {
00172 edict_t* ent = lastEnt;
00173
00174 while ((ent = G_EdictsGetNextInUse(ent))) {
00175 if (G_IsLivingActor(ent))
00176 break;
00177 }
00178 return ent;
00179 }
00180
00186 edict_t* G_EdictsGetNextLivingActorOfTeam (edict_t* lastEnt, const int team)
00187 {
00188 edict_t* ent = lastEnt;
00189
00190 while ((ent = G_EdictsGetNextLivingActor(ent))) {
00191 if (ent->team == team)
00192 break;
00193 }
00194 return ent;
00195 }
00196
00201 edict_t* G_EdictsGetNextActor (edict_t* lastEnt)
00202 {
00203 edict_t* ent = lastEnt;
00204
00205 assert(lastEnt < &g_edicts[globals.num_edicts]);
00206
00207 while ((ent = G_EdictsGetNextInUse(ent))) {
00208 if (G_IsActor(ent))
00209 break;
00210 }
00211 return ent;
00212 }
00213
00218 void G_EdictCalcOrigin (edict_t* ent)
00219 {
00220 gi.GridPosToVec(gi.routingMap, ent->fieldSize, ent->pos, ent->origin);
00221 }
00222
00228 void G_EdictSetOrigin (edict_t* ent, const pos3_t newPos)
00229 {
00230 VectorCopy(newPos, ent->pos);
00231 gi.GridPosToVec(gi.routingMap, ent->fieldSize, ent->pos, ent->origin);
00232 }
00233
00240 qboolean G_EdictPosIsSameAs (edict_t* ent, const pos3_t cmpPos)
00241 {
00242 return VectorCompare(cmpPos, ent->pos);
00243 }