|
@@ -1669,7 +1669,7 @@ int map_searchrandfreecell(int16 m,int16 *x,int16 *y,int stack) {
|
|
|
}
|
|
|
if(free_cell==0)
|
|
|
return 0;
|
|
|
- free_cell = rnd()%free_cell;
|
|
|
+ free_cell = rnd_value(0, free_cell-1);
|
|
|
*x = free_cells[free_cell][0];
|
|
|
*y = free_cells[free_cell][1];
|
|
|
return 1;
|
|
@@ -1697,8 +1697,6 @@ int map_search_freecell(struct block_list *src, int16 m, int16 *x,int16 *y, int1
|
|
|
{
|
|
|
int tries, spawn=0;
|
|
|
int bx, by;
|
|
|
- int rx2 = 2*rx+1;
|
|
|
- int ry2 = 2*ry+1;
|
|
|
|
|
|
if( !src && (!(flag&1) || flag&2) )
|
|
|
{
|
|
@@ -1728,7 +1726,7 @@ int map_search_freecell(struct block_list *src, int16 m, int16 *x,int16 *y, int1
|
|
|
}
|
|
|
|
|
|
if (rx >= 0 && ry >= 0) {
|
|
|
- tries = rx2*ry2;
|
|
|
+ tries = (rx * 2 + 1) * (ry * 2 + 1);
|
|
|
if (tries > 100) tries = 100;
|
|
|
} else {
|
|
|
tries = mapdata->xs*mapdata->ys;
|
|
@@ -1736,8 +1734,8 @@ int map_search_freecell(struct block_list *src, int16 m, int16 *x,int16 *y, int1
|
|
|
}
|
|
|
|
|
|
while(tries--) {
|
|
|
- *x = (rx >= 0)?(rnd()%rx2-rx+bx):(rnd()%(mapdata->xs-2)+1);
|
|
|
- *y = (ry >= 0)?(rnd()%ry2-ry+by):(rnd()%(mapdata->ys-2)+1);
|
|
|
+ *x = (rx >= 0) ? rnd_value(bx - rx, bx + rx) : rnd_value<int16>(1, mapdata->xs - 1);
|
|
|
+ *y = (ry >= 0) ? rnd_value(by - ry, by + ry) : rnd_value<int16>(1, mapdata->ys - 1);
|
|
|
|
|
|
if (*x == bx && *y == by)
|
|
|
continue; //Avoid picking the same target tile.
|
|
@@ -1860,7 +1858,6 @@ bool map_closest_freecell(int16 m, int16 *x, int16 *y, int type, int flag)
|
|
|
*------------------------------------------*/
|
|
|
int map_addflooritem(struct item *item, int amount, int16 m, int16 x, int16 y, int first_charid, int second_charid, int third_charid, int flags, unsigned short mob_id, bool canShowEffect)
|
|
|
{
|
|
|
- int r;
|
|
|
struct flooritem_data *fitem = NULL;
|
|
|
|
|
|
nullpo_ret(item);
|
|
@@ -1870,7 +1867,6 @@ int map_addflooritem(struct item *item, int amount, int16 m, int16 x, int16 y, i
|
|
|
|
|
|
if (!map_searchrandfreecell(m,&x,&y,flags&2?1:0))
|
|
|
return 0;
|
|
|
- r = rnd();
|
|
|
|
|
|
CREATE(fitem, struct flooritem_data, 1);
|
|
|
fitem->bl.type=BL_ITEM;
|
|
@@ -1894,8 +1890,8 @@ int map_addflooritem(struct item *item, int amount, int16 m, int16 x, int16 y, i
|
|
|
|
|
|
memcpy(&fitem->item,item,sizeof(*item));
|
|
|
fitem->item.amount = amount;
|
|
|
- fitem->subx = (r&3)*3+3;
|
|
|
- fitem->suby = ((r>>2)&3)*3+3;
|
|
|
+ fitem->subx = rnd_value(1, 4) * 3;
|
|
|
+ fitem->suby = rnd_value(1, 4) * 3;
|
|
|
fitem->cleartimer = add_timer(gettick()+battle_config.flooritem_lifetime,map_clearflooritem_timer,fitem->bl.id,0);
|
|
|
|
|
|
map_addiddb(&fitem->bl);
|
|
@@ -3090,8 +3086,8 @@ int map_random_dir(struct block_list *bl, int16 *x, int16 *y)
|
|
|
if (dist < 1) dist =1;
|
|
|
|
|
|
do {
|
|
|
- short j = 1 + 2*(rnd()%4); //Pick a random diagonal direction
|
|
|
- short segment = 1+(rnd()%dist); //Pick a random interval from the whole vector in that direction
|
|
|
+ directions j = static_cast<directions>(1 + 2 * rnd_value(0, 3)); //Pick a random diagonal direction
|
|
|
+ short segment = rnd_value((short)1, dist); //Pick a random interval from the whole vector in that direction
|
|
|
xi = bl->x + segment*dirx[j];
|
|
|
segment = (short)sqrt((float)(dist2 - segment*segment)); //The complement of the previously picked segment
|
|
|
yi = bl->y + segment*diry[j];
|
|
@@ -5181,7 +5177,6 @@ bool MapServer::initialize( int argc, char *argv[] ){
|
|
|
#endif
|
|
|
cli_get_options(argc,argv);
|
|
|
|
|
|
- rnd_init();
|
|
|
map_config_read(MAP_CONF_NAME);
|
|
|
|
|
|
if (save_settings == CHARSAVE_NONE)
|