blinkyzero

[WIP] KotOR1 Enemy Enhancer

Recommended Posts

Hi folks! About a year and a half ago I was working on a mod for KotOR1 to make enemies more dangerous by improving their AI and use of feats and weapons, but I had to set it aside after a while when life got too busy. Thankfully, though, all the kind advice the good souls here at Deadly Stream gave me back then won't be wasted, as I've finally got a bit of free time coming my way this month and hope to be able to finish the project.

 

I'll be tracking what I get done here on this WIP post. I'd be particularly grateful for any suggestions, too, especially pertaining to how we can make enemy AI smarter. So far, the focus fire feature has proven to be particularly challenging to fight against, and I suspect it could be even more fiendish with additional priorities beyond the standard "kill the one in the dress waving his hands and healing" sort of thing. 8)

 

KotOR1 Enemy Enhancer

 

Completed Features


 

Player Quality of Life Changes

[X] New Passive AI script. This selectable script prevents party members who have it assigned to them from performing any actions in combat other than those the player queues up.

[X] Party AI toggle. Turning on Solo Mode now disables all party member AI in combat, regardless of assigned scripts. Turning Solo Mode off causes party AI to return to normal.

 

Enemy Enhancements and Bug Fixes

[X] Focus fire. Enemies now tend to seek out the party's weakest members/support characters (especially healers) and coordinate their attacks against them.

[X] Guns 'n stuff. All enemies and party members with ranged attack feats now use them properly.

[X] Shield happy! Enemies who possess shield units can now activate them more than once per fight and will do so when prudent.

[X] Stat scaling. Enemies whose ability scores are lower than what their level would give an equivalent player will be dynamically granted bonuses to make up the difference.

[X] Difficulty scaling. Instead of altering enemy damage totals, the in-game difficulty settings will instead determine the frequency and degree of the various Enemy Enhancer features.

 

In Progress


 

[-] Bonus equipment. Enemies will randomly be given medpacs, shield units, grenades, and other goodies to use against you in combat.

[-] Extra feats. Enemies will sometimes receive a package of new feats (in line with their level and class, of course).

[-] Stim junkies. Enemies will now use combat stims, including the squad recovery stim.

 

Possibilities...


 

[?] Enemy reinforcements. Certain enemies will have a chance to summon friends to help them.

  • Like 4

Share this post


Link to post
Share on other sites

Hello!

 

Very interesting project, this one.

 

While I do not have particular suggestions to give, I can tell you that the "COMPLETED" section has already the improvement I would like to see in the game. And the only other one I would really like from the "IN PROGRESS" list is the "Shield Happy!" and "Steam Junkies" feature (but I would reserve this one for unique battles). The rest, while interesting, may be a bit too arbitrary for my taste, with the possible exception of "Stat scaling" and "Extra feats", if it doesn't go overboard.

 

One question about the "Focus Fire": how would the enemies figure out which of the party members should become a priority? Will you set for a number of combat rounds to pass before they switch to the weakest party members? Or...?

 

Good luck with this and keep us updated! :beer:

Share this post


Link to post
Share on other sites

Blinky, you're back! :D

I remember working on some of this with you and trying to get it to work over at LF. If you need some help, I'm usually around here, Discord, and Skype.

In regards to each of your in-progress things, I will detail some stuff here below:

Bonus Equipment:

1. I would use a custom OnSpawn script with a pool of items (for example, 30 strings of item template resrefs) and then use two integers in a while and a switch:case loops. Could even throw in a third integer to give a random amount of the items.

 

void main()
{
    // The OBJECT_SELF will randomly get anywhere from 1-5 items.
    int iNumOfItems = Random(5) + 1;
    int iCurrNum    = 0;

    string sItem1 = "g_i_medeqpmnt01";
    // Repeat ad nauseum (as needed) for your pool of items.

    while(iCurrNum < iNumOfItems)
    {
        string sItem = "";

        switch(Random(30) + 1)  // Replace 30 with the number of items in your pool.
        {
            case 1:
            {
                sItem = sItem1;
                break;
            }
        }

        // Replace last bit with how many of the item to give.
        CreateItemOnObject(sItem, OBJECT_SELF, Random(5) + 1);
        iCurrNum += 1;
    }
}

 



You could even modify the code to add another integer in the switch:case loop to determine on a case-by-case basis how many of the item should be given, even if you're just changing the range of the possible number (for example, Random(6) + 5 would be anywhere between 5 and 10 of the item).

Extra Feats and Stat Scaling:

Both of these would need to be handled the same way, so I'm going at them at the same time. Basically, you can't directly do these things in KotOR, but KotOR 2 has the functions to do this.

Instead, what I would do is make items that give packs of feats and then make items that give set attribute bonuses. I would combine these into string lists like above with the bonus equipment. And just like the bonus equipment, I would do a switch:case loop (but not a while loop. JUST the switch:case loop) to compare the difference in the OBJECT_SELF's level versus the PC's level and give a "tiered" attribute item and one or two feat.

 

With this approach, you have 1 Attribute item + 1 or 2 Feat Packs, which means that you can equip all three of these in the "hidden" Inventory slots for the Creature Weapons (which is what the creatures in the game, like Kinrath, use to give you poison).

 

Those slots are INVENTORY_SLOT_CWEAPON_L, INVENTORY_SLOT_CWEAPON_R, and INVENTORY_SLOT_CWEAPON_B (or 14, 115, and 16, respectively).

 

Shield Happy! and Stim Junkie!:

 

I believe I helped you on the Shields, but I recall you weren't getting quite the results you wanted. As for the Stims, you can probably use the same approach as the Shields when those work.

 

Difficulty Scaling:

 

This one you probably already know how to do, since you'd just be doing integer checks on the effects of your code against the difficulty level to see how often the effects should be ran. Basically just an if-if/else-else series.

 

Enemy Reinforcements:

I know you got this one to work rather well, except that you were disappointed that the player could often see the people showing up, so the immersion was ruined.

 

I worked on a bit of an arena at one point after you and I stopped talking, and I came up with some code from adapting a fellow modder's and someone else's code. This bit of code allowed me to spawn things quite randomly and anywhere in relation to the player. I need to go grab the code off the other computer, so I can PM it to you tomorrow and also post it in here.

 

It'd also be quite possible to add line-of-sight checks on the coordinates BEFORE the things are actually spawned in, allowing even more control for you.

Share this post


Link to post
Share on other sites

Thanks for the feedback, guys!

 

 

While I do not have particular suggestions to give, I can tell you that the "COMPLETED" section has already the improvement I would like to see in the game. And the only other one I would really like from the "IN PROGRESS" list is the "Shield Happy!" and "Steam Junkies" feature (but I would reserve this one for unique battles). The rest, while interesting, may be a bit too arbitrary for my taste, with the possible exception of "Stat scaling" and "Extra feats", if it doesn't go overboard.

 

Yeah, it's a pretty broad range of changes. I'll probably have a few different installation configurations so that people can choose how many of the features they'd like to use. This is of course very easy with the TSLPatcher.

 

 

One question about the "Focus Fire": how would the enemies figure out which of the party members should become a priority? Will you set for a number of combat rounds to pass before they switch to the weakest party members? Or...?

 

The focus fire mechanic works by modifying DetermineCombatRound's target selection function. It's not hard to implement a series of checks at the beginning of every combat round to see if there's a better target available for the enemy to go after. I'm looking at potentially using the shout system to do some other things with it, too, though at the moment it seems unnecessary.

 

 

 

1. I would use a custom OnSpawn script with a pool of items (for example, 30 strings of item template resrefs) and then use two integers in a while and a switch:case loops. Could even throw in a third integer to give a random amount of the items.

 

Yup, this is basically how I had it implemented when I had to set the project aside last year.

 

 

Both of these would need to be handled the same way, so I'm going at them at the same time. Basically, you can't directly do these things in KotOR, but KotOR 2 has the functions to do this.

 

Yeah, unfortunately KotOR1's way of adding feats is really inelegant compared to KotOR2's. You have to have an item grant the bonus instead of using a function to directly apply it. I've also found some weird bugs with this, like GetCreatureHasTalent() being unable to detect the talents associated with combat feats when those feats are granted via item. Looks as though that function in KotOR1 only looks at the NPC's raw data from the .utc file. GetHasFeat() does pick up these added feats, though, so changing the combo selection functions to check for possession of the feat instead of possession of the talent (and then forcing the use of that feat's associated talent) works.

 

 

With this approach, you have 1 Attribute item + 1 or 2 Feat Packs, which means that you can equip all three of these in the "hidden" Inventory slots for the Creature Weapons (which is what the creatures in the game, like Kinrath, use to give you poison).

 

Creature items seem ideal for this sort of thing, yup. Attributes can be modified on the fly by script commands, which I've found easier and more flexible, especially because that makes fewer items that need to be equipped to the NPC (which can cause issues considering that the only way to get the items equipped is to have an action do it -- not always ideal in hectic combat situations when the action queue is a delicate thing).

 

 

I believe I helped you on the Shields, but I recall you weren't getting quite the results you wanted. As for the Stims, you can probably use the same approach as the Shields when those work.

 

I was having all kinds of little issues with them last year. I understand the DCR system much better now, though (and whoever wrote parts of it for BioWare did a sloppy job in places, I've got to admit), and I managed to fix the problems pretty easily this time around.

 

 

This one you probably already know how to do, since you'd just be doing integer checks on the effects of your code against the difficulty level to see how often the effects should be ran. Basically just an if-if/else-else series.

 

Yup, this one was a snap. So was the Passive AI script once I figured out how to best implement it. There's actually plenty of room for more of these scripts, too -- I'm considering making some more complex ones for party members because the existing choices aren't very robust. (KotOR's party AI can be downright stupid a lot of the time as it is, which was my reason for wanting to be able to just switch it off at the drop of a hat.)

 

 

I worked on a bit of an arena at one point after you and I stopped talking, and I came up with some code from adapting a fellow modder's and someone else's code. This bit of code allowed me to spawn things quite randomly and anywhere in relation to the player. I need to go grab the code off the other computer, so I can PM it to you tomorrow and also post it in here.

 

Neato! Yeah, I'd like to see that. I actually got pretty much the same thing working toward the end of developing this project, but it never hurts to see more methods.

 

The reinforcement system may never be a reality. Some of the issues it introduces are pretty awkward, like XP bloat from killing additional enemies. There are ways around this -- making reinforcement challenge ratings low or nonexistent so they grant little to no XP -- but that's just kind of goofy. As someone suggested elsewhere, though, it could be a nice addition to certain places where slews of enemies are expected, like the Leviathan or the Star Forge. It also wouldn't be hard to pick and choose only certain places in the game, like boss fights, where reinforcements have a chance to pop in. I like the idea of making specific battles more challenging, too. This would also make it much simpler to solve the issue of reinforcements messing up scripted sequences (of which KotOR has so many, and which are difficult to work around without arduous decompiling and examination of the myriad NPC scripts).

 

Probably I'll just shelve this for now and make it part of a separate "boss mods" mod or something down the road.

 

 

This sounds like a beautiful idea! 

 

Thanks! It's a fun diversion. Any sort of scripting that deals with the combat system (which is frankly a tangled mess) is frustrating, but still fun. 8)

 

 

Please no level scaling... 

 

I loathe level scaling, yeah. I really only want to scale enemy stats/skills up to where they should be for their class and level (a lot of the default enemies are woefully undertuned).

Share this post


Link to post
Share on other sites

Oh yes. This will be a must when it's completed!

 

Things like the targeting weak party members - is that EVERY mob? Because certain enemies, like Rakghouls or Tuskens (mayyyybe Gammoreans too) aren't intelligent in-universe, so realistically wouldn't fight along those lines. Ditto for wild beasts like Kinrath or Wraids

Share this post


Link to post
Share on other sites

Oh yes. This will be a must when it's completed!

 

Things like the targeting weak party members - is that EVERY mob? Because certain enemies, like Rakghouls or Tuskens (mayyyybe Gammoreans too) aren't intelligent in-universe, so realistically wouldn't fight along those lines. Ditto for wild beasts like Kinrath or Wraids

 

Oh, good suggestion! This makes sense. I can easily include an Intelligence/subrace check.

Share this post


Link to post
Share on other sites

 

 

[-] Stim junkies. Enemies will now use combat stims, including the squad recovery stim.

 

I'm not sure if a Squad Recovery Stim would work since that item revives your party members and only your party members

Share this post


Link to post
Share on other sites

 

 

I'm not sure if a Squad Recovery Stim would work since that item revives your party members and only your party members

 

 

Right, yeah, resurrecting the enemies isn't really feasible. It can be done, but it's not really worth the headache. Instead I just rewrote the function that governs the recovery stim to heal the enemy and all of his nearby buddies, which the item also does for the player and the party when you use it. Sort of an enemy group heal.

Share this post


Link to post
Share on other sites

Don't suppose there are any enemies Force users who have heal? As far as I know, they only use variants of drain. The closest we could get to testing enemy group heals is the three Jedi Masters in TSL, but they're always fought alone. Hmm

Share this post


Link to post
Share on other sites

Don't suppose there are any enemies Force users who have heal? As far as I know, they only use variants of drain. The closest we could get to testing enemy group heals is the three Jedi Masters in TSL, but they're always fought alone. Hmm

 

I'm not sure offhand, but the group healing really isn't difficult anyway. It's a simple matter of cycling through nearby enemies and applying a heal effect to them.

Share this post


Link to post
Share on other sites

Brief update because I found some time to work on this again today and like keeping a written record of what I've done, lest I forget and do something twice. :3

 

I setup a few additional difficulty levels and nullified the damage decrease/increase of the old system. Now difficulties are just settings for which Enemy Enhancer features you want to use. The Impossible difficulty is for true masochists -- not only does it give all of the bonuses of the difficulties below it, it also boosts an enemy's stats (and available feats) as though they are 2 levels higher than their current level. (Maybe I should make it a random number of levels, like 0-3?)

 
* Easy:
[X] Party AI Improvements
[ ] Enemy AI Improvements
[ ] Enemy Stat Enhancements
[ ] Enemy Equipment Bonuses
[ ] Enemy Level Up Bonuses
 
* Normal: 
[X] Party AI Improvements
[X] Enemy AI Improvements
[ ] Enemy Stat Enhancements
[ ] Enemy Equipment Bonuses
[ ] Enemy Level Up Bonuses
 
* Difficult: 
[X] Party AI Improvements
[X] Enemy AI Improvements
[X] Enemy Stat Enhancements
[ ] Enemy Equipment Bonuses
[ ] Enemy Level Up Bonuses
 
* Very Difficult: 
[X] Party AI Improvements
[X] Enemy AI Improvements
[X] Enemy Stat Enhancements
[X] Enemy Equipment Bonuses
[ ] Enemy Level Up Bonuses
 
* Impossible: 
[X] Party AI Improvements
[X] Enemy AI Improvements
[X] Enemy Stat Enhancements
[X] Enemy Equipment Bonuses
[X] Enemy Level Up Bonuses
  • Like 1

Share this post


Link to post
Share on other sites

Excellent, blinkyzero!

 

If you have a moment, would you please check your PM box? :cheers:

 

Done. :D

 

Also, think I might change the highest level of difficulty a bit. I got the artificial level-up system working fine (KotOR1 has no way of forcing an enemy to level up so you have to fake it), but it's sort of goofy. You end up with a lot of enemies that are significantly more powerful but don't grant any additional reward for defeating them (which is one of my problems with the lame damage multiplier of the default difficulty system). You can't change enemy Encounter Ratings on the fly in scripts, unfortunately, and though I suppose I could calculate the difference between the old level/new artificial level and award XP accordingly when enemies die, I don't really want to, since it's sort of clunky to do so and would also result in that pesky XP inflation -- always a problem in a game where the level cap is more or less hardcoded (and I'd rather not just make it harder to level; that's beyond the scope of this project).

 

Instead, I recalled a feature of some Baldur's Gate 2 mods that I love: fast buffing. (I think the NWN series had this at some point too? It's been a long time.) Essentially the idea is that enemies capable of buffing themselves with something do it instantly at the start of combat to simulate the sort of pre-buffing that players usually engage in. Seems to me that would be a fair difficulty increase for KotOR players -- running up against pre-stimmed, pre-shielded, pre-Force buffed enemies.

 

