Skip to content

Commit

Permalink
tank mostly functional
Browse files Browse the repository at this point in the history
  • Loading branch information
Doubleumc committed Nov 4, 2023
1 parent 581ec52 commit 01872ae
Show file tree
Hide file tree
Showing 13 changed files with 169 additions and 113 deletions.
83 changes: 60 additions & 23 deletions code/modules/vehicles/hardpoints/hardpoint.dm
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,9 @@
///Current selected firemode of the gun.
var/gun_firemode = GUN_FIREMODE_SEMIAUTO
///List of allowed firemodes.
var/list/gun_firemode_list = list()
var/list/gun_firemode_list = list(
GUN_FIREMODE_SEMIAUTO,
)

//Semi-auto and full-auto.
///For regular shots, how long to wait before firing again. Use modify_fire_delay and set_fire_delay instead of modifying this on the fly
Expand All @@ -128,16 +130,18 @@

//Firing cooldown.
///When it was last fired, related to world.time.
var/last_fired = 0
//var/last_fired = 0
///Fire delay of last firemode used.
var/last_delay = 0
//var/last_delay = 0
COOLDOWN_DECLARE(fire_cooldown)

/// Currently selected target to fire at. Set with set_target()
VAR_PRIVATE/atom/target
/// Current operator (crew) of the hardpoint.
VAR_PRIVATE/mob/hp_operator

var/empty_alarm = 'sound/weapons/hmg_eject_mag.ogg'
var/shots_fired = 0

//-----------------------------
//------GENERAL PROCS----------
Expand Down Expand Up @@ -355,10 +359,12 @@
to_chat(user, SPAN_WARNING("<b>\The [name] is broken!</b>"))
return FALSE

/* done in initiate_fire instead, as don't want to block continue_fire
if(world.time < next_use)
if(cooldown >= 20) //filter out guns with high firerate to prevent message spam.
to_chat(user, SPAN_WARNING("You need to wait [SPAN_HELPFUL((next_use - world.time) / 10)] seconds before [name] can be used again."))
return FALSE
*/

if(ammo && ammo.current_rounds <= 0)
to_chat(user, SPAN_WARNING("<b>\The [name] is out of ammo!</b> Magazines: <b>[SPAN_HELPFUL(LAZYLEN(backup_clips))]/[SPAN_HELPFUL(max_clips)]</b>"))
Expand All @@ -374,10 +380,12 @@

return TRUE

/*
//Called when you want to activate the hardpoint, by default firing a gun
//This can also be used for some type of temporary buff or toggling mode, up to you
/obj/item/hardpoint/proc/activate(mob/user, atom/A)
fire(user, A)
*/

/obj/item/hardpoint/proc/deactivate()
return
Expand Down Expand Up @@ -531,6 +539,7 @@
user.visible_message(SPAN_NOTICE("[user] stops repairing \the [name]."), SPAN_NOTICE("You stop repairing \the [name]. The integrity of the module is at [SPAN_HELPFUL(round(get_integrity_percent()))]%."))
return

/* allowed northwest firing when facing east, undesirable
//determines whether something is in firing arc of a hardpoint
/obj/item/hardpoint/proc/in_firing_arc(atom/A)
if(!owner)
Expand Down Expand Up @@ -567,7 +576,9 @@
angle += 180
return abs(angle) <= (firing_arc/2)
*/

/*
//doing last preparation before actually firing gun
/obj/item/hardpoint/proc/fire(mob/user, atom/A)
if(!ammo) //Prevents a runtime
Expand All @@ -585,7 +596,9 @@
fire_projectile(user, A)
to_chat(user, SPAN_WARNING("[name] Ammo: <b>[SPAN_HELPFUL(ammo ? ammo.current_rounds : 0)]/[SPAN_HELPFUL(ammo ? ammo.max_rounds : 0)]</b> | Mags: <b>[SPAN_HELPFUL(LAZYLEN(backup_clips))]/[SPAN_HELPFUL(max_clips)]</b>"))
*/

/*
//finally firing the gun
/obj/item/hardpoint/proc/fire_projectile(mob/user, atom/A)
set waitfor = 0
Expand All @@ -601,13 +614,15 @@
muzzle_flash(Get_Angle(origin_turf, A))
ammo.current_rounds--
*/

/// Setter proc to toggle burst firing
/obj/item/hardpoint/proc/set_burst_firing(burst = FALSE)
burst_firing = burst

