/* * Copyright (C) 2002-2007 The Warp Rogue Team * Part of the Warp Rogue Project * * This software is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License. * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY. * * See the license.txt file for more details. */ /* * Module Name: WorldGeneration * Description: - */ /* * Area Generator 'cave' */ #define Uses_World #define Uses_Area #define Uses_Sector #define Uses_Object #define Uses_Terrain #define Uses_ProgramManager #define Uses_LoadSave #define Uses_Util #include "mheader.h" #include "cellcave.h" #include "generate.h" #define CAVE_Y_MIN 2 #define CAVE_X_MIN 8 #define CAVE_Y_MAX (AREA_HEIGHT - CAVE_Y_MIN - 1) #define CAVE_X_MAX (AREA_WIDTH - CAVE_X_MIN - 1) #define CAVE_GATE_HEIGHT 5 #define CAVE_GATE_SIDE_EX 2 #define CAVE_HEIGHT (AREA_HEIGHT - CAVE_Y_MIN * 2) #define CAVE_WIDTH (AREA_WIDTH - CAVE_X_MIN * 2) /* * cave generator configuration type */ typedef struct { char wall[OBJECT_NAME_SIZE]; char floor[TERRAIN_NAME_SIZE]; char way_up[OBJECT_NAME_SIZE]; char way_down[OBJECT_NAME_SIZE]; WORLD_COORD gate_level; char env_terrain[TERRAIN_NAME_SIZE]; char env_object[OBJECT_NAME_SIZE]; } CAVE_CONFIG; static void cave_generate_sector(const AREA_POINT *, CCD_TILE ); static void cave_build_gate(void); /* * cave generator configuartion */ static CAVE_CONFIG CaveConfig; /* * cave generator configuration template (default values) */ static const CAVE_CONFIG CaveConfigTemplate = { /* WALL */ "", /* FLOOR */ "", /* WAY_UP */ "", /* WAY_DOWN */ "", /* GATE_LEVEL */ WORLD_COORD_NIL, /* ENV_TERRAIN */ "", /* EVN_OBJECT */ "" }; /* * the area section occupied by the cave */ static AREA_SECTION CaveArea = { CAVE_Y_MIN, CAVE_Y_MAX, CAVE_X_MIN, CAVE_X_MAX }; /* * generates a cave area */ void cave_generate(void) { AREA *area; CCD_DUNGEON *cave; AREA_POINT p; area = active_area(); cave = ccd_build_dungeon(CAVE_HEIGHT, CAVE_WIDTH, CCD_DT_CAVE ); for (p.y = CaveArea.top; p.y <= CaveArea.bottom; p.y++) { for (p.x = CaveArea.left; p.x <= CaveArea.right; p.x++) { AREA_COORD y, x; y = p.y - CAVE_Y_MIN; x = p.x - CAVE_X_MIN; cave_generate_sector(&p, cave->map[y][x]); } } ccd_free_dungeon(cave); if (area->location.z == CaveConfig.gate_level) { cave_build_gate(); } add_environment(CaveConfig.env_terrain, CaveConfig.env_object ); add_connections(&CaveArea, CaveConfig.way_up, CaveConfig.way_down ); } /* * sets the wall object */ void cave_set_wall(const char *object) { strcpy(CaveConfig.wall, object); } /* * sets the floor terrain */ void cave_set_floor(const char *terrain) { strcpy(CaveConfig.floor, terrain); } /* * sets the connection objects */ void cave_set_connections(const char *way_up, const char *way_down) { strcpy(CaveConfig.way_up, way_up); strcpy(CaveConfig.way_down, way_down); } /* * sets the gate level */ void cave_set_gate_level(WORLD_COORD level) { CaveConfig.gate_level = level; } /* * sets the environment */ void cave_set_environment(const char *terrain, const char *object) { strcpy(CaveConfig.env_terrain, terrain); if (object != NULL) { strcpy(CaveConfig.env_object, object); } } /* * generates a cave sector */ static void cave_generate_sector(const AREA_POINT *p, CCD_TILE dungeon_tile ) { TERRAIN *terrain; OBJECT *object; object = NULL; terrain = terrain_create(CaveConfig.floor); place_terrain(terrain, p); if (dungeon_tile == CCD_TILE_FLOOR) return; if (dungeon_tile == CCD_TILE_WALL) { object = object_create(CaveConfig.wall); } if (object != NULL) { place_object(object, p); } } /* * builds the cave gate */ static void cave_build_gate(void) { AREA_POINT c; c.y = CaveArea.bottom; c.x = (CAVE_WIDTH / 2) + CAVE_X_MIN; build_gate(&c, CAVE_GATE_HEIGHT, CAVE_GATE_SIDE_EX); }