Skip to content
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
14 changes: 9 additions & 5 deletions src/components/game/BattleSimulatorPanel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,12 @@ export const BattleSimulatorPanel = memo(function BattleSimulatorPanel() {
// Collect units by team and compute team center positions
const player1Units: number[] = [];
const player2Units: number[] = [];
let p1SumX = 0, p1SumY = 0, p1Count = 0;
let p2SumX = 0, p2SumY = 0, p2Count = 0;
let p1SumX = 0,
p1SumY = 0,
p1Count = 0;
let p2SumX = 0,
p2SumY = 0,
p2Count = 0;

const entities = worldAdapter.getEntitiesWith('Unit', 'Selectable', 'Transform', 'Health');

Expand Down Expand Up @@ -136,12 +140,12 @@ export const BattleSimulatorPanel = memo(function BattleSimulatorPanel() {
const player2Center = p2Count > 0 ? { x: p2SumX / p2Count, y: p2SumY / p2Count } : null;

// Issue attack-move commands to each team toward the enemy center
// Attack-move triggers assault mode: units continuously seek and engage enemies
// ATTACK_MOVE routes to MovementOrchestrator which handles both pathfinding and combat
if (player1Units.length > 0 && player2Center) {
const command: GameCommand = {
tick: currentTick,
playerId: 'player1',
type: 'ATTACK',
type: 'ATTACK_MOVE',
entityIds: player1Units,
targetPosition: player2Center,
};
Expand All @@ -152,7 +156,7 @@ export const BattleSimulatorPanel = memo(function BattleSimulatorPanel() {
const command: GameCommand = {
tick: currentTick,
playerId: 'player2',
type: 'ATTACK',
type: 'ATTACK_MOVE',
entityIds: player2Units,
targetPosition: player1Center,
};
Expand Down
14 changes: 9 additions & 5 deletions src/engine/ai/UnitBehaviors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,8 @@ function getNearestEnemy(
for (const id of nearbyIds) {
if (id === ctx.entityId) continue;

const enemy = ctx.world.getEntity(id);
// SpatialGrid returns entity indices, use getEntityByIndex for lookup
const enemy = ctx.world.getEntityByIndex(id);
if (!enemy) continue;

const enemySelectable = enemy.get<Selectable>('Selectable');
Expand All @@ -99,7 +100,7 @@ function getNearestEnemy(
if (dist < nearestDist) {
nearestDist = dist;
nearest = {
entityId: id,
entityId: enemy.id,
distance: dist,
transform: enemyTransform,
unit: enemyUnit,
Expand Down Expand Up @@ -127,7 +128,8 @@ function calculateThreatScore(ctx: BehaviorContext): number {
for (const id of nearbyIds) {
if (id === ctx.entityId) continue;

const enemy = ctx.world.getEntity(id);
// SpatialGrid returns entity indices, use getEntityByIndex for lookup
const enemy = ctx.world.getEntityByIndex(id);
if (!enemy) continue;

const enemySelectable = enemy.get<Selectable>('Selectable');
Expand Down Expand Up @@ -263,7 +265,8 @@ export function hasMeleeThreatClose(ctx: BehaviorContext): boolean {
for (const id of nearbyIds) {
if (id === ctx.entityId) continue;

const enemy = ctx.world.getEntity(id);
// SpatialGrid returns entity indices, use getEntityByIndex for lookup
const enemy = ctx.world.getEntityByIndex(id);
if (!enemy) continue;

const enemySelectable = enemy.get<Selectable>('Selectable');
Expand Down Expand Up @@ -383,7 +386,8 @@ export const kiteFromMelee = action('KiteFromMelee', (ctx) => {
for (const id of nearbyIds) {
if (id === ctx.entityId) continue;

const enemy = ctx.world.getEntity(id);
// SpatialGrid returns entity indices, use getEntityByIndex for lookup
const enemy = ctx.world.getEntityByIndex(id);
if (!enemy) continue;

const enemySelectable = enemy.get<Selectable>('Selectable');
Expand Down
20 changes: 12 additions & 8 deletions src/engine/combat/TargetAcquisition.ts
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,8 @@ export function findBestTarget(world: World, options: TargetQueryOptions): Targe
continue;
}

const entity = world.getEntity(entityId);
// SpatialGrid returns entity indices, use getEntityByIndex for lookup
const entity = world.getEntityByIndex(entityId);
if (!entity) continue;

const transform = entity.get<Transform>('Transform');
Expand Down Expand Up @@ -190,7 +191,7 @@ export function findBestTarget(world: World, options: TargetQueryOptions): Targe
);

if (!bestTarget || score > bestTarget.score) {
bestTarget = { entityId, score, distance, isBuilding: false };
bestTarget = { entityId: entity.id, score, distance, isBuilding: false };
}
}

Expand All @@ -203,7 +204,8 @@ export function findBestTarget(world: World, options: TargetQueryOptions): Targe
continue;
}

const entity = world.getEntity(entityId);
// SpatialGrid returns entity indices, use getEntityByIndex for lookup
const entity = world.getEntityByIndex(entityId);
if (!entity) continue;

const transform = entity.get<Transform>('Transform');
Expand Down Expand Up @@ -241,7 +243,7 @@ export function findBestTarget(world: World, options: TargetQueryOptions): Targe
);

if (!bestTarget || score > bestTarget.score) {
bestTarget = { entityId, score, distance, isBuilding: true };
bestTarget = { entityId: entity.id, score, distance, isBuilding: true };
}
}
}
Expand Down Expand Up @@ -280,7 +282,8 @@ export function findAllTargets(
continue;
}

const entity = world.getEntity(entityId);
// SpatialGrid returns entity indices, use getEntityByIndex for lookup
const entity = world.getEntityByIndex(entityId);
if (!entity) continue;

const transform = entity.get<Transform>('Transform');
Expand Down Expand Up @@ -322,7 +325,7 @@ export function findAllTargets(
config
);

targets.push({ entityId, score, distance, isBuilding: false });
targets.push({ entityId: entity.id, score, distance, isBuilding: false });
}

// Query buildings
Expand All @@ -334,7 +337,8 @@ export function findAllTargets(
continue;
}

const entity = world.getEntity(entityId);
// SpatialGrid returns entity indices, use getEntityByIndex for lookup
const entity = world.getEntityByIndex(entityId);
if (!entity) continue;

const transform = entity.get<Transform>('Transform');
Expand Down Expand Up @@ -376,7 +380,7 @@ export function findAllTargets(
config
);

targets.push({ entityId, score, distance, isBuilding: true });
targets.push({ entityId: entity.id, score, distance, isBuilding: true });
}
}

Expand Down
6 changes: 4 additions & 2 deletions src/engine/systems/AIMicroSystem.ts
Original file line number Diff line number Diff line change
Expand Up @@ -668,7 +668,8 @@ export class AIMicroSystem extends System {
for (const nearbyId of nearbyUnits) {
if (nearbyId === entityId) continue;

const nearbyEntity = this.world.getEntity(nearbyId);
// SpatialGrid returns entity indices, use getEntityByIndex for lookup
const nearbyEntity = this.world.getEntityByIndex(nearbyId);
if (!nearbyEntity) continue;

const nearbyUnit = nearbyEntity.get<Unit>('Unit');
Expand Down Expand Up @@ -823,7 +824,8 @@ export class AIMicroSystem extends System {
for (const nearbyId of nearbyUnits) {
if (nearbyId === entityId) continue;

const nearbyEntity = this.world.getEntity(nearbyId);
// SpatialGrid returns entity indices, use getEntityByIndex for lookup
const nearbyEntity = this.world.getEntityByIndex(nearbyId);
if (!nearbyEntity) continue;

const nearbyUnit = nearbyEntity.get<Unit>('Unit');
Expand Down
9 changes: 6 additions & 3 deletions src/engine/systems/CombatSystem.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1163,7 +1163,8 @@ export class CombatSystem extends System {
);

for (const entityId of nearbyBuildingIds) {
const entity = this.world.getEntity(entityId);
// SpatialGrid returns entity indices, use getEntityByIndex for lookup
const entity = this.world.getEntityByIndex(entityId);
if (!validateEntityAlive(entity, entityId, 'CombatSystem:checkCombatZone:buildings'))
continue;

Expand Down Expand Up @@ -1552,7 +1553,8 @@ export class CombatSystem extends System {
for (const entityId of nearbyUnitIds) {
if (entityId === attackerId) continue;

const entity = this.world.getEntity(entityId);
// SpatialGrid returns entity indices, use getEntityByIndex for lookup
const entity = this.world.getEntityByIndex(entityId);
if (!validateEntityAlive(entity, entityId, 'CombatSystem:applySplashDamage:units')) continue;

const transform = entity.get<Transform>('Transform');
Expand Down Expand Up @@ -1610,7 +1612,8 @@ export class CombatSystem extends System {
);

for (const entityId of nearbyBuildingIds) {
const entity = this.world.getEntity(entityId);
// SpatialGrid returns entity indices, use getEntityByIndex for lookup
const entity = this.world.getEntityByIndex(entityId);
if (!validateEntityAlive(entity, entityId, 'CombatSystem:applySplashDamage:buildings'))
continue;

Expand Down
6 changes: 4 additions & 2 deletions src/engine/systems/ProjectileSystem.ts
Original file line number Diff line number Diff line change
Expand Up @@ -372,7 +372,8 @@ export class ProjectileSystem extends System {
// Skip primary target (already damaged)
if (entityId === projectile.targetEntityId) continue;

const entity = this.world.getEntity(entityId);
// SpatialGrid returns entity indices, use getEntityByIndex for lookup
const entity = this.world.getEntityByIndex(entityId);
if (!validateEntityAlive(entity, entityId, 'ProjectileSystem:applySplashDamage:units'))
continue;

Expand Down Expand Up @@ -449,7 +450,8 @@ export class ProjectileSystem extends System {
for (const entityId of nearbyBuildingIds) {
if (entityId === projectile.targetEntityId) continue;

const entity = this.world.getEntity(entityId);
// SpatialGrid returns entity indices, use getEntityByIndex for lookup
const entity = this.world.getEntityByIndex(entityId);
if (!validateEntityAlive(entity, entityId, 'ProjectileSystem:applySplashDamage:buildings'))
continue;

Expand Down
Loading
Loading