#include "g_local.h"
Include dependency graph for g_utils.c:

Go to the source code of this file.
Data Structures | |
| struct | shaderRemap_t |
Defines | |
| #define | MAX_SHADER_REMAPS 128 |
| #define | MAXCHOICES 32 |
Functions | |
| void | AddRemap (const char *oldShader, const char *newShader, float timeOffset) |
| const char * | BuildShaderStateConfig () |
| int | DebugLine (vec3_t start, vec3_t end, int color) |
| void | G_AddEvent (gentity_t *ent, int event, int eventParm) |
| void | G_AddPredictableEvent (gentity_t *ent, int event, int eventParm) |
| qboolean | G_EntitiesFree (void) |
| gentity_t * | G_Find (gentity_t *from, int fieldofs, const char *match) |
| int | G_FindConfigstringIndex (char *name, int start, int max, qboolean create) |
| void | G_FreeEntity (gentity_t *ed) |
| void | G_InitGentity (gentity_t *e) |
| void | G_KillBox (gentity_t *ent) |
| int | G_ModelIndex (char *name) |
| gentity_t * | G_PickTarget (char *targetname) |
| void | G_SetMovedir (vec3_t angles, vec3_t movedir) |
| void | G_SetOrigin (gentity_t *ent, vec3_t origin) |
| void | G_Sound (gentity_t *ent, int channel, int soundIndex) |
| int | G_SoundIndex (char *name) |
| gentity_t * | G_Spawn (void) |
| void | G_TeamCommand (team_t team, char *cmd) |
| gentity_t * | G_TempEntity (vec3_t origin, int event) |
| void | G_UseTargets (gentity_t *ent, gentity_t *activator) |
| float * | tv (float x, float y, float z) |
| float | vectoyaw (const vec3_t vec) |
| char * | vtos (const vec3_t v) |
Variables | |
| int | remapCount = 0 |
| shaderRemap_t | remappedShaders [MAX_SHADER_REMAPS] |
|
|
|
|
|
|
|
||||||||||||||||
|
Definition at line 38 of file g_utils.c. References i, Q_stricmp(), remapCount, remappedShaders, strcpy(), and shaderRemap_t::timeOffset. Referenced by G_RemapTeamShaders(), and G_UseTargets(). 00038 {
00039 int i;
00040
00041 for (i = 0; i < remapCount; i++) {
00042 if (Q_stricmp(oldShader, remappedShaders[i].oldShader) == 0) {
00043 // found it, just update this one
00044 strcpy(remappedShaders[i].newShader,newShader);
00045 remappedShaders[i].timeOffset = timeOffset;
00046 return;
00047 }
00048 }
00049 if (remapCount < MAX_SHADER_REMAPS) {
00050 strcpy(remappedShaders[remapCount].newShader,newShader);
00051 strcpy(remappedShaders[remapCount].oldShader,oldShader);
00052 remappedShaders[remapCount].timeOffset = timeOffset;
00053 remapCount++;
00054 }
00055 }
|
Here is the call graph for this function:

|
|
Definition at line 57 of file g_utils.c. References Com_sprintf(), i, MAX_QPATH, MAX_STRING_CHARS, memset(), Q_strcat(), and remappedShaders. Referenced by G_RemapTeamShaders(), and G_UseTargets(). 00057 {
00058 static char buff[MAX_STRING_CHARS*4];
00059 char out[(MAX_QPATH * 2) + 5];
00060 int i;
00061
00062 memset(buff, 0, MAX_STRING_CHARS);
00063 for (i = 0; i < remapCount; i++) {
00064 Com_sprintf(out, (MAX_QPATH * 2) + 5, "%s=%s:%5.2f@", remappedShaders[i].oldShader, remappedShaders[i].newShader, remappedShaders[i].timeOffset);
00065 Q_strcat( buff, sizeof( buff ), out);
00066 }
00067 return buff;
00068 }
|
Here is the call graph for this function:

