diff options
author | Jared Adams <jaxad0127@gmail.com> | 2009-01-03 22:37:04 +0000 |
---|---|---|
committer | Jared Adams <jaxad0127@gmail.com> | 2009-01-03 22:37:04 +0000 |
commit | 97e3980d2f2facaf710c881023cad9199e28b2c5 (patch) | |
tree | 60168cbd2291b1147f29a0727f0bcf98ecf12b60 /src/map | |
parent | 4e66ea28ae7dadf8204472891754fbfbce8c195f (diff) | |
download | tmwa-97e3980d2f2facaf710c881023cad9199e28b2c5.tar.gz tmwa-97e3980d2f2facaf710c881023cad9199e28b2c5.tar.bz2 tmwa-97e3980d2f2facaf710c881023cad9199e28b2c5.tar.xz tmwa-97e3980d2f2facaf710c881023cad9199e28b2c5.zip |
Add a function to calculate mob exp based on stats
The formula is as close to radiant's as I can get. It only applies if
mobs have 0 exp set.
Diffstat (limited to 'src/map')
-rw-r--r-- | src/map/mob.c | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/src/map/mob.c b/src/map/mob.c index 9710441..34d1b83 100644 --- a/src/map/mob.c +++ b/src/map/mob.c @@ -1,4 +1,5 @@ // $Id: mob.c,v 1.7 2004/09/25 05:32:18 MouseJstr Exp $ +#include <math.h> #include <stdio.h> #include <stdlib.h> #include <stdarg.h> @@ -25,6 +26,10 @@ #include "memwatch.h" #endif +#ifndef max + #define max( a, b ) ( ((a) > (b)) ? (a) : (b) ) +#endif + #define MIN_MOBTHINKTIME 100 #define MOB_LAZYMOVEPERC 50 // Move probability in the negligent mode MOB (rate of 1000 minute) @@ -254,6 +259,22 @@ mob_mutate(struct mob_data *md, int stat, int intensity) // intensity: positive: } } +// This calculates the exp of a given mob +int +mob_gen_exp(struct mob_db *mob) +{ + if (mob->max_hp <= 1) return 1; + double mod_def = 100 - mob->def; + if (mod_def == 0) mod_def = 1; + double effective_hp = ((50 - mob->luk) * mob->max_hp / 50.0) + (2 * mob->luk * mob->max_hp / mod_def); + double attack_factor = (mob->atk1 + mob->atk2 + mob->str / 3.0 + mob->dex / 2.0 + mob->luk) * (1872 / mob->adelay) / 4; + double dodge_factor = pow(mob->lv + mob->agi + mob->luk / 2.0, 4.0 / 3.0); + double persuit_factor = (3 + mob->range) * (mob->mode % 2) * 1000 / mob->speed; + double aggression_factor = (mob->mode & 4) == 4 ? 10.0 / 9.0 : 1.0; + double xp = floor(effective_hp * pow(sqrt(attack_factor) + sqrt(dodge_factor) + sqrt(persuit_factor) + 55, 3) * aggression_factor / 2000000.0); + if (xp < 1) xp = 1; + return xp; +} static void mob_init(struct mob_data *md) @@ -3975,6 +3996,8 @@ static int mob_readdb(void) mob_db[class].head_mid=0; mob_db[class].head_buttom=0; mob_db[class].clothes_color=0; //Add for player monster dye - Valaris + + if (mob_db[class].base_exp == 0) mob_db[class].base_exp = mob_gen_exp(&mob_db[class]); } fclose(fp); printf("read %s done\n",filename[i]); |