The problem is a lot of aircraft don't specify ICAO type or airline necessarily (ICAO type should be in atc_type field in config files but it's not always correct or filled in). Descriptions rarely include it either, or not as ICAO (like "B737-800" or "Delta Boeing 737-800" instead of "B738"). Sooooo... we first need to scan the installed aircraft and figure out what ICAO type it is (required field) and what ICAO airline it appears to be (optional, only if airline ICAO or name is listed in description). Then we build a "Matching List" which for every possible ICAO type (at least majority used on VATSIM) it either points to the installed aircraft of that ICAO type, or points to another installed aircraft with the closest physical match to that ICAO type.
Basic algorithm:
Have Aircraft database of 95% most common VATSIM aircraft with size (either wingspan or length?), high/low wing, jet/prop, number of engines, wing-or-tail-engine-mount flag, ICAO type, type description (e.g. B738 would be "737-800" to hopefully match with either "B737-800" or "Boeing 737-800" or "Delta 737-800" in installed aircraft description fields).
Have Airline database with most common airlines (name and ICAO)
On startup: parse installed a/c config files and put in Installed Aircraft memory database: size (front and back contact points), wing high/low (left/rightmost contact points height compared to viewpoint?), jet/prop, number of engines, wing-or-tail-mount (wing contact points compared to engine positions), description, and atc_type fields. Scan description field for match with airlines database (both name and ICAO) to determine ICAO airline, else leave blank. Scan description field and atc_type for match with Aircraft database to determine ICAO type. If not found, find closest aircraft in database to this aircraft's characteristics and put that as ICAO type. Check for ICAO type duplicates in Installed Aircraft database and chain the same type together (1 entry with different liveries). Check ICAO assignment override file for user-specified and re-assign those. Lastly create Matching list showing all ICAO types in aircraft database, plus user additions file. For each line in list, search Installed Aircraft database for that ICAO type. If not found, find closest installed aircraft/chain to this ICAO aircraft's physical characteristics and use that for the "matches to" field. Matching list is stored in memory for user editing, adding to (saved in additions file) and overriding (saved in override file). User can also edit Installed Aircraft ICAO field to override our derived ICAO type for each installed aircraft (saved in ICAO assignment override file).
Note: "closest physical match" is fuzzy, weighted score. For small prop aircraft probably high/low wing is highest, size second, #engines third. For jets, size probably first then wing/tail engine mount, then # engines. A DC-10 should match to an installed 747, not an installed 727 (despite same # engines and tail mount); An ATR-72 should match to an installed MD80 over a King Air, but should match to an installed DC-3 over an MD80. Whole thing probably doesn't matter much since user can override odd pairings.
In GetBestModelForAircraftType: given ICAO type and optional airline, search Matching list for that ICAO type. If not found, use default a/c. If found, get corresponding installed aircraft name/chain if more than one. Search through chain for exact ICAO airline. If found, use that, else pick randomly from within chain. If ICAO type not found in Matching list, use default aircraft.
The problem is a lot of aircraft don't specify ICAO type or airline necessarily (ICAO type should be in atc_type field in config files but it's not always correct or filled in). Descriptions rarely include it either, or not as ICAO (like "B737-800" or "Delta Boeing 737-800" instead of "B738"). Sooooo... we first need to scan the installed aircraft and figure out what ICAO type it is (required field) and what ICAO airline it appears to be (optional, only if airline ICAO or name is listed in description). Then we build a "Matching List" which for every possible ICAO type (at least majority used on VATSIM) it either points to the installed aircraft of that ICAO type, or points to another installed aircraft with the closest physical match to that ICAO type.
Basic algorithm:
Have Aircraft database of 95% most common VATSIM aircraft with size (either wingspan or length?), high/low wing, jet/prop, number of engines, wing-or-tail-engine-mount flag, ICAO type, type description (e.g. B738 would be "737-800" to hopefully match with either "B737-800" or "Boeing 737-800" or "Delta 737-800" in installed aircraft description fields).
Have Airline database with most common airlines (name and ICAO)
On startup: parse installed a/c config files and put in Installed Aircraft memory database: size (front and back contact points), wing high/low (left/rightmost contact points height compared to viewpoint?), jet/prop, number of engines, wing-or-tail-mount (wing contact points compared to engine positions), description, and atc_type fields. Scan description field for match with airlines database (both name and ICAO) to determine ICAO airline, else leave blank. Scan description field and atc_type for match with Aircraft database to determine ICAO type. If not found, find closest aircraft in database to this aircraft's characteristics and put that as ICAO type. Check for ICAO type duplicates in Installed Aircraft database and chain the same type together (1 entry with different liveries). Check ICAO assignment override file for user-specified and re-assign those. Lastly create Matching list showing all ICAO types in aircraft database, plus user additions file. For each line in list, search Installed Aircraft database for that ICAO type. If not found, find closest installed aircraft/chain to this ICAO aircraft's physical characteristics and use that for the "matches to" field. Matching list is stored in memory for user editing, adding to (saved in additions file) and overriding (saved in override file). User can also edit Installed Aircraft ICAO field to override our derived ICAO type for each installed aircraft (saved in ICAO assignment override file).
Note: "closest physical match" is fuzzy, weighted score. For small prop aircraft probably high/low wing is highest, size second, #engines third. For jets, size probably first then wing/tail engine mount, then # engines. A DC-10 should match to an installed 747, not an installed 727 (despite same # engines and tail mount); An ATR-72 should match to an installed MD80 over a King Air, but should match to an installed DC-3 over an MD80. Whole thing probably doesn't matter much since user can override odd pairings.