home *** CD-ROM | disk | FTP | other *** search
/ The World of Computer Software / World_Of_Computer_Software-02-387-Vol-3of3.iso / d / d-linux.zip / dm-dist / limits.c < prev    next >
C/C++ Source or Header  |  1991-03-01  |  11KB  |  507 lines

  1. /* ************************************************************************
  2. *  file: limits.c , Limit and gain control module.        Part of DIKUMUD *
  3. *  Usage: Procedures controling gain and limit.                           *
  4. *  Copyright (C) 1990, 1991 - see 'license.doc' for complete information. *
  5. ************************************************************************* */
  6.  
  7. #include <stdio.h>
  8. #include <assert.h>
  9. #include "structs.h"
  10. #include "limits.h"
  11. #include "utils.h"
  12. #include "spells.h"
  13. #include "comm.h"
  14.  
  15. #define READ_TITLE(ch) (GET_SEX(ch) == SEX_MALE ?   \
  16.     titles[GET_CLASS(ch)-1][GET_LEVEL(ch)].title_m :  \
  17.     titles[GET_CLASS(ch)-1][GET_LEVEL(ch)].title_f)
  18.  
  19.  
  20. extern struct char_data *character_list;
  21. extern struct obj_data *object_list;
  22. extern struct title_type titles[4][25];
  23. extern struct room_data *world;
  24.  
  25. /* External procedures */
  26.  
  27. void update_pos( struct char_data *victim );                 /* in fight.c */
  28. void damage(struct char_data *ch, struct char_data *victim,  /*    do      */
  29.             int damage, int weapontype);
  30. struct time_info_data age(struct char_data *ch);
  31.  
  32.  
  33.  
  34. /* When age < 15 return the value p0 */
  35. /* When age in 15..29 calculate the line between p1 & p2 */
  36. /* When age in 30..44 calculate the line between p2 & p3 */
  37. /* When age in 45..59 calculate the line between p3 & p4 */
  38. /* When age in 60..79 calculate the line between p4 & p5 */
  39. /* When age >= 80 return the value p6 */
  40. int graf(int age, int p0, int p1, int p2, int p3, int p4, int p5, int p6)
  41. {
  42.  
  43.     if (age < 15)
  44.         return(p0);                               /* < 15   */
  45.     else if (age <= 29) 
  46.         return (int) (p1+(((age-15)*(p2-p1))/15));  /* 15..29 */
  47.     else if (age <= 44)
  48.         return (int) (p2+(((age-30)*(p3-p2))/15));  /* 30..44 */
  49.     else if (age <= 59)
  50.         return (int) (p3+(((age-45)*(p4-p3))/15));  /* 45..59 */
  51.     else if (age <= 79)
  52.         return (int) (p4+(((age-60)*(p5-p4))/20));  /* 60..79 */
  53.     else
  54.         return(p6);                               /* >= 80 */
  55. }
  56.  
  57.  
  58. /* The three MAX functions define a characters Effective maximum */
  59. /* Which is NOT the same as the ch->points.max_xxxx !!!          */
  60. int mana_limit(struct char_data *ch)
  61. {
  62.     int max;
  63.  
  64.     if (!IS_NPC(ch))
  65.         max = (100); /* + (graf(age(ch).year, 0,0,10,30,50,70,60)); */
  66.     else 
  67.         max = 100;
  68.  
  69.     return(max);
  70. }
  71.  
  72.  
  73. int hit_limit(struct char_data *ch)
  74. {
  75.     int max;
  76.  
  77.     if (!IS_NPC(ch))
  78.         max = (ch->points.max_hit) +
  79.               (graf(age(ch).year, 2,4,17,14,8,4,3));
  80.     else 
  81.         max = (ch->points.max_hit);
  82.  
  83.  
  84. /* Class/Level calculations */
  85.  
  86. /* Skill/Spell calculations */
  87.     
  88.   return (max);
  89. }
  90.  
  91.  
  92. int move_limit(struct char_data *ch)
  93. {
  94.     int max;
  95.  
  96.     if (!IS_NPC(ch))
  97.         /* HERE SHOULD BE CON CALCULATIONS INSTEAD */
  98.         max = graf(age(ch).year, 50,70,160,120,100,40,20);
  99.     else
  100.         max = ch->points.max_move;
  101.  
  102. /* Class/Level calculations */
  103.  
  104. /* Skill/Spell calculations */
  105.  
  106.   return (max);
  107. }
  108.  
  109.  
  110.  
  111.  
  112. /* manapoint gain pr. game hour */
  113. int mana_gain(struct char_data *ch)
  114. {
  115.     int gain;
  116.  
  117.     if(IS_NPC(ch)) {
  118.         /* Neat and fast */
  119.         gain = GET_LEVEL(ch);
  120.     } else {
  121.         gain = graf(age(ch).year, 2,4,6,8,6,5,8);
  122.  
  123.         /* Class calculations */
  124.  
  125.         /* Skill/Spell calculations */
  126.  
  127.         /* Position calculations    */
  128.         switch (GET_POS(ch)) {
  129.             case POSITION_SLEEPING:
  130.                 gain += gain;
  131.                 break;
  132.             case POSITION_RESTING:
  133.                 gain+= (gain>>1);  /* Divide by 2 */
  134.                 break;
  135.             case POSITION_SITTING:
  136.                 gain += (gain>>2); /* Divide by 4 */
  137.                 break;
  138.         }
  139.  
  140.         if ((GET_CLASS(ch) == CLASS_MAGIC_USER) || (GET_CLASS(ch) == CLASS_CLERIC))
  141.             gain += gain;
  142.     }
  143.  
  144.     if (IS_AFFECTED(ch,AFF_POISON))
  145.         gain >>= 2;
  146.  
  147.     if((GET_COND(ch,FULL)==0)||(GET_COND(ch,THIRST)==0))
  148.         gain >>= 2;
  149.  
  150.   return (gain);
  151. }
  152.  
  153.  
  154. int hit_gain(struct char_data *ch)
  155. /* Hitpoint gain pr. game hour */
  156. {
  157.     int gain;
  158.  
  159.     if(IS_NPC(ch)) {
  160.         gain = GET_LEVEL(ch);
  161.         /* Neat and fast */
  162.     } else {
  163.  
  164.         gain = graf(age(ch).year, 2,5,10,18,6,4,2);
  165.  
  166.         /* Class/Level calculations */
  167.  
  168.         /* Skill/Spell calculations */
  169.  
  170.         /* Position calculations    */
  171.  
  172.         switch (GET_POS(ch)) {
  173.             case POSITION_SLEEPING:
  174.                 gain += (gain>>1); /* Divide by 2 */
  175.                 break;
  176.             case POSITION_RESTING:
  177.                 gain+= (gain>>2);  /* Divide by 4 */
  178.                 break;
  179.             case POSITION_SITTING:
  180.                 gain += (gain>>3); /* Divide by 8 */
  181.                 break;
  182.         }
  183.  
  184.         if ((GET_CLASS(ch) == CLASS_MAGIC_USER) || (GET_CLASS(ch) == CLASS_CLERIC))
  185.             gain >>= 1;
  186.   }
  187.  
  188.   if (IS_AFFECTED(ch,AFF_POISON))
  189.     {
  190.         gain >>= 2;
  191.       damage(ch,ch,2,SPELL_POISON);
  192.     }
  193.  
  194.     if((GET_COND(ch,FULL)==0)||(GET_COND(ch,THIRST)==0))
  195.         gain >>= 2;
  196.  
  197.   return (gain);
  198. }
  199.  
  200.  
  201.  
  202. int move_gain(struct char_data *ch)
  203. /* move gain pr. game hour */
  204. {
  205.     int gain;
  206.  
  207.     if(IS_NPC(ch)) {
  208.         return(GET_LEVEL(ch));    
  209.         /* Neat and fast */
  210.     } else {
  211.         gain = graf(age(ch).year, 12,18,22,21,14,10,6);
  212.  
  213.         /* Class/Level calculations */
  214.  
  215.         /* Skill/Spell calculations */
  216.  
  217.  
  218.         /* Position calculations    */
  219.         switch (GET_POS(ch)) {
  220.             case POSITION_SLEEPING:
  221.                 gain += (gain>>1); /* Divide by 2 */
  222.                 break;
  223.             case POSITION_RESTING:
  224.                 gain+= (gain>>2);  /* Divide by 4 */
  225.                 break;
  226.             case POSITION_SITTING:
  227.                 gain += (gain>>3); /* Divide by 8 */
  228.                 break;
  229.         }
  230.     }
  231.  
  232.     if (IS_AFFECTED(ch,AFF_POISON))
  233.         gain >>= 2;
  234.  
  235.     if((GET_COND(ch,FULL)==0)||(GET_COND(ch,THIRST)==0))
  236.         gain >>= 2;
  237.  
  238.     return (gain);
  239. }
  240.  
  241.  
  242.  
  243. /* Gain maximum in various points */
  244. void advance_level(struct char_data *ch)
  245. {
  246.     int add_hp, i;
  247.  
  248.     extern struct wis_app_type wis_app[];
  249.     extern struct con_app_type con_app[];
  250.  
  251.     
  252.     add_hp = con_app[GET_CON(ch)].hitp;
  253.  
  254.     switch(GET_CLASS(ch)) {
  255.  
  256.         case CLASS_MAGIC_USER : {
  257.             add_hp += number(3, 8);
  258.         } break;
  259.  
  260.         case CLASS_CLERIC : {
  261.             add_hp += number(5, 10);
  262.         } break;
  263.  
  264.         case CLASS_THIEF : {
  265.             add_hp += number(7,13);
  266.         } break;
  267.  
  268.         case CLASS_WARRIOR : {
  269.             add_hp += number(10,15);
  270.         } break;
  271.     }
  272.  
  273.     ch->points.max_hit += MAX(1, add_hp);
  274.  
  275.     if (GET_CLASS(ch) == CLASS_MAGIC_USER || GET_CLASS(ch) == CLASS_CLERIC)
  276.         ch->specials.spells_to_learn += MAX(2, wis_app[GET_WIS(ch)].bonus);
  277.     else
  278.         ch->specials.spells_to_learn += MIN(2,MAX(1, wis_app[GET_WIS(ch)].bonus));
  279.  
  280.     if (GET_LEVEL(ch) > 20)
  281.         for (i = 0; i < 3; i++)
  282.             ch->specials.conditions[i] = -1;
  283. }    
  284.  
  285.  
  286. void set_title(struct char_data *ch)
  287. {
  288.     if (GET_TITLE(ch))
  289.         RECREATE(GET_TITLE(ch),char,strlen(READ_TITLE(ch))+1);
  290.     else
  291.         CREATE(GET_TITLE(ch),char,strlen(READ_TITLE(ch)));
  292.  
  293.     strcpy(GET_TITLE(ch), READ_TITLE(ch));
  294. }
  295.  
  296.  
  297.  
  298. void gain_exp(struct char_data *ch, int gain)
  299. {
  300.     int i;
  301.   bool is_altered = FALSE;
  302.  
  303.     if (IS_NPC(ch) || ((GET_LEVEL(ch) < 21) && (GET_LEVEL(ch) > 0))) {
  304.  
  305.         if (gain > 0) {
  306.             gain = MIN(100000, gain);
  307.             GET_EXP(ch) += gain;
  308.             if (!IS_NPC(ch)) {
  309.                 for (i = 0; titles[GET_CLASS(ch)-1][i].exp <= GET_EXP(ch); i++) {
  310.                     if (i > GET_LEVEL(ch)) {
  311.                         send_to_char("You raise a level\n\r", ch);
  312.                         GET_LEVEL(ch) = i;
  313.                         advance_level(ch);
  314.                         is_altered = TRUE;
  315.                     }
  316.                 }
  317.             }
  318.         }
  319.  
  320.         if (gain < 0) {
  321.             gain = MAX(-500000, gain);  /* Never loose more than 1/2 mil */
  322.             GET_EXP(ch) += gain;
  323.             if (GET_EXP(ch) < 0)
  324.                 GET_EXP(ch) = 0;
  325.         }
  326.  
  327.         if (is_altered)
  328.             set_title(ch);
  329.     }
  330. }
  331.  
  332.  
  333. void gain_exp_regardless(struct char_data *ch, int gain)
  334. {
  335.     int i;
  336.   bool is_altered = FALSE;
  337.  
  338.     if (!IS_NPC(ch)) {
  339.         if (gain > 0) {
  340.             GET_EXP(ch) += gain;
  341.             for (i = 0; (i<25) && (titles[GET_CLASS(ch)-1][i].exp <= GET_EXP(ch)); i++) {
  342.                 if (i > GET_LEVEL(ch)) {
  343.                     send_to_char("You raise a level\n\r", ch);
  344.                     GET_LEVEL(ch) = i;
  345.                     advance_level(ch);
  346.                     is_altered = TRUE;
  347.                 }
  348.             }
  349.         }
  350.         if (gain < 0) 
  351.             GET_EXP(ch) += gain;
  352.         if (GET_EXP(ch) < 0)
  353.             GET_EXP(ch) = 0;
  354.     }
  355.     if (is_altered)
  356.         set_title(ch);
  357. }
  358.  
  359. void gain_condition(struct char_data *ch,int condition,int value)
  360. {
  361.     bool intoxicated;
  362.  
  363.     if(GET_COND(ch, condition)==-1) /* No change */
  364.         return;
  365.  
  366.     intoxicated=(GET_COND(ch, DRUNK) > 0);
  367.  
  368.     GET_COND(ch, condition)  += value;
  369.  
  370.     GET_COND(ch,condition) = MAX(0,GET_COND(ch,condition));
  371.     GET_COND(ch,condition) = MIN(24,GET_COND(ch,condition));
  372.  
  373.     if(GET_COND(ch,condition))
  374.         return;
  375.  
  376.     switch(condition){
  377.         case FULL :
  378.         {
  379.             send_to_char("You are hungry.\n\r",ch);
  380.             return;
  381.         }
  382.         case THIRST :
  383.         {
  384.             send_to_char("You are thirsty.\n\r",ch);
  385.             return;
  386.         }
  387.         case DRUNK :
  388.         {
  389.             if(intoxicated)
  390.                 send_to_char("You are now sober.\n\r",ch);
  391.             return;
  392.         }
  393.         default : break;
  394.     }
  395.  
  396. }
  397.  
  398.  
  399. void check_idling(struct char_data *ch)
  400. {
  401.     if (++(ch->specials.timer) > 8)
  402.         if (ch->specials.was_in_room == NOWHERE && ch->in_room != NOWHERE)
  403.         {
  404.             ch->specials.was_in_room = ch->in_room;
  405.             if (ch->specials.fighting)
  406.             {
  407.                 stop_fighting(ch->specials.fighting);
  408.                 stop_fighting(ch);
  409.             }
  410.             act("$n disappears into the void.", TRUE, ch, 0, 0, TO_ROOM);
  411.             send_to_char("You have been idle, and are pulled into a void.\n\r", ch);
  412.             char_from_room(ch);
  413.             char_to_room(ch, 1);  /* Into room number 0 */
  414.         }
  415.         else if (ch->specials.timer > 48)
  416.         {
  417.             if (ch->in_room != NOWHERE)
  418.                 char_from_room(ch);
  419.             if (ch->specials.was_in_room != NOWHERE)
  420.                 char_to_room(ch, ch->specials.was_in_room);
  421.             else
  422.                 char_to_room(ch, 1);
  423.             if (ch->desc)
  424.                 close_socket(ch->desc);
  425.             ch->desc = 0;
  426.             extract_char(ch);
  427.         }
  428. }
  429.  
  430.  
  431.  
  432.  
  433.  
  434. /* Update both PC's & NPC's and objects*/
  435. void point_update( void )
  436. {    
  437.     void update_char_objects( struct char_data *ch ); /* handler.c */
  438.   void extract_obj(struct obj_data *obj); /* handler.c */
  439.     struct char_data *i, *next_dude;
  440.   struct obj_data *j, *next_thing, *jj, *next_thing2;
  441.  
  442.   /* characters */
  443.     for (i = character_list; i; i = next_dude) {
  444.         next_dude = i->next;
  445.         if (GET_POS(i) > POSITION_STUNNED) {
  446.             GET_HIT(i)  = MIN(GET_HIT(i)  + hit_gain(i),  hit_limit(i));
  447.             GET_MANA(i) = MIN(GET_MANA(i) + mana_gain(i), mana_limit(i));
  448.             GET_MOVE(i) = MIN(GET_MOVE(i) + move_gain(i), move_limit(i));
  449.         } else if (GET_POS(i) == POSITION_STUNNED) {
  450.             GET_HIT(i)  = MIN(GET_HIT(i)  + hit_gain(i),  hit_limit(i));
  451.             GET_MANA(i) = MIN(GET_MANA(i) + mana_gain(i), mana_limit(i));
  452.             GET_MOVE(i) = MIN(GET_MOVE(i) + move_gain(i), move_limit(i));
  453.             update_pos( i );
  454.         } else if    (GET_POS(i) == POSITION_INCAP)
  455.             damage(i, i, 1, TYPE_SUFFERING);
  456.         else if (!IS_NPC(i) && (GET_POS(i) == POSITION_MORTALLYW))
  457.             damage(i, i, 2, TYPE_SUFFERING);
  458.         if (!IS_NPC(i))
  459.         {
  460.             update_char_objects(i);
  461.             if (GET_LEVEL(i) < 22)
  462.                 check_idling(i);
  463.         }
  464.         gain_condition(i,FULL,-1);
  465.         gain_condition(i,DRUNK,-1);
  466.         gain_condition(i,THIRST,-1);
  467.     } /* for */
  468.  
  469.   /* objects */
  470.     for(j = object_list; j ; j = next_thing){
  471.         next_thing = j->next; /* Next in object list */
  472.  
  473.       /* If this is a corpse */
  474.         if ( (GET_ITEM_TYPE(j) == ITEM_CONTAINER) && (j->obj_flags.value[3]) ) {
  475.             /* timer count down */
  476.             if (j->obj_flags.timer > 0) j->obj_flags.timer--;
  477.  
  478.             if (!j->obj_flags.timer) {
  479.  
  480.                 if (j->carried_by)
  481.                     act("$p decay in your hands.", FALSE, j->carried_by, j, 0, TO_CHAR);
  482.                 else if ((j->in_room != NOWHERE) && (world[j->in_room].people)){
  483.                     act("A quivering hoard of maggots consume $p.",
  484.                       TRUE, world[j->in_room].people, j, 0, TO_ROOM);
  485.                     act("A quivering hoard of maggots consume $p.",
  486.                       TRUE, world[j->in_room].people, j, 0, TO_CHAR);
  487.                 }
  488.  
  489.         for(jj = j->contains; jj; jj = next_thing2) {
  490.                     next_thing2 = jj->next_content; /* Next in inventory */
  491.                     obj_from_obj(jj);
  492.  
  493.                     if (j->in_obj)
  494.                         obj_to_obj(jj,j->in_obj);
  495.                     else if (j->carried_by)
  496.                         obj_to_room(jj,j->carried_by->in_room);
  497.                     else if (j->in_room != NOWHERE)
  498.                         obj_to_room(jj,j->in_room);
  499.                     else
  500.                         assert(FALSE);
  501.                 }
  502.                 extract_obj(j);
  503.             }
  504.         }
  505.     }
  506. }
  507.