• New Horizons on Maelstrom
    Maelstrom New Horizons


    Visit our website www.piratehorizons.com to quickly find download links for the newest versions of our New Horizons mods Beyond New Horizons and Maelstrom New Horizons!

Fixed Character LAi Group not properly restored after stunned

Grey Roger

Sea Dog
Staff member
Administrator
Storm Modder
Previously, after I'd stolen a guard's weapons, he'd wander around aimlessly and swordlessly. The only difference is that now he's no longer swordless.
 
I think the problem lies here in PROGRAM\Loc_ai\types\LAi_stunned.c:
Code:
  if(!CheckAttribute(chr,"stuntime.old_type_resume") && !CheckAttribute(chr, "stuntime.actor"))
   {
     if(!CheckAttribute(chr, "first_oldtype")) chr.first_oldtype = chr.stuntime.old_type; // for logoff
     LAi_SetCitizenTypeNoGroup(chr);
     chr.stunnewtype = true;
   }
I think these characters end up being set to CitizenType, which walk around freely.
This happens even if they weren't that type before, which applies to Item Traders and Town Guards for example.

It's a little bit weird though, since it looks like there IS code in place to handle different LAi groups.

@Grey Roger: Can you try something? Stun a town guard, then leave the location BEFORE he awakens.
Then when you return, see if he's wandering around or is back at his post.
There might be a difference in how characters are treated if they awaken in real-time or are forced to awaken because you left the location.
 
They always wandered off after I'd relieved them of their weapons. The only difference is that now they wander off carrying their new replacement weapons. My guess is that whatever code was added to re-arm them hasn't affected the AI, so they know they've been mugged but don't know they are now armed again.
 
The rearming code has nothing to do with the AI group code.
See my post above for the cause of them wandering.

Just need to know now the answer to that question there as that may influence how it can be fixed.
 
@Grey Roger: Can you try something? Stun a town guard, then leave the location BEFORE he awakens.
Then when you return, see if he's wandering around or is back at his post.
I could do that, but it's nothing to do with what I've been observing because I don't normally stun them. I pick their pockets with the thief's knife. The guards are fully conscious throughout the whole process.
 
