From bff2b21ecb0b3ddb5b8459cfe5222e163a0f32f0 Mon Sep 17 00:00:00 2001 From: Juhu <5894800-Juhu_@users.noreply.gitlab.com> Date: Sat, 4 Feb 2023 00:34:04 +0100 Subject: [PATCH] q3df compat: trigger_push_velocity code clean up and bug fix to properly remember last MAX_PUSHED velocity jump pads --- qcsrc/common/mapobjects/trigger/jumppads.qc | 32 ++++++++++++++------- qcsrc/common/mapobjects/trigger/jumppads.qh | 18 ++++++------ 2 files changed, 30 insertions(+), 20 deletions(-) diff --git a/qcsrc/common/mapobjects/trigger/jumppads.qc b/qcsrc/common/mapobjects/trigger/jumppads.qc index 82192ea66..fca91832d 100644 --- a/qcsrc/common/mapobjects/trigger/jumppads.qc +++ b/qcsrc/common/mapobjects/trigger/jumppads.qc @@ -131,20 +131,28 @@ vector trigger_push_calculatevelocity(vector org, entity tgt, float ht, entity p vector trigger_push_velocity_calculatevelocity(entity this, vector org, entity tgt, float speed, float count, entity pushed_entity, bool is_pushed) { + bool is_playerdir_xy = boolean(this.spawnflags & PUSH_VELOCITY_PLAYERDIR_XY); + bool is_add_xy = boolean(this.spawnflags & PUSH_VELOCITY_ADD_XY); + bool is_playerdir_z = boolean(this.spawnflags & PUSH_VELOCITY_PLAYERDIR_Z); + bool is_add_z = boolean(this.spawnflags & PUSH_VELOCITY_ADD_Z); + bool is_bidirectional_xy = boolean(this.spawnflags & PUSH_VELOCITY_BIDIRECTIONAL_XY); + bool is_bidirectional_z = boolean(this.spawnflags & PUSH_VELOCITY_BIDIRECTIONAL_Z); + bool is_clamp_negative_adds = boolean(this.spawnflags & PUSH_VELOCITY_CLAMP_NEGATIVE_ADDS); + vector sdir = normalize(vec2(pushed_entity.velocity)); float zdir = pushed_entity.velocity.z; - if(zdir != 0) zdir = copysign(1, pushed_entity.velocity.z); + if(zdir != 0) zdir = copysign(1, zdir); vector vs_tgt = '0 0 0'; float vz_tgt = 0; - if (!(this.spawnflags & PLAYERDIR_XY) || !(this.spawnflags & PLAYERDIR_Z)) + if (!is_playerdir_xy || !is_playerdir_z) { vector vel_tgt = trigger_push_calculatevelocity(org, tgt, 0, pushed_entity); vs_tgt = vec2(vel_tgt); vz_tgt = vel_tgt.z; // bidirectional jump pads do not play nicely with xonotic's jump pad targets - if (this.spawnflags & BIDIRECTIONAL_XY) + if (is_bidirectional_xy) { if (normalize(vs_tgt) * sdir < 0) { @@ -152,7 +160,7 @@ vector trigger_push_velocity_calculatevelocity(entity this, vector org, entity t } } - if (this.spawnflags & BIDIRECTIONAL_Z) + if (is_bidirectional_z) { if (signbit(vz_tgt) != signbit(zdir)) { @@ -162,7 +170,7 @@ vector trigger_push_velocity_calculatevelocity(entity this, vector org, entity t } vector vs; - if (this.spawnflags & PLAYERDIR_XY) + if (is_playerdir_xy) { vs = sdir * speed; } @@ -172,7 +180,7 @@ vector trigger_push_velocity_calculatevelocity(entity this, vector org, entity t } float vz; - if (this.spawnflags & PLAYERDIR_Z) + if (is_playerdir_z) { vz = zdir * count; } @@ -181,7 +189,7 @@ vector trigger_push_velocity_calculatevelocity(entity this, vector org, entity t vz = vz_tgt; } - if (this.spawnflags & ADD_XY) + if (is_add_xy) { vector vs_add = vec2(pushed_entity.velocity); if (is_pushed) @@ -192,7 +200,7 @@ vector trigger_push_velocity_calculatevelocity(entity this, vector org, entity t { vs += vs_add; - if (this.spawnflags & CLAMP_NEGATIVE_ADDS) + if (is_clamp_negative_adds) { if ((normalize(vs) * sdir) < 0) { @@ -202,7 +210,7 @@ vector trigger_push_velocity_calculatevelocity(entity this, vector org, entity t } } - if (this.spawnflags & ADD_Z) + if (is_add_z) { float vz_add = pushed_entity.velocity.z; if (is_pushed) @@ -213,7 +221,7 @@ vector trigger_push_velocity_calculatevelocity(entity this, vector org, entity t { vz += vz_add; - if (this.spawnflags & CLAMP_NEGATIVE_ADDS) + if (is_clamp_negative_adds) { if (signbit(vz) != signbit(zdir)) { @@ -226,6 +234,7 @@ vector trigger_push_velocity_calculatevelocity(entity this, vector org, entity t return vs + '0 0 1' * vz; } +// TODO: move this check to player/projectile physics? void check_pushed(entity this) // first jump pad to think thinks for every jump pad { IL_EACH(are_pushed, true, @@ -286,6 +295,7 @@ bool jumppad_push(entity this, entity targ, bool is_velocity_pad) if(targ.has_pushed[i]) continue; limit_reached = false; targ.has_pushed[i] = this; // may be briefly out of sync between client and server if client prediction is toggled + break; } if(limit_reached) { @@ -342,7 +352,7 @@ bool jumppad_push(entity this, entity targ, bool is_velocity_pad) } } - if(!is_pushed) UNSET_ONGROUND(targ); + if(!is_velocity_pad) UNSET_ONGROUND(targ); #ifdef CSQC if (targ.flags & FL_PROJECTILE) diff --git a/qcsrc/common/mapobjects/trigger/jumppads.qh b/qcsrc/common/mapobjects/trigger/jumppads.qh index 51ec38d98..9dad3c6ea 100644 --- a/qcsrc/common/mapobjects/trigger/jumppads.qh +++ b/qcsrc/common/mapobjects/trigger/jumppads.qh @@ -4,13 +4,13 @@ const int PUSH_ONCE = BIT(0); // legacy, deactivate with relay instead const int PUSH_SILENT = BIT(1); // not used? -const int PLAYERDIR_XY = BIT(0); // if set, trigger will apply the horizontal speed in the player's horizontal direction of travel, otherwise it uses the target XY component. -const int ADD_XY = BIT(1); // if set, trigger will add to the player's horizontal velocity, otherwise it sets the player's horizontal velocity. -const int PLAYERDIR_Z = BIT(2); // if set, trigger will apply the vertical speed in the player's vertical direction of travel, otherwise it uses the target Z component. -const int ADD_Z = BIT(3); // if set, trigger will add to the player's vertical velocity, otherwise it sets the player's vertical velocity. -const int BIDIRECTIONAL_XY = BIT(4); // if set, non-playerdir velocity pads will function in 2 directions based on the target specified. The chosen direction is based on the current direction of travel. Applies to horizontal direction. -const int BIDIRECTIONAL_Z = BIT(5); // if set, non-playerdir velocity pads will function in 2 directions based on the target specified. The chosen direction is based on the current direction of travel. Applies to vertical direction. -const int CLAMP_NEGATIVE_ADDS = BIT(6); // if set, then a velocity pad that adds negative velocity will be clamped to 0, if the resultant velocity would bounce the player in the opposite direction. +const int PUSH_VELOCITY_PLAYERDIR_XY = BIT(0); +const int PUSH_VELOCITY_ADD_XY = BIT(1); +const int PUSH_VELOCITY_PLAYERDIR_Z = BIT(2); +const int PUSH_VELOCITY_ADD_Z = BIT(3); +const int PUSH_VELOCITY_BIDIRECTIONAL_XY = BIT(4); +const int PUSH_VELOCITY_BIDIRECTIONAL_Z = BIT(5); +const int PUSH_VELOCITY_CLAMP_NEGATIVE_ADDS = BIT(6); IntrusiveList g_jumppads; STATIC_INIT(g_jumppads) { g_jumppads = IL_NEW(); } @@ -56,7 +56,7 @@ bool trigger_push_test(entity this, entity item); void trigger_push_findtarget(entity this); /* - * ENTITY PARAMETERS: + * ENTITY PARAMETERS trigger_push: * * target: target of jump * height: the absolute value is the height of the highest point of the jump @@ -69,7 +69,7 @@ void trigger_push_findtarget(entity this); */ /* - * ENTITY PARAMETERS: + * ENTITY PARAMETERS trigger_push_velocity: * * target: this points to the target_position to which the player will jump. * speed: XY speed for player-directional velocity pads - either sets or adds to the player's horizontal velocity. -- 2.39.2