Load the CC2 thin walls (and canopy)

This commit is contained in:
Eevee (Evelyn Woods) 2020-09-08 14:11:20 -06:00
parent d38cbc9294
commit 214a430e52
3 changed files with 36 additions and 9 deletions

View File

@ -171,7 +171,7 @@ const TILE_ENCODING = {
// 0x6a: Time penalty : '#next' // 0x6a: Time penalty : '#next'
// 0x6b: Custom floor (green) : Modifier allows other styles, see below // 0x6b: Custom floor (green) : Modifier allows other styles, see below
// 0x6c: (Unused) : // 0x6c: (Unused) :
// 0x6d: Thin wall / Canopy : Panel/Canopy bitmask (see below), '#next' 0x6d: ['#thinwall/canopy', '#next'],
// 0x6e: (Unused) : // 0x6e: (Unused) :
// 0x6f: Railroad sign : '#next' // 0x6f: Railroad sign : '#next'
// 0x70: Custom wall (green) : Modifier allows other styles, see below // 0x70: Custom wall (green) : Modifier allows other styles, see below
@ -401,6 +401,7 @@ export function parse_level(buf) {
let [name, ...args] = read_spec(); let [name, ...args] = read_spec();
if (name === undefined) continue; // XXX modifier skip hack if (name === undefined) continue; // XXX modifier skip hack
// Deal with modifiers
let modifier; let modifier;
if (name === '#mod8') { if (name === '#mod8') {
if (args[0] !== '#next') if (args[0] !== '#next')
@ -414,6 +415,36 @@ export function parse_level(buf) {
throw new Error(`Expected a tile requiring a modifier`); throw new Error(`Expected a tile requiring a modifier`);
} }
// Make a tile template, possibly dealing with some special cases
if (name === '#thinwall/canopy') {
// Thin walls and the canopy are combined into a single
// byte for some reason; split them apart here. Which
// ones we get is determined by a bitmask
let mask = bytes[p];
p++;
// This order is important; this is the order CC2 draws them in
if (mask & 0x10) {
cell.push({name: 'canopy'});
}
if (mask & 0x08) {
cell.push({name: 'thinwall_w'});
}
if (mask & 0x04) {
cell.push({name: 'thinwall_s'});
}
if (mask & 0x02) {
cell.push({name: 'thinwall_e'});
}
if (mask & 0x01) {
cell.push({name: 'thinwall_n'});
}
// Skip the rest of the loop. That means we don't
// handle any of the other special behavior below, but
// neither thin walls nor canopies should use any of
// it, so that's fine
continue;
}
let tile = {name, modifier}; let tile = {name, modifier};
cell.push(tile); cell.push(tile);
let type = TILE_TYPES[name]; let type = TILE_TYPES[name];
@ -421,11 +452,6 @@ export function parse_level(buf) {
if (type.is_required_chip) { if (type.is_required_chip) {
level.chips_required++; level.chips_required++;
} }
if (type.is_player) {
// TODO handle multiple starts
level.player_start_x = n % width;
level.player_start_y = Math.floor(n / width);
}
if (type.is_hint) { if (type.is_hint) {
// Remember all the hint tiles (in reading order) so we // Remember all the hint tiles (in reading order) so we
// can map extra hints to them later. Don't do it now, // can map extra hints to them later. Don't do it now,

View File

@ -20,9 +20,6 @@ export class StoredLevel {
this.size_y = 0; this.size_y = 0;
this.linear_cells = []; this.linear_cells = [];
this.player_start_x = 0;
this.player_start_y = 0;
// Maps of button positions to trap/cloner positions, as scalar indexes // Maps of button positions to trap/cloner positions, as scalar indexes
// in the linear cell list // in the linear cell list
this.custom_trap_wiring = {}; this.custom_trap_wiring = {};

View File

@ -5,6 +5,7 @@ const LAYER_TERRAIN = 0;
const LAYER_ITEM = 1; const LAYER_ITEM = 1;
const LAYER_ACTOR = 2; const LAYER_ACTOR = 2;
const LAYER_OVERLAY = 3; const LAYER_OVERLAY = 3;
// TODO cc2 order is: swivel, thinwalls, canopy (and yes you can have them all in the same tile)
const TILE_TYPES = { const TILE_TYPES = {
// Floors and walls // Floors and walls
@ -76,6 +77,9 @@ const TILE_TYPES = {
level.transmute_tile(me, 'floor'); level.transmute_tile(me, 'floor');
}, },
}, },
canopy: {
draw_layer: LAYER_OVERLAY,
},
// Swivel doors // Swivel doors
swivel_floor: { swivel_floor: {