2 REGISTER_WEAPON(MINE_LAYER, w_minelayer, IT_ROCKETS, 9, WEP_FLAG_NORMAL | WEP_TYPE_SPLASH, BOT_PICKUP_RATING_HIGH, "minelayer", "minelayer", "Mine Layer");
5 .float minelayer_detonate;
8 void spawnfunc_weapon_minelayer (void)
10 weapon_defaultspawnfunc(WEP_MINE_LAYER);
13 void W_Mine_Unregister()
15 if(self.owner && self.owner.lastmine == self)
16 self.owner.lastmine = world;
19 void W_Mine_Explode ()
23 if(other.takedamage == DAMAGE_AIM)
24 if(other.classname == "player")
25 if(IsDifferentTeam(self.owner, other))
27 AnnounceTo(self.owner, "airshot");
29 self.event_damage = SUB_Null;
30 self.takedamage = DAMAGE_NO;
32 RadiusDamage (self, self.owner, cvar("g_balance_minelayer_damage"), cvar("g_balance_minelayer_edgedamage"), cvar("g_balance_minelayer_radius"), world, cvar("g_balance_minelayer_force"), self.projectiledeathtype, other);
34 if (self.owner.weapon == WEP_MINE_LAYER)
36 if(self.owner.ammo_rockets < cvar("g_balance_minelayer_ammo"))
38 self.owner.cnt = WEP_MINE_LAYER;
39 ATTACK_FINISHED(self.owner) = time;
40 self.owner.switchweapon = w_getbestweapon(self.owner);
46 void W_Mine_DoRemoteExplode ()
50 self.event_damage = SUB_Null;
51 self.takedamage = DAMAGE_NO;
53 RadiusDamage (self, self.owner, cvar("g_balance_minelayer_remote_damage"), cvar("g_balance_minelayer_remote_edgedamage"), cvar("g_balance_minelayer_remote_radius"), world, cvar("g_balance_minelayer_remote_force"), self.projectiledeathtype | HITTYPE_BOUNCE, world);
55 if (self.owner.weapon == WEP_MINE_LAYER)
57 if(self.owner.ammo_rockets < cvar("g_balance_minelayer_ammo"))
59 self.owner.cnt = WEP_MINE_LAYER;
60 ATTACK_FINISHED(self.owner) = time;
61 self.owner.switchweapon = w_getbestweapon(self.owner);
67 void W_Mine_RemoteExplode()
69 if(self.owner.deadflag == DEAD_NO)
70 if(self.owner.lastmine)
72 if((self.spawnshieldtime >= 0)
73 ? (time >= self.spawnshieldtime) // timer
74 : (vlen(NearestPointOnBox(self.owner, self.origin) - self.origin) > cvar("g_balance_minelayer_radius")) // safety device
77 W_Mine_DoRemoteExplode();
82 void W_Mine_Think (void)
84 self.nextthink = time;
88 self.projectiledeathtype |= HITTYPE_BOUNCE;
93 // detect players who are close the mine and explode if the player should detonate it
95 head = findradius(self.origin, cvar("g_balance_minelayer_detectionradius"));
99 if(head.classname == "player" && head.deadflag == DEAD_NO)
100 if(head != self.owner)
101 if(IsDifferentTeam(head, self.owner)) // don't detonate for team mates
107 if (self.owner.weapon == WEP_MINE_LAYER)
108 if (self.owner.deadflag == DEAD_NO)
109 if (self.minelayer_detonate)
110 W_Mine_RemoteExplode();
112 if(self.csqcprojectile_clientanimate == 0)
113 UpdateCSQCProjectile(self);
116 void W_Mine_Touch (void)
119 spamsound (self, CHAN_PROJECTILE, "weapons/mine_stick.wav", VOL_BASE, ATTN_NORM);
120 self.movetype = MOVETYPE_NONE; // lock the mine in place
121 // TODO: make sure this doesn't cause the mine to get stuck in the air if it falls over a moving entity
124 void W_Mine_Damage (entity inflictor, entity attacker, float damage, float deathtype, vector hitloc, vector force)
126 if (self.health <= 0)
128 self.health = self.health - damage;
129 self.angles = vectoangles(self.velocity);
130 if (self.health <= 0)
131 W_PrepareExplosionByDamage(attacker, W_Mine_Explode);
134 void W_Mine_Attack (void)
139 // scan how many mines we placed, and return if we reached our limit
140 if(cvar("g_balance_minelayer_limit"))
143 self.mine_number = 0;
144 for(mine = world; (mine = find(mine, classname, "mine")); ) if(mine.owner == self)
145 self.mine_number += 1;
147 if(self.mine_number >= cvar("g_balance_minelayer_limit"))
149 // the refire delay keeps this message from being spammed
150 sprint(self, strcat("You cannot place more than ^2", cvar_string("g_balance_minelayer_limit"), " ^7mines at a time\n") );
151 play2(self, "weapons/unavailable.wav");
156 if not(self.items & IT_UNLIMITED_WEAPON_AMMO)
157 self.ammo_rockets = self.ammo_rockets - cvar("g_balance_minelayer_ammo");
159 W_SetupShot_ProjectileSize (self, '-4 -4 -4', '4 4 4', FALSE, 5, "weapons/mine_fire.wav", cvar("g_balance_minelayer_damage"));
160 pointparticles(particleeffectnum("rocketlauncher_muzzleflash"), w_shotorg, w_shotdir * 1000, 1);
162 mine = WarpZone_RefSys_SpawnSameRefSys(self);
164 self.lastmine = mine;
165 if(cvar("g_balance_minelayer_detonatedelay") >= 0)
166 mine.spawnshieldtime = time + cvar("g_balance_minelayer_detonatedelay");
168 mine.spawnshieldtime = -1;
169 mine.classname = "mine";
170 mine.bot_dodge = TRUE;
171 mine.bot_dodgerating = cvar("g_balance_minelayer_damage") * 2; // * 2 because it can detonate inflight which makes it even more dangerous
173 mine.takedamage = DAMAGE_YES;
174 mine.damageforcescale = cvar("g_balance_minelayer_damageforcescale");
175 mine.health = cvar("g_balance_minelayer_health");
176 mine.event_damage = W_Mine_Damage;
178 mine.movetype = MOVETYPE_TOSS;
179 PROJECTILE_MAKETRIGGER(mine);
180 mine.projectiledeathtype = WEP_MINE_LAYER;
181 setsize (mine, '-4 -4 -4', '4 4 4'); // give it some size so it can be shot
183 setorigin (mine, w_shotorg - v_forward * 4); // move it back so it hits the wall at the right point
184 W_SetupProjectileVelocity(mine, cvar("g_balance_minelayer_speedstart"), 0);
185 mine.angles = vectoangles (mine.velocity);
187 mine.touch = W_Mine_Touch;
188 mine.think = W_Mine_Think;
189 mine.nextthink = time;
190 mine.cnt = time + cvar("g_balance_minelayer_lifetime");
191 mine.flags = FL_PROJECTILE;
193 CSQCProjectile(mine, FALSE, PROJECTILE_MINE, TRUE);
195 // muzzle flash for 1st person view
197 setmodel (flash, "models/flash.md3"); // precision set below
198 SUB_SetFade (flash, time, 0.1);
199 flash.effects = EF_ADDITIVE | EF_FULLBRIGHT | EF_LOWPRECISION;
200 W_AttachToShotorg(flash, '5 0 0');
205 void spawnfunc_weapon_minelayer (void); // defined in t_items.qc
207 float w_minelayer(float req)
213 // aim and decide to fire if appropriate
214 self.BUTTON_ATCK = bot_aim(cvar("g_balance_minelayer_speed"), 0, cvar("g_balance_minelayer_lifetime"), FALSE);
215 if(skill >= 2) // skill 0 and 1 bots won't detonate mines!
217 // decide whether to detonate mines
218 local entity mine, targetlist, targ;
219 local float edgedamage, coredamage, edgeradius, recipricoledgeradius, d;
220 local float selfdamage, teamdamage, enemydamage;
221 edgedamage = cvar("g_balance_minelayer_edgedamage");
222 coredamage = cvar("g_balance_minelayer_damage");
223 edgeradius = cvar("g_balance_minelayer_radius");
224 recipricoledgeradius = 1 / edgeradius;
228 targetlist = findchainfloat(bot_attack, TRUE);
229 mine = find(world, classname, "mine");
232 if (mine.owner != self)
234 mine = find(mine, classname, "mine");
240 d = vlen(targ.origin + (targ.mins + targ.maxs) * 0.5 - mine.origin);
241 d = bound(0, edgedamage + (coredamage - edgedamage) * sqrt(1 - d * recipricoledgeradius), 10000);
242 // count potential damage according to type of target
244 selfdamage = selfdamage + d;
245 else if (targ.team == self.team && teams_matter)
246 teamdamage = teamdamage + d;
247 else if (bot_shouldattack(targ))
248 enemydamage = enemydamage + d;
251 mine = find(mine, classname, "mine");
253 local float desirabledamage;
254 desirabledamage = enemydamage;
255 if (teamplay != 1 && time > self.invincible_finished && time > self.spawnshieldtime)
256 desirabledamage = desirabledamage - selfdamage * cvar("g_balance_selfdamagepercent");
257 if (self.team && teamplay != 1)
258 desirabledamage = desirabledamage - teamdamage;
260 mine = find(world, classname, "mine");
263 if (mine.owner != self)
265 mine = find(mine, classname, "mine");
268 makevectors(mine.v_angle);
270 if (skill > 9) // normal players only do this for the target they are tracking
276 (v_forward * normalize(mine.origin - targ.origin)< 0.1)
277 && desirabledamage > 0.1*coredamage
278 )self.BUTTON_ATCK2 = TRUE;
282 local float distance; distance= bound(300,vlen(self.origin-self.enemy.origin),30000);
283 //As the distance gets larger, a correct detonation gets near imposible
284 //Bots are assumed to use the mine spawnfunc_light to see if the mine gets near a player
285 if(v_forward * normalize(mine.origin - self.enemy.origin)< 0.1)
286 if(self.enemy.classname == "player")
287 if(desirabledamage >= 0.1*coredamage)
288 if(random()/distance*300 > frametime*bound(0,(10-skill)*0.2,1))
289 self.BUTTON_ATCK2 = TRUE;
290 // dprint(ftos(random()/distance*300),">");dprint(ftos(frametime*bound(0,(10-skill)*0.2,1)),"\n");
293 mine = find(mine, classname, "mine");
295 // if we would be doing at X percent of the core damage, detonate it
296 // but don't fire a new shot at the same time!
297 if (desirabledamage >= 0.75 * coredamage) //this should do group damage in rare fortunate events
298 self.BUTTON_ATCK2 = TRUE;
299 if ((skill > 6.5) && (selfdamage > self.health))
300 self.BUTTON_ATCK2 = FALSE;
301 //if(self.BUTTON_ATCK2 == TRUE)
302 // dprint(ftos(desirabledamage),"\n");
303 if (self.BUTTON_ATCK2 == TRUE) self.BUTTON_ATCK = FALSE;
306 else if (req == WR_THINK)
308 if (self.BUTTON_ATCK)
310 if(weapon_prepareattack(0, cvar("g_balance_minelayer_refire")))
313 weapon_thinkf(WFRAME_FIRE1, cvar("g_balance_minelayer_animtime"), w_ready);
317 if (self.BUTTON_ATCK2)
320 for(mine = world; (mine = find(mine, classname, "mine")); ) if(mine.owner == self)
322 if(!mine.minelayer_detonate)
324 mine.minelayer_detonate = TRUE;
329 sound (self, CHAN_WEAPON2, "weapons/mine_det.wav", VOL_BASE, ATTN_NORM);
332 else if (req == WR_PRECACHE)
334 precache_model ("models/flash.md3");
335 precache_model ("models/weapons/g_minelayer.md3");
336 precache_model ("models/weapons/v_minelayer.md3");
337 precache_model ("models/weapons/h_minelayer.iqm");
338 precache_sound ("weapons/mine_det.wav");
339 precache_sound ("weapons/mine_fire.wav");
340 precache_sound ("weapons/mine_stick.wav");
342 else if (req == WR_SETUP)
344 weapon_setup(WEP_MINE_LAYER);
346 else if (req == WR_CHECKAMMO1)
348 // don't switch while placing a mine
349 if ((ATTACK_FINISHED(self) <= time || self.weapon != WEP_MINE_LAYER)
350 && self.ammo_rockets < cvar("g_balance_minelayer_ammo"))
353 else if (req == WR_CHECKAMMO2)
359 float w_minelayer(float req)
361 if(req == WR_IMPACTEFFECT)
364 org2 = w_org + w_backoff * 12;
365 pointparticles(particleeffectnum("rocket_explode"), org2, '0 0 0', 1);
367 sound(self, CHAN_PROJECTILE, "weapons/mine_exp.wav", VOL_BASE, ATTN_NORM);
369 else if(req == WR_PRECACHE)
371 precache_sound("weapons/mine_exp.wav");
373 else if (req == WR_SUICIDEMESSAGE)
374 w_deathtypestring = "%s exploded";
375 else if (req == WR_KILLMESSAGE)
377 if(w_deathtype & HITTYPE_BOUNCE) // (remote detonation)
378 w_deathtypestring = "%s got too close to %s's mine";
379 else if(w_deathtype & HITTYPE_SPLASH)
380 w_deathtypestring = "%s almost dodged %s's mine";
382 w_deathtypestring = "%s stepped on %s's mine";