查看: 14222|回复: 10

[搬运汉化] RandomMapGenerator-随机地图生成

[复制链接]
梦石
0
星屑
2382
在线时间
1018 小时
注册时间
2012-4-30
回帖
1461

开拓者

发表于 2017-6-17 13:11:23 | 显示全部楼层 |阅读模式

加入我们,或者,欢迎回来。

您需要 登录 才可以下载或查看,没有账号?注册会员

×
本帖最后由 铅笔描绘的思念 于 2017-6-17 14:20 编辑

本来昨天在研究roguelike地图的生成算法
但晚上找到了一个插件能实现随机生成地图。。生成的是房间加通道的地牢类型
简单翻译了一些分享给大家
其实还有些调整的空间可以给插件设置参数的。。但原作者貌似没有想到那些参数不设置会很怪(其实那些最好是根据地图大小来设置)
本体
  1. //=============================================================================
  2. // SAN_MapGenerator.js
  3. //=============================================================================
  4. // Copyright (c) 2015 Sanshiro
  5. // Released under the MIT license
  6. // [url]http://opensource.org/licenses/mit-license.php[/url]
  7. //=============================================================================

  8. /*:
  9. * @plugindesc SAN_MapGenerator ver1.00a
  10. * Generate map and allocate events automatically.
  11. * @author Sanshiro [url]https://twitter.com/rev2nym[/url]
  12. *
  13. * @help
  14. * When the plugin command is called, the map is generated
  15. * and the player moves to position of start(entrance) event.
  16. *
  17. * Set following tiles and events in a position on the base map.
  18. *
  19. * -Tiles
  20. *   space :{x:0, y:0}
  21. *   room  :{x:0, y:1}
  22. *   pass  :{x:0, y:2}
  23. *   roof  :{x:0, y:3}
  24. *   wall  :{x:0, y:4}
  25. *   rubble:{x:0, y:5}
  26. *
  27. * -Events
  28. *   start:{x:1, y:0}
  29. *   goal :{x:1, y:1}
  30. *   other:other position than above
  31. *
  32. * Appearance rate can be set as events besides the start and the goal.
  33. * Set as the following on a memo space of events.
  34. * The event which has no setting of the appearance rate isn't generated.
  35. *
  36. * -Appearance rate
  37. *   each map :<RateMap: [Positive small number of less than 1.0]>
  38. *   each room:<RateRoom:[Positive small number of less than 1.0]>
  39. *
  40. * -Plugin Command
  41. *   MapGenerator RoomAndPass # Generate map consists of rooms and passes.
  42. *   MapGenerator FillRoom    # Generate map consists of a room whole the map.
  43. *   
  44. * There is no plugin parameter.
  45. *
  46. *
  47. * It's possible to commercial use, distribute, and modify under the MIT license.
  48. * But, don't eliminate and don't alter a comment of the beginning.
  49. * If it's good, please indicate an author name on credit.
  50. *
  51. * Author doesn't shoulder any responsibility in all kind of damage by using this.
  52. * And please don't expect support. X(
  53. */

  54. /*:ja
  55. * @plugindesc 自動マップ生成 ver1.00a
  56. * 自動的にマップを生成しイベントを配置します。
  57. * @author サンシロ [url]https://twitter.com/rev2nym[/url]
  58. * @version 1.00a 2015/12/19 ヘルプ文書のイベントメモ欄設定の誤りを修正
  59. * 1.00 2015/11/29 公開
  60. *
  61. * @help
  62. * プラグインコマンドを実行するとマップが生成され
  63. * プレイヤーが入口イベントの地点に移動します。
  64. *
  65. * ベースとなるマップの座標に下記のタイルとイベントをそれぞれ配置して下さい。
  66. * ・タイル
  67. *  空白:{x:0, y:0}
  68. *  部屋:{x:0, y:1}
  69. *  通路:{x:0, y:2}
  70. *  天井:{x:0, y:3}
  71. *  壁 :{x:0, y:4}
  72. *  瓦礫:{x:0, y:5}
  73. *
  74. * ・イベント
  75. *  入口:{x:1, y:0}
  76. *  出口:{x:1, y:1}
  77. *  他 :上記以外の座標
  78. *
  79. * 入口と出口以外のイベントには出現率を設定できます。
  80. * イベントのメモ欄に下記を記載して下さい。
  81. * 出現率設定がないイベント生成されません。
  82. *
  83. * ・イベント出現率
  84. *  マップ毎の出現率:<RateMap: [1.0以下の正の小数]>
  85. *  部屋毎の出現率 :<RateRoom:[1.0以下の正の小数]>
  86. *
  87. * ・プラグインコマンド
  88. * MapGenerator RoomAndPass # 部屋と通路から構成されるマップを生成します。
  89. * MapGenerator FillRoom    # マップ全体に及ぶ一つの部屋を生成します。
  90. *
  91. * プラグインパラメータはありません。
  92. *
  93. * MITライセンスのもと、商用利用、改変、再配布が可能です。
  94. * ただし冒頭のコメントは削除や改変をしないでください。
  95. * よかったらクレジットに作者名を記載してください。
  96. *
  97. * これを利用したことによるいかなる損害にも作者は責任を負いません。
  98. * サポートは期待しないでください><。
  99. */

  100. /*:zh
  101. * @plugindesc SAN_MapGenerator ver1.00a
  102. * 自动生成地图已经分配事件
  103. * @author Sanshiro [url]https://twitter.com/rev2nym[/url]
  104. *
  105. * @help
  106. * 当使用插件指令后会生成一个自动生成的地图
  107. * 然后玩家会被移动到入口
  108. *
  109. * 把图块和事件放在地图的对应位置
  110. *
  111. * -图块
  112. *   空白  :{x:0, y:0}
  113. *   房间地面  :{x:0, y:1}
  114. *   道路  :{x:0, y:2}
  115. *   屋顶  :{x:0, y:3}
  116. *   墙   :{x:0, y:4}
  117. *   屋瓦  :{x:0, y:5}
  118. *
  119. * -事件
  120. *   开始(入口) :{x:1, y:0}
  121. *   目标(出口) :{x:1, y:1}
  122. *   其他 :之后的其他位置
  123. *
  124. * 除了开始和目标之外,可以为事件设置出现率。
  125. * 在事件的备注内设置如下。
  126. * 不会生成不具有出现率设置的事件。
  127. *
  128. * -出现几率
  129. *   每个地图 :<RateMap: [Positive small number of less than 1.0]>
  130. *   每个房间 :<RateRoom:[Positive small number of less than 1.0]>
  131. *
  132. * -插件指令
  133. *   MapGenerator RoomAndPass # 生成有道路和房间的地图(地牢)
  134. *   MapGenerator FillRoom    # 生成一个用房间设置填充满的房间
  135. *
  136. * 没有插件参数
  137. *
  138. *
  139. * 使用MIT许可协议 XP
  140. * 但是不要删除一开始的注释
  141. * 如果可以保留原作者姓名
  142. *
  143. * 作者不承担使用该脚本后的任何责任
  144. * 请不要期待支持.X(
  145. */

  146. var Imported = Imported || {};
  147. Imported.SAN_MapGenerator = true;

  148. var Sanshiro = Sanshiro || {};
  149. Sanshiro.Game_MapGenerator = Sanshiro.Game_MapGenerator || {};

  150. //-----------------------------------------------------------------------------
  151. // Game_MapGenerator
  152. //
  153. // マップジェネレーター(大部屋)

  154. function Game_MapGenerator() {
  155.     this.initialize();
  156. }

  157. // オートタイル解析タイルidリスト
  158. //   tileIdsFloor : 床
  159. //   tileIdsWall  : 壁
  160. //   candidate    : 候補タイル ID
  161. //   connect      : 接続タイル ID
  162. //   noConnect    : 非接続タイル ID
  163. Game_MapGenerator.tileIdsFloor = {};

  164. Game_MapGenerator.tileIdsFloor.candidate =
  165.     [ 0,  1,  2,  3,  4,  5,  6,  7,  8,  9, 10, 11,
  166.      12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23,
  167.      24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35,
  168.      36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47];

  169. Game_MapGenerator.tileIdsFloor.connect = {
  170.     1:[ 0,  1,  2,  3,  4,  5,  6,  7, 16, 17, 18, 19,
  171.        20, 21, 24, 26, 28, 29, 30, 31, 32, 33, 34, 35,
  172.        36, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47],         // 1:左下
  173.     2:[ 0,  1,  2,  3,  4,  5,  6,  7,  8,  9, 10, 11,
  174.        12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23,
  175.        24, 25, 26, 27, 32, 34, 35, 36, 37, 42, 47],         // 2:下
  176.     3:[ 0,  1,  2,  3,  8,  9, 10, 11, 16, 17, 20, 22,
  177.        24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 36,
  178.        37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47],         // 3:右下
  179.      4:[ 0,  1,  2,  3,  4,  5,  6,  7,  8,  9, 10, 11,
  180.         12, 13, 14, 15, 20, 21, 22, 23, 24, 25, 26, 27,
  181.         28, 29, 30, 31, 33, 36, 37, 38, 39, 45, 47],         // 4:左
  182.     6:[ 0,  1,  2,  3,  4,  5,  6,  7,  8,  9, 10, 11,
  183.        12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23,
  184.        28, 29, 30, 31, 33, 34, 35, 40, 41, 43, 47],         // 6:右
  185.     7:[ 0,  2,  4,  6,  8, 10, 12, 14, 16, 17, 18, 19,
  186.        20, 21, 22, 23, 24, 25, 28, 30, 32, 33, 34, 35,
  187.        36, 37, 38, 40, 41, 42, 43, 44, 45, 46, 47],         // 7:左上
  188.     8:[ 0,  1,  2,  3,  4,  5,  6,  7,  8,  9, 10, 11,
  189.        12, 13, 14, 15, 16, 17, 18, 19, 24, 25, 26, 27,
  190.        28, 29, 30, 31, 32, 38, 39, 40, 41, 44, 47],         // 8:上
  191.     9:[ 0,  1,  4,  5,  8,  9, 12, 13, 16, 18, 20, 21,
  192.        22, 23, 24, 25, 26, 27, 28, 29, 32, 33, 34, 35,
  193.        36, 37, 38, 39, 40, 42, 43, 44, 45, 46, 47]          // 9:右上
  194. };

  195. Game_MapGenerator.tileIdsFloor.noConnect = {
  196.     1:[ 8,  9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19,
  197.        22, 23, 25, 27, 28, 29, 30, 31, 32, 33, 34, 35,
  198.        37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47],         // 1:左下
  199.     2:[28, 29, 30, 31, 33, 38, 39, 40, 41, 43, 44, 45, 46], // 2:下
  200.     3:[ 4,  5,  6,  7, 12, 13, 14, 15, 18, 19, 21, 23,
  201.        24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 35, 36,
  202.        37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47],         // 3:右下
  203.     4:[16, 17, 18, 19, 32, 34, 35, 40, 41, 42, 43, 44, 46], // 4:左
  204.     6:[24, 25, 26, 27, 32, 36, 37, 38, 39, 42, 44, 45, 46], // 6:右
  205.     7:[ 1,  3,  5,  7,  9, 11, 13, 15, 16, 17, 18, 19,
  206.        20, 21, 22, 23, 26, 27, 29, 31, 32, 33, 34, 35,
  207.        36, 37, 39, 40, 41, 42, 43, 44, 45, 46, 47],         // 7:左上
  208.     8:[20, 21, 22, 23, 33, 34, 35, 36, 37, 42, 43, 45, 46], // 8:上
  209.     9:[ 2,  3,  6,  7, 10, 11, 14, 15, 17, 19, 20, 21,
  210.        22, 23, 24, 25, 26, 27, 30, 31, 32, 33, 34, 35,
  211.        36, 37, 38, 39, 41, 42, 43, 44, 45, 46, 47]          // 9:右上
  212. };

  213. Game_MapGenerator.tileIdsWall = {};

  214. Game_MapGenerator.tileIdsWall.candidate =
  215.     [ 0,  1,  2,  3,  4,  5,  6,  7,
  216.       8,  9, 10, 11, 12, 13, 14, 15];

  217. Game_MapGenerator.tileIdsWall.connect = {
  218.     2:[ 0,  1,  2,  3,  4,  5,  6,  7],  // 2:下
  219.     4:[ 0,  2,  4,  6,  8, 10, 12, 14],  // 4:左
  220.     6:[ 0,  1,  2,  3,  8,  9, 10, 11],  // 6:右
  221.     8:[ 0,  1,  4,  5,  8,  9, 12, 13]   // 8:上
  222. };

  223. Game_MapGenerator.tileIdsWall.noConnect = {
  224.     2:[ 8,  9, 10, 11, 12, 13, 14, 15],  // 2:下
  225.     4:[ 1,  3,  5,  7,  9, 11, 13, 15],  // 4:左
  226.     6:[ 4,  5,  6,  7, 12, 13, 14, 15],  // 6:右
  227.     8:[ 2,  3,  6,  7, 10, 11, 14, 15]   // 8:上
  228. };

  229. // 初期化
  230. Game_MapGenerator.prototype.initialize = function() {
  231.     this._wallHeight = 2;
  232.     this._startXY = {x:0, y:0};
  233.     this._goalXY  = {x:0, y:0};
  234.     this._blocks  = [];
  235.     this._rooms   = [];
  236.     this._passes  = [];
  237.     this._data    = [];
  238.     this._isReady = false;
  239. };

  240. // マップ生成
  241. Game_MapGenerator.prototype.setup = function() {
  242.     $gameMap._events = [];
  243.     for (key in $gameSelfSwitches._data) {
  244.         if (key.split(",")[0] === String($gameMap.mapId())) {
  245.             delete $gameSelfSwitches._data[key];
  246.         }
  247.     }
  248.     this._isReady = false;
  249.     this._blocks  = [];
  250.     this._rooms   = [];
  251.     this._passes  = [];
  252.     this._startXY = {x:0, y:0};
  253.     this._goalXY  = {x:0, y:0};
  254.     this._data    = [];
  255.     this.initSymbolTable();
  256.     this.initSymbolMap();
  257.     this.generateMap();
  258.     this.refreshWallAndRoof();
  259.     this.makeData();
  260.     this.setStart();
  261.     this.setGoal();
  262.     this.setRateEvents();
  263.     SceneManager._scene.createDisplayObjects();
  264.     this._isReady = true;
  265. }

  266. // シンボル定義表の初期化
  267. Game_MapGenerator.prototype.initSymbolTable = function() {
  268.     // シンボル定義
  269.     //  refXY      : シンボルに対応するタイルのツクールのマップ上の座標
  270.     //  baseTileId : シンボルに対応するタイル ID
  271.     //  dispChar   : 生成したマップを文字列として表示する際の文字
  272.     this._symbolTable = {
  273.         player: {refXY:{x:0, y:0}, baseTileId:[], dispChar:'@'},
  274.         space:  {refXY:{x:0, y:0}, baseTileId:[], dispChar:' '},
  275.         room:   {refXY:{x:0, y:1}, baseTileId:[], dispChar:'□'},
  276.         pass:   {refXY:{x:0, y:2}, baseTileId:[], dispChar:'■'},
  277.         roof:   {refXY:{x:0, y:3}, baseTileId:[], dispChar:'#'},
  278.         wall:   {refXY:{x:0, y:4}, baseTileId:[], dispChar:'='},
  279.         rubble: {refXY:{x:0, y:5}, baseTileId:[], dispChar:'*'},
  280.         start:  {refXY:{x:1, y:0}, baseTileId:[], dispChar:'△'},
  281.         goal:   {refXY:{x:1, y:1}, baseTileId:[], dispChar:'▽'}//,
  282.     //  fence:  {refXY:{x:0, y:6}, baseTileId:[], dispChar:'只'},
  283.     //  pond:   {refXY:{x:0, y:7}, baseTileId:[], dispChar:'○'},
  284.     //  hole:   {refXY:{x:0, y:8}, baseTileId:[], dispChar:'●'},
  285.     //  brink:  {refXY:{x:0, y:9}, baseTileId:[], dispChar:'^'},
  286.     //  enemy:  {refXY:{x:1, y:2}, baseTileId:[], dispChar:'$'},
  287.     //  crawler:{refXY:{x:0, y:1}, baseTileId:[], dispChar:'&'}
  288.     };
  289.     for (symbol in this._symbolTable) {
  290.         var x = this._symbolTable[symbol].refXY.x;
  291.         var y = this._symbolTable[symbol].refXY.y;
  292.         for (var z = 0; z < 6; z ++) {
  293.             // z0:タイルA下層, z1:タイルA上層, z2:タイルB下層, z3:タイルB上層, z4:影, z5:リージョン
  294.             this._symbolTable[symbol].baseTileId[z] = this.baseAutoTileId(x, y, z);
  295.         }
  296.     }
  297. };

  298. // オートタイルタイルの基点タイルID
  299. Game_MapGenerator.prototype.baseAutoTileId = function(x, y, z) {
  300.     if ($gameMap.tileId(x, y, z) >= Tilemap.TILE_ID_A1) {
  301.         return (Math.floor(($gameMap.tileId(x, y, z) - Tilemap.TILE_ID_A1) / 48)) * 48 + Tilemap.TILE_ID_A1;
  302.     } else {
  303.         return $gameMap.tileId(x, y, z);
  304.     }
  305. };

  306. // シンボルで表現されるマップの初期化(初期化時はスペースで埋める)
  307. Game_MapGenerator.prototype.initSymbolMap = function() {
  308.     this._symbolMap = new Array($gameMap.width());
  309.     for (var x = 0; x < $gameMap.width(); x++) {
  310.         this._symbolMap[x] = new Array($gameMap.height());
  311.         for (var y = 0; y < $gameMap.height(); y++) {
  312.             this._symbolMap[x][y] = 'space';
  313.         }
  314.     }
  315. };

  316. // シンボルによる通行可能判定(通行可否定義)
  317. Game_MapGenerator.prototype.isPassable = function(x, y) {
  318.     if (!this._symbolMap[x] || !this._symbolMap[x][y]) {
  319.         return false;
  320.     }
  321.     return ['room', 'pass', 'start', 'goal', 'crawler'].indexOf(this._symbolMap[x][y]) !== -1;
  322. };

  323. // マップ上における通行可能タイルの割合
  324. Game_MapGenerator.prototype.passableRatio = function() {
  325.     var passableCount = 0;
  326.     for(var x = 0; x < $gameMap.width(); x++) {
  327.         for(var y = 0; y < $gameMap.height(); y++) {
  328.             if (this.isPassable(x, y)) {
  329.                 passableCount++;
  330.             }
  331.         }
  332.     }
  333.     return passableCount / ($gameMap.width() * $gameMap.height());
  334. };

  335. // シンボルマップ生成
  336. Game_MapGenerator.prototype.generateMap = function() {
  337.     var room = {x:0, y:0, w:0, h:0};
  338.     room.x = 1;
  339.     room.y = 1 + this._wallHeight;
  340.     room.w = $dataMap.width - 4;
  341.     room.h = $dataMap.height - (this._wallHeight + 1) * 4;
  342.     for (var oX = 0; oX < room.w; oX++) {
  343.         for (var oY = 0; oY < room.h; oY++) {
  344.             this._symbolMap[oX + room.x][oY + room.y] = 'room';
  345.         }
  346.     }
  347.     this._rooms.push(room);
  348. }

  349. // イベントの設置
  350. Game_MapGenerator.prototype.setEvent = function(event, targetSymbols, targetArea) {
  351.     targetSymbols = targetSymbols || ['room'];
  352.     targetArea = targetArea || {x:0, y:0, w:$dataMap.width, h:$dataMap.height};
  353.     var canSet = false;
  354.     for (var x = targetArea.x; x < targetArea.x + targetArea.w && !canSet; x++) {
  355.         for (var y = targetArea.y; y < targetArea.y + targetArea.h && !canSet; y ++) {
  356.             canSet = (targetSymbols.indexOf(this._symbolMap[x][y]) !== -1);
  357.         }
  358.     }
  359.     if (canSet) {
  360.         for (var i = 0; i < Math.pow(targetArea.w * targetArea.h, 2); i++) {
  361.             var x = targetArea.x + Math.randomInt(targetArea.w);
  362.             var y = targetArea.y + Math.randomInt(targetArea.h);
  363.             if ($gameMap.eventsXy(x, y).length === 0 &&
  364.                 targetSymbols.indexOf(this._symbolMap[x][y]) !== -1)
  365.             {
  366.                 break;
  367.             }
  368.         }
  369.         $gameMap._events.push(event);
  370.         event._eventId = $gameMap._events.indexOf(event);
  371.         event.setPosition(x, y);
  372.         return {x:x, y:y}
  373.     } else {
  374.         return undefined;
  375.     }
  376. };

  377. // 座標によるイベントデータの配列
  378. Game_MapGenerator.prototype.dataMapEventsXy = function(x, y) {
  379.     return $dataMap.events.filter(function(event) {
  380.         return (!!event && event.x === x && event.y === y);
  381.     }, this);
  382. };

  383. // スタート地点イベントの設置
  384. Game_MapGenerator.prototype.setStart = function() {
  385.     var refXY = this._symbolTable['start'].refXY;
  386.     var event = new Game_Event($gameMap.mapId(), this.dataMapEventsXy(refXY.x, refXY.y)[0].id);
  387.     this._startXY = this.setEvent(event);
  388.     $gamePlayer.locate(this._startXY.x, this._startXY.y);
  389.     $gamePlayer.reserveTransfer($gameMap.mapId(), this._startXY.x, this._startXY.y);
  390.     $gameMap._interpreter.setWaitMode('transfer')
  391. };

  392. // ゴール地点イベントの設置
  393. Game_MapGenerator.prototype.setGoal = function() {
  394.     var refXY = this._symbolTable['goal'].refXY;
  395.     var event = new Game_Event($gameMap.mapId(), this.dataMapEventsXy(refXY.x, refXY.y)[0].id);
  396.     this._goalXY = this.setEvent(event);
  397. };

  398. // 確率イベントの設置
  399. Game_MapGenerator.prototype.setRateEvents = function() {
  400.     var mapDataRateMapEvents = $dataMap.events.filter(function(event) {
  401.         return !!event && !!event.meta.RateMap;
  402.     });
  403.     mapDataRateMapEvents.forEach(function(mapDataEvent) {
  404.         if (this.randBool(parseFloat(mapDataEvent.meta.RateMap))) {
  405.             var event = new Game_Event($gameMap.mapId(), mapDataEvent.id);
  406.             this.setEvent(event);
  407.         }
  408.     }, this);
  409.     var mapDataRateRoomEvents = $dataMap.events.filter(function(event) {
  410.         return !!event && !!event.meta.RateRoom;
  411.     });
  412.     mapDataRateRoomEvents.forEach(function(mapDataEvent) {
  413.         this._rooms.forEach(function(room) {
  414.             if (this.randBool(parseFloat(mapDataEvent.meta.RateRoom))) {
  415.                 var event = new Game_Event($gameMap.mapId(), mapDataEvent.id);
  416.                 this.setEvent(event, 'room', room);
  417.             }
  418.         }, this);
  419.     }, this);
  420. };

  421. //ランダムブール
  422. //probability : true が返る確立
  423. Game_MapGenerator.prototype.randBool = function(probability) {
  424.     return Math.random() < probability;
  425. };

  426. // シンボルマップの壁と天井を設置:マップ全体
  427. // 床と通路だけのシンボルマップに壁と天井を追加する
  428. Game_MapGenerator.prototype.refreshWallAndRoof = function() {
  429.     for (var x = 0; x < this._symbolMap.length; x++) {
  430.         for (var y = 0; y < this._symbolMap[x].length; y++) {
  431.             if (!this.isPassable(x, y)) {
  432.                 continue;
  433.             }
  434.             this.refreshWallAndRoofUpperSide(x - 1, y - 1);  // 左上
  435.             this.refreshWallAndRoofUpper(x, y - 1);          // 上
  436.             this.refreshWallAndRoofUpperSide(x + 1, y - 1);  // 右上
  437.             this.refreshWallAndRoofSide(x - 1, y);           // 左
  438.             this.refreshWallAndRoofSide(x + 1, y);           // 右
  439.             this.refreshWallAndRoofDowner(x - 1, y + 1);     // 左下
  440.             this.refreshWallAndRoofDowner(x, y + 1);         // 下
  441.             this.refreshWallAndRoofDowner(x + 1, y + 1);     // 右下
  442.         }
  443.     }
  444.     for (var x = this._symbolMap.length - 1; x >= this._symbolMap.length; x--) {
  445.         for (var y = this._symbolMap[x].length - 1; y >= this._symbolMap[x].length; y--) {
  446.             if (this._symbolMap[x][y] === 'roof' && this._symbolMap[x][y - 1] === 'wall') {
  447.                 this._symbolMap[x][y - 1] = 'roof';
  448.             }
  449.         }
  450.     }
  451. };

  452. // シンボルマップの壁と天井を設置:上
  453. Game_MapGenerator.prototype.refreshWallAndRoofUpper = function(x, y) {
  454.     if (!this._symbolMap[x] || !this._symbolMap[x][y] || this.isPassable(x, y)) {
  455.         return;
  456.     }
  457.     for (var h = 0; h < y && !this.isPassable(x, y - h); h++);
  458.     if (h > this._wallHeight) {
  459.         for (var wH = 0; wH < this._wallHeight; wH++) {
  460.             this._symbolMap[x][y - wH] = 'wall';
  461.         }
  462.         this._symbolMap[x][y - this._wallHeight] = 'roof';
  463.     } else {
  464.         for (var wH = 0; wH < h; wH++) {
  465.             if (this._symbolMap[x][y - wH] === 'space') {
  466.                 this._symbolMap[x][y - wH] = 'rubble';
  467.             }
  468.         }
  469.     }
  470. };

  471. // シンボルマップの壁と天井を設置:下
  472. Game_MapGenerator.prototype.refreshWallAndRoofDowner = function(x, y) {
  473.     if (!this._symbolMap[x] || !this._symbolMap[x][y] || this.isPassable(x, y)) {
  474.         return;
  475.     }
  476.     for (var h = 0; h + y < $gameMap.height() && !this.isPassable(x, y + h); h++);
  477.     if (h > this._wallHeight) {
  478.         this._symbolMap[x][y] = 'roof';
  479.         for (var wH = 0; wH < this._wallHeight; wH++) {
  480.             if (this._symbolMap[x][y + wH + 1] !== 'roof') {
  481.                 this._symbolMap[x][y + wH + 1] = 'wall';
  482.             }
  483.         }
  484.     } else {
  485.         for (var wH = 0; wH < h; wH++) {
  486.             if (this._symbolMap[x][y + wH] === 'space') {
  487.                 this._symbolMap[x][y + wH] = 'rubble';
  488.             }
  489.         }
  490.     }
  491. };

  492. //シンボルマップの壁と天井を設置:横
  493. Game_MapGenerator.prototype.refreshWallAndRoofSide = function(x, y) {
  494.     if (!this._symbolMap[x] || !this._symbolMap[x][y] || this.isPassable(x, y)) {
  495.         return;
  496.     }
  497.     if (this.isPassable(x, y + 1)) {
  498.         this.refreshWallAndRoofUpper(x, y);
  499.     } else {
  500.         this.refreshWallAndRoofDowner(x, y);
  501.     }
  502. };

  503. // シンボルマップの壁と天井を設置:斜め上
  504. Game_MapGenerator.prototype.refreshWallAndRoofUpperSide = function(x, y) {
  505.     if (!this._symbolMap[x] || !this._symbolMap[x][y] || this.isPassable(x, y)) {
  506.         return;
  507.     }
  508.     this.refreshWallAndRoofDowner(x, y - this._wallHeight);
  509. };

  510. // オートタイルを考慮したタイルID
  511. Game_MapGenerator.prototype.autoTileId = function(x, y, z) {
  512.     if ((x < 0 || x >= $dataMap.width) || (y < 0 || y >= $dataMap.height)) {
  513.         return 0;
  514.     } else if (z === 4) {
  515.         return this.shadow(x, y);
  516.     } else if ((z !== 0 && z !== 1) || this._symbolTable[this._symbolMap[x][y]].baseTileId[z] === 0) {
  517.         return this._symbolTable[this._symbolMap[x][y]].baseTileId[z];
  518.     }
  519.     var candidateTileIds = [];
  520.     if (this._symbolMap[x][y] !== 'wall') {
  521.         // 壁以外の場合
  522.         candidateTileIds = Game_MapGenerator.tileIdsFloor.candidate.concat();
  523.         [1, 2, 3, 4, 6, 7, 8, 9].forEach (function(direction) {
  524.             var dx = x + Math.floor((direction - 1) % 3) - 1;
  525.             var dy = y - Math.floor((direction - 1) / 3) + 1;
  526.             if ((dx < 0 || dx >= $dataMap.width) || (dy < 0 || dy >= $dataMap.height)) {
  527.                 return; // マップ範囲外なら判定しない
  528.             }
  529.             if (this._symbolMap[x][y] === this._symbolMap[dx][dy]) {
  530.                 candidateTileIds = candidateTileIds.filter(function(Id) {
  531.                     return Game_MapGenerator.tileIdsFloor.connect[direction].indexOf(Id) !== -1;
  532.                 }); // 同種シンボルの場合候補タイルIDから接続タイルIDを選択
  533.             } else {
  534.                 candidateTileIds = candidateTileIds.filter(function(Id) {
  535.                     return Game_MapGenerator.tileIdsFloor.noConnect[direction].indexOf(Id) !== -1;
  536.                 }); // 異種シンボルの場合候補タイルIDから非接続タイルIDを選択
  537.             }
  538.         }, this);
  539.     } else {
  540.         // 壁の場合
  541.         candidateTileIds = Game_MapGenerator.tileIdsWall.candidate.concat();
  542.         for (var by = y; this._symbolMap[x][y] === this._symbolMap[x][by + 1]; by++);  // 壁の下端
  543.         for (var ty = y; this._symbolMap[x][y] === this._symbolMap[x][ty - 1]; ty--);  // 壁の上端
  544.         // 上下の処理
  545.         [2, 8].forEach(function(direction) {
  546.             var dx = x + Math.floor((direction - 1) % 3) - 1;
  547.             var dy = y - Math.floor((direction - 1) / 3) + 1;
  548.             if ((dx < 0 || dx >= $dataMap.width) || (dy < 0 || dy >= $dataMap.height)) {
  549.                 return; // マップ範囲外なら判定しない
  550.             }
  551.             if (this._symbolMap[x][y] === this._symbolMap[dx][dy]) {
  552.                 candidateTileIds = candidateTileIds.filter(function(Id) {
  553.                     return Game_MapGenerator.tileIdsWall.connect[direction].indexOf(Id) !== -1;
  554.                 }); // 同種シンボルの場合候補タイルIDから接続タイルIDを選択
  555.             } else {
  556.                 candidateTileIds = candidateTileIds.filter(function(Id) {
  557.                     return Game_MapGenerator.tileIdsWall.noConnect[direction].indexOf(Id) !== -1;
  558.                 }); // 異種シンボルの場合候補タイルIDから非接続タイルIDを選択
  559.             }
  560.         }, this);
  561.         // 左右の処理
  562.         [4, 6].forEach(function(direction) {
  563.             var dx = x + Math.floor((direction - 1) % 3) - 1;
  564.             var dy = y - Math.floor((direction - 1) / 3) + 1;
  565.             if ((dx < 0 || dx >= $dataMap.width) || (dy < 0 || dy >= $dataMap.height)) {
  566.                 return; // マップ範囲外なら判定しない
  567.             }
  568.             if ((this._symbolMap[dx][ty] === 'wall' || this._symbolMap[dx][ty] === 'roof') &&
  569.                 (this._symbolMap[dx][by] === 'wall' || this._symbolMap[dx][by] === 'roof'))
  570.             {
  571.                 candidateTileIds = candidateTileIds.filter(function(Id) {
  572.                     return Game_MapGenerator.tileIdsWall.connect[direction].indexOf(Id) !== -1;
  573.                 }); // 壁の下端の両横隣が壁または天井でかつ上端の両横隣が壁または天井でなければ接続タイルIDを選択
  574.             } else {
  575.                 candidateTileIds = candidateTileIds.filter(function(Id) {
  576.                     return Game_MapGenerator.tileIdsWall.noConnect[direction].indexOf(Id) !== -1;
  577.                 }); // 非接続タイルIDを選択
  578.             }
  579.         }, this);
  580.     }
  581.     return this._symbolTable[this._symbolMap[x][y]].baseTileId[z] + candidateTileIds[0];
  582. };

  583. // 影の算出
  584. Game_MapGenerator.prototype.shadow = function(x, y) {
  585.     if (!this._symbolMap[x - 1] ||
  586.         this._symbolMap[x][y] === 'space'||
  587.         this._symbolMap[x][y] === 'roof' ||
  588.         this._symbolMap[x][y] === 'wall')
  589.     {
  590.         return 0;
  591.     } else if (this._symbolMap[x - 1][y] === 'roof') {
  592.         if (this._symbolMap[x - 1][y - 1] === 'roof' ||
  593.             this._symbolMap[x - 1][y - 1] === 'wall')
  594.         {
  595.             return 5;
  596.         }
  597.     }  else if (this._symbolMap[x - 1][y] === 'wall') {
  598.         return 5;
  599.     }
  600.     return 0;
  601. };

  602. //マップデータ作成
  603. Game_MapGenerator.prototype.makeData = function() {
  604.     var width = $dataMap.width;
  605.     var height = $dataMap.height;
  606.     for (var x = 0; x < this._symbolMap.length; x++) {
  607.         for (var y = 0; y < this._symbolMap[x].length; y++) {
  608.             for (var z = 0; z < 6; z++) {
  609.                 this._data[(z * height + y) * width + x] = this.autoTileId(x, y, z);
  610.             }
  611.         }
  612.     }
  613. };

  614. // マップデータ
  615. Game_MapGenerator.prototype.data = function() {
  616.     return this._data;
  617. };

  618. // タイルID
  619. Game_MapGenerator.prototype.tileId = function(x, y, z) {
  620.     return this._data[(z * $dataMap.height + y) * $dataMap.width + x];
  621. };

  622. // 準備完了判定
  623. Game_MapGenerator.prototype.isReady = function() {
  624.     return this._isReady;
  625. };

  626. // マップのコンソール表示(デバッグ用)
  627. Game_MapGenerator.prototype.printMap = function() {
  628.     var dispMap = "";
  629.     for (var y = 0; y < this._symbolMap[0].length; y++) {
  630.         for (var x = 0; x < this._symbolMap.length; x++) {
  631.             dispMap += this._symbolTable[this._symbolMap[x][y]].dispChar;
  632.         }
  633.         dispMap += "\r\n";
  634.     }
  635.     console.log(dispMap);
  636.     // this.fPrintMap(dispMap);
  637. };

  638. // テキスト出力(デバッグ用)
  639. Game_MapGenerator.prototype.fPrintMap = function(mapString) {
  640.     var data = LZString.compressToBase64(mapString);
  641.     var fs = require('fs');
  642.     var dirPath = StorageManager.localFileDirectoryPath();
  643.     var filePath = StorageManager.localFileDirectoryPath() + 'mapData.txt';
  644.     if (!fs.existsSync(dirPath)) {
  645.         fs.mkdirSync(dirPath);
  646.     }
  647.     fs.writeFileSync(filePath, mapString);
  648. };

  649. //-----------------------------------------------------------------------------
  650. // Game_MapGeneratorRoomAndPass
  651. //
  652. // マップジェネレーター(部屋と通路)

  653. function Game_MapGeneratorRoomAndPass() {
  654.     this.initialize.apply(this, arguments);
  655. }

  656. Game_MapGeneratorRoomAndPass.prototype = Object.create(Game_MapGenerator.prototype);
  657. Game_MapGeneratorRoomAndPass.prototype.constructor = Game_MapGeneratorRoomAndPass;

  658. // 初期化
  659. Game_MapGeneratorRoomAndPass.prototype.initialize = function() {
  660.     Game_MapGenerator.prototype.initialize.call(this);
  661. };

  662. // マップ(ダンジョン)自動生成
  663. Game_MapGeneratorRoomAndPass.prototype.generateMap = function() {
  664.     this._minRoomSize = 4;
  665.     this._minBlockSize = this._minRoomSize;
  666.     this._minRooms = 2;
  667.     this._maxRooms = 25;
  668.     this._adjacentBlockIndexList = [];
  669.     var block = {
  670.         x:1,
  671.         y:1 + this._wallHeight,
  672.         w:$dataMap.width - 2,
  673.         h:$dataMap.height - (this._wallHeight + 1) * 2
  674.     };
  675.     this._blocks.push(block);
  676.     this.splitBlock(this._blocks[0]);
  677.     this.makeAdjacentBlockIndexList();
  678.     this.makeRooms();
  679.     this.makePasses();
  680. };

  681. // 隣り合うブロックのリスト作成
  682. Game_MapGeneratorRoomAndPass.prototype.makeAdjacentBlockIndexList = function() {
  683.     for (var crntIndex = 0; crntIndex < this._blocks.length; crntIndex++) {
  684.         var crntBlock = this._blocks[crntIndex];
  685.         this._adjacentBlockIndexList[crntIndex] = {t:[], b:[], l:[], r:[]};
  686.         for (var tgetIndex = 0; tgetIndex < this._blocks.length; tgetIndex++) {
  687.             var tgetBlock = this._blocks[tgetIndex];
  688.             if (crntBlock === tgetBlock) {
  689.                 continue;
  690.             }
  691.             var adjacentT = (crntBlock.y === tgetBlock.y + tgetBlock.h + 1);
  692.             var adjacentB = (tgetBlock.y === crntBlock.y + crntBlock.h + 1);
  693.             var adjacentL = (crntBlock.x === tgetBlock.x + tgetBlock.w + 1);
  694.             var adjacentR = (tgetBlock.x === crntBlock.x + crntBlock.w + 1);
  695.             if (!adjacentT && !adjacentB && !adjacentL && !adjacentR) {
  696.                 continue;
  697.             }
  698.             var matchH =
  699.                 (tgetBlock.x <= crntBlock.x + crntBlock.w && tgetBlock.x >= crntBlock.x) ||
  700.                 (tgetBlock.x + tgetBlock.w <= crntBlock.x + crntBlock.w && tgetBlock.x + tgetBlock.w >= crntBlock.x) ||
  701.                 (crntBlock.x <= tgetBlock.x + tgetBlock.w && crntBlock.x >= tgetBlock.x) ||
  702.                 (crntBlock.x + crntBlock.w <= tgetBlock.x + tgetBlock.w && crntBlock.x + crntBlock.w >= tgetBlock.x);
  703.             var matchV =
  704.                 (tgetBlock.y <= crntBlock.y + crntBlock.h && tgetBlock.y >= crntBlock.y) ||
  705.                 (tgetBlock.y + tgetBlock.h <= crntBlock.y + crntBlock.h && tgetBlock.y + tgetBlock.h >= crntBlock.y) ||
  706.                 (crntBlock.y <= tgetBlock.y + tgetBlock.h && crntBlock.y >= tgetBlock.y) ||
  707.                 (crntBlock.y + crntBlock.h <= tgetBlock.y + tgetBlock.h && crntBlock.y + crntBlock.h >= tgetBlock.y);
  708.             if (adjacentT && matchH) {
  709.                 this._adjacentBlockIndexList[crntIndex].t.push(tgetIndex);
  710.                 continue;
  711.             } else if (adjacentB && matchH) {
  712.                 this._adjacentBlockIndexList[crntIndex].b.push(tgetIndex);
  713.                 continue;
  714.             }
  715.             if (adjacentL && matchV) {
  716.                 this._adjacentBlockIndexList[crntIndex].l.push(tgetIndex);
  717.                 continue;
  718.             } else if (adjacentR && matchV) {
  719.                 this._adjacentBlockIndexList[crntIndex].r.push(tgetIndex);
  720.                 continue;
  721.             }
  722.         }
  723.     }
  724. };

  725. // 部屋作成
  726. Game_MapGeneratorRoomAndPass.prototype.makeRooms = function() {
  727.     this._blocks.forEach(function(block) {
  728.         var roomW = this._minRoomSize + Math.randomInt(block.w - this._minRoomSize - 2);
  729.         var roomH = this._minRoomSize + Math.randomInt(block.h - this._minRoomSize - 2);
  730.         var roomX = block.x + 1 + Math.randomInt(block.w - roomW - 2);     
  731.         var roomY = block.y + 1 + Math.randomInt(block.h - roomH - 2);     
  732.         var room = {x:roomX, y:roomY, w:roomW, h:roomH};
  733.         this._rooms.push(room);
  734.     }, this);
  735.     this._rooms.forEach(function(room) {
  736.         for (var y = 0; y < room.h; y++) {
  737.             for (var x = 0 ; x < room.w; x++) {
  738.                 this._symbolMap[room.x + x][room.y + y] = 'room';
  739.             }
  740.         }
  741.     }, this);
  742. };

  743. // 通路作成
  744. Game_MapGeneratorRoomAndPass.prototype.makePasses = function() {
  745.     var cache = {};
  746.     for (var crntIndex = 0; crntIndex < this._adjacentBlockIndexList.length; crntIndex++ ) {
  747.         cache[crntIndex] = [];
  748.         var crngBlock = this._blocks[crntIndex];
  749.         for(var direction in this._adjacentBlockIndexList[crntIndex]) {
  750.             var tgetIndexList = this._adjacentBlockIndexList[crntIndex][direction];
  751.             tgetIndexList.forEach(function(tgetIndex) {
  752.                 if (cache[tgetIndex] !== undefined && cache[tgetIndex].indexOf(crntIndex) !== -1)
  753.                 {
  754.                     return;
  755.                 }
  756.                 cache[crntIndex].push(tgetIndex);
  757.                 var tgetBlock = this._blocks[tgetIndex];
  758.                 var crntRoom = this._rooms[crntIndex];
  759.                 var tgetRoom = this._rooms[tgetIndex];
  760.                 var crntPass = {};
  761.                 var tgetPass = {};
  762.                 var bordPass = {};
  763.                 switch (direction) {
  764.                 case 't':
  765.                     crntPass.x = crntRoom.x + 1 + Math.randomInt(crntRoom.w - 2);
  766.                     crntPass.y = crngBlock.y;
  767.                     crntPass.w = 1;
  768.                     crntPass.h = crntRoom.y - crngBlock.y;
  769.                     tgetPass.x = tgetRoom.x + 1 + Math.randomInt(tgetRoom.w - 2);
  770.                     tgetPass.y = tgetRoom.y + tgetRoom.h;
  771.                     tgetPass.w = 1;
  772.                     tgetPass.h = crngBlock.y - tgetPass.y;
  773.                     bordPass.x = Math.min(crntPass.x, tgetPass.x);
  774.                     bordPass.y = crngBlock.y - 1;
  775.                     bordPass.w = Math.max(crntPass.x, tgetPass.x) - bordPass.x + 1;
  776.                     bordPass.h = 1;
  777.                     break;
  778.                 case 'b':
  779.                     crntPass.x = crntRoom.x + 1 + Math.randomInt(crntRoom.w - 2);
  780.                     crntPass.y = crntRoom.y + crntRoom.h;
  781.                     crntPass.w = 1;
  782.                     crntPass.h = tgetBlock.y - crntPass.y;
  783.                     tgetPass.x = tgetRoom.x + 1 + Math.randomInt(tgetRoom.w - 2);
  784.                     tgetPass.y = tgetBlock.y;
  785.                     tgetPass.w = 1;
  786.                     tgetPass.h = tgetRoom.y - tgetBlock.y;
  787.                     bordPass.x = Math.min(crntPass.x, tgetPass.x);
  788.                     bordPass.y = tgetBlock.y - 1;
  789.                     bordPass.w = Math.max(crntPass.x, tgetPass.x) - bordPass.x + 1;
  790.                     bordPass.h = 1;
  791.                     break;
  792.                 case 'l':
  793.                     crntPass.x = crngBlock.x - 1;
  794.                     crntPass.y = crntRoom.y + 1 + Math.randomInt(crntRoom.h - 2);
  795.                     crntPass.w = crntRoom.x - crntPass.x;
  796.                     crntPass.h = 1;
  797.                     tgetPass.x = tgetRoom.x + tgetRoom.w;
  798.                     tgetPass.y = tgetRoom.y + 1 + Math.randomInt(tgetRoom.h - 2);
  799.                     tgetPass.w = crntPass.x - tgetRoom.x - tgetRoom.w;
  800.                     tgetPass.h = 1;
  801.                     bordPass.x = crngBlock.x - 1;
  802.                     bordPass.y = Math.min(crntPass.y, tgetPass.y);
  803.                     bordPass.w = 1;
  804.                     bordPass.h = Math.max(crntPass.y, tgetPass.y) - bordPass.y + 1;
  805.                     break;
  806.                 case 'r':
  807.                     crntPass.x = crntRoom.x + crntRoom.w
  808.                     crntPass.w = tgetBlock.x - 1 - crntRoom.x - crntRoom.w
  809.                     crntPass.y = crntRoom.y + 1 + Math.randomInt(crntRoom.h - 2);
  810.                     crntPass.h = 1;
  811.                     tgetPass.x = tgetBlock.x - 1;
  812.                     tgetPass.y = tgetRoom.y + 1 + Math.randomInt(tgetRoom.h - 2);
  813.                     tgetPass.w = tgetRoom.x - tgetPass.x;
  814.                     tgetPass.h = 1;
  815.                     bordPass.x = tgetBlock.x - 1;
  816.                     bordPass.y = Math.min(crntPass.y, tgetPass.y);
  817.                     bordPass.w = 1;
  818.                     bordPass.h = Math.max(crntPass.y, tgetPass.y) - bordPass.y + 1;
  819.                     break;
  820.                 }
  821.                 this._passes.push(crntPass);
  822.                 this._passes.push(tgetPass);
  823.                 this._passes.push(bordPass);
  824.             }, this);
  825.         }
  826.     }
  827.     this._passes.forEach(function(pass) {
  828.         for (var y = 0; y < pass.h; y++) {
  829.             for (var x = 0; x < pass.w; x++) {
  830.                 this._symbolMap[pass.x + x][pass.y + y] = 'pass';
  831.             }
  832.         }
  833.     }, this);
  834. };

  835. // ブロック分割:ランダム
  836. Game_MapGeneratorRoomAndPass.prototype.splitBlock = function(block) {
  837.     if (this.randBool(0.5)) {
  838.         if (this.isSplitableH(block)) {
  839.             this.splitBlockH(block);
  840.         }
  841.         if (this.isSplitableV(block)) {
  842.             this.splitBlockV(block);
  843.         }
  844.     } else {
  845.         if (this.isSplitableV(block)) {
  846.             this.splitBlockV(block);
  847.         }
  848.         if (this.isSplitableH(block)) {
  849.             this.splitBlockH(block);
  850.         }
  851.     }
  852. };

  853. //ブロック分割:横分割
  854. Game_MapGeneratorRoomAndPass.prototype.splitBlockH = function(block) {
  855.     var width1 = 0;
  856.     var width2 = 0;
  857.     while (width1 < this._minBlockSize || width2 < this._minBlockSize) {
  858.         width1 = Math.floor(block.w / 4 + block.w * Math.random() / 2);
  859.         width2 = block.w - width1 - 1;
  860.     }
  861.     block.w = width1;
  862.     var newBlock = {x:block.x + width1 + 1, y:block.y, w:width2, h:block.h};
  863.     this._blocks.push(newBlock);
  864.     this.splitBlock(block);
  865.     this.splitBlock(newBlock);
  866. };

  867. // ブロック分割:縦分割
  868. Game_MapGeneratorRoomAndPass.prototype.splitBlockV = function(block) {
  869.     var height1 = 0;
  870.     var height2 = 0;
  871.     while (height1 < this._minBlockSize || height2 < this._minBlockSize) {
  872.         height1 = Math.floor(block.h / 4 + block.h * Math.random() / 2);
  873.         height2 = block.h - height1 - 1;
  874.     }
  875.     block.h = height1;
  876.     var newBlock = {x:block.x, y:block.y + height1 + 1, w:block.w, h:height2};
  877.     this._blocks.push(newBlock);
  878.     this.splitBlock(block);
  879.     this.splitBlock(newBlock);
  880. };

  881. // ブロック分割可能判定:部屋数
  882. Game_MapGeneratorRoomAndPass.prototype.isSplitableByRoomNum = function() {
  883.     if (this._blocks.length >= this._maxRooms) {
  884.         return false;
  885.     }
  886.     if (this._blocks.length >= this._minRooms &&
  887.         this.randBool((this._blocks.length - this._minRooms + 1) / (this._maxRooms - this.minRooms + 1)))
  888.     {
  889.         return false;
  890.     }
  891.     return true;
  892. };

  893. // ブロック分割可能判定:横分割
  894. Game_MapGeneratorRoomAndPass.prototype.isSplitableV = function(block) {
  895.     return (block.h > (this._minRoomSize + 2) * 2 + 1) && this.isSplitableByRoomNum();
  896. };

  897. // ブロック分割可能判定:縦分割
  898. Game_MapGeneratorRoomAndPass.prototype.isSplitableH = function(block) {
  899.     return (block.w > (this._minRoomSize + 2) * 2 + 1) && this.isSplitableByRoomNum();
  900. };

  901. // 座標によって部屋を取得
  902. Game_MapGeneratorRoomAndPass.prototype.roomByXY = function(x, y) {
  903.     this._rooms.forEach(function(room) {
  904.         if (room.x <= x && x <= room.x + room.w && room.y <= y && y <= room.y + room.h) {
  905.             return result = room;
  906.         }
  907.     }, this);
  908.     return undefined;
  909. };

  910. //-----------------------------------------------------------------------------
  911. // Game_Map
  912. //
  913. // マップクラス

  914. // マップクラスの初期化
  915. Sanshiro.Game_MapGenerator.Game_Map_initialize = Game_Map.prototype.initialize;
  916. Game_Map.prototype.initialize = function() {
  917.     Sanshiro.Game_MapGenerator.Game_Map_initialize.call(this);
  918. };

  919. // マップクラスのセットアップ
  920. Sanshiro.Game_MapGenerator.Game_Map_setup = Game_Map.prototype.setup;
  921. Game_Map.prototype.setup = function(mapId) {
  922.     Sanshiro.Game_MapGenerator.Game_Map_setup.call(this, mapId)
  923.     this._mapGenerator = null;
  924. };

  925. // マップクラスのタイルID
  926. Sanshiro.Game_MapGenerator.Game_Map_tileId = Game_Map.prototype.tileId
  927. Game_Map.prototype.tileId = function(x, y, z) {
  928.     if (!!this._mapGenerator && this._mapGenerator.isReady()) {
  929.         return this._mapGenerator.tileId(x, y, z);
  930.     } else {
  931.         return Sanshiro.Game_MapGenerator.Game_Map_tileId.call(this, x, y, z);
  932.     }
  933. };

  934. // マップクラスのマップデータ
  935. Sanshiro.Game_MapGenerator.Game_Map_data = Game_Map.prototype.data
  936. Game_Map.prototype.data = function() {
  937.     if (!!this._mapGenerator && this._mapGenerator.isReady()) {
  938.         return this._mapGenerator.data();
  939.     } else {
  940.         return Sanshiro.Game_MapGenerator.Game_Map_data.call(this);
  941.     }
  942. };

  943. // マップクラスのマップ自動生成
  944. Game_Map.prototype.generateMap = function(mapType) {
  945.     mapType = mapType || 'FillRoom';
  946.     switch (mapType) {
  947.     case 'RoomAndPass':
  948.         this._mapGenerator = new Game_MapGeneratorRoomAndPass();
  949.         break;
  950.     case 'FillRoom':
  951.         this._mapGenerator = new Game_MapGenerator();
  952.         break;
  953.     }
  954.     this._mapGenerator.setup();
  955.     if (Imported.SAN_AnalogMove) {
  956.         Game_CollideMap.setup();
  957.     }
  958. };

  959. //-----------------------------------------------------------------------------
  960. // Game_Event
  961. //
  962. // イベントクラス

  963. // イベントクラスの初期化
  964. Sanshiro.Game_MapGenerator.Game_Event_initialize = Game_Event.prototype.initialize;
  965. Game_Event.prototype.initialize = function(mapId, eventId) {
  966.     this._dataEventId = eventId;
  967.     Sanshiro.Game_MapGenerator.Game_Event_initialize.call(this, mapId, eventId);
  968. };

  969. // イベントクラスのデータベースのイベントデータ
  970. Game_Event.prototype.event = function() {
  971.     return $dataMap.events[this._dataEventId];
  972. };

  973. //-----------------------------------------------------------------------------
  974. // Game_Interpreter
  975. //
  976. // インタープリタークラス

  977. // プラグインコマンド
  978. Sanshiro.Game_MapGenerator.Game_Interpreter_pluginCommand = Game_Interpreter.prototype.pluginCommand;
  979. Game_Interpreter.prototype.pluginCommand = function(command, args) {
  980.     Sanshiro.Game_MapGenerator.Game_Interpreter_pluginCommand.call(this, command, args);
  981.     if (command === 'MapGenerator') {
  982.         $gameMap.generateMap(args[0]);
  983.     }
  984. };
