]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/server/compat/quake3.qc
Spawn HLAC and cell ammo in place of QL HMG and ammo_hmg
[xonotic/xonotic-data.pk3dir.git] / qcsrc / server / compat / quake3.qc
1 #include "quake3.qh"
2
3 #include <server/defs.qh>
4 #include <server/miscfunctions.qh>
5 #include <server/items/items.qh>
6 #include <server/items/spawning.qh>
7 #include <server/resources.qh>
8 #include <common/gamemodes/_mod.qh>
9 #include <common/gamemodes/gamemode/ctf/sv_ctf.qh>
10 #include <common/mapobjects/triggers.qh>
11 #include <common/mapobjects/trigger/counter.qh>
12 #include <common/mutators/mutator/buffs/buffs.qh>
13 #include <common/notifications/all.qh>
14 #include <common/weapons/_all.qh>
15
16 /***********************
17  * QUAKE 3 ENTITIES - So people can play quake3 maps with the xonotic weapons
18  ***********************
19
20  * Map entities NOT handled in this file:
21  holdable_invulnerability       Q3TA    currently unsupported
22  holdable_kamikaze              Q3TA    currently unsupported
23  item_ammoregen                 Q3TA    handled by buffs mutator
24  item_doubler                   Q3TA    handled by buffs mutator
25  item_guard                     Q3TA    handled by buffs mutator
26  item_scout                     Q3TA    handled by buffs mutator
27  item_armor_jacket              CPMA    handled in quake2.qc
28  item_flight                    Q3A     handled by buffs mutator
29  item_haste                     Q3A     handled by buffs mutator
30  item_health                    Q3A     handled in quake.qc
31  item_health_large              Q3A     handled in items.qc
32  item_health_small              Q3A     handled in health.qh
33  item_health_mega               Q3A     handled in health.qh
34  item_invis                     Q3A     handled by buffs mutator
35  item_quad                      Q3A     handled in items.qc
36  item_regen                     Q3A     handled by buffs mutator
37  CTF spawnfuncs handled in sv_ctf.qc
38
39  NOTE: for best experience, you need to swap MGs with SGs in the map or it won't have a MG
40 */
41
42 // SG -> MG || SG
43 SPAWNFUNC_ITEM_COND(ammo_shells, (q3compat & BIT(0)), ITEM_Bullets, ITEM_Shells)
44 SPAWNFUNC_WEAPON_COND(weapon_shotgun, (q3compat & BIT(0)), WEP_MACHINEGUN, WEP_SHOTGUN)
45
46 // MG -> SG || MG
47 SPAWNFUNC_ITEM_COND(ammo_bullets, (q3compat & BIT(0)), ITEM_Shells, ITEM_Bullets)
48
49 // GL -> Mortar
50 SPAWNFUNC_ITEM(ammo_grenades, ITEM_Rockets)
51
52 // Team Arena Proximity Launcher -> Mine Layer
53 SPAWNFUNC_WEAPON(weapon_prox_launcher, WEP_MINE_LAYER)
54 SPAWNFUNC_ITEM(ammo_mines, ITEM_Rockets)
55
56 // Team Arena Chaingun -> HLAC
57 SPAWNFUNC_WEAPON(weapon_chaingun, WEP_HLAC)
58 SPAWNFUNC_ITEM(ammo_belt, ITEM_Cells)
59
60 // Quake Live Heavy Machine Gun -> HLAC
61 SPAWNFUNC_WEAPON(weapon_hmg, WEP_HLAC)
62 SPAWNFUNC_ITEM(ammo_hmg, ITEM_Cells)
63
64 // Team Arena Nailgun -> Crylink || Quake Nailgun -> Electro
65 SPAWNFUNC_WEAPON_COND(weapon_nailgun, cvar("sv_mapformat_is_quake3"), WEP_CRYLINK, WEP_ELECTRO)
66 SPAWNFUNC_ITEM(ammo_nails, ITEM_Cells)
67
68 // LG -> Electro
69 SPAWNFUNC_WEAPON(weapon_lightning, WEP_ELECTRO)
70 SPAWNFUNC_ITEM(ammo_lightning, ITEM_Cells)
71
72 // Plasma -> Hagar
73 SPAWNFUNC_WEAPON(weapon_plasmagun, WEP_HAGAR)
74 SPAWNFUNC_ITEM(ammo_cells, ITEM_Rockets)
75
76 // Rail -> Vortex
77 SPAWNFUNC_WEAPON(weapon_railgun, WEP_VORTEX)
78 SPAWNFUNC_ITEM(ammo_slugs, ITEM_Cells)
79
80 // BFG -> Crylink || Fireball
81 SPAWNFUNC_WEAPON_COND(weapon_bfg, cvar_string("g_mod_balance") == "XDF", WEP_CRYLINK, WEP_FIREBALL)
82 SPAWNFUNC_ITEM_COND(ammo_bfg, cvar_string("g_mod_balance") == "XDF", ITEM_Cells, ITEM_Rockets)
83
84 // grappling hook -> hook
85 SPAWNFUNC_WEAPON(weapon_grapplinghook, WEP_HOOK)
86
87 // RL -> RL
88 SPAWNFUNC_ITEM(ammo_rockets, ITEM_Rockets)
89
90 // Armor
91 SPAWNFUNC_ITEM(item_armor_body, ITEM_ArmorMega)
92 SPAWNFUNC_ITEM(item_armor_combat, ITEM_ArmorBig)
93 SPAWNFUNC_ITEM(item_armor_shard, ITEM_ArmorSmall)
94 SPAWNFUNC_ITEM(item_armor_green, ITEM_ArmorMedium) // CCTF
95
96 // Battle Suit
97 SPAWNFUNC_ITEM(item_enviro, ITEM_Shield)
98
99 // medkit -> armor (we have no holdables)
100 SPAWNFUNC_ITEM(holdable_medkit, ITEM_ArmorBig)
101
102 .float wait;
103 .float delay;
104
105 // weapon remove ent from df
106 void target_init_verify(entity this)
107 {
108         entity trigger, targ;
109         for(trigger = NULL; (trigger = find(trigger, classname, "trigger_multiple")); )
110                 for(targ = NULL; (targ = find(targ, targetname, trigger.target)); )
111                         if (targ.classname == "target_init" || targ.classname == "target_give" || targ.classname == "target_items")
112                         {
113                                 trigger.wait = 0;
114                                 trigger.delay = 0;
115                                 targ.wait = 0;
116                                 targ.delay = 0;
117
118                                 //setsize(targ, trigger.mins, trigger.maxs);
119                                 //setorigin(targ, trigger.origin);
120                                 //remove(trigger);
121                         }
122 }
123
124 void target_init_use(entity this, entity actor, entity trigger)
125 {
126         if (!(this.spawnflags & 1))
127         {
128                 SetResource(actor, RES_ARMOR, start_armorvalue);
129                 actor.pauserotarmor_finished = time + autocvar_g_balance_pause_armor_rot;
130         }
131
132         if (!(this.spawnflags & 2))
133         {
134                 SetResource(actor, RES_HEALTH, start_health);
135                 actor.pauserothealth_finished = time + autocvar_g_balance_pause_health_rot;
136                 actor.pauseregen_finished = time + autocvar_g_balance_pause_health_regen;
137         }
138
139         if (!(this.spawnflags & 4))
140         {
141                 if(this.spawnflags & 32) // spawn with only melee
142                 {
143                         SetResource(actor, RES_SHELLS, 0);
144                         SetResource(actor, RES_BULLETS, 0);
145                         SetResource(actor, RES_ROCKETS, 0);
146                         SetResource(actor, RES_CELLS, 0);
147                         SetResource(actor, RES_PLASMA, 0);
148                         SetResource(actor, RES_FUEL, 0);
149
150                         STAT(WEAPONS, actor) = WEPSET(SHOTGUN);
151                 }
152                 else
153                 {
154                         SetResource(actor, RES_SHELLS, start_ammo_shells);
155                         SetResource(actor, RES_BULLETS, start_ammo_nails);
156                         SetResource(actor, RES_ROCKETS, start_ammo_rockets);
157                         SetResource(actor, RES_CELLS, start_ammo_cells);
158                         SetResource(actor, RES_PLASMA, start_ammo_plasma);
159                         SetResource(actor, RES_FUEL, start_ammo_fuel);
160
161                         STAT(WEAPONS, actor) = start_weapons;
162                 }
163         }
164
165         if (!(this.spawnflags & 8))
166         {
167                 STAT(STRENGTH_FINISHED, actor) = 0;
168                 STAT(INVINCIBLE_FINISHED, actor) = 0;
169                 if(STAT(BUFFS, actor)) // TODO: make a dropbuffs function to handle this
170                 {
171                         int buffid = buff_FirstFromFlags(STAT(BUFFS, actor)).m_id;
172                         Send_Notification(NOTIF_ONE, actor, MSG_MULTI, ITEM_BUFF_DROP, buffid);
173                         sound(actor, CH_TRIGGER, SND_BUFF_LOST, VOL_BASE, ATTN_NORM);
174                         if(!IS_INDEPENDENT_PLAYER(actor))
175                                 Send_Notification(NOTIF_ALL_EXCEPT, actor, MSG_INFO, INFO_ITEM_BUFF_LOST, actor.netname, buffid);
176                         STAT(BUFFS, actor) = 0;
177                         STAT(BUFF_TIME, actor) = 0;
178                 }
179         }
180
181         if (!(this.spawnflags & 16))
182         {
183                 // We don't have holdables.
184         }
185
186         SUB_UseTargets(this, actor, trigger);
187 }
188
189 spawnfunc(target_init)
190 {
191         this.use = target_init_use;
192         InitializeEntity(this, target_init_verify, INITPRIO_FINDTARGET);
193 }
194
195 // weapon give ent from defrag
196 void target_give_init(entity this)
197 {
198         IL_EACH(g_items, it.targetname == this.target,
199         {
200                 if (it.classname == "weapon_devastator") {
201                         SetResourceExplicit(this, RES_ROCKETS, GetResource(this, RES_ROCKETS) + it.count * WEP_CVAR_PRI(devastator, ammo)); // WEAPONTODO
202                         this.netname = cons(this.netname, "devastator");
203                 }
204                 else if (it.classname == "weapon_vortex") {
205                         SetResourceExplicit(this, RES_CELLS, GetResource(this, RES_CELLS) + it.count * WEP_CVAR_PRI(vortex, ammo)); // WEAPONTODO
206                         this.netname = cons(this.netname, "vortex");
207                 }
208                 else if (it.classname == "weapon_electro") {
209                         SetResourceExplicit(this, RES_CELLS, GetResource(this, RES_CELLS) + it.count * WEP_CVAR_PRI(electro, ammo)); // WEAPONTODO
210                         this.netname = cons(this.netname, "electro");
211                 }
212                 else if (it.classname == "weapon_hagar") {
213                         SetResourceExplicit(this, RES_ROCKETS, GetResource(this, RES_ROCKETS) + it.count * WEP_CVAR_PRI(hagar, ammo)); // WEAPONTODO
214                         this.netname = cons(this.netname, "hagar");
215                 }
216                 else if (it.classname == "weapon_crylink") {
217                         SetResourceExplicit(this, RES_CELLS, GetResource(this, RES_CELLS) + it.count * WEP_CVAR_PRI(crylink, ammo)); // WEAPONTODO
218                         this.netname = cons(this.netname, "crylink");
219                 }
220                 else if (it.classname == "weapon_mortar") {
221                         SetResourceExplicit(this, RES_ROCKETS, GetResource(this, RES_ROCKETS) + it.count * WEP_CVAR_PRI(mortar, ammo)); // WEAPONTODO
222                         this.netname = cons(this.netname, "mortar");
223                 }
224                 else if (it.classname == "weapon_shotgun") {
225                         SetResourceExplicit(this, RES_SHELLS, GetResource(this, RES_SHELLS) + it.count * WEP_CVAR_PRI(shotgun, ammo)); // WEAPONTODO
226                         this.netname = cons(this.netname, "shotgun");
227                 }
228                 else if (it.classname == "item_armor_mega")
229                         SetResourceExplicit(this, RES_ARMOR, 100);
230                 else if (it.classname == "item_health_mega")
231                         SetResourceExplicit(this, RES_HEALTH, 200);
232                 else if (it.classname == "item_buff") {
233                         entity buff = buff_FirstFromFlags(STAT(BUFFS, it));
234                         this.netname = cons(this.netname, buff.netname);
235                         STAT(BUFF_TIME, this) = it.count;
236                 }
237
238                 //remove(it); // removing ents in init functions causes havoc, workaround:
239         setthink(it, SUB_Remove);
240         it.nextthink = time;
241         });
242         this.spawnflags = 2;
243         this.spawnfunc_checked = true;
244         spawnfunc_target_items(this);
245         InitializeEntity(this, target_init_verify, INITPRIO_FINDTARGET);
246 }
247
248 spawnfunc(target_give)
249 {
250         InitializeEntity(this, target_give_init, INITPRIO_FINDTARGET);
251 }
252
253 void score_use(entity this, entity actor, entity trigger)
254 {
255         if(!IS_PLAYER(actor))
256                 return;
257         actor.fragsfilter_cnt += this.count;
258 }
259 spawnfunc(target_score)
260 {
261         if(!g_cts) { delete(this); return; }
262
263         if(!this.count)
264                 this.count = 1;
265         this.use = score_use;
266 }
267
268 void fragsfilter_use(entity this, entity actor, entity trigger)
269 {
270         if(!IS_PLAYER(actor))
271                 return;
272         if(actor.fragsfilter_cnt >= this.frags)
273                 SUB_UseTargets(this, actor, trigger);
274 }
275 spawnfunc(target_fragsFilter)
276 {
277         if(!g_cts) { delete(this); return; }
278
279         if(!this.frags)
280                 this.frags = 1;
281         this.use = fragsfilter_use;
282 }
283
284 .bool notteam;
285 .bool notsingle;
286 .bool notfree;
287 .bool notta;
288 .bool notvq3;
289 .bool notcpm;
290 .string gametype;
291 bool DoesQ3ARemoveThisEntity(entity this)
292 {
293         // Q3 style filters (DO NOT USE, THIS IS COMPAT ONLY)
294
295         // DeFRaG mappers use "notcpm" or "notvq3" to disable an entity in CPM or VQ3 physics
296         // Xonotic is usually played with a CPM-based physics so we default to CPM mode
297         if(cvar_string("g_mod_physics") == "Q3")
298         {
299                 if(this.notvq3)
300                         return true;
301         }
302         else if(this.notcpm)
303                 return true;
304
305         // Q3 mappers use "notq3a" or "notta" to disable an entity in Q3A or Q3TA
306         // Xonotic has ~equivalent features to Team Arena
307         if(this.notta)
308                 return true;
309
310         if(this.notsingle)
311                 if(maxclients == 1)
312                         return true;
313
314         if(this.notteam)
315                 if(teamplay)
316                         return true;
317
318         if(this.notfree)
319                 if(!teamplay)
320                         return true;
321
322         if(this.gametype)
323         {
324                 string gametypename;
325                 // From ioq3 g_spawn.c: static char *gametypeNames[] = {"ffa", "tournament", "single", "team", "ctf", "oneflag", "obelisk", "harvester"};
326                 gametypename = "ffa";
327                 if(teamplay)
328                         gametypename = "team";
329                 if(g_ctf)
330                         gametypename = "ctf";
331                 if(g_ctf && ctf_oneflag)
332                         gametypename = "oneflag";
333                 if(g_duel)
334                         gametypename = "tournament";
335                 if(maxclients == 1)
336                         gametypename = "single";
337                 // we do not have the other types (obelisk, harvester)
338                 if(strstrofs(this.gametype, gametypename, 0) < 0)
339                         return true;
340         }
341
342         return false;
343 }