Sensors, SetProp, and SetRule (#9943)

* some fun things for world proc only

* fix the format artifact

* SetProp and reformating

* Wildcard imports

* Wildcard imports

* velocity conversion

* compacting description

Co-authored-by: Anuken <arnukren@gmail.com>

* Update core/src/mindustry/world/blocks/defense/turrets/Turret.java

---------

Co-authored-by: Anuken <arnukren@gmail.com>
This commit is contained in:
TripleToxic 2024-07-07 11:28:19 -04:00 committed by GitHub
parent e07a739ae2
commit 82bcf5966e
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
8 changed files with 38 additions and 2 deletions

View file

@ -2438,6 +2438,7 @@ lenum.shootp = Shoot at a unit/building with velocity prediction.
lenum.config = Building configuration, e.g. sorter item.
lenum.enabled = Whether the block is enabled.
laccess.currentammotype = Current ammo item/liquid of a turret.
laccess.color = Illuminator color.
laccess.controller = Unit controller. If processor controlled, returns processor.\nOtherwise, returns the unit itself.
laccess.dead = Whether a unit/building is dead or no longer valid.

View file

@ -214,6 +214,8 @@ abstract class UnitComp implements Healthc, Physicsc, Hitboxc, Statusc, Teamc, I
case ammoCapacity -> type.ammoCapacity;
case x -> World.conv(x);
case y -> World.conv(y);
case velocityX -> vel.x * 60f / tilesize;
case velocityY -> vel.y * 60f / tilesize;
case dead -> dead || !isAdded() ? 1 : 0;
case team -> team.id;
case shooting -> isShooting() ? 1 : 0;
@ -282,6 +284,8 @@ abstract class UnitComp implements Healthc, Physicsc, Hitboxc, Statusc, Teamc, I
y = World.unconv((float)value);
if(!isLocal()) snapInterpolation();
}
case velocityX -> vel.x = (float)(value * tilesize / 60d);
case velocityY -> vel.y = (float)(value * tilesize / 60d);
case rotation -> rotation = (float)value;
case team -> {
if(!net.client()){

View file

@ -17,6 +17,7 @@ public enum LAccess{
powerNetOut,
ammo,
ammoCapacity,
currentAmmoType,
health,
maxHealth,
heat,
@ -28,6 +29,8 @@ public enum LAccess{
rotation,
x,
y,
velocityX,
velocityY,
shootX,
shootY,
cameraX,
@ -68,7 +71,7 @@ public enum LAccess{
all = values(),
senseable = Seq.select(all, t -> t.params.length <= 1).toArray(LAccess.class),
controls = Seq.select(all, t -> t.params.length > 0).toArray(LAccess.class),
settable = {x, y, rotation, speed, armor, health, shield, team, flag, totalPower, payloadType};
settable = {x, y, velocityX, velocityY, rotation, speed, armor, health, shield, team, flag, totalPower, payloadType};
LAccess(String... params){
this.params = params;
@ -79,5 +82,4 @@ public enum LAccess{
this.params = params;
isObj = obj;
}
}

View file

@ -1497,6 +1497,7 @@ public class LExecutor{
}
case ambientLight -> state.rules.ambientLight.fromDouble(value.num());
case solarMultiplier -> state.rules.solarMultiplier = Math.max(value.numf(), 0f);
case dragMultiplier -> state.rules.dragMultiplier = Math.max(value.numf(), 0f);
case ban -> {
Object cont = value.obj();
if(cont instanceof Block b){

View file

@ -15,6 +15,7 @@ public enum LogicRule{
lighting,
ambientLight,
solarMultiplier,
dragMultiplier,
ban,
unban,

View file

@ -4,6 +4,7 @@ import arc.struct.*;
import mindustry.content.*;
import mindustry.entities.bullet.*;
import mindustry.gen.*;
import mindustry.logic.*;
import mindustry.type.*;
import mindustry.world.consumers.*;
import mindustry.world.meta.*;
@ -77,6 +78,14 @@ public class ContinuousLiquidTurret extends ContinuousTurret{
super.updateTile();
}
@Override
public Object senseObject(LAccess sensor){
return switch(sensor){
case currentAmmoType -> liquids.current();
default -> super.senseObject(sensor);
};
}
@Override
public boolean canConsume(){
return hasCorrectAmmo() && super.canConsume();

View file

@ -11,6 +11,7 @@ import mindustry.entities.bullet.*;
import mindustry.game.EventType.*;
import mindustry.gen.*;
import mindustry.graphics.*;
import mindustry.logic.*;
import mindustry.type.*;
import mindustry.ui.*;
import mindustry.world.consumers.*;
@ -107,6 +108,14 @@ public class ItemTurret extends Turret{
}
}
@Override
public Object senseObject(LAccess sensor){
return switch(sensor){
case currentAmmoType -> ammo.size > 0 ? ((ItemEntry)ammo.peek()).item : null;
default -> super.senseObject(sensor);
};
}
@Override
public void updateTile(){
unit.ammo((float)unit.type().ammoCapacity * totalAmmo / maxAmmo);

View file

@ -6,6 +6,7 @@ import mindustry.core.*;
import mindustry.entities.*;
import mindustry.entities.bullet.*;
import mindustry.gen.*;
import mindustry.logic.*;
import mindustry.type.*;
import mindustry.world.*;
import mindustry.world.consumers.*;
@ -72,6 +73,14 @@ public class LiquidTurret extends Turret{
super.updateTile();
}
@Override
public Object senseObject(LAccess sensor){
return switch(sensor){
case currentAmmoType -> liquids.current();
default -> super.senseObject(sensor);
};
}
@Override
protected void findTarget(){
if(extinguish && liquids.current().canExtinguish()){