Cleanup can_fire(), projectile flag

Removes can_fire() and moves some of it's functionality into
get_next_projectile(), which was renamed to consume_next_projectile() to
indicate the possibility of side-effects.
Also renamed flag var to check_armour
This commit is contained in:
mwerezak
2015-02-12 00:53:02 -05:00
parent 931213fb7e
commit ea39f7f718
24 changed files with 83 additions and 196 deletions

View File

@@ -455,7 +455,7 @@
return
/obj/machinery/bot/medbot/bullet_act(var/obj/item/projectile/Proj)
if(Proj.flag == "taser")
if(Proj.taser_effect)
src.stunned = min(stunned+10,20)
..()

View File

@@ -585,7 +585,7 @@
chassis.visible_message("The [chassis.name] armor deflects the projectile")
chassis.log_append_to_last("Armor saved.")
else
chassis.take_damage(round(Proj.damage*src.damage_coeff),Proj.flag)
chassis.take_damage(round(Proj.damage*src.damage_coeff),Proj.check_armour)
chassis.check_for_internal_damage(list(MECHA_INT_FIRE,MECHA_INT_TEMP_CONTROL,MECHA_INT_TANK_BREACH,MECHA_INT_CONTROL_LOST))
Proj.on_hit(chassis)
set_ready_state(0)

View File

@@ -487,7 +487,7 @@
/obj/mecha/bullet_act(var/obj/item/projectile/Proj) //wrapper
src.log_message("Hit by projectile. Type: [Proj.name]([Proj.flag]).",1)
src.log_message("Hit by projectile. Type: [Proj.name]([Proj.check_armour]).",1)
call((proc_res["dynbulletdamage"]||src), "dynbulletdamage")(Proj) //calls equipment
..()
return
@@ -506,10 +506,10 @@
var/ignore_threshold
if(istype(Proj, /obj/item/projectile/beam/pulse))
ignore_threshold = 1
src.take_damage(Proj.damage, Proj.flag)
src.take_damage(Proj.damage, Proj.check_armour)
if(prob(25)) spark_system.start()
src.check_for_internal_damage(list(MECHA_INT_FIRE,MECHA_INT_TEMP_CONTROL,MECHA_INT_TANK_BREACH,MECHA_INT_CONTROL_LOST,MECHA_INT_SHORT_CIRCUIT),ignore_threshold)
//AP projectiles have a chance to cause additional damage
if(Proj.penetrating)
var/distance = get_dist(Proj.starting, get_turf(loc))
@@ -520,9 +520,9 @@
hit_occupant = 0
else
src.check_for_internal_damage(list(MECHA_INT_FIRE,MECHA_INT_TEMP_CONTROL,MECHA_INT_TANK_BREACH,MECHA_INT_CONTROL_LOST,MECHA_INT_SHORT_CIRCUIT), 1)
Proj.penetrating--
if(prob(15))
break //give a chance to exit early

View File

@@ -63,10 +63,10 @@
return
//Armor
var/absorb = run_armor_check(def_zone, P.flag)
var/absorb = run_armor_check(def_zone, P.check_armour)
var/proj_sharp = is_sharp(P)
var/proj_edge = has_edge(P)
if ((proj_sharp || proj_edge) && prob(getarmor(def_zone, P.flag)))
if ((proj_sharp || proj_edge) && prob(getarmor(def_zone, P.check_armour)))
proj_sharp = 0
proj_edge = 0

View File

@@ -127,7 +127,7 @@
/obj/machinery/power/am_control_unit/bullet_act(var/obj/item/projectile/Proj)
if(Proj.flag != "bullet")
if(Proj.check_armour != "bullet")
stability -= Proj.force
return 0

View File

@@ -117,7 +117,7 @@ proc/cardinalrange(var/center)
/obj/machinery/am_shielding/bullet_act(var/obj/item/projectile/Proj)
if(Proj.flag != "bullet")
if(Proj.check_armour != "bullet")
stability -= Proj.force/2
return 0

View File

@@ -42,7 +42,7 @@
name = "collector [mysize] OFF"
/obj/effect/rust_particle_catcher/bullet_act(var/obj/item/projectile/Proj)
if(Proj.flag != "bullet" && parent)
if(Proj.check_armour != "bullet" && parent)
parent.AddEnergy(Proj.damage * 20, 0, 1)
update_icon()
return 0

View File

