]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blobdiff - qcsrc/server/cl_client.qc
Clean up g_vehicles_enter nearby vehicle checking
[xonotic/xonotic-data.pk3dir.git] / qcsrc / server / cl_client.qc
index 457822e8e406107d15721fe15eca3f223794470f..4263bc3b31cc99495ebc7b534f746b10a2480a8a 100644 (file)
@@ -247,7 +247,7 @@ void PutObserverInServer(entity this)
 
        if (this.killcount != FRAGS_SPECTATOR)
        {
-               Send_Notification(NOTIF_ALL, world, MSG_INFO, INFO_QUIT_SPECTATE, this.netname);
+               Send_Notification(NOTIF_ALL, NULL, MSG_INFO, INFO_QUIT_SPECTATE, this.netname);
                if(!intermission_running)
                if(autocvar_g_chat_nospectators == 1 || (!(warmup_stage || gameover) && autocvar_g_chat_nospectators == 2))
                        Send_Notification(NOTIF_ONE_ONLY, this, MSG_INFO, INFO_CHAT_NOSPECTATORS);
@@ -441,8 +441,7 @@ void FixPlayermodel(entity player)
 
 /** Called when a client spawns in the server */
 void PutClientInServer()
-{
-       SELFPARAM(); // needed for engine functions
+{ENGINE_EVENT();
        if (IS_BOT_CLIENT(this)) {
                TRANSMUTE(Player, this);
        } else if (IS_REAL_CLIENT(this)) {
@@ -711,7 +710,7 @@ void ClientInit_Spawn()
        setthink(e, ClientInit_CheckUpdate);
        Net_LinkEntity(e, false, 0, ClientInit_SendEntity);
 
-       WITHSELF(e, ClientInit_CheckUpdate(e));
+       ClientInit_CheckUpdate(e);
 }
 
 /*
@@ -733,7 +732,7 @@ SetChangeParms
 =============
 */
 void SetChangeParms ()
-{SELFPARAM(); // needed for engine functions
+{ENGINE_EVENT();
        // save parms for level change
        parm1 = this.parm_idlesince - time;
 
@@ -799,7 +798,7 @@ void ClientKill_Now(entity this)
        if(this.killindicator && !wasfreed(this.killindicator))
                remove(this.killindicator);
 
-       this.killindicator = world;
+       this.killindicator = NULL;
 
        if(this.killindicator_teamchange)
                ClientKill_Now_TeamChange(this);
@@ -813,14 +812,14 @@ void KillIndicator_Think(entity this)
 {
        if (gameover)
        {
-               this.owner.killindicator = world;
+               this.owner.killindicator = NULL;
                remove(this);
                return;
        }
 
        if (this.owner.alpha < 0 && !this.owner.vehicle)
        {
-               this.owner.killindicator = world;
+               this.owner.killindicator = NULL;
                remove(this);
                return;
        }
@@ -897,7 +896,7 @@ void ClientKill_TeamChange (entity this, float targetteam) // 0 = don't change,
                        this.killindicator.count = bound(0, ceil(killtime), 10);
                        //sprint(this, strcat("^1You'll be dead in ", ftos(this.killindicator.cnt), " seconds\n"));
 
-                       for(e = world; (e = find(e, classname, "body")) != world; )
+                       for(e = NULL; (e = find(e, classname, "body")) != NULL; )
                        {
                                if(e.enemy != this)
                                        continue;
@@ -949,7 +948,7 @@ void ClientKill_TeamChange (entity this, float targetteam) // 0 = don't change,
 }
 
 void ClientKill ()
-{SELFPARAM(); // needed for engine functions
+{ENGINE_EVENT();
        if(gameover) return;
        if(this.player_blocked) return;
        if(STAT(FROZEN, this)) return;
@@ -999,7 +998,7 @@ Called once (not at each match start) when a client begins a connection to the s
 =============
 */
 void ClientPreConnect ()
-{SELFPARAM(); // needed for engine functions
+{ENGINE_EVENT();
        if(autocvar_sv_eventlog)
        {
                GameLogEcho(sprintf(":connect:%d:%d:%s",
@@ -1019,8 +1018,7 @@ Called when a client connects to the server
 =============
 */
 void ClientConnect()
-{
-       SELFPARAM(); // needed for engine functions
+{ENGINE_EVENT();
        if (Ban_MaybeEnforceBanOnce(this)) return;
        assert(!IS_CLIENT(this), return);
        this.flags |= FL_CLIENT;
@@ -1176,8 +1174,7 @@ Called when a client disconnects from the server
 .entity chatbubbleentity;
 void ReadyCount();
 void ClientDisconnect()
-{
-       SELFPARAM(); // needed for engine functions
+{ENGINE_EVENT();
        assert(IS_CLIENT(this), return);
 
        PlayerStats_GameReport_FinalizePlayer(this);
@@ -1188,7 +1185,7 @@ void ClientDisconnect()
        if (autocvar_sv_eventlog)
                GameLogEcho(strcat(":part:", ftos(this.playerid)));
 
-       Send_Notification(NOTIF_ALL, world, MSG_INFO, INFO_QUIT_DISCONNECT, this.netname);
+       Send_Notification(NOTIF_ALL, NULL, MSG_INFO, INFO_QUIT_DISCONNECT, this.netname);
 
     MUTATOR_CALLHOOK(ClientDisconnect, this);
 
@@ -1226,8 +1223,8 @@ void ChatBubbleThink(entity this)
        this.nextthink = time;
        if ((this.owner.alpha < 0) || this.owner.chatbubbleentity != this)
        {
-               if(this.owner) // but why can that ever be world?
-                       this.owner.chatbubbleentity = world;
+               if(this.owner) // but why can that ever be NULL?
+                       this.owner.chatbubbleentity = NULL;
                remove(this);
                return;
        }
@@ -1304,7 +1301,7 @@ void respawn(entity this)
        CopyBody(this, 1);
 
        this.effects |= EF_NODRAW; // prevent another CopyBody
-       PutClientInServer();
+       WITHSELF(this, PutClientInServer());
 }
 
 void play_countdown(entity this, float finished, Sound samp)
@@ -1343,7 +1340,7 @@ void player_powerups(entity this)
                        if (time > this.strength_finished)
                        {
                                this.items = this.items - (this.items & ITEM_Strength.m_itemid);
-                               //Send_Notification(NOTIF_ALL, world, MSG_INFO, INFO_POWERDOWN_STRENGTH, this.netname);
+                               //Send_Notification(NOTIF_ALL, NULL, MSG_INFO, INFO_POWERDOWN_STRENGTH, this.netname);
                                Send_Notification(NOTIF_ONE, this, MSG_CENTER, CENTER_POWERDOWN_STRENGTH);
                        }
                }
@@ -1352,7 +1349,7 @@ void player_powerups(entity this)
                        if (time < this.strength_finished)
                        {
                                this.items = this.items | ITEM_Strength.m_itemid;
-                               Send_Notification(NOTIF_ALL, world, MSG_INFO, INFO_POWERUP_STRENGTH, this.netname);
+                               Send_Notification(NOTIF_ALL, NULL, MSG_INFO, INFO_POWERUP_STRENGTH, this.netname);
                                Send_Notification(NOTIF_ONE, this, MSG_CENTER, CENTER_POWERUP_STRENGTH);
                        }
                }
@@ -1363,7 +1360,7 @@ void player_powerups(entity this)
                        if (time > this.invincible_finished)
                        {
                                this.items = this.items - (this.items & ITEM_Shield.m_itemid);
-                               //Send_Notification(NOTIF_ALL, world, MSG_INFO, INFO_POWERDOWN_SHIELD, this.netname);
+                               //Send_Notification(NOTIF_ALL, NULL, MSG_INFO, INFO_POWERDOWN_SHIELD, this.netname);
                                Send_Notification(NOTIF_ONE, this, MSG_CENTER, CENTER_POWERDOWN_SHIELD);
                        }
                }
@@ -1372,7 +1369,7 @@ void player_powerups(entity this)
                        if (time < this.invincible_finished)
                        {
                                this.items = this.items | ITEM_Shield.m_itemid;
-                               Send_Notification(NOTIF_ALL, world, MSG_INFO, INFO_POWERUP_SHIELD, this.netname);
+                               Send_Notification(NOTIF_ALL, NULL, MSG_INFO, INFO_POWERUP_SHIELD, this.netname);
                                Send_Notification(NOTIF_ONE, this, MSG_CENTER, CENTER_POWERUP_SHIELD);
                        }
                }
@@ -1382,7 +1379,7 @@ void player_powerups(entity this)
                        {
                                this.superweapons_finished = 0;
                                this.items = this.items - (this.items & IT_SUPERWEAPON);
-                               //Send_Notification(NOTIF_ALL, world, MSG_INFO, INFO_SUPERWEAPON_LOST, this.netname);
+                               //Send_Notification(NOTIF_ALL, NULL, MSG_INFO, INFO_SUPERWEAPON_LOST, this.netname);
                                Send_Notification(NOTIF_ONE, this, MSG_CENTER, CENTER_SUPERWEAPON_LOST);
                        }
                        else if (this.items & IT_UNLIMITED_SUPERWEAPONS)
@@ -1396,7 +1393,7 @@ void player_powerups(entity this)
                                {
                                        this.items = this.items - (this.items & IT_SUPERWEAPON);
                                        this.weapons &= ~WEPSET_SUPERWEAPONS;
-                                       //Send_Notification(NOTIF_ALL, world, MSG_INFO, INFO_SUPERWEAPON_BROKEN, this.netname);
+                                       //Send_Notification(NOTIF_ALL, NULL, MSG_INFO, INFO_SUPERWEAPON_BROKEN, this.netname);
                                        Send_Notification(NOTIF_ONE, this, MSG_CENTER, CENTER_SUPERWEAPON_BROKEN);
                                }
                        }
@@ -1406,7 +1403,7 @@ void player_powerups(entity this)
                        if (time < this.superweapons_finished || (this.items & IT_UNLIMITED_SUPERWEAPONS))
                        {
                                this.items = this.items | IT_SUPERWEAPON;
-                               Send_Notification(NOTIF_ALL, world, MSG_INFO, INFO_SUPERWEAPON_PICKUP, this.netname);
+                               Send_Notification(NOTIF_ALL, NULL, MSG_INFO, INFO_SUPERWEAPON_PICKUP, this.netname);
                                Send_Notification(NOTIF_ONE, this, MSG_CENTER, CENTER_SUPERWEAPON_PICKUP);
                        }
                        else
@@ -1483,18 +1480,28 @@ void player_regen(entity this)
 {
        float max_mod, regen_mod, rot_mod, limit_mod;
        max_mod = regen_mod = rot_mod = limit_mod = 1;
-       regen_mod_max = max_mod;
-       regen_mod_regen = regen_mod;
-       regen_mod_rot = rot_mod;
-       regen_mod_limit = limit_mod;
-
-       regen_health = autocvar_g_balance_health_regen;
-       regen_health_linear = autocvar_g_balance_health_regenlinear;
-       regen_health_rot = autocvar_g_balance_health_rot;
-       regen_health_rotlinear = autocvar_g_balance_health_rotlinear;
-       regen_health_stable = autocvar_g_balance_health_regenstable;
-       regen_health_rotstable = autocvar_g_balance_health_rotstable;
-       if(!MUTATOR_CALLHOOK(PlayerRegen))
+
+       float regen_health = autocvar_g_balance_health_regen;
+       float regen_health_linear = autocvar_g_balance_health_regenlinear;
+       float regen_health_rot = autocvar_g_balance_health_rot;
+       float regen_health_rotlinear = autocvar_g_balance_health_rotlinear;
+       float regen_health_stable = autocvar_g_balance_health_regenstable;
+       float regen_health_rotstable = autocvar_g_balance_health_rotstable;
+       bool mutator_returnvalue = MUTATOR_CALLHOOK(PlayerRegen, this, max_mod, regen_mod, rot_mod, limit_mod, regen_health, regen_health_linear, regen_health_rot,
+               regen_health_rotlinear, regen_health_stable, regen_health_rotstable);
+       max_mod = M_ARGV(1, float);
+       regen_mod = M_ARGV(2, float);
+       rot_mod = M_ARGV(3, float);
+       limit_mod = M_ARGV(4, float);
+       regen_health = M_ARGV(5, float);
+       regen_health_linear = M_ARGV(6, float);
+       regen_health_rot = M_ARGV(7, float);
+       regen_health_rotlinear = M_ARGV(8, float);
+       regen_health_stable = M_ARGV(9, float);
+       regen_health_rotstable = M_ARGV(10, float);
+
+
+       if(!mutator_returnvalue)
        if(!STAT(FROZEN, this))
        {
                float mina, maxa, limith, limita;
@@ -1503,11 +1510,6 @@ void player_regen(entity this)
                limith = autocvar_g_balance_health_limit;
                limita = autocvar_g_balance_armor_limit;
 
-               max_mod = regen_mod_max;
-               regen_mod = regen_mod_regen;
-               rot_mod = regen_mod_rot;
-               limit_mod = regen_mod_limit;
-
                regen_health_rotstable = regen_health_rotstable * max_mod;
                regen_health_stable = regen_health_stable * max_mod;
                limith = limith * limit_mod;
@@ -1798,7 +1800,7 @@ void LeaveSpectatorMode(entity this)
 
                        WITHSELF(this, PutClientInServer());
 
-                       if(IS_PLAYER(this)) { Send_Notification(NOTIF_ALL, world, MSG_INFO, ((teamplay && this.team != -1) ? APP_TEAM_ENT(this, INFO_JOIN_PLAY_TEAM) : INFO_JOIN_PLAY), this.netname); }
+                       if(IS_PLAYER(this)) { Send_Notification(NOTIF_ALL, NULL, MSG_INFO, ((teamplay && this.team != -1) ? APP_TEAM_ENT(this, INFO_JOIN_PLAY_TEAM) : INFO_JOIN_PLAY), this.netname); }
                }
                else
                        stuffcmd(this, "menu_showteamselect\n");
@@ -2024,7 +2026,7 @@ void PlayerUseKey(entity this)
                if(!IS_DEAD(this))
                if(!gameover)
                {
-                       entity head, closest_target = world;
+                       entity head, closest_target = NULL;
                        head = WarpZone_FindRadius(this.origin, autocvar_g_vehicles_enter_radius, true);
 
                        while(head) // find the closest acceptable target to enter
@@ -2036,7 +2038,7 @@ void PlayerUseKey(entity this)
                                {
                                        if(closest_target)
                                        {
-                                               if(vlen(this.origin - head.origin) < vlen(this.origin - closest_target.origin))
+                                               if(vlen2(this.origin - head.origin) < vlen2(this.origin - closest_target.origin))
                                                { closest_target = head; }
                                        }
                                        else { closest_target = head; }
@@ -2065,8 +2067,7 @@ Called every frame for each client before the physics are run
 .float last_vehiclecheck;
 .int items_added;
 void PlayerPreThink ()
-{
-    SELFPARAM(); // needed for engine functions
+{ENGINE_EVENT();
        WarpZone_PlayerPhysics_FixVAngle(this);
 
     STAT(GAMESTARTTIME, this) = game_starttime;
@@ -2154,26 +2155,27 @@ void PlayerPreThink ()
 
        MUTATOR_CALLHOOK(PlayerPreThink, this);
 
-       if(autocvar_g_vehicles_enter)
-       if(time > this.last_vehiclecheck)
-       if(IS_PLAYER(this))
-       if(!gameover)
-       if(!STAT(FROZEN, this))
-       if(!this.vehicle)
-       if(!IS_DEAD(this))
+       if(autocvar_g_vehicles_enter && (time > this.last_vehiclecheck) && !gameover && !this.vehicle)
+       if(IS_PLAYER(this) && !STAT(FROZEN, this) && !IS_DEAD(this))
        {
-               entity veh;
-               for(veh = world; (veh = findflags(veh, vehicle_flags, VHF_ISVEHICLE)); )
-               if(vlen(veh.origin - this.origin) < autocvar_g_vehicles_enter_radius)
-               if(!IS_DEAD(veh))
-               if(veh.takedamage != DAMAGE_NO)
-               if((veh.vehicle_flags & VHF_MULTISLOT) && SAME_TEAM(veh.owner, this))
-                       Send_Notification(NOTIF_ONE, this, MSG_CENTER, CENTER_VEHICLE_ENTER_GUNNER);
-               else if(!veh.owner)
-               if(!veh.team || SAME_TEAM(this, veh))
-                       Send_Notification(NOTIF_ONE, this, MSG_CENTER, CENTER_VEHICLE_ENTER);
-               else if(autocvar_g_vehicles_steal)
-                       Send_Notification(NOTIF_ONE, this, MSG_CENTER, CENTER_VEHICLE_ENTER_STEAL);
+               FOREACH_ENTITY_FLAGS(vehicle_flags, VHF_ISVEHICLE,
+               {
+                       if(!IS_DEAD(it) && it.takedamage != DAMAGE_NO)
+                       if(vdist(it.origin - this.origin, <, autocvar_g_vehicles_enter_radius))
+                       if((it.vehicle_flags & VHF_MULTISLOT) && SAME_TEAM(it.owner, this))
+                       {
+                               Send_Notification(NOTIF_ONE, this, MSG_CENTER, CENTER_VEHICLE_ENTER_GUNNER);
+                       }
+                       else if(!it.owner)
+                       {
+                               if(!it.team || SAME_TEAM(this, it))
+                                       Send_Notification(NOTIF_ONE, this, MSG_CENTER, CENTER_VEHICLE_ENTER);
+                       }
+                       else if(autocvar_g_vehicles_steal)
+                       {
+                               Send_Notification(NOTIF_ONE, this, MSG_CENTER, CENTER_VEHICLE_ENTER_STEAL);
+                       }
+               });
 
                this.last_vehiclecheck = time + 1;
        }
@@ -2400,7 +2402,7 @@ void DrownPlayer(entity this)
        {       // drown!
                if (this.pain_finished < time)
                {
-                       Damage (this, world, world, autocvar_g_balance_contents_playerdamage_drowning * autocvar_g_balance_contents_damagerate, DEATH_DROWN.m_id, this.origin, '0 0 0');
+                       Damage (this, NULL, NULL, autocvar_g_balance_contents_playerdamage_drowning * autocvar_g_balance_contents_damagerate, DEATH_DROWN.m_id, this.origin, '0 0 0');
                        this.pain_finished = time + 0.5;
                }
        }
@@ -2415,8 +2417,7 @@ Called every frame for each client after the physics are run
 */
 .float idlekick_lasttimeleft;
 void PlayerPostThink ()
-{
-    SELFPARAM(); // needed for engine functions
+{ENGINE_EVENT();
        if (sv_maxidle > 0)
        if (frametime) // WORKAROUND: only use dropclient in server frames (frametime set). Never use it in cl_movement frames (frametime zero).
        if (IS_REAL_CLIENT(this))
@@ -2438,7 +2439,7 @@ void PlayerPostThink ()
                                        Send_Notification(NOTIF_ONE_ONLY, this, MSG_CENTER, CENTER_DISCONNECT_IDLING, timeleft);
                        }
                        if (timeleft <= 0) {
-                               Send_Notification(NOTIF_ALL, world, MSG_INFO, INFO_QUIT_KICK_IDLING, this.netname);
+                               Send_Notification(NOTIF_ALL, NULL, MSG_INFO, INFO_QUIT_KICK_IDLING, this.netname);
                                dropclient(this);
                                return;
                        }