wc3campaigns
WC3C Homepage - www.wc3c.netUser Control Panel (Requires Log-In)Engage in discussions with other users and join contests in the WC3C forums!Read one of our many tutorials, ranging in difficulty from beginner to advanced!Show off your artistic talents in the WC3C Gallery!Download quality models, textures, spells (vJASS/JASS), systems, and scripts!Download maps that have passed through our rigorous approval process!

Go Back   Wc3C.net > Resources > Code Resources > Systems
User Name
Password
Register Rules Get Hosted! Chat Pastebin FAQ and Rules Members List Calendar



Reply
 
Thread Tools Search this Thread
Old 07-21-2008, 01:45 AM   #1
moyack
Evil Emoticon
 
moyack's Avatar


Respected User
Project Leader: PoC
 
Join Date: Jan 2006
Posts: 3,278

Submissions (17)

moyack is a splendid one to behold (666)moyack is a splendid one to behold (666)moyack is a splendid one to behold (666)moyack is a splendid one to behold (666)

AI Tournament #2 - 2nd PlaceHero Contest - Second place

Send a message via MSN to moyack
Idea Unit Recycler & Simple Damage Detection System

NOTE: You have been redirected in order for our attachments to be made available to you. This will only last two minutes; these measures where taken to avoid hotlinking and bandwidth theft.
To avoid these restrictions Log in or Register

Unit Recycler & Uber simple damage detection
By moyack - 2009


Introduction:

