Merge branch 'campaign'

# Conflicts:
#	core/src/mindustry/world/consumers/ConsumeItemFilter.java
This commit is contained in:
Anuken
2020-10-01 13:37:25 -04:00
12 changed files with 67 additions and 97 deletions

View File

@@ -87,8 +87,8 @@ public class BuilderAI extends AIController{
} }
//find new request //find new request
if(!unit.team().data().blocks.isEmpty() && following == null && timer.get(timerTarget3, 60 * 2f)){ if(!unit.team.data().blocks.isEmpty() && following == null && timer.get(timerTarget3, 60 * 2f)){
Queue<BlockPlan> blocks = unit.team().data().blocks; Queue<BlockPlan> blocks = unit.team.data().blocks;
BlockPlan block = blocks.first(); BlockPlan block = blocks.first();
//check if it's already been placed //check if it's already been placed

View File

@@ -1580,13 +1580,13 @@ public class Blocks implements ContentList{
requirements(Category.turret, with(Items.silicon, 130, Items.thorium, 80, Items.phasefabric, 40)); requirements(Category.turret, with(Items.silicon, 130, Items.thorium, 80, Items.phasefabric, 40));
health = 250 * size * size; health = 250 * size * size;
range = 140f; range = 160f;
hasPower = true; hasPower = true;
consumes.powerCond(8f, (PointDefenseBuild b) -> b.target != null); consumes.powerCond(8f, (PointDefenseBuild b) -> b.target != null);
size = 2; size = 2;
shootLength = 5f; shootLength = 5f;
bulletDamage = 25f; bulletDamage = 25f;
reloadTime = 10f; reloadTime = 9f;
}}; }};
tsunami = new LiquidTurret("tsunami"){{ tsunami = new LiquidTurret("tsunami"){{
@@ -1701,7 +1701,7 @@ public class Blocks implements ContentList{
trailEffect = Fx.instTrail; trailEffect = Fx.instTrail;
despawnEffect = Fx.instBomb; despawnEffect = Fx.instBomb;
trailSpacing = 20f; trailSpacing = 20f;
damage = 1250; damage = 1350;
tileDamageMultiplier = 0.5f; tileDamageMultiplier = 0.5f;
speed = brange; speed = brange;
hitShake = 6f; hitShake = 6f;

View File

@@ -519,7 +519,7 @@ public class Control implements ApplicationListener, Loadable{
platform.updateRPC(); platform.updateRPC();
} }
if(Core.input.keyTap(Binding.pause) && !state.isOutOfTime() && !scene.hasDialog() && !scene.hasKeyboard() && !ui.restart.isShown() && (state.is(State.paused) || state.is(State.playing))){ if(Core.input.keyTap(Binding.pause) && !scene.hasDialog() && !scene.hasKeyboard() && !ui.restart.isShown() && (state.is(State.paused) || state.is(State.playing))){
state.set(state.is(State.playing) ? State.paused : State.playing); state.set(state.is(State.playing) ? State.paused : State.playing);
} }

View File

@@ -50,11 +50,6 @@ public class GameState{
return rules.sector != null; return rules.sector != null;
} }
/** @return whether the player is in a campaign and they are out of sector time */
public boolean isOutOfTime(){
return isCampaign() && isGame() && getSector().getTimeSpent() >= turnDuration && !net.active();
}
public boolean hasSector(){ public boolean hasSector(){
return rules.sector != null; return rules.sector != null;
} }

View File

@@ -282,18 +282,6 @@ public class Logic implements ApplicationListener{
state.enemies = Groups.unit.count(u -> u.team() == state.rules.waveTeam && u.type().isCounted); state.enemies = Groups.unit.count(u -> u.team() == state.rules.waveTeam && u.type().isCounted);
} }
//force pausing when the player is out of sector time
if(state.isOutOfTime()){
if(!state.wasTimeout){
universe.displayTimeEnd();
state.wasTimeout = true;
}
//if no turn was run.
if(state.isOutOfTime()){
state.set(State.paused);
}
}
if(!state.isPaused()){ if(!state.isPaused()){
if(state.isCampaign()){ if(state.isCampaign()){
state.secinfo.update(); state.secinfo.update();

View File

@@ -24,7 +24,7 @@ public class SectorInfo{
/** Export statistics. */ /** Export statistics. */
public ObjectMap<Item, ExportStat> export = new ObjectMap<>(); public ObjectMap<Item, ExportStat> export = new ObjectMap<>();
/** Items stored in all cores. */ /** Items stored in all cores. */
public ObjectIntMap<Item> coreItems = new ObjectIntMap<>(); public ItemSeq coreItems = new ItemSeq();
/** The best available core type. */ /** The best available core type. */
public Block bestCoreType = Blocks.air; public Block bestCoreType = Blocks.air;
/** Max storage capacity. */ /** Max storage capacity. */
@@ -80,7 +80,7 @@ public class SectorInfo{
if(entity != null){ if(entity != null){
ItemModule items = entity.items; ItemModule items = entity.items;
for(int i = 0; i < items.length(); i++){ for(int i = 0; i < items.length(); i++){
coreItems.put(content.item(i), items.get(i)); coreItems.set(content.item(i), items.get(i));
} }
} }
@@ -88,7 +88,7 @@ public class SectorInfo{
bestCoreType = !hasCore ? Blocks.air : state.rules.defaultTeam.cores().max(e -> e.block.size).block; bestCoreType = !hasCore ? Blocks.air : state.rules.defaultTeam.cores().max(e -> e.block.size).block;
storageCapacity = entity != null ? entity.storageCapacity : 0; storageCapacity = entity != null ? entity.storageCapacity : 0;
//update sector's internal time spent counter1 //update sector's internal time spent counter
state.rules.sector.setTimeSpent(internalTimeSpent); state.rules.sector.setTimeSpent(internalTimeSpent);
} }
@@ -100,6 +100,12 @@ public class SectorInfo{
internalTimeSpent += Time.delta; internalTimeSpent += Time.delta;
//autorun turns
if(internalTimeSpent >= turnDuration){
internalTimeSpent = 0;
universe.runTurn();
}
//create last stored core items //create last stored core items
if(lastCoreItems == null){ if(lastCoreItems == null){
lastCoreItems = new int[content.items().size]; lastCoreItems = new int[content.items().size];

View File

@@ -5,7 +5,6 @@ import arc.math.*;
import arc.struct.*; import arc.struct.*;
import arc.util.*; import arc.util.*;
import mindustry.content.*; import mindustry.content.*;
import mindustry.core.GameState.*;
import mindustry.game.EventType.*; import mindustry.game.EventType.*;
import mindustry.type.*; import mindustry.type.*;
import mindustry.world.blocks.storage.*; import mindustry.world.blocks.storage.*;
@@ -54,25 +53,9 @@ public class Universe{
} }
} }
public void displayTimeEnd(){ /** @return sectors attacked on the current planet, minus the ones that are being played on right now. */
if(!headless){ public Seq<Sector> getAttacked(Planet planet){
//check if any sectors are under attack to display this return planet.sectors.select(s -> s.hasWaves() && s.hasBase() && !s.isBeingPlayed() && s.getSecondsPassed() > 1);
Seq<Sector> attacked = state.getSector().planet.sectors.select(s -> s.hasWaves() && s.hasBase() && !s.isBeingPlayed() && s.getSecondsPassed() > 1);
if(attacked.any()){
state.set(State.paused);
//TODO localize
String text = attacked.size > 1 ? attacked.size + " sectors attacked." : "Sector " + attacked.first().id + " under attack.";
ui.hudfrag.sectorText = text;
ui.hudfrag.attackedSectors = attacked;
ui.announce(text);
}else{
//autorun next turn
universe.runTurn();
}
}
} }
/** Update planet rotations, global time and relevant state. */ /** Update planet rotations, global time and relevant state. */

View File

@@ -98,8 +98,10 @@ public class ItemSeq implements Iterable<ItemStack>, Serializable{
@Override @Override
public void read(Json json, JsonValue jsonData){ public void read(Json json, JsonValue jsonData){
total = 0;
for(Item item : Vars.content.items()){ for(Item item : Vars.content.items()){
values[item.id] = jsonData.getInt(item.name, 0); values[item.id] = jsonData.getInt(item.name, 0);
total += values[item.id];
} }
} }

View File

@@ -3,7 +3,6 @@ package mindustry.type;
import arc.*; import arc.*;
import arc.func.*; import arc.func.*;
import arc.math.geom.*; import arc.math.geom.*;
import arc.struct.ObjectIntMap.*;
import arc.struct.*; import arc.struct.*;
import arc.util.ArcAnnotate.*; import arc.util.ArcAnnotate.*;
import arc.util.*; import arc.util.*;
@@ -152,6 +151,26 @@ public class Sector{
}else{ }else{
ItemSeq recv = getExtraItems(); ItemSeq recv = getExtraItems();
if(save != null){
//"shave off" extra items
ItemSeq count = new ItemSeq();
//add items already present
count.add(save.meta.secinfo.coreItems);
count.add(calculateReceivedItems());
int capacity = save.meta.secinfo.storageCapacity;
//when over capacity, add that to the extra items
count.each((i, a) -> {
if(a > capacity){
recv.remove(i, (a - capacity));
}
});
}
recv.remove(item, amount); recv.remove(item, amount);
setExtraItems(recv); setExtraItems(recv);
@@ -166,21 +185,19 @@ public class Sector{
count.add(state.rules.defaultTeam.items()); count.add(state.rules.defaultTeam.items());
}else if(save != null){ }else if(save != null){
//add items already present //add items already present
for(Entry<Item> ent : save.meta.secinfo.coreItems){ count.add(save.meta.secinfo.coreItems);
count.add(ent.key, ent.value);
}
count.add(calculateReceivedItems()); count.add(calculateReceivedItems());
int capacity = save.meta.secinfo.storageCapacity; int capacity = save.meta.secinfo.storageCapacity;
//validation //validation
for(Item item : content.items()){ count.each((item, amount) -> {
//ensure positive items //ensure positive items
if(count.get(item) < 0) count.set(item, 0); if(amount < 0) count.set(item, 0);
//cap the items //cap the items
if(count.get(item) > capacity) count.set(item, capacity); if(amount > capacity) count.set(item, capacity);
} });
} }
return count; return count;
@@ -196,7 +213,7 @@ public class Sector{
save.meta.secinfo.production.each((item, stat) -> count.add(item, (int)(stat.mean * seconds))); save.meta.secinfo.production.each((item, stat) -> count.add(item, (int)(stat.mean * seconds)));
//add received items //add received items
getExtraItems().each(count::add); count.add(getExtraItems());
} }
return count; return count;
@@ -244,14 +261,14 @@ public class Sector{
return Core.settings.getFloat(key("time-spent")); return Core.settings.getFloat(key("time-spent"));
} }
public void setSecondsPassed(long number){ public void setSecondsPassed(int number){
put("seconds-passed", number); put("secondsi-passed", number);
} }
/** @return how much time has passed in this sector without the player resuming here. /** @return how much time has passed in this sector without the player resuming here.
* Used for resource production calculations. */ * Used for resource production calculations. */
public long getSecondsPassed(){ public int getSecondsPassed(){
return Core.settings.getLong(key("seconds-passed")); return Core.settings.getInt(key("secondsi-passed"));
} }
private String key(String key){ private String key(String key){

View File

@@ -381,7 +381,7 @@ public class PlanetDialog extends BaseDialog implements PlanetInterfaceRenderer{
} }
//stored resources //stored resources
if(sector.hasBase() && sector.save.meta.secinfo.coreItems.size > 0){ if(sector.hasBase() && sector.save.meta.secinfo.coreItems.total > 0){
stable.add("@sectors.stored").row(); stable.add("@sectors.stored").row();
stable.table(t -> { stable.table(t -> {
t.left(); t.left();

View File

@@ -33,10 +33,6 @@ public class HudFragment extends Fragment{
public final PlacementFragment blockfrag = new PlacementFragment(); public final PlacementFragment blockfrag = new PlacementFragment();
//TODO localize
public String sectorText = "Out of sector time.";
public Seq<Sector> attackedSectors = new Seq<>();
private ImageButton flip; private ImageButton flip;
private Table lastUnlockTable; private Table lastUnlockTable;
private Table lastUnlockLayout; private Table lastUnlockLayout;
@@ -68,9 +64,23 @@ public class HudFragment extends Fragment{
coreItems.clear(); coreItems.clear();
}); });
Events.on(TurnEvent.class, e -> {
Seq<Sector> attacked = universe.getAttacked(state.getSector().planet);
if(attacked.any()){
//TODO localize
String text = attacked.size > 1 ? attacked.size + " sectors attacked." : "Sector " + attacked.first().id + " under attack.";
showToast(Icon.warning, text);
}
//ui.announce("[accent][[ Turn " + universe.turn() + " ]\n[scarlet]" + attackedSectors.size + "[lightgray] sector(s) attacked.");
});
//paused table //paused table
parent.fill(t -> { parent.fill(t -> {
t.top().visible(() -> state.isPaused() && !state.isOutOfTime()).touchable = Touchable.disabled; t.top().visible(() -> state.isPaused()).touchable = Touchable.disabled;
t.table(Styles.black5, top -> top.add("@paused").style(Styles.outlineLabel).pad(8f)).growX(); t.table(Styles.black5, top -> top.add("@paused").style(Styles.outlineLabel).pad(8f)).growX();
}); });
@@ -273,37 +283,6 @@ public class HudFragment extends Fragment{
.update(label -> label.color.set(Color.orange).lerp(Color.scarlet, Mathf.absin(Time.time(), 2f, 1f)))).touchable(Touchable.disabled); .update(label -> label.color.set(Color.orange).lerp(Color.scarlet, Mathf.absin(Time.time(), 2f, 1f)))).touchable(Touchable.disabled);
}); });
//paused table for when the player is out of time
parent.fill(t -> {
t.top().visible(() -> state.isOutOfTime());
t.table(Styles.black5, top -> {
//TODO localize
top.add(sectorText).style(Styles.outlineLabel).color(Pal.accent).update(l -> {
l.color.a = Mathf.absin(Time.globalTime(), 7f, 1f);
l.setText(sectorText);
}).colspan(2);
top.row();
top.defaults().pad(2).size(150f, 54f);
//TODO localize
top.button("Skip", () -> {
universe.runTurn();
state.set(State.playing);
//announce turn info only when something is skipped.
ui.announce("[accent][[ Turn " + universe.turn() + " ]\n[scarlet]" + attackedSectors.size + "[lightgray] sector(s) attacked.");
});
//TODO localize
top.button("Switch Sectors", () -> {
ui.paused.runExitSave();
//switch to first attacked sector
control.playSector(attackedSectors.first());
}).disabled(b -> attackedSectors.isEmpty());
}).margin(8).growX();
});
//tutorial text //tutorial text
parent.fill(t -> { parent.fill(t -> {
Runnable resize = () -> { Runnable resize = () -> {

View File

@@ -1,3 +1,3 @@
org.gradle.daemon=true org.gradle.daemon=true
org.gradle.jvmargs=-Xms256m -Xmx1024m org.gradle.jvmargs=-Xms256m -Xmx1024m
archash=f4e823e80a634226c617e30f2d67d61562b8faaa archash=8278e148026dab6b5f74ded2ed2be76a22418c76