home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Usenet 1994 January
/
usenetsourcesnewsgroupsinfomagicjanuary1994.iso
/
sources
/
games
/
volume15
/
xstratego
/
part02
/
buzz.c
next >
Wrap
C/C++ Source or Header
|
1993-01-27
|
7KB
|
216 lines
/*
* "buzz.c"
*/
#include "buzz.h"
#define NIL_CHAR ((char *) 0)
#define MEND {NIL_CHAR, 101} /* table closer */
MESSAGE move_opponent [] = { /* moving enemy piece */
{"Sorry, no response!", 100},
{"The Bomb turns around and says: \"I should have blown you to bits\"",
10},
{"The Marshall turns around and says: \"Burp!\"", 10},
{"The enemy piece turns around and says: \"Hands off\"", 50},
{"The enemy piece turns around and says: \"Ok, I'll help you. \
What's it worth?\"", 50},
{"The enemy piece turns around and says: \"Go away thy fiend!\"", 50},
{"The Spy turns around and says: \"Clever! How did you find out?\"",
10},
{"The enemy piece turns around and says: \"Stick to your own\"", 50},
{"C'mon that's no way to win.", 100},
{"I think you're playing the other color.", 100},
{"Boom!!! It turned out to be a Bomb!", 50},
{"Move yer own, will ya..", 100},
{"The General won't answer.", 10},
{"The Scout won't answer.", 10},
{"The Bomb won't answer.", 10},
{"Try again. He might give himself away.", 100},
{"Don't, your opponent is watching.", 100},
{"It seems to speak a different language.", 100},
{"Your opponent won't agree.", 100},
{"Ask the other player.", 100},
MEND
};
MESSAGE move_empty [] = { /* trying to move empty location */
{"There is nothing there!", 100},
{"You thought someone dug a hole here?", 100},
{"He moved out.", 100},
{"You start digging...", 100},
{"You continue digging...", 50},
{"The ground is to hard to dig into.", 50},
{"You dug a pit.", 50},
{"Vell, vell. Und vere's all zat void going, hah?", 50},
{"Don't use innocent civilians, dirtbag!", 50},
{"Trying to dig up a corpse are ya?", 50},
MEND
};
MESSAGE move_flag [] = { /* flag movement */
{"But it hasn't got any legs!", 100},
{"It seems to be stuck.", 100},
{"With enormous effort, you move the flag.", 50},
{"No no, read page 546, paragraph 93a of the manual.", 100},
{"Get somebody to help.", 50},
{"Its no use, your going to lose anyway.", 50},
{"I wouldn't try to attack anything with it.", 100},
{"It's surrounded by bombs!", 50},
{"Leider zis here fahn von't move.", 50},
MEND
};
MESSAGE move_bomb [] = { /* bomb movement */
{"Don't muck about with explosives. You might get your head blown off.", 100},
{"Ask an enemy miner to help you.", 100},
{"That's a ball. Try kicking it.", 100},
{"Not implemented yet.", 100},
{"You fool, you put it out of order!", 50},
{"No no, read page 546, paragraph 93b of the manual.", 100},
{"A bomb once laid, is a joy forever.", 100},
{"C'mon, there are so many other nice pieces waiting to be moved.", 50},
{"It iz unwize to fumble wiz beumbs.", 50},
MEND
};
MESSAGE kill_own [] = { /* trying to "hit" one of your own */
{"You traitor! You're attacking your own army.", 100},
{"It turned out to be a draw. They return to their positions.", 50},
{"Yeez, watch out will ye. Somebody's gonna get hurt!", 100},
{"Oh you cannibal, you will be sorry for this!", 50},
{"Fortunately, your subordinates do have brains.", 100},
{"It can't be that hopeless.", 50},
{"Wait, wait, I think that's page 546, paragraph 93c of the manual.",
100},
{"Rebellion! There's a coup going on!", 100},
MEND
};
MESSAGE illegal [] = { /* all other illegal moves */
{"Illegal move.", 100},
{"Read page 546, paragraph 93d of the manual.", 50},
{"Wait! Read page 546, paragraph 93e of the manual.", 50},
{"No! Read page 546, paragraph 93f of the manual.", 50},
{"\"Mother, somebody is cheating again\"", 50},
{"No dice, sucker...", 100},
{"End of input?", 50},
{"Interesting...", 100},
{"Something wrong with your eyes, squarehead?", 100},
{"Take a day off.", 100},
{"Ha ha.", 50},
MEND
};
MESSAGE finished_premature [] = { /* illegal board setup */
{"Don't fool around", 100},
{"Something's missing...", 100},
{"No no, I insist you get a fair chance.", 100},
MEND
};
MESSAGE in_water [] = { /* moving a piece into the water */
{"If you wanted that piece to swim across, \
you should have said \"swim\".", 50},
{"He can't. The piranhas will eat him.", 100},
{"Blub. Bloeb.", 100},
{"You'll first have to teach him how to swim!", 50},
{"Remember the Titanic...", 100},
MEND
};
MESSAGE win_capture [] = { /* hitting enemy piece (and winning) */
{"Bang!!", 50},
{"Did you consider the possibility that his marshall was there?", 10},
{"You'll lose either way.", 100},
{"You'll win anyway.", 50},
{"Try to move one of his, you might find out what it is!", 50},
{"I'd have moved the other one.", 100},
{"WARNING: It's against the rules to click Give Up.", 50},
{"Ok, how about Remise now.", 50},
{"His flag is more to the left.", 10},
{"Ok, who's to get slaughtered next?", 100},
{"Well, at least there's more room now.", 100},
{"D-d-d-d-destruction!!!", 50},
{"Dead and buried.", 100},
{"Surprise!", 100},
{"Kling, klang!", 100},
MEND
};
MESSAGE lose_capture [] = { /* hitting enemy piece (and losing) */
{"Bang!!", 50},
{"NOW he does it!", 50},
{"You really blew it, sucker.", 50},
{"Did you consider the possibility that his marshall was there?", 10},
{"You'll lose either way.", 100},
{"You'll win anyway.", 50},
{"Try to move one of his, you might find out what it is!", 50},
{"You should have put a bomb in front.", 50},
{"I would have moved the other one.", 100},
{"Oh oh, somebody is coming.", 100},
{"WARNING: It's against the rules to click Give Up.", 50},
{"Ok, how about an Remise now.", 50},
{"Ok, who will be slaughtered next?", 100},
{"Well, at least there's more room now.", 100},
{"D-d-d-d-destruction!!!", 50},
{"Dead and buried.", 100},
{"Surprise!", 100},
{"Klang, kling!", 100},
MEND
};
/*
* Returns message of m (ptr).
*/
#define mesg(m) (m->_mesg)
/*
* Retruns chance of m (ptr).
*/
#define chance(m) (m->_chance)
/*
* Returns 1 if chance of m > 100, else 0.
*/
#define mnul(m) (chance (m) > 100)
extern rand (); /* Returns number between 0 .. very large */
/*
* Buzz returns pointer to (random) message from mesg_tab.
* Mesg_tab is seen as array of MESSAGE's, terminated by a MNUL entry.
* All messages with equal "chance" (>=0, <=100) have equal chance to be
* selected. All messages with chance k.X have a
* k times bigger chance as all messages with chance X.
*/
char *
buzz (mesg_tab)
MESSAGE *mesg_tab;
{
# define lowrand 1 /* lower bound random number */
register unsigned upprand = 0; /* upper bound random number */
register unsigned chanceacc = 0; /* accumulated chances */
register unsigned chancebound; /* usable random number */
register MESSAGE *m;
if (mesg_tab == (MESSAGE *) 0)
return NIL_CHAR;
for (m = mesg_tab; !mnul (m); m++)
upprand += chance (m);
if (upprand != 0)
chancebound = ((rand () % (upprand - lowrand + 1))) + lowrand;
else
chancebound = 1;
for (m = mesg_tab; !mnul (m); m++) {
chanceacc += chance (m);
if (chancebound <= chanceacc)
return mesg (m);
}
return NIL_CHAR;
}