Many various logic changes
This commit is contained in:
@@ -3,6 +3,7 @@ package mindustry.world.blocks.defense;
|
||||
import arc.Graphics.*;
|
||||
import arc.Graphics.Cursor.*;
|
||||
import arc.graphics.g2d.*;
|
||||
import arc.math.*;
|
||||
import arc.math.geom.*;
|
||||
import arc.struct.*;
|
||||
import arc.util.*;
|
||||
@@ -12,6 +13,8 @@ import mindustry.content.*;
|
||||
import mindustry.entities.*;
|
||||
import mindustry.entities.units.*;
|
||||
import mindustry.gen.*;
|
||||
import mindustry.logic.*;
|
||||
import mindustry.world.blocks.defense.Door.*;
|
||||
|
||||
import static mindustry.Vars.*;
|
||||
|
||||
@@ -33,6 +36,11 @@ public class Door extends Wall{
|
||||
Sounds.door.at(base);
|
||||
|
||||
for(DoorEntity entity : base.chained){
|
||||
//skip doors with things in them
|
||||
if((Units.anyEntities(entity.tile) && !open) || entity.open == open){
|
||||
continue;
|
||||
}
|
||||
|
||||
entity.open = open;
|
||||
pathfinder.updateTile(entity.tile());
|
||||
entity.effect();
|
||||
@@ -66,6 +74,19 @@ public class Door extends Wall{
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void control(LAccess type, double p1, double p2, double p3, double p4){
|
||||
if(type == LAccess.enabled){
|
||||
boolean shouldOpen = !Mathf.zero(p1);
|
||||
|
||||
if(open == shouldOpen || (Units.anyEntities(tile) && !shouldOpen) || !timer(timerToggle, 60f)){
|
||||
return;
|
||||
}
|
||||
|
||||
configureAny(shouldOpen);
|
||||
}
|
||||
}
|
||||
|
||||
public void effect(){
|
||||
(open ? closefx : openfx).at(this);
|
||||
}
|
||||
@@ -104,7 +125,7 @@ public class Door extends Wall{
|
||||
|
||||
@Override
|
||||
public void tapped(Player player){
|
||||
if((Units.anyEntities(tile) && open) || !timer(timerToggle, 30f)){
|
||||
if((Units.anyEntities(tile) && open) || !timer(timerToggle, 40f)){
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
@@ -18,6 +18,7 @@ import mindustry.entities.bullet.*;
|
||||
import mindustry.game.EventType.*;
|
||||
import mindustry.gen.*;
|
||||
import mindustry.graphics.*;
|
||||
import mindustry.logic.*;
|
||||
import mindustry.type.*;
|
||||
import mindustry.world.*;
|
||||
import mindustry.world.blocks.*;
|
||||
@@ -25,9 +26,12 @@ import mindustry.world.consumers.*;
|
||||
import mindustry.world.meta.*;
|
||||
import mindustry.world.meta.values.*;
|
||||
|
||||
import static mindustry.Vars.tilesize;
|
||||
import static mindustry.Vars.*;
|
||||
|
||||
public abstract class Turret extends Block{
|
||||
//after being logic-controlled and this amount of time passes, the turret will resume normal AI
|
||||
public final static float logicControlCooldown = 60 * 2;
|
||||
|
||||
public final int timerTarget = timers++;
|
||||
public int targetInterval = 20;
|
||||
|
||||
@@ -140,8 +144,9 @@ public abstract class Turret extends Block{
|
||||
public class TurretEntity extends Building implements ControlBlock{
|
||||
public Seq<AmmoEntry> ammo = new Seq<>();
|
||||
public int totalAmmo;
|
||||
public float reload, rotation = 90, recoil, heat;
|
||||
public float reload, rotation = 90, recoil, heat, logicControlTime = -1;
|
||||
public int shotCounter;
|
||||
public boolean logicShooting = false;
|
||||
public @Nullable Posc target;
|
||||
public Vec2 targetPos = new Vec2();
|
||||
public @NonNull BlockUnitc unit = Nulls.blockUnit;
|
||||
@@ -152,11 +157,26 @@ public abstract class Turret extends Block{
|
||||
unit.tile(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void control(LAccess type, double p1, double p2, double p3, double p4){
|
||||
if(type == LAccess.shoot && !unit.isPlayer()){
|
||||
targetPos.set((float)p1, (float)p2);
|
||||
logicControlTime = logicControlCooldown;
|
||||
logicShooting = !Mathf.zero(p3);
|
||||
}
|
||||
|
||||
super.control(type, p1, p2, p3, p4);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Unit unit(){
|
||||
return (Unit)unit;
|
||||
}
|
||||
|
||||
public boolean logicControlled(){
|
||||
return logicControlTime > 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void draw(){
|
||||
Draw.rect(baseRegion, x, y);
|
||||
@@ -184,6 +204,10 @@ public abstract class Turret extends Block{
|
||||
unit.rotation(rotation);
|
||||
unit.team(team);
|
||||
|
||||
if(logicControlTime > 0){
|
||||
logicControlTime -= Time.delta;
|
||||
}
|
||||
|
||||
if(hasAmmo()){
|
||||
|
||||
if(timer(timerTarget, targetInterval)){
|
||||
@@ -193,10 +217,11 @@ public abstract class Turret extends Block{
|
||||
if(validateTarget()){
|
||||
boolean canShoot = true;
|
||||
|
||||
//player behavior
|
||||
if(isControlled()){
|
||||
if(isControlled()){ //player behavior
|
||||
targetPos.set(unit.aimX(), unit.aimY());
|
||||
canShoot = unit.isShooting();
|
||||
}else if(logicControlled()){ //logic behavior
|
||||
canShoot = logicShooting;
|
||||
}else{ //default AI behavior
|
||||
BulletType type = peekAmmo();
|
||||
float speed = type.speed;
|
||||
|
||||
@@ -19,8 +19,7 @@ public class LogicDisplay extends Block{
|
||||
commandRect = 4,
|
||||
commandLineRect = 5,
|
||||
commandPoly = 6,
|
||||
commandLinePoly = 7,
|
||||
commandFlush = 8;
|
||||
commandLinePoly = 7;
|
||||
|
||||
public int maxSides = 25;
|
||||
|
||||
@@ -91,7 +90,7 @@ public class LogicDisplay extends Block{
|
||||
}
|
||||
}
|
||||
|
||||
public enum CommandType{
|
||||
public enum GraphicsType{
|
||||
clear,
|
||||
color,
|
||||
stroke,
|
||||
@@ -99,11 +98,9 @@ public class LogicDisplay extends Block{
|
||||
rect,
|
||||
lineRect,
|
||||
poly,
|
||||
linePoly,
|
||||
flush;
|
||||
linePoly;
|
||||
|
||||
public static final CommandType[] all = values();
|
||||
public static final CommandType[] allNormal = Seq.select(all, t -> t != flush).toArray(CommandType.class);
|
||||
public static final GraphicsType[] all = values();
|
||||
}
|
||||
|
||||
@Struct
|
||||
|
||||
@@ -109,8 +109,8 @@ public class NuclearReactor extends PowerGenerator{
|
||||
}
|
||||
|
||||
@Override
|
||||
public double sense(LSensor sensor){
|
||||
if(sensor == LSensor.heat) return heat;
|
||||
public double sense(LAccess sensor){
|
||||
if(sensor == LAccess.heat) return heat;
|
||||
return super.sense(sensor);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user