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