///Clean all references
/obj/item/hardpoint/proc/reset_fire()
shots_fired = 0
set_auto_firing(FALSE)
set_target(null)

Expand Down Expand Up @@ -638,10 +653,6 @@
//to_chat(user, SPAN_DANGER("[ammo.current_rounds] / [ammo.max_rounds] ROUNDS REMAINING"))
to_chat(user, SPAN_WARNING("[name] Ammo: <b>[SPAN_HELPFUL(ammo ? ammo.current_rounds : 0)]/[SPAN_HELPFUL(ammo ? ammo.max_rounds : 0)]</b> | Mags: <b>[SPAN_HELPFUL(LAZYLEN(backup_clips))]/[SPAN_HELPFUL(max_clips)]</b>"))

/obj/item/hardpoint/proc/handle_ammo_out(mob/user)
visible_message(SPAN_NOTICE("[icon2html(src, viewers(src))] [src] beeps steadily and its ammo light blinks red."))
playsound(loc, empty_alarm, 25, 1)

/obj/item/hardpoint/proc/crew_mouseup(datum/source, atom/object, turf/location, control, params)
if(auto_firing || burst_firing)
SEND_SIGNAL(src, COMSIG_GUN_STOP_FIRE)
Expand Down Expand Up @@ -685,7 +696,12 @@

/obj/item/hardpoint/proc/initiate_fire(atom/target, mob/living/user, params)
//still actively firing
if(auto_firing || burst_firing || world.time < last_fired + last_delay)
if(auto_firing || burst_firing)
return NONE

if(!COOLDOWN_FINISHED(src, fire_cooldown))
if(max(fire_delay, burst_delay + extra_delay) >= 2.0 SECONDS) //filter out guns with high firerate to prevent message spam.
to_chat(user, SPAN_WARNING("You need to wait [SPAN_HELPFUL(COOLDOWN_SECONDSLEFT(src, fire_cooldown))] seconds before [name] can be used again."))
return NONE

switch(gun_firemode)
Expand All @@ -706,9 +722,13 @@
if(!target || !user)
return NONE

if(!can_activate(user, target)) //since it doesn't follow the multitile_interaction -> can_activate() pathway have to do it here
return NONE

return try_fire(target, user, params)

/obj/item/hardpoint/proc/try_fire(atom/target, mob/living/user, params)
/* currently checked by multitile_interaction doing can_activate() first
if(health <= 0)
to_chat(user, SPAN_WARNING("<b>\The [name] is broken!</b>"))
return NONE
Expand All @@ -720,44 +740,44 @@
if(!in_firing_arc(target))
to_chat(user, SPAN_WARNING("<b>The target is not within your firing arc!</b>"))
return NONE
*/

return fire_shot(target, user, params)

/obj/item/hardpoint/proc/fire_shot(atom/target, mob/living/user, params)
//offset fire origin from lower-left corner
var/turf/origin_turf = get_turf(src)
origin_turf = locate(origin_turf.x + origins[1], origin_turf.y + origins[2], origin_turf.z)
var/turf/origin_turf = get_origin_turf()

var/obj/projectile/projectile_to_fire = generate_bullet(user, origin_turf)
SEND_SIGNAL(projectile_to_fire, COMSIG_BULLET_USER_EFFECTS, user)

play_firing_sounds(projectile_to_fire, user)

INVOKE_ASYNC(projectile_to_fire, TYPE_PROC_REF(/obj/projectile, fire_at), target, user, src, projectile_to_fire.ammo.max_range, projectile_to_fire.ammo.shell_speed)
projectile_to_fire = null

ammo.current_rounds--
shots_fired++
play_firing_sounds()
if(use_muzzle_flash)
muzzle_flash(Get_Angle(origin_turf, target))

ammo.current_rounds--
//just ran out
if(ammo.current_rounds <= 0)
playsound(get_turf(src), empty_alarm, 70, 1)

//cooldown to respect intended ROF
last_fired = world.time
var/cooldown_time = 0
switch(gun_firemode)
if(GUN_FIREMODE_SEMIAUTO)
last_delay = fire_delay
cooldown_time = fire_delay
reset_fire()
display_ammo()
if(GUN_FIREMODE_BURSTFIRE)
last_delay = burst_delay + extra_delay
cooldown_time = burst_delay + extra_delay
if(GUN_FIREMODE_AUTOMATIC)
last_delay = fire_delay
cooldown_time = fire_delay
COOLDOWN_START(src, fire_cooldown, cooldown_time)

return AUTOFIRE_CONTINUE