Ah, good point! That is due to this code in PROGRAM\CCCFunctions.c:
Code:
void LAi_AttemptSteal(aref attack, aref enemy, aref weapon)
{
   if(CheckAttribute(enemy,"itemtrade")) // Jul05 for streetmerchants only
   {
     Logit(TranslateString("","The Merchantguild's watchmen are very vigilant..."));
     Ambush("rn_warnt18_2", 4, "enemy", "friend",""); // 4 cops attack you
   }

   if(frnd() < stf(weapon.steal)*GetAttackLuckMod(&attack)) // chance of successful theft are 75% + luckskill
   {
     bEnemyExchange = true; // added by MAXIMUS
     LaunchCharacterItemChange(enemy);   // ccc jun 05 stealinterface

     LAi_SetCitizenTypeNoGroup(enemy);   // makes disarmed victim flee
     PlaySound("INTERFACE\took_item.wav");
   } else {
     if(enemy.sex == "man") {PlaySound("VOICE\" + LanguageGetLanguage() + "\Eng_m_a_067.wav"); }   // victim raises alarm
     else{PlaySound("VOICE\" + LanguageGetLanguage() + "\Eng_f_c_016.wav"); }
     ChangeCharacterReputation(attack, -3);     // rephit for being caught
     LAi_group_Attack(attack, enemy); // NK do this too
     SetAllNormalGroupsRel(LAI_GROUP_PLAYER, LAI_GROUP_ENEMY); // NK do this in one function 05-07-10
   }
}
As you can see, that also contains an LAi_SetCitizenTypeNoGroup line which causes this behaviour.

Could you still do a test to actually stun a guard or item trader and see if they reset properly after a location reload?
Perhaps that part DOES actually work properly and it gets messed up when LAi_SetCitizenTypeNoGroup is called without being part of the "stunned" code.

There is code in place to reset characters back to normal after being stunned upon exiting from a location.
I am thinking that code might need to be adapted to handle characters that were set to flee in other ways as well.
 
I wonder if this is why, when I'm playing the "Assassin" storyline and get to the bit where I have to kill all the guards outside a fort before sabotaging the cannons, it doesn't work if I stun them with cobblestones and then kill them with a sword? If stunning them turns them into civilians then in effect I'm not killing any guards, I'm killing a lot of civilians. (But I don't get the massive reputation loss which I'd suffer for going round killing genuine civilians who haven't drawn their weapons.)

Has this part of the code changed much since Build 13? Because I remember on one occasion someone said "French quality and service are yours". As this was at Conceicao port, there was only one person who could have just confessed to being a French spy, so the trader by the gate found himself face to face with a ballistic cobblestone. I can't remember whether I then helped myself to his entire stock, but I do remember that from then on, whenever I went to Conceicao, he would be walking around the port area rather than standing next to his stall.
 
I think this code is still very similar to Build 13.

And your trader story is indeed the same issue, I think.

Not sure about the Assassin case though. That might be a bit different.
 
I've tried a few experiments, lobbing cobblestones or using the thief's knife, with or without robbing afterwards, against both guards and street vendors.

Stoning the victim does not cause him to go for a walk. If I stand and watch him, he doesn't get up, at least not during the time I waited. If I leave town via the gate to the plantation, he's still sitting when I return but does start to get up right away. Then he stands where he is supposed to be.

Both guards and street vendors do go for a walk after being hit with the thief's knife. I tried to rob the vendor but found no items, only a small amount of gold. That's probably because he had no items and only a small amount of gold, as confirmed by reloading the savegame with which I'd started these experiments and then trying to trade with him honestly.
 
So.... When you knock the characters out altogether, they return back to normal.
But if you use the Thief's Knife, that is when they get confused. Right?

For item traders, if you never talked to the character, he wouldn't have any items.
The item tree is generated only after talking.
 
So.... When you knock the characters out altogether, they return back to normal.
But if you use the Thief's Knife, that is when they get confused. Right?
Exactly.
For item traders, if you never talked to the character, he wouldn't have any items.
The item tree is generated only after talking.
Except that there have been several traders to whom I've talked and they had no items, even though I didn't use either thief's knife or cobblestone (or any other form of attack) against them. Even more annoying is when they have little or no money either, because the main use I have for street traders is to sell low grade weapons taken from dead enemies. Does their stock depend on their relations? Because it seems to be French traders who have nothing for me to buy and no money with which to buy my stuff, and Nelson is not exactly friendly with France!
 
Good to know! Then the best fix is probably to call the same code that restores these characters after being knocked out and apply it after using the Thief's Knife too.
Not sure when I'll get round to actually doing that, but at least it gives me a clue on how to do it. :doff

Except that there have been several traders to whom I've talked and they had no items, even though I didn't use either thief's knife or cobblestone (or any other form of attack) against them. Even more annoying is when they have little or no money either, because the main use I have for street traders is to sell low grade weapons taken from dead enemies. Does their stock depend on their relations? Because it seems to be French traders who have nothing for me to buy and no money with which to buy my stuff, and Nelson is not exactly friendly with France!
That probably use a separate Bug Tracker entry.
Savegame would be useful, since I would probably need to check how far the code progresses before not giving the trader any items/money.

For these characters, did they use to have items and money and now don't or did they never have it to begin with as far as you're aware?
 
That probably actually makes more sense than if they did and lost it.

Anyway, please provide a savegame and I'll see if I can figure out why they're not behaving like proper item traders.
 
This is fixed now too. If you use the Thief's Knife on a character and he/she flees, then that will be reset as soon as you exit the location.

Additionally, I think this may not have worked quite right for stunned characters either but should do now.
So that's one more thing that makes a bit more sense.
 
The town guards work like they always have with the cobblestone. I knock them out, kill, then rob them. I then leave the area and when I come back they have their weapons. I have not tried just robbing them.
 
If you are successful, then there should indeed be no difference.
The change comes when you are caught.
 
Im playing BBF storyline. I have play it for a time, But now, when boarding ships, this dialog from my officer is beginning
to come up. I have never seen this before, what is it. seadogs2_0011.jpg
 
Last edited:
Im playing BBF storyline. I have play it for time, But now, when boarding ships, this dialog from my officer is beginning
to come up. I have never seen this before, what is it.
That is the dialog of a stunned character. Is there a particular officer that has that dialog?
Perhaps he got stunned and didn't reset properly. I did recently rewrite that code, but I thought it should work more reliably now.
Maybe it needs some further looking at....
 
Back
Top