Skip to content

Commit

Permalink
Add fillWater landing back
Browse files Browse the repository at this point in the history
Now moving logs around within the world has the desired effect
  • Loading branch information
jcreedcmu committed Feb 11, 2024
1 parent 3e72053 commit be2712d
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 34 deletions.
1 change: 0 additions & 1 deletion src/core/action.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ export type GameLowAction =
| { t: 'deselect' }
| { t: 'flipOrientation' }
| { t: 'dynamiteTile', wp: WidgetPoint }
| { t: 'fillWater', p_in_world_int: Point }
| { t: 'dropTopHandTile' }
| { t: 'debug' }
| { t: 'incrementScore', amount: number }
Expand Down
4 changes: 2 additions & 2 deletions src/core/kill-helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,14 @@ function eligibleKillIntent(state: CoreState, intent: KillIntent): boolean {
switch (intent.t) {
case 'kill': return state.slowState.inventory.dynamites >= 1;
case 'bomb': return state.slowState.inventory.bombs >= 1;
case 'fillWater': return state.slowState.resource.wood >= 1;
case 'fillWater': return true;
}
}
function spendKillIntent(state: CoreState, intent: KillIntent): CoreState {
switch (intent.t) {
case 'kill': return produce(state, s => { s.slowState.inventory.dynamites--; });
case 'bomb': return produce(state, s => { s.slowState.inventory.bombs--; });
case 'fillWater': return produce(state, s => { s.slowState.resource.wood--; });
case 'fillWater': return state;
}
}

Expand Down
37 changes: 23 additions & 14 deletions src/core/landing-resolve.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
import { produce } from "../util/produce";
import { Point } from "../util/types";
import { LandingMove, LandingResult, MoveSource, ProperLandingResult } from "./landing-result";
import { MobType } from "./mobs";
import { tryKillTileOfStateLoc } from "./kill-helpers";
import { LandingResult, ProperLandingResult } from "./landing-result";
import { CoreState, MoveMobile } from "./state";
import { checkValid } from "./state-helpers";
import { addResourceMobile, putMobileInWorld } from "./tile-helpers";
import { Resource } from "./tools";
import { addResourceMobile, putMobileInWorld, putMobileNowhere } from "./tile-helpers";
import { Resource, fillWaterIntent } from "./tools";

// A thing that can be moved onto something else
export type MoveSourceId =
Expand All @@ -15,19 +14,29 @@ export type MoveSourceId =

export type LandingMoveId = { src: MoveSourceId, p_in_world_int: Point };

