Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add log message for Renovation Company #138

Merged
merged 1 commit into from
Oct 31, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 2 additions & 5 deletions src/board/Buttons.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,19 +20,16 @@ export default class Buttons extends React.Component<BoardProps<MachikoroG>, obj
const canAddTwo = isActive && Game.canAddTwo(G, ctx);
const canEndTurn = isActive && Game.canEndTurn(G);

// if not null, then the player can activate the Renovation Company on this establishment, effectively "skipping" it
const skipRenovationCompanyEst = Game.canSkipRenovationCompany(G);

const canSkipOffice = isActive && Game.canSkipOffice(G);
const canSkipRenovationCompany = isActive && skipRenovationCompanyEst !== null;
const canSkipRenovationCompany = isActive && Game.canSkipRenovationCompany(G);
const canSkipExhibitHall = isActive && Game.canSkipExhibitHall(G);

const skipButtonActive = canSkipOffice || canSkipRenovationCompany || canSkipExhibitHall;
let onClickSkipEvent: () => void;
if (canSkipOffice) {
onClickSkipEvent = () => moves.skipOffice();
} else if (canSkipRenovationCompany) {
onClickSkipEvent = () => moves.doRenovationCompany(skipRenovationCompanyEst);
onClickSkipEvent = () => moves.skipRenovationCompany();
} else if (canSkipExhibitHall) {
onClickSkipEvent = () => moves.skipExhibitHall();
} else {
Expand Down
5 changes: 3 additions & 2 deletions src/game/establishments/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -220,8 +220,9 @@ export const setRenovationCount = (G: MachikoroG, player: number, est: Establish

/**
* @param G
* @returns An unowned red, blue, or green establishment, or null if none
* exists. This is useful for "skipping" the Renovation Company action.
* @returns A non-Major establishment that is in use but no player currently
* owns, or null if none exists. This is useful for "skipping" the Renovation
* Company action.
*/
export const unownedRedBlueGreenEst = (G: MachikoroG): Establishment | null => {
const ests = getAllInUse(G.version, G.expansions).filter((est) => est.color !== EstColor.Purple);
Expand Down
93 changes: 60 additions & 33 deletions src/game/log/parsers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
// Parsing log entries.
//

import { assertUnreachable } from 'common/typescript';
import { coinPlural } from '../display';

import type { MachikoroG } from '../types';
Expand All @@ -29,6 +28,7 @@ const LogEventType = {
Office: 'Office',
DemolitionCompany: 'DemolitionCompany',
MovingCompany: 'MovingCompany',
RenovationCompany: 'RenovationCompany',
Park: 'Park',
ExhibitHall: 'ExhibitHall',
TechStartup: 'TechStartup',
Expand All @@ -52,6 +52,7 @@ export type LogEvent =
| Office
| DemolitionCompany
| MovingCompany
| RenovationCompany
| Park
| ExhibitHall
| TechStartup
Expand All @@ -65,38 +66,39 @@ export type LogEvent =
* @returns String to display for the log event.
*/
export const parseLogEvent = (logEvent: LogEvent, names: string[]): string => {
if (logEvent.type === LogEventType.RollOne) {
return parseRollOne(logEvent);
} else if (logEvent.type === LogEventType.RollTwo) {
return parseRollTwo(logEvent);
} else if (logEvent.type === LogEventType.AddTwo) {
return parseAddTwo(logEvent);
} else if (logEvent.type === LogEventType.Earn) {
return parseEarn(logEvent, names);
} else if (logEvent.type === LogEventType.Take) {
return parseTake(logEvent, names);
} else if (logEvent.type === LogEventType.Buy) {
return parseBuy(logEvent);
} else if (logEvent.type === LogEventType.Office) {
return parseOffice(logEvent, names);
} else if (logEvent.type === LogEventType.DemolitionCompany) {
return parseDemolitionCompany(logEvent);
} else if (logEvent.type === LogEventType.MovingCompany) {
return parseMovingCompany(logEvent, names);
} else if (logEvent.type === LogEventType.Park) {
return parsePark(logEvent);
} else if (logEvent.type === LogEventType.ExhibitHall) {
return parseExhibitHall(logEvent);
} else if (logEvent.type === LogEventType.TechStartup) {
return parseInvestTechStartup(logEvent);
} else if (logEvent.type === LogEventType.TunaRoll) {
return parseTunaRoll(logEvent);
} else if (logEvent.type === LogEventType.EndGame) {
return parseEndGame(logEvent, names);
} else if (logEvent.type === LogEventType.OtherEvent) {
return parseOtherEvent(logEvent);
} else {
return assertUnreachable(logEvent);
switch (logEvent.type) {
case LogEventType.RollOne:
return parseRollOne(logEvent);
case LogEventType.RollTwo:
return parseRollTwo(logEvent);
case LogEventType.AddTwo:
return parseAddTwo(logEvent);
case LogEventType.Earn:
return parseEarn(logEvent, names);
case LogEventType.Take:
return parseTake(logEvent, names);
case LogEventType.Buy:
return parseBuy(logEvent);
case LogEventType.Office:
return parseOffice(logEvent, names);
case LogEventType.DemolitionCompany:
return parseDemolitionCompany(logEvent);
case LogEventType.MovingCompany:
return parseMovingCompany(logEvent, names);
case LogEventType.RenovationCompany:
return parseRenovationCompany(logEvent);
case LogEventType.Park:
return parsePark(logEvent);
case LogEventType.ExhibitHall:
return parseExhibitHall(logEvent);
case LogEventType.TechStartup:
return parseInvestTechStartup(logEvent);
case LogEventType.TunaRoll:
return parseTunaRoll(logEvent);
case LogEventType.EndGame:
return parseEndGame(logEvent, names);
case LogEventType.OtherEvent:
return parseOtherEvent(logEvent);
}
};

Expand Down Expand Up @@ -365,6 +367,31 @@ const parseMovingCompany = (logEvent: MovingCompany, names: string[]): string =>

// ----------------------------------------------------------------------------

interface RenovationCompany extends BaseLogEvent {
type: typeof LogEventType.RenovationCompany;
estName: string;
}

/**
* Log the effect of the Renovation Company establishment.
* @param G
* @param estName
*/
export const logRenovationCompany = (G: MachikoroG, estName: string): void => {
const logEvent: RenovationCompany = { type: LogEventType.RenovationCompany, estName };
G._logBuffer.push(logEvent);
};

/**
* @param logEvent
* @returns Displayed log text for the Renovation Company establishment.
*/
const parseRenovationCompany = (logEvent: RenovationCompany): string => {
return `\trenovated ${logEvent.estName}`;
};

// ----------------------------------------------------------------------------

interface Park extends BaseLogEvent {
type: typeof LogEventType.Park;
coins: number;
Expand Down
35 changes: 27 additions & 8 deletions src/game/machikoro.ts
Original file line number Diff line number Diff line change
Expand Up @@ -275,15 +275,15 @@ export const canDoRenovationCompany = (G: MachikoroG, est: Establishment): boole

/**
* @param G
* @returns An establishment that the current player can activate with the
* Renovation Company action to effectively "skip" it, or null if such a move
* is not allowed / possible.
* @returns True if the current player can skip the Renovation Company action
* by activating it on an unowned establishment.
*/
export const canSkipRenovationCompany = (G: MachikoroG): Establishment | null => {
if (G.turnState !== TurnState.RenovationCompany) {
return null;
}
return Est.unownedRedBlueGreenEst(G);
export const canSkipRenovationCompany = (G: MachikoroG): boolean => {
return (
G.turnState === TurnState.RenovationCompany &&
// an unknown establishment exists
Est.unownedRedBlueGreenEst(G) !== null
);
};

/**
Expand Down Expand Up @@ -699,6 +699,7 @@ const doRenovationCompany: Move<MachikoroG> = (context, est: Establishment) => {
// close own establishments
const playerCount = Est.countOwned(G, player, est);
Est.setRenovationCount(G, player, est, playerCount);
Log.logRenovationCompany(G, est.name);

// get coins from opponents and close their establishments
for (const opponent of getPreviousPlayers(ctx)) {
Expand All @@ -716,6 +717,23 @@ const doRenovationCompany: Move<MachikoroG> = (context, est: Establishment) => {
return;
};

/**
* Skip the Renovation Company action by picking an unowned establishment to
* renovate.
* @param context
* @returns
*/
const skipRenovationCompany: Move<MachikoroG> = (context) => {
const { G } = context;
if (!canSkipRenovationCompany(G)) {
return INVALID_MOVE;
}

switchState(context);

return;
};

/**
* Perform the Exhibit Hall (Machi Koro 1) action by picking an establishment
* to activate.
Expand Down Expand Up @@ -1673,6 +1691,7 @@ export const Machikoro: Game<MachikoroG, Record<string, unknown>, SetupData> = {
doDemolitionCompany,
doMovingCompanyOpp,
doRenovationCompany,
skipRenovationCompany,
doExhibitHall,
skipExhibitHall,
investTechStartup,
Expand Down
Loading