--- deliantra/server/random_maps/decor.C 2006/08/13 17:16:03 1.1 +++ deliantra/server/random_maps/decor.C 2006/09/10 16:06:37 1.2 @@ -1,6 +1,7 @@ + /* * static char *rcsid_decor_ = - * "$Id: decor.C,v 1.1 2006/08/13 17:16:03 elmex Exp $"; + * "$Id: decor.C,v 1.2 2006/09/10 16:06:37 root Exp $"; */ /* @@ -35,70 +36,90 @@ /* return a simple count of objects in the map at x,y. */ -int obj_count_in_map(mapstruct *map,int x,int y) { - int count=0; +int +obj_count_in_map (mapstruct *map, int x, int y) +{ + int count = 0; object *tmp; - for(tmp=get_map_ob(map,x,y);tmp!=NULL;tmp=tmp->above) - count++; + + for (tmp = get_map_ob (map, x, y); tmp != NULL; tmp = tmp->above) + count++; return count; } + /* put the decor into the map. Right now, it's very primitive. */ -void put_decor(mapstruct *map,char **maze,char *decorstyle,int decor_option,RMParms *RP) { +void +put_decor (mapstruct *map, char **maze, char *decorstyle, int decor_option, RMParms * RP) +{ mapstruct *decor_map; char style_name[256]; - sprintf(style_name,"/styles/decorstyles"); + sprintf (style_name, "/styles/decorstyles"); - decor_map = find_style(style_name,decorstyle,-1); - if(decor_map == NULL) return; + decor_map = find_style (style_name, decorstyle, -1); + if (decor_map == NULL) + return; /* pick a random option, only 1 option right now. */ - if(decor_option==0) - decor_option = RANDOM() % NR_DECOR_OPTIONS +1; - switch(decor_option) { - case 0: break; - case 1: { /* random placement of decor objects. */ - int number_to_place = RANDOM() % ( (RP->Xsize *RP->Ysize) / 5); - int failures=0; - object *new_decor_object; - while(failures < 100 && number_to_place > 0) { - int x,y; - x = RANDOM() % (RP->Xsize-2) +1; - y = RANDOM() % (RP->Ysize-2) +1; - if(maze[x][y]==0 && obj_count_in_map(map,x,y)<2) { /* empty */ - object *this_object; - new_decor_object = pick_random_object(decor_map); - this_object = arch_to_object(new_decor_object->arch); - copy_object(new_decor_object,this_object); - this_object->x = x; - this_object->y = y; - /* it screws things up if decor can stop people */ - this_object->move_block = MOVE_BLOCK_DEFAULT; - insert_ob_in_map(this_object,map,NULL,0); - number_to_place--; - } - else - failures++; - } - break; - } - default: { /* place decor objects everywhere: tile the map. */ - int i,j; - for(i=1;iXsize-1;i++) for(j=1;jYsize-1;j++) { - if(maze[i][j]==0) { - object *new_decor_object, *this_object; - - new_decor_object = pick_random_object(decor_map); - this_object = arch_to_object(new_decor_object->arch); - copy_object(new_decor_object,this_object); - this_object->x = i; - this_object->y = j; - /* it screws things up if decor can stop people */ - this_object->move_block = MOVE_BLOCK_DEFAULT; - insert_ob_in_map(this_object,map,NULL,0); + if (decor_option == 0) + decor_option = RANDOM () % NR_DECOR_OPTIONS + 1; + switch (decor_option) + { + case 0: + break; + case 1: + { /* random placement of decor objects. */ + int number_to_place = RANDOM () % ((RP->Xsize * RP->Ysize) / 5); + int failures = 0; + object *new_decor_object; + + while (failures < 100 && number_to_place > 0) + { + int x, y; + + x = RANDOM () % (RP->Xsize - 2) + 1; + y = RANDOM () % (RP->Ysize - 2) + 1; + if (maze[x][y] == 0 && obj_count_in_map (map, x, y) < 2) + { /* empty */ + object *this_object; + + new_decor_object = pick_random_object (decor_map); + this_object = arch_to_object (new_decor_object->arch); + copy_object (new_decor_object, this_object); + this_object->x = x; + this_object->y = y; + /* it screws things up if decor can stop people */ + this_object->move_block = MOVE_BLOCK_DEFAULT; + insert_ob_in_map (this_object, map, NULL, 0); + number_to_place--; + } + else + failures++; + } + break; + } + default: + { /* place decor objects everywhere: tile the map. */ + int i, j; + + for (i = 1; i < RP->Xsize - 1; i++) + for (j = 1; j < RP->Ysize - 1; j++) + { + if (maze[i][j] == 0) + { + object *new_decor_object, *this_object; + + new_decor_object = pick_random_object (decor_map); + this_object = arch_to_object (new_decor_object->arch); + copy_object (new_decor_object, this_object); + this_object->x = i; + this_object->y = j; + /* it screws things up if decor can stop people */ + this_object->move_block = MOVE_BLOCK_DEFAULT; + insert_ob_in_map (this_object, map, NULL, 0); + } + } + break; } - } - break; - } - } + } }