]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/server/weapons/spawning.qc
Merge branch 'master' into Mario/bulldozer
[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         float n = tokenize_console(in);
11         string out = "", s, replacement;
12         float i, j;
13         entity e;
14         for(i = 0; i < n; ++i)
15         {
16                 replacement = "";
17                 s = argv(i);
18
19                 for(j = WEP_FIRST; j <= WEP_LAST; ++j)
20                 {
21                         e = get_weaponinfo(j);
22                         if(e.netname == s)
23                         {
24                                 replacement = e.weaponreplace;
25                         }
26                 }
27
28                 if(replacement == "")
29                         out = strcat(out, " ", s);
30                 else if(replacement != "0")
31                         out = strcat(out, " ", replacement);
32         }
33         return substring(out, 1, -1);
34 }
35
36 void weapon_defaultspawnfunc(entity this, Weapon e)
37 {
38         int wpn = e.m_id;
39         if (this.classname != "droppedweapon" && this.classname != "replacedweapon")
40         {
41                 if (e.spawnflags & WEP_FLAG_MUTATORBLOCKED)
42                 {
43                         objerror("Attempted to spawn a mutator-blocked weapon rejected");
44                         startitem_failed = true;
45                         return;
46                 }
47
48                 string s = W_Apply_Weaponreplace(e.netname);
49                 MUTATOR_CALLHOOK(SetWeaponreplace, this, e, s);
50                 s = ret_string;
51                 if (s == "")
52                 {
53                         remove(this);
54                         startitem_failed = true;
55                         return;
56                 }
57                 int t = tokenize_console(s);
58                 if (t >= 2)
59                 {
60                         this.team = --internalteam;
61                         for (int i = 1; i < t; ++i)
62                         {
63                                 s = argv(i);
64                                 int j;
65                                 for (j = WEP_FIRST; j <= WEP_LAST; ++j)
66                                 {
67                                         e = get_weaponinfo(j);
68                                         if (e.netname == s)
69                                         {
70                                                 entity replacement = spawn();
71                                                 copyentity(this, replacement);
72                                                 replacement.classname = "replacedweapon";
73                                                 weapon_defaultspawnfunc(replacement, e);
74                                                 break;
75                                         }
76                                 }
77                                 if (j > WEP_LAST)
78                                 {
79                                         LOG_INFO("The weapon replace list for ", this.classname, " contains an unknown weapon ", s, ". Skipped.\n");
80                                 }
81                         }
82                 }
83                 if (t >= 1) // always the case!
84                 {
85                         s = argv(0);
86                         wpn = 0;
87                         int j;
88                         for (j = WEP_FIRST; j <= WEP_LAST; ++j)
89                         {
90                                 e = get_weaponinfo(j);
91                                 if (e.netname == s)
92                                 {
93                                         wpn = j;
94                                         break;
95                                 }
96                         }
97                         if (j > WEP_LAST)
98                         {
99                                 LOG_INFO("The weapon replace list for ", this.classname, " contains an unknown weapon ", s, ". Skipped.\n");
100                         }
101                 }
102                 if (wpn == 0)
103                 {
104                         remove(this);
105                         startitem_failed = true;
106                         return;
107                 }
108         }
109
110         e = get_weaponinfo(wpn);
111
112         if (!this.respawntime)
113         {
114                 if (e.weapons & WEPSET_SUPERWEAPONS)
115                 {
116                         this.respawntime = g_pickup_respawntime_superweapon;
117                         this.respawntimejitter = g_pickup_respawntimejitter_superweapon;
118                 }
119                 else
120                 {
121                         this.respawntime = g_pickup_respawntime_weapon;
122                         this.respawntimejitter = g_pickup_respawntimejitter_weapon;
123                 }
124         }
125
126         if (e.weapons & WEPSET_SUPERWEAPONS)
127                 if (!this.superweapons_finished)
128                         this.superweapons_finished = autocvar_g_balance_superweapons_time;
129
130         // if we don't already have ammo, give us some ammo
131         if (!this.(e.ammo_field))
132         {
133                 switch (e.ammo_field)
134                 {
135                         case ammo_shells:  this.ammo_shells  = cvar("g_pickup_shells_weapon");  break;
136                         case ammo_nails:   this.ammo_nails   = cvar("g_pickup_nails_weapon");   break;
137                         case ammo_rockets: this.ammo_rockets = cvar("g_pickup_rockets_weapon"); break;
138                         case ammo_cells:   this.ammo_cells   = cvar("g_pickup_cells_weapon");   break;
139                         case ammo_plasma:  this.ammo_plasma  = cvar("g_pickup_plasma_weapon");  break;
140                         case ammo_fuel:    this.ammo_fuel    = cvar("g_pickup_fuel_weapon");    break;
141                 }
142         }
143
144         #if 0 // WEAPONTODO
145         if (e.items)
146         {
147                 for (int i = 0, j = 1; i < 24; ++i, j <<= 1)
148                 {
149                         if (e.items & j)
150                         {
151                                 ammotype = Item_CounterField(j);
152                                 if (!this.ammotype)
153                                         this.ammotype = cvar(strcat("g_pickup_", Item_CounterFieldName(j), "_weapon"));
154                         }
155                 }
156         }
157         #endif
158
159         // pickup anyway
160         if (g_pickup_weapons_anyway)
161                 this.pickup_anyway = true;
162
163         GameItem def = e.m_pickup;
164         _StartItem(
165                 this,
166                 this.itemdef = def,
167                 this.respawntime, // defaultrespawntime
168                 this.respawntimejitter // defaultrespawntimejitter
169         );
170         #if 0 // WEAPONTODO
171         if (this.modelindex) { // don't precache if this was removed
172                 e.wr_init(e);
173         }
174         #endif
175 }