]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/server/weapons/spawning.qc
#include this
[xonotic/xonotic-data.pk3dir.git] / qcsrc / server / weapons / spawning.qc
1 #if defined(CSQC)
2 #elif defined(MENUQC)
3 #elif defined(SVQC)
4         #include "../../dpdefs/progsdefs.qc"
5     #include "../../dpdefs/dpextensions.qc"
6     #include "../sys-post.qh"
7     #include "../../common/weapons/weapons.qh"
8     #include "spawning.qh"
9     #include "weaponsystem.qh"
10     #include "../t_items.qh"
11     #include "../autocvars.qh"
12     #include "../constants.qh"
13     #include "../defs.qh"
14     #include "../mutators/mutators_include.qh"
15 #endif
16
17 string W_Apply_Weaponreplace(string in)
18 {
19         float n = tokenize_console(in);
20         string out = "", s, replacement;
21         float i, j;
22         entity e;
23         for(i = 0; i < n; ++i)
24         {
25                 replacement = "";
26                 s = argv(i);
27                 
28                 for(j = WEP_FIRST; j <= WEP_LAST; ++j)
29                 {
30                         e = get_weaponinfo(j);
31                         if(e.netname == s)
32                         {
33                                 replacement = e.weaponreplace;
34                         }
35                 }
36
37                 if(replacement == "")
38                         out = strcat(out, " ", s);
39                 else if(replacement != "0")
40                         out = strcat(out, " ", replacement);
41         }
42         return substring(out, 1, -1);
43 }
44
45 void weapon_defaultspawnfunc(float wpn)
46 {
47         entity e;
48         float t;
49         string s;
50         entity oldself;
51         float i, j;
52         float f;
53
54         if(self.classname != "droppedweapon" && self.classname != "replacedweapon")
55         {
56                 e = get_weaponinfo(wpn);
57
58                 if(e.spawnflags & WEP_FLAG_MUTATORBLOCKED)
59                 {
60                         objerror("Attempted to spawn a mutator-blocked weapon rejected");
61                         startitem_failed = true;
62                         return;
63                 }
64
65                 s = W_Apply_Weaponreplace(e.netname);
66                 ret_string = s;
67                 other = e;
68                 MUTATOR_CALLHOOK(SetWeaponreplace);
69                 s = ret_string;
70                 if(s == "")
71                 {
72                         remove(self);
73                         startitem_failed = true;
74                         return;
75                 }
76                 t = tokenize_console(s);
77                 if(t >= 2)
78                 {
79                         self.team = --internalteam;
80                         oldself = self;
81                         for(i = 1; i < t; ++i)
82                         {
83                                 s = argv(i);
84                                 for(j = WEP_FIRST; j <= WEP_LAST; ++j)
85                                 {
86                                         e = get_weaponinfo(j);
87                                         if(e.netname == s)
88                                         {
89                                                 self = spawn();
90                                                 copyentity(oldself, self);
91                                                 self.classname = "replacedweapon";
92                                                 weapon_defaultspawnfunc(j);
93                                                 break;
94                                         }
95                                 }
96                                 if(j > WEP_LAST)
97                                 {
98                                         print("The weapon replace list for ", oldself.classname, " contains an unknown weapon ", s, ". Skipped.\n");
99                                 }
100                         }
101                         self = oldself;
102                 }
103                 if(t >= 1) // always the case!
104                 {
105                         s = argv(0);
106                         wpn = 0;
107                         for(j = WEP_FIRST; j <= WEP_LAST; ++j)
108                         {
109                                 e = get_weaponinfo(j);
110                                 if(e.netname == s)
111                                 {
112                                         wpn = j;
113                                         break;
114                                 }
115                         }
116                         if(j > WEP_LAST)
117                         {
118                                 print("The weapon replace list for ", self.classname, " contains an unknown weapon ", s, ". Skipped.\n");
119                         }
120                 }
121                 if(wpn == 0)
122                 {
123                         remove(self);
124                         startitem_failed = true;
125                         return;
126                 }
127         }
128
129         e = get_weaponinfo(wpn);
130
131         if(!self.respawntime)
132         {
133                 if(e.weapons & WEPSET_SUPERWEAPONS)
134                 {
135                         self.respawntime = g_pickup_respawntime_superweapon;
136                         self.respawntimejitter = g_pickup_respawntimejitter_superweapon;
137                 }
138                 else
139                 {
140                         self.respawntime = g_pickup_respawntime_weapon;
141                         self.respawntimejitter = g_pickup_respawntimejitter_weapon;
142                 }
143         }
144
145         if(e.weapons & WEPSET_SUPERWEAPONS)
146                 if(!self.superweapons_finished)
147                         self.superweapons_finished = autocvar_g_balance_superweapons_time;
148
149         // if we don't already have ammo, give us some ammo
150         if(!self.(e.ammo_field))
151         {
152                 switch(e.ammo_field)
153                 {
154                         case ammo_shells:  self.ammo_shells  = cvar("g_pickup_shells_weapon");  break;
155                         case ammo_nails:   self.ammo_nails   = cvar("g_pickup_nails_weapon");   break;
156                         case ammo_rockets: self.ammo_rockets = cvar("g_pickup_rockets_weapon"); break;
157                         case ammo_cells:   self.ammo_cells   = cvar("g_pickup_cells_weapon");   break;
158                         case ammo_plasma:  self.ammo_plasma  = cvar("g_pickup_plasma_weapon");  break;
159                         case ammo_fuel:    self.ammo_fuel    = cvar("g_pickup_fuel_weapon");    break;
160                 }
161         }
162
163         #if 0 // WEAPONTODO
164         if(e.items)
165         {
166                 for(i = 0, j = 1; i < 24; ++i, j *= 2)
167                 {
168                         if(e.items & j)
169                         {
170                                 ammotype = Item_CounterField(j);
171                                 if(!self.ammotype)
172                                         self.ammotype = cvar(strcat("g_pickup_", Item_CounterFieldName(j), "_weapon"));
173                         }
174                 }
175         }
176         #endif
177
178         // pickup anyway
179         if(g_pickup_weapons_anyway)
180                 self.pickup_anyway = true;
181
182         f = FL_WEAPON;
183
184         // no weapon-stay on superweapons
185         if(e.weapons & WEPSET_SUPERWEAPONS)
186                 f |= FL_NO_WEAPON_STAY;
187
188         // weapon stay isn't supported for teamed weapons
189         if(self.team)
190                 f |= FL_NO_WEAPON_STAY;
191
192         StartItem(e.model, "weapons/weaponpickup.wav", self.respawntime, self.respawntimejitter, e.message, 0, e.weapon, f, weapon_pickupevalfunc, e.bot_pickupbasevalue);
193         #if 0 // WEAPONTODO
194         if (self.modelindex) // don't precache if self was removed
195                 WEP_ACTION(e.weapon, WR_INIT);
196         #endif
197 }