]> git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/server/weapons/spawning.qc
More work on switching over to using entity field instead of item field
[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         string s;
23         entity oldself;
24         float i, j;
25         float f;
26
27         if(self.classname != "droppedweapon" && self.classname != "replacedweapon")
28         {
29                 e = get_weaponinfo(wpn);
30
31                 if(e.spawnflags & WEP_FLAG_MUTATORBLOCKED)
32                 {
33                         objerror("Attempted to spawn a mutator-blocked weapon rejected");
34                         startitem_failed = TRUE;
35                         return;
36                 }
37
38                 s = W_Apply_Weaponreplace(e.netname);
39                 ret_string = s;
40                 other = e;
41                 MUTATOR_CALLHOOK(SetWeaponreplace);
42                 s = ret_string;
43                 if(s == "")
44                 {
45                         remove(self);
46                         startitem_failed = TRUE;
47                         return;
48                 }
49                 t = tokenize_console(s);
50                 if(t >= 2)
51                 {
52                         self.team = --internalteam;
53                         oldself = self;
54                         for(i = 1; i < t; ++i)
55                         {
56                                 s = argv(i);
57                                 for(j = WEP_FIRST; j <= WEP_LAST; ++j)
58                                 {
59                                         e = get_weaponinfo(j);
60                                         if(e.netname == s)
61                                         {
62                                                 self = spawn();
63                                                 copyentity(oldself, self);
64                                                 self.classname = "replacedweapon";
65                                                 weapon_defaultspawnfunc(j);
66                                                 break;
67                                         }
68                                 }
69                                 if(j > WEP_LAST)
70                                 {
71                                         print("The weapon replace list for ", oldself.classname, " contains an unknown weapon ", s, ". Skipped.\n");
72                                 }
73                         }
74                         self = oldself;
75                 }
76                 if(t >= 1) // always the case!
77                 {
78                         s = argv(0);
79                         wpn = 0;
80                         for(j = WEP_FIRST; j <= WEP_LAST; ++j)
81                         {
82                                 e = get_weaponinfo(j);
83                                 if(e.netname == s)
84                                 {
85                                         wpn = j;
86                                         break;
87                                 }
88                         }
89                         if(j > WEP_LAST)
90                         {
91                                 print("The weapon replace list for ", self.classname, " contains an unknown weapon ", s, ". Skipped.\n");
92                         }
93                 }
94                 if(wpn == 0)
95                 {
96                         remove(self);
97                         startitem_failed = TRUE;
98                         return;
99                 }
100         }
101
102         e = get_weaponinfo(wpn);
103
104         if(!self.respawntime)
105         {
106                 if(e.weapons & WEPSET_SUPERWEAPONS)
107                 {
108                         self.respawntime = g_pickup_respawntime_superweapon;
109                         self.respawntimejitter = g_pickup_respawntimejitter_superweapon;
110                 }
111                 else
112                 {
113                         self.respawntime = g_pickup_respawntime_weapon;
114                         self.respawntimejitter = g_pickup_respawntimejitter_weapon;
115                 }
116         }
117
118         if(e.weapons & WEPSET_SUPERWEAPONS)
119                 if(!self.superweapons_finished)
120                         self.superweapons_finished = autocvar_g_balance_superweapons_time;
121
122         // if we don't already have ammo, give us some ammo
123         if(!self.(e.current_ammo))
124         {
125                 switch(e.current_ammo)
126                 {
127                         case ammo_shells:  self.ammo_shells  = cvar("g_pickup_shells_weapon");  break;
128                         case ammo_nails:   self.ammo_nails   = cvar("g_pickup_nails_weapon");   break;
129                         case ammo_rockets: self.ammo_rockets = cvar("g_pickup_rockets_weapon"); break;
130                         case ammo_cells:   self.ammo_cells   = cvar("g_pickup_cells_weapon");   break;
131                         case ammo_fuel:    self.ammo_fuel    = cvar("g_pickup_fuel_weapon");    break;
132                 }
133         }
134
135         print(sprintf("defaultspawnfunc: current ammo count: %f\n", self.(e.current_ammo)));
136
137         #if 0
138         if(e.items)
139         {
140                 for(i = 0, j = 1; i < 24; ++i, j *= 2)
141                 {
142                         if(e.items & j)
143                         {
144                                 ammofield = Item_CounterField(j);
145                                 if(!self.ammofield)
146                                         self.ammofield = cvar(strcat("g_pickup_", Item_CounterFieldName(j), "_weapon"));
147                         }
148                 }
149         }
150         #endif
151
152         // pickup anyway
153         if(g_pickup_weapons_anyway)
154                 self.pickup_anyway = TRUE;
155
156         f = FL_WEAPON;
157
158         // no weapon-stay on superweapons
159         if(e.weapons & WEPSET_SUPERWEAPONS)
160                 f |= FL_NO_WEAPON_STAY;
161
162         // weapon stay isn't supported for teamed weapons
163         if(self.team)
164                 f |= FL_NO_WEAPON_STAY;
165
166         StartItem(e.model, "weapons/weaponpickup.wav", self.respawntime, self.respawntimejitter, e.message, 0, e.weapon, f, weapon_pickupevalfunc, e.bot_pickupbasevalue);
167         if (self.modelindex) // don't precache if self was removed
168                 WEP_ACTION(e.weapon, WR_INIT);
169 }