]> git.rm.cloudns.org Git - xonotic/xonotic-data.pk3dir.git/commitdiff
RandomItems mutator: simplify item initialisation using new function
authorbones_was_here <bones_was_here@xonotic.au>
Sun, 18 Jun 2023 22:17:42 +0000 (08:17 +1000)
committerbones_was_here <bones_was_here@xonotic.au>
Wed, 21 Jun 2023 10:59:04 +0000 (20:59 +1000)
qcsrc/common/mutators/mutator/random_items/sv_random_items.qc

index c0fa7ff9697b7f1dd3d004054e032cd5ae2ad6c2..ed2bd91861d9afc3ba1f9e7993f7df095ad92193 100644 (file)
@@ -266,36 +266,18 @@ entity RandomItems_ReplaceMapItem(entity item)
                return NULL;
        }
        random_items_is_spawning = true;
-       entity new_item;
-       if (!MUTATOR_IS_ENABLED(ok))
-       {
-               // TODO: doesn't copy many fields from items
-               new_item = Item_Create(strzone(new_classname), item.origin,
-                       Item_ShouldKeepPosition(item));
-               random_items_is_spawning = false;
-               if (new_item == NULL)
-               {
-                       return NULL;
-               }
-       }
-       else
-       {
-               new_item = spawn();
-               Item_CopyFields(item, new_item);
-               new_item.classname = strzone(new_classname);
+
+       entity new_item = spawn();
+       Item_CopyFields(item, new_item);
+       new_item.classname = strzone(new_classname);
+       new_item.lifetime = -1; // permanent (not loot)
+       if (MUTATOR_IS_ENABLED(ok))
                new_item.ok_item = true;
-               Item_Initialize(new_item, new_classname);
-               random_items_is_spawning = false;
-               if (wasfreed(new_item))
-               {
-                       return NULL;
-               }
-       }
-       if (item.team)
-       {
-               new_item.team = item.team;
-       }
-       return new_item;
+       Item_Initialise(new_item);
+
+       random_items_is_spawning = false;
+
+       return wasfreed(new_item) ? NULL : new_item;
 }
 
 /// \brief Spawns a random loot item.
@@ -312,19 +294,16 @@ void RandomItems_SpawnLootItem(vector position)
        spread.z = autocvar_g_random_loot_spread / 2;
        spread += randomvec() * autocvar_g_random_loot_spread;
        random_items_is_spawning = true;
-       if (!MUTATOR_IS_ENABLED(ok))
-       {
-               Item_CreateLoot(class_name, position, spread,
-                       autocvar_g_random_loot_time);
-       }
-       else
-       {
-               entity item = spawn();
+
+       entity item = spawn();
+       item.classname = class_name;
+       item.origin = position;
+       item.velocity = spread;
+       item.lifetime = autocvar_g_random_loot_time;
+       if (MUTATOR_IS_ENABLED(ok))
                item.ok_item = true;
-               item.classname = class_name;
-               Item_InitializeLoot(item, class_name, position, spread,
-                       autocvar_g_random_loot_time);
-       }
+       Item_Initialise(item);
+
        random_items_is_spawning = false;
 }