I'm not sure if there is a "good" way to do this, but I have been recently trying to do something similiar and come up with a workable, if somewhat messy, solution. Ok, make that very messy.
The ally piece is easy, just set the NPC's the player allies with to [GOODCUTOFF], that way, anyone who is marked as [ENEMY] will attack them.
The enemy attacks enemy piece is a where it gets messy.
The only way I could figure out how to do it was to have the NPC's scripts force them to attack each NPC on the other side individually. This quickly gets out of control if each side has 10+ different types of fighters on the field. And mages are even worse. I'm not sure how you would even make a mage script that wasn't 500 lines long.
Anyway, I was trying to have a scenario where Baatezu would fight Tanar'ri and vice versa, all the while attacking the player and some temple guards who were allied with the player. This meant that the Baatezu's scripts looked something like this:
IF
See("Tana01")
THEN
RESPONSE #100
Attack("Tana01")
Continue()
END
IF
See("Tana02")
THEN
RESPONSE #100
Attack("Tana02")
Continue()
END
and so on for each type of Tanar'ri. (I only had 5 types so it wasn't so bad) The Tanar'ri's scripts looked exactly the same but with the Baatezu DV's instead.
This way, whoever they see, they will attack.
I also had the requisite:
See(NearestEnemyOf(myself))
Attack(NearestEnemyOf(myself)) at the end.
The only problem is that sometimes a NPC will get fixated on one target and refuse to retarget even if they are being beaten on by someone else. That's why I added the continues, but it didn't seem to help.
With your scenario, it might be wise to make multiple scripts for each side, one for if the player allies with A, one for B, one for C and one for mayhem mode. That way each script only has to target one side (except for mayhem of course) at a time. This would limit the number of unnecessary checks that the engine had to make.
If someone has a better way of doing this I would love to hear it since this has very limited applications in terms of the number of actors that can be used before the scripts become to long to run efficiently. And it requires a lot of cut/paste.
Hope that helps. If you come up with anything better feel free to share