An experiment
This commit is contained in:
@@ -15,6 +15,7 @@ import mindustry.gen.*;
|
||||
import mindustry.type.*;
|
||||
import mindustry.world.*;
|
||||
import mindustry.world.blocks.payloads.*;
|
||||
import mindustry.world.blocks.power.*;
|
||||
|
||||
/** An entity that holds a payload. */
|
||||
@Component
|
||||
@@ -22,8 +23,38 @@ abstract class PayloadComp implements Posc, Rotc, Hitboxc, Unitc{
|
||||
@Import float x, y, rotation;
|
||||
@Import UnitType type;
|
||||
|
||||
private transient @Nullable PowerGraph payloadPower;
|
||||
|
||||
Seq<Payload> payloads = new Seq<>();
|
||||
|
||||
//uncomment for insanity
|
||||
/*
|
||||
@Override
|
||||
public void update(){
|
||||
if(payloadPower != null){
|
||||
payloadPower.clear();
|
||||
}
|
||||
|
||||
//update power graph first, resolve everything
|
||||
for(Payload pay : payloads){
|
||||
if(pay instanceof BuildPayload pb && pb.build.power != null){
|
||||
if(payloadPower == null) payloadPower = new PowerGraph();
|
||||
|
||||
pb.build.power.graph = null;
|
||||
payloadPower.add(pb.build);
|
||||
}
|
||||
}
|
||||
|
||||
if(payloadPower != null){
|
||||
payloadPower.update();
|
||||
}
|
||||
|
||||
for(Payload pay : payloads){
|
||||
pay.set(x, y, rotation);
|
||||
pay.update(true);
|
||||
}
|
||||
}*/
|
||||
|
||||
float payloadUsed(){
|
||||
return payloads.sumf(p -> p.size() * p.size());
|
||||
}
|
||||
@@ -50,7 +81,7 @@ abstract class PayloadComp implements Posc, Rotc, Hitboxc, Unitc{
|
||||
|
||||
void pickup(Unit unit){
|
||||
unit.remove();
|
||||
payloads.add(new UnitPayload(unit));
|
||||
addPayload(new UnitPayload(unit));
|
||||
Fx.unitPickup.at(unit);
|
||||
if(Vars.net.client()){
|
||||
Vars.netClient.clearRemovedEntity(unit.id);
|
||||
@@ -62,7 +93,7 @@ abstract class PayloadComp implements Posc, Rotc, Hitboxc, Unitc{
|
||||
tile.pickedUp();
|
||||
tile.tile.remove();
|
||||
tile.tile = Vars.emptyTile;
|
||||
payloads.add(new BuildPayload(tile));
|
||||
addPayload(new BuildPayload(tile));
|
||||
Fx.unitPickup.at(tile);
|
||||
Events.fire(new PickupEvent(self(), tile));
|
||||
}
|
||||
|
||||
@@ -120,6 +120,8 @@ public class Block extends UnlockableContent{
|
||||
public boolean autoResetEnabled = true;
|
||||
/** if true, the block stops updating when disabled */
|
||||
public boolean noUpdateDisabled = false;
|
||||
/** if true, this block updates when a payload of a unit. Currently unused! */
|
||||
public boolean updateInUnits = true;
|
||||
/** Whether to use this block's color in the minimap. Only used for overlays. */
|
||||
public boolean useColor = true;
|
||||
/** item that drops from this block, used for drills */
|
||||
|
||||
@@ -31,6 +31,7 @@ public class BaseTurret extends Block{
|
||||
priority = TargetPriority.turret;
|
||||
group = BlockGroup.turrets;
|
||||
flags = EnumSet.of(BlockFlag.turret);
|
||||
updateInUnits = false;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -127,7 +127,7 @@ public class PayloadConveyor extends Block{
|
||||
if(!enabled) return;
|
||||
|
||||
if(item != null){
|
||||
item.update();
|
||||
item.update(false);
|
||||
}
|
||||
|
||||
lastInterp = curInterp;
|
||||
|
||||
@@ -37,7 +37,9 @@ public class BuildPayload implements Payload{
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update(){
|
||||
public void update(boolean inUnit){
|
||||
if(inUnit && !build.block.updateInUnits) return;
|
||||
|
||||
if(build.tile == null) build.tile = emptyTile;
|
||||
build.update();
|
||||
}
|
||||
|
||||
@@ -36,8 +36,9 @@ public interface Payload extends Position{
|
||||
/** @return the time taken to build this payload. */
|
||||
float buildTime();
|
||||
|
||||
/** update this payload if it is a block */
|
||||
default void update(){}
|
||||
/** update this payload if it is a block
|
||||
* @param inUnit whether this payload is in a unit */
|
||||
default void update(boolean inUnit){}
|
||||
|
||||
/** @return whether this payload was dumped. */
|
||||
default boolean dump(){
|
||||
|
||||
@@ -138,7 +138,7 @@ public class PayloadBlock extends Block{
|
||||
@Override
|
||||
public void updateTile(){
|
||||
if(payload != null){
|
||||
payload.update();
|
||||
payload.update(false);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -49,6 +49,7 @@ public class NuclearReactor extends PowerGenerator{
|
||||
|
||||
public NuclearReactor(String name){
|
||||
super(name);
|
||||
updateInUnits = false;
|
||||
itemCapacity = 30;
|
||||
liquidCapacity = 30;
|
||||
hasItems = true;
|
||||
@@ -138,7 +139,7 @@ public class NuclearReactor extends PowerGenerator{
|
||||
if((fuel < 5 && heat < 0.5f) || !state.rules.reactorExplosions) return;
|
||||
|
||||
Effect.shake(6f, 16f, x, y);
|
||||
Damage.damage(x, y, explosionRadius * tilesize, explosionDamage * 4);
|
||||
Damage.damage(x, y, explosionRadius * tilesize * (float)(fuel / itemCapacity), explosionDamage * 4);
|
||||
|
||||
explodeEffect.at(x, y);
|
||||
}
|
||||
|
||||
@@ -280,6 +280,13 @@ public class PowerGraph{
|
||||
}
|
||||
}
|
||||
|
||||
public void clear(){
|
||||
all.clear();
|
||||
producers.clear();
|
||||
consumers.clear();
|
||||
batteries.clear();
|
||||
}
|
||||
|
||||
public void reflow(Building tile){
|
||||
queue.clear();
|
||||
queue.addLast(tile);
|
||||
|
||||
@@ -68,7 +68,8 @@ public class ConsumePower extends Consume{
|
||||
* @return The amount of power which is requested per tick.
|
||||
*/
|
||||
public float requestedPower(Building entity){
|
||||
if(entity.tile == null || entity.tile.build == null) return 0f;
|
||||
if(entity == null) return 0f;
|
||||
|
||||
if(buffered){
|
||||
return (1f-entity.power.status)*capacity;
|
||||
}else{
|
||||
|
||||
Reference in New Issue
Block a user