From: bones_was_here Date: Sun, 18 Jun 2023 22:17:42 +0000 (+1000) Subject: RandomItems mutator: simplify item initialisation using new function X-Git-Url: https://git.rm.cloudns.org/?a=commitdiff_plain;h=b9515b59597aae19247d1b012c68c26049d44c4b;p=xonotic%2Fxonotic-data.pk3dir.git RandomItems mutator: simplify item initialisation using new function --- diff --git a/qcsrc/common/mutators/mutator/random_items/sv_random_items.qc b/qcsrc/common/mutators/mutator/random_items/sv_random_items.qc index c0fa7ff96..ed2bd9186 100644 --- a/qcsrc/common/mutators/mutator/random_items/sv_random_items.qc +++ b/qcsrc/common/mutators/mutator/random_items/sv_random_items.qc @@ -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; }