Guest User

Untitled

a guest
Jan 27th, 2013
4,944
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. class HouseGenerator
  2. {
  3. private:
  4.     static const area MinSplittableArea = ...; // 3 squares at least;
  5.     static const float MaxHallRate = ...; // 15%..40% I guess;
  6.  
  7.     rect House;
  8.     area TotalHallArea = 0;
  9.     queue<rect> Chunks, Halls, Blocks, Rooms;
  10.    
  11. public:
  12.     HouseGenerator() // ctor;
  13.     {
  14.         House = rect(x, y);
  15.     }
  16.    
  17.     void Generate()
  18.     {
  19.         ChunksToBlocks();
  20.         BlocksToRooms();
  21.        
  22.         ... //// TODO:
  23.        
  24.             // carve halls;
  25.             // where hall faces much older hall:
  26.                 // place wall;
  27.            
  28.             // carve rooms, leaving walls;
  29.            
  30.             // put every room in queue of unreachable rooms;
  31.             // while this queue is not empty:
  32.                 // get next room from queue;
  33.                 // if room is touching any number of halls:
  34.                     // make door, facing any avaliable hall;
  35.                     // put this room in queue of reachable rooms;
  36.                     // `continue`;
  37.                 // if room is touching any other reachable room:
  38.                     // connect this with other;
  39.                     // place door, if Random wants so;
  40.                     // `continue`;
  41.                 // put this room in queue of unreachable rooms;
  42.            
  43.             // place windows;
  44.     }
  45.    
  46. private:
  47.     void ChunksToBlocks()
  48.     {
  49.         Chunks << House;
  50.         while ((not Chunks.empty) && (TotalHallArea / House.area < MaxHallRate))
  51.         {
  52.             rect chunk;
  53.             Chunks >> chunk;
  54.            
  55.             if(chunk.area > MinSplittableArea)
  56.                 SplitChunk(chunk);
  57.             else Blocks << chunk;
  58.         }
  59.     }
  60.    
  61.     void SplitChunk(rect chunk)
  62.     {
  63.         rect hall;
  64.        
  65.         if (coin_flip()) // split in three;
  66.         {
  67.             rect chunk_a, chunk_b;
  68.             RandomChunkSplit3(current_block, chunk_a, hall, chunk_b);
  69.             Chunks << chunk_a << chunk_b;
  70.         }
  71.         else // split in two;
  72.         {
  73.             rect chunk_a;
  74.             RandomChunkSplit3(current_block, chunk_a, hall);
  75.             Chunks << chunk_a;
  76.         }
  77.        
  78.         Halls << hall;
  79.         TotalHallArea += hall.area;
  80.     }
  81.    
  82.     void BlocksToRooms()
  83.     {
  84.         while (not Blocks.empty)
  85.         {
  86.             rect block;
  87.             Blocks >> block;
  88.            
  89.             if (WantSplitBlock(block))
  90.             {
  91.                 rect block_a, block_b;
  92.                 RandomBlockSplit(block, block_a, block_b);
  93.                 Blocks << block_a << block_b;
  94.             }
  95.             else
  96.                 Rooms << block;
  97.         }
  98.     }
  99.    
  100.     //// TODO:
  101.     void RandomChunkSplit3(...);
  102.     void RandomChunkSplit2(...);
  103.     bool WantSplitBlock(...);
  104.     void RandomBlockSplit(...);
  105. }
RAW Paste Data

Adblocker detected! Please consider disabling it...

We've detected AdBlock Plus or some other adblocking software preventing Pastebin.com from fully loading.

We don't have any obnoxious sound, or popup ads, we actively block these annoying types of ads!

Please add Pastebin.com to your ad blocker whitelist or disable your adblocking software.

×