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