]> git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/server/weapons/spawning.qc
Merge remote-tracking branch 'origin/master' into samual/weapons
[xonotic/xonotic-data.pk3dir.git] / qcsrc / server / weapons / spawning.qc
1 string W_Apply_Weaponreplace(string in)
2 {
3         float n = tokenize_console(in);
4         string out = "";
5         float i;
6         for(i = 0; i < n; ++i)
7         {
8                 string s = argv(i);
9                 string r = cvar_string(strcat("g_weaponreplace_", s));
10                 if(r == "")
11                         out = strcat(out, " ", s);
12                 else if(r != "0")
13                         out = strcat(out, " ", r);
14         }
15         return substring(out, 1, -1);
16 }
17
18 void weapon_defaultspawnfunc(float wpn)
19 {
20         entity e;
21         float t;
22         var .float ammofield;
23         string s;
24         entity oldself;
25         float i, j;
26         float f;
27
28         if(self.classname != "droppedweapon" && self.classname != "replacedweapon")
29         {
30                 e = get_weaponinfo(wpn);
31
32                 if(e.spawnflags & WEP_FLAG_MUTATORBLOCKED)
33                 {
34                         objerror("Attempted to spawn a mutator-blocked weapon rejected");
35                         startitem_failed = TRUE;
36                         return;
37                 }
38
39                 s = W_Apply_Weaponreplace(e.netname);
40                 ret_string = s;
41                 other = e;
42                 MUTATOR_CALLHOOK(SetWeaponreplace);
43                 s = ret_string;
44                 if(s == "")
45                 {
46                         remove(self);
47                         startitem_failed = TRUE;
48                         return;
49                 }
50                 t = tokenize_console(s);
51                 if(t >= 2)
52                 {
53                         self.team = --internalteam;
54                         oldself = self;
55                         for(i = 1; i < t; ++i)
56                         {
57                                 s = argv(i);
58                                 for(j = WEP_FIRST; j <= WEP_LAST; ++j)
59                                 {
60                                         e = get_weaponinfo(j);
61                                         if(e.netname == s)
62                                         {
63                                                 self = spawn();
64                                                 copyentity(oldself, self);
65                                                 self.classname = "replacedweapon";
66                                                 weapon_defaultspawnfunc(j);
67                                                 break;
68                                         }
69                                 }
70                                 if(j > WEP_LAST)
71                                 {
72                                         print("The weapon replace list for ", oldself.classname, " contains an unknown weapon ", s, ". Skipped.\n");
73                                 }
74                         }
75                         self = oldself;
76                 }
77                 if(t >= 1) // always the case!
78                 {
79                         s = argv(0);
80                         wpn = 0;
81                         for(j = WEP_FIRST; j <= WEP_LAST; ++j)
82                         {
83                                 e = get_weaponinfo(j);
84                                 if(e.netname == s)
85                                 {
86                                         wpn = j;
87                                         break;
88                                 }
89                         }
90                         if(j > WEP_LAST)
91                         {
92                                 print("The weapon replace list for ", self.classname, " contains an unknown weapon ", s, ". Skipped.\n");
93                         }
94                 }
95                 if(wpn == 0)
96                 {
97                         remove(self);
98                         startitem_failed = TRUE;
99                         return;
100                 }
101         }
102
103         e = get_weaponinfo(wpn);
104
105         if(!self.respawntime)
106         {
107                 if(e.weapons & WEPSET_SUPERWEAPONS)
108                 {
109                         self.respawntime = g_pickup_respawntime_superweapon;
110                         self.respawntimejitter = g_pickup_respawntimejitter_superweapon;
111                 }
112                 else
113                 {
114                         self.respawntime = g_pickup_respawntime_weapon;
115                         self.respawntimejitter = g_pickup_respawntimejitter_weapon;
116                 }
117         }
118
119         if(e.weapons & WEPSET_SUPERWEAPONS)
120                 if(!self.superweapons_finished)
121                         self.superweapons_finished = autocvar_g_balance_superweapons_time;
122
123         if(e.items)
124         {
125                 for(i = 0, j = 1; i < 24; ++i, j *= 2)
126                 {
127                         if(e.items & j)
128                         {
129                                 ammofield = Item_CounterField(j);
130                                 if(!self.ammofield)
131                                         self.ammofield = cvar(strcat("g_pickup_", Item_CounterFieldName(j), "_weapon"));
132                         }
133                 }
134         }
135
136         // pickup anyway
137         if(g_pickup_weapons_anyway)
138                 self.pickup_anyway = TRUE;
139
140         f = FL_WEAPON;
141
142         // no weapon-stay on superweapons
143         if(e.weapons & WEPSET_SUPERWEAPONS)
144                 f |= FL_NO_WEAPON_STAY;
145
146         // weapon stay isn't supported for teamed weapons
147         if(self.team)
148                 f |= FL_NO_WEAPON_STAY;
149
150         StartItem(e.model, "weapons/weaponpickup.wav", self.respawntime, self.respawntimejitter, e.message, 0, e.weapon, f, weapon_pickupevalfunc, e.bot_pickupbasevalue);
151         if (self.modelindex) // don't precache if self was removed
152                 WEP_ACTION(e.weapon, WR_INIT);
153 }