//"Entity @GT_SelectSpawnPoint( Entity @ent )" edict_t *GT_asCallSelectSpawnPoint( edict_t *ent ) { int error; asIScriptContext *ctx; edict_t *spot; if( !level.gametype.selectSpawnPointFunc ) return SelectDeathmatchSpawnPoint( ent ); // should have a hardcoded backup ctx = angelExport->asAcquireContext( GAME_AS_ENGINE() ); error = ctx->Prepare( static_cast<asIScriptFunction *>(level.gametype.selectSpawnPointFunc) ); if( error < 0 ) return SelectDeathmatchSpawnPoint( ent ); // Now we need to pass the parameters to the script function. ctx->SetArgObject( 0, ent ); error = ctx->Execute(); if( G_ExecutionErrorReport( error ) ) GT_asShutdownScript(); spot = ( edict_t * )ctx->GetReturnObject(); if( !spot ) spot = SelectDeathmatchSpawnPoint( ent ); return spot; }
/* =========== SelectSpawnPoint Chooses a player start, deathmatch start, coop start, etc ============ */ void SelectSpawnPoint(edict_t *ent, vec3_t origin, vec3_t angles){ edict_t *spot = NULL; if(deathmatch->value) spot = SelectDeathmatchSpawnPoint(); else if(coop->value) spot = SelectCoopSpawnPoint(ent); // find a single player start spot if(!spot){ while((spot = G_Find(spot, FOFS(classname), "info_player_start")) != NULL){ if(!game.spawnpoint[0] && !spot->targetname) break; if(!game.spawnpoint[0] || !spot->targetname) continue; if(Q_stricmp(game.spawnpoint, spot->targetname) == 0) break; } if(!spot){ if(!game.spawnpoint[0]){ // there wasn't a spawnpoint without a target, so use any spot = G_Find(spot, FOFS(classname), "info_player_start"); } if(!spot) gi.error("Couldn't find spawn point %s\n", game.spawnpoint); } } VectorCopy(spot->s.origin, origin); origin[2] += 9; VectorCopy(spot->s.angles, angles); }
/* * SelectSpawnPoint * * Chooses a player start, deathmatch start, etc */ void SelectSpawnPoint( edict_t *ent, edict_t **spawnpoint, vec3_t origin, vec3_t angles ) { edict_t *spot = NULL; if( GS_MatchState() >= MATCH_STATE_POSTMATCH ) { spot = G_SelectIntermissionSpawnPoint(); } else { if( game.asEngine != NULL ) spot = GT_asCallSelectSpawnPoint( ent ); if( !spot ) spot = SelectDeathmatchSpawnPoint( ent ); } // find a single player start spot if( !spot ) { spot = G_Find( spot, FOFS( classname ), "info_player_start" ); if( !spot ) { spot = G_Find( spot, FOFS( classname ), "team_CTF_alphaspawn" ); if( !spot ) spot = G_Find( spot, FOFS( classname ), "team_CTF_betaspawn" ); if( !spot ) spot = world; } } *spawnpoint = spot; VectorCopy( spot->s.origin, origin ); VectorCopy( spot->s.angles, angles ); if( !Q_stricmp( spot->classname, "info_player_intermission" ) ) { // if it has a target, look towards it if( spot->target ) { vec3_t dir; edict_t *target; target = G_PickTarget( spot->target ); if( target ) { VectorSubtract( target->s.origin, origin, dir ); VecToAngles( dir, angles ); } } } // SPAWN TELEFRAGGING PROTECTION. if( ent->r.solid == SOLID_YES && ( level.gametype.spawnpointRadius > ( playerbox_stand_maxs[0] - playerbox_stand_mins[0] ) ) ) G_OffsetSpawnPoint( origin, playerbox_stand_mins, playerbox_stand_maxs, level.gametype.spawnpointRadius, !( spot->spawnflags & 1 ) ? true : false ); }
edict_t* TBI_FindSpawn(edict_t *ent) { edict_t *potential_spot; int iter = 0; if (!ent) return NULL; if (!ent->client || !ent->inuse) return NULL; if (G_IsSpectator(ent)) { return SelectDeathmatchSpawnPoint(ent); } if (!ent->teamnum) { TBI_AssignTeam(ent); } if (ent->spawn) { edict_t* spawn = ent->spawn; ent->spawn = NULL; return spawn; } potential_spot = TBI_FindRandomSpawnForTeam(ent->teamnum); while (potential_spot->deadflag == DEAD_DEAD && iter != 256) { iter++; // don't let it drift off for too long potential_spot = TBI_FindRandomSpawnForTeam(ent->teamnum); } if (potential_spot->deadflag == DEAD_DEAD) // so didn't find an alive spot? return SelectDeathmatchSpawnPoint(ent) ; // find a random one return potential_spot; }
/* * Chooses a player start, deathmatch start, coop start, etc */ void SelectSpawnPoint(edict_t *ent, vec3_t origin, vec3_t angles) { edict_t *spot = NULL; edict_t *coopspot = NULL; int index; int counter = 0; vec3_t d; if (!ent) { return; } if (deathmatch->value) { spot = SelectDeathmatchSpawnPoint(); } else if (coop->value) { spot = SelectCoopSpawnPoint(ent); } /* find a single player start spot */ if (!spot) { while ((spot = G_Find(spot, FOFS(classname), "info_player_start")) != NULL) { if (!game.spawnpoint[0] && !spot->targetname) { break; } if (!game.spawnpoint[0] || !spot->targetname) { continue; } if (Q_stricmp(game.spawnpoint, spot->targetname) == 0) { break; } } if (!spot) { if (!game.spawnpoint[0]) { /* there wasn't a spawnpoint without a target, so use any */ spot = G_Find(spot, FOFS(classname), "info_player_start"); } if (!spot) { gi.error("Couldn't find spawn point %s\n", game.spawnpoint); } } } /* If we are in coop and we didn't find a coop spawnpoint due to map bugs (not correctly connected or the map was loaded via console and thus no previously map is known to the client) use one in 550 units radius. */ if (coop->value) { index = ent->client - game.clients; if (Q_stricmp(spot->classname, "info_player_start") == 0 && index != 0) { while(counter < 3) { coopspot = G_Find(coopspot, FOFS(classname), "info_player_coop"); if (!coopspot) { break; } VectorSubtract(coopspot->s.origin, spot->s.origin, d); if ((VectorLength(d) < 550)) { if (index == counter) { spot = coopspot; break; } else { counter++; } } } } } VectorCopy(spot->s.origin, origin); origin[2] += 9; VectorCopy(spot->s.angles, angles); }