1 float Spawn_Send(entity to, float sf)
3 WriteByte(MSG_ENTITY, ENT_CLIENT_SPAWNPOINT);
4 WriteByte(MSG_ENTITY, sf);
8 WriteByte(MSG_ENTITY, self.team);
9 WriteShort(MSG_ENTITY, self.origin_x);
10 WriteShort(MSG_ENTITY, self.origin_y);
11 WriteShort(MSG_ENTITY, self.origin_z);
15 WriteLong(MSG_ENTITY, self.last_spawn_time);
24 if(have_team_spawns > 0)
26 self.team = activator.team;
27 some_spawn_has_been_used = 1;
29 print("spawnpoint was used!\n");
30 self.last_spawn_time = time;
34 void relocate_spawnpoint()
36 // nudge off the floor
37 setorigin(self, self.origin + '0 0 1');
39 tracebox(self.origin, PL_MIN, PL_MAX, self.origin, TRUE, self);
46 if (!move_out_of_solid(self))
47 objerror("could not get out of solid at all!");
48 print("^1NOTE: this map needs FIXING. Spawnpoint at ", vtos(o - '0 0 1'));
49 print(" needs to be moved out of solid, e.g. by '", ftos(self.origin_x - o_x));
50 print(" ", ftos(self.origin_y - o_y));
51 print(" ", ftos(self.origin_z - o_z), "'\n");
52 if (autocvar_g_spawnpoints_auto_move_out_of_solid)
55 print("\{1}^1NOTE: this map needs FIXING (it contains spawnpoints in solid, see server log)\n");
61 self.mins = self.maxs = '0 0 0';
62 objerror("player spawn point in solid, mapper sucks!\n");
67 self.use = spawnpoint_use;
68 self.team_saved = self.team;
72 if (have_team_spawns != 0)
75 have_team_spawns_forteam[self.team] = 1;
77 if (autocvar_r_showbboxes)
79 // show where spawnpoints point at too
80 makevectors(self.angles);
83 e.classname = "info_player_foo";
84 setorigin(e, self.origin + v_forward * 24);
85 setsize(e, '-8 -8 -8', '8 8 8');
86 e.solid = SOLID_TRIGGER;
89 //self.think = Spawn_Send_Think;
90 //self.nextthink = time;
92 Net_LinkEntity(self, FALSE, 0, Spawn_Send);
95 void spawnfunc_info_player_survivor (void)
97 spawnfunc_info_player_deathmatch();
100 void spawnfunc_info_player_start (void)
102 spawnfunc_info_player_deathmatch();
105 void spawnfunc_info_player_deathmatch (void)
107 self.classname = "info_player_deathmatch";
108 relocate_spawnpoint();
112 // _x: prio (-1 if unusable)
114 vector Spawn_Score(entity spot, float mindist, float teamcheck)
116 float shortest, thisdist;
122 // filter out spots for the wrong team
124 if(spot.team != teamcheck)
128 if(spot.target == "")
131 if(clienttype(self) == CLIENTTYPE_REAL)
133 if(spot.restriction == 1)
138 if(spot.restriction == 2)
142 shortest = vlen(world.maxs - world.mins);
143 FOR_EACH_PLAYER(player) if (player != self)
145 thisdist = vlen(player.origin - spot.origin);
146 if (thisdist < shortest)
149 if(shortest > mindist)
150 prio += SPAWN_PRIO_GOOD_DISTANCE;
152 spawn_score = prio * '1 0 0' + shortest * '0 1 0';
155 // filter out spots for assault
156 if(spot.target != "") {
161 for(ent = world; (ent = find(ent, targetname, spot.target)); )
164 if(ent.spawn_evalfunc)
166 entity oldself = self;
168 spawn_score = ent.spawn_evalfunc(oldself, spot, spawn_score);
170 if(spawn_score_x < 0)
177 dprint("WARNING: spawnpoint at ", vtos(spot.origin), " could not find its target ", spot.target, "\n");
182 MUTATOR_CALLHOOK(Spawn_Score);
186 void Spawn_ScoreAll(entity firstspot, float mindist, float teamcheck)
189 for(spot = firstspot; spot; spot = spot.chain)
190 spot.spawnpoint_score = Spawn_Score(spot, mindist, teamcheck);
193 entity Spawn_FilterOutBadSpots(entity firstspot, float mindist, float teamcheck)
195 entity spot, spotlist, spotlistend;
200 Spawn_ScoreAll(firstspot, mindist, teamcheck);
202 for(spot = firstspot; spot; spot = spot.chain)
204 if(spot.spawnpoint_score_x >= 0) // spawning allowed here
207 spotlistend.chain = spot;
214 spotlistend.chain = world;
219 entity Spawn_WeightedPoint(entity firstspot, float lower, float upper, float exponent)
221 // weight of a point: bound(lower, mindisttoplayer, upper)^exponent
222 // multiplied by spot.cnt (useful if you distribute many spawnpoints in a small area)
225 RandomSelection_Init();
226 for(spot = firstspot; spot; spot = spot.chain)
227 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);
229 return RandomSelection_chosen_ent;
236 Finds a point to respawn
239 entity SelectSpawnPoint (float anypoint)
242 entity spot, firstspot;
244 spot = find (world, classname, "testplayerstart");
248 if(anypoint || autocvar_g_spawn_useallspawns)
250 else if(have_team_spawns > 0)
252 if(have_team_spawns_forteam[self.team] == 0)
254 // we request a spawn for a team, and we have team
255 // spawns, but that team has no spawns?
256 if(have_team_spawns_forteam[0])
260 // if not, any spawn has to do
264 teamcheck = self.team; // MUST be team
266 else if(have_team_spawns == 0 && have_team_spawns_forteam[0])
267 teamcheck = 0; // MUST be noteam
270 // 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
273 // get the entire list of spots
274 firstspot = findchain(classname, "info_player_deathmatch");
275 // filter out the bad ones
276 // (note this returns the original list if none survived)
279 spot = Spawn_WeightedPoint(firstspot, 1, 1, 1);
284 if (arena_roundbased && !g_ca)
288 firstspot = Spawn_FilterOutBadSpots(firstspot, mindist, teamcheck);
290 // there is 50/50 chance of choosing a random spot or the furthest spot
291 // (this means that roughly every other spawn will be furthest, so you
292 // usually won't get fragged at spawn twice in a row)
293 if (random() > autocvar_g_spawn_furthest)
294 spot = Spawn_WeightedPoint(firstspot, 1, 1, 1);
296 spot = Spawn_WeightedPoint(firstspot, 1, 5000, 5); // chooses a far far away spawnpoint
301 if(autocvar_spawn_debug)
305 if(some_spawn_has_been_used)
306 return world; // team can't spawn any more, because of actions of other team
308 error("Cannot find a spawn point - please fix the map!");