|
||||||||||||||||
|
Definition at line 640 of file g_utils.c. References CrossProduct(), DotProduct, points, trap_DebugPolygonCreate(), up, vec3_t, VectorCopy, VectorMA, VectorNormalize(), VectorSet, and VectorSubtract. 00640 {
00641 vec3_t points[4], dir, cross, up = {0, 0, 1};
00642 float dot;
00643
00644 VectorCopy(start, points[0]);
00645 VectorCopy(start, points[1]);
00646 //points[1][2] -= 2;
00647 VectorCopy(end, points[2]);
00648 //points[2][2] -= 2;
00649 VectorCopy(end, points[3]);
00650
00651
00652 VectorSubtract(end, start, dir);
00653 VectorNormalize(dir);
00654 dot = DotProduct(dir, up);
00655 if (dot > 0.99 || dot < -0.99) VectorSet(cross, 1, 0, 0);
00656 else CrossProduct(dir, up, cross);
00657
00658 VectorNormalize(cross);
00659
00660 VectorMA(points[0], 2, cross, points[0]);
00661 VectorMA(points[1], -2, cross, points[1]);
00662 VectorMA(points[2], -2, cross, points[2]);
00663 VectorMA(points[3], 2, cross, points[3]);
00664
00665 return trap_DebugPolygonCreate(color, 4, points);
00666 }
|
Here is the call graph for this function:

|
||||||||||||||||
Here is the call graph for this function:

|
||||||||||||||||
|
Definition at line 559 of file g_utils.c. References BG_AddPredictableEventToPlayerstate(), gentity_s::client, gentity_t, and gclient_s::ps. Referenced by Touch_Item(). 00559 {
00560 if ( !ent->client ) {
00561 return;
00562 }
00563 BG_AddPredictableEventToPlayerstate( event, eventParm, &ent->client->ps );
00564 }
|
Here is the call graph for this function:

|
|
Definition at line 441 of file g_utils.c. References e, g_entities, gentity_t, i, gentity_s::inuse, level, level_locals_t::num_entities, and qboolean. 00441 {
00442 int i;
00443 gentity_t *e;
00444
00445 e = &g_entities[MAX_CLIENTS];
00446 for ( i = MAX_CLIENTS; i < level.num_entities; i++, e++) {
00447 if ( e->inuse ) {
00448 continue;
00449 }
00450 // slot available
00451 return qtrue;
00452 }
00453 return qfalse;
00454 }
|
|
||||||||||||||||
|
Definition at line 159 of file g_utils.c. References byte, g_entities, gentity_t, gentity_s::inuse, level, match(), level_locals_t::num_entities, Q_stricmp(), and s. Referenced by CheckAlmostCapture(), CheckAlmostScored(), FindIntermissionPoint(), G_CheckTeamItems(), G_PickTarget(), G_UseTargets(), SelectInitialSpawnPoint(), SelectNearestDeathmatchSpawnPoint(), SelectRandomDeathmatchSpawnPoint(), SelectRandomFurthestSpawnPoint(), SelectRandomTeamSpawnPoint(), target_laser_start(), Team_FragBonuses(), Team_ResetFlag(), Think_SetupTrainTargets(), and Use_Target_Give(). 00160 {
00161 char *s;
00162
00163 if (!from)
00164 from = g_entities;
00165 else
00166 from++;
00167
00168 for ( ; from < &g_entities[level.num_entities] ; from++)
00169 {
00170 if (!from->inuse)
00171 continue;
00172 s = *(char **) ((byte *)from + fieldofs);
00173 if (!s)
00174 continue;
00175 if (!Q_stricmp (s, match))
00176 return from;
00177 }
00178
00179 return NULL;
00180 }
|
Here is the call graph for this function:

|
||||||||||||||||||||
|
Definition at line 84 of file g_utils.c. References G_Error(), i, name, s, strcmp(), trap_GetConfigstring(), and trap_SetConfigstring(). Referenced by G_ModelIndex(), and G_SoundIndex(). 00084 {
00085 int i;
00086 char s[MAX_STRING_CHARS];
00087
00088 if ( !name || !name[0] ) {
00089 return 0;
00090 }
00091
00092 for ( i=1 ; i<max ; i++ ) {
00093 trap_GetConfigstring( start + i, s, sizeof( s ) );
00094 if ( !s[0] ) {
00095 break;
00096 }
00097 if ( !strcmp( s, name ) ) {
00098 return i;
00099 }
00100 }
00101
00102 if ( !create ) {
00103 return 0;
00104 }
00105
00106 if ( i == max ) {
00107 G_Error( "G_FindConfigstringIndex: overflow" );
00108 }
00109
00110 trap_SetConfigstring( start + i, name );
00111
00112 return i;
00113 }
|
Here is the call graph for this function:

|
|
Definition at line 464 of file g_utils.c. References gentity_s::classname, gentity_s::freetime, gentity_t, level, memset(), gentity_s::neverFree, level_locals_t::time, and trap_UnlinkEntity(). Referenced by AimAtTarget(), Blocked_Door(), Cmd_Give_f(), FinishSpawningItem(), G_MoverPush(), G_RunFrame(), G_RunItem(), G_RunMissile(), G_SpawnGEntityFromSpawnVars(), GibEntity(), locateCamera(), Pickup_Team(), SP_func_train(), SP_info_null(), SP_light(), SP_misc_model(), SP_path_corner(), Team_ResetFlag(), trigger_always_think(), and Weapon_HookFree(). 00464 {
00465 trap_UnlinkEntity (ed); // unlink from world
00466
00467 if ( ed->neverFree ) {
00468 return;
00469 }
00470
00471 memset (ed, 0, sizeof(*ed));
00472 ed->classname = "freed";
00473 ed->freetime = level.time;
00474 ed->inuse = qfalse;
00475 }
|
Here is the call graph for this function:

|
|
Definition at line 367 of file g_utils.c. References gentity_s::classname, e, gentity_t, gentity_s::inuse, entityState_s::number, entityShared_t::ownerNum, gentity_s::r, and gentity_s::s. Referenced by ClientBegin(), and G_Spawn(). 00367 {
00368 e->inuse = qtrue;
00369 e->classname = "noclass";
00370 e->s.number = e - g_entities;
00371 e->r.ownerNum = ENTITYNUM_NONE;
00372 }
|
|
|
Definition at line 525 of file g_utils.c. References gentity_s::client, DAMAGE_NO_PROTECTION, G_Damage(), g_entities, gentity_t, i, MAX_GENTITIES, entityShared_t::maxs, entityShared_t::mins, MOD_TELEFRAG, NULL, playerState_s::origin, gclient_s::ps, gentity_s::r, trap_EntitiesInBox(), vec3_t, and VectorAdd. Referenced by ClientSpawn(), and TeleportPlayer(). 00525 {
00526 int i, num;
00527 int touch[MAX_GENTITIES];
00528 gentity_t *hit;
00529 vec3_t mins, maxs;
00530
00531 VectorAdd( ent->client->ps.origin, ent->r.mins, mins );
00532 VectorAdd( ent->client->ps.origin, ent->r.maxs, maxs );
00533 num = trap_EntitiesInBox( mins, maxs, touch, MAX_GENTITIES );
00534
00535 for (i=0 ; i<num ; i++) {
00536 hit = &g_entities[touch[i]];
00537 if ( !hit->client ) {
00538 continue;
00539 }
00540
00541 // nail it
00542 G_Damage ( hit, ent, ent, NULL, NULL,
00543 100000, DAMAGE_NO_PROTECTION, MOD_TELEFRAG);
00544 }
00545
00546 }
|
Here is the call graph for this function:

|
|
Definition at line 116 of file g_utils.c. References CS_MODELS, G_FindConfigstringIndex(), MAX_MODELS, name, and qtrue. Referenced by BotSetEntityNumForGoalWithModel(), G_InitGame(), InitMover(), SP_misc_model(), and SpawnPodium(). 00116 {
00117 return G_FindConfigstringIndex (name, CS_MODELS, MAX_MODELS, qtrue);
00118 }
|
Here is the call graph for this function:

|
|
Definition at line 192 of file g_utils.c. References FOFS, G_Find(), G_Printf(), gentity_t, and rand(). Referenced by AimAtTarget(), FindIntermissionPoint(), InitShooter_Finish(), locateCamera(), target_relay_use(), target_teleporter_use(), and trigger_teleporter_touch(). 00193 {
00194 gentity_t *ent = NULL;
00195 int num_choices = 0;
00196 gentity_t *choice[MAXCHOICES];
00197
00198 if (!targetname)
00199 {
00200 G_Printf("G_PickTarget called with NULL targetname\n");
00201 return NULL;
00202 }
00203
00204 while(1)
00205 {
00206 ent = G_Find (ent, FOFS(targetname), targetname);
00207 if (!ent)
00208 break;
00209 choice[num_choices++] = ent;
00210 if (num_choices == MAXCHOICES)
00211 break;
00212 }
00213
00214 if (!num_choices)
00215 {
00216 G_Printf("G_PickTarget: target %s not found\n", targetname);
00217 return NULL;
00218 }
00219
00220 return choice[rand() % num_choices];
00221 }
|
Here is the call graph for this function:

|
||||||||||||
|
Definition at line 328 of file g_utils.c. References AngleVectors(), NULL, vec3_t, VectorClear, VectorCompare(), and VectorCopy. Referenced by InitShooter(), InitTrigger(), locateCamera(), SP_func_button(), SP_func_door(), SP_target_push(), and target_laser_start(). 00328 {
00329 static vec3_t VEC_UP = {0, -1, 0};
00330 static vec3_t MOVEDIR_UP = {0, 0, 1};
00331 static vec3_t VEC_DOWN = {0, -2, 0};
00332 static vec3_t MOVEDIR_DOWN = {0, 0, -1};
00333
00334 if ( VectorCompare (angles, VEC_UP) ) {
00335 VectorCopy (MOVEDIR_UP, movedir);
00336 } else if ( VectorCompare (angles, VEC_DOWN) ) {
00337 VectorCopy (MOVEDIR_DOWN, movedir);
00338 } else {
00339 AngleVectors (angles, movedir, NULL, NULL);
00340 }
00341 VectorClear( angles );
00342 }
|
Here is the call graph for this function:

|
||||||||||||
|
Definition at line 622 of file g_utils.c. References entityShared_t::currentOrigin, gentity_t, entityState_s::pos, gentity_s::r, gentity_s::s, trajectory_t::trBase, trajectory_t::trDelta, trajectory_t::trDuration, trajectory_t::trTime, trajectory_t::trType, VectorClear, and VectorCopy. Referenced by ClientSpawn(), FinishSpawningItem(), G_BounceItem(), G_BounceMissile(), G_ExplodeMissile(), G_MissileImpact(), G_TempEntity(), LaunchItem(), PodiumPlacementThink(), SP_info_camp(), SP_info_notnull(), SP_misc_model(), SP_target_location(), SP_target_position(), SpawnModelOnVictoryPad(), SpawnPodium(), and Weapon_HookThink(). 00622 {
00623 VectorCopy( origin, ent->s.pos.trBase );
00624 ent->s.pos.trType = TR_STATIONARY;
00625 ent->s.pos.trTime = 0;
00626 ent->s.pos.trDuration = 0;
00627 VectorClear( ent->s.pos.trDelta );
00628
00629 VectorCopy( origin, ent->r.currentOrigin );
00630 }
|
|
||||||||||||||||
|
Definition at line 604 of file g_utils.c. References entityShared_t::currentOrigin, EV_GENERAL_SOUND, entityState_s::eventParm, G_TempEntity(), gentity_t, gentity_s::r, and gentity_s::s. Referenced by hurt_touch(), P_WorldEffects(), and Use_target_push(). 00604 {
00605 gentity_t *te;
00606
00607 te = G_TempEntity( ent->r.currentOrigin, EV_GENERAL_SOUND );
00608 te->s.eventParm = soundIndex;
00609 }
|
Here is the call graph for this function:

|
|
Definition at line 120 of file g_utils.c. References CS_SOUNDS, G_FindConfigstringIndex(), MAX_SOUNDS, name, and qtrue. Referenced by G_InitGame(), G_SetClientSound(), G_SpawnItem(), InitMover(), P_WorldEffects(), RespawnItem(), SP_func_button(), SP_func_door(), SP_func_plat(), SP_target_push(), SP_target_speaker(), SP_trigger_hurt(), SP_trigger_push(), and SP_trigger_teleport(). 00120 {
00121 return G_FindConfigstringIndex (name, CS_SOUNDS, MAX_SOUNDS, qtrue);
00122 }
|
Here is the call graph for this function:

|
|
Definition at line 389 of file g_utils.c. References level_locals_t::clients, e, gentity_s::freetime, g_entities, G_Error(), G_InitGentity(), G_Printf(), level_locals_t::gentities, gentity_t, i, gentity_s::inuse, level, level_locals_t::num_entities, gclient_s::ps, level_locals_t::startTime, level_locals_t::time, and trap_LocateGameData(). Referenced by Cmd_Give_f(), fire_bfg(), fire_grapple(), fire_grenade(), fire_plasma(), fire_rocket(), G_MissileImpact(), G_SpawnGEntityFromSpawnVars(), G_TempEntity(), InitBodyQue(), LaunchItem(), SpawnModelOnVictoryPad(), SpawnPlatTrigger(), SpawnPodium(), and Think_SpawnNewDoorTrigger(). 00389 {
00390 int i, force;
00391 gentity_t *e;
00392
00393 e = NULL; // shut up warning
00394 i = 0; // shut up warning
00395 for ( force = 0 ; force < 2 ; force++ ) {
00396 // if we go through all entities and can't find one to free,
00397 // override the normal minimum times before use
00398 e = &g_entities[MAX_CLIENTS];
00399 for ( i = MAX_CLIENTS ; i<level.num_entities ; i++, e++) {
00400 if ( e->inuse ) {
00401 continue;
00402 }
00403
00404 // the first couple seconds of server time can involve a lot of
00405 // freeing and allocating, so relax the replacement policy
00406 if ( !force && e->freetime > level.startTime + 2000 && level.time - e->freetime < 1000 ) {
00407 continue;
00408 }
00409
00410 // reuse this slot
00411 G_InitGentity( e );
00412 return e;
00413 }
00414 if ( i != MAX_GENTITIES ) {
00415 break;
00416 }
00417 }
00418 if ( i == ENTITYNUM_MAX_NORMAL ) {
00419 for (i = 0; i < MAX_GENTITIES; i++) {
00420 G_Printf("%4i: %s\n", i, g_entities[i].classname);
00421 }
00422 G_Error( "G_Spawn: no free entities" );
00423 }
00424
00425 // open up a new slot
00426 level.num_entities++;
00427
00428 // let the server system know that there are more entities
00429 trap_LocateGameData( level.gentities, level.num_entities, sizeof( gentity_t ),
00430 &level.clients[0].ps, sizeof( level.clients[0] ) );
00431
00432 G_InitGentity( e );
00433 return e;
00434 }
|
Here is the call graph for this function:

|
||||||||||||
|
Definition at line 134 of file g_utils.c. References level_locals_t::clients, clientPersistant_t::connected, i, level, level_locals_t::maxclients, gclient_s::pers, gclient_s::sess, clientSession_t::sessionTeam, trap_SendServerCommand(), and va(). Referenced by Use_Target_Print(). 00134 {
00135 int i;
00136
00137 for ( i = 0 ; i < level.maxclients ; i++ ) {
00138 if ( level.clients[i].pers.connected == CON_CONNECTED ) {
00139 if ( level.clients[i].sess.sessionTeam == team ) {
00140 trap_SendServerCommand( i, va("%s", cmd ));
00141 }
00142 }
00143 }
00144 }
|
Here is the call graph for this function:

