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