This system is the result of working with a damage detection system that actually can be safe (AKA avoid totally the DestroyTrigger() function), so one solution to this issue is to avoid as much as possible (hopefully completely) the destruction of units and therefore the EVENT_DAMAGED triggers related to them, and the only way to make it possible is by recycling the units. The current result is a system that recycle most type of units (summoned and buildings simply don't work for their harcoded properties).


Why is convenient this system?

because the game won't need to allocate memory creating units, instead, they'll be backed up for a later use, which can improve your map performance. This can be very useful in maps where the unit spawning is a very common task (like AoS, footies, etc).


What's the issue with buildings and summoned units??

Buildings have limitations in moving them (they can be moved but their basement remains in the original place, which won't allow the construction of new units in those places). About summoned units, their dead is totally harcoded by the summoning abilities and can't be stopped by detecting the damage, therefore they can't be recycled.


How it works?

This library takes into account units that are being damaged, and detects if they're going to die (if the damage dealt to a unit is enough to kill them), if that situation happens, then it will be moved to the heaven, a place that you define in your map where the units are restored, cleaned and left ready for later use. Additionally this system offer a set of replacement functions which will help to this system to recycle units more efficiently.


How to install & final comments
  • Create a trigger and call it "UnitRecycler" or whatever you consider it best.
  • Convert it to custom text
  • Paste the content below.
  • In the configuration globals, set the AUTO_LOC = true if you want the system set automatically the Heaven location. Set it to false if you need to set it manually in the HEAVEN_POS variable.
  • That's all :)

That's all??? not actually. By doing only this the library will be able to add damage detection to units and store the fallen units into the heaven. But it's up to you to develop the code to recycle the units. How?? using the functions provided (you can see them in the library comments).


Expand Core library:

Changelog

(14/10/2008):
- Small improvements in the core library
- Developed a better example (a tiny AOS, much better than AotZ, DoE and ToB together :P)

(09/09/2008):
- Added a custom trigger event so the system can detect when a unit is about to be recycled
- Added some improvements

(31/12/2008):
- Other minor and final improvements (hopefully)

(06/01/2009):
- Now you can set up the system so it automatically set the heaven in a non playable area of the map (Thanks Troll brain for the idea)
- Added IsUnitDummy function to define if a unit is a placeholder or not.
- Added GetUnitsInHeaven function to retrieve the group that stores the units in Heaven. Useful to do operations with those units.
- Improved the test map with a leaderboard which shows data about units killed per player, units in map, units taht are being recycled, and the percentage of units recycled respect the total of active units.

(29/01/2009):
- Minor improvement in the DD code, now it's more efficient getting units in to the DD group.

(05/04/2009):
- Fixed an unit leak (thanks a lot Litany :D) and improved the CreateUnitEx function.



Please download the test map for further testing. (last updated: 05/04/2009)
Attached Images
File Type: gif recycle.gif (1.1 KB, 1377 views)
Attached Files
File Type: w3x Unit Recycler and DD.w3x (66.6 KB, 533 views)

Last edited by moyack : 05-31-2011 at 10:24 AM.
moyack is offline   Reply With Quote
Sponsored Links - Login to hide this ad!
Old 07-21-2008, 06:10 PM   #2
moyack
Evil Emoticon
 
moyack's Avatar


Respected User
Project Leader: PoC
 
Join Date: Jan 2006
Posts: 3,278

Submissions (17)

moyack is a splendid one to behold (666)moyack is a splendid one to behold (666)moyack is a splendid one to behold (666)moyack is a splendid one to behold (666)

AI Tournament #2 - 2nd PlaceHero Contest - Second place

Send a message via MSN to moyack
Default

Damage Detection only code:

Collapse DD without unit recycling:
//******************************************************************************
//*
//* Damage Detection script
//* By moyack. 2009
//*
//* ============================================================================
//* Credits to Litany, DioD, Captain Griffen, Troll Brain and other nice guys  *
//* for their suggestions, comments and ideas.                                 *
//* ============================================================================
//*
//* For Damage detection, you just need to use these functions:
//*
//*  => AddDamageCondition(<Boolexpr variable>) returns nothing
//*     -------------------------------------------------------
//*     Just add a condition function which manage the damaged unit and the script
//*     will use it with all the the units in the DD.D group.
//*
//*  => CreateDummy( player, 'Unitid', x, y, facing_Angle ) returns unit
//*     ----------------------------------------------------------------
//*     Like the CreateUnit function, but all the units created with this function
//*     won't trigger the this Damage Detection script. 
//*
//*  => DoNonDetectableDamage(unit, widget, damage, boolean_attack, boolean_ranged, attacktype, damagetype, weapontype) returns boolean
//*     -------------------------------------------------------------------------------------------------------------------------------
//*     Like the UnitDamageTarget function, but it can be used inside condition functions.
//*     How to know if you need to use it? if you use UnitDamageTarget() inside a DD function and 
//*     it freezes the game until it kills the attacked unit(s), then you have to replace that
//*     function by this custom one.
//********************************************************************************
library UnitDamage

struct DD // damage detection struct
    static group D // group of units that will have damage detection
    static group Dummies // group of units which will not be detected by the system
    static trigger T
    
    // Add the attacked unit to the damage detection if the unit is not in the pack
    static method AddUnit takes unit d returns nothing
        if not IsUnitInGroup(d, thistype.D) and not IsUnitInGroup(d, thistype.Dummies) then
            debug call DisplayTimedTextFromPlayer(GetLocalPlayer(), 0,0,2,"Added " + GetUnitName(d) + " to the DD")
            call TriggerRegisterUnitEvent(thistype.T, d, EVENT_UNIT_DAMAGED)
            call GroupAddUnit(thistype.D, d)
        endif
        set d = null
    endmethod
    
    private static method Attacked takes nothing returns nothing
        call thistype.AddUnit(GetTriggerUnit())
    endmethod
    
    private static method Spelled takes nothing returns nothing
        if GetSpellTargetUnit() != null then
            call thistype.AddUnit(GetSpellTargetUnit())
        endif
    endmethod
    
    private static method onInit takes nothing returns nothing
        set thistype.T = CreateTrigger()
        set thistype.D = CreateGroup()
        set thistype.Dummies = CreateGroup()
        call TriggerRegisterAnyUnitEventBJ(thistype.T, EVENT_PLAYER_UNIT_ATTACKED)
        call TriggerAddAction(thistype.T, function thistype.Attacked)
        set thistype.T = CreateTrigger()
        call TriggerRegisterAnyUnitEventBJ(thistype.T, EVENT_PLAYER_UNIT_SPELL_EFFECT)
        call TriggerAddAction(thistype.T, function thistype.Spelled)
        set thistype.T = CreateTrigger()
    endmethod
endstruct

// Damage detection system functions...
function AddDamageCondition takes code func returns nothing
    call TriggerAddCondition(DD.T, Condition(func))
endfunction

function CreateDummy takes player p, integer id, real x, real y, real f returns unit 
    local unit u = CreateUnit(p, id, x, y, f)
    call GroupAddUnit(DD.Dummies, u)
    return u
endfunction

function DoSafeDamage takes unit u, widget t, real damage, boolean attack, boolean ranged, attacktype AT, damagetype DT, weapontype WT returns boolean
    local boolean b
    call DisableTrigger(DD.T)
    set b = UnitDamageTarget(u, t, damage, attack, ranged, AT, DT, WT)
    call EnableTrigger(DD.T)
    return b
endfunction

function AddUnittoDD takes unit u returns nothing
    call DD.AddUnit(u)
endfunction

endlibrary

DD examples with this script

Expand Triggered Critical Strike:

Expand Triggered Evasion:

Last edited by moyack : 07-01-2011 at 04:46 AM.
moyack is offline   Reply With Quote
Old 07-21-2008, 11:46 PM   #3
Joker
User
 
Joker's Avatar
 
Join Date: Sep 2006
Posts: 687

Joker will become famous soon enough (32)Joker will become famous soon enough (32)

Default

So it needs orbs?
Joker is offline   Reply With Quote
Old 07-22-2008, 12:20 AM   #4
moyack
Evil Emoticon
 
moyack's Avatar


Respected User
Project Leader: PoC
 
Join Date: Jan 2006
Posts: 3,278

Submissions (17)

moyack is a splendid one to behold (666)moyack is a splendid one to behold (666)moyack is a splendid one to behold (666)moyack is a splendid one to behold (666)

AI Tournament #2 - 2nd PlaceHero Contest - Second place

Send a message via MSN to moyack
Default

No, it doesn't need any orbs if you want, but if you want to use them in your triggers, then go ahead!!

Edit: edited the comments in the script due to a typo.

Last edited by moyack : 08-03-2008 at 01:39 AM.
moyack is offline   Reply With Quote
Old 08-05-2008, 11:21 PM   #5
Rising_Dusk
Obscurity, the Art


Projects Director
Project Leader: OD
 
Join Date: Feb 2006
Posts: 9,729

Submissions (27)

Rising_Dusk has a reputation beyond repute (1192)Rising_Dusk has a reputation beyond repute (1192)Rising_Dusk has a reputation beyond repute (1192)Rising_Dusk has a reputation beyond repute (1192)Rising_Dusk has a reputation beyond repute (1192)Rising_Dusk has a reputation beyond repute (1192)Rising_Dusk has a reputation beyond repute (1192)Rising_Dusk has a reputation beyond repute (1192)Rising_Dusk has a reputation beyond repute (1192)

Hero Contest #3 - 1st PlaceApproved Map: Desert of ExileApproved Map: Advent of the ZenithHero Contest #2 - 1st PlaceHero Contest - Third place>

Send a message via AIM to Rising_Dusk Send a message via MSN to Rising_Dusk
Default

I was looking at this, and it really falters because of the use of dynamic triggers. I would much rather leak the event than deal with all of the long-since proven potential issues associated with destroying triggers at runtime. The only way to not destroy triggers as you have it is to use a single trigger and leak the event, but then you have really accomplished nothing other than porting out a small fraction of any damage detection/rendering system already in the resource section.

Also, O(n) searches are unacceptable in the database. You're going to have to approach them in a different way, potentially with cache.
__________________
Rising_Dusk is offline   Reply With Quote
Old 08-08-2008, 07:12 PM   #6
moyack
Evil Emoticon
 
moyack's Avatar


Respected User
Project Leader: PoC
 
Join Date: Jan 2006
Posts: 3,278

Submissions (17)

moyack is a splendid one to behold (666)moyack is a splendid one to behold (666)moyack is a splendid one to behold (666)moyack is a splendid one to behold (666)

AI Tournament #2 - 2nd PlaceHero Contest - Second place

Send a message via MSN to moyack
Default

I think I have a solution... I'm working on this so be patient please....

Last edited by moyack : 08-09-2008 at 01:54 AM.
moyack is offline   Reply With Quote
Old 08-09-2008, 01:55 AM   #7
moyack
Evil Emoticon
 
moyack's Avatar


Respected User
Project Leader: PoC
 
Join Date: Jan 2006
Posts: 3,278

Submissions (17)

moyack is a splendid one to behold (666)moyack is a splendid one to behold (666)moyack is a splendid one to behold (666)moyack is a splendid one to behold (666)

AI Tournament #2 - 2nd PlaceHero Contest - Second place

Send a message via MSN to moyack
Default

Ok, This is the code thus far:

Expand Unit recycler (not fully working):

Right now I'm having issues in the code that detects if a unit decays, sometimes work, sometimes it doesn't.

Any help will be appreciated & credited.
moyack is offline   Reply With Quote
Old 08-09-2008, 05:34 AM   #8
DioD
obey
 
DioD's Avatar
 
Join Date: Feb 2006
Posts: 1,532

Submissions (4)

DioD is a jewel in the rough (220)DioD is a jewel in the rough (220)DioD is a jewel in the rough (220)DioD is a jewel in the rough (220)

Send a message via ICQ to DioD
Default

Jass code without map for actually "better to see" systems useless.

Write some AOS code (creep walkers) add your system and show.

note: Artillery type attacks will surely crush your system.
DioD is offline   Reply With Quote
Old 08-09-2008, 08:54 AM   #9
Captain Griffen
Dread Lord of the Cookies
 
Captain Griffen's Avatar


Content Director
 
Join Date: Sep 2003
Posts: 5,375

Submissions (2)

Captain Griffen is a glorious beacon of light (497)Captain Griffen is a glorious beacon of light (497)Captain Griffen is a glorious beacon of light (497)Captain Griffen is a glorious beacon of light (497)Captain Griffen is a glorious beacon of light (497)

Approved Map: Warlords[Quicksilver #2] - 1st Place

Default

moyack, I'm not quite sure you've grasped the problems with unit recycling. The coding in the whole map must be adjusted for it.
__________________
Quote:
Originally Posted by Earth-Fury
Griffen is correct, you are not.
Quote:
[13:32] <Akolyt0r> hmm.. stil i want to have some unused women
Captain Griffen is offline   Reply With Quote
Old 08-09-2008, 02:21 PM   #10
moyack
Evil Emoticon
 
moyack's Avatar


Respected User
Project Leader: PoC
 
Join Date: Jan 2006
Posts: 3,278

Submissions (17)

moyack is a splendid one to behold (666)moyack is a splendid one to behold (666)moyack is a splendid one to behold (666)moyack is a splendid one to behold (666)

AI Tournament #2 - 2nd PlaceHero Contest - Second place

Send a message via MSN to moyack
Default

Quote:
Originally Posted by DioD
Jass code without map for actually "better to see" systems useless.

Write some AOS code (creep walkers) add your system and show.

note: Artillery type attacks will surely crush your system.
I have an ugly test map, but useful, I'll post it this nght.

Artillery is a scenario I haven't thought... well, it's bad and good at the same time because it makes the script simpler, but less versatile....

Quote:
Originally Posted by Captain Griffen
moyack, I'm not quite sure you've grasped the problems with unit recycling. The coding in the whole map must be adjusted for it.
You're right, actually I wanted to do this because all the time I saw in other posts in other threads that unit recycling is possible, so I wanted to know how complete this could be. As a learning experience is pretty good and after all this test I conclude it's only viable for units with corpse. So I decided to reduce it to the recycling process of the corpses, I think in this way the script is very simple and efficient and can be easily applied to any kind of map.

This should be the simplified code (not tested in game):

Expand JASS:
moyack is offline   Reply With Quote
Old 08-09-2008, 05:34 PM   #11
Rising_Dusk
Obscurity, the Art


Projects Director
Project Leader: OD
 
Join Date: Feb 2006
Posts: 9,729

Submissions (27)

Rising_Dusk has a reputation beyond repute (1192)Rising_Dusk has a reputation beyond repute (1192)Rising_Dusk has a reputation beyond repute (1192)Rising_Dusk has a reputation beyond repute (1192)Rising_Dusk has a reputation beyond repute (1192)Rising_Dusk has a reputation beyond repute (1192)Rising_Dusk has a reputation beyond repute (1192)Rising_Dusk has a reputation beyond repute (1192)Rising_Dusk has a reputation beyond repute (1192)

Hero Contest #3 - 1st PlaceApproved Map: Desert of ExileApproved Map: Advent of the ZenithHero Contest #2 - 1st PlaceHero Contest - Third place>

Send a message via AIM to Rising_Dusk Send a message via MSN to Rising_Dusk
Default

I was discussing this with Griffen the other day. Unit Recycling isn't too wretchedly difficult, but I think it's entirely impossible to write one generalized and fully global script that would properly allow you to recycle units in any map. I think those sorts of things must be tailored heavily and specifically for the type of map in question.

Griffen was saying he wants to write one too, but I'm fairly certain it'll run into similar blockades.
__________________
Rising_Dusk is offline   Reply With Quote
Old 08-09-2008, 08:13 PM   #12
Captain Griffen
Dread Lord of the Cookies
 
Captain Griffen's Avatar


Content Director
 
Join Date: Sep 2003
Posts: 5,375

Submissions (2)

Captain Griffen is a glorious beacon of light (497)Captain Griffen is a glorious beacon of light (497)Captain Griffen is a glorious beacon of light (497)Captain Griffen is a glorious beacon of light (497)Captain Griffen is a glorious beacon of light (497)

Approved Map: Warlords[Quicksilver #2] - 1st Place

Default

Quote:
Originally Posted by Rising_Dusk
I was discussing this with Griffen the other day. Unit Recycling isn't too wretchedly difficult, but I think it's entirely impossible to write one generalized and fully global script that would properly allow you to recycle units in any map. I think those sorts of things must be tailored heavily and specifically for the type of map in question.

Griffen was saying he wants to write one too, but I'm fairly certain it'll run into similar blockades.

I don't think it has to be tailored heavily, but all code would have to be tweaked (eg: with my code, all non-instant unit variables would have to be of type Unit, a value 'struct' holding the index and the life count). All on enter, train, summon, etc. code would have to go through a single system, and it would have to include a unit attachment system (or at least handle one).

It could be made generic, but it would require quite a bit of tweaking to other stuff. And certain stuff would be out (not sure about summoned units, but adding expiration timers? Can't be undone, that'd be out, etc.).
__________________
Quote:
Originally Posted by Earth-Fury
Griffen is correct, you are not.
Quote:
[13:32] <Akolyt0r> hmm.. stil i want to have some unused women
Captain Griffen is offline   Reply With Quote
Old 08-09-2008, 10:03 PM   #13
Captain Griffen
Dread Lord of the Cookies
 
Captain Griffen's Avatar


Content Director
 
Join Date: Sep 2003
Posts: 5,375

Submissions (2)

Captain Griffen is a glorious beacon of light (497)Captain Griffen is a glorious beacon of light (497)Captain Griffen is a glorious beacon of light (497)Captain Griffen is a glorious beacon of light (497)Captain Griffen is a glorious beacon of light (497)

Approved Map: Warlords[Quicksilver #2] - 1st Place

Default

Quote:
Originally Posted by Litany
Hm. Seems like it would be pretty simple using cache to create unit stacks as needed, but this of course assumes all abilities are triggered for the reasons Griff points out.

The stack is the easy part, and I'm fairly a linked list approach is faster than cache, but it's more limited with units...would depend on the map whether that limit would of 8191 would be a problem, unless you use big arrays, in which case cache starts to look much more attractive.

Quote:
Units just die when the timer expires, no?

Ooo, good point. I hadn't actually got to testing out how to do timer expiration (any my pc has broken, grr).

Quote:
The issue would be with unit types that don't decay/leave a corpse (which you could fake as part of the system anyway).

Indeed.
__________________
Quote:
Originally Posted by Earth-Fury
Griffen is correct, you are not.
Quote:
[13:32] <Akolyt0r> hmm.. stil i want to have some unused women
Captain Griffen is offline   Reply With Quote
Old 08-10-2008, 12:01 AM   #14
moyack
Evil Emoticon
 
moyack's Avatar


Respected User
Project Leader: PoC
 
Join Date: Jan 2006
Posts: 3,278

Submissions (17)

moyack is a splendid one to behold (666)moyack is a splendid one to behold (666)moyack is a splendid one to behold (666)moyack is a splendid one to behold (666)

AI Tournament #2 - 2nd PlaceHero Contest - Second place

Send a message via MSN to moyack
Default

Quote:
Originally Posted by Litany
The issue would be with unit types that don't decay/leave a corpse (which you could fake as part of the system anyway).
that's the problem, they die and are removed without option of being moved and revived. Besides, DioD did a good point, for example with the artillery missiles the units with corpses won't work, so your map must avoid unit explosions and such.... shit, too much variables to take into account.

So, in order to make it as more "universal" as possible, I should keep it as a script that squish as possible the units with corpses (if we think twice, most of the units in a AoS, melee, foties have decay bones), so it would be very useful.

Hey.... I was thinking this: other option is not to wait until the unit dies, but "pseudo killing" it if it gets 1 hitpoints or less.... but... it would look a little bit odd and damage detection will be mandatory.
moyack is offline   Reply With Quote
Old 08-10-2008, 02:15 AM   #15
moyack
Evil Emoticon
 
moyack's Avatar


Respected User
Project Leader: PoC
 
Join Date: Jan 2006
Posts: 3,278

Submissions (17)

moyack is a splendid one to behold (666)moyack is a splendid one to behold (666)moyack is a splendid one to behold (666)moyack is a splendid one to behold (666)

AI Tournament #2 - 2nd PlaceHero Contest - Second place

Send a message via MSN to moyack
Default

Quote:
Originally Posted by Litany
Dude. This is a Damage Detection System. Just catch the artillery kills, fake the explosion effect and recycle the units immediately. Ditto this for units that don't leave corpses.
The question: How to detect the damage type?? getting that info from a database?? because via an imaginary function GetDamageType(GetEventAttacker()) would depends of a Database...

Quote:
Incidentally, I wouldn't even bother deferring recycling to decay and such. When the unit dies, I'd throw it into the recycle queue immediately and spawn/kill a copy of the unit to provide all the corpse stuff. This should let you use a single setup to cover units whether they decay/leave corpses or not.
Hmmm, that's actaully a good idea! The only thing to test is how to revive a unit without a corpse.... unless.... I can add reincarnation in the dead event... I'll do the test right now.

Quote:
I think you're already saying what I just suggested. Why would it look odd exactly? And why shouldn't damage detection be mandatory?
mmm yes, I mean... the eyecandy when a unit dies.... but this could be fixed in some way...

Last edited by moyack : 08-10-2008 at 02:38 AM.
moyack is offline   Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off


All times are GMT. The time now is 07:03 AM.


Affiliates
The Hubb The JASS Vault Clan WEnW Campaign Creations Clan CBS GamesModding Flixreel Videos

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