[CF-Devel] Patch submission: item renaming
crossfire-devel-admin at archives.real-time.com
crossfire-devel-admin at archives.real-time.com
Fri Aug 8 16:44:23 CDT 2003
Hello.
As discussed on this list, I implemented item renaming function.
Attached are the patches against current CVS.
I think i may be missing some CVS option, since file names aren't that
great it seems...
Sorry if patches are messy... decided to make one per modified file,
copied from cvs output.
Here's a short description on how renaming works:
* new field in object structure, 'custom_name'. This way custom name
doesn't break anything (slaying, altars, and so on)
* mark an item, then 'rename <new name>' to rename it, 'rename' to clean
the custom name
* custom name appears in the 'examine' output (regular name still
displayed, too)
* custom name is kept when dropping, but removed when selling (to avoid
bad jokes)
* custom name appears in inventory & floor item list instead of
'regular' name
* custom name is used in 'apply', 'mark', 'drop' commands (and maybe
others, any command using item_matched_string)
* regular name takes precedence over custom name. Thus if i have 'bottle
of wine' and 'haggises' named 'wine', 'mark wine' will mark the bottle
of wine, NOT the haggies. On the other hand 'drop wine' will drop both
bottle & haggises
I guess that pretty sums it...
I tested everything EXCEPT custom name loading, as i don't have lexx to
regenerate loader.c. But i copied the 'name' field, so it should be ok...
As usual feel free to try it, trash it, rename (lol) it, change it, eat
it (not sure you'd give any resistance, but we never know... been
playing too much my dragon char lol)
Nicolas 'Ryo'
-------------- next part --------------
RCS file: /cvsroot/crossfire/crossfire/common/arch.c,v
retrieving revision 1.24
diff -r1.24 arch.c
171c171,175
< if (strcasecmp(cp,op->name)==0 && !count) return 4;
---
>
if (strcasecmp(cp,op->name)==0 && !count) return 4;
>
else if (op->custom_name && strcasecmp(cp,op->custom_name)==0) {
>
pl->contr->count=count; /* May not do anything */
>
return 3;
>
}
-------------- next part --------------
RCS file: /cvsroot/crossfire/crossfire/common/loader.l,v
retrieving revision 1.47
diff -r1.47 loader.l
279a280,284
>
^custom_name{S} { char *yv=yval();
>
>
if (*yv=='\0') LOG(llevError,"Custom name without val\n");
>
else FREE_AND_COPY(op->custom, yv);
>
}
1170a1176,1178
>
if(op->custom_name && op->custom_name!=op2->custom_name) {
>
ADD_STRINGLINE_ENTRY(fastbuf,"custom_name ",op->custom_name,12);
>
}
-------------- next part --------------
RCS file: /cvsroot/crossfire/crossfire/common/object.c,v
retrieving revision 1.70
diff -r1.70 object.c
125c125,126
< (ob1->name != ob2->name) ||
---
>
(ob1->name != ob2->name) ||
>
(ob1->custom_name != ob2->custom_name) ||
500c501,502
< op->name_pl = NULL;
---
>
op->name_pl = NULL;
>
op->custom_name = NULL;
524a527
>
if (op->custom_name!=NULL) FREE_AND_CLEAR_STR(op->custom_name);
600c603,605
< free_string(op->name_pl);
---
>
free_string(op->name_pl);
>
if(op->custom_name!=NULL)
>
free_string(op->custom_name);
623c628,630
< add_refcount(op->name_pl);
---
>
add_refcount(op->name_pl);
>
if(op->custom_name!=NULL)
>
add_refcount(op->custom_name);
705c712,713
< op->name_pl=NULL;
---
>
op->name_pl=NULL;
>
op->custom_name=NULL;
1005c1013,1014
< if(ob->name_pl!=NULL) FREE_AND_CLEAR_STR(ob->name_pl);
---
>
if(ob->name_pl!=NULL) FREE_AND_CLEAR_STR(ob->name_pl);
>
if(ob->custom_name!=NULL) FREE_AND_CLEAR_STR(ob->custom_name);
-------------- next part --------------
RCS file: /cvsroot/crossfire/crossfire/include/object.h,v
retrieving revision 1.31
diff -r1.31 object.h
111c111
< char *name_pl; /* The plural name of the object */
---
>
char *name_pl; /* The plural name of the object */
214a215,216
>
>
char *custom_name; /* Custom name assigned by player */
-------------- next part --------------
RCS file: /cvsroot/crossfire/crossfire/include/sproto.h,v
retrieving revision 1.93
diff -r1.93 sproto.h
227a228
>
int command_rename_item(object *op, char *params);
-------------- next part --------------
RCS file: /cvsroot/crossfire/crossfire/server/c_object.c,v
retrieving revision 1.50
diff -r1.50 c_object.c
1388c1388,1397
< buf[0]='\0';
---
>
buf[0]='\0';
>
>
if(tmp->custom_name) {
>
strcpy(buf,"You name it ");
>
strncat(buf, tmp->custom_name, VERY_BIG_BUF-strlen(buf)-1);
>
buf[VERY_BIG_BUF-1]=0;
>
new_draw_info(NDI_UNIQUE, 0,op,buf);
>
buf[0]='\0';
>
}
>
1717a1727,1749
>
int command_rename_item(object *op, char *params)
>
{
>
char buf[VERY_BIG_BUF];
>
>
object *mark=find_marked_object(op);
>
if (!mark) {
>
new_draw_info(NDI_UNIQUE,0,op,"Rename what object?");
>
return 1;
>
}
>
>
if(params == NULL) {
>
if(mark->custom_name) FREE_AND_CLEAR_STR(mark->custom_name);
>
sprintf(buf,"You stop calling your %s with weird names.",query_base_name(mark,mark->nrof>1?1:0));
>
} else {
>
FREE_AND_COPY(mark->custom_name,params);
>
sprintf(buf,"Your %s will now be called %s.",query_base_name(mark,mark->nrof>1?1:0),params);
>
}
>
>
new_draw_info(NDI_UNIQUE, 0, op,buf);
>
esrv_update_item(UPD_NAME,op,mark);
>
>
return 1;
>
}
-------------- next part --------------
RCS file: /cvsroot/crossfire/crossfire/server/commands.c,v
retrieving revision 1.37
diff -r1.37 commands.c
94c94,95
< {"quit", command_quit, 0.0},
---
>
{"quit", command_quit, 0.0},
>
{"rename", command_rename_item, 0.0},
-------------- next part --------------
RCS file: /cvsroot/crossfire/crossfire/server/shop.c,v
retrieving revision 1.22
diff -r1.22 shop.c
527c527,530
< }
---
>
}
>
>
if(op->custom_name) FREE_AND_CLEAR_STR(op->custom_name);
>
-------------- next part --------------
RCS file: /cvsroot/crossfire/crossfire/socket/item.c,v
retrieving revision 1.24
diff -r1.24 item.c
223,226c223,234
< strncpy(item_n,query_base_name(tmp, 0),127);
< item_n[127]=0;
< len=strlen(item_n);
< item_p=query_base_name(tmp, 1);
---
>
if (!tmp->custom_name) {
>
strncpy(item_n,query_base_name(tmp, 0),127);
>
item_n[127]=0;
>
len=strlen(item_n);
>
item_p=query_base_name(tmp, 1);
>
}
>
else {
>
strncpy(item_n,tmp->custom_name,127);
>
item_n[127]=0;
>
len=strlen(item_n);
>
item_p=tmp->custom_name;
>
}
302,305c310,321
< strncpy(item_n,query_base_name(tmp, 0),127);
< item_n[127]=0;
< len=strlen(item_n);
< item_p=query_base_name(tmp, 1);
---
>
if (!tmp->custom_name) {
>
strncpy(item_n,query_base_name(tmp, 0),127);
>
item_n[127]=0;
>
len=strlen(item_n);
>
item_p=query_base_name(tmp, 1);
>
}
>
else {
>
strncpy(item_n,tmp->custom_name,127);
>
item_n[127]=0;
>
len=strlen(item_n);
>
item_p=tmp->custom_name;
>
}
398a415,427
>
>
if (!op->custom_name) {
>
strncpy(item_n,query_base_name(op, 0),127);
>
item_n[127]=0;
>
len=strlen(item_n);
>
item_p=query_base_name(op, 1);
>
}
>
else {
>
strncpy(item_n,op->custom_name,127);
>
item_n[127]=0;
>
len=strlen(item_n);
>
item_p=op->custom_name;
>
}
400,403d428
< strncpy(item_n,query_base_name(op, 0),127);
< item_n[127]=0;
< len=strlen(item_n);
< item_p=query_base_name(op, 1);
471,475c496,507
<
< strncpy(item_n,query_base_name(op, 0),127);
< item_n[127]=0;
< len=strlen(item_n);
< item_p=query_base_name(op, 1);
---
>
>
if(!op->custom_name) {
>
strncpy(item_n,query_base_name(op, 0),127);
>
item_n[127]=0;
>
len=strlen(item_n);
>
item_p=query_base_name(op, 1);
>
} else {
>
strncpy(item_n,op->custom_name,127);
>
item_n[127]=0;
>
len=strlen(item_n);
>
item_p=op->custom_name;
>
}
More information about the crossfire
mailing list