2 .float last_spawn_time;
4 float Spawn_Send(entity to, float sf)
6 WriteByte(MSG_ENTITY, ENT_CLIENT_SPAWNPOINT);
7 WriteByte(MSG_ENTITY, sf);
11 WriteByte(MSG_ENTITY, self.team);
12 WriteShort(MSG_ENTITY, self.origin_x);
13 WriteShort(MSG_ENTITY, self.origin_y);
14 WriteShort(MSG_ENTITY, self.origin_z);
18 WriteLong(MSG_ENTITY, self.last_spawn_time);
24 void Spawn_Think(void)
26 if(self.send_spawn < 0)
33 self.last_spawn_time = self.send_spawn;
42 if(have_team_spawns > 0)
44 self.team = activator.team;
45 some_spawn_has_been_used = 1;
47 print("spawnpoint was used!\n");
48 self.send_spawn = time;
49 self.nextthink = time;
52 void relocate_spawnpoint()
54 // nudge off the floor
55 setorigin(self, self.origin + '0 0 1');
57 tracebox(self.origin, PL_MIN, PL_MAX, self.origin, TRUE, self);
64 if (!move_out_of_solid(self))
65 objerror("could not get out of solid at all!");
66 print("^1NOTE: this map needs FIXING. Spawnpoint at ", vtos(o - '0 0 1'));
67 print(" needs to be moved out of solid, e.g. by '", ftos(self.origin_x - o_x));
68 print(" ", ftos(self.origin_y - o_y));
69 print(" ", ftos(self.origin_z - o_z), "'\n");
70 if (autocvar_g_spawnpoints_auto_move_out_of_solid)
73 print("\{1}^1NOTE: this map needs FIXING (it contains spawnpoints in solid, see server log)\n");
79 self.mins = self.maxs = '0 0 0';
80 objerror("player spawn point in solid, mapper sucks!\n");
85 self.use = spawnpoint_use;
86 self.team_saved = self.team;
90 if (have_team_spawns != 0)
93 have_team_spawns_forteam[self.team] = 1;
95 if (autocvar_r_showbboxes)
97 // show where spawnpoints point at too
98 makevectors(self.angles);
101 e.classname = "info_player_foo";
102 setorigin(e, self.origin + v_forward * 24);
103 setsize(e, '-8 -8 -8', '8 8 8');
104 e.solid = SOLID_TRIGGER;
107 self.send_spawn = -1;
108 self.think = Spawn_Think;
109 self.nextthink = time;
111 Net_LinkEntity(self, FALSE, 0, Spawn_Send);
114 void spawnfunc_info_player_survivor (void)
116 spawnfunc_info_player_deathmatch();
119 void spawnfunc_info_player_start (void)
121 spawnfunc_info_player_deathmatch();
124 void spawnfunc_info_player_deathmatch (void)
126 self.classname = "info_player_deathmatch";
127 relocate_spawnpoint();
131 // _x: prio (-1 if unusable)
133 vector Spawn_Score(entity spot, float mindist, float teamcheck)
135 float shortest, thisdist;
141 // filter out spots for the wrong team
143 if(spot.team != teamcheck)
147 if(spot.target == "")
150 if(clienttype(self) == CLIENTTYPE_REAL)
152 if(spot.restriction == 1)
157 if(spot.restriction == 2)
161 shortest = vlen(world.maxs - world.mins);
162 FOR_EACH_PLAYER(player) if (player != self)
164 thisdist = vlen(player.origin - spot.origin);
165 if (thisdist < shortest)
168 if(shortest > mindist)
169 prio += SPAWN_PRIO_GOOD_DISTANCE;
171 spawn_score = prio * '1 0 0' + shortest * '0 1 0';
174 // filter out spots for assault
175 if(spot.target != "") {
180 for(ent = world; (ent = find(ent, targetname, spot.target)); )
183 if(ent.spawn_evalfunc)
185 entity oldself = self;
187 spawn_score = ent.spawn_evalfunc(oldself, spot, spawn_score);
189 if(spawn_score_x < 0)
196 dprint("WARNING: spawnpoint at ", vtos(spot.origin), " could not find its target ", spot.target, "\n");
201 MUTATOR_CALLHOOK(Spawn_Score);
205 void Spawn_ScoreAll(entity firstspot, float mindist, float teamcheck)
208 for(spot = firstspot; spot; spot = spot.chain)
209 spot.spawnpoint_score = Spawn_Score(spot, mindist, teamcheck);
212 entity Spawn_FilterOutBadSpots(entity firstspot, float mindist, float teamcheck)
214 entity spot, spotlist, spotlistend;
219 Spawn_ScoreAll(firstspot, mindist, teamcheck);
221 for(spot = firstspot; spot; spot = spot.chain)
223 if(spot.spawnpoint_score_x >= 0) // spawning allowed here
226 spotlistend.chain = spot;
233 spotlistend.chain = world;
238 entity Spawn_WeightedPoint(entity firstspot, float lower, float upper, float exponent)
240 // weight of a point: bound(lower, mindisttoplayer, upper)^exponent
241 // multiplied by spot.cnt (useful if you distribute many spawnpoints in a small area)
244 RandomSelection_Init();
245 for(spot = firstspot; spot; spot = spot.chain)
246 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);
248 return RandomSelection_chosen_ent;
255 Finds a point to respawn
258 entity SelectSpawnPoint (float anypoint)
261 entity spot, firstspot;
263 spot = find (world, classname, "testplayerstart");
267 if(anypoint || autocvar_g_spawn_useallspawns)
269 else if(have_team_spawns > 0)
271 if(have_team_spawns_forteam[self.team] == 0)
273 // we request a spawn for a team, and we have team
274 // spawns, but that team has no spawns?
275 if(have_team_spawns_forteam[0])
279 // if not, any spawn has to do
283 teamcheck = self.team; // MUST be team
285 else if(have_team_spawns == 0 && have_team_spawns_forteam[0])
286 teamcheck = 0; // MUST be noteam
289 // 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
292 // get the entire list of spots
293 firstspot = findchain(classname, "info_player_deathmatch");
294 // filter out the bad ones
295 // (note this returns the original list if none survived)
298 spot = Spawn_WeightedPoint(firstspot, 1, 1, 1);
303 if(g_arena && arena_roundbased)
307 firstspot = Spawn_FilterOutBadSpots(firstspot, mindist, teamcheck);
309 // there is 50/50 chance of choosing a random spot or the furthest spot
310 // (this means that roughly every other spawn will be furthest, so you
311 // usually won't get fragged at spawn twice in a row)
312 if (random() > autocvar_g_spawn_furthest)
313 spot = Spawn_WeightedPoint(firstspot, 1, 1, 1);
315 spot = Spawn_WeightedPoint(firstspot, 1, 5000, 5); // chooses a far far away spawnpoint
320 if(autocvar_spawn_debug)
324 if(some_spawn_has_been_used)
325 return world; // team can't spawn any more, because of actions of other team
327 error("Cannot find a spawn point - please fix the map!");