Skip to content

Commit

Permalink
Added Logic Sense Payload
Browse files Browse the repository at this point in the history
  • Loading branch information
BlackDeluxeCat committed Jun 28, 2023
1 parent f01df70 commit 52bacd1
Show file tree
Hide file tree
Showing 6 changed files with 60 additions and 2 deletions.
4 changes: 4 additions & 0 deletions core/src/mindustry/entities/comp/BuildingComp.java
Original file line number Diff line number Diff line change
Expand Up @@ -1931,6 +1931,10 @@ public Object senseObject(LAccess sensor){
public double sense(Content content){
if(content instanceof Item i && items != null) return items.get(i);
if(content instanceof Liquid l && liquids != null) return liquids.get(l);
if(getPayloads() != null){
if(content instanceof UnitType u) return getPayloads().get(u);
if(content instanceof Block b) return getPayloads().get(b);
}
return Float.NaN; //invalid sense
}

Expand Down
12 changes: 12 additions & 0 deletions core/src/mindustry/entities/comp/UnitComp.java
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,8 @@ public double sense(LAccess sensor){
controller instanceof CommandAI command && command.hasCommand() ? ctrlCommand :
0;
case payloadCount -> ((Object)this) instanceof Payloadc pay ? pay.payloads().size : 0;
case totalPayload -> ((Object)this) instanceof Payloadc pay ? pay.payloadUsed() : 0;
case payloadCapacity -> type.payloadCapacity;
case size -> hitSize / tilesize;
case color -> Color.toDoubleBits(team.color.r, team.color.g, team.color.b, 1f);
default -> Float.NaN;
Expand All @@ -255,6 +257,16 @@ public Object senseObject(LAccess sensor){
@Override
public double sense(Content content){
if(content == stack().item) return stack().amount;
if(content instanceof UnitType u){
return ((Object)this) instanceof Payloadc pay ?
(pay.payloads().isEmpty() ? 0 :
pay.payloads().count(p -> p instanceof UnitPayload up && up.unit.type == u)) : 0;
}
if(content instanceof Block b){
return ((Object)this) instanceof Payloadc pay ?
(pay.payloads().isEmpty() ? 0 :
pay.payloads().count(p -> p instanceof BuildPayload bp && bp.build.block == b)) : 0;
}
return Float.NaN;
}

Expand Down
2 changes: 2 additions & 0 deletions core/src/mindustry/logic/LAccess.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ public enum LAccess{
name,
payloadCount,
payloadType,
totalPayload,
payloadCapacity,

//values with parameters are considered controllable
enabled("to"), //"to" is standard for single parameter access
Expand Down
28 changes: 26 additions & 2 deletions core/src/mindustry/logic/LStatements.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import mindustry.logic.LExecutor.*;
import mindustry.type.*;
import mindustry.ui.*;
import mindustry.world.*;
import mindustry.world.meta.*;

import static mindustry.Vars.*;
Expand Down Expand Up @@ -503,6 +504,29 @@ public void build(Table table){
if(++c % 6 == 0) i.row();
}
}),
new Table(i -> {
i.left();
int c = 0;
for(UnitType item : Vars.content.units()){
if(!item.unlockedNow() || item.hidden) continue;
i.button(new TextureRegionDrawable(item.uiIcon), Styles.flati, iconSmall, () -> {
stype("@" + item.name);
hide.run();
}).size(40f);

if(++c % 6 == 0) i.row();
}

for(Block item : Vars.content.blocks()){
if(!item.unlockedNow() || item.isHidden()) continue;
i.button(new TextureRegionDrawable(item.uiIcon), Styles.flati, iconSmall, () -> {
stype("@" + item.name);
hide.run();
}).size(40f);

if(++c % 6 == 0) i.row();
}
}),
//sensors
new Table(i -> {
for(LAccess sensor : LAccess.senseable){
Expand All @@ -514,7 +538,7 @@ public void build(Table table){
})
};

Drawable[] icons = {Icon.box, Icon.liquid, Icon.tree};
Drawable[] icons = {Icon.box, Icon.liquid, Icon.units, Icon.tree};
Stack stack = new Stack(tables[selected]);
ButtonGroup<Button> group = new ButtonGroup<>();

Expand All @@ -532,7 +556,7 @@ public void build(Table table){
}).height(50f).growX().checked(selected == fi).group(group);
}
t.row();
t.add(stack).colspan(3).width(240f).left();
t.add(stack).colspan(4).width(240f).left();
}));
}, Styles.logict, () -> {}).size(40f).padLeft(-1).color(table.color);

Expand Down
8 changes: 8 additions & 0 deletions core/src/mindustry/world/blocks/payloads/PayloadBlock.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import arc.math.geom.*;
import arc.util.*;
import arc.util.io.*;
import mindustry.ctype.*;
import mindustry.gen.*;
import mindustry.graphics.*;
import mindustry.world.*;
Expand Down Expand Up @@ -235,6 +236,13 @@ public void drawPayload(){
}
}

@Override
public double sense(Content content){
if(payload instanceof UnitPayload up) return up.unit.type == content ? 1 : 0;
if(payload instanceof BuildPayload bp) return bp.build.block == content ? 1 : 0;
return super.sense(content);
}

@Override
public void write(Writes write){
super.write(write);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import arc.util.*;
import arc.util.io.*;
import mindustry.content.*;
import mindustry.ctype.*;
import mindustry.gen.*;
import mindustry.graphics.*;
import mindustry.logic.*;
Expand Down Expand Up @@ -190,6 +191,13 @@ public void updateTile(){
}
}

@Override
public double sense(Content content){
if(deconstructing instanceof UnitPayload up) return up.unit.type == content ? 1 : 0;
if(deconstructing instanceof BuildPayload bp) return bp.build.block == content ? 1 : 0;
return super.sense(content);
}

@Override
public double sense(LAccess sensor){
if(sensor == LAccess.progress) return progress;
Expand Down

0 comments on commit 52bacd1

Please sign in to comment.