Skip to content

Conversation

@quietust
Copy link
Member

aside from the link removal stuff at the end, which might still be slightly different

Amends #5526

aside from the link removal stuff at the end, which might still be
slightly different
@quietust
Copy link
Member Author

Note: I don't have any fortresses with which to test this change - please verify before merging.

Copy link
Member

@chdoc chdoc left a comment

Choose a reason for hiding this comment

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

Apart from the few nitpicks below, I have let autotraining run for a few months based on this implementation, and have not noticed any bad behaviors or crashes.

Comment on lines 520 to 521
unit->military.squad_id = -1;
unit->military.squad_position = -1;
Copy link
Member

Choose a reason for hiding this comment

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

How about moving this before the if (squad) and turning the test into an early return if the squad is not defined, reducing the nesting level by one.

}
// remove entity squad link
df::historical_figure* hf = df::historical_figure::find(unit->hist_figure_id);
if (hf == nullptr || squad == nullptr)
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
if (hf == nullptr || squad == nullptr)
if (hf == nullptr)

assuming the test for the squad is turned into an early return

Copy link
Member Author

@quietust quietust Jul 29, 2025

Choose a reason for hiding this comment

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

Because the in-game logic will still clear user->military.squad_id + user->military.squad_position even if the squad doesn't actually exist anymore.

I suppose the case could be made for clearing those variables earlier, but I'm also replicating the order in which the game's own logic does it.

Copy link
Member

Choose a reason for hiding this comment

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

Yes, I wasn't suggesting to change the behavior. As it comes to the order of things, I don't see any volatile variables. So the real order is whatever the compiler makes of it, both for our code and the game code. I would prefer to see less nesting and not fetching the historical_figure if there is no squad. But then, this is all well and truly in the eye of the beholder. What I truly care about is that autotraining works, which it seems to do with his implementation.

@ab9rf ab9rf merged commit c2007f0 into DFHack:develop Aug 15, 2025
36 of 38 checks passed
@quietust quietust deleted the removeFromSquad branch November 4, 2025 21:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants