Skip to content

Commit

Permalink
Do not assume a player has already spawned on a map when figuring out…
Browse files Browse the repository at this point in the history
… spawn locations.

GitOrigin-RevId: 0fcede83a96e0aca0317ba6c0afbc83fe69d0283
  • Loading branch information
cpojer committed Dec 11, 2024
1 parent c387d4c commit 298837b
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 5 deletions.
6 changes: 3 additions & 3 deletions athena/map/Unit.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -490,14 +490,14 @@ export default class Unit extends Entity {
);
}

canCapture(player: Player) {
canCapture(player: Player | null) {
return (
this.info.hasAbility(Ability.Capture) ||
(this.info === Sniper &&
this.isLeader() &&
!this.isUnfolded() &&
player.skills.has(Skill.UnitAbilitySniperImmediateAction)) ||
(this.info === Dragon && player.skills.has(Skill.DragonSaboteur))
player?.skills.has(Skill.UnitAbilitySniperImmediateAction)) ||
(this.info === Dragon && player?.skills.has(Skill.DragonSaboteur))
);
}

Expand Down
26 changes: 26 additions & 0 deletions dionysus/lib/__tests__/estimateClosestTarget.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import { Sniper } from '@deities/athena/info/Unit.tsx';
import withModifiers from '@deities/athena/lib/withModifiers.tsx';
import vec from '@deities/athena/map/vec.tsx';
import MapData from '@deities/athena/MapData.tsx';
import { expect, test } from 'vitest';
import estimateClosestTarget from '../estimateClosestTarget.tsx';

const map = withModifiers(
MapData.createMap({
map: [
1, 1, 1, 3, 2, 1, 1, 1, 3, 1, 1, 2, 3, 1, 3, 1, 1, 1, 1, 1, 1, 2, 3, 1, 1,
],
size: { height: 5, width: 5 },
}),
);

test('estimateClosestTarget should not require a player to be present on the map', () => {
const [target] = estimateClosestTarget(
map,
Sniper.create(3, { name: -1 }),
vec(1, 1),
[vec(5, 1), vec(1, 5)],
true,
);
expect(target?.vector).toEqual(vec(1, 5));
});
2 changes: 1 addition & 1 deletion dionysus/lib/estimateClosestTarget.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ const maybeOptimizeTargets = (
return targets;
}

if (unit.canCapture(map.getPlayer(unit))) {
if (unit.canCapture(map.maybeGetPlayer(unit) || null)) {
const sortedTargets = sortBy(
targets.map((vector) => radius.get(vector)).filter(isPresent),
minByCost,
Expand Down
2 changes: 1 addition & 1 deletion dionysus/lib/shouldCaptureBuilding.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export default function shouldCaptureBuilding(
return (
!maybeUnit ||
(!map.matchesPlayer(maybeUnit, building) &&
!maybeUnit.canCapture(map.getPlayer(maybeUnit)))
!maybeUnit.canCapture(map.maybeGetPlayer(maybeUnit) || null))
);
}

Expand Down

0 comments on commit 298837b

Please sign in to comment.