Everything has been broken

This commit is contained in:
Anuken
2018-03-17 12:22:21 -04:00
parent ba84bb82b4
commit 713875100b
22 changed files with 78 additions and 112 deletions

View File

@@ -164,7 +164,9 @@ public class NetClient extends Module {
});
Net.handleClient(PlacePacket.class, (packet) -> {
Placement.placeBlock(packet.x, packet.y, Block.getByID(packet.block), packet.rotation, true, Timers.get("placeblocksound", 10));
Player placer = playerGroup.getByID(packet.playerid);
Placement.placeBlock(placer.team, packet.x, packet.y, Block.getByID(packet.block), packet.rotation, true, Timers.get("placeblocksound", 10));
if(packet.playerid == player.id){
Tile tile = world.tile(packet.x, packet.y);
@@ -172,8 +174,11 @@ public class NetClient extends Module {
}
});
Net.handleClient(BreakPacket.class, (packet) ->
Placement.breakBlock(packet.x, packet.y, true, Timers.get("breakblocksound", 10)));
Net.handleClient(BreakPacket.class, (packet) -> {
Player placer = playerGroup.getByID(packet.playerid);
Placement.breakBlock(placer.team, packet.x, packet.y, true, Timers.get("breakblocksound", 10));
});
Net.handleClient(EntitySpawnPacket.class, packet -> {
EntityGroup group = packet.group;

View File

@@ -172,11 +172,12 @@ public class NetServer extends Module{
});
Net.handleServer(PlacePacket.class, (id, packet) -> {
packet.playerid = connections.get(id).id;
Player placer = connections.get(id);
packet.playerid = placer.id;
Block block = Block.getByID(packet.block);
if(!Placement.validPlace(packet.x, packet.y, block)) return;
if(!Placement.validPlace(placer.team, packet.x, packet.y, block)) return;
Recipe recipe = Recipes.getByResult(block);
@@ -184,7 +185,7 @@ public class NetServer extends Module{
state.inventory.removeItems(recipe.requirements);
Placement.placeBlock(packet.x, packet.y, block, packet.rotation, true, false);
Placement.placeBlock(placer.team, packet.x, packet.y, block, packet.rotation, true, false);
admins.getTrace(Net.getConnection(id).address).lastBlockPlaced = block;
admins.getTrace(Net.getConnection(id).address).totalBlocksPlaced ++;
@@ -193,11 +194,12 @@ public class NetServer extends Module{
});
Net.handleServer(BreakPacket.class, (id, packet) -> {
packet.playerid = connections.get(id).id;
Player placer = connections.get(id);
packet.playerid = placer.id;
if(!Placement.validBreak(packet.x, packet.y)) return;
if(!Placement.validBreak(placer.team, packet.x, packet.y)) return;
Block block = Placement.breakBlock(packet.x, packet.y, true, false);
Block block = Placement.breakBlock(placer.team, packet.x, packet.y, true, false);
if(block != null) {
admins.getTrace(Net.getConnection(id).address).lastBlockBroken = block;

View File

@@ -224,9 +224,9 @@ public class Renderer extends RendererModule{
Shaders.outline.color.set(team.color);
Graphics.beginShaders(Shaders.outline);
//Graphics.shader(Shaders.hit);
Graphics.shader(Shaders.hit, false);
drawTeam(team, flying);
//Graphics.shader();
Graphics.shader();
Graphics.endShaders();
}
}

View File

@@ -29,7 +29,8 @@ public class World extends Module{
private Tile[][] tiles;
private Pathfind pathfind = new Pathfind();
private Maps maps = new Maps();
private Tile core;
private Array<Tile> allyCores = new Array<>();
private Array<Tile> enemyCores = new Array<>();
private Array<SpawnPoint> spawns = new Array<>();
private Array<Tile> tempTiles = new Array<>();
@@ -185,43 +186,12 @@ public class World extends Module{
core = WorldGenerator.generate(map.pixmap, tiles, spawns);
Placement.placeBlock(core.x, core.y, ProductionBlocks.core, 0, false, false);
if(!map.name.equals("tutorial")){
setDefaultBlocks();
}else{
control.tutorial().setDefaultBlocks(core.x, core.y);
}
control.tutorial().setDefaultBlocks(core.x, core.y);
pathfind.resetPaths();
}
void setDefaultBlocks(){
int x = core.x, y = core.y;
int flip = Mathf.sign(!currentMap.flipBase);
int fr = currentMap.flipBase ? 2 : 0;
set(x, y-2*flip, DistributionBlocks.conveyor, 1 + fr);
set(x, y-3*flip, DistributionBlocks.conveyor, 1 + fr);
for(int i = 0; i < 2; i ++){
int d = Mathf.sign(i-0.5f);
set(x+2*d, y-2*flip, ProductionBlocks.stonedrill, d);
set(x+2*d, y-1*flip, DistributionBlocks.conveyor, 1 + fr);
set(x+2*d, y, DistributionBlocks.conveyor, 1 + fr);
set(x+2*d, y+1*flip, WeaponBlocks.doubleturret, 0 + fr);
set(x+1*d, y-3*flip, DistributionBlocks.conveyor, 2*d);
set(x+2*d, y-3*flip, DistributionBlocks.conveyor, 2*d);
set(x+2*d, y-4*flip, DistributionBlocks.conveyor, 1 + fr);
set(x+2*d, y-5*flip, DistributionBlocks.conveyor, 1 + fr);
set(x+3*d, y-5*flip, ProductionBlocks.stonedrill, 0 + fr);
set(x+3*d, y-4*flip, ProductionBlocks.stonedrill, 0 + fr);
set(x+3*d, y-3*flip, ProductionBlocks.stonedrill, 0 + fr);
}
}
void set(int x, int y, Block type, int rot){
if(!Mathf.inBounds(x, y, tiles)){
return;

View File

@@ -1,10 +1,8 @@
package io.anuke.mindustry.entities;
import io.anuke.mindustry.entities.units.BaseUnit;
import io.anuke.mindustry.game.Team;
import io.anuke.mindustry.world.Tile;
import io.anuke.ucore.entities.BulletEntity;
import io.anuke.ucore.entities.Entity;
import io.anuke.ucore.util.Timer;
import static io.anuke.mindustry.Vars.*;
@@ -12,7 +10,7 @@ import static io.anuke.mindustry.Vars.*;
public class Bullet extends BulletEntity{
public Timer timer = new Timer(3);
public Bullet(BulletType type, Entity owner, float x, float y, float angle){
public Bullet(BulletType type, Unit owner, float x, float y, float angle){
super(type, owner, angle);
set(x, y);
this.type = type;
@@ -38,7 +36,11 @@ public class Bullet extends BulletEntity{
}
public boolean collidesTiles(){
return owner instanceof BaseUnit;
return true;
}
public Unit owner(){
return (Unit)owner;
}
public Team team(){
@@ -56,7 +58,7 @@ public class Bullet extends BulletEntity{
if (tile == null) return false;
tile = tile.target();
if (tile.entity != null && tile.entity.collide(this) && !tile.entity.dead) {
if (tile.entity != null && tile.entity.collide(this) && !tile.entity.dead && tile.entity.tile.getTeam() != team()) {
tile.entity.collision(this);
remove();
type.hit(this);

View File

@@ -148,7 +148,7 @@ public abstract class BulletType extends BaseBulletType<Bullet>{
public void hit(Bullet b, float hitx, float hity) {
Effects.effect(shellsmoke, b);
for(int i = 0; i < 3; i ++){
Bullet bullet = new Bullet(flakspark, b.owner, hitx, hity, b.angle() + Mathf.range(120f));
Bullet bullet = new Bullet(flakspark, b.owner(), hitx, hity, b.angle() + Mathf.range(120f));
bullet.add();
}
}
@@ -255,7 +255,7 @@ public abstract class BulletType extends BaseBulletType<Bullet>{
//TODO remove translation() usage
Angles.circleVectors(30, 6f, (nx, ny) -> {
float ang = Mathf.atan2(nx, ny);
Bullet o = new Bullet(blastshot, b.owner, b.x + nx, b.y + ny, ang).add();
Bullet o = new Bullet(blastshot, b.owner(), b.x + nx, b.y + ny, ang).add();
o.damage = b.damage/9;
});
}
@@ -419,7 +419,7 @@ public abstract class BulletType extends BaseBulletType<Bullet>{
public void hit(Bullet b, float hitx, float hity) {
for(int i = 0; i < 4; i ++){
Bullet bullet = new Bullet(scrap, b.owner, b.x, b.y, b.angle() + Mathf.range(80f));
Bullet bullet = new Bullet(scrap, b.owner(), b.x, b.y, b.angle() + Mathf.range(80f));
bullet.add();
}
}

View File

@@ -143,7 +143,7 @@ public class Player extends Unit{
float ft = Mathf.sin(walktime, 6f, 2f);
//Draw.alpha(hitTime / hitDuration);
Draw.alpha(hitTime / hitDuration);
if(!mech.flying) {
for (int i : Mathf.signs) {
@@ -163,7 +163,7 @@ public class Player extends Unit{
Draw.rect(weapon.name + "-equip", x + tr.x, y + tr.y, w, 8, rotation - 90);
}
//Draw.alpha(1f);
Draw.alpha(1f);
x = px;
y = py;

View File

@@ -103,7 +103,7 @@ public class BaseUnit extends Unit {
public void added(){
maxhealth = type.health;
//hitbox.solid = true;
hitbox.solid = true;
hitbox.setSize(type.hitsize);
hitboxTile.setSize(type.hitsizeTile);

View File

@@ -1,5 +1,6 @@
package io.anuke.mindustry.entities.units;
import io.anuke.mindustry.entities.Unit;
import io.anuke.ucore.graphics.Draw;
import io.anuke.ucore.util.Mathf;
import io.anuke.ucore.util.Translator;
@@ -16,6 +17,8 @@ public abstract class GroundUnitType extends UnitType{
@Override
public void draw(BaseUnit unit) {
Draw.alpha(unit.hitTime / Unit.hitDuration);
float walktime = unit.walkTime; //TODO!
float ft = Mathf.sin(walktime, 6f, 2f);
@@ -28,6 +31,8 @@ public abstract class GroundUnitType extends UnitType{
Draw.rect(name + "-base", unit.x, unit.y, unit.baseRotation- 90);
Draw.rect(name, unit.x, unit.y, unit.rotation -90);
Draw.alpha(1f);
}
@Override

View File

@@ -48,6 +48,12 @@ public abstract class UnitType {
}
public void update(BaseUnit unit){
if(unit.hitTime > 0){
unit.hitTime -= Timers.delta();
}
if(unit.hitTime < 0) unit.hitTime = 0;
if(Net.client()){
unit.interpolate();
return;

View File

@@ -91,7 +91,7 @@ public abstract class InputHandler extends InputAdapter{
return false;
}
return Placement.validPlace(x, y, type);
return Placement.validPlace(player.team, x, y, type);
}
public boolean validBreak(int x, int y){
@@ -111,12 +111,12 @@ public abstract class InputHandler extends InputAdapter{
}
}
return Placement.validBreak(x, y);
return Placement.validBreak(player.team, x, y);
}
public void placeBlock(int x, int y, Block result, int rotation, boolean effects, boolean sound){
if(!Net.client()){
Placement.placeBlock(x, y, result, rotation, effects, sound);
Placement.placeBlock(player.team, x, y, result, rotation, effects, sound);
Tile tile = world.tile(x, y);
if(tile != null) result.placed(tile);
}
@@ -127,7 +127,7 @@ public abstract class InputHandler extends InputAdapter{
}
public void breakBlock(int x, int y, boolean sound){
if(!Net.client()) Placement.breakBlock(x, y, true, sound);
if(!Net.client()) Placement.breakBlock(player.team, x, y, true, sound);
if(Net.active()){
NetEvents.handleBreak(x, y);

View File

@@ -114,7 +114,6 @@ public class BlockLoader {
DistributionBlocks.conduit,
ProductionBlocks.coaldrill,
WeaponBlocks.chainturret,
SpecialBlocks.enemySpawn,
DebugBlocks.powerVoid
//add any new block sections here
};

View File

@@ -9,7 +9,11 @@ public class Item implements Comparable<Item>{
private static final Array<Item> items = new Array<>();
public static final Item
stone = new Item("stone"),
stone = new Item("stone"){
{
material = false;
}
},
iron = new Item("iron"),
coal = new Item("coal"){
{

View File

@@ -1,33 +1,10 @@
package io.anuke.mindustry.world;
import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.graphics.Pixmap;
import com.badlogic.gdx.graphics.Texture;
import io.anuke.ucore.util.Bundles;
public class Map{
public int id = -1;
public String name;
public String author;
public String description;
public boolean visible = true;
public boolean flipBase = false;
public boolean custom = false;
public boolean oreGen = true;
public Color backgroundColor = Color.valueOf("646464");
public transient Pixmap pixmap;
public transient Texture texture;
public Map(){}
public String localized(){
return Bundles.get("map."+name+".name", name);
}
public int getWidth(){
return pixmap.getWidth();
}
public int getHeight(){
return pixmap.getHeight();
}
}

View File

@@ -6,6 +6,7 @@ import com.badlogic.gdx.utils.Array;
import io.anuke.mindustry.entities.Player;
import io.anuke.mindustry.entities.Units;
import io.anuke.mindustry.game.SpawnPoint;
import io.anuke.mindustry.game.Team;
import io.anuke.mindustry.graphics.Fx;
import io.anuke.mindustry.resource.ItemStack;
import io.anuke.mindustry.resource.Recipe;
@@ -22,7 +23,7 @@ public class Placement {
private static Array<Tile> tempTiles = new Array<>();
/**Returns block type that was broken, or null if unsuccesful.*/
public static Block breakBlock(int x, int y, boolean effect, boolean sound){
public static Block breakBlock(Team team, int x, int y, boolean effect, boolean sound){
Tile tile = world.tile(x, y);
if(tile == null) return null;
@@ -58,13 +59,14 @@ public class Placement {
return block;
}
public static void placeBlock(int x, int y, Block result, int rotation, boolean effects, boolean sound){
public static void placeBlock(Team team, int x, int y, Block result, int rotation, boolean effects, boolean sound){
Tile tile = world.tile(x, y);
//just in case
if(tile == null) return;
tile.setBlock(result, rotation);
tile.setTeam(team);
if(result.isMultiblock()){
int offsetx = -(result.size-1)/2;
@@ -76,8 +78,10 @@ public class Placement {
int worldy = dy + offsety + y;
if(!(worldx == x && worldy == y)){
Tile toplace = world.tile(worldx, worldy);
if(toplace != null)
toplace.setLinked((byte)(dx + offsetx), (byte)(dy + offsety));
if(toplace != null) {
toplace.setLinked((byte) (dx + offsetx), (byte) (dy + offsety));
toplace.setTeam(team);
}
}
if(effects) Effects.effect(Fx.place, worldx * tilesize, worldy * tilesize);
@@ -88,7 +92,7 @@ public class Placement {
if(effects && sound) threads.run(() -> Effects.sound("place", x * tilesize, y * tilesize));
}
public static boolean validPlace(int x, int y, Block type){
public static boolean validPlace(Team team, int x, int y, Block type){
for(int i = 0; i < world.getSpawns().size; i ++){
SpawnPoint spawn = world.getSpawns().get(i);
if(Vector2.dst(x * tilesize, y * tilesize, spawn.start.worldx(), spawn.start.worldy()) < enemyspawnspace){
@@ -147,7 +151,7 @@ public class Placement {
}
return true;
}else {
return tile.block() != type
return tile.block() != type && (tile.getTeam() == Team.none || tile.getTeam() == team)
&& (type.canReplace(tile.block()) || tile.block().alwaysReplace)
&& tile.block().isMultiblock() == type.isMultiblock() || tile.block() == Blocks.air;
}
@@ -157,7 +161,7 @@ public class Placement {
return tile != null && tile.x == world.getCore().x && tile.y == world.getCore().y - 2;
}
public static boolean validBreak(int x, int y){
public static boolean validBreak(Team team, int x, int y){
Tile tile = world.tile(x, y);
if(tile == null || tile.block() == ProductionBlocks.core) return false;
@@ -166,6 +170,6 @@ public class Placement {
return false;
}
return tile.breakable();
return tile.breakable() && (tile.getTeam() == Team.none || tile.getTeam() == team);
}
}

View File

@@ -298,6 +298,8 @@ public class Tile{
entity = null;
}
team = 0;
Block block = block();
if (block.destructible || block.update) {

View File

@@ -15,7 +15,7 @@ import io.anuke.ucore.util.Mathf;
import static io.anuke.mindustry.Vars.world;
public class WorldGenerator {
public static final ObjectMap<Block, Block> rocks = new ObjectMap(){{
public static final ObjectMap<Block, Block> rocks = new ObjectMap<Block, Block>(){{
put(Blocks.stone, Blocks.rock);
put(Blocks.snow, Blocks.icerock);
put(Blocks.grass, Blocks.shrub);
@@ -23,10 +23,8 @@ public class WorldGenerator {
}};
/**Returns the core (starting) block. Should fill spawns with the correct spawnpoints.*/
public static Tile generate(Pixmap pixmap, Tile[][] tiles, Array<SpawnPoint> spawns){
public static void generate(Tile[][] tiles, Map map){
Noise.setSeed(world.getSeed());
Tile core = null;
for(int x = 0; x < pixmap.getWidth(); x ++){
for(int y = 0; y < pixmap.getHeight(); y ++){
@@ -88,7 +86,5 @@ public class WorldGenerator {
tiles[x][y].updateOcclusion();
}
}
return core;
}
}

View File

@@ -10,6 +10,9 @@ import io.anuke.mindustry.world.blocks.types.*;
public class Blocks{
public static final Block
//player/enemy spawnpoint
spawn = new Block("spawn"){},
air = new Block("air"){
//no drawing here

View File

@@ -1,9 +0,0 @@
package io.anuke.mindustry.world.blocks;
import io.anuke.mindustry.world.Block;
public class SpecialBlocks{
public static final Block
playerSpawn = new Block("playerspawn"){},
enemySpawn = new Block("enemyspawn"){};
}