/// Get turf at hardpoint origin position, used as the muzzle.
/obj/item/hardpoint/proc/get_origin_turf()
return get_offset_target_turf(get_turf(src), origins[1], origins[2])

/// Toggles the gun's firemode one down the list
/obj/item/hardpoint/proc/do_toggle_firemode(mob/user, new_firemode)
/*
Expand Down Expand Up @@ -795,10 +815,27 @@
else
playsound(src, 'sound/weapons/gun_empty.ogg', 25, 1, 5)

/obj/item/hardpoint/proc/play_firing_sounds(obj/projectile/projectile_to_fire, mob/user)
/obj/item/hardpoint/proc/play_firing_sounds()
if(LAZYLEN(activation_sounds))
playsound(get_turf(src), pick(activation_sounds), 60, 1)

/// Determines whether something is in firing arc of a hardpoint.
/obj/item/hardpoint/proc/in_firing_arc(atom/target)
if(!firing_arc || !ISINRANGE_EX(firing_arc, 0, 360))
return TRUE

var/turf/muzzle_turf = get_origin_turf()
var/turf/target_turf = get_turf(target)

var/angle_diff = SIMPLIFY_DEGREES(dir2angle(dir) - get_angle(muzzle_turf, target_turf))
if(angle_diff < -180)
angle_diff += 360
else if(angle_diff > 180)
angle_diff -= 360
//debug_msg("Get_Angle: [Get_Angle(muzzle_turf, target_turf)] get_angle: [get_angle(muzzle_turf, target_turf)] dir2angle: [dir2angle(dir)] angle_diff: [angle_diff]")

return abs(angle_diff) <= (firing_arc * 0.5)

//-----------------------------
//------ICON PROCS----------
//-----------------------------
Expand Down
39 changes: 39 additions & 0 deletions code/modules/vehicles/hardpoints/holder/tank_turret.dm
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,14 @@
// Used during the windup
var/rotating = FALSE

burst_amount = 2
burst_delay = 1.0 SECONDS
extra_delay = 13.0 SECONDS
gun_firemode = GUN_FIREMODE_BURSTFIRE
gun_firemode_list = list(
GUN_FIREMODE_BURSTFIRE,
)

/obj/item/hardpoint/holder/tank_turret/update_icon()
var/broken = (health <= 0)
icon_state = "tank_turret_[broken]"
Expand Down Expand Up @@ -182,6 +190,34 @@
user.client.pixel_x = -1 * AM.view_tile_offset * 32
user.client.pixel_y = 0

/obj/item/hardpoint/holder/tank_turret/try_fire(atom/target, mob/living/user, params)
var/turf/L
var/turf/R
switch(owner.dir)
if(NORTH)
L = locate(owner.x - 2, owner.y + 4, owner.z)
R = locate(owner.x + 2, owner.y + 4, owner.z)
if(SOUTH)
L = locate(owner.x + 2, owner.y - 4, owner.z)
R = locate(owner.x - 2, owner.y - 4, owner.z)
if(EAST)
L = locate(owner.x + 4, owner.y + 2, owner.z)
R = locate(owner.x + 4, owner.y - 2, owner.z)
else
L = locate(owner.x - 4, owner.y + 2, owner.z)
R = locate(owner.x - 4, owner.y - 2, owner.z)

if(shots_fired)
L = R

return fire_shot(L, user, params)

/obj/item/hardpoint/holder/tank_turret/get_origin_turf()
var/origin_turf = get_offset_target_turf(get_turf(src), origins[1], origins[2])
origin_turf = get_step(get_step(origin_turf, owner.dir), owner.dir) //this should get us tile in front of tank to prevent grenade being stuck under us.
return origin_turf

/*
/obj/item/hardpoint/holder/tank_turret/fire(mob/user, atom/A)
if(ammo.current_rounds <= 0)
return
Expand Down Expand Up @@ -215,7 +251,9 @@
fire_projectile(user, R)
to_chat(user, SPAN_WARNING("Smoke Screen uses left: <b>[SPAN_HELPFUL(ammo ? ammo.current_rounds / 2 : 0)]/[SPAN_HELPFUL(ammo ? ammo.max_rounds / 2 : 0)]</b> | Mags: <b>[SPAN_HELPFUL(LAZYLEN(backup_clips))]/[SPAN_HELPFUL(max_clips)]</b>"))
*/

