X-Git-Url: http://de.git.xonotic.org/?a=blobdiff_plain;f=qcsrc%2Fserver%2Fitems.qc;h=04b0ba41d596e05d1c40addc88b06a3e8c2640c2;hb=f41f81f37e3ecf5a2d14f7bc7ffd7bbf09fff32e;hp=eb0d9966603cb9dd8b366d9d16d5fc4acf42055f;hpb=1ca73fe4276fe1b0b1e20e3c981f438ad0054c88;p=xonotic%2Fxonotic-data.pk3dir.git diff --git a/qcsrc/server/items.qc b/qcsrc/server/items.qc index eb0d99666..04b0ba41d 100644 --- a/qcsrc/server/items.qc +++ b/qcsrc/server/items.qc @@ -5,216 +5,71 @@ /// game items. /// \copyright GNU GPLv2 or any later version. -#include +#include "g_subs.qh" +#include "mutators/events.qh" +#include .bool m_isloot; ///< Holds whether item is loot. +/// \brief Holds whether strength, shield or superweapon timers expire while +/// this item is on the ground. +.bool m_isexpiring; -void Item_Initialize(entity item, string class_name) +entity Item_FindDefinition(string class_name) { - switch (class_name) + FOREACH(Items, it.m_canonical_spawnfunc == class_name, + { + return it; + }); + FOREACH(Weapons, it.m_canonical_spawnfunc == class_name, { - case "item_health_small": - { - StartItem(item, ITEM_HealthSmall); - return; - } - case "item_health_medium": - { - StartItem(item, ITEM_HealthMedium); - return; - } - case "item_health_big": - case "item_health_large": - { - StartItem(item, ITEM_HealthBig); - return; - } - case "item_health_mega": - { - StartItem(item, ITEM_HealthMega); - return; - } - case "item_armor_small": - { - StartItem(item, ITEM_ArmorSmall); - return; - } - case "item_armor_medium": - { - StartItem(item, ITEM_ArmorMedium); - return; - } - case "item_armor_big": - case "item_armor_large": - { - StartItem(item, ITEM_ArmorBig); - return; - } - case "item_armor_mega": - { - StartItem(item, ITEM_ArmorMega); - return; - } - case "item_shells": - { - StartItem(item, ITEM_Shells); - return; - } - case "item_bullets": - { - StartItem(item, ITEM_Bullets); - return; - } - case "item_rockets": - { - StartItem(item, ITEM_Rockets); - return; - } - case "item_cells": - { - StartItem(item, ITEM_Cells); - return; - } - case "item_plasma": - { - StartItem(item, ITEM_Plasma); - return; - } - case "item_fuel": - { - StartItem(item, ITEM_JetpackFuel); - return; - } - case "weapon_blaster": - case "weapon_laser": - { - weapon_defaultspawnfunc(item, WEP_BLASTER); - return; - } - case "weapon_shotgun": - { - weapon_defaultspawnfunc(item, WEP_SHOTGUN); - return; - } - case "weapon_machinegun": - case "weapon_uzi": - { - weapon_defaultspawnfunc(item, WEP_MACHINEGUN); - return; - } - case "weapon_mortar": - case "weapon_grenadelauncher": - { - weapon_defaultspawnfunc(item, WEP_MORTAR); - return; - } - case "weapon_electro": - { - weapon_defaultspawnfunc(item, WEP_ELECTRO); - return; - } - case "weapon_crylink": - { - weapon_defaultspawnfunc(item, WEP_CRYLINK); - return; - } - case "weapon_vortex": - case "weapon_nex": - { - weapon_defaultspawnfunc(item, WEP_VORTEX); - return; - } - case "weapon_hagar": - { - weapon_defaultspawnfunc(item, WEP_HAGAR); - return; - } - case "weapon_devastator": - case "weapon_rocketlauncher": - { - weapon_defaultspawnfunc(item, WEP_DEVASTATOR); - return; - } - case "weapon_shockwave": - { - weapon_defaultspawnfunc(item, WEP_SHOCKWAVE); - return; - } - case "weapon_arc": - { - weapon_defaultspawnfunc(item, WEP_ARC); - return; - } - case "weapon_hook": - { - weapon_defaultspawnfunc(item, WEP_HOOK); - return; - } - case "weapon_tuba": - { - weapon_defaultspawnfunc(item, WEP_TUBA); - return; - } - case "weapon_porto": - { - weapon_defaultspawnfunc(item, WEP_PORTO); - return; - } - case "weapon_fireball": - { - weapon_defaultspawnfunc(item, WEP_FIREBALL); - return; - } - case "weapon_minelayer": - { - weapon_defaultspawnfunc(item, WEP_MINE_LAYER); - return; - } - case "weapon_hlac": - { - weapon_defaultspawnfunc(item, WEP_HLAC); - return; - } - case "weapon_rifle": - case "weapon_campingrifle": - case "weapon_sniperrifle": - { - weapon_defaultspawnfunc(item, WEP_RIFLE); - return; - } - case "weapon_seeker": - { - weapon_defaultspawnfunc(item, WEP_SEEKER); - return; - } - case "weapon_vaporizer": - case "weapon_minstanex": - { - weapon_defaultspawnfunc(item, WEP_VAPORIZER); - return; - } - case "item_strength": - { - StartItem(item, ITEM_Strength); - return; - } - case "item_invincible": - { - StartItem(item, ITEM_Shield); - return; - } - case "item_fuel_regen": - { - StartItem(item, ITEM_JetpackRegen); - return; - } - case "item_jetpack": - { - StartItem(item, ITEM_Jetpack); - return; - } + return it.m_pickup; + }); + return NULL; +} + +bool Item_IsAllowed(string class_name) +{ + entity definition = Item_FindDefinition(class_name); + if (definition == NULL) + { + return false; } - error("Item_Initialize: Invalid classname"); + return Item_IsDefinitionAllowed(definition); +} + +bool Item_IsDefinitionAllowed(entity definition) +{ + return !MUTATOR_CALLHOOK(FilterItemDefinition, definition); +} + +entity Item_Create(string class_name, vector position, bool no_align) +{ + entity item = spawn(); + item.classname = class_name; + item.spawnfunc_checked = true; + setorigin(item, position); + item.noalign = no_align; + Item_Initialize(item, class_name); + if (wasfreed(item)) + { + return NULL; + } + return item; +} + +void Item_Initialize(entity item, string class_name) +{ + FOREACH(Weapons, it.m_canonical_spawnfunc == class_name, + { + weapon_defaultspawnfunc(item, it); + return; + }); + FOREACH(Items, it.m_canonical_spawnfunc == class_name, + { + StartItem(item, it); + return; + }); + LOG_FATALF("Item_Initialize: Invalid classname: %s", class_name); } entity Item_CreateLoot(string class_name, vector position, vector vel, @@ -234,6 +89,7 @@ bool Item_InitializeLoot(entity item, string class_name, vector position, item.classname = class_name; Item_SetLoot(item, true); item.noalign = true; + setorigin(item, position); item.pickup_anyway = true; item.spawnfunc_checked = true; Item_Initialize(item, class_name); @@ -242,7 +98,6 @@ bool Item_InitializeLoot(entity item, string class_name, vector position, return false; } item.gravity = 1; - setorigin(item, position); item.velocity = vel; SUB_SetFade(item, time + time_to_live, 1); return true; @@ -250,10 +105,44 @@ bool Item_InitializeLoot(entity item, string class_name, vector position, bool Item_IsLoot(entity item) { - return item.m_isloot || (item.classname == "droppedweapon"); + return item.m_isloot; } void Item_SetLoot(entity item, bool loot) { item.m_isloot = loot; } + +bool Item_ShouldKeepPosition(entity item) +{ + return item.noalign || (item.spawnflags & 1); +} + +bool Item_IsExpiring(entity item) +{ + return item.m_isexpiring; +} + +void Item_SetExpiring(entity item, bool expiring) +{ + item.m_isexpiring = expiring; +} + +// Compatibility spawn functions + +// FIXME: in Quake this is green armor, in Xonotic maps it is an armor shard +SPAWNFUNC_ITEM(item_armor1, ITEM_ArmorSmall) + +SPAWNFUNC_ITEM(item_armor25, ITEM_ArmorMega) + +SPAWNFUNC_ITEM(item_armor_large, ITEM_ArmorMega) + +SPAWNFUNC_ITEM(item_health1, ITEM_HealthSmall) + +SPAWNFUNC_ITEM(item_health25, ITEM_HealthMedium) + +SPAWNFUNC_ITEM(item_health_large, ITEM_HealthBig) + +SPAWNFUNC_ITEM(item_health100, ITEM_HealthMega) + +SPAWNFUNC_ITEM(item_quad, ITEM_Strength)