Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Total Turret Refactor #3844

Merged
merged 17 commits into from
Dec 3, 2024
Merged
Show file tree
Hide file tree
Changes from 11 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion _maps/RandomRuins/SandRuins/whitesands_cave_base.dmm
Original file line number Diff line number Diff line change
Expand Up @@ -2182,7 +2182,7 @@
/turf/open/floor/plating/asteroid/whitesands/grass,
/area/overmap_encounter/planetoid/cave/explored)
"Xe" = (
/obj/machinery/porta_turret,
/obj/machinery/porta_turret/cave_base,
/turf/closed/mineral/random/whitesands,
/area/overmap_encounter/planetoid/cave/explored)
"XF" = (
Expand Down
24 changes: 24 additions & 0 deletions code/__DEFINES/machines.dm
Original file line number Diff line number Diff line change
Expand Up @@ -143,3 +143,27 @@
#define CLONING_DELETE_RECORD (1<<1)

#define CLICKSOUND_INTERVAL (0.1 SECONDS) //! clicky noises, how much time needed in between clicks on the machine for the sound to play on click again.

/// ONLY shoots at mobs who match the rest of the flags and have weaponry/are otherwise dangerous
#define TURRET_FLAG_SHOOT_DANGEROUS_ONLY (1<<0)
/// Will shoot at things that shoot at it
#define TURRET_FLAG_SHOOT_RETALIATE (1<<1)

/// Will shoot at things that aren't human
#define TURRET_FLAG_SHOOT_FAUNA (1<<2)
/// Will shoot at humans
#define TURRET_FLAG_SHOOT_HUMANS (1<<3)
/// Will shoot at silicons
#define TURRET_FLAG_SHOOT_SILICONS (1<<4)
/// Will shoot at any kind of mob
#define TURRET_FLAG_SHOOT_ALLMOBS TURRET_FLAG_SHOOT_FAUNA|TURRET_FLAG_SHOOT_HUMANS|TURRET_FLAG_SHOOT_SILICONS

/// Will only shoot at things that AREN'T in the turret's set faction
#define TURRET_FLAG_SHOOT_NONFACTION (1<<5)
/// Will only shoot at things that ARE in the turret's set faction
#define TURRET_FLAG_SHOOT_SPECIFIC_FACTION (1<<6)
/// Will totally ignore targets' factions - the same as not setting the above two flags
//#define TURRET_FLAG_SHOOT_ALLFACTION (1<<8)

#define TURRET_FLAG_DEFAULT TURRET_FLAG_SHOOT_DANGEROUS_ONLY|TURRET_FLAG_SHOOT_RETALIATE|TURRET_FLAG_SHOOT_FAUNA|TURRET_FLAG_SHOOT_NONFACTION
#define TURRET_FLAG_HOSTILE TURRET_FLAG_SHOOT_ALLMOBS|TURRET_FLAG_SHOOT_RETALIATE|TURRET_FLAG_SHOOT_NONFACTION
10 changes: 10 additions & 0 deletions code/_globalvars/bitfields.dm
Original file line number Diff line number Diff line change
Expand Up @@ -277,3 +277,13 @@ DEFINE_BITFIELD(bodytype, list(
"BODYTYPE_KEPORI" = BODYTYPE_KEPORI,
"BODYTYPE_VOX" = BODYTYPE_VOX
))

DEFINE_BITFIELD(turret_flags, list(
"TURRET_FLAG_SHOOT_DANGEROUS_ONLY" = TURRET_FLAG_SHOOT_DANGEROUS_ONLY,
"TURRET_FLAG_SHOOT_RETALIATE" = TURRET_FLAG_SHOOT_RETALIATE,
"TURRET_FLAG_SHOOT_FAUNA" = TURRET_FLAG_SHOOT_FAUNA,
"TURRET_FLAG_SHOOT_HUMANS" = TURRET_FLAG_SHOOT_HUMANS,
"TURRET_FLAG_SHOOT_SILICONS" = TURRET_FLAG_SHOOT_SILICONS,
"TURRET_FLAG_SHOOT_NONFACTION" = TURRET_FLAG_SHOOT_NONFACTION,
"TURRET_FLAG_SHOOT_SPECIFIC_FACTION" = TURRET_FLAG_SHOOT_SPECIFIC_FACTION,
))
39 changes: 1 addition & 38 deletions code/controllers/subsystem/turrets.dm
Original file line number Diff line number Diff line change
@@ -1,41 +1,4 @@
SUBSYSTEM_DEF(turrets)
PROCESSING_SUBSYSTEM_DEF(turrets)
name = "Turrets"
wait = 5
init_order = INIT_ORDER_MACHINES
flags = SS_KEEP_TIMING
runlevels = RUNLEVEL_GAME | RUNLEVEL_POSTGAME
var/list/processing = list()
var/list/currentrun = list()

/datum/controller/subsystem/turrets/get_metrics()
. = ..()
var/list/cust = list()
cust["processing"] = length(processing)
.["custom"] = cust

/datum/controller/subsystem/turrets/stat_entry(msg)
msg = "M:[length(processing)]]"
return ..()


/datum/controller/subsystem/turrets/fire(resumed = 0)
if (!resumed)
src.currentrun = processing.Copy()

//cache for sanic speed (lists are references anyways)
var/list/currentrun = src.currentrun

var/seconds = wait * 0.1
while(currentrun.len)
var/obj/machinery/thing = currentrun[currentrun.len]
currentrun.len--
if(QDELETED(thing) || thing.process(seconds) == PROCESS_KILL)
processing -= thing
if (!QDELETED(thing))
thing.datum_flags &= ~DF_ISPROCESSING
if (MC_TICK_CHECK)
return

/datum/controller/subsystem/turrets/Recover()
if (istype(SSturrets.processing))
processing = SSmachines.processing
71 changes: 71 additions & 0 deletions code/datums/simple_beam.dm
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
/datum/simple_beam
///The source of the beam, which must be visible for the beam to be seen. Can NOT be null.
VAR_PRIVATE/atom/movable/origin
///The target of the beam. Can be null.
VAR_PRIVATE/atom/movable/target
///The visual representation of the beam.
VAR_PRIVATE/obj/effect/simple_beam/its_beam

/datum/simple_beam/New(_origin, _target, icon = 'icons/effects/beam.dmi', icon_state = "1-full", icon_color = null, icon_alpha = 255)
origin = _origin
target = _target

its_beam = new /obj/effect/simple_beam(origin, icon, icon_state, icon_color, icon_alpha)
origin.vis_contents += its_beam

set_target(target)

/datum/simple_beam/Destroy(force)
origin.vis_contents -= its_beam
QDEL_NULL(its_beam)

if(target)
UnregisterSignal(origin, COMSIG_MOVABLE_MOVED)
UnregisterSignal(target, COMSIG_MOVABLE_MOVED)

return ..()

/datum/simple_beam/proc/draw()
if(origin.z != target.z)
set_target(null)
return

var/f_dx = ((target.pixel_x - origin.pixel_x + 16) / world.icon_size) + (target.x - origin.x)
var/f_dy = ((target.pixel_y - origin.pixel_y) / world.icon_size) + (target.y - origin.y)
var/dist = sqrt(f_dx * f_dx + f_dy * f_dy)
var/s_dx = f_dy/dist
var/s_dy = -f_dx/dist
var/matrix/translation = matrix()
translation.Translate(0, 16)
translation.Multiply(new /matrix(s_dx, f_dx, 0, s_dy, f_dy, 0))

its_beam.transform = translation

/datum/simple_beam/proc/set_target(new_target)
if(target)
UnregisterSignal(target, COMSIG_MOVABLE_MOVED)
UnregisterSignal(origin, COMSIG_MOVABLE_MOVED)

target = new_target

if(target)
its_beam.vis_flags &= ~VIS_HIDE

RegisterSignal(target, COMSIG_MOVABLE_MOVED, PROC_REF(draw))
RegisterSignal(origin, COMSIG_MOVABLE_MOVED, PROC_REF(draw))

draw()
else
its_beam.vis_flags |= VIS_HIDE

/obj/effect/simple_beam
layer = ABOVE_LIGHTING_LAYER
plane = ABOVE_LIGHTING_PLANE

/obj/effect/simple_beam/New(loc, icon, icon_state, icon_color, icon_alpha)
src.icon = icon
src.icon_state = icon_state
src.color = icon_color
src.alpha = icon_alpha

return ..()
Loading
Loading