]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blobdiff - qcsrc/client/main.qc
Add a hack to fix the use of self in .predraw functions
[xonotic/xonotic-data.pk3dir.git] / qcsrc / client / main.qc
index 20f949bf3fc70b68f6e513c1412503a20531bc6d..464ae689a14186f20486fb35ad9de835eb72d418 100644 (file)
@@ -1,81 +1,57 @@
 #include "main.qh"
 
-#include "controlpoint.qh"
-#include "damage.qh"
-#include "effects.qh"
-#include "generator.qh"
-#include "gibs.qh"
-#include "hook.qh"
-#include "hud.qh"
-#include "hud_config.qh"
-#include "laser.qh"
+#include <common/effects/qc/all.qh>
+#include "hud/all.qh"
 #include "mapvoting.qh"
-#include "modeleffects.qh"
 #include "mutators/events.qh"
-#include "particles.qh"
 #include "quickmenu.qh"
 #include "scoreboard.qh"
 #include "shownames.qh"
-#include "tuba.qh"
-#include "t_items.qh"
+#include <common/t_items.qh>
 #include "wall.qh"
 #include "weapons/projectile.qh"
-#include "../common/deathtypes/all.qh"
-#include "../common/items/all.qh"
-#include "../common/mapinfo.qh"
-#include "../common/minigames/cl_minigames.qh"
-#include "../common/minigames/cl_minigames_hud.qh"
-#include "../common/net_notice.qh"
-#include "../common/triggers/include.qh"
-#include "../common/turrets/cl_turrets.qh"
-#include "../common/vehicles/all.qh"
-#include "../lib/csqcmodel/cl_model.qh"
-#include "../lib/csqcmodel/interpolate.qh"
-#include "../lib/warpzone/client.qh"
+#include <common/deathtypes/all.qh>
+#include <common/items/all.qh>
+#include <common/mapinfo.qh>
+#include <common/minigames/cl_minigames.qh>
+#include <common/minigames/cl_minigames_hud.qh>
+#include <common/net_notice.qh>
+#include <common/triggers/include.qh>
+#include <common/vehicles/all.qh>
+#include <lib/csqcmodel/cl_model.qh>
+#include <lib/csqcmodel/interpolate.qh>
+#include <lib/warpzone/client.qh>
 
 // --------------------------------------------------------------------------
 // BEGIN REQUIRED CSQC FUNCTIONS
 //include "main.qh"
 
-entity clearentity_ent;
-void clearentity(entity e)
-{
-       if (!clearentity_ent)
-       {
-               clearentity_ent = spawn();
-               clearentity_ent.classname = "clearentity";
-       }
-       int n = e.entnum;
-       copyentity(clearentity_ent, e);
-       e.entnum = n;
-}
-
 #define DP_CSQC_ENTITY_REMOVE_IS_B0RKED
-void menu_show_error()
-{
-       drawstring('0 200 0', _("ERROR - MENU IS VISIBLE BUT NO MENU WAS DEFINED!"), '8 8 0', '1 0 0', 1, 0);
-}
 
 // CSQC_Init : Called every time the CSQC code is initialized (essentially at map load)
 // Useful for precaching things
 
-void menu_sub_null()
-{
-}
-
-void draw_null(entity this) { }
-
-string forcefog;
 void ConsoleCommand_macro_init();
-void CSQC_Init(void)
+void CSQC_Init()
 {
        prvm_language = strzone(cvar_string("prvm_language"));
 
 #ifdef WATERMARK
-       LOG_TRACEF("^4CSQC Build information: ^1%s\n", WATERMARK);
+       LOG_INFOF("^4CSQC Build information: ^1%s\n", WATERMARK);
 #endif
 
-       int i;
+       {
+               int i = 0;
+               for ( ; i < 255; ++i)
+                       if (getplayerkeyvalue(i, "viewentity") == "")
+                               break;
+               maxclients = i;
+       }
+
+       // needs to be done so early because of the constants they create
+       static_init();
+       static_init_late();
+       static_init_precache();
 
        binddb = db_create();
        tempdb = db_create();
@@ -83,14 +59,6 @@ void CSQC_Init(void)
        compressShortVector_init();
 
        draw_endBoldFont();
-       menu_visible = false;
-       menu_show = menu_show_error;
-       menu_action = func_null;
-
-       for(i = 0; i < 255; ++i)
-               if(getplayerkeyvalue(i, "viewentity") == "")
-                       break;
-       maxclients = i;
 
        //registercommand("hud_configure");
        //registercommand("hud_save");
@@ -114,7 +82,7 @@ void CSQC_Init(void)
        gametype = 0;
 
        // hud_fields uses strunzone on the titles!
-       for(i = 0; i < MAX_HUD_FIELDS; ++i)
+       for(int i = 0; i < MAX_HUD_FIELDS; ++i)
                hud_title[i] = strzone("(null)");
 
        Cmd_HUD_SetFields(0);
@@ -128,48 +96,40 @@ void CSQC_Init(void)
 
        GetTeam(NUM_SPECTATOR, true); // add specs first
 
-       // needs to be done so early because of the constants they create
-       static_init();
-       static_init_late();
-       static_init_precache();
-
        // precaches
 
-       Projectile_Precache();
-       Tuba_Precache();
-
        if(autocvar_cl_reticle)
        {
                precache_pic("gfx/reticle_normal");
                // weapon reticles are precached in weapon files
        }
 
-       get_mi_min_max_texcoords(1); // try the CLEVER way first
-       minimapname = strcat("gfx/", mi_shortname, "_radar.tga");
-       shortmapname = mi_shortname;
-
-       if(precache_pic(minimapname) == "")
        {
-               // but maybe we have a non-clever minimap
-               minimapname = strcat("gfx/", mi_shortname, "_mini.tga");
-               if(precache_pic(minimapname) == "")
-                       minimapname = ""; // FAIL
-               else
-                       get_mi_min_max_texcoords(0); // load new texcoords
-       }
+               get_mi_min_max_texcoords(1); // try the CLEVER way first
+               minimapname = strcat("gfx/", mi_shortname, "_radar.tga");
+               shortmapname = mi_shortname;
 
-       mi_center = (mi_min + mi_max) * 0.5;
-       mi_scale = mi_max - mi_min;
-       minimapname = strzone(minimapname);
+               if (precache_pic(minimapname) == "")
+               {
+                       // but maybe we have a non-clever minimap
+                       minimapname = strcat("gfx/", mi_shortname, "_mini.tga");
+                       if (precache_pic(minimapname) == "")
+                               minimapname = ""; // FAIL
+                       else
+                               get_mi_min_max_texcoords(0); // load new texcoords
+               }
 
-       WarpZone_Init();
+               mi_center = (mi_min + mi_max) * 0.5;
+               mi_scale = mi_max - mi_min;
+               minimapname = strzone(minimapname);
+       }
 
        hud_skin_path = strzone(strcat("gfx/hud/", autocvar_hud_skin));
        draw_currentSkin = strzone(strcat("gfx/menu/", cvar_string("menu_skin")));
 }
 
 // CSQC_Shutdown : Called every time the CSQC code is shutdown (changing maps, quitting, etc)
