]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/server/compat/quake3.qc
Improve target_init support.
[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 <common/weapons/_all.qh>
7
8 spawnfunc(target_items);
9
10 //***********************
11 //QUAKE 3 ENTITIES - So people can play quake3 maps with the xonotic weapons
12 //***********************
13
14 // NOTE: for best experience, you need to swap MGs with SGs in the map or it won't have a MG
15
16 // SG -> SG
17 SPAWNFUNC_ITEM(ammo_shells, ITEM_Shells)
18
19 // MG -> MG
20 SPAWNFUNC_ITEM(ammo_bullets, ITEM_Bullets)
21
22 // GL -> Mortar
23 SPAWNFUNC_ITEM(ammo_grenades, ITEM_Rockets)
24
25 // Mines -> Rockets
26 SPAWNFUNC_WEAPON(weapon_prox_launcher, WEP_MINE_LAYER)
27 SPAWNFUNC_ITEM(ammo_mines, ITEM_Rockets)
28
29 // LG -> Lightning
30 SPAWNFUNC_WEAPON(weapon_lightning, WEP_ELECTRO)
31 SPAWNFUNC_ITEM(ammo_lightning, ITEM_Cells)
32
33 // Plasma -> Hagar
34 SPAWNFUNC_WEAPON(weapon_plasmagun, WEP_HAGAR)
35 SPAWNFUNC_ITEM(ammo_cells, ITEM_Rockets)
36
37 // Rail -> Vortex
38 SPAWNFUNC_WEAPON(weapon_railgun, WEP_VORTEX)
39 SPAWNFUNC_ITEM(ammo_slugs, ITEM_Cells)
40
41 // BFG -> Crylink
42 SPAWNFUNC_WEAPON(weapon_bfg, WEP_CRYLINK)
43 SPAWNFUNC_ITEM(ammo_bfg, ITEM_Cells)
44
45 // grappling hook -> hook
46 SPAWNFUNC_WEAPON(weapon_grapplinghook, WEP_HOOK)
47
48 // RL -> RL
49 SPAWNFUNC_ITEM(ammo_rockets, ITEM_Rockets)
50
51 // Armor
52 SPAWNFUNC_ITEM(item_armor_body, ITEM_ArmorMega)
53 SPAWNFUNC_ITEM(item_armor_combat, ITEM_ArmorBig)
54 SPAWNFUNC_ITEM(item_armor_shard, ITEM_ArmorSmall)
55 SPAWNFUNC_ITEM(item_enviro, ITEM_Shield)
56
57 // medkit -> armor (we have no holdables)
58 SPAWNFUNC_ITEM(holdable_medkit, ITEM_ArmorMega)
59
60 // doubler -> strength
61 SPAWNFUNC_ITEM(item_doubler, ITEM_Strength)
62
63 .float wait;
64 .float delay;
65
66 // weapon remove ent from df
67 void target_init_verify(entity this)
68 {
69         entity trigger, targ;
70         for(trigger = NULL; (trigger = find(trigger, classname, "trigger_multiple")); )
71                 for(targ = NULL; (targ = find(targ, targetname, trigger.target)); )
72                         if (targ.classname == "target_init" || targ.classname == "target_give" || targ.classname == "target_items")
73                         {
74                                 trigger.wait = 0;
75                                 trigger.delay = 0;
76                                 targ.wait = 0;
77                                 targ.delay = 0;
78
79                                 //setsize(targ, trigger.mins, trigger.maxs);
80                                 //setorigin(targ, trigger.origin);
81                                 //remove(trigger);
82                         }
83 }
84
85 void target_init_use(entity this, entity actor, entity trigger)
86 {
87         if (!(this.spawnflags & 1))
88         {
89                 SetResourceAmount(actor, RESOURCE_ARMOR, start_armorvalue);
90                 actor.pauserotarmor_finished = time + autocvar_g_balance_pause_armor_rot;
91         }
92
93         if (!(this.spawnflags & 2))
94         {
95                 SetResourceAmount(actor, RESOURCE_HEALTH, start_health);
96                 actor.pauserothealth_finished = time + autocvar_g_balance_pause_health_rot;
97                 actor.pauseregen_finished = time + autocvar_g_balance_pause_health_regen;
98         }
99
100         if (!(this.spawnflags & 4))
101         {
102                 SetResourceAmount(actor, RESOURCE_SHELLS, start_ammo_shells);
103                 SetResourceAmount(actor, RESOURCE_BULLETS, start_ammo_nails);
104                 SetResourceAmount(actor, RESOURCE_ROCKETS, start_ammo_rockets);
105                 SetResourceAmount(actor, RESOURCE_CELLS, start_ammo_cells);
106                 SetResourceAmount(actor, RESOURCE_PLASMA, start_ammo_plasma);
107                 SetResourceAmount(actor, RESOURCE_FUEL, start_ammo_fuel);
108
109                 actor.weapons = start_weapons;
110                 if (this.spawnflags & 32)
111                 {
112                         // TODO
113                 }
114         }
115
116         if (!(this.spawnflags & 8))
117         {
118                 actor.strength_finished = 0;
119                 actor.invincible_finished = 0;
120                 actor.buffs = 0;
121         }
122
123         if (!(this.spawnflags & 16))
124         {
125                 // We don't have holdables.
126         }
127
128         SUB_UseTargets(this, actor, trigger);
129 }
130
131 spawnfunc(target_init)
132 {
133         this.use = target_init_use;
134         InitializeEntity(this, target_init_verify, INITPRIO_FINDTARGET);
135 }
136
137 // weapon give ent from defrag
138 void target_give_init(entity this)
139 {
140         IL_EACH(g_items, it.targetname == this.target,
141         {
142                 if (it.classname == "weapon_devastator") {
143                         this.ammo_rockets += it.count * WEP_CVAR(devastator, ammo);
144                         this.netname = cons(this.netname, "devastator");
145                 }
146                 else if (it.classname == "weapon_vortex") {
147                         this.ammo_cells += it.count * WEP_CVAR_PRI(vortex, ammo); // WEAPONTODO
148                         this.netname = cons(this.netname, "vortex");
149                 }
150                 else if (it.classname == "weapon_electro") {
151                         this.ammo_cells += it.count * WEP_CVAR_PRI(electro, ammo); // WEAPONTODO
152                         this.netname = cons(this.netname, "electro");
153                 }
154                 else if (it.classname == "weapon_hagar") {
155                         this.ammo_rockets += it.count * WEP_CVAR_PRI(hagar, ammo); // WEAPONTODO
156                         this.netname = cons(this.netname, "hagar");
157                 }
158                 else if (it.classname == "weapon_crylink") {
159                         this.ammo_cells += it.count * WEP_CVAR_PRI(crylink, ammo);
160                         this.netname = cons(this.netname, "crylink");
161                 }
162                 else if (it.classname == "weapon_mortar") {
163                         this.ammo_rockets += it.count * WEP_CVAR_PRI(mortar, ammo); // WEAPONTODO
164                         this.netname = cons(this.netname, "mortar");
165                 }
166                 else if (it.classname == "item_armor_mega")
167                         this.armorvalue = 100;
168                 else if (it.classname == "item_health_mega")
169                         this.health = 200;
170                 //remove(it); // removing ents in init functions causes havoc, workaround:
171         setthink(it, SUB_Remove);
172         it.nextthink = time;
173         });
174         this.spawnflags = 2;
175         this.spawnfunc_checked = true;
176         spawnfunc_target_items(this);
177         InitializeEntity(this, target_init_verify, INITPRIO_FINDTARGET);
178 }
179
180 spawnfunc(target_give)
181 {
182         InitializeEntity(this, target_give_init, INITPRIO_FINDTARGET);
183 }
184
185 //spawnfunc(item_flight)       /* handled by buffs mutator */
186 //spawnfunc(item_haste)        /* handled by buffs mutator */
187 //spawnfunc(item_health)       /* handled in t_quake.qc */
188 //spawnfunc(item_health_large) /* handled in t_items.qc */
189 //spawnfunc(item_health_small) /* handled in t_items.qc */
190 //spawnfunc(item_health_mega)  /* handled in t_items.qc */
191 //spawnfunc(item_invis)        /* handled by buffs mutator */
192 //spawnfunc(item_regen)        /* handled by buffs mutator */
193
194 // CTF spawnfuncs handled in mutators/gamemode_ctf.qc now
195
196 .float notteam;
197 .float notsingle;
198 .float notfree;
199 .float notq3a;
200 .float notta;
201 .string gametype;
202 bool DoesQ3ARemoveThisEntity(entity this)
203 {
204         // Q3 style filters (DO NOT USE, THIS IS COMPAT ONLY)
205
206         if(this.notq3a)
207                 if(!teamplay || g_tdm || g_ctf)
208                         return true;
209
210         if(this.notta)
211                 if (!(!teamplay || g_tdm || g_ctf))
212                         return true;
213
214         if(this.notsingle)
215                 if(maxclients == 1)
216                         return true;
217
218         if(this.notteam)
219                 if(teamplay)
220                         return true;
221
222         if(this.notfree)
223                 if(!teamplay)
224                         return true;
225
226         if(this.gametype)
227         {
228                 string gametypename;
229                 // static char *gametypeNames[] = {"ffa", "tournament", "single", "team", "ctf", "oneflag", "obelisk", "harvester", "teamtournament"}
230                 gametypename = "ffa";
231                 if(teamplay)
232                         gametypename = "team";
233                 if(g_ctf)
234                         gametypename = "ctf";
235                 if(maxclients == 1)
236                         gametypename = "single";
237                 // we do not have the other types (oneflag, obelisk, harvester, teamtournament)
238                 if(strstrofs(this.gametype, gametypename, 0) < 0)
239                         return true;
240         }
241
242         return false;
243 }