Bugfixes / Sprite update / Multiplayer in-game editor / Drone tweaks

This commit is contained in:
Anuken
2019-06-17 21:35:19 -04:00
parent bc3405d11d
commit 185a7bb7d8
49 changed files with 4906 additions and 4819 deletions

View File

@@ -424,8 +424,8 @@ public class Blocks implements ContentList{
hasLiquids = true;
hasPower = true;
consumes.power(2f);
consumes.item(Items.coal, 4);
consumes.power(1.8f);
consumes.item(Items.coal, 3);
consumes.liquid(Liquids.water, 0.1f);
}};

View File

@@ -197,7 +197,14 @@ public class Logic implements ApplicationListener{
Entities.update(bulletGroup);
Entities.update(tileGroup);
Entities.update(fireGroup);
}else{
for(EntityGroup group : unitGroups){
group.updateEvents();
collisions.updatePhysics(group);
}
}
Entities.update(playerGroup);
//effect group only contains item transfers in the headless version, update it!

View File

@@ -17,6 +17,7 @@ import io.anuke.mindustry.entities.traits.BuilderTrait.BuildRequest;
import io.anuke.mindustry.entities.traits.SyncTrait;
import io.anuke.mindustry.entities.traits.TypeTrait;
import io.anuke.mindustry.entities.type.Player;
import io.anuke.mindustry.entities.type.Unit;
import io.anuke.mindustry.game.Version;
import io.anuke.mindustry.gen.Call;
import io.anuke.mindustry.gen.RemoteReadClient;
@@ -230,7 +231,7 @@ public class NetClient implements ApplicationListener{
byte typeID = input.readByte();
SyncTrait entity = group == null ? null : (SyncTrait)group.getByID(id);
boolean add = false;
boolean add = false, created = false;
if(entity == null && id == player.id){
entity = player;
@@ -244,11 +245,20 @@ public class NetClient implements ApplicationListener{
if(!netClient.isEntityUsed(entity.getID())){
add = true;
}
created = true;
}
//read the entity
entity.read(input);
if(created){
//set initial starting position
entity.setNet(entity.getInterpolator().target.x, entity.getInterpolator().target.y);
if(entity instanceof Unit && entity.getInterpolator().targets.length > 0){
((Unit)entity).rotation = entity.getInterpolator().targets[0];
}
}
if(add){
entity.add();
netClient.addRemovedEntity(entity.getID());

View File

@@ -90,6 +90,14 @@ public class World implements ApplicationListener{
return tiles == null ? 0 : tiles[0].length;
}
public int unitWidth(){
return width()*tilesize;
}
public int unitHeight(){
return height()*tilesize;
}
public @Nullable Tile tile(int pos){
return tiles == null ? null : tile(Pos.x(pos), Pos.y(pos));
}

View File

@@ -96,6 +96,7 @@ public class Fire extends TimedEntity implements SaveTrait, SyncTrait{
}
time = Mathf.clamp(time + Time.delta(), 0, lifetime());
map.put(tile.pos(), this);
if(Net.client()){
return;

View File

@@ -265,6 +265,15 @@ public abstract class Unit extends DestructibleEntity implements SaveTrait, Targ
}
}
//repel player out of bounds
final float warpDst = 230f;
if(x < 0) velocity.x += (-x/warpDst);
if(y < 0) velocity.y += (-y/warpDst);
if(x > world.unitWidth()) velocity.x -= (x - world.unitWidth())/warpDst;
if(y > world.unitHeight()) velocity.y -= (y - world.unitHeight())/warpDst;
if(isFlying()){
drownTime = 0f;
move(velocity.x * Time.delta(), velocity.y * Time.delta());

View File

@@ -150,7 +150,8 @@ public class BuilderDrone extends BaseDrone implements BuilderTrait{
}
boolean isRebuild(){
return Vars.state.rules.enemyCheat && team == waveTeam;
//disabled until further notice, reason being that it's too annoying when playing enemies and too broken for ally use
return false; //Vars.state.rules.enemyCheat && team == waveTeam;
}
@Override

View File

@@ -14,7 +14,9 @@ public abstract class SaveFileReader{
protected final DataOutputStream dataBytes = new DataOutputStream(byteOutput);
protected final ReusableByteOutStream byteOutputSmall = new ReusableByteOutStream();
protected final DataOutputStream dataBytesSmall = new DataOutputStream(byteOutputSmall);
protected final ObjectMap<String, String> fallback = ObjectMap.of();
protected final ObjectMap<String, String> fallback = ObjectMap.of(
);
protected void region(String name, DataInput stream, CounterInputStream counter, IORunner<DataInput> cons) throws IOException{
counter.resetCount();

View File

@@ -86,15 +86,15 @@ public class TypeIO{
@WriteClass(BaseUnit.class)
public static void writeBaseUnit(ByteBuffer buffer, BaseUnit unit){
buffer.put((byte)unitGroups[unit.getTeam().ordinal()].getID());
buffer.put((byte)unit.getTeam().ordinal());
buffer.putInt(unit.getID());
}
@ReadClass(BaseUnit.class)
public static BaseUnit writeBaseUnit(ByteBuffer buffer){
byte gid = buffer.get();
public static BaseUnit readBaseUnit(ByteBuffer buffer){
byte tid = buffer.get();
int id = buffer.getInt();
return (BaseUnit)Entities.getGroup(gid).getByID(id);
return unitGroups[tid].getByID(id);
}
@WriteClass(Tile.class)
@@ -193,6 +193,16 @@ public class TypeIO{
return Effects.getEffect(buffer.getShort());
}
@WriteClass(UnitType.class)
public static void writeUnitType(ByteBuffer buffer, UnitType effect){
buffer.putShort(effect.id);
}
@ReadClass(UnitType.class)
public static UnitType readUnitType(ByteBuffer buffer){
return content.getByID(ContentType.unit, buffer.getShort());
}
@WriteClass(Color.class)
public static void writeColor(ByteBuffer buffer, Color color){
buffer.putInt(Color.rgba8888(color));

View File

@@ -10,6 +10,7 @@ import static io.anuke.mindustry.Vars.*;
public class PausedDialog extends FloatingDialog{
private SaveDialog save = new SaveDialog();
private LoadDialog load = new LoadDialog();
private boolean wasClient = false;
public PausedDialog(){
super("$menu");
@@ -55,13 +56,12 @@ public class PausedDialog extends FloatingDialog{
cont.row();
if(!state.isEditor()){
cont.addButton("$hostserver", ui.host::show).disabled(b -> Net.active()).colspan(2).width(dw * 2 + 20f);
cont.row();
}
cont.addButton("$hostserver", ui.host::show).disabled(b -> Net.active()).colspan(2).width(dw * 2 + 20f);
cont.row();
cont.addButton("$quit", () -> {
ui.showConfirm("$confirm", "$quit.confirm", () -> {
wasClient = Net.client();
if(Net.client()) netClient.disconnectQuietly();
runExitSave();
hide();
@@ -85,11 +85,11 @@ public class PausedDialog extends FloatingDialog{
cont.row();
}
if(!state.isEditor()){
cont.addRowImageTextButton("$hostserver.mobile", "icon-host", isize, ui.host::show).disabled(b -> Net.active());
}
cont.addRowImageTextButton("$hostserver.mobile", "icon-host", isize, ui.host::show).disabled(b -> Net.active());
cont.addRowImageTextButton("$quit", "icon-quit", isize, () -> {
ui.showConfirm("$confirm", "$quit.confirm", () -> {
wasClient = Net.client();
if(Net.client()) netClient.disconnectQuietly();
runExitSave();
hide();
@@ -99,7 +99,7 @@ public class PausedDialog extends FloatingDialog{
}
public void runExitSave(){
if(state.isEditor()){
if(state.isEditor() && !wasClient){
ui.editor.resumeEditing();
return;
}

View File

@@ -1,5 +1,7 @@
package io.anuke.mindustry.ui.fragments;
import io.anuke.annotations.Annotations.Loc;
import io.anuke.annotations.Annotations.Remote;
import io.anuke.arc.Core;
import io.anuke.arc.Events;
import io.anuke.arc.collection.Array;
@@ -19,11 +21,10 @@ import io.anuke.arc.scene.ui.*;
import io.anuke.arc.scene.ui.layout.*;
import io.anuke.arc.scene.utils.Elements;
import io.anuke.arc.util.*;
import io.anuke.mindustry.content.Fx;
import io.anuke.mindustry.core.GameState.State;
import io.anuke.mindustry.entities.Effects;
import io.anuke.mindustry.entities.Units;
import io.anuke.mindustry.entities.type.BaseUnit;
import io.anuke.mindustry.entities.type.Player;
import io.anuke.mindustry.game.EventType.StateChangeEvent;
import io.anuke.mindustry.game.Team;
import io.anuke.mindustry.game.UnlockableContent;
@@ -181,7 +182,7 @@ public class HudFragment extends Fragment{
teams.left();
int i = 0;
for(Team team : Team.all){
ImageButton button = teams.addImageButton("white", "clear-toggle-partial", 40f, () -> player.setTeam(team))
ImageButton button = teams.addImageButton("white", "clear-toggle-partial", 40f, () -> Call.setPlayerTeamEditor(player, team))
.size(50f).margin(6f).get();
button.getImageCell().grow();
button.getStyle().imageUpColor = team.color;
@@ -199,13 +200,7 @@ public class HudFragment extends Fragment{
int i = 0;
for(UnitType type : content.<UnitType>getBy(ContentType.unit)){
dialog.cont.addImageButton("white", 48, () -> {
BaseUnit unit = type.create(player.getTeam());
unit.set(player.x, player.y);
unit.rotation = player.rotation;
unit.add();
//trigger the entity to become visible
unitGroups[player.getTeam().ordinal()].updateEvents();
collisions.updatePhysics( unitGroups[player.getTeam().ordinal()]);
Call.spawnUnitEditor(player, type);
dialog.hide();
}).get().getStyle().imageUp = new TextureRegionDrawable(type.iconRegion);
if(++i % 4 == 0) dialog.cont.row();
@@ -230,10 +225,7 @@ public class HudFragment extends Fragment{
Units.nearby(world.x, world.y, 1f, 1f, unit -> {
if(!found[0] && unit instanceof BaseUnit){
if(Core.input.keyTap(KeyCode.MOUSE_LEFT)){
Effects.effect(Fx.spawn, unit);
unit.remove();
unitGroups[unit.getTeam().ordinal()].updateEvents();
collisions.updatePhysics(unitGroups[unit.getTeam().ordinal()]);
Call.removeUnitEditor(player, (BaseUnit)unit);
}
found[0] = true;
unit.hitbox(Tmp.r1);
@@ -242,7 +234,6 @@ public class HudFragment extends Fragment{
position[1] = unit.y;
}
});
//TODO check for unit removal, remove unit if needed
}
}
@@ -284,19 +275,6 @@ public class HudFragment extends Fragment{
.margin(6).update(u -> u.color.a = Mathf.lerpDelta(u.color.a, Mathf.num(world.spawner.playerNear()), 0.1f)).get().color.a = 0f;
});
//out of bounds warning
parent.fill(t -> {
t.touchable(Touchable.disabled);
t.visible(() -> !state.is(State.menu));
t.table("flat", c -> c.add("")
.update(l -> {
l.setColor(Tmp.c1.set(Color.WHITE).lerp(Color.SCARLET, Mathf.absin(Time.time(), 10f, 1f)));
l.setText(Core.bundle.format("outofbounds", (int)((boundsCountdown - player.destructTime) / 60f)));
}).get().setAlignment(Align.center, Align.center)).margin(6).update(u -> {
u.color.a = Mathf.lerpDelta(u.color.a, Mathf.num(player.isOutOfBounds()), 0.1f);
}).get().color.a = 0f;
});
parent.fill(t -> {
t.visible(() -> netServer.isWaitingForPlayers() && !state.is(State.menu));
t.table("button", c -> c.add("$waiting.players"));
@@ -417,6 +395,30 @@ public class HudFragment extends Fragment{
blockfrag.build(Core.scene.root);
}
@Remote(targets = Loc.both, forward = true, called = Loc.both)
public static void setPlayerTeamEditor(Player player, Team team){
if(state.isEditor()){
player.setTeam(team);
}
}
@Remote(targets = Loc.both, called = Loc.server)
public static void spawnUnitEditor(Player player, UnitType type){
if(state.isEditor()){
BaseUnit unit = type.create(player.getTeam());
unit.set(player.x, player.y);
unit.rotation = player.rotation;
unit.add();
}
}
@Remote(targets = Loc.both, called = Loc.server, forward = true)
public static void removeUnitEditor(Player player, BaseUnit unit){
if(state.isEditor() && unit != null){
unit.remove();
}
}
public void showToast(String text){
Table table = new Table("button");
table.update(() -> {

View File

@@ -114,7 +114,7 @@ public class ItemBridge extends Block{
float h = (link.y == y ? tilesize : Math.abs(link.y - y) * tilesize - tilesize);
Lines.rect((x + link.x) / 2f * tilesize - w / 2f, (y + link.y) / 2f * tilesize - h / 2f, w, h);
Draw.rect("bridge-poly", link.x * tilesize + Geometry.d4[rot].x * tilesize, link.y * tilesize + Geometry.d4[rot].y * tilesize, link.absoluteRelativeTo(x, y) * 90);
Draw.rect("bridge-arrow", link.x * tilesize + Geometry.d4[rot].x * tilesize, link.y * tilesize + Geometry.d4[rot].y * tilesize, link.absoluteRelativeTo(x, y) * 90);
}
Draw.reset();
}

View File

@@ -31,8 +31,7 @@ public class ImpactReactor extends PowerGenerator{
protected int explosionDamage = 2000;
protected Color plasma1 = Color.valueOf("ffd06b"), plasma2 = Color.valueOf("ff361b");
protected Color ind1 = Color.valueOf("858585"), ind2 = Color.valueOf("fea080");
protected int bottomRegion, topRegion, lightRegion;
protected int bottomRegion;
protected int[] plasmaRegions;
public ImpactReactor(String name){
@@ -44,8 +43,6 @@ public class ImpactReactor extends PowerGenerator{
outputsPower = consumesPower = true;
bottomRegion = reg("-bottom");
topRegion = reg("-top");
lightRegion = reg("-light");
plasmaRegions = new int[plasmas];
for(int i = 0; i < plasmas; i++){
plasmaRegions[i] = reg("-plasma-" + i);
@@ -112,17 +109,12 @@ public class ImpactReactor extends PowerGenerator{
Draw.rect(region, tile.drawx(), tile.drawy());
Draw.rect(reg(topRegion), tile.drawx(), tile.drawy());
Draw.color(ind1, ind2, entity.warmup + Mathf.absin(entity.productionEfficiency, 3f, entity.warmup * 0.5f));
Draw.rect(reg(lightRegion), tile.drawx(), tile.drawy());
Draw.color();
}
@Override
public TextureRegion[] generateIcons(){
return new TextureRegion[]{Core.atlas.find(name + "-bottom"), Core.atlas.find(name), Core.atlas.find(name + "-top")};
return new TextureRegion[]{Core.atlas.find(name + "-bottom"), Core.atlas.find(name)};
}
@Override