X-Git-Url: http://de.git.xonotic.org/?p=xonotic%2Fxonotic-data.pk3dir.git;a=blobdiff_plain;f=qcsrc%2Fwarpzonelib%2Fserver.qc;h=25bcd2901f9e449cffa4a1274a99b19c78936a7f;hp=6c27842ef27f2066034a09e7bc81dd3e372bb074;hb=ae2c1407ec9a05e4f501a6604a7cce8e1030df9f;hpb=966ecd5b871fc8ef6db7665c08bd17971a8830db diff --git a/qcsrc/warpzonelib/server.qc b/qcsrc/warpzonelib/server.qc index 6c27842ef..f3dd22ad3 100644 --- a/qcsrc/warpzonelib/server.qc +++ b/qcsrc/warpzonelib/server.qc @@ -1,4 +1,22 @@ -#define REMOVEHACK +#include "server.qh" + +#include "common.qh" +#if defined(CSQC) +#elif defined(MENUQC) +#elif defined(SVQC) + #include "../common/constants.qh" + #include "../common/triggers/subs.qh" + #include "../common/util.qh" + #include "../dpdefs/dpextensions.qh" + #include "../dpdefs/progsdefs.qh" + #include "../server/command/common.qh" + #include "../server/constants.qh" + #include "../server/defs.qh" +#endif + +#ifdef WARPZONELIB_KEEPDEBUG +#define WARPZONELIB_REMOVEHACK +#endif // for think function .vector warpzone_save_origin; @@ -24,24 +42,24 @@ void WarpZone_TeleportPlayer(entity teleporter, entity player, vector to, vector setorigin (player, to); // NOTE: this also aborts the move, when this is called by touch player.oldorigin = to; // for DP's unsticking player.angles = to_angles; - player.fixangle = TRUE; + player.fixangle = true; player.velocity = to_velocity; BITXOR_ASSIGN(player.effects, EF_TELEPORT_BIT); - if(player.classname == "player") + if(IS_PLAYER(player)) BITCLR_ASSIGN(player.flags, FL_ONGROUND); WarpZone_PostTeleportPlayer_Callback(player); } -float WarpZone_Teleported_Send(entity to, float sf) +bool WarpZone_Teleported_Send(entity to, int sf) { WriteByte(MSG_ENTITY, ENT_CLIENT_WARPZONE_TELEPORTED); - WriteCoord(MSG_ENTITY, self.angles_x); - WriteCoord(MSG_ENTITY, self.angles_y); - WriteCoord(MSG_ENTITY, self.angles_z); - return TRUE; + WriteCoord(MSG_ENTITY, self.angles.x); + WriteCoord(MSG_ENTITY, self.angles.y); + WriteCoord(MSG_ENTITY, self.angles.z); + return true; } float WarpZone_Teleport(entity wz, entity player, float f0, float f1) @@ -54,7 +72,7 @@ float WarpZone_Teleport(entity wz, entity player, float f0, float f1) o10 = o1 = WarpZone_TransformOrigin(wz, o0); v1 = WarpZone_TransformVelocity(wz, v0); - if(clienttype(player) != CLIENTTYPE_NOTACLIENT) + if (!IS_NOT_A_CLIENT(player)) a1 = WarpZone_TransformVAngles(wz, player.v_angle); else a1 = WarpZone_TransformAngles(wz, a0); @@ -114,10 +132,12 @@ float WarpZone_Teleport(entity wz, entity player, float f0, float f1) player.warpzone_teleport_finishtime += sys_frametime - dt; #ifndef WARPZONE_USE_FIXANGLE - if(player.classname == "player") + if(IS_VEHICLE(player) && player.owner) + player = player.owner; // hax + if(IS_PLAYER(player)) { // instead of fixangle, send the transform to the client for smoother operation - player.fixangle = FALSE; + player.fixangle = false; entity ts = spawn(); setmodel(ts, "null"); @@ -170,7 +190,7 @@ void WarpZone_Touch (void) // 96*frametime float d; d = 24 + max(vlen(other.mins), vlen(other.maxs)); - if(clienttype(other) == CLIENTTYPE_NOTACLIENT) + if(IS_NOT_A_CLIENT(other)) f = -d / bound(frametime * d * 1, frametime * vlen(other.velocity), d); else f = -1; @@ -182,16 +202,16 @@ void WarpZone_Touch (void) save1 = self.target; self.target = string_null; save2 = self.target3; self.target3 = string_null; SUB_UseTargets(); - if not(self.target) self.target = save1; - if not(self.target3) self.target3 = save2; + if (!self.target) self.target = save1; + if (!self.target3) self.target3 = save2; oldself = self; self = self.enemy; save1 = self.target; self.target = string_null; save2 = self.target2; self.target2 = string_null; SUB_UseTargets(); - if not(self.target) self.target = save1; - if not(self.target2) self.target2 = save2; + if (!self.target) self.target = save1; + if (!self.target2) self.target2 = save2; self = oldself; } else @@ -200,13 +220,12 @@ void WarpZone_Touch (void) } } -float WarpZone_Send(entity to, float sendflags) +bool WarpZone_Send(entity to, int sendflags) { - float f; WriteByte(MSG_ENTITY, ENT_CLIENT_WARPZONE); // we must send this flag for clientside to match properly too - f = 0; + int f = 0; if(self.warpzone_isboxy) BITSET_ASSIGN(f, 1); if(self.warpzone_fadestart) @@ -218,33 +237,33 @@ float WarpZone_Send(entity to, float sendflags) // we need THESE to render the warpzone (and cull properly)... if(f & 4) { - WriteCoord(MSG_ENTITY, self.origin_x); - WriteCoord(MSG_ENTITY, self.origin_y); - WriteCoord(MSG_ENTITY, self.origin_z); + WriteCoord(MSG_ENTITY, self.origin.x); + WriteCoord(MSG_ENTITY, self.origin.y); + WriteCoord(MSG_ENTITY, self.origin.z); } WriteShort(MSG_ENTITY, self.modelindex); - WriteCoord(MSG_ENTITY, self.mins_x); - WriteCoord(MSG_ENTITY, self.mins_y); - WriteCoord(MSG_ENTITY, self.mins_z); - WriteCoord(MSG_ENTITY, self.maxs_x); - WriteCoord(MSG_ENTITY, self.maxs_y); - WriteCoord(MSG_ENTITY, self.maxs_z); + WriteCoord(MSG_ENTITY, self.mins.x); + WriteCoord(MSG_ENTITY, self.mins.y); + WriteCoord(MSG_ENTITY, self.mins.z); + WriteCoord(MSG_ENTITY, self.maxs.x); + WriteCoord(MSG_ENTITY, self.maxs.y); + WriteCoord(MSG_ENTITY, self.maxs.z); WriteByte(MSG_ENTITY, bound(1, self.scale * 16, 255)); // we need THESE to calculate the proper transform - WriteCoord(MSG_ENTITY, self.warpzone_origin_x); - WriteCoord(MSG_ENTITY, self.warpzone_origin_y); - WriteCoord(MSG_ENTITY, self.warpzone_origin_z); - WriteCoord(MSG_ENTITY, self.warpzone_angles_x); - WriteCoord(MSG_ENTITY, self.warpzone_angles_y); - WriteCoord(MSG_ENTITY, self.warpzone_angles_z); - WriteCoord(MSG_ENTITY, self.warpzone_targetorigin_x); - WriteCoord(MSG_ENTITY, self.warpzone_targetorigin_y); - WriteCoord(MSG_ENTITY, self.warpzone_targetorigin_z); - WriteCoord(MSG_ENTITY, self.warpzone_targetangles_x); - WriteCoord(MSG_ENTITY, self.warpzone_targetangles_y); - WriteCoord(MSG_ENTITY, self.warpzone_targetangles_z); + WriteCoord(MSG_ENTITY, self.warpzone_origin.x); + WriteCoord(MSG_ENTITY, self.warpzone_origin.y); + WriteCoord(MSG_ENTITY, self.warpzone_origin.z); + WriteCoord(MSG_ENTITY, self.warpzone_angles.x); + WriteCoord(MSG_ENTITY, self.warpzone_angles.y); + WriteCoord(MSG_ENTITY, self.warpzone_angles.z); + WriteCoord(MSG_ENTITY, self.warpzone_targetorigin.x); + WriteCoord(MSG_ENTITY, self.warpzone_targetorigin.y); + WriteCoord(MSG_ENTITY, self.warpzone_targetorigin.z); + WriteCoord(MSG_ENTITY, self.warpzone_targetangles.x); + WriteCoord(MSG_ENTITY, self.warpzone_targetangles.y); + WriteCoord(MSG_ENTITY, self.warpzone_targetangles.z); if(f & 2) { @@ -252,12 +271,12 @@ float WarpZone_Send(entity to, float sendflags) WriteShort(MSG_ENTITY, self.warpzone_fadeend); } - return TRUE; + return true; } -float WarpZone_Camera_Send(entity to, float sendflags) +bool WarpZone_Camera_Send(entity to, int sendflags) { - float f; + int f = 0; WriteByte(MSG_ENTITY, ENT_CLIENT_WARPZONE_CAMERA); if(self.warpzone_fadestart) @@ -269,27 +288,27 @@ float WarpZone_Camera_Send(entity to, float sendflags) // we need THESE to render the warpzone (and cull properly)... if(f & 4) { - WriteCoord(MSG_ENTITY, self.origin_x); - WriteCoord(MSG_ENTITY, self.origin_y); - WriteCoord(MSG_ENTITY, self.origin_z); + WriteCoord(MSG_ENTITY, self.origin.x); + WriteCoord(MSG_ENTITY, self.origin.y); + WriteCoord(MSG_ENTITY, self.origin.z); } WriteShort(MSG_ENTITY, self.modelindex); - WriteCoord(MSG_ENTITY, self.mins_x); - WriteCoord(MSG_ENTITY, self.mins_y); - WriteCoord(MSG_ENTITY, self.mins_z); - WriteCoord(MSG_ENTITY, self.maxs_x); - WriteCoord(MSG_ENTITY, self.maxs_y); - WriteCoord(MSG_ENTITY, self.maxs_z); + WriteCoord(MSG_ENTITY, self.mins.x); + WriteCoord(MSG_ENTITY, self.mins.y); + WriteCoord(MSG_ENTITY, self.mins.z); + WriteCoord(MSG_ENTITY, self.maxs.x); + WriteCoord(MSG_ENTITY, self.maxs.y); + WriteCoord(MSG_ENTITY, self.maxs.z); WriteByte(MSG_ENTITY, bound(1, self.scale * 16, 255)); // we need THESE to calculate the proper transform - WriteCoord(MSG_ENTITY, self.enemy.origin_x); - WriteCoord(MSG_ENTITY, self.enemy.origin_y); - WriteCoord(MSG_ENTITY, self.enemy.origin_z); - WriteCoord(MSG_ENTITY, self.enemy.angles_x); - WriteCoord(MSG_ENTITY, self.enemy.angles_y); - WriteCoord(MSG_ENTITY, self.enemy.angles_z); + WriteCoord(MSG_ENTITY, self.enemy.origin.x); + WriteCoord(MSG_ENTITY, self.enemy.origin.y); + WriteCoord(MSG_ENTITY, self.enemy.origin.z); + WriteCoord(MSG_ENTITY, self.enemy.angles.x); + WriteCoord(MSG_ENTITY, self.enemy.angles.y); + WriteCoord(MSG_ENTITY, self.enemy.angles.z); if(f & 2) { @@ -297,9 +316,10 @@ float WarpZone_Camera_Send(entity to, float sendflags) WriteShort(MSG_ENTITY, self.warpzone_fadeend); } - return TRUE; + return true; } +#ifdef WARPZONELIB_KEEPDEBUG float WarpZone_CheckProjectileImpact(entity player) { vector o0, v0; @@ -317,7 +337,7 @@ float WarpZone_CheckProjectileImpact(entity player) if(!wz) return 0; -#ifdef REMOVEHACK +#ifdef WARPZONELIB_REMOVEHACK print("impactfilter found something - and it no longer gets handled correctly - please tell divVerent whether anything behaves broken now\n"); #else print("impactfilter found something - and it even gets handled correctly - please tell divVerent that this code apparently gets triggered again\n"); @@ -326,7 +346,7 @@ float WarpZone_CheckProjectileImpact(entity player) print("Origin: ", vtos(player.origin), "\n"); print("Velocity: ", vtos(player.velocity), "\n"); -#ifdef REMOVEHACK +#ifdef WARPZONELIB_REMOVEHACK return 0; #else // retry previous move @@ -345,15 +365,15 @@ float WarpZone_CheckProjectileImpact(entity player) save1 = self.target; self.target = string_null; save2 = self.target3; self.target3 = string_null; SUB_UseTargets(); - if not(self.target) self.target = save1; - if not(self.target3) self.target3 = save2; + if (!self.target) self.target = save1; + if (!self.target3) self.target3 = save2; self = self.enemy; save1 = self.target; self.target = string_null; save2 = self.target2; self.target2 = string_null; SUB_UseTargets(); - if not(self.target) self.target = save1; - if not(self.target2) self.target2 = save2; + if (!self.target) self.target = save1; + if (!self.target2) self.target2 = save2; self = oldself; } else @@ -365,16 +385,23 @@ float WarpZone_CheckProjectileImpact(entity player) return +1; #endif } +#endif + float WarpZone_Projectile_Touch() { - float f; if(other.classname == "trigger_warpzone") - return TRUE; + return true; // no further impacts if we teleported this frame! + // this is because even if we did teleport, the engine still may raise + // touch events for the previous location + // engine now aborts moves on teleport, so this SHOULD not happen any more + // but if this is called from TouchAreaGrid of the projectile moving, + // then this won't do if(time == self.warpzone_teleport_time) - return TRUE; + return true; +#ifdef WARPZONELIB_KEEPDEBUG // this SEEMS to not happen at the moment, but if it did, it would be more reliable { float save_dpstartcontents; @@ -403,6 +430,7 @@ float WarpZone_Projectile_Touch() save_ent = trace_ent; save_inopen = trace_inopen; save_inwater = trace_inwater; + float f; if((f = WarpZone_CheckProjectileImpact(self)) != 0) return (f > 0); trace_dpstartcontents = save_dpstartcontents; @@ -419,11 +447,12 @@ float WarpZone_Projectile_Touch() trace_inopen = save_inopen; trace_inwater = save_inwater; } +#endif if(WarpZone_Projectile_Touch_ImpactFilter_Callback()) - return TRUE; + return true; - return FALSE; + return false; } void WarpZone_InitStep_FindOriginTarget() @@ -512,7 +541,7 @@ void WarpZone_InitStep_UpdateTransform() { vector org, ang, norm, point; float area; - vector tri, a, b, c, p, q, n; + vector tri, a, b, c, n; float i_s, i_t, n_t; string tex; @@ -525,7 +554,7 @@ void WarpZone_InitStep_UpdateTransform() for(i_s = 0; ; ++i_s) { tex = getsurfacetexture(self, i_s); - if not(tex) + if (!tex) break; // this is beyond the last one if(tex == "textures/common/trigger" || tex == "trigger") continue; @@ -533,14 +562,10 @@ void WarpZone_InitStep_UpdateTransform() for(i_t = 0; i_t < n_t; ++i_t) { tri = getsurfacetriangle(self, i_s, i_t); - a = getsurfacepoint(self, i_s, tri_x); - b = getsurfacepoint(self, i_s, tri_y); - c = getsurfacepoint(self, i_s, tri_z); - p = b - a; - q = c - a; - n = '1 0 0' * (q_y * p_z - q_z * p_y) - + '0 1 0' * (q_z * p_x - q_x * p_z) - + '0 0 1' * (q_x * p_y - q_y * p_x); + a = getsurfacepoint(self, i_s, tri.x); + b = getsurfacepoint(self, i_s, tri.y); + c = getsurfacepoint(self, i_s, tri.z); + n = cross(c - a, b - a); area = area + vlen(n); norm = norm + n; point = point + vlen(n) * (a + b + c); @@ -558,6 +583,7 @@ void WarpZone_InitStep_UpdateTransform() norm = normalize(norm); } + ang = '0 0 0'; if(self.aiment) { org = self.aiment.origin; @@ -572,7 +598,7 @@ void WarpZone_InitStep_UpdateTransform() norm = -1 * norm; } ang = vectoangles2(norm, v_up); // keep rotation, but turn exactly against plane - ang_x = -ang_x; + ang.x = -ang.x; if(norm * v_forward < 0.99) print("trigger_warpzone near ", vtos(self.aiment.origin), " has been turned to match plane orientation (", vtos(self.aiment.angles), " -> ", vtos(ang), "\n"); if(vlen(org - self.aiment.origin) > 0.5) @@ -583,7 +609,7 @@ void WarpZone_InitStep_UpdateTransform() { org = point; ang = vectoangles(norm); - ang_x = -ang_x; + ang.x = -ang.x; } else error("cannot infer origin/angles for this warpzone, please use a killtarget or a trigger_warpzone_position"); @@ -653,7 +679,7 @@ void WarpZone_InitStep_FinalizeTransform() } float warpzone_initialized; -entity warpzone_first; +//entity warpzone_first; entity warpzone_position_first; entity warpzone_camera_first; .entity warpzone_next; @@ -794,23 +820,22 @@ void WarpZone_StartFrame() for(e = world; (e = nextent(e)); ) { if(warpzone_warpzones_exist) { WarpZone_StoreProjectileData(e); } - - float f = clienttype(e); - if(f == CLIENTTYPE_REAL) + + if(IS_REAL_CLIENT(e)) { if(e.solid == SOLID_NOT) // not spectating? if(e.movetype == MOVETYPE_NOCLIP || e.movetype == MOVETYPE_FLY || e.movetype == MOVETYPE_FLY_WORLDONLY) // not spectating? (this is to catch observers) { other = e; // player - + // warpzones - if(warpzone_warpzones_exist) { - self = WarpZone_Find(e.origin + e.mins, e.origin + e.maxs); + if(warpzone_warpzones_exist) { + self = WarpZone_Find(e.origin + e.mins, e.origin + e.maxs); if(self) if(!WarpZoneLib_ExactTrigger_Touch()) if(WarpZone_PlaneDist(self, e.origin + e.view_ofs) <= 0) WarpZone_Teleport(self, e, -1, 0); } // NOT triggering targets by this! - + // teleporters self = Teleport_Find(e.origin + e.mins, e.origin + e.maxs); if(self) @@ -818,11 +843,11 @@ void WarpZone_StartFrame() Simple_TeleportPlayer(self, other); // NOT triggering targets by this! } } - - if(f == CLIENTTYPE_NOTACLIENT) + + if(IS_NOT_A_CLIENT(e)) { if(warpzone_warpzones_exist) - for(; (e = nextent(e)); ) + for (; (e = nextent(e)); ) WarpZone_StoreProjectileData(e); break; } @@ -835,8 +860,8 @@ void WarpZone_StartFrame() float visible_to_some_client(entity ent) { entity e; - for(e = nextent(world); clienttype(e) != CLIENTTYPE_NOTACLIENT; e = nextent(e)) - if(e.classname == "player" && clienttype(e) == CLIENTTYPE_REAL) + for(e = nextent(world); !IS_NOT_A_CLIENT(e); e = nextent(e)) + if(IS_PLAYER(e) && IS_REAL_CLIENT(e)) if(checkpvs(e.origin + e.view_ofs, ent)) return 1; return 0; @@ -879,8 +904,8 @@ void spawnfunc_target_warpzone_reconnect() void WarpZone_PlayerPhysics_FixVAngle(void) { #ifndef WARPZONE_DONT_FIX_VANGLE - if(clienttype(self) == CLIENTTYPE_REAL) - if(self.v_angle_z <= 360) // if not already adjusted + if(IS_REAL_CLIENT(self)) + if(self.v_angle.z <= 360) // if not already adjusted if(time - self.ping * 0.001 < self.warpzone_teleport_time) { self.v_angle = WarpZone_TransformVAngles(self.warpzone_teleport_zone, self.v_angle);