4 #include "../dpdefs/progsdefs.qh"
5 #include "../dpdefs/dpextensions.qh"
6 #include "../warpzonelib/util_server.qh"
7 #include "../common/constants.qh"
8 #include "../common/teams.qh"
9 #include "../common/triggers/subs.qh"
10 #include "../common/util.qh"
11 #include "autocvars.qh"
12 #include "constants.qh"
14 #include "mutators/mutators_include.qh"
15 #include "spawnpoints.qh"
19 float SpawnPoint_Send(entity to, float sf)
21 WriteByte(MSG_ENTITY, ENT_CLIENT_SPAWNPOINT);
23 WriteByte(MSG_ENTITY, self.team);
24 WriteShort(MSG_ENTITY, self.origin.x);
25 WriteShort(MSG_ENTITY, self.origin.y);
26 WriteShort(MSG_ENTITY, self.origin.z);
31 float SpawnEvent_Send(entity to, float sf)
35 WriteByte(MSG_ENTITY, ENT_CLIENT_SPAWNEVENT);
37 if(autocvar_g_spawn_alloweffects)
39 WriteByte(MSG_ENTITY, num_for_edict(self.owner));
40 WriteShort(MSG_ENTITY, self.owner.origin.x);
41 WriteShort(MSG_ENTITY, self.owner.origin.y);
42 WriteShort(MSG_ENTITY, self.owner.origin.z);
45 else if((to == self.owner) || (IS_SPEC(to) && (to.enemy == self.owner)) )
47 WriteByte(MSG_ENTITY, 0);
50 else { send = false; }
58 if(have_team_spawns > 0)
60 self.team = activator.team;
61 some_spawn_has_been_used = 1;
63 print("spawnpoint was used!\n");
66 void relocate_spawnpoint()
68 // nudge off the floor
69 setorigin(self, self.origin + '0 0 1');
71 tracebox(self.origin, PL_MIN, PL_MAX, self.origin, true, self);
78 if (!move_out_of_solid(self))
79 objerror("could not get out of solid at all!");
80 print("^1NOTE: this map needs FIXING. Spawnpoint at ", vtos(o - '0 0 1'));
81 print(" needs to be moved out of solid, e.g. by '", ftos(self.origin.x - o.x));
82 print(" ", ftos(self.origin.y - o.y));
83 print(" ", ftos(self.origin.z - o.z), "'\n");
84 if (autocvar_g_spawnpoints_auto_move_out_of_solid)
87 print("\{1}^1NOTE: this map needs FIXING (it contains spawnpoints in solid, see server log)\n");
93 self.mins = self.maxs = '0 0 0';
94 objerror("player spawn point in solid, mapper sucks!\n");
99 self.use = spawnpoint_use;
100 self.team_saved = self.team;
104 if (have_team_spawns != 0)
106 have_team_spawns = 1;
107 have_team_spawns_forteam[self.team] = 1;
109 if (autocvar_r_showbboxes)
111 // show where spawnpoints point at too
112 makevectors(self.angles);
115 e.classname = "info_player_foo";
116 setorigin(e, self.origin + v_forward * 24);
117 setsize(e, '-8 -8 -8', '8 8 8');
118 e.solid = SOLID_TRIGGER;
121 // Don't show team spawns in non-team matches,
122 // and don't show non-team spawns in team matches.
123 // (Unless useallspawns is activated)
126 ( // if this passes, there is a DM spawn on a team match
128 && (self.team != NUM_TEAM_1)
129 && (self.team != NUM_TEAM_2)
130 && (self.team != NUM_TEAM_3)
131 && (self.team != NUM_TEAM_4)
134 ( // if this passes, there is a team spawn on a DM match
138 (self.team == NUM_TEAM_1)
139 || (self.team == NUM_TEAM_2)
140 || (self.team == NUM_TEAM_3)
141 || (self.team == NUM_TEAM_4)
146 autocvar_g_spawn_useallspawns
148 { Net_LinkEntity(self, false, 0, SpawnPoint_Send); }
151 void spawnfunc_info_player_survivor (void)
153 spawnfunc_info_player_deathmatch();
156 void spawnfunc_info_player_start (void)
158 spawnfunc_info_player_deathmatch();
161 void spawnfunc_info_player_deathmatch (void)
163 self.classname = "info_player_deathmatch";
164 relocate_spawnpoint();
168 // _x: prio (-1 if unusable)
170 vector Spawn_Score(entity spot, float mindist, float teamcheck)
172 float shortest, thisdist;
178 // filter out spots for the wrong team
180 if(spot.team != teamcheck)
184 if(spot.target == "")
187 if(IS_REAL_CLIENT(self))
189 if(spot.restriction == 1)
194 if(spot.restriction == 2)
198 shortest = vlen(world.maxs - world.mins);
199 FOR_EACH_PLAYER(player) if (player != self)
201 thisdist = vlen(player.origin - spot.origin);
202 if (thisdist < shortest)
205 if(shortest > mindist)
206 prio += SPAWN_PRIO_GOOD_DISTANCE;
208 spawn_score = prio * '1 0 0' + shortest * '0 1 0';
211 // filter out spots for assault
212 if(spot.target != "") {
217 for(ent = world; (ent = find(ent, targetname, spot.target)); )
220 if(ent.spawn_evalfunc)
222 entity oldself = self;
224 spawn_score = ent.spawn_evalfunc(oldself, spot, spawn_score);
226 if(spawn_score.x < 0)
233 dprint("WARNING: spawnpoint at ", vtos(spot.origin), " could not find its target ", spot.target, "\n");
238 MUTATOR_CALLHOOK(Spawn_Score);
242 void Spawn_ScoreAll(entity firstspot, float mindist, float teamcheck)
245 for(spot = firstspot; spot; spot = spot.chain)
246 spot.spawnpoint_score = Spawn_Score(spot, mindist, teamcheck);
249 entity Spawn_FilterOutBadSpots(entity firstspot, float mindist, float teamcheck)
251 entity spot, spotlist, spotlistend;
256 Spawn_ScoreAll(firstspot, mindist, teamcheck);
258 for(spot = firstspot; spot; spot = spot.chain)
260 if(spot.spawnpoint_score.x >= 0) // spawning allowed here
263 spotlistend.chain = spot;
270 spotlistend.chain = world;
275 entity Spawn_WeightedPoint(entity firstspot, float lower, float upper, float exponent)
277 // weight of a point: bound(lower, mindisttoplayer, upper)^exponent
278 // multiplied by spot.cnt (useful if you distribute many spawnpoints in a small area)
281 RandomSelection_Init();
282 for(spot = firstspot; spot; spot = spot.chain)
283 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);
285 return RandomSelection_chosen_ent;
292 Finds a point to respawn
295 entity SelectSpawnPoint (float anypoint)
298 entity spot, firstspot;
300 spot = find (world, classname, "testplayerstart");
304 if(anypoint || autocvar_g_spawn_useallspawns)
306 else if(have_team_spawns > 0)
308 if(have_team_spawns_forteam[self.team] == 0)
310 // we request a spawn for a team, and we have team
311 // spawns, but that team has no spawns?
312 if(have_team_spawns_forteam[0])
316 // if not, any spawn has to do
320 teamcheck = self.team; // MUST be team
322 else if(have_team_spawns == 0 && have_team_spawns_forteam[0])
323 teamcheck = 0; // MUST be noteam
326 // 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
329 // get the entire list of spots
330 firstspot = findchain(classname, "info_player_deathmatch");
331 // filter out the bad ones
332 // (note this returns the original list if none survived)
335 spot = Spawn_WeightedPoint(firstspot, 1, 1, 1);
339 firstspot = Spawn_FilterOutBadSpots(firstspot, 100, teamcheck);
341 // there is 50/50 chance of choosing a random spot or the furthest spot
342 // (this means that roughly every other spawn will be furthest, so you
343 // usually won't get fragged at spawn twice in a row)
344 if (random() > autocvar_g_spawn_furthest)
345 spot = Spawn_WeightedPoint(firstspot, 1, 1, 1);
347 spot = Spawn_WeightedPoint(firstspot, 1, 5000, 5); // chooses a far far away spawnpoint
352 if(autocvar_spawn_debug)
356 if(some_spawn_has_been_used)
357 return world; // team can't spawn any more, because of actions of other team
359 error("Cannot find a spawn point - please fix the map!");