X-Git-Url: https://de.git.xonotic.org/?p=xonotic%2Fxonotic-data.pk3dir.git;a=blobdiff_plain;f=qcsrc%2Fcommon%2Ftriggers%2Ftrigger%2Fviewloc.qc;h=9d675bbc734dbba6ad08ea4a549b005297b779cc;hp=b36b5eadb2f8f39c27f0f3aa33e9d1f93816d33b;hb=3220cab5a7b69ced4a641504a6a5f4eccf2d3bfc;hpb=b6b2f6f6a9fa502c524c474db6510bc998ba861a diff --git a/qcsrc/common/triggers/trigger/viewloc.qc b/qcsrc/common/triggers/trigger/viewloc.qc index b36b5eadb..9d675bbc7 100644 --- a/qcsrc/common/triggers/trigger/viewloc.qc +++ b/qcsrc/common/triggers/trigger/viewloc.qc @@ -1,181 +1,188 @@ #if defined(CSQC) #elif defined(MENUQC) #elif defined(SVQC) - #include "../../../dpdefs/progsdefs.qh" - #include "../../../warpzonelib/util_server.qh" - #include "../../../server/defs.qh" + #include + #include #endif +REGISTER_NET_LINKED(ENT_CLIENT_VIEWLOC) +REGISTER_NET_LINKED(ENT_CLIENT_VIEWLOC_TRIGGER) + #ifdef SVQC -void viewloc_think() +void viewloc_think(entity this) { entity e; // we abuse this method, rather than using normal .touch, because touch isn't reliable with multiple clients inside the same trigger, and can't "untouch" entities // set myself as current viewloc where possible - for(e = world; (e = findentity(e, viewloc, self)); ) - e.viewloc = world; + for(e = NULL; (e = findentity(e, viewloc, this)); ) + e.viewloc = NULL; - for(e = findradius((self.absmin + self.absmax) * 0.5, vlen(self.absmax - self.absmin) * 0.5 + 1); e; e = e.chain) + for(e = findradius((this.absmin + this.absmax) * 0.5, vlen(this.absmax - this.absmin) * 0.5 + 1); e; e = e.chain) if(!e.viewloc) if(IS_PLAYER(e)) // should we support non-player entities with this? - //if(e.deadflag == DEAD_NO) // death view is handled separately, we can't override this just yet + //if(!IS_DEAD(e)) // death view is handled separately, we can't override this just yet { vector emin = e.absmin; vector emax = e.absmax; - if(self.solid == SOLID_BSP) + if(this.solid == SOLID_BSP) { emin -= '1 1 1'; emax += '1 1 1'; } - if(boxesoverlap(emin, emax, self.absmin, self.absmax)) // quick - if(WarpZoneLib_BoxTouchesBrush(emin, emax, self, e)) // accurate - e.viewloc = self; + if(boxesoverlap(emin, emax, this.absmin, this.absmax)) // quick + if(WarpZoneLib_BoxTouchesBrush(emin, emax, this, e)) // accurate + e.viewloc = this; } - self.nextthink = time; + this.nextthink = time; } -bool trigger_viewloc_send(entity to, int sf) +bool trigger_viewloc_send(entity this, entity to, int sf) { // CSQC doesn't need to know our origin (yet), as we're only available for referencing - WriteByte(MSG_ENTITY, ENT_CLIENT_VIEWLOC_TRIGGER); + WriteHeader(MSG_ENTITY, ENT_CLIENT_VIEWLOC_TRIGGER); - WriteEntity(MSG_ENTITY, self.enemy); - WriteEntity(MSG_ENTITY, self.goalentity); + WriteEntity(MSG_ENTITY, this.enemy); + WriteEntity(MSG_ENTITY, this.goalentity); - WriteCoord(MSG_ENTITY, self.origin_x); - WriteCoord(MSG_ENTITY, self.origin_y); - WriteCoord(MSG_ENTITY, self.origin_z); + WriteCoord(MSG_ENTITY, this.origin_x); + WriteCoord(MSG_ENTITY, this.origin_y); + WriteCoord(MSG_ENTITY, this.origin_z); return true; } -void viewloc_init() +void viewloc_init(entity this) { entity e; - for(e = world; (e = find(e, targetname, self.target)); ) + for(e = NULL; (e = find(e, targetname, this.target)); ) if(e.classname == "target_viewlocation_start") { - self.enemy = e; + this.enemy = e; break; } - for(e = world; (e = find(e, targetname, self.target2)); ) + for(e = NULL; (e = find(e, targetname, this.target2)); ) if(e.classname == "target_viewlocation_end") { - self.goalentity = e; + this.goalentity = e; break; } - if(!self.enemy) { print("^1FAIL!\n"); remove(self); return; } + if(!this.enemy) { LOG_INFO("^1FAIL!\n"); remove(this); return; } - if(!self.goalentity) - self.goalentity = self.enemy; // make them match so CSQC knows what to do + if(!this.goalentity) + this.goalentity = this.enemy; // make them match so CSQC knows what to do - Net_LinkEntity(self, false, 0, trigger_viewloc_send); + Net_LinkEntity(this, false, 0, trigger_viewloc_send); - self.think = viewloc_think; - self.nextthink = time; + setthink(this, viewloc_think); + this.nextthink = time; } -void spawnfunc_trigger_viewlocation() +spawnfunc(trigger_viewlocation) { // we won't check target2 here yet, as it may not even need to exist - if(self.target == "") { print("^1FAIL!\n"); remove(self); return; } + if(this.target == "") { LOG_INFO("^1FAIL!\n"); remove(this); return; } EXACTTRIGGER_INIT; - InitializeEntity(self, viewloc_init, INITPRIO_FINDTARGET); + InitializeEntity(this, viewloc_init, INITPRIO_FINDTARGET); } -bool viewloc_send(entity to, int sf) +bool viewloc_send(entity this, entity to, int sf) { - WriteByte(MSG_ENTITY, ENT_CLIENT_VIEWLOC); + WriteHeader(MSG_ENTITY, ENT_CLIENT_VIEWLOC); - WriteByte(MSG_ENTITY, self.cnt); + WriteByte(MSG_ENTITY, this.cnt); - WriteCoord(MSG_ENTITY, self.origin_x); - WriteCoord(MSG_ENTITY, self.origin_y); - WriteCoord(MSG_ENTITY, self.origin_z); + WriteCoord(MSG_ENTITY, this.origin_x); + WriteCoord(MSG_ENTITY, this.origin_y); + WriteCoord(MSG_ENTITY, this.origin_z); - WriteCoord(MSG_ENTITY, self.angles_x); - WriteCoord(MSG_ENTITY, self.angles_y); - WriteCoord(MSG_ENTITY, self.angles_z); + WriteCoord(MSG_ENTITY, this.angles_x); + WriteCoord(MSG_ENTITY, this.angles_y); + WriteCoord(MSG_ENTITY, this.angles_z); return true; } .float angle; -void viewloc_link() +void viewloc_link(entity this) { - if(self.angle) - self.angles_y = self.angle; - Net_LinkEntity(self, false, 0, viewloc_send); + if(this.angle) + this.angles_y = this.angle; + Net_LinkEntity(this, false, 0, viewloc_send); } -void spawnfunc_target_viewlocation_start() +spawnfunc(target_viewlocation_start) { - self.classname = "target_viewlocation_start"; - self.cnt = 1; - viewloc_link(); + this.classname = "target_viewlocation_start"; + this.cnt = 1; + viewloc_link(this); } -void spawnfunc_target_viewlocation_end() +spawnfunc(target_viewlocation_end) { - self.classname = "target_viewlocation_end"; - self.cnt = 2; - viewloc_link(); + this.classname = "target_viewlocation_end"; + this.cnt = 2; + viewloc_link(this); } // compatibility -void spawnfunc_target_viewlocation() { spawnfunc_target_viewlocation_start(); } +spawnfunc(target_viewlocation) { spawnfunc_target_viewlocation_start(this); } #elif defined(CSQC) -void trigger_viewloc_updatelink() +void trigger_viewloc_updatelink(entity this) { - self.enemy = findfloat(world, entnum, self.cnt); - self.goalentity = findfloat(world, entnum, self.count); + this.enemy = findfloat(NULL, entnum, this.cnt); + this.goalentity = findfloat(NULL, entnum, this.count); } -void ent_viewloc_trigger() +NET_HANDLE(ENT_CLIENT_VIEWLOC_TRIGGER, bool isnew) { float point1 = ReadShort(); float point2 = ReadShort(); - self.enemy = findfloat(world, entnum, point1); - self.goalentity = findfloat(world, entnum, point2); + this.enemy = findfloat(NULL, entnum, point1); + this.goalentity = findfloat(NULL, entnum, point2); + + this.origin_x = ReadCoord(); + this.origin_y = ReadCoord(); + this.origin_z = ReadCoord(); - self.origin_x = ReadCoord(); - self.origin_y = ReadCoord(); - self.origin_z = ReadCoord(); - setorigin(self, self.origin); + return = true; - self.cnt = point1; - self.count = point2; + setorigin(this, this.origin); - self.think = trigger_viewloc_updatelink; - self.nextthink = time + 1; // we need to delay this or else + this.cnt = point1; + this.count = point2; - self.classname = "trigger_viewlocation"; - self.drawmask = MASK_NORMAL; // not so concerned, but better keep it alive + setthink(this, trigger_viewloc_updatelink); + this.nextthink = time + 1; // we need to delay this or else + + this.classname = "trigger_viewlocation"; + this.drawmask = MASK_NORMAL; // not so concerned, but better keep it alive } -void ent_viewloc() +NET_HANDLE(ENT_CLIENT_VIEWLOC, bool isnew) { - self.cnt = ReadByte(); + this.cnt = ReadByte(); + + this.origin_x = ReadCoord(); + this.origin_y = ReadCoord(); + this.origin_z = ReadCoord(); + setorigin(this, this.origin); - self.origin_x = ReadCoord(); - self.origin_y = ReadCoord(); - self.origin_z = ReadCoord(); - setorigin(self, self.origin); + this.movedir_x = ReadCoord(); + this.movedir_y = ReadCoord(); + this.movedir_z = ReadCoord(); - self.movedir_x = ReadCoord(); - self.movedir_y = ReadCoord(); - self.movedir_z = ReadCoord(); + return = true; - self.classname = ((self.cnt == 2) ? "target_viewlocation_end" : "target_viewlocation_start"); - self.drawmask = MASK_NORMAL; // don't cull it + this.classname = ((this.cnt == 2) ? "target_viewlocation_end" : "target_viewlocation_start"); + this.drawmask = MASK_NORMAL; // don't cull it } #endif