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, message, string, _("Mine Layer"));
18 REGISTER_WEAPON(MINE_LAYER, NEW(MineLayer));
20 #define MINELAYER_SETTINGS(w_cvar,w_prop) MINELAYER_SETTINGS_LIST(w_cvar, w_prop, MINE_LAYER, minelayer)
21 #define MINELAYER_SETTINGS_LIST(w_cvar,w_prop,id,sn) \
22 w_cvar(id, sn, NONE, ammo) \
23 w_cvar(id, sn, NONE, animtime) \
24 w_cvar(id, sn, NONE, damage) \
25 w_cvar(id, sn, NONE, damageforcescale) \
26 w_cvar(id, sn, NONE, detonatedelay) \
27 w_cvar(id, sn, NONE, edgedamage) \
28 w_cvar(id, sn, NONE, force) \
29 w_cvar(id, sn, NONE, health) \
30 w_cvar(id, sn, NONE, lifetime) \
31 w_cvar(id, sn, NONE, lifetime_countdown) \
32 w_cvar(id, sn, NONE, limit) \
33 w_cvar(id, sn, NONE, protection) \
34 w_cvar(id, sn, NONE, proximityradius) \
35 w_cvar(id, sn, NONE, radius) \
36 w_cvar(id, sn, NONE, refire) \
37 w_cvar(id, sn, NONE, remote_damage) \
38 w_cvar(id, sn, NONE, remote_edgedamage) \
39 w_cvar(id, sn, NONE, remote_force) \
40 w_cvar(id, sn, NONE, remote_radius) \
41 w_cvar(id, sn, NONE, speed) \
42 w_cvar(id, sn, NONE, time) \
43 w_prop(id, sn, float, reloading_ammo, reload_ammo) \
44 w_prop(id, sn, float, reloading_time, reload_time) \
45 w_prop(id, sn, float, switchdelay_raise, switchdelay_raise) \
46 w_prop(id, sn, float, switchdelay_drop, switchdelay_drop) \
47 w_prop(id, sn, string, weaponreplace, weaponreplace) \
48 w_prop(id, sn, float, weaponstart, weaponstart) \
49 w_prop(id, sn, float, weaponstartoverride, weaponstartoverride) \
50 w_prop(id, sn, float, weaponthrowable, weaponthrowable)
53 MINELAYER_SETTINGS(WEP_ADD_CVAR, WEP_ADD_PROP)
54 void W_MineLayer_Think(void);
55 .float minelayer_detonate, mine_explodeanyway;
57 .vector mine_orientation;
62 spawnfunc(weapon_minelayer) { weapon_defaultspawnfunc(WEP_MINE_LAYER.m_id); }
64 void W_MineLayer_Stick(entity to)
66 spamsound(self, CH_SHOTS, SND(MINE_STICK), VOL_BASE, ATTN_NORM);
68 // 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 newmine.classname = self.classname;
74 newmine.bot_dodge = self.bot_dodge;
75 newmine.bot_dodgerating = self.bot_dodgerating;
77 newmine.owner = self.owner;
78 newmine.realowner = self.realowner;
79 setsize(newmine, '-4 -4 -4', '4 4 4');
80 setorigin(newmine, self.origin);
81 setmodel(newmine, MDL_MINELAYER_MINE);
82 newmine.angles = vectoangles(-trace_plane_normal); // face against the surface
84 newmine.mine_orientation = -trace_plane_normal;
86 newmine.takedamage = self.takedamage;
87 newmine.damageforcescale = self.damageforcescale;
88 newmine.health = self.health;
89 newmine.event_damage = self.event_damage;
90 newmine.spawnshieldtime = self.spawnshieldtime;
91 newmine.damagedbycontents = true;
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 = func_null;
99 newmine.think = W_MineLayer_Think;
100 newmine.nextthink = time;
101 newmine.cnt = self.cnt;
102 newmine.flags = self.flags;
108 SetMovetypeFollow(self, to);
111 void W_MineLayer_Explode(void)
113 if(other.takedamage == DAMAGE_AIM)
115 if(DIFF_TEAM(self.realowner, other))
116 if(other.deadflag == DEAD_NO)
118 Send_Notification(NOTIF_ONE, self.realowner, MSG_ANNCE, ANNCE_ACHIEVEMENT_AIRSHOT);
120 self.event_damage = func_null;
121 self.takedamage = DAMAGE_NO;
123 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);
125 if(self.realowner.weapon == WEP_MINE_LAYER.m_id)
127 setself(self.realowner);
128 Weapon w = WEP_MINE_LAYER;
129 if(!w.wr_checkammo1(w))
131 self.cnt = WEP_MINE_LAYER.m_id;
132 int slot = 0; // TODO: unhardcode
133 ATTACK_FINISHED(self, slot) = time;
134 self.switchweapon = w_getbestweapon(self);
138 self.realowner.minelayer_mines -= 1;
142 void W_MineLayer_DoRemoteExplode(void)
144 self.event_damage = func_null;
145 self.takedamage = DAMAGE_NO;
147 if(self.movetype == MOVETYPE_NONE || self.movetype == MOVETYPE_FOLLOW)
148 self.velocity = self.mine_orientation; // particle fx and decals need .velocity
150 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);
152 if(self.realowner.weapon == WEP_MINE_LAYER.m_id)
154 setself(self.realowner);
155 Weapon w = WEP_MINE_LAYER;
156 if(!w.wr_checkammo1(w))
158 self.cnt = WEP_MINE_LAYER.m_id;
159 int slot = 0; // TODO: unhardcode
160 ATTACK_FINISHED(self, slot) = time;
161 self.switchweapon = w_getbestweapon(self);
165 self.realowner.minelayer_mines -= 1;
169 void W_MineLayer_RemoteExplode(void)
171 if(self.realowner.deadflag == DEAD_NO)
172 if((self.spawnshieldtime >= 0)
173 ? (time >= self.spawnshieldtime) // timer
174 : (vlen(NearestPointOnBox(self.realowner, self.origin) - self.origin) > WEP_CVAR(minelayer, remote_radius)) // safety device
177 W_MineLayer_DoRemoteExplode();
181 void W_MineLayer_ProximityExplode(void)
183 // make sure no friend is in the mine's radius. If there is any, explosion is delayed until he's at a safe distance
184 if(WEP_CVAR(minelayer, protection) && self.mine_explodeanyway == 0)
187 head = findradius(self.origin, WEP_CVAR(minelayer, radius));
190 if(head == self.realowner || SAME_TEAM(head, self.realowner))
197 W_MineLayer_Explode();
200 int W_MineLayer_Count(entity e)
204 for(mine = world; (mine = find(mine, classname, "mine")); ) if(mine.realowner == e)
210 void W_MineLayer_Think(void)
214 self.nextthink = time;
216 if(self.movetype == MOVETYPE_FOLLOW)
218 if(LostMovetypeFollow(self))
220 UnsetMovetypeFollow(self);
221 self.movetype = MOVETYPE_NONE;
225 // our lifetime has expired, it's time to die - mine_time just allows us to play a sound for this
226 // TODO: replace this mine_trigger.wav sound with a real countdown
227 if((time > self.cnt) && (!self.mine_time) && (self.cnt > 0))
229 if(WEP_CVAR(minelayer, lifetime_countdown) > 0)
230 spamsound(self, CH_SHOTS, SND(MINE_TRIGGER), VOL_BASE, ATTN_NORM);
231 self.mine_time = time + WEP_CVAR(minelayer, lifetime_countdown);
232 self.mine_explodeanyway = 1; // make the mine super aggressive -- Samual: Rather, make it not care if a team mate is near.
235 // a player's mines shall explode if he disconnects or dies
236 // TODO: Do this on team change too -- Samual: But isn't a player killed when they switch teams?
237 if(!IS_PLAYER(self.realowner) || self.realowner.deadflag != DEAD_NO || self.realowner.frozen)
240 self.projectiledeathtype |= HITTYPE_BOUNCE;
241 W_MineLayer_Explode();
245 // set the mine for detonation when a foe gets close enough
246 head = findradius(self.origin, WEP_CVAR(minelayer, proximityradius));
249 if(IS_PLAYER(head) && head.deadflag == DEAD_NO && !head.frozen)
250 if(head != self.realowner && DIFF_TEAM(head, self.realowner)) // don't trigger for team mates
253 spamsound(self, CH_SHOTS, SND(MINE_TRIGGER), VOL_BASE, ATTN_NORM);
254 self.mine_time = time + WEP_CVAR(minelayer, time);
259 // explode if it's time to
260 if(self.mine_time && time >= self.mine_time)
262 W_MineLayer_ProximityExplode();
267 if(self.realowner.weapon == WEP_MINE_LAYER.m_id)
268 if(self.realowner.deadflag == DEAD_NO)
269 if(self.minelayer_detonate)
270 W_MineLayer_RemoteExplode();
273 void W_MineLayer_Touch(void)
275 if(self.movetype == MOVETYPE_NONE || self.movetype == MOVETYPE_FOLLOW)
276 return; // we're already a stuck mine, why do we get called? TODO does this even happen?
278 if(WarpZone_Projectile_Touch())
281 self.realowner.minelayer_mines -= 1;
285 if(other && IS_PLAYER(other) && other.deadflag == DEAD_NO)
292 W_MineLayer_Stick(other);
296 void W_MineLayer_Damage(entity inflictor, entity attacker, float damage, int deathtype, vector hitloc, vector force)
301 float is_from_enemy = (inflictor.realowner != self.realowner);
303 if(!W_CheckProjectileDamage(inflictor.realowner, self.realowner, deathtype, (is_from_enemy ? 1 : -1)))
304 return; // g_projectiles_damage says to halt
306 self.health = self.health - damage;
307 self.angles = vectoangles(self.velocity);
310 W_PrepareExplosionByDamage(attacker, W_MineLayer_Explode);
313 void W_MineLayer_Attack(Weapon thiswep)
318 // scan how many mines we placed, and return if we reached our limit
319 if(WEP_CVAR(minelayer, limit))
321 if(self.minelayer_mines >= WEP_CVAR(minelayer, limit))
323 // the refire delay keeps this message from being spammed
324 Send_Notification(NOTIF_ONE, self, MSG_MULTI, WEAPON_MINELAYER_LIMIT, WEP_CVAR(minelayer, limit));
325 play2(self, SND(UNAVAILABLE));
330 W_DecreaseAmmo(thiswep, self, WEP_CVAR(minelayer, ammo));
332 W_SetupShot_ProjectileSize(self, '-4 -4 -4', '4 4 4', false, 5, SND(MINE_FIRE), CH_WEAPON_A, WEP_CVAR(minelayer, damage));
333 Send_Effect(EFFECT_ROCKET_MUZZLEFLASH, w_shotorg, w_shotdir * 1000, 1);
335 mine = WarpZone_RefSys_SpawnSameRefSys(self);
336 mine.owner = mine.realowner = self;
337 if(WEP_CVAR(minelayer, detonatedelay) >= 0)
338 mine.spawnshieldtime = time + WEP_CVAR(minelayer, detonatedelay);
340 mine.spawnshieldtime = -1;
341 mine.classname = "mine";
342 mine.bot_dodge = true;
343 mine.bot_dodgerating = WEP_CVAR(minelayer, damage) * 2; // * 2 because it can detonate inflight which makes it even more dangerous
345 mine.takedamage = DAMAGE_YES;
346 mine.damageforcescale = WEP_CVAR(minelayer, damageforcescale);
347 mine.health = WEP_CVAR(minelayer, health);
348 mine.event_damage = W_MineLayer_Damage;
349 mine.damagedbycontents = true;
351 mine.movetype = MOVETYPE_TOSS;
352 PROJECTILE_MAKETRIGGER(mine);
353 mine.projectiledeathtype = WEP_MINE_LAYER.m_id;
354 setsize(mine, '-4 -4 -4', '4 4 4'); // give it some size so it can be shot
356 setorigin(mine, w_shotorg - v_forward * 4); // move it back so it hits the wall at the right point
357 W_SetupProjVelocity_Basic(mine, WEP_CVAR(minelayer, speed), 0);
358 mine.angles = vectoangles(mine.velocity);
360 mine.touch = W_MineLayer_Touch;
361 mine.think = W_MineLayer_Think;
362 mine.nextthink = time;
363 mine.cnt = (WEP_CVAR(minelayer, lifetime) - WEP_CVAR(minelayer, lifetime_countdown));
364 mine.flags = FL_PROJECTILE;
365 mine.missile_flags = MIF_SPLASH | MIF_ARC | MIF_PROXY;
367 if(mine.cnt > 0) { mine.cnt += time; }
369 CSQCProjectile(mine, true, PROJECTILE_MINE, true);
371 // muzzle flash for 1st person view
373 setmodel(flash, MDL_MINELAYER_MUZZLEFLASH); // precision set below
374 SUB_SetFade(flash, time, 0.1);
375 flash.effects = EF_ADDITIVE | EF_FULLBRIGHT | EF_LOWPRECISION;
376 W_AttachToShotorg(self, flash, '5 0 0');
380 MUTATOR_CALLHOOK(EditProjectile, self, mine);
382 self.minelayer_mines = W_MineLayer_Count(self);
385 float W_MineLayer_PlacedMines(float detonate)
390 for(mine = world; (mine = find(mine, classname, "mine")); ) if(mine.realowner == self)
394 if(!mine.minelayer_detonate)
396 mine.minelayer_detonate = true;
406 METHOD(MineLayer, wr_aim, void(entity thiswep))
408 // aim and decide to fire if appropriate
409 if(self.minelayer_mines >= WEP_CVAR(minelayer, limit))
410 self.BUTTON_ATCK = false;
412 self.BUTTON_ATCK = bot_aim(WEP_CVAR(minelayer, speed), 0, WEP_CVAR(minelayer, lifetime), false);
413 if(skill >= 2) // skill 0 and 1 bots won't detonate mines!
415 // decide whether to detonate mines
416 entity targetlist, targ;
417 float edgedamage, coredamage, edgeradius, recipricoledgeradius, d;
418 float selfdamage, teamdamage, enemydamage;
419 edgedamage = WEP_CVAR(minelayer, edgedamage);
420 coredamage = WEP_CVAR(minelayer, damage);
421 edgeradius = WEP_CVAR(minelayer, radius);
422 recipricoledgeradius = 1 / edgeradius;
426 targetlist = findchainfloat(bot_attack, true);
427 entity mine = find(world, classname, "mine");
430 if(mine.realowner != self)
432 mine = find(mine, classname, "mine");
438 d = vlen(targ.origin + (targ.mins + targ.maxs) * 0.5 - mine.origin);
439 d = bound(0, edgedamage + (coredamage - edgedamage) * sqrt(1 - d * recipricoledgeradius), 10000);
440 // count potential damage according to type of target
442 selfdamage = selfdamage + d;
443 else if(targ.team == self.team && teamplay)
444 teamdamage = teamdamage + d;
445 else if(bot_shouldattack(targ))
446 enemydamage = enemydamage + d;
449 mine = find(mine, classname, "mine");
451 float desirabledamage;
452 desirabledamage = enemydamage;
453 if(time > self.invincible_finished && time > self.spawnshieldtime)
454 desirabledamage = desirabledamage - selfdamage * autocvar_g_balance_selfdamagepercent;
455 if(teamplay && self.team)
456 desirabledamage = desirabledamage - teamdamage;
458 mine = find(world, classname, "mine");
461 if(mine.realowner != self)
463 mine = find(mine, classname, "mine");
466 makevectors(mine.v_angle);
468 if(skill > 9) // normal players only do this for the target they are tracking
474 (v_forward * normalize(mine.origin - targ.origin)< 0.1)
475 && desirabledamage > 0.1*coredamage
476 )self.BUTTON_ATCK2 = true;
480 float distance; distance= bound(300,vlen(self.origin-self.enemy.origin),30000);
481 //As the distance gets larger, a correct detonation gets near imposible
482 //Bots are assumed to use the mine spawnfunc_light to see if the mine gets near a player
483 if(v_forward * normalize(mine.origin - self.enemy.origin)< 0.1)
484 if(IS_PLAYER(self.enemy))
485 if(desirabledamage >= 0.1*coredamage)
486 if(random()/distance*300 > frametime*bound(0,(10-skill)*0.2,1))
487 self.BUTTON_ATCK2 = true;
488 // dprint(ftos(random()/distance*300),">");dprint(ftos(frametime*bound(0,(10-skill)*0.2,1)),"\n");
491 mine = find(mine, classname, "mine");
493 // if we would be doing at X percent of the core damage, detonate it
494 // but don't fire a new shot at the same time!
495 if(desirabledamage >= 0.75 * coredamage) //this should do group damage in rare fortunate events
496 self.BUTTON_ATCK2 = true;
497 if((skill > 6.5) && (selfdamage > self.health))
498 self.BUTTON_ATCK2 = false;
499 //if(self.BUTTON_ATCK2 == true)
500 // dprint(ftos(desirabledamage),"\n");
501 if(self.BUTTON_ATCK2 == true) self.BUTTON_ATCK = false;
504 METHOD(MineLayer, wr_think, void(entity thiswep, entity actor, int slot, int fire))
506 if(autocvar_g_balance_minelayer_reload_ammo && actor.clip_load < WEP_CVAR(minelayer, ammo)) // forced reload
508 // not if we're holding the minelayer without enough ammo, but can detonate existing mines
509 if(!(W_MineLayer_PlacedMines(false) && actor.WEP_AMMO(MINE_LAYER) < WEP_CVAR(minelayer, ammo))) {
510 Weapon w = get_weaponinfo(actor.weapon);
516 if(weapon_prepareattack(thiswep, actor, slot, false, WEP_CVAR(minelayer, refire)))
518 W_MineLayer_Attack(thiswep);
519 weapon_thinkf(actor, slot, WFRAME_FIRE1, WEP_CVAR(minelayer, animtime), w_ready);
525 if(W_MineLayer_PlacedMines(true))
526 sound(actor, CH_WEAPON_B, SND_MINE_DET, VOL_BASE, ATTN_NORM);
529 METHOD(MineLayer, wr_init, void(entity thiswep))
531 MINELAYER_SETTINGS(WEP_SKIP_CVAR, WEP_SET_PROP);
533 METHOD(MineLayer, wr_checkammo1, bool(entity thiswep))
535 int slot = 0; // TODO: unhardcode
536 // don't switch while placing a mine
537 if(ATTACK_FINISHED(self, slot) <= time || self.weapon != WEP_MINE_LAYER.m_id)
539 float ammo_amount = self.WEP_AMMO(MINE_LAYER) >= WEP_CVAR(minelayer, ammo);
540 ammo_amount += self.(weapon_load[WEP_MINE_LAYER.m_id]) >= WEP_CVAR(minelayer, ammo);
545 METHOD(MineLayer, wr_checkammo2, bool(entity thiswep))
547 if(W_MineLayer_PlacedMines(false))
552 METHOD(MineLayer, wr_config, void(entity thiswep))
554 MINELAYER_SETTINGS(WEP_CONFIG_WRITE_CVARS, WEP_CONFIG_WRITE_PROPS);
556 METHOD(MineLayer, wr_resetplayers, void(entity thiswep))
558 self.minelayer_mines = 0;
560 METHOD(MineLayer, wr_reload, void(entity thiswep))
562 W_Reload(self, WEP_CVAR(minelayer, ammo), SND(RELOAD));
564 METHOD(MineLayer, wr_suicidemessage, int(entity thiswep))
566 return WEAPON_MINELAYER_SUICIDE;
568 METHOD(MineLayer, wr_killmessage, int(entity thiswep))
570 return WEAPON_MINELAYER_MURDER;
576 METHOD(MineLayer, wr_impacteffect, void(entity thiswep))
579 org2 = w_org + w_backoff * 12;
580 pointparticles(particleeffectnum(EFFECT_ROCKET_EXPLODE), org2, '0 0 0', 1);
582 sound(self, CH_SHOTS, SND_MINE_EXP, VOL_BASE, ATTN_NORM);