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) {
|
||||
let is_first = true;
|
||||
@ -15,45 +15,45 @@ export function trace_floor_circuit(level, start_cell, start_edge, on_wire, on_d
|
||||
let seen_edges = seen_cells.get(cell) ?? 0;
|
||||
if (seen_edges & edgeinfo.bit)
|
||||
continue;
|
||||
|
||||
|
||||
let tile = terrain;
|
||||
let actor = cell.get_actor();
|
||||
let wire_directions = terrain.wire_directions;
|
||||
if ((actor?.wire_directions ?? null !== null) && (actor.movement_cooldown === 0 || level.compat.tiles_react_instantly))
|
||||
if (actor && actor.type.contains_wire && (
|
||||
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
|
||||
// cell, then check for any neighbors
|
||||
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
|
||||
// case we trust the caller)
|
||||
if (on_dead_end) {
|
||||
on_dead_end(terrain.cell, edge);
|
||||
on_dead_end(cell, edge);
|
||||
}
|
||||
continue;
|
||||
}
|
||||
else if (terrain.type.wire_propagation_mode === 'none') {
|
||||
else if (mode === 'none') {
|
||||
// The wires in this tile never connect to each other
|
||||
}
|
||||
else if (terrain.type.wire_propagation_mode === 'cross' ||
|
||||
(wire_directions === 0x0f && terrain.type.wire_propagation_mode !== 'all'))
|
||||
{
|
||||
else if (mode === 'cross' || (mode === 'autocross' && tile.wire_directions === 0x0f)) {
|
||||
// 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;
|
||||
}
|
||||
}
|
||||
else {
|
||||
// Everything connects
|
||||
connections |= wire_directions;
|
||||
connections |= tile.wire_directions;
|
||||
}
|
||||
|
||||
seen_cells.set(cell, seen_edges | connections);
|
||||
|
||||
if (on_wire) {
|
||||
on_wire(terrain, connections);
|
||||
on_wire(tile, connections);
|
||||
}
|
||||
|
||||
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;
|
||||
if ((terrain.wire_tunnel_directions ?? 0) & dirinfo.bit) {
|
||||
// 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);
|
||||
}
|
||||
else {
|
||||
|
||||
@ -2445,9 +2445,12 @@ export class Level extends LevelInterface {
|
||||
if (! wired)
|
||||
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)
|
||||
continue;
|
||||
}
|
||||
|
||||
if ((wired.wire_directions & dirinfo.opposite_bit) &&
|
||||
! (wired.wire_tunnel_directions & dirinfo.opposite_bit))
|
||||
|
||||
@ -2258,9 +2258,9 @@ export class Tileset {
|
||||
// Draw the base tile
|
||||
packet.blit(drawspec.base[0], drawspec.base[1]);
|
||||
|
||||
let mode = tile.wire_propagation_mode || TILE_TYPES[name].wire_propagation_mode;
|
||||
let is_crossed = (
|
||||
tile.wire_directions === 0x0f && drawspec.wired_cross && mode === 'cross');
|
||||
let mode = tile.wire_propagation_mode ?? TILE_TYPES[name].wire_propagation_mode;
|
||||
let is_crossed = drawspec.wired_cross && (
|
||||
mode === 'cross' || (mode === 'autocross' && tile.wire_directions === 0x0f));
|
||||
if (is_crossed && tile.powered_edges && tile.powered_edges !== 0x0f) {
|
||||
// For crossed wires with different power, order matters; horizontal is on top
|
||||
// TODO note that this enforces the CC2 wire order
|
||||
|
||||
@ -251,7 +251,7 @@ const TILE_TYPES = {
|
||||
floor: {
|
||||
layer: LAYERS.terrain,
|
||||
contains_wire: true,
|
||||
wire_propagation_mode: 'cross',
|
||||
wire_propagation_mode: 'autocross',
|
||||
on_approach(me, level, other) {
|
||||
if (other.type.name === 'blob' || other.type.name === 'boulder') {
|
||||
// Blobs spread slime onto floor
|
||||
@ -474,7 +474,7 @@ const TILE_TYPES = {
|
||||
layer: LAYERS.terrain,
|
||||
blocks_collision: COLLISION.all,
|
||||
contains_wire: true,
|
||||
wire_propagation_mode: 'cross',
|
||||
wire_propagation_mode: 'autocross',
|
||||
},
|
||||
canopy: {
|
||||
layer: LAYERS.canopy,
|
||||
@ -2408,13 +2408,14 @@ const TILE_TYPES = {
|
||||
is_actor: true,
|
||||
is_block: true,
|
||||
contains_wire: true,
|
||||
wire_propagation_mode: 'cross',
|
||||
wire_propagation_mode: 'autocross',
|
||||
can_reverse_on_railroad: true,
|
||||
movement_speed: 4,
|
||||
on_clone(me, original) {
|
||||
me.wire_directions = original.wire_directions;
|
||||
},
|
||||
on_starting_move(me, level) {
|
||||
level._set_tile_prop(me, 'powered_edges', 0);
|
||||
level.recalculate_circuitry_next_wire_phase = true;
|
||||
},
|
||||
on_finishing_move(me, level) {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user