View Single Post
  #1  
Old 03-21-2010, 08:30 AM
cbk1994 cbk1994 is offline
the fake one
cbk1994's Avatar
Join Date: Mar 2003
Location: San Francisco
Posts: 10,718
cbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond repute
Send a message via AIM to cbk1994
Level Tiling Fixer

Many servers use tiles that are supposed to be used in a block pattern, but often are destroyed by levelers who don't pay attention to such things. This script fixes it.

It turns this:



into this:



I find it most useful on grass. It works on individual levels or GMAPs.

Note that you may have to download and reupload the levels because updateBoard2 doesn't always change the file modification time, which can result in old levels being shown for some players.

Example usage:
PHP Code:
FloodFiller.fill("my_map.gmap""water");

// or

FloodFiller.fillMultiple("mylevel.nw", {"water""road""grass"}); 
PHP Code:
// DBNPC FloodFiller
function onCreated() {
  
// pattern to fill; lay it out in rows
  
this.pattern.grass.pattern = {
                                {
102410251026102710281029},
                                {
104010411042104310441045},
                                {
105610571058105910601061},
                                {
107210731074107510761077},
                                {
108810891090109110921093},
                                {
110411051106110711081109}
                              };
  
  
// tiles to fill even if not in pattern
  //   (for filling blank levels with grass, etc)
  
this.pattern.grass.exceptions = {0};
  
  
  
  
// pattern to fill; lay it out in rows
  
this.pattern.water.pattern = {
                                 {
6465},
                                 {
8081}
                               };
  
  
// tiles to fill even if not in pattern
  //   (for filling blank levels with grass, etc)
  
this.pattern.water.exceptions = {};
}

public function 
floodMultiple(levelNamepatternNames) {
  for (
temp.patternName patternNames) {
    
flood(levelNamepatternName);
    
sleep(0.1);
  }
}

public function 
flood(levelNamepatternName) {
  
temp.floodLevel findLevel(levelName);
  
  if (
floodLevel == null) {
    return echo(
"Level Flood: Level '" levelName "' not found!");
  }
  
  
temp.pattern this.pattern.(@ patternName).pattern;
  
temp.exceptions this.pattern.(@ patternName).exceptions;
  
  if (
pattern == null) {
    return echo(
"Level Flood: Pattern '" patternName "' has no defined pattern!");
  }
  
  
this.maxlooplimit 100000// 100,000
  
sleep(0.1); // make the max loop limit take effect
  
  
this.loopCount 0;
  
  
temp.possibleTiles exceptions;
  
  for (
temp.row pattern) {
    for (
temp.tile row) {
      
possibleTiles.add(tile);
      
this.nextLoop();
    }
    
    
this.nextLoop();
  }
  
  for (
temp.0floodLevel.width++) {
    for (
temp.0floodLevel.height++) {
      for (
temp.layer floodLevel.tilelayers) {
        
temp.tile layer.tiles[xy];
        
        if (
tile in possibleTiles) {
          
// replace tile
          
          
temp.row pattern[row.size()];
          
layer.tiles[xy] = row[row.size()];
        }
        
        
this.nextLoop();
      }
      
      
this.nextLoop();
    }
    
    
this.nextLoop();
  }
  
  
floodLevel.updateBoard2(00floodLevel.widthfloodLevel.height);
  
  echo(
"Level Flood: Successfully applied pattern '" patternName "' to level '" floodLevel.name "'!");
}

// increase number of loops; do I need to wait?
function nextLoop() {
  
this.loopCount ++;
  
  if (
this.loopCount >= this.maxlooplimit 1) {
    
this.loopCount 0;
    echo(
"Level Flood: Working...");
    
sleep(0.1);
  }

It should work fine with layers (it checks each layer individually for tiles that need to be replaced), but I haven't tested it.

It might be a good idea to back the levels up first since I haven't tested this in some situations.
__________________
Reply With Quote