Skip to content

Commit

Permalink
SSTurrets (#3453)
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

Defines a small subsystem for turrets that fires every 5 ticks. Allows
us to actually set turret fire rates that aren't bound to SSMachines
will.

Resolves #3407 
<!-- Describe The Pull Request. Please be sure every change is
documented or this can delay review and even discourage maintainers from
merging your PR! -->

## Why It's Good For The Game
Turret Function :)
<!-- Please add a short description of why you think these changes would
benefit the game. If you can't justify it in words, it might not be
worth adding. -->

## Changelog

:cl:
fix: Turrets should now actually fire at their defined fire rates. 
/: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. -->

---------

Signed-off-by: Erika Fox <[email protected]>
  • Loading branch information
Erikafox authored Oct 9, 2024
1 parent 7b12eef commit 0155f24
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 1 deletion.
1 change: 1 addition & 0 deletions code/__DEFINES/subsystems.dm
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@
#define INIT_ORDER_ATOMS 30
#define INIT_ORDER_LANGUAGE 25
#define INIT_ORDER_MACHINES 20
#define INIT_ORDER_TURRETS 17
#define INIT_ORDER_SKILLS 15
#define INIT_ORDER_TIMER 1
#define INIT_ORDER_DEFAULT 0
Expand Down
41 changes: 41 additions & 0 deletions code/controllers/subsystem/turrets.dm
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
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
3 changes: 2 additions & 1 deletion code/game/machinery/porta_turret/portable_turret.dm
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ DEFINE_BITFIELD(turret_flags, list(
integrity_failure = 0.5
armor = list("melee" = 50, "bullet" = 30, "laser" = 30, "energy" = 30, "bomb" = 30, "bio" = 0, "rad" = 0, "fire" = 90, "acid" = 90)
base_icon_state = "standard"
subsystem_type = /datum/controller/subsystem/turrets
/// Scan range of the turret for locating targets
var/scan_range = 7
/// For turrets inside other objects
Expand Down Expand Up @@ -77,7 +78,7 @@ DEFINE_BITFIELD(turret_flags, list(
var/has_cover = TRUE
/// The cover that is covering this turret
var/obj/machinery/porta_turret_cover/cover = null
/// Ticks until next shot (1.5 ?)
/// Ticks until next shot (1.5 ?) If this needs to go below 5, use SSFastProcess
var/shot_delay = 15
/// Turret flags about who is turret allowed to shoot
var/turret_flags = TURRET_FLAG_SHOOT_CRIMINALS | TURRET_FLAG_SHOOT_ANOMALOUS
Expand Down
1 change: 1 addition & 0 deletions shiptest.dme
Original file line number Diff line number Diff line change
Expand Up @@ -393,6 +393,7 @@
#include "code\controllers\subsystem\title.dm"
#include "code\controllers\subsystem\traumas.dm"
#include "code\controllers\subsystem\turf_fire.dm"
#include "code\controllers\subsystem\turrets.dm"
#include "code\controllers\subsystem\verb_manager.dm"
#include "code\controllers\subsystem\vis_overlays.dm"
#include "code\controllers\subsystem\vote.dm"
Expand Down

0 comments on commit 0155f24

Please sign in to comment.