@@ -53,15 +53,18 @@
if(HULK in M.mutations)
M << "<span class='danger'>Your fingers are much too large for the trigger guard!</span>"
return 0
if((CLUMSY in M.mutations) && prob(40) && can_fire()) //Clumsy handling
var/obj/P = get_next_projectile()
if(P && process_projectile(P, user, user, pick("l_foot", "r_foot")))
handle_post_fire(user, user)
user.visible_message(
"<span class='danger'>[user] shoots \himself in the foot with \the [src]!</span>",
"<span class='danger'>You shoot yourself in the foot with \the [src]!</span>"
)
M.drop_item()
if((CLUMSY in M.mutations) && prob(40)) //Clumsy handling
var/obj/P = consume_next_projectile()
if(P)
if(process_projectile(P, user, user, pick("l_foot", "r_foot")))
handle_post_fire(user, user)
user.visible_message(
"<span class='danger'>[user] shoots \himself in the foot with \the [src]!</span>",
"<span class='danger'>You shoot yourself in the foot with \the [src]!</span>"
)
M.drop_item()
else
handle_click_empty(user)
return 0
return 1
@@ -110,14 +113,14 @@
user << "<span class='warning'>[src] is not ready to fire again!"
return
var/obj/in_chamber = get_next_projectile()
if(!in_chamber)
var/obj/projectile = consume_next_projectile()
if(!projectile)
handle_click_empty(user)
return
user.next_move = world.time + 4
if(process_projectile(in_chamber, user, target, user.zone_sel.selecting, params, pointblank, reflex))
if(process_projectile(projectile, user, target, user.zone_sel.selecting, params, pointblank, reflex))
handle_post_fire(user, target, pointblank, reflex)
update_icon()
@@ -127,20 +130,17 @@
user.update_inv_r_hand()
//returns the next projectile to fire
/obj/item/weapon/gun/proc/get_next_projectile()
//obtains the next projectile to fire
/obj/item/weapon/gun/proc/consume_next_projectile()
return null
//TODO integrate this with gun code better.
//TODO maybe provide user so that subtypes can emit messages if they want?
/obj/item/weapon/gun/proc/can_fire()
return 0
//used by aiming code
/obj/item/weapon/gun/proc/can_hit(atom/target as mob, var/mob/living/user as mob)
if(!special_check(user))
return 2
return 0 //in_chamber.check_fire(target,user)
//just assume we can shoot through glass and stuff. No big deal, the player can just choose to not target someone
//on the other side of a window if it makes a difference. Or if they run behind a window, too bad.
return check_trajectory(target, user)
//called if there was no projectile to shoot
/obj/item/weapon/gun/proc/handle_click_empty(mob/user)
@@ -208,7 +208,7 @@
M.visible_message("\blue [user] decided life was worth living")
mouthshoot = 0
return
var/obj/item/projectile/in_chamber = get_next_projectile()
var/obj/item/projectile/in_chamber = consume_next_projectile()
if (istype(in_chamber))
user.visible_message("<span class = 'warning'>[user] pulls the trigger.</span>")
if(silenced)

View File

@@ -50,10 +50,7 @@
/obj/item/weapon/gun/launcher/spikethrower/update_release_force()
return
/obj/item/weapon/gun/launcher/spikethrower/can_fire()
return (spikes >= 1)
/obj/item/weapon/gun/launcher/spikethrower/get_next_projectile()
/obj/item/weapon/gun/launcher/spikethrower/consume_next_projectile()
if(spikes < 1) return null
spikes--
return new /obj/item/weapon/spike(src)
@@ -100,7 +97,7 @@
icon_state = "particle"
damage = 60
damage_type = BRUTE
flag = "bullet"
check_armour = "bullet"
pass_flags = PASSTABLE | PASSGLASS | PASSGRILLE
embed = 0

View File

@@ -54,7 +54,7 @@
update_icon()
return 1
/obj/item/weapon/gun/energy/get_next_projectile()
/obj/item/weapon/gun/energy/consume_next_projectile()
if(!power_supply) return null
if(!ispath(projectile_type)) return null
if(!power_supply.use(charge_cost)) return null

View File

@@ -35,16 +35,8 @@
if(ispath(magazine_type) && (load_method & MAGAZINE))
ammo_magazine = new magazine_type(src)
update_icon()
/obj/item/weapon/gun/projectile/can_fire()
var/obj/item/ammo_casing/C
if(loaded.len)
C = loaded[1]
else if(ammo_magazine && ammo_magazine.stored_ammo.len)
C = ammo_magazine.stored_ammo[1]
return (C && C.BB)
/obj/item/weapon/gun/projectile/get_next_projectile()
/obj/item/weapon/gun/projectile/consume_next_projectile()
//store the next ammo_casing in a var so that handle_post_fire() knows which one to eject
//also we might as well remove chambered here, so that we don't have to figure out where it came from later
if(loaded.len)

View File

@@ -66,19 +66,13 @@
if(cell && severity)
cell.use(100*severity)
/obj/item/weapon/gun/launcher/crossbow/special_check(user)
if(tension <= 0)
user << "\red \The [src] is not drawn back!"
return 0
return 1
/obj/item/weapon/gun/launcher/crossbow/update_release_force()
release_force = tension*release_speed
/obj/item/weapon/gun/launcher/crossbow/can_fire()
return (tension && bolt)
/obj/item/weapon/gun/launcher/crossbow/get_next_projectile()
/obj/item/weapon/gun/launcher/crossbow/consume_next_projectile(mob/user=null)
if(tension <= 0)
user << "\red \The [src] is not drawn back!"
return null
return bolt
/obj/item/weapon/gun/launcher/crossbow/handle_post_fire(mob/user, atom/target)

View File

@@ -86,16 +86,19 @@
user << "There is nothing to remove in \the [src]."
return
/obj/item/weapon/gun/launcher/pneumatic/get_next_projectile()
/obj/item/weapon/gun/launcher/pneumatic/consume_next_projectile(mob/user=null)
if(!contents.len)
return null
return contents[1]
if (!tank)
user << "There is no gas tank in [src]!"
return null
/obj/item/weapon/gun/launcher/pneumatic/can_fire()
if(!contents.len)
return 0
var/fire_pressure = (tank.air_contents.return_pressure()/100)*pressure_setting
return (fire_pressure >= minimum_tank_pressure)
if(fire_pressure < minimum_tank_pressure)
user << "There isn't enough gas in the tank to fire [src]."
return null
return contents[1]
/obj/item/weapon/gun/launcher/pneumatic/examine(mob/user)
if(!..(user, 2))
@@ -106,18 +109,6 @@
else
user << "Nothing is attached to the tank valve!"
/obj/item/weapon/gun/launcher/pneumatic/special_check(user)
if (!tank)
user << "There is no gas tank in [src]!"
return 0
fire_pressure = (tank.air_contents.return_pressure()/100)*pressure_setting
if (fire_pressure < minimum_tank_pressure)
user << "There isn't enough gas in the tank to fire [src]."
return 0
return ..()
/obj/item/weapon/gun/launcher/pneumatic/update_release_force(obj/item/projectile)
if(tank)
release_force = ((fire_pressure*tank.volume)/projectile.w_class)/force_divisor //projectile speed.

View File

@@ -81,88 +81,3 @@
caliber = "38"
desc = initial(desc)
user << "<span class='warning'>You remove the modifications on [src]! Now it will fire .38 rounds.</span>"
/*
// A gun to play Russian Roulette!
// You can spin the chamber to randomize the position of the bullet.
/obj/item/weapon/gun/projectile/russian
name = "\improper Russian revolver"
desc = "A Russian made revolver. Uses .357 ammo. It has a single slot in it's chamber for a bullet."
max_shells = 6
origin_tech = "combat=2;materials=2"
/obj/item/weapon/gun/projectile/russian/New()
Spin()
update_icon()
/obj/item/weapon/gun/projectile/russian/proc/Spin()
for(var/obj/item/ammo_casing/AC in loaded)
del(AC)
loaded = list()
var/random = rand(1, max_shells)
for(var/i = 1; i <= max_shells; i++)
if(i != random)
loaded += i // Basically null
else
loaded += new ammo_type(src)
/obj/item/weapon/gun/projectile/russian/attackby(var/obj/item/A as obj, mob/user as mob)
if(!A) return
var/num_loaded = 0
if(istype(A, /obj/item/ammo_magazine))
if((load_method == MAGAZINE) && loaded.len) return
var/obj/item/ammo_magazine/AM = A
for(var/obj/item/ammo_casing/AC in AM.stored_ammo)
if(getAmmo() > 0 || loaded.len >= max_shells)
break
if(AC.caliber == caliber && loaded.len < max_shells)
AC.loc = src
AM.stored_ammo -= AC
loaded += AC
num_loaded++
break
A.update_icon()
if(num_loaded)
user.visible_message("<span class='warning'>[user] loads a single bullet into the revolver and spins the chamber.</span>", "<span class='warning'>You load a single bullet into the chamber and spin it.</span>")
else
user.visible_message("<span class='warning'>[user] spins the chamber of the revolver.</span>", "<span class='warning'>You spin the revolver's chamber.</span>")
if(getAmmo() > 0)
Spin()
update_icon()
return
/obj/item/weapon/gun/projectile/russian/attack_self(mob/user as mob)
user.visible_message("<span class='warning'>[user] spins the chamber of the revolver.</span>", "<span class='warning'>You spin the revolver's chamber.</span>")
if(getAmmo() > 0)
Spin()
/obj/item/weapon/gun/projectile/russian/attack(atom/target as mob|obj|turf|area, mob/living/user as mob|obj)
if(!loaded.len)
user.visible_message("\red *click*", "\red *click*")
playsound(user, 'sound/weapons/empty.ogg', 100, 1)
return
if(isliving(target) && isliving(user))
if(target == user)
var/datum/organ/external/affecting = user.zone_sel.selecting
if(affecting == "head")
var/obj/item/ammo_casing/AC = loaded[1]
if(!load_into_chamber())
user.visible_message("\red *click*", "\red *click*")
playsound(user, 'sound/weapons/empty.ogg', 100, 1)
return
if(!in_chamber)
return
var/obj/item/projectile/P = new AC.projectile_type
playsound(user, fire_sound, 50, 1)
user.visible_message("<span class='danger'>[user.name] fires [src] at \his head!</span>", "<span class='danger'>You fire [src] at your head!</span>", "You hear a [istype(in_chamber, /obj/item/projectile/beam) ? "laser blast" : "gunshot"]!")
if(!P.nodamage)
user.apply_damage(300, BRUTE, affecting, sharp=1) // You are dead, dead, dead.
return
..()
*/

View File

@@ -33,10 +33,7 @@
else
usr << "\red [src] cannot hold more rockets."
/obj/item/weapon/gun/launcher/rocket/can_fire()
return rockets.len
/obj/item/weapon/gun/launcher/rocket/get_next_projectile()
/obj/item/weapon/gun/launcher/rocket/consume_next_projectile()
if(rockets.len)
var/obj/item/ammo_casing/rocket/I = rockets[1]
var/obj/item/missile/M = new (src)

View File

@@ -15,10 +15,7 @@
handle_casings = HOLD_CASINGS
var/recentpump = 0 // to prevent spammage
/obj/item/weapon/gun/projectile/shotgun/pump/can_fire()
return (chambered && chambered.BB)
/obj/item/weapon/gun/projectile/shotgun/pump/get_next_projectile()
/obj/item/weapon/gun/projectile/shotgun/pump/consume_next_projectile()
if(chambered)
return chambered.BB
return null

View File

@@ -37,7 +37,7 @@
var/damage_type = BRUTE //BRUTE, BURN, TOX, OXY, CLONE are the only things that should be in here
var/nodamage = 0 //Determines if the projectile will skip any damage inflictions
var/taser_effect = 0 //If set then the projectile will apply it's agony damage using stun_effect_act() to mobs it hits, and other damage will be ignored
var/flag = "bullet" //Defines what armor to use when it hits things. Must be set to bullet, laser, energy,or bomb //Cael - bio and rad are also valid
var/check_armour = "bullet" //Defines what armor to use when it hits things. Must be set to bullet, laser, energy,or bomb //Cael - bio and rad are also valid
var/projectile_type = /obj/item/projectile
var/penetrating = 0 //If greater than zero, the projectile will pass through dense objects as specified by on_penetrate()
var/kill_count = 50 //This will de-increment every process(). When 0, it will delete the projectile.
@@ -70,16 +70,7 @@
return 1
/obj/item/projectile/proc/check_fire(atom/target as mob, var/mob/living/user as mob) //Checks if you can hit them or not.
if(!istype(target) || !istype(user))
return 0
var/obj/item/projectile/test/trace = new /obj/item/projectile/test(get_step_to(user,target)) //Making the test....
trace.target = target
trace.flags = flags //Set the flags...
trace.pass_flags = pass_flags //And the pass flags to that of the real projectile...
trace.firer = user
var/output = trace.process() //Test it!
del(trace) //No need for it anymore
return output //Send it back to the gun!
check_trajectory(target, user, pass_flags, flags)
//sets the click point of the projectile using mouse input params
/obj/item/projectile/proc/set_clickpoint(var/params)
@@ -293,3 +284,16 @@
M = locate() in get_step(src,target)
if(istype(M))
return 1
/proc/check_trajectory(atom/target as mob, var/mob/living/user as mob, var/pass_flags=PASSTABLE|PASSGLASS|PASSGRILLE, flags=null) //Checks if you can hit them or not.
if(!istype(target) || !istype(user))
return 0
var/obj/item/projectile/test/trace = new /obj/item/projectile/test(get_step_to(user,target)) //Making the test....
trace.target = target
if(!isnull(flags))
trace.flags = flags //Set the flags...
trace.pass_flags = pass_flags //And the pass flags to that of the real projectile...
trace.firer = user
var/output = trace.process() //Test it!
del(trace) //No need for it anymore
return output //Send it back to the gun!

View File

@@ -4,7 +4,7 @@
damage = 0
damage_type = BURN
nodamage = 1
flag = "energy"
check_armour = "energy"
/obj/item/projectile/animate/Bump(var/atom/change)
if((istype(change, /obj/item) || istype(change, /obj/structure)) && !is_type_in_list(change, protected_objects))

View File

@@ -14,7 +14,7 @@ var/list/beam_master = list()
pass_flags = PASSTABLE | PASSGLASS | PASSGRILLE
damage = 40
damage_type = BURN
flag = "laser"
check_armour = "laser"
eyeblur = 4
var/frequency = 1
@@ -87,7 +87,7 @@ var/list/beam_master = list()
pass_flags = PASSTABLE | PASSGLASS | PASSGRILLE
damage = 0
damage_type = BURN
flag = "laser"
check_armour = "laser"
eyeblur = 2
/obj/item/projectile/beam/heavylaser
@@ -121,7 +121,7 @@ var/list/beam_master = list()
pass_flags = PASSTABLE | PASSGLASS | PASSGRILLE
damage = 0
damage_type = BURN
flag = "laser"
check_armour = "laser"
/obj/item/projectile/beam/lastertag/blue/on_hit(var/atom/target, var/blocked = 0)
if(istype(target, /mob/living/carbon/human))
@@ -136,7 +136,7 @@ var/list/beam_master = list()
pass_flags = PASSTABLE | PASSGLASS | PASSGRILLE
damage = 0
damage_type = BURN
flag = "laser"
check_armour = "laser"
/obj/item/projectile/beam/lastertag/red/on_hit(var/atom/target, var/blocked = 0)
if(istype(target, /mob/living/carbon/human))
@@ -151,7 +151,7 @@ var/list/beam_master = list()
pass_flags = PASSTABLE | PASSGLASS | PASSGRILLE
damage = 0
damage_type = BURN
flag = "laser"
check_armour = "laser"
/obj/item/projectile/beam/lastertag/omni/on_hit(var/atom/target, var/blocked = 0)
if(istype(target, /mob/living/carbon/human))

View File

@@ -4,7 +4,7 @@
damage = 60
damage_type = BRUTE
nodamage = 0
flag = "bullet"
check_armour = "bullet"
embed = 1
sharp = 1

View File

@@ -4,7 +4,7 @@
damage = 0
damage_type = BURN
nodamage = 1
flag = "energy"
check_armour = "energy"
on_hit(var/atom/change)
wabbajack(change)

View File

@@ -3,7 +3,7 @@
icon_state = "spark"
damage = 0
damage_type = BURN
flag = "energy"
check_armour = "energy"
//releases a very short burst of light on impact, mainly used to blind people

View File

@@ -3,7 +3,7 @@
icon = 'icons/obj/projectiles.dmi'
icon_state = "ice_1"
damage = 20
flag = "energy"
check_armour = "energy"
/obj/item/projectile/forcebolt/strong
name = "force bolt"

View File

@@ -4,7 +4,7 @@
damage = 0
damage_type = BURN
nodamage = 1
flag = "energy"
check_armour = "energy"
on_hit(var/atom/target, var/blocked = 0)
@@ -16,7 +16,7 @@
name ="explosive bolt"
icon_state= "bolter"
damage = 50
flag = "bullet"
check_armour = "bullet"
sharp = 1
edge = 1
@@ -30,7 +30,7 @@
damage = 0
damage_type = BURN
nodamage = 1
flag = "energy"
check_armour = "energy"
var/temperature = 300
@@ -47,7 +47,7 @@
damage = 0
damage_type = BRUTE
nodamage = 1
flag = "bullet"
check_armour = "bullet"
Bump(atom/A as mob|obj|turf|area)
if(A == firer)
@@ -76,7 +76,7 @@
damage = 0
damage_type = TOX
nodamage = 1
flag = "energy"
check_armour = "energy"
on_hit(var/atom/target, var/blocked = 0)
var/mob/living/M = target
@@ -115,7 +115,7 @@
damage = 0
damage_type = TOX
nodamage = 1
flag = "energy"
check_armour = "energy"
on_hit(var/atom/target, var/blocked = 0)
var/mob/M = target