Merge pull request #48504 from ninjanomnom/gravity-element

Makes forced_gravity an element
This commit is contained in:
81Denton
2020-01-01 17:18:48 +01:00
committed by GitHub
6 changed files with 61 additions and 48 deletions
-20
View File
@@ -1,20 +0,0 @@
/datum/component/forced_gravity
var/gravity
var/ignore_space = FALSE //If forced gravity should also work on space turfs
/datum/component/forced_gravity/Initialize(forced_value = 1)
if(!isatom(parent))
return COMPONENT_INCOMPATIBLE
RegisterSignal(parent, COMSIG_ATOM_HAS_GRAVITY, .proc/gravity_check)
if(isturf(parent))
RegisterSignal(parent, COMSIG_TURF_HAS_GRAVITY, .proc/turf_gravity_check)
gravity = forced_value
/datum/component/forced_gravity/proc/gravity_check(datum/source, turf/location, list/gravs)
if(!ignore_space && isspaceturf(location))
return
gravs += gravity
/datum/component/forced_gravity/proc/turf_gravity_check(datum/source, atom/checker, list/gravs)
return gravity_check(null, parent, gravs)
+30
View File
@@ -0,0 +1,30 @@
/datum/element/forced_gravity
element_flags = ELEMENT_BESPOKE
id_arg_index = 2
var/gravity
var/ignore_space
/datum/element/forced_gravity/Attach(datum/target, gravity=1, ignore_space=FALSE)
. = ..()
if(!isatom(target))
return ELEMENT_INCOMPATIBLE
src.gravity = gravity
src.ignore_space = ignore_space
RegisterSignal(target, COMSIG_ATOM_HAS_GRAVITY, .proc/gravity_check)
if(isturf(target))
RegisterSignal(target, COMSIG_TURF_HAS_GRAVITY, .proc/turf_gravity_check)
/datum/element/forced_gravity/Detach(datum/source, force)
. = ..()
var/static/list/signals_b_gone = list(COMSIG_ATOM_HAS_GRAVITY, COMSIG_TURF_HAS_GRAVITY)
UnregisterSignal(source, signals_b_gone)
/datum/element/forced_gravity/proc/gravity_check(datum/source, turf/location, list/gravs)
if(!ignore_space && isspaceturf(location))
return
gravs += gravity
/datum/element/forced_gravity/proc/turf_gravity_check(datum/source, atom/checker, list/gravs)
return gravity_check(null, source, gravs)
@@ -2,16 +2,16 @@
name = "antigravity grenade"
icon_state = "emp"
item_state = "emp"
var/range = 7
var/forced_value = 0
var/duration = 300
/obj/item/grenade/antigravity/prime()
update_mob()
for(var/turf/T in view(range,src))
var/datum/component/C = T.AddComponent(/datum/component/forced_gravity,forced_value)
QDEL_IN(C,duration)
T.AddElement(/datum/element/forced_gravity, forced_value)
addtimer(CALLBACK(T, /datum/.proc/RemoveElement, forced_value), duration)
qdel(src)
+7 -6
View File
@@ -2,16 +2,17 @@
name = "modified gravity zone"
setup_field_turfs = TRUE
var/gravity_value = 0
var/list/grav_components = list()
var/list/modified_turfs = list()
field_shape = FIELD_SHAPE_RADIUS_SQUARE
/datum/proximity_monitor/advanced/gravity/setup_field_turf(turf/T)
. = ..()
grav_components[T] = T.AddComponent(/datum/component/forced_gravity,gravity_value)
T.AddElement(/datum/element/forced_gravity, gravity_value)
modified_turfs[T] = gravity_value
/datum/proximity_monitor/advanced/gravity/cleanup_field_turf(turf/T)
. = ..()
var/datum/component/forced_gravity/G = grav_components[T]
grav_components -= T
if(G)
qdel(G)
if(isnull(modified_turfs[T]))
return
T.RemoveElement(/datum/element/forced_gravity, modified_turfs[T])
modified_turfs -= T
@@ -13,8 +13,8 @@
///Removes gravity from affected mobs upon guardian death to prevent permanent effects
/mob/living/simple_animal/hostile/guardian/gravitokinetic/death()
. = ..()
for(var/datum/component/C in gravito_targets)
remove_gravity(C)
for(var/i in gravito_targets)
remove_gravity(i)
/mob/living/simple_animal/hostile/guardian/gravitokinetic/AttackingTarget()
. = ..()
@@ -38,26 +38,28 @@
/mob/living/simple_animal/hostile/guardian/gravitokinetic/Recall(forced)
. = ..()
to_chat(src, "<span class='danger'><B>You have released your gravitokinetic powers!</span></B>")
for(var/datum/component/C in gravito_targets)
remove_gravity(C)
for(var/i in gravito_targets)
remove_gravity(i)
/mob/living/simple_animal/hostile/guardian/gravitokinetic/Moved(oldLoc, dir)
. = ..()
for(var/datum/component/C in gravito_targets)
if(get_dist(src, C.parent) > gravity_power_range)
remove_gravity(C)
for(var/i in gravito_targets)
if(get_dist(src, i) > gravity_power_range)
remove_gravity(i)
/mob/living/simple_animal/hostile/guardian/gravitokinetic/proc/add_gravity(atom/A, new_gravity = 2)
var/datum/component/C = A.AddComponent(/datum/component/forced_gravity,new_gravity)
RegisterSignal(A, COMSIG_MOVABLE_MOVED, .proc/__distance_check)
gravito_targets.Add(C)
playsound(src, 'sound/effects/gravhit.ogg', 100, TRUE)
A.AddElement(/datum/element/forced_gravity, new_gravity)
gravito_targets[A] = new_gravity
RegisterSignal(A, COMSIG_MOVABLE_MOVED, .proc/__distance_check)
playsound(src, 'sound/effects/gravhit.ogg', 100, TRUE)
/mob/living/simple_animal/hostile/guardian/gravitokinetic/proc/remove_gravity(datum/component/C)
UnregisterSignal(C.parent, COMSIG_MOVABLE_MOVED)
gravito_targets.Remove(C)
qdel(C)
/mob/living/simple_animal/hostile/guardian/gravitokinetic/proc/remove_gravity(atom/target)
if(isnull(gravito_targets[target]))
return
UnregisterSignal(target, COMSIG_MOVABLE_MOVED)
target.RemoveElement(/datum/element/forced_gravity, gravito_targets[target])
gravito_targets -= target
/mob/living/simple_animal/hostile/guardian/gravitokinetic/proc/__distance_check(atom/movable/AM, OldLoc, Dir, Forced)
if(get_dist(src, AM) > gravity_power_range)
remove_gravity(AM.GetComponent(/datum/component/forced_gravity))
remove_gravity(AM)
+1 -1
View File
@@ -383,7 +383,6 @@
#include "code\datums\components\empprotection.dm"
#include "code\datums\components\explodable.dm"
#include "code\datums\components\footstep.dm"
#include "code\datums\components\forced_gravity.dm"
#include "code\datums\components\forensics.dm"
#include "code\datums\components\gps.dm"
#include "code\datums\components\gunpoint.dm"
@@ -518,6 +517,7 @@
#include "code\datums\elements\digitalcamo.dm"
#include "code\datums\elements\earhealing.dm"
#include "code\datums\elements\firestacker.dm"
#include "code\datums\elements\forced_gravity.dm"
#include "code\datums\elements\selfknockback.dm"
#include "code\datums\elements\snail_crawl.dm"
#include "code\datums\elements\squish.dm"