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