diff --git a/core/src/mindustry/ai/Pathfinder.java b/core/src/mindustry/ai/Pathfinder.java index 50b8e83d83..06550d602c 100644 --- a/core/src/mindustry/ai/Pathfinder.java +++ b/core/src/mindustry/ai/Pathfinder.java @@ -238,7 +238,7 @@ public class Pathfinder implements Runnable{ } private PathTarget getTarget(Position position){ - return targetCache.getOr(position, () -> new PositionTarget(position)); + return targetCache.get(position, () -> new PositionTarget(position)); } /** @return whether a tile can be passed through by this team. Pathfinding thread only. */ diff --git a/core/src/mindustry/audio/LoopControl.java b/core/src/mindustry/audio/LoopControl.java index 6ed4035ef1..1b102ab0a4 100644 --- a/core/src/mindustry/audio/LoopControl.java +++ b/core/src/mindustry/audio/LoopControl.java @@ -16,7 +16,7 @@ public class LoopControl{ float baseVol = sound.calcFalloff(pos.getX(), pos.getY()); float vol = baseVol * volume; - SoundData data = sounds.getOr(sound, SoundData::new); + SoundData data = sounds.get(sound, SoundData::new); data.volume += vol; data.volume = Mathf.clamp(data.volume, 0f, 1f); data.total += baseVol; diff --git a/core/src/mindustry/core/NetClient.java b/core/src/mindustry/core/NetClient.java index 7aa36a7981..8117bedd62 100644 --- a/core/src/mindustry/core/NetClient.java +++ b/core/src/mindustry/core/NetClient.java @@ -130,11 +130,11 @@ public class NetClient implements ApplicationListener{ } public void addPacketHandler(String type, Cons handler){ - customPacketHandlers.getOr(type, Array::new).add(handler); + customPacketHandlers.get(type, Array::new).add(handler); } public Array> getPacketHandlers(String type){ - return customPacketHandlers.getOr(type, Array::new); + return customPacketHandlers.get(type, Array::new); } @Remote(targets = Loc.server, variants = Variant.both) diff --git a/core/src/mindustry/core/NetServer.java b/core/src/mindustry/core/NetServer.java index ac8c06e5fb..e36f61829f 100644 --- a/core/src/mindustry/core/NetServer.java +++ b/core/src/mindustry/core/NetServer.java @@ -393,7 +393,7 @@ public class NetServer implements ApplicationListener{ }else if(found.team() != player.team()){ player.sendMessage("[scarlet]Only players on your team can be kicked."); }else{ - Timekeeper vtime = cooldowns.getOr(player.uuid(), () -> new Timekeeper(voteCooldown)); + Timekeeper vtime = cooldowns.get(player.uuid(), () -> new Timekeeper(voteCooldown)); if(!vtime.get()){ player.sendMessage("[scarlet]You must wait " + voteCooldown/60 + " minutes between votekicks."); @@ -481,11 +481,11 @@ public class NetServer implements ApplicationListener{ } public void addPacketHandler(String type, Cons2 handler){ - customPacketHandlers.getOr(type, Array::new).add(handler); + customPacketHandlers.get(type, Array::new).add(handler); } public Array> getPacketHandlers(String type){ - return customPacketHandlers.getOr(type, Array::new); + return customPacketHandlers.get(type, Array::new); } public static void onDisconnect(Playerc player, String reason){ diff --git a/core/src/mindustry/entities/comp/HealthComp.java b/core/src/mindustry/entities/comp/HealthComp.java index 5840b7f23a..d906adb714 100644 --- a/core/src/mindustry/entities/comp/HealthComp.java +++ b/core/src/mindustry/entities/comp/HealthComp.java @@ -2,7 +2,6 @@ package mindustry.entities.comp; import arc.math.*; import arc.util.*; -import mindustry.*; import mindustry.annotations.Annotations.*; import mindustry.gen.*; @@ -53,7 +52,7 @@ abstract class HealthComp implements Entityc{ /** Damage and pierce armor. */ void damagePierce(float amount, boolean withEffect){ if(this instanceof Shieldc){ - damage(amount / Math.max(1f - ((Shieldc)this).armor(), Vars.minArmorDamage), withEffect); + damage(amount + ((Shieldc)this).armor(), withEffect); }else{ damage(amount, withEffect); } diff --git a/core/src/mindustry/entities/comp/PlayerComp.java b/core/src/mindustry/entities/comp/PlayerComp.java index 4789c97561..1516d7ad95 100644 --- a/core/src/mindustry/entities/comp/PlayerComp.java +++ b/core/src/mindustry/entities/comp/PlayerComp.java @@ -12,6 +12,7 @@ import mindustry.annotations.Annotations.*; import mindustry.core.*; import mindustry.entities.units.*; import mindustry.game.*; +import mindustry.game.EventType.*; import mindustry.gen.*; import mindustry.graphics.*; import mindustry.net.Administration.*; @@ -143,6 +144,8 @@ abstract class PlayerComp implements UnitController, Entityc, Syncc, Timerc, Dra unit.team(team); unit.controller(this); } + + Events.fire(new UnitChangeEvent((Playerc)this, unit)); } boolean dead(){ diff --git a/core/src/mindustry/entities/comp/ShieldComp.java b/core/src/mindustry/entities/comp/ShieldComp.java index 0d1257b02a..204efff128 100644 --- a/core/src/mindustry/entities/comp/ShieldComp.java +++ b/core/src/mindustry/entities/comp/ShieldComp.java @@ -23,7 +23,8 @@ abstract class ShieldComp implements Healthc, Posc{ @Override public void damage(float amount){ //apply armor - amount *= Math.max(1f - armor, minArmorDamage); + //TODO balancing of armor stats & minArmorDamage + amount = Math.max(amount - armor, minArmorDamage * amount); hitTime = 1f; diff --git a/core/src/mindustry/game/EventType.java b/core/src/mindustry/game/EventType.java index 86d4d58992..cad55d7931 100644 --- a/core/src/mindustry/game/EventType.java +++ b/core/src/mindustry/game/EventType.java @@ -289,14 +289,13 @@ public class EventType{ } } - //TODO rename - public static class MechChangeEvent{ + public static class UnitChangeEvent{ public final Playerc player; - public final UnitType mech; + public final Unitc unit; - public MechChangeEvent(Playerc player, UnitType mech){ + public UnitChangeEvent(Playerc player, Unitc unit){ this.player = player; - this.mech = mech; + this.unit = unit; } } diff --git a/core/src/mindustry/game/Stats.java b/core/src/mindustry/game/Stats.java index fcc388ea74..bc2147c7e8 100644 --- a/core/src/mindustry/game/Stats.java +++ b/core/src/mindustry/game/Stats.java @@ -5,9 +5,12 @@ import arc.struct.*; import arc.util.*; import mindustry.type.*; import mindustry.world.blocks.storage.CoreBlock.*; +import mindustry.world.modules.*; import static mindustry.Vars.*; +//TODO more stats: +//- units constructed public class Stats{ /** export window size in seconds */ private static final int exportWindow = 60; @@ -30,6 +33,8 @@ public class Stats{ public int buildingsDestroyed; /** Export statistics. */ public ObjectMap export = new ObjectMap<>(); + /** Items stored in all cores. Used for the campaign. */ + public ObjectIntMap coreItems = new ObjectIntMap<>(); /** Counter refresh state. */ private transient Interval time = new Interval(); @@ -43,19 +48,30 @@ public class Stats{ /** Updates export statistics. */ public void handleItemExport(Item item, int amount){ - export.getOr(item, ExportStat::new).counter += amount; + export.get(item, ExportStat::new).counter += amount; } /** Subtracts from export statistics. */ public void handleItemImport(Item item, int amount){ - export.getOr(item, ExportStat::new).counter -= amount; + export.get(item, ExportStat::new).counter -= amount; } public float getExport(Item item){ - return export.getOr(item, ExportStat::new).mean; + return export.get(item, ExportStat::new).mean; } public void update(){ + //update core items + CoreEntity entity = state.rules.defaultTeam.core(); + if(entity != null){ + ItemModule items = entity.items; + for(int i = 0; i < items.length(); i++){ + coreItems.put(content.item(i), items.get(i)); + } + }else{ + coreItems.clear(); + } + //create last stored core items if(lastCoreItems == null){ lastCoreItems = new int[content.items().size]; diff --git a/core/src/mindustry/mod/Mods.java b/core/src/mindustry/mod/Mods.java index 0212607b1a..9961eb8f8c 100644 --- a/core/src/mindustry/mod/Mods.java +++ b/core/src/mindustry/mod/Mods.java @@ -346,7 +346,7 @@ public class Mods implements Loadable{ for(Fi file : folder.list()){ if(file.name().startsWith("bundle") && file.extension().equals("properties")){ String name = file.nameWithoutExtension(); - bundles.getOr(name, Array::new).add(file); + bundles.get(name, Array::new).add(file); } } } @@ -357,7 +357,7 @@ public class Mods implements Loadable{ while(bundle != null){ String str = bundle.getLocale().toString(); String locale = "bundle" + (str.isEmpty() ? "" : "_" + str); - for(Fi file : bundles.getOr(locale, Array::new)){ + for(Fi file : bundles.get(locale, Array::new)){ try{ PropertiesUtils.load(bundle.getProperties(), file.reader()); }catch(Throwable e){ diff --git a/core/src/mindustry/ui/dialogs/MapsDialog.java b/core/src/mindustry/ui/dialogs/MapsDialog.java index 07b7bc5ce7..5a2f4aab34 100644 --- a/core/src/mindustry/ui/dialogs/MapsDialog.java +++ b/core/src/mindustry/ui/dialogs/MapsDialog.java @@ -80,7 +80,7 @@ public class MapsDialog extends BaseDialog{ //when you attempt to import a save, it will have no name, so generate one - String name = map.tags.getOr("name", () -> { + String name = map.tags.get("name", () -> { String result = "unknown"; int number = 0; while(maps.byName(result + number++) != null); diff --git a/core/src/mindustry/world/meta/BlockStats.java b/core/src/mindustry/world/meta/BlockStats.java index de7ac8d5b7..905d656b05 100644 --- a/core/src/mindustry/world/meta/BlockStats.java +++ b/core/src/mindustry/world/meta/BlockStats.java @@ -55,7 +55,7 @@ public class BlockStats{ map.put(stat.category, new OrderedMap<>()); } - map.get(stat.category).getOr(stat, Array::new).add(value); + map.get(stat.category).get(stat, Array::new).add(value); dirty = true; } diff --git a/desktop/src/mindustry/desktop/steam/SWorkshop.java b/desktop/src/mindustry/desktop/steam/SWorkshop.java index 5acd588f6d..9f064db597 100644 --- a/desktop/src/mindustry/desktop/steam/SWorkshop.java +++ b/desktop/src/mindustry/desktop/steam/SWorkshop.java @@ -51,7 +51,7 @@ public class SWorkshop implements SteamUGCCallback{ } public Array getWorkshopFiles(Class type){ - return workshopFiles.getOr(type, () -> new Array<>(0)); + return workshopFiles.get(type, () -> new Array<>(0)); } /** Publish a new item and submit an update for it.