Language: 
To browser these website, it's necessary to store cookies on your computer.
The cookies contain no personal information, they are required for program control.
  the storage of cookies while browsing this website, on Login and Register.

Author Topic:  Quick Slots  (Read 3765 times)

0 Members and 0 Guests are viewing this topic.

tarriel

« on: 25, December 2009, 16:03:43 »
Along with others I seem to be having some problems with quick slots not being saved.  So as a christmas present to Yuna, myself and any others that have this problem,  I decided to take a look at it.  As the old code confused the heck out of me I decided to store the quick slots in a plain text file similar to the kill list.  Have tested this under ubuntu and windows, and a couple of different alts, it seems to work ok. 

The only problem will be with unidentified things in quickslots, but who does this?

Code: [Select]
Index: menu.c
===================================================================
--- menu.c (revision 1)
+++ menu.c (working copy)
@@ -2259,6 +2259,7 @@
                         sound_play_effect(SOUND_GET, 0, 0, 100); /* no bug - we 'get' it in quickslots */
                         sprintf(buf, "set F%d to %s", ind + 1, locate_item(cpl.win_quick_tag)->s_name);
                         draw_info(buf, COLOR_DGOLD);
+                        save_quickslots_entrys();
                     }
                 }
             }
@@ -2286,10 +2287,11 @@
                     draggingInvItem(DRAG_QUICKSLOT);
                 }
                 quick_slots[ind].shared.tag = -1;
+                save_quickslots_entrys();
             }
             else
             {
-                int stemp = cpl.      inventory_win, itemp = cpl.win_inv_tag;
+                int stemp = cpl.inventory_win, itemp = cpl.win_inv_tag;
                 cpl.inventory_win = IWIN_INV;
                 cpl.win_inv_tag = quick_slots[ind].shared.tag;
                 process_macro_keys(KEYFUNC_APPLY, 0);
@@ -2345,195 +2347,54 @@
     }
 }
 
-static void freeQuickSlots(_quickslot *quickslots, int size)
-{
-    int i;
-
-    for (i = 0; i != size; ++i)
-    {
-        if (quickslots[i].shared.is_spell == FALSE)
-            free(quickslots[i].name.name);
-    }
-}
-
-static int readNextQuickSlots(FILE *fp, char *server, int *port, char *name, _quickslot *quickslots)
-{
-    int     ch, i, r;
-
-    for (ch = 1, i = 0; ch;)
-    {
-        if (i == 2048)
-            return 0;
-        ch = fgetc(fp);
-        if (ch == EOF)
-            return 0;
-        server[i++] = ch;
-    }
-    if (!fread(port, sizeof(int), 1, fp))
-        return 0;
-    for (ch = 1, i = 0; ch;)
-    {
-        if (i == 40)
-            return 0;
-        ch = fgetc(fp);
-        if (ch == EOF)
-            return 0;
-        name[i++] = ch;
-    }
-    for (i = r = 0; i != MAX_QUICK_SLOTS; ++i)
-    {
-        if (!fread(&quickslots[i].shared.is_spell, sizeof(Boolean), 1, fp))
-        {
-            freeQuickSlots(quickslots, i);
-            return 0;
-        }
-        r += sizeof(Boolean);
-        if (quickslots[i].shared.is_spell == FALSE)
-        {
-            int j;
-
-            if (!fread(&quickslots[i].item.nr, sizeof(int), 1, fp))
-            {
-                freeQuickSlots(quickslots, i);
-                return 0;
-            }
-            r += sizeof(int);
-            quickslots[i].name.name = (char *)malloc(sizeof(char) * 128);
-            for (ch = 1, j = 0; ch; ++r)
-            {
-                if (j == 128)
-                {
-                    freeQuickSlots(quickslots, i + 1);
-                    return 0;
-                }
-                ch = fgetc(fp);
-                if (ch == EOF)
-                {
-                    freeQuickSlots(quickslots, i + 1);
-                    return 0;
-                }
-                quickslots[i].name.name[j++] = ch;
-            }
-        }
-        else
-        {
-            if (!fread(&quickslots[i].shared.tag, sizeof(int), 1, fp))
-            {
-                freeQuickSlots(quickslots, i);
-                return 0;
-            }
-            if (!fread(&quickslots[i].spell.groupNr, sizeof(int), 1, fp))
-            {
-                freeQuickSlots(quickslots, i);
-                return 0;
-            }
-            if (!fread(&quickslots[i].spell.classNr, sizeof(int), 1, fp))
-            {
-                freeQuickSlots(quickslots, i);
-                return 0;
-            }
-            r += sizeof(int) * 3;
-        }
-    }
-    return r;
-}
-
 /******************************************************************
  Restore quickslots from last game.
 ******************************************************************/
-#define QUICKSLOT_FILE "settings/quick.dat"
-#define QUICKSLOT_FILE_VERSION 2
-#define QUICKSLOT_FILE_HEADER ((QUICKSLOT_FILE_VERSION << 24) | 0x53 << 16 | 0x51 << 8 | 0x44)
 void load_quickslots_entrys()
 {
-    long        header;
-    int         i, port;
-    char        name[40], server[2048];
-    _quickslot  quickslots[MAX_QUICK_SLOTS];
-    FILE       *stream;
+    char    buf[128];
+ char    filename[255];
+ FILE    *stream;
+ int     ind=0;
+ char    *item_name;
+ item    *ob;
 
-    if (!(stream = fopen_wrapper(QUICKSLOT_FILE, "rb")))
-        return;
-    fread(&header, sizeof(header), 1, stream);
-    if (header != QUICKSLOT_FILE_HEADER)
+    sprintf(filename,"settings/%s.quickslots.dat",cpl.name);
+    LOG(LOG_DEBUG,"Trying to read the quickslots file: %s\n",filename);
+
+    if (!(stream = fopen_wrapper(filename, "r")))
+    {
+        /* no QuickSlot File - no problem */
+    }
+    else
     {
-        fclose(stream);
-        remove(file_path(QUICKSLOT_FILE, ""));
-        return;
-    }
-    while (readNextQuickSlots(stream, server, &port, name, quickslots))
-    {
-        if (!strcmp(ServerName, server) && ServerPort == port)
+        while ((fgets(buf, 128, stream) != NULL) && (ind < MAX_QUICK_SLOTS))
         {
-            Boolean cont = FALSE;
-
-            port = strlen(cpl.name) + 1;
-            for (i = 0; i != port; ++i)
+            item_name = strtok (buf, "#");
+            if (0==strcmp(item_name, "SPELL"))
             {
-                if (tolower(cpl.name[i]) != tolower(name[i]))
-                {
-                    cont = TRUE;
-                    break;
-                }
-            }
-
-            if (cont == TRUE)
-                continue;
-
-            for (i = 0; i != MAX_QUICK_SLOTS; ++i)
+                quick_slots[ind].shared.is_spell = TRUE;
+                quick_slots[ind].spell.groupNr = atoi(strtok (NULL, "#"));
+                quick_slots[ind].spell.classNr = atoi(strtok (NULL, "#"));
+                quick_slots[ind].shared.tag = atoi(strtok (NULL, "#\n"));
+                cpl.win_quick_tag = -1;
+            }
+            else if (0==strcmp(item_name, "ITEM"))
             {
-                if (quick_slots[i].shared.is_spell == FALSE)
+                item_name = strtok (NULL, "#\n");
+                ob = locate_item_from_item_name(cpl.ob->inv, item_name);
+                if (ob!=NULL)
                 {
-                    int      j;
-                    Boolean  match = FALSE;
-                    item    *ob = cpl.ob->inv;
-
-                    for (j = 0; ob != NULL; ++j, ob = ob->next)
-                    {
-                        if (j == quick_slots[i].item.nr)
-                        {
-                            if (!strcmp(ob->s_name, quick_slots[i].name.name))
-                            {
-                                quick_slots[i].item.tag = ob->tag;
-                                match = TRUE;
-                            }
-                            break;
-                        }
-                    }
-                    if (match == FALSE)
-                    {
-                        for (ob = cpl.ob->inv; ob; ob = ob->next)
-                        {
-                            if (!strcmp(ob->s_name, quick_slots[i].name.name))
-                            {
-                                quick_slots[i].item.tag = ob->tag;
-                                match = TRUE;
-                                break;
-                            }
-                        }
-                        if (match == FALSE)
-                        {
-                            cont = TRUE;
-                            quick_slots[i].item.tag = -1;
-                        }
-                    }
-                    free(quick_slots[i].name.name);
-                }
-                else
-                {
-                    memcpy(&quick_slots[i], &quickslots[i], sizeof(_quickslot));
-                    if (quick_slots[i].shared.tag == -1)
-                        cont = TRUE;
-                }
-                if (cont == TRUE)
-                    continue;
-                if (quick_slots[i].shared.is_spell == FALSE)
-                    cpl.win_inv_slot = quick_slots[i].item.invSlot;
+                    quick_slots[ind].item.tag = ob->tag;
+                    quick_slots[ind].spell.groupNr = -1;
+                    quick_slots[ind].spell.classNr = -1;
+                    quick_slots[ind].shared.is_spell = FALSE;
+                }
             }
-            break;
+            ind++;
         }
+        fclose(stream);
     }
-    fclose(stream);
     update_quickslots(-1);
 }
 
@@ -2542,117 +2403,42 @@
 ******************************************************************/
 void save_quickslots_entrys()
 {
-    long        header;
-    char        name[40], server[2048];
-    int         n, size, w;
-    _quickslot  quickslots[MAX_QUICK_SLOTS];
-    FILE       *stream;
+    FILE *stream;
+    char buf[512];
+    char filename[255];
+    int ind;
 
-    if (!(stream = fopen_wrapper(QUICKSLOT_FILE, "rb+")))
-    {
-        if (!(stream = fopen_wrapper(QUICKSLOT_FILE, "wb+")))
-            return;
-    }
-    header = QUICKSLOT_FILE_HEADER;
-    fwrite(&header, sizeof(header), 1, stream);
-    for (n = w = 0; n != MAX_QUICK_SLOTS; ++n)
-    {
-        w += sizeof(Boolean);
-        if (quick_slots[n].shared.is_spell == FALSE)
-        {
-            item *ob = locate_item_from_inv(cpl.ob->inv, quick_slots[n].item.tag);
+    sprintf(filename,"settings/%s.quickslots.dat",cpl.name);
+    LOG(LOG_DEBUG,"Trying to save the quickslot file: %s\n",filename);
 
-            w += sizeof(int);
-            quick_slots[n].name.name = (char *)malloc(sizeof(char) * 128);
-            if (ob != NULL)
-            {
-                int i = strlen(ob->s_name) + 1;
+    if (!(stream = fopen_wrapper(filename, "w")))
+        return;
 
-                strncpy(quick_slots[n].name.name, ob->s_name, i);
-                w += i;
-            }
-            else
-                w += sizeof(char);
-        }
-        else
-            w += sizeof(int) * 3;
-    }
-    /* readNextQuickSlots has problems with wb+ and rb+ opened files */
-    n = ftell(stream);
-    freopen(file_path(QUICKSLOT_FILE, "rb"),"rb",stream);
-    fseek(stream,n,SEEK_SET);
-    while ((size = readNextQuickSlots(stream, server, &n, name, quickslots)) != 0)
+    for (ind = 0; ind != MAX_QUICK_SLOTS; ++ind)
     {
-        if (!strcmp(ServerName, server) && n == ServerPort && !strcmp(cpl.name, name))
+        if (quick_slots[ind].shared.is_spell == FALSE)
         {
-            if ((n = w - size) != 0)
+            item *ob = locate_item_from_inv(cpl.ob->inv, quick_slots[ind].item.tag);
+            if (ob != NULL)
             {
-                char *buf;
-                long  pos = ftell(stream);
-                freopen(file_path(QUICKSLOT_FILE, "rb+"),"rb+",stream);
-                fseek(stream, 0, SEEK_END);
-                w = ftell(stream) - pos;
-                buf = (char *)malloc(w);
-                fseek(stream, pos, SEEK_SET);
-                fread(buf, 1, w, stream);
-                fseek(stream, pos + n, SEEK_SET);
-                fwrite(buf, 1, w, stream);
-                if (n < 0)
-                {
-                    w = ftell(stream);
-                    rewind(stream);
-                    buf = (char *)realloc(buf, w);
-                    fread(buf, 1, w, stream);
-                    freopen(file_path(QUICKSLOT_FILE, "wb+"), "wb+", stream);
-                    fwrite(buf, 1, w, stream);
-                }
-                free(buf);
-                fseek(stream, pos, SEEK_SET);
-            }
-            fseek(stream, -size, SEEK_CUR);
-            for (n = 0; n != MAX_QUICK_SLOTS; ++n)
-            {
-                fwrite(&quick_slots[n].shared.is_spell, sizeof(Boolean), 1, stream);
-                if (quick_slots[n].shared.is_spell == FALSE)
-                {
-                    fwrite(&quick_slots[n].item.nr, sizeof(int), 1, stream);
-                    fwrite(quick_slots[n].name.name, sizeof(char), strlen(quick_slots[n].name.name) + 1, stream);
-                }
-                else
-                {
-                    fwrite(&quick_slots[n].shared.tag, sizeof(int), 1, stream);
-                    fwrite(&quick_slots[n].spell.groupNr, sizeof(int), 1, stream);
-                    fwrite(&quick_slots[n].spell.classNr, sizeof(int), 1, stream);
-                }
-            }
-            fclose(stream);
-            freeQuickSlots(quick_slots, MAX_QUICK_SLOTS);
-            return;
+                sprintf(buf,"ITEM#%s\n",ob->s_name);
+                fputs(buf, stream);
+           }
+           else
+           {
+                sprintf(buf,"EMPTY#\n");
+                fputs(buf, stream);
+           }
         }
-    }
-    freopen(file_path(QUICKSLOT_FILE, "rb+"),"rb+",stream);
-    fseek(stream, 0, SEEK_END);
-    fwrite(&ServerName, sizeof(char), strlen(ServerName) + 1, stream);
-    fwrite(&ServerPort, sizeof(int), 1, stream);
-    fwrite(&cpl.name, sizeof(char), strlen(cpl.name) + 1, stream);
-    for (n = 0; n != MAX_QUICK_SLOTS; ++n)
-    {
-        fwrite(&quick_slots[n].shared.is_spell, sizeof(Boolean), 1, stream);
-        if (quick_slots[n].shared.is_spell == FALSE)
-        {
-            fwrite(&quick_slots[n].item.nr, sizeof(int), 1, stream);
-            fwrite(quick_slots[n].name.name, sizeof(char), strlen(quick_slots[n].name.name) + 1, stream);
-        }
         else
         {
-            fwrite(&quick_slots[n].shared.tag, sizeof(int), 1, stream);
-            fwrite(&quick_slots[n].spell.groupNr, sizeof(int), 1, stream);
-            fwrite(&quick_slots[n].spell.classNr, sizeof(int), 1, stream);
+            sprintf(buf,"SPELL#%d#%d#%d\n",quick_slots[ind].spell.groupNr, quick_slots[ind].spell.classNr, quick_slots[ind].shared.tag);
+            fputs(buf, stream);
         }
     }
     fclose(stream);
-    freeQuickSlots(quick_slots, MAX_QUICK_SLOTS);
 }
+
 void widget_event_target(int x, int y, SDL_Event event)
 {
     /* combat modus */

clobber

« Reply #1 on: 26, December 2009, 01:18:03 »
Or as another way around you can just delete your old file "keys" in the "settings" folder of the client package while playing, then with all of your macros assigned type "/save" and they will save. I think its on tech support somewhere.

Although well done, nice bit of code ;)
Posted by Clobber

Collector Of Burnt out torches, 0 and Counting.

,-.  ___ ,-.
 \/ .   .  \ / 
(___O___)
 /  \      /   )
 ( ||       || )
  000     000
Woof, Woof!

Quote from: Longir
I use caution, fear is a distraction

ThePlaneskeeper

« Reply #2 on: 26, December 2009, 02:24:21 »
This is a good start, but a rule of thumb here: if there is a way to break anything, expect it to be broken.

Prime example:  When Rods/Horns used to be important, I would have 3 or 4 in quickslots.  Now if i found a new one, i would equip it just to see what it was.  If it happened to be useful, I would quickslot it with my other horns/rods.  Hence: A valid case for unidentified quickslot items.

I would expect there to be a need for unidentified items in quickslots.  Or, perhaps, need on a temporary basis.  How about they not save items (to the file) that are unidentified when they are in quickslots (so that way if there are 3 different ones in your inventory, it does not load the wrong one/crash), but still remain usable untill you log out?

polyveg

« Reply #3 on: 26, December 2009, 11:41:45 »
The inventory stuff (including quick slots) will be completly rewritten.
Perhaps the quickslots will then also be stored server-sided.

There will be also a button for autosorting.
Every item is known to the server as weapon, cloth, ...
so the autosort will put them in the correct place (aka slotgroup).
For every slotgroup you can set some parameters.

example Slotgroup1 (a slotgroup is a link to one of your bags):
Tick the option "scrolls" and "potions",
After an autosort all scrolls and potions are put in there.
Everythink that doesn't fit in there will be put into the last bag.

Like seen in other games the bags (but the first) must be found, bought or build.
The higher the price/skill the higher the amount of space in the bag.

smacky

« Reply #4 on: 26, December 2009, 13:23:13 »
Sarah the Seamstress sees a market opportunity. :)

Cutintwo

« Reply #5 on: 26, December 2009, 16:39:45 »
Sarah, like Smith is in need of some competition. She charged me Gold to embroider my Lich gaunts.  I will sharpen my darning needle in preparation for the hordes descending on me.

'A Cutin stitch saves two' (old dwarven saying).

Cutin2

smacky

« Reply #6 on: 26, December 2009, 16:57:49 »
Yup. Various code enhancements in B5 will allow for better handling of these kinds of NPCs in B6.

drace

« Reply #7 on: 28, December 2009, 06:08:06 »
I'm not shure if this is valid place for this statemetnt but i need to make it anyway.

I'm running windows 7 ulitmate, and with the widge client, if I minimise it, by ALT -TAB,
 it seems to block or Compelately  LOCK OUT  the games code to allow any range weapon or magic switching.
thru the TAB fuction, and doesn't adjust or change with slecting spells.

I've also have suffer significant memory loss in many areas and have forgotten many habits, such as macros.
Are macros still available to non mod/Dev player?
And if so can someone direct me to a "spe****ed" lists on here?

I especialy miss the "ready_ranged" item as to hit a key for slecting bow and arrow item loads
(we all still know that every effort, or work around to keep that F1-0 keys stable is a patch at best)
And the TAB-minimise also narffs the Quick slot keys, even more-so then my former XP OS.

I'd like to macro patch my "spell and range item" TAB lock out disfuction in the widget cleint
(o boy do I STILL miss the old hard coded, gui handy  one of old!)
And also Get that beloved 1 key macrod   /shout (seeing as comunity is based on talk, and drace-sim talk was a hot item at one point -Vainty warning--)

tarriel

