-
-
Notifications
You must be signed in to change notification settings - Fork 538
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
<!-- 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 Port of tgstation/tgstation#76961, which is itself a port of lizardqueenlexi/orbstation#630. This PR will add one new object, the portable weather radio. ![theradio](https://github.com/shiptest-ss13/Shiptest/assets/34109002/2d9acb59-30fa-4354-944d-f5bcc3b88666) ![image](https://github.com/shiptest-ss13/Shiptest/assets/34109002/76bad17f-b15e-4c50-99de-5cb860b19a89) ![image](https://github.com/shiptest-ss13/Shiptest/assets/34109002/ca0db81b-d8dc-43d9-9e8c-8a85b083d7cb) Wallmount shown in these has been axed. ### Todo - [x] Fix the existing code to work for our cases. - [x] Fix runtime errors. - [x] Stay hydrated. <!-- 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 They look neat, they add flavor, and the barometer function on analyzers is used maybe once every 50 rounds. <!-- 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 🆑 CoiledLamb, Jacquerel, GenericDM add: Adds Weather Radios! /🆑 <!-- Both 🆑's are required for the changelog to work! You can put your name to the right of the first 🆑 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
Showing
8 changed files
with
210 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,170 @@ | ||
#define WEATHER_ALERT_CLEAR 0 | ||
#define WEATHER_ALERT_INCOMING 1 | ||
#define WEATHER_ALERT_IMMINENT_OR_ACTIVE 2 | ||
|
||
/// Component which makes you yell about what the weather is | ||
/datum/component/weather_announcer | ||
/// Currently displayed warning level | ||
var/warning_level = WEATHER_ALERT_CLEAR | ||
/// Whether the incoming weather is actually going to harm you | ||
var/is_weather_dangerous = TRUE | ||
/// Are we actually turned on right now? | ||
var/enabled = TRUE | ||
/// Overlay added when things are alright | ||
var/state_normal | ||
/// Overlay added when you should start looking for shelter | ||
var/state_warning | ||
/// Overlay added when you are in danger | ||
var/state_danger | ||
|
||
/datum/component/weather_announcer/Initialize( | ||
state_normal, | ||
state_warning, | ||
state_danger, | ||
) | ||
. = ..() | ||
if (!ismovable(parent)) | ||
return COMPONENT_INCOMPATIBLE | ||
|
||
START_PROCESSING(SSprocessing, src) | ||
RegisterSignal(parent, COMSIG_ATOM_UPDATE_OVERLAYS, PROC_REF(on_update_overlays)) | ||
RegisterSignal(parent, COMSIG_MACHINERY_POWER_RESTORED, PROC_REF(on_powered)) | ||
RegisterSignal(parent, COMSIG_MACHINERY_POWER_LOST, PROC_REF(on_power_lost)) | ||
|
||
src.state_normal = state_normal | ||
src.state_warning = state_warning | ||
src.state_danger = state_danger | ||
var/atom/speaker = parent | ||
speaker.update_appearance(UPDATE_ICON) | ||
update_light_color() | ||
|
||
/datum/component/weather_announcer/Destroy(force, silent) | ||
STOP_PROCESSING(SSprocessing, src) | ||
return ..() | ||
|
||
/// Add appropriate overlays | ||
/datum/component/weather_announcer/proc/on_update_overlays(atom/parent_atom, list/overlays) | ||
SIGNAL_HANDLER | ||
if (!enabled || !state_normal || !state_warning || !state_danger) | ||
return | ||
|
||
switch (warning_level) | ||
if(WEATHER_ALERT_CLEAR) | ||
overlays += state_normal | ||
if(WEATHER_ALERT_INCOMING) | ||
overlays += state_warning | ||
if(WEATHER_ALERT_IMMINENT_OR_ACTIVE) | ||
overlays += (is_weather_dangerous) ? state_danger : state_warning | ||
|
||
/// If powered, receive updates | ||
/datum/component/weather_announcer/proc/on_powered() | ||
SIGNAL_HANDLER | ||
enabled = TRUE | ||
var/atom/speaker = parent | ||
speaker.update_appearance(UPDATE_ICON) | ||
|
||
/// If no power, don't receive updates | ||
/datum/component/weather_announcer/proc/on_power_lost() | ||
SIGNAL_HANDLER | ||
enabled = FALSE | ||
var/atom/speaker = parent | ||
speaker.update_appearance(UPDATE_ICON) | ||
|
||
/datum/component/weather_announcer/process(seconds_per_tick) | ||
if (!enabled) | ||
return | ||
|
||
var/previous_level = warning_level | ||
var/previous_danger = is_weather_dangerous | ||
set_current_alert_level() | ||
if(previous_level == warning_level && previous_danger == is_weather_dangerous) | ||
return // No change | ||
var/atom/movable/speaker = parent | ||
speaker.say(get_warning_message()) | ||
speaker.update_appearance(UPDATE_ICON) | ||
update_light_color() | ||
|
||
/datum/component/weather_announcer/proc/update_light_color() | ||
var/atom/movable/light = parent | ||
switch(warning_level) | ||
if(WEATHER_ALERT_CLEAR) | ||
light.set_light_color(LIGHT_COLOR_GREEN) | ||
if(WEATHER_ALERT_INCOMING) | ||
light.set_light_color(LIGHT_COLOR_YELLOW) | ||
if(WEATHER_ALERT_IMMINENT_OR_ACTIVE) | ||
light.set_light_color(LIGHT_COLOR_INTENSE_RED) | ||
light.update_light() | ||
|
||
/// Returns a string we should display to communicate what you should be doing | ||
/datum/component/weather_announcer/proc/get_warning_message() | ||
if (!is_weather_dangerous) | ||
return "No risk expected from incoming weather front." | ||
switch(warning_level) | ||
if(WEATHER_ALERT_CLEAR) | ||
return "All clear, no weather alerts to report." | ||
if(WEATHER_ALERT_INCOMING) | ||
return "Weather front incoming, begin to seek shelter." | ||
if(WEATHER_ALERT_IMMINENT_OR_ACTIVE) | ||
return "Weather front imminent, find shelter immediately." | ||
return "Error in meteorological calculation. Please report this deviation to a trained programmer." | ||
|
||
/datum/component/weather_announcer/proc/time_till_storm() | ||
var/datum/weather_controller/local_weather_controller = SSmapping.get_map_zone_weather_controller(parent) | ||
if(!local_weather_controller.next_weather) | ||
return null | ||
for(var/type_index in local_weather_controller.current_weathers) | ||
var/datum/weather/check_weather = local_weather_controller.current_weathers[type_index] | ||
if(!check_weather.barometer_predictable || check_weather.stage == WIND_DOWN_STAGE || check_weather.stage == END_STAGE) | ||
continue | ||
warning_level = WEATHER_ALERT_IMMINENT_OR_ACTIVE | ||
return 0 | ||
|
||
var/time_until_next = INFINITY | ||
var/next_time = local_weather_controller.next_weather - world.time || INFINITY | ||
if (next_time && next_time < time_until_next) | ||
time_until_next = next_time | ||
return time_until_next | ||
|
||
/// Polls existing weather for what kind of warnings we should be displaying. | ||
/datum/component/weather_announcer/proc/set_current_alert_level() | ||
var/time_until_next = time_till_storm() | ||
if(isnull(time_until_next)) | ||
return // No problems if there are no mining z levels | ||
if(time_until_next >= 2 MINUTES) | ||
warning_level = WEATHER_ALERT_CLEAR | ||
return | ||
|
||
if(time_until_next >= 30 SECONDS) | ||
warning_level = WEATHER_ALERT_INCOMING | ||
return | ||
|
||
// Weather is here, now we need to figure out if it is dangerous | ||
warning_level = WEATHER_ALERT_IMMINENT_OR_ACTIVE | ||
|
||
var/datum/weather_controller/local_weather_controller = SSmapping.get_map_zone_weather_controller(parent) | ||
for(var/type_index in local_weather_controller.current_weathers) | ||
var/datum/weather/check_weather = local_weather_controller.current_weathers[type_index] | ||
if(!check_weather.barometer_predictable || check_weather.stage == WIND_DOWN_STAGE || check_weather.stage == END_STAGE) | ||
continue | ||
is_weather_dangerous = !check_weather.aesthetic | ||
return | ||
|
||
/datum/component/weather_announcer/proc/on_examine(atom/radio, mob/examiner, list/examine_texts) | ||
var/time_until_next = time_till_storm() | ||
if(isnull(time_until_next)) | ||
return | ||
if (time_until_next == 0) | ||
examine_texts += span_warning ("A storm is currently active, please seek shelter.") | ||
else | ||
examine_texts += span_notice("The next storm is inbound in [DisplayTimeText(time_until_next)].") | ||
|
||
/datum/component/weather_announcer/RegisterWithParent() | ||
RegisterSignal(parent, COMSIG_PARENT_EXAMINE, PROC_REF(on_examine)) | ||
|
||
/datum/component/weather_announcer/UnregisterFromParent() | ||
.=..() | ||
UnregisterSignal(parent, COMSIG_PARENT_EXAMINE) | ||
|
||
#undef WEATHER_ALERT_CLEAR | ||
#undef WEATHER_ALERT_INCOMING | ||
#undef WEATHER_ALERT_IMMINENT_OR_ACTIVE |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
/// Portable mining radio purchasable by miners | ||
/obj/item/radio/weather_monitor | ||
icon = 'icons/obj/miningradio.dmi' | ||
name = "mining weather radio" | ||
icon_state = "miningradio" | ||
desc = "A weather radio designed for use in inhospitable environments. Gives audible warnings when storms approach." | ||
luminosity = 1 | ||
light_power = 1 | ||
light_range = 1.6 | ||
|
||
/obj/item/radio/weather_monitor/update_overlays() | ||
. = ..() | ||
. += emissive_appearance(icon, "small_emissive", src, alpha = src.alpha) | ||
|
||
/obj/item/radio/weather_monitor/Initialize(mapload) | ||
. = ..() | ||
AddComponent( \ | ||
/datum/component/weather_announcer, \ | ||
state_normal = "weatherwarning", \ | ||
state_warning = "urgentwarning", \ | ||
state_danger = "direwarning", \ | ||
) | ||
set_frequency(FREQ_COMMON) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters