Skip to content

Commit

Permalink
Correctly do destructibility by tool
Browse files Browse the repository at this point in the history
  • Loading branch information
jcreedcmu committed Feb 7, 2024
1 parent a29ac9f commit b6e3d8c
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 7 deletions.
14 changes: 13 additions & 1 deletion src/core/intent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { WidgetPoint } from '../ui/widget-helpers';
import { produce } from '../util/produce';
import { Point } from '../util/types';
import { vint, vm } from '../util/vutil';
import { Bonus } from './bonus';
import { tryKillTileOfState } from './kill-helpers';
import { vacuous_down } from './low-actions';
import { SelectionOperation, deselect, selectionOperationOfMods } from './selection';
Expand All @@ -27,7 +28,18 @@ export type Intent =
;

function dynamiteableCell(cell: CellContents): boolean {
return cell.t == 'tile' || (cell.t == 'bonus' && (cell.bonus.t != 'empty'));
return cell.t == 'tile' || (cell.t == 'bonus' && killableBonus(dynamiteIntent, cell.bonus));
}

export function killableBonus(intent: KillIntent, bonus: Bonus): boolean {
switch (intent.t) {
case 'fillWater':
return !(bonus.t == 'required' || bonus.t == 'empty');
case 'kill':
case 'bomb':
return !(bonus.t == 'block' || bonus.t == 'required' || bonus.t == 'empty');
}

}

export function getIntentOfMouseDown(tool: Tool, wp: WidgetPoint, button: number, mods: Set<string>, hoverCell: CellContents, pinned: boolean): Intent {
Expand Down
8 changes: 2 additions & 6 deletions src/core/kill-helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { Point } from "../util/types";
import { vequal, vint } from "../util/vutil";
import { Animation, mkExplosionAnimation } from './animations';
import { getBonusFromLayer, updateBonusLayer } from "./bonus-helpers";
import { KillIntent } from './intent';
import { KillIntent, killableBonus } from './intent';
import { getScore, incrementScore } from "./scoring";
import { deselect } from "./selection";
import { CoreState, MainTile } from "./state";
Expand Down Expand Up @@ -62,10 +62,6 @@ function killTileOfState(state: CoreState, wp: DragWidgetPoint, intent: KillInte
function tileAt(p: Point): MainTile | undefined {
return get_main_tiles(state).find(tile => vequal(tile.loc.p_in_world_int, p));
}
function killableBonusAt(p: Point) {
// FIXME: any unbombable ones? Maybe 'water', in the future?
return getBonusFromLayer(state, p).t != 'empty';
}

const tilesToDestroy: Point[] = splashDamage(p_in_world_int, radius);
// remove all tiles in radius
Expand All @@ -76,7 +72,7 @@ function killTileOfState(state: CoreState, wp: DragWidgetPoint, intent: KillInte
});
// remove all killable bonuses in radius
tilesToDestroy.forEach(p => {
if (killableBonusAt(p)) {
if (killableBonus(intent, getBonusFromLayer(state, p))) {
state = updateBonusLayer(state, p, { t: 'empty' });
}
});
Expand Down

0 comments on commit b6e3d8c

Please sign in to comment.