-void Shutdown(void)
+void Shutdown()
 {
        WarpZone_Shutdown();
 
@@ -205,6 +165,7 @@ void Shutdown(void)
 .float has_team;
 float SetTeam(entity o, int Team)
 {
+       devassert_once(Team);
        entity tm;
        if(teamplay)
        {
@@ -275,13 +236,14 @@ float SetTeam(entity o, int Team)
 }
 
 void Playerchecker_Think()
-{SELFPARAM();
+{
+       SELFPARAM();
     int i;
        entity e;
        for(i = 0; i < maxclients; ++i)
        {
                e = playerslots[i];
-               if(GetPlayerName(i) == "")
+               if(entcs_GetName(i) == "")
                {
                        if(e.sort_prev)
                        {
@@ -298,27 +260,31 @@ void Playerchecker_Think()
                        {
                                // player connected
                                if (!e)
-                                       playerslots[i] = e = spawn();
+                               {
+                                       playerslots[i] = e = new(playerslot);
+                                       make_pure(e);
+                               }
                                e.sv_entnum = i;
                                e.ping = 0;
                                e.ping_packetloss = 0;
                                e.ping_movementloss = 0;
                                //e.gotscores = 0; // we might already have the scores...
-                               SetTeam(e, GetPlayerColor(i)); // will not hurt; later updates come with HUD_UpdatePlayerTeams
+                               int t = entcs_GetScoreTeam(i);
+                               if (t) SetTeam(e, t); // will not hurt; later updates come with HUD_UpdatePlayerTeams
                                RegisterPlayer(e);
                                HUD_UpdatePlayerPos(e);
                        }
                }
        }
-       self.nextthink = time + 0.2;
+       this.nextthink = time + 0.2;
 }
 
 void Porto_Init();
 void TrueAim_Init();
-void PostInit(void)
+void PostInit()
 {
-       entity playerchecker;
-       playerchecker = spawn();
+       entity playerchecker = new(playerchecker);
+       make_pure(playerchecker);
        playerchecker.think = Playerchecker_Think;
        playerchecker.nextthink = time + 0.2;
 
@@ -337,16 +303,13 @@ void PostInit(void)
 // In the case of mouse input after a setcursormode(1) call, nPrimary is xpos, nSecondary is ypos.
 float CSQC_InputEvent(float bInputType, float nPrimary, float nSecondary)
 {
-       float bSkipKey;
-       bSkipKey = false;
-
        if (HUD_Panel_InputEvent(bInputType, nPrimary, nSecondary))
                return true;
 
        if (QuickMenu_InputEvent(bInputType, nPrimary, nSecondary))
                return true;
 
-       if ( HUD_Radar_InputEvent(bInputType, nPrimary, nSecondary) )
+       if (HUD_Radar_InputEvent(bInputType, nPrimary, nSecondary))
                return true;
 
        if (MapVote_InputEvent(bInputType, nPrimary, nSecondary))
@@ -355,11 +318,7 @@ float CSQC_InputEvent(float bInputType, float nPrimary, float nSecondary)
        if (HUD_Minigame_InputEvent(bInputType, nPrimary, nSecondary))
                return true;
 
-       if(menu_visible && menu_action)
-               if(menu_action(bInputType, nPrimary, nSecondary))
-                       return true;
-
-       return bSkipKey;
+       return false;
 }
 
 // END REQUIRED CSQC FUNCTIONS
@@ -368,83 +327,64 @@ float CSQC_InputEvent(float bInputType, float nPrimary, float nSecondary)
 // --------------------------------------------------------------------------
 // BEGIN OPTIONAL CSQC FUNCTIONS
 
-void Ent_RemoveEntCS()
-{SELFPARAM();
-       entcs_receiver[self.sv_entnum] = NULL;
+.void(entity) predraw_qc;
+void PreDraw_self()
+{
+       if(self.predraw_qc)
+               self.predraw_qc(self);
 }
-void Ent_ReadEntCS()
-{SELFPARAM();
-       InterpolateOrigin_Undo();
-       self.classname = "entcs_receiver";
-       int sf = ReadByte();
-
-       if(sf & BIT(0))
-               self.sv_entnum = ReadByte();
-       if (sf & BIT(1))
-       {
-               self.origin_x = ReadShort();
-               self.origin_y = ReadShort();
-               self.origin_z = ReadShort();
-               setorigin(self, self.origin);
-       }
-       if (sf & BIT(2))
-       {
-               self.angles_y = ReadByte() * 360.0 / 256;
-               self.angles_x = self.angles_z = 0;
-       }
-       if (sf & BIT(3))
-               self.healthvalue = ReadByte() * 10;
-       if (sf & BIT(4))
-               self.armorvalue = ReadByte() * 10;
-
-       entcs_receiver[self.sv_entnum] = self;
-       self.entremove = Ent_RemoveEntCS;
-       self.iflags |= IFLAG_ORIGIN;
 
-       InterpolateOrigin_Note();
+void setpredraw(entity this, void(entity) pdfunc)
+{
+       this.predraw = PreDraw_self;
+       this.predraw_qc = pdfunc;
 }
 
-void Ent_Remove();
+void Ent_Remove(entity this);
 
-void Ent_RemovePlayerScore()
-{SELFPARAM();
-       if(self.owner) {
-               SetTeam(self.owner, -1);
-               self.owner.gotscores = 0;
+void Ent_RemovePlayerScore(entity this)
+{
+       if(this.owner) {
+               SetTeam(this.owner, -1);
+               this.owner.gotscores = 0;
                for(int i = 0; i < MAX_SCORE; ++i) {
-                       self.owner.(scores[i]) = 0; // clear all scores
+                       this.owner.(scores[i]) = 0; // clear all scores
                }
        }
 }
 
-void Ent_ReadPlayerScore()
-{SELFPARAM();
+NET_HANDLE(ENT_CLIENT_SCORES, bool isnew)
+{
+       make_pure(this);
        int i, n;
        bool isNew;
        entity o;
 
        // damnit -.- don't want to go change every single .sv_entnum in hud.qc AGAIN
        // (no I've never heard of M-x replace-string, sed, or anything like that)
-       isNew = !self.owner; // workaround for DP bug
+       isNew = !this.owner; // workaround for DP bug
        n = ReadByte()-1;
 
 #ifdef DP_CSQC_ENTITY_REMOVE_IS_B0RKED
-       if(!isNew && n != self.sv_entnum)
+       if(!isNew && n != this.sv_entnum)
        {
                //print("A CSQC entity changed its owner!\n");
-               LOG_INFOF("A CSQC entity changed its owner! (edict: %d, classname: %s)\n", num_for_edict(self), self.classname);
+               LOG_INFOF("A CSQC entity changed its owner! (edict: %d, classname: %s)\n", etof(this), this.classname);
                isNew = true;
-               Ent_Remove();
-               self.enttype = ENT_CLIENT_SCORES;
+               Ent_Remove(this);
        }
 #endif
 
-       self.sv_entnum = n;
+       this.sv_entnum = n;
 
-       if (!(playerslots[self.sv_entnum]))
-               playerslots[self.sv_entnum] = spawn();
-       o = self.owner = playerslots[self.sv_entnum];
-       o.sv_entnum = self.sv_entnum;
+       o = playerslots[this.sv_entnum];
+       if (!o)
+       {
+               o = playerslots[this.sv_entnum] = new(playerslot);
+               make_pure(o);
+       }
+       this.owner = o;
+       o.sv_entnum = this.sv_entnum;
        o.gotscores = 1;
 
        //if (!o.sort_prev)
@@ -469,19 +409,22 @@ void Ent_ReadPlayerScore()
                                o.(scores[i]) = ReadChar();
                }
 
+       return = true;
+
        if(o.sort_prev)
                HUD_UpdatePlayerPos(o); // if not registered, we cannot do this yet!
 
-       self.entremove = Ent_RemovePlayerScore;
+       this.entremove = Ent_RemovePlayerScore;
 }
 
-void Ent_ReadTeamScore()
-{SELFPARAM();
+NET_HANDLE(ENT_CLIENT_TEAMSCORES, bool isnew)
+{
+       make_pure(this);
        int i;
        entity o;
 
-       self.team = ReadByte();
-       o = self.owner = GetTeam(self.team, true); // these team numbers can always be trusted
+       this.team = ReadByte();
+       o = this.owner = GetTeam(this.team, true); // these team numbers can always be trusted
 
     int sf, lf;
 #if MAX_TEAMSCORE <= 8
@@ -501,11 +444,14 @@ void Ent_ReadTeamScore()
                                o.(teamscores[i]) = ReadChar();
                }
 
+       return = true;
+
        HUD_UpdateTeamPos(o);
 }
 
-void Ent_ClientData()
+NET_HANDLE(ENT_CLIENT_CLIENTDATA, bool isnew)
 {
+       make_pure(this);
        float newspectatee_status;
 
     int f = ReadByte();
@@ -533,6 +479,8 @@ void Ent_ClientData()
        else
                angles_held_status = 0;
 
+       return = true;
+
        if(newspectatee_status != spectatee_status)
        {
                // clear race stuff
@@ -553,8 +501,9 @@ void Ent_ClientData()
        // we could get rid of spectatee_status, and derive it from player_localentnum and player_localnum
 }
 
-void Ent_Nagger()
+NET_HANDLE(ENT_CLIENT_NAGGER, bool isnew)
 {
+       make_pure(this);
     int i, j, b, f;
 
     int nags = ReadByte(); // NAGS NAGS NAGS NAGS NAGS NAGS NADZ NAGS NAGS NAGS
@@ -601,6 +550,8 @@ void Ent_Nagger()
                }
        }
 
+       return = true;
+
        ready_waiting = (nags & BIT(0));
        ready_waiting_for_me = (nags & BIT(1));
        vote_waiting = (nags & BIT(2));
@@ -608,8 +559,9 @@ void Ent_Nagger()
        warmup_stage = (nags & BIT(4));
 }
 
-void Ent_EliminatedPlayers()
+NET_HANDLE(ENT_CLIENT_ELIMINATEDPLAYERS, bool isnew)
 {
+       make_pure(this);
     int i, j, b, f;
 
     int sf = ReadByte();
@@ -627,23 +579,26 @@ void Ent_EliminatedPlayers()
                                                playerslots[j].eliminated = 0;
                }
        }
+       return true;
 }
 
-void Ent_RandomSeed()
+NET_HANDLE(ENT_CLIENT_RANDOMSEED, bool isnew)
 {
-       float s;
+       make_pure(this);
        prandom_debug();
-       s = ReadShort();
+       float s = ReadShort();
        psrandom(s);
+       return true;
 }
 
-void Ent_ReadAccuracy()
+NET_HANDLE(ENT_CLIENT_ACCURACY, bool isnew)
 {
+       make_pure(this);
     int sf = ReadInt24_t();
        if (sf == 0) {
                for (int w = 0; w <= WEP_LAST - WEP_FIRST; ++w)
                        weapon_accuracy[w] = -1;
-               return;
+               return true;
        }
 
        int f = 1;
@@ -659,6 +614,7 @@ void Ent_ReadAccuracy()
                }
                f = (f == 0x800000) ? 1 : f * 2;
        }
+       return true;
 }
 
 void Spawn_Draw(entity this)
@@ -666,8 +622,8 @@ void Spawn_Draw(entity this)
        __pointparticles(this.cnt, this.origin + '0 0 28', '0 0 2', bound(0, frametime, 0.1));
 }
 
-void Ent_ReadSpawnPoint(float is_new) // entity for spawnpoint
-{SELFPARAM();
+NET_HANDLE(ENT_CLIENT_SPAWNPOINT, bool is_new)
+{
        float teamnum = (ReadByte() - 1);
        vector spn_origin;
        spn_origin.x = ReadShort();
@@ -676,19 +632,19 @@ void Ent_ReadSpawnPoint(float is_new) // entity for spawnpoint
 
        //if(is_new)
        //{
-               self.origin = spn_origin;
-               setsize(self, PL_MIN_CONST, PL_MAX_CONST);
+               this.origin = spn_origin;
+               setsize(this, PL_MIN_CONST, PL_MAX_CONST);
                //droptofloor();
 
                /*if(autocvar_cl_spawn_point_model) // needs a model first
                {
-                       self.mdl = "models/spawnpoint.md3";
-                       self.colormod = Team_ColorRGB(teamnum);
-                       precache_model(self.mdl);
-                       setmodel(self, self.mdl);
-                       self.drawmask = MASK_NORMAL;
-                       //self.movetype = MOVETYPE_NOCLIP;
-                       //self.draw = Spawn_Draw;
+                       this.mdl = "models/spawnpoint.md3";
+                       this.colormod = Team_ColorRGB(teamnum);
+                       precache_model(this.mdl);
+                       setmodel(this, this.mdl);
+                       this.drawmask = MASK_NORMAL;
+                       //this.movetype = MOVETYPE_NOCLIP;
+                       //this.draw = Spawn_Draw;
                }*/
                if(autocvar_cl_spawn_point_particles)
                {
@@ -696,24 +652,25 @@ void Ent_ReadSpawnPoint(float is_new) // entity for spawnpoint
                        {
                                switch(teamnum)
                                {
-                                       case NUM_TEAM_1: self.cnt = particleeffectnum(EFFECT_SPAWNPOINT_RED); break;
-                                       case NUM_TEAM_2: self.cnt = particleeffectnum(EFFECT_SPAWNPOINT_BLUE); break;
-                                       case NUM_TEAM_3: self.cnt = particleeffectnum(EFFECT_SPAWNPOINT_YELLOW); break;
-                                       case NUM_TEAM_4: self.cnt = particleeffectnum(EFFECT_SPAWNPOINT_PINK); break;
-                                       default: self.cnt = particleeffectnum(EFFECT_SPAWNPOINT_NEUTRAL); break;
+                                       case NUM_TEAM_1: this.cnt = particleeffectnum(EFFECT_SPAWNPOINT_RED); break;
+                                       case NUM_TEAM_2: this.cnt = particleeffectnum(EFFECT_SPAWNPOINT_BLUE); break;
+                                       case NUM_TEAM_3: this.cnt = particleeffectnum(EFFECT_SPAWNPOINT_YELLOW); break;
+                                       case NUM_TEAM_4: this.cnt = particleeffectnum(EFFECT_SPAWNPOINT_PINK); break;
+                                       default: this.cnt = particleeffectnum(EFFECT_SPAWNPOINT_NEUTRAL); break;
                                }
                        }
-                       else { self.cnt = particleeffectnum(EFFECT_SPAWNPOINT_NEUTRAL); }
+                       else { this.cnt = particleeffectnum(EFFECT_SPAWNPOINT_NEUTRAL); }
 
-                       self.draw = Spawn_Draw;
+                       this.draw = Spawn_Draw;
                }
        //}
 
-       //printf("Ent_ReadSpawnPoint(is_new = %d); origin = %s, team = %d, effect = %d\n", is_new, vtos(self.origin), teamnum, self.cnt);
+       //printf("Ent_ReadSpawnPoint(is_new = %d); origin = %s, team = %d, effect = %d\n", is_new, vtos(this.origin), teamnum, this.cnt);
+       return true;
 }
 
-void Ent_ReadSpawnEvent(float is_new)
-{SELFPARAM();
+NET_HANDLE(ENT_CLIENT_SPAWNEVENT, bool is_new)
+{
        // If entnum is 0, ONLY do the local spawn actions
        // this way the server can disable the sending of
        // spawn origin or such to clients if wanted.
@@ -721,31 +678,32 @@ void Ent_ReadSpawnEvent(float is_new)
 
        if(entnum)
        {
-               self.origin_x = ReadShort();
-               self.origin_y = ReadShort();
-               self.origin_z = ReadShort();
+               this.origin_x = ReadShort();
+               this.origin_y = ReadShort();
+               this.origin_z = ReadShort();
 
                if(is_new)
                {
-                       float teamnum = GetPlayerColor(entnum - 1);
+                       float teamnum = entcs_GetTeam(entnum - 1);
 
                        if(autocvar_cl_spawn_event_particles)
                        {
                                switch(teamnum)
                                {
-                                       case NUM_TEAM_1: pointparticles(EFFECT_SPAWN_RED, self.origin, '0 0 0', 1); break;
-                                       case NUM_TEAM_2: pointparticles(EFFECT_SPAWN_BLUE, self.origin, '0 0 0', 1); break;
-                                       case NUM_TEAM_3: pointparticles(EFFECT_SPAWN_YELLOW, self.origin, '0 0 0', 1); break;
-                                       case NUM_TEAM_4: pointparticles(EFFECT_SPAWN_PINK, self.origin, '0 0 0', 1); break;
-                                       default: pointparticles(EFFECT_SPAWN_NEUTRAL, self.origin, '0 0 0', 1); break;
+                                       case NUM_TEAM_1: pointparticles(EFFECT_SPAWN_RED, this.origin, '0 0 0', 1); break;
+                                       case NUM_TEAM_2: pointparticles(EFFECT_SPAWN_BLUE, this.origin, '0 0 0', 1); break;
+                                       case NUM_TEAM_3: pointparticles(EFFECT_SPAWN_YELLOW, this.origin, '0 0 0', 1); break;
+                                       case NUM_TEAM_4: pointparticles(EFFECT_SPAWN_PINK, this.origin, '0 0 0', 1); break;
+                                       default: pointparticles(EFFECT_SPAWN_NEUTRAL, this.origin, '0 0 0', 1); break;
                                }
                        }
                        if(autocvar_cl_spawn_event_sound)
                        {
-                               sound(self, CH_TRIGGER, SND_SPAWN, VOL_BASE, ATTEN_NORM);
+                               sound(this, CH_TRIGGER, SND_SPAWN, VOL_BASE, ATTEN_NORM);
                        }
                }
        }
+       return = true;
 
        // local spawn actions
        if(is_new && (!entnum || (entnum == player_localentnum)))
@@ -760,21 +718,17 @@ void Ent_ReadSpawnEvent(float is_new)
                }
        }
        HUD_Radar_Hide_Maximized();
-       //printf("Ent_ReadSpawnEvent(is_new = %d); origin = %s, entnum = %d, localentnum = %d\n", is_new, vtos(self.origin), entnum, player_localentnum);
+       //printf("Ent_ReadSpawnEvent(is_new = %d); origin = %s, entnum = %d, localentnum = %d\n", is_new, vtos(this.origin), entnum, player_localentnum);
 }
 
 // CSQC_Ent_Update : Called every frame that the server has indicated an update to the SSQC / CSQC entity has occured.
 // The only parameter reflects if the entity is "new" to the client, meaning it just came into the client's PVS.
-void Ent_RadarLink();
-void Ent_Init();
-void Ent_ScoresInfo();
-void CSQC_Ent_Update(float bIsNewEntity)
-{SELFPARAM();
+void CSQC_Ent_Update(bool isnew)
+{
+       SELFPARAM();
+       this.sourceLoc = __FILE__ ":" STR(__LINE__);
        int t = ReadByte();
 
-       if(autocvar_developer_csqcentities)
-               LOG_INFOF("CSQC_Ent_Update(%d) with self=%i self.entnum=%d self.enttype=%d t=%d\n", bIsNewEntity, self, self.entnum, self.enttype, t);
-
        // set up the "time" global for received entities to be correct for interpolation purposes
        float savetime = time;
        if(servertime)
@@ -784,148 +738,83 @@ void CSQC_Ent_Update(float bIsNewEntity)
        else
        {
                serverprevtime = time;
-               serverdeltatime = getstatf(STAT_MOVEVARS_TICRATE) * getstatf(STAT_MOVEVARS_TIMESCALE);
+               serverdeltatime = STAT(MOVEVARS_TICRATE) * STAT(MOVEVARS_TIMESCALE);
                time = serverprevtime + serverdeltatime;
        }
 
 #ifdef DP_CSQC_ENTITY_REMOVE_IS_B0RKED
-       if(self.enttype)
+       if (this.enttype)
        {
-               if(t != self.enttype || bIsNewEntity)
+               if (t != this.enttype || isnew)
                {
-                       LOG_INFOF("A CSQC entity changed its type! (edict: %d, server: %d, type: %d -> %d)\n", num_for_edict(self), self.entnum, self.enttype, t);
-                       Ent_Remove();
-                       clearentity(self);
-                       bIsNewEntity = 1;
+                       LOG_INFOF("A CSQC entity changed its type! (edict: %d, server: %d, type: %d -> %d)\n", etof(this), this.entnum, this.enttype, t);
+                       Ent_Remove(this);
+                       clearentity(this);
+                       isnew = true;
                }
        }
        else
        {
-               if(!bIsNewEntity)
+               if (!isnew)
                {
-                       LOG_INFOF("A CSQC entity appeared out of nowhere! (edict: %d, server: %d, type: %d)\n", num_for_edict(self), self.entnum, t);
-                       bIsNewEntity = 1;
+                       LOG_INFOF("A CSQC entity appeared out of nowhere! (edict: %d, server: %d, type: %d)\n", etof(this), this.entnum, t);
+                       isnew = true;
                }
        }
 #endif
-       self.enttype = t;
+       this.enttype = t;
        bool done = false;
        FOREACH(LinkedEntities, it.m_id == t, LAMBDA(
-               it.m_read(self, bIsNewEntity);
-               done = true;
+               if (isnew) this.classname = it.netname;
+               if (autocvar_developer_csqcentities)
+            LOG_INFOF("CSQC_Ent_Update(%d) at %f with this=%i {.entnum=%d, .enttype=%d} t=%s (%d)\n", isnew, savetime, this, this.entnum, this.enttype, this.classname, t);
+               done = it.m_read(this, NULL, isnew);
                break;
        ));
+       time = savetime;
        if (!done)
-       switch(t)
        {
-               case ENT_CLIENT_MUTATOR: {
-                       int mutID = ReadMutator();
-                       if (!MUTATOR_CALLHOOK(CSQC_Ent_Update, mutID, bIsNewEntity))
-                       error(sprintf("Unknown mutator type in CSQC_Ent_Update (mutID: %d, edict: %d, classname: %s)\n", mutID, num_for_edict(self), self.classname));
-                       break;
-               }
-               case ENT_CLIENT_ENTCS: Ent_ReadEntCS(); break;
-               case ENT_CLIENT_SCORES: Ent_ReadPlayerScore(); break;
-               case ENT_CLIENT_TEAMSCORES: Ent_ReadTeamScore(); break;
-               case ENT_CLIENT_POINTPARTICLES: Ent_PointParticles(); break;
-               case ENT_CLIENT_RAINSNOW: Ent_RainOrSnow(); break;
-               case ENT_CLIENT_LASER: Ent_Laser(); break;
-               case ENT_CLIENT_NAGGER: Ent_Nagger(); break;
-               case ENT_CLIENT_ELIMINATEDPLAYERS: Ent_EliminatedPlayers(); break;
-               case ENT_CLIENT_RADARLINK: Ent_RadarLink(); break;
-               case ENT_CLIENT_PROJECTILE: Ent_Projectile(); break;
-               case ENT_CLIENT_GIBSPLASH: Ent_GibSplash(bIsNewEntity); break;
-               case ENT_CLIENT_DAMAGEINFO: Ent_DamageInfo(bIsNewEntity); break;
-               case ENT_CLIENT_INIT: Ent_Init(); break;
-               case ENT_CLIENT_SCORES_INFO: Ent_ScoresInfo(); break;
-               case ENT_CLIENT_MAPVOTE: Ent_MapVote(); break;
-               case ENT_CLIENT_CLIENTDATA: Ent_ClientData(); break;
-               case ENT_CLIENT_RANDOMSEED: Ent_RandomSeed(); break;
-               case ENT_CLIENT_WALL: Ent_Wall(); break;
-               case ENT_CLIENT_MODELEFFECT: Ent_ModelEffect(bIsNewEntity); break;
-               case ENT_CLIENT_TUBANOTE: Ent_TubaNote(bIsNewEntity); break;
-               case ENT_CLIENT_WARPZONE: WarpZone_Read(bIsNewEntity); break;
-               case ENT_CLIENT_WARPZONE_CAMERA: WarpZone_Camera_Read(bIsNewEntity); break;
-               case ENT_CLIENT_WARPZONE_TELEPORTED: WarpZone_Teleported_Read(bIsNewEntity); break;
-               case ENT_CLIENT_TRIGGER_MUSIC: Ent_ReadTriggerMusic(); break;
-               case ENT_CLIENT_HOOK: Ent_ReadHook(bIsNewEntity, ENT_CLIENT_HOOK); break;
-               case ENT_CLIENT_INVENTORY: Inventory_Read(self); break;
-               case ENT_CLIENT_ARC_BEAM: Ent_ReadArcBeam(bIsNewEntity); break;
-               case ENT_CLIENT_ACCURACY: Ent_ReadAccuracy(); break;
-               case ENT_CLIENT_AUXILIARYXHAIR: Net_AuXair2(bIsNewEntity); break;
-               case ENT_CLIENT_TURRET: ent_turret(); break;
-               case ENT_CLIENT_GENERATOR: ent_generator(); break;
-               case ENT_CLIENT_CONTROLPOINT_ICON: ent_cpicon(this); break;
-               case ENT_CLIENT_MODEL: CSQCModel_Read(bIsNewEntity); break;
-               case ENT_CLIENT_ITEM: ItemRead(bIsNewEntity); break;
-               case ENT_CLIENT_BUMBLE_RAYGUN: bumble_raygun_read(bIsNewEntity); break;
-               case ENT_CLIENT_SPAWNPOINT: Ent_ReadSpawnPoint(bIsNewEntity); break;
-               case ENT_CLIENT_SPAWNEVENT: Ent_ReadSpawnEvent(bIsNewEntity); break;
-               case ENT_CLIENT_NOTIFICATION: Read_Notification(bIsNewEntity); break;
-               case ENT_CLIENT_MINIGAME: ent_read_minigame(); break;
-               case ENT_CLIENT_VIEWLOC: ent_viewloc(); break;
-               case ENT_CLIENT_VIEWLOC_TRIGGER: ent_viewloc_trigger(); break;
-               case ENT_CLIENT_LADDER: ent_func_ladder(); break;
-               case ENT_CLIENT_TRIGGER_PUSH: ent_trigger_push(); break;
-               case ENT_CLIENT_TARGET_PUSH: ent_target_push(); break;
-               case ENT_CLIENT_CONVEYOR: ent_conveyor(); break;
-               case ENT_CLIENT_DOOR: ent_door(); break;
-               case ENT_CLIENT_PLAT: ent_plat(); break;
-               case ENT_CLIENT_SWAMP: ent_swamp(); break;
-               case ENT_CLIENT_CORNER: ent_corner(); break;
-               case ENT_CLIENT_KEYLOCK: ent_keylock(); break;
-               case ENT_CLIENT_TRAIN: ent_train(); break;
-               case ENT_CLIENT_TRIGGER_IMPULSE: ent_trigger_impulse(); break;
-               case ENT_CLIENT_EFFECT: Read_Effect(bIsNewEntity); break;
-
-               default:
-                       //error(strcat(_("unknown entity type in CSQC_Ent_Update: %d\n"), self.enttype));
-                       error(sprintf("Unknown entity type in CSQC_Ent_Update (enttype: %d, edict: %d, classname: %s)\n", self.enttype, num_for_edict(self), self.classname));
-                       break;
+               LOG_FATALF("CSQC_Ent_Update(%d) at %f with this=%i {.entnum=%d, .enttype=%d} t=%s (%d)\n", isnew, savetime, this, this.entnum, this.enttype, this.classname, t);
        }
-
-       time = savetime;
 }
+
 // Destructor, but does NOT deallocate the entity by calling remove(). Also
 // used when an entity changes its type. For an entity that someone interacts
 // with others, make sure it can no longer do so.
-void Ent_Remove()
-{SELFPARAM();
-       if(self.entremove)
-               self.entremove();
+void Ent_Remove(entity this)
+{
+       if(this.entremove) this.entremove(this);
 
-       if(self.skeletonindex)
+       if(this.skeletonindex)
        {
-               skel_delete(self.skeletonindex);
-               self.skeletonindex = 0;
+               skel_delete(this.skeletonindex);
+               this.skeletonindex = 0;
        }
 
-       if(self.snd_looping > 0)
+       if(this.snd_looping > 0)
        {
-               sound(self, self.snd_looping, SND_Null, VOL_BASE, autocvar_g_jetpack_attenuation);
-               self.snd_looping = 0;
+               sound(this, this.snd_looping, SND_Null, VOL_BASE, autocvar_g_jetpack_attenuation);
+               this.snd_looping = 0;
        }
 
-       self.enttype = 0;
-       self.classname = "";
-       self.draw = draw_null;
-       self.entremove = menu_sub_null;
+       this.enttype = 0;
+       this.classname = "";
+       this.draw = func_null;
+       this.entremove = func_null;
        // TODO possibly set more stuff to defaults
 }
-// CSQC_Ent_Remove : Called when the server requests a SSQC / CSQC entity to be removed.  Essentially call remove(self) as well.
+// CSQC_Ent_Remove : Called when the server requests a SSQC / CSQC entity to be removed.  Essentially call remove(this) as well.
 void CSQC_Ent_Remove()
-{SELFPARAM();
-       if(autocvar_developer_csqcentities)
-               LOG_INFOF("CSQC_Ent_Remove() with self=%i self.entnum=%d self.enttype=%d\n", self, self.entnum, self.enttype);
-
-       if(wasfreed(self))
+{
+       SELFPARAM();
+       if (autocvar_developer_csqcentities) LOG_INFOF("CSQC_Ent_Remove() with this=%i {.entnum=%d, .enttype=%d}\n", this, this.entnum, this.enttype);
+       if (wasfreed(this))
        {
-               LOG_INFO("WARNING: CSQC_Ent_Remove called for already removed entity. Packet loss?\n");
+               LOG_WARNING("CSQC_Ent_Remove called for already removed entity. Packet loss?\n");
                return;
        }
-       if(self.enttype)
-               Ent_Remove();
-       remove(self);
+       if (this.enttype) Ent_Remove(this);
+       remove(this);
 }
 
 void Gamemode_Init()
@@ -940,70 +829,79 @@ void Gamemode_Init()
 // CSQC_Parse_StuffCmd : Provides the stuffcmd string in the first parameter that the server provided.  To execute standard behavior, simply execute localcmd with the string.
 void CSQC_Parse_StuffCmd(string strMessage)
 {
-       if(autocvar_developer_csqcentities)
-               LOG_INFOF("CSQC_Parse_StuffCmd(\"%s\")\n", strMessage);
-
+       if (autocvar_developer_csqcentities) LOG_INFOF("CSQC_Parse_StuffCmd(\"%s\")\n", strMessage);
        localcmd(strMessage);
 }
 // CSQC_Parse_Print : Provides the print string in the first parameter that the server provided.  To execute standard behavior, simply execute print with the string.
 void CSQC_Parse_Print(string strMessage)
 {
-       if(autocvar_developer_csqcentities)
-               LOG_INFOF("CSQC_Parse_Print(\"%s\")\n", strMessage);
-
+       if (autocvar_developer_csqcentities) LOG_INFOF("CSQC_Parse_Print(\"%s\")\n", strMessage);
        print(ColorTranslateRGB(strMessage));
 }
 
 // CSQC_Parse_CenterPrint : Provides the centerprint_hud string in the first parameter that the server provided.
 void CSQC_Parse_CenterPrint(string strMessage)
 {
-       if(autocvar_developer_csqcentities)
-               LOG_INFOF("CSQC_Parse_CenterPrint(\"%s\")\n", strMessage);
-
+       if (autocvar_developer_csqcentities) LOG_INFOF("CSQC_Parse_CenterPrint(\"%s\")\n", strMessage);
        centerprint_hud(strMessage);
 }
 
-string notranslate_fogcmd1 = "\nfog ";
-string notranslate_fogcmd2 = "\nr_fog_exp2 0\nr_drawfog 1\n";
-void Fog_Force()
+// CSQC_Parse_TempEntity : Handles all temporary entity network data in the CSQC layer.
+// You must ALWAYS first acquire the temporary ID, which is sent as a byte.
+// Return value should be 1 if CSQC handled the temporary entity, otherwise return 0 to have the engine process the event.
+bool CSQC_Parse_TempEntity()
 {
-       // TODO somehow thwart prvm_globalset client ...
+       // Acquire TE ID
+       int nTEID = ReadByte();
+
+       FOREACH(TempEntities, it.m_id == nTEID, LAMBDA(
+               if (autocvar_developer_csqcentities)
+                       LOG_INFOF("CSQC_Parse_TempEntity() nTEID=%s (%d)\n", it.netname, nTEID);
+               return it.m_read(NULL, NULL, true);
+       ));
 
-       if(autocvar_cl_orthoview && autocvar_cl_orthoview_nofog)
-               { localcmd("\nr_drawfog 0\n"); }
-       else if(forcefog != "")
-               { localcmd(strcat(notranslate_fogcmd1, forcefog, notranslate_fogcmd2)); }
+       if (autocvar_developer_csqcentities)
+               LOG_INFOF("CSQC_Parse_TempEntity() with nTEID=%d\n", nTEID);
+
+       // No special logic for this temporary entity; return 0 so the engine can handle it
+       return false;
+}
+
+/** TODO somehow thwart prvm_globalset client ... */
+string forcefog;
+void Fog_Force()
+{
+       if (autocvar_cl_orthoview && autocvar_cl_orthoview_nofog)
+               localcmd("\nr_drawfog 0\n");
+       else if (forcefog != "")
+               localcmd(sprintf("\nfog %s\nr_fog_exp2 0\nr_drawfog 1\n", forcefog));
 }
 
 void Gamemode_Init();
-void Ent_ScoresInfo()
-{SELFPARAM();
-    int i;
-       self.classname = "ent_client_scores_info";
+NET_HANDLE(ENT_CLIENT_SCORES_INFO, bool isnew)
+{
+       make_pure(this);
        gametype = ReadInt24_t();
        HUD_ModIcons_SetFunc();
-       for(i = 0; i < MAX_SCORE; ++i)
+       for (int i = 0; i < MAX_SCORE; ++i)
        {
-               if(scores_label[i])
-                       strunzone(scores_label[i]);
+               if (scores_label[i]) strunzone(scores_label[i]);
                scores_label[i] = strzone(ReadString());
                scores_flags[i] = ReadByte();
        }
-       for(i = 0; i < MAX_TEAMSCORE; ++i)
+       for (int i = 0; i < MAX_TEAMSCORE; ++i)
        {
-               if(teamscores_label[i])
-                       strunzone(teamscores_label[i]);
+               if (teamscores_label[i]) strunzone(teamscores_label[i]);
                teamscores_label[i] = strzone(ReadString());
                teamscores_flags[i] = ReadByte();
        }
+       return = true;
        HUD_InitScores();
        Gamemode_Init();
 }
 
-void Ent_Init()
-{SELFPARAM();
-       self.classname = "ent_client_init";
-
+NET_HANDLE(ENT_CLIENT_INIT, bool isnew)
+{
        nb_pb_period = ReadByte() / 32; //Accuracy of 1/32th
 
        hook_shotorigin[0] = decompressShotOrigin(ReadInt24_t());
@@ -1015,42 +913,27 @@ void Ent_Init()
        arc_shotorigin[2] = decompressShotOrigin(ReadInt24_t());
        arc_shotorigin[3] = decompressShotOrigin(ReadInt24_t());
 
-       if(forcefog)
-               strunzone(forcefog);
+       if (forcefog) strunzone(forcefog);
        forcefog = strzone(ReadString());
 
        armorblockpercent = ReadByte() / 255.0;
 
-       g_balance_mortar_bouncefactor = ReadCoord();
-       g_balance_mortar_bouncestop = ReadCoord();
-       g_balance_electro_secondary_bouncefactor = ReadCoord();
-       g_balance_electro_secondary_bouncestop = ReadCoord();
-
-       vortex_scope = !ReadByte();
-       rifle_scope = !ReadByte();
-
        serverflags = ReadByte();
 
-       minelayer_maxmines = ReadByte();
-
-       hagar_maxrockets = ReadByte();
-
        g_trueaim_minrange = ReadCoord();
-       g_balance_porto_secondary = ReadByte();
+
+       return = true;
 
        MUTATOR_CALLHOOK(Ent_Init);
 
-       if(!postinit)
-               PostInit();
+       if (!postinit) PostInit();
 }
 
-void Net_ReadRace()
+NET_HANDLE(TE_CSQC_RACE, bool isNew)
 {
-       float b;
-
-       b = ReadByte();
+       int b = ReadByte();
 
-       switch(b)
+       switch (b)
        {
                case RACE_NET_CHECKPOINT_HIT_QUALIFYING:
                        race_checkpoint = ReadByte();
@@ -1189,7 +1072,7 @@ void Net_ReadRace()
                                strunzone(grecordholder[pos-1]);
                        grecordholder[pos-1] = strzone(ReadString());
                        grecordtime[pos-1] = ReadInt24_t();
-                       if(grecordholder[pos-1] == GetPlayerName(player_localnum))
+                       if(grecordholder[pos-1] == entcs_GetName(player_localnum))
                                race_myrank = pos;
                        break;
                case RACE_NET_SERVER_STATUS:
@@ -1198,36 +1081,34 @@ void Net_ReadRace()
                                strunzone(race_status_name);
                        race_status_name = strzone(ReadString());
        }
+       return true;
 }
 
-void Net_TeamNagger()
+NET_HANDLE(TE_CSQC_TEAMNAGGER, bool isNew)
 {
        teamnagger = 1;
+       return true;
 }
 
-void Net_ReadPingPLReport()
+NET_HANDLE(TE_CSQC_PINGPLREPORT, bool isNew)
 {
-       int e, pi, pl, ml;
-       e = ReadByte();
-       pi = ReadShort();
-       pl = ReadByte();
-       ml = ReadByte();
-       if (!(playerslots[e]))
-               return;
-       playerslots[e].ping = pi;
-       playerslots[e].ping_packetloss = pl / 255.0;
-       playerslots[e].ping_movementloss = ml / 255.0;
+       int i = ReadByte();
+       int pi = ReadShort();
+       int pl = ReadByte();
+       int ml = ReadByte();
+       return = true;
+       entity e = playerslots[i];
+       if (!e) return;
+       e.ping = pi;
+       e.ping_packetloss = pl / 255.0;
+       e.ping_movementloss = ml / 255.0;
 }
 
-void Net_WeaponComplain()
+NET_HANDLE(TE_CSQC_WEAPONCOMPLAIN, bool isNew)
 {
        complain_weapon = ReadByte();
-
-       if(complain_weapon_name)
-               strunzone(complain_weapon_name);
-       complain_weapon_name = strzone(WEP_NAME(complain_weapon));
-
        complain_weapon_type = ReadByte();
+       return = true;
 
        complain_weapon_time = time;
        weapontime = time; // ping the weapon panel
@@ -1240,66 +1121,6 @@ void Net_WeaponComplain()
        }
 }
 
-// CSQC_Parse_TempEntity : Handles all temporary entity network data in the CSQC layer.
-// You must ALWAYS first acquire the temporary ID, which is sent as a byte.
-// Return value should be 1 if CSQC handled the temporary entity, otherwise return 0 to have the engine process the event.
-bool CSQC_Parse_TempEntity()
-{
-       // Acquire TE ID
-       int nTEID = ReadByte();
-
-       if (autocvar_developer_csqcentities)
-               LOG_INFOF("CSQC_Parse_TempEntity() with nTEID=%d\n", nTEID);
-
-       FOREACH(TempEntities, it.m_id == nTEID, LAMBDA(
-               it.m_read(NULL, true);
-               return true;
-       ));
-       switch (nTEID)
-       {
-               case TE_CSQC_MUTATOR:
-                       int mutID = ReadMutator();
-                       if (MUTATOR_CALLHOOK(CSQC_Parse_TempEntity, mutID))
-                       return true;
-               case TE_CSQC_TARGET_MUSIC:
-                       Net_TargetMusic();
-                       return true;
-               case TE_CSQC_PICTURE:
-                       Net_MapVote_Picture();
-                       return true;
-               case TE_CSQC_RACE:
-                       Net_ReadRace();
-                       return true;
-               case TE_CSQC_VORTEXBEAMPARTICLE:
-                       Net_ReadVortexBeamParticle();
-                       return true;
-               case TE_CSQC_TEAMNAGGER:
-                       Net_TeamNagger();
-                       return true;
-               case TE_CSQC_ARC:
-                       Net_ReadArc();
-                       return true;
-               case TE_CSQC_PINGPLREPORT:
-                       Net_ReadPingPLReport();
-                       return true;
-               case TE_CSQC_WEAPONCOMPLAIN:
-                       Net_WeaponComplain();
-                       return true;
-               case TE_CSQC_VEHICLESETUP:
-                       Net_VehicleSetup();
-                       return true;
-               case TE_CSQC_SVNOTICE:
-                       cl_notice_read();
-                       return true;
-               case TE_CSQC_SHOCKWAVEPARTICLE:
-                       Net_ReadShockwaveParticle();
-                       return true;
-               default:
-                       // No special logic for this temporary entity; return 0 so the engine can handle it
-                       return false;
-       }
-}
-
 string getcommandkey(string text, string command)
 {
        string keys;