-
Notifications
You must be signed in to change notification settings - Fork 491
Don't include raiding units in Units::isActive; make getPosition return invalid coords #4959
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
base: develop
Are you sure you want to change the base?
Changes from all commits
e2f1598
6f51b36
b0da75d
556a8bd
8d1ddb7
6f196e2
2750fcf
e9158d4
2995ab9
84e9a09
7664545
2cd932a
fdf8217
a53ed8b
342afcc
b618d45
33aa7db
15547fb
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -128,7 +128,11 @@ constexpr uint32_t exclude_flags2 = ( | |
|
|
||
| bool Units::isActive(df::unit *unit) { | ||
| CHECK_NULL_POINTER(unit); | ||
| return !unit->flags1.bits.inactive; | ||
| if (unit->flags1.bits.inactive) | ||
| return false; | ||
| else if (unit->flags1.bits.move_state || unit->flags1.bits.can_swap) | ||
| return true; // These are always unset when leaving the map | ||
| return linear_index(world->units.active, &df::unit::id, unit->id) >= 0; | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I did a check on my fort, and all of my units in I went through all the uses of I don't fully understand
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That call to That test is not acceptable in a high-velocity code path. If we need this information in a high-velocity code path, we need to figure out a way to cache it (on an intra-tick basis) in a manner that doesn't require thousands of scattered reads every time it's used. For example, I'm on board with offering this as a secondary
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That's considering the flag checks that should reduce it to raiding units only, not all active? And given those units shouldn't even be checked when properly iterating Can we keep a cache directly in the Units module? Where would we maintain it from? If there's a second predicate, that means you need one for |
||
| } | ||
|
|
||
| bool Units::isVisible(df::unit *unit) { | ||
|
|
@@ -665,7 +669,8 @@ bool Units::isGreatDanger(df::unit *unit) { | |
|
|
||
| bool Units::isUnitInBox(df::unit *u, const cuboid &box) { | ||
| CHECK_NULL_POINTER(u); | ||
| return box.containsPos(getPosition(u)); | ||
| auto pos = getPosition(u); | ||
| return pos.isValid() ? box.containsPos(pos) : false; | ||
| } | ||
|
|
||
| bool Units::getUnitsInBox(vector<df::unit *> &units, const cuboid &box, std::function<bool(df::unit *)> filter) { | ||
|
|
@@ -750,6 +755,8 @@ bool Units::getCitizens(vector<df::unit *> &citizens, bool exclude_residents, bo | |
|
|
||
| df::coord Units::getPosition(df::unit *unit) { | ||
| CHECK_NULL_POINTER(unit); | ||
| if (!isActive(unit)) | ||
| return df::coord(); | ||
| if (unit->flags1.bits.caged) { | ||
| if (auto cage = getContainer(unit)) | ||
| return Items::getPosition(cage); | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -446,7 +446,7 @@ static void handle_missing_assignments(color_ostream &out, | |
| if (!hf || hf->died_year > -1 || was_expelled(hf)) | ||
| continue; | ||
| if (auto unit = df::unit::find(hf->unit_id)) { | ||
| if (Units::isActive(unit) && !Units::isDead(unit) && active_unit_ids.contains(unit->id)) { | ||
| if (!Units::isDead(unit) && Units::isActive(unit) && active_unit_ids.contains(unit->id)) { | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Moved Or maybe switch to directly testing the |
||
| // unit is still alive on the map; assume the unassigment was intentional/expected | ||
| continue; | ||
| } | ||
|
|
@@ -458,7 +458,7 @@ static void handle_missing_assignments(color_ostream &out, | |
| auto spouse_hf = df::historical_figure::find(spouse_hfid); | ||
| auto spouse = spouse_hf ? df::unit::find(spouse_hf->unit_id) : nullptr; | ||
| if (spouse_hf && share_with_spouse) { | ||
| if (spouse && Units::isActive(spouse) && !Units::isDead(spouse) && active_unit_ids.contains(spouse->id)) | ||
| if (spouse && !Units::isDead(spouse) && Units::isActive(spouse) && active_unit_ids.contains(spouse->id)) | ||
| { | ||
| DEBUG(cycle,out).print("assigning zone %d (%s) to spouse %s\n", | ||
| zone_id, ENUM_KEY_STR(civzone_type, zone->type).c_str(), | ||
|
|
||
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.
This looks like a backwards-incompatible change to the API that should at least be documented.
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.
Probably. Everyone would've assumed raiding units didn't pass the "active" test, and the code hasn't been touched in 7-13 years, so I didn't suspect it would break anything (more than Toady already did).