From d01bc95c05ef55e56f31c9dfccdf332d606be34a Mon Sep 17 00:00:00 2001 From: Anuken Date: Wed, 5 Feb 2025 11:54:07 -0500 Subject: [PATCH] Allow team lookup --- core/src/mindustry/game/Team.java | 11 +++++++++-- core/src/mindustry/logic/GlobalVars.java | 11 ++++++++--- 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/core/src/mindustry/game/Team.java b/core/src/mindustry/game/Team.java index affcbe525c..f27f099eca 100644 --- a/core/src/mindustry/game/Team.java +++ b/core/src/mindustry/game/Team.java @@ -8,12 +8,13 @@ import arc.util.*; import mindustry.game.Rules.*; import mindustry.game.Teams.*; import mindustry.graphics.*; +import mindustry.logic.*; import mindustry.world.blocks.storage.CoreBlock.*; import mindustry.world.modules.*; import static mindustry.Vars.*; -public class Team implements Comparable{ +public class Team implements Comparable, Senseable{ public final int id; public final Color color; public final Color[] palette; @@ -138,7 +139,7 @@ public class Team implements Comparable{ public String localized(){ return Core.bundle.get("team." + name + ".name", name); } - + public String coloredName(){ return emoji + "[#" + color + "]" + localized() + "[]"; } @@ -152,4 +153,10 @@ public class Team implements Comparable{ public String toString(){ return name; } + + @Override + public double sense(LAccess sensor){ + if(sensor == LAccess.id) return id; + return 0; + } } diff --git a/core/src/mindustry/logic/GlobalVars.java b/core/src/mindustry/logic/GlobalVars.java index e1a57959cd..b4f5a59467 100644 --- a/core/src/mindustry/logic/GlobalVars.java +++ b/core/src/mindustry/logic/GlobalVars.java @@ -22,7 +22,7 @@ import static mindustry.Vars.*; /** Stores global logic variables for logic processors. */ public class GlobalVars{ public static final int ctrlProcessor = 1, ctrlPlayer = 2, ctrlCommand = 3; - public static final ContentType[] lookableContent = {ContentType.block, ContentType.unit, ContentType.item, ContentType.liquid}; + public static final ContentType[] lookableContent = {ContentType.block, ContentType.unit, ContentType.item, ContentType.liquid, ContentType.team}; /** Global random state. */ public static final Rand rand = new Rand(); @@ -220,8 +220,13 @@ public class GlobalVars{ return varEntries; } - /** @return a piece of content based on its logic ID. This is not equivalent to content ID. */ - public @Nullable Content lookupContent(ContentType type, int id){ + /** @return a piece of content based on its logic ID. This is not equivalent to content ID. In the case of teams, the return value may not be Content. */ + public @Nullable Object lookupContent(ContentType type, int id){ + //teams are a special case; they are not technically content, but can be looked up + if(type == ContentType.team){ + return id >= 0 && id < 256 ? Team.all[id] : null; + } + var arr = logicIdToContent[type.ordinal()]; return arr != null && id >= 0 && id < arr.length ? arr[id] : null; }