System Bonus

Discussion in 'Systems and Snippets' started by Nestharus, Jun 9, 2011.

  1. Nestharus

    Nestharus o-o

    Ratings:
    +83 / 0 / -0
    Known Issues
    Does not work properly with unit upgrades that change health/mana max. Your units will die when working with negative bonuses if their health/mana was modified by an upgrade. In fact, it's best to just do all upgrades through Bonus as there may be other bugs that I have not yet discovered.

    Lua Installation Scripts

    JASS:
    
    //! externalblock extension=lua FileExporter $FILENAME$
        //! runtextmacro LUA_FILE_HEADER()
        
        //BonusAbility v1.0.0.1
        //BonusJASS v1.0.0.0
        
        //! i writelua("BonusAbility", [======[
        //////////////////////////////////////////////////////////////////
        //code
        
        //! i abilities = {}
        //! i 
        //! i Ability = {}    --[[
        //! i -------------------------------------------------------------------------------------------------------
        //! i *
        //! i *   Fields
        //! i *   ---------------------------------------------------------------------------------------------------
        //! i *   *   ->  maxpower        |   maximum power of ability (in base 2)
        //! i *   *   ->  isperc          |   is percent
        //! i *   *   ->  abilityid       |   id of ability object
        //! i *   *   ->  field           |   id of ability field that gives data bonus
        //! i *   *   ->  name            |   name to assign to ability object
        //! i *   *   ->  ranged          |   the ability has a definite range
        //! i *   ---------------------------------------------------------------------------------------------------
        //! i *
        //! i *   Functions
        //! i *   ---------------------------------------------------------------------------------------------------
        //! i *   *   ->  function Ability.new(perc, abilityid, bonusfield, name, ranged, enabled) returns ability
        //! i *   ---------------------------------------------------------------------------------------------------
        //! i *
        //! i ------------------------------------------------------------------------------------------------------- ]]
        //! i local function genobjects(self)
        //! i     local function getmultiplier(power)
        //! i         --[[get multiplier value]]
        //! i         local multiplier
        //! i         
        //! i         multiplier = 1
        //! i         
        //! i         if (self.isperc) then
        //! i             multiplier = .01
        //! i         end
        //! i         
        //! i         --[[get multiplier sign]]
        //! i         if (self.ranged) then
        //! i             if (power == self.maxpower) then
        //! i                 multiplier = -multiplier
        //! i             end
        //! i         elseif (power == 0) then
        //! i             multiplier = 0
        //! i         elseif (power ~= self.maxpower + 1) then
        //! i             multiplier = -multiplier
        //! i         end
        //! i         
        //! i         return multiplier
        //! i     end
        //! i 
        //! i     ----------------------------------------------------------------------------
        //! i     --  CODE
        //! i     ----------------------------------------------------------------------------
        //! i         --[[generate objects]]
        //! i         if (self.ranged) then
        //! i             for power = 0, self.maxpower, 1 do
        //! i                 --[[create object]]
        //! i                 self.objects[power]=getvarobject(self.abilityid, "abilities","BONUS_" .. self.name .. "_" .. tostring(power), false)
        //! i                 self.abilities[power] = createobject(self.abilityid, self.objects[power])
        //! i                 
        //! i                 --[[set object name]]
        //! i                 makechange(self.abilities[power], "anam", "BONUS_" .. self.name .. "_" .. tostring(power))
        //! i                 
        //! i                 --[[set object bonus]]
        //! i                 makechange(current, self.field, 1, getmultiplier(power)*2^power)
        //! i             end
        //! i         else
        //! i             --[[create object]]
        //! i             self.objects[0] = getvarobject(self.abilityid, "abilities", "BONUS_" .. self.name, false)
        //! i             self.abilities[0] = createobject(self.abilityid, self.objects[0])
        //! i             makechange(self.abilities[0], "anam", "BONUS_" .. self.name .. "_" .. tostring(power))
        //! i             
        //! i             --[[Level 1: 0]]
        //! i             --[[Level Mid: Negative Power - 1]]
        //! i             --[[Level Max: Positive Power - 1]]
        //! i             makechange(current, "alev", self.maxpower + 2)
        //! i             
        //! i             --[[set object bonus]]
        //! i             for power = 0, self.maxpower + 2, 1 do
        //! i                 makechange(current, self.field, power + 1, getmultiplier(power)*2^(power - 1))
        //! i             end
        //! i         end
        //! i     ----------------------------------------------------------------------------
        //! i end
        //! i 
        //! i function Ability.new(perc, abilityid, bonusfield, name, ranged, enabled, maxpower)    --[[
        //! i -------------------------------------------------------------------------------------------------------
        //! i *   -> perc                 |   is ability value percent?
        //! i *   -> abilityid            |   base ability id 
        //! i *   -> bonusfield           |   field with value of ability
        //! i *   -> name                 |   name of ability
        //! i *   -> ranged               |   does ability have defined range
        //! i *   -> enabled              |   is ability enabled
        //! i *   -> maxpower             |   maximum power
        //! i ------------------------------------------------------------------------------------------------------- ]]
        //! i     local self = nil
        //! i     
        //! i     if (enabled) then
        //! i         self = {}
        //! i         
        //! i         --[[init fields]]
        //! i         self.objects = {}           	--> stores generated ability ids
        //! i         self.abilities = {}             --> stores generated ability objects
        //! i         self.maxpower = maxpower    	--> stores max power of 2 ability value can be
        //! i         self.isperc = perc          	--> does ability use a percent value?
        //! i         self.abilityid = abilityid  	--> base ability id
        //! i         self.field = bonusfield     	--> object field that modifies bonus value
        //! i         self.name = name            	--> ability name
        //! i         self.ranged = ranged        	--> ability has definite range
        //! i         
        //! i         --[[generate objects]]
        //! i         genobjects(self)
        //! i   	end
        //! i     
        //! i     table.insert(abilities,self)
        //! i     abilities = Ability.getvalid(abilities)                             --> filter out invalid abilities
        //! i     abilities.containslimited = Ability.limitedenabled(abilities)       --> determine if any abilities are limited
        //! i     abilities.containsunlimited = Ability.unlimitedenabled(abilities)   --> determines if any abilites are unlimited
        //! i     
        //! i     return self
        //! i end
        //! i 
        //! i function Ability.getvalid(abilities)
        //! i     local abilitylist = {}
        //! i     for id, ability in ipairs(abilities) do
        //! i         if (ability~=nil) then
        //! i             table.insert(abilitylist, ability)
        //! i         end
        //! i     end
        //! i     return abilitylist
        //! i end
        //! i 
        //! i function Ability.limitedenabled(abilities)
        //! i     for id, ability in ipairs(abilities) do
        //! i         if (ability.limited) then
        //! i             return true
        //! i         end
        //! i     end
        //! i     return false
        //! i end
        //! i function Ability.unlimitedenabled(abilities)
        //! i     for id, ability in ipairs(abilities) do
        //! i         if (ability.limited) then
        //! i             return true
        //! i         end
        //! i     end
        //! i     return false
        //! i end
        
        //end code
        //////////////////////////////////////////////////////////////////
        //! i ]======])
        
        
        //! i writelua("BonusJASS", [======[
        //////////////////////////////////////////////////////////////////
        //code
    
        //! i BonusJASS = { }
        //! i 
        //! i local POWER_MAX = "pm"      --> max power
        //! i local POWER_SET = "ps"      --> power set (2^0 to 2^POWER_MAX)
        //! i local OBJECT_ID = "bo"      --> object ids
        //! i local IS_RANGED = "ir"      --> is ranged
        //! i local BINARY_POWER = "bp"   --> power of 2
        //! i local CURRENT_BONUS = "cb"  --> current bonus of unit
        //! i 
        //! i local function getabilityids(abilities)
        //! i     local constants = ""
        //! i     local prefix
        //! i     local cur = 0
        //! i     
        //! i     for id, ability in ipairs(abilities) do
        //! i         constants = constants .. "constant integer BONUS_" .. ability.name .. "=" .. tostring(cur) .. "\n"
        //! i         cur = cur + ability.maxpower + 1
        //! i         if (not ability.ranged) then
        //! i             cur = cur + 1
        //! i         end
        //! i     end
        //! i     
        //! i     return constants
        //! i end
        //! i 
        //! i local function getisranged(abilities)
        //! i     local isranged = ""
        //! i     local cur = 0
        //! i     
        //! i     for id, ability in ipairs(abilities) do
        //! i         if (ability.ranged) then
        //! i             isranged = isranged .. "set " .. IS_RANGED .. "[" .. tostring(cur) .. "]=true\n"
        //! i         else
        //! i             isranged = isranged .. "set " .. IS_RANGED .. "[" .. tostring(cur) .. "]=false\n"
        //! i             cur = cur + 1
        //! i         end
        //! i         cur = cur + ability.maxpower + 1
        //! i     end
        //! i     
        //! i     return isranged
        //! i end
        //! i 
        //! i local function getpowermax(abilities)
        //! i     local powermax = ""
        //! i     local cur = 0
        //! i     
        //! i     for id, ability in ipairs(abilities) do
        //! i         powermax = powermax .. "set " .. POWER_MAX .. "[" .. tostring(cur) .. "]=" .. tostring(ability.maxpower) .. "\n"
        //! i         cur = cur + ability.maxpower + 1
        //! i         if (not ability.ranged) then
        //! i             cur = cur + 1
        //! i         end
        //! i     end
        //! i     
        //! i     return powermax
        //! i end
        //! i 
        //! i local function getpowerset(abilities)
        //! i     local powerset = ""
        //! i     local index = 0
        //! i     for id, ability in ipairs(abilities) do
        //! i         if (ability.ranged) then
        //! i             for power = 0, ability.maxpower - 1, 1 do
        //! i                 powerset = powerset .. "set " .. POWER_SET .. "[" .. tostring(index) .. "]=" .. tostring((2^power)) .. "\n"
        //! i                 powerset = powerset .. "set " .. BINARY_POWER .. "[" .. tostring(index) .. "]=" .. tostring(power) .. "\n"
        //! i                 index = index + 1
        //! i             end
        //! i         else
        //! i             powerset = powerset .. "set " .. POWER_SET .. "[" .. tostring(index) .. "]=" .. tostring(0) .. "\n"
        //! i             index = index + 1
        //! i             for power = 0, ability.maxpower - 1, 1 do
        //! i                 powerset = powerset .. "set " .. POWER_SET .. "[" .. tostring(index) .. "]=" .. tostring((2^power)) .. "\n"
        //! i                 powerset = powerset .. "set " .. BINARY_POWER .. "[" .. tostring(index) .. "]=" .. tostring(power) .. "\n"
        //! i                 index = index + 1
        //! i             end
        //! i         end
        //! i         powerset = powerset .. "set " .. POWER_SET .. "[" .. tostring(index) .. "]=" .. tostring(-(2^ability.maxpower)) .. "\n"
        //! i         powerset = powerset .. "set " .. BINARY_POWER .. "[" .. tostring(index) .. "]=" .. tostring(-ability.maxpower) .. "\n"
        //! i         index = index + 1
        //! i     end
        //! i     return powerset
        //! i end
        //! i 
        //! i local function getobjectids(abilities)
        //! i     local powerset = ""
        //! i     local index = 0
        //! i     for id, ability in ipairs(abilities) do
        //! i         if (ability.ranged) then
        //! i             for power = 0, ability.maxpower, 1 do
        //! i                 powerset = powerset .. "set " .. OBJECT_ID .. "[" .. tostring(index) .. "]='" .. ability.objects[power] .. "'\/\/" .. tostring(power) .. "\n"
        //! i                 index = index + 1
        //! i             end
        //! i         else
        //! i             powerset = powerset .. "set " .. OBJECT_ID .. "[" .. tostring(index) .. "]='" .. ability.objects[0] .. "'\n"
        //! i             index = index + 2 + ability.maxpower
        //! i         end
        //! i     end
        //! i     return powerset
        //! i end
        //! i 
        //! i local function getpreload(abilities)
        //! i     local preload=""
        //! i     for id, ability in ipairs(abilities) do
        //! i         if (ability.ranged) then
        //! i             for power = 0, ability.maxpower, 1 do
        //! i                 preload = preload .. "call UnitAddAbility(u,'" .. ability.objects[power] .. "')\n"
        //! i             end
        //! i         else
        //! i             preload = preload .. "call UnitAddAbility(u,'" .. ability.objects[0] .. "')\n"
        //! i         end
        //! i     end
        //! i     return preload
        //! i end
        //! i 
        //! i function BonusJASS.get(abilities)
        //! i     local beginglobals = "globals\n"
        //! i         local powermax = "private integer array " .. POWER_MAX .. "\n"
        //! i         local powerset = "private integer array " .. POWER_SET .. "\n"
        //! i         local binarypower = "private integer array " .. BINARY_POWER .. "\n"
        //! i         local objectid = "private integer array " .. OBJECT_ID .. "\n"
        //! i         local isranged = "private boolean array " .. IS_RANGED .. "\n"
        //! i         local currentbonus = "private Table array " .. CURRENT_BONUS .. "\n"
        //! i         local abilityids = getabilityids(abilities)
        //! i     local endglobals = "endglobals\n"
        //! i     
        //! i     local begininit = "private module I\nprivate static method onInit takes nothing returns nothing\n"
        //! i         local preloadif = "static if PRELOAD then\n"
        //! i         local preloadend = "endif\n"
        //! i         local preload = "local unit u\nset UnitIndexer.enabled=false\nset u = CreateUnit(Player(14),'hpea',0,0,0)\n" .. getpreload(abilities) .. "call RemoveUnit(u)\nset u = null\nset UnitIndexer.enabled=true\n"
        //! i         local index = "call RegisterUnitIndexEvent(Condition(function thistype.index), UnitIndexer.INDEX)\n"
        //! i         local deindex = "call RegisterUnitIndexEvent(Condition(function thistype.deindex), UnitIndexer.DEINDEX)\n"
        //! i         local objectids = getobjectids(abilities)   --> actual object ids of abilities for UnitAddAbility
        //! i         local powermaxes = getpowermax(abilities)   --> max power (from config)
        //! i         local powersets = getpowerset(abilities)    --> power set: 1, 2, 4, 8, -16 etc
        //! i         local israngeds = getisranged(abilities)    --> is ability ranged or not
        //! i     local endinit = "endmethod\nendmodule\n"
        //! i     
        //! i     local beginstruct = "private struct O extends array\n"
        //! i         local beginindex = "private static method index takes nothing returns boolean\n"
        //! i             local indexcode =
        //! i             [[set cb[GetIndexedUnitId()] = Table.create()]] .. "\n"
        //! i         local endindex = "return false\nendmethod\n"
        //! i         local begindeindex = "private static method deindex takes nothing returns boolean\n"
        //! i             local deindexcode =
        //! i             [[call cb[GetIndexedUnitId()].destroy()]] .. "\n"
        //! i         local enddeindex = "return false\nendmethod\n"
        //! i     local endstruct = "implement I\nendstruct\n"
        //! i     
        //! i     local jass = ""
        //! i     
        //! i     jass = jass .. [[//! textmacro BONUS_SCRIPT]] .. "\n"
        //! i         jass = jass .. beginglobals
        //! i             jass = jass .. powermax
        //! i             jass = jass .. powerset
        //! i             jass = jass .. binarypower
        //! i             jass = jass .. objectid
        //! i             jass = jass .. isranged
        //! i             jass = jass .. currentbonus
        //! i             jass = jass .. abilityids
        //! i         jass = jass .. endglobals
        //! i         
        //! i         jass = jass .. begininit
        //! i             jass = jass .. preloadif
        //! i                 jass = jass .. preload
        //! i             jass = jass .. preloadend
        //! i             jass = jass .. index
        //! i             jass = jass .. deindex
        //! i             jass = jass .. objectids
        //! i             jass = jass .. powermaxes
        //! i             jass = jass .. powersets
        //! i             jass = jass .. israngeds
        //! i         jass = jass .. endinit
        //! i         
        //! i         jass = jass .. beginstruct
        //! i             jass = jass .. beginindex
        //! i                 jass = jass .. indexcode
        //! i             jass = jass .. endindex
        //! i             jass = jass .. begindeindex
        //! i                 jass = jass .. deindexcode
        //! i             jass = jass .. enddeindex
        //! i         jass = jass .. endstruct
        //! i     jass = jass .. [[//! endtextmacro]] .. "\n"
        //! i     
        //! i     return jass
        //! i end
    
        //end code
        //////////////////////////////////////////////////////////////////
        //! i ]======])
    //! endexternalblock


    Initialization Script

    LUA_GET_VAR_OBJECT

    This script can be used to create new bonuses, just be sure to add them to this script rather than generating them solo, or your map will only have that single generated bonus.
    JASS:
    
    /****************************************************************************************
    *                                                                                       *
    *                               Ranged Bonus Power                                      *
    *                                                                                       *
    *   Power determines how big a bonus range can go. For example, a power of 15 would be  *
    *   -(2^16) to 2^(16)-1 or -65536 to 65535.                                            *
    *                                                                                       *
    *****************************************************************************************
    *                                                                                       *
    *                               Unlimited Bonus Power                                   *
    *                                                                                       *
    *   Power for unlimited bonuses increases speed of add/remove for larger values         *
    *   and makes larger values easier to get to. For example, 50,000,000 is much           *
    *   faster adding units of 1,048,576 than adding units of 16. In units of 16,           *
    *   50,000,000 might as well be impossible to get to.                                   *
    *                                                                                       *
    *****************************************************************************************
    *                                                                                       *
    *                               ENABLED                                                 *
    *                                                                                       *
    *   Should the bonus be implemented into the system? By disabling a bonus, it will not  *
    *   be in the system at all. Abilities and constants won't be made.                     *
    *                                                                                       *
    ****************************************************************************************/
    //! textmacro BONUS_CREATE_BONUSES
        /********************
        *                   *
        *   ability data    *
        *                   *
        ********************/
        //                perc          abil        field       name                    ranged 	        enabled	      max power
        //! i Ability.new(false,        "AId1",     "Idef",     "ARMOR",                true,  	        true,	        12)	        --> armor
        //! i Ability.new(false,        "AItg",     "Iatt",     "DAMAGE",               true,  	        true,	        15)	        --> damage
        //! i Ability.new(false,        "AIa1",     "Iagi",     "AGILITY",              true,  	        true,	        13)	        --> agility
        //! i Ability.new(false,        "AIs1",     "Istr",     "STRENGTH",             true,  	        true,	        13)	        --> strength
        //! i Ability.new(false,        "AIi1",     "Iint",     "INTELLIGENCE",         true,  	        true,	        13)	        --> intelligence
        //! i Ability.new(false,        "AIlf",     "Ilif",     "LIFE",                 false, 	        true,	        17)	        --> life
        //! i Ability.new(false,        "Arel",     "Ihpr",     "LIFE_REGEN",           true,  	        true,	        15)	        --> life regen
        //! i Ability.new(false,        "AImb",     "Iman",     "MANA",                 false, 	        true,	        17)	        --> mana
        //! i Ability.new(true,         "AIrm",     "Imrp",     "MANA_REGEN",           true,  	        true,	        8)	         --> mana regen, 8 max
        //! i Ability.new(false,        "AIsi",     "Isib",     "SIGHT",                true,  	        true,	        10)	        --> sight, 10 max
        //! i Ability.new(true,         "AIsx",     "Isx1",     "ATTACK_SPEED",         true,  	        true,	        8)	         --> attack speed, 8 max
    //! endtextmacro
    
    /********************
    *                   *
    *       code        *
    *                   *
    ********************/
    //! externalblock extension=lua ObjectMerger $FILENAME$
    //! runtextmacro LUA_FILE_HEADER()
    //! i dofile("GetVarObject")
    //! i dofile("BonusAbility")
    //! i dofile("BonusJASS")
    //! runtextmacro BONUS_CREATE_BONUSES()
    //! i local jass = BonusJASS.get(abilities)
    //! i writejass("BONUS",jass)
    //! i updateobjects()
    //! endexternalblock


    System Code

    JASS:
    
    library Bonus /* v2.0.0.2
    *************************************************************************************
    *
    *   Adds bonuses to units. In the ini area, these bonuses can be enabled and disabled.
    *   Ranges of bonus values can also be modified.
    *
    *   Bonuses
    *       -   Armor                   any unit                        non percent bonus
    *       -   Damage                  units with attack only          non percent bonus
    *       -   Agility                 hero only                       non percent bonus
    *       -   Strength                hero only                       non percent bonus
    *       -   Intelligence            hero only                       non percent bonus
    *       -   Life                    any unit                        non percent bonus
    *       -   Life Regeneration       any unit                        non percent bonus
    *       -   Mana                    any unit                        non percent bonus
    *       -   Mana Regeneration       units with mana only            percent bonus
    *       -   Sight Range             any unit                        non percent bonus
    *       -   Attack Speed            units with attack only          percent bonus
    *
    *************************************************************************************
    *
    *   */uses/*
    *       */ UnitIndexer /*       hiveworkshop.com/forums/jass-resources-412/system-unit-indexer-172090/
    *       */ Table /*             hiveworkshop.com/forums/jass-resources-412/snippet-new-table-188084/
    *
    ************************************************************************************
    *   SETTINGS
    */
    globals
        /*************************************************************************************
        *
        *                                   PRELOAD
        *
        *   Preloads all bonus abilities. This will add a hefty load time to the map but will
        *   prevent lag in game.
        *
        *************************************************************************************/
        private constant boolean PRELOAD = false
    endglobals
    /*
    *************************************************************************************
    *
    *   Bonuses
    *
    *       constant integer BONUS_ARMOR
    *       constant integer BONUS_DAMAGE
    *       constant integer BONUS_AGILITY
    *       constant integer BONUS_STRENGTH
    *       constant integer BONUS_INTELLIGENCE
    *       constant integer BONUS_LIFE
    *       constant integer BONUS_LIFE_REGEN
    *       constant integer BONUS_MANA
    *       constant integer BONUS_MANA_REGEN
    *       constant integer BONUS_ATTACK_SPEED
    *       constant integer BONUS_SIGHT
    *
    *   Functions
    *
    *       function GetUnitBonus takes unit whichUnit, integer whichBonus returns integer
    *       function SetUnitBonus takes unit whichUnit, integer whichBonus, integer value returns nothing
    *       function AddUnitBonus takes unit whichUnit, integer whichBonus, integer value returns nothing
    *
    ************************************************************************************/
        //! runtextmacro BONUS_SCRIPT()
        function SetUnitBonus takes unit u, integer b, integer v returns nothing
            local boolean n
            local integer a
            local integer p
            local integer on
            local integer i
            local integer nch
            local integer nb
            debug if (not IsUnitIndexed(u)) then
                debug call DisplayTimedTextToPlayer(GetLocalPlayer(), 0, 0, 60, "UNIT BONUS ERROR: INVALID UNIT")
                debug return
            debug endif
            debug if (0==pm[b]) then
                debug call DisplayTimedTextToPlayer(GetLocalPlayer(), 0, 0, 60, "UNIT BONUS ERROR: INVALID BONUS TYPE")
                debug return
            debug endif
            set i=GetUnitUserData(u)
            if (v != cb[i][b]) then
                set nch=0
                if (ir[b]) then
                    set n=0>v
                    set cb[i][b]=v
                    set p=b+pm[b]-1
                    set on=p+1
                    call UnitRemoveAbility(u,bo[on])
                    if (n) then
                        set v=v-ps[on]
                    endif
                    loop
                        if (0>v-ps[p]) then
                            call UnitRemoveAbility(u,bo[p])
                        else
                            call UnitAddAbility(u,bo[p])
                            call UnitMakeAbilityPermanent(u,true,bo[p])
                            set v=v-ps[p]
                        endif
                        exitwhen p==b
                        set p=p-1
                    endloop
                    if (n) then
                        call UnitAddAbility(u,bo[on])
                        call UnitMakeAbilityPermanent(u,true,bo[on])
                    endif
                else
                    set nb=v
                    set v=v-cb[i][b]
                    set cb[i][b]=nb
                    set a=bo[b]
                    set on=b+pm[b]+1
                    loop
                        loop
                            exitwhen 0<v
                            set v=v-ps[on]
                            set nch=nch+1
                        endloop
                        set p=b+pm[b]
                        loop
                            if (0<=v-ps[p]) then
                                set v=v-ps[p]
                                call UnitAddAbility(u,a)
                                call SetUnitAbilityLevel(u,a,bp[p]+2)
                                call UnitRemoveAbility(u,a)
                            else
                                set p=p-1
                                exitwhen p==b
                            endif
                        endloop
                        exitwhen 0==v
                    endloop
                    loop
                        exitwhen 0==nch
                        set nch=nch-1
                        call UnitAddAbility(u,a)
                        call SetUnitAbilityLevel(u,a,(-bp[on])+2)
                        call UnitRemoveAbility(u,a)
                    endloop
                endif
            endif
        endfunction
        function GetUnitBonus takes unit u, integer b returns integer
            return cb[GetUnitUserData(u)][b]
        endfunction
        function AddUnitBonus takes unit u, integer b, integer v returns nothing
            call SetUnitBonus(u,b,GetUnitBonus(u,b)+v)
        endfunction
    endlibrary

     
    • Like Like x 1
  2. Nestharus

    Nestharus o-o

    Ratings:
    +83 / 0 / -0
    Updated =)

    Quite a bit better if I do say so myself ; P


    And here is a look at ini script (generated)

    And jass tags have a bug >: O. Scroll down a little and you shall see o_O
    JASS:
    
    //! textmacro BONUS_DATA
    globals
    private integer array bd
    private integer array bp
    private integer array pw
    private integer array pm
    constant integer BONUS_ARMOR=0
    constant integer BONUS_DAMAGE=15
    constant integer BONUS_AGILITY=33
    constant integer BONUS_STRENGTH=49
    constant integer BONUS_INTELLIGENCE=65
    constant integer BONUS_LIFE=81
    constant integer BONUS_LIFE_REGEN=103
    constant integer BONUS_MANA=121
    constant integer BONUS_MANA_REGEN=143
    constant integer BONUS_SIGHT=154
    constant integer BONUS_ATTACK_SPEED=167
    endglobals
    private module I
    private static method onInit takes nothing returns nothing
    static if PRELOAD then
    local unit u = CreateUnit(Player(14),'hpea',100000,100000,0)
    call UnitAddAbility(u,'A!(@')
    call UnitAddAbility(u,'A!([')
    call UnitAddAbility(u,'A!(]')
    call UnitAddAbility(u,'A!(^')
    call UnitAddAbility(u,'A!(_')
    call UnitAddAbility(u,'A!({')
    call UnitAddAbility(u,'A!(|')
    call UnitAddAbility(u,'A!(}')
    call UnitAddAbility(u,'A!(~')
    call UnitAddAbility(u,'A!)!')
    call UnitAddAbility(u,'A!)"')
    call UnitAddAbility(u,'A!)#')
    call UnitAddAbility(u,'A!)$')
    call UnitAddAbility(u,'A!)%')
    call UnitAddAbility(u,'A!)&')
    call UnitAddAbility(u,'A!)(')
    call UnitAddAbility(u,'A!))')
    call UnitAddAbility(u,'A!)*')
    call UnitAddAbility(u,'A!)+')
    call UnitAddAbility(u,'A!)-')
    call UnitAddAbility(u,'A!).')
    call UnitAddAbility(u,'A!):')
    call UnitAddAbility(u,'A!);')
    call UnitAddAbility(u,'A!)<')
    call UnitAddAbility(u,'A!)=')
    call UnitAddAbility(u,'A!)>')
    call UnitAddAbility(u,'A!)?')
    call UnitAddAbility(u,'A!)@')
    call UnitAddAbility(u,'A!)[')
    call UnitAddAbility(u,'A!)]')
    call UnitAddAbility(u,'A!)^')
    call UnitAddAbility(u,'A!)_')
    call UnitAddAbility(u,'A!){')
    call UnitAddAbility(u,'A!)|')
    call UnitAddAbility(u,'A!)}')
    call UnitAddAbility(u,'A!)~')
    call UnitAddAbility(u,'A!*!')
    call UnitAddAbility(u,'A!*"')
    call UnitAddAbility(u,'A!*#')
    call UnitAddAbility(u,'A!*$')
    call UnitAddAbility(u,'A!*%')
    call UnitAddAbility(u,'A!*&')
    call UnitAddAbility(u,'A!*(')
    call UnitAddAbility(u,'A!*)')
    call UnitAddAbility(u,'A!**')
    call UnitAddAbility(u,'A!*+')
    call UnitAddAbility(u,'A!*-')
    call UnitAddAbility(u,'A!*.')
    call UnitAddAbility(u,'A!*:')
    call UnitAddAbility(u,'A!*;')
    call UnitAddAbility(u,'A!*<')
    call UnitAddAbility(u,'A!*=')
    call UnitAddAbility(u,'A!*>')
    call UnitAddAbility(u,'A!*?')
    call UnitAddAbility(u,'A!*@')
    call UnitAddAbility(u,'A!*[')
    call UnitAddAbility(u,'A!*]')
    call UnitAddAbility(u,'A!*^')
    call UnitAddAbility(u,'A!*_')
    call UnitAddAbility(u,'A!*{')
    call UnitAddAbility(u,'A!*|')
    call UnitAddAbility(u,'A!*}')
    call UnitAddAbility(u,'A!*~')
    call UnitAddAbility(u,'A!+!')
    call UnitAddAbility(u,'A!+"')
    call UnitAddAbility(u,'A!+#')
    call UnitAddAbility(u,'A!+$')
    call UnitAddAbility(u,'A!+%')
    call UnitAddAbility(u,'A!+&')
    call UnitAddAbility(u,'A!+(')
    call UnitAddAbility(u,'A!+)')
    call UnitAddAbility(u,'A!+*')
    call UnitAddAbility(u,'A!++')
    call UnitAddAbility(u,'A!+-')
    call UnitAddAbility(u,'A!+.')
    call UnitAddAbility(u,'A!+:')
    call UnitAddAbility(u,'A!+;')
    call UnitAddAbility(u,'A!+<')
    call UnitAddAbility(u,'A!+=')
    call UnitAddAbility(u,'A!+>')
    call UnitAddAbility(u,'A!+?')
    call UnitAddAbility(u,'A!+@')
    call UnitAddAbility(u,'A!+[')
    call UnitAddAbility(u,'A!+]')
    call UnitAddAbility(u,'A!+^')
    call UnitAddAbility(u,'A!+_')
    call UnitAddAbility(u,'A!+{')
    call UnitAddAbility(u,'A!+|')
    call UnitAddAbility(u,'A!+}')
    call UnitAddAbility(u,'A!+~')
    call UnitAddAbility(u,'A!-!')
    call UnitAddAbility(u,'A!-"')
    call UnitAddAbility(u,'A!-#')
    call UnitAddAbility(u,'A!-$')
    call UnitAddAbility(u,'A!-%')
    call UnitAddAbility(u,'A!-&')
    call UnitAddAbility(u,'A!-(')
    call UnitAddAbility(u,'A!-)')
    call UnitAddAbility(u,'A!-*')
    call UnitAddAbility(u,'A!-+')
    call UnitAddAbility(u,'A!--')
    call UnitAddAbility(u,'A!-.')
    call UnitAddAbility(u,'A!-:')
    call UnitAddAbility(u,'A!-;')
    call UnitAddAbility(u,'A!-<')
    call UnitAddAbility(u,'A!-=')
    call UnitAddAbility(u,'A!->')
    call UnitAddAbility(u,'A!-?')
    call UnitAddAbility(u,'A!-@')
    call UnitAddAbility(u,'A!-[')
    call UnitAddAbility(u,'A!-]')
    call UnitAddAbility(u,'A!-^')
    call UnitAddAbility(u,'A!-_')
    call UnitAddAbility(u,'A!-{')
    call UnitAddAbility(u,'A!-|')
    call UnitAddAbility(u,'A!-}')
    call UnitAddAbility(u,'A!-~')
    call UnitAddAbility(u,'A!.!')
    call UnitAddAbility(u,'A!."')
    call UnitAddAbility(u,'A!.#')
    call UnitAddAbility(u,'A!.$')
    call UnitAddAbility(u,'A!.%')
    call UnitAddAbility(u,'A!.&')
    call UnitAddAbility(u,'A!.(')
    call UnitAddAbility(u,'A!.)')
    call UnitAddAbility(u,'A!.*')
    call UnitAddAbility(u,'A!.+')
    call UnitAddAbility(u,'A!.-')
    call UnitAddAbility(u,'A!..')
    call UnitAddAbility(u,'A!.:')
    call UnitAddAbility(u,'A!.;')
    call UnitAddAbility(u,'A!.<')
    call UnitAddAbility(u,'A!.=')
    call UnitAddAbility(u,'A!.>')
    call UnitAddAbility(u,'A!.?')
    call UnitAddAbility(u,'A!.@')
    call UnitAddAbility(u,'A!.[')
    call UnitAddAbility(u,'A!.]')
    call UnitAddAbility(u,'A!.^')
    call UnitAddAbility(u,'A!._')
    call UnitAddAbility(u,'A!.{')
    call UnitAddAbility(u,'A!.|')
    call UnitAddAbility(u,'A!.}')
    call UnitAddAbility(u,'A!.~')
    call UnitAddAbility(u,'A!:!')
    call UnitAddAbility(u,'A!:"')
    call UnitAddAbility(u,'A!:#')
    call UnitAddAbility(u,'A!:$')
    call UnitAddAbility(u,'A!:%')
    call UnitAddAbility(u,'A!:&')
    call UnitAddAbility(u,'A!:(')
    call UnitAddAbility(u,'A!:)')
    call UnitAddAbility(u,'A!:*')
    call UnitAddAbility(u,'A!:+')
    call UnitAddAbility(u,'A!:-')
    call UnitAddAbility(u,'A!:.')
    call UnitAddAbility(u,'A!::')
    call UnitAddAbility(u,'A!:;')
    call UnitAddAbility(u,'A!:<')
    call UnitAddAbility(u,'A!:=')
    call UnitAddAbility(u,'A!:>')
    call UnitAddAbility(u,'A!:?')
    call UnitAddAbility(u,'A!:@')
    call UnitAddAbility(u,'A!:[')
    call UnitAddAbility(u,'A!:]')
    call UnitAddAbility(u,'A!:^')
    call UnitAddAbility(u,'A!:_')
    call UnitAddAbility(u,'A!:{')
    call UnitAddAbility(u,'A!:|')
    call UnitAddAbility(u,'A!:}')
    call UnitAddAbility(u,'A!:~')
    call UnitAddAbility(u,'A!;!')
    call UnitAddAbility(u,'A!;"')
    call UnitAddAbility(u,'A!;#')
    call UnitAddAbility(u,'A!;$')
    call UnitAddAbility(u,'A!;%')
    call UnitAddAbility(u,'A!;&')
    call UnitAddAbility(u,'A!;(')
    call RemoveUnit(u)
    set u = null
    endif
    set bd[0]='A!(@'
    set bd[1]='A!(['
    set bd[2]='A!(]'
    set bd[3]='A!(^'
    set bd[4]='A!(_'
    set bd[5]='A!({'
    set bd[6]='A!(|'
    set bd[7]='A!(}'
    set bd[8]='A!(~'
    set bd[9]='A!)!'
    set bd[10]='A!)"'
    set bd[11]='A!)#'
    set bd[12]='A!)$'
    set bd[13]='A!)%'
    set bd[14]='A!)&'
    set bd[15]='A!)('
    set bd[16]='A!))'
    set bd[17]='A!)*'
    set bd[18]='A!)+'
    set bd[19]='A!)-'
    set bd[20]='A!).'
    set bd[21]='A!):'
    set bd[22]='A!);'
    set bd[23]='A!)<'
    set bd[24]='A!)='
    set bd[25]='A!)>'
    set bd[26]='A!)?'
    set bd[27]='A!)@'
    set bd[28]='A!)['
    set bd[29]='A!)]'
    set bd[30]='A!)^'
    set bd[31]='A!)_'
    set bd[32]='A!){'
    set bd[33]='A!)|'
    set bd[34]='A!)}'
    set bd[35]='A!)~'
    set bd[36]='A!*!'
    set bd[37]='A!*"'
    set bd[38]='A!*#'
    set bd[39]='A!*$'
    set bd[40]='A!*%'
    set bd[41]='A!*&'
    set bd[42]='A!*('
    set bd[43]='A!*)'
    set bd[44]='A!**'
    set bd[45]='A!*+'
    set bd[46]='A!*-'
    set bd[47]='A!*.'
    set bd[48]='A!*:'
    set bd[49]='A!*;'
    set bd[50]='A!*<'
    set bd[51]='A!*='
    set bd[52]='A!*>'
    set bd[53]='A!*?'
    set bd[54]='A!*@'
    set bd[55]='A!*['
    set bd[56]='A!*]'
    set bd[57]='A!*^'
    set bd[58]='A!*_'
    set bd[59]='A!*{'
    set bd[60]='A!*|'
    set bd[61]='A!*}'
    set bd[62]='A!*~'
    set bd[63]='A!+!'
    set bd[64]='A!+"'
    set bd[65]='A!+#'
    set bd[66]='A!+$'
    set bd[67]='A!+%'
    set bd[68]='A!+&'
    set bd[69]='A!+('
    set bd[70]='A!+)'
    set bd[71]='A!+*'
    set bd[72]='A!++'
    set bd[73]='A!+-'
    set bd[74]='A!+.'
    set bd[75]='A!+:'
    set bd[76]='A!+;'
    set bd[77]='A!+<'
    set bd[78]='A!+='
    set bd[79]='A!+>'
    set bd[80]='A!+?'
    set bd[81]='A!+@'
    set bd[82]='A!+['
    set bd[83]='A!+]'
    set bd[84]='A!+^'
    set bd[85]='A!+_'
    set bd[86]='A!+{'
    set bd[87]='A!+|'
    set bd[88]='A!+}'
    set bd[89]='A!+~'
    set bd[90]='A!-!'
    set bd[91]='A!-"'
    set bd[92]='A!-#'
    set bd[93]='A!-$'
    set bd[94]='A!-%'
    set bd[95]='A!-&'
    set bd[96]='A!-('
    set bd[97]='A!-)'
    set bd[98]='A!-*'
    set bd[99]='A!-+'
    set bd[100]='A!--'
    set bd[101]='A!-.'
    set bd[102]='A!-:'
    set bd[103]='A!-;'
    set bd[104]='A!-<'
    set bd[105]='A!-='
    set bd[106]='A!->'
    set bd[107]='A!-?'
    set bd[108]='A!-@'
    set bd[109]='A!-['
    set bd[110]='A!-]'
    set bd[111]='A!-^'
    set bd[112]='A!-_'
    set bd[113]='A!-{'
    set bd[114]='A!-|'
    set bd[115]='A!-}'
    set bd[116]='A!-~'
    set bd[117]='A!.!'
    set bd[118]='A!."'
    set bd[119]='A!.#'
    set bd[120]='A!.$'
    set bd[121]='A!.%'
    set bd[122]='A!.&'
    set bd[123]='A!.('
    set bd[124]='A!.)'
    set bd[125]='A!.*'
    set bd[126]='A!.+'
    set bd[127]='A!.-'
    set bd[128]='A!..'
    set bd[129]='A!.:'
    set bd[130]='A!.;'
    set bd[131]='A!.<'
    set bd[132]='A!.='
    set bd[133]='A!.>'
    set bd[134]='A!.?'
    set bd[135]='A!.@'
    set bd[136]='A!.['
    set bd[137]='A!.]'
    set bd[138]='A!.^'
    set bd[139]='A!._'
    set bd[140]='A!.{'
    set bd[141]='A!.|'
    set bd[142]='A!.}'
    set bd[143]='A!.~'
    set bd[144]='A!:!'
    set bd[145]='A!:"'
    set bd[146]='A!:#'
    set bd[147]='A!:$'
    set bd[148]='A!:%'
    set bd[149]='A!:&'
    set bd[150]='A!:('
    set bd[151]='A!:)'
    set bd[152]='A!:*'
    set bd[153]='A!:+'
    set bd[154]='A!:-'
    set bd[155]='A!:.'
    set bd[156]='A!::'
    set bd[157]='A!:;'
    set bd[158]='A!:<'
    set bd[159]='A!:='
    set bd[160]='A!:>'
    set bd[161]='A!:?'
    set bd[162]='A!:@'
    set bd[163]='A!:['
    set bd[164]='A!:]'
    set bd[165]='A!:^'
    set bd[166]='A!:_'
    set bd[167]='A!:{'
    set bd[168]='A!:|'
    set bd[169]='A!:}'
    set bd[170]='A!:~'
    set bd[171]='A!;!'
    set bd[172]='A!;"'
    set bd[173]='A!;#'
    set bd[174]='A!;$'
    set bd[175]='A!;%'
    set bd[176]='A!;&'
    set bd[177]='A!;('
    set pm[0]=14
    set pm[15]=17
    set pm[33]=15
    set pm[49]=15
    set pm[65]=15
    set pm[81]=21
    set pm[103]=17
    set pm[121]=21
    set pm[143]=10
    set pm[154]=12
    set pm[167]=10
    set bp[0]=8192
    set bp[15]=65536
    set bp[33]=16384
    set bp[49]=16384
    set bp[65]=16384
    set bp[81]=1048576
    set bp[103]=65536
    set bp[121]=1048576
    set bp[143]=512
    set bp[154]=2048
    set bp[167]=512
    set pw[0]=1
    set pw[1]=2
    set pw[2]=4
    set pw[3]=8
    set pw[4]=16
    set pw[5]=32
    set pw[6]=64
    set pw[7]=128
    set pw[8]=256
    set pw[9]=512
    set pw[10]=1024
    set pw[11]=2048
    set pw[12]=4096
    set pw[13]=8192
    set pw[14]=-8192
    set pw[15]=1
    set pw[16]=2
    set pw[17]=4
    set pw[18]=8
    set pw[19]=16
    set pw[20]=32
    set pw[21]=64
    set pw[22]=128
    set pw[23]=256
    set pw[24]=512
    set pw[25]=1024
    set pw[26]=2048
    set pw[27]=4096
    set pw[28]=8192
    set pw[29]=16384
    set pw[30]=32768
    set pw[31]=65536
    set pw[32]=-65536
    set pw[33]=1
    set pw[34]=2
    set pw[35]=4
    set pw[36]=8
    set pw[37]=16
    set pw[38]=32
    set pw[39]=64
    set pw[40]=128
    set pw[41]=256
    set pw[42]=512
    set pw[43]=1024
    set pw[44]=2048
    set pw[45]=4096
    set pw[46]=8192
    set pw[47]=16384
    set pw[48]=-16384
    set pw[49]=1
    set pw[50]=2
    set pw[51]=4
    set pw[52]=8
    set pw[53]=16
    set pw[54]=32
    set pw[55]=64
    set pw[56]=128
    set pw[57]=256
    set pw[58]=512
    set pw[59]=1024
    set pw[60]=2048
    set pw[61]=4096
    set pw[62]=8192
    set pw[63]=16384
    set pw[64]=-16384
    set pw[65]=1
    set pw[66]=2
    set pw[67]=4
    set pw[68]=8
    set pw[69]=16
    set pw[70]=32
    set pw[71]=64
    set pw[72]=128
    set pw[73]=256
    set pw[74]=512
    set pw[75]=1024
    set pw[76]=2048
    set pw[77]=4096
    set pw[78]=8192
    set pw[79]=16384
    set pw[80]=-16384
    set pw[81]=1
    set pw[82]=2
    set pw[83]=4
    set pw[84]=8
    set pw[85]=16
    set pw[86]=32
    set pw[87]=64
    set pw[88]=128
    set pw[89]=256
    set pw[90]=512
    set pw[91]=1024
    set pw[92]=2048
    set pw[93]=4096
    set pw[94]=8192
    set pw[95]=16384
    set pw[96]=32768
    set pw[97]=65536
    set pw[98]=131072
    set pw[99]=262144
    set pw[100]=524288
    set pw[101]=1048576
    set pw[102]=-1048576
    set pw[103]=1
    set pw[104]=2
    set pw[105]=4
    set pw[106]=8
    set pw[107]=16
    set pw[108]=32
    set pw[109]=64
    set pw[110]=128
    set pw[111]=256
    set pw[112]=512
    set pw[113]=1024
    set pw[114]=2048
    set pw[115]=4096
    set pw[116]=8192
    set pw[117]=16384
    set pw[118]=32768
    set pw[119]=65536
    set pw[120]=-65536
    set pw[121]=1
    set pw[122]=2
    set pw[123]=4
    set pw[124]=8
    set pw[125]=16
    set pw[126]=32
    set pw[127]=64
    set pw[128]=128
    set pw[129]=256
    set pw[130]=512
    set pw[131]=1024
    set pw[132]=2048
    set pw[133]=4096
    set pw[134]=8192
    set pw[135]=16384
    set pw[136]=32768
    set pw[137]=65536
    set pw[138]=131072
    set pw[139]=262144
    set pw[140]=524288
    set pw[141]=1048576
    set pw[142]=-1048576
    set pw[143]=1
    set pw[144]=2
    set pw[145]=4
    set pw[146]=8
    set pw[147]=16
    set pw[148]=32
    set pw[149]=64
    set pw[150]=128
    set pw[151]=256
    set pw[152]=512
    set pw[153]=-512
    set pw[154]=1
    set pw[155]=2
    set pw[156]=4
    set pw[157]=8
    set pw[158]=16
    set pw[159]=32
    set pw[160]=64
    set pw[161]=128
    set pw[162]=256
    set pw[163]=512
    set pw[164]=1024
    set pw[165]=2048
    set pw[166]=-2048
    set pw[167]=1
    set pw[168]=2
    set pw[169]=4
    set pw[170]=8
    set pw[171]=16
    set pw[172]=32
    set pw[173]=64
    set pw[174]=128
    set pw[175]=256
    set pw[176]=512
    set pw[177]=-512
    endmethod
    endmodule
    private struct O extends array
    implement I
    endstruct
    //! endtextmacro
     
  3. Nestharus

    Nestharus o-o

    Ratings:
    +83 / 0 / -0
    Updated to 1.1.1.0

    The ini script is now down to 554 lines with default settings and the amount of objects generated are now down to 167 with default settings =). In the previous version, it was 587 lines and 178 objects.
     
  4. emjlr3

    emjlr3 Change can be a good thing Staff Member

    Ratings:
    +396 / 0 / -0
    this would have been great like 5 years ago when i actually cared - where were you then huh?

    I understand, from an ability level perspective, why you take an integer argument, but from a usage perspective, it should really be a real, as the majority of these values can have decimals - even if it just tricks the user into thinking the system has that level of control.... ^^

    maybe just silly rambling though
     
  5. Nestharus

    Nestharus o-o

    Ratings:
    +83 / 0 / -0
    Well, having a real argument would be misleading since the system doesn't support decimals =). I don't think that tricking the user is very nice =P.

    I mean, I guess I could support decimals for the ones that take decimals, but that'd be nearly useless =). Are 6 new abilities for each object that supports it worth it for decimals? :p

    That'd also add in overhead as I'd have to retrieve the decimals from the real (separate them out and cut out ones past hundredths) =).



    Most of the people commenting on this state that Status from jesus4lyf and BonusMod from Earht-Fury already do this =P, but they don't support safe object generation and obviously this is much easier to customize. This even has faster loops, although those don't really matter since the speed in this case is negligible =).
     
  6. tooltiperror

    tooltiperror Super Moderator Staff Member

    Ratings:
    +233 / 0 / -0
    Simple and useful. Distinct from Status.

    Approved.
     
  7. Nestharus

    Nestharus o-o

    Ratings:
    +83 / 0 / -0
    Updated ^)^. Now it is the most configurable Bonus system around : o.
     

Share This Page