01a3aeae3d68dd14df21ab6782dd9aba6e7aa868
[voretournament/voretournament.git] / data / qcsrc / server / cl_client.qc
1 void race_send_recordtime(float msg);\r
2 void race_SendRankings(float pos, float prevpos, float del, float msg);\r
3 \r
4 void send_CSQC_teamnagger() {\r
5         WriteByte(0, SVC_TEMPENTITY);\r
6         WriteByte(0, TE_CSQC_TEAMNAGGER);\r
7 }\r
8 \r
9 void Announce(string snd) {\r
10         WriteByte(MSG_ALL, SVC_TEMPENTITY);\r
11         WriteByte(MSG_ALL, TE_CSQC_ANNOUNCE);\r
12         WriteString(MSG_ALL, snd);\r
13 }\r
14 \r
15 void AnnounceTo(entity e, string snd) {\r
16         if (clienttype(e) == CLIENTTYPE_REAL)\r
17         {\r
18                 msg_entity = e;\r
19                 WriteByte(MSG_ONE, SVC_TEMPENTITY);\r
20                 WriteByte(MSG_ONE, TE_CSQC_ANNOUNCE);\r
21                 WriteString(MSG_ONE, snd);\r
22         }\r
23 }\r
24 \r
25 float ClientData_Send(entity to, float sf)\r
26 {\r
27         if(to != self.owner)\r
28         {\r
29                 error("wtf");\r
30                 return FALSE;\r
31         }\r
32 \r
33         entity e;\r
34 \r
35         e = to;\r
36         if(to.classname == "spectator")\r
37                 e = to.enemy;\r
38 \r
39         sf = 0;\r
40 \r
41         if(e.race_completed)\r
42                 sf |= 1; // forced scoreboard\r
43         if(to.spectatee_status)\r
44                 sf |= 2; // spectator ent number follows\r
45         if(e.zoomstate)\r
46                 sf |= 4; // zoomed\r
47 \r
48         WriteByte(MSG_ENTITY, ENT_CLIENT_CLIENTDATA);\r
49         WriteByte(MSG_ENTITY, sf);\r
50 \r
51         if(sf & 2)\r
52                 WriteByte(MSG_ENTITY, to.spectatee_status);\r
53 \r
54         if(sf & 8)\r
55         {\r
56                 WriteAngle(MSG_ENTITY, e.v_angle_x);\r
57                 WriteAngle(MSG_ENTITY, e.v_angle_y);\r
58         }\r
59 \r
60         return TRUE;\r
61 }\r
62 \r
63 void ClientData_Attach()\r
64 {\r
65         Net_LinkEntity(self.clientdata = spawn(), FALSE, 0, ClientData_Send);\r
66         self.clientdata.drawonlytoclient = self;\r
67         self.clientdata.owner = self;\r
68 }\r
69 \r
70 void ClientData_Detach()\r
71 {\r
72         remove(self.clientdata);\r
73         self.clientdata = world;\r
74 }\r
75 \r
76 void ClientData_Touch(entity e)\r
77 {\r
78         e.clientdata.SendFlags = 1;\r
79 \r
80         // make it spectatable\r
81         entity e2;\r
82         FOR_EACH_REALCLIENT(e2)\r
83         {\r
84                 if(e2 != e)\r
85                         if(e2.classname == "spectator")\r
86                                 if(e2.enemy == e)\r
87                                         e2.clientdata.SendFlags = 1;\r
88         }\r
89 }\r
90 \r
91 \r
92 .vector spawnpoint_score;\r
93 .string netname_previous;\r
94 \r
95 void spawnfunc_info_player_survivor (void)\r
96 {\r
97         spawnfunc_info_player_deathmatch();\r
98 }\r
99 \r
100 void spawnfunc_info_player_start (void)\r
101 {\r
102         spawnfunc_info_player_deathmatch();\r
103 }\r
104 \r
105 void spawnfunc_info_player_deathmatch (void)\r
106 {\r
107         self.classname = "info_player_deathmatch";\r
108         relocate_spawnpoint();\r
109 }\r
110 \r
111 void spawnpoint_use()\r
112 {\r
113         if(teams_matter)\r
114         if(have_team_spawns > 0)\r
115         {\r
116                 self.team = activator.team;\r
117                 some_spawn_has_been_used = 1;\r
118         }\r
119 };\r
120 \r
121 // Returns:\r
122 //   _x: prio (-1 if unusable)\r
123 //   _y: weight\r
124 vector Spawn_Score(entity spot, entity playerlist, float teamcheck, float anypoint)\r
125 {\r
126         float shortest, thisdist;\r
127         float prio;\r
128         entity player;\r
129 \r
130         prio = 0;\r
131 \r
132         // filter out spots for the wrong team\r
133         if(teamcheck)\r
134         if(spot.team != teamcheck)\r
135                 return '-1 0 0';\r
136 \r
137         if(race_spawns)\r
138                 if(spot.target == "")\r
139                         return '-1 0 0';\r
140 \r
141         if(clienttype(self) == CLIENTTYPE_REAL)\r
142         {\r
143                 if(spot.restriction == 1)\r
144                         return '-1 0 0';\r
145         }\r
146         else\r
147         {\r
148                 if(spot.restriction == 2)\r
149                         return '-1 0 0';\r
150         }\r
151 \r
152         // filter out spots for assault\r
153         if(spot.target != "") {\r
154                 local entity ent;\r
155                 float good, found;\r
156                 ent = find(world, targetname, spot.target);\r
157 \r
158                 while(ent) {\r
159                         if(ent.classname == "target_objective")\r
160                         {\r
161                                 found = 1;\r
162                                 if(ent.health < 0 || ent.health >= ASSAULT_VALUE_INACTIVE)\r
163                                         return '-1 0 0';\r
164                                 good = 1;\r
165                         }\r
166                         else if(ent.classname == "trigger_race_checkpoint")\r
167                         {\r
168                                 found = 1;\r
169                                 if(!anypoint) // spectators may spawn everywhere\r
170 \r
171                                 {\r
172                                         if(g_race_qualifying)\r
173                                         {\r
174                                                 // spawn at first\r
175                                                 if(ent.race_checkpoint != 0)\r
176                                                         return '-1 0 0';\r
177                                                 if(spot.race_place != race_lowest_place_spawn)\r
178                                                         return '-1 0 0';\r
179                                         }\r
180                                         else\r
181                                         {\r
182                                                 if(ent.race_checkpoint != self.race_respawn_checkpoint)\r
183                                                         return '-1 0 0';\r
184                                                 // try reusing the previous spawn\r
185                                                 if(ent == self.race_respawn_spotref || spot == self.race_respawn_spotref)\r
186                                                         prio += 1;\r
187                                                 if(ent.race_checkpoint == 0)\r
188                                                 {\r
189                                                         float pl;\r
190                                                         pl = self.race_place;\r
191                                                         if(pl > race_highest_place_spawn)\r
192                                                                 pl = 0;\r
193                                                         if(pl == 0 && !self.race_started)\r
194                                                                 pl = race_highest_place_spawn; // use last place if he has not even touched finish yet\r
195                                                         if(spot.race_place != pl)\r
196                                                                 return '-1 0 0';\r
197                                                 }\r
198                                         }\r
199                                 }\r
200                                 good = 1;\r
201                         }\r
202                         ent = find(ent, targetname, spot.target);\r
203                 }\r
204 \r
205                 if(found && !good)\r
206                         return '-1 0 0';\r
207         }\r
208 \r
209         player = playerlist;\r
210         shortest = vlen(world.maxs - world.mins);\r
211         for(player = playerlist; player; player = player.chain)\r
212                 if (player != self)\r
213                 {\r
214                         thisdist = vlen(player.origin - spot.origin);\r
215                         if (thisdist < shortest)\r
216                                 shortest = thisdist;\r
217                 }\r
218         return prio * '1 0 0' + shortest * '0 1 0';\r
219 }\r
220 \r
221 float spawn_allbad;\r
222 float spawn_allgood;\r
223 entity Spawn_FilterOutBadSpots(entity firstspot, entity playerlist, float mindist, float teamcheck, float anypoint)\r
224 {\r
225         local entity spot, spotlist, spotlistend;\r
226         spawn_allgood = TRUE;\r
227         spawn_allbad = TRUE;\r
228 \r
229         spotlist = world;\r
230         spotlistend = world;\r
231 \r
232         for(spot = firstspot; spot; spot = spot.chain)\r
233         {\r
234                 spot.spawnpoint_score = Spawn_Score(spot, playerlist, teamcheck, anypoint);\r
235 \r
236                 if(cvar("spawn_debugview"))\r
237                 {\r
238                         setmodel(spot, "models/rune.mdl");\r
239                         if(spot.spawnpoint_score_y < mindist)\r
240                         {\r
241                                 spot.colormod = '1 0 0';\r
242                                 spot.scale = 1;\r
243                         }\r
244                         else\r
245                         {\r
246                                 spot.colormod = '0 1 0';\r
247                                 spot.scale = spot.spawnpoint_score_y / mindist;\r
248                         }\r
249                 }\r
250 \r
251                 if(spot.spawnpoint_score_x >= 0) // spawning allowed here\r
252                 {\r
253                         if(spot.spawnpoint_score_y < mindist)\r
254                         {\r
255                                 // too short distance\r
256                                 spawn_allgood = FALSE;\r
257                         }\r
258                         else\r
259                         {\r
260                                 // perfect\r
261                                 spawn_allbad = FALSE;\r
262 \r
263                                 if(spotlistend)\r
264                                         spotlistend.chain = spot;\r
265                                 spotlistend = spot;\r
266                                 if(!spotlist)\r
267                                         spotlist = spot;\r
268 \r
269                                 /*\r
270                                 if(teamcheck)\r
271                                 if(spot.team != teamcheck)\r
272                                         error("invalid spawn added");\r
273 \r
274                                 print("added ", etos(spot), "\n");\r
275                                 */\r
276                         }\r
277                 }\r
278         }\r
279         if(spotlistend)\r
280                 spotlistend.chain = world;\r
281 \r
282         /*\r
283                 entity e;\r
284                 if(teamcheck)\r
285                         for(e = spotlist; e; e = e.chain)\r
286                         {\r
287                                 print("seen ", etos(e), "\n");\r
288                                 if(e.team != teamcheck)\r
289                                         error("invalid spawn found");\r
290                         }\r
291         */\r
292 \r
293         return spotlist;\r
294 }\r
295 \r
296 entity Spawn_WeightedPoint(entity firstspot, float lower, float upper, float exponent)\r
297 {\r
298         // weight of a point: bound(lower, mindisttoplayer, upper)^exponent\r
299         // multiplied by spot.cnt (useful if you distribute many spawnpoints in a small area)\r
300         local entity spot;\r
301 \r
302         RandomSelection_Init();\r
303         for(spot = firstspot; spot; spot = spot.chain)\r
304                 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);\r
305 \r
306         return RandomSelection_chosen_ent;\r
307 }\r
308 \r
309 /*\r
310 =============\r
311 SelectSpawnPoint\r
312 \r
313 Finds a point to respawn\r
314 =============\r
315 */\r
316 entity SelectSpawnPoint (float anypoint)\r
317 {\r
318         local float teamcheck;\r
319         local entity firstspot_new;\r
320         local entity spot, firstspot, playerlist;\r
321 \r
322         spot = find (world, classname, "testplayerstart");\r
323         if (spot)\r
324                 return spot;\r
325 \r
326         teamcheck = 0;\r
327 \r
328         if(!anypoint && have_team_spawns > 0)\r
329                 teamcheck = self.team;\r
330 \r
331         // get the list of players\r
332         playerlist = findchain(classname, "player");\r
333         // get the entire list of spots\r
334         firstspot = findchain(classname, "info_player_deathmatch");\r
335         // filter out the bad ones\r
336         // (note this returns the original list if none survived)\r
337         if(anypoint)\r
338         {\r
339                 spot = Spawn_WeightedPoint(firstspot, 1, 1, 1);\r
340         }\r
341         else\r
342         {\r
343                 firstspot_new = Spawn_FilterOutBadSpots(firstspot, playerlist, 100, teamcheck, anypoint);\r
344                 if(!firstspot_new)\r
345                         firstspot_new = Spawn_FilterOutBadSpots(firstspot, playerlist, -1, teamcheck, anypoint);\r
346                 firstspot = firstspot_new;\r
347 \r
348                 // there is 50/50 chance of choosing a random spot or the furthest spot\r
349                 // (this means that roughly every other spawn will be furthest, so you\r
350                 // usually won't get fragged at spawn twice in a row)\r
351                 if (arena_roundbased && !g_ca)\r
352                 {\r
353                         firstspot_new = Spawn_FilterOutBadSpots(firstspot, playerlist, 800, teamcheck, anypoint);\r
354                         if(firstspot_new)\r
355                                 firstspot = firstspot_new;\r
356                         spot = Spawn_WeightedPoint(firstspot, 1, 1, 1);\r
357                 }\r
358                 else if (random() > cvar("g_spawn_furthest"))\r
359                         spot = Spawn_WeightedPoint(firstspot, 1, 1, 1);\r
360                 else\r
361                         spot = Spawn_WeightedPoint(firstspot, 1, 5000, 5); // chooses a far far away spawnpoint\r
362         }\r
363 \r
364         if(cvar("spawn_debugview"))\r
365         {\r
366                 print("spot mindistance: ", vtos(spot.spawnpoint_score), "\n");\r
367 \r
368                 entity e;\r
369                 if(teamcheck)\r
370                         for(e = firstspot; e; e = e.chain)\r
371                                 if(e.team != teamcheck)\r
372                                         error("invalid spawn found");\r
373         }\r
374 \r
375         if (!spot)\r
376         {\r
377                 if(cvar("spawn_debug"))\r
378                         GotoNextMap();\r
379                 else\r
380                 {\r
381                         if(some_spawn_has_been_used)\r
382                                 return world; // team can't spawn any more, because of actions of other team\r
383                         else\r
384                                 error("Cannot find a spawn point - please fix the map!");\r
385                 }\r
386         }\r
387 \r
388         return spot;\r
389 }\r
390 \r
391 /*\r
392 =============\r
393 CheckPlayerModel\r
394 \r
395 Checks if the argument string can be a valid playermodel.\r
396 Returns a valid one in doubt.\r
397 =============\r
398 */\r
399 string FallbackPlayerModel = "models/player/fox.iqm";\r
400 string CheckPlayerModel(string plyermodel) {\r
401         if(strlen(plyermodel) < 4)\r
402                 return FallbackPlayerModel;\r
403         if( substring(plyermodel,0,14) != "models/player/")\r
404                 return FallbackPlayerModel;\r
405         else if(cvar("sv_servermodelsonly"))\r
406         {\r
407                 if(substring(plyermodel,-4,4) != ".zym")\r
408                 if(substring(plyermodel,-4,4) != ".dpm")\r
409                 if(substring(plyermodel,-4,4) != ".iqm")\r
410                 if(substring(plyermodel,-4,4) != ".md3")\r
411                 if(substring(plyermodel,-4,4) != ".psk")\r
412                         return FallbackPlayerModel;\r
413                 if(plyermodel != strtolower(plyermodel))\r
414                         return FallbackPlayerModel;\r
415                 if(!fexists(plyermodel))\r
416                         return FallbackPlayerModel;\r
417         }\r
418         return plyermodel;\r
419 }\r
420 \r
421 void setmodel_apply(string modelname, float reset_anims)\r
422 {\r
423         precache_model(modelname);\r
424         setmodel(self, modelname); // players have high precision\r
425         if(reset_anims)\r
426                 player_setupanimsformodel();\r
427 }\r
428 \r
429 string setmodel_state()\r
430 {\r
431         // set the proper belly model depending on how full we are\r
432         string newmodel_name, newmodel_extension, applymodel;\r
433 \r
434         // 4 is the extension length\r
435         newmodel_name = substring(self.playermodel, 0, strlen(self.playermodel) - 4);\r
436         newmodel_extension = substring(self.playermodel, strlen(self.playermodel) - 4, 4);\r
437 \r
438         float vore_state;\r
439         if(self.stomach_load > self.stomach_maxload * 0.75)\r
440                 vore_state = 3;\r
441         else if(self.stomach_load > self.stomach_maxload * 0.5)\r
442                 vore_state = 2;\r
443         else if(self.stomach_load > self.stomach_maxload * 0.25)\r
444                 vore_state = 1;\r
445 \r
446         if(vore_state)\r
447                 applymodel = strcat(newmodel_name, "_state", ftos(vore_state), newmodel_extension);\r
448         else\r
449                 applymodel = self.playermodel;\r
450 \r
451         return applymodel;\r
452 }\r
453 \r
454 /*\r
455 =============\r
456 Client_customizeentityforclient\r
457 =============\r
458 */\r
459 void Client_setmodel(string applymodel)\r
460 {\r
461         local vector m1, m2;\r
462         if(self.classname != "player") // prevent some bugs\r
463                 return;\r
464         if(applymodel == self.model || self.spectatee_status) // no change to apply\r
465                 return;\r
466 \r
467         applymodel = CheckPlayerModel(applymodel); // this is never "", so no endless loop\r
468         m1 = self.mins;\r
469         m2 = self.maxs;\r
470         setmodel_apply(applymodel, FALSE);\r
471         setsize (self, m1, m2);\r
472 }\r
473 \r
474 void Client_uncustomizeentityforclient()\r
475 {\r
476         self.skin = self.skinindex;\r
477 }\r
478 \r
479 float Client_customizeentityforclient()\r
480 {\r
481         entity modelsource;\r
482         string stomachmodel;\r
483 \r
484         if(self.modelindex == 0)\r
485                 return TRUE;\r
486 \r
487         // forcemodel stuff\r
488 \r
489 #ifdef PROFILING\r
490         float t0;\r
491         t0 = gettime(GETTIME_HIRES); // reference\r
492 #endif\r
493 \r
494         modelsource = self;\r
495 \r
496 #ifdef ALLOW_FORCEMODELS\r
497         if(other.cvar_cl_forceplayermodelsfromvoretournament)\r
498                 modelsource = other;\r
499         if(other.cvar_cl_forceplayermodels && sv_clforceplayermodels)\r
500                 modelsource = other;\r
501 #endif\r
502 \r
503         self.skin = modelsource.skinindex;\r
504 \r
505 #if 0\r
506         if(modelsource == self)\r
507                 self.skin = modelsource.skinindex;\r
508         else\r
509                 self.skin = mod(modelsource.skinindex, 3); // forbid the fbskins as forced skins\r
510 #endif\r
511 \r
512         // self: me\r
513         // other: the player viewing me\r
514 \r
515 #ifdef PROFILING\r
516         float t1;\r
517         t1 = gettime(GETTIME_HIRES); // reference\r
518         client_cefc_accumulator += (t1 - t0);\r
519 #endif\r
520 \r
521         // now change the predator's player model into a stomach model for the prey\r
522         // in other words, when a player is swallowed by another player, the predator becomes an inward stomach model so the prey can see theirself in the stomach\r
523         // this is only visible to the prey however, otherwise players would appear as a floating stomach to everyone (ewww)\r
524         stomachmodel = strcat(substring(self.playermodel, 0, strlen(self.playermodel) - 4), "_stomach.iqm"); // 4 is the extension length\r
525 \r
526         float chase;\r
527         chase = other.cvar_chase_active;\r
528 \r
529         if(other.spectatee_status && other.spectatee_status == num_for_edict(other.enemy))\r
530                 other = other.enemy; // also do this for the player we are spectating\r
531 \r
532         // don't do this if we have chase_active enabled, as we'd be seeing a floating stomach from third person view\r
533         if not(chase || other.classname == "observer") // the observer check prevents a bug\r
534         if(other.predator == self)\r
535         {\r
536                 Client_setmodel(stomachmodel);\r
537                 self.angles_x = self.angles_z = 0; // don't apply player leaning to stomach models\r
538                 self.effects |= EF_NODEPTHTEST; // don't hide behind walls\r
539                 self.alpha = other.cvar_cl_vore_stomachmodel;\r
540                 return TRUE;\r
541         }\r
542 \r
543         Client_setmodel(setmodel_state());\r
544         if(cvar("g_nodepthtestplayers"))\r
545                 self.effects |= EF_NODEPTHTEST;\r
546         else\r
547                 self.effects &~= EF_NODEPTHTEST;\r
548         if(cvar("g_fullbrightplayers"))\r
549                 self.effects |= EF_FULLBRIGHT;\r
550 \r
551         if not(self.stat_eaten)\r
552         {\r
553                 self.alpha = default_player_alpha;\r
554                 if(cvar("g_vore_swallowfade"))\r
555                 if not(other == self && !chase)\r
556                         self.alpha *= 1 - self.swallow_progress_prey; // fade players out as they are swallowed, to better simulate their disappearing\r
557         }\r
558         else if(cvar("g_vore_neighborprey_distance") && self.predator == other.predator && !(chase || other.classname == "observer"))\r
559         {\r
560                 self.alpha = default_player_alpha; // allow seeing neighboring prey\r
561                 self.effects |= EF_NODEPTHTEST; // don't hide behind the stomach's own EF_NODEPTHTEST\r
562         }\r
563         else\r
564                 self.alpha = -1; // hide prey\r
565         return TRUE;\r
566 }\r
567 \r
568 /*\r
569 =============\r
570 PutObserverInServer\r
571 \r
572 putting a client as observer in the server\r
573 =============\r
574 */\r
575 void FixPlayermodel();\r
576 void PutObserverInServer (void)\r
577 {\r
578         entity  spot;\r
579 \r
580         race_PreSpawnObserver();\r
581 \r
582         spot = SelectSpawnPoint (TRUE);\r
583         if(!spot)\r
584                 error("No spawnpoints for observers?!?\n");\r
585         RemoveGrabber(self); // Wazat's Grabber\r
586 \r
587         if(clienttype(self) == CLIENTTYPE_REAL)\r
588         {\r
589                 msg_entity = self;\r
590                 WriteByte(MSG_ONE, SVC_SETVIEW);\r
591                 WriteEntity(MSG_ONE, self);\r
592         }\r
593 \r
594         Vore_Disconnect(TRUE);\r
595 \r
596         kh_Key_DropAll(self, TRUE);\r
597 \r
598         if(self.flagcarried)\r
599                 DropFlag(self.flagcarried, world, world);\r
600 \r
601         WaypointSprite_PlayerDead();\r
602 \r
603         if not(g_ca)  // don't reset teams when moving a ca player to the spectators\r
604                 self.team = -1;  // move this as it is needed to log the player spectating in eventlog\r
605 \r
606         if(self.killcount != -666) {\r
607                 if(g_lms) {\r
608                         if(PlayerScore_Add(self, SP_LMS_RANK, 0) > 0)\r
609                                 bprint ("^4", self.netname, "^4 has no more lives left\n");\r
610                         else\r
611                                 bprint ("^4", self.netname, "^4 is spectating now\n"); // TODO turn this into a proper forfeit?\r
612                 } else\r
613                         bprint ("^4", self.netname, "^4 is spectating now\n");\r
614 \r
615                 if(self.just_joined == FALSE) {\r
616                         LogTeamchange(self.playerid, -1, 4);\r
617                 } else\r
618                         self.just_joined = FALSE;\r
619         }\r
620 \r
621         PlayerScore_Clear(self); // clear scores when needed\r
622 \r
623         self.spectatortime = time;\r
624 \r
625         self.classname = "observer";\r
626         self.iscreature = FALSE;\r
627         self.health = -666;\r
628         self.takedamage = DAMAGE_NO;\r
629         self.solid = SOLID_NOT;\r
630         self.movetype = MOVETYPE_FLY_WORLDONLY; // user preference is controlled by playerprethink\r
631         self.flags = FL_CLIENT | FL_NOTARGET;\r
632         self.armorvalue = 666;\r
633         self.effects = 0;\r
634         self.armorvalue = cvar("g_balance_armor_start");\r
635         self.pauserotarmor_finished = 0;\r
636         self.pauserothealth_finished = 0;\r
637         self.pauseregenhealth_finished = 0;\r
638         self.pauseregenarmor_finished = 0;\r
639         self.damageforcescale = 0;\r
640         self.death_time = 0;\r
641         self.dead_frame = 0;\r
642         self.alpha = 0;\r
643         self.scale = 0;\r
644         self.fade_time = 0;\r
645         self.pain_frame = 0;\r
646         self.pain_finished = 0;\r
647         self.strength_finished = 0;\r
648         self.invincible_finished = 0;\r
649         self.pushltime = 0;\r
650         self.think = SUB_Null;\r
651         self.nextthink = 0;\r
652         self.grabber_time = 0;\r
653         self.deadflag = DEAD_NO;\r
654         self.angles = spot.angles;\r
655         self.angles_z = 0;\r
656         self.fixangle = TRUE;\r
657         self.crouch = FALSE;\r
658 \r
659         self.view_ofs = '0 0 0'; // so that your view doesn't go into the ceiling with MOVETYPE_FLY_WORLDONLY, previously "PL_VIEW_OFS"\r
660         setorigin (self, spot.origin);\r
661         setsize (self, PL_CROUCH_MIN, PL_CROUCH_MAX); // give the spectator some space between walls for MOVETYPE_FLY_WORLDONLY\r
662         self.prevorigin = self.origin;\r
663         self.items = 0;\r
664         self.weapons = 0;\r
665         self.model = "";\r
666         FixPlayermodel();\r
667         self.model = "";\r
668         self.modelindex = 0;\r
669         self.weapon = 0;\r
670         self.weaponmodel = "";\r
671         self.weaponentity = world;\r
672         self.exteriorweaponentity = world;\r
673         self.killcount = -666;\r
674         self.velocity = '0 0 0';\r
675         self.avelocity = '0 0 0';\r
676         self.punchangle = '0 0 0';\r
677         self.punchvector = '0 0 0';\r
678         self.oldvelocity = self.velocity;\r
679         self.fire_endtime = -1;\r
680 \r
681         SetCustomizer(self, Client_customizeentityforclient, Client_uncustomizeentityforclient);\r
682 \r
683         if(g_arena)\r
684         {\r
685                 if(self.version_mismatch)\r
686                 {\r
687                         Spawnqueue_Unmark(self);\r
688                         Spawnqueue_Remove(self);\r
689                 }\r
690                 else\r
691                 {\r
692                         Spawnqueue_Insert(self);\r
693                 }\r
694         }\r
695         else if(g_lms)\r
696         {\r
697                 // Only if the player cannot play at all\r
698                 if(PlayerScore_Add(self, SP_LMS_RANK, 0) == 666)\r
699                         self.frags = FRAGS_SPECTATOR;\r
700                 else\r
701                         self.frags = FRAGS_LMS_LOSER;\r
702         }\r
703         else\r
704                 self.frags = FRAGS_SPECTATOR;\r
705 }\r
706 \r
707 float RestrictSkin(float s)\r
708 {\r
709         if(!teams_matter)\r
710                 return s;\r
711         if(s == 6)\r
712                 return 6;\r
713         return mod(s, 3);\r
714 }\r
715 \r
716 void FixPlayermodel()\r
717 {\r
718         local string defaultmodel;\r
719         local float defaultskin, chmdl, oldskin;\r
720         local vector m1, m2;\r
721 \r
722         defaultmodel = "";\r
723 \r
724         if(cvar("sv_defaultcharacter") == 1) {\r
725                 defaultskin = 0;\r
726 \r
727                 if(teams_matter)\r
728                 {\r
729                         string s;\r
730                         s = Team_ColorNameLowerCase(self.team);\r
731                         if(s != "neutral")\r
732                         {\r
733                                 defaultmodel = cvar_string(strcat("sv_defaultplayermodel_", s));\r
734                                 defaultskin = cvar(strcat("sv_defaultplayerskin_", s));\r
735                         }\r
736                 }\r
737 \r
738                 if(defaultmodel == "")\r
739                 {\r
740                         defaultmodel = cvar_string("sv_defaultplayermodel");\r
741                         defaultskin = cvar("sv_defaultplayerskin");\r
742                 }\r
743         }\r
744 \r
745         if(self.modelindex == 0 && self.deadflag == DEAD_NO)\r
746         {\r
747                 if(self.model != "")\r
748                         bprint("\{1}^1Player ", self.netname, "^1 has a zero modelindex, trying to fix...\n");\r
749                 self.model = ""; // force the != checks to return true\r
750         }\r
751 \r
752         if(defaultmodel != "")\r
753         {\r
754                 if (defaultmodel != self.model)\r
755                 {\r
756                         m1 = self.mins;\r
757                         m2 = self.maxs;\r
758                         setmodel_apply (defaultmodel, TRUE);\r
759                         setsize (self, m1, m2);\r
760                         chmdl = TRUE;\r
761                 }\r
762 \r
763                 oldskin = self.skinindex;\r
764                 self.skinindex = defaultskin;\r
765         } else {\r
766                 if (self.model == "")\r
767                 {\r
768                         self.playermodel = CheckPlayerModel(self.playermodel); // this is never "", so no endless loop\r
769                         m1 = self.mins;\r
770                         m2 = self.maxs;\r
771                         setmodel_apply (self.playermodel, TRUE);\r
772                         setsize (self, m1, m2);\r
773                         chmdl = TRUE;\r
774                 }\r
775                 // update player sounds if we changed model\r
776                 if(self.model == self.playermodel) // don't apply sounds for other models (like the player stomach state models)\r
777                         UpdatePlayerSounds();\r
778 \r
779                 oldskin = self.skinindex;\r
780                 self.skinindex = RestrictSkin(stof(self.playerskin));\r
781         }\r
782 \r
783         if(chmdl || oldskin != self.skinindex)\r
784                 self.species = player_getspecies(); // model or skin has changed\r
785 \r
786         if(!teams_matter)\r
787                 if(strlen(cvar_string("sv_defaultplayercolors")))\r
788                         if(self.clientcolors != cvar("sv_defaultplayercolors"))\r
789                                 setcolor(self, cvar("sv_defaultplayercolors"));\r
790 }\r
791 \r
792 void PlayerTouchExplode(entity p1, entity p2)\r
793 {\r
794         vector org;\r
795         org = (p1.origin + p2.origin) * 0.5;\r
796         org_z += (p1.mins_z + p2.mins_z) * 0.5;\r
797 \r
798         te_explosion(org);\r
799 \r
800         entity e;\r
801         e = spawn();\r
802         setorigin(e, org);\r
803         RadiusDamage(e, world, g_touchexplode_damage, g_touchexplode_edgedamage, g_touchexplode_radius, world, g_touchexplode_force, DEATH_TOUCHEXPLODE, world);\r
804         remove(e);\r
805 }\r
806 \r
807 /*\r
808 =============\r
809 PutClientInServer\r
810 \r
811 Called when a client spawns in the server\r
812 =============\r
813 */\r
814 //void() ctf_playerchanged;\r
815 void PutClientInServer (void)\r
816 {\r
817         entity e;\r
818 \r
819         if(clienttype(self) == CLIENTTYPE_BOT)\r
820         {\r
821                 self.classname = "player";\r
822         }\r
823         else if(clienttype(self) == CLIENTTYPE_REAL)\r
824         {\r
825                 msg_entity = self;\r
826                 WriteByte(MSG_ONE, SVC_SETVIEW);\r
827                 WriteEntity(MSG_ONE, self);\r
828         }\r
829 \r
830         // player is dead and becomes observer\r
831         // FIXME fix LMS scoring for new system\r
832         if(g_lms)\r
833         {\r
834                 if(PlayerScore_Add(self, SP_LMS_RANK, 0) > 0)\r
835                         self.classname = "observer";\r
836         }\r
837 \r
838         if(g_arena || (g_ca && !allowed_to_spawn))\r
839         if(!self.spawned)\r
840                 self.classname = "observer";\r
841 \r
842         if(gameover)\r
843                 self.classname = "observer";\r
844 \r
845         if(self.classname == "player" && (!g_ca || (g_ca && allowed_to_spawn))) {\r
846                 entity spot, oldself;\r
847                 float j;\r
848 \r
849                 if(self.team < 0)\r
850                         JoinBestTeam(self, FALSE, TRUE);\r
851 \r
852                 race_PreSpawn();\r
853 \r
854                 spot = SelectSpawnPoint (FALSE);\r
855                 if(!spot)\r
856                 {\r
857                         centerprint(self, "Sorry, no spawnpoints available!\nHope your team can fix it...");\r
858                         return; // spawn failed\r
859                 }\r
860 \r
861                 RemoveGrabber(self); // Wazat's Grabber\r
862 \r
863                 Vore_Disconnect(TRUE);\r
864                 self.swallow_progress_pred = self.swallow_progress_prey = 0;\r
865 \r
866                 self.classname = "player";\r
867                 self.wasplayer = TRUE;\r
868                 self.iscreature = TRUE;\r
869                 self.movetype = MOVETYPE_WALK;\r
870                 if(cvar("g_player_colisions"))\r
871                         self.solid = SOLID_SLIDEBOX;\r
872                 else\r
873                         self.solid = SOLID_CORPSE;\r
874                 self.dphitcontentsmask = DPCONTENTS_BODY | DPCONTENTS_SOLID;\r
875                 if(cvar("g_playerclip_collisions"))\r
876                         self.dphitcontentsmask |= DPCONTENTS_PLAYERCLIP;\r
877                 if(clienttype(self) == CLIENTTYPE_BOT && cvar("g_botclip_collisions"))\r
878                         self.dphitcontentsmask |= DPCONTENTS_BOTCLIP;\r
879                 self.frags = FRAGS_PLAYER;\r
880                 if(independent_players)\r
881                         MAKE_INDEPENDENT_PLAYER(self);\r
882                 self.flags = FL_CLIENT;\r
883                 self.takedamage = DAMAGE_AIM;\r
884                 self.effects = 0;\r
885                 self.air_finished = time + 12;\r
886                 self.dmg = 2;\r
887 \r
888                 if(inWarmupStage)\r
889                 {\r
890                         self.ammo_fuel = warmup_start_ammo_fuel;\r
891                         self.health = warmup_start_health;\r
892                         self.armorvalue = warmup_start_armorvalue;\r
893                         self.weapons = warmup_start_weapons;\r
894                 }\r
895                 else\r
896                 {\r
897                         self.ammo_fuel = start_ammo_fuel;\r
898                         self.health = start_health;\r
899                         self.armorvalue = start_armorvalue;\r
900                         self.weapons = start_weapons;\r
901                 }\r
902 \r
903                 self.items = start_items;\r
904                 self.switchweapon = w_getbestweapon(self);\r
905                 self.cnt = self.switchweapon;\r
906                 self.weapon = 0;\r
907 \r
908                 self.spawnshieldtime = time + cvar("g_spawnshieldtime");\r
909                 self.pauserotarmor_finished = time + cvar("g_balance_pause_armor_rot_spawn");\r
910                 self.pauserothealth_finished = time + cvar("g_balance_pause_health_rot_spawn");\r
911                 self.pauserotfuel_finished = time + cvar("g_balance_pause_fuel_rot_spawn");\r
912                 self.pauseregenhealth_finished = time + cvar("g_balance_pause_health_regen_spawn");\r
913                 self.pauseregenarmor_finished = time + cvar("g_balance_pause_armor_regen_spawn");\r
914                 //extend the pause of rotting if client was reset at the beginning of the countdown\r
915                 if(!cvar("sv_ready_restart_after_countdown") && time < game_starttime) { // TODO why is this cvar NOTted?\r
916                         self.spawnshieldtime += game_starttime - time;\r
917                         self.pauserotarmor_finished += game_starttime - time;\r
918                         self.pauserothealth_finished += game_starttime - time;\r
919                         self.pauseregenhealth_finished += game_starttime - time;\r
920                         self.pauseregenarmor_finished += game_starttime - time;\r
921                 }\r
922                 self.damageforcescale = 2;\r
923                 self.death_time = 0;\r
924                 self.dead_frame = 0;\r
925                 self.alpha = 0;\r
926                 self.scale = 0;\r
927                 self.fade_time = 0;\r
928                 self.pain_frame = 0;\r
929                 self.pain_finished = 0;\r
930                 self.strength_finished = 0;\r
931                 self.invincible_finished = 0;\r
932                 self.pushltime = 0;\r
933                 // players have no think function\r
934                 self.think = SUB_Null;\r
935                 self.nextthink = 0;\r
936                 self.grabber_time = 0;\r
937                 self.dmg_team = 0;\r
938 \r
939                 self.deadflag = DEAD_NO;\r
940                 self.stomach_load = 0;\r
941                 self.angles = spot.angles;\r
942 \r
943                 self.angles_z = 0; // never spawn tilted even if the spot says to\r
944                 self.fixangle = TRUE; // turn this way immediately\r
945                 self.velocity = '0 0 0';\r
946                 self.avelocity = '0 0 0';\r
947                 self.punchangle = '0 0 0';\r
948                 self.punchvector = '0 0 0';\r
949                 self.oldvelocity = self.velocity;\r
950                 self.fire_endtime = -1;\r
951 \r
952                 msg_entity = self;\r
953                 WRITESPECTATABLE_MSG_ONE({\r
954                         WriteByte(MSG_ONE, SVC_TEMPENTITY);\r
955                         WriteByte(MSG_ONE, TE_CSQC_SPAWN);\r
956                 });\r
957 \r
958                 SetCustomizer(self, Client_customizeentityforclient, Client_uncustomizeentityforclient);\r
959 \r
960                 self.model = "";\r
961                 FixPlayermodel();\r
962 \r
963                 self.crouch = FALSE;\r
964                 self.view_ofs = PL_VIEW_OFS;\r
965                 setsize (self, PL_MIN, PL_MAX);\r
966                 self.spawnorigin = spot.origin;\r
967                 setorigin (self, spot.origin + '0 0 1' * (1 - self.mins_z - 24));\r
968                 // don't reset back to last position, even if new position is stuck in solid\r
969                 self.oldorigin = self.origin;\r
970                 self.prevorigin = self.origin;\r
971                 self.lastteleporttime = time; // prevent insane speeds due to changing origin\r
972 \r
973                 if(g_arena)\r
974                 {\r
975                         Spawnqueue_Remove(self);\r
976                         Spawnqueue_Mark(self);\r
977                 }\r
978 \r
979                 else if(g_ca)\r
980                         self.caplayer = 1;\r
981 \r
982                 self.event_damage = PlayerDamage;\r
983 \r
984                 self.bot_attack = TRUE;\r
985 \r
986                 self.statdraintime = time + 5;\r
987                 self.BUTTON_ATCK = self.BUTTON_JUMP = self.BUTTON_ATCK2 = 0;\r
988 \r
989                 if(self.killcount == -666) {\r
990                         PlayerScore_Clear(self);\r
991                         self.killcount = 0;\r
992                 }\r
993 \r
994                 CL_SpawnWeaponentity();\r
995                 self.alpha = default_player_alpha;\r
996                 self.colormod = '1 1 1' * cvar("g_player_brightness");\r
997                 self.exteriorweaponentity.alpha = default_weapon_alpha;\r
998 \r
999                 self.lms_nextcheck = time + cvar("g_lms_campcheck_interval")*2;\r
1000                 self.lms_traveled_distance = 0;\r
1001                 self.speedrunning = FALSE;\r
1002 \r
1003                 race_PostSpawn(spot);\r
1004 \r
1005                 if(cvar("spawn_debug"))\r
1006                 {\r
1007                         sprint(self, strcat("spawnpoint origin:  ", vtos(spot.origin), "\n"));\r
1008                         remove(spot);   // usefull for checking if there are spawnpoints, that let drop through the floor\r
1009                 }\r
1010 \r
1011                 //stuffcmd(self, "chase_active 0");\r
1012                 //stuffcmd(self, "set viewsize $tmpviewsize \n");\r
1013 \r
1014                 if (cvar("g_spawnsound"))\r
1015                         sound (self, CHAN_TRIGGER, "misc/spawn.wav", VOL_BASE, ATTN_NORM);\r
1016                 pointparticles(particleeffectnum("player_respawn"), self.origin, '0 0 0', 1);\r
1017 \r
1018                 if(g_assault) {\r
1019                         if(self.team == assault_attacker_team)\r
1020                                 centerprint(self, "You are attacking!");\r
1021                         else\r
1022                                 centerprint(self, "You are defending!");\r
1023                 }\r
1024 \r
1025                 target_voicescript_clear(self);\r
1026 \r
1027                 // reset fields the weapons may use\r
1028         for (j = WEP_FIRST; j <= WEP_LAST; ++j)\r
1029                 {\r
1030             weapon_action(j, WR_RESETPLAYER);\r
1031 \r
1032                         // all weapons must be fully loaded when we spawn\r
1033                         e = get_weaponinfo(j);\r
1034                         if(e.spawnflags & WEP_FLAG_RELOADABLE) // prevent accessing undefined cvars\r
1035                                 self.(weapon_load[j]) = cvar(strcat("g_balance_", e.netname, "_reload_ammo"));\r
1036                 }\r
1037 \r
1038                 oldself = self;\r
1039                 self = spot;\r
1040                         activator = oldself;\r
1041                                 SUB_UseTargets();\r
1042                         activator = world;\r
1043                 self = oldself;\r
1044         } else if(self.classname == "observer" || (g_ca && !allowed_to_spawn)) {\r
1045                 PutObserverInServer ();\r
1046         }\r
1047 \r
1048         //if(g_ctf)\r
1049         //      ctf_playerchanged();\r
1050 }\r
1051 \r
1052 float ClientInit_SendEntity(entity to, float sf)\r
1053 {\r
1054         WriteByte(MSG_ENTITY, ENT_CLIENT_INIT);\r
1055         WriteCoord(MSG_ENTITY, grabber_shotorigin_x);\r
1056         WriteCoord(MSG_ENTITY, grabber_shotorigin_y);\r
1057         WriteCoord(MSG_ENTITY, grabber_shotorigin_z);\r
1058 \r
1059         if(sv_foginterval && world.fog != "")\r
1060                 WriteString(MSG_ENTITY, world.fog);\r
1061         else\r
1062                 WriteString(MSG_ENTITY, "");\r
1063         WriteShort(MSG_ENTITY, cvar("g_campaign"));\r
1064         WriteByte(MSG_ENTITY, cvar("g_balance_armor_blockpercent") * 255.0);\r
1065         WriteByte(MSG_ENTITY, cvar("g_balance_weaponswitchdelay") * 255.0);\r
1066 \r
1067         WriteShort(MSG_ENTITY, cvar("g_vore"));\r
1068         if(cvar("g_healthsize"))\r
1069                 WriteShort(MSG_ENTITY, cvar("g_healthsize_center"));\r
1070         else\r
1071                 WriteShort(MSG_ENTITY, -1); // healthsize is disabled\r
1072         WriteShort(MSG_ENTITY, cvar("g_healthsize_min"));\r
1073         WriteShort(MSG_ENTITY, cvar("g_healthsize_max"));\r
1074 \r
1075         // tell the client if this server uses armor\r
1076         float armor_max;\r
1077         if(cvar("g_balance_armor_start") || (cvar("g_lms") && cvar("g_lms_start_armor")) /*|| (inWarmupStage && cvar("g_warmup_start_armor"))*/ || cvar("g_balance_armor_regen") || cvar("g_balance_armor_regenlinear"))\r
1078                 armor_max = cvar("g_balance_armor_limit");\r
1079         WriteCoord(MSG_ENTITY, armor_max);\r
1080 \r
1081         float teamheal_max;\r
1082         if(cvar("g_vore") && cvar("g_vore_teamvore") && cvar("g_balance_vore_teamheal"))\r
1083                 teamheal_max = cvar("g_balance_vore_teamheal_stable");\r
1084         WriteCoord(MSG_ENTITY, teamheal_max);\r
1085 \r
1086         WriteShort(MSG_ENTITY, cvar("g_power"));\r
1087         WriteShort(MSG_ENTITY, cvar("g_power_reboot"));\r
1088         WriteByte(MSG_ENTITY, cvar("g_power_reboot_spawn"));\r
1089 \r
1090         return TRUE;\r
1091 }\r
1092 \r
1093 void ClientInit_Spawn()\r
1094 {\r
1095         Net_LinkEntity(spawn(), FALSE, 0, ClientInit_SendEntity);\r
1096 }\r
1097 \r
1098 /*\r
1099 =============\r
1100 SetNewParms\r
1101 =============\r
1102 */\r
1103 void SetNewParms (void)\r
1104 {\r
1105         // initialize parms for a new player\r
1106         parm1 = -(86400 * 366);\r
1107 }\r
1108 \r
1109 /*\r
1110 =============\r
1111 SetChangeParms\r
1112 =============\r
1113 */\r
1114 void SetChangeParms (void)\r
1115 {\r
1116         // save parms for level change\r
1117         parm1 = self.parm_idlesince - time;\r
1118 }\r
1119 \r
1120 /*\r
1121 =============\r
1122 DecodeLevelParms\r
1123 =============\r
1124 */\r
1125 void DecodeLevelParms (void)\r
1126 {\r
1127         // load parms\r
1128         self.parm_idlesince = parm1;\r
1129         if(self.parm_idlesince == -(86400 * 366))\r
1130                 self.parm_idlesince = time;\r
1131 \r
1132         // whatever happens, allow 60 seconds of idling directly after connect for map loading\r
1133         self.parm_idlesince = max(self.parm_idlesince, time - sv_maxidle + 60);\r
1134 }\r
1135 \r
1136 /*\r
1137 =============\r
1138 ClientKill\r
1139 \r
1140 Called when a client types 'kill' in the console\r
1141 =============\r
1142 */\r
1143 \r
1144 .float clientkill_nexttime;\r
1145 void ClientKill_Now_TeamChange()\r
1146 {\r
1147         if(self.killindicator_teamchange == -1)\r
1148         {\r
1149                 self.team = -1;\r
1150                 JoinBestTeam( self, FALSE, FALSE );\r
1151         }\r
1152         else if(self.killindicator_teamchange == -2)\r
1153         {\r
1154                 if(g_ca)\r
1155                         self.caplayer = 0;\r
1156                 if(blockSpectators)\r
1157                         sprint(self, strcat("^7You have to become a player within the next ", ftos(cvar("g_maxplayers_spectator_blocktime")), " seconds, otherwise you will be kicked, because spectators aren't allowed at this time!\n"));\r
1158                 PutObserverInServer();\r
1159         }\r
1160         else\r
1161                 SV_ChangeTeam(self.killindicator_teamchange - 1);\r
1162 }\r
1163 \r
1164 void ClientKill_Now()\r
1165 {       \r
1166         if(self.killindicator && !wasfreed(self.killindicator))\r
1167         remove(self.killindicator);\r
1168         \r
1169         self.killindicator = world;\r
1170 \r
1171         if(self.killindicator_teamchange)\r
1172                 ClientKill_Now_TeamChange();\r
1173 \r
1174         // in any case:\r
1175         Damage(self, self, self, 100000, DEATH_KILL, self.origin, '0 0 0');\r
1176 \r
1177         // now I am sure the player IS dead\r
1178 }\r
1179 void KillIndicator_Think()\r
1180 {\r
1181         if (!self.owner.modelindex)\r
1182         {\r
1183                 self.owner.killindicator = world;\r
1184                 remove(self);\r
1185                 return;\r
1186         }\r
1187 \r
1188         if(self.cnt <= 0)\r
1189         {\r
1190                 self = self.owner;\r
1191                 ClientKill_Now(); // no oldself needed\r
1192                 return;\r
1193         }\r
1194     else if(g_cts && self.health == 1) // health == 1 means that it's silent\r
1195     {\r
1196         self.nextthink = time + 1;\r
1197         self.cnt -= 1;\r
1198     }\r
1199         else\r
1200         {\r
1201                 if(self.cnt <= 10)\r
1202                         setmodel(self, strcat("models/sprites/", ftos(self.cnt), ".spr32"));\r
1203                 if(clienttype(self.owner) == CLIENTTYPE_REAL)\r
1204                 {\r
1205                         if(self.cnt <= 10)\r
1206                                 AnnounceTo(self.owner, strcat(ftos(self.cnt), ""));\r
1207                         if(self.owner.killindicator_teamchange)\r
1208                         {\r
1209                                 if(self.owner.killindicator_teamchange == -1)\r
1210                                         centerprint(self.owner, strcat("Changing team in ", ftos(self.cnt), " seconds"));\r
1211                                 else if(self.owner.killindicator_teamchange == -2)\r
1212                                         centerprint(self.owner, strcat("Spectating in ", ftos(self.cnt), " seconds"));\r
1213                                 else\r
1214                                         centerprint(self.owner, strcat("Changing to ", ColoredTeamName(self.owner.killindicator_teamchange), " in ", ftos(self.cnt), " seconds"));\r
1215                         }\r
1216                         else\r
1217                                 centerprint(self.owner, strcat("^1Suicide in ", ftos(self.cnt), " seconds"));\r
1218                 }\r
1219                 self.nextthink = time + 1;\r
1220                 self.cnt -= 1;\r
1221         }\r
1222 }\r
1223 \r
1224 void ClientKill_TeamChange (float targetteam) // 0 = don't change, -1 = auto, -2 = spec\r
1225 {\r
1226         float killtime;\r
1227         entity e;\r
1228         killtime = cvar("g_balance_kill_delay");\r
1229 \r
1230         if(g_race_qualifying || g_cts)\r
1231                 killtime = 0;\r
1232 \r
1233     if(g_cts && self.killindicator && self.killindicator.health == 1) // self.killindicator.health == 1 means that the kill indicator was spawned by CTS_ClientKill\r
1234     {\r
1235                 remove(self.killindicator);\r
1236                 self.killindicator = world;\r
1237 \r
1238         ClientKill_Now(); // allow instant kill in this case\r
1239         return;\r
1240     }\r
1241 \r
1242         self.killindicator_teamchange = targetteam;\r
1243 \r
1244     if(!self.killindicator)\r
1245         {\r
1246                 if(self.modelindex && self.deadflag == DEAD_NO)\r
1247                 {\r
1248                         killtime = max(killtime, self.clientkill_nexttime - time);\r
1249                         self.clientkill_nexttime = time + killtime + cvar("g_balance_kill_antispam");\r
1250                 }\r
1251 \r
1252                 if(killtime <= 0 || !self.modelindex || self.deadflag != DEAD_NO)\r
1253                 {\r
1254                         ClientKill_Now();\r
1255                 }\r
1256                 else\r
1257                 {\r
1258                         self.killindicator = spawn();\r
1259                         self.killindicator.owner = self;\r
1260                         self.killindicator.scale = 0.5;\r
1261                         setattachment(self.killindicator, self, "");\r
1262                         setorigin(self.killindicator, '0 0 52');\r
1263                         self.killindicator.think = KillIndicator_Think;\r
1264                         self.killindicator.nextthink = time + (self.lip) * 0.05;\r
1265                         self.killindicator.cnt = ceil(killtime);\r
1266                         self.killindicator.count = bound(0, ceil(killtime), 10);\r
1267                         //sprint(self, strcat("^1You'll be dead in ", ftos(self.killindicator.cnt), " seconds\n"));\r
1268 \r
1269                         for(e = world; (e = find(e, classname, "body")) != world; )\r
1270                         {\r
1271                                 if(e.enemy != self)\r
1272                                         continue;\r
1273                                 e.killindicator = spawn();\r
1274                                 e.killindicator.owner = e;\r
1275                                 e.killindicator.scale = 0.5;\r
1276                                 setattachment(e.killindicator, e, "");\r
1277                                 setorigin(e.killindicator, '0 0 52');\r
1278                                 e.killindicator.think = KillIndicator_Think;\r
1279                                 e.killindicator.nextthink = time + (e.lip) * 0.05;\r
1280                                 e.killindicator.cnt = ceil(killtime);\r
1281                         }\r
1282                         self.lip = 0;\r
1283                 }\r
1284         }\r
1285         if(self.killindicator)\r
1286         {\r
1287                 if(targetteam == 0) // just die\r
1288                         self.killindicator.colormod = '0 0 0';\r
1289                 else if(targetteam == -1) // auto\r
1290                         self.killindicator.colormod = '0 1 0';\r
1291                 else if(targetteam == -2) // spectate\r
1292                         self.killindicator.colormod = '0.5 0.5 0.5';\r
1293                 else\r
1294                         self.killindicator.colormod = TeamColor(targetteam);\r
1295         }\r
1296 }\r
1297 \r
1298 void ClientKill (void)\r
1299 {\r
1300         if((g_arena || g_ca) && ((champion && champion.classname == "player" && player_count > 1) || player_count == 1)) // don't allow a kill in this case either\r
1301         {\r
1302                 // do nothing\r
1303         }\r
1304         else\r
1305                 ClientKill_TeamChange(0);\r
1306 }\r
1307 \r
1308 void CTS_ClientKill (entity e) // silent version of ClientKill, used when player finishes a CTS run. Useful to prevent cheating by running back to the start line and starting out with more speed\r
1309 {\r
1310     e.killindicator = spawn();\r
1311     e.killindicator.owner = e;\r
1312     e.killindicator.think = KillIndicator_Think;\r
1313     e.killindicator.nextthink = time + (e.lip) * 0.05;\r
1314     e.killindicator.cnt = ceil(cvar("g_cts_finish_kill_delay"));\r
1315     e.killindicator.health = 1; // this is used to indicate that it should be silent\r
1316     e.lip = 0;\r
1317 }\r
1318 \r
1319 void DoTeamChange(float destteam)\r
1320 {\r
1321         float t, c0;\r
1322         if(!teamplay)\r
1323         {\r
1324                 if(destteam >= 0)\r
1325                         SetPlayerColors(self, destteam);\r
1326                 return;\r
1327         }\r
1328         if(self.classname == "player")\r
1329         if(destteam == -1)\r
1330         {\r
1331                 CheckAllowedTeams(self);\r
1332                 t = FindSmallestTeam(self, TRUE);\r
1333                 switch(self.team)\r
1334                 {\r
1335                         case COLOR_TEAM1: c0 = c1; break;\r
1336                         case COLOR_TEAM2: c0 = c2; break;\r
1337                         case COLOR_TEAM3: c0 = c3; break;\r
1338                         case COLOR_TEAM4: c0 = c4; break;\r
1339                         default:          c0 = 999;\r
1340                 }\r
1341                 switch(t)\r
1342                 {\r
1343                         case 1:\r
1344                                 if(c0 > c1)\r
1345                                         destteam = COLOR_TEAM1;\r
1346                                 break;\r
1347                         case 2:\r
1348                                 if(c0 > c2)\r
1349                                         destteam = COLOR_TEAM2;\r
1350                                 break;\r
1351                         case 3:\r
1352                                 if(c0 > c3)\r
1353                                         destteam = COLOR_TEAM3;\r
1354                                 break;\r
1355                         case 4:\r
1356                                 if(c0 > c4)\r
1357                                         destteam = COLOR_TEAM4;\r
1358                                 break;\r
1359                 }\r
1360                 if(destteam == -1)\r
1361                         return;\r
1362         }\r
1363         if(destteam == self.team && destteam >= 0 && !self.killindicator)\r
1364                 return;\r
1365         ClientKill_TeamChange(destteam);\r
1366 }\r
1367 \r
1368 void FixClientCvars(entity e)\r
1369 {\r
1370         // send prediction settings to the client\r
1371         stuffcmd(e, "\nin_bindmap 0 0\n");\r
1372         if(g_race || g_cts)\r
1373                 stuffcmd(e, "cl_cmd settemp cl_movecliptokeyboard 2\n");\r
1374         if(cvar("g_antilag") == 3) // client side hitscan\r
1375                 //stuffcmd(e, "cl_cmd settemp cl_prydoncursor -1\ncl_cmd settemp cl_prydoncursor_notrace 0\n");\r
1376                 stuffcmd(e, "cl_cmd settemp cl_prydoncursor_notrace 0\n");\r
1377         /*\r
1378          * we no longer need to stuff this. Remove this comment block if you feel\r
1379          * 2.3 and higher (or was it 2.2.3?) don't need these any more\r
1380         stuffcmd(e, strcat("cl_gravity ", ftos(cvar("sv_gravity")), "\n"));\r
1381         stuffcmd(e, strcat("cl_movement_accelerate ", ftos(cvar("sv_accelerate")), "\n"));\r
1382         stuffcmd(e, strcat("cl_movement_friction ", ftos(cvar("sv_friction")), "\n"));\r
1383         stuffcmd(e, strcat("cl_movement_maxspeed ", ftos(cvar("sv_maxspeed")), "\n"));\r
1384         stuffcmd(e, strcat("cl_movement_airaccelerate ", ftos(cvar("sv_airaccelerate")), "\n"));\r
1385         stuffcmd(e, strcat("cl_movement_maxairspeed ", ftos(cvar("sv_maxairspeed")), "\n"));\r
1386         stuffcmd(e, strcat("cl_movement_stopspeed ", ftos(cvar("sv_stopspeed")), "\n"));\r
1387         stuffcmd(e, strcat("cl_movement_jumpvelocity ", ftos(cvar("sv_jumpvelocity")), "\n"));\r
1388         stuffcmd(e, strcat("cl_movement_crouchvelocity ", ftos(cvar("sv_crouchvelocity")), "\n"));\r
1389         stuffcmd(e, strcat("cl_movement_stepheight ", ftos(cvar("sv_stepheight")), "\n"));\r
1390         stuffcmd(e, strcat("set cl_movement_friction_on_land ", ftos(cvar("sv_friction_on_land")), "\n"));\r
1391         stuffcmd(e, strcat("set cl_movement_airaccel_qw ", ftos(cvar("sv_airaccel_qw")), "\n"));\r
1392         stuffcmd(e, strcat("set cl_movement_airaccel_sideways_friction ", ftos(cvar("sv_airaccel_sideways_friction")), "\n"));\r
1393         stuffcmd(e, "cl_movement_edgefriction 1\n");\r
1394          */\r
1395 }\r
1396 \r
1397 /*\r
1398 =============\r
1399 ClientConnect\r
1400 \r
1401 Called when a client connects to the server\r
1402 =============\r
1403 */\r
1404 //void ctf_clientconnect();\r
1405 string ColoredTeamName(float t);\r
1406 void DecodeLevelParms (void);\r
1407 //void dom_player_join_team(entity pl);\r
1408 #ifdef UID\r
1409 .float uid_kicktime;\r
1410 .string uid;\r
1411 #endif\r
1412 void ClientConnect (void)\r
1413 {\r
1414         float t;\r
1415 \r
1416         if(self.flags & FL_CLIENT)\r
1417         {\r
1418                 print("Warning: ClientConnect, but already connected!\n");\r
1419                 return;\r
1420         }\r
1421 \r
1422         if(Ban_MaybeEnforceBan(self))\r
1423                 return;\r
1424 \r
1425         DecodeLevelParms();\r
1426 \r
1427         self.classname = "player_joining";\r
1428 \r
1429         self.flags = FL_CLIENT;\r
1430         self.version_nagtime = time + 10 + random() * 10;\r
1431 \r
1432         if(player_count<0)\r
1433         {\r
1434                 dprint("BUG player count is lower than zero, this cannot happen!\n");\r
1435                 player_count = 0;\r
1436         }\r
1437 \r
1438         PlayerScore_Attach(self);\r
1439         ClientData_Attach();\r
1440 \r
1441         bot_clientconnect();\r
1442 \r
1443         playerdemo_init();\r
1444 \r
1445         anticheat_init();\r
1446         \r
1447         race_PreSpawnObserver();\r
1448 \r
1449         //if(g_domination)\r
1450         //      dom_player_join_team(self);\r
1451 \r
1452         JoinBestTeam(self, FALSE, FALSE); // if the team number is valid, keep it\r
1453 \r
1454         if((cvar("sv_spectate") == 1 && !g_lms) || cvar("g_campaign")) {\r
1455                 self.classname = "observer";\r
1456         } else {\r
1457                 if(teams_matter)\r
1458                 {\r
1459                         if(cvar("g_balance_teams") || cvar("g_balance_teams_force"))\r
1460                         {\r
1461                                 self.classname = "player";\r
1462                                 campaign_bots_may_start = 1;\r
1463                         }\r
1464                         else\r
1465                         {\r
1466                                 self.classname = "observer"; // do it anyway\r
1467                         }\r
1468                 }\r
1469                 else\r
1470                 {\r
1471                         self.classname = "player";\r
1472                         campaign_bots_may_start = 1;\r
1473                 }\r
1474         }\r
1475 \r
1476         self.playerid = (playerid_last = playerid_last + 1);\r
1477 \r
1478         if(cvar("sv_eventlog"))\r
1479                 GameLogEcho(strcat(":join:", ftos(self.playerid), ":", ftos(num_for_edict(self)), ":", ((clienttype(self) == CLIENTTYPE_REAL) ? self.netaddress : "bot"), ":", self.netname));\r
1480 \r
1481         LogTeamchange(self.playerid, self.team, 1);\r
1482 \r
1483         self.just_joined = TRUE;  // stop spamming the eventlog with additional lines when the client connects\r
1484 \r
1485         self.netname_previous = strzone(self.netname);\r
1486 \r
1487         bprint("^4", self.netname, "^4 connected");\r
1488 \r
1489         if(self.classname != "observer" && (g_domination || g_ctf))\r
1490                 bprint(" and joined the ", ColoredTeamName(self.team));\r
1491 \r
1492         bprint("\n");\r
1493 \r
1494         self.welcomemessage_time = 0;\r
1495 \r
1496         stuffcmd(self, strcat(clientstuff, "\n"));\r
1497         stuffcmd(self, strcat("exec maps/", mapname, ".cfg\n"));\r
1498         stuffcmd(self, "cl_particles_reloadeffects\n");\r
1499 \r
1500         FixClientCvars(self);\r
1501 \r
1502         // spawnfunc_waypoint sprites\r
1503         WaypointSprite_InitClient(self);\r
1504 \r
1505         // Wazat's grabber\r
1506         SetGrabberBindings();\r
1507 \r
1508         // get autoswitch state from player when he toggles it\r
1509         stuffcmd(self, "alias autoswitch \"set cl_autoswitch $1 ; cmd autoswitch $1\"\n"); // default.cfg-ed in 2.4.1\r
1510 \r
1511         // get version info from player\r
1512         stuffcmd(self, "cmd clientversion $gameversion\n");\r
1513 \r
1514         // get other cvars from player\r
1515         GetCvars(0);\r
1516 \r
1517         // set cvar for team scoreboard\r
1518         stuffcmd(self, strcat("set teamplay ", ftos(teamplay), "\n"));\r
1519 \r
1520         // notify about available teams\r
1521         if(teams_matter)\r
1522         {\r
1523                 CheckAllowedTeams(self);\r
1524                 t = 0; if(c1 >= 0) t |= 1; if(c2 >= 0) t |= 2; if(c3 >= 0) t |= 4; if(c4 >= 0) t |= 8;\r
1525                 stuffcmd(self, strcat("set _teams_available ", ftos(t), "\n"));\r
1526         }\r
1527         else\r
1528                 stuffcmd(self, "set _teams_available 0\n");\r
1529 \r
1530         stuffcmd(self, strcat("set gametype ", ftos(game), "\n"));\r
1531 \r
1532         if(g_arena || g_ca)\r
1533         {\r
1534                 self.classname = "observer";\r
1535                 if(g_arena)\r
1536                         Spawnqueue_Insert(self);\r
1537         }\r
1538         /*else if(g_ctf)\r
1539         {\r
1540                 ctf_clientconnect();\r
1541         }*/\r
1542 \r
1543         attach_entcs();\r
1544 \r
1545         bot_relinkplayerlist();\r
1546 \r
1547         self.spectatortime = time;\r
1548         if(blockSpectators)\r
1549         {\r
1550                 sprint(self, strcat("^7You have to become a player within the next ", ftos(cvar("g_maxplayers_spectator_blocktime")), " seconds, otherwise you will be kicked, because spectators aren't allowed at this time!\n"));\r
1551         }\r
1552 \r
1553         self.jointime = time;\r
1554         self.allowedTimeouts = cvar("sv_timeout_number");\r
1555 \r
1556         if(clienttype(self) == CLIENTTYPE_REAL)\r
1557         {\r
1558                 if(cvar("g_bugrigs"))\r
1559                         stuffcmd(self, "cl_cmd settemp chase_active 1\n");\r
1560         }\r
1561 \r
1562         if(g_lms)\r
1563         {\r
1564                 if(PlayerScore_Add(self, SP_LMS_LIVES, LMS_NewPlayerLives()) <= 0)\r
1565                 {\r
1566                         PlayerScore_Add(self, SP_LMS_RANK, 666);\r
1567                         self.frags = FRAGS_SPECTATOR;\r
1568                 }\r
1569         }\r
1570 \r
1571         if(!sv_foginterval && world.fog != "")\r
1572                 stuffcmd(self, strcat("\nfog ", world.fog, "\nr_fog_exp2 0\nr_drawfog 1\n"));\r
1573 \r
1574         SoundEntity_Attach(self);\r
1575 \r
1576         if(cvar("g_hitplots") || strstrofs(strcat(" ", cvar_string("g_hitplots_individuals"), " "), strcat(" ", self.netaddress, " "), 0) >= 0)\r
1577         {\r
1578                 self.hitplotfh = fopen(strcat("hits-", matchid, "-", self.netaddress, "-", ftos(self.playerid), ".plot"), FILE_WRITE);\r
1579                 fputs(self.hitplotfh, strcat("#name ", self.netname, "\n"));\r
1580         }\r
1581         else\r
1582                 self.hitplotfh = -1;\r
1583 \r
1584 #ifdef UID\r
1585         if(clienttype(self) == CLIENTTYPE_REAL)\r
1586         if not(self.uid)\r
1587                 self.uid_kicktime = time + 60;\r
1588 #endif\r
1589 \r
1590         if(g_race || g_cts) {\r
1591                 string rr;\r
1592                 if(g_cts)\r
1593                         rr = CTS_RECORD;\r
1594                 else\r
1595                         rr = RACE_RECORD;\r
1596                 t = stof(db_get(ServerProgsDB, strcat(GetMapname(), rr, "time")));\r
1597 \r
1598                 race_send_recordtime(MSG_ONE);\r
1599                 race_send_speedaward(MSG_ONE);\r
1600 \r
1601                 speedaward_alltimebest = stof(db_get(ServerProgsDB, strcat(GetMapname(), rr, "speed/speed")));\r
1602                 speedaward_alltimebest_holder = db_get(ServerProgsDB, strcat(GetMapname(), rr, "speed/netname"));\r
1603                 race_send_speedaward_alltimebest(MSG_ONE);\r
1604 \r
1605                 float i;\r
1606                 for (i = 1; i <= RANKINGS_CNT; ++i) {\r
1607                         race_SendRankings(i, 0, 0, MSG_ONE);\r
1608                 }\r
1609         }\r
1610         else if(cvar("sv_teamnagger") && !g_ca) // teamnagger is currently bad for ca\r
1611                 send_CSQC_teamnagger();\r
1612 \r
1613         CheatInitClient();\r
1614 }\r
1615 \r
1616 /*\r
1617 =============\r
1618 ClientDisconnect\r
1619 \r
1620 Called when a client disconnects from the server\r
1621 =============\r
1622 */\r
1623 .entity chatbubbleentity;\r
1624 void ReadyCount();\r
1625 void ClientDisconnect (void)\r
1626 {\r
1627         if not(self.flags & FL_CLIENT)\r
1628         {\r
1629                 print("Warning: ClientDisconnect without ClientConnect\n");\r
1630                 return;\r
1631         }\r
1632 \r
1633         Vore_Disconnect(TRUE);\r
1634 \r
1635         CheatShutdownClient();\r
1636 \r
1637         if(self.hitplotfh >= 0)\r
1638         {\r
1639                 fclose(self.hitplotfh);\r
1640                 self.hitplotfh = -1;\r
1641         }\r
1642 \r
1643         anticheat_report();\r
1644         anticheat_shutdown();\r
1645 \r
1646         playerdemo_shutdown();\r
1647 \r
1648         bot_clientdisconnect();\r
1649 \r
1650         if(self.entcs)\r
1651                 detach_entcs();\r
1652 \r
1653         if(cvar("sv_eventlog"))\r
1654                 GameLogEcho(strcat(":part:", ftos(self.playerid)));\r
1655         bprint ("^4",self.netname);\r
1656         bprint ("^4 disconnected\n");\r
1657 \r
1658         SoundEntity_Detach(self);\r
1659 \r
1660         kh_Key_DropAll(self, TRUE);\r
1661 \r
1662         if(self.flagcarried)\r
1663                 DropFlag(self.flagcarried, world, world);\r
1664         // Here, everything has been done that requires this player to be a client.\r
1665 \r
1666         self.flags &~= FL_CLIENT;\r
1667 \r
1668         if (self.chatbubbleentity)\r
1669                 remove (self.chatbubbleentity);\r
1670 \r
1671         if (self.killindicator)\r
1672                 remove (self.killindicator);\r
1673 \r
1674         WaypointSprite_PlayerGone();\r
1675 \r
1676         bot_relinkplayerlist();\r
1677 \r
1678         if(g_arena)\r
1679         {\r
1680                 Spawnqueue_Unmark(self);\r
1681                 Spawnqueue_Remove(self);\r
1682         }\r
1683 \r
1684         ClientData_Detach();\r
1685         PlayerScore_Detach(self);\r
1686 \r
1687         if(self.netname_previous)\r
1688                 strunzone(self.netname_previous);\r
1689         if(self.clientstatus)\r
1690                 strunzone(self.clientstatus);\r
1691 \r
1692         ClearPlayerSounds();\r
1693 \r
1694         if(self.personal)\r
1695                 remove(self.personal);\r
1696 \r
1697         self.playerid = 0;\r
1698         ReadyCount();\r
1699 \r
1700         // free cvars\r
1701         GetCvars(-1);\r
1702 }\r
1703 \r
1704 .float BUTTON_CHAT;\r
1705 void ChatBubbleThink()\r
1706 {\r
1707         self.nextthink = time;\r
1708         if (!self.owner.modelindex || self.owner.chatbubbleentity != self)\r
1709         {\r
1710                 if(self.owner) // but why can that ever be world?\r
1711                         self.owner.chatbubbleentity = world;\r
1712                 remove(self);\r
1713                 return;\r
1714         }\r
1715         if ((self.owner.BUTTON_CHAT && !self.owner.deadflag && !self.owner.stat_eaten)\r
1716 #ifdef TETRIS\r
1717                 || self.owner.tetris_on\r
1718 #endif\r
1719         )\r
1720                 self.model = self.mdl;\r
1721         else\r
1722                 self.model = "";\r
1723 };\r
1724 \r
1725 void UpdateChatBubble()\r
1726 {\r
1727         if (!self.modelindex)\r
1728                 return;\r
1729         // spawn a chatbubble entity if needed\r
1730         if (!self.chatbubbleentity)\r
1731         {\r
1732                 self.chatbubbleentity = spawn();\r
1733                 self.chatbubbleentity.owner = self;\r
1734                 self.chatbubbleentity.exteriormodeltoclient = self;\r
1735                 self.chatbubbleentity.think = ChatBubbleThink;\r
1736                 self.chatbubbleentity.nextthink = time;\r
1737                 setmodel(self.chatbubbleentity, "models/misc/chatbubble.spr"); // precision set below\r
1738                 //setorigin(self.chatbubbleentity, self.origin + '0 0 15' + self.maxs_z * '0 0 1');\r
1739                 setorigin(self.chatbubbleentity, '0 0 15' + self.maxs_z * '0 0 1');\r
1740                 setattachment(self.chatbubbleentity, self, "");  // sticks to moving player better, also conserves bandwidth\r
1741                 self.chatbubbleentity.mdl = self.chatbubbleentity.model;\r
1742                 self.chatbubbleentity.model = "";\r
1743                 self.chatbubbleentity.effects = EF_LOWPRECISION;\r
1744         }\r
1745 }\r
1746 \r
1747 // LordHavoc: this hack will be removed when proper _pants/_shirt layers are\r
1748 // added to the model skins\r
1749 /*void UpdateColorModHack()\r
1750 {\r
1751         local float c;\r
1752         c = self.clientcolors & 15;\r
1753         // LordHavoc: only bothering to support white, green, red, yellow, blue\r
1754              if (!teams_matter) self.colormod = '0 0 0';\r
1755         else if (c ==  0) self.colormod = '1.00 1.00 1.00';\r
1756         else if (c ==  3) self.colormod = '0.10 1.73 0.10';\r
1757         else if (c ==  4) self.colormod = '1.73 0.10 0.10';\r
1758         else if (c == 12) self.colormod = '1.22 1.22 0.10';\r
1759         else if (c == 13) self.colormod = '0.10 0.10 1.73';\r
1760         else self.colormod = '1 1 1';\r
1761 };*/\r
1762 \r
1763 .float oldcolormap;\r
1764 void respawn(void)\r
1765 {\r
1766         // don't allow respawing if the prey is still digesting\r
1767         if(cvar("g_balance_vore_digestion_limit_blockrespawn"))\r
1768         if(self.predator.digesting && self.health > cvar("g_balance_vore_digestion_limit"))\r
1769                 return;\r
1770 \r
1771         setmodel(self, self.playermodel); // prevents an issue with dead predators\r
1772         if(self.alpha >= 0 && self.modelindex != 0 && cvar("g_respawn_ghosts"))\r
1773         {\r
1774                 self.solid = SOLID_NOT;\r
1775                 self.takedamage = DAMAGE_NO;\r
1776                 self.movetype = MOVETYPE_FLY;\r
1777                 self.velocity = '0 0 1' * cvar("g_respawn_ghosts_speed");\r
1778                 self.avelocity = randomvec() * cvar("g_respawn_ghosts_speed") * 3 - randomvec() * cvar("g_respawn_ghosts_speed") * 3;\r
1779                 self.effects |= EF_ADDITIVE;\r
1780                 self.oldcolormap = self.colormap;\r
1781                 self.colormap = 512;\r
1782                 pointparticles(particleeffectnum("respawn_ghost"), self.origin, '0 0 0', 1);\r
1783                 if(cvar("g_respawn_ghosts_maxtime"))\r
1784                         SUB_SetFade (self, time + cvar("g_respawn_ghosts_maxtime") / 2 + random () * (cvar("g_respawn_ghosts_maxtime") - cvar("g_respawn_ghosts_maxtime") / 2), 1.5);\r
1785         }\r
1786 \r
1787         CopyBody(1);\r
1788         self.effects |= EF_NODRAW; // prevent another CopyBody\r
1789         if(self.oldcolormap)\r
1790         {\r
1791                 self.colormap = self.oldcolormap;\r
1792                 self.oldcolormap = 0;\r
1793         }\r
1794         PutClientInServer();\r
1795 }\r
1796 \r
1797 void play_countdown(float finished, string samp)\r
1798 {\r
1799         if(clienttype(self) == CLIENTTYPE_REAL)\r
1800                 if(floor(finished - time - frametime) != floor(finished - time))\r
1801                         if(finished - time < 6)\r
1802                                 sound (self, CHAN_AUTO, samp, VOL_BASE, ATTN_NORM);\r
1803 }\r
1804 \r
1805 /**\r
1806  * When sv_timeout is used this function returs strings like\r
1807  * "Timeout begins in 2 seconds!\n" or "Timeout ends in 23 seconds!\n".\r
1808  * Called by centerprint functions\r
1809  * @param addOneSecond boolean, set to 1 if the welcome-message centerprint asks for the text\r
1810  */\r
1811 string getTimeoutText(float addOneSecond) {\r
1812         if (!cvar("sv_timeout") || !timeoutStatus)\r
1813                 return "";\r
1814 \r
1815         local string retStr;\r
1816         if (timeoutStatus == 1) {\r
1817                 if (addOneSecond == 1) {\r
1818                         retStr = strcat("Timeout begins in ", ftos(remainingLeadTime + 1), " seconds!\n");\r
1819                 }\r
1820                 else {\r
1821                         retStr = strcat("Timeout begins in ", ftos(remainingLeadTime), " seconds!\n");\r
1822                 }\r
1823                 return retStr;\r
1824         }\r
1825         else if (timeoutStatus == 2) {\r
1826                 if (addOneSecond) {\r
1827                         retStr = strcat("Timeout ends in ", ftos(remainingTimeoutTime + 1), " seconds!\n");\r
1828                         //don't show messages like "Timeout ends in 0 seconds"...\r
1829                         if ((remainingTimeoutTime + 1) > 0)\r
1830                                 return retStr;\r
1831                         else\r
1832                                 return "";\r
1833                 }\r
1834                 else {\r
1835                         retStr = strcat("Timeout ends in ", ftos(remainingTimeoutTime), " seconds!\n");\r
1836                         //don't show messages like "Timeout ends in 0 seconds"...\r
1837                         if (remainingTimeoutTime > 0)\r
1838                                 return retStr;\r
1839                         else\r
1840                                 return "";\r
1841                 }\r
1842         }\r
1843         else return "";\r
1844 }\r
1845 \r
1846 void player_powerups (void)\r
1847 {\r
1848         if((self.items & IT_USING_JETPACK) && !self.deadflag)\r
1849         {\r
1850                 SoundEntity_StartSound(self, CHAN_PLAYER, "misc/jetpack_fly.wav", VOL_BASE, cvar("g_jetpack_attenuation"));\r
1851                 self.modelflags |= MF_ROCKET;\r
1852         }\r
1853         else\r
1854         {\r
1855                 SoundEntity_StopSound(self, CHAN_PLAYER);\r
1856                 self.modelflags &~= MF_ROCKET;\r
1857         }\r
1858 \r
1859         self.effects &~= (EF_RED | EF_BLUE | EF_ADDITIVE | EF_FULLBRIGHT | EF_FLAME | EF_NODEPTHTEST);\r
1860 \r
1861         if(!self.modelindex || self.deadflag) // don't apply the flags if the player is gibbed\r
1862                 return;\r
1863         \r
1864         Fire_ApplyDamage(self);\r
1865         Fire_ApplyEffect(self);\r
1866 \r
1867         if (self.items & IT_STRENGTH)\r
1868         {\r
1869                 play_countdown(self.strength_finished, "misc/poweroff.wav");\r
1870                 self.effects = self.effects | (EF_BLUE | EF_ADDITIVE | EF_FULLBRIGHT);\r
1871                 if (time > self.strength_finished && cvar("g_balance_powerup_timer"))\r
1872                 {\r
1873                         self.items = self.items - (self.items & IT_STRENGTH);\r
1874                         sprint(self, "^3Strength has worn off\n");\r
1875                 }\r
1876         }\r
1877         else\r
1878         {\r
1879                 if (time < self.strength_finished)\r
1880                 {\r
1881                         self.items = self.items | IT_STRENGTH;\r
1882                         sprint(self, "^3Strength infuses your weapons with devastating power\n");\r
1883                 }\r
1884         }\r
1885         if (self.items & IT_INVINCIBLE)\r
1886         {\r
1887                 play_countdown(self.invincible_finished, "misc/poweroff.wav");\r
1888                 self.effects = self.effects | (EF_RED | EF_ADDITIVE | EF_FULLBRIGHT);\r
1889                 if (time > self.invincible_finished && cvar("g_balance_powerup_timer"))\r
1890                 {\r
1891                         self.items = self.items - (self.items & IT_INVINCIBLE);\r
1892                         sprint(self, "^3Shield has worn off\n");\r
1893                 }\r
1894         }\r
1895         else\r
1896         {\r
1897                 if (time < self.invincible_finished)\r
1898                 {\r
1899                         self.items = self.items | IT_INVINCIBLE;\r
1900                         sprint(self, "^3Shield surrounds you\n");\r
1901                 }\r
1902         }\r
1903 \r
1904         // midair gamemode: damage only while in the air\r
1905         // if in midair mode, being on ground grants temporary invulnerability\r
1906         // (this is so that multishot weapon don't clear the ground flag on the\r
1907         // first damage in the frame, leaving the player vulnerable to the\r
1908         // remaining hits in the same frame)\r
1909         if (self.flags & FL_ONGROUND)\r
1910         if (g_midair)\r
1911                 self.spawnshieldtime = max(self.spawnshieldtime, time + cvar("g_midair_shieldtime"));\r
1912 \r
1913         if (time >= game_starttime)\r
1914         if (time < self.spawnshieldtime)\r
1915                 self.effects = self.effects | (EF_ADDITIVE | EF_FULLBRIGHT);\r
1916 }\r
1917 \r
1918 float CalcRegen(float current, float stable, float regenfactor, float regenframetime)\r
1919 {\r
1920         if(current > stable)\r
1921                 return current;\r
1922         else if(current > stable - 0.25) // when close enough, "snap"\r
1923                 return stable;\r
1924         else\r
1925                 return min(stable, current + (stable - current) * regenfactor * regenframetime);\r
1926 }\r
1927 \r
1928 float CalcRot(float current, float stable, float rotfactor, float rotframetime)\r
1929 {\r
1930         if(current < stable)\r
1931                 return current;\r
1932         else if(current < stable + 0.25) // when close enough, "snap"\r
1933                 return stable;\r
1934         else\r
1935                 return max(stable, current + (stable - current) * rotfactor * rotframetime);\r
1936 }\r
1937 \r
1938 .float regen_soundtime;\r
1939 float CalcRotRegen(float current, float regenstable, float regenfactor, float regenlinear, float regenframetime, float rotstable, float rotfactor, float rotlinear, float rotframetime, float limit, string regensound)\r
1940 {\r
1941         if(current > rotstable)\r
1942         {\r
1943                 if(rotframetime > 0)\r
1944                 {\r
1945                         current = CalcRot(current, rotstable, rotfactor, rotframetime);\r
1946                         current = max(rotstable, current - rotlinear * rotframetime);\r
1947                 }\r
1948         }\r
1949         else if(current < regenstable)\r
1950         {\r
1951                 if(regenframetime > 0)\r
1952                 {\r
1953                         current = CalcRegen(current, regenstable, regenfactor, regenframetime);\r
1954                         current = min(regenstable, current + regenlinear * regenframetime);\r
1955 \r
1956                         if(regensound != "")\r
1957                         if(regenfactor || regenlinear)\r
1958                         {\r
1959                                 if(self.regen_soundtime < time)\r
1960                                 {\r
1961                                         msg_entity = self;\r
1962                                         if(clienttype(msg_entity) == CLIENTTYPE_REAL)\r
1963                                                 soundto(MSG_ONE, self, CHAN_AUTO, regensound, VOL_BASE, ATTN_NONE, 0);\r
1964                                 }\r
1965                                 self.regen_soundtime = time + 1; // only replay the sound if regen was paused for one second\r
1966                         }\r
1967                 }\r
1968         }\r
1969 \r
1970         if(current > limit)\r
1971                 current = limit;\r
1972 \r
1973         return current;\r
1974 }\r
1975 \r
1976 void player_regen (void)\r
1977 {\r
1978         float minh, mina, minf, maxh, maxa, maxf, limith, limita, limitf, max_mod, regen_mod, rot_mod, limit_mod;\r
1979         maxh = cvar("g_balance_health_rotstable");\r
1980         maxa = cvar("g_balance_armor_rotstable");\r
1981         maxf = cvar("g_balance_fuel_rotstable");\r
1982         minh = cvar("g_balance_health_regenstable");\r
1983         mina = cvar("g_balance_armor_regenstable");\r
1984         minf = cvar("g_balance_fuel_regenstable");\r
1985         limith = cvar("g_balance_health_limit");\r
1986         limita = cvar("g_balance_armor_limit");\r
1987         limitf = cvar("g_balance_fuel_limit");\r
1988 \r
1989         max_mod = regen_mod = rot_mod = limit_mod = 1;\r
1990 \r
1991         maxh = maxh * max_mod;\r
1992         //maxa = maxa * max_mod;\r
1993         //maxf = maxf * max_mod;\r
1994         minh = minh * max_mod;\r
1995         //mina = mina * max_mod;\r
1996         //minf = minf * max_mod;\r
1997         limith = limith * limit_mod;\r
1998         limita = limita * limit_mod;\r
1999         //limitf = limitf * limit_mod;\r
2000 \r
2001         if(g_lms && g_ca)\r
2002                 rot_mod = 0;\r
2003 \r
2004         if (!g_ca && (!g_lms || cvar("g_lms_regenerate")))\r
2005         {\r
2006                 self.armorvalue = CalcRotRegen(self.armorvalue, mina, cvar("g_balance_armor_regen"), cvar("g_balance_armor_regenlinear"), regen_mod * frametime * (time > self.pauseregenarmor_finished), maxa, cvar("g_balance_armor_rot"), cvar("g_balance_armor_rotlinear"), rot_mod * frametime * (time > self.pauserotarmor_finished), limita, "misc/armor_regen.wav");\r
2007                 self.health = CalcRotRegen(self.health, minh, cvar("g_balance_health_regen"), cvar("g_balance_health_regenlinear"), regen_mod * frametime * (time > self.pauseregenhealth_finished), maxh, cvar("g_balance_health_rot"), cvar("g_balance_health_rotlinear"), rot_mod * frametime * (time > self.pauserothealth_finished), limith, "misc/health_regen.wav");\r
2008 \r
2009                 // if player rotted to death...  die!\r
2010                 if(self.health < 1)\r
2011                         self.event_damage(self, self, 1, DEATH_ROT, self.origin, '0 0 0');\r
2012         }\r
2013 \r
2014         if not(self.items & IT_UNLIMITED_WEAPON_AMMO)\r
2015                 self.ammo_fuel = CalcRotRegen(self.ammo_fuel, minf, cvar("g_balance_fuel_regen"), cvar("g_balance_fuel_regenlinear"), regen_mod * frametime * (time > self.pauseregenhealth_finished) * (self.items & IT_FUEL_REGEN != 0), maxf, cvar("g_balance_fuel_rot"), cvar("g_balance_fuel_rotlinear"), rot_mod * frametime * (time > self.pauserotfuel_finished), limitf, "");\r
2016 }\r
2017 \r
2018 float zoomstate_set;\r
2019 void SetZoomState(float z)\r
2020 {\r
2021         if(z != self.zoomstate)\r
2022         {\r
2023                 self.zoomstate = z;\r
2024                 ClientData_Touch(self);\r
2025         }\r
2026         zoomstate_set = 1;\r
2027 }\r
2028 \r
2029 // get pressed keys for PlayerDodge\r
2030 void PlayerDodge_GetPressedKeys()\r
2031 {\r
2032         float length;\r
2033         float tap_direction_x;\r
2034         float tap_direction_y;\r
2035         float dodge_detected;\r
2036 \r
2037         // first check if the last dodge is far enough back in time so we can dodge again\r
2038         if ((time - self.last_dodging_time) < cvar("sv_dodging_delay"))\r
2039                 return;\r
2040 \r
2041         if (check_close_to_ground(cvar("sv_dodging_height_threshold")) != 1 \r
2042                 && check_close_to_wall(cvar("sv_dodging_wall_distance_threshold")) != 1)\r
2043                 return;\r
2044 \r
2045         if (self.movement_x > 0) {\r
2046                 // is this a state change?\r
2047                 if (!(self.pressedkeys & KEY_FORWARD)) {\r
2048                         if ((time - self.last_FORWARD_KEY_time) < self.cvar_cl_dodging_timeout) { \r
2049                                 tap_direction_x = 1.0;\r
2050                                 dodge_detected = 1;\r
2051                         }\r
2052                         self.last_FORWARD_KEY_time = time;\r
2053                 }\r
2054         }\r
2055 \r
2056         if (self.movement_x < 0) {\r
2057                 // is this a state change?\r
2058                 if (!(self.pressedkeys & KEY_BACKWARD)) {\r
2059                         tap_direction_x = -1.0;\r
2060                         if ((time - self.last_BACKWARD_KEY_time) < self.cvar_cl_dodging_timeout)        { \r
2061                                 dodge_detected = 1;\r
2062                         }\r
2063                         self.last_BACKWARD_KEY_time = time;\r
2064                 }\r
2065         }\r
2066 \r
2067         if (self.movement_y > 0) {\r
2068                 // is this a state change?\r
2069                 if (!(self.pressedkeys & KEY_RIGHT)) {\r
2070                         tap_direction_y = 1.0;\r
2071                         if ((time - self.last_RIGHT_KEY_time) < self.cvar_cl_dodging_timeout)   { \r
2072                                 dodge_detected = 1;\r
2073                         }\r
2074                         self.last_RIGHT_KEY_time = time;\r
2075                 }\r
2076         }\r
2077 \r
2078         if (self.movement_y < 0) {\r
2079                 // is this a state change?\r
2080                 if (!(self.pressedkeys & KEY_LEFT)) {\r
2081                         tap_direction_y = -1.0;\r
2082                         if ((time - self.last_LEFT_KEY_time) < self.cvar_cl_dodging_timeout)    { \r
2083                                 dodge_detected = 1;\r
2084                         }\r
2085                         self.last_LEFT_KEY_time = time;\r
2086                 }\r
2087         }\r
2088 \r
2089         if (dodge_detected == 1) {\r
2090                 self.last_dodging_time = time;\r
2091 \r
2092                 self.dodging_action = 1;\r
2093                 self.dodging_single_action = 1;\r
2094 \r
2095                 self.dodging_velocity_gain = cvar("sv_dodging_horiz_speed");\r
2096 \r
2097                 self.dodging_direction_x = tap_direction_x;\r
2098                 self.dodging_direction_y = tap_direction_y;\r
2099 \r
2100                 // normalize the dodging_direction vector.. (unlike UT99) XD\r
2101                 length =          self.dodging_direction_x * self.dodging_direction_x;\r
2102                 length = length + self.dodging_direction_y * self.dodging_direction_y;\r
2103                 length = sqrt(length);\r
2104 \r
2105                 self.dodging_direction_x = self.dodging_direction_x * 1.0 / length;\r
2106                 self.dodging_direction_y = self.dodging_direction_y * 1.0 / length;\r
2107         }\r
2108 }\r
2109 \r
2110 void GetPressedKeys(void) {\r
2111         // get keys for dodging\r
2112         if(cvar("g_dodging"))\r
2113                 PlayerDodge_GetPressedKeys();\r
2114 \r
2115         if (self.movement_x > 0) // get if movement keys are pressed\r
2116         {       // forward key pressed\r
2117                 self.pressedkeys |= KEY_FORWARD;\r
2118                 self.pressedkeys &~= KEY_BACKWARD;\r
2119         }\r
2120         else if (self.movement_x < 0)\r
2121         {       // backward key pressed\r
2122                 self.pressedkeys |= KEY_BACKWARD;\r
2123                 self.pressedkeys &~= KEY_FORWARD;\r
2124         }\r
2125         else\r
2126         {       // no x input\r
2127                 self.pressedkeys &~= KEY_FORWARD;\r
2128                 self.pressedkeys &~= KEY_BACKWARD;\r
2129         }\r
2130 \r
2131         if (self.movement_y > 0)\r
2132         {       // right key pressed\r
2133                 self.pressedkeys |= KEY_RIGHT;\r
2134                 self.pressedkeys &~= KEY_LEFT;\r
2135         }\r
2136         else if (self.movement_y < 0)\r
2137         {       // left key pressed\r
2138                 self.pressedkeys |= KEY_LEFT;\r
2139                 self.pressedkeys &~= KEY_RIGHT;\r
2140         }\r
2141         else\r
2142         {       // no y input\r
2143                 self.pressedkeys &~= KEY_RIGHT;\r
2144                 self.pressedkeys &~= KEY_LEFT;\r
2145         }\r
2146 \r
2147         if (self.BUTTON_JUMP) // get if jump and crouch keys are pressed\r
2148                 self.pressedkeys |= KEY_JUMP;\r
2149         else\r
2150                 self.pressedkeys &~= KEY_JUMP;\r
2151         if (self.BUTTON_CROUCH)\r
2152                 self.pressedkeys |= KEY_CROUCH;\r
2153         else\r
2154                 self.pressedkeys &~= KEY_CROUCH;\r
2155 }\r
2156 \r
2157 void update_stats (float number, float hit, float fired) {\r
2158 // self.stat_hit   = number + ((number==0) ? 1 : 64) * hit   * sv_accuracy_data_share;\r
2159 // self.stat_fired = number + ((number==0) ? 1 : 64) * fired * sv_accuracy_data_share;\r
2160 \r
2161         if(number) {\r
2162                 self.stat_hit = number + 64 * hit * sv_accuracy_data_share;\r
2163                 self.stat_fired = number + 64 * fired * sv_accuracy_data_share;\r
2164         } else {\r
2165                 self.stat_hit = hit * sv_accuracy_data_share;\r
2166                 self.stat_fired = fired * sv_accuracy_data_share;\r
2167         }\r
2168 }\r
2169 \r
2170 /*\r
2171 ======================\r
2172 spectate mode routines\r
2173 ======================\r
2174 */\r
2175 \r
2176 .float weapon_count;\r
2177 void SpectateCopy(entity spectatee) {\r
2178         if(spectatee.weapon_count < WEP_LAST) {\r
2179                 update_stats (spectatee.weapon_count, spectatee.cvar_cl_accuracy_data_share * floor(spectatee.stats_hit[spectatee.weapon_count - 1]), spectatee.cvar_cl_accuracy_data_share * floor(spectatee.stats_fired[spectatee.weapon_count - 1]));\r
2180                 spectatee.weapon_count ++;\r
2181         } else\r
2182                 update_stats (0, spectatee.cvar_cl_accuracy_data_share * spectatee.stat_hit, spectatee.cvar_cl_accuracy_data_share * spectatee.stat_fired);\r
2183 \r
2184         self.kh_state = spectatee.kh_state;\r
2185         self.armortype = spectatee.armortype;\r
2186         self.armorvalue = spectatee.armorvalue;\r
2187         self.ammo_fuel = spectatee.ammo_fuel;\r
2188         self.clip_load = spectatee.clip_load;\r
2189         self.clip_size = spectatee.clip_size;\r
2190         self.effects = spectatee.effects & EFMASK_CHEAP; // eat performance\r
2191         self.health = spectatee.health;\r
2192         self.impulse = 0;\r
2193         self.items = spectatee.items;\r
2194         self.last_pickup = spectatee.last_pickup;\r
2195         self.strength_finished = spectatee.strength_finished;\r
2196         self.invincible_finished = spectatee.invincible_finished;\r
2197         self.pressedkeys = spectatee.pressedkeys;\r
2198         self.weapons = spectatee.weapons;\r
2199         self.switchweapon = spectatee.switchweapon;\r
2200         self.weapon = spectatee.weapon;\r
2201         self.punchangle = spectatee.punchangle;\r
2202         self.view_ofs = spectatee.view_ofs;\r
2203         self.v_angle = spectatee.v_angle;\r
2204         self.velocity = spectatee.velocity;\r
2205         self.dmg_take = spectatee.dmg_take;\r
2206         self.dmg_save = spectatee.dmg_save;\r
2207         self.dmg_inflictor = spectatee.dmg_inflictor;\r
2208         self.angles = spectatee.v_angle;\r
2209         self.scale = spectatee.scale;\r
2210         self.fixangle = TRUE;\r
2211         self.stomach_load = spectatee.stomach_load;\r
2212         self.stat_eaten = spectatee.stat_eaten;\r
2213         self.swallow_progress_prey = spectatee.swallow_progress_prey;\r
2214         self.swallow_progress_pred = spectatee.swallow_progress_pred;\r
2215         self.stat_stomachload = spectatee.stat_stomachload;\r
2216         self.stat_stomachmaxload = spectatee.stat_stomachmaxload;\r
2217         self.stat_digesting = spectatee.stat_digesting;\r
2218         self.stat_canleave = spectatee.stat_canleave;\r
2219         self.stat_canswallow = spectatee.stat_canswallow;\r
2220         self.stat_sbring1_type = spectatee.stat_sbring1_type;\r
2221         self.stat_sbring1_clip = spectatee.stat_sbring1_clip;\r
2222         self.stat_sbring2_type = spectatee.stat_sbring2_type;\r
2223         self.stat_sbring2_clip = spectatee.stat_sbring2_clip;\r
2224         self.stat_respawn_time = spectatee.stat_respawn_time;\r
2225         setorigin(self, spectatee.origin);\r
2226         setsize(self, spectatee.mins, spectatee.maxs);\r
2227         SetZoomState(spectatee.zoomstate);\r
2228 \r
2229         // copy necessary flags\r
2230         if(spectatee.flags & FL_ONGROUND)       self.flags |= FL_ONGROUND;      else    self.flags &~= FL_ONGROUND;\r
2231 \r
2232         anticheat_spectatecopy(spectatee);\r
2233 }\r
2234 \r
2235 float SpectateUpdate() {\r
2236         if(!self.enemy)\r
2237                 return 0;\r
2238 \r
2239         if (self == self.enemy)\r
2240                 return 0;\r
2241 \r
2242         if(self.enemy.classname != "player")\r
2243                 return 0;\r
2244 \r
2245         SpectateCopy(self.enemy);\r
2246 \r
2247         return 1;\r
2248 }\r
2249 \r
2250 float SpectateNext() {\r
2251         other = find(self.enemy, classname, "player");\r
2252 \r
2253         if (!other)\r
2254                 other = find(other, classname, "player");\r
2255 \r
2256         if (other)\r
2257                 self.enemy = other;\r
2258 \r
2259         if(self.enemy.classname == "player") {\r
2260                 msg_entity = self;\r
2261                 WriteByte(MSG_ONE, SVC_SETVIEW);\r
2262                 WriteEntity(MSG_ONE, self.enemy);\r
2263                 //stuffcmd(self, "set viewsize $tmpviewsize \n");\r
2264                 self.movetype = MOVETYPE_NONE;\r
2265 \r
2266                 self.enemy.weapon_count = 0;\r
2267 \r
2268                 if(!SpectateUpdate())\r
2269                         PutObserverInServer();\r
2270 \r
2271                 return 1;\r
2272         } else {\r
2273                 return 0;\r
2274         }\r
2275 }\r
2276 \r
2277 /*\r
2278 =============\r
2279 ShowRespawnCountdown()\r
2280 \r
2281 Update a respawn countdown display.\r
2282 =============\r
2283 */\r
2284 void ShowRespawnCountdown()\r
2285 {\r
2286         float number;\r
2287         if(self.deadflag == DEAD_NO) // just respawned?\r
2288                 return;\r
2289         else\r
2290         {\r
2291                 number = ceil(self.death_time - time);\r
2292                 if(number <= 0)\r
2293                         return;\r
2294                 if(number <= self.respawn_countdown)\r
2295                 {\r
2296                         self.respawn_countdown = number - 1;\r
2297                         if(ceil(self.death_time - (time + 0.5)) == number) // only say it if it is the same number even in 0.5s; to prevent overlapping sounds\r
2298                                 AnnounceTo(self, strcat(ftos(number), ""));\r
2299                 }\r
2300         }\r
2301 }\r
2302 \r
2303 void LeaveSpectatorMode()\r
2304 {\r
2305         if(isJoinAllowed()) {\r
2306                 if(!teams_matter || cvar("g_campaign") || cvar("g_balance_teams") || (self.wasplayer && cvar("g_changeteam_banned"))) {\r
2307                         self.classname = "player";\r
2308 \r
2309                         if(cvar("g_campaign") || cvar("g_balance_teams") || cvar("g_balance_teams_force"))\r
2310                                 JoinBestTeam(self, FALSE, TRUE);\r
2311 \r
2312                         if(cvar("g_campaign"))\r
2313                                 campaign_bots_may_start = 1;\r
2314 \r
2315                         self.stat_count = WEP_LAST;\r
2316 \r
2317                         PutClientInServer();\r
2318 \r
2319                         if(self.classname == "player")\r
2320                                 bprint ("^4", self.netname, "^4 is playing now\n");\r
2321 \r
2322                         if(!cvar("g_campaign"))\r
2323                                 centerprint(self,""); // clear MOTD\r
2324 \r
2325                         return;\r
2326                 } else {\r
2327                         if (g_ca && self.caplayer) {\r
2328                         }       // do nothing\r
2329                         else\r
2330                                 stuffcmd(self,"menu_showteamselect\n");\r
2331                         return;\r
2332                 }\r
2333         }\r
2334         else {\r
2335                 //player may not join because of g_maxplayers is set\r
2336                 centerprint_atprio(self, CENTERPRIO_MAPVOTE, PREVENT_JOIN_TEXT);\r
2337         }\r
2338 }\r
2339 \r
2340 /**\r
2341  * Determines whether the player is allowed to join. This depends on cvar\r
2342  * g_maxplayers, if it isn't used this function always return TRUE, otherwise\r
2343  * it checks whether the number of currently playing players exceeds g_maxplayers.\r
2344  * @return bool TRUE if the player is allowed to join, false otherwise\r
2345  */\r
2346 float isJoinAllowed() {\r
2347         if (!cvar("g_maxplayers"))\r
2348                 return TRUE;\r
2349 \r
2350         local entity e;\r
2351         local float currentlyPlaying;\r
2352         FOR_EACH_REALPLAYER(e) {\r
2353                 if(e.classname == "player")\r
2354                         currentlyPlaying += 1;\r
2355         }\r
2356         if(currentlyPlaying < cvar("g_maxplayers"))\r
2357                 return TRUE;\r
2358 \r
2359         return FALSE;\r
2360 }\r
2361 \r
2362 /**\r
2363  * Checks whether the client is an observer or spectator, if so, he will get kicked after\r
2364  * g_maxplayers_spectator_blocktime seconds\r
2365  */\r
2366 void checkSpectatorBlock() {\r
2367         if(self.classname == "spectator" || self.classname == "observer") {\r
2368                 if( time > (self.spectatortime + cvar("g_maxplayers_spectator_blocktime")) ) {\r
2369                         sprint(self, "^7You were kicked from the server because you are spectator and spectators aren't allowed at the moment.\n");\r
2370                         dropclient(self);\r
2371                 }\r
2372         }\r
2373 }\r
2374 \r
2375 float vercmp_recursive(string v1, string v2)\r
2376 {\r
2377         float dot1, dot2;\r
2378         string s1, s2;\r
2379         float r;\r
2380 \r
2381         dot1 = strstrofs(v1, ".", 0);\r
2382         dot2 = strstrofs(v2, ".", 0);\r
2383         if(dot1 == -1)\r
2384                 s1 = v1;\r
2385         else\r
2386                 s1 = substring(v1, 0, dot1);\r
2387         if(dot2 == -1)\r
2388                 s2 = v2;\r
2389         else\r
2390                 s2 = substring(v2, 0, dot2);\r
2391 \r
2392         r = stof(s1) - stof(s2);\r
2393         if(r != 0)\r
2394                 return r;\r
2395 \r
2396         r = strcasecmp(s1, s2);\r
2397         if(r != 0)\r
2398                 return r;\r
2399 \r
2400         if(dot1 == -1)\r
2401                 if(dot2 == -1)\r
2402                         return 0;\r
2403                 else\r
2404                         return -1;\r
2405         else\r
2406                 if(dot2 == -1)\r
2407                         return 1;\r
2408                 else\r
2409                         return vercmp_recursive(substring(v1, dot1 + 1, 999), substring(v2, dot2 + 1, 999));\r
2410 }\r
2411 \r
2412 float vercmp(string v1, string v2)\r
2413 {\r
2414         if(strcasecmp(v1, v2) == 0) // early out check\r
2415                 return 0;\r
2416         return vercmp_recursive(v1, v2);\r
2417 }\r
2418 \r
2419 .float last_alive_scale;\r
2420 void SetPlayerSize()\r
2421 {\r
2422         if(!cvar("g_healthsize"))\r
2423                 return;\r
2424 \r
2425         if(self.deadflag == DEAD_NO)\r
2426         {\r
2427                 // change player scale based on the amount of health we have\r
2428                 self.scale = pow(bound(cvar("g_healthsize_min"), self.health, cvar("g_healthsize_max")) / cvar("g_healthsize_center"), cvar("g_healthsize"));\r
2429 \r
2430                 // The following code sets the bounding box to match the player's size.\r
2431                 // It is currently disabled because of issues with engine movement prediction (cl_movement).\r
2432                 // The engine expects the bounding box to be default size, and changing it will cause glitches.\r
2433                 // This code may be enabled once the engine has the ability to use different bbox sizes for movement prediction.\r
2434                 if(self.crouch)\r
2435                 {\r
2436                         //setsize (self, PL_CROUCH_MIN * self.scale, PL_CROUCH_MAX * self.scale);\r
2437                         if(!self.stat_eaten)\r
2438                                 self.view_ofs = PL_CROUCH_VIEW_OFS * self.scale;\r
2439                 }\r
2440                 else\r
2441                 {\r
2442                         //setsize (self, PL_MIN * self.scale, PL_MAX * self.scale);\r
2443                         if(!self.stat_eaten)\r
2444                                 self.view_ofs = PL_VIEW_OFS * pow(self.scale, cvar("g_healthsize_viewfactor"));\r
2445                 }\r
2446 \r
2447                 self.last_alive_scale = self.scale;\r
2448         }\r
2449         else if(self.last_alive_scale)\r
2450         {\r
2451                 // if the player is dead, use the last scale he had when he was alive\r
2452                 self.scale = self.last_alive_scale;\r
2453         }\r
2454 \r
2455         if(cvar("g_healthsize_death") && self.deadflag != DEAD_NO)\r
2456         {\r
2457                 // dead players shrink to zero as they head toward the health limit\r
2458                 self.scale *= 1 - bound(0, (self.health / cvar("g_healthsize_death_min")) * cvar("g_healthsize_death"), 1);\r
2459         }\r
2460 \r
2461         if(self.scale < 0.1)\r
2462                 self.scale = 0.1; // stuff breaks if scale is smaller than this\r
2463 }\r
2464 \r
2465 void ObserverThink()\r
2466 {\r
2467         float prefered_movetype;\r
2468         if (self.flags & FL_JUMPRELEASED) {\r
2469                 if (self.BUTTON_JUMP && !self.version_mismatch) {\r
2470                         self.flags &~= FL_JUMPRELEASED;\r
2471                         self.flags |= FL_SPAWNING;\r
2472                 } else if(self.BUTTON_ATCK && !self.version_mismatch) {\r
2473                         self.flags &~= FL_JUMPRELEASED;\r
2474                         if(SpectateNext() == 1) {\r
2475                                 self.classname = "spectator";\r
2476                         }\r
2477                 } else {\r
2478                         prefered_movetype = ((!self.BUTTON_USE ? self.cvar_cl_clippedspectating : !self.cvar_cl_clippedspectating) ? MOVETYPE_FLY_WORLDONLY : MOVETYPE_NOCLIP);\r
2479                         if (self.movetype != prefered_movetype)\r
2480                                 self.movetype = prefered_movetype;\r
2481                 }\r
2482         } else {\r
2483                 if (!(self.BUTTON_ATCK || self.BUTTON_JUMP)) {\r
2484                         self.flags |= FL_JUMPRELEASED;\r
2485                         if(self.flags & FL_SPAWNING)\r
2486                         {\r
2487                                 self.flags &~= FL_SPAWNING;\r
2488                                 LeaveSpectatorMode();\r
2489                                 return;\r
2490                         }\r
2491                 }\r
2492         }\r
2493 \r
2494         PrintWelcomeMessage(self);\r
2495 }\r
2496 \r
2497 void SpectatorThink()\r
2498 {\r
2499         if (self.flags & FL_JUMPRELEASED) {\r
2500                 if (self.BUTTON_JUMP && !self.version_mismatch) {\r
2501                         self.welcomemessage_time = 0;\r
2502                         self.flags &~= FL_JUMPRELEASED;\r
2503                         self.flags |= FL_SPAWNING;\r
2504                 } else if(self.BUTTON_ATCK) {\r
2505                         self.welcomemessage_time = 0;\r
2506                         self.flags &~= FL_JUMPRELEASED;\r
2507                         if(SpectateNext() == 1) {\r
2508                                 self.classname = "spectator";\r
2509                         } else {\r
2510                                 self.classname = "observer";\r
2511                                 self.stat_count = WEP_LAST;\r
2512                                 PutClientInServer();\r
2513                         }\r
2514                 } else if (self.BUTTON_ATCK2) {\r
2515                         self.welcomemessage_time = 0;\r
2516                         self.flags &~= FL_JUMPRELEASED;\r
2517                         self.classname = "observer";\r
2518                         self.stat_count = WEP_LAST;\r
2519                         PutClientInServer();\r
2520                 } else {\r
2521                         if(!SpectateUpdate())\r
2522                                 PutObserverInServer();\r
2523                 }\r
2524         } else {\r
2525                 if (!(self.BUTTON_ATCK || self.BUTTON_ATCK2)) {\r
2526                         self.flags |= FL_JUMPRELEASED;\r
2527                         if(self.flags & FL_SPAWNING)\r
2528                         {\r
2529                                 self.flags &~= FL_SPAWNING;\r
2530                                 LeaveSpectatorMode();\r
2531                                 return;\r
2532                         }\r
2533                 }\r
2534         }\r
2535 \r
2536         PrintWelcomeMessage(self);\r
2537         self.flags |= FL_CLIENT | FL_NOTARGET;\r
2538 }\r
2539 \r
2540 .float touchexplode_time;\r
2541 \r
2542 /*\r
2543 =============\r
2544 PlayerPreThink\r
2545 \r
2546 Called every frame for each client before the physics are run\r
2547 =============\r
2548 */\r
2549 void() ctf_setstatus;\r
2550 .float items_added;\r
2551 .vector avg_vel;\r
2552 .float power_sounded;\r
2553 void PlayerPreThink (void)\r
2554 {\r
2555         self.stat_game_starttime = game_starttime;\r
2556         self.stat_allow_oldnexbeam = cvar("g_allow_oldnexbeam");\r
2557         self.stat_leadlimit = cvar("leadlimit");\r
2558 \r
2559         if(g_arena || (g_ca && !allowed_to_spawn))\r
2560                 self.stat_respawn_time = 0;\r
2561         else\r
2562                 self.stat_respawn_time = self.death_time;\r
2563 \r
2564         if(frametime)\r
2565         {\r
2566                 // physics frames: update anticheat stuff\r
2567                 anticheat_prethink();\r
2568         }\r
2569 \r
2570         if(blockSpectators && frametime)\r
2571                 // WORKAROUND: only use dropclient in server frames (frametime set). Never use it in cl_movement frames (frametime zero).\r
2572                 checkSpectatorBlock();\r
2573 \r
2574         zoomstate_set = 0;\r
2575 \r
2576         if(self.netname_previous != self.netname)\r
2577         {\r
2578                 if(cvar("sv_eventlog"))\r
2579                         GameLogEcho(strcat(":name:", ftos(self.playerid), ":", self.netname));\r
2580                 if(self.netname_previous)\r
2581                         strunzone(self.netname_previous);\r
2582                 self.netname_previous = strzone(self.netname);\r
2583         }\r
2584 \r
2585         // core code for the vore system\r
2586         Vore();\r
2587 \r
2588         // play power fail sound\r
2589         if(self.armorvalue < cvar("g_power"))\r
2590         {\r
2591                 if(!self.power_sounded)\r
2592                 {\r
2593                         sound(self, CHAN_TRIGGER, "misc/power_fail.ogg", VOL_BASE, ATTN_NORM);\r
2594                         self.power_sounded = TRUE;\r
2595                 }\r
2596         }\r
2597         else\r
2598                 self.power_sounded = FALSE;\r
2599 \r
2600         // version nagging\r
2601         if(self.version_nagtime)\r
2602                 if(self.cvar_g_voretournamentversion)\r
2603                         if(time > self.version_nagtime)\r
2604                         {\r
2605                                 if(strstr(self.cvar_g_voretournamentversion, "svn", 0) < 0)\r
2606                                 {\r
2607                                         if(strstr(cvar_string("g_voretournamentversion"), "svn", 0) >= 0)\r
2608                                         {\r
2609                                                 dprint("^1NOTE^7 to ", self.netname, "^7 - the server is running ^3Voretournament ", cvar_string("g_voretournamentversion"), " (beta)^7, you have ^3Voretournament ", self.cvar_g_voretournamentversion, "^1\n");\r
2610                                                 sprint(self, strcat("\{1}^1NOTE: ^7the server is running ^3Voretournament ", cvar_string("g_voretournamentversion"), " (beta)^7, you have ^3Voretournament ", self.cvar_g_voretournamentversion, "^1\n"));\r
2611                                         }\r
2612                                         else\r
2613                                         {\r
2614                                                 float r;\r
2615                                                 r = vercmp(self.cvar_g_voretournamentversion, cvar_string("g_voretournamentversion"));\r
2616                                                 if(r < 0)\r
2617                                                 {\r
2618                                                         dprint("^1NOTE^7 to ", self.netname, "^7 - ^3Voretournament ", cvar_string("g_voretournamentversion"), "^7 is out, and you still have ^3Voretournament ", self.cvar_g_voretournamentversion, "^1 - get the update from ^4http://www.alientrap.org/voretournament/^1!\n");\r
2619                                                         sprint(self, strcat("\{1}^1NOTE: ^3Voretournament ", cvar_string("g_voretournamentversion"), "^7 is out, and you still have ^3Voretournament ", self.cvar_g_voretournamentversion, "^1 - get the update from ^4http://www.alientrap.org/voretournament/^1!\n"));\r
2620                                                 }\r
2621                                                 else if(r > 0)\r
2622                                                 {\r
2623                                                         dprint("^1NOTE^7 to ", self.netname, "^7 - the server is running ^3Voretournament ", cvar_string("g_voretournamentversion"), "^7, you have ^3Voretournament ", self.cvar_g_voretournamentversion, "^1\n");\r
2624                                                         sprint(self, strcat("\{1}^1NOTE: ^7the server is running ^3Voretournament ", cvar_string("g_voretournamentversion"), "^7, you have ^3Voretournament ", self.cvar_g_voretournamentversion, "^1\n"));\r
2625                                                 }\r
2626                                         }\r
2627                                 }\r
2628                                 self.version_nagtime = 0;\r
2629                         }\r
2630 \r
2631         // GOD MODE info\r
2632         if(!(self.flags & FL_GODMODE)) if(self.max_armorvalue)\r
2633         {\r
2634                 sprint(self, strcat("godmode saved you ", ftos(self.max_armorvalue), " units of damage, cheater!\n"));\r
2635                 self.max_armorvalue = 0;\r
2636         }\r
2637 \r
2638 #ifdef TETRIS\r
2639         if (TetrisPreFrame())\r
2640                 return;\r
2641 #endif\r
2642 \r
2643         if(self.classname == "player") {\r
2644 //              if(self.netname == "Wazat")\r
2645 //                      bprint(self.classname, "\n");\r
2646 \r
2647                 CheckRules_Player();\r
2648 \r
2649                 PrintWelcomeMessage(self);\r
2650 \r
2651                 if (intermission_running)\r
2652                 {\r
2653                         IntermissionThink ();   // otherwise a button could be missed between\r
2654                         return;                                 // the think tics\r
2655                 }\r
2656 \r
2657                 if(self.teleport_time)\r
2658                 if(time > self.teleport_time)\r
2659                 {\r
2660                         self.teleport_time = 0;\r
2661                         self.effects = self.effects - (self.effects & EF_NODRAW);\r
2662                 }\r
2663 \r
2664                 if(frametime > 0) // don't do this in cl_movement frames, just in server ticks\r
2665                         UpdateSelectedPlayer();\r
2666 \r
2667                 //don't allow the player to turn around while game is paused!\r
2668                 if(timeoutStatus == 2) {\r
2669                         self.v_angle = self.lastV_angle;\r
2670                         self.angles = self.lastV_angle;\r
2671                         self.fixangle = TRUE;\r
2672                 }\r
2673 \r
2674                 SetPlayerSize();\r
2675 \r
2676                 if(frametime)\r
2677                 {\r
2678                         if(self.health <= 0 && cvar("g_deathglow"))\r
2679                         {\r
2680                                 if(self.glowmod_x > 0)\r
2681                                         self.glowmod_x -= cvar("g_deathglow") * frametime;\r
2682                                 else\r
2683                                         self.glowmod_x = -1;\r
2684                                 if(self.glowmod_y > 0)\r
2685                                         self.glowmod_y -= cvar("g_deathglow") * frametime;\r
2686                                 else\r
2687                                         self.glowmod_y = -1;\r
2688                                 if(self.glowmod_z > 0)\r
2689                                         self.glowmod_z -= cvar("g_deathglow") * frametime;\r
2690                                 else\r
2691                                         self.glowmod_z = -1;\r
2692                         }\r
2693                         else\r
2694                         {\r
2695                                 // set weapon and player glowmod\r
2696                                 self.glowmod = colormapPaletteColor(self.clientcolors & 0x0F, TRUE) * 2;\r
2697                                 if(self.armorvalue < cvar("g_power"))\r
2698                                         self.glowmod = self.glowmod * random(); // make glow flicker when power is down\r
2699                                 self.weaponentity_glowmod = self.glowmod;\r
2700                         }\r
2701 \r
2702                         player_powerups();\r
2703                 }\r
2704 \r
2705                 if (self.deadflag != DEAD_NO)\r
2706                 {\r
2707                         float button_pressed, force_respawn;\r
2708                         if(self.personal && g_race_qualifying)\r
2709                         {\r
2710                                 if(time > self.death_time)\r
2711                                 {\r
2712                                         self.death_time = time + 1; // only retry once a second\r
2713                                         respawn();\r
2714                                         self.impulse = 141;\r
2715                                 }\r
2716                         }\r
2717                         else\r
2718                         {\r
2719                                 if(frametime)\r
2720                                         player_anim();\r
2721                                 button_pressed = (self.BUTTON_ATCK || self.BUTTON_JUMP || self.BUTTON_ATCK2 || self.BUTTON_JETPACK || self.BUTTON_USE);\r
2722                                 force_respawn = (g_lms || (g_ca) || cvar("g_forced_respawn"));\r
2723                                 if (self.deadflag == DEAD_DYING)\r
2724                                 {\r
2725                                         if(force_respawn)\r
2726                                                 self.deadflag = DEAD_RESPAWNING;\r
2727                                         else if(!button_pressed)\r
2728                                                 self.deadflag = DEAD_DEAD;\r
2729                                 }\r
2730                                 else if (self.deadflag == DEAD_DEAD)\r
2731                                 {\r
2732                                         if(button_pressed)\r
2733                                                 self.deadflag = DEAD_RESPAWNABLE;\r
2734                                 }\r
2735                                 else if (self.deadflag == DEAD_RESPAWNABLE)\r
2736                                 {\r
2737                                         if(!button_pressed)\r
2738                                                 self.deadflag = DEAD_RESPAWNING;\r
2739                                 }\r
2740                                 else if (self.deadflag == DEAD_RESPAWNING)\r
2741                                 {\r
2742                                         if(time > self.death_time)\r
2743                                         {\r
2744                                                 self.death_time = time + 1; // only retry once a second\r
2745                                                 respawn();\r
2746                                         }\r
2747                                 }\r
2748                                 ShowRespawnCountdown();\r
2749                         }\r
2750 \r
2751                         // if respawning, invert stat_respawn_time to indicate this, the client translates it\r
2752                         if(self.deadflag == DEAD_RESPAWNING && self.stat_respawn_time > 0)\r
2753                                 self.stat_respawn_time *= -1;\r
2754 \r
2755                         return;\r
2756                 }\r
2757 \r
2758                 if(g_touchexplode)\r
2759                 if(time > self.touchexplode_time)\r
2760                 if(self.classname == "player")\r
2761                 if(self.deadflag == DEAD_NO)\r
2762                 if not(IS_INDEPENDENT_PLAYER(self))\r
2763                 FOR_EACH_PLAYER(other) if(self != other)\r
2764                 {\r
2765                         if(time > other.touchexplode_time)\r
2766                         if(other.classname == "player")\r
2767                         if(other.deadflag == DEAD_NO)\r
2768                         if not(IS_INDEPENDENT_PLAYER(other))\r
2769                         if(boxesoverlap(self.absmin, self.absmax, other.absmin, other.absmax))\r
2770                         {\r
2771                                 PlayerTouchExplode(self, other);\r
2772                                 self.touchexplode_time = other.touchexplode_time = time + 0.2;\r
2773                         }\r
2774                 }\r
2775 \r
2776                 if(g_lms && !self.deadflag && cvar("g_lms_campcheck_interval"))\r
2777                 {\r
2778                         vector dist;\r
2779 \r
2780                         // calculate player movement (in 2 dimensions only, so jumping on one spot doesn't count as movement)\r
2781                         dist = self.prevorigin - self.origin;\r
2782                         dist_z = 0;\r
2783                         self.lms_traveled_distance += fabs(vlen(dist));\r
2784 \r
2785                         if((cvar("g_campaign") && !campaign_bots_may_start) || (time < game_starttime))\r
2786                         {\r
2787                                 self.lms_nextcheck = time + cvar("g_lms_campcheck_interval")*2;\r
2788                                 self.lms_traveled_distance = 0;\r
2789                         }\r
2790 \r
2791                         if(time > self.lms_nextcheck)\r
2792                         {\r
2793                                 //sprint(self, "distance: ", ftos(self.lms_traveled_distance), "\n");\r
2794                                 if(self.lms_traveled_distance < cvar("g_lms_campcheck_distance"))\r
2795                                 {\r
2796                                         centerprint(self, cvar_string("g_lms_campcheck_message"));\r
2797                                         // FIXME KadaverJack: gibbing player here causes playermodel to bounce around, instead of eye.md3\r
2798                                         // I wasn't able to find out WHY that happens, so I put a workaround in place that shall prevent players from being gibbed :(\r
2799                                         Damage(self, self, self, bound(0, cvar("g_lms_campcheck_damage"), self.health + self.armorvalue * cvar("g_balance_armor_blockpercent") + 5), DEATH_CAMP, self.origin, '0 0 0');\r
2800                                 }\r
2801                                 self.lms_nextcheck = time + cvar("g_lms_campcheck_interval");\r
2802                                 self.lms_traveled_distance = 0;\r
2803                         }\r
2804                 }\r
2805 \r
2806                 self.prevorigin = self.origin;\r
2807 \r
2808                 if ((self.BUTTON_CROUCH && !self.grabber.state) || self.health <= g_bloodloss)\r
2809                 {\r
2810                         if (!self.crouch)\r
2811                         {\r
2812                                 self.crouch = TRUE;\r
2813                                 self.view_ofs = PL_CROUCH_VIEW_OFS;\r
2814                                 setsize (self, PL_CROUCH_MIN, PL_CROUCH_MAX);\r
2815                                 setanim(self, self.anim_duck, FALSE, TRUE, TRUE);\r
2816                         }\r
2817                 }\r
2818                 else\r
2819                 {\r
2820                         if (self.crouch)\r
2821                         {\r
2822                                 tracebox(self.origin, PL_MIN, PL_MAX, self.origin, FALSE, self);\r
2823                                 if (!trace_startsolid)\r
2824                                 {\r
2825                                         self.crouch = FALSE;\r
2826                                         self.view_ofs = PL_VIEW_OFS;\r
2827                                         setsize (self, PL_MIN, PL_MAX);\r
2828                                 }\r
2829                         }\r
2830                 }\r
2831 \r
2832                 if(self.health <= g_bloodloss && self.deadflag == DEAD_NO)\r
2833                 {\r
2834                         if(self.bloodloss_timer < time)\r
2835                         {\r
2836                                 self.event_damage(self, self, 1, DEATH_ROT, self.origin, '0 0 0');\r
2837                                 self.bloodloss_timer = time + 0.5 + random() * 0.5;\r
2838                         }\r
2839                 }\r
2840 \r
2841                 FixPlayermodel();\r
2842 \r
2843                 GrabberFrame();\r
2844 \r
2845                 // LordHavoc: allow firing on move frames (sub-ticrate), this gives better timing on slow servers\r
2846                 //if(frametime)\r
2847                 {\r
2848                         self.items &~= self.items_added;\r
2849 \r
2850                         W_WeaponFrame();\r
2851 \r
2852                         self.items_added = 0;\r
2853                         if(self.items & IT_JETPACK)\r
2854                                 if(self.items & IT_FUEL_REGEN || self.ammo_fuel >= 0.01)\r
2855                                         self.items_added |= IT_FUEL;\r
2856 \r
2857                         self.items |= self.items_added;\r
2858                 }\r
2859 \r
2860                 player_regen();\r
2861                 if(frametime)\r
2862                         player_anim();\r
2863 \r
2864                 ctf_setstatus();\r
2865 \r
2866                 self.dmg_team = max(0, self.dmg_team - cvar("g_teamdamage_resetspeed") * frametime);\r
2867 \r
2868                 //self.angles_y=self.v_angle_y + 90;   // temp\r
2869         } else if(gameover) {\r
2870                 if (intermission_running)\r
2871                         IntermissionThink ();   // otherwise a button could be missed between\r
2872                 return;\r
2873         } else if(self.classname == "observer") {\r
2874                 ObserverThink();\r
2875         } else if(self.classname == "spectator") {\r
2876                 SpectatorThink();\r
2877         }\r
2878 \r
2879         if(!zoomstate_set)\r
2880                 SetZoomState(self.BUTTON_ZOOM);\r
2881 \r
2882         float oldspectatee_status;\r
2883         oldspectatee_status = self.spectatee_status;\r
2884         if(self.classname == "spectator")\r
2885                 self.spectatee_status = num_for_edict(self.enemy);\r
2886         else if(self.classname == "observer")\r
2887                 self.spectatee_status = num_for_edict(self);\r
2888         else\r
2889                 self.spectatee_status = 0;\r
2890         if(self.spectatee_status != oldspectatee_status)\r
2891         {\r
2892                 ClientData_Touch(self);\r
2893                 if(g_race || g_cts)\r
2894                         race_InitSpectator();\r
2895         }\r
2896 \r
2897         if(self.teamkill_soundtime)\r
2898         if(time > self.teamkill_soundtime)\r
2899         {\r
2900                 self.teamkill_soundtime = 0;\r
2901 \r
2902                 entity oldpusher, oldself;\r
2903 \r
2904                 oldself = self; self = self.teamkill_soundsource;\r
2905                 oldpusher = self.pusher; self.pusher = oldself;\r
2906 \r
2907                 PlayerSound(self, playersound_teamshoot, CHAN_VOICE, VOICETYPE_LASTATTACKER_ONLY);\r
2908 \r
2909                 self.pusher = oldpusher;\r
2910                 self = oldself;\r
2911         }\r
2912 \r
2913         if(self.taunt_soundtime)\r
2914         if(time > self.taunt_soundtime)\r
2915         {\r
2916                 switch(self.taunt_soundtype)\r
2917                 {\r
2918                         case TAUNTTYPE_DEATH:\r
2919                                 PlayerSound(self, playersound_taunt, CHAN_VOICE, VOICETYPE_AUTOTAUNT);\r
2920                                 break;\r
2921                         case TAUNTTYPE_VOREPRED:\r
2922                                 PlayerSound(self, playersound_pred, CHAN_VOICE, VOICETYPE_AUTOTAUNT);\r
2923                                 break;\r
2924                         case TAUNTTYPE_VOREPREY:\r
2925                                 PlayerSound(self, playersound_prey, CHAN_VOICE, VOICETYPE_AUTOTAUNT);\r
2926                                 break;\r
2927                         default:\r
2928                                 dprint("Incorrect autotaunt type\n");\r
2929                                 break;\r
2930                 }\r
2931 \r
2932                 self.taunt_soundtime = 0;\r
2933                 self.taunt_soundtype = 0;\r
2934         }\r
2935 \r
2936         target_voicescript_next(self);\r
2937 \r
2938         // if a player goes unarmed after holding a loaded weapon, empty his clip size and remove the crosshair ammo ring\r
2939         if(!self.weapon)\r
2940                 self.clip_load = self.clip_size = 0;\r
2941 }\r
2942 \r
2943 float isInvisibleString(string s)\r
2944 {\r
2945         float i, n, c;\r
2946         s = strdecolorize(s);\r
2947         for((i = 0), (n = strlen(s)); i < n; ++i)\r
2948         {\r
2949                 c = str2chr(s, i);\r
2950                 switch(c)\r
2951                 {\r
2952                         case 0:\r
2953                         case 32: // space\r
2954                                 break;\r
2955                         case 192: // charmap space\r
2956                                 if (!cvar("utf8_enable"))\r
2957                                         break;\r
2958                                 return FALSE;\r
2959                         case 160: // space in unicode fonts\r
2960                         case 0xE000 + 192: // utf8 charmap space\r
2961                                 if (cvar("utf8_enable"))\r
2962                                         break;\r
2963                         default:\r
2964                                 return FALSE;\r
2965                 }\r
2966         }\r
2967         return TRUE;\r
2968 }\r
2969 \r
2970 /*\r
2971 =============\r
2972 PlayerPostThink\r
2973 \r
2974 Called every frame for each client after the physics are run\r
2975 =============\r
2976 */\r
2977 .float idlekick_lasttimeleft;\r
2978 void PlayerPostThink (void)\r
2979 {\r
2980         // Savage: Check for nameless players\r
2981         if (isInvisibleString(self.netname)) {\r
2982                 self.netname = "Player";\r
2983                 stuffcmd(self, strcat("name ", self.netname, substring(ftos(random()), 2, -1), "\n"));\r
2984         }\r
2985 \r
2986         // send the clients accuracy stats to the client\r
2987         if(self.stat_count > 0)\r
2988         if(frametime)\r
2989         {\r
2990                 self.stat_hit = self.stat_count + 64 * floor(self.(stats_hit[self.stat_count - 1]));\r
2991                 self.stat_fired = self.stat_count + 64 * floor(self.(stats_fired[self.stat_count - 1]));\r
2992                 self.stat_count -= 1;\r
2993         }\r
2994 \r
2995 #ifdef UID\r
2996         if(self.uid_kicktime)\r
2997         if(time > self.uid_kicktime)\r
2998         {\r
2999                 bprint("^3", self.netname, "^3 was kicked for missing UID.\n");\r
3000                 dropclient(self);\r
3001                 return;\r
3002         }\r
3003 #endif\r
3004 \r
3005         if(sv_maxidle && frametime)\r
3006         {\r
3007                 // WORKAROUND: only use dropclient in server frames (frametime set). Never use it in cl_movement frames (frametime zero).\r
3008                 float timeleft;\r
3009                 timeleft = ceil(sv_maxidle - (time - self.parm_idlesince));\r
3010                 if(timeleft <= 0)\r
3011                 {\r
3012                         bprint("^3", self.netname, "^3 was kicked for idling.\n");\r
3013                         AnnounceTo(self, "terminated");\r
3014                         dropclient(self);\r
3015                         return;\r
3016                 }\r
3017                 else if(timeleft <= 10)\r
3018                 {\r
3019                         if(timeleft != self.idlekick_lasttimeleft)\r
3020                         {\r
3021                                 centerprint_atprio(self, CENTERPRIO_IDLEKICK, strcat("^3Stop idling!\n^3Disconnecting in ", ftos(timeleft), "..."));\r
3022                                 AnnounceTo(self, strcat(ftos(timeleft), ""));\r
3023                         }\r
3024                 }\r
3025                 else\r
3026                 {\r
3027                         centerprint_expire(self, CENTERPRIO_IDLEKICK);\r
3028                 }\r
3029                 self.idlekick_lasttimeleft = timeleft;\r
3030         }\r
3031 \r
3032 #ifdef TETRIS\r
3033         if(self.impulse == 100)\r
3034                 ImpulseCommands();\r
3035         if (TetrisPostFrame())\r
3036                 return;\r
3037 #endif\r
3038 \r
3039         CheatFrame();\r
3040 \r
3041         if(self.classname == "player") {\r
3042                 CheckRules_Player();\r
3043                 UpdateChatBubble();\r
3044                 if (self.impulse)\r
3045                         ImpulseCommands();\r
3046                 if (intermission_running)\r
3047                         return;         // intermission or finale\r
3048 \r
3049                 GetPressedKeys();\r
3050         } else if (self.classname == "observer") {\r
3051                 //do nothing\r
3052         } else if (self.classname == "spectator") {\r
3053                 //do nothing\r
3054         }\r
3055 \r
3056         /*\r
3057         float i;\r
3058         for(i = 0; i < 1000; ++i)\r
3059         {\r
3060                 vector end;\r
3061                 end = self.origin + '0 0 1024' + 512 * randomvec();\r
3062                 tracebox(self.origin, self.mins, self.maxs, end, MOVE_NORMAL, self);\r
3063                 if(trace_fraction < 1)\r
3064                 if(!(trace_dphitq3surfaceflags & Q3SURFACEFLAG_NOIMPACT))\r
3065                 {\r
3066                         print("I HIT SOLID: ", vtos(self.origin), " -> ", vtos(end), "\n");\r
3067                         break;\r
3068                 }\r
3069         }\r
3070         */\r
3071 \r
3072         Arena_Warmup();\r
3073 \r
3074         //pointparticles(particleeffectnum("machinegun_impact"), self.origin + self.view_ofs + '0 0 7', '0 0 0', 1);\r
3075 \r
3076         if(self.waypointsprite_attachedforcarrier)\r
3077                 WaypointSprite_UpdateHealth(self.waypointsprite_attachedforcarrier, '1 0 0' * healtharmor_maxdamage(self.health, self.armorvalue, cvar("g_balance_armor_blockpercent")));\r
3078         \r
3079         playerdemo_write();\r
3080 \r
3081         /*\r
3082         if(g_race)\r
3083                 dprint(sprintf("%f %.6f\n", time, race_GetFractionalLapCount(self)));\r
3084         */\r
3085 }\r