Wc3C.net

Wc3C.net (http://www.wc3c.net/forums.php)
-   Scripts (http://www.wc3c.net/forumdisplay.php?f=737)
-   -   IsDestructableTree (http://www.wc3c.net/showthread.php?t=103927)

PitzerMike 01-03-2009 12:39 PM

IsDestructableTree
 
1 Attachment(s)
So I went through my old scripts at www.wc3jass.com and found this one. I decided to remake it as a library with some minor improvements. The IsDestructableTree function should come in handy for certain spells and systems. It works for the standard trees as well as custom trees (destructables based off trees). I've also included IsDestructableDead for completeness. It uses the unmodified footman as a dummy with the ghoul harvest ability, so there are no changes in the object editor required.


Collapse Library:
library DestructableLib initializer Initialization
//* ============================================================================ *
//* Made by PitzerMike                                                           *
//*                                                                              *
//* I made this to detect if a destructable is a tree or not. It works not only  *
//* for the standard trees but also for custom destructables created with the    *
//* object editor. It uses a footie as a dummy with the goul's harvest ability.  *
//* The dummy ids can be changed though. I also added the IsDestructableDead     *
//* function for completeness.                                                   *
//* ============================================================================ *

globals
    private constant integer DUMMY_UNIT_ID = 'hfoo' // footman
    private constant integer HARVEST_ID    = 'Ahrl' // ghouls harvest
    private constant player OWNING_PLAYER  = Player(15)
    
    private unit dummy = null
endglobals

function IsDestructableDead takes destructable dest returns boolean
    return GetDestructableLife(dest) <= 0.405
endfunction

function IsDestructableTree takes destructable dest returns boolean
    local boolean result = false
    if (dest != null) then
        call PauseUnit(dummy, false)
        set result = IssueTargetOrder(dummy, "harvest", dest)
        call PauseUnit(dummy, true) // stops order
    endif
    return result
endfunction

private function Initialization takes nothing returns nothing
    set dummy = CreateUnit(OWNING_PLAYER, DUMMY_UNIT_ID, 0.0, 0.0, 0.0)
    call ShowUnit(dummy, false) // cannot enumerate
    call UnitAddAbility(dummy, HARVEST_ID)
    call UnitAddAbility(dummy, 'Aloc') // unselectable, invulnerable
    call PauseUnit(dummy, true)
endfunction
endlibrary


I've also included a test map with standard and custom trees to validate the script. It's not too exciting though.
Can you think of anything else that could be useful in a DestructableLib?

PS: Anyone noticed how similar this looks to Dusquo's PathabilityCheck? :panda:

Pyrogasm 01-03-2009 01:35 PM

Giving a unit Aloc also makes it invulnerable and it also removes its pathing, so aren't these two lines useless?
Collapse JASS:
call SetUnitPathing(dummy, false)
call UnitAddAbility(dummy, 'Avul') // invulnerable
Aside from that, I see no downsides and nothing wrong with this system, plus the demo map works, FWIW. If you remove those lines or explain why they're necessary I'll approve this.

Vestras 01-03-2009 01:41 PM

So many of these (I mean types... the IsSomethingSomething)... but very useful, I've needed one of those many times.

PitzerMike 01-03-2009 02:36 PM

I wasn't exactly sure about the properties of Aloc, I'll just remove the two lines.
Also updated the demo map.

Flame_Phoenix 01-03-2009 02:56 PM

Does this only works for trees or can it work for other things such as bridges and other destructibles such as boxes?

Troll-Brain 01-03-2009 03:06 PM

A wood abilitie can target only a tree or a custom destructable based on a tree, that's your anwser.

Rising_Dusk 01-03-2009 08:13 PM

Yeah, approved.

PitzerMike 01-03-2009 08:43 PM

Thanks, Dusk and Pyro. :)

Spec 01-04-2009 07:47 AM

Hmm...
1. Why not creating ghoul ('ugho'), which is already have harvest ability, instead of footman? This can get rid of another two lines in script :)
2. GetWidgetLife(dest) is a little bit faster than GetDestructableLife(dest) (not noticeable, in fact...)

Pyrogasm 01-04-2009 08:35 AM

Because what if someone edits the default ghoul unit on their map to not have the harvest ability? Then it doesn't matter what unit it is because you still have to add the harvest ability to it, so it's better to be safe and do it the way he has done.

Bribe 09-06-2011 09:58 AM

This library could be shortened to just this:

Collapse JASS:
library IsDestructableTree
//* ============================================================================ *
//* Made by PitzerMike                                                           *
//*                                                                              *
//* I made this to detect if a destructable is a tree or not. It works not only  *
//* for the standard trees but also for custom destructables created with the    *
//* object editor. It uses a locust as a dummy with the ghoul's harvest ability. *
//* ============================================================================ *

globals
    private constant integer HARVEST_ABIL = 'Ahrl'     // ghouls harvest
    private constant integer HARVEST_ID   = 0xD0032    // harvest order ID
    private constant integer DUMMY_ID     = 'uloc'     // locust unit type
    private          unit    u            = null
endglobals

function IsDestructableTree takes destructable d returns boolean
    return IssueTargetOrderById(u, HARVEST_ID, d)
endfunction

private module M
    private static method onInit takes nothing returns nothing
        set u = CreateUnit(Player(15), DUMMY_ID, 0, 0, 0) // unselectable, untargetable, can't be enumerated
        call ShowUnit(u, false) //Invisible
        call UnitAddAbility(u, HARVEST_ABIL)
        call UnitRemoveAbility(u, 'Amov')  // the unit can never follow through with order, so
    endmethod                              // you don't need to pause/unpause the unit.
endmodule
private struct S extends array
    implement M
endstruct
endlibrary

Bannar 09-23-2011 09:55 PM

Instead of call UnitAddAbility(u, HARVEST_ID) should be:
call UnitAddAbility(u, HARVEST_ABIL)

Bribe 09-24-2011 05:35 AM

Thanks Spinnaker, I messed it up when I changed the order ID to be a constant and took over the old name.

cokemonkey11 05-07-2014 02:21 PM

1 Attachment(s)
Bribe, your version is incorrect because hidden units can move and destroy trees. See attached map. Also see http://www.hiveworkshop.com/forums/j...letree-248054/

Fledermaus 05-07-2014 11:23 PM

They tend to struggle at moving if they've had the move ability removed though :p
call UnitRemoveAbility(u, 'Amov')


All times are GMT. The time now is 11:01 AM.

Powered by vBulletin (Copyright ©2000 - 2019, Jelsoft Enterprises Ltd).
Hosted by www.OICcam.com
IT Support and Services provided by Executive IT Services