1 float Spawn_Send(entity to, float sf)
3 WriteByte(MSG_ENTITY, ENT_CLIENT_SPAWNPOINT);
4 WriteByte(MSG_ENTITY, self.team);
5 WriteShort(MSG_ENTITY, self.origin_x);
6 WriteShort(MSG_ENTITY, self.origin_y);
7 WriteShort(MSG_ENTITY, self.origin_z);
14 if(have_team_spawns > 0)
16 self.team = activator.team;
17 some_spawn_has_been_used = 1;
21 void relocate_spawnpoint()
23 // nudge off the floor
24 setorigin(self, self.origin + '0 0 1');
26 tracebox(self.origin, PL_MIN, PL_MAX, self.origin, TRUE, self);
33 if (!move_out_of_solid(self))
34 objerror("could not get out of solid at all!");
35 print("^1NOTE: this map needs FIXING. Spawnpoint at ", vtos(o - '0 0 1'));
36 print(" needs to be moved out of solid, e.g. by '", ftos(self.origin_x - o_x));
37 print(" ", ftos(self.origin_y - o_y));
38 print(" ", ftos(self.origin_z - o_z), "'\n");
39 if (autocvar_g_spawnpoints_auto_move_out_of_solid)
42 print("\{1}^1NOTE: this map needs FIXING (it contains spawnpoints in solid, see server log)\n");
48 self.mins = self.maxs = '0 0 0';
49 objerror("player spawn point in solid, mapper sucks!\n");
54 self.use = spawnpoint_use;
55 self.team_saved = self.team;
59 if (have_team_spawns != 0)
62 have_team_spawns_forteam[self.team] = 1;
64 if (autocvar_r_showbboxes)
66 // show where spawnpoints point at too
67 makevectors(self.angles);
70 e.classname = "info_player_foo";
71 setorigin(e, self.origin + v_forward * 24);
72 setsize(e, '-8 -8 -8', '8 8 8');
73 e.solid = SOLID_TRIGGER;
76 //self.think = Spawn_Send_Think;
77 //self.nextthink = time;
79 Net_LinkEntity(self, FALSE, 0, Spawn_Send);
82 void spawnfunc_info_player_survivor (void)
84 spawnfunc_info_player_deathmatch();
87 void spawnfunc_info_player_start (void)
89 spawnfunc_info_player_deathmatch();
92 void spawnfunc_info_player_deathmatch (void)
94 self.classname = "info_player_deathmatch";
95 relocate_spawnpoint();
99 // _x: prio (-1 if unusable)
101 vector Spawn_Score(entity spot, float mindist, float teamcheck)
103 float shortest, thisdist;
109 // filter out spots for the wrong team
111 if(spot.team != teamcheck)
115 if(spot.target == "")
118 if(clienttype(self) == CLIENTTYPE_REAL)
120 if(spot.restriction == 1)
125 if(spot.restriction == 2)
129 shortest = vlen(world.maxs - world.mins);
130 FOR_EACH_PLAYER(player) if (player != self)
132 thisdist = vlen(player.origin - spot.origin);
133 if (thisdist < shortest)
136 if(shortest > mindist)
137 prio += SPAWN_PRIO_GOOD_DISTANCE;
139 spawn_score = prio * '1 0 0' + shortest * '0 1 0';
142 // filter out spots for assault
143 if(spot.target != "") {
148 for(ent = world; (ent = find(ent, targetname, spot.target)); )
151 if(ent.spawn_evalfunc)
153 entity oldself = self;
155 spawn_score = ent.spawn_evalfunc(oldself, spot, spawn_score);
157 if(spawn_score_x < 0)
164 dprint("WARNING: spawnpoint at ", vtos(spot.origin), " could not find its target ", spot.target, "\n");
169 MUTATOR_CALLHOOK(Spawn_Score);
173 void Spawn_ScoreAll(entity firstspot, float mindist, float teamcheck)
176 for(spot = firstspot; spot; spot = spot.chain)
177 spot.spawnpoint_score = Spawn_Score(spot, mindist, teamcheck);
180 entity Spawn_FilterOutBadSpots(entity firstspot, float mindist, float teamcheck)
182 entity spot, spotlist, spotlistend;
187 Spawn_ScoreAll(firstspot, mindist, teamcheck);
189 for(spot = firstspot; spot; spot = spot.chain)
191 if(spot.spawnpoint_score_x >= 0) // spawning allowed here
194 spotlistend.chain = spot;
201 spotlistend.chain = world;
206 entity Spawn_WeightedPoint(entity firstspot, float lower, float upper, float exponent)
208 // weight of a point: bound(lower, mindisttoplayer, upper)^exponent
209 // multiplied by spot.cnt (useful if you distribute many spawnpoints in a small area)
212 RandomSelection_Init();
213 for(spot = firstspot; spot; spot = spot.chain)
214 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);
216 return RandomSelection_chosen_ent;
223 Finds a point to respawn
226 entity SelectSpawnPoint (float anypoint)
229 entity spot, firstspot;
231 spot = find (world, classname, "testplayerstart");
235 if(anypoint || autocvar_g_spawn_useallspawns)
237 else if(have_team_spawns > 0)
239 if(have_team_spawns_forteam[self.team] == 0)
241 // we request a spawn for a team, and we have team
242 // spawns, but that team has no spawns?
243 if(have_team_spawns_forteam[0])
247 // if not, any spawn has to do
251 teamcheck = self.team; // MUST be team
253 else if(have_team_spawns == 0 && have_team_spawns_forteam[0])
254 teamcheck = 0; // MUST be noteam
257 // 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
260 // get the entire list of spots
261 firstspot = findchain(classname, "info_player_deathmatch");
262 // filter out the bad ones
263 // (note this returns the original list if none survived)
266 spot = Spawn_WeightedPoint(firstspot, 1, 1, 1);
271 if (arena_roundbased && !g_ca)
275 firstspot = Spawn_FilterOutBadSpots(firstspot, mindist, teamcheck);
277 // there is 50/50 chance of choosing a random spot or the furthest spot
278 // (this means that roughly every other spawn will be furthest, so you
279 // usually won't get fragged at spawn twice in a row)
280 if (random() > autocvar_g_spawn_furthest)
281 spot = Spawn_WeightedPoint(firstspot, 1, 1, 1);
283 spot = Spawn_WeightedPoint(firstspot, 1, 5000, 5); // chooses a far far away spawnpoint
288 if(autocvar_spawn_debug)
292 if(some_spawn_has_been_used)
293 return world; // team can't spawn any more, because of actions of other team
295 error("Cannot find a spawn point - please fix the map!");