Merge branch 'master' into Mario/strength_stat_field
[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                 SetResource(actor, RES_SHELLS, start_ammo_shells);
104                 SetResource(actor, RES_BULLETS, start_ammo_nails);
105                 SetResource(actor, RES_ROCKETS, start_ammo_rockets);
106                 SetResource(actor, RES_CELLS, start_ammo_cells);
107                 SetResource(actor, RES_PLASMA, start_ammo_plasma);
108                 SetResource(actor, RES_FUEL, start_ammo_fuel);
109
110                 STAT(WEAPONS, actor) = start_weapons;
111                 if (this.spawnflags & 32)
112                 {
113                         // TODO
114                 }
115         }
116
117         if (!(this.spawnflags & 8))
118         {
119                 STAT(STRENGTH_FINISHED, actor) = 0;
120                 actor.invincible_finished = 0;
121                 if(STAT(BUFFS, actor)) // TODO: make a dropbuffs function to handle this
122                 {
123                         int buffid = buff_FirstFromFlags(STAT(BUFFS, actor)).m_id;
124                         Send_Notification(NOTIF_ONE, actor, MSG_MULTI, ITEM_BUFF_DROP, buffid);
125                         sound(actor, CH_TRIGGER, SND_BUFF_LOST, VOL_BASE, ATTN_NORM);
126                         if(!IS_INDEPENDENT_PLAYER(actor))
127                                 Send_Notification(NOTIF_ALL_EXCEPT, actor, MSG_INFO, INFO_ITEM_BUFF_LOST, actor.netname, buffid);
128                         STAT(BUFFS, actor) = 0;
129                         STAT(BUFF_TIME, actor) = 0;
130                 }
131         }
132
133         if (!(this.spawnflags & 16))
134         {
135                 // We don't have holdables.
136         }
137
138         SUB_UseTargets(this, actor, trigger);
139 }
140
141 spawnfunc(target_init)
142 {
143         this.use = target_init_use;
144         InitializeEntity(this, target_init_verify, INITPRIO_FINDTARGET);
145 }
146
147 // weapon give ent from defrag
148 void target_give_init(entity this)
149 {
150         IL_EACH(g_items, it.targetname == this.target,
151         {
152                 if (it.classname == "weapon_devastator") {
153                         SetResourceExplicit(this, RES_ROCKETS, GetResource(this, RES_ROCKETS) + it.count * WEP_CVAR_PRI(devastator, ammo)); // WEAPONTODO
154                         this.netname = cons(this.netname, "devastator");
155                 }
156                 else if (it.classname == "weapon_vortex") {
157                         SetResourceExplicit(this, RES_CELLS, GetResource(this, RES_CELLS) + it.count * WEP_CVAR_PRI(vortex, ammo)); // WEAPONTODO
158                         this.netname = cons(this.netname, "vortex");
159                 }
160                 else if (it.classname == "weapon_electro") {
161                         SetResourceExplicit(this, RES_CELLS, GetResource(this, RES_CELLS) + it.count * WEP_CVAR_PRI(electro, ammo)); // WEAPONTODO
162                         this.netname = cons(this.netname, "electro");
163                 }
164                 else if (it.classname == "weapon_hagar") {
165                         SetResourceExplicit(this, RES_ROCKETS, GetResource(this, RES_ROCKETS) + it.count * WEP_CVAR_PRI(hagar, ammo)); // WEAPONTODO
166                         this.netname = cons(this.netname, "hagar");
167                 }
168                 else if (it.classname == "weapon_crylink") {
169                         SetResourceExplicit(this, RES_CELLS, GetResource(this, RES_CELLS) + it.count * WEP_CVAR_PRI(crylink, ammo)); // WEAPONTODO
170                         this.netname = cons(this.netname, "crylink");
171                 }
172                 else if (it.classname == "weapon_mortar") {
173                         SetResourceExplicit(this, RES_ROCKETS, GetResource(this, RES_ROCKETS) + it.count * WEP_CVAR_PRI(mortar, ammo)); // WEAPONTODO
174                         this.netname = cons(this.netname, "mortar");
175                 }
176                 else if (it.classname == "item_armor_mega")
177                         SetResourceExplicit(this, RES_ARMOR, 100);
178                 else if (it.classname == "item_health_mega")
179                         SetResourceExplicit(this, RES_HEALTH, 200);
180                 else if (it.classname == "item_buff") {
181                         entity buff = buff_FirstFromFlags(STAT(BUFFS, it));
182                         this.netname = cons(this.netname, buff.netname);
183                         STAT(BUFF_TIME, this) = it.count;
184                 }
185
186                 //remove(it); // removing ents in init functions causes havoc, workaround:
187         setthink(it, SUB_Remove);
188         it.nextthink = time;
189         });
190         this.spawnflags = 2;
191         this.spawnfunc_checked = true;
192         spawnfunc_target_items(this);
193         InitializeEntity(this, target_init_verify, INITPRIO_FINDTARGET);
194 }
195
196 spawnfunc(target_give)
197 {
198         InitializeEntity(this, target_give_init, INITPRIO_FINDTARGET);
199 }
200
201 void score_use(entity this, entity actor, entity trigger)
202 {
203         if(!IS_PLAYER(actor))
204                 return;
205         actor.fragsfilter_cnt += this.count;
206 }
207 spawnfunc(target_score)
208 {
209         if(!g_cts) { delete(this); return; }
210
211         if(!this.count)
212                 this.count = 1;
213         this.use = score_use;
214 }
215
216 void fragsfilter_use(entity this, entity actor, entity trigger)
217 {
218         if(!IS_PLAYER(actor))
219                 return;
220         if(actor.fragsfilter_cnt >= this.frags)
221                 SUB_UseTargets(this, actor, trigger);
222 }
223 spawnfunc(target_fragsFilter)
224 {
225         if(!g_cts) { delete(this); return; }
226
227         if(!this.frags)
228                 this.frags = 1;
229         this.use = fragsfilter_use;
230 }
231
232 //spawnfunc(item_flight)       /* handled by buffs mutator */
233 //spawnfunc(item_doubler)        /* handled by buffs mutator */
234 //spawnfunc(item_haste)        /* handled by buffs mutator */
235 //spawnfunc(item_health)       /* handled in t_quake.qc */
236 //spawnfunc(item_health_large) /* handled in t_items.qc */
237 //spawnfunc(item_health_small) /* handled in t_items.qc */
238 //spawnfunc(item_health_mega)  /* handled in t_items.qc */
239 //spawnfunc(item_invis)        /* handled by buffs mutator */
240 //spawnfunc(item_regen)        /* handled by buffs mutator */
241
242 // CTF spawnfuncs handled in mutators/gamemode_ctf.qc now
243
244 .float notteam;
245 .float notsingle;
246 .float notfree;
247 .float notq3a;
248 .float notta;
249 .string gametype;
250 bool DoesQ3ARemoveThisEntity(entity this)
251 {
252         // Q3 style filters (DO NOT USE, THIS IS COMPAT ONLY)
253
254         if(this.notq3a)
255                 if(!teamplay || g_tdm || g_ctf)
256                         return true;
257
258         if(this.notta)
259                 if (!(!teamplay || g_tdm || g_ctf))
260                         return true;
261
262         if(this.notsingle)
263                 if(maxclients == 1)
264                         return true;
265
266         if(this.notteam)
267                 if(teamplay)
268                         return true;
269
270         if(this.notfree)
271                 if(!teamplay)
272                         return true;
273
274         if(this.gametype)
275         {
276                 string gametypename;
277                 // static char *gametypeNames[] = {"ffa", "tournament", "single", "team", "ctf", "oneflag", "obelisk", "harvester", "teamtournament"}
278                 gametypename = "ffa";
279                 if(teamplay)
280                         gametypename = "team";
281                 if(g_ctf)
282                         gametypename = "ctf";
283                 if(g_duel)
284                         gametypename = "tournament";
285                 if(maxclients == 1)
286                         gametypename = "single";
287                 // we do not have the other types (oneflag, obelisk, harvester, teamtournament)
288                 if(strstrofs(this.gametype, gametypename, 0) < 0)
289                         return true;
290         }
291
292         return false;
293 }