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