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