/// game items.
/// \copyright GNU GPLv2 or any later version.
-#include <common/t_items.qh>
+#include <server/mutators/_mod.qh>
+#include <common/weapons/all.qh>
+#include <common/mapobjects/subs.qh>
.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,
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);
return false;
}
item.gravity = 1;
- setorigin(item, position);
item.velocity = vel;
SUB_SetFade(item, time + time_to_live, 1);
return true;
bool Item_IsLoot(entity item)
{
- return item.m_isloot || (item.classname == "droppedweapon");
+ return item.m_isloot || item.classname == "droppedweapon";
}
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)