« Reply #8 on: 29, January 2010, 13:21:46 »
Thanks for the feed back.  I thought about some of these things and modified my code.  The old quickslot saving relies on the position in the inventory and the name, so I have done the same thing, however if the item isn't found at the expected position and the item is identified it will look for the name and use the first one it finds, if the item is not identified it will ignore it.  It also saves a different file for each character which seems to prevent many of the problems of the original version. 
The essential changes are in menu.c
Code: [Select]
--- menu.c Fri Jan 29 21:15:15 2010
+++ menu.c Fri Jan 29 21:15:15 2010
@@ -2289,7 +2289,7 @@
             }
             else
             {
-                int stemp = cpl.      inventory_win, itemp = cpl.win_inv_tag;
+                int stemp = cpl.inventory_win, itemp = cpl.win_inv_tag;
                 cpl.inventory_win = IWIN_INV;
                 cpl.win_inv_tag = quick_slots[ind].shared.tag;
                 process_macro_keys(KEYFUNC_APPLY, 0);
@@ -2345,195 +2345,68 @@
     }
 }
 
-static void freeQuickSlots(_quickslot *quickslots, int size)
-{
-    int i;
-
-    for (i = 0; i != size; ++i)
-    {
-        if (quickslots[i].shared.is_spell == FALSE)
-            free(quickslots[i].name.name);
-    }
-}
-
-static int readNextQuickSlots(FILE *fp, char *server, int *port, char *name, _quickslot *quickslots)
-{
-    int     ch, i, r;
-
-    for (ch = 1, i = 0; ch;)
-    {
-        if (i == 2048)
-            return 0;
-        ch = fgetc(fp);
-        if (ch == EOF)
-            return 0;
-        server[i++] = ch;
-    }
-    if (!fread(port, sizeof(int), 1, fp))
-        return 0;
-    for (ch = 1, i = 0; ch;)
-    {
-        if (i == 40)
-            return 0;
-        ch = fgetc(fp);
-        if (ch == EOF)
-            return 0;
-        name[i++] = ch;
-    }
-    for (i = r = 0; i != MAX_QUICK_SLOTS; ++i)
-    {
-        if (!fread(&quickslots[i].shared.is_spell, sizeof(Boolean), 1, fp))
-        {
-            freeQuickSlots(quickslots, i);
-            return 0;
-        }
-        r += sizeof(Boolean);
-        if (quickslots[i].shared.is_spell == FALSE)
-        {
-            int j;
-
-            if (!fread(&quickslots[i].item.nr, sizeof(int), 1, fp))
-            {
-                freeQuickSlots(quickslots, i);
-                return 0;
-            }
-            r += sizeof(int);
-            quickslots[i].name.name = (char *)malloc(sizeof(char) * 128);
-            for (ch = 1, j = 0; ch; ++r)
-            {
-                if (j == 128)
-                {
-                    freeQuickSlots(quickslots, i + 1);
-                    return 0;
-                }
-                ch = fgetc(fp);
-                if (ch == EOF)
-                {
-                    freeQuickSlots(quickslots, i + 1);
-                    return 0;
-                }
-                quickslots[i].name.name[j++] = ch;
-            }
-        }
-        else
-        {
-            if (!fread(&quickslots[i].shared.tag, sizeof(int), 1, fp))
-            {
-                freeQuickSlots(quickslots, i);
-                return 0;
-            }
-            if (!fread(&quickslots[i].spell.groupNr, sizeof(int), 1, fp))
-            {
-                freeQuickSlots(quickslots, i);
-                return 0;
-            }
-            if (!fread(&quickslots[i].spell.classNr, sizeof(int), 1, fp))
-            {
-                freeQuickSlots(quickslots, i);
-                return 0;
-            }
-            r += sizeof(int) * 3;
-        }
-    }
-    return r;
-}
-
 /******************************************************************
  Restore quickslots from last game.
 ******************************************************************/
