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