Files
Yogstation/code/datums/components
XDTM b4b543e111 [Ready] [Reviewed] Nanites 2 (#37922)
* Adds programmable nanites to robotics

* Oh yeah i might want to actually PR the files

* nanite injectors, nanite printer, nanite analyzer

* We're back

* remove some reagent stuff

* more removal

* those too

* cool icons!

* might pass travis now

* lotsa code

* tgui fixes/misc fixes

* WE'RE FUNCTIONAL BOYS

* some ui stuff

* Misc fixes, cloud update, access nanites

* activation check

* stuff

* preparing for new chamber sprite

* Physical backups, sensor nanite programs

* techweb sensor nanites

* fix

* include

* fix again

* revert

* blinding nanites

* minor change

* minor tweaks

* makes minor shocks interfere with nanites

* fix

* split trigger file into the others, for consistency

* cleanup, added mindshield nanites to techwebs

* include n all

* how'd that even happen

* Fixed HUD, readded missing remote icon, added nanite scanner, health analyzers can now detect nanites, added stealth program

* cost tweaks

* better term

* new icon! by MrDoomBringer

* icons/tweaks

* tgui build

* boards

* fix

* fixes implants not updating mindshield status

* move implant hud to living

* new remote sprite

* scanner sprite

* biotype checks

* some nerfs

* new open chamber sprite

* Fixes mindshield implants not updating the HUD, fixes uninstalling always removing the first program, adds 25% and 75% health sensors

* correction

* nerfs antistun nanites

* fixes scanners and minor tweaks

* fixes revs with mindshield

* oh yeah haha

* Fixes wonky techweb

* Moves pyro program to weapon node

* Adds defib program and some investigate logging

* mistype

* fix

* fix2

* save your files before committing

* emps can desync from cloud

* pretty outdated

* Cloud backups are now tied to the cloud consoles; you can no longer build a new console to access existing backups.

* UI fix

* more fix

* okay fix for real

* tested and working

* Extra Settings rework, sensor nanites vastly better

* non-unique glitches

* Public chamber, extra settings rework, new sensors, speech program

* Mute and mind control nanites

* mind control into hazard

* better description

* fixes

* fixes relay nanites

* fixes TK access

* mind control costs less

* UI update

* removed pointless code bit

* tgui build

* compiles

* dammit

* paralysis keeps victim upright

* Adds sounds to consoles

* some feedback for some subtle effects

* new chem lore

* Viral nanite customization

* fix

* tgui build

* Added mitosis nanites

* removes glitched nanites from techwebs

* Added flesh eating nanites, poison nanites, hallucination nanites

* ,

* #traviscoding

* Adds memory leak, renames nanite roam node to nanite smart

* Voice sensor + some techweb desc tweaks

* hallucination and Hear() fix

* changes signal registering to the new method

* 75% done, i think

* should be all

* more fix

* more changes

* okay should be fine now

* ninja

* inheritance

* i don't care about originality!

* line endings

* line endings 2

* maybe

* fixes program installation

* new review

* line endings?

* line endings??

* line endings???

* wait do i even use this

* fixes public nanite chamber cloud id

* maint overlay for chambers

* args doesn't work well here

* antiabuse checks

* compile tho

* fixes locked remotes

* disk renaming

* skull echo nanites

* self scan program

* Condenses a lot of sensors into a few generic but customizable versions

* fixes machinery runtimes. Hacky, but a proper fix would likely require a refactor of machinery typing.

* forgot to save

* empty

* metastation nanite lab

* Removes duplicate APC

* fix for nanite chamber

* Raise max programs

* UI Tweaks, aggr. replication rebalance, minor fixes

* let's not do that again

* Fixes nanites meta merge conflict

* Merge conflict v2

* fuck this HDD is slow

* What the fuck did you just fucking say about me, you little leaf? I'll have you know I graduated top of my class in the Lawyer School, and I've been involved in numerous secret DMCA raids. I am trained in law violations warfare and you are nothing to me but just another target. I will wipe you the fuck out with precision the likes of which has never been seen before on BYOND, mark my fucking words. You think you can get away with changing the code? Think again, fucker. As we speak I am contacting my secret network of attorneys in the Fox and your IP is being traced right now so you better prepare for an outstanding warrant, maggot. The storm that wipes out the pathetic little thing you call your leaked code. You're fucking done, kid. I can file for an injunction anywhere, anytime, and I can take legal actions in over seven hundred ways, and that's just with my bare hands. Not only am I extensively trained in unarmed combat, but I have access to the entire arsenal of the Florida Statute and I will use it to its full extent to wipe your miserable ass off the face of Canada, you little shit. If only you could have known what unholy retribution your little "clever" action was about to bring down upon you, maybe you would have held your fucking tongue. But you couldn't, you didn't, and now you're paying the price, you goddamn idiot. I will send you to spend time in a Florida State Penitentiary if you ever decide to travel from Canada to the U.S. You're fucking done, kiddo.

* Adds virus symptoms that interact with nanites

* Fixes spreading nanites being more infective the more protection the victims have

* Review plus public chamber tweak

* . = ..()

* ball

* cloud

* . = ..()

* always press save all before committing

* missed a couple
2018-08-20 12:45:39 +01:00
..
2018-06-28 21:26:38 +02:00
2018-08-11 10:32:34 +02:00

Datum Component System (DCS)

Concept

Loosely adapted from /vg/. This is an entity component system for adding behaviours to datums when inheritance doesn't quite cut it. By using signals and events instead of direct inheritance, you can inject behaviours without hacky overloads. It requires a different method of thinking, but is not hard to use correctly. If a behaviour can have application across more than one thing. Make it generic, make it a component. Atom/mob/obj event? Give it a signal, and forward it's arguments with a SendSignal() call. Now every component that want's to can also know about this happening.

In the code

Slippery things

At the time of this writing, every object that is slippery overrides atom/Crossed does some checks, then slips the mob. Instead of all those Crossed overrides they could add a slippery component to all these objects. And have the checks in one proc that is run by the Crossed event

Powercells

A lot of objects have powercells. The get_cell() proc was added to give generic access to the cell var if it had one. This is just a specific use case of GetComponent()

Radios

The radio object as it is should not exist, given that more things use the concept of radios rather than the object itself. The actual function of the radio can exist in a component which all the things that use it (Request consoles, actual radios, the SM shard) can add to themselves.

Standos

Stands have a lot of procs which mimic mob procs. Rather than inserting hooks for all these procs in overrides, the same can be accomplished with signals

API

Defines

  1. COMPONENT_INCOMPATIBLE Return this from /datum/component/Initialize or datum/component/OnTransfer to have the component be deleted if it's applied to an incorrect type. parent must not be modified if this is to be returned. This will be noted in the runtime logs

Vars

  1. /datum/var/list/datum_components (private)
    • Lazy associated list of type -> component/list of components.
  2. /datum/component/var/enabled (protected, boolean)
    • If the component is enabled. If not, it will not react to signals
    • FALSE by default, set to TRUE when a signal is registered
  3. /datum/component/var/dupe_mode (protected, enum)
    • How duplicate component types are handled when added to the datum.
      • COMPONENT_DUPE_HIGHLANDER (default): Old component will be deleted, new component will first have /datum/component/proc/InheritComponent(datum/component/old, FALSE) on it
      • COMPONENT_DUPE_ALLOWED: The components will be treated as separate, GetComponent() will return the first added
      • COMPONENT_DUPE_UNIQUE: New component will be deleted, old component will first have /datum/component/proc/InheritComponent(datum/component/new, TRUE) on it
      • COMPONENT_DUPE_UNIQUE_PASSARGS: New component will never exist and instead its initialization arguments will be passed on to the old component.
  4. /datum/component/var/dupe_type (protected, type)
    • Definition of a duplicate component type
      • null means exact match on type (default)
      • Any other type means that and all subtypes
  5. /datum/component/var/list/signal_procs (private)
    • Associated lazy list of signals -> /datum/callbacks that will be run when the parent datum receives that signal
  6. /datum/component/var/datum/parent (protected, read-only)
    • The datum this component belongs to
    • Never null in child procs
  7. report_signal_origin (protected, boolean)
    • If TRUE, will invoke the callback when signalled with the signal type as the first argument.
    • FALSE by default.

Procs

  1. /datum/proc/GetComponent(component_type(type)) -> datum/component? (public, final)
    • Returns a reference to a component of component_type if it exists in the datum, null otherwise
  2. /datum/proc/GetComponents(component_type(type)) -> list (public, final)
    • Returns a list of references to all components of component_type that exist in the datum
  3. /datum/proc/GetExactComponent(component_type(type)) -> datum/component? (public, final)
    • Returns a reference to a component whose type MATCHES component_type if that component exists in the datum, null otherwise
  4. GET_COMPONENT(varname, component_type) OR GET_COMPONENT_FROM(varname, component_type, src)
    • Shorthand for var/component_type/varname = src.GetComponent(component_type)
  5. SEND_SIGNAL(target, sigtype, ...) (public, final)
    • Use to send signals to target datum
    • Extra arguments are to be specified in the signal definition
    • Returns a bitflag with signal specific information assembled from all activated components
    • Arguments are packaged in a list and handed off to _SendSignal()
  6. /datum/proc/AddComponent(component_type(type), ...) -> datum/component (public, final)
    • Creates an instance of component_type in the datum and passes ... to its Initialize() call
    • Sends the COMSIG_COMPONENT_ADDED signal to the datum
    • All components a datum owns are deleted with the datum
    • Returns the component that was created. Or the old component in a dupe situation where COMPONENT_DUPE_UNIQUE was set
    • If this tries to add an component to an incompatible type, the component will be deleted and the result will be null. This is very unperformant, try not to do it
    • Properly handles duplicate situations based on the dupe_mode var
  7. /datum/proc/LoadComponent(component_type(type), ...) -> datum/component (public, final)
    • Equivalent to calling GetComponent(component_type) where, if the result would be null, returns AddComponent(component_type, ...) instead
  8. /datum/proc/ComponentActivated(datum/component/C) (abstract, async)
    • Called on a component's parent after a signal received causes it to activate. src is the parameter
    • Will only be called if a component's callback returns TRUE
  9. /datum/proc/TakeComponent(datum/component/C) (public, final)
    • Properly transfers ownership of a component from one datum to another
    • Signals COMSIG_COMPONENT_REMOVING on the parent
    • Called on the datum you want to own the component with another datum's component
  10. /datum/proc/_SendSignal(signal, list/arguments) (private, final)
    • Handles most of the actual signaling procedure
    • Will runtime if used on datums with an empty component list
  11. /datum/component/New(datum/parent, ...) (private, final)
    • Runs internal setup for the component
    • Extra arguments are passed to Initialize()
  12. /datum/component/Initialize(...) (abstract, no-sleep)
    • Called by New() with the same argments excluding parent
    • Component does not exist in parent's datum_components list yet, although parent is set and may be used
    • Signals will not be received while this function is running
    • Component may be deleted after this function completes without being attached
    • Do not call qdel(src) from this function
  13. /datum/component/Destroy(force(bool), silent(bool)) (virtual, no-sleep)
    • Sends the COMSIG_COMPONENT_REMOVING signal to the parent datum if the parent isn't being qdeleted
    • Properly removes the component from parent and cleans up references
    • Setting force makes it not check for and remove the component from the parent
    • Setting silent deletes the component without sending a COMSIG_COMPONENT_REMOVING signal
  14. /datum/component/proc/InheritComponent(datum/component/C, i_am_original(boolean)) (abstract, no-sleep)
    • Called on a component when a component of the same type was added to the same parent
    • See /datum/component/var/dupe_mode
    • C's type will always be the same of the called component
  15. /datum/component/proc/AfterComponentActivated() (abstract, async)
    • Called on a component that was activated after it's parent's ComponentActivated() is called
  16. /datum/component/proc/OnTransfer(datum/new_parent) (abstract, no-sleep)
    • Called before new_parent is assigned to parent in TakeComponent()
    • Allows the component to react to ownership transfers
  17. /datum/component/proc/_RemoveFromParent() (private, final)
    • Clears parent and removes the component from it's component list
  18. /datum/component/proc/_JoinParent (private, final)
    • Tries to add the component to it's parents datum_components list
  19. /datum/component/proc/RegisterWithParent (abstract, no-sleep)
    • Used to register the signals that should be on the parent object
    • Use this if you plan on the component transfering between parents
  20. /datum/component/proc/UnregisterFromParent (abstract, no-sleep)
    • Counterpart to RegisterWithParent()
    • Used to unregister the signals that should only be on the parent object
  21. /datum/component/proc/RegisterSignal(datum/target, signal(string/list of strings), proc_ref(type), override(boolean)) (protected, final)
    • If signal is a list it will be as if RegisterSignal was called for each of the entries with the same following arguments
    • Makes a component listen for the specified signal on it's parent datum.
    • When that signal is received proc_ref will be called on the component, along with associated arguments
    • Example proc ref: .proc/OnEvent
    • If a previous registration is overwritten by the call, a runtime occurs. Setting override to TRUE prevents this
    • These callbacks run asyncronously
    • Returning TRUE from these callbacks will trigger a TRUE return from the SendSignal() that initiated it

See/Define signals and their arguments in __DEFINES\components.dm