1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126
|
/*
* static char *rcsid_floor_c =
* "$Id: floor.c 8073 2008-01-03 10:50:04Z ryo_saeba $";
*/
/*
CrossFire, A Multiplayer game for X-windows
Copyright (C) 2002 Mark Wedel & Crossfire Development Team
Copyright (C) 1992 Frank Tore Johansen
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
The authors can be reached via e-mail at crossfire-devel@real-time.com
*/
#include <global.h>
#include <random_map.h>
#include <rproto.h>
/**
* Checks if the tile 'propagates' the floor.
* @param item
* tile to check.
* @return
* 1 if this tile should propagate, 0 else.
*/
static int can_propagate(char item) {
return (item == '\0' || item == '<' || item == '>') ? 1 : 0;
}
/**
* Put a floor at specified location, and then to adjacent tiles if applicable.
* @param map
* where to put the floor.
* @param layout
* layout that was used to generate the map.
* @param x
* @param y
* coordinates.
* @param floor_arch
* what floor to use.
*/
static void put_floor(mapstruct* map, char** layout, int x, int y, object* floor_arch) {
int dx, dy;
object* floor;
floor = arch_to_object(floor_arch->arch);
floor->x = x;
floor->y = y;
insert_ob_in_map(floor,map,floor,INS_NO_MERGE | INS_NO_WALK_ON);
for (dx = -1; dx < 2; dx++) {
for (dy = -1; dy < 2; dy++) {
if (GET_MAP_OB(map, x + dx, y + dy) == NULL && can_propagate(layout[x + dx][y + dy]))
put_floor(map, layout, x + dx, y + dy, floor_arch);
}
}
}
/**
* Creates the Crossfire mapstruct object from the layout, and adds the floor.
* @param layout
* generated layout.
* @param floorstyle
* floor style. Can be NULL, in which case a random one is chosen.
* @param RP
* parameters of the random map.
* @return
* Crossfire map.
* @todo
* use safe string functions.
*/
mapstruct *make_map_floor(char **layout, char *floorstyle,RMParms *RP) {
char styledirname[256];
char stylefilepath[256];
mapstruct *style_map=0;
object *the_floor;
mapstruct *newMap =0; /* (mapstruct *) calloc(sizeof(mapstruct),1); */
object *thisfloor;
int x, y;
/* allocate the map */
newMap = get_empty_map(RP->Xsize,RP->Ysize);
/* get the style map */
sprintf(styledirname,"%s","/styles/floorstyles");
sprintf(stylefilepath,"%s/%s",styledirname,floorstyle);
style_map = find_style(styledirname,floorstyle,-1);
if(style_map == 0) return newMap;
if (RP->multiple_floors) {
for (x = 0; x < RP->Xsize; x++) {
for (y = 0; y < RP->Ysize; y++) {
if (GET_MAP_OB(newMap, x, y) == NULL && layout[x][y] == '\0')
put_floor(newMap, layout, x, y, pick_random_object(style_map));
}
}
}
/* fill up the map with the given floor style */
if ((the_floor=pick_random_object(style_map))!=NULL) {
for(x=0;x<RP->Xsize;x++)
for(y=0;y<RP->Ysize;y++) {
if (GET_MAP_OB(newMap, x, y) != NULL)
continue;
thisfloor = arch_to_object(the_floor->arch);
thisfloor->x = x; thisfloor->y = y;
insert_ob_in_map(thisfloor,newMap,thisfloor,INS_NO_MERGE | INS_NO_WALK_ON);
}
}
return newMap;
}
|