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(entity this);
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 this, entity to)
68 spamsound(this, 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 IL_PUSH(g_mines, newmine);
74 newmine.classname = this.classname;
76 newmine.bot_dodge = this.bot_dodge;
77 newmine.bot_dodgerating = this.bot_dodgerating;
79 newmine.owner = this.owner;
80 newmine.realowner = this.realowner;
81 setsize(newmine, '-4 -4 -4', '4 4 4');
82 setorigin(newmine, this.origin);
83 setmodel(newmine, MDL_MINELAYER_MINE);
84 newmine.angles = vectoangles(-trace_plane_normal); // face against the surface
86 newmine.mine_orientation = -trace_plane_normal;
88 newmine.takedamage = this.takedamage;
89 newmine.damageforcescale = this.damageforcescale;
90 newmine.health = this.health;
91 newmine.event_damage = this.event_damage;
92 newmine.spawnshieldtime = this.spawnshieldtime;
93 newmine.damagedbycontents = true;
95 set_movetype(newmine, MOVETYPE_NONE); // lock the mine in place
96 newmine.projectiledeathtype = this.projectiledeathtype;
98 newmine.mine_time = this.mine_time;
100 settouch(newmine, func_null);
101 setthink(newmine, W_MineLayer_Think);
102 newmine.nextthink = time;
103 newmine.cnt = this.cnt;
104 newmine.flags = this.flags;
109 SetMovetypeFollow(newmine, to);
112 void W_MineLayer_Explode(entity this, entity directhitentity)
114 if(directhitentity.takedamage == DAMAGE_AIM)
115 if(IS_PLAYER(directhitentity))
116 if(DIFF_TEAM(this.realowner, directhitentity))
117 if(!IS_DEAD(directhitentity))
118 if(IsFlying(directhitentity))
119 Send_Notification(NOTIF_ONE, this.realowner, MSG_ANNCE, ANNCE_ACHIEVEMENT_AIRSHOT);
121 this.event_damage = func_null;
122 this.takedamage = DAMAGE_NO;
124 RadiusDamage(this, this.realowner, WEP_CVAR(minelayer, damage), WEP_CVAR(minelayer, edgedamage), WEP_CVAR(minelayer, radius), NULL, NULL, WEP_CVAR(minelayer, force), this.projectiledeathtype, directhitentity);
126 if(PS(this.realowner).m_weapon == WEP_MINE_LAYER)
128 entity own = this.realowner;
129 Weapon w = WEP_MINE_LAYER;
130 if(!w.wr_checkammo1(w, own))
132 own.cnt = WEP_MINE_LAYER.m_id;
133 int slot = 0; // TODO: unhardcode
134 ATTACK_FINISHED(own, slot) = time;
135 PS(own).m_switchweapon = w_getbestweapon(own);
138 this.realowner.minelayer_mines -= 1;
142 void W_MineLayer_Explode_think(entity this)
144 W_MineLayer_Explode(this, NULL);
147 void W_MineLayer_DoRemoteExplode(entity this)
149 this.event_damage = func_null;
150 this.takedamage = DAMAGE_NO;
152 if(this.move_movetype == MOVETYPE_NONE || this.move_movetype == MOVETYPE_FOLLOW)
153 this.velocity = this.mine_orientation; // particle fx and decals need .velocity
155 RadiusDamage(this, this.realowner, WEP_CVAR(minelayer, remote_damage), WEP_CVAR(minelayer, remote_edgedamage), WEP_CVAR(minelayer, remote_radius), NULL, NULL, WEP_CVAR(minelayer, remote_force), this.projectiledeathtype | HITTYPE_BOUNCE, NULL);
157 if(PS(this.realowner).m_weapon == WEP_MINE_LAYER)
159 entity own = this.realowner;
160 Weapon w = WEP_MINE_LAYER;
161 if(!w.wr_checkammo1(w, own))
163 own.cnt = WEP_MINE_LAYER.m_id;
164 int slot = 0; // TODO: unhardcode
165 ATTACK_FINISHED(own, slot) = time;
166 PS(own).m_switchweapon = w_getbestweapon(own);
169 this.realowner.minelayer_mines -= 1;
173 void W_MineLayer_RemoteExplode(entity this)
175 if(!IS_DEAD(this.realowner))
176 if((this.spawnshieldtime >= 0)
177 ? (time >= this.spawnshieldtime) // timer
178 : (vdist(NearestPointOnBox(this.realowner, this.origin) - this.origin, >, WEP_CVAR(minelayer, remote_radius))) // safety device
181 W_MineLayer_DoRemoteExplode(this);
185 void W_MineLayer_ProximityExplode(entity this)
187 // make sure no friend is in the mine's radius. If there is any, explosion is delayed until he's at a safe distance
188 if(WEP_CVAR(minelayer, protection) && this.mine_explodeanyway == 0)
191 head = findradius(this.origin, WEP_CVAR(minelayer, radius));
194 if(head == this.realowner || SAME_TEAM(head, this.realowner))
201 W_MineLayer_Explode(this, NULL);
204 int W_MineLayer_Count(entity e)
207 IL_EACH(g_mines, it.realowner == e,
215 void W_MineLayer_Think(entity this)
219 this.nextthink = time;
221 if(this.move_movetype == MOVETYPE_FOLLOW)
223 if(LostMovetypeFollow(this))
225 UnsetMovetypeFollow(this);
226 set_movetype(this, MOVETYPE_NONE);
230 // our lifetime has expired, it's time to die - mine_time just allows us to play a sound for this
231 // TODO: replace this mine_trigger.wav sound with a real countdown
232 if((time > this.cnt) && (!this.mine_time) && (this.cnt > 0))
234 if(WEP_CVAR(minelayer, lifetime_countdown) > 0)
235 spamsound(this, CH_SHOTS, SND(MINE_TRIGGER), VOL_BASE, ATTN_NORM);
236 this.mine_time = time + WEP_CVAR(minelayer, lifetime_countdown);
237 this.mine_explodeanyway = 1; // make the mine super aggressive -- Samual: Rather, make it not care if a team mate is near.
240 // a player's mines shall explode if he disconnects or dies
241 // TODO: Do this on team change too -- Samual: But isn't a player killed when they switch teams?
242 if(!IS_PLAYER(this.realowner) || IS_DEAD(this.realowner) || STAT(FROZEN, this.realowner))
244 this.projectiledeathtype |= HITTYPE_BOUNCE;
245 W_MineLayer_Explode(this, NULL);
249 // set the mine for detonation when a foe gets close enough
250 head = findradius(this.origin, WEP_CVAR(minelayer, proximityradius));
253 if(IS_PLAYER(head) && !IS_DEAD(head) && !STAT(FROZEN, head))
254 if(head != this.realowner && DIFF_TEAM(head, this.realowner)) // don't trigger for team mates
257 spamsound(this, CH_SHOTS, SND(MINE_TRIGGER), VOL_BASE, ATTN_NORM);
258 this.mine_time = time + WEP_CVAR(minelayer, time);
263 // explode if it's time to
264 if(this.mine_time && time >= this.mine_time)
266 W_MineLayer_ProximityExplode(this);
271 if(PS(this.realowner).m_weapon == WEP_MINE_LAYER)
272 if(!IS_DEAD(this.realowner))
273 if(this.minelayer_detonate)
274 W_MineLayer_RemoteExplode(this);
277 void W_MineLayer_Touch(entity this, entity toucher)
279 if(this.move_movetype == MOVETYPE_NONE || this.move_movetype == MOVETYPE_FOLLOW)
280 return; // we're already a stuck mine, why do we get called? TODO does this even happen?
282 if(WarpZone_Projectile_Touch(this, toucher))
285 this.realowner.minelayer_mines -= 1;
289 if(toucher && IS_PLAYER(toucher) && !IS_DEAD(toucher))
296 W_MineLayer_Stick(this, toucher);
300 void W_MineLayer_Damage(entity this, entity inflictor, entity attacker, float damage, int deathtype, vector hitloc, vector force)
305 float is_from_enemy = (inflictor.realowner != this.realowner);
307 if(!W_CheckProjectileDamage(inflictor.realowner, this.realowner, deathtype, (is_from_enemy ? 1 : -1)))
308 return; // g_projectiles_damage says to halt
310 this.health = this.health - damage;
311 this.angles = vectoangles(this.velocity);
314 W_PrepareExplosionByDamage(this, attacker, W_MineLayer_Explode_think);
317 void W_MineLayer_Attack(Weapon thiswep, entity actor)
322 // scan how many mines we placed, and return if we reached our limit
323 if(WEP_CVAR(minelayer, limit))
325 if(actor.minelayer_mines >= WEP_CVAR(minelayer, limit))
327 // the refire delay keeps this message from being spammed
328 Send_Notification(NOTIF_ONE, actor, MSG_MULTI, WEAPON_MINELAYER_LIMIT, WEP_CVAR(minelayer, limit));
329 play2(actor, SND(UNAVAILABLE));
334 W_DecreaseAmmo(thiswep, actor, WEP_CVAR(minelayer, ammo));
336 W_SetupShot_ProjectileSize(actor, '-4 -4 -4', '4 4 4', false, 5, SND_MINE_FIRE, CH_WEAPON_A, WEP_CVAR(minelayer, damage));
337 Send_Effect(EFFECT_ROCKET_MUZZLEFLASH, w_shotorg, w_shotdir * 1000, 1);
339 mine = WarpZone_RefSys_SpawnSameRefSys(actor);
340 IL_PUSH(g_mines, mine);
341 mine.owner = mine.realowner = actor;
342 if(WEP_CVAR(minelayer, detonatedelay) >= 0)
343 mine.spawnshieldtime = time + WEP_CVAR(minelayer, detonatedelay);
345 mine.spawnshieldtime = -1;
346 mine.classname = "mine";
347 mine.bot_dodge = true;
348 mine.bot_dodgerating = WEP_CVAR(minelayer, damage) * 2; // * 2 because it can detonate inflight which makes it even more dangerous
350 mine.takedamage = DAMAGE_YES;
351 mine.damageforcescale = WEP_CVAR(minelayer, damageforcescale);
352 mine.health = WEP_CVAR(minelayer, health);
353 mine.event_damage = W_MineLayer_Damage;
354 mine.damagedbycontents = true;
356 set_movetype(mine, MOVETYPE_TOSS);
357 PROJECTILE_MAKETRIGGER(mine);
358 mine.projectiledeathtype = WEP_MINE_LAYER.m_id;
359 setsize(mine, '-4 -4 -4', '4 4 4'); // give it some size so it can be shot
361 setorigin(mine, w_shotorg - v_forward * 4); // move it back so it hits the wall at the right point
362 W_SetupProjVelocity_Basic(mine, WEP_CVAR(minelayer, speed), 0);
363 mine.angles = vectoangles(mine.velocity);
365 settouch(mine, W_MineLayer_Touch);
366 setthink(mine, W_MineLayer_Think);
367 mine.nextthink = time;
368 mine.cnt = (WEP_CVAR(minelayer, lifetime) - WEP_CVAR(minelayer, lifetime_countdown));
369 mine.flags = FL_PROJECTILE;
370 mine.missile_flags = MIF_SPLASH | MIF_ARC | MIF_PROXY;
372 if(mine.cnt > 0) { mine.cnt += time; }
374 CSQCProjectile(mine, true, PROJECTILE_MINE, true);
376 // muzzle flash for 1st person view
378 setmodel(flash, MDL_MINELAYER_MUZZLEFLASH); // precision set below
379 SUB_SetFade(flash, time, 0.1);
380 flash.effects = EF_ADDITIVE | EF_FULLBRIGHT | EF_LOWPRECISION;
381 W_AttachToShotorg(actor, flash, '5 0 0');
385 MUTATOR_CALLHOOK(EditProjectile, actor, mine);
387 actor.minelayer_mines = W_MineLayer_Count(actor);
390 bool W_MineLayer_PlacedMines(entity this, bool detonate)
392 bool minfound = false;
394 IL_EACH(g_mines, it.realowner == this,
398 if(!it.minelayer_detonate)
400 it.minelayer_detonate = true;
410 METHOD(MineLayer, wr_aim, void(entity thiswep, entity actor))
412 // aim and decide to fire if appropriate
413 if(actor.minelayer_mines >= WEP_CVAR(minelayer, limit))
414 PHYS_INPUT_BUTTON_ATCK(actor) = false;
416 PHYS_INPUT_BUTTON_ATCK(actor) = bot_aim(actor, WEP_CVAR(minelayer, speed), 0, WEP_CVAR(minelayer, lifetime), false);
417 if(skill >= 2) // skill 0 and 1 bots won't detonate mines!
419 // decide whether to detonate mines
420 float edgedamage, coredamage, edgeradius, recipricoledgeradius;
421 float selfdamage, teamdamage, enemydamage;
422 edgedamage = WEP_CVAR(minelayer, edgedamage);
423 coredamage = WEP_CVAR(minelayer, damage);
424 edgeradius = WEP_CVAR(minelayer, radius);
425 recipricoledgeradius = 1 / edgeradius;
430 IL_EACH(g_mines, it.realowner == actor,
433 FOREACH_ENTITY_FLOAT(bot_attack, true,
435 float d = vlen(it.origin + (it.mins + it.maxs) * 0.5 - mine.origin);
436 d = bound(0, edgedamage + (coredamage - edgedamage) * sqrt(1 - d * recipricoledgeradius), 10000);
437 // count potential damage according to type of target
439 selfdamage = selfdamage + d;
440 else if(SAME_TEAM(it, actor))
441 teamdamage = teamdamage + d;
442 else if(bot_shouldattack(actor, it))
443 enemydamage = enemydamage + d;
447 float desirabledamage;
448 desirabledamage = enemydamage;
449 if(time > actor.invincible_finished && time > actor.spawnshieldtime)
450 desirabledamage = desirabledamage - selfdamage * autocvar_g_balance_selfdamagepercent;
451 if(teamplay && actor.team)
452 desirabledamage = desirabledamage - teamdamage;
454 makevectors(actor.v_angle);
455 IL_EACH(g_mines, it.realowner == actor,
457 if(skill > 9) // normal players only do this for the target they are tracking
460 FOREACH_ENTITY_FLOAT(bot_attack, true,
462 if((v_forward * normalize(mine.origin - it.origin) < 0.1)
463 && desirabledamage > 0.1 * coredamage
464 ) PHYS_INPUT_BUTTON_ATCK2(actor) = true;
469 //As the distance gets larger, a correct detonation gets near imposible
470 //Bots are assumed to use the mine spawnfunc_light to see if the mine gets near a player
471 if((v_forward * normalize(it.origin - actor.enemy.origin) < 0.1)
472 && IS_PLAYER(actor.enemy)
473 && (desirabledamage >= 0.1 * coredamage)
476 float distance = bound(300, vlen(actor.origin - actor.enemy.origin), 30000);
477 if(random() / distance * 300 > frametime * bound(0, (10 - skill) * 0.2, 1))
478 PHYS_INPUT_BUTTON_ATCK2(actor) = true;
483 // if we would be doing at X percent of the core damage, detonate it
484 // but don't fire a new shot at the same time!
485 if(desirabledamage >= 0.75 * coredamage) //this should do group damage in rare fortunate events
486 PHYS_INPUT_BUTTON_ATCK2(actor) = true;
487 if((skill > 6.5) && (selfdamage > actor.health))
488 PHYS_INPUT_BUTTON_ATCK2(actor) = false;
489 //if(PHYS_INPUT_BUTTON_ATCK2(actor) == true)
490 // dprint(ftos(desirabledamage),"\n");
491 if(PHYS_INPUT_BUTTON_ATCK2(actor)) PHYS_INPUT_BUTTON_ATCK(actor) = false;
494 METHOD(MineLayer, wr_think, void(entity thiswep, entity actor, .entity weaponentity, int fire))
496 if(autocvar_g_balance_minelayer_reload_ammo && actor.clip_load < WEP_CVAR(minelayer, ammo)) // forced reload
498 // not if we're holding the minelayer without enough ammo, but can detonate existing mines
499 if(!(W_MineLayer_PlacedMines(actor, false) && actor.(thiswep.ammo_field) < WEP_CVAR(minelayer, ammo))) {
500 thiswep.wr_reload(thiswep, actor, weaponentity);
505 if(weapon_prepareattack(thiswep, actor, weaponentity, false, WEP_CVAR(minelayer, refire)))
507 W_MineLayer_Attack(thiswep, actor);
508 weapon_thinkf(actor, weaponentity, WFRAME_FIRE1, WEP_CVAR(minelayer, animtime), w_ready);
514 if(W_MineLayer_PlacedMines(actor, true))
515 sound(actor, CH_WEAPON_B, SND_MINE_DET, VOL_BASE, ATTN_NORM);
518 METHOD(MineLayer, wr_checkammo1, bool(entity thiswep, entity actor))
520 //int slot = 0; // TODO: unhardcode
521 // actually do // don't switch while placing a mine
522 //if(ATTACK_FINISHED(actor, slot) <= time || PS(actor).m_weapon != WEP_MINE_LAYER)
524 float ammo_amount = actor.(thiswep.ammo_field) >= WEP_CVAR(minelayer, ammo);
525 ammo_amount += actor.(weapon_load[WEP_MINE_LAYER.m_id]) >= WEP_CVAR(minelayer, ammo);
530 METHOD(MineLayer, wr_checkammo2, bool(entity thiswep, entity actor))
532 if(W_MineLayer_PlacedMines(actor, false))
537 METHOD(MineLayer, wr_resetplayer, void(entity thiswep, entity actor))
539 actor.minelayer_mines = 0;
541 METHOD(MineLayer, wr_reload, void(entity thiswep, entity actor, .entity weaponentity))
543 W_Reload(actor, WEP_CVAR(minelayer, ammo), SND_RELOAD);
545 METHOD(MineLayer, wr_suicidemessage, Notification(entity thiswep))
547 return WEAPON_MINELAYER_SUICIDE;
549 METHOD(MineLayer, wr_killmessage, Notification(entity thiswep))
551 return WEAPON_MINELAYER_MURDER;
557 METHOD(MineLayer, wr_impacteffect, void(entity thiswep, entity actor))
560 org2 = w_org + w_backoff * 12;
561 pointparticles(EFFECT_ROCKET_EXPLODE, org2, '0 0 0', 1);
563 sound(actor, CH_SHOTS, SND_MINE_EXP, VOL_BASE, ATTN_NORM);