]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/server/compat/quake3.qc
39a26540539fb8edc8496ff28b4550f5f3d10f31
[xonotic/xonotic-data.pk3dir.git] / qcsrc / server / compat / quake3.qc
1 #include "quake3.qh"
2
3 #include <common/gamemodes/_mod.qh>
4 #include <common/gamemodes/gamemode/ctf/sv_ctf.qh>
5 #include <common/mapobjects/trigger/counter.qh>
6 #include <common/mapobjects/triggers.qh>
7 #include <common/mutators/mutator/buffs/buffs.qh>
8 #include <common/mutators/mutator/buffs/sv_buffs.qh>
9 #include <common/mutators/mutator/powerups/_mod.qh>
10 #include <common/mutators/mutator/status_effects/_mod.qh>
11 #include <common/notifications/all.qh>
12 #include <common/resources/sv_resources.qh>
13 #include <common/stats.qh>
14 #include <common/weapons/_all.qh>
15 #include <common/weapons/_all.qh>
16 #include <server/client.qh>
17 #include <server/items/items.qh>
18 #include <server/items/spawning.qh>
19 #include <server/world.qh>
20
21 /***********************
22  * QUAKE 3 ENTITIES - So people can play quake3 maps with the xonotic weapons
23  ***********************
24
25  * Map entities NOT handled in this file:
26  holdable_invulnerability    Q3TA   buffs/all.inc
27  holdable_kamikaze           Q3TA   buffs/all.inc
28  holdable_teleporter         Q3A    buffs/all.inc
29  item_ammoregen              Q3TA   buffs/all.inc
30  item_doubler                Q3TA   buffs/all.inc
31  item_guard                  Q3TA   buffs/all.inc
32  item_scout                  Q3TA   buffs/all.inc
33  item_armor_jacket           CPMA   quake2.qc
34  item_flight                 Q3A    buffs/all.inc
35  item_health                 Q3A    quake.qc
36  item_health_large           Q3A    items/spawning.qc
37  item_health_small           Q3A    health.qh
38  item_health_mega            Q3A    health.qh
39  item_regen                  Q3A    buffs/all.inc
40  item_key_gold               QL     keys.qc
41  item_key_silver             QL     keys.qc
42  item_key_master             QL     keys.qc
43  weapon_machinegun           Q3A    machinegun.qh
44  weapon_grenadelauncher      Q3A    mortar.qh
45  weapon_rocketlauncher       Q3A    devastator.qh
46  * CTF spawnfuncs in sv_ctf.qc
47
48  NOTE: for best experience, you need to swap MGs with SGs in the map or it won't have a MG
49 */
50
51 // SG -> MG || SG
52 SPAWNFUNC_Q3_COND(weapon_shotgun, ammo_shells, (q3compat & Q3COMPAT_ARENA), WEP_MACHINEGUN, WEP_SHOTGUN)
53
54 // MG -> SG || MG
55 // Technically we should replace weapon_machinegun with WEP_SHOTGUN if Q3COMPAT_ARENA, but it almost never occurs on Q3 maps
56 SPAWNFUNC_Q3AMMO_COND(ammo_bullets, (q3compat & Q3COMPAT_ARENA), WEP_SHOTGUN, WEP_MACHINEGUN)
57
58 // GL -> Mortar
59 SPAWNFUNC_Q3AMMO(ammo_grenades, WEP_MORTAR)
60
61 // Team Arena Proximity Launcher -> Mine Layer
62 SPAWNFUNC_Q3(weapon_prox_launcher, ammo_mines, WEP_MINE_LAYER)
63
64 // Team Arena Chaingun -> HLAC
65 SPAWNFUNC_Q3(weapon_chaingun, ammo_belt, WEP_HLAC)
66
67 // Quake Live Heavy Machine Gun -> HLAC
68 SPAWNFUNC_Q3(weapon_hmg, ammo_hmg, WEP_HLAC)
69
70 // Team Arena Nailgun -> Crylink || Quake Nailgun -> Electro
71 SPAWNFUNC_Q3_COND(weapon_nailgun, ammo_nails, autocvar_sv_mapformat_is_quake3, WEP_CRYLINK, WEP_ELECTRO)
72
73 // LG -> Electro
74 SPAWNFUNC_Q3(weapon_lightning, ammo_lightning, WEP_ELECTRO)
75
76 // Plasma -> Hagar
77 SPAWNFUNC_Q3(weapon_plasmagun, ammo_cells, WEP_HAGAR)
78
79 // Rail -> Vortex
80 SPAWNFUNC_Q3(weapon_railgun, ammo_slugs, WEP_VORTEX)
81
82 // BFG -> Crylink || Fireball
83 SPAWNFUNC_Q3_COND(weapon_bfg, ammo_bfg, cvar_string("g_mod_balance") == "XDF", WEP_CRYLINK, WEP_FIREBALL)
84         // FIXME: WEP_FIREBALL has no ammo_type field so ammo_bfg is deleted by SPAWNFUNC_BODY
85
86 // grappling hook -> hook
87 SPAWNFUNC_WEAPON(weapon_grapplinghook, WEP_HOOK)
88
89 // RL -> RL
90 SPAWNFUNC_Q3AMMO(ammo_rockets, WEP_DEVASTATOR)
91
92 // Gauntlet -> Tuba
93 SPAWNFUNC_ITEM(weapon_gauntlet, WEP_TUBA)
94
95 // Armor
96 SPAWNFUNC_ITEM(item_armor_body, ITEM_ArmorMega)
97 SPAWNFUNC_ITEM(item_armor_combat, ITEM_ArmorBig)
98 SPAWNFUNC_ITEM(item_armor_shard, ITEM_ArmorSmall)
99 SPAWNFUNC_ITEM(item_armor_green, ITEM_ArmorMedium) // CCTF
100
101 // Powerups
102 SPAWNFUNC_ITEM(item_quad, ITEM_Strength)
103 SPAWNFUNC_ITEM(item_enviro, ITEM_Shield)
104 SPAWNFUNC_ITEM(item_haste, ITEM_Speed)
105 SPAWNFUNC_ITEM(item_invis, ITEM_Invisibility)
106
107 // medkit -> armor (we have no holdables)
108 SPAWNFUNC_ITEM(holdable_medkit, ITEM_ArmorBig)
109
110 .float wait;
111 .float delay;
112
113 // weapon remove ent from df
114 void target_init_verify(entity this)
115 {
116         entity trigger, targ;
117         for(trigger = NULL; (trigger = find(trigger, classname, "trigger_multiple")); )
118                 for(targ = NULL; (targ = find(targ, targetname, trigger.target)); )
119                         if (targ.classname == "target_init" || targ.classname == "target_give" || targ.classname == "target_items")
120                         {
121                                 trigger.wait = 0;
122                                 trigger.delay = 0;
123                                 targ.wait = 0;
124                                 targ.delay = 0;
125
126                                 //setsize(targ, trigger.mins, trigger.maxs);
127                                 //setorigin(targ, trigger.origin);
128                                 //remove(trigger);
129                         }
130 }
131
132 void target_init_use(entity this, entity actor, entity trigger)
133 {
134         if (!(this.spawnflags & 1))
135         {
136                 SetResource(actor, RES_ARMOR, start_armorvalue);
137                 actor.pauserotarmor_finished = time + autocvar_g_balance_pause_armor_rot;
138         }
139
140         if (!(this.spawnflags & 2))
141         {
142                 SetResource(actor, RES_HEALTH, start_health);
143                 actor.pauserothealth_finished = time + autocvar_g_balance_pause_health_rot;
144                 actor.pauseregen_finished = time + autocvar_g_balance_pause_health_regen;
145         }
146
147         if (!(this.spawnflags & 4))
148         {
149                 if(this.spawnflags & 32) // spawn with only melee
150                 {
151                         SetResource(actor, RES_SHELLS, 0);
152                         SetResource(actor, RES_BULLETS, 0);
153                         SetResource(actor, RES_ROCKETS, 0);
154                         SetResource(actor, RES_CELLS, 0);
155                         SetResource(actor, RES_PLASMA, 0);
156                         SetResource(actor, RES_FUEL, 0);
157
158                         STAT(WEAPONS, actor) = WEPSET(SHOTGUN);
159                 }
160                 else
161                 {
162                         SetResource(actor, RES_SHELLS, start_ammo_shells);
163                         SetResource(actor, RES_BULLETS, start_ammo_nails);
164                         SetResource(actor, RES_ROCKETS, start_ammo_rockets);
165                         SetResource(actor, RES_CELLS, start_ammo_cells);
166                         SetResource(actor, RES_PLASMA, start_ammo_plasma);
167                         SetResource(actor, RES_FUEL, start_ammo_fuel);
168
169                         STAT(WEAPONS, actor) = start_weapons;
170                 }
171         }
172
173         if (!(this.spawnflags & 8))
174         {
175                 FOREACH(StatusEffect, it.instanceOfPowerups,
176                 {
177                         it.m_remove(it, actor, STATUSEFFECT_REMOVE_NORMAL);
178                 });
179                 entity heldbuff = buff_FirstFromFlags(actor);
180                 if(heldbuff) // TODO: make a dropbuffs function to handle this
181                 {
182                         int buffid = heldbuff.m_id;
183                         Send_Notification(NOTIF_ONE, actor, MSG_MULTI, ITEM_BUFF_DROP, buffid);
184                         sound(actor, CH_TRIGGER, SND_BUFF_LOST, VOL_BASE, ATTN_NORM);
185                         if(!IS_INDEPENDENT_PLAYER(actor))
186                                 Send_Notification(NOTIF_ALL_EXCEPT, actor, MSG_INFO, INFO_ITEM_BUFF_LOST, actor.netname, buffid);
187                         buff_RemoveAll(actor, STATUSEFFECT_REMOVE_NORMAL);
188                 }
189         }
190
191         if (!(this.spawnflags & 16))
192         {
193                 // We don't have holdables.
194         }
195
196         SUB_UseTargets(this, actor, trigger);
197 }
198
199 spawnfunc(target_init)
200 {
201         this.use = target_init_use;
202         InitializeEntity(this, target_init_verify, INITPRIO_FINDTARGET);
203 }
204
205 // weapon give ent from Q3
206 void target_give_init(entity this)
207 {
208         IL_EACH(g_items, it.targetname == this.target,
209         {
210                 if (it.classname == "item_buff")
211                 {
212                         this.netname = cons(this.netname, it.buffdef.netname);
213                         this.buffs_finished += it.buffs_finished;
214                 }
215                 else
216                 {
217                         this.ammo_rockets          += it.ammo_rockets;
218                         this.ammo_cells            += it.ammo_cells;
219                         this.ammo_shells           += it.ammo_shells;
220                         this.ammo_nails            += it.ammo_nails;
221                         this.invincible_finished   += it.invincible_finished;
222                         this.strength_finished     += it.strength_finished;
223                         this.speed_finished        += it.speed_finished;
224                         this.invisibility_finished += it.invisibility_finished;
225                         this.health                += it.health;
226                         this.armorvalue            += it.armorvalue;
227
228                         this.netname = cons(this.netname, (it.itemdef.m_weapon) ? it.itemdef.m_weapon.netname : it.itemdef.netname);
229                 }
230
231                 //remove(it); // removing ents in init functions causes havoc, workaround:
232                 setthink(it, SUB_Remove);
233                 it.nextthink = time;
234         });
235         this.spawnflags = 2;
236         this.spawnfunc_checked = true;
237         spawnfunc_target_items(this);
238         InitializeEntity(this, target_init_verify, INITPRIO_FINDTARGET);
239 }
240
241 spawnfunc(target_give)
242 {
243         InitializeEntity(this, target_give_init, INITPRIO_FINDTARGET);
244 }
245
246 void score_use(entity this, entity actor, entity trigger)
247 {
248         if(!IS_PLAYER(actor))
249                 return;
250         actor.fragsfilter_cnt += this.count;
251 }
252 spawnfunc(target_score)
253 {
254         if(!g_cts) { delete(this); return; }
255
256         if(!this.count)
257                 this.count = 1;
258         this.use = score_use;
259 }
260
261 void fragsfilter_use(entity this, entity actor, entity trigger)
262 {
263         if(!IS_PLAYER(actor))
264                 return;
265         if(actor.fragsfilter_cnt >= this.frags)
266                 SUB_UseTargets(this, actor, trigger);
267 }
268 spawnfunc(target_fragsFilter)
269 {
270         if(!g_cts) { delete(this); return; }
271
272         if(!this.frags)
273                 this.frags = 1;
274         this.use = fragsfilter_use;
275 }
276
277 #define PRINT_REDTEAM BIT(0) // Q3 only, not used in Q3DF
278 #define PRINT_BLUETEAM BIT(1) // Q3 only, not used in Q3DF
279 #define PRINT_PRIVATE BIT(2) // Q3 only, not used in Q3DF
280 #define PRINT_BROADCAST BIT(3) // Q3DF only, default behavior in Q3
281
282 void target_print_message(entity this, entity actor)
283 {
284         centerprint(actor, this.message);
285         play2(actor, SND(TALK));
286 }
287
288 void target_print_use(entity this, entity actor, entity trigger)
289 {
290         if(!IS_PLAYER(actor))
291                 return;
292
293         if(this.message == "")
294                 return;
295
296         bool priv, red, blue;
297         if(!(q3compat & Q3COMPAT_DEFI)) // Q3 spawnflags
298         {
299                 priv = boolean(this.spawnflags & PRINT_PRIVATE);
300                 red = boolean(this.spawnflags & PRINT_REDTEAM);
301                 blue = boolean(this.spawnflags & PRINT_BLUETEAM);
302         }
303         else // Q3DF spawnflags
304         {
305                 priv = !boolean(this.spawnflags & PRINT_BROADCAST);
306                 red = blue = false;
307         }
308
309         if(priv)
310         {
311                 target_print_message(this, actor);
312         }
313         else
314         {
315                 FOREACH_CLIENT(IS_PLAYER(it) && IS_REAL_CLIENT(it) && ((!red && !blue) || (red && it.team == NUM_TEAM_1) || (blue && it.team == NUM_TEAM_2)), target_print_message(this, it));
316         }
317 }
318
319 /*
320  * ENTITY PARAMETERS:
321  *
322  *   message: text string to print on screen.
323  *   targetname: the activating trigger points to this.
324  */
325 spawnfunc(target_print)
326 {
327         this.use = target_print_use;
328 }
329
330 // target_smallprint, Q3DF only
331 spawnfunc(target_smallprint)
332 {
333         spawnfunc_target_print(this);
334 }
335
336 .bool notteam;
337 .bool notsingle;
338 .bool notfree;
339 .bool notta;
340 .bool notvq3;
341 .bool notcpm;
342 .string gametype;
343 .string not_gametype;
344 bool DoesQ3ARemoveThisEntity(entity this)
345 {
346         // Q3 style filters (DO NOT USE, THIS IS COMPAT ONLY)
347
348         if (!this.classname)
349                 return true;
350
351         // DeFRaG mappers use "notcpm" or "notvq3" to disable an entity in CPM or VQ3 physics
352         // Xonotic is usually played with a CPM-based physics so we default to CPM mode
353         if(cvar_string("g_mod_physics") == "Q3")
354         {
355                 if(this.notvq3)
356                         return true;
357         }
358         else if(this.notcpm)
359                 return true;
360
361         // Q3 mappers use "notq3a" or "notta" to disable an entity in Q3A or Q3TA
362         // Xonotic has ~equivalent features to Team Arena
363         if(this.notta)
364                 return true;
365
366         // FIXME: singleplayer does not use maxclients 1 as that would prevent bots,
367         // this is the case in Q3 also, it uses another method to block clients.
368         // Only accessible in VQ3, via the `spmap` command.
369         if(this.notsingle)
370                 if(maxclients == 1 && IS_GAMETYPE(DEATHMATCH))
371                         return true;
372
373         if(this.notteam)
374                 if(teamplay)
375                         return true;
376
377         if(this.notfree)
378                 if(!teamplay)
379                         return true;
380
381         if(this.gametype || this.not_gametype)
382         {
383                 // Q3 checks these with strstr(): case-sensitive, no gametype can be a substring of another,
384                 // any separator is allowed (conventions are: spaces, commas, or commas with spaces).
385                 // QL's entities.def says they're space delineated.
386
387                 // Q3 gametype entity fields: ffa tournament single team ctf oneflag obelisk  harvester    (game/g_spawn.c)
388                 // Q3 arena file 'type' key:  ffa tourney                ctf oneflag overload harvester    (ui/ui_gameinfo.c)
389
390                 // QL gametype entity fields: ffa duel tdm ca ft rr ctf ad dom har 1f      race ob
391                 // QL arena file 'type' key:  ffa duel tdm ca ft rr ctf ad dom har oneflag race
392
393                 string gametypename_q3, gametypename_ql;
394
395                 // One of these will apply if our gametype has no Q3/QL equivalent
396                 if(teamplay)
397                 {
398                         gametypename_q3 = "team";
399                         gametypename_ql = "tdm";
400                 }
401                 else
402                         gametypename_q3 = gametypename_ql = "ffa";
403
404                 if(g_ctf)
405                 {
406                         if (ctf_oneflag)
407                         {
408                                 gametypename_q3 = "oneflag";
409                                 gametypename_ql = "1f";
410                         }
411                         else
412                                 gametypename_q3 = gametypename_ql = "ctf";
413                 }
414                 else if(g_duel)
415                 {
416                         gametypename_q3 = "tournament";
417                         gametypename_ql = "duel";
418                 }
419                 else if(IS_GAMETYPE(DEATHMATCH) && maxclients == 1)
420                         gametypename_q3 = "single";
421                 else if(g_ca)
422                         gametypename_ql = "ql";
423                 else if(IS_GAMETYPE(FREEZETAG))
424                         gametypename_ql = "ft";
425                 else if(IS_GAMETYPE(DOMINATION))
426                         gametypename_ql = "dom";
427                 else if(g_race || g_cts)
428                         gametypename_ql = "race";
429
430                 if(this.gametype)
431                 if(strstrofs(this.gametype, gametypename_q3, 0) < 0
432                 && strstrofs(this.gametype, gametypename_ql, 0) < 0)
433                         return true;
434
435                 // Only supported by QL
436                 if(strstrofs(this.not_gametype, gametypename_ql, 0) >= 0)
437                         return true;
438         }
439
440         return false;
441 }
442
443 int GetAmmoConsumptionQ3(string netname)
444 // Returns ammo consumed per shot by the primary/default fire mode
445 // Returns 0 if the netname has no ammo cvar
446 {
447         switch (netname)
448         {
449                 case "arc":        return autocvar_g_balance_arc_beam_ammo;
450                 case "devastator": return autocvar_g_balance_devastator_ammo;
451                 case "machinegun": return autocvar_g_balance_machinegun_sustained_ammo;
452                 case "minelayer":  return autocvar_g_balance_minelayer_ammo;
453                 case "seeker":     return autocvar_g_balance_seeker_tag_ammo;
454                 default:           return cvar(strcat("g_balance_", netname, "_primary_ammo"));
455         }
456 }
457