Welcome

Please register for Total War Access to use the forums. If you're an existing user, your forum details will be merged with Total War Access if you register with the same email or username. For more information please read our FAQ’s here.

Categories

script_unit.name is not unique - bugs script_ai_planner if there is more than 1 reinforcing army

paperpancakepaperpancake Registered Users Posts: 28

Build 1.12.1

(but this bug has existed for years)

Summary:

When using the Script AI Planner in a battle with more than one reinforcing army from the same faction, the Script AI Planner thinks some of the reinforcements are duplicates and so ignores those reinforcements.

Details:

- In lib_battle_script_ai_planner.lua, the function script_ai_planner:add_sunits expects script_unit.name to be unique. If two units share a name, only one gets added while the other is ignored.

- In lib_battle_script_unit.lua, a comment claims that script_unit.name is unique, but it doesn't seem to be if there is more than 1 reinforcing army from the same faction. It's not obvious from the script, because you might expect army_num to be different for each reinforcing army. However, for each reinforcing army from the same faction, the alliance_num and army_num will be the same (usually 1 if it's the player's armies), so if script units are created using numerical references, each reinforcing army's general will have a script_unit.name of "1:1:R_1", the second unit in each reinforcing army will have a script_unit.name of "1:1:R_2", etc.

To see that script_unit.name is not unique:

1. Enable console logging

2. I've attached a script to this post that just creates script_unit objects for all the player's units and outputs script_unit.name. Put that script wherever you like to test scripts for battle, such as battle_startup_test_scripts_here() in working_data/script/_lib/mod/test_script_here.lua

3. Start a battle using at least three friendly armies from the same faction (at least two reinforcing armies).

4. Once the battle loads, inspect the console log file. Notice that multiple units have script names of "1:1:R_1" even though they have different unique_ui_ids. Also notice that there's nothing special about their script_unit.unit:name that would cause them to be split up into different generated_armies, so there will be conflicts whenever a unique name is expected, as is the case in script_ai_planner:add_sunits.

To fix:

Hambango's simple solution was to replace the line in script_unit:new that currently sets new_ref = "R_"..reinforcing_ref and change it to new_ref = "R_" .. tostring(i) .. "_" .. reinforcing_ref;.

Leave a Comment

BoldItalicStrikethroughOrdered listUnordered list
Emoji
Image
Align leftAlign centerAlign rightToggle HTML viewToggle full pageToggle lights
Drop image/file