Patches #1145

Merge in xonotic/xonotic-data.pk3dir.git: mirceakitsune/physical_entities

Added by git-manager over 2 years ago. Updated over 1 year ago.

Status:ResolvedStart date:04/04/2012
Priority:NormalDue date:
Assignee:-% Done:

100%

Category:-
Target version:-

Description

Purpose of the branch:

A mutator which allows making items physical. Requires ODE to be enabled and functional. Quick testing reveals no issues (apart from ODE glitches) but in-depth testing would be recommended.

http://www.youtube.com/watch?v=2QbEQK7-iRw

Repository: xonotic/xonotic-data.pk3dir.git
Commit: 3b75b57ac236d38d653da1e21216dd2a876e621f
Branch: mirceakitsune/physical_entities

Merge commands:

cd data/xonotic-data.pk3dir
git checkout master
git reset --hard origin/master
git pull && git diff '3b75b57ac236d38d653da1e21216dd2a876e621f'..'origin/mirceakitsune/physical_entities'

# please check that the diff you just saw did not contain anything complex that
# needs a new merge request, and review these changes

git merge --no-ff 'origin/mirceakitsune/physical_entities'

# please make sure this merge worked, and if not, fix merge conflicts and git
# commit BEFORE the next command
#
# also, THIS is the point to do final pre-merge testing
#
# use git reset --hard origin/master to bail out

git push && git push --delete origin 'mirceakitsune/physical_entities'

Diffstat:

 defaultXonotic.cfg                              |    4 +
 qcsrc/server/autocvars.qh                       |    3 +
 qcsrc/server/cl_weapons.qc                      |    1 +
 qcsrc/server/miscfunctions.qc                   |    2 +
 qcsrc/server/mutators/base.qh                   |    6 +
 qcsrc/server/mutators/mutator_physical_items.qc |  113 +++++++++++++++++++++++
 qcsrc/server/mutators/mutators.qh               |    1 +
 qcsrc/server/progs.src                          |    1 +
 qcsrc/server/t_items.qc                         |    8 ++
 9 files changed, 139 insertions(+), 0 deletions(-)

Revision log:

commit 3b75b57ac236d38d653da1e21216dd2a876e621f
Author: Mircea Kitsune <sonichedgehog_hyperblast00@yahoo.com>
Commit: Mircea Kitsune <sonichedgehog_hyperblast00@yahoo.com>

    Warn the player when no physics engine exists and physical items are therefore disabled

commit 46180becda38cac61d15a5168380b2784a21336f
Author: Mircea Kitsune <sonichedgehog_hyperblast00@yahoo.com>
Commit: Mircea Kitsune <sonichedgehog_hyperblast00@yahoo.com>

    Properly check the physics engine

commit c266d996f7f885a570ea6b1f77caa52cd6184ef7
Author: Mircea Kitsune <sonichedgehog_hyperblast00@yahoo.com>
Commit: Mircea Kitsune <sonichedgehog_hyperblast00@yahoo.com>

    Some code comments, and disable the mutator by default. Considered finished and up for testing

commit e13b404cae02faad07d65ad29fac1d9e7b7ff0f3
Author: Mircea Kitsune <sonichedgehog_hyperblast00@yahoo.com>
Commit: Mircea Kitsune <sonichedgehog_hyperblast00@yahoo.com>

    More name correction and also make items that fall into lava and slime return to spawn

commit 2fab686be80d997ed9152d6370a4a97f0c4d2d19
Author: Mircea Kitsune <sonichedgehog_hyperblast00@yahoo.com>
Commit: Mircea Kitsune <sonichedgehog_hyperblast00@yahoo.com>

    Rename physical_weapons to physical_items

commit fd2b4bf81c805552031942baa7ab64c97dce5543
Author: Mircea Kitsune <sonichedgehog_hyperblast00@yahoo.com>
Commit: Mircea Kitsune <sonichedgehog_hyperblast00@yahoo.com>

    Properly detect if the item is dropped or not. If some mod ever happens to allow dropping other items, this should automatically work now

commit 3296fbe8b2081a5524b45e436b7dc554a396abc4
Author: Mircea Kitsune <sonichedgehog_hyperblast00@yahoo.com>
Commit: Mircea Kitsune <sonichedgehog_hyperblast00@yahoo.com>

    Only return map items to spawn origin, not dropped ones

