Page 1 of 1

The combat pseudo-code isn't? [resolved]

Posted: Mon Feb 14, 2011 8:54 pm
by andenixa
Hello everyone.
I have implemented the core pseudocode damage calculation (found in doc99), and the basedamage supplied by the core, doesn't match the damage produced by the custom function (its like 25% lower). I didn't do the attack hook, I just wanted to produce my own damage calculation for the core combat.
Does anyone know why it could be?

Re: The combat pseudo-code isn't?

Posted: Tue Feb 15, 2011 2:29 am
by CWO
Are you sure you calculated it correctly? I just went through the POL source code and compared it to the pseudo code and they match up exactly.

Re: The combat pseudo-code isn't?

Posted: Tue Feb 15, 2011 6:22 am
by andenixa
I practically implemented it line by line. I would be much obliged if you could post the actual pol source snippet there. Perhaps then I could just translate it directly to eScript.

Re: The combat pseudo-code isn't?

Posted: Tue Feb 15, 2011 8:31 am
by Turley

Re: The combat pseudo-code isn't?

Posted: Tue Feb 15, 2011 11:59 pm
by andenixa
Thanks a lot,
It does look like a pseudo-code you provided, though I didn't dig deep enough.

maybe the weapon damage formula is different.

What I did was:

Code: Select all

var weapon_damage := (RandomDiceRoll( weapon_cfg_elem[weapon.objtype].Damage ) + weapon.dmg_mod) * weapon.quality;

// and then the rest of the damage_multiplier routine applies

But thats an improvisation, perhaps I am wrong.

Re: The combat pseudo-code isn't?

Posted: Wed Feb 16, 2011 12:23 am
by Turley
jep thats the problem
UWeapon::get_random_damage()
int dmg = int(tmpl->get_random_damage()) * hp_ / maxhp();
dmg += dmg_mod_;

or in escript:
var descriptor := GetItemDescriptor(weapon.objtype);
var dmg:=CInt(RandomDiceRoll( descriptor.Damage )*(weapon.hp/(descriptor.maxhp+weapon.maxhp_mod))+weapon.dmg_mod)

Re: The combat pseudo-code isn't?

Posted: Wed Feb 16, 2011 1:35 am
by andenixa
Thanks a lot Turley,

This code gives values identical to the core:

Code: Select all

function CalcBaseDamage( who )

    var weapon := who.weapon;

    // just in case
    if( not weapon )
        return 1;
    endif    

    //or in escript:
    var descriptor := GetItemDescriptor(weapon.objtype);

    var random_weapon_die_damage := 
        CInt(RandomDiceRoll( descriptor.Damage ) * (CDbl(weapon.hp)/(descriptor.maxhp+weapon.maxhp_mod))+weapon.dmg_mod);

    var base_damage := random_weapon_die_damage;

    var damage_multiplier := GetAttribute( who, "tactics" ) + 50;       
    damage_multiplier += GetAttribute( who, "strength" ) * 0.2;    

    damage_multiplier *= 0.01;    
    base_damage *= damage_multiplier;

    return CInt(base_damage);

endfunction
PS: GetItemDescriptor() is roughly ~25x times slower than accessing :*:itemdesc

Re: The combat pseudo-code isn't?

Posted: Wed Feb 16, 2011 3:34 am
by Turley
andenixa wrote:PS: GetItemDescriptor() is roughly ~25x times slower than accessing :*:itemdesc
mmmh could be never did performance checks. But the function can easily be converted to use itemdesc instead of descriptor.