Ammo system redesign
This commit is contained in:
@@ -22,6 +22,7 @@ public class Units{
|
||||
private static float cdist;
|
||||
private static boolean boolResult;
|
||||
private static int intResult;
|
||||
private static Building buildResult;
|
||||
|
||||
@Remote(called = Loc.server)
|
||||
public static void unitCapDeath(Unit unit){
|
||||
@@ -157,6 +158,26 @@ public class Units{
|
||||
return indexer.findEnemyTile(team, x, y, range, pred);
|
||||
}
|
||||
|
||||
/** @return the closest building of the provided team that matches the predicate. */
|
||||
public static @Nullable Building closestBuilding(Team team, float wx, float wy, float range, Boolf<Building> pred){
|
||||
buildResult = null;
|
||||
cdist = 0f;
|
||||
|
||||
var buildings = team.data().buildings;
|
||||
if(buildings == null) return null;
|
||||
buildings.intersect(wx - range, wy - range, range*2f, range*2f, b -> {
|
||||
if(pred.get(b)){
|
||||
float dst = b.dst(wx, wy) - b.hitSize()/2f;
|
||||
if(dst <= range && (buildResult == null || dst <= cdist)){
|
||||
cdist = dst;
|
||||
buildResult = b;
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
return buildResult;
|
||||
}
|
||||
|
||||
/** Iterates through all buildings in a range. */
|
||||
public static void nearbyBuildings(float x, float y, float range, Cons<Building> cons){
|
||||
indexer.allBuildings(x, y, range, cons);
|
||||
|
||||
@@ -1,28 +0,0 @@
|
||||
package mindustry.entities.comp;
|
||||
|
||||
import arc.util.*;
|
||||
import mindustry.annotations.Annotations.*;
|
||||
import mindustry.game.*;
|
||||
import mindustry.gen.*;
|
||||
import mindustry.type.*;
|
||||
import mindustry.world.blocks.units.*;
|
||||
|
||||
@Component
|
||||
abstract class AmmoDistributeComp implements Unitc{
|
||||
@Import float x, y;
|
||||
@Import UnitType type;
|
||||
@Import Team team;
|
||||
@Import float ammo;
|
||||
|
||||
private transient float ammoCooldown;
|
||||
|
||||
@Override
|
||||
public void update(){
|
||||
if(ammoCooldown > 0f) ammoCooldown -= Time.delta;
|
||||
|
||||
if(ammo > 0 && ammoCooldown <= 0f && ResupplyPoint.resupply(team, x, y, type.ammoResupplyRange, Math.min(type.ammoResupplyAmount, ammo), type.ammoType.color, u -> u != self())){
|
||||
ammo -= Math.min(type.ammoResupplyAmount, ammo);
|
||||
ammoCooldown = 5f;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user