Atrinik Server 2.5
random_maps/floor.c
Go to the documentation of this file.
00001 /************************************************************************
00002 *            Atrinik, a Multiplayer Online Role Playing Game            *
00003 *                                                                       *
00004 *    Copyright (C) 2009-2011 Alex Tokar and Atrinik Development Team    *
00005 *                                                                       *
00006 * Fork from Daimonin (Massive Multiplayer Online Role Playing Game)     *
00007 * and Crossfire (Multiplayer game for X-windows).                       *
00008 *                                                                       *
00009 * This program is free software; you can redistribute it and/or modify  *
00010 * it under the terms of the GNU General Public License as published by  *
00011 * the Free Software Foundation; either version 2 of the License, or     *
00012 * (at your option) any later version.                                   *
00013 *                                                                       *
00014 * This program is distributed in the hope that it will be useful,       *
00015 * but WITHOUT ANY WARRANTY; without even the implied warranty of        *
00016 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
00017 * GNU General Public License for more details.                          *
00018 *                                                                       *
00019 * You should have received a copy of the GNU General Public License     *
00020 * along with this program; if not, write to the Free Software           *
00021 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.             *
00022 *                                                                       *
00023 * The author can be reached at admin@atrinik.org                        *
00024 ************************************************************************/
00025 
00030 #include <global.h>
00031 
00038 mapstruct *make_map_floor(char *floorstyle, RMParms *RP)
00039 {
00040     char styledirname[256], stylefilepath[256];
00041     mapstruct *style_map = NULL, *newMap = NULL;
00042     int x, y;
00043 
00044     /* Allocate the map */
00045     newMap = get_empty_map(RP->Xsize, RP->Ysize);
00046 
00047     /* Get the style map */
00048     strncpy(styledirname, "/styles/floorstyles", sizeof(styledirname) - 1);
00049     snprintf(stylefilepath, sizeof(stylefilepath), "%s/%s", styledirname, floorstyle);
00050     style_map = find_style(styledirname, floorstyle, -1);
00051 
00052     if (style_map == NULL)
00053     {
00054         return newMap;
00055     }
00056 
00057     /* Fill up the map with the given floor style */
00058     for (x = 0; x < RP->Xsize; x++)
00059     {
00060         for (y = 0; y < RP->Ysize; y++)
00061         {
00062             object *the_floor = pick_random_object(style_map), *thisfloor = get_object();
00063 
00064             copy_object(the_floor, thisfloor, 0);
00065             thisfloor->x = x;
00066             thisfloor->y = y;
00067 
00068             insert_ob_in_map(thisfloor, newMap, thisfloor, INS_NO_MERGE | INS_NO_WALK_ON);
00069         }
00070     }
00071 
00072     return newMap;
00073 }