00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 #ifndef DUNGEONGENERATOR_H
00019 #define DUNGEONGENERATOR_H
00020
00021 #include <stdio.h>
00022 #include <stdlib.h>
00023 #include <map>
00024 #include "constants.h"
00025 #include "map.h"
00026 #include "creature.h"
00027 #include "shapepalette.h"
00028 #include "board.h"
00029 #include "gui/progress.h"
00030
00031 using namespace std;
00032
00033
00034 class Map;
00035 class Creature;
00036 class Mission;
00037 class Progress;
00038
00039 #define DRAW_UNVISITED 0
00040
00041
00042 typedef struct _ShapePosition {
00043 char name[80];
00044 int x, y, z;
00045 } ShapePosition;
00046
00047 typedef struct _MapLocation {
00048 int x, y, w, h;
00049 int start[4][2];
00050 bool monsters;
00051 int roomCount;
00052 Uint16 roomDimension[20][5];
00053 char *map[MAP_WIDTH];
00054 int shapeCount;
00055 ShapePosition shapePosition[100];
00056 } MapLocation;
00057
00062 class DungeonGenerator {
00063 private:
00064
00065 static const char MESSAGE[];
00066
00067 typedef struct _Room {
00068 int x, y, w, h;
00069 int valueBonus;
00070 } Room;
00071 Room room[20];
00072
00073 enum { dgWIDTH = 0, dgHEIGHT, dgCURVYNESS, dgSPARSENESS,
00074 dgLOOPYNESS, dgROOMCOUNT, dgROOMMAXWIDTH, dgROOMMAXHEIGHT,
00075 dgOBJECTCOUNT };
00076 static const int levels[][9];
00077
00078 int level;
00079 int depth;
00080 int width;
00081 int height;
00082 int curvyness;
00083 int sparseness;
00084 Uint16 **nodes;
00085 int notVisitedCount, visitedCount;
00086 int *notVisited, *visited;
00087 int loopyness;
00088 int roomCount;
00089 int roomMaxWidth;
00090 int roomMaxHeight;
00091 int objectCount;
00092 int monsters;
00093 bool stairsDown, stairsUp;
00094 Mission *mission;
00095 Progress *progress;
00096
00097 Sint16 *ff;
00098 int ffCount;
00099
00100
00101 const static int DIR_N = 0;
00102 const static int DIR_E = 1;
00103 const static int DIR_S = 2;
00104 const static int DIR_W = 3;
00105 const static int DIR_COUNT = 4;
00106
00107
00108 const static Uint16 UNVISITED = 0x0000;
00109 const static Uint16 N_PASS = 0x0001;
00110 const static Uint16 S_PASS = 0x0002;
00111 const static Uint16 W_PASS = 0x0004;
00112 const static Uint16 E_PASS = 0x0008;
00113
00114 const static Uint16 N_DOOR = 0x0010;
00115 const static Uint16 S_DOOR = 0x0020;
00116 const static Uint16 E_DOOR = 0x0040;
00117 const static Uint16 W_DOOR = 0x0080;
00118
00119 const static Uint16 PASSAGE = 0x0100;
00120 const static Uint16 ROOM = 0x0200;
00121 const static Uint16 ROOM2 = 0x0400;
00122
00123 const static Uint16 EMPTY_ROOM = ROOM + N_PASS + S_PASS + E_PASS + W_PASS;
00124
00125 const static Sint16 offset = MAP_OFFSET;
00126
00127 const static Sint16 torches = 25;
00128 const static Sint16 randomDoors = 20;
00129
00130 int dirCount;
00131 int dirs[DIR_COUNT];
00132
00133
00134 const static Uint8 VERT_SHORT = 1;
00135 const static Uint8 VERT_LONG = 2;
00136 const static Uint8 HORIZ_SHORT = 3;
00137 const static Uint8 HORIZ_LONG = 4;
00138 const static Uint8 HORIZ_MEDIUM = 5;
00139 const static Uint8 HORIZ_SHORT2 = 6;
00140 const static Uint8 EMPTY_SHAPE = 7;
00141
00142 const static bool debug = false;
00143
00144 const static Sint16 unitOffset = MAP_UNIT_OFFSET;
00145 const static Sint16 unitSide = MAP_UNIT;
00146 const static Sint16 wallHeight = MAP_WALL_HEIGHT;
00147
00148 Scourge *scourge;
00149
00150 static const MapLocation location[];
00151
00152 const static int MAX_DOOR_COUNT = 500;
00153 int doorCount;
00154 int door[MAX_DOOR_COUNT][2];
00155
00156 vector<Item*> containers;
00157 vector<int> containerX;
00158 vector<int> containerY;
00159 vector<int> teleporterX;
00160 vector<int> teleporterY;
00161
00162 Uint32 start;
00163
00164 public:
00165
00166
00167 enum {
00168 HQ_LOCATION = 1,
00169
00170
00171 LOCATION_COUNT
00172 };
00173
00174 DungeonGenerator(Scourge *scourge, int level, int depth, bool stairsDown, bool stairsUp, Mission *mission = NULL);
00175 ~DungeonGenerator();
00176
00177 void toMap(Map *map, ShapePalette *shapePal, int location=0);
00178
00179 protected:
00180
00181
00182 void drawBasics(Map *map, ShapePalette *shapePal, bool preGenerated, int locationIndex);
00183 void removeColumns(Map *map, ShapePalette *shapePal, bool preGenerated, int locationIndex);
00184 void addContainers(Map *map, ShapePalette *shapePal, bool preGenerated, int locationIndex);
00185 bool addStairs(Map *map, ShapePalette *shapePal, bool preGenerated, int locationIndex);
00186 void addPregeneratedShapes(Map *map, ShapePalette *shapePal, bool preGenerated, int locationIndex);
00187 void addItems(Map *map, ShapePalette *shapePal, bool preGenerated, int locationIndex);
00188 void addMissionObjectives(Map *map, ShapePalette *shapePal, bool preGenerated, int locationIndex);
00189 void addMonsters(Map *map, ShapePalette *shapePal, bool preGenerated, int locationIndex);
00190 void addFurniture(Map *map, ShapePalette *shapePal, bool preGenerated, int locationIndex);
00191 bool addTeleporters(Map *map, ShapePalette *shapePal, bool preGenerated, int locationIndex);
00192 void addParty(Map *map, ShapePalette *shapePal, bool preGenerated, int locationIndex);
00193 void lockDoors(Map *map, ShapePalette *shapePal, bool preGenerated, int locationIndex);
00194 void lockLocation(Map *map, int mapx, int mapy);
00195 void createFreeSpaceMap(Map *map, ShapePalette *shapePal, bool preGenerated, int locationIndex);
00196 void deleteFreeSpaceMap(Map *map, ShapePalette *shapePal, bool preGenerated, int locationIndex);
00197 void calculateRoomValues(Map *map, ShapePalette *shapePal, bool preGenerated, int locationIndex);
00198
00199 void initByLevel();
00200 void generateMaze();
00201 void makeSparse();
00202 void makeLoops();
00203 void makeRooms();
00204
00205
00206 void constructMaze(int location);
00207
00208 bool drawNodesOnMap(Map *map, ShapePalette *shapePal,
00209 bool preGenerated, int locationIndex);
00210
00215 void nextNotVisited(int *x, int *y);
00216
00217 void nextVisited(int *x, int *y);
00218
00219 bool isVisited(int x, int y);
00220
00221 void markVisited(int x, int y);
00222
00223 int initDirections();
00224
00225 int nextDirection();
00226
00227 void printMaze();
00228
00229 void generatePassage(const int x, const int y, const bool stopAtVisited);
00230
00231 int getScore(int x, int y, int rw, int rh);
00232
00233 void getRandomLocation(Map *map, Shape *shape, int *x, int *y, bool accessible=false, int fromX=0, int fromY=0);
00234
00235 bool getLocationInRoom(Map *map, int roomIndex, Shape *shape,
00236 int *xpos, int *ypos, bool startMiddle=false);
00237
00238 bool coversDoor(Map *map, ShapePalette *shapePal, Shape *shape, int x, int y);
00239
00240 static const int MAX_STEPS = 10000;
00241 bool isAccessible(Map *map, int x, int y, int fromX, int fromY, int stepsTaken=0, int dir=DIR_N);
00242
00243 void addItem(Map *map, Creature *creature, Item *item, Shape *shape, int x, int y, int z = 0);
00244
00245 void drawDoor(Map *map, ShapePalette *shapePal,
00246 Sint16 mapx, Sint16 mapy, int doorType);
00247
00248 void addItemsInRoom(RpgItem *rpgItem, int n, bool preGenerated, int locationIndex);
00249
00250 bool addShapeInARoom(int shapeIndex);
00251
00252 void getRandomDeadEndLocation(int *x, int *y, GLShape *shape, Map *map);
00253
00254 int getRoomIndex(int x, int y);
00255
00256 void updateStatus(const char *statusMessage);
00257
00258 };
00259
00260 #endif
00261
00262
00263
00264