Results 1 to 9 of 9

Thread: Fear algorithm modification

  
  1. #1
    KeeperFX Author mefistotelis's Avatar
    Join Date
    Sep 2009
    Location
    Poland
    Posts
    1,242

    Default Fear algorithm modification

    I'm thinking about making fear more flexible.

    Original:
    Code:
    TbBool creature_is_actually_scared(struct Thing *thing, struct Thing *enmtng)
    {
        struct CreatureStats *crstat;
        crstat = creature_stats_get_from_thing(thing);
        // Creature with fear 255 are scared of everything other that their own model
        if (crstat->fear_wounded == 255)
        {
            if (enmtng->model != thing->model)
                return true;
            if (creature_has_other_attackers(thing, thing->model))
                return true;
            return false;
        }
        // With "Flee" tendency on, creatures are scared if their health
        // drops lower than  fear_wounded/256 percentage of base health
        if (player_creature_tends_to(thing->owner,CrTend_Flee))
        {
            long maxhealth;
            struct CreatureControl *cctrl;
            cctrl = creature_control_get_from_thing(thing);
            maxhealth = compute_creature_max_health(crstat->health,cctrl->explevel);
            if (thing->health <= (crstat->fear_wounded * maxhealth) / 256)
            {
                if (thing->owner != game.neutral_player_num)
                {
                    SYNCDBG(8,"Creature is scared due to tendencies");
                    return true;
                }
            }
        }
        // Don't fear
        return false;
    }
    What I'm planning to do:
    - introduce 2 fear factors: fear_wounded and fear_stronger
    - fear_wounded would work like it does now - if a creature is wounded, retreat when lost given % of health
    - fear_stronger would make the creature retreat if enemy strength rating is given % times higher than its own rating

    Some details:
    - Strength rating could be simply health*strength
    - Both types of fear would work with and without flee
    - Without flee, the factors would be multiplied ie. 10 times, so creature would escape only if situation is really bad


    What do you think?

  2. #2
    Dragon DragonsLover's Avatar
    Join Date
    Aug 2009
    Location
    Quebec
    Posts
    1,490
    Gamer IDs

    Steam ID: dragonslover

    Default Re: Fear algorithm modification

    If that doesn't make creatures act too much like cowards, I find it a good idea!
    I like dragons! They're the center of my life! I'll never forget them...



  3. #3

    Default Re: Fear algorithm modification

    sounds like a good model! I would also like to see some individuality aspects in the "fear", some individuas are more fearful then others. Modeled e.g. by the "strength" assumed by a creature for his opponent which could vary by +20% to -20% (mis-perception).

    cheers
    PS: also, I take the chance for thanking you for the great keeperFX project!

  4. #4

    Default Re: Fear algorithm modification

    Strength rating could be simply health*strength
    Have the strength rating contained within the individual creature configs to allow for flexibility due to changing skills,
    and would allow for more customization for future campaigns

    - Both types of fear would work with and without flee
    - Without flee, the factors would be multiplied ie. 10 times, so creature would escape only if situation is really bad
    Have the factor contained in the ideally campaign associated creature.cfg file (the one currently in fxdata), to allow for same reason

  5. #5
    KeeperFX Author mefistotelis's Avatar
    Join Date
    Sep 2009
    Location
    Poland
    Posts
    1,242

    Default Re: Fear algorithm modification

    I just commited the change.

    Replaced "Fear=" with 3 commands in creature config files; documented in imp.cfg:
    Code:
    ; Wounded fear set to 101 will make creature escape from any combat other than
    ; protecting heart, or a combat with single creature of the same kind.
    ; This special value works the same way regardless of creature tendencies.
    ; Smaller value will make the creature escape if it has less than given percentage
    ; of health left (0-never escape, 100-escape even if no health is lost).
    FearWounded = 101
    ; Fear of stronger creatures - how many times the enemy has to be stronger in order
    ; for the creature to escape. Value of 100 will make the creature fear an enemy with
    ; same strength, 200 will make it fear enemies which are twice as strong, etc.
    ; The proper range of this value is 100..30000 %.  
    FearStronger = 800
    ; The FearWounded and FearStronger values are used unmodified only when Flee tendency
    ; is enabled. If the keeper didn't turned on flee, FearWounded is divided and
    ; FearStronger is multiplied by the following value before they are used (1..100).
    FearNoFleeFactor = 8
    Fo Ancient Keeper, I used:
    Code:
    FearStronger = 10000
    FearNoFleeFactor = 60
    so that the new settings won't affect it in noticeable level.

    If there is no LEVEL_VERSION in level script, then old SET_CREATURE_FEAR will be used (scaled 0..255). If there is LEVEL_VERSION(1), then new command (SET_CREATURE_FEAR_WOUNDED scaled 0..101) is used, and also SET_CREATURE_FEAR_STRONGER is available.

    EDIT:
    Note that these factors will also affect hero creatures (heroes have tendencies off).
    Last edited by mefistotelis; August 4th, 2012 at 00:12.

  6. #6
    Fly Trotim's Avatar
    Join Date
    Feb 2010
    Location
    Germany
    Posts
    90

    Default Re: Fear algorithm modification

    That's actually brilliant. Fear will now actually work like fear, so low level monsters will run away from high level ones instead of just recklessly attacking ya? That's the plan at least. What are the values set to exactly, or what's an example situation where it will now be noticeable?

  7. #7

    Default Re: Fear algorithm modification

    Code:
       // If the enemy is way stronger, a creature may be scared anyway
        long long enmstrength,ownstrength;
        if (player_creature_tends_to(thing->owner,CrTend_Flee) || (crstat->fear_noflee_factor <= 0)) {
            fear = crstat->fear_stronger;
        } else {
            fear = (long)crstat->fear_stronger * crstat->fear_noflee_factor;
        }
        enmstrength = calculate_melee_damage(enmtng) * enmtng->health;
        ownstrength = calculate_melee_damage(thing) * thing->health;
        if (enmstrength >= (fear * ownstrength) / 100)
        {
            SYNCDBG(8,"The %s is scared due to enemy %s strength (%ld vs. %ld)",thing_model_name(thing),thing_model_name(enmtng),(long)ownstrength,(long)enmstrength);
            return true;
    I'm a bit concerned about the way the creature strength is calculated here.

    1. It only accounts for their health and melee strength.
    example
    a wizards strength according to this is:
    350 * 20 (lvl 1)
    while a spiders is
    400 * 40 (lvl 1)

    now at low levels the spider has a chance of winning, but a level 10 wizard can beat a level 10 spider, yet the code seems to indicate that the wizard should flee?

    2. It doesn't seem to account for multiple creatures in the same combat,
    so from how I'm reading it
    8 lvl 10 mistresses would flee independently from 1 lvl 10 avatar

    so perhaps something like this for creature strength instead ?

    Code:
    skill_strength = sum of damage of all single target abilities (ie fireball, missile, etc + heal )
    
    buff_strength = sum of worth of buffing abilities against given target (rebound, armour, conceal creature)
     ie rebound is largely irrelevant against melee fighters while 
     also should include keeper spells
    
     ownstrength =(1+allied_creature_number/allied_creature_modifier) *(1+ buff_strengths)* ( melee_damage * health + skill_strength)

  8. #8
    KeeperFX Author mefistotelis's Avatar
    Join Date
    Sep 2009
    Location
    Poland
    Posts
    1,242

    Default Re: Fear algorithm modification

    I think using damage of one mostly used attack type should be enough. But now I'm only using melee - I will check if if I can estimate strength of a spell (many spells don't simply do damage).

    You are completely right about multiple creatures. I will have to deal with this in some way.

  9. #9

    Default Re: Fear algorithm modification

    I think that the original algorithm has some problems, causing the so called (by myself) "fear 0 paradox". Too many times during my gamplay I seen the Avatar run away from something like a fly, and so I think that this has to be corrected...

Similar Threads

  1. Replies: 6
    Last Post: July 30th, 2012, 08:16

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •