Crossfire Server, Branch 1.12
R12190
|
00001 /* 00002 * static char *rcsid_floor_c = 00003 * "$Id: floor.c 11578 2009-02-23 22:02:27Z lalo $"; 00004 */ 00005 00006 /* 00007 CrossFire, A Multiplayer game for X-windows 00008 00009 Copyright (C) 2002 Mark Wedel & Crossfire Development Team 00010 Copyright (C) 1992 Frank Tore Johansen 00011 00012 This program is free software; you can redistribute it and/or modify 00013 it under the terms of the GNU General Public License as published by 00014 the Free Software Foundation; either version 2 of the License, or 00015 (at your option) any later version. 00016 00017 This program is distributed in the hope that it will be useful, 00018 but WITHOUT ANY WARRANTY; without even the implied warranty of 00019 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00020 GNU General Public License for more details. 00021 00022 You should have received a copy of the GNU General Public License 00023 along with this program; if not, write to the Free Software 00024 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 00025 00026 The authors can be reached via e-mail at crossfire-devel@real-time.com 00027 */ 00028 00034 #include <global.h> 00035 #include <random_map.h> 00036 #include <rproto.h> 00037 00045 static int can_propagate(char item) { 00046 return (item == '\0' || item == '<' || item == '>') ? 1 : 0; 00047 } 00048 00061 static void put_floor(mapstruct *map, char **layout, int x, int y, object *floor_arch) { 00062 int dx, dy; 00063 object *floor; 00064 00065 floor = arch_to_object(floor_arch->arch); 00066 floor->x = x; 00067 floor->y = y; 00068 insert_ob_in_map(floor, map, floor, INS_NO_MERGE|INS_NO_WALK_ON); 00069 00070 for (dx = -1; dx < 2; dx++) { 00071 for (dy = -1; dy < 2; dy++) { 00072 if (GET_MAP_OB(map, x+dx, y+dy) == NULL && can_propagate(layout[x+dx][y+dy])) 00073 put_floor(map, layout, x+dx, y+dy, floor_arch); 00074 } 00075 } 00076 } 00077 00089 mapstruct *make_map_floor(char **layout, char *floorstyle, RMParms *RP) { 00090 char styledirname[256]; 00091 char stylefilepath[256]; 00092 mapstruct *style_map = NULL; 00093 object *the_floor; 00094 mapstruct *newMap = NULL; 00095 int x, y; 00096 00097 /* allocate the map */ 00098 newMap = get_empty_map(RP->Xsize, RP->Ysize); 00099 00100 /* get the style map */ 00101 snprintf(styledirname, sizeof(styledirname), "%s", "/styles/floorstyles"); 00102 snprintf(stylefilepath, sizeof(stylefilepath), "%s/%s", styledirname, floorstyle); 00103 style_map = find_style(styledirname, floorstyle, -1); 00104 if (style_map == NULL) 00105 return newMap; 00106 00107 if (RP->multiple_floors) { 00108 for (x = 0; x < RP->Xsize; x++) { 00109 for (y = 0; y < RP->Ysize; y++) { 00110 if (GET_MAP_OB(newMap, x, y) == NULL && layout[x][y] == '\0') 00111 put_floor(newMap, layout, x, y, pick_random_object(style_map)); 00112 } 00113 } 00114 } 00115 00116 /* fill up the map with the given floor style */ 00117 if ((the_floor = pick_random_object(style_map)) != NULL) { 00118 object *thisfloor; 00119 00120 for (x = 0; x < RP->Xsize; x++) 00121 for (y = 0; y < RP->Ysize; y++) { 00122 if (GET_MAP_OB(newMap, x, y) != NULL) 00123 continue; 00124 thisfloor = arch_to_object(the_floor->arch); 00125 thisfloor->x = x; 00126 thisfloor->y = y; 00127 insert_ob_in_map(thisfloor, newMap, thisfloor, INS_NO_MERGE|INS_NO_WALK_ON); 00128 } 00129 } 00130 return newMap; 00131 }