4 if(have_team_spawns > 0)
6 self.team = activator.team;
7 some_spawn_has_been_used = 1;
11 void relocate_spawnpoint()
13 // nudge off the floor
14 setorigin(self, self.origin + '0 0 1');
16 tracebox(self.origin, PL_MIN, PL_MAX, self.origin, TRUE, self);
23 if (!move_out_of_solid(self))
24 objerror("could not get out of solid at all!");
25 print("^1NOTE: this map needs FIXING. Spawnpoint at ", vtos(o - '0 0 1'));
26 print(" needs to be moved out of solid, e.g. by '", ftos(self.origin_x - o_x));
27 print(" ", ftos(self.origin_y - o_y));
28 print(" ", ftos(self.origin_z - o_z), "'\n");
29 if (autocvar_g_spawnpoints_auto_move_out_of_solid)
32 print("\{1}^1NOTE: this map needs FIXING (it contains spawnpoints in solid, see server log)\n");
38 self.mins = self.maxs = '0 0 0';
39 objerror("player spawn point in solid, mapper sucks!\n");
44 self.use = spawnpoint_use;
45 self.team_saved = self.team;
49 if (have_team_spawns != 0)
52 have_team_spawns_forteam[self.team] = 1;
54 if (autocvar_r_showbboxes)
56 // show where spawnpoints point at too
57 makevectors(self.angles);
60 e.classname = "info_player_foo";
61 setorigin(e, self.origin + v_forward * 24);
62 setsize(e, '-8 -8 -8', '8 8 8');
63 e.solid = SOLID_TRIGGER;
66 //Net_LinkEntity(self, FALSE, 0, ItemSend);
69 void spawnfunc_info_player_survivor (void)
71 spawnfunc_info_player_deathmatch();
74 void spawnfunc_info_player_start (void)
76 spawnfunc_info_player_deathmatch();
79 void spawnfunc_info_player_deathmatch (void)
81 self.classname = "info_player_deathmatch";
82 relocate_spawnpoint();
86 // _x: prio (-1 if unusable)
88 vector Spawn_Score(entity spot, float mindist, float teamcheck)
90 float shortest, thisdist;
96 // filter out spots for the wrong team
98 if(spot.team != teamcheck)
102 if(spot.target == "")
105 if(clienttype(self) == CLIENTTYPE_REAL)
107 if(spot.restriction == 1)
112 if(spot.restriction == 2)
116 shortest = vlen(world.maxs - world.mins);
117 FOR_EACH_PLAYER(player) if (player != self)
119 thisdist = vlen(player.origin - spot.origin);
120 if (thisdist < shortest)
123 if(shortest > mindist)
124 prio += SPAWN_PRIO_GOOD_DISTANCE;
126 spawn_score = prio * '1 0 0' + shortest * '0 1 0';
129 // filter out spots for assault
130 if(spot.target != "") {
135 for(ent = world; (ent = find(ent, targetname, spot.target)); )
138 if(ent.spawn_evalfunc)
140 entity oldself = self;
142 spawn_score = ent.spawn_evalfunc(oldself, spot, spawn_score);
144 if(spawn_score_x < 0)
151 dprint("WARNING: spawnpoint at ", vtos(spot.origin), " could not find its target ", spot.target, "\n");
156 MUTATOR_CALLHOOK(Spawn_Score);
160 void Spawn_ScoreAll(entity firstspot, float mindist, float teamcheck)
163 for(spot = firstspot; spot; spot = spot.chain)
164 spot.spawnpoint_score = Spawn_Score(spot, mindist, teamcheck);
167 entity Spawn_FilterOutBadSpots(entity firstspot, float mindist, float teamcheck)
169 entity spot, spotlist, spotlistend;
174 Spawn_ScoreAll(firstspot, mindist, teamcheck);
176 for(spot = firstspot; spot; spot = spot.chain)
178 if(spot.spawnpoint_score_x >= 0) // spawning allowed here
181 spotlistend.chain = spot;
188 spotlistend.chain = world;
193 entity Spawn_WeightedPoint(entity firstspot, float lower, float upper, float exponent)
195 // weight of a point: bound(lower, mindisttoplayer, upper)^exponent
196 // multiplied by spot.cnt (useful if you distribute many spawnpoints in a small area)
199 RandomSelection_Init();
200 for(spot = firstspot; spot; spot = spot.chain)
201 RandomSelection_Add(spot, 0, string_null, pow(bound(lower, spot.spawnpoint_score_y, upper), exponent) * spot.cnt, (spot.spawnpoint_score_y >= lower) * 0.5 + spot.spawnpoint_score_x);
203 return RandomSelection_chosen_ent;
210 Finds a point to respawn
213 entity SelectSpawnPoint (float anypoint)
216 entity spot, firstspot;
218 spot = find (world, classname, "testplayerstart");
222 if(anypoint || autocvar_g_spawn_useallspawns)
224 else if(have_team_spawns > 0)
226 if(have_team_spawns_forteam[self.team] == 0)
228 // we request a spawn for a team, and we have team
229 // spawns, but that team has no spawns?
230 if(have_team_spawns_forteam[0])
234 // if not, any spawn has to do
238 teamcheck = self.team; // MUST be team
240 else if(have_team_spawns == 0 && have_team_spawns_forteam[0])
241 teamcheck = 0; // MUST be noteam
244 // if we get here, we either require team spawns but have none, or we require non-team spawns and have none; use any spawn then
247 // get the entire list of spots
248 firstspot = findchain(classname, "info_player_deathmatch");
249 // filter out the bad ones
250 // (note this returns the original list if none survived)
253 spot = Spawn_WeightedPoint(firstspot, 1, 1, 1);
258 if (arena_roundbased && !g_ca)
262 firstspot = Spawn_FilterOutBadSpots(firstspot, mindist, teamcheck);
264 // there is 50/50 chance of choosing a random spot or the furthest spot
265 // (this means that roughly every other spawn will be furthest, so you
266 // usually won't get fragged at spawn twice in a row)
267 if (random() > autocvar_g_spawn_furthest)
268 spot = Spawn_WeightedPoint(firstspot, 1, 1, 1);
270 spot = Spawn_WeightedPoint(firstspot, 1, 5000, 5); // chooses a far far away spawnpoint
275 if(autocvar_spawn_debug)
279 if(some_spawn_has_been_used)
280 return world; // team can't spawn any more, because of actions of other team
282 error("Cannot find a spawn point - please fix the map!");