summaryrefslogtreecommitdiff
path: root/src/map/mob.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/map/mob.c')
-rw-r--r--src/map/mob.c61
1 files changed, 31 insertions, 30 deletions
diff --git a/src/map/mob.c b/src/map/mob.c
index 1ddc9a662..3d48ba9ba 100644
--- a/src/map/mob.c
+++ b/src/map/mob.c
@@ -8,6 +8,7 @@
#include "../common/malloc.h"
#include "../common/showmsg.h"
#include "../common/ers.h"
+#include "../common/random.h"
#include "../common/strlib.h"
#include "../common/utils.h"
#include "../common/socket.h"
@@ -261,13 +262,13 @@ int mob_get_random_id(int type, int flag, int lv)
}
do {
if (type)
- class_ = summon[type].class_[rand()%summon[type].qty];
+ class_ = summon[type].class_[rnd()%summon[type].qty];
else //Dead branch
- class_ = rand() % MAX_MOB_DB;
+ class_ = rnd() % MAX_MOB_DB;
mob = mob_db(class_);
} while ((mob == mob_dummy ||
mob_is_clone(class_) ||
- (flag&1 && mob->summonper[type] <= rand() % 1000000) ||
+ (flag&1 && mob->summonper[type] <= rnd() % 1000000) ||
(flag&2 && lv < mob->lv) ||
(flag&4 && mob->status.mode&MD_BOSS) ||
(flag&8 && mob->spawn[0].qty < 1)
@@ -480,8 +481,8 @@ int mob_once_spawn_area(struct map_session_data* sd,int m,int x0,int y0,int x1,i
// find a suitable map cell
do {
- x = rand()%(x1-x0+1)+x0;
- y = rand()%(y1-y0+1)+y0;
+ x = rnd()%(x1-x0+1)+x0;
+ y = rnd()%(y1-y0+1)+y0;
j++;
} while( map_getcell(m,x,y,CELL_CHKNOPASS) && j < max );
@@ -797,7 +798,7 @@ int mob_setdelayspawn(struct mob_data *md)
spawntime = md->spawn->delay1; //Base respawn time
if (md->spawn->delay2) //random variance
- spawntime+= rand()%md->spawn->delay2;
+ spawntime+= rnd()%md->spawn->delay2;
//Apply the spawn delay fix [Skotlex]
db = mob_db(md->spawn->class_);
@@ -891,7 +892,7 @@ int mob_spawn (struct mob_data *md)
md->state.aggressive = md->status.mode&MD_ANGRY?1:0;
md->state.skillstate = MSS_IDLE;
- md->next_walktime = tick+rand()%5000+1000;
+ md->next_walktime = tick+rnd()%5000+1000;
md->last_linktime = tick;
md->last_pcneartime = 0;
@@ -1213,14 +1214,14 @@ int mob_unlocktarget(struct mob_data *md, unsigned int tick)
DIFF_TICK(md->next_walktime, tick) <= 0 &&
!mob_randomwalk(md,tick))
//Delay next random walk when this one failed.
- md->next_walktime=tick+rand()%3000;
+ md->next_walktime=tick+rnd()%3000;
break;
default:
mob_stop_attack(md);
if (battle_config.mob_ai&0x8)
mob_stop_walking(md,1); //Immediately stop chasing.
md->state.skillstate = MSS_IDLE;
- md->next_walktime=tick+rand()%3000+3000;
+ md->next_walktime=tick+rnd()%3000+3000;
break;
}
if (md->target_id) {
@@ -1248,7 +1249,7 @@ int mob_randomwalk(struct mob_data *md,unsigned int tick)
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=rnd();
x=r%(d*2+1)-d;
y=r/(d*2+1)%(d*2+1)-d;
x+=md->bl.x;
@@ -1276,7 +1277,7 @@ int mob_randomwalk(struct mob_data *md,unsigned int tick)
}
md->state.skillstate=MSS_WALK;
md->move_fail_count=0;
- md->next_walktime = tick+rand()%3000+3000+c;
+ md->next_walktime = tick+rnd()%3000+3000+c;
return 1;
}
@@ -1373,7 +1374,7 @@ static bool mob_ai_sub_hard(struct mob_data *md, unsigned int tick)
)
&& md->state.attacked_count++ >= RUDE_ATTACKED_COUNT
&& !mobskill_use(md, tick, MSC_RUDEATTACKED) // If can't rude Attack
- && can_move && unit_escape(&md->bl, tbl, rand()%10 +1)) // Attempt escape
+ && can_move && unit_escape(&md->bl, tbl, rnd()%10 +1)) // Attempt escape
{ //Escaped
md->attacked_id = 0;
return true;
@@ -1395,7 +1396,7 @@ static bool mob_ai_sub_hard(struct mob_data *md, unsigned int tick)
{ // Rude attacked
if (md->state.attacked_count++ >= RUDE_ATTACKED_COUNT
&& !mobskill_use(md, tick, MSC_RUDEATTACKED) && can_move
- && !tbl && unit_escape(&md->bl, abl, rand()%10 +1))
+ && !tbl && unit_escape(&md->bl, abl, rnd()%10 +1))
{ //Escaped.
//TODO: Maybe it shouldn't attempt to run if it has another, valid target?
md->attacked_id = 0;
@@ -1635,15 +1636,15 @@ static int mob_ai_sub_lazy(struct mob_data *md, va_list args)
{
if( map[md->bl.m].users > 0 )
{
- if( rand()%1000 < MOB_LAZYMOVEPERC(md) )
+ if( rnd()%1000 < MOB_LAZYMOVEPERC(md) )
mob_randomwalk(md, tick);
else
- if( rand()%1000 < MOB_LAZYSKILLPERC ) //Chance to do a mob's idle skill.
+ if( rnd()%1000 < MOB_LAZYSKILLPERC ) //Chance to do a mob's idle skill.
mobskill_use(md, tick, -1);
}
else
{
- if( rand()%1000 < MOB_LAZYMOVEPERC(md) )
+ if( rnd()%1000 < MOB_LAZYMOVEPERC(md) )
mob_randomwalk(md, tick);
}
}
@@ -2127,9 +2128,9 @@ int mob_dead(struct mob_data *md, struct block_list *src, int type)
if(battle_config.zeny_from_mobs && md->level) {
// zeny calculation moblv + random moblv [Valaris]
- zeny=(int) ((md->level+rand()%md->level)*per*bonus/100.);
+ zeny=(int) ((md->level+rnd()%md->level)*per*bonus/100.);
if(md->db->mexp > 0)
- zeny*=rand()%250;
+ zeny*=rnd()%250;
}
if (map[m].flag.nobaseexp || !md->db->base_exp)
@@ -2256,7 +2257,7 @@ int mob_dead(struct mob_data *md, struct block_list *src, int type)
drop_rate = drop_rate * drop_modifier / 100;
#endif
// attempt to drop the item
- if (rand() % 10000 >= drop_rate)
+ if (rnd() % 10000 >= drop_rate)
continue;
if( mvp_sd && it->type == IT_PETEGG ) {
@@ -2279,7 +2280,7 @@ int mob_dead(struct mob_data *md, struct block_list *src, int type)
}
// Ore Discovery [Celest]
- if (sd == mvp_sd && pc_checkskill(sd,BS_FINDINGORE)>0 && battle_config.finding_ore_rate/10 >= rand()%10000) {
+ if (sd == mvp_sd && pc_checkskill(sd,BS_FINDINGORE)>0 && battle_config.finding_ore_rate/10 >= rnd()%10000) {
ditem = mob_setdropitem(itemdb_searchrandomid(IG_FINDINGORE), 1);
mob_item_drop(md, dlist, ditem, 0, battle_config.finding_ore_rate/10, homkillonly);
}
@@ -2307,7 +2308,7 @@ int mob_dead(struct mob_data *md, struct block_list *src, int type)
//it's positive, then it goes as it is
drop_rate = sd->add_drop[i].rate;
- if (rand()%10000 >= drop_rate)
+ if (rnd()%10000 >= drop_rate)
continue;
itemid = (sd->add_drop[i].id > 0) ? sd->add_drop[i].id : itemdb_searchrandomid(sd->add_drop[i].group);
mob_item_drop(md, dlist, mob_setdropitem(itemid,1), 0, drop_rate, homkillonly);
@@ -2315,11 +2316,11 @@ int mob_dead(struct mob_data *md, struct block_list *src, int type)
}
// process script-granted zeny bonus (get_zeny_num) [Skotlex]
- if(sd->get_zeny_num && rand()%100 < sd->get_zeny_rate)
+ if(sd->get_zeny_num && rnd()%100 < sd->get_zeny_rate)
{
i = sd->get_zeny_num > 0?sd->get_zeny_num:-md->level*sd->get_zeny_num;
if (!i) i = 1;
- pc_getzeny(sd, 1+rand()%i);
+ pc_getzeny(sd, 1+rnd()%i);
}
}
@@ -2374,7 +2375,7 @@ int mob_dead(struct mob_data *md, struct block_list *src, int type)
else
for(j=0;j<3;j++)
{
- i = rand() % 3;
+ i = rnd() % 3;
if(md->db->mvpitem[i].nameid <= 0)
continue;
@@ -2384,7 +2385,7 @@ int mob_dead(struct mob_data *md, struct block_list *src, int type)
temp = md->db->mvpitem[i].p;
if(temp <= 0 && !battle_config.drop_rate0item)
temp = 1;
- if(temp <= rand()%10000+1) //if ==0, then it doesn't drop
+ if(temp <= rnd()%10000+1) //if ==0, then it doesn't drop
continue;
memset(&item,0,sizeof(item));
@@ -2494,7 +2495,7 @@ void mob_revive(struct mob_data *md, unsigned int hp)
unsigned int tick = gettick();
md->state.skillstate = MSS_IDLE;
md->last_thinktime = tick;
- md->next_walktime = tick+rand()%50+5000;
+ md->next_walktime = tick+rnd()%50+5000;
md->last_linktime = tick;
md->last_pcneartime = 0;
memset(md->dmglog, 0, sizeof(md->dmglog)); // Reset the damage done on the rebirthed monster, otherwise will grant full exp + damage done. [Valaris]
@@ -2577,7 +2578,7 @@ int mob_random_class (int *value, size_t count)
return 0;
}
//Pick a random value, hoping it exists. [Skotlex]
- return mobdb_checkid(value[rand()%count]);
+ return mobdb_checkid(value[rnd()%count]);
}
/*==========================================
@@ -2742,7 +2743,7 @@ int mob_summonslave(struct mob_data *md2,int *value,int amount,int skill_id)
while(count < 5 && mobdb_checkid(value[count])) count++;
if(count < 1) return 0;
if (amount > 0 && amount < count) { //Do not start on 0, pick some random sub subset [Skotlex]
- k = rand()%count;
+ k = rnd()%count;
amount+=k; //Increase final value by same amount to preserve total number to summon.
}
@@ -2946,7 +2947,7 @@ int mobskill_use(struct mob_data *md, unsigned int tick, int event)
return 0; //Skill act delay only affects non-event skills.
//Pick a starting position and loop from that.
- i = battle_config.mob_ai&0x100?rand()%md->db->maxskill:0;
+ i = battle_config.mob_ai&0x100?rnd()%md->db->maxskill:0;
for (n = 0; n < md->db->maxskill; i++, n++) {
int c2, flag = 0;
@@ -2966,7 +2967,7 @@ int mobskill_use(struct mob_data *md, unsigned int tick, int event)
else
continue;
}
- if (rand() % 10000 > ms[i].permillage) //Lupus (max value = 10000)
+ if (rnd() % 10000 > ms[i].permillage) //Lupus (max value = 10000)
continue;
if (ms[i].cond1 == event)