nkzw-tech / athena-crisis

Athena Crisis is a modern-retro turn-based tactical strategy game. Athena Crisis is open core technology.
https://athenacrisis.com/open-source
Other
1.54k stars 116 forks source link

Fix unit placement for a different team in map editor #28

Closed sookmax closed 4 months ago

sookmax commented 4 months ago

Closes https://github.com/nkzw-tech/athena-crisis/issues/27

The root cause of this issue was the Array.slice() operation below:

const players = Array.from(
      new Set([...state.map.active, ...PlayerIDs.filter((id) => id !== 0)]),
).slice(0, vectors.length);

So when vectors is of length 1 (i.e., no mirroring / single player placement), the remainder operation (%) below always produces an index 0 (anything is divisible by 1, so n % 1 = 0 for any n):

const playerId =
    players[
      ((currentPlayerIndex >= 0 ? currentPlayerIndex : 0) + index) %
        players.length
    ];

By removing the slice() operation above and keeping players as [1,2,3,4,5,6,7] all the time, multiple-player selection logic is much simpler as well.

For example,

Single player placement

https://github.com/nkzw-tech/athena-crisis/assets/71210554/4fda8ded-328b-4df2-80d9-d6eb18d75983

Multiple player (4) placement

https://github.com/nkzw-tech/athena-crisis/assets/71210554/c8fe864f-ba05-4350-9880-289f781be49f

cpojer commented 4 months ago

Thank you for reporting and fixing the issue! I put a bounty of it, and the funds were sent to you.

sookmax commented 4 months ago

Hey you didn't have to put a bounty on this one but thank you!