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

[CR] Hordes don't wander to 0,0 #74053

Merged
merged 4 commits into from
Jun 3, 2024

Conversation

RenechCDDA
Copy link
Member

Summary

Bugfixes "Hordes won't wander without a reason"

Purpose of change

Hordes(mongroup) would most often be initialized without specifying a target. This meant that the default value would be used - 0,0.

mongroup( const mongroup_id &ptype, const tripoint_abs_sm &ppos,
unsigned int ppop )
: type( ptype )
, abs_pos( ppos )
, population( ppop ) {
}

With wandering hordes set to on, hordes would receive a new target every 2.5 minutes. However, if wandering hordes was set to off... that never happened. (Most*) every horde would be laser-targeted as tripoint_abs_sm 0,0. Thus, depending on your orientation from 0,0 they would run in a specific direction.... this is why the reports were so confused.

Describe the solution

Don't rely on default constructed value of 0,0 to set the target of the horde.

Don't rely on wandering hordes being set to on, either...

Construct the default target of the horde as its position if target is unspecified.

For existing savegames, check if their targets are 0,0 and set target to the current position if so.

Describe alternatives you've considered

Get rid of the wandering hordes option, force it always on.

Testing

Load the provided save from #73725, check nearby hordes with debug. Their targets are all their current position instead of 0,0.

Additional context

Our monster group serialization (overmap::load_monster_groups specifically) will probably not like this very much? As each group will have a separate target, instead of serializing them all into one object they'll each need a separate object as they have different targets.

The debug menu additions were actually not at all helpful here, but no reason to throw them out.

@RenechCDDA RenechCDDA changed the title [CR] Horde dont wander to 0,0 [CR] Hordes don;t wander to 0,0 May 24, 2024
@RenechCDDA RenechCDDA changed the title [CR] Hordes don;t wander to 0,0 [CR] Hordes don't wander to 0,0 May 24, 2024
@github-actions github-actions bot added [JSON] Changes (can be) made in JSON Map / Mapgen Overmap, Mapgen, Map extras, Map display Spawn Creatures, items, vehicles, locations appearing on map [C++] Changes (can be) made in C++. Previously named `Code` <Bugfix> This is a fix for a bug (or closes open issue) labels May 24, 2024
src/overmap.cpp Outdated Show resolved Hide resolved
src/overmap.cpp Outdated Show resolved Hide resolved
@github-actions github-actions bot added the json-styled JSON lint passed, label assigned by github actions label May 24, 2024
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
@github-actions github-actions bot added BasicBuildPassed This PR builds correctly, label assigned by github actions astyled astyled PR, label is assigned by github actions and removed BasicBuildPassed This PR builds correctly, label assigned by github actions labels May 24, 2024
@PatrikLundell
Copy link
Contributor

If serialization depends on all groups having the same target the serialization logic is broken and needs to be fixed. Hordes shouldn't be synchronized even if they're enabled.

Sneaking hordes back in for people who disabled them and then later on enable the hordes anyway would be a dastardly deed.

@github-actions github-actions bot added the BasicBuildPassed This PR builds correctly, label assigned by github actions label May 25, 2024
@RenechCDDA
Copy link
Member Author

If serialization depends on all groups having the same target the serialization logic is broken and needs to be fixed. Hordes shouldn't be synchronized even if they're enabled.

Sneaking hordes back in for people who disabled them and then later on enable the hordes anyway would be a dastardly deed.

I'm not sure I conveyed it properly. This won't enable wandering behavior for worlds with it disabled, wandering behavior is technically always on. This just tells them to wander to their own location instead of to 0,0.

The serialization issue can be summarized by simply posting an example. Here's without the patch:

[{"type":"GROUP_ZOMBIE","population":10,"horde":true},[[4,60,0],[5,60,0],[5,276,0],[7,54,0],[7,60,0],[9,54,0],[9,62,0],[9,262,0],[9,275,0],[10,54,0],[10,60,0],[10,61,0],[10,245,0],[10,246,0],[11,60,0],[11,242,0],[11,247,0],[11,263,0],[12,247,0],[12,256,0],[12,262,0],[12,264,0],[12,275,0],[13,251,0],[13,253,0],[13,257,0],[13,259,0],[13,260,0],[13,270,0],[13,272,0],[14,48,0],[14,51,0],[14,57,0],[14,63,0],[14,232,0],[14,234,0],[14,237,0],[14,240,0],[14,244,0],[15,58,0],[15,236,0],[15,237,0],[15,240,0],[15,241,0],[15,243,0],[16,54,0],[16,61,0],[16,245,0],[17,54,0],[17,257,0],[18,54,0],[18,238,0],[18,252,0],[18,264,0],[18,267,0],[18,269,0],[18,273,0],[19,54,0],[19,245,0],[19,245,0],[19,255,0],[19,258,0],[19,259,0],[19,264,0],[19,273,0],[19,275,0],[20,56,0],[20,59,0],[20,65,0],[20,68,0],[20,235,0],[20,263,0],[20,275,0],[21,52,0],[21,56,0],[21,57,0],[21,61,0],[21,62,0],[21,66,0],[21,67,0],[21,69,0],[21,239,0],[21,242,0],[21,244,0],[21,268,0],[22,53,0],[23,52,0],[23,60,0],[23,263,0],[23,269,0],[23,275,0],[24,42,0],[24,47,0],[24,48,0],[24,49,0],[24,54,0],[24,55,0],[24,57,0],[24,60,0],[24,261,0],[24,263,0],[24,269,0],[25,49,0],[25,50,0],[25,51,0],[25,54,0],[25,55,0],[25,57,0],[25,60,0],[25,61,0],[26,23,0],[26,53,0],[26,60,0],[26,257,0],[27,256,0],[27,275,0],[28,21,0],[28,22,0],[28,52,0],[28,57,0],[28,60,0],[28,61,0],[28,262,0],[28,263,0],[29,19,0],[29,20,0],[29,53,0],[29,57,0],[30,19,0],[30,56,0],[30,57,0],[31,53,0],[31,54,0],[31,56,0],[32,15,0],[32,17,0],[32,20,0],[32,21,0],[33,17,0],[34,18,0],[34,74,0],[35,19,0],[35,74,0],[35,75,0],[36,18,0],[36,19,0],[36,69,0],[36,71,0],[36,72,0],[36,77,0],[36,78,0],[36,79,0],[36,82,0],[37,73,0],[37,76,0],[37,76,0],[37,77,0],[37,80,0],[37,129,0],[38,18,0],[39,74,0],[39,74,0],[39,75,0],[39,78,0],[39,79,0],[40,74,0],[40,75,0],[40,78,0],[40,79,0],[40,122,0],[40,125,0],[41,74,0],[41,78,0],[41,78,0],[42,81,0],[43,81,0],[43,83,0],[43,84,0],[43,111,0],[46,79,0],[46,121,0],[48,114,0],[48,116,0],[48,119,0],[48,127,0],[48,129,0],[49,111,0],[49,112,0],[49,115,0],[49,119,0],[49,123,0],[49,125,0],[49,127,0],[49,132,0],[51,121,0],[52,116,0],[52,117,0],[52,119,0],[53,118,0],[53,121,0],[54,121,0],[55,117,0],[55,120,0],[57,114,0],[57,115,0],[57,117,0],[57,121,0],[61,112,0],[63,17,0],[64,26,0],[65,32,0],[65,42,0],[67,38,0],[68,19,0],[68,28,0],[69,28,0],[69,38,0],[70,26,0],[70,38,0],[73,19,0],[74,18,0],[74,20,0],[74,23,0],[74,25,0],[74,28,0],[74,29,0],[75,25,0],[75,28,0],[75,35,0],[76,19,0],[76,108,0],[76,114,0],[77,108,0],[78,19,0],[78,109,0],[79,18,0],[79,27,0],[79,108,0],[80,22,0],[80,28,0],[80,29,0],[80,30,0],[80,34,0],[80,35,0],[80,104,0],[80,107,0],[80,111,0],[80,112,0],[80,113,0],[81,19,0],[81,22,0],[81,23,0],[81,40,0],[81,105,0],[81,106,0],[81,107,0],[81,110,0],[81,111,0],[81,115,0],[82,26,0],[82,33,0],[83,19,0],[83,32,0],[83,33,0],[83,39,0],[84,26,0],[84,42,0],[84,45,0],[84,141,0],[84,142,0],[85,26,0],[85,42,0],[85,44,0],[86,31,0],[86,32,0],[86,38,0],[86,42,0],[86,187,0],[87,31,0],[87,38,0],[87,43,0],[87,143,0],[88,43,0],[88,148,0],[88,180,0],[88,186,0],[89,136,0],[89,182,0],[89,185,0],[89,187,0],[90,40,0],[90,41,0],[90,44,0],[90,46,0],[90,139,0],[90,144,0],[90,186,0],[90,187,0],[91,13,0],[91,38,0],[91,41,0],[91,136,0],[91,141,0],[91,146,0],[91,149,0],[92,14,0],[92,31,0],[92,33,0],[92,35,0],[92,36,0],[92,42,0],[92,142,0],[92,185,0],[92,189,0],[93,16,0],[93,21,0],[93,32,0],[93,36,0],[93,143,0],[93,180,0],[93,189,0],[93,190,0],[93,191,0],[94,17,0],[94,42,0],[94,43,0],[95,42,0],[95,136,0],[95,143,0],[96,27,0],[96,43,0],[96,145,0],[96,187,0],[97,16,0],[97,186,0],[99,15,0],[103,227,0],[104,227,0],[107,220,0],[107,227,0],[108,222,0],[108,224,0],[108,228,0],[109,221,0],[109,224,0],[109,228,0],[111,221,0],[112,61,0],[112,213,0],[112,216,0],[112,220,0],[113,218,0],[113,220,0],[113,226,0],[114,60,0],[114,223,0],[114,229,0],[114,296,0],[114,297,0],[115,230,0],[116,60,0],[116,297,0],[117,60,0],[117,61,0],[117,297,0],[118,57,0],[118,62,0],[118,63,0],[118,212,0],[118,213,0],[118,214,0],[118,218,0],[118,220,0],[118,291,0],[118,293,0],[118,295,0],[118,298,0],[118,299,0],[119,54,0],[119,59,0],[119,62,0],[119,64,0],[119,214,0],[119,215,0],[119,221,0],[119,298,0],[119,300,0],[119,301,0],[120,60,0],[120,61,0],[120,297,0],[121,61,0],[121,220,0],[121,221,0],[121,296,0],[122,61,0],[122,297,0],[123,220,0],[124,221,0],[124,262,0],[124,263,0],[124,296,0],[125,259,0],[125,261,0],[126,258,0],[128,252,0],[128,256,0],[128,257,0],[128,263,0],[129,257,0],[129,261,0],[129,351,0],[130,264,0],[130,352,0],[131,258,0],[131,354,0],[131,355,0],[132,264,0],[133,259,0],[134,350,0],[134,351,0],[134,354,0],[135,255,0],[135,354,0],[136,350,0],[136,355,0],[137,355,0],[138,350,0],[139,296,0],[139,351,0],[140,288,0],[140,297,0],[140,347,0],[140,349,0],[140,355,0],[141,343,0],[141,344,0],[141,348,0],[141,349,0],[141,352,0],[141,353,0],[142,294,0],[142,295,0],[142,296,0],[142,350,0],[142,351,0],[143,289,0],[143,301,0],[143,351,0],[144,307,0],[144,308,0],[144,311,0],[144,313,0],[144,317,0],[144,318,0],[144,350,0],[144,351,0],[145,303,0],[145,307,0],[145,313,0],[145,314,0],[145,316,0],[145,342,0],[146,302,0],[146,303,0],[146,350,0],[147,303,0],[147,351,0],[148,290,0],[148,293,0],[148,305,0],[148,306,0],[148,308,0],[148,309,0],[148,311,0],[148,340,0],[149,298,0],[149,342,0],[151,294,0],[151,295,0],[152,294,0],[152,302,0],[152,303,0],[153,297,0],[156,303,0],[157,296,0],[157,297,0],[157,302,0],[159,302,0],[159,303,0],[160,7,0],[160,294,0],[160,302,0],[161,11,0],[161,295,0],[161,304,0],[161,307,0],[161,308,0],[162,6,0],[164,7,0],[165,6,0],[165,7,0],[166,4,0],[166,9,0],[167,4,0],[167,9,0],[167,10,0],[168,7,0],[169,7,0],[171,6,0],[171,7,0],[172,4,0],[181,146,0],[181,147,0],[182,147,0],[183,147,0],[184,105,0],[184,149,0],[185,103,0],[185,142,0],[185,144,0],[185,145,0],[185,149,0],[186,146,0],[187,146,0],[188,145,0],[188,147,0],[189,141,0],[189,142,0],[189,144,0],[190,103,0],[190,122,0],[190,124,0],[193,101,0],[193,102,0],[193,122,0],[194,114,0],[194,116,0],[194,117,0],[194,119,0],[194,120,0],[194,122,0],[194,123,0],[195,115,0],[196,112,0],[196,113,0],[196,116,0],[196,244,0],[196,248,0],[197,112,0],[198,112,0],[198,116,0],[198,123,0],[199,122,0],[199,248,0],[200,116,0],[200,117,0],[200,250,0],[200,253,0],[201,113,0],[201,117,0],[201,248,0],[201,249,0],[201,254,0],[203,112,0],[203,117,0],[204,254,0],[204,257,0],[204,259,0],[204,267,0],[205,118,0],[205,248,0],[205,258,0],[205,261,0],[206,255,0],[207,118,0],[207,214,0],[208,212,0],[209,208,0],[209,210,0],[209,211,0],[209,212,0],[209,213,0],[209,219,0],[209,255,0],[210,23,0],[210,210,0],[210,215,0],[210,253,0],[210,254,0],[210,257,0],[210,258,0],[210,259,0],[210,260,0],[210,261,0],[211,210,0],[211,250,0],[211,253,0],[211,257,0],[211,262,0],[211,264,0],[211,264,0],[212,6,0],[212,15,0],[212,18,0],[212,19,0],[212,23,0],[212,28,0],[212,31,0],[212,33,0],[212,212,0],[212,214,0],[212,215,0],[212,255,0],[212,266,0],[213,6,0],[213,18,0],[213,19,0],[213,21,0],[213,29,0],[213,210,0],[213,254,0],[213,266,0],[214,7,0],[214,8,0],[214,9,0],[214,16,0],[214,254,0],[214,266,0],[215,6,0],[215,7,0],[215,16,0],[215,22,0],[215,28,0],[215,215,0],[215,255,0],[215,255,0],[216,251,0],[216,257,0],[216,258,0],[216,259,0],[216,259,0],[216,268,0],[216,270,0],[217,17,0],[217,23,0],[217,250,0],[217,253,0],[217,257,0],[217,259,0],[217,260,0],[217,262,0],[217,263,0],[217,264,0],[217,265,0],[217,267,0],[217,270,0],[217,273,0],[217,275,0],[218,5,0],[218,7,0],[218,8,0],[218,9,0],[218,11,0],[218,12,0],[218,13,0],[218,15,0],[218,17,0],[218,21,0],[218,23,0],[218,26,0],[218,33,0],[218,234,0],[218,255,0],[218,260,0],[218,261,0],[218,277,0],[219,4,0],[219,10,0],[219,11,0],[219,12,0],[219,16,0],[219,18,0],[219,23,0],[219,24,0],[219,26,0],[219,27,0],[219,29,0],[219,39,0],[219,232,0],[219,235,0],[219,255,0],[219,255,0],[219,267,0],[219,276,0],[220,232,0],[220,233,0],[220,267,0],[220,281,0],[221,16,0],[221,260,0],[221,270,0],[221,274,0],[222,16,0],[222,233,0],[222,260,0],[222,264,0],[222,270,0],[222,270,0],[223,232,0],[223,261,0],[223,265,0],[223,265,0],[223,277,0],[224,8,0],[224,10,0],[224,13,0],[224,19,0],[224,28,0],[224,228,0],[224,229,0],[224,234,0],[224,235,0],[224,265,0],[224,267,0],[224,271,0],[224,271,0],[224,276,0],[224,282,0],[225,6,0],[225,20,0],[225,22,0],[225,26,0],[225,230,0],[225,236,0],[225,237,0],[225,237,0],[226,17,0],[226,233,0],[226,260,0],[226,260,0],[227,232,0],[227,233,0],[227,260,0],[227,264,0],[227,270,0],[228,265,0],[228,271,0],[228,276,0],[228,280,0],[229,233,0],[229,265,0],[229,281,0],[230,268,0],[230,272,0],[230,281,0],[231,260,0],[231,268,0],[231,272,0],[231,278,0],[232,26,0],[232,270,0],[232,271,0],[232,276,0],[233,22,0],[233,271,0],[234,143,0],[234,147,0],[235,136,0],[235,270,0],[235,271,0],[235,276,0],[235,280,0],[236,136,0],[237,142,0],[237,277,0],[237,281,0],[238,137,0],[238,280,0],[238,281,0],[240,136,0],[240,277,0],[241,137,0],[241,140,0],[241,271,0],[241,283,0],[242,137,0],[242,141,0],[243,271,0],[244,137,0],[244,265,0],[244,268,0],[244,270,0],[244,332,0],[244,338,0],[244,339,0],[244,341,0],[245,136,0],[245,137,0],[245,331,0],[245,333,0],[245,334,0],[245,335,0],[245,339,0],[245,340,0],[245,342,0],[246,129,0],[246,132,0],[246,133,0],[246,134,0],[246,135,0],[246,140,0],[246,147,0],[246,265,0],[247,130,0],[247,139,0],[247,140,0],[247,142,0],[247,146,0],[247,343,0],[248,136,0],[248,341,0],[248,342,0],[249,340,0],[250,137,0],[250,341,0],[251,128,0],[251,265,0],[252,129,0],[253,137,0],[253,265,0],[254,137,0],[289,264,0],[290,265,0],[292,264,0],[292,352,0],[293,264,0],[293,265,0],[294,258,0],[294,260,0],[294,261,0],[294,262,0],[294,263,0],[294,352,0],[295,267,0],[295,268,0],[296,265,0],[296,352,0],[296,353,0],[297,265,0],[297,353,0],[298,349,0],[298,354,0],[298,355,0],[299,265,0],[299,348,0],[299,350,0],[299,354,0],[300,352,0],[300,353,0],[301,264,0],[302,353,0],[303,353,0],[305,352,0]]]

And here's with the patch:

[{"type":"GROUP_ZOMBIE","population":10,"horde":true,"target":[108,228]},[[108,228,0]]],[{"type":"GROUP_ZOMBIE","population":10,"horde":true,"target":[109,221]},[[109,221,0]]],[{"type":"GROUP_SUBWAY_CITY","target":[222,233]},[[222,233,-2]]],[{"type":"GROUP_ZOMBIE","population":10,"horde":true,"target":[148,290]},[[148,290,0]]],[{"type":"GROUP_ZOMBIE","population":10,"horde":true,"target":[109,224]},[[109,224,0]]],[{"type":"GROUP_SUBWAY_CITY","target":[109,225]},[[109,225,-2]]],[{"type":"GROUP_ZOMBIE","population":10,"horde":true,"target":[109,228]},[[109,228,0]]],[{"type":"GROUP_SUBWAY_CITY","target":[110,225]},[[110,225,-2]]],[{"type":"GROUP_ZOMBIE","population":10,"horde":true,"target":[112,61]},[[112,61,0]]],[{"type":"GROUP_ZOMBIE","population":10,"horde":true,"target":[112,213]},[[112,213,0]]],[{"type":"GROUP_ZOMBIE","population":10,"horde":true,"target":[112,216]},[[112,216,0]]],[{"type":"GROUP_ZOMBIE","population":10,"horde":true,"target":[112,220]},[[112,220,0]]],[{"type":"GROUP_ZOMBIE","population":10,"horde":true,"target":[113,218]},[[113,218,0]]],[{"type":"GROUP_RIVER","population":3,"target":[342,326]},[[342,326,0]]],[{"type":"GROUP_ZOMBIE","population":10,"horde":true,"target":[113,220]},[[113,220,0]]],[{"type":"GROUP_ZOMBIE","population":10,"horde":true,"target":[113,226]},[[113,226,0]]],[{"type":"GROUP_RIVER","population":9,"target":[315,203]},[[315,203,0]]],[{"type":"GROUP_ZOMBIE","population":10,"horde":true,"target":[114,60]},[[114,60,0]]],[{"type":"GROUP_ZOMBIE","population":10,"horde":true,"target":[114,223]},[[114,223,0]]],[{"type":"GROUP_ZOMBIE","population":10,"horde":true,"target":[128,252]},[[128,252,0]]],[{"type":"GROUP_ZOMBIE","population":10,"horde":true,"target":[114,229]},[[114,229,0]]],[{"type":"GROUP_ZOMBIE","population":10,"horde":true,"target":[114,297]},[[114,297,0]]],[{"type":"GROUP_ZOMBIE","population":10,"horde":true,"target":[115,230]},[[115,230,0]]]

