| 11-12-2007, 08:04 AM | #1 |
I have a gamecache that will be storing each unit's current sight range. There is no function to get this, so I have made a few sight-range modifying functions that also enable the user to get the unit's current sight range. Obviously, this information will need to be reset for each unit so that the game doesn't think units have a different sight range than they actually do. The problem is that I want to clean the values stored in the gamecache when they won't be needed anymore and I've no idea how to do it. I thought of just detecting the "A unit dies" event and then just flushing the needed stuff then, but the problem of units being revived (through triggers or otherwise) arises. If the unit were to revive, the system wouldn't be able to determine the correct base value for the unit. What's the best way to devise a cleanup method? And by this I mean to ask when should I clean these values? Upon unit death? With a timer after unit death? Below is the code I have so far, the init is at the bottom. JASS:globals gamecache udg_SightRangeCache = null endglobals constant function SightRangeCache takes nothing returns gamecache return udg_SightRangeCache endfunction constant function SightRangeModifierAbility takes nothing returns integer return 'A000' endfunction function StoreDefaultSightRange takes integer unitId, integer defaultRange returns nothing call StoreInteger(SightRangeCache(), "Sight Range Defaults", I2S(unitId), defaultRange) endfunction function SetMapUnknownSightRange takes integer unknownRange returns nothing call StoreInteger(SightRangeCache(), "Sight Range Defaults", "Unknown", unknownRange) endfunction function SightRangeSetup takes nothing returns nothing call StoreDefaultSightRange('hfoo', 1400) call StoreDefualtSightRange('hrif', 1400) call StoreDefualtSightRange('hpea', 800) call StoreDefualtSightRange('uaob', 1400) call StoreDefualtSightRange('uaco', 800) call StoreDefualtSightRange('ufro', 1600) call StoreDefaultSightRange('u000', 425) call SetMapUnknownSightRange(1400) endfunction function SR_U2I takes unit whichUnit returns integer return whichUnit return 0 endfunction function GetUnitSightRange takes unit whichUnit returns integer return GetStoredInteger(SightRangeCache(), "Sight Range Currents", I2S(SR_U2I(whichUnit))) endfunction function ModifyUnitSightRange takes unit whichUnit, integer rangeModifier, boolean setFlag returns nothing local integer SRMId = SightRangeModifierAbility() local integer StoreRange = rangeModifier if setFlag then call UnitAddAbility(whichUnit, SRMId) call SetUnitAbilityLevel(whichUnit, SRMId, 10) call UnitRemoveAbility(whichUnit, SRMId) else set StoreRange = StoreRange+GetStoredInteger(SightRangeCache(), "Sight Range Currents", I2S(SR_U2I(whichUnit))) endif if StoreRange < 0 then set StoreRange = 0 endif call StoreInteger(SightRangeCache(), "Sight Range Currents", I2S(SR_U2I(whichUnit)), StoreRange) if rangeModifier > 0 then loop exitwhen rangeModifier<1000 call UnitAddAbility(whichUnit, SRMId) call SetUnitAbilityLevel(whichUnit, SRMId, 9) call UnitRemoveAbility(whichUnit, SRMId) set rangeModifier = rangeModifier-100 endloop loop exitwhen rangeModifier<100 call UnitAddAbility(whichUnit, SRMId) call SetUnitAbilityLevel(whichUnit, SRMId, 8) call UnitRemoveAbility(whichUnit, SRMId) set rangeModifier = rangeModifier-100 endloop loop exitwhen rangeModifier<10 call UnitAddAbility(whichUnit, SRMId) call SetUnitAbilityLevel(whichUnit, SRMId, 7) call UnitRemoveAbility(whichUnit, SRMId) set rangeModifier = rangeModifier-10 endloop loop exitwhen rangeModifier==0 call UnitAddAbility(whichUnit, SRMId) call SetUnitAbilityLevel(whichUnit, SRMId, 6) call UnitRemoveAbility(whichUnit, SRMId) set rangeModifier = rangeModifier-1 endloop else loop exitwhen rangeModifier>-1000 call UnitAddAbility(whichUnit, SRMId) call SetUnitAbilityLevel(whichUnit, SRMId, 8) call UnitRemoveAbility(whichUnit, SRMId) set rangeModifier = rangeModifier+100 endloop loop exitwhen rangeModifier>-100 call UnitAddAbility(whichUnit, SRMId) call SetUnitAbilityLevel(whichUnit, SRMId, 7) call UnitRemoveAbility(whichUnit, SRMId) set rangeModifier = rangeModifier+100 endloop loop exitwhen rangeModifier>-10 call UnitAddAbility(whichUnit, SRMId) call SetUnitAbilityLevel(whichUnit, SRMId, 6) call UnitRemoveAbility(whichUnit, SRMId) set rangeModifier = rangeModifier+10 endloop loop exitwhen rangeModifier==0 call UnitAddAbility(whichUnit, SRMId) call SetUnitAbilityLevel(whichUnit, SRMId, 5) call UnitRemoveAbility(whichUnit, SRMId) set rangeModifier = rangeModifier+1 endloop endif endfunction function SR_True takes nothing returns boolean return true endfunction function SR_Enter takes nothing returns nothing local unit U = GetTriggerUnit() local integer Range = GetStoredInteger(SightRangeCache(), "Sight Range Defaults", I2S(unitId)) if Range == 0 then set Range = GetStoredInteger(SightRangeCache(), "Sight Range Defaults", "Unknown") endif call StoreInteger(SightRangeCache(), "Sight Range Currents", I2S(SR_U2I(U)), Range) set U = null endfunction function SR_Init takes nothing returns nothing local trigger Enter = CreateTrigger() call TriggerRegisterEnterRegion(Enter, bj_mapInitialPlayableArea, Condition(function SR_True)) call TriggerAddAction(Enter, function SR_Enter) set Enter = null call SightRangeSetup() endfunction |
| 11-12-2007, 08:56 AM | #2 |
ok. clean ONLY in the first NEW storing. don't clean anything on death etc. you will create a new unit. and you will set a custom sight range. AND before you do this clean it up. hmmm but in this case you don't need to clean up. well it's your decision. // this allows you to resurrect unit etc. and not to lose data. and the ~10-30 mbs of memory no one cares. blizz default need more memory. (i mean try to play a melee and see how many memory is used ^^) |
| 11-12-2007, 08:59 AM | #3 |
There is a "unit decays" event. |
| 11-12-2007, 09:05 AM | #4 |
grim001 it does suck due if unit doesnt have a decay animation it will be skipped (and trigger will be not triggered). + corpses may be revived ^^ (decay event launches on decay begin) |
| 11-12-2007, 10:23 AM | #5 |
Ah, I hadn't thought of what Toadcop suggested, and I'll just do that. |
| 11-12-2007, 04:03 PM | #6 |
Will you share this with others as well (when you finish it of course), because I love bug-based systems. |
| 11-13-2007, 04:34 AM | #7 |
Yes, I'm planning on releasing my so-called "Sight Range Utilities". |
| 11-13-2007, 04:48 AM | #8 |
Kewl, thanks. ![]() |
