1 float SpawnPoint_Send(entity to, float sf)
3 WriteByte(MSG_ENTITY, ENT_CLIENT_SPAWNPOINT);
5 WriteByte(MSG_ENTITY, self.team);
6 WriteShort(MSG_ENTITY, self.origin_x);
7 WriteShort(MSG_ENTITY, self.origin_y);
8 WriteShort(MSG_ENTITY, self.origin_z);
13 float SpawnEvent_Send(entity to, float sf)
17 WriteByte(MSG_ENTITY, ENT_CLIENT_SPAWNEVENT);
19 if(autocvar_g_spawn_alloweffects)
21 WriteByte(MSG_ENTITY, num_for_edict(self.owner));
22 WriteShort(MSG_ENTITY, self.owner.origin_x);
23 WriteShort(MSG_ENTITY, self.owner.origin_y);
24 WriteShort(MSG_ENTITY, self.owner.origin_z);
27 else if((to == self.owner) || (IS_SPEC(to) && (to.enemy == self.owner)) )
29 WriteByte(MSG_ENTITY, 0);
32 else { send = FALSE; }
40 if(have_team_spawns > 0)
42 self.team = activator.team;
43 some_spawn_has_been_used = 1;
45 print("spawnpoint was used!\n");
48 void relocate_spawnpoint()
50 // nudge off the floor
51 setorigin(self, self.origin + '0 0 1');
53 tracebox(self.origin, PL_MIN, PL_MAX, self.origin, TRUE, self);
60 if (!move_out_of_solid(self))
61 objerror("could not get out of solid at all!");
62 print("^1NOTE: this map needs FIXING. Spawnpoint at ", vtos(o - '0 0 1'));
63 print(" needs to be moved out of solid, e.g. by '", ftos(self.origin_x - o_x));
64 print(" ", ftos(self.origin_y - o_y));
65 print(" ", ftos(self.origin_z - o_z), "'\n");
66 if (autocvar_g_spawnpoints_auto_move_out_of_solid)
69 print("\{1}^1NOTE: this map needs FIXING (it contains spawnpoints in solid, see server log)\n");
75 self.mins = self.maxs = '0 0 0';
76 objerror("player spawn point in solid, mapper sucks!\n");
81 self.use = spawnpoint_use;
82 self.team_saved = self.team;
86 if (have_team_spawns != 0)
89 have_team_spawns_forteam[self.team] = 1;
91 if (autocvar_r_showbboxes)
93 // show where spawnpoints point at too
94 makevectors(self.angles);
97 e.classname = "info_player_foo";
98 setorigin(e, self.origin + v_forward * 24);
99 setsize(e, '-8 -8 -8', '8 8 8');
100 e.solid = SOLID_TRIGGER;
103 // Don't show team spawns in non-team matches,
104 // and don't show non-team spawns in team matches.
105 // (Unless useallspawns is activated)
108 ( // if this passes, there is a DM spawn on a team match
110 && (self.team != NUM_TEAM_1)
111 && (self.team != NUM_TEAM_2)
112 && (self.team != NUM_TEAM_3)
113 && (self.team != NUM_TEAM_4)
116 ( // if this passes, there is a team spawn on a DM match
120 (self.team == NUM_TEAM_1)
121 || (self.team == NUM_TEAM_2)
122 || (self.team == NUM_TEAM_3)
123 || (self.team == NUM_TEAM_4)
128 autocvar_g_spawn_useallspawns
130 { Net_LinkEntity(self, FALSE, 0, SpawnPoint_Send); }
133 void spawnfunc_info_player_survivor (void)
135 spawnfunc_info_player_deathmatch();
138 void spawnfunc_info_player_start (void)
140 spawnfunc_info_player_deathmatch();
143 void spawnfunc_info_player_deathmatch (void)
145 self.classname = "info_player_deathmatch";
146 relocate_spawnpoint();
150 // _x: prio (-1 if unusable)
152 vector Spawn_Score(entity spot, float mindist, float teamcheck)
154 float shortest, thisdist;
160 // filter out spots for the wrong team
162 if(spot.team != teamcheck)
166 if(spot.target == "")
169 if(IS_REAL_CLIENT(self))
171 if(spot.restriction == 1)
176 if(spot.restriction == 2)
180 shortest = vlen(world.maxs - world.mins);
181 FOR_EACH_PLAYER(player) if (player != self)
183 thisdist = vlen(player.origin - spot.origin);
184 if (thisdist < shortest)
187 if(shortest > mindist)
188 prio += SPAWN_PRIO_GOOD_DISTANCE;
190 spawn_score = prio * '1 0 0' + shortest * '0 1 0';
193 // filter out spots for assault
194 if(spot.target != "") {
199 for(ent = world; (ent = find(ent, targetname, spot.target)); )
202 if(ent.spawn_evalfunc)
204 entity oldself = self;
206 spawn_score = ent.spawn_evalfunc(oldself, spot, spawn_score);
208 if(spawn_score_x < 0)
215 dprint("WARNING: spawnpoint at ", vtos(spot.origin), " could not find its target ", spot.target, "\n");
220 MUTATOR_CALLHOOK(Spawn_Score);
224 void Spawn_ScoreAll(entity firstspot, float mindist, float teamcheck)
227 for(spot = firstspot; spot; spot = spot.chain)
228 spot.spawnpoint_score = Spawn_Score(spot, mindist, teamcheck);
231 entity Spawn_FilterOutBadSpots(entity firstspot, float mindist, float teamcheck)
233 entity spot, spotlist, spotlistend;
238 Spawn_ScoreAll(firstspot, mindist, teamcheck);
240 for(spot = firstspot; spot; spot = spot.chain)
242 if(spot.spawnpoint_score_x >= 0) // spawning allowed here
245 spotlistend.chain = spot;
252 spotlistend.chain = world;
257 entity Spawn_WeightedPoint(entity firstspot, float lower, float upper, float exponent)
259 // weight of a point: bound(lower, mindisttoplayer, upper)^exponent
260 // multiplied by spot.cnt (useful if you distribute many spawnpoints in a small area)
263 RandomSelection_Init();
264 for(spot = firstspot; spot; spot = spot.chain)
265 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);
267 return RandomSelection_chosen_ent;
274 Finds a point to respawn
277 entity SelectSpawnPoint (float anypoint)
280 entity spot, firstspot;
282 spot = find (world, classname, "testplayerstart");
286 if(anypoint || autocvar_g_spawn_useallspawns)
288 else if(have_team_spawns > 0)
290 if(have_team_spawns_forteam[self.team] == 0)
292 // we request a spawn for a team, and we have team
293 // spawns, but that team has no spawns?
294 if(have_team_spawns_forteam[0])
298 // if not, any spawn has to do
302 teamcheck = self.team; // MUST be team
304 else if(have_team_spawns == 0 && have_team_spawns_forteam[0])
305 teamcheck = 0; // MUST be noteam
308 // 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
311 // get the entire list of spots
312 firstspot = findchain(classname, "info_player_deathmatch");
313 // filter out the bad ones
314 // (note this returns the original list if none survived)
317 spot = Spawn_WeightedPoint(firstspot, 1, 1, 1);
322 if(g_arena && arena_roundbased)
326 firstspot = Spawn_FilterOutBadSpots(firstspot, mindist, teamcheck);
328 // there is 50/50 chance of choosing a random spot or the furthest spot
329 // (this means that roughly every other spawn will be furthest, so you
330 // usually won't get fragged at spawn twice in a row)
331 if (random() > autocvar_g_spawn_furthest)
332 spot = Spawn_WeightedPoint(firstspot, 1, 1, 1);
334 spot = Spawn_WeightedPoint(firstspot, 1, 5000, 5); // chooses a far far away spawnpoint
339 if(autocvar_spawn_debug)
343 if(some_spawn_has_been_used)
344 return world; // team can't spawn any more, because of actions of other team
346 error("Cannot find a spawn point - please fix the map!");