mirror of
https://github.com/Anuken/Mindustry.git
synced 2025-02-10 10:47:13 +07:00
pain and suffering of various kinds
This commit is contained in:
parent
eb3e507a11
commit
2c8962cf5f
@ -27,7 +27,7 @@ allprojects {
|
||||
appName = 'Mindustry'
|
||||
gdxVersion = '1.9.8'
|
||||
roboVMVersion = '2.3.0'
|
||||
uCoreVersion = '367f0b0bab5936ce47155f17a74150451a0cddea'
|
||||
uCoreVersion = '33a2bc650be42394821acad06aceb6f9ba74e77a'
|
||||
|
||||
getVersionString = {
|
||||
String buildVersion = getBuildVersion()
|
||||
|
@ -20,7 +20,7 @@ public class Mindustry extends ModuleCore{
|
||||
|
||||
Log.setUseColors(false);
|
||||
BundleLoader.load();
|
||||
ContentLoader.load();
|
||||
content.load();
|
||||
|
||||
module(logic = new Logic());
|
||||
module(world = new World());
|
||||
|
@ -109,6 +109,7 @@ public class Vars{
|
||||
public static float baseControllerSpeed = 11f;
|
||||
//only if smoothCamera
|
||||
public static boolean snapCamera = true;
|
||||
public static ContentLoader content;
|
||||
public static GameState state;
|
||||
public static ThreadHandler threads;
|
||||
|
||||
@ -153,6 +154,8 @@ public class Vars{
|
||||
|
||||
Version.init();
|
||||
|
||||
content = new ContentLoader();
|
||||
|
||||
playerGroup = Entities.addGroup(Player.class).enableMapping();
|
||||
tileGroup = Entities.addGroup(TileEntity.class, false);
|
||||
bulletGroup = Entities.addGroup(Bullet.class).enableMapping();
|
||||
|
@ -1,13 +1,12 @@
|
||||
package io.anuke.mindustry.content;
|
||||
|
||||
import com.badlogic.gdx.utils.Array;
|
||||
import io.anuke.mindustry.content.bullets.*;
|
||||
import io.anuke.mindustry.content.fx.BulletFx;
|
||||
import io.anuke.mindustry.content.fx.Fx;
|
||||
import io.anuke.mindustry.content.fx.ShootFx;
|
||||
import io.anuke.mindustry.game.Content;
|
||||
import io.anuke.mindustry.type.AmmoType;
|
||||
import io.anuke.mindustry.game.ContentList;
|
||||
import io.anuke.mindustry.type.AmmoType;
|
||||
import io.anuke.mindustry.type.ContentType;
|
||||
|
||||
public class AmmoTypes implements ContentList{
|
||||
public static AmmoType bulletCopper, bulletDense, bulletThorium, bulletSilicon, bulletPyratite,
|
||||
@ -219,7 +218,7 @@ public class AmmoTypes implements ContentList{
|
||||
}
|
||||
|
||||
@Override
|
||||
public Array<? extends Content> getAll(){
|
||||
return AmmoType.all();
|
||||
public ContentType type(){
|
||||
return ContentType.ammo;
|
||||
}
|
||||
}
|
||||
|
@ -1,9 +1,8 @@
|
||||
package io.anuke.mindustry.content;
|
||||
|
||||
import com.badlogic.gdx.graphics.Color;
|
||||
import com.badlogic.gdx.utils.Array;
|
||||
import io.anuke.mindustry.game.Content;
|
||||
import io.anuke.mindustry.game.ContentList;
|
||||
import io.anuke.mindustry.type.ContentType;
|
||||
import io.anuke.mindustry.type.Item;
|
||||
import io.anuke.mindustry.type.ItemType;
|
||||
|
||||
@ -96,7 +95,7 @@ public class Items implements ContentList{
|
||||
}
|
||||
|
||||
@Override
|
||||
public Array<? extends Content> getAll(){
|
||||
return Item.all();
|
||||
public ContentType type(){
|
||||
return ContentType.item;
|
||||
}
|
||||
}
|
||||
|
@ -1,9 +1,8 @@
|
||||
package io.anuke.mindustry.content;
|
||||
|
||||
import com.badlogic.gdx.graphics.Color;
|
||||
import com.badlogic.gdx.utils.Array;
|
||||
import io.anuke.mindustry.game.Content;
|
||||
import io.anuke.mindustry.game.ContentList;
|
||||
import io.anuke.mindustry.type.ContentType;
|
||||
import io.anuke.mindustry.type.Liquid;
|
||||
|
||||
public class Liquids implements ContentList{
|
||||
@ -50,7 +49,7 @@ public class Liquids implements ContentList{
|
||||
}
|
||||
|
||||
@Override
|
||||
public Array<? extends Content> getAll(){
|
||||
return Liquid.all();
|
||||
public ContentType type(){
|
||||
return ContentType.liquid;
|
||||
}
|
||||
}
|
||||
|
@ -3,7 +3,6 @@ package io.anuke.mindustry.content;
|
||||
import com.badlogic.gdx.graphics.Color;
|
||||
import com.badlogic.gdx.graphics.g2d.TextureRegion;
|
||||
import com.badlogic.gdx.math.Rectangle;
|
||||
import com.badlogic.gdx.utils.Array;
|
||||
import io.anuke.mindustry.content.fx.BulletFx;
|
||||
import io.anuke.mindustry.content.fx.UnitFx;
|
||||
import io.anuke.mindustry.entities.Player;
|
||||
@ -13,11 +12,11 @@ import io.anuke.mindustry.entities.effect.Fire;
|
||||
import io.anuke.mindustry.entities.effect.Lightning;
|
||||
import io.anuke.mindustry.entities.units.BaseUnit;
|
||||
import io.anuke.mindustry.entities.units.types.AlphaDrone;
|
||||
import io.anuke.mindustry.game.Content;
|
||||
import io.anuke.mindustry.game.ContentList;
|
||||
import io.anuke.mindustry.graphics.Palette;
|
||||
import io.anuke.mindustry.graphics.Shaders;
|
||||
import io.anuke.mindustry.net.Net;
|
||||
import io.anuke.mindustry.game.ContentList;
|
||||
import io.anuke.mindustry.type.ContentType;
|
||||
import io.anuke.mindustry.type.Mech;
|
||||
import io.anuke.mindustry.world.Tile;
|
||||
import io.anuke.ucore.core.Core;
|
||||
@ -349,7 +348,7 @@ public class Mechs implements ContentList{
|
||||
}
|
||||
|
||||
@Override
|
||||
public Array<? extends Content> getAll(){
|
||||
return Mech.all();
|
||||
public ContentType type(){
|
||||
return ContentType.mech;
|
||||
}
|
||||
}
|
||||
|
@ -1,9 +1,8 @@
|
||||
package io.anuke.mindustry.content;
|
||||
|
||||
import com.badlogic.gdx.utils.Array;
|
||||
import io.anuke.mindustry.content.blocks.*;
|
||||
import io.anuke.mindustry.game.Content;
|
||||
import io.anuke.mindustry.game.ContentList;
|
||||
import io.anuke.mindustry.type.ContentType;
|
||||
import io.anuke.mindustry.type.ItemStack;
|
||||
import io.anuke.mindustry.type.Recipe;
|
||||
|
||||
@ -181,7 +180,7 @@ public class Recipes implements ContentList{
|
||||
}
|
||||
|
||||
@Override
|
||||
public Array<? extends Content> getAll(){
|
||||
return Recipe.all();
|
||||
public ContentType type(){
|
||||
return ContentType.recipe;
|
||||
}
|
||||
}
|
||||
|
@ -1,11 +1,10 @@
|
||||
package io.anuke.mindustry.content;
|
||||
|
||||
import com.badlogic.gdx.utils.Array;
|
||||
import io.anuke.mindustry.content.fx.EnvironmentFx;
|
||||
import io.anuke.mindustry.entities.StatusController.StatusEntry;
|
||||
import io.anuke.mindustry.entities.Unit;
|
||||
import io.anuke.mindustry.game.Content;
|
||||
import io.anuke.mindustry.game.ContentList;
|
||||
import io.anuke.mindustry.type.ContentType;
|
||||
import io.anuke.mindustry.type.StatusEffect;
|
||||
import io.anuke.ucore.core.Effects;
|
||||
import io.anuke.ucore.core.Timers;
|
||||
@ -149,7 +148,7 @@ public class StatusEffects implements ContentList{
|
||||
}
|
||||
|
||||
@Override
|
||||
public Array<? extends Content> getAll(){
|
||||
return StatusEffect.all();
|
||||
public ContentType type(){
|
||||
return ContentType.status;
|
||||
}
|
||||
}
|
||||
|
@ -1,12 +1,11 @@
|
||||
package io.anuke.mindustry.content;
|
||||
|
||||
import com.badlogic.gdx.graphics.Color;
|
||||
import com.badlogic.gdx.utils.Array;
|
||||
import com.badlogic.gdx.utils.ObjectSet;
|
||||
import io.anuke.mindustry.entities.units.UnitType;
|
||||
import io.anuke.mindustry.entities.units.types.*;
|
||||
import io.anuke.mindustry.game.Content;
|
||||
import io.anuke.mindustry.game.ContentList;
|
||||
import io.anuke.mindustry.type.ContentType;
|
||||
|
||||
public class UnitTypes implements ContentList{
|
||||
public static UnitType drone, alphaDrone, dagger, interceptor, monsoon, titan, fabricator;
|
||||
@ -93,7 +92,7 @@ public class UnitTypes implements ContentList{
|
||||
}
|
||||
|
||||
@Override
|
||||
public Array<? extends Content> getAll(){
|
||||
return UnitType.all();
|
||||
public ContentType type(){
|
||||
return ContentType.unit;
|
||||
}
|
||||
}
|
||||
|
@ -1,10 +1,9 @@
|
||||
package io.anuke.mindustry.content;
|
||||
|
||||
import com.badlogic.gdx.utils.Array;
|
||||
import io.anuke.mindustry.content.fx.Fx;
|
||||
import io.anuke.mindustry.content.fx.ShootFx;
|
||||
import io.anuke.mindustry.game.Content;
|
||||
import io.anuke.mindustry.game.ContentList;
|
||||
import io.anuke.mindustry.type.ContentType;
|
||||
import io.anuke.mindustry.type.Weapon;
|
||||
|
||||
public class Weapons implements ContentList{
|
||||
@ -153,7 +152,7 @@ public class Weapons implements ContentList{
|
||||
}
|
||||
|
||||
@Override
|
||||
public Array<? extends Content> getAll(){
|
||||
return Weapon.all();
|
||||
public ContentType type(){
|
||||
return ContentType.weapon;
|
||||
}
|
||||
}
|
||||
|
@ -1,14 +1,12 @@
|
||||
package io.anuke.mindustry.content.blocks;
|
||||
|
||||
import com.badlogic.gdx.utils.Array;
|
||||
import io.anuke.mindustry.game.Content;
|
||||
import io.anuke.mindustry.game.ContentList;
|
||||
import io.anuke.mindustry.world.Block;
|
||||
import io.anuke.mindustry.type.ContentType;
|
||||
|
||||
public abstract class BlockList implements ContentList{
|
||||
|
||||
@Override
|
||||
public Array<? extends Content> getAll(){
|
||||
return Block.all();
|
||||
public ContentType type(){
|
||||
return ContentType.item;
|
||||
}
|
||||
}
|
||||
|
@ -23,6 +23,7 @@ import io.anuke.ucore.scene.ui.layout.Table;
|
||||
import java.io.DataInputStream;
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.IOException;
|
||||
import static io.anuke.mindustry.Vars.*;
|
||||
|
||||
public class DebugBlocks extends BlockList implements ContentList{
|
||||
public static Block powerVoid, powerInfinite, itemSource, liquidSource, itemVoid;
|
||||
@ -105,7 +106,7 @@ public class DebugBlocks extends BlockList implements ContentList{
|
||||
public void buildTable(Tile tile, Table table){
|
||||
LiquidSourceEntity entity = tile.entity();
|
||||
|
||||
Array<Liquid> items = Liquid.all();
|
||||
Array<Liquid> items = content.liquids();
|
||||
|
||||
ButtonGroup<ImageButton> group = new ButtonGroup<>();
|
||||
Table cont = new Table();
|
||||
@ -159,7 +160,7 @@ public class DebugBlocks extends BlockList implements ContentList{
|
||||
|
||||
@Override
|
||||
public void read(DataInputStream stream) throws IOException{
|
||||
source = Liquid.getByID(stream.readByte());
|
||||
source = content.liquid(stream.readByte());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -6,6 +6,7 @@ import io.anuke.mindustry.type.Item;
|
||||
import io.anuke.mindustry.world.Block;
|
||||
import io.anuke.mindustry.world.blocks.Floor;
|
||||
import io.anuke.mindustry.world.blocks.OreBlock;
|
||||
import static io.anuke.mindustry.Vars.*;
|
||||
|
||||
public class OreBlocks extends BlockList{
|
||||
private static final ObjectMap<Item, ObjectMap<Block, Block>> oreBlockMap = new ObjectMap<>();
|
||||
@ -25,7 +26,7 @@ public class OreBlocks extends BlockList{
|
||||
ObjectMap<Block, Block> map = new ObjectMap<>();
|
||||
oreBlockMap.put(item, map);
|
||||
|
||||
for(Block block : Block.all()){
|
||||
for(Block block : content.blocks()){
|
||||
if(block instanceof Floor && ((Floor) block).hasOres){
|
||||
map.put(block, new OreBlock(item, (Floor) block));
|
||||
}
|
||||
|
@ -1,14 +1,12 @@
|
||||
package io.anuke.mindustry.content.bullets;
|
||||
|
||||
import com.badlogic.gdx.utils.Array;
|
||||
import io.anuke.mindustry.entities.bullet.BulletType;
|
||||
import io.anuke.mindustry.game.Content;
|
||||
import io.anuke.mindustry.game.ContentList;
|
||||
import io.anuke.mindustry.type.ContentType;
|
||||
|
||||
public abstract class BulletList implements ContentList{
|
||||
|
||||
@Override
|
||||
public Array<? extends Content> getAll(){
|
||||
return BulletType.all();
|
||||
public ContentType type(){
|
||||
return ContentType.bullet;
|
||||
}
|
||||
}
|
||||
|
@ -14,9 +14,8 @@ import io.anuke.mindustry.entities.bullet.LiquidBulletType;
|
||||
import io.anuke.mindustry.entities.effect.Fire;
|
||||
import io.anuke.mindustry.entities.effect.ItemDrop;
|
||||
import io.anuke.mindustry.entities.effect.Lightning;
|
||||
import io.anuke.mindustry.graphics.Palette;
|
||||
import io.anuke.mindustry.game.ContentList;
|
||||
import io.anuke.mindustry.type.Item;
|
||||
import io.anuke.mindustry.graphics.Palette;
|
||||
import io.anuke.mindustry.world.Tile;
|
||||
import io.anuke.mindustry.world.blocks.distribution.MassDriver.DriverBulletData;
|
||||
import io.anuke.ucore.core.Effects;
|
||||
@ -28,6 +27,7 @@ import io.anuke.ucore.graphics.Shapes;
|
||||
import io.anuke.ucore.util.Angles;
|
||||
import io.anuke.ucore.util.Mathf;
|
||||
|
||||
import static io.anuke.mindustry.Vars.content;
|
||||
import static io.anuke.mindustry.Vars.world;
|
||||
|
||||
public class TurretBullets extends BulletList implements ContentList{
|
||||
@ -328,7 +328,7 @@ public class TurretBullets extends BulletList implements ContentList{
|
||||
if(amountDropped > 0){
|
||||
float angle = b.angle() + Mathf.range(100f);
|
||||
float vs = Mathf.random(0f, 4f);
|
||||
ItemDrop.create(Item.getByID(i), amountDropped, b.x, b.y, Angles.trnsx(angle, vs), Angles.trnsy(angle, vs));
|
||||
ItemDrop.create(content.item(i), amountDropped, b.x, b.y, Angles.trnsx(angle, vs), Angles.trnsy(angle, vs));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,13 +1,12 @@
|
||||
package io.anuke.mindustry.content.fx;
|
||||
|
||||
import com.badlogic.gdx.utils.Array;
|
||||
import io.anuke.mindustry.game.Content;
|
||||
import io.anuke.mindustry.game.ContentList;
|
||||
import io.anuke.mindustry.type.ContentType;
|
||||
|
||||
public abstract class FxList implements ContentList{
|
||||
|
||||
@Override
|
||||
public Array<? extends Content> getAll(){
|
||||
return Array.with();
|
||||
public ContentType type(){
|
||||
return ContentType.effect;
|
||||
}
|
||||
}
|
||||
|
@ -1,6 +1,9 @@
|
||||
package io.anuke.mindustry.core;
|
||||
|
||||
import com.badlogic.gdx.utils.*;
|
||||
import com.badlogic.gdx.utils.Array;
|
||||
import com.badlogic.gdx.utils.IntMap;
|
||||
import com.badlogic.gdx.utils.ObjectMap;
|
||||
import com.badlogic.gdx.utils.ObjectSet;
|
||||
import io.anuke.mindustry.content.*;
|
||||
import io.anuke.mindustry.content.blocks.*;
|
||||
import io.anuke.mindustry.content.bullets.*;
|
||||
@ -17,10 +20,12 @@ import io.anuke.mindustry.entities.units.UnitType;
|
||||
import io.anuke.mindustry.game.Content;
|
||||
import io.anuke.mindustry.game.ContentList;
|
||||
import io.anuke.mindustry.game.MappableContent;
|
||||
import io.anuke.mindustry.type.*;
|
||||
import io.anuke.mindustry.type.ContentType;
|
||||
import io.anuke.mindustry.type.Item;
|
||||
import io.anuke.mindustry.type.Liquid;
|
||||
import io.anuke.mindustry.type.Recipe;
|
||||
import io.anuke.mindustry.world.Block;
|
||||
import io.anuke.mindustry.world.ColorMapper;
|
||||
import io.anuke.ucore.core.Effects;
|
||||
import io.anuke.ucore.function.Consumer;
|
||||
import io.anuke.ucore.util.Log;
|
||||
|
||||
@ -28,13 +33,15 @@ import io.anuke.ucore.util.Log;
|
||||
* Loads all game content.
|
||||
* Call load() before doing anything with content.
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public class ContentLoader{
|
||||
private static boolean loaded = false;
|
||||
private static ObjectSet<Array<? extends Content>> contentSet = new OrderedSet<>();
|
||||
private static OrderedMap<ContentType, Array<Content>> contentMap = new OrderedMap<>();
|
||||
private static ObjectMap<ContentType, ObjectMap<String, MappableContent>> contentNameMap = new ObjectMap<>();
|
||||
private static ObjectSet<Consumer<Content>> initialization = new ObjectSet<>();
|
||||
private static ContentList[] content = {
|
||||
private boolean loaded = false;
|
||||
|
||||
private ObjectMap<String, MappableContent>[] contentNameMap = new ObjectMap[ContentType.values().length];
|
||||
private Array<Content>[] contentMap = new Array[ContentType.values().length];
|
||||
private IntMap<IntMap<MappableContent>> temporaryMapper;
|
||||
private ObjectSet<Consumer<Content>> initialization = new ObjectSet<>();
|
||||
private ContentList[] content = {
|
||||
//effects
|
||||
new BlockFx(),
|
||||
new BulletFx(),
|
||||
@ -96,10 +103,8 @@ public class ContentLoader{
|
||||
new Recipes(),
|
||||
};
|
||||
|
||||
/**
|
||||
* Creates all content types.
|
||||
*/
|
||||
public static void load(){
|
||||
/**Creates all content types.*/
|
||||
public void load(){
|
||||
if(loaded){
|
||||
Log.info("Content already loaded, skipping.");
|
||||
return;
|
||||
@ -107,51 +112,63 @@ public class ContentLoader{
|
||||
|
||||
registerTypes();
|
||||
|
||||
for(io.anuke.mindustry.game.ContentList list : content){
|
||||
list.load();
|
||||
for(ContentType type : ContentType.values()){
|
||||
contentMap[type.ordinal()] = new Array<>();
|
||||
contentNameMap[type.ordinal()] = new ObjectMap<>();
|
||||
}
|
||||
|
||||
for(ContentList list : content){
|
||||
if(list.getAll().size != 0){
|
||||
ContentType type = list.getAll().first().getContentType();
|
||||
|
||||
if(!contentMap.containsKey(type)){
|
||||
contentMap.put(type, new Array<>());
|
||||
contentNameMap.put(type, new ObjectMap<>());
|
||||
}
|
||||
|
||||
contentMap.get(type).addAll(list.getAll());
|
||||
for(Content c : list.getAll()){
|
||||
if(c instanceof MappableContent){
|
||||
contentNameMap.get(type).put(((MappableContent) c).getContentName(), (MappableContent) c);
|
||||
}
|
||||
}
|
||||
}
|
||||
contentSet.add(list.getAll());
|
||||
list.load();
|
||||
}
|
||||
|
||||
if(Block.all().size >= 256){
|
||||
throw new IllegalArgumentException("THE TIME HAS COME. More than 256 blocks have been created.");
|
||||
int total = 0;
|
||||
|
||||
for(ContentType type : ContentType.values()){
|
||||
|
||||
for(Content c : contentMap[type.ordinal()]){
|
||||
if(c instanceof MappableContent){
|
||||
String name = ((MappableContent) c).getContentName();
|
||||
if(contentNameMap[type.ordinal()].containsKey(name)){
|
||||
throw new IllegalArgumentException("Two content objects cannot have the same name! (issue: '" + name + "')");
|
||||
}
|
||||
contentNameMap[type.ordinal()].put(name, (MappableContent) c);
|
||||
}
|
||||
total ++;
|
||||
}
|
||||
}
|
||||
|
||||
//set up ID mapping
|
||||
for(int k = 0; k < contentMap.length; k ++){
|
||||
Array<Content> arr = contentMap[k];
|
||||
for(int i = 0; i < arr.size; i++){
|
||||
int id = arr.get(i).id;
|
||||
if(id < 0) id += 256;
|
||||
if(id != i){
|
||||
throw new IllegalArgumentException("Out-of-order IDs for content '" + arr.get(i) + "' (expected " + i + " but got " + id + ")");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(blocks().size >= 256){
|
||||
throw new ImpendingDoomException("THE TIME HAS COME. More than 256 blocks have been created.");
|
||||
}
|
||||
|
||||
Log.info("--- CONTENT INFO ---");
|
||||
Log.info("Blocks loaded: {0}\nItems loaded: {1}\nLiquids loaded: {2}\nUpgrades loaded: {3}\nUnits loaded: {4}\nAmmo types loaded: {5}\nBullet types loaded: {6}\nStatus effects loaded: {7}\nRecipes loaded: {8}\nEffects loaded: {9}\nTotal content classes: {10}",
|
||||
Block.all().size, Item.all().size, Liquid.all().size, Mech.all().size, UnitType.all().size,
|
||||
AmmoType.all().size, BulletType.all().size, StatusEffect.all().size, Recipe.all().size, Effects.all().size, content.length);
|
||||
|
||||
for(int k = 0; k < contentMap.length; k ++){
|
||||
Log.info("[{0}]: loaded {1}", ContentType.values()[k].name(), contentMap[k].size);
|
||||
}
|
||||
Log.info("Total content loaded: {0}", total);
|
||||
Log.info("-------------------");
|
||||
|
||||
loaded = true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Initializes all content with the specified function.
|
||||
*/
|
||||
public static void initialize(Consumer<Content> callable){
|
||||
/**Initializes all content with the specified function.*/
|
||||
public void initialize(Consumer<Content> callable){
|
||||
if(initialization.contains(callable)) return;
|
||||
|
||||
for(Array<? extends Content> arr : contentSet){
|
||||
for(Content content : arr){
|
||||
for(ContentType type : ContentType.values()){
|
||||
for(Content content : contentMap[type.ordinal()]){
|
||||
callable.accept(content);
|
||||
}
|
||||
}
|
||||
@ -159,26 +176,102 @@ public class ContentLoader{
|
||||
initialization.add(callable);
|
||||
}
|
||||
|
||||
public static void dispose(){
|
||||
public void dispose(){
|
||||
//TODO clear all content.
|
||||
}
|
||||
|
||||
public static OrderedMap<ContentType, Array<Content>> getContentMap(){
|
||||
public void handleContent(Content content){
|
||||
contentMap[content.getContentType().ordinal()].add(content);
|
||||
}
|
||||
|
||||
public void setTemporaryMapper(IntMap<IntMap<MappableContent>> temporaryMapper){
|
||||
this.temporaryMapper = temporaryMapper;
|
||||
}
|
||||
|
||||
public Array<Content>[] getContentMap(){
|
||||
return contentMap;
|
||||
}
|
||||
|
||||
public static MappableContent getByName(ContentType type, String name){
|
||||
if(!contentNameMap.containsKey(type)){
|
||||
public <T extends MappableContent> T getByName(ContentType type, String name){
|
||||
if(contentNameMap[type.ordinal()] == null){
|
||||
return null;
|
||||
}
|
||||
return contentNameMap.get(type).get(name);
|
||||
return (T)contentNameMap[type.ordinal()].get(name);
|
||||
}
|
||||
|
||||
public <T extends Content> T getByID(ContentType type, int id){
|
||||
if(temporaryMapper != null && temporaryMapper.containsKey(type.ordinal()) && temporaryMapper.get(type.ordinal()).containsKey(id)){
|
||||
return (T)temporaryMapper.get(type.ordinal()).get(id);
|
||||
}
|
||||
|
||||
if(id < 0){ //offset negative values by 256, as they are probably a product of byte overflow
|
||||
id += 256;
|
||||
}
|
||||
if(id >= contentMap[type.ordinal()].size || id < 0){
|
||||
throw new RuntimeException("No " + type.name() + " with ID '" + id + "' found!");
|
||||
}
|
||||
return (T)contentMap[type.ordinal()].get(id);
|
||||
}
|
||||
|
||||
public <T extends Content> Array<T> getBy(ContentType type){
|
||||
return (Array<T>) contentMap[type.ordinal()];
|
||||
}
|
||||
|
||||
//utility methods, just makes things a bit shorter
|
||||
|
||||
public Array<Block> blocks(){
|
||||
return getBy(ContentType.block);
|
||||
}
|
||||
|
||||
public Block block(int id){
|
||||
return (Block) getByID(ContentType.block, id);
|
||||
}
|
||||
|
||||
public Array<Recipe> recipes(){
|
||||
return getBy(ContentType.recipe);
|
||||
}
|
||||
|
||||
public Recipe recipe(int id){
|
||||
return (Recipe) getByID(ContentType.recipe, id);
|
||||
}
|
||||
|
||||
public Array<Item> items(){
|
||||
return getBy(ContentType.block);
|
||||
}
|
||||
|
||||
public Item item(int id){
|
||||
return (Item) getByID(ContentType.item, id);
|
||||
}
|
||||
|
||||
public Array<Liquid> liquids(){
|
||||
return getBy(ContentType.liquid);
|
||||
}
|
||||
|
||||
public Liquid liquid(int id){
|
||||
return (Liquid) getByID(ContentType.liquid, id);
|
||||
}
|
||||
|
||||
public Array<BulletType> bullets(){
|
||||
return getBy(ContentType.bullet);
|
||||
}
|
||||
|
||||
public BulletType bullet(int id){
|
||||
return (BulletType) getByID(ContentType.bullet, id);
|
||||
}
|
||||
|
||||
public Array<UnitType> units(){
|
||||
return getBy(ContentType.unit);
|
||||
}
|
||||
|
||||
public UnitType unit(int id){
|
||||
return (UnitType) getByID(ContentType.unit, id);
|
||||
}
|
||||
|
||||
/**
|
||||
* Registers sync IDs for all types of sync entities.
|
||||
* Do not register units here!
|
||||
*/
|
||||
private static void registerTypes(){
|
||||
private void registerTypes(){
|
||||
TypeTrait.registerType(Player.class, Player::new);
|
||||
TypeTrait.registerType(ItemDrop.class, ItemDrop::new);
|
||||
TypeTrait.registerType(Fire.class, Fire::new);
|
||||
@ -186,4 +279,8 @@ public class ContentLoader{
|
||||
TypeTrait.registerType(Bullet.class, Bullet::new);
|
||||
TypeTrait.registerType(Lightning.class, Lightning::new);
|
||||
}
|
||||
|
||||
private class ImpendingDoomException extends RuntimeException{
|
||||
public ImpendingDoomException(String s){ super(s); }
|
||||
}
|
||||
}
|
||||
|
@ -60,10 +60,10 @@ public class Control extends Module{
|
||||
|
||||
Effects.setShakeFalloff(10000f);
|
||||
|
||||
ContentLoader.initialize(Content::init);
|
||||
content.initialize(Content::init);
|
||||
Core.atlas = new Atlas("sprites.atlas");
|
||||
Core.atlas.setErrorRegion("error");
|
||||
ContentLoader.initialize(Content::load);
|
||||
content.initialize(Content::load);
|
||||
|
||||
db.load();
|
||||
|
||||
@ -270,8 +270,8 @@ public class Control extends Module{
|
||||
control.database().unlockContent(players[0].inventory.getItem().item);
|
||||
}
|
||||
|
||||
for(int i = 0; i < Recipe.all().size; i++){
|
||||
Recipe recipe = Recipe.all().get(i);
|
||||
for(int i = 0; i < content.recipes().size; i ++){
|
||||
Recipe recipe = content.recipes().get(i);
|
||||
if(!recipe.debugOnly && recipe.requirements != null && entity.items.has(recipe.requirements, 1.4f)){
|
||||
if(control.database().unlockContent(recipe)){
|
||||
ui.hudfrag.showUnlock(recipe);
|
||||
@ -283,7 +283,7 @@ public class Control extends Module{
|
||||
@Override
|
||||
public void dispose(){
|
||||
Platform.instance.onGameExit();
|
||||
ContentLoader.dispose();
|
||||
content.dispose();
|
||||
Net.dispose();
|
||||
ui.editor.dispose();
|
||||
inputs = new InputHandler[]{};
|
||||
|
@ -50,7 +50,7 @@ public class Logic extends Module{
|
||||
|
||||
for(Tile tile : state.teams.get(defaultTeam).cores){
|
||||
if(debug){
|
||||
for(Item item : Item.all()){
|
||||
for(Item item : content.items()){
|
||||
if(item.type == ItemType.material){
|
||||
tile.entity.items.set(item, 1000);
|
||||
}
|
||||
|
@ -10,6 +10,7 @@ import io.anuke.mindustry.world.blocks.Floor;
|
||||
import io.anuke.ucore.function.IntPositionConsumer;
|
||||
import io.anuke.ucore.util.Bits;
|
||||
|
||||
import static io.anuke.mindustry.Vars.content;
|
||||
import static io.anuke.mindustry.Vars.ui;
|
||||
|
||||
public enum EditorTool{
|
||||
@ -26,7 +27,7 @@ public enum EditorTool{
|
||||
bw = editor.getMap().read(x, y, DataPosition.wall);
|
||||
}
|
||||
|
||||
Block block = Block.getByID(bw == 0 ? bf : bw);
|
||||
Block block = content.block(bw == 0 ? bf : bw);
|
||||
editor.setDrawBlock(block);
|
||||
ui.editor.updateSelectedBlock();
|
||||
}
|
||||
|
@ -12,7 +12,7 @@ import io.anuke.mindustry.world.Block;
|
||||
import io.anuke.mindustry.world.blocks.Floor;
|
||||
import io.anuke.ucore.util.Bits;
|
||||
import io.anuke.ucore.util.Mathf;
|
||||
|
||||
import static io.anuke.mindustry.Vars.content;
|
||||
public class MapEditor{
|
||||
public static final int minMapSize = 128, maxMapSize = 512;
|
||||
public static final int[] brushSizes = {1, 2, 3, 4, 5, 9, 15};
|
||||
@ -137,7 +137,7 @@ public class MapEditor{
|
||||
|
||||
if(link != 0){
|
||||
removeLinked(worldx - (Bits.getLeftByte(link) - 8), worldy - (Bits.getRightByte(link) - 8));
|
||||
}else if(Block.getByID(block).isMultiblock()){
|
||||
}else if(content.block(block).isMultiblock()){
|
||||
removeLinked(worldx, worldy);
|
||||
}
|
||||
}
|
||||
@ -217,7 +217,7 @@ public class MapEditor{
|
||||
}
|
||||
|
||||
private void removeLinked(int x, int y){
|
||||
Block block = Block.getByID(map.read(x, y, DataPosition.wall));
|
||||
Block block = content.block(map.read(x, y, DataPosition.wall));
|
||||
|
||||
int offsetx = -(block.size - 1) / 2;
|
||||
int offsety = -(block.size - 1) / 2;
|
||||
|
@ -8,6 +8,7 @@ import com.badlogic.gdx.math.Vector2;
|
||||
import com.badlogic.gdx.utils.Align;
|
||||
import com.badlogic.gdx.utils.Disposable;
|
||||
import com.badlogic.gdx.utils.ObjectMap;
|
||||
import io.anuke.mindustry.Vars;
|
||||
import io.anuke.mindustry.content.blocks.StorageBlocks;
|
||||
import io.anuke.mindustry.core.Platform;
|
||||
import io.anuke.mindustry.game.Team;
|
||||
@ -362,7 +363,7 @@ public class MapEditorDialog extends Dialog implements Disposable{
|
||||
|
||||
public void updateSelectedBlock(){
|
||||
Block block = editor.getDrawBlock();
|
||||
for(int j = 0; j < Block.all().size; j++){
|
||||
for(int j = 0; j < content.blocks().size; j++){
|
||||
if(block.id == j && j < blockgroup.getButtons().size){
|
||||
blockgroup.getButtons().get(j).setChecked(true);
|
||||
break;
|
||||
@ -564,7 +565,7 @@ public class MapEditorDialog extends Dialog implements Disposable{
|
||||
|
||||
int i = 0;
|
||||
|
||||
for(Block block : Block.all()){
|
||||
for(Block block : Vars.content.blocks()){
|
||||
TextureRegion[] regions = block.getCompactIcon();
|
||||
if((block.synthetic() && (Recipe.getByResult(block) == null || !control.database().isUnlocked(Recipe.getByResult(block))))
|
||||
&& !debug && block != StorageBlocks.core){
|
||||
|
@ -17,6 +17,7 @@ import io.anuke.ucore.util.Bits;
|
||||
import io.anuke.ucore.util.Geometry;
|
||||
import io.anuke.ucore.util.Mathf;
|
||||
|
||||
import static io.anuke.mindustry.Vars.content;
|
||||
import static io.anuke.mindustry.Vars.tilesize;
|
||||
|
||||
public class MapRenderer implements Disposable{
|
||||
@ -108,8 +109,8 @@ public class MapRenderer implements Disposable{
|
||||
byte rotation = Bits.getLeftByte(btr);
|
||||
Team team = Team.all[Bits.getRightByte(btr)];
|
||||
|
||||
Block floor = Block.getByID(bf);
|
||||
Block wall = Block.getByID(bw);
|
||||
Block floor = content.block(bf);
|
||||
Block wall = content.block(bw);
|
||||
|
||||
TextureRegion region;
|
||||
|
||||
|
@ -20,6 +20,7 @@ import io.anuke.mindustry.graphics.Palette;
|
||||
import io.anuke.mindustry.graphics.Trail;
|
||||
import io.anuke.mindustry.net.Net;
|
||||
import io.anuke.mindustry.net.NetConnection;
|
||||
import io.anuke.mindustry.type.ContentType;
|
||||
import io.anuke.mindustry.type.ItemStack;
|
||||
import io.anuke.mindustry.type.Mech;
|
||||
import io.anuke.mindustry.type.Weapon;
|
||||
@ -765,13 +766,13 @@ public class Player extends Unit implements BuilderTrait, CarryTrait, ShooterTra
|
||||
byte mechid = stream.readByte();
|
||||
int index = stream.readByte();
|
||||
players[index].readSaveSuper(stream);
|
||||
players[index].mech = Mech.getByID(mechid);
|
||||
players[index].mech = content.getByID(ContentType.mech, mechid);
|
||||
players[index].dead = false;
|
||||
}else if(local){
|
||||
byte mechid = stream.readByte();
|
||||
stream.readByte();
|
||||
readSaveSuper(stream);
|
||||
mech = Mech.getByID(mechid);
|
||||
mech = content.getByID(ContentType.mech, mechid);
|
||||
dead = false;
|
||||
}
|
||||
}
|
||||
@ -807,7 +808,7 @@ public class Player extends Unit implements BuilderTrait, CarryTrait, ShooterTra
|
||||
boolean boosting = (bools & 4) != 0;
|
||||
boolean alt = (bools & 8) != 0;
|
||||
color.set(buffer.readInt());
|
||||
mech = Mech.getByID(buffer.readByte());
|
||||
mech = content.getByID(ContentType.mech, buffer.readByte());
|
||||
int mine = buffer.readInt();
|
||||
spawner = buffer.readInt();
|
||||
float baseRotation = buffer.readShort() / 2f;
|
||||
|
@ -3,6 +3,7 @@ package io.anuke.mindustry.entities;
|
||||
import com.badlogic.gdx.utils.Array;
|
||||
import io.anuke.mindustry.content.StatusEffects;
|
||||
import io.anuke.mindustry.entities.traits.Saveable;
|
||||
import io.anuke.mindustry.type.ContentType;
|
||||
import io.anuke.mindustry.type.StatusEffect;
|
||||
import io.anuke.ucore.core.Timers;
|
||||
import io.anuke.ucore.util.Pooling;
|
||||
@ -11,7 +12,7 @@ import io.anuke.ucore.util.ThreadArray;
|
||||
import java.io.DataInput;
|
||||
import java.io.DataOutput;
|
||||
import java.io.IOException;
|
||||
|
||||
import static io.anuke.mindustry.Vars.content;
|
||||
/**
|
||||
* Class for controlling status effects on an entity.
|
||||
*/
|
||||
@ -129,7 +130,7 @@ public class StatusController implements Saveable{
|
||||
byte id = stream.readByte();
|
||||
float time = stream.readShort() / 2f;
|
||||
StatusEntry entry = Pooling.obtain(StatusEntry.class);
|
||||
entry.set(StatusEffect.getByID(id), time);
|
||||
entry.set(content.getByID(ContentType.status, id), time);
|
||||
statuses.add(entry);
|
||||
}
|
||||
}
|
||||
|
@ -9,6 +9,8 @@ import java.io.DataInput;
|
||||
import java.io.DataOutput;
|
||||
import java.io.IOException;
|
||||
|
||||
import static io.anuke.mindustry.Vars.content;
|
||||
|
||||
public class UnitInventory implements Saveable{
|
||||
private final Unit unit;
|
||||
private ItemStack item = new ItemStack(Items.stone, 0);
|
||||
@ -32,7 +34,7 @@ public class UnitInventory implements Saveable{
|
||||
short iamount = stream.readShort();
|
||||
byte iid = stream.readByte();
|
||||
|
||||
item.item = Item.getByID(iid);
|
||||
item.item = content.item(iid);
|
||||
item.amount = iamount;
|
||||
}
|
||||
|
||||
|
@ -23,6 +23,7 @@ import java.io.DataOutput;
|
||||
import java.io.IOException;
|
||||
|
||||
import static io.anuke.mindustry.Vars.bulletGroup;
|
||||
import static io.anuke.mindustry.Vars.content;
|
||||
import static io.anuke.mindustry.Vars.world;
|
||||
|
||||
public class Bullet extends BulletEntity<BulletType> implements TeamTrait, SyncTrait{
|
||||
@ -149,7 +150,7 @@ public class Bullet extends BulletEntity<BulletType> implements TeamTrait, SyncT
|
||||
velocity.x = data.readFloat();
|
||||
velocity.y = data.readFloat();
|
||||
team = Team.all[data.readByte()];
|
||||
type = BulletType.getByID(data.readByte());
|
||||
type = content.bullet(data.readByte());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -1,6 +1,5 @@
|
||||
package io.anuke.mindustry.entities.bullet;
|
||||
|
||||
import com.badlogic.gdx.utils.Array;
|
||||
import io.anuke.mindustry.content.StatusEffects;
|
||||
import io.anuke.mindustry.content.fx.BulletFx;
|
||||
import io.anuke.mindustry.game.Content;
|
||||
@ -8,13 +7,20 @@ import io.anuke.mindustry.type.ContentType;
|
||||
import io.anuke.mindustry.type.StatusEffect;
|
||||
import io.anuke.mindustry.world.Tile;
|
||||
import io.anuke.ucore.core.Effects;
|
||||
import io.anuke.ucore.core.Effects.Effect;
|
||||
import io.anuke.ucore.entities.impl.BaseBulletType;
|
||||
import io.anuke.ucore.util.Translator;
|
||||
|
||||
public abstract class BulletType extends BaseBulletType<Bullet> implements Content{
|
||||
private static int lastid = 0;
|
||||
private static Array<BulletType> types = new Array<>();
|
||||
public abstract class BulletType extends Content implements BaseBulletType<Bullet>{
|
||||
public float lifetime = 100;
|
||||
public float speed = 1f;
|
||||
public float damage = 1;
|
||||
public float hitsize = 4;
|
||||
public float drawSize = 20f;
|
||||
public float drag = 0f;
|
||||
public boolean pierce;
|
||||
public Effect hiteffect = null, despawneffect = null;
|
||||
|
||||
public final int id;
|
||||
/**Knockback in velocity.*/
|
||||
public float knockback;
|
||||
/**Whether this bullet hits tiles.*/
|
||||
@ -36,29 +42,65 @@ public abstract class BulletType extends BaseBulletType<Bullet> implements Conte
|
||||
/**Whether velocity is inherited from the shooter.*/
|
||||
public boolean keepVelocity = true;
|
||||
|
||||
protected Translator vector = new Translator();
|
||||
|
||||
public BulletType(float speed, float damage){
|
||||
this.id = lastid++;
|
||||
this.speed = speed;
|
||||
this.damage = damage;
|
||||
lifetime = 40f;
|
||||
hiteffect = BulletFx.hitBulletSmall;
|
||||
despawneffect = BulletFx.hitBulletSmall;
|
||||
|
||||
types.add(this);
|
||||
}
|
||||
|
||||
public static BulletType getByID(int id){
|
||||
return types.get(id);
|
||||
}
|
||||
|
||||
public static Array<BulletType> all(){
|
||||
return types;
|
||||
}
|
||||
|
||||
public void hitTile(Bullet b, Tile tile){
|
||||
hit(b);
|
||||
}
|
||||
|
||||
@Override
|
||||
public float drawSize(){
|
||||
return 40;
|
||||
}
|
||||
|
||||
@Override
|
||||
public float lifetime(){
|
||||
return lifetime;
|
||||
}
|
||||
|
||||
@Override
|
||||
public float speed(){
|
||||
return speed;
|
||||
}
|
||||
|
||||
@Override
|
||||
public float damage(){
|
||||
return damage;
|
||||
}
|
||||
|
||||
@Override
|
||||
public float hitSize(){
|
||||
return hitSize();
|
||||
}
|
||||
|
||||
@Override
|
||||
public float drag(){
|
||||
return drag;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean pierce(){
|
||||
return pierce;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Effect hitEffect(){
|
||||
return hiteffect;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Effect despawnEffect(){
|
||||
return despawneffect;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void hit(Bullet b, float hitx, float hity){
|
||||
Effects.effect(hiteffect, hitx, hity, b.angle());
|
||||
@ -73,9 +115,4 @@ public abstract class BulletType extends BaseBulletType<Bullet> implements Conte
|
||||
public ContentType getContentType(){
|
||||
return ContentType.bullet;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Array<? extends Content> getAll(){
|
||||
return types;
|
||||
}
|
||||
}
|
||||
|
@ -228,7 +228,7 @@ public class ItemDrop extends SolidEntity implements SaveTrait, SyncTrait, DrawT
|
||||
public void readSave(DataInput data) throws IOException{
|
||||
x = data.readFloat();
|
||||
y = data.readFloat();
|
||||
item = Item.getByID(data.readByte());
|
||||
item = content.item(data.readByte());
|
||||
amount = data.readShort();
|
||||
add();
|
||||
}
|
||||
@ -244,7 +244,7 @@ public class ItemDrop extends SolidEntity implements SaveTrait, SyncTrait, DrawT
|
||||
@Override
|
||||
public void read(DataInput data, long time) throws IOException{
|
||||
interpolator.read(x, y, data.readFloat(), data.readFloat(), time);
|
||||
item = Item.getByID(data.readByte());
|
||||
item = content.item(data.readByte());
|
||||
amount = data.readShort();
|
||||
}
|
||||
}
|
||||
|
@ -36,6 +36,7 @@ import java.io.DataInput;
|
||||
import java.io.DataOutput;
|
||||
import java.io.IOException;
|
||||
|
||||
import static io.anuke.mindustry.Vars.content;
|
||||
import static io.anuke.mindustry.Vars.puddleGroup;
|
||||
import static io.anuke.mindustry.Vars.world;
|
||||
|
||||
@ -261,7 +262,7 @@ public class Puddle extends BaseEntity implements SaveTrait, Poolable, DrawTrait
|
||||
this.loadedPosition = stream.readInt();
|
||||
this.x = stream.readFloat();
|
||||
this.y = stream.readFloat();
|
||||
this.liquid = Liquid.getByID(stream.readByte());
|
||||
this.liquid = content.liquid(stream.readByte());
|
||||
this.amount = stream.readFloat();
|
||||
this.generation = stream.readByte();
|
||||
add();
|
||||
@ -304,7 +305,7 @@ public class Puddle extends BaseEntity implements SaveTrait, Poolable, DrawTrait
|
||||
public void read(DataInput data, long time) throws IOException{
|
||||
x = data.readFloat();
|
||||
y = data.readFloat();
|
||||
liquid = Liquid.getByID(data.readByte());
|
||||
liquid = content.liquid(data.readByte());
|
||||
targetAmount = data.readShort() / 4f;
|
||||
tile = world.tile(data.readInt());
|
||||
|
||||
|
@ -34,9 +34,7 @@ import java.io.DataOutput;
|
||||
import java.io.IOException;
|
||||
import java.util.Arrays;
|
||||
|
||||
import static io.anuke.mindustry.Vars.tilesize;
|
||||
import static io.anuke.mindustry.Vars.tmptr;
|
||||
import static io.anuke.mindustry.Vars.world;
|
||||
import static io.anuke.mindustry.Vars.*;
|
||||
|
||||
/**
|
||||
* Interface for units that build, break or mine things.
|
||||
@ -101,7 +99,7 @@ public interface BuilderTrait extends Entity{
|
||||
}else{ //place
|
||||
byte recipe = input.readByte();
|
||||
byte rotation = input.readByte();
|
||||
request = new BuildRequest(position % world.width(), position / world.width(), rotation, Recipe.getByID(recipe));
|
||||
request = new BuildRequest(position % world.width(), position / world.width(), rotation, content.recipe(recipe));
|
||||
}
|
||||
|
||||
request.progress = progress;
|
||||
|
@ -385,7 +385,7 @@ public abstract class BaseUnit extends Unit implements ShooterTrait{
|
||||
this.isWave = stream.readBoolean();
|
||||
this.spawner = stream.readInt();
|
||||
|
||||
this.type = UnitType.getByID(type);
|
||||
this.type = content.unit(type);
|
||||
add();
|
||||
}
|
||||
|
||||
@ -400,7 +400,7 @@ public abstract class BaseUnit extends Unit implements ShooterTrait{
|
||||
public void read(DataInput data, long time) throws IOException{
|
||||
float lastx = x, lasty = y, lastrot = rotation;
|
||||
super.readSave(data);
|
||||
this.type = UnitType.getByID(data.readByte());
|
||||
this.type = content.unit(data.readByte());
|
||||
this.spawner = data.readInt();
|
||||
|
||||
interpolator.read(lastx, lasty, x, y, time, rotation);
|
||||
|
@ -8,6 +8,7 @@ import io.anuke.mindustry.entities.TileEntity;
|
||||
import io.anuke.mindustry.entities.Units;
|
||||
import io.anuke.mindustry.game.Team;
|
||||
import io.anuke.mindustry.type.AmmoType;
|
||||
import io.anuke.mindustry.type.ContentType;
|
||||
import io.anuke.mindustry.type.Weapon;
|
||||
import io.anuke.mindustry.world.Tile;
|
||||
import io.anuke.mindustry.world.blocks.Floor;
|
||||
@ -21,6 +22,7 @@ import java.io.DataInput;
|
||||
import java.io.DataOutput;
|
||||
import java.io.IOException;
|
||||
|
||||
import static io.anuke.mindustry.Vars.content;
|
||||
import static io.anuke.mindustry.Vars.world;
|
||||
|
||||
public abstract class GroundUnit extends BaseUnit{
|
||||
@ -210,7 +212,7 @@ public abstract class GroundUnit extends BaseUnit{
|
||||
@Override
|
||||
public void read(DataInput data, long time) throws IOException{
|
||||
super.read(data, time);
|
||||
weapon = Weapon.getByID(data.readByte());
|
||||
weapon = content.getByID(ContentType.weapon, data.readByte());
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -221,7 +223,7 @@ public abstract class GroundUnit extends BaseUnit{
|
||||
|
||||
@Override
|
||||
public void readSave(DataInput stream) throws IOException{
|
||||
weapon = Weapon.getByID(stream.readByte());
|
||||
weapon = content.getByID(ContentType.weapon, stream.readByte());
|
||||
super.readSave(stream);
|
||||
}
|
||||
|
||||
|
@ -2,12 +2,10 @@ package io.anuke.mindustry.entities.units;
|
||||
|
||||
import com.badlogic.gdx.graphics.Color;
|
||||
import com.badlogic.gdx.graphics.g2d.TextureRegion;
|
||||
import com.badlogic.gdx.utils.Array;
|
||||
import com.badlogic.gdx.utils.ObjectSet;
|
||||
import io.anuke.mindustry.content.Items;
|
||||
import io.anuke.mindustry.content.Weapons;
|
||||
import io.anuke.mindustry.entities.traits.TypeTrait;
|
||||
import io.anuke.mindustry.game.Content;
|
||||
import io.anuke.mindustry.game.Team;
|
||||
import io.anuke.mindustry.game.UnlockableContent;
|
||||
import io.anuke.mindustry.type.ContentType;
|
||||
@ -22,15 +20,11 @@ import io.anuke.ucore.util.Log;
|
||||
import io.anuke.ucore.util.Strings;
|
||||
|
||||
//TODO merge unit type with mech
|
||||
public class UnitType implements UnlockableContent{
|
||||
private static byte lastid = 0;
|
||||
private static Array<UnitType> types = new Array<>();
|
||||
|
||||
public class UnitType extends UnlockableContent{
|
||||
protected final Supplier<? extends BaseUnit> constructor;
|
||||
|
||||
public final String name;
|
||||
public final String description;
|
||||
public final byte id;
|
||||
public float health = 60;
|
||||
public float hitsize = 5f;
|
||||
public float hitsizeTile = 4f;
|
||||
@ -55,13 +49,10 @@ public class UnitType implements UnlockableContent{
|
||||
public TextureRegion iconRegion, legRegion, baseRegion, region;
|
||||
|
||||
public <T extends BaseUnit> UnitType(String name, Class<T> type, Supplier<T> mainConstructor){
|
||||
this.id = lastid++;
|
||||
this.name = name;
|
||||
this.constructor = mainConstructor;
|
||||
this.description = Bundles.getOrNull("unit." + name + ".description");
|
||||
|
||||
types.add(this);
|
||||
|
||||
TypeTrait.registerType(type, mainConstructor);
|
||||
|
||||
if(!Bundles.has("unit." + this.name + ".name")){
|
||||
@ -70,19 +61,6 @@ public class UnitType implements UnlockableContent{
|
||||
}
|
||||
}
|
||||
|
||||
public static UnitType getByID(byte id){
|
||||
return types.get(id);
|
||||
}
|
||||
|
||||
public static Array<UnitType> all(){
|
||||
return types;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getID() {
|
||||
return id;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void displayInfo(Table table){
|
||||
ContentDisplay.displayUnit(table, this);
|
||||
@ -119,11 +97,6 @@ public class UnitType implements UnlockableContent{
|
||||
return name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Array<? extends Content> getAll(){
|
||||
return types;
|
||||
}
|
||||
|
||||
public BaseUnit create(Team team){
|
||||
BaseUnit unit = constructor.get();
|
||||
unit.init(this, team);
|
||||
|
@ -1,34 +1,37 @@
|
||||
package io.anuke.mindustry.game;
|
||||
|
||||
import com.badlogic.gdx.utils.Array;
|
||||
import io.anuke.mindustry.Vars;
|
||||
import io.anuke.mindustry.type.ContentType;
|
||||
|
||||
/**
|
||||
* Base interface for a content type that is loaded in {@link io.anuke.mindustry.core.ContentLoader}.
|
||||
*/
|
||||
public interface Content{
|
||||
|
||||
/**Base class for a content type that is loaded in {@link io.anuke.mindustry.core.ContentLoader}.*/
|
||||
public abstract class Content{
|
||||
public final byte id;
|
||||
|
||||
public Content(){
|
||||
this.id = (byte)Vars.content.getBy(getContentType()).size;
|
||||
Vars.content.handleContent(this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the type name of this piece of content.
|
||||
* This should return the same value for all instances of this content type.
|
||||
*/
|
||||
ContentType getContentType();
|
||||
public abstract ContentType getContentType();
|
||||
|
||||
/**
|
||||
* Returns a list of all instances of this content.
|
||||
*/
|
||||
Array<? extends Content> getAll();
|
||||
|
||||
/**
|
||||
* Called after all content is created. Do not use to load regions or texture data!
|
||||
*/
|
||||
default void init(){
|
||||
/**Called after all content is created. Do not use to load regions or texture data!*/
|
||||
public void init(){
|
||||
}
|
||||
|
||||
/**
|
||||
* Called after all content is created, only on non-headless versions.
|
||||
* Use for loading regions or other image data.
|
||||
*/
|
||||
default void load(){
|
||||
public void load(){
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString(){
|
||||
return getContentType().name() + "#" + id;
|
||||
}
|
||||
}
|
||||
|
@ -1,12 +1,12 @@
|
||||
package io.anuke.mindustry.game;
|
||||
|
||||
import com.badlogic.gdx.utils.Array;
|
||||
import io.anuke.mindustry.type.ContentType;
|
||||
|
||||
/**Interface for a list of content to be loaded in {@link io.anuke.mindustry.core.ContentLoader}.*/
|
||||
public interface ContentList{
|
||||
/**This method should create all the content.*/
|
||||
void load();
|
||||
|
||||
/**This method should return the list of the content of this type, for further loading.*/
|
||||
Array<? extends Content> getAll();
|
||||
/**This method should return the type of content being loaded.*/
|
||||
ContentType type();
|
||||
}
|
||||
|
@ -1,13 +1,16 @@
|
||||
package io.anuke.mindustry.game;
|
||||
|
||||
public interface MappableContent extends Content {
|
||||
public abstract class MappableContent extends Content {
|
||||
/**
|
||||
* Returns the unqiue name of this piece of content.
|
||||
* The name only needs to be unique for all content of this type.
|
||||
* Do not use IDs for names! Make sure this string stays constant with each update unless removed.
|
||||
* (e.g. having a recipe and a block, both with name "wall" is fine, as they are different types).
|
||||
*/
|
||||
String getContentName();
|
||||
public abstract String getContentName();
|
||||
|
||||
int getID();
|
||||
@Override
|
||||
public String toString(){
|
||||
return getContentName();
|
||||
}
|
||||
}
|
||||
|
@ -6,31 +6,31 @@ import io.anuke.ucore.scene.ui.layout.Table;
|
||||
import static io.anuke.mindustry.Vars.control;
|
||||
|
||||
/**Base interface for an unlockable content type.*/
|
||||
public interface UnlockableContent extends MappableContent{
|
||||
public abstract class UnlockableContent extends MappableContent{
|
||||
/**Returns the localized name of this content.*/
|
||||
String localizedName();
|
||||
public abstract String localizedName();
|
||||
|
||||
TextureRegion getContentIcon();
|
||||
public abstract TextureRegion getContentIcon();
|
||||
|
||||
/**This should show all necessary info about this content in the specified table.*/
|
||||
void displayInfo(Table table);
|
||||
public abstract void displayInfo(Table table);
|
||||
|
||||
/**Called when this content is unlocked. Use this to unlock other related content.*/
|
||||
default void onUnlock(){
|
||||
public void onUnlock(){
|
||||
}
|
||||
|
||||
/**Whether this content is always hidden in the content info dialog.*/
|
||||
default boolean isHidden(){
|
||||
public boolean isHidden(){
|
||||
return false;
|
||||
}
|
||||
|
||||
/**Lists the content that must be unlocked in order for this specific content to become unlocked. May return null.*/
|
||||
default UnlockableContent[] getDependencies(){
|
||||
public UnlockableContent[] getDependencies(){
|
||||
return null;
|
||||
}
|
||||
|
||||
/**Returns whether dependencies are satisfied for unlocking this content.*/
|
||||
default boolean canBeUnlocked(){
|
||||
public boolean canBeUnlocked(){
|
||||
UnlockableContent[] depend = getDependencies();
|
||||
if(depend == null){
|
||||
return true;
|
||||
|
@ -8,8 +8,6 @@ import io.anuke.mindustry.entities.Player;
|
||||
import io.anuke.mindustry.graphics.Palette;
|
||||
import io.anuke.mindustry.input.PlaceUtils.NormalizeDrawResult;
|
||||
import io.anuke.mindustry.input.PlaceUtils.NormalizeResult;
|
||||
import io.anuke.mindustry.maps.generation.StructureFormat;
|
||||
import io.anuke.mindustry.maps.generation.StructureFormat.StructBlock;
|
||||
import io.anuke.mindustry.net.Net;
|
||||
import io.anuke.mindustry.world.Block;
|
||||
import io.anuke.mindustry.world.Tile;
|
||||
@ -20,9 +18,7 @@ import io.anuke.ucore.core.KeyBinds;
|
||||
import io.anuke.ucore.core.Settings;
|
||||
import io.anuke.ucore.graphics.Draw;
|
||||
import io.anuke.ucore.graphics.Lines;
|
||||
import io.anuke.ucore.input.Input;
|
||||
import io.anuke.ucore.scene.ui.layout.Unit;
|
||||
import io.anuke.ucore.util.Log;
|
||||
import io.anuke.ucore.util.Mathf;
|
||||
|
||||
import static io.anuke.mindustry.Vars.*;
|
||||
@ -66,23 +62,6 @@ public class DesktopInput extends InputHandler{
|
||||
}
|
||||
}
|
||||
|
||||
void printArea(NormalizeResult result){
|
||||
StructBlock[][] blocks = new StructBlock[Math.abs(result.x2 - result.x) + 1][Math.abs(result.y2 - result.y) + 1];
|
||||
|
||||
for(int x = 0; x <= Math.abs(result.x2 - result.x); x++){
|
||||
for(int y = 0; y <= Math.abs(result.y2 - result.y); y++){
|
||||
int wx = result.x + x;
|
||||
int wy = result.y + y;
|
||||
|
||||
Block block = world.tile(wx, wy).block();
|
||||
|
||||
blocks[x][y] = new StructBlock(block == Blocks.blockpart ? Blocks.air : block, world.tile(wx, wy).getRotation());
|
||||
}
|
||||
}
|
||||
|
||||
Log.info(StructureFormat.writeBase64(blocks));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isDrawing(){
|
||||
return mode != none || recipe != null;
|
||||
@ -269,17 +248,12 @@ public class DesktopInput extends InputHandler{
|
||||
}
|
||||
}else if(mode == breaking){ //touch up while breaking, break everything in selection
|
||||
NormalizeResult result = PlaceUtils.normalizeArea(selectX, selectY, cursor.x, cursor.y, rotation, false, maxLength);
|
||||
for(int x = 0; x <= Math.abs(result.x2 - result.x); x++){
|
||||
for(int y = 0; y <= Math.abs(result.y2 - result.y); y++){
|
||||
int wx = selectX + x * Mathf.sign(cursor.x - selectX);
|
||||
int wy = selectY + y * Mathf.sign(cursor.y - selectY);
|
||||
|
||||
if(debug && Inputs.keyDown(Input.CONTROL_LEFT)){
|
||||
printArea(result);
|
||||
}else{
|
||||
for(int x = 0; x <= Math.abs(result.x2 - result.x); x++){
|
||||
for(int y = 0; y <= Math.abs(result.y2 - result.y); y++){
|
||||
int wx = selectX + x * Mathf.sign(cursor.x - selectX);
|
||||
int wy = selectY + y * Mathf.sign(cursor.y - selectY);
|
||||
|
||||
tryBreakBlock(wx, wy);
|
||||
}
|
||||
tryBreakBlock(wx, wy);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -13,6 +13,7 @@ import io.anuke.mindustry.maps.MapMeta;
|
||||
import io.anuke.mindustry.maps.MapTileData;
|
||||
import io.anuke.mindustry.maps.MapTileData.DataPosition;
|
||||
import io.anuke.mindustry.maps.MapTileData.TileDataMarker;
|
||||
import io.anuke.mindustry.type.ContentType;
|
||||
import io.anuke.mindustry.world.Block;
|
||||
import io.anuke.mindustry.world.ColorMapper;
|
||||
|
||||
@ -20,6 +21,7 @@ import java.io.DataInputStream;
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.OutputStream;
|
||||
import static io.anuke.mindustry.Vars.content;
|
||||
|
||||
/**
|
||||
* Reads and writes map files.
|
||||
@ -29,7 +31,7 @@ public class MapIO{
|
||||
private static IntIntMap defaultBlockMap = new IntIntMap();
|
||||
|
||||
private static void loadDefaultBlocks(){
|
||||
for(Block block : Block.all()){
|
||||
for(Block block : content.blocks()){
|
||||
defaultBlockMap.put(block.id, block.id);
|
||||
}
|
||||
}
|
||||
@ -44,8 +46,8 @@ public class MapIO{
|
||||
for(int y = 0; y < data.height(); y++){
|
||||
for(int x = 0; x < data.width(); x++){
|
||||
data.read(marker);
|
||||
Block floor = Block.getByID(marker.floor);
|
||||
Block wall = Block.getByID(marker.wall);
|
||||
Block floor = content.block(marker.floor);
|
||||
Block wall = content.block(marker.wall);
|
||||
int wallc = ColorMapper.getBlockColor(wall);
|
||||
if(wallc == 0 && (wall.update || wall.solid || wall.breakable)) wallc = Team.all[marker.team].intColor;
|
||||
wallc = wallc == 0 ? ColorMapper.getBlockColor(floor) : wallc;
|
||||
@ -146,7 +148,7 @@ public class MapIO{
|
||||
for(int i = 0; i < blocks; i++){
|
||||
short id = stream.readShort();
|
||||
String name = stream.readUTF();
|
||||
Block block = Block.getByName(name);
|
||||
Block block = content.getByName(ContentType.block, name);
|
||||
if(block == null){
|
||||
//Log.info("Map load info: No block with name {0} found.", name);
|
||||
block = Blocks.air;
|
||||
@ -169,8 +171,8 @@ public class MapIO{
|
||||
stream.writeUTF(entry.value);
|
||||
}
|
||||
|
||||
stream.writeShort(Block.all().size);
|
||||
for(Block block : Block.all()){
|
||||
stream.writeShort(content.blocks().size);
|
||||
for(Block block : content.blocks()){
|
||||
stream.writeShort(block.id);
|
||||
stream.writeUTF(block.name);
|
||||
}
|
||||
|
@ -2,9 +2,6 @@ package io.anuke.mindustry.io;
|
||||
|
||||
import com.badlogic.gdx.utils.Array;
|
||||
import com.badlogic.gdx.utils.IntMap;
|
||||
import com.badlogic.gdx.utils.ObjectMap;
|
||||
import com.badlogic.gdx.utils.ObjectMap.Entry;
|
||||
import io.anuke.mindustry.core.ContentLoader;
|
||||
import io.anuke.mindustry.game.Content;
|
||||
import io.anuke.mindustry.game.Difficulty;
|
||||
import io.anuke.mindustry.game.MappableContent;
|
||||
@ -14,6 +11,8 @@ import java.io.DataInputStream;
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.IOException;
|
||||
|
||||
import static io.anuke.mindustry.Vars.content;
|
||||
|
||||
public abstract class SaveFileVersion{
|
||||
public final int version;
|
||||
|
||||
@ -33,19 +32,19 @@ public abstract class SaveFileVersion{
|
||||
return new SaveMeta(version, time, playtime, build, sector, mode, map, wave, Difficulty.values()[difficulty]);
|
||||
}
|
||||
|
||||
public ObjectMap<ContentType, IntMap<MappableContent>> readContentHeader(DataInputStream stream) throws IOException{
|
||||
ObjectMap<ContentType, IntMap<MappableContent>> map = new ObjectMap<>();
|
||||
public IntMap<IntMap<MappableContent>> readContentHeader(DataInputStream stream) throws IOException{
|
||||
IntMap<IntMap<MappableContent>> map = new IntMap<>();
|
||||
|
||||
byte mapped = stream.readByte();
|
||||
for (int i = 0; i < mapped; i++) {
|
||||
ContentType type = ContentType.values()[stream.readByte()];
|
||||
map.put(type, new IntMap<>());
|
||||
map.put(type.ordinal(), new IntMap<>());
|
||||
short total = stream.readShort();
|
||||
for (int j = 0; j < total; j++) {
|
||||
byte id = stream.readByte();
|
||||
int id = stream.readUnsignedByte();
|
||||
String name = stream.readUTF();
|
||||
if(ContentLoader.getContentMap().get(type).size == 0) continue;
|
||||
map.get(type).put(id, ContentLoader.getByName(type, name));
|
||||
if(content.getContentMap()[type.ordinal()].size == 0) continue;
|
||||
map.get(type.ordinal()).put(id, content.getByName(type, name));
|
||||
}
|
||||
}
|
||||
|
||||
@ -53,24 +52,26 @@ public abstract class SaveFileVersion{
|
||||
}
|
||||
|
||||
public void writeContentHeader(DataOutputStream stream) throws IOException{
|
||||
ObjectMap<ContentType, Array<Content>> map = ContentLoader.getContentMap();
|
||||
Array<Content>[] map = content.getContentMap();
|
||||
|
||||
int mappable = 0;
|
||||
for(Entry<ContentType, Array<Content>> entry : map.entries()){
|
||||
if(entry.value.size > 0 && entry.value.first() instanceof MappableContent){
|
||||
for(int i =0; i < map.length; i ++){
|
||||
Array<Content> arr = map[i];
|
||||
if(arr.size > 0 && arr.first() instanceof MappableContent){
|
||||
mappable ++;
|
||||
}
|
||||
}
|
||||
|
||||
stream.writeByte(mappable);
|
||||
for(Entry<ContentType, Array<Content>> entry : map.entries()){
|
||||
if(entry.value.size > 0 && entry.value.first() instanceof MappableContent){
|
||||
stream.writeByte(entry.value.first().getContentType().ordinal());
|
||||
stream.writeShort(entry.value.size);
|
||||
for(Content c : entry.value){
|
||||
for(int i =0; i < map.length; i ++){
|
||||
Array<Content> arr = map[i];
|
||||
if(arr.size > 0 && arr.first() instanceof MappableContent){
|
||||
stream.writeByte(arr.first().getContentType().ordinal());
|
||||
stream.writeShort(arr.size);
|
||||
for(Content c : arr){
|
||||
MappableContent m = (MappableContent)c;
|
||||
if(m.getID() >= 128) throw new RuntimeException("Content " + c + " has ID > 127!");
|
||||
stream.writeByte(m.getID());
|
||||
if(m.id > 255) throw new RuntimeException("Content " + c + " has ID > 255!");
|
||||
stream.writeByte(m.id);
|
||||
stream.writeUTF(m.getContentName());
|
||||
}
|
||||
}
|
||||
|
@ -154,7 +154,7 @@ public class TypeIO{
|
||||
|
||||
@ReadClass(Block.class)
|
||||
public static Block readBlock(ByteBuffer buffer){
|
||||
return Block.getByID(buffer.get());
|
||||
return content.block(buffer.get());
|
||||
}
|
||||
|
||||
@WriteClass(KickReason.class)
|
||||
@ -224,7 +224,7 @@ public class TypeIO{
|
||||
|
||||
@ReadClass(Weapon.class)
|
||||
public static Weapon readWeapon(ByteBuffer buffer){
|
||||
return Weapon.getByID(buffer.get());
|
||||
return content.getByID(ContentType.weapon, buffer.get());
|
||||
}
|
||||
|
||||
@WriteClass(Mech.class)
|
||||
@ -234,7 +234,7 @@ public class TypeIO{
|
||||
|
||||
@ReadClass(Mech.class)
|
||||
public static Mech readMech(ByteBuffer buffer){
|
||||
return Mech.getByID(buffer.get());
|
||||
return content.getByID(ContentType.mech, buffer.get());
|
||||
}
|
||||
|
||||
@WriteClass(Liquid.class)
|
||||
@ -244,7 +244,7 @@ public class TypeIO{
|
||||
|
||||
@ReadClass(Liquid.class)
|
||||
public static Liquid readLiquid(ByteBuffer buffer){
|
||||
return Liquid.getByID(buffer.get());
|
||||
return content.liquid(buffer.get());
|
||||
}
|
||||
|
||||
@WriteClass(AmmoType.class)
|
||||
@ -254,7 +254,7 @@ public class TypeIO{
|
||||
|
||||
@ReadClass(AmmoType.class)
|
||||
public static AmmoType readAmmo(ByteBuffer buffer){
|
||||
return AmmoType.getByID(buffer.get());
|
||||
return content.getByID(ContentType.weapon, buffer.get());
|
||||
}
|
||||
|
||||
@WriteClass(BulletType.class)
|
||||
@ -264,7 +264,7 @@ public class TypeIO{
|
||||
|
||||
@ReadClass(BulletType.class)
|
||||
public static BulletType readBulletType(ByteBuffer buffer){
|
||||
return BulletType.getByID(buffer.get());
|
||||
return content.getByID(ContentType.bullet, buffer.get());
|
||||
}
|
||||
|
||||
@WriteClass(Item.class)
|
||||
@ -275,7 +275,7 @@ public class TypeIO{
|
||||
@ReadClass(Item.class)
|
||||
public static Item readItem(ByteBuffer buffer){
|
||||
byte id = buffer.get();
|
||||
return id == -1 ? null : Item.getByID(id);
|
||||
return id == -1 ? null : content.item(id);
|
||||
}
|
||||
|
||||
@WriteClass(Recipe.class)
|
||||
@ -285,7 +285,7 @@ public class TypeIO{
|
||||
|
||||
@ReadClass(Recipe.class)
|
||||
public static Recipe readRecipe(ByteBuffer buffer){
|
||||
return Recipe.getByID(buffer.get());
|
||||
return content.recipe(buffer.get());
|
||||
}
|
||||
|
||||
@WriteClass(String.class)
|
||||
@ -356,9 +356,9 @@ public class TypeIO{
|
||||
info.android = buffer.get() == 1;
|
||||
info.totalBlocksBroken = buffer.getInt();
|
||||
info.structureBlocksBroken = buffer.getInt();
|
||||
info.lastBlockBroken = Block.getByID(buffer.getInt());
|
||||
info.lastBlockBroken = content.block(buffer.getInt());
|
||||
info.totalBlocksPlaced = buffer.getInt();
|
||||
info.lastBlockPlaced = Block.getByID(buffer.getInt());
|
||||
info.lastBlockPlaced = content.block(buffer.getInt());
|
||||
byte[] uuid = new byte[8];
|
||||
buffer.get(uuid);
|
||||
|
||||
|
@ -1,16 +1,16 @@
|
||||
package io.anuke.mindustry.io.versions;
|
||||
|
||||
import com.badlogic.gdx.utils.IntMap;
|
||||
import com.badlogic.gdx.utils.ObjectMap;
|
||||
import com.badlogic.gdx.utils.TimeUtils;
|
||||
import io.anuke.mindustry.content.blocks.Blocks;
|
||||
import io.anuke.mindustry.content.blocks.StorageBlocks;
|
||||
import io.anuke.mindustry.entities.traits.SaveTrait;
|
||||
import io.anuke.mindustry.entities.traits.TypeTrait;
|
||||
import io.anuke.mindustry.game.*;
|
||||
import io.anuke.mindustry.game.Difficulty;
|
||||
import io.anuke.mindustry.game.GameMode;
|
||||
import io.anuke.mindustry.game.Team;
|
||||
import io.anuke.mindustry.game.Version;
|
||||
import io.anuke.mindustry.io.SaveFileVersion;
|
||||
import io.anuke.mindustry.maps.Map;
|
||||
import io.anuke.mindustry.type.ContentType;
|
||||
import io.anuke.mindustry.world.Tile;
|
||||
import io.anuke.mindustry.world.blocks.BlockPart;
|
||||
import io.anuke.ucore.core.Timers;
|
||||
@ -56,8 +56,7 @@ public class Save16 extends SaveFileVersion{
|
||||
state.wave = wave;
|
||||
state.wavetime = wavetime;
|
||||
|
||||
ObjectMap<ContentType, IntMap<MappableContent>> contentMap = readContentHeader(stream);
|
||||
//TODO implement
|
||||
content.setTemporaryMapper(readContentHeader(stream));
|
||||
|
||||
state.spawner.read(stream);
|
||||
|
||||
@ -151,6 +150,7 @@ public class Save16 extends SaveFileVersion{
|
||||
i += consecutives;
|
||||
}
|
||||
|
||||
content.setTemporaryMapper(null);
|
||||
world.endMapLoad();
|
||||
}
|
||||
|
||||
|
@ -34,6 +34,7 @@ import io.anuke.ucore.function.IntPositionConsumer;
|
||||
import io.anuke.ucore.function.TriFunction;
|
||||
import io.anuke.ucore.util.Geometry;
|
||||
import io.anuke.ucore.util.Mathf;
|
||||
import static io.anuke.mindustry.Vars.content;
|
||||
|
||||
public class FortressGenerator{
|
||||
private final static int coreDst = 120;
|
||||
@ -246,7 +247,7 @@ public class FortressGenerator{
|
||||
|
||||
Array<Block> find(Predicate<Block> pred){
|
||||
Array<Block> out = new Array<>();
|
||||
for(Block block : Block.all()){
|
||||
for(Block block : content.blocks()){
|
||||
if(pred.evaluate(block) && Recipe.getByResult(block) != null){
|
||||
out.add(block);
|
||||
}
|
||||
|
@ -1,97 +0,0 @@
|
||||
package io.anuke.mindustry.maps.generation;
|
||||
|
||||
import com.badlogic.gdx.utils.Base64Coder;
|
||||
import com.badlogic.gdx.utils.IntMap;
|
||||
import com.badlogic.gdx.utils.ObjectIntMap;
|
||||
import com.badlogic.gdx.utils.ObjectIntMap.Entry;
|
||||
import io.anuke.mindustry.content.blocks.Blocks;
|
||||
import io.anuke.mindustry.world.Block;
|
||||
|
||||
import java.io.*;
|
||||
|
||||
public class StructureFormat{
|
||||
|
||||
public static byte[] write(StructBlock[][] blocks){
|
||||
try{
|
||||
ByteArrayOutputStream out = new ByteArrayOutputStream();
|
||||
DataOutputStream stream = new DataOutputStream(out);
|
||||
|
||||
ObjectIntMap<Block> mapping = new ObjectIntMap<>();
|
||||
int lastid = 1;
|
||||
mapping.put(Blocks.air, 0);
|
||||
|
||||
for(int x = 0; x < blocks.length; x++){
|
||||
for(int y = 0; y < blocks[0].length; y++){
|
||||
Block block = blocks[x][y].block;
|
||||
if(!mapping.containsKey(block)){
|
||||
mapping.put(block, lastid++);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
stream.writeByte(mapping.size);
|
||||
for(Entry<Block> entry : mapping){
|
||||
stream.writeByte(entry.value);
|
||||
stream.writeUTF(entry.key.name);
|
||||
}
|
||||
|
||||
stream.writeByte(blocks.length);
|
||||
stream.writeByte(blocks[0].length);
|
||||
|
||||
for(int x = 0; x < blocks.length; x++){
|
||||
for(int y = 0; y < blocks[0].length; y++){
|
||||
StructBlock block = blocks[x][y];
|
||||
stream.writeByte(mapping.get(block.block, 0));
|
||||
stream.writeByte(block.rotation);
|
||||
}
|
||||
}
|
||||
|
||||
return out.toByteArray();
|
||||
|
||||
}catch(IOException e){
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
public static String writeBase64(StructBlock[][] blocks){
|
||||
return new String(Base64Coder.encode(write(blocks)));
|
||||
}
|
||||
|
||||
public static StructBlock[][] read(byte[] bytes){
|
||||
try{
|
||||
|
||||
DataInputStream stream = new DataInputStream(new ByteArrayInputStream(bytes));
|
||||
byte size = stream.readByte();
|
||||
IntMap<Block> map = new IntMap<>();
|
||||
for(int i = 0; i < size; i++){
|
||||
map.put(stream.readByte(), Block.getByName(stream.readUTF()));
|
||||
}
|
||||
|
||||
byte width = stream.readByte(), height = stream.readByte();
|
||||
StructBlock[][] blocks = new StructBlock[width][height];
|
||||
for(int x = 0; x < width; x++){
|
||||
for(int y = 0; y < height; y++){
|
||||
blocks[x][y] = new StructBlock(map.get(stream.readByte()), stream.readByte());
|
||||
}
|
||||
}
|
||||
|
||||
return blocks;
|
||||
}catch(IOException e){
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
public static StructBlock[][] read(String base64){
|
||||
return read(Base64Coder.decode(base64));
|
||||
}
|
||||
|
||||
public static class StructBlock{
|
||||
public final Block block;
|
||||
public final byte rotation;
|
||||
|
||||
public StructBlock(Block block, byte rotation){
|
||||
this.block = block;
|
||||
this.rotation = rotation;
|
||||
}
|
||||
}
|
||||
}
|
@ -8,7 +8,6 @@ import io.anuke.mindustry.entities.Player;
|
||||
import io.anuke.mindustry.entities.Unit;
|
||||
import io.anuke.mindustry.entities.traits.BuilderTrait.BuildRequest;
|
||||
import io.anuke.mindustry.game.Version;
|
||||
import io.anuke.mindustry.type.Recipe;
|
||||
import io.anuke.mindustry.world.Tile;
|
||||
import io.anuke.ucore.io.IOUtils;
|
||||
import io.anuke.ucore.util.Bundles;
|
||||
@ -16,6 +15,7 @@ import io.anuke.ucore.util.Mathf;
|
||||
|
||||
import java.nio.ByteBuffer;
|
||||
|
||||
import static io.anuke.mindustry.Vars.content;
|
||||
import static io.anuke.mindustry.Vars.world;
|
||||
|
||||
/**
|
||||
@ -187,7 +187,7 @@ public class Packets{
|
||||
buffer.put(request.remove ? (byte) 1 : 0);
|
||||
buffer.putInt(world.toPacked(request.x, request.y));
|
||||
if(!request.remove){
|
||||
buffer.put((byte) request.recipe.id);
|
||||
buffer.put(request.recipe.id);
|
||||
buffer.put((byte) request.rotation);
|
||||
}
|
||||
}
|
||||
@ -224,7 +224,7 @@ public class Packets{
|
||||
}else{ //place
|
||||
byte recipe = buffer.get();
|
||||
byte rotation = buffer.get();
|
||||
currentRequest = new BuildRequest(position % world.width(), position / world.width(), rotation, Recipe.getByID(recipe));
|
||||
currentRequest = new BuildRequest(position % world.width(), position / world.width(), rotation, content.recipe(recipe));
|
||||
}
|
||||
|
||||
requests.add(currentRequest);
|
||||
|
@ -1,16 +1,11 @@
|
||||
package io.anuke.mindustry.type;
|
||||
|
||||
import com.badlogic.gdx.utils.Array;
|
||||
import io.anuke.mindustry.content.fx.Fx;
|
||||
import io.anuke.mindustry.entities.bullet.BulletType;
|
||||
import io.anuke.mindustry.game.Content;
|
||||
import io.anuke.ucore.core.Effects.Effect;
|
||||
|
||||
public class AmmoType implements Content {
|
||||
private static int lastID = 0;
|
||||
private static Array<AmmoType> allTypes = new Array<>(32);
|
||||
|
||||
public final byte id;
|
||||
public class AmmoType extends Content {
|
||||
/**The item used. Always null if liquid isn't.*/
|
||||
public final Item item;
|
||||
/**The liquid used. Always null if item isn't.*/
|
||||
@ -33,11 +28,6 @@ public class AmmoType implements Content {
|
||||
/**Extra smoke effect created when shooting.*/
|
||||
public Effect smokeEffect = Fx.none;
|
||||
|
||||
{
|
||||
this.id = (byte) (lastID++);
|
||||
allTypes.add(this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates an AmmoType with no liquid or item. Used for power-based ammo.
|
||||
*/
|
||||
@ -69,14 +59,6 @@ public class AmmoType implements Content {
|
||||
this.quantityMultiplier = multiplier;
|
||||
}
|
||||
|
||||
public static Array<AmmoType> all(){
|
||||
return allTypes;
|
||||
}
|
||||
|
||||
public static AmmoType getByID(int id){
|
||||
return allTypes.get(id);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns maximum distance the bullet this ammo type has can travel.
|
||||
*/
|
||||
@ -88,9 +70,4 @@ public class AmmoType implements Content {
|
||||
public ContentType getContentType(){
|
||||
return ContentType.ammo;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Array<? extends Content> getAll(){
|
||||
return allTypes;
|
||||
}
|
||||
}
|
||||
|
@ -12,5 +12,6 @@ public enum ContentType {
|
||||
status,
|
||||
unit,
|
||||
ammo,
|
||||
weather
|
||||
weather,
|
||||
effect
|
||||
}
|
||||
|
@ -2,8 +2,6 @@ package io.anuke.mindustry.type;
|
||||
|
||||
import com.badlogic.gdx.graphics.Color;
|
||||
import com.badlogic.gdx.graphics.g2d.TextureRegion;
|
||||
import com.badlogic.gdx.utils.Array;
|
||||
import io.anuke.mindustry.game.Content;
|
||||
import io.anuke.mindustry.game.UnlockableContent;
|
||||
import io.anuke.mindustry.graphics.Palette;
|
||||
import io.anuke.mindustry.ui.ContentDisplay;
|
||||
@ -12,12 +10,8 @@ import io.anuke.ucore.scene.ui.layout.Table;
|
||||
import io.anuke.ucore.util.Bundles;
|
||||
import io.anuke.ucore.util.Log;
|
||||
import io.anuke.ucore.util.Strings;
|
||||
import io.anuke.ucore.util.ThreadArray;
|
||||
|
||||
public class Item implements Comparable<Item>, UnlockableContent{
|
||||
private static final ThreadArray<Item> items = new ThreadArray<>();
|
||||
|
||||
public final int id;
|
||||
public class Item extends UnlockableContent implements Comparable<Item>{
|
||||
public final String name;
|
||||
public final String description;
|
||||
public final Color color;
|
||||
@ -44,36 +38,20 @@ public class Item implements Comparable<Item>, UnlockableContent{
|
||||
public float cost = 3f;
|
||||
|
||||
public Item(String name, Color color){
|
||||
this.id = items.size;
|
||||
this.name = name;
|
||||
this.color = color;
|
||||
this.description = Bundles.getOrNull("item." + this.name + ".description");
|
||||
|
||||
items.add(this);
|
||||
|
||||
if(!Bundles.has("item." + this.name + ".name")){
|
||||
Log.err("Warning: item '" + name + "' is missing a localized name. Add the follow to bundle.properties:");
|
||||
Log.err("item." + this.name + ".name=" + Strings.capitalize(name.replace('-', '_')));
|
||||
}
|
||||
}
|
||||
|
||||
public static Array<Item> all(){
|
||||
return Item.items;
|
||||
}
|
||||
|
||||
public static Item getByID(int id){
|
||||
return items.get(id);
|
||||
}
|
||||
|
||||
public void load(){
|
||||
this.region = Draw.region("item-" + name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getID() {
|
||||
return id;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void displayInfo(Table table){
|
||||
ContentDisplay.displayItem(table, this);
|
||||
@ -108,9 +86,4 @@ public class Item implements Comparable<Item>, UnlockableContent{
|
||||
public ContentType getContentType(){
|
||||
return ContentType.item;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Array<? extends Content> getAll(){
|
||||
return all();
|
||||
}
|
||||
}
|
||||
|
@ -2,88 +2,47 @@ package io.anuke.mindustry.type;
|
||||
|
||||
import com.badlogic.gdx.graphics.Color;
|
||||
import com.badlogic.gdx.graphics.g2d.TextureRegion;
|
||||
import com.badlogic.gdx.utils.Array;
|
||||
import io.anuke.mindustry.content.StatusEffects;
|
||||
import io.anuke.mindustry.game.Content;
|
||||
import io.anuke.mindustry.game.UnlockableContent;
|
||||
import io.anuke.mindustry.ui.ContentDisplay;
|
||||
import io.anuke.ucore.graphics.Draw;
|
||||
import io.anuke.ucore.scene.ui.layout.Table;
|
||||
import io.anuke.ucore.util.Bundles;
|
||||
import io.anuke.ucore.util.ThreadArray;
|
||||
|
||||
public class Liquid implements UnlockableContent{
|
||||
private static final Array<Liquid> liquids = new ThreadArray<>();
|
||||
|
||||
public class Liquid extends UnlockableContent{
|
||||
public final Color color;
|
||||
public final String name;
|
||||
public final String description;
|
||||
public final int id;
|
||||
|
||||
/**
|
||||
* 0-1, 0 is completely inflammable, anything above that may catch fire when exposed to heat, 0.5+ is very flammable.
|
||||
*/
|
||||
/**0-1, 0 is completely inflammable, anything above that may catch fire when exposed to heat, 0.5+ is very flammable.*/
|
||||
public float flammability;
|
||||
/**
|
||||
* temperature: 0.5 is 'room' temperature, 0 is very cold, 1 is molten hot
|
||||
*/
|
||||
/**temperature: 0.5 is 'room' temperature, 0 is very cold, 1 is molten hot*/
|
||||
public float temperature = 0.5f;
|
||||
/**
|
||||
* how much heat this liquid can store. 0.75=water (high), anything lower is probably less dense and bad at cooling.
|
||||
*/
|
||||
/**how much heat this liquid can store. 0.75=water (high), anything lower is probably less dense and bad at cooling.*/
|
||||
public float heatCapacity = 0.5f;
|
||||
/**
|
||||
* how thick this liquid is. 0.5=water (relatively viscous), 1 would be something like tar (very slow)
|
||||
*/
|
||||
/**how thick this liquid is. 0.5=water (relatively viscous), 1 would be something like tar (very slow)*/
|
||||
public float viscosity = 0.5f;
|
||||
/**
|
||||
* how prone to exploding this liquid is, when heated. 0 = nothing, 1 = nuke
|
||||
*/
|
||||
/**how prone to exploding this liquid is, when heated. 0 = nothing, 1 = nuke*/
|
||||
public float explosiveness;
|
||||
/**
|
||||
* the burning color of this liquid
|
||||
*/
|
||||
/**the burning color of this liquid*/
|
||||
public Color flameColor = Color.valueOf("ffb763");
|
||||
/**
|
||||
* The associated status effect.
|
||||
*/
|
||||
/**The associated status effect.*/
|
||||
public StatusEffect effect = StatusEffects.none;
|
||||
/**
|
||||
* Pump tier. Controls which pumps can use this liquid.
|
||||
*/
|
||||
/**Pump tier. Controls which pumps can use this liquid.*/
|
||||
public int tier;
|
||||
/**
|
||||
* Displayed icon.
|
||||
*/
|
||||
/**Displayed icon.*/
|
||||
public TextureRegion iconRegion;
|
||||
|
||||
public Liquid(String name, Color color){
|
||||
this.name = name;
|
||||
this.color = new Color(color);
|
||||
|
||||
this.id = liquids.size;
|
||||
this.description = Bundles.getOrNull("liquid." + name + ".description");
|
||||
|
||||
Liquid.liquids.add(this);
|
||||
}
|
||||
|
||||
public boolean canExtinguish(){
|
||||
return flammability < 0.1f && temperature <= 0.5f;
|
||||
}
|
||||
|
||||
public static Array<Liquid> all(){
|
||||
return Liquid.liquids;
|
||||
}
|
||||
|
||||
public static Liquid getByID(int id){
|
||||
return liquids.get(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getID() {
|
||||
return id;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void load(){
|
||||
iconRegion = Draw.region("liquid-icon-" + name);
|
||||
@ -118,9 +77,4 @@ public class Liquid implements UnlockableContent{
|
||||
public ContentType getContentType(){
|
||||
return ContentType.liquid;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Array<? extends Content> getAll(){
|
||||
return all();
|
||||
}
|
||||
}
|
||||
|
@ -2,10 +2,8 @@ package io.anuke.mindustry.type;
|
||||
|
||||
import com.badlogic.gdx.graphics.Color;
|
||||
import com.badlogic.gdx.graphics.g2d.TextureRegion;
|
||||
import com.badlogic.gdx.utils.Array;
|
||||
import io.anuke.mindustry.content.Weapons;
|
||||
import io.anuke.mindustry.entities.Player;
|
||||
import io.anuke.mindustry.game.Content;
|
||||
import io.anuke.mindustry.game.UnlockableContent;
|
||||
import io.anuke.mindustry.graphics.Palette;
|
||||
import io.anuke.mindustry.ui.ContentDisplay;
|
||||
@ -16,11 +14,7 @@ import io.anuke.ucore.util.Bundles;
|
||||
import static io.anuke.mindustry.Vars.mobile;
|
||||
|
||||
//TODO merge unit type with mech
|
||||
public class Mech implements UnlockableContent{
|
||||
private static Array<Mech> mechs = new Array<>();
|
||||
private static byte lastid;
|
||||
|
||||
public final byte id;
|
||||
public class Mech extends UnlockableContent{
|
||||
public final String name;
|
||||
public final String description;
|
||||
|
||||
@ -50,19 +44,8 @@ public class Mech implements UnlockableContent{
|
||||
|
||||
public Mech(String name, boolean flying){
|
||||
this.flying = flying;
|
||||
this.id = lastid++;
|
||||
this.name = name;
|
||||
this.description = Bundles.get("mech." + name + ".description");
|
||||
|
||||
mechs.add(this);
|
||||
}
|
||||
|
||||
public static Array<Mech> all() {
|
||||
return mechs;
|
||||
}
|
||||
|
||||
public static Mech getByID(int id){
|
||||
return mechs.get(id);
|
||||
}
|
||||
|
||||
public String localizedName(){
|
||||
@ -87,11 +70,6 @@ public class Mech implements UnlockableContent{
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getID() {
|
||||
return id;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isHidden() {
|
||||
return !flying && mobile;
|
||||
@ -132,9 +110,4 @@ public class Mech implements UnlockableContent{
|
||||
public String toString(){
|
||||
return localizedName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Array<? extends Content> getAll(){
|
||||
return all();
|
||||
}
|
||||
}
|
||||
|
@ -5,7 +5,6 @@ import com.badlogic.gdx.utils.Array;
|
||||
import com.badlogic.gdx.utils.ObjectMap;
|
||||
import com.badlogic.gdx.utils.OrderedMap;
|
||||
import io.anuke.mindustry.Vars;
|
||||
import io.anuke.mindustry.game.Content;
|
||||
import io.anuke.mindustry.game.UnlockableContent;
|
||||
import io.anuke.mindustry.ui.ContentDisplay;
|
||||
import io.anuke.mindustry.world.Block;
|
||||
@ -21,12 +20,9 @@ import java.util.Arrays;
|
||||
|
||||
import static io.anuke.mindustry.Vars.*;
|
||||
|
||||
public class Recipe implements UnlockableContent{
|
||||
private static int lastid;
|
||||
private static Array<Recipe> allRecipes = new Array<>();
|
||||
public class Recipe extends UnlockableContent{
|
||||
private static ObjectMap<Block, Recipe> recipeMap = new ObjectMap<>();
|
||||
|
||||
public final int id;
|
||||
public final Block result;
|
||||
public final ItemStack[] requirements;
|
||||
public final Category category;
|
||||
@ -40,7 +36,6 @@ public class Recipe implements UnlockableContent{
|
||||
private Block[] blockDependencies;
|
||||
|
||||
public Recipe(Category category, Block result, ItemStack... requirements){
|
||||
this.id = lastid++;
|
||||
this.result = result;
|
||||
this.requirements = requirements;
|
||||
this.category = category;
|
||||
@ -54,7 +49,6 @@ public class Recipe implements UnlockableContent{
|
||||
|
||||
this.cost = timeToPlace;
|
||||
|
||||
allRecipes.add(this);
|
||||
recipeMap.put(result, this);
|
||||
}
|
||||
|
||||
@ -68,7 +62,7 @@ public class Recipe implements UnlockableContent{
|
||||
}
|
||||
|
||||
r.clear();
|
||||
for(Recipe recipe : allRecipes){
|
||||
for(Recipe recipe : content.recipes()){
|
||||
if(recipe.category == category && (Vars.control.database().isUnlocked(recipe) || (debug && recipe.debugOnly))){
|
||||
r.add(recipe);
|
||||
}
|
||||
@ -80,29 +74,17 @@ public class Recipe implements UnlockableContent{
|
||||
*/
|
||||
public static void getByCategory(Category category, Array<Recipe> r){
|
||||
r.clear();
|
||||
for(Recipe recipe : allRecipes){
|
||||
for(Recipe recipe : content.recipes()){
|
||||
if(recipe.category == category){
|
||||
r.add(recipe);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static Array<Recipe> all(){
|
||||
return allRecipes;
|
||||
}
|
||||
|
||||
public static Recipe getByResult(Block block){
|
||||
return recipeMap.get(block);
|
||||
}
|
||||
|
||||
public static Recipe getByID(int id){
|
||||
if(id < 0 || id >= allRecipes.size){
|
||||
return null;
|
||||
}else{
|
||||
return allRecipes.get(id);
|
||||
}
|
||||
}
|
||||
|
||||
public Recipe setPad(){
|
||||
this.isPad = true;
|
||||
return this;
|
||||
@ -118,11 +100,6 @@ public class Recipe implements UnlockableContent{
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getID() {
|
||||
return id;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isHidden(){
|
||||
return debugOnly || (desktopOnly && mobile);
|
||||
@ -199,9 +176,4 @@ public class Recipe implements UnlockableContent{
|
||||
this.blockDependencies = dependencies;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Array<? extends Content> getAll(){
|
||||
return allRecipes;
|
||||
}
|
||||
}
|
||||
|
@ -1,52 +1,28 @@
|
||||
package io.anuke.mindustry.type;
|
||||
|
||||
import com.badlogic.gdx.utils.Array;
|
||||
import com.badlogic.gdx.utils.ObjectSet;
|
||||
import io.anuke.mindustry.entities.StatusController.StatusEntry;
|
||||
import io.anuke.mindustry.entities.Unit;
|
||||
import io.anuke.mindustry.game.Content;
|
||||
|
||||
public class StatusEffect implements Content{
|
||||
private static final Array<StatusEffect> array = new Array<>();
|
||||
private static int lastid;
|
||||
|
||||
/**
|
||||
* Duration of this status effect in ticks at maximum power.
|
||||
*/
|
||||
public class StatusEffect extends Content{
|
||||
/**Duration of this status effect in ticks at maximum power.*/
|
||||
public final float baseDuration;
|
||||
public final int id;
|
||||
|
||||
public float damageMultiplier = 1f; //damage dealt
|
||||
public float armorMultiplier = 1f; //armor points
|
||||
public float speedMultiplier = 1f; //speed
|
||||
|
||||
/**
|
||||
* Set of 'opposite' effects, which will decrease the duration of this effect when applied.
|
||||
*/
|
||||
/**Set of 'opposite' effects, which will decrease the duration of this effect when applied.*/
|
||||
protected ObjectSet<StatusEffect> opposites = new ObjectSet<>();
|
||||
/**
|
||||
* The strength of time decrease when met with an opposite effect, as a fraction of the other's duration.
|
||||
*/
|
||||
/**The strength of time decrease when met with an opposite effect, as a fraction of the other's duration.*/
|
||||
protected float oppositeScale = 0.5f;
|
||||
|
||||
public StatusEffect(float baseDuration){
|
||||
this.baseDuration = baseDuration;
|
||||
|
||||
id = lastid++;
|
||||
array.add(this);
|
||||
}
|
||||
|
||||
public static StatusEffect getByID(int id){
|
||||
return array.get(id);
|
||||
}
|
||||
|
||||
public static Array<StatusEffect> all(){
|
||||
return array;
|
||||
}
|
||||
|
||||
/**
|
||||
* Runs every tick on the affected unit while time is greater than 0.
|
||||
*/
|
||||
/**Runs every tick on the affected unit while time is greater than 0.*/
|
||||
public void update(Unit unit, float time){
|
||||
}
|
||||
|
||||
@ -88,9 +64,4 @@ public class StatusEffect implements Content{
|
||||
public ContentType getContentType(){
|
||||
return ContentType.status;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Array<? extends Content> getAll(){
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
@ -1,7 +1,6 @@
|
||||
package io.anuke.mindustry.type;
|
||||
|
||||
import com.badlogic.gdx.graphics.g2d.TextureRegion;
|
||||
import com.badlogic.gdx.utils.Array;
|
||||
import io.anuke.annotations.Annotations.Loc;
|
||||
import io.anuke.annotations.Annotations.Remote;
|
||||
import io.anuke.mindustry.Vars;
|
||||
@ -19,11 +18,7 @@ import io.anuke.ucore.util.Angles;
|
||||
import io.anuke.ucore.util.Mathf;
|
||||
import io.anuke.ucore.util.Translator;
|
||||
|
||||
public class Weapon implements Content{
|
||||
private static Array<Weapon> weapons = new Array<>();
|
||||
private static byte lastid;
|
||||
|
||||
public final byte id;
|
||||
public class Weapon extends Content{
|
||||
public final String name;
|
||||
|
||||
/**minimum cursor distance from player, fixes 'cross-eyed' shooting.*/
|
||||
@ -58,9 +53,7 @@ public class Weapon implements Content{
|
||||
public TextureRegion equipRegion, region;
|
||||
|
||||
protected Weapon(String name){
|
||||
this.id = lastid ++;
|
||||
this.name = name;
|
||||
weapons.add(this);
|
||||
}
|
||||
|
||||
@Remote(targets = Loc.server, called = Loc.both, unreliable = true)
|
||||
@ -105,14 +98,6 @@ public class Weapon implements Content{
|
||||
shooter.getTimer().get(shooter.getShootTimer(left), weapon.reload);
|
||||
}
|
||||
|
||||
public static Array<Weapon> all() {
|
||||
return weapons;
|
||||
}
|
||||
|
||||
public static Weapon getByID(int id){
|
||||
return weapons.get(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void load(){
|
||||
equipRegion = Draw.region(name + "-equip");
|
||||
@ -124,11 +109,6 @@ public class Weapon implements Content{
|
||||
return ContentType.weapon;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Array<? extends Content> getAll() {
|
||||
return weapons;
|
||||
}
|
||||
|
||||
public AmmoType getAmmo(){
|
||||
return ammo;
|
||||
}
|
||||
|
@ -1,38 +1,17 @@
|
||||
package io.anuke.mindustry.type;
|
||||
|
||||
import com.badlogic.gdx.utils.Array;
|
||||
import io.anuke.mindustry.game.Content;
|
||||
|
||||
//TODO implement this class
|
||||
public class WeatherEvent implements Content{
|
||||
private static final Array<WeatherEvent> all = new Array<>();
|
||||
private static int lastid;
|
||||
|
||||
public final int id;
|
||||
//TODO implement-- should it even be content?
|
||||
public class WeatherEvent extends Content{
|
||||
public final String name;
|
||||
|
||||
public WeatherEvent(String name){
|
||||
this.id = lastid++;
|
||||
this.name = name;
|
||||
|
||||
all.add(this);
|
||||
}
|
||||
|
||||
public static Array<WeatherEvent> all(){
|
||||
return all;
|
||||
}
|
||||
|
||||
public static WeatherEvent getByID(int id){
|
||||
return all.get(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ContentType getContentType(){
|
||||
return ContentType.weather;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Array<? extends Content> getAll(){
|
||||
return all();
|
||||
}
|
||||
}
|
||||
|
@ -1,9 +1,7 @@
|
||||
package io.anuke.mindustry.ui.dialogs;
|
||||
|
||||
import com.badlogic.gdx.utils.Array;
|
||||
import com.badlogic.gdx.utils.OrderedMap;
|
||||
import io.anuke.mindustry.Vars;
|
||||
import io.anuke.mindustry.core.ContentLoader;
|
||||
import io.anuke.mindustry.game.Content;
|
||||
import io.anuke.mindustry.game.UnlockableContent;
|
||||
import io.anuke.mindustry.graphics.Palette;
|
||||
@ -15,6 +13,7 @@ import io.anuke.ucore.scene.ui.Tooltip;
|
||||
import io.anuke.ucore.scene.ui.layout.Table;
|
||||
import io.anuke.ucore.scene.utils.UIUtils;
|
||||
|
||||
import static io.anuke.mindustry.Vars.content;
|
||||
import static io.anuke.mindustry.Vars.control;
|
||||
|
||||
public class UnlocksDialog extends FloatingDialog{
|
||||
@ -35,13 +34,15 @@ public class UnlocksDialog extends FloatingDialog{
|
||||
table.margin(20);
|
||||
ScrollPane pane = new ScrollPane(table, "clear-black");
|
||||
|
||||
OrderedMap<ContentType, Array<Content>> allContent = ContentLoader.getContentMap();
|
||||
Array<Content>[] allContent = content.getContentMap();
|
||||
|
||||
for(ContentType key : allContent.orderedKeys()){
|
||||
Array<Content> array = allContent.get(key);
|
||||
for(int j =0; j< allContent.length; j ++){
|
||||
ContentType type = ContentType.values()[j];
|
||||
|
||||
Array<Content> array = allContent[j];
|
||||
if(array.size == 0 || !(array.first() instanceof UnlockableContent)) continue;
|
||||
|
||||
table.add("$content." + key + ".name").growX().left().color(Palette.accent);
|
||||
table.add("$content." + type.name() + ".name").growX().left().color(Palette.accent);
|
||||
table.row();
|
||||
table.addImage("white").growX().pad(5).padLeft(0).padRight(0).height(3).color(Palette.accent);
|
||||
table.row();
|
||||
|
@ -105,8 +105,8 @@ public class BlockInventoryFragment extends Fragment{
|
||||
|
||||
updateTablePosition();
|
||||
if(tile.block().hasItems){
|
||||
for(int i = 0; i < Item.all().size; i++){
|
||||
boolean has = tile.entity.items.has(Item.getByID(i));
|
||||
for(int i = 0; i < content.items().size; i++){
|
||||
boolean has = tile.entity.items.has(content.item(i));
|
||||
if(has != container.contains(i)){
|
||||
rebuild(false);
|
||||
}
|
||||
@ -123,8 +123,8 @@ public class BlockInventoryFragment extends Fragment{
|
||||
|
||||
if(tile.block().hasItems){
|
||||
|
||||
for(int i = 0; i < Item.all().size; i++){
|
||||
Item item = Item.getByID(i);
|
||||
for(int i = 0; i < content.items().size; i++){
|
||||
Item item = content.item(i);
|
||||
if(!tile.entity.items.has(item)) continue;
|
||||
|
||||
container.add(i);
|
||||
|
@ -149,7 +149,7 @@ public class DebugFragment extends Fragment{
|
||||
t.row();
|
||||
t.addButton("spawn", () -> {
|
||||
FloatingDialog dialog = new FloatingDialog("debug spawn");
|
||||
for(UnitType type : UnitType.all()){
|
||||
for(UnitType type : content.units()){
|
||||
dialog.content().addImageButton("white", 40, () -> {
|
||||
BaseUnit unit = type.create(player.getTeam());
|
||||
unit.setWave();
|
||||
|
@ -1,10 +1,12 @@
|
||||
package io.anuke.mindustry.world;
|
||||
|
||||
import com.badlogic.gdx.utils.Array;
|
||||
import io.anuke.mindustry.Vars;
|
||||
import io.anuke.mindustry.content.fx.EnvironmentFx;
|
||||
import io.anuke.mindustry.entities.TileEntity;
|
||||
import io.anuke.mindustry.entities.Unit;
|
||||
import io.anuke.mindustry.entities.effect.Puddle;
|
||||
import io.anuke.mindustry.game.MappableContent;
|
||||
import io.anuke.mindustry.type.Item;
|
||||
import io.anuke.mindustry.type.Liquid;
|
||||
import io.anuke.mindustry.world.consumers.ConsumeItem;
|
||||
@ -16,7 +18,7 @@ import io.anuke.ucore.core.Timers;
|
||||
import io.anuke.ucore.util.Mathf;
|
||||
import io.anuke.ucore.util.Translator;
|
||||
|
||||
public abstract class BaseBlock{
|
||||
public abstract class BaseBlock extends MappableContent{
|
||||
public boolean hasItems;
|
||||
public boolean hasLiquids;
|
||||
public boolean hasPower;
|
||||
@ -234,8 +236,8 @@ public abstract class BaseBlock{
|
||||
|
||||
if(todump == null){
|
||||
|
||||
for(int ii = 0; ii < Item.all().size; ii++){
|
||||
Item item = Item.getByID(ii);
|
||||
for(int ii = 0; ii < Vars.content.items().size; ii++){
|
||||
Item item = Vars.content.item(ii);
|
||||
|
||||
if(other.getTeamID() == tile.getTeamID() && entity.items.has(item) && other.block().acceptItem(item, other, in) && canDump(tile, other, item)){
|
||||
other.block().handleItem(item, other, in);
|
||||
|
@ -3,7 +3,6 @@ package io.anuke.mindustry.world;
|
||||
import com.badlogic.gdx.graphics.Color;
|
||||
import com.badlogic.gdx.graphics.g2d.TextureRegion;
|
||||
import com.badlogic.gdx.utils.Array;
|
||||
import com.badlogic.gdx.utils.ObjectMap;
|
||||
import com.badlogic.gdx.utils.reflect.ClassReflection;
|
||||
import io.anuke.mindustry.entities.Damage;
|
||||
import io.anuke.mindustry.entities.Player;
|
||||
@ -13,7 +12,6 @@ import io.anuke.mindustry.entities.bullet.Bullet;
|
||||
import io.anuke.mindustry.entities.effect.Puddle;
|
||||
import io.anuke.mindustry.entities.effect.RubbleDecal;
|
||||
import io.anuke.mindustry.game.Content;
|
||||
import io.anuke.mindustry.game.MappableContent;
|
||||
import io.anuke.mindustry.game.UnlockableContent;
|
||||
import io.anuke.mindustry.graphics.CacheLayer;
|
||||
import io.anuke.mindustry.graphics.Layer;
|
||||
@ -34,15 +32,9 @@ import io.anuke.ucore.util.Mathf;
|
||||
|
||||
import static io.anuke.mindustry.Vars.*;
|
||||
|
||||
public class Block extends BaseBlock implements MappableContent {
|
||||
private static int lastid;
|
||||
private static Array<Block> blocks = new Array<>(140);
|
||||
private static ObjectMap<String, Block> map = new ObjectMap<>();
|
||||
|
||||
public class Block extends BaseBlock {
|
||||
/** internal name */
|
||||
public final String name;
|
||||
/** internal ID */
|
||||
public final int id;
|
||||
/** display name */
|
||||
public String formalName;
|
||||
/** Detailed description of the block. Can be as long as necesary. */
|
||||
@ -127,39 +119,13 @@ public class Block extends BaseBlock implements MappableContent {
|
||||
this.formalName = Bundles.get("block." + name + ".name", name);
|
||||
this.fullDescription = Bundles.getOrNull("block." + name + ".description");
|
||||
this.solid = false;
|
||||
this.id = lastid++;
|
||||
|
||||
if(map.containsKey(name)){
|
||||
throw new RuntimeException("Two blocks cannot have the same names! Problematic block: " + name);
|
||||
}
|
||||
|
||||
map.put(name, this);
|
||||
blocks.add(this);
|
||||
}
|
||||
|
||||
public static Array<Block> all(){
|
||||
return blocks;
|
||||
}
|
||||
|
||||
public static Block getByName(String name){
|
||||
return map.get(name);
|
||||
}
|
||||
|
||||
public static Block getByID(int id){
|
||||
if(id < 0){ //offset negative values by 256, as they are a product of byte overflow
|
||||
id += 256;
|
||||
}
|
||||
if(id >= blocks.size || id < 0){
|
||||
throw new RuntimeException("No block with ID '" + id + "' found!");
|
||||
}
|
||||
return blocks.get(id);
|
||||
}
|
||||
|
||||
/**Populates the array with all blocks that produce this content.*/
|
||||
public static void getByProduction(Array<Block> arr, Content content){
|
||||
public static void getByProduction(Array<Block> arr, Content result){
|
||||
arr.clear();
|
||||
for(Block block : Block.all()){
|
||||
if(block.produces.get() == content){
|
||||
for(Block block : content.<Block>getBy(ContentType.block)){
|
||||
if(block.produces.get() == result){
|
||||
arr.add(block);
|
||||
}
|
||||
}
|
||||
@ -212,8 +178,8 @@ public class Block extends BaseBlock implements MappableContent {
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getID() {
|
||||
return id;
|
||||
public ContentType getContentType(){
|
||||
return ContentType.block;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -350,7 +316,7 @@ public class Block extends BaseBlock implements MappableContent {
|
||||
tempColor.set(Palette.darkFlame);
|
||||
|
||||
if(hasItems){
|
||||
for(Item item : Item.all()){
|
||||
for(Item item : content.items()){
|
||||
int amount = tile.entity.items.get(item);
|
||||
explosiveness += item.explosiveness * amount;
|
||||
flammability += item.flammability * amount;
|
||||
@ -505,19 +471,4 @@ public class Block extends BaseBlock implements MappableContent {
|
||||
"entity.items.total", hasItems ? tile.entity.items.total() : null
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ContentType getContentType(){
|
||||
return ContentType.block;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Array<? extends Content> getAll(){
|
||||
return all();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString(){
|
||||
return name;
|
||||
}
|
||||
}
|
@ -7,6 +7,7 @@ import io.anuke.mindustry.content.blocks.Blocks;
|
||||
import io.anuke.mindustry.entities.Units;
|
||||
import io.anuke.mindustry.game.EventType.BlockBuildEvent;
|
||||
import io.anuke.mindustry.game.Team;
|
||||
import io.anuke.mindustry.type.ContentType;
|
||||
import io.anuke.mindustry.type.Recipe;
|
||||
import io.anuke.mindustry.world.blocks.BuildBlock.BuildEntity;
|
||||
import io.anuke.ucore.core.Events;
|
||||
@ -34,7 +35,7 @@ public class Build{
|
||||
|
||||
Block previous = tile.block();
|
||||
|
||||
Block sub = Block.getByName("build" + previous.size);
|
||||
Block sub = content.getByName(ContentType.block, "build" + previous.size);
|
||||
|
||||
tile.setBlock(sub);
|
||||
tile.<BuildEntity>entity().setDeconstruct(previous);
|
||||
@ -75,7 +76,7 @@ public class Build{
|
||||
Block result = recipe.result;
|
||||
Block previous = tile.block();
|
||||
|
||||
Block sub = Block.getByName("build" + result.size);
|
||||
Block sub = content.getByName(ContentType.block, "build" + result.size);
|
||||
|
||||
tile.setBlock(sub, rotation);
|
||||
tile.<BuildEntity>entity().setConstruct(previous, recipe);
|
||||
|
@ -1,14 +1,15 @@
|
||||
package io.anuke.mindustry.world;
|
||||
|
||||
import com.badlogic.gdx.graphics.Color;
|
||||
import com.badlogic.gdx.utils.Array;
|
||||
import com.badlogic.gdx.utils.IntMap;
|
||||
import com.badlogic.gdx.utils.ObjectIntMap;
|
||||
import io.anuke.mindustry.game.Content;
|
||||
import io.anuke.mindustry.game.Team;
|
||||
import io.anuke.mindustry.game.ContentList;
|
||||
import io.anuke.mindustry.game.Team;
|
||||
import io.anuke.mindustry.type.ContentType;
|
||||
import io.anuke.ucore.util.Mathf;
|
||||
|
||||
import static io.anuke.mindustry.Vars.content;
|
||||
|
||||
public class ColorMapper implements ContentList{
|
||||
private static IntMap<Block> blockMap = new IntMap<>();
|
||||
private static ObjectIntMap<Block> colorMap = new ObjectIntMap<>();
|
||||
@ -45,7 +46,7 @@ public class ColorMapper implements ContentList{
|
||||
|
||||
@Override
|
||||
public void load(){
|
||||
for(Block block : Block.all()){
|
||||
for(Block block : content.blocks()){
|
||||
int color = Color.rgba8888(block.minimapColor);
|
||||
if(color == 0) continue; //skip blocks that are not mapped
|
||||
|
||||
@ -55,7 +56,7 @@ public class ColorMapper implements ContentList{
|
||||
}
|
||||
|
||||
@Override
|
||||
public Array<? extends Content> getAll(){
|
||||
return new Array<>();
|
||||
public ContentType type(){
|
||||
return ContentType.mech;
|
||||
}
|
||||
}
|
||||
|
@ -4,6 +4,7 @@ import com.badlogic.gdx.utils.NumberUtils;
|
||||
import io.anuke.mindustry.type.Item;
|
||||
import io.anuke.ucore.core.Timers;
|
||||
import io.anuke.ucore.util.Bits;
|
||||
import static io.anuke.mindustry.Vars.*;
|
||||
|
||||
public class ItemBuffer{
|
||||
private final float speed;
|
||||
@ -35,7 +36,7 @@ public class ItemBuffer{
|
||||
float time = NumberUtils.intBitsToFloat(Bits.getLeftInt(l));
|
||||
|
||||
if(Timers.time() >= time + speed || Timers.time() < time){
|
||||
return Item.getByID(Bits.getLeftShort(Bits.getRightInt(l)));
|
||||
return content.item(Bits.getLeftShort(Bits.getRightInt(l)));
|
||||
}
|
||||
}
|
||||
return null;
|
||||
|
@ -54,15 +54,15 @@ public class Tile implements PosTrait, TargetTrait{
|
||||
|
||||
public Tile(int x, int y, byte floor, byte wall){
|
||||
this(x, y);
|
||||
this.floor = (Floor) Block.getByID(floor);
|
||||
this.wall = Block.getByID(wall);
|
||||
this.floor = (Floor) content.block(floor);
|
||||
this.wall = content.block(wall);
|
||||
changed();
|
||||
}
|
||||
|
||||
public Tile(int x, int y, byte floor, byte wall, byte rotation, byte team, byte elevation){
|
||||
this(x, y);
|
||||
this.floor = (Floor) Block.getByID(floor);
|
||||
this.wall = Block.getByID(wall);
|
||||
this.floor = (Floor) content.block(floor);
|
||||
this.wall = content.block(wall);
|
||||
this.rotation = rotation;
|
||||
this.setElevation(elevation);
|
||||
changed();
|
||||
|
@ -337,8 +337,8 @@ public class BuildBlock extends Block{
|
||||
}
|
||||
}
|
||||
|
||||
if(pid != -1) previous = Block.getByID(pid);
|
||||
if(rid != -1) recipe = Recipe.getByResult(Block.getByID(rid));
|
||||
if(pid != -1) previous = content.block(pid);
|
||||
if(rid != -1) recipe = Recipe.getByResult(content.block(rid));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -11,6 +11,7 @@ import io.anuke.ucore.scene.ui.ImageButton;
|
||||
import io.anuke.ucore.scene.ui.layout.Table;
|
||||
|
||||
import static io.anuke.mindustry.Vars.control;
|
||||
import static io.anuke.mindustry.Vars.*;
|
||||
|
||||
public interface SelectionTrait{
|
||||
|
||||
@ -20,7 +21,7 @@ public interface SelectionTrait{
|
||||
|
||||
default void buildItemTable(Table table, boolean nullItem, Supplier<Item> holder, Consumer<Item> consumer){
|
||||
|
||||
Array<Item> items = Item.all();
|
||||
Array<Item> items = content.items();
|
||||
|
||||
ButtonGroup<ImageButton> group = new ButtonGroup<>();
|
||||
Table cont = new Table();
|
||||
|
@ -15,6 +15,7 @@ import io.anuke.mindustry.graphics.Layer;
|
||||
import io.anuke.mindustry.graphics.Palette;
|
||||
import io.anuke.mindustry.type.AmmoEntry;
|
||||
import io.anuke.mindustry.type.AmmoType;
|
||||
import io.anuke.mindustry.type.ContentType;
|
||||
import io.anuke.mindustry.world.Block;
|
||||
import io.anuke.mindustry.world.Tile;
|
||||
import io.anuke.mindustry.world.meta.BlockFlag;
|
||||
@ -34,6 +35,7 @@ import java.io.DataInputStream;
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.IOException;
|
||||
|
||||
import static io.anuke.mindustry.Vars.content;
|
||||
import static io.anuke.mindustry.Vars.tilesize;
|
||||
|
||||
public abstract class Turret extends Block{
|
||||
@ -358,7 +360,7 @@ public abstract class Turret extends Block{
|
||||
public void read(DataInputStream stream) throws IOException{
|
||||
byte amount = stream.readByte();
|
||||
for(int i = 0; i < amount; i++){
|
||||
AmmoType type = AmmoType.getByID(stream.readByte());
|
||||
AmmoType type = content.getByID(ContentType.ammo, stream.readByte());
|
||||
short ta = stream.readShort();
|
||||
ammo.add(new AmmoEntry(type, ta));
|
||||
totalAmmo += ta;
|
||||
|
@ -23,6 +23,8 @@ import java.io.IOException;
|
||||
import static io.anuke.mindustry.Vars.itemSize;
|
||||
import static io.anuke.mindustry.Vars.tilesize;
|
||||
|
||||
import static io.anuke.mindustry.Vars.*;
|
||||
|
||||
public class Conveyor extends Block{
|
||||
private static final float itemSpace = 0.135f * 2.2f;
|
||||
private static final float offsetScl = 128f * 3f;
|
||||
@ -473,10 +475,10 @@ public class Conveyor extends Block{
|
||||
ItemPos set(long lvalue, short[] values){
|
||||
Bits.getShorts(lvalue, values);
|
||||
|
||||
if(values[0] >= Item.all().size || values[0] < 0)
|
||||
if(values[0] >= content.items().size || values[0] < 0)
|
||||
item = null;
|
||||
else
|
||||
item = Item.all().get(values[0]);
|
||||
item = content.items().get(values[0]);
|
||||
|
||||
x = values[1] / (float) Short.MAX_VALUE;
|
||||
y = ((float) values[2]) / Short.MAX_VALUE + 1f;
|
||||
|
@ -11,6 +11,8 @@ import io.anuke.ucore.core.Timers;
|
||||
import io.anuke.ucore.function.Consumer;
|
||||
import io.anuke.ucore.util.Bits;
|
||||
|
||||
import static io.anuke.mindustry.Vars.*;
|
||||
|
||||
public class Junction extends Block{
|
||||
protected float speed = 26; //frames taken to go through this junction
|
||||
protected int capacity = 32;
|
||||
@ -44,7 +46,7 @@ public class Junction extends Block{
|
||||
|
||||
int val = Bits.getRightInt(l);
|
||||
|
||||
Item item = Item.getByID(Bits.getLeftShort(val));
|
||||
Item item = content.item(Bits.getLeftShort(val));
|
||||
int direction = Bits.getRightShort(val);
|
||||
Tile dest = tile.getNearby(direction);
|
||||
|
||||
@ -108,7 +110,7 @@ public class Junction extends Block{
|
||||
long l = b.items[i];
|
||||
float time = NumberUtils.intBitsToFloat(Bits.getLeftInt(l));
|
||||
int val = Bits.getRightInt(l);
|
||||
Item item = Item.getByID(Bits.getLeftShort(val));
|
||||
Item item = content.item(Bits.getLeftShort(val));
|
||||
int direction = Bits.getRightShort(val);
|
||||
Tile dest = tile.getNearby(direction);
|
||||
arr.add(" bufferx.item");
|
||||
|
@ -82,8 +82,8 @@ public class MassDriver extends Block{
|
||||
DriverBulletData data = Pooling.obtain(DriverBulletData.class);
|
||||
data.from = entity;
|
||||
data.to = other;
|
||||
for(int i = 0; i < Item.all().size; i++){
|
||||
data.items[i] = entity.items.get(Item.getByID(i));
|
||||
for(int i = 0; i < content.items().size; i++){
|
||||
data.items[i] = entity.items.get(content.item(i));
|
||||
}
|
||||
entity.items.clear();
|
||||
|
||||
@ -247,7 +247,7 @@ public class MassDriver extends Block{
|
||||
|
||||
public static class DriverBulletData implements Poolable{
|
||||
public MassDriverEntity from, to;
|
||||
public int[] items = new int[Item.all().size];
|
||||
public int[] items = new int[content.items().size];
|
||||
|
||||
@Override
|
||||
public void reset(){
|
||||
@ -274,7 +274,7 @@ public class MassDriver extends Block{
|
||||
//add all the items possible
|
||||
for(int i = 0; i < data.items.length; i++){
|
||||
int maxAdd = Math.min(data.items[i], itemCapacity - totalItems);
|
||||
items.add(Item.getByID(i), maxAdd);
|
||||
items.add(content.item(i), maxAdd);
|
||||
data.items[i] -= maxAdd;
|
||||
totalItems += maxAdd;
|
||||
|
||||
@ -289,7 +289,7 @@ public class MassDriver extends Block{
|
||||
if(amountDropped > 0){
|
||||
float angle = Mathf.range(180f);
|
||||
float vs = Mathf.random(0f, 4f);
|
||||
ItemDrop.create(Item.getByID(i), amountDropped, bullet.x, bullet.y, Angles.trnsx(angle, vs), Angles.trnsy(angle, vs));
|
||||
ItemDrop.create(content.item(i), amountDropped, bullet.x, bullet.y, Angles.trnsx(angle, vs), Angles.trnsy(angle, vs));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -17,6 +17,7 @@ import io.anuke.ucore.util.Mathf;
|
||||
import java.io.DataInputStream;
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.IOException;
|
||||
import static io.anuke.mindustry.Vars.*;
|
||||
|
||||
public class Sorter extends Block implements SelectionTrait{
|
||||
|
||||
@ -118,7 +119,7 @@ public class Sorter extends Block implements SelectionTrait{
|
||||
}
|
||||
|
||||
public static class SorterEntity extends TileEntity{
|
||||
public Item sortItem = Item.getByID(0);
|
||||
public Item sortItem = content.item(0);
|
||||
|
||||
@Override
|
||||
public void write(DataOutputStream stream) throws IOException{
|
||||
@ -127,7 +128,7 @@ public class Sorter extends Block implements SelectionTrait{
|
||||
|
||||
@Override
|
||||
public void read(DataInputStream stream) throws IOException{
|
||||
sortItem = Item.all().get(stream.readByte());
|
||||
sortItem = content.items().get(stream.readByte());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -10,6 +10,7 @@ import io.anuke.ucore.core.Timers;
|
||||
import io.anuke.ucore.graphics.Draw;
|
||||
import io.anuke.ucore.util.Mathf;
|
||||
|
||||
import static io.anuke.mindustry.Vars.content;
|
||||
import static io.anuke.mindustry.Vars.tilesize;
|
||||
|
||||
public abstract class ItemLiquidGenerator extends ItemGenerator{
|
||||
@ -33,7 +34,7 @@ public abstract class ItemLiquidGenerator extends ItemGenerator{
|
||||
ItemGeneratorEntity entity = tile.entity();
|
||||
|
||||
Liquid liquid = null;
|
||||
for(Liquid other : Liquid.all()){
|
||||
for(Liquid other : content.liquids()){
|
||||
if(entity.liquids.get(other) >= 0.001f && getLiquidEfficiency(other) >= minLiquidEfficiency){
|
||||
liquid = other;
|
||||
break;
|
||||
|
@ -21,7 +21,7 @@ import io.anuke.ucore.core.Graphics;
|
||||
import io.anuke.ucore.core.Timers;
|
||||
import io.anuke.ucore.graphics.Draw;
|
||||
import io.anuke.ucore.util.Mathf;
|
||||
|
||||
import static io.anuke.mindustry.Vars.content;
|
||||
public class Drill extends Block{
|
||||
protected final static float hardnessDrillMultiplier = 50f;
|
||||
protected final int timerDump = timers++;
|
||||
@ -120,7 +120,7 @@ public class Drill extends Block{
|
||||
stats.add(BlockStat.drillTier, table -> {
|
||||
Array<Item> list = new Array<>();
|
||||
|
||||
for(Item item : Item.all()){
|
||||
for(Item item : content.items()){
|
||||
if(tier >= item.hardness && Draw.hasRegion(item.name + "1")){
|
||||
list.add(item);
|
||||
}
|
||||
|
@ -23,6 +23,8 @@ import java.io.DataInputStream;
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.IOException;
|
||||
|
||||
import static io.anuke.mindustry.Vars.*;
|
||||
|
||||
public class PowerSmelter extends PowerBlock{
|
||||
protected final int timerDump = timers++;
|
||||
protected final int timerCraft = timers++;
|
||||
@ -113,7 +115,7 @@ public class PowerSmelter extends PowerBlock{
|
||||
}
|
||||
|
||||
float baseSmeltSpeed = 1f;
|
||||
for(Item item : Item.all()){
|
||||
for(Item item : content.items()){
|
||||
if(item.fluxiness >= minFlux && tile.entity.items.get(item) > 0){
|
||||
baseSmeltSpeed = fluxSpeedMult;
|
||||
break;
|
||||
@ -130,7 +132,7 @@ public class PowerSmelter extends PowerBlock{
|
||||
|
||||
if(useFlux){
|
||||
//remove flux materials if present
|
||||
for(Item item : Item.all()){
|
||||
for(Item item : content.items()){
|
||||
if(item.fluxiness >= minFlux && tile.entity.items.get(item) >= fluxNeeded){
|
||||
tile.entity.items.remove(item, fluxNeeded);
|
||||
|
||||
|
@ -20,6 +20,8 @@ import io.anuke.ucore.graphics.Draw;
|
||||
import io.anuke.ucore.graphics.Fill;
|
||||
import io.anuke.ucore.util.Mathf;
|
||||
|
||||
import static io.anuke.mindustry.Vars.*;
|
||||
|
||||
public class Smelter extends Block{
|
||||
protected final int timerDump = timers++;
|
||||
protected final int timerCraft = timers++;
|
||||
@ -109,7 +111,7 @@ public class Smelter extends Block{
|
||||
}
|
||||
|
||||
float baseSmeltSpeed = 1f;
|
||||
for(Item item : Item.all()){
|
||||
for(Item item : content.items()){
|
||||
if(item.fluxiness >= minFlux && tile.entity.items.get(item) > 0){
|
||||
baseSmeltSpeed = fluxSpeedMult;
|
||||
break;
|
||||
@ -126,7 +128,7 @@ public class Smelter extends Block{
|
||||
|
||||
if(useFlux){
|
||||
//remove flux materials if present
|
||||
for(Item item : Item.all()){
|
||||
for(Item item : content.items()){
|
||||
if(item.fluxiness >= minFlux && tile.entity.items.get(item) > 0){
|
||||
tile.entity.items.remove(item, 1);
|
||||
|
||||
|
@ -15,6 +15,7 @@ import io.anuke.ucore.scene.ui.layout.Table;
|
||||
import java.io.DataInputStream;
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.IOException;
|
||||
import static io.anuke.mindustry.Vars.*;
|
||||
|
||||
public class SortedUnloader extends Unloader implements SelectionTrait{
|
||||
|
||||
@ -81,7 +82,7 @@ public class SortedUnloader extends Unloader implements SelectionTrait{
|
||||
@Override
|
||||
public void read(DataInputStream stream) throws IOException{
|
||||
byte id = stream.readByte();
|
||||
sortItem = id == -1 ? null : Item.all().get(id);
|
||||
sortItem = id == -1 ? null : content.items().get(id);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -6,6 +6,7 @@ import io.anuke.mindustry.type.Item;
|
||||
import io.anuke.mindustry.world.Edges;
|
||||
import io.anuke.mindustry.world.Tile;
|
||||
import io.anuke.ucore.core.Timers;
|
||||
import static io.anuke.mindustry.Vars.*;
|
||||
|
||||
public class Vault extends StorageBlock{
|
||||
|
||||
@ -56,8 +57,8 @@ public class Vault extends StorageBlock{
|
||||
|
||||
if(!(other.block() instanceof Vault)){
|
||||
|
||||
for(int ii = 0; ii < Item.all().size; ii++){
|
||||
Item item = Item.getByID(ii);
|
||||
for(int ii = 0; ii < content.items().size; ii++){
|
||||
Item item = content.item(ii);
|
||||
|
||||
if(entity.items.has(item) && other.block().acceptItem(item, other, in) && canDump(tile, other, item)){
|
||||
other.block().handleItem(item, other, in);
|
||||
@ -67,7 +68,7 @@ public class Vault extends StorageBlock{
|
||||
}
|
||||
}
|
||||
}else{
|
||||
todump = Item.getByID(0);
|
||||
todump = content.item(0);
|
||||
|
||||
if(other.block().acceptItem(todump, other, in) && canDump(tile, other, todump)){
|
||||
other.block().handleItem(removeItem(tile, null), other, in);
|
||||
|
@ -9,6 +9,7 @@ import io.anuke.mindustry.world.meta.BlockStats;
|
||||
import io.anuke.mindustry.world.meta.values.ItemFilterValue;
|
||||
import io.anuke.ucore.function.Predicate;
|
||||
import io.anuke.ucore.scene.ui.layout.Table;
|
||||
import static io.anuke.mindustry.Vars.*;
|
||||
|
||||
public class ConsumeItemFilter extends Consume{
|
||||
private final Predicate<Item> filter;
|
||||
@ -21,7 +22,7 @@ public class ConsumeItemFilter extends Consume{
|
||||
public void buildTooltip(Table table){
|
||||
Array<Item> list = new Array<>();
|
||||
|
||||
for(Item item : Item.all()){
|
||||
for(Item item : content.items()){
|
||||
if(filter.test(item)) list.add(item);
|
||||
}
|
||||
|
||||
@ -46,8 +47,8 @@ public class ConsumeItemFilter extends Consume{
|
||||
|
||||
@Override
|
||||
public boolean valid(Block block, TileEntity entity){
|
||||
for(int i = 0; i < Item.all().size; i++){
|
||||
Item item = Item.getByID(i);
|
||||
for(int i = 0; i < content.items().size; i++){
|
||||
Item item = content.item(i);
|
||||
if(entity.items != null && entity.items.has(item) && this.filter.test(item)){
|
||||
return true;
|
||||
}
|
||||
|
@ -11,6 +11,7 @@ import io.anuke.mindustry.world.meta.values.LiquidFilterValue;
|
||||
import io.anuke.ucore.core.Timers;
|
||||
import io.anuke.ucore.function.Predicate;
|
||||
import io.anuke.ucore.scene.ui.layout.Table;
|
||||
import static io.anuke.mindustry.Vars.*;
|
||||
|
||||
public class ConsumeLiquidFilter extends Consume{
|
||||
private final Predicate<Liquid> filter;
|
||||
@ -31,7 +32,7 @@ public class ConsumeLiquidFilter extends Consume{
|
||||
public void buildTooltip(Table table){
|
||||
Array<Liquid> list = new Array<>();
|
||||
|
||||
for(Liquid item : Liquid.all()){
|
||||
for(Liquid item : content.liquids()){
|
||||
if(!item.isHidden() && filter.test(item)) list.add(item);
|
||||
}
|
||||
|
||||
|
@ -5,6 +5,7 @@ import io.anuke.mindustry.type.Item;
|
||||
import io.anuke.mindustry.world.meta.StatValue;
|
||||
import io.anuke.ucore.function.Predicate;
|
||||
import io.anuke.ucore.scene.ui.layout.Table;
|
||||
import static io.anuke.mindustry.Vars.*;
|
||||
|
||||
public class ItemFilterValue implements StatValue{
|
||||
private final Predicate<Item> filter;
|
||||
@ -17,7 +18,7 @@ public class ItemFilterValue implements StatValue{
|
||||
public void display(Table table){
|
||||
Array<Item> list = new Array<>();
|
||||
|
||||
for(Item item : Item.all()){
|
||||
for(Item item : content.items()){
|
||||
if(filter.test(item)) list.add(item);
|
||||
}
|
||||
|
||||
|
@ -5,6 +5,7 @@ import io.anuke.mindustry.type.Liquid;
|
||||
import io.anuke.mindustry.world.meta.StatValue;
|
||||
import io.anuke.ucore.function.Predicate;
|
||||
import io.anuke.ucore.scene.ui.layout.Table;
|
||||
import static io.anuke.mindustry.Vars.*;
|
||||
|
||||
public class LiquidFilterValue implements StatValue{
|
||||
private final Predicate<Liquid> filter;
|
||||
@ -17,7 +18,7 @@ public class LiquidFilterValue implements StatValue{
|
||||
public void display(Table table){
|
||||
Array<Liquid> list = new Array<>();
|
||||
|
||||
for(Liquid item : Liquid.all()){
|
||||
for(Liquid item : content.liquids()){
|
||||
if(!item.isHidden() && filter.test(item)) list.add(item);
|
||||
}
|
||||
|
||||
|
@ -7,15 +7,16 @@ import java.io.DataInput;
|
||||
import java.io.DataOutput;
|
||||
import java.io.IOException;
|
||||
import java.util.Arrays;
|
||||
import static io.anuke.mindustry.Vars.content;
|
||||
|
||||
public class InventoryModule extends BlockModule{
|
||||
private int[] items = new int[Item.all().size];
|
||||
private int[] items = new int[content.items().size];
|
||||
private int total;
|
||||
|
||||
public void forEach(ItemConsumer cons){
|
||||
for(int i = 0; i < items.length; i++){
|
||||
if(items[i] > 0){
|
||||
cons.accept(Item.getByID(i), items[i]);
|
||||
cons.accept(content.item(i), items[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -24,7 +25,7 @@ public class InventoryModule extends BlockModule{
|
||||
float sum = 0f;
|
||||
for(int i = 0; i < items.length; i++){
|
||||
if(items[i] > 0){
|
||||
sum += calc.get(Item.getByID(i), items[i]);
|
||||
sum += calc.get(content.item(i), items[i]);
|
||||
}
|
||||
}
|
||||
return sum;
|
||||
@ -71,7 +72,7 @@ public class InventoryModule extends BlockModule{
|
||||
if(items[i] > 0){
|
||||
items[i]--;
|
||||
total--;
|
||||
return Item.getByID(i);
|
||||
return content.item(i);
|
||||
}
|
||||
}
|
||||
return null;
|
||||
@ -132,7 +133,7 @@ public class InventoryModule extends BlockModule{
|
||||
for(int j = 0; j < count; j++){
|
||||
int itemid = stream.readByte();
|
||||
int itemamount = stream.readInt();
|
||||
items[itemid] = itemamount;
|
||||
items[content.item(itemid).id] = itemamount;
|
||||
total += itemamount;
|
||||
}
|
||||
}
|
||||
|
@ -5,11 +5,12 @@ import io.anuke.mindustry.type.Liquid;
|
||||
import java.io.DataInput;
|
||||
import java.io.DataOutput;
|
||||
import java.io.IOException;
|
||||
import static io.anuke.mindustry.Vars.content;
|
||||
|
||||
public class LiquidModule extends BlockModule{
|
||||
private float[] liquids = new float[Liquid.all().size];
|
||||
private float[] liquids = new float[content.liquids().size];
|
||||
private float total;
|
||||
private Liquid current = Liquid.getByID(0);
|
||||
private Liquid current = content.liquid(0);
|
||||
|
||||
/**Returns total amount of liquids.*/
|
||||
public float total(){
|
||||
@ -51,7 +52,7 @@ public class LiquidModule extends BlockModule{
|
||||
public void forEach(LiquidConsumer cons){
|
||||
for(int i = 0; i < liquids.length; i++){
|
||||
if(liquids[i] > 0){
|
||||
cons.accept(Liquid.getByID(i), liquids[i]);
|
||||
cons.accept(content.liquid(i), liquids[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -60,7 +61,7 @@ public class LiquidModule extends BlockModule{
|
||||
float sum = 0f;
|
||||
for(int i = 0; i < liquids.length; i++){
|
||||
if(liquids[i] > 0){
|
||||
sum += calc.get(Liquid.getByID(i), liquids[i]);
|
||||
sum += calc.get(content.liquid(i), liquids[i]);
|
||||
}
|
||||
}
|
||||
return sum;
|
||||
@ -92,7 +93,7 @@ public class LiquidModule extends BlockModule{
|
||||
float amount = stream.readFloat();
|
||||
liquids[liquidid] = amount;
|
||||
if(amount > 0){
|
||||
current = Liquid.getByID(liquidid);
|
||||
current = content.liquid(liquidid);
|
||||
}
|
||||
this.total += amount;
|
||||
}
|
||||
|
@ -17,7 +17,7 @@ public class Generators {
|
||||
public static void generate(ImageContext context){
|
||||
|
||||
context.generate("block-icons", () -> {
|
||||
for(Block block : Block.all()){
|
||||
for(Block block : content.blocks()){
|
||||
TextureRegion[] regions = block.getBlockIcon();
|
||||
|
||||
if(regions.length == 0){
|
||||
@ -139,7 +139,7 @@ public class Generators {
|
||||
});
|
||||
|
||||
context.generate("block-edges", () -> {
|
||||
for(Block block : Block.all()){
|
||||
for(Block block : content.blocks()){
|
||||
if(!(block instanceof Floor)) continue;
|
||||
Floor floor = (Floor)block;
|
||||
if(floor.getIcon().length > 0 && !Draw.hasRegion(floor.name + "-cliff-side")){
|
||||
@ -166,7 +166,7 @@ public class Generators {
|
||||
});
|
||||
|
||||
context.generate("ore-icons", () -> {
|
||||
for(Block block : Block.all()){
|
||||
for(Block block : content.blocks()){
|
||||
if(!(block instanceof OreBlock)) continue;
|
||||
|
||||
OreBlock ore = (OreBlock)block;
|
||||
|
@ -320,7 +320,7 @@ public class ServerControl extends Module{
|
||||
return;
|
||||
}
|
||||
|
||||
for(Item item : Item.all()){
|
||||
for(Item item : content.items()){
|
||||
if(item.type == ItemType.material){
|
||||
state.teams.get(Team.blue).cores.first().entity.items.add(item, 2000);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user