Closes Anuken/Mindustry-Suggestions/issues/4608

This commit is contained in:
Anuken
2023-08-11 12:16:40 -04:00
parent 398a6f6a42
commit fb4787ba52
8 changed files with 34 additions and 7 deletions

View File

@@ -2237,7 +2237,7 @@ lst.operation = Perform an operation on 1-2 variables.
lst.end = Jump to the top of the instruction stack. lst.end = Jump to the top of the instruction stack.
lst.wait = Wait a certain number of seconds. lst.wait = Wait a certain number of seconds.
lst.stop = Halt execution of this processor. lst.stop = Halt execution of this processor.
lst.lookup = Look up an item/liquid/unit/block type by ID.\nTotal counts of each type can be accessed with:\n[accent]@unitCount[] / [accent]@itemCount[] / [accent]@liquidCount[] / [accent]@blockCount[] lst.lookup = Look up an item/liquid/unit/block type by ID.\nTotal counts of each type can be accessed with:\n[accent]@unitCount[] / [accent]@itemCount[] / [accent]@liquidCount[] / [accent]@blockCount[]\nFor the inverse operation, sense [accent]@id[] of the object.
lst.jump = Conditionally jump to another statement. lst.jump = Conditionally jump to another statement.
lst.unitbind = Bind to the next unit of a type, and store it in [accent]@unit[]. lst.unitbind = Bind to the next unit of a type, and store it in [accent]@unit[].
lst.unitcontrol = Control the currently bound unit. lst.unitcontrol = Control the currently bound unit.
@@ -2275,6 +2275,7 @@ laccess.dead = Whether a unit/building is dead or no longer valid.
laccess.controlled = Returns:\n[accent]@ctrlProcessor[] if unit controller is processor\n[accent]@ctrlPlayer[] if unit/building controller is player\n[accent]@ctrlCommand[] if unit controller is a player command\nOtherwise, 0. laccess.controlled = Returns:\n[accent]@ctrlProcessor[] if unit controller is processor\n[accent]@ctrlPlayer[] if unit/building controller is player\n[accent]@ctrlCommand[] if unit controller is a player command\nOtherwise, 0.
laccess.progress = Action progress, 0 to 1.\nReturns production, turret reload or construction progress. laccess.progress = Action progress, 0 to 1.\nReturns production, turret reload or construction progress.
laccess.speed = Top speed of a unit, in tiles/sec. laccess.speed = Top speed of a unit, in tiles/sec.
laccess.id = ID of a unit/block/item/liquid.\nThis is the inverse of the lookup operation.
lcategory.unknown = Unknown lcategory.unknown = Unknown
lcategory.unknown.description = Uncategorized instructions. lcategory.unknown.description = Uncategorized instructions.

View File

@@ -68,6 +68,10 @@ public abstract class UnlockableContent extends MappableContent{
uiIcon = Core.atlas.find(getContentType().name() + "-" + name + "-ui", fullIcon); uiIcon = Core.atlas.find(getContentType().name() + "-" + name + "-ui", fullIcon);
} }
public int getLogicId(){
return logicVars.lookupLogicId(this);
}
public String displayDescription(){ public String displayDescription(){
return minfo.mod == null ? description : description + "\n" + Core.bundle.format("mod.display", minfo.mod.meta.displayName); return minfo.mod == null ? description : description + "\n" + Core.bundle.format("mod.display", minfo.mod.meta.displayName);
} }

View File

@@ -46,6 +46,7 @@ public enum LAccess{
name, name,
payloadCount, payloadCount,
payloadType, payloadType,
id,
//values with parameters are considered controllable //values with parameters are considered controllable
enabled("to"), //"to" is standard for single parameter access enabled("to"), //"to" is standard for single parameter access

View File

@@ -1143,7 +1143,6 @@ public class LExecutor{
} }
} }
//TODO inverse lookup
public static class LookupI implements LInstruction{ public static class LookupI implements LInstruction{
public int dest; public int dest;
public int from; public int from;

View File

@@ -153,8 +153,9 @@ public class Item extends UnlockableContent implements Senseable{
@Override @Override
public double sense(LAccess sensor){ public double sense(LAccess sensor){
if(sensor == LAccess.color) return color.toFloatBits(); if(sensor == LAccess.color) return color.toDoubleBits();
return 0; if(sensor == LAccess.id) return getLogicId();
return Float.NaN;
} }
@Override @Override

View File

@@ -171,8 +171,9 @@ public class Liquid extends UnlockableContent implements Senseable{
@Override @Override
public double sense(LAccess sensor){ public double sense(LAccess sensor){
if(sensor == LAccess.color) return color.toFloatBits(); if(sensor == LAccess.color) return color.toDoubleBits();
return 0; if(sensor == LAccess.id) return getLogicId();
return Double.NaN;
} }
@Override @Override

View File

@@ -28,6 +28,7 @@ import mindustry.game.*;
import mindustry.gen.*; import mindustry.gen.*;
import mindustry.graphics.*; import mindustry.graphics.*;
import mindustry.graphics.MultiPacker.*; import mindustry.graphics.MultiPacker.*;
import mindustry.logic.*;
import mindustry.type.ammo.*; import mindustry.type.ammo.*;
import mindustry.ui.*; import mindustry.ui.*;
import mindustry.world.*; import mindustry.world.*;
@@ -40,7 +41,7 @@ import mindustry.world.meta.*;
import static arc.graphics.g2d.Draw.*; import static arc.graphics.g2d.Draw.*;
import static mindustry.Vars.*; import static mindustry.Vars.*;
public class UnitType extends UnlockableContent{ public class UnitType extends UnlockableContent implements Senseable{
public static final float shadowTX = -12, shadowTY = -13; public static final float shadowTX = -12, shadowTY = -13;
private static final Vec2 legOffset = new Vec2(); private static final Vec2 legOffset = new Vec2();
@@ -1124,6 +1125,24 @@ public class UnitType extends UnlockableContent{
return super.researchRequirements(); return super.researchRequirements();
} }
@Override
public double sense(LAccess sensor){
return switch(sensor){
case health, maxHealth -> health;
case size -> hitSize / tilesize;
case itemCapacity -> itemCapacity;
case speed -> speed * 60f / tilesize;
case id -> getLogicId();
default -> Double.NaN;
};
}
@Override
public Object senseObject(LAccess sensor){
if(sensor == LAccess.name) return name;
return noSensed;
}
@Override @Override
public ContentType getContentType(){ public ContentType getContentType(){
return ContentType.unit; return ContentType.unit;

View File

@@ -1374,6 +1374,7 @@ public class Block extends UnlockableContent implements Senseable{
case itemCapacity -> itemCapacity; case itemCapacity -> itemCapacity;
case liquidCapacity -> liquidCapacity; case liquidCapacity -> liquidCapacity;
case powerCapacity -> consPower != null && consPower.buffered ? consPower.capacity : 0f; case powerCapacity -> consPower != null && consPower.buffered ? consPower.capacity : 0f;
case id -> getLogicId();
default -> Double.NaN; default -> Double.NaN;
}; };
} }