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

optimize sorting loot activity #79229

Closed
wants to merge 1 commit into from

Conversation

o175
Copy link
Contributor

@o175 o175 commented Jan 18, 2025

If this commit is applied it will prevent PC running to sorted zones.

It was made because PC was running across the map when there was no items to move

Summary

Bugfixes "Sorting loot: stop player running to items that's not going to be moved"

Purpose of change

Player or NPC were travelling all across the map to unsorted loot zone with items that does not have a valid destination stockpile. This was annoying and time consuming. NPCs were perceived as being dumb

Describe the solution

The issue was there because we did not check in the "THINK" stage of activity if unsorted zone tile has any items that require action. I copied all the logic from the "DO" stage carefully to predict if we need to run to the source tile at all.

Describe alternatives you've considered

I thought about extracting the logic to separate function instead of mimicking it but it would require a full rewrite of the DO stage. And I'm not yet comfortable with tasks of this size.

Testing

I did the ./tests/cata_test and a lot of manual testing to prevent any regressions:
I checked cases with disabling source and target zones, stripping corpses, unloading containers, custom loot target zones, removing mods from a gun

Additional context

After this change NPC will think better about his destination and stop wasting his time running between stockpiles. This makes him 'smarter' for the player.

If this commit is applied it will prevent PC running to sorted
zones.

It was made because PC was running across the map when there was not
items to move
@github-actions github-actions bot added [C++] Changes (can be) made in C++. Previously named `Code` new contributor <Bugfix> This is a fix for a bug (or closes open issue) labels Jan 18, 2025
bool unload_corpses = false;

std::vector<zone_data const *> const zones = mgr.get_zones_at( src, zone_type_UNLOAD_ALL,
_fac_id( you ) );
Copy link
Contributor

Choose a reason for hiding this comment

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

[JSON & C++ formatters] reported by reviewdog 🐶

Suggested change
_fac_id( you ) );
_fac_id( you ) );

Comment on lines +2119 to +2120
for( zone_data const *zone : zones )
{
Copy link
Contributor

Choose a reason for hiding this comment

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

[JSON & C++ formatters] reported by reviewdog 🐶

Suggested change
for( zone_data const *zone : zones )
{
for( zone_data const *zone : zones ) {

Comment on lines +2137 to +2139
if( vp )
{
for( const item& it : vp->items() ) {
Copy link
Contributor

Choose a reason for hiding this comment

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

[JSON & C++ formatters] reported by reviewdog 🐶

Suggested change
if( vp )
{
for( const item& it : vp->items() ) {
if( vp ) {
for( const item &it : vp->items() ) {

Comment on lines +2142 to +2144
} else
{
for( const item& it : here.i_at( src_loc ) ) {
Copy link
Contributor

Choose a reason for hiding this comment

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

[JSON & C++ formatters] reported by reviewdog 🐶

Suggested change
} else
{
for( const item& it : here.i_at( src_loc ) ) {
} else {
for( const item &it : here.i_at( src_loc ) ) {

Comment on lines +2151 to +2152
for( const item * it : items )
{
Copy link
Contributor

Choose a reason for hiding this comment

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

[JSON & C++ formatters] reported by reviewdog 🐶

Suggested change
for( const item * it : items )
{
for( const item *it : items ) {

Comment on lines +2221 to +2222
if( !has_items_to_work_on )
{
Copy link
Contributor

Choose a reason for hiding this comment

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

[JSON & C++ formatters] reported by reviewdog 🐶

Suggested change
if( !has_items_to_work_on )
{
if( !has_items_to_work_on ) {

@o175 o175 closed this Jan 18, 2025
@Zireael07
Copy link
Contributor

Why close?

@o175
Copy link
Contributor Author

o175 commented Jan 18, 2025

@Zireael07 I need to update master first

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
<Bugfix> This is a fix for a bug (or closes open issue) [C++] Changes (can be) made in C++. Previously named `Code` new contributor
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants