Allow team lookup

This commit is contained in:
Anuken
2025-02-05 11:54:07 -05:00
parent c08ebc149a
commit d01bc95c05
2 changed files with 17 additions and 5 deletions

View File

@@ -8,12 +8,13 @@ import arc.util.*;
import mindustry.game.Rules.*; import mindustry.game.Rules.*;
import mindustry.game.Teams.*; import mindustry.game.Teams.*;
import mindustry.graphics.*; import mindustry.graphics.*;
import mindustry.logic.*;
import mindustry.world.blocks.storage.CoreBlock.*; import mindustry.world.blocks.storage.CoreBlock.*;
import mindustry.world.modules.*; import mindustry.world.modules.*;
import static mindustry.Vars.*; import static mindustry.Vars.*;
public class Team implements Comparable<Team>{ public class Team implements Comparable<Team>, Senseable{
public final int id; public final int id;
public final Color color; public final Color color;
public final Color[] palette; public final Color[] palette;
@@ -152,4 +153,10 @@ public class Team implements Comparable<Team>{
public String toString(){ public String toString(){
return name; return name;
} }
@Override
public double sense(LAccess sensor){
if(sensor == LAccess.id) return id;
return 0;
}
} }

View File

@@ -22,7 +22,7 @@ import static mindustry.Vars.*;
/** Stores global logic variables for logic processors. */ /** Stores global logic variables for logic processors. */
public class GlobalVars{ public class GlobalVars{
public static final int ctrlProcessor = 1, ctrlPlayer = 2, ctrlCommand = 3; 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. */ /** Global random state. */
public static final Rand rand = new Rand(); public static final Rand rand = new Rand();
@@ -220,8 +220,13 @@ public class GlobalVars{
return varEntries; return varEntries;
} }
/** @return a piece of content based on its logic ID. This is not equivalent to content 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 Content lookupContent(ContentType type, int id){ 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()]; var arr = logicIdToContent[type.ordinal()];
return arr != null && id >= 0 && id < arr.length ? arr[id] : null; return arr != null && id >= 0 && id < arr.length ? arr[id] : null;
} }