summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJared Adams <jaxad0127@gmail.com>2009-10-15 06:38:48 -0600
committerJared Adams <jaxad0127@gmail.com>2009-10-15 06:38:48 -0600
commitd6dbf554bd866124b7c676187c351c3f67fd3906 (patch)
tree2301dbf20ee0994963ccebfd1c5f7fd73e08a200 /src
parenta11a55e91bd25f52eac46a99f4c906e773245046 (diff)
parent29844ce5e2cd043551b46c1cd7bf3a36e357e3c6 (diff)
downloadtmwa-d6dbf554bd866124b7c676187c351c3f67fd3906.tar.gz
tmwa-d6dbf554bd866124b7c676187c351c3f67fd3906.tar.bz2
tmwa-d6dbf554bd866124b7c676187c351c3f67fd3906.tar.xz
tmwa-d6dbf554bd866124b7c676187c351c3f67fd3906.zip
Merge remote branch 'taw/master'
Diffstat (limited to 'src')
-rw-r--r--src/common/mt_rand.c9
-rw-r--r--src/common/mt_rand.h1
-rw-r--r--src/map/itemdb.c4
-rw-r--r--src/map/magic-expr.c17
-rw-r--r--src/map/mob.c41
-rw-r--r--src/map/script.c2
6 files changed, 52 insertions, 22 deletions
diff --git a/src/common/mt_rand.c b/src/common/mt_rand.c
index ab733ae..fc9a9ec 100644
--- a/src/common/mt_rand.c
+++ b/src/common/mt_rand.c
@@ -108,3 +108,12 @@ unsigned long mt_random(void)
y ^= (y << 15) & 0xEFC60000U;
return(y ^ (y >> 18));
}
+
+int mt_rand(void) {
+ unsigned long r = mt_random();
+ while (r >> 16)
+ r = (r & 0xFFFF) + (r >> 16);
+
+ return(r);
+}
+
diff --git a/src/common/mt_rand.h b/src/common/mt_rand.h
index 07f6ef0..bda5861 100644
--- a/src/common/mt_rand.h
+++ b/src/common/mt_rand.h
@@ -4,5 +4,6 @@
void mt_seed(unsigned long seed);
unsigned long mt_reload(void);
unsigned long mt_random(void);
+int mt_rand(void);
#endif /* __mt_rand_h */
diff --git a/src/map/itemdb.c b/src/map/itemdb.c
index d9cb429..3b49b50 100644
--- a/src/map/itemdb.c
+++ b/src/map/itemdb.c
@@ -111,8 +111,8 @@ int itemdb_searchrandomid(int flags)
if(count > 0) {
for(i=0;i<1000;i++) {
- index = rand()%count;
- if( rand()%1000000 < list[index].per) {
+ index = MRAND(count);
+ if( MRAND(1000000) < list[index].per) {
nameid = list[index].nameid;
break;
}
diff --git a/src/map/magic-expr.c b/src/map/magic-expr.c
index c136a17..9d3c751 100644
--- a/src/map/magic-expr.c
+++ b/src/map/magic-expr.c
@@ -607,8 +607,6 @@ fun_location(env_t *env, int args_nr, val_t *result, val_t *args)
return 0;
}
-/* Recall that glibc's rand() isnt' too bad in the lower bits */
-
static int
fun_random(env_t *env, int args_nr, val_t *result, val_t *args)
{
@@ -619,7 +617,8 @@ fun_random(env_t *env, int args_nr, val_t *result, val_t *args)
RESULTINT = 0;
return 0;
}
- RESULTINT = rand() % delta;
+ RESULTINT = MRAND(delta);
+
if (ARGINT(0) < 0)
RESULTINT = -RESULTINT;
return 0;
@@ -629,9 +628,9 @@ static int
fun_random_dir(env_t *env, int args_nr, val_t *result, val_t *args)
{
if (ARGINT(0))
- RESULTDIR = rand() & 0x7;
+ RESULTDIR = mt_random() & 0x7;
else
- RESULTDIR = (rand() & 0x3) * 2;
+ RESULTDIR = (mt_random() & 0x3) * 2;
return 0;
}
@@ -850,7 +849,7 @@ magic_random_location(location_t *dest, area_t *area)
{
switch (area->ty) {
case AREA_UNION: {
- int rv = rand() % area->size;
+ int rv = MRAND(area->size);
if (rv < area->a.a_union[0]->size)
magic_random_location(dest, area->a.a_union[0]);
else
@@ -870,14 +869,14 @@ magic_random_location(location_t *dest, area_t *area)
if (h <= 1)
h = 1;
- x += rand() % w;
- y += rand() % h;
+ x += MRAND(w);
+ y += MRAND(h);
if (!map_is_solid(m, x, y)) {
int start_x = x;
int start_y = y;
int i;
- int initial_dir = rand() & 0x7;
+ int initial_dir = mt_random() & 0x7;
int dir = initial_dir;
/* try all directions, up to a distance to 10, for a free slot */
diff --git a/src/map/mob.c b/src/map/mob.c
index cec0b92..5a0bedc 100644
--- a/src/map/mob.c
+++ b/src/map/mob.c
@@ -699,10 +699,10 @@ static int mob_walk(struct mob_data *md,unsigned int tick,int data)
}
/*==========================================
- * Attack processing of mob
+ * Check if mob should be attempting to attack
*------------------------------------------
*/
-static int mob_attack(struct mob_data *md,unsigned int tick,int data)
+static int mob_check_attack(struct mob_data *md)
{
struct block_list *tbl=NULL;
struct map_session_data *tsd=NULL;
@@ -716,7 +716,7 @@ static int mob_attack(struct mob_data *md,unsigned int tick,int data)
md->state.state=MS_IDLE;
md->state.skillstate=MSS_IDLE;
- if( md->skilltimer!=-1 ) // スキル使用中
+ if( md->skilltimer!=-1 )
return 0;
if(md->opt1>0 || md->option&2)
@@ -742,11 +742,11 @@ static int mob_attack(struct mob_data *md,unsigned int tick,int data)
return 0;
if(tsd){
- if( pc_isdead(tsd) || tsd->invincible_timer != -1 || pc_isinvisible(tsd) || md->bl.m != tbl->m || tbl->prev == NULL || distance(md->bl.x,md->bl.y,tbl->x,tbl->y)>=13 ){
- md->target_id=0;
- md->state.targettype = NONE_ATTACKABLE;
- return 0;
- }
+ if( pc_isdead(tsd) || tsd->invincible_timer != -1 || pc_isinvisible(tsd) || md->bl.m != tbl->m || tbl->prev == NULL || distance(md->bl.x,md->bl.y,tbl->x,tbl->y)>=13 ) {
+ md->target_id=0;
+ md->state.targettype = NONE_ATTACKABLE;
+ return 0;
+ }
}
if(tmd){
if(md->bl.m != tbl->m || tbl->prev == NULL || distance(md->bl.x,md->bl.y,tbl->x,tbl->y)>=13){
@@ -758,7 +758,7 @@ static int mob_attack(struct mob_data *md,unsigned int tick,int data)
if(!md->mode)
- mode=mob_db[md->class].mode;
+ mode=mob_db[md->class].mode;
else
mode=md->mode;
@@ -780,6 +780,26 @@ static int mob_attack(struct mob_data *md,unsigned int tick,int data)
range++;
if(distance(md->bl.x,md->bl.y,tbl->x,tbl->y) > range)
return 0;
+
+ return 1;
+}
+
+/*==========================================
+ * Attack processing of mob
+ *------------------------------------------
+ */
+static int mob_attack(struct mob_data *md,unsigned int tick,int data)
+{
+ struct block_list *tbl=NULL;
+
+ nullpo_retr(0, md);
+
+ if((tbl=map_id2bl(md->target_id))==NULL)
+ return 0;
+
+ if (!mob_check_attack(md))
+ return 0;
+
if(battle_config.monster_attack_direction_change)
md->dir=map_calc_dir(&md->bl, tbl->x,tbl->y ); // 向き設定
@@ -918,6 +938,7 @@ static int mob_timer(int tid,unsigned int tick,int id,int data)
map_freeblock_lock();
switch(md->state.state){
case MS_WALK:
+ mob_check_attack(md);
mob_walk(md,tick,data);
break;
case MS_ATTACK:
@@ -1651,7 +1672,7 @@ static int mob_randomwalk(struct mob_data *md,int tick)
int i,x,y,c,d=12-md->move_fail_count;
if(d<5) d=5;
for(i=0;i<retrycount;i++){ // Search of a movable place
- int r=rand();
+ int r=mt_random();
x=md->bl.x+r%(d*2+1)-d;
y=md->bl.y+r/(d*2+1)%(d*2+1)-d;
if((c=map_getcell(md->bl.m,x,y))!=1 && c!=5 && mob_walktoxy(md,x,y,1)==0){
diff --git a/src/map/script.c b/src/map/script.c
index d01fc99..7c63b85 100644
--- a/src/map/script.c
+++ b/src/map/script.c
@@ -4158,7 +4158,7 @@ int buildin_sc_start2(struct script_state *st)
bl = map_id2bl(st->rid);
if(bl->type == BL_PC && ((struct map_session_data *)bl)->state.potionpitcher_flag)
bl = map_id2bl(((struct map_session_data *)bl)->skilltarget);
- if(rand()%10000 < per)
+ if(MRAND(10000) < per)
skill_status_change_start(bl,type,val1,0,0,0,tick,0);
return 0;
}