From 38c4b88ded9bcac1c2aa86a1a31178ec025ae02b Mon Sep 17 00:00:00 2001 From: Anewbe Date: Thu, 21 Feb 2019 12:49:00 -0600 Subject: [PATCH] BTW I USE (FIXED) ARC --- code/modules/mob/living/simple_mob/combat.dm | 28 ++++- .../mob/living/simple_mob/simple_mob.dm | 2 + code/modules/projectiles/projectile.dm | 75 +++++++++---- code/modules/projectiles/projectile/arc.dm | 100 +++++++++++++++++- 4 files changed, 179 insertions(+), 26 deletions(-) diff --git a/code/modules/mob/living/simple_mob/combat.dm b/code/modules/mob/living/simple_mob/combat.dm index 8cb60cd1773..0f3205fb8c2 100644 --- a/code/modules/mob/living/simple_mob/combat.dm +++ b/code/modules/mob/living/simple_mob/combat.dm @@ -127,9 +127,12 @@ // Otherwise default to the mob's firing sound. playsound(src, P.fire_sound ? P.fire_sound : projectilesound, 80, 1) - P.firer = src // So we can't shoot ourselves. - P.old_style_target(A, src) - P.fire() + // For some reason there isn't an argument for accuracy, so access the projectile directly instead. + // Also, placing dispersion here instead of in forced_spread will randomize the chosen angle between dispersion and -dispersion in fire() instead of having to do that here. + P.accuracy += calculate_accuracy() + P.dispersion += calculate_dispersion() + + P.launch_projectile(target = A, target_zone = null, user = src, params = null, angle_override = null, forced_spread = 0) if(needs_reload) reload_count++ @@ -149,6 +152,25 @@ . = FALSE set_AI_busy(FALSE) +/mob/living/simple_mob/proc/calculate_dispersion() + . = projectile_dispersion // Start with the basic var. + + // Some modifiers change dispersion. This makes simple_mobs respect that. + for(var/datum/modifier/M in modifiers) + if(!isnull(M.accuracy_dispersion)) + . += M.accuracy_dispersion + + // Make sure we don't go under zero dispersion. + . = max(., 0) + +/mob/living/simple_mob/proc/calculate_accuracy() + . = projectile_accuracy // Start with the basic var. + + // Some modifiers make it harder or easier to hit things. + for(var/datum/modifier/M in modifiers) + if(!isnull(M.accuracy)) + . += M.accuracy + // Can we currently do a special attack? /mob/living/simple_mob/proc/can_special_attack(atom/A) // Validity check. diff --git a/code/modules/mob/living/simple_mob/simple_mob.dm b/code/modules/mob/living/simple_mob/simple_mob.dm index 9ad2ec58bef..ed012264906 100644 --- a/code/modules/mob/living/simple_mob/simple_mob.dm +++ b/code/modules/mob/living/simple_mob/simple_mob.dm @@ -82,6 +82,8 @@ //Attack ranged settings var/projectiletype // The projectiles I shoot var/projectilesound // The sound I make when I do it + var/projectile_accuracy = 0 // Accuracy modifier to add onto the bullet when its fired. + var/projectile_dispersion = 0 // How many degrees to vary when I do it. var/casingtype // What to make the hugely laggy casings pile out of // Reloading settings, part of ranged code diff --git a/code/modules/projectiles/projectile.dm b/code/modules/projectiles/projectile.dm index 1d67ebb3d86..bbfb1c33375 100644 --- a/code/modules/projectiles/projectile.dm +++ b/code/modules/projectiles/projectile.dm @@ -207,12 +207,14 @@ animate(src, pixel_x = trajectory.return_px(), pixel_y = trajectory.return_py(), time = 1, flags = ANIMATION_END_NOW) Range() -/obj/item/projectile/Crossed(atom/movable/AM) //A mob moving on a tile with a projectile is hit by it. - ..() - if(isliving(AM) && !(pass_flags & PASSMOB)) - var/mob/living/L = AM - if(can_hit_target(L, permutated, (AM == original))) - Bump(AM) +//sets the click point of the projectile using mouse input params +/obj/item/projectile/proc/set_clickpoint(var/params) + var/list/mouse_control = params2list(params) + if(mouse_control["icon-x"]) + p_x = text2num(mouse_control["icon-x"]) + if(mouse_control["icon-y"]) + p_y = text2num(mouse_control["icon-y"]) +<<<<<<< HEAD /obj/item/projectile/proc/process_homing() //may need speeding up in the future performance wise. if(!homing_target) @@ -317,21 +319,52 @@ START_PROCESSING(SSprojectiles, src) pixel_move(1, FALSE) //move it now! -/obj/item/projectile/Move(atom/newloc, dir = NONE) - . = ..() - if(.) - if(temporary_unstoppable_movement) - temporary_unstoppable_movement = FALSE - DISABLE_BITFIELD(movement_type, UNSTOPPABLE) - if(fired && can_hit_target(original, permutated, TRUE)) - Bump(original) +======= + if(mouse_control["screen-loc"]) + //Split screen-loc up into X+Pixel_X and Y+Pixel_Y + var/list/screen_loc_params = splittext(mouse_control["screen-loc"], ",") + + //Split X+Pixel_X up into list(X, Pixel_X) + var/list/screen_loc_X = splittext(screen_loc_params[1],":") + + //Split Y+Pixel_Y up into list(Y, Pixel_Y) + var/list/screen_loc_Y = splittext(screen_loc_params[2],":") + var/x = text2num(screen_loc_X[1]) * 32 + text2num(screen_loc_X[2]) - 32 + var/y = text2num(screen_loc_Y[1]) * 32 + text2num(screen_loc_Y[2]) - 32 + + //Calculate the "resolution" of screen based on client's view and world's icon size. This will work if the user can view more tiles than average. + var/list/screenview = user.client? getviewsize(user.client.view) : world.view + var/screenviewX = screenview[1] * world.icon_size + var/screenviewY = screenview[2] * world.icon_size + + var/ox = round(screenviewX/2) - user.client.pixel_x //"origin" x + var/oy = round(screenviewY/2) - user.client.pixel_y //"origin" y + angle = ATAN2(y - oy, x - ox) + return list(angle, p_x, p_y) + +/obj/item/projectile/proc/redirect(x, y, starting, source) + old_style_target(locate(x, y, z), starting? get_turf(starting) : get_turf(source)) + +/obj/item/projectile/proc/old_style_target(atom/target, atom/source) + if(!source) + source = get_turf(src) + starting = get_turf(source) +>>>>>>> f083fba... Merge pull request #5977 from Neerti/btw_i_use_fixed_arc + original = target + def_zone = target_zone /obj/item/projectile/proc/after_z_change(atom/olcloc, atom/newloc) /obj/item/projectile/proc/before_z_change(atom/oldloc, atom/newloc) -/obj/item/projectile/proc/before_move() - return +<<<<<<< HEAD +//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 /obj/item/projectile/proc/after_move() return @@ -382,8 +415,14 @@ //Split screen-loc up into X+Pixel_X and Y+Pixel_Y var/list/screen_loc_params = splittext(mouse_control["screen-loc"], ",") - //Split X+Pixel_X up into list(X, Pixel_X) - var/list/screen_loc_X = splittext(screen_loc_params[1],":") +//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) + if(!istype(target_mob)) +======= +/obj/item/projectile/proc/generate_hitscan_tracers(cleanup = TRUE, duration = 5, impacting = TRUE) + if(!length(beam_segments)) +>>>>>>> f083fba... Merge pull request #5977 from Neerti/btw_i_use_fixed_arc + return //Split Y+Pixel_Y up into list(Y, Pixel_Y) var/list/screen_loc_Y = splittext(screen_loc_params[2],":") diff --git a/code/modules/projectiles/projectile/arc.dm b/code/modules/projectiles/projectile/arc.dm index ef61558518f..07e5ad1493a 100644 --- a/code/modules/projectiles/projectile/arc.dm +++ b/code/modules/projectiles/projectile/arc.dm @@ -9,11 +9,12 @@ /obj/item/projectile/arc name = "arcing shot" icon_state = "fireball" // WIP - speed = 2 // Travel a bit slower, to really sell the arc visuals. movement_type = UNSTOPPABLE plane = ABOVE_PLANE // Since projectiles are 'in the air', they might visually overlap mobs while in flight, so the projectile needs to be above their plane. - var/target_distance = null // How many tiles the impact site is. var/fired_dir = null // Which direction was the projectile fired towards. Needed to invert the projectile turning based on if facing left or right. + var/distance_to_fly = null // How far, in pixels, to fly for. Will call on_range() when this is passed. + var/visual_y_offset = -16 // Adjusts how high the projectile and its shadow start, visually. This is so the projectile and shadow align with the center of the tile. + var/projectile_speed_modifier = 0.5 // Slows it down to make the arcing more noticable, and improve pixel calculation accuracy. var/obj/effect/projectile_shadow/shadow = null // Visual indicator for the projectile's 'true' position. Needed due to being bound to two dimensions in reality. /obj/item/projectile/arc/Bump() @@ -27,6 +28,14 @@ QDEL_NULL(shadow) return ..() +<<<<<<< HEAD +/obj/item/projectile/arc/Bump(atom/A, forced=0) + return 0 +// if(get_turf(src) != original) +// return 0 +// else +// return ..() + // This is a test projectile in the sense that its testing the code to make sure it works, // as opposed to a 'can I hit this thing' projectile. /obj/item/projectile/arc/test/on_impact(turf/T) @@ -80,6 +89,78 @@ // Update our shadow. shadow.forceMove(loc) +======= + +/obj/item/projectile/arc/proc/calculate_initial_pixel_distance(atom/user, atom/target) + var/datum/point/A = new(user) + var/datum/point/B = new(target) + + // Set the pixel offsets if they exist. + A.x += (p_x - 16) + A.y += (p_y - 16) + + return pixel_length_between_points(A, B) + +/obj/item/projectile/arc/proc/distance_flown() + var/datum/point/current_point = new(src) + var/datum/point/starting_point = new(starting) + return pixel_length_between_points(current_point, starting_point) + +/obj/item/projectile/arc/on_range() + if(loc) + on_impact(loc) + return ..() + + +/obj/item/projectile/arc/launch_projectile(atom/target, target_zone, mob/user, params, angle_override, forced_spread = 0) + fired_dir = get_dir(user, target) // Used to determine if the projectile should turn in the air. + distance_to_fly = calculate_initial_pixel_distance(user, target) // Calculates how many pixels to travel before hitting the ground. + ..() // Does the actual launching. The projectile will be out after this. + +// For legacy. +/obj/item/projectile/arc/old_style_target(atom/target, atom/source) + ..() + fired_dir = get_dir(source, target) + distance_to_fly = calculate_initial_pixel_distance(source, target) + + +/obj/item/projectile/arc/fire(angle, atom/direct_target) + ..() // The trajectory must exist for set_pixel_speed() to work. + set_pixel_speed(projectile_speed_modifier) // Slows it down and makes the distance checking more accurate. + +/obj/item/projectile/arc/pixel_move(trajectory_multiplier, hitscanning = FALSE) + // Do the other important stuff first. + ..(trajectory_multiplier, hitscanning) + + // Test to see if its time to 'hit the ground'. + var/pixels_flown = distance_flown() + + if(pixels_flown >= distance_to_fly) + on_range() // This will also cause the projectile to be deleted. + + else + // Handle visual projectile turning in flight. + var/arc_progress = between(0, pixels_flown / distance_to_fly, 1) + var/new_visual_degree = LERP(45, 135, arc_progress) + + if(fired_dir & EAST) + adjust_rotation(new_visual_degree) + else if(fired_dir & WEST) + adjust_rotation(-new_visual_degree) + + // Now for the fake height. + var/arc_max_pixel_height = distance_to_fly / 2 + var/sine_position = arc_progress * 180 + var/pixel_z_position = (arc_max_pixel_height * sin(sine_position)) + visual_y_offset + animate(src, pixel_z = pixel_z_position, time = 1, flags = ANIMATION_END_NOW) + + // Update our shadow. + if(shadow) + shadow.forceMove(loc) + shadow.pixel_x = pixel_x + shadow.pixel_y = pixel_y + visual_y_offset + +>>>>>>> f083fba... Merge pull request #5977 from Neerti/btw_i_use_fixed_arc /obj/effect/projectile_shadow name = "shadow" @@ -87,11 +168,18 @@ icon = 'icons/obj/projectiles.dmi' icon_state = "arc_shadow" anchored = TRUE + animate_movement = 0 // Just like the projectile it's following. ////////////// // Subtypes ////////////// +// This is a test projectile in the sense that its testing the code to make sure it works, +// as opposed to a 'can I hit this thing' projectile. +/obj/item/projectile/arc/test/on_impact(turf/T) + new /obj/effect/explosion(T) + T.color = "#FF0000" + // Generic, Hivebot related /obj/item/projectile/arc/blue_energy name = "energy missile" @@ -99,6 +187,10 @@ damage = 15 damage_type = BURN +/obj/item/projectile/arc/blue_energy/on_impact(turf/T) + for(var/mob/living/L in T) + attack_mob(L) // Everything on the turf it lands gets hit. + // Fragmentation arc shot /obj/item/projectile/arc/fragmentation name = "fragmentation shot" @@ -125,11 +217,9 @@ /obj/item/projectile/arc/emp_blast/on_impact(turf/T) empulse(T, 2, 4, 7, 10) // Normal EMP grenade. - return ..() /obj/item/projectile/arc/emp_blast/weak/on_impact(turf/T) empulse(T, 1, 2, 3, 4) // Sec EMP grenade. - return ..() // Radiation arc shot /obj/item/projectile/arc/radioactive @@ -139,4 +229,4 @@ var/rad_power = 50 /obj/item/projectile/arc/radioactive/on_impact(turf/T) - radiation_repository.radiate(T, rad_power) \ No newline at end of file + radiation_repository.radiate(T, rad_power)