I also think I'll split the improved enemy feats off into a separate, complementary mod designed to work with the Enhancer, but alone if need be. The reason for this is that I'm finding the overwhelming majority of enemies in the game are either Minions or Soldiers (or Jedi Guardians, later on). There's very few Scouts or Scoundrels, which is disappointing, since those classes have some really nasty feats (Sneak Attack is absolutely brutal to have used against you). You can't change an enemy's class via scripting, unfortunately, and though I could fake it by assigning feats to them as though they were of a different class, it's not particularly elegant. I'd rather go through each module and do an overhaul of the UTCs themselves, changing classes and whatnot manually. The only concern there is with mod compatibility, but it's a minor issue -- folks could just go with another mod's module file in the case of a conflict. All they'd lose would be some relatively minor tweaks to stats and feats for enemies in that area.

 

Additional observations: I got through Taris on a test run so far and no issues. Squishy party members definitely need to be watched out for now -- poor Mission keeps getting absolutely rekt, since most of the enemies make a beeline for her. I find myself using tactics I've never bothered with before, like stuns, slows, and mines, just to keep them off her. Also enemies with grenades are a minor nightmare, especially if a large group all lucked out and got assigned some -- they're smart enough now to toss them all in at the same time and just devastate you. :o

Share this post


Link to post
Share on other sites

