2 REGISTER_WEAPON(MINE_LAYER, w_minelayer, IT_ROCKETS, 4, WEP_FLAG_RELOADABLE | WEP_TYPE_SPLASH, BOT_PICKUP_RATING_HIGH, "minelayer", "minelayer", _("Mine Layer"))
5 void W_Mine_Think (void);
6 .float minelayer_detonate, mine_explodeanyway;
9 void spawnfunc_weapon_minelayer (void)
11 weapon_defaultspawnfunc(WEP_MINE_LAYER);
14 void W_Mine_Stick (entity to)
16 spamsound (self, CH_SHOTS, "weapons/mine_stick.wav", VOL_BASE, ATTN_NORM);
18 // in order for mines to face properly when sticking to the ground, they must be a server side entity rather than a csqc projectile
22 newmine.classname = self.classname;
24 newmine.bot_dodge = self.bot_dodge;
25 newmine.bot_dodgerating = self.bot_dodgerating;
27 newmine.owner = self.owner;
28 newmine.realowner = self.realowner;
29 setsize(newmine, '-4 -4 -4', '4 4 4');
30 setorigin(newmine, self.origin);
31 setmodel(newmine, "models/mine.md3");
32 newmine.angles = vectoangles(-trace_plane_normal); // face against the surface
34 newmine.oldvelocity = self.velocity;
36 newmine.takedamage = self.takedamage;
37 newmine.damageforcescale = self.damageforcescale;
38 newmine.health = self.health;
39 newmine.event_damage = self.event_damage;
40 newmine.spawnshieldtime = self.spawnshieldtime;
41 newmine.damagedbycontents = TRUE;
43 newmine.movetype = MOVETYPE_NONE; // lock the mine in place
44 newmine.projectiledeathtype = self.projectiledeathtype;
46 newmine.mine_time = self.mine_time;
48 newmine.touch = SUB_Null;
49 newmine.think = W_Mine_Think;
50 newmine.nextthink = time;
51 newmine.cnt = self.cnt;
52 newmine.flags = self.flags;
58 SetMovetypeFollow(self, to);
61 void W_Mine_Explode ()
63 if(other.takedamage == DAMAGE_AIM)
64 if(other.classname == "player")
65 if(IsDifferentTeam(self.realowner, other))
66 if(other.deadflag == DEAD_NO)
68 AnnounceTo(self.realowner, "airshot");
70 self.event_damage = SUB_Null;
71 self.takedamage = DAMAGE_NO;
73 RadiusDamage (self, self.realowner, autocvar_g_balance_minelayer_damage, autocvar_g_balance_minelayer_edgedamage, autocvar_g_balance_minelayer_radius, world, autocvar_g_balance_minelayer_force, self.projectiledeathtype, other);
75 if (self.realowner.weapon == WEP_MINE_LAYER)
79 self = self.realowner;
80 if (!weapon_action(WEP_MINE_LAYER, WR_CHECKAMMO1))
82 self.cnt = WEP_MINE_LAYER;
83 ATTACK_FINISHED(self) = time;
84 self.switchweapon = w_getbestweapon(self);
88 self.realowner.minelayer_mines -= 1;
92 void W_Mine_DoRemoteExplode ()
94 self.event_damage = SUB_Null;
95 self.takedamage = DAMAGE_NO;
97 if(self.movetype == MOVETYPE_NONE || self.movetype == MOVETYPE_FOLLOW)
98 self.velocity = self.oldvelocity;
100 RadiusDamage (self, self.realowner, autocvar_g_balance_minelayer_remote_damage, autocvar_g_balance_minelayer_remote_edgedamage, autocvar_g_balance_minelayer_remote_radius, world, autocvar_g_balance_minelayer_remote_force, self.projectiledeathtype | HITTYPE_BOUNCE, world);
102 if (self.realowner.weapon == WEP_MINE_LAYER)
106 self = self.realowner;
107 if (!weapon_action(WEP_MINE_LAYER, WR_CHECKAMMO1))
109 self.cnt = WEP_MINE_LAYER;
110 ATTACK_FINISHED(self) = time;
111 self.switchweapon = w_getbestweapon(self);
115 self.realowner.minelayer_mines -= 1;
119 void W_Mine_RemoteExplode ()
121 if(self.realowner.deadflag == DEAD_NO)
122 if((self.spawnshieldtime >= 0)
123 ? (time >= self.spawnshieldtime) // timer
124 : (vlen(NearestPointOnBox(self.realowner, self.origin) - self.origin) > autocvar_g_balance_minelayer_remote_radius) // safety device
127 W_Mine_DoRemoteExplode();
131 void W_Mine_ProximityExplode ()
133 // make sure no friend is in the mine's radius. If there is any, explosion is delayed until he's at a safe distance
134 if(autocvar_g_balance_minelayer_protection && self.mine_explodeanyway == 0)
137 head = findradius(self.origin, autocvar_g_balance_minelayer_radius);
140 if(head == self.realowner || !IsDifferentTeam(head, self.realowner))
150 float W_Mine_Count(entity e)
154 for(mine = world; (mine = find(mine, classname, "mine")); ) if(mine.realowner == e)
160 void W_Mine_Think (void)
164 self.nextthink = time;
166 if(self.movetype == MOVETYPE_FOLLOW)
168 if(LostMovetypeFollow(self))
170 UnsetMovetypeFollow(self);
171 self.movetype = MOVETYPE_NONE;
175 // our lifetime has expired, it's time to die - mine_time just allows us to play a sound for this
176 // TODO: replace this mine_trigger.wav sound with a real countdown
177 if ((time > self.cnt) && (!self.mine_time))
179 if(autocvar_g_balance_minelayer_lifetime_countdown > 0)
180 spamsound (self, CH_SHOTS, "weapons/mine_trigger.wav", VOL_BASE, ATTN_NORM);
181 self.mine_time = time + autocvar_g_balance_minelayer_lifetime_countdown;
182 self.mine_explodeanyway = 1; // make the mine super aggressive -- Samual: Rather, make it not care if a team mate is near.
185 // a player's mines shall explode if he disconnects or dies
186 // TODO: Do this on team change too -- Samual: But isn't a player killed when they switch teams?
187 if(self.realowner.classname != "player" || self.realowner.deadflag != DEAD_NO)
190 self.projectiledeathtype |= HITTYPE_BOUNCE;
195 // set the mine for detonation when a foe gets close enough
196 head = findradius(self.origin, autocvar_g_balance_minelayer_proximityradius);
199 if(head.classname == "player" && head.deadflag == DEAD_NO)
200 if(head != self.realowner && IsDifferentTeam(head, self.realowner)) // don't trigger for team mates
203 spamsound (self, CH_SHOTS, "weapons/mine_trigger.wav", VOL_BASE, ATTN_NORM);
204 self.mine_time = time + autocvar_g_balance_minelayer_time;
209 // explode if it's time to
210 if(self.mine_time && time >= self.mine_time)
212 W_Mine_ProximityExplode();
217 if (self.realowner.weapon == WEP_MINE_LAYER)
218 if (self.realowner.deadflag == DEAD_NO)
219 if (self.minelayer_detonate)
220 W_Mine_RemoteExplode();
223 void W_Mine_Touch (void)
225 if(self.movetype == MOVETYPE_NONE || self.movetype == MOVETYPE_FOLLOW)
226 return; // we're already a stuck mine, why do we get called? TODO does this even happen?
230 if(other && other.classname == "player" && other.deadflag == DEAD_NO)
241 void W_Mine_Damage (entity inflictor, entity attacker, float damage, float deathtype, vector hitloc, vector force)
243 if (self.health <= 0)
246 float is_from_enemy = (inflictor.realowner != self.realowner);
248 if (!W_CheckProjectileDamage(inflictor.realowner, self.realowner, deathtype, (is_from_enemy ? 1 : -1)))
249 return; // g_projectiles_damage says to halt
251 self.health = self.health - damage;
252 self.angles = vectoangles(self.velocity);
254 if (self.health <= 0)
255 W_PrepareExplosionByDamage(attacker, W_Mine_Explode);
258 void W_Mine_Attack (void)
263 // scan how many mines we placed, and return if we reached our limit
264 if(autocvar_g_balance_minelayer_limit)
267 if(W_Mine_Count(self) >= autocvar_g_balance_minelayer_limit)
269 // the refire delay keeps this message from being spammed
270 sprint(self, strcat("You cannot place more than ^2", ftos(autocvar_g_balance_minelayer_limit), " ^7mines at a time\n") );
271 play2(self, "weapons/unavailable.wav");
276 W_DecreaseAmmo(ammo_rockets, autocvar_g_balance_minelayer_ammo, autocvar_g_balance_minelayer_reload_ammo);
278 W_SetupShot_ProjectileSize (self, '-4 -4 -4', '4 4 4', FALSE, 5, "weapons/mine_fire.wav", CH_WEAPON_A, autocvar_g_balance_minelayer_damage);
279 pointparticles(particleeffectnum("rocketlauncher_muzzleflash"), w_shotorg, w_shotdir * 1000, 1);
281 mine = WarpZone_RefSys_SpawnSameRefSys(self);
282 mine.owner = mine.realowner = self;
283 if(autocvar_g_balance_minelayer_detonatedelay >= 0)
284 mine.spawnshieldtime = time + autocvar_g_balance_minelayer_detonatedelay;
286 mine.spawnshieldtime = -1;
287 mine.classname = "mine";
288 mine.bot_dodge = TRUE;
289 mine.bot_dodgerating = autocvar_g_balance_minelayer_damage * 2; // * 2 because it can detonate inflight which makes it even more dangerous
291 mine.takedamage = DAMAGE_YES;
292 mine.damageforcescale = autocvar_g_balance_minelayer_damageforcescale;
293 mine.health = autocvar_g_balance_minelayer_health;
294 mine.event_damage = W_Mine_Damage;
295 mine.damagedbycontents = TRUE;
297 mine.movetype = MOVETYPE_TOSS;
298 PROJECTILE_MAKETRIGGER(mine);
299 mine.projectiledeathtype = WEP_MINE_LAYER;
300 setsize (mine, '-4 -4 -4', '4 4 4'); // give it some size so it can be shot
302 setorigin (mine, w_shotorg - v_forward * 4); // move it back so it hits the wall at the right point
303 W_SetupProjectileVelocity(mine, autocvar_g_balance_minelayer_speed, 0);
304 mine.angles = vectoangles (mine.velocity);
306 mine.touch = W_Mine_Touch;
307 mine.think = W_Mine_Think;
308 mine.nextthink = time;
309 mine.cnt = time + (autocvar_g_balance_minelayer_lifetime - autocvar_g_balance_minelayer_lifetime_countdown);
310 mine.flags = FL_PROJECTILE;
312 CSQCProjectile(mine, TRUE, PROJECTILE_MINE, TRUE);
314 // muzzle flash for 1st person view
316 setmodel (flash, "models/flash.md3"); // precision set below
317 SUB_SetFade (flash, time, 0.1);
318 flash.effects = EF_ADDITIVE | EF_FULLBRIGHT | EF_LOWPRECISION;
319 W_AttachToShotorg(flash, '5 0 0');
323 other = mine; MUTATOR_CALLHOOK(EditProjectile);
325 self.minelayer_mines = W_Mine_Count(self);
328 void spawnfunc_weapon_minelayer (void); // defined in t_items.qc
330 float W_PlacedMines(float detonate)
335 for(mine = world; (mine = find(mine, classname, "mine")); ) if(mine.realowner == self)
339 if(!mine.minelayer_detonate)
341 mine.minelayer_detonate = TRUE;
351 float w_minelayer(float req)
358 // aim and decide to fire if appropriate
359 self.BUTTON_ATCK = bot_aim(autocvar_g_balance_minelayer_speed, 0, autocvar_g_balance_minelayer_lifetime, FALSE);
360 if(skill >= 2) // skill 0 and 1 bots won't detonate mines!
362 // decide whether to detonate mines
363 entity targetlist, targ;
364 float edgedamage, coredamage, edgeradius, recipricoledgeradius, d;
365 float selfdamage, teamdamage, enemydamage;
366 edgedamage = autocvar_g_balance_minelayer_edgedamage;
367 coredamage = autocvar_g_balance_minelayer_damage;
368 edgeradius = autocvar_g_balance_minelayer_radius;
369 recipricoledgeradius = 1 / edgeradius;
373 targetlist = findchainfloat(bot_attack, TRUE);
374 mine = find(world, classname, "mine");
377 if (mine.realowner != self)
379 mine = find(mine, classname, "mine");
385 d = vlen(targ.origin + (targ.mins + targ.maxs) * 0.5 - mine.origin);
386 d = bound(0, edgedamage + (coredamage - edgedamage) * sqrt(1 - d * recipricoledgeradius), 10000);
387 // count potential damage according to type of target
389 selfdamage = selfdamage + d;
390 else if (targ.team == self.team && teamplay)
391 teamdamage = teamdamage + d;
392 else if (bot_shouldattack(targ))
393 enemydamage = enemydamage + d;
396 mine = find(mine, classname, "mine");
398 float desirabledamage;
399 desirabledamage = enemydamage;
400 if (time > self.invincible_finished && time > self.spawnshieldtime)
401 desirabledamage = desirabledamage - selfdamage * autocvar_g_balance_selfdamagepercent;
402 if (teamplay && self.team)
403 desirabledamage = desirabledamage - teamdamage;
405 mine = find(world, classname, "mine");
408 if (mine.realowner != self)
410 mine = find(mine, classname, "mine");
413 makevectors(mine.v_angle);
415 if (skill > 9) // normal players only do this for the target they are tracking
421 (v_forward * normalize(mine.origin - targ.origin)< 0.1)
422 && desirabledamage > 0.1*coredamage
423 )self.BUTTON_ATCK2 = TRUE;
427 float distance; distance= bound(300,vlen(self.origin-self.enemy.origin),30000);
428 //As the distance gets larger, a correct detonation gets near imposible
429 //Bots are assumed to use the mine spawnfunc_light to see if the mine gets near a player
430 if(v_forward * normalize(mine.origin - self.enemy.origin)< 0.1)
431 if(self.enemy.classname == "player")
432 if(desirabledamage >= 0.1*coredamage)
433 if(random()/distance*300 > frametime*bound(0,(10-skill)*0.2,1))
434 self.BUTTON_ATCK2 = TRUE;
435 // dprint(ftos(random()/distance*300),">");dprint(ftos(frametime*bound(0,(10-skill)*0.2,1)),"\n");
438 mine = find(mine, classname, "mine");
440 // if we would be doing at X percent of the core damage, detonate it
441 // but don't fire a new shot at the same time!
442 if (desirabledamage >= 0.75 * coredamage) //this should do group damage in rare fortunate events
443 self.BUTTON_ATCK2 = TRUE;
444 if ((skill > 6.5) && (selfdamage > self.health))
445 self.BUTTON_ATCK2 = FALSE;
446 //if(self.BUTTON_ATCK2 == TRUE)
447 // dprint(ftos(desirabledamage),"\n");
448 if (self.BUTTON_ATCK2 == TRUE) self.BUTTON_ATCK = FALSE;
451 else if (req == WR_THINK)
453 if(autocvar_g_balance_minelayer_reload_ammo && self.clip_load < autocvar_g_balance_minelayer_ammo) // forced reload
455 // not if we're holding the minelayer without enough ammo, but can detonate existing mines
456 if not (W_PlacedMines(FALSE) && self.ammo_rockets < autocvar_g_balance_minelayer_ammo)
457 weapon_action(self.weapon, WR_RELOAD);
459 else if (self.BUTTON_ATCK)
461 if(weapon_prepareattack(0, autocvar_g_balance_minelayer_refire))
464 weapon_thinkf(WFRAME_FIRE1, autocvar_g_balance_minelayer_animtime, w_ready);
468 if (self.BUTTON_ATCK2)
470 if(W_PlacedMines(TRUE))
471 sound (self, CH_WEAPON_B, "weapons/mine_det.wav", VOL_BASE, ATTN_NORM);
474 else if (req == WR_PRECACHE)
476 precache_model ("models/flash.md3");
477 precache_model ("models/mine.md3");
478 precache_model ("models/weapons/g_minelayer.md3");
479 precache_model ("models/weapons/v_minelayer.md3");
480 precache_model ("models/weapons/h_minelayer.iqm");
481 precache_sound ("weapons/mine_det.wav");
482 precache_sound ("weapons/mine_fire.wav");
483 precache_sound ("weapons/mine_stick.wav");
484 precache_sound ("weapons/mine_trigger.wav");
485 //precache_sound ("weapons/reload.wav"); // until weapons have individual reload sounds, precache the reload sound somewhere else
487 else if (req == WR_SETUP)
489 weapon_setup(WEP_MINE_LAYER);
490 self.current_ammo = ammo_rockets;
492 else if (req == WR_CHECKAMMO1)
494 // don't switch while placing a mine
495 if (ATTACK_FINISHED(self) <= time || self.weapon != WEP_MINE_LAYER)
497 ammo_amount = self.ammo_rockets >= autocvar_g_balance_minelayer_ammo;
498 ammo_amount += self.(weapon_load[WEP_MINE_LAYER]) >= autocvar_g_balance_minelayer_ammo;
502 else if (req == WR_CHECKAMMO2)
504 if (W_PlacedMines(FALSE))
509 else if (req == WR_RELOAD)
511 W_Reload(autocvar_g_balance_minelayer_ammo, autocvar_g_balance_minelayer_reload_ammo, autocvar_g_balance_minelayer_reload_time, "weapons/reload.wav");
517 float w_minelayer(float req)
519 if(req == WR_IMPACTEFFECT)
522 org2 = w_org + w_backoff * 12;
523 pointparticles(particleeffectnum("rocket_explode"), org2, '0 0 0', 1);
525 sound(self, CH_SHOTS, "weapons/mine_exp.wav", VOL_BASE, ATTN_NORM);
527 else if(req == WR_PRECACHE)
529 precache_sound("weapons/mine_exp.wav");
531 else if (req == WR_SUICIDEMESSAGE)
532 if(w_deathtype & HITTYPE_BOUNCE) // (remote detonation)
533 w_deathtypestring = _("%s blew themself up with their minelayer");
535 w_deathtypestring = _("%s forgot about their mine");
536 else if (req == WR_KILLMESSAGE)
538 if(w_deathtype & HITTYPE_BOUNCE) // (remote detonation)
539 w_deathtypestring = _("%s got too close to %s's mine");
540 else if(w_deathtype & HITTYPE_SPLASH)
541 w_deathtypestring = _("%s almost dodged %s's mine");
543 w_deathtypestring = _("%s stepped on %s's mine");