diff --git a/src/main/kotlin/ru/dbotthepony/mc/otm/android/AndroidResearch.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/android/AndroidResearch.kt index 4181a4705..8846050e8 100644 --- a/src/main/kotlin/ru/dbotthepony/mc/otm/android/AndroidResearch.kt +++ b/src/main/kotlin/ru/dbotthepony/mc/otm/android/AndroidResearch.kt @@ -141,8 +141,8 @@ abstract class AndroidResearch(val type: AndroidResearchType<*>, val capability: isResearched = nbt.getBoolean("researched") } - inline val prerequisites get() = type.definedPrerequisites + inline val prerequisites get() = type.flatPrerequisites inline val unlocks get() = type.flatUnlocks - inline val blockedBy get() = type.definedBlockedBy + inline val blockedBy get() = type.flatBlockedBy inline val blocking get() = type.flatBlocking } diff --git a/src/main/kotlin/ru/dbotthepony/mc/otm/android/AndroidResearchBuilder.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/android/AndroidResearchBuilder.kt index c81622a19..43c6b481d 100644 --- a/src/main/kotlin/ru/dbotthepony/mc/otm/android/AndroidResearchBuilder.kt +++ b/src/main/kotlin/ru/dbotthepony/mc/otm/android/AndroidResearchBuilder.kt @@ -354,7 +354,7 @@ class AndroidResearchBuilder( )) } - for (value in this.type.definedBlockedBy) { + for (value in this.type.flatBlockedBy) { builder.add(TranslatableComponent("android_research.status.blocked_by", capability.getResearch(value).screenTooltipHeader).withStyle(ChatFormatting.DARK_RED)) } diff --git a/src/main/kotlin/ru/dbotthepony/mc/otm/android/AndroidResearchType.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/android/AndroidResearchType.kt index 8ef214791..564f592d5 100644 --- a/src/main/kotlin/ru/dbotthepony/mc/otm/android/AndroidResearchType.kt +++ b/src/main/kotlin/ru/dbotthepony/mc/otm/android/AndroidResearchType.kt @@ -132,7 +132,7 @@ open class AndroidResearchType( /** * Prerequisites as-is. * - * Please avoid having more than one prerequisite as this case don't have proper research tree + * Please avoid having more than one prerequisite, as this case doesn't have proper research tree * rendering code (yet). */ open val definedPrerequisites: List> get() = emptyList() @@ -217,6 +217,42 @@ open class AndroidResearchType( ListSet(list.build()) } + /** + * Flat list of research blocking this research. + * + * This list won't contain any research blocked by this' research parents. + * + * E.g. + * + * * C depends on B + * * B is blocked by A + * * C is blocked by A + * + * Both B and C are blocked by A, but C requires B, so C's [flatBlockedBy] will not contain A, but B's will. + * + * Returns list which also doubles as set (for contains method). + */ + val flatBlockedBy: List> by lazy { + val list = ImmutableList.builder>() + + for (blocker in definedBlockedBy) { + var hit = false + + for (research in allPrerequisites) { + if (blocker in research.flatBlockedBy) { + hit = true + break + } + } + + if (!hit) { + list.add(blocker) + } + } + + ListSet(list.build()) + } + /** * All research directly unlocked by this research. *