I suppose the answer depends on just what you think of as a "berserker".
The historical Berserkers were shock troops who focused their attention on engaging and slaying their opponents with little regard to anything else, including their own safety or that of others on their side. Different sources disagree on just how indiscriminate they were in their killing: some describe them as willfully slaying anyone and everyone around them, while others merely describe them as fearless warriors. Here's a fairly middle-of-the-road quote from the Ynglinga saga, via Wikipedia:
"His (Odin's) men rushed forwards without armour, were as mad as dogs or wolves, bit their shields, and were strong as bears or wild oxen, and killed people at a blow, but neither fire nor iron told upon them. This was called Berserkergang."
So, my conception of a berserker would be something like this:
- Completely fearless, probably oblivious to pain. Willing to engage enemies of any level.
- Highly focused on fighting, to the exclusion of anything else going on around them.
- Not completely indiscriminate in killing, but probably willing to attack friendlies (perhaps without even noticing) if they get in his way. Might also attack friendlies if there are no enemies around, but should still prefer enemy targets if there are any.
- Disdainful of subtle or cautious tactics: charge the enemy and hack them to bits is the name of the game here. Prefers mêlée combat, but might use sufficiently powerful ranged weapons (like guns, preferably on full auto and fired while running towards the enemy) if available.
- Unnaturally strong and tough — maybe not Superman-level tough, but they should definitely get some attack and defense bonuses, and perhaps a slight speed boost.
So, how would I translate these traits into game AI behavior? Well, here are a few ideas:
This should be kind of a no-brainer, but a berserker should never run away, even if he's down to a single hit point and bleeding. Just turn that code off. Ditto for any other "defensive" tactics.
Prioritize tactical options in this order: 1. Attack. 2. Move towards target. 3. Everything else. In particular, berserkers should not stop to pick up items if there are enemies in sight, even if the items are, say, better weapons than they currently have. (However, switching from bare hands to an already held mêlée weapon might be reasonably prioritized even over attacking.)
If both attacking and chasing after the target can ever be valid tactical options at the same time, consider giving your berserkers the ability to do both at the same time (an attack "in passing"), even if your creatures can't normally do that (possibly with an accuracy penalty to compensate). That way, your berserkers won't have to slow down their charge to take attacks of opportunity.
Target selection: I'd suggest just picking the nearest visible enemy (regardless of level) and having the berserker chase him, at least unless another enemy comes significantly closer (say, half the distance to current target). Keep chasing the target even if you temporarily lose line of sight, as long as the target doesn't get too far away. This should give some feeling of single-mindedness. Once the target is in mêlée range, attack him.
Pathfinding: If there are friendlies between the berserker and his target, consider letting him just attack them and hack his way through. It's up to you how eager to do that you'll make him — at least he should do it if there's no other path to the target, but you might even consider making him ignore friendlies entirely in pathfinding.
The above probably works best if you also make the (non-berserker) friendlies try to flee out of the square that the berserker will be next moving into (and maybe the next square or two in his path, too). Of course, if there's too much crowding, they might not be able to flee in time...
If there are no enemy targets around, consider letting the berserker attack nearby (adjacent, or maybe one or two squares away) friendlies instead. Of course, said friendlies should try to flee. On any turn where the berserker has no enemy target and doesn't make an attack, make him move around randomly and give him a random per-turn chance of calming down and reverting to normal state.
Weapon choice: As I noted above, real berserkers were big on mêlée combat. Don't use ranged weapons, unless they're particularly common and powerful in your game (e.g. guns in a modern setting). If you do let your berserkers use ranged or area-effect weapons, let them fire them while chasing their target (see "in passing" attacks above). Obviously, collateral damage should be ignored (by the berserker — making other enemies scramble to stay out of the line between you and a berserker with a gun would be a very nice touch).
And, of course, the berserker should have appropriate attack, defense and speed buffs. They should probably also be immune to any fatigue or fear effects. If blinded or confused, just have them make random attacks in the hope of hitting something.
You noted that you want berserking to be a state that can sometimes be entered by normal enemies (with a propensity to it). Thus, you'll need to decide what will trigger it. IRL, traditionally described triggers include combat, heavy exertion and stress. Some potential triggers for a game might include:
- seeing enemies,
- attacking,
- being attacked,
- being seriously wounded,
- seeing others in combat,
- seeing others get killed, or
- seeing traces of combat (bloodstains, dead bodies).
None of those should probably IMO be an automatic trigger; rather, there should be a random chance for each such event to trigger the berserk state, with the odds perhaps varying based on individual propensity and the severity of the event. Also, combinations of several triggers might make berserking more likely: for example, the presence of a visible enemy might be a precondition for any of the other events to trigger berserking, while low hit points might increase the odds for the other triggers.
Also, you might consider introducing a "rage meter" instead of just a simple on/off berserk state. For example, a newly triggered berserk might start at, say, rage = 1, with attacking and being attacked increasing the meter, and not seeing any enemies decreasing it. At low rage, a berserk would simply be fearless and buffed, but would generally avoid attacking friendlies, while increased rage would increase the buffs but also make the berserker's attacks less and less discriminate. When the rage meter goes down to zero, the berserker calms down and goes back to normal.
As for the obscene shouts, I'd mostly get rid of them: I see a berserker as being too focused on attacking to bother with any silly taunts. I suppose you could have him shout something when the berserk state is triggered, and maybe roar or make a simple war cry when closing to mêlée range, but that would seem enough for me.
Edit: After re-reading what I wrote above, I guess that real gist of what I'm trying to say is this: don't focus too much on the berserker AI itself. In the end, it's likely to turn out pretty simple, probably much simpler than your normal enemy AI. Instead, focus on how the other enemies will behave when they see a berserker nearby — that's where the really interesting dynamics will arise.