2 REGISTER_WEAPON(MINE_LAYER, w_minelayer, IT_ROCKETS, 4, WEP_TYPE_SPLASH, BOT_PICKUP_RATING_HIGH, "minelayer", "minelayer", _("Mine Layer"))
5 void W_Mine_Think (void);
6 .float minelayer_detonate, minelayer_mines;
11 void W_MineLayer_SetAmmoCounter()
13 // set clip_load to the weapon we have switched to, if the gun uses reloading
14 if(!autocvar_g_balance_minelayer_reload_ammo)
15 self.clip_load = 0; // also keeps crosshair ammo from displaying
18 self.clip_load = self.minelayer_load;
19 self.clip_size = autocvar_g_balance_minelayer_reload_ammo; // for the crosshair ammo display
23 void W_MineLayer_ReloadedAndReady()
27 // now do the ammo transfer
28 self.clip_load = self.old_clip_load; // restore the ammo counter, in case we still had ammo in the weapon before reloading
29 while(self.clip_load < autocvar_g_balance_minelayer_reload_ammo && self.ammo_rockets) // make sure we don't add more ammo than we have
32 self.ammo_rockets -= 1;
34 self.minelayer_load = self.clip_load;
36 t = ATTACK_FINISHED(self) - autocvar_g_balance_minelayer_reload_time - 1;
37 ATTACK_FINISHED(self) = t;
41 void W_MineLayer_Reload()
43 // return if reloading is disabled for this weapon
44 if(!autocvar_g_balance_minelayer_reload_ammo)
47 if(!W_ReloadCheck(self.ammo_rockets))
52 sound (self, CHAN_WEAPON2, "weapons/reload.wav", VOL_BASE, ATTN_NORM);
54 t = max(time, ATTACK_FINISHED(self)) + autocvar_g_balance_minelayer_reload_time + 1;
55 ATTACK_FINISHED(self) = t;
57 weapon_thinkf(WFRAME_RELOAD, autocvar_g_balance_minelayer_reload_time, W_MineLayer_ReloadedAndReady);
59 self.old_clip_load = self.clip_load;
63 void spawnfunc_weapon_minelayer (void)
65 weapon_defaultspawnfunc(WEP_MINE_LAYER);
70 spamsound (self, CHAN_PROJECTILE, "weapons/mine_stick.wav", VOL_BASE, ATTN_NORM);
72 // in order for mines to face properly when sticking to the ground, they must be a server side entity rather than a csqc projectile
76 newmine.classname = self.classname;
78 newmine.bot_dodge = self.bot_dodge;
79 newmine.bot_dodgerating = self.bot_dodgerating;
81 newmine.owner = self.owner;
82 setsize(newmine, '-4 -4 -4', '4 4 4');
83 setorigin(newmine, self.origin);
84 setmodel(newmine, "models/mine.md3");
85 newmine.angles = vectoangles(-trace_plane_normal); // face against the surface
87 newmine.takedamage = self.takedamage;
88 newmine.damageforcescale = self.damageforcescale;
89 newmine.health = self.health;
90 newmine.event_damage = self.event_damage;
91 newmine.spawnshieldtime = self.spawnshieldtime;
93 newmine.movetype = MOVETYPE_NONE; // lock the mine in place
94 newmine.projectiledeathtype = self.projectiledeathtype;
96 newmine.mine_time = self.mine_time;
98 newmine.touch = SUB_Null;
99 newmine.think = W_Mine_Think;
100 newmine.nextthink = time;
101 newmine.cnt = self.cnt;
102 newmine.flags = self.flags;
108 void W_Mine_Explode ()
110 if(other.takedamage == DAMAGE_AIM)
111 if(other.classname == "player")
112 if(IsDifferentTeam(self.owner, other))
114 AnnounceTo(self.owner, "airshot");
116 self.event_damage = SUB_Null;
117 self.takedamage = DAMAGE_NO;
119 RadiusDamage (self, self.owner, autocvar_g_balance_minelayer_damage, autocvar_g_balance_minelayer_edgedamage, autocvar_g_balance_minelayer_radius, world, autocvar_g_balance_minelayer_force, self.projectiledeathtype, other);
121 if (self.owner.weapon == WEP_MINE_LAYER)
123 if(self.owner.ammo_rockets < autocvar_g_balance_minelayer_ammo)
125 self.owner.cnt = WEP_MINE_LAYER;
126 ATTACK_FINISHED(self.owner) = time;
127 self.owner.switchweapon = w_getbestweapon(self.owner);
133 void W_Mine_DoRemoteExplode ()
135 self.event_damage = SUB_Null;
136 self.takedamage = DAMAGE_NO;
138 RadiusDamage (self, self.owner, 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);
140 if (self.owner.weapon == WEP_MINE_LAYER)
142 if(self.owner.ammo_rockets < autocvar_g_balance_minelayer_ammo)
144 self.owner.cnt = WEP_MINE_LAYER;
145 ATTACK_FINISHED(self.owner) = time;
146 self.owner.switchweapon = w_getbestweapon(self.owner);
152 void W_Mine_RemoteExplode ()
154 if(self.owner.deadflag == DEAD_NO)
155 if((self.spawnshieldtime >= 0)
156 ? (time >= self.spawnshieldtime) // timer
157 : (vlen(NearestPointOnBox(self.owner, self.origin) - self.origin) > autocvar_g_balance_minelayer_remote_radius) // safety device
160 W_Mine_DoRemoteExplode();
164 void W_Mine_ProximityExplode ()
166 // make sure no friend is in the mine's radius. If there is any, explosion is delayed until he's at a safe distance
167 if(autocvar_g_balance_minelayer_protection)
170 head = findradius(self.origin, autocvar_g_balance_minelayer_radius);
173 if(head == self.owner || !IsDifferentTeam(head, self.owner))
183 void W_Mine_Think (void)
187 self.nextthink = time;
191 self.projectiledeathtype |= HITTYPE_BOUNCE;
196 // a player's mines shall explode if he disconnects or dies
197 // TODO: Do this on team change too
198 if(self.owner.classname != "player" || self.owner.deadflag != DEAD_NO)
201 self.projectiledeathtype |= HITTYPE_BOUNCE;
206 // set the mine for detonation when a foe gets close enough
207 head = findradius(self.origin, autocvar_g_balance_minelayer_proximityradius);
210 if(head.classname == "player" && head.deadflag == DEAD_NO)
211 if(head != self.owner && IsDifferentTeam(head, self.owner)) // don't trigger for team mates
214 spamsound (self, CHAN_PROJECTILE, "weapons/mine_trigger.wav", VOL_BASE, ATTN_NORM);
215 self.mine_time = time + autocvar_g_balance_minelayer_time;
220 // explode if it's time to
221 if(self.mine_time && time >= self.mine_time)
222 W_Mine_ProximityExplode();
225 if (self.owner.weapon == WEP_MINE_LAYER)
226 if (self.owner.deadflag == DEAD_NO)
227 if (self.minelayer_detonate)
228 W_Mine_RemoteExplode();
231 void W_Mine_Touch (void)
234 if(!other || (other.takedamage != DAMAGE_AIM && other.movetype == MOVETYPE_NONE))
236 else if(self.movetype != MOVETYPE_NONE) // don't unstick a locked mine when someone touches it
237 self.velocity = '0 0 0';
240 void W_Mine_Damage (entity inflictor, entity attacker, float damage, float deathtype, vector hitloc, vector force)
242 if (self.health <= 0)
244 self.health = self.health - damage;
245 self.angles = vectoangles(self.velocity);
246 if (self.health <= 0)
247 W_PrepareExplosionByDamage(attacker, W_Mine_Explode);
250 void W_Mine_Attack (void)
252 if(autocvar_g_balance_minelayer_reload_ammo && self.clip_load <= 0)
253 return; // reloading, so we are done
258 // scan how many mines we placed, and return if we reached our limit
259 if(autocvar_g_balance_minelayer_limit)
261 self.minelayer_mines = 0;
262 for(mine = world; (mine = find(mine, classname, "mine")); ) if(mine.owner == self)
263 self.minelayer_mines += 1;
265 if(self.minelayer_mines >= autocvar_g_balance_minelayer_limit)
267 // the refire delay keeps this message from being spammed
268 sprint(self, strcat("You cannot place more than ^2", ftos(autocvar_g_balance_minelayer_limit), " ^7mines at a time\n") );
269 play2(self, "weapons/unavailable.wav");
274 W_SetupShot_ProjectileSize (self, '-4 -4 -4', '4 4 4', FALSE, 5, "weapons/mine_fire.wav", CHAN_WEAPON, autocvar_g_balance_minelayer_damage);
275 pointparticles(particleeffectnum("rocketlauncher_muzzleflash"), w_shotorg, w_shotdir * 1000, 1);
277 mine = WarpZone_RefSys_SpawnSameRefSys(self);
279 if(autocvar_g_balance_minelayer_detonatedelay >= 0)
280 mine.spawnshieldtime = time + autocvar_g_balance_minelayer_detonatedelay;
282 mine.spawnshieldtime = -1;
283 mine.classname = "mine";
284 mine.bot_dodge = TRUE;
285 mine.bot_dodgerating = autocvar_g_balance_minelayer_damage * 2; // * 2 because it can detonate inflight which makes it even more dangerous
287 mine.takedamage = DAMAGE_YES;
288 mine.damageforcescale = autocvar_g_balance_minelayer_damageforcescale;
289 mine.health = autocvar_g_balance_minelayer_health;
290 mine.event_damage = W_Mine_Damage;
292 mine.movetype = MOVETYPE_TOSS;
293 PROJECTILE_MAKETRIGGER(mine);
294 mine.projectiledeathtype = WEP_MINE_LAYER;
295 setsize (mine, '-4 -4 -4', '4 4 4'); // give it some size so it can be shot
297 setorigin (mine, w_shotorg - v_forward * 4); // move it back so it hits the wall at the right point
298 W_SetupProjectileVelocity(mine, autocvar_g_balance_minelayer_speed, 0);
299 mine.angles = vectoangles (mine.velocity);
301 mine.touch = W_Mine_Touch;
302 mine.think = W_Mine_Think;
303 mine.nextthink = time;
304 mine.cnt = time + autocvar_g_balance_minelayer_lifetime;
305 mine.flags = FL_PROJECTILE;
307 CSQCProjectile(mine, TRUE, PROJECTILE_MINE, TRUE);
309 // muzzle flash for 1st person view
311 setmodel (flash, "models/flash.md3"); // precision set below
312 SUB_SetFade (flash, time, 0.1);
313 flash.effects = EF_ADDITIVE | EF_FULLBRIGHT | EF_LOWPRECISION;
314 W_AttachToShotorg(flash, '5 0 0');
318 other = mine; MUTATOR_CALLHOOK(EditProjectile);
320 // if this weapon is reloadable, decrease its load. Else decrease the player's ammo
321 if not(self.items & IT_UNLIMITED_WEAPON_AMMO)
323 if(autocvar_g_balance_minelayer_reload_ammo)
325 self.clip_load -= autocvar_g_balance_minelayer_ammo;
326 self.minelayer_load = self.clip_load;
329 self.ammo_rockets -= autocvar_g_balance_minelayer_ammo;
333 void spawnfunc_weapon_minelayer (void); // defined in t_items.qc
335 float w_minelayer(float req)
341 // aim and decide to fire if appropriate
342 self.BUTTON_ATCK = bot_aim(autocvar_g_balance_minelayer_speed, 0, autocvar_g_balance_minelayer_lifetime, FALSE);
343 if(skill >= 2) // skill 0 and 1 bots won't detonate mines!
345 // decide whether to detonate mines
346 entity targetlist, targ;
347 float edgedamage, coredamage, edgeradius, recipricoledgeradius, d;
348 float selfdamage, teamdamage, enemydamage;
349 edgedamage = autocvar_g_balance_minelayer_edgedamage;
350 coredamage = autocvar_g_balance_minelayer_damage;
351 edgeradius = autocvar_g_balance_minelayer_radius;
352 recipricoledgeradius = 1 / edgeradius;
356 targetlist = findchainfloat(bot_attack, TRUE);
357 mine = find(world, classname, "mine");
360 if (mine.owner != self)
362 mine = find(mine, classname, "mine");
368 d = vlen(targ.origin + (targ.mins + targ.maxs) * 0.5 - mine.origin);
369 d = bound(0, edgedamage + (coredamage - edgedamage) * sqrt(1 - d * recipricoledgeradius), 10000);
370 // count potential damage according to type of target
372 selfdamage = selfdamage + d;
373 else if (targ.team == self.team && teams_matter)
374 teamdamage = teamdamage + d;
375 else if (bot_shouldattack(targ))
376 enemydamage = enemydamage + d;
379 mine = find(mine, classname, "mine");
381 float desirabledamage;
382 desirabledamage = enemydamage;
383 if (time > self.invincible_finished && time > self.spawnshieldtime)
384 desirabledamage = desirabledamage - selfdamage * autocvar_g_balance_selfdamagepercent;
385 if (teams_matter && self.team)
386 desirabledamage = desirabledamage - teamdamage;
388 mine = find(world, classname, "mine");
391 if (mine.owner != self)
393 mine = find(mine, classname, "mine");
396 makevectors(mine.v_angle);
398 if (skill > 9) // normal players only do this for the target they are tracking
404 (v_forward * normalize(mine.origin - targ.origin)< 0.1)
405 && desirabledamage > 0.1*coredamage
406 )self.BUTTON_ATCK2 = TRUE;
410 float distance; distance= bound(300,vlen(self.origin-self.enemy.origin),30000);
411 //As the distance gets larger, a correct detonation gets near imposible
412 //Bots are assumed to use the mine spawnfunc_light to see if the mine gets near a player
413 if(v_forward * normalize(mine.origin - self.enemy.origin)< 0.1)
414 if(self.enemy.classname == "player")
415 if(desirabledamage >= 0.1*coredamage)
416 if(random()/distance*300 > frametime*bound(0,(10-skill)*0.2,1))
417 self.BUTTON_ATCK2 = TRUE;
418 // dprint(ftos(random()/distance*300),">");dprint(ftos(frametime*bound(0,(10-skill)*0.2,1)),"\n");
421 mine = find(mine, classname, "mine");
423 // if we would be doing at X percent of the core damage, detonate it
424 // but don't fire a new shot at the same time!
425 if (desirabledamage >= 0.75 * coredamage) //this should do group damage in rare fortunate events
426 self.BUTTON_ATCK2 = TRUE;
427 if ((skill > 6.5) && (selfdamage > self.health))
428 self.BUTTON_ATCK2 = FALSE;
429 //if(self.BUTTON_ATCK2 == TRUE)
430 // dprint(ftos(desirabledamage),"\n");
431 if (self.BUTTON_ATCK2 == TRUE) self.BUTTON_ATCK = FALSE;
434 else if (req == WR_THINK)
436 if(autocvar_g_balance_minelayer_reload_ammo && self.clip_load < autocvar_g_balance_minelayer_ammo) // forced reload
437 W_MineLayer_Reload();
438 else if (self.BUTTON_ATCK)
440 if(weapon_prepareattack(0, autocvar_g_balance_minelayer_refire))
443 weapon_thinkf(WFRAME_FIRE1, autocvar_g_balance_minelayer_animtime, w_ready);
447 else if (self.BUTTON_ATCK2)
450 for(mine = world; (mine = find(mine, classname, "mine")); ) if(mine.owner == self)
452 if(!mine.minelayer_detonate)
454 mine.minelayer_detonate = TRUE;
459 sound (self, CHAN_WEAPON2, "weapons/mine_det.wav", VOL_BASE, ATTN_NORM);
464 if(self.switchweapon == self.weapon)
466 if(self.weaponentity.state == WS_READY)
468 self.wish_reload = 0;
469 W_MineLayer_Reload();
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");
486 else if (req == WR_SETUP)
488 weapon_setup(WEP_MINE_LAYER);
489 W_MineLayer_SetAmmoCounter();
491 else if (req == WR_CHECKAMMO1)
493 // don't switch while placing a mine
494 if ((ATTACK_FINISHED(self) <= time || self.weapon != WEP_MINE_LAYER)
495 && self.ammo_rockets < autocvar_g_balance_minelayer_ammo)
498 else if (req == WR_CHECKAMMO2)
502 else if (req == WR_RELOAD)
504 W_MineLayer_Reload();
510 float w_minelayer(float req)
512 if(req == WR_IMPACTEFFECT)
515 org2 = w_org + w_backoff * 12;
516 pointparticles(particleeffectnum("rocket_explode"), org2, '0 0 0', 1);
518 sound(self, CHAN_PROJECTILE, "weapons/mine_exp.wav", VOL_BASE, ATTN_NORM);
520 else if(req == WR_PRECACHE)
522 precache_sound("weapons/mine_exp.wav");
524 else if (req == WR_SUICIDEMESSAGE)
525 w_deathtypestring = "%s exploded";
526 else if (req == WR_KILLMESSAGE)
528 if(w_deathtype & HITTYPE_BOUNCE) // (remote detonation)
529 w_deathtypestring = "%s got too close to %s's mine";
530 else if(w_deathtype & HITTYPE_SPLASH)
531 w_deathtypestring = "%s almost dodged %s's mine";
533 w_deathtypestring = "%s stepped on %s's mine";