Better targeting range calculation
This commit is contained in:
@@ -1563,6 +1563,7 @@ lenum.len = Length of vector.
|
|||||||
lenum.sin = Sine, in degrees.
|
lenum.sin = Sine, in degrees.
|
||||||
lenum.cos = Cosine, in degrees.
|
lenum.cos = Cosine, in degrees.
|
||||||
lenum.tan = Tangent, in degrees.
|
lenum.tan = Tangent, in degrees.
|
||||||
|
#not a typo, look up 'range notation'
|
||||||
lenum.rand = Random number in range [0, value).
|
lenum.rand = Random number in range [0, value).
|
||||||
lenum.log = Natural logarithm (ln).
|
lenum.log = Natural logarithm (ln).
|
||||||
lenum.log10 = Base 10 logarithm.
|
lenum.log10 = Base 10 logarithm.
|
||||||
|
|||||||
Binary file not shown.
@@ -269,7 +269,6 @@ public class BlockIndexer{
|
|||||||
public Building findTile(Team team, float x, float y, float range, Boolf<Building> pred, boolean usePriority){
|
public Building findTile(Team team, float x, float y, float range, Boolf<Building> pred, boolean usePriority){
|
||||||
Building closest = null;
|
Building closest = null;
|
||||||
float dst = 0;
|
float dst = 0;
|
||||||
float range2 = range * range;
|
|
||||||
|
|
||||||
for(int rx = Math.max((int)((x - range) / tilesize / quadrantSize), 0); rx <= (int)((x + range) / tilesize / quadrantSize) && rx < quadWidth(); rx++){
|
for(int rx = Math.max((int)((x - range) / tilesize / quadrantSize), 0); rx <= (int)((x + range) / tilesize / quadrantSize) && rx < quadWidth(); rx++){
|
||||||
for(int ry = Math.max((int)((y - range) / tilesize / quadrantSize), 0); ry <= (int)((y + range) / tilesize / quadrantSize) && ry < quadHeight(); ry++){
|
for(int ry = Math.max((int)((y - range) / tilesize / quadrantSize), 0); ry <= (int)((y + range) / tilesize / quadrantSize) && ry < quadHeight(); ry++){
|
||||||
@@ -282,13 +281,13 @@ public class BlockIndexer{
|
|||||||
|
|
||||||
if(e == null || e.team != team || !pred.get(e) || !e.block.targetable || e.team == Team.derelict) continue;
|
if(e == null || e.team != team || !pred.get(e) || !e.block.targetable || e.team == Team.derelict) continue;
|
||||||
|
|
||||||
float ndst = e.dst2(x, y);
|
float bdst = e.dst(x, y) - e.hitSize() / 2f;
|
||||||
if(ndst < range2 && (closest == null ||
|
if(bdst < range && (closest == null ||
|
||||||
//this one is closer, and it is at least of equal priority
|
//this one is closer, and it is at least of equal priority
|
||||||
(ndst < dst && (!usePriority || closest.block.priority.ordinal() <= e.block.priority.ordinal())) ||
|
(bdst < dst && (!usePriority || closest.block.priority.ordinal() <= e.block.priority.ordinal())) ||
|
||||||
//priority is used, and new block has higher priority regardless of range
|
//priority is used, and new block has higher priority regardless of range
|
||||||
(usePriority && closest.block.priority.ordinal() < e.block.priority.ordinal()))){
|
(usePriority && closest.block.priority.ordinal() < e.block.priority.ordinal()))){
|
||||||
dst = ndst;
|
dst = bdst;
|
||||||
closest = e;
|
closest = e;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2047,6 +2047,7 @@ public class Blocks implements ContentList{
|
|||||||
hasPower = true;
|
hasPower = true;
|
||||||
consumes.power(10f);
|
consumes.power(10f);
|
||||||
buildCostMultiplier = 0.5f;
|
buildCostMultiplier = 0.5f;
|
||||||
|
health = size * size * 80;
|
||||||
}};
|
}};
|
||||||
|
|
||||||
//endregion campaign
|
//endregion campaign
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ import arc.math.geom.*;
|
|||||||
import arc.struct.*;
|
import arc.struct.*;
|
||||||
import mindustry.annotations.Annotations.*;
|
import mindustry.annotations.Annotations.*;
|
||||||
import mindustry.content.*;
|
import mindustry.content.*;
|
||||||
|
import mindustry.entities.comp.*;
|
||||||
import mindustry.game.*;
|
import mindustry.game.*;
|
||||||
import mindustry.game.Teams.*;
|
import mindustry.game.Teams.*;
|
||||||
import mindustry.gen.*;
|
import mindustry.gen.*;
|
||||||
@@ -93,7 +94,7 @@ public class Units{
|
|||||||
* @return whether the target is invalid
|
* @return whether the target is invalid
|
||||||
*/
|
*/
|
||||||
public static boolean invalidateTarget(Posc target, Team team, float x, float y, float range){
|
public static boolean invalidateTarget(Posc target, Team team, float x, float y, float range){
|
||||||
return target == null || (range != Float.MAX_VALUE && !target.within(x, y, range)) || (target instanceof Teamc && ((Teamc)target).team() == team) || (target instanceof Healthc && !((Healthc)target).isValid());
|
return target == null || (range != Float.MAX_VALUE && !target.within(x, y, range + (target instanceof Sized hb ? hb.hitSize()/2f : 0f))) || (target instanceof Teamc t && t.team() == team) || (target instanceof Healthc h && !h.isValid());
|
||||||
}
|
}
|
||||||
|
|
||||||
/** See {@link #invalidateTarget(Posc, Team, float, float, float)} */
|
/** See {@link #invalidateTarget(Posc, Team, float, float, float)} */
|
||||||
@@ -217,7 +218,7 @@ public class Units{
|
|||||||
cdist = 0f;
|
cdist = 0f;
|
||||||
|
|
||||||
nearbyEnemies(team, x - range, y - range, range*2f, range*2f, e -> {
|
nearbyEnemies(team, x - range, y - range, range*2f, range*2f, e -> {
|
||||||
if(e.dead() || !predicate.get(e) || !e.within(x, y, range)) return;
|
if(e.dead() || !predicate.get(e) || !e.within(x, y, range + e.hitSize/2f)) return;
|
||||||
|
|
||||||
float cost = sort.cost(e, x, y);
|
float cost = sort.cost(e, x, y);
|
||||||
if(result == null || cost < cdist){
|
if(result == null || cost < cdist){
|
||||||
@@ -292,7 +293,7 @@ public class Units{
|
|||||||
/** Iterates over all units in a circle around this position. */
|
/** Iterates over all units in a circle around this position. */
|
||||||
public static void nearby(Team team, float x, float y, float radius, Cons<Unit> cons){
|
public static void nearby(Team team, float x, float y, float radius, Cons<Unit> cons){
|
||||||
nearby(team, x - radius, y - radius, radius*2f, radius*2f, unit -> {
|
nearby(team, x - radius, y - radius, radius*2f, radius*2f, unit -> {
|
||||||
if(unit.within(x, y, radius)){
|
if(unit.within(x, y, radius + unit.hitSize/2f)){
|
||||||
cons.get(unit);
|
cons.get(unit);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -43,7 +43,7 @@ import static mindustry.Vars.*;
|
|||||||
|
|
||||||
@EntityDef(value = {Buildingc.class}, isFinal = false, genio = false, serialize = false)
|
@EntityDef(value = {Buildingc.class}, isFinal = false, genio = false, serialize = false)
|
||||||
@Component(base = true)
|
@Component(base = true)
|
||||||
abstract class BuildingComp implements Posc, Teamc, Healthc, Buildingc, Timerc, QuadTreeObject, Displayable, Senseable, Controllable{
|
abstract class BuildingComp implements Posc, Teamc, Healthc, Buildingc, Timerc, QuadTreeObject, Displayable, Senseable, Controllable, Sized{
|
||||||
//region vars and initialization
|
//region vars and initialization
|
||||||
static final float timeToSleep = 60f * 1, timeToUncontrol = 60f * 6;
|
static final float timeToSleep = 60f * 1, timeToUncontrol = 60f * 6;
|
||||||
static final ObjectSet<Building> tmpTiles = new ObjectSet<>();
|
static final ObjectSet<Building> tmpTiles = new ObjectSet<>();
|
||||||
@@ -1277,6 +1277,11 @@ abstract class BuildingComp implements Posc, Teamc, Healthc, Buildingc, Timerc,
|
|||||||
return tile.build == self() && !dead();
|
return tile.build == self() && !dead();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public float hitSize(){
|
||||||
|
return tile.block().size * tilesize;
|
||||||
|
}
|
||||||
|
|
||||||
@Replace
|
@Replace
|
||||||
@Override
|
@Override
|
||||||
public void kill(){
|
public void kill(){
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ import mindustry.annotations.Annotations.*;
|
|||||||
import mindustry.gen.*;
|
import mindustry.gen.*;
|
||||||
|
|
||||||
@Component
|
@Component
|
||||||
abstract class HitboxComp implements Posc, QuadTreeObject{
|
abstract class HitboxComp implements Posc, Sized, QuadTreeObject{
|
||||||
@Import float x, y;
|
@Import float x, y;
|
||||||
|
|
||||||
transient float lastX, lastY, deltaX, deltaY, hitSize;
|
transient float lastX, lastY, deltaX, deltaY, hitSize;
|
||||||
@@ -28,6 +28,11 @@ abstract class HitboxComp implements Posc, QuadTreeObject{
|
|||||||
updateLastPosition();
|
updateLastPosition();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public float hitSize(){
|
||||||
|
return hitSize;
|
||||||
|
}
|
||||||
|
|
||||||
void getCollisions(Cons<QuadTree> consumer){
|
void getCollisions(Cons<QuadTree> consumer){
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
5
core/src/mindustry/entities/comp/Sized.java
Normal file
5
core/src/mindustry/entities/comp/Sized.java
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
package mindustry.entities.comp;
|
||||||
|
|
||||||
|
public interface Sized{
|
||||||
|
float hitSize();
|
||||||
|
}
|
||||||
@@ -1,3 +1,3 @@
|
|||||||
org.gradle.daemon=true
|
org.gradle.daemon=true
|
||||||
org.gradle.jvmargs=-Xms256m -Xmx1024m
|
org.gradle.jvmargs=-Xms256m -Xmx1024m
|
||||||
archash=8b6d59e004463585b333c8cda9ea91dd66f3bcee
|
archash=5b04a94d53e279e3af3a2654978fff5ab16e7cb8
|
||||||
|
|||||||
@@ -2,7 +2,6 @@
|
|||||||
<executableName>${app.executable}</executableName>
|
<executableName>${app.executable}</executableName>
|
||||||
<mainClass>${app.mainclass}</mainClass>
|
<mainClass>${app.mainclass}</mainClass>
|
||||||
<os>ios</os>
|
<os>ios</os>
|
||||||
<arch>thumbv7</arch>
|
|
||||||
<target>ios</target>
|
<target>ios</target>
|
||||||
<iosInfoPList>Info.plist.xml</iosInfoPList>
|
<iosInfoPList>Info.plist.xml</iosInfoPList>
|
||||||
<resources>
|
<resources>
|
||||||
|
|||||||
Reference in New Issue
Block a user