Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implemented grid based positioning and layout handling in space battles. #1126

Merged
merged 1 commit into from
Mar 28, 2024

Conversation

hemoridos
Copy link
Contributor

The first intent of this PR was to implement pathfinding in spaceware battles, but for that I first needed to move the layout ship handling to a grid based logic so I did that instead.
Therefore some pre-work related to pathfinding also made it into this PR, most prominently a new WarUnit interface class for pathfinding objects. This class extracts some of the base functionality needed for allowing the already existing pathfinding code to be used also for space battles.

But most of the code here is related to grid handling and layouts.

The grid size is calculated by a set cell size given in pixels and how many of these cells can be fit into the battle space image. Currently that size is 26x26 pixels of the battle space, which results in a 19*38 sized grid.
If the cell size is changed, all grid based calculations will scale to the new cell sizes layouts included. This can be used for later optimizations of pathfinding or implementing different battle sizes etc.
In original IG the grid size is 18x36 and that can still be used if needed, but I found when playing with the original that all the ship layouts have an odd height and fitting them neatly was just not possible with the og grid size.

The ship layouts and their handling/usage was reworked.
First the handling of layout images/maps:
All layouts were given an extra colored dot for battleships, as in the original all battleships have pre-determined places in the layout, even if it is not showed in the icons. The parser now uses the ResearchSubCategory to differentiate between ship types.
When parsing the layouts simply the pixel locations are read and used as layout locations as-is. For this to work in a precise manner the layout images' size was reduced to 19x38 to match the grid size. These are then upscaled when drawing the layout icons in the layout selection tab.
(The layout placement positions are also scaled according to the grid size when used for ship placement, if the grid size is different than 19x38)
Some og IG layouts were adjusted a bit as some of the placements went against the pathfinding rules of the og IG(ie. battleship overlapping with cruiser areas when deploying) These are minor 1 cell movements of some placements.

The ship placements using layouts:
For placing ships the og IG object passability rules are used:

  • fighters have a size of 1x1
  • battleships 3x3
  • cruisers 3x3 with 1 cell wide overlap allowed with another cruiser typed ship.

When entering combat the layout_1 is used by default for both sides. In og IG a slight variation of that layout is used by alien fleets so it is used here as well.
(This is not usable layout by the player fleet for some reason, maybe because it only has 4 fighter placements, but who knows. It should be possible to create a layout image that represents that layout and use that for aliens as a hidden layout.)
In planetary defense the planet image size is converted to grid size and that is used as an offset to the defending fleet when applying the layout. Same goes for space stations(but this might be changed to hard coded 3*3 when pathing is implemented.)
Any planetary defense fighters are laid out together with the defending fleet if there is one nearby. If no fleet is available layout_10(wall) is used for them.
The options of fighter splitting/grouping was implemented for the player. For aliens or defending player split placement is the default.
All structures placed on the battlespace are added to a pathfinding helper map the same as in ground war. Currently this is only used for checking if a structure fits in a desired position when placing.

Other:

  • Added a debug option to show applied layout when show grid is enabled.
  • Dashed lines are used for show grid

Implemented fighter splitting grouping.
Adjusted layout maps, added new colour for battleships.
Added interface class for pathfinding units.
@rebolha
Copy link

rebolha commented Apr 22, 2024

Since this update all battleships (both sides) are positioned in the top left corner upon each other. Could you please advise?
Thanks!

@akarnokd
Copy link
Owner

Could you post a save just before the battle?

@akarnokd
Copy link
Owner

Could you also verify the game files via the launcher?

@rebolha
Copy link

rebolha commented Apr 22, 2024

save.zip
Yes, I did. Here goes the save. Many thanks!!

@akarnokd
Copy link
Owner

Strange. Works for me:

image

@rebolha
Copy link

rebolha commented Apr 22, 2024

Indeed. I tried to verify, reinstall, whatever... Still. X-file. Thank you again anyway.

@akarnokd
Copy link
Owner

Could you post a windowed screenshot of the issue?

@rebolha
Copy link

rebolha commented Apr 22, 2024

2024-04-22 18_55_25-
Here it is. Even tried a newer Java version since.

@akarnokd
Copy link
Owner

Very weird. Could you please delete any file named open-ig-images-*.zip and verify game files with the launcher again?

@rebolha
Copy link

rebolha commented Apr 22, 2024

No change. I even tried a full reinstall. Anyway special thanks for the support, I never imagined such a prompt and thorough investigation :).

@akarnokd
Copy link
Owner

Very strange. I tried with 21.0.3, still no issues.

image

@akarnokd
Copy link
Owner

akarnokd commented Apr 22, 2024

@hemoridos

This looks suss. Map.Entry reuse bug?

List<Map.Entry<Location, ResearchSubCategory>> result = new ArrayList<>(map.entrySet());

akarnokd added a commit that referenced this pull request Apr 22, 2024
@hemoridos
Copy link
Contributor Author

Looking at the screenshots posted it seems the layout images were not updated with the new ones containig battleship positions.
The fighter layout looks off too.

@hemoridos
Copy link
Contributor Author

Oh I see there was a full reinstall.
Indeed weird as the fighter placements suggest that the old images are used for some reason.

@rebolha
Copy link

rebolha commented Apr 22, 2024

It's alive!!!! Thank you guys for your help, much appreciated!! :)

@akarnokd
Copy link
Owner

It's alive!!!! Thank you guys for your help, much appreciated!! :)

What did fix it? 244, deleting the zip, verifying files?

@rebolha
Copy link

rebolha commented Apr 22, 2024

244, deleting the zip, and upgrade zip, deleting all image directories, then verification. Not sure if all were necessary.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants