Skip to content

Commit

Permalink
Total Turret Refactor (#3844)
Browse files Browse the repository at this point in the history
<!-- Write **BELOW** The Headers and **ABOVE** The comments else it may
not be viewable. -->
<!-- You can view Contributing.MD for a detailed description of the pull
request process. -->

## About The Pull Request
Turret code was absolute garbage. This goes through and re-does
practically all of it, plus adds some new goodies for good measure.

Adds my own half-baked "simple beam" system, for when performance is
allegedly important and you don't care that they look ugly and only show
up when you can see the source object.

## Why It's Good For The Game
Not spending so much time processing JUST turrets is super nice. Plus
giving players the ability to actually control their turrets more is
nice.

## Changelog

:cl:
add: You can now set turrets to filter by faction, mob type, and a few
more criteria including "dangerous only" as well as the ability to
disable retaliation.
add: Turret retaliation is a lot more vengeful. Don't mess with them.
add: Turrets will now spend a short time targetting you, pointing a beam
at you to indicate that they're doing so.
del: Turret covers, because they sucked.
fix: Turretcode is a LOT less laggy.
tweak: Turrets are now built like normal machines. The boards are
currently not available (except through salvaging).
tweak: You can now access full turret settings from the turret control
panel.
/:cl:

<!-- Both :cl:'s are required for the changelog to work! You can put
your name to the right of the first :cl: if you want to overwrite your
GitHub username as author ingame. -->
<!-- You can use multiple of the same prefix (they're only used for the
icon ingame) and delete the unneeded ones. Despite some of the tags,
changelogs should generally represent how a player might be affected by
the changes rather than a summary of the PR's contents. -->
  • Loading branch information
MarkSuckerberg authored Dec 3, 2024
1 parent 126b402 commit 2dc59a5
Show file tree
Hide file tree
Showing 28 changed files with 1,344 additions and 1,595 deletions.
12 changes: 6 additions & 6 deletions _maps/RandomRuins/SandRuins/whitesands_cave_base.dmm
Original file line number Diff line number Diff line change
Expand Up @@ -864,7 +864,7 @@
/area/ruin/whitesands/cave_base)
"tB" = (
/obj/machinery/porta_turret/cave_base{
mode = 1
lethal = 1
},
/obj/effect/turf_decal/box/red,
/obj/structure/cable,
Expand Down Expand Up @@ -1103,7 +1103,7 @@
/area/ruin/whitesands/cave_base)
"yD" = (
/obj/machinery/porta_turret/cave_base{
mode = 1
lethal = 1
},
/obj/structure/cable,
/obj/effect/turf_decal/box/red,
Expand Down Expand Up @@ -1507,7 +1507,7 @@
},
/obj/machinery/light/floor,
/obj/machinery/porta_turret/cave_base{
mode = 1
lethal = 1
},
/turf/open/floor/concrete/slab_1/whitesands,
/area/ruin/whitesands/cave_base)
Expand Down Expand Up @@ -1536,7 +1536,7 @@
/area/overmap_encounter/planetoid/cave/explored)
"HF" = (
/obj/machinery/porta_turret/cave_base{
mode = 1
lethal = 1
},
/obj/structure/cable{
icon_state = "0-4"
Expand Down Expand Up @@ -2016,7 +2016,7 @@
/obj/effect/turf_decal/box/red,
/obj/machinery/light/floor,
/obj/machinery/porta_turret/cave_base{
mode = 1
lethal = 1
},
/turf/open/floor/concrete/slab_1/whitesands,
/area/ruin/whitesands/cave_base)
Expand Down 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
32 changes: 16 additions & 16 deletions _maps/shuttles/pgf/pgf_crying_sun.dmm
Original file line number Diff line number Diff line change
Expand Up @@ -1190,8 +1190,8 @@
},
/obj/machinery/porta_turret/ship/pgf/light{
dir = 5;
mode = 1;
id = "crying_sun_grid"
id = "crying_sun_grid";
lethal = 1
},
/turf/open/floor/engine/hull,
/area/ship/external/dark)
Expand Down Expand Up @@ -1484,8 +1484,8 @@
},
/obj/machinery/porta_turret/ship/pgf/light{
dir = 8;
mode = 1;
id = "crying_sun_grid"
id = "crying_sun_grid";
lethal = 1
},
/turf/open/floor/engine/hull/reinforced,
/area/ship/external/dark)
Expand Down Expand Up @@ -3177,8 +3177,8 @@
/obj/structure/catwalk/over/plated_catwalk/dark,
/obj/machinery/porta_turret/ship/pgf/light{
dir = 4;
mode = 1;
id = "crying_sun_grid"
id = "crying_sun_grid";
lethal = 1
},
/turf/open/floor/plating/airless,
/area/ship/external/dark)
Expand Down Expand Up @@ -4241,8 +4241,8 @@
},
/obj/machinery/porta_turret/ship/pgf/light{
dir = 4;
mode = 1;
id = "crying_sun_grid"
id = "crying_sun_grid";
lethal = 1
},
/turf/open/floor/plating/airless,
/area/ship/external/dark)
Expand Down Expand Up @@ -5846,8 +5846,8 @@
},
/obj/machinery/porta_turret/ship/pgf/light{
dir = 10;
mode = 1;
id = "crying_sun_grid"
id = "crying_sun_grid";
lethal = 1
},
/turf/open/floor/engine/hull,
/area/ship/external/dark)
Expand Down Expand Up @@ -6312,8 +6312,8 @@
},
/obj/machinery/porta_turret/ship/pgf/light{
dir = 6;
mode = 1;
id = "crying_sun_grid"
id = "crying_sun_grid";
lethal = 1
},
/turf/open/floor/engine/hull,
/area/ship/external/dark)
Expand Down Expand Up @@ -6398,8 +6398,8 @@
},
/obj/machinery/porta_turret/ship/pgf/light{
dir = 5;
mode = 1;
id = "crying_sun_grid"
id = "crying_sun_grid";
lethal = 1
},
/turf/open/floor/engine/hull,
/area/ship/external/dark)
Expand Down Expand Up @@ -6726,8 +6726,8 @@
/obj/structure/cable,
/obj/machinery/porta_turret/ship/pgf/light{
dir = 5;
mode = 1;
id = "crying_sun_grid"
id = "crying_sun_grid";
lethal = 1
},
/turf/open/floor/engine/hull,
/area/ship/external/dark)
Expand Down
4 changes: 2 additions & 2 deletions _maps/shuttles/subshuttles/pgf_nail.dmm
Original file line number Diff line number Diff line change
Expand Up @@ -397,8 +397,8 @@
},
/obj/machinery/porta_turret/ship/pgf/light{
dir = 8;
mode = 1;
id = "nail_grid"
id = "nail_grid";
lethal = 1
},
/turf/open/floor/engine/hull/reinforced/interior,
/area/ship/external/dark)
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 ..()
3 changes: 0 additions & 3 deletions code/game/atoms.dm
Original file line number Diff line number Diff line change
Expand Up @@ -1320,9 +1320,6 @@
/atom/proc/connect_to_shuttle(obj/docking_port/mobile/port, obj/docking_port/stationary/dock)
return

/atom/proc/disconnect_from_shuttle(obj/docking_port/mobile/port)
return

/// Generic logging helper
/atom/proc/log_message(message, message_type, color=null, log_globally=TRUE)
if(!log_globally)
Expand Down
Loading

0 comments on commit 2dc59a5

Please sign in to comment.