Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: prevent chickens from escaping chicken coop #4333

Closed

Conversation

ekaratzas
Copy link
Contributor

@ekaratzas ekaratzas commented Mar 10, 2024

The idea is to prevent pet chickens from escaping the chicken coop when the player goes in/out of the coop by adding a specific flag both to the open chicken gate tile as well as the chickens themselves.

This flag will prevent the pet chicken from considering moving to the chicken gate tile a valid move. This concept can be applied to other types of gates and animals by reusing the new flags PASTURE_GATE and PET_AVOID_PASTURE_GATE.

Purpose of change

The idea behind this PR is to help chicken farmer players keep their chickens in their chicken coop areas.

Traditionally, what chicken farmers are forced to do in cata is climb through the fence into the chicken coop so as to not risk the chickens escaping while getting in/out of the coop gate.

This change makes it so that pet chickens will not consider escaping via the chicken coop gate tile, even if it's open, making it easier for the player to get in and out of the area without any of the birds escaping. This PR also makes chickens have the PET_WONT_FOLLOW flag as well.

Describe the solution

Solution works by introducing 2 new flags that work in tandem. Creatures with PET_AVOID_PASTURE_GATE flag that are also pets of the player will not consider moving through tiles that have the PASTURE_GATE flag.

This essentially makes monster::will_move_to() consider the position containing the tile with the new flag as a non valid destination for the pet monster.

Therefore when the player is going in-out of the pasture area, there is no fear of the little creatures following them. In this PR I'm also marking chickens/baby chickens as not following the player because it's annoying when they do and IRL chickens don't really follow you anyway in my experience.

However I should point out that this PR does introduce one corner-case where the experience might be clunky:

If the player tries to move from position A to position B, where

  • position A is a tile the bird cannot move to (e.g. on the fence, or now the pasture gate)
  • position B contains the bird

Then this will produce an error message and stop the movement. See PR #4325

This problem has already existed when players try to get in via the fence as mentioned earlier, but now it might also appear for the same reasons with the gate as well.

What this means is that if the player is trying to move into the coop and all 3 adjacent tiles to the coop gate contain chickens, then the player can't get into the coop area via the gate as the player cannot displace the chickens and swap places with them so they end up in the gate.

A visual representation of the corner-case:

Fc
Gc
Fc

G = gate, F = fence, c = chicken

If the player is standing on G and tries to move to the right into the coop area, all 3 possible positions are taken over by chickens. Then player can't move into the area as they cannot displace any of the chickens.

In this corner-case the player has to either 'push' the chicken in front of them, or mash the direction button/wait for them to move. Since PR #4332 has been merged, creatures with wont follow actually move randomly and dont follow the player so that's not much of a problem anymore but wanted to bring it up for full disclosure. I tested this behavior in a 3x3 coop with 6 friendly chickens and did not see this as an issue. However if the coop was full/almost full, at that point you'd have to either start slaughtering chickens or make it larger.

Describe alternatives you've considered

Climbing through fences to avoid this issue seems silly.

I've considered adding these new flags to more tiles/gates/monster types but figured I'd first see reactions to the mechanism itself. It's always easy to expand it to cover more animals/gates.

Testing

Easiest way to test this is to have a chicken cook with pet chickens. Coop should have chickenwire-gate for this to work. Leave gate open, see no friendly chickens escape.

Additional context

Checklist

The idea is to prevent pet chickens from escaping the chicken coop when
the player goes in/out of the coop by adding a specific flag both
to the open chicken gate tile as well as the chickens themselves.

This flag will prevent the pet chicken from considering moving to the
chicken gate tile a valid move. This concept can be applied to other
types of gates and animals by reusing the new flags PASTURE_GATE and
PET_AVOID_PASTURE_GATE.
@github-actions github-actions bot added src changes related to source code. JSON related to game datas in JSON format. labels Mar 10, 2024
Copy link
Contributor

autofix-ci bot commented Mar 10, 2024

Autofix has formatted code style violation in this PR.

I edit commits locally (e.g: git, github desktop) and want to keep autofix
  1. Run git pull. this will merge the automated commit into your local copy of the PR branch.
  2. Continue working.
I do not want the automated commit
  1. Format your code locally, then commit it.
  2. Run git push --force to force push your branch. This will overwrite the automated commit on remote with your local one.
  3. Continue working.

If you don't do this, your following commits will be based on the old commit, and cause MERGE CONFLICT.

@Zlorthishen
Copy link
Contributor

you should add this flag to all livestock animals

@ekaratzas
Copy link
Contributor Author

Hey @Zlorthishen, thanks for taking the time to look at this. As I mentioned in the PR description

I've considered adding these new flags to more tiles/gates/monster types but figured I'd first see reactions to the mechanism itself. It's always easy to expand it to cover more animals/gates.

Copy link
Member

@scarf005 scarf005 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

there might be two issues with this approach:

  • current solution only works for pets
  • PET_AVOID_PASTURE_GATE has to be applied for all future pets.
  • won't be much an perf issue, but this adds checks for each monsters.

alternatively, how about adding AUTOPASS flag that lets only characters to pass through? this way, players can choose how to manage pets via

  • closed chickenwire gate: only player can go in and out
  • open chickenwire gate: both player and chickens can go in and out

@ekaratzas
Copy link
Contributor Author

@scarf005 thanks for taking the time to comment on this. I'm not sure how the AUTOPASS flag you suggest can be coded honestly. Not saying it can't be done, just not sure how atm.

Regarding this approach and what it should apply to, imho it should only apply to bird pets as they overpopulate quickly and that's the main issue farmer players in either fork have faced in the past with regards to getting in/out of the area they are kept. In addition, bird-pets are usually introduced into the main pasture area via a chickenbox or such mechanism so they don't even need to enter into the coop by themselves even then.

In other words, if it were solely up to me, this flag would not get applied to cows, sheep, dogs, cats and so on; just bird* pets. That's my answer to your first two points.

No clue about performance impact, I don't have any data for that. Valid question on how something like this would impact mobile devices that can run the game though as it's an extra check for each monster's plan().

All that being said, I'm also not convinced this is the best solution to solve the problem with. Ideally I'd want to designate pets -and their offspring- to pasture zones and have them magically stick to those zones like in rimworld, but that's way beyond my current know-how with how submaps/zones can get partially loaded and so on.

@scarf005
Copy link
Member

bool map::open_door( const tripoint &p, const bool inside, const bool check_only )

//Wooden Fence Gate (or equivalently walkable doors):
// open it if we are walking
// vault over it if we are running
if( m.passable_ter_furn( dest_loc )
&& you.movement_mode_is( CMM_WALK )
&& m.open_door( dest_loc, !m.is_outside( you.pos() ) ) ) {
you.moves -= 100;
// if auto-move is on, continue moving next turn
if( you.is_auto_moving() ) {
you.defer_move( dest_loc );
}
return true;
}

maybe we could update avatar_action::move so if a gate is designated as AUTOPASS or AUTOCLOSE (example name), opening gate gets skipped. (it's only a suggestion, tho)

@ekaratzas
Copy link
Contributor Author

Thanks for the suggestion, I can take a look at that @scarf005 and see if I can come up with something.

Atm I've context switched to a different idea that I have altogether, but I'll come back to check out this approach.

@ekaratzas
Copy link
Contributor Author

@scarf005 I took a look at the move() function you pointed me to. I had no idea you could 'run over' a wooden gate without opening it, that's cool and something I'm going to start using!

I see what you mean about checking for a specific flag on the terrain and in that case, skip opening the door. It'd basically be the equivalent of the running check for gates.

What I don't like about that approach is that you can actually displace an animal into the closed gate as you come into the pasture. In other words, moving in the chicken coop while there's a chicken on the first tile of the coop would make you swap places with it. At least I was able to swap places with my horse while 'vaulting' over the wooden gate and the horse ended up on the closed gate lol :D

pic related

horse_on_closed_gate_lol

How I prevented that in the original PR was by enforcing the can-i-move-here check on the monster side of things.

All that being said, if we are not happy with the original approach, I am fine abandoning this PR so we can focus on other things, like my other PR which is tied to a broader idea I'm working on.

Lemme know.

@ekaratzas
Copy link
Contributor Author

No traction, I'm closing the PR!

@ekaratzas ekaratzas closed this Mar 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
JSON related to game datas in JSON format. src changes related to source code.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants