Skip to content

More mod compat and bug fixes, add QoL Ui and refactor some command stuff#2251

Merged
schombert merged 19 commits intoschombert:mainfrom
ZombieFreak115:more-mod-compat-fixes
Apr 13, 2026
Merged

More mod compat and bug fixes, add QoL Ui and refactor some command stuff#2251
schombert merged 19 commits intoschombert:mainfrom
ZombieFreak115:more-mod-compat-fixes

Conversation

@ZombieFreak115
Copy link
Copy Markdown
Contributor

@ZombieFreak115 ZombieFreak115 commented Apr 11, 2026

  • Increase the max event options and max national mod to be able to cope events and modifiers from GFM and TGC.

_ Change factory bonuses to be an array instead of 3 diffrent fields. Up the max factory bonuses to 6 to add support for more mods' bonuses.

  • Up the dcon max factory count from 20k to 100k, it is quite easy to reach the 20k cap (GFM reached it in 1898).

  • Add legacy is_colonial_crisis trigger, which was missing previously.

  • Move "update_events" call to after "ai_take_decisions" so that events popped as a result of a decision are popped immediately.

  • Add ai_take_decisions call to "execute_start_game", so that ai make take decisions at game start.

  • Move many calls which writes to "state.selected_armies" and "state.selected_navies" to execute on UI thread to prevent race conditions with UI reading it while the update thread is writing.

  • Fix bug in crisis peacedeals in which it would always send a peacedeal with all wargoals checked, even though they weren't checked in the UI.

  • Fix tax_efficiency national modifier being 100x less effective than it should be, as it used the same function as the "tax_eff" technology modifier.

  • Add icons for colonization, which were previously missing.

  • Add guard against invalid sea trade routes which become invalid due to a state being split up and losing its coast.

  • Refactor some commands such as splitting units to be more uniform and AI being able to use the same functions as the player for checking if they are allowed to do it, but with a diffrent template parameter. Eventually this is the method i will use to try to centralize "can ai do this thing" check in ai code directly, with a vectorized version if needed.

ZombieFreak115 and others added 18 commits April 5, 2026 14:24
…upport. Add support for clr_country_flag in country history file (also used by GFM).
…ng allowed, up from 3 to support mods with more bonuses. Fix edge case with unit splitting where a unit of 2 or 3 units with all seperate unit types could not be split.
… as GFM. Add ui displaying how many wargoals would be added in add wargoal screen. Do not display more than 10 tooltips for navies/armies to avoid wall of text.
…r. Change the can_change_land_unit_type functions to work on a single item at a time. Make the AI code use these functions directly.
…register immediately. Change all calls to select,deselect and clearing selected armies/navies to be on UI thread to avoid potential UB.
Make sure reserves' dig in also get decremented in battles.

Fix bug in which the battle finished popop wouldnt pop up because there woundt be a valid lead defender or attacker anymore if all armies on one side were stackwiped.
Comment thread src/common_types/constants_dcon.hpp Outdated
railroad, fort, naval_base, bank, university, last, factory, province_selector, province_immigrator
};
constexpr inline int32_t max_building_types = 5;
constexpr inline size_t MAX_PRODUCTION_TYPE_BONUSES = 6;
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

generally, ALL_CAPS names are reserved for defines and macros; I know that I have been letting this slip a bit, but ...

In any case, you should touch base with peter regarding the performance of this change. The issue with increasing the number of bonuses is that the all involve running triggers as part of the econ update, and the econ update is already heavy.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I see, i changed all the ALL_CAPS constants that i remember i added to normal snake_case.

std::copy(initializer.begin(), initializer.end(), data());
}

fixed_size_vector& operator=(fixed_size_vector<data_type, capacity> const& other) noexcept {
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

you probably need the appropriate move and copy constructors as well

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Added appropriate constructors which should work

Comment thread src/common_types/container_types.hpp Outdated
}
}
data_type& back() {
return _storage.back();
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

these will return the end of the storage array, presumably, and not the last "live" element

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Yup, i changed it

Comment thread src/common_types/container_types.hpp Outdated
auto end() {
return iterator(data(), size());
}
auto rbegin() {
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

these functions are supposed to return reverse iterators; not only should rbegin return an iterator that points to the last item in the collection, but incrementing it should advance to the previous element, etc. It is perfectly fine to omit these functions if you don't want to implement.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I replaced them with proper reverse iterators from std::array, should work now i think

Comment thread src/common_types/container_types.hpp Outdated
}
void resize(size_t new_size) {
if(new_size < size()) {
std::fill_n(_storage[new_size - 1], size() - new_size, data_type{ });
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

if new_size is 0, this would attempt to fill_n starting from position -1, which is probably not the intended behavior.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Yep, fixed it

Comment thread src/nations/nations.cpp

static tagged_vector<fixed_bool_t, dcon::trade_route_id> to_delete;
to_delete.resize(state.world.trade_route_size());
std::fill(to_delete.begin(), to_delete.end(), false);
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

While this isn't inefficient, it doesn't feel very efficient either, because in our expected use case here we probably won't be deleting routes very often, but this is going to allocate a vector full of bools, clear then, and then eventually iterate over all the routes to check if one should be deleted. For the expected situation in which deletions are rare, my feeling is that a normal vector holding the ids to delete that you push to, and then sort prior to the deletion loop ( so you can call delete on just the is in the vector ) would be more efficient in the typical cases, since in most cases nothing will ever be added, so it will remain empty with no memory allocated, the sort will exit immediately, and the loop over its contents to do the deletions will exit immediately.

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

That said, I see that the routes to be deleted are discovered in parallel, which complicates things ...

Copy link
Copy Markdown
Owner

@schombert schombert Apr 11, 2026

Choose a reason for hiding this comment

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

Perhaps it would be better to delete them in advance outside the parallel work here. Finding the coastal "capitals" will fail for the sea routes in the case that state_is_coastal fails for either of them (that is cheaper than the capital finding function which compares populations). That may be a cheapish loop to run in reverse order on the trade routes. Then they could be deleted as found without having to make a separate storage container for them.

Copy link
Copy Markdown
Owner

@schombert schombert Apr 11, 2026

Choose a reason for hiding this comment

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

On third thought, maybe your first approach here is as good as it gets, since even doing the above you still end up looping over all the trade routes one additional time (in the pre-delete loop instead of the post delete loop).

... so ignore all my comments here I guess

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Peter and i were also discussing an alternative solution which was to basically run a full trade route update on a daily tick if any provinces changed owners in the previous tick (via a flag being set on province ownership changing). I went with this solution instead cause i recall there was a reason to not update it that often (iirc its a very heavy update).

@schombert schombert merged commit de59188 into schombert:main Apr 13, 2026
5 checks passed
@ZombieFreak115 ZombieFreak115 deleted the more-mod-compat-fixes branch April 19, 2026 09:57
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.

2 participants