Weapons: remove WEP_ACTION
[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 {SELFPARAM();
39         entity e;
40         float t;
41         string s;
42         float i, j;
43         int f;
44
45         if(self.classname != "droppedweapon" && self.classname != "replacedweapon")
46         {
47                 e = get_weaponinfo(wpn);
48
49                 if(e.spawnflags & WEP_FLAG_MUTATORBLOCKED)
50                 {
51                         objerror("Attempted to spawn a mutator-blocked weapon rejected");
52                         startitem_failed = true;
53                         return;
54                 }
55
56                 s = W_Apply_Weaponreplace(e.netname);
57                 MUTATOR_CALLHOOK(SetWeaponreplace, self, e, s);
58                 s = ret_string;
59                 if(s == "")
60                 {
61                         remove(self);
62                         startitem_failed = true;
63                         return;
64                 }
65                 t = tokenize_console(s);
66                 if(t >= 2)
67                 {
68                         self.team = --internalteam;
69                         for(i = 1; i < t; ++i)
70                         {
71                                 s = argv(i);
72                                 for(j = WEP_FIRST; j <= WEP_LAST; ++j)
73                                 {
74                                         e = get_weaponinfo(j);
75                                         if(e.netname == s)
76                                         {
77                                                 setself(spawn());
78                                                 copyentity(this, self);
79                                                 self.classname = "replacedweapon";
80                                                 weapon_defaultspawnfunc(j);
81                                                 break;
82                                         }
83                                 }
84                                 if(j > WEP_LAST)
85                                 {
86                                         LOG_INFO("The weapon replace list for ", this.classname, " contains an unknown weapon ", s, ". Skipped.\n");
87                                 }
88                         }
89                         setself(this);
90                 }
91                 if(t >= 1) // always the case!
92                 {
93                         s = argv(0);
94                         wpn = 0;
95                         for(j = WEP_FIRST; j <= WEP_LAST; ++j)
96                         {
97                                 e = get_weaponinfo(j);
98                                 if(e.netname == s)
99                                 {
100                                         wpn = j;
101                                         break;
102                                 }
103                         }
104                         if(j > WEP_LAST)
105                         {
106                                 LOG_INFO("The weapon replace list for ", self.classname, " contains an unknown weapon ", s, ". Skipped.\n");
107                         }
108                 }
109                 if(wpn == 0)
110                 {
111                         remove(self);
112                         startitem_failed = true;
113                         return;
114                 }
115         }
116
117         e = get_weaponinfo(wpn);
118
119         if(!self.respawntime)
120         {
121                 if(e.weapons & WEPSET_SUPERWEAPONS)
122                 {
123                         self.respawntime = g_pickup_respawntime_superweapon;
124                         self.respawntimejitter = g_pickup_respawntimejitter_superweapon;
125                 }
126                 else
127                 {
128                         self.respawntime = g_pickup_respawntime_weapon;
129                         self.respawntimejitter = g_pickup_respawntimejitter_weapon;
130                 }
131         }
132
133         if(e.weapons & WEPSET_SUPERWEAPONS)
134                 if(!self.superweapons_finished)
135                         self.superweapons_finished = autocvar_g_balance_superweapons_time;
136
137         // if we don't already have ammo, give us some ammo
138         if(!self.(e.ammo_field))
139         {
140                 switch(e.ammo_field)
141                 {
142                         case ammo_shells:  self.ammo_shells  = cvar("g_pickup_shells_weapon");  break;
143                         case ammo_nails:   self.ammo_nails   = cvar("g_pickup_nails_weapon");   break;
144                         case ammo_rockets: self.ammo_rockets = cvar("g_pickup_rockets_weapon"); break;
145                         case ammo_cells:   self.ammo_cells   = cvar("g_pickup_cells_weapon");   break;
146                         case ammo_plasma:  self.ammo_plasma  = cvar("g_pickup_plasma_weapon");  break;
147                         case ammo_fuel:    self.ammo_fuel    = cvar("g_pickup_fuel_weapon");    break;
148                 }
149         }
150
151         #if 0 // WEAPONTODO
152         if(e.items)
153         {
154                 for(i = 0, j = 1; i < 24; ++i, j *= 2)
155                 {
156                         if(e.items & j)
157                         {
158                                 ammotype = Item_CounterField(j);
159                                 if(!self.ammotype)
160                                         self.ammotype = cvar(strcat("g_pickup_", Item_CounterFieldName(j), "_weapon"));
161                         }
162                 }
163         }
164         #endif
165
166         // pickup anyway
167         if(g_pickup_weapons_anyway)
168                 self.pickup_anyway = true;
169
170         f = FL_WEAPON;
171
172         // no weapon-stay on superweapons
173         if(e.weapons & WEPSET_SUPERWEAPONS)
174                 f |= FL_NO_WEAPON_STAY;
175
176         // weapon stay isn't supported for teamed weapons
177         if(self.team)
178                 f |= FL_NO_WEAPON_STAY;
179
180         StartItem(strzone(e.m_model.model_str()), string_null, self.respawntime, self.respawntimejitter, e.message, 0, e.weapon, f, weapon_pickupevalfunc, e.bot_pickupbasevalue);
181         self.item_pickupsound_ent = SND_WEAPONPICKUP;
182         #if 0 // WEAPONTODO
183         if (self.modelindex) { // don't precache if self was removed
184                 Weapon w = get_weaponinfo(e.weapon);
185                 w.wr_init(w);
186         }
187         #endif
188 }