We save a lot of save data (no pun intended) by grouping the hordes together when their type, population, and horde values are the same, then serializing them as one huge block of tripoints. When it is deserialized instead of reading each group individually, it simply goes through the tripoint list and copy-pastes the same group into each spot, since it knows each group (of this particular binning) is the same. When they have different targets it cannot do that.

The code in question may be more informative than my ability to explain:

for( JsonArray mongroup_with_tripoints : jsin ) {
mongroup new_group;
new_group.deserialize( mongroup_with_tripoints.next_object() );
JsonArray tripoints_json = mongroup_with_tripoints.next_array();
tripoint_om_sm temp;
for( JsonValue tripoint_json : tripoints_json ) {
temp.deserialize( tripoint_json );
new_group.abs_pos = project_combine( pos(), temp );
add_mon_group( new_group );
}

@PatrikLundell
Copy link
Contributor

Your description of the movement enabling wasn't particularly clear (to me at least). If, however, it means they wander in place, that should be fine.

If you're only binning matching hordes that would be reasonable. I'd address the differing destinations by replacing the current absolute tripoint locations with a pair of location and destination, allowing you to still factor out the common part.

@TealcOneill
Copy link
Contributor

Might also fix #20363? At least the first part. I think it's two separate issues meshed together and not explained well.

@Maleclypse Maleclypse merged commit 21e776f into CleverRaven:master Jun 3, 2024
28 checks passed
@RenechCDDA RenechCDDA deleted the horde_dont_wander_to_zero branch June 3, 2024 02:10
@GuardianDll
Copy link
Member

Why do they need to wander anywhere? Can't they just transform to horde once they leave the reality bubble, instead of menacingly moving to that direction they picked, sometimes ignoring everything else like enemy (character/npc) presence?

@RenechCDDA
Copy link
Member Author

Why do they need to wander anywhere? Can't they just transform to horde once they leave the reality bubble, instead of menacingly moving to that direction they picked, sometimes ignoring everything else like enemy (character/npc) presence?

Wandering behavior is very very tied into our systems. For example, when you make noise that they can't see - wandering. If they're chasing you but you duck out of sight - wandering.

Wandering is what causes them to do the moving. They're set to wander towards 0,0 when they transform from being a [horde] into actual [monsters]. What this PR has done is instead of going towards 0,0... they simply wander towards their current position.

This is also not accomplishable by setting wander desire - because of course it's possible to modify wander desire without modifying the wander destination. And if that happened... they'd just start sprinting towards 0,0 again.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
astyled astyled PR, label is assigned by github actions BasicBuildPassed This PR builds correctly, label assigned by github actions <Bugfix> This is a fix for a bug (or closes open issue) [C++] Changes (can be) made in C++. Previously named `Code` [JSON] Changes (can be) made in JSON json-styled JSON lint passed, label assigned by github actions Map / Mapgen Overmap, Mapgen, Map extras, Map display Spawn Creatures, items, vehicles, locations appearing on map
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Zombie hordes flee north
5 participants