Skip to content

Commit

Permalink
Allow ActivatePower actions to have a from for targeting.
Browse files Browse the repository at this point in the history
GitOrigin-RevId: 13dc2468ae340652ce9e5173d5bb6a5b73ca204f
  • Loading branch information
cpojer committed Feb 26, 2025
1 parent 4f8c90a commit 075ceb4
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 176 deletions.
98 changes: 22 additions & 76 deletions apollo/Action.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -86,15 +86,9 @@ type AttackBuildingAction = Readonly<{
type: 'AttackBuilding';
}>;

type CaptureAction = Readonly<{
from: Vector;
type: 'Capture';
}>;
type CaptureAction = Readonly<{ from: Vector; type: 'Capture' }>;

type SupplyAction = Readonly<{
from: Vector;
type: 'Supply';
}>;
type SupplyAction = Readonly<{ from: Vector; type: 'Supply' }>;

type CreateUnitAction = Readonly<{
from: Vector;
Expand All @@ -116,34 +110,20 @@ type CreateBuildingAction = Readonly<{
type: 'CreateBuilding';
}>;

type CreateTracksAction = Readonly<{
from: Vector;
type: 'CreateTracks';
}>;
type CreateTracksAction = Readonly<{ from: Vector; type: 'CreateTracks' }>;

type FoldAction = Readonly<{
from: Vector;
type: 'Fold';
}>;
type FoldAction = Readonly<{ from: Vector; type: 'Fold' }>;

type UnfoldAction = Readonly<{
from: Vector;
type: 'Unfold';
}>;
type UnfoldAction = Readonly<{ from: Vector; type: 'Unfold' }>;

type CompleteUnitAction = Readonly<{
from: Vector;
type: 'CompleteUnit';
}>;
type CompleteUnitAction = Readonly<{ from: Vector; type: 'CompleteUnit' }>;

type CompleteBuildingAction = Readonly<{
from: Vector;
type: 'CompleteBuilding';
}>;

type EndTurnAction = Readonly<{
type: 'EndTurn';
}>;
type EndTurnAction = Readonly<{ type: 'EndTurn' }>;

type MessageAction = Readonly<{
message: string;
Expand All @@ -157,23 +137,11 @@ type ToggleLightningAction = Readonly<{
type: 'ToggleLightning';
}>;

type HealAction = Readonly<{
from: Vector;
to: Vector;
type: 'Heal';
}>;
type HealAction = Readonly<{ from: Vector; to: Vector; type: 'Heal' }>;

type RescueAction = Readonly<{
from: Vector;
to: Vector;
type: 'Rescue';
}>;
type RescueAction = Readonly<{ from: Vector; to: Vector; type: 'Rescue' }>;

type SabotageAction = Readonly<{
from: Vector;
to: Vector;
type: 'Sabotage';
}>;
type SabotageAction = Readonly<{ from: Vector; to: Vector; type: 'Sabotage' }>;

export type SpawnEffectAction = Readonly<{
buildings?: ImmutableMap<Vector, Building>;
Expand All @@ -189,7 +157,11 @@ type BuySkillAction = Readonly<{
type: 'BuySkill';
}>;

type ActivatePowerAction = Readonly<{ skill: Skill; type: 'ActivatePower' }>;
type ActivatePowerAction = Readonly<{
from?: Vector;
skill: Skill;
type: 'ActivatePower';
}>;

export type ActivateCrystalAction = Readonly<{
biome?: Biome;
Expand Down Expand Up @@ -217,9 +189,7 @@ export type IncreaseFundsEffectAction = Readonly<{
type: 'IncreaseFundsEffect';
}>;

type StartAction = Readonly<{
type: 'Start';
}>;
type StartAction = Readonly<{ type: 'Start' }>;

export type Action =
| ActivateCrystalAction
Expand Down Expand Up @@ -302,13 +272,7 @@ function move(
const unitB = map.units.get(to);
if (unitB) {
if (canLoad(map, unitB, unitA, to)) {
return {
from,
fuel: unitA.fuel - cost,
path,
to,
type: 'Move',
} as const;
return { from, fuel: unitA.fuel - cost, path, to, type: 'Move' } as const;
}
} else if (
!map.buildings.has(to) ||
Expand Down Expand Up @@ -716,10 +680,7 @@ function createTracks(map: MapData, { from }: CreateTracksAction) {
map.getPlayer(unit).funds >= CreateTracksCost &&
canPlaceRailTrack(map, from)
) {
return {
from,
type: 'CreateTracks',
} as const;
return { from, type: 'CreateTracks' } as const;
}
return null;
}
Expand Down Expand Up @@ -780,11 +741,7 @@ function endTurn(map: MapData) {
}

function message(_: MapData, { message, player }: MessageAction) {
return {
message,
player,
type: 'Message',
} as const;
return { message, player, type: 'Message' } as const;
}

function toggleLightning(map: MapData, { from, to }: ToggleLightningAction) {
Expand Down Expand Up @@ -904,9 +861,7 @@ function spawnEffect(
}

if (buildings) {
const futureMap = map.copy({
units: map.units.merge(newUnits),
});
const futureMap = map.copy({ units: map.units.merge(newUnits) });

for (const [vector, building] of buildings) {
if (
Expand Down Expand Up @@ -959,12 +914,7 @@ function buySkill(map: MapData, { from, skill }: BuySkillAction) {
(!unit || map.matchesTeam(unit, building)) &&
map.isCurrentPlayer(building)
) {
return {
from,
player: player.id,
skill,
type: 'BuySkill',
} as const;
return { from, player: player.id, skill, type: 'BuySkill' } as const;
}
return null;
}
Expand Down Expand Up @@ -996,11 +946,7 @@ function activateCrystal(
if (isEffect) {
return Crystals.includes(crystal) &&
(!biome || (Biomes.includes(biome) && biome !== Biome.Spaceship))
? ({
biome,
crystal,
type: 'ActivateCrystal',
} as const)
? ({ biome, crystal, type: 'ActivateCrystal' } as const)
: null;
}

Expand Down
2 changes: 1 addition & 1 deletion apollo/ActionMap.json
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@
["Rescue", [37, ["type", "from", "to", "player", "name"]]],
["ReceiveReward", [38, ["type", "player", "reward", "permanent"]]],
["BuySkill", [39, ["type", "from", "skill", "player"]]],
["ActivatePower", [40, ["type", "skill", "units", "free"]]],
["ActivatePower", [40, ["type", "skill", "from", "units", "free"]]],
["PreviousTurnGameOver", [41, ["type", "fromPlayer"]]],
["SecretDiscovered", [42, ["type", "objective", "toPlayer"]]],
["OptionalObjective", [43, ["type", "objective", "objectiveId", "toPlayer"]]],
Expand Down
121 changes: 22 additions & 99 deletions apollo/action-mutators/ActionMutators.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,141 +18,64 @@ export const MoveAction = (
}) as const;

export const AttackUnitAction = (from: Vector, to: Vector) =>
({
from,
to,
type: 'AttackUnit',
}) as const;
({ from, to, type: 'AttackUnit' }) as const;

export const AttackBuildingAction = (from: Vector, to: Vector) =>
({
from,
to,
type: 'AttackBuilding',
}) as const;
({ from, to, type: 'AttackBuilding' }) as const;

export const CaptureAction = (from: Vector) =>
({
from,
type: 'Capture',
}) as const;
({ from, type: 'Capture' }) as const;

export const SupplyAction = (from: Vector) =>
({
from,
type: 'Supply',
}) as const;
({ from, type: 'Supply' }) as const;

export const CreateUnitAction = (from: Vector, id: number, to: Vector) =>
({
from,
id,
to,
type: 'CreateUnit',
}) as const;
({ from, id, to, type: 'CreateUnit' }) as const;

export const DropUnitAction = (from: Vector, index: number, to: Vector) =>
({
from,
index,
to,
type: 'DropUnit',
}) as const;
({ from, index, to, type: 'DropUnit' }) as const;

export const CreateBuildingAction = (from: Vector, id: number) =>
({
from,
id,
type: 'CreateBuilding',
}) as const;
({ from, id, type: 'CreateBuilding' }) as const;

export const CreateTracksAction = (from: Vector) =>
({
from,
type: 'CreateTracks',
}) as const;
({ from, type: 'CreateTracks' }) as const;

export const FoldAction = (from: Vector) =>
({
from,
type: 'Fold',
}) as const;
export const FoldAction = (from: Vector) => ({ from, type: 'Fold' }) as const;

export const UnfoldAction = (from: Vector) =>
({
from,
type: 'Unfold',
}) as const;
({ from, type: 'Unfold' }) as const;

export const CompleteUnitAction = (from: Vector) =>
({
from,
type: 'CompleteUnit',
}) as const;
({ from, type: 'CompleteUnit' }) as const;

export const CompleteBuildingAction = (from: Vector) =>
({
from,
type: 'CompleteBuilding',
}) as const;
({ from, type: 'CompleteBuilding' }) as const;

export const EndTurnAction = () => ({ type: 'EndTurn' }) as const;

export const MessageAction = (message: string, player?: PlayerID) =>
({
message,
player,
type: 'Message',
}) as const;
({ message, player, type: 'Message' }) as const;

export const ToggleLightningAction = (from: Vector, to: Vector) =>
({
from,
to,
type: 'ToggleLightning',
}) as const;
({ from, to, type: 'ToggleLightning' }) as const;

export const HealAction = (from: Vector, to: Vector) =>
({
from,
to,
type: 'Heal',
}) as const;
({ from, to, type: 'Heal' }) as const;

export const RescueAction = (from: Vector, to: Vector) =>
({
from,
to,
type: 'Rescue',
}) as const;
({ from, to, type: 'Rescue' }) as const;

export const SabotageAction = (from: Vector, to: Vector) =>
({
from,
to,
type: 'Sabotage',
}) as const;
({ from, to, type: 'Sabotage' }) as const;

export const StartAction = () =>
({
type: 'Start',
}) as const;
export const StartAction = () => ({ type: 'Start' }) as const;

export const BuySkillAction = (from: Vector, skill: Skill) =>
({
from,
skill,
type: 'BuySkill',
}) as const;
({ from, skill, type: 'BuySkill' }) as const;

export const ActivatePowerAction = (skill: Skill) =>
({
skill,
type: 'ActivatePower',
}) as const;
export const ActivatePowerAction = (skill: Skill, from?: Vector) =>
({ from, skill, type: 'ActivatePower' }) as const;

export const ActivateCrystalAction = (crystal: Crystal) =>
({
crystal,
type: 'ActivateCrystal',
}) as const;
({ crystal, type: 'ActivateCrystal' }) as const;

0 comments on commit 075ceb4

Please sign in to comment.