]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/server/compat/quake3.qc
Resolve conflicts 2: 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/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/stats.qh>
13 #include <common/weapons/_all.qh>
14 #include <common/weapons/_all.qh>
15 #include <server/client.qh>
16 #include <server/items/items.qh>
17 #include <server/items/spawning.qh>
18 #include <server/resources.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 mutator
27  holdable_kamikaze              Q3TA    buffs mutator
28  holdable_teleporter            Q3A     buffs mutator
29  item_ammoregen                 Q3TA    buffs mutator
30  item_doubler                   Q3TA    buffs mutator
31  item_guard                     Q3TA    buffs mutator
32  item_scout                     Q3TA    buffs mutator
33  item_armor_jacket              CPMA    quake2.qc
34  item_flight                    Q3A     buffs mutator
35  item_haste                     Q3A     buffs mutator
36  item_health                    Q3A     quake.qc
37  item_health_large              Q3A     items.qc
38  item_health_small              Q3A     health.qh
39  item_health_mega               Q3A     health.qh
40  item_invis                     Q3A     buffs mutator
41  item_quad                      Q3A     items.qc
42  item_regen                     Q3A     buffs mutator
43  weapon_machinegun              Q3A     machinegun.qh
44  weapon_grenadelauncher         Q3A     mortar.qh
45  weapon_rocketlauncher          Q3A     devastator.qh
46  CTF spawnfuncs handled 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 -> Mortar
62 // 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
63 SPAWNFUNC_Q3(weapon_prox_launcher, ammo_mines, WEP_MORTAR)
64
65 // Team Arena Chaingun -> HLAC
66 SPAWNFUNC_Q3(weapon_chaingun, ammo_belt, WEP_HLAC)
67
68 // Quake Live Heavy Machine Gun -> HLAC
69 SPAWNFUNC_Q3(weapon_hmg, ammo_hmg, WEP_HLAC)
70
71 // Team Arena Nailgun -> Crylink || Quake Nailgun -> Electro
72 SPAWNFUNC_Q3_COND(weapon_nailgun, ammo_nails, cvar("sv_mapformat_is_quake3"), WEP_CRYLINK, WEP_ELECTRO)
73
74 // LG -> Electro
75 SPAWNFUNC_Q3(weapon_lightning, ammo_lightning, WEP_ELECTRO)
76
77 // Plasma -> Hagar
78 SPAWNFUNC_Q3(weapon_plasmagun, ammo_cells, WEP_HAGAR)
79
80 // Rail -> Vortex
81 SPAWNFUNC_Q3(weapon_railgun, ammo_slugs, WEP_VORTEX)
82
83 // BFG -> Crylink || Fireball
84 SPAWNFUNC_Q3_COND(weapon_bfg, ammo_bfg, cvar_string("g_mod_balance") == "XDF", WEP_CRYLINK, WEP_FIREBALL)
85         // FIXME: WEP_FIREBALL has no ammo_type field so ammo_bfg is deleted by SPAWNFUNC_BODY
86
87 // grappling hook -> hook
88 SPAWNFUNC_WEAPON(weapon_grapplinghook, WEP_HOOK)
89
90 // RL -> RL
91 SPAWNFUNC_Q3AMMO(ammo_rockets, WEP_DEVASTATOR)
92
93 // Gauntlet -> Tuba
94 SPAWNFUNC_ITEM(weapon_gauntlet, WEP_TUBA)
95
96 // Armor
97 SPAWNFUNC_ITEM(item_armor_body, ITEM_ArmorMega)
98 SPAWNFUNC_ITEM(item_armor_combat, ITEM_ArmorBig)
99 SPAWNFUNC_ITEM(item_armor_shard, ITEM_ArmorSmall)
100 SPAWNFUNC_ITEM(item_armor_green, ITEM_ArmorMedium) // CCTF
101
102 // Battle Suit
103 SPAWNFUNC_ITEM(item_enviro, ITEM_Shield)
104
105 // medkit -> armor (we have no holdables)
106 SPAWNFUNC_ITEM(holdable_medkit, ITEM_ArmorBig)
107
108 .float wait;
109 .float delay;
110
111 // weapon remove ent from df
112 void target_init_verify(entity this)
113 {
114         entity trigger, targ;
115         for(trigger = NULL; (trigger = find(trigger, classname, "trigger_multiple")); )
116                 for(targ = NULL; (targ = find(targ, targetname, trigger.target)); )
117                         if (targ.classname == "target_init" || targ.classname == "target_give" || targ.classname == "target_items")
118                         {
119                                 trigger.wait = 0;
120                                 trigger.delay = 0;
121                                 targ.wait = 0;
122                                 targ.delay = 0;
123
124                                 //setsize(targ, trigger.mins, trigger.maxs);
125                                 //setorigin(targ, trigger.origin);
126                                 //remove(trigger);
127                         }
128 }
129
130 void target_init_use(entity this, entity actor, entity trigger)
131 {
132         if (!(this.spawnflags & 1))
133         {
134                 SetResource(actor, RES_ARMOR, start_armorvalue);
135                 actor.pauserotarmor_finished = time + autocvar_g_balance_pause_armor_rot;
136         }
137
138         if (!(this.spawnflags & 2))
139         {
140                 SetResource(actor, RES_HEALTH, start_health);
141                 actor.pauserothealth_finished = time + autocvar_g_balance_pause_health_rot;
142                 actor.pauseregen_finished = time + autocvar_g_balance_pause_health_regen;
143         }
144
145         if (!(this.spawnflags & 4))
146         {
147                 if(this.spawnflags & 32) // spawn with only melee
148                 {
149                         SetResource(actor, RES_SHELLS, 0);
150                         SetResource(actor, RES_BULLETS, 0);
151                         SetResource(actor, RES_ROCKETS, 0);
152                         SetResource(actor, RES_CELLS, 0);
153                         SetResource(actor, RES_PLASMA, 0);
154                         SetResource(actor, RES_FUEL, 0);
155
156                         STAT(WEAPONS, actor) = WEPSET(SHOTGUN);
157                 }
158                 else
159                 {
160                         SetResource(actor, RES_SHELLS, start_ammo_shells);
161                         SetResource(actor, RES_BULLETS, start_ammo_nails);
162                         SetResource(actor, RES_ROCKETS, start_ammo_rockets);
163                         SetResource(actor, RES_CELLS, start_ammo_cells);
164                         SetResource(actor, RES_PLASMA, start_ammo_plasma);
165                         SetResource(actor, RES_FUEL, start_ammo_fuel);
166
167                         STAT(WEAPONS, actor) = start_weapons;
168                 }
169         }
170
171         if (!(this.spawnflags & 8))
172         {
173                 FOREACH(StatusEffect, it.instanceOfPowerups,
174                 {
175                         it.m_remove(it, actor, STATUSEFFECT_REMOVE_NORMAL);
176                 });
177                 entity heldbuff = buff_FirstFromFlags(actor);
178                 if(heldbuff) // TODO: make a dropbuffs function to handle this
179                 {
180                         int buffid = heldbuff.m_id;
181                         Send_Notification(NOTIF_ONE, actor, MSG_MULTI, ITEM_BUFF_DROP, buffid);
182                         sound(actor, CH_TRIGGER, SND_BUFF_LOST, VOL_BASE, ATTN_NORM);
183                         if(!IS_INDEPENDENT_PLAYER(actor))
184                                 Send_Notification(NOTIF_ALL_EXCEPT, actor, MSG_INFO, INFO_ITEM_BUFF_LOST, actor.netname, buffid);
185                         buff_RemoveAll(actor, STATUSEFFECT_REMOVE_NORMAL);
186                 }
187         }
188
189         if (!(this.spawnflags & 16))
190         {
191                 // We don't have holdables.
192         }
193
194         SUB_UseTargets(this, actor, trigger);
195 }
196
197 spawnfunc(target_init)
198 {
199         this.use = target_init_use;
200         InitializeEntity(this, target_init_verify, INITPRIO_FINDTARGET);
201 }
202
203 // weapon give ent from Q3
204 void target_give_init(entity this)
205 {
206         IL_EACH(g_items, it.targetname == this.target,
207         {
208                 if (it.classname == "item_buff")
209                 {
210                         entity buff = it.buffdef;
211                         this.netname = cons(this.netname, buff.netname);
212                         this.buffs_finished += it.count;
213                 }
214                 else
215                 {
216                         if (it.ammo_rockets)
217                                 this.ammo_rockets += it.ammo_rockets;
218                         else if (it.ammo_cells)
219                                 this.ammo_cells += it.ammo_cells;
220                         else if (it.ammo_shells)
221                                 this.ammo_shells += it.ammo_shells;
222                         else if (it.ammo_nails)
223                                 this.ammo_nails += it.ammo_nails;
224                         else if (it.invincible_finished)
225                                 this.invincible_finished += it.invincible_finished;
226                         else if (it.strength_finished)
227                                 this.strength_finished += it.strength_finished;
228                         else if (it.health)
229                                 this.health += it.health;
230                         else if (it.armorvalue)
231                                 this.armorvalue += it.armorvalue;
232
233                         this.netname = cons(this.netname, it.netname);
234                 }
235
236                 //remove(it); // removing ents in init functions causes havoc, workaround:
237                 setthink(it, SUB_Remove);
238                 it.nextthink = time;
239         });
240         this.spawnflags = 2;
241         this.spawnfunc_checked = true;
242         spawnfunc_target_items(this);
243         InitializeEntity(this, target_init_verify, INITPRIO_FINDTARGET);
244 }
245
246 spawnfunc(target_give)
247 {
248         InitializeEntity(this, target_give_init, INITPRIO_FINDTARGET);
249 }
250
251 void score_use(entity this, entity actor, entity trigger)
252 {
253         if(!IS_PLAYER(actor))
254                 return;
255         actor.fragsfilter_cnt += this.count;
256 }
257 spawnfunc(target_score)
258 {
259         if(!g_cts) { delete(this); return; }
260
261         if(!this.count)
262                 this.count = 1;
263         this.use = score_use;
264 }
265
266 void fragsfilter_use(entity this, entity actor, entity trigger)
267 {
268         if(!IS_PLAYER(actor))
269                 return;
270         if(actor.fragsfilter_cnt >= this.frags)
271                 SUB_UseTargets(this, actor, trigger);
272 }
273 spawnfunc(target_fragsFilter)
274 {
275         if(!g_cts) { delete(this); return; }
276
277         if(!this.frags)
278                 this.frags = 1;
279         this.use = fragsfilter_use;
280 }
281
282 .bool notteam;
283 .bool notsingle;
284 .bool notfree;
285 .bool notta;
286 .bool notvq3;
287 .bool notcpm;
288 .string gametype;
289 bool DoesQ3ARemoveThisEntity(entity this)
290 {
291         // Q3 style filters (DO NOT USE, THIS IS COMPAT ONLY)
292
293         // DeFRaG mappers use "notcpm" or "notvq3" to disable an entity in CPM or VQ3 physics
294         // Xonotic is usually played with a CPM-based physics so we default to CPM mode
295         if(cvar_string("g_mod_physics") == "Q3")
296         {
297                 if(this.notvq3)
298                         return true;
299         }
300         else if(this.notcpm)
301                 return true;
302
303         // Q3 mappers use "notq3a" or "notta" to disable an entity in Q3A or Q3TA
304         // Xonotic has ~equivalent features to Team Arena
305         if(this.notta)
306                 return true;
307
308         if(this.notsingle)
309                 if(maxclients == 1)
310                         return true;
311
312         if(this.notteam)
313                 if(teamplay)
314                         return true;
315
316         if(this.notfree)
317                 if(!teamplay)
318                         return true;
319
320         if(this.gametype)
321         {
322                 string gametypename;
323                 // From ioq3 g_spawn.c: static char *gametypeNames[] = {"ffa", "tournament", "single", "team", "ctf", "oneflag", "obelisk", "harvester"};
324                 gametypename = "ffa";
325                 if(teamplay)
326                         gametypename = "team";
327                 if(g_ctf)
328                         gametypename = "ctf";
329                 if(g_ctf && ctf_oneflag)
330                         gametypename = "oneflag";
331                 if(g_duel)
332                         gametypename = "tournament";
333                 if(maxclients == 1)
334                         gametypename = "single";
335                 // we do not have the other types (obelisk, harvester)
336                 if(strstrofs(this.gametype, gametypename, 0) < 0)
337                         return true;
338         }
339
340         return false;
341 }
342
343 int GetAmmoConsumptionQ3(string netname)
344 // Returns ammo consumed per shot by the primary/default fire mode
345 // Returns 0 if the netname has no ammo cvar
346 {
347         switch (netname)
348         {
349                 case "arc":        return autocvar_g_balance_arc_beam_ammo;
350                 case "devastator": return autocvar_g_balance_devastator_ammo;
351                 case "machinegun": return autocvar_g_balance_machinegun_sustained_ammo;
352                 case "minelayer":  return autocvar_g_balance_minelayer_ammo;
353                 case "seeker":     return autocvar_g_balance_seeker_tag_ammo;
354                 default:           return cvar(strcat("g_balance_", netname, "_primary_ammo"));
355         }
356 }
357