Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //=============================================================================
- // Terrain Tags
- // by Shaz
- // Last Updated: 2015.12.04
- //-----------------------------------------------------------------------------
- // This plugin is still under development
- //=============================================================================
- /*:
- * @plugindesc Uses terrain tags to change map behaviour
- * @author Shaz
- *
- * @param Passability Number
- * @desc Terrain tag to indicate "use passability from tile below"
- * @default -1
- *
- * @param Counter Number
- * @desc Terrain tag to indicate "behave like counter (allow interaction)"
- * @default -1
- *
- * @param Offset Numbers
- * @desc Terrain tag to indicate tile should be drawn higher (separate by ;)
- * @default -1
- *
- * @param Offset Pixels
- * @desc Height adjustment for Offset (one per offset number, separate by ;)
- * @default
- *
- * @param Under Shadow Number
- * @descr Draws the tile below the auto shadow
- * @default -1
- *
- * @help This plugin does not provide plugin commands.
- *
- * Set the terrain tag on the parameters you want to use to the relevant
- * terrain tag, then flag tiles with that terrain tag as necessary. Any
- * parameters left as -1 indicate those parts of the plugin will not be
- * active.
- *
- * Passability Number
- * ------------------
- * This terrain tag allows you to ignore the passage settings on that tile
- * and to look at the tile below it. For example, a cliff with a small flower
- * right on the upper edge, with the flower having a O passage setting, would
- * allow the player to walk off the upper edge of the cliff. With this
- * parameter, the game ignores the O passage setting on the flower and looks
- * at the setting on the cliff tile below it.
- *
- * Counter Number
- * --------------
- * This terrain tag allows you to assign a tile to act like a counter tile,
- * without looking like a counter tile. Normally, autotiles flagged as counters
- * are drawn so that they extend over the tile below, which looks okay for
- * tables, but not for other things, like fences or narrow streams. With this
- * parameter, the player can interact with NPC events with a tile between them.
- *
- * Offset Numbers and Pixels
- * -------------------------
- * This terrain tag and the paired pixel count allow you to move those tiles up
- * by the specified number of pixels, so they aren't drawn snapped to the grid.
- * If used, there must be the same number of entries in the terrain tags list
- * and the pixels list, separated by a semi-colon (;). An example of usage is
- * to move pictures higher up on a wall so they are not aligned to either the
- * bottom half or the top half, without needing to rearrange the tileset images.
- *
- * Under Shadow Number
- * -------------------
- * This terrain tag, used on B-E tiles, indicates that those tiles are to be
- * drawn BELOW any autoshadow if one exists. If two B-E tiles are drawn on the
- * same spot, make sure one with this terrain tag is drawn first.
- *
- *
- *
- */
- (function() {
- var parameters = PluginManager.parameters('TerrainTags');
- var passageTerrain = Number(parameters['Passability Number'] || -1);
- var counterTerrain = Number(parameters['Counter Number'] || -1);
- var offsetTerrain = String(parameters['Offset Numbers'] || -1).split(';').map(function(id) {
- return Number(id);
- });
- var offsetPixels = String(parameters['Offset Pixels'] || 0).split(';').map(function(id) {
- return Number(id);
- });
- var mapOffsets = {};
- offsetTerrain.forEach(function(id, index) {
- if (id !== -1) {
- mapOffsets[id] = offsetPixels[index];
- }
- }.bind(this));
- var underShadowTerrain = Number(parameters['Under Shadow Number'] || -1);
- var _Game_Map_checkPassage = Game_Map.prototype.checkPassage;
- Game_Map.prototype.checkPassage = function(x, y, bit) {
- if (passageTerrain === -1) {
- return _Game_Map_checkPassage.call(this, x, y, bit);
- } else {
- var flags = this.tilesetFlags();
- var tiles = this.allTiles(x, y);
- for (var i = 0; i < tiles.length; i++) {
- var flag = flags[tiles[i]];
- if ((flag & 0x10) !== 0) // [*] No effect on passage
- continue;
- if (flag >> 12 === passageTerrain) // Take passage from tile below
- continue;
- if ((flag & bit) === 0) // [o] Passable
- return true;
- if ((flag & bit) === bit) // [x] Impassable
- return false;
- }
- return false;
- }
- };
- var _Game_Map_isCounter = Game_Map.prototype.isCounter;
- Game_Map.prototype.isCounter = function(x, y) {
- if (counterTerrain === -1) {
- return _Game_Map_isCounter.call(this, x, y);
- } else {
- return _Game_Map_isCounter.call(this, x, y) || this.terrainTag(x, y) === counterTerrain;
- }
- };
- var _Tilemap_drawNormalTile = Tilemap.prototype._drawNormalTile;
- Tilemap.prototype._drawNormalTile = function(bitmap, tileId, dx, dy) {
- dy -= mapOffsets[$gameMap.tilesetFlags()[tileId] >> 12] || 0;
- _Tilemap_drawNormalTile.call(this, bitmap, tileId, dx, dy);
- };
- Tilemap.prototype._paintTiles = function(startX, startY, x, y) {
- var tableEdgeVirtualId = 10000;
- var mx = startX + x;
- var my = startY + y;
- var dx = (mx * this._tileWidth).mod(this._layerWidth);
- var dy = (my * this._tileHeight).mod(this._layerHeight);
- var lx = dx / this._tileWidth;
- var ly = dy / this._tileHeight;
- var tileId0 = this._readMapData(mx, my, 0);
- var tileId1 = this._readMapData(mx, my, 1);
- var tileId2 = this._readMapData(mx, my, 2);
- var tileId3 = this._readMapData(mx, my, 3);
- var shadowBits = this._readMapData(mx, my, 4);
- var upperTileId1 = this._readMapData(mx, my - 1, 1);
- var lowerTiles = [];
- var upperTiles = [];
- var flags = $gameMap.tilesetFlags();
- if (this._isHigherTile(tileId0)) {
- upperTiles.push(tileId0);
- } else {
- lowerTiles.push(tileId0);
- }
- if (this._isHigherTile(tileId1)) {
- upperTiles.push(tileId1);
- } else {
- lowerTiles.push(tileId1);
- }
- var shadowDrawn = false;
- if (underShadowTerrain === -1) {
- lowerTiles.push(-shadowBits);
- shadowDrawn = true;
- }
- if (this._isTableTile(upperTileId1) && !this._isTableTile(tileId1)) {
- if (!Tilemap.isShadowingTile(tileId0)) {
- if (underShadowTerrain !== -1 && !shadowDrawn && flags[upperTileId1] >> 12 !== underShadowTerrain) {
- lowerTiles.push(-shadowBits);
- shadowDrawn = true;
- }
- lowerTiles.push(tableEdgeVirtualId + upperTileId1);
- }
- }
- if (this._isOverpassPosition(mx, my)) {
- upperTiles.push(tileId2);
- upperTiles.push(tileId3);
- } else {
- if (this._isHigherTile(tileId2)) {
- upperTiles.push(tileId2);
- } else {
- if (underShadowTerrain !== -1 && !shadowDrawn && flags[tileId2] >> 12 !== underShadowTerrain) {
- lowerTiles.push(-shadowBits);
- shadowDrawn = true;
- }
- lowerTiles.push(tileId2);
- }
- if (this._isHigherTile(tileId3)) {
- upperTiles.push(tileId3);
- } else {
- if (underShadowTerrain !== -1 && !shadowDrawn && flags[tileId3] >> 12 !== underShadowTerrain) {
- lowerTiles.push(-shadowBits);
- shadowDrawn = true;
- }
- lowerTiles.push(tileId3);
- }
- }
- if (!shadowDrawn) {
- lowerTiles.push(-shadowBits);
- }
- var count = 1000 + this.animationCount - my;
- var frameUpdated = (count % 30 === 0);
- this._animationFrame = Math.floor(count / 30);
- var lastLowerTiles = this._readLastTiles(0, lx, ly);
- if (!lowerTiles.equals(lastLowerTiles) ||
- (Tilemap.isTileA1(tileId0) && frameUpdated)) {
- this._lowerBitmap.clearRect(dx, dy, this._tileWidth, this._tileHeight);
- for (var i = 0; i < lowerTiles.length; i++) {
- var lowerTileId = lowerTiles[i];
- if (lowerTileId < 0) {
- this._drawShadow(this._lowerBitmap, shadowBits, dx, dy);
- } else if (lowerTileId >= tableEdgeVirtualId) {
- this._drawTableEdge(this._lowerBitmap, upperTileId1, dx, dy);
- } else {
- this._drawTile(this._lowerBitmap, lowerTileId, dx, dy);
- }
- }
- this._writeLastTiles(0, lx, ly, lowerTiles);
- }
- var lastUpperTiles = this._readLastTiles(1, lx, ly);
- if (!upperTiles.equals(lastUpperTiles)) {
- this._upperBitmap.clearRect(dx, dy, this._tileWidth, this._tileHeight);
- for (var j = 0; j < upperTiles.length; j++) {
- this._drawTile(this._upperBitmap, upperTiles[j], dx, dy);
- }
- this._writeLastTiles(1, lx, ly, upperTiles);
- }
- };
- })();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement