mirror of
https://github.com/Anuken/Mindustry.git
synced 2026-03-27 01:01:09 -07:00
merge
This commit is contained in:
commit
82f43a362f
14 changed files with 143 additions and 202 deletions
|
|
@ -124,7 +124,7 @@ save.new = New Save
|
|||
save.overwrite = Are you sure you want to overwrite\nthis save slot?
|
||||
overwrite = Overwrite
|
||||
save.none = No saves found!
|
||||
saveload = [accent]Saving...
|
||||
saveload = Saving...
|
||||
savefail = Failed to save game!
|
||||
save.delete.confirm = Are you sure you want to delete this save?
|
||||
save.delete = Delete
|
||||
|
|
|
|||
|
|
@ -119,7 +119,7 @@ public class BlockIndexer{
|
|||
|
||||
ObjectSet<Tile> set = damagedTiles[team.ordinal()];
|
||||
for(Tile tile : set){
|
||||
if((tile.entity == null || tile.entity.getTeam() != team || !tile.entity.damaged()) && !(tile.block() instanceof BuildBlock)){
|
||||
if((tile.entity == null || tile.entity.getTeam() != team || !tile.entity.damaged()) || tile.block() instanceof BuildBlock){
|
||||
returnArray.add(tile);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -84,7 +84,7 @@ public class Control implements ApplicationListener{
|
|||
});
|
||||
|
||||
Events.on(PlayEvent.class, event -> {
|
||||
player.setTeam(defaultTeam);
|
||||
player.setTeam(state.rules.pvp ? netServer.assignTeam(playerGroup.all()) : defaultTeam);
|
||||
player.setDead(true);
|
||||
player.add();
|
||||
|
||||
|
|
@ -237,7 +237,7 @@ public class Control implements ApplicationListener{
|
|||
public void playMap(Map map, Rules rules){
|
||||
ui.loadAnd(() -> {
|
||||
logic.reset();
|
||||
world.loadMap(map);
|
||||
world.loadMap(map, rules);
|
||||
state.rules = rules;
|
||||
logic.play();
|
||||
});
|
||||
|
|
|
|||
|
|
@ -40,7 +40,7 @@ import static io.anuke.mindustry.Vars.*;
|
|||
|
||||
public class NetServer implements ApplicationListener{
|
||||
public final static int maxSnapshotSize = 430;
|
||||
private final static float serverSyncTime = 15, kickDuration = 30 * 1000;
|
||||
private final static float serverSyncTime = 12, kickDuration = 30 * 1000;
|
||||
private final static Vector2 vector = new Vector2();
|
||||
private final static Rectangle viewport = new Rectangle();
|
||||
/** If a player goes away of their server-side coordinates by this distance, they get teleported back. */
|
||||
|
|
|
|||
|
|
@ -220,6 +220,10 @@ public class World implements ApplicationListener{
|
|||
}
|
||||
|
||||
public void loadMap(Map map){
|
||||
loadMap(map, new Rules());
|
||||
}
|
||||
|
||||
public void loadMap(Map map, Rules checkRules){
|
||||
try{
|
||||
SaveIO.load(map.file, new FilterContext(map));
|
||||
}catch(Exception e){
|
||||
|
|
@ -238,20 +242,21 @@ public class World implements ApplicationListener{
|
|||
invalidMap = false;
|
||||
|
||||
if(!headless){
|
||||
if(state.teams.get(defaultTeam).cores.size == 0){
|
||||
if(state.teams.get(defaultTeam).cores.size == 0 && !checkRules.pvp){
|
||||
ui.showError("$map.nospawn");
|
||||
invalidMap = true;
|
||||
}else if(state.rules.pvp){ //pvp maps need two cores to be valid
|
||||
invalidMap = true;
|
||||
}else if(checkRules.pvp){ //pvp maps need two cores to be valid
|
||||
int teams = 0;
|
||||
for(Team team : Team.all){
|
||||
if(state.teams.get(team).cores.size != 0 && team != defaultTeam){
|
||||
invalidMap = false;
|
||||
if(state.teams.get(team).cores.size != 0){
|
||||
teams ++;
|
||||
}
|
||||
}
|
||||
if(invalidMap){
|
||||
if(teams < 2){
|
||||
invalidMap = true;
|
||||
ui.showError("$map.nospawn.pvp");
|
||||
}
|
||||
}else if(state.rules.attackMode){ //pvp maps need two cores to be valid
|
||||
}else if(checkRules.attackMode){ //attack maps need two cores to be valid
|
||||
invalidMap = state.teams.get(waveTeam).cores.isEmpty();
|
||||
if(invalidMap){
|
||||
ui.showError("$map.nospawn.attack");
|
||||
|
|
|
|||
|
|
@ -1,33 +1,28 @@
|
|||
package io.anuke.mindustry.entities.traits;
|
||||
|
||||
import io.anuke.annotations.Annotations.*;
|
||||
import io.anuke.arc.Core;
|
||||
import io.anuke.arc.Events;
|
||||
import io.anuke.arc.collection.Array;
|
||||
import io.anuke.arc.*;
|
||||
import io.anuke.arc.collection.Queue;
|
||||
import io.anuke.arc.collection.*;
|
||||
import io.anuke.arc.graphics.g2d.*;
|
||||
import io.anuke.arc.math.Angles;
|
||||
import io.anuke.arc.math.Mathf;
|
||||
import io.anuke.arc.math.geom.Vector2;
|
||||
import io.anuke.arc.util.Time;
|
||||
import io.anuke.mindustry.Vars;
|
||||
import io.anuke.mindustry.content.Blocks;
|
||||
import io.anuke.mindustry.entities.type.TileEntity;
|
||||
import io.anuke.mindustry.entities.type.Unit;
|
||||
import io.anuke.mindustry.game.EventType.BuildSelectEvent;
|
||||
import io.anuke.mindustry.gen.Call;
|
||||
import io.anuke.mindustry.graphics.Pal;
|
||||
import io.anuke.mindustry.net.Net;
|
||||
import io.anuke.arc.math.*;
|
||||
import io.anuke.arc.math.geom.*;
|
||||
import io.anuke.arc.util.*;
|
||||
import io.anuke.mindustry.*;
|
||||
import io.anuke.mindustry.content.*;
|
||||
import io.anuke.mindustry.entities.type.*;
|
||||
import io.anuke.mindustry.game.EventType.*;
|
||||
import io.anuke.mindustry.gen.*;
|
||||
import io.anuke.mindustry.graphics.*;
|
||||
import io.anuke.mindustry.world.*;
|
||||
import io.anuke.mindustry.world.blocks.BuildBlock;
|
||||
import io.anuke.mindustry.world.blocks.BuildBlock.BuildEntity;
|
||||
import io.anuke.mindustry.world.blocks.*;
|
||||
import io.anuke.mindustry.world.blocks.BuildBlock.*;
|
||||
|
||||
import java.io.*;
|
||||
import java.util.Arrays;
|
||||
import java.util.*;
|
||||
|
||||
import static io.anuke.mindustry.Vars.*;
|
||||
import static io.anuke.mindustry.entities.traits.BuilderTrait.BuildDataStatic.removal;
|
||||
import static io.anuke.mindustry.entities.traits.BuilderTrait.BuildDataStatic.tmptr;
|
||||
import static io.anuke.mindustry.entities.traits.BuilderTrait.BuildDataStatic.*;
|
||||
|
||||
/** Interface for units that build things.*/
|
||||
public interface BuilderTrait extends Entity, TeamTrait{
|
||||
|
|
@ -106,19 +101,14 @@ public interface BuilderTrait extends Entity, TeamTrait{
|
|||
unit.rotation = Mathf.slerpDelta(unit.rotation, unit.angleTo(entity), 0.4f);
|
||||
}
|
||||
|
||||
//progress is synced, thus not updated clientside
|
||||
if(!Net.client()){
|
||||
//deconstructing is 2x as fast
|
||||
if(current.breaking){
|
||||
entity.deconstruct(unit, core, 2f / entity.buildCost * Time.delta() * getBuildPower(tile) * state.rules.buildSpeedMultiplier);
|
||||
}else{
|
||||
entity.construct(unit, core, 1f / entity.buildCost * Time.delta() * getBuildPower(tile) * state.rules.buildSpeedMultiplier);
|
||||
}
|
||||
|
||||
current.progress = entity.progress();
|
||||
//deconstructing is 2x as fast
|
||||
if(current.breaking){
|
||||
entity.deconstruct(unit, core, 2f / entity.buildCost * Time.delta() * getBuildPower(tile) * state.rules.buildSpeedMultiplier);
|
||||
}else{
|
||||
entity.progress = current.progress;
|
||||
entity.construct(unit, core, 1f / entity.buildCost * Time.delta() * getBuildPower(tile) * state.rules.buildSpeedMultiplier);
|
||||
}
|
||||
|
||||
current.progress = entity.progress;
|
||||
}
|
||||
|
||||
/** Returns the queue for storing build requests. */
|
||||
|
|
@ -135,7 +125,7 @@ public interface BuilderTrait extends Entity, TeamTrait{
|
|||
default void writeBuilding(DataOutput output) throws IOException{
|
||||
BuildRequest request = buildRequest();
|
||||
|
||||
if(request != null){
|
||||
if(request != null && (request.block != null || request.breaking)){
|
||||
output.writeByte(request.breaking ? 1 : 0);
|
||||
output.writeInt(Pos.get(request.x, request.y));
|
||||
output.writeFloat(request.progress);
|
||||
|
|
@ -174,7 +164,11 @@ public interface BuilderTrait extends Entity, TeamTrait{
|
|||
if(applyChanges){
|
||||
buildQueue().addLast(request);
|
||||
}else if(isBuilding()){
|
||||
buildRequest().progress = progress;
|
||||
BuildRequest last = buildRequest();
|
||||
last.progress = progress;
|
||||
if(last.tile() != null && last.tile().entity instanceof BuildEntity){
|
||||
((BuildEntity)last.tile().entity).progress = progress;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@ import io.anuke.mindustry.entities.type.TileEntity;
|
|||
import io.anuke.mindustry.entities.units.UnitState;
|
||||
import io.anuke.mindustry.world.Pos;
|
||||
import io.anuke.mindustry.world.Tile;
|
||||
import io.anuke.mindustry.world.blocks.*;
|
||||
|
||||
import java.io.*;
|
||||
|
||||
|
|
@ -23,6 +24,10 @@ public class RepairDrone extends BaseDrone{
|
|||
target = Units.findDamagedTile(team, x, y);
|
||||
}
|
||||
|
||||
if(target instanceof TileEntity && ((TileEntity)target).block instanceof BuildBlock){
|
||||
target = null;
|
||||
}
|
||||
|
||||
if(target != null){
|
||||
if(target.dst(RepairDrone.this) > type.range){
|
||||
circle(type.range * 0.9f);
|
||||
|
|
|
|||
|
|
@ -1,14 +1,15 @@
|
|||
package io.anuke.mindustry.net;
|
||||
|
||||
import io.anuke.arc.math.Mathf;
|
||||
import io.anuke.arc.math.geom.Vector2;
|
||||
import io.anuke.arc.util.Time;
|
||||
import io.anuke.arc.math.*;
|
||||
import io.anuke.arc.math.geom.*;
|
||||
import io.anuke.arc.util.*;
|
||||
|
||||
public class Interpolator{
|
||||
//used for movement
|
||||
public Vector2 target = new Vector2();
|
||||
public Vector2 last = new Vector2();
|
||||
public float[] targets = {};
|
||||
public float[] lasts = {};
|
||||
public long lastUpdated, updateSpacing;
|
||||
|
||||
//current state
|
||||
|
|
@ -21,6 +22,12 @@ public class Interpolator{
|
|||
lastUpdated = Time.millis();
|
||||
|
||||
targets = target1ds;
|
||||
if(lasts.length != values.length){
|
||||
lasts = new float[values.length];
|
||||
}
|
||||
for(int i = 0; i < values.length; i++){
|
||||
lasts[i] = values[i];
|
||||
}
|
||||
last.set(cx, cy);
|
||||
target.set(x, y);
|
||||
}
|
||||
|
|
@ -46,8 +53,12 @@ public class Interpolator{
|
|||
values = new float[targets.length];
|
||||
}
|
||||
|
||||
if(lasts.length != targets.length){
|
||||
lasts = new float[targets.length];
|
||||
}
|
||||
|
||||
for(int i = 0; i < values.length; i++){
|
||||
values[i] = Mathf.slerp(values[i], targets[i], alpha);
|
||||
values[i] = Mathf.slerp(lasts[i], targets[i], alpha);
|
||||
}
|
||||
}else{
|
||||
pos.set(target);
|
||||
|
|
|
|||
|
|
@ -162,8 +162,8 @@ public class Net{
|
|||
/**
|
||||
* Returns a list of all connections IDs.
|
||||
*/
|
||||
public static Array<NetConnection> getConnections(){
|
||||
return (Array<NetConnection>)serverProvider.getConnections();
|
||||
public static Iterable<NetConnection> getConnections(){
|
||||
return (Iterable<NetConnection>)serverProvider.getConnections();
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -377,16 +377,53 @@ public class Net{
|
|||
void host(int port) throws IOException;
|
||||
|
||||
/** Sends a large stream of data to a specific client. */
|
||||
void sendStream(int id, Streamable stream);
|
||||
default void sendStream(int id, Streamable stream){
|
||||
NetConnection connection = getByID(id);
|
||||
if(connection == null) return;
|
||||
try{
|
||||
int cid;
|
||||
StreamBegin begin = new StreamBegin();
|
||||
begin.total = stream.stream.available();
|
||||
begin.type = Registrator.getID(stream.getClass());
|
||||
connection.send(begin, SendMode.tcp);
|
||||
cid = begin.id;
|
||||
|
||||
/** Send an object to everyone connected. */
|
||||
void send(Object object, SendMode mode);
|
||||
while(stream.stream.available() > 0){
|
||||
byte[] bytes = new byte[Math.min(512, stream.stream.available())];
|
||||
stream.stream.read(bytes);
|
||||
|
||||
/** Send an object to a specific client ID. */
|
||||
void sendTo(int id, Object object, SendMode mode);
|
||||
StreamChunk chunk = new StreamChunk();
|
||||
chunk.id = cid;
|
||||
chunk.data = bytes;
|
||||
connection.send(chunk, SendMode.tcp);
|
||||
}
|
||||
}catch(IOException e){
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
/** Send an object to everyone <i>except</i> a client ID. */
|
||||
void sendExcept(int id, Object object, SendMode mode);
|
||||
default void send(Object object, SendMode mode){
|
||||
for(NetConnection con : getConnections()){
|
||||
con.send(object, mode);
|
||||
}
|
||||
}
|
||||
|
||||
default void sendTo(int id, Object object, SendMode mode){
|
||||
NetConnection conn = getByID(id);
|
||||
if(conn == null){
|
||||
Log.err("Failed to find connection with ID {0}.", id);
|
||||
return;
|
||||
}
|
||||
conn.send(object, mode);
|
||||
}
|
||||
|
||||
default void sendExcept(int id, Object object, SendMode mode){
|
||||
for(NetConnection con : getConnections()){
|
||||
if(con.id != id){
|
||||
con.send(object, mode);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/** Close the server connection. */
|
||||
void close();
|
||||
|
|
@ -395,7 +432,7 @@ public class Net{
|
|||
byte[] compressSnapshot(byte[] input);
|
||||
|
||||
/** Return all connected users. */
|
||||
Array<? extends NetConnection> getConnections();
|
||||
Iterable<? extends NetConnection> getConnections();
|
||||
|
||||
/** Returns a connection by ID. */
|
||||
NetConnection getByID(int id);
|
||||
|
|
|
|||
|
|
@ -3,6 +3,8 @@ package io.anuke.mindustry.net;
|
|||
import io.anuke.mindustry.net.Net.SendMode;
|
||||
|
||||
public abstract class NetConnection{
|
||||
private static int lastID;
|
||||
|
||||
public final int id;
|
||||
public final String address;
|
||||
|
||||
|
|
@ -18,8 +20,9 @@ public abstract class NetConnection{
|
|||
public boolean hasBegunConnecting = false;
|
||||
public float viewWidth, viewHeight, viewX, viewY;
|
||||
|
||||
public NetConnection(int id, String address){
|
||||
this.id = id;
|
||||
/** Assigns this connection a unique ID. No two connections will ever have the same ID.*/
|
||||
public NetConnection(String address){
|
||||
this.id = lastID++;
|
||||
this.address = address;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -106,7 +106,7 @@ public class PausedDialog extends FloatingDialog{
|
|||
return;
|
||||
}
|
||||
|
||||
if(control.saves.getCurrent() == null || !control.saves.getCurrent().isAutosave() || state.rules.tutorial){
|
||||
if(control.saves.getCurrent() == null || !control.saves.getCurrent().isAutosave() || state.rules.tutorial || Net.client()){
|
||||
state.set(State.menu);
|
||||
logic.reset();
|
||||
return;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue