Login
User Name:

Password:



Register
Forgot your password?
LOP Building Guide v1.0
Author: Hanaisse
Submitted by: Hanaisse
Reset Guide
Author: Hanaisse
Submitted by: Hanaisse
LOP 1.38r2
Author: Remcon
Submitted by: Remcon
LOP 1.37
Author: Remcon
Submitted by: Remcon
LOP 1.36
Author: Remcon
Submitted by: Remcon
Yahoo! Slurp, MSN Search

Members: 0
Guests: 2
Stats
Files
Topics
Posts
Members
Newest Member
369
3,185
15,632
526
Craty####
» SmaugMuds.org » Codebases » SmaugFUSS » determining dodge
Forum Rules | Mark all | Recent Posts

determining dodge
< Newer Topic :: Older Topic >

Pages:<< prev 1 next >>
Post is unread #1 Oct 28, 2009, 12:05 pm
Go to the bottom of the page Go to the top of the page
blueice
Fledgling
GroupMembers
Posts17
JoinedOct 21, 2006

hello i have hit a wall in trying to rewrite the check_dodge function in my game. i scoured google, but the only thing i could find, besides references to world of warcraft, were function and formulas based entirely on the individual and not both fighters. just barely got back into programming so its probably something really simple, but god help me i cant figure it out.

Code:
bool check_dodge( CHAR_DATA *ch, CHAR_DATA *victim )
{
    int perc = number_percent();
    double dif, attacker, vict;

    attacker = (sqrt(get_curr_spd(ch))*1.25) + (sqrt(get_curr_agi(ch))*.75);
    vict = (sqrt(get_curr_spd(victim))*1.25) + (sqrt(get_curr_agi(victim))*.75);

    if ( attacker == vict )
        dif = number_range(5,10);
    else
        dif = (attacker - vict)*10;

    if ( dif > 0 )
    {
        if ( dif >= perc )
            return FALSE;
    }
    else
    {
        dif = dif * -1;
        if ( dif <= perc )
            return FALSE;
    }

    if ( !IS_NPC(victim) )
        act( AT_SKILL, "You twist your body to the side and dodge $n's attack.", ch, NULL, victim, TO_VICT );

    if ( !IS_NPC(ch) )
        act( AT_SKILL, "$N twists $S body to the side and dodges your attack.", ch, NULL, victim, TO_CHAR );

    act( AT_SKILL, "$N twists $S body to the side and dodges $n's attack.", ch, NULL, victim, TO_NOTVICT );
    return TRUE;
}


the idea is that as the difference increases, the harder it will be for the victim to dodge your attack, and as the difference decreases, the harder it will be for you to him. any ideas?
       
Post is unread #2 Oct 28, 2009, 12:21 pm
Go to the bottom of the page Go to the top of the page


Kayle
Nibelungen
GroupAdministrators
Posts885
JoinedMar 21, 2006
WWW

What exactly are you trying to do? I'm not sure I really follow what it is you're attempting enough to offer advice yet.

.........................
Owner/Coder                                                                    Coder
Malevolent Whispers                                                        Star Wars: The Sith Wars
{Development Phase - Not accepting players}                {Open Alpha - Players welcome, but with frequent changes to core systems.}
IMC2 Contact: Kayle@MW                                                IMC2 Contact: Kayle@SWTSW
       
Post is unread #3 Oct 28, 2009, 1:38 pm   Last edited Oct 28, 2009, 1:39 pm by blueice
Go to the bottom of the page Go to the top of the page
blueice
Fledgling
GroupMembers
Posts17
JoinedOct 21, 2006

i want to change the check_dodge function calculate the chance to dodge based on both the attacker and the victim, by comparing their combined attributes that affect the chance to hit/dodge, speed and agility.

            difference =  attacker chance to hit - victim chance to dodge
                                  -100                        0                              100
completely miss |--------------------------()---------------------------------| unable to miss
       
Post is unread #4 Oct 28, 2009, 2:12 pm
Go to the bottom of the page Go to the top of the page


David Haley
Sorcerer
GroupMembers
Posts830
JoinedJan 29, 2007
WWW

What is the problem that you're seeing with your code? I haven't gone through it beyond a cursory glance, but it looks like the general idea is what you've described. Is it behaving differently from your expectation? .........................
David Haley
Head Coder, Legends of the Darkstone
BabbleMUD Project
http://david.the-haleys.org
       
Post is unread #5 Oct 28, 2009, 3:48 pm
Go to the bottom of the page Go to the top of the page
blueice
Fledgling
GroupMembers
Posts17
JoinedOct 21, 2006

