X-Git-Url: http://git.xonotic.org/?a=blobdiff_plain;f=qcsrc%2Fserver%2Fw_minelayer.qc;h=b4ecb9b5519620411ac834deb9098cff4c615b45;hb=0cb3657fcecaadef31226c4181f07c871da3baf1;hp=b5ca7aa14d692417f0487f2e1501c08fe2a41255;hpb=fdb8fddad19ce594e98563dd156fa349c0a834c6;p=xonotic%2Fxonotic-data.pk3dir.git diff --git a/qcsrc/server/w_minelayer.qc b/qcsrc/server/w_minelayer.qc index b5ca7aa14..b4ecb9b55 100644 --- a/qcsrc/server/w_minelayer.qc +++ b/qcsrc/server/w_minelayer.qc @@ -1,72 +1,17 @@ #ifdef REGISTER_WEAPON -REGISTER_WEAPON(MINE_LAYER, w_minelayer, IT_ROCKETS, 4, WEP_TYPE_SPLASH, BOT_PICKUP_RATING_HIGH, "minelayer", "minelayer", _("Mine Layer")) +REGISTER_WEAPON(MINE_LAYER, w_minelayer, IT_ROCKETS, 4, WEP_FLAG_RELOADABLE | WEP_TYPE_SPLASH, BOT_PICKUP_RATING_HIGH, "minelayer", "minelayer", _("Mine Layer")) #else #ifdef SVQC void W_Mine_Think (void); -.float minelayer_detonate, minelayer_mines; +.float minelayer_detonate, mine_explodeanyway; .float mine_time; -// weapon load persistence, for weapons that support reloading -.float minelayer_load; - -void W_MineLayer_SetAmmoCounter() -{ - // set clip_load to the weapon we have switched to, if the gun uses reloading - if(!autocvar_g_balance_minelayer_reload_ammo) - self.clip_load = 0; // also keeps crosshair ammo from displaying - else - { - self.clip_load = self.minelayer_load; - self.clip_size = autocvar_g_balance_minelayer_reload_ammo; // for the crosshair ammo display - } -} - -void W_MineLayer_ReloadedAndReady() -{ - float t; - - // now do the ammo transfer - self.clip_load = self.old_clip_load; // restore the ammo counter, in case we still had ammo in the weapon before reloading - while(self.clip_load < autocvar_g_balance_minelayer_reload_ammo && self.ammo_rockets) // make sure we don't add more ammo than we have - { - self.clip_load += 1; - self.ammo_rockets -= 1; - } - self.minelayer_load = self.clip_load; - - t = ATTACK_FINISHED(self) - autocvar_g_balance_minelayer_reload_time - 1; - ATTACK_FINISHED(self) = t; - w_ready(); -} - -void W_MineLayer_Reload() -{ - // return if reloading is disabled for this weapon - if(!autocvar_g_balance_minelayer_reload_ammo) - return; - - if(!W_ReloadCheck(self.ammo_rockets, autocvar_g_balance_minelayer_ammo)) - return; - - float t; - - sound (self, CHAN_WEAPON2, "weapons/reload.wav", VOL_BASE, ATTN_NORM); - - t = max(time, ATTACK_FINISHED(self)) + autocvar_g_balance_minelayer_reload_time + 1; - ATTACK_FINISHED(self) = t; - - weapon_thinkf(WFRAME_RELOAD, autocvar_g_balance_minelayer_reload_time, W_MineLayer_ReloadedAndReady); - - self.old_clip_load = self.clip_load; - self.clip_load = -1; -} - void spawnfunc_weapon_minelayer (void) { weapon_defaultspawnfunc(WEP_MINE_LAYER); } -void W_Mine_Stick () +void W_Mine_Stick (entity to) { spamsound (self, CHAN_PROJECTILE, "weapons/mine_stick.wav", VOL_BASE, ATTN_NORM); @@ -85,6 +30,8 @@ void W_Mine_Stick () setmodel(newmine, "models/mine.md3"); newmine.angles = vectoangles(-trace_plane_normal); // face against the surface + newmine.oldvelocity = self.velocity; + newmine.takedamage = self.takedamage; newmine.damageforcescale = self.damageforcescale; newmine.health = self.health; @@ -104,6 +51,9 @@ void W_Mine_Stick () remove(self); self = newmine; + + if(to) + SetMovetypeFollow(self, to); } void W_Mine_Explode () @@ -111,8 +61,9 @@ void W_Mine_Explode () if(other.takedamage == DAMAGE_AIM) if(other.classname == "player") if(IsDifferentTeam(self.owner, other)) - if(IsFlying(other)) - AnnounceTo(self.owner, "airshot"); + if(other.deadflag == DEAD_NO) + if(IsFlying(other)) + AnnounceTo(self.owner, "airshot"); self.event_damage = SUB_Null; self.takedamage = DAMAGE_NO; @@ -121,13 +72,18 @@ void W_Mine_Explode () if (self.owner.weapon == WEP_MINE_LAYER) { - if(self.owner.ammo_rockets < autocvar_g_balance_minelayer_ammo) + entity oldself; + oldself = self; + self = self.owner; + if (!weapon_action(WEP_MINE_LAYER, WR_CHECKAMMO1)) { - self.owner.cnt = WEP_MINE_LAYER; - ATTACK_FINISHED(self.owner) = time; - self.owner.switchweapon = w_getbestweapon(self.owner); + self.cnt = WEP_MINE_LAYER; + ATTACK_FINISHED(self) = time; + self.switchweapon = w_getbestweapon(self); } + self = oldself; } + self.owner.minelayer_mines -= 1; remove (self); } @@ -136,17 +92,25 @@ void W_Mine_DoRemoteExplode () self.event_damage = SUB_Null; self.takedamage = DAMAGE_NO; + if(self.movetype == MOVETYPE_NONE || self.movetype == MOVETYPE_FOLLOW) + self.velocity = self.oldvelocity; + 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); if (self.owner.weapon == WEP_MINE_LAYER) { - if(self.owner.ammo_rockets < autocvar_g_balance_minelayer_ammo) + entity oldself; + oldself = self; + self = self.owner; + if (!weapon_action(WEP_MINE_LAYER, WR_CHECKAMMO1)) { - self.owner.cnt = WEP_MINE_LAYER; - ATTACK_FINISHED(self.owner) = time; - self.owner.switchweapon = w_getbestweapon(self.owner); + self.cnt = WEP_MINE_LAYER; + ATTACK_FINISHED(self) = time; + self.switchweapon = w_getbestweapon(self); } + self = oldself; } + self.owner.minelayer_mines -= 1; remove (self); } @@ -165,7 +129,7 @@ void W_Mine_RemoteExplode () void W_Mine_ProximityExplode () { // make sure no friend is in the mine's radius. If there is any, explosion is delayed until he's at a safe distance - if(autocvar_g_balance_minelayer_protection) + if(autocvar_g_balance_minelayer_protection && self.mine_explodeanyway == 0) { entity head; head = findradius(self.origin, autocvar_g_balance_minelayer_radius); @@ -181,21 +145,43 @@ void W_Mine_ProximityExplode () W_Mine_Explode(); } +float W_Mine_Count(entity e) +{ + float minecount; + entity mine; + for(mine = world; (mine = find(mine, classname, "mine")); ) if(mine.owner == e) + minecount += 1; + + return minecount; +} + void W_Mine_Think (void) { entity head; self.nextthink = time; - if (time > self.cnt) + + if(self.movetype == MOVETYPE_FOLLOW) { - other = world; - self.projectiledeathtype |= HITTYPE_BOUNCE; - W_Mine_Explode(); - return; + if(LostMovetypeFollow(self)) + { + UnsetMovetypeFollow(self); + self.movetype = MOVETYPE_NONE; + } + } + + // our lifetime has expired, it's time to die - mine_time just allows us to play a sound for this + // TODO: replace this mine_trigger.wav sound with a real countdown + if ((time > self.cnt) && (!self.mine_time)) + { + if(autocvar_g_balance_minelayer_lifetime_countdown > 0) + spamsound (self, CHAN_PROJECTILE, "weapons/mine_trigger.wav", VOL_BASE, ATTN_NORM); + self.mine_time = time + autocvar_g_balance_minelayer_lifetime_countdown; + self.mine_explodeanyway = 1; // make the mine super aggressive -- Samual: Rather, make it not care if a team mate is near. } // a player's mines shall explode if he disconnects or dies - // TODO: Do this on team change too + // TODO: Do this on team change too -- Samual: But isn't a player killed when they switch teams? if(self.owner.classname != "player" || self.owner.deadflag != DEAD_NO) { other = world; @@ -220,7 +206,10 @@ void W_Mine_Think (void) // explode if it's time to if(self.mine_time && time >= self.mine_time) + { W_Mine_ProximityExplode(); + return; + } // remote detonation if (self.owner.weapon == WEP_MINE_LAYER) @@ -231,11 +220,20 @@ void W_Mine_Think (void) void W_Mine_Touch (void) { + if(self.movetype == MOVETYPE_NONE || self.movetype == MOVETYPE_FOLLOW) + return; // we're already a stuck mine, why do we get called? TODO does this even happen? + PROJECTILE_TOUCH; - if(!other || (other.takedamage != DAMAGE_AIM && other.movetype == MOVETYPE_NONE)) - W_Mine_Stick(); - else if(self.movetype != MOVETYPE_NONE) // don't unstick a locked mine when someone touches it - self.velocity = '0 0 0'; + + if(other && other.classname == "player" && other.deadflag == DEAD_NO) + { + // hit a player + // don't stick + } + else + { + W_Mine_Stick(other); + } } void W_Mine_Damage (entity inflictor, entity attacker, float damage, float deathtype, vector hitloc, vector force) @@ -256,11 +254,8 @@ void W_Mine_Attack (void) // scan how many mines we placed, and return if we reached our limit if(autocvar_g_balance_minelayer_limit) { - self.minelayer_mines = 0; - for(mine = world; (mine = find(mine, classname, "mine")); ) if(mine.owner == self) - self.minelayer_mines += 1; - - if(self.minelayer_mines >= autocvar_g_balance_minelayer_limit) + + if(W_Mine_Count(self) >= autocvar_g_balance_minelayer_limit) { // the refire delay keeps this message from being spammed sprint(self, strcat("You cannot place more than ^2", ftos(autocvar_g_balance_minelayer_limit), " ^7mines at a time\n") ); @@ -269,17 +264,7 @@ void W_Mine_Attack (void) } } - // if this weapon is reloadable, decrease its load. Else decrease the player's ammo - if not(self.items & IT_UNLIMITED_WEAPON_AMMO) - { - if(autocvar_g_balance_minelayer_reload_ammo) - { - self.clip_load -= autocvar_g_balance_minelayer_ammo; - self.minelayer_load = self.clip_load; - } - else - self.ammo_rockets -= autocvar_g_balance_minelayer_ammo; - } + W_DecreaseAmmo(ammo_rockets, autocvar_g_balance_minelayer_ammo, autocvar_g_balance_minelayer_reload_ammo); W_SetupShot_ProjectileSize (self, '-4 -4 -4', '4 4 4', FALSE, 5, "weapons/mine_fire.wav", CHAN_WEAPON, autocvar_g_balance_minelayer_damage); pointparticles(particleeffectnum("rocketlauncher_muzzleflash"), w_shotorg, w_shotdir * 1000, 1); @@ -311,7 +296,7 @@ void W_Mine_Attack (void) mine.touch = W_Mine_Touch; mine.think = W_Mine_Think; mine.nextthink = time; - mine.cnt = time + autocvar_g_balance_minelayer_lifetime; + mine.cnt = time + (autocvar_g_balance_minelayer_lifetime - autocvar_g_balance_minelayer_lifetime_countdown); mine.flags = FL_PROJECTILE; CSQCProjectile(mine, TRUE, PROJECTILE_MINE, TRUE); @@ -326,14 +311,36 @@ void W_Mine_Attack (void) // common properties other = mine; MUTATOR_CALLHOOK(EditProjectile); + + self.minelayer_mines = W_Mine_Count(self); } void spawnfunc_weapon_minelayer (void); // defined in t_items.qc -float w_minelayer(float req) +float W_PlacedMines(float detonate) { entity mine; float minfound; + + for(mine = world; (mine = find(mine, classname, "mine")); ) if(mine.owner == self) + { + if(detonate) + { + if(!mine.minelayer_detonate) + { + mine.minelayer_detonate = TRUE; + minfound = 1; + } + } + else + minfound = 1; + } + return minfound; +} + +float w_minelayer(float req) +{ + entity mine; float ammo_amount; if (req == WR_AIM) @@ -370,7 +377,7 @@ float w_minelayer(float req) // count potential damage according to type of target if (targ == self) selfdamage = selfdamage + d; - else if (targ.team == self.team && teams_matter) + else if (targ.team == self.team && teamplay) teamdamage = teamdamage + d; else if (bot_shouldattack(targ)) enemydamage = enemydamage + d; @@ -382,7 +389,7 @@ float w_minelayer(float req) desirabledamage = enemydamage; if (time > self.invincible_finished && time > self.spawnshieldtime) desirabledamage = desirabledamage - selfdamage * autocvar_g_balance_selfdamagepercent; - if (teams_matter && self.team) + if (teamplay && self.team) desirabledamage = desirabledamage - teamdamage; mine = find(world, classname, "mine"); @@ -434,7 +441,11 @@ float w_minelayer(float req) else if (req == WR_THINK) { if(autocvar_g_balance_minelayer_reload_ammo && self.clip_load < autocvar_g_balance_minelayer_ammo) // forced reload - W_MineLayer_Reload(); + { + // not if we're holding the minelayer without enough ammo, but can detonate existing mines + if not (W_PlacedMines(FALSE) && self.ammo_rockets < autocvar_g_balance_minelayer_ammo) + weapon_action(self.weapon, WR_RELOAD); + } else if (self.BUTTON_ATCK) { if(weapon_prepareattack(0, autocvar_g_balance_minelayer_refire)) @@ -444,18 +455,9 @@ float w_minelayer(float req) } } - else if (self.BUTTON_ATCK2) + if (self.BUTTON_ATCK2) { - minfound = 0; - for(mine = world; (mine = find(mine, classname, "mine")); ) if(mine.owner == self) - { - if(!mine.minelayer_detonate) - { - mine.minelayer_detonate = TRUE; - minfound = 1; - } - } - if(minfound) + if(W_PlacedMines(TRUE)) sound (self, CHAN_WEAPON2, "weapons/mine_det.wav", VOL_BASE, ATTN_NORM); } } @@ -470,40 +472,33 @@ float w_minelayer(float req) precache_sound ("weapons/mine_fire.wav"); precache_sound ("weapons/mine_stick.wav"); precache_sound ("weapons/mine_trigger.wav"); - precache_sound ("weapons/reload.wav"); + //precache_sound ("weapons/reload.wav"); // until weapons have individual reload sounds, precache the reload sound somewhere else } else if (req == WR_SETUP) { weapon_setup(WEP_MINE_LAYER); - W_MineLayer_SetAmmoCounter(); + self.current_ammo = ammo_rockets; } else if (req == WR_CHECKAMMO1) { // don't switch while placing a mine if (ATTACK_FINISHED(self) <= time || self.weapon != WEP_MINE_LAYER) { - if(autocvar_g_balance_minelayer_reload_ammo) - { - if(self.ammo_rockets < autocvar_g_balance_minelayer_ammo && self.minelayer_load < autocvar_g_balance_minelayer_ammo) - ammo_amount = TRUE; - } - else if(self.ammo_rockets < autocvar_g_balance_minelayer_ammo) - ammo_amount = TRUE; - return !ammo_amount; + ammo_amount = self.ammo_rockets >= autocvar_g_balance_minelayer_ammo; + ammo_amount += self.weapon_load[WEP_MINE_LAYER] >= autocvar_g_balance_minelayer_ammo; + return ammo_amount; } } else if (req == WR_CHECKAMMO2) { - return FALSE; - } - else if (req == WR_RESETPLAYER) - { - // all weapons must be fully loaded when we spawn - self.minelayer_load = autocvar_g_balance_minelayer_reload_ammo; + if (W_PlacedMines(FALSE)) + return TRUE; + else + return FALSE; } else if (req == WR_RELOAD) { - W_MineLayer_Reload(); + W_Reload(autocvar_g_balance_minelayer_ammo, autocvar_g_balance_minelayer_reload_ammo, autocvar_g_balance_minelayer_reload_time, "weapons/reload.wav"); } return TRUE; };