]> icculus.org git repositories - divverent/nexuiz.git/blob - data/qcsrc/server/gamec/cl_client.c
- added wisellama's advanced bash script (nexuiz-linux.sh can now be symlinked to...
[divverent/nexuiz.git] / data / qcsrc / server / gamec / cl_client.c
1 void info_player_start (void)
2 {
3         self.classname = "info_player_deathmatch";
4 }
5
6 void info_player_deathmatch (void)
7 {
8 }
9
10 float spawn_goodspots, spawn_badspots;
11 entity Spawn_ClassifyPoints(entity firstspot, entity playerlist, float mindist, float goodspotnum, float badspotnum)
12 {
13         local entity spot, player;
14         local float pcount;
15         local string spotname;
16         spawn_goodspots = 0;
17         spawn_badspots = 0;
18         spot = firstspot;
19         while (spot)
20         {
21                 pcount = 0;
22                 player = playerlist;
23                 while (player)
24                 {
25                         if (player != self)
26                         if (vlen(player.origin - spot.origin) < 100)
27                                 pcount = pcount + 1;
28                         player = player.chain;
29                 }
30                 if (pcount)
31                 {
32                         if (spawn_goodspots >= badspotnum)
33                                 return spot;
34                         spawn_badspots = spawn_badspots + 1;
35                 }
36                 else
37                 {
38                         if (spawn_goodspots >= goodspotnum)
39                                 return spot;
40                         spawn_goodspots = spawn_goodspots + 1;
41                 }
42                 if(cvar("g_ctf"))
43                 {
44                         if(self.team == 5)//4)
45                                 spotname = "info_player_team1";
46                         if(self.team == 14)//13)
47                                 spotname = "info_player_team2";
48                         if(self.team == 10)//9)
49                                 spotname = "info_player_team3";
50                         if(self.team == 13)//12)
51                                 spotname = "info_player_team4";
52                         spot = find(spot, classname, spotname);
53                 }
54                 else
55                         spot = find(spot, classname, "info_player_deathmatch");
56         }
57         return firstspot;
58 }
59
60 entity Spawn_FurthestPoint(entity firstspot, entity playerlist)
61 {
62         local entity best, spot, player;
63         local float bestrating, rating;
64         best = world;
65         bestrating = -1000000;
66         spot = firstspot;
67         while (spot)
68         {
69                 rating = 1000000000;
70                 player = playerlist;
71                 while (player)
72                 {
73                         if (player != self)
74                                 rating = min(rating, vlen(player.origin - spot.origin));
75                         player = player.chain;
76                 }
77                 rating = rating + random() * 16;
78                 if (bestrating < rating)
79                 {
80                         best = spot;
81                         bestrating = rating;
82                 }
83                 spot = find(spot, classname, "info_player_deathmatch");
84         }
85         return best;
86 }
87
88 /*
89 =============
90 SelectSpawnPoint
91
92 Finds a point to respawn
93 =============
94 */
95 entity SelectSpawnPoint (float anypoint)
96 {
97         local entity spot, firstspot, playerlist;
98         string spotname;
99
100         spot = find (world, classname, "testplayerstart");
101         if (spot)
102                 return spot;
103
104         spotname = "info_player_deathmatch";
105
106         if(!anypoint && cvar("g_ctf") )
107         {
108                 if(self.team == 5)//4)
109                         spotname = "info_player_team1";
110                 if(self.team == 14)//13)
111                         spotname = "info_player_team2";
112                 if(self.team == 10)//9)
113                         spotname = "info_player_team3";
114                 if(self.team == 13)//12)
115                         spotname = "info_player_team4";
116         }
117
118         playerlist = findchain(classname, "player");
119         firstspot = find(world, classname, spotname);
120         Spawn_ClassifyPoints(firstspot, playerlist, 100, 1000000, 1000000);
121         // first check if there are ANY good spots
122         if (spawn_goodspots > 0)
123         {
124                 // good spots exist, there is 50/50 chance of choosing a random good
125                 // spot or the furthest spot
126                 // (this means that roughly every other spawn will be furthest, so you
127                 // usually won't get fragged at spawn twice in a row)
128                 if (random() > 0.5)
129                         spot = Spawn_ClassifyPoints(firstspot, playerlist, 100, min(floor(random() * spawn_goodspots), spawn_goodspots - 1), 1000000);
130                 else
131                         spot = Spawn_FurthestPoint(firstspot, playerlist);
132         }
133         else
134         {
135                 // no good spots exist, pick a random bad spot
136                 spot = Spawn_ClassifyPoints(firstspot, playerlist, 100, 1000000, min(floor(random() * spawn_badspots), spawn_badspots - 1));
137         }
138         if (!spot)
139         {
140                 if(anypoint)
141                         error ("PutClientInServer: no start points on level");
142                 else // try again with deathmatch spots
143                         spot = SelectSpawnPoint(TRUE);
144         }
145
146         return spot;
147 }
148
149 /*
150 =============
151 CheckPlayerModel
152
153 Checks if the argument string can be a valid playermodel.
154 Returns a valid one in doubt.
155 =============
156 */
157 string CheckPlayerModel(string plyermodel) {
158         if( substring(plyermodel,0,14) != "models/player/") plyermodel = "models/player/marine.zym";
159
160         /* Possible Fixme: Check if server can open the model?
161            This would kill custom models, however. */
162
163         return plyermodel;
164 }
165
166 /*
167 =============
168 PutObserverInServer
169
170 putting a client as observer in the server
171 =============
172 */
173 void PutObserverInServer (void)
174 {
175         entity  spot;
176         spot = SelectSpawnPoint (FALSE);
177         RemoveGrapplingHook(self); // Wazat's Grappling Hook
178
179         if(self.frags == 0 && cvar("g_lms") && self.killcount != -666)
180                 bprint (strcat("^4", self.netname, "^4 has no more lives left\n"));
181         else if(self.killcount != -666)
182                 bprint (strcat("^4", self.netname, "^4 is spectating now\n"));
183
184         self.classname = "observer";
185         self.health = -666;
186         self.takedamage = DAMAGE_NO;
187         self.solid = SOLID_NOT;
188         self.movetype = MOVETYPE_NOCLIP;
189         self.flags = FL_CLIENT | FL_NOTARGET;
190         self.armorvalue = 666;
191         self.effects = 0;
192         self.armorvalue = cvar("g_balance_armor_start");
193         self.pauserotarmor_finished = 0;
194         self.pauserothealth_finished = 0;
195         self.pauseregen_finished = 0;
196         self.damageforcescale = 0;
197         self.death_time = 0;
198         self.dead_time = 0;
199         self.dead_frame = 0;
200         self.die_frame = 0;
201         self.alpha = 0;
202         self.scale = 0;
203         self.fade_time = 0;
204         self.pain_frame = 0;
205         self.pain_finished = 0;
206         self.strength_finished = 0;
207         self.invincible_finished = 0;
208         self.pushltime = 0;
209         self.think = SUB_Null;
210         self.nextthink = 0;
211         self.hook_time = 0;
212         self.runes = 0;
213         self.deadflag = DEAD_NO;
214         self.angles = spot.angles;
215         self.angles_z = 0;
216         self.fixangle = TRUE;
217         self.crouch = FALSE;
218         self.view_ofs = PL_VIEW_OFS;
219         setorigin (self, spot.origin + '0 0 1' * (1 - self.mins_z - 14));
220         self.oldorigin = self.origin;
221         self.items = 0;
222         self.model = "";
223         self.modelindex = 0;
224         self.weapon = 0;
225         self.weaponmodel = "";
226         self.weaponframe = 0;
227         self.weaponentity = world;
228         self.killcount = -666;
229         if(!cvar("g_lms"))
230                 self.frags = -666;
231         //stuffcmd(self, "set viewsize 120 \n");
232 //      bprint (strcat("^4", self.netname, "^4 is spectating now\n"));
233 }
234
235
236 /*
237 =============
238 PutClientInServer
239
240 Called when a client spawns in the server
241 =============
242 */
243 void PutClientInServer (void)
244 {
245         if(clienttype(self) ==  CLIENTTYPE_BOT)
246         {
247                 self.classname = "player";
248         }
249
250         // player is dead and becomes observer
251         if(cvar("g_lms") && self.frags < 1)
252                 self.classname = "observer";
253
254         if(self.classname == "player") {
255                 entity  spot;
256
257                 spot = SelectSpawnPoint (FALSE);
258
259                 RemoveGrapplingHook(self); // Wazat's Grappling Hook
260
261                 self.classname = "player";
262                 self.iscreature = TRUE;
263                 self.movetype = MOVETYPE_WALK;
264                 self.solid = SOLID_SLIDEBOX;
265                 self.flags = FL_CLIENT;
266                 self.takedamage = DAMAGE_AIM;
267                 self.effects = 0;
268                 self.health = cvar("g_balance_health_start");
269                 self.armorvalue = cvar("g_balance_armor_start");
270                 self.spawnshieldtime = time + cvar("g_spawnshieldtime");
271                 self.pauserotarmor_finished = time + 10;
272                 self.pauserothealth_finished = time + 10;
273                 self.pauseregen_finished = 0;
274                 self.damageforcescale = 2;
275                 self.death_time = 0;
276                 self.dead_time = 0;
277                 self.dead_frame = 0;
278                 self.die_frame = 0;
279                 self.alpha = 0;
280                 self.scale = 0;
281                 self.fade_time = 0;
282                 self.pain_frame = 0;
283                 self.pain_finished = 0;
284                 self.strength_finished = 0;
285                 self.invincible_finished = 0;
286                 self.pushltime = 0;
287                 //self.speed_finished = 0;
288                 //self.slowmo_finished = 0;
289                 // players have no think function
290                 self.think = SUB_Null;
291                 self.nextthink = 0;
292
293                 self.hook_time = 0;
294
295                 self.runes = 0;
296
297                 self.deadflag = DEAD_NO;
298
299                 self.angles = spot.angles;
300
301                 self.angles_z = 0; // never spawn tilted even if the spot says to
302                 self.fixangle = TRUE; // turn this way immediately
303                 self.velocity = '0 0 0';
304                 self.avelocity = '0 0 0';
305                 self.punchangle = '0 0 0';
306                 self.punchvector = '0 0 0';
307                 self.oldvelocity = self.velocity;
308
309                 self.viewzoom = 0.6;
310
311                 if(cvar("sv_defaultcharacter") == 1) {
312                         local string defaultmodel;
313                         defaultmodel = CheckPlayerModel(cvar_string("sv_defaultplayermodel"));
314
315                         precache_model (defaultmodel);
316                         setmodel (self, defaultmodel);
317                         self.skin = stof(cvar_string("sv_defaultplayerskin"));
318                 } else {
319                         self.playermodel = CheckPlayerModel(self.playermodel);
320
321                         precache_model (self.playermodel);
322                         setmodel (self, self.playermodel);
323                         self.skin = stof(self.playerskin);
324
325                 }
326
327                 self.crouch = FALSE;
328                 self.view_ofs = PL_VIEW_OFS;
329                 setsize (self, PL_MIN, PL_MAX);
330                 setorigin (self, spot.origin + '0 0 1' * (1 - self.mins_z - 24));
331                 // don't reset back to last position, even if new position is stuck in solid
332                 self.oldorigin = self.origin;
333
334                 if(cvar("g_lms"))
335                 {
336                         self.ammo_shells = cvar("g_lms_start_ammo_shells");
337                         self.ammo_nails = cvar("g_lms_start_ammo_nails");
338                         self.ammo_rockets = cvar("g_lms_start_ammo_rockets");
339                         self.ammo_cells = cvar("g_lms_start_ammo_cells");
340                         self.health = cvar("g_lms_start_health");
341                         self.armorvalue = cvar("g_lms_start_armor");
342                 }
343                 else if (cvar("g_use_ammunition")) {
344                         self.ammo_shells = cvar("g_start_ammo_shells");
345                         self.ammo_nails = cvar("g_start_ammo_nails");
346                         self.ammo_rockets = cvar("g_start_ammo_rockets");
347                         self.ammo_cells = cvar("g_start_ammo_cells");
348                 } else {
349                         self.ammo_shells = 999;
350                         self.ammo_nails = 999;
351                         self.ammo_rockets = 999;
352                         self.ammo_cells = 999;
353                 }
354
355                 self.items = 0;
356                 if (cvar("g_start_weapon_laser") || cvar("g_lms"))
357                 {
358                         self.items = self.items | IT_LASER;
359                         self.switchweapon = WEP_LASER;
360                 }
361                 if (cvar("g_start_weapon_shotgun") || cvar("g_lms"))
362                 {
363                         self.items = self.items | IT_SHOTGUN;
364                         self.switchweapon = WEP_SHOTGUN;
365                 }
366                 if (cvar("g_start_weapon_uzi") || cvar("g_lms"))
367                 {
368                         self.items = self.items | IT_UZI;
369                         self.switchweapon = WEP_UZI;
370                 }
371                 if (cvar("g_start_weapon_grenadelauncher") || cvar("g_lms"))
372                 {
373                         self.items = self.items | IT_GRENADE_LAUNCHER;
374                         self.switchweapon = WEP_GRENADE_LAUNCHER;
375                 }
376                 if (cvar("g_start_weapon_electro") || cvar("g_lms"))
377                 {
378                         self.items = self.items | IT_ELECTRO;
379                         self.switchweapon = WEP_ELECTRO;
380                 }
381                 if (cvar("g_start_weapon_crylink") || cvar("g_lms"))
382                 {
383                         self.items = self.items | IT_CRYLINK;
384                         self.switchweapon = WEP_CRYLINK;
385                 }
386                 if (cvar("g_start_weapon_nex") || cvar("g_lms"))
387                 {
388                         self.items = self.items | IT_NEX;
389                         self.switchweapon = WEP_NEX;
390                 }
391                 if (cvar("g_start_weapon_hagar") || cvar("g_lms"))
392                 {
393                         self.items = self.items | IT_HAGAR;
394                         self.switchweapon = WEP_HAGAR;
395                 }
396                 if (cvar("g_start_weapon_rocketlauncher") || cvar("g_lms"))
397                 {
398                         self.items = self.items | IT_ROCKET_LAUNCHER;
399                         self.switchweapon = WEP_ROCKET_LAUNCHER;
400                 }
401
402                 if(cvar("g_instagib"))
403                 {
404                         self.items = IT_NEX;
405                         self.switchweapon = WEP_NEX;
406                         self.ammo_cells = 999;
407                 }
408
409                 if(cvar("g_rocketarena"))
410                 {
411                         self.items = IT_ROCKET_LAUNCHER;
412                         self.switchweapon = WEP_ROCKET_LAUNCHER;
413                         self.ammo_rockets = 999;
414                 }
415
416                 if(cvar("g_minstagib"))
417                 {
418                         self.health = 100;
419                         self.armorvalue = 0;
420                         self.items = IT_NEX;
421                         self.switchweapon = WEP_NEX;
422                         self.ammo_cells = cvar("g_minstagib_ammo_start");
423                         self.extralives = 0;
424                         self.jump_interval = time;
425                 }
426
427                 self.event_damage = PlayerDamage;
428
429                 self.statdraintime = time + 5;
430                 self.button0 = self.button1 = self.button2 = self.button3 = 0;
431
432                 if(self.killcount == -666) {
433                         self.killcount = 0;
434                         self.frags = 0;
435                 }
436
437                 self.cnt = WEP_LASER;
438
439                 /*
440                 W_UpdateWeapon();
441                 W_UpdateAmmo();
442                 */
443                 CL_SpawnWeaponentity();
444                 self.alpha = 1;
445                 self.exteriorweaponentity.alpha = 1;
446
447                 self.lms_nextcheck = time + cvar("g_lms_campcheck_interval");
448                 self.lms_traveled_distance = 0;
449
450                 //stuffcmd(self, "chase_active 0");
451                 //stuffcmd(self, "set viewsize $tmpviewsize \n");
452         } else if(self.classname == "observer") {
453                 PutObserverInServer ();
454         }
455 }
456
457 /*
458 =============
459 SetNewParms
460 =============
461 */
462 void SetNewParms (void)
463 {
464
465 }
466
467 /*
468 =============
469 SetChangeParms
470 =============
471 */
472 void SetChangeParms (void)
473 {
474
475 }
476
477 /*
478 =============
479 ClientKill
480
481 Called when a client types 'kill' in the console
482 =============
483 */
484 void ClientKill (void)
485 {
486         Damage(self, self, self, 100000, DEATH_KILL, self.origin, '0 0 0');
487 }
488
489 /*
490 =============
491 ClientConnect
492
493 Called when a client connects to the server
494 =============
495 */
496 string ColoredTeamName(float t);
497 //void dom_player_join_team(entity pl);
498 void ClientConnect (void)
499 {
500         self.classname = "player_joining";
501
502         if(player_count<0) player_count = 0;
503
504         //if(cvar("g_domination"))
505         //      dom_player_join_team(self);
506
507         //JoinBestTeam(self, FALSE);
508         if(cvar("teamplay") && self.version == cvar("g_nexuizversion_major")) stuffcmd(self,"menu_showteamselect\n");
509
510
511         if(cvar("sv_spectate") == 1 && !cvar("g_lms")) {
512                 self.classname = "observer";
513         } else {
514                 self.classname = "player";
515         }
516
517         //stuffcmd(self, "set tmpviewsize $viewsize \n");
518
519         bprint ("^4",self.netname);
520         bprint ("^4 connected");
521
522         if(cvar("g_domination") || cvar("g_ctf"))
523         {
524                 bprint(" and joined the ");
525                 bprint(ColoredTeamName(self.team));
526         }
527
528         bprint("\n");
529
530         self.welcomemessage_time = time + cvar("welcome_message_time");
531         self.welcomemessage_time2 = 0;
532
533         stuffcmd(self, strcat("exec maps/", mapname, ".cfg\n"));
534         // send prediction settings to the client
535         stuffcmd(self, strcat("cl_movement_maxspeed ", ftos(cvar("sv_maxspeed")), "\n"));
536         stuffcmd(self, strcat("cl_movement_maxairspeed ", ftos(cvar("sv_maxairspeed")), "\n"));
537         stuffcmd(self, strcat("cl_movement_accelerate ", ftos(cvar("sv_accelerate")), "\n"));
538         stuffcmd(self, strcat("cl_movement_friction ", ftos(cvar("sv_friction")), "\n"));
539         stuffcmd(self, strcat("cl_movement_stopspeed ", ftos(cvar("sv_stopspeed")), "\n"));
540         stuffcmd(self, strcat("cl_movement_jumpvelocity ", ftos(cvar("g_balance_jumpheight")), "\n"));
541         stuffcmd(self, strcat("cl_movement_stepheight ", ftos(cvar("sv_stepheight")), "\n"));
542         stuffcmd(self, strcat("cl_movement_edgefriction 0\n"));
543         // Wazat's grappling hook
544         SetGrappleHookBindings();
545
546         // get autoswitch state from player
547         stuffcmd(self, "alias autoswitch \"set cl_autoswitch $1; cmd autoswitch $1\"\n");
548         stuffcmd(self, "cmd autoswitch $cl_autoswitch\n");
549
550         // get version info from player
551         stuffcmd(self, "cmd clientversion $g_nexuizversion_major\n");
552
553         // set cvar for team scoreboard
554         stuffcmd(self, strcat("set teamplay ", ftos(teams_matter), "\n"));
555
556         if(cvar("g_lms"))
557         {
558                 self.frags = cvar("fraglimit");
559                 // no fraglimit was set, so player gets 999 lives
560                 if(self.frags < 1)
561                         self.frags = 999;
562
563                 // disallow player to join after the worst player has lost g_lms_last_join lives
564                 // if "g_lms_join_anytime" new players spawn with same amount of lives as the worst active player
565                 if(((cvar("fraglimit") - cvar("g_lms_last_join")) > lms_lowest_lives && !cvar("g_lms_join_anytime")) || lms_lowest_lives < 1)
566                 {
567                         self.frags = -1;
568                         lms_dead_count += 1;
569                 }
570                 else if(cvar("fraglimit") > lms_lowest_lives)
571                 {
572                         self.frags = lms_lowest_lives;
573                 }
574         }
575
576         player_count += 1;
577         self.jointime = time;
578 }
579
580 /*
581 =============
582 ClientDisconnect
583
584 Called when a client disconnects from the server
585 =============
586 */
587 .entity chatbubbleentity;
588 .entity teambubbleentity;
589 void ClientDisconnect (void)
590 {
591         bprint ("^4",self.netname);
592         bprint ("^4 disconnected\n");
593
594         if (self.chatbubbleentity)
595         {
596                 remove (self.chatbubbleentity);
597                 self.chatbubbleentity = world;
598         }
599
600         if (self.teambubbleentity)
601         {
602                 remove (self.teambubbleentity);
603                 self.teambubbleentity = world;
604         }
605
606         DropAllRunes(self);
607         // decrease player count for lms
608         player_count -= 1;
609         // player was dead, decrease dead count
610         if(cvar("g_lms") && self.frags < 1)
611                 lms_dead_count -= 1;
612         //stuffcmd(self, "set viewsize $tmpviewsize \n");
613 }
614
615 .float buttonchat;
616 void() ChatBubbleThink =
617 {
618         self.nextthink = time;
619         if (!self.owner.modelindex || self.owner.chatbubbleentity != self)
620         {
621                 remove(self);
622                 return;
623         }
624         setorigin(self, self.owner.origin + '0 0 15' + self.owner.maxs_z * '0 0 1');
625         if (self.owner.buttonchat && !self.owner.deadflag)
626                 self.model = self.mdl;
627         else
628                 self.model = "";
629 };
630
631 void() UpdateChatBubble =
632 {
633         if (!self.modelindex)
634                 return;
635         // spawn a chatbubble entity if needed
636         if (!self.chatbubbleentity)
637         {
638                 self.chatbubbleentity = spawn();
639                 self.chatbubbleentity.owner = self;
640                 self.chatbubbleentity.exteriormodeltoclient = self;
641                 self.chatbubbleentity.think = ChatBubbleThink;
642                 self.chatbubbleentity.nextthink = time;
643                 setmodel(self.chatbubbleentity, "models/misc/chatbubble.spr");
644                 setorigin(self.chatbubbleentity, self.origin + '0 0 15' + self.maxs_z * '0 0 1');
645                 self.chatbubbleentity.mdl = self.chatbubbleentity.model;
646                 self.chatbubbleentity.model = "";
647         }
648 }
649
650
651 void() TeamBubbleThink =
652 {
653         self.nextthink = time;
654         if (!self.owner.modelindex || self.owner.teambubbleentity != self)
655         {
656                 remove(self);
657                 return;
658         }
659 //      setorigin(self, self.owner.origin + '0 0 15' + self.owner.maxs_z * '0 0 1');  // bandwidth hog. setattachment does this now
660         if (self.owner.buttonchat || self.owner.deadflag)
661                 self.model = "";
662         else
663                 self.model = self.mdl;
664
665 };
666
667 .float() customizeentityforclient;
668 float() ChatBubble_customizeentityforclient = {return (self.owner.team == other.team && other.killcount > -666);};
669
670 void() UpdateTeamBubble =
671 {
672         if (!self.modelindex || !cvar("teamplay"))
673                 return;
674         // spawn a teambubble entity if needed
675         if (!self.teambubbleentity && cvar("teamplay"))
676         {
677                 self.teambubbleentity = spawn();
678                 self.teambubbleentity.owner = self;
679                 self.teambubbleentity.exteriormodeltoclient = self;
680                 self.teambubbleentity.think = TeamBubbleThink;
681                 self.teambubbleentity.nextthink = time;
682                 setmodel(self.teambubbleentity, "models/misc/teambubble.spr");
683 //              setorigin(self.teambubbleentity, self.origin + '0 0 15' + self.maxs_z * '0 0 1');
684                 setorigin(self.teambubbleentity, self.teambubbleentity.origin + '0 0 15' + self.maxs_z * '0 0 1');
685                 setattachment(self.teambubbleentity, self, "");  // sticks to moving player better, also conserves bandwidth
686                 self.teambubbleentity.mdl = self.teambubbleentity.model;
687                 self.teambubbleentity.model = self.teambubbleentity.mdl;
688                 self.teambubbleentity.customizeentityforclient = ChatBubble_customizeentityforclient;
689         }
690 }
691
692 // LordHavoc: this hack will be removed when proper _pants/_shirt layers are
693 // added to the model skins
694 /*void() UpdateColorModHack =
695 {
696         local float c;
697         c = self.clientcolors & 15;
698         // LordHavoc: only bothering to support white, green, red, yellow, blue
699              if (teamplay == 0) self.colormod = '0 0 0';
700         else if (c ==  0) self.colormod = '1.00 1.00 1.00';
701         else if (c ==  3) self.colormod = '0.10 1.73 0.10';
702         else if (c ==  4) self.colormod = '1.73 0.10 0.10';
703         else if (c == 12) self.colormod = '1.22 1.22 0.10';
704         else if (c == 13) self.colormod = '0.10 0.10 1.73';
705         else self.colormod = '1 1 1';
706 };*/
707
708 void UpdatePlayerColors () {
709         if(self.weaponentity) {
710                 self.weaponentity.colormap = self.colormap;
711                 self.exteriorweaponentity.colormap = self.colormap;
712         }
713 }
714 /*
715 =============
716 PlayerJump
717
718 When you press the jump key
719 =============
720 */
721 void PlayerJump (void)
722 {
723         float mjumpheight;
724
725         mjumpheight = cvar("g_balance_jumpheight");
726         if (self.waterlevel >= 2)
727         {
728                 if (self.watertype == CONTENT_WATER)
729                         self.velocity_z = 200;
730                 else if (self.watertype == CONTENT_SLIME)
731                         self.velocity_z = 80;
732                 else
733                         self.velocity_z = 50;
734
735                 return;
736         }
737
738
739         if (!(self.flags & FL_ONGROUND))
740                 return;
741
742         if (!(self.flags & FL_JUMPRELEASED))
743                 return;
744
745         if(cvar("g_runematch"))
746         {
747                 if(self.runes & RUNE_SPEED)
748                 {
749                         if(self.runes & CURSE_SLOW)
750                                 mjumpheight = mjumpheight * cvar("g_balance_rune_speed_combo_jumpheight");
751                         else
752                                 mjumpheight = mjumpheight * cvar("g_balance_rune_speed_jumpheight");
753                 }
754                 else if(self.runes & CURSE_SLOW)
755                 {
756                         mjumpheight = mjumpheight * cvar("g_balance_curse_slow_jumpheight");
757                 }
758         }
759
760         if(cvar("g_minstagib") && (self.items & IT_INVINCIBLE))
761         {
762                 mjumpheight = mjumpheight * cvar("g_balance_rune_speed_jumpheight");
763         }
764
765         self.velocity_z = self.velocity_z + mjumpheight;
766         self.oldvelocity_z = self.velocity_z;
767
768         self.flags = self.flags - FL_ONGROUND;
769         self.flags = self.flags - FL_JUMPRELEASED;
770 }
771
772 void() CheckWaterJump =
773 {
774         local vector start, end;
775
776 // check for a jump-out-of-water
777         makevectors (self.angles);
778         start = self.origin;
779         start_z = start_z + 8;
780         v_forward_z = 0;
781         normalize(v_forward);
782         end = start + v_forward*24;
783         traceline (start, end, TRUE, self);
784         if (trace_fraction < 1)
785         {       // solid at waist
786                 start_z = start_z + self.maxs_z - 8;
787                 end = start + v_forward*24;
788                 self.movedir = trace_plane_normal * -50;
789                 traceline (start, end, TRUE, self);
790                 if (trace_fraction == 1)
791                 {       // open at eye level
792                         self.flags = self.flags | FL_WATERJUMP;
793                         self.velocity_z = 225;
794                         self.flags = self.flags - (self.flags & FL_JUMPRELEASED);
795                         self.teleport_time = time + 2;  // safety net
796                         return;
797                 }
798         }
799 };
800
801
802 void respawn(void)
803 {
804         CopyBody(1);
805         PutClientInServer();
806 }
807
808 void player_powerups (void)
809 {
810         if (cvar("g_minstagib"))
811         {
812                 self.effects = EF_FULLBRIGHT;
813                 if (self.items & IT_STRENGTH)
814                 {
815                         if (time > self.strength_finished)
816                         {
817                                 self.alpha = 1;
818                                 self.exteriorweaponentity.alpha = 1;
819                                 self.items = self.items - (self.items & IT_STRENGTH);
820                                 sprint(self, "^3Invisibility has worn off\n");
821                         }
822                 }
823                 else
824                 {
825                         if (time < self.strength_finished)
826                         {
827                                 self.alpha = cvar("g_minstagib_invis_alpha");
828                                 self.exteriorweaponentity.alpha = cvar("g_minstagib_invis_alpha");
829                                 self.items = self.items | IT_STRENGTH;
830                                 sprint(self, "^3You are invisible\n");
831                         }
832                 }
833
834                 if (self.items & IT_INVINCIBLE)
835                 {
836                         if (time > self.invincible_finished)
837                         {
838                                 self.items = self.items - (self.items & IT_INVINCIBLE);
839                                 sprint(self, "^3Speed has worn off\n");
840                         }
841                 }
842                 else
843                 {
844                         if (time < self.invincible_finished)
845                         {
846                                 self.items = self.items | IT_INVINCIBLE;
847                                 sprint(self, "^3You are on speed\n");
848                         }
849                 }
850                 return;
851         }
852
853         self.effects = self.effects - (self.effects & (EF_RED | EF_BLUE | EF_ADDITIVE | EF_FULLBRIGHT));
854         if (self.items & IT_STRENGTH)
855         {
856                 self.effects = self.effects | (EF_BLUE | EF_ADDITIVE | EF_FULLBRIGHT);
857                 if (time > self.strength_finished)
858                 {
859                         self.items = self.items - (self.items & IT_STRENGTH);
860                         sprint(self, "^3Strength has worn off\n");
861                 }
862         }
863         else
864         {
865                 if (time < self.strength_finished)
866                 {
867                         self.items = self.items | IT_STRENGTH;
868                         sprint(self, "^3Strength infuses your weapons with devestating power\n");
869                 }
870         }
871         if (self.items & IT_INVINCIBLE)
872         {
873                 self.effects = self.effects | (EF_RED | EF_ADDITIVE | EF_FULLBRIGHT);
874                 if (time > self.invincible_finished)
875                 {
876                         self.items = self.items - (self.items & IT_INVINCIBLE);
877                         sprint(self, "^3Shield has worn off\n");
878                 }
879         }
880         else
881         {
882                 if (time < self.invincible_finished)
883                 {
884                         self.items = self.items | IT_INVINCIBLE;
885                         sprint(self, "^3Shield surrounds you\n");
886                 }
887         }
888
889         if (cvar("g_fullbrightplayers"))
890                 self.effects = self.effects | EF_FULLBRIGHT;
891
892         // midair gamemode: damage only while in the air
893         // if in midair mode, being on ground grants temporary invulnerability
894         // (this is so that multishot weapon don't clear the ground flag on the
895         // first damage in the frame, leaving the player vulnerable to the
896         // remaining hits in the same frame)
897         if (self.flags & FL_ONGROUND)
898         if (cvar("g_midair"))
899                 self.spawnshieldtime = max(self.spawnshieldtime, time + cvar("g_midair_shieldtime"));
900
901         if (time < self.spawnshieldtime)
902                 self.effects = self.effects | (EF_ADDITIVE | EF_FULLBRIGHT);
903 }
904
905 void player_regen (void)
906 {
907         float maxh, maxa, max_mod, regen_mod, rot_mod;
908         maxh = cvar("g_balance_health_stable");
909         maxa = cvar("g_balance_armor_stable");
910
911         if (cvar("g_minstagib") || (cvar("g_lms") && !cvar("g_lms_regenerate")))
912                 return;
913
914         if(cvar("g_runematch"))
915         {
916                 max_mod = regen_mod = rot_mod = 1;
917                 if (self.runes & RUNE_REGEN)
918                 {
919                         if (self.runes & CURSE_VENOM) // do we have both rune/curse?
920                         {
921                                 regen_mod = cvar("g_balance_rune_regen_combo_regenrate");
922                                 max_mod = cvar("g_balance_rune_regen_combo_hpmod");
923                         }
924                         else
925                         {
926                                 regen_mod = cvar("g_balance_rune_regen_regenrate");
927                                 max_mod = cvar("g_balance_rune_regen_hpmod");
928                         }
929                 }
930                 else if (self.runes & CURSE_VENOM)
931                 {
932                         max_mod = cvar("g_balance_curse_venom_hpmod");
933                         if (self.runes & RUNE_REGEN) // do we have both rune/curse?
934                                 rot_mod = cvar("g_balance_rune_regen_combo_rotrate");
935                         else
936                                 rot_mod = cvar("g_balance_curse_venom_rotrate");
937                         //if (!self.runes & RUNE_REGEN)
938                         //      rot_mod = cvar("g_balance_curse_venom_rotrate");
939                 }
940                 maxh = maxh * max_mod;
941                 //maxa = maxa * max_mod;
942
943                 if (time > self.pauserotarmor_finished)
944                 {
945                         if (self.armorvalue > maxa)
946                                 self.armorvalue = bound(0, self.armorvalue + (maxa - self.armorvalue) * cvar("g_balance_armor_rot") * frametime, 1000);
947                 }
948                 if (time > self.pauserothealth_finished)
949                 {
950                         if (self.health > maxh)
951                                 self.health = bound(0, self.health + (maxh - self.health) * rot_mod*cvar("g_balance_health_rot") * frametime, 1000);
952                 }
953                 if (time > self.pauseregen_finished)
954                 {
955                         if (self.health < maxh)
956                                 self.health = bound(0, self.health + (maxh- self.health) * regen_mod*cvar("g_balance_health_regen") * frametime, 1000);
957                         if (self.armorvalue < maxa)
958                                 self.armorvalue = bound(0, self.armorvalue + (maxa - self.armorvalue) * cvar("g_balance_armor_regen") * frametime, 1000);
959                 }
960         }
961         else
962         {
963                 if (time > self.pauserothealth_finished)
964                 if (self.health > maxh)
965                         self.health = bound(0, self.health + (maxh - self.health) * cvar("g_balance_health_rot") * frametime, 1000);
966                 if (time > self.pauserotarmor_finished)
967                 if (self.armorvalue > maxa)
968                         self.armorvalue = bound(0, self.armorvalue + (maxa - self.armorvalue) * cvar("g_balance_armor_rot") * frametime, 1000);
969                 if (time > self.pauseregen_finished)
970                 {
971                         if (self.health < maxh)
972                                 self.health = bound(0, self.health + (maxh- self.health) * cvar("g_balance_health_regen") * frametime, 1000);
973                         if (self.armorvalue < maxa)
974                                 self.armorvalue = bound(0, self.armorvalue + (maxa - self.armorvalue) * cvar("g_balance_armor_regen") * frametime, 1000);
975                 }
976         }
977 }
978
979 /*
980 ======================
981 spectate mode routines
982 ======================
983 */
984 void SpectateCopy(entity spectatee) {
985         self.armortype = spectatee.armortype;
986         self.armorvalue = spectatee.armorvalue;
987         self.currentammo = spectatee.currentammo;
988         self.effects = spectatee.effects;
989         self.health = spectatee.health;
990         self.impulse = 0;
991         self.items = spectatee.items;
992         self.punchangle = spectatee.punchangle;
993         self.view_ofs = spectatee.view_ofs;
994         self.v_angle = spectatee.v_angle;
995         self.viewzoom = spectatee.viewzoom;
996         setorigin(self, spectatee.origin);
997         setsize(self, spectatee.mins, spectatee.maxs);
998 }
999
1000 void SpectateUpdate() {
1001         if (self != self.enemy) {
1002                 SpectateCopy(self.enemy);
1003                 msg_entity = self;
1004                 WriteByte(MSG_ONE, SVC_SETANGLE);
1005                 WriteAngle(MSG_ONE, self.enemy.v_angle_x);
1006                 WriteAngle(MSG_ONE, self.enemy.v_angle_y);
1007                 WriteAngle(MSG_ONE, self.enemy.v_angle_z);
1008         }
1009 }
1010
1011 float SpectateNext() {
1012         other = find(self.enemy, classname, "player");
1013         if (!other) {
1014                 other = find(other, classname, "player");
1015         }
1016         if (other) {
1017                 self.enemy = other;
1018         }
1019         if(self.enemy.classname == "player") {
1020                 msg_entity = self;
1021                 WriteByte(MSG_ONE, SVC_SETVIEW);
1022                 WriteEntity(MSG_ONE, self.enemy);
1023                 //stuffcmd(self, "set viewsize $tmpviewsize \n");
1024                 SpectateUpdate();
1025                 return 1;
1026         } else {
1027                 return 0;
1028         }
1029 }
1030
1031 /*
1032 =============
1033 PlayerPreThink
1034
1035 Called every frame for each client before the physics are run
1036 =============
1037 */
1038 void PlayerPreThink (void)
1039 {
1040         if(self.classname == "player") {
1041                 local vector m1, m2;
1042
1043 //              MauveBot_AI();
1044
1045 //              if(self.netname == "Wazat")
1046 //                      bprint(strcat(self.classname, "\n"));
1047
1048                 CheckRules_Player();
1049
1050                 if (intermission_running)
1051                 {
1052                         IntermissionThink ();   // otherwise a button could be missed between
1053                         return;                                 // the think tics
1054                 }
1055
1056                 if (self.deadflag != DEAD_NO)
1057                 {
1058                         player_anim();
1059                         weapon_freeze();
1060                         if (self.deadflag == DEAD_DYING)
1061                         {
1062                                 if (time > self.dead_time)
1063                                         self.deadflag = DEAD_DEAD;
1064                         }
1065                         else if (self.deadflag == DEAD_DEAD)
1066                         {
1067                                 if (!self.button0 && !self.button2 && !self.button3)
1068                                         self.deadflag = DEAD_RESPAWNABLE;
1069                         }
1070                         else if (self.deadflag == DEAD_RESPAWNABLE)
1071                         {
1072                                 if (self.button0  ||
1073                                     self.button2  ||
1074                                     self.button3  ||
1075                                     self.button4  ||
1076                                     cvar("g_lms") ||
1077                                     cvar("g_forced_respawn"))
1078                                         respawn();
1079                         }
1080                         return;
1081                 }
1082
1083                 if(cvar("g_lms") && !self.deadflag && cvar("g_lms_campcheck_interval"))
1084                 {
1085                         vector dist;
1086
1087                         // calculate player movement (in 2 dimensions only, so jumping on one spot doesn't count as movement)
1088                         dist = self.oldorigin - self.origin;
1089                         dist_z = 0;
1090                         self.lms_traveled_distance += fabs(vlen(dist));
1091                         
1092                         if(time > self.lms_nextcheck)
1093                         {
1094                                 //sprint(self, "distance: ", ftos(self.lms_traveled_distance), "\n");
1095                                 if(self.lms_traveled_distance < cvar("g_lms_campcheck_distance"))
1096                                 {
1097                                         centerprint(self, cvar_string("g_lms_campcheck_message"));
1098                                         Damage(self, self, self, cvar("g_lms_campcheck_damage"), DEATH_CAMP, self.origin, '0 0 0');
1099                                 }
1100                                 self.lms_nextcheck = time + cvar("g_lms_campcheck_interval");
1101                                 self.lms_traveled_distance = 0;
1102                         }
1103                 }
1104
1105                 if (self.button5)
1106                 {
1107                         if (!self.crouch)
1108                         {
1109                                 self.crouch = TRUE;
1110                                 self.view_ofs = PL_CROUCH_VIEW_OFS;
1111                                 setsize (self, PL_CROUCH_MIN, PL_CROUCH_MAX);
1112                         }
1113                 }
1114                 else
1115                 {
1116                         if (self.crouch)
1117                         {
1118                                 tracebox(self.origin, PL_MIN, PL_MAX, self.origin, FALSE, self);
1119                                 if (!trace_startsolid)
1120                                 {
1121                                         self.crouch = FALSE;
1122                                         self.view_ofs = PL_VIEW_OFS;
1123                                         setsize (self, PL_MIN, PL_MAX);
1124                                 }
1125                         }
1126                 }
1127
1128                 if(cvar("sv_defaultcharacter") == 1) {
1129                         local string defaultmodel;
1130                         defaultmodel = CheckPlayerModel(cvar_string("sv_defaultplayermodel"));
1131
1132                         if (defaultmodel != self.model)
1133                         {
1134                                 m1 = self.mins;
1135                                 m2 = self.maxs;
1136                                 precache_model (defaultmodel);
1137                                 setmodel (self, defaultmodel);
1138                                 setsize (self, m1, m2);
1139                         }
1140
1141                         if (self.skin != stof(cvar_string("sv_defaultplayerskin")))
1142                                 self.skin = stof(cvar_string("sv_defaultplayerskin"));
1143                 } else {
1144                         if (self.playermodel != self.model)
1145                         {
1146                                 self.playermodel = CheckPlayerModel(self.playermodel);
1147                                 m1 = self.mins;
1148                                 m2 = self.maxs;
1149                                 precache_model (self.playermodel);
1150                                 setmodel (self, self.playermodel);
1151                                 setsize (self, m1, m2);
1152                         }
1153
1154                         if (self.skin != stof(self.playerskin))
1155                                 self.skin = stof(self.playerskin);
1156                 }
1157                 // Savage: Check for nameless players
1158                 if (strlen(self.netname) < 1) {
1159                         self.netname = "Player";
1160                         stuffcmd(self, "name Player\n");
1161                 }
1162
1163                 GrapplingHookFrame();
1164
1165                 W_WeaponFrame();
1166
1167                 if (self.button4 || (self.weapon == WEP_NEX && self.button3))
1168                 {
1169                         if (cvar("g_minstagib") && self.button3)
1170                         {
1171                                 if (self.jump_interval <= (time + 0.1))
1172                                 {
1173                                         self.jump_interval = time + 1;
1174                                         weapon_doattack(laser_check, laser_check, W_Laser_Attack);
1175                                 }
1176                         }
1177                         else if (self.viewzoom > 0.4)
1178                                 self.viewzoom = max (0.4, self.viewzoom - frametime * 2);
1179                 }
1180                 else if (self.viewzoom < 1.0)
1181                         self.viewzoom = min (1.0, self.viewzoom + frametime);
1182
1183
1184                 if (self.button2)
1185                         PlayerJump ();
1186                 else
1187                         self.flags = self.flags | FL_JUMPRELEASED;
1188
1189                 player_powerups();
1190                 player_regen();
1191                 player_anim();
1192
1193                 //self.angles_y=self.v_angle_y + 90;   // temp
1194
1195                 if (self.waterlevel == 2)
1196                         CheckWaterJump ();
1197
1198                 //if (TetrisPreFrame()) return;
1199         } else if(gameover) {
1200                 if (intermission_running)
1201                         IntermissionThink ();   // otherwise a button could be missed between
1202                 return;
1203         } else if(self.classname == "observer") {
1204
1205                 if (self.flags & FL_JUMPRELEASED) {
1206                         if (self.button2 && self.version == cvar("g_nexuizversion_major")) {
1207                                 if(!cvar("teamplay")) {
1208                                         self.flags = self.flags & !FL_JUMPRELEASED;
1209                                         self.classname = "player";
1210                                         if(!cvar("g_lms"))
1211                                                 bprint (strcat("^4", self.netname, "^4 is playing now\n"));
1212                                         PutClientInServer();
1213                                         centerprint(self,"");
1214                                         return;
1215                                 } else {
1216                                         self.flags = self.flags & !FL_JUMPRELEASED;
1217                                         stuffcmd(self,"menu_showteamselect\n");
1218                                         return;
1219                                 }
1220                         } else if(self.button0 && self.version == cvar("g_nexuizversion_major")) {
1221                                 self.flags = self.flags & !FL_JUMPRELEASED;
1222                                 if(SpectateNext() == 1) {
1223                                         self.classname = "spectator";
1224                                 }
1225                         }
1226                 } else {
1227                         if (!(self.button0 || self.button2)) {
1228                                 self.flags = self.flags | FL_JUMPRELEASED;
1229                         }
1230                 }
1231                 if(cvar("g_lms") && self.frags == 0)
1232                         centerprint(self, "\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n^1You have no more lives left\nwait for next round\n\n\n^7press attack to spectate other players");
1233                 else if(cvar("g_lms") && self.frags == -1)
1234                         centerprint(self, "\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n^1Match has already begun\nwait for next round\n\n\n^7press attack to spectate other players");
1235                 else
1236                         PrintWelcomeMessage(self);
1237                         //centerprint(self, "\n\n\npress jump to play\npress attack to spectate other players");
1238         } else if(self.classname == "spectator") {
1239
1240                 if (self.flags & FL_JUMPRELEASED) {
1241                         if (self.button2 && self.version == cvar("g_nexuizversion_major")) {
1242                                 if(!cvar("teamplay")) {
1243                                         self.flags = self.flags & !FL_JUMPRELEASED;
1244                                         self.classname = "player";
1245                                         if(!cvar("g_lms"))
1246                                                 bprint (strcat("^4", self.netname, "^4 is playing now\n"));
1247
1248                                         msg_entity = self;
1249                                         WriteByte(MSG_ONE, SVC_SETVIEW);
1250                                         WriteEntity(MSG_ONE, self);
1251                                         PutClientInServer();
1252                                         centerprint(self,"");
1253                                         return;
1254                                 } else {
1255                                         self.flags = self.flags & !FL_JUMPRELEASED;
1256                                         stuffcmd(self,"menu_showteamselect\n");
1257                                         return;
1258                                 }
1259                         } else if(self.button0) {
1260                                 self.flags = self.flags & !FL_JUMPRELEASED;
1261                                 if(SpectateNext() == 1) {
1262                                         self.classname = "spectator";
1263                                 } else {
1264                                         self.classname = "observer";
1265                                         msg_entity = self;
1266                                         WriteByte(MSG_ONE, SVC_SETVIEW);
1267                                         WriteEntity(MSG_ONE, self);
1268                                         PutClientInServer();
1269                                 }
1270                         } else if (self.button3) {
1271                                 self.flags = self.flags & !FL_JUMPRELEASED;
1272                                 self.classname = "observer";
1273                                 msg_entity = self;
1274                                 WriteByte(MSG_ONE, SVC_SETVIEW);
1275                                 WriteEntity(MSG_ONE, self);
1276                                 PutClientInServer();
1277                         } else {
1278                                 SpectateUpdate();
1279                         }
1280         } else {
1281                 if (!(self.button0 || self.button3)) {
1282                         self.flags = self.flags | FL_JUMPRELEASED;
1283                 }
1284                 }
1285                 if (cvar("g_lms") && self.frags < 1)
1286                         centerprint(self, strcat("\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\nspectating ", self.enemy.netname, "\n\n\n^7press attack for next player\npress attack2 for free fly mode"));
1287                 else
1288                         centerprint(self, strcat("\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\nspectating ", self.enemy.netname, "\n\n\n^7press jump to play\n^7press attack for next player\npress attack2 for free fly mode"));
1289
1290         }
1291 }
1292
1293 /*
1294 =============
1295 PlayerPostThink
1296
1297 Called every frame for each client after the physics are run
1298 =============
1299 */
1300 void PlayerPostThink (void)
1301 {
1302         if(self.classname == "player") {
1303                 CheckRules_Player();
1304                 UpdateChatBubble();
1305                 UpdateTeamBubble();
1306                 UpdatePlayerColors();
1307                 if (self.deadflag == DEAD_NO)
1308                 if (self.impulse)
1309                         ImpulseCommands ();
1310                 if (intermission_running)
1311                         return;         // intermission or finale
1312
1313                 //PrintWelcomeMessage(self);
1314                 //if (TetrisPostFrame()) return;
1315         } else if (self.classname == "observer") {
1316                 //do nothing
1317         } else if (self.classname == "spectator") {
1318                 //do nothing
1319         }
1320 }