export function resolveLandResult(state: CoreState, lr: ProperLandingResult, move: LandingMoveId): CoreState {
const src = move.src;
export function removeSource(state: CoreState, src: MoveSourceId): CoreState {
switch (src.t) {
case 'mobile':
return putMobileInWorld(state, src.id, move.p_in_world_int, 'noclear');
case 'freshResource': {
const cs1 = produce(state, cs => { cs.slowState.resource[src.res]--; });
return addResourceMobile(cs1, move.p_in_world_int, src.res);
}
case 'mobile': return putMobileNowhere(state, src.id, 'noclear');
case 'freshResource': return produce(state, cs => { cs.slowState.resource[src.res]--; });
}
}

class CollisionException extends Error { }
export function resolveLandResult(_state: CoreState, lr: ProperLandingResult, move: LandingMoveId): CoreState {
const src = move.src;
const state = removeSource(_state, move.src);

switch (lr.t) {
case 'place':
switch (src.t) {
case 'mobile': return putMobileInWorld(state, src.id, move.p_in_world_int, 'noclear');
case 'freshResource': return addResourceMobile(state, move.p_in_world_int, src.res);

}
case 'fillWater': {
return tryKillTileOfStateLoc(state, { t: 'world', p_in_world_int: move.p_in_world_int }, fillWaterIntent);
}
}
}

export function requireNoCollision(lr: LandingResult): ProperLandingResult | undefined {
if (lr.t == 'collision')
Expand Down
24 changes: 16 additions & 8 deletions src/core/landing-result.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export type LandingMove = { src: MoveSource, p_in_world_int: Point };
export type ProperLandingResult =
| { t: 'place' } // the attempt to place A on B "succeeds" in the most trivial way
/* other things that I expect to go here include: success which transforms the B somehow */
/* e.g.: wood fills water */
| { t: 'fillWater' }
;

export type LandingResult =
Expand All @@ -47,6 +47,7 @@ export type LandingResult =
export function disjunction(lr1: LandingResult, lr2: LandingResult): LandingResult {
switch (lr1.t) {
case 'collision': return { t: 'collision' };
case 'fillWater': return { t: 'fillWater' };
case 'place': return lr2;
}
}
Expand All @@ -62,12 +63,19 @@ export function landMobileOnCell(m: MoveSource, c: CellContents): LandingResult
case 'mobile': return { t: 'collision' };
case 'bonus': {
const bonus = c.bonus;
if (bonus.t == 'empty')
return { t: 'place' };
if (bonus.t == 'required') {
return (m.t == 'tile' && (m.letter == bonus.letter || DEBUG.allWords)) ? { t: 'place' } : { t: 'collision' };
switch (bonus.t) {
case 'empty': return { t: 'place' };
case 'tree': return { t: 'collision' };
case 'bomb': return { t: 'collision' };
case 'required': return (m.t == 'tile' && (m.letter == bonus.letter || DEBUG.allWords)) ? { t: 'place' } : { t: 'collision' };
case 'consonant': return { t: 'collision' };
case 'vowel': return { t: 'collision' };
case 'copy': return { t: 'collision' };
case 'word': return { t: 'collision' };
case 'time': return { t: 'collision' };
case 'dynamite': return { t: 'collision' };
case 'water': return (m.t == 'resource' && m.res == 'wood') ? { t: 'fillWater' } : { t: 'collision' };
}
return { t: 'collision' };
}
}
}
Expand All @@ -83,15 +91,15 @@ export function landMoveOnMob(m: LandingMove, mob: MobState): LandingResult {

export function landingMoveOfMoveMobile(m: MoveMobile): LandingMove {
return {
src: m.mobile, // NOTE: RenderableMobile is a sutbtype of MoveSource for now...
src: m.mobile, // NOTE: RenderableMobile is a sutbtype of MoveSource for now...
p_in_world_int: m.p_in_world_int
};
}

export function landMoveOnStateForMobiles(m: LandingMove, state: CoreState, mobiles: MobileEntity[]): LandingResult {
return disjuncts(
...state.mobsState.mobs.map(mob => landMoveOnMob(m, mob)),
landMobileOnCell(m.src, cellAtPointForMobiles(state, m.p_in_world_int, mobiles)),
...state.mobsState.mobs.map(mob => landMoveOnMob(m, mob))
);
}

Expand Down
15 changes: 6 additions & 9 deletions src/core/low-actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,20 @@ import { Point } from '../util/types';
import { flatUndef, getRandomOrder } from '../util/util';
import { vequal, vint, vm, vscale, vsub } from '../util/vutil';
import { GameAction, GameLowAction, LowAction } from './action';
import { getBonusFromLayer } from './bonus-helpers';
import { getPanicFraction, now_in_game } from './clock';
import { getIntentOfMouseDown, reduceIntent } from './intent';
import { tryKillTileOfState, tryKillTileOfStateLoc } from './kill-helpers';
import { LandingMoveId, landingMoveIdOfMoveMobile, requireNoCollision, resolveLandResult } from './landing-resolve';
import { ProperLandingResult, landMoveOnState, landMoveOnStateForMobiles, landingMoveOfMoveMobile } from './landing-result';
import { tryKillTileOfState } from './kill-helpers';
import { landingMoveIdOfMoveMobile, requireNoCollision, resolveLandResult } from './landing-resolve';
import { landMoveOnState, landMoveOnStateForMobiles, landingMoveOfMoveMobile } from './landing-result';
import { mkOverlayFrom } from './layer';
import { addRandomMob, advanceMob } from './mobs';
import { reduceKey } from './reduceKey';
import { incrementScore, setScore } from './scoring';
import { deselect, resolveSelection, setSelected } from './selection';
import { CacheUpdate, CoreState, GameState, Location, MobsState, MoveMobile, SceneState } from './state';
import { addWorldTiles, checkValid, drawOfState, dropTopHandTile, filterExpiredAnimations, filterExpiredWordBonusState, isMobilePinned, needsRefresh, pointFall, proposedHandDragOverLimit, tileFall, unpauseState, withCoreState } from './state-helpers';
import { addResourceMobile, cellAtPoint, getMobileId, getMobileLoc, getRenderableMobile, get_hand_tiles, get_mobiles, mobileAtPoint, moveTiles, moveToHandLoc, putTileInHand, putTilesInHandFromNotHand, removeAllMobiles } from "./tile-helpers";
import { Resource, bombIntent, dynamiteIntent, fillWaterIntent, getCurrentTool, reduceToolSelect, toolPrecondition } from './tools';
import { addWorldTiles, checkValid, drawOfState, dropTopHandTile, filterExpiredAnimations, filterExpiredWordBonusState, isMobilePinned, needsRefresh, proposedHandDragOverLimit, tileFall, unpauseState, withCoreState } from './state-helpers';
import { cellAtPoint, getMobileId, getMobileLoc, getRenderableMobile, get_hand_tiles, get_mobiles, mobileAtPoint, moveTiles, moveToHandLoc, putTileInHand, putTilesInHandFromNotHand, removeAllMobiles } from "./tile-helpers";
import { bombIntent, dynamiteIntent, getCurrentTool, reduceToolSelect, toolPrecondition } from './tools';
import { shouldDisplayBackButton } from './winState';

export function reduceZoom(state: GameState, p_in_canvas: Point, delta: number): GameState {
Expand Down Expand Up @@ -403,8 +402,6 @@ function resolveGameLowAction(state: GameState, action: GameLowAction): GameStat
}
case 'dynamiteTile':
return withCoreState(state, cs => tryKillTileOfState(cs, action.wp, dynamiteIntent));
case 'fillWater':
return withCoreState(state, cs => tryKillTileOfStateLoc(cs, { t: 'world', p_in_world_int: action.p_in_world_int }, fillWaterIntent));
case 'dropTopHandTile': return dropTopHandTile(state);
case 'debug': {
return withCoreState(state, cs => checkValid(produce(addWorldTiles(removeAllMobiles(cs), debugTiles()), s => {
Expand Down

0 comments on commit be2712d

Please sign in to comment.