Difference for server/shop.c from version 1.25 to 1.26


version 1.25 version 1.26
Line 1
 
Line 1
 /*  /*
  * static char *rcsid_shop_c =   * static char *rcsid_shop_c =
  *   "$Id: shop.c,v 1.25 2003/10/26 06:56:57 mwedel Exp $";   *   "$Id: shop.c,v 1.26 2004/02/17 03:38:59 mwedel Exp $";
  */   */
   
 /*  /*
Line 59
 
Line 59
 int query_cost(object *tmp, object *who, int flag) {  int query_cost(object *tmp, object *who, int flag) {
   int val;    int val;
   int number; /* used to better calculate value */    int number; /* used to better calculate value */
   int charisma;      int no_bargain;
       float diff;
       float ratio;
   
       no_bargain = flag & F_NO_BARGAIN;
       flag &= ~F_NO_BARGAIN;
   
   if (tmp->type==MONEY) return (tmp->nrof * tmp->value);    if (tmp->type==MONEY) return (tmp->nrof * tmp->value);
   if (tmp->type==GEM) {    if (tmp->type==GEM) {
Line 84
 
Line 89
         LOG(llevError, "Asking for buy-value of unidentified object.");          LOG(llevError, "Asking for buy-value of unidentified object.");
         val = tmp->arch->clone.value * 50 * number;          val = tmp->arch->clone.value * 50 * number;
       }        }
       else /* Trying to sell something, or get true value */       else { /* Trying to sell something, or get true value */
         if (tmp->type == POTION)          if (tmp->type == POTION)
           val = number * 1000; /* Don't want to give anything away */            val = number * 1000; /* Don't want to give anything away */
         else {          else {
Line 96
 
Line 101
    else     else
      val = number * tmp->arch->clone.value / 3;       val = number * tmp->arch->clone.value / 3;
  }   }
        }
     } else { /* No archetype with this object */      } else { /* No archetype with this object */
       LOG(llevDebug,"In sell item: Have object with no archetype: %s\n", tmp->name);        LOG(llevDebug,"In sell item: Have object with no archetype: %s\n", tmp->name);
       if (flag == F_BUY) {        if (flag == F_BUY) {
Line 131
 
Line 137
   if (tmp->type==WAND) {    if (tmp->type==WAND) {
  /* Value of the wand is multiplied by the number of   /* Value of the wand is multiplied by the number of
  * charges.  the treasure code already sets up the value   * charges.  the treasure code already sets up the value
    * 50 charges is used as the baseline.
  */   */
  if (QUERY_FLAG(tmp, FLAG_IDENTIFIED) || !need_identify(tmp))   if (QUERY_FLAG(tmp, FLAG_IDENTIFIED) || !need_identify(tmp))
      val=(val*tmp->stats.food) / 50;       val=(val*tmp->stats.food) / 50;
Line 146
 
Line 153
     }      }
   }    }
   
 /* this  modification is for merchant skill      /* This modification is for bargaining skill.
  * now players with readied merchant skill get       * Now only players with max level in bargaining
  * more Cha up to the limit of modified Cha = 30.       * AND Cha = 30 will get optimal price.
  * -b.t. thomas@nomad.astro.psu.edu       * Thus charisma will never get useless.
        * -b.e. edler@heydernet.de
  */   */
   
   if (who!=NULL && who->type==PLAYER) {    if (who!=NULL && who->type==PLAYER) {
       float diff;   int lev_bargain = 0;
   
       charisma = who->stats.Cha;  /* used for SK_BARGAINING modification */   /* ratio determines how much of the price modification
    * will come from the basic stat charisma
    * the rest will come from the level in bargaining skill
    */
    ratio = 0.5;
   
       if (find_skill_by_number(who,SK_BARGAINING)) {        if (find_skill_by_number(who,SK_BARGAINING)) {
  charisma += (who->level+2)/3;       lev_bargain = find_skill_by_number(who,SK_BARGAINING)->level;
  if(charisma>30) charisma = 30;  
       }  
       if (cha_bonus[charisma]<=1.0) {  
  LOG(llevError,"Illegal charisma bonus, %d <=1.0", cha_bonus[charisma]);  
  diff=0.9; /*pretty bad case */  
       }        }
    if ( !no_bargain && (lev_bargain>0) )
        diff = (0.8 - 0.6*((lev_bargain+settings.max_level*0.05)
                            /(settings.max_level*1.05)));
       else        else
  /* Diff is now a float between 0 and 1 */       diff = 0.8;
  diff=(cha_bonus[charisma]-1)/(1+cha_bonus[charisma]);  
    diff *= 1-ratio;
   
    /* Diff is now a float between 0.2 and 0.8 */
    diff+=(cha_bonus[who->stats.Cha]-1)/(1+cha_bonus[who->stats.Cha])*ratio;
   
       /* we need to multiply these by 4.0 to keep buy costs roughly the same        /* we need to multiply these by 4.0 to keep buy costs roughly the same
        * (otherwise, you could buy a potion of charisma for around 400 pp.         * (otherwise, you could buy a potion of charisma for around 400 pp.
Line 181
 
Line 195
       else val *=4;        else val *=4;
   }    }
   
   /* I don't understand this code...., I'm changing it to      /* I don't think this should really happen - if it does, it indicates and
    use 0 instead of 1000000 if we're selling*/       * overflow of diff above.  That shoudl only happen if
   if(val<0) {       * we are selling objects - in that case, the person just
  if(flag==F_SELL)       * gets no money.
        */
       if(val<0)
  val=0;   val=0;
  else  
  val=1000000;  
   }  
   
   /* Unidentified stuff won't sell for more than 60gp */    /* Unidentified stuff won't sell for more than 60gp */
   if(flag==F_SELL && !QUERY_FLAG(tmp, FLAG_IDENTIFIED) && need_identify(tmp)) {    if(flag==F_SELL && !QUERY_FLAG(tmp, FLAG_IDENTIFIED) && need_identify(tmp)) {
Line 325
 
Line 338
 int pay_for_item(object *op,object *pl) {  int pay_for_item(object *op,object *pl) {
     int to_pay = query_cost(op,pl,F_BUY);      int to_pay = query_cost(op,pl,F_BUY);
     object *pouch;      object *pouch;
       int saved_money;
   
     if (to_pay==0) return 1;      if (to_pay==0) return 1;
     if(to_pay>query_money(pl)) return 0;      if(to_pay>query_money(pl)) return 0;
   
       /* We compare the paid price with the one for a player
        * without bargaining skill.
        * This determins the amount of exp (if any) gained for bargaining.
        */
       saved_money = query_cost(op,pl,F_BUY | F_NO_BARGAIN) - to_pay;
   
       if (saved_money > 0)
         change_exp(pl,saved_money,"bargaining",SK_EXP_NONE);
   
     to_pay = pay_from_container(op, pl, to_pay);      to_pay = pay_from_container(op, pl, to_pay);
   
     for (pouch=pl->inv; (pouch!=NULL) && (to_pay>0); pouch=pouch->below) {      for (pouch=pl->inv; (pouch!=NULL) && (to_pay>0); pouch=pouch->below) {
Line 517
 
Line 540
   object *tmp;    object *tmp;
   object *pouch;    object *pouch;
   archetype *at;    archetype *at;
     int extra_gain;
   
   if(pl==NULL||pl->type!=PLAYER) {    if(pl==NULL||pl->type!=PLAYER) {
     LOG(llevDebug,"Object other than player tried to sell something.\n");      LOG(llevDebug,"Object other than player tried to sell something.\n");
Line 537
 
Line 561
     identify(op);      identify(op);
     return;      return;
   }    }
     /* We compare the price with the one for a player
      * without bargaining skill.
      * This determins the amount of exp (if any) gained for bargaining.
      * exp/10 -> 1 for each gold coin
      */
     extra_gain = i - query_cost(op,pl,F_SELL | F_NO_BARGAIN);
   
     if (extra_gain > 0)
       change_exp(pl,extra_gain/10,"bargaining",SK_EXP_NONE);
    
   for (count=0; coins[count]!=NULL; count++) {    for (count=0; coins[count]!=NULL; count++) {
       at = find_archetype(coins[count]);        at = find_archetype(coins[count]);
       if (at==NULL) LOG(llevError, "Could not find %s archetype", coins[count]);        if (at==NULL) LOG(llevError, "Could not find %s archetype", coins[count]);


Legend:
line(s) removed in v.1.25 
line(s) changed
 line(s) added in v.1.26

File made using version 1.98 of cvs2html by leaf at 2011-07-21 17:44