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