void RDC::G(Mesh& m) const { Mesh m2(Mesh::Box(q.p1, q.p2, q.p3, q.p4, h)); m.merge(m2); addDoor(m, q.p1, q.p2, q.p3, q.p4, h); // La grammaire commence ici int e = rand()%100; if (e < dif) { int e = rand() % 100; if (e < 95){ float window_size = 1.5f + (float)(rand() % 100) / 100.f; Etage(q.p1 + Vec3<float>(0.0, 0.0, h), q.p2 + Vec3<float>(0.0, 0.0, h), q.p3 + Vec3<float>(0.0, 0.0, h), q.p4 + Vec3<float>(0.0, 0.0, h), h, dif, type, 0.f, false, 0, window_size).G(m); } else{ EtageCircle(q.p1 + Vec3<float>(0.0, 0.0, h), q.p2 + Vec3<float>(0.0, 0.0, h), q.p3 + Vec3<float>(0.0, 0.0, h), q.p4 + Vec3<float>(0.0, 0.0, h), h, dif+20, 0).G(m); } } else { Toit(q.p1 + Vec3<float>(0.0, 0.0, h), q.p2 + Vec3<float>(0.0, 0.0, h), q.p3 + Vec3<float>(0.0, 0.0, h), q.p4 + Vec3<float>(0.0, 0.0, h), h,0.f,0).G(m); } }
void refreshTileMap(Game* g) { memset(g->doors, 0, g->doorArraySize * sizeof(door)); memset(g->enemies, 0, g->enemyArraySize * sizeof(enemy)); memset(g->gameKeys, 0, g->keyArraySize * sizeof(key)); memset(g->shots, 0, g->shotArraySize * sizeof(shot)); memset(&g->player1, 0, sizeof(player)); memset(&g->stairs, 0, sizeof(stair)); Tile* t; for (int i = 0; i < TILEMAPSIDE; i++) { for (int j = 0; j < TILEMAPSIDE; j++) { t = &g->tileMaps[0].tiles[i][j]; switch (t->tileID) { case Tile::FLOOR: t->filled = FALSE; t->texID = g->floorTex; break; case Tile::WALL: t->filled = TRUE; t->texID = g->wallTex; break; case Tile::ENEMY_FLOOR: t->filled = false; t->texID = g->floorTex; //enemy spawn addEnemy(g, TILESIDE*(j + 0.5), TILESIDE*(i + 0.5), g->enemyTex); break; case Tile::PLAYER_FLOOR: t->filled = false; t->texID = g->floorTex; //player spawn setPlayer(g, TILESIDE*(j + 0.5) , TILESIDE*(i + 0.5), g->playerTex); break; case Tile::STAIR: t->filled = false; t->texID = g->floorTex; setStair(g, TILESIDE*(j + 0.5), TILESIDE*(i + 0.5), g->stairTex); break; case Tile::DOOR: t->filled = false; t->texID = g->floorTex; addDoor(g, TILESIDE*(j + 0.5), TILESIDE*(i + 0.5), g->doorTex); break; } } } printf(""); }
Entity *addEntityFromResource(char *type, char *name, int startX, int startY) { Entity *e = NULL; if (strcmpignorecase(type, "ITEM") == 0 || strcmpignorecase(type, "SHIELD") == 0 || strcmpignorecase(type, "WEAPON") == 0) { e = addPermanentItem(name, startX, startY); } else if (strcmpignorecase(type, "TEMP_ITEM") == 0 || strcmpignorecase(type, "HEALTH") == 0) { e = addTemporaryItem(name, startX, startY, LEFT, 0, 0); } else if (strcmpignorecase(type, "PLAYER") == 0) { e = loadPlayer(startX, startY, NULL); } else if (strcmpignorecase(type, "PLAYER_WEAPON") == 0) { setPlayerWeaponName(name); } else if (strcmpignorecase(type, "PLAYER_SHIELD") == 0) { setPlayerShieldName(name); } else if (strcmpignorecase(type, "KEY_ITEM") == 0) { e = addKeyItem(name, startX, startY); } else if (strcmpignorecase(type, "ENEMY") == 0) { e = addEnemy(name, startX, startY); } else if (strcmpignorecase(type, "NPC") == 0) { e = addNPC(name, startX, startY); } else if (strcmpignorecase(type, "AUTO_LIFT") == 0 || strcmpignorecase(type, "MANUAL_LIFT") == 0) { e = addLift(name, startX, startY, getEntityTypeByName(type)); } else if (strcmpignorecase(type, "SPAWNER") == 0) { e = addSpawner(startX, startY, name); } else if (strcmpignorecase(type, "TARGET") == 0) { addTarget(startX, startY, name); } else if (strcmpignorecase(type, "PRESSURE_PLATE") == 0) { e = addPressurePlate(name, startX, startY); } else if (strcmpignorecase(type, "TELEPORTER") == 0) { e = addTeleporter(name, startX, startY); } else if (strcmpignorecase(type, "AUTO_DOOR") == 0 || strcmpignorecase(type, "MANUAL_DOOR") == 0) { e = addDoor(name, startX, startY, getEntityTypeByName(type)); } else if (strcmpignorecase(type, "WEAK_WALL") == 0) { e = addWeakWall(name, startX, startY); } else if (strcmpignorecase(type, "TRAP_DOOR") == 0) { e = addTrapDoor(name, startX, startY); } else if (strcmpignorecase(type, "CONVEYOR_BELT") == 0) { e = addConveyorBelt(name, startX, startY); } else if (strcmpignorecase(type, "SWITCH") == 0) { e = addSwitch(name, startX, startY); } else if (strcmpignorecase(type, "SCRIPT_LINE_DEF") == 0 || strcmpignorecase(type, "LINE_DEF") == 0) { e = addLineDef(type, name, startX, startY); } else if (strcmpignorecase(type, "LEVEL_EXIT") == 0) { e = addLevelExit(name, startX, startY); } else if (strcmpignorecase(type, "SAVE_POINT") == 0) { /* Save points don't spawn for replays */ if (game.gameType == NORMAL) { e = addSavePoint(startX, startY); } } else if (strcmpignorecase(type, "TRIGGER") == 0) { addTriggerFromResource(key, value); } else if (strcmpignorecase(type, "GLOBAL_TRIGGER") == 0) { addGlobalTriggerFromResource(key, value); } else if (strcmpignorecase(type, "MAP_TRIGGER") == 0) { addMapTriggerFromResource(key, value); } else if (strcmpignorecase(type, "OBJECTIVE") == 0) { addObjectiveFromResource(key, value); } else if (strcmpignorecase(type, "ACTION_POINT") == 0) { e = addActionPoint(name, startX, startY); } else if (strcmpignorecase(type, "FALLING_PLATFORM") == 0) { e = addFallingPlatform(startX, startY, name); } else if (strcmpignorecase(type, "VANISHING_PLATFORM") == 0) { e = addVanishingPlatform(startX, startY, name); } else if (strcmpignorecase(type, "ANTI_GRAVITY") == 0) { e = addAntiGravityField(startX, startY, name); } else { showErrorAndExit("Unknown Entity type %s", type); } return e; }
int shMapLevel::buildBunkerRooms () { #define MSX 10 #define MSY 4 #define MAXROOMS 20 /* macro sq 5x6 cells of regular squares */ int macrosq[MSX][MSY]; int x, y; int i, n; int retry; int firstroom; struct { int sx, sy, ex, ey; /* macro dimensions */ int rsx, rsy, rex, rey; /* real dimensions */ int mark; } rooms[MAXROOMS]; char connect [MAXROOMS][MAXROOMS]; int maxcorridorlength = 3; mMapType = kBunkerRooms; // I->debug ("building bunker rooms"); n = 7 + RNG (3) + RNG (3); // n = 5; for (x = 0; x < MSX; x++) for (y = 0; y < MSY; y++) macrosq[x][y] = -1; for (x = 0; x < MAXROOMS; x++) for (y = 0; y < MAXROOMS; y++) connect[x][y] = 0; firstroom = 0; /* first step: determine the macro dimensions of the rooms */ reloop: retry = 0; for (i = firstroom; i < n; ++i) { rooms[i].mark = 0; retry: if (++retry > 100) { n = i; break; } x = RNG (MSX); if (RNG (2)) { /* a wide room */ y = RNG (MSY); if (-1 == macrosq[x][y] and x < MSX - 1 and -1 == macrosq[x+1][y]) { if (RNG(3) and y > 0 and (-1 != macrosq[x][y-1] or -1 != macrosq[x+1][y-1])) { goto retry; } if (RNG(2) and y < MSY - 1 and (-1 != macrosq[x][y+1] or -1 != macrosq[x+1][y+1])) { goto retry; } macrosq[x][y] = i; macrosq[x+1][y] = i; rooms[i].sx = x; rooms[i].sy = y; if (RNG(4) and x < MSX - 2 and -1 == macrosq[x+2][y]) { macrosq[x+2][y] = i; rooms[i].ex = x+2; } else { rooms[i].ex = x+1; if (y < MSY - 1 and -1 == macrosq[x][y+1] and -1 == macrosq[x+1][y+1]) { macrosq[x][y+1] = i; macrosq[x+1][y+1] = i; rooms[i].ey = y + 1; } } rooms[i].ey = y; } else { goto retry; } } else { /* a tall room */ y = RNG (MSY-1); if (-1 == macrosq[x][y] and -1 == macrosq[x][y+1]) { macrosq[x][y] = i; macrosq[x][y+1] = i; rooms[i].sx = x; rooms[i].sy = y; rooms[i].ey = y+1; rooms[i].ex = x; if (RNG (4) and x < MSX - 1 and -1 == macrosq[x+1][y] and -1 == macrosq[x+1][y+1]) { macrosq[x+1][y] = i; macrosq[x+1][y+1] = i; rooms[i].ex = x+1; } if (RNG (4) and x > 0 and -1 == macrosq[x-1][y] and -1 == macrosq[x-1][y+1]) { macrosq[x-1][y] = i; macrosq[x-1][y+1] = i; rooms[i].sx = x-1; } } else { goto retry; } } } /* deterimine real dimensions, and actually make the rooms: */ for (i = firstroom; i < n; i++) { int w, h; w = 6 * (rooms[i].ex - rooms[i].sx); if (w > 0) w -= 2; w = 5 + RNG (2) + RNG (w / 2, w); x = (RNG (1 + 6 * (1 + rooms[i].ex - rooms[i].sx) - w) + RNG (1 + 6 * (1 + rooms[i].ex - rooms[i].sx) - w)) / 2; if (rooms[i].sy != rooms[i].ey) { h = 5 + RNG (5); y = RNG (1 + 5 * (1 + rooms[i].ey - rooms[i].sy) - h); } else { h = RNG (5) ? 5 : 4; y = RNG (1 + 5 - h); } rooms[i].rsx = rooms[i].sx * 6 + x; rooms[i].rex = rooms[i].rsx + w - 1; rooms[i].rsy = rooms[i].sy * 5 + y; rooms[i].rey = rooms[i].rsy + h - 1; layRoom (rooms[i].rsx, rooms[i].rsy, rooms[i].rex, rooms[i].rey); } /* connect the rooms with corridors */ corridor: for (i = 0; i < n; i++) { int j; int cnt; int dir[4]; dir[0] = kNorth; dir[1] = kEast; dir[2] = kWest; dir[3] = kSouth; shuffle (dir, 4, sizeof (int)); for (j = 0; j < 4; j++) { int sx, sy, ex, ey; x = RNG (rooms[i].sx, rooms[i].ex); y = RNG (rooms[i].sy, rooms[i].ey); sx = x; sy = y; assert (x >= 0 and y >= 0); for (cnt = maxcorridorlength; cnt; --cnt) { int room; moveForward ((shDirection) dir[j], &x, &y); if (x < 0 or x >= MSX or y < 0 or y >= MSY) { break; } room = macrosq[x][y]; if (i == room) { sx = x; sy = y; continue; } else if (-2 == room) { /* we hit another corridor */ break; } else if (-1 != room) { /* we hit another room */ if (connect[i][room]) { /* but there's already a connecting corridor*/ break; } if (isHorizontal ((shDirection) dir[j])) { int lo, hi; lo = maxi (y * 5, 1 + maxi(rooms[room].rsy, rooms[i].rsy)); hi = mini (y * 5 + 4, mini(rooms[room].rey, rooms[i].rey) - 1); if (lo > hi) { break; } ex = maxi (x, sx); sx = mini (x, sx); for (x = sx + 1; x < ex; x++) { macrosq[x][y] = -2; } sx = mini (rooms[room].rex, rooms[i].rex); ex = maxi (rooms[room].rsx, rooms[i].rsx); /* I->debug ("y %d (%d, %d) (%d, %d)", y, rooms[room].rsy, rooms[room].rey, rooms[i].rsy, rooms[i].rey); */ y = RNG (lo, hi); /* Test for neighboring corridors or rooms. */ for (x = sx + 1; x <= ex - 1; ++x) { if (GETSQ (x, y) != kStone) break; } if (x != ex) break; int dark = RNG (mDLevel + 6) > 7; for (x = sx; x <= ex; x++) { SETSQ (x, y, kFloor); SETSQFLAG (x, y, kHallway); if (kStone == GETSQ (x, y - 1)) SETSQ (x, y - 1, kHWall); if (kStone == GETSQ (x, y + 1)) SETSQ (x, y + 1, kHWall); if (dark) { //NW NE SW SE setLit (x, y, x > sx ? -1 : 0, x < ex ? -1 : 0, x > sx ? -1 : 0, x < ex ? -1 : 0); setLit (x, y - 1, 0, 0, x > sx ? -1 : 0, x < ex ? -1 : 0); setLit (x, y + 1, x > sx ? -1 : 0, x < ex ? -1 : 0, 0, 0); } } addDoor (sx, y, 0); addDoor (ex, y, 0); } else { /* vertical */ if (rooms[room].rsx + 1 > rooms[i].rex - 1 or rooms[room].rex - 1 < rooms[i].rsx + 1) { break; } ey = maxi (y, sy); sy = mini (y, sy); for (y = sy + 1; y < ey; y++) { macrosq[x][y] = -2; } sy = mini (rooms[room].rey, rooms[i].rey); ey = maxi (rooms[room].rsy, rooms[i].rsy); x = RNG (1 + maxi(rooms[room].rsx, rooms[i].rsx), mini(rooms[room].rex, rooms[i].rex) - 1); /* Test for neighboring corridors or rooms. */ for (y = sy + 1; y <= ey - 1; ++y) { if (GETSQ (x, y) != kStone) break; } if (y != ey) break; int dark = RNG (mDLevel + 6) > 7; for (y = sy; y <= ey; y++) { SETSQ (x, y, kFloor); SETSQFLAG (x, y, kHallway); if (kStone == GETSQ (x - 1, y)) SETSQ (x - 1, y, kVWall); if (kStone == GETSQ (x + 1, y)) SETSQ (x + 1, y, kVWall); if (dark) { setLit (x, y, y > sy ? -1 : 0, y > sy ? -1 : 0, y < ey ? -1 : 0, y < ey ? -1 : 0); setLit (x - 1, y, 0, y > sy ? -1 : 0, 0, y < ey ? -1 : 0); setLit (x + 1, y, y > sy ? -1 : 0, 0, y < ey ? -1 : 0, 0); } } addDoor (x, sy, 1); addDoor (x, ey, 1); } j += RNG (3); connect[i][room] = 1; connect[room][i] = 1; break; } } } } /* The final check: are the rooms connected? Do a breadth first search, marking all the rooms reachable from room 0 */ { int j; int k; int bfs[MAXROOMS]; for (i = 0; i < n; ++i) { bfs[i] = -1; rooms[i].mark = 0; } k = 1; bfs[0] = 0; rooms[0].mark = 1; for (i = 0; i < k; i++) { int room = bfs[i]; for (j = 0; j < n; j++) { if (room != j and (connect[j][room] or connect[room][j]) and 0 == rooms[j].mark) { /* mark this room, add it to the search queue: */ rooms[j].mark = 1; bfs[k++] = j; } } } if (k != n) { // I->debug ("not connected!!! %d %d", k, n); /* add a new room? */ if (RNG (3) and n < MAXROOMS) { firstroom = n; n++; //I->debug ("desperately adding a room!"); goto reloop; } /* try again, with longer corridors */ ++maxcorridorlength; if (maxcorridorlength < MSX) { goto corridor; } else { /* miserable failure! */ //I->debug ("giving up :-("); for (i = 0; i < mFeatures.count (); i++) { delete mFeatures.get(i); } mFeatures.reset (); return 0; } } else { //I->debug ("connected! %d", n); } } for (i = 0; i < n; i++) { decorateRoom (rooms[i].rsx, rooms[i].rsy, rooms[i].rex, rooms[i].rey); } /* All newly dug tunnels will be dark. */ for (int y = 0; y < mRows ; ++y) { for (int x = 0; x < mColumns; ++x) { if (kStone == GETSQ (x, y)) setLit (x, y, -1, -1, -1, -1); } } /* for (y = 0; y < MSY; y++) { char buff[MSX+1]; for (x = 0; x < MSX; x++) { macrosq[x][y]; buff[x] = c >= 0 ? c + 'A' : c == -1 ? ' ' : '0' - c; } buff[MSX] = 0; I->debug ("%s", buff); } */ return 1; #undef MSX #undef MSY }
int generate ( int region[], int map, cUOSocket* socket ) { int count = 0; for ( int rx = region[0]; rx < region[2]; ++rx ) { for ( int ry = region[1]; ry < region[3]; ++ry ) { StaticsIterator tiles = Map->staticsIterator( map, rx, ry, true ); for ( ; !tiles.atEnd(); ++tiles ) { int id = tiles.data().itemid; int z = tiles.data().zoff; if ( isWestFrame( id ) ) { if ( coordHasEastFrame( rx + 2, ry, z, map ) ) { addDoor( rx + 1, ry, z, map, WestCW ); ++count; } else if ( coordHasEastFrame( rx + 3, ry, z, map ) ) { cItem* first = addDoor( rx + 1, ry, z, map, WestCW ); cItem* second = addDoor( rx + 2, ry, z, map, EastCCW ); count += 2; if ( first && second ) { first->setTag( "link", second->serial() ); second->setTag( "link", first->serial() ); } else { if ( !first && second ) { second->remove(); --count; } if ( !second && first ) { first->remove(); --count; } } } } else if ( isNorthFrame( id ) ) { if ( coordHasSouthFrame( rx, ry + 2, z, map ) ) { addDoor( rx, ry + 1, z, map, SouthCW ); ++count; } else if ( coordHasSouthFrame( rx, ry + 3, z, map ) ) { cItem* first = addDoor( rx, ry + 1, z, map, NorthCCW ); cItem* second = addDoor( rx, ry + 2, z, map, SouthCW ); count += 2; if ( first && second ) { first->setTag( "link", second->serial() ); second->setTag( "link", first->serial() ); } else { if ( !first && second ) { second->remove(); --count; } if ( !second && first ) { first->remove(); --count; } } } } } } } return count; }
//RETURNS: # of doors int shMapLevel::buildRoomOrElRoom (int sx, int sy, int ey) { int ex; int x; int y; int ndoors = 0; int doortries = 0; int ra = 0 == RNG (20); for (ex = sx + 2; ex < mColumns; ex++) { if ((ex > sx + 4) and (0 == RNG(7))) { /* check for nearby hallway */ if (isClear (ex, sy, mColumns, ey)) { do { --sx; --ex; } while (isClear (sx, sy, sx, ey)); ++sx; break; } while (1) { if (RNG (2)) { if (isClear (sx, ey, ex, ey)) { ey++; sy++; if (ey >= mRows) { return -1; } } else { break; } } else if (isClear (ex, sy, ex, ey)) { ex++; sx++; } else { break; } } } if (!isClear (ex, sy, ex, ey - 1)) { break; } } for (x = sx + 1; x < ex -1; x++) { for (y = sy + 1; y < ey -1; y++) { SETSQ (x, y, kFloor); if (ra) { SETSQFLAG (x, y, kRadioactive); } } } /* add walls */ for (x = sx + 1; x < ex - 1; x++) { SETSQ (x, sy, kHWall); SETSQ (x, ey - 1, kHWall); } for (y = sy + 1; y < ey - 1; y++) { SETSQ (sx, y, kVWall); SETSQ (ex - 1, y, kVWall); } SETSQ (sx, sy, kNWCorner); SETSQ (sx, ey - 1, kSWCorner); SETSQ (ex - 1, sy, kNECorner); SETSQ (ex - 1, ey - 1, kSECorner); /* add doors */ while ((doortries < 122) and (ndoors < 1 + RNG (ex - sx) / 4)) { if (RNG (2)) { x = RNG (sx + 1, ex - 2); y = RNG (2) ? sy : ey -1; if (TESTSQ (x, y - 1, kFloor) and TESTSQ (x, y + 1, kFloor)) { SETSQ (x, y, kFloor); addDoor (x, y, 0 == RNG (4), 0 == RNG (5), -1); ++ndoors; } } else { y = RNG (sy + 1, ey - 1); x = RNG (2) ? sx : ex - 1; if (TESTSQ (x - 1, y, kFloor) and TESTSQ (x + 1, y, kFloor)) { SETSQ (x, y, kFloor); addDoor (x, y, 0 == RNG (4), 0 == RNG (5), -1); ++ndoors; } } ++doortries; } return ndoors; }
void shMapLevel::decorateRoom (int sx, int sy, int ex, int ey) { if ((ex-sx) * (ey-sy) <= 20 + RNG (1, 20) and mDLevel > 1 and !RNG (1 + mDLevel) and !(kHasShop & mFlags) and makeShop (sx, sy, ex, ey)) { return; } while (!RNG (8)) { /* secret treasure niche */ int x, y, dx, dy, horiz; failedniche: if (!RNG (222)) break; if (RNG (2)) { x = RNG (sx + 1, ex - 1); dx = x; horiz = 1; if (RNG (2)) { if (!testSquares (x - 1, sy - 2, x + 1, sy - 1, kStone)) goto failedniche; y = sy - 1; dy = sy; } else { if (!testSquares (x - 1, ey + 1, x + 1, ey + 2, kStone)) goto failedniche; y = ey + 1; dy = ey; } } else { y = RNG (sy + 1, ey - 1); dy = y; horiz = 0; if (RNG (2)) { if (!testSquares (sx - 2, y - 1, sx - 1, y + 1, kStone)) goto failedniche; x = sx - 1; dx = sx; } else { if (!testSquares (ex + 1, y - 1, ex + 2, y + 1, kStone)) goto failedniche; x = ex + 1; dx = ex; } } SETSQ (x-1, y-1, kHWall); SETSQ (x, y-1, kHWall); SETSQ (x+1, y-1, kHWall); SETSQ (x-1, y, kVWall); SETSQ (x, y, kFloor); SETSQ (x+1, y, kVWall); SETSQ (x-1, y+1, kHWall); SETSQ (x, y+1, kHWall); SETSQ (x+1, y+1, kHWall); SETSQ (dx, dy, kFloor); addDoor (dx, dy, horiz, 0, RNG (6), 1, !RNG(3), !RNG(10)); SETSQFLAG (x, y, kHallway); if (RNG (6)) putObject (generateObject (mDLevel), x, y); if (RNG (2)) putObject (generateObject (mDLevel), x, y); } if (mDLevel > 7 and !RNG (15)) { /* monolith room */ shMonster *m = new shMonster (kMonMonolith); putCreature (m, (sx + ex) / 2, (sy + ey) / 2); return; } if ((mDLevel > 6) and !RNG (22) and makeNest (sx, sy, ex, ey)) { return; } if (mDLevel > 1 and mDLevel < 10 and !(kHasMelnorme & mFlags) and !RNG (30)) { /* Melnorme room. */ makeTradePost (sx, sy, ex, ey); } /* No return statement. Trade post is a mundane room. */ mundaneRoom (sx, sy, ex, ey); }