it seems that no matter what i do, i have problems with fights where either a NPC that shouldnt be able to dodge a single attack does, or fights where the fighters are extremely close and almost every attack is being dodged by both parties. like u said it seems like it should work, but doesnt. strength and agility have no restrictions on my game, so the two attributes can range anywhere from 1 to 10000 and above, though the average combination for my highest experienced players is around 3000
       
Post is unread #6 Oct 28, 2009, 6:46 pm
Go to the bottom of the page Go to the top of the page
blueice
Fledgling
GroupMembers
Posts17
JoinedOct 21, 2006

the problem has to be in my execution of this part
Code:
    if ( dif > 0 )
    {
        if ( dif >= perc )
            return FALSE;
    }
    else
    {
        perc = perc * -1;

        if ( dif <= perc )
            return FALSE;
    }


no matter how i can change the evaluations for diference and percentage, one end of the spectrum messes up, it seems to be the middle area where it is messing up, perhaps i should only be evaluating it based on whoever has the highest total value?
       
Post is unread #7 Oct 28, 2009, 6:59 pm
Go to the bottom of the page Go to the top of the page
blueice
Fledgling
GroupMembers
Posts17
JoinedOct 21, 2006

ok so maybe i can figure this out if i focus on one thing at a time. ok based on a situation where attacker value is always greater than vict

Code:
    if ( dif > 0 )
    {
        if ( perc < dif )
            return FALSE;
    }


ok so if i try it this way, it works perfectly for someone who is extremely higher than the other person, but as the difference between them gets closer, the chance to dodge increases so much that the attacker actually can barely hit the vict, if i switch the evaluator around ( perc > dif ), its the exact opposite, the closer the speeds the more dodges happen. how can we get this better?
       
Post is unread #8 Oct 29, 2009, 1:31 pm
Go to the bottom of the page Go to the top of the page


David Haley
Sorcerer
GroupMembers
Posts830
JoinedJan 29, 2007
WWW

One problem here is that you are comparing a number that is basically unbounded with a number generated as a percentage. If the difference between them is, say, 100, then perc will always be less than diff.

If you want to compare against a percentage, you need to find some way of normalizing the difference between their "dodge scores" to be comparable to the percentage roll. This isn't really a programming problem, it's a design problem. You have to make sure that you're coming up with a difference that makes sense to compare. Your differences are on an entirely different scale than your die roll.

You should work out a few cases by hand where you write out the speed and agility of each, then run those through your formula to get their "dodge scores", compute the difference, and then see what the numbers are like as you scale input variables. This will give you a feeling for how to normalize the difference against the percentage. You can do this by graphing the difference along the x axis, and the normalized number on the y axis. Make sure to always express things the same way, e.g., always trying to figure out if the attacker succeeds, or always trying to figure out if the defender succeeds. This will help you get your signs right.

Basically, you need to work this out by hand and see what the numbers actually are, and not try to write formulas until you understand how the numbers and signs interact. .........................
David Haley
Head Coder, Legends of the Darkstone
BabbleMUD Project
http://david.the-haleys.org
       
Post is unread #9 Oct 31, 2009, 1:49 pm
Go to the bottom of the page Go to the top of the page
blueice
Fledgling
GroupMembers
Posts17
JoinedOct 21, 2006

thanks for the suggestions, i think this new version is working pretty well, time will tell.

Code:
bool check_dodge( CHAR_DATA *ch, CHAR_DATA *victim )
{
    double perc = ((double)number_range(50,200)/100);
    double dif, attacker, vict;

    if ( !IS_AWAKE(victim) )
        return FALSE;

    attacker = (sqrt(get_curr_spd(ch))*1.25) + (sqrt(get_curr_agi(ch))*.75);
    vict = (sqrt(get_curr_spd(victim))*1.25) + (sqrt(get_curr_agi(victim))*.75);

    if ( attacker == vict )
    {
        // with fighters or equal caliber, lets give it a generic 10% chance to dodge
        if ( number_percent() > 10 )
            return FALSE;
    }
    else if ( attacker > vict )
    {
        dif = vict*perc;

        if ( attacker > dif )
            return FALSE;
    }
    else
    {
        dif = attacker*perc;

        if ( vict < dif )
            return FALSE;
    }

    if ( !IS_NPC(victim) )
        act( AT_SKILL, "You twist your body to the side and dodge $n's attack.", ch, NULL, victim, TO_VICT );

    if ( !IS_NPC(ch) )
        act( AT_SKILL, "$N twists $S body to the side and dodges your attack.", ch, NULL, victim, TO_CHAR );

    act( AT_SKILL, "$N twists $S body to the side and dodges $n's attack.", ch, NULL, victim, TO_NOTVICT );
    return TRUE;
}
       
Pages:<< prev 1 next >>