Author Topic: Battle AI - creatures summoning familiars & animal companions  (Read 602 times)

Legacy_Grani

  • Hero Member
  • *****
  • Posts: 1040
  • Karma: +0/-0
Battle AI - creatures summoning familiars & animal companions
« on: September 09, 2015, 02:18:38 pm »


               

I installed Tony K's battle AI script package in my module and I noticed that spellcaster creatures are now fond of familiars and the like. I'd actually want them not to summon them (especially considering I have a spellcaster summon in the module, so it could be a bit much for summons to summon more summons '<img'> ). The thing is, there are so many scripts I don't even know where to look, since I never really dealt with AI scripting.


 


Any help? '<img'>



               
               

               
            

Legacy_meaglyn

  • Hero Member
  • *****
  • Posts: 1451
  • Karma: +0/-0
Battle AI - creatures summoning familiars & animal companions
« Reply #1 on: September 09, 2015, 02:57:06 pm »


               

The first thing to try is setting int "DontSummon" to TRUE (non-zero) on the creatures you don't want to summon.  I'm not sure if that only effects henchpeople or if it applies to hostiles, but it looks like they both use the same code. So see if that does what you want. If not we can look more closely.



               
               

               
            

Legacy_Grani

  • Hero Member
  • *****
  • Posts: 1040
  • Karma: +0/-0
Battle AI - creatures summoning familiars & animal companions
« Reply #2 on: September 09, 2015, 03:02:31 pm »


               

Tried it just now, but it doesn't work.



               
               

               
            

Legacy_meaglyn

  • Hero Member
  • *****
  • Posts: 1451
  • Karma: +0/-0
Battle AI - creatures summoning familiars & animal companions
« Reply #3 on: September 09, 2015, 03:45:10 pm »


               

Okay. I think I see what it is. That setting will work for the regular AI path, but is not checked in the HenchTalentAdvancedBuff code which may be called first.   You can take a look in hench_i0_ai.nss  around line 554 for that function. You can pretty easily make that code respect that variable for all the summoning spells listed in there.



               
               

               
            

Legacy_Grani

  • Hero Member
  • *****
  • Posts: 1040
  • Karma: +0/-0
Battle AI - creatures summoning familiars & animal companions
« Reply #4 on: September 09, 2015, 03:51:00 pm »


               

I see no code for familiars and animal companions there, though. And frankly, that's what I'm most interested in.



               
               

               
            

Legacy_meaglyn

  • Hero Member
  • *****
  • Posts: 1451
  • Karma: +0/-0
Battle AI - creatures summoning familiars & animal companions
« Reply #5 on: September 09, 2015, 04:05:51 pm »


               

Okay.  Look in hench_i0_spells.nss. There are two places to fix. Look for HenchSummonFamiliar and HenchSummonAnimalCompanion. I did not notice that those we also not respecting the allowSummons variable.  In my code there's a totally unnecessary TRUE in the if statements. Replace that TRUE with allowSummons and it should stop them. 



               
               

               
            

Legacy_Grani

  • Hero Member
  • *****
  • Posts: 1040
  • Karma: +0/-0
Battle AI - creatures summoning familiars & animal companions
« Reply #6 on: September 09, 2015, 05:06:07 pm »


               

There's no ifs with TRUE in this script for me, though. Here's how it looks like:



void HenchSummonFamiliar(object oTarget)
{

    if (GetFamiliarName(OBJECT_SELF) != "")
    {
        ActionUseFeat(FEAT_SUMMON_FAMILIAR, OBJECT_SELF);
        return;
    }

    SetLocalInt(OBJECT_SELF, sHenchSummonedFamiliar, TRUE);
    DecrementRemainingFeatUses(OBJECT_SELF, FEAT_SUMMON_FAMILIAR);

    int bSoUInstalled = Get2DAString("hen_familiar", "BASERESREF", 8) == "X0_FM_FDRG";
    int bHoTUInstalled = Get2DAString("hen_familiar", "BASERESREF", 10) == "X2_FM_EYE0";

    int nGoodEvil = GetAlignmentGoodEvil(OBJECT_SELF);
    if (nGoodEvil == ALIGNMENT_NEUTRAL && GetRacialType(OBJECT_SELF) == RACIAL_TYPE_UNDEAD)
    {
        // convert neutral undead to evil for familiar
        nGoodEvil = ALIGNMENT_EVIL;
    }
    string sTemplate;
    if (nGoodEvil == ALIGNMENT_EVIL)
    {
        switch (d4())
        {
        case 1:
            sTemplate = "NW_FM_ICE";
            break;
        case 2:
            sTemplate = "NW_FM_FIRE";
            break;
        default:
            sTemplate = "NW_FM_IMP";
            break;
        }
        if (bHoTUInstalled && d3() == 1)
        {
            sTemplate = "X2_FM_EYE0";
        }
    }
    else if (nGoodEvil == ALIGNMENT_GOOD)
    {
        switch (d6())
        {
        case 1:
            sTemplate = "NW_FM_BAT";
            break;
        case 2:
            sTemplate = "NW_FM_RAVE";
            break;
        case 3:
        case 4:
            sTemplate = "NW_FM_CRAG";
            break;
        default:
            sTemplate = "NW_FM_PIXI";
            break;
        }
        if (d3() == 1 && bSoUInstalled)
        {
            if (d2() == 1)
            {
                sTemplate = "X0_FM_FDRG";
            }
            else
            {
                sTemplate = "X0_FM_PDRG0";
            }
        }
    }
    else    // ALIGNMENT_NEUTRAL
    {
        switch (d6())
        {
        case 1:
            sTemplate = "NW_FM_BAT";
            break;
        case 2:
            sTemplate = "NW_FM_RAVE";
            break;
        case 3:
            sTemplate = "NW_FM_ICE";
            break;
        case 4:
            sTemplate = "NW_FM_FIRE";
            break;
        default:
            sTemplate = "NW_FM_CRAG";
            break;
        }
    }

    object oFam = HenchDoFakeSummons(sTemplate, GetLevelByClass(CLASS_TYPE_WIZARD) +
        GetLevelByClass(CLASS_TYPE_SORCERER), oTarget, bHoTUInstalled);
    SetLocalObject(OBJECT_SELF, sHenchSummonedFamiliar, oFam);
}

I also tried adding something like this on the beginning:



if (GetLocalInt(OBJECT_SELF, "Summons") == FALSE)
        {
            DecrementRemainingFeatUses(OBJECT_SELF, FEAT_SUMMON_FAMILIAR);
            return;
        }

And it did almost work, but if the Spell Resistance of my PC was too high for the creature to be able to attack him with a spell successfully, the creature just stood there after buffing itself. Without this part of code, the creature would (apart from summoning a familiar) attack my character in melee after buffing itself. With this workaround, it just stood there, which is not exactly desirable behavior.



               
               

               
            

Legacy_meaglyn

  • Hero Member
  • *****
  • Posts: 1451
  • Karma: +0/-0
Battle AI - creatures summoning familiars & animal companions
« Reply #7 on: September 09, 2015, 05:11:18 pm »


               

No... not in the function. Find where the functions are called (in  TK_UseBestSpell):



 if (GetHasFeat(FEAT_ANIMAL_COMPANION))
        {
            bFoundSpellGlobal = TRUE;
            if (allowSummons && iAmMonster && !GetLocalInt(OBJECT_SELF, "HenchSummonedAniComp") && !GetIsObjectValid(GetAssociate(ASSOCIATE_TYPE_ANIMALCOMPANION)) && (GetMonsterOptions(HENCH_MONAI_COMP) & HENCH_MONAI_COMP))
            {
                HenchSummonAnimalCompanion(oTarget); return TK_SUMMON;
            }
        }

That "allowSummons" was just "TRUE".  Same for the code around the HenchSummonFamiliar call.


               
               

               
            

Legacy_Grani

  • Hero Member
  • *****
  • Posts: 1040
  • Karma: +0/-0
Battle AI - creatures summoning familiars & animal companions
« Reply #8 on: September 09, 2015, 05:28:24 pm »


               

Great! It works now. '<img'> Thanks a lot for help, meaglyn.



               
               

               
            

Legacy_meaglyn

  • Hero Member
  • *****
  • Posts: 1451
  • Karma: +0/-0
Battle AI - creatures summoning familiars & animal companions
« Reply #9 on: September 09, 2015, 06:03:48 pm »


               

Sure thing. I've been poking at that code anyway - pulling it in mostly for henchman use - so it was all pretty fresh.