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