commit 365013f5b53a1cbb2463e94fc6bcb0dadf515481
Author: Mircea Kitsune <sonichedgehog_hyperblast00@yahoo.com>
Commit: Mircea Kitsune <sonichedgehog_hyperblast00@yahoo.com>

    Reset an item if it fell off the map (eg: in lava)

commit 1ccab7d2856c450754e7c245208bf954c779ded8
Author: Mircea Kitsune <sonichedgehog_hyperblast00@yahoo.com>
Commit: Mircea Kitsune <sonichedgehog_hyperblast00@yahoo.com>

    Floating items must not be physical

commit e33912f371b21750b06d543aa69c4bbdb17ffc0d
Author: Mircea Kitsune <sonichedgehog_hyperblast00@yahoo.com>
Commit: Mircea Kitsune <sonichedgehog_hyperblast00@yahoo.com>

    Cvar resetting of picked up items

commit 58522ab3b3a645809dcd0674f29ab7974e8137d6
Author: Mircea Kitsune <sonichedgehog_hyperblast00@yahoo.com>
Commit: Mircea Kitsune <sonichedgehog_hyperblast00@yahoo.com>

    Fail

commit a93dcc6f88a07b8c1e148516e8d0a86959026bcf
Author: Mircea Kitsune <sonichedgehog_hyperblast00@yahoo.com>
Commit: Mircea Kitsune <sonichedgehog_hyperblast00@yahoo.com>

    Make ghost items return to their original spawning point after being shot

commit 69635b211c59faf9a291a9f25c53d91d130cd1e8
Author: Mircea Kitsune <sonichedgehog_hyperblast00@yahoo.com>
Commit: Mircea Kitsune <sonichedgehog_hyperblast00@yahoo.com>

    Copy ghost items effect on physical map items

commit b53581a7d8cf14b87df6262398dc575f24789e59
Author: Mircea Kitsune <sonichedgehog_hyperblast00@yahoo.com>
Commit: Mircea Kitsune <sonichedgehog_hyperblast00@yahoo.com>

    Properly copy colormap and glowmod

commit 7cbff355ba196ad1c10c9b4a908a51086249cbe7
Author: Mircea Kitsune <sonichedgehog_hyperblast00@yahoo.com>
Commit: Mircea Kitsune <sonichedgehog_hyperblast00@yahoo.com>

    Make the physical item visible and hide the trigger weapon instead

commit c7a3b6c1a8aca003d61ca18a654c600993fe9565
Author: Mircea Kitsune <sonichedgehog_hyperblast00@yahoo.com>
Commit: Mircea Kitsune <sonichedgehog_hyperblast00@yahoo.com>

    Setting the cvar to 2 makes all items physical, including placed map items. Not recommended, but since this is a mutator why not allow it?

commit b7d1be9e3e620f75faf5ac3447331c1ba9c54f31
Author: Mircea Kitsune <sonichedgehog_hyperblast00@yahoo.com>
Commit: Mircea Kitsune <sonichedgehog_hyperblast00@yahoo.com>

    Move the physical weapon code to the new mutator

commit 68740440bd42805dc22788aa7c7bdc9eb87860c2
Author: Mircea Kitsune <sonichedgehog_hyperblast00@yahoo.com>
Commit: Mircea Kitsune <sonichedgehog_hyperblast00@yahoo.com>

    Call the new hook after everything else has been done, otherwise physics might get overwritten

commit cf4fffb8f56fbd5f42a130974812dcf72f44a0c4
Author: Mircea Kitsune <sonichedgehog_hyperblast00@yahoo.com>
Commit: Mircea Kitsune <sonichedgehog_hyperblast00@yahoo.com>

    div said this might work as a mutator, so add a new mutator and a hook and prepare to move it there. Also rename cvars

commit 0a0e078e8f0e2aba73cac6b908cb93bcc5a3c6b6
Author: Mircea Kitsune <sonichedgehog_hyperblast00@yahoo.com>
Commit: Mircea Kitsune <sonichedgehog_hyperblast00@yahoo.com>

    Some final fixes to the physical weapons. Since the current implementation was declared unacceptable, this remains a test that people can play with for fun

