]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/server/weapons/spawning.qc
Merge branch 'master' into terencehill/dynamic_hud
[xonotic/xonotic-data.pk3dir.git] / qcsrc / server / weapons / spawning.qc
1 #include "spawning.qh"
2
3 #include "weaponsystem.qh"
4 #include "../mutators/all.qh"
5 #include <common/t_items.qh>
6 #include <common/weapons/all.qh>
7
8 string W_Apply_Weaponreplace(string in)
9 {
10         string out = "";
11         FOREACH_WORD(in, true, {
12                 string replacement = "";
13                 Weapon w = Weapons_fromstr(it);
14                 if (w)
15                 {
16             replacement = w.weaponreplace;
17             if (replacement == "") replacement = it;
18                 }
19                 if (replacement == "0") continue;
20                 out = cons(out, replacement);
21         });
22         return out;
23 }
24
25 void weapon_defaultspawnfunc(entity this, Weapon e)
26 {
27         Weapon wpn = e;
28         if (this.classname != "droppedweapon" && this.classname != "replacedweapon")
29         {
30                 if (e.spawnflags & WEP_FLAG_MUTATORBLOCKED)
31                 {
32                         LOG_MAPWARNF("Attempted to spawn a mutator-blocked weapon rejected: prvm_edict server %i", this);
33                         startitem_failed = true;
34                         return;
35                 }
36
37                 string s = W_Apply_Weaponreplace(e.netname);
38                 MUTATOR_CALLHOOK(SetWeaponreplace, this, e, s);
39                 s = ret_string;
40                 if (s == "")
41                 {
42                         remove(this);
43                         startitem_failed = true;
44                         return;
45                 }
46                 int t = tokenize_console(s);
47                 if (t >= 2)
48                 {
49                         this.team = --internalteam;
50                         for (int i = 1; i < t; ++i)
51                         {
52                                 s = argv(i);
53                                 FOREACH(Weapons, it != WEP_Null, LAMBDA(
54                                         if(it.netname == s)
55                                         {
56                                                 entity replacement = spawn();
57                                                 copyentity(this, replacement);
58                                                 replacement.classname = "replacedweapon";
59                                                 weapon_defaultspawnfunc(replacement, it);
60                                                 break;
61                                         }
62                                 ));
63                         }
64                 }
65                 if (t >= 1) // always the case!
66                 {
67                         s = argv(0);
68                         wpn = WEP_Null;
69                         FOREACH(Weapons, it != WEP_Null, LAMBDA(
70                                 if(it.netname == s)
71                                 {
72                                         wpn = it;
73                                         break;
74                                 }
75                         ));
76                 }
77                 if (wpn == WEP_Null)
78                 {
79                         remove(this);
80                         startitem_failed = true;
81                         return;
82                 }
83         }
84
85         if (!this.respawntime)
86         {
87                 if (wpn.spawnflags & WEP_FLAG_SUPERWEAPON)
88                 {
89                         this.respawntime = g_pickup_respawntime_superweapon;
90                         this.respawntimejitter = g_pickup_respawntimejitter_superweapon;
91                 }
92                 else
93                 {
94                         this.respawntime = g_pickup_respawntime_weapon;
95                         this.respawntimejitter = g_pickup_respawntimejitter_weapon;
96                 }
97         }
98
99         if (wpn.spawnflags & WEP_FLAG_SUPERWEAPON)
100                 if (!this.superweapons_finished)
101                         this.superweapons_finished = autocvar_g_balance_superweapons_time;
102
103         // if we don't already have ammo, give us some ammo
104         if (!this.(wpn.ammo_field))
105         {
106                 switch (wpn.ammo_field)
107                 {
108                         case ammo_shells:  this.ammo_shells  = cvar("g_pickup_shells_weapon");  break;
109                         case ammo_nails:   this.ammo_nails   = cvar("g_pickup_nails_weapon");   break;
110                         case ammo_rockets: this.ammo_rockets = cvar("g_pickup_rockets_weapon"); break;
111                         case ammo_cells:   this.ammo_cells   = cvar("g_pickup_cells_weapon");   break;
112                         case ammo_plasma:  this.ammo_plasma  = cvar("g_pickup_plasma_weapon");  break;
113                         case ammo_fuel:    this.ammo_fuel    = cvar("g_pickup_fuel_weapon");    break;
114                 }
115         }
116
117         #if 0 // WEAPONTODO
118         if (wpn.items)
119         {
120                 for (int i = 0, j = 1; i < 24; ++i, j <<= 1)
121                 {
122                         if (wpn.items & j)
123                         {
124                                 ammotype = Item_CounterField(j);
125                                 if (!this.ammotype)
126                                         this.ammotype = cvar(strcat("g_pickup_", Item_CounterFieldName(j), "_weapon"));
127                         }
128                 }
129         }
130         #endif
131
132         // pickup anyway
133         if (g_pickup_weapons_anyway)
134                 this.pickup_anyway = true;
135
136         GameItem def = wpn.m_pickup;
137         _StartItem(
138                 this,
139                 this.itemdef = def,
140                 this.respawntime, // defaultrespawntime
141                 this.respawntimejitter // defaultrespawntimejitter
142         );
143         #if 0 // WEAPONTODO
144         if (this.modelindex) { // don't precache if this was removed
145                 wpn.wr_init(wpn);
146         }
147         #endif
148 }