Different range for different target categories?

Different range for different target categories?

Discuss game development here, from a distinct game project to an accessible third-party mutator, down to the interaction and design of individual units if you like.

Moderator: Moderators

Post Reply
User avatar
Pxtl
Posts: 6112
Joined: 23 Oct 2004, 01:43

Different range for different target categories?

Post by Pxtl »

Is it possible? A weapon that is long-ranged vs unit X but short-ranged vs unit Y? Without swapping weapons around and dealing with all the bugs associated with that?
User avatar
smoth
Posts: 22309
Joined: 13 Jan 2005, 00:46

Re: Different range for different target categories?

Post by smoth »

Not possible and dunno
luckywaldo7
Posts: 1398
Joined: 17 Sep 2008, 04:36

Re: Different range for different target categories?

Post by luckywaldo7 »

By weapon swapping do you mean giving it 2 different weapons identical in everything except range and target catergories? You could use the script to block the other weapon when one is firing, but I suppose the potential bugs come from what happens when it tries to retarget.
User avatar
knorke
Posts: 7971
Joined: 22 Feb 2006, 01:02

Re: Different range for different target categories?

Post by knorke »

By weapon swapping do you mean giving it 2 different weapons identical in everything except range and target catergories?
as i understand that is the way he does not want to use for whatever reason.
I did something similiar:
rocketlauncher, vs vehicles it "locks on" and is tracking but not vs infantry targets. It consists of 2 weapons and when one is fired, the other is blocked until reload is finished.
Seems to work okayish.


Maybe try like this:
1) figure out what unitID the unit is targeting:
gadget:AllowWeaponTarget or in unitscript targetWeight
2) see what category that unit belongs into
3) adjust weapon range accordingly
or
3b) get distance to target and make it retarget

It basically comes down to the question "How can I control what target is picked by a weapon/unit?"

When I tried similiar things it never really worked right eg:
http://answers.springlobby.info/questio ... rgetweight

My feeling is that such things are possible but I do not really understand how the targeting and callins work. Or maybe bugs.
User avatar
Pxtl
Posts: 6112
Joined: 23 Oct 2004, 01:43

Re: Different range for different target categories?

Post by Pxtl »

Hmm... correct me if I'm wrong, but when a Spring unit decides to "attack" something, how does it choose which range to fire at? That is, if I have a long-ranged antiA weapon and a short-ranged antiB weapon, will it intelligently pursue units properly when patrolling/fighting? That is, if I see an "A", will I be dumb and try to move into my primary (short-ranged) weapon range? I know Spring's logic is generally "get close to unit until you can hit it, then fire and stop advancing on it" or is there any more intelligent consideration of firing range or "primary" vs "secondary" weapons?

Maybe the two-weapon / jamming approach would work, but it would be tricky to switch around which weapon was "active" if they tried to choose different targets (but Knorke's thing might have the same problem). Is it possible to read the Target Priority calculated value that the engine is using internally to determine which one to go with?

edit: googles reveal there is a CLuaUnitScript::TargetWeight that you can use to read the target weigh for a given weapon/unit combo, so yes, the latter could work.

Dual weapon setup might be the way to go for something like this. Duly noted for the day I get off my duff and code something.
User avatar
Pressure Line
Posts: 2283
Joined: 21 May 2007, 02:09

Re: Different range for different target categories?

Post by Pressure Line »

is there any more intelligent consideration of firing range or "primary" vs "secondary" weapons?
No. Spring gets the unit to move into range of Weapon1. 'Best' way would be to do something like knorke suggested.

Code: Select all

function gadget:AllowWeaponTarget(attackerID, targetID, attackerWeaponNum, attackerWeaponDefID, defaultPriority)
	attackerUnitDefID = Spring.GetUnitDefID(attackerID)
	targetUnitDefID = Spring.GetUnitDefID(targetID)
	if UnitDefs[attackerUnitDefID].name = "footank"
		if UnitDefs[targetDefID].name = "infantry"
			Spring.SetUnitWeaponState(attackerID, 1, "range", 128)
		else
			Spring.SetUnitWeaponState(attackerID, 1, "range", 512)
		end
	end

	return true, defaultPriority
end
something like that should do the trick. Doing it by unit category shouldnt be much more complicated. Would be better to get the information via a config file, that way it would be fully adaptable to any situation.

PS: don't use that code verbatim, it will only cause fail and lulz.

I have a few other gadgets that I want to write, and with this weekend being a 3 day weekend I might be able to quickly whack something out :)
User avatar
Pressure Line
Posts: 2283
Joined: 21 May 2007, 02:09

Re: Different range for different target categories?

Post by Pressure Line »

Bump for new info in previous post.
User avatar
knorke
Posts: 7971
Joined: 22 Feb 2006, 01:02

Re: Different range for different target categories?

Post by knorke »

i had played around a bit:

Code: Select all

function gadget:AllowWeaponTarget(attackerID, targetID, attackerWeaponNum, attackerWeaponDefID, defaultPriority)
   Spring.Echo ("attackerID=".. attackerID .."  " .. "targetID=" .. targetID)

   attackerUnitDefID = Spring.GetUnitDefID(attackerID)
   targetUnitDefID = Spring.GetUnitDefID(targetID)
   if UnitDefs[attackerUnitDefID].name == "tptank" then
    
	if UnitDefs[targetUnitDefID].name == "tpdude" then
         Spring.Echo ("aiming at a dude")
		 Spring.SetUnitWeaponState(attackerID, 0, "range", 2000)
      else
		Spring.Echo ("aiming at something else")
         Spring.SetUnitWeaponState(attackerID, 0, "range", 400)
      end
	  
   end   
   return true, defaultPriority
end
problem is, if a there is a "far-range" target in far range then the unit can only shot at it after is has previously shot a "far-range" target at close range.
AllowWeaponTarget is only called when the target is in range but if the weapons range is not "extended" yet, it will not be called.
So the range will not e extended and so on.

One way to get around that would be with using 2 weapons:
weapon 0: fake weapon (invisible)
weapon 1: real weapon
(SetUnitWeaponState starts counting with 0)

weapon 0 would be a bit like a targeting laser/painter..
and then add something like

Code: Select all

function gadget:AllowWeaponTarget(attackerID, targetID, attackerWeaponNum, attackerWeaponDefID, defaultPriority)
if attackerWeaponNum == 0 then
...
blabla adjust range of weapon 1
On the good side is, it seems not abuseable:
I thought it might be possible to target a "far-category" target and at last moment change target to a "near-category" target to cheat but that seems not possible.

Anyway thats just quick note i thought might be helpful ;)
User avatar
Pxtl
Posts: 6112
Joined: 23 Oct 2004, 01:43

Re: Different range for different target categories?

Post by Pxtl »

PL, don't hammer something out on account of me... I was just hammering out an idea for a project in my head and wanted to know feasibility.
User avatar
Pressure Line
Posts: 2283
Joined: 21 May 2007, 02:09

Re: Different range for different target categories?

Post by Pressure Line »

I wanna do it for shits and giggles

i did write a gadget to add a ui button to select a range for a unit, but yeah, easiest to use a fake weapon1 imo.
Post Reply

Return to “Game Development”