Files
Bubberstation/code/modules/unit_tests/mouse_bite_cable.dm
Swift 67a3eb415d [UPSTREAM] [NO GBP] Slime AI fixes + prerequisites (#1432)
…not idle) (#27470)

* Reworks targeting behavior to fall back onto proximity monitors.
Refactors ai cooldowns a bit (#82640)

Nother bit ripped out of #79498
[Implements a get_cooldown() proc to get around dumb manual overrides
and empower me to optimize the findtarget

logic](7047d294dd)

[Adds modify_cooldown, uses it to optimize find_potential_targets
further](4ebc8cedce)

No sense running the behavior if we're just waiting on its output, so
let's run it once a minute just in case, then push an update instantly
if we find something

[Optimizes connect_range and

promxity_monitors](bcf7d7c5b3)

We know what turfs exist before and after a move
We can use this information to prevent trying to update turfs we don't
care about.

This is important because post these changes mobs with fields will be
moving a lot more, so it's gotta be cheap

[Implements a special kind of field to handle ai

targeting](80b63b3445)

If we run targeting and don't like, find anything, we should setup a
field that listens for things coming near us and then handle those
things as we find them.

This incurs a slight startup cost but saves so much time on the churn of
constant costs

Note:
We should also work to figure out a way to avoid waking ais if none is
near them/they aren't doing anything interesting

We don't need to do that immediately this acts as somewhat of a stopgap
(and would be good regardless) but it is worth keeping in mind)

I am unsure whether this is worth it anymore since #82539 was merged. As
I say it was done as a stopgap because ais didn't know how to idle. If
not I'll rip er out and we'll keep the other
refactoring/optimizations.

Cleaner basic ai code, maybe? faster basic ai code, for sure faster
proximity monitors (significantly)

* ai controllers use cell trackers to know when to idle (#82691)

this makes ai controllers use cell trackers and signals to determine
when to idle

might be better than looping over all clients for every controller

🆑
code: The way mobs idle has been refactored, please report any issues
with non-reactive mobs
/🆑

* makes slimes not idle (#82742)

slimes should still be able to do their everyday routine without needing
to be watched over

makes xenobiologist's lives easier

🆑
qol: slimes will stay active without needing any one to watch over /🆑

---------

<!-- 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

<!-- Describe The Pull Request. Please be sure every change is
documented or this can delay review and even discourage maintainers from
merging your PR! -->

<!-- Please make sure to actually test your PRs. If you have not tested
your PR mention it. -->

## Why It's Good For The Game

<!-- Argue for the merits of your changes and how they benefit the game,
especially if they are controversial and/or far reaching. If you can't
actually explain WHY what you are doing will improve the game, then it
probably isn't good for the game in the first place. -->

## Proof Of Testing

<!-- Compile and run your code locally. Make sure it works. This is the
place to show off your changes! We are not responsible for testing your
features. -->

## Changelog

<!-- If your PR modifies aspects of the game that can be concretely
observed by players or admins you should add a changelog. If your change
does NOT meet this description, remove this section. Be sure to properly
mark your PRs to prevent unnecessary GBP loss. You can read up on GBP
and it's effects on PRs in the tgstation guides for contributors. Please
note that maintainers freely reserve the right to remove and add tags
should they deem it appropriate. You can attempt to finagle the system
all you want, but it's best to shoot for clear communication right off
the bat. -->

🆑
add: Added new mechanics or gameplay changes
add: Added more things
del: Removed old things
qol: made something easier to use
balance: rebalanced something
fix: fixed a few things
sound: added/modified/removed audio or sound effects
image: added/modified/removed some icons or images
spellcheck: fixed a few typos
code: changed some code
refactor: refactored some code
config: changed some config setting
admin: messed with admin stuff
server: something server ops should know
/🆑

<!-- 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. -->

<!-- By opening a pull request. You have read and understood the
repository rules located on the main README.md on this project. -->

---------

Co-authored-by: Waterpig <49160555+Majkl-J@users.noreply.github.com>
Co-authored-by: LemonInTheDark <58055496+LemonInTheDark@users.noreply.github.com>
Co-authored-by: Ben10Omintrix <138636438+Ben10Omintrix@users.noreply.github.com>
Co-authored-by: SkyratBot <59378654+SkyratBot@users.noreply.github.com>
Co-authored-by: Iamgoofball <iamgoofball@gmail.com>
Co-authored-by: Waterpig <wtryoutube@seznam.cz>
2024-04-25 23:13:16 -05:00

58 lines
3.0 KiB
Plaintext

/// Unit Test to ensure that a mouse bites a cable, gets shocked, and dies.
/datum/unit_test/mouse_bite_cable
/datum/unit_test/mouse_bite_cable/Run()
// use dummy subtype that will bypass the probability check to bite on a cable
var/mob/living/basic/mouse/biter = allocate(/mob/living/basic/mouse/cable_lover)
var/obj/structure/cable/wire = allocate(/obj/structure/cable)
// Make sure the cable has a powernet.
wire.powernet = new()
// Make sure the powernet has a good amount of power!
// mice bites check if there is ANY power in the powernet and passes fine, but better safe than sorry
wire.powernet.avail = 100000
var/turf/open/floor/stage = get_turf(wire)
// the unit tests room has normal flooring so let's just make it be interactable for the sake of this test
stage.underfloor_accessibility = UNDERFLOOR_INTERACTABLE
// relocate the rat
biter.forceMove(stage)
// Ai controlling processes expect a seconds_per_tick, supply a real-fake dt
var/fake_dt = SSai_controllers.wait * 0.1
// Set AI - AIs by default are off in z-levels with no client, we have to force it on.
biter.ai_controller.set_ai_status(AI_STATUS_ON)
biter.ai_controller.can_idle = FALSE
// Select behavior - this will queue finding the cable
biter.ai_controller.SelectBehaviors(fake_dt)
// Process behavior - this will execute the "locate the cable" behavior
biter.ai_controller.process(fake_dt)
// Check that the cable was found
TEST_ASSERT(biter.ai_controller.blackboard[BB_LOW_PRIORITY_HUNTING_TARGET] == wire, "Mouse, after executing find, did not set the cable as a target.")
// Select behavior - this will queue hunting
biter.ai_controller.SelectBehaviors(fake_dt)
// Process behavior - this will execute the hunt for the cable and cause a bite (as we're in the min range)
biter.ai_controller.process(fake_dt)
// Check that the cable was removed, as it was hunted correctly
TEST_ASSERT_NULL(biter.ai_controller.blackboard[BB_LOW_PRIORITY_HUNTING_TARGET], "Mouse, after executing hunt, did not clear their target blackboard.")
// Now check that the bite went through - remember we qdel mice on death
TEST_ASSERT(QDELETED(biter), "Mouse, did not die after biting a powered cable.")
TEST_ASSERT(QDELETED(wire), "Cable, was not deleted after being bitten by a mouse.")
// reset the floor to its original state, to be nice to other tests in case that matters
stage.underfloor_accessibility = initial(stage.underfloor_accessibility)
/// Dummy mouse that is guaranteed to die when biting shocked cables.
/mob/living/basic/mouse/cable_lover
cable_zap_prob = 100
ai_controller = /datum/ai_controller/basic_controller/mouse/guaranteed_to_bite
/// Dummy mouse's ai controller that is guaranteed to find and bite a cable beneath it
/datum/ai_controller/basic_controller/mouse/guaranteed_to_bite
planning_subtrees = list(/datum/ai_planning_subtree/find_and_hunt_target/look_for_cables/guaranteed)
/// Cable hunting subtree that's guarantee to hunt its target.
/datum/ai_planning_subtree/find_and_hunt_target/look_for_cables/guaranteed
hunt_chance = 100