Bannable units / Show tech tree icon for unresearched units
This commit is contained in:
@@ -71,11 +71,11 @@ public class PayloadSource extends PayloadBlock{
|
||||
}
|
||||
|
||||
public boolean canProduce(Block b){
|
||||
return b.isVisible() && b.size < size && !(b instanceof CoreBlock);
|
||||
return b.isVisible() && b.size < size && !(b instanceof CoreBlock) && !state.rules.bannedBlocks.contains(b);
|
||||
}
|
||||
|
||||
public boolean canProduce(UnitType t){
|
||||
return !t.isHidden();
|
||||
return !t.isHidden() && !t.isBanned();
|
||||
}
|
||||
|
||||
public class PayloadSourceBuild extends PayloadBlockBuild<Payload>{
|
||||
|
||||
@@ -4,6 +4,7 @@ import arc.*;
|
||||
import arc.graphics.*;
|
||||
import arc.graphics.g2d.*;
|
||||
import arc.math.*;
|
||||
import arc.scene.style.*;
|
||||
import arc.util.*;
|
||||
import arc.util.io.*;
|
||||
import mindustry.*;
|
||||
@@ -13,16 +14,31 @@ import mindustry.entities.*;
|
||||
import mindustry.game.EventType.*;
|
||||
import mindustry.gen.*;
|
||||
|
||||
import static mindustry.Vars.*;
|
||||
|
||||
public class UnitPayload implements Payload{
|
||||
public static final float deactiveDuration = 40f;
|
||||
public static final float overlayDuration = 40f;
|
||||
|
||||
public Unit unit;
|
||||
public float deactiveTime = 0f;
|
||||
public float overlayTime = 0f;
|
||||
public @Nullable TextureRegion overlayRegion;
|
||||
|
||||
public UnitPayload(Unit unit){
|
||||
this.unit = unit;
|
||||
}
|
||||
|
||||
/** Flashes a red overlay region. */
|
||||
public void showOverlay(TextureRegion icon){
|
||||
overlayRegion = icon;
|
||||
overlayTime = 1f;
|
||||
}
|
||||
|
||||
/** Flashes a red overlay region. */
|
||||
public void showOverlay(TextureRegionDrawable icon){
|
||||
if(icon == null || headless) return;
|
||||
showOverlay(icon.getRegion());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(Writes write){
|
||||
write.b(payloadUnit);
|
||||
@@ -62,7 +78,8 @@ public class UnitPayload implements Payload{
|
||||
if(unit.type == null) return true;
|
||||
|
||||
if(!Units.canCreate(unit.team, unit.type)){
|
||||
deactiveTime = 1f;
|
||||
overlayTime = 1f;
|
||||
overlayRegion = null;
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -103,16 +120,17 @@ public class UnitPayload implements Payload{
|
||||
unit.type.drawCell(unit);
|
||||
|
||||
//draw warning
|
||||
if(deactiveTime > 0){
|
||||
if(overlayTime > 0){
|
||||
var region = overlayRegion == null ? Icon.warning.getRegion() : overlayRegion;
|
||||
Draw.color(Color.scarlet);
|
||||
Draw.alpha(0.8f * Interp.exp5Out.apply(deactiveTime));
|
||||
Draw.alpha(0.8f * Interp.exp5Out.apply(overlayTime));
|
||||
|
||||
float size = 8f;
|
||||
Draw.rect(Icon.warning.getRegion(), unit.x, unit.y, size, size);
|
||||
Draw.rect(region, unit.x, unit.y, size, size);
|
||||
|
||||
Draw.reset();
|
||||
|
||||
deactiveTime = Math.max(deactiveTime - Time.delta/deactiveDuration, 0f);
|
||||
overlayTime = Math.max(overlayTime - Time.delta/overlayDuration, 0f);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -116,11 +116,28 @@ public class Reconstructor extends UnitBlock{
|
||||
|
||||
@Override
|
||||
public boolean acceptPayload(Building source, Payload payload){
|
||||
return this.payload == null
|
||||
&& (this.enabled || source == this)
|
||||
&& relativeTo(source) != rotation
|
||||
&& payload instanceof UnitPayload pay
|
||||
&& hasUpgrade(pay.unit.type);
|
||||
if(!(this.payload == null
|
||||
&& (this.enabled || source == this)
|
||||
&& relativeTo(source) != rotation
|
||||
&& payload instanceof UnitPayload pay)){
|
||||
return false;
|
||||
}
|
||||
|
||||
var upgrade = upgrade(pay.unit.type);
|
||||
|
||||
if(upgrade != null){
|
||||
if(!upgrade.unlockedNow()){
|
||||
//flash "not researched"
|
||||
pay.showOverlay(Icon.tree);
|
||||
}
|
||||
|
||||
if(upgrade.isBanned()){
|
||||
//flash an X, meaning 'banned'
|
||||
pay.showOverlay(Icon.cancel);
|
||||
}
|
||||
}
|
||||
|
||||
return upgrade != null && upgrade.unlockedNow() && !upgrade.isBanned();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -224,7 +241,7 @@ public class Reconstructor extends UnitBlock{
|
||||
|
||||
public boolean hasUpgrade(UnitType type){
|
||||
UnitType t = upgrade(type);
|
||||
return t != null && t.unlockedNow();
|
||||
return t != null && t.unlockedNow() && !type.isBanned();
|
||||
}
|
||||
|
||||
public UnitType upgrade(UnitType type){
|
||||
|
||||
@@ -149,7 +149,7 @@ public class UnitFactory extends UnitBlock{
|
||||
|
||||
@Override
|
||||
public void buildConfiguration(Table table){
|
||||
Seq<UnitType> units = Seq.with(plans).map(u -> u.unit).filter(u -> u.unlockedNow());
|
||||
Seq<UnitType> units = Seq.with(plans).map(u -> u.unit).filter(u -> u.unlockedNow() && !u.isBanned());
|
||||
|
||||
if(units.any()){
|
||||
ItemSelection.buildTable(table, units, () -> currentPlan == -1 ? null : plans.get(currentPlan).unit, unit -> configure(plans.indexOf(u -> u.unit == unit)));
|
||||
@@ -225,6 +225,12 @@ public class UnitFactory extends UnitBlock{
|
||||
if(currentPlan != -1 && payload == null){
|
||||
UnitPlan plan = plans.get(currentPlan);
|
||||
|
||||
//make sure to reset plan when the unit got banned after placement
|
||||
if(plan.unit.isBanned()){
|
||||
currentPlan = -1;
|
||||
return;
|
||||
}
|
||||
|
||||
if(progress >= plan.time && consValid()){
|
||||
progress %= 1f;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user