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/util.qh"
10 #include "autocvars.qh"
11 #include "constants.qh"
13 #include "mutators/mutators_include.qh"
14 #include "spawnpoints.qh"
18 float SpawnPoint_Send(entity to, float sf)
20 WriteByte(MSG_ENTITY, ENT_CLIENT_SPAWNPOINT);
22 WriteByte(MSG_ENTITY, self.team);
23 WriteShort(MSG_ENTITY, self.origin.x);
24 WriteShort(MSG_ENTITY, self.origin.y);
25 WriteShort(MSG_ENTITY, self.origin.z);
30 float SpawnEvent_Send(entity to, float sf)
34 WriteByte(MSG_ENTITY, ENT_CLIENT_SPAWNEVENT);
36 if(autocvar_g_spawn_alloweffects)
38 WriteByte(MSG_ENTITY, num_for_edict(self.owner));
39 WriteShort(MSG_ENTITY, self.owner.origin.x);
40 WriteShort(MSG_ENTITY, self.owner.origin.y);
41 WriteShort(MSG_ENTITY, self.owner.origin.z);
44 else if((to == self.owner) || (IS_SPEC(to) && (to.enemy == self.owner)) )
46 WriteByte(MSG_ENTITY, 0);
49 else { send = false; }
57 if(have_team_spawns > 0)
59 self.team = activator.team;
60 some_spawn_has_been_used = 1;
62 print("spawnpoint was used!\n");
65 void relocate_spawnpoint()
67 // nudge off the floor
68 setorigin(self, self.origin + '0 0 1');
70 tracebox(self.origin, PL_MIN, PL_MAX, self.origin, true, self);
77 if (!move_out_of_solid(self))
78 objerror("could not get out of solid at all!");
79 print("^1NOTE: this map needs FIXING. Spawnpoint at ", vtos(o - '0 0 1'));
80 print(" needs to be moved out of solid, e.g. by '", ftos(self.origin.x - o.x));
81 print(" ", ftos(self.origin.y - o.y));
82 print(" ", ftos(self.origin.z - o.z), "'\n");
83 if (autocvar_g_spawnpoints_auto_move_out_of_solid)
86 print("\{1}^1NOTE: this map needs FIXING (it contains spawnpoints in solid, see server log)\n");
92 self.mins = self.maxs = '0 0 0';
93 objerror("player spawn point in solid, mapper sucks!\n");
98 self.use = spawnpoint_use;
99 self.team_saved = self.team;
103 if (have_team_spawns != 0)
105 have_team_spawns = 1;
106 have_team_spawns_forteam[self.team] = 1;
108 if (autocvar_r_showbboxes)
110 // show where spawnpoints point at too
111 makevectors(self.angles);
114 e.classname = "info_player_foo";
115 setorigin(e, self.origin + v_forward * 24);
116 setsize(e, '-8 -8 -8', '8 8 8');
117 e.solid = SOLID_TRIGGER;
120 // Don't show team spawns in non-team matches,
121 // and don't show non-team spawns in team matches.
122 // (Unless useallspawns is activated)
125 ( // if this passes, there is a DM spawn on a team match
127 && (self.team != NUM_TEAM_1)
128 && (self.team != NUM_TEAM_2)
129 && (self.team != NUM_TEAM_3)
130 && (self.team != NUM_TEAM_4)
133 ( // if this passes, there is a team spawn on a DM match
137 (self.team == NUM_TEAM_1)
138 || (self.team == NUM_TEAM_2)
139 || (self.team == NUM_TEAM_3)
140 || (self.team == NUM_TEAM_4)
145 autocvar_g_spawn_useallspawns
147 { Net_LinkEntity(self, false, 0, SpawnPoint_Send); }
150 void spawnfunc_info_player_survivor (void)
152 spawnfunc_info_player_deathmatch();
155 void spawnfunc_info_player_start (void)
157 spawnfunc_info_player_deathmatch();
160 void spawnfunc_info_player_deathmatch (void)
162 self.classname = "info_player_deathmatch";
163 relocate_spawnpoint();
167 // _x: prio (-1 if unusable)
169 vector Spawn_Score(entity spot, float mindist, float teamcheck)
171 float shortest, thisdist;
177 // filter out spots for the wrong team
179 if(spot.team != teamcheck)
183 if(spot.target == "")
186 if(IS_REAL_CLIENT(self))
188 if(spot.restriction == 1)
193 if(spot.restriction == 2)
197 shortest = vlen(world.maxs - world.mins);
198 FOR_EACH_PLAYER(player) if (player != self)
200 thisdist = vlen(player.origin - spot.origin);
201 if (thisdist < shortest)
204 if(shortest > mindist)
205 prio += SPAWN_PRIO_GOOD_DISTANCE;
207 spawn_score = prio * '1 0 0' + shortest * '0 1 0';
210 // filter out spots for assault
211 if(spot.target != "") {
216 for(ent = world; (ent = find(ent, targetname, spot.target)); )
219 if(ent.spawn_evalfunc)
221 entity oldself = self;
223 spawn_score = ent.spawn_evalfunc(oldself, spot, spawn_score);
225 if(spawn_score.x < 0)
232 dprint("WARNING: spawnpoint at ", vtos(spot.origin), " could not find its target ", spot.target, "\n");
237 MUTATOR_CALLHOOK(Spawn_Score);
241 void Spawn_ScoreAll(entity firstspot, float mindist, float teamcheck)
244 for(spot = firstspot; spot; spot = spot.chain)
245 spot.spawnpoint_score = Spawn_Score(spot, mindist, teamcheck);
248 entity Spawn_FilterOutBadSpots(entity firstspot, float mindist, float teamcheck)
250 entity spot, spotlist, spotlistend;
255 Spawn_ScoreAll(firstspot, mindist, teamcheck);
257 for(spot = firstspot; spot; spot = spot.chain)
259 if(spot.spawnpoint_score.x >= 0) // spawning allowed here
262 spotlistend.chain = spot;
269 spotlistend.chain = world;
274 entity Spawn_WeightedPoint(entity firstspot, float lower, float upper, float exponent)
276 // weight of a point: bound(lower, mindisttoplayer, upper)^exponent
277 // multiplied by spot.cnt (useful if you distribute many spawnpoints in a small area)
280 RandomSelection_Init();
281 for(spot = firstspot; spot; spot = spot.chain)
282 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);
284 return RandomSelection_chosen_ent;
291 Finds a point to respawn
294 entity SelectSpawnPoint (float anypoint)
297 entity spot, firstspot;
299 spot = find (world, classname, "testplayerstart");
303 if(anypoint || autocvar_g_spawn_useallspawns)
305 else if(have_team_spawns > 0)
307 if(have_team_spawns_forteam[self.team] == 0)
309 // we request a spawn for a team, and we have team
310 // spawns, but that team has no spawns?
311 if(have_team_spawns_forteam[0])
315 // if not, any spawn has to do
319 teamcheck = self.team; // MUST be team
321 else if(have_team_spawns == 0 && have_team_spawns_forteam[0])
322 teamcheck = 0; // MUST be noteam
325 // 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
328 // get the entire list of spots
329 firstspot = findchain(classname, "info_player_deathmatch");
330 // filter out the bad ones
331 // (note this returns the original list if none survived)
334 spot = Spawn_WeightedPoint(firstspot, 1, 1, 1);
338 firstspot = Spawn_FilterOutBadSpots(firstspot, 100, teamcheck);
340 // there is 50/50 chance of choosing a random spot or the furthest spot
341 // (this means that roughly every other spawn will be furthest, so you
342 // usually won't get fragged at spawn twice in a row)
343 if (random() > autocvar_g_spawn_furthest)
344 spot = Spawn_WeightedPoint(firstspot, 1, 1, 1);
346 spot = Spawn_WeightedPoint(firstspot, 1, 5000, 5); // chooses a far far away spawnpoint
351 if(autocvar_spawn_debug)
355 if(some_spawn_has_been_used)
356 return world; // team can't spawn any more, because of actions of other team
358 error("Cannot find a spawn point - please fix the map!");