Per-unit cap (still broken)

This commit is contained in:
Anuken
2020-07-21 15:43:02 -04:00
parent 4ef0143928
commit 5c9e005397
20 changed files with 3758 additions and 1996 deletions

View File

@@ -4,6 +4,7 @@ import arc.math.geom.*;
import mindustry.*;
import mindustry.game.*;
import mindustry.gen.*;
import mindustry.type.*;
import java.util.*;
@@ -11,6 +12,7 @@ import java.util.*;
public class TeamIndexProcess implements AsyncProcess{
private QuadTree<Unit>[] trees = new QuadTree[Team.all.length];
private int[] counts = new int[Team.all.length];
private int[][] typeCounts = new int[Team.all.length][0];
public QuadTree<Unit> tree(Team team){
if(trees[team.id] == null) trees[team.id] = new QuadTree<>(Vars.world.getQuadBounds(new Rect()));
@@ -22,8 +24,18 @@ public class TeamIndexProcess implements AsyncProcess{
return counts[team.id];
}
public void updateCount(Team team, int amount){
public int countType(Team team, UnitType type){
return typeCounts[team.id].length < type.id ? 0 : typeCounts[team.id][type.id];
}
public void updateCount(Team team, UnitType type, int amount){
int tid = type.id;
counts[team.id] += amount;
if(typeCounts[team.id].length < tid){
typeCounts[team.id] = new int[Vars.content.units().size];
}
typeCounts[team.id][tid] += amount;
}
@Override
@@ -39,13 +51,16 @@ public class TeamIndexProcess implements AsyncProcess{
if(trees[team.id] != null){
trees[team.id].clear();
}
Arrays.fill(typeCounts[team.id], 0);
}
Arrays.fill(counts, 0);
for(Unit unit : Groups.unit){
tree(unit.team).insert(unit);
counts[unit.team.id] ++;
updateCount(unit.team, unit.type(), 1);
}
}

View File

@@ -1284,6 +1284,8 @@ public class Blocks implements ContentList{
health = 1100;
itemCapacity = 4000;
size = 3;
unitCapModifier = 8;
}};
coreFoundation = new CoreBlock("core-foundation"){{
@@ -1293,6 +1295,8 @@ public class Blocks implements ContentList{
health = 2000;
itemCapacity = 9000;
size = 4;
unitCapModifier = 16;
}};
coreNucleus = new CoreBlock("core-nucleus"){{
@@ -1302,6 +1306,8 @@ public class Blocks implements ContentList{
health = 4000;
itemCapacity = 13000;
size = 5;
unitCapModifier = 24;
}};
vault = new StorageBlock("vault"){{
@@ -1411,7 +1417,6 @@ public class Blocks implements ContentList{
Liquids.cryofluid, Bullets.cryoShot,
Liquids.oil, Bullets.oilShot
);
targetAir = false;
size = 2;
recoilAmount = 0f;
reloadTime = 2f;

View File

@@ -349,7 +349,7 @@ public class UnitTypes implements ContentList{
despawnEffect = Fx.none;
width = 0.54f;
lifetime = 35f;
knockback = -1f;
knockback = -1.2f;
}};
}});
@@ -368,7 +368,7 @@ public class UnitTypes implements ContentList{
despawnEffect = Fx.none;
width = 0.4f;
lifetime = 25f;
knockback = -0.5f;
knockback = -0.6f;
}};
}});
}};

View File

