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