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 Net_LinkEntity(self, FALSE, 0, SpawnPoint_Send);
106 void spawnfunc_info_player_survivor (void)
108 spawnfunc_info_player_deathmatch();
111 void spawnfunc_info_player_start (void)
113 spawnfunc_info_player_deathmatch();
116 void spawnfunc_info_player_deathmatch (void)
118 self.classname = "info_player_deathmatch";
119 relocate_spawnpoint();
123 // _x: prio (-1 if unusable)
125 vector Spawn_Score(entity spot, float mindist, float teamcheck)
127 float shortest, thisdist;
133 // filter out spots for the wrong team
135 if(spot.team != teamcheck)
139 if(spot.target == "")
142 if(IS_REAL_CLIENT(self))
144 if(spot.restriction == 1)
149 if(spot.restriction == 2)
153 shortest = vlen(world.maxs - world.mins);
154 FOR_EACH_PLAYER(player) if (player != self)
156 thisdist = vlen(player.origin - spot.origin);
157 if (thisdist < shortest)
160 if(shortest > mindist)
161 prio += SPAWN_PRIO_GOOD_DISTANCE;
163 spawn_score = prio * '1 0 0' + shortest * '0 1 0';
166 // filter out spots for assault
167 if(spot.target != "") {
172 for(ent = world; (ent = find(ent, targetname, spot.target)); )
175 if(ent.spawn_evalfunc)
177 entity oldself = self;
179 spawn_score = ent.spawn_evalfunc(oldself, spot, spawn_score);
181 if(spawn_score_x < 0)
188 dprint("WARNING: spawnpoint at ", vtos(spot.origin), " could not find its target ", spot.target, "\n");
193 MUTATOR_CALLHOOK(Spawn_Score);
197 void Spawn_ScoreAll(entity firstspot, float mindist, float teamcheck)
200 for(spot = firstspot; spot; spot = spot.chain)
201 spot.spawnpoint_score = Spawn_Score(spot, mindist, teamcheck);
204 entity Spawn_FilterOutBadSpots(entity firstspot, float mindist, float teamcheck)
206 entity spot, spotlist, spotlistend;
211 Spawn_ScoreAll(firstspot, mindist, teamcheck);
213 for(spot = firstspot; spot; spot = spot.chain)
215 if(spot.spawnpoint_score_x >= 0) // spawning allowed here
218 spotlistend.chain = spot;
225 spotlistend.chain = world;
230 entity Spawn_WeightedPoint(entity firstspot, float lower, float upper, float exponent)
232 // weight of a point: bound(lower, mindisttoplayer, upper)^exponent
233 // multiplied by spot.cnt (useful if you distribute many spawnpoints in a small area)
236 RandomSelection_Init();
237 for(spot = firstspot; spot; spot = spot.chain)
238 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);
240 return RandomSelection_chosen_ent;
247 Finds a point to respawn
250 entity SelectSpawnPoint (float anypoint)
253 entity spot, firstspot;
255 spot = find (world, classname, "testplayerstart");
259 if(anypoint || autocvar_g_spawn_useallspawns)
261 else if(have_team_spawns > 0)
263 if(have_team_spawns_forteam[self.team] == 0)
265 // we request a spawn for a team, and we have team
266 // spawns, but that team has no spawns?
267 if(have_team_spawns_forteam[0])
271 // if not, any spawn has to do
275 teamcheck = self.team; // MUST be team
277 else if(have_team_spawns == 0 && have_team_spawns_forteam[0])
278 teamcheck = 0; // MUST be noteam
281 // 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
284 // get the entire list of spots
285 firstspot = findchain(classname, "info_player_deathmatch");
286 // filter out the bad ones
287 // (note this returns the original list if none survived)
290 spot = Spawn_WeightedPoint(firstspot, 1, 1, 1);
295 if(g_arena && arena_roundbased)
299 firstspot = Spawn_FilterOutBadSpots(firstspot, mindist, teamcheck);
301 // there is 50/50 chance of choosing a random spot or the furthest spot
302 // (this means that roughly every other spawn will be furthest, so you
303 // usually won't get fragged at spawn twice in a row)
304 if (random() > autocvar_g_spawn_furthest)
305 spot = Spawn_WeightedPoint(firstspot, 1, 1, 1);
307 spot = Spawn_WeightedPoint(firstspot, 1, 5000, 5); // chooses a far far away spawnpoint
312 if(autocvar_spawn_debug)
316 if(some_spawn_has_been_used)
317 return world; // team can't spawn any more, because of actions of other team
319 error("Cannot find a spawn point - please fix the map!");