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

CF: patch: apply



Hi,

this is a quick patch to add two options to 'apply:
-a -> always apply (i.e. do nothing if already applied)
-u -> always unapply (i.e. do nothing if not applied)

This doesn't work for containers yet -:(

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

*** crossfire-0.93.7/server/apply.c	Tue Jan  6 10:29:23 1998
--- /usr/stud/stieber/crossfire/server/apply.c	Thu Jan 15 21:50:35 1998
***************
*** 1185,1194 ****
--- 1209,1222 ----
  /* op is the object that is causing object to be applied, tmp is the object
   * being applied.
   */
  
  int apply(object *op, object *tmp) {
+   return My_apply(op,tmp,0);
+ }
+ 
+ int My_apply(object *op, object *tmp, int Mode) {
    char buf[MAX_BUF];
    int inven;
  
    if(tmp==NULL) {
      if(op!=NULL&&op->type==PLAYER)
***************
*** 1748,1758 ****
      remove_ob(op);
      insert_ob_in_map(op,op->map);
      break;
    }
    case WAND:
!     if(apply_special(op,tmp))
        return 1;
      if(op->type==PLAYER) {
        if(QUERY_FLAG(tmp, FLAG_APPLIED)) {
          op->contr->shoottype=range_wand;
  	op->contr->chosen_item_spell= tmp->stats.sp;
--- 1774,1784 ----
      remove_ob(op);
      insert_ob_in_map(op,op->map);
      break;
    }
    case WAND:
!     if(My_apply_special(op,tmp,Mode))
        return 1;
      if(op->type==PLAYER) {
        if(QUERY_FLAG(tmp, FLAG_APPLIED)) {
          op->contr->shoottype=range_wand;
  	op->contr->chosen_item_spell= tmp->stats.sp;
***************
*** 1768,1778 ****
        else
  	CLEAR_FLAG(op, FLAG_READY_WAND);
      }
      return 1;
    case ROD:
!     if(apply_special(op,tmp))
        return 1;
      if(op->type==PLAYER) {
        if(QUERY_FLAG(tmp, FLAG_APPLIED)) {
          op->contr->shoottype=range_rod;
          op->contr->chosen_item_spell=tmp->stats.sp;
--- 1794,1804 ----
        else
  	CLEAR_FLAG(op, FLAG_READY_WAND);
      }
      return 1;
    case ROD:
!     if(My_apply_special(op,tmp,Mode))
        return 1;
      if(op->type==PLAYER) {
        if(QUERY_FLAG(tmp, FLAG_APPLIED)) {
          op->contr->shoottype=range_rod;
          op->contr->chosen_item_spell=tmp->stats.sp;
***************
*** 1788,1798 ****
        else
  	CLEAR_FLAG(op, FLAG_READY_ROD);
      }
      return 1;
    case HORN:
!     if(apply_special(op,tmp))
        return 1;
      if(op->type==PLAYER) {
        if(QUERY_FLAG(tmp, FLAG_APPLIED)) {
          op->contr->shoottype=range_horn;
          op->contr->chosen_item_spell=tmp->stats.sp;
--- 1814,1824 ----
        else
  	CLEAR_FLAG(op, FLAG_READY_ROD);
      }
      return 1;
    case HORN:
!     if(My_apply_special(op,tmp,Mode))
        return 1;
      if(op->type==PLAYER) {
        if(QUERY_FLAG(tmp, FLAG_APPLIED)) {
          op->contr->shoottype=range_horn;
          op->contr->chosen_item_spell=tmp->stats.sp;
***************
*** 1808,1818 ****
        else
  	CLEAR_FLAG(op, FLAG_READY_HORN);
      }
      return 1;
    case BOW:
!     if(apply_special(op,tmp))
        return 0;
      if(QUERY_FLAG(tmp, FLAG_APPLIED)) {
        new_draw_info_format(NDI_UNIQUE, 0, op,
  	"You will now fire %s with %s.",
  	      tmp->race ? tmp->race : "nothing", query_name(tmp));
--- 1834,1844 ----
        else
  	CLEAR_FLAG(op, FLAG_READY_HORN);
      }
      return 1;
    case BOW:
!     if(My_apply_special(op,tmp,Mode))
        return 0;
      if(QUERY_FLAG(tmp, FLAG_APPLIED)) {
        new_draw_info_format(NDI_UNIQUE, 0, op,
  	"You will now fire %s with %s.",
  	      tmp->race ? tmp->race : "nothing", query_name(tmp));
***************
*** 1822,1832 ****
        }
      }
      return 1;
  #ifdef ALLOW_SKILLS
    case SKILL:   /* allows skill tools  to be used -b.t */
!     if(apply_special(op,tmp))
        return 0;
      if((!tmp->invisible||op->type!=PLAYER)&&QUERY_FLAG(tmp, FLAG_APPLIED)) {
          SET_FLAG(op, FLAG_READY_SKILL);
          op->chosen_skill=tmp;
          if(op->type==PLAYER) {
--- 1848,1858 ----
        }
      }
      return 1;
  #ifdef ALLOW_SKILLS
    case SKILL:   /* allows skill tools  to be used -b.t */
!     if(My_apply_special(op,tmp,Mode))
        return 0;
      if((!tmp->invisible||op->type!=PLAYER)&&QUERY_FLAG(tmp, FLAG_APPLIED)) {
          SET_FLAG(op, FLAG_READY_SKILL);
          op->chosen_skill=tmp;
          if(op->type==PLAYER) {
***************
*** 1854,1864 ****
    case HELMET:
    case RING:
    case CLOAK:
  /* Mol(mol@meryl.csd.uu.se) compressed return & apply_s into one statement */
  /* Frank: If done this way, a ! must be prepended */
!     return !apply_special(op,tmp);
    case DRINK:
    case FOOD:
    case FLESH:
      if(QUERY_FLAG(tmp, FLAG_UNPAID)) {
        new_draw_info(NDI_UNIQUE, 0,op,"You should pay for it first.");
--- 1880,1890 ----
    case HELMET:
    case RING:
    case CLOAK:
  /* Mol(mol@meryl.csd.uu.se) compressed return & apply_s into one statement */
  /* Frank: If done this way, a ! must be prepended */
!     return !My_apply_special(op,tmp,Mode);
    case DRINK:
    case FOOD:
    case FLESH:
      if(QUERY_FLAG(tmp, FLAG_UNPAID)) {
        new_draw_info(NDI_UNIQUE, 0,op,"You should pay for it first.");
***************
*** 2058,2067 ****
--- 2084,2097 ----
    } else
      for(tmp=op->below;tmp!=NULL&&!apply(op,tmp);tmp=tmp->below);
  }
  
  int apply_special(object *who,object *op) { /* wear/wield */
+   return My_apply_special(who,op,0);
+ }
+ 
+ int My_apply_special(object *who,object *op,int Mode) { /* wear/wield */
    object *tmp;
    char buf[MAX_BUF];
    int i;
  
    if(who==NULL) {
***************
*** 2072,2081 ****
--- 2102,2112 ----
    if(op->env!=who) {
      new_draw_info(NDI_UNIQUE, 0,who,"You must get it first.");
      return 1;
    }
    if(QUERY_FLAG(op,FLAG_APPLIED)) {
+     if (Mode<0) return 0;
      if (QUERY_FLAG(op, FLAG_CURSED) || QUERY_FLAG(op, FLAG_DAMNED))
      {
        new_draw_info_format(NDI_UNIQUE, 0, who,
  	"No matter how hard you try, you just can't\nremove %s.",
  	      query_name(op));
***************
*** 2170,2179 ****
--- 2201,2211 ----
        } else
  	  draw_inventory(who);
  
      return 0;
    }
+   if (Mode>0) return 0;
    if (QUERY_FLAG(op, FLAG_UNPAID)) {
      new_draw_info(NDI_UNIQUE, 0,who, "You should pay for it first.\n");
      return 0;
    }
    i=0;
*** crossfire-0.93.7/server/c_object.c	Tue Jan  6 10:29:23 1998
--- /usr/stud/stieber/crossfire/server/c_object.c	Thu Jan 15 21:44:35 1998
***************
*** 377,389 ****
    if (!params) {
      apply_below(op);
      return 0;
    }
    else {
!     object *inv=find_best_object_match(op, params);
      if (inv) {
! 	if(!apply(op,inv)) {
  	  new_draw_info_format(NDI_UNIQUE, 0, op,
  	    "I don't know how to apply the %s.",query_name(inv));
  	}
      } else
  	  new_draw_info_format(NDI_UNIQUE, 0, op,
--- 377,405 ----
    if (!params) {
      apply_below(op);
      return 0;
    }
    else {
!     object *inv;
!     int Mode;
! 
!     Mode=0;
!     while (*params==' ') params++;
!     if (params[0]=='-' && params[1]=='a' && params[2]==' ')
!       {
! 	Mode=-1;
! 	params+=3;
!       }
!     if (params[0]=='-' && params[1]=='u' && params[2]==' ')
!       {
! 	Mode=1;
! 	params+=3;
!       }
!     while (*params==' ') params++;
!     inv=find_best_object_match(op, params);
      if (inv) {
! 	if(!My_apply(op,inv,Mode)) {
  	  new_draw_info_format(NDI_UNIQUE, 0, op,
  	    "I don't know how to apply the %s.",query_name(inv));
  	}
      } else
  	  new_draw_info_format(NDI_UNIQUE, 0, op,

-- 
Christian (Icho/Gandhi/Ribald @sunbroy53.informatik.tu-muenchen.de, 13326)
[to unsubscribe etc., send mail to crossfire-request@ifi.uio.no]