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