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