Company of Heroes 2

Company of Heroes 2

Zycat AI
Zycat  [developer] 11 Nov, 2021 @ 3:58am
Technical reading and FAQs - Issues and stuff about the A.I
#1 Philosophy of my mod is, above all, to be FUN to play with and/or against. Challenging without sacrificing flair and variety.

Issues people bring up :

* The A.I units are not doing any teamwork.
It is not currently possible to have A.I units do teamwork.

First, the targetting function for any normal attack (i.e right click) is not modable. I can only modify targetting functions of abilities. There is some "teamwork" from my smoke grenade targetting function (targets low health friendly units, targets any enemy team weapons that isn't being attacked, etc.) but that's probably the most I can do.

Second, the A.I does not use control groups. They are individual squads that has no awareness of the things surrounding them. Well, actually they do have a "combat eval" value where it will try to calculate their combat effectiveness, but so far it's kind of a black box and not very effective. Beyond that though, any semblance of teamwork is merely due to the squads being assigned the same target at the same time.

* Will the friendly AI be affected by this mod?
Yes. They will have the exact same capabilities as an enemy AI of the same difficulty. In fact I've tested 3 vs 3+1(me doing nothing) a lot and they definitely behave the same.

* Philosophy of the difficulty settings
Easy - First 8+ minutes will only build weird/ineffective squads. After that it tries to build Light tanks not upgrading to medium tanks until much later in the game. Some reactionary abilities (i.e retreat and avoid) are delayed by a random value.
Standard - The philosophy of standard A.I is bleeding edge efficiency. If the A.I can't handle a certain unit well it will be disabled (e.g M3A1, M20) or reduced in number (MGs, AT guns except Raketenwerfer). If the A.I is better without a certain unit in the build order it will be disabled (e.g T-70 and Su-76M).
Hard - Hard is almost like Standard but with more flair and some units that are disabled in Standard due to pursuing faster T3-T4 times present (e.g T-70)
Expert - This difficulty is geared more towards fun than anything else. It will try to build at least one of every unit for flair and variety (yes, those M3A1, M20, Su-76M), not because it can handle them but because it can afford to do so.

* How the A.I has more manpower etc.?
The original A.I has these resource values :

Easy : 0.6x Manpower, 0.7x Munitions, 0.8x Fuel
Standard : 1.0x across the board
Hard : 1.25x Manpower and Fuel, 1.0x Munitions (3.5 Total)
Expert : 1.6x Manpower and Fuel, 1.3x Munitions, Plus a 20% Manpower boost when below a certain point. (4.5 + 20% Manpower boost total)

My A.I has these (yes I finally modified them to better balance the A.I economy) :

Easy : 1.0x across the board
Standard : 1.0x across the board
Hard : 1.15x Manpower, 1.3x Fuel, 1.05x Munitions (3.5 Total)
Expert : 1.45x Manpower + 20% boost below a certain point, 1.6x Fuel (unchanged), 1.45x Munitions. (4.5 + 20% Manpower boost total)

The reason is A.Is especially Expert gets ridiculous amount of manpower it's practically useless for you to bleed models, so I reduced Manpower in exchange for slightly more Fuel and Munitions. I'm looking to implement some sort of dynamic multipliers so they have less resources when winning and more when losing, i.e "catchup mechanic" and less ridiculous behavior when they're winning, but so far there isn't any good way to do it. The total multiplier is still the same across the difficulties barring Easy.

Related question is - Is it possible to have a good A.I that doesn't cheat? My answer is, play my A.I on Standard. I always work with Standard A.I first and I believe it has the most optimized build out of all difficulties. That's close to the maximum the A.I can do, and if you want more, just play PvP I guess?

* I want the AI to have more (or less) resources!
You can always use a gamemode mod to override the resource values. I don't have a specific recommendation of one, but there are several gamemode mods that modify the AI resources (and more!).

* Do you modify the units? Or is it 100% like the original?
I do not modify the stats of the units. However, I do modify some squads that's usable for the A.I only. The A.I gets special MG teams/AT guns/Mortars that cost exactly the same as the players', the MG teams and AT guns just have one extra ability that does nothing but lock them in place so they don't move around as much. They're also built from non production buildings (base defenses, weapon racks) and do not have an interface so the players will probably not notice anything.

Why can't it build from the standard buildings you ask, well, making them build from the standard buildings (barracks etc.) means modifying the building itself, and it will break updates. I doubt at this stage Relic will change base defenses or weapon racks in future patches.

* Why is the A.I maphacking (and its variants)?
A.I is a program embedded deeply into the game system. The A.I we have is NOT designed to take fog of war into account.
When people talk about "A.I is not able to see anymore" they are most likely talking about the boolean switches in the ai_settings file, and surprise, it does not work. Not properly.

First setting is pathing_detect_squads_in_fog_of_war. This setting is ONLY applied to the pathing algorithm, so it does nothing for the "A.I showered me with katyusha love while having no vision" thing.

Second, closely related to above is pathing_threat_memory_duration. This also only applies to the pathing algorithm and guess what, the "memory" follows the squads around so the A.I basically have the same maphack after it sees the squad for the first time.

Third is detect_squads_in_fog_of_war. It is used for target identification. But wait, the targetting system for abilities like the aforementioned katyusha love uses a DIFFERENT function that is inaccessible without using SCAR workarounds.

Fourth is the easiest and it is disabled on my mod at all times, that is A.I sees invisible units. This doesn't affect the A.I too much and so I disabled it.

There is a way to do this but it's very crude, that is redoing all skill targeting to use Player_CanSeeSquad or Player_CanSeeEntity. However, they will have NO memory whatsoever and thus can only reliably target things they can see constantly. So if an enemy squad goes to your vision, then one second gone from your vision, it will not execute the ability. We humans know intuitively the squad is still there in green cover, but the A.I don't.

* Why can't Relic build a better A.I?
Ask them. Mods like this shouldn't exist in the first place when Relic does their job properly. As of this date (2/6/22) the A.I in Age of Empires 4 isn't that good either (although they're better simply because macro multitasking, the thing that A.I excels at, exist in that game. Also, the nature of no unit preservation means A.I can just chuck units to die and replace them, supported by their macro.)

* What's broken from the original A.I?
Too much to list. Most broken A.I in the original is British, it's pure laziness on Relic's side to group Centaur weapon burst, Firefly tulip, Concentrated Barrage, Bofors suppressive barrage, and British 3 inch mortar barrage under ONE behavior file. Also apparently Universal Carrier's suppression (Vickers upgrade) and 6-pounder rapid maneuver is the same according to Relic (hint, they're very very different abilities). The retreat thresholds and delays are also out of whack.

Infantry HP check functions does not return the correct HP when the squad is split by crewing a team weapon or by Conscript's merge ability, causing problems with reinforcement and retreat.

Squads like Fallschirmjäger hinders the A.I's ability to produce more units. Why? They have either no dispatch A.I files or a specific condition dispatch (i.e on recon only etc.) and the A.I will keep trying to build them to no avail.

* Hardest faction to work with?
British. Way too many things to work on (weapon racks, Bofors, AEC, Hammer/Anvil, all the missing abilities, etc.)
Dishonorable mention goes to OKW because of their sWS truck system. It's really hard to control because OKW has very different system internally than everyone else, also most likely leftovers from the days when OKW automatically gets sWS trucks. Also the fact that Luftwaffe Ground Forces stumped me for a very long time before finally figuring out why.

* How do you test the AI?
Road to Arnhem. 3v3+1 (I do nothing). It has nice mix of garrison-able buildings and side paths with covers. I have over 500 plays on this map alone due to the testing. Why 3v3? Allows me to test build orders of several factions/difficulties at once, also I don't have to play as I can just idle my computer and come back later to watch the replay which can be sped up.

[This will be constantly edited to write new stuff]
Last edited by Zycat; 24 Aug, 2022 @ 7:58am
< >
Showing 1-2 of 2 comments
Trigg 14 Jan, 2024 @ 7:12pm 
"Squads like Fallschirmjäger hinders the A.I's ability to produce more units. Why? They have either no dispatch A.I files or a specific condition dispatch (i.e on recon only etc.) and the A.I will keep trying to build them to no avail."

Does it keep trying to build FJ to the exclusion of anything else?
Zycat  [developer] 15 Jan, 2024 @ 4:54am 
Yes it does.
< >
Showing 1-2 of 2 comments
Per page: 1530 50