View topic - AllowWeaponTarget



All times are UTC + 1 hour


Post new topic Reply to topic  [ 6 posts ] 
Author Message
 Post subject: AllowWeaponTarget
PostPosted: 21 Jul 2012, 10:20 
Battletech Developer
User avatar

Joined: 21 May 2007, 01:09
Location: New Zealand
How the hell does this work?

Code:
function gadget:AllowWeaponTarget(aID, tID, aWN, aWDID, dP)
   local tDID = Spring.GetUnitDefID(tID)
   if UnitDefs[tDID].name == "resourcepoint" then
      Spring.Echo(foo)
      return false, 0
   end
   Spring.Echo("bar")
   return false, 0
   --return true, dP
end


does nothing, the echos print out fine, but otherwise does nothing.


Top
 Offline Profile  
 
 Post subject: Re: AllowWeaponTarget
PostPosted: 23 Jul 2012, 18:33 
Moderator

Joined: 12 Oct 2007, 08:24
I have a gadget unit_dont_fire_at_radar that implements units which cannot be fired at. It also takes some LUS.


Top
 Offline Profile  
 
 Post subject: Re: AllowWeaponTarget
PostPosted: 24 Jul 2012, 00:02 
Moderator

Joined: 05 Aug 2009, 19:42
I don't think that function works in the way we think it does, and I'm not sure on what the intended effect was.
http://springrts.com/mantis/view.php?id=3219
That got closed early, and it would perhaps be better if we discussed it here after all, it might be explained in more detail, and it seems I'm not the only one having trouble grasping it.

What is the point of that function if not to prevent units targeting other units? How else can we prevent specific units from firing at each other?
PS: I'm returning false for all calls of AllowWeaponTarget, and I was returning true for all calls of AllowWeaponTargetCheck, which I assumed would allow calling of AllowWeaponTarget.


Top
 Offline Profile  
 
 Post subject: Re: AllowWeaponTarget
PostPosted: 24 Jul 2012, 01:58 
Battletech Developer
User avatar

Joined: 21 May 2007, 01:09
Location: New Zealand
kloot wrote:
you don't seem to understand what returning false from AllowWeaponTarget does and does not do...


since there are no references to the callin in the changelog (other than the fixes in more recent versions) and the Wiki only mentions that the return value is expected to be "targetAllowed, targetPriority"

What this says to me is that:
a) if I 'return false,number' that weapon will completely ignore that target as a possible target
b)if I 'return true,priority' i can use some sort of logic to adjust the default priority value to make a unit prefer to attack certain target unitdefs (or whatever) first (something like a hypothetical 'preferredtargetcategory'), or conversely prefer to shoot anything other than a certain target first (iow badtargetcategory)

since there does not appear to be anything written down (changelog,wiki,source comments) anywhere other than the mantis comment, there is no way for us to know what it does or how to use it.

kloot wrote:
IT DOES:

* block a specific target from being considered during a weapon's periodic auto-targeting sweep


great!

kloot wrote:
IT DOES NOT:

* prevent a weapon from auto-generating a target for itself (that's the job of the AllowWeaponTargetCheck callin / commandfire WeaponDef key / unit states other than fire-at-will), unless false is always returned for all targets


And if it is returning false for all targets? As far as I could tell units would gleefully shoot at anything in range even if the entire gadget consisted of GetInfo and:

Code:
function gadget:AllowWeaponTarget(attID, tarID, attWepNum, attWePDefID, defPri)
     return false,0
end


kloot wrote:
* prevent a unit from returning fire at its last attacker (that's what the hold-fire unit state is for)

* prevent a unit's command "AI" from picking a target when the unit is idle (which is again controlled by a unit's fire- and movestate)


Imo it should be up to the game maker/gadget writer to impliment this properly, I don't think it's the engine's job to protect us from bad game design. (I could easily add a gadget to BA that randomly explodes metalmakers as nuclear explosions :twisted:. Possible? Yes. A good idea? Probably not. But nothing is stopping me from doing it.)

Examples:
1) Use AllowWeapontarget to impliment a minimum range. Minimum range is minimum range, it doesn't matter what the potential target is doing, I'm too close, so I cant shoot at it.

2) Game F has a unit that when given a custom command by the user becomes invulnerable, I dont want units wasting time shooting something that can't be hurt anyway, they should ignore it, or run away (or whatever, it's up to me to code behaviours for this)

3) Game U has massive radar wobble, I don't want my sharpshooter units shooting at things unless its in los *even if the radar blip is shooting at the sharpshooter* because it's a waste of time/metal/energy/whatever because the chance of the shots actually hitting is miniscule. Again, it should be up to me as the game dev to write in behaviours to manage this.


Top
 Offline Profile  
 
 Post subject: Re: AllowWeaponTarget
PostPosted: 24 Jul 2012, 06:19 
Moderator

Joined: 12 Oct 2007, 08:24
Here is my gadget which uses allowWeaponTarget. It implements '3' but there is a function canShootAtUnit which could be adapted for anything. It requires LUS (or a lot of painful cob stuff).

http://code.google.com/p/zero-k/source/ ... _radar.lua

Example script http://code.google.com/p/zero-k/source/ ... msnipe.lua


Top
 Offline Profile  
 
 Post subject: Re: AllowWeaponTarget
PostPosted: 24 Jul 2012, 07:23 
Battletech Developer
User avatar

Joined: 21 May 2007, 01:09
Location: New Zealand
The point is it shouldn't be painful. You should just be able to hit the "Don't shoot at radar blips" button in your gadget and the unit should just not shoot at radar blips.

Then you can just add functionality in the gadget to let it shoot at its last attacker if it is set to return fire/fire at will (easy), and/or move to a position it can see the unit from (a bit tricker) but imo it should all be able to be done gadget-side.


Top
 Offline Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 6 posts ] 

All times are UTC + 1 hour


Who is online

Users browsing this forum: alfianjoe and 3 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB® Forum Software © phpBB Group

Site layout created by Roflcopter et al.