Date: Sunday August 6, 2000 @ 22:27 Author: cvs Update of /home/cvs/CVS/client In directory boltzmann.eecs.berkeley.edu:/tmp/cvs-serv6826 Modified Files: CHANGES Protocol client.h commands.c gx11.c item.c item.h player.c x11.c Log Message: The following matches a change made to the server which includes two piece item names to make the item names in the client appear more perfect. Protocol: Updated to document the new item name transmission method. client.h: Update SC version to 1024. item.h: Remove name and o_name from item structure, instead there is now d_name, s_name, and p_name, representing the display name, singular name, and plural name. display name is derived from the s/p names plus nrof value. commands.c: Chance strncpy to memcpy, as a null character is used to seperate the two name values. UpdateItemCmd is also modified to supply an empty string to set_item_values instead of the same name if the name is unchanged. gx11.c, player.c, x11.c: use d_name instead of name to correspond with changes to item.h item.c: Update item initialization and clearing functions with new name elements. Update set_item_values with new two piece name support. remove adding 'a' and 'an' prefix to singular objects, as it generally doesn't look good in the look window and isn't all that useful in the inventory window either. Mark Wedel 8/6/2000 **************************************** Index: client/CHANGES diff -u client/CHANGES:1.17 client/CHANGES:1.18 --- client/CHANGES:1.17 Tue Jun 20 21:45:47 2000 +++ client/CHANGES Sun Aug 6 22:27:22 2000 @@ -1,5 +1,28 @@ -"$Id: CHANGES,v 1.17 2000/06/21 04:45:47 cvs Exp $" +"$Id: CHANGES,v 1.18 2000/08/07 05:27:22 cvs Exp $" Top of CVS tree: + +The following matches a change made to the server which includes two +piece item names to make the item names in the client appear more perfect. +Protocol: Updated to document the new item name transmission method. +client.h: Update SC version to 1024. +item.h: Remove name and o_name from item structure, instead there is now + d_name, s_name, and p_name, representing the display name, singular name, + and plural name. display name is derived from the s/p names plus nrof value. +commands.c: Chance strncpy to memcpy, as a null character is used to seperate + the two name values. UpdateItemCmd is also modified to supply an empty + string to set_item_values instead of the same name if the name is unchanged. +gx11.c, player.c, x11.c: use d_name instead of name to correspond with + changes to item.h +item.c: Update item initialization and clearing functions with new name + elements. Update set_item_values with new two piece name support. + remove adding 'a' and 'an' prefix to singular objects, as it generally + doesn't look good in the look window and isn't all that useful in the + inventory window either. +Mark Wedel 8/6/2000 + +item_types, item_types.h: Update with new item types - MSW 7/19/2000 + +player.c: Comment out command buffering output - MSW 7/19/2000 ------------------------------------------------------------------------------ Changes for 0.95.6: Index: client/Protocol diff -u client/Protocol:1.2 client/Protocol:1.3 --- client/Protocol:1.2 Sat Jun 3 00:20:23 2000 +++ client/Protocol Sun Aug 6 22:27:22 2000 @@ -393,7 +393,9 @@ to the client before actually sending a face number. name is the name of the object. The first byte of this field is the - text length of the name. + text length of the name. Starting at SC 1024, this name is two + strings, with a null seperation. The first byte (length) is the + length for both of these strings. Below here are fields/differences for the item1 command. @@ -827,6 +829,9 @@ SC version 1022 -> 1023: Server supports sending png images (addition of image command). + +SC version 1023 -> 1024: Server will send two part names (described in +item command) which contains the singular & plural form of the name) ------------------------------------------------------------------------------ Todo: Index: client/client.h diff -u client/client.h:1.4 client/client.h:1.5 --- client/client.h:1.4 Sat Jun 3 00:20:23 2000 +++ client/client.h Sun Aug 6 22:27:22 2000 @@ -41,7 +41,7 @@ #endif #define VERSION_CS 1022 -#define VERSION_SC 1023 +#define VERSION_SC 1024 #ifdef GTK_CLIENT #define VERSION_INFO "GTK C Client" Index: client/commands.c diff -u client/commands.c:1.3 client/commands.c:1.4 --- client/commands.c:1.3 Sat Jun 3 00:20:23 2000 +++ client/commands.c Sun Aug 6 22:27:22 2000 @@ -1,6 +1,6 @@ /* * static char *rcsid_commands_c = - * "$Id: commands.c,v 1.3 2000/06/03 07:20:23 cvs Exp $"; + * "$Id: commands.c,v 1.4 2000/08/07 05:27:22 cvs Exp $"; */ /* Crossfire client, a client program for the crossfire program. @@ -329,7 +329,7 @@ face= GetInt_String(data+i); i+=4; nlen=data[i++]; - strncpy(name, (const char*)data+i, nlen); + memcpy(name, (const char*)data+i, nlen); name[nlen]='\0'; i+= nlen; @@ -382,7 +382,7 @@ weight = GetInt_String(data+pos); pos+=4; face = GetInt_String(data+pos); pos+=4; nlen = data[pos++]; - strncpy(name, (char*)data+pos, nlen); + memcpy(name, (char*)data+pos, nlen); pos += nlen; name[nlen]='\0'; update_item (tag, loc, name, weight, face, flags,0,0,-1); @@ -421,7 +421,7 @@ weight = GetInt_String(data+pos); pos+=4; face = GetInt_String(data+pos); pos+=4; nlen = data[pos++]; - strncpy(name, (char*)data+pos, nlen); + memcpy(name, (char*)data+pos, nlen); pos += nlen; name[nlen]='\0'; anim = GetShort_String(data+pos); pos+=2; @@ -456,7 +456,7 @@ /* Copy all of these so we can pass the values to update_item and * don't need to figure out which ones were modified by this function. */ - strcpy(name, ip->name); + *name='\0'; loc=ip->env?ip->env->tag:0; weight=ip->weight * 1000; face = ip->face; @@ -485,7 +485,7 @@ } if (sendflags & UPD_NAME) { nlen = data[pos++]; - strncpy(name, (char*)data+pos, nlen); + memcpy(name, (char*)data+pos, nlen); pos += nlen; name[nlen]='\0'; } Index: client/gx11.c diff -u client/gx11.c:1.5 client/gx11.c:1.6 --- client/gx11.c:1.5 Sat Jun 3 00:20:23 2000 +++ client/gx11.c Sun Aug 6 22:27:22 2000 @@ -1,6 +1,6 @@ /* * static char *rcsid_xio_c = - * "$Id: gx11.c,v 1.5 2000/06/03 07:20:23 cvs Exp $"; + * "$Id: gx11.c,v 1.6 2000/08/07 05:27:22 cvs Exp $"; * * This file handles all the windowing stuff. The idea is * that all of it is in one file, so to port to different systems @@ -2104,7 +2104,7 @@ strcpy (buffer[0]," "); - strcpy (buffer[1], tmp->name); + strcpy (buffer[1], tmp->d_name); if (l->show_icon == 0) strcat (buffer[1], tmp->flags); @@ -3444,7 +3444,7 @@ void open_container (item *op) { look_list.env = op; - sprintf (look_list.title, "%s:", op->name); + sprintf (look_list.title, "%s:", op->d_name); draw_list (&look_list); } Index: client/item.c diff -u client/item.c:1.2 client/item.c:1.3 --- client/item.c:1.2 Tue Apr 18 23:20:59 2000 +++ client/item.c Sun Aug 6 22:27:22 2000 @@ -101,10 +101,6 @@ for (itmp = it->env->inv; itmp!=NULL; itmp=itmp->next) { /* If the next item is higher in the order, insert here */ if (itmp->type >= it->type) { -#if 0 - fprintf(stderr,"Inserting object %s (%d) before %s (%d)\n", - it->name, it->type, itmp->name, itmp->type); -#endif /* If we have a previous object, update the list. If * not, we need to update the environment to point to us */ @@ -175,8 +171,9 @@ exit(0); op->next = op->prev = NULL; - copy_name (op->name, ""); - copy_name (op->o_name, ""); + copy_name (op->d_name, ""); + copy_name (op->s_name, ""); + copy_name (op->p_name, ""); op->inv = NULL; op->env = NULL; op->tag = 0; @@ -294,8 +291,9 @@ op->prev = NULL; op->env = NULL; op->tag = 0; - copy_name (op->name, ""); - copy_name (op->o_name, ""); + copy_name (op->d_name, ""); + copy_name (op->s_name, ""); + copy_name (op->p_name, ""); op->inv = NULL; op->env = NULL; op->tag = 0; @@ -342,7 +340,6 @@ tmp->next->prev = op; tmp->next = op; } -/* fprintf(stderr,"Added object %s to %s\n", op->name, env->name);*/ } /* @@ -463,30 +460,63 @@ return; } if (nrof<0) { - copy_name (op->name, name); + char *cp; + /* for s_name and p_name, we want to truncate the prefix (number + * or a/an), so that when it gets remade, it looks OK. + */ + copy_name (op->d_name, name); op->nrof = get_nrof(name); + cp = strchr(name, ' '); + if (cp) { + cp++; + copy_name (op->s_name, cp); + copy_name (op->p_name, cp); + } + else { + copy_name (op->s_name, name); + copy_name (op->p_name, name); + } } else { /* we have a nrof - item1 command */ - int need_new_name=0; - /* Program always expect at least 1 object internall */ if (nrof==0) nrof=1; - /* Little hack to force it to make a new name if nrof changes */ - if (nrof != op->nrof) need_new_name=1; - op->nrof = nrof; - /* Bunch of hacks here. First, the UpdItem command passes the - * same name to us, and nrof has been set by the first item command. - * So, if the name passed matches the name we used, don't - * recopy.. + if (*name!='\0') { + copy_name(op->s_name, name); + + /* Unfortunately, we don't get a length parameter, so we just have + * to assume that if it is a new server, it is giving us two piece + * names. + */ + if (csocket.sc_version>=1024) { + copy_name(op->p_name, name+strlen(name)+1); + } + else { /* If not new version, just use same for both */ + copy_name(op->p_name, name); + } + } + + /* Rather than try to get too clever on trying to figure out when + * to up d_name, just do it all the time. */ - if (strcmp(name, op->name)) { - copy_name (op->o_name, name); - sprintf(op->name,"%s %s", get_number(nrof), op->o_name); + if (op->nrof!=1) { + sprintf(op->d_name, "%s %s", get_number(nrof), op->p_name); + } else { + strcpy(op->d_name, op->s_name); +#if 0 +/* I don't think adding 'a' or 'an' to the name really adds much, and + * I think it actually detracts as it reduces the displayed name by that + * much, so I have disabled this for now. + */ + /* Deal with our a/an prefix properly */ + if (*op->s_name=='a' || *op->s_name=='e' || *op->s_name=='i' || + *op->s_name=='o' || *op->s_name=='u') + sprintf(op->d_name, "an %s", op->s_name); + else + sprintf(op->d_name, "a %s", op->s_name); +#endif } - else if (need_new_name) - sprintf(op->name,"%s %s", get_number(nrof), op->o_name); } if (op->env) op->env->inv_updated = 1; @@ -497,7 +527,7 @@ get_flags (op, flags); /* We don't sort the map, so lets not do this either */ if (op->env != map) - op->type =get_type_from_name(op->name); + op->type =get_type_from_name(op->s_name); update_item_sort(op); } @@ -546,9 +576,7 @@ return map; } -/* This makes debugging much easier. declare it static so it isn't - * multiple defined at the link stage. - */ +/* Upates an item with new attributes. */ void update_item(int tag, int loc, char *name, int weight, int face, int flags, int anim, int animspeed, int nrof) { @@ -558,7 +586,10 @@ * being updated. */ if (player->tag==tag) { - copy_name (player->name, name); + copy_name (player->d_name, name); + /* I don't think this makes sense, as you can have + * two players merged together, so nrof should always be one + */ player->nrof = get_nrof(name); player->weight = (float) weight / 1000; player->face = face; @@ -581,6 +612,7 @@ /* * Prints players inventory, contain extra information for debugging purposes + * This isn't pretty, but is only used for debugging, so it doesn't need to be. */ void print_inventory (item *op) { @@ -591,14 +623,14 @@ int info_width = get_info_width(); if (l == 0) { - sprintf (buf, "%s's inventory (%d):", op->name, op->tag); + sprintf (buf, "%s's inventory (%d):", op->d_name, op->tag); sprintf (buf2, "%-*s%6.1f kg", info_width - 10, buf, op->weight); draw_info (buf2,NDI_BLACK); } l += 2; for (tmp = op->inv; tmp; tmp=tmp->next) { - sprintf (buf, "%*s- %d %s%s (%d)", l - 2, "", tmp->nrof, tmp->name, + sprintf (buf, "%*s- %d %s%s (%d)", l - 2, "", tmp->nrof, tmp->d_name, tmp->flags, tmp->tag); sprintf (buf2, "%-*s%6.1f kg", info_width - 8 - l, buf, tmp->nrof*tmp->weight); draw_info (buf2,NDI_BLACK); Index: client/item.h diff -u client/item.h:1.1 client/item.h:1.2 --- client/item.h:1.1 Sun Mar 28 21:11:25 1999 +++ client/item.h Sun Aug 6 22:27:22 2000 @@ -30,13 +30,14 @@ struct item_struct *prev; /* previous item in inventory */ struct item_struct *env; /* which items inventory is this item */ struct item_struct *inv; /* items inventory */ - char name[NAME_LEN]; /* item's full name w/o status information */ + char d_name[NAME_LEN]; /* item's full name w/o status information */ + char s_name[NAME_LEN]; /* item's singular name as sent to us */ + char p_name[NAME_LEN]; /* item's plural name as sent to us */ char flags[NAME_LEN]; /* item's status information */ sint32 tag; /* item identifier (0 = free) */ sint32 nrof; /* number of items */ float weight; /* how much item weights */ sint16 face; /* index for face array */ - char o_name[NAME_LEN]; /* name as sent with item1 command */ uint16 animation_id; /* Index into animation array */ uint8 anim_speed; /* how often to animate */ uint8 anim_state; /* last face in sequence drawn */ Index: client/player.c diff -u client/player.c:1.4 client/player.c:1.5 --- client/player.c:1.4 Wed Jul 19 23:49:32 2000 +++ client/player.c Sun Aug 6 22:27:22 2000 @@ -1,6 +1,6 @@ /* * static char *rcsid_player_c = - * "$Id: player.c,v 1.4 2000/07/20 06:49:32 cvs Exp $"; + * "$Id: player.c,v 1.5 2000/08/07 05:27:22 cvs Exp $"; */ #include <client.h> @@ -34,7 +34,7 @@ { cpl.ob->tag = tag; cpl.ob->nrof = 1; - copy_name (cpl.ob->name, name); + copy_name (cpl.ob->d_name, name); cpl.ob->weight = (float) weight / 1000; cpl.ob->face = face; } Index: client/x11.c diff -u client/x11.c:1.8 client/x11.c:1.9 --- client/x11.c:1.8 Tue Jun 20 21:45:47 2000 +++ client/x11.c Sun Aug 6 22:27:22 2000 @@ -1,6 +1,6 @@ /* * static char *rcsid_x11_c = - * "$Id: x11.c,v 1.8 2000/06/21 04:45:47 cvs Exp $"; + * "$Id: x11.c,v 1.9 2000/08/07 05:27:22 cvs Exp $"; */ /* Crossfire client, a client program for the crossfire program. @@ -1694,7 +1694,7 @@ } } /* draw name */ - strcpy (buf2, tmp->name); + strcpy (buf2, tmp->d_name); if (l->show_icon == 0) strcat (buf2, tmp->flags); @@ -1781,7 +1781,7 @@ void open_container (item *op) { look_list.env = op; - sprintf (look_list.title, "%s:", op->name); + sprintf (look_list.title, "%s:", op->d_name); draw_list (&look_list); }