]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blobdiff - qcsrc/server/mutators/sandbox.qc
Particle count should always be a whole number. Also add a code comment
[xonotic/xonotic-data.pk3dir.git] / qcsrc / server / mutators / sandbox.qc
index 39e01519ef2e1bb178e446b5c18066b8e5e6400e..9afe34ffb3c09ccd3a8270c744d30b9f44398e68 100644 (file)
@@ -1,6 +1,7 @@
 .string object_clipboard;
 .float material;
 
+const float MATERIAL_NONE = 0;
 const float MATERIAL_METAL = 1;
 const float MATERIAL_STONE = 2;
 const float MATERIAL_WOOD = 3;
@@ -14,22 +15,31 @@ void sandbox_Object_Touch()
        if(self.touch_timer > time)
                return; // don't execute each frame
        self.touch_timer = time + 0.1;
-       if not(vlen(self.velocity) >= autocvar_g_sandbox_object_matvel || vlen(other.velocity) >= autocvar_g_sandbox_object_matvel)
+       if not(vlen(self.velocity) > autocvar_g_sandbox_object_material_velocity_min || vlen(other.velocity) > autocvar_g_sandbox_object_material_velocity_min)
                return; // impact not strong enough
 
+       // make particle count and sound intensity depend on impact speed
+       float intensity;
+       intensity = (vlen(self.velocity) + vlen(other.velocity)) / 2;
+       intensity = bound(0, intensity * autocvar_g_sandbox_object_material_velocity_factor, 1);
+
        switch(self.material)
        {
                case MATERIAL_METAL:
-                       sound(self, CH_TRIGGER, strcat("object/impact_metal_", ftos(ceil(random() * 5)) , ".ogg"), VOL_BASE, ATTN_NORM);
+                       sound(self, CH_TRIGGER, strcat("object/impact_metal_", ftos(ceil(random() * 5)) , ".ogg"), VOL_BASE * intensity, ATTN_NORM);
+                       pointparticles(particleeffectnum("impact_metal"), self.origin, '0 0 0', ceil(intensity * 10)); // allow a count from 1 to 10
                        break;
                case MATERIAL_STONE:
-                       sound(self, CH_TRIGGER, strcat("object/impact_stone_", ftos(ceil(random() * 5)) , ".ogg"), VOL_BASE, ATTN_NORM);
+                       sound(self, CH_TRIGGER, strcat("object/impact_stone_", ftos(ceil(random() * 5)) , ".ogg"), VOL_BASE * intensity, ATTN_NORM);
+                       pointparticles(particleeffectnum("impact_stone"), self.origin, '0 0 0', ceil(intensity * 10)); // allow a count from 1 to 10
                        break;
                case MATERIAL_WOOD:
-                       sound(self, CH_TRIGGER, strcat("object/impact_wood_", ftos(ceil(random() * 5)) , ".ogg"), VOL_BASE, ATTN_NORM);
+                       sound(self, CH_TRIGGER, strcat("object/impact_wood_", ftos(ceil(random() * 5)) , ".ogg"), VOL_BASE * intensity, ATTN_NORM);
+                       pointparticles(particleeffectnum("impact_wood"), self.origin, '0 0 0', ceil(intensity * 10)); // allow a count from 1 to 10
                        break;
                case MATERIAL_FLESH:
-                       sound(self, CH_TRIGGER, strcat("object/impact_flesh_", ftos(ceil(random() * 5)) , ".ogg"), VOL_BASE, ATTN_NORM);
+                       sound(self, CH_TRIGGER, strcat("object/impact_flesh_", ftos(ceil(random() * 5)) , ".ogg"), VOL_BASE * intensity, ATTN_NORM);
+                       pointparticles(particleeffectnum("impact_flesh"), self.origin, '0 0 0', ceil(intensity * 10)); // allow a count from 1 to 10
                        break;
                default:
                        break;
@@ -72,7 +82,7 @@ entity sandbox_SpawnObject()
        e.movetype = MOVETYPE_TOSS;
        e.frame = 0;
        e.skin = 0;
-       e.material = MATERIAL_METAL;
+       e.material = MATERIAL_NONE;
 
        e.touch = sandbox_Object_Touch;
 
@@ -85,9 +95,10 @@ entity sandbox_SpawnObject()
        return e;
 }
 
-void sandbox_Storage_Save(entity e, string s)
+string sandbox_Storage_Save(entity e)
 {
        // save object properties
+       string s;
 
        s = strcat(e.model, " ");
        s = strcat(s, ftos(e.skin), " ");
@@ -99,6 +110,8 @@ void sandbox_Storage_Save(entity e, string s)
        s = strcat(s, ftos(e.movetype), " ");
        s = strcat(s, ftos(e.damageforcescale), " ");
        s = strcat(s, ftos(e.material), " ");
+
+       return s;
 }
 
 void sandbox_Storage_Load(entity e, string s)
@@ -232,8 +245,7 @@ MUTATOR_HOOKFUNCTION(sandbox_PlayerCommand)
                                {
                                        if(self.object_clipboard)
                                                strunzone(self.object_clipboard);
-                                       sandbox_Storage_Save(e, self.object_clipboard);
-                                       self.object_clipboard = strzone(self.object_clipboard);
+                                       self.object_clipboard = strzone(sandbox_Storage_Save(e));
 
                                        print_to(self, "Object copied to clipboard");
                                        return TRUE;