From 5d4ece62d0d5e430f5789ff2c9e2e57837d4d6c8 Mon Sep 17 00:00:00 2001 From: Anuken Date: Sun, 13 Oct 2024 23:16:44 -0400 Subject: [PATCH] Researched list is now UnlockableContent --- core/src/mindustry/core/Logic.java | 2 +- .../mindustry/ctype/UnlockableContent.java | 21 +++++++++++-------- core/src/mindustry/game/Rules.java | 3 ++- core/src/mindustry/net/NetworkIO.java | 2 +- 4 files changed, 16 insertions(+), 12 deletions(-) diff --git a/core/src/mindustry/core/Logic.java b/core/src/mindustry/core/Logic.java index bbf4d7f3ed..c6e39cf0ff 100644 --- a/core/src/mindustry/core/Logic.java +++ b/core/src/mindustry/core/Logic.java @@ -395,7 +395,7 @@ public class Logic implements ApplicationListener{ if(!(content instanceof UnlockableContent u)) return; boolean was = u.unlockedNow(); - state.rules.researched.add(u.name); + state.rules.researched.add(u); if(!was){ Events.fire(new UnlockEvent(u)); diff --git a/core/src/mindustry/ctype/UnlockableContent.java b/core/src/mindustry/ctype/UnlockableContent.java index d1bb37fc6a..c4ed0bf708 100644 --- a/core/src/mindustry/ctype/UnlockableContent.java +++ b/core/src/mindustry/ctype/UnlockableContent.java @@ -222,17 +222,25 @@ public abstract class UnlockableContent extends MappableContent{ } } - /** @return in multiplayer, whether this is unlocked for the host player, otherwise, whether it is unlocked for the local player (same as unlocked()) */ public boolean unlockedNowHost(){ - if(!state.isCampaign()) return true; + return !state.isCampaign() || unlockedHost(); + } + + /** @return in multiplayer, whether this is unlocked for the host player, otherwise, whether it is unlocked for the local player (same as unlocked()) */ + public boolean unlockedHost(){ return net != null && net.client() ? - alwaysUnlocked || state.rules.researched.contains(name) : + alwaysUnlocked || state.rules.researched.contains(this) : unlocked || alwaysUnlocked; } + /** @return whether this content is unlocked, or the player is in a custom (non-campaign) game. */ + public boolean unlockedNow(){ + return unlocked() || !state.isCampaign(); + } + public boolean unlocked(){ return net != null && net.client() ? - alwaysUnlocked || unlocked || state.rules.researched.contains(name) : + alwaysUnlocked || unlocked || state.rules.researched.contains(this) : unlocked || alwaysUnlocked; } @@ -244,11 +252,6 @@ public abstract class UnlockableContent extends MappableContent{ } } - /** @return whether this content is unlocked, or the player is in a custom (non-campaign) game. */ - public boolean unlockedNow(){ - return unlocked() || !state.isCampaign(); - } - public boolean locked(){ return !unlocked(); } diff --git a/core/src/mindustry/game/Rules.java b/core/src/mindustry/game/Rules.java index 37632948b0..f2b940154c 100644 --- a/core/src/mindustry/game/Rules.java +++ b/core/src/mindustry/game/Rules.java @@ -7,6 +7,7 @@ import arc.util.serialization.*; import arc.util.serialization.Json.*; import mindustry.*; import mindustry.content.*; +import mindustry.ctype.*; import mindustry.graphics.g3d.*; import mindustry.io.*; import mindustry.type.*; @@ -160,7 +161,7 @@ public class Rules{ /** Reveals blocks normally hidden by build visibility. */ public ObjectSet revealedBlocks = new ObjectSet<>(); /** Unlocked content names. Only used in multiplayer when the campaign is enabled. */ - public ObjectSet researched = new ObjectSet<>(); + public ObjectSet researched = new ObjectSet<>(); /** In-map objective executor. */ public MapObjectives objectives = new MapObjectives(); /** Flags set by objectives. Used in world processors. */ diff --git a/core/src/mindustry/net/NetworkIO.java b/core/src/mindustry/net/NetworkIO.java index 48599c6b96..3dac108090 100644 --- a/core/src/mindustry/net/NetworkIO.java +++ b/core/src/mindustry/net/NetworkIO.java @@ -30,7 +30,7 @@ public class NetworkIO{ for(ContentType type : ContentType.all){ for(Content c : content.getBy(type)){ if(c instanceof UnlockableContent u && u.unlocked() && u.techNode != null){ - state.rules.researched.add(u.name); + state.rules.researched.add(u); } } }