Special Aircraft Service

Please login or register.

Login with username, password and session length
Advanced search  
Pages: [1]   Go Down

Author Topic: Create counter Attack  (Read 219 times)

0 Members and 1 Guest are viewing this topic.

Ghostil

  • member
  • Offline Offline
  • Posts: 22
Create counter Attack
« on: January 28, 2025, 11:17:02 PM »

1) In Maneuver.java i create variable protected int gattackCounterMods = 0; Default my counter = 0.
2 I add  in my void attack.
Code: [Select]
[color=blue]public void  groundattackDirectionWest(Actor actor, float f) {
if (submaneuver == 0 && sub_Man_Count == 0 && CT.Weapons[1] != null) {
    float f_131_ = ((GunGeneric) CT.Weapons[1][0]).bulletSpeed();
    if (f_131_ > 0.01F)
bullTime = 1.0F / (f_131_ + getSpeed());
}
maxAOA = 15.0F;
minElevCoeff = 20.0F;
switch (submaneuver) {
case 0: {
    setCheckGround(true);
    setSpeedMode(4);
    smConstSpeed = 100.0F;
    P.set(actor.pos.getAbsPoint());
    P.y -= 5000.0;
    P.z += 350.0;
    Vector1.set(P);
    TurnToDirection(Vector1);
    Ve.normalize();
    double d = Loc.distance(P);
    if (d < 300.0)
submaneuver = 1;
    if (Alt < 30.0F) {
push(0);
push(8);
pop();
    }
    break;
}
case 1: {
    setCheckGround(true);
    setSpeedMode(4);
    smConstSpeed = 100.0F;
    if (StartGAttack == true)
    gattackCounterMods++;
  Voice.speakEndGattack((Aircraft) this.actor);
    P.set(actor.pos.getAbsPoint());
    P.y -= 5000.0;
    P.x -= 5000.0;
    P.z += 350.0;
    Vector1.set(P);
    TurnToDirection(Vector1);
    Ve.normalize();
    double d = Loc.distance(P);
    if (d < 300.0)
submaneuver = 2;
    if (Alt < 30.0F) {
push(0);
push(8);
pop();
    }
    break;
}
case 2: {
    setCheckGround(true);
    setSpeedMode(4);
    smConstSpeed = 100.0F;
    Voice.speakLeaderStayFormation((Aircraft) this.actor);
    P.set(actor.pos.getAbsPoint());
    P.x -= 5000.0;
    P.z += 350.0;
    Vector1.set(P);
    TurnToDirection(Vector1);
    Ve.normalize();
    double d = Loc.distance(P);
    if (d < 300.0)
submaneuver = 3;
    if (Alt < 30.0F) {
push(0);
push(8);
pop();
    }
    break;
}
case 3: {
    setCheckGround(true);
    setSpeedMode(4);
    smConstSpeed = 100.0F;
    P.set(actor.pos.getAbsPoint());
    P.x -= 5000.0;
    P.y += 5000.0;
    P.z += 350.0;
    Vector1.set(P);
    TurnToDirection(Vector1);
    Ve.normalize();
    double d = Loc.distance(P);
    if (d < 300.0)
submaneuver = 4;
    if (Alt < 30.0F) {
push(0);
push(8);
pop();
    }
    break;
}
case 4: {
    setCheckGround(true);
    setSpeedMode(4);
    smConstSpeed = 100.0F;
    P.set(actor.pos.getAbsPoint());
    P.y += 5000.0;
    P.z += 350.0;
    Vector1.set(P);
    TurnToDirection(Vector1);
    Ve.normalize();
    double d = Loc.distance(P);
    if (d < 300.0)
submaneuver = 5;
    if (Alt < 30.0F) {
push(0);
push(8);
pop();
    }
    break;
}
case 5: {
    setCheckGround(true);
    setSpeedMode(4);
    smConstSpeed = 100.0F;
    P.set(actor.pos.getAbsPoint());
    P.y += 2500.0;
    P.z += 350.0;
    Vector1.set(P);
    TurnToDirection(Vector1);
    Ve.normalize();
    double d = Loc.distance(P);
    if (d < 300.0)
submaneuver = 6;
    if (Alt < 30.0F) {
push(0);
push(8);
pop();
    }
    break;
}
case 6: {
    if (rocketsDelay > 0)
rocketsDelay--;
    if (sub_Man_Count > 100)
setCheckGround(false);
    P.set(actor.pos.getAbsPoint());
    P.z = 4.0;
    Engine.land();
    if (Alt < 45.0F && Landscape.rayHitHQ(Loc, P, P)) {
push(0);
push(38);
pop();
gattackCounter--;
if (gattackCounter < 0)
    gattackCounter = 0;

    }
    P.set(actor.pos.getAbsPoint());
    Ve.sub(P, Loc);
    float f_132_ = (float) Ve.length();
    setRSDgrd(shootingDeviation, f_132_ * bullTime);
    actor.getSpeed(tmpV3d);
    tmpV3f.x = (double) (float) tmpV3d.x;
    tmpV3f.y = (double) (float) tmpV3d.y;
    tmpV3f.z = (double) (float) tmpV3d.z;
    tmpV3f.sub(Vwld);
    tmpV3f.scale((double) (f_132_ * bullTime * 0.3333F
   * (float) Skill));
    Ve.add(tmpV3f);
    float f_133_ = 0.3F * (f_132_ - 1000.0F);
    if (f_133_ < 0.0F)
f_133_ = 0.0F;
    if (f_133_ > 300.0F)
f_133_ = 300.0F;
    f_133_ += f_132_ * getAOA() * 0.005F;
    Ve.z += (double) (f_133_ + Group.getAaaNum() * 0.5F);
    Or.transformInv(Ve);
    if (f_132_ < 800.0F && (shotAtFriend <= 0 || distToFriend > f_132_)) {
shootingDeviation -= f;
if (shootingDeviation < (float) (6 - gunnery))
    shootingDeviation = (float) (6 - gunnery);
if (Math.abs(Ve.y) < 15.0 && Math.abs(Ve.z) < 10.0) {
    if (f_132_ < 500.0F && Group.getAaaNum() > 10.0F || f_132_ < 650.0F)
CT.WeaponControl[0] = true;
    if (f_132_ < 400.0F && Group.getAaaNum() > 10.0F || f_132_ < 550.0F)
CT.WeaponControl[1] = true;
    StartGAttack = true;
    if (CT.Weapons[2] != null && CT.Weapons[2][0] != null && CT.Weapons[2][CT.Weapons[2].length - 1].countBullets() != 0 && rocketsDelay < 1 && f_132_ < 570.0F) {
CT.WeaponControl[2] = true;
Voice.speakAttackByRockets((Aircraft) this.actor);
if (Group.getAaaNum() > 2.0F)
    rocketsDelay += 30.0F - Group.getAaaNum();
else
    rocketsDelay += 30;
    }
}
    }
    if (f_132_ < 200.0F) {
Voice.speakEndGattack((Aircraft) this.actor);
submaneuver = 0;
    }
    Ve.normalize();
    attackTurnToDirection(f_132_, f, 10.0F + (float) Skill * 2.0F);
    setSpeedMode(4);
    smConstSpeed = 100.0F;
    break;
}
}
    }  [/color]


Upon fulfillment of 3 conditions, the meter is increased by 1.
Since this is in the attack cycle and the code works every time in a circle, I think so when executing case 1 each time the counter must be added.

3) In AirGroup.
Code: [Select]
case 4: {

if (w.curr().waypointType == 0) {
if (w.curr().getTarget() != null) {
if (grTask == 21) {
boolean cangattack = false;
boolean cangattackall = somebodyGAttacks();
for (int i = 0; i < nOfAirc; i++) {
    Maneuver maneuver_102_ = (Maneuver) airc[i].FM;
    if (maneuver_102_.gattackCounterMods >=  w.curr().gattackcounter)
    cangattack = true;        
}

if(!cangattackall && cangattack == true){
gTargDestroyed = true;
switchWayPoint();
airc[0].FM.AP.way.next();
   w.next();
       Voice.speakMissionAccomplished(airc[0]);
       setGroupTask(1);
        for (int i = 1; i < nOfAirc; i++) {
Maneuver maneuver_103_ = (Maneuver) airc[i].FM;
maneuver_103_.push(57);
maneuver_103_.pop();
    }
       }
       if (cangattack) {
for (int i = 0; i < nOfAirc; i++)
    ((Maneuver) airc[i].FM).gattackCounterMods = 0;
    }
     }
       
setGTargMode(w.curr().getTarget());
setGroupTask(21);
}
   }

if (w.curr().waypointType == 802) {
if (w.curr().getTarget() != null) {
    setGTargMode(w.curr().getTarget());
   
if (gTargMode != 0) {
maneuver.target_ground = setGAttackObject(0);
if (maneuver.target_ground != null && (maneuver.target_ground.distance(airc[0]) < 12000.0)) {
    setGroupTask(21);
if (weWereInGAttack == false && (maneuver.target_ground.distance(airc[0]) < 1200.0)) {
      Voice.speakBeginGattack(airc[0]);
      weWereInGAttack = true;
    }
   
}
  }
}
   }
   
   if (w.curr().waypointType == 803) {
if (w.curr().getTarget() != null) {
    setGTargMode(w.curr().getTarget());
   
if (gTargMode != 0) {
maneuver.target_ground = setGAttackObject(0);
if (maneuver.target_ground != null && (maneuver.target_ground.distance(airc[0]) < 12000.0)) {
    setGroupTask(22);
if (weWereInGAttack == false && (maneuver.target_ground.distance(airc[0]) < 1200.0)) {
      Voice.speakBeginGattack(airc[0]);
      weWereInGAttack = true;
    }
   
}
  }
}
   }
   
   if (w.curr().waypointType == 804) {
if (w.curr().getTarget() != null) {
    setGTargMode(w.curr().getTarget());
   
if (gTargMode != 0) {
maneuver.target_ground = setGAttackObject(0);
if (maneuver.target_ground != null && (maneuver.target_ground.distance(airc[0]) < 12000.0)) {
    setGroupTask(17);
if (weWereInGAttack == false && (maneuver.target_ground.distance(airc[0]) < 1200.0)) {
      Voice.speakBeginGattack(airc[0]);
      weWereInGAttack = true;
    }
   
}
  }
}
   }
   if (w.curr().waypointType == 805) {
if (w.curr().getTarget() != null) {
    setGTargMode(w.curr().getTarget());
   
if (gTargMode != 0) {
maneuver.target_ground = setGAttackObject(0);
if (maneuver.target_ground != null && (maneuver.target_ground.distance(airc[0]) < 12000.0)) {
    setGroupTask(14);
if (weWereInGAttack == false && (maneuver.target_ground.distance(airc[0]) < 1200.0)) {
      Voice.speakBeginGattack(airc[0]);
      weWereInGAttack = true;
    }
   
}
  }
}
   }

In  void update i add switch Action 4.
There is a check of actions and tasks.
If action 4, then check the code.
Why doesn't the counter work?

Code: [Select]
if (grTask == 4) {
weWereInGAttack = true;
boolean bool_100_ = somebodyGAttacks();
boolean bool_101_ = false;
for (int i = 0; i < nOfAirc; i++) {
    Maneuver maneuver_102_ = (Maneuver) airc[i].FM;
    if (maneuver_102_.gattackCounter >= 7)
bool_101_ = true;
}
if (!bool_100_ || bool_101_ || gTargDestroyed) {
    airc[0].FM.AP.way.next();
    w.next();
    setGroupTask(1);
    for (int i = 1; i < nOfAirc; i++) {
Maneuver maneuver_103_ = (Maneuver) airc[i].FM;
maneuver_103_.push(57);
maneuver_103_.pop();
    }
    setFormationAndScale((byte) (maneuver.AP.way.curr()
.formation),
1.0F, true);
    if (bool_101_) {
for (int i = 0; i < nOfAirc; i++)
    ((Maneuver) airc[i].FM).gattackCounter = 0;
    }
}
    }

This is in the 3rd type, but in mine the same thing, but with a task 21 not.



Logged

SAS~Storebror

  • Editor
  • member
  • Offline Offline
  • Posts: 24030
  • Taking a timeout
    • STFU
Re: Create counter Attack
« Reply #1 on: January 29, 2025, 08:52:04 AM »

I have no idea what you did there and what the intention is.
There's no comment in the code, no way for anyone to guess which things you modified in code where and why.

]cheers[
Mike
Logged
Don't split your mentality without thinking twice.

taly01

  • member
  • Offline Offline
  • Posts: 66
    • MY Sim Tech
Re: Create counter Attack
« Reply #2 on: January 30, 2025, 06:39:45 PM »

I've been playing with AI code checkers and have been wanting to learn how the plane AI works so I ran this through the checker.  It mostly gives useless style comments but it picked up this

........Addressed the issue of 'weWereInGAttack' being compared against 'false' instead of using '!' in front of the variable for the boolean check......................

if (weWereInGAttack == false

should be

if (!weWereInGAttack

Logged
Pages: [1]   Go Up
 

Page created in 0.09 seconds with 26 queries.