Page 1 of 3

REQ: Wiget Auto D-gun?

Posted: 25 Oct 2008, 21:20
by Super Mario
That way you don't have to click on the G-gun button everytime when attacking something. I don't know how to program though...

Re: REQ: Wiget Auto D-gun?

Posted: 25 Oct 2008, 21:37
by Pendrokar
Super Mario wrote:I don't know how to program though...
Then you know everything about movement prediction? :shock:
I once questioned that! - viewtopic.php?f=23&t=13465&hilit=prediction
(regrettably I did not understand ILMTitan's evaluation) :?

Well I wanted to create a helper widget which draws circles of where you need to shoot the D-gun but what you want is an A.I.

Re: REQ: Wiget Auto D-gun?

Posted: 25 Oct 2008, 21:56
by Super Mario
I just want the COM to shoot D-guns automatically when attacking something.

Re: REQ: Wiget Auto D-gun?

Posted: 25 Oct 2008, 22:18
by Pendrokar
Super Mario wrote:I just want the COM to shoot D-guns automatically when attacking something.
Then he would shoot down anything behind the enemy unit(of course an if function is possible) and wouldn't be more effective than a skilled player because of possible less hits for more units if you know what I mean. :roll:

Re: REQ: Wiget Auto D-gun?

Posted: 26 Oct 2008, 11:47
by REVENGE
I considered doing this, but it's to the point where I believe it's taking over some essential micro actions that should be done by the player, and not by an algorithm.

Although I must say, this is a fairly important piece of code for a competent AI to have.

Re: REQ: Wiget Auto D-gun?

Posted: 26 Oct 2008, 15:19
by Tribulexrenamed
noob

Also dont click, press D

Re: REQ: Wiget Auto D-gun?

Posted: 26 Oct 2008, 21:58
by quantum
Here you go!

Code: Select all

--------------------------------------------------------------------------------
--------------------------------------------------------------------------------

function widget:GetInfo()
  return {
    name      = "Auto D-Gunner",
    desc      = "Gives a d-gun order on units in range.",
    author    = "quantum",
    date      = "Oct, 26, 2008",
    license   = "GNU GPL, v2 or later",
    layer     = 0,
    enabled   = true  --  loaded by default?
  }
end

--------------------------------------------------------------------------------
--------------------------------------------------------------------------------

local commIDs = {}
local lastAttack = 0

--------------------------------------------------------------------------------
--------------------------------------------------------------------------------

function widget:UnitCreated(unitID, unitDefID)
  if (UnitDefs[unitDefID].isCommander) then
    for _, weaponData in ipairs(UnitDefs[unitDefID].weapons) do
      local wd = WeaponDefs[weaponData.weaponDef]
      if (wd.name:lower():find"disintegrator") then
        commIDs[unitID] = wd.range
      end
    end
  end
end


function widget:UnitDestroyed(unitID)
  commIDs[unitID] = nil
end


function widget:Initialize()
  for _, unitID in ipairs(Spring.GetAllUnits()) do
    widget:UnitCreated(unitID, Spring.GetUnitDefID(unitID))
  end
end


function widget:Update(dt)
  if (Spring.GetGameSeconds() - lastAttack < 0.2) then
    return
  end
  for unitID, range in pairs(commIDs) do
    if (not Spring.GetUnitIsDead(unitID)) then
      local nearestEnemy = Spring.GetUnitNearestEnemy(unitID, range)
      if (nearestEnemy) then
        Spring.GiveOrderToUnit(unitID, CMD.DGUN, { nearestEnemy },{})
        lastAttack = Spring.GetGameSeconds();
      end
    end
  end
end

--------------------------------------------------------------------------------
--------------------------------------------------------------------------------

Re: REQ: Wiget Auto D-gun?

Posted: 26 Oct 2008, 22:23
by REVENGE
Meh... :?
I hope people won't start demanding widget whitelists because of this! :P

Re: REQ: Wiget Auto D-gun?

Posted: 26 Oct 2008, 23:12
by Pendrokar

Code: Select all

Spring.GiveOrderToUnit(unitID, CMD.DGUN, { nearestEnemy },{})
"Bam... miss Bam... miss Bam... miss Bam... Oh finally a lucky shot yuhu! whups there was a friendly krogoth behind that one. BBBBUUUUUMMMM!!!"

Re: REQ: Wiget Auto D-gun?

Posted: 27 Oct 2008, 00:38
by Noruas
Well its good but bad at the same time, it forces the commander to move by itself, if i could just move it and let the widget worry about the aiming part itd be great. :twisted:

Re: REQ: Wiget Auto D-gun?

Posted: 27 Oct 2008, 01:15
by REVENGE
Noruas wrote:Well its good but bad at the same time, it forces the commander to move by itself, if i could just move it and let the widget worry about the aiming part itd be great. :twisted:
Trying to get that working, along with a target movement prediction algorithm. 8)

Re: REQ: Wiget Auto D-gun?

Posted: 27 Oct 2008, 11:30
by AF
Using such a widget can be troublesome because:
  • DGun can be expensive energywise in certain situations
  • Your now open to a horrible exploit where lots of cheap units surround commander and commander dguns, destroying hugely expensive base
  • DGun shots only work effectively when the unit is sitting still, otherwise you need to use predictive aiming
Next time someone plays you they know to spam fleas early game and trick your commander into auto d-gunning your factory crippling you.

Re: REQ: Wiget Auto D-gun?

Posted: 27 Oct 2008, 11:32
by TheFatController
Just do a string of GetUnitsInCylinder checks along the path of the dgun and look for friendly units :p

Re: REQ: Wiget Auto D-gun?

Posted: 27 Oct 2008, 15:54
by 1v0ry_k1ng
there were some awesome widgets for xta that *someone* made:

1) where you could set unit types the commander would automaticly be set to dgun when they came within 240 range (ie, if an atlas came in dgun range it would be autotargetted and killed)

2) where you could set the number x unit type x coming within distance x make the commander cloak until they moved away

for obvious and funny reasons these were [RoX] only but these were excellent for people to lazy to microprotect their com

Re: REQ: Wiget Auto D-gun?

Posted: 27 Oct 2008, 18:29
by Noruas
I always knew there was no way you were that good when you beat me to a pulp :lol:

Re: REQ: Wiget Auto D-gun?

Posted: 27 Oct 2008, 19:15
by Otherside
LEARN2DGUN

Re: REQ: Wiget Auto D-gun?

Posted: 27 Oct 2008, 22:19
by Pendrokar
Otherside wrote:LEARN2DGUN
Face it and A.I. could D-gun BETTER! :D

Re: REQ: Wiget Auto D-gun?

Posted: 28 Oct 2008, 00:36
by Super Mario
AF wrote:Using such a widget can be troublesome because:
  • 1.DGun can be expensive energywise in certain situations
    2.Your now open to a horrible exploit where lots of cheap units surround commander and commander dguns, destroying hugely expensive base
    3.DGun shots only work effectively when the unit is sitting still, otherwise you need to use predictive aiming
Next time someone plays you they know to spam fleas early game and trick your commander into auto d-gunning your factory crippling you.
1.Then program the widget to not use the D-Gun when your energy is low.

2.Then program the widget to not fire when friendly units is in the D-Gun range and not to fire when friendly buildings is near by.

3. Then program the widget to only fire when the enemy unit is holding still.(The buildings shouldn't be a problem.

if that doesn't work out then program the widget to Auto D-gun when manually targeting a building or a enemy unit.
Otherside wrote:LEARN2DGUN
That's not what I was talking about
Tribulex wrote:noob
Also dont click, press D
When a swarm of enemy units surround your commander, believe me you have to D-gun them, AS FAST AS YOU CAN and besides you still have to click even though you already press D. I can D-gun a lot faster in FPS mode (which its frustrating when attacking something with a D-gun BTW)

Re: REQ: Wiget Auto D-gun?

Posted: 28 Oct 2008, 01:41
by Noruas
Super Mario im putting you in charge of this project.

Re: REQ: Wiget Auto D-gun?

Posted: 28 Oct 2008, 03:08
by Scikar
Didn't AF or someone make a dgun unit AI that could snipe planes out of the sky?