|
| 1 | +/// Component that manages a list of plane masters that are dependent on weather |
| 2 | +/// Force hides/shows them depending on the weather activity of their z stack |
| 3 | +/// Applied to the plane master group that owns them |
| 4 | +/datum/component/hide_weather_planes |
| 5 | + dupe_mode = COMPONENT_DUPE_UNIQUE_PASSARGS |
| 6 | + var/list/datum/weather/active_weather = list() |
| 7 | + var/list/atom/movable/screen/plane_master/plane_masters = list() |
| 8 | + |
| 9 | +/datum/component/hide_weather_planes/Initialize(atom/movable/screen/plane_master/care_about) |
| 10 | + if(!istype(parent, /datum/plane_master_group)) |
| 11 | + return COMPONENT_INCOMPATIBLE |
| 12 | + var/datum/plane_master_group/home = parent |
| 13 | + plane_masters += care_about |
| 14 | + RegisterSignal(care_about, COMSIG_QDELETING, PROC_REF(plane_master_deleted)) |
| 15 | + |
| 16 | + var/list/starting_signals = list() |
| 17 | + var/list/ending_signals = list() |
| 18 | + for(var/datum/weather/weather_type as anything in typesof(/datum/weather)) |
| 19 | + starting_signals += COMSIG_WEATHER_TELEGRAPH(weather_type) |
| 20 | + ending_signals += COMSIG_WEATHER_END(weather_type) |
| 21 | + |
| 22 | + RegisterSignals(SSdcs, starting_signals, PROC_REF(weather_started)) |
| 23 | + RegisterSignals(SSdcs, ending_signals, PROC_REF(weather_finished)) |
| 24 | + |
| 25 | + if(home.our_hud) |
| 26 | + attach_hud(home.our_hud) |
| 27 | + else |
| 28 | + RegisterSignal(home, COMSIG_GROUP_HUD_CHANGED, PROC_REF(new_hud_attached)) |
| 29 | + |
| 30 | +/datum/component/hide_weather_planes/Destroy(force) |
| 31 | + hide_planes() |
| 32 | + active_weather = null |
| 33 | + plane_masters = null |
| 34 | + return ..() |
| 35 | + |
| 36 | +/datum/component/hide_weather_planes/InheritComponent(datum/component/new_comp, i_am_original, atom/movable/screen/plane_master/care_about) |
| 37 | + if(!i_am_original) |
| 38 | + return |
| 39 | + plane_masters += care_about |
| 40 | + RegisterSignal(care_about, COMSIG_QDELETING, PROC_REF(plane_master_deleted)) |
| 41 | + if(length(active_weather)) |
| 42 | + care_about.enable_alpha() |
| 43 | + else |
| 44 | + care_about.disable_alpha() |
| 45 | + |
| 46 | +/datum/component/hide_weather_planes/proc/new_hud_attached(datum/source, datum/hud/new_hud) |
| 47 | + SIGNAL_HANDLER |
| 48 | + if(new_hud) |
| 49 | + attach_hud(new_hud) |
| 50 | + |
| 51 | +/datum/component/hide_weather_planes/proc/attach_hud(datum/hud/new_hud) |
| 52 | + RegisterSignal(new_hud, COMSIG_HUD_Z_CHANGED, PROC_REF(z_changed)) |
| 53 | + var/mob/eye = new_hud?.mymob?.client?.eye |
| 54 | + var/turf/eye_location = get_turf(eye) |
| 55 | + z_changed(new_hud, eye_location?.z) |
| 56 | + |
| 57 | +/datum/component/hide_weather_planes/proc/plane_master_deleted(atom/movable/screen/plane_master/source) |
| 58 | + SIGNAL_HANDLER |
| 59 | + plane_masters -= source |
| 60 | + |
| 61 | +/datum/component/hide_weather_planes/proc/display_planes() |
| 62 | + var/datum/plane_master_group/home = parent |
| 63 | + var/mob/our_lad = home.our_hud?.mymob |
| 64 | + var/our_offset = GET_TURF_PLANE_OFFSET(our_lad) |
| 65 | + for(var/atom/movable/screen/plane_master/weather_concious as anything in plane_masters) |
| 66 | + //We need to make sure that planes above us are hidden, but below us are visible |
| 67 | + if(!weather_concious.alpha_enabled && weather_concious.offset >= our_offset) |
| 68 | + weather_concious.enable_alpha() |
| 69 | + |
| 70 | +/datum/component/hide_weather_planes/proc/hide_planes() |
| 71 | + for(var/atom/movable/screen/plane_master/weather_concious as anything in plane_masters) |
| 72 | + weather_concious.disable_alpha() |
| 73 | + |
| 74 | +/datum/component/hide_weather_planes/proc/z_changed(datum/source, new_z) |
| 75 | + SIGNAL_HANDLER |
| 76 | + /** |
| 77 | + * We hide all impacted planes on z change first because weather planes on lower offsets will show through the game world |
| 78 | + * so we can't count on them just not being visible like turfs above you. This is a result of attaching weather effects to areas, |
| 79 | + * which aren't beholden to z-levels and planes like atoms we're used to |
| 80 | + */ |
| 81 | + hide_planes() |
| 82 | + active_weather = list() |
| 83 | + if(!SSmapping.initialized) |
| 84 | + return |
| 85 | + |
| 86 | + var/list/connected_levels = SSmapping.get_connected_levels(new_z) |
| 87 | + for(var/datum/weather/active as anything in SSweather.processing) |
| 88 | + if(length(connected_levels & active.impacted_z_levels)) |
| 89 | + active_weather += WEAKREF(active) |
| 90 | + |
| 91 | + if(length(active_weather)) |
| 92 | + display_planes() |
| 93 | + |
| 94 | +/datum/component/hide_weather_planes/proc/weather_started(datum/source, datum/weather/starting) |
| 95 | + SIGNAL_HANDLER |
| 96 | + var/datum/plane_master_group/home = parent |
| 97 | + var/mob/eye = home.our_hud?.mymob?.client?.eye |
| 98 | + var/turf/viewing_from = get_turf(eye) |
| 99 | + if(!viewing_from) |
| 100 | + return |
| 101 | + |
| 102 | + var/list/connected_levels = SSmapping.get_connected_levels(viewing_from) |
| 103 | + if(length(connected_levels & starting.impacted_z_levels)) |
| 104 | + active_weather += WEAKREF(starting) |
| 105 | + |
| 106 | + if(!length(active_weather)) |
| 107 | + return |
| 108 | + display_planes() |
| 109 | + |
| 110 | +/datum/component/hide_weather_planes/proc/weather_finished(datum/source, datum/weather/stopping) |
| 111 | + SIGNAL_HANDLER |
| 112 | + active_weather -= WEAKREF(stopping) |
| 113 | + |
| 114 | + if(length(active_weather)) |
| 115 | + return |
| 116 | + hide_planes() |
0 commit comments