复制代码


一个我修改过后生成的效果
GenerateBaseMap1-3.png 因为最多房间数和最小房间数都是固定设置。所以就很拥挤但小了就很空。。这就是应该用地图长宽来设置的原因

SANMapGenerator.zip (317.64 KB, 下载次数: 767)


其实这个生成的算法还是有点差强人意的= =b 房间和道路的链接实在是怪。。

评分

参与人数 2星屑 +200 收起 理由
king + 80 迷宫最佳,加点事件机关即可
garfeng + 120 塞糖

查看全部评分

梦石
2
星屑
5550
在线时间
2566 小时
注册时间
2012-2-9
回帖
947

开拓者

发表于 2017-6-17 14:32:32 | 显示全部楼层
支持,自己再修饰一下就可以了。用来偷懒简直太棒
回复

使用道具 举报

梦石
0
星屑
50
在线时间
12 小时
注册时间
2016-11-5
回帖
4
发表于 2017-7-10 14:41:31 | 显示全部楼层
这个不错的 自己在按照意愿修改下就行了
回复

使用道具 举报

梦石
0
星屑
3930
在线时间
1198 小时
注册时间
2016-8-9
回帖
2355

开拓者

发表于 2017-7-10 17:51:45 | 显示全部楼层
弱弱的问一下这个插件和软件自带的地图生成器的区别,谢谢大大

点评

楼主那个生成出来可能会比默认的复杂一些吧  发表于 2017-7-19 15:10
我用了,真感觉不出有什么区别,都是地下城,都是光秃秃的路和墙,你知道区别,请大神不吝赐教!  发表于 2017-7-17 23:42
系统自带的自己用用就能知道区别了= =  发表于 2017-7-15 20:23
酸酸甜甜就④哇噢
回复

使用道具 举报

梦石
0
星屑
25555
在线时间
1137 小时
注册时间
2019-3-5
回帖
1303
发表于 2019-12-1 21:25:04 | 显示全部楼层
用的压缩包里的文件,测试后发现生成会出现没有设定的图块。而且遇到一些地方无法左右移动的情况,不知道问题出在哪里。
回复

使用道具 举报

梦石
0
星屑
1285
在线时间
121 小时
注册时间
2019-11-16
回帖
121
发表于 2019-12-3 10:44:48 | 显示全部楼层
多谢分享
回复

使用道具 举报

梦石
0
星屑
2184
在线时间
124 小时
注册时间
2019-8-12
回帖
25
发表于 2020-5-9 20:24:36 | 显示全部楼层
白嫩白嫩的 发表于 2017-7-10 17:51
弱弱的问一下这个插件和软件自带的地图生成器的区别,谢谢大大

系统自带的不是在游戏内随机生成的呀,这个插件主要是可以实现在游戏内的随机生成吧。虽然你用系统自带的做多个模板也是OK的,但是这个插件确实能省不少时间,而且还可以设置事件的随机生成,可以做简单的随机地下迷宫……

点评

感谢大神三年后解惑233333  发表于 2020-5-10 21:16

评分

参与人数 1赞 +1 收起 理由
白嫩白嫩的 + 1 666666

查看全部评分

回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册会员

本版积分规则

Powered by Discuz! X5.0 © 2001-2026 Discuz! Team.

在本版发帖返回顶部