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