Merge branch 'master' of https://github.com/Anuken/Mindustry into new-pathfinding

This commit is contained in:
Anuken
2024-04-15 13:08:48 -04:00
235 changed files with 10974 additions and 3792 deletions

View File

@@ -86,9 +86,9 @@ abstract class BuilderComp implements Posc, Statusc, Teamc, Rotc{
buildAlpha = Mathf.lerpDelta(buildAlpha, activelyBuilding() ? 1f : 0f, 0.15f);
}
//validate regardless of whether building is enabled.
validatePlans();
if(!updateBuilding || !canBuild()){
validatePlans();
return;
}
@@ -99,19 +99,18 @@ abstract class BuilderComp implements Posc, Statusc, Teamc, Rotc{
if(Float.isNaN(buildCounter) || Float.isInfinite(buildCounter)) buildCounter = 0f;
buildCounter = Math.min(buildCounter, 10f);
boolean instant = state.rules.instantBuild && state.rules.infiniteResources;
//random attempt to fix a freeze that only occurs on Android
int maxPerFrame = 10, count = 0;
int maxPerFrame = instant ? plans.size : 10, count = 0;
while(buildCounter >= 1 && count++ < maxPerFrame){
var core = core();
if((core == null && !infinite)) return;
while((buildCounter >= 1 || instant) && count++ < maxPerFrame && plans.size > 0){
buildCounter -= 1f;
validatePlans();
var core = core();
//nothing to build.
if(buildPlan() == null) return;
//find the next build plan
if(plans.size > 1){
int total = 0;
@@ -163,7 +162,7 @@ abstract class BuilderComp implements Posc, Statusc, Teamc, Rotc{
}
//if there is no core to build with or no build entity, stop building!
if((core == null && !infinite) || !(tile.build instanceof ConstructBuild entity)){
if(!(tile.build instanceof ConstructBuild entity)){
continue;
}

View File

@@ -1310,7 +1310,7 @@ abstract class BuildingComp implements Posc, Teamc, Healthc, Buildingc, Timerc,
if(value instanceof UnitType) type = UnitType.class;
if(builder != null && builder.isPlayer()){
lastAccessed = builder.getPlayer().coloredName();
updateLastAccess(builder.getPlayer());
}
if(block.configurations.containsKey(type)){
@@ -1324,6 +1324,10 @@ abstract class BuildingComp implements Posc, Teamc, Healthc, Buildingc, Timerc,
}
}
public void updateLastAccess(Player player){
lastAccessed = player.coloredName();
}
/** Called when the block is tapped by the local player. */
public void tapped(){
@@ -1344,6 +1348,15 @@ abstract class BuildingComp implements Posc, Teamc, Healthc, Buildingc, Timerc,
return block.itemCapacity;
}
/** Called when a block begins (not finishes!) deconstruction. The building is still present at this point. */
public void onDeconstructed(@Nullable Unit builder){
//deposit non-incinerable liquid on ground
if(liquids != null && liquids.currentAmount() > 0 && (!liquids.current().incinerable || block.deconstructDropAllLiquid)){
float perCell = liquids.currentAmount() / (block.size * block.size) * 2f;
tile.getLinkedTiles(other -> Puddles.deposit(other, liquids.current(), perCell));
}
}
/** Called when the block is destroyed. The tile is still intact at this stage. */
public void onDestroyed(){
float explosiveness = block.baseExplosiveness;

View File

@@ -45,6 +45,7 @@ abstract class BulletComp implements Timedc, Damagec, Hitboxc, Teamc, Posc, Draw
transient @Nullable Mover mover;
transient boolean absorbed, hit;
transient @Nullable Trail trail;
transient int frags;
@Override
public void getCollisions(Cons<QuadTree> consumer){

View File

@@ -4,6 +4,7 @@ import arc.math.*;
import arc.util.*;
import mindustry.annotations.Annotations.*;
import mindustry.gen.*;
import mindustry.world.blocks.*;
@Component
abstract class ChildComp implements Posc, Rotc{
@@ -18,9 +19,14 @@ abstract class ChildComp implements Posc, Rotc{
if(parent != null){
offsetX = x - parent.getX();
offsetY = y - parent.getY();
if(rotWithParent && parent instanceof Rotc r){
offsetPos = -r.rotation();
offsetRot = rotation - r.rotation();
if(rotWithParent){
if(parent instanceof Rotc r){
offsetPos = -r.rotation();
offsetRot = rotation - r.rotation();
}else if(parent instanceof RotBlock rot){
offsetPos = -rot.buildRotation();
offsetRot = rotation - rot.buildRotation();
}
}
}
}
@@ -28,10 +34,16 @@ abstract class ChildComp implements Posc, Rotc{
@Override
public void update(){
if(parent != null){
if(rotWithParent && parent instanceof Rotc r){
x = parent.getX() + Angles.trnsx(r.rotation() + offsetPos, offsetX, offsetY);
y = parent.getY() + Angles.trnsy(r.rotation() + offsetPos, offsetX, offsetY);
rotation = r.rotation() + offsetRot;
if(rotWithParent){
if(parent instanceof Rotc r){
x = parent.getX() + Angles.trnsx(r.rotation() + offsetPos, offsetX, offsetY);
y = parent.getY() + Angles.trnsy(r.rotation() + offsetPos, offsetX, offsetY);
rotation = r.rotation() + offsetRot;
}else if(parent instanceof RotBlock rot){
x = parent.getX() + Angles.trnsx(rot.buildRotation() + offsetPos, offsetX, offsetY);
y = parent.getY() + Angles.trnsy(rot.buildRotation() + offsetPos, offsetX, offsetY);
rotation = rot.buildRotation() + offsetRot;
}
}else{
x = parent.getX() + offsetX;
y = parent.getY() + offsetY;

View File

@@ -66,4 +66,9 @@ abstract class EntityComp{
void afterRead(){
}
/** Called after *all* entities are read. */
void afterAllRead(){
}
}

View File

@@ -60,6 +60,11 @@ abstract class PayloadComp implements Posc, Rotc, Hitboxc, Unitc{
}
}
@Override
public void destroy(){
if(Vars.state.rules.unitPayloadsExplode) payloads.each(Payload::destroyed);
}
float payloadUsed(){
return payloads.sumf(p -> p.size() * p.size());
}

View File

@@ -183,6 +183,9 @@ abstract class PlayerComp implements UnitController, Entityc, Syncc, Timerc, Dra
if(!unit.isNull()){
clearUnit();
}
lastReadUnit = Nulls.unit;
justSwitchTo = justSwitchFrom = null;
}
public void team(Team team){

View File

@@ -59,6 +59,7 @@ abstract class PuddleComp implements Posc, Puddlec, Drawc, Syncc{
amount -= Time.delta * (1f - liquid.viscosity) / (5f + addSpeed);
amount += accepting;
amount = Math.min(amount, maxLiquid);
accepting = 0f;
if(amount >= maxLiquid / 1.5f){

View File

@@ -127,10 +127,10 @@ abstract class StatusComp implements Posc, Flyingc{
return entry;
}
/** Uses a dynamic status effect to override speed. */
/** Uses a dynamic status effect to override speed (in tiles/second). */
public void statusSpeed(float speed){
//type.speed should never be 0
applyDynamicStatus().speedMultiplier = speed / type.speed;
applyDynamicStatus().speedMultiplier = speed / (type.speed * 60f / tilesize);
}
/** Uses a dynamic status effect to change damage. */

View File

@@ -92,7 +92,7 @@ abstract class UnitComp implements Healthc, Physicsc, Hitboxc, Statusc, Teamc, I
moveAt(Tmp.v2.trns(rotation, vec.len()));
if(!vec.isZero()){
rotation = Angles.moveToward(rotation, vec.angle(), type.rotateSpeed * Time.delta);
rotation = Angles.moveToward(rotation, vec.angle(), type.rotateSpeed * Time.delta * speedMultiplier);
}
}
@@ -110,7 +110,6 @@ abstract class UnitComp implements Healthc, Physicsc, Hitboxc, Statusc, Teamc, I
return !type.flying && world.tiles.in(tileX, tileY) && type.pathCost.getCost(team.id, pathfinder.get(tileX, tileY)) == -1;
}
/** @return approx. square size of the physical hitbox for physics */
public float physicSize(){
return hitSize * 0.7f;
@@ -490,6 +489,11 @@ abstract class UnitComp implements Healthc, Physicsc, Hitboxc, Statusc, Teamc, I
}
}
@Override
public void afterAllRead(){
controller.afterRead(self());
}
@Override
public void add(){
team.data().updateCount(type, 1);
@@ -730,7 +734,7 @@ abstract class UnitComp implements Healthc, Physicsc, Hitboxc, Statusc, Teamc, I
/** @return name of direct or indirect player controller. */
@Override
public @Nullable String getControllerName(){
if(isPlayer()) return getPlayer().name;
if(isPlayer()) return getPlayer().coloredName();
if(controller instanceof LogicAI ai && ai.controller != null) return ai.controller.lastAccessed;
return null;
}