Hello!

Yes, I am familiar with that mod you are talking about. It should be Sword Coast Stratagems (SCS) which offers a different kind of pre-buff options. I honestly do not like it but I understand many do.

 

Please try and not be too nasty to poor Mission now! ;)

Share this post


Link to post
Share on other sites

Hello!

 

Yes, I am familiar with that mod you are talking about. It should be Sword Coast Stratagems (SCS) which offers a different kind of pre-buff options. I honestly do not like it but I understand many do.

 

Please try and not be too nasty to poor Mission now! ;)

 

Yeah, I'm actually not a huge fan of it myself either, but it'll be easy to turn on and off (and you're right, many people do like it, which is why I figured it'd be a good inclusion).

Share this post


Link to post
Share on other sites

Wonderful idea! :D

I have some random thoughts about AI:

What about party AI improvements? It's even hard to roam with them because they try to get stuck all the time. Party members seem to be not bad with offensive force powers and strikes (well, it could be better, I suppose), but  they also need to learn how to use those individual buffs like force speed/force immunity and etc (activation out of combat, perhaps?). Manual activation of all these buffs in 3-jedi party is frustrating, considering their duration.  At least force speed buff AI activation is a need. And HK-47 never uses his power shot (is it fixable?).

 

I would like to see jedi guardians (enemies and Juhani) jumping back and forth (they should use their advantageous force jump). Also enemies' combat strikes should be based on their weapons - sneak attackers should be stabbing in the back with flurry all the time, tanks and low-damage opponents should go with power strike, guys with 20-20 crits and high damage should go also with flurry and etc. If an enemy has several strike feats, he should use appropriate - probably enemy check his attack vs defense of party members (not to waste power strikes on high-defense guys, and flurry strikes on toughness-guys). And of course, enemies/party members should not constantly cast debilitating force powers on already debilitated enemies - sometimes it's better to do some damage.

 

Anyway, I don't know if all these changes are possible to implement. Still a great work - AI is ridiculous sometimes and definitely should be reworked.

  • Like 1

Share this post


Link to post
Share on other sites

Instead, I recalled a feature of some Baldur's Gate 2 mods that I love: fast buffing. (I think the NWN series had this at some point too? It's been a long time.) Essentially the idea is that enemies capable of buffing themselves with something do it instantly at the start of combat to simulate the sort of pre-buffing that players usually engage in. Seems to me that would be a fair difficulty increase for KotOR players -- running up against pre-stimmed, pre-shielded, pre-Force buffed enemies.

 

I like this idea, but you might want to implement a UI element (maybe a mousover tooltip if possible?) to indicate exactly what buffs the enemies are using, so that you're not guessing wildly as to which enemies are the biggest threat and can formulate a strategy.

 

That said, enemy smart grenade usage sounds horrifying yet great in equal measure. :)

 

Since you are improving the enemy AI, were you planning in improving the party companion AI as well?

Share this post


Link to post
Share on other sites

Wonderful idea! :D

I have some random thoughts about AI:

What about party AI improvements? It's even hard to roam with them because they try to get stuck all the time. Party members seem to be not bad with offensive force powers and strikes (well, it could be better, I suppose), but  they also need to learn how to use those individual buffs like force speed/force immunity and etc (activation out of combat, perhaps?). Manual activation of all these buffs in 3-jedi party is frustrating, considering their duration.  At least force speed buff AI activation is a need. And HK-47 never uses his power shot (is it fixable?).

 

I would like to see jedi guardians (enemies and Juhani) jumping back and forth (they should use their advantageous force jump). Also enemies' combat strikes should be based on their weapons - sneak attackers should be stabbing in the back with flurry all the time, tanks and low-damage opponents should go with power strike, guys with 20-20 crits and high damage should go also with flurry and etc. If an enemy has several strike feats, he should use appropriate - probably enemy check his attack vs defense of party members (not to waste power strikes on high-defense guys, and flurry strikes on toughness-guys). And of course, enemies/party members should not constantly cast debilitating force powers on already debilitated enemies - sometimes it's better to do some damage.

 

Anyway, I don't know if all these changes are possible to implement. Still a great work - AI is ridiculous sometimes and definitely should be reworked.

 

Hmm, good ideas! Most of this is very doable. It would be a pretty simple matter to get party members who have Force Speed to use it when the active party member does so out of combat. Maybe the best quality-of-life change we can make here is to simply have Force Speed affect all members of the party while out of combat (and wipe the effects immediately from non-Jedi when combat begins).

 

HK-47 not using his Power Shot is in fact a BioWare bug and one which I've fixed in this mod. As for enemy combat feat selection, that can also be improved, for sure. The vanilla system is downright stupid -- there's a set list of pre-determined combos that enemies can use, and the AI just randomly picks an available one (or a generic attack). I don't like these combos at all, since I think it's better to have enemies weigh their options before each individual attack, and I was planning on reworking the system. This will also affect party members, of course.

 

I like this idea, but you might want to implement a UI element (maybe a mousover tooltip if possible?) to indicate exactly what buffs the enemies are using, so that you're not guessing wildly as to which enemies are the biggest threat and can formulate a strategy.

 

That said, enemy smart grenade usage sounds horrifying yet great in equal measure.  :D

 

Since you are improving the enemy AI, were you planning in improving the party companion AI as well?

 

Hmm, not sure something like a tooltip is possible. I could have pre-buffing trigger a descriptive dialogue pop-up of some kind -- not a full conversation that stops the action, just one of those windows you get sometimes in the corner of the screen to tell you stuff. That said, enemies can't tell what you've got pre-buffed, so why should you be able to?  B)

 

Party AI will definitely be improved. I myself find being able to turn it off completely now to be wonderful, but I'm a micromanager sort of person I suppose. :D

  • Like 2

Share this post


Link to post
Share on other sites
Hmm, not sure something like a tooltip is possible. I could have pre-buffing trigger a descriptive dialogue pop-up of some kind -- not a full conversation that stops the action, just one of those windows you get sometimes in the corner of the screen to tell you stuff. That said, enemies can't tell what you've got pre-buffed, so why should you be able to?  B)

 

Party AI will definitely be improved. I myself find being able to turn it off completely now to be wonderful, but I'm a micromanager sort of person I suppose. :D

 

To answer the first question, we shouldn't.

 

And I'd prefer it that way.

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.