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