]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/server/items/spawning.qc
f03f9e2173d1e3a9fdf453f62af4a46c9defe9fd
[xonotic/xonotic-data.pk3dir.git] / qcsrc / server / items / spawning.qc
1 #include "spawning.qh"
2
3 /// \file
4 /// \brief Source file that contains implementation of the functions related to
5 /// creation of game items.
6 /// \copyright GNU GPLv2 or any later version.
7
8 #include <common/mapobjects/subs.qh>
9 #include <common/weapons/all.qh>
10 #include <server/items/items.qh>
11 #include <server/mutators/_mod.qh>
12 #include <server/weapons/spawning.qh>
13 #include <server/world.qh>
14
15 .bool m_isloot; ///< Holds whether item is loot.
16 /// \brief Holds whether strength, shield or superweapon timers expire while
17 /// this item is on the ground.
18 .bool m_isexpiring;
19
20 bool Item_IsDefinitionAllowed(entity definition)
21 {
22         return !MUTATOR_CALLHOOK(FilterItemDefinition, definition);
23 }
24
25 // An optimised and generic way to initialise items (loot or permanent)
26 // required field: itemdef (faster, preferred) OR classname
27 // optional fields: origin, velocity, lifetime, noalign
28 // lifetime < 0 means permanent (not loot), lifetime > 0 overrides the default
29 // permanent items only: noalign means the item is suspended (won't drop to floor)
30 bool Item_Initialise(entity item)
31 {
32         if (item.lifetime >= 0)
33         {
34                 Item_SetLoot(item, true);
35                 item.pickup_anyway = true; // these are ALWAYS pickable
36         }
37
38         if (item.itemdef) // no search required
39         {
40                 if (item.itemdef.instanceOfWeapon)
41                         weapon_defaultspawnfunc(item, item.itemdef);
42                 else
43                         StartItem(item, item.itemdef);
44         }
45         else // fall back to classname search
46         {
47                 FOREACH(Weapons, it.m_canonical_spawnfunc == item.classname,
48                 {
49                         weapon_defaultspawnfunc(item, it);
50                         goto classname_found;
51                 });
52                 FOREACH(Items, it.m_canonical_spawnfunc == item.classname,
53                 {
54                         StartItem(item, it);
55                         goto classname_found;
56                 });
57                 LOG_FATALF("Item_Initialize: Invalid classname: %s", item.classname);
58                 LABEL(classname_found)
59         }
60
61         if (wasfreed(item))
62                 return false;
63
64         // StartItem sets the default .wait expiry time which is respected by Item_Think()
65         if (item.lifetime > 0)
66                 item.wait = time + item.lifetime;
67
68         item.spawnfunc_checked = true;
69         return true;
70 }
71
72 bool Item_IsLoot(entity item)
73 {
74         return item.m_isloot || item.classname == "droppedweapon";
75 }
76
77 void Item_SetLoot(entity item, bool loot)
78 {
79         item.m_isloot = loot;
80 }
81
82 bool Item_ShouldKeepPosition(entity item)
83 {
84         return item.noalign || (item.spawnflags & 1);
85 }
86
87 bool Item_IsExpiring(entity item)
88 {
89         return item.m_isexpiring;
90 }
91
92 void Item_SetExpiring(entity item, bool expiring)
93 {
94         item.m_isexpiring = expiring;
95 }
96
97 // Compatibility spawn functions
98
99 // in Quake this is green armor, in Xonotic maps it is an armor shard
100 SPAWNFUNC_ITEM_COND(item_armor1, autocvar_sv_mapformat_is_quake3, ITEM_ArmorSmall, ITEM_ArmorMedium)
101 SPAWNFUNC_ITEM(item_armor25, ITEM_ArmorMega) // Nexuiz used item_armor25 to spawn a Mega Armor
102 SPAWNFUNC_ITEM(item_health1, ITEM_HealthSmall)
103 SPAWNFUNC_ITEM(item_health25, ITEM_HealthMedium)
104 SPAWNFUNC_ITEM(item_health100, ITEM_HealthMega)
105 SPAWNFUNC_ITEM(item_armor_large, ITEM_ArmorMega)
106 SPAWNFUNC_ITEM(item_health_large, ITEM_HealthBig)