You just made that creature (a bear, a town guard, Zuggtmoy...) your friend or mind slave with a charm or a dominate effect! That effect just wore off and now you simply must kill your friend! I request that a T+ house rule be added so mind controlled units don't become automatically hostile after their mind control effect ends. However hilarious it is pitting the Welcome Wench Inn against 2 charmed bears from the True Neutral vignette.
The Charm spells are already overpowered and do more than in the RAW. Cham Person does not give you full control over a guy who just before were on the side of your enemies. And they are specifically written that - if you do not take further action - then the victim of a charm spell will remember what happened and his attitude towards you changed accordingly. https://www.d20srd.org/srd/spells/charmPerson.htm
I would say, that to do anything, a specification should be described what Charmed or Dominated critter should do. For example, charmed person would run off to some distance from combatants, but otherwise simply stand in Full Defense. But if attacked or harmed by PC spell, the Charm would go off. This is quite a work, but can be done in T+.
It doesn't seem like charm gives you control over your enemies in my game. They seem to just skip their turns in battle against their own faction. The only control you get is if they survive and stay following your group; they'll move in formation. I guess maybe they should just become friendly and not automatically agree to fight further with you. It seems like the big AI problem is that all of their previous allies will immediately try to kill them. They should probably ignore the charmed guy just like the charmed guy ignores them.
The engine has a few issues/bugs related to a maximum number of AI-controlled units in the game. There is a numerical point where the AI either skips/rotates/queues turns for the controlled units. This is very apparent in big battles and when you have quite a few summons/charmed units in smaller battles. The AI picks a number of units within its control maximum and puts everything else in queue or rotation. I'm not quite sure how it picks the units. I often try to kill any disabled/unconscious enemies in order to remove them from the current AI group - including friendlies (not the core party). It helps to move the battle along imho. When one of these dies, you'll notice the AI moving a new unit into the fray. Otherwise you can end up with cases where the enemy has almost no pawns in play, as the AI is playing all your stuff...which is pretty meh for a battle. For example, if you charm all the bugbears in the moathouse and bring them to battle with Lareth = they will all eventually get around to attacking, but some might take time to get a turn. If you send them all into an already hostile spot with not too many AI controlled units, they will all fight. The charmed bugbears will also take attack commands and attack their group, immediately when charmed. Charm in ToEE behaves more like domination for absolute battle command, except that most of your unfavorable spells will turn them hostile. And you can only tell them where to move or attack when in party LoS, unless using a group command.
Does charming count as having more AI units than before? What I did was charm some guys in the fight outside the moathouse. They ran up to me, then after charming they stood around. Sometimes they got killed before their turn came around, but toward the end of the fight I had like three guys charmed and only one enemy left, and I think they still didn't do anything. It also happened in the KOTS challenge module anatoliy posted. Charming one guy in that fight just resulted in him standing around for the rest of the fight. Maybe this behavior doesn't last for subsequent battles, though.
At the time of charm, no. It's already part of the AI load. The AI might shift them to later in the queue , though. You may be correct that some stand around during the fight where charmed...I can't remember. In further battles, yes.
The engine can handle a maximum of 32 units in its initiative list IIRC. The engine cycles through this list when switching the current actor, and AI NPCs will be added on a first serve basis (they generally constantly try to alert each other each turn). It can be expanded in principle, but the main obstacle is the UI which is hardcoded to 32 portraits. Having said that, what you've observed @dolio is due to a small revision of the AI function that determines who to attack. IIRC when an explicit faction is shared, charmed critters will now not attack faction mates. However many mobs don't have an explicit faction (just faction 0, which is regarded as factionless), so in these cases they can attack their apparent group. You can check faction via turning on the DM and right clicking on critters. BTW I think the reason for that change was to fix the "friendly fire" you'd sometimes see when AI groups fought each other. IIRC it was due to a discrepancy between the is_friendly result and another function used internally by the AI (ehich I called GetAllegianceStrength). The whole system is pretty messy though and could definitely use a reform.