-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
faction camp: menial labor uses the zone autosort feature #28571
faction camp: menial labor uses the zone autosort feature #28571
Conversation
6409278
to
ec6d52a
Compare
Current status: the NPC does some sorting, taking up time and freezing PC activity. I don't think that's right. I think the issue is that |
The problem is that Also, letting npcs sort may cause some strange behavior if the player defines new zones during sorting. Edit: Looks like new unsorted zones will be sorted from but not make use of the caching. |
82e99c7
to
f96cf58
Compare
e20e588
to
e7b01b1
Compare
@ifreund if you have a chance, please review or playtest. thanks! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good, still need to fetch and test though.
Changing zone_manager::get_num_processed()
to
int zone_manager::get_num_processed( const tripoint &src )
{
auto it = num_processed.find( src );
if( it != num_processed.end() ) {
return it->second;
}
// A zone was added while sorting, so add it to the cache.
return num_processed[src] = 0;
}
should fix the minor caching issue I brought up.
Edit: Need to de-constify get_num_processed
then of course.
e7b01b1
to
57284ed
Compare
Shoot, somehow it took me until now to realize that this actually totally breaks caching if the player decides to remove items from the unsorted zone. What we need to do is clear the cache then restart the activity one extra time the first time we think we are done. There's a low chance that could still leave some items unsorted, but I think that's not a huge deal. |
I will address your caching concerns tomorrow when I am slightly less brain-fried. |
Alright just to flesh out what I said about caching a bit:
Hopefully that all makes sense. |
57284ed
to
7129f0c
Compare
Add a function to check that there is at least one zone nearby that is a loot destination.
player:: uses has_destination to indicate a local destination while npc:: uses has_destination to indicate an omt destination. This is confusing, so rename the npc:: functions to *_omt_destination.
Add support for allied NPCs performing player_activity by calling activity.do_turn() and having the ability to navigate through activity destinations. NPCs that are unloaded while performing a player_activity get the delta time bonus moves when they are reloaded. They can then perform their player_activity backlog is empty. When they have completed all player_activity, their remaining moves are zeroed and they return to normal operation.
pass player &p to the underlying functions and adjust that player's moves, not g->u. Handle the new corner case of player &p not being inbounds of g->m, which can't happen if p is g->u but can happen if it is an NPC. Some minor incidental cleanups of the code.
Get rid of the confusing sort point interface and replace it with the slightly better supported zone interface. Have NPCs assigned to menial labor stay on the map and sort loot in real time. Adjust the distribute food mission to use a new zone "camp food."
7129f0c
to
d5c53a8
Compare
jenkins rebuild |
Resolved the caching issue by calling end_sort() on any exit from the function. Added logic to handle the NPC leaving the reality bubble by unloading them and then giving them a lot of bonus moves when they're loaded back into the reality bubble. It seems to work in my tests but could use more testing. |
Summary
SUMMARY: Features "faction camp: menial labor uses the zone autosort feature"
Purpose of change
Fixes #25397
Fixes #28880
Fix faction camp menial labor sorting by making it use the existing zone autosort feature. As a side effect, add the infrastructure for NPCs performing player activities on an ongoing basis.
Describe the solution
Add a function to clzones to determine if there are any loot zones nearby.
Alter the npc
*_destination
functions so it is clear that deal with omt destinations.Add infrastructure to npcmove to let friendly NPCs perform player activities using the NPC_MISSION_ACTIVITY mission. NPCs gain bonus moves from elapsed time during
npc::on_load()
if they have an activity, and lose those bonus moves when the activity is complete and their activity backlog is emptyUpdate do_turn_move_loot to support NPCs instead of the player performing the activity. Handle a weird NPC only corner case where the NPC is still active but not in the bounds of map by unloading them.
Change validate_sort_points to check if there is an unsorted loot zone, sorted loot zone, and camp food zone nearby. Change the Distribute Food pseudo mission to take food from the camp food zone. Change the Menial Labor mission to have the NPC perform the loot sorting activity using the infrastructure set up earlier in this PR.
Describe alternatives you've considered
Leaving the NPC in the overmap buffer and copy-pasting the do_activity_move_turn code into menial_return is easier but not the best solution.
Additional context