• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!
  • It's time for the first HD Modeling Contest of 2024. Join the theme discussion for Hive's HD Modeling Contest #6! Click here to post your idea!

[General] Save/Load Algorithms (what you guys want?)

Status
Not open for further replies.
Level 31
Joined
Jul 10, 2007
Messages
6,306
Ok, so I've been writing lots of little scripts and detailed examples into Encoder Framework for how to do various things from simple things to complicated things ^)^.


Here's what I'm planning to cover-
Item Catalogs
General, Shared between Heroes, Hero Specific, Item Charges, Shared between Heroes with Hero Specific and Item Charges, Items specific to slots (like a chestplate slot)

Hero Catalogs

Saving an inventory (two techniques)

Saving multiple units (two techniques)

Saving multiple units that may or may not exist (like pets)

Saving resources

Saving experience and level

Each topic will include the catalog (if it merits one), how to save it, how to load it, and how to write the Encoder object code for it complete with detailed descriptions. Of all of those topics above, the item catalogs with shared items between heroes + hero specific items + item charges + items specific to slots is the most complex, but I break it up so that it is easy (though still tedious and huge).

Here is a preview-
JASS:
    struct Items extends array
        //with item specific catalog, the best way to determine whether a class can have an item
        //or not is with flags
        //first set up your flag table
    
        //item classes
        /*
            0   --------------------------  Misc
            1   --------------------------  Clothes
            2   --------------------------  Leather
            3   --------------------------  Chain
            4   --------------------------  Plated
            5   --------------------------  One Handed Sword/Axe/Hammer
            6   --------------------------  Two Handed Sword/Axe/Hammer
            7   --------------------------  Dagger
            8   --------------------------  Fist
            9   --------------------------  Wand/Staff
            10  --------------------------  Bow/Crossbow
        */
        
        //item class constants
        private static constant integer MISC = 0
        private static constant integer CLOTHES = 1
        private static constant integer LEATHER = 2
        private static constant integer CHAIN = 3
        private static constant integer PLATED = 4
        private static constant integer ONE_HAND = 5
        private static constant integer TWO_HAND = 6
        private static constant integer DAGGER = 7
        private static constant integer FIST = 8
        private static constant integer MAGIC = 9
        private static constant integer RANGED = 10
        
        //each item class needs its own catalog, so need an array of catalogs
        private static integer array itemClassCatalogs
        private static integer array groupCatalogs
        private static Table hero2Group = 0
        implement Catalog
        private static method onInit takes nothing returns nothing
            //create the item class catalogs
            set itemClassCatalogs[MISC]=CatalogCreate()
            set itemClassCatalogs[CLOTHES]=CatalogCreate()
            set itemClassCatalogs[LEATHER]=CatalogCreate()
            set itemClassCatalogs[CHAIN]=CatalogCreate()
            set itemClassCatalogs[PLATED]=CatalogCreate()
            set itemClassCatalogs[ONE_HAND]=CatalogCreate()
            set itemClassCatalogs[TWO_HAND]=CatalogCreate()
            set itemClassCatalogs[DAGGER]=CatalogCreate()
            set itemClassCatalogs[FIST]=CatalogCreate()
            set itemClassCatalogs[MAGIC]=CatalogCreate()
            set itemClassCatalogs[RANGED]=CatalogCreate()
            
            //now determine which classes can equip which items
            /*
                all classes
                    MISC
                
                warrior, knight, paladin
                    CHAIN, PLATED, ONE_HAND, TWO_HAND, DAGGER, FIST
                
                ranger
                    LEATHER, ONE_HAND, CHAIN, RANGED, DAGGER
                
                wizard
                    CLOTHES, LEATHER, MAGIC
            */
            
            //create one catalog for each group
            set groupCatalogs[0]=CatalogCreate()        //warrior, knight, paladin
            set groupCatalogs[1]=CatalogCreate()        //ranger
            set groupCatalogs[2]=CatalogCreate()        //wizard
            
            //add items to various catalogs
            call CatalogAdd(itemClassCatalogs[MISC],'1000')
            call CatalogAdd(itemClassCatalogs[MISC],'1001')
            call CatalogAdd(itemClassCatalogs[MISC],'1002')
            
            call CatalogAdd(itemClassCatalogs[CLOTHES],'1100')
            call CatalogAdd(itemClassCatalogs[CLOTHES],'1101')
            call CatalogAdd(itemClassCatalogs[CLOTHES],'1102')
            
            call CatalogAdd(itemClassCatalogs[LEATHER],'1200')
            call CatalogAdd(itemClassCatalogs[LEATHER],'1201')
            call CatalogAdd(itemClassCatalogs[LEATHER],'1202')
            
            call CatalogAdd(itemClassCatalogs[CHAIN],'1300')
            call CatalogAdd(itemClassCatalogs[CHAIN],'1301')
            call CatalogAdd(itemClassCatalogs[CHAIN],'1302')
            
            call CatalogAdd(itemClassCatalogs[PLATED],'1400')
            call CatalogAdd(itemClassCatalogs[PLATED],'1401')
            call CatalogAdd(itemClassCatalogs[PLATED],'1402')
            
            call CatalogAdd(itemClassCatalogs[ONE_HAND],'1500')
            call CatalogAdd(itemClassCatalogs[ONE_HAND],'1501')
            call CatalogAdd(itemClassCatalogs[ONE_HAND],'1502')
            
            call CatalogAdd(itemClassCatalogs[TWO_HAND],'1600')
            call CatalogAdd(itemClassCatalogs[TWO_HAND],'1601')
            call CatalogAdd(itemClassCatalogs[TWO_HAND],'1602')
            
            call CatalogAdd(itemClassCatalogs[DAGGER],'1700')
            call CatalogAdd(itemClassCatalogs[DAGGER],'1701')
            call CatalogAdd(itemClassCatalogs[DAGGER],'1702')
            
            call CatalogAdd(itemClassCatalogs[FIST],'1800')
            call CatalogAdd(itemClassCatalogs[FIST],'1801')
            call CatalogAdd(itemClassCatalogs[FIST],'1802')
            
            call CatalogAdd(itemClassCatalogs[MAGIC],'1900')
            call CatalogAdd(itemClassCatalogs[MAGIC],'1901')
            call CatalogAdd(itemClassCatalogs[MAGIC],'1902')
            
            call CatalogAdd(itemClassCatalogs[RANGED],'2000')
            call CatalogAdd(itemClassCatalogs[RANGED],'2001')
            call CatalogAdd(itemClassCatalogs[RANGED],'2002')
            
            //add various catalogs to group catalogs
            //warrior, knight, paladin
            //CHAIN, PLATED, ONE_HAND, TWO_HAND, DAGGER, FIST, MISC
            call CatalogAddCatalog(groupCatalogs[0],itemClassCatalogs[CHAIN])
            call CatalogAddCatalog(groupCatalogs[0],itemClassCatalogs[PLATED])
            call CatalogAddCatalog(groupCatalogs[0],itemClassCatalogs[ONE_HAND])
            call CatalogAddCatalog(groupCatalogs[0],itemClassCatalogs[TWO_HAND])
            call CatalogAddCatalog(groupCatalogs[0],itemClassCatalogs[DAGGER])
            call CatalogAddCatalog(groupCatalogs[0],itemClassCatalogs[FIST])
            call CatalogAddCatalog(groupCatalogs[0],itemClassCatalogs[MISC])
            //ranger
            //LEATHER, ONE_HAND, CHAIN, RANGED, DAGGER, MISC
            call CatalogAddCatalog(groupCatalogs[1],itemClassCatalogs[LEATHER])
            call CatalogAddCatalog(groupCatalogs[1],itemClassCatalogs[ONE_HAND])
            call CatalogAddCatalog(groupCatalogs[1],itemClassCatalogs[CHAIN])
            call CatalogAddCatalog(groupCatalogs[1],itemClassCatalogs[RANGED])
            call CatalogAddCatalog(groupCatalogs[1],itemClassCatalogs[DAGGER])
            call CatalogAddCatalog(groupCatalogs[1],itemClassCatalogs[MISC])
            //wizard
            //CLOTHES, LEATHER, MAGIC, MISC
            call CatalogAddCatalog(groupCatalogs[2],itemClassCatalogs[CLOTHES])
            call CatalogAddCatalog(groupCatalogs[2],itemClassCatalogs[LEATHER])
            call CatalogAddCatalog(groupCatalogs[2],itemClassCatalogs[MAGIC])
            call CatalogAddCatalog(groupCatalogs[2],itemClassCatalogs[MISC])
            
            /**********************************************************************
            *
            *   for hero specific items, you can create a catalog for the hero
            *       ->  set heroCatalogs[warriorCatalog] = CatalogCreate()
            *   and add the group catalog to it
            *       ->  call CatalogAddCatalog(heroCatalogs[warriorCatalog], groupCatalogs[0])
            *   this allows you to add hero specific gear
            *       ->  call CatalogAdd(warriorCatalog, 'war1')
            *
            **********************************************************************/
            
            //now need a way to get group from hero
            set hero2Group = Table.create()
            set hero2Group[warriorTypeId]=0
            set hero2Group[knightTypeId]=0
            set hero2Group[paladinTypeId]=0
            set hero2Group[rangerTypeId]=1
            set hero2Group[wizardTypeId]=2
            
            //keep in mind that with hero specific catalogs, a hero only needs to point to its
            //hero specific catalog
            //hero2Group[warriorTypeId] = warriorCatalog
        endmethod
        
        //now need to add public properties for the save/load
        static method operator [] takes integer heroId returns thistype
            return hero2Group[heroId]
        endmethod
        
        method raw takes integer itemId returns integer
            return CatalogRaw(groupCatalogs[this],itemId)
        endmethod
        
        method id takes integer itemRaw returns integer
            return CatalogId(groupCatalogs[this],itemRaw)
        endmethod
        
        //and the above would turn into this
        //raw = Items[warriorTypeId].raw(axeCatalogId)
        //id = Items[warriorTypeId].id(GetUnitTypeId(axe))
    endstruct


