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