commit b828d257f0da8ec2c783cc82617d914b9c8f5459
Author: Mircea Kitsune <sonichedgehog_hyperblast00@yahoo.com>
Commit: Mircea Kitsune <sonichedgehog_hyperblast00@yahoo.com>

    Disable rotation of the physical weapon. For some reason, the trigger weapon still shows. I REALLY need to find a way to use only the dropped weapon entity, and make that physical instead

commit 37ee8383a37d13c69b1714a3434cad97613229dc
Author: Mircea Kitsune <sonichedgehog_hyperblast00@yahoo.com>
Commit: Mircea Kitsune <sonichedgehog_hyperblast00@yahoo.com>

    Correct cvar names

commit 995a17ca8ab147707b8b371d4d53955dfa699d90
Author: Mircea Kitsune <sonichedgehog_hyperblast00@yahoo.com>
Commit: Mircea Kitsune <sonichedgehog_hyperblast00@yahoo.com>

    Give dropped weapons a random anagular velocity. Doesn't work for some reason

commit 54ffd83cdce59963ac08f5b6357d55c8b4147fd1
Author: Mircea Kitsune <sonichedgehog_hyperblast00@yahoo.com>
Commit: Mircea Kitsune <sonichedgehog_hyperblast00@yahoo.com>

    Fix cvars

commit bfb4ad5acf6d396b3d92575d025152613352323d
Author: Mircea Kitsune <sonichedgehog_hyperblast00@yahoo.com>
Commit: Mircea Kitsune <sonichedgehog_hyperblast00@yahoo.com>

    Make the fake physical weapon disappear after the dropped one has.

commit 1682b9ed6b90aa31577ed8a03c8295aac58761ce
Author: Mircea Kitsune <sonichedgehog_hyperblast00@yahoo.com>
Commit: Mircea Kitsune <sonichedgehog_hyperblast00@yahoo.com>

    A try at making dropped weapons physical. Requires the ODE library for darkplaces and physics_ode to be enabled

User agreed to the GPLv2+.

Diff:

diff --git a/defaultXonotic.cfg b/defaultXonotic.cfg
index 89edddf..1f74617 100644
--- a/defaultXonotic.cfg
+++ b/defaultXonotic.cfg
@@ -1387,6 +1387,10 @@ alias sethostname "set menu_use_default_hostname 0; hostname $*" 

 set sv_foginterval 1 "force enable fog in regular intervals" 

+set g_ode_items 0 "1 uses ODE physics for dropped weapons, 2 for all items, requires physics_ode to be enabled" 
+set g_ode_items_damageforcescale 3 "how affected physical weapons are by damage" 
+set g_ode_items_reset 1 "return map items to their original lotation after being picked up" 
+
 // Audio track names (for old-style "cd loop NUMBER" usage)
 set _cdtrack_first "1" 
 alias _cdtrack_0 "g_cdtracks_remaplist \"$g_cdtracks_remaplist $1\"" 
diff --git a/qcsrc/server/autocvars.qh b/qcsrc/server/autocvars.qh
index 002cce3..8ec28c0 100644
--- a/qcsrc/server/autocvars.qh
+++ b/qcsrc/server/autocvars.qh
@@ -1216,3 +1216,6 @@ float autocvar_g_sandbox_object_material_velocity_min;
 float autocvar_g_sandbox_object_material_velocity_factor;
 float autocvar_g_max_info_autoscreenshot;
 float autocvar_physics_ode;
+float autocvar_g_ode_items;
+float autocvar_g_ode_items_damageforcescale;
+float autocvar_g_ode_items_reset;
diff --git a/qcsrc/server/cl_weapons.qc b/qcsrc/server/cl_weapons.qc
index 94eaccd..64f6778 100644
--- a/qcsrc/server/cl_weapons.qc
+++ b/qcsrc/server/cl_weapons.qc
@@ -302,6 +302,7 @@ string W_ThrowNewWeapon(entity own, float wpn, float doreduce, vector org, vecto
         wep.savenextthink = wep.nextthink;
         wep.nextthink = min(wep.nextthink, time + 0.5);
         wep.pickup_anyway = TRUE; // these are ALWAYS pickable
+
         return s;
     }
 }
diff --git a/qcsrc/server/miscfunctions.qc b/qcsrc/server/miscfunctions.qc
index 1359c05..71ae10b 100644
--- a/qcsrc/server/miscfunctions.qc
+++ b/qcsrc/server/miscfunctions.qc
@@ -1078,6 +1078,8 @@ void readlevelcvars(void)
         MUTATOR_ADD(mutator_vampire);
     if(cvar("g_spawn_near_teammate"))
         MUTATOR_ADD(mutator_spawn_near_teammate);
