• 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 AMBUSH for town guards is in other group

Levis

Find(Rum) = false;
Staff member
Administrator
Creative Support
Programmer
Storm Modder
When you kill a townguard the ambush which is generated is in another relation group so if you get them to fire on each other you can see them fight each other instead. I think this should be fixed shouldn't it @Pieter Boelen ?
 
When you kill a townguard the ambush which is generated is in another relation group so if you get them to fire on each other you can see them fight each other instead. I think this should be fixed shouldn't it @Pieter Boelen ?
Probably, yes. :cheeky

Any chance you can post the offending code?
 
Hmmm this actually is right

Code:
void Ambush(string modeltype, int bmax, string mainrel, string npcrel, string locator)        // horde of attackers appears
// bmax is number of chr, mainrel relation to player, npcrel to NPCs, Nov05 added "guards" as modeloption for local guards
{

    ref chr;
    ref PChar = GetMainCharacter();
    ref lcn = &Locations[FindLocation(pchar.location)];
    float hasgun;
    string ani, group, model;
    hasgun = 0.5;
    ani = "man";
    group = "ambush";
    // Julian jan08 changed to enable use of pre-defined locator
//    if(locator == "") locator = LAi_FindRandomLocator(group); // PB: This always returns "" as 'ambush' is no valid locator group!

    // ccc Nov05 make local guards if modeltype is "guards"
    if(modeltype == "guards" || modeltype == "Navy_office4")
    {
        int nat = GetCurrentLocationNation();
        group = GetCurrentSoldierGroup();
    }

    for(int i = 0; i < bmax; i++)
    {
        if(modeltype == "guards"){model = SelectSoldierModelByNation(nat, "Soldier");} 
        else {model = GetRandomModelForTypeSex(1, modeltype, ani);}

        chr = LAi_CreateFantomCharacterExOt(npcrel ==  LAI_GROUP_FRIEND, 0, true, OFFIC_TYPE_GUARD, GetRandomRank(npcrel ==  LAI_GROUP_FRIEND, OFFIC_TYPE_GUARD, makeint((GetDifficulty()-1)*3)), true, hasgun, model, ani, "reload", locator);
        LAi_SetWarriorType(chr);
        LAi_group_MoveCharacter(chr, group);
    }

    LAi_group_SetRelation(LAI_GROUP_PLAYER, group, mainrel);
    if(mainrel=="enemy")
    {
        // PB: Don't draw blades if not necessary -->
        if(CheckAttribute(PChar, "locationLock"))
        {
            LAi_group_SetHearRadius(group, 40000000.0);
            LAi_group_SetSayRadius(group, 40000000.0);
        }
        // PB: Don't draw blades if not necessary <--
        else
        {
            LAi_group_FightGroups(group, LAI_GROUP_PLAYER, true);
        }
    }

    LAi_group_SetRelation(LAI_GROUP_GUARDS, "ambush", npcrel);
    LAi_group_SetRelation(LAI_DEFAULT_GROUP, "ambush", npcrel);
    LAi_group_SetRelation(LAI_GROUP_MONSTERS, "ambush", npcrel);

    // ccc Nov05 set relation to local soldiers (which are NOT! LAI_GROUP_GUARDS) with NK's new function
    SetAllNormalGroupsRel("ambush", npcrel);
   
    if(npcrel=="enemy") LAi_group_FightGroups("ambush", LAI_GROUP_GUARDS, true);

    if(!CheckAttribute(PChar, "locationLock"))
    {
        Log_SetStringToLog(TranslateString("","ALARM !  AN AMBUSH !!!!"));
        PlaySound("OBJECTS\abordage\abordage2.wav");
    }
}

I think already know what was happening .... This normally works, but the normal guards attacked me because I killed an unarmed citizen.
They where probably called by this code:

Code:
[...]
    if(LAi_IsDead(enemy))
    {
        //Íà÷èñëèì çà óáèéñòâî
        exp = exp + LAi_CalcDeadExp(attack, enemy);
        if(!isSetBalde)
        {
            // ccc mar05 REPLOSS tweak added
            if(enemy.chr_ai.group != LAi_monsters_group)
            {
                if(sti(attack.index) == GetMainCharacterIndex()) LogIt("CHANGE REP for player: " + -REPLOSS*3 + " - undrawn blade 1");     // LDH 19Dec08
                LAi_ChangeReputation(attack, - REPLOSS*3); // NK tempfix for un-drawn blades 04-17
                if(IsMainCharacter(attack)) GuardsAttackOpium(); //All near guards will attack you now. -Levis
            }
        }
    }
[...]

which calls this:
Code:
void GuardsAttackOpium()
{
    if(DEBUG_SMUGGLING>0) trace("OPIUM SMUGGLING start fight");
    int radius = 50;
    FindGuards(radius); //Get all in a certain radius;
    ref pchar = getMainCharacter();
    aref Guards; makearef(Guards,pchar.quest.opium_smuggling.guards);
    for(int i=0;i<GetAttributesNum(Guards);i++)
    {
        aref guard = GetAttributeN(Guards,i);
        //Filter out other info
        if(CheckAttribute(guard,"idx"))
        {
            ref sld = getCharacter(sti(guard.idx));
            LAi_SetActorType(sld);
            if(DEBUG_SMUGGLING>2) trace("OPIUM SMUGGLING guard "+sld.id+" attack");
            LAi_group_MoveCharacter(sld, "OpiumAmbush");
        }
    }
    LAi_group_FightGroups(LAI_GROUP_PLAYER, "OpiumAmbush", true);
}

This was put in place because the normal reaction didn't seem to work anymore. This was just a temp fix and hopefully for the next release we can get the hear radius etc to work right again.
But as you see they are moved to another group here so probably I just need to add a line here which makes them friendly with the local guard group and they can't attack each other.
Do you agree @Pieter Boelen ?
 
Ahaaaa, so it ISN'T an actual Ambush at all, is it? Because that code appears fine to me.

But probably in your Opium function, you should replace this:
Code:
  LAi_group_MoveCharacter(sld, "OpiumAmbush");
  }
  }
  LAi_group_FightGroups(LAI_GROUP_PLAYER, "OpiumAmbush", true);
With this:
Code:
  LAi_group_MoveCharacter(sld, GetCurrentSoldierGroup() );
  }
  }
  LAi_group_FightGroups(LAI_GROUP_PLAYER, GetCurrentSoldierGroup(), true);
 
@Pieter Boelen I think I want to add a line so the newly created group wont attack the normal guards. because else if you do this all guards in the town will attack you. And the function should only make the guards which can actually see you attack you.
I will fix and test this (hopefully) today
 
Then maybe use:
Code:
LAi_group_SetRelation(GetCurrentSoldierGroup(), "OpiumAmbush", LAI_GROUP_FRIEND);
But I'm not sure if that works due to the fact that this system IS still not working as it was once meant to.

For now, I'd suggest the simplest solution possible.
At some point I should do some archeology and figure out when the whole AI group relations got bugged to see if I can figure out why.
It has been messy for many, many years now. But I'd really rather NOT do that before Beta 4, because that would mean yet another major delay.
 
Back
Top