```
// breadth-first search for movement
Game_CharacterBase.prototype.makeMoveTable = function (x, y, move, unused, tag) {
var edges = [];
if (move > 0) edges = [[x, y, move, [0]]];
$gameTemp.setMoveTable(x, y, move, [0]);
$gameTemp.pushMoveList([x, y, false]);
$gameMap.makeSrpgZoCTable(this.isType() == 'actor' ? 'enemy' : 'actor', this.throughZoC());
while (edges.length > 0) {
var cell = edges.shift();
for (var d = 2; d < 10; d += 2) {
if (!this.srpgMoveCanPass(cell[0], cell[1], d, tag)) continue;
var dx = $gameMap.roundXWithDirection(cell[0], d);
var dy = $gameMap.roundYWithDirection(cell[1], d);
//Shoukang edit - Terrain passability (original function is if there is movement available, all squares can be moved to regardless of terrain move cost
//This edit means movement must equal terrain move cost for a square to be a valid movement option
var movecost = 1;
if (tag < $gameMap.terrainTag(dx, dy)) {
movecost = _terrainCost[$gameMap.terrainTag(dx, dy)];
//Add notetag to modify terrainCost by states - Boomy Edit
$gameSystem.EventToUnit($gameTemp.activeEvent().eventId())[1].states().forEach(function (item) { //check all states
if (item.meta["SRPGTerrainCost" + $gameMap.terrainTag(dx, dy)]) {
movecost = Number(item.meta["SRPGTerrainCost" + $gameMap.terrainTag(dx, dy)]);
}
});
//Add notetag to modify terrainCost by Class - Boomy Edit
if ($gameSystem.EventToUnit($gameTemp.activeEvent().eventId())[1].isActor()) {
if ($gameSystem.EventToUnit($gameTemp.activeEvent().eventId())[1].currentClass().meta["SRPGTerrainCost" + $gameMap.terrainTag(dx, dy)]) {
movecost = Number($gameSystem.EventToUnit($gameTemp.activeEvent().eventId())[1].currentClass().meta["SRPGTerrainCost" + $gameMap.terrainTag(dx, dy)]);
}
}
}
// if ($gameTemp.MoveTable(dx, dy)[0] >= 0) continue;
if ($gameTemp.MoveTable(dx, dy)[0] >= 0 || (cell[2] - movecost < 0)) continue;
var dmove = Math.max(cell[2] - $gameMap.srpgMoveCost(dx, dy), 0);
var route = cell[3].concat(d);
$gameTemp.setMoveTable(dx, dy, dmove, route);
$gameTemp.pushMoveList([dx, dy, false]);
if (dmove > 0 && !$gameMap._zocTable[dx + ',' + dy]) {
edges.push([dx, dy, dmove, route]);
edges.sort(function (a, b) {
return b[2] - a[2];
});
}
}
}
}
// get the cost of moving through a given space
Game_Map.prototype.srpgMoveCost = function (x, y) {
var terrain = this.terrainTag(x, y);
var stateTerrainCost = -1;
// state tags - Boomy Edit
$gameSystem.EventToUnit($gameTemp.activeEvent().eventId())[1].states().forEach(function (item) { //check all states
if (item.meta["SRPGTerrainCost" + $gameMap.terrainTag(x, y)]) {
stateTerrainCost = Number(item.meta["SRPGTerrainCost" + $gameMap.terrainTag(x, y)]);
}
});
// class tags - Boomy Edit
if ($gameSystem.EventToUnit($gameTemp.activeEvent().eventId())[1].isActor()) {
if ($gameSystem.EventToUnit($gameTemp.activeEvent().eventId())[1].currentClass().meta["SRPGTerrainCost" + $gameMap.terrainTag(x, y)]) {
stateTerrainCost = Number($gameSystem.EventToUnit($gameTemp.activeEvent().eventId())[1].currentClass().meta["SRPGTerrainCost" + $gameMap.terrainTag(x, y)]);
}
}
if (stateTerrainCost > 0) {
return stateTerrainCost;
}
// map tags
if ($dataMap.meta["srpgTerrain" + terrain + "Cost"]) {
return Number($dataMap.meta["srpgTerrain" + terrain + "Cost"] || 1);
}
// tileset tags
if (this.tileset().meta["srpgTerrain" + terrain + "Cost"]) {
return Number(this.tileset().meta["srpgTerrain" + terrain + "Cost"] || 1);
}
// plugin parameters
return _terrainCost[terrain];
};
```