|
||||||||||||
Here is the call graph for this function:

|
||||||||||||
|
Definition at line 235 of file g_utils.c. References AddRemap(), BuildShaderStateConfig(), CS_SHADERSTATE, f, FOFS, G_Find(), G_Printf(), gentity_t, gentity_s::inuse, level, t, gentity_s::target, gentity_s::targetShaderName, gentity_s::targetShaderNewName, level_locals_t::time, trap_SetConfigstring(), and gentity_s::use. Referenced by ClientSpawn(), func_timer_think(), multi_trigger(), Reached_BinaryMover(), Reached_Train(), target_relay_use(), Think_Target_Delay(), Touch_Item(), and trigger_always_think(). 00235 {
00236 gentity_t *t;
00237
00238 if ( !ent ) {
00239 return;
00240 }
00241
00242 if (ent->targetShaderName && ent->targetShaderNewName) {
00243 float f = level.time * 0.001;
00244 AddRemap(ent->targetShaderName, ent->targetShaderNewName, f);
00245 trap_SetConfigstring(CS_SHADERSTATE, BuildShaderStateConfig());
00246 }
00247
00248 if ( !ent->target ) {
00249 return;
00250 }
00251
00252 t = NULL;
00253 while ( (t = G_Find (t, FOFS(targetname), ent->target)) != NULL ) {
00254 if ( t == ent ) {
00255 G_Printf ("WARNING: Entity used itself.\n");
00256 } else {
00257 if ( t->use ) {
00258 t->use (t, ent, activator);
00259 }
00260 }
00261 if ( !ent->inuse ) {
00262 G_Printf("entity was removed while using targets\n");
00263 return;
00264 }
00265 }
00266 }
|
Here is the call graph for this function:

|
||||||||||||||||
|
Definition at line 277 of file g_utils.c. References v, vec3_t, and vecs. Referenced by Face_TextureVectors(), QuakeTextureVecs(), TexinfoForBrushTexture(), and WriteMapBrush(). 00277 {
00278 static int index;
00279 static vec3_t vecs[8];
00280 float *v;
00281
00282 // use an array so that multiple tempvectors won't collide
00283 // for a while
00284 v = vecs[index];
00285 index = (index + 1)&7;
00286
00287 v[0] = x;
00288 v[1] = y;
00289 v[2] = z;
00290
00291 return v;
00292 }
|
|
|
Definition at line 345 of file g_utils.c. References atan2(), PITCH, and YAW. Referenced by LookAtKiller(), and SpawnPodium(). 00345 {
00346 float yaw;
00347
00348 if (vec[YAW] == 0 && vec[PITCH] == 0) {
00349 yaw = 0;
00350 } else {
00351 if (vec[PITCH]) {
00352 yaw = ( atan2( vec[YAW], vec[PITCH]) * 180 / M_PI );
00353 } else if (vec[YAW] > 0) {
00354 yaw = 90;
00355 } else {
00356 yaw = 270;
00357 }
00358 if (yaw < 0) {
00359 yaw += 360;
00360 }
00361 }
00362
00363 return yaw;
00364 }
|
Here is the call graph for this function:

|
|
Definition at line 303 of file g_utils.c. References Com_sprintf(), s, and v. Referenced by Cmd_Where_f(), FinishSpawningItem(), SP_func_timer(), SP_func_train(), SP_path_corner(), SP_target_speaker(), SP_target_teleporter(), target_laser_start(), and Think_SetupTrainTargets(). 00303 {
00304 static int index;
00305 static char str[8][32];
00306 char *s;
00307
00308 // use an array so that multiple vtos won't collide
00309 s = str[index];
00310 index = (index + 1)&7;
00311
00312 Com_sprintf (s, 32, "(%i %i %i)", (int)v[0], (int)v[1], (int)v[2]);
00313
00314 return s;
00315 }
|
Here is the call graph for this function:

|