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