]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/server/weapons/spawning.qc
Removed references to droppedweapon.
[xonotic/xonotic-data.pk3dir.git] / qcsrc / server / weapons / spawning.qc
1 #include "spawning.qh"
2
3 #include "weaponsystem.qh"
4 #include "../resources.qh"
5 #include "../mutators/_mod.qh"
6 #include <common/t_items.qh>
7 #include <server/items.qh>
8 #include <common/weapons/_all.qh>
9
10 string W_Apply_Weaponreplace(string in)
11 {
12         string out = "";
13         FOREACH_WORD(in, true, {
14                 string replacement = "";
15                 Weapon w = Weapons_fromstr(it);
16                 if (w)
17                 {
18             replacement = w.weaponreplace;
19             if (replacement == "") replacement = it;
20                 }
21                 if (replacement == "0") continue;
22                 out = cons(out, replacement);
23         });
24         return out;
25 }
26
27 void weapon_defaultspawnfunc(entity this, Weapon e)
28 {
29         Weapon wpn = e;
30         e = wpn = wpn.m_spawnfunc_hookreplace(wpn, this);
31         this.classname = wpn.m_canonical_spawnfunc;
32         if (!Item_IsLoot(this) && this.classname != "replacedweapon")
33         {
34                 if (e.spawnflags & WEP_FLAG_MUTATORBLOCKED)
35                 {
36                         LOG_WARNF("Attempted to spawn a mutator-blocked weapon rejected: prvm_edict server %i", this);
37                         startitem_failed = true;
38                         return;
39                 }
40
41                 string s = W_Apply_Weaponreplace(e.netname);
42                 MUTATOR_CALLHOOK(SetWeaponreplace, this, e, s);
43                 s = M_ARGV(2, string);
44                 if (s == "")
45                 {
46                         delete(this);
47                         startitem_failed = true;
48                         return;
49                 }
50                 int t = tokenize_console(s);
51                 if (t >= 2)
52                 {
53                         this.team = --internalteam;
54                         for (int i = 1; i < t; ++i)
55                         {
56                                 s = argv(i);
57                                 FOREACH(Weapons, it != WEP_Null, {
58                                         if(it.netname == s)
59                                         {
60                                                 entity replacement = spawn();
61                                                 copyentity(this, replacement);
62                                                 replacement.classname = "replacedweapon";
63                                                 weapon_defaultspawnfunc(replacement, it);
64                                                 break;
65                                         }
66                                 });
67                         }
68                 }
69                 if (t >= 1) // always the case!
70                 {
71                         s = argv(0);
72                         wpn = WEP_Null;
73                         FOREACH(Weapons, it != WEP_Null, {
74                                 if(it.netname == s)
75                                 {
76                                         wpn = it;
77                                         break;
78                                 }
79                         });
80                 }
81                 if (wpn == WEP_Null)
82                 {
83                         delete(this);
84                         startitem_failed = true;
85                         return;
86                 }
87         }
88
89         if (!this.respawntime)
90         {
91                 if (wpn.spawnflags & WEP_FLAG_SUPERWEAPON)
92                 {
93                         this.respawntime = g_pickup_respawntime_superweapon;
94                         this.respawntimejitter = g_pickup_respawntimejitter_superweapon;
95                 }
96                 else
97                 {
98                         this.respawntime = g_pickup_respawntime_weapon;
99                         this.respawntimejitter = g_pickup_respawntimejitter_weapon;
100                 }
101         }
102
103         if (wpn.spawnflags & WEP_FLAG_SUPERWEAPON)
104                 if (!this.superweapons_finished)
105                         this.superweapons_finished = autocvar_g_balance_superweapons_time;
106
107         // if we don't already have ammo, give us some ammo
108         if ((wpn.ammo_type != RESOURCE_NONE) && !GetResourceAmount(this, wpn.ammo_type))
109         {
110                 switch (wpn.ammo_type)
111                 {
112                         case RESOURCE_SHELLS:  SetResourceAmount(this, wpn.ammo_type, cvar("g_pickup_shells_weapon"));  break;
113                         case RESOURCE_BULLETS: SetResourceAmount(this, wpn.ammo_type, cvar("g_pickup_nails_weapon"));   break;
114                         case RESOURCE_ROCKETS: SetResourceAmount(this, wpn.ammo_type, cvar("g_pickup_rockets_weapon")); break;
115                         case RESOURCE_CELLS:   SetResourceAmount(this, wpn.ammo_type, cvar("g_pickup_cells_weapon"));   break;
116                         case RESOURCE_PLASMA:  SetResourceAmount(this, wpn.ammo_type, cvar("g_pickup_plasma_weapon"));  break;
117                         case RESOURCE_FUEL:    SetResourceAmount(this, wpn.ammo_type, cvar("g_pickup_fuel_weapon"));    break;
118                 }
119         }
120
121         #if 0 // WEAPONTODO
122         if (wpn.items)
123         {
124                 for (int i = 0, j = 1; i < 24; ++i, j <<= 1)
125                 {
126                         if (wpn.items & j)
127                         {
128                                 ammotype = Item_CounterField(j);
129                                 if (!this.ammotype)
130                                         this.ammotype = cvar(strcat("g_pickup_", Item_CounterFieldName(j), "_weapon"));
131                         }
132                 }
133         }
134         #endif
135
136         // pickup anyway
137         if (g_pickup_weapons_anyway)
138                 this.pickup_anyway = true;
139
140         if(!this.owner)
141                 this.glowmod = wpn.wpcolor;
142
143         GameItem def = wpn.m_pickup;
144         _StartItem(
145                 this,
146                 this.itemdef = def,
147                 this.respawntime, // defaultrespawntime
148                 this.respawntimejitter // defaultrespawntimejitter
149         );
150         #if 0 // WEAPONTODO
151         if (this.modelindex) { // don't precache if this was removed
152                 wpn.wr_init(wpn);
153         }
154         #endif
155 }