2 CLASS(MineLayer, Weapon)
3 /* ammotype */ ATTRIB(MineLayer, ammo_field, .int, ammo_rockets)
4 /* impulse */ ATTRIB(MineLayer, impulse, int, 4)
5 /* flags */ ATTRIB(MineLayer, spawnflags, int, WEP_FLAG_MUTATORBLOCKED | WEP_FLAG_RELOADABLE | WEP_TYPE_SPLASH);
6 /* rating */ ATTRIB(MineLayer, bot_pickupbasevalue, float, BOT_PICKUP_RATING_HIGH);
7 /* color */ ATTRIB(MineLayer, wpcolor, vector, '0.75 1 0');
8 /* modelname */ ATTRIB(MineLayer, mdl, string, "minelayer");
10 /* model */ ATTRIB(MineLayer, m_model, Model, MDL_MINELAYER_ITEM);
12 /* crosshair */ ATTRIB(MineLayer, w_crosshair, string, "gfx/crosshairminelayer");
13 /* crosshair */ ATTRIB(MineLayer, w_crosshair_size, float, 0.9);
14 /* wepimg */ ATTRIB(MineLayer, model2, string, "weaponminelayer");
15 /* refname */ ATTRIB(MineLayer, netname, string, "minelayer");
16 /* wepname */ ATTRIB(MineLayer, m_name, string, _("Mine Layer"));
18 #define X(BEGIN, P, END, class, prefix) \
20 P(class, prefix, ammo, float, NONE) \
21 P(class, prefix, animtime, float, NONE) \
22 P(class, prefix, damageforcescale, float, NONE) \
23 P(class, prefix, damage, float, NONE) \
24 P(class, prefix, detonatedelay, float, NONE) \
25 P(class, prefix, edgedamage, float, NONE) \
26 P(class, prefix, force, float, NONE) \
27 P(class, prefix, health, float, NONE) \
28 P(class, prefix, lifetime, float, NONE) \
29 P(class, prefix, lifetime_countdown, float, NONE) \
30 P(class, prefix, limit, float, NONE) \
31 P(class, prefix, protection, float, NONE) \
32 P(class, prefix, proximityradius, float, NONE) \
33 P(class, prefix, radius, float, NONE) \
34 P(class, prefix, refire, float, NONE) \
35 P(class, prefix, reload_ammo, float, NONE) \
36 P(class, prefix, reload_time, float, NONE) \
37 P(class, prefix, remote_damage, float, NONE) \
38 P(class, prefix, remote_edgedamage, float, NONE) \
39 P(class, prefix, remote_force, float, NONE) \
40 P(class, prefix, remote_radius, float, NONE) \
41 P(class, prefix, speed, float, NONE) \
42 P(class, prefix, switchdelay_drop, float, NONE) \
43 P(class, prefix, switchdelay_raise, float, NONE) \
44 P(class, prefix, time, float, NONE) \
45 P(class, prefix, weaponreplace, string, NONE) \
46 P(class, prefix, weaponstartoverride, float, NONE) \
47 P(class, prefix, weaponstart, float, NONE) \
48 P(class, prefix, weaponthrowable, float, NONE) \
50 W_PROPS(X, MineLayer, minelayer)
53 REGISTER_WEAPON(MINE_LAYER, minelayer, NEW(MineLayer));
56 void W_MineLayer_Think();
57 .float minelayer_detonate, mine_explodeanyway;
59 .vector mine_orientation;
64 spawnfunc(weapon_minelayer) { weapon_defaultspawnfunc(this, WEP_MINE_LAYER); }
66 void W_MineLayer_Stick(entity to)
68 spamsound(self, CH_SHOTS, SND(MINE_STICK), VOL_BASE, ATTN_NORM);
70 // in order for mines to face properly when sticking to the ground, they must be a server side entity rather than a csqc projectile
72 entity newmine = spawn();
73 newmine.classname = self.classname;
75 newmine.bot_dodge = self.bot_dodge;
76 newmine.bot_dodgerating = self.bot_dodgerating;
78 newmine.owner = self.owner;
79 newmine.realowner = self.realowner;
80 setsize(newmine, '-4 -4 -4', '4 4 4');
81 setorigin(newmine, self.origin);
82 setmodel(newmine, MDL_MINELAYER_MINE);
83 newmine.angles = vectoangles(-trace_plane_normal); // face against the surface
85 newmine.mine_orientation = -trace_plane_normal;
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;
92 newmine.damagedbycontents = true;
94 newmine.movetype = MOVETYPE_NONE; // lock the mine in place
95 newmine.projectiledeathtype = self.projectiledeathtype;
97 newmine.mine_time = self.mine_time;
99 newmine.touch = func_null;
100 newmine.think = W_MineLayer_Think;
101 newmine.nextthink = time;
102 newmine.cnt = self.cnt;
103 newmine.flags = self.flags;
109 SetMovetypeFollow(self, to);
112 void W_MineLayer_Explode()
114 if(other.takedamage == DAMAGE_AIM)
116 if(DIFF_TEAM(self.realowner, other))
119 Send_Notification(NOTIF_ONE, self.realowner, MSG_ANNCE, ANNCE_ACHIEVEMENT_AIRSHOT);
121 self.event_damage = func_null;
122 self.takedamage = DAMAGE_NO;
124 RadiusDamage(self, self.realowner, WEP_CVAR(minelayer, damage), WEP_CVAR(minelayer, edgedamage), WEP_CVAR(minelayer, radius), world, world, WEP_CVAR(minelayer, force), self.projectiledeathtype, other);
126 if(PS(self.realowner).m_weapon == WEP_MINE_LAYER)
128 setself(self.realowner);
129 Weapon w = WEP_MINE_LAYER;
130 if(!w.wr_checkammo1(w))
132 self.cnt = WEP_MINE_LAYER.m_id;
133 int slot = 0; // TODO: unhardcode
134 ATTACK_FINISHED(self, slot) = time;
135 PS(self).m_switchweapon = w_getbestweapon(self);
139 self.realowner.minelayer_mines -= 1;
143 void W_MineLayer_DoRemoteExplode()
145 self.event_damage = func_null;
146 self.takedamage = DAMAGE_NO;
148 if(self.movetype == MOVETYPE_NONE || self.movetype == MOVETYPE_FOLLOW)
149 self.velocity = self.mine_orientation; // particle fx and decals need .velocity
151 RadiusDamage(self, self.realowner, WEP_CVAR(minelayer, remote_damage), WEP_CVAR(minelayer, remote_edgedamage), WEP_CVAR(minelayer, remote_radius), world, world, WEP_CVAR(minelayer, remote_force), self.projectiledeathtype | HITTYPE_BOUNCE, world);
153 if(PS(self.realowner).m_weapon == WEP_MINE_LAYER)
155 setself(self.realowner);
156 Weapon w = WEP_MINE_LAYER;
157 if(!w.wr_checkammo1(w))
159 self.cnt = WEP_MINE_LAYER.m_id;
160 int slot = 0; // TODO: unhardcode
161 ATTACK_FINISHED(self, slot) = time;
162 PS(self).m_switchweapon = w_getbestweapon(self);
166 self.realowner.minelayer_mines -= 1;
170 void W_MineLayer_RemoteExplode()
172 if(!IS_DEAD(self.realowner))
173 if((self.spawnshieldtime >= 0)
174 ? (time >= self.spawnshieldtime) // timer
175 : (vdist(NearestPointOnBox(self.realowner, self.origin) - self.origin, >, WEP_CVAR(minelayer, remote_radius))) // safety device
178 W_MineLayer_DoRemoteExplode();
182 void W_MineLayer_ProximityExplode()
184 // make sure no friend is in the mine's radius. If there is any, explosion is delayed until he's at a safe distance
185 if(WEP_CVAR(minelayer, protection) && self.mine_explodeanyway == 0)
188 head = findradius(self.origin, WEP_CVAR(minelayer, radius));
191 if(head == self.realowner || SAME_TEAM(head, self.realowner))
198 W_MineLayer_Explode();
201 int W_MineLayer_Count(entity e)
205 for(mine = world; (mine = find(mine, classname, "mine")); ) if(mine.realowner == e)
211 void W_MineLayer_Think()
215 self.nextthink = time;
217 if(self.movetype == MOVETYPE_FOLLOW)
219 if(LostMovetypeFollow(self))
221 UnsetMovetypeFollow(self);
222 self.movetype = MOVETYPE_NONE;
226 // our lifetime has expired, it's time to die - mine_time just allows us to play a sound for this
227 // TODO: replace this mine_trigger.wav sound with a real countdown
228 if((time > self.cnt) && (!self.mine_time) && (self.cnt > 0))
230 if(WEP_CVAR(minelayer, lifetime_countdown) > 0)
231 spamsound(self, CH_SHOTS, SND(MINE_TRIGGER), VOL_BASE, ATTN_NORM);
232 self.mine_time = time + WEP_CVAR(minelayer, lifetime_countdown);
233 self.mine_explodeanyway = 1; // make the mine super aggressive -- Samual: Rather, make it not care if a team mate is near.
236 // a player's mines shall explode if he disconnects or dies
237 // TODO: Do this on team change too -- Samual: But isn't a player killed when they switch teams?
238 if(!IS_PLAYER(self.realowner) || IS_DEAD(self.realowner) || STAT(FROZEN, self.realowner))
241 self.projectiledeathtype |= HITTYPE_BOUNCE;
242 W_MineLayer_Explode();
246 // set the mine for detonation when a foe gets close enough
247 head = findradius(self.origin, WEP_CVAR(minelayer, proximityradius));
250 if(IS_PLAYER(head) && !IS_DEAD(head) && !STAT(FROZEN, head))
251 if(head != self.realowner && DIFF_TEAM(head, self.realowner)) // don't trigger for team mates
254 spamsound(self, CH_SHOTS, SND(MINE_TRIGGER), VOL_BASE, ATTN_NORM);
255 self.mine_time = time + WEP_CVAR(minelayer, time);
260 // explode if it's time to
261 if(self.mine_time && time >= self.mine_time)
263 W_MineLayer_ProximityExplode();
268 if(PS(self.realowner).m_weapon == WEP_MINE_LAYER)
269 if(!IS_DEAD(self.realowner))
270 if(self.minelayer_detonate)
271 W_MineLayer_RemoteExplode();
274 void W_MineLayer_Touch()
276 if(self.movetype == MOVETYPE_NONE || self.movetype == MOVETYPE_FOLLOW)
277 return; // we're already a stuck mine, why do we get called? TODO does this even happen?
279 if(WarpZone_Projectile_Touch())
282 self.realowner.minelayer_mines -= 1;
286 if(other && IS_PLAYER(other) && !IS_DEAD(other))
293 W_MineLayer_Stick(other);
297 void W_MineLayer_Damage(entity this, entity inflictor, entity attacker, float damage, int deathtype, vector hitloc, vector force)
302 float is_from_enemy = (inflictor.realowner != this.realowner);
304 if(!W_CheckProjectileDamage(inflictor.realowner, this.realowner, deathtype, (is_from_enemy ? 1 : -1)))
305 return; // g_projectiles_damage says to halt
307 this.health = this.health - damage;
308 this.angles = vectoangles(this.velocity);
311 WITHSELF(this, W_PrepareExplosionByDamage(attacker, W_MineLayer_Explode));
314 void W_MineLayer_Attack(Weapon thiswep)
319 // scan how many mines we placed, and return if we reached our limit
320 if(WEP_CVAR(minelayer, limit))
322 if(self.minelayer_mines >= WEP_CVAR(minelayer, limit))
324 // the refire delay keeps this message from being spammed
325 Send_Notification(NOTIF_ONE, self, MSG_MULTI, WEAPON_MINELAYER_LIMIT, WEP_CVAR(minelayer, limit));
326 play2(self, SND(UNAVAILABLE));
331 W_DecreaseAmmo(thiswep, self, WEP_CVAR(minelayer, ammo));
333 W_SetupShot_ProjectileSize(self, '-4 -4 -4', '4 4 4', false, 5, SND_MINE_FIRE, CH_WEAPON_A, WEP_CVAR(minelayer, damage));
334 Send_Effect(EFFECT_ROCKET_MUZZLEFLASH, w_shotorg, w_shotdir * 1000, 1);
336 mine = WarpZone_RefSys_SpawnSameRefSys(self);
337 mine.owner = mine.realowner = self;
338 if(WEP_CVAR(minelayer, detonatedelay) >= 0)
339 mine.spawnshieldtime = time + WEP_CVAR(minelayer, detonatedelay);
341 mine.spawnshieldtime = -1;
342 mine.classname = "mine";
343 mine.bot_dodge = true;
344 mine.bot_dodgerating = WEP_CVAR(minelayer, damage) * 2; // * 2 because it can detonate inflight which makes it even more dangerous
346 mine.takedamage = DAMAGE_YES;
347 mine.damageforcescale = WEP_CVAR(minelayer, damageforcescale);
348 mine.health = WEP_CVAR(minelayer, health);
349 mine.event_damage = W_MineLayer_Damage;
350 mine.damagedbycontents = true;
352 mine.movetype = MOVETYPE_TOSS;
353 PROJECTILE_MAKETRIGGER(mine);
354 mine.projectiledeathtype = WEP_MINE_LAYER.m_id;
355 setsize(mine, '-4 -4 -4', '4 4 4'); // give it some size so it can be shot
357 setorigin(mine, w_shotorg - v_forward * 4); // move it back so it hits the wall at the right point
358 W_SetupProjVelocity_Basic(mine, WEP_CVAR(minelayer, speed), 0);
359 mine.angles = vectoangles(mine.velocity);
361 mine.touch = W_MineLayer_Touch;
362 mine.think = W_MineLayer_Think;
363 mine.nextthink = time;
364 mine.cnt = (WEP_CVAR(minelayer, lifetime) - WEP_CVAR(minelayer, lifetime_countdown));
365 mine.flags = FL_PROJECTILE;
366 mine.missile_flags = MIF_SPLASH | MIF_ARC | MIF_PROXY;
368 if(mine.cnt > 0) { mine.cnt += time; }
370 CSQCProjectile(mine, true, PROJECTILE_MINE, true);
372 // muzzle flash for 1st person view
374 setmodel(flash, MDL_MINELAYER_MUZZLEFLASH); // precision set below
375 SUB_SetFade(flash, time, 0.1);
376 flash.effects = EF_ADDITIVE | EF_FULLBRIGHT | EF_LOWPRECISION;
377 W_AttachToShotorg(self, flash, '5 0 0');
381 MUTATOR_CALLHOOK(EditProjectile, self, mine);
383 self.minelayer_mines = W_MineLayer_Count(self);
386 float W_MineLayer_PlacedMines(float detonate)
391 for(mine = world; (mine = find(mine, classname, "mine")); ) if(mine.realowner == self)
395 if(!mine.minelayer_detonate)
397 mine.minelayer_detonate = true;
407 METHOD(MineLayer, wr_aim, void(entity thiswep))
410 // aim and decide to fire if appropriate
411 if(self.minelayer_mines >= WEP_CVAR(minelayer, limit))
412 PHYS_INPUT_BUTTON_ATCK(self) = false;
414 PHYS_INPUT_BUTTON_ATCK(self) = bot_aim(self, WEP_CVAR(minelayer, speed), 0, WEP_CVAR(minelayer, lifetime), false);
415 if(skill >= 2) // skill 0 and 1 bots won't detonate mines!
417 // decide whether to detonate mines
418 entity targetlist, targ;
419 float edgedamage, coredamage, edgeradius, recipricoledgeradius, d;
420 float selfdamage, teamdamage, enemydamage;
421 edgedamage = WEP_CVAR(minelayer, edgedamage);
422 coredamage = WEP_CVAR(minelayer, damage);
423 edgeradius = WEP_CVAR(minelayer, radius);
424 recipricoledgeradius = 1 / edgeradius;
428 targetlist = findchainfloat(bot_attack, true);
429 entity mine = find(world, classname, "mine");
432 if(mine.realowner != self)
434 mine = find(mine, classname, "mine");
440 d = vlen(targ.origin + (targ.mins + targ.maxs) * 0.5 - mine.origin);
441 d = bound(0, edgedamage + (coredamage - edgedamage) * sqrt(1 - d * recipricoledgeradius), 10000);
442 // count potential damage according to type of target
444 selfdamage = selfdamage + d;
445 else if(targ.team == self.team && teamplay)
446 teamdamage = teamdamage + d;
447 else if(bot_shouldattack(self, targ))
448 enemydamage = enemydamage + d;
451 mine = find(mine, classname, "mine");
453 float desirabledamage;
454 desirabledamage = enemydamage;
455 if(time > self.invincible_finished && time > self.spawnshieldtime)
456 desirabledamage = desirabledamage - selfdamage * autocvar_g_balance_selfdamagepercent;
457 if(teamplay && self.team)
458 desirabledamage = desirabledamage - teamdamage;
460 mine = find(world, classname, "mine");
463 if(mine.realowner != self)
465 mine = find(mine, classname, "mine");
468 makevectors(mine.v_angle);
470 if(skill > 9) // normal players only do this for the target they are tracking
476 (v_forward * normalize(mine.origin - targ.origin)< 0.1)
477 && desirabledamage > 0.1*coredamage
478 ) PHYS_INPUT_BUTTON_ATCK2(self) = true;
482 float distance; distance= bound(300,vlen(self.origin-self.enemy.origin),30000);
483 //As the distance gets larger, a correct detonation gets near imposible
484 //Bots are assumed to use the mine spawnfunc_light to see if the mine gets near a player
485 if(v_forward * normalize(mine.origin - self.enemy.origin)< 0.1)
486 if(IS_PLAYER(self.enemy))
487 if(desirabledamage >= 0.1*coredamage)
488 if(random()/distance*300 > frametime*bound(0,(10-skill)*0.2,1))
489 PHYS_INPUT_BUTTON_ATCK2(self) = true;
490 // dprint(ftos(random()/distance*300),">");dprint(ftos(frametime*bound(0,(10-skill)*0.2,1)),"\n");
493 mine = find(mine, classname, "mine");
495 // if we would be doing at X percent of the core damage, detonate it
496 // but don't fire a new shot at the same time!
497 if(desirabledamage >= 0.75 * coredamage) //this should do group damage in rare fortunate events
498 PHYS_INPUT_BUTTON_ATCK2(self) = true;
499 if((skill > 6.5) && (selfdamage > self.health))
500 PHYS_INPUT_BUTTON_ATCK2(self) = false;
501 //if(PHYS_INPUT_BUTTON_ATCK2(self) == true)
502 // dprint(ftos(desirabledamage),"\n");
503 if(PHYS_INPUT_BUTTON_ATCK2(self)) PHYS_INPUT_BUTTON_ATCK(self) = false;
506 METHOD(MineLayer, wr_think, void(entity thiswep, entity actor, .entity weaponentity, int fire))
508 if(autocvar_g_balance_minelayer_reload_ammo && actor.clip_load < WEP_CVAR(minelayer, ammo)) // forced reload
510 // not if we're holding the minelayer without enough ammo, but can detonate existing mines
511 if(!(W_MineLayer_PlacedMines(false) && actor.(thiswep.ammo_field) < WEP_CVAR(minelayer, ammo))) {
512 thiswep.wr_reload(thiswep, actor, weaponentity);
517 if(weapon_prepareattack(thiswep, actor, weaponentity, false, WEP_CVAR(minelayer, refire)))
519 W_MineLayer_Attack(thiswep);
520 weapon_thinkf(actor, weaponentity, WFRAME_FIRE1, WEP_CVAR(minelayer, animtime), w_ready);
526 if(W_MineLayer_PlacedMines(true))
527 sound(actor, CH_WEAPON_B, SND_MINE_DET, VOL_BASE, ATTN_NORM);
530 METHOD(MineLayer, wr_checkammo1, bool(entity thiswep))
533 int slot = 0; // TODO: unhardcode
534 // don't switch while placing a mine
535 if(ATTACK_FINISHED(self, slot) <= time || PS(self).m_weapon != WEP_MINE_LAYER)
537 float ammo_amount = self.(thiswep.ammo_field) >= WEP_CVAR(minelayer, ammo);
538 ammo_amount += self.(weapon_load[WEP_MINE_LAYER.m_id]) >= WEP_CVAR(minelayer, ammo);
543 METHOD(MineLayer, wr_checkammo2, bool(entity thiswep))
545 if(W_MineLayer_PlacedMines(false))
550 METHOD(MineLayer, wr_resetplayers, void(entity thiswep))
553 self.minelayer_mines = 0;
555 METHOD(MineLayer, wr_reload, void(entity thiswep, entity actor, .entity weaponentity))
558 W_Reload(self, WEP_CVAR(minelayer, ammo), SND_RELOAD);
560 METHOD(MineLayer, wr_suicidemessage, Notification(entity thiswep))
562 return WEAPON_MINELAYER_SUICIDE;
564 METHOD(MineLayer, wr_killmessage, Notification(entity thiswep))
566 return WEAPON_MINELAYER_MURDER;
572 METHOD(MineLayer, wr_impacteffect, void(entity thiswep))
576 org2 = w_org + w_backoff * 12;
577 pointparticles(EFFECT_ROCKET_EXPLODE, org2, '0 0 0', 1);
579 sound(self, CH_SHOTS, SND_MINE_EXP, VOL_BASE, ATTN_NORM);