From 4037cdf86bd7ad2f17017b88083a055cbbabe2cc Mon Sep 17 00:00:00 2001 From: "Timothy.Stiles" Date: Wed, 3 Mar 2021 13:04:55 +1100 Subject: [PATCH 1/6] don't crash in _draw_standard if p < 0 (fixes #58) --- js/tileset.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/js/tileset.js b/js/tileset.js index a152967..a7baeba 100644 --- a/js/tileset.js +++ b/js/tileset.js @@ -1185,6 +1185,10 @@ export class Tileset { // Lexy runs cooldown from S to 1; CC2 from S-1 to 0. 0 is bad, because p becomes 1 // and will overflow the cel lookup // FIXME handle this better! it happens even to lexy + // this new one happened because of turntable attempt_step, not sure why yet + if (p < 0) { + p = 0; + } if (p >= 1) { p = 0.999; } From 7c357820794fcc39b80e99ca6085209942b75cd1 Mon Sep 17 00:00:00 2001 From: "Timothy.Stiles" Date: Wed, 3 Mar 2021 13:25:46 +1100 Subject: [PATCH 2/6] fix glass blocks vs mines and pseudo-items (fixes #63, 59) --- js/tileset.js | 2 +- js/tiletypes.js | 34 ++++++++-------------------------- 2 files changed, 9 insertions(+), 27 deletions(-) diff --git a/js/tileset.js b/js/tileset.js index a7baeba..1f54b4e 100644 --- a/js/tileset.js +++ b/js/tileset.js @@ -1603,7 +1603,7 @@ export class Tileset { _draw_encased_item(drawspec, name, tile, packet) { //draw the encased item if (tile !== null && tile.encased_item !== undefined && tile.encased_item !== null) { - this._draw_standard(this.layout[tile.encased_item], tile.encased_item, TILE_TYPES[tile.encased_item], packet); + this._draw_standard(this.layout[tile.encased_item], tile.encased_item, null, packet); } //then draw the glass block this._draw_standard(drawspec.base, name, tile, packet); diff --git a/js/tiletypes.js b/js/tiletypes.js index 112d474..cc1195b 100644 --- a/js/tiletypes.js +++ b/js/tiletypes.js @@ -1324,29 +1324,18 @@ const TILE_TYPES = { can_reverse_on_railroad: true, movement_speed: 4, try_pickup_item(me, level) { + //suck up any item that ever CAN be picked up off of the floor (except hearts!) and put it in our encased_item slot (not an inventory since e.g. a glass block with red key can't unlock red doors) if (me.encased_item === null) { let item = me.cell.get_item(); - if (item && !item.type.is_chip) { - level.attempt_take(me, item); - //then if we picked it up, encase it (so we have max one item at a time and so we can't 'use' the item) - if (me.keyring !== undefined && me.keyring !== null && Object.keys(me.keyring).length > 0) { - level._set_tile_prop(me, 'encased_item', Object.keys(me.keyring)[0]); - level.take_all_keys_from_actor(me); - } - else if (me.toolbelt !== undefined && me.toolbelt !== null && me.toolbelt.length > 0) - { - level._set_tile_prop(me, 'encased_item', me.toolbelt[0]); - level.take_all_tools_from_actor(me); - } + let mod = me.cell.get_item_mod(); + if (mod && mod.type.item_modifier === 'ignore') { + return; + } + if (item && !item.type.is_chip && item.type.item_priority !== undefined) { + level._set_tile_prop(me, 'encased_item', item.type.name); + level.remove_tile(item); } } - /*if ((me.keyring === undefined || Object.keys(me.keyring).length == 0) && - (me.toolbelt === undefined || me.toolbelt.length == 0)) { - let item = me.cell.get_item(); - if (item) { - level.attempt_take(me, item); - } - }*/ }, on_ready(me, level) { level._set_tile_prop(me, 'encased_item', null); @@ -1354,13 +1343,6 @@ const TILE_TYPES = { }, on_clone(me, original) { me.encased_item = original.encased_item; - /*if (original.keyring !== undefined) { - me.keyring = {}; - Object.assign(me.keyring, original.keyring); - } - if (original.toolbelt !== undefined) { - me.toolbelt = original.toolbelt.map((x) => x); - }*/ }, on_finishing_move(me, level) { this.try_pickup_item(me, level); From 094e94a69ce34a0053924b13b2c955627c41c316 Mon Sep 17 00:00:00 2001 From: "Timothy.Stiles" Date: Wed, 3 Mar 2021 13:33:13 +1100 Subject: [PATCH 3/6] for fun, let glass blocks pick up chips; let's see what happens? --- js/tiletypes.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/js/tiletypes.js b/js/tiletypes.js index cc1195b..7f45312 100644 --- a/js/tiletypes.js +++ b/js/tiletypes.js @@ -1324,14 +1324,15 @@ const TILE_TYPES = { can_reverse_on_railroad: true, movement_speed: 4, try_pickup_item(me, level) { - //suck up any item that ever CAN be picked up off of the floor (except hearts!) and put it in our encased_item slot (not an inventory since e.g. a glass block with red key can't unlock red doors) + //suck up any item that ever CAN be picked up off of the floor and put it in our encased_item slot (not an inventory since e.g. a glass block with red key can't unlock red doors) if (me.encased_item === null) { let item = me.cell.get_item(); let mod = me.cell.get_item_mod(); if (mod && mod.type.item_modifier === 'ignore') { return; } - if (item && !item.type.is_chip && item.type.item_priority !== undefined) { + //hmm, actually chips seem to work OK. Alright, why not then? + if (item /*&& !item.type.is_chip*/ && item.type.item_priority !== undefined) { level._set_tile_prop(me, 'encased_item', item.type.name); level.remove_tile(item); } From ee718323cdfd20b8bb628992b1efe758e6f6f729 Mon Sep 17 00:00:00 2001 From: "Timothy.Stiles" Date: Wed, 3 Mar 2021 13:51:25 +1100 Subject: [PATCH 4/6] glass block blown up by dynamite/halo drops its item (fixes #62) --- js/game.js | 3 +++ js/tiletypes.js | 7 ++++++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/js/game.js b/js/game.js index c4f9d08..7dccba2 100644 --- a/js/game.js +++ b/js/game.js @@ -2441,6 +2441,9 @@ export class Level extends LevelInterface { { if (killer.type.is_actor || killer.type.is_item) { + if (killer.type.on_death) { + killer.type.on_death(killer, this); + } this.remove_tile(killer); } else //presumably terrain diff --git a/js/tiletypes.js b/js/tiletypes.js index 7f45312..71eb047 100644 --- a/js/tiletypes.js +++ b/js/tiletypes.js @@ -1351,7 +1351,7 @@ const TILE_TYPES = { on_death(me, level) { //needs to be called by transmute_tile to ttl and by lit_dynamite before remove_tile if (me.encased_item !== null) { - level._place_dropped_item(me.encased_item, me.cell, me); + level._place_dropped_item(me.encased_item, me.cell ?? me.previous_cell, me); level._set_tile_prop(me, 'encased_item', null); } } @@ -2638,6 +2638,7 @@ const TILE_TYPES = { let actor = cell.get_actor(); let terrain = cell.get_terrain(); + let item = cell.get_item(); let removed_anything; for (let layer = LAYERS.MAX - 1; layer >= 0; layer--) { let tile = cell[layer]; @@ -2653,6 +2654,10 @@ const TILE_TYPES = { level.fail(me.type.name, me, tile); } else { + //newly appearing items (e.g. dropped by a glass block) are safe + if (tile.type.layer === LAYERS.item && tile !== item) { + continue; + } // Everything else is destroyed if (tile.type.on_death) { tile.type.on_death(tile, level); From 6971eb4d54a91d6d0e0df4d7b1357993918d75e7 Mon Sep 17 00:00:00 2001 From: "Timothy.Stiles" Date: Wed, 3 Mar 2021 14:10:44 +1100 Subject: [PATCH 5/6] dynamite vs electrified floor, holes and cracked floor (60 partial fix) --- js/game.js | 7 ++++--- js/tiletypes.js | 28 +++++++++++++++++++++------- 2 files changed, 25 insertions(+), 10 deletions(-) diff --git a/js/game.js b/js/game.js index 7dccba2..b73af09 100644 --- a/js/game.js +++ b/js/game.js @@ -2587,9 +2587,10 @@ export class Level extends LevelInterface { this._set_tile_prop(tile, 'last_extra_cooldown_tic', null); } this._do_extra_cooldown(tile); - if (old_type.on_death) { - old_type.on_death(tile, this); - } + } + + if (old_type.on_death) { + old_type.on_death(tile, this); } } diff --git a/js/tiletypes.js b/js/tiletypes.js index 71eb047..bcdc279 100644 --- a/js/tiletypes.js +++ b/js/tiletypes.js @@ -1079,12 +1079,14 @@ const TILE_TYPES = { if (other === level.player) { level.sfx.play_once('popwall', me.cell); } - //update hole visual state - me.type.on_begin(me, level); - var one_south = level.cell(me.cell.x, me.cell.y + 1); - if (one_south !== null && one_south.get_terrain().type.name == 'hole') { - me.type.on_begin(one_south.get_terrain(), level); - } + }, + on_death(me, level) { + //update hole visual state + me.type.on_begin(me, level); + var one_south = level.cell(me.cell.x, me.cell.y + 1); + if (one_south !== null && one_south.get_terrain().type.name == 'hole') { + me.type.on_begin(one_south.get_terrain(), level); + } }, }, thief_tools: { @@ -1860,6 +1862,11 @@ const TILE_TYPES = { on_depower(me, level) { level._set_tile_prop(me, 'is_active', false); }, + on_death(me, level) { + //need to remove our wires since they're an implementation detail + level._set_tile_prop(me, 'wire_directions', 0); + level.recalculate_circuitry_next_wire_phase = true; + }, visual_state(me) { return ! me || me.is_active ? 'active' : 'inactive'; }, @@ -2687,7 +2694,14 @@ const TILE_TYPES = { } else if (terrain) { // Anything other than these babies gets blown up and turned into floor - if (!( + if (terrain.type.name === 'hole') { + //do nothing + } + else if (terrain.type.name === 'cracked_floor') { + level.transmute_tile(terrain, 'hole'); + removed_anything = true; + } + else if (!( terrain.type.name === 'steel' || terrain.type.name === 'socket' || terrain.type.name === 'logic_gate' || terrain.type.name === 'floor')) { From e4ce9d0bccb84e061cfe64fd3914733f0b7ba04a Mon Sep 17 00:00:00 2001 From: "Timothy.Stiles" Date: Wed, 3 Mar 2021 14:15:17 +1100 Subject: [PATCH 6/6] glass block-with-item can't move onto a tile with an item in it --- js/game.js | 7 +++++-- js/tiletypes.js | 3 +++ 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/js/game.js b/js/game.js index b73af09..e2a4716 100644 --- a/js/game.js +++ b/js/game.js @@ -92,8 +92,11 @@ export class Tile { other.type.name !== 'ghost') return true; - if (this.type.blocks) - return this.type.blocks(this, level, other, direction); + if (this.type.blocks && this.type.blocks(this, level, other, direction)) + return true; + + if (other.type.blocked_by && other.type.blocked_by(other, level, this)) + return true; return false; } diff --git a/js/tiletypes.js b/js/tiletypes.js index bcdc279..d2c6d61 100644 --- a/js/tiletypes.js +++ b/js/tiletypes.js @@ -1350,6 +1350,9 @@ const TILE_TYPES = { on_finishing_move(me, level) { this.try_pickup_item(me, level); }, + blocked_by(me, level, other) { + return other.cell.get_item() !== null && me.encased_item !== null; + }, on_death(me, level) { //needs to be called by transmute_tile to ttl and by lit_dynamite before remove_tile if (me.encased_item !== null) {