mirror of
https://github.com/Anuken/Mindustry.git
synced 2025-02-02 20:33:50 +07:00
Building / Fixed some tests
This commit is contained in:
parent
03d0f54083
commit
8b4fcf99a6
@ -3,10 +3,13 @@
|
||||
mindustry.entities.def.PuddleComp=6
|
||||
mindustry.entities.def.BulletComp=1
|
||||
dagger=0
|
||||
phantom=11
|
||||
mindustry.entities.def.StandardEffectComp=7
|
||||
vanguard=9
|
||||
mindustry.entities.def.PlayerComp=5
|
||||
draug=10
|
||||
mindustry.entities.def.DecalComp=2
|
||||
mindustry.entities.def.TileComp=8
|
||||
spirit=12
|
||||
mindustry.entities.def.FireComp=3
|
||||
mindustry.entities.def.GroundEffectComp=4
|
@ -0,0 +1 @@
|
||||
{fields:[{name:drownTime,type:float,size:4},{name:elevation,type:float,size:4},{name:health,type:float,size:4},{name:rotation,type:float,size:4},{name:team,type:mindustry.game.Team,size:-1},{name:type,type:mindustry.type.UnitType,size:-1},{name:x,type:float,size:4},{name:y,type:float,size:4}]}
|
@ -0,0 +1 @@
|
||||
{fields:[{name:drownTime,type:float,size:4},{name:elevation,type:float,size:4},{name:health,type:float,size:4},{name:mineTile,type:mindustry.world.Tile,size:-1},{name:rotation,type:float,size:4},{name:team,type:mindustry.game.Team,size:-1},{name:type,type:mindustry.type.UnitType,size:-1},{name:x,type:float,size:4},{name:y,type:float,size:4}]}
|
@ -0,0 +1 @@
|
||||
{fields:[{name:drownTime,type:float,size:4},{name:elevation,type:float,size:4},{name:health,type:float,size:4},{name:rotation,type:float,size:4},{name:team,type:mindustry.game.Team,size:-1},{name:type,type:mindustry.type.UnitType,size:-1},{name:x,type:float,size:4},{name:y,type:float,size:4}]}
|
@ -7,12 +7,14 @@ import mindustry.type.*;
|
||||
|
||||
public class UnitTypes implements ContentList{
|
||||
public static UnitType
|
||||
draug, spirit, phantom,
|
||||
wraith, ghoul, revenant, lich, reaper,
|
||||
crawler, titan, fortress, eruptor, chaosArray, eradicator;
|
||||
|
||||
public static @EntityDef({Unitc.class, Legsc.class}) UnitType dagger;
|
||||
public static @EntityDef({Unitc.class, WaterMovec.class}) UnitType vanguard;
|
||||
public static @EntityDef({Unitc.class, Minerc.class}) UnitType draug;
|
||||
public static @EntityDef({Unitc.class}) UnitType spirit;
|
||||
public static @EntityDef({Unitc.class, Builderc.class}) UnitType phantom;
|
||||
|
||||
public static UnitType alpha, delta, tau, omega, dart, javelin, trident, glaive;
|
||||
public static UnitType starter;
|
||||
@ -52,63 +54,51 @@ public class UnitTypes implements ContentList{
|
||||
}});
|
||||
}};
|
||||
|
||||
/*
|
||||
draug = new UnitDef("draug", MinerDrone::new){{
|
||||
draug = new UnitType("draug"){{
|
||||
flying = true;
|
||||
drag = 0.01f;
|
||||
speed = 0.3f;
|
||||
maxVelocity = 1.2f;
|
||||
drag = 0.05f;
|
||||
speed = 1.5f;
|
||||
range = 50f;
|
||||
health = 80;
|
||||
minePower = 0.9f;
|
||||
mineSpeed = 0.9f;
|
||||
engineSize = 1.8f;
|
||||
engineOffset = 5.7f;
|
||||
drillTier = 1;
|
||||
}};
|
||||
|
||||
spirit = new UnitDef("spirit", RepairDrone::new){{
|
||||
spirit = new UnitType("spirit"){{
|
||||
flying = true;
|
||||
drag = 0.01f;
|
||||
speed = 0.42f;
|
||||
maxVelocity = 1.6f;
|
||||
drag = 0.05f;
|
||||
speed = 1.5f;
|
||||
range = 50f;
|
||||
health = 100;
|
||||
engineSize = 1.8f;
|
||||
engineOffset = 5.7f;
|
||||
weapon = new Weapon(){{
|
||||
length = 1.5f;
|
||||
weapons.add(new Weapon(){{
|
||||
y = 1.5f;
|
||||
reload = 40f;
|
||||
width = 0.5f;
|
||||
x = 0.5f;
|
||||
alternate = true;
|
||||
ejectEffect = Fx.none;
|
||||
recoil = 2f;
|
||||
bullet = Bullets.healBulletBig;
|
||||
shootSound = Sounds.pew;
|
||||
}};
|
||||
}});
|
||||
}};
|
||||
|
||||
phantom = new UnitDef("phantom", BuilderDrone::new){{
|
||||
phantom = new UnitType("phantom"){{
|
||||
flying = true;
|
||||
drag = 0.01f;
|
||||
drag = 0.05f;
|
||||
mass = 2f;
|
||||
speed = 0.45f;
|
||||
maxVelocity = 1.9f;
|
||||
speed = 1.5f;
|
||||
range = 70f;
|
||||
itemCapacity = 70;
|
||||
health = 400;
|
||||
buildPower = 0.4f;
|
||||
buildSpeed = 0.4f;
|
||||
engineOffset = 6.5f;
|
||||
toMine = ObjectSet.with(Items.lead, Items.copper, Items.titanium);
|
||||
weapon = new Weapon(){{
|
||||
length = 1.5f;
|
||||
reload = 20f;
|
||||
width = 0.5f;
|
||||
alternate = true;
|
||||
ejectEffect = Fx.none;
|
||||
recoil = 2f;
|
||||
bullet = Bullets.healBullet;
|
||||
}};
|
||||
}};
|
||||
|
||||
/*
|
||||
dagger = new UnitDef("dagger", GroundUnit::new){{
|
||||
maxVelocity = 1.1f;
|
||||
speed = 0.2f;
|
||||
@ -421,7 +411,7 @@ public class UnitTypes implements ContentList{
|
||||
{
|
||||
flying = true;
|
||||
drillTier = 1;
|
||||
minePower = 4f;
|
||||
mineSpeed = 4f;
|
||||
speed = 0.49f;
|
||||
drag = 0.09f;
|
||||
health = 200f;
|
||||
@ -430,7 +420,7 @@ public class UnitTypes implements ContentList{
|
||||
weaponOffsetY = -1;
|
||||
engineColor = Pal.lightTrail;
|
||||
cellTrnsY = 1f;
|
||||
buildPower = 1.2f;
|
||||
buildSpeed = 1.2f;
|
||||
weapon = new Weapon("vanguard-blaster"){{
|
||||
length = 1.5f;
|
||||
reload = 30f;
|
||||
@ -479,7 +469,7 @@ public class UnitTypes implements ContentList{
|
||||
itemCapacity = 15;
|
||||
mass = 0.9f;
|
||||
health = 150f;
|
||||
buildPower = 0.9f;
|
||||
buildSpeed = 0.9f;
|
||||
weaponOffsetX = 1;
|
||||
weaponOffsetY = -1;
|
||||
engineColor = Pal.heal;
|
||||
@ -519,7 +509,7 @@ public class UnitTypes implements ContentList{
|
||||
speed = 0.5f;
|
||||
itemCapacity = 40;
|
||||
boostSpeed = 0.95f;
|
||||
buildPower = 1.2f;
|
||||
buildSpeed = 1.2f;
|
||||
engineColor = Color.valueOf("ffd37f");
|
||||
health = 250f;
|
||||
weaponOffsetX = 4f;
|
||||
@ -559,7 +549,7 @@ public class UnitTypes implements ContentList{
|
||||
boostSpeed = 0.8f;
|
||||
canHeal = true;
|
||||
health = 200f;
|
||||
buildPower = 1.6f;
|
||||
buildSpeed = 1.6f;
|
||||
engineColor = Pal.heal;
|
||||
|
||||
weapon = new Weapon("heal-blaster"){{
|
||||
@ -609,7 +599,7 @@ public class UnitTypes implements ContentList{
|
||||
weaponOffsetY = 0;
|
||||
engineColor = Color.valueOf("feb380");
|
||||
health = 350f;
|
||||
buildPower = 1.5f;
|
||||
buildSpeed = 1.5f;
|
||||
weapon = new Weapon("swarmer"){{
|
||||
length = 1.5f;
|
||||
recoil = 4f;
|
||||
@ -682,7 +672,7 @@ public class UnitTypes implements ContentList{
|
||||
weaponOffsetY = -1;
|
||||
engineColor = Pal.lightTrail;
|
||||
cellTrnsY = 1f;
|
||||
buildPower = 1.1f;
|
||||
buildSpeed = 1.1f;
|
||||
weapon = new Weapon("blaster"){{
|
||||
length = 1.5f;
|
||||
reload = 15f;
|
||||
@ -789,7 +779,7 @@ public class UnitTypes implements ContentList{
|
||||
itemCapacity = 30;
|
||||
engineColor = Color.valueOf("84f491");
|
||||
cellTrnsY = 1f;
|
||||
buildPower = 2.5f;
|
||||
buildSpeed = 2.5f;
|
||||
weapon = new Weapon("bomber"){{
|
||||
length = 0f;
|
||||
width = 2f;
|
||||
@ -831,7 +821,7 @@ public class UnitTypes implements ContentList{
|
||||
itemCapacity = 60;
|
||||
engineColor = Color.valueOf("feb380");
|
||||
cellTrnsY = 1f;
|
||||
buildPower = 1.2f;
|
||||
buildSpeed = 1.2f;
|
||||
|
||||
weapon = new Weapon("bomber"){{
|
||||
length = 1.5f;
|
||||
|
@ -11,6 +11,7 @@ import arc.util.serialization.*;
|
||||
import mindustry.*;
|
||||
import mindustry.annotations.Annotations.*;
|
||||
import mindustry.core.GameState.*;
|
||||
import mindustry.entities.units.*;
|
||||
import mindustry.game.EventType.*;
|
||||
import mindustry.game.*;
|
||||
import mindustry.gen.*;
|
||||
@ -528,23 +529,28 @@ public class NetClient implements ApplicationListener{
|
||||
}
|
||||
|
||||
void sync(){
|
||||
//TODO implement
|
||||
/*
|
||||
if(timer.get(0, playerSyncTime)){
|
||||
BuildRequest[] requests;
|
||||
//limit to 10 to prevent buffer overflows
|
||||
int usedRequests = Math.min(player.builder().requests().size, 10);
|
||||
BuildRequest[] requests = null;
|
||||
if(player.isBuilder() && control.input.isBuilding){
|
||||
//limit to 10 to prevent buffer overflows
|
||||
int usedRequests = Math.min(player.builder().requests().size, 10);
|
||||
|
||||
requests = new BuildRequest[usedRequests];
|
||||
for(int i = 0; i < usedRequests; i++){
|
||||
requests[i] = player.builder().requests().get(i);
|
||||
requests = new BuildRequest[usedRequests];
|
||||
for(int i = 0; i < usedRequests; i++){
|
||||
requests[i] = player.builder().requests().get(i);
|
||||
}
|
||||
}
|
||||
|
||||
Call.onClientShapshot(lastSent++, player.x, player.y,
|
||||
player.pointerX, player.pointerY, player.rotation, player.baseRotation,
|
||||
player.vel().x, player.vel().y,
|
||||
Unitc unit = player.dead() ? Nulls.unit : player.unit();
|
||||
|
||||
Call.onClientShapshot(lastSent++,
|
||||
unit.x(), unit.y(),
|
||||
player.mouseX(), player.mouseY(),
|
||||
unit.rotation(),
|
||||
unit instanceof Legsc ? ((Legsc)unit).baseRotation() : 0,
|
||||
unit.vel().x, unit.vel().y,
|
||||
player.miner().mineTile(),
|
||||
player.isBoosting, player.isShooting, ui.chatfrag.shown(), player.isBuilding,
|
||||
/*player.isBoosting*/false, control.input.isShooting, ui.chatfrag.shown(),
|
||||
requests,
|
||||
Core.camera.position.x, Core.camera.position.y,
|
||||
Core.camera.width * viewScale, Core.camera.height * viewScale);
|
||||
@ -552,7 +558,7 @@ public class NetClient implements ApplicationListener{
|
||||
|
||||
if(timer.get(1, 60)){
|
||||
Call.onPing(Time.millis());
|
||||
}*/
|
||||
}
|
||||
}
|
||||
|
||||
String getUsid(String ip){
|
||||
|
@ -10,6 +10,7 @@ import arc.util.CommandHandler.*;
|
||||
import arc.util.io.*;
|
||||
import arc.util.serialization.*;
|
||||
import mindustry.annotations.Annotations.*;
|
||||
import mindustry.content.*;
|
||||
import mindustry.core.GameState.*;
|
||||
import mindustry.entities.units.*;
|
||||
import mindustry.game.EventType.*;
|
||||
@ -501,8 +502,6 @@ public class NetServer implements ApplicationListener{
|
||||
BuildRequest[] requests,
|
||||
float viewX, float viewY, float viewWidth, float viewHeight
|
||||
){
|
||||
//TODO this entire thing needs to be rewritten.
|
||||
/*
|
||||
NetConnection connection = player.con();
|
||||
if(connection == null || snapshotID < connection.lastRecievedClientSnapshot) return;
|
||||
|
||||
@ -515,78 +514,90 @@ public class NetServer implements ApplicationListener{
|
||||
connection.viewWidth = viewWidth;
|
||||
connection.viewHeight = viewHeight;
|
||||
|
||||
long elapsed = Time.timeSinceMillis(connection.lastRecievedClientTime);
|
||||
|
||||
float maxSpeed = boosting && !player.mech.flying ? player.mech.compoundSpeedBoost : player.mech.compoundSpeed;
|
||||
float maxMove = elapsed / 1000f * 60f * Math.min(maxSpeed, player.mech.maxSpeed) * 1.2f;
|
||||
|
||||
player.mouseX(pointerX);
|
||||
player.mouseY(pointerY);
|
||||
player.miner().mineTile(mining);
|
||||
player.isTyping = chatting;
|
||||
player.isBoosting = boosting;
|
||||
player.isShooting = shooting;
|
||||
player.isBuilding = building;
|
||||
player.builder().requests().clear();
|
||||
player.typing(chatting);
|
||||
|
||||
for(BuildRequest req : requests){
|
||||
if(req == null) continue;
|
||||
Tile tile = world.tile(req.x, req.y);
|
||||
if(tile == null || (!req.breaking && req.block == null)) continue;
|
||||
//auto-skip done requests
|
||||
if(req.breaking && tile.block() == Blocks.air){
|
||||
continue;
|
||||
}else if(!req.breaking && tile.block() == req.block && (!req.block.rotate || tile.rotation() == req.rotation)){
|
||||
continue;
|
||||
}else if(connection.rejectedRequests.contains(r -> r.breaking == req.breaking && r.x == req.x && r.y == req.y)){ //check if request was recently rejected, and skip it if so
|
||||
continue;
|
||||
}else if(!netServer.admins.allowAction(player, req.breaking ? ActionType.breakBlock : ActionType.placeBlock, tile, action -> { //make sure request is allowed by the server
|
||||
action.block = req.block;
|
||||
action.rotation = req.rotation;
|
||||
action.config = req.config;
|
||||
})){
|
||||
//force the player to remove this request if that's not the case
|
||||
Call.removeQueueBlock(player.con(), req.x, req.y, req.breaking);
|
||||
connection.rejectedRequests.add(req);
|
||||
continue;
|
||||
player.unit().controlWeapons(shooting, shooting);
|
||||
player.unit().aim(pointerX, pointerY);
|
||||
|
||||
if(player.isBuilder()){
|
||||
player.builder().clearBuilding();
|
||||
}
|
||||
|
||||
if(player.isMiner()){
|
||||
player.miner().mineTile(mining);
|
||||
}
|
||||
|
||||
if(requests != null){
|
||||
for(BuildRequest req : requests){
|
||||
if(req == null) continue;
|
||||
Tile tile = world.tile(req.x, req.y);
|
||||
if(tile == null || (!req.breaking && req.block == null)) continue;
|
||||
//auto-skip done requests
|
||||
if(req.breaking && tile.block() == Blocks.air){
|
||||
continue;
|
||||
}else if(!req.breaking && tile.block() == req.block && (!req.block.rotate || tile.rotation() == req.rotation)){
|
||||
continue;
|
||||
}else if(connection.rejectedRequests.contains(r -> r.breaking == req.breaking && r.x == req.x && r.y == req.y)){ //check if request was recently rejected, and skip it if so
|
||||
continue;
|
||||
}else if(!netServer.admins.allowAction(player, req.breaking ? ActionType.breakBlock : ActionType.placeBlock, tile, action -> { //make sure request is allowed by the server
|
||||
action.block = req.block;
|
||||
action.rotation = req.rotation;
|
||||
action.config = req.config;
|
||||
})){
|
||||
//force the player to remove this request if that's not the case
|
||||
Call.removeQueueBlock(player.con(), req.x, req.y, req.breaking);
|
||||
connection.rejectedRequests.add(req);
|
||||
continue;
|
||||
}
|
||||
player.builder().requests().addLast(req);
|
||||
}
|
||||
player.builder().requests().addLast(req);
|
||||
}
|
||||
|
||||
connection.rejectedRequests.clear();
|
||||
|
||||
vector.set(x - player.getInterpolator().target.x, y - player.getInterpolator().target.y);
|
||||
vector.limit(maxMove);
|
||||
if(!player.dead()){
|
||||
Unitc unit = player.unit();
|
||||
long elapsed = Time.timeSinceMillis(connection.lastRecievedClientTime);
|
||||
float maxSpeed = player.dead() ? Float.MAX_VALUE : player.unit().type().speed;
|
||||
float maxMove = elapsed / 1000f * 60f * maxSpeed * 1.1f;
|
||||
|
||||
float prevx = player.x, prevy = player.y;
|
||||
player.set(player.getInterpolator().target.x, player.getInterpolator().target.y);
|
||||
if(!player.mech.flying && player.boostHeat < 0.01f){
|
||||
player.move(vector.x, vector.y);
|
||||
vector.set(x - unit.interpolator().target.x, y - unit.interpolator().target.y);
|
||||
vector.limit(maxMove);
|
||||
|
||||
float prevx = unit.x(), prevy = unit.y();
|
||||
unit.set(unit.interpolator().target.x, unit.interpolator().target.y);
|
||||
if(!unit.isFlying()){
|
||||
unit.move(vector.x, vector.y);
|
||||
}else{
|
||||
unit.trns(vector.x, vector.y);
|
||||
}
|
||||
float newx = unit.x(), newy = unit.y();
|
||||
|
||||
if(!verifyPosition){
|
||||
unit.x(prevx);
|
||||
unit.y(prevy);
|
||||
newx = x;
|
||||
newy = y;
|
||||
}else if(Mathf.dst(x, y, newx, newy) > correctDist){
|
||||
Call.onPositionSet(player.con(), newx, newy); //teleport and correct position when necessary
|
||||
}
|
||||
|
||||
//reset player to previous synced position so it gets interpolated
|
||||
unit.x(prevx);
|
||||
unit.y(prevy);
|
||||
|
||||
//set interpolator target to *new* position so it moves toward it
|
||||
unit.interpolator().read(unit.x(), unit.y(), newx, newy, rotation, baseRotation);
|
||||
unit.vel().set(xVelocity, yVelocity); //only for visual calculation purposes, doesn't actually update the player
|
||||
}else{
|
||||
player.x += vector.x;
|
||||
player.y += vector.y;
|
||||
player.x(x);
|
||||
player.y(y);
|
||||
}
|
||||
float newx = player.x, newy = player.y;
|
||||
|
||||
if(!verifyPosition){
|
||||
player.x = prevx;
|
||||
player.y = prevy;
|
||||
newx = x;
|
||||
newy = y;
|
||||
}else if(Mathf.dst(x, y, newx, newy) > correctDist){
|
||||
Call.onPositionSet(player.con(), newx, newy); //teleport and correct position when necessary
|
||||
}
|
||||
|
||||
//reset player to previous synced position so it gets interpolated
|
||||
player.x = prevx;
|
||||
player.y = prevy;
|
||||
|
||||
//set interpolator target to *new* position so it moves toward it
|
||||
player.getInterpolator().read(player.x, player.y, newx, newy, rotation, baseRotation);
|
||||
player.vel().set(xVelocity, yVelocity); //only for visual calculation purposes, doesn't actually update the player
|
||||
|
||||
connection.lastRecievedClientSnapshot = snapshotID;
|
||||
connection.lastRecievedClientTime = Time.millis();*/
|
||||
connection.lastRecievedClientTime = Time.millis();
|
||||
}
|
||||
|
||||
@Remote(targets = Loc.client, called = Loc.server)
|
||||
|
@ -10,7 +10,7 @@ class AllDefs{
|
||||
|
||||
}
|
||||
|
||||
@GroupDef(Playerc.class)
|
||||
@GroupDef(value = Playerc.class, mapping = true)
|
||||
class player{
|
||||
|
||||
}
|
||||
@ -20,7 +20,7 @@ class AllDefs{
|
||||
|
||||
}
|
||||
|
||||
@GroupDef(value = Unitc.class, spatial = true, collide = {unit.class})
|
||||
@GroupDef(value = Unitc.class, spatial = true, collide = {unit.class}, mapping = true)
|
||||
class unit{
|
||||
|
||||
}
|
||||
@ -30,7 +30,7 @@ class AllDefs{
|
||||
|
||||
}
|
||||
|
||||
@GroupDef(Syncc.class)
|
||||
@GroupDef(value = Syncc.class, mapping = true)
|
||||
class sync{
|
||||
|
||||
}
|
||||
|
@ -23,7 +23,7 @@ import java.util.*;
|
||||
import static mindustry.Vars.*;
|
||||
|
||||
@Component
|
||||
abstract class BuilderComp implements Unitc{
|
||||
abstract class BuilderComp implements Unitc, DrawLayerFlyingc{
|
||||
static final Vec2[] tmptr = new Vec2[]{new Vec2(), new Vec2(), new Vec2(), new Vec2()};
|
||||
|
||||
@Import float x, y, rotation;
|
||||
@ -32,7 +32,8 @@ abstract class BuilderComp implements Unitc{
|
||||
transient float buildSpeed = 1f;
|
||||
//boolean building;
|
||||
|
||||
void updateBuilding(){
|
||||
@Override
|
||||
public void update(){
|
||||
float finalPlaceDst = state.rules.infiniteResources ? Float.MAX_VALUE : buildingRange;
|
||||
|
||||
Iterator<BuildRequest> it = requests.iterator();
|
||||
@ -189,7 +190,8 @@ abstract class BuilderComp implements Unitc{
|
||||
return requests.size == 0 ? null : requests.first();
|
||||
}
|
||||
|
||||
void drawOver(){
|
||||
@Override
|
||||
public void drawFlying(){
|
||||
if(!isBuilding()) return;
|
||||
BuildRequest request = buildRequest();
|
||||
Tile tile = world.tile(request.x, request.y);
|
||||
@ -211,7 +213,7 @@ abstract class BuilderComp implements Unitc{
|
||||
tmptr[2].set(tile.drawx() - sz, tile.drawy() + sz);
|
||||
tmptr[3].set(tile.drawx() + sz, tile.drawy() + sz);
|
||||
|
||||
Arrays.sort(tmptr, Structs.comparingFloat(vec -> Angles.angleDist(angleTo(vec), ang)));
|
||||
Arrays.sort(tmptr, Structs.comparingFloat(vec -> -Angles.angleDist(angleTo(vec), ang)));
|
||||
|
||||
float x1 = tmptr[0].x, y1 = tmptr[0].y,
|
||||
x3 = tmptr[1].x, y3 = tmptr[1].y;
|
||||
|
@ -33,7 +33,8 @@ abstract class MinerComp implements Itemsc, Posc, Teamc, Rotc{
|
||||
return mineTile != null;
|
||||
}
|
||||
|
||||
void updateMining(){
|
||||
@Override
|
||||
public void update(){
|
||||
Tilec core = closestCore();
|
||||
|
||||
if(core != null && mineTile != null && mineTile.drop() != null && !acceptsItem(mineTile.drop()) && dst(core) < mineTransferRange){
|
||||
@ -47,6 +48,7 @@ abstract class MinerComp implements Itemsc, Posc, Teamc, Rotc{
|
||||
}
|
||||
|
||||
if(mineTile == null || core == null || mineTile.block() != Blocks.air || dst(mineTile.worldx(), mineTile.worldy()) > miningRange
|
||||
|| (((Object)this) instanceof Builderc && ((Builderc)(Object)this).isBuilding())
|
||||
|| mineTile.drop() == null || !acceptsItem(mineTile.drop()) || !canMine(mineTile.drop())){
|
||||
mineTile = null;
|
||||
mineTimer = 0f;
|
||||
|
@ -20,7 +20,7 @@ import static mindustry.Vars.*;
|
||||
@Component
|
||||
abstract class UnitComp implements Healthc, Velc, Statusc, Teamc, Itemsc, Hitboxc, Rotc, Massc, Unitc, Weaponsc, Drawc, Boundedc,
|
||||
DrawLayerGroundc, DrawLayerFlyingc, DrawLayerGroundShadowsc, DrawLayerFlyingShadowsc, Syncc{
|
||||
@Import float x, y, rotation;
|
||||
@Import float x, y, rotation, elevation;
|
||||
|
||||
private UnitController controller;
|
||||
private UnitType type;
|
||||
@ -83,6 +83,8 @@ abstract class UnitComp implements Healthc, Velc, Statusc, Teamc, Itemsc, Hitbox
|
||||
hitSize(type.hitsize);
|
||||
controller(type.createController());
|
||||
setupWeapons(type);
|
||||
|
||||
elevation = type.flying ? 1f : 0f;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -186,4 +188,22 @@ abstract class UnitComp implements Healthc, Velc, Statusc, Teamc, Itemsc, Hitbox
|
||||
Events.fire(Trigger.suicideBomb);
|
||||
}
|
||||
}
|
||||
|
||||
//TODO this is bad
|
||||
|
||||
public boolean isPlayer(){
|
||||
return controller instanceof Playerc;
|
||||
}
|
||||
|
||||
public boolean canMine(Item item){
|
||||
return type.drillTier >= item.hardness;
|
||||
}
|
||||
|
||||
public float miningSpeed(){
|
||||
return type.mineSpeed;
|
||||
}
|
||||
|
||||
public boolean offloadImmediately(){
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
@ -1,7 +1,6 @@
|
||||
package mindustry.entities.units;
|
||||
|
||||
import arc.math.*;
|
||||
import arc.util.*;
|
||||
import mindustry.gen.*;
|
||||
|
||||
public class AIController implements UnitController{
|
||||
@ -21,11 +20,12 @@ public class AIController implements UnitController{
|
||||
|
||||
@Override
|
||||
public void update(){
|
||||
rot += Mathf.range(3f) * Time.delta();
|
||||
//TODO implement
|
||||
//rot += Mathf.range(3f) * Time.delta();
|
||||
|
||||
unit.moveAt(Tmp.v1.trns(rot, unit.type().speed));
|
||||
if(!unit.vel().isZero()){
|
||||
unit.lookAt(unit.vel().angle());
|
||||
}
|
||||
//unit.moveAt(Tmp.v1.trns(rot, unit.type().speed));
|
||||
//if(!unit.vel().isZero()){
|
||||
// unit.lookAt(unit.vel().angle());
|
||||
//}
|
||||
}
|
||||
}
|
||||
|
@ -3,8 +3,8 @@ package mindustry.game;
|
||||
import arc.util.ArcAnnotate.*;
|
||||
import mindustry.core.GameState.*;
|
||||
import mindustry.ctype.*;
|
||||
import mindustry.gen.*;
|
||||
import mindustry.entities.units.*;
|
||||
import mindustry.gen.*;
|
||||
import mindustry.type.*;
|
||||
import mindustry.world.*;
|
||||
|
||||
@ -264,14 +264,13 @@ public class EventType{
|
||||
public static class BlockBuildEndEvent{
|
||||
public final Tile tile;
|
||||
public final Team team;
|
||||
public final @Nullable
|
||||
Playerc player;
|
||||
public final @Nullable Unitc unit;
|
||||
public final boolean breaking;
|
||||
|
||||
public BlockBuildEndEvent(Tile tile, @Nullable Playerc player, Team team, boolean breaking){
|
||||
public BlockBuildEndEvent(Tile tile, @Nullable Unitc unit, Team team, boolean breaking){
|
||||
this.tile = tile;
|
||||
this.team = team;
|
||||
this.player = player;
|
||||
this.unit = unit;
|
||||
this.breaking = breaking;
|
||||
}
|
||||
}
|
||||
|
@ -35,7 +35,7 @@ public class UnitType extends UnlockableContent{
|
||||
|
||||
public int itemCapacity = 30;
|
||||
public int drillTier = -1;
|
||||
public float buildPower = 1f, minePower = 1f;
|
||||
public float buildSpeed = 1f, mineSpeed = 1f;
|
||||
|
||||
public Color engineColor = Pal.boostTo;
|
||||
public float engineOffset = 5f, engineSize = 2.5f;
|
||||
@ -46,6 +46,8 @@ public class UnitType extends UnlockableContent{
|
||||
public Color lightColor = Pal.powerLight;
|
||||
public boolean drawCell = true, drawItems = true;
|
||||
|
||||
//public ObjectSet<Item> mineables = new ObjectSet<>();
|
||||
|
||||
public ObjectSet<StatusEffect> immunities = new ObjectSet<>();
|
||||
public Sound deathSound = Sounds.bang;
|
||||
|
||||
|
@ -11,6 +11,7 @@ import arc.util.io.*;
|
||||
import mindustry.annotations.Annotations.*;
|
||||
import mindustry.content.*;
|
||||
import mindustry.entities.*;
|
||||
import mindustry.entities.units.*;
|
||||
import mindustry.game.EventType.*;
|
||||
import mindustry.game.*;
|
||||
import mindustry.gen.*;
|
||||
@ -20,8 +21,6 @@ import mindustry.ui.*;
|
||||
import mindustry.world.*;
|
||||
import mindustry.world.modules.*;
|
||||
|
||||
import java.io.*;
|
||||
|
||||
import static mindustry.Vars.*;
|
||||
|
||||
public class BuildBlock extends Block{
|
||||
@ -55,7 +54,7 @@ public class BuildBlock extends Block{
|
||||
public static void onDeconstructFinish(Tile tile, Block block, int builderID){
|
||||
Team team = tile.team();
|
||||
Fx.breakBlock.at(tile.drawx(), tile.drawy(), block.size);
|
||||
Events.fire(new BlockBuildEndEvent(tile, Groups.player.getByID(builderID), team, true));
|
||||
Events.fire(new BlockBuildEndEvent(tile, Groups.unit.getByID(builderID), team, true));
|
||||
tile.remove();
|
||||
if(shouldPlay()) Sounds.breaks.at(tile, calcPitch(false));
|
||||
}
|
||||
@ -105,7 +104,7 @@ public class BuildBlock extends Block{
|
||||
Call.onConstructFinish(tile, block, builderID, rotation, team, skipConfig);
|
||||
tile.block().placed(tile);
|
||||
|
||||
Events.fire(new BlockBuildEndEvent(tile, Groups.player.getByID(builderID), team, false));
|
||||
Events.fire(new BlockBuildEndEvent(tile, Groups.unit.getByID(builderID), team, false));
|
||||
if(shouldPlay()) Sounds.place.at(tile, calcPitch(true));
|
||||
}
|
||||
|
||||
@ -141,16 +140,13 @@ public class BuildBlock extends Block{
|
||||
public void tapped(Tile tile, Playerc player){
|
||||
BuildEntity entity = tile.ent();
|
||||
|
||||
//TODO building
|
||||
/*
|
||||
//if the target is constructible, begin constructing
|
||||
if(entity.cblock != null){
|
||||
if(player.buildWasAutoPaused && !player.isBuilding){
|
||||
player.isBuilding = true;
|
||||
if(!headless && entity.cblock != null){
|
||||
if(control.input.buildWasAutoPaused && !control.input.isBuilding && player.isBuilder()){
|
||||
control.input.isBuilding = true;
|
||||
}
|
||||
//player.clearBuilding();
|
||||
player.builder().addBuild(new BuildRequest(tile.x, tile.y, tile.rotation(), entity.cblock), false);
|
||||
}*/
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -281,9 +277,7 @@ public class BuildBlock extends Block{
|
||||
|
||||
progress = Mathf.clamp(progress - amount);
|
||||
|
||||
if(builder instanceof Playerc){
|
||||
builderID = builder.id();
|
||||
}
|
||||
builderID = builder.id();
|
||||
|
||||
if(progress <= 0 || state.rules.infiniteResources){
|
||||
Call.onDeconstructFinish(tile, this.cblock == null ? previous : this.cblock, builderID);
|
||||
|
@ -105,7 +105,7 @@ public class SStats implements SteamUserStatsCallback{
|
||||
});
|
||||
|
||||
Events.on(BlockBuildEndEvent.class, e -> {
|
||||
if(campaign() && e.player == player && !e.breaking){
|
||||
if(campaign() && e.unit != null && e.unit.isLocal() && !e.breaking){
|
||||
SStat.blocksBuilt.add();
|
||||
|
||||
if(e.tile.block() == Blocks.router && e.tile.entity.proximity().contains(t -> t.block() == Blocks.router)){
|
||||
|
@ -8,9 +8,9 @@ import mindustry.content.*;
|
||||
import mindustry.core.*;
|
||||
import mindustry.core.GameState.*;
|
||||
import mindustry.ctype.*;
|
||||
import mindustry.entities.type.base.*;
|
||||
import mindustry.entities.units.*;
|
||||
import mindustry.game.*;
|
||||
import mindustry.gen.*;
|
||||
import mindustry.io.*;
|
||||
import mindustry.maps.*;
|
||||
import mindustry.net.Net;
|
||||
@ -103,8 +103,8 @@ public class ApplicationTests{
|
||||
Time.update();
|
||||
Time.update();
|
||||
Time.setDeltaProvider(() -> 1f);
|
||||
unitGroup.update();
|
||||
assertFalse(unitGroup.isEmpty(), "No enemies spawned.");
|
||||
Groups.unit.update();
|
||||
assertFalse(Groups.unit.isEmpty(), "No enemies spawned.");
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -335,18 +335,18 @@ public class ApplicationTests{
|
||||
void buildingOverlap(){
|
||||
initBuilding();
|
||||
|
||||
BuilderDrone d1 = (BuilderDrone)UnitTypes.phantom.create(Team.sharded);
|
||||
BuilderDrone d2 = (BuilderDrone)UnitTypes.phantom.create(Team.sharded);
|
||||
Builderc d1 = (Builderc)UnitTypes.phantom.create(Team.sharded);
|
||||
Builderc d2 = (Builderc)UnitTypes.phantom.create(Team.sharded);
|
||||
|
||||
d1.set(10f, 20f);
|
||||
d2.set(10f, 20f);
|
||||
|
||||
d1.addBuildRequest(new BuildRequest(0, 0, 0, Blocks.copperWallLarge));
|
||||
d2.addBuildRequest(new BuildRequest(1, 1, 0, Blocks.copperWallLarge));
|
||||
d1.addBuild(new BuildRequest(0, 0, 0, Blocks.copperWallLarge));
|
||||
d2.addBuild(new BuildRequest(1, 1, 0, Blocks.copperWallLarge));
|
||||
|
||||
Time.setDeltaProvider(() -> 9999999f);
|
||||
d1.updateBuilding();
|
||||
d2.updateBuilding();
|
||||
d1.update();
|
||||
d2.update();
|
||||
|
||||
assertEquals(Blocks.copperWallLarge, world.tile(0, 0).block());
|
||||
assertEquals(Blocks.air, world.tile(2, 2).block());
|
||||
@ -357,26 +357,26 @@ public class ApplicationTests{
|
||||
void buildingDestruction(){
|
||||
initBuilding();
|
||||
|
||||
BuilderDrone d1 = (BuilderDrone)UnitTypes.phantom.create(Team.sharded);
|
||||
BuilderDrone d2 = (BuilderDrone)UnitTypes.phantom.create(Team.sharded);
|
||||
Builderc d1 = (Builderc)UnitTypes.phantom.create(Team.sharded);
|
||||
Builderc d2 = (Builderc)UnitTypes.phantom.create(Team.sharded);
|
||||
|
||||
d1.set(10f, 20f);
|
||||
d2.set(10f, 20f);
|
||||
|
||||
d1.addBuildRequest(new BuildRequest(0, 0, 0, Blocks.copperWallLarge));
|
||||
d2.addBuildRequest(new BuildRequest(1, 1));
|
||||
d1.addBuild(new BuildRequest(0, 0, 0, Blocks.copperWallLarge));
|
||||
d2.addBuild(new BuildRequest(1, 1));
|
||||
|
||||
Time.setDeltaProvider(() -> 3f);
|
||||
d1.updateBuilding();
|
||||
d1.update();
|
||||
Time.setDeltaProvider(() -> 1f);
|
||||
d2.updateBuilding();
|
||||
d2.update();
|
||||
|
||||
assertEquals(content.getByName(ContentType.block, "build2"), world.tile(0, 0).block());
|
||||
|
||||
Time.setDeltaProvider(() -> 9999f);
|
||||
|
||||
d1.updateBuilding();
|
||||
d2.updateBuilding();
|
||||
d1.update();
|
||||
d2.update();
|
||||
|
||||
assertEquals(Blocks.air, world.tile(0, 0).block());
|
||||
assertEquals(Blocks.air, world.tile(2, 2).block());
|
||||
@ -414,8 +414,8 @@ public class ApplicationTests{
|
||||
}catch(Throwable t){
|
||||
fail("Failed to update block '" + tile.block() + "'.", t);
|
||||
}
|
||||
assertEquals(tile.block(), tile.entity.block);
|
||||
assertEquals(tile.block().health, tile.entity.health);
|
||||
assertEquals(tile.block(), tile.entity.block());
|
||||
assertEquals(tile.block().health, tile.entity.health());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,12 +1,9 @@
|
||||
import arc.util.*;
|
||||
import arc.util.io.*;
|
||||
import mindustry.content.*;
|
||||
import mindustry.game.*;
|
||||
import mindustry.gen.*;
|
||||
import mindustry.io.*;
|
||||
import org.junit.jupiter.api.*;
|
||||
|
||||
import java.io.*;
|
||||
import java.nio.*;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
@ -50,9 +47,9 @@ public class IOTests{
|
||||
rules.attackMode = true;
|
||||
rules.buildSpeedMultiplier = 99f;
|
||||
|
||||
TypeIO.writeRules(buffer, rules);
|
||||
TypeIO.writeRules(new Writes(new ByteBufferOutput(buffer)), rules);
|
||||
buffer.position(0);
|
||||
Rules res = TypeIO.readRules(buffer);
|
||||
Rules res = TypeIO.readRules(new Reads(new ByteBufferInput(buffer)));
|
||||
|
||||
assertEquals(rules.buildSpeedMultiplier, res.buildSpeedMultiplier);
|
||||
assertEquals(rules.attackMode, res.attackMode);
|
||||
|
@ -37,8 +37,8 @@ public class DirectConsumerTests extends PowerTestFixture{
|
||||
consumes.power(requestedPower);
|
||||
consumes.items(new ItemStack(Items.silicon, 30), new ItemStack(Items.lead, 30));
|
||||
}});
|
||||
consumertile.entity.items().add(Items.silicon, siliconAmount);
|
||||
consumertile.entity.items().add(Items.lead, leadAmount);
|
||||
consumerTile.entity.items().add(Items.silicon, siliconAmount);
|
||||
consumerTile.entity.items().add(Items.lead, leadAmount);
|
||||
|
||||
Tile producerTile = createFakeTile(2, 0, createFakeProducerBlock(producedPower));
|
||||
producerTile.<PowerGenerator.GeneratorEntity>ent().productionEfficiency = 1f;
|
||||
@ -50,6 +50,6 @@ public class DirectConsumerTests extends PowerTestFixture{
|
||||
consumerTile.entity.update();
|
||||
graph.update();
|
||||
|
||||
assertEquals(expectedSatisfaction, consumertile.entity.power().status);
|
||||
assertEquals(expectedSatisfaction, consumerTile.entity.power().status);
|
||||
}
|
||||
}
|
||||
|
@ -1,6 +1,7 @@
|
||||
package power;
|
||||
|
||||
import arc.*;
|
||||
import arc.mock.*;
|
||||
import arc.util.*;
|
||||
import mindustry.*;
|
||||
import mindustry.content.*;
|
||||
@ -14,7 +15,7 @@ import org.junit.jupiter.api.*;
|
||||
|
||||
import java.lang.reflect.*;
|
||||
|
||||
import static mindustry.Vars.content;
|
||||
import static mindustry.Vars.*;
|
||||
|
||||
/**
|
||||
* This class provides objects commonly used by power related unit tests.
|
||||
@ -26,8 +27,11 @@ public class PowerTestFixture{
|
||||
|
||||
@BeforeAll
|
||||
static void initializeDependencies(){
|
||||
headless = true;
|
||||
Core.graphics = new FakeGraphics();
|
||||
Core.files = new MockFiles();
|
||||
Vars.state = new GameState();
|
||||
Vars.tree = new FileTree();
|
||||
Vars.content = new ContentLoader(){
|
||||
@Override
|
||||
public void handleMappableContent(MappableContent content){
|
||||
@ -87,11 +91,11 @@ public class PowerTestFixture{
|
||||
|
||||
// Simulate the "changed" method. Calling it through reflections would require half the game to be initialized.
|
||||
tile.entity = block.newEntity().init(tile, false);
|
||||
tile.entity.cons() = new ConsumeModule(tile.entity);
|
||||
if(block.hasItems) tile.entity.items() = new ItemModule();
|
||||
if(block.hasLiquids) tile.entity.liquids() = new LiquidModule();
|
||||
tile.entity.cons(new ConsumeModule(tile.entity));
|
||||
if(block.hasItems) tile.entity.items(new ItemModule());
|
||||
if(block.hasLiquids) tile.entity.liquids(new LiquidModule());
|
||||
if(block.hasPower){
|
||||
tile.entity.power() = new PowerModule();
|
||||
tile.entity.power(new PowerModule());
|
||||
tile.entity.power().graph = new PowerGraph(){
|
||||
//assume there's always something consuming power
|
||||
@Override
|
||||
@ -104,7 +108,7 @@ public class PowerTestFixture{
|
||||
|
||||
// Assign incredibly high health so the block does not get destroyed on e.g. burning Blast Compound
|
||||
block.health = 100000;
|
||||
tile.entity.health = 100000.0f;
|
||||
tile.entity.health(100000.0f);
|
||||
|
||||
return tile;
|
||||
}catch(Exception ex){
|
||||
|
@ -66,7 +66,7 @@ public class PowerTests extends PowerTestFixture{
|
||||
|
||||
// Update and check for the expected power status of the consumer
|
||||
powerGraph.update();
|
||||
assertEquals(expectedSatisfaction, directConsumertile.entity.power().status, Mathf.FLOAT_ROUNDING_ERROR, parameterDescription + ": Satisfaction of direct consumer did not match");
|
||||
assertEquals(expectedSatisfaction, directConsumerTile.entity.power().status, Mathf.FLOAT_ROUNDING_ERROR, parameterDescription + ": Satisfaction of direct consumer did not match");
|
||||
}
|
||||
|
||||
/**
|
||||
@ -104,14 +104,14 @@ public class PowerTests extends PowerTestFixture{
|
||||
}
|
||||
float maxCapacity = 100f;
|
||||
Tile batteryTile = createFakeTile(0, 2, createFakeBattery(maxCapacity));
|
||||
batterytile.entity.power().status = initialBatteryCapacity / maxCapacity;
|
||||
batteryTile.entity.power().status = initialBatteryCapacity / maxCapacity;
|
||||
|
||||
powerGraph.add(batteryTile);
|
||||
|
||||
powerGraph.update();
|
||||
assertEquals(expectedBatteryCapacity / maxCapacity, batterytile.entity.power().status, Mathf.FLOAT_ROUNDING_ERROR, parameterDescription + ": Expected battery status did not match");
|
||||
assertEquals(expectedBatteryCapacity / maxCapacity, batteryTile.entity.power().status, Mathf.FLOAT_ROUNDING_ERROR, parameterDescription + ": Expected battery status did not match");
|
||||
if(directConsumerTile != null){
|
||||
assertEquals(expectedSatisfaction, directConsumertile.entity.power().status, Mathf.FLOAT_ROUNDING_ERROR, parameterDescription + ": Satisfaction of direct consumer did not match");
|
||||
assertEquals(expectedSatisfaction, directConsumerTile.entity.power().status, Mathf.FLOAT_ROUNDING_ERROR, parameterDescription + ": Satisfaction of direct consumer did not match");
|
||||
}
|
||||
}
|
||||
|
||||
@ -127,13 +127,13 @@ public class PowerTests extends PowerTestFixture{
|
||||
powerGraph.add(consumerTile);
|
||||
powerGraph.update();
|
||||
|
||||
assertEquals(1.0f, consumertile.entity.power().status, Mathf.FLOAT_ROUNDING_ERROR);
|
||||
assertEquals(1.0f, consumerTile.entity.power().status, Mathf.FLOAT_ROUNDING_ERROR);
|
||||
|
||||
powerGraph.remove(producerTile);
|
||||
powerGraph.add(consumerTile);
|
||||
powerGraph.update();
|
||||
|
||||
assertEquals(0.0f, consumertile.entity.power().status, Mathf.FLOAT_ROUNDING_ERROR);
|
||||
assertEquals(0.0f, consumerTile.entity.power().status, Mathf.FLOAT_ROUNDING_ERROR);
|
||||
if(consumerTile.block().consumes.hasPower()){
|
||||
ConsumePower consumePower = consumerTile.block().consumes.getPower();
|
||||
assertFalse(consumePower.valid(consumerTile.ent()));
|
||||
|
Loading…
Reference in New Issue
Block a user