You can now link fishing portal generators to other fishing spots. (#86291)

## About The Pull Request
You can now interact with the fishing portal generator with a multitool
to load it in the buffer and subsequently link fishing spots to it by
tapping them with the same multitool. The maximum number of fishing
spots that can be linked at once depends on the tier of the matter bins
of the machinery. Normally, while you can link fishing spots from other
z-levels, they can only be activated if they're on the same z-level as
the machinery (or if both are on station for multi-z stations). This
limitation can be bypassed by upgrading the machinery with a tier 3 or
higher capacitator.

While it's possible, I'm not spriting new fishing portal overlays and
icons for the radial menu for every fish source out there (yet). The
code is enough work for now.

This also comes with a unit test, because there is no such thing as too
many unit tests for fishing.

## Why It's Good For The Game
Fish portal generators are designed to let players fish a different
bunch of things while being able to be moved wherever you like, unlike a
lake or an ocean, with all the comfort of being able to able to catch
fish from distant locations. Allowing players to link other fishing
spots to it fits its design. It also means that you can go out and
explore, find more fishing spots and then return to the station without
having to detach yourself from the ongoing round for several more
minutes.

## Changelog

🆑
add: You can now link fishing portal generators to other fishing spots
with a multitool. The number of fishing spots that can be linked at once
and whether the link can be activated from different z levels depends on
the tier of the stock parts it's built with.
/🆑

---------

Co-authored-by: Emmett Gaines <ninjanomnom@gmail.com>
This commit is contained in:
Ghom
2024-09-18 16:14:04 +02:00
committed by GitHub
parent 4687b1725a
commit 1aad3e118c
12 changed files with 291 additions and 16 deletions
@@ -190,6 +190,54 @@
. = ..()
probability = 0 //works around the global list initialization skipping abstract/impossible evolutions.
///A test that checks that fishing portals can be linked and function as expected
/datum/unit_test/fish_portal_gen_linking
/datum/unit_test/fish_portal_gen_linking/Run()
var/mob/living/carbon/human/consistent/user = allocate(/mob/living/carbon/human/consistent)
var/obj/machinery/fishing_portal_generator/portal = allocate(/obj/machinery/fishing_portal_generator/no_power)
var/obj/structure/toilet/unit_test/fishing_spot = new(get_turf(user)) //This is deleted during the test
var/obj/structure/moisture_trap/extra_spot = allocate(/obj/structure/moisture_trap)
var/obj/machinery/hydroponics/constructable/inaccessible = allocate(/obj/machinery/hydroponics/constructable)
ADD_TRAIT(inaccessible, TRAIT_UNLINKABLE_FISHING_SPOT, INNATE_TRAIT)
var/obj/item/multitool/tool = allocate(/obj/item/multitool)
var/datum/fish_source/toilet/fish_source = GLOB.preset_fish_sources[/datum/fish_source/toilet]
portal.max_fishing_spots = 1 //We've no scrying orb to know if it'll be buffed or nerfed this in the future. We only have space for one here.
portal.activate(fish_source, user)
TEST_ASSERT(!portal.active, "[portal] was activated with a fish source from an unlinked fishing spot")
portal.multitool_act(user, tool)
TEST_ASSERT_EQUAL(tool.buffer, portal, "[portal] wasn't set as buffer for [tool]")
tool.melee_attack_chain(user, fishing_spot)
TEST_ASSERT_EQUAL(LAZYACCESS(portal.linked_fishing_spots, fishing_spot), fish_source, "We tried linking [portal] to the fishing spot but didn't succeed.")
portal.activate(fish_source, user)
TEST_ASSERT(portal.active?.fish_source == fish_source, "[portal] can't acces a fish source from a linked fishing spot")
//Let's move the fishing spot away. This is fine as long as the portal moves to another z level, away from the toilet
var/turf/other_z_turf = pick(GLOB.newplayer_start)
portal.forceMove(other_z_turf)
TEST_ASSERT(!portal.active, "[portal] (not upgraded) is still active though the fishing spot is on another z-level.[portal.z == fishing_spot.z ? " Actually they're still on the same level!" : ""]")
portal.long_range_link = TRUE
portal.activate(fish_source, user)
TEST_ASSERT(portal.active?.fish_source == fish_source, "[portal] can't acces a fish source from a linked fishing spot on a different z-level despite being upgraded")
fishing_spot.forceMove(other_z_turf)
portal.forceMove(get_turf(user))
TEST_ASSERT(portal.active?.fish_source == fish_source, "[portal] (upgraded) deactivated while changing z-level")
tool.melee_attack_chain(user, extra_spot)
TEST_ASSERT_EQUAL(length(portal.linked_fishing_spots), 1, "We managed to link to another fishing spot when there's only space for one")
TEST_ASSERT_EQUAL(LAZYACCESS(portal.linked_fishing_spots, fishing_spot), fish_source, "linking to another fishing spot fouled up the other linked spots")
QDEL_NULL(fishing_spot)
TEST_ASSERT(!portal.active, "[portal] is still linked to the fish source of the deleted fishing spot it's associated to")
tool.melee_attack_chain(user, inaccessible)
TEST_ASSERT(!length(portal.linked_fishing_spots), "We managed to link to an unlinkable fishing spot")
/obj/machinery/fishing_portal_generator/no_power
use_power = NO_POWER_USE
/obj/structure/toilet/unit_test/Initialize(mapload)
. = ..()
if(!HAS_TRAIT(src, TRAIT_FISHING_SPOT)) //Ensure this toilet has a fishing spot because only maploaded ones have it.
AddElement(/datum/element/lazy_fishing_spot, /datum/fish_source/toilet)
// we want no default spawns in this unit test
/datum/chasm_detritus/restricted/bodies/no_defaults
default_contents_chance = 0