1 void info_player_survivor (void)
3 info_player_deathmatch();
6 void info_player_start (void)
8 info_player_deathmatch();
11 void info_player_deathmatch (void)
13 self.classname = "info_player_deathmatch";
14 relocate_spawnpoint();
19 entity Spawn_FilterOutBadSpots(entity firstspot, entity playerlist, float mindist, float teamcheck)
21 local entity spot, player, nextspot, previousspot, newfirstspot;
30 nextspot = spot.chain;
31 // count team mismatches as bad spots
33 local float spotactive;
36 // filter out spots for assault
37 if(spot.target != "") {
39 ent = find(world, targetname, spot.target);
41 if(ent.classname == "target_objective")
42 if(ent.health < 0 || ent.health >= ASSAULT_VALUE_INACTIVE)
44 ent = find(ent, targetname, spot.target);
48 if (spot.team == teamcheck && spotactive > 0)
55 if (vlen(player.origin - spot.origin) < mindist)
57 player = player.chain;
63 previousspot.chain = spot;
70 spawn_allgood = FALSE;
74 // if we couldn't find ANY good points, return the original list
76 newfirstspot = firstspot;
80 entity Spawn_RandomPoint(entity firstspot)
84 // count number of spots
89 numspots = numspots + 1;
93 numspots = numspots * random();
95 while (spot.chain && numspots >= 1)
97 numspots = numspots - 1;
103 entity Spawn_FurthestPoint(entity firstspot, entity playerlist)
105 local entity best, spot, player;
106 local float bestrating, rating;
108 bestrating = -1000000;
117 rating = min(rating, vlen(player.origin - spot.origin));
118 player = player.chain;
120 rating = rating + random() * 16;
121 if (bestrating < rating)
135 Finds a point to respawn
138 entity SelectSpawnPoint (float anypoint)
140 local float teamcheck;
141 local entity spot, firstspot, playerlist;
143 spot = find (world, classname, "testplayerstart");
149 if(!anypoint && (g_ctf || g_assault))
150 teamcheck = self.team;
152 // get the list of players
153 playerlist = findchain(classname, "player");
154 // get the entire list of spots
155 firstspot = findchain(classname, "info_player_deathmatch");
156 // filter out the bad ones
157 // (note this returns the original list if none survived)
158 firstspot = Spawn_FilterOutBadSpots(firstspot, playerlist, 100, teamcheck);
160 // there is 50/50 chance of choosing a random spot or the furthest spot
161 // (this means that roughly every other spawn will be furthest, so you
162 // usually won't get fragged at spawn twice in a row)
163 if (arena_roundbased)
165 firstspot = Spawn_FilterOutBadSpots(firstspot, playerlist, 800, teamcheck);
166 spot = Spawn_RandomPoint(firstspot);
168 else if (random() > 0.5 || spawn_allbad || spawn_allgood)
169 spot = Spawn_RandomPoint(firstspot);
171 spot = Spawn_FurthestPoint(firstspot, playerlist);
175 if(cvar("spawn_debug"))
178 error ("PutClientInServer: no start points on level");
188 Checks if the argument string can be a valid playermodel.
189 Returns a valid one in doubt.
192 string FallbackPlayerModel = "models/player/marine.zym";
193 string CheckPlayerModel(string plyermodel) {
194 if(strlen(plyermodel) < 4)
195 return FallbackPlayerModel;
196 if( substring(plyermodel,0,14) != "models/player/")
197 return FallbackPlayerModel;
198 else if(cvar("sv_servermodelsonly"))
200 if(substring(plyermodel,strlen(plyermodel)-4,4) != ".zym")
201 if(substring(plyermodel,strlen(plyermodel)-4,4) != ".dpm")
202 if(substring(plyermodel,strlen(plyermodel)-4,4) != ".md3")
203 if(substring(plyermodel,strlen(plyermodel)-4,4) != ".psk")
204 return FallbackPlayerModel;
205 if(!fexists(plyermodel))
206 return FallbackPlayerModel;
213 Client_customizeentityforclient
218 float Client_customizeentityforclient()
220 #ifdef ALLOW_VARIABLE_LOD
222 // other: the player viewing me
226 if(self.flags & FL_NOTARGET) // we don't need LOD for spectators
229 if(other.cvar_cl_playerdetailreduction <= 0)
231 if(other.cvar_cl_playerdetailreduction <= -2)
232 self.modelindex = self.modelindex_lod2;
233 else if(other.cvar_cl_playerdetailreduction <= -1)
234 self.modelindex = self.modelindex_lod1;
236 self.modelindex = self.modelindex_lod0;
240 distance = vlen(self.origin - other.origin);
241 f = (distance + 100.0) * other.cvar_cl_playerdetailreduction;
243 self.modelindex = self.modelindex_lod2;
245 self.modelindex = self.modelindex_lod1;
247 self.modelindex = self.modelindex_lod0;
254 void UpdatePlayerSounds();
255 void setmodel_lod(entity e, string modelname)
257 #ifdef ALLOW_VARIABLE_LOD
260 // FIXME: this only supports 3-letter extensions
261 s = strcat(substring(modelname, 0, strlen(modelname) - 4), "_1", substring(modelname, 0, strlen(modelname) - 4));
265 setmodel(e, s); // players have high precision
266 self.modelindex_lod1 = self.modelindex;
269 self.modelindex_lod1 = -1;
271 s = strcat(substring(modelname, 0, strlen(modelname) - 4), "_2", substring(modelname, 0, strlen(modelname) - 4));
275 setmodel(e, s); // players have high precision
276 self.modelindex_lod2 = self.modelindex;
279 self.modelindex_lod2 = -1;
281 precache_model(modelname);
282 setmodel(e, modelname); // players have high precision
283 self.modelindex_lod0 = self.modelindex;
285 if(self.modelindex_lod1 < 0)
286 self.modelindex_lod1 = self.modelindex;
288 if(self.modelindex_lod2 < 0)
289 self.modelindex_lod2 = self.modelindex;
291 precache_model(modelname);
292 setmodel(e, modelname); // players have high precision
294 player_setupanimsformodel();
295 UpdatePlayerSounds();
302 putting a client as observer in the server
305 void PutObserverInServer (void)
308 spot = SelectSpawnPoint (TRUE);
309 RemoveGrapplingHook(self); // Wazat's Grappling Hook
311 if(clienttype(self) == CLIENTTYPE_REAL)
314 WriteByte(MSG_ONE, SVC_SETVIEW);
315 WriteEntity(MSG_ONE, self);
319 kh_Key_DropAll(self, TRUE);
322 DropFlag(self.flagcarried);
324 WaypointSprite_PlayerDead();
326 DistributeFragsAmongTeam(self, self.team, 1);
328 if(self.frags <= 0 && self.frags > -666 && g_lms && self.killcount != -666)
329 bprint ("^4", self.netname, "^4 has no more lives left\n");
330 else if(self.killcount != -666)
331 bprint ("^4", self.netname, "^4 is spectating now\n");
333 self.classname = "observer";
335 self.takedamage = DAMAGE_NO;
336 self.solid = SOLID_NOT;
337 self.movetype = MOVETYPE_NOCLIP;
338 self.flags = FL_CLIENT | FL_NOTARGET;
339 self.armorvalue = 666;
341 self.armorvalue = cvar("g_balance_armor_start");
342 self.pauserotarmor_finished = 0;
343 self.pauserothealth_finished = 0;
344 self.pauseregen_finished = 0;
345 self.damageforcescale = 0;
353 self.pain_finished = 0;
354 self.strength_finished = 0;
355 self.invincible_finished = 0;
357 self.think = SUB_Null;
361 self.deadflag = DEAD_NO;
362 self.angles = spot.angles;
364 self.fixangle = TRUE;
367 self.view_ofs = PL_VIEW_OFS;
368 setorigin (self, spot.origin);
369 setsize (self, '0 0 0', '0 0 0');
370 self.oldorigin = self.origin;
375 self.weaponmodel = "";
376 self.weaponentity = world;
377 self.killcount = -666;
378 self.velocity = '0 0 0';
379 self.avelocity = '0 0 0';
380 self.punchangle = '0 0 0';
381 self.punchvector = '0 0 0';
382 self.oldvelocity = self.velocity;
383 self.customizeentityforclient = Client_customizeentityforclient;
389 Spawnqueue_Insert(self);
393 Spawnqueue_Unmark(self);
394 Spawnqueue_Remove(self);
401 float RestrictSkin(float s)
407 return math_mod(s, 3);
414 Called when a client spawns in the server
417 void PutClientInServer (void)
419 if(clienttype(self) == CLIENTTYPE_BOT)
421 self.classname = "player";
423 else if(clienttype(self) == CLIENTTYPE_REAL)
426 WriteByte(MSG_ONE, SVC_SETVIEW);
427 WriteEntity(MSG_ONE, self);
430 // player is dead and becomes observer
431 if(g_lms && self.frags < 1)
432 self.classname = "observer";
436 self.classname = "observer";
438 if(self.classname == "player") {
441 spot = SelectSpawnPoint (FALSE);
443 RemoveGrapplingHook(self); // Wazat's Grappling Hook
445 self.classname = "player";
446 self.iscreature = TRUE;
447 self.movetype = MOVETYPE_WALK;
448 self.solid = SOLID_SLIDEBOX;
449 self.flags = FL_CLIENT;
450 self.takedamage = DAMAGE_AIM;
452 self.effects = EF_FULLBRIGHT;
455 self.air_finished = time + 12;
458 self.ammo_shells = start_ammo_shells;
459 self.ammo_nails = start_ammo_nails;
460 self.ammo_rockets = start_ammo_rockets;
461 self.ammo_cells = start_ammo_cells;
462 self.health = start_health;
463 self.armorvalue = start_armorvalue;
464 self.items = start_items;
465 self.switchweapon = start_switchweapon;
467 self.jump_interval = time;
469 self.spawnshieldtime = time + cvar("g_spawnshieldtime");
470 self.pauserotarmor_finished = time + cvar("g_balance_pause_armor_rot_spawn");
471 self.pauserothealth_finished = time + cvar("g_balance_pause_health_rot_spawn");
472 self.pauseregen_finished = time + cvar("g_balance_pause_health_regen_spawn");
473 self.damageforcescale = 2;
480 self.pain_finished = 0;
481 self.strength_finished = 0;
482 self.invincible_finished = 0;
484 //self.speed_finished = 0;
485 //self.slowmo_finished = 0;
486 // players have no think function
487 self.think = SUB_Null;
493 self.deadflag = DEAD_NO;
495 self.angles = spot.angles;
497 self.angles_z = 0; // never spawn tilted even if the spot says to
498 self.fixangle = TRUE; // turn this way immediately
499 self.velocity = '0 0 0';
500 self.avelocity = '0 0 0';
501 self.punchangle = '0 0 0';
502 self.punchvector = '0 0 0';
503 self.oldvelocity = self.velocity;
508 self.customizeentityforclient = Client_customizeentityforclient;
510 if(cvar("sv_defaultcharacter") == 1) {
511 local string defaultmodel;
512 defaultmodel = cvar_string("sv_defaultplayermodel");
513 setmodel_lod (self, defaultmodel);
514 self.skin = stof(cvar_string("sv_defaultplayerskin"));
516 self.playermodel = CheckPlayerModel(self.playermodel);
517 setmodel_lod (self, self.playermodel);
518 self.skin = RestrictSkin(stof(self.playerskin));
521 if(strlen(cvar_string("sv_defaultplayercolors")))
522 setcolor(self, cvar("sv_defaultplayercolors"));
525 self.view_ofs = PL_VIEW_OFS;
526 setsize (self, PL_MIN, PL_MAX);
527 self.spawnorigin = spot.origin;
528 setorigin (self, spot.origin + '0 0 1' * (1 - self.mins_z - 24));
529 // don't reset back to last position, even if new position is stuck in solid
530 self.oldorigin = self.origin;
534 Spawnqueue_Remove(self);
535 Spawnqueue_Mark(self);
538 self.event_damage = PlayerDamage;
540 self.bot_attack = TRUE;
542 self.statdraintime = time + 5;
543 self.button0 = self.button1 = self.button2 = self.button3 = 0;
545 if(self.killcount == -666) {
552 self.cnt = WEP_LASER;
553 self.nixnex_lastchange_id = -1;
555 CL_SpawnWeaponentity();
556 self.alpha = default_player_alpha;
557 self.colormod = '1 1 1' * cvar("g_player_brightness");
558 self.exteriorweaponentity.alpha = default_weapon_alpha;
560 self.lms_nextcheck = time + cvar("g_lms_campcheck_interval")*2;
561 self.lms_traveled_distance = 0;
563 if(cvar("spawn_debug"))
565 sprint(self, strcat("spawnpoint origin: ", vtos(spot.origin), "\n"));
566 remove(spot); // usefull for checking if there are spawnpoints, that let drop through the floor
569 //stuffcmd(self, "chase_active 0");
570 //stuffcmd(self, "set viewsize $tmpviewsize \n");
572 if (cvar("g_spawnsound"))
573 sound (self, CHAN_AUTO, "misc/spawn.wav", 1, ATTN_NORM);
576 if(self.team == assault_attacker_team)
577 centerprint(self, "You are attacking!\n");
579 centerprint(self, "You are defending!\n");
582 } else if(self.classname == "observer") {
583 PutObserverInServer ();
592 void SetNewParms (void)
602 void SetChangeParms (void)
611 Called when a client types 'kill' in the console
614 void ClientKill (void)
616 Damage(self, self, self, 100000, DEATH_KILL, self.origin, '0 0 0');
619 void FixClientCvars(entity e)
622 // send prediction settings to the client
623 stuffcmd(e, "\nin_bindmap 0 0\n");
624 stuffcmd(e, strcat("cl_gravity ", ftos(cvar("sv_gravity")), "\n"));
625 stuffcmd(e, strcat("cl_movement_accelerate ", ftos(cvar("sv_accelerate")), "\n"));
626 stuffcmd(e, strcat("cl_movement_friction ", ftos(cvar("sv_friction")), "\n"));
627 stuffcmd(e, strcat("cl_movement_maxspeed ", ftos(cvar("sv_maxspeed")), "\n"));
628 stuffcmd(e, strcat("cl_movement_airaccelerate ", ftos(cvar("sv_airaccelerate")), "\n"));
629 stuffcmd(e, strcat("cl_movement_maxairspeed ", ftos(cvar("sv_maxairspeed")), "\n"));
630 stuffcmd(e, strcat("cl_movement_stopspeed ", ftos(cvar("sv_stopspeed")), "\n"));
631 stuffcmd(e, strcat("cl_movement_jumpvelocity ", ftos(cvar("sv_jumpvelocity")), "\n"));
632 stuffcmd(e, strcat("cl_movement_stepheight ", ftos(cvar("sv_stepheight")), "\n"));
633 stuffcmd(e, strcat("set cl_movement_friction_on_land ", ftos(cvar("sv_friction_on_land")), "\n"));
634 stuffcmd(e, strcat("set cl_movement_airaccel_qw ", ftos(cvar("sv_airaccel_qw")), "\n"));
635 stuffcmd(e, strcat("set cl_movement_airaccel_sideways_friction ", ftos(cvar("sv_airaccel_sideways_friction")), "\n"));
636 stuffcmd(e, "cl_movement_edgefriction 1\n");
638 // notify about available teams
641 CheckAllowedTeams(e);
642 t = 0; if(c1 >= 0) t |= 1; if(c2 >= 0) t |= 2; if(c3 >= 0) t |= 4; if(c4 >= 0) t |= 8;
643 stuffcmd(e, strcat("set _teams_available ", ftos(t), "\n"));
646 stuffcmd(e, "set _teams_available 0\n");
653 Called when a client connects to the server
656 string ColoredTeamName(float t);
657 //void dom_player_join_team(entity pl);
658 void ClientConnect (void)
663 if(Ban_IsClientBanned(self))
665 s = strcat("^1NOTE:^7 banned client ", self.netaddress, " just tried to enter\n");
671 self.classname = "player_joining";
672 self.flags = self.flags | FL_CLIENT;
673 self.version_nagtime = time + 10 + random() * 10;
677 dprint("BUG player count is lower than zero, this cannot happen!\n");
684 // dom_player_join_team(self);
686 //JoinBestTeam(self, FALSE);
688 if((cvar("sv_spectate") == 1 && !g_lms) || cvar("g_campaign")) {
689 self.classname = "observer";
691 self.classname = "player";
692 campaign_bots_may_start = 1;
695 self.playerid = (playerid_last = playerid_last + 1);
696 if(cvar("sv_eventlog"))
698 if(clienttype(self) == CLIENTTYPE_REAL)
702 GameLogEcho(strcat(":join:", ftos(self.playerid), ":", s, ":", self.netname), TRUE);
703 s = strcat(":team:", ftos(self.playerid), ":");
704 s = strcat(s, ftos(self.team));
705 GameLogEcho(s, FALSE);
708 //stuffcmd(self, "set tmpviewsize $viewsize \n");
710 bprint ("^4",self.netname);
711 bprint ("^4 connected");
713 if(g_domination || g_ctf)
715 bprint(" and joined the ");
716 bprint(ColoredTeamName(self.team));
721 self.welcomemessage_time = 0;
723 stuffcmd(self, strcat("exec maps/", mapname, ".cfg\n"));
724 // TODO: is this being used for anything else than cd tracks?
725 // Remember: SVC_CDTRACK exists. Maybe it should be used.
727 FixClientCvars(self);
730 WaypointSprite_InitClient(self);
732 // Wazat's grappling hook
733 SetGrappleHookBindings();
735 // get autoswitch state from player when he toggles it
736 stuffcmd(self, "alias autoswitch \"set cl_autoswitch $1 ; cmd autoswitch $1\"\n");
738 // get version info from player
739 stuffcmd(self, "cmd clientversion $gameversion\n");
741 // send all weapon info strings
742 stuffcmd(self, "register_bestweapon clear\n"); // clear the Quake stuff
744 while (wep <= WEP_LAST)
746 weapon_action(wep, WR_REGISTER);
750 // get other cvars from player
753 // set cvar for team scoreboard
757 t = cvar("teamplay");
758 // we have to stuff the correct teamplay value because if this is a listen server, this changes the teamplay mode of the server itself, which is bad
759 stuffcmd(self, strcat("set teamplay ", ftos(t), "\n"));
762 stuffcmd(self, "set teamplay 0\n");
766 self.frags = LMS_NewPlayerLives();
772 self.classname = "observer";
773 Spawnqueue_Insert(self);
776 bot_relinkplayerlist();
778 self.jointime = time;
785 Called when a client disconnects from the server
788 void(entity e) DropFlag;
789 .entity chatbubbleentity;
790 .entity teambubbleentity;
791 void ClientDisconnect (void)
794 if(cvar("sv_eventlog"))
795 GameLogEcho(strcat(":part:", ftos(self.playerid)), FALSE);
796 bprint ("^4",self.netname);
797 bprint ("^4 disconnected\n");
799 if (self.chatbubbleentity)
801 remove (self.chatbubbleentity);
802 self.chatbubbleentity = world;
805 if (self.teambubbleentity)
807 remove (self.teambubbleentity);
808 self.teambubbleentity = world;
811 WaypointSprite_PlayerGone();
814 kh_Key_DropAll(self, TRUE);
817 DropFlag(self.flagcarried);
819 DistributeFragsAmongTeam(self, self.team, 1);
822 self.flags = self.flags - (self.flags & FL_CLIENT);
823 bot_relinkplayerlist();
827 if(self.weaponentity)
828 if(self.weaponentity.lasertarget)
829 remove(self.weaponentity.lasertarget);
833 Spawnqueue_Unmark(self);
834 Spawnqueue_Remove(self);
842 void() ChatBubbleThink =
844 self.nextthink = time;
845 if (!self.owner.modelindex || self.owner.chatbubbleentity != self)
847 self.owner.chatbubbleentity = world;
851 setorigin(self, self.owner.origin + '0 0 15' + self.owner.maxs_z * '0 0 1');
852 if (self.owner.buttonchat && !self.owner.deadflag)
853 self.model = self.mdl;
858 void() UpdateChatBubble =
860 if (!self.modelindex)
862 // spawn a chatbubble entity if needed
863 if (!self.chatbubbleentity)
865 self.chatbubbleentity = spawn();
866 self.chatbubbleentity.owner = self;
867 self.chatbubbleentity.exteriormodeltoclient = self;
868 self.chatbubbleentity.think = ChatBubbleThink;
869 self.chatbubbleentity.nextthink = time;
870 setmodel(self.chatbubbleentity, "models/misc/chatbubble.spr"); // precision set below
871 setorigin(self.chatbubbleentity, self.origin + '0 0 15' + self.maxs_z * '0 0 1');
872 self.chatbubbleentity.mdl = self.chatbubbleentity.model;
873 self.chatbubbleentity.model = "";
874 self.chatbubbleentity.effects = EF_LOWPRECISION;
879 void() TeamBubbleThink =
881 self.nextthink = time;
882 if (!self.owner.modelindex || self.owner.teambubbleentity != self)
884 self.owner.teambubbleentity = world;
888 // setorigin(self, self.owner.origin + '0 0 15' + self.owner.maxs_z * '0 0 1'); // bandwidth hog. setattachment does this now
889 if (self.owner.buttonchat || self.owner.deadflag)
892 self.model = self.mdl;
896 float() TeamBubble_customizeentityforclient
898 return (self.owner != other && self.owner.team == other.team && other.killcount > -666);
901 void() UpdateTeamBubble =
903 if (!self.modelindex || !cvar("teamplay"))
905 // spawn a teambubble entity if needed
906 if (!self.teambubbleentity && cvar("teamplay"))
908 self.teambubbleentity = spawn();
909 self.teambubbleentity.owner = self;
910 self.teambubbleentity.exteriormodeltoclient = self;
911 self.teambubbleentity.think = TeamBubbleThink;
912 self.teambubbleentity.nextthink = time;
913 setmodel(self.teambubbleentity, "models/misc/teambubble.spr"); // precision set below
914 // setorigin(self.teambubbleentity, self.origin + '0 0 15' + self.maxs_z * '0 0 1');
915 setorigin(self.teambubbleentity, self.teambubbleentity.origin + '0 0 15' + self.maxs_z * '0 0 1');
916 setattachment(self.teambubbleentity, self, ""); // sticks to moving player better, also conserves bandwidth
917 self.teambubbleentity.mdl = self.teambubbleentity.model;
918 self.teambubbleentity.model = self.teambubbleentity.mdl;
919 self.teambubbleentity.customizeentityforclient = TeamBubble_customizeentityforclient;
920 self.teambubbleentity.effects = EF_LOWPRECISION;
924 // LordHavoc: this hack will be removed when proper _pants/_shirt layers are
925 // added to the model skins
926 /*void() UpdateColorModHack =
929 c = self.clientcolors & 15;
930 // LordHavoc: only bothering to support white, green, red, yellow, blue
931 if (teamplay == 0) self.colormod = '0 0 0';
932 else if (c == 0) self.colormod = '1.00 1.00 1.00';
933 else if (c == 3) self.colormod = '0.10 1.73 0.10';
934 else if (c == 4) self.colormod = '1.73 0.10 0.10';
935 else if (c == 12) self.colormod = '1.22 1.22 0.10';
936 else if (c == 13) self.colormod = '0.10 0.10 1.73';
937 else self.colormod = '1 1 1';
946 void player_powerups (void)
950 if (self.items & IT_STRENGTH)
952 if (time > self.strength_finished)
954 if (g_minstagib_invis_alpha > 0)
956 self.alpha = default_player_alpha;
957 self.exteriorweaponentity.alpha = default_weapon_alpha;
958 self.effects = self.effects | EF_FULLBRIGHT;
962 self.effects -= self.effects & EF_NODRAW;
964 self.items = self.items - (self.items & IT_STRENGTH);
965 sprint(self, "^3Invisibility has worn off\n");
970 if (time < self.strength_finished)
972 if (g_minstagib_invis_alpha > 0)
974 self.alpha = g_minstagib_invis_alpha;
975 self.exteriorweaponentity.alpha = g_minstagib_invis_alpha;
976 self.effects -= self.effects & EF_FULLBRIGHT;
980 self.effects = self.effects | EF_NODRAW;
982 self.items = self.items | IT_STRENGTH;
983 sprint(self, "^3You are invisible\n");
987 if (self.items & IT_INVINCIBLE)
989 if (time > self.invincible_finished)
991 self.items = self.items - (self.items & IT_INVINCIBLE);
992 sprint(self, "^3Speed has worn off\n");
997 if (time < self.invincible_finished)
999 self.items = self.items | IT_INVINCIBLE;
1000 sprint(self, "^3You are on speed\n");
1006 self.effects = self.effects - (self.effects & (EF_RED | EF_BLUE | EF_ADDITIVE | EF_FULLBRIGHT));
1007 if (self.items & IT_STRENGTH)
1009 self.effects = self.effects | (EF_BLUE | EF_ADDITIVE | EF_FULLBRIGHT);
1010 if (time > self.strength_finished)
1012 self.items = self.items - (self.items & IT_STRENGTH);
1013 sprint(self, "^3Strength has worn off\n");
1018 if (time < self.strength_finished)
1020 self.items = self.items | IT_STRENGTH;
1021 sprint(self, "^3Strength infuses your weapons with devastating power\n");
1024 if (self.items & IT_INVINCIBLE)
1026 self.effects = self.effects | (EF_RED | EF_ADDITIVE | EF_FULLBRIGHT);
1027 if (time > self.invincible_finished)
1029 self.items = self.items - (self.items & IT_INVINCIBLE);
1030 sprint(self, "^3Shield has worn off\n");
1035 if (time < self.invincible_finished)
1037 self.items = self.items | IT_INVINCIBLE;
1038 sprint(self, "^3Shield surrounds you\n");
1042 if (cvar("g_fullbrightplayers"))
1043 self.effects = self.effects | EF_FULLBRIGHT;
1045 // midair gamemode: damage only while in the air
1046 // if in midair mode, being on ground grants temporary invulnerability
1047 // (this is so that multishot weapon don't clear the ground flag on the
1048 // first damage in the frame, leaving the player vulnerable to the
1049 // remaining hits in the same frame)
1050 if (self.flags & FL_ONGROUND)
1052 self.spawnshieldtime = max(self.spawnshieldtime, time + cvar("g_midair_shieldtime"));
1054 if (time < self.spawnshieldtime)
1055 self.effects = self.effects | (EF_ADDITIVE | EF_FULLBRIGHT);
1058 float CalcRegen(float current, float stable, float regenfactor)
1060 if(current > stable)
1062 else if(current > stable - 0.25) // when close enough, "snap"
1065 return min(stable, current + (stable - current) * regenfactor * frametime);
1068 void player_regen (void)
1070 float maxh, maxa, limith, limita, max_mod, regen_mod, rot_mod, limit_mod;
1071 maxh = cvar("g_balance_health_stable");
1072 maxa = cvar("g_balance_armor_stable");
1073 limith = cvar("g_balance_health_limit");
1074 limita = cvar("g_balance_armor_limit");
1076 if (g_minstagib || (g_lms && !cvar("g_lms_regenerate")))
1079 max_mod = regen_mod = rot_mod = limit_mod = 1;
1081 if (self.runes & RUNE_REGEN)
1083 if (self.runes & CURSE_VENOM) // do we have both rune/curse?
1085 regen_mod = cvar("g_balance_rune_regen_combo_regenrate");
1086 max_mod = cvar("g_balance_rune_regen_combo_hpmod");
1087 limit_mod = cvar("g_balance_rune_regen_combo_limitmod");
1091 regen_mod = cvar("g_balance_rune_regen_regenrate");
1092 max_mod = cvar("g_balance_rune_regen_hpmod");
1093 limit_mod = cvar("g_balance_rune_regen_limitmod");
1096 else if (self.runes & CURSE_VENOM)
1098 max_mod = cvar("g_balance_curse_venom_hpmod");
1099 if (self.runes & RUNE_REGEN) // do we have both rune/curse?
1100 rot_mod = cvar("g_balance_rune_regen_combo_rotrate");
1102 rot_mod = cvar("g_balance_curse_venom_rotrate");
1103 limit_mod = cvar("g_balance_curse_venom_limitmod");
1104 //if (!self.runes & RUNE_REGEN)
1105 // rot_mod = cvar("g_balance_curse_venom_rotrate");
1107 maxh = maxh * max_mod;
1108 //maxa = maxa * max_mod;
1109 limith = limith * limit_mod;
1110 limita = limita * limit_mod;
1112 if (self.armorvalue > maxa)
1114 if (time > self.pauserotarmor_finished)
1116 self.armorvalue = max(maxa, self.armorvalue + (maxa - self.armorvalue) * cvar("g_balance_armor_rot") * frametime);
1117 self.armorvalue = max(maxa, self.armorvalue - cvar("g_balance_armor_rotlinear") * frametime);
1120 else if (self.armorvalue < maxa)
1122 if (time > self.pauseregen_finished)
1124 self.armorvalue = CalcRegen(self.armorvalue, maxa, cvar("g_balance_armor_regen"));
1125 self.armorvalue = min(maxa, self.armorvalue + cvar("g_balance_armor_regenlinear") * frametime);
1128 if (self.health > maxh)
1130 if (time > self.pauserothealth_finished)
1132 self.health = max(maxh, self.health + (maxh - self.health) * rot_mod*cvar("g_balance_health_rot") * frametime);
1133 self.health = max(maxh, self.health - rot_mod*cvar("g_balance_health_rotlinear") * frametime);
1136 else if (self.health < maxh)
1138 if (time > self.pauseregen_finished)
1140 self.health = CalcRegen(self.health, maxh, regen_mod * cvar("g_balance_health_regen"));
1141 self.health = min(maxh, self.health + regen_mod*cvar("g_balance_health_regenlinear") * frametime);
1145 if (self.health > limith)
1146 self.health = limith;
1147 if (self.armorvalue > limita)
1148 self.armorvalue = limita;
1150 // if player rotted to death... die!
1152 self.event_damage(self, self, 1, DEATH_ROT, self.origin, '0 0 0');
1156 ======================
1157 spectate mode routines
1158 ======================
1160 void SpectateCopy(entity spectatee) {
1161 self.armortype = spectatee.armortype;
1162 self.armorvalue = spectatee.armorvalue;
1163 self.currentammo = spectatee.currentammo;
1164 self.effects = spectatee.effects;
1165 self.health = spectatee.health;
1167 self.items = spectatee.items;
1168 self.punchangle = spectatee.punchangle;
1169 self.view_ofs = spectatee.view_ofs;
1170 self.v_angle = spectatee.v_angle;
1171 self.viewzoom = spectatee.viewzoom;
1172 self.velocity = spectatee.velocity;
1173 self.dmg_take = spectatee.dmg_take;
1174 self.dmg_save = spectatee.dmg_save;
1175 self.dmg_inflictor = spectatee.dmg_inflictor;
1176 self.angles = spectatee.v_angle;
1177 self.fixangle = TRUE;
1178 setorigin(self, spectatee.origin);
1179 setsize(self, spectatee.mins, spectatee.maxs);
1182 void SpectateUpdate() {
1184 PutObserverInServer();
1186 if (self != self.enemy) {
1187 if(self.enemy.flags & FL_NOTARGET)
1188 PutObserverInServer();
1189 SpectateCopy(self.enemy);
1190 //msg_entity = self;
1191 //WriteByte(MSG_ONE, SVC_SETANGLE);
1192 //WriteAngle(MSG_ONE, self.enemy.v_angle_x);
1193 //WriteAngle(MSG_ONE, self.enemy.v_angle_y);
1194 //WriteAngle(MSG_ONE, self.enemy.v_angle_z);
1198 float SpectateNext() {
1199 other = find(self.enemy, classname, "player");
1201 other = find(other, classname, "player");
1206 if(self.enemy.classname == "player") {
1208 WriteByte(MSG_ONE, SVC_SETVIEW);
1209 WriteEntity(MSG_ONE, self.enemy);
1210 //stuffcmd(self, "set viewsize $tmpviewsize \n");
1220 ShowRespawnCountdown()
1222 Update a respawn countdown display.
1225 void ShowRespawnCountdown()
1228 if(self.deadflag == DEAD_NO) // just respawned?
1232 number = ceil(self.death_time - time);
1235 if(number <= self.respawn_countdown)
1237 self.respawn_countdown = number - 1;
1238 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
1239 play2(self, strcat("announcer/robotic/", ftos(number), ".ogg"));
1244 void LeaveSpectatorMode()
1246 if(!cvar("teamplay") || cvar("g_campaign") || cvar("g_balance_teams")) {
1247 self.classname = "player";
1248 if(cvar("g_campaign") || cvar("g_balance_teams"))
1249 JoinBestTeam(self, 0);
1250 if(cvar("g_campaign"))
1251 campaign_bots_may_start = 1;
1252 PutClientInServer();
1253 if(!(self.flags & FL_NOTARGET))
1254 bprint ("^4", self.netname, "^4 is playing now\n");
1255 centerprint(self,"");
1258 stuffcmd(self,"menu_showteamselect\n");
1267 Called every frame for each client before the physics are run
1270 void() ctf_setstatus;
1271 .float vote_nagtime;
1272 void PlayerPreThink (void)
1277 if(self.version_nagtime)
1278 if(self.cvar_g_nexuizversion)
1279 if(time > self.version_nagtime)
1281 if(strstr(self.cvar_g_nexuizversion, "svn", 0) < 0)
1282 if(self.cvar_g_nexuizversion != cvar_string("g_nexuizversion"))
1284 dprint("^1NOTE^7 to ", self.netname, "^7 - the server is running ^3Nexuiz ", cvar_string("g_nexuizversion"), "^7, you have ^3Nexuiz ", self.cvar_g_nexuizversion, "\n");
1285 sprint(self, strcat("\{1}^1NOTE: ^7the server is running ^3Nexuiz ", cvar_string("g_nexuizversion"), "^7, you have ^3Nexuiz ", self.cvar_g_nexuizversion, "\n"));
1287 self.version_nagtime = 0;
1291 if(self.cvar_scr_centertime)
1292 if(time > self.vote_nagtime)
1295 self.vote_nagtime = time + self.cvar_scr_centertime * 0.6;
1299 if(!(self.flags & FL_GODMODE)) if(self.max_armorvalue)
1301 sprint(self, strcat("godmode saved you ", ftos(self.max_armorvalue), " units of damage, cheater!\n"));
1302 self.max_armorvalue = 0;
1305 if(self.classname == "player") {
1306 local vector m1, m2;
1308 // if(self.netname == "Wazat")
1309 // bprint(self.classname, "\n");
1311 CheckRules_Player();
1314 PrintWelcomeMessage(self);
1316 if(g_lms || !cvar("sv_spectate"))
1317 if((time - self.jointime) <= cvar("welcome_message_time"))
1318 PrintWelcomeMessage(self);
1320 if (intermission_running)
1322 IntermissionThink (); // otherwise a button could be missed between
1323 return; // the think tics
1326 if(self.teleport_time)
1327 if(time > self.teleport_time)
1329 self.teleport_time = 0;
1330 self.effects = self.effects - (self.effects & EF_NODRAW);
1331 if(self.weaponentity)
1332 self.weaponentity.flags = self.weaponentity.flags - (self.weaponentity.flags & EF_NODRAW);
1335 Nixnex_GiveCurrentWeapon();
1337 if(frametime > 0) // don't do this in cl_movement frames, just in server ticks
1338 UpdateSelectedPlayer();
1340 if (self.deadflag != DEAD_NO)
1342 float button_pressed, force_respawn;
1344 button_pressed = (self.button0 || self.button2 || self.button3 || self.button6 || self.buttonuse);
1345 force_respawn = (g_lms || cvar("g_forced_respawn"));
1346 if (self.deadflag == DEAD_DYING)
1349 self.deadflag = DEAD_RESPAWNING;
1350 else if(!button_pressed)
1351 self.deadflag = DEAD_DEAD;
1353 else if (self.deadflag == DEAD_DEAD)
1356 self.deadflag = DEAD_RESPAWNABLE;
1358 else if (self.deadflag == DEAD_RESPAWNABLE)
1361 self.deadflag = DEAD_RESPAWNING;
1363 else if (self.deadflag == DEAD_RESPAWNING)
1365 if(time > self.death_time)
1368 ShowRespawnCountdown();
1372 if(g_lms && !self.deadflag && cvar("g_lms_campcheck_interval"))
1376 // calculate player movement (in 2 dimensions only, so jumping on one spot doesn't count as movement)
1377 dist = self.oldorigin - self.origin;
1379 self.lms_traveled_distance += fabs(vlen(dist));
1381 if((cvar("g_campaign") && !campaign_bots_may_start) || (time < restart_countdown))
1383 self.lms_nextcheck = time + cvar("g_lms_campcheck_interval")*2;
1384 self.lms_traveled_distance = 0;
1387 if(time > self.lms_nextcheck)
1389 //sprint(self, "distance: ", ftos(self.lms_traveled_distance), "\n");
1390 if(self.lms_traveled_distance < cvar("g_lms_campcheck_distance"))
1392 centerprint(self, cvar_string("g_lms_campcheck_message"));
1393 // FIXME KadaverJack: gibbing player here causes playermodel to bounce around, instead of eye.md3
1394 // I wasn't able to find out WHY that happens, so I put a workaround in place that shall prevent players from being gibbed :(
1395 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');
1397 self.lms_nextcheck = time + cvar("g_lms_campcheck_interval");
1398 self.lms_traveled_distance = 0;
1402 if (self.button5 && !self.hook.state)
1407 self.view_ofs = PL_CROUCH_VIEW_OFS;
1408 setsize (self, PL_CROUCH_MIN, PL_CROUCH_MAX);
1409 player_setanim(self.anim_duck, FALSE, TRUE, TRUE);
1416 tracebox(self.origin, PL_MIN, PL_MAX, self.origin, FALSE, self);
1417 if (!trace_startsolid)
1419 self.crouch = FALSE;
1420 self.view_ofs = PL_VIEW_OFS;
1421 setsize (self, PL_MIN, PL_MAX);
1426 if(cvar("sv_defaultcharacter") == 1) {
1427 local string defaultmodel;
1428 defaultmodel = cvar_string("sv_defaultplayermodel");
1430 if (defaultmodel != self.model)
1434 setmodel_lod (self, defaultmodel);
1435 setsize (self, m1, m2);
1438 if (self.skin != cvar("sv_defaultplayerskin"))
1439 self.skin = cvar("sv_defaultplayerskin");
1441 if (self.playermodel != self.model)
1443 self.playermodel = CheckPlayerModel(self.playermodel);
1446 setmodel_lod (self, self.playermodel);
1447 setsize (self, m1, m2);
1450 f = RestrictSkin(stof(self.playerskin));
1455 if(strlen(cvar_string("sv_defaultplayercolors")))
1456 if(self.clientcolors != cvar("sv_defaultplayercolors"))
1457 setcolor(self, cvar("sv_defaultplayercolors"));
1459 GrapplingHookFrame();
1464 float zoomfactor, zoomspeed, zoomdir;
1465 zoomfactor = self.cvar_cl_zoomfactor;
1466 if(zoomfactor < 1 || zoomfactor > 16)
1468 zoomspeed = self.cvar_cl_zoomspeed;
1469 if(zoomspeed >= 0) // < 0 is instant zoom
1470 if(zoomspeed < 0.5 || zoomspeed > 16)
1473 zoomdir = self.button4;
1475 if(self.weapon == WEP_NEX)
1480 self.has_zoomed = 1;
1484 if(zoomspeed <= 0) // instant zoom
1487 self.viewzoom = 1 / zoomfactor;
1493 // geometric zoom would be:
1494 // self.viewzoom = bound(1 / zoomfactor, self.viewzoom * pow(zoomfactor, (zoomdir ? -1 : 1) * frametime * zoomspeed), 1);
1495 // however, testing showed that arithmetic/harmonic zoom works better
1497 // self.viewzoom = 1 / bound(1, 1 / self.viewzoom + (zoomdir ? 1 : -1) * frametime * zoomspeed * (zoomfactor - 1), zoomfactor);
1498 // zoom in = arithmetic: 1x, 2x, 3x, 4x, ..., 8x
1499 self.viewzoom = 1 / bound(1, 1 / self.viewzoom + frametime * zoomspeed * (zoomfactor - 1), zoomfactor);
1501 // self.viewzoom = bound(1 / zoomfactor, self.viewzoom + (zoomdir ? -1 : 1) * frametime * zoomspeed * (1 - 1 / zoomfactor), 1);
1502 // zoom out = harmonic: 8/1x, 8/2x, 8/3x, 8/4x, ..., 8/8x
1503 self.viewzoom = bound(1 / zoomfactor, self.viewzoom + frametime * zoomspeed * (1 - 1 / zoomfactor), 1);
1507 self.viewzoom = min(1, self.viewzoom + frametime); // spawn zoom-in
1515 minstagib_ammocheck();
1520 //self.angles_y=self.v_angle_y + 90; // temp
1522 //if (TetrisPreFrame()) return;
1523 } else if(gameover) {
1524 if (intermission_running)
1525 IntermissionThink (); // otherwise a button could be missed between
1527 } else if(self.classname == "observer") {
1529 if (self.flags & FL_JUMPRELEASED) {
1530 if (self.button2 && self.version == cvar("gameversion")) {
1531 self.welcomemessage_time = 0;
1532 self.flags = self.flags - FL_JUMPRELEASED;
1533 LeaveSpectatorMode();
1535 } else if(self.button0 && self.version == cvar("gameversion")) {
1536 self.welcomemessage_time = 0;
1537 self.flags = self.flags - FL_JUMPRELEASED;
1538 if(SpectateNext() == 1) {
1539 self.classname = "spectator";
1543 if (!(self.button0 || self.button2)) {
1544 self.flags = self.flags | FL_JUMPRELEASED;
1547 PrintWelcomeMessage(self);
1548 } else if(self.classname == "spectator") {
1549 if (self.flags & FL_JUMPRELEASED) {
1550 if (self.button2 && self.version == cvar("gameversion")) {
1551 self.welcomemessage_time = 0;
1552 self.flags = self.flags - FL_JUMPRELEASED;
1553 LeaveSpectatorMode();
1555 } else if(self.button0) {
1556 self.welcomemessage_time = 0;
1557 self.flags = self.flags - FL_JUMPRELEASED;
1558 if(SpectateNext() == 1) {
1559 self.classname = "spectator";
1561 self.classname = "observer";
1562 PutClientInServer();
1564 } else if (self.button3) {
1565 self.welcomemessage_time = 0;
1566 self.flags = self.flags - FL_JUMPRELEASED;
1567 self.classname = "observer";
1568 PutClientInServer();
1573 if (!(self.button0 || self.button3)) {
1574 self.flags = self.flags | FL_JUMPRELEASED;
1577 PrintWelcomeMessage(self);
1578 self.flags = self.flags | FL_CLIENT | FL_NOTARGET;
1587 Called every frame for each client after the physics are run
1590 void PlayerPostThink (void)
1592 // Savage: Check for nameless players
1593 if (strlen(self.netname) < 1) {
1594 self.netname = "Player";
1595 stuffcmd(self, "seta _cl_name Player\n");
1598 if(self.classname == "player") {
1599 CheckRules_Player();
1604 if (intermission_running)
1605 return; // intermission or finale
1607 //PrintWelcomeMessage(self);
1608 //if (TetrisPostFrame()) return;
1610 // restart countdown
1611 if(time < restart_countdown)
1616 sec = ceil(restart_countdown-time);
1617 s = strcat(NEWLINES, "^1Game starts in ", ftos(sec), " seconds");
1618 centerprint(self, s);
1619 self.movetype = MOVETYPE_NONE;
1620 self.velocity = '0 0 0';
1621 self.avelocity = '0 0 0';
1622 self.movement = '0 0 0';
1624 else if(self.movetype == MOVETYPE_NONE)
1626 self.movetype = MOVETYPE_WALK;
1627 centerprint(self, "\n");
1629 } else if (self.classname == "observer") {
1631 } else if (self.classname == "spectator") {