aliens

Author Topic: [SUGGESTION]Custom Hangar/Craft types  (Read 6350 times)

Offline 0xEBJC

  • Colonel
  • ****
  • Posts: 180
  • Y'all are awesome! Thankful for this community.
    • View Profile
    • My Projects
Re: [SUGGESTION]Custom Hangar/Craft types
« Reply #30 on: February 21, 2024, 12:36:26 am »
I have already said in this thread that I don't need help with the implementation of this feature.

Reviewing your code, learning how it works, changing it to my liking and testing it will take me longer than doing everything myself.

It's a valiant effort, but this is a critical feature that I want to do right and want to understand every detail so that I can support it long-term.

Please don't send pull-requests, they will just be closed.

I just posted a new Facility Expansion Pack Mod that has custom hangar facilities using BRUTAL-AI currently until when you release your version into the main OXCE branch.

One suggestion for your consideration when you look at implementing this would be to have an option for a default hangar to accept any crafts. 

For example if:
   hangerType: 1 = (cars)
   hangerType: 0 = (Aircrafts)

Then have the option for something like:
   hangerType: -1 = (anything)

Example scenario:
   All automobiles = craftType: 1
   Garage = hangarType: 1

   All Aircrafts = craftType: 0
   Hangar = hangarType: -1

That way a hangar can store both aircrafts and automobiles, but a garage can only store automobiles.  Then the logic would check if there is a hangarType and craftType match first, then a craftType to universal hangarType second when determining facility space available.  The crafts would always count against the matching hangarType first before a universal one.  So if you had 2 cars, 1 garage and 1 hangar (with hangarType: -1) and one of the cars was sold, then the second car would be counted against the garage first so that any craft could be placed into the hangar.


Currently, the implementation in BRUTAL-AI has explicit matches both craftType and hangarType have to match so an automobile could not be placed into a hangar.

 

Offline Flaubert

  • Sergeant
  • **
  • Posts: 38
    • View Profile
Re: [SUGGESTION]Custom Hangar/Craft types
« Reply #31 on: February 21, 2024, 10:10:57 am »
My implementation of Hangar mods, had this "-1" wildcard already. If rules for crafts didn't have an entry for hangar type, they were automatically assigned a "-1" Id, which corresponds with the default id for vanilla hangar.
This way my OXCE engine version didn't break mods made for official OXCE+ branch.
I'm sure Meridian has special care with compatibility for previous mods, so probably he has in mind a similar mechanism.

Offline 0xEBJC

  • Colonel
  • ****
  • Posts: 180
  • Y'all are awesome! Thankful for this community.
    • View Profile
    • My Projects
Re: [SUGGESTION]Custom Hangar/Craft types
« Reply #32 on: March 25, 2024, 05:38:47 pm »
My implementation of Hangar mods, had this "-1" wildcard already. If rules for crafts didn't have an entry for hangar type, they were automatically assigned a "-1" Id, which corresponds with the default id for vanilla hangar.
This way my OXCE engine version didn't break mods made for official OXCE+ branch.
I'm sure Meridian has special care with compatibility for previous mods, so probably he has in mind a similar mechanism.

First I just want to say thank you! for implementing this as a short term solution! I really appreciate all your work!

The capability I'm looking for is if I have a hangar type -1 (the original 2x2 hangar), automobiles are craft type 1 and aircrafts are craft type 0, I want both to be able be able to go into (the original 2x2 hangar) with a hangar type -1, and if I have a different hangar that is hangar type 0 then only aircrafts could go in there and not automobiles and hangarType 1 only automobiles.  Currently the issues I'm having is where I have a hangar type -1 (the original 2x2 hangar), then I have to set aircrafts to craftType -1 for them to be stored there, if I set aircrafts to craftType 0 then they won't go into hangarType -1.

The code implementation I think would work would be to crate a sum of hayngar types and crafts types

Example:
Garage               = (size 1x1) capacity (1) hangarType (1)
Original Hangar   = (size 2x2) capacity (1) hangarType (-1)
Aerodock            = (size 2x2) capacity (3) hangarType (0)

Base has (0 crafts), (2 garages), (1 original hangar)
Space:
  hangarType 0  = (1 spaces)
  hangarType 1  = (2 spaces)
  hangarType -1 = (1 spaces)

1.) add craftType 1,
       - check hangarType 1 spaces available,
       - if available then count against hangerType 1
       - if no spaces left in hangarType 1, then check if hangarType -1 spaces available
       - if available then count against hangarType -1
       - if no spaces left in hangarType -1, then present GUI error "no craft spaces available"
 2.) add craftType 0
       - check hangarType 0 spaces available,
       - if available then count against hangerType 0
       - if no spaces left in hangarType 1, then check if hangarType -1 spaces available
       - if available then count against hangarType -1
       - if no spaces left in hangarType -1, then present GUI error "no craft spaces available"
follow this same logic for additional hangar types, you's also have to key track of what crafts types are stored in hangar type -1,
for example base has hangarType -1 (space available = 3)
1.) store craftType 0 in hangarType -1,             hangarType -1 (stored spaces = craftTypes [{0, 1}]
     next store craftType 1 in hangar type -1,     hangarType -1 (stored spaces = craftTypes [{0, 1}, {1, 1}]
     next store craftType 0,                               hangarType -1 (stored spaces = craftTypes [{0, 2}, {1, 1}]

when removing crafts from the base, sell or transfer, logic would always check hangerType -1 first and remove the craft from that hangar 1st before removing craftType 0 from hangarType 0 where 2 craftType 0 are being stored, one in hangarType 0, and one in hangarType -1

For backwards compatibility would be that if a hangarType is unspecified for a hangar then it's -1, and if a craftType for a craft isn't specified, then it's -1, and craftType -1 can only go into hangarType -1.


Related Posts
------------------------------
https://openxcom.org/forum/index.php/topic,11590.0.html
« Last Edit: March 25, 2024, 06:49:54 pm by 0xEBJC »

Offline WarStalkeR

  • Sergeant
  • **
  • Posts: 42
  • Repensum Est Canicula
    • View Profile
Re: [SUGGESTION]Custom Hangar/Craft types
« Reply #33 on: April 04, 2024, 08:12:48 pm »
The code implementation I think would work would be to crate a sum of hangar types and crafts types

Example:
Garage               = (size 1x1) capacity (1) hangarType (1)
Original Hangar   = (size 2x2) capacity (1) hangarType (-1)
Aerodock            = (size 2x2) capacity (3) hangarType (0)

Base has (0 crafts), (2 garages), (1 original hangar)
This implementation has one big issue: sorting and allocation. Lets assume that your two hangars. One allows types {0,1,2,3} and another allows types {0,1,3,4} and here you encounter issue - which craft type should be placed first? Basically, you might end up with issue: you've bough type 3 craft and it was placed in first hangar, the second hangar is still empty. And if you're trying to buy type 2 craft, you can't because the only compatible hangar is occupied, whilst 2nd hangar is unused.

In my case, to avoid this issue, I implemented craft size parameter, allowed granulation of craft size ranges to a craft class and only then implemented multi-craft hangars support that rely on craft size to sort crafts via heuristic approach into craft slots provided by hangars.

You can take a look at my approach here:
https://github.com/WarStalkeR/OpenXcomExMore/commit/41d4bd5395ad8327cda2008c4da191300bbba3ef
https://github.com/WarStalkeR/OpenXcomExMore/commit/7a661b2b5fea8a13a2fa4b738206f76ebe48b897

Offline 0xEBJC

  • Colonel
  • ****
  • Posts: 180
  • Y'all are awesome! Thankful for this community.
    • View Profile
    • My Projects
Re: [SUGGESTION]Custom Hangar/Craft types
« Reply #34 on: April 05, 2024, 01:54:55 am »
This implementation has one big issue: sorting and allocation. Lets assume that your two hangars. One allows types {0,1,2,3} and another allows types {0,1,3,4} and here you encounter issue - which craft type should be placed first? Basically, you might end up with issue: you've bough type 3 craft and it was placed in first hangar, the second hangar is still empty. And if you're trying to buy type 2 craft, you can't because the only compatible hangar is occupied, whilst 2nd hangar is unused.

In my case, to avoid this issue, I implemented craft size parameter, allowed granulation of craft size ranges to a craft class and only then implemented multi-craft hangars support that rely on craft size to sort crafts via heuristic approach into craft slots provided by hangars.

You can take a look at my approach here:
https://github.com/WarStalkeR/OpenXcomExMore/commit/41d4bd5395ad8327cda2008c4da191300bbba3ef
https://github.com/WarStalkeR/OpenXcomExMore/commit/7a661b2b5fea8a13a2fa4b738206f76ebe48b897

I see your point.

I was thinking that when adding a new craft, the logic would check total available slots and move crafts accordingly if needed to other hangars automatically, so if a crafttype 3 was in one specific hangar and blocked another craft then crafttype 3 would just be moved to the other hangar.


i'll look at your PR and see what your approach looks like