HomeUser Control Panel (unavailable in archive)ForumsTutorialsArt GalleryResourcesMaps

best way to know if a building is under construction or finished ?

01-10-2009, 04:57 PM#1
Troll-Brain
I need to know if a building's construction is finished or not.
I think the best way is to create a trigger with player_unit_event , finish and start constructing, and also 1 unit group.
When a building start his construction then add him in the group Starting, when the building is finished, then remove it of the unit group.

If the building is the group Starting, then the building is under construction, if not then it is finished.
Ofc, assume that this "system" is in a library, and checking if the unit is not null and a building.

Have you better ideas ?
01-10-2009, 05:01 PM#2
Flame_Phoenix
yes
the building can die while under construction. you should use table to see if the unit in cause is dead. If it is dead than you can also remove it from the group and the table, same for when it is finished.
01-10-2009, 05:12 PM#3
Troll-Brain
Quote:
Originally Posted by Flame_Phoenix
yes
the building can die while under construction. you should use table to see if the unit in cause is dead. If it is dead than you can also remove it from the group and the table, same for when it is finished.
There is no need of using game cache, really.

I could "refresh" the unit group periodically with Captain Griffen's script.
01-10-2009, 05:50 PM#4
chobibo
You can detect when the building dies and then remove it from the group, assuming that in your map buildings cannot be resurrected.
01-10-2009, 06:00 PM#5
Flame_Phoenix
Quote:
You can detect when the building dies and then remove it from the group, assuming that in your map buildings cannot be resurrected.
The point is YOU CAN detect when a unit dies, and YOU CAN find out if it is the specific unit in cause if you know how to use "Table". I do that all the time in my spells, just check them.

Quote:
I could "refresh" the unit group periodically with Captain Griffen's script.
If you are going to use a timer and attach information to it, you will be using game cache ... I just think that having code that fires on an event is more efficient than having a timer checking all units in a group all the time.
01-10-2009, 06:55 PM#6
Troll-Brain
Quote:
Originally Posted by Flame_Phoenix
The point is YOU CAN detect when a unit dies, and YOU CAN find out if it is the specific unit in cause if you know how to use "Table". I do that all the time in my spells, just check them.
If you check my last resource DetectRevivingStructure, you will see that i know how to use Table.

I don't need to detect the death, i can check his life, and when an unit is removed of the game, it isn't in any group any more, but to manage leak and increase efficient i would need this :
http://www.wc3campaigns.net/showthread.php?t=102162

Quote:
If you are going to use a timer and attach information to it, you will be using game cache ... I just think that having code that fires on an event is more efficient than having a timer checking all units in a group all the time.
Periodically doesn't mean something like 0.01 s, but more like 120 s or something like that, so game cache is a lame solution here.
And i still don't see why i would need it ...
01-10-2009, 06:56 PM#7
chobibo
I was answering Troll-Brain's inquiry, in which the objective was to determine if a building is under construction or already finished, that's all, I didn't put into consideration if ever he tried attaching values to those units since he didn't ask for that.

Anyways, what is Troll-Brain specifically asking for, I can't tell from his first post.

EDIT: Oh now I got it Troll.
01-10-2009, 07:24 PM#8
Troll-Brain
Here is my script :

Collapse JASS:
library DetectBuildingConstructingStatus initializer init uses GroupRefresh

globals
    private constant real TIME_OUT = 120.0
    private group ConstructedBuildings
endglobals

function IsBuildingFinished takes unit u returns boolean
    return IsUnitInGroup(u,ConstructedBuildings) and not IsUnitType(u,UNIT_TYPE_DEAD)
endfunction

private function ManageBuildings takes nothing returns boolean
    call GroupAddUnit(ConstructedBuildings,GetConstructedStructure())
    return false
endfunction

private function RefreshGroup takes nothing returns nothing
    call GroupRefresh(ConstructedBuildings)
endfunction

private function init takes nothing returns nothing
    local trigger trig = CreateTrigger()
    local timer tim = CreateTimer()
    
    set ConstructedBuildings = CreateGroup()
    call TimerStart(tim,TIME_OUT,true,function RefreshGroup)
    call TriggerRegisterAnyUnitEventBJ(trig,EVENT_PLAYER_UNIT_CONSTRUCT_FINISH)
    call TriggerAddCondition(trig,Condition(function ManageBuildings))
    
    // unneeded but i tend to null all handles, even if it is never destroyed 
    set trig = null
    set tim = null
endfunction

endlibrary
01-10-2009, 08:31 PM#9
Flame_Phoenix
SO, if a unit dies during those 120 seconds, it will still be in the group for 120 secs for you remove it right ?
01-10-2009, 09:54 PM#10
Troll-Brain
Quote:
Originally Posted by Flame_Phoenix
SO, if a unit dies during those 120 seconds, it will still be in the group for 120 secs for you remove it right ?
Yes, and no.
It takes a little memory but the unit isn't really in the group.

EDIT : Asuming that the buildings dead without corpse.
01-10-2009, 10:21 PM#11
Flame_Phoenix
So, your system suffers from a high delay. Imagine I want to heal all units when a building under construction dies, in a TD. I start the building (it gets added to the group) but some stupid creep kills it right after. Assuming I am bad luck, the timer just started a new cycle, and so the heal will take place 120 seconds after, when all my army is dead ....

If this situation is correct, I suggest you find another solution, or decrease the check time.
01-10-2009, 10:31 PM#12
Troll-Brain
Quote:
Originally Posted by Flame_Phoenix
So, your system suffers from a high delay. Imagine I want to heal all units when a building under construction dies, in a TD. I start the building (it gets added to the group) but some stupid creep kills it right after. Assuming I am bad luck, the timer just started a new cycle, and so the heal will take place 120 seconds after, when all my army is dead ....

If this situation is correct, I suggest you find another solution, or decrease the check time.

I suggest you to read more the code.
I just need to use the function IsBuildingFinished, which work in all cases, and i don't need to get the death of a building.
01-11-2009, 03:05 AM#13
chobibo
Troll-Brain's periodic timer usage was intended to clean the shadow units from the global group where he stored the building that are already finished.

@Troll-Brain: I was just thinking that it would be much better to store into the group those units that are still under construction since you wouldn't need to periodically clean the group containing those units since they would be automatically removed when the building gets killed or when it finishes construction, the problem is that you need 3 events running for that approach, while yours needs only 1, but the group doesn't need to be periodically checked. Anyways I was only mentioning the difference of the two solutions. Thanks Troll.
01-11-2009, 11:40 AM#14
Troll-Brain
Quote:
I was just thinking that it would be much better to store into the group those units that are still under construction since you wouldn't need to periodically clean the group containing those units since they would be automatically removed when the building gets killed or when it finishes construction, the problem is that you need 3 events running for that approach, while yours needs only 1, but the group doesn't need to be periodically checked. Anyways I was only mentioning the difference of the two solutions
Again, yes and no :p

You forgot the function RemoveUnit. A such periodic is really irrevelant, imho.
I just wonder if there is a simplier method, like trying to add an ability (returns a boolean).
01-11-2009, 12:45 PM#15
chobibo
Oh so you intend to use RemoveUnit(), I thought that wasn't the case, I stand corrected.
Have you tried using IsUnitPaused to buildings under construction? I'll try doing that and tell you if it works.