Java AI: How get unit damage and weapon range?

Java AI: How get unit damage and weapon range?

Here is where ideas can be collected for the skirmish AI in development

Moderators: hoijui, Moderators

Post Reply
playerO1
Posts: 57
Joined: 25 Jun 2014, 15:22

Java AI: How get unit damage and weapon range?

Post by playerO1 »

My bot is were peacy and don't do shooting. On this time he can only make eco, and with human help make tech up to new level (in the next do it automaticly). I don't planing smart army startegy on my bot, only were smart eco (absolute further mathematics precission eco :twisted: that best human players can't make better that my bot eco on extreme-low resource map (blue fields for example).
But I don't want see how my team bot factory do nothing. I can talk to my bot "hey, make 200 unit Peewe" or "bot make bomber". But now I have idea say "bot make army 7 min 30 sec for fast atack long range" then say "give me army" and he will be make best army and give to me. For this I need know next unit params: weapon range and weapon damage. On Spring engine weapon is were smart oblect, I see. I take this param as:

Code: Select all

        float damage=0.0f, range=0.0f;
        for (WeaponMount weaponMount:unit.getWeaponMounts()) {
            WeaponDef weapon=weaponMount.getWeaponDef();
            range = Math.max(range, weapon.getRange());
            damage += weapon.getDamage().getImpulseBoost(); // it's true?
        }
But I'm not sure that I getting true damage from this sourse code. How get weapon damage for sort unit by weapon power?
User avatar
knorke
Posts: 7971
Joined: 22 Feb 2006, 01:02

Re: Java AI: How get unit damage and weapon range?

Post by knorke »

damage += weapon.getDamage().getImpulseBoost(); // it's true?
Think it is not accurate.
Assuming that the Java interface is somewhat similiar to spring's defs when modding: then getDamage() is only the damage for one projectile.
1) Weapons can shot multiple projectiles at once, example: ARM Janus rocket.vehicle in BA always shots two rockets at once.
:arrow: weapon.getProjectilesPerShot()
2) Weapon can shot in bursts, example: ARM Rocketspider in BA always shots 3 rockets after each other.
In modding that is called "burst", in JavaAI maybe is called "salvo"
:arrow: weapon.getSalvoSize()

So needs to multiply damage by those factors.
http://spring.abma.de/doc-Interface-Jav ... onDef.html
User avatar
jK
Spring Developer
Posts: 2299
Joined: 28 Jun 2007, 07:30

Re: Java AI: How get unit damage and weapon range?

Post by jK »

the answer for your question is:
http://spring.abma.de/doc-Interface-Jav ... l#getTypes()

(0-type is likely default dmgtype)
playerO1
Posts: 57
Joined: 25 Jun 2014, 15:22

Re: Java AI: How get unit damage and weapon range?

Post by playerO1 »

Now I use this code for check damage:

Code: Select all

double damage=0.0, range=0.0;
for (WeaponMount weaponMount:unit.getWeaponMounts()) {
  WeaponDef weapon=weaponMount.getWeaponDef();
  range = Math.max(range, weapon.getRange());
  //weapon.getDamage().getTypes() !
  float dMultipler=weapon.getSalvoSize()*weapon.getProjectilesPerShot();
  float dmg= weapon.getDamage().getImpulseBoost();
  owner.sendTextMsg(" Weapon "+weapon.getName()+" damage="+dmg+" x multipler="+dMultipler+";" ,FieldBOT.MSG_DBG_ALL);
  damage += dmg*dMultipler; // TODO Test
}
Then have next info:
Weapon corak1_gator_laser damage=0.0 x multipler=1.0;
Weapon corstorm_core_kbot_rocket damage=0.123 x multipler=1.0;
Weapon corrock_lightartmiss damage=0.123 x multipler=1.0;
Weapon corcrash_bogus_missile damage=0.0 x multipler=1.0;
Weapon noweapon damage=0.0 x multipler=1.0;
Weapon corcrash_corekbot_missile damage=0.123 x multipler=1.0;
Weapon corak_gator_laser damage=0.0 x multipler=1.0;
Weapon gladiator_armkbot_missile3 damage=0.0 x multipler=1.0;
Weapon gladiator_gladiator_laser damage=0.0 x multipler=1.0;
Weapon corthud_arm_ham damage=0.123 x multipler=1.0;

The laser have damage 0.0, it is not true :(
User avatar
Anarchid
Posts: 1384
Joined: 30 Nov 2008, 04:31

Re: Java AI: How get unit damage and weapon range?

Post by Anarchid »

Weapon corstorm_core_kbot_rocket damage=0.123 x multipler=1.0;
All non-laser weapons having 0.123 damage is also incorrect, the weapons you listed should have different damages, with values measured in hundreds.

I suspect that's the damage multiplier vs some armor type, but that needs to be cleared up.
playerO1
Posts: 57
Joined: 25 Jun 2014, 15:22

Re: Java AI: How get unit damage and weapon range?

Post by playerO1 »

I rewrite code, now this is:

Code: Select all

double damage=0.0, range=0.0;
        for (WeaponMount weaponMount:unit.getWeaponMounts()) {
            WeaponDef weapon=weaponMount.getWeaponDef();
            if (!weapon.isParalyzer()
                && weapon.isAbleToAttackGround() && !weapon.isShield()) {
                range = Math.max(range, weapon.getRange());
                //weapon.getDamage().getTypes() // test!!!
                owner.sendTextMsg(" Weapon types: "+weapon.getDamage().getTypes().toString(), FieldBOT.MSG_DBG_ALL);

                float dMultipler=weapon.getSalvoSize()*weapon.getProjectilesPerShot();
                float dmg= weapon.getAreaOfEffect();// ?! //weapon.getDamage().getTypes().get(0);
                    //weapon.getDamage().getImpulseBoost(); //last test failed
              owner.sendTextMsg(" Weapon "+weapon.getName()+" damage="+dmg+" x multipler="+dMultipler+" (isSelfExplode="+weapon.isSelfExplode()+" isNoSelfDamage="+weapon.isNoSelfDamage()+" isParalyzer="+weapon.isParalyzer()+" isShield="+weapon.isShield()+" isAbleToAttackGround="+weapon.isAbleToAttackGround()+");" ,FieldBOT.MSG_DBG_ALL);
                damage += dmg*dMultipler;
            } else owner.sendTextMsg(" Weapon "+weapon.getName()+" isSelfExplode="+weapon.isSelfExplode()+", isNoSelfDamage="+weapon.isNoSelfDamage()+" isParalyzer="+weapon.isParalyzer()+" isShield="+weapon.isShield()+" isAbleToAttackGround="+weapon.isAbleToAttackGround()+";" ,FieldBOT.MSG_DBG_ALL);
        }
Output debug text:

Code: Select all

 Weapon types: [24.0, 24.0, 24.0, 24.0, 24.0, 24.0, 24.0, 24.0, 24.0, 24.0, 24.0, 24.0, 24.0, 12.0, 24.0, 24.0, 5.0, 24.0]
 Weapon armflea_flea_laser damage=4.0 x multipler=1.0 (isSelfExplode=false isNoSelfDamage=true isParalyzer=false isShield=false isAbleToAttackGround=true);
 Weapon armjeth_bogus_missile isSelfExplode=false, isNoSelfDamage=false isParalyzer=false isShield=false isAbleToAttackGround=false;
 Weapon types: [1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0]
 Weapon noweapon damage=4.0 x multipler=1.0 (isSelfExplode=false isNoSelfDamage=false isParalyzer=false isShield=false isAbleToAttackGround=true);
Whay that many weapon types?
Ok, I agree about weapon.getDamage().getTypes().get(0) is the near for real damage count.
Now I found new problem: How check weapon environment (fround, air, underwather)? I found that my bot choose best weapon for big range is anti-air, but I want choose best weapon range for ground atack.
How check that weapon is not self-destruction (no mine)?
User avatar
knorke
Posts: 7971
Joined: 22 Feb 2006, 01:02

Re: Java AI: How get unit damage and weapon range?

Post by knorke »

Whay that many weapon types?
Seems like that is the damage that the weapon does against different armor classes. Like this weapon:
[24.0, 24.0, 24.0, 24.0, 24.0, 24.0, 24.0, 24.0, 24.0, 24.0, 24.0, 24.0, 24.0, 12.0, 24.0, 24.0, 5.0, 24.0]
does 24.0 damage vs most units, but against some it will do a bit less damage.
Which mod is that by the way? I thought BA but there the flea laser is a bit different:
damage = {
bombers = 2,
default = 24,
fighters = 2,
subs = 1,
vtol = 2,
},
The other weapon does 1.0 damage vs everything but it is named armjeth_bogus_missile:
Some mods use such fake-weapons (that never actually fire) for various scripting tricks.
How check weapon environment (fround, air, underwather)? I found that my bot choose best weapon for big range is anti-air, but I want choose best weapon range for ground atack.
The mod sets sets the "what weapon can target what" via onlyTargetCategory , see http://springrts.com/wiki/Gamedev:UnitDefs#weapons
Note that this in the unitfile, but on loading it gets all mish-mashed anyway. :shock:
In the Java AI doc this looks similiar: getOnlyTargetCategory
How check that weapon is not self-destruction (no mine)?
That is again something that the mod sets per unit (not per weapon) via kamikaze=true
isAbleToKamikaze() from http://spring.abma.de/doc-Interface-Jav ... itDef.html looks good.

It seems the best way to figure things out is to look how the mod defines it
( http://springrts.com/wiki/Gamedev:UnitDefs and http://springrts.com/wiki/Gamedev:WeaponDefs ) then look in the Java AI docs for anything that looks similiar.
Bla
Posts: 79
Joined: 25 Feb 2013, 14:44

Re: Java AI: How get unit damage and weapon range?

Post by Bla »

If you're using tech annihilation, I think the numbers may be weird too, as I once tried getting the LoS of a flash, and the number came out to be like 24 or something ridiculously small.
playerO1
Posts: 57
Joined: 25 Jun 2014, 15:22

Re: Java AI: How get unit damage and weapon range?

Post by playerO1 »

Thank you knorke for information.
This test on Tech Anihilation (near from BA). But my bot work for NOTA and same other mods. My bot can spam eco, now they can spam army now too.
I found UnitDef.getMaxWeaponRange() function for get unit weapon range.
Bla
Posts: 79
Joined: 25 Feb 2013, 14:44

Re: Java AI: How get unit damage and weapon range?

Post by Bla »

playerO1 wrote: I found UnitDef.getMaxWeaponRange() function for get unit weapon range.
Ah, that should, help, thanks!
Post Reply

Return to “AI”