]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/server/compat/quake3.qc
Spawn HLAC and cell ammo in place of Q3TA chaingun and ammo_belt
[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 // Q3TA chaingun -> HLAC
34 SPAWNFUNC_WEAPON(weapon_chaingun, WEP_HLAC)
35 SPAWNFUNC_ITEM(ammo_belt, ITEM_Cells)
36
37 // Q3TA nails -> cells
38 SPAWNFUNC_ITEM(ammo_nails, ITEM_Cells)
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                 STAT(STRENGTH_FINISHED, actor) = 0;
137                 STAT(INVINCIBLE_FINISHED, actor) = 0;
138                 if(STAT(BUFFS, actor)) // TODO: make a dropbuffs function to handle this
139                 {
140                         int buffid = buff_FirstFromFlags(STAT(BUFFS, actor)).m_id;
141                         Send_Notification(NOTIF_ONE, actor, MSG_MULTI, ITEM_BUFF_DROP, buffid);
142                         sound(actor, CH_TRIGGER, SND_BUFF_LOST, VOL_BASE, ATTN_NORM);
143                         if(!IS_INDEPENDENT_PLAYER(actor))
144                                 Send_Notification(NOTIF_ALL_EXCEPT, actor, MSG_INFO, INFO_ITEM_BUFF_LOST, actor.netname, buffid);
145                         STAT(BUFFS, actor) = 0;
146                         STAT(BUFF_TIME, actor) = 0;
147                 }
148         }
149
150         if (!(this.spawnflags & 16))
151         {
152                 // We don't have holdables.
153         }
154
155         SUB_UseTargets(this, actor, trigger);
156 }
157
158 spawnfunc(target_init)
159 {
160         this.use = target_init_use;
161         InitializeEntity(this, target_init_verify, INITPRIO_FINDTARGET);
162 }
163
164 // weapon give ent from defrag
165 void target_give_init(entity this)
166 {
167         IL_EACH(g_items, it.targetname == this.target,
168         {
169                 if (it.classname == "weapon_devastator") {
170                         SetResourceExplicit(this, RES_ROCKETS, GetResource(this, RES_ROCKETS) + it.count * WEP_CVAR_PRI(devastator, ammo)); // WEAPONTODO
171                         this.netname = cons(this.netname, "devastator");
172                 }
173                 else if (it.classname == "weapon_vortex") {
174                         SetResourceExplicit(this, RES_CELLS, GetResource(this, RES_CELLS) + it.count * WEP_CVAR_PRI(vortex, ammo)); // WEAPONTODO
175                         this.netname = cons(this.netname, "vortex");
176                 }
177                 else if (it.classname == "weapon_electro") {
178                         SetResourceExplicit(this, RES_CELLS, GetResource(this, RES_CELLS) + it.count * WEP_CVAR_PRI(electro, ammo)); // WEAPONTODO
179                         this.netname = cons(this.netname, "electro");
180                 }
181                 else if (it.classname == "weapon_hagar") {
182                         SetResourceExplicit(this, RES_ROCKETS, GetResource(this, RES_ROCKETS) + it.count * WEP_CVAR_PRI(hagar, ammo)); // WEAPONTODO
183                         this.netname = cons(this.netname, "hagar");
184                 }
185                 else if (it.classname == "weapon_crylink") {
186                         SetResourceExplicit(this, RES_CELLS, GetResource(this, RES_CELLS) + it.count * WEP_CVAR_PRI(crylink, ammo)); // WEAPONTODO
187                         this.netname = cons(this.netname, "crylink");
188                 }
189                 else if (it.classname == "weapon_mortar") {
190                         SetResourceExplicit(this, RES_ROCKETS, GetResource(this, RES_ROCKETS) + it.count * WEP_CVAR_PRI(mortar, ammo)); // WEAPONTODO
191                         this.netname = cons(this.netname, "mortar");
192                 }
193                 else if (it.classname == "weapon_shotgun") {
194                         SetResourceExplicit(this, RES_SHELLS, GetResource(this, RES_SHELLS) + it.count * WEP_CVAR_PRI(shotgun, ammo)); // WEAPONTODO
195                         this.netname = cons(this.netname, "shotgun");
196                 }
197                 else if (it.classname == "item_armor_mega")
198                         SetResourceExplicit(this, RES_ARMOR, 100);
199                 else if (it.classname == "item_health_mega")
200                         SetResourceExplicit(this, RES_HEALTH, 200);
201                 else if (it.classname == "item_buff") {
202                         entity buff = buff_FirstFromFlags(STAT(BUFFS, it));
203                         this.netname = cons(this.netname, buff.netname);
204                         STAT(BUFF_TIME, this) = it.count;
205                 }
206
207                 //remove(it); // removing ents in init functions causes havoc, workaround:
208         setthink(it, SUB_Remove);
209         it.nextthink = time;
210         });
211         this.spawnflags = 2;
212         this.spawnfunc_checked = true;
213         spawnfunc_target_items(this);
214         InitializeEntity(this, target_init_verify, INITPRIO_FINDTARGET);
215 }
216
217 spawnfunc(target_give)
218 {
219         InitializeEntity(this, target_give_init, INITPRIO_FINDTARGET);
220 }
221
222 void score_use(entity this, entity actor, entity trigger)
223 {
224         if(!IS_PLAYER(actor))
225                 return;
226         actor.fragsfilter_cnt += this.count;
227 }
228 spawnfunc(target_score)
229 {
230         if(!g_cts) { delete(this); return; }
231
232         if(!this.count)
233                 this.count = 1;
234         this.use = score_use;
235 }
236
237 void fragsfilter_use(entity this, entity actor, entity trigger)
238 {
239         if(!IS_PLAYER(actor))
240                 return;
241         if(actor.fragsfilter_cnt >= this.frags)
242                 SUB_UseTargets(this, actor, trigger);
243 }
244 spawnfunc(target_fragsFilter)
245 {
246         if(!g_cts) { delete(this); return; }
247
248         if(!this.frags)
249                 this.frags = 1;
250         this.use = fragsfilter_use;
251 }
252
253 //spawnfunc(item_flight)       /* handled by buffs mutator */
254 //spawnfunc(item_doubler)        /* handled by buffs mutator */
255 //spawnfunc(item_haste)        /* handled by buffs mutator */
256 //spawnfunc(item_health)       /* handled in t_quake.qc */
257 //spawnfunc(item_health_large) /* handled in t_items.qc */
258 //spawnfunc(item_health_small) /* handled in t_items.qc */
259 //spawnfunc(item_health_mega)  /* handled in t_items.qc */
260 //spawnfunc(item_invis)        /* handled by buffs mutator */
261 //spawnfunc(item_regen)        /* handled by buffs mutator */
262
263 // CTF spawnfuncs handled in mutators/gamemode_ctf.qc now
264
265 .bool notteam;
266 .bool notsingle;
267 .bool notfree;
268 .bool notta;
269 .bool notvq3;
270 .bool notcpm;
271 .string gametype;
272 bool DoesQ3ARemoveThisEntity(entity this)
273 {
274         // Q3 style filters (DO NOT USE, THIS IS COMPAT ONLY)
275
276         // DeFRaG mappers use "notcpm" or "notvq3" to disable an entity in CPM or VQ3 physics
277         // Xonotic is usually played with a CPM-based physics so we default to CPM mode
278         if(cvar_string("g_mod_physics") == "Q3") {
279                 if(this.notvq3) return true;
280         }
281         else if(this.notcpm) return true;
282
283         // Q3 mappers use "notq3a" or "notta" to disable an entity in Q3A or Q3TA
284         // Xonotic has ~equivalent features to Team Arena
285         if(this.notta)
286                 return true;
287
288         if(this.notsingle)
289                 if(maxclients == 1)
290                         return true;
291
292         if(this.notteam)
293                 if(teamplay)
294                         return true;
295
296         if(this.notfree)
297                 if(!teamplay)
298                         return true;
299
300         if(this.gametype)
301         {
302                 string gametypename;
303                 // static char *gametypeNames[] = {"ffa", "tournament", "single", "team", "ctf", "oneflag", "obelisk", "harvester", "teamtournament"}
304                 gametypename = "ffa";
305                 if(teamplay)
306                         gametypename = "team";
307                 if(g_ctf)
308                         gametypename = "ctf";
309                 if(g_duel)
310                         gametypename = "tournament";
311                 if(maxclients == 1)
312                         gametypename = "single";
313                 // we do not have the other types (oneflag, obelisk, harvester, teamtournament)
314                 if(strstrofs(this.gametype, gametypename, 0) < 0)
315                         return true;
316         }
317
318         return false;
319 }