use of io.anuke.mindustry.world.Tile in project Mindustry by Anuken.
the class EMP method drawOver.
@Override
public void drawOver() {
Draw.color(Color.SKY);
for (int i = 0; i < targets.size; i++) {
Tile target = targets.get(i);
drawLine(target.worldx(), target.worldy());
float rad = 5f * fract();
Draw.rect("circle", target.worldx(), target.worldy(), rad, rad);
}
for (int i = 0; i < 14 - targets.size; i++) {
tr.trns(Mathf.randomSeed(i + id * 77) * 360f, radius * tilesize);
drawLine(x + tr.x, y + tr.y);
}
Lines.stroke(fract() * 2f);
Lines.poly(x, y, 34, radius * tilesize);
Draw.reset();
}
use of io.anuke.mindustry.world.Tile in project Mindustry by Anuken.
the class EnemyType method move.
public void move(Enemy enemy) {
if (Net.client()) {
enemy.interpolate();
if (targetClient)
updateTargeting(enemy, false);
return;
}
float speed = this.speed + 0.04f * enemy.tier;
float range = this.range + enemy.tier * 5;
Tile core = world.getCore();
if (core == null)
return;
if (enemy.idletime > maxIdleLife && enemy.node > 0) {
enemy.onDeath();
return;
}
boolean nearCore = enemy.distanceTo(core.worldx(), core.worldy()) <= range - 18f && stopNearCore;
Vector2 vec;
if (nearCore) {
vec = move.setZero();
if (targetCore)
enemy.target = core.entity;
} else {
vec = world.pathfinder().find(enemy);
vec.sub(enemy.x, enemy.y).limit(speed);
}
shift.setZero();
float shiftRange = enemy.hitbox.width + 2f;
float avoidRange = shiftRange + 4f;
float attractRange = avoidRange + 7f;
float avoidSpeed = this.speed / 2.7f;
Entities.getNearby(enemyGroup, enemy.x, enemy.y, range, en -> {
Enemy other = (Enemy) en;
if (other == enemy)
return;
float dst = other.distanceTo(enemy);
if (dst < shiftRange) {
float scl = Mathf.clamp(1.4f - dst / shiftRange) * mass * 1f / mass;
shift.add((enemy.x - other.x) * scl, (enemy.y - other.y) * scl);
} else if (dst < avoidRange) {
calc.set((enemy.x - other.x), (enemy.y - other.y)).setLength(avoidSpeed);
shift.add(calc.scl(1.1f));
} else if (dst < attractRange && !nearCore && !isCalculating(enemy)) {
calc.set((enemy.x - other.x), (enemy.y - other.y)).setLength(avoidSpeed);
shift.add(calc.scl(-1));
}
});
shift.limit(1f);
vec.add(shift.scl(0.5f));
enemy.move(vec.x * Timers.delta(), vec.y * Timers.delta());
updateTargeting(enemy, nearCore);
behavior(enemy);
}
use of io.anuke.mindustry.world.Tile in project Mindustry by Anuken.
the class BlockRenderer method processBlocks.
/**
*Process all blocks to draw, simultaneously drawing block shadows and static blocks.
*/
public void processBlocks() {
requestidx = 0;
int crangex = (int) (camera.viewportWidth / (chunksize * tilesize)) + 1;
int crangey = (int) (camera.viewportHeight / (chunksize * tilesize)) + 1;
int rangex = (int) (camera.viewportWidth * camera.zoom / tilesize / 2) + 2;
int rangey = (int) (camera.viewportHeight * camera.zoom / tilesize / 2) + 2;
int expandr = 3;
Graphics.surface(renderer.shadowSurface);
for (int x = -rangex - expandr; x <= rangex + expandr; x++) {
for (int y = -rangey - expandr; y <= rangey + expandr; y++) {
int worldx = Mathf.scl(camera.position.x, tilesize) + x;
int worldy = Mathf.scl(camera.position.y, tilesize) + y;
boolean expanded = (x < -rangex || x > rangex || y < -rangey || y > rangey);
Tile tile = world.tile(worldx, worldy);
if (tile != null) {
Block block = tile.block();
if (!expanded && block != Blocks.air && world.isAccessible(worldx, worldy)) {
block.drawShadow(tile);
}
if (!(block instanceof StaticBlock)) {
if (block == Blocks.air) {
if (!state.is(State.paused))
tile.floor().update(tile);
} else {
if (!expanded) {
addRequest(tile, Layer.block);
}
if (block.expanded || !expanded) {
if (block.layer != null && block.isLayer(tile)) {
addRequest(tile, block.layer);
}
if (block.layer2 != null && block.isLayer2(tile)) {
addRequest(tile, block.layer2);
}
}
}
}
}
}
}
Draw.color(0, 0, 0, 0.15f);
Graphics.flushSurface();
Draw.color();
Graphics.end();
drawCache(1, crangex, crangey);
Graphics.begin();
Arrays.sort(requests.items, 0, requestidx);
iterateidx = 0;
}
use of io.anuke.mindustry.world.Tile in project Mindustry by Anuken.
the class BlockRenderer method cacheChunk.
void cacheChunk(int cx, int cy, boolean floor) {
if (cbatch == null) {
createBatch();
}
cbatch.begin();
Graphics.useBatch(cbatch);
for (int tilex = cx * chunksize; tilex < (cx + 1) * chunksize; tilex++) {
for (int tiley = cy * chunksize; tiley < (cy + 1) * chunksize; tiley++) {
Tile tile = world.tile(tilex, tiley);
if (tile == null)
continue;
if (floor) {
if (!(tile.block() instanceof StaticBlock)) {
tile.floor().draw(tile);
}
} else if (tile.block() instanceof StaticBlock) {
tile.block().draw(tile);
}
}
}
Graphics.popBatch();
cbatch.end();
cache[cx][cy][floor ? 0 : 1] = cbatch.getLastCache();
}
use of io.anuke.mindustry.world.Tile in project Mindustry by Anuken.
the class ServerControl method registerCommands.
private void registerCommands() {
handler.register("help", "Displays this command list.", arg -> {
info("Commands:");
for (Command command : handler.getCommandList()) {
print(" &y" + command.text + (command.paramText.isEmpty() ? "" : " ") + command.paramText + " - &lm" + command.description);
}
});
handler.register("version", "Displays server version info.", arg -> {
info("&lmVersion: &lyMindustry {0} {1} / {2}", Version.code, Version.type, Version.buildName);
});
handler.register("exit", "Exit the server application.", arg -> {
info("Shutting down server.");
Net.dispose();
Gdx.app.exit();
});
handler.register("stop", "Stop hosting the server.", arg -> {
Net.closeServer();
state.set(State.menu);
netServer.reset();
Log.info("Stopped server.");
});
handler.register("host", "[mapname] [mode]", "Open the server with a specific map.", arg -> {
if (state.is(State.playing)) {
err("Already hosting. Type 'stop' to stop hosting first.");
return;
}
Map result = null;
if (arg.length > 0) {
String search = arg[0];
for (Map map : world.maps().list()) {
if (map.name.equalsIgnoreCase(search))
result = map;
}
if (result == null) {
err("No map with name &y'{0}'&lr found.", search);
return;
}
} else {
while (result == null || !result.visible) result = world.maps().getAllMaps().random();
Log.info("&ly&fiNo map specified, so &lb{0}&ly was chosen randomly.", result.name);
}
GameMode mode;
try {
mode = arg.length < 2 ? GameMode.waves : GameMode.valueOf(arg[1]);
} catch (IllegalArgumentException e) {
err("No gamemode '{0}' found.", arg[1]);
return;
}
info("Loading map...");
state.mode = mode;
logic.reset();
world.loadMap(result);
state.set(State.playing);
info("Map loaded.");
host();
});
handler.register("maps", "Display all available maps.", arg -> {
Log.info("Maps:");
for (Map map : world.maps().getAllMaps()) {
Log.info(" &ly{0}: &lb&fi{1} / {2}x{3}", map.name, map.custom ? "Custom" : "Default", map.getWidth(), map.getHeight());
}
});
handler.register("status", "Display server status.", arg -> {
if (state.is(State.menu)) {
info("&lyStatus: &rserver closed");
} else {
info("&lyStatus: &lcPlaying on map &fi{0}&fb &lb/&lc Wave {1} &lb/&lc {2}", Strings.capitalize(world.getMap().name), state.wave, Strings.capitalize(state.difficulty.name()));
if (state.enemies > 0) {
info("&ly{0} enemies remaining.", state.enemies);
} else {
info("&ly{0} seconds until next wave.", (int) (state.wavetime / 60));
}
if (playerGroup.size() > 0) {
info("&lyPlayers: {0}", playerGroup.size());
for (Player p : playerGroup.all()) {
print(" &y" + p.name);
}
} else {
info("&lyNo players connected.");
}
info("&lbFPS: {0}", (int) (60f / Timers.delta()));
}
});
handler.register("players", "Display player info.", arg -> {
if (state.is(State.menu)) {
info("&lyServer is closed.");
} else {
if (playerGroup.size() > 0) {
info("&lyPlayers: {0}", playerGroup.size());
for (Player p : playerGroup.all()) {
print(" &y{0} / Connection {1} / IP: {2}", p.name, p.clientid, Net.getConnection(p.clientid).address);
}
} else {
info("&lyNo players connected.");
}
}
});
handler.register("say", "<message...>", "Send a message to all players.", arg -> {
if (!state.is(State.playing)) {
err("Not hosting. Host a game first.");
return;
}
netCommon.sendMessage("[GRAY][[Server]:[] " + arg[0]);
info("&lyServer: &lb{0}", arg[0]);
});
handler.register("difficulty", "<difficulty>", "Set game difficulty.", arg -> {
try {
Difficulty diff = Difficulty.valueOf(arg[0]);
state.difficulty = diff;
info("Difficulty set to '{0}'.", arg[0]);
} catch (IllegalArgumentException e) {
err("No difficulty with name '{0}' found.", arg[0]);
}
});
handler.register("friendlyfire", "<on/off>", "Enable or disable friendly fire", arg -> {
String s = arg[0];
if (s.equalsIgnoreCase("on")) {
NetEvents.handleFriendlyFireChange(true);
state.friendlyFire = true;
info("Friendly fire enabled.");
} else if (s.equalsIgnoreCase("off")) {
NetEvents.handleFriendlyFireChange(false);
state.friendlyFire = false;
info("Friendly fire disabled.");
} else {
err("Incorrect command usage.");
}
});
handler.register("shuffle", "<normal/custom/both/off>", "Set map shuffling.", arg -> {
try {
mode = ShuffleMode.valueOf(arg[0]);
Settings.putString("shufflemode", arg[0]);
Settings.save();
info("Shuffle mode set to '{0}'.", arg[0]);
} catch (Exception e) {
err("Unknown shuffle mode '{0}'.", arg[0]);
}
});
handler.register("kick", "<username...>", "Kick a person by name.", arg -> {
if (!state.is(State.playing)) {
err("Not hosting a game yet. Calm down.");
return;
}
Player target = null;
for (Player player : playerGroup.all()) {
if (player.name.equalsIgnoreCase(arg[0])) {
target = player;
break;
}
}
if (target != null) {
netServer.kick(target.clientid, KickReason.kick);
info("It is done.");
} else {
info("Nobody with that name could be found...");
}
});
handler.register("ban", "<username...>", "Ban a person by name.", arg -> {
if (!state.is(State.playing)) {
err("Can't ban people by name with no players.");
return;
}
Player target = null;
for (Player player : playerGroup.all()) {
if (player.name.equalsIgnoreCase(arg[0])) {
target = player;
break;
}
}
if (target != null) {
String ip = Net.getConnection(target.clientid).address;
netServer.admins.banPlayerIP(ip);
netServer.admins.banPlayerID(netServer.admins.getTrace(ip).uuid);
netServer.kick(target.clientid, KickReason.banned);
info("Banned player by IP and ID: {0} / {1}", ip, netServer.admins.getTrace(ip).uuid);
} else {
info("Nobody with that name could be found.");
}
});
handler.register("bans", "List all banned IPs and IDs.", arg -> {
Array<PlayerInfo> bans = netServer.admins.getBanned();
if (bans.size == 0) {
Log.info("No ID-banned players have been found.");
} else {
Log.info("&lyBanned players [ID]:");
for (PlayerInfo info : bans) {
Log.info(" &ly {0} / Last known name: '{1}'", info.id, info.lastName);
}
}
Array<String> ipbans = netServer.admins.getBannedIPs();
if (ipbans.size == 0) {
Log.info("No IP-banned players have been found.");
} else {
Log.info("&lmBanned players [IP]:");
for (String string : ipbans) {
PlayerInfo info = netServer.admins.findByIP(string);
Log.info(" &lm '{0}' / Last known name: '{1}' / ID: '{2}'", string, info.lastName, info.id);
}
}
});
handler.register("banip", "<ip>", "Ban a person by IP.", arg -> {
if (netServer.admins.banPlayerIP(arg[0])) {
info("Banned player by IP: {0}.", arg[0]);
for (Player player : playerGroup.all()) {
if (Net.getConnection(player.clientid).address.equals(arg[0])) {
netServer.kick(player.clientid, KickReason.banned);
break;
}
}
} else {
err("That IP is already banned!");
}
});
handler.register("banid", "<id>", "Ban a person by their unique ID.", arg -> {
if (netServer.admins.banPlayerID(arg[0])) {
info("Banned player by ID: {0}.", arg[0]);
for (Player player : playerGroup.all()) {
if (netServer.admins.getTrace(Net.getConnection(player.clientid).address).uuid.equals(arg[0])) {
netServer.kick(player.clientid, KickReason.banned);
break;
}
}
} else {
err("That ID is already banned!");
}
});
handler.register("unbanip", "<ip>", "Completely unban a person by IP.", arg -> {
if (netServer.admins.unbanPlayerIP(arg[0])) {
info("Unbanned player by IP: {0}.", arg[0]);
} else {
err("That IP is not banned!");
}
});
handler.register("unbanid", "<id>", "Completely unban a person by ID.", arg -> {
if (netServer.admins.unbanPlayerID(arg[0])) {
info("&lmUnbanned player by ID: {0}.", arg[0]);
} else {
err("That IP is not banned!");
}
});
handler.register("admin", "<username...>", "Make a user admin", arg -> {
if (!state.is(State.playing)) {
err("Open the server first.");
return;
}
Player target = null;
for (Player player : playerGroup.all()) {
if (player.name.equalsIgnoreCase(arg[0])) {
target = player;
break;
}
}
if (target != null) {
String id = netServer.admins.getTrace(Net.getConnection(target.clientid).address).uuid;
netServer.admins.adminPlayer(id, Net.getConnection(target.clientid).address);
NetEvents.handleAdminSet(target, true);
info("Admin-ed player by ID: {0} / {1}", id, arg[0]);
} else {
info("Nobody with that name could be found.");
}
});
handler.register("unadmin", "<username...>", "Removes admin status from a player", arg -> {
if (!state.is(State.playing)) {
err("Open the server first.");
return;
}
Player target = null;
for (Player player : playerGroup.all()) {
if (player.name.equalsIgnoreCase(arg[0])) {
target = player;
break;
}
}
if (target != null) {
String id = netServer.admins.getTrace(Net.getConnection(target.clientid).address).uuid;
netServer.admins.unAdminPlayer(id);
NetEvents.handleAdminSet(target, false);
info("Un-admin-ed player by ID: {0} / {1}", id, arg[0]);
} else {
info("Nobody with that name could be found.");
}
});
handler.register("admins", "List all admins.", arg -> {
Array<PlayerInfo> admins = netServer.admins.getAdmins();
if (admins.size == 0) {
Log.info("No admins have been found.");
} else {
Log.info("&lyAdmins:");
for (PlayerInfo info : admins) {
Log.info(" &lm {0} / ID: '{1}' / IP: '{2}'", info.lastName, info.id, info.lastIP);
}
}
});
handler.register("runwave", "Trigger the next wave.", arg -> {
if (!state.is(State.playing)) {
err("Not hosting. Host a game first.");
} else if (state.enemies > 0) {
err("There are still {0} enemies remaining.", state.enemies);
} else {
logic.runWave();
info("Wave spawned.");
}
});
handler.register("load", "<slot>", "Load a save from a slot.", arg -> {
if (state.is(State.playing)) {
err("Already hosting. Type 'stop' to stop hosting first.");
return;
} else if (!Strings.canParseInt(arg[0])) {
err("Invalid save slot '{0}'.", arg[0]);
return;
}
int slot = Strings.parseInt(arg[0]);
if (!SaveIO.isSaveValid(slot)) {
err("No save data found for slot.");
return;
}
SaveIO.loadFromSlot(slot);
info("Save loaded.");
host();
state.set(State.playing);
});
handler.register("save", "<slot>", "Save game state to a slot.", arg -> {
if (!state.is(State.playing)) {
err("Not hosting. Host a game first.");
return;
} else if (!Strings.canParseInt(arg[0])) {
err("Invalid save slot '{0}'.", arg[0]);
return;
}
int slot = Strings.parseInt(arg[0]);
SaveIO.saveToSlot(slot);
info("Saved to slot {0}.", slot);
});
handler.register("gameover", "Force a game over.", arg -> {
if (state.is(State.menu)) {
info("Not playing a map.");
return;
}
world.removeBlock(world.getCore());
info("Core destroyed.");
});
handler.register("debug", "Print debug info", arg -> {
info(DebugFragment.debugInfo());
});
handler.register("traceblock", "<x> <y>", "Prints debug info about a block", arg -> {
try {
int x = Integer.parseInt(arg[0]);
int y = Integer.parseInt(arg[1]);
Tile tile = world.tile(x, y);
if (tile != null) {
if (tile.entity != null) {
Array<Object> arr = tile.block().getDebugInfo(tile);
StringBuilder result = new StringBuilder();
for (int i = 0; i < arr.size / 2; i++) {
result.append(arr.get(i * 2));
result.append(": ");
result.append(arr.get(i * 2 + 1));
result.append("\n");
}
Log.info("&ly{0}", result);
} else {
Log.info("No tile entity for that block.");
}
} else {
Log.info("No tile at that location.");
}
} catch (NumberFormatException e) {
Log.err("Invalid coordinates passed.");
}
});
handler.register("info", "<UUID>", "Get global info for a player's UUID.", arg -> {
PlayerInfo info = netServer.admins.getInfoOptional(arg[0]);
if (info != null) {
Log.info("&lcTrace info for player '{0}':", info.lastName);
Log.info(" &lyall names used: {0}", info.names);
Log.info(" &lyIP: {0}", info.lastIP);
Log.info(" &lyall IPs used: {0}", info.ips);
Log.info(" &lytimes joined: {0}", info.timesJoined);
Log.info(" &lytimes kicked: {0}", info.timesKicked);
Log.info("");
Log.info(" &lytotal blocks broken: {0}", info.totalBlocksBroken);
Log.info(" &lytotal blocks placed: {0}", info.totalBlockPlaced);
} else {
info("Nobody with that UUID could be found.");
}
});
handler.register("trace", "<username...>", "Trace a player's actions", arg -> {
if (!state.is(State.playing)) {
err("Open the server first.");
return;
}
Player target = null;
for (Player player : playerGroup.all()) {
if (player.name.equalsIgnoreCase(arg[0])) {
target = player;
break;
}
}
if (target != null) {
TraceInfo info = netServer.admins.getTrace(Net.getConnection(target.clientid).address);
Log.info("&lcTrace info for player '{0}':", target.name);
Log.info(" &lyEntity ID: {0}", info.playerid);
Log.info(" &lyIP: {0}", info.ip);
Log.info(" &lyUUID: {0}", info.uuid);
Log.info(" &lycustom client: {0}", info.modclient);
Log.info(" &lyandroid: {0}", info.android);
Log.info("");
Log.info(" &lytotal blocks broken: {0}", info.totalBlocksBroken);
Log.info(" &lystructure blocks broken: {0}", info.structureBlocksBroken);
Log.info(" &lylast block broken: {0}", info.lastBlockBroken.formalName);
Log.info("");
Log.info(" &lytotal blocks placed: {0}", info.totalBlocksPlaced);
Log.info(" &lylast block placed: {0}", info.lastBlockPlaced.formalName);
} else {
info("Nobody with that name could be found.");
}
});
}
Aggregations