MCPcopy Create free account
hub / github.com/OpenTTD/OpenTTD / AcceptEnginePreview

Function AcceptEnginePreview

src/engine.cpp:882–907  ·  view source on GitHub ↗

* 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. */

Source from the content-addressed store, hash-verified

880 * @param recursion_depth Recursion depth to avoid infinite loop.
881 */
882static 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.

Callers 1

CmdWantEnginePreviewFunction · 0.85

Calls 5

InvalidFunction · 0.85
EnableEngineForCompanyFunction · 0.85
TestMethod · 0.80
InvalidateWindowDataFunction · 0.70
SetMethod · 0.45

Tested by

no test coverage detected