From 4f0ff2b34690fa4997a5bc98a3c0dce9ad0bad21 Mon Sep 17 00:00:00 2001 From: Timothy Stiles Date: Sat, 6 Feb 2021 23:08:39 +1100 Subject: [PATCH] Terraformer alt behaviour when it has an item on top When activated, if there's an item on its tile, copies the item to the tile in front of it. Otherwise, copies the item AND terrain BEHIND it to the tile in front of it. --- js/main-editor.js | 2 +- js/tiletypes.js | 24 ++++++++++++++++++------ 2 files changed, 19 insertions(+), 7 deletions(-) diff --git a/js/main-editor.js b/js/main-editor.js index 3370329..bc8a9ea 100644 --- a/js/main-editor.js +++ b/js/main-editor.js @@ -2178,7 +2178,7 @@ const EDITOR_TILE_DESCRIPTIONS = { }, terraformer_n: { name: "Terraformer", - desc: "When activated, copies the terrain and item behind it to the tile in front of it.", + desc: "When activated, if there's an item on its tile, copies the item to the tile in front of it. Otherwise, copies the item AND terrain BEHIND it to the tile in front of it.", }, global_cycler: { name: "Global Cycler", diff --git a/js/tiletypes.js b/js/tiletypes.js index ce56904..1c21b38 100644 --- a/js/tiletypes.js +++ b/js/tiletypes.js @@ -91,18 +91,30 @@ function _define_gate(key) { function activate_terraformer(me, level, dx, dy) { let did_something = false; - let old_cell = level.cell( + let item_only = false; + let old_cell = level.cell(me.cell.x, me.cell.y); + if (old_cell.get_item() != null) + { + item_only = true; + } + else + { + old_cell = level.cell( (me.cell.x - dx + level.width) % level.width, (me.cell.y - dy + level.height) % level.height); + } let new_cell = level.cell( (me.cell.x + dx + level.width) % level.width, (me.cell.y + dy + level.height) % level.height); - let old_terrain = old_cell.get_terrain(); - let new_terrain = new_cell.get_terrain(); - if (old_terrain.type.name != new_terrain.type.name) + if (!item_only) { - level.transmute_tile(new_cell.get_terrain(), old_terrain.type.name); - did_something = true; + let old_terrain = old_cell.get_terrain(); + let new_terrain = new_cell.get_terrain(); + if (old_terrain.type.name != new_terrain.type.name) + { + level.transmute_tile(new_cell.get_terrain(), old_terrain.type.name); + did_something = true; + } } let old_item = old_cell.get_item(); if (old_item != null)