]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/server/weapons/spawning.qc
d6a108b52d6092e24ac79ae1b43998746849364f
[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 "../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         int wpn = e.m_id;
28         if (this.classname != "droppedweapon" && this.classname != "replacedweapon")
29         {
30                 if (e.spawnflags & WEP_FLAG_MUTATORBLOCKED)
31                 {
32                         objerror("Attempted to spawn a mutator-blocked weapon rejected");
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                                 int j;
54                                 for (j = WEP_FIRST; j <= WEP_LAST; ++j)
55                                 {
56                                         e = Weapons_from(j);
57                                         if (e.netname == s)
58                                         {
59                                                 entity replacement = spawn();
60                                                 copyentity(this, replacement);
61                                                 replacement.classname = "replacedweapon";
62                                                 weapon_defaultspawnfunc(replacement, e);
63                                                 break;
64                                         }
65                                 }
66                                 if (j > WEP_LAST)
67                                 {
68                                         LOG_INFO("The weapon replace list for ", this.classname, " contains an unknown weapon ", s, ". Skipped.\n");
69                                 }
70                         }
71                 }
72                 if (t >= 1) // always the case!
73                 {
74                         s = argv(0);
75                         wpn = 0;
76                         int j;
77                         for (j = WEP_FIRST; j <= WEP_LAST; ++j)
78                         {
79                                 e = Weapons_from(j);
80                                 if (e.netname == s)
81                                 {
82                                         wpn = j;
83                                         break;
84                                 }
85                         }
86                         if (j > WEP_LAST)
87                         {
88                                 LOG_INFO("The weapon replace list for ", this.classname, " contains an unknown weapon ", s, ". Skipped.\n");
89                         }
90                 }
91                 if (wpn == 0)
92                 {
93                         remove(this);
94                         startitem_failed = true;
95                         return;
96                 }
97         }
98
99         e = Weapons_from(wpn);
100
101         if (!this.respawntime)
102         {
103                 if (e.spawnflags & WEP_FLAG_SUPERWEAPON)
104                 {
105                         this.respawntime = g_pickup_respawntime_superweapon;
106                         this.respawntimejitter = g_pickup_respawntimejitter_superweapon;
107                 }
108                 else
109                 {
110                         this.respawntime = g_pickup_respawntime_weapon;
111                         this.respawntimejitter = g_pickup_respawntimejitter_weapon;
112                 }
113         }
114
115         if (e.spawnflags & WEP_FLAG_SUPERWEAPON)
116                 if (!this.superweapons_finished)
117                         this.superweapons_finished = autocvar_g_balance_superweapons_time;
118
119         // if we don't already have ammo, give us some ammo
120         if (!this.(e.ammo_field))
121         {
122                 switch (e.ammo_field)
123                 {
124                         case ammo_shells:  this.ammo_shells  = cvar("g_pickup_shells_weapon");  break;
125                         case ammo_nails:   this.ammo_nails   = cvar("g_pickup_nails_weapon");   break;
126                         case ammo_rockets: this.ammo_rockets = cvar("g_pickup_rockets_weapon"); break;
127                         case ammo_cells:   this.ammo_cells   = cvar("g_pickup_cells_weapon");   break;
128                         case ammo_plasma:  this.ammo_plasma  = cvar("g_pickup_plasma_weapon");  break;
129                         case ammo_fuel:    this.ammo_fuel    = cvar("g_pickup_fuel_weapon");    break;
130                 }
131         }
132
133         #if 0 // WEAPONTODO
134         if (e.items)
135         {
136                 for (int i = 0, j = 1; i < 24; ++i, j <<= 1)
137                 {
138                         if (e.items & j)
139                         {
140                                 ammotype = Item_CounterField(j);
141                                 if (!this.ammotype)
142                                         this.ammotype = cvar(strcat("g_pickup_", Item_CounterFieldName(j), "_weapon"));
143                         }
144                 }
145         }
146         #endif
147
148         // pickup anyway
149         if (g_pickup_weapons_anyway)
150                 this.pickup_anyway = true;
151
152         GameItem def = e.m_pickup;
153         _StartItem(
154                 this,
155                 this.itemdef = def,
156                 this.respawntime, // defaultrespawntime
157                 this.respawntimejitter // defaultrespawntimejitter
158         );
159         #if 0 // WEAPONTODO
160         if (this.modelindex) { // don't precache if this was removed
161                 e.wr_init(e);
162         }
163         #endif
164 }