-#define QUICKSLOT_FILE "settings/quick.dat"
-#define QUICKSLOT_FILE_VERSION 2
-#define QUICKSLOT_FILE_HEADER ((QUICKSLOT_FILE_VERSION << 24) | 0x53 << 16 | 0x51 << 8 | 0x44)
 void load_quickslots_entrys()
 {
-    long        header;
-    int         i, port;
-    char        name[40], server[2048];
-    _quickslot  quickslots[MAX_QUICK_SLOTS];
-    FILE       *stream;
+    char    buf[128];
+ char    filename[255];
+ FILE    *stream;
+ int     qsIndex=0;
+ char    *item_name;
+ int     item_number;
+ uint8   item_quality;
+ uint32  item_tag;
+ item    *ob;
 
-    if (!(stream = fopen_wrapper(QUICKSLOT_FILE, "rb")))
-        return;
-    fread(&header, sizeof(header), 1, stream);
-    if (header != QUICKSLOT_FILE_HEADER)
-    {
-        fclose(stream);
-        remove(file_path(QUICKSLOT_FILE, ""));
-        return;
-    }
-    while (readNextQuickSlots(stream, server, &port, name, quickslots))
-    {
-        if (!strcmp(ServerName, server) && ServerPort == port)
-        {
-            Boolean cont = FALSE;
+    sprintf(filename,"settings/%s.quickslots.dat",cpl.name);
+    LOG(LOG_DEBUG,"Trying read the quickslots file: %s\n",filename);
 
-            port = strlen(cpl.name) + 1;
-            for (i = 0; i != port; ++i)
+    if (!(stream = fopen_wrapper(filename, "r")))
+        {  /* no QuickSlot File - no problem */ } else {
+        while ((fgets(buf, 128, stream) != NULL) && (qsIndex < MAX_QUICK_SLOTS))
+        {
+            item_name = strtok (buf, "#");
+            if (0==strcmp(item_name, "SPELL"))
             {
-                if (tolower(cpl.name[i]) != tolower(name[i]))
+                quick_slots[qsIndex].shared.is_spell = TRUE;
+                quick_slots[qsIndex].spell.groupNr = atoi(strtok (NULL, "#"));
+                quick_slots[qsIndex].spell.classNr = atoi(strtok (NULL, "#"));
+                quick_slots[qsIndex].shared.tag = atoi(strtok (NULL, "#"));
+                cpl.win_quick_tag = -1;
+            } else if (0==strcmp(item_name, "ITEM")) {
+                item_name = strtok (NULL, "#");
+                item_number = atoi(strtok (NULL, "#"));
+                item_quality = atoi(strtok (NULL, "#"));
+                item_tag = locate_item_tag_from_nr(cpl.ob->inv, item_number);
+                ob = locate_item_from_inv(cpl.ob->inv,item_tag);
+                // if the item position and name match we have what we want
+                // note the player is set up twice for some reason, first time the inventory is not filled yet so items aren't found
+                if (ob!=NULL)
                 {
-                    cont = TRUE;
-                    break;
-                }
-            }
-
-            if (cont == TRUE)
-                continue;
-
-            for (i = 0; i != MAX_QUICK_SLOTS; ++i)
-            {
-                if (quick_slots[i].shared.is_spell == FALSE)
-                {
-                    int      j;
-                    Boolean  match = FALSE;
-                    item    *ob = cpl.ob->inv;
-
-                    for (j = 0; ob != NULL; ++j, ob = ob->next)
+                    if (0==strcmp(item_name, ob->s_name))
                     {
-                        if (j == quick_slots[i].item.nr)
-                        {
-                            if (!strcmp(ob->s_name, quick_slots[i].name.name))
-                            {
-                                quick_slots[i].item.tag = ob->tag;
-                                match = TRUE;
-                            }
-                            break;
-                        }
+                        quick_slots[qsIndex].item.tag = ob->tag;
                     }
-                    if (match == FALSE)
+                    else if (255 != item_quality) // if the item is identified lets fine the name as it should be unique
                     {
-                        for (ob = cpl.ob->inv; ob; ob = ob->next)
+                        ob = locate_item_from_item_name(cpl.ob->inv, item_name);
+                        if (ob!=NULL)
                         {
-                            if (!strcmp(ob->s_name, quick_slots[i].name.name))
-                            {
-                                quick_slots[i].item.tag = ob->tag;
-                                match = TRUE;
-                                break;
-                            }
+                            quick_slots[qsIndex].item.tag = ob->tag;
                         }
-                        if (match == FALSE)
-                        {
-                            cont = TRUE;
-                            quick_slots[i].item.tag = -1;
-                        }
                     }
-                    free(quick_slots[i].name.name);
+                    quick_slots[qsIndex].spell.groupNr = -1;
+                    quick_slots[qsIndex].spell.classNr = -1;
+                    quick_slots[qsIndex].shared.is_spell = FALSE;
                 }
-                else
-                {
-                    memcpy(&quick_slots[i], &quickslots[i], sizeof(_quickslot));
-                    if (quick_slots[i].shared.tag == -1)
-                        cont = TRUE;
-                }
-                if (cont == TRUE)
-                    continue;
-                if (quick_slots[i].shared.is_spell == FALSE)
-                    cpl.win_inv_slot = quick_slots[i].item.invSlot;
             }
-            break;
+            qsIndex++;
         }
+        fclose(stream);
     }
-    fclose(stream);
+    // sanity check to make sure they are all ok, probably not required
     update_quickslots(-1);
 }
 
@@ -2542,117 +2415,47 @@
 ******************************************************************/
 void save_quickslots_entrys()
 {
-    long        header;
-    char        name[40], server[2048];
-    int         n, size, w;
-    _quickslot  quickslots[MAX_QUICK_SLOTS];
-    FILE       *stream;
+    FILE *stream;
+    char buf[512];
+    char filename[255];
+    int n;
+    int item_index;
 
-    if (!(stream = fopen_wrapper(QUICKSLOT_FILE, "rb+")))
-    {
-        if (!(stream = fopen_wrapper(QUICKSLOT_FILE, "wb+")))
-            return;
-    }
-    header = QUICKSLOT_FILE_HEADER;
-    fwrite(&header, sizeof(header), 1, stream);
-    for (n = w = 0; n != MAX_QUICK_SLOTS; ++n)
-    {
-        w += sizeof(Boolean);
-        if (quick_slots[n].shared.is_spell == FALSE)
-        {
-            item *ob = locate_item_from_inv(cpl.ob->inv, quick_slots[n].item.tag);
+    // Lets make the quick slots individual,  Players are unlikely to have identical exuipment
+    sprintf(filename,"settings/%s.quickslots.dat",cpl.name);
+    LOG(LOG_DEBUG,"Trying to save the quickslot file: %s\n",filename);
 
-            w += sizeof(int);
-            quick_slots[n].name.name = (char *)malloc(sizeof(char) * 128);
-            if (ob != NULL)
-            {
-                int i = strlen(ob->s_name) + 1;
+    if (!(stream = fopen_wrapper(filename, "w")))
+        return;
 
-                strncpy(quick_slots[n].name.name, ob->s_name, i);
-                w += i;
-            }
-            else
-                w += sizeof(char);
-        }
-        else
-            w += sizeof(int) * 3;
-    }
-    /* readNextQuickSlots has problems with wb+ and rb+ opened files */
-    n = ftell(stream);
-    freopen(file_path(QUICKSLOT_FILE, "rb"),"rb",stream);
-    fseek(stream,n,SEEK_SET);
-    while ((size = readNextQuickSlots(stream, server, &n, name, quickslots)) != 0)
-    {
-        if (!strcmp(ServerName, server) && n == ServerPort && !strcmp(cpl.name, name))
-        {
-            if ((n = w - size) != 0)
-            {
-                char *buf;
-                long  pos = ftell(stream);
-                freopen(file_path(QUICKSLOT_FILE, "rb+"),"rb+",stream);
-                fseek(stream, 0, SEEK_END);
-                w = ftell(stream) - pos;
-                buf = (char *)malloc(w);
-                fseek(stream, pos, SEEK_SET);
-                fread(buf, 1, w, stream);
-                fseek(stream, pos + n, SEEK_SET);
-                fwrite(buf, 1, w, stream);
-                if (n < 0)
-                {
-                    w = ftell(stream);
-                    rewind(stream);
-                    buf = (char *)realloc(buf, w);
-                    fread(buf, 1, w, stream);
-                    freopen(file_path(QUICKSLOT_FILE, "wb+"), "wb+", stream);
-                    fwrite(buf, 1, w, stream);
-                }
-                free(buf);
-                fseek(stream, pos, SEEK_SET);
-            }
-            fseek(stream, -size, SEEK_CUR);
-            for (n = 0; n != MAX_QUICK_SLOTS; ++n)
-            {
-                fwrite(&quick_slots[n].shared.is_spell, sizeof(Boolean), 1, stream);
-                if (quick_slots[n].shared.is_spell == FALSE)
-                {
-                    fwrite(&quick_slots[n].item.nr, sizeof(int), 1, stream);
-                    fwrite(quick_slots[n].name.name, sizeof(char), strlen(quick_slots[n].name.name) + 1, stream);
-                }
-                else
-                {
-                    fwrite(&quick_slots[n].shared.tag, sizeof(int), 1, stream);
-                    fwrite(&quick_slots[n].spell.groupNr, sizeof(int), 1, stream);
-                    fwrite(&quick_slots[n].spell.classNr, sizeof(int), 1, stream);
-                }
-            }
-            fclose(stream);
-            freeQuickSlots(quick_slots, MAX_QUICK_SLOTS);
-            return;
-        }
-    }
-    freopen(file_path(QUICKSLOT_FILE, "rb+"),"rb+",stream);
-    fseek(stream, 0, SEEK_END);
-    fwrite(&ServerName, sizeof(char), strlen(ServerName) + 1, stream);
-    fwrite(&ServerPort, sizeof(int), 1, stream);
-    fwrite(&cpl.name, sizeof(char), strlen(cpl.name) + 1, stream);
+
     for (n = 0; n != MAX_QUICK_SLOTS; ++n)
     {
-        fwrite(&quick_slots[n].shared.is_spell, sizeof(Boolean), 1, stream);
         if (quick_slots[n].shared.is_spell == FALSE)
         {
-            fwrite(&quick_slots[n].item.nr, sizeof(int), 1, stream);
-            fwrite(quick_slots[n].name.name, sizeof(char), strlen(quick_slots[n].name.name) + 1, stream);
+            item *ob = locate_item_from_inv(cpl.ob->inv, quick_slots[n].item.tag);
+            item_index = locate_item_nr_from_tag(cpl.ob->inv, quick_slots[n].item.tag);
+            if (ob != NULL)
+            {   // the numbers etc. change each log in, the names stay the same thought.
+                // item_qua = 255 is unidentified
+                sprintf(buf,"ITEM#%s#%d#%d\n", ob->s_name, item_index, ob->item_qua );
+                fputs(buf, stream);
+           }
+           else
+           {
+                sprintf(buf,"EMPTY#\n");
+                fputs(buf, stream);
+           }
         }
         else
         {
-            fwrite(&quick_slots[n].shared.tag, sizeof(int), 1, stream);
-            fwrite(&quick_slots[n].spell.groupNr, sizeof(int), 1, stream);
-            fwrite(&quick_slots[n].spell.classNr, sizeof(int), 1, stream);
+            sprintf(buf,"SPELL#%d#%d#%d\n",quick_slots[n].spell.groupNr, quick_slots[n].spell.classNr, quick_slots[n].shared.tag);
+            fputs(buf, stream);
         }
     }
     fclose(stream);
-    freeQuickSlots(quick_slots, MAX_QUICK_SLOTS);
 }
+
 void widget_event_target(int x, int y, SDL_Event event)
 {
     /* combat modus */

I also changed the direction of the count, instead of counting from the top of the inventory, I started from the bottom.  This allowed me to go on holidays and use several different computers with longish gaps between using them with relatively few problems.  These changes were in item.c
Code: [Select]
--- item.c Fri Jan 29 21:13:23 2010
+++ item.c Fri Jan 29 21:13:23 2010
@@ -247,25 +247,40 @@
     }
     return NULL;
 }
-
+/*
+    Changed to count from the bottom of the inventory rather then the top, as the items players use
+    tend to end up at the botton of the inventory rather then the top.  Also changed locate_item_tag_from_nr to match.
+*/
 int locate_item_nr_from_tag(item *op, int tag)
 {
     int count   = 0;
-    for (; op != NULL; count++,op = op->next)
+    if (op != NULL)
     {
-        if (op->tag == tag)
-            return count;
+        for (; op->next != NULL; op = op->next);
+        for (; op != NULL; count++,op = op->prev)
+        {
+            if (op->tag == tag)
+                return count;
+        }
     }
     return -1;
 }
 
+/*
+    Changed to count from the bottom of the inventory rather then the top, as the items players use
+    tend to end up at the botton of the inventory rather then the top.  Also changed locate_item_nr_from_tag to match.
+*/
 int locate_item_tag_from_nr(item *op, int nr)
 {
     int count   = 0;
-    for (; op != NULL; op = op->next, count++)
+    if (op != NULL)
     {
-        if (count == nr)
-            return op->tag;
+        for (; op->next != NULL; op = op->next);
+        for (; op != NULL; op = op->prev, count++)
+        {
+            if (count == nr)
+                return op->tag;
+        }
     }
     return -1;
 }

for Drace the old fixed client is still there in svn in \tags\0.9.7\client, I compiled it, ran it, and remembered why I liked the widget client...  The only problem I had with it was I had to tell it the correct meta server.  Not sure about the windows 7 bug though.

smacky

« Reply #9 on: 29, January 2010, 16:12:25 »
Quote
  It also saves a different file for each character which seems to prevent many of the problems of the original version. 

Very good. Yes, this is something long needed (obviously if we store quickslots server-side as Polyveg suggests this'll be the case then too).

Just to be sure, this is trunk (B5) you're modifying, right?

Anyway if you like I'll add you to the devteam and give you SF commit access so you can commit stuff directly and not wait for me to pass judgement. ;)

Do you have a SF account (if so, what's the user name)?

EDIT, BTW does this fix/get round this issue: https://www.daimonin.org/bugtracker/task/4
« Last Edit: 29, January 2010, 16:15:21 by smacky »

tarriel

« Reply #10 on: 30, January 2010, 07:13:09 »
Hi Smacky,

The patch here is for the B4 client. (as I (and others) actually play sometimes).  The patch for B5 is almost the same, line numbers might have changed a little.. 

If you will have me on the development team I would love to join.  I had a SF account years ago, I will get back to you shortly with the name, if I can get it reactivated (probably Monday I am told).

This should get around the bug track issue as I have avoided making a second copy of the quick slots.

smacky

« Reply #11 on: 30, January 2010, 17:52:03 »
OK I added you to varioous groups and reassigned that bug to you as well.

It's fine to fix bugs (as opposed too add features) in B4 (we can then issue an auto-update), though I wouldn't go out of your way to do this. But you must also ensure the bug is fixed in trunk (ie, B5) as well. Which can be a pain as the two codelines are ever diverging, so for some things it is literally having to implement the fix twice. Which is why I only work on B5.

Anyway, come Monday or so I'll give you commit.

Tags:
 

Related Topics

  Subject / Started by Replies Last post
1 Replies
847 Views
Last post 16, October 2005, 20:48:23
by Cheristheus
1 Replies
903 Views
Last post 22, June 2006, 01:09:15
by Unislash
2 Replies
4242 Views
Last post 09, February 2007, 15:18:54
by Alderan
6 Replies
1921 Views
Last post 16, March 2008, 12:20:20
by Fontus
7 Replies
2249 Views
Last post 23, December 2009, 02:45:56
by fiendstar