]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/server/weapons/spawning.qc
Merge branch 'TimePath/qc_updates' into 'master'
[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/weapons.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                 ret_string = s;
59                 other = e;
60                 MUTATOR_CALLHOOK(SetWeaponreplace);
61                 s = ret_string;
62                 if(s == "")
63                 {
64                         remove(self);
65                         startitem_failed = true;
66                         return;
67                 }
68                 t = tokenize_console(s);
69                 if(t >= 2)
70                 {
71                         self.team = --internalteam;
72                         oldself = self;
73                         for(i = 1; i < t; ++i)
74                         {
75                                 s = argv(i);
76                                 for(j = WEP_FIRST; j <= WEP_LAST; ++j)
77                                 {
78                                         e = get_weaponinfo(j);
79                                         if(e.netname == s)
80                                         {
81                                                 self = spawn();
82                                                 copyentity(oldself, self);
83                                                 self.classname = "replacedweapon";
84                                                 weapon_defaultspawnfunc(j);
85                                                 break;
86                                         }
87                                 }
88                                 if(j > WEP_LAST)
89                                 {
90                                         print("The weapon replace list for ", oldself.classname, " contains an unknown weapon ", s, ". Skipped.\n");
91                                 }
92                         }
93                         self = oldself;
94                 }
95                 if(t >= 1) // always the case!
96                 {
97                         s = argv(0);
98                         wpn = 0;
99                         for(j = WEP_FIRST; j <= WEP_LAST; ++j)
100                         {
101                                 e = get_weaponinfo(j);
102                                 if(e.netname == s)
103                                 {
104                                         wpn = j;
105                                         break;
106                                 }
107                         }
108                         if(j > WEP_LAST)
109                         {
110                                 print("The weapon replace list for ", self.classname, " contains an unknown weapon ", s, ". Skipped.\n");
111                         }
112                 }
113                 if(wpn == 0)
114                 {
115                         remove(self);
116                         startitem_failed = true;
117                         return;
118                 }
119         }
120
121         e = get_weaponinfo(wpn);
122
123         if(!self.respawntime)
124         {
125                 if(e.weapons & WEPSET_SUPERWEAPONS)
126                 {
127                         self.respawntime = g_pickup_respawntime_superweapon;
128                         self.respawntimejitter = g_pickup_respawntimejitter_superweapon;
129                 }
130                 else
131                 {
132                         self.respawntime = g_pickup_respawntime_weapon;
133                         self.respawntimejitter = g_pickup_respawntimejitter_weapon;
134                 }
135         }
136
137         if(e.weapons & WEPSET_SUPERWEAPONS)
138                 if(!self.superweapons_finished)
139                         self.superweapons_finished = autocvar_g_balance_superweapons_time;
140
141         // if we don't already have ammo, give us some ammo
142         if(!self.(e.ammo_field))
143         {
144                 switch(e.ammo_field)
145                 {
146                         case ammo_shells:  self.ammo_shells  = cvar("g_pickup_shells_weapon");  break;
147                         case ammo_nails:   self.ammo_nails   = cvar("g_pickup_nails_weapon");   break;
148                         case ammo_rockets: self.ammo_rockets = cvar("g_pickup_rockets_weapon"); break;
149                         case ammo_cells:   self.ammo_cells   = cvar("g_pickup_cells_weapon");   break;
150                         case ammo_plasma:  self.ammo_plasma  = cvar("g_pickup_plasma_weapon");  break;
151                         case ammo_fuel:    self.ammo_fuel    = cvar("g_pickup_fuel_weapon");    break;
152                 }
153         }
154
155         #if 0 // WEAPONTODO
156         if(e.items)
157         {
158                 for(i = 0, j = 1; i < 24; ++i, j *= 2)
159                 {
160                         if(e.items & j)
161                         {
162                                 ammotype = Item_CounterField(j);
163                                 if(!self.ammotype)
164                                         self.ammotype = cvar(strcat("g_pickup_", Item_CounterFieldName(j), "_weapon"));
165                         }
166                 }
167         }
168         #endif
169
170         // pickup anyway
171         if(g_pickup_weapons_anyway)
172                 self.pickup_anyway = true;
173
174         f = FL_WEAPON;
175
176         // no weapon-stay on superweapons
177         if(e.weapons & WEPSET_SUPERWEAPONS)
178                 f |= FL_NO_WEAPON_STAY;
179
180         // weapon stay isn't supported for teamed weapons
181         if(self.team)
182                 f |= FL_NO_WEAPON_STAY;
183
184         StartItem(e.model, "weapons/weaponpickup.wav", self.respawntime, self.respawntimejitter, e.message, 0, e.weapon, f, weapon_pickupevalfunc, e.bot_pickupbasevalue);
185         #if 0 // WEAPONTODO
186         if (self.modelindex) // don't precache if self was removed
187                 WEP_ACTION(e.weapon, WR_INIT);
188         #endif
189 }