tile_st tile;
static int getname(P_ITEM pi, char* itemname){	tile_st tile;	int j, len, mode, used, ok, namLen;	if (pi == NULL)		return 1;	if (pi->name() != "#")	{		strcpy((char*)itemname, pi->name().ascii());		return strlen((char*)itemname)+1;	}	Map->SeekTile(pi->id(), &tile);	if (tile.flag2&0x80) strcpy((char*)itemname, "an ");	else if (tile.flag2&0x40) strcpy((char*)itemname, "a ");	else itemname[0]=0;	namLen = strlen( (char*)itemname );	mode=0;	used=0;	len=strlen((char *) tile.name);	for (j=0;j<len;j++)	{		ok=0;		if ((tile.name[j]=='%')&&(mode==0)) mode=2;		else if ((tile.name[j]=='%')&&(mode!=0)) mode=0;		else if ((tile.name[j]=='/')&&(mode==2)) mode=1;		else if (mode==0) ok=1;		else if ( ( mode == 1 ) && ( pi->amount() == 1 ) ) ok = 1;		else if ( ( mode == 2 ) && ( pi->amount() > 1 ) ) ok = 1;		if (ok)		{			itemname[namLen++] = tile.name[j];			itemname[namLen] = '\0';			if (mode) used=1;		}	}	return strlen((char*)itemname)+1;}