From 53affb4e44634eb19b86731c5fd231134a77c96b Mon Sep 17 00:00:00 2001 From: HarpyEagle Date: Tue, 14 Jul 2015 17:14:55 -0400 Subject: [PATCH 1/2] Projectile cleanup Moves projectile trajectory related setup into setup_trajectory(), removes redundant target var on test projectiles. --- code/modules/projectiles/projectile.dm | 59 +++++++++++++------------- 1 file changed, 29 insertions(+), 30 deletions(-) diff --git a/code/modules/projectiles/projectile.dm b/code/modules/projectiles/projectile.dm index 6d8c40c16c2..a8b7aa44411 100644 --- a/code/modules/projectiles/projectile.dm +++ b/code/modules/projectiles/projectile.dm @@ -26,7 +26,7 @@ var/xo = null var/current = null var/obj/shot_from = null // the object which shot us - var/atom/original = null // the original target clicked + var/atom/original = null // the target clicked (not necessarily where the projectile is headed). Should probably be renamed to 'target' or something. var/turf/starting = null // the projectile's starting turf var/list/permutated = list() // we've passed through these atoms, don't try to hit them again @@ -133,30 +133,25 @@ original = target loc = curloc - starting = curloc - current = curloc - yo = targloc.y - curloc.y + y_offset - xo = targloc.x - curloc.x + x_offset shot_from = launcher silenced = launcher.silenced spawn() + setup_trajectory(curloc, targloc, x_offset, y_offset) //plot the initial trajectory process() return 0 //Used to change the direction of the projectile in flight. /obj/item/projectile/proc/redirect(var/new_x, var/new_y, var/atom/starting_loc, var/mob/new_firer=null) - original = locate(new_x, new_y, src.z) - starting = starting_loc - current = starting_loc + var/turf/new_target = locate(new_x, new_y, src.z) + + original = new_target if(new_firer) firer = src - yo = new_y - starting_loc.y - xo = new_x - starting_loc.x - setup_trajectory() + setup_trajectory(starting_loc, new_target) //Called when the projectile intercepts a mob. Returns 1 if the projectile hit the mob, 0 if it missed and should keep flying. /obj/item/projectile/proc/attack_mob(var/mob/living/target_mob, var/distance, var/miss_modifier=0) @@ -275,9 +270,6 @@ /obj/item/projectile/process() var/first_step = 1 - //plot the initial trajectory - setup_trajectory() - spawn while(src && src.loc) if(kill_count-- < 1) on_impact(src.loc) //for any final impact behaviours @@ -320,7 +312,13 @@ /obj/item/projectile/proc/before_move() return -/obj/item/projectile/proc/setup_trajectory() +/obj/item/projectile/proc/setup_trajectory(turf/startloc, turf/targloc, var/x_offset = 0, var/y_offset = 0) + // setup projectile state + starting = startloc + current = startloc + yo = targloc.y - curloc.y + y_offset + xo = targloc.x - curloc.x + x_offset + // trajectory dispersion var/offset = 0 if(dispersion) @@ -379,9 +377,12 @@ invisibility = 101 //Nope! Can't see me! yo = null xo = null - var/target = null var/result = 0 //To pass the message back to the gun. +/obj/item/projectile/test/New(var/newloc, atom/target) + ..(newloc) + original = target + /obj/item/projectile/test/Bump(atom/A as mob|obj|turf|area) if(A == firer) loc = A.loc @@ -396,23 +397,18 @@ /obj/item/projectile/test/process() var/turf/curloc = get_turf(src) - var/turf/targloc = get_turf(target) + var/turf/targloc = get_turf(original) if(!curloc || !targloc) return 0 - yo = targloc.y - curloc.y - xo = targloc.x - curloc.x - target = targloc - original = target - starting = curloc //plot the initial trajectory - setup_trajectory() + setup_trajectory(curloc, targloc) while(src) //Loop on through! if(result) return (result - 1) - if((!( target ) || loc == target)) - target = locate(min(max(x + xo, 1), world.maxx), min(max(y + yo, 1), world.maxy), z) //Finding the target turf at map edge + if((!( targloc ) || loc == targloc)) + targloc = locate(min(max(x + xo, 1), world.maxx), min(max(y + yo, 1), world.maxy), z) //Finding the target turf at map edge trajectory.increment() // increment the current location location = trajectory.return_location(location) // update the locally stored location data @@ -423,18 +419,21 @@ if(istype(M)) //If there is someting living... return 1 //Return 1 else - M = locate() in get_step(src,target) + M = locate() in get_step(src,targloc) if(istype(M)) return 1 /proc/check_trajectory(atom/target as mob|obj, atom/firer as mob|obj, var/pass_flags=PASSTABLE|PASSGLASS|PASSGRILLE, flags=null) //Checks if you can hit them or not. if(!istype(target) || !istype(firer)) return 0 - var/obj/item/projectile/test/trace = new /obj/item/projectile/test(get_turf(firer)) //Making the test.... - trace.target = target + + var/obj/item/projectile/test/trace = new /obj/item/projectile/test(get_turf(firer), target) //Making the test.... + + //Set the flags and pass flags to that of the real projectile... 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.flags = flags + trace.pass_flags = pass_flags + var/output = trace.process() //Test it! qdel(trace) //No need for it anymore return output //Send it back to the gun! From 8cbd14c1a5c5a786094009281986c70435d37c1f Mon Sep 17 00:00:00 2001 From: HarpyEagle Date: Tue, 14 Jul 2015 17:49:50 -0400 Subject: [PATCH 2/2] Splits up projectile/launch() --- code/modules/projectiles/gun.dm | 2 +- code/modules/projectiles/projectile.dm | 60 ++++++++++++++------------ 2 files changed, 34 insertions(+), 28 deletions(-) diff --git a/code/modules/projectiles/gun.dm b/code/modules/projectiles/gun.dm index 14e70bcfa44..235c759acd8 100644 --- a/code/modules/projectiles/gun.dm +++ b/code/modules/projectiles/gun.dm @@ -311,7 +311,7 @@ y_offset = rand(-1,1) x_offset = rand(-1,1) - return !P.launch(target, user, src, target_zone, x_offset, y_offset) + return !P.launch_from_gun(target, user, src, target_zone, x_offset, y_offset) //Suicide handling. /obj/item/weapon/gun/var/mouthshoot = 0 //To stop people from suiciding twice... >.> diff --git a/code/modules/projectiles/projectile.dm b/code/modules/projectiles/projectile.dm index a8b7aa44411..b9ba2ba0df2 100644 --- a/code/modules/projectiles/projectile.dm +++ b/code/modules/projectiles/projectile.dm @@ -110,21 +110,13 @@ p_x = between(0, p_x + rand(-radius, radius), world.icon_size) p_y = between(0, p_y + rand(-radius, radius), world.icon_size) -//called to launch a projectile from a gun -/obj/item/projectile/proc/launch(atom/target, mob/user, obj/item/weapon/gun/launcher, var/target_zone, var/x_offset=0, var/y_offset=0) - var/turf/curloc = get_turf(user) +//called to launch a projectile +/obj/item/projectile/proc/launch(atom/target, var/target_zone, var/x_offset=0, var/y_offset=0) + var/turf/curloc = get_turf(src) var/turf/targloc = get_turf(target) if (!istype(targloc) || !istype(curloc)) return 1 - firer = user - def_zone = target_zone - - if(user == target) //Shooting yourself - user.bullet_act(src, target_zone) - on_impact(user) - qdel(src) - return 0 if(targloc == curloc) //Shooting something in the same turf target.bullet_act(src, target_zone) on_impact(target) @@ -132,10 +124,7 @@ return 0 original = target - loc = curloc - - shot_from = launcher - silenced = launcher.silenced + def_zone = target_zone spawn() setup_trajectory(curloc, targloc, x_offset, y_offset) //plot the initial trajectory @@ -143,6 +132,22 @@ return 0 +//called to launch a projectile from a gun +/obj/item/projectile/proc/launch_from_gun(atom/target, mob/user, obj/item/weapon/gun/launcher, var/target_zone, var/x_offset=0, var/y_offset=0) + if(user == target) //Shooting yourself + user.bullet_act(src, target_zone) + on_impact(user) + qdel(src) + return 0 + + loc = get_turf(user) //move the projectile out into the world + + firer = user + shot_from = launcher + silenced = launcher.silenced + + return launch(target, target_zone, x_offset, y_offset) + //Used to change the direction of the projectile in flight. /obj/item/projectile/proc/redirect(var/new_x, var/new_y, var/atom/starting_loc, var/mob/new_firer=null) var/turf/new_target = locate(new_x, new_y, src.z) @@ -316,8 +321,8 @@ // setup projectile state starting = startloc current = startloc - yo = targloc.y - curloc.y + y_offset - xo = targloc.x - curloc.x + x_offset + yo = targloc.y - startloc.y + y_offset + xo = targloc.x - startloc.x + x_offset // trajectory dispersion var/offset = 0 @@ -379,10 +384,6 @@ xo = null var/result = 0 //To pass the message back to the gun. -/obj/item/projectile/test/New(var/newloc, atom/target) - ..(newloc) - original = target - /obj/item/projectile/test/Bump(atom/A as mob|obj|turf|area) if(A == firer) loc = A.loc @@ -395,15 +396,19 @@ result = 1 return -/obj/item/projectile/test/process() +/obj/item/projectile/test/launch(atom/target) var/turf/curloc = get_turf(src) - var/turf/targloc = get_turf(original) + var/turf/targloc = get_turf(target) if(!curloc || !targloc) return 0 - + + original = target + //plot the initial trajectory setup_trajectory(curloc, targloc) + return process(targloc) +/obj/item/projectile/test/process(var/turf/targloc) while(src) //Loop on through! if(result) return (result - 1) @@ -423,17 +428,18 @@ if(istype(M)) return 1 -/proc/check_trajectory(atom/target as mob|obj, atom/firer as mob|obj, var/pass_flags=PASSTABLE|PASSGLASS|PASSGRILLE, flags=null) //Checks if you can hit them or not. +//Helper proc to check if you can hit them or not. +/proc/check_trajectory(atom/target as mob|obj, atom/firer as mob|obj, var/pass_flags=PASSTABLE|PASSGLASS|PASSGRILLE, flags=null) if(!istype(target) || !istype(firer)) return 0 - var/obj/item/projectile/test/trace = new /obj/item/projectile/test(get_turf(firer), target) //Making the test.... + var/obj/item/projectile/test/trace = new /obj/item/projectile/test(get_turf(firer)) //Making the test.... //Set the flags and pass flags to that of the real projectile... if(!isnull(flags)) trace.flags = flags trace.pass_flags = pass_flags - var/output = trace.process() //Test it! + var/output = trace.launch(target) //Test it! qdel(trace) //No need for it anymore return output //Send it back to the gun!