From d095008e7c6776177eab2ffce86854aea03a4f0a Mon Sep 17 00:00:00 2001 From: Anuken Date: Tue, 23 Jun 2020 20:01:55 -0400 Subject: [PATCH] Some initial multiplayer bugfixes --- .../annotations/entity/EntityIO.java | 8 ++++- .../mindustry/entities/comp/PlayerComp.java | 1 + .../src/mindustry/entities/comp/UnitComp.java | 33 ++++++++++++------- core/src/mindustry/io/TypeIO.java | 4 +-- core/src/mindustry/type/UnitType.java | 1 + core/src/mindustry/world/Block.java | 16 +++------ 6 files changed, 38 insertions(+), 25 deletions(-) diff --git a/annotations/src/main/java/mindustry/annotations/entity/EntityIO.java b/annotations/src/main/java/mindustry/annotations/entity/EntityIO.java index 2ec0185aef..d1a212b93a 100644 --- a/annotations/src/main/java/mindustry/annotations/entity/EntityIO.java +++ b/annotations/src/main/java/mindustry/annotations/entity/EntityIO.java @@ -142,7 +142,13 @@ public class EntityIO{ io(field.type, "this." + (sf ? field.name + targetSuf : field.name) + " = "); - if(sl) econt(); + if(sl){ + ncont("else" ); + + st("read.f()"); + + econt(); + } } st("afterSync()"); diff --git a/core/src/mindustry/entities/comp/PlayerComp.java b/core/src/mindustry/entities/comp/PlayerComp.java index a79dc15f5f..abd7a428c4 100644 --- a/core/src/mindustry/entities/comp/PlayerComp.java +++ b/core/src/mindustry/entities/comp/PlayerComp.java @@ -113,6 +113,7 @@ abstract class PlayerComp implements UnitController, Entityc, Syncc, Timerc, Dra //(this is not for balance) deathTimer += Time.delta(); if(deathTimer >= deathDelay){ + //request spawn - this happens serverside only core.requestSpawn((Playerc)this); deathTimer = 0; } diff --git a/core/src/mindustry/entities/comp/UnitComp.java b/core/src/mindustry/entities/comp/UnitComp.java index c125cdb984..56da4ca4cc 100644 --- a/core/src/mindustry/entities/comp/UnitComp.java +++ b/core/src/mindustry/entities/comp/UnitComp.java @@ -23,7 +23,7 @@ import static mindustry.Vars.*; @Component abstract class UnitComp implements Healthc, Physicsc, Hitboxc, Statusc, Teamc, Itemsc, Rotc, Unitc, Weaponsc, Drawc, Boundedc, Syncc, Shieldc, Displayable{ - @Import float x, y, rotation, elevation, maxHealth, drag, armor; + @Import float x, y, rotation, elevation, maxHealth, drag, armor, hitSize; private UnitController controller; private UnitType type; @@ -85,16 +85,9 @@ abstract class UnitComp implements Healthc, Physicsc, Hitboxc, Statusc, Teamc, I @Override public void type(UnitType type){ - this.type = type; - this.maxHealth = type.health; - this.drag = type.drag; - this.elevation = type.flying ? 1f : type.baseElevation; - this.armor = type.armor; + if(this.type == type) return; - heal(); - hitSize(type.hitsize); - controller(type.createController()); - setupWeapons(type); + setStats(type); } @Override @@ -118,10 +111,28 @@ abstract class UnitComp implements Healthc, Physicsc, Hitboxc, Statusc, Teamc, I return controller instanceof AIController; } + private void setStats(UnitType type){ + this.type = type; + this.maxHealth = type.health; + this.drag = type.drag; + this.elevation = type.flying ? 1f : type.baseElevation; + this.armor = type.armor; + this.hitSize = type.hitsize; + + if(controller == null) controller(type.createController()); + if(mounts().length != type.weapons.size) setupWeapons(type); + } + + @Override + public void afterSync(){ + //set up type info after reading + setStats(this.type); + } + @Override public void afterRead(){ //set up type info after reading - type(this.type); + setStats(this.type); } @Override diff --git a/core/src/mindustry/io/TypeIO.java b/core/src/mindustry/io/TypeIO.java index 641fc91b95..959b9c0944 100644 --- a/core/src/mindustry/io/TypeIO.java +++ b/core/src/mindustry/io/TypeIO.java @@ -245,8 +245,8 @@ public class TypeIO{ if(type == 0){ //is player int id = read.i(); Playerc player = Groups.player.getByID(id); - //local players will cause problems if assigned, since they may not know they are controlling the unit - if(player == null || player.isLocal()) return prev; + //make sure player exists + if(player == null) return prev; return player; }else if(type == 1){ int id = read.i(); diff --git a/core/src/mindustry/type/UnitType.java b/core/src/mindustry/type/UnitType.java index 473671f227..a69443ce03 100644 --- a/core/src/mindustry/type/UnitType.java +++ b/core/src/mindustry/type/UnitType.java @@ -89,6 +89,7 @@ public class UnitType extends UnlockableContent{ unit.team(team); unit.type(this); unit.ammo(ammoCapacity); //fill up on ammo upon creation + unit.heal(); return unit; } diff --git a/core/src/mindustry/world/Block.java b/core/src/mindustry/world/Block.java index 87a800c93e..38aeee0d0a 100644 --- a/core/src/mindustry/world/Block.java +++ b/core/src/mindustry/world/Block.java @@ -208,11 +208,8 @@ public class Block extends UnlockableContent{ public float percentSolid(int x, int y){ Tile tile = world.tile(x, y); if(tile == null) return 0; - float sum = 0; - for(Tile other : tile.getLinkedTilesAs(this, tempTiles)){ - sum += !other.floor().isLiquid ? 1f : 0f; - } - return sum / size / size; + return tile.getLinkedTilesAs(this, tempTiles) + .sumf(other -> !other.floor().isLiquid ? 1f : 0f) / size / size; } /** Drawn when you are placing a block. */ @@ -253,11 +250,8 @@ public class Block extends UnlockableContent{ public float sumAttribute(Attribute attr, int x, int y){ Tile tile = world.tile(x, y); if(tile == null) return 0; - float sum = 0; - for(Tile other : tile.getLinkedTilesAs(this, tempTiles)){ - sum += other.floor().attributes.get(attr); - } - return sum; + return tile.getLinkedTilesAs(this, tempTiles) + .sumf(other -> other.floor().attributes.get(attr)); } public TextureRegion getDisplayIcon(Tile tile){ @@ -666,7 +660,7 @@ public class Block extends UnlockableContent{ outer: for(int rx = -radius; rx <= radius; rx++){ for(int ry = -radius; ry <= radius; ry++){ - if(Structs.inBounds(rx + x, ry + y, region.width, region.height) && Mathf.dst2(rx, ry) <= radius*radius && color.set(region.getPixel(rx + x, ry + y)).a > 0.01f){ + if(Structs.inBounds(rx + x, ry + y, region.width, region.height) && Mathf.within(rx, ry, radius) && color.set(region.getPixel(rx + x, ry + y)).a > 0.01f){ found = true; break outer; }