* Company \a company accepts engine \a eid for preview. * @param eid Engine being accepted (is under preview). * @param company Current company previewing the engine. * @param recursion_depth Recursion depth to avoid infinite loop. */
| 880 | * @param recursion_depth Recursion depth to avoid infinite loop. |
| 881 | */ |
| 882 | static void AcceptEnginePreview(EngineID eid, CompanyID company, int recursion_depth = 0) |
| 883 | { |
| 884 | Engine *e = Engine::Get(eid); |
| 885 | |
| 886 | e->preview_company = CompanyID::Invalid(); |
| 887 | e->preview_asked.Set(); |
| 888 | |
| 889 | EnableEngineForCompany(eid, company); |
| 890 | |
| 891 | /* Notify preview window, that it might want to close. |
| 892 | * Note: We cannot directly close the window. |
| 893 | * In singleplayer this function is called from the preview window, so |
| 894 | * we have to use the GUI-scope scheduling of InvalidateWindowData. |
| 895 | */ |
| 896 | InvalidateWindowData(WC_ENGINE_PREVIEW, eid); |
| 897 | |
| 898 | /* Don't search for variants to include if we are 10 levels deep already. */ |
| 899 | if (recursion_depth >= 10) return; |
| 900 | |
| 901 | /* Find variants to be included in preview. */ |
| 902 | for (Engine *ve : Engine::IterateType(e->type)) { |
| 903 | if (ve->index != eid && ve->info.variant_id == eid && ve->info.extra_flags.Test(ExtraEngineFlag::JoinPreview)) { |
| 904 | AcceptEnginePreview(ve->index, company, recursion_depth + 1); |
| 905 | } |
| 906 | } |
| 907 | } |
| 908 | |
| 909 | /** |
| 910 | * Get the best company for an engine preview. |
no test coverage detected