Fix circuit blocks; distinguish floor wiring from black button wiring
This commit is contained in:
parent
3802b10956
commit
e1e99e73e7
@ -1,4 +1,4 @@
|
|||||||
import { DIRECTIONS, DIRECTION_ORDER } from './defs.js';
|
import { DIRECTIONS } from './defs.js';
|
||||||
|
|
||||||
export function trace_floor_circuit(level, start_cell, start_edge, on_wire, on_dead_end) {
|
export function trace_floor_circuit(level, start_cell, start_edge, on_wire, on_dead_end) {
|
||||||
let is_first = true;
|
let is_first = true;
|
||||||
@ -16,44 +16,44 @@ export function trace_floor_circuit(level, start_cell, start_edge, on_wire, on_d
|
|||||||
if (seen_edges & edgeinfo.bit)
|
if (seen_edges & edgeinfo.bit)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
|
let tile = terrain;
|
||||||
let actor = cell.get_actor();
|
let actor = cell.get_actor();
|
||||||
let wire_directions = terrain.wire_directions;
|
if (actor && actor.type.contains_wire && (
|
||||||
if ((actor?.wire_directions ?? null !== null) && (actor.movement_cooldown === 0 || level.compat.tiles_react_instantly))
|
actor.movement_cooldown === 0 || level.compat.tiles_react_instantly))
|
||||||
{
|
{
|
||||||
wire_directions = actor.wire_directions;
|
tile = actor;
|
||||||
}
|
}
|
||||||
|
|
||||||
// The wire comes in from this edge towards the center; see how it connects within this
|
// The wire comes in from this edge towards the center; see how it connects within this
|
||||||
// cell, then check for any neighbors
|
// cell, then check for any neighbors
|
||||||
let connections = edgeinfo.bit;
|
let connections = edgeinfo.bit;
|
||||||
if (! is_first && ((wire_directions ?? 0) & edgeinfo.bit) === 0) {
|
let mode = tile.wire_propagation_mode ?? tile.type.wire_propagation_mode;
|
||||||
|
if (! is_first && ((tile.wire_directions ?? 0) & edgeinfo.bit) === 0) {
|
||||||
// There's not actually a wire here (but not if this is our starting cell, in which
|
// There's not actually a wire here (but not if this is our starting cell, in which
|
||||||
// case we trust the caller)
|
// case we trust the caller)
|
||||||
if (on_dead_end) {
|
if (on_dead_end) {
|
||||||
on_dead_end(terrain.cell, edge);
|
on_dead_end(cell, edge);
|
||||||
}
|
}
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
else if (terrain.type.wire_propagation_mode === 'none') {
|
else if (mode === 'none') {
|
||||||
// The wires in this tile never connect to each other
|
// The wires in this tile never connect to each other
|
||||||
}
|
}
|
||||||
else if (terrain.type.wire_propagation_mode === 'cross' ||
|
else if (mode === 'cross' || (mode === 'autocross' && tile.wire_directions === 0x0f)) {
|
||||||
(wire_directions === 0x0f && terrain.type.wire_propagation_mode !== 'all'))
|
|
||||||
{
|
|
||||||
// This is a cross pattern, so only opposite edges connect
|
// This is a cross pattern, so only opposite edges connect
|
||||||
if (wire_directions & edgeinfo.opposite_bit) {
|
if (tile.wire_directions & edgeinfo.opposite_bit) {
|
||||||
connections |= edgeinfo.opposite_bit;
|
connections |= edgeinfo.opposite_bit;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
// Everything connects
|
// Everything connects
|
||||||
connections |= wire_directions;
|
connections |= tile.wire_directions;
|
||||||
}
|
}
|
||||||
|
|
||||||
seen_cells.set(cell, seen_edges | connections);
|
seen_cells.set(cell, seen_edges | connections);
|
||||||
|
|
||||||
if (on_wire) {
|
if (on_wire) {
|
||||||
on_wire(terrain, connections);
|
on_wire(tile, connections);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (let [direction, dirinfo] of Object.entries(DIRECTIONS)) {
|
for (let [direction, dirinfo] of Object.entries(DIRECTIONS)) {
|
||||||
@ -67,6 +67,8 @@ export function trace_floor_circuit(level, start_cell, start_edge, on_wire, on_d
|
|||||||
let neighbor;
|
let neighbor;
|
||||||
if ((terrain.wire_tunnel_directions ?? 0) & dirinfo.bit) {
|
if ((terrain.wire_tunnel_directions ?? 0) & dirinfo.bit) {
|
||||||
// Search in this direction for a matching tunnel
|
// Search in this direction for a matching tunnel
|
||||||
|
// Note that while actors (the fuckin circuit block) can be wired, tunnels ONLY
|
||||||
|
// appear on terrain, and are NOT affected by actors on top
|
||||||
neighbor = find_matching_wire_tunnel(level, cell.x, cell.y, direction);
|
neighbor = find_matching_wire_tunnel(level, cell.x, cell.y, direction);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
|||||||
@ -2445,9 +2445,12 @@ export class Level extends LevelInterface {
|
|||||||
if (! wired)
|
if (! wired)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
if (wired.type.wire_propagation_mode === 'none' && ! wired.type.is_power_source)
|
if ((wired.wire_propagation_mode ?? wired.type.wire_propagation_mode) === 'none' &&
|
||||||
|
! wired.type.is_power_source)
|
||||||
|
{
|
||||||
// Being next to e.g. a red teleporter doesn't count (but pink button is ok)
|
// Being next to e.g. a red teleporter doesn't count (but pink button is ok)
|
||||||
continue;
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
if ((wired.wire_directions & dirinfo.opposite_bit) &&
|
if ((wired.wire_directions & dirinfo.opposite_bit) &&
|
||||||
! (wired.wire_tunnel_directions & dirinfo.opposite_bit))
|
! (wired.wire_tunnel_directions & dirinfo.opposite_bit))
|
||||||
|
|||||||
@ -2258,9 +2258,9 @@ export class Tileset {
|
|||||||
// Draw the base tile
|
// Draw the base tile
|
||||||
packet.blit(drawspec.base[0], drawspec.base[1]);
|
packet.blit(drawspec.base[0], drawspec.base[1]);
|
||||||
|
|
||||||
let mode = tile.wire_propagation_mode || TILE_TYPES[name].wire_propagation_mode;
|
let mode = tile.wire_propagation_mode ?? TILE_TYPES[name].wire_propagation_mode;
|
||||||
let is_crossed = (
|
let is_crossed = drawspec.wired_cross && (
|
||||||
tile.wire_directions === 0x0f && drawspec.wired_cross && mode === 'cross');
|
mode === 'cross' || (mode === 'autocross' && tile.wire_directions === 0x0f));
|
||||||
if (is_crossed && tile.powered_edges && tile.powered_edges !== 0x0f) {
|
if (is_crossed && tile.powered_edges && tile.powered_edges !== 0x0f) {
|
||||||
// For crossed wires with different power, order matters; horizontal is on top
|
// For crossed wires with different power, order matters; horizontal is on top
|
||||||
// TODO note that this enforces the CC2 wire order
|
// TODO note that this enforces the CC2 wire order
|
||||||
|
|||||||
@ -251,7 +251,7 @@ const TILE_TYPES = {
|
|||||||
floor: {
|
floor: {
|
||||||
layer: LAYERS.terrain,
|
layer: LAYERS.terrain,
|
||||||
contains_wire: true,
|
contains_wire: true,
|
||||||
wire_propagation_mode: 'cross',
|
wire_propagation_mode: 'autocross',
|
||||||
on_approach(me, level, other) {
|
on_approach(me, level, other) {
|
||||||
if (other.type.name === 'blob' || other.type.name === 'boulder') {
|
if (other.type.name === 'blob' || other.type.name === 'boulder') {
|
||||||
// Blobs spread slime onto floor
|
// Blobs spread slime onto floor
|
||||||
@ -474,7 +474,7 @@ const TILE_TYPES = {
|
|||||||
layer: LAYERS.terrain,
|
layer: LAYERS.terrain,
|
||||||
blocks_collision: COLLISION.all,
|
blocks_collision: COLLISION.all,
|
||||||
contains_wire: true,
|
contains_wire: true,
|
||||||
wire_propagation_mode: 'cross',
|
wire_propagation_mode: 'autocross',
|
||||||
},
|
},
|
||||||
canopy: {
|
canopy: {
|
||||||
layer: LAYERS.canopy,
|
layer: LAYERS.canopy,
|
||||||
@ -2408,13 +2408,14 @@ const TILE_TYPES = {
|
|||||||
is_actor: true,
|
is_actor: true,
|
||||||
is_block: true,
|
is_block: true,
|
||||||
contains_wire: true,
|
contains_wire: true,
|
||||||
wire_propagation_mode: 'cross',
|
wire_propagation_mode: 'autocross',
|
||||||
can_reverse_on_railroad: true,
|
can_reverse_on_railroad: true,
|
||||||
movement_speed: 4,
|
movement_speed: 4,
|
||||||
on_clone(me, original) {
|
on_clone(me, original) {
|
||||||
me.wire_directions = original.wire_directions;
|
me.wire_directions = original.wire_directions;
|
||||||
},
|
},
|
||||||
on_starting_move(me, level) {
|
on_starting_move(me, level) {
|
||||||
|
level._set_tile_prop(me, 'powered_edges', 0);
|
||||||
level.recalculate_circuitry_next_wire_phase = true;
|
level.recalculate_circuitry_next_wire_phase = true;
|
||||||
},
|
},
|
||||||
on_finishing_move(me, level) {
|
on_finishing_move(me, level) {
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user