What others would you guys like me to cover?
 
Level 31
Joined
Jul 10, 2007
Messages
6,306
Er.. these scripts aren't part of the system. They are more like mini tutorials on how to do certain things with ready made scripts.


I don't know if hero played time would be useful ; P. That'd expand the code for something that wouldn't really benefit any maps. If people actually need it for their map, then sure, I could write a little script for it, but what I'm focusing on here are scripts that are generally used in RPG/ORPG maps. For example, saving inventories is a common problem, saving hero xp/level, saving hero, etc.
 
Level 33
Joined
Mar 27, 2008
Messages
8,035
Real-time Event.

This system only applicable to Host (when Host of the game -load his characters), let's say he loads his character to Level 50 Assassin. In the past, he had killed a legendary beast and had destroyed a bridge, these two situations will be happening immediately (the beast and the bridge will be destroyed instantly) once the Host -load his character

It is used to detect what has the Host had done in the past (previous game, he -save it)

But don't apply this to all Event, it will make the game, less playable (just make some cool Events only, like bridge is destroyed, bla bla)
 
Level 31
Joined
Jul 10, 2007
Messages
6,306
That sounds rather map specific ; P. It's different depending on the map.

Let's say that there are booleans that signify whether a player has done an event or not. When a player completes an event, the flag is set to true. In the code, these flags are stored. After the host loads up their code, the flags loaded from that code are checked to see if the event should be instantly done or not. Make sense?
 
Level 33
Joined
Mar 27, 2008
Messages
8,035
It's just a suggestion though :)

But like I said, you should not make this for all Event.
Only apply it to fun/entertaining events, not repeatable quests such as killing wolves and such.

This will make the game speed up the process, let's say your RPG should kill Twineria (a Boss) which would need a minimum of Level 150 Tanker-type Hero and you must beat his Guardians and destroy the Portals first in order to reach Twineria

If you apply this system, both Guardians and Portals should die (if the Player has killed it in the past) and makes it easier to reach the Twineria

You must balance all these things in aspect of RPG-type game, don't make it too simple, don't make it too hard.
 
Level 31
Joined
Jul 10, 2007
Messages
6,306
What you said doesn't even make sense...


This is for a general save/load system used for map making... why would it include random events?


Again, you are talking about map specific things.


My question is do all maps contain your Twineria boss? Do all maps contain the same events? Is your Twineria boss even a pretty general map thing, or is it possibly specific to only 1 map? Notice I've been covering things like saving inventories, which are very common across many maps. Can you say the same thing of specific events?


Stop confusing making a map with making a resource for map making ; P.
 
Status
Not open for further replies.
Top