]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/server/items.qc
Merge branch 'master' into Lyberta/KillSound
[xonotic/xonotic-data.pk3dir.git] / qcsrc / server / items.qc
1 #include "items.qh"
2
3 /// \file
4 /// \brief Source file that contains implementation of the functions related to
5 /// game items.
6 /// \copyright GNU GPLv2 or any later version.
7
8 #include "g_subs.qh"
9 #include <common/weapons/all.qh>
10
11 .bool m_isloot; ///< Holds whether item is loot.
12 /// \brief Holds whether strength, shield or superweapon timers expire while
13 /// this item is on the ground.
14 .bool m_isexpiring;
15
16 entity Item_Create(string class_name, vector position, bool no_align)
17 {
18         entity item = spawn();
19         item.classname = class_name;
20         item.spawnfunc_checked = true;
21         setorigin(item, position);
22         item.noalign = no_align;
23         Item_Initialize(item, class_name);
24         if (wasfreed(item))
25         {
26                 return NULL;
27         }
28         return item;
29 }
30
31 void Item_Initialize(entity item, string class_name)
32 {
33         FOREACH(Weapons, it.m_canonical_spawnfunc == class_name,
34         {
35                 weapon_defaultspawnfunc(item, it);
36                 return;
37         });
38         FOREACH(Items, it.m_canonical_spawnfunc == class_name,
39         {
40                 StartItem(item, it);
41                 return;
42         });
43         LOG_FATALF("Item_Initialize: Invalid classname: %s", class_name);
44 }
45
46 entity Item_CreateLoot(string class_name, vector position, vector vel,
47         float time_to_live)
48 {
49         entity item = spawn();
50         if (!Item_InitializeLoot(item, class_name, position, vel, time_to_live))
51         {
52                 return NULL;
53         }
54         return item;
55 }
56
57 bool Item_InitializeLoot(entity item, string class_name, vector position,
58         vector vel, float time_to_live)
59 {
60         item.classname = class_name;
61         Item_SetLoot(item, true);
62         item.noalign = true;
63         setorigin(item, position);
64         item.pickup_anyway = true;
65         item.spawnfunc_checked = true;
66         Item_Initialize(item, class_name);
67         if (wasfreed(item))
68         {
69                 return false;
70         }
71         item.gravity = 1;
72         item.velocity = vel;
73         SUB_SetFade(item, time + time_to_live, 1);
74         return true;
75 }
76
77 bool Item_IsLoot(entity item)
78 {
79         return item.m_isloot;
80 }
81
82 void Item_SetLoot(entity item, bool loot)
83 {
84         item.m_isloot = loot;
85 }
86
87 bool Item_ShouldKeepPosition(entity item)
88 {
89         return item.noalign || (item.spawnflags & 1);
90 }
91
92 bool Item_IsExpiring(entity item)
93 {
94         return item.m_isexpiring;
95 }
96
97 void Item_SetExpiring(entity item, bool expiring)
98 {
99         item.m_isexpiring = expiring;
100 }
101
102 // Compatibility spawn functions
103
104 // FIXME: in Quake this is green armor, in Xonotic maps it is an armor shard
105 SPAWNFUNC_ITEM(item_armor1, ITEM_ArmorSmall)
106
107 SPAWNFUNC_ITEM(item_armor25, ITEM_ArmorMega)
108
109 SPAWNFUNC_ITEM(item_armor_large, ITEM_ArmorMega)
110
111 SPAWNFUNC_ITEM(item_health1, ITEM_HealthSmall)
112
113 SPAWNFUNC_ITEM(item_health25, ITEM_HealthMedium)
114
115 SPAWNFUNC_ITEM(item_health_large, ITEM_HealthBig)
116
117 SPAWNFUNC_ITEM(item_health100, ITEM_HealthMega)
118
119 SPAWNFUNC_ITEM(item_quad, ITEM_Strength)