+    if(cvar("g_ode_items"))
+        MUTATOR_ADD(mutator_physical_items);

     // is this a mutator? is this a mode?
     if(cvar("g_sandbox"))
diff --git a/qcsrc/server/mutators/base.qh b/qcsrc/server/mutators/base.qh
index 137eeba..ff5de6c 100644
--- a/qcsrc/server/mutators/base.qh
+++ b/qcsrc/server/mutators/base.qh
@@ -205,3 +205,9 @@ MUTATOR_HOOKABLE(SV_StartFrame);
 MUTATOR_HOOKABLE(SetModname);
     // OUT
     string modname; // name of the mutator/mod if it warrants showing as such in the server browser
+    
+MUTATOR_HOOKABLE(Item_Spawn);
+    // called for each item being spawned on a map, including dropped weapons
+    // return 1 to remove an item
+    // INPUT
+    entity self; // the item
diff --git a/qcsrc/server/mutators/mutator_physical_items.qc b/qcsrc/server/mutators/mutator_physical_items.qc
new file mode 100644
index 0000000..60d5a09
--- /dev/null
+++ b/qcsrc/server/mutators/mutator_physical_items.qc
@@ -0,0 +1,113 @@
+.vector spawn_origin, spawn_angles;
+
+void physical_item_think()
+{
+    self.nextthink = time;
+
+    self.alpha = self.owner.alpha; // apply fading and ghosting
+
+    if(!self.cnt) // map item, not dropped
+    {
+        // copy ghost item properties
+        self.colormap = self.owner.colormap;
+        self.colormod = self.owner.colormod;
+        self.glowmod = self.owner.glowmod;
+
+        // if the item is not spawned, make sure the invisible / ghost item returns to its origin and stays there
+        if(autocvar_g_ode_items_reset)
+        {
+            if(self.owner.nextthink > time) // awaiting respawn
+            {
+                setorigin(self, self.spawn_origin);
+                self.angles = self.spawn_angles;
+                self.solid = SOLID_NOT;
+                self.movetype = MOVETYPE_NONE;
+            }
+            else
+            {
+                self.solid = SOLID_CORPSE;
+                self.movetype = MOVETYPE_PHYSICS;
+            }
+        }
+    }
+
+    if(!self.owner.modelindex)
+        remove(self); // the real item is gone, remove this
+}
+
+void physical_item_touch()
+{
+    if(!self.cnt) // not for dropped items
+    if (ITEM_TOUCH_NEEDKILL())
+    {
+        setorigin(self, self.spawn_origin);
+        self.angles = self.spawn_angles;
+    }
+}
+
+void physical_item_damage(entity inflictor, entity attacker, float damage, float deathtype, vector hitloc, vector force)
+{
+    if(!self.cnt) // not for dropped items
+    if(ITEM_DAMAGE_NEEDKILL(deathtype))
+    {
+        setorigin(self, self.spawn_origin);
+        self.angles = self.spawn_angles;
+    }
+}
+
+MUTATOR_HOOKFUNCTION(item_spawning)
+{
+    if(self.owner == world && autocvar_g_ode_items <= 1)
+        return FALSE;
+    if (self.spawnflags & 1) // floating item
+        return FALSE;
+
+    // The actual item can't be physical and trigger at the same time, so make it invisible and use a second entity for physics.
+    // Ugly hack, but unless SOLID_TRIGGER is gotten to work with MOVETYPE_PHYSICS in the engine it can't be fixed.
+    entity wep;
+    wep = spawn();
+    setmodel(wep, self.model);
+    setsize(wep, self.mins, self.maxs);
+    setorigin(wep, self.origin);
+    wep.angles = self.angles;
+    wep.velocity = self.velocity;
+
+    wep.owner = self;
+    wep.solid = SOLID_CORPSE;
+    wep.movetype = MOVETYPE_PHYSICS;
+    wep.takedamage = DAMAGE_AIM;
+    wep.effects |= EF_NOMODELFLAGS; // disable the spinning
+    wep.colormap = self.owner.colormap;
+    wep.glowmod = self.owner.glowmod;
+    wep.damageforcescale = autocvar_g_ode_items_damageforcescale;
+    wep.dphitcontentsmask = self.dphitcontentsmask;
+    wep.cnt = (self.owner != world);
+
+    wep.think = physical_item_think;
+    wep.nextthink = time;
+    wep.touch = physical_item_touch;
+    wep.event_damage = physical_item_damage;
+
+    wep.spawn_origin = self.origin;
+    wep.spawn_angles = self.angles;
+
+    self.effects |= EF_NODRAW; // hide the original weapon
+    self.movetype = MOVETYPE_FOLLOW;
+    self.aiment = wep; // attach the original weapon
+
+    return FALSE;
+}
+
+MUTATOR_DEFINITION(mutator_physical_items)
+{
+    // check if we have a physics engine
+    if not(autocvar_physics_ode && checkextension("DP_PHYSICS_ODE"))
+    {
+        dprint("Warning: Physical items are enabled but no physics engine can be used. Reverting to old items.\n");
+        return FALSE;
+    }
+
+    MUTATOR_HOOK(Item_Spawn, item_spawning, CBC_ORDER_ANY);
+
+    return FALSE;
+}
diff --git a/qcsrc/server/mutators/mutators.qh b/qcsrc/server/mutators/mutators.qh
index bc3c3fb..4d019ee 100644
--- a/qcsrc/server/mutators/mutators.qh
+++ b/qcsrc/server/mutators/mutators.qh
@@ -10,5 +10,6 @@ MUTATOR_DECLARATION(mutator_rocketflying);
 MUTATOR_DECLARATION(mutator_vampire);
 MUTATOR_DECLARATION(mutator_spawn_near_teammate);
 MUTATOR_DECLARATION(mutator_spawn_near_teammate);
