Partial 7.0 merge - API preview
This commit is contained in:
@@ -23,8 +23,6 @@ public class AIController implements UnitController{
|
||||
|
||||
/** main target that is being faced */
|
||||
protected Teamc target;
|
||||
/** targets for each weapon */
|
||||
protected Teamc[] targets = {};
|
||||
|
||||
{
|
||||
timer.reset(0, Mathf.random(40f));
|
||||
@@ -94,8 +92,6 @@ public class AIController implements UnitController{
|
||||
}
|
||||
|
||||
protected void updateWeapons(){
|
||||
if(targets.length != unit.mounts.length) targets = new Teamc[unit.mounts.length];
|
||||
|
||||
float rotation = unit.rotation - 90;
|
||||
boolean ret = retarget();
|
||||
|
||||
@@ -109,39 +105,39 @@ public class AIController implements UnitController{
|
||||
|
||||
unit.isShooting = false;
|
||||
|
||||
for(int i = 0; i < targets.length; i++){
|
||||
WeaponMount mount = unit.mounts[i];
|
||||
for(var mount : unit.mounts){
|
||||
Weapon weapon = mount.weapon;
|
||||
|
||||
//let uncontrollable weapons do their own thing
|
||||
if(!weapon.controllable) continue;
|
||||
|
||||
float mountX = unit.x + Angles.trnsx(rotation, weapon.x, weapon.y),
|
||||
mountY = unit.y + Angles.trnsy(rotation, weapon.x, weapon.y);
|
||||
|
||||
if(unit.type.singleTarget){
|
||||
targets[i] = target;
|
||||
mount.target = target;
|
||||
}else{
|
||||
if(ret){
|
||||
targets[i] = findTarget(mountX, mountY, weapon.bullet.range(), weapon.bullet.collidesAir, weapon.bullet.collidesGround);
|
||||
mount.target = findTarget(mountX, mountY, weapon.bullet.range(), weapon.bullet.collidesAir, weapon.bullet.collidesGround);
|
||||
}
|
||||
|
||||
if(checkTarget(targets[i], mountX, mountY, weapon.bullet.range())){
|
||||
targets[i] = null;
|
||||
if(checkTarget(mount.target, mountX, mountY, weapon.bullet.range())){
|
||||
mount.target = null;
|
||||
}
|
||||
}
|
||||
|
||||
boolean shoot = false;
|
||||
|
||||
if(targets[i] != null){
|
||||
shoot = targets[i].within(mountX, mountY, weapon.bullet.range()) && shouldShoot();
|
||||
if(mount.target != null){
|
||||
shoot = mount.target.within(mountX, mountY, weapon.bullet.range() + (mount.target instanceof Sized s ? s.hitSize()/2f : 0f)) && shouldShoot();
|
||||
|
||||
Vec2 to = Predict.intercept(unit, targets[i], weapon.bullet.speed);
|
||||
Vec2 to = Predict.intercept(unit, mount.target, weapon.bullet.speed);
|
||||
mount.aimX = to.x;
|
||||
mount.aimY = to.y;
|
||||
}
|
||||
|
||||
mount.shoot = shoot;
|
||||
mount.rotate = shoot;
|
||||
unit.isShooting |= (mount.shoot = mount.rotate = shoot);
|
||||
|
||||
unit.isShooting |= shoot;
|
||||
if(shoot){
|
||||
unit.aimX = mount.aimX;
|
||||
unit.aimY = mount.aimY;
|
||||
|
||||
Reference in New Issue
Block a user