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 if(self.modelindex == 0) // no need to uncustomize then
401 self.modelindex = self.modelindex_lod0;
402 self.skin = self.skinindex;
405 float Client_customizeentityforclient()
409 if(self.modelindex == 0)
416 t0 = gettime(GETTIME_HIRES); // reference
420 if(other.cvar_cl_forceplayermodelsfromnexuiz)
421 if not(self.modelindex_lod0_from_nexuiz)
423 if(other.cvar_cl_forceplayermodels && sv_clforceplayermodels)
425 self.skin = modelsource.skinindex;
428 if(modelsource == self)
429 self.skin = modelsource.skinindex;
431 self.skin = mod(modelsource.skinindex, 3); // forbid the fbskins as forced skins
435 // other: the player viewing me
439 if(other.cvar_cl_playerdetailreduction <= 0)
441 if(other.cvar_cl_playerdetailreduction <= -2)
442 self.modelindex = modelsource.modelindex_lod2;
443 else if(other.cvar_cl_playerdetailreduction <= -1)
444 self.modelindex = modelsource.modelindex_lod1;
446 self.modelindex = modelsource.modelindex_lod0;
450 distance = vlen(self.origin - other.origin);
451 f = (distance + 100.0) * other.cvar_cl_playerdetailreduction;
452 if(f > sv_loddistance2)
453 self.modelindex = modelsource.modelindex_lod2;
454 else if(f > sv_loddistance1)
455 self.modelindex = modelsource.modelindex_lod1;
457 self.modelindex = modelsource.modelindex_lod0;
462 t1 = gettime(GETTIME_HIRES); // reference
463 client_cefc_accumulator += (t1 - t0);
469 void UpdatePlayerSounds();
470 void setmodel_lod(entity e, string modelname)
476 // FIXME: this only supports 3-letter extensions
477 s = strcat(substring(modelname, 0, strlen(modelname)-4), "_lod1", substring(modelname, -4, 4));
480 setmodel(e, s); // players have high precision
481 self.modelindex_lod1 = self.modelindex;
484 self.modelindex_lod1 = -1;
486 s = strcat(substring(modelname, 0, strlen(modelname)-4), "_lod2", substring(modelname, -4, 4));
489 setmodel(e, s); // players have high precision
490 self.modelindex_lod2 = self.modelindex;
493 self.modelindex_lod2 = -1;
495 precache_model(modelname);
496 setmodel(e, modelname); // players have high precision
497 self.modelindex_lod0 = self.modelindex;
499 if(self.modelindex_lod1 < 0)
500 self.modelindex_lod1 = self.modelindex;
502 if(self.modelindex_lod2 < 0)
503 self.modelindex_lod2 = self.modelindex;
507 precache_model(modelname);
508 setmodel(e, modelname); // players have high precision
509 self.modelindex_lod0 = self.modelindex;
510 // save it for possible player model forcing
513 s = whichpack(self.model);
514 self.modelindex_lod0_from_nexuiz = ((s == "") || (substring(s, 0, 4) == "data"));
516 player_setupanimsformodel();
517 UpdatePlayerSounds();
524 putting a client as observer in the server
527 void PutObserverInServer (void)
531 race_PreSpawnObserver();
533 spot = SelectSpawnPoint (TRUE);
535 error("No spawnpoints for observers?!?\n");
536 RemoveGrapplingHook(self); // Wazat's Grappling Hook
538 if(clienttype(self) == CLIENTTYPE_REAL)
541 WriteByte(MSG_ONE, SVC_SETVIEW);
542 WriteEntity(MSG_ONE, self);
546 kh_Key_DropAll(self, TRUE);
548 Portal_ClearAll(self);
551 DropFlag(self.flagcarried, world, world);
553 DropBall(self.ballcarried, self.origin + self.ballcarried.origin, self.velocity);
555 WaypointSprite_PlayerDead();
557 if(self.killcount != -666)
561 if(PlayerScore_Add(self, SP_LMS_RANK, 0) > 0)
562 bprint ("^4", self.netname, "^4 has no more lives left\n");
564 bprint ("^4", self.netname, "^4 is spectating now\n"); // TODO turn this into a proper forfeit?
567 bprint ("^4", self.netname, "^4 is spectating now\n");
570 PlayerScore_Clear(self); // clear scores when needed
572 self.spectatortime = time;
574 self.classname = "observer";
575 self.iscreature = FALSE;
577 self.takedamage = DAMAGE_NO;
578 self.solid = SOLID_NOT;
579 self.movetype = MOVETYPE_NOCLIP;
580 self.flags = FL_CLIENT | FL_NOTARGET;
581 self.armorvalue = 666;
583 self.armorvalue = cvar("g_balance_armor_start");
584 self.pauserotarmor_finished = 0;
585 self.pauserothealth_finished = 0;
586 self.pauseregen_finished = 0;
587 self.damageforcescale = 0;
594 self.pain_finished = 0;
595 self.strength_finished = 0;
596 self.invincible_finished = 0;
597 self.damage_hits = 0;
598 self.maxdamage_fired = 0;
600 self.think = SUB_Null;
604 self.deadflag = DEAD_NO;
605 self.angles = spot.angles;
607 self.fixangle = TRUE;
610 self.view_ofs = PL_VIEW_OFS;
611 setorigin (self, spot.origin);
612 setsize (self, '0 0 0', '0 0 0');
613 self.prevorigin = self.origin;
619 self.weaponmodel = "";
620 self.weaponentity = world;
621 self.exteriorweaponentity = world;
622 self.killcount = -666;
623 self.velocity = '0 0 0';
624 self.avelocity = '0 0 0';
625 self.punchangle = '0 0 0';
626 self.punchvector = '0 0 0';
627 self.oldvelocity = self.velocity;
630 SetCustomizer(self, Client_customizeentityforclient, Client_uncustomizeentityforclient);
636 if(self.version_mismatch)
638 Spawnqueue_Unmark(self);
639 Spawnqueue_Remove(self);
643 Spawnqueue_Insert(self);
648 // Only if the player cannot play at all
649 if(PlayerScore_Add(self, SP_LMS_RANK, 0) == 666)
650 self.frags = FRAGS_SPECTATOR;
652 self.frags = FRAGS_LMS_LOSER;
655 self.frags = FRAGS_SPECTATOR;
658 float RestrictSkin(float s)
667 void FixPlayermodel()
669 local string defaultmodel;
670 local float defaultskin, chmdl, oldskin;
675 if(cvar("sv_defaultcharacter") == 1) {
680 defaultmodel = cvar_string(strcat("sv_defaultplayermodel_", Team_ColorNameLowerCase(self.team)));
681 defaultskin = cvar(strcat("sv_defaultplayerskin_", Team_ColorNameLowerCase(self.team)));
684 if(defaultmodel == "")
686 defaultmodel = cvar_string("sv_defaultplayermodel");
687 defaultskin = cvar("sv_defaultplayerskin");
691 if(self.modelindex == 0 && self.deadflag == DEAD_NO)
694 bprint("\{1}^1Player ", self.netname, "^1 has a zero modelindex, trying to fix...\n");
695 self.model = ""; // force the != checks to return true
698 if(defaultmodel != "")
700 if (defaultmodel != self.model)
704 setmodel_lod (self, defaultmodel);
705 setsize (self, m1, m2);
709 oldskin = self.skinindex;
710 self.skinindex = defaultskin;
712 if (self.playermodel != self.model)
714 self.playermodel = CheckPlayerModel(self.playermodel);
717 setmodel_lod (self, self.playermodel);
718 setsize (self, m1, m2);
722 oldskin = self.skinindex;
723 self.skinindex = RestrictSkin(stof(self.playerskin));
726 if(chmdl || oldskin != self.skinindex)
727 self.species = player_getspecies(); // model or skin has changed
730 if(strlen(cvar_string("sv_defaultplayercolors")))
731 if(self.clientcolors != cvar("sv_defaultplayercolors"))
732 setcolor(self, cvar("sv_defaultplayercolors"));
735 void PlayerTouchExplode(entity p1, entity p2)
738 org = (p1.origin + p2.origin) * 0.5;
739 org_z += (p1.mins_z + p2.mins_z) * 0.5;
746 RadiusDamage(e, world, g_touchexplode_damage, g_touchexplode_edgedamage, g_touchexplode_radius, world, g_touchexplode_force, DEATH_TOUCHEXPLODE, world);
754 Called when a client spawns in the server
757 //void() ctf_playerchanged;
758 void PutClientInServer (void)
760 if(clienttype(self) == CLIENTTYPE_BOT)
762 self.classname = "player";
764 else if(clienttype(self) == CLIENTTYPE_REAL)
767 WriteByte(MSG_ONE, SVC_SETVIEW);
768 WriteEntity(MSG_ONE, self);
771 // player is dead and becomes observer
772 // FIXME fix LMS scoring for new system
775 if(PlayerScore_Add(self, SP_LMS_RANK, 0) > 0)
776 self.classname = "observer";
781 self.classname = "observer";
783 if(self.classname == "player") {
784 entity spot, oldself;
787 JoinBestTeam(self, FALSE, TRUE);
791 spot = SelectSpawnPoint (FALSE);
794 centerprint(self, "Sorry, no spawnpoints available!\nHope your team can fix it...");
795 return; // spawn failed
798 RemoveGrapplingHook(self); // Wazat's Grappling Hook
799 self.campingrifle_bulletcounter = 0;
801 self.classname = "player";
802 self.wasplayer = TRUE;
803 self.iscreature = TRUE;
804 self.movetype = MOVETYPE_WALK;
805 self.solid = SOLID_SLIDEBOX;
806 self.dphitcontentsmask = DPCONTENTS_SOLID | DPCONTENTS_BODY | DPCONTENTS_PLAYERCLIP;
807 self.frags = FRAGS_PLAYER;
808 if(independent_players)
809 MAKE_INDEPENDENT_PLAYER(self);
810 self.flags = FL_CLIENT;
811 self.takedamage = DAMAGE_AIM;
813 self.effects = EF_FULLBRIGHT;
816 self.air_finished = time + 12;
821 self.ammo_shells = warmup_start_ammo_shells;
822 self.ammo_nails = warmup_start_ammo_nails;
823 self.ammo_rockets = warmup_start_ammo_rockets;
824 self.ammo_cells = warmup_start_ammo_cells;
825 self.ammo_fuel = warmup_start_ammo_fuel;
826 self.health = warmup_start_health;
827 self.armorvalue = warmup_start_armorvalue;
828 self.weapons = warmup_start_weapons;
832 self.ammo_shells = start_ammo_shells;
833 self.ammo_nails = start_ammo_nails;
834 self.ammo_rockets = start_ammo_rockets;
835 self.ammo_cells = start_ammo_cells;
836 self.ammo_fuel = start_ammo_fuel;
837 self.health = start_health;
838 self.armorvalue = start_armorvalue;
839 self.weapons = start_weapons;
841 self.items = start_items;
842 self.switchweapon = w_getbestweapon(self);
843 self.cnt = self.switchweapon;
845 self.jump_interval = time;
847 self.spawnshieldtime = time + cvar("g_spawnshieldtime");
848 self.pauserotarmor_finished = time + cvar("g_balance_pause_armor_rot_spawn");
849 self.pauserothealth_finished = time + cvar("g_balance_pause_health_rot_spawn");
850 self.pauserotfuel_finished = time + cvar("g_balance_pause_fuel_rot_spawn");
851 self.pauseregen_finished = time + cvar("g_balance_pause_health_regen_spawn");
852 //extend the pause of rotting if client was reset at the beginning of the countdown
853 if(!cvar("sv_ready_restart_after_countdown") && time < game_starttime) { // TODO why is this cvar NOTted?
854 self.spawnshieldtime += game_starttime - time;
855 self.pauserotarmor_finished += game_starttime - time;
856 self.pauserothealth_finished += game_starttime - time;
857 self.pauseregen_finished += game_starttime - time;
859 self.damageforcescale = 2;
866 self.pain_finished = 0;
867 self.strength_finished = 0;
868 self.invincible_finished = 0;
869 self.maxdamage_fired = 0;
870 self.damage_hits = 0;
872 //self.speed_finished = 0;
873 //self.slowmo_finished = 0;
874 // players have no think function
875 self.think = SUB_Null;
884 self.deadflag = DEAD_NO;
886 self.angles = spot.angles;
888 self.angles_z = 0; // never spawn tilted even if the spot says to
889 self.fixangle = TRUE; // turn this way immediately
890 self.velocity = '0 0 0';
891 self.avelocity = '0 0 0';
892 self.punchangle = '0 0 0';
893 self.punchvector = '0 0 0';
894 self.oldvelocity = self.velocity;
897 WRITESPECTATABLE_MSG_ONE({
898 WriteByte(MSG_ONE, SVC_TEMPENTITY);
899 WriteByte(MSG_ONE, TE_CSQC_SPAWN);
903 SetCustomizer(self, Client_customizeentityforclient, Client_uncustomizeentityforclient);
909 self.view_ofs = PL_VIEW_OFS;
910 setsize (self, PL_MIN, PL_MAX);
911 self.spawnorigin = spot.origin;
912 setorigin (self, spot.origin + '0 0 1' * (1 - self.mins_z - 24));
913 // don't reset back to last position, even if new position is stuck in solid
914 self.oldorigin = self.origin;
915 self.prevorigin = self.origin;
916 self.lastrocket = world; // stop rocket guiding, no revenge from the grave!
920 Spawnqueue_Remove(self);
921 Spawnqueue_Mark(self);
924 self.event_damage = PlayerDamage;
926 self.bot_attack = TRUE;
928 self.statdraintime = time + 5;
929 self.BUTTON_ATCK = self.BUTTON_JUMP = self.BUTTON_ATCK2 = 0;
931 if(self.killcount == -666) {
932 PlayerScore_Clear(self);
936 self.cnt = WEP_LASER;
937 self.nixnex_lastchange_id = -1;
939 CL_SpawnWeaponentity();
940 self.alpha = default_player_alpha;
941 self.colormod = '1 1 1' * cvar("g_player_brightness");
942 self.exteriorweaponentity.alpha = default_weapon_alpha;
944 self.lms_nextcheck = time + cvar("g_lms_campcheck_interval")*2;
945 self.lms_traveled_distance = 0;
946 self.speedrunning = FALSE;
948 race_PostSpawn(spot);
950 if(cvar("spawn_debug"))
952 sprint(self, strcat("spawnpoint origin: ", vtos(spot.origin), "\n"));
953 remove(spot); // usefull for checking if there are spawnpoints, that let drop through the floor
956 //stuffcmd(self, "chase_active 0");
957 //stuffcmd(self, "set viewsize $tmpviewsize \n");
959 if (cvar("g_spawnsound"))
960 sound (self, CHAN_TRIGGER, "misc/spawn.wav", VOL_BASE, ATTN_NORM);
963 if(self.team == assault_attacker_team)
964 centerprint(self, "You are attacking!");
966 centerprint(self, "You are defending!");
969 target_voicescript_clear(self);
978 } else if(self.classname == "observer") {
979 PutObserverInServer ();
983 // ctf_playerchanged();
986 float ClientInit_SendEntity(entity to, float sf)
989 WriteByte(MSG_ENTITY, ENT_CLIENT_INIT);
990 WriteByte(MSG_ENTITY, g_nexball_meter_period * 32);
991 for(i = 1; i <= 24; ++i)
992 WriteByte(MSG_ENTITY, (get_weaponinfo(i)).impulse + 1);
993 WriteCoord(MSG_ENTITY, hook_shotorigin_x);
994 WriteCoord(MSG_ENTITY, hook_shotorigin_y);
995 WriteCoord(MSG_ENTITY, hook_shotorigin_z);
997 if(sv_foginterval && world.fog != "")
998 WriteString(MSG_ENTITY, world.fog);
1000 WriteString(MSG_ENTITY, "");
1001 WriteByte(MSG_ENTITY, cvar("g_balance_armor_blockpercent") * 255.0);
1005 void ClientInit_Spawn()
1007 Net_LinkEntity(spawn(), FALSE, 0, ClientInit_SendEntity);
1015 void SetNewParms (void)
1017 // initialize parms for a new player
1018 parm1 = -(86400 * 366);
1026 void SetChangeParms (void)
1028 // save parms for level change
1029 parm1 = self.parm_idlesince - time;
1037 void DecodeLevelParms (void)
1040 self.parm_idlesince = parm1;
1041 if(self.parm_idlesince == -(86400 * 366))
1042 self.parm_idlesince = time;
1044 // whatever happens, allow 60 seconds of idling directly after connect for map loading
1045 self.parm_idlesince = max(self.parm_idlesince, time - sv_maxidle + 60);
1052 Called when a client types 'kill' in the console
1056 void ClientKill_Now_TeamChange()
1058 if(self.killindicator_teamchange == -1)
1061 JoinBestTeam( self, FALSE, FALSE );
1064 SV_ChangeTeam(self.killindicator_teamchange - 1);
1067 void ClientKill_Now()
1069 if(self.killindicator_teamchange)
1070 ClientKill_Now_TeamChange();
1073 Damage(self, self, self, 100000, DEATH_KILL, self.origin, '0 0 0');
1075 if(self.killindicator)
1077 dprint("Cleaned up after a leaked kill indicator.\n");
1078 remove(self.killindicator);
1079 self.killindicator = world;
1082 void KillIndicator_Think()
1084 if (!self.owner.modelindex)
1086 self.owner.killindicator = world;
1094 ClientKill_Now(); // no oldself needed
1100 setmodel(self, strcat("models/sprites/", ftos(self.cnt), ".spr32"));
1101 if(clienttype(self.owner) == CLIENTTYPE_REAL)
1104 announce(self.owner, strcat("announcer/robotic/", ftos(self.cnt), ".wav"));
1105 if(self.owner.killindicator_teamchange)
1107 if(self.owner.killindicator_teamchange == -1)
1108 centerprint(self.owner, strcat("Changing team in ", ftos(self.cnt), " seconds"));
1110 centerprint(self.owner, strcat("Changing to ", ColoredTeamName(self.owner.killindicator_teamchange), " in ", ftos(self.cnt), " seconds"));
1113 centerprint(self.owner, strcat("^1Suicide in ", ftos(self.cnt), " seconds"));
1115 self.nextthink = time + 1;
1120 void ClientKill_TeamChange (float targetteam) // 0 = don't change, -1 = auto
1124 killtime = cvar("g_balance_kill_delay");
1126 self.killindicator_teamchange = targetteam;
1128 if(!self.killindicator)
1130 if(killtime <= 0 || !self.modelindex || self.deadflag != DEAD_NO)
1136 self.killindicator = spawn();
1137 self.killindicator.owner = self;
1138 self.killindicator.scale = 0.5;
1139 setattachment(self.killindicator, self, "");
1140 setorigin(self.killindicator, '0 0 52');
1141 self.killindicator.think = KillIndicator_Think;
1142 self.killindicator.nextthink = time + (self.lip) * 0.05;
1143 self.killindicator.cnt = ceil(killtime);
1144 self.killindicator.count = bound(0, ceil(killtime), 10);
1145 sprint(self, strcat("^1You'll be dead in ", ftos(self.killindicator.cnt), " seconds\n"));
1147 for(e = world; (e = find(e, classname, "body")) != world; )
1151 e.killindicator = spawn();
1152 e.killindicator.owner = e;
1153 e.killindicator.scale = 0.5;
1154 setattachment(e.killindicator, e, "");
1155 setorigin(e.killindicator, '0 0 52');
1156 e.killindicator.think = KillIndicator_Think;
1157 e.killindicator.nextthink = time + (e.lip) * 0.05;
1158 e.killindicator.cnt = ceil(killtime);
1163 if(self.killindicator)
1166 self.killindicator.colormod = TeamColor(targetteam);
1168 self.killindicator.colormod = '0 0 0';
1172 void ClientKill (void)
1174 ClientKill_TeamChange(0);
1177 void DoTeamChange(float destteam)
1183 SetPlayerColors(self, destteam);
1186 if(self.classname == "player")
1189 CheckAllowedTeams(self);
1190 t = FindSmallestTeam(self, TRUE);
1193 case COLOR_TEAM1: c0 = c1; break;
1194 case COLOR_TEAM2: c0 = c2; break;
1195 case COLOR_TEAM3: c0 = c3; break;
1196 case COLOR_TEAM4: c0 = c4; break;
1203 destteam = COLOR_TEAM1;
1207 destteam = COLOR_TEAM2;
1211 destteam = COLOR_TEAM3;
1215 destteam = COLOR_TEAM4;
1221 if(destteam == self.team && destteam >= 0 && !self.killindicator)
1223 ClientKill_TeamChange(destteam);
1226 void FixClientCvars(entity e)
1228 // send prediction settings to the client
1229 stuffcmd(e, "\nin_bindmap 0 0\n");
1231 * we no longer need to stuff this. Remove this comment block if you feel
1232 * 2.3 and higher (or was it 2.2.3?) don't need these any more
1233 stuffcmd(e, strcat("cl_gravity ", ftos(cvar("sv_gravity")), "\n"));
1234 stuffcmd(e, strcat("cl_movement_accelerate ", ftos(cvar("sv_accelerate")), "\n"));
1235 stuffcmd(e, strcat("cl_movement_friction ", ftos(cvar("sv_friction")), "\n"));
1236 stuffcmd(e, strcat("cl_movement_maxspeed ", ftos(cvar("sv_maxspeed")), "\n"));
1237 stuffcmd(e, strcat("cl_movement_airaccelerate ", ftos(cvar("sv_airaccelerate")), "\n"));
1238 stuffcmd(e, strcat("cl_movement_maxairspeed ", ftos(cvar("sv_maxairspeed")), "\n"));
1239 stuffcmd(e, strcat("cl_movement_stopspeed ", ftos(cvar("sv_stopspeed")), "\n"));
1240 stuffcmd(e, strcat("cl_movement_jumpvelocity ", ftos(cvar("sv_jumpvelocity")), "\n"));
1241 stuffcmd(e, strcat("cl_movement_stepheight ", ftos(cvar("sv_stepheight")), "\n"));
1242 stuffcmd(e, strcat("set cl_movement_friction_on_land ", ftos(cvar("sv_friction_on_land")), "\n"));
1243 stuffcmd(e, strcat("set cl_movement_airaccel_qw ", ftos(cvar("sv_airaccel_qw")), "\n"));
1244 stuffcmd(e, strcat("set cl_movement_airaccel_sideways_friction ", ftos(cvar("sv_airaccel_sideways_friction")), "\n"));
1245 stuffcmd(e, "cl_movement_edgefriction 1\n");
1253 Called when a client connects to the server
1256 //void ctf_clientconnect();
1257 string ColoredTeamName(float t);
1258 void DecodeLevelParms (void);
1259 //void dom_player_join_team(entity pl);
1260 void ClientConnect (void)
1265 if(self.flags & FL_CLIENT)
1267 print("Warning: ClientConnect, but already connected!\n");
1271 if(Ban_MaybeEnforceBan(self))
1276 self.classname = "player_joining";
1278 self.flags = FL_CLIENT;
1279 self.version_nagtime = time + 10 + random() * 10;
1283 dprint("BUG player count is lower than zero, this cannot happen!\n");
1287 PlayerScore_Attach(self);
1288 ClientData_Attach();
1290 bot_clientconnect();
1292 race_PreSpawnObserver();
1295 // dom_player_join_team(self);
1297 JoinBestTeam(self, FALSE, FALSE); // if the team number is valid, keep it
1299 if((cvar("sv_spectate") == 1 && !g_lms) || cvar("g_campaign")) {
1300 self.classname = "observer";
1304 if(cvar("g_balance_teams") || cvar("g_balance_teams_force"))
1306 self.classname = "player";
1307 campaign_bots_may_start = 1;
1311 self.classname = "observer"; // do it anyway
1316 self.classname = "player";
1317 campaign_bots_may_start = 1;
1321 self.playerid = (playerid_last = playerid_last + 1);
1322 if(cvar("sv_eventlog"))
1324 if(clienttype(self) == CLIENTTYPE_REAL)
1325 GameLogEcho(strcat(":join:", ftos(self.playerid), ":", ftos(num_for_edict(self)), ":", self.netaddress, ":", self.netname));
1327 GameLogEcho(strcat(":join:", ftos(self.playerid), ":", ftos(num_for_edict(self)), ":bot:", self.netname));
1328 s = strcat(":team:", ftos(self.playerid), ":");
1329 s = strcat(s, ftos(self.team));
1332 self.netname_previous = strzone(self.netname);
1334 //stuffcmd(self, "set tmpviewsize $viewsize \n");
1336 bprint ("^4",self.netname);
1337 bprint ("^4 connected");
1339 if(g_domination || g_ctf)
1341 bprint(" and joined the ");
1342 bprint(ColoredTeamName(self.team));
1347 self.welcomemessage_time = 0;
1349 stuffcmd(self, strcat(clientstuff, "\n"));
1350 stuffcmd(self, strcat("exec maps/", mapname, ".cfg\n"));
1351 stuffcmd(self, "cl_particles_reloadeffects\n");
1353 FixClientCvars(self);
1355 // spawnfunc_waypoint sprites
1356 WaypointSprite_InitClient(self);
1358 // Wazat's grappling hook
1359 SetGrappleHookBindings();
1361 // get autoswitch state from player when he toggles it
1362 stuffcmd(self, "alias autoswitch \"set cl_autoswitch $1 ; cmd autoswitch $1\"\n"); // default.cfg-ed in 2.4.1
1364 // get version info from player
1365 stuffcmd(self, "cmd clientversion $gameversion\n");
1367 // get other cvars from player
1370 // set cvar for team scoreboard
1371 stuffcmd(self, strcat("set teamplay ", ftos(teamplay), "\n"));
1373 // notify about available teams
1376 CheckAllowedTeams(self);
1377 t = 0; if(c1 >= 0) t |= 1; if(c2 >= 0) t |= 2; if(c3 >= 0) t |= 4; if(c4 >= 0) t |= 8;
1378 stuffcmd(self, strcat("set _teams_available ", ftos(t), "\n"));
1381 stuffcmd(self, "set _teams_available 0\n");
1383 stuffcmd(self, strcat("set gametype ", ftos(game), "\n"));
1387 self.classname = "observer";
1388 Spawnqueue_Insert(self);
1392 ctf_clientconnect();
1395 if(teams_matter || sv_cheats)
1398 bot_relinkplayerlist();
1400 self.spectatortime = time;
1403 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"));
1406 self.jointime = time;
1407 self.allowedTimeouts = cvar("sv_timeout_number");
1409 if(clienttype(self) == CLIENTTYPE_REAL)
1411 if(cvar("g_bugrigs") || g_weaponarena == WEPBIT_TUBA)
1412 stuffcmd(self, "cl_cmd settemp chase_active 1\n");
1417 if(PlayerScore_Add(self, SP_LMS_LIVES, LMS_NewPlayerLives()) <= 0)
1419 PlayerScore_Add(self, SP_LMS_RANK, 666);
1420 self.frags = FRAGS_SPECTATOR;
1424 if(!sv_foginterval && world.fog != "")
1425 stuffcmd(self, strcat("\nfog ", world.fog, "\nr_fog_exp2 0\nr_drawfog 1\n"));
1427 SoundEntity_Attach(self);
1429 if(cvar("g_hitplots"))
1431 self.hitplotfh = fopen(strcat("hits-", matchid, "-", ftos(self.playerid), ".plot"), FILE_WRITE);
1432 fputs(self.hitplotfh, strcat("#name ", self.netname, "\n"));
1435 self.hitplotfh = -1;
1442 Called when a client disconnects from the server
1445 .entity chatbubbleentity;
1446 .entity teambubbleentity;
1448 void ClientDisconnect (void)
1450 if not(self.flags & FL_CLIENT)
1452 print("Warning: ClientDisconnect without ClientConnect\n");
1456 if(self.hitplotfh >= 0)
1458 fclose(self.hitplotfh);
1459 self.hitplotfh = -1;
1462 bot_clientdisconnect();
1467 if(cvar("sv_eventlog"))
1468 GameLogEcho(strcat(":part:", ftos(self.playerid)));
1469 bprint ("^4",self.netname);
1470 bprint ("^4 disconnected\n");
1472 SoundEntity_Detach(self);
1475 kh_Key_DropAll(self, TRUE);
1477 Portal_ClearAll(self);
1479 if(self.flagcarried)
1480 DropFlag(self.flagcarried, world, world);
1481 if(self.ballcarried)
1482 DropBall(self.ballcarried, self.origin + self.ballcarried.origin, self.velocity);
1484 // Here, everything has been done that requires this player to be a client.
1486 self.flags &~= FL_CLIENT;
1488 if (self.chatbubbleentity)
1489 remove (self.chatbubbleentity);
1491 if (self.teambubbleentity)
1492 remove (self.teambubbleentity);
1494 if (self.killindicator)
1495 remove (self.killindicator);
1497 WaypointSprite_PlayerGone();
1499 bot_relinkplayerlist();
1502 if(self.weaponentity)
1503 if(self.weaponentity.lasertarget)
1504 remove(self.weaponentity.lasertarget);
1508 Spawnqueue_Unmark(self);
1509 Spawnqueue_Remove(self);
1512 ClientData_Detach();
1513 PlayerScore_Detach(self);
1515 if(self.netname_previous)
1516 strunzone(self.netname_previous);
1517 if(self.clientstatus)
1518 strunzone(self.clientstatus);
1520 ClearPlayerSounds();
1530 void ChatBubbleThink()
1532 self.nextthink = time;
1533 if (!self.owner.modelindex || self.owner.chatbubbleentity != self)
1535 if(self.owner) // but why can that ever be world?
1536 self.owner.chatbubbleentity = world;
1540 if (self.owner.BUTTON_CHAT && !self.owner.deadflag)
1541 self.model = self.mdl;
1546 void UpdateChatBubble()
1548 if (!self.modelindex)
1550 // spawn a chatbubble entity if needed
1551 if (!self.chatbubbleentity)
1553 self.chatbubbleentity = spawn();
1554 self.chatbubbleentity.owner = self;
1555 self.chatbubbleentity.exteriormodeltoclient = self;
1556 self.chatbubbleentity.think = ChatBubbleThink;
1557 self.chatbubbleentity.nextthink = time;
1558 setmodel(self.chatbubbleentity, "models/misc/chatbubble.spr"); // precision set below
1559 //setorigin(self.chatbubbleentity, self.origin + '0 0 15' + self.maxs_z * '0 0 1');
1560 setorigin(self.chatbubbleentity, '0 0 15' + self.maxs_z * '0 0 1');
1561 setattachment(self.chatbubbleentity, self, ""); // sticks to moving player better, also conserves bandwidth
1562 self.chatbubbleentity.mdl = self.chatbubbleentity.model;
1563 self.chatbubbleentity.model = "";
1564 self.chatbubbleentity.effects = EF_LOWPRECISION;
1569 void TeamBubbleThink()
1571 self.nextthink = time;
1572 if (!self.owner.modelindex || self.owner.teambubbleentity != self)
1574 if(self.owner) // but why can that ever be world?
1575 self.owner.teambubbleentity = world;
1579 // setorigin(self, self.owner.origin + '0 0 15' + self.owner.maxs_z * '0 0 1'); // bandwidth hog. setattachment does this now
1580 if (self.owner.BUTTON_CHAT || self.owner.deadflag || self.owner.killindicator)
1583 self.model = self.mdl;
1587 float TeamBubble_customizeentityforclient()
1589 return (self.owner != other && self.owner.team == other.team && other.killcount > -666);
1592 void UpdateTeamBubble()
1594 if (!self.modelindex || !teams_matter)
1596 // spawn a teambubble entity if needed
1597 if (!self.teambubbleentity && teams_matter)
1599 self.teambubbleentity = spawn();
1600 self.teambubbleentity.owner = self;
1601 self.teambubbleentity.exteriormodeltoclient = self;
1602 self.teambubbleentity.think = TeamBubbleThink;
1603 self.teambubbleentity.nextthink = time;
1604 setmodel(self.teambubbleentity, "models/misc/teambubble.spr"); // precision set below
1605 // setorigin(self.teambubbleentity, self.origin + '0 0 15' + self.maxs_z * '0 0 1');
1606 setorigin(self.teambubbleentity, '0 0 15' + self.maxs_z * '0 0 1');
1607 setattachment(self.teambubbleentity, self, ""); // sticks to moving player better, also conserves bandwidth
1608 self.teambubbleentity.mdl = self.teambubbleentity.model;
1609 self.teambubbleentity.model = self.teambubbleentity.mdl;
1610 self.teambubbleentity.customizeentityforclient = TeamBubble_customizeentityforclient;
1611 self.teambubbleentity.effects = EF_LOWPRECISION;
1615 // LordHavoc: this hack will be removed when proper _pants/_shirt layers are
1616 // added to the model skins
1617 /*void UpdateColorModHack()
1620 c = self.clientcolors & 15;
1621 // LordHavoc: only bothering to support white, green, red, yellow, blue
1622 if (!teams_matter) self.colormod = '0 0 0';
1623 else if (c == 0) self.colormod = '1.00 1.00 1.00';
1624 else if (c == 3) self.colormod = '0.10 1.73 0.10';
1625 else if (c == 4) self.colormod = '1.73 0.10 0.10';
1626 else if (c == 12) self.colormod = '1.22 1.22 0.10';
1627 else if (c == 13) self.colormod = '0.10 0.10 1.73';
1628 else self.colormod = '1 1 1';
1634 self.effects |= EF_NODRAW; // prevent another CopyBody
1635 PutClientInServer();
1638 void play_countdown(float finished, string samp)
1640 if(clienttype(self) == CLIENTTYPE_REAL)
1641 if(floor(finished - time - frametime) != floor(finished - time))
1642 if(finished - time < 6)
1643 sound (self, CHAN_AUTO, samp, VOL_BASE, ATTN_NORM);
1647 * When sv_timeout is used this function returs strings like
1648 * "Timeout begins in 2 seconds!\n" or "Timeout ends in 23 seconds!\n".
1649 * Called by centerprint functions
1650 * @param addOneSecond boolean, set to 1 if the welcome-message centerprint asks for the text
1652 string getTimeoutText(float addOneSecond) {
1653 if (!cvar("sv_timeout") || !timeoutStatus)
1656 local string retStr;
1657 if (timeoutStatus == 1) {
1658 if (addOneSecond == 1) {
1659 retStr = strcat("Timeout begins in ", ftos(remainingLeadTime + 1), " seconds!\n");
1662 retStr = strcat("Timeout begins in ", ftos(remainingLeadTime), " seconds!\n");
1666 else if (timeoutStatus == 2) {
1668 retStr = strcat("Timeout ends in ", ftos(remainingTimeoutTime + 1), " seconds!\n");
1669 //don't show messages like "Timeout ends in 0 seconds"...
1670 if ((remainingTimeoutTime + 1) > 0)
1676 retStr = strcat("Timeout ends in ", ftos(remainingTimeoutTime), " seconds!\n");
1677 //don't show messages like "Timeout ends in 0 seconds"...
1678 if (remainingTimeoutTime > 0)
1687 void player_powerups (void)
1689 if((self.items & IT_USING_JETPACK) && !self.deadflag)
1691 SoundEntity_StartSound(self, CHAN_PLAYER, "misc/jetpack_fly.wav", VOL_BASE, cvar("g_jetpack_attenuation"));
1692 self.modelflags |= MF_ROCKET;
1696 SoundEntity_StopSound(self, CHAN_PLAYER);
1697 self.modelflags &~= MF_ROCKET;
1700 self.effects &~= (EF_RED | EF_BLUE | EF_ADDITIVE | EF_FULLBRIGHT);
1702 if(!self.modelindex || self.deadflag) // don't apply the flags if the player is gibbed
1707 self.effects |= EF_FULLBRIGHT;
1709 if (self.items & IT_STRENGTH)
1711 play_countdown(self.strength_finished, "misc/poweroff.wav");
1712 if (time > self.strength_finished)
1714 self.alpha = default_player_alpha;
1715 self.exteriorweaponentity.alpha = default_weapon_alpha;
1716 self.items &~= IT_STRENGTH;
1717 sprint(self, "^3Invisibility has worn off\n");
1722 if (time < self.strength_finished)
1724 self.alpha = g_minstagib_invis_alpha;
1725 self.exteriorweaponentity.alpha = g_minstagib_invis_alpha;
1726 self.items |= IT_STRENGTH;
1727 sprint(self, "^3You are invisible\n");
1731 if (self.items & IT_INVINCIBLE)
1733 play_countdown(self.invincible_finished, "misc/poweroff.wav");
1734 if (time > self.invincible_finished)
1736 self.items = self.items - (self.items & IT_INVINCIBLE);
1737 sprint(self, "^3Speed has worn off\n");
1742 if (time < self.invincible_finished)
1744 self.items = self.items | IT_INVINCIBLE;
1745 sprint(self, "^3You are on speed\n");
1751 if (self.items & IT_STRENGTH)
1753 play_countdown(self.strength_finished, "misc/poweroff.wav");
1754 self.effects = self.effects | (EF_BLUE | EF_ADDITIVE | EF_FULLBRIGHT);
1755 if (time > self.strength_finished)
1757 self.items = self.items - (self.items & IT_STRENGTH);
1758 sprint(self, "^3Strength has worn off\n");
1763 if (time < self.strength_finished)
1765 self.items = self.items | IT_STRENGTH;
1766 sprint(self, "^3Strength infuses your weapons with devastating power\n");
1769 if (self.items & IT_INVINCIBLE)
1771 play_countdown(self.invincible_finished, "misc/poweroff.wav");
1772 self.effects = self.effects | (EF_RED | EF_ADDITIVE | EF_FULLBRIGHT);
1773 if (time > self.invincible_finished)
1775 self.items = self.items - (self.items & IT_INVINCIBLE);
1776 sprint(self, "^3Shield has worn off\n");
1781 if (time < self.invincible_finished)
1783 self.items = self.items | IT_INVINCIBLE;
1784 sprint(self, "^3Shield surrounds you\n");
1788 if (cvar("g_fullbrightplayers"))
1789 self.effects = self.effects | EF_FULLBRIGHT;
1791 // midair gamemode: damage only while in the air
1792 // if in midair mode, being on ground grants temporary invulnerability
1793 // (this is so that multishot weapon don't clear the ground flag on the
1794 // first damage in the frame, leaving the player vulnerable to the
1795 // remaining hits in the same frame)
1796 if (self.flags & FL_ONGROUND)
1798 self.spawnshieldtime = max(self.spawnshieldtime, time + cvar("g_midair_shieldtime"));
1800 if (time >= game_starttime)
1801 if (time < self.spawnshieldtime)
1802 self.effects = self.effects | (EF_ADDITIVE | EF_FULLBRIGHT);
1805 float CalcRegen(float current, float stable, float regenfactor, float regenframetime)
1807 if(current > stable)
1809 else if(current > stable - 0.25) // when close enough, "snap"
1812 return min(stable, current + (stable - current) * regenfactor * regenframetime);
1815 float CalcRot(float current, float stable, float rotfactor, float rotframetime)
1817 if(current < stable)
1819 else if(current < stable + 0.25) // when close enough, "snap"
1822 return max(stable, current + (stable - current) * rotfactor * rotframetime);
1825 float CalcRotRegen(float current, float regenstable, float regenfactor, float regenlinear, float regenframetime, float rotstable, float rotfactor, float rotlinear, float rotframetime, float limit)
1827 if(current > rotstable)
1829 if(rotframetime > 0)
1831 current = CalcRot(current, rotstable, rotfactor, rotframetime);
1832 current = max(rotstable, current - rotlinear * rotframetime);
1835 else if(current < regenstable)
1837 if(regenframetime > 0)
1839 current = CalcRegen(current, regenstable, regenfactor, regenframetime);
1840 current = min(regenstable, current + regenlinear * regenframetime);
1850 void player_regen (void)
1852 float minh, mina, minf, maxh, maxa, maxf, limith, limita, limitf, max_mod, regen_mod, rot_mod, limit_mod;
1853 maxh = cvar("g_balance_health_rotstable");
1854 maxa = cvar("g_balance_armor_rotstable");
1855 maxf = cvar("g_balance_fuel_rotstable");
1856 minh = cvar("g_balance_health_regenstable");
1857 mina = cvar("g_balance_armor_regenstable");
1858 minf = cvar("g_balance_fuel_regenstable");
1859 limith = cvar("g_balance_health_limit");
1860 limita = cvar("g_balance_armor_limit");
1861 limitf = cvar("g_balance_fuel_limit");
1863 max_mod = regen_mod = rot_mod = limit_mod = 1;
1865 if (self.runes & RUNE_REGEN)
1867 if (self.runes & CURSE_VENOM) // do we have both rune/curse?
1869 regen_mod = cvar("g_balance_rune_regen_combo_regenrate");
1870 max_mod = cvar("g_balance_rune_regen_combo_hpmod");
1871 limit_mod = cvar("g_balance_rune_regen_combo_limitmod");
1875 regen_mod = cvar("g_balance_rune_regen_regenrate");
1876 max_mod = cvar("g_balance_rune_regen_hpmod");
1877 limit_mod = cvar("g_balance_rune_regen_limitmod");
1880 else if (self.runes & CURSE_VENOM)
1882 max_mod = cvar("g_balance_curse_venom_hpmod");
1883 if (self.runes & RUNE_REGEN) // do we have both rune/curse?
1884 rot_mod = cvar("g_balance_rune_regen_combo_rotrate");
1886 rot_mod = cvar("g_balance_curse_venom_rotrate");
1887 limit_mod = cvar("g_balance_curse_venom_limitmod");
1888 //if (!self.runes & RUNE_REGEN)
1889 // rot_mod = cvar("g_balance_curse_venom_rotrate");
1891 maxh = maxh * max_mod;
1892 //maxa = maxa * max_mod;
1893 //maxf = maxf * max_mod;
1894 minh = minh * max_mod;
1895 //mina = mina * max_mod;
1896 //minf = minf * max_mod;
1897 limith = limith * limit_mod;
1898 limita = limita * limit_mod;
1899 //limitf = limitf * limit_mod;
1904 if (!g_minstagib && (!g_lms || cvar("g_lms_regenerate")))
1906 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);
1907 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);
1909 // if player rotted to death... die!
1911 self.event_damage(self, self, 1, DEATH_ROT, self.origin, '0 0 0');
1914 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);
1917 float zoomstate_set;
1918 void SetZoomState(float z)
1920 if(z != self.zoomstate)
1923 ClientData_Touch(self);
1928 void GetPressedKeys(void) {
1929 if (self.movement_x > 0) // get if movement keys are pressed
1930 { // forward key pressed
1931 self.pressedkeys |= KEY_FORWARD;
1932 self.pressedkeys &~= KEY_BACKWARD;
1934 else if (self.movement_x < 0)
1935 { // backward key pressed
1936 self.pressedkeys |= KEY_BACKWARD;
1937 self.pressedkeys &~= KEY_FORWARD;
1941 self.pressedkeys &~= KEY_FORWARD;
1942 self.pressedkeys &~= KEY_BACKWARD;
1945 if (self.movement_y > 0)
1946 { // right key pressed
1947 self.pressedkeys |= KEY_RIGHT;
1948 self.pressedkeys &~= KEY_LEFT;
1950 else if (self.movement_y < 0)
1951 { // left key pressed
1952 self.pressedkeys |= KEY_LEFT;
1953 self.pressedkeys &~= KEY_RIGHT;
1957 self.pressedkeys &~= KEY_RIGHT;
1958 self.pressedkeys &~= KEY_LEFT;
1961 if (self.BUTTON_JUMP) // get if jump and crouch keys are pressed
1962 self.pressedkeys |= KEY_JUMP;
1964 self.pressedkeys &~= KEY_JUMP;
1965 if (self.BUTTON_CROUCH)
1966 self.pressedkeys |= KEY_CROUCH;
1968 self.pressedkeys &~= KEY_CROUCH;
1972 ======================
1973 spectate mode routines
1974 ======================
1976 void SpectateCopy(entity spectatee) {
1977 self.armortype = spectatee.armortype;
1978 self.armorvalue = spectatee.armorvalue;
1979 self.ammo_cells = spectatee.ammo_cells;
1980 self.ammo_shells = spectatee.ammo_shells;
1981 self.ammo_nails = spectatee.ammo_nails;
1982 self.ammo_rockets = spectatee.ammo_rockets;
1983 self.ammo_fuel = spectatee.ammo_fuel;
1984 self.effects = spectatee.effects & EFMASK_CHEAP; // eat performance
1985 self.health = spectatee.health;
1987 self.items = spectatee.items;
1988 self.metertime = spectatee.metertime;
1989 self.strength_finished = spectatee.strength_finished;
1990 self.invincible_finished = spectatee.invincible_finished;
1991 self.maxdamage_fired = spectatee.maxdamage_fired;
1992 self.damage_hits = spectatee.damage_hits;
1993 self.pressedkeys = spectatee.pressedkeys;
1994 self.weapons = spectatee.weapons;
1995 self.switchweapon = spectatee.switchweapon;
1996 self.weapon = spectatee.weapon;
1997 self.punchangle = spectatee.punchangle;
1998 self.view_ofs = spectatee.view_ofs;
1999 self.v_angle = spectatee.v_angle;
2000 self.velocity = spectatee.velocity;
2001 self.dmg_take = spectatee.dmg_take;
2002 self.dmg_save = spectatee.dmg_save;
2003 self.dmg_inflictor = spectatee.dmg_inflictor;
2004 self.angles = spectatee.v_angle;
2005 self.fixangle = TRUE;
2006 setorigin(self, spectatee.origin);
2007 setsize(self, spectatee.mins, spectatee.maxs);
2008 SetZoomState(spectatee.zoomstate);
2011 float SpectateUpdate() {
2015 if (self == self.enemy)
2018 if(self.enemy.classname != "player")
2021 SpectateCopy(self.enemy);
2026 float SpectateNext() {
2027 other = find(self.enemy, classname, "player");
2029 other = find(other, classname, "player");
2034 if(self.enemy.classname == "player") {
2036 WriteByte(MSG_ONE, SVC_SETVIEW);
2037 WriteEntity(MSG_ONE, self.enemy);
2038 //stuffcmd(self, "set viewsize $tmpviewsize \n");
2039 if(!SpectateUpdate())
2040 PutObserverInServer();
2049 ShowRespawnCountdown()
2051 Update a respawn countdown display.
2054 void ShowRespawnCountdown()
2057 if(self.deadflag == DEAD_NO) // just respawned?
2061 number = ceil(self.death_time - time);
2064 if(number <= self.respawn_countdown)
2066 self.respawn_countdown = number - 1;
2067 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
2068 announce(self, strcat("announcer/robotic/", ftos(number), ".wav"));
2073 void LeaveSpectatorMode()
2075 if(isJoinAllowed()) {
2076 if(!teams_matter || cvar("g_campaign") || cvar("g_balance_teams") || (self.wasplayer && cvar("g_changeteam_banned"))) {
2077 self.classname = "player";
2078 if(cvar("g_campaign") || cvar("g_balance_teams") || cvar("g_balance_teams_force"))
2079 JoinBestTeam(self, FALSE, TRUE);
2080 if(cvar("g_campaign"))
2081 campaign_bots_may_start = 1;
2082 PutClientInServer();
2083 if(self.classname == "player")
2084 bprint ("^4", self.netname, "^4 is playing now\n");
2085 if(!cvar("g_campaign"))
2086 centerprint(self,""); // clear MOTD
2089 stuffcmd(self,"menu_showteamselect\n");
2094 //player may not join because of g_maxplayers is set
2095 centerprint_atprio(self, CENTERPRIO_MAPVOTE, PREVENT_JOIN_TEXT);
2100 * Determines whether the player is allowed to join. This depends on cvar
2101 * g_maxplayers, if it isn't used this function always return TRUE, otherwise
2102 * it checks whether the number of currently playing players exceeds g_maxplayers.
2103 * @return bool TRUE if the player is allowed to join, false otherwise
2105 float isJoinAllowed() {
2106 if (!cvar("g_maxplayers"))
2110 local float currentlyPlaying;
2111 FOR_EACH_REALPLAYER(e) {
2112 if(e.classname == "player")
2113 currentlyPlaying += 1;
2115 if(currentlyPlaying < cvar("g_maxplayers"))
2122 * Checks whether the client is an observer or spectator, if so, he will get kicked after
2123 * g_maxplayers_spectator_blocktime seconds
2125 void checkSpectatorBlock() {
2126 if(self.classname == "spectator" || self.classname == "observer") {
2127 if( time > (self.spectatortime + cvar("g_maxplayers_spectator_blocktime")) ) {
2128 sprint(self, "^7You were kicked from the server because you are spectator and spectators aren't allowed at the moment.\n");
2134 float vercmp_recursive(string v1, string v2)
2140 dot1 = strstrofs(v1, ".", 0);
2141 dot2 = strstrofs(v2, ".", 0);
2145 s1 = substring(v1, 0, dot1);
2149 s2 = substring(v2, 0, dot2);
2151 r = stof(s1) - stof(s2);
2155 r = strcasecmp(s1, s2);
2168 return vercmp_recursive(substring(v1, dot1 + 1, 999), substring(v2, dot2 + 1, 999));
2171 float vercmp(string v1, string v2)
2173 if(strcasecmp(v1, v2) == 0) // early out check
2175 return vercmp_recursive(v1, v2);
2178 void ObserverThink()
2180 if (self.flags & FL_JUMPRELEASED) {
2181 if (self.BUTTON_JUMP && !self.version_mismatch) {
2182 self.welcomemessage_time = 0;
2183 self.flags &~= FL_JUMPRELEASED;
2184 self.flags |= FL_SPAWNING;
2185 } else if(self.BUTTON_ATCK && !self.version_mismatch) {
2186 self.welcomemessage_time = 0;
2187 self.flags &~= FL_JUMPRELEASED;
2188 if(SpectateNext() == 1) {
2189 self.classname = "spectator";
2193 if (!(self.BUTTON_ATCK || self.BUTTON_JUMP)) {
2194 self.flags |= FL_JUMPRELEASED;
2195 if(self.flags & FL_SPAWNING)
2197 self.flags &~= FL_SPAWNING;
2198 LeaveSpectatorMode();
2203 PrintWelcomeMessage(self);
2206 void SpectatorThink()
2208 if (self.flags & FL_JUMPRELEASED) {
2209 if (self.BUTTON_JUMP && !self.version_mismatch) {
2210 self.welcomemessage_time = 0;
2211 self.flags &~= FL_JUMPRELEASED;
2212 self.flags |= FL_SPAWNING;
2213 } else if(self.BUTTON_ATCK) {
2214 self.welcomemessage_time = 0;
2215 self.flags &~= FL_JUMPRELEASED;
2216 if(SpectateNext() == 1) {
2217 self.classname = "spectator";
2219 self.classname = "observer";
2220 PutClientInServer();
2222 } else if (self.BUTTON_ATCK2) {
2223 self.welcomemessage_time = 0;
2224 self.flags &~= FL_JUMPRELEASED;
2225 self.classname = "observer";
2226 PutClientInServer();
2228 if(!SpectateUpdate())
2229 PutObserverInServer();
2232 if (!(self.BUTTON_ATCK || self.BUTTON_ATCK2)) {
2233 self.flags |= FL_JUMPRELEASED;
2234 if(self.flags & FL_SPAWNING)
2236 self.flags &~= FL_SPAWNING;
2237 LeaveSpectatorMode();
2242 PrintWelcomeMessage(self);
2243 self.flags |= FL_CLIENT | FL_NOTARGET;
2246 .float touchexplode_time;
2252 Called every frame for each client before the physics are run
2255 void() ctf_setstatus;
2256 void() nexball_setstatus;
2258 void PlayerPreThink (void)
2260 self.stat_game_starttime = game_starttime;
2261 self.stat_allow_oldnexbeam = cvar("g_allow_oldnexbeam");
2262 self.stat_leadlimit = cvar("leadlimit");
2264 if(blockSpectators && frametime)
2265 // WORKAROUND: only use dropclient in server frames (frametime set). Never use it in cl_movement frames (frametime zero).
2266 checkSpectatorBlock();
2270 if(self.netname_previous != self.netname)
2272 if(cvar("sv_eventlog"))
2273 GameLogEcho(strcat(":name:", ftos(self.playerid), ":", self.netname));
2274 if(self.netname_previous)
2275 strunzone(self.netname_previous);
2276 self.netname_previous = strzone(self.netname);
2280 if(self.version_nagtime)
2281 if(self.cvar_g_nexuizversion)
2282 if(time > self.version_nagtime)
2284 if(strstr(self.cvar_g_nexuizversion, "svn", 0) < 0)
2286 if(strstr(cvar_string("g_nexuizversion"), "svn", 0) >= 0)
2288 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");
2289 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"));
2294 r = vercmp(self.cvar_g_nexuizversion, cvar_string("g_nexuizversion"));
2297 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");
2298 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"));
2302 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");
2303 sprint(self, strcat("\{1}^1NOTE: ^7the server is running ^3Nexuiz ", cvar_string("g_nexuizversion"), "^7, you have ^3Nexuiz ", self.cvar_g_nexuizversion, "^1\n"));
2307 self.version_nagtime = 0;
2311 if(!(self.flags & FL_GODMODE)) if(self.max_armorvalue)
2313 sprint(self, strcat("godmode saved you ", ftos(self.max_armorvalue), " units of damage, cheater!\n"));
2314 self.max_armorvalue = 0;
2318 antilag_record(self);
2320 if(self.classname == "player") {
2321 // if(self.netname == "Wazat")
2322 // bprint(self.classname, "\n");
2324 CheckRules_Player();
2326 PrintWelcomeMessage(self);
2328 if (intermission_running)
2330 IntermissionThink (); // otherwise a button could be missed between
2331 return; // the think tics
2334 if(self.teleport_time)
2335 if(time > self.teleport_time)
2337 self.teleport_time = 0;
2338 self.effects = self.effects - (self.effects & EF_NODRAW);
2341 Nixnex_GiveCurrentWeapon();
2343 if(frametime > 0) // don't do this in cl_movement frames, just in server ticks
2344 UpdateSelectedPlayer();
2346 //don't allow the player to turn around while game is paused!
2347 if(timeoutStatus == 2) {
2348 self.v_angle = self.lastV_angle;
2349 self.angles = self.lastV_angle;
2350 self.fixangle = TRUE;
2356 if (self.deadflag != DEAD_NO)
2358 float button_pressed, force_respawn;
2361 button_pressed = (self.BUTTON_ATCK || self.BUTTON_JUMP || self.BUTTON_ATCK2 || self.BUTTON_HOOK || self.BUTTON_USE);
2362 force_respawn = (g_lms || cvar("g_forced_respawn"));
2363 if (self.deadflag == DEAD_DYING)
2366 self.deadflag = DEAD_RESPAWNING;
2367 else if(!button_pressed)
2368 self.deadflag = DEAD_DEAD;
2370 else if (self.deadflag == DEAD_DEAD)
2373 self.deadflag = DEAD_RESPAWNABLE;
2375 else if (self.deadflag == DEAD_RESPAWNABLE)
2378 self.deadflag = DEAD_RESPAWNING;
2380 else if (self.deadflag == DEAD_RESPAWNING)
2382 if(time > self.death_time)
2384 self.death_time = time + 1; // only retry once a second
2388 ShowRespawnCountdown();
2393 if(time > self.touchexplode_time)
2394 if(self.classname == "player")
2395 if(self.deadflag == DEAD_NO)
2396 if not(IS_INDEPENDENT_PLAYER(self))
2397 FOR_EACH_PLAYER(other) if(self != other)
2399 if(time > other.touchexplode_time)
2400 if(other.classname == "player")
2401 if(other.deadflag == DEAD_NO)
2402 if not(IS_INDEPENDENT_PLAYER(other))
2403 if(boxesoverlap(self.absmin, self.absmax, other.absmin, other.absmax))
2405 PlayerTouchExplode(self, other);
2406 self.touchexplode_time = other.touchexplode_time = time + 0.2;
2410 if(g_lms && !self.deadflag && cvar("g_lms_campcheck_interval"))
2414 // calculate player movement (in 2 dimensions only, so jumping on one spot doesn't count as movement)
2415 dist = self.prevorigin - self.origin;
2417 self.lms_traveled_distance += fabs(vlen(dist));
2419 if((cvar("g_campaign") && !campaign_bots_may_start) || (time < game_starttime))
2421 self.lms_nextcheck = time + cvar("g_lms_campcheck_interval")*2;
2422 self.lms_traveled_distance = 0;
2425 if(time > self.lms_nextcheck)
2427 //sprint(self, "distance: ", ftos(self.lms_traveled_distance), "\n");
2428 if(self.lms_traveled_distance < cvar("g_lms_campcheck_distance"))
2430 centerprint(self, cvar_string("g_lms_campcheck_message"));
2431 // FIXME KadaverJack: gibbing player here causes playermodel to bounce around, instead of eye.md3
2432 // I wasn't able to find out WHY that happens, so I put a workaround in place that shall prevent players from being gibbed :(
2433 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');
2435 self.lms_nextcheck = time + cvar("g_lms_campcheck_interval");
2436 self.lms_traveled_distance = 0;
2440 self.prevorigin = self.origin;
2442 if ((self.BUTTON_CROUCH && !self.hook.state) || self.health <= g_bloodloss)
2447 self.view_ofs = PL_CROUCH_VIEW_OFS;
2448 setsize (self, PL_CROUCH_MIN, PL_CROUCH_MAX);
2449 setanim(self, self.anim_duck, FALSE, TRUE, TRUE);
2456 tracebox(self.origin, PL_MIN, PL_MAX, self.origin, FALSE, self);
2457 if (!trace_startsolid)
2459 self.crouch = FALSE;
2460 self.view_ofs = PL_VIEW_OFS;
2461 setsize (self, PL_MIN, PL_MAX);
2466 if(self.health <= g_bloodloss && self.deadflag == DEAD_NO)
2468 if(self.bloodloss_timer < time)
2470 self.event_damage(self, self, 1, DEATH_ROT, self.origin, '0 0 0');
2471 self.bloodloss_timer = time + 0.5 + random() * 0.5;
2477 GrapplingHookFrame();
2481 self.items &~= self.items_added;
2485 self.items_added = 0;
2486 if(self.items & IT_JETPACK)
2487 if(self.items & IT_FUEL_REGEN || self.ammo_fuel >= 0.01)
2488 self.items_added |= IT_FUEL;
2490 self.items |= self.items_added;
2498 minstagib_ammocheck();
2502 nexball_setstatus();
2504 self.dmg_team = max(0, self.dmg_team - cvar("g_teamdamage_resetspeed") * frametime);
2506 //self.angles_y=self.v_angle_y + 90; // temp
2508 //if (TetrisPreFrame()) return;
2509 } else if(gameover) {
2510 if (intermission_running)
2511 IntermissionThink (); // otherwise a button could be missed between
2513 } else if(self.classname == "observer") {
2515 } else if(self.classname == "spectator") {
2520 SetZoomState(self.BUTTON_ZOOM || (self.BUTTON_ATCK2 && self.weapon == WEP_NEX));
2522 float oldspectatee_status;
2523 oldspectatee_status = self.spectatee_status;
2524 if(self.classname == "spectator")
2525 self.spectatee_status = num_for_edict(self.enemy);
2526 else if(self.classname == "observer")
2527 self.spectatee_status = num_for_edict(self);
2529 self.spectatee_status = 0;
2530 if(self.spectatee_status != oldspectatee_status)
2532 ClientData_Touch(self);
2534 race_InitSpectator();
2537 if(self.teamkill_soundtime)
2538 if(time > self.teamkill_soundtime)
2540 self.teamkill_soundtime = 0;
2542 entity oldpusher, oldself;
2544 oldself = self; self = self.teamkill_soundsource;
2545 oldpusher = self.pusher; self.pusher = oldself;
2547 PlayerSound(playersound_teamshoot, CHAN_VOICE, VOICETYPE_LASTATTACKER_ONLY);
2549 self.pusher = oldpusher;
2553 if(self.taunt_soundtime)
2554 if(time > self.taunt_soundtime)
2556 self.taunt_soundtime = 0;
2557 PlayerSound(playersound_taunt, CHAN_VOICE, VOICETYPE_AUTOTAUNT);
2560 target_voicescript_next(self);
2566 .float dragspeed; // speed of mouse wheel action
2567 .float dragdistance; // distance of dragentity's draglocalvector from view_ofs
2568 .vector draglocalvector; // local attachment vector of the dragentity
2569 .float draglocalangle;
2572 .float dragmovetype;
2573 void Drag_Begin(entity dragger, entity draggee, vector touchpoint)
2577 draggee.dragmovetype = draggee.movetype;
2578 draggee.draggravity = draggee.gravity;
2579 draggee.movetype = MOVETYPE_WALK;
2580 draggee.gravity = 0.00001;
2581 draggee.flags &~= FL_ONGROUND;
2582 draggee.draggedby = dragger;
2584 dragger.dragentity = draggee;
2586 dragger.dragdistance = vlen(touchpoint - dragger.origin - dragger.view_ofs);
2587 dragger.draglocalangle = draggee.angles_y - dragger.v_angle_y;
2588 touchpoint = touchpoint - gettaginfo(draggee, 0);
2589 tagscale = pow(vlen(v_forward), -2);
2590 dragger.draglocalvector_x = touchpoint * v_forward * tagscale;
2591 dragger.draglocalvector_y = touchpoint * v_right * tagscale;
2592 dragger.draglocalvector_z = touchpoint * v_up * tagscale;
2594 dragger.dragspeed = 64;
2597 void Drag_Finish(entity dragger)
2600 draggee = dragger.dragentity;
2602 dragger.dragentity = world;
2603 draggee.draggedby = world;
2604 draggee.movetype = draggee.dragmovetype;
2605 draggee.gravity = draggee.draggravity;
2607 switch(draggee.movetype)
2612 case MOVETYPE_FLYMISSILE:
2613 case MOVETYPE_BOUNCE:
2614 case MOVETYPE_BOUNCEMISSILE:
2617 draggee.velocity = '0 0 0';
2621 if((draggee.flags & FL_ITEM) && (vlen(draggee.velocity) < 32))
2623 draggee.velocity = '0 0 0';
2624 draggee.flags |= FL_ONGROUND; // floating items are FUN
2628 float Drag_IsDraggable(entity draggee)
2630 // TODO add more checks for bad stuff here
2631 if(draggee.classname == "func_bobbing")
2633 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)
2635 if(draggee.classname == "plat")
2637 if(draggee.classname == "func_button")
2639 if(draggee.model == "")
2641 if(draggee.classname == "spectator")
2643 if(draggee.classname == "observer")
2645 if(draggee.classname == "exteriorweaponentity")
2651 float Drag_MayChangeAngles(entity draggee)
2653 // TODO add more checks for bad stuff here
2654 if(substring(draggee.model, 0, 1) == "*")
2659 void Drag_MoveForward(entity dragger)
2661 dragger.dragdistance += dragger.dragspeed;
2664 void Drag_SetSpeed(entity dragger, float s)
2666 dragger.dragspeed = pow(2, s);
2669 void Drag_MoveBackward(entity dragger)
2671 dragger.dragdistance = max(0, dragger.dragdistance - dragger.dragspeed);
2674 void Drag_Update(entity dragger)
2676 vector curorigin, neworigin, goodvelocity;
2680 draggee = dragger.dragentity;
2681 draggee.flags &~= FL_ONGROUND;
2683 curorigin = gettaginfo(draggee, 0);
2684 curorigin = curorigin + v_forward * dragger.draglocalvector_x + v_right * dragger.draglocalvector_y + v_up * dragger.draglocalvector_z;
2685 makevectors(dragger.v_angle);
2686 neworigin = dragger.origin + dragger.view_ofs + v_forward * dragger.dragdistance;
2687 goodvelocity = (neworigin - curorigin) * (1 / frametime);
2689 while(draggee.angles_y - dragger.v_angle_y - dragger.draglocalangle > 180)
2690 dragger.draglocalangle += 360;
2691 while(draggee.angles_y - dragger.v_angle_y - dragger.draglocalangle <= -180)
2692 dragger.draglocalangle -= 360;
2694 f = min(frametime * 10, 1);
2695 draggee.velocity = draggee.velocity * (1 - f) + goodvelocity * f;
2697 if(Drag_MayChangeAngles(draggee))
2698 draggee.angles_y = draggee.angles_y * (1 - f) + (dragger.v_angle_y + dragger.draglocalangle) * f;
2700 draggee.ltime = max(servertime + serverframetime, draggee.ltime); // fixes func_train breakage
2702 te_lightning1(dragger, dragger.origin + dragger.view_ofs, curorigin);
2705 float Drag_CanDrag(entity dragger)
2707 return (dragger.deadflag == DEAD_NO) || (dragger.classname == "player");
2710 float Drag_IsDragging(entity dragger)
2712 if(!dragger.dragentity)
2714 if(wasfreed(dragger.dragentity) || dragger.dragentity.draggedby != dragger)
2716 dragger.dragentity = world;
2719 if(!Drag_CanDrag(dragger) || !Drag_IsDraggable(dragger.dragentity))
2721 Drag_Finish(dragger);
2727 void Drag_MoveDrag(entity from, entity to)
2731 to.draggedby = from.draggedby;
2732 to.draggedby.dragentity = to;
2733 from.draggedby = world;
2741 Called every frame for each client after the physics are run
2744 .float idlekick_lasttimeleft;
2745 .float race_penalty;
2746 .float race_penalty_nagged;
2747 .float race_penalty_nagtime;
2748 void PlayerPostThink (void)
2750 // Savage: Check for nameless players
2751 if (strlen(self.netname) < 1) {
2752 self.netname = "Player";
2753 stuffcmd(self, "seta _cl_name Player\n");
2756 if(sv_maxidle && frametime)
2758 // WORKAROUND: only use dropclient in server frames (frametime set). Never use it in cl_movement frames (frametime zero).
2760 timeleft = ceil(sv_maxidle - (time - self.parm_idlesince));
2763 bprint("^3", self.netname, "^3 was kicked for idling.\n");
2764 announce(self, "announcer/robotic/terminated.wav");
2768 else if(timeleft <= 10)
2770 if(timeleft != self.idlekick_lasttimeleft)
2772 centerprint_atprio(self, CENTERPRIO_IDLEKICK, strcat("^3Stop idling!\n^3Disconnecting in ", ftos(timeleft), "..."));
2773 announce(self, strcat("announcer/robotic/", ftos(timeleft), ".wav"));
2778 centerprint_expire(self, CENTERPRIO_IDLEKICK);
2780 self.idlekick_lasttimeleft = timeleft;
2783 if(sv_cheats || self.maycheat)
2784 if(Drag_CanDrag(self))
2785 if(self.BUTTON_DRAG)
2786 if(!self.dragentity)
2787 if(self.cursor_trace_ent)
2788 if(Drag_IsDraggable(self.cursor_trace_ent))
2790 if(self.cursor_trace_ent.draggedby)
2791 Drag_Finish(self.cursor_trace_ent.draggedby);
2792 if(self.cursor_trace_ent.tag_entity)
2793 detach_sameorigin(self.cursor_trace_ent);
2794 Drag_Begin(self, self.cursor_trace_ent, self.cursor_trace_endpos);
2797 if(Drag_IsDragging(self))
2799 if(self.BUTTON_DRAG)
2801 if(self.impulse == 10 || self.impulse == 15 || self.impulse == 18)
2803 Drag_MoveForward(self);
2806 else if(self.impulse == 12 || self.impulse == 16 || self.impulse == 19)
2808 Drag_MoveBackward(self);
2811 else if(self.impulse >= 1 && self.impulse <= 9)
2813 Drag_SetSpeed(self, self.impulse - 1);
2815 else if(self.impulse == 14)
2817 Drag_SetSpeed(self, 9);
2829 if(self.classname == "player") {
2830 CheckRules_Player();
2835 if (intermission_running)
2836 return; // intermission or finale
2838 //if (TetrisPostFrame()) return;
2840 // restart countdown
2841 if(time < game_starttime) {
2842 if (!cvar("sv_ready_restart_after_countdown"))
2844 if(self.movement != '0 0 0' && g_race && !g_race_qualifying)
2846 if(time < game_starttime - 2)
2848 if(!self.race_penalty_nagged)
2850 // TODO better notification for this!
2851 self.race_penalty_nagtime = 0;
2852 self.race_penalty_nagged = 1;
2855 else if(!self.race_penalty)
2857 self.race_penalty_nagtime = 0;
2858 self.race_penalty = time + 5;
2861 if(time > self.race_penalty_nagtime)
2863 if(self.race_penalty > time)
2865 centerprint_atprio(self, CENTERPRIO_IDLEKICK, "^1FIVE SECONDS PENALTY.");
2867 else if(self.race_penalty_nagged && time < game_starttime - 2)
2869 centerprint_atprio(self, CENTERPRIO_IDLEKICK, "^1DO NOT MOVE DURING THE COUNTDOWN.");
2871 self.race_penalty_nagtime = time + self.cvar_scr_centertime * 0.6;
2873 self.movetype = MOVETYPE_NONE;
2874 self.velocity = '0 0 0';
2875 self.avelocity = '0 0 0';
2876 self.movement = '0 0 0';
2879 else if (time < self.race_penalty)
2881 self.movetype = MOVETYPE_NONE;
2882 self.velocity = '0 0 0';
2883 self.avelocity = '0 0 0';
2884 self.movement = '0 0 0';
2888 //allow the player to move again if sv_ready_restart_after_countdown is not used and countdown is over
2889 if (!cvar("sv_ready_restart_after_countdown"))
2891 if(self.movetype == MOVETYPE_NONE)
2893 self.movetype = MOVETYPE_WALK;
2895 self.race_penalty = 0;
2896 self.race_penalty_nagged = 0;
2900 } else if (self.classname == "observer") {
2902 } else if (self.classname == "spectator") {
2908 for(i = 0; i < 1000; ++i)
2911 end = self.origin + '0 0 1024' + 512 * randomvec();
2912 tracebox(self.origin, self.mins, self.maxs, end, MOVE_NORMAL, self);
2913 if(trace_fraction < 1)
2914 if(!(trace_dphitq3surfaceflags & Q3SURFACEFLAG_NOIMPACT))
2916 print("I HIT SOLID: ", vtos(self.origin), " -> ", vtos(end), "\n");
2924 //pointparticles(particleeffectnum("machinegun_impact"), self.origin + self.view_ofs + '0 0 7', '0 0 0', 1);
2926 if(self.waypointsprite_attachedforcarrier)
2927 WaypointSprite_UpdateHealth(self.waypointsprite_attachedforcarrier, '1 0 0' * healtharmor_maxdamage(self.health, self.armorvalue, cvar("g_balance_armor_blockpercent")));