1 .float spectatee_status;
3 .float bloodloss_timer;
7 float ClientData_Send(entity to, float sf)
18 if(to.classname == "spectator")
24 sf |= 1; // forced scoreboard
25 if(to.spectatee_status)
26 sf |= 2; // spectator ent number follows
29 if(e.porto_v_angle_held)
30 sf |= 8; // angles held
32 WriteByte(MSG_ENTITY, ENT_CLIENT_CLIENTDATA);
33 WriteByte(MSG_ENTITY, sf);
36 WriteByte(MSG_ENTITY, to.spectatee_status);
40 WriteAngle(MSG_ENTITY, e.v_angle_x);
41 WriteAngle(MSG_ENTITY, e.v_angle_y);
47 void ClientData_Attach()
49 Net_LinkEntity(self.clientdata = spawn(), FALSE, 0, ClientData_Send);
50 self.clientdata.drawonlytoclient = self;
51 self.clientdata.owner = self;
54 void ClientData_Detach()
56 remove(self.clientdata);
57 self.clientdata = world;
60 void ClientData_Touch(entity e)
62 e.clientdata.SendFlags = 1;
64 // make it spectatable
66 FOR_EACH_REALCLIENT(e2)
69 if(e2.classname == "spectator")
71 e2.clientdata.SendFlags = 1;
76 #define SPAWNPOINT_SCORE frags
78 .string netname_previous;
80 void spawnfunc_info_player_survivor (void)
82 spawnfunc_info_player_deathmatch();
85 void spawnfunc_info_player_start (void)
87 spawnfunc_info_player_deathmatch();
90 void spawnfunc_info_player_deathmatch (void)
92 self.classname = "info_player_deathmatch";
93 relocate_spawnpoint();
101 self.team = activator.team;
102 some_spawn_has_been_used = 1;
107 // -1 if a spawn can't be used
108 // otherwise, a weight of the spawnpoint
109 float Spawn_Score(entity spot, entity playerlist, float teamcheck)
111 float shortest, thisdist;
114 // filter out spots for the wrong team
116 if(spot.team != teamcheck)
120 if(spot.target == "")
123 if(clienttype(self) == CLIENTTYPE_REAL)
125 if(spot.restriction == 1)
130 if(spot.restriction == 2)
134 // filter out spots for assault
135 if(spot.target != "") {
138 ent = find(world, targetname, spot.target);
140 if(ent.classname == "target_objective")
143 if(ent.health < 0 || ent.health >= ASSAULT_VALUE_INACTIVE)
147 else if(ent.classname == "trigger_race_checkpoint")
150 if(self.classname == "player") // spectators may spawn everywhere
152 if(g_race_qualifying)
155 if(ent.race_checkpoint != 0)
157 if(spot.race_place != race_lowest_place_spawn)
162 if(ent.race_checkpoint != race_PreviousCheckpoint(self.race_checkpoint))
165 pl = self.race_place;
166 if(pl > race_highest_place_spawn)
168 if(spot.race_place != pl)
174 ent = find(ent, targetname, spot.target);
182 shortest = vlen(world.maxs - world.mins);
183 for(player = playerlist; player; player = player.chain)
186 thisdist = vlen(player.origin - spot.origin);
187 if (thisdist < shortest)
195 entity Spawn_FilterOutBadSpots(entity firstspot, entity playerlist, float mindist, float teamcheck)
197 local entity spot, spotlist, spotlistend;
198 spawn_allgood = TRUE;
204 for(spot = firstspot; spot; spot = spot.chain)
206 spot.SPAWNPOINT_SCORE = Spawn_Score(spot, playerlist, teamcheck);
208 if(cvar("spawn_debugview"))
210 setmodel(spot, "models/runematch/rune.mdl");
211 if(spot.SPAWNPOINT_SCORE < mindist)
213 spot.colormod = '1 0 0';
218 spot.colormod = '0 1 0';
219 spot.scale = spot.SPAWNPOINT_SCORE / mindist;
223 if(spot.SPAWNPOINT_SCORE >= 0) // spawning allowed here
225 if(spot.SPAWNPOINT_SCORE < mindist)
227 // too short distance
228 spawn_allgood = FALSE;
233 spawn_allbad = FALSE;
236 spotlistend.chain = spot;
243 if(spot.team != teamcheck)
244 error("invalid spawn added");
246 print("added ", etos(spot), "\n");
252 spotlistend.chain = world;
257 for(e = spotlist; e; e = e.chain)
259 print("seen ", etos(e), "\n");
260 if(e.team != teamcheck)
261 error("invalid spawn found");
268 entity Spawn_WeightedPoint(entity firstspot, float lower, float upper, float exponent)
270 // weight of a point: bound(lower, mindisttoplayer, upper)^exponent
271 // multiplied by spot.cnt (useful if you distribute many spawnpoints in a small area)
274 RandomSelection_Init();
275 for(spot = firstspot; spot; spot = spot.chain)
276 RandomSelection_Add(spot, 0, string_null, pow(bound(lower, spot.SPAWNPOINT_SCORE, upper), exponent) * spot.cnt, spot.SPAWNPOINT_SCORE >= lower);
278 return RandomSelection_chosen_ent;
285 Finds a point to respawn
288 entity SelectSpawnPoint (float anypoint)
290 local float teamcheck;
291 local entity firstspot_new;
292 local entity spot, firstspot, playerlist;
294 spot = find (world, classname, "testplayerstart");
300 if(!anypoint && have_team_spawns)
301 teamcheck = self.team;
303 // get the list of players
304 playerlist = findchain(classname, "player");
305 // get the entire list of spots
306 firstspot = findchain(classname, "info_player_deathmatch");
307 // filter out the bad ones
308 // (note this returns the original list if none survived)
309 firstspot_new = Spawn_FilterOutBadSpots(firstspot, playerlist, 100, teamcheck);
311 firstspot_new = Spawn_FilterOutBadSpots(firstspot, playerlist, -1, teamcheck);
312 firstspot = firstspot_new;
314 // there is 50/50 chance of choosing a random spot or the furthest spot
315 // (this means that roughly every other spawn will be furthest, so you
316 // usually won't get fragged at spawn twice in a row)
317 if (arena_roundbased)
319 firstspot_new = Spawn_FilterOutBadSpots(firstspot, playerlist, 800, teamcheck);
321 firstspot = firstspot_new;
322 spot = Spawn_WeightedPoint(firstspot, 1, 1, 1);
324 else if (random() > cvar("g_spawn_furthest"))
325 spot = Spawn_WeightedPoint(firstspot, 1, 1, 1);
327 spot = Spawn_WeightedPoint(firstspot, 1, 5000, 5); // chooses a far far away spawnpoint
329 if(cvar("spawn_debugview"))
331 print("spot mindistance: ", ftos(spot.SPAWNPOINT_SCORE), "\n");
335 for(e = firstspot; e; e = e.chain)
336 if(e.team != teamcheck)
337 error("invalid spawn found");
342 if(cvar("spawn_debug"))
346 if(some_spawn_has_been_used)
347 return world; // team can't spawn any more, because of actions of other team
349 error("Cannot find a spawn point - please fix the map!");
360 Checks if the argument string can be a valid playermodel.
361 Returns a valid one in doubt.
364 string FallbackPlayerModel = "models/player/marine.zym";
365 string CheckPlayerModel(string plyermodel) {
366 if(strlen(plyermodel) < 4)
367 return FallbackPlayerModel;
368 if( substring(plyermodel,0,14) != "models/player/")
369 return FallbackPlayerModel;
370 else if(cvar("sv_servermodelsonly"))
372 if(substring(plyermodel,-4,4) != ".zym")
373 if(substring(plyermodel,-4,4) != ".dpm")
374 if(substring(plyermodel,-4,4) != ".md3")
375 if(substring(plyermodel,-4,4) != ".psk")
376 return FallbackPlayerModel;
377 // forbid the LOD models
378 if(substring(plyermodel, -9,5) == "_lod1")
379 return FallbackPlayerModel;
380 if(substring(plyermodel, -9,5) == "_lod2")
381 return FallbackPlayerModel;
382 if(plyermodel != strtolower(plyermodel))
383 return FallbackPlayerModel;
384 if(!fexists(plyermodel))
385 return FallbackPlayerModel;
392 Client_customizeentityforclient
397 void Client_uncustomizeentityforclient()
399 self.modelindex = self.modelindex_lod0;
400 self.skin = self.skinindex;
403 float Client_customizeentityforclient()
407 if(self.modelindex == 0)
414 t0 = gettime(GETTIME_HIRES); // reference
418 if(other.cvar_cl_forceplayermodelsfromnexuiz)
419 if not(self.modelindex_lod0_from_nexuiz)
421 if(other.cvar_cl_forceplayermodels && sv_clforceplayermodels)
423 self.skin = modelsource.skinindex;
426 if(modelsource == self)
427 self.skin = modelsource.skinindex;
429 self.skin = mod(modelsource.skinindex, 3); // forbid the fbskins as forced skins
433 // other: the player viewing me
437 if(other.cvar_cl_playerdetailreduction <= 0)
439 if(other.cvar_cl_playerdetailreduction <= -2)
440 self.modelindex = modelsource.modelindex_lod2;
441 else if(other.cvar_cl_playerdetailreduction <= -1)
442 self.modelindex = modelsource.modelindex_lod1;
444 self.modelindex = modelsource.modelindex_lod0;
448 distance = vlen(self.origin - other.origin);
449 f = (distance + 100.0) * other.cvar_cl_playerdetailreduction;
450 if(f > sv_loddistance2)
451 self.modelindex = modelsource.modelindex_lod2;
452 else if(f > sv_loddistance1)
453 self.modelindex = modelsource.modelindex_lod1;
455 self.modelindex = modelsource.modelindex_lod0;
460 t1 = gettime(GETTIME_HIRES); // reference
461 client_cefc_accumulator += (t1 - t0);
467 void UpdatePlayerSounds();
468 void setmodel_lod(entity e, string modelname)
474 // FIXME: this only supports 3-letter extensions
475 s = strcat(substring(modelname, 0, strlen(modelname)-4), "_lod1", substring(modelname, -4, 4));
478 setmodel(e, s); // players have high precision
479 self.modelindex_lod1 = self.modelindex;
482 self.modelindex_lod1 = -1;
484 s = strcat(substring(modelname, 0, strlen(modelname)-4), "_lod2", substring(modelname, -4, 4));
487 setmodel(e, s); // players have high precision
488 self.modelindex_lod2 = self.modelindex;
491 self.modelindex_lod2 = -1;
493 precache_model(modelname);
494 setmodel(e, modelname); // players have high precision
495 self.modelindex_lod0 = self.modelindex;
497 if(self.modelindex_lod1 < 0)
498 self.modelindex_lod1 = self.modelindex;
500 if(self.modelindex_lod2 < 0)
501 self.modelindex_lod2 = self.modelindex;
505 precache_model(modelname);
506 setmodel(e, modelname); // players have high precision
507 self.modelindex_lod0 = self.modelindex;
508 // save it for possible player model forcing
511 s = whichpack(self.model);
512 self.modelindex_lod0_from_nexuiz = ((s == "") || (substring(s, 0, 4) == "data"));
514 player_setupanimsformodel();
515 UpdatePlayerSounds();
522 putting a client as observer in the server
525 void PutObserverInServer (void)
529 race_PreSpawnObserver();
531 spot = SelectSpawnPoint (TRUE);
533 error("No spawnpoints for observers?!?\n");
534 RemoveGrapplingHook(self); // Wazat's Grappling Hook
536 if(clienttype(self) == CLIENTTYPE_REAL)
539 WriteByte(MSG_ONE, SVC_SETVIEW);
540 WriteEntity(MSG_ONE, self);
544 kh_Key_DropAll(self, TRUE);
546 Portal_ClearAll(self);
549 DropFlag(self.flagcarried, world, world);
551 DropBall(self.ballcarried, self.origin + self.ballcarried.origin, self.velocity);
553 WaypointSprite_PlayerDead();
555 if(self.killcount != -666)
559 if(PlayerScore_Add(self, SP_LMS_RANK, 0) > 0)
560 bprint ("^4", self.netname, "^4 has no more lives left\n");
562 bprint ("^4", self.netname, "^4 is spectating now\n"); // TODO turn this into a proper forfeit?
565 bprint ("^4", self.netname, "^4 is spectating now\n");
568 PlayerScore_Clear(self); // clear scores when needed
570 self.spectatortime = time;
572 self.classname = "observer";
573 self.iscreature = FALSE;
575 self.takedamage = DAMAGE_NO;
576 self.solid = SOLID_NOT;
577 self.movetype = MOVETYPE_NOCLIP;
578 self.flags = FL_CLIENT | FL_NOTARGET;
579 self.armorvalue = 666;
581 self.armorvalue = cvar("g_balance_armor_start");
582 self.pauserotarmor_finished = 0;
583 self.pauserothealth_finished = 0;
584 self.pauseregen_finished = 0;
585 self.damageforcescale = 0;
592 self.pain_finished = 0;
593 self.strength_finished = 0;
594 self.invincible_finished = 0;
595 self.damage_hits = 0;
596 self.maxdamage_fired = 0;
598 self.think = SUB_Null;
602 self.deadflag = DEAD_NO;
603 self.angles = spot.angles;
605 self.fixangle = TRUE;
608 self.view_ofs = PL_VIEW_OFS;
609 setorigin (self, spot.origin);
610 setsize (self, '0 0 0', '0 0 0');
611 self.prevorigin = self.origin;
617 self.weaponmodel = "";
618 self.weaponentity = world;
619 self.exteriorweaponentity = world;
620 self.killcount = -666;
621 self.velocity = '0 0 0';
622 self.avelocity = '0 0 0';
623 self.punchangle = '0 0 0';
624 self.punchvector = '0 0 0';
625 self.oldvelocity = self.velocity;
628 SetCustomizer(self, Client_customizeentityforclient, Client_uncustomizeentityforclient);
634 if(self.version_mismatch)
636 Spawnqueue_Unmark(self);
637 Spawnqueue_Remove(self);
641 Spawnqueue_Insert(self);
646 // Only if the player cannot play at all
647 if(PlayerScore_Add(self, SP_LMS_RANK, 0) == 666)
648 self.frags = FRAGS_SPECTATOR;
650 self.frags = FRAGS_LMS_LOSER;
653 self.frags = FRAGS_SPECTATOR;
656 float RestrictSkin(float s)
665 void FixPlayermodel()
667 local string defaultmodel;
668 local float defaultskin, chmdl, oldskin;
673 if(cvar("sv_defaultcharacter") == 1) {
678 defaultmodel = cvar_string(strcat("sv_defaultplayermodel_", Team_ColorNameLowerCase(self.team)));
679 defaultskin = cvar(strcat("sv_defaultplayerskin_", Team_ColorNameLowerCase(self.team)));
682 if(defaultmodel == "")
684 defaultmodel = cvar_string("sv_defaultplayermodel");
685 defaultskin = cvar("sv_defaultplayerskin");
689 if(self.modelindex == 0 && self.deadflag == DEAD_NO)
692 bprint("\{1}^1Player ", self.netname, "^1 has a zero modelindex, trying to fix...\n");
693 self.model = ""; // force the != checks to return true
696 if(defaultmodel != "")
698 if (defaultmodel != self.model)
702 setmodel_lod (self, defaultmodel);
703 setsize (self, m1, m2);
707 oldskin = self.skinindex;
708 self.skinindex = defaultskin;
710 if (self.playermodel != self.model)
712 self.playermodel = CheckPlayerModel(self.playermodel);
715 setmodel_lod (self, self.playermodel);
716 setsize (self, m1, m2);
720 oldskin = self.skinindex;
721 self.skinindex = RestrictSkin(stof(self.playerskin));
724 if(chmdl || oldskin != self.skinindex)
725 self.species = player_getspecies(); // model or skin has changed
728 if(strlen(cvar_string("sv_defaultplayercolors")))
729 if(self.clientcolors != cvar("sv_defaultplayercolors"))
730 setcolor(self, cvar("sv_defaultplayercolors"));
733 void PlayerTouchExplode(entity p1, entity p2)
736 org = (p1.origin + p2.origin) * 0.5;
737 org_z += (p1.mins_z + p2.mins_z) * 0.5;
744 RadiusDamage(e, world, g_touchexplode_damage, g_touchexplode_edgedamage, g_touchexplode_radius, world, g_touchexplode_force, DEATH_TOUCHEXPLODE, world);
752 Called when a client spawns in the server
755 //void() ctf_playerchanged;
756 void PutClientInServer (void)
758 if(clienttype(self) == CLIENTTYPE_BOT)
760 self.classname = "player";
762 else if(clienttype(self) == CLIENTTYPE_REAL)
765 WriteByte(MSG_ONE, SVC_SETVIEW);
766 WriteEntity(MSG_ONE, self);
769 // player is dead and becomes observer
770 // FIXME fix LMS scoring for new system
773 if(PlayerScore_Add(self, SP_LMS_RANK, 0) > 0)
774 self.classname = "observer";
779 self.classname = "observer";
781 if(self.classname == "player") {
782 entity spot, oldself;
785 JoinBestTeam(self, FALSE, TRUE);
789 spot = SelectSpawnPoint (FALSE);
792 centerprint(self, "Sorry, no spawnpoints available!\nHope your team can fix it...");
793 return; // spawn failed
796 RemoveGrapplingHook(self); // Wazat's Grappling Hook
797 self.campingrifle_bulletcounter = 0;
799 self.classname = "player";
800 self.wasplayer = TRUE;
801 self.iscreature = TRUE;
802 self.movetype = MOVETYPE_WALK;
803 self.solid = SOLID_SLIDEBOX;
804 self.dphitcontentsmask = DPCONTENTS_SOLID | DPCONTENTS_BODY | DPCONTENTS_PLAYERCLIP;
805 self.frags = FRAGS_PLAYER;
806 if(independent_players)
807 MAKE_INDEPENDENT_PLAYER(self);
808 self.flags = FL_CLIENT;
809 self.takedamage = DAMAGE_AIM;
811 self.effects = EF_FULLBRIGHT;
814 self.air_finished = time + 12;
819 self.ammo_shells = warmup_start_ammo_shells;
820 self.ammo_nails = warmup_start_ammo_nails;
821 self.ammo_rockets = warmup_start_ammo_rockets;
822 self.ammo_cells = warmup_start_ammo_cells;
823 self.ammo_fuel = warmup_start_ammo_fuel;
824 self.health = warmup_start_health;
825 self.armorvalue = warmup_start_armorvalue;
826 self.weapons = warmup_start_weapons;
830 self.ammo_shells = start_ammo_shells;
831 self.ammo_nails = start_ammo_nails;
832 self.ammo_rockets = start_ammo_rockets;
833 self.ammo_cells = start_ammo_cells;
834 self.ammo_fuel = start_ammo_fuel;
835 self.health = start_health;
836 self.armorvalue = start_armorvalue;
837 self.weapons = start_weapons;
839 self.items = start_items;
840 self.switchweapon = w_getbestweapon(self);
841 self.cnt = self.switchweapon;
843 self.jump_interval = time;
845 self.spawnshieldtime = time + cvar("g_spawnshieldtime");
846 self.pauserotarmor_finished = time + cvar("g_balance_pause_armor_rot_spawn");
847 self.pauserothealth_finished = time + cvar("g_balance_pause_health_rot_spawn");
848 self.pauserotfuel_finished = time + cvar("g_balance_pause_fuel_rot_spawn");
849 self.pauseregen_finished = time + cvar("g_balance_pause_health_regen_spawn");
850 //extend the pause of rotting if client was reset at the beginning of the countdown
851 if(!cvar("sv_ready_restart_after_countdown") && time < game_starttime) { // TODO why is this cvar NOTted?
852 self.spawnshieldtime += game_starttime - time;
853 self.pauserotarmor_finished += game_starttime - time;
854 self.pauserothealth_finished += game_starttime - time;
855 self.pauseregen_finished += game_starttime - time;
857 self.damageforcescale = 2;
864 self.pain_finished = 0;
865 self.strength_finished = 0;
866 self.invincible_finished = 0;
867 self.maxdamage_fired = 0;
868 self.damage_hits = 0;
870 //self.speed_finished = 0;
871 //self.slowmo_finished = 0;
872 // players have no think function
873 self.think = SUB_Null;
882 self.deadflag = DEAD_NO;
884 self.angles = spot.angles;
886 self.angles_z = 0; // never spawn tilted even if the spot says to
887 self.fixangle = TRUE; // turn this way immediately
888 self.velocity = '0 0 0';
889 self.avelocity = '0 0 0';
890 self.punchangle = '0 0 0';
891 self.punchvector = '0 0 0';
892 self.oldvelocity = self.velocity;
895 WRITESPECTATABLE_MSG_ONE({
896 WriteByte(MSG_ONE, SVC_TEMPENTITY);
897 WriteByte(MSG_ONE, TE_CSQC_SPAWN);
901 SetCustomizer(self, Client_customizeentityforclient, Client_uncustomizeentityforclient);
907 self.view_ofs = PL_VIEW_OFS;
908 setsize (self, PL_MIN, PL_MAX);
909 self.spawnorigin = spot.origin;
910 setorigin (self, spot.origin + '0 0 1' * (1 - self.mins_z - 24));
911 // don't reset back to last position, even if new position is stuck in solid
912 self.oldorigin = self.origin;
913 self.prevorigin = self.origin;
914 self.lastrocket = world; // stop rocket guiding, no revenge from the grave!
918 Spawnqueue_Remove(self);
919 Spawnqueue_Mark(self);
922 self.event_damage = PlayerDamage;
924 self.bot_attack = TRUE;
926 self.statdraintime = time + 5;
927 self.BUTTON_ATCK = self.BUTTON_JUMP = self.BUTTON_ATCK2 = 0;
929 if(self.killcount == -666) {
930 PlayerScore_Clear(self);
934 self.cnt = WEP_LASER;
935 self.nixnex_lastchange_id = -1;
937 CL_SpawnWeaponentity();
938 self.alpha = default_player_alpha;
939 self.colormod = '1 1 1' * cvar("g_player_brightness");
940 self.exteriorweaponentity.alpha = default_weapon_alpha;
942 self.lms_nextcheck = time + cvar("g_lms_campcheck_interval")*2;
943 self.lms_traveled_distance = 0;
944 self.speedrunning = FALSE;
946 race_PostSpawn(spot);
948 if(cvar("spawn_debug"))
950 sprint(self, strcat("spawnpoint origin: ", vtos(spot.origin), "\n"));
951 remove(spot); // usefull for checking if there are spawnpoints, that let drop through the floor
954 //stuffcmd(self, "chase_active 0");
955 //stuffcmd(self, "set viewsize $tmpviewsize \n");
957 if (cvar("g_spawnsound"))
958 sound (self, CHAN_TRIGGER, "misc/spawn.wav", VOL_BASE, ATTN_NORM);
961 if(self.team == assault_attacker_team)
962 centerprint(self, "You are attacking!");
964 centerprint(self, "You are defending!");
967 target_voicescript_clear(self);
976 } else if(self.classname == "observer") {
977 PutObserverInServer ();
981 // ctf_playerchanged();
984 float ClientInit_SendEntity(entity to, float sf)
987 WriteByte(MSG_ENTITY, ENT_CLIENT_INIT);
988 WriteByte(MSG_ENTITY, g_nexball_meter_period * 32);
989 for(i = 1; i <= 24; ++i)
990 WriteByte(MSG_ENTITY, (get_weaponinfo(i)).impulse + 1);
991 WriteCoord(MSG_ENTITY, hook_shotorigin_x);
992 WriteCoord(MSG_ENTITY, hook_shotorigin_y);
993 WriteCoord(MSG_ENTITY, hook_shotorigin_z);
995 if(sv_foginterval && world.fog != "")
996 WriteString(MSG_ENTITY, world.fog);
998 WriteString(MSG_ENTITY, "");
999 WriteByte(MSG_ENTITY, cvar("g_balance_armor_blockpercent") * 255.0);
1003 void ClientInit_Spawn()
1005 Net_LinkEntity(spawn(), FALSE, 0, ClientInit_SendEntity);
1013 void SetNewParms (void)
1015 // initialize parms for a new player
1016 parm1 = -(86400 * 366);
1024 void SetChangeParms (void)
1026 // save parms for level change
1027 parm1 = self.parm_idlesince - time;
1035 void DecodeLevelParms (void)
1038 self.parm_idlesince = parm1;
1039 if(self.parm_idlesince == -(86400 * 366))
1040 self.parm_idlesince = time;
1042 // whatever happens, allow 60 seconds of idling directly after connect for map loading
1043 self.parm_idlesince = max(self.parm_idlesince, time - sv_maxidle + 60);
1050 Called when a client types 'kill' in the console
1054 void ClientKill_Now_TeamChange()
1056 if(self.killindicator_teamchange == -1)
1059 JoinBestTeam( self, FALSE, FALSE );
1062 SV_ChangeTeam(self.killindicator_teamchange - 1);
1065 void ClientKill_Now()
1067 if(self.killindicator_teamchange)
1068 ClientKill_Now_TeamChange();
1071 Damage(self, self, self, 100000, DEATH_KILL, self.origin, '0 0 0');
1073 if(self.killindicator)
1075 dprint("Cleaned up after a leaked kill indicator.\n");
1076 remove(self.killindicator);
1077 self.killindicator = world;
1080 void KillIndicator_Think()
1082 if (!self.owner.modelindex)
1084 self.owner.killindicator = world;
1092 ClientKill_Now(); // no oldself needed
1098 setmodel(self, strcat("models/sprites/", ftos(self.cnt), ".spr32"));
1099 if(clienttype(self.owner) == CLIENTTYPE_REAL)
1102 announce(self.owner, strcat("announcer/robotic/", ftos(self.cnt), ".wav"));
1103 if(self.owner.killindicator_teamchange)
1105 if(self.owner.killindicator_teamchange == -1)
1106 centerprint(self.owner, strcat("Changing team in ", ftos(self.cnt), " seconds"));
1108 centerprint(self.owner, strcat("Changing to ", ColoredTeamName(self.owner.killindicator_teamchange), " in ", ftos(self.cnt), " seconds"));
1111 centerprint(self.owner, strcat("^1Suicide in ", ftos(self.cnt), " seconds"));
1113 self.nextthink = time + 1;
1118 void ClientKill_TeamChange (float targetteam) // 0 = don't change, -1 = auto
1122 killtime = cvar("g_balance_kill_delay");
1124 self.killindicator_teamchange = targetteam;
1126 if(!self.killindicator)
1128 if(killtime <= 0 || !self.modelindex || self.deadflag != DEAD_NO)
1134 self.killindicator = spawn();
1135 self.killindicator.owner = self;
1136 self.killindicator.scale = 0.5;
1137 setattachment(self.killindicator, self, "");
1138 setorigin(self.killindicator, '0 0 52');
1139 self.killindicator.think = KillIndicator_Think;
1140 self.killindicator.nextthink = time + (self.lip) * 0.05;
1141 self.killindicator.cnt = ceil(killtime);
1142 self.killindicator.count = bound(0, ceil(killtime), 10);
1143 sprint(self, strcat("^1You'll be dead in ", ftos(self.killindicator.cnt), " seconds\n"));
1145 for(e = world; (e = find(e, classname, "body")) != world; )
1149 e.killindicator = spawn();
1150 e.killindicator.owner = e;
1151 e.killindicator.scale = 0.5;
1152 setattachment(e.killindicator, e, "");
1153 setorigin(e.killindicator, '0 0 52');
1154 e.killindicator.think = KillIndicator_Think;
1155 e.killindicator.nextthink = time + (e.lip) * 0.05;
1156 e.killindicator.cnt = ceil(killtime);
1161 if(self.killindicator)
1164 self.killindicator.colormod = TeamColor(targetteam);
1166 self.killindicator.colormod = '0 0 0';
1170 void ClientKill (void)
1172 ClientKill_TeamChange(0);
1175 void DoTeamChange(float destteam)
1181 SetPlayerColors(self, destteam);
1184 if(self.classname == "player")
1187 CheckAllowedTeams(self);
1188 t = FindSmallestTeam(self, TRUE);
1191 case COLOR_TEAM1: c0 = c1; break;
1192 case COLOR_TEAM2: c0 = c2; break;
1193 case COLOR_TEAM3: c0 = c3; break;
1194 case COLOR_TEAM4: c0 = c4; break;
1201 destteam = COLOR_TEAM1;
1205 destteam = COLOR_TEAM2;
1209 destteam = COLOR_TEAM3;
1213 destteam = COLOR_TEAM4;
1219 if(destteam == self.team && destteam >= 0 && !self.killindicator)
1221 ClientKill_TeamChange(destteam);
1224 void FixClientCvars(entity e)
1226 // send prediction settings to the client
1227 stuffcmd(e, "\nin_bindmap 0 0\n");
1229 * we no longer need to stuff this. Remove this comment block if you feel
1230 * 2.3 and higher (or was it 2.2.3?) don't need these any more
1231 stuffcmd(e, strcat("cl_gravity ", ftos(cvar("sv_gravity")), "\n"));
1232 stuffcmd(e, strcat("cl_movement_accelerate ", ftos(cvar("sv_accelerate")), "\n"));
1233 stuffcmd(e, strcat("cl_movement_friction ", ftos(cvar("sv_friction")), "\n"));
1234 stuffcmd(e, strcat("cl_movement_maxspeed ", ftos(cvar("sv_maxspeed")), "\n"));
1235 stuffcmd(e, strcat("cl_movement_airaccelerate ", ftos(cvar("sv_airaccelerate")), "\n"));
1236 stuffcmd(e, strcat("cl_movement_maxairspeed ", ftos(cvar("sv_maxairspeed")), "\n"));
1237 stuffcmd(e, strcat("cl_movement_stopspeed ", ftos(cvar("sv_stopspeed")), "\n"));
1238 stuffcmd(e, strcat("cl_movement_jumpvelocity ", ftos(cvar("sv_jumpvelocity")), "\n"));
1239 stuffcmd(e, strcat("cl_movement_stepheight ", ftos(cvar("sv_stepheight")), "\n"));
1240 stuffcmd(e, strcat("set cl_movement_friction_on_land ", ftos(cvar("sv_friction_on_land")), "\n"));
1241 stuffcmd(e, strcat("set cl_movement_airaccel_qw ", ftos(cvar("sv_airaccel_qw")), "\n"));
1242 stuffcmd(e, strcat("set cl_movement_airaccel_sideways_friction ", ftos(cvar("sv_airaccel_sideways_friction")), "\n"));
1243 stuffcmd(e, "cl_movement_edgefriction 1\n");
1251 Called when a client connects to the server
1254 //void ctf_clientconnect();
1255 string ColoredTeamName(float t);
1256 void DecodeLevelParms (void);
1257 //void dom_player_join_team(entity pl);
1258 void ClientConnect (void)
1263 if(self.flags & FL_CLIENT)
1265 print("Warning: ClientConnect, but already connected!\n");
1269 if(Ban_MaybeEnforceBan(self))
1274 self.classname = "player_joining";
1276 self.flags = FL_CLIENT;
1277 self.version_nagtime = time + 10 + random() * 10;
1281 dprint("BUG player count is lower than zero, this cannot happen!\n");
1285 PlayerScore_Attach(self);
1286 ClientData_Attach();
1288 bot_clientconnect();
1290 race_PreSpawnObserver();
1293 // dom_player_join_team(self);
1295 JoinBestTeam(self, FALSE, FALSE); // if the team number is valid, keep it
1297 if((cvar("sv_spectate") == 1 && !g_lms) || cvar("g_campaign")) {
1298 self.classname = "observer";
1302 if(cvar("g_balance_teams") || cvar("g_balance_teams_force"))
1304 self.classname = "player";
1305 campaign_bots_may_start = 1;
1309 self.classname = "observer"; // do it anyway
1314 self.classname = "player";
1315 campaign_bots_may_start = 1;
1319 self.playerid = (playerid_last = playerid_last + 1);
1320 if(cvar("sv_eventlog"))
1322 if(clienttype(self) == CLIENTTYPE_REAL)
1323 GameLogEcho(strcat(":join:", ftos(self.playerid), ":", ftos(num_for_edict(self)), ":", self.netaddress, ":", self.netname));
1325 GameLogEcho(strcat(":join:", ftos(self.playerid), ":", ftos(num_for_edict(self)), ":bot:", self.netname));
1326 s = strcat(":team:", ftos(self.playerid), ":");
1327 s = strcat(s, ftos(self.team));
1330 self.netname_previous = strzone(self.netname);
1332 //stuffcmd(self, "set tmpviewsize $viewsize \n");
1334 bprint ("^4",self.netname);
1335 bprint ("^4 connected");
1337 if(g_domination || g_ctf)
1339 bprint(" and joined the ");
1340 bprint(ColoredTeamName(self.team));
1345 self.welcomemessage_time = 0;
1347 stuffcmd(self, strcat(clientstuff, "\n"));
1348 stuffcmd(self, strcat("exec maps/", mapname, ".cfg\n"));
1349 stuffcmd(self, "cl_particles_reloadeffects\n");
1351 FixClientCvars(self);
1353 // spawnfunc_waypoint sprites
1354 WaypointSprite_InitClient(self);
1356 // Wazat's grappling hook
1357 SetGrappleHookBindings();
1359 // get autoswitch state from player when he toggles it
1360 stuffcmd(self, "alias autoswitch \"set cl_autoswitch $1 ; cmd autoswitch $1\"\n"); // default.cfg-ed in 2.4.1
1362 // get version info from player
1363 stuffcmd(self, "cmd clientversion $gameversion\n");
1365 // get other cvars from player
1368 // set cvar for team scoreboard
1369 stuffcmd(self, strcat("set teamplay ", ftos(teamplay), "\n"));
1371 // notify about available teams
1374 CheckAllowedTeams(self);
1375 t = 0; if(c1 >= 0) t |= 1; if(c2 >= 0) t |= 2; if(c3 >= 0) t |= 4; if(c4 >= 0) t |= 8;
1376 stuffcmd(self, strcat("set _teams_available ", ftos(t), "\n"));
1379 stuffcmd(self, "set _teams_available 0\n");
1381 stuffcmd(self, strcat("set gametype ", ftos(game), "\n"));
1385 self.classname = "observer";
1386 Spawnqueue_Insert(self);
1390 ctf_clientconnect();
1393 if(teams_matter || sv_cheats)
1396 bot_relinkplayerlist();
1398 self.spectatortime = time;
1401 sprint(self, strcat("^7You have to become a player within the next ", ftos(cvar("g_maxplayers_spectator_blocktime")), " seconds, otherwise you will be kicked, because spectators aren't allowed at this time!\n"));
1404 self.jointime = time;
1405 self.allowedTimeouts = cvar("sv_timeout_number");
1407 if(clienttype(self) == CLIENTTYPE_REAL)
1409 if(cvar("g_bugrigs") || g_weaponarena == WEPBIT_TUBA)
1410 stuffcmd(self, "cl_cmd settemp chase_active 1\n");
1415 if(PlayerScore_Add(self, SP_LMS_LIVES, LMS_NewPlayerLives()) <= 0)
1417 PlayerScore_Add(self, SP_LMS_RANK, 666);
1418 self.frags = FRAGS_SPECTATOR;
1422 if(!sv_foginterval && world.fog != "")
1423 stuffcmd(self, strcat("\nfog ", world.fog, "\nr_fog_exp2 0\nr_drawfog 1\n"));
1425 SoundEntity_Attach(self);
1427 if(cvar("g_hitplots"))
1429 self.hitplotfh = fopen(strcat("hits-", matchid, "-", ftos(self.playerid), ".plot"), FILE_WRITE);
1430 fputs(self.hitplotfh, strcat("#name ", self.netname, "\n"));
1433 self.hitplotfh = -1;
1440 Called when a client disconnects from the server
1443 .entity chatbubbleentity;
1444 .entity teambubbleentity;
1446 void ClientDisconnect (void)
1448 if not(self.flags & FL_CLIENT)
1450 print("Warning: ClientDisconnect without ClientConnect\n");
1454 if(self.hitplotfh >= 0)
1456 fclose(self.hitplotfh);
1457 self.hitplotfh = -1;
1460 bot_clientdisconnect();
1465 if(cvar("sv_eventlog"))
1466 GameLogEcho(strcat(":part:", ftos(self.playerid)));
1467 bprint ("^4",self.netname);
1468 bprint ("^4 disconnected\n");
1470 SoundEntity_Detach(self);
1473 kh_Key_DropAll(self, TRUE);
1475 Portal_ClearAll(self);
1477 if(self.flagcarried)
1478 DropFlag(self.flagcarried, world, world);
1479 if(self.ballcarried)
1480 DropBall(self.ballcarried, self.origin + self.ballcarried.origin, self.velocity);
1482 // Here, everything has been done that requires this player to be a client.
1484 self.flags &~= FL_CLIENT;
1486 if (self.chatbubbleentity)
1487 remove (self.chatbubbleentity);
1489 if (self.teambubbleentity)
1490 remove (self.teambubbleentity);
1492 if (self.killindicator)
1493 remove (self.killindicator);
1495 WaypointSprite_PlayerGone();
1497 bot_relinkplayerlist();
1500 if(self.weaponentity)
1501 if(self.weaponentity.lasertarget)
1502 remove(self.weaponentity.lasertarget);
1506 Spawnqueue_Unmark(self);
1507 Spawnqueue_Remove(self);
1510 ClientData_Detach();
1511 PlayerScore_Detach(self);
1513 if(self.netname_previous)
1514 strunzone(self.netname_previous);
1515 if(self.clientstatus)
1516 strunzone(self.clientstatus);
1518 ClearPlayerSounds();
1528 void ChatBubbleThink()
1530 self.nextthink = time;
1531 if (!self.owner.modelindex || self.owner.chatbubbleentity != self)
1533 if(self.owner) // but why can that ever be world?
1534 self.owner.chatbubbleentity = world;
1538 if (self.owner.BUTTON_CHAT && !self.owner.deadflag)
1539 self.model = self.mdl;
1544 void UpdateChatBubble()
1546 if (!self.modelindex)
1548 // spawn a chatbubble entity if needed
1549 if (!self.chatbubbleentity)
1551 self.chatbubbleentity = spawn();
1552 self.chatbubbleentity.owner = self;
1553 self.chatbubbleentity.exteriormodeltoclient = self;
1554 self.chatbubbleentity.think = ChatBubbleThink;
1555 self.chatbubbleentity.nextthink = time;
1556 setmodel(self.chatbubbleentity, "models/misc/chatbubble.spr"); // precision set below
1557 //setorigin(self.chatbubbleentity, self.origin + '0 0 15' + self.maxs_z * '0 0 1');
1558 setorigin(self.chatbubbleentity, '0 0 15' + self.maxs_z * '0 0 1');
1559 setattachment(self.chatbubbleentity, self, ""); // sticks to moving player better, also conserves bandwidth
1560 self.chatbubbleentity.mdl = self.chatbubbleentity.model;
1561 self.chatbubbleentity.model = "";
1562 self.chatbubbleentity.effects = EF_LOWPRECISION;
1567 void TeamBubbleThink()
1569 self.nextthink = time;
1570 if (!self.owner.modelindex || self.owner.teambubbleentity != self)
1572 if(self.owner) // but why can that ever be world?
1573 self.owner.teambubbleentity = world;
1577 // setorigin(self, self.owner.origin + '0 0 15' + self.owner.maxs_z * '0 0 1'); // bandwidth hog. setattachment does this now
1578 if (self.owner.BUTTON_CHAT || self.owner.deadflag || self.owner.killindicator)
1581 self.model = self.mdl;
1585 float TeamBubble_customizeentityforclient()
1587 return (self.owner != other && self.owner.team == other.team && other.killcount > -666);
1590 void UpdateTeamBubble()
1592 if (!self.modelindex || !teams_matter)
1594 // spawn a teambubble entity if needed
1595 if (!self.teambubbleentity && teams_matter)
1597 self.teambubbleentity = spawn();
1598 self.teambubbleentity.owner = self;
1599 self.teambubbleentity.exteriormodeltoclient = self;
1600 self.teambubbleentity.think = TeamBubbleThink;
1601 self.teambubbleentity.nextthink = time;
1602 setmodel(self.teambubbleentity, "models/misc/teambubble.spr"); // precision set below
1603 // setorigin(self.teambubbleentity, self.origin + '0 0 15' + self.maxs_z * '0 0 1');
1604 setorigin(self.teambubbleentity, '0 0 15' + self.maxs_z * '0 0 1');
1605 setattachment(self.teambubbleentity, self, ""); // sticks to moving player better, also conserves bandwidth
1606 self.teambubbleentity.mdl = self.teambubbleentity.model;
1607 self.teambubbleentity.model = self.teambubbleentity.mdl;
1608 self.teambubbleentity.customizeentityforclient = TeamBubble_customizeentityforclient;
1609 self.teambubbleentity.effects = EF_LOWPRECISION;
1613 // LordHavoc: this hack will be removed when proper _pants/_shirt layers are
1614 // added to the model skins
1615 /*void UpdateColorModHack()
1618 c = self.clientcolors & 15;
1619 // LordHavoc: only bothering to support white, green, red, yellow, blue
1620 if (!teams_matter) self.colormod = '0 0 0';
1621 else if (c == 0) self.colormod = '1.00 1.00 1.00';
1622 else if (c == 3) self.colormod = '0.10 1.73 0.10';
1623 else if (c == 4) self.colormod = '1.73 0.10 0.10';
1624 else if (c == 12) self.colormod = '1.22 1.22 0.10';
1625 else if (c == 13) self.colormod = '0.10 0.10 1.73';
1626 else self.colormod = '1 1 1';
1632 self.effects |= EF_NODRAW; // prevent another CopyBody
1633 PutClientInServer();
1636 void play_countdown(float finished, string samp)
1638 if(clienttype(self) == CLIENTTYPE_REAL)
1639 if(floor(finished - time - frametime) != floor(finished - time))
1640 if(finished - time < 6)
1641 sound (self, CHAN_AUTO, samp, VOL_BASE, ATTN_NORM);
1645 * When sv_timeout is used this function returs strings like
1646 * "Timeout begins in 2 seconds!\n" or "Timeout ends in 23 seconds!\n".
1647 * Called by centerprint functions
1648 * @param addOneSecond boolean, set to 1 if the welcome-message centerprint asks for the text
1650 string getTimeoutText(float addOneSecond) {
1651 if (!cvar("sv_timeout") || !timeoutStatus)
1654 local string retStr;
1655 if (timeoutStatus == 1) {
1656 if (addOneSecond == 1) {
1657 retStr = strcat("Timeout begins in ", ftos(remainingLeadTime + 1), " seconds!\n");
1660 retStr = strcat("Timeout begins in ", ftos(remainingLeadTime), " seconds!\n");
1664 else if (timeoutStatus == 2) {
1666 retStr = strcat("Timeout ends in ", ftos(remainingTimeoutTime + 1), " seconds!\n");
1667 //don't show messages like "Timeout ends in 0 seconds"...
1668 if ((remainingTimeoutTime + 1) > 0)
1674 retStr = strcat("Timeout ends in ", ftos(remainingTimeoutTime), " seconds!\n");
1675 //don't show messages like "Timeout ends in 0 seconds"...
1676 if (remainingTimeoutTime > 0)
1685 void player_powerups (void)
1687 if((self.items & IT_USING_JETPACK) && !self.deadflag)
1689 SoundEntity_StartSound(self, CHAN_PLAYER, "misc/jetpack_fly.wav", VOL_BASE, cvar("g_jetpack_attenuation"));
1690 self.modelflags |= MF_ROCKET;
1694 SoundEntity_StopSound(self, CHAN_PLAYER);
1695 self.modelflags &~= MF_ROCKET;
1698 self.effects &~= (EF_RED | EF_BLUE | EF_ADDITIVE | EF_FULLBRIGHT);
1700 if(!self.modelindex || self.deadflag) // don't apply the flags if the player is gibbed
1705 self.effects |= EF_FULLBRIGHT;
1707 if (self.items & IT_STRENGTH)
1709 play_countdown(self.strength_finished, "misc/poweroff.wav");
1710 if (time > self.strength_finished)
1712 self.alpha = default_player_alpha;
1713 self.exteriorweaponentity.alpha = default_weapon_alpha;
1714 self.items &~= IT_STRENGTH;
1715 sprint(self, "^3Invisibility has worn off\n");
1720 if (time < self.strength_finished)
1722 self.alpha = g_minstagib_invis_alpha;
1723 self.exteriorweaponentity.alpha = g_minstagib_invis_alpha;
1724 self.items |= IT_STRENGTH;
1725 sprint(self, "^3You are invisible\n");
1729 if (self.items & IT_INVINCIBLE)
1731 play_countdown(self.invincible_finished, "misc/poweroff.wav");
1732 if (time > self.invincible_finished)
1734 self.items = self.items - (self.items & IT_INVINCIBLE);
1735 sprint(self, "^3Speed has worn off\n");
1740 if (time < self.invincible_finished)
1742 self.items = self.items | IT_INVINCIBLE;
1743 sprint(self, "^3You are on speed\n");
1749 if (self.items & IT_STRENGTH)
1751 play_countdown(self.strength_finished, "misc/poweroff.wav");
1752 self.effects = self.effects | (EF_BLUE | EF_ADDITIVE | EF_FULLBRIGHT);
1753 if (time > self.strength_finished)
1755 self.items = self.items - (self.items & IT_STRENGTH);
1756 sprint(self, "^3Strength has worn off\n");
1761 if (time < self.strength_finished)
1763 self.items = self.items | IT_STRENGTH;
1764 sprint(self, "^3Strength infuses your weapons with devastating power\n");
1767 if (self.items & IT_INVINCIBLE)
1769 play_countdown(self.invincible_finished, "misc/poweroff.wav");
1770 self.effects = self.effects | (EF_RED | EF_ADDITIVE | EF_FULLBRIGHT);
1771 if (time > self.invincible_finished)
1773 self.items = self.items - (self.items & IT_INVINCIBLE);
1774 sprint(self, "^3Shield has worn off\n");
1779 if (time < self.invincible_finished)
1781 self.items = self.items | IT_INVINCIBLE;
1782 sprint(self, "^3Shield surrounds you\n");
1786 if (cvar("g_fullbrightplayers"))
1787 self.effects = self.effects | EF_FULLBRIGHT;
1789 // midair gamemode: damage only while in the air
1790 // if in midair mode, being on ground grants temporary invulnerability
1791 // (this is so that multishot weapon don't clear the ground flag on the
1792 // first damage in the frame, leaving the player vulnerable to the
1793 // remaining hits in the same frame)
1794 if (self.flags & FL_ONGROUND)
1796 self.spawnshieldtime = max(self.spawnshieldtime, time + cvar("g_midair_shieldtime"));
1798 if (time >= game_starttime)
1799 if (time < self.spawnshieldtime)
1800 self.effects = self.effects | (EF_ADDITIVE | EF_FULLBRIGHT);
1803 float CalcRegen(float current, float stable, float regenfactor, float regenframetime)
1805 if(current > stable)
1807 else if(current > stable - 0.25) // when close enough, "snap"
1810 return min(stable, current + (stable - current) * regenfactor * regenframetime);
1813 float CalcRot(float current, float stable, float rotfactor, float rotframetime)
1815 if(current < stable)
1817 else if(current < stable + 0.25) // when close enough, "snap"
1820 return max(stable, current + (stable - current) * rotfactor * rotframetime);
1823 float CalcRotRegen(float current, float regenstable, float regenfactor, float regenlinear, float regenframetime, float rotstable, float rotfactor, float rotlinear, float rotframetime, float limit)
1825 if(current > rotstable)
1827 if(rotframetime > 0)
1829 current = CalcRot(current, rotstable, rotfactor, rotframetime);
1830 current = max(rotstable, current - rotlinear * rotframetime);
1833 else if(current < regenstable)
1835 if(regenframetime > 0)
1837 current = CalcRegen(current, regenstable, regenfactor, regenframetime);
1838 current = min(regenstable, current + regenlinear * regenframetime);
1848 void player_regen (void)
1850 float minh, mina, minf, maxh, maxa, maxf, limith, limita, limitf, max_mod, regen_mod, rot_mod, limit_mod;
1851 maxh = cvar("g_balance_health_rotstable");
1852 maxa = cvar("g_balance_armor_rotstable");
1853 maxf = cvar("g_balance_fuel_rotstable");
1854 minh = cvar("g_balance_health_regenstable");
1855 mina = cvar("g_balance_armor_regenstable");
1856 minf = cvar("g_balance_fuel_regenstable");
1857 limith = cvar("g_balance_health_limit");
1858 limita = cvar("g_balance_armor_limit");
1859 limitf = cvar("g_balance_fuel_limit");
1861 max_mod = regen_mod = rot_mod = limit_mod = 1;
1863 if (self.runes & RUNE_REGEN)
1865 if (self.runes & CURSE_VENOM) // do we have both rune/curse?
1867 regen_mod = cvar("g_balance_rune_regen_combo_regenrate");
1868 max_mod = cvar("g_balance_rune_regen_combo_hpmod");
1869 limit_mod = cvar("g_balance_rune_regen_combo_limitmod");
1873 regen_mod = cvar("g_balance_rune_regen_regenrate");
1874 max_mod = cvar("g_balance_rune_regen_hpmod");
1875 limit_mod = cvar("g_balance_rune_regen_limitmod");
1878 else if (self.runes & CURSE_VENOM)
1880 max_mod = cvar("g_balance_curse_venom_hpmod");
1881 if (self.runes & RUNE_REGEN) // do we have both rune/curse?
1882 rot_mod = cvar("g_balance_rune_regen_combo_rotrate");
1884 rot_mod = cvar("g_balance_curse_venom_rotrate");
1885 limit_mod = cvar("g_balance_curse_venom_limitmod");
1886 //if (!self.runes & RUNE_REGEN)
1887 // rot_mod = cvar("g_balance_curse_venom_rotrate");
1889 maxh = maxh * max_mod;
1890 //maxa = maxa * max_mod;
1891 //maxf = maxf * max_mod;
1892 minh = minh * max_mod;
1893 //mina = mina * max_mod;
1894 //minf = minf * max_mod;
1895 limith = limith * limit_mod;
1896 limita = limita * limit_mod;
1897 //limitf = limitf * limit_mod;
1902 if (!g_minstagib && (!g_lms || cvar("g_lms_regenerate")))
1904 self.armorvalue = CalcRotRegen(self.armorvalue, mina, cvar("g_balance_armor_regen"), cvar("g_balance_armor_regenlinear"), regen_mod * frametime * (time > self.pauseregen_finished), maxa, cvar("g_balance_armor_rot"), cvar("g_balance_armor_rotlinear"), rot_mod * frametime * (time > self.pauserotarmor_finished), limita);
1905 self.health = CalcRotRegen(self.health, minh, cvar("g_balance_health_regen"), cvar("g_balance_health_regenlinear"), regen_mod * frametime * (time > self.pauseregen_finished), maxh, cvar("g_balance_health_rot"), cvar("g_balance_health_rotlinear"), rot_mod * frametime * (time > self.pauserothealth_finished), limith);
1907 // if player rotted to death... die!
1909 self.event_damage(self, self, 1, DEATH_ROT, self.origin, '0 0 0');
1912 self.ammo_fuel = CalcRotRegen(self.ammo_fuel, minf, cvar("g_balance_fuel_regen"), cvar("g_balance_fuel_regenlinear"), regen_mod * frametime * (time > self.pauseregen_finished) * (self.items & IT_FUEL_REGEN != 0), maxf, cvar("g_balance_fuel_rot"), cvar("g_balance_fuel_rotlinear"), rot_mod * frametime * (time > self.pauserotfuel_finished), limitf);
1915 float zoomstate_set;
1916 void SetZoomState(float z)
1918 if(z != self.zoomstate)
1921 ClientData_Touch(self);
1926 void GetPressedKeys(void) {
1927 if (self.movement_x > 0) // get if movement keys are pressed
1928 { // forward key pressed
1929 self.pressedkeys |= KEY_FORWARD;
1930 self.pressedkeys &~= KEY_BACKWARD;
1932 else if (self.movement_x < 0)
1933 { // backward key pressed
1934 self.pressedkeys |= KEY_BACKWARD;
1935 self.pressedkeys &~= KEY_FORWARD;
1939 self.pressedkeys &~= KEY_FORWARD;
1940 self.pressedkeys &~= KEY_BACKWARD;
1943 if (self.movement_y > 0)
1944 { // right key pressed
1945 self.pressedkeys |= KEY_RIGHT;
1946 self.pressedkeys &~= KEY_LEFT;
1948 else if (self.movement_y < 0)
1949 { // left key pressed
1950 self.pressedkeys |= KEY_LEFT;
1951 self.pressedkeys &~= KEY_RIGHT;
1955 self.pressedkeys &~= KEY_RIGHT;
1956 self.pressedkeys &~= KEY_LEFT;
1959 if (self.BUTTON_JUMP) // get if jump and crouch keys are pressed
1960 self.pressedkeys |= KEY_JUMP;
1962 self.pressedkeys &~= KEY_JUMP;
1963 if (self.BUTTON_CROUCH)
1964 self.pressedkeys |= KEY_CROUCH;
1966 self.pressedkeys &~= KEY_CROUCH;
1970 ======================
1971 spectate mode routines
1972 ======================
1974 void SpectateCopy(entity spectatee) {
1975 self.armortype = spectatee.armortype;
1976 self.armorvalue = spectatee.armorvalue;
1977 self.ammo_cells = spectatee.ammo_cells;
1978 self.ammo_shells = spectatee.ammo_shells;
1979 self.ammo_nails = spectatee.ammo_nails;
1980 self.ammo_rockets = spectatee.ammo_rockets;
1981 self.ammo_fuel = spectatee.ammo_fuel;
1982 self.effects = spectatee.effects & EFMASK_CHEAP; // eat performance
1983 self.health = spectatee.health;
1985 self.items = spectatee.items;
1986 self.metertime = spectatee.metertime;
1987 self.strength_finished = spectatee.strength_finished;
1988 self.invincible_finished = spectatee.invincible_finished;
1989 self.maxdamage_fired = spectatee.maxdamage_fired;
1990 self.damage_hits = spectatee.damage_hits;
1991 self.pressedkeys = spectatee.pressedkeys;
1992 self.weapons = spectatee.weapons;
1993 self.switchweapon = spectatee.switchweapon;
1994 self.weapon = spectatee.weapon;
1995 self.punchangle = spectatee.punchangle;
1996 self.view_ofs = spectatee.view_ofs;
1997 self.v_angle = spectatee.v_angle;
1998 self.velocity = spectatee.velocity;
1999 self.dmg_take = spectatee.dmg_take;
2000 self.dmg_save = spectatee.dmg_save;
2001 self.dmg_inflictor = spectatee.dmg_inflictor;
2002 self.angles = spectatee.v_angle;
2003 self.fixangle = TRUE;
2004 setorigin(self, spectatee.origin);
2005 setsize(self, spectatee.mins, spectatee.maxs);
2006 SetZoomState(spectatee.zoomstate);
2009 float SpectateUpdate() {
2013 if (self == self.enemy)
2016 if(self.enemy.classname != "player")
2019 SpectateCopy(self.enemy);
2024 float SpectateNext() {
2025 other = find(self.enemy, classname, "player");
2027 other = find(other, classname, "player");
2032 if(self.enemy.classname == "player") {
2034 WriteByte(MSG_ONE, SVC_SETVIEW);
2035 WriteEntity(MSG_ONE, self.enemy);
2036 //stuffcmd(self, "set viewsize $tmpviewsize \n");
2037 if(!SpectateUpdate())
2038 PutObserverInServer();
2047 ShowRespawnCountdown()
2049 Update a respawn countdown display.
2052 void ShowRespawnCountdown()
2055 if(self.deadflag == DEAD_NO) // just respawned?
2059 number = ceil(self.death_time - time);
2062 if(number <= self.respawn_countdown)
2064 self.respawn_countdown = number - 1;
2065 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
2066 announce(self, strcat("announcer/robotic/", ftos(number), ".wav"));
2071 void LeaveSpectatorMode()
2073 if(isJoinAllowed()) {
2074 if(!teams_matter || cvar("g_campaign") || cvar("g_balance_teams") || (self.wasplayer && cvar("g_changeteam_banned"))) {
2075 self.classname = "player";
2076 if(cvar("g_campaign") || cvar("g_balance_teams") || cvar("g_balance_teams_force"))
2077 JoinBestTeam(self, FALSE, TRUE);
2078 if(cvar("g_campaign"))
2079 campaign_bots_may_start = 1;
2080 PutClientInServer();
2081 if(self.classname == "player")
2082 bprint ("^4", self.netname, "^4 is playing now\n");
2083 if(!cvar("g_campaign"))
2084 centerprint(self,""); // clear MOTD
2087 stuffcmd(self,"menu_showteamselect\n");
2092 //player may not join because of g_maxplayers is set
2093 centerprint_atprio(self, CENTERPRIO_MAPVOTE, PREVENT_JOIN_TEXT);
2098 * Determines whether the player is allowed to join. This depends on cvar
2099 * g_maxplayers, if it isn't used this function always return TRUE, otherwise
2100 * it checks whether the number of currently playing players exceeds g_maxplayers.
2101 * @return bool TRUE if the player is allowed to join, false otherwise
2103 float isJoinAllowed() {
2104 if (!cvar("g_maxplayers"))
2108 local float currentlyPlaying;
2109 FOR_EACH_REALPLAYER(e) {
2110 if(e.classname == "player")
2111 currentlyPlaying += 1;
2113 if(currentlyPlaying < cvar("g_maxplayers"))
2120 * Checks whether the client is an observer or spectator, if so, he will get kicked after
2121 * g_maxplayers_spectator_blocktime seconds
2123 void checkSpectatorBlock() {
2124 if(self.classname == "spectator" || self.classname == "observer") {
2125 if( time > (self.spectatortime + cvar("g_maxplayers_spectator_blocktime")) ) {
2126 sprint(self, "^7You were kicked from the server because you are spectator and spectators aren't allowed at the moment.\n");
2132 float vercmp_recursive(string v1, string v2)
2138 dot1 = strstrofs(v1, ".", 0);
2139 dot2 = strstrofs(v2, ".", 0);
2143 s1 = substring(v1, 0, dot1);
2147 s2 = substring(v2, 0, dot2);
2149 r = stof(s1) - stof(s2);
2153 r = strcasecmp(s1, s2);
2166 return vercmp_recursive(substring(v1, dot1 + 1, 999), substring(v2, dot2 + 1, 999));
2169 float vercmp(string v1, string v2)
2171 if(strcasecmp(v1, v2) == 0) // early out check
2173 return vercmp_recursive(v1, v2);
2176 void ObserverThink()
2178 if (self.flags & FL_JUMPRELEASED) {
2179 if (self.BUTTON_JUMP && !self.version_mismatch) {
2180 self.welcomemessage_time = 0;
2181 self.flags &~= FL_JUMPRELEASED;
2182 self.flags |= FL_SPAWNING;
2183 } else if(self.BUTTON_ATCK && !self.version_mismatch) {
2184 self.welcomemessage_time = 0;
2185 self.flags &~= FL_JUMPRELEASED;
2186 if(SpectateNext() == 1) {
2187 self.classname = "spectator";
2191 if (!(self.BUTTON_ATCK || self.BUTTON_JUMP)) {
2192 self.flags |= FL_JUMPRELEASED;
2193 if(self.flags & FL_SPAWNING)
2195 self.flags &~= FL_SPAWNING;
2196 LeaveSpectatorMode();
2201 PrintWelcomeMessage(self);
2204 void SpectatorThink()
2206 if (self.flags & FL_JUMPRELEASED) {
2207 if (self.BUTTON_JUMP && !self.version_mismatch) {
2208 self.welcomemessage_time = 0;
2209 self.flags &~= FL_JUMPRELEASED;
2210 self.flags |= FL_SPAWNING;
2211 } else if(self.BUTTON_ATCK) {
2212 self.welcomemessage_time = 0;
2213 self.flags &~= FL_JUMPRELEASED;
2214 if(SpectateNext() == 1) {
2215 self.classname = "spectator";
2217 self.classname = "observer";
2218 PutClientInServer();
2220 } else if (self.BUTTON_ATCK2) {
2221 self.welcomemessage_time = 0;
2222 self.flags &~= FL_JUMPRELEASED;
2223 self.classname = "observer";
2224 PutClientInServer();
2226 if(!SpectateUpdate())
2227 PutObserverInServer();
2230 if (!(self.BUTTON_ATCK || self.BUTTON_ATCK2)) {
2231 self.flags |= FL_JUMPRELEASED;
2232 if(self.flags & FL_SPAWNING)
2234 self.flags &~= FL_SPAWNING;
2235 LeaveSpectatorMode();
2240 PrintWelcomeMessage(self);
2241 self.flags |= FL_CLIENT | FL_NOTARGET;
2244 .float touchexplode_time;
2250 Called every frame for each client before the physics are run
2253 void() ctf_setstatus;
2254 void() nexball_setstatus;
2256 void PlayerPreThink (void)
2258 self.stat_game_starttime = game_starttime;
2259 self.stat_allow_oldnexbeam = cvar("g_allow_oldnexbeam");
2260 self.stat_leadlimit = cvar("leadlimit");
2262 if(blockSpectators && frametime)
2263 // WORKAROUND: only use dropclient in server frames (frametime set). Never use it in cl_movement frames (frametime zero).
2264 checkSpectatorBlock();
2268 if(self.netname_previous != self.netname)
2270 if(cvar("sv_eventlog"))
2271 GameLogEcho(strcat(":name:", ftos(self.playerid), ":", self.netname));
2272 if(self.netname_previous)
2273 strunzone(self.netname_previous);
2274 self.netname_previous = strzone(self.netname);
2278 if(self.version_nagtime)
2279 if(self.cvar_g_nexuizversion)
2280 if(time > self.version_nagtime)
2282 if(strstr(self.cvar_g_nexuizversion, "svn", 0) < 0)
2284 if(strstr(cvar_string("g_nexuizversion"), "svn", 0) >= 0)
2286 dprint("^1NOTE^7 to ", self.netname, "^7 - the server is running ^3Nexuiz ", cvar_string("g_nexuizversion"), " (beta)^7, you have ^3Nexuiz ", self.cvar_g_nexuizversion, "^1\n");
2287 sprint(self, strcat("\{1}^1NOTE: ^7the server is running ^3Nexuiz ", cvar_string("g_nexuizversion"), " (beta)^7, you have ^3Nexuiz ", self.cvar_g_nexuizversion, "^1\n"));
2292 r = vercmp(self.cvar_g_nexuizversion, cvar_string("g_nexuizversion"));
2295 dprint("^1NOTE^7 to ", self.netname, "^7 - ^3Nexuiz ", cvar_string("g_nexuizversion"), "^7 is out, and you still have ^3Nexuiz ", self.cvar_g_nexuizversion, "^1 - get the update from ^4http://www.nexuiz.com/^1!\n");
2296 sprint(self, strcat("\{1}^1NOTE: ^3Nexuiz ", cvar_string("g_nexuizversion"), "^7 is out, and you still have ^3Nexuiz ", self.cvar_g_nexuizversion, "^1 - get the update from ^4http://www.nexuiz.com/^1!\n"));
2300 dprint("^1NOTE^7 to ", self.netname, "^7 - the server is running ^3Nexuiz ", cvar_string("g_nexuizversion"), "^7, you have ^3Nexuiz ", self.cvar_g_nexuizversion, "^1\n");
2301 sprint(self, strcat("\{1}^1NOTE: ^7the server is running ^3Nexuiz ", cvar_string("g_nexuizversion"), "^7, you have ^3Nexuiz ", self.cvar_g_nexuizversion, "^1\n"));
2305 self.version_nagtime = 0;
2309 if(!(self.flags & FL_GODMODE)) if(self.max_armorvalue)
2311 sprint(self, strcat("godmode saved you ", ftos(self.max_armorvalue), " units of damage, cheater!\n"));
2312 self.max_armorvalue = 0;
2316 antilag_record(self);
2318 if(self.classname == "player") {
2319 // if(self.netname == "Wazat")
2320 // bprint(self.classname, "\n");
2322 CheckRules_Player();
2324 PrintWelcomeMessage(self);
2326 if (intermission_running)
2328 IntermissionThink (); // otherwise a button could be missed between
2329 return; // the think tics
2332 if(self.teleport_time)
2333 if(time > self.teleport_time)
2335 self.teleport_time = 0;
2336 self.effects = self.effects - (self.effects & EF_NODRAW);
2339 Nixnex_GiveCurrentWeapon();
2341 if(frametime > 0) // don't do this in cl_movement frames, just in server ticks
2342 UpdateSelectedPlayer();
2344 //don't allow the player to turn around while game is paused!
2345 if(timeoutStatus == 2) {
2346 self.v_angle = self.lastV_angle;
2347 self.angles = self.lastV_angle;
2348 self.fixangle = TRUE;
2354 if (self.deadflag != DEAD_NO)
2356 float button_pressed, force_respawn;
2359 button_pressed = (self.BUTTON_ATCK || self.BUTTON_JUMP || self.BUTTON_ATCK2 || self.BUTTON_HOOK || self.BUTTON_USE);
2360 force_respawn = (g_lms || cvar("g_forced_respawn"));
2361 if (self.deadflag == DEAD_DYING)
2364 self.deadflag = DEAD_RESPAWNING;
2365 else if(!button_pressed)
2366 self.deadflag = DEAD_DEAD;
2368 else if (self.deadflag == DEAD_DEAD)
2371 self.deadflag = DEAD_RESPAWNABLE;
2373 else if (self.deadflag == DEAD_RESPAWNABLE)
2376 self.deadflag = DEAD_RESPAWNING;
2378 else if (self.deadflag == DEAD_RESPAWNING)
2380 if(time > self.death_time)
2382 self.death_time = time + 1; // only retry once a second
2386 ShowRespawnCountdown();
2391 if(time > self.touchexplode_time)
2392 if(self.classname == "player")
2393 if(self.deadflag == DEAD_NO)
2394 if not(IS_INDEPENDENT_PLAYER(self))
2395 FOR_EACH_PLAYER(other) if(self != other)
2397 if(time > other.touchexplode_time)
2398 if(other.classname == "player")
2399 if(other.deadflag == DEAD_NO)
2400 if not(IS_INDEPENDENT_PLAYER(other))
2401 if(boxesoverlap(self.absmin, self.absmax, other.absmin, other.absmax))
2403 PlayerTouchExplode(self, other);
2404 self.touchexplode_time = other.touchexplode_time = time + 0.2;
2408 if(g_lms && !self.deadflag && cvar("g_lms_campcheck_interval"))
2412 // calculate player movement (in 2 dimensions only, so jumping on one spot doesn't count as movement)
2413 dist = self.prevorigin - self.origin;
2415 self.lms_traveled_distance += fabs(vlen(dist));
2417 if((cvar("g_campaign") && !campaign_bots_may_start) || (time < game_starttime))
2419 self.lms_nextcheck = time + cvar("g_lms_campcheck_interval")*2;
2420 self.lms_traveled_distance = 0;
2423 if(time > self.lms_nextcheck)
2425 //sprint(self, "distance: ", ftos(self.lms_traveled_distance), "\n");
2426 if(self.lms_traveled_distance < cvar("g_lms_campcheck_distance"))
2428 centerprint(self, cvar_string("g_lms_campcheck_message"));
2429 // FIXME KadaverJack: gibbing player here causes playermodel to bounce around, instead of eye.md3
2430 // I wasn't able to find out WHY that happens, so I put a workaround in place that shall prevent players from being gibbed :(
2431 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');
2433 self.lms_nextcheck = time + cvar("g_lms_campcheck_interval");
2434 self.lms_traveled_distance = 0;
2438 self.prevorigin = self.origin;
2440 if ((self.BUTTON_CROUCH && !self.hook.state) || self.health <= g_bloodloss)
2445 self.view_ofs = PL_CROUCH_VIEW_OFS;
2446 setsize (self, PL_CROUCH_MIN, PL_CROUCH_MAX);
2447 setanim(self, self.anim_duck, FALSE, TRUE, TRUE);
2454 tracebox(self.origin, PL_MIN, PL_MAX, self.origin, FALSE, self);
2455 if (!trace_startsolid)
2457 self.crouch = FALSE;
2458 self.view_ofs = PL_VIEW_OFS;
2459 setsize (self, PL_MIN, PL_MAX);
2464 if(self.health <= g_bloodloss && self.deadflag == DEAD_NO)
2466 if(self.bloodloss_timer < time)
2468 self.event_damage(self, self, 1, DEATH_ROT, self.origin, '0 0 0');
2469 self.bloodloss_timer = time + 0.5 + random() * 0.5;
2475 GrapplingHookFrame();
2479 self.items &~= self.items_added;
2483 self.items_added = 0;
2484 if(self.items & IT_JETPACK)
2485 if(self.items & IT_FUEL_REGEN || self.ammo_fuel >= 0.01)
2486 self.items_added |= IT_FUEL;
2488 self.items |= self.items_added;
2496 minstagib_ammocheck();
2500 nexball_setstatus();
2502 self.dmg_team = max(0, self.dmg_team - cvar("g_teamdamage_resetspeed") * frametime);
2504 //self.angles_y=self.v_angle_y + 90; // temp
2506 //if (TetrisPreFrame()) return;
2507 } else if(gameover) {
2508 if (intermission_running)
2509 IntermissionThink (); // otherwise a button could be missed between
2511 } else if(self.classname == "observer") {
2513 } else if(self.classname == "spectator") {
2518 SetZoomState(self.BUTTON_ZOOM || (self.BUTTON_ATCK2 && self.weapon == WEP_NEX));
2520 float oldspectatee_status;
2521 oldspectatee_status = self.spectatee_status;
2522 if(self.classname == "spectator")
2523 self.spectatee_status = num_for_edict(self.enemy);
2524 else if(self.classname == "observer")
2525 self.spectatee_status = num_for_edict(self);
2527 self.spectatee_status = 0;
2528 if(self.spectatee_status != oldspectatee_status)
2530 ClientData_Touch(self);
2532 race_InitSpectator();
2535 if(self.teamkill_soundtime)
2536 if(time > self.teamkill_soundtime)
2538 self.teamkill_soundtime = 0;
2540 entity oldpusher, oldself;
2542 oldself = self; self = self.teamkill_soundsource;
2543 oldpusher = self.pusher; self.pusher = oldself;
2545 PlayerSound(playersound_teamshoot, CHAN_VOICE, VOICETYPE_LASTATTACKER_ONLY);
2547 self.pusher = oldpusher;
2551 if(self.taunt_soundtime)
2552 if(time > self.taunt_soundtime)
2554 self.taunt_soundtime = 0;
2555 PlayerSound(playersound_taunt, CHAN_VOICE, VOICETYPE_AUTOTAUNT);
2558 target_voicescript_next(self);
2564 .float dragspeed; // speed of mouse wheel action
2565 .float dragdistance; // distance of dragentity's draglocalvector from view_ofs
2566 .vector draglocalvector; // local attachment vector of the dragentity
2567 .float draglocalangle;
2570 .float dragmovetype;
2571 void Drag_Begin(entity dragger, entity draggee, vector touchpoint)
2575 draggee.dragmovetype = draggee.movetype;
2576 draggee.draggravity = draggee.gravity;
2577 draggee.movetype = MOVETYPE_WALK;
2578 draggee.gravity = 0.00001;
2579 draggee.flags &~= FL_ONGROUND;
2580 draggee.draggedby = dragger;
2582 dragger.dragentity = draggee;
2584 dragger.dragdistance = vlen(touchpoint - dragger.origin - dragger.view_ofs);
2585 dragger.draglocalangle = draggee.angles_y - dragger.v_angle_y;
2586 touchpoint = touchpoint - gettaginfo(draggee, 0);
2587 tagscale = pow(vlen(v_forward), -2);
2588 dragger.draglocalvector_x = touchpoint * v_forward * tagscale;
2589 dragger.draglocalvector_y = touchpoint * v_right * tagscale;
2590 dragger.draglocalvector_z = touchpoint * v_up * tagscale;
2592 dragger.dragspeed = 64;
2595 void Drag_Finish(entity dragger)
2598 draggee = dragger.dragentity;
2600 dragger.dragentity = world;
2601 draggee.draggedby = world;
2602 draggee.movetype = draggee.dragmovetype;
2603 draggee.gravity = draggee.draggravity;
2605 switch(draggee.movetype)
2610 case MOVETYPE_FLYMISSILE:
2611 case MOVETYPE_BOUNCE:
2612 case MOVETYPE_BOUNCEMISSILE:
2615 draggee.velocity = '0 0 0';
2619 if((draggee.flags & FL_ITEM) && (vlen(draggee.velocity) < 32))
2621 draggee.velocity = '0 0 0';
2622 draggee.flags |= FL_ONGROUND; // floating items are FUN
2626 float Drag_IsDraggable(entity draggee)
2628 // TODO add more checks for bad stuff here
2629 if(draggee.classname == "func_bobbing")
2631 if(draggee.classname == "door") // FIXME find out why these must be excluded, or work around the problem (trying to drag these causes like 4 fps)
2633 if(draggee.classname == "plat")
2635 if(draggee.classname == "func_button")
2637 if(draggee.model == "")
2639 if(draggee.classname == "spectator")
2641 if(draggee.classname == "observer")
2643 if(draggee.classname == "exteriorweaponentity")
2649 float Drag_MayChangeAngles(entity draggee)
2651 // TODO add more checks for bad stuff here
2652 if(substring(draggee.model, 0, 1) == "*")
2657 void Drag_MoveForward(entity dragger)
2659 dragger.dragdistance += dragger.dragspeed;
2662 void Drag_SetSpeed(entity dragger, float s)
2664 dragger.dragspeed = pow(2, s);
2667 void Drag_MoveBackward(entity dragger)
2669 dragger.dragdistance = max(0, dragger.dragdistance - dragger.dragspeed);
2672 void Drag_Update(entity dragger)
2674 vector curorigin, neworigin, goodvelocity;
2678 draggee = dragger.dragentity;
2679 draggee.flags &~= FL_ONGROUND;
2681 curorigin = gettaginfo(draggee, 0);
2682 curorigin = curorigin + v_forward * dragger.draglocalvector_x + v_right * dragger.draglocalvector_y + v_up * dragger.draglocalvector_z;
2683 makevectors(dragger.v_angle);
2684 neworigin = dragger.origin + dragger.view_ofs + v_forward * dragger.dragdistance;
2685 goodvelocity = (neworigin - curorigin) * (1 / frametime);
2687 while(draggee.angles_y - dragger.v_angle_y - dragger.draglocalangle > 180)
2688 dragger.draglocalangle += 360;
2689 while(draggee.angles_y - dragger.v_angle_y - dragger.draglocalangle <= -180)
2690 dragger.draglocalangle -= 360;
2692 f = min(frametime * 10, 1);
2693 draggee.velocity = draggee.velocity * (1 - f) + goodvelocity * f;
2695 if(Drag_MayChangeAngles(draggee))
2696 draggee.angles_y = draggee.angles_y * (1 - f) + (dragger.v_angle_y + dragger.draglocalangle) * f;
2698 draggee.ltime = max(servertime + serverframetime, draggee.ltime); // fixes func_train breakage
2700 te_lightning1(dragger, dragger.origin + dragger.view_ofs, curorigin);
2703 float Drag_CanDrag(entity dragger)
2705 return (dragger.deadflag == DEAD_NO) || (dragger.classname == "player");
2708 float Drag_IsDragging(entity dragger)
2710 if(!dragger.dragentity)
2712 if(wasfreed(dragger.dragentity) || dragger.dragentity.draggedby != dragger)
2714 dragger.dragentity = world;
2717 if(!Drag_CanDrag(dragger) || !Drag_IsDraggable(dragger.dragentity))
2719 Drag_Finish(dragger);
2725 void Drag_MoveDrag(entity from, entity to)
2729 to.draggedby = from.draggedby;
2730 to.draggedby.dragentity = to;
2731 from.draggedby = world;
2739 Called every frame for each client after the physics are run
2742 .float idlekick_lasttimeleft;
2743 .float race_penalty;
2744 .float race_penalty_nagged;
2745 .float race_penalty_nagtime;
2746 void PlayerPostThink (void)
2748 // Savage: Check for nameless players
2749 if (strlen(self.netname) < 1) {
2750 self.netname = "Player";
2751 stuffcmd(self, "seta _cl_name Player\n");
2754 if(sv_maxidle && frametime)
2756 // WORKAROUND: only use dropclient in server frames (frametime set). Never use it in cl_movement frames (frametime zero).
2758 timeleft = ceil(sv_maxidle - (time - self.parm_idlesince));
2761 bprint("^3", self.netname, "^3 was kicked for idling.\n");
2762 announce(self, "announcer/robotic/terminated.wav");
2766 else if(timeleft <= 10)
2768 if(timeleft != self.idlekick_lasttimeleft)
2770 centerprint_atprio(self, CENTERPRIO_IDLEKICK, strcat("^3Stop idling!\n^3Disconnecting in ", ftos(timeleft), "..."));
2771 announce(self, strcat("announcer/robotic/", ftos(timeleft), ".wav"));
2776 centerprint_expire(self, CENTERPRIO_IDLEKICK);
2778 self.idlekick_lasttimeleft = timeleft;
2781 if(sv_cheats || self.maycheat)
2782 if(Drag_CanDrag(self))
2783 if(self.BUTTON_DRAG)
2784 if(!self.dragentity)
2785 if(self.cursor_trace_ent)
2786 if(Drag_IsDraggable(self.cursor_trace_ent))
2788 if(self.cursor_trace_ent.draggedby)
2789 Drag_Finish(self.cursor_trace_ent.draggedby);
2790 if(self.cursor_trace_ent.tag_entity)
2791 detach_sameorigin(self.cursor_trace_ent);
2792 Drag_Begin(self, self.cursor_trace_ent, self.cursor_trace_endpos);
2795 if(Drag_IsDragging(self))
2797 if(self.BUTTON_DRAG)
2799 if(self.impulse == 10 || self.impulse == 15 || self.impulse == 18)
2801 Drag_MoveForward(self);
2804 else if(self.impulse == 12 || self.impulse == 16 || self.impulse == 19)
2806 Drag_MoveBackward(self);
2809 else if(self.impulse >= 1 && self.impulse <= 9)
2811 Drag_SetSpeed(self, self.impulse - 1);
2813 else if(self.impulse == 14)
2815 Drag_SetSpeed(self, 9);
2827 if(self.classname == "player") {
2828 CheckRules_Player();
2833 if (intermission_running)
2834 return; // intermission or finale
2836 //if (TetrisPostFrame()) return;
2838 // restart countdown
2839 if(time < game_starttime) {
2840 if (!cvar("sv_ready_restart_after_countdown"))
2842 if(self.movement != '0 0 0' && g_race && !g_race_qualifying)
2844 if(time < game_starttime - 2)
2846 if(!self.race_penalty_nagged)
2848 // TODO better notification for this!
2849 self.race_penalty_nagtime = 0;
2850 self.race_penalty_nagged = 1;
2853 else if(!self.race_penalty)
2855 self.race_penalty_nagtime = 0;
2856 self.race_penalty = time + 5;
2859 if(time > self.race_penalty_nagtime)
2861 if(self.race_penalty > time)
2863 centerprint_atprio(self, CENTERPRIO_IDLEKICK, "^1FIVE SECONDS PENALTY.");
2865 else if(self.race_penalty_nagged && time < game_starttime - 2)
2867 centerprint_atprio(self, CENTERPRIO_IDLEKICK, "^1DO NOT MOVE DURING THE COUNTDOWN.");
2869 self.race_penalty_nagtime = time + self.cvar_scr_centertime * 0.6;
2871 self.movetype = MOVETYPE_NONE;
2872 self.velocity = '0 0 0';
2873 self.avelocity = '0 0 0';
2874 self.movement = '0 0 0';
2877 else if (time < self.race_penalty)
2879 self.movetype = MOVETYPE_NONE;
2880 self.velocity = '0 0 0';
2881 self.avelocity = '0 0 0';
2882 self.movement = '0 0 0';
2886 //allow the player to move again if sv_ready_restart_after_countdown is not used and countdown is over
2887 if (!cvar("sv_ready_restart_after_countdown"))
2889 if(self.movetype == MOVETYPE_NONE)
2891 self.movetype = MOVETYPE_WALK;
2893 self.race_penalty = 0;
2894 self.race_penalty_nagged = 0;
2898 } else if (self.classname == "observer") {
2900 } else if (self.classname == "spectator") {
2906 for(i = 0; i < 1000; ++i)
2909 end = self.origin + '0 0 1024' + 512 * randomvec();
2910 tracebox(self.origin, self.mins, self.maxs, end, MOVE_NORMAL, self);
2911 if(trace_fraction < 1)
2912 if(!(trace_dphitq3surfaceflags & Q3SURFACEFLAG_NOIMPACT))
2914 print("I HIT SOLID: ", vtos(self.origin), " -> ", vtos(end), "\n");
2922 //pointparticles(particleeffectnum("machinegun_impact"), self.origin + self.view_ofs + '0 0 7', '0 0 0', 1);
2924 if(self.waypointsprite_attachedforcarrier)
2925 WaypointSprite_UpdateHealth(self.waypointsprite_attachedforcarrier, '1 0 0' * healtharmor_maxdamage(self.health, self.armorvalue, cvar("g_balance_armor_blockpercent")));