home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / games / volume15 / xstratego / part02 / buzz.c next >
C/C++ Source or Header  |  1993-01-27  |  7KB  |  216 lines

  1. /*
  2.  * "buzz.c"
  3.  */
  4.  
  5. #include "buzz.h"
  6.  
  7. #define        NIL_CHAR    ((char *) 0)
  8. #define     MEND        {NIL_CHAR, 101}    /* table closer */
  9.  
  10. MESSAGE    move_opponent [] = {        /* moving enemy piece */
  11.     {"Sorry, no response!", 100},
  12.     {"The Bomb turns around and says: \"I should have blown you to bits\"",
  13.         10},
  14.     {"The Marshall turns around and says: \"Burp!\"", 10},
  15.     {"The enemy piece turns around and says: \"Hands off\"", 50},
  16.     {"The enemy piece turns around and says: \"Ok, I'll help you.  \
  17. What's it worth?\"", 50},
  18.     {"The enemy piece turns around and says: \"Go away thy fiend!\"", 50},
  19.     {"The Spy turns around and says: \"Clever!  How did you find out?\"",
  20.         10},
  21.     {"The enemy piece turns around and says: \"Stick to your own\"", 50},
  22.     {"C'mon that's no way to win.", 100},
  23.     {"I think you're playing the other color.", 100},
  24.     {"Boom!!!  It turned out to be a Bomb!", 50},
  25.     {"Move yer own, will ya..", 100},
  26.     {"The General won't answer.", 10},
  27.     {"The Scout won't answer.", 10},
  28.     {"The Bomb won't answer.", 10},
  29.     {"Try again.  He might give himself away.", 100},
  30.     {"Don't, your opponent is watching.", 100},
  31.     {"It seems to speak a different language.", 100},
  32.     {"Your opponent won't agree.", 100},
  33.     {"Ask the other player.", 100},
  34.     MEND
  35. };
  36.  
  37. MESSAGE    move_empty [] = {        /* trying to move empty location */
  38.      {"There is nothing there!", 100},
  39.     {"You thought someone dug a hole here?", 100},
  40.     {"He moved out.", 100},
  41.     {"You start digging...", 100},
  42.     {"You continue digging...", 50},
  43.     {"The ground is to hard to dig into.", 50},
  44.     {"You dug a pit.", 50},
  45.     {"Vell, vell.  Und vere's all zat void going, hah?", 50},
  46.     {"Don't use innocent civilians, dirtbag!", 50},
  47.     {"Trying to dig up a corpse are ya?", 50},
  48.     MEND
  49. };
  50.  
  51. MESSAGE    move_flag [] = {        /* flag movement */
  52.     {"But it hasn't got any legs!", 100},
  53.     {"It seems to be stuck.", 100},
  54.     {"With enormous effort, you move the flag.", 50},
  55.     {"No no, read page 546, paragraph 93a of the manual.", 100},
  56.     {"Get somebody to help.", 50},
  57.     {"Its no use, your going to lose anyway.", 50},
  58.     {"I wouldn't try to attack anything with it.", 100},
  59.     {"It's surrounded by bombs!", 50},
  60.     {"Leider zis here fahn von't move.", 50},
  61.     MEND
  62. };
  63.  
  64. MESSAGE    move_bomb [] = {        /* bomb movement */
  65.     {"Don't muck about with explosives. You might get your head blown off.",        100},
  66.     {"Ask an enemy miner to help you.", 100},
  67.     {"That's a ball.  Try kicking it.", 100},
  68.     {"Not implemented yet.", 100},
  69.     {"You fool, you put it out of order!", 50},
  70.     {"No no, read page 546, paragraph 93b of the manual.", 100},
  71.     {"A bomb once laid, is a joy forever.", 100},
  72.     {"C'mon, there are so many other nice pieces waiting to be moved.", 50},
  73.     {"It iz unwize to fumble wiz beumbs.", 50},
  74.     MEND
  75. };
  76.  
  77. MESSAGE    kill_own [] = {            /* trying to "hit" one of your own */
  78.     {"You traitor! You're attacking your own army.", 100},
  79.     {"It turned out to be a draw.  They return to their positions.", 50},
  80.     {"Yeez, watch out will ye.  Somebody's gonna get hurt!", 100},
  81.     {"Oh you cannibal, you will be sorry for this!", 50},
  82.     {"Fortunately, your subordinates do have brains.", 100},
  83.     {"It can't be that hopeless.", 50},
  84.     {"Wait, wait, I think that's page 546, paragraph 93c of the manual.",
  85.         100},
  86.     {"Rebellion!  There's a coup going on!", 100},
  87.     MEND
  88. };
  89.  
  90. MESSAGE    illegal [] = {            /* all other illegal moves */
  91.     {"Illegal move.", 100},
  92.     {"Read page 546, paragraph 93d of the manual.", 50},
  93.     {"Wait!  Read page 546, paragraph 93e of the manual.", 50},
  94.     {"No!  Read page 546, paragraph 93f of the manual.", 50},
  95.     {"\"Mother, somebody is cheating again\"", 50},
  96.     {"No dice, sucker...", 100},
  97.     {"End of input?", 50},
  98.     {"Interesting...", 100},
  99.     {"Something wrong with your eyes, squarehead?", 100},
  100.     {"Take a day off.", 100},
  101.     {"Ha ha.", 50},
  102.     MEND
  103. };
  104.  
  105. MESSAGE    finished_premature [] = {    /* illegal board setup */
  106.     {"Don't fool around", 100},
  107.     {"Something's missing...", 100},
  108.     {"No no, I insist you get a fair chance.", 100},
  109.     MEND
  110. };
  111.  
  112. MESSAGE in_water [] = {            /* moving a piece into the water */
  113.     {"If you wanted that piece to swim across, \
  114. you should have said \"swim\".", 50},
  115.     {"He can't. The piranhas will eat him.", 100},
  116.     {"Blub. Bloeb.", 100},
  117.     {"You'll first have to teach him how to swim!", 50},
  118.     {"Remember the Titanic...", 100},
  119.     MEND
  120. };
  121.     
  122. MESSAGE    win_capture [] = {        /* hitting enemy piece (and winning) */
  123.     {"Bang!!", 50},
  124.     {"Did you consider the possibility that his marshall was there?", 10},
  125.     {"You'll lose either way.", 100},
  126.     {"You'll win anyway.", 50},
  127.     {"Try to move one of his, you might find out what it is!", 50},
  128.     {"I'd have moved the other one.", 100},
  129.     {"WARNING:  It's against the rules to click Give Up.", 50},
  130.     {"Ok, how about Remise now.", 50},
  131.     {"His flag is more to the left.", 10},
  132.     {"Ok, who's to get slaughtered next?", 100},
  133.     {"Well, at least there's more room now.", 100},
  134.     {"D-d-d-d-destruction!!!", 50},
  135.     {"Dead and buried.", 100},
  136.     {"Surprise!", 100},
  137.     {"Kling, klang!", 100},
  138.     MEND
  139. };
  140.  
  141. MESSAGE    lose_capture [] = {        /* hitting enemy piece (and losing) */
  142.     {"Bang!!", 50},
  143.     {"NOW he does it!", 50},
  144.     {"You really blew it, sucker.", 50},
  145.     {"Did you consider the possibility that his marshall was there?", 10},
  146.     {"You'll lose either way.", 100},
  147.     {"You'll win anyway.", 50},
  148.     {"Try to move one of his, you might find out what it is!", 50},
  149.     {"You should have put a bomb in front.", 50},
  150.     {"I would have moved the other one.", 100},
  151.     {"Oh oh, somebody is coming.", 100},
  152.     {"WARNING:  It's against the rules to click Give Up.", 50},
  153.     {"Ok, how about an Remise now.", 50},
  154.     {"Ok, who will be slaughtered next?", 100},
  155.     {"Well, at least there's more room now.", 100},
  156.     {"D-d-d-d-destruction!!!", 50},
  157.     {"Dead and buried.", 100},
  158.     {"Surprise!", 100},
  159.     {"Klang, kling!", 100},
  160.     MEND
  161. };
  162.  
  163. /*
  164.  * Returns message of m (ptr).
  165.  */
  166. #define        mesg(m)        (m->_mesg)
  167.  
  168. /*
  169.  * Retruns chance of m (ptr).
  170.  */
  171. #define        chance(m)    (m->_chance)
  172.  
  173. /*
  174.  * Returns 1 if chance of m > 100, else 0.
  175.  */
  176. #define        mnul(m)        (chance (m) > 100)
  177.  
  178. extern     rand ();    /* Returns number between 0 .. very large */
  179.  
  180. /*
  181.  * Buzz returns pointer to (random) message from mesg_tab.
  182.  * Mesg_tab is seen as array of MESSAGE's, terminated by a MNUL entry.
  183.  * All messages with equal "chance" (>=0, <=100) have equal chance to be
  184.  * selected.  All messages with chance k.X have a
  185.  * k times bigger chance as all messages with chance X.
  186.  */
  187. char *
  188. buzz (mesg_tab)
  189. MESSAGE    *mesg_tab;
  190. {
  191. #    define    lowrand        1        /* lower bound random number */
  192.     register unsigned upprand = 0;        /* upper bound random number */
  193.     register unsigned chanceacc = 0;    /* accumulated chances  */
  194.     register unsigned chancebound;        /* usable random number  */
  195.     register MESSAGE  *m;
  196.  
  197.     if (mesg_tab == (MESSAGE *) 0)
  198.         return NIL_CHAR;
  199.  
  200.     for (m = mesg_tab; !mnul (m); m++)
  201.         upprand += chance (m);
  202.     
  203.     if (upprand != 0)
  204.         chancebound = ((rand () % (upprand - lowrand + 1))) + lowrand;
  205.     else
  206.         chancebound = 1;
  207.  
  208.     for (m = mesg_tab; !mnul (m); m++) {
  209.         chanceacc += chance (m);
  210.         if (chancebound <= chanceacc)
  211.             return mesg (m);
  212.     }
  213.  
  214.     return NIL_CHAR;
  215. }
  216.