/*
/obj/item/hardpoint/holder/tank_turret/fire_projectile(mob/user, atom/A)
set waitfor = 0
Expand All @@ -227,3 +265,4 @@
SEND_SIGNAL(P, COMSIG_BULLET_USER_EFFECTS, owner.seats[VEHICLE_GUNNER])
P.fire_at(A, owner.seats[VEHICLE_GUNNER], src, get_dist(origin_turf, A) + 1, P.ammo.shell_speed)
ammo.current_rounds--
*/
6 changes: 6 additions & 0 deletions code/modules/vehicles/hardpoints/primary/autocannon.dm
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,9 @@
"4" = list(32, 0),
"8" = list(-32, 0)
)

fire_delay = 0.7 SECONDS
gun_firemode = GUN_FIREMODE_AUTOMATIC
gun_firemode_list = list(
GUN_FIREMODE_AUTOMATIC,
)
2 changes: 1 addition & 1 deletion code/modules/vehicles/hardpoints/primary/dual_cannon.dm
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
fire_delay = 0.5 SECONDS
burst_amount = 2
burst_delay = 0.3 SECONDS
extra_delay = 0.4 SECONDS
extra_delay = 0.1 SECONDS
gun_firemode = GUN_FIREMODE_BURSTFIRE
gun_firemode_list = list(
GUN_FIREMODE_SEMIAUTO,
Expand Down
23 changes: 4 additions & 19 deletions code/modules/vehicles/hardpoints/primary/flamer.dm
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@

use_muzzle_flash = FALSE

fire_delay = 2.0 SECONDS

/obj/item/hardpoint/primary/flamer/set_bullet_traits()
..()
LAZYADD(traits_to_give, list(
Expand All @@ -36,26 +38,9 @@
if(!..())
return FALSE

var/turf/origin_turf = get_turf(src)
origin_turf = locate(origin_turf.x + origins[1], origin_turf.y + origins[2], origin_turf.z)
var/turf/origin_turf = get_origin_turf()
if(origin_turf == get_turf(A))
to_chat(user, SPAN_WARNING("The target is too close."))
return FALSE

return TRUE

/obj/item/hardpoint/primary/flamer/fire_projectile(mob/user, atom/A)
set waitfor = 0

var/turf/origin_turf = get_turf(src)
origin_turf = locate(origin_turf.x + origins[1], origin_turf.y + origins[2], origin_turf.z)

var/range = get_dist(origin_turf, A) + 1

var/obj/projectile/P = generate_bullet(user, origin_turf)
SEND_SIGNAL(P, COMSIG_BULLET_USER_EFFECTS, owner.seats[VEHICLE_GUNNER])
P.fire_at(A, owner.seats[VEHICLE_GUNNER], src, range < P.ammo.max_range ? range : P.ammo.max_range, P.ammo.shell_speed)

if(use_muzzle_flash)
muzzle_flash(Get_Angle(owner, A))

ammo.current_rounds--
6 changes: 6 additions & 0 deletions code/modules/vehicles/hardpoints/primary/ltb.dm
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,9 @@
"4" = list(89, -4),
"8" = list(-89, -4)
)

fire_delay = 20.0 SECONDS
gun_firemode = GUN_FIREMODE_SEMIAUTO
gun_firemode_list = list(
GUN_FIREMODE_SEMIAUTO,
)
12 changes: 12 additions & 0 deletions code/modules/vehicles/hardpoints/primary/minigun.dm
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,18 @@
var/last_shot_time = 0 //when was last shot fired, after 3 seconds we stop barrel
var/list/chain_bursts = list(1, 1, 2, 2, 3, 3, 3, 4, 4, 4) //how many shots per click we do

fire_delay = 0.2 SECONDS
gun_firemode = GUN_FIREMODE_AUTOMATIC
gun_firemode_list = list(
GUN_FIREMODE_AUTOMATIC,
)

var/start_sound = 'sound/weapons/vehicles/minigun_start.ogg'
var/loop_sound = 'sound/weapons/vehicles/minigun_loop.ogg'
var/stop_sound = 'sound/weapons/vehicles/minigun_stop.ogg'
activation_sounds = list('sound/weapons/gun_minigun.ogg')

/*
/obj/item/hardpoint/primary/minigun/fire(mob/user, atom/A)
var/S = 'sound/weapons/vehicles/minigun_stop.ogg'
Expand Down Expand Up @@ -73,3 +84,4 @@
playsound(get_turf(src), S, 40, 1)
last_shot_time = world.time
*/
Loading

0 comments on commit 01872ae

Please sign in to comment.