@@ -6,6 +6,7 @@ import mindustry.annotations.Annotations.*;
import mindustry.content.*;
import mindustry.game.*;
import mindustry.gen.*;
import mindustry.type.*;
import mindustry.world.*;
import static mindustry.Vars.*;
@@ -29,8 +30,8 @@ public class Units{
}
/** @return whether a new instance of a unit of this team can be created. */
public static boolean canCreate(Team team){
return teamIndex.count(team) < getCap(team);
public static boolean canCreate(Team team, UnitType type){
return teamIndex.countType(team, type) < getCap(team);
}
public static int getCap(Team team){

View File

@@ -147,12 +147,12 @@ abstract class UnitComp implements Healthc, Physicsc, Hitboxc, Statusc, Teamc, I
@Override
public void add(){
teamIndex.updateCount(team, 1);
teamIndex.updateCount(team, type, 1);
}
@Override
public void remove(){
teamIndex.updateCount(team, -1);
teamIndex.updateCount(team, type, -1);
controller.removed(base());
}

View File

@@ -28,6 +28,7 @@ import java.util.*;
public class Fonts{
private static ObjectIntMap<String> unicodeIcons = new ObjectIntMap<>();
private static ObjectMap<String, String> stringIcons = new ObjectMap<>();
public static BitmapFont def;
public static BitmapFont outline;
@@ -39,6 +40,10 @@ public class Fonts{
return unicodeIcons.get(content, 0);
}
public static String getUnicodeStr(String content){
return stringIcons.get(content, "");
}
/** Called from a static context to make the cursor appear immediately upon startup.*/
public static void loadSystemCursors(){
SystemCursor.arrow.set(Core.graphics.newCursor("cursor", cursorScale()));
@@ -86,6 +91,7 @@ public class Fonts{
}
unicodeIcons.put(nametex[0], ch);
stringIcons.put(nametex[0], ((char)ch) + "");
Glyph glyph = new Glyph();
glyph.id = ch;

View File

@@ -81,13 +81,6 @@ public class CoreBlock extends StorageBlock{
() -> Pal.items,
() -> e.items.total() / ((float)e.storageCapacity * content.items().count(i -> i.unlockedNow()))
));
bars.add("units", e ->
new Bar(
() -> Core.bundle.format("bar.units", teamIndex.count(e.team()), Units.getCap(e.team())),
() -> Pal.power,
() -> (float)teamIndex.count(e.team()) / Units.getCap(e.team())
));
}
@Override

View File

@@ -1,5 +1,6 @@
package mindustry.world.blocks.units;
import arc.*;
import arc.graphics.*;
import arc.graphics.g2d.*;
import arc.math.*;
@@ -7,6 +8,7 @@ import arc.scene.style.*;
import arc.scene.ui.layout.*;
import arc.struct.*;
import arc.util.*;
import arc.util.ArcAnnotate.*;
import arc.util.io.*;
import mindustry.*;
import mindustry.entities.*;
@@ -20,6 +22,8 @@ import mindustry.world.blocks.payloads.*;
import mindustry.world.consumers.*;
import mindustry.world.meta.*;
import static mindustry.Vars.*;
public class UnitFactory extends UnitBlock{
public int[] capacities;
@@ -61,7 +65,19 @@ public class UnitFactory extends UnitBlock{
@Override
public void setBars(){
super.setBars();
bars.add("progress", (UnitFactoryEntity entity) -> new Bar("bar.progress", Pal.ammo, entity::fraction));
bars.add("progress", (UnitFactoryEntity e) -> new Bar("bar.progress", Pal.ammo, e::fraction));
bars.add("units", (UnitFactoryEntity e) ->
new Bar(
() -> e.unit() == null ? "[lightgray]" + Iconc.cancel :
Core.bundle.format("bar.unitcap",
Fonts.getUnicodeStr(e.unit().name),
teamIndex.countType(e.team, e.unit()),
Units.getCap(e.team)
),
() -> Pal.power,
() -> e.unit() == null ? 0f : (float)teamIndex.countType(e.team, e.unit()) / Units.getCap(e.team)
));
}
@Override
@@ -129,13 +145,14 @@ public class UnitFactory extends UnitBlock{
table.row();
table.table(t -> {
t.left();
t.image().update(i -> {
i.setDrawable(currentPlan == -1 ? Icon.cancel : reg.set(plans[currentPlan].unit.icon(Cicon.medium)));
i.setScaling(Scaling.fit);
i.setColor(currentPlan == -1 ? Color.lightGray : Color.white);
}).size(32).padBottom(-4).padRight(2);
t.label(() -> currentPlan == -1 ? "$none" : plans[currentPlan].unit.localizedName).color(Color.lightGray);
});
}).left();
}
@Override
@@ -182,7 +199,7 @@ public class UnitFactory extends UnitBlock{
if(currentPlan != -1 && payload == null){
UnitPlan plan = plans[currentPlan];
if(progress >= plan.time && Units.canCreate(team)){
if(progress >= plan.time && consValid()){
progress = 0f;
payload = new UnitPayload(plan.unit.create(team));
@@ -196,6 +213,15 @@ public class UnitFactory extends UnitBlock{
}
}
@Override
public boolean shouldConsume(){
//do not consume when cap reached
if(currentPlan != -1 && !Units.canCreate(team, plans[currentPlan].unit)){
return false;
}
return super.shouldConsume();
}
@Override
public int getMaximumAccepted(Item item){
return capacities[item.id];
@@ -207,6 +233,10 @@ public class UnitFactory extends UnitBlock{
Structs.contains(plans[currentPlan].requirements, stack -> stack.item == item);
}
public @Nullable UnitType unit(){
return currentPlan == - 1 ? null : plans[currentPlan].unit;
}
@Override
public byte version(){
return 1;