Total War: WARHAMMER III

Total War: WARHAMMER III

Attack Move and Countercharge (WH3)
paperpancake  [developer] 30 Mar, 2023 @ 12:19pm
Ideas for improvements
From the mod description: I wish that this mod would auto-unlock units if you try to give them new orders, but scripting limitations for this game prevent that. This is the best I could come up with. The main issues I run into are that the command callback handlers don't indicate which unit received an order, and that they don't differentiate between orders given by the user and orders from other sources like unit controllers and AI Planners.

--------------------

I've spent months trying to unsuccessfully think of or create workarounds, but perhaps I'm thinking along the wrong lines. I'm not perfect and would love to discover that there's a better solution that I've missed, so feel free to try your own solutions or to discuss possibilities here.
Last edited by paperpancake; 2 Apr, 2023 @ 10:42pm
< >
Showing 1-9 of 9 comments
paperpancake  [developer] 30 Mar, 2023 @ 12:31pm 
GeneralKong said in the comments:

"Or even add the option (or leave it for another mod entirely if you feel this does not fit the scope of this mod) to have it where units can be set to just attack anything nearby, but can still be given new orders and such (an auto attack order basically)

...having it where units can be ordered about as normal, just with Attack Move always on

so basically, I can understand having the order lock due to countercharge, but having it where you disable countercharge entirely, and this will allow you to attack move and give orders otherwise with them being locked"

-----------------

My reply:

@GeneralKong Ah, I see the subtle difference now. Unfortunately, I believe that an implementation of your suggestion would have its own quirks due to technical limitations of scripted mods. For example, if your unit got close enough to start charging an enemy and you wanted to cancel the charge to move away, this would be impossible. Also, the mod would need to decide whether to allow order changes once an attack order was given. If they weren't allowed, then the mod wouldn't work with ranged units (because of how current_target is reported), and the melee units couldn't react to new situations, so they could be easily baited. If attack order changes were allowed, then it could interfere with player-given attack orders. For example, if you wanted to attack an enemy back-line unit and your unit first needed to pass close to an enemy front-line unit, it would attack the front-line unit instead. To reiterate, not all of these are problems with your idea. The biggest problems are caused by scripting limitations that (I think) prevent a straightforward implementation of your suggestion.

If you're curious for more details about why this is so technically fraught, the underlying technical problems are that mods can't tell which unit is receiving an order and also can't tell whether the order came from the user or from a mod. This means that in some common situations the mod wouldn't know whether it needed to issue a new order or keep the existing order. Even if you use no other mods besides this one, I don't think this mod can't tell. You'd think that it could just un-register the command handler just for the duration of the order, but that doesn't work because the orders are queued and don't fire events until later in the game loop. You'd think that it could just remember what orders this mod gave and look for new orders that don't fit, but a straightforward implementation isn't possible because command handlers don't specify which unit received the order, and an implementation that looks at current targets has many exceptions that start piling up due to a combination of game-loop order and also due to how current_target and ordered_position are handled in various situations. (I tried to do something like that with my Aerial Pursuit mod, for example. There is a config option in that mod to turn on the beta for auto-unlocking, but it had so many false positives and negatives that I disabled it by default.)

(Command listeners distinguishing between player orders and scripted orders has been on my wishlist since WH2.)
GeneralKong 30 Mar, 2023 @ 12:43pm 
ahhh I understand, thank you for the in-depth explanation.

Its a shame that the game is limited in that way when it comes to scripting, we can only hope that at some point later in WH3 life cycle it will open up, but I doubt it.
paperpancake  [developer] 30 Mar, 2023 @ 12:57pm 
CA did make more things accessible to modders in WH3 than were available in WH2: the context viewer, Cco objects, several new functions (even though current_target has quirks, it is still helpful for my mods and it wasn't available to modders until WH3), and probably more that I'm not even aware of. So I haven't lost hope yet. :)
GeneralKong 3 Apr, 2023 @ 7:44am 
ahhh that is good to hear, I am glad they have improved things, that increases my hope slightly that we might see that scripting capability down the line.

I am curious, are you able to add a toggle for magic units that during attack move and such, that they will use spells/abilities?
paperpancake  [developer] 3 Apr, 2023 @ 11:14am 
@GeneralKong For right now, at least, I don't anticipate adding that for this mod. I think that it's technically possible, but I think it would require a fair bit of work because the conditions for using each type of spell/ability would need to be accounted for within the script. Other projects would take priority for me, like improving how AI General 3 chases units after battle.
GeneralKong 3 Apr, 2023 @ 3:49pm 
thats understandable, and will look forward to the AIG3 update
shadow_sc 14 Nov, 2024 @ 7:36pm 
I am not a veteran modder, but just mention about my thought.
I read the just good babysetter mod's script, but I am not sure whether I have fully understood it. There's a piece of code:

local function attack_cb(event)
local unit = event:battle_unit()
local unit_id = unit:unique_ui_id()
if (not unit:is_controllable()) or
(not unit:is_player_controlled()) or
unit:is_behaviour_active("defend") or
unit:is_script_controlled() or
unit:is_ai_controlled() or
is_pancake_controlling_by_id(unit_id) then
return
end

It seems that event:battle_unit() can be used to figure out which unit received the order(this is for attack order but others may be similar).
And a bunch of functions shaped like is_xxx_controlled() can be used to find out who is in control of the unit. Though this does not directly mean where the order come from, but can be used to filter the orders only when the unit is controlled by player.
shadow_sc 28 Nov, 2024 @ 8:38am 
I was trying to stick this mod and Just Good Babysitter together, and I seemed to have found a way to recognize auto order and manual order.

First I use two functions attack_cb and non_attack_cb to monitor all the orders, no matter where it is from, if a unit is in attack-move mode, this mod may automatically order it to attack nearby enemies and restore the move order after that. Player can also give attack or move order at any time.
I set a rule that, when player gives a move order, the unit is changed to attack-move mode to its destination. When already in attack-move mode, player's another move order will cancel the attack-move mode and perform a normal move. And a player's attack order should always cancel the attack-move mode. But when in attack-move mode, the auto given move and attack order should not change the mode.
To achieve this, in function check_attack_move_orders, before the auto order is given, a flag named self.auto_order_flag[current_friendly_id] is set to true, this auto order will soon be caught by the cb functions, so the two cb functions can check this flag to identify whether the order captured is given by this mod or by user. Of course this flag should be set to false after either situation.

I made a prototype mod to prove the feasibility, but I'm not a veteran modder so the code looks quite messy, and I actually just stuck the two mods together without fully understanding them, I don't know what cco is at all and can not find a document about it.
https://steamhost.cn/steamcommunity_com/sharedfiles/filedetails/?id=3373356409


This prototype kinda works, but sometimes not, maybe a move order to cancel the attack-move mode is given, but the mode is not cancelled immediately so the unit tried to move or attack again, then I click again but it brings the attack-move mode back again, and I should give a third order to cancel it again...
I think that this is because the function is implemented by using several callback functions so some synchronize problem may happen when orders are given to frequently, maybe the state change should be recorded and processed altogether in one timer callback, that is check_attack_move_orders function, but this is too hard for me without fully understanding your mod for now.

Notice that I didn't use the toggle attack-move mode button at all, again, I just made a prototype for proof. You can use this button to make the attack-move mode for example only turned on by button but cancelled by any manual order.
And also there's another suggestion, when a move order is caught, checks can be made that is the target the same as the recorded move order, to identify whether the move order is given to restore the movement or a new one.
paperpancake  [developer] 28 Nov, 2024 @ 2:15pm 
@shadow_sc My reply is short for now. I'm away from my computer and won't be able to look into this for quite a while (possibly into the new year), but in the meantime, if you're interested in Cco and other scripting documentation, you can find it here:
https://chadvandy.github.io/tw_modding_resources/index.html

(The documentation is also sometimes included in the game files themselves.)

If you want to find a community of modders, including some that have written tutorials on Cco, the Modding Den has a very active discord and a sometimes updated wiki.
< >
Showing 1-9 of 9 comments
Per page: 1530 50