• Listen to a special audio message from Bill Roper to the Hive Workshop community (Bill is a former Vice President of Blizzard Entertainment, Producer, Designer, Musician, Voice Actor) 🔗Click here to hear his message!
  • Read Evilhog's interview with Gregory Alper, the original composer of the music for WarCraft: Orcs & Humans 🔗Click here to read the full interview.

IsDestructableTree

This bundle is marked as useful / simple. Simplicity is bliss, low effort and/or may contain minor bugs.
I created this system because it is the most efficient way to detect if a destructable is a tree or not. Though it does take some time to register every tree.
JASS:
/*This system is the most efficient way to detect whether or not a destructable is a tree.
  The only downside to this, is that you must save every tree ID into the hashtable.
  To do so do the following:
  Go to object editor and find your tree. Press CTR+D. Now take the first four characters
  before the name.
  Example:
  ATtr (Ashenvale Tree Wall)
  Take ATtr and put it into the apostrophes
  
  call SaveBoolean(h,'HERE',0,true)
  
  So the result would be:
  
  call SaveBoolean(h,'ATtr',0,true//And for organization purposes, you may put the name here.
  
  IsDestructableTree takes destructable returns boolean
  
  IsDestructableTypeTree takes destructabletype/ID/Integer returns boolean
  
*/
library IsDestructableTree initializer init
globals
private hashtable h=InitHashtable()
endglobals
private function init takes nothing returns nothing
call SaveBoolean(h,'ATtr',0,true)//Ashenvale Tree Wall
call SaveBoolean(h,'BTtw',0,true)//Barrens Tree Wall
call SaveBoolean(h,'KTtw',0,true)//Black Citadel Tree Wall
call SaveBoolean(h,'YTft',0,true)//Cityscape Fall Tree Wall
call SaveBoolean(h,'JTct',0,true)//Cityscape Ruined Tree Wall
call SaveBoolean(h,'YTst',0,true)//Cityscape Snowy Tree Wall
call SaveBoolean(h,'YTct',0,true)//Cityscape Summer Tree Wall
call SaveBoolean(h,'YTwt',0,true)//Cityscape Winter Tree Wall
call SaveBoolean(h,'Jtwt',0,true)//Dalaran Ruins Tree Wall
call SaveBoolean(h,'DTsh',0,true)//Dungeon Tree Wall
call SaveBoolean(h,'FTtw',0,true)//Fall Tree Wall
call SaveBoolean(h,'CTtr',0,true)//Felwood Tree Wall
call SaveBoolean(h,'ITtw',0,true)//Icecrown Tree Wall
call SaveBoolean(h,'NTtw',0,true)//Northrend Tree Wall
call SaveBoolean(h,'OTtw',0,true)//Outland Tree Wall
call SaveBoolean(h,'ZTtw',0,true)//Ruins Tree Wall
call SaveBoolean(h,'WTst',0,true)//Snowy Tree Wall
call SaveBoolean(h,'LTlt',0,true)//Summer Tree Wall
call SaveBoolean(h,'GTsh',0,true)//Underground Tree Wall
call SaveBoolean(h,'VTlt',0,true)//Village Tree Wall
call SaveBoolean(h,'WTtw',0,true)//Winter Tree Wall
call SaveBoolean(h,'ATtc',0,true)//Ashenvale Canopy Tree
call SaveBoolean(h,'BTtc',0,true)//Barrens Canopy Tree
call SaveBoolean(h,'CTtc',0,true)//Felwood Canopy Tree
call SaveBoolean(h,'ITtc',0,true)//Icecrown Canopy Tree
call SaveBoolean(h,'NTtc',0,true)//Northrend Canopy Tree
call SaveBoolean(h,'ZTtc',0,true)//Ruins Canopy Tree
endfunction
function IsDestructableTree takes destructable d returns boolean
return LoadBoolean(h,GetDestructableTypeId(d),0)
endfunction
function IsDestructableTypeTree takes integer i returns boolean
return LoadBoolean(h,i,0)
endfunction
endlibrary

Keywords:
Tree, Detect, Boolean
Contents

Just another Warcraft III map (Map)

Reviews
12th Dec 2015 IcemanBo: Too long as NeedsFix. Rejected. 17:51, 2nd Sep 2012 Magtheridon96: Yes, I know I said this would be the fastest way to detect trees, but this method over here is still quite fast: library IsDestructableTree requires...

Moderator

M

Moderator

12th Dec 2015
IcemanBo: Too long as NeedsFix. Rejected.

17:51, 2nd Sep 2012
Magtheridon96: Yes, I know I said this would be the fastest way to detect trees, but this method over here is still quite fast:

JASS:
library IsDestructableTree requires OrderId

	globals
		private unit dummy = null
	endglobals

	function IsDestructableTree takes destructable d returns boolean
		return IssueTargetOrderById(dummy, ORDER_harvest, d) and IssueImmediateOrderById(dummy, ORDER_stop)
	endfunction

	private module Init
		private static method onInit takes nothing returns nothing
			set dummy = CreateUnit(Player(15), 'hpea', 0, 0, 0)
			call UnitAddAbility(dummy, 'Aloc')
			call ShowUnit(dummy, false)
		endmethod
	endmodule
	private struct InitS extends array
		implement Init
	endstruct

endlibrary

It also requires no work at all from the user making it a perfect system.
 
Level 33
Joined
Mar 27, 2008
Messages
8,035
There is a better way (others has been using it - link by Purge) :/
1. Create dummy unit on mapInit (set it to variable)
2. Each time you want to check if the destructible or not, move the dummy to the destructible's location and order the dummy to 'harvest' it
3. Check if current order of the dummy is 'harvest', then it's a tree, else, it's not a tree.

Simple.
 
We are not rejecting this because we think it is slow:
Magtheridon96 said:
Yes, I know I said this would be the fastest way to detect trees, but this method over here is still quite fast:
Purgeandfire111 said:
This system requires more work from the user.

It just has less modularity. In this case, yes a simple O(1) retrieval is advantageous speed-wise (most likely very minimally though), but if someone uses custom trees, it requires extra implementation opposed to the harvester method which requires none. :)
 
Top