HomeUser Control Panel (unavailable in archive)ForumsTutorialsArt GalleryResourcesMaps

database script criticism

08-08-2009, 10:34 AM#1
fX_
i was reading a thread somewhere where this user Litany directed ppl to a Game Mode movie in his sig (which was impressive)... i checked out the other links and was led to one where unit attack projectiles were manipulated and he stated that he used an object data database (functionality of GetUnitArmorType, and i would think GetUnitDamagePoint for the feature in that vid this is sampled in) to be able to work with these kinds of things.
indeed it is impossible to adjust the speed of a projectile; then he uses a dummy model with properties equivalent to the unit's projectile.

i want this sort of control for my map, whether for this feature or for others, so i set out making a database.

this is the current build i have:
Collapse JASS:
library UnitTypeData initializer Initializer

/!==================================================================================================================!//
    //!  UnitTypeData
    //!------------------------------------------------------------------------------------------------------------------!//
    //!     Database of the property valuations for (registered) unit types.
    //!==================================================================================================================!//

    //must be easy and appropriative for property declaration and indexing.

    private function ConvertUnitIdToArrayIndex takes integer unitId returns integer
        return 0   //how to convert unitIds (most, if not all, > 8191) into in-range array
                      //indexes???
    endfunction

    //! textmacro Property takes property, valueType
    globals
        private $valueType$ array $property$[8191]
    endglobals

    function GetUnitType$property$ takes integer unitId returns $valueType$
        return $property$[ConvertUnitIdToArrayIndex(unitId)]
    endfunction

    function DefineUnitType$property$ takes integer unitId, $valueType$ value returns nothing
        set $proeprty$[ConvertUnitIdToArrayIndex(unitId)] = value
    endfunction
    //! endtextmacro

    //!macroproperty   <==>     indexunittype   *correspondence *indexunittype(macroproperty)
    //!                            integer unitId
    //!--------                    !
    //!--------                    !
    //!--------                    !
    //!--------                    !
    //!endmacroproperty         endindexunittype

    //!macro IndexUnitType takes integer unitId, valueType property1Value, valueType property2Value ... valueType propertyNValue
    // variable argument list not possible.
    //!macro IndexUnitType takes integer unitId, valueType property1Value, ... valueType propertyNValue
    // add another property1value, all existing ones need to be updated to accord to new macro structure; need variability or w/e its termed.
    // index unit and valuate property independently.
    //!macro IndexUnitType property1 takes valueType property1Value
    //!macro IndexUnitType property2 takes valueType property2Value
    //!...
    //!//!macro IndexUnitType propertyN takes valueType propertyNValue

    private function Initializer takes nothing returns nothing
        //Footman
        //call DefineUnitTypeDamagePoint('hfoo', 1.00) // pretend that footman dmg point is 1.00
        //Sorceress        //call DefineUnitTypeCastPoint('hfoo', 1.00) // pretend that sorceress cast point is 1.00

        //*dont care about cast point for footman; nor about damage point for sorceress.
        //*properties can be logged independently of each other. indexing of unit types is 'free' of property type declaration.
    endfunction

endlibrary

tried to work with textmacros for propertyType declaration and unitType indexing/definition but it doesnt work because the latter is 'molded' or 'is a function' of the former but it cannot be macro'd internally. add a new propertyType, all unitType indexing macro calls get screwed...
etc...
then i contrived this.
but it sucks that id have to call a line for every unit type and for every (relevant, and so, valuated) property for that unit.

any other (better) ways?
08-08-2009, 10:52 AM#2
Deaod
http://www.wc3c.net/vexorian/jasshelpermanual.html#slk
08-08-2009, 12:27 PM#3
fX_
any automated way to make an slk file out of data in the object editor?
08-08-2009, 04:09 PM#4
Flame_Phoenix
Collapse JASS:
    private function ConvertUnitIdToArrayIndex takes integer unitId returns integer
        return 0   //how to convert unitIds (most, if not all, > 8191) into in-range array
                      //indexes???
    endfunction
You could use the return bug before patch 1.24 -.-
Now you can use Blizz natives to do that - however they won't give you a value between 0 and 8191. So to do this, if I am not mistaken, you need a hash function.There are many hash functions, so I will not pick one for you. Instead you may want to read this link:
http://en.wikipedia.org/wiki/Hash_function

So, my idea is: you get the id of a unit with Blizz natives and then you pass that id to a hash function that will resize it in order to be unique and to fit inside an array.

DANGER: When using hash functions you must consider the possibility of collisions. A good hash function reduces collisions to the maximum (among other things), but they will eventually happen - you need a plan if, by any case, a collision occurs.

Also, I didn't read the entire system, but accordingly to your hasing problem, you may want to consider the fact that using an array may not be the best solution. Instead you may want to use Table, PUI, DUI or whatever.
08-09-2009, 05:22 AM#5
fX_
why is it that when i comment out the .create part of the getFromKey method, the method only ever returns the instance corresponding to the last row of the .slk?

how does loaddata load stuff?
does loaddata load directly into the storage thing? getFromKey simply retrieves the loaded stuff from the storage thing.

i modified the getFromKey method to use Table instead of CSData and it works just the same. apparently loading isnt compromised by this. is it because these 2 work the same way - as it seems? or is it because it can 'adapt'? or it because it 'doesnt care' about this, working some other way?