Yankes, are you planning to enable displaying several crafts per hangar as well?
Right now I do not write any code that would do this, but overall functionality have explicit link between crafts and hangars.
Again, this is about being able to assign actual craft and hangar sizes/types, not about buildings.
Low level testing, I even do not run game once, probably over moth of coding without any tests. And I know first report: "game crash" and this will not help much.
Would this still be a problem if the sizes are exclusive? As in, only one size can be assigned per craft/hangar?
Default/vanillar hangar or non-defined size defaults to 1, number of free slots per hangar also defaults to 1 if not assigned to not break compatibility. Check the largest hangar size and max. number of total hangar slots per size, create an array with 1:[largest size] lines and 1:[max. hangar slots] columns. Write a 1 for every free slot per size. The sum of the array gives you your total slots.
Do the same for the crafts. Pad both arrays accordingly. Substract the craft array from the hangar array. The sum of the resulting array is your (total) free hangar space. Check the sums of the individual line vectors. If any of those are 0 or negative there is no free space for that type of craft.
Disclaimer: Above is (a probably overcomplicated way of) how i would implement this in matlab. I'm very bad at matlab and have no idea how this should actually be implemented.
You could always allow multiple sizes later on, but i for one would be happy to even be able to assign one type of size per craft/hangar. I think having multiple sizes per hangar while also having multiple slots per hangar might be overly complicated, at least for an initial implementation.
First of all, I paned that each hangar can store selected types of crafts, and this can overlap with other hangars. This mean one hangar can be used to store A, B or C, another can store A or B, and last hangar only B. Now depending order in with you allocate you can end up with free hangars and not allocated crafts.
e.g. first get craft A, second B and last one cant fit C because only allow B. And now consider that you have 16 hangars and 16 crafts with different types.
Over all I write already algorithm that should solve this in some effective manner but it need lot of testing to fix all corner cases.
For any one interested WIP branch:
https://github.com/Yankes/OpenXcom/commit/08bc53208f0e9dabdfccc323f5c6ac1a4c826bf9