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