From 3c920a80171669e83e8e57e0f764f4ec51f03c4b Mon Sep 17 00:00:00 2001 From: div0 Date: Thu, 19 Mar 2009 10:39:49 +0000 Subject: [PATCH] make misc_follow able to set up attachments (so you can attach a model to another in a map, useful for zym animations) add a cheat +button8: drag'n'drop of entities git-svn-id: svn://svn.icculus.org/nexuiz/trunk@6216 f962a42d-fe04-0410-a3ab-8c8b0445ebaa --- data/qcsrc/server/cl_client.qc | 27 ++++++++++++ data/qcsrc/server/defs.qh | 3 ++ data/qcsrc/server/g_triggers.qc | 32 ++++++++++++--- data/qcsrc/server/miscfunctions.qc | 66 ++++++++++++++++++++++++++++++ data/scripts/entities.def | 7 +++- 5 files changed, 129 insertions(+), 6 deletions(-) diff --git a/data/qcsrc/server/cl_client.qc b/data/qcsrc/server/cl_client.qc index 8fd24ebc3..ac23e6b21 100644 --- a/data/qcsrc/server/cl_client.qc +++ b/data/qcsrc/server/cl_client.qc @@ -2377,6 +2377,33 @@ void PlayerPreThink (void) } target_voicescript_next(self); + + if(sv_cheats) + if(self.BUTTON_DRAG) + if(!self.dragentity) + if(self.cursor_trace_ent) + if(!self.cursor_trace_ent.tag_index) + { + self.dragentity = self.cursor_trace_ent; + if(cvar("chase_active")) + { + if(gettagindex(self, "tag_weapon")) + attach_sameorigin(self.dragentity, self, "tag_weapon"); + else + attach_sameorigin(self.dragentity, self, ""); + } + else + attach_sameorigin(self.dragentity, self.weaponentity, ""); + self.dragentity.effects |= EF_FLAME; + } + + if(!self.BUTTON_DRAG) + if(self.dragentity) + { + self.dragentity.effects &~= EF_FLAME; + detach_sameorigin(self.dragentity); + self.dragentity = world; + } } diff --git a/data/qcsrc/server/defs.qh b/data/qcsrc/server/defs.qh index f6d086062..add93bf30 100644 --- a/data/qcsrc/server/defs.qh +++ b/data/qcsrc/server/defs.qh @@ -11,6 +11,7 @@ float require_spawnfunc_prefix; // if this float exists, only functions with spa #define BUTTON_INFO button7 #define BUTTON_CHAT buttonchat #define BUTTON_USE buttonuse +#define BUTTON_DRAG button8 // Globals @@ -551,3 +552,5 @@ vector debug_shotorg; // if non-zero, overrides the shot origin of all weapons .float wasplayer; float servertime, serverprevtime, serverframetime; + +.entity dragentity; diff --git a/data/qcsrc/server/g_triggers.qc b/data/qcsrc/server/g_triggers.qc index 687050e8e..51a1fe5e6 100644 --- a/data/qcsrc/server/g_triggers.qc +++ b/data/qcsrc/server/g_triggers.qc @@ -1347,11 +1347,33 @@ void follow_init() return; } - dst.movetype = MOVETYPE_FOLLOW; - dst.aiment = src; - dst.punchangle = src.angles; - dst.view_ofs = dst.origin - src.origin; - dst.v_angle = dst.angles - src.angles; + if(self.spawnflags & 1) + { + // attach + if(self.spawnflags & 2) + { + setattachment(dst, src, self.message); + } + else + { + attach_sameorigin(dst, src, self.message); + } + } + else + { + if(self.spawnflags & 2) + { + dst.movetype = MOVETYPE_FOLLOW; + dst.aiment = src; + // dst.punchangle = '0 0 0'; // keep unchanged + dst.view_ofs = dst.origin; + dst.v_angle = dst.angles; + } + else + { + follow_sameorigin(dst, src); + } + } remove(self); } diff --git a/data/qcsrc/server/miscfunctions.qc b/data/qcsrc/server/miscfunctions.qc index 2cbf43576..48fc11c27 100644 --- a/data/qcsrc/server/miscfunctions.qc +++ b/data/qcsrc/server/miscfunctions.qc @@ -2047,3 +2047,69 @@ vector shotorg_adjust(vector vecs, float y_is_right, float visual) } return vecs; } + + + +void attach_sameorigin(entity e, entity to, string tag) +{ + vector org, t_forward, t_left, t_up, e_forward, e_up; + vector org0, ang0; + + ang0 = e.angles; + org0 = e.origin; + + org = e.origin - gettaginfo(to, gettagindex(to, tag)); + t_forward = v_forward; + t_left = v_right * -1; + t_up = v_up; + + e.origin_x = org * t_forward; + e.origin_y = org * t_left; + e.origin_z = org * t_up; + + // current forward and up directions + if(substring(e.model, 0, 1) == "*") // bmodels have their own rules + e.angles_x = -e.angles_x; + fixedmakevectors(e.angles); + + // untransform forward, up! + e_forward_x = v_forward * t_forward; + e_forward_y = v_forward * t_left; + e_forward_z = v_forward * t_up; + e_up_x = v_up * t_forward; + e_up_y = v_up * t_left; + e_up_z = v_up * t_up; + + e.angles = fixedvectoangles2(e_forward, e_up); + if(substring(e.model, 0, 1) == "*") // bmodels have their own rules + e.angles_x = -e.angles_x; + + setattachment(e, to, tag); + setorigin(e, e.origin); +} + +void detach_sameorigin(entity e) +{ + vector org; + org = gettaginfo(e, 0); + e.angles = fixedvectoangles2(v_forward, v_up); + if(substring(e.model, 0, 1) == "*") // bmodels have their own rules + e.angles_x = -e.angles_x; + e.origin = org; + setattachment(e, world, ""); + setorigin(e, e.origin); +} + +void follow_sameorigin(entity e, entity to) +{ + e.movetype = MOVETYPE_FOLLOW; // make the hole follow + e.aiment = to; // make the hole follow bmodel + e.punchangle = to.angles; // the original angles of bmodel + e.view_ofs = e.origin - to.origin; // relative origin + e.v_angle = e.angles - to.angles; // relative angles +} + +void unfollow_sameorigin(entity e) +{ + e.movetype = MOVETYPE_NONE; +} diff --git a/data/scripts/entities.def b/data/scripts/entities.def index 109dac9d2..01c75706f 100644 --- a/data/scripts/entities.def +++ b/data/scripts/entities.def @@ -1183,11 +1183,16 @@ target4: trigger all entities with this targetname when starting the game wait: wait so many seconds before triggering */ -/*QUAKED misc_follow (.5 .5 .5) (-8 -8 -8) (8 8 8) +/*QUAKED misc_follow (.5 .5 .5) (-8 -8 -8) (8 8 8) ATTACH LOCAL Makes one entity follow another. Will not work with all entities. -------- KEYS -------- target: points to the entity to move (e.g. something that won't move by itself) killtarget: points to the entity that is to be used as the source (e.g. a func_plat) +message: tag name to attach to (if ATTACH is used) +punchangle: angle modifier (if LOCAL is used, and ATTACH is not) +-------- SPAWNFLAGS -------- +ATTACH: attachment will be used instead of MOVETYPE_FOLLOW (mostly useful for attaching stuff to ZYM models) +LOCAL: do not untransform the coordinates (that is, the map specifies local coordinates, not global ones). Mostly useful with ATTACH. */ /*QUAKED weapon_minstanex (1 0 .5) (-30 -30 0) (30 30 32) FLOATING -- 2.39.2