]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/server/items.qc
Merge branch 'master' into Lyberta/RandomItems
[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)
17 {
18         entity item = spawn();
19         item.classname = class_name;
20         item.spawnfunc_checked = true;
21         Item_Initialize(item, class_name);
22         if (wasfreed(item))
23         {
24                 return NULL;
25         }
26         setorigin(item, position);
27         return item;
28 }
29
30 void Item_Initialize(entity item, string class_name)
31 {
32         FOREACH(Weapons, it.m_canonical_spawnfunc == class_name,
33         {
34                 weapon_defaultspawnfunc(item, it);
35                 return;
36         });
37         FOREACH(Items, it.m_canonical_spawnfunc == class_name,
38         {
39                 StartItem(item, it);
40                 return;
41         });
42         LOG_FATALF("Item_Initialize: Invalid classname: %s", class_name);
43 }
44
45 entity Item_CreateLoot(string class_name, vector position, vector vel,
46         float time_to_live)
47 {
48         entity item = spawn();
49         if (!Item_InitializeLoot(item, class_name, position, vel, time_to_live))
50         {
51                 return NULL;
52         }
53         return item;
54 }
55
56 bool Item_InitializeLoot(entity item, string class_name, vector position,
57         vector vel, float time_to_live)
58 {
59         item.classname = class_name;
60         Item_SetLoot(item, true);
61         item.noalign = true;
62         item.pickup_anyway = true;
63         item.spawnfunc_checked = true;
64         Item_Initialize(item, class_name);
65         if (wasfreed(item))
66         {
67                 return false;
68         }
69         item.gravity = 1;
70         setorigin(item, position);
71         item.velocity = vel;
72         SUB_SetFade(item, time + time_to_live, 1);
73         return true;
74 }
75
76 bool Item_IsLoot(entity item)
77 {
78         return item.m_isloot;
79 }
80
81 void Item_SetLoot(entity item, bool loot)
82 {
83         item.m_isloot = loot;
84 }
85
86 bool Item_IsExpiring(entity item)
87 {
88         return item.m_isexpiring;
89 }
90
91 void Item_SetExpiring(entity item, bool expiring)
92 {
93         item.m_isexpiring = expiring;
94 }
95
96 // Compatibility spawn functions
97
98 // FIXME: in Quake this is green armor, in Xonotic maps it is an armor shard
99 SPAWNFUNC_ITEM(item_armor1, ITEM_ArmorSmall)
100
101 SPAWNFUNC_ITEM(item_armor25, ITEM_ArmorMega)
102
103 SPAWNFUNC_ITEM(item_armor_large, ITEM_ArmorMega)
104
105 SPAWNFUNC_ITEM(item_health1, ITEM_HealthSmall)
106
107 SPAWNFUNC_ITEM(item_health25, ITEM_HealthMedium)
108
109 SPAWNFUNC_ITEM(item_health_large, ITEM_HealthBig)
110
111 SPAWNFUNC_ITEM(item_health100, ITEM_HealthMega)
112
113 SPAWNFUNC_ITEM(item_quad, ITEM_Strength)