+MUTATOR_DECLARATION(mutator_physical_items);

 MUTATOR_DECLARATION(sandbox);
diff --git a/qcsrc/server/progs.src b/qcsrc/server/progs.src
index 0dbe537..d8210e7 100644
--- a/qcsrc/server/progs.src
+++ b/qcsrc/server/progs.src
@@ -215,6 +215,7 @@ mutators/mutator_dodging.qc
 mutators/mutator_rocketflying.qc
 mutators/mutator_vampire.qc
 mutators/mutator_spawn_near_teammate.qc
+mutators/mutator_physical_items.qc
 mutators/sandbox.qc

 ../warpzonelib/anglestransform.qc
diff --git a/qcsrc/server/t_items.qc b/qcsrc/server/t_items.qc
index 5b9a2e5..e1d405d 100644
--- a/qcsrc/server/t_items.qc
+++ b/qcsrc/server/t_items.qc
@@ -924,6 +924,14 @@ void StartItem (string itemmodel, string pickupsound, float defaultrespawntime,
     }
     else
         Item_Reset();
+
+    // call this hook after everything else has been done
+    if(MUTATOR_CALLHOOK(Item_Spawn))
+    {
+        startitem_failed = TRUE;
+        remove(self);
+        return;
+    }
 }

 /* replace items in minstagib

Associated revisions

Revision 4b252b30
Added by divVerent over 1 year ago

various mutator system fixes; add proper rollback of failed add, fixes #1145

History

#1 Updated by merlijn about 2 years ago

  • Status changed from New to In Progress

Who's going to volunteer to test this so it's at least safe to merge?

#2 Updated by MirceaKitsune about 2 years ago

Yes, this needs to be tested first. Especially since tZork merged his CSQC weapons since the change. No, the physics cannot be moved to the client since they also affect the weapon trigger, and the server decides when you touched a weapon in order to pick it up. So it likely must stay server-side, but needs to be tested again.

#3 Updated by divVerent over 1 year ago

Did anyone test this?

#4 Updated by MirceaKitsune over 1 year ago

I tested it when I merge requested it. But in several months no. I probably don't even have the ODE lib set up for Darkplaces on Linux so if anyone else wishes to they are welcome.

#5 Updated by Samual over 1 year ago

Well, it clearly has no negative side effects with the mutator disabled-- but dunno if it actually works, I don't know how to get ODE working on my environment.

#6 Updated by divVerent over 1 year ago

  • Status changed from In Progress to Resolved
  • % Done changed from 0 to 100

Applied in changeset xonotic:xonotic-data|commit:4b252b30e38b09fcb9bdf37673b3c567a3e5670c.

Also available in: Atom PDF