2 REGISTER_WEAPON(MINE_LAYER, w_minelayer, IT_ROCKETS, 4, WEP_FLAG_NORMAL | WEP_TYPE_SPLASH, BOT_PICKUP_RATING_HIGH, "minelayer", "minelayer", "Mine Layer");
5 void W_Mine_Think (void);
6 .float minelayer_detonate, minelayer_mines;
9 void spawnfunc_weapon_minelayer (void)
11 weapon_defaultspawnfunc(WEP_MINE_LAYER);
16 spamsound (self, CHAN_PROJECTILE, "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 setsize(newmine, '-4 -4 -4', '4 4 4');
29 setorigin(newmine, self.origin);
30 setmodel(newmine, "models/mine.md3");
31 newmine.angles = vectoangles(-trace_plane_normal); // face against the surface
33 newmine.takedamage = self.takedamage;
34 newmine.damageforcescale = self.damageforcescale;
35 newmine.health = self.health;
36 newmine.event_damage = self.event_damage;
38 newmine.movetype = MOVETYPE_NONE; // lock the mine in place
39 newmine.projectiledeathtype = self.projectiledeathtype;
41 newmine.mine_time = self.mine_time;
43 newmine.touch = SUB_Null;
44 newmine.think = W_Mine_Think;
45 newmine.nextthink = time;
46 newmine.cnt = self.cnt;
47 newmine.flags = self.flags;
53 void W_Mine_Explode ()
55 if(other.takedamage == DAMAGE_AIM)
56 if(other.classname == "player")
57 if(IsDifferentTeam(self.owner, other))
59 AnnounceTo(self.owner, "airshot");
61 self.event_damage = SUB_Null;
62 self.takedamage = DAMAGE_NO;
64 RadiusDamage (self, self.owner, cvar("g_balance_minelayer_damage"), cvar("g_balance_minelayer_edgedamage"), cvar("g_balance_minelayer_radius"), world, cvar("g_balance_minelayer_force"), self.projectiledeathtype, other);
66 if (self.owner.weapon == WEP_MINE_LAYER)
68 if(self.owner.ammo_rockets < cvar("g_balance_minelayer_ammo"))
70 self.owner.cnt = WEP_MINE_LAYER;
71 ATTACK_FINISHED(self.owner) = time;
72 self.owner.switchweapon = w_getbestweapon(self.owner);
78 void W_Mine_DoRemoteExplode ()
80 self.event_damage = SUB_Null;
81 self.takedamage = DAMAGE_NO;
83 RadiusDamage (self, self.owner, cvar("g_balance_minelayer_remote_damage"), cvar("g_balance_minelayer_remote_edgedamage"), cvar("g_balance_minelayer_remote_radius"), world, cvar("g_balance_minelayer_remote_force"), self.projectiledeathtype | HITTYPE_BOUNCE, world);
85 if (self.owner.weapon == WEP_MINE_LAYER)
87 if(self.owner.ammo_rockets < cvar("g_balance_minelayer_ammo"))
89 self.owner.cnt = WEP_MINE_LAYER;
90 ATTACK_FINISHED(self.owner) = time;
91 self.owner.switchweapon = w_getbestweapon(self.owner);
97 void W_Mine_RemoteExplode ()
99 if(self.owner.deadflag == DEAD_NO)
100 if((self.spawnshieldtime >= 0)
101 ? (time >= self.spawnshieldtime) // timer
102 : (vlen(NearestPointOnBox(self.owner, self.origin) - self.origin) > cvar("g_balance_minelayer_remote_radius")) // safety device
105 W_Mine_DoRemoteExplode();
109 void W_Mine_ProximityExplode ()
111 // make sure no friend is in the mine's radius. If there is any, explosion is delayed until he's at a safe distance
112 if(cvar("g_balance_minelayer_protection"))
115 head = findradius(self.origin, cvar("g_balance_minelayer_radius"));
118 if(head == self.owner || !IsDifferentTeam(head, self.owner))
128 void W_Mine_Think (void)
132 self.nextthink = time;
136 self.projectiledeathtype |= HITTYPE_BOUNCE;
141 // a player's mines shall explode if he disconnects or dies
142 // TODO: Do this on team change too
143 if(self.owner.classname != "player" || self.owner.deadflag != DEAD_NO)
146 self.projectiledeathtype |= HITTYPE_BOUNCE;
151 // set the mine for detonation when a foe gets close enough
152 head = findradius(self.origin, cvar("g_balance_minelayer_proximityradius"));
155 if(head.classname == "player" && head.deadflag == DEAD_NO)
156 if(head != self.owner && IsDifferentTeam(head, self.owner)) // don't trigger for team mates
159 spamsound (self, CHAN_PROJECTILE, "weapons/mine_trigger.wav", VOL_BASE, ATTN_NORM);
160 self.mine_time = time + cvar("g_balance_minelayer_time");
165 // explode if it's time to
166 if(self.mine_time && time >= self.mine_time)
167 W_Mine_ProximityExplode();
170 if (self.owner.weapon == WEP_MINE_LAYER)
171 if (self.owner.deadflag == DEAD_NO)
172 if (self.minelayer_detonate)
173 W_Mine_RemoteExplode();
176 void W_Mine_Touch (void)
179 if(!other || (other.takedamage != DAMAGE_AIM && other.movetype == MOVETYPE_NONE))
181 else if(self.movetype != MOVETYPE_NONE) // don't unstick a locked mine when someone touches it
182 self.velocity = '0 0 0';
185 void W_Mine_Damage (entity inflictor, entity attacker, float damage, float deathtype, vector hitloc, vector force)
187 if (self.health <= 0)
189 self.health = self.health - damage;
190 self.angles = vectoangles(self.velocity);
191 if (self.health <= 0)
192 W_PrepareExplosionByDamage(attacker, W_Mine_Explode);
195 void W_Mine_Attack (void)
200 // scan how many mines we placed, and return if we reached our limit
201 if(cvar("g_balance_minelayer_limit"))
203 self.minelayer_mines = 0;
204 for(mine = world; (mine = find(mine, classname, "mine")); ) if(mine.owner == self)
205 self.minelayer_mines += 1;
207 if(self.minelayer_mines >= cvar("g_balance_minelayer_limit"))
209 // the refire delay keeps this message from being spammed
210 sprint(self, strcat("You cannot place more than ^2", cvar_string("g_balance_minelayer_limit"), " ^7mines at a time\n") );
211 play2(self, "weapons/unavailable.wav");
216 if not(self.items & IT_UNLIMITED_WEAPON_AMMO)
217 self.ammo_rockets = self.ammo_rockets - cvar("g_balance_minelayer_ammo");
219 W_SetupShot_ProjectileSize (self, '-4 -4 -4', '4 4 4', FALSE, 5, "weapons/mine_fire.wav", cvar("g_balance_minelayer_damage"));
220 pointparticles(particleeffectnum("rocketlauncher_muzzleflash"), w_shotorg, w_shotdir * 1000, 1);
222 mine = WarpZone_RefSys_SpawnSameRefSys(self);
224 if(cvar("g_balance_minelayer_detonatedelay") >= 0)
225 mine.spawnshieldtime = time + cvar("g_balance_minelayer_detonatedelay");
227 mine.spawnshieldtime = -1;
228 mine.classname = "mine";
229 mine.bot_dodge = TRUE;
230 mine.bot_dodgerating = cvar("g_balance_minelayer_damage") * 2; // * 2 because it can detonate inflight which makes it even more dangerous
232 mine.takedamage = DAMAGE_YES;
233 mine.damageforcescale = cvar("g_balance_minelayer_damageforcescale");
234 mine.health = cvar("g_balance_minelayer_health");
235 mine.event_damage = W_Mine_Damage;
237 mine.movetype = MOVETYPE_TOSS;
238 PROJECTILE_MAKETRIGGER(mine);
239 mine.projectiledeathtype = WEP_MINE_LAYER;
240 setsize (mine, '-4 -4 -4', '4 4 4'); // give it some size so it can be shot
242 setorigin (mine, w_shotorg - v_forward * 4); // move it back so it hits the wall at the right point
243 W_SetupProjectileVelocity(mine, cvar("g_balance_minelayer_speed"), 0);
244 mine.angles = vectoangles (mine.velocity);
246 mine.touch = W_Mine_Touch;
247 mine.think = W_Mine_Think;
248 mine.nextthink = time;
249 mine.cnt = time + cvar("g_balance_minelayer_lifetime");
250 mine.flags = FL_PROJECTILE;
252 CSQCProjectile(mine, TRUE, PROJECTILE_MINE, TRUE);
254 // muzzle flash for 1st person view
256 setmodel (flash, "models/flash.md3"); // precision set below
257 SUB_SetFade (flash, time, 0.1);
258 flash.effects = EF_ADDITIVE | EF_FULLBRIGHT | EF_LOWPRECISION;
259 W_AttachToShotorg(flash, '5 0 0');
263 other = mine; MUTATOR_CALLHOOK(EditProjectile);
266 void spawnfunc_weapon_minelayer (void); // defined in t_items.qc
268 float w_minelayer(float req)
274 // aim and decide to fire if appropriate
275 self.BUTTON_ATCK = bot_aim(cvar("g_balance_minelayer_speed"), 0, cvar("g_balance_minelayer_lifetime"), FALSE);
276 if(skill >= 2) // skill 0 and 1 bots won't detonate mines!
278 // decide whether to detonate mines
279 entity targetlist, targ;
280 float edgedamage, coredamage, edgeradius, recipricoledgeradius, d;
281 float selfdamage, teamdamage, enemydamage;
282 edgedamage = cvar("g_balance_minelayer_edgedamage");
283 coredamage = cvar("g_balance_minelayer_damage");
284 edgeradius = cvar("g_balance_minelayer_radius");
285 recipricoledgeradius = 1 / edgeradius;
289 targetlist = findchainfloat(bot_attack, TRUE);
290 mine = find(world, classname, "mine");
293 if (mine.owner != self)
295 mine = find(mine, classname, "mine");
301 d = vlen(targ.origin + (targ.mins + targ.maxs) * 0.5 - mine.origin);
302 d = bound(0, edgedamage + (coredamage - edgedamage) * sqrt(1 - d * recipricoledgeradius), 10000);
303 // count potential damage according to type of target
305 selfdamage = selfdamage + d;
306 else if (targ.team == self.team && teams_matter)
307 teamdamage = teamdamage + d;
308 else if (bot_shouldattack(targ))
309 enemydamage = enemydamage + d;
312 mine = find(mine, classname, "mine");
314 float desirabledamage;
315 desirabledamage = enemydamage;
316 if (teamplay != 1 && time > self.invincible_finished && time > self.spawnshieldtime)
317 desirabledamage = desirabledamage - selfdamage * cvar("g_balance_selfdamagepercent");
318 if (self.team && teamplay != 1)
319 desirabledamage = desirabledamage - teamdamage;
321 mine = find(world, classname, "mine");
324 if (mine.owner != self)
326 mine = find(mine, classname, "mine");
329 makevectors(mine.v_angle);
331 if (skill > 9) // normal players only do this for the target they are tracking
337 (v_forward * normalize(mine.origin - targ.origin)< 0.1)
338 && desirabledamage > 0.1*coredamage
339 )self.BUTTON_ATCK2 = TRUE;
343 float distance; distance= bound(300,vlen(self.origin-self.enemy.origin),30000);
344 //As the distance gets larger, a correct detonation gets near imposible
345 //Bots are assumed to use the mine spawnfunc_light to see if the mine gets near a player
346 if(v_forward * normalize(mine.origin - self.enemy.origin)< 0.1)
347 if(self.enemy.classname == "player")
348 if(desirabledamage >= 0.1*coredamage)
349 if(random()/distance*300 > frametime*bound(0,(10-skill)*0.2,1))
350 self.BUTTON_ATCK2 = TRUE;
351 // dprint(ftos(random()/distance*300),">");dprint(ftos(frametime*bound(0,(10-skill)*0.2,1)),"\n");
354 mine = find(mine, classname, "mine");
356 // if we would be doing at X percent of the core damage, detonate it
357 // but don't fire a new shot at the same time!
358 if (desirabledamage >= 0.75 * coredamage) //this should do group damage in rare fortunate events
359 self.BUTTON_ATCK2 = TRUE;
360 if ((skill > 6.5) && (selfdamage > self.health))
361 self.BUTTON_ATCK2 = FALSE;
362 //if(self.BUTTON_ATCK2 == TRUE)
363 // dprint(ftos(desirabledamage),"\n");
364 if (self.BUTTON_ATCK2 == TRUE) self.BUTTON_ATCK = FALSE;
367 else if (req == WR_THINK)
369 if (self.BUTTON_ATCK)
371 if(weapon_prepareattack(0, cvar("g_balance_minelayer_refire")))
374 weapon_thinkf(WFRAME_FIRE1, cvar("g_balance_minelayer_animtime"), w_ready);
378 if (self.BUTTON_ATCK2)
381 for(mine = world; (mine = find(mine, classname, "mine")); ) if(mine.owner == self)
383 if(!mine.minelayer_detonate)
385 mine.minelayer_detonate = TRUE;
390 sound (self, CHAN_WEAPON2, "weapons/mine_det.wav", VOL_BASE, ATTN_NORM);
393 else if (req == WR_PRECACHE)
395 precache_model ("models/flash.md3");
396 precache_model ("models/mine.md3");
397 precache_model ("models/weapons/g_minelayer.md3");
398 precache_model ("models/weapons/v_minelayer.md3");
399 precache_model ("models/weapons/h_minelayer.iqm");
400 precache_sound ("weapons/mine_det.wav");
401 precache_sound ("weapons/mine_fire.wav");
402 precache_sound ("weapons/mine_stick.wav");
403 precache_sound ("weapons/mine_trigger.wav");
405 else if (req == WR_SETUP)
407 weapon_setup(WEP_MINE_LAYER);
409 else if (req == WR_CHECKAMMO1)
411 // don't switch while placing a mine
412 if ((ATTACK_FINISHED(self) <= time || self.weapon != WEP_MINE_LAYER)
413 && self.ammo_rockets < cvar("g_balance_minelayer_ammo"))
416 else if (req == WR_CHECKAMMO2)
422 float w_minelayer(float req)
424 if(req == WR_IMPACTEFFECT)
427 org2 = w_org + w_backoff * 12;
428 pointparticles(particleeffectnum("rocket_explode"), org2, '0 0 0', 1);
430 sound(self, CHAN_PROJECTILE, "weapons/mine_exp.wav", VOL_BASE, ATTN_NORM);
432 else if(req == WR_PRECACHE)
434 precache_sound("weapons/mine_exp.wav");
436 else if (req == WR_SUICIDEMESSAGE)
437 w_deathtypestring = "%s exploded";
438 else if (req == WR_KILLMESSAGE)
440 if(w_deathtype & HITTYPE_BOUNCE) // (remote detonation)
441 w_deathtypestring = "%s got too close to %s's mine";
442 else if(w_deathtype & HITTYPE_SPLASH)
443 w_deathtypestring = "%s almost dodged %s's mine";
445 w_deathtypestring = "%s stepped on %s's mine";