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