Crossfire Archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

CF: Patch: 'alias



Hi,

since I started to maintain our crossfire installation, I have added
several things to the server (and wrote a new (telnet-type) client
designed for clustered environments). Since the modifications and
additions have been discussed with the local users, I believe that
other people might find them useful, too.

I'm trying to get all those "quick & dirty" hacks a little organized now,
by separating the patches into separate diff files. I'm just sending
this one to the list; if you don't want to see any patches here, tell me.

A probably incomplete list of patches is:

1) a new command, 'alias, to give new names to objects
2) archetype patches to give proper names to some objects
x) a fix to make peaceful work properly
x) a REAL_WIZ #define to enable a real dungeon master
x) DM-'kick to kick players out of the game
x) 'shutdown to shut down the server (DM and non-DM)
x) using keys inside containers
x) using woodsman/mountaineer automatically when moving
x) merging more objects

"x)" just indicates that I don't know the order that I'll post them in -:)

I hoe the patches are "complete" --- I have to go through the diffs
and extract the pieces that belong to the feature in question.

So, here is the first one: The 'alias command lets you change the name of
a marked item, like "'alias foobar". "'alias" will restore the original
name and title. The original name and title will be restored automatically
when you prepare an aliased weapon (this should be fixed, but it's not
a very high priority). The old name will be appended in parenthesis; so
the names will be something like
   Icho's purse (Lepred's bag)
   a Killer (Dragonbane) +21

------------------------------ Cut ------------------------------

diff -r -C 5 crossfire-0.93.7/common/loader.c crossfire/common/loader.c
*** crossfire-0.93.7/common/loader.c	Tue Jan  6 10:29:18 1998
--- crossfire/common/loader.c	Fri Jan  9 11:54:17 1998
***************
*** 79,88 ****
--- 79,89 ----
    "no_skill_ident","glow_radius","is_blind","can_see_in_dark",
    "is_cauldron","randomitems","is_dust", "no_steal",
  #ifdef NPC_PROG
    "npc_status","npc_program",
  #endif
+   "real_name", "real_title",
  };
  
  char *variables[NR_OF_VARIABLES];
  
  /* This array equates the FLAG_ values with the V_ values.  Use -1 to
***************
*** 208,217 ****
--- 209,226 ----
    if(op->msg && op->msg!=op2->msg) {
      strcat(buf,"msg\n");
      strcat(buf,op->msg);
      strcat(buf,"endmsg\n");
    }
+   if(op->real_name && op->real_name!=op2->real_name) {
+     sprintf(buf2,"real_name %s\n",op->real_name);
+     strcat(buf,buf2);
+   }
+   if(op->real_title && op->real_title!=op2->real_title) {
+     sprintf(buf2,"real_title %s\n", op->real_title);
+     strcat(buf, buf2);
+   }
    if(op->other_arch!=op2->other_arch&&op->other_arch!=NULL && 
       op->other_arch->name) {
      sprintf(buf2,"other_arch %s\n",op->other_arch->name);
      strcat(buf,buf2);
    }
***************
*** 525,534 ****
--- 534,561 ----
        break;
      }
      if(op->title!=NULL)
        free_string(op->title);
      op->title = add_string(vbp);
+     break;
+   case V_REALNAME:
+     if(*vbp=='\0') {
+       LOG(llevError,"real_name without name\n");
+       break;
+     }
+     if(op->real_name!=NULL)
+       free_string(op->real_name);
+     op->real_name=add_string(vbp);
+     break;
+   case V_REALTITLE:
+     if(*vbp=='\0') {
+       LOG(llevError, "real_title without name\n");
+       break;
+     }
+     if(op->real_title!=NULL)
+       free_string(op->real_title);
+     op->real_title = add_string(vbp);
      break;
    case V_SPEED:
      sscanf(vbp,"%f",&op->speed);
      if (op->speed<0)
        op->speed_left=op->speed_left-RANDOM()%100/100.0;
diff -r -C 5 crossfire-0.93.7/common/object.c crossfire/common/object.c
*** crossfire-0.93.7/common/object.c	Tue Jan  6 10:29:18 1998
--- crossfire/common/object.c	Fri Jan  9 11:59:15 1998
***************
*** 96,105 ****
--- 96,106 ----
      if ((ob1->arch != ob2->arch) || (ob1->stats.sp != ob2->stats.sp) ||
  	(ob1->flags[0] != ob2->flags[0]) || (ob1->flags[1] != ob2->flags[1]) ||
  	((ob1->flags[2] & ~0x400000) != (ob2->flags[2] & ~ 0x400000)) ||
  	(ob1->flags[3] != ob2->flags[3]) || (ob1->magic != ob2->magic) ||
  	(ob1->name != ob2->name) || (ob1->title != ob2->title) ||
+ 	(ob1->real_name != ob2->real_name) || (ob1->real_title != ob2->real_title) ||
  	(ob1->msg != ob2->msg) || (ob1->stats.food != ob2->stats.food) ||
  	(ob1->protected != ob2->protected) || (ob1->immune != ob2->immune) ||
  	(ob1->vulnerable != ob2->vulnerable) || (ob1->weight != ob2->weight))
  	    return 0;
  
***************
*** 396,405 ****
--- 397,408 ----
    op->name = NULL;
    op->title = NULL;
    op->race = NULL;
    op->slaying = NULL;
    op->msg = NULL;
+   op->real_name=NULL;
+   op->real_title=NULL;
    clear_object(op);
  }
  /*
   * clear_object() frees everything allocated by an object, and also
   * clears all variables and flags to default settings.
***************
*** 426,435 ****
--- 429,446 ----
    }
    if(op->msg!=NULL) {
      free_string(op->msg);
      op->msg=NULL;
    }
+   if(op->real_name!=NULL) {
+     free_string(op->real_name);
+     op->real_name=NULL;
+   }
+   if(op->real_title!=NULL) {
+     free_string(op->real_title);
+     op->real_title=NULL;
+   }
    for (tmp=0; tmp<=(NUM_FLAGS/32); tmp++)
  	op->flags[tmp] = 0;
    op->map=NULL;
    op->below=NULL;
    op->above=NULL;
***************
*** 513,522 ****
--- 524,537 ----
      free_string(op->race);
    if(op->slaying!=NULL)
      free_string(op->slaying);
    if(op->msg!=NULL)
      free_string(op->msg);
+   if(op->real_name!=NULL)
+     free_string(op->real_name);
+   if(op->real_title!=NULL)
+     free_string(op->real_title);
    (void) memcpy((void *)((char *) op +offsetof(object,name)),
                  (void *)((char *) op2+offsetof(object,name)),
                  sizeof(object)-offsetof(object, name));
    if(is_freed)
      SET_FLAG(op,FLAG_FREED);
***************
*** 530,539 ****
--- 545,558 ----
      add_refcount(op->race);
    if(op->slaying!=NULL)
      add_refcount(op->slaying);
    if(op->msg!=NULL)
      add_refcount(op->msg);
+   if(op->real_name!=NULL)
+     add_refcount(op->real_name);
+   if(op->real_title!=NULL)
+     add_refcount(op->real_title);
    if(op2->speed<0)
      op->speed_left=op2->speed_left-RANDOM()%200/100.0;
    update_ob_speed(op);
  }
  
***************
*** 592,601 ****
--- 611,622 ----
    op->name=NULL;
    op->title=NULL;
    op->race=NULL;
    op->slaying=NULL;
    op->msg=NULL;
+   op->real_name=NULL;
+   op->real_title=NULL;
    op->next=objects;
    op->prev=NULL;
    op->active_next = NULL;
    op->active_prev = NULL;
    if(objects!=NULL)
***************
*** 889,898 ****
--- 910,927 ----
      ob->slaying=NULL;
    }
    if(ob->msg!=NULL) {
      free_string(ob->msg);
      ob->msg=NULL;
+   }
+   if(ob->real_name!=NULL) {
+     free_string(ob->real_name);
+     ob->real_name=NULL;
+   }
+   if(ob->real_title!=NULL) {
+     free_string(ob->real_title);
+     ob->real_title=NULL;
    }
    nroffreeobjects++;
  }
  
  /*
diff -r -C 5 crossfire-0.93.7/include/loader.h crossfire/include/loader.h
*** crossfire-0.93.7/include/loader.h	Tue Jan  6 10:29:29 1998
--- crossfire/include/loader.h	Fri Jan  9 11:48:59 1998
***************
*** 60,69 ****
--- 60,70 ----
    V_NO_SKILL_IDENT,V_GLOW_RADIUS,V_BLIND,V_SEE_IN_DARK,
    V_IS_CAULDRON,V_RANDOMITEMS,V_DUST,V_NO_STEAL,
  #ifdef NPCPROG
    V_NPC_STATUS,V_NPC_PROGRAM,
  #endif
+   V_REALNAME,V_REALTITLE,
    NR_OF_VARIABLES
  };
  
  extern char *variables[NR_OF_VARIABLES];
  
diff -r -C 5 crossfire-0.93.7/include/structs.h crossfire/include/structs.h
*** crossfire-0.93.7/include/structs.h	Tue Jan  6 10:29:29 1998
--- crossfire/include/structs.h	Fri Jan  9 11:49:32 1998
***************
*** 168,177 ****
--- 168,179 ----
    char *title;			/* Of foo, etc */
    char *race;			/* human, goblin, dragon, etc */
    char *slaying;		/* Which race to do double damage to */
    char *msg;			/* If this is a book/sign/magic mouth/etc */
  				/* If this is an exit, this is the filename */
+   char *real_name;
+   char *real_title;
  /* These variables are copied by memcpy() in copy_object(): */
    sint16 x,y;			/* Position in the map for this object */
    sint16 ox,oy;			/* For debugging: Where it was last inserted */
    float speed;                  /* The overall speed of this object */
    float speed_left;             /* How much speed is left to spend this round */
diff -r -C 5 crossfire-0.93.7/server/apply.c crossfire/server/apply.c
*** crossfire-0.93.7/server/apply.c	Tue Jan  6 10:29:23 1998
--- crossfire/server/apply.c	Fri Jan  9 12:06:27 1998
***************
*** 542,551 ****
--- 542,553 ----
      return 0;
    }
  }
  #else
  
+ extern void RemoveAliasName(object *);
+ 
  /* This does the prepare weapon scroll */
  
  int prepare_weapon(object *op, object *improver, object *weapon)
  {
      int sacrifice_count;
***************
*** 573,582 ****
--- 575,586 ----
      sacrifice_count = isqrt(sacrifice_count);
      weapon->level=sacrifice_count;
      new_draw_info(NDI_UNIQUE,0,op,"Your sacrifice was accepted.");
      eat_item(op, improver->slaying);
  
+     RemoveAliasName(weapon);
+ 
      new_draw_info_format(NDI_UNIQUE, 0, op,"Your *%s may be improved %d times.",
  	    weapon->name,sacrifice_count);
  
      tmp = (char *) malloc(strlen(weapon->name)+strlen(op->name) + 4);
      sprintf(tmp,"%s's %s",op->name,weapon->name);
***************
*** 632,642 ****
  /* This is the new improve weapon code */
  /* build_weapon returns 0 if it was not able to work. */
  /* #### We are hiding extra information about the weapon in the level and
     last_eat numbers for an object.  Hopefully this won't break anything ?? 
     level == max improve last_eat == current improve*/
! int improve_weapon(object *op,object *improver,object *weapon)
  {
    int sacrifice_count, sacrifice_needed=0;
  
    if(improver->stats.sp==IMPROVE_PREPARE) {
  	return prepare_weapon(op, improver, weapon);
--- 636,646 ----
  /* This is the new improve weapon code */
  /* build_weapon returns 0 if it was not able to work. */
  /* #### We are hiding extra information about the weapon in the level and
     last_eat numbers for an object.  Hopefully this won't break anything ?? 
     level == max improve last_eat == current improve*/
! static INLINE int improve_weapon_1(object *op,object *improver,object *weapon)
  {
    int sacrifice_count, sacrifice_needed=0;
  
    if(improver->stats.sp==IMPROVE_PREPARE) {
  	return prepare_weapon(op, improver, weapon);
***************
*** 739,748 ****
--- 743,771 ----
      new_draw_info(NDI_UNIQUE, 0,op,"Unknown improvement type.");
    }
    LOG(llevError,"improve_weapon: Got to end of function\n");
    return 0;
  }
+ 
+ int improve_weapon(object *op,object *improver,object *weapon)
+ {
+   object *tmp;
+   int Result;
+ 
+   tmp=NULL;
+   if (weapon->nrof>1)
+     {
+       tmp=get_split_ob(weapon,weapon->nrof-1);
+     }
+   Result=improve_weapon_1(op,improver,weapon);
+   if (tmp!=NULL)
+     {
+       insert_ob_in_ob(tmp,op);
+     }
+   return Result;
+ }
+ 
  #endif
  
  int check_improve_weapon (object *op, object *tmp)
  {
      object *otmp;
diff -r -C 5 crossfire-0.93.7/server/commands.c crossfire/server/commands.c
*** crossfire-0.93.7/server/commands.c	Tue Jan  6 10:29:23 1998
--- crossfire/server/commands.c	Fri Jan  9 12:13:21 1998
***************
*** 11,21 ****
--- 11,80 ----
  /* Added times to all the commands.  However, this was quickly done,
   * and probably needs more refinements.  All socket and DM commands
   * take 0 time.
   */
  
+ void RemoveAliasName(object *tmp)
+ {
+   if (tmp->real_name!=NULL)
+     {
+       if (tmp->name!=NULL)
+ 	{
+ 	  free_string(tmp->name);
+ 	}
+       if (tmp->title!=NULL)
+ 	{
+ 	  free_string(tmp->title);
+ 	}
+       tmp->name=tmp->real_name;
+       tmp->title=tmp->real_title;
+       tmp->real_name=NULL;
+       tmp->real_title=NULL;
+     }
+ }
  
+ int command_alias (object *op, char *params)
+ {
+   object *tmp;
+ 
+   if ((tmp=find_marked_object(op))==NULL)
+     {
+       new_draw_info(NDI_UNIQUE, 0,op,"You need to mark an item.");
+       return 0;
+     }
+   if (tmp->type==WEAPON && tmp->level>0)
+     {
+       char Buffer[MAX_BUF];
+ 
+       sprintf(Buffer,"You can't alias %s",tmp->name);
+       new_draw_info(NDI_UNIQUE, 0,op,Buffer);
+       return 0;
+     }
+   if (tmp->nrof>0)
+     {
+       tmp=get_split_ob(tmp,1);
+     }
+   else
+     {
+       remove_ob(tmp);
+     }
+   RemoveAliasName(tmp);
+   if (params!=NULL)
+     {
+       char Buffer[256];
+ 
+       tmp->real_name=tmp->name;
+       tmp->real_title=tmp->title;
+       tmp->name=add_string(params);
+       sprintf(Buffer,"(%s)",tmp->real_name);
+       tmp->title=add_string(Buffer);
+     }
+   insert_ob_in_ob(tmp,op);
+   return 0;
+ }
+ 
+ 
  /*
   * Normal game commands
   */
  CommArray_s Commands[] = {
    {"save", command_save,	0.0},
***************
*** 36,45 ****
--- 95,105 ----
  #endif
  #ifdef DEBUG_MALLOC_LEVEL
    {"verify", command_malloc_verify,0.0},
  #endif
    {"add", command_add,		0.0},
+   {"alias", command_alias,      0.0},
    {"apply", command_apply,	1.0},	/* should be variable */
    {"archs", command_archs,	0.0},
    {"bell", command_bell,	0.0},
    {"berzerk", command_berzerk,	0.0},
    {"bind", command_bind,	0.0},
[to unsubscribe etc., send mail to crossfire-request@ifi.uio.no]


Follow-Ups: