yairm210 / Unciv

Open-source Android/Desktop remake of Civ V
Mozilla Public License 2.0
8.49k stars 1.57k forks source link

`Never appears as a Barbarian unit` does not work for Unit type #9135

Closed marek22k closed 8 months ago

marek22k commented 1 year ago

UnCiv Version: 4.5.16-patch1

Hello,

I am creating a mod and I noticed that the Unique Never appears as a Barbarian unit does not work for Unit type. Units of this type still appear as barbarian. Someone else on Discord could observe the same thing.

SomeTroglodyte commented 1 year ago

True, uniques from different sources are only "assembled" for MapUnits, not for BaseUnits. Seems it was never intendend that uniques on UnitTypes could be in effect before an actual unit exists.

SomeTroglodyte commented 1 year ago

@yairm210 - architectural questions...

just an idea // Can not be a hashset as that would remove doubles // I bet there's a way of initializing these without having to override it everywhere... val uniqueObjects: List // MUST - WIN - BET fun uniqueObjectsInitializer() = lazy { if (uniques.isEmpty()) emptyList() else uniques.map { Unique(it, getUniqueTarget(), (this as? INamed)?.name } } } abstract class RulesetObject: IRulesetObject { @Suppress("LeakingThis") @delegate:Transient override val uniqueObjects: List by uniqueObjectsInitializer() } ```

... works (same for UniqueMap), but raises other questions. I might have forgotten or missed the design discussions, so feel free to ignore.

SomeTroglodyte commented 1 year ago
... ```kotlin class UniqueMap(): HashMap>() { constructor(uniqueObjects: Iterable) : this() { addUniques(uniqueObjects) } ... abstract class RulesetObject: IRulesetObject { @delegate:Transient override val uniqueMap: UniqueMap by lazy { UniqueMap(uniqueObjects) } ... ```

... another way to prettify that part of the hierarchy, sacrificing a tiny shortcut (not triggering the uniqueObjects lazy if uniques is empty - will trigger soon enough anyway?)?