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