]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/server/compat/quake3.qc
Merge branch 'master' into bones_was_here/q3compat
[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/notifications/all.qh>
9 #include <common/stats.qh>
10 #include <common/weapons/_all.qh>
11 #include <common/weapons/_all.qh>
12 #include <server/client.qh>
13 #include <server/items/items.qh>
14 #include <server/items/spawning.qh>
15 #include <server/resources.qh>
16 #include <server/world.qh>
17
18 /***********************
19  * QUAKE 3 ENTITIES - So people can play quake3 maps with the xonotic weapons
20  ***********************
21
22  * Map entities NOT handled in this file:
23  holdable_invulnerability       Q3TA    buffs mutator
24  holdable_kamikaze              Q3TA    buffs mutator
25  holdable_teleporter            Q3A     buffs mutator
26  item_ammoregen                 Q3TA    buffs mutator
27  item_doubler                   Q3TA    buffs mutator
28  item_guard                     Q3TA    buffs mutator
29  item_scout                     Q3TA    buffs mutator
30  item_armor_jacket              CPMA    quake2.qc
31  item_flight                    Q3A     buffs mutator
32  item_haste                     Q3A     buffs mutator
33  item_health                    Q3A     quake.qc
34  item_health_large              Q3A     items.qc
35  item_health_small              Q3A     health.qh
36  item_health_mega               Q3A     health.qh
37  item_invis                     Q3A     buffs mutator
38  item_quad                      Q3A     items.qc
39  item_regen                     Q3A     buffs mutator
40  weapon_machinegun              Q3A     machinegun.qh
41  weapon_grenadelauncher         Q3A     mortar.qh
42  weapon_rocketlauncher          Q3A     devastator.qh
43  CTF spawnfuncs handled in sv_ctf.qc
44
45  NOTE: for best experience, you need to swap MGs with SGs in the map or it won't have a MG
46 */
47
48 // SG -> MG || SG
49 SPAWNFUNC_Q3_COND(weapon_shotgun, ammo_shells, (q3compat & Q3COMPAT_ARENA), WEP_MACHINEGUN, WEP_SHOTGUN)
50
51 // MG -> SG || MG
52 // Technically we should replace weapon_machinegun with WEP_SHOTGUN if Q3COMPAT_ARENA, but it almost never occurs on Q3 maps
53 SPAWNFUNC_Q3AMMO_COND(ammo_bullets, (q3compat & Q3COMPAT_ARENA), WEP_SHOTGUN, WEP_MACHINEGUN)
54
55 // GL -> Mortar
56 SPAWNFUNC_Q3AMMO(ammo_grenades, WEP_MORTAR)
57
58 // Team Arena Proximity Launcher -> Mortar
59 // It's more accurate to spawn Mine Layer but players prefer Mortar, and weapon_grenadelauncher is usually disabled by "notta" and weapon_prox_launcher placed at the same origin
60 SPAWNFUNC_Q3(weapon_prox_launcher, ammo_mines, WEP_MORTAR)
61
62 // Team Arena Chaingun -> HLAC
63 SPAWNFUNC_Q3(weapon_chaingun, ammo_belt, WEP_HLAC)
64
65 // Quake Live Heavy Machine Gun -> HLAC
66 SPAWNFUNC_Q3(weapon_hmg, ammo_hmg, WEP_HLAC)
67
68 // Team Arena Nailgun -> Crylink || Quake Nailgun -> Electro
69 SPAWNFUNC_Q3_COND(weapon_nailgun, ammo_nails, cvar("sv_mapformat_is_quake3"), WEP_CRYLINK, WEP_ELECTRO)
70
71 // LG -> Electro
72 SPAWNFUNC_Q3(weapon_lightning, ammo_lightning, WEP_ELECTRO)
73
74 // Plasma -> Hagar
75 SPAWNFUNC_Q3(weapon_plasmagun, ammo_cells, WEP_HAGAR)
76
77 // Rail -> Vortex
78 SPAWNFUNC_Q3(weapon_railgun, ammo_slugs, WEP_VORTEX)
79
80 // BFG -> Crylink || Fireball
81 SPAWNFUNC_Q3_COND(weapon_bfg, ammo_bfg, cvar_string("g_mod_balance") == "XDF", WEP_CRYLINK, WEP_FIREBALL)
82         // FIXME: WEP_FIREBALL has no ammo_type field so ammo_bfg is deleted by SPAWNFUNC_BODY
83
84 // grappling hook -> hook
85 SPAWNFUNC_WEAPON(weapon_grapplinghook, WEP_HOOK)
86
87 // RL -> RL
88 SPAWNFUNC_Q3AMMO(ammo_rockets, WEP_DEVASTATOR)
89
90 // Gauntlet -> Tuba
91 SPAWNFUNC_ITEM(weapon_gauntlet, WEP_TUBA)
92
93 // Armor
94 SPAWNFUNC_ITEM(item_armor_body, ITEM_ArmorMega)
95 SPAWNFUNC_ITEM(item_armor_combat, ITEM_ArmorBig)
96 SPAWNFUNC_ITEM(item_armor_shard, ITEM_ArmorSmall)
97 SPAWNFUNC_ITEM(item_armor_green, ITEM_ArmorMedium) // CCTF
98
99 // Battle Suit
100 SPAWNFUNC_ITEM(item_enviro, ITEM_Shield)
101
102 // medkit -> armor (we have no holdables)
103 SPAWNFUNC_ITEM(holdable_medkit, ITEM_ArmorBig)
104
105 .float wait;
106 .float delay;
107
108 // weapon remove ent from df
109 void target_init_verify(entity this)
110 {
111         entity trigger, targ;
112         for(trigger = NULL; (trigger = find(trigger, classname, "trigger_multiple")); )
113                 for(targ = NULL; (targ = find(targ, targetname, trigger.target)); )
114                         if (targ.classname == "target_init" || targ.classname == "target_give" || targ.classname == "target_items")
115                         {
116                                 trigger.wait = 0;
117                                 trigger.delay = 0;
118                                 targ.wait = 0;
119                                 targ.delay = 0;
120
121                                 //setsize(targ, trigger.mins, trigger.maxs);
122                                 //setorigin(targ, trigger.origin);
123                                 //remove(trigger);
124                         }
125 }
126
127 void target_init_use(entity this, entity actor, entity trigger)
128 {
129         if (!(this.spawnflags & 1))
130         {
131                 SetResource(actor, RES_ARMOR, start_armorvalue);
132                 actor.pauserotarmor_finished = time + autocvar_g_balance_pause_armor_rot;
133         }
134
135         if (!(this.spawnflags & 2))
136         {
137                 SetResource(actor, RES_HEALTH, start_health);
138                 actor.pauserothealth_finished = time + autocvar_g_balance_pause_health_rot;
139                 actor.pauseregen_finished = time + autocvar_g_balance_pause_health_regen;
140         }
141
142         if (!(this.spawnflags & 4))
143         {
144                 if(this.spawnflags & 32) // spawn with only melee
145                 {
146                         SetResource(actor, RES_SHELLS, 0);
147                         SetResource(actor, RES_BULLETS, 0);
148                         SetResource(actor, RES_ROCKETS, 0);
149                         SetResource(actor, RES_CELLS, 0);
150                         SetResource(actor, RES_PLASMA, 0);
151                         SetResource(actor, RES_FUEL, 0);
152
153                         STAT(WEAPONS, actor) = WEPSET(SHOTGUN);
154                 }
155                 else
156                 {
157                         SetResource(actor, RES_SHELLS, start_ammo_shells);
158                         SetResource(actor, RES_BULLETS, start_ammo_nails);
159                         SetResource(actor, RES_ROCKETS, start_ammo_rockets);
160                         SetResource(actor, RES_CELLS, start_ammo_cells);
161                         SetResource(actor, RES_PLASMA, start_ammo_plasma);
162                         SetResource(actor, RES_FUEL, start_ammo_fuel);
163
164                         STAT(WEAPONS, actor) = start_weapons;
165                 }
166         }
167
168         if (!(this.spawnflags & 8))
169         {
170                 STAT(STRENGTH_FINISHED, actor) = 0;
171                 STAT(INVINCIBLE_FINISHED, actor) = 0;
172                 if(STAT(BUFFS, actor)) // TODO: make a dropbuffs function to handle this
173                 {
174                         int buffid = buff_FirstFromFlags(STAT(BUFFS, actor)).m_id;
175                         Send_Notification(NOTIF_ONE, actor, MSG_MULTI, ITEM_BUFF_DROP, buffid);
176                         sound(actor, CH_TRIGGER, SND_BUFF_LOST, VOL_BASE, ATTN_NORM);
177                         if(!IS_INDEPENDENT_PLAYER(actor))
178                                 Send_Notification(NOTIF_ALL_EXCEPT, actor, MSG_INFO, INFO_ITEM_BUFF_LOST, actor.netname, buffid);
179                         STAT(BUFFS, actor) = 0;
180                         STAT(BUFF_TIME, actor) = 0;
181                 }
182         }
183
184         if (!(this.spawnflags & 16))
185         {
186                 // We don't have holdables.
187         }
188
189         SUB_UseTargets(this, actor, trigger);
190 }
191
192 spawnfunc(target_init)
193 {
194         this.use = target_init_use;
195         InitializeEntity(this, target_init_verify, INITPRIO_FINDTARGET);
196 }
197
198 // weapon give ent from Q3
199 void target_give_init(entity this)
200 {
201         IL_EACH(g_items, it.targetname == this.target,
202         {
203                 if (it.classname == "item_buff")
204                 {
205                         entity buff = buff_FirstFromFlags(STAT(BUFFS, it));
206                         this.netname = cons(this.netname, buff.netname);
207                         STAT(BUFF_TIME, this) += it.count;
208                 }
209                 else
210                 {
211                         if (it.ammo_rockets)
212                                 this.ammo_rockets += it.ammo_rockets;
213                         else if (it.ammo_cells)
214                                 this.ammo_cells += it.ammo_cells;
215                         else if (it.ammo_shells)
216                                 this.ammo_shells += it.ammo_shells;
217                         else if (it.ammo_nails)
218                                 this.ammo_nails += it.ammo_nails;
219                         else if (it.invincible_finished)
220                                 this.invincible_finished += it.invincible_finished;
221                         else if (it.strength_finished)
222                                 this.strength_finished += it.strength_finished;
223                         else if (it.health)
224                                 this.health += it.health;
225                         else if (it.armorvalue)
226                                 this.armorvalue += it.armorvalue;
227
228                         this.netname = cons(this.netname, it.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 .bool notteam;
278 .bool notsingle;
279 .bool notfree;
280 .bool notta;
281 .bool notvq3;
282 .bool notcpm;
283 .string gametype;
284 bool DoesQ3ARemoveThisEntity(entity this)
285 {
286         // Q3 style filters (DO NOT USE, THIS IS COMPAT ONLY)
287
288         // DeFRaG mappers use "notcpm" or "notvq3" to disable an entity in CPM or VQ3 physics
289         // Xonotic is usually played with a CPM-based physics so we default to CPM mode
290         if(cvar_string("g_mod_physics") == "Q3")
291         {
292                 if(this.notvq3)
293                         return true;
294         }
295         else if(this.notcpm)
296                 return true;
297
298         // Q3 mappers use "notq3a" or "notta" to disable an entity in Q3A or Q3TA
299         // Xonotic has ~equivalent features to Team Arena
300         if(this.notta)
301                 return true;
302
303         if(this.notsingle)
304                 if(maxclients == 1)
305                         return true;
306
307         if(this.notteam)
308                 if(teamplay)
309                         return true;
310
311         if(this.notfree)
312                 if(!teamplay)
313                         return true;
314
315         if(this.gametype)
316         {
317                 string gametypename;
318                 // From ioq3 g_spawn.c: static char *gametypeNames[] = {"ffa", "tournament", "single", "team", "ctf", "oneflag", "obelisk", "harvester"};
319                 gametypename = "ffa";
320                 if(teamplay)
321                         gametypename = "team";
322                 if(g_ctf)
323                         gametypename = "ctf";
324                 if(g_ctf && ctf_oneflag)
325                         gametypename = "oneflag";
326                 if(g_duel)
327                         gametypename = "tournament";
328                 if(maxclients == 1)
329                         gametypename = "single";
330                 // we do not have the other types (obelisk, harvester)
331                 if(strstrofs(this.gametype, gametypename, 0) < 0)
332                         return true;
333         }
334
335         return false;
336 }
337
338 int GetAmmoConsumptionQ3(string netname)
339 // Returns ammo consumed per shot by the primary/default fire mode
340 // Returns 0 if the netname has no ammo cvar
341 {
342         switch (netname)
343         {
344                 case "arc":        return autocvar_g_balance_arc_beam_ammo;
345                 case "devastator": return autocvar_g_balance_devastator_ammo;
346                 case "machinegun": return autocvar_g_balance_machinegun_sustained_ammo;
347                 case "minelayer":  return autocvar_g_balance_minelayer_ammo;
348                 case "seeker":     return autocvar_g_balance_seeker_tag_ammo;
349                 default:           return cvar(strcat("g_balance_", netname, "_primary_ammo"));
350         }
351 }
352