Refactor constraints and action definitions for improved clarity and functionality

- Renamed `requireMinimumTerm` to `reqMinimumTreatyTerm` for consistency in naming conventions.
- Introduced `battleGroundCity` constraint to encapsulate logic for checking if a city is in a war zone.
- Added `hasRouteToDestCity` constraint to validate city accessibility based on distance and resource requirements.
- Replaced `alwaysFail` with `denyWithReason` for better error handling in action definitions.
- Implemented `reqEnvValue` for environment value checks with comparison operators.
- Enhanced nation constraints with `reqNationValue` and `reqDestNationValue` for flexible value comparisons.
- Added `wanderingNation` constraint to check if a nation is classified as wandering.
- Improved general constraints with `reqGeneralValue` for dynamic value checks.
- Updated various action definitions to utilize new constraints for better maintainability and readability.
This commit is contained in:
2026-02-06 18:55:43 +00:00
parent d7cb8c77e3
commit 15730feafe
35 changed files with 1004 additions and 298 deletions
+22
View File
@@ -499,6 +499,28 @@ export const beNeutralCity = (): Constraint => ({
},
});
export const constructableCity = (): Constraint => ({
name: 'constructableCity',
requires: (ctx) => (ctx.cityId !== undefined ? [{ kind: 'city', id: ctx.cityId }] : []),
test: (ctx, view) => {
const city = readCity(view, ctx.cityId);
if (!city) {
if (ctx.cityId === undefined) {
return unknownOrDeny(ctx, [], '도시 정보가 없습니다.');
}
const req: RequirementKey = { kind: 'city', id: ctx.cityId };
return unknownOrDeny(ctx, [req], '도시 정보가 없습니다.');
}
if (city.nationId !== 0) {
return { kind: 'deny', reason: '공백지가 아닙니다.' };
}
if (![5, 6].includes(city.level)) {
return { kind: 'deny', reason: '중, 소 도시에만 가능합니다.' };
}
return allow();
},
});
export const reqCityLevel = (levels: number[]): Constraint => ({
name: 'reqCityLevel',
requires: (ctx) => (ctx.cityId !== undefined ? [{ kind: 'city', id: ctx.cityId }] : []),