From 6693db176654a0f25095ec64d0a74d58dcf0e47e Mon Sep 17 00:00:00 2001 From: Sascha Wildner Date: Sun, 10 Jan 2010 00:32:31 +0100 Subject: [PATCH] games: Massive style(9) cleanup commit. Reduces differences to NetBSD. Submitted-by: Ulrich Spoerlein --- games/adventure/adventure.6 | 6 +- games/adventure/crc.c | 130 +- games/adventure/done.c | 155 +- games/adventure/hdr.h | 237 +- games/adventure/init.c | 140 +- games/adventure/io.c | 617 ++--- games/adventure/main.c | 967 ++++---- games/adventure/save.c | 185 +- games/adventure/setup.c | 26 +- games/adventure/subr.c | 1424 +++++++----- games/adventure/vocab.c | 165 +- games/adventure/wizard.c | 80 +- games/arithmetic/arithmetic.6 | 6 +- games/arithmetic/arithmetic.c | 32 +- games/atc/atc.6 | 6 +- games/atc/def.h | 6 +- games/atc/extern.c | 6 +- games/atc/extern.h | 6 +- games/atc/grammar.y | 52 +- games/atc/graphics.c | 14 +- games/atc/include.h | 6 +- games/atc/input.c | 38 +- games/atc/lex.l | 6 +- games/atc/list.c | 8 +- games/atc/log.c | 7 +- games/atc/main.c | 38 +- games/atc/pathnames.h | 6 +- games/atc/struct.h | 6 +- games/atc/tunable.c | 6 +- games/atc/tunable.h | 6 +- games/atc/update.c | 6 +- games/backgammon/backgammon/backgammon.6 | 6 +- games/backgammon/backgammon/extra.c | 187 +- games/backgammon/backgammon/main.c | 466 ++-- games/backgammon/backgammon/move.c | 383 ++-- games/backgammon/backgammon/text.c | 32 +- games/backgammon/backgammon/version.c | 8 +- games/backgammon/common_source/allow.c | 45 +- games/backgammon/common_source/back.h | 97 +- games/backgammon/common_source/board.c | 109 +- games/backgammon/common_source/check.c | 98 +- games/backgammon/common_source/fancy.c | 694 +++--- games/backgammon/common_source/init.c | 12 +- games/backgammon/common_source/odds.c | 56 +- games/backgammon/common_source/one.c | 102 +- games/backgammon/common_source/save.c | 156 +- games/backgammon/common_source/subs.c | 285 ++- games/backgammon/common_source/table.c | 183 +- games/backgammon/teachgammon/data.c | 10 +- games/backgammon/teachgammon/teach.c | 52 +- games/backgammon/teachgammon/ttext1.c | 8 +- games/backgammon/teachgammon/ttext2.c | 73 +- games/backgammon/teachgammon/tutor.c | 65 +- games/backgammon/teachgammon/tutor.h | 8 +- games/battlestar/battlestar.6 | 6 +- games/battlestar/battlestar.c | 31 +- games/battlestar/com1.c | 145 +- games/battlestar/com2.c | 362 +-- games/battlestar/com3.c | 402 ++-- games/battlestar/com4.c | 442 ++-- games/battlestar/com5.c | 388 ++-- games/battlestar/com6.c | 135 +- games/battlestar/com7.c | 364 ++- games/battlestar/cypher.c | 719 +++--- games/battlestar/dayfile.c | 8 +- games/battlestar/dayobjs.c | 8 +- games/battlestar/externs.h | 118 +- games/battlestar/fly.c | 248 +- games/battlestar/getcom.c | 17 +- games/battlestar/globals.c | 94 +- games/battlestar/init.c | 14 +- games/battlestar/misc.c | 19 +- games/battlestar/nightfile.c | 8 +- games/battlestar/nightobjs.c | 8 +- games/battlestar/parse.c | 23 +- games/battlestar/pathnames.h | 6 +- games/battlestar/room.c | 268 ++- games/battlestar/save.c | 20 +- games/battlestar/words.c | 10 +- games/bcd/bcd.6 | 6 +- games/bcd/bcd.c | 16 +- games/bs/bs.c | 74 +- games/caesar/caesar.6 | 6 +- games/caesar/caesar.c | 63 +- games/caesar/rot13.sh | 6 +- games/canfield/canfield/canfield.6 | 6 +- games/canfield/canfield/canfield.c | 51 +- games/canfield/canfield/pathnames.h | 6 +- games/canfield/cfscores/cfscores.c | 18 +- games/cribbage/cards.c | 9 +- games/cribbage/crib.c | 22 +- games/cribbage/cribbage.6 | 6 +- games/cribbage/cribbage.h | 69 +- games/cribbage/cribcur.h | 10 +- games/cribbage/deck.h | 16 +- games/cribbage/extern.c | 9 +- games/cribbage/instr.c | 8 +- games/cribbage/io.c | 10 +- games/cribbage/pathnames.h | 6 +- games/cribbage/score.c | 12 +- games/cribbage/support.c | 16 +- games/factor/factor.6 | 6 +- games/factor/factor.c | 16 +- games/fish/fish.6 | 6 +- games/fish/fish.c | 49 +- games/fish/pathnames.h | 6 +- games/fortune/Makefile.inc | 2 +- games/fortune/datfiles/dragonfly-funny | 20 +- games/fortune/datfiles/dragonfly-tips | 20 +- games/fortune/datfiles/fortunes2 | 2 +- games/fortune/fortune/fortune.6 | 6 +- games/fortune/fortune/fortune.c | 583 ++--- games/fortune/fortune/pathnames.h | 6 +- games/fortune/strfile/strfile.8 | 6 +- games/fortune/strfile/strfile.c | 148 +- games/fortune/strfile/strfile.h | 6 +- games/fortune/unstr/unstr.c | 56 +- games/grdc/grdc.c | 11 +- games/hack/Original_READ_ME | 4 +- games/hack/alloc.c | 12 +- games/hack/config.h | 14 +- games/hack/data | 2 +- games/hack/def.gen.h | 4 +- games/hack/def.gold.h | 2 +- games/hack/def.mkroom.h | 6 +- games/hack/def.monst.h | 60 +- games/hack/def.obj.h | 24 +- games/hack/def.objclass.h | 20 +- games/hack/def.objects.h | 10 +- games/hack/def.permonst.h | 4 +- games/hack/def.rm.h | 10 +- games/hack/def.trap.h | 14 +- games/hack/def.wseg.h | 4 +- games/hack/hack.Decl.c | 8 +- games/hack/hack.apply.c | 322 +-- games/hack/hack.bones.c | 91 +- games/hack/hack.c | 948 ++++---- games/hack/hack.cmd.c | 194 +- games/hack/hack.do.c | 463 ++-- games/hack/hack.do_name.c | 233 +- games/hack/hack.do_wear.c | 340 +-- games/hack/hack.dog.c | 449 ++-- games/hack/hack.eat.c | 318 +-- games/hack/hack.end.c | 684 +++--- games/hack/hack.engrave.c | 283 +-- games/hack/hack.fight.c | 385 ++-- games/hack/hack.fix | 4 +- games/hack/hack.h | 54 +- games/hack/hack.invent.c | 795 ++++--- games/hack/hack.ioctl.c | 17 +- games/hack/hack.lev.c | 166 +- games/hack/hack.main.c | 302 +-- games/hack/hack.makemon.c | 180 +- games/hack/hack.mhitu.c | 338 +-- games/hack/hack.mklev.c | 764 ++++--- games/hack/hack.mkmaze.c | 147 +- games/hack/hack.mkobj.c | 82 +- games/hack/hack.mkshop.c | 297 +-- games/hack/hack.mon.c | 916 ++++---- games/hack/hack.monst.c | 4 +- games/hack/hack.o_init.c | 173 +- games/hack/hack.objnam.c | 476 ++-- games/hack/hack.options.c | 166 +- games/hack/hack.pager.c | 343 +-- games/hack/hack.potion.c | 308 +-- games/hack/hack.pri.c | 525 +++-- games/hack/hack.read.c | 706 +++--- games/hack/hack.rip.c | 36 +- games/hack/hack.rumors.c | 70 +- games/hack/hack.save.c | 188 +- games/hack/hack.search.c | 162 +- games/hack/hack.shk.c | 949 ++++---- games/hack/hack.shknam.c | 27 +- games/hack/hack.steal.c | 190 +- games/hack/hack.termcap.c | 119 +- games/hack/hack.timeout.c | 80 +- games/hack/hack.topl.c | 119 +- games/hack/hack.track.c | 24 +- games/hack/hack.trap.c | 343 +-- games/hack/hack.tty.c | 144 +- games/hack/hack.u_init.c | 171 +- games/hack/hack.unix.c | 227 +- games/hack/hack.vault.c | 308 +-- games/hack/hack.version.c | 6 +- games/hack/hack.wield.c | 79 +- games/hack/hack.wizard.c | 244 +- games/hack/hack.worm.c | 127 +- games/hack/hack.worn.c | 37 +- games/hack/hack.zap.c | 623 ++--- games/hack/makedefs.c | 168 +- games/hack/pathnames.h | 6 +- games/hack/rnd.c | 13 +- games/hangman/Makefile | 4 +- games/hangman/endgame.c | 10 +- games/hangman/extern.c | 51 +- games/hangman/getguess.c | 22 +- games/hangman/getword.c | 16 +- games/hangman/hangman.6 | 6 +- games/hangman/hangman.h | 22 +- games/hangman/main.c | 13 +- games/hangman/pathnames.h | 6 +- games/hangman/playgame.c | 8 +- games/hangman/prdata.c | 8 +- games/hangman/prman.c | 8 +- games/hangman/prword.c | 6 +- games/hangman/setup.c | 16 +- games/hunt/README | 2 +- games/hunt/README.protocol | 32 +- games/hunt/hunt/client.h | 50 +- games/hunt/hunt/connect.c | 50 +- games/hunt/hunt/display.c | 16 +- games/hunt/hunt/display.h | 4 +- games/hunt/hunt/hunt.c | 58 +- games/hunt/hunt/list.c | 10 +- games/hunt/hunt/list.h | 2 +- games/hunt/hunt/otto.c | 50 +- games/hunt/hunt/playit.c | 52 +- games/hunt/huntd/answer.c | 74 +- games/hunt/huntd/conf.c | 26 +- games/hunt/huntd/conf.h | 2 +- games/hunt/huntd/draw.c | 56 +- games/hunt/huntd/driver.c | 20 +- games/hunt/huntd/execute.c | 52 +- games/hunt/huntd/expl.c | 50 +- games/hunt/huntd/extern.c | 54 +- games/hunt/huntd/hunt.h | 50 +- games/hunt/huntd/makemaze.c | 50 +- games/hunt/huntd/server.h | 50 +- games/hunt/huntd/shots.c | 58 +- games/hunt/huntd/terminal.c | 50 +- games/larn/Fixed.Bugs | 8 +- games/larn/README | 4 +- games/larn/bill.c | 20 +- games/larn/config.c | 19 +- games/larn/create.c | 721 +++--- games/larn/data.c | 535 +++-- games/larn/datfiles/larn.help | 4 +- games/larn/diag.c | 438 ++-- games/larn/display.c | 751 +++--- games/larn/fortune.c | 6 +- games/larn/global.c | 937 +++++--- games/larn/header.h | 185 +- games/larn/help.c | 103 +- games/larn/holidays | 66 - games/larn/io.c | 1064 +++++---- games/larn/larn.6 | 6 +- games/larn/main.c | 1575 ++++++++----- games/larn/monster.c | 2111 ++++++++++------- games/larn/moreobj.c | 638 +++--- games/larn/movem.c | 558 +++-- games/larn/nap.c | 9 +- games/larn/object.c | 1809 +++++++++------ games/larn/pathnames.h | 6 +- games/larn/regen.c | 213 +- games/larn/savelev.c | 50 +- games/larn/scores.c | 811 ++++--- games/larn/signal.c | 250 +- games/larn/store.c | 898 +++++--- games/larn/tok.c | 332 +-- games/mille/comp.c | 18 +- games/mille/end.c | 18 +- games/mille/extern.c | 38 +- games/mille/init.c | 22 +- games/mille/mille.6 | 6 +- games/mille/mille.c | 22 +- games/mille/mille.h | 246 +- games/mille/misc.c | 21 +- games/mille/move.c | 32 +- games/mille/print.c | 24 +- games/mille/roll.c | 12 +- games/mille/save.c | 41 +- games/mille/types.c | 15 +- games/mille/varpush.c | 46 +- games/morse/morse.6 | 6 +- games/morse/morse.c | 8 +- games/number/number.6 | 6 +- games/number/number.c | 8 +- games/phantasia/fight.c | 2659 ++++++++++------------ games/phantasia/gamesupport.c | 1203 +++++----- games/phantasia/interplayer.c | 1893 +++++++-------- games/phantasia/io.c | 637 +++--- games/phantasia/macros.h | 2 + games/phantasia/main.c | 1942 +++++++--------- games/phantasia/misc.c | 2541 +++++++++------------ games/phantasia/pathnames.h | 6 +- games/phantasia/phantdefs.h | 86 +- games/phantasia/phantglobs.c | 52 +- games/phantasia/phantglobs.h | 2 +- games/phantasia/setup.c | 262 +-- games/pig/pig.6 | 6 +- games/pig/pig.c | 6 +- games/pom/pom.6 | 6 +- games/pom/pom.c | 8 +- games/ppt/ppt.c | 8 +- games/primes/pattern.c | 8 +- games/primes/pr_tbl.c | 8 +- games/primes/primes.c | 8 +- games/primes/primes.h | 8 +- games/quiz/pathnames.h | 6 +- games/quiz/quiz.6 | 6 +- games/quiz/quiz.c | 6 +- games/quiz/quiz.h | 6 +- games/quiz/rxp.c | 6 +- games/rain/rain.6 | 6 +- games/rain/rain.c | 8 +- games/random/random.6 | 6 +- games/random/random.c | 8 +- games/random/randomize_fd.c | 2 +- games/random/randomize_fd.h | 2 +- games/robots/extern.c | 71 +- games/robots/flush_in.c | 18 +- games/robots/init_field.c | 24 +- games/robots/main.c | 74 +- games/robots/make_level.c | 20 +- games/robots/move.c | 76 +- games/robots/move_robs.c | 26 +- games/robots/pathnames.h | 6 +- games/robots/play_level.c | 28 +- games/robots/query.c | 14 +- games/robots/rnd_pos.c | 19 +- games/robots/robots.6 | 6 +- games/robots/robots.h | 106 +- games/robots/score.c | 68 +- games/rogue/CHANGES | 2 +- games/rogue/Makefile | 2 +- games/rogue/USD.doc/rogue.me | 10 +- games/rogue/hit.c | 39 +- games/rogue/init.c | 29 +- games/rogue/inventory.c | 10 +- games/rogue/level.c | 46 +- games/rogue/machdep.c | 25 +- games/rogue/main.c | 10 +- games/rogue/message.c | 18 +- games/rogue/monster.c | 30 +- games/rogue/move.c | 27 +- games/rogue/object.c | 35 +- games/rogue/pack.c | 25 +- games/rogue/pathnames.h | 7 +- games/rogue/play.c | 8 +- games/rogue/random.c | 11 +- games/rogue/ring.c | 18 +- games/rogue/rogue.6 | 6 +- games/rogue/rogue.h | 44 +- games/rogue/room.c | 21 +- games/rogue/save.c | 42 +- games/rogue/score.c | 39 +- games/rogue/spec_hit.c | 37 +- games/rogue/throw.c | 19 +- games/rogue/trap.c | 10 +- games/rogue/use.c | 22 +- games/rogue/zap.c | 20 +- games/sail/assorted.c | 24 +- games/sail/dr_1.c | 23 +- games/sail/dr_2.c | 47 +- games/sail/dr_3.c | 28 +- games/sail/dr_4.c | 8 +- games/sail/dr_5.c | 8 +- games/sail/dr_main.c | 10 +- games/sail/driver.h | 8 +- games/sail/externs.h | 166 +- games/sail/game.c | 17 +- games/sail/globals.c | 607 ++--- games/sail/lo_main.c | 8 +- games/sail/machdep.h | 8 +- games/sail/main.c | 15 +- games/sail/misc.c | 24 +- games/sail/parties.c | 14 +- games/sail/pathnames.h | 6 +- games/sail/pl_1.c | 10 +- games/sail/pl_2.c | 8 +- games/sail/pl_3.c | 11 +- games/sail/pl_4.c | 10 +- games/sail/pl_5.c | 10 +- games/sail/pl_6.c | 10 +- games/sail/pl_7.c | 22 +- games/sail/pl_main.c | 18 +- games/sail/player.h | 10 +- games/sail/sail.6 | 6 +- games/sail/sync.c | 17 +- games/sail/version.c | 8 +- games/snake/snake/pathnames.h | 8 +- games/snake/snake/snake.6 | 6 +- games/snake/snake/snake.c | 448 ++-- games/snake/snscore/Makefile | 4 +- games/snake/snscore/snscore.c | 14 +- games/trek/DOC/trekmanual.nr | 4 +- games/trek/USD.doc/trek.me | 8 +- games/trek/abandon.c | 42 +- games/trek/attack.c | 50 +- games/trek/autover.c | 16 +- games/trek/capture.c | 33 +- games/trek/cgetc.c | 14 +- games/trek/check_out.c | 10 +- games/trek/checkcond.c | 16 +- games/trek/compkl.c | 35 +- games/trek/computer.c | 102 +- games/trek/damage.c | 18 +- games/trek/damaged.c | 13 +- games/trek/dcrept.c | 29 +- games/trek/destruct.c | 23 +- games/trek/dock.c | 40 +- games/trek/dumpgame.c | 34 +- games/trek/dumpme.c | 22 +- games/trek/dumpssradio.c | 19 +- games/trek/events.c | 116 +- games/trek/externs.c | 16 +- games/trek/getcodi.c | 12 +- games/trek/getpar.c | 72 +- games/trek/getpar.h | 36 +- games/trek/help.c | 50 +- games/trek/impulse.c | 24 +- games/trek/initquad.c | 39 +- games/trek/kill.c | 64 +- games/trek/klmove.c | 49 +- games/trek/lose.c | 19 +- games/trek/lrscan.c | 37 +- games/trek/main.c | 46 +- games/trek/move.c | 64 +- games/trek/nova.c | 46 +- games/trek/out.c | 10 +- games/trek/phaser.c | 149 +- games/trek/play.c | 22 +- games/trek/ram.c | 16 +- games/trek/ranf.c | 10 +- games/trek/rest.c | 19 +- games/trek/schedule.c | 35 +- games/trek/score.c | 25 +- games/trek/setup.c | 83 +- games/trek/setwarp.c | 14 +- games/trek/shield.c | 57 +- games/trek/snova.c | 62 +- games/trek/srscan.c | 55 +- games/trek/systemname.c | 12 +- games/trek/torped.c | 83 +- games/trek/trek.6 | 6 +- games/trek/trek.h | 252 +- games/trek/utility.c | 8 +- games/trek/visual.c | 19 +- games/trek/warp.c | 80 +- games/trek/win.c | 25 +- games/wargames/wargames.6 | 20 +- games/wargames/wargames.sh | 6 +- games/worm/worm.6 | 6 +- games/worm/worm.c | 66 +- games/worms/worms.6 | 21 +- games/worms/worms.c | 21 +- games/wump/pathnames.h | 6 +- games/wump/wump.6 | 6 +- games/wump/wump.c | 64 +- games/wump/wump.info | 4 +- 450 files changed, 31450 insertions(+), 29998 deletions(-) diff --git a/games/adventure/adventure.6 b/games/adventure/adventure.6 index c4be539c02..c6330d8426 100644 --- a/games/adventure/adventure.6 +++ b/games/adventure/adventure.6 @@ -14,11 +14,7 @@ .\" 2. Redistributions in binary form must reproduce the above copyright .\" notice, this list of conditions and the following disclaimer in the .\" documentation and/or other materials provided with the distribution. -.\" 3. All advertising materials mentioning features or use of this software -.\" must display the following acknowledgement: -.\" This product includes software developed by the University of -.\" California, Berkeley and its contributors. -.\" 4. Neither the name of the University nor the names of its contributors +.\" 3. Neither the name of the University nor the names of its contributors .\" may be used to endorse or promote products derived from this software .\" without specific prior written permission. .\" diff --git a/games/adventure/crc.c b/games/adventure/crc.c index bca77354eb..b4966dfd2d 100644 --- a/games/adventure/crc.c +++ b/games/adventure/crc.c @@ -13,11 +13,7 @@ * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. - * 4. Neither the name of the University nor the names of its contributors + * 3. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * @@ -42,59 +38,59 @@ #include #include "hdr.h" -const u_long crctab[] = { +const unsigned long crctab[] = { 0x7fffffff, - 0x77073096, 0xee0e612c, 0x990951ba, 0x076dc419, 0x706af48f, - 0xe963a535, 0x9e6495a3, 0x0edb8832, 0x79dcb8a4, 0xe0d5e91e, - 0x97d2d988, 0x09b64c2b, 0x7eb17cbd, 0xe7b82d07, 0x90bf1d91, - 0x1db71064, 0x6ab020f2, 0xf3b97148, 0x84be41de, 0x1adad47d, - 0x6ddde4eb, 0xf4d4b551, 0x83d385c7, 0x136c9856, 0x646ba8c0, - 0xfd62f97a, 0x8a65c9ec, 0x14015c4f, 0x63066cd9, 0xfa0f3d63, - 0x8d080df5, 0x3b6e20c8, 0x4c69105e, 0xd56041e4, 0xa2677172, - 0x3c03e4d1, 0x4b04d447, 0xd20d85fd, 0xa50ab56b, 0x35b5a8fa, - 0x42b2986c, 0xdbbbc9d6, 0xacbcf940, 0x32d86ce3, 0x45df5c75, - 0xdcd60dcf, 0xabd13d59, 0x26d930ac, 0x51de003a, 0xc8d75180, - 0xbfd06116, 0x21b4f4b5, 0x56b3c423, 0xcfba9599, 0xb8bda50f, - 0x2802b89e, 0x5f058808, 0xc60cd9b2, 0xb10be924, 0x2f6f7c87, - 0x58684c11, 0xc1611dab, 0xb6662d3d, 0x76dc4190, 0x01db7106, - 0x98d220bc, 0xefd5102a, 0x71b18589, 0x06b6b51f, 0x9fbfe4a5, - 0xe8b8d433, 0x7807c9a2, 0x0f00f934, 0x9609a88e, 0xe10e9818, - 0x7f6a0dbb, 0x086d3d2d, 0x91646c97, 0xe6635c01, 0x6b6b51f4, - 0x1c6c6162, 0x856530d8, 0xf262004e, 0x6c0695ed, 0x1b01a57b, - 0x8208f4c1, 0xf50fc457, 0x65b0d9c6, 0x12b7e950, 0x8bbeb8ea, - 0xfcb9887c, 0x62dd1ddf, 0x15da2d49, 0x8cd37cf3, 0xfbd44c65, - 0x4db26158, 0x3ab551ce, 0xa3bc0074, 0xd4bb30e2, 0x4adfa541, - 0x3dd895d7, 0xa4d1c46d, 0xd3d6f4fb, 0x4369e96a, 0x346ed9fc, - 0xad678846, 0xda60b8d0, 0x44042d73, 0x33031de5, 0xaa0a4c5f, - 0xdd0d7cc9, 0x5005713c, 0x270241aa, 0xbe0b1010, 0xc90c2086, - 0x5768b525, 0x206f85b3, 0xb966d409, 0xce61e49f, 0x5edef90e, - 0x29d9c998, 0xb0d09822, 0xc7d7a8b4, 0x59b33d17, 0x2eb40d81, - 0xb7bd5c3b, 0xc0ba6cad, 0xedb88320, 0x9abfb3b6, 0x03b6e20c, - 0x74b1d29a, 0xead54739, 0x9dd277af, 0x04db2615, 0x73dc1683, - 0xe3630b12, 0x94643b84, 0x0d6d6a3e, 0x7a6a5aa8, 0xe40ecf0b, - 0x9309ff9d, 0x0a00ae27, 0x7d079eb1, 0xf00f9344, 0x8708a3d2, - 0x1e01f268, 0x6906c2fe, 0xf762575d, 0x806567cb, 0x196c3671, - 0x6e6b06e7, 0xfed41b76, 0x89d32be0, 0x10da7a5a, 0x67dd4acc, - 0xf9b9df6f, 0x8ebeeff9, 0x17b7be43, 0x60b08ed5, 0xd6d6a3e8, - 0xa1d1937e, 0x38d8c2c4, 0x4fdff252, 0xd1bb67f1, 0xa6bc5767, - 0x3fb506dd, 0x48b2364b, 0xd80d2bda, 0xaf0a1b4c, 0x36034af6, - 0x41047a60, 0xdf60efc3, 0xa867df55, 0x316e8eef, 0x4669be79, - 0xcb61b38c, 0xbc66831a, 0x256fd2a0, 0x5268e236, 0xcc0c7795, - 0xbb0b4703, 0x220216b9, 0x5505262f, 0xc5ba3bbe, 0xb2bd0b28, - 0x2bb45a92, 0x5cb36a04, 0xc2d7ffa7, 0xb5d0cf31, 0x2cd99e8b, - 0x5bdeae1d, 0x9b64c2b0, 0xec63f226, 0x756aa39c, 0x026d930a, - 0x9c0906a9, 0xeb0e363f, 0x72076785, 0x05005713, 0x95bf4a82, - 0xe2b87a14, 0x7bb12bae, 0x0cb61b38, 0x92d28e9b, 0xe5d5be0d, - 0x7cdcefb7, 0x0bdbdf21, 0x86d3d2d4, 0xf1d4e242, 0x68ddb3f8, - 0x1fda836e, 0x81be16cd, 0xf6b9265b, 0x6fb077e1, 0x18b74777, - 0x88085ae6, 0xff0f6a70, 0x66063bca, 0x11010b5c, 0x8f659eff, - 0xf862ae69, 0x616bffd3, 0x166ccf45, 0xa00ae278, 0xd70dd2ee, - 0x4e048354, 0x3903b3c2, 0xa7672661, 0xd06016f7, 0x4969474d, - 0x3e6e77db, 0xaed16a4a, 0xd9d65adc, 0x40df0b66, 0x37d83bf0, - 0xa9bcae53, 0xdebb9ec5, 0x47b2cf7f, 0x30b5ffe9, 0xbdbdf21c, - 0xcabac28a, 0x53b39330, 0x24b4a3a6, 0xbad03605, 0xcdd70693, - 0x54de5729, 0x23d967bf, 0xb3667a2e, 0xc4614ab8, 0x5d681b02, - 0x2a6f2b94, 0xb40bbe37, 0xc30c8ea1, 0x5a05df1b, 0x2d02ef8d + 0x77073096, 0xee0e612c, 0x990951ba, 0x076dc419, 0x706af48f, + 0xe963a535, 0x9e6495a3, 0x0edb8832, 0x79dcb8a4, 0xe0d5e91e, + 0x97d2d988, 0x09b64c2b, 0x7eb17cbd, 0xe7b82d07, 0x90bf1d91, + 0x1db71064, 0x6ab020f2, 0xf3b97148, 0x84be41de, 0x1adad47d, + 0x6ddde4eb, 0xf4d4b551, 0x83d385c7, 0x136c9856, 0x646ba8c0, + 0xfd62f97a, 0x8a65c9ec, 0x14015c4f, 0x63066cd9, 0xfa0f3d63, + 0x8d080df5, 0x3b6e20c8, 0x4c69105e, 0xd56041e4, 0xa2677172, + 0x3c03e4d1, 0x4b04d447, 0xd20d85fd, 0xa50ab56b, 0x35b5a8fa, + 0x42b2986c, 0xdbbbc9d6, 0xacbcf940, 0x32d86ce3, 0x45df5c75, + 0xdcd60dcf, 0xabd13d59, 0x26d930ac, 0x51de003a, 0xc8d75180, + 0xbfd06116, 0x21b4f4b5, 0x56b3c423, 0xcfba9599, 0xb8bda50f, + 0x2802b89e, 0x5f058808, 0xc60cd9b2, 0xb10be924, 0x2f6f7c87, + 0x58684c11, 0xc1611dab, 0xb6662d3d, 0x76dc4190, 0x01db7106, + 0x98d220bc, 0xefd5102a, 0x71b18589, 0x06b6b51f, 0x9fbfe4a5, + 0xe8b8d433, 0x7807c9a2, 0x0f00f934, 0x9609a88e, 0xe10e9818, + 0x7f6a0dbb, 0x086d3d2d, 0x91646c97, 0xe6635c01, 0x6b6b51f4, + 0x1c6c6162, 0x856530d8, 0xf262004e, 0x6c0695ed, 0x1b01a57b, + 0x8208f4c1, 0xf50fc457, 0x65b0d9c6, 0x12b7e950, 0x8bbeb8ea, + 0xfcb9887c, 0x62dd1ddf, 0x15da2d49, 0x8cd37cf3, 0xfbd44c65, + 0x4db26158, 0x3ab551ce, 0xa3bc0074, 0xd4bb30e2, 0x4adfa541, + 0x3dd895d7, 0xa4d1c46d, 0xd3d6f4fb, 0x4369e96a, 0x346ed9fc, + 0xad678846, 0xda60b8d0, 0x44042d73, 0x33031de5, 0xaa0a4c5f, + 0xdd0d7cc9, 0x5005713c, 0x270241aa, 0xbe0b1010, 0xc90c2086, + 0x5768b525, 0x206f85b3, 0xb966d409, 0xce61e49f, 0x5edef90e, + 0x29d9c998, 0xb0d09822, 0xc7d7a8b4, 0x59b33d17, 0x2eb40d81, + 0xb7bd5c3b, 0xc0ba6cad, 0xedb88320, 0x9abfb3b6, 0x03b6e20c, + 0x74b1d29a, 0xead54739, 0x9dd277af, 0x04db2615, 0x73dc1683, + 0xe3630b12, 0x94643b84, 0x0d6d6a3e, 0x7a6a5aa8, 0xe40ecf0b, + 0x9309ff9d, 0x0a00ae27, 0x7d079eb1, 0xf00f9344, 0x8708a3d2, + 0x1e01f268, 0x6906c2fe, 0xf762575d, 0x806567cb, 0x196c3671, + 0x6e6b06e7, 0xfed41b76, 0x89d32be0, 0x10da7a5a, 0x67dd4acc, + 0xf9b9df6f, 0x8ebeeff9, 0x17b7be43, 0x60b08ed5, 0xd6d6a3e8, + 0xa1d1937e, 0x38d8c2c4, 0x4fdff252, 0xd1bb67f1, 0xa6bc5767, + 0x3fb506dd, 0x48b2364b, 0xd80d2bda, 0xaf0a1b4c, 0x36034af6, + 0x41047a60, 0xdf60efc3, 0xa867df55, 0x316e8eef, 0x4669be79, + 0xcb61b38c, 0xbc66831a, 0x256fd2a0, 0x5268e236, 0xcc0c7795, + 0xbb0b4703, 0x220216b9, 0x5505262f, 0xc5ba3bbe, 0xb2bd0b28, + 0x2bb45a92, 0x5cb36a04, 0xc2d7ffa7, 0xb5d0cf31, 0x2cd99e8b, + 0x5bdeae1d, 0x9b64c2b0, 0xec63f226, 0x756aa39c, 0x026d930a, + 0x9c0906a9, 0xeb0e363f, 0x72076785, 0x05005713, 0x95bf4a82, + 0xe2b87a14, 0x7bb12bae, 0x0cb61b38, 0x92d28e9b, 0xe5d5be0d, + 0x7cdcefb7, 0x0bdbdf21, 0x86d3d2d4, 0xf1d4e242, 0x68ddb3f8, + 0x1fda836e, 0x81be16cd, 0xf6b9265b, 0x6fb077e1, 0x18b74777, + 0x88085ae6, 0xff0f6a70, 0x66063bca, 0x11010b5c, 0x8f659eff, + 0xf862ae69, 0x616bffd3, 0x166ccf45, 0xa00ae278, 0xd70dd2ee, + 0x4e048354, 0x3903b3c2, 0xa7672661, 0xd06016f7, 0x4969474d, + 0x3e6e77db, 0xaed16a4a, 0xd9d65adc, 0x40df0b66, 0x37d83bf0, + 0xa9bcae53, 0xdebb9ec5, 0x47b2cf7f, 0x30b5ffe9, 0xbdbdf21c, + 0xcabac28a, 0x53b39330, 0x24b4a3a6, 0xbad03605, 0xcdd70693, + 0x54de5729, 0x23d967bf, 0xb3667a2e, 0xc4614ab8, 0x5d681b02, + 0x2a6f2b94, 0xb40bbe37, 0xc30c8ea1, 0x5a05df1b, 0x2d02ef8d }; /* @@ -105,29 +101,27 @@ const u_long crctab[] = { * it. */ -u_long crcval; -u_int step; +unsigned long crcval; +unsigned int step; -void +void crc_start(void) { crcval = step = 0; } /* Process nr bytes at a time; ptr points to them */ -u_long +unsigned long crc(const char *ptr, int nr) { - int i; - const char *p; + int i; + const char *p; while (nr > 0) - for (p = ptr; nr--; ++p) - { - if (!(i = crcval >> 24 ^ *p)) - { + for (p = ptr; nr--; ++p) { + if (!(i = crcval >> 24 ^ *p)) { i = step++; - if (step >= sizeof(crctab)/sizeof(crctab[0])) + if (step >= sizeof(crctab) / sizeof(crctab[0])) step = 0; } crcval = ((crcval << 8) ^ crctab[i]) & 0xffffffff; diff --git a/games/adventure/done.c b/games/adventure/done.c index 212bff3f23..5d68e5a9a6 100644 --- a/games/adventure/done.c +++ b/games/adventure/done.c @@ -15,11 +15,7 @@ * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. - * 4. Neither the name of the University nor the names of its contributors + * 3. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * @@ -40,105 +36,132 @@ * $DragonFly: src/games/adventure/done.c,v 1.4 2007/04/18 18:32:12 swildner Exp $ */ -/* Re-coding of advent in C: termination routines */ +/* Re-coding of advent in C: termination routines */ #include #include #include "hdr.h" -/* sort of like 20000 */ +/* sort of like 20000 */ int score(void) -{ int scor,i; - mxscor=scor=0; - for (i=50; i<=maxtrs; i++) - { if (ptext[i].txtlen==0) continue; - k=12; - if (i==chest) k=14; - if (i>chest) k=16; - if (prop[i]>=0) scor += 2; - if (place[i]==3&&prop[i]==0) scor += k-2; +{ + int scor, i; + + mxscor = scor = 0; + for (i = 50; i <= maxtrs; i++) { + if (ptext[i].txtlen == 0) + continue; + k = 12; + if (i == chest) + k = 14; + if (i > chest) + k = 16; + if (prop[i] >= 0) + scor += 2; + if (place[i] == 3 && prop[i] == 0) + scor += k - 2; mxscor += k; } - scor += (maxdie-numdie)*10; - mxscor += maxdie*10; - if (!(scorng||gaveup)) scor += 4; + scor += (maxdie - numdie) * 10; + mxscor += maxdie * 10; + if (!(scorng || gaveup)) + scor += 4; mxscor += 4; - if (dflag!=0) scor += 25; + if (dflag != 0) + scor += 25; mxscor += 25; - if (closng) scor += 25; + if (closng) + scor += 25; mxscor += 25; - if (closed) - { if (bonus==0) scor += 10; - if (bonus==135) scor += 25; - if (bonus==134) scor += 30; - if (bonus==133) scor += 45; + if (closed) { + if (bonus == 0) + scor += 10; + if (bonus == 135) + scor += 25; + if (bonus == 134) + scor += 30; + if (bonus == 133) + scor += 45; } mxscor += 45; - if (place[magzin]==108) scor++; + if (place[magzin] == 108) + scor++; mxscor++; scor += 2; mxscor += 2; - for (i=1; i<=hntmax; i++) - if (hinted[i]) scor -= hints[i][2]; - return(scor); + for (i = 1; i <= hntmax; i++) + if (hinted[i]) + scor -= hints[i][2]; + return (scor); } -/* entry=1 means goto 13000 */ /* game is over */ -/* entry=2 means goto 20000 */ /* 3=19000 */ +/* entry=1 means goto 13000 */ /* game is over */ +/* entry=2 means goto 20000 */ /* 3=19000 */ void done(int entry) -{ int i,sc; - if (entry==1) mspeak(1); - if (entry==3) rspeak(136); - printf("\n\n\nYou scored %d out of a ",(sc=score())); - printf("possible %d using %d turns.\n",mxscor,turns); - for (i=1; i<=clsses; i++) - if (cval[i]>=sc) - { speak(&ctext[i]); - if (i==clsses-1) - { printf("To achieve the next higher rating"); +{ + int i, sc; + + if (entry == 1) + mspeak(1); + if (entry == 3) + rspeak(136); + printf("\n\n\nYou scored %d out of a ", (sc = score())); + printf("possible %d using %d turns.\n", mxscor, turns); + for (i = 1; i <= clsses; i++) + if (cval[i] >= sc) { + speak(&ctext[i]); + if (i == clsses - 1) { + printf("To achieve the next higher rating"); printf(" would be a neat trick!\n\n"); printf("Congratulations!!\n"); exit(0); } - k=cval[i]+1-sc; + k = cval[i] + 1 - sc; printf("To achieve the next higher rating, you need"); - printf(" %d more point",k); - if (k==1) printf(".\n"); - else printf("s.\n"); + printf(" %d more point", k); + if (k == 1) + printf(".\n"); + else + printf("s.\n"); exit(0); } printf("You just went off my scale!!!\n"); exit(0); } - -/* label 90 */ +/* label 90 */ void die(int entry) -{ int i; - if (entry != 99) - { rspeak(23); - oldlc2=loc; +{ + int i; + + if (entry != 99) { + rspeak(23); + oldlc2 = loc; } - if (closng) /* 99 */ - { rspeak(131); + if (closng) { /* 99 */ + rspeak(131); numdie++; done(2); } - yea=yes(81+numdie*2,82+numdie*2,54); + yea = yes(81 + numdie * 2, 82 + numdie * 2, 54); numdie++; - if (numdie==maxdie || !yea) done(2); - place[water]=0; - place[oil]=0; - if (toting(lamp)) prop[lamp]=0; - for (i=100; i>=1; i--) - { if (!toting(i)) continue; - k=oldlc2; - if (i==lamp) k=1; - drop(i,k); + if (numdie == maxdie || !yea) + done(2); + place[water] = 0; + place[oil] = 0; + if (toting(lamp)) + prop[lamp] = 0; + for (i = 100; i >= 1; i--) { + if (!toting(i)) + continue; + k = oldlc2; + if (i == lamp) + k = 1; + drop(i, k); } - loc=3; - oldloc=loc; + loc = 3; + oldloc = loc; } diff --git a/games/adventure/hdr.h b/games/adventure/hdr.h index f45a9064c0..9f2f96475d 100644 --- a/games/adventure/hdr.h +++ b/games/adventure/hdr.h @@ -15,11 +15,7 @@ * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. - * 4. Neither the name of the University nor the names of its contributors + * 3. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * @@ -50,6 +46,9 @@ * The data file distributed with the fortran source is assumed to be called * "glorkz" in the directory where the program is first run. * + * The original FORTRAN version can be found at + * . + * * $FreeBSD: src/games/adventure/hdr.h,v 1.5.2.1 2001/03/05 11:43:11 kris Exp $ * $DragonFly: src/games/adventure/hdr.h,v 1.3 2004/09/12 17:19:58 dillon Exp $ */ @@ -58,162 +57,158 @@ #include #include -int datfd; /* message file descriptor */ +int datfd; /* message file descriptor */ volatile sig_atomic_t delhit; int yea; -extern char data_file[]; /* Virtual data file */ +extern char data_file[]; /* Virtual data file */ #define TAB 011 #define LF 012 #define FLUSHLINE do { int flushline_ch; while ((flushline_ch = getchar()) != EOF && flushline_ch != '\n'); } while (0) #define FLUSHLF while (next()!=LF) -int loc,newloc,oldloc,oldlc2,wzdark,gaveup,kq,k,k2; -char *wd1,*wd2; /* the complete words */ -int verb,obj,spk; +int loc, newloc, oldloc, oldlc2, wzdark, gaveup, kq, k, k2; +char *wd1, *wd2; /* the complete words */ +int verb, obj, spk; extern int blklin; -int saved,savet,mxscor,latncy; +int saved, savet, mxscor, latncy; -#define SHORT 50 /* How short is a demo game? */ +#define SHORT 50 /* How short is a demo game? */ -#define MAXSTR 20 /* max length of user's words */ +#define MAXSTR 20 /* max length of user's words */ -#define HTSIZE 512 /* max number of vocab words */ -struct hashtab /* hash table for vocabulary */ -{ int val; /* word type &index (ktab) */ - char *atab; /* pointer to actual string */ +#define HTSIZE 512 /* max number of vocab words */ +struct hashtab { /* hash table for vocabulary */ + int val; /* word type &index (ktab) */ + char *atab; /* pointer to actual string */ } voc[HTSIZE]; -#define SEED 1815622 /* "Encryption" seed */ +#define SEED 1815622 /* "Encryption" seed */ -struct text -#ifdef OLDSTUFF -{ int seekadr; /* DATFILE must be < 2**16 */ -#endif /* !OLDSTUFF */ -{ char *seekadr; /* Msg start in virtual disk */ - int txtlen; /* length of msg starting here */ +struct text { + char *seekadr; /* Msg start in virtual disk */ + int txtlen; /* length of msg starting here */ }; -#define RTXSIZ 205 -struct text rtext[RTXSIZ]; /* random text messages */ +#define RTXSIZ 205 +struct text rtext[RTXSIZ]; /* random text messages */ -#define MAGSIZ 35 -struct text mtext[MAGSIZ]; /* magic messages */ +#define MAGSIZ 35 +struct text mtext[MAGSIZ]; /* magic messages */ int clsses; #define CLSMAX 12 -struct text ctext[CLSMAX]; /* classes of adventurer */ +struct text ctext[CLSMAX]; /* classes of adventurer */ int cval[CLSMAX]; -struct text ptext[101]; /* object descriptions */ +struct text ptext[101]; /* object descriptions */ -#define LOCSIZ 141 /* number of locations */ -struct text ltext[LOCSIZ]; /* long loc description */ -struct text stext[LOCSIZ]; /* short loc descriptions */ +#define LOCSIZ 141 /* number of locations */ +struct text ltext[LOCSIZ]; /* long loc description */ +struct text stext[LOCSIZ]; /* short loc descriptions */ -struct travlist /* direcs & conditions of travel*/ -{ struct travlist *next; /* ptr to next list entry */ - int conditions; /* m in writeup (newloc / 1000) */ - int tloc; /* n in writeup (newloc % 1000) */ - int tverb; /* the verb that takes you there*/ -} *travel[LOCSIZ],*tkk; /* travel is closer to keys(...)*/ +struct travlist { /* direcs & conditions of travel */ + struct travlist *next; /* ptr to next list entry */ + int conditions; /* m in writeup (newloc / 1000) */ + int tloc; /* n in writeup (newloc % 1000) */ + int tverb; /* the verb that takes you there */ +} *travel[LOCSIZ], *tkk; /* travel is closer to keys(...) */ int atloc[LOCSIZ]; -int plac[101]; /* initial object placement */ -int fixd[101],fixed[101]; /* location fixed? */ +int plac[101]; /* initial object placement */ +int fixd[101], fixed[101]; /* location fixed? */ -int actspk[35]; /* rtext msg for verb */ +int actspk[35]; /* rtext msg for verb */ -int cond[LOCSIZ]; /* various condition bits */ +int cond[LOCSIZ]; /* various condition bits */ -extern int setbit[16]; /* bit defn masks 1,2,4,... */ +extern int setbit[16]; /* bit defn masks 1,2,4,... */ int hntmax; -int hints[20][5]; /* info on hints */ -int hinted[20],hintlc[20]; +int hints[20][5]; /* info on hints */ +int hinted[20], hintlc[20]; -int place[101], prop[101],linkx[201]; +int place[101], prop[101], linkx[201]; int abb[LOCSIZ]; -int maxtrs,tally,tally2; /* treasure values */ +int maxtrs, tally, tally2; /* treasure values */ #define FALSE 0 #define TRUE 1 -int keys,lamp,grate,cage,rod,rod2,steps,/* mnemonics */ - bird,door,pillow,snake,fissur,tablet,clam,oyster,magzin, - dwarf,knife,food,bottle,water,oil,plant,plant2,axe,mirror,dragon, - chasm,troll,troll2,bear,messag,vend,batter, - nugget,coins,chest,eggs,tridnt,vase,emrald,pyram,pearl,rug,chain, - spices, - back,look,cave,null,entrnc,dprssn, - enter, stream, pour, - say,lock,throw,find,invent; - -int chloc,chloc2,dseen[7],dloc[7], /* dwarf stuff */ - odloc[7],dflag,daltlc; - -int tk[21],stick,dtotal,attack; -int turns,lmwarn,iwest,knfloc,detail, /* various flags & counters */ - abbnum,maxdie,numdie,holdng,dkill,foobar,bonus,clock1,clock2, - closng,panic,closed,scorng; - -int demo,limit; - -int at (int objj); -int bug (int n); -void carry (int, int); -void caveclose (void); -void checkhints (void); -void ciao (void); -void closing (void); -u_long crc (const char *ptr, int nr); -void crc_start (void); -int dark (void); -void datime (int *d, int *t); -char *decr (const char *, const char *, const char *, const char *, const char *); -void die (int entry); -void done (int entry); -void drop (int object,int where); -void dstroy (int); -int fdwarf (void); -int forced (int locc); -void getin (char **wrd1, char **wrd2); -int here (int objj); -void init (void); -void juggle (int); -int liq (void); -int liqloc (int locc); -int march (void); -void move (int, int); -void mspeak (int); -int pct (int n); -void poof (void); -void pspeak (int m, int skip); -int put (int, int, int); -int ran (int range); -void rdata (void); -int restore (const char *infile); -void rspeak (int); -int save (const char *); -int score (void); -void speak (const struct text *); -int Start (void); -void startup (void); -int toting (int objj); -void trapdel (int sig); -int trdrop (void); -int trfeed (void); -int trfill (void); -int trkill (void); -int tropen (void); -int trsay (void); -int trtake (void); -int trtoss (void); -int vocab (const char *,int,int); -int yes (int x, int y, int z); -int yesm (int x, int y, int z); +int axe, back, batter, bear, bird, bottle, /* mnemonics */ + cage, cave, chain, chasm, chest, clam, coins, door, dprssn, dragon, + dwarf, eggs, emrald, enter, entrnc, find, fissur, food, grate, invent, + keys, knife, lamp, lock, look, magzin, messag, mirror, nugget, null, + oil, oyster, pearl, pillow, plant, plant2, pour, pyram, rod, rod2, + rug, say, snake, spices, steps, stream, tablet, throw, tridnt, troll, + troll2, vase, vend, water; + +int chloc, chloc2, daltlc, dflag, dloc[7], /* dwarf stuff */ + dseen[7], odloc[7]; + +int attack, dtotal, stick, tk[21]; + +int abbnum, bonus, clock1, clock2, closed, /* various flags and counters */ + closng, detail, dkill, foobar, holdng, iwest, knfloc, + lmwarn, maxdie, numdie, panic, scorng, turns; + +int demo, limit; + +int at(int objj); +int bug(int n); +void carry(int, int); +void caveclose(void); +void checkhints(void); +void ciao(void); +void closing(void); +unsigned long crc(const char *ptr, int nr); +void crc_start(void); +int dark(void); +void datime(int *d, int *t); +char *decr(const char *, const char *, const char *, const char *, const char *); +void die(int entry); +void done(int entry); +void drop(int object, int where); +void dstroy(int); +int fdwarf(void); +int forced(int locc); +void getin(char **wrd1, char **wrd2); +int here(int objj); +void init(void); +void juggle(int); +int liq(void); +int liqloc(int locc); +int march(void); +void move(int, int); +void mspeak(int); +int pct(int n); +void poof(void); +void pspeak(int m, int skip); +int put(int, int, int); +int ran(int range); +void rdata(void); +int restore(const char *infile); +void rspeak(int); +int save(const char *); +int score(void); +void speak(const struct text *); +int Start(void); +void startup(void); +int toting(int objj); +void trapdel(int sig); +int trdrop(void); +int trfeed(void); +int trfill(void); +int trkill(void); +int tropen(void); +int trsay(void); +int trtake(void); +int trtoss(void); +int vocab(const char *, int, int); +int yes(int x, int y, int z); +int yesm(int x, int y, int z); /* We need to get a little tricky to avoid strings */ #define DECR(a,b,c,d,e) decr(#a,#b,#c,#d,#e) diff --git a/games/adventure/init.c b/games/adventure/init.c index 1b4e88db74..122b90d4b8 100644 --- a/games/adventure/init.c +++ b/games/adventure/init.c @@ -15,11 +15,7 @@ * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. - * 4. Neither the name of the University nor the names of its contributors + * 3. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * @@ -40,7 +36,7 @@ * $DragonFly: src/games/adventure/init.c,v 1.4 2007/04/18 18:32:12 swildner Exp $ */ -/* Re-coding of advent in C: data initialization */ +/* Re-coding of advent in C: data initialization */ #include #include @@ -50,16 +46,16 @@ int blklin = TRUE; -int setbit[16] = {1,2,4,010,020,040,0100,0200,0400,01000,02000,04000, - 010000,020000,040000,0100000}; +int setbit[16] = { 1, 2, 4, 010, 020, 040, 0100, 0200, 0400, 01000, 02000, + 04000, 010000, 020000, 040000, 0100000 }; static void linkdata (void); -/* everything for 1st time run */ +/* everything for 1st time run */ void init(void) { - rdata(); /* read data from orig. file */ + rdata(); /* read data from orig. file */ linkdata(); poof(); } @@ -78,42 +74,46 @@ decr(const char *a, const char *b, const char *c, const char *d, const char *e) return buf; } -/* secondary data manipulation */ +/* secondary data manipulation */ static void linkdata(void) -{ int i,j; - - /* array linkages */ - for (i=1; i<=LOCSIZ; i++) - if (ltext[i].seekadr!=0 && travel[i] != 0) - if ((travel[i]->tverb)==1) cond[i]=2; - for (j=100; j>0; j--) - if (fixd[j]>0) - { drop(j+100,fixd[j]); - drop(j,plac[j]); +{ + int i, j; + + /* array linkages */ + for (i = 1; i <= LOCSIZ; i++) + if (ltext[i].seekadr != 0 && travel[i] != 0) + if ((travel[i]->tverb) == 1) + cond[i] = 2; + for (j = 100; j > 0; j--) + if (fixd[j] > 0) { + drop(j + 100, fixd[j]); + drop(j, plac[j]); } - for (j=100; j>0; j--) - { fixed[j]=fixd[j]; - if (plac[j]!=0 && fixd[j]<=0) drop(j,plac[j]); + for (j = 100; j > 0; j--) { + fixed[j] = fixd[j]; + if (plac[j] != 0 && fixd[j] <= 0) + drop(j, plac[j]); } - maxtrs=79; - tally=0; - tally2=0; + maxtrs = 79; + tally = 0; + tally2 = 0; - for (i=50; i<=maxtrs; i++) - { if (ptext[i].seekadr!=0) prop[i] = -1; + for (i = 50; i <= maxtrs; i++) { + if (ptext[i].seekadr != 0) + prop[i] = -1; tally -= prop[i]; } /* define mnemonics */ - keys = vocab(DECR(k,e,y,s,\0), 1, 0); - lamp = vocab(DECR(l,a,m,p,\0), 1, 0); + keys = vocab(DECR(k,e,y,s,\0), 1, 0); + lamp = vocab(DECR(l,a,m,p,\0), 1, 0); grate = vocab(DECR(g,r,a,t,e), 1, 0); cage = vocab(DECR(c,a,g,e,\0),1, 0); rod = vocab(DECR(r,o,d,\0,\0),1, 0); - rod2=rod+1; - steps=vocab(DECR(s,t,e,p,s),1, 0); + rod2 = rod + 1; + steps = vocab(DECR(s,t,e,p,s),1, 0); bird = vocab(DECR(b,i,r,d,\0),1, 0); door = vocab(DECR(d,o,o,r,\0),1, 0); pillow= vocab(DECR(p,i,l,l,o), 1, 0); @@ -130,13 +130,13 @@ linkdata(void) water = vocab(DECR(w,a,t,e,r), 1, 0); oil = vocab(DECR(o,i,l,\0,\0),1, 0); plant = vocab(DECR(p,l,a,n,t), 1, 0); - plant2=plant+1; + plant2 = plant + 1; axe = vocab(DECR(a,x,e,\0,\0), 1, 0); mirror= vocab(DECR(m,i,r,r,o), 1, 0); dragon= vocab(DECR(d,r,a,g,o), 1, 0); chasm = vocab(DECR(c,h,a,s,m), 1, 0); troll = vocab(DECR(t,r,o,l,l), 1, 0); - troll2=troll+1; + troll2 = troll + 1; bear = vocab(DECR(b,e,a,r,\0),1, 0); messag= vocab(DECR(m,e,s,s,a), 1, 0); vend = vocab(DECR(v,e,n,d,i), 1, 0); @@ -170,51 +170,53 @@ linkdata(void) invent= vocab(DECR(i,n,v,e,n), 2, 0); /* initialize dwarves */ - chloc=114; - chloc2=140; - for (i=1; i<=6; i++) - dseen[i]=FALSE; - dflag=0; - dloc[1]=19; - dloc[2]=27; - dloc[3]=33; - dloc[4]=44; - dloc[5]=64; - dloc[6]=chloc; - daltlc=18; + chloc = 114; + chloc2 = 140; + for (i = 1; i <= 6; i++) + dseen[i] = FALSE; + dflag = 0; + dloc[1] = 19; + dloc[2] = 27; + dloc[3] = 33; + dloc[4] = 44; + dloc[5] = 64; + dloc[6] = chloc; + daltlc = 18; /* random flags & ctrs */ - turns=0; - lmwarn=FALSE; - iwest=0; - knfloc=0; - detail=0; - abbnum=5; - for (i=0; i<=4; i++) - if (rtext[2*i+81].seekadr!=0) maxdie=i+1; - numdie=holdng=dkill=foobar=bonus=0; - clock1=30; - clock2=50; - saved=0; - closng=panic=closed=scorng=FALSE; + turns = 0; + lmwarn = FALSE; + iwest = 0; + knfloc = 0; + detail = 0; + abbnum = 5; + for (i = 0; i <= 4; i++) + if (rtext[2 * i + 81].seekadr != 0) + maxdie = i + 1; + numdie = holdng = dkill = foobar = bonus = 0; + clock1 = 30; + clock2 = 50; + saved = 0; + closng = panic = closed = scorng = FALSE; } -/* come here if he hits a del */ +/* come here if he hits a del */ void trapdel(int sig __unused) -{ - delhit = 1; /* main checks, treats as QUIT */ - signal(2,trapdel); /* catch subsequent DELs */ +{ + delhit = 1; /* main checks, treats as QUIT */ + signal(SIGINT, trapdel); /* catch subsequent DELs */ } void startup(void) { - demo=Start(); + demo = Start(); srandomdev(); - hinted[3]=yes(65,1,0); - newloc=1; + hinted[3] = yes(65, 1, 0); + newloc = 1; delhit = 0; - limit=330; - if (hinted[3]) limit=1000; /* better batteries if instrucs */ + limit = 330; + if (hinted[3]) + limit = 1000; /* better batteries if instrucs */ } diff --git a/games/adventure/io.c b/games/adventure/io.c index d5bb247a7a..6d3ca81520 100644 --- a/games/adventure/io.c +++ b/games/adventure/io.c @@ -15,11 +15,7 @@ * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. - * 4. Neither the name of the University nor the names of its contributors + * 3. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * @@ -40,7 +36,7 @@ * $DragonFly: src/games/adventure/io.c,v 1.3 2007/04/18 18:32:12 swildner Exp $ */ -/* Re-coding of advent in C: file i/o and user i/o */ +/* Re-coding of advent in C: file i/o and user i/o */ #include "hdr.h" #include @@ -48,58 +44,57 @@ #include #include -static int next (void); -static int rnum (void); -static void rdesc (int); -static void rdflt (void); -static void rhints (void); -static void rliq (void); -static void rlocs (void); -static void rtrav (void); -static void rvoc (void); +static int next(void); +static void rdesc(int); +static void rdflt(void); +static void rhints(void); +static void rliq(void); +static void rlocs(void); +static int rnum(void); +static void rtrav(void); +static void rvoc(void); #ifdef DEBUG -static void twrite (int); +static void twrite(int); #endif -/* get command from user */ -/* no prompt, usually */ +/* Get command from user. No prompt, usually. */ void getin(char **wrd1, char **wrd2) -{ char *s; - static char wd1buf[MAXSTR],wd2buf[MAXSTR]; +{ + char *s; + static char wd1buf[MAXSTR], wd2buf[MAXSTR]; int first, numch; - *wrd1=wd1buf; /* return ptr to internal string*/ - *wrd2=wd2buf; - wd2buf[0]=0; /* in case it isn't set here */ - for (s=wd1buf, first=1, numch=0;;) - { if ((*s=getchar())>='A' && *s <='Z') *s = *s - ('A' -'a'); - /* convert to upper case */ - switch(*s) /* start reading from user */ - { case '\n': - *s=0; + *wrd1 = wd1buf; /* return ptr to internal string */ + *wrd2 = wd2buf; + wd2buf[0] = 0; /* in case it isn't set here */ + for (s = wd1buf, first = 1, numch = 0;;) { + if ((*s = getchar()) >= 'A' && *s <= 'Z') + *s = *s - ('A' - 'a'); /* convert to upper case */ + switch (*s) { /* start reading from user */ + case '\n': + *s = 0; return; - case ' ': - if (s==wd1buf||s==wd2buf) /* initial blank */ + case ' ': + if (s == wd1buf || s == wd2buf) /* initial blank */ continue; - *s=0; - if (first) /* finished 1st wd; start 2nd */ - { first=numch=0; - s=wd2buf; + *s = 0; + if (first) { /* finished 1st wd; start 2nd */ + first = numch = 0; + s = wd2buf; break; - } - else /* finished 2nd word */ - { FLUSHLINE; - *s=0; + } else { /* finished 2nd word */ + FLUSHLINE; + *s = 0; return; } - case EOF: + case EOF: printf("user closed input stream, quitting...\n"); exit(0); - default: - if (++numch>=MAXSTR) /* string too long */ - { printf("Give me a break!!\n"); - wd1buf[0]=wd2buf[0]=0; + default: + if (++numch >= MAXSTR) { /* string too long */ + printf("Give me a break!!\n"); + wd1buf[0] = wd2buf[0] = 0; FLUSHLINE; return; } @@ -108,166 +103,185 @@ getin(char **wrd1, char **wrd2) } } -/* confirm with rspeak */ +/* confirm with rspeak */ int yes(int x, int y, int z) -{ int result; +{ + int result; int ch; result = FALSE; - for (;;) - { rspeak(x); /* tell him what we want*/ - if ((ch=getchar())=='y') - result=TRUE; - else if (ch=='n') result=FALSE; + for (;;) { + rspeak(x); /* tell him what we want */ + if ((ch = getchar()) == 'y') + result = TRUE; + else if (ch == 'n') + result = FALSE; else if (ch == EOF) { printf("user closed input stream, quitting...\n"); exit(0); } FLUSHLINE; - if (ch=='y'|| ch=='n') break; + if (ch == 'y' || ch == 'n') + break; printf("Please answer the question.\n"); } - if (result==TRUE) rspeak(y); - if (result==FALSE) rspeak(z); - return(result); + if (result == TRUE) + rspeak(y); + if (result == FALSE) + rspeak(z); + return (result); } -/* confirm with mspeak */ +/* confirm with mspeak */ int yesm(int x, int y, int z) -{ int result; +{ + int result; int ch; result = FALSE; - for (;;) - { mspeak(x); /* tell him what we want*/ - if ((ch=getchar())=='y') - result=TRUE; - else if (ch=='n') result=FALSE; + for (;;) { + mspeak(x); /* tell him what we want */ + if ((ch = getchar()) == 'y') + result = TRUE; + else if (ch == 'n') + result = FALSE; else if (ch == EOF) { printf("user closed input stream, quitting...\n"); exit(0); } FLUSHLINE; - if (ch=='y'|| ch=='n') break; + if (ch == 'y' || ch == 'n') + break; printf("Please answer the question.\n"); } - if (result==TRUE) mspeak(y); - if (result==FALSE) mspeak(z); - return(result); + if (result == TRUE) + mspeak(y); + if (result == FALSE) + mspeak(z); + return (result); } -/* FILE *inbuf,*outbuf; */ +/* FILE *inbuf, *outbuf; */ -char *inptr; /* Pointer into virtual disk */ +char *inptr; /* Pointer into virtual disk */ -int outsw = 0; /* putting stuff to data file? */ +int outsw = 0; /* putting stuff to data file? */ const char iotape[] = "Ax3F'\003tt$8h\315qer*h\017nGKrX\207:!l"; -const char *tape = iotape; /* pointer to encryption tape */ +const char *tape = iotape; /* pointer to encryption tape */ -/* next virtual char, bump adr */ +/* next virtual char, bump adr */ static int next(void) { int ch; - ch=(*inptr ^ random()) & 0xFF; /* Decrypt input data */ - if (outsw) /* putting data in tmp file */ - { if (*tape==0) tape=iotape; /* rewind encryption tape */ - *inptr = ch ^ *tape++; /* re-encrypt and replace value */ + ch = (*inptr ^ random()) & 0xFF; /* Decrypt input data */ + if (outsw) { /* putting data in tmp file */ + if (*tape == 0) + tape = iotape; /* rewind encryption tape */ + *inptr = ch ^ *tape++; /* re-encrypt and replace value */ } inptr++; - return(ch); + return (ch); } -char breakch; /* tell which char ended rnum */ +char breakch; /* tell which char ended rnum */ -/* "read" data from virtual file*/ +/* "read" data from virtual file */ void rdata(void) -{ int sect; +{ + int sect; char ch; - inptr = data_file; /* Pointer to virtual data file */ - srandom(SEED); /* which is lightly encrypted. */ + inptr = data_file; /* Pointer to virtual data file */ + srandom(SEED); /* which is lightly encrypted. */ - clsses=1; - for (;;) /* read data sections */ - { sect=next()-'0'; /* 1st digit of section number */ + clsses = 1; + for (;;) { /* read data sections */ + sect = next() - '0'; /* 1st digit of section number */ #ifdef VERBOSE - printf("Section %c",sect+'0'); + printf("Section %c", sect + '0'); #endif - if ((ch=next())!=LF) /* is there a second digit? */ - { + if ((ch = next()) != LF) { /* is there a second digit? */ FLUSHLF; #ifdef VERBOSE putchar(ch); #endif - sect=10*sect+ch-'0'; + sect = 10 * sect + ch - '0'; } #ifdef VERBOSE putchar('\n'); #endif - switch(sect) - { case 0: /* finished reading database */ + switch (sect) { + case 0: /* finished reading database */ return; - case 1: /* long form descriptions */ + case 1: /* long form descriptions */ rdesc(1); break; - case 2: /* short form descriptions */ + case 2: /* short form descriptions */ rdesc(2); break; - case 3: /* travel table */ - rtrav(); break; - case 4: /* vocabulary */ + case 3: /* travel table */ + rtrav(); + break; + case 4: /* vocabulary */ rvoc(); break; - case 5: /* object descriptions */ + case 5: /* object descriptions */ rdesc(5); break; - case 6: /* arbitrary messages */ + case 6: /* arbitrary messages */ rdesc(6); break; - case 7: /* object locations */ - rlocs(); break; - case 8: /* action defaults */ - rdflt(); break; - case 9: /* liquid assets */ - rliq(); break; - case 10: /* class messages */ + case 7: /* object locations */ + rlocs(); + break; + case 8: /* action defaults */ + rdflt(); + break; + case 9: /* liquid assets */ + rliq(); + break; + case 10: /* class messages */ rdesc(10); break; - case 11: /* hints */ - rhints(); break; - case 12: /* magic messages */ + case 11: /* hints */ + rhints(); + break; + case 12: /* magic messages */ rdesc(12); break; - default: - printf("Invalid data section number: %d\n",sect); - for (;;) putchar(next()); + default: + printf("Invalid data section number: %d\n", sect); + for (;;) + putchar(next()); } - if (breakch!=LF) /* routines return after "-1" */ + if (breakch != LF) /* routines return after "-1" */ FLUSHLF; } } char nbf[12]; - -/* read initial location num */ +/* read initial location num */ static int rnum(void) -{ char *s; - tape = iotape; /* restart encryption tape */ - for (s=nbf,*s=0;; s++) - if ((*s=next())==TAB || *s=='\n' || *s==LF) +{ + char *s; + + tape = iotape; /* restart encryption tape */ + for (s = nbf, *s = 0;; s++) + if ((*s = next()) == TAB || *s == '\n' || *s == LF) break; - breakch= *s; /* save char for rtrav() */ - *s=0; /* got the number as ascii */ - if (nbf[0]=='-') return(-1); /* end of data */ - return(atoi(nbf)); /* convert it to integer */ + breakch = *s; /* save char for rtrav() */ + *s = 0; /* got the number as ascii */ + if (nbf[0] == '-') /* end of data */ + return (-1); + return (atoi(nbf)); /* convert it to integer */ } char *seekhere; @@ -279,118 +293,117 @@ rdesc(int sect) int locc; char *seekstart, *maystart; - seekhere = inptr; /* Where are we in virtual file?*/ - outsw=1; /* these msgs go into tmp file */ - for (oldloc= -1, seekstart=seekhere;;) - { maystart=inptr; /* maybe starting new entry */ - if ((locc=rnum())!=oldloc && oldloc>=0 /* finished msg */ - && ! (sect==5 && (locc==0 || locc>=100)))/* unless sect 5*/ - { switch(sect) /* now put it into right table */ - { case 1: /* long descriptions */ - ltext[oldloc].seekadr=seekhere; - ltext[oldloc].txtlen=maystart-seekstart; + seekhere = inptr; /* Where are we in virtual file? */ + outsw = 1; /* these msgs go into tmp file */ + for (oldloc = -1, seekstart = seekhere;;) { + maystart = inptr; /* maybe starting new entry */ + if ((locc = rnum()) != oldloc && oldloc >= 0 /* finished msg */ + /* unless sect 5 */ + && !(sect == 5 && (locc == 0 || locc >= 100))) { + switch (sect) { /* now put it into right table */ + case 1: /* long descriptions */ + ltext[oldloc].seekadr = seekhere; + ltext[oldloc].txtlen = maystart - seekstart; break; - case 2: /* short descriptions */ - stext[oldloc].seekadr=seekhere; - stext[oldloc].txtlen=maystart-seekstart; + case 2: /* short descriptions */ + stext[oldloc].seekadr = seekhere; + stext[oldloc].txtlen = maystart - seekstart; break; - case 5: /* object descriptions */ - ptext[oldloc].seekadr=seekhere; - ptext[oldloc].txtlen=maystart-seekstart; + case 5: /* object descriptions */ + ptext[oldloc].seekadr = seekhere; + ptext[oldloc].txtlen = maystart - seekstart; break; - case 6: /* random messages */ - if (oldloc>RTXSIZ) - { errx(1, "Too many random msgs"); - } - rtext[oldloc].seekadr=seekhere; - rtext[oldloc].txtlen=maystart-seekstart; + case 6: /* random messages */ + if (oldloc > RTXSIZ) + errx(1, "Too many random msgs"); + rtext[oldloc].seekadr = seekhere; + rtext[oldloc].txtlen = maystart - seekstart; break; - case 10: /* class messages */ - ctext[clsses].seekadr=seekhere; - ctext[clsses].txtlen=maystart-seekstart; - cval[clsses++]=oldloc; + case 10: /* class messages */ + ctext[clsses].seekadr = seekhere; + ctext[clsses].txtlen = maystart - seekstart; + cval[clsses++] = oldloc; break; - case 12: /* magic messages */ - if (oldloc>MAGSIZ) - { errx(1, "Too many magic msgs"); - } - mtext[oldloc].seekadr=seekhere; - mtext[oldloc].txtlen=maystart-seekstart; + case 12: /* magic messages */ + if (oldloc > MAGSIZ) + errx(1, "Too many magic msgs"); + mtext[oldloc].seekadr = seekhere; + mtext[oldloc].txtlen = maystart - seekstart; break; - default: + default: errx(1, "rdesc called with bad section"); } - seekhere += maystart-seekstart; + seekhere += maystart - seekstart; } - if (locc<0) - { outsw=0; /* turn off output */ - seekhere += 3; /* -1 */ + if (locc < 0) { + outsw = 0; /* turn off output */ + seekhere += 3; /* -1 */ return; } - if (sect!=5 || (locc>0 && locc<100)) - { if (oldloc!=locc)/* starting a new message */ - seekstart=maystart; - oldloc=locc; + if (sect != 5 || (locc > 0 && locc < 100)) { + if (oldloc != locc) /* starting a new message */ + seekstart = maystart; + oldloc = locc; } - FLUSHLF; /* scan the line */ + FLUSHLF; /* scan the line */ } } - -/* read travel table */ +/* read travel table */ static void rtrav(void) -{ int locc; +{ + int locc; struct travlist *t; char *s; char buf[12]; - int len,m,n,entries; + int len, m, n, entries; entries = 0; t = NULL; - for (oldloc= -1;;) /* get another line */ - { if ((locc=rnum())!=oldloc && oldloc>=0) /* end of entry */ - { - t->next = 0; /* terminate the old entry */ + for (oldloc = -1;;) { /* get another line */ + /* end of entry */ + if ((locc = rnum()) != oldloc && oldloc >= 0) { + t->next = 0; /* terminate the old entry */ #if DEBUG - printf("%d:%d entries\n",oldloc,entries); + printf("%d:%d entries\n", oldloc, entries); twrite(oldloc); #endif } - if (locc== -1) return; - if (locc!=oldloc) /* getting a new entry */ - { t=travel[locc]=(struct travlist *) malloc(sizeof (struct travlist)); - /* printf("New travel list for %d\n",locc); */ + if (locc == -1) + return; + if (locc != oldloc) { /* getting a new entry */ + t = travel[locc] = malloc(sizeof(*t)); if (t == NULL) errx(1, "Out of memory!"); - entries=0; - oldloc=locc; + /* printf("New travel list for %d\n", locc); */ + entries = 0; + oldloc = locc; } - s = buf; - for (;; s++) /* get the newloc number /ASCII */ - if ((*s=next())==TAB || *s==LF) break; - *s=0; - len=strlen(buf); /* quad long number handling */ - /* printf("Newloc: %s (%d chars)\n",buf,len); */ - if (len<4) /* no "m" conditions */ - { m=0; - n=atoi(buf); /* newloc mod 1000 = newloc */ - } - else /* a long integer */ - { n=atoi(buf+len-3); - buf[len-3]=0; /* terminate newloc/1000 */ - m=atoi(buf); + for (s = buf;; s++) /* get the newloc number /ASCII */ + if ((*s = next()) == TAB || *s == LF) + break; + *s = 0; + len = strlen(buf); /* quad long number handling */ + /* printf("Newloc: %s (%d chars)\n", buf, len); */ + if (len < 4) { /* no "m" conditions */ + m = 0; + n = atoi(buf); /* newloc mod 1000 = newloc */ + } else { /* a long integer */ + n = atoi(buf + len - 3); + buf[len - 3] = 0; /* terminate newloc/1000 */ + m = atoi(buf); } - while (breakch!=LF) /* only do one line at a time */ - { if (entries++) { - t=t->next=(struct travlist *) malloc(sizeof (struct travlist)); + while (breakch != LF) { /* only do one line at a time */ + if (entries++) { + t = t->next = malloc(sizeof(*t)); if (t == NULL) errx(1, "Out of memory!"); } - t->tverb=rnum();/* get verb from the file */ - t->tloc=n; /* table entry mod 1000 */ - t->conditions=m;/* table entry / 1000 */ - /* printf("entry %d for %d\n",entries,locc); */ + t->tverb = rnum(); /* get verb from the file */ + t->tloc = n; /* table entry mod 1000 */ + t->conditions = m; /* table entry / 1000 */ + /* printf("entry %d for %d\n", entries, locc); */ } } } @@ -400,104 +413,124 @@ rtrav(void) /* travel options from this loc */ static void twrite(int loq) -{ struct travlist *t; +{ + struct travlist *t; + printf("If"); speak(<ext[loq]); printf("then\n"); - for (t=travel[loq]; t!=0; t=t->next) - { printf("verb %d takes you to ",t->tverb); - if (t->tloc<=300) + for (t = travel[loq]; t != 0; t = t->next) { + printf("verb %d takes you to ", t->tverb); + if (t->tloc <= 300) speak(<ext[t->tloc]); - else if (t->tloc<=500) - printf("special code %d\n",t->tloc-300); + else if (t->tloc <= 500) + printf("special code %d\n", t->tloc - 300); else - rspeak(t->tloc-500); - printf("under conditions %d\n",t->conditions); + rspeak(t->tloc - 500); + printf("under conditions %d\n", t->conditions); } } - #endif /* DEBUG */ +/* read the vocabulary */ static void rvoc(void) -{ char *s; /* read the vocabulary */ +{ + char *s; int rv_index; char buf[6]; - for (;;) - { rv_index=rnum(); - if (rv_index<0) break; - for (s=buf,*s=0;; s++) /* get the word */ - if ((*s=next())==TAB || *s=='\n' || *s==LF - || *s==' ') break; - /* terminate word with newline, LF, tab, blank */ - if (*s!='\n' && *s!=LF) FLUSHLF; /* can be comments */ - *s=0; - /* printf("\"%s\"=%d\n",buf,index);*/ - vocab(buf,-2,rv_index); + + for (;;) { + rv_index = rnum(); + if (rv_index < 0) + break; + for (s = buf, *s = 0;; s++) /* get the word */ + if ((*s = next()) == TAB || *s == '\n' || *s == LF + || *s == ' ') + break; + /* terminate word with newline, LF, tab, blank */ + if (*s != '\n' && *s != LF) + FLUSHLF; /* can be comments */ + *s = 0; + /* printf("\"%s\"=%d\n", buf, rv_index); */ + vocab(buf, -2, rv_index); } } - -/* initial object locations */ +/* initial object locations */ static void rlocs(void) -{ for (;;) - { if ((obj=rnum())<0) break; - plac[obj]=rnum(); /* initial loc for this obj */ - if (breakch==TAB) /* there's another entry */ - fixd[obj]=rnum(); - else fixd[obj]=0; +{ + for (;;) { + if ((obj = rnum()) < 0) + break; + plac[obj] = rnum(); /* initial loc for this obj */ + if (breakch == TAB) /* there's another entry */ + fixd[obj] = rnum(); + else + fixd[obj] = 0; } } -/* default verb messages */ +/* default verb messages */ static void rdflt(void) -{ for (;;) - { if ((verb=rnum())<0) break; - actspk[verb]=rnum(); +{ + for (;;) { + if ((verb = rnum()) < 0) + break; + actspk[verb] = rnum(); } } -/* liquid assets &c: cond bits */ +/* liquid assets &c: cond bits */ static void rliq(void) -{ int bitnum; - for (;;) /* read new bit list */ - { if ((bitnum=rnum())<0) break; - for (;;) /* read locs for bits */ - { cond[rnum()] |= setbit[bitnum]; - if (breakch==LF) break; +{ + int bitnum; + + for (;;) { /* read new bit list */ + if ((bitnum = rnum()) < 0) + break; + for (;;) { /* read locs for bits */ + cond[rnum()] |= setbit[bitnum]; + if (breakch == LF) + break; } } } static void rhints(void) -{ int hintnum,i; - hntmax=0; - for (;;) - { if ((hintnum=rnum())<0) break; - for (i=1; i<5; i++) - hints[hintnum][i]=rnum(); - if (hintnum>hntmax) hntmax=hintnum; +{ + int hintnum, i; + + hntmax = 0; + for (;;) { + if ((hintnum = rnum()) < 0) + break; + for (i = 1; i < 5; i++) + hints[hintnum][i] = rnum(); + if (hintnum > hntmax) + hntmax = hintnum; } } - void rspeak(int msg) -{ if (msg!=0) speak(&rtext[msg]); +{ + if (msg != 0) + speak(&rtext[msg]); } - void mspeak(int msg) -{ if (msg!=0) speak(&mtext[msg]); +{ + if (msg != 0) + speak(&mtext[msg]); } - -/* read, decrypt, and print a message (not ptext) */ +/* read, decrypt, and print a message (not ptext) */ /* msg is a pointer to seek address and length of mess */ void speak(const struct text *msg) @@ -505,62 +538,70 @@ speak(const struct text *msg) char *s, nonfirst; s = msg->seekadr; - nonfirst=0; - while (s - msg->seekadr < msg->txtlen) /* read a line at a time */ - { tape=iotape; /* restart decryption tape */ - while ((*s++ ^ *tape++) != TAB); /* read past loc num */ - /* assume tape is longer than location number */ - /* plus the lookahead put together */ + nonfirst = 0; + while (s - msg->seekadr < msg->txtlen) { /* read a line at a time */ + tape = iotape; /* restart decryption tape */ + while ((*s++ ^ *tape++) != TAB); /* read past loc num */ + /* assume tape is longer than location number */ + /* plus the lookahead put together */ if ((*s ^ *tape) == '>' && - (*(s+1) ^ *(tape+1)) == '$' && - (*(s+2) ^ *(tape+2)) == '<') break; - if (blklin && !nonfirst++) putchar('\n'); - do - { if (*tape == 0) tape = iotape;/* rewind decryp tape */ + (*(s + 1) ^ *(tape + 1)) == '$' && + (*(s + 2) ^ *(tape + 2)) == '<') + break; + if (blklin && !nonfirst++) + putchar('\n'); + do { + if (*tape == 0) + tape = iotape; /* rewind decryp tape */ putchar(*s ^ *tape); - } while ((*s++ ^ *tape++) != LF); /* better end with LF */ + } while ((*s++ ^ *tape++) != LF); /* better end with LF */ } } - -/* read, decrypt an print a ptext message */ -/* msg is the number of all the p msgs for this place */ -/* assumes object 1 doesn't have prop 1, obj 2 no prop 2 &c*/ +/* read, decrypt and print a ptext message */ +/* msg is the number of all the p msgs for this place */ +/* assumes object 1 doesn't have prop 1, obj 2 no prop 2, etc. */ void pspeak(int m, int skip) { - char *s,nonfirst; + char *s, nonfirst; char *numst, ps_save; struct text *msg; char *tbuf; msg = &ptext[m]; - if ((tbuf=(char *) malloc(msg->txtlen + 1)) == 0) + if ((tbuf = malloc(msg->txtlen + 1)) == 0) errx(1, "Out of memory!"); - memcpy(tbuf, msg->seekadr, (u_int)msg->txtlen + 1); /* Room to null */ + memcpy(tbuf, msg->seekadr, (unsigned)msg->txtlen + 1); /* Room to null */ s = tbuf; - nonfirst=0; - while (s - tbuf < msg->txtlen) /* read line at a time */ - { tape=iotape; /* restart decryption tape */ - for (numst=s; (*s^= *tape++)!=TAB; s++); /* get number */ + nonfirst = 0; + while (s - tbuf < msg->txtlen) { /* read line at a time */ + tape = iotape; /* restart decryption tape */ + for (numst = s; (*s ^= *tape++) != TAB; s++) /* get number */ + ; /* nothing */ - ps_save = *s; /* Temporarily trash the string (cringe) */ - *s++ = 0; /* decrypting number within the string */ + ps_save = *s; /* Temporarily trash the string (cringe) */ + *s++ = 0; /* decrypting number within the string */ - if (atoi(numst) != 100 * skip && skip >= 0) - { while ((*s++^*tape++)!=LF) /* flush the line */ - if (*tape==0) tape=iotape; + if (atoi(numst) != 100 * skip && skip >= 0) { + while ((*s++ ^ *tape++) != LF) /* flush the line */ + if (*tape == 0) + tape = iotape; continue; } - if ((*s^*tape)=='>' && (*(s+1)^*(tape+1))=='$' && - (*(s+2)^*(tape+2))=='<') break; - if (blklin && ! nonfirst++) putchar('\n'); - do - { if (*tape==0) tape=iotape; - putchar(*s^*tape); - } while ((*s++^*tape++)!=LF); /* better end with LF */ - if (skip<0) break; + if ((*s ^ *tape) == '>' && (*(s + 1) ^ *(tape + 1)) == '$' && + (*(s + 2) ^ *(tape + 2)) == '<') + break; + if (blklin && !nonfirst++) + putchar('\n'); + do { + if (*tape == 0) + tape = iotape; + putchar(*s ^ *tape); + } while ((*s++ ^ *tape++) != LF); /* better end with LF */ + if (skip < 0) + break; } free(tbuf); } diff --git a/games/adventure/main.c b/games/adventure/main.c index b1923b5a51..e5aee27bac 100644 --- a/games/adventure/main.c +++ b/games/adventure/main.c @@ -15,11 +15,7 @@ * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. - * 4. Neither the name of the University nor the names of its contributors + * 3. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * @@ -41,7 +37,7 @@ * $DragonFly: src/games/adventure/main.c,v 1.3 2005/03/25 12:56:48 liamfoy Exp $ */ -/* Re-coding of advent in C: main program */ +/* Re-coding of advent in C: main program */ #include #include @@ -53,525 +49,690 @@ #include #include "hdr.h" - int -main(int argc, char **argv) +main(int argc, char *argv[]) { int i; - int rval,ll; + int rval, ll; struct text *kk; - /* revoke */ + /* revoke setgid privileges from dm */ setgid(getgid()); - init(); /* Initialize everything */ - signal(SIGINT,trapdel); + init(); /* Initialize everything */ + signal(SIGINT, trapdel); - if (argc > 1) /* Restore file specified */ - { /* Restart is label 8305 (Fortran) */ - i = restore(argv[1]); /* See what we've got */ - switch(i) - { - case 0: /* The restore worked fine */ - yea=Start(); - k=null; + if (argc > 1) { /* Restore file specified */ + /* Restart is label 8305 (Fortran) */ + i = restore(argv[1]); /* See what we've got */ + switch (i) { + case 0: /* The restore worked fine */ + yea = Start(); + k = null; unlink(argv[1]);/* Don't re-use the save */ - goto l8; /* Get where we're going */ - case 1: /* Couldn't open it */ - exit(1); /* So give up */ - case 2: /* Oops -- file was altered */ - rspeak(202); /* You dissolve */ - exit(1); /* File could be non-adventure */ - } /* So don't unlink it. */ + goto l8; /* Get where we're going */ + case 1: /* Couldn't open it */ + exit(1); /* So give up */ + case 2: /* Oops -- file was altered */ + rspeak(202); /* You dissolve */ + exit(1); /* File could be non-adventure */ + } /* So don't unlink it. */ } + startup(); /* prepare for a user */ - startup(); /* prepare for a user */ - - for (;;) /* main command loop (label 2) */ - { if (newloc<9 && newloc!=0 && closng) - { rspeak(130); /* if closing leave only by */ - newloc=loc; /* main office */ - if (!panic) clock2=15; - panic=TRUE; + for (;;) { /* main command loop (label 2) */ + if (newloc < 9 && newloc != 0 && closng) { + rspeak(130); /* if closing leave only by */ + newloc = loc; /* main office */ + if (!panic) + clock2 = 15; + panic = TRUE; } + rval = fdwarf(); /* dwarf stuff */ + if (rval == 99) + die(99); - rval=fdwarf(); /* dwarf stuff */ - if (rval==99) die(99); - - l2000: if (loc==0) die(99); /* label 2000 */ +l2000: if (loc == 0) + die(99); /* label 2000 */ kk = &stext[loc]; - if ((abb[loc]%abbnum)==0 || kk->seekadr==0) + if ((abb[loc] % abbnum) == 0 || kk->seekadr == 0) kk = <ext[loc]; - if (!forced(loc) && dark()) - { if (wzdark && pct(35)) - { die(90); + if (!forced(loc) && dark()) { + if (wzdark && pct(35)) { + die(90); goto l2000; } kk = &rtext[16]; } - if (toting(bear)) rspeak(141); /* 2001 */ + if (toting(bear)) + rspeak(141); /* label 2001 */ speak(kk); - k=1; + k = 1; if (forced(loc)) goto l8; - if (loc==33 && pct(25)&&!closng) rspeak(8); - if (!dark()) - { abb[loc]++; - for (i=atloc[loc]; i!=0; i=linkx[i]) /*2004 */ - { obj=i; - if (obj>100) obj -= 100; - if (obj==steps && toting(nugget)) continue; - if (prop[obj]<0) - { if (closed) continue; - prop[obj]=0; - if (obj==rug||obj==chain) - prop[obj]=1; + if (loc == 33 && pct(25) && !closng) + rspeak(8); + if (!dark()) { + abb[loc]++; + for (i = atloc[loc]; i != 0; i = linkx[i]) { /* 2004 */ + obj = i; + if (obj > 100) + obj -= 100; + if (obj == steps && toting(nugget)) + continue; + if (prop[obj] < 0) { + if (closed) + continue; + prop[obj] = 0; + if (obj == rug || obj == chain) + prop[obj] = 1; tally--; - if (tally==tally2 && tally != 0) - if (limit>35) limit=35; + if (tally == tally2 && tally != 0) + if (limit > 35) + limit = 35; } - ll = prop[obj]; /* 2006 */ - if (obj==steps && loc==fixed[steps]) + ll = prop[obj]; /* 2006 */ + if (obj == steps && loc == fixed[steps]) ll = 1; pspeak(obj, ll); - } /* 2008 */ + } /* 2008 */ goto l2012; - l2009: k=54; /* 2009 */ - l2010: spk=k; - l2011: rspeak(spk); +l2009: k = 54; /* 2009 */ +l2010: spk = k; +l2011: rspeak(spk); } - l2012: verb=0; /* 2012 */ - obj=0; - l2600: checkhints(); /* to 2600-2602 */ - if (closed) - { if (prop[oyster]<0 && toting(oyster)) - pspeak(oyster,1); - for (i=1; i<100; i++) - if (toting(i)&&prop[i]<0) /*2604 */ - prop[i] = -1-prop[i]; +l2012: verb = 0; /* 2012 */ + obj = 0; +l2600: checkhints(); /* to 2600-2602 */ + if (closed) { + if (prop[oyster] < 0 && toting(oyster)) + pspeak(oyster, 1); + for (i = 1; i < 100; i++) + if (toting(i) && prop[i] < 0) /* 2604 */ + prop[i] = -1 - prop[i]; } - wzdark=dark(); /* 2605 */ - if (knfloc>0 && knfloc!=loc) knfloc=1; - getin(&wd1,&wd2); - if (delhit) /* user typed a DEL */ - { delhit=0; /* reset counter */ - strcpy(wd1,"quit"); /* pretend he's quitting*/ - *wd2=0; + wzdark = dark(); /* 2605 */ + if (knfloc > 0 && knfloc != loc) + knfloc = 1; + getin(&wd1, &wd2); + if (delhit) { /* user typed a DEL */ + delhit = 0; /* reset counter */ + strcpy(wd1, "quit"); /* pretend he's quitting */ + wd2[0] = 0; } - l2608: if ((foobar = -foobar)>0) foobar=0; /* 2608 */ - /* should check here for "magic mode" */ +l2608: if ((foobar = -foobar) > 0) + foobar = 0; /* 2608 */ + /* should check here for "magic mode" */ turns++; - if (demo && turns>=SHORT) done(1); /* to 13000 */ + if (demo && turns >= SHORT) + done(1); /* to 13000 */ - if (verb==say && *wd2!=0) verb=0; - if (verb==say) + if (verb == say && wd2[0] != 0) + verb = 0; + if (verb == say) goto l4090; - if (tally==0 && loc>=15 && loc!=33) clock1--; - if (clock1==0) - { closing(); /* to 10000 */ + if (tally == 0 && loc >= 15 && loc != 33) + clock1--; + if (clock1 == 0) { + closing(); /* to 10000 */ goto l19999; } - if (clock1<0) clock2--; - if (clock2==0) - { caveclose(); /* to 11000 */ - continue; /* back to 2 */ + if (clock1 < 0) + clock2--; + if (clock2 == 0) { + caveclose(); /* to 11000 */ + continue; /* back to 2 */ } - if (prop[lamp]==1) limit--; - if (limit<=30 && here(batter) && prop[batter]==0 - && here(lamp)) - { rspeak(188); /* 12000 */ - prop[batter]=1; - if (toting(batter)) drop(batter,loc); - limit=limit+2500; - lmwarn=FALSE; + if (prop[lamp] == 1) + limit--; + if (limit <= 30 && here(batter) && prop[batter] == 0 + && here(lamp)) { + rspeak(188); /* 12000 */ + prop[batter] = 1; + if (toting(batter)) + drop(batter, loc); + limit += 2500; + lmwarn = FALSE; goto l19999; } - if (limit==0) - { limit = -1; /* 12400 */ - prop[lamp]=0; + if (limit == 0) { + limit = -1; /* 12400 */ + prop[lamp] = 0; rspeak(184); goto l19999; } - if (limit<0&&loc<=8) - { rspeak(185); /* 12600 */ - gaveup=TRUE; - done(2); /* to 20000 */ + if (limit < 0 && loc <= 8) { + rspeak(185); /* 12600 */ + gaveup = TRUE; + done(2); /* to 20000 */ } - if (limit<=30) - { if (lmwarn|| !here(lamp)) goto l19999; /*12200*/ - lmwarn=TRUE; - spk=187; - if (place[batter]==0) spk=183; - if (prop[batter]==1) spk=189; + if (limit <= 30) { + if (lmwarn || !here(lamp)) + goto l19999; /* 12200 */ + lmwarn = TRUE; + spk = 187; + if (place[batter] == 0) + spk = 183; + if (prop[batter] == 1) + spk = 189; rspeak(spk); } - l19999: k=43; - if (liqloc(loc)==water) k=70; - if (!strncmp(wd1,"enter",5) && - (!strncmp(wd2,"strea",5)||!strncmp(wd2,"water",5))) +l19999: k = 43; + if (liqloc(loc) == water) + k = 70; + if (!strncmp(wd1, "enter", 5) && + (!strncmp(wd2, "strea", 5) || !strncmp(wd2, "water", 5))) goto l2010; - if (!strncmp(wd1,"enter",5) && *wd2!=0) goto l2800; - if ((strncmp(wd1,"water",5)&&strncmp(wd1,"oil",3)) - || (strncmp(wd2,"plant",5)&&strncmp(wd2,"door",4))) + if (!strncmp(wd1, "enter", 5) && wd2[0] != 0) + goto l2800; + if ((strncmp(wd1, "water", 5) && strncmp(wd1, "oil", 3)) + || (strncmp(wd2, "plant", 5) && strncmp(wd2, "door", 4))) goto l2610; - if (at(vocab(wd2,1,0))) strcpy(wd2,"pour"); + if (at(vocab(wd2, 1, 0))) + strcpy(wd2, "pour"); - l2610: if (!strncmp(wd1,"west",4)) - if (++iwest==10) rspeak(17); - l2630: i=vocab(wd1,-1,0); - if (i== -1) - { spk=60; /* 3000 */ - if (pct(20)) spk=61; - if (pct(20)) spk=13; +l2610: if (!strncmp(wd1, "west", 4)) + if (++iwest == 10) + rspeak(17); +l2630: i = vocab(wd1, -1, 0); + if (i == -1) { + spk = 60; /* 3000 */ + if (pct(20)) + spk = 61; + if (pct(20)) + spk = 13; rspeak(spk); goto l2600; } - k=i%1000; - kq=i/1000+1; - switch(kq) - { case 1: goto l8; - case 2: goto l5000; - case 3: goto l4000; - case 4: goto l2010; - default: + k = i % 1000; + kq = i / 1000 + 1; + switch (kq) { + case 1: + goto l8; + case 2: + goto l5000; + case 3: + goto l4000; + case 4: + goto l2010; + default: bug(22); } - l8: - switch(march()) - { case 2: continue; /* i.e. goto l2 */ - case 99: +l8: + switch (march()) { + case 2: + continue; /* i.e. goto l2 */ + case 99: die(99); goto l2000; - default: bug(110); + default: + bug(110); } - l2800: strcpy(wd1,wd2); - *wd2=0; +l2800: strcpy(wd1, wd2); + wd2[0] = 0; goto l2610; - l4000: verb=k; - spk=actspk[verb]; - if (*wd2!=0 && verb!=say) goto l2800; - if (verb==say) obj= *wd2; - if (obj!=0) goto l4090; - switch(verb) - { case 1: /* take = 8010 */ - if (atloc[loc]==0||linkx[atloc[loc]]!=0) goto l8000; - for (i=1; i<=5; i++) - if (dloc[i]==loc&&dflag>=2) goto l8000; - obj=atloc[loc]; +l4000: verb = k; + spk = actspk[verb]; + if (wd2[0] != 0 && verb != say) + goto l2800; + if (verb == say) + obj = wd2[0]; + if (obj != 0) + goto l4090; + switch (verb) { + case 1: /* take = 8010 */ + if (atloc[loc] == 0 || linkx[atloc[loc]] != 0) + goto l8000; + for (i = 1; i <= 5; i++) + if (dloc[i] == loc && dflag >= 2) + goto l8000; + obj = atloc[loc]; goto l9010; - case 2: case 3: case 9: /* 8000 : drop,say,wave */ - case 10: case 16: case 17: /* calm,rub,toss */ - case 19: case 21: case 28: /* find,feed,break */ - case 29: /* wake */ - l8000: printf("%s what?\n",wd1); - obj=0; + case 2: /* 8000: drop */ + case 3: /* say */ + case 9: /* wave */ + case 10: /* calm */ + case 16: /* rub */ + case 17: /* toss */ + case 19: /* find */ + case 21: /* feed */ + case 28: /* break */ + case 29: /* wake */ +l8000: printf("%s what?\n", wd1); + obj = 0; goto l2600; - case 4: case 6: /* 8040 open,lock */ - spk=28; - if (here(clam)) obj=clam; - if (here(oyster)) obj=oyster; - if (at(door)) obj=door; - if (at(grate)) obj=grate; - if (obj!=0 && here(chain)) goto l8000; - if (here(chain)) obj=chain; - if (obj==0) goto l2011; + case 4: /* 8040: open */ + case 6: /* lock */ + spk = 28; + if (here(clam)) + obj = clam; + if (here(oyster)) + obj = oyster; + if (at(door)) + obj = door; + if (at(grate)) + obj = grate; + if (obj != 0 && here(chain)) + goto l8000; + if (here(chain)) + obj = chain; + if (obj == 0) + goto l2011; goto l9040; - case 5: goto l2009; /* nothing */ - case 7: goto l9070; /* on */ - case 8: goto l9080; /* off */ - case 11: goto l8000; /* walk */ - case 12: goto l9120; /* kill */ - case 13: goto l9130; /* pour */ - case 14: /* eat: 8140 */ - if (!here(food)) goto l8000; - l8142: dstroy(food); - spk=72; + case 5: /* nothing */ + goto l2009; + case 7: /* on */ + goto l9070; + case 8: /* off */ + goto l9080; + case 11: /* walk */ + goto l8000; + case 12: /* kill */ + goto l9120; + case 13: /* pour */ + goto l9130; + case 14: /* eat: 8140 */ + if (!here(food)) + goto l8000; +l8142: dstroy(food); + spk = 72; goto l2011; - case 15: goto l9150; /* drink */ - case 18: /* quit: 8180 */ - gaveup=yes(22,54,54); - if (gaveup) done(2); /* 8185 */ + case 15: /* drink */ + goto l9150; + case 18: /* quit: 8180 */ + gaveup = yes(22, 54, 54); + if (gaveup) + done(2); /* 8185 */ goto l2012; - case 20: /* invent=8200 */ - spk=98; - for (i=1; i<=100; i++) - { if (i!=bear && toting(i)) - { if (spk==98) rspeak(99); - blklin=FALSE; - pspeak(i,-1); - blklin=TRUE; - spk=0; + case 20: /* invent=8200 */ + spk = 98; + for (i = 1; i <= 100; i++) { + if (i != bear && toting(i)) { + if (spk == 98) + rspeak(99); + blklin = FALSE; + pspeak(i, -1); + blklin = TRUE; + spk = 0; } } - if (toting(bear)) spk=141; + if (toting(bear)) + spk = 141; goto l2011; - case 22: goto l9220; /* fill */ - case 23: goto l9230; /* blast */ - case 24: /* score: 8240 */ - scorng=TRUE; + case 22: /* fill */ + goto l9220; + case 23: /* blast */ + goto l9230; + case 24: /* score: 8240 */ + scorng = TRUE; printf("If you were to quit now, you would score"); - printf(" %d out of a possible ",score()); - printf("%d.",mxscor); - scorng=FALSE; - gaveup=yes(143,54,54); - if (gaveup) done(2); + printf(" %d out of a possible ", score()); + printf("%d.", mxscor); + scorng = FALSE; + gaveup = yes(143, 54, 54); + if (gaveup) + done(2); goto l2012; - case 25: /* foo: 8250 */ - k=vocab(wd1,3,0); - spk=42; - if (foobar==1-k) goto l8252; - if (foobar!=0) spk=151; + case 25: /* foo: 8250 */ + k = vocab(wd1, 3, 0); + spk = 42; + if (foobar == 1 - k) + goto l8252; + if (foobar != 0) + spk = 151; goto l2011; - l8252: foobar=k; - if (k!=4) goto l2009; - foobar=0; - if (place[eggs]==plac[eggs] - ||(toting(eggs)&&loc==plac[eggs])) goto l2011; - if (place[eggs]==0&&place[troll]==0&&prop[troll]==0) - prop[troll]=1; - k=2; - if (here(eggs)) k=1; - if (loc==plac[eggs]) k=0; - move(eggs,plac[eggs]); - pspeak(eggs,k); +l8252: foobar = k; + if (k != 4) + goto l2009; + foobar = 0; + if (place[eggs] == plac[eggs] + || (toting(eggs) && loc == plac[eggs])) + goto l2011; + if (place[eggs] == 0 && place[troll] == 0 && + prop[troll] == 0) + prop[troll] = 1; + k = 2; + if (here(eggs)) + k = 1; + if (loc == plac[eggs]) + k = 0; + move(eggs, plac[eggs]); + pspeak(eggs, k); goto l2012; - case 26: /* brief=8260 */ - spk=156; - abbnum=10000; - detail=3; + case 26: /* brief=8260 */ + spk = 156; + abbnum = 10000; + detail = 3; goto l2011; - case 27: /* read=8270 */ - if (here(magzin)) obj=magzin; - if (here(tablet)) obj=obj*100+tablet; - if (here(messag)) obj=obj*100+messag; - if (closed&&toting(oyster)) obj=oyster; - if (obj>100||obj==0||dark()) goto l8000; + case 27: /* read=8270 */ + if (here(magzin)) + obj = magzin; + if (here(tablet)) + obj = obj * 100 + tablet; + if (here(messag)) + obj = obj * 100 + messag; + if (closed && toting(oyster)) + obj = oyster; + if (obj > 100 || obj == 0 || dark()) + goto l8000; goto l9270; - case 30: /* suspend=8300 */ - spk=201; - if (demo) goto l2011; + case 30: /* suspend=8300 */ + spk = 201; + if (demo) + goto l2011; printf("I can suspend your adventure for you so"); printf(" you can resume later, but\n"); printf("you will have to wait at least"); - printf(" %d minutes before continuing.",latncy); - if (!yes(200,54,54)) goto l2012; - datime(&saved,&savet); - ciao(); /* Do we quit? */ - continue; /* Maybe not */ - case 31: /* hours=8310 */ + printf(" %d minutes before continuing.", latncy); + if (!yes(200, 54, 54)) + goto l2012; + datime(&saved, &savet); + ciao(); /* Do we quit? */ + continue; /* Maybe not */ + case 31: /* hours=8310 */ printf("Colossal cave is closed 9am-5pm Mon "); printf("through Fri except holidays.\n"); goto l2012; - default: bug(23); + default: + bug(23); } - l4090: - switch(verb) - { case 1: /* take = 9010 */ - l9010: switch(trtake()) - { case 2011: goto l2011; - case 9220: goto l9220; - case 2009: goto l2009; - case 2012: goto l2012; - default: bug(102); +l4090: + switch (verb) { + case 1: /* take = 9010 */ +l9010: switch (trtake()) { + case 2011: + goto l2011; + case 9220: + goto l9220; + case 2009: + goto l2009; + case 2012: + goto l2012; + default: + bug(102); } - l9020: case 2: /* drop = 9020 */ - switch(trdrop()) - { case 2011: goto l2011; - case 19000: done(3); - case 2012: goto l2012; - default: bug(105); +l9020: case 2: /* drop = 9020 */ + switch (trdrop()) { + case 2011: + goto l2011; + case 19000: + done(3); + case 2012: + goto l2012; + default: + bug(105); } - case 3: - switch(trsay()) - { case 2012: goto l2012; - case 2630: goto l2630; - default: bug(107); + case 3: /* label 9030 */ + switch (trsay()) { + case 2012: + goto l2012; + case 2630: + goto l2630; + default: + bug(107); } - l9040: case 4: case 6: /* open, close */ - switch(tropen()) - { case 2011: goto l2011; - case 2010: goto l2010; - default: bug(106); +l9040: case 4: /* open */ + case 6: /* close */ + switch (tropen()) { + case 2011: + goto l2011; + case 2010: + goto l2010; + default: + bug(106); } - case 5: goto l2009; /* nothing */ - case 7: /* on 9070 */ - l9070: if (!here(lamp)) goto l2011; - spk=184; - if (limit<0) goto l2011; - prop[lamp]=1; + case 5: /* nothing */ + goto l2009; + case 7: /* on 9070 */ +l9070: if (!here(lamp)) + goto l2011; + spk = 184; + if (limit < 0) + goto l2011; + prop[lamp] = 1; rspeak(39); - if (wzdark) goto l2000; + if (wzdark) + goto l2000; goto l2012; - case 8: /* off */ - l9080: if (!here(lamp)) goto l2011; - prop[lamp]=0; + case 8: /* off */ +l9080: if (!here(lamp)) + goto l2011; + prop[lamp] = 0; rspeak(40); - if (dark()) rspeak(16); + if (dark()) + rspeak(16); goto l2012; - case 9: /* wave */ - if ((!toting(obj))&&(obj!=rod||!toting(rod2))) - spk=29; - if (obj!=rod||!at(fissur)||!toting(obj)||closng) + case 9: /* wave */ + if ((!toting(obj)) && (obj != rod || !toting(rod2))) + spk = 29; + if (obj != rod || !at(fissur) || !toting(obj) || closng) goto l2011; - prop[fissur]=1-prop[fissur]; - pspeak(fissur,2-prop[fissur]); + prop[fissur] = 1 - prop[fissur]; + pspeak(fissur, 2 - prop[fissur]); goto l2012; - case 10: case 11: case 18: /* calm, walk, quit */ - case 24: case 25: case 26: /* score, foo, brief */ - case 30: case 31: /* suspend, hours */ - goto l2011; - l9120: case 12: /* kill */ - switch(trkill()) - { case 8000: goto l8000; - case 8: goto l8; - case 2011: goto l2011; - case 2608: goto l2608; - case 19000: done(3); - default: bug(112); + case 10: /* calm */ + case 11: /* walk */ + case 18: /* quit */ + case 24: /* score */ + case 25: /* foo */ + case 26: /* brief */ + case 30: /* suspend */ + case 31: /* hours */ + goto l2011; +l9120: case 12: /* kill */ + switch (trkill()) { + case 8000: + goto l8000; + case 8: + goto l8; + case 2011: + goto l2011; + case 2608: + goto l2608; + case 19000: + done(3); + default: + bug(112); } - l9130: case 13: /* pour */ - if (obj==bottle||obj==0) obj=liq(); - if (obj==0) goto l8000; - if (!toting(obj)) goto l2011; - spk=78; - if (obj!=oil&&obj!=water) goto l2011; - prop[bottle]=1; - place[obj]=0; - spk=77; - if (!(at(plant)||at(door))) goto l2011; - if (at(door)) - { prop[door]=0; /* 9132 */ - if (obj==oil) prop[door]=1; - spk=113+prop[door]; +l9130: case 13: /* pour */ + if (obj == bottle || obj == 0) + obj = liq(); + if (obj == 0) + goto l8000; + if (!toting(obj)) + goto l2011; + spk = 78; + if (obj != oil && obj != water) + goto l2011; + prop[bottle] = 1; + place[obj] = 0; + spk = 77; + if (!(at(plant) || at(door))) + goto l2011; + if (at(door)) { + prop[door] = 0; /* 9132 */ + if (obj == oil) + prop[door] = 1; + spk = 113 + prop[door]; goto l2011; } - spk=112; - if (obj!=water) goto l2011; - pspeak(plant,prop[plant]+1); - prop[plant]=(prop[plant]+2)% 6; - prop[plant2]=prop[plant]/2; - k=null; + spk = 112; + if (obj != water) + goto l2011; + pspeak(plant, prop[plant] + 1); + prop[plant] = (prop[plant] + 2)% 6; + prop[plant2] = prop[plant] / 2; + k = null; goto l8; - case 14: /* 9140 - eat */ - if (obj==food) goto l8142; - if (obj==bird||obj==snake||obj==clam||obj==oyster - ||obj==dwarf||obj==dragon||obj==troll - ||obj==bear) spk=71; + case 14: /* 9140: eat */ + if (obj == food) + goto l8142; + if (obj == bird || obj == snake || obj == clam + || obj == oyster || obj == dwarf || obj == dragon + || obj == troll || obj == bear) + spk = 71; goto l2011; - l9150: case 15: /* 9150 - drink */ - if (obj==0&&liqloc(loc)!=water&&(liq()!=water - ||!here(bottle))) goto l8000; - if (obj!=0&&obj!=water) spk=110; - if (spk==110||liq()!=water||!here(bottle)) +l9150: case 15: /* 9150: drink */ + if (obj == 0 && liqloc(loc) != water && (liq() != water + || !here(bottle))) + goto l8000; + if (obj != 0 && obj != water) + spk = 110; + if (spk == 110 || liq() != water || !here(bottle)) goto l2011; - prop[bottle]=1; - place[water]=0; - spk=74; + prop[bottle] = 1; + place[water] = 0; + spk = 74; goto l2011; - case 16: /* 9160: rub */ - if (obj!=lamp) spk=76; + case 16: /* 9160: rub */ + if (obj != lamp) + spk = 76; goto l2011; - case 17: /* 9170: throw */ - switch(trtoss()) - { case 2011: goto l2011; - case 9020: goto l9020; - case 9120: goto l9120; - case 8: goto l8; - case 9210: goto l9210; - default: bug(113); + case 17: /* 9170: throw */ + switch (trtoss()) { + case 2011: + goto l2011; + case 9020: + goto l9020; + case 9120: + goto l9120; + case 8: + goto l8; + case 9210: + goto l9210; + default: + bug(113); } - case 19: case 20: /* 9190: find, invent */ - if (at(obj)||(liq()==obj&&at(bottle)) - ||k==liqloc(loc)) spk=94; - for (i=1; i<=5; i++) - if (dloc[i]==loc&&dflag>=2&&obj==dwarf) - spk=94; - if (closed) spk=138; - if (toting(obj)) spk=24; + case 19: /* 9190: find */ + case 20: /* invent */ + if (at(obj) || (liq() == obj && at(bottle)) + || k == liqloc(loc)) + spk = 94; + for (i = 1; i <= 5; i++) + if (dloc[i] == loc && dflag >= 2 + && obj == dwarf) + spk = 94; + if (closed) + spk = 138; + if (toting(obj)) + spk = 24; goto l2011; - l9210: case 21: /* feed */ - switch(trfeed()) - { case 2011: goto l2011; - default: bug(114); +l9210: case 21: /* feed */ + switch (trfeed()) { + case 2011: + goto l2011; + default: + bug(114); } - l9220: case 22: /* fill */ - switch(trfill()) - { case 2011: goto l2011; - case 8000: goto l8000; - case 9020: goto l9020; - default: bug(115); +l9220: case 22: /* fill */ + switch (trfill()) { + case 2011: + goto l2011; + case 8000: + goto l8000; + case 9020: + goto l9020; + default: + bug(115); } - l9230: case 23: /* blast */ - if (prop[rod2]<0||!closed) goto l2011; - bonus=133; - if (loc==115) bonus=134; - if (here(rod2)) bonus=135; +l9230: case 23: /* blast */ + if (prop[rod2] < 0 || !closed) + goto l2011; + bonus = 133; + if (loc == 115) + bonus = 134; + if (here(rod2)) + bonus = 135; rspeak(bonus); done(2); - l9270: case 27: /* read */ - if (dark()) goto l5190; - if (obj==magzin) spk=190; - if (obj==tablet) spk=196; - if (obj==messag) spk=191; - if (obj==oyster&&hinted[2]&&toting(oyster)) spk=194; - if (obj!=oyster||hinted[2]||!toting(oyster) - ||!closed) goto l2011; - hinted[2]=yes(192,193,54); +l9270: case 27: /* read */ + if (dark()) + goto l5190; + if (obj == magzin) + spk = 190; + if (obj == tablet) + spk = 196; + if (obj == messag) + spk = 191; + if (obj == oyster && hinted[2] && toting(oyster)) + spk = 194; + if (obj != oyster || hinted[2] || !toting(oyster) + || !closed) + goto l2011; + hinted[2] = yes(192, 193, 54); goto l2012; - case 28: /* break */ - if (obj==mirror) spk=148; - if (obj==vase&&prop[vase]==0) - { spk=198; - if (toting(vase)) drop(vase,loc); - prop[vase]=2; - fixed[vase]= -1; + case 28: /* 9280: break */ + if (obj == mirror) + spk = 148; + if (obj == vase && prop[vase] == 0) { + spk = 198; + if (toting(vase)) + drop(vase, loc); + prop[vase] = 2; + fixed[vase] = -1; goto l2011; } - if (obj!=mirror||!closed) goto l2011; + if (obj != mirror || !closed) + goto l2011; rspeak(197); done(3); - - case 29: /* wake */ - if (obj!=dwarf||!closed) goto l2011; + case 29: /* 9290: wake */ + if (obj != dwarf || !closed) + goto l2011; rspeak(199); done(3); - default: bug(24); + default: + bug(24); } - l5000: - obj=k; - if (fixed[k]!=loc && !here(k)) goto l5100; - l5010: if (*wd2!=0) goto l2800; - if (verb!=0) goto l4090; - printf("What do you want to do with the %s?\n",wd1); +l5000: + obj = k; + if (fixed[k] != loc && !here(k)) + goto l5100; +l5010: if (wd2[0] != 0) + goto l2800; + if (verb != 0) + goto l4090; + printf("What do you want to do with the %s?\n", wd1); goto l2600; - l5100: if (k!=grate) goto l5110; - if (loc==1||loc==4||loc==7) k=dprssn; - if (loc>9&&loc<15) k=entrnc; - if (k!=grate) goto l8; - l5110: if (k!=dwarf) goto l5120; - for (i=1; i<=5; i++) - if (dloc[i]==loc&&dflag>=2) goto l5010; - l5120: if ((liq()==k&&here(bottle))||k==liqloc(loc)) goto l5010; - if (obj!=plant||!at(plant2)||prop[plant2]==0) goto l5130; - obj=plant2; +l5100: if (k != grate) + goto l5110; + if (loc == 1 || loc == 4 || loc == 7) + k = dprssn; + if (loc > 9 && loc < 15) + k = entrnc; + if (k != grate) + goto l8; +l5110: if (k != dwarf) + goto l5120; + for (i = 1; i <= 5; i++) + if (dloc[i] == loc && dflag >= 2) + goto l5010; +l5120: if ((liq() == k && here(bottle)) || k == liqloc(loc)) + goto l5010; + if (obj != plant || !at(plant2) || prop[plant2] == 0) + goto l5130; + obj = plant2; goto l5010; - l5130: if (obj!=knife||knfloc!=loc) goto l5140; +l5130: if (obj != knife || knfloc != loc) + goto l5140; knfloc = -1; - spk=116; + spk = 116; goto l2011; - l5140: if (obj!=rod||!here(rod2)) goto l5190; - obj=rod2; +l5140: if (obj != rod || !here(rod2)) + goto l5190; + obj = rod2; goto l5010; - l5190: if ((verb==find||verb==invent)&&*wd2==0) goto l5010; - printf("I see no %s here\n",wd1); +l5190: if ((verb == find || verb == invent) && wd2[0] == 0) + goto l5010; + printf("I see no %s here\n", wd1); goto l2012; } } diff --git a/games/adventure/save.c b/games/adventure/save.c index a6a48a4705..9693707d8f 100644 --- a/games/adventure/save.c +++ b/games/adventure/save.c @@ -15,11 +15,7 @@ * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. - * 4. Neither the name of the University nor the names of its contributors + * 3. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * @@ -45,80 +41,81 @@ #include #include "hdr.h" -struct savestruct -{ +struct savestruct { void *address; int width; }; struct savestruct save_array[] = { - {&abbnum, sizeof(abbnum)}, - {&attack, sizeof(attack)}, - {&blklin, sizeof(blklin)}, - {&bonus, sizeof(bonus)}, - {&chloc, sizeof(chloc)}, - {&chloc2, sizeof(chloc2)}, - {&clock1, sizeof(clock1)}, - {&clock2, sizeof(clock2)}, - {&closed, sizeof(closed)}, - {&closng, sizeof(closng)}, - {&daltlc, sizeof(daltlc)}, - {&demo, sizeof(demo)}, - {&detail, sizeof(detail)}, - {&dflag, sizeof(dflag)}, - {&dkill, sizeof(dkill)}, - {&dtotal, sizeof(dtotal)}, - {&foobar, sizeof(foobar)}, - {&gaveup, sizeof(gaveup)}, - {&holdng, sizeof(holdng)}, - {&iwest, sizeof(iwest)}, - {&k, sizeof(k)}, - {&k2, sizeof(k2)}, - {&knfloc, sizeof(knfloc)}, - {&kq, sizeof(kq)}, - {&latncy, sizeof(latncy)}, - {&limit, sizeof(limit)}, - {&lmwarn, sizeof(lmwarn)}, - {&loc, sizeof(loc)}, - {&maxdie, sizeof(maxdie)}, - {&mxscor, sizeof(mxscor)}, - {&newloc, sizeof(newloc)}, - {&numdie, sizeof(numdie)}, - {&obj, sizeof(obj)}, - {&oldlc2, sizeof(oldlc2)}, - {&oldloc, sizeof(oldloc)}, - {&panic, sizeof(panic)}, - {&saved, sizeof(saved)}, - {&savet, sizeof(savet)}, - {&scorng, sizeof(scorng)}, - {&spk, sizeof(spk)}, - {&stick, sizeof(stick)}, - {&tally, sizeof(tally)}, - {&tally2, sizeof(tally2)}, - {&tkk, sizeof(tkk)}, - {&turns, sizeof(turns)}, - {&verb, sizeof(verb)}, - {&wd1, sizeof(wd1)}, - {&wd2, sizeof(wd2)}, - {&wzdark, sizeof(wzdark)}, - {&yea, sizeof(yea)}, - {atloc, sizeof(atloc)}, - {dloc, sizeof(dloc)}, - {dseen, sizeof(dseen)}, - {fixed, sizeof(fixed)}, - {hinted, sizeof(hinted)}, - {linkx, sizeof(linkx)}, - {odloc, sizeof(odloc)}, - {place, sizeof(place)}, - {prop, sizeof(prop)}, - {tk, sizeof(tk)}, + {&abbnum, sizeof(abbnum)}, + {&attack, sizeof(attack)}, + {&blklin, sizeof(blklin)}, + {&bonus, sizeof(bonus)}, + {&chloc, sizeof(chloc)}, + {&chloc2, sizeof(chloc2)}, + {&clock1, sizeof(clock1)}, + {&clock2, sizeof(clock2)}, + {&closed, sizeof(closed)}, + {&closng, sizeof(closng)}, + {&daltlc, sizeof(daltlc)}, + {&demo, sizeof(demo)}, + {&detail, sizeof(detail)}, + {&dflag, sizeof(dflag)}, + {&dkill, sizeof(dkill)}, + {&dtotal, sizeof(dtotal)}, + {&foobar, sizeof(foobar)}, + {&gaveup, sizeof(gaveup)}, + {&holdng, sizeof(holdng)}, + {&iwest, sizeof(iwest)}, + {&k, sizeof(k)}, + {&k2, sizeof(k2)}, + {&knfloc, sizeof(knfloc)}, + {&kq, sizeof(kq)}, + {&latncy, sizeof(latncy)}, + {&limit, sizeof(limit)}, + {&lmwarn, sizeof(lmwarn)}, + {&loc, sizeof(loc)}, + {&maxdie, sizeof(maxdie)}, + {&mxscor, sizeof(mxscor)}, + {&newloc, sizeof(newloc)}, + {&numdie, sizeof(numdie)}, + {&obj, sizeof(obj)}, + {&oldlc2, sizeof(oldlc2)}, + {&oldloc, sizeof(oldloc)}, + {&panic, sizeof(panic)}, + {&saved, sizeof(saved)}, + {&savet, sizeof(savet)}, + {&scorng, sizeof(scorng)}, + {&spk, sizeof(spk)}, + {&stick, sizeof(stick)}, + {&tally, sizeof(tally)}, + {&tally2, sizeof(tally2)}, + {&tkk, sizeof(tkk)}, + {&turns, sizeof(turns)}, + {&verb, sizeof(verb)}, + {&wd1, sizeof(wd1)}, + {&wd2, sizeof(wd2)}, + {&wzdark, sizeof(wzdark)}, + {&yea, sizeof(yea)}, + {atloc, sizeof(atloc)}, + {dloc, sizeof(dloc)}, + {dseen, sizeof(dseen)}, + {fixed, sizeof(fixed)}, + {hinted, sizeof(hinted)}, + {linkx, sizeof(linkx)}, + {odloc, sizeof(odloc)}, + {place, sizeof(place)}, + {prop, sizeof(prop)}, + {tk, sizeof(tk)}, - {NULL, 0} + {NULL, 0} }; -/* Two passes on data: first to get checksum, second */ -/* to output the data using checksum to start random #s */ +/* + * Two passes on data: first to get checksum, second + * to output the data using checksum to start random #s + */ int save(const char *outfile) { @@ -131,21 +128,18 @@ save(const char *outfile) crc_start(); for (p = save_array; p->address != NULL; p++) sum = crc(p->address, p->width); - srandom((int) sum); + srandom(sum); - if ((out = fopen(outfile, "wb")) == NULL) - { - fprintf(stderr, - "Hmm. The name \"%s\" appears to be magically blocked.\n", - outfile); - return 1; + if ((out = fopen(outfile, "wb")) == NULL) { + fprintf(stderr, + "Hmm. The name \"%s\" appears to be magically blocked.\n", + outfile); + return 1; } - - fwrite(&sum, sizeof(sum), 1, out); /* Here's the random() key */ - for (p = save_array; p->address != NULL; p++) - { + fwrite(&sum, sizeof(sum), 1, out); /* Here's the random() key */ + for (p = save_array; p->address != NULL; p++) { for (s = p->address, i = 0; i < p->width; i++, s++) - *s = (*s ^ random()) & 0xFF; /* Lightly encrypt */ + *s = (*s ^ random()) & 0xFF; /* Lightly encrypt */ fwrite(p->address, p->width, 1, out); } fclose(out); @@ -162,29 +156,26 @@ restore(const char *infile) int i; cksum = 0; - if ((in = fopen(infile, "rb")) == NULL) - { - fprintf(stderr, - "Hmm. The file \"%s\" appears to be magically blocked.\n", - infile); - return 1; + if ((in = fopen(infile, "rb")) == NULL) { + fprintf(stderr, + "Hmm. The file \"%s\" appears to be magically blocked.\n", + infile); + return 1; } - - fread(&sum, sizeof(sum), 1, in); /* Get the seed */ - srandom((int) sum); - for (p = save_array; p->address != NULL; p++) - { + fread(&sum, sizeof(sum), 1, in); /* Get the seed */ + srandom(sum); + for (p = save_array; p->address != NULL; p++) { fread(p->address, p->width, 1, in); for (s = p->address, i = 0; i < p->width; i++, s++) - *s = (*s ^ random()) & 0xFF; /* Lightly decrypt */ + *s = (*s ^ random()) & 0xFF; /* Lightly decrypt */ } fclose(in); - crc_start(); /* See if she cheated */ + crc_start(); /* See if she cheated */ for (p = save_array; p->address != NULL; p++) cksum = crc(p->address, p->width); - if (sum != cksum) /* Tsk tsk */ - return 2; /* Altered the file */ + if (sum != cksum) /* Tsk tsk */ + return 2; /* Altered the file */ /* We successfully restored, so this really was a save file */ /* Get rid of the file, but don't bother checking that we did */ return 0; diff --git a/games/adventure/setup.c b/games/adventure/setup.c index a83911ac0f..1217872e88 100644 --- a/games/adventure/setup.c +++ b/games/adventure/setup.c @@ -13,11 +13,7 @@ * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. - * 4. Neither the name of the University nor the names of its contributors + * 3. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * @@ -55,14 +51,14 @@ #include #include #include -#include "hdr.h" /* SEED lives in there; keep them coordinated. */ +#include "hdr.h" /* SEED lives in there; keep them coordinated. */ #define USAGE "Usage: setup file > data.c (file is typically glorkz)" #define YES 1 #define NO 0 -#define LINE 10 /* How many values do we get on a line? */ +#define LINE 10 /* How many values do we get on a line? */ int main(int argc, char **argv) @@ -70,7 +66,8 @@ main(int argc, char **argv) FILE *infile; int c, count, linestart; - if (argc != 2) errx(1, USAGE); + if (argc != 2) + errx(1, USAGE); if ((infile = fopen(argv[1], "r")) == NULL) err(1, "Can't read file %s", argv[1]); @@ -83,10 +80,8 @@ main(int argc, char **argv) count = 0; linestart = YES; - while ((c = getc(infile)) != EOF) - { - if (linestart && c == ' ') /* Convert first spaces to tab */ - { + while ((c = getc(infile)) != EOF) { + if (linestart && c == ' ') { /* Convert first spaces to tab */ if (count++ % LINE == 0) printf("\n\t"); printf("0x%02lx,", ('\t' ^ random()) & 0xFF); @@ -94,12 +89,11 @@ main(int argc, char **argv) /* Drop the non-whitespace character through */ linestart = NO; } - switch(c) - { - case '\t': + switch (c) { + case '\t': linestart = NO; /* Don't need to convert spaces */ break; - case '\n': + case '\n': linestart = YES; /* Ready to convert spaces again */ break; } diff --git a/games/adventure/subr.c b/games/adventure/subr.c index a4276d9f6d..13480c2001 100644 --- a/games/adventure/subr.c +++ b/games/adventure/subr.c @@ -15,11 +15,7 @@ * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. - * 4. Neither the name of the University nor the names of its contributors + * 3. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * @@ -40,837 +36,1021 @@ * $DragonFly: src/games/adventure/subr.c,v 1.4 2007/04/18 18:32:12 swildner Exp $ */ -/* Re-coding of advent in C: subroutines from main */ +/* Re-coding of advent in C: subroutines from main */ #include #include #include #include "hdr.h" -static void badmove (void); -static int bitset (int,int); -static int dropper (void); -static int liq2 (int); -static int mback (void); -static int specials (void); -static int trbridge (void); +static void badmove(void); +static int bitset(int, int); +static int dropper(void); +static int liq2(int); +static int mback(void); +static int specials(void); +static int trbridge(void); -/* Statement functions */ +/* Statement functions */ int toting(int objj) -{ if (place[objj] == -1) return(TRUE); - else return(FALSE); +{ + if (place[objj] == -1) + return (TRUE); + else + return (FALSE); } int here(int objj) -{ if (place[objj]==loc || toting(objj)) return(TRUE); - else return(FALSE); +{ + if (place[objj] == loc || toting(objj)) + return (TRUE); + else + return (FALSE); } int at(int objj) -{ if (place[objj]==loc || fixed[objj]==loc) return(TRUE); - else return (FALSE); +{ + if (place[objj] == loc || fixed[objj] == loc) + return (TRUE); + else + return (FALSE); } static int liq2(int pbotl) -{ return((1-pbotl)*water+(pbotl/2)*(water+oil)); +{ + return ((1 - pbotl) * water + (pbotl / 2) * (water + oil)); } int liq(void) -{ int i; - i=prop[bottle]; - if (i>-1-i) return(liq2(i)); - else return(liq2(-1-i)); +{ + int i; + i = prop[bottle]; + if (i > -1 - i) + return (liq2(i)); + else + return (liq2(-1 - i)); } /* may want to clean this one up a bit */ int liqloc(int locc) -{ int i,j,l; - i=cond[locc]/2; - j=((i*2)%8)-5; - l=cond[locc]/4; - l=l%2; - return(liq2(j*l+1)); +{ + int i, j, l; + i = cond[locc] / 2; + j = ((i * 2) % 8) - 5; + l = cond[locc] / 4; + l = l % 2; + return (liq2(j * l + 1)); } static int bitset(int l, int n) -{ if (cond[l] & setbit[n]) return(TRUE); - return(FALSE); +{ + if (cond[l] & setbit[n]) + return (TRUE); + return (FALSE); } int forced(int locc) -{ if (cond[locc]==2) return(TRUE); - return(FALSE); +{ + if (cond[locc] == 2) + return (TRUE); + return (FALSE); } int dark(void) -{ if ((cond[loc]%2)==0 && (prop[lamp]==0 || !here(lamp))) - return(TRUE); - return(FALSE); +{ + if ((cond[loc] % 2) == 0 && (prop[lamp] == 0 || !here(lamp))) + return (TRUE); + return (FALSE); } int pct(int n) -{ if (ran(100)=15) dflag=1; - return(2000); - } - if (dflag==1) /* 6000 */ - { if (loc<15||pct(95)) return(2000); - dflag=2; - for (i=1; i<=2; i++) - { j=1+ran(5); - if (pct(50)&&saved== -1) dloc[j]=0; /* 6001 */ + loc = newloc; /* 74 */ + if (loc == 0 || forced(loc) || bitset(newloc, 3)) + return (2000); + if (dflag == 0) { + if (loc >= 15) + dflag = 1; + return (2000); + } + if (dflag == 1) { /* 6000 */ + if (loc < 15 || pct(95)) + return (2000); + dflag = 2; + for (i = 1; i <= 2; i++) { + j = 1 + ran(5); + if (pct(50) && saved == -1) + dloc[j] = 0; /* 6001 */ } - for (i=1; i<=5; i++) - { if (dloc[i]==loc) dloc[i]=daltlc; - odloc[i]=dloc[i]; /* 6002 */ + for (i = 1; i <= 5; i++) { + if (dloc[i] == loc) + dloc[i] = daltlc; + odloc[i] = dloc[i]; /* 6002 */ } rspeak(3); - drop(axe,loc); - return(2000); - } - dtotal=attack=stick=0; /* 6010 */ - for (i=1; i<=6; i++) /* loop to 6030 */ - { if (dloc[i]==0) continue; - j=1; - for (kk=travel[dloc[i]]; kk!=0; kk=kk->next) - { newloc=kk->tloc; - if (newloc>300||newloc<15||newloc==odloc[i] - ||(j>1&&newloc==tk[j-1])||j>=20 - ||newloc==dloc[i]||forced(newloc) - ||(i==6&&bitset(newloc,3)) - ||kk->conditions==100) continue; - tk[j++]=newloc; + drop(axe, loc); + return (2000); + } + dtotal = attack = stick = 0; /* 6010 */ + for (i = 1; i <= 6; i++) { /* loop to 6030 */ + if (dloc[i] == 0) + continue; + j = 1; + for (kk = travel[dloc[i]]; kk != 0; kk = kk->next) { + newloc = kk->tloc; + if (newloc > 300 || newloc < 15 || newloc == odloc[i] + || (j > 1 && newloc == tk[j - 1]) || j >= 20 + || newloc == dloc[i] || forced(newloc) + || (i == 6 && bitset(newloc, 3)) + || kk->conditions == 100) + continue; + tk[j++] = newloc; } - tk[j]=odloc[i]; /* 6016 */ - if (j>=2) j--; - j=1+ran(j); - odloc[i]=dloc[i]; - dloc[i]=tk[j]; - dseen[i]=(dseen[i]&&loc>=15)||(dloc[i]==loc||odloc[i]==loc); - if (!dseen[i]) continue; /* i.e. goto 6030 */ - dloc[i]=loc; - if (i==6) /* pirate's spotted him */ - { if (loc==chloc||prop[chest]>=0) continue; - k=0; - for (j=50; j<=maxtrs; j++) /* loop to 6020 */ - { if (j==pyram&&(loc==plac[pyram] - || loc==plac[emrald])) goto l6020; - if (toting(j)) goto l6022; - l6020: if (here(j)) k=1; - } /* 6020 */ - if (tally==tally2+1 && k==0 && place[chest]==0 - &&here(lamp) && prop[lamp]==1) goto l6025; - if (odloc[6]!=dloc[6]&&pct(20)) + tk[j] = odloc[i]; /* 6016 */ + if (j >= 2) + j--; + j = 1 + ran(j); + odloc[i] = dloc[i]; + dloc[i] = tk[j]; + dseen[i] = (dseen[i] && loc >= 15) || + (dloc[i] == loc || odloc[i] == loc); + if (!dseen[i]) /* i.e. goto 6030 */ + continue; + dloc[i] = loc; + if (i == 6) { /* pirate's spotted him */ + if (loc == chloc || prop[chest] >= 0) + continue; + k = 0; + for (j = 50; j <= maxtrs; j++) { /* loop to 6020 */ + if (j == pyram && (loc == plac[pyram] + || loc == plac[emrald])) + goto l6020; + if (toting(j)) + goto l6022; +l6020: if (here(j)) + k = 1; + } /* 6020 */ + if (tally == tally2 + 1 && k == 0 && place[chest] == 0 + && here(lamp) && prop[lamp] == 1) + goto l6025; + if (odloc[6] != dloc[6] && pct(20)) rspeak(127); - continue; /* to 6030 */ - l6022: rspeak(128); - if (place[messag]==0) move(chest,chloc); - move(messag,chloc2); - for (j=50; j<=maxtrs; j++) /* loop to 6023 */ - { if (j==pyram && (loc==plac[pyram] - || loc==plac[emrald])) continue; - if (at(j)&&fixed[j]==0) carry(j,loc); - if (toting(j)) drop(j,chloc); + continue; /* to 6030 */ +l6022: rspeak(128); + if (place[messag] == 0) + move(chest, chloc); + move(messag, chloc2); + for (j = 50; j <= maxtrs; j++) { /* loop to 6023 */ + if (j == pyram && (loc == plac[pyram] + || loc == plac[emrald])) + continue; + if (at(j) && fixed[j] == 0) + carry(j, loc); + if (toting(j)) + drop(j, chloc); } - l6024: dloc[6]=odloc[6]=chloc; - dseen[6]=FALSE; +l6024: dloc[6] = odloc[6] = chloc; + dseen[6] = FALSE; continue; - l6025: rspeak(186); - move(chest,chloc); - move(messag,chloc2); +l6025: rspeak(186); + move(chest, chloc); + move(messag, chloc2); goto l6024; } - dtotal++; /* 6027 */ - if (odloc[i]!=dloc[i]) continue; + dtotal++; /* 6027 */ + if (odloc[i] != dloc[i]) + continue; attack++; - if (knfloc>=0) knfloc=loc; - if (ran(1000)<95*(dflag-2)) stick++; - } /* 6030 */ - if (dtotal==0) return(2000); - if (dtotal!=1) - { printf("There are %d threatening little dwarves ",dtotal); + if (knfloc >= 0) + knfloc = loc; + if (ran(1000) < 95 * (dflag - 2)) + stick++; + } /* 6030 */ + if (dtotal == 0) + return (2000); + if (dtotal != 1) { + printf("There are %d threatening little dwarves ", dtotal); printf("in the room with you.\n"); - } - else rspeak(4); - if (attack==0) return(2000); - if (dflag==2) dflag=3; - if (saved!= -1) dflag=20; - if (attack!=1) - { printf("%d of them throw knives at you!\n",attack); - k=6; - l82: if (stick<=1) /* 82 */ - { rspeak(k+stick); - if (stick==0) return(2000); - } - else - printf("%d of them get you!\n",stick); /* 83 */ - oldlc2=loc; - return(99); + } else + rspeak(4); + if (attack == 0) + return (2000); + if (dflag == 2) + dflag = 3; + if (saved != -1) + dflag = 20; + if (attack != 1) { + printf("%d of them throw knives at you!\n", attack); + k = 6; +l82: if (stick <= 1) { /* 82 */ + rspeak(k + stick); + if (stick == 0) + return (2000); + } else + printf("%d of them get you!\n", stick); /* 83 */ + oldlc2 = loc; + return (99); } rspeak(5); - k=52; + k = 52; goto l82; } - -/* label 8 */ +/* label 8 */ int march(void) -{ int ll1,ll2; - - if ((tkk=travel[newloc=loc])==0) bug(26); - if (k==null) return(2); - if (k==cave) /* 40 */ - { if (loc<8) rspeak(57); - if (loc>=8) rspeak(58); - return(2); - } - if (k==look) /* 30 */ - { if (detail++<3) rspeak(15); - wzdark=FALSE; - abb[loc]=0; - return(2); - } - if (k==back) /* 20 */ - { switch(mback()) - { case 2: return(2); - case 9: goto l9; - default: bug(100); +{ + int ll1, ll2; + + if ((tkk = travel[newloc = loc]) == 0) + bug(26); + if (k == null) + return (2); + if (k == cave) { /* 40 */ + if (loc < 8) + rspeak(57); + if (loc >= 8) + rspeak(58); + return (2); + } + if (k == look) { /* 30 */ + if (detail++ < 3) + rspeak(15); + wzdark = FALSE; + abb[loc] = 0; + return (2); + } + if (k == back) { /* 20 */ + switch (mback()) { + case 2: + return (2); + case 9: + goto l9; + default: + bug(100); } } - oldlc2=oldloc; - oldloc=loc; + oldlc2 = oldloc; + oldloc = loc; l9: - for (; tkk!=0; tkk=tkk->next) - if (tkk->tverb==1 || tkk->tverb==k) break; - if (tkk==0) - { badmove(); - return(2); - } -l11: ll1=tkk->conditions; /* 11 */ - ll2=tkk->tloc; - newloc=ll1; /* newloc=conditions */ - k=newloc%100; /* k used for prob */ - if (newloc<=300) - { if (newloc<=100) /* 13 */ - { if (newloc!=0&&!pct(newloc)) goto l12; /* 14 */ - l16: newloc=ll2; /* newloc=location */ - if (newloc<=300) return(2); - if (newloc<=500) - switch(specials())/* to 30000 */ - { case 2: return(2); - case 12: goto l12; - case 99: return(99); - default: bug(101); + for (; tkk != 0; tkk = tkk->next) + if (tkk->tverb == 1 || tkk->tverb == k) + break; + if (tkk == 0) { + badmove(); + return (2); + } +l11: ll1 = tkk->conditions; /* 11 */ + ll2 = tkk->tloc; + newloc = ll1; /* newloc=conditions */ + k = newloc % 100; /* k used for prob */ + if (newloc <= 300) { + if (newloc <= 100) { /* 13 */ + if (newloc != 0 && !pct(newloc)) /* 14 */ + goto l12; +l16: newloc = ll2; /* newloc=location */ + if (newloc <= 300) + return (2); + if (newloc <= 500) + switch (specials()) { /* to 30000 */ + case 2: + return (2); + case 12: + goto l12; + case 99: + return (99); + default: + bug(101); } - rspeak(newloc-500); - newloc=loc; - return(2); + rspeak(newloc - 500); + newloc = loc; + return (2); } - if (toting(k)||(newloc>200&&at(k))) goto l16; + if (toting(k) || (newloc > 200 && at(k))) + goto l16; goto l12; } - if (prop[k]!=(newloc/100)-3) goto l16; /* newloc still conditions*/ -l12: /* alternative to probability move */ - for (; tkk!=0; tkk=tkk->next) - if (tkk->tloc!=ll2 || tkk->conditions!=ll1) break; - if (tkk==0) bug(25); + if (prop[k] != (newloc / 100) - 3) /* newloc still conditions */ + goto l16; +l12: /* alternative to probability move */ + for (; tkk != 0; tkk = tkk->next) + if (tkk->tloc != ll2 || tkk->conditions != ll1) + break; + if (tkk == 0) + bug(25); goto l11; } - -/* 20 */ +/* 20 */ static int mback(void) -{ struct travlist *tk2,*j; +{ + struct travlist *tk2, *j; int ll; - if (forced(k=oldloc)) k=oldlc2; /* k=location */ - oldlc2=oldloc; - oldloc=loc; - tk2=0; - if (k==loc) - { rspeak(91); - return(2); - } - for (; tkk!=0; tkk=tkk->next) /* 21 */ - { ll=tkk->tloc; - if (ll==k) - { k=tkk->tverb; /* k back to verb */ - tkk=travel[loc]; - return(9); + + if (forced(k = oldloc)) /* k=location */ + k = oldlc2; + oldlc2 = oldloc; + oldloc = loc; + tk2 = 0; + if (k == loc) { + rspeak(91); + return (2); + } + for (; tkk != 0; tkk = tkk->next) { /* 21 */ + ll = tkk->tloc; + if (ll == k) { + k = tkk->tverb; /* k back to verb */ + tkk = travel[loc]; + return (9); } - if (ll<=300) - { j=travel[loc]; - if (forced(ll) && k==j->tloc) tk2=tkk; + if (ll <= 300) { + j = travel[loc]; + if (forced(ll) && k == j->tloc) + tk2 = tkk; } } - tkk=tk2; /* 23 */ - if (tkk!=0) - { k=tkk->tverb; - tkk=travel[loc]; - return(9); + tkk = tk2; /* 23 */ + if (tkk != 0) { + k = tkk->tverb; + tkk = travel[loc]; + return (9); } rspeak(140); - return(2); + return (2); } - -/* 30000 */ +/* 30000 */ static int specials(void) -{ switch(newloc -= 300) - { case 1: /* 30100 */ - newloc = 99+100-loc; - if (holdng==0||(holdng==1&&toting(emrald))) return(2); - newloc=loc; +{ + switch (newloc -= 300) { + case 1: /* 30100 */ + newloc = 99 + 100 - loc; + if (holdng == 0 || (holdng == 1 && toting(emrald))) + return (2); + newloc = loc; rspeak(117); - return(2); - case 2: /* 30200 */ - drop(emrald,loc); - return(12); - case 3: /* to 30300 */ - return(trbridge()); - default: bug(29); + return (2); + case 2: /* 30200 */ + drop(emrald, loc); + return (12); + case 3: /* to 30300 */ + return (trbridge()); + default: + bug(29); } /* NOTREACHED */ - return(-1); + return (-1); } - -/* 30300 */ +/* 30300 */ static int trbridge(void) -{ if (prop[troll]==1) - { pspeak(troll,1); - prop[troll]=0; - move(troll2,0); - move(troll2+100,0); - move(troll,plac[troll]); - move(troll+100,fixd[troll]); +{ + if (prop[troll] == 1) { + pspeak(troll, 1); + prop[troll] = 0; + move(troll2, 0); + move(troll2 + 100, 0); + move(troll, plac[troll]); + move(troll + 100, fixd[troll]); juggle(chasm); - newloc=loc; - return(2); + newloc = loc; + return (2); } - newloc=plac[troll]+fixd[troll]-loc; /* 30310 */ - if (prop[troll]==0) prop[troll]=1; - if (!toting(bear)) return(2); + newloc = plac[troll] + fixd[troll] - loc; /* 30310 */ + if (prop[troll] == 0) + prop[troll] = 1; + if (!toting(bear)) + return (2); rspeak(162); - prop[chasm]=1; - prop[troll]=2; - drop(bear,newloc); + prop[chasm] = 1; + prop[troll] = 2; + drop(bear, newloc); fixed[bear] = -1; - prop[bear]=3; - if (prop[spices]<0) tally2++; - oldlc2=newloc; - return(99); + prop[bear] = 3; + if (prop[spices] < 0) + tally2++; + oldlc2 = newloc; + return (99); } - -/* 20 */ +/* 20 */ static void badmove(void) -{ spk=12; - if (k>=43 && k<=50) spk=9; - if (k==29||k==30) spk=9; - if (k==7||k==36||k==37) spk=10; - if (k==11||k==19) spk=11; - if (verb==find||verb==invent) spk=59; - if (k==62||k==65) spk=42; - if (k==17) spk=80; +{ + spk = 12; + if (k >= 43 && k <= 50) + spk = 9; + if (k == 29 || k == 30) + spk = 9; + if (k == 7 || k == 36 || k == 37) + spk = 10; + if (k == 11 || k == 19) + spk = 11; + if (verb == find || verb == invent) + spk = 59; + if (k == 62 || k == 65) + spk = 42; + if (k == 17) + spk = 80; rspeak(spk); } int bug(int n) -{ printf("Please tell jim@rand.org that fatal bug %d happened.\n",n); +{ + printf("Please tell jim@rand.org that fatal bug %d happened.\n", n); exit(1); } - -/* 2600 &c */ +/* 2600 etc */ void checkhints(void) -{ int hint; - for (hint=4; hint<=hntmax; hint++) - { if (hinted[hint]) continue; - if (!bitset(loc,hint)) hintlc[hint]= -1; +{ + int hint; + + for (hint = 4; hint <= hntmax; hint++) { + if (hinted[hint]) + continue; + if (!bitset(loc, hint)) + hintlc[hint] = -1; hintlc[hint]++; - if (hintlc[hint]1) goto l40010; + case 7: /* 40700 */ + if (atloc[loc] == 0 && atloc[oldloc] == 0 + && atloc[oldlc2] == 0 && holdng > 1) + goto l40010; goto l40020; - case 8: /* 40800 */ - if (prop[emrald]!= -1&&prop[pyram]== -1) goto l40010; + case 8: /* 40800 */ + if (prop[emrald] != -1 && prop[pyram] == -1) + goto l40010; goto l40020; - case 9: - goto l40010; /* 40900 */ - default: bug(27); + case 9: /* 40900 */ + goto l40010; + default: + bug(27); } - l40010: hintlc[hint]=0; - if (!yes(hints[hint][3],0,54)) continue; +l40010: hintlc[hint] = 0; + if (!yes(hints[hint][3], 0, 54)) + continue; printf("I am prepared to give you a hint, but it will "); - printf("cost you %d points.\n",hints[hint][2]); - hinted[hint]=yes(175,hints[hint][4],54); - l40020: hintlc[hint]=0; + printf("cost you %d points.\n", hints[hint][2]); + hinted[hint] = yes(175, hints[hint][4], 54); +l40020: hintlc[hint] = 0; } } - -/* 9030 */ +/* 9030 */ int trsay(void) -{ int i; - if (*wd2!=0) strcpy(wd1,wd2); - i=vocab(wd1,-1,0); - if (i==62||i==65||i==71||i==2025) - { *wd2=0; - obj=0; - return(2630); - } - printf("\nOkay, \"%s\".\n",wd2); - return(2012); -} +{ + int i; + if (wd2[0] != 0) + strcpy(wd1, wd2); + i = vocab(wd1, -1, 0); + if (i == 62 || i == 65 || i == 71 || i == 2025) { + wd2[0] = 0; + obj = 0; + return (2630); + } + printf("\nOkay, \"%s\".\n", wd2); + return (2012); +} -/* 9010 */ +/* 9010 */ int trtake(void) { - if (toting(obj)) return(2011); /* 9010 */ - spk=25; - if (obj==plant&&prop[plant]<=0) spk=115; - if (obj==bear&&prop[bear]==1) spk=169; - if (obj==chain&&prop[bear]!=0) spk=170; - if (fixed[obj]!=0) return(2011); - if (obj==water||obj==oil) - { if (here(bottle)&&liq()==obj) - { obj=bottle; + if (toting(obj)) /* 9010 */ + return (2011); + spk = 25; + if (obj == plant && prop[plant] <= 0) + spk = 115; + if (obj == bear && prop[bear] == 1) + spk = 169; + if (obj == chain && prop[bear] != 0) + spk = 170; + if (fixed[obj] != 0) + return (2011); + if (obj == water || obj == oil) { + if (here(bottle) && liq() == obj) { + obj = bottle; goto l9017; } - obj=bottle; - if (toting(bottle)&&prop[bottle]==1) - return(9220); - if (prop[bottle]!=1) spk=105; - if (!toting(bottle)) spk=104; - return(2011); - } -l9017: if (holdng>=7) - { rspeak(92); - return(2012); - } - if (obj==bird) - { if (prop[bird]!=0) goto l9014; - if (toting(rod)) - { rspeak(26); - return(2012); + obj = bottle; + if (toting(bottle) && prop[bottle] == 1) + return (9220); + if (prop[bottle] != 1) + spk = 105; + if (!toting(bottle)) + spk = 104; + return (2011); + } +l9017: if (holdng >= 7) { + rspeak(92); + return (2012); + } + if (obj == bird) { + if (prop[bird] != 0) + goto l9014; + if (toting(rod)) { + rspeak(26); + return (2012); } - if (!toting(cage)) /* 9013 */ - { rspeak(27); - return(2012); + if (!toting(cage)) { /* 9013 */ + rspeak(27); + return (2012); } - prop[bird]=1; /* 9015 */ - } -l9014: if ((obj==bird||obj==cage)&&prop[bird]!=0) - carry(bird+cage-obj,loc); - carry(obj,loc); - k=liq(); - if (obj==bottle && k!=0) place[k] = -1; - return(2009); + prop[bird] = 1; /* 9015 */ + } +l9014: if ((obj == bird || obj == cage) && prop[bird] != 0) + carry(bird + cage - obj, loc); + carry(obj, loc); + k = liq(); + if (obj == bottle && k != 0) + place[k] = -1; + return (2009); } - -/* 9021 */ +/* 9021 */ static int dropper(void) -{ k=liq(); - if (k==obj) obj=bottle; - if (obj==bottle&&k!=0) place[k]=0; - if (obj==cage&&prop[bird]!=0) drop(bird,loc); - if (obj==bird) prop[bird]=0; - drop(obj,loc); - return(2012); +{ + k = liq(); + if (k == obj) + obj = bottle; + if (obj == bottle && k != 0) + place[k] = 0; + if (obj == cage && prop[bird] != 0) + drop(bird, loc); + if (obj == bird) + prop[bird] = 0; + drop(obj, loc); + return (2012); } -/* 9020 */ +/* 9020 */ int trdrop(void) { - if (toting(rod2)&&obj==rod&&!toting(rod)) obj=rod2; - if (!toting(obj)) return(2011); - if (obj==bird&&here(snake)) - { rspeak(30); - if (closed) return(19000); + if (toting(rod2) && obj == rod && !toting(rod)) + obj = rod2; + if (!toting(obj)) + return (2011); + if (obj == bird && here(snake)) { + rspeak(30); + if (closed) + return (19000); dstroy(snake); - prop[snake]=1; - return(dropper()); + prop[snake] = 1; + return (dropper()); } - if (obj==coins&&here(vend)) /* 9024 */ - { dstroy(coins); - drop(batter,loc); - pspeak(batter,0); - return(2012); + if (obj == coins && here(vend)) { /* 9024 */ + dstroy(coins); + drop(batter, loc); + pspeak(batter, 0); + return (2012); } - if (obj==bird&&at(dragon)&&prop[dragon]==0) /* 9025 */ - { rspeak(154); + if (obj == bird && at(dragon) && prop[dragon] == 0) { /* 9025 */ + rspeak(154); dstroy(bird); - prop[bird]=0; - if (place[snake]==plac[snake]) tally2--; - return(2012); - } - if (obj==bear&&at(troll)) /* 9026 */ - { rspeak(163); - move(troll,0); - move(troll+100,0); - move(troll2,plac[troll]); - move(troll2+100,fixd[troll]); + prop[bird] = 0; + if (place[snake] == plac[snake]) + tally2--; + return (2012); + } + if (obj == bear && at(troll)) { /* 9026 */ + rspeak(163); + move(troll, 0); + move(troll + 100, 0); + move(troll2, plac[troll]); + move(troll2 + 100, fixd[troll]); juggle(chasm); - prop[troll]=2; - return(dropper()); - } - if (obj!=vase||loc==plac[pillow]) /* 9027 */ - { rspeak(54); - return(dropper()); - } - prop[vase]=2; /* 9028 */ - if (at(pillow)) prop[vase]=0; - pspeak(vase,prop[vase]+1); - if (prop[vase]!=0) fixed[vase] = -1; - return(dropper()); + prop[troll] = 2; + return (dropper()); + } + if (obj != vase || loc == plac[pillow]) { /* 9027 */ + rspeak(54); + return (dropper()); + } + prop[vase] = 2; /* 9028 */ + if (at(pillow)) + prop[vase] = 0; + pspeak(vase, prop[vase] + 1); + if (prop[vase] != 0) + fixed[vase] = -1; + return (dropper()); } - -/* 9040 */ +/* 9040 */ int tropen(void) -{ if (obj==clam||obj==oyster) - { k=0; /* 9046 */ - if (obj==oyster) k=1; - spk=124+k; - if (toting(obj)) spk=120+k; - if (!toting(tridnt)) spk=122+k; - if (verb==lock) spk=61; - if (spk!=124) return(2011); +{ + if (obj == clam || obj == oyster) { + k = 0; /* 9046 */ + if (obj == oyster) + k = 1; + spk = 124 + k; + if (toting(obj)) + spk = 120 + k; + if (!toting(tridnt)) + spk = 122 + k; + if (verb == lock) + spk = 61; + if (spk != 124) + return (2011); dstroy(clam); - drop(oyster,loc); - drop(pearl,105); - return(2011); - } - if (obj==door) spk=111; - if (obj==door&&prop[door]==1) spk=54; - if (obj==cage) spk=32; - if (obj==keys) spk=55; - if (obj==grate||obj==chain) spk=31; - if (spk!=31||!here(keys)) return(2011); - if (obj==chain) - { if (verb==lock) - { spk=172; /* 9049: lock */ - if (prop[chain]!=0) spk=34; - if (loc!=plac[chain]) spk=173; - if (spk!=172) return(2011); - prop[chain]=2; - if (toting(chain)) drop(chain,loc); - fixed[chain]= -1; - return(2011); + drop(oyster, loc); + drop(pearl, 105); + return (2011); + } + if (obj == door) + spk = 111; + if (obj == door && prop[door] == 1) + spk = 54; + if (obj == cage) + spk = 32; + if (obj == keys) + spk = 55; + if (obj == grate || obj == chain) + spk = 31; + if (spk != 31 || !here(keys)) + return (2011); + if (obj == chain) { + if (verb == lock) { + spk = 172; /* 9049: lock */ + if (prop[chain] != 0) + spk = 34; + if (loc != plac[chain]) + spk = 173; + if (spk != 172) + return (2011); + prop[chain] = 2; + if (toting(chain)) + drop(chain, loc); + fixed[chain] = -1; + return (2011); } - spk=171; - if (prop[bear]==0) spk=41; - if (prop[chain]==0) spk=37; - if (spk!=171) return(2011); - prop[chain]=0; - fixed[chain]=0; - if (prop[bear]!=3) prop[bear]=2; - fixed[bear]=2-prop[bear]; - return(2011); - } - if (closng) - { k=130; - if (!panic) clock2=15; - panic=TRUE; - return(2010); - } - k=34+prop[grate]; /* 9043 */ - prop[grate]=1; - if (verb==lock) prop[grate]=0; - k=k+2*prop[grate]; - return(2010); + spk = 171; + if (prop[bear] == 0) + spk = 41; + if (prop[chain] == 0) + spk = 37; + if (spk != 171) + return (2011); + prop[chain] = 0; + fixed[chain] = 0; + if (prop[bear] != 3) + prop[bear] = 2; + fixed[bear] = 2 - prop[bear]; + return (2011); + } + if (closng) { + k = 130; + if (!panic) + clock2 = 15; + panic = TRUE; + return (2010); + } + k = 34 + prop[grate]; /* 9043 */ + prop[grate] = 1; + if (verb == lock) + prop[grate] = 0; + k = k + 2 * prop[grate]; + return (2010); } - -/* 9120 */ +/* 9120 */ int trkill(void) -{ int i; - for (i=1; i<=5; i++) - if (dloc[i]==loc&&dflag>=2) break; - if (i==6) i=0; - if (obj==0) /* 9122 */ - { if (i!=0) obj=dwarf; - if (here(snake)) obj=obj*100+snake; - if (at(dragon)&&prop[dragon]==0) obj=obj*100+dragon; - if (at(troll)) obj=obj*100+troll; - if (here(bear)&&prop[bear]==0) obj=obj*100+bear; - if (obj>100) return(8000); - if (obj==0) - { if (here(bird)&&verb!=throw) obj=bird; - if (here(clam)||here(oyster)) obj=100*obj+clam; - if (obj>100) return(8000); +{ + int i; + + for (i = 1; i <= 5; i++) + if (dloc[i] == loc && dflag >= 2) + break; + if (i == 6) + i = 0; + if (obj == 0) { /* 9122 */ + if (i != 0) + obj = dwarf; + if (here(snake)) + obj = obj * 100 + snake; + if (at(dragon) && prop[dragon] == 0) + obj = obj * 100 + dragon; + if (at(troll)) + obj = obj * 100 + troll; + if (here(bear) && prop[bear] == 0) + obj = obj * 100 + bear; + if (obj > 100) + return (8000); + if (obj == 0) { + if (here(bird) && verb != throw) + obj = bird; + if (here(clam) || here(oyster)) + obj = 100 * obj + clam; + if (obj > 100) + return (8000); } } - if (obj==bird) /* 9124 */ - { spk=137; - if (closed) return(2011); + if (obj == bird) { /* 9124 */ + spk = 137; + if (closed) + return (2011); dstroy(bird); - prop[bird]=0; - if (place[snake]==plac[snake]) tally2++; - spk=45; - } - if (obj==0) spk=44; /* 9125 */ - if (obj==clam||obj==oyster) spk=150; - if (obj==snake) spk=46; - if (obj==dwarf) spk=49; - if (obj==dwarf&&closed) return(19000); - if (obj==dragon) spk=147; - if (obj==troll) spk=157; - if (obj==bear) spk=165+(prop[bear]+1)/2; - if (obj!=dragon||prop[dragon]!=0) return(2011); + prop[bird] = 0; + if (place[snake] == plac[snake]) + tally2++; + spk = 45; + } + if (obj == 0) /* 9125 */ + spk = 44; + if (obj == clam || obj == oyster) + spk = 150; + if (obj == snake) + spk = 46; + if (obj == dwarf) + spk = 49; + if (obj == dwarf && closed) + return (19000); + if (obj == dragon) + spk = 147; + if (obj == troll) + spk = 157; + if (obj == bear) + spk = 165 + (prop[bear] + 1) / 2; + if (obj != dragon || prop[dragon] != 0) + return (2011); rspeak(49); - verb=0; - obj=0; - getin(&wd1,&wd2); - if (strncmp(wd1,"y",1)&&strncmp(wd1,"yes",3)) return(2608); - pspeak(dragon,1); - prop[dragon]=2; - prop[rug]=0; - k=(plac[dragon]+fixd[dragon])/2; - move(dragon+100,-1); - move(rug+100,0); - move(dragon,k); - move(rug,k); - for (obj=1; obj<=100; obj++) - if (place[obj]==plac[dragon]||place[obj]==fixd[dragon]) - move(obj,k); - loc=k; - k=null; - return(8); + verb = 0; + obj = 0; + getin(&wd1, &wd2); + if (strncmp(wd1, "y", 1) && strncmp(wd1, "yes", 3)) + return (2608); + pspeak(dragon, 1); + prop[dragon] = 2; + prop[rug] = 0; + k = (plac[dragon] + fixd[dragon]) / 2; + move(dragon + 100, -1); + move(rug + 100, 0); + move(dragon, k); + move(rug, k); + for (obj = 1; obj <= 100; obj++) + if (place[obj] == plac[dragon] || place[obj] == fixd[dragon]) + move(obj, k); + loc = k; + k = null; + return (8); } - -/* 9170: throw */ +/* 9170: throw */ int trtoss(void) -{ int i; - if (toting(rod2)&&obj==rod&&!toting(rod)) obj=rod2; - if (!toting(obj)) return(2011); - if (obj>=50&&obj<=maxtrs&&at(troll)) - { spk=159; /* 9178 */ - drop(obj,0); - move(troll,0); - move(troll+100,0); - drop(troll2,plac[troll]); - drop(troll2+100,fixd[troll]); +{ + int i; + + if (toting(rod2) && obj == rod && !toting(rod)) + obj = rod2; + if (!toting(obj)) + return (2011); + if (obj >= 50 && obj <= maxtrs && at(troll)) { + spk = 159; /* 9178 */ + drop(obj, 0); + move(troll, 0); + move(troll + 100, 0); + drop(troll2, plac[troll]); + drop(troll2 + 100, fixd[troll]); juggle(chasm); - return(2011); - } - if (obj==food&&here(bear)) - { obj=bear; /* 9177 */ - return(9210); - } - if (obj!=axe) return(9020); - for (i=1; i<=5; i++) - { if (dloc[i]==loc) - { spk=48; /* 9172 */ - if (ran(3)==0||saved!= -1) - l9175: { rspeak(spk); - drop(axe,loc); - k=null; - return(8); + return (2011); + } + if (obj == food && here(bear)) { + obj = bear; /* 9177 */ + return (9210); + } + if (obj != axe) + return (9020); + for (i = 1; i <= 5; i++) { + if (dloc[i] == loc) { + spk = 48; /* 9172 */ + if (ran(3) == 0 || saved != -1) { +l9175: rspeak(spk); + drop(axe, loc); + k = null; + return (8); } - dseen[i]=FALSE; - dloc[i]=0; - spk=47; + dseen[i] = FALSE; + dloc[i] = 0; + spk = 47; dkill++; - if (dkill==1) spk=149; + if (dkill == 1) + spk = 149; goto l9175; } } - spk=152; - if (at(dragon)&&prop[dragon]==0) + spk = 152; + if (at(dragon) && prop[dragon] == 0) goto l9175; - spk=158; - if (at(troll)) goto l9175; - if (here(bear)&&prop[bear]==0) - { spk=164; - drop(axe,loc); - fixed[axe]= -1; - prop[axe]=1; + spk = 158; + if (at(troll)) + goto l9175; + if (here(bear) && prop[bear] == 0) { + spk = 164; + drop(axe, loc); + fixed[axe] = -1; + prop[axe] = 1; juggle(bear); - return(2011); + return (2011); } - obj=0; - return(9120); + obj = 0; + return (9120); } - -/* 9210 */ +/* 9210 */ int trfeed(void) -{ if (obj==bird) - { spk=100; - return(2011); - } - if (obj==snake||obj==dragon||obj==troll) - { spk=102; - if (obj==dragon&&prop[dragon]!=0) spk=110; - if (obj==troll) spk=182; - if (obj!=snake||closed||!here(bird)) return(2011); - spk=101; +{ + if (obj == bird) { + spk = 100; + return (2011); + } + if (obj == snake || obj == dragon || obj == troll) { + spk = 102; + if (obj == dragon && prop[dragon] != 0) + spk = 110; + if (obj == troll) + spk = 182; + if (obj != snake || closed || !here(bird)) + return (2011); + spk = 101; dstroy(bird); - prop[bird]=0; + prop[bird] = 0; tally2++; - return(2011); + return (2011); } - if (obj==dwarf) - { if (!here(food)) return(2011); - spk=103; + if (obj == dwarf) { + if (!here(food)) + return (2011); + spk = 103; dflag++; - return(2011); + return (2011); } - if (obj==bear) - { if (prop[bear]==0) spk=102; - if (prop[bear]==3) spk=110; - if (!here(food)) return(2011); + if (obj == bear) { + if (prop[bear] == 0) + spk = 102; + if (prop[bear] == 3) + spk = 110; + if (!here(food)) + return (2011); dstroy(food); - prop[bear]=1; - fixed[axe]=0; - prop[axe]=0; - spk=168; - return(2011); - } - spk=14; - return(2011); + prop[bear] = 1; + fixed[axe] = 0; + prop[axe] = 0; + spk = 168; + return (2011); + } + spk = 14; + return (2011); } - /* 9220 */ int trfill(void) -{ if (obj==vase) - { spk=29; - if (liqloc(loc)==0) spk=144; - if (liqloc(loc)==0||!toting(vase)) return(2011); +{ + if (obj == vase) { + spk = 29; + if (liqloc(loc) == 0) + spk = 144; + if (liqloc(loc) == 0 || !toting(vase)) + return (2011); rspeak(145); - prop[vase]=2; - fixed[vase]= -1; - return(9020); /* advent/10 goes to 9024 */ - } - if (obj!=0&&obj!=bottle) return(2011); - if (obj==0&&!here(bottle)) return(8000); - spk=107; - if (liqloc(loc)==0) spk=106; - if (liq()!=0) spk=105; - if (spk!=107) return(2011); - prop[bottle]=((cond[loc]%4)/2)*2; - k=liq(); - if (toting(bottle)) place[k]= -1; - if (k==oil) spk=108; - return(2011); + prop[vase] = 2; + fixed[vase] = -1; + return (9020); /* advent/10 goes to 9024 */ + } + if (obj != 0 && obj != bottle) + return (2011); + if (obj == 0 && !here(bottle)) + return (8000); + spk = 107; + if (liqloc(loc) == 0) + spk = 106; + if (liq() != 0) + spk = 105; + if (spk != 107) + return (2011); + prop[bottle] = ((cond[loc] % 4) / 2) * 2; + k = liq(); + if (toting(bottle)) + place[k] = -1; + if (k == oil) + spk = 108; + return (2011); } - /* 10000 */ void closing(void) -{ int i; +{ + int i; - prop[grate]=prop[fissur]=0; - for (i=1; i<=6; i++) - { dseen[i]=FALSE; - dloc[i]=0; + prop[grate] = prop[fissur] = 0; + for (i = 1; i <= 6; i++) { + dseen[i] = FALSE; + dloc[i] = 0; } - move(troll,0); - move(troll+100,0); - move(troll2,plac[troll]); - move(troll2+100,fixd[troll]); + move(troll, 0); + move(troll + 100, 0); + move(troll2, plac[troll]); + move(troll2 + 100, fixd[troll]); juggle(chasm); - if(prop[bear]!=3) dstroy(bear); - prop[chain]=0; - fixed[chain]=0; - prop[axe]=0; - fixed[axe]=0; + if (prop[bear] != 3) + dstroy(bear); + prop[chain] = 0; + fixed[chain] = 0; + prop[axe] = 0; + fixed[axe] = 0; rspeak(129); clock1 = -1; - closng=TRUE; + closng = TRUE; } - /* 11000 */ void caveclose(void) -{ int i; - prop[bottle]=put(bottle,115,1); - prop[plant]=put(plant,115,0); - prop[oyster]=put(oyster,115,0); - prop[lamp]=put(lamp,115,0); - prop[rod]=put(rod,115,0); - prop[dwarf]=put(dwarf,115,0); - loc=115; - oldloc=115; - newloc=115; - - put(grate,116,0); - prop[snake]=put(snake,116,1); - prop[bird]=put(bird,116,1); - prop[cage]=put(cage,116,0); - prop[rod2]=put(rod2,116,0); - prop[pillow]=put(pillow,116,0); - - prop[mirror]=put(mirror,115,0); - fixed[mirror]=116; - - for (i=1; i<=100; i++) - if (toting(i)) dstroy(i); +{ + int i; + + prop[bottle] = put(bottle, 115, 1); + prop[plant] = put(plant, 115, 0); + prop[oyster] = put(oyster, 115, 0); + prop[lamp] = put(lamp, 115, 0); + prop[rod] = put(rod, 115, 0); + prop[dwarf] = put(dwarf, 115, 0); + loc = 115; + oldloc = 115; + newloc = 115; + + put(grate, 116, 0); + prop[snake] = put(snake, 116, 1); + prop[bird] = put(bird, 116, 1); + prop[cage] = put(cage, 116, 0); + prop[rod2] = put(rod2, 116, 0); + prop[pillow] = put(pillow, 116, 0); + + prop[mirror] = put(mirror, 115, 0); + fixed[mirror] = 116; + + for (i = 1; i <= 100; i++) + if (toting(i)) + dstroy(i); rspeak(132); - closed=TRUE; + closed = TRUE; } diff --git a/games/adventure/vocab.c b/games/adventure/vocab.c index 66813f220f..4e3c05ca6b 100644 --- a/games/adventure/vocab.c +++ b/games/adventure/vocab.c @@ -15,11 +15,7 @@ * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. - * 4. Neither the name of the University nor the names of its contributors + * 3. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * @@ -40,7 +36,7 @@ * $DragonFly: src/games/adventure/vocab.c,v 1.4 2007/04/18 18:32:12 swildner Exp $ */ -/* Re-coding of advent in C: data structure routines */ +/* Re-coding of advent in C: data structure routines */ #include #include @@ -50,126 +46,137 @@ void dstroy(int object) -{ move(object,0); +{ + move(object, 0); } void juggle(int object) -{ int i,j; +{ + int i, j; - i=place[object]; - j=fixed[object]; - move(object,i); - move(object+100,j); + i = place[object]; + j = fixed[object]; + move(object, i); + move(object + 100, j); } - void move(int object, int where) -{ int from; +{ + int from; - if (object<=100) - from=place[object]; + if (object <= 100) + from = place[object]; else - from=fixed[object-100]; - if (from>0 && from<=300) carry(object,from); - drop(object,where); + from = fixed[object - 100]; + if (from > 0 && from <= 300) + carry(object, from); + drop(object, where); } - int put(int object, int where, int pval) -{ move(object,where); - return(-1-pval); +{ + move(object, where); + return (-1 - pval); } void carry(int object, int where) -{ int temp; +{ + int temp; - if (object<=100) - { if (place[object]== -1) return; + if (object <= 100) { + if (place[object] == -1) + return; place[object] = -1; holdng++; } - if (atloc[where]==object) - { atloc[where]=linkx[object]; + if (atloc[where] == object) { + atloc[where] = linkx[object]; return; } - for (temp=atloc[where]; linkx[temp]!=object; temp=linkx[temp]); - linkx[temp]=linkx[object]; + for (temp = atloc[where]; linkx[temp] != object; temp = linkx[temp]) + ; /* nothing */ + linkx[temp] = linkx[object]; } - void drop(int object, int where) -{ if (object>100) fixed[object-100]=where; - else - { if (place[object]== -1) holdng--; - place[object]=where; +{ + if (object > 100) + fixed[object - 100] = where; + else { + if (place[object] == -1) + holdng--; + place[object] = where; } - if (where<=0) return; - linkx[object]=atloc[where]; - atloc[where]=object; + if (where <= 0) + return; + linkx[object] = atloc[where]; + atloc[where] = object; } - -/* look up or store a word */ +/* look up or store a word */ /* type is -2 for store, -1 for user word, >=0 for canned lookup*/ -/* value is used for storing only */ +/* value is used for storing only */ int vocab(const char *word, int type, int value) -{ int adr; +{ + int adr; const char *s; char *t; int hash, i; struct hashtab *h; - for (hash=0,s=word,i=0; i<5 &&*s; i++) /* some kind of hash */ - hash += *s++; /* add all chars in the word */ - hash = (hash*3719)&077777; /* pulled that one out of a hat */ - hash %= HTSIZE; /* put it into range of table */ - - for(adr=hash;; adr++) /* look for entry in table */ - { if (adr==HTSIZE) adr=0; /* wrap around */ - h = &voc[adr]; /* point at the entry */ - switch(type) - { case -2: /* fill in entry */ - if (h->val) /* already got an entry? */ + for (hash = 0, s = word, i = 0; i < 5 && *s; i++) /* some kind of hash */ + hash += *s++; /* add all chars in the word */ + hash = (hash * 3719) & 077777; /* pulled that one out of a hat */ + hash %= HTSIZE; /* put it into range of table */ + + for (adr = hash;; adr++) { /* look for entry in table */ + if (adr == HTSIZE) /* wrap around */ + adr = 0; + h = &voc[adr]; /* point at the entry */ + switch (type) { + case -2: /* fill in entry */ + if (h->val) /* already got an entry? */ goto exitloop2; - h->val=value; - h->atab=malloc(strlen(word)+1); + h->val = value; + h->atab = malloc(strlen(word) + 1); if (h->atab == NULL) errx(1, "Out of memory!"); - for (s=word,t=h->atab; *s;) + for (s = word, t = h->atab; *s;) *t++ = *s++ ^ '='; - *t=0^'='; - /* encrypt slightly to thwart core reader */ - /* printf("Stored \"%s\" (%d ch) as entry %d\n", */ - /* word, strlen(word)+1, adr); */ - return(0); /* entry unused */ - case -1: /* looking up user word */ - if (h->val==0) return(-1); /* not found */ - for (s=word, t=h->atab;*t ^ '=';) + *t = 0 ^ '='; + /* encrypt slightly to thwart core reader */ + /* printf("Stored \"%s\" (%d ch) as entry %d\n", */ + /* word, strlen(word)+1, adr); */ + return (0); /* entry unused */ + case -1: /* looking up user word */ + if (h->val == 0) /* not found */ + return (-1); + for (s = word, t = h->atab; *t ^ '=';) if ((*s++ ^ '=') != *t++) goto exitloop2; - if ((*s ^ '=') != *t && s-word<5) goto exitloop2; - /* the word matched o.k. */ - return(h->val); - default: /* looking up known word */ - if (h->val==0) - { errx(1, "Unable to find %s in vocab", word); - } - for (s=word, t=h->atab;*t ^ '=';) - if ((*s++ ^ '=') != *t++) goto exitloop2; - /* the word matched o.k. */ - if (h->val/1000 != type) continue; - return(h->val%1000); + if ((*s ^ '=') != *t && s - word < 5) + goto exitloop2; + /* the word matched o.k. */ + return (h->val); + default: /* looking up known word */ + if (h->val == 0) + errx(1, "Unable to find %s in vocab", word); + for (s = word, t = h->atab; *t ^ '=';) + if ((*s++ ^ '=') != *t++) + goto exitloop2; + if (h->val / 1000 != type) /* the word matched o.k. */ + continue; + return (h->val % 1000); } - exitloop2: /* hashed entry does not match */ - if (adr+1==hash || (adr==HTSIZE && hash==0)) - { errx(1, "Hash table overflow"); - } +exitloop2: /* hashed entry does not match */ + if (adr + 1 == hash || (adr == HTSIZE && hash == 0)) + errx(1, "Hash table overflow"); } } diff --git a/games/adventure/wizard.c b/games/adventure/wizard.c index 7843992001..26ffa2f623 100644 --- a/games/adventure/wizard.c +++ b/games/adventure/wizard.c @@ -15,11 +15,7 @@ * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. - * 4. Neither the name of the University nor the names of its contributors + * 3. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * @@ -40,7 +36,7 @@ * $DragonFly: src/games/adventure/wizard.c,v 1.3 2007/04/18 18:32:12 swildner Exp $ */ -/* Re-coding of advent in C: privileged operations */ +/* Re-coding of advent in C: privileged operations */ #include #include @@ -50,80 +46,84 @@ #include #include "hdr.h" -static int wizard (void); +static int wizard(void); void datime(int *d, int *t) -{ struct tm *tptr; +{ + struct tm *tptr; time_t tvec; time(&tvec); - tptr=localtime(&tvec); + tptr = localtime(&tvec); /* day since 1977 */ *d = (tptr->tm_yday + 365 * (tptr->tm_year - 77) - + (tptr->tm_year - 77) / 4 - (tptr->tm_year - 1) / 100 - + (tptr->tm_year + 299) / 400); + + (tptr->tm_year - 77) / 4 - (tptr->tm_year - 1) / 100 + + (tptr->tm_year + 299) / 400); /* bug: this will overflow in the year 2066 AD (with 16 bit int) */ - /* it will be attributed to Wm the C's millenial celebration */ + /* it will be attributed to Wm the C's millenial celebration */ /* and minutes since midnite */ - *t=tptr->tm_hour*60+tptr->tm_min; + *t = tptr->tm_hour * 60 + tptr->tm_min; } - char magic[6]; void poof(void) { - strcpy(magic, DECR(d,w,a,r,f)); + strcpy(magic, DECR(d, w, a, r, f)); latncy = 45; } int Start(void) -{ int d,t,delay; +{ + int d, t, delay; - datime(&d,&t); - delay=(d-saved)*1440+(t-savet); /* good for about a month */ + datime(&d, &t); + delay = (d - saved) * 1440 + (t - savet); /* good for about a month */ - if (delay >= latncy) - { saved = -1; - return(FALSE); + if (delay >= latncy) { + saved = -1; + return (FALSE); } printf("This adventure was suspended a mere %d minute%s ago.", - delay, delay == 1? "" : "s"); - if (delay <= latncy/3) - { mspeak(2); + delay, delay == 1 ? "" : "s"); + if (delay <= latncy / 3) { + mspeak(2); exit(0); } mspeak(8); - if (!wizard()) - { mspeak(9); + if (!wizard()) { + mspeak(9); exit(0); } saved = -1; - return(FALSE); + return (FALSE); } -/* not as complex as advent/10 (for now) */ +/* not as complex as advent/10 (for now) */ static int wizard(void) { - char *word,*x; - if (!yesm(16,0,7)) return(FALSE); + char *word, *x; + + if (!yesm(16, 0, 7)) + return (FALSE); mspeak(17); - getin(&word,&x); - if (strncmp(word,magic,5)) - { mspeak(20); - return(FALSE); + getin(&word, &x); + if (strncmp(word, magic, 5)) { + mspeak(20); + return (FALSE); } mspeak(19); - return(TRUE); + return (TRUE); } void ciao(void) -{ char *c; +{ + char *c; char fname[80]; printf("What would you like to call the saved version?\n"); @@ -135,19 +135,19 @@ ciao(void) break; *c = ch; } - *c=0; - if (save(fname) != 0) return; /* Save failed */ + *c = 0; + if (save(fname) != 0) /* Save failed */ + return; printf("To resume, say \"adventure %s\".\n", fname); printf("\"With these rooms I might now have been familiarly acquainted.\"\n"); exit(0); } - int ran(int range) { int i; i = random() % range; - return(i); + return (i); } diff --git a/games/arithmetic/arithmetic.6 b/games/arithmetic/arithmetic.6 index b56a1379e8..b767cda4e3 100644 --- a/games/arithmetic/arithmetic.6 +++ b/games/arithmetic/arithmetic.6 @@ -12,11 +12,7 @@ .\" 2. Redistributions in binary form must reproduce the above copyright .\" notice, this list of conditions and the following disclaimer in the .\" documentation and/or other materials provided with the distribution. -.\" 3. All advertising materials mentioning features or use of this software -.\" must display the following acknowledgement: -.\" This product includes software developed by the University of -.\" California, Berkeley and its contributors. -.\" 4. Neither the name of the University nor the names of its contributors +.\" 3. Neither the name of the University nor the names of its contributors .\" may be used to endorse or promote products derived from this software .\" without specific prior written permission. .\" diff --git a/games/arithmetic/arithmetic.c b/games/arithmetic/arithmetic.c index 6974932b66..c42f41b17f 100644 --- a/games/arithmetic/arithmetic.c +++ b/games/arithmetic/arithmetic.c @@ -1,4 +1,4 @@ -/* +/*- * Copyright (c) 1989, 1993 * The Regents of the University of California. All rights reserved. * @@ -13,11 +13,7 @@ * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. - * 4. Neither the name of the University nor the names of its contributors + * 3. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * @@ -68,14 +64,22 @@ */ #include -#include #include +#include #include -#include #include +#include #include #include +int getrandom(int, int, int); +void intr(int); +int opnum(int); +void penalise(int, int, int); +int problem(void); +void showstats(void); +static void usage(void); + const char keylist[] = "+-x/"; const char defaultkeys[] = "+-"; const char *keys = defaultkeys; @@ -85,14 +89,6 @@ int nright, nwrong; time_t qtime; #define NQUESTS 20 -static void usage (void); -int getrandom (int, int, int); -void intr (int); -int opnum (int); -void penalise (int, int, int); -int problem (void); -void showstats (void); - /* * Select keys from +-x/ to be asked addition, subtraction, multiplication, * and division problems. More than one key may be given. The default is @@ -101,7 +97,7 @@ void showstats (void); * so far are printed. */ int -main(int argc, char **argv) +main(int argc, char *argv[]) { int ch, cnt; @@ -302,7 +298,7 @@ penalise(int value, int op, int operand) struct penalty *p; op = opnum(op); - if ((p = (struct penalty *)malloc((u_int)sizeof(*p))) == NULL) + if ((p = malloc(sizeof(*p))) == NULL) return; p->next = penlist[op][operand]; penlist[op][operand] = p; diff --git a/games/atc/atc.6 b/games/atc/atc.6 index 2679c34227..68c4203188 100644 --- a/games/atc/atc.6 +++ b/games/atc/atc.6 @@ -12,11 +12,7 @@ .\" 2. Redistributions in binary form must reproduce the above copyright .\" notice, this list of conditions and the following disclaimer in the .\" documentation and/or other materials provided with the distribution. -.\" 3. All advertising materials mentioning features or use of this software -.\" must display the following acknowledgement: -.\" This product includes software developed by the University of -.\" California, Berkeley and its contributors. -.\" 4. Neither the name of the University nor the names of its contributors +.\" 3. Neither the name of the University nor the names of its contributors .\" may be used to endorse or promote products derived from this software .\" without specific prior written permission. .\" diff --git a/games/atc/def.h b/games/atc/def.h index 99e3190182..c19816d69d 100644 --- a/games/atc/def.h +++ b/games/atc/def.h @@ -13,11 +13,7 @@ * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. - * 4. Neither the name of the University nor the names of its contributors + * 3. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * diff --git a/games/atc/extern.c b/games/atc/extern.c index abb3bb8973..944a635546 100644 --- a/games/atc/extern.c +++ b/games/atc/extern.c @@ -13,11 +13,7 @@ * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. - * 4. Neither the name of the University nor the names of its contributors + * 3. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * diff --git a/games/atc/extern.h b/games/atc/extern.h index dc368b3539..ce8d0dc4d6 100644 --- a/games/atc/extern.h +++ b/games/atc/extern.h @@ -13,11 +13,7 @@ * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. - * 4. Neither the name of the University nor the names of its contributors + * 3. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * diff --git a/games/atc/grammar.y b/games/atc/grammar.y index bae0478825..2ee9d0c268 100644 --- a/games/atc/grammar.y +++ b/games/atc/grammar.y @@ -13,11 +13,7 @@ * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. - * 4. Neither the name of the University nor the names of its contributors + * 3. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * @@ -81,7 +77,7 @@ int line = 1; %% file: bunch_of_defs { if (checkdefs() < 0) return (errors); } bunch_of_lines - { + { if (sp->num_exits + sp->num_airports < 2) yyerror("Need at least 2 airports and/or exits."); return (errors); @@ -132,7 +128,7 @@ hdef: else if ($3 < 3) return (yyerror("'height' is too small.")); else - sp->height = $3; + sp->height = $3; } ; @@ -144,7 +140,7 @@ wdef: else if ($3 < 3) return (yyerror("'width' is too small.")); else - sp->width = $3; + sp->width = $3; } ; @@ -178,12 +174,12 @@ Bpoint: { if (sp->num_beacons % REALLOC == 0) { if (sp->beacon == NULL) - sp->beacon = (BEACON *) malloc((sp->num_beacons - + REALLOC) * sizeof (BEACON)); + sp->beacon = malloc((sp->num_beacons + REALLOC) + * sizeof(BEACON)); else - sp->beacon = (BEACON *) realloc(sp->beacon, - (sp->num_beacons + REALLOC) * - sizeof (BEACON)); + sp->beacon = realloc(sp->beacon, + (sp->num_beacons + REALLOC) * + sizeof(BEACON)); if (sp->beacon == NULL) return (yyerror("No memory available.")); } @@ -208,12 +204,11 @@ Epoint: if (sp->num_exits % REALLOC == 0) { if (sp->exit == NULL) - sp->exit = (EXIT *) malloc((sp->num_exits + - REALLOC) * sizeof (EXIT)); + sp->exit = malloc((sp->num_exits + REALLOC) * + sizeof(EXIT)); else - sp->exit = (EXIT *) realloc(sp->exit, - (sp->num_exits + REALLOC) * - sizeof (EXIT)); + sp->exit = realloc(sp->exit, (sp->num_exits + + REALLOC) * sizeof(EXIT)); if (sp->exit == NULL) return (yyerror("No memory available.")); } @@ -241,11 +236,11 @@ Apoint: if (sp->num_airports % REALLOC == 0) { if (sp->airport == NULL) - sp->airport=(AIRPORT *)malloc((sp->num_airports - + REALLOC) * sizeof(AIRPORT)); + sp->airport = malloc((sp->num_airports + + REALLOC) * sizeof(AIRPORT)); else - sp->airport = (AIRPORT *) realloc(sp->airport, - (sp->num_airports + REALLOC) * + sp->airport = realloc(sp->airport, + (sp->num_airports + REALLOC) * sizeof(AIRPORT)); if (sp->airport == NULL) return (yyerror("No memory available.")); @@ -271,12 +266,11 @@ Lline: { if (sp->num_lines % REALLOC == 0) { if (sp->line == NULL) - sp->line = (LINE *) malloc((sp->num_lines + - REALLOC) * sizeof (LINE)); + sp->line = malloc((sp->num_lines + REALLOC) * + sizeof(LINE)); else - sp->line = (LINE *) realloc(sp->line, - (sp->num_lines + REALLOC) * - sizeof (LINE)); + sp->line = realloc(sp->line, (sp->num_lines + + REALLOC) * sizeof(LINE)); if (sp->line == NULL) return (yyerror("No memory available.")); } @@ -293,7 +287,7 @@ Lline: static void check_edge(int x, int y) { - if (!(x == 0) && !(x == sp->width - 1) && + if (!(x == 0) && !(x == sp->width - 1) && !(y == 0) && !(y == sp->height - 1)) yyerror("edge value not on edge."); } @@ -353,7 +347,7 @@ check_edir(int x, int y, int dir) y = 2; else if (y != 0) y = 1; - + switch (x * 10 + y) { case 00: if (dir != 3) bad++; break; case 01: if (dir < 1 || dir > 3) bad++; break; diff --git a/games/atc/graphics.c b/games/atc/graphics.c index dfd04efde8..5441c3a854 100644 --- a/games/atc/graphics.c +++ b/games/atc/graphics.c @@ -13,11 +13,7 @@ * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. - * 4. Neither the name of the University nor the names of its contributors + * 3. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * @@ -59,10 +55,9 @@ #define C_BEACON '*' #define C_CREDIT '*' -WINDOW *radar, *cleanradar, *credit, *input, *planes; - -static void draw_line(WINDOW *, int, int, int, int, const char *); +static void draw_line(WINDOW *, int, int, int, int, const char *); +WINDOW *radar, *cleanradar, *credit, *input, *planes; int getAChar(void) @@ -313,7 +308,6 @@ quit(void) wmove(input, y, x); wrefresh(input); fflush(stdout); - return; } void @@ -323,7 +317,7 @@ planewin(void) int warning = 0; wclear(planes); - wmove(planes, 0,0); + wmove(planes, 0, 0); wprintw(planes, "Time: %-4d Safe: %d", clck, safe_planes); wmove(planes, 2, 0); waddstr(planes, "pl dt comm"); diff --git a/games/atc/include.h b/games/atc/include.h index 2984ee1905..f84ccd83f8 100644 --- a/games/atc/include.h +++ b/games/atc/include.h @@ -13,11 +13,7 @@ * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. - * 4. Neither the name of the University nor the names of its contributors + * 3. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * diff --git a/games/atc/input.c b/games/atc/input.c index 18cd41944a..bf72f71af0 100644 --- a/games/atc/input.c +++ b/games/atc/input.c @@ -13,11 +13,7 @@ * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. - * 4. Neither the name of the University nor the names of its contributors + * 3. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * @@ -201,7 +197,6 @@ int level; int tval; int dest_type, dest_no, dir; - static int pop(void) { @@ -386,7 +381,7 @@ setplane(int c) } static const char * -turn(__unused int c) +turn(int c __unused) { if (p.altitude == 0) return ("Planes at airports may not change direction"); @@ -394,7 +389,7 @@ turn(__unused int c) } static const char * -circle(__unused int c) +circle(int c __unused) { if (p.altitude == 0) return ("Planes cannot circle on the ground"); @@ -403,7 +398,7 @@ circle(__unused int c) } static const char * -left(__unused int c) +left(int c __unused) { dir = D_LEFT; p.new_dir = p.dir - 1; @@ -413,7 +408,7 @@ left(__unused int c) } static const char * -right(__unused int c) +right(int c __unused) { dir = D_RIGHT; p.new_dir = p.dir + 1; @@ -423,7 +418,7 @@ right(__unused int c) } static const char * -Left(__unused int c) +Left(int c __unused) { p.new_dir = p.dir - 2; if (p.new_dir < 0) @@ -432,7 +427,7 @@ Left(__unused int c) } static const char * -Right(__unused int c) +Right(int c __unused) { p.new_dir = p.dir + 2; if (p.new_dir >= MAXDIR) @@ -486,35 +481,35 @@ delayb(int c) } static const char * -beacon(__unused int c) +beacon(int c __unused) { dest_type = T_BEACON; return (NULL); } static const char * -ex_it(__unused int c) +ex_it(int c __unused) { dest_type = T_EXIT; return (NULL); } static const char * -airport(__unused int c) +airport(int c __unused) { dest_type = T_AIRPORT; return (NULL); } static const char * -climb(__unused int c) +climb(int c __unused) { dir = D_UP; return (NULL); } static const char * -descend(__unused int c) +descend(int c __unused) { dir = D_DOWN; return (NULL); @@ -624,7 +619,7 @@ rel_dir(int c) } static const char * -mark(__unused int c) +mark(int c __unused) { if (p.altitude == 0) return ("Cannot mark planes on the ground"); @@ -635,7 +630,7 @@ mark(__unused int c) } static const char * -unmark(__unused int c) +unmark(int c __unused) { if (p.altitude == 0) return ("Cannot unmark planes on the ground"); @@ -646,7 +641,7 @@ unmark(__unused int c) } static const char * -ignore(__unused int c) +ignore(int c __unused) { if (p.altitude == 0) return ("Cannot ignore planes on the ground"); @@ -659,8 +654,9 @@ ignore(__unused int c) int dir_no(char ch) { - int dirno = dir; + int dirno; + dirno = dir; switch (ch) { case 'w': dirno = 0; break; case 'e': dirno = 1; break; diff --git a/games/atc/lex.l b/games/atc/lex.l index a307b9d38c..c4926230aa 100644 --- a/games/atc/lex.l +++ b/games/atc/lex.l @@ -14,11 +14,7 @@ * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. - * 4. Neither the name of the University nor the names of its contributors + * 3. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * diff --git a/games/atc/list.c b/games/atc/list.c index 514fbc785f..0ae2f72e3c 100644 --- a/games/atc/list.c +++ b/games/atc/list.c @@ -13,11 +13,7 @@ * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. - * 4. Neither the name of the University nor the names of its contributors + * 3. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * @@ -50,7 +46,7 @@ #include "include.h" -PLANE * +PLANE * newplane(void) { return ((PLANE *) calloc(1, sizeof (PLANE))); diff --git a/games/atc/log.c b/games/atc/log.c index 40848d0dd4..aed6d7ee11 100644 --- a/games/atc/log.c +++ b/games/atc/log.c @@ -13,11 +13,7 @@ * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. - * 4. Neither the name of the University nor the names of its contributors + * 3. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * @@ -68,7 +64,6 @@ compar(const void *va, const void *vb) a = (const SCORE *)va; b = (const SCORE *)vb; - if (b->planes == a->planes) return (b->time - a->time); else diff --git a/games/atc/main.c b/games/atc/main.c index 8ae48e38c2..dc867e6190 100644 --- a/games/atc/main.c +++ b/games/atc/main.c @@ -13,11 +13,7 @@ * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. - * 4. Neither the name of the University nor the names of its contributors + * 3. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * @@ -53,14 +49,13 @@ #include "pathnames.h" extern FILE *yyin; -static int read_file(const char *); -static const char *default_game(void); -static const char *okay_game(const char *); -static int list_games(void); - +static int read_file(const char *); +static const char *default_game(void); +static const char *okay_game(const char *); +static int list_games(void); int -main(__unused int ac, char **av) +main(int argc __unused, char *argv[]) { int seed = 0; int f_usage = 0, f_list = 0, f_showscore = 0; @@ -75,15 +70,15 @@ main(__unused int ac, char **av) start_time = time(0); - p_name = *av++; - while (*av) { + p_name = *argv++; + while (*argv) { #ifndef SAVEDASH - if (**av == '-') - ++*av; + if (**argv == '-') + ++*argv; else break; #endif - ptr = *av++; + ptr = *argv++; while (*ptr) { switch (*ptr) { case '?': @@ -101,14 +96,14 @@ main(__unused int ac, char **av) f_printpath++; break; case 'r': - srandom(atoi(*av)); + srandom(atoi(*argv)); seed = 1; - av++; + argv++; break; case 'f': case 'g': - file = *av; - av++; + file = *argv; + argv++; break; default: fprintf(stderr, "Unknown option '%c'\n", *ptr); @@ -162,8 +157,7 @@ main(__unused int ac, char **av) tcgetattr(fileno(stdin), &tty_start); bcopy(&tty_start, &tty_new, sizeof(tty_new)); - tty_new.c_lflag &= ~ICANON; - tty_new.c_lflag &= ~ECHO; + tty_new.c_lflag &= ~(ICANON|ECHO); tty_new.c_cc[VMIN] = 1; tty_new.c_cc[VTIME] = 0; tcsetattr(fileno(stdin), TCSANOW, &tty_new); diff --git a/games/atc/pathnames.h b/games/atc/pathnames.h index e2ee4f8c89..fd8b559cf4 100644 --- a/games/atc/pathnames.h +++ b/games/atc/pathnames.h @@ -10,11 +10,7 @@ * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. - * 4. Neither the name of the University nor the names of its contributors + * 3. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * diff --git a/games/atc/struct.h b/games/atc/struct.h index 6034557af2..cc43cd3166 100644 --- a/games/atc/struct.h +++ b/games/atc/struct.h @@ -13,11 +13,7 @@ * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. - * 4. Neither the name of the University nor the names of its contributors + * 3. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * diff --git a/games/atc/tunable.c b/games/atc/tunable.c index 85a31ae949..fbb2354b0d 100644 --- a/games/atc/tunable.c +++ b/games/atc/tunable.c @@ -13,11 +13,7 @@ * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. - * 4. Neither the name of the University nor the names of its contributors + * 3. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * diff --git a/games/atc/tunable.h b/games/atc/tunable.h index d2cb932304..32464f64fe 100644 --- a/games/atc/tunable.h +++ b/games/atc/tunable.h @@ -13,11 +13,7 @@ * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. - * 4. Neither the name of the University nor the names of its contributors + * 3. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * diff --git a/games/atc/update.c b/games/atc/update.c index 12d212a9e1..6ef0425fdc 100644 --- a/games/atc/update.c +++ b/games/atc/update.c @@ -13,11 +13,7 @@ * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. - * 4. Neither the name of the University nor the names of its contributors + * 3. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * diff --git a/games/backgammon/backgammon/backgammon.6 b/games/backgammon/backgammon/backgammon.6 index 0b6dd2dfec..c7616af692 100644 --- a/games/backgammon/backgammon/backgammon.6 +++ b/games/backgammon/backgammon/backgammon.6 @@ -9,11 +9,7 @@ .\" 2. Redistributions in binary form must reproduce the above copyright .\" notice, this list of conditions and the following disclaimer in the .\" documentation and/or other materials provided with the distribution. -.\" 3. All advertising materials mentioning features or use of this software -.\" must display the following acknowledgement: -.\" This product includes software developed by the University of -.\" California, Berkeley and its contributors. -.\" 4. Neither the name of the University nor the names of its contributors +.\" 3. Neither the name of the University nor the names of its contributors .\" may be used to endorse or promote products derived from this software .\" without specific prior written permission. .\" diff --git a/games/backgammon/backgammon/extra.c b/games/backgammon/backgammon/extra.c index a9a044ef5c..3a9f1d6041 100644 --- a/games/backgammon/backgammon/extra.c +++ b/games/backgammon/backgammon/extra.c @@ -1,4 +1,4 @@ -/* +/*- * Copyright (c) 1980, 1993 * The Regents of the University of California. All rights reserved. * @@ -10,11 +10,7 @@ * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. - * 4. Neither the name of the University nor the names of its contributors + * 3. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * @@ -52,54 +48,50 @@ static int eval(void); void dble(void) { - int resp; /* response to y/n */ + int resp; /* response to y/n */ - for (;;) { - writel (" doubles."); /* indicate double */ + for (;;) { + writel(" doubles."); /* indicate double */ - if (cturn == -pnum) { /* see if computer accepts */ - if (dblgood()) { /* guess not */ - writel (" Declined.\n"); + if (cturn == -pnum) { /* see if computer accepts */ + if (dblgood()) { /* guess not */ + writel(" Declined.\n"); nexturn(); - cturn *= -2; /* indicate loss */ + cturn *= -2; /* indicate loss */ return; - } else { /* computer accepts */ - writel (" Accepted.\n"); - gvalue *= 2; /* double game value */ + } else { /* computer accepts */ + writel(" Accepted.\n"); + gvalue *= 2; /* double game value */ dlast = cturn; if (tflag) gwrite(); return; } } - - /* ask if player accepts */ - writel (" Does "); - writel (cturn == 1? color[2]: color[3]); - writel (" accept?"); - - /* get response from yorn, - * a "2" means he said "p" - * for print board. */ - if ((resp = yorn ('R')) == 2) { - writel (" Reprint.\n"); + /* ask if player accepts */ + writel(" Does "); + writel(cturn == 1 ? color[2] : color[3]); + writel(" accept?"); + + /* get response from yorn, a "2" means he said "p" for print + * board. */ + if ((resp = yorn('R')) == 2) { + writel(" Reprint.\n"); buflush(); wrboard(); - writel (*Colorptr); + writel(*Colorptr); continue; } - - /* check response */ - if (resp) { - /* accepted */ + /* check response */ + if (resp) { + /* accepted */ gvalue *= 2; dlast = cturn; if (tflag) gwrite(); return; } - - nexturn (); /* declined */ + nexturn(); /* declined */ cturn *= -2; return; } @@ -119,43 +111,42 @@ dble(void) int dblgood(void) { - int n; /* accumulated judgment */ - int OFFC = *offptr; /* no. of computer's men off */ - int OFFO = *offopp; /* no. of player's men off */ + int n; /* accumulated judgment */ + int OFFC = *offptr; /* no. of computer's men off */ + int OFFO = *offopp; /* no. of player's men off */ #ifdef DEBUG - int i; + int i; if (trace == NULL) - trace = fopen ("bgtrace","w"); + trace = fopen("bgtrace", "w"); #endif - /* get real pip value */ - n = eval()*cturn; + /* get real pip value */ + n = eval() * cturn; #ifdef DEBUG - fputs ("\nDoubles:\nBoard: ",trace); + fputs("\nDoubles:\nBoard: ", trace); for (i = 0; i < 26; i++) - fprintf (trace," %d",board[i]); - fprintf (trace,"\n\tpip = %d, ",n); + fprintf(trace, " %d", board[i]); + fprintf(trace, "\n\tpip = %d, ", n); #endif - /* below adjusts pip value - * according to position - * judgments */ + /* below adjusts pip value according to position judgments */ - /* check men moving off - * board */ - if (OFFC > -15 || OFFO > -15) { - if (OFFC < 0 && OFFO < 0) { + /* check men moving off board */ + if (OFFC > -15 || OFFO > -15) { + if (OFFC < 0 && OFFO < 0) { OFFC += 15; OFFO += 15; - n +=((OFFC-OFFO)*7)/2; - } else if (OFFC < 0) { - OFFC += 15; - n -= OFFO*7/2; - } else if (OFFO < 0) { - OFFO += 15; - n += OFFC*7/2; - } + n += ((OFFC - OFFO) * 7) / 2; + } else + if (OFFC < 0) { + OFFC += 15; + n -= OFFO * 7 / 2; + } else + if (OFFO < 0) { + OFFO += 15; + n += OFFC * 7 / 2; + } if (OFFC < 8 && OFFO > 8) n -= 7; if (OFFC < 10 && OFFO > 10) @@ -168,91 +159,91 @@ dblgood(void) n += 7; if (OFFO < 12 && OFFC > 12) n += 7; - n += ((OFFC-OFFO)*7)/2; + n += ((OFFC - OFFO) * 7) / 2; } #ifdef DEBUG - fprintf (trace,"off = %d, ",n); + fprintf(trace, "off = %d, ", n); #endif - /* see if men are trapped */ + /* see if men are trapped */ n -= freemen(bar); n += freemen(home); - n += trapped(home,-cturn); - n -= trapped(bar,cturn); + n += trapped(home, -cturn); + n -= trapped(bar, cturn); #ifdef DEBUG - fprintf (trace,"free = %d\n",n); - fprintf (trace,"\tOFFC = %d, OFFO = %d\n",OFFC,OFFO); - fflush (trace); + fprintf(trace, "free = %d\n", n); + fprintf(trace, "\tOFFC = %d, OFFO = %d\n", OFFC, OFFO); + fflush(trace); #endif - /* double if 2-3 moves ahead */ - if (n > 10+rnum(7)) - return(1); + /* double if 2-3 moves ahead */ + if (n > 10 + rnum(7)) + return (1); return (0); } int freemen(int b) { - int i, inc, lim; + int i, inc, lim; - odds(0,0,0); + odds(0, 0, 0); if (board[b] == 0) return (0); - inc = (b == 0? 1: -1); - lim = (b == 0? 7: 18); - for (i = b+inc; i != lim; i += inc) - if (board[i]*inc < -1) - odds(abs(b-i),0,abs(board[b])); + inc = (b == 0 ? 1 : -1); + lim = (b == 0 ? 7 : 18); + for (i = b + inc; i != lim; i += inc) + if (board[i] * inc < -1) + odds(abs(b - i), 0, abs(board[b])); if (abs(board[b]) == 1) - return ((36-count())/5); - return (count()/5); + return ((36 - count()) / 5); + return (count() / 5); } int trapped(int n, int inc) { - int i, j, k; - int c, l, ct; + int i, j, k; + int c, l, ct; ct = 0; - l = n+7*inc; - for (i = n+inc; i != l; i += inc) { - odds (0,0,0); - c = abs(i-l); - if (board[i]*inc > 0) { + l = n + 7 * inc; + for (i = n + inc; i != l; i += inc) { + odds(0, 0, 0); + c = abs(i - l); + if (board[i] * inc > 0) { for (j = c; j < 13; j++) - if (board[i+inc*j]*inc < -1) { + if (board[i + inc * j] * inc < -1) { if (j < 7) - odds (j,0,1); + odds(j, 0, 1); for (k = 1; k < 7 && k < j; k++) - if (j-k < 7) - odds (k,j-k,1); + if (j - k < 7) + odds(k, j - k, 1); } - ct += abs(board[i])*(36-count()); + ct += abs(board[i]) * (36 - count()); } } - return (ct/5); + return (ct / 5); } static int eval(void) { - int i, j; + int i, j; for (j = i = 0; i < 26; i++) - j += (board[i] >= 0 ? i*board[i] : (25-i)*board[i]); + j += (board[i] >= 0 ? i * board[i] : (25 - i) * board[i]); if (off[1] >= 0) - j += 25*off[1]; + j += 25 * off[1]; else - j += 25*(off[1]+15); + j += 25 * (off[1] + 15); if (off[0] >= 0) - j -= 25*off[0]; + j -= 25 * off[0]; else - j -= 25*(off[0]+15); + j -= 25 * (off[0] + 15); return (j); } diff --git a/games/backgammon/backgammon/main.c b/games/backgammon/backgammon/main.c index 3ae7c540e0..c683a07af2 100644 --- a/games/backgammon/backgammon/main.c +++ b/games/backgammon/backgammon/main.c @@ -1,4 +1,4 @@ -/* +/*- * Copyright (c) 1980, 1993 * The Regents of the University of California. All rights reserved. * @@ -10,11 +10,7 @@ * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. - * 4. Neither the name of the University nor the names of its contributors + * 3. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * @@ -87,102 +83,94 @@ static char pbuf[10]; int main(int argc, char **argv) { - int i; /* non-descript index */ - int l; /* non-descript index */ - char c; /* non-descript character storage */ + int i, l; + char c; /* revoke privs */ setgid(getgid()); /* initialization */ - bflag = 2; /* default no board */ - acnt = 1; /* Nuber of args */ - signal (SIGINT,(sig_t)getout); /* trap interrupts */ - if (tcgetattr (0,&tty) == -1) /* get old tty mode */ - errexit ("backgammon(tcgetattr)"); + bflag = 2; /* default no board */ + acnt = 1; /* Number of args */ + signal(SIGINT, (sig_t)getout); /* trap interrupts */ + if (tcgetattr(0, &tty) == -1) /* get old tty mode */ + errexit("backgammon(tcgetattr)"); old = tty.c_lflag; - raw = ((noech = old & ~ECHO) & ~ICANON); /* set up modes */ - ospeed = cfgetospeed(&tty); /* for termlib */ - - /* get terminal - * capabilities, and - * decide if it can - * cursor address */ - tflag = getcaps (getenv ("TERM")); - /* use whole screen - * for text */ + raw = ((noech = old & ~ECHO) & ~ICANON); /* set up modes */ + ospeed = cfgetospeed(&tty); /* for termlib */ + + /* get terminal capabilities, and decide if it can cursor address */ + tflag = getcaps(getenv("TERM")); + /* use whole screen for text */ if (tflag) begscr = 0; srandomdev(); - getarg (argc, argv); + getarg(argc, argv); args[acnt] = NULL; - if (tflag) { /* clear screen */ - noech &= ~(ICRNL|OXTABS); - raw &= ~(ICRNL|OXTABS); + if (tflag) { /* clear screen */ + noech &= ~(ICRNL | OXTABS); + raw &= ~(ICRNL | OXTABS); clear(); } - fixtty (raw); /* go into raw mode */ - - /* check if restored - * game and save flag - * for later */ - if ((rfl = rflag) != 0) { - text (message); /* print message */ - text (contin); - wrboard(); /* print board */ - /* if new game, pretend - * to be a non-restored - * game */ + fixtty(raw); /* go into raw mode */ + + /* check if restored game and save flag for later */ + if ((rfl = rflag) != 0) { + text(message); /* print message */ + text(contin); + wrboard(); /* print board */ + /* if new game, pretend + * to be a non-restored game + */ if (cturn == 0) rflag = 0; - } else { - rscore = wscore = 0; /* zero score */ - text (message); /* update message + } else { + rscore = wscore = 0; /* zero score */ + text(message); /* update message * without pausing */ - if (aflag) { /* print rules */ - writel (rules); - if (yorn(0)) { - - fixtty (old); /* restore tty */ - args[0] = strdup ("teachgammon"); - execv (TEACH,args); + if (aflag) { /* print rules */ + writel(rules); + if (yorn(0)) { + fixtty(old); /* restore tty */ + args[0] = strdup("teachgammon"); + execv(TEACH, args); - tflag = 0; /* error! */ - writel (noteach); + tflag = 0; /* error! */ + writel(noteach); exit(1); - } else { /* if not rules, then - * instructions */ - writel (need); - if (yorn(0)) { /* print instructions */ + } else { /* if not rules, then + * instructions + */ + writel(need); + if (yorn(0)) { /* print instructions */ clear(); - text (instr); + text(instr); } } } for (i = 0; i < acnt; i++) - free (args[i]); + free(args[i]); - init(); /* initialize board */ + init(); /* initialize board */ - if (pnum == 2) { /* ask for color(s) */ - writec ('\n'); - writel (askcol); - while (pnum == 2) { + if (pnum == 2) { /* ask for color(s) */ + writec('\n'); + writel(askcol); + while (pnum == 2) { c = readc(); - switch (c) { - - case 'R': /* red */ + switch (c) { + case 'R': /* red */ pnum = -1; break; - case 'W': /* white */ + case 'W': /* white */ pnum = 1; break; - case 'B': /* both */ + case 'B': /* both */ pnum = 0; break; @@ -190,21 +178,21 @@ main(int argc, char **argv) if (iroll) break; if (tflag) - curmove (curr,0); + curmove(curr, 0); else - writec ('\n'); - writel ("Password:"); - signal (SIGALRM,(sig_t)getout); + writec('\n'); + writel("Password:"); + signal(SIGALRM, (sig_t)getout); cflag = 1; - alarm (10); - for (i = 0; i < 10; i++) { + alarm(10); + for (i = 0; i < 10; i++) { pbuf[i] = readc(); if (pbuf[i] == '\n') break; } if (i == 10) while (readc() != '\n'); - alarm (0); + alarm(0); cflag = 0; if (i < 10) pbuf[i] = '\0'; @@ -213,68 +201,62 @@ main(int argc, char **argv) getout(); iroll = 1; if (tflag) - curmove (curr,0); + curmove(curr, 0); else - writec ('\n'); - writel (askcol); + writec('\n'); + writel(askcol); break; - default: /* error */ - writec ('\007'); + default: /* error */ + writec('\007'); } } - } else if (!aflag) - /* pause to read - * message */ - text (contin); + } else + if (!aflag) + /* pause to read message */ + text(contin); - wrboard(); /* print board */ + wrboard(); /* print board */ if (tflag) - curmove (18,0); + curmove(18, 0); else - writec ('\n'); + writec('\n'); } - /* limit text to bottom - * of screen */ + /* limit text to bottom of screen */ if (tflag) begscr = 17; - for (;;) { /* begin game! */ - /* initial roll if - * needed */ - if ((! rflag) || raflag) + for (;;) { /* begin game! */ + /* initial roll if needed */ + if ((!rflag) || raflag) roll(); - /* perform ritual of - * first roll */ - if (! rflag) { + /* perform ritual of first roll */ + if (!rflag) { if (tflag) - curmove (17,0); - while (D0 == D1) /* no doubles */ + curmove(17, 0); + while (D0 == D1) /* no doubles */ roll(); - /* print rolls */ - writel (rollr); - writec (D0+'0'); - writel (rollw); - writec (D1+'0'); + /* print rolls */ + writel(rollr); + writec(D0 + '0'); + writel(rollw); + writec(D1 + '0'); - /* winner goes first */ - if (D0 > D1) { - writel (rstart); + /* winner goes first */ + if (D0 > D1) { + writel(rstart); cturn = 1; - } else { - writel (wstart); + } else { + writel(wstart); cturn = -1; } } - /* initalize variables - * according to whose - * turn it is */ - - if (cturn == 1) { /* red */ + /* initialize variables according to whose turn it is */ + if (cturn == 1) { /* red */ home = 25; bar = 0; inptr = &in[1]; @@ -284,7 +266,7 @@ main(int argc, char **argv) Colorptr = &color[1]; colorptr = &color[3]; colen = 3; - } else { /* white */ + } else { /* white */ home = 0; bar = 25; inptr = &in[0]; @@ -296,263 +278,241 @@ main(int argc, char **argv) colen = 5; } - /* do first move - * (special case) */ - if (! (rflag && raflag)) { - if (cturn == pnum) /* computer's move */ - move (0); - else { /* player's move */ + /* do first move (special case) */ + if (!(rflag && raflag)) { + if (cturn == pnum) /* computer's move */ + move(0); + else { /* player's move */ mvlim = movallow(); - /* reprint roll */ + /* reprint roll */ if (tflag) - curmove (cturn == -1? 18: 19,0); + curmove(cturn == -1 ? 18 : 19, 0); proll(); - getmove(); /* get player's move */ + getmove(); /* get player's move */ } } - if (tflag) { - curmove (17,0); + if (tflag) { + curmove(17, 0); cline(); begscr = 18; } - /* no longer any diff- - * erence between normal - * game and recovered - * game. */ + /* no longer any difference between normal and recovered game. */ rflag = 0; - /* move as long as it's - * someone's turn */ - while (cturn == 1 || cturn == -1) { - - /* board maintainence */ + /* move as long as it's someone's turn */ + while (cturn == 1 || cturn == -1) { + /* board maintenance */ if (tflag) - refresh(); /* fix board */ + refresh(); /* fix board */ else - /* redo board if -p */ + /* redo board if -p */ if (cturn == bflag || bflag == 0) wrboard(); - /* do computer's move */ - if (cturn == pnum) { - move (1); + /* do computer's move */ + if (cturn == pnum) { + move(1); - /* see if double - * refused */ + /* see if double refused */ if (cturn == -2 || cturn == 2) break; - /* check for winning - * move */ - if (*offopp == 15) { + /* check for winning move */ + if (*offopp == 15) { cturn *= -2; break; } continue; - } - /* (player's move) */ + /* (player's move) */ - /* clean screen if - * safe */ - if (tflag && hflag) { - curmove (20,0); - clend (); + /* clean screen if safe */ + if (tflag && hflag) { + curmove(20, 0); + clend(); hflag = 1; } - /* if allowed, give him - * a chance to double */ - if (dlast != cturn && gvalue < 64) { + /* if allowed, give him a chance to double */ + if (dlast != cturn && gvalue < 64) { if (tflag) - curmove (cturn == -1? 18: 19,0); - writel (*Colorptr); + curmove(cturn == -1 ? 18 : 19, 0); + writel(*Colorptr); c = readc(); - /* character cases */ - switch (c) { - - /* reprint board */ - case 'R': + /* character cases */ + switch (c) { + case 'R': /* reprint board */ wrboard(); break; - /* save game */ - case 'S': + case 'S': /* save game */ raflag = 1; - save (1); + save(1); break; - /* quit */ - case 'Q': + case 'Q': /* quit */ quit(); break; - /* double */ - case 'D': + case 'D': /* double */ dble(); break; - /* roll */ - case ' ': + case ' ': /* roll */ case '\n': roll(); - writel (" rolls "); - writec (D0+'0'); - writec (' '); - writec (D1+'0'); - writel (". "); - - /* see if he can move */ - if ( (mvlim = movallow()) == 0) { - - /* can't move */ - writel (toobad1); - writel (*colorptr); - writel (unable); - if (tflag) { - if (pnum) { + writel(" rolls "); + writec(D0 + '0'); + writec(' '); + writec(D1 + '0'); + writel(". "); + + /* see if he can move */ + if ((mvlim = movallow()) == 0) { + /* can't move */ + writel(toobad1); + writel(*colorptr); + writel(unable); + if (tflag) { + if (pnum) { buflush(); - sleep (MVPAUSE); + sleep(MVPAUSE); } } nexturn(); break; } - /* get move */ + /* get move */ getmove(); - /* okay to clean - * screen */ + /* okay to clean screen */ hflag = 1; break; - /* invalid character */ + /* invalid character */ default: - /* print help message */ + /* print help message */ if (tflag) - curmove (20,0); + curmove(20, 0); else - writec ('\n'); - text (helpm); + writec('\n'); + text(helpm); if (tflag) - curmove (cturn == -1? 18: 19,0); + curmove(cturn == -1 ? 18 : 19, + 0); else - writec ('\n'); + writec('\n'); - /* don't erase */ + /* don't erase */ hflag = 0; } - } else { /* couldn't double */ - - /* print roll */ + } else { /* couldn't double */ + /* print roll */ roll(); if (tflag) - curmove (cturn == -1? 18: 19,0); - proll (); - - /* can he move? */ - if ((mvlim = movallow()) == 0) { + curmove(cturn == -1 ? 18 : 19, 0); + proll(); - /* he can't */ - writel (toobad2); - writel (*colorptr); - writel (cantmv); + /* can he move? */ + if ((mvlim = movallow()) == 0) { + /* he can't */ + writel(toobad2); + writel(*colorptr); + writel(cantmv); buflush(); - sleep (MVPAUSE); + sleep(MVPAUSE); nexturn(); continue; } - /* get move */ + /* get move */ getmove(); } } - /* don't worry about who - * won if quit */ + /* don't worry about who won if quit */ if (cturn == 0) break; - /* fix cturn = winner */ + /* fix cturn = winner */ cturn /= -2; - /* final board pos. */ + /* final board pos. */ if (tflag) refresh(); - /* backgammon? */ + /* backgammon? */ mflag = 0; - l = bar+7*cturn; + l = bar + 7 * cturn; for (i = bar; i != l; i += cturn) - if (board[i]*cturn) mflag++; + if (board[i] * cturn) + mflag++; - /* compute game value */ + /* compute game value */ if (tflag) - curmove (20,0); - if (*offopp == 15) { - if (mflag) { - writel (bgammon); + curmove(20, 0); + if (*offopp == 15) { + if (mflag) { + writel(bgammon); gvalue *= 3; - } - else if (*offptr <= 0) { - writel (gammon); - gvalue *= 2; - } + } else + if (*offptr <= 0) { + writel(gammon); + gvalue *= 2; + } } - /* report situation */ - if (cturn == -1) { - writel ("Red wins "); + /* report situation */ + if (cturn == -1) { + writel("Red wins "); rscore += gvalue; } else { - writel ("White wins "); + writel("White wins "); wscore += gvalue; } - wrint (gvalue); - writel (" point"); + wrint(gvalue); + writel(" point"); if (gvalue > 1) - writec ('s'); - writel (".\n"); + writec('s'); + writel(".\n"); - /* write score */ + /* write score */ wrscore(); - /* see if he wants - * another game */ - writel (again); - if ((i = yorn ('S')) == 0) + /* see if he wants another game */ + writel(again); + if ((i = yorn('S')) == 0) break; init(); - if (i == 2) { - writel (" Save.\n"); + if (i == 2) { + writel(" Save.\n"); cturn = 0; - save (0); + save(0); } - /* yes, reset game */ + /* yes, reset game */ wrboard(); } /* give him a chance to save if game was recovered */ - if (rfl && cturn) { - writel (svpromt); - if (yorn (0)) { - /* re-initialize for - * recovery */ + if (rfl && cturn) { + writel(svpromt); + if (yorn(0)) { + /* re-initialize for recovery */ init(); cturn = 0; save(0); } } - /* leave peacefully */ - getout (); + /* leave peacefully */ + getout(); /* NOTREACHED */ - return(0); + return (0); } diff --git a/games/backgammon/backgammon/move.c b/games/backgammon/backgammon/move.c index 4b78be8217..f1202982ea 100644 --- a/games/backgammon/backgammon/move.c +++ b/games/backgammon/backgammon/move.c @@ -1,4 +1,4 @@ -/* +/*- * Copyright (c) 1980, 1993 * The Regents of the University of California. All rights reserved. * @@ -10,11 +10,7 @@ * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. - * 4. Neither the name of the University nor the names of its contributors + * 3. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * @@ -67,8 +63,7 @@ struct BOARD { /* structure of game position */ struct BOARD *freeq = 0; struct BOARD *checkq = 0; - /* these variables are values for the - * candidate move */ +/* these variables are values for the candidate move */ static int ch; /* chance of being hit */ static int op; /* computer's open men */ static int pt; /* comp's protected points */ @@ -76,8 +71,7 @@ static int em; /* farthest man back */ static int frc; /* chance to free comp's men */ static int frp; /* chance to free pl's men */ - /* these values are the values for the - * move chosen (so far) */ +/* these values are the values for the move chosen (so far) */ static int chance; /* chance of being hit */ static int openmen; /* computer's open men */ static int points; /* comp's protected points */ @@ -93,19 +87,20 @@ static int cg[5]; /* candidate finish position */ static int race; /* game reduced to a race */ +/* zero if first move */ void move(int okay) { - int i; /* index */ - int l = 0; /* last man */ - - /* first move? */ - if (okay) { - /* see if comp should double */ - if (gvalue < 64 && dlast != cturn && dblgood()) { - writel (*Colorptr); - dble(); /* double */ - /* return if declined */ + int i; /* index */ + int l; /* last man */ + + l = 0; + if (okay) { + /* see if comp should double */ + if (gvalue < 64 && dlast != cturn && dblgood()) { + writel(*Colorptr); + dble(); /* double */ + /* return if declined */ if (cturn != 1 && cturn != -1) return; } @@ -113,75 +108,74 @@ move(int okay) } race = 0; - for (i = 0; i < 26; i++) { + for (i = 0; i < 26; i++) { if (board[i] < 0) l = i; } - for (i = 0; i < l; i++) { + for (i = 0; i < l; i++) { if (board[i] > 0) break; } if (i == l) race = 1; - /* print roll */ + /* print roll */ if (tflag) - curmove (cturn == -1? 18: 19,0); - writel (*Colorptr); - writel (" rolls "); - writec (D0+'0'); - writec (' '); - writec (D1+'0'); - /* make tty interruptable - * while thinking */ + curmove(cturn == -1 ? 18 : 19, 0); + writel(*Colorptr); + writel(" rolls "); + writec(D0 + '0'); + writec(' '); + writec(D1 + '0'); + /* make tty interruptable while thinking */ if (tflag) cline(); - fixtty (noech); + fixtty(noech); - /* find out how many moves */ + /* find out how many moves */ mvlim = movallow(); - if (mvlim == 0) { - writel (" but cannot use it.\n"); + if (mvlim == 0) { + writel(" but cannot use it.\n"); nexturn(); - fixtty (raw); + fixtty(raw); return; } - /* initialize */ + /* initialize */ for (i = 0; i < 4; i++) cp[i] = cg[i] = 0; - /* strategize */ - trymove (0,0); + /* strategize */ + trymove(0, 0); pickmove(); - /* print move */ - writel (" and moves "); - for (i = 0; i < mvlim; i++) { + /* print move */ + writel(" and moves "); + for (i = 0; i < mvlim; i++) { if (i > 0) - writec (','); - wrint (p[i] = cp[i]); - writec ('-'); - wrint (g[i] = cg[i]); - makmove (i); + writec(','); + wrint(p[i] = cp[i]); + writec('-'); + wrint(g[i] = cg[i]); + makmove(i); } - writec ('.'); + writec('.'); - /* print blots hit */ + /* print blots hit */ if (tflag) - curmove (20,0); + curmove(20, 0); else - writec ('\n'); + writec('\n'); for (i = 0; i < mvlim; i++) if (h[i]) wrhit(g[i]); - /* get ready for next move */ + /* get ready for next move */ nexturn(); - if (!okay) { + if (!okay) { buflush(); - sleep (3); + sleep(3); } - fixtty (raw); /* no more tty interrupt */ + fixtty(raw); /* no more tty interrupt */ } /* @@ -191,72 +185,70 @@ move(int okay) static void trymove(int mvnum, int swapped) { - int pos; /* position on board */ - int rval; /* value of roll */ + int pos; /* position on board */ + int rval; /* value of roll */ - /* if recursed through all dice - * values, compare move */ - if (mvnum == mvlim) { - binsert (bsave()); + /* if recursed through all dice values, compare move */ + if (mvnum == mvlim) { + binsert(bsave()); return; } - /* make sure dice in always - * same order */ + /* make sure dice in always same order */ if (d0 == swapped) swap; - /* choose value for this move */ + /* choose value for this move */ rval = dice[mvnum != 0]; - /* find all legitimate moves */ - for (pos = bar; pos != home; pos += cturn) { - /* fix order of dice */ + /* find all legitimate moves */ + for (pos = bar; pos != home; pos += cturn) { + /* fix order of dice */ if (d0 == swapped) swap; - /* break if stuck on bar */ + /* break if stuck on bar */ if (board[bar] != 0 && pos != bar) break; - /* on to next if not occupied */ - if (board[pos]*cturn <= 0) + /* on to next if not occupied */ + if (board[pos] * cturn <= 0) continue; - /* set up arrays for move */ + /* set up arrays for move */ p[mvnum] = pos; - g[mvnum] = pos+rval*cturn; - if (g[mvnum]*cturn >= home) { + g[mvnum] = pos + rval * cturn; + if (g[mvnum] * cturn >= home) { if (*offptr < 0) break; g[mvnum] = home; } - /* try to move */ - if (makmove (mvnum)) + /* try to move */ + if (makmove(mvnum)) continue; else - trymove (mvnum+1,2); - /* undo move to try another */ - backone (mvnum); + trymove(mvnum + 1, 2); + /* undo move to try another */ + backone(mvnum); } - /* swap dice and try again */ + /* swap dice and try again */ if ((!swapped) && D0 != D1) - trymove (0,1); + trymove(0, 1); } static struct BOARD * bsave(void) { - int i; /* index */ - struct BOARD *now; /* current position */ + int i; /* index */ + struct BOARD *now; /* current position */ - now = nextfree (); /* get free BOARD */ + now = nextfree(); /* get free BOARD */ - /* store position */ + /* store position */ for (i = 0; i < 26; i++) now->b_board[i] = board[i]; now->b_in[0] = in[0]; now->b_in[1] = in[1]; now->b_off[0] = off[0]; now->b_off[1] = off[1]; - for (i = 0; i < mvlim; i++) { + for (i = 0; i < mvlim; i++) { now->b_st[i] = p[i]; now->b_fn[i] = g[i]; } @@ -266,42 +258,41 @@ bsave(void) static void binsert(struct BOARD *new) { - struct BOARD *qp = checkq; /* queue pointer */ - int result; /* comparison result */ + int result; /* comparison result */ + struct BOARD *qp; /* queue pointer */ - if (qp == 0) { /* check if queue empty */ + qp = checkq; + if (qp == 0) { /* check if queue empty */ checkq = qp = new; qp->b_next = 0; return; } - - result = bcomp (new,qp); /* compare to first element */ - if (result < 0) { /* insert in front */ + result = bcomp(new, qp); /* compare to first element */ + if (result < 0) { /* insert in front */ new->b_next = qp; checkq = new; return; } - if (result == 0) { /* duplicate entry */ - mvcheck (qp,new); - makefree (new); + if (result == 0) { /* duplicate entry */ + mvcheck(qp, new); + makefree(new); return; } - - while (qp->b_next != 0) { /* traverse queue */ - result = bcomp (new,qp->b_next); - if (result < 0) { /* found place */ + while (qp->b_next != 0) { /* traverse queue */ + result = bcomp(new, qp->b_next); + if (result < 0) { /* found place */ new->b_next = qp->b_next; qp->b_next = new; return; } - if (result == 0) { /* duplicate entry */ - mvcheck (qp->b_next,new); - makefree (new); + if (result == 0) { /* duplicate entry */ + mvcheck(qp->b_next, new); + makefree(new); return; } qp = qp->b_next; } - /* place at end of queue */ + /* place at end of queue */ qp->b_next = new; new->b_next = 0; } @@ -309,27 +300,27 @@ binsert(struct BOARD *new) static int bcomp(struct BOARD *a, struct BOARD *b) { - int *aloc = a->b_board; /* pointer to board a */ - int *bloc = b->b_board; /* pointer to board b */ - int i; /* index */ - int result; /* comparison result */ + int *aloc = a->b_board; /* pointer to board a */ + int *bloc = b->b_board; /* pointer to board b */ + int i; /* index */ + int result; /* comparison result */ - for (i = 0; i < 26; i++) { /* compare boards */ - result = cturn*(aloc[i]-bloc[i]); + for (i = 0; i < 26; i++) { /* compare boards */ + result = cturn * (aloc[i] - bloc[i]); if (result) - return (result); /* found inequality */ + return (result); /* found inequality */ } - return (0); /* same position */ + return (0); /* same position */ } static void mvcheck(struct BOARD *incumbent, struct BOARD *candidate) { - int i; - int result; + int i; + int result; - for (i = 0; i < mvlim; i++) { - result = cturn*(candidate->b_st[i]-incumbent->b_st[i]); + for (i = 0; i < mvlim; i++) { + result = cturn * (candidate->b_st[i] - incumbent->b_st[i]); if (result > 0) return; if (result < 0) @@ -337,7 +328,7 @@ mvcheck(struct BOARD *incumbent, struct BOARD *candidate) } if (i == mvlim) return; - for (i = 0; i < mvlim; i++) { + for (i = 0; i < mvlim; i++) { incumbent->b_st[i] = candidate->b_st[i]; incumbent->b_fn[i] = candidate->b_fn[i]; } @@ -346,19 +337,19 @@ mvcheck(struct BOARD *incumbent, struct BOARD *candidate) static void makefree(struct BOARD *dead) { - dead->b_next = freeq; /* add to freeq */ + dead->b_next = freeq; /* add to freeq */ freeq = dead; } static struct BOARD * nextfree(void) { - struct BOARD *new; + struct BOARD *new; - if (freeq == 0) { - new = (struct BOARD *)calloc (1,sizeof (struct BOARD)); - if (new == 0) { - writel ("\nOut of memory\n"); + if (freeq == 0) { + new = calloc(1, sizeof(struct BOARD)); + if (new == 0) { + writel("\nOut of memory\n"); getout(); } new->b_next = 0; @@ -372,39 +363,39 @@ nextfree(void) static void pickmove(void) { - /* current game position */ - struct BOARD *now = bsave(); - struct BOARD *next; /* next move */ + /* current game position */ + struct BOARD *now = bsave(); + struct BOARD *next; /* next move */ #ifdef DEBUG if (trace == NULL) - trace = fopen ("bgtrace","w"); - fprintf (trace,"\nRoll: %d %d%s\n",D0,D1,race? " (race)": ""); - fflush (trace); + trace = fopen("bgtrace", "w"); + fprintf(trace, "\nRoll: %d %d%s\n", D0, D1, race ? " (race)" : ""); + fflush(trace); #endif - do { /* compare moves */ - boardcopy (checkq); + do { /* compare moves */ + boardcopy(checkq); next = checkq->b_next; - makefree (checkq); + makefree(checkq); checkq = next; movcmp(); } while (checkq != 0); - boardcopy (now); + boardcopy(now); } static void boardcopy(struct BOARD *s) { - int i; /* index */ + int i; /* index */ for (i = 0; i < 26; i++) board[i] = s->b_board[i]; - for (i = 0; i < 2; i++) { + for (i = 0; i < 2; i++) { in[i] = s->b_in[i]; off[i] = s->b_off[i]; } - for (i = 0; i < mvlim; i++) { + for (i = 0; i < mvlim; i++) { p[i] = s->b_st[i]; g[i] = s->b_fn[i]; } @@ -413,58 +404,58 @@ boardcopy(struct BOARD *s) static void movcmp(void) { - int i; + int i; #ifdef DEBUG if (trace == NULL) - trace = fopen ("bgtrace","w"); + trace = fopen("bgtrace", "w"); #endif - odds (0,0,0); - if (!race) { + odds(0, 0, 0); + if (!race) { ch = op = pt = 0; - for (i = 1; i < 25; i++) { + for (i = 1; i < 25; i++) { if (board[i] == cturn) - ch = canhit (i,1); - op += abs (bar-i); + ch = canhit(i, 1); + op += abs(bar - i); } - for (i = bar+cturn; i != home; i += cturn) - if (board[i]*cturn > 1) - pt += abs(bar-i); - frc = freemen (bar)+trapped (bar,cturn); - frp = freemen (home)+trapped (home,-cturn); + for (i = bar + cturn; i != home; i += cturn) + if (board[i] * cturn > 1) + pt += abs(bar - i); + frc = freemen(bar) + trapped(bar, cturn); + frp = freemen(home) + trapped(home, -cturn); } for (em = bar; em != home; em += cturn) - if (board[em]*cturn > 0) + if (board[em] * cturn > 0) break; - em = abs(home-em); + em = abs(home - em); #ifdef DEBUG - fputs ("Board: ",trace); + fputs("Board: ", trace); for (i = 0; i < 26; i++) - fprintf (trace, " %d",board[i]); + fprintf(trace, " %d", board[i]); if (race) - fprintf (trace,"\n\tem = %d\n",em); + fprintf(trace, "\n\tem = %d\n", em); else - fprintf (trace, - "\n\tch = %d, pt = %d, em = %d, frc = %d, frp = %d\n", - ch,pt,em,frc,frp); - fputs ("\tMove: ",trace); + fprintf(trace, + "\n\tch = %d, pt = %d, em = %d, frc = %d, frp = %d\n", + ch, pt, em, frc, frp); + fputs("\tMove: ", trace); for (i = 0; i < mvlim; i++) - fprintf (trace," %d-%d",p[i],g[i]); - fputs ("\n",trace); - fflush (trace); - strcpy (tests,""); + fprintf(trace, " %d-%d", p[i], g[i]); + fputs("\n", trace); + fflush(trace); + strcpy(tests, ""); #endif - if ((cp[0] == 0 && cg[0] == 0) || movegood()) { + if ((cp[0] == 0 && cg[0] == 0) || movegood()) { #ifdef DEBUG - fprintf (trace,"\t[%s] ... wins.\n",tests); - fflush (trace); + fprintf(trace, "\t[%s] ... wins.\n", tests); + fflush(trace); #endif - for (i = 0; i < mvlim; i++) { + for (i = 0; i < mvlim; i++) { cp[i] = p[i]; cg[i] = g[i]; } - if (!race) { + if (!race) { chance = ch; openmen = op; points = pt; @@ -477,9 +468,9 @@ movcmp(void) menoff = *offptr; } #ifdef DEBUG - else { - fprintf (trace,"\t[%s] ... loses.\n",tests); - fflush (trace); + else { + fprintf(trace, "\t[%s] ... loses.\n", tests); + fflush(trace); } #endif } @@ -487,82 +478,82 @@ movcmp(void) static int movegood(void) { - int n; + int n; if (*offptr == 15) return (1); if (menoff == 15) return (0); - if (race) { + if (race) { #ifdef DEBUG - strcat (tests,"o"); + strcat(tests, "o"); #endif - if (*offptr-menoff) + if (*offptr - menoff) return (*offptr > menoff); #ifdef DEBUG - strcat (tests,"e"); + strcat(tests, "e"); #endif - if (endman-em) + if (endman - em) return (endman > em); #ifdef DEBUG - strcat (tests,"i"); + strcat(tests, "i"); #endif if (menin == 15) return (0); if (*inptr == 15) return (1); #ifdef DEBUG - strcat (tests,"i"); + strcat(tests, "i"); #endif - if (*inptr-menin) + if (*inptr - menin) return (*inptr > menin); return (rnum(2)); - } else { - n = barmen-abs(board[home]); + } else { + n = barmen - abs(board[home]); #ifdef DEBUG - strcat (tests,"c"); + strcat(tests, "c"); #endif - if (abs(chance-ch)+25*n > rnum(150)) - return (n? (n < 0): (ch < chance)); + if (abs(chance - ch) + 25 * n > rnum(150)) + return (n ? (n < 0) : (ch < chance)); #ifdef DEBUG - strcat (tests,"o"); + strcat(tests, "o"); #endif - if (*offptr-menoff) + if (*offptr - menoff) return (*offptr > menoff); #ifdef DEBUG - strcat (tests,"o"); + strcat(tests, "o"); #endif - if (abs(openmen-op) > 7+rnum(12)) + if (abs(openmen - op) > 7 + rnum(12)) return (openmen > op); #ifdef DEBUG - strcat (tests,"b"); + strcat(tests, "b"); #endif if (n) return (n < 0); #ifdef DEBUG - strcat (tests,"e"); + strcat(tests, "e"); #endif - if (abs(endman-em) > rnum(2)) + if (abs(endman - em) > rnum(2)) return (endman > em); #ifdef DEBUG - strcat (tests,"f"); + strcat(tests, "f"); #endif - if (abs(frc-oldfrc) > rnum(2)) + if (abs(frc - oldfrc) > rnum(2)) return (frc < oldfrc); #ifdef DEBUG - strcat (tests,"p"); + strcat(tests, "p"); #endif - if (abs(n = pt-points) > rnum(4)) + if (abs(n = pt - points) > rnum(4)) return (n > 0); #ifdef DEBUG - strcat (tests,"i"); + strcat(tests, "i"); #endif - if (*inptr-menin) + if (*inptr - menin) return (*inptr > menin); #ifdef DEBUG - strcat (tests,"f"); + strcat(tests, "f"); #endif - if (abs(frp-oldfrp) > rnum(2)) + if (abs(frp - oldfrp) > rnum(2)) return (frp > oldfrp); return (rnum(2)); } diff --git a/games/backgammon/backgammon/text.c b/games/backgammon/backgammon/text.c index 0a7d750256..27387b1ec2 100644 --- a/games/backgammon/backgammon/text.c +++ b/games/backgammon/backgammon/text.c @@ -1,4 +1,4 @@ -/* +/*- * Copyright (c) 1980, 1993 * The Regents of the University of California. All rights reserved. * @@ -10,11 +10,7 @@ * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. - * 4. Neither the name of the University nor the names of its contributors + * 3. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * @@ -106,25 +102,25 @@ const char *const instr[] = { void text(const char *const *t) { - int i; - const char *s, *a; + int i; + const char *s, *a; - fixtty (noech); - while (*t != 0) { + fixtty(noech); + while (*t != 0) { s = a = *t; for (i = 0; *a != '\0'; i--) a++; - if (i) { - writel (s); - writec ('\n'); - } else { - writel ("-->"); - fixtty (raw); + if (i) { + writel(s); + writec('\n'); + } else { + writel("-->"); + fixtty(raw); while ((i = readc()) != ' ' && i != '\n'); - fixtty (noech); + fixtty(noech); clear(); } t++; } - fixtty (raw); + fixtty(raw); } diff --git a/games/backgammon/backgammon/version.c b/games/backgammon/backgammon/version.c index a67837d760..ac0bc28b56 100644 --- a/games/backgammon/backgammon/version.c +++ b/games/backgammon/backgammon/version.c @@ -1,4 +1,4 @@ -/* +/*- * Copyright (c) 1980, 1987, 1993 * The Regents of the University of California. All rights reserved. * @@ -10,11 +10,7 @@ * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. - * 4. Neither the name of the University nor the names of its contributors + * 3. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * diff --git a/games/backgammon/common_source/allow.c b/games/backgammon/common_source/allow.c index ca89404c9a..cad5d06fe9 100644 --- a/games/backgammon/common_source/allow.c +++ b/games/backgammon/common_source/allow.c @@ -1,4 +1,4 @@ -/* +/*- * Copyright (c) 1980, 1993 * The Regents of the University of California. All rights reserved. * @@ -10,11 +10,7 @@ * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. - * 4. Neither the name of the University nor the names of its contributors + * 3. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * @@ -40,30 +36,29 @@ int movallow(void) { - - int i, m, iold; - int r; + int i, m, iold; + int r; if (d0) swap; - m = (D0 == D1? 4: 2); + m = (D0 == D1 ? 4 : 2); for (i = 0; i < 4; i++) p[i] = bar; i = iold = 0; - while (i < m) { + while (i < m) { if (*offptr == 15) break; h[i] = 0; - if (board[bar]) { + if (board[bar]) { if (i == 1 || m == 4) - g[i] = bar+cturn*D1; + g[i] = bar + cturn * D1; else - g[i] = bar+cturn*D0; - if ((r = makmove(i)) != 0) { + g[i] = bar + cturn * D0; + if ((r = makmove(i)) != 0) { if (d0 || m == 4) break; swap; - movback (i); + movback(i); if (i > iold) iold = i; for (i = 0; i < 4; i++) @@ -73,10 +68,10 @@ movallow(void) i++; continue; } - if ((p[i] += cturn) == home) { + if ((p[i] += cturn) == home) { if (i > iold) iold = i; - if (m == 2 && i) { + if (m == 2 && i) { movback(i); p[i--] = bar; if (p[i] != bar) @@ -87,25 +82,25 @@ movallow(void) if (d0 || m == 4) break; swap; - movback (i); + movback(i); for (i = 0; i < 4; i++) p[i] = bar; i = 0; continue; } if (i == 1 || m == 4) - g[i] = p[i]+cturn*D1; + g[i] = p[i] + cturn * D1; else - g[i] = p[i]+cturn*D0; - if (g[i]*cturn > home) { + g[i] = p[i] + cturn * D0; + if (g[i] * cturn > home) { if (*offptr >= 0) g[i] = home; else continue; } - if (board[p[i]]*cturn > 0 && (r = makmove(i)) == 0) + if (board[p[i]] * cturn > 0 && (r = makmove(i)) == 0) i++; } - movback (i); - return (iold > i? iold: i); + movback(i); + return (iold > i ? iold : i); } diff --git a/games/backgammon/common_source/back.h b/games/backgammon/common_source/back.h index 4469531965..33a03c6315 100644 --- a/games/backgammon/common_source/back.h +++ b/games/backgammon/common_source/back.h @@ -1,4 +1,4 @@ -/* +/*- * Copyright (c) 1980, 1993 * The Regents of the University of California. All rights reserved. * @@ -10,11 +10,7 @@ * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. - * 4. Neither the name of the University nor the names of its contributors + * 3. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * @@ -51,7 +47,7 @@ * Numeric values which are one color or the other use * -1 for white, 1 for red. * Hence, white will be negative values, red positive one. - * This makes a lot of sense since white is going in decending + * This makes a lot of sense since white is going in descending * order around the board, and red is ascending. * */ @@ -127,66 +123,55 @@ extern int curc; /* column position of cursor */ extern int begscr; /* 'beginning' of screen (not including board) */ -int movallow(void); - -void wrboard(void); - -void getmove(void); -int movokay(int); - -void fboard(void); -void refresh(void); -void curmove(int, int); -void newpos(void); +int addbuf(int); +void backone(int); +void buflush(void); +int canhit(int, int); +int checkmove(int); void clear(void); -void fancyc(char); void clend(void); void cline(void); -int getcaps(const char *); - -void odds(int, int, int); int count(void); -int canhit(int, int); - +void curmove(int, int); +void dble(void); +int dblgood(void); +void errexit(const char *); +void fancyc(char); +void fboard(void); +void fixtty(int); +int freemen(int); +void getarg(int, char **); +int getcaps(const char *); +void getmove(void); +void getout(void); /* function to exit backgammon cleanly */ +void gwrite(void); +void init(void); int makmove(int); -void moverr(int); +int movallow(void); void movback(int); -void backone(int); - -void save(int); -void recover(const char *); - -void errexit(const char *); -int addbuf(int); -void buflush(void); -char readc(void); -void writec(char); -void writel(const char *); +void move(int); +void moverr(int); +int movokay(int); +void newpos(void); +void nexturn(void); +void odds(int, int, int); void proll(void); -void wrint(int); -void gwrite(void); int quit(void); -int yorn(char); -void wrhit(int); -void nexturn(void); -void getarg(int, char **); -void init(void); -void wrscore(void); -void fixtty(int); -void getout(void); /* function to exit backgammon cleanly */ +char readc(void); +void recover(const char *); +void refresh(void); void roll(void); - -int checkmove(int); - -void dble(void); -int dblgood(void); -int freemen(int); -int trapped(int, int); - -void move(int); - +void save(int); #ifdef TEACHGAMMON_TEXT int text(const char *const *); #else void text(const char *const *); #endif +int trapped(int, int); +void wrboard(void); +void wrhit(int); +void wrint(int); +void writec(char); +void writel(const char *); +void wrscore(void); +int yorn(char); diff --git a/games/backgammon/common_source/board.c b/games/backgammon/common_source/board.c index ef71c59400..8302620d43 100644 --- a/games/backgammon/common_source/board.c +++ b/games/backgammon/common_source/board.c @@ -1,4 +1,4 @@ -/* +/*- * Copyright (c) 1980, 1993 * The Regents of the University of California. All rights reserved. * @@ -10,11 +10,7 @@ * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. - * 4. Neither the name of the University nor the names of its contributors + * 3. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * @@ -46,117 +42,116 @@ static char ln[60]; void wrboard(void) { - int l; - static const char bl[] = + int l; + static const char bl[] = "| | | |\n"; - static const char sv[] = + static const char sv[] = "| | | | \n"; - fixtty (noech); + fixtty(noech); clear(); - if (tflag) { + if (tflag) { fboard(); goto lastline; } - - writel ("_____________________________________________________\n"); - writel (bl); - strcpy (ln,bl); + writel("_____________________________________________________\n"); + writel(bl); + strcpy(ln, bl); for (j = 1; j < 50; j += 4) { - k = j/4+(j > 24? 12: 13); - ln[j+1] = k%10+'0'; - ln[j] = k/10+'0'; + k = j / 4 + (j > 24 ? 12 : 13); + ln[j + 1] = k % 10 + '0'; + ln[j] = k / 10 + '0'; if (j == 21) j += 4; } - writel (ln); + writel(ln); for (i = 0; i < 5; i++) { - strcpy (ln,sv); + strcpy(ln, sv); for (j = 1; j < 50; j += 4) { - k = j/4+(j > 24? 12: 13); - wrbsub (); + k = j / 4 + (j > 24 ? 12 : 13); + wrbsub(); if (j == 21) j += 4; } if (-board[25] > i) ln[26] = 'w'; - if (-board[25] > i+5) + if (-board[25] > i + 5) ln[25] = 'w'; - if (-board[25] > i+10) + if (-board[25] > i + 10) ln[27] = 'w'; l = 53; - if (off[1] > i || (off[1] < 0 && off[1]+15 > i)) { + if (off[1] > i || (off[1] < 0 && off[1] + 15 > i)) { ln[54] = 'r'; l = 55; } - if (off[1] > i+5 || (off[1] < 0 && off[1]+15 > i+5)) { + if (off[1] > i + 5 || (off[1] < 0 && off[1] + 15 > i + 5)) { ln[55] = 'r'; l = 56; } - if (off[1] > i+10 || (off[1] < 0 && off[1]+15 > i+10)) { + if (off[1] > i + 10 || (off[1] < 0 && off[1] + 15 > i + 10)) { ln[56] = 'r'; l = 57; } ln[l++] = '\n'; ln[l] = '\0'; - writel (ln); + writel(ln); } - strcpy (ln,bl); + strcpy(ln, bl); ln[25] = 'B'; ln[26] = 'A'; ln[27] = 'R'; - writel (ln); - strcpy (ln,sv); + writel(ln); + strcpy(ln, sv); for (i = 4; i > -1; i--) { for (j = 1; j < 50; j += 4) { - k = ((j > 24? 53: 49)-j)/4; + k = ((j > 24 ? 53 : 49) - j) / 4; wrbsub(); if (j == 21) j += 4; } if (board[0] > i) ln[26] = 'r'; - if (board[0] > i+5) + if (board[0] > i + 5) ln[25] = 'r'; - if (board[0] > i+10) + if (board[0] > i + 10) ln[27] = 'r'; l = 53; - if (off[0] > i || (off[0] < 0 && off[0]+15 > i)) { + if (off[0] > i || (off[0] < 0 && off[0] + 15 > i)) { ln[54] = 'w'; l = 55; } - if (off[0] > i+5 || (off[0] < 0 && off[0]+15 > i+5)) { + if (off[0] > i + 5 || (off[0] < 0 && off[0] + 15 > i + 5)) { ln[55] = 'w'; l = 56; } - if (off[0] > i+10 || (off[0] < 0 && off[0]+15 > i+10)) { + if (off[0] > i + 10 || (off[0] < 0 && off[0] + 15 > i + 10)) { ln[56] = 'w'; l = 57; } ln[l++] = '\n'; ln[l] = '\0'; - writel (ln); + writel(ln); } - strcpy (ln,bl); + strcpy(ln, bl); for (j = 1; j < 50; j += 4) { - k = ((j > 24? 53: 49)-j)/4; - ln[j+1] = k%10+'0'; + k = ((j > 24 ? 53 : 49) - j) / 4; + ln[j + 1] = k % 10 + '0'; if (k > 9) - ln[j] = k/10+'0'; + ln[j] = k / 10 + '0'; if (j == 21) j += 4; } - writel (ln); - writel ("|_______________________|___|_______________________|\n"); + writel(ln); + writel("|_______________________|___|_______________________|\n"); lastline: - gwrite (); + gwrite(); if (tflag) - curmove (18,0); - else { - writec ('\n'); - writec ('\n'); + curmove(18, 0); + else { + writec('\n'); + writec('\n'); } fixtty(raw); } @@ -164,20 +159,20 @@ lastline: static void wrbsub(void) { - int m; - char d; + int m; + char d; - if (board[k] > 0) { + if (board[k] > 0) { m = board[k]; d = 'r'; } else { m = -board[k]; d = 'w'; } - if (m>i) - ln[j+1] = d; - if (m>i+5) + if (m > i) + ln[j + 1] = d; + if (m > i + 5) ln[j] = d; - if (m>i+10) - ln[j+2] = d; + if (m > i + 10) + ln[j + 2] = d; } diff --git a/games/backgammon/common_source/check.c b/games/backgammon/common_source/check.c index f75a040ba0..1f8d14ec8f 100644 --- a/games/backgammon/common_source/check.c +++ b/games/backgammon/common_source/check.c @@ -1,4 +1,4 @@ -/* +/*- * Copyright (c) 1980, 1993 * The Regents of the University of California. All rights reserved. * @@ -10,11 +10,7 @@ * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. - * 4. Neither the name of the University nor the names of its contributors + * 3. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * @@ -40,19 +36,19 @@ void getmove(void) { - int i, c; + int i, c; c = 0; - for (;;) { + for (;;) { i = checkmove(c); - switch (i) { + switch (i) { case -1: - if (movokay(mvlim)) { + if (movokay(mvlim)) { if (tflag) - curmove (20,0); + curmove(20, 0); else - writec ('\n'); + writec('\n'); for (i = 0; i < mvlim; i++) if (h[i]) wrhit(g[i]); @@ -63,7 +59,6 @@ getmove(void) bflag = pnum; return; } - case -4: case 0: if (tflag) @@ -71,20 +66,20 @@ getmove(void) if (i != 0 && i != -4) break; if (tflag) - curmove (20,0); + curmove(20, 0); else - writec ('\n'); - writel (*Colorptr); + writec('\n'); + writel(*Colorptr); if (i == -4) - writel (" must make "); + writel(" must make "); else - writel (" can only make "); - writec (mvlim+'0'); - writel (" move"); + writel(" can only make "); + writec(mvlim + '0'); + writel(" move"); if (mvlim > 1) - writec ('s'); - writec ('.'); - writec ('\n'); + writec('s'); + writec('.'); + writec('\n'); break; case -3: @@ -92,11 +87,11 @@ getmove(void) return; } - if (! tflag) - proll (); - else { - curmove (cturn == -1? 18: 19,39); - cline (); + if (!tflag) + proll(); + else { + curmove(cturn == -1 ? 18 : 19, 39); + cline(); c = -1; } } @@ -105,52 +100,47 @@ getmove(void) int movokay(int mv) { - int i, m; + int i, m; if (d0) swap; - for (i = 0; i < mv; i++) { - - if (p[i] == g[i]) { - moverr (i); - curmove (20,0); - writel ("Attempt to move to same location.\n"); + for (i = 0; i < mv; i++) { + if (p[i] == g[i]) { + moverr(i); + curmove(20, 0); + writel("Attempt to move to same location.\n"); return (0); } - - if (cturn*(g[i]-p[i]) < 0) { - moverr (i); - curmove (20,0); - writel ("Backwards move.\n"); + if (cturn * (g[i] - p[i]) < 0) { + moverr(i); + curmove(20, 0); + writel("Backwards move.\n"); return (0); } - - if (abs(board[bar]) && p[i] != bar) { - moverr (i); - curmove (20,0); - writel ("Men still on bar.\n"); + if (abs(board[bar]) && p[i] != bar) { + moverr(i); + curmove(20, 0); + writel("Men still on bar.\n"); return (0); } - - if ( (m = makmove(i)) ) { - moverr (i); - switch (m) { - + if ((m = makmove(i))) { + moverr(i); + switch (m) { case 1: - writel ("Move not rolled.\n"); + writel("Move not rolled.\n"); break; case 2: - writel ("Bad starting position.\n"); + writel("Bad starting position.\n"); break; case 3: - writel ("Destination occupied.\n"); + writel("Destination occupied.\n"); break; case 4: - writel ("Can't remove men yet.\n"); + writel("Can't remove men yet.\n"); } return (0); } diff --git a/games/backgammon/common_source/fancy.c b/games/backgammon/common_source/fancy.c index 3f70c1f8f5..7b36784213 100644 --- a/games/backgammon/common_source/fancy.c +++ b/games/backgammon/common_source/fancy.c @@ -1,4 +1,4 @@ -/* +/*- * Copyright (c) 1980, 1993 * The Regents of the University of California. All rights reserved. * @@ -10,11 +10,7 @@ * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. - * 4. Neither the name of the University nor the names of its contributors + * 3. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * @@ -78,111 +74,111 @@ int oldb[] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}; int oldr; int oldw; - /* "real" cursor positions, so - * it knows when to reposition. - * These are -1 if curr and curc - * are accurate */ +/* + * "real" cursor positions, so it knows when to reposition. These are -1 if + * curr and curc are accurate + */ int realr; int realc; void fboard(void) { - int i, j, l; + int i, j, l; - curmove (0,0); /* do top line */ + curmove(0, 0); /* do top line */ for (i = 0; i < 53; i++) - fancyc ('_'); + fancyc('_'); - curmove (15,0); /* do botttom line */ + curmove(15, 0); /* do bottom line */ for (i = 0; i < 53; i++) - fancyc ('_'); - - l = 1; /* do vertical lines */ - for (i = 52; i > -1; i -= 28) { - curmove ( (l == 1? 1: 15) ,i); - fancyc ('|'); - for (j = 0; j < 14; j++) { - curmove (curr+l,curc-1); - fancyc ('|'); + fancyc('_'); + + l = 1; /* do vertical lines */ + for (i = 52; i > -1; i -= 28) { + curmove((l == 1 ? 1 : 15), i); + fancyc('|'); + for (j = 0; j < 14; j++) { + curmove(curr + l, curc - 1); + fancyc('|'); } if (i == 24) i += 32; - l = -l; /* alternate directions */ + l = -l; /* alternate directions */ } - curmove (2,1); /* label positions 13-18 */ - for (i = 13; i < 18; i++) { - fancyc ('1'); - fancyc ((i % 10)+'0'); - curmove (curr,curc+2); + curmove(2, 1); /* label positions 13-18 */ + for (i = 13; i < 18; i++) { + fancyc('1'); + fancyc((i % 10) + '0'); + curmove(curr, curc + 2); } - fancyc ('1'); - fancyc ('8'); - - curmove (2,29); /* label positions 19-24 */ - fancyc ('1'); - fancyc ('9'); - for (i = 20; i < 25; i++) { - curmove (curr,curc+2); - fancyc ('2'); - fancyc ((i % 10)+'0'); + fancyc('1'); + fancyc('8'); + + curmove(2, 29); /* label positions 19-24 */ + fancyc('1'); + fancyc('9'); + for (i = 20; i < 25; i++) { + curmove(curr, curc + 2); + fancyc('2'); + fancyc((i % 10) + '0'); } - curmove (14,1); /* label positions 12-7 */ - fancyc ('1'); - fancyc ('2'); - for (i = 11; i > 6; i--) { - curmove (curr,curc+2); - fancyc (i > 9? '1': ' '); - fancyc ((i % 10)+'0'); + curmove(14, 1); /* label positions 12-7 */ + fancyc('1'); + fancyc('2'); + for (i = 11; i > 6; i--) { + curmove(curr, curc + 2); + fancyc(i > 9 ? '1' : ' '); + fancyc((i % 10) + '0'); } - curmove (14,30); /* label positions 6-1 */ - fancyc ('6'); + curmove(14, 30); /* label positions 6-1 */ + fancyc('6'); for (i = 5; i > 0; i--) { - curmove (curr,curc+3); - fancyc (i+'0'); + curmove(curr, curc + 3); + fancyc(i + '0'); } - for (i = 12; i > 6; i--) /* print positions 12-7 */ + for (i = 12; i > 6; i--) /* print positions 12-7 */ if (board[i]) - bsect (board[i],13,1+4*(12-i),-1); + bsect(board[i], 13, 1 + 4 * (12 - i), -1); - if (board[0]) /* print red men on bar */ - bsect (board[0],13,25,-1); + if (board[0]) /* print red men on bar */ + bsect(board[0], 13, 25, -1); - for (i = 6; i > 0; i--) /* print positions 6-1 */ + for (i = 6; i > 0; i--) /* print positions 6-1 */ if (board[i]) - bsect (board[i],13,29+4*(6-i),-1); + bsect(board[i], 13, 29 + 4 * (6 - i), -1); - l = (off[1] < 0? off[1]+15: off[1]); /* print white's home */ - bsect (l,3,54,1); + l = (off[1] < 0 ? off[1] + 15 : off[1]); /* print white's home */ + bsect(l, 3, 54, 1); - curmove (8,25); /* print the word BAR */ - fancyc ('B'); - fancyc ('A'); - fancyc ('R'); + curmove(8, 25); /* print the word BAR */ + fancyc('B'); + fancyc('A'); + fancyc('R'); - for (i = 13; i < 19; i++) /* print positions 13-18 */ + for (i = 13; i < 19; i++) /* print positions 13-18 */ if (board[i]) - bsect (board[i],3,1+4*(i-13),1); + bsect(board[i], 3, 1 + 4 * (i - 13), 1); - if (board[25]) /* print white's men on bar */ - bsect (board[25],3,25,1); + if (board[25]) /* print white's men on bar */ + bsect(board[25], 3, 25, 1); - for (i = 19; i < 25; i++) /* print positions 19-24 */ + for (i = 19; i < 25; i++) /* print positions 19-24 */ if (board[i]) - bsect (board[i],3,29+4*(i-19),1); + bsect(board[i], 3, 29 + 4 * (i - 19), 1); - l = (off[0] < 0? off[0]+15: off[0]); /* print red's home */ - bsect (-l,13,54,-1); + l = (off[0] < 0 ? off[0] + 15 : off[0]); /* print red's home */ + bsect(-l, 13, 54, -1); - for (i = 0; i < 26; i++) /* save board position - * for refresh later */ + for (i = 0; i < 26; i++) /* save board position + * for refresh later */ oldb[i] = board[i]; - oldr = (off[1] < 0? off[1]+15: off[1]); - oldw = -(off[0] < 0? off[0]+15: off[0]); + oldr = (off[1] < 0 ? off[1] + 15 : off[1]); + oldw = -(off[0] < 0 ? off[0] + 15 : off[0]); } /* @@ -194,60 +190,57 @@ fboard(void) * to see if the position is a player's home, since those are printed * differently. */ - static void bsect(int b, int rpos, int cpos, int cnext) { - int j; /* index */ - int n; /* number of men on position */ - int bct; /* counter */ - int k; /* index */ - char pc; /* color of men on position */ + int j; /* index */ + int n; /* number of men on position */ + int bct; /* counter */ + int k; /* index */ + char pc; /* color of men on position */ bct = 0; - n = abs(b); /* initialize n and pc */ - pc = (b > 0? 'r': 'w'); + n = abs(b); /* initialize n and pc */ + pc = (b > 0 ? 'r' : 'w'); - if (n < 6 && cpos < 54) /* position cursor at start */ - curmove (rpos,cpos+1); + if (n < 6 && cpos < 54) /* position cursor at start */ + curmove(rpos, cpos + 1); else - curmove (rpos,cpos); + curmove(rpos, cpos); - for (j = 0; j < 5; j++) { /* print position row by row */ + for (j = 0; j < 5; j++) { /* print position row by row */ + for (k = 0; k < 15; k += 5) /* print men */ + if (n > j + k) + fancyc(pc); - for (k = 0; k < 15; k += 5) /* print men */ - if (n > j+k) - fancyc (pc); - - if (j < 4) { /* figure how far to - * back up for next - * row */ - if (n < 6) { /* stop if none left */ - if (j+1 == n) + if (j < 4) { /* figure how far to back up for next row */ + if (n < 6) { /* stop if none left */ + if (j + 1 == n) break; - bct = 1; /* single column */ - } else { - if (n < 11) { /* two columns */ - if (cpos == 54) { /* home pos */ - if (j+5 >= n) + bct = 1; /* single column */ + } else { + if (n < 11) { /* two columns */ + if (cpos == 54) { /* home pos */ + if (j + 5 >= n) bct = 1; else bct = 2; } - if (cpos < 54) { /* not home */ - if (j+6 >= n) + if (cpos < 54) { /* not home */ + if (j + 6 >= n) bct = 1; else bct = 2; } - } else { /* three columns */ - if (j+10 >= n) + } else { /* three columns */ + if (j + 10 >= n) bct = 2; else bct = 3; } } - curmove (curr+cnext,curc-bct); /* reposition cursor */ + /* reposition cursor */ + curmove(curr + cnext, curc - bct); } } } @@ -255,58 +248,50 @@ bsect(int b, int rpos, int cpos, int cnext) void refresh(void) { - int i, r, c; + int i, r, c; - r = curr; /* save current position */ + r = curr; /* save current position */ c = curc; - for (i = 12; i > 6; i--) /* fix positions 12-7 */ - if (board[i] != oldb[i]) { - fixpos (oldb[i],board[i],13,1+(12-i)*4,-1); + for (i = 12; i > 6; i--) /* fix positions 12-7 */ + if (board[i] != oldb[i]) { + fixpos(oldb[i], board[i], 13, 1 + (12 - i) * 4, -1); oldb[i] = board[i]; } - - if (board[0] != oldb[0]) { /* fix red men on bar */ - fixpos (oldb[0],board[0],13,25,-1); + if (board[0] != oldb[0]) { /* fix red men on bar */ + fixpos(oldb[0], board[0], 13, 25, -1); oldb[0] = board[0]; } - - for (i = 6; i > 0; i--) /* fix positions 6-1 */ - if (board[i] != oldb[i]) { - fixpos (oldb[i],board[i],13,29+(6-i)*4,-1); + for (i = 6; i > 0; i--) /* fix positions 6-1 */ + if (board[i] != oldb[i]) { + fixpos(oldb[i], board[i], 13, 29 + (6 - i) * 4, -1); oldb[i] = board[i]; } - - i = -(off[0] < 0? off[0]+15: off[0]); /* fix white's home */ - if (oldw != i) { - fixpos (oldw,i,13,54,-1); + i = -(off[0] < 0 ? off[0] + 15 : off[0]); /* fix white's home */ + if (oldw != i) { + fixpos(oldw, i, 13, 54, -1); oldw = i; } - - for (i = 13; i < 19; i++) /* fix positions 13-18 */ - if (board[i] != oldb[i]) { - fixpos (oldb[i],board[i],3,1+(i-13)*4,1); + for (i = 13; i < 19; i++) /* fix positions 13-18 */ + if (board[i] != oldb[i]) { + fixpos(oldb[i], board[i], 3, 1 + (i - 13) * 4, 1); oldb[i] = board[i]; } - - if (board[25] != oldb[25]) { /* fix white men on bar */ - fixpos (oldb[25],board[25],3,25,1); + if (board[25] != oldb[25]) { /* fix white men on bar */ + fixpos(oldb[25], board[25], 3, 25, 1); oldb[25] = board[25]; } - - for (i = 19; i < 25; i++) /* fix positions 19-24 */ - if (board[i] != oldb[i]) { - fixpos (oldb[i],board[i],3,29+(i-19)*4,1); + for (i = 19; i < 25; i++) /* fix positions 19-24 */ + if (board[i] != oldb[i]) { + fixpos(oldb[i], board[i], 3, 29 + (i - 19) * 4, 1); oldb[i] = board[i]; } - - i = (off[1] < 0? off[1]+15: off[1]); /* fix red's home */ - if (oldr != i) { - fixpos (oldr,i,3,54,1); + i = (off[1] < 0 ? off[1] + 15 : off[1]); /* fix red's home */ + if (oldr != i) { + fixpos(oldr, i, 3, 54, 1); oldr = i; } - - curmove (r,c); /* return to saved position */ + curmove(r, c); /* return to saved position */ newpos(); buflush(); } @@ -314,83 +299,97 @@ refresh(void) static void fixpos(int cur, int new, int r, int c, int inc) { - int o, n, nv; - int ov, nc; - char col; + int o, n, nv; + int ov, nc; + char col; nc = 0; - if (cur*new >= 0) { + if (cur * new >= 0) { ov = abs(cur); nv = abs(new); - col = (cur+new > 0? 'r': 'w'); - o = (ov-1)/5; - n = (nv-1)/5; - if (o == n) { + col = (cur + new > 0 ? 'r' : 'w'); + o = (ov - 1) / 5; + n = (nv - 1) / 5; + if (o == n) { if (o == 2) - nc = c+2; + nc = c + 2; if (o == 1) - nc = c < 54? c: c+1; + nc = c < 54 ? c : c + 1; if (o == 0) - nc = c < 54? c+1: c; + nc = c < 54 ? c + 1 : c; if (ov > nv) - fixcol (r+inc*(nv-n*5),nc,abs(ov-nv),' ',inc); + fixcol(r + inc * (nv - n * 5), nc, + abs(ov - nv), ' ', inc); else - fixcol (r+inc*(ov-o*5),nc,abs(ov-nv),col,inc); + fixcol(r + inc * (ov - o * 5), nc, + abs(ov - nv), col, inc); return; - } else { - if (c < 54) { - if (o+n == 1) { - if (n) { - fixcol (r,c,abs(nv-5),col,inc); + } else { + if (c < 54) { + if (o + n == 1) { + if (n) { + fixcol(r, c, abs(nv - 5), col, + inc); if (ov != 5) - fixcol (r+inc*ov,c+1,abs(ov-5),col,inc); - } else { - fixcol (r,c,abs(ov-5),' ',inc); + fixcol(r + inc * ov, + c + 1, abs(ov - 5), + col, inc); + } else { + fixcol(r, c, abs(ov - 5), ' ', + inc); if (nv != 5) - fixcol (r+inc*nv,c+1,abs(nv-5),' ',inc); + fixcol(r + inc * nv, + c + 1, abs(nv - 5), + ' ', inc); } return; } - if (n == 2) { + if (n == 2) { if (ov != 10) - fixcol (r+inc*(ov-5),c,abs(ov-10),col,inc); - fixcol (r,c+2,abs(nv-10),col,inc); - } else { + fixcol(r + inc * (ov - 5), c, + abs(ov - 10), col, inc); + fixcol(r, c + 2, abs(nv - 10), col, inc); + } else { if (nv != 10) - fixcol (r+inc*(nv-5),c,abs(nv-10),' ',inc); - fixcol (r,c+2,abs(ov-10),' ',inc); + fixcol(r + inc * (nv - 5), c, + abs(nv - 10), ' ', inc); + fixcol(r, c + 2, abs(ov - 10), ' ', inc); } return; } - if (n > o) { - fixcol (r+inc*(ov%5),c+o,abs(5*n-ov),col,inc); - if (nv != 5*n) - fixcol (r,c+n,abs(5*n-nv),col,inc); - } else { - fixcol (r+inc*(nv%5),c+n,abs(5*n-nv),' ',inc); - if (ov != 5*o) - fixcol (r,c+o,abs(5*o-ov),' ',inc); + if (n > o) { + fixcol(r + inc * (ov % 5), c + o, + abs(5 * n - ov), col, inc); + if (nv != 5 * n) + fixcol(r, c + n, abs(5 * n - nv), + col, inc); + } else { + fixcol(r + inc * (nv % 5), c + n, + abs(5 * n - nv), ' ', inc); + if (ov != 5 * o) + fixcol(r, c + o, abs(5 * o - ov), + ' ', inc); } return; } } nv = abs(new); - fixcol (r,c+1,nv,new > 0? 'r': 'w',inc); + fixcol(r, c + 1, nv, new > 0 ? 'r' : 'w', inc); if (abs(cur) <= abs(new)) return; - fixcol (r+inc*new,c+1,abs(cur+new),' ',inc); + fixcol(r + inc * new, c + 1, abs(cur + new), ' ', inc); } static void fixcol(int r, int c, int l, int ch, int inc) { - int i; + int i; - curmove (r,c); - fancyc (ch); - for (i = 1; i < l; i++) { - curmove (curr+inc,curc-1); - fancyc (ch); + curmove(r, c); + fancyc(ch); + for (i = 1; i < l; i++) { + curmove(curr + inc, curc - 1); + fancyc(ch); } } @@ -399,7 +398,7 @@ curmove(int r, int c) { if (curr == r && curc == c) return; - if (realr == -1) { + if (realr == -1) { realr = curr; realc = curc; } @@ -410,165 +409,154 @@ curmove(int r, int c) void newpos(void) { - int r; /* destination row */ - int c; /* destination column */ - int mode = -1; /* mode of movement */ + int r; /* destination row */ + int c; /* destination column */ + int mode; /* mode of movement */ - int ccount = 1000; /* character count */ - int i; /* index */ - int n; /* temporary variable */ - char *m; /* string containing CM movement */ + int ccount; /* character count */ + int i; /* index */ + int n; /* temporary variable */ + char *m; /* string containing CM movement */ + mode = -1; + ccount = 1000; m = NULL; - if (realr == -1) /* see if already there */ + if (realr == -1) /* see if already there */ return; - r = curr; /* set current and dest. positions */ + r = curr; /* set current and dest. positions */ c = curc; curr = realr; curc = realc; - /* double check position */ - if (curr == r && curc == c) { + /* double check position */ + if (curr == r && curc == c) { realr = realc = -1; return; } - - if (CM) { /* try CM to get there */ + if (CM) { /* try CM to get there */ mode = 0; - m = (char *)tgoto (CM,c,r); - ccount = strlen (m); + m = (char *)tgoto(CM, c, r); + ccount = strlen(m); } - - /* try HO and local movement */ - if (HO && (n = r+c*lND+lHO) < ccount) { + /* try HO and local movement */ + if (HO && (n = r + c * lND + lHO) < ccount) { mode = 1; ccount = n; } - - /* try various LF combinations */ - if (r >= curr) { - /* CR, LF, and ND */ - if ((n = (r-curr)+c*lND+1) < ccount) { + /* try various LF combinations */ + if (r >= curr) { + /* CR, LF, and ND */ + if ((n = (r - curr) + c * lND + 1) < ccount) { mode = 2; ccount = n; } - /* LF, ND */ - if (c >= curc && (n = (r-curr)+(c-curc)*lND) < ccount) { + /* LF, ND */ + if (c >= curc && (n = (r - curr) + (c - curc) * lND) < ccount) { mode = 3; ccount = n; } - /* LF, BS */ - if (c < curc && (n = (r-curr)+(curc-c)*lBC) < ccount) { + /* LF, BS */ + if (c < curc && (n = (r - curr) + (curc - c) * lBC) < ccount) { mode = 4; ccount = n; } } - - /* try corresponding UP combinations */ - if (r < curr) { - /* CR, UP, and ND */ - if ((n = (curr-r)*lUP+c*lND+1) < ccount) { + /* try corresponding UP combinations */ + if (r < curr) { + /* CR, UP, and ND */ + if ((n = (curr - r) * lUP + c * lND + 1) < ccount) { mode = 5; ccount = n; } - /* UP and ND */ - if (c >= curc && (n = (curr-r)*lUP+(c-curc)*lND) < ccount) { + /* UP and ND */ + if (c >= curc && + (n = (curr - r) * lUP + (c - curc) * lND) < ccount) { mode = 6; ccount = n; } - /* UP and BS */ - if (c < curc && (n = (curr-r)*lUP+(curc-c)*lBC) < ccount) { + /* UP and BS */ + if (c < curc && + (n = (curr - r) * lUP + (curc - c) * lBC) < ccount) { mode = 7; ccount = n; } } - - /* space over */ - if (curr == r && c > curc && linect[r] < curc && c-curc < ccount) + /* space over */ + if (curr == r && c > curc && linect[r] < curc && c - curc < ccount) mode = 8; - switch (mode) { - - case -1: /* error! */ - write (2,"\r\nInternal cursor error.\r\n",26); + switch (mode) { + case -1: /* error! */ + write(2, "\r\nInternal cursor error.\r\n", 26); getout(); - /* direct cursor motion */ - case 0: - tputs (m,abs(curr-r),addbuf); + case 0: /* direct cursor motion */ + tputs(m, abs(curr - r), addbuf); break; - /* relative to "home" */ - case 1: - tputs (HO,r,addbuf); + case 1: /* relative to "home" */ + tputs(HO, r, addbuf); for (i = 0; i < r; i++) - addbuf ('\012'); + addbuf('\012'); for (i = 0; i < c; i++) - tputs (ND,1,addbuf); + tputs(ND, 1, addbuf); break; - /* CR and down and over */ - case 2: - addbuf ('\015'); - for (i = 0; i < r-curr; i++) - addbuf ('\012'); + case 2: /* CR and down and over */ + addbuf('\015'); + for (i = 0; i < r - curr; i++) + addbuf('\012'); for (i = 0; i < c; i++) - tputs (ND,1,addbuf); + tputs(ND, 1, addbuf); break; - /* down and over */ - case 3: - for (i = 0; i < r-curr; i++) - addbuf ('\012'); - for (i = 0; i < c-curc; i++) - tputs (ND,1,addbuf); + case 3: /* down and over */ + for (i = 0; i < r - curr; i++) + addbuf('\012'); + for (i = 0; i < c - curc; i++) + tputs(ND, 1, addbuf); break; - /* down and back */ - case 4: - for (i = 0; i < r-curr; i++) - addbuf ('\012'); - for (i = 0; i < curc-c; i++) - addbuf ('\010'); + case 4: /* down and back */ + for (i = 0; i < r - curr; i++) + addbuf('\012'); + for (i = 0; i < curc - c; i++) + addbuf('\010'); break; - /* CR and up and over */ - case 5: - addbuf ('\015'); - for (i = 0; i < curr-r; i++) - tputs (UP,1,addbuf); + case 5: /* CR and up and over */ + addbuf('\015'); + for (i = 0; i < curr - r; i++) + tputs(UP, 1, addbuf); for (i = 0; i < c; i++) - tputs (ND,1,addbuf); + tputs(ND, 1, addbuf); break; - /* up and over */ - case 6: - for (i = 0; i < curr-r; i++) - tputs (UP,1,addbuf); - for (i = 0; i < c-curc; i++) - tputs (ND,1,addbuf); + case 6: /* up and over */ + for (i = 0; i < curr - r; i++) + tputs(UP, 1, addbuf); + for (i = 0; i < c - curc; i++) + tputs(ND, 1, addbuf); break; - /* up and back */ - case 7: - for (i = 0; i < curr-r; i++) - tputs (UP,1,addbuf); - for (i = 0; i < curc-c; i++) { + case 7: /* up and back */ + for (i = 0; i < curr - r; i++) + tputs(UP, 1, addbuf); + for (i = 0; i < curc - c; i++) { if (BC) - tputs (BC,1,addbuf); + tputs(BC, 1, addbuf); else - addbuf ('\010'); + addbuf('\010'); } break; - /* safe space */ - case 8: - for (i = 0; i < c-curc; i++) - addbuf (' '); + case 8: /* safe space */ + for (i = 0; i < c - curc; i++) + addbuf(' '); } - /* fix positions */ + /* fix positions */ curr = r; curc = c; realr = -1; @@ -578,121 +566,117 @@ newpos(void) void clear(void) { - int i; + int i; - /* double space if can't clear */ - if (CL == 0) { - writel ("\n\n"); + /* double space if can't clear */ + if (CL == 0) { + writel("\n\n"); return; } - curr = curc = 0; /* fix position markers */ realr = realc = -1; for (i = 0; i < 24; i++) /* clear line counts */ linect[i] = -1; buffnum = -1; /* ignore leftover buffer contents */ - tputs (CL,CO,addbuf); /* put CL in buffer */ + tputs(CL, CO, addbuf); /* put CL in buffer */ } - /* input is character to output */ void fancyc(char c) { - int sp; /* counts spaces in a tab */ + int sp; /* counts spaces in a tab */ - if (c == '\007') { /* bells go in blindly */ - addbuf (c); + if (c == '\007') { /* bells go in blindly */ + addbuf(c); return; } - /* process tabs, use spaces if the - * the tab should be erasing things, - * otherwise use cursor movement - * routines. Note this does not use - * hardware tabs at all. */ - if (c == '\t') { - sp = (curc+8) & (~ 7); /* compute spaces */ - /* check line length */ - if (linect[curr] >= curc || sp < 4) { + /* + * process tabs, use spaces if the the tab should be erasing things, + * otherwise use cursor movement routines. Note this does not use + * hardware tabs at all. + */ + if (c == '\t') { + sp = (curc + 8) & (~7); /* compute spaces */ + /* check line length */ + if (linect[curr] >= curc || sp < 4) { for (; sp > curc; sp--) - addbuf (' '); + addbuf(' '); curc = sp; /* fix curc */ } else - curmove (curr,sp); + curmove(curr, sp); return; } - - /* do newline be calling newline */ - if (c == '\n') { + /* do newline be calling newline */ + if (c == '\n') { newline(); return; } - - /* ignore any other control chars */ + /* ignore any other control chars */ if (c < ' ') return; - /* if an erasing space or non-space, - * just add it to buffer. Otherwise - * use cursor movement routine, so that - * multiple spaces will be grouped - * together */ - if (c > ' ' || linect[curr] >= curc) { - newpos (); /* make sure position correct */ - addbuf (c); /* add character to buffer */ - /* fix line length */ + /* + * if an erasing space or non-space, just add it to buffer. Otherwise + * use cursor movement routine, so that multiple spaces will be grouped + * together + */ + if (c > ' ' || linect[curr] >= curc) { + newpos(); /* make sure position correct */ + addbuf(c); /* add character to buffer */ + /* fix line length */ if (c == ' ' && linect[curr] == curc) linect[curr]--; - else if (linect[curr] < curc) - linect[curr] = curc; - curc++; /* fix curc */ + else + if (linect[curr] < curc) + linect[curr] = curc; + curc++; /* fix curc */ } else - /* use cursor movement routine */ - curmove (curr,curc+1); + /* use cursor movement routine */ + curmove(curr, curc + 1); } void clend(void) { - int i; + int i; - if (CD) { - tputs (CD,CO-curr,addbuf); + if (CD) { + tputs(CD, CO - curr, addbuf); for (i = curr; i < LI; i++) linect[i] = -1; return; } - - curmove (i = curr,0); + curmove(i = curr, 0); cline(); - while (curr < LI-1) { - curmove (curr+1,0); + while (curr < LI - 1) { + curmove(curr + 1, 0); if (linect[curr] > -1) - cline (); + cline(); } - curmove (i,0); + curmove(i, 0); } void cline(void) { - int c; + int c; if (curc > linect[curr]) return; - newpos (); - if (CE) { - tputs (CE,1,addbuf); - linect[curr] = curc-1; - } else { - c = curc-1; - while (linect[curr] > c) { - addbuf (' '); + newpos(); + if (CE) { + tputs(CE, 1, addbuf); + linect[curr] = curc - 1; + } else { + c = curc - 1; + while (linect[curr] > c) { + addbuf(' '); curc++; linect[curr]--; } - curmove (curr,c+1); + curmove(curr, c + 1); } } @@ -700,54 +684,54 @@ static void newline(void) { cline(); - if (curr == LI-1) - curmove (begscr,0); + if (curr == LI - 1) + curmove(begscr, 0); else - curmove (curr+1,0); + curmove(curr + 1, 0); } int getcaps(const char *s) { - char *code; /* two letter code */ - char ***cap; /* pointer to cap string */ - char *bufp; /* pointer to cap buffer */ - char tentry[1024]; /* temporary uncoded caps buffer */ + char *code; /* two letter code */ + char ***cap; /* pointer to cap string */ + char *bufp; /* pointer to cap buffer */ + char tentry[1024]; /* temporary uncoded caps buffer */ - tgetent (tentry, s); /* get uncoded termcap entry */ + tgetent(tentry, s); /* get uncoded termcap entry */ - LI = tgetnum ("li"); /* get number of lines */ + LI = tgetnum("li"); /* get number of lines */ if (LI == -1) LI = 12; - CO = tgetnum ("co"); /* get number of columns */ + CO = tgetnum("co"); /* get number of columns */ if (CO == -1) CO = 65; - bufp = tbuf; /* get padding character */ - tgetstr ("pc",&bufp); + bufp = tbuf; /* get padding character */ + tgetstr("pc", &bufp); if (bufp != tbuf) PC = *tbuf; else PC = 0; - bufp = tbuf; /* get string entries */ + bufp = tbuf; /* get string entries */ cap = tstr; for (code = tcap; *code; code += 2) - **cap++ = (char *)tgetstr (code,&bufp); + **cap++ = (char *)tgetstr(code, &bufp); - /* get pertinent lengths */ + /* get pertinent lengths */ if (HO) - lHO = strlen (HO); + lHO = strlen(HO); if (BC) - lBC = strlen (BC); + lBC = strlen(BC); else lBC = 1; if (UP) - lUP = strlen (UP); + lUP = strlen(UP); if (ND) - lND = strlen (ND); + lND = strlen(ND); if (LI < 24 || CO < 72 || !(CL && UP && ND)) return (0); - linect = (int *)calloc (LI+1,sizeof(int)); + linect = calloc(LI + 1, sizeof(int)); return (1); } diff --git a/games/backgammon/common_source/init.c b/games/backgammon/common_source/init.c index e13a9ab24d..d5ac3cc3a3 100644 --- a/games/backgammon/common_source/init.c +++ b/games/backgammon/common_source/init.c @@ -1,4 +1,4 @@ -/* +/*- * Copyright (c) 1980, 1993 * The Regents of the University of California. All rights reserved. * @@ -10,11 +10,7 @@ * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. - * 4. Neither the name of the University nor the names of its contributors + * 3. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * @@ -42,7 +38,7 @@ * variable initialization. */ - /* name of executable object programs */ +/* name of executable object programs */ const char EXEC[] = "/usr/games/backgammon"; const char TEACH[] = "/usr/games/teachgammon"; @@ -63,7 +59,7 @@ int tflag = 0; /* cursor addressing flag */ int iroll = 0; /* special flag for inputting rolls */ int rfl = 0; -const char *const color[] = {"White","Red","white","red"}; +const char *const color[] = {"White", "Red", "white", "red"}; const char *const *Colorptr; const char *const *colorptr; diff --git a/games/backgammon/common_source/odds.c b/games/backgammon/common_source/odds.c index 2d0814183d..4ced830c56 100644 --- a/games/backgammon/common_source/odds.c +++ b/games/backgammon/common_source/odds.c @@ -1,4 +1,4 @@ -/* +/*- * Copyright (c) 1980, 1993 * The Regents of the University of California. All rights reserved. * @@ -10,11 +10,7 @@ * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. - * 4. Neither the name of the University nor the names of its contributors + * 3. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * @@ -40,21 +36,21 @@ void odds(int r1, int r2, int val) { - int i, j; + int i, j; - if (r1 == 0) { + if (r1 == 0) { for (i = 0; i < 6; i++) for (j = 0; j < 6; j++) table[i][j] = 0; return; - } else { + } else { r1--; - if (r2-- == 0) - for (i = 0; i < 6; i++) { + if (r2-- == 0) { + for (i = 0; i < 6; i++) { table[i][r1] += val; table[r1][i] += val; } - else { + } else { table[r2][r1] += val; table[r1][r2] += val; } @@ -64,9 +60,7 @@ odds(int r1, int r2, int val) int count(void) { - int i; - int j; - int total; + int i, j, total; total = 0; for (i = 0; i < 6; i++) @@ -78,33 +72,33 @@ count(void) int canhit(int i, int c) { - int j, k, b; - int a, diff, place, addon, menstuck; + int j, k, b; + int a, diff, place, addon, menstuck; if (c == 0) - odds (0,0,0); - if (board[i] > 0) { + odds(0, 0, 0); + if (board[i] > 0) { a = -1; b = 25; - } else { + } else { a = 1; b = 0; } - place = abs (25-b-i); - menstuck = abs (board[b]); - for (j = b; j != i; j += a) { - if (board[j]*a > 0) { - diff = abs(j-i); - addon = place+((board[j]*a > 2 || j == b)? 5: 0); + place = abs(25 - b - i); + menstuck = abs(board[b]); + for (j = b; j != i; j += a) { + if (board[j] * a > 0) { + diff = abs(j - i); + addon = place + ((board[j] * a > 2 || j == b) ? 5 : 0); if ((j == b && menstuck == 1) && (j != b && menstuck == 0)) for (k = 1; k < diff; k++) - if (k < 7 && diff-k < 7 && - (board[i+a*k]*a >= 0 || - board[i+a*(diff-k)] >= 0)) - odds (k,diff-k,addon); + if (k < 7 && diff - k < 7 && + (board[i + a * k] * a >= 0 || + board[i + a * (diff - k)] >= 0)) + odds(k, diff - k, addon); if ((j == b || menstuck < 2) && diff < 7) - odds (diff,0,addon); + odds(diff, 0, addon); } if (j == b && menstuck > 1) break; diff --git a/games/backgammon/common_source/one.c b/games/backgammon/common_source/one.c index 78a6ea24cb..ca43a485f3 100644 --- a/games/backgammon/common_source/one.c +++ b/games/backgammon/common_source/one.c @@ -1,4 +1,4 @@ -/* +/*- * Copyright (c) 1980, 1993 * The Regents of the University of California. All rights reserved. * @@ -10,11 +10,7 @@ * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. - * 4. Neither the name of the University nor the names of its contributors + * 3. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * @@ -43,47 +39,47 @@ static int last(void); int makmove(int i) { - int n, d; - int max; + int n, d; + int max; d = d0; - n = abs(g[i]-p[i]); - max = (*offptr < 0? 7: last()); - if (board[p[i]]*cturn <= 0) - return (checkd(d)+2); - if (g[i] != home && board[g[i]]*cturn < -1) - return (checkd(d)+3); - if (i || D0 == D1) { - if (n == max? D1 < n: D1 != n) - return (checkd(d)+1); - } else { - if (n == max? D0 < n && D1 < n: D0 != n && D1 != n) - return (checkd(d)+1); - if (n == max? D0 < n: D0 != n) { + n = abs(g[i] - p[i]); + max = (*offptr < 0 ? 7 : last()); + if (board[p[i]] * cturn <= 0) + return (checkd(d) + 2); + if (g[i] != home && board[g[i]] * cturn < -1) + return (checkd(d) + 3); + if (i || D0 == D1) { + if (n == max ? D1 < n : D1 != n) + return (checkd(d) + 1); + } else { + if (n == max ? D0 < n && D1 < n : D0 != n && D1 != n) + return (checkd(d) + 1); + if (n == max ? D0 < n : D0 != n) { if (d0) - return (checkd(d)+1); + return (checkd(d) + 1); swap; } } if (g[i] == home && *offptr < 0) - return (checkd(d)+4); + return (checkd(d) + 4); h[i] = 0; board[p[i]] -= cturn; - if (g[i] != home) { - if (board[g[i]] == -cturn) { + if (g[i] != home) { + if (board[g[i]] == -cturn) { board[home] -= cturn; board[g[i]] = 0; h[i] = 1; - if (abs(bar-g[i]) < 7) { + if (abs(bar - g[i]) < 7) { (*inopp)--; if (*offopp >= 0) *offopp -= 15; } } board[g[i]] += cturn; - if (abs(home-g[i]) < 7 && abs(home-p[i]) > 6) { + if (abs(home - g[i]) < 7 && abs(home - p[i]) > 6) { (*inptr)++; - if (*inptr+*offptr == 0) + if (*inptr + *offptr == 0) *offptr += 15; } } else { @@ -96,22 +92,22 @@ makmove(int i) void moverr(int i) { - int j; + int j; if (tflag) - curmove (20,0); + curmove(20, 0); else - writec ('\n'); - writel ("Error: "); - for (j = 0; j <= i; j++) { - wrint (p[j]); - writec ('-'); - wrint (g[j]); + writec('\n'); + writel("Error: "); + for (j = 0; j <= i; j++) { + wrint(p[j]); + writec('-'); + wrint(g[j]); if (j < i) - writec (','); + writec(','); } - writel ("... "); - movback (i); + writel("... "); + movback(i); } static int @@ -125,20 +121,20 @@ checkd(int d) static int last(void) { - int i; + int i; - for (i = home-6*cturn; i != home; i += cturn) - if (board[i]*cturn > 0) - return (abs(home-i)); - return(-1); + for (i = home - 6 * cturn; i != home; i += cturn) + if (board[i] * cturn > 0) + return (abs(home - i)); + return (-1); } void movback(int i) { - int j; + int j; - for (j = i-1; j >= 0; j--) + for (j = i - 1; j >= 0; j--) backone(j); } @@ -146,23 +142,23 @@ void backone(int i) { board[p[i]] += cturn; - if (g[i] != home) { + if (g[i] != home) { board[g[i]] -= cturn; - if (abs(g[i]-home) < 7 && abs(p[i]-home) > 6) { + if (abs(g[i] - home) < 7 && abs(p[i] - home) > 6) { (*inptr)--; - if (*inptr+*offptr < 15 && *offptr >= 0) + if (*inptr + *offptr < 15 && *offptr >= 0) *offptr -= 15; } - } else { + } else { (*offptr)--; (*inptr)++; } - if (h[i]) { + if (h[i]) { board[home] += cturn; board[g[i]] = -cturn; - if (abs(bar-g[i]) < 7) { + if (abs(bar - g[i]) < 7) { (*inopp)++; - if (*inopp+*offopp == 0) + if (*inopp + *offopp == 0) *offopp += 15; } } diff --git a/games/backgammon/common_source/save.c b/games/backgammon/common_source/save.c index 6a0f27a637..4e36a82c41 100644 --- a/games/backgammon/common_source/save.c +++ b/games/backgammon/common_source/save.c @@ -1,4 +1,4 @@ -/* +/*- * Copyright (c) 1980, 1993 * The Regents of the University of California. All rights reserved. * @@ -10,11 +10,7 @@ * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. - * 4. Neither the name of the University nor the names of its contributors + * 3. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * @@ -55,123 +51,123 @@ static const char cantrec[] = "Can't recover file: "; void save(int n) { - int fdesc; - char *fs; - char fname[50]; + int fdesc; + char *fs; + char fname[50]; - if (n) { - if (tflag) { - curmove (20,0); + if (n) { + if (tflag) { + curmove(20, 0); clend(); } else - writec ('\n'); - writel (confirm); - if (! yorn(0)) + writec('\n'); + writel(confirm); + if (!yorn(0)) return; } cflag = 1; - for (;;) { - writel (prompt); + for (;;) { + writel(prompt); fs = fname; - while ((*fs = readc()) != '\n') { - if (*fs == tty.c_cc[VERASE]) { - if (fs > fname) { + while ((*fs = readc()) != '\n') { + if (*fs == tty.c_cc[VERASE]) { + if (fs > fname) { fs--; if (tflag) - curmove (curr,curc-1); + curmove(curr, curc - 1); else - writec (*fs); + writec(*fs); } else - writec ('\007'); + writec('\007'); continue; } - writec (*fs++); + writec(*fs++); } *fs = '\0'; - if ((fdesc = open(fname,O_RDWR)) == -1 && errno == ENOENT) { - if ((fdesc = creat (fname,0600)) != -1) - break; + if ((fdesc = open(fname, O_RDWR)) == -1 && errno == ENOENT) { + if ((fdesc = creat(fname, 0600)) != -1) + break; } - if (fdesc != -1) { - if (tflag) { - curmove (18,0); + if (fdesc != -1) { + if (tflag) { + curmove(18, 0); clend(); } else - writec ('\n'); - writel (exist1); - writel (fname); - writel (exist2); + writec('\n'); + writel(exist1); + writel(fname); + writel(exist2); cflag = 0; - close (fdesc); - if (yorn (0)) { - unlink (fname); - fdesc = creat (fname,0700); + close(fdesc); + if (yorn(0)) { + unlink(fname); + fdesc = creat(fname, 0700); break; - } else { + } else { cflag = 1; continue; } } - writel (cantuse); - writel (fname); - writel (".\n"); + writel(cantuse); + writel(fname); + writel(".\n"); cflag = 1; } - write (fdesc,board,sizeof board); - write (fdesc,off,sizeof off); - write (fdesc,in,sizeof in); - write (fdesc,dice,sizeof dice); - write (fdesc,&cturn,sizeof cturn); - write (fdesc,&dlast,sizeof dlast); - write (fdesc,&pnum,sizeof pnum); - write (fdesc,&rscore,sizeof rscore); - write (fdesc,&wscore,sizeof wscore); - write (fdesc,&gvalue,sizeof gvalue); - write (fdesc,&raflag,sizeof raflag); - close (fdesc); + write(fdesc, board, sizeof board); + write(fdesc, off, sizeof off); + write(fdesc, in, sizeof in); + write(fdesc, dice, sizeof dice); + write(fdesc, &cturn, sizeof cturn); + write(fdesc, &dlast, sizeof dlast); + write(fdesc, &pnum, sizeof pnum); + write(fdesc, &rscore, sizeof rscore); + write(fdesc, &wscore, sizeof wscore); + write(fdesc, &gvalue, sizeof gvalue); + write(fdesc, &raflag, sizeof raflag); + close(fdesc); if (tflag) - curmove (18,0); - writel (saved); - writel (fname); - writel (type); - writel (fname); - writel (rec); + curmove(18, 0); + writel(saved); + writel(fname); + writel(type); + writel(fname); + writel(rec); if (tflag) clend(); - getout (); + getout(); } void recover(const char *s) { - int fdesc; + int fdesc; - if ((fdesc = open (s,O_RDONLY)) == -1) - norec (s); - read (fdesc,board,sizeof board); - read (fdesc,off,sizeof off); - read (fdesc,in,sizeof in); - read (fdesc,dice,sizeof dice); - read (fdesc,&cturn,sizeof cturn); - read (fdesc,&dlast,sizeof dlast); - read (fdesc,&pnum,sizeof pnum); - read (fdesc,&rscore,sizeof rscore); - read (fdesc,&wscore,sizeof wscore); - read (fdesc,&gvalue,sizeof gvalue); - read (fdesc,&raflag,sizeof raflag); - close (fdesc); + if ((fdesc = open(s, O_RDONLY)) == -1) + norec(s); + read(fdesc, board, sizeof board); + read(fdesc, off, sizeof off); + read(fdesc, in, sizeof in); + read(fdesc, dice, sizeof dice); + read(fdesc, &cturn, sizeof cturn); + read(fdesc, &dlast, sizeof dlast); + read(fdesc, &pnum, sizeof pnum); + read(fdesc, &rscore, sizeof rscore); + read(fdesc, &wscore, sizeof wscore); + read(fdesc, &gvalue, sizeof gvalue); + read(fdesc, &raflag, sizeof raflag); + close(fdesc); rflag = 1; } static void norec(const char *s) { - const char *c; + const char *c; tflag = 0; - writel (cantrec); + writel(cantrec); c = s; while (*c != '\0') - writec (*c++); - getout (); + writec(*c++); + getout(); } diff --git a/games/backgammon/common_source/subs.c b/games/backgammon/common_source/subs.c index 77676bfd16..ee5ee9d900 100644 --- a/games/backgammon/common_source/subs.c +++ b/games/backgammon/common_source/subs.c @@ -1,4 +1,4 @@ -/* +/*- * Copyright (c) 1980, 1993 * The Regents of the University of California. All rights reserved. * @@ -10,11 +10,7 @@ * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. - * 4. Neither the name of the University nor the names of its contributors + * 3. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * @@ -63,8 +59,8 @@ const char *const descr[] = { void errexit(const char *s) { - write (2,"\n",1); - perror (s); + write(2, "\n", 1); + perror(s); getout(); } @@ -72,9 +68,9 @@ int addbuf(int c) { buffnum++; - if (buffnum == BUFSIZ) { - if (write(1,outbuff,BUFSIZ) != BUFSIZ) - errexit ("addbuf (write):"); + if (buffnum == BUFSIZ) { + if (write(1, outbuff, BUFSIZ) != BUFSIZ) + errexit("addbuf (write):"); buffnum = 0; } outbuff[buffnum] = c; @@ -87,23 +83,23 @@ buflush(void) if (buffnum < 0) return; buffnum++; - if (write (1,outbuff,buffnum) != buffnum) - errexit ("buflush (write):"); + if (write(1, outbuff, buffnum) != buffnum) + errexit("buflush (write):"); buffnum = -1; } char readc(void) { - char c; + char c; - if (tflag) { + if (tflag) { cline(); newpos(); } buflush(); - if (read(0,&c,1) != 1) - errexit ("readc"); + if (read(0, &c, 1) != 1) + errexit("readc"); #ifdef WHY_IS_THIS_HARDWIRED_IN_HERE if (c == '\177') getout(); @@ -123,33 +119,33 @@ void writec(char c) { if (tflag) - fancyc (c); + fancyc(c); else - addbuf (c); + addbuf(c); } void writel(const char *l) { #ifdef DEBUG - const char *s; + const char *s; if (trace == NULL) - trace = fopen ("bgtrace","w"); + trace = fopen("bgtrace", "w"); - fprintf (trace,"writel: \""); + fprintf(trace, "writel: \""); for (s = l; *s; s++) { if (*s < ' ' || *s == '\177') - fprintf (trace,"^%c",(*s)^0100); + fprintf(trace, "^%c", (*s) ^ 0100); else - putc (*s,trace); + putc(*s, trace); } - fprintf (trace,"\"\n"); - fflush (trace); + fprintf(trace, "\"\n"); + fflush(trace); #endif while (*l) - writec (*l++); + writec(*l++); } void @@ -158,12 +154,12 @@ proll(void) if (d0) swap; if (cturn == 1) - writel ("Red's roll: "); + writel("Red's roll: "); else - writel ("White's roll: "); - writec (D0+'0'); - writec ('\040'); - writec (D1+'0'); + writel("White's roll: "); + writec(D0 + '0'); + writec('\040'); + writec(D1 + '0'); if (tflag) cline(); } @@ -171,75 +167,73 @@ proll(void) void wrint(int n) { - int i, j, t; + int i, j, t; - for (i = 4; i > 0; i--) { + for (i = 4; i > 0; i--) { t = 1; - for (j = 0; j t-1) - writec ((n/t)%10+'0'); + if (n > t - 1) + writec((n / t) % 10 + '0'); } - writec (n%10+'0'); + writec(n % 10 + '0'); } void gwrite(void) { - int r, c; + int r, c; r = curr; c = curc; - if (tflag) { - curmove (16,0); - } + if (tflag) + curmove(16, 0); - if (gvalue > 1) { - writel ("Game value: "); - wrint (gvalue); - writel (". "); + if (gvalue > 1) { + writel("Game value: "); + wrint(gvalue); + writel(". "); if (dlast == -1) - writel (color[0]); + writel(color[0]); else - writel (color[1]); - writel (" doubled last."); - } else { - switch (pnum) { - case -1: /* player is red */ - writel (plred); + writel(color[1]); + writel(" doubled last."); + } else { + switch (pnum) { + case -1: /* player is red */ + writel(plred); break; - case 0: /* player is both colors */ - writel (nocomp); + case 0: /* player is both colors */ + writel(nocomp); break; - case 1: /* player is white */ - writel (plwhite); + case 1: /* player is white */ + writel(plwhite); } } - if (rscore || wscore) { - writel (" "); + if (rscore || wscore) { + writel(" "); wrscore(); } - - if (tflag) { + if (tflag) { cline(); - curmove (r,c); + curmove(r, c); } } int quit(void) { - if (tflag) { - curmove (20,0); + if (tflag) { + curmove(20, 0); clend(); } else - writec ('\n'); - writel ("Are you sure you want to quit?"); - if (yorn (0)) { - if (rfl) { - writel ("Would you like to save this game?"); + writec('\n'); + writel("Are you sure you want to quit?"); + if (yorn(0)) { + if (rfl) { + writel("Would you like to save this game?"); if (yorn(0)) save(0); } @@ -252,28 +246,28 @@ quit(void) int yorn(char special) { - char c; - int i; + char c; + int i; i = 1; - while ( (c = readc()) != 'Y' && c != 'N') { + while ((c = readc()) != 'Y' && c != 'N') { if (special && c == special) return (2); - if (i) { - if (special) { - writel (" (Y, N, or "); - writec (special); - writec (')'); + if (i) { + if (special) { + writel(" (Y, N, or "); + writec(special); + writec(')'); } else - writel (" (Y or N)"); + writel(" (Y or N)"); i = 0; } else - writec ('\007'); + writec('\007'); } if (c == 'Y') - writel (" Yes.\n"); + writel(" Yes.\n"); else - writel (" No.\n"); + writel(" No.\n"); if (tflag) buflush(); return (c == 'Y'); @@ -282,21 +276,21 @@ yorn(char special) void wrhit(int i) { - writel ("Blot hit on "); - wrint (i); - writec ('.'); - writec ('\n'); + writel("Blot hit on "); + wrint(i); + writec('.'); + writec('\n'); } void nexturn(void) { - int c; + int c; cturn = -cturn; - c = cturn/abs(cturn); + c = cturn / abs(cturn); home = bar; - bar = 25-bar; + bar = 25 - bar; offptr += c; offopp -= c; inptr += c; @@ -308,21 +302,20 @@ nexturn(void) void getarg(int argc, char **argv) { - char ch; + char ch; int i; - /* process arguments here. dashes are ignored, nbrw are ignored - if the game is being recovered */ - - while ((ch = getopt (argc, argv, "nbrwp:t:s:h")) != -1) { - switch (ch) { + /* process arguments here. dashes are ignored, nbrw are ignored if + * the game is being recovered */ + while ((ch = getopt(argc, argv, "nbrwp:t:s:h")) != -1) { + switch (ch) { /* don't ask if rules or instructions needed */ case 'n': if (rflag) break; aflag = 0; - args[acnt++] = strdup ("-n"); + args[acnt++] = strdup("-n"); break; /* player is both red and white */ @@ -331,7 +324,7 @@ getarg(int argc, char **argv) break; pnum = 0; aflag = 0; - args[acnt++] = strdup ("-b"); + args[acnt++] = strdup("-b"); break; /* player is red */ @@ -340,7 +333,7 @@ getarg(int argc, char **argv) break; pnum = -1; aflag = 0; - args[acnt++] = strdup ("-r"); + args[acnt++] = strdup("-r"); break; /* player is white */ @@ -349,14 +342,15 @@ getarg(int argc, char **argv) break; pnum = 1; aflag = 0; - args[acnt++] = strdup ("-w"); + args[acnt++] = strdup("-w"); break; /* print board after move according to following character */ case 'p': - if (optarg[0] != 'r' && optarg[0] != 'w' && optarg[0] != 'b') + if (optarg[0] != 'r' && optarg[0] != 'w' && + optarg[0] != 'b') break; - args[acnt] = strdup ("-p "); + args[acnt] = strdup("-p "); args[acnt++][2] = optarg[0]; if (optarg[0] == 'r') bflag = 1; @@ -367,30 +361,31 @@ getarg(int argc, char **argv) break; case 't': - tflag = getcaps (optarg); + tflag = getcaps(optarg); break; case 's': /* recover file */ - recover (optarg); + recover(optarg); break; case 'h': for (i = 0; descr[i] != 0; i++) - puts (descr[i]); + puts(descr[i]); getout(); } } argc -= optind; argv += optind; - if ( argc && argv[0][0] != '\0' ) + if (argc && argv[0][0] != '\0') recover(argv[0]); } void init(void) { - int i; - for (i = 0; i < 26;) + int i; + + for (i = 0; i < 26; ) board[i++] = 0; board[1] = 2; board[6] = board[13] = -5; @@ -407,14 +402,14 @@ init(void) void wrscore(void) { - writel ("Score: "); - writel (color[1]); - writec (' '); - wrint (rscore); - writel (", "); - writel (color[0]); - writec (' '); - wrint (wscore); + writel("Score: "); + writel(color[1]); + writec(' '); + wrint(rscore); + writel(", "); + writel(color[0]); + writec(' '); + wrint(wscore); } void @@ -424,7 +419,7 @@ fixtty(int mode) newpos(); buflush(); tty.c_lflag = mode; - if (tcsetattr (0,TCSANOW,&tty) < 0) + if (tcsetattr(0, TCSANOW, &tty) < 0) errexit("fixtty"); } @@ -432,61 +427,61 @@ void getout(void) { /* go to bottom of screen */ - if (tflag) { - curmove (23,0); + if (tflag) { + curmove(23, 0); cline(); } else - writec ('\n'); + writec('\n'); /* fix terminal status */ - fixtty (old); + fixtty(old); exit(0); } void roll(void) { - char c; - int row; - int col; + char c; + int row; + int col; - if (iroll) { + if (iroll) { row = curr; col = curc; - if (tflag) { - curmove (17,0); - } else - writec ('\n'); - writel ("ROLL: "); + if (tflag) + curmove(17, 0); + else + writec('\n'); + writel("ROLL: "); c = readc(); - if (c != '\n') { + if (c != '\n') { while (c < '1' || c > '6') c = readc(); - D0 = c-'0'; - writec (' '); - writec (c); + D0 = c - '0'; + writec(' '); + writec(c); c = readc(); while (c < '1' || c > '6') c = readc(); - D1 = c-'0'; - writec (' '); - writec (c); - if (tflag) { - curmove (17,0); + D1 = c - '0'; + writec(' '); + writec(c); + if (tflag) { + curmove(17, 0); cline(); - curmove (row,col); + curmove(row, col); } else - writec ('\n'); + writec('\n'); return; } - if (tflag) { - curmove (17,0); + if (tflag) { + curmove(17, 0); cline(); - curmove (row,col); + curmove(row, col); } else - writec ('\n'); + writec('\n'); } - D0 = rnum(6)+1; - D1 = rnum(6)+1; + D0 = rnum(6) + 1; + D1 = rnum(6) + 1; d0 = 0; } diff --git a/games/backgammon/common_source/table.c b/games/backgammon/common_source/table.c index 7635023eac..c0e096ad09 100644 --- a/games/backgammon/common_source/table.c +++ b/games/backgammon/common_source/table.c @@ -1,4 +1,4 @@ -/* +/*- * Copyright (c) 1980, 1993 * The Regents of the University of California. All rights reserved. * @@ -10,11 +10,7 @@ * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. - * 4. Neither the name of the University nor the names of its contributors + * 3. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * @@ -53,7 +49,7 @@ struct state { int newst; }; -static const struct state atmata[] = { +static const struct state atmata[] = { {'R', 1, 0}, {'?', 7, 0}, {'Q', 0, -3}, {'B', 8, 25}, {'9', 2, 25}, {'8', 2, 25}, {'7', 2, 25}, {'6', 2, 25}, @@ -80,16 +76,16 @@ static const struct state atmata[] = { int checkmove(int ist) { - int j, n; - char c; + int j, n; + char c; domove: - if (ist == 0) { + if (ist == 0) { if (tflag) - curmove (curr,32); + curmove(curr, 32); else - writel ("\t\t"); - writel ("Move: "); + writel("\t\t"); + writel("Move: "); } ist = mvl = ncin = 0; for (j = 0; j < 5; j++) @@ -98,32 +94,31 @@ domove: dochar: c = readc(); - if (c == 'S') { + if (c == 'S') { raflag = 0; - save (1); - if (tflag) { - curmove (cturn == -1? 18: 19,39); + save(1); + if (tflag) { + curmove(cturn == -1 ? 18 : 19, 39); ist = -1; goto domove; - } else { - proll (); + } else { + proll(); ist = 0; goto domove; } } - - if (c == tty.c_cc[VERASE] && ncin > 0) { + if (c == tty.c_cc[VERASE] && ncin > 0) { if (tflag) - curmove (curr,curc-1); - else { + curmove(curr, curc - 1); + else { if (tty.c_cc[VERASE] == '\010') - writel ("\010 \010"); + writel("\010 \010"); else - writec (cin[ncin-1]); + writec(cin[ncin - 1]); } ncin--; n = rsetbrd(); - if (n == 0) { + if (n == 0) { n = -1; if (tflag) refresh(); @@ -132,108 +127,103 @@ dochar: goto dochar; goto domove; } - - if (c == tty.c_cc[VKILL] && ncin > 0) { - if (tflag) { + if (c == tty.c_cc[VKILL] && ncin > 0) { + if (tflag) { refresh(); - curmove (curr,39); - ist = -1; - goto domove; - } else if (tty.c_cc[VERASE] == '\010') { - for (j = 0; j < ncin; j++) - writel ("\010 \010"); + curmove(curr, 39); ist = -1; goto domove; - } else { - writec ('\\'); - writec ('\n'); - proll (); - ist = 0; - goto domove; - } + } else + if (tty.c_cc[VERASE] == '\010') { + for (j = 0; j < ncin; j++) + writel("\010 \010"); + ist = -1; + goto domove; + } else { + writec('\\'); + writec('\n'); + proll(); + ist = 0; + goto domove; + } } - - n = dotable(c,ist); - if (n >= 0) { + n = dotable(c, ist); + if (n >= 0) { cin[ncin++] = c; if (n > 2) - if ((! tflag) || c != '\n') - writec (c); + if ((!tflag) || c != '\n') + writec(c); ist = n; if (n) goto dochar; else goto domove; } - if (n == -1 && mvl >= mvlim) - return(0); - if (n == -1 && mvl < mvlim-1) - return(-4); + return (0); + if (n == -1 && mvl < mvlim - 1) + return (-4); - if (n == -6) { - if (! tflag) { - if (movokay(mvl+1)) { + if (n == -6) { + if (!tflag) { + if (movokay(mvl + 1)) { wrboard(); - movback (mvl+1); + movback(mvl + 1); } - proll (); - writel ("\t\tMove: "); - for (j = 0; j < ncin;) - writec (cin[j++]); - } else { - if (movokay(mvl+1)) { + proll(); + writel("\t\tMove: "); + for (j = 0; j < ncin; ) + writec(cin[j++]); + } else { + if (movokay(mvl + 1)) { refresh(); - movback (mvl+1); + movback(mvl + 1); } else - curmove (cturn == -1? 18:19,ncin+39); + curmove(cturn == -1 ? 18 : 19, ncin + 39); } ist = n = rsetbrd(); goto dochar; } - if (n != -5) - return(n); - writec ('\007'); + return (n); + writec('\007'); goto dochar; } static int dotable(char c, int i) { - int a; - int test; + int a, test; test = (c == 'R'); - while ( (a = atmata[i].ch) != '.') { - if (a == c || (test && a == '\n')) { - switch (atmata[i].fcode) { - + while ((a = atmata[i].ch) != '.') { + if (a == c || (test && a == '\n')) { + switch (atmata[i].fcode) { case 1: wrboard(); - if (tflag) { - curmove (cturn == -1? 18: 19,0); - proll (); - writel ("\t\t"); + if (tflag) { + curmove(cturn == -1 ? 18 : 19, 0); + proll(); + writel("\t\t"); } else - proll (); + proll(); break; case 2: if (p[mvl] == -1) - p[mvl] = c-'0'; + p[mvl] = c - '0'; else - p[mvl] = p[mvl]*10+c-'0'; + p[mvl] = p[mvl] * 10 + c - '0'; break; case 3: - if (g[mvl] != -1) { + if (g[mvl] != -1) { if (mvl < mvlim) mvl++; - p[mvl] = p[mvl-1]; + p[mvl] = p[mvl - 1]; } - g[mvl] = p[mvl]+cturn*(c-'0'); + g[mvl] = p[mvl] + cturn * (c - '0'); if (g[mvl] < 0) g[mvl] = 0; if (g[mvl] > 25) @@ -242,15 +232,15 @@ dotable(char c, int i) case 4: if (g[mvl] == -1) - g[mvl] = c-'0'; + g[mvl] = c - '0'; else - g[mvl] = g[mvl]*10+c-'0'; + g[mvl] = g[mvl] * 10 + c - '0'; break; case 5: if (mvl < mvlim) mvl++; - p[mvl] = g[mvl-1]; + p[mvl] = g[mvl - 1]; break; case 6: @@ -260,16 +250,16 @@ dotable(char c, int i) case 7: if (tflag) - curmove (20,0); + curmove(20, 0); else - writec ('\n'); - text (help2); - if (tflag) { - curmove (cturn == -1? 18: 19,39); - } else { - writec ('\n'); + writec('\n'); + text(help2); + if (tflag) + curmove(cturn == -1 ? 18 : 19, 39); + else { + writec('\n'); proll(); - writel ("\t\tMove: "); + writel("\t\tMove: "); } break; @@ -281,12 +271,11 @@ dotable(char c, int i) g[mvl] = home; } - if (! test || a != '\n') + if (!test || a != '\n') return (atmata[i].newst); else return (-6); } - i++; } @@ -296,7 +285,7 @@ dotable(char c, int i) static int rsetbrd(void) { - int i, j, n; + int i, j, n; n = 0; mvl = 0; @@ -304,6 +293,6 @@ rsetbrd(void) p[i] = g[i] = -1; for (j = 0; j < ncin; j++) if ((n = dotable(cin[j], n)) < 0) - return n; + return (n); return (n); } diff --git a/games/backgammon/teachgammon/data.c b/games/backgammon/teachgammon/data.c index 4ff61af507..dbc93cd529 100644 --- a/games/backgammon/teachgammon/data.c +++ b/games/backgammon/teachgammon/data.c @@ -1,4 +1,4 @@ -/* +/*- * Copyright (c) 1980, 1993 * The Regents of the University of California. All rights reserved. * @@ -10,11 +10,7 @@ * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. - * 4. Neither the name of the University nor the names of its contributors + * 3. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * @@ -215,7 +211,7 @@ const char *const text23[] = { 0 }; -const struct situatn test[] = { +const struct situatn test[] = { { {0,2,0,0,0,0,-5,0,-3,0,0,0,5,-5,0,0,0,3,0,5,0,0,0,0,-2,0}, 3, 1, {8,6,0,0}, {5,5,0,0}, 4, 2, {text0} diff --git a/games/backgammon/teachgammon/teach.c b/games/backgammon/teachgammon/teach.c index 0bb3fc6a8f..b6d60ca9ed 100644 --- a/games/backgammon/teachgammon/teach.c +++ b/games/backgammon/teachgammon/teach.c @@ -1,4 +1,4 @@ -/* +/*- * Copyright (c) 1980, 1993 * The Regents of the University of California. All rights reserved. * @@ -10,11 +10,7 @@ * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. - * 4. Neither the name of the University nor the names of its contributors + * 3. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * @@ -60,34 +56,33 @@ const char *const contin[] = { int main(int argc, char **argv) { - int i; + int i; /* revoke privs */ setgid(getgid()); acnt = 1; - signal (SIGINT,(sig_t)getout); - if (tcgetattr (0,&tty) == -1) /* get old tty mode */ - errexit ("teachgammon(tcgetattr)"); + signal(SIGINT, (sig_t)getout); + if (tcgetattr(0, &tty) == -1) /* get old tty mode */ + errexit("teachgammon(tcgetattr)"); old = tty.c_lflag; - raw = ((noech = old & ~ECHO) & ~ICANON); /* set up modes */ - ospeed = cfgetospeed(&tty); /* for termlib */ - tflag = getcaps (getenv ("TERM")); - getarg (argc, argv); - if (tflag) { - noech &= ~(ICRNL|OXTABS); - raw &= ~(ICRNL|OXTABS); + raw = ((noech = old & ~ECHO) & ~ICANON); /* set up modes */ + ospeed = cfgetospeed(&tty); /* for termlib */ + tflag = getcaps(getenv("TERM")); + getarg(argc, argv); + if (tflag) { + noech &= ~(ICRNL | OXTABS); + raw &= ~(ICRNL | OXTABS); clear(); } - text (hello); - text (list); - i = text (contin); + text(hello); + text(list); + i = text(contin); if (i == 0) i = 2; init(); while (i) - switch (i) { - + switch (i) { case 1: leave(); @@ -132,24 +127,25 @@ main(int argc, char **argv) } tutor(); /* NOTREACHED */ - return(0); + return (0); } void leave(void) { int i; + if (tflag) clear(); else - writec ('\n'); + writec('\n'); fixtty(old); args[0] = strdup("backgammon"); args[acnt++] = strdup("-n"); args[acnt] = 0; - execv (EXEC,args); + execv(EXEC, args); for (i = 0; i < acnt; i++) - free (args[i]); - writel ("Help! Backgammon program is missing\007!!\n"); - exit (-1); + free(args[i]); + writel("Help! Backgammon program is missing\007!!\n"); + exit(-1); } diff --git a/games/backgammon/teachgammon/ttext1.c b/games/backgammon/teachgammon/ttext1.c index 85f9e9437c..dfa2027db9 100644 --- a/games/backgammon/teachgammon/ttext1.c +++ b/games/backgammon/teachgammon/ttext1.c @@ -1,4 +1,4 @@ -/* +/*- * Copyright (c) 1980, 1993 * The Regents of the University of California. All rights reserved. * @@ -10,11 +10,7 @@ * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. - * 4. Neither the name of the University nor the names of its contributors + * 3. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * diff --git a/games/backgammon/teachgammon/ttext2.c b/games/backgammon/teachgammon/ttext2.c index 6a456d5635..cddec42338 100644 --- a/games/backgammon/teachgammon/ttext2.c +++ b/games/backgammon/teachgammon/ttext2.c @@ -1,4 +1,4 @@ -/* +/*- * Copyright (c) 1980, 1993 * The Regents of the University of California. All rights reserved. * @@ -10,11 +10,7 @@ * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. - * 4. Neither the name of the University nor the names of its contributors + * 3. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * @@ -127,67 +123,68 @@ const char *const lastch[] = { int text(const char *const *txt) { - const char *const *begin; - const char *a; - char b; - const char *c; - int i; + const char *const *begin; + const char *a; + char b; + const char *c; + int i; - fixtty (noech); + fixtty(noech); begin = txt; - while (*txt) { + while (*txt) { a = *(txt++); - if (*a != '\0') { + if (*a != '\0') { c = a; - for (i = 0; *(c++) != '\0'; i--); - writel (a); - writec ('\n'); - } else { - fixtty (raw); - writel (prompt); - for (;;) { - if ((b = readc()) == '?') { - if (tflag) { - if (begscr) { - curmove (18,0); + for (i = 0; *(c++) != '\0'; i--) + ; /* nothing */ + writel(a); + writec('\n'); + } else { + fixtty(raw); + writel(prompt); + for (;;) { + if ((b = readc()) == '?') { + if (tflag) { + if (begscr) { + curmove(18, 0); clend(); } else clear(); } else - writec ('\n'); - text (list); - writel (prompt); + writec('\n'); + text(list); + writel(prompt); continue; } i = 0; if (b == '\n') break; - while (i < 11) { + while (i < 11) { if (b == opts[i]) break; i++; } if (i == 11) - writec ('\007'); + writec('\007'); else break; } - if (tflag) { - if (begscr) { - curmove (18,0); + if (tflag) { + if (begscr) { + curmove(18, 0); clend(); } else clear(); } else - writec ('\n'); + writec('\n'); if (i) - return(i); - fixtty (noech); + return (i); + fixtty(noech); if (tflag) - curmove (curr,0); + curmove(curr, 0); begin = txt; } } - fixtty (raw); + fixtty(raw); return (0); } diff --git a/games/backgammon/teachgammon/tutor.c b/games/backgammon/teachgammon/tutor.c index f45155d34f..c4de5923aa 100644 --- a/games/backgammon/teachgammon/tutor.c +++ b/games/backgammon/teachgammon/tutor.c @@ -1,4 +1,4 @@ -/* +/*- * Copyright (c) 1980, 1993 * The Regents of the University of California. All rights reserved. * @@ -10,11 +10,7 @@ * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. - * 4. Neither the name of the University nor the names of its contributors + * 3. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * @@ -41,12 +37,12 @@ static void clrest(void); static int brdeq(const int *, const int *); -static const char better[] = "That is a legal move, but there is a better one.\n"; +static const char better[] = "That is a legal move, but there is a better one.\n"; void tutor(void) { - int i, j; + int i, j; i = 0; begscr = 18; @@ -62,40 +58,39 @@ tutor(void) colen = 5; wrboard(); - while (1) { - if (! brdeq(test[i].brd,board)) { + while (1) { + if (!brdeq(test[i].brd, board)) { if (tflag && curr == 23) - curmove (18,0); - writel (better); + curmove(18, 0); + writel(better); nexturn(); - movback (mvlim); - if (tflag) { + movback(mvlim); + if (tflag) { refresh(); - clrest (); + clrest(); } - if ((! tflag) || curr == 19) { + if ((!tflag) || curr == 19) { proll(); - writec ('\t'); - } - else - curmove (curr > 19? curr-2: curr+4,25); + writec('\t'); + } else + curmove(curr > 19 ? curr - 2 : curr + 4, 25); getmove(); if (cturn == 0) leave(); continue; } if (tflag) - curmove (18,0); - text (*test[i].com); - if (! tflag) - writec ('\n'); + curmove(18, 0); + text(*test[i].com); + if (!tflag) + writec('\n'); if (i == maxmoves) break; D0 = test[i].roll1; D1 = test[i].roll2; d0 = 0; mvlim = 0; - for (j = 0; j < 4; j++) { + for (j = 0; j < 4; j++) { if (test[i].mp[j] == test[i].mg[j]) break; p[j] = test[i].mp[j]; @@ -105,7 +100,7 @@ tutor(void) if (mvlim) for (j = 0; j < mvlim; j++) if (makmove(j)) - writel ("AARGH!!!\n"); + writel("AARGH!!!\n"); if (tflag) refresh(); nexturn(); @@ -114,7 +109,7 @@ tutor(void) d0 = 0; i++; mvlim = movallow(); - if (mvlim) { + if (mvlim) { if (tflag) clrest(); proll(); @@ -132,25 +127,25 @@ tutor(void) static void clrest(void) { - int r, c, j; + int r, c, j; r = curr; c = curc; - for (j = r+1; j < 24; j++) { - curmove (j,0); + for (j = r + 1; j < 24; j++) { + curmove(j, 0); cline(); } - curmove (r,c); + curmove(r, c); } static int brdeq(const int *b1, const int *b2) { - const int *e; + const int *e; - e = b1+26; + e = b1 + 26; while (b1 < e) if (*b1++ != *b2++) - return(0); - return(1); + return (0); + return (1); } diff --git a/games/backgammon/teachgammon/tutor.h b/games/backgammon/teachgammon/tutor.h index 6cacdd5202..962d6e36f2 100644 --- a/games/backgammon/teachgammon/tutor.h +++ b/games/backgammon/teachgammon/tutor.h @@ -1,4 +1,4 @@ -/* +/*- * Copyright (c) 1980, 1993 * The Regents of the University of California. All rights reserved. * @@ -10,11 +10,7 @@ * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. - * 4. Neither the name of the University nor the names of its contributors + * 3. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * diff --git a/games/battlestar/battlestar.6 b/games/battlestar/battlestar.6 index b131cd3e7d..ddd4e82170 100644 --- a/games/battlestar/battlestar.6 +++ b/games/battlestar/battlestar.6 @@ -9,11 +9,7 @@ .\" 2. Redistributions in binary form must reproduce the above copyright .\" notice, this list of conditions and the following disclaimer in the .\" documentation and/or other materials provided with the distribution. -.\" 3. All advertising materials mentioning features or use of this software -.\" must display the following acknowledgement: -.\" This product includes software developed by the University of -.\" California, Berkeley and its contributors. -.\" 4. Neither the name of the University nor the names of its contributors +.\" 3. Neither the name of the University nor the names of its contributors .\" may be used to endorse or promote products derived from this software .\" without specific prior written permission. .\" diff --git a/games/battlestar/battlestar.c b/games/battlestar/battlestar.c index e78ec59001..48594fdd09 100644 --- a/games/battlestar/battlestar.c +++ b/games/battlestar/battlestar.c @@ -1,4 +1,4 @@ -/* +/*- * Copyright (c) 1983, 1993 * The Regents of the University of California. All rights reserved. * @@ -10,11 +10,7 @@ * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. - * 4. Neither the name of the University nor the names of its contributors + * 3. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * @@ -51,9 +47,8 @@ main(int argc, char **argv) char mainbuf[LINELENGTH]; char *next; + /* Open the score file then revoke setgid privileges */ open_score_file(); - - /* revoke privs. */ setgid(getgid()); initialize(argc < 2 || strcmp(argv[1], "-r")); @@ -61,12 +56,12 @@ start: news(); beenthere[position]++; if (notes[LAUNCHED]) - crash(); /* decrements fuel & crash */ + crash(); /* decrements fuel & crash */ if (matchlight) { puts("Your match splutters out."); matchlight = 0; } - if (!notes[CANTSEE] || testbit(inven,LAMPON) || + if (!notes[CANTSEE] || testbit(inven, LAMPON) || testbit(location[position].objects, LAMPON)) { writedes(); printobjs(); @@ -75,17 +70,17 @@ start: whichway(location[position]); run: next = getcom(mainbuf, sizeof mainbuf, ">-: ", - "Please type in something."); + "Please type in something."); for (wordcount = 0; next && wordcount < 20; wordcount++) next = getword(next, words[wordcount], -1); parse(); switch (cypher()) { - case -1: - goto run; - case 0: - goto start; - default: - exit(1); /* Shouldn't happen */ + case -1: + goto run; + case 0: + goto start; + default: + exit(1); /* Shouldn't happen */ } - return(1); + return (1); } diff --git a/games/battlestar/com1.c b/games/battlestar/com1.c index b3d086e07a..b1978ba2b9 100644 --- a/games/battlestar/com1.c +++ b/games/battlestar/com1.c @@ -1,4 +1,4 @@ -/* +/*- * Copyright (c) 1983, 1993 * The Regents of the University of California. All rights reserved. * @@ -10,11 +10,7 @@ * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. - * 4. Neither the name of the University nor the names of its contributors + * 3. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * @@ -37,7 +33,7 @@ #include "externs.h" -static void convert(int); +static void convert(int); int battlestar_move(int thataway, int token) @@ -45,23 +41,24 @@ battlestar_move(int thataway, int token) wordnumber++; if ((!notes[CANTMOVE] && !notes[LAUNCHED]) || ((testbit(location[position].objects, LAND) || fuel > 0) && - notes[LAUNCHED])) + notes[LAUNCHED])) { if (thataway) { position = thataway; newway(token); gtime++; - } - else { + } else { puts("You can't go this way."); newway(token); whichway(location[position]); - return(0); + return (0); } - else if (notes[CANTMOVE] && !notes[LAUNCHED]) - puts("You aren't able to move; you better drop something."); - else - puts("You are out of fuel; now you will rot in space forever!"); - return(1); + } else { + if (notes[CANTMOVE] && !notes[LAUNCHED]) + puts("You aren't able to move; you better drop something."); + else + puts("You are out of fuel; now you will rot in space forever!"); + } + return (1); } /* @@ -97,7 +94,7 @@ news(void) int n; int hurt; - if (gtime > 30 && position < 32){ + if (gtime > 30 && position < 32) { puts("An explosion of shuddering magnitude splinters bulkheads and"); puts("ruptures the battlestar's hull. You are sucked out into the"); puts("frozen void of space and killed."); @@ -105,7 +102,7 @@ news(void) } if (gtime > 20 && position < 32) puts("Explosions rock the battlestar."); - if (gtime > snooze){ + if (gtime > snooze) { puts("You drop from exhaustion..."); zzz(); } @@ -132,91 +129,93 @@ news(void) rythmn = gtime - gtime % CYCLE; } if (!wiz && !tempwiz) - if ((testbit(inven,TALISMAN) || testbit(wear,TALISMAN)) && (testbit(inven,MEDALION) || testbit(wear,MEDALION)) && (testbit(inven,AMULET) || testbit(wear,AMULET))){ + if ((testbit(inven, TALISMAN) || testbit(wear, TALISMAN)) && + (testbit(inven, MEDALION) || testbit(wear, MEDALION)) && + (testbit(inven, AMULET) || testbit(wear, AMULET))) { tempwiz = 1; puts("The three amulets glow and reenforce each other in power.\nYou are now a wizard."); + } + if (testbit(location[position].objects, ELF)) { + printf("%s\n", objdes[ELF]); + fight(ELF, rnd(30)); } - if (testbit(location[position].objects,ELF)){ - printf("%s\n",objdes[ELF]); - fight(ELF,rnd(30)); - } - if (testbit(location[position].objects,DARK)){ - printf("%s\n",objdes[DARK]); - fight(DARK,100); + if (testbit(location[position].objects, DARK)) { + printf("%s\n", objdes[DARK]); + fight(DARK, 100); } - if (testbit(location[position].objects,WOODSMAN)){ - printf("%s\n",objdes[WOODSMAN]); - fight(WOODSMAN,50); + if (testbit(location[position].objects, WOODSMAN)) { + printf("%s\n", objdes[WOODSMAN]); + fight(WOODSMAN, 50); } - switch(position){ - - case 267: - case 257: /* entering a cave */ - case 274: - case 246: - notes[CANTSEE] = 1; - break; - case 160: - case 216: /* leaving a cave */ - case 230: - case 231: - case 232: - notes[CANTSEE] = 0; - break; + switch (position) { + case 267: + case 257: /* entering a cave */ + case 274: + case 246: + notes[CANTSEE] = 1; + break; + case 160: + case 216: /* leaving a cave */ + case 230: + case 231: + case 232: + notes[CANTSEE] = 0; + break; } if (testbit(location[position].objects, GIRL)) meetgirl = 1; - if (meetgirl && CYCLE * 1.5 - gtime < 10){ - setbit(location[GARDEN].objects,GIRLTALK); - setbit(location[GARDEN].objects,LAMPON); - setbit(location[GARDEN].objects,ROPE); + if (meetgirl && CYCLE * 1.5 - gtime < 10) { + setbit(location[GARDEN].objects, GIRLTALK); + setbit(location[GARDEN].objects, LAMPON); + setbit(location[GARDEN].objects, ROPE); } - if (position == DOCK && (beenthere[position] || gtime > CYCLE)){ + if (position == DOCK && (beenthere[position] || gtime > CYCLE)) { clearbit(location[DOCK].objects, GIRL); - clearbit(location[DOCK].objects,MAN); + clearbit(location[DOCK].objects, MAN); } - if (meetgirl && gtime - CYCLE * 1.5 > 10){ - clearbit(location[GARDEN].objects,GIRLTALK); - clearbit(location[GARDEN].objects,LAMPON); - clearbit(location[GARDEN].objects,ROPE); + if (meetgirl && gtime - CYCLE * 1.5 > 10) { + clearbit(location[GARDEN].objects, GIRLTALK); + clearbit(location[GARDEN].objects, LAMPON); + clearbit(location[GARDEN].objects, ROPE); meetgirl = 0; } - if (testbit(location[position].objects,CYLON)){ + if (testbit(location[position].objects, CYLON)) { puts("Oh my God, you're being shot at by an alien spacecraft!"); - printf("The targeting computer says we have %d seconds to attack!\n",gclock); + printf("The targeting computer says we have %d seconds to attack!\n", + gclock); fflush(stdout); sleep(1); - if (!visual()){ + if (!visual()) { hurt = rnd(NUMOFINJURIES); injuries[hurt] = 1; puts("Laser blasts sear the cockpit, and the alien veers off in a victory roll."); puts("The viper shudders under a terrible explosion."); - printf("I'm afraid you have suffered %s.\n", ouch[hurt]); - } - else - clearbit(location[position].objects,CYLON); + printf("I'm afraid you have suffered %s.\n", + ouch[hurt]); + } else + clearbit(location[position].objects, CYLON); } - if (injuries[SKULL] && injuries[INCISE] && injuries[NECK]){ + if (injuries[SKULL] && injuries[INCISE] && injuries[NECK]) { puts("I'm afraid you have suffered fatal injuries."); die(0); } - for (n=0; n < NUMOFINJURIES; n++) - if (injuries[n] == 1){ + for (n = 0; n < NUMOFINJURIES; n++) + if (injuries[n] == 1) { injuries[n] = 2; if (WEIGHT > 5) WEIGHT -= 5; else WEIGHT = 0; } - if (injuries[ARM] == 2){ + if (injuries[ARM] == 2) { CUMBER -= 5; injuries[ARM]++; } - if (injuries[RIBS] == 2){ + if (injuries[RIBS] == 2) { CUMBER -= 2; injuries[RIBS]++; } - if (injuries[SPINE] == 2){ + if (injuries[SPINE] == 2) { WEIGHT = 0; injuries[SPINE]++; } @@ -229,15 +228,15 @@ news(void) void crash(void) { - int hurt1,hurt2; + int hurt1, hurt2; fuel--; - if (!location[position].flyhere || (testbit(location[position].objects,LAND) && fuel <= 0)){ + if (!location[position].flyhere || (testbit(location[position].objects, LAND) && fuel <= 0)) { if (!location[position].flyhere) puts("You're flying too low. We're going to crash!"); else{ puts("You're out of fuel. We'll have to crash land!"); - if (!location[position].down){ + if (!location[position].down) { puts("Your viper strikes the ground and explodes into firey fragments."); puts("Thick black smoke billows up from the wreckage."); die(0); @@ -245,8 +244,8 @@ crash(void) position = location[position].down; } notes[LAUNCHED] = 0; - setbit(location[position].objects,CRASH); - gtime += rnd(CYCLE/4); + setbit(location[position].objects, CRASH); + gtime += rnd(CYCLE / 4); puts("The viper explodes into the ground and you lose consciousness..."); zzz(); hurt1 = rnd(NUMOFINJURIES - 2) + 2; @@ -255,6 +254,6 @@ crash(void) injuries[hurt2] = 1; injuries[0] = 1; /* abrasions */ injuries[1] = 1; /* lacerations */ - printf("I'm afraid you have suffered %s and %s.\n",ouch[hurt1],ouch[hurt2]); + printf("I'm afraid you have suffered %s and %s.\n", ouch[hurt1], ouch[hurt2]); } } diff --git a/games/battlestar/com2.c b/games/battlestar/com2.c index 211535ac3b..ca000669c2 100644 --- a/games/battlestar/com2.c +++ b/games/battlestar/com2.c @@ -1,4 +1,4 @@ -/* +/*- * Copyright (c) 1983, 1993 * The Regents of the University of California. All rights reserved. * @@ -10,11 +10,7 @@ * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. - * 4. Neither the name of the University nor the names of its contributors + * 3. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * @@ -44,70 +40,75 @@ wearit(void) /* synonyms = {sheathe, sheath} */ int firstnumber, value; firstnumber = wordnumber; - while(wordtype[++wordnumber] == ADJS); - while(wordnumber <= wordcount){ + while(wordtype[++wordnumber] == ADJS) + ; /* nothing */ + while(wordnumber <= wordcount) { value = wordvalue[wordnumber]; if (value == -1) { puts("Wear what?"); return (firstnumber); } - for (n=0; objsht[value][n]; n++); - switch(value){ - default: - printf("You can't wear%s%s!\n",(objsht[value][n-1] == 's' ? " " : " a "),objsht[value]); - return(firstnumber); + for (n = 0; objsht[value][n]; n++); + switch (value) { + default: + printf("You can't wear%s%s!\n", + (objsht[value][n-1] == 's' ? " " : " a "), objsht[value]); + return(firstnumber); - case KNIFE: - /* case SHIRT: */ - case ROBE: - case LEVIS: /* wearable things */ - case SWORD: - case MAIL: - case HELM: - case SHOES: - case PAJAMAS: - case COMPASS: - case LASER: - case AMULET: - case TALISMAN: - case MEDALION: - case ROPE: - case RING: - case BRACELET: - case GRENADE: + case KNIFE: + /* case SHIRT: */ + case ROBE: + case LEVIS: /* wearable things */ + case SWORD: + case MAIL: + case HELM: + case SHOES: + case PAJAMAS: + case COMPASS: + case LASER: + case AMULET: + case TALISMAN: + case MEDALION: + case ROPE: + case RING: + case BRACELET: + case GRENADE: - if (testbit(inven,value)){ - clearbit(inven,value); - setbit(wear,value); - carrying -= objwt[value]; - encumber -= objcumber[value]; - gtime++; - printf("You are now wearing %s %s.\n",(objsht[value][n-1] == 's' ? "the" : "a"), objsht[value]); - } - else if (testbit(wear,value)) + if (testbit(inven, value)) { + clearbit(inven, value); + setbit(wear, value); + carrying -= objwt[value]; + encumber -= objcumber[value]; + gtime++; + printf("You are now wearing %s %s.\n", + (objsht[value][n-1] == 's' ? "the" : "a"), objsht[value]); + } else { + if (testbit(wear, value)) printf("You are already wearing the %s.\n", objsht[value]); else printf("You aren't holding the %s.\n", objsht[value]); - if (wordnumber < wordcount - 1 && wordvalue[++wordnumber] == AND) - wordnumber++; - else - return(firstnumber); - } /* end switch */ - } /* end while */ + } + if (wordnumber < wordcount - 1 && + wordvalue[++wordnumber] == AND) + wordnumber++; + else + return (firstnumber); + } /* end switch */ + } /* end while */ puts("Don't be ridiculous."); - return(firstnumber); + return (firstnumber); } int put(void) /* synonyms = {buckle, strap, tie} */ { - if (wordvalue[wordnumber + 1] == ON){ + if (wordvalue[wordnumber + 1] == ON) { wordvalue[++wordnumber] = PUTON; - return(cypher()); + return (cypher()); } - if (wordvalue[wordnumber + 1] == DOWN){ + if (wordvalue[wordnumber + 1] == DOWN) { wordvalue[++wordnumber] = DROP; - return(cypher()); + return (cypher()); } puts("I don't understand what you want to put."); return(-1); @@ -117,23 +118,25 @@ put(void) /* synonyms = {buckle, strap, tie} */ int draw(void) /* synonyms = {pull, carry} */ { - return(take(wear)); + return (take(wear)); } int use(void) { - while (wordtype[++wordnumber] == ADJS && wordnumber < wordcount); - if (wordvalue[wordnumber] == AMULET && testbit(inven,AMULET) && position != FINAL){ + while (wordtype[++wordnumber] == ADJS && wordnumber < wordcount) + ; /* nothing */ + if (wordvalue[wordnumber] == AMULET && testbit(inven, AMULET) && + position != FINAL) { puts("The amulet begins to glow."); - if (testbit(inven,MEDALION)){ + if (testbit(inven, MEDALION)) { puts("The medallion comes to life too."); - if (position == 114){ + if (position == 114) { location[position].down = 160; whichway(location[position]); puts("The waves subside and it is possible to descend to the sea cave now."); gtime++; - return(-1); + return (-1); } } puts("A light mist falls over your eyes and the sound of purling water trickles in"); @@ -145,18 +148,17 @@ use(void) gtime++; notes[CANTSEE] = 0; return(0); - } - else if (position == FINAL) + } else if (position == FINAL) puts("The amulet won't work in here."); - else if (wordvalue[wordnumber] == COMPASS && testbit(inven,COMPASS)) - printf("Your compass points %s.\n",truedirec(NORTH,'-')); + else if (wordvalue[wordnumber] == COMPASS && testbit(inven, COMPASS)) + printf("Your compass points %s.\n", truedirec(NORTH, '-')); else if (wordvalue[wordnumber] == COMPASS) puts("You aren't holding the compass."); else if (wordvalue[wordnumber] == AMULET) puts("You aren't holding the amulet."); else puts("There is no apparent use."); - return(-1); + return (-1); } void @@ -164,64 +166,72 @@ murder(void) { int n; - for (n=0; !((n == SWORD || n == KNIFE || n == TWO_HANDED || n == MACE || n == CLEAVER || n == BROAD || n == CHAIN || n == SHOVEL || n == HALBERD) && testbit(inven,n)) && n < NUMOFOBJECTS; n++); - if (n == NUMOFOBJECTS) + for (n = 0; + !((n == SWORD || n == KNIFE || n == TWO_HANDED || n == MACE || + n == CLEAVER || n == BROAD || n == CHAIN || n == SHOVEL || + n == HALBERD) && testbit(inven, n)) && n < NUMOFOBJECTS; + n++); + if (n == NUMOFOBJECTS) { puts("You don't have suitable weapons to kill."); - else { - printf("Your %s should do the trick.\n",objsht[n]); - while (wordtype[++wordnumber] == ADJS); - switch(wordvalue[wordnumber]){ + } else { + printf("Your %s should do the trick.\n", objsht[n]); + while (wordtype[++wordnumber] == ADJS) + ; /* nothing */ + switch (wordvalue[wordnumber]) { + case NORMGOD: + if (testbit(location[position].objects, BATHGOD)) { + puts("The goddess's head slices off. Her corpse floats in the water."); + clearbit(location[position].objects, BATHGOD); + setbit(location[position].objects, DEADGOD); + power += 5; + notes[JINXED]++; + } else if (testbit(location[position].objects, NORMGOD)) { + puts("The goddess pleads but you strike her mercilessly. Her broken body lies in a\npool of blood."); + clearbit(location[position].objects, NORMGOD); + setbit(location[position].objects, DEADGOD); + power += 5; + notes[JINXED]++; + if (wintime) + live(); + } else + puts("I dont see her anywhere."); + break; + case TIMER: + if (testbit(location[position].objects, TIMER)) { + puts("The old man offers no resistance."); + clearbit(location[position].objects, TIMER); + setbit(location[position].objects, DEADTIME); + power++; + notes[JINXED]++; + } else + puts("Who?"); + break; + case NATIVE: + if (testbit(location[position].objects, NATIVE)) { + puts("The girl screams as you cut her body to shreds. She is dead."); + clearbit(location[position].objects, NATIVE); + setbit(location[position].objects, DEADNATIVE); + power += 5; + notes[JINXED]++; + } else + puts("What girl?"); + break; + case MAN: + if (testbit(location[position].objects, MAN)) { + puts("You strike him to the ground, and he coughs up blood."); + puts("Your fantasy is over."); + die(0); + } + case -1: + puts("Kill what?"); + break; - case NORMGOD: - if (testbit(location[position].objects,BATHGOD)){ - puts("The goddess's head slices off. Her corpse floats in the water."); - clearbit(location[position].objects,BATHGOD); - setbit(location[position].objects,DEADGOD); - power += 5; - notes[JINXED]++; - } else if (testbit(location[position].objects,NORMGOD)){ - puts("The goddess pleads but you strike her mercilessly. Her broken body lies in a\npool of blood."); - clearbit(location[position].objects,NORMGOD); - setbit(location[position].objects,DEADGOD); - power += 5; - notes[JINXED]++; - if (wintime) - live(); - } else puts("I dont see her anywhere."); - break; - case TIMER: - if (testbit(location[position].objects,TIMER)){ - puts("The old man offers no resistance."); - clearbit(location[position].objects,TIMER); - setbit(location[position].objects,DEADTIME); - power++; - notes[JINXED]++; - } else puts("Who?"); - break; - case NATIVE: - if (testbit(location[position].objects,NATIVE)){ - puts("The girl screams as you cut her body to shreds. She is dead."); - clearbit(location[position].objects,NATIVE); - setbit(location[position].objects,DEADNATIVE); - power += 5; - notes[JINXED]++; - } else puts("What girl?"); - break; - case MAN: - if (testbit(location[position].objects,MAN)){ - puts("You strike him to the ground, and he coughs up blood."); - puts("Your fantasy is over."); - die(0); - } - case -1: + default: + if (wordtype[wordnumber] != NOUNS) puts("Kill what?"); - break; - - default: - if (wordtype[wordnumber] != NOUNS) - puts("Kill what?"); - else - printf("You can't kill the %s!\n",objsht[wordvalue[wordnumber]]); + else + printf("You can't kill the %s!\n", + objsht[wordvalue[wordnumber]]); } } } @@ -229,75 +239,75 @@ murder(void) void ravage(void) { - while (wordtype[++wordnumber] != NOUNS && wordnumber <= wordcount); - if (wordtype[wordnumber] == NOUNS && testbit(location[position].objects,wordvalue[wordnumber])){ + while (wordtype[++wordnumber] != NOUNS && wordnumber <= wordcount) + ; /* nothing */ + if (wordtype[wordnumber] == NOUNS && + testbit(location[position].objects, wordvalue[wordnumber])) { gtime++; - switch(wordvalue[wordnumber]){ - case NORMGOD: - puts("You attack the goddess, and she screams as you beat her. She falls down"); - puts("crying and tries to hold her torn and bloodied dress around her."); - power += 5; - pleasure += 8; - ego -= 10; - wordnumber--; - godready = -30000; - murder(); - bs_win = -30000; - break; - case NATIVE: - puts("The girl tries to run, but you catch her and throw her down. Her face is"); - puts("bleeding, and she screams as you tear off her clothes."); - power += 3; - pleasure += 5; - ego -= 10; - wordnumber--; - murder(); - if (rnd(100) < 50){ - puts("Her screams have attracted attention. I think we are surrounded."); - setbit(location[ahead].objects,WOODSMAN); - setbit(location[ahead].objects,DEADWOOD); - setbit(location[ahead].objects,MALLET); - setbit(location[back].objects,WOODSMAN); - setbit(location[back].objects,DEADWOOD); - setbit(location[back].objects,MALLET); - setbit(location[left].objects,WOODSMAN); - setbit(location[left].objects,DEADWOOD); - setbit(location[left].objects,MALLET); - setbit(location[right].objects,WOODSMAN); - setbit(location[right].objects,DEADWOOD); - setbit(location[right].objects,MALLET); - } - break; - default: - puts("You are perverted."); + switch (wordvalue[wordnumber]) { + case NORMGOD: + puts("You attack the goddess, and she screams as you beat her. She falls down"); + puts("crying and tries to hold her torn and bloodied dress around her."); + power += 5; + pleasure += 8; + ego -= 10; + wordnumber--; + godready = -30000; + murder(); + bs_win = -30000; + break; + case NATIVE: + puts("The girl tries to run, but you catch her and throw her down. Her face is"); + puts("bleeding, and she screams as you tear off her clothes."); + power += 3; + pleasure += 5; + ego -= 10; + wordnumber--; + murder(); + if (rnd(100) < 50) { + puts("Her screams have attracted attention. I think we are surrounded."); + setbit(location[ahead].objects, WOODSMAN); + setbit(location[ahead].objects, DEADWOOD); + setbit(location[ahead].objects, MALLET); + setbit(location[back].objects, WOODSMAN); + setbit(location[back].objects, DEADWOOD); + setbit(location[back].objects, MALLET); + setbit(location[left].objects, WOODSMAN); + setbit(location[left].objects, DEADWOOD); + setbit(location[left].objects, MALLET); + setbit(location[right].objects, WOODSMAN); + setbit(location[right].objects, DEADWOOD); + setbit(location[right].objects, MALLET); + } + break; + default: + puts("You are perverted."); } - } - else + } else puts("Who?"); } int follow(void) { - if (followfight == gtime){ + if (followfight == gtime) { puts("The Dark Lord leaps away and runs down secret tunnels and corridors."); puts("You chase him through the darkness and splash in pools of water."); puts("You have cornered him. His laser sword extends as he steps forward."); position = FINAL; - fight(DARK,75); - setbit(location[position].objects,TALISMAN); - setbit(location[position].objects,AMULET); - return(0); - } - else if (followgod == gtime){ - puts("The goddess leads you down a steamy tunnel and into a high, wide chamber."); - puts("She sits down on a throne."); - position = 268; - setbit(location[position].objects,NORMGOD); - notes[CANTSEE] = 1; - return(0); - } - else - puts("There is no one to follow."); - return(-1); + fight(DARK, 75); + setbit(location[position].objects, TALISMAN); + setbit(location[position].objects, AMULET); + return (0); + } else + if (followgod == gtime) { + puts("The goddess leads you down a steamy tunnel and into a high, wide chamber."); + puts("She sits down on a throne."); + position = 268; + setbit(location[position].objects, NORMGOD); + notes[CANTSEE] = 1; + return (0); + } else + puts("There is no one to follow."); + return (-1); } diff --git a/games/battlestar/com3.c b/games/battlestar/com3.c index 0dc355cacb..73fbd1b315 100644 --- a/games/battlestar/com3.c +++ b/games/battlestar/com3.c @@ -1,4 +1,4 @@ -/* +/*- * Copyright (c) 1983, 1993 * The Regents of the University of California. All rights reserved. * @@ -10,11 +10,7 @@ * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. - * 4. Neither the name of the University nor the names of its contributors + * 3. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * @@ -40,25 +36,24 @@ void dig(void) { - if (testbit(inven,SHOVEL)){ + if (testbit(inven, SHOVEL)) { puts("OK"); gtime++; - switch(position){ - case 144: /* copse near beach */ - if (!notes[DUG]){ - setbit(location[position].objects,DEADWOOD); - setbit(location[position].objects,COMPASS); - setbit(location[position].objects,KNIFE); - setbit(location[position].objects,MACE); - notes[DUG] = 1; - } - break; + switch (position) { + case 144: /* copse near beach */ + if (!notes[DUG]) { + setbit(location[position].objects, DEADWOOD); + setbit(location[position].objects, COMPASS); + setbit(location[position].objects, KNIFE); + setbit(location[position].objects, MACE); + notes[DUG] = 1; + } + break; - default: - puts("Nothing happens."); + default: + puts("Nothing happens."); } - } - else + } else puts("You don't have a shovel."); } @@ -67,39 +62,39 @@ jump(void) { int n; - switch(position){ - default: - puts("Nothing happens."); - return(-1); + switch (position) { + default: + puts("Nothing happens."); + return (-1); - case 242: - position = 133; - break; - case 214: - case 215: - case 162: - case 159: - position = 145; - break; - case 232: - position = 275; - break; - case 3: - position = 1; - break; - case 172: - position = 201; + case 242: + position = 133; + break; + case 214: + case 215: + case 162: + case 159: + position = 145; + break; + case 232: + position = 275; + break; + case 3: + position = 1; + break; + case 172: + position = 201; } puts("Ahhhhhhh..."); injuries[12] = injuries[8] = injuries[7] = injuries[6] = 1; - for (n=0; n < NUMOFOBJECTS; n++) - if (testbit(inven,n)){ - clearbit(inven,n); - setbit(location[position].objects,n); + for (n = 0; n < NUMOFOBJECTS; n++) + if (testbit(inven, n)) { + clearbit(inven, n); + setbit(location[position].objects, n); } carrying = 0; encumber = 0; - return(0); + return (0); } void @@ -107,62 +102,76 @@ bury(void) { int value; - if (testbit(inven,SHOVEL)){ - while(wordtype[++wordnumber] != OBJECT && wordtype[wordnumber] != NOUNS && wordnumber < wordcount); + if (testbit(inven, SHOVEL)) { + while (wordtype[++wordnumber] != OBJECT && + wordtype[wordnumber] != NOUNS && wordnumber < wordcount) + ; /* nothing */ value = wordvalue[wordnumber]; - if (wordtype[wordnumber] == NOUNS && (testbit(location[position].objects,value) || value == BODY)) - switch(value){ - case BODY: - wordtype[wordnumber] = OBJECT; - if (testbit(inven,MAID) || testbit(location[position].objects,MAID)) - value = MAID; - if (testbit(inven,DEADWOOD) || testbit(location[position].objects,DEADWOOD)) - value = DEADWOOD; - if (testbit(inven,DEADGOD) || testbit(location[position].objects,DEADGOD)) - value = DEADGOD; - if (testbit(inven,DEADTIME) || testbit(location[position].objects,DEADTIME)) - value = DEADTIME; - if (testbit(inven,DEADNATIVE) || testbit(location[position].objects,DEADNATIVE)) - value = DEADNATIVE; - break; + if (wordtype[wordnumber] == NOUNS && + (testbit(location[position].objects, value) || + value == BODY)) + switch (value) { + case BODY: + wordtype[wordnumber] = OBJECT; + if (testbit(inven, MAID) || + testbit(location[position].objects, MAID)) + value = MAID; + if (testbit(inven, DEADWOOD) || + testbit(location[position].objects, + DEADWOOD)) + value = DEADWOOD; + if (testbit(inven, DEADGOD) || + testbit(location[position].objects, + DEADGOD)) + value = DEADGOD; + if (testbit(inven, DEADTIME) || + testbit(location[position].objects, + DEADTIME)) + value = DEADTIME; + if (testbit(inven, DEADNATIVE) || + testbit(location[position].objects, + DEADNATIVE)) + value = DEADNATIVE; + break; - case NATIVE: - case NORMGOD: - puts("She screams as you wrestle her into the hole."); - case TIMER: - power += 7; - ego -= 10; - case AMULET: - case MEDALION: - case TALISMAN: - wordtype[wordnumber] = OBJECT; - break; + case NATIVE: + case NORMGOD: + puts("She screams as you wrestle her into the hole."); + case TIMER: + power += 7; + ego -= 10; + case AMULET: + case MEDALION: + case TALISMAN: + wordtype[wordnumber] = OBJECT; + break; - default: - puts("Wha..?"); + default: + puts("Wha..?"); } - if (wordtype[wordnumber] == OBJECT && position > 88 && (testbit(inven,value) || testbit(location[position].objects,value))){ + if (wordtype[wordnumber] == OBJECT && position > 88 && + (testbit(inven, value) || + testbit(location[position].objects, value))) { puts("Buried."); - if (testbit(inven,value)){ - clearbit(inven,value); + if (testbit(inven, value)) { + clearbit(inven, value); carrying -= objwt[value]; encumber -= objcumber[value]; } - clearbit(location[position].objects,value); - switch(value){ - case MAID: - case DEADWOOD: - case DEADNATIVE: - case DEADTIME: - case DEADGOD: - ego += 2; - printf("The %s should rest easier now.\n",objsht[value]); + clearbit(location[position].objects, value); + switch (value) { + case MAID: + case DEADWOOD: + case DEADNATIVE: + case DEADTIME: + case DEADGOD: + ego += 2; + printf("The %s should rest easier now.\n", + objsht[value]); } - } - else + } else puts("It doesn't seem to work."); - } - else + } else puts("You aren't holding a shovel."); } @@ -171,19 +180,18 @@ drink(void) { int n; - if (testbit(inven,POTION)){ + if (testbit(inven, POTION)) { puts("The cool liquid runs down your throat but turns to fire and you choke."); puts("The heat reaches your limbs and tingles your spirit. You feel like falling"); puts("asleep."); clearbit(inven, POTION); WEIGHT = MAXWEIGHT; CUMBER = MAXCUMBER; - for (n=0; n < NUMOFINJURIES; n++) + for (n = 0; n < NUMOFINJURIES; n++) injuries[n] = 0; gtime++; zzz(); - } - else + } else puts("I'm not thirsty."); } @@ -194,76 +202,86 @@ shoot(void) int n; firstnumber = wordnumber; - if (!testbit(inven,LASER)) + if (!testbit(inven, LASER)) puts("You aren't holding a blaster."); else { - while(wordtype[++wordnumber] == ADJS); - while(wordnumber<=wordcount && wordtype[wordnumber] == OBJECT){ + while (wordtype[++wordnumber] == ADJS) + ; /* nothing */ + while (wordnumber <= wordcount && + wordtype[wordnumber] == OBJECT) { value = wordvalue[wordnumber]; printf("%s:\n", objsht[value]); - for (n=0; objsht[value][n]; n++); - if (testbit(location[position].objects,value)){ - clearbit(location[position].objects,value); + for (n = 0; objsht[value][n]; n++) + ; /* nothing */ + if (testbit(location[position].objects, value)) { + clearbit(location[position].objects, value); gtime++; - printf("The %s explode%s\n",objsht[value],(objsht[value][n-1]=='s' ? (objsht[value][n-2]=='s' ? "s." : ".") : "s.")); + printf("The %s explode%s\n", objsht[value], + (objsht[value][n - 1] == + 's' ? (objsht[value][n - 2] == + 's' ? "s." : ".") : "s.")); if (value == BOMB) die(0); - } - else - printf("I dont see any %s around here.\n", objsht[value]); - if (wordnumber < wordcount - 1 && wordvalue[++wordnumber] == AND) + } else + printf("I dont see any %s around here.\n", + objsht[value]); + if (wordnumber < wordcount - 1 && + wordvalue[++wordnumber] == AND) wordnumber++; else - return(firstnumber); + return (firstnumber); } - /* special cases with their own return()'s */ + /* special cases with their own return()'s */ - if (wordnumber <= wordcount && wordtype[wordnumber] == NOUNS){ + if (wordnumber <= wordcount && wordtype[wordnumber] == NOUNS) { gtime++; - switch(wordvalue[wordnumber]){ - - case DOOR: - switch(position){ - case 189: - case 231: - puts("The door is unhinged."); - location[189].north = 231; - location[231].south = 189; - whichway(location[position]); - break; - case 30: - puts("The wooden door splinters."); - location[30].west = 25; - whichway(location[position]); - break; - case 31: - puts("The laser blast has no effect on the door."); - break; - case 20: - puts("The blast hits the door and it explodes into flame. The magnesium burns"); - puts("so rapidly that we have no chance to escape."); - die(0); - default: - puts("Nothing happens."); - } + switch (wordvalue[wordnumber]) { + case DOOR: + switch (position) { + case 189: + case 231: + puts("The door is unhinged."); + location[189].north = 231; + location[231].south = 189; + whichway(location[position]); break; + case 30: + puts("The wooden door splinters."); + location[30].west = 25; + whichway(location[position]); + break; + case 31: + puts("The laser blast has no effect on the door."); + break; + case 20: + puts("The blast hits the door and it explodes into flame. The magnesium burns"); + puts("so rapidly that we have no chance to escape."); + die(0); + default: + puts("Nothing happens."); + } + break; - case NORMGOD: - if (testbit(location[position].objects,BATHGOD)){ - puts("The goddess is hit in the chest and splashes back against the rocks."); - puts("Dark blood oozes from the charred blast hole. Her naked body floats in the"); - puts("pools and then off downstream."); - clearbit(location[position].objects,BATHGOD); - setbit(location[180].objects,DEADGOD); - power += 5; - ego -= 10; - notes[JINXED]++; - } else if (testbit(location[position].objects,NORMGOD)){ + case NORMGOD: + if (testbit(location[position].objects, + BATHGOD)) { + puts("The goddess is hit in the chest and splashes back against the rocks."); + puts("Dark blood oozes from the charred blast hole. Her naked body floats in the"); + puts("pools and then off downstream."); + clearbit(location[position].objects, + BATHGOD); + setbit(location[180].objects, DEADGOD); + power += 5; + ego -= 10; + notes[JINXED]++; + } else + if (testbit(location[position].objects, + NORMGOD)) { puts("The blast catches the goddess in the stomach, knocking her to the ground."); puts("She writhes in the dirt as the agony of death taunts her."); puts("She has stopped moving."); - clearbit(location[position].objects,NORMGOD); - setbit(location[position].objects,DEADGOD); + clearbit(location[position].objects, NORMGOD); + setbit(location[position].objects, DEADGOD); power += 5; ego -= 10; notes[JINXED]++; @@ -272,46 +290,54 @@ shoot(void) break; } else puts("I don't see any goddess around here."); - break; + break; - case TIMER: - if (testbit(location[position].objects,TIMER)){ - puts("The old man slumps over the bar."); - power++; - ego -= 2; - notes[JINXED]++; - clearbit(location[position].objects,TIMER); - setbit(location[position].objects,DEADTIME); - } - else puts("What old timer?"); - break; - case MAN: - if (testbit(location[position].objects,MAN)){ - puts("The man falls to the ground with blood pouring all over his white suit."); - puts("Your fantasy is over."); - die(0); - } - else puts("What man?"); - break; - case NATIVE: - if (testbit(location[position].objects,NATIVE)){ - puts("The girl is blown backwards several feet and lies in a pool of blood."); - clearbit(location[position].objects,NATIVE); - setbit(location[position].objects,DEADNATIVE); - power += 5; - ego -= 2; - notes[JINXED]++; - } else puts("There is no girl here."); - break; - case -1: - puts("Shoot what?"); - break; + case TIMER: + if (testbit(location[position].objects, + TIMER)) { + puts("The old man slumps over the bar."); + power++; + ego -= 2; + notes[JINXED]++; + clearbit(location[position].objects, + TIMER); + setbit(location[position].objects, + DEADTIME); + } else + puts("What old timer?"); + break; + case MAN: + if (testbit(location[position].objects, MAN)) { + puts("The man falls to the ground with blood pouring all over his white suit."); + puts("Your fantasy is over."); + die(0); + } else + puts("What man?"); + break; + case NATIVE: + if (testbit(location[position].objects, + NATIVE)) { + puts("The girl is blown backwards several feet and lies in a pool of blood."); + clearbit(location[position].objects, + NATIVE); + setbit(location[position].objects, + DEADNATIVE); + power += 5; + ego -= 2; + notes[JINXED]++; + } else + puts("There is no girl here."); + break; + case -1: + puts("Shoot what?"); + break; - default: - printf("You can't shoot the %s.\n",objsht[wordvalue[wordnumber]]); + default: + printf("You can't shoot the %s.\n", + objsht[wordvalue[wordnumber]]); } - } - else puts("You must be a looney."); + } else + puts("You must be a looney."); } - return(firstnumber); + return (firstnumber); } diff --git a/games/battlestar/com4.c b/games/battlestar/com4.c index e0e9947f15..1c529b9714 100644 --- a/games/battlestar/com4.c +++ b/games/battlestar/com4.c @@ -1,4 +1,4 @@ -/* +/*- * Copyright (c) 1983, 1993 * The Regents of the University of California. All rights reserved. * @@ -10,11 +10,7 @@ * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. - * 4. Neither the name of the University nor the names of its contributors + * 3. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * @@ -44,245 +40,260 @@ take(unsigned int from[]) int n; firstnumber = wordnumber; - if (wordnumber < wordcount && wordvalue[wordnumber+1] == OFF){ + if (wordnumber < wordcount && wordvalue[wordnumber + 1] == OFF) { wordnumber++; wordvalue[wordnumber] = TAKEOFF; - return(cypher()); - } - else { - while(wordtype[++wordnumber] == ADJS); - while(wordnumber<=wordcount && wordtype[wordnumber] == OBJECT){ + return (cypher()); + } else { + while (wordtype[++wordnumber] == ADJS) + ; /* nothing */ + while (wordnumber <= wordcount && wordtype[wordnumber] == + OBJECT) { value = wordvalue[wordnumber]; printf("%s:\n", objsht[value]); - for (n=0; objsht[value][n]; n++); + for (n = 0; objsht[value][n]; n++) + ; /* nothing */ heavy = (carrying + objwt[value]) <= WEIGHT; bulky = (encumber + objcumber[value]) <= CUMBER; - if ((testbit(from,value) || wiz || tempwiz) && heavy && bulky && !testbit(inven,value)){ - setbit(inven,value); + if ((testbit(from, value) || wiz || tempwiz) && + heavy && bulky && !testbit(inven, value)) { + setbit(inven, value); carrying += objwt[value]; encumber += objcumber[value]; gtime++; - if (testbit(from,value)) + if (testbit(from, value)) printf("Taken.\n"); else printf("Zap! Taken from thin air.\n"); - clearbit(from,value); + clearbit(from, value); if (value == MEDALION) bs_win--; - } - else if (testbit(inven,value)) - printf("You're already holding%s%s.\n", (objsht[value][n-1] == 's' ? " " : " a "),objsht[value]); + } else if (testbit(inven, value)) + printf("You're already holding%s%s.\n", + (objsht[value][n - 1] == + 's' ? " " : " a "), + objsht[value]); else if (!heavy) - printf("The %s %s too heavy.\n", objsht[value],(objsht[value][n-1] == 's' ? "are" : "is")); + printf("The %s %s too heavy.\n", objsht[value], + (objsht[value][n - 1] == + 's' ? "are" : "is")); else if (!bulky) - printf("The %s %s too cumbersome to hold.\n", objsht[value],(objsht[value][n-1] == 's' ? "are" : "is")); + printf( + "The %s %s too cumbersome to hold.\n", + objsht[value], + (objsht[value][n - 1] == + 's' ? "are" : "is")); else - printf("I dont see any %s around here.\n", objsht[value]); - if (wordnumber < wordcount -1 && wordvalue[++wordnumber] == AND) + printf("I dont see any %s around here.\n", + objsht[value]); + if (wordnumber < wordcount - 1 && + wordvalue[++wordnumber] == AND) wordnumber++; else - return(firstnumber); + return (firstnumber); } } - /* special cases with their own return()'s */ - + /* special cases with their own return()'s */ if (wordnumber <= wordcount && wordtype[wordnumber] == NOUNS) - switch(wordvalue[wordnumber]){ - - case SWORD: - if (testbit(from, SWORD)){ - wordtype[wordnumber--] = OBJECT; - return(take(from)); - } - if (testbit(from, TWO_HANDED)){ - wordvalue[wordnumber] = TWO_HANDED; - wordtype[wordnumber--] = OBJECT; - return(take(from)); - } - wordvalue[wordnumber] = BROAD; + switch (wordvalue[wordnumber]) { + case SWORD: + if (testbit(from, SWORD)) { + wordtype[wordnumber--] = OBJECT; + return (take(from)); + } + if (testbit(from, TWO_HANDED)) { + wordvalue[wordnumber] = TWO_HANDED; wordtype[wordnumber--] = OBJECT; - return(take(from)); + return (take(from)); + } + wordvalue[wordnumber] = BROAD; + wordtype[wordnumber--] = OBJECT; + return (take(from)); - case BODY: - if (testbit(from,MAID)){ - wordvalue[wordnumber] = MAID; - wordtype[wordnumber--] = OBJECT; - return(take(from)); - } - else if (testbit(from,DEADWOOD)){ - wordvalue[wordnumber] = DEADWOOD; - wordtype[wordnumber--] = OBJECT; - return(take(from)); - } - else if (testbit(from,DEADNATIVE)){ - wordvalue[wordnumber] = DEADNATIVE; - wordtype[wordnumber--] = OBJECT; - return(take(from)); - } - else if (testbit(from,DEADGOD)){ + case BODY: + if (testbit(from, MAID)) { + wordvalue[wordnumber] = MAID; + wordtype[wordnumber--] = OBJECT; + return (take(from)); + } else if (testbit(from, DEADWOOD)) { + wordvalue[wordnumber] = DEADWOOD; + wordtype[wordnumber--] = OBJECT; + return (take(from)); + } else if (testbit(from, DEADNATIVE)) { + wordvalue[wordnumber] = DEADNATIVE; + wordtype[wordnumber--] = OBJECT; + return (take(from)); + } else { + if (testbit(from, DEADGOD)) { wordvalue[wordnumber] = DEADGOD; wordtype[wordnumber--] = OBJECT; - return(take(from)); - } - else { + return (take(from)); + } else { wordvalue[wordnumber] = DEADTIME; wordtype[wordnumber--] = OBJECT; - return(take(from)); + return (take(from)); } - break; + } + break; - case AMULET: - if (testbit(location[position].objects,AMULET)){ - puts("The amulet is warm to the touch, and its beauty catches your breath."); - puts("A mist falls over your eyes, but then it is gone. Sounds seem clearer"); - puts("and sharper but far away as if in a dream. The sound of purling water reaches"); - puts("you from afar. The mist falls again, and your heart leaps in horror. The gold"); - puts("freezes your hands and fathomless darkness engulfs your soul."); - } - wordtype[wordnumber--] = OBJECT; - return(take(from)); + case AMULET: + if (testbit(location[position].objects, AMULET)) { + puts("The amulet is warm to the touch, and its beauty catches your breath."); + puts("A mist falls over your eyes, but then it is gone. Sounds seem clearer"); + puts("and sharper but far away as if in a dream. The sound of purling water reaches"); + puts("you from afar. The mist falls again, and your heart leaps in horror. The gold"); + puts("freezes your hands and fathomless darkness engulfs your soul."); + } + wordtype[wordnumber--] = OBJECT; + return (take(from)); - case MEDALION: - if (testbit(location[position].objects, MEDALION)){ - puts("The medallion is warm, and it rekindles your spirit with the warmth of life."); - puts("Your amulet begins to glow as the medallion is brought near to it, and together\nthey radiate."); - } - wordtype[wordnumber--] = OBJECT; - return(take(from)); + case MEDALION: + if (testbit(location[position].objects, MEDALION)) { + puts("The medallion is warm, and it rekindles your spirit with the warmth of life."); + puts("Your amulet begins to glow as the medallion is brought near to it, and together\nthey radiate."); + } + wordtype[wordnumber--] = OBJECT; + return (take(from)); - case TALISMAN: - if (testbit(location[position].objects,TALISMAN)){ - puts("The talisman is cold to the touch, and it sends a chill down your spine."); - } - wordtype[wordnumber--] = OBJECT; - return(take(from)); + case TALISMAN: + if (testbit(location[position].objects, TALISMAN)) + puts("The talisman is cold to the touch, and it sends a chill down your spine."); + wordtype[wordnumber--] = OBJECT; + return (take(from)); - case NORMGOD: - if (testbit(location[position].objects,BATHGOD) && (testbit(wear,AMULET) || testbit(inven,AMULET))){ - puts("She offers a delicate hand, and you help her out of the sparkling springs."); - puts("Water droplets like liquid silver bedew her golden skin, but when they part"); - puts("from her, they fall as teardrops. She wraps a single cloth around her and"); - puts("ties it at the waist. Around her neck hangs a golden amulet."); - puts("She bids you to follow her."); - pleasure++; - followgod = gtime; - clearbit(location[position].objects,BATHGOD); - } else if (!testbit(location[position].objects,BATHGOD)) + case NORMGOD: + if (testbit(location[position].objects, BATHGOD) && + (testbit(wear, AMULET) || testbit(inven, AMULET))) { + puts("She offers a delicate hand, and you help her out of the sparkling springs."); + puts("Water droplets like liquid silver bedew her golden skin, but when they part"); + puts("from her, they fall as teardrops. She wraps a single cloth around her and"); + puts("ties it at the waist. Around her neck hangs a golden amulet."); + puts("She bids you to follow her."); + pleasure++; + followgod = gtime; + clearbit(location[position].objects, BATHGOD); + } else + if (!testbit(location[position].objects, BATHGOD)) puts("You're in no position to take her."); else puts("She moves away from you."); - break; + break; - default: - puts("It doesn't seem to work."); + default: + puts("It doesn't seem to work."); } else puts("You've got to be kidding."); - return(firstnumber); + return (firstnumber); } int throw(const char *name) { - int n; - int deposit = 0; + int n, deposit; int first, value; + deposit = 0; first = wordnumber; - if (drop(name) != -1){ - switch(wordvalue[wordnumber]){ + if (drop(name) != -1) { + switch (wordvalue[wordnumber]) { + case AHEAD: + deposit = ahead; + break; - case AHEAD: - deposit = ahead; - break; + case BACK: + deposit = back; + break; - case BACK: - deposit = back; - break; + case LEFT: + deposit = left; + break; - case LEFT: - deposit = left; - break; + case RIGHT: + deposit = right; + break; - case RIGHT: - deposit = right; - break; + case UP: + deposit = location[position].up * + (location[position].access || position == FINAL); + break; - case UP: - deposit = location[position].up * (location[position].access || position == FINAL); - break; - - case DOWN: - deposit = location[position].down; - break; + case DOWN: + deposit = location[position].down; + break; } wordnumber = first; - while (wordtype[++wordnumber] == ADJS); - while (wordnumber <= wordcount){ + while (wordtype[++wordnumber] == ADJS) + ; /* nothing */ + while (wordnumber <= wordcount) { value = wordvalue[wordnumber]; - if (deposit && testbit(location[position].objects,value)){ - clearbit(location[position].objects,value); + if (deposit && + testbit(location[position].objects, value)) { + clearbit(location[position].objects, value); if (value != GRENADE) - setbit(location[deposit].objects,value); - else{ + setbit(location[deposit].objects, value); + else { puts("A thundering explosion nearby sends up a cloud of smoke and shrapnel."); - for (n = 0; n < NUMOFWORDS; n ++) + for (n = 0; n < NUMOFWORDS; n++) location[deposit].objects[n] = 0; - setbit(location[deposit].objects,CHAR); + setbit(location[deposit].objects, CHAR); } if (value == ROPE && position == FINAL) location[position].access = 1; - switch(deposit){ - case 189: - case 231: - puts("The stone door is unhinged."); - location[189].north = 231; - location[231].south = 189; - break; - case 30: - puts("The wooden door is blown open."); - location[30].west = 25; - break; - case 31: - puts("The door is not damaged."); + switch (deposit) { + case 189: + case 231: + puts("The stone door is unhinged."); + location[189].north = 231; + location[231].south = 189; + break; + case 30: + puts("The wooden door is blown open."); + location[30].west = 25; + break; + case 31: + puts("The door is not damaged."); } - } - else if (value == GRENADE && testbit(location[position].objects,value)){ - puts("You are blown into shreds when your grenade explodes."); - die(0); - } - if (wordnumber < wordcount - 1 && wordvalue[++wordnumber] == AND) + } else + if (value == GRENADE && + testbit(location[position].objects, value)) { + puts("You are blown into shreds when your grenade explodes."); + die(0); + } + if (wordnumber < wordcount - 1 && + wordvalue[++wordnumber] == AND) wordnumber++; else - return(first); + return (first); } - return(first); + return (first); } - return(first); + return (first); } int drop(const char *name) { - int firstnumber, value; firstnumber = wordnumber; while (wordtype[++wordnumber] == ADJS) ; - while (wordnumber<=wordcount && (wordtype[wordnumber] == OBJECT || wordtype[wordnumber] == NOUNS)) { + while (wordnumber <= wordcount && + (wordtype[wordnumber] == OBJECT || wordtype[wordnumber] == NOUNS)) { value = wordvalue[wordnumber]; printf("%s:\n", objsht[value]); - if (testbit(inven,value)){ - clearbit(inven,value); + if (testbit(inven, value)) { + clearbit(inven, value); carrying -= objwt[value]; encumber -= objcumber[value]; - if (value == BOMB){ + if (value == BOMB) { puts("The bomb explodes. A blinding white light and immense concussion obliterate us."); die(0); } - if (value != AMULET && value != MEDALION && value != TALISMAN) - setbit(location[position].objects,value); + if (value != AMULET && value != MEDALION && value != + TALISMAN) + setbit(location[position].objects, value); else tempwiz = 0; gtime++; @@ -290,11 +301,12 @@ drop(const char *name) puts("Drop kicked."); else printf("%s.\n", name); - } - else { + } else { if (*name != 'K') { - printf("You aren't holding the %s.\n", objsht[value]); - if (testbit(location[position].objects,value)) { + printf("You aren't holding the %s.\n", + objsht[value]); + if (testbit(location[position].objects, + value)) { if (*name == 'T') puts("Kicked instead."); else if (*name == 'G') @@ -303,27 +315,28 @@ drop(const char *name) } else puts("Kicked."); } - if (wordnumber < wordcount - 1 && wordvalue[++wordnumber] == AND) + if (wordnumber < wordcount - 1 && + wordvalue[++wordnumber] == AND) wordnumber++; else - return(firstnumber); + return (firstnumber); } puts("Do what?"); - return(-1); + return (-1); } int takeoff(void) { wordnumber = take(wear); - return(drop("Dropped")); + return (drop("Dropped")); } int puton(void) { wordnumber = take(location[position].objects); - return(wearit()); + return (wearit()); } int @@ -332,51 +345,54 @@ eat(void) int firstnumber, value; firstnumber = wordnumber; - while(wordtype[++wordnumber] == ADJS); - while(wordnumber <= wordcount){ + while (wordtype[++wordnumber] == ADJS) + ; /* nothing */ + while (wordnumber <= wordcount) { value = wordvalue[wordnumber]; - switch(value){ + switch (value) { + case -1: + puts("Eat what?"); + return (firstnumber); - case -1: - puts("Eat what?"); - return(firstnumber); + default: + printf("You can't eat%s%s!\n", + wordtype[wordnumber] == OBJECT && + objsht[value] + [strlen(objsht[value]) - 1] == 's' ? + " " : " a ", + words[wordnumber]); + return (firstnumber); - default: - printf("You can't eat%s%s!\n", - wordtype[wordnumber] == OBJECT && - objsht[value] - [strlen(objsht[value]) - 1] == 's' ? - " " : " a ", - words[wordnumber]); - return(firstnumber); + case PAPAYAS: + case PINEAPPLE: + case KIWI: + case COCONUTS: /* eatable things */ + case MANGO: - case PAPAYAS: - case PINEAPPLE: - case KIWI: - case COCONUTS: /* eatable things */ - case MANGO: - - printf("%s:\n",objsht[value]); - if (testbit(inven,value) && gtime > ate - CYCLE && testbit(inven,KNIFE)){ - clearbit(inven,value); - carrying -= objwt[value]; - encumber -= objcumber[value]; - ate = max(gtime,ate) + CYCLE/3; - snooze += CYCLE/10; - gtime++; - puts("Eaten. You can explore a little longer now."); - } - else if (gtime < ate - CYCLE) - puts("You're stuffed."); - else if (!testbit(inven,KNIFE)) - puts("You need a knife."); - else - printf("You aren't holding the %s.\n", objsht[value]); - if (wordnumber < wordcount - 1 && wordvalue[++wordnumber] == AND) - wordnumber++; - else - return(firstnumber); - } /* end switch */ - } /* end while */ - return(firstnumber); + printf("%s:\n", objsht[value]); + if (testbit(inven, value) && + gtime > ate - CYCLE && + testbit(inven, KNIFE)) { + clearbit(inven, value); + carrying -= objwt[value]; + encumber -= objcumber[value]; + ate = max(gtime, ate) + CYCLE / 3; + snooze += CYCLE / 10; + gtime++; + puts("Eaten. You can explore a little longer now."); + } else if (gtime < ate - CYCLE) + puts("You're stuffed."); + else if (!testbit(inven, KNIFE)) + puts("You need a knife."); + else + printf("You aren't holding the %s.\n", + objsht[value]); + if (wordnumber < wordcount - 1 && + wordvalue[++wordnumber] == AND) + wordnumber++; + else + return (firstnumber); + } /* end switch */ + } /* end while */ + return (firstnumber); } diff --git a/games/battlestar/com5.c b/games/battlestar/com5.c index 4e23fdd78c..84c4ed992f 100644 --- a/games/battlestar/com5.c +++ b/games/battlestar/com5.c @@ -1,4 +1,4 @@ -/* +/*- * Copyright (c) 1983, 1993 * The Regents of the University of California. All rights reserved. * @@ -10,11 +10,7 @@ * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. - * 4. Neither the name of the University nor the names of its contributors + * 3. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * @@ -40,41 +36,42 @@ void kiss(void) { - while (wordtype[++wordnumber] != NOUNS && wordnumber <= wordcount); - if (wordtype[wordnumber] == NOUNS && testbit(location[position].objects,wordvalue[wordnumber])){ + while (wordtype[++wordnumber] != NOUNS && wordnumber <= wordcount) + ; /* nothing */ + if (wordtype[wordnumber] == NOUNS && testbit(location[position].objects, wordvalue[wordnumber])) { pleasure++; printf("Kissed.\n"); - switch (wordvalue[wordnumber]){ - case NORMGOD: - switch(godready++){ - case 0: - puts("She squirms and avoids your advances."); - break; - case 1: - puts("She is coming around; she didn't fight it as much."); - break; - case 2: - puts("She's beginning to like it."); - break; - default: - puts("She's gone limp."); - - } - break; - case NATIVE: - puts("The lips are warm and her body robust. She pulls you down to the ground."); + switch (wordvalue[wordnumber]) { + case NORMGOD: + switch (godready++) { + case 0: + puts("She squirms and avoids your advances."); break; - case TIMER: - puts("The old man blushes."); + case 1: + puts("She is coming around; she didn't fight it as much."); break; - case MAN: - puts("The dwarf punches you in the kneecap."); + case 2: + puts("She's beginning to like it."); break; default: - pleasure--; + puts("She's gone limp."); + + } + break; + case NATIVE: + puts("The lips are warm and her body robust. She pulls you down to the ground."); + break; + case TIMER: + puts("The old man blushes."); + break; + case MAN: + puts("The dwarf punches you in the kneecap."); + break; + default: + pleasure--; } - } - else puts("I'd prefer not to."); + } else + puts("I'd prefer not to."); } void @@ -82,35 +79,36 @@ love(void) { int n; - while (wordtype[++wordnumber] != NOUNS && wordnumber <= wordcount); - if (wordtype[wordnumber] == NOUNS && testbit(location[position].objects,wordvalue[wordnumber])){ + while (wordtype[++wordnumber] != NOUNS && wordnumber <= wordcount) + ; /* nothing */ + if (wordtype[wordnumber] == NOUNS && + testbit(location[position].objects, wordvalue[wordnumber])) { if (wordvalue[wordnumber] == NORMGOD && !loved) { - if (godready >= 2){ + if (godready >= 2) { puts("She cuddles up to you, and her mouth starts to work:\n'That was my sister's amulet. The lovely goddess, Purl, was she. The Empire\ncaptured her just after the Darkness came. My other sister, Vert, was killed\nby the Dark Lord himself. He took her amulet and warped its power.\nYour quest was foretold by my father before he died, but to get the Dark Lord's\namulet you must use cunning and skill. I will leave you my amulet."); puts("which you may use as you wish. As for me, I am the last goddess of the\nwaters. My father was the Island King, and the rule is rightfully mine.'\n\nShe pulls the throne out into a large bed."); power++; pleasure += 15; ego++; - if (card(injuries, NUMOFINJURIES)){ + if (card(injuries, NUMOFINJURIES)) { puts("Her kisses revive you; your wounds are healed.\n"); - for (n=0; n < NUMOFINJURIES; n++) + for (n = 0; n < NUMOFINJURIES; n++) injuries[n] = 0; WEIGHT = MAXWEIGHT; CUMBER = MAXCUMBER; } printf("Goddess:\n"); if (!loved) - setbit(location[position].objects,MEDALION); + setbit(location[position].objects, MEDALION); loved = 1; gtime += 10; zzz(); - } - else { + } else { puts("You wish!"); return; } } - if (wordvalue[wordnumber] == NATIVE){ + if (wordvalue[wordnumber] == NATIVE) { puts("The girl is easy prey. She peels off her sarong and indulges you."); power++; pleasure += 5; @@ -119,8 +117,8 @@ love(void) zzz(); } printf("Loved.\n"); - } - else puts("I't doesn't seem to work."); + } else + puts("I't doesn't seem to work."); } int @@ -130,105 +128,104 @@ zzz(void) int n; oldtime = gtime; - if ((snooze - gtime) < (0.75 * CYCLE)){ + if ((snooze - gtime) < (0.75 * CYCLE)) { gtime += 0.75 * CYCLE - (snooze - gtime); printf(""); for (n = 0; n < gtime - oldtime; n++) printf("."); printf("\n"); snooze += 3 * (gtime - oldtime); - if (notes[LAUNCHED]){ + if (notes[LAUNCHED]) { fuel -= (gtime - oldtime); - if (location[position].down){ + if (location[position].down) { position = location[position].down; crash(); - } - else + } else notes[LAUNCHED] = 0; } - if (OUTSIDE && rnd(100) < 50){ + if (OUTSIDE && rnd(100) < 50) { puts("You are awakened abruptly by the sound of someone nearby."); - switch(rnd(4)){ - case 0: - if (ucard(inven)){ + switch (rnd(4)) { + case 0: + if (ucard(inven)) { + n = rnd(NUMOFOBJECTS); + while (!testbit(inven, n)) n = rnd(NUMOFOBJECTS); - while(!testbit(inven,n)) - n = rnd(NUMOFOBJECTS); - clearbit(inven,n); - if (n != AMULET && n != MEDALION && n != TALISMAN) - setbit(location[position].objects,n); - carrying -= objwt[n]; - encumber -= objcumber[n]; - } - puts("A fiendish little Elf is stealing your treasures!"); - fight(ELF,10); - break; - case 1: - setbit(location[position].objects,DEADWOOD); - break; - case 2: - setbit(location[position].objects,HALBERD); - break; - default: - break; + clearbit(inven, n); + if (n != AMULET && n != MEDALION && + n != TALISMAN) + setbit(location[position].objects, n); + carrying -= objwt[n]; + encumber -= objcumber[n]; + } + puts("A fiendish little Elf is stealing your treasures!"); + fight(ELF, 10); + break; + case 1: + setbit(location[position].objects, DEADWOOD); + break; + case 2: + setbit(location[position].objects, HALBERD); + break; + default: + break; } } - } - else - return(0); - return(1); + } else + return (0); + return (1); } void chime(void) { if ((gtime / CYCLE + 1) % 2 && OUTSIDE) - switch((gtime % CYCLE)/(CYCLE / 7)){ - case 0: - puts("It is just after sunrise."); - break; - case 1: - puts("It is early morning."); - break; - case 2: - puts("It is late morning."); - break; - case 3: - puts("It is near noon."); - break; - case 4: - puts("It is early afternoon."); - break; - case 5: - puts("It is late afternoon."); - break; - case 6: - puts("It is near sunset."); - break; + switch ((gtime % CYCLE) / (CYCLE / 7)) { + case 0: + puts("It is just after sunrise."); + break; + case 1: + puts("It is early morning."); + break; + case 2: + puts("It is late morning."); + break; + case 3: + puts("It is near noon."); + break; + case 4: + puts("It is early afternoon."); + break; + case 5: + puts("It is late afternoon."); + break; + case 6: + puts("It is near sunset."); + break; } else if (OUTSIDE) - switch((gtime % CYCLE)/(CYCLE / 7)){ - case 0: - puts("It is just after sunset."); - break; - case 1: - puts("It is early evening."); - break; - case 2: - puts("The evening is getting old."); - break; - case 3: - puts("It is near midnight."); - break; - case 4: - puts("These are the wee hours of the morning."); - break; - case 5: - puts("The night is waning."); - break; - case 6: - puts("It is almost morning."); - break; + switch ((gtime % CYCLE) / (CYCLE / 7)) { + case 0: + puts("It is just after sunset."); + break; + case 1: + puts("It is early evening."); + break; + case 2: + puts("The evening is getting old."); + break; + case 3: + puts("It is near midnight."); + break; + case 4: + puts("These are the wee hours of the morning."); + break; + case 5: + puts("The night is waning."); + break; + case 6: + puts("It is almost morning."); + break; } else puts("I can't tell the time in here."); @@ -237,20 +234,28 @@ chime(void) int give(void) { - int obj = -1, result = -1, person = 0, firstnumber; - int last1 = 0, last2 = 0; + int obj, result, person, firstnumber; + int last1, last2; + obj = result = -1; + last1 = last2 = person = 0; firstnumber = wordnumber; - while (wordtype[++wordnumber] != OBJECT && wordvalue[wordnumber] != AMULET && wordvalue[wordnumber] != MEDALION && wordvalue[wordnumber] != TALISMAN && wordnumber <= wordcount); - if (wordnumber <= wordcount){ + while (wordtype[++wordnumber] != OBJECT && + wordvalue[wordnumber] != AMULET && + wordvalue[wordnumber] != MEDALION && + wordvalue[wordnumber] != TALISMAN && wordnumber <= wordcount) + ; /* nothing */ + if (wordnumber <= wordcount) { obj = wordvalue[wordnumber]; if (obj == EVERYTHING) wordtype[wordnumber] = -1; last1 = wordnumber; } wordnumber = firstnumber; - while ((wordtype[++wordnumber] != NOUNS || wordvalue[wordnumber] == obj) && wordnumber <= wordcount); - if (wordtype[wordnumber] == NOUNS){ + while ((wordtype[++wordnumber] != NOUNS || + wordvalue[wordnumber] == obj) && wordnumber <= wordcount) + ; /* nothing */ + if (wordtype[wordnumber] == NOUNS) { person = wordvalue[wordnumber]; last2 = wordnumber; } @@ -268,78 +273,81 @@ give(void) * that's no worse than what other commands than give do in * the same place. */ wordnumber = last1 - 1; - if (person && testbit(location[position].objects,person)) - if (person == NORMGOD && godready < 2 && !(obj == RING || obj == BRACELET)) + if (person && testbit(location[position].objects, person)) { + if (person == NORMGOD && godready < 2 && + !(obj == RING || obj == BRACELET)) puts("The goddess won't look at you."); else result = drop("Given"); - else { + } else { puts("I don't think that is possible."); wordnumber = max(last1, last2) + 1; - return(0); + return (0); } - if (result != -1 && (testbit(location[position].objects,obj) || obj == AMULET || obj == MEDALION || obj == TALISMAN)){ - clearbit(location[position].objects,obj); + if (result != -1 && (testbit(location[position].objects, obj) || + obj == AMULET || obj == MEDALION || obj == TALISMAN)) { + clearbit(location[position].objects, obj); gtime++; ego++; - switch(person){ - case NATIVE: - puts("She accepts it shyly."); - ego += 2; - break; - case NORMGOD: - if (obj == RING || obj == BRACELET){ - puts("She takes the charm and puts it on. A little kiss on the cheek is"); - puts("your reward."); - ego += 5; - godready += 3; - } - if (obj == AMULET || obj == MEDALION || obj == TALISMAN){ - bs_win++; - ego += 5; - power -= 5; - if (bs_win >= 3){ - puts("The powers of the earth are now legitimate. You have destroyed the Darkness"); - puts("and restored the goddess to her thrown. The entire island celebrates with"); - puts("dancing and spring feasts. As a measure of her gratitude, the goddess weds you"); - puts("in the late summer and crowns you Prince Liverwort, Lord of Fungus."); - puts("\nBut, as the year wears on and autumn comes along, you become restless and"); - puts("yearn for adventure. The goddess, too, realizes that the marriage can't last."); - puts("She becomes bored and takes several more natives as husbands. One evening,"); - puts("after having been out drinking with the girls, she kicks the throne particularly"); - puts("hard and wakes you up. (If you want to win this game, you're going to have to\nshoot her!)"); - clearbit(location[position].objects,MEDALION); - wintime = gtime; - } - } - break; - case TIMER: - if (obj == COINS){ - puts("He fingers the coins for a moment and then looks up agape. `Kind you are and"); - puts("I mean to repay you as best I can.' Grabbing a pencil and cocktail napkin...\n"); - printf( "+-----------------------------------------------------------------------------+\n"); - printf( "| xxxxxxxx\\ |\n"); - printf( "| xxxxx\\ CLIFFS |\n"); - printf( "| FOREST xxx\\ |\n"); - printf( "| \\\\ x\\ OCEAN |\n"); - printf( "| || x\\ |\n"); - printf( "| || ROAD x\\ |\n"); - printf( "| || x\\ |\n"); - printf( "| SECRET || ......... |\n"); - printf( "| - + - || ........ |\n"); - printf( "| ENTRANCE || ... BEACH |\n"); - printf( "| || ... E |\n"); - printf( "| || ... | |\n"); - printf( "| // ... N <-- + --- S |\n"); - printf( "| PALM GROVE // ... | |\n"); - printf( "| // ... W |\n"); - printf( "+-----------------------------------------------------------------------------+\n"); - puts("\n`This map shows a secret entrance to the catacombs."); - puts("You will know when you arrive because I left an old pair of shoes there.'"); + switch (person) { + case NATIVE: + puts("She accepts it shyly."); + ego += 2; + break; + case NORMGOD: + if (obj == RING || obj == BRACELET) { + puts("She takes the charm and puts it on. A little kiss on the cheek is"); + puts("your reward."); + ego += 5; + godready += 3; + } + if (obj == AMULET || obj == MEDALION || + obj == TALISMAN) { + bs_win++; + ego += 5; + power -= 5; + if (bs_win >= 3) { + puts("The powers of the earth are now legitimate. You have destroyed the Darkness"); + puts("and restored the goddess to her thrown. The entire island celebrates with"); + puts("dancing and spring feasts. As a measure of her gratitude, the goddess weds you"); + puts("in the late summer and crowns you Prince Liverwort, Lord of Fungus."); + puts("\nBut, as the year wears on and autumn comes along, you become restless and"); + puts("yearn for adventure. The goddess, too, realizes that the marriage can't last."); + puts("She becomes bored and takes several more natives as husbands. One evening,"); + puts("after having been out drinking with the girls, she kicks the throne particularly"); + puts("hard and wakes you up. (If you want to win this game, you're going to have to\nshoot her!)"); + clearbit(location[position].objects, MEDALION); + wintime = gtime; } - break; + } + break; + case TIMER: + if (obj == COINS) { + puts("He fingers the coins for a moment and then looks up agape. `Kind you are and"); + puts("I mean to repay you as best I can.' Grabbing a pencil and cocktail napkin...\n"); + printf("+-----------------------------------------------------------------------------+\n"); + printf("| xxxxxxxx\\ |\n"); + printf("| xxxxx\\ CLIFFS |\n"); + printf("| FOREST xxx\\ |\n"); + printf("| \\\\ x\\ OCEAN |\n"); + printf("| || x\\ |\n"); + printf("| || ROAD x\\ |\n"); + printf("| || x\\ |\n"); + printf("| SECRET || ......... |\n"); + printf("| - + - || ........ |\n"); + printf("| ENTRANCE || ... BEACH |\n"); + printf("| || ... E |\n"); + printf("| || ... | |\n"); + printf("| // ... N <-- + --- S |\n"); + printf("| PALM GROVE // ... | |\n"); + printf("| // ... W |\n"); + printf("+-----------------------------------------------------------------------------+\n"); + puts("\n`This map shows a secret entrance to the catacombs."); + puts("You will know when you arrive because I left an old pair of shoes there.'"); + } + break; } } - wordnumber = max(last1,last2) + 1; - return(firstnumber); + wordnumber = max(last1, last2) + 1; + return (firstnumber); } diff --git a/games/battlestar/com6.c b/games/battlestar/com6.c index 945a57bbb5..a94f6b7504 100644 --- a/games/battlestar/com6.c +++ b/games/battlestar/com6.c @@ -1,4 +1,4 @@ -/* +/*- * Copyright (c) 1983, 1993 * The Regents of the University of California. All rights reserved. * @@ -10,11 +10,7 @@ * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. - * 4. Neither the name of the University nor the names of its contributors + * 3. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * @@ -36,54 +32,53 @@ */ #include +#include #include "externs.h" #include "pathnames.h" -static void post (unsigned int ch); +static FILE *score_fp; +static void post(unsigned int ch); int launch(void) { - if (testbit(location[position].objects,VIPER) && !notes[CANTLAUNCH]){ - if (fuel > 4){ - clearbit(location[position].objects,VIPER); + if (testbit(location[position].objects, VIPER) && !notes[CANTLAUNCH]) { + if (fuel > 4) { + clearbit(location[position].objects, VIPER); position = location[position].up; notes[LAUNCHED] = 1; gtime++; fuel -= 4; puts("You climb into the viper and prepare for launch."); puts("With a touch of your thumb the turbo engines ignite, thrusting you back into\nyour seat."); - return(1); - } - else + return (1); + } else puts("Not enough fuel to launch."); - } - else + } else puts("Can't launch."); - return(0); + return (0); } int land(void) { - if (notes[LAUNCHED] && testbit(location[position].objects,LAND) && location[position].down){ + if (notes[LAUNCHED] && testbit(location[position].objects, LAND) && + location[position].down) { notes[LAUNCHED] = 0; position = location[position].down; - setbit(location[position].objects,VIPER); + setbit(location[position].objects, VIPER); fuel -= 2; gtime++; puts("You are down."); - return(1); - } - else + return (1); + } else puts("You can't land here."); - return(0); + return (0); } void -die(int sig) /* endgame */ +die(int sig __unused) /* endgame */ { - sig = 0; printf("bye.\nYour rating was %s.\n", rate()); post(' '); exit(0); @@ -97,14 +92,10 @@ live(void) exit(0); } -#include - -static FILE *score_fp; - void open_score_file(void) { - if ((score_fp = fopen(_PATH_SCORE,"a")) == NULL) + if ((score_fp = fopen(_PATH_SCORE, "a")) == NULL) perror(_PATH_SCORE); } @@ -121,8 +112,8 @@ post(unsigned int ch) s = sigblock(sigmask(SIGINT)); - gettimeofday(&tv, NULL); /* can't call time */ - tvsec = (time_t) tv.tv_sec; + gettimeofday(&tv, NULL); /* can't call time */ + tvsec = (time_t)tv.tv_sec; date = ctime(&tvsec); date[24] = '\0'; @@ -142,65 +133,67 @@ rate(void) { int score; - score = max(max(pleasure,power),ego); - if (score == pleasure){ + score = max(max(pleasure, power), ego); + if (score == pleasure) { if (score < 5) - return("novice"); + return ("novice"); else if (score < 20) - return("junior voyeur"); + return ("junior voyeur"); else if (score < 35) - return("Don Juan"); - else return("Marquis De Sade"); - } - else if (score == power){ + return ("Don Juan"); + else + return ("Marquis De Sade"); + } else if (score == power) { if (score < 5) - return("serf"); + return ("serf"); else if (score < 8) - return("Samurai"); + return ("Samurai"); else if (score < 13) - return("Klingon"); + return ("Klingon"); else if (score < 22) - return("Darth Vader"); - else return("Sauron the Great"); - } - else{ + return ("Darth Vader"); + else + return ("Sauron the Great"); + } else { if (score < 5) - return("Polyanna"); + return ("Polyanna"); else if (score < 10) - return("philanthropist"); + return ("philanthropist"); else if (score < 20) - return("Tattoo"); - else return("Mr. Roarke"); + return ("Tattoo"); + else + return ("Mr. Roarke"); } } int drive(void) { - if (testbit(location[position].objects,CAR)){ + if (testbit(location[position].objects, CAR)) { puts("You hop in the car and turn the key. There is a perceptible grating noise,"); puts("and an explosion knocks you unconscious..."); - clearbit(location[position].objects,CAR); - setbit(location[position].objects,CRASH); + clearbit(location[position].objects, CAR); + setbit(location[position].objects, CRASH); injuries[5] = injuries[6] = injuries[7] = injuries[8] = 1; gtime += 15; zzz(); - return(0); - } - else + return (0); + } else puts("There is nothing to drive here."); - return(-1); + return (-1); } int ride(void) { - if (testbit(location[position].objects,HORSE)){ + if (testbit(location[position].objects, HORSE)) { puts("You climb onto the stallion and kick it in the guts. The stupid steed launches"); puts("forward through bush and fern. You are thrown and the horse gallups off."); - clearbit(location[position].objects,HORSE); - while (!(position = rnd(NUMOFROOMS+1)) || !OUTSIDE || !beenthere[position] || location[position].flyhere); - setbit(location[position].objects,HORSE); + clearbit(location[position].objects, HORSE); + while (!(position = rnd(NUMOFROOMS + 1)) || !OUTSIDE || + !beenthere[position] || location[position].flyhere) + ; /* nothing */ + setbit(location[position].objects, HORSE); if (location[position].north) position = location[position].north; else if (location[position].south) @@ -209,24 +202,24 @@ ride(void) position = location[position].east; else position = location[position].west; - return(0); - } - else puts("There is no horse here."); - return(-1); + return (0); + } else + puts("There is no horse here."); + return (-1); } void -light(void) /* synonyms = {strike, smoke} */ -{ /* for matches, cigars */ - if (testbit(inven,MATCHES) && matchcount){ +light(void) /* synonyms = {strike, smoke} */ +{ /* for matches, cigars */ + if (testbit(inven, MATCHES) && matchcount) { puts("Your match splutters to life."); gtime++; matchlight = 1; matchcount--; - if (position == 217){ + if (position == 217) { puts("The whole bungalow explodes with an intense blast."); die(0); } - } - else puts("You're out of matches."); + } else + puts("You're out of matches."); } diff --git a/games/battlestar/com7.c b/games/battlestar/com7.c index 78d1a7efc7..983690e28e 100644 --- a/games/battlestar/com7.c +++ b/games/battlestar/com7.c @@ -1,4 +1,4 @@ -/* +/*- * Copyright (c) 1983, 1993 * The Regents of the University of California. All rights reserved. * @@ -10,11 +10,7 @@ * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. - * 4. Neither the name of the University nor the names of its contributors + * 3. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * @@ -40,18 +36,19 @@ int fight(int enemy, int strength) { - int lifeline = 0; + int lifeline; int hurt; char auxbuf[LINELENGTH]; char *next; int i; - int exhaustion = 0; + int exhaustion; + exhaustion = lifeline = 0; fighton: gtime++; snooze -= 5; if (snooze > gtime) - exhaustion = CYCLE/(snooze - gtime); + exhaustion = CYCLE / (snooze - gtime); else { puts("You collapse exhausted, and he pulverizes your skull."); die(0); @@ -59,209 +56,206 @@ fighton: if (snooze - gtime < 20) puts("You look tired! I hope you're able to fight."); next = getcom(auxbuf, LINELENGTH, "-: ", 0); - for (i=0; next && i < 10; i++) + for (i = 0; next && i < 10; i++) next = getword(next, words[i], -1); parse(); - switch(wordvalue[wordnumber]){ - - case KILL: - case SMITE: - if (testbit(inven,TWO_HANDED)) - hurt = rnd(70) - 2 * card(injuries,NUMOFINJURIES) - ucard(wear) - exhaustion; - else if (testbit(inven,SWORD) || testbit(inven, BROAD)) - hurt = rnd(50)%(WEIGHT-carrying)-card(injuries,NUMOFINJURIES)-encumber - exhaustion; - else if (testbit(inven,KNIFE) || testbit(inven,MALLET) || testbit(inven,CHAIN) || testbit(inven,MACE) || testbit(inven,HALBERD)) - hurt = rnd(15) - card(injuries,NUMOFINJURIES) - exhaustion; - else - hurt = rnd(7) - encumber; - if (hurt < 5) - switch(rnd(3)){ - - case 0: - puts("You swung wide and missed."); - break; - case 1: - puts("He checked your blow. CLASH! CLANG!"); - break; - case 2: - puts("His filthy tunic hangs by one less thread."); - break; - } - else if (hurt < 10){ - switch(rnd(3)){ - case 0: - puts("He's bleeding."); - break; - case 1: - puts("A trickle of blood runs down his face."); - break; - case 2: - puts("A huge purple bruise is forming on the side of his face."); - break; - } - lifeline++; + switch (wordvalue[wordnumber]) { + case KILL: + case SMITE: + if (testbit(inven, TWO_HANDED)) + hurt = rnd(70) - 2 * card(injuries, NUMOFINJURIES) - + ucard(wear) - exhaustion; + else if (testbit(inven, SWORD) || testbit(inven, BROAD)) + hurt = rnd(50) % (WEIGHT - carrying) - + card(injuries, NUMOFINJURIES) - encumber - + exhaustion; + else if (testbit(inven, KNIFE) || testbit(inven, MALLET) || + testbit(inven, CHAIN) || testbit(inven, MACE) || + testbit(inven, HALBERD)) + hurt = rnd(15) - card(injuries, NUMOFINJURIES) - + exhaustion; + else + hurt = rnd(7) - encumber; + if (hurt < 5) + switch (rnd(3)) { + case 0: + puts("You swung wide and missed."); + break; + case 1: + puts("He checked your blow. CLASH! CLANG!"); + break; + case 2: + puts("His filthy tunic hangs by one less thread."); + break; } - else if (hurt < 20){ - switch(rnd(3)){ - case 0: - puts("He staggers back quavering."); - break; - case 1: - puts("He jumps back with his hand over the wound."); - break; - case 2: - puts("His shirt falls open with a swath across the chest."); - break; - } - lifeline += 5; - } - else if (hurt < 30){ - switch(rnd(3)){ - case 0: - printf("A bloody gash opens up on his %s side.\n",(rnd(2) ? "left" : "right")); - break; - case 1: - puts("The steel bites home and scrapes along his ribs."); - break; - case 2: - puts("You pierce him, and his breath hisses through clenched teeth."); - break; - } - lifeline += 10; + else if (hurt < 10) { + switch (rnd(3)) { + case 0: + puts("He's bleeding."); + break; + case 1: + puts("A trickle of blood runs down his face."); + break; + case 2: + puts("A huge purple bruise is forming on the side of his face."); + break; } - else if (hurt < 40){ - switch(rnd(3)){ - case 0: - puts("You smite him to the ground."); - if (strength - lifeline > 20) - puts("But in a flurry of steel he regains his feet!"); - break; - case 1: - puts("The force of your blow sends him to his knees."); - puts("His arm swings lifeless at his side."); - break; - case 2: - puts("Clutching his blood drenched shirt, he collapses stunned."); - break; - } - lifeline += 20; + lifeline++; + } else if (hurt < 20) { + switch (rnd(3)) { + case 0: + puts("He staggers back quavering."); + break; + case 1: + puts("He jumps back with his hand over the wound."); + break; + case 2: + puts("His shirt falls open with a swath across the chest."); + break; } - else { - switch(rnd(3)){ - case 0: - puts("His ribs crack under your powerful swing, flooding his lungs with blood."); - break; - case 1: - puts("You shatter his upheld arm in a spray of blood. The blade continues deep"); - puts("into his back, severing the spinal cord."); - lifeline += 25; - break; - case 2: - puts("With a mighty lunge the steel slides in, and gasping, he falls to the ground."); - lifeline += 25; - break; - } - lifeline += 30; + lifeline += 5; + } else if (hurt < 30) { + switch (rnd(3)) { + case 0: + printf("A bloody gash opens up on his %s side.\n", + (rnd(2) ? "left" : "right")); + break; + case 1: + puts("The steel bites home and scrapes along his ribs."); + break; + case 2: + puts("You pierce him, and his breath hisses through clenched teeth."); + break; } - break; - - case BACK: - if (enemy == DARK && lifeline > strength * 0.33){ - puts("He throws you back against the rock and pummels your face."); - if (testbit(inven,AMULET) || testbit(wear,AMULET)){ - printf("Lifting the amulet from you, "); - if (testbit(inven,MEDALION) || testbit(wear,MEDALION)){ - puts("his power grows and the walls of\nthe earth tremble."); - puts("When he touches the medallion, your chest explodes and the foundations of the\nearth collapse."); - puts("The planet is consumed by darkness."); - die(0); - } - if (testbit(inven,AMULET)){ - clearbit(inven,AMULET); - carrying -= objwt[AMULET]; - encumber -= objcumber[AMULET]; - } - else - clearbit(wear,AMULET); - puts("he flees down the dark caverns."); - clearbit(location[position].objects,DARK); - injuries[SKULL] = 1; - followfight = gtime; - return (0); - } - else{ - puts("I'm afraid you have been killed."); - die(0); - } + lifeline += 10; + } else if (hurt < 40) { + switch (rnd(3)) { + case 0: + puts("You smite him to the ground."); + if (strength - lifeline > 20) + puts("But in a flurry of steel he regains his feet!"); + break; + case 1: + puts("The force of your blow sends him to his knees."); + puts("His arm swings lifeless at his side."); + break; + case 2: + puts("Clutching his blood drenched shirt, he collapses stunned."); + break; } - else{ - puts("You escape stunned and disoriented from the fight."); - puts("A victorious bellow echoes from the battlescene."); - if (back && position != back) - battlestar_move(back,BACK); - else if (ahead &&position != ahead) - battlestar_move(ahead,AHEAD); - else if (left && position != left) - battlestar_move(left,LEFT); - else if (right && position != right) - battlestar_move(right,RIGHT); - else - battlestar_move(location[position].down, - AHEAD); - return(0); + lifeline += 20; + } else { + switch (rnd(3)) { + case 0: + puts("His ribs crack under your powerful swing, flooding his lungs with blood."); + break; + case 1: + puts("You shatter his upheld arm in a spray of blood. The blade continues deep"); + puts("into his back, severing the spinal cord."); + lifeline += 25; + break; + case 2: + puts("With a mighty lunge the steel slides in, and gasping, he falls to the ground."); + lifeline += 25; + break; } + lifeline += 30; + } + break; - case SHOOT: - if (testbit(inven,LASER)){ - if (strength - lifeline <= 50){ - printf("The %s took a direct hit!\n",objsht[enemy]); - lifeline += 50; - } - else { - puts("With his bare hand he deflects the laser blast and whips the pistol from you!"); - clearbit(inven,LASER); - setbit(location[position].objects,LASER); - carrying -= objwt[LASER]; - encumber -= objcumber[LASER]; + case BACK: + if (enemy == DARK && lifeline > strength * 0.33) { + puts("He throws you back against the rock and pummels your face."); + if (testbit(inven, AMULET) || testbit(wear, AMULET)) { + printf("Lifting the amulet from you, "); + if (testbit(inven, MEDALION) || + testbit(wear, MEDALION)) { + puts("his power grows and the walls of\nthe earth tremble."); + puts("When he touches the medallion, your chest explodes and the foundations of the\nearth collapse."); + puts("The planet is consumed by darkness."); + die(0); } + if (testbit(inven, AMULET)) { + clearbit(inven, AMULET); + carrying -= objwt[AMULET]; + encumber -= objcumber[AMULET]; + } else + clearbit(wear, AMULET); + puts("he flees down the dark caverns."); + clearbit(location[position].objects, DARK); + injuries[SKULL] = 1; + followfight = gtime; + return (0); + } else { + puts("I'm afraid you have been killed."); + die(0); } + } else { + puts("You escape stunned and disoriented from the fight."); + puts("A victorious bellow echoes from the battlescene."); + if (back && position != back) + battlestar_move(back, BACK); + else if (ahead && position != ahead) + battlestar_move(ahead, AHEAD); + else if (left && position != left) + battlestar_move(left, LEFT); + else if (right && position != right) + battlestar_move(right, RIGHT); else - puts("Unfortunately, you don't have a blaster handy."); - break; + battlestar_move(location[position].down, AHEAD); + return (0); + } - case DROP: - case DRAW: - cypher(); - gtime--; - break; + case SHOOT: + if (testbit(inven, LASER)) { + if (strength - lifeline <= 50) { + printf("The %s took a direct hit!\n", + objsht[enemy]); + lifeline += 50; + } else { + puts("With his bare hand he deflects the laser blast and whips the pistol from you!"); + clearbit(inven, LASER); + setbit(location[position].objects, LASER); + carrying -= objwt[LASER]; + encumber -= objcumber[LASER]; + } + } else + puts("Unfortunately, you don't have a blaster handy."); + break; - default: - puts("You don't have a chance, he is too quick."); - break; + case DROP: + case DRAW: + cypher(); + gtime--; + break; + default: + puts("You don't have a chance, he is too quick."); + break; } - if (lifeline >= strength){ + if (lifeline >= strength) { printf("You have killed the %s.\n", objsht[enemy]); if (enemy == ELF || enemy == DARK) puts("A watery black smoke consumes his body and then vanishes with a peal of thunder!"); - clearbit(location[position].objects,enemy); + clearbit(location[position].objects, enemy); power += 2; notes[JINXED]++; - return(0); + return (0); } puts("He attacks..."); - /* some embellisments */ - hurt = rnd(NUMOFINJURIES) - (testbit(inven,SHIELD) != 0) - (testbit(wear,MAIL) != 0) - (testbit(wear,HELM) != 0); - hurt += (testbit(wear,AMULET) != 0) + (testbit(wear,MEDALION) != 0) + (testbit(wear,TALISMAN) != 0); + /* Some embellishments. */ + hurt = rnd(NUMOFINJURIES) - (testbit(inven, SHIELD) != 0) - + (testbit(wear, MAIL) != 0) - (testbit(wear, HELM) != 0); + hurt += (testbit(wear, AMULET) != 0) + + (testbit(wear, MEDALION) != 0) + (testbit(wear, TALISMAN) != 0); hurt = hurt < 0 ? 0 : hurt; - hurt = hurt >= NUMOFINJURIES ? NUMOFINJURIES -1 : hurt; - if (!injuries[hurt]){ + hurt = hurt >= NUMOFINJURIES ? NUMOFINJURIES - 1 : hurt; + if (!injuries[hurt]) { injuries[hurt] = 1; printf("I'm afraid you have suffered %s.\n", ouch[hurt]); - } - else + } else puts("You emerge unscathed."); - if (injuries[SKULL] && injuries[INCISE] && injuries[NECK]){ + if (injuries[SKULL] && injuries[INCISE] && injuries[NECK]) { puts("I'm afraid you have suffered fatal injuries."); die(0); } diff --git a/games/battlestar/cypher.c b/games/battlestar/cypher.c index 09341b1aec..8114e7e83e 100644 --- a/games/battlestar/cypher.c +++ b/games/battlestar/cypher.c @@ -1,4 +1,4 @@ -/* +/*- * Copyright (c) 1983, 1993 * The Regents of the University of California. All rights reserved. * @@ -10,11 +10,7 @@ * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. - * 4. Neither the name of the University nor the names of its contributors + * 3. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * @@ -42,391 +38,390 @@ cypher(void) { int n; int junk; - int lflag = -1; + int lflag; char buffer[10]; + lflag = -1; while (wordtype[wordnumber] == ADJS) wordnumber++; while (wordnumber <= wordcount) { - switch(wordvalue[wordnumber]) { - - case UP: - if (location[position].access || wiz || tempwiz) { - if (!location[position].access) - puts("Zap! A gust of wind lifts you up."); - if (!battlestar_move(location[position].up, AHEAD)) - return(-1); - } else { - puts("There is no way up"); - return(-1); - } - lflag = 0; - break; - - case DOWN: - if (!battlestar_move(location[position].down, - AHEAD)) - return(-1); - lflag = 0; - break; - - case LEFT: - if (!battlestar_move(left, LEFT)) - return(-1); - lflag = 0; - break; - - case RIGHT: - if (!battlestar_move(right, RIGHT)) - return(-1); - lflag = 0; - break; - - case AHEAD: - if (!battlestar_move(ahead, AHEAD)) - return(-1); - lflag = 0; - break; - - case BACK: - if (!battlestar_move(back, BACK)) - return(-1); - lflag = 0; - break; - - case SHOOT: - if (wordnumber < wordcount && wordvalue[wordnumber+1] == EVERYTHING){ - for (n=0; n < NUMOFOBJECTS; n++) - if (testbit(location[position].objects,n) && objsht[n]){ - wordvalue[wordnumber+1] = n; - wordnumber = shoot(); - } + switch (wordvalue[wordnumber]) { + case UP: + if (location[position].access || wiz || tempwiz) { + if (!location[position].access) + puts("Zap! A gust of wind lifts you up."); + if (!battlestar_move(location[position].up, AHEAD)) + return (-1); + } else { + puts("There is no way up"); + return (-1); + } + lflag = 0; + break; + + case DOWN: + if (!battlestar_move(location[position].down, AHEAD)) + return (-1); + lflag = 0; + break; + + case LEFT: + if (!battlestar_move(left, LEFT)) + return (-1); + lflag = 0; + break; + + case RIGHT: + if (!battlestar_move(right, RIGHT)) + return (-1); + lflag = 0; + break; + + case AHEAD: + if (!battlestar_move(ahead, AHEAD)) + return (-1); + lflag = 0; + break; + + case BACK: + if (!battlestar_move(back, BACK)) + return (-1); + lflag = 0; + break; + + case SHOOT: + if (wordnumber < wordcount && + wordvalue[wordnumber + 1] == EVERYTHING) { + for (n = 0; n < NUMOFOBJECTS; n++) + if (testbit(location[position].objects, + n) && objsht[n]) { + wordvalue[wordnumber + 1] = n; + wordnumber = shoot(); + } wordnumber++; wordnumber++; - } - else - shoot(); - break; - - case TAKE: - if (wordnumber < wordcount && wordvalue[wordnumber+1] == EVERYTHING){ - for (n=0; n < NUMOFOBJECTS; n++) - if (testbit(location[position].objects,n) && objsht[n]){ - wordvalue[wordnumber+1] = n; - wordnumber = take(location[position].objects); - } + } else + shoot(); + break; + + case TAKE: + if (wordnumber < wordcount && + wordvalue[wordnumber + 1] == EVERYTHING) { + for (n = 0; n < NUMOFOBJECTS; n++) + if (testbit(location[position].objects, + n) && objsht[n]) { + wordvalue[wordnumber + 1] = n; + wordnumber = + take(location[position].objects); + } wordnumber++; wordnumber++; - } - else - take(location[position].objects); - break; - - case DROP: - - if (wordnumber < wordcount && wordvalue[wordnumber+1] == EVERYTHING){ - for (n=0; n < NUMOFOBJECTS; n++) - if (testbit(inven,n)){ - wordvalue[wordnumber+1] = n; - wordnumber = drop("Dropped"); - } + } else + take(location[position].objects); + break; + + case DROP: + if (wordnumber < wordcount && + wordvalue[wordnumber + 1] == EVERYTHING) { + for (n = 0; n < NUMOFOBJECTS; n++) + if (testbit(inven, n)) { + wordvalue[wordnumber + 1] = n; + wordnumber = drop("Dropped"); + } wordnumber++; wordnumber++; + } else + drop("Dropped"); + break; + + case KICK: + case THROW: + if (wordnumber < wordcount && + wordvalue[wordnumber + 1] == EVERYTHING) { + for (n = 0; n < NUMOFOBJECTS; n++) { + if ((testbit(inven, n) || + testbit(location[position].objects, n)) && objsht[n]) { + wordvalue[wordnumber + 1] = n; + wordnumber = throw(wordvalue[wordnumber] == + KICK ? "Kicked" : "Thrown"); + } } - else - drop("Dropped"); - break; - - - case KICK: - case THROW: - if (wordnumber < wordcount && wordvalue[wordnumber+1] == EVERYTHING){ - for (n=0; n < NUMOFOBJECTS; n++) - if ((testbit(inven,n) || - testbit(location[position].objects, n)) && objsht[n]){ - wordvalue[wordnumber+1] = n; - wordnumber = throw(wordvalue[wordnumber] == KICK ? "Kicked" : "Thrown"); - } - wordnumber += 2; - } else - throw(wordvalue[wordnumber] == KICK ? "Kicked" : "Thrown"); - break; - - case TAKEOFF: - if (wordnumber < wordcount && wordvalue[wordnumber+1] == EVERYTHING){ - for (n=0; n < NUMOFOBJECTS; n++) - if (testbit(wear,n)){ - wordvalue[wordnumber+1] = n; - wordnumber = takeoff(); - } - wordnumber += 2; - } - else - takeoff(); - break; - - - case DRAW: - - if (wordnumber < wordcount && wordvalue[wordnumber+1] == EVERYTHING){ - for (n=0; n < NUMOFOBJECTS; n++) - if (testbit(wear,n)){ - wordvalue[wordnumber+1] = n; - wordnumber = draw(); - } - wordnumber += 2; - } - else - draw(); - break; - - - case PUTON: - - if (wordnumber < wordcount && wordvalue[wordnumber+1] == EVERYTHING){ - for (n=0; n < NUMOFOBJECTS; n++) - if (testbit(location[position].objects,n) && objsht[n]){ - wordvalue[wordnumber+1] = n; - wordnumber = puton(); - } - wordnumber += 2; - } - else - puton(); - break; - - case WEARIT: - - if (wordnumber < wordcount && wordvalue[wordnumber+1] == EVERYTHING){ - for (n=0; n < NUMOFOBJECTS; n++) - if (testbit(inven,n)){ - wordvalue[wordnumber+1] = n; - wordnumber = wearit(); - } - wordnumber += 2; - } - else - wearit(); - break; - - - case EAT: - - if (wordnumber < wordcount && wordvalue[wordnumber+1] == EVERYTHING){ - for (n=0; n < NUMOFOBJECTS; n++) - if (testbit(inven,n)){ - wordvalue[wordnumber+1] = n; - wordnumber = eat(); - } - wordnumber += 2; - } - else - eat(); - break; - - - case PUT: - put(); - break; - - - case INVEN: - if (ucard(inven)){ - puts("You are holding:\n"); - for (n=0; n < NUMOFOBJECTS; n++) - if (testbit(inven,n)) - printf("\t%s\n", objsht[n]); - printf("\n= %d kilogram%s (%d%%)\n", carrying, (carrying == 1 ? "." : "s."),(WEIGHT ? carrying*100/WEIGHT : -1)); - printf("Your arms are %d%% full.\n",encumber*100/CUMBER); - } - else - puts("You aren't carrying anything."); - - if (ucard(wear)){ - puts("\nYou are wearing:\n"); - for (n=0; n < NUMOFOBJECTS; n++) - if (testbit(wear,n)) - printf("\t%s\n", objsht[n]); - } - else - puts("\nYou are stark naked."); - if (card(injuries,NUMOFINJURIES)){ - puts("\nYou have suffered:\n"); - for (n=0; n < NUMOFINJURIES; n++) - if (injuries[n]) - printf("\t%s\n",ouch[n]); - printf("\nYou can still carry up to %d kilogram%s\n",WEIGHT,(WEIGHT == 1 ? "." : "s.")); - } - else - puts("\nYou are in perfect health."); - break; - - case USE: - lflag = use(); - break; - - case LOOK: - if (!notes[CANTSEE] || testbit(inven,LAMPON) || testbit(location[position].objects,LAMPON) || matchlight){ - beenthere[position] = 2; - writedes(); - printobjs(); - if (matchlight){ - puts("\nYour match splutters out."); - matchlight = 0; + wordnumber += 2; + } else + throw(wordvalue[wordnumber] == KICK ? "Kicked" : "Thrown"); + break; + + case TAKEOFF: + if (wordnumber < wordcount && + wordvalue[wordnumber + 1] == EVERYTHING) { + for (n = 0; n < NUMOFOBJECTS; n++) + if (testbit(wear, n)) { + wordvalue[wordnumber + 1] = n; + wordnumber = takeoff(); + } + wordnumber += 2; + } else + takeoff(); + break; + + case DRAW: + if (wordnumber < wordcount && + wordvalue[wordnumber + 1] == EVERYTHING) { + for (n = 0; n < NUMOFOBJECTS; n++) + if (testbit(wear, n)) { + wordvalue[wordnumber + 1] = n; + wordnumber = draw(); + } + wordnumber += 2; + } else + draw(); + break; + + case PUTON: + if (wordnumber < wordcount && + wordvalue[wordnumber + 1] == EVERYTHING) { + for (n = 0; n < NUMOFOBJECTS; n++) + if (testbit(location[position].objects, + n) && objsht[n]) { + wordvalue[wordnumber + 1] = n; + wordnumber = puton(); } - } else - puts("I can't see anything."); - return(-1); - break; + wordnumber += 2; + } else + puton(); + break; + + case WEARIT: + if (wordnumber < wordcount && + wordvalue[wordnumber + 1] == EVERYTHING) { + for (n = 0; n < NUMOFOBJECTS; n++) + if (testbit(inven, n)) { + wordvalue[wordnumber + 1] = n; + wordnumber = wearit(); + } + wordnumber += 2; + } else + wearit(); + break; + + case EAT: + if (wordnumber < wordcount && + wordvalue[wordnumber + 1] == EVERYTHING) { + for (n = 0; n < NUMOFOBJECTS; n++) + if (testbit(inven, n)) { + wordvalue[wordnumber + 1] = n; + wordnumber = eat(); + } + wordnumber += 2; + } else + eat(); + break; + + case PUT: + put(); + break; + + case INVEN: + if (ucard(inven)) { + puts("You are holding:\n"); + for (n = 0; n < NUMOFOBJECTS; n++) + if (testbit(inven, n)) + printf("\t%s\n", objsht[n]); + printf("\n= %d kilogram%s (%d%%)\n", carrying, + (carrying == 1 ? "." : "s."), + (WEIGHT ? carrying * 100 / WEIGHT : -1)); + printf("Your arms are %d%% full.\n", + encumber * 100 / CUMBER); + } else + puts("You aren't carrying anything."); + + if (ucard(wear)) { + puts("\nYou are wearing:\n"); + for (n = 0; n < NUMOFOBJECTS; n++) + if (testbit(wear, n)) + printf("\t%s\n", objsht[n]); + } else + puts("\nYou are stark naked."); + if (card(injuries, NUMOFINJURIES)) { + puts("\nYou have suffered:\n"); + for (n = 0; n < NUMOFINJURIES; n++) + if (injuries[n]) + printf("\t%s\n", ouch[n]); + printf("\nYou can still carry up to %d kilogram%s\n", + WEIGHT, (WEIGHT == 1 ? "." : "s.")); + } else + puts("\nYou are in perfect health."); + break; + + case USE: + lflag = use(); + break; + + case LOOK: + if (!notes[CANTSEE] || testbit(inven, LAMPON) || + testbit(location[position].objects, LAMPON) || + matchlight) { + beenthere[position] = 2; + writedes(); + printobjs(); + if (matchlight) { + puts("\nYour match splutters out."); + matchlight = 0; + } + } else + puts("I can't see anything."); + return (-1); + break; - case SU: - if (wiz || tempwiz){ + case SU: + if (wiz || tempwiz) { printf("\nRoom (was %d) = ", position); - fgets(buffer,10,stdin); + fgets(buffer, 10, stdin); if (*buffer != '\n') - sscanf(buffer,"%d", &position); - printf("Time (was %d) = ",gtime); - fgets(buffer,10,stdin); + sscanf(buffer, "%d", &position); + printf("Time (was %d) = ", gtime); + fgets(buffer, 10, stdin); if (*buffer != '\n') - sscanf(buffer,"%d", >ime); - printf("Fuel (was %d) = ",fuel); - fgets(buffer,10,stdin); + sscanf(buffer, "%d", >ime); + printf("Fuel (was %d) = ", fuel); + fgets(buffer, 10, stdin); if (*buffer != '\n') - sscanf(buffer,"%d", &fuel); - printf("Torps (was %d) = ",torps); - fgets(buffer,10,stdin); + sscanf(buffer, "%d", &fuel); + printf("Torps (was %d) = ", torps); + fgets(buffer, 10, stdin); if (*buffer != '\n') - sscanf(buffer,"%d", &torps); - printf("CUMBER (was %d) = ",CUMBER); - fgets(buffer,10,stdin); + sscanf(buffer, "%d", &torps); + printf("CUMBER (was %d) = ", CUMBER); + fgets(buffer, 10, stdin); if (*buffer != '\n') - sscanf(buffer,"%d", &CUMBER); - printf("WEIGHT (was %d) = ",WEIGHT); - fgets(buffer,10,stdin); + sscanf(buffer, "%d", &CUMBER); + printf("WEIGHT (was %d) = ", WEIGHT); + fgets(buffer, 10, stdin); if (*buffer != '\n') - sscanf(buffer,"%d",&WEIGHT); - printf("Clock (was %d) = ",gclock); - fgets(buffer,10,stdin); + sscanf(buffer, "%d", &WEIGHT); + printf("Clock (was %d) = ", gclock); + fgets(buffer, 10, stdin); if (*buffer != '\n') - sscanf(buffer,"%d",&gclock); - printf("Wizard (was %d, %d) = ",wiz, tempwiz); - fgets(buffer,10,stdin); - if (*buffer != '\n'){ - sscanf(buffer,"%d",&junk); + sscanf(buffer, "%d", &gclock); + printf("Wizard (was %d, %d) = ", wiz, tempwiz); + fgets(buffer, 10, stdin); + if (*buffer != '\n') { + sscanf(buffer, "%d", &junk); if (!junk) tempwiz = wiz = 0; } printf("\nDONE.\n"); - return(0); - } - else - puts("You aren't a wizard."); - break; - - case SCORE: - printf("\tPLEASURE\tPOWER\t\tEGO\n"); - printf("\t%3d\t\t%3d\t\t%3d\n\n",pleasure,power,ego); - printf("This gives you the rating of %s in %d turns.\n",rate(),gtime); - printf("You have visited %d out of %d rooms this run (%d%%).\n",card(beenthere,NUMOFROOMS),NUMOFROOMS,card(beenthere,NUMOFROOMS)*100/NUMOFROOMS); - break; - - case KNIFE: - case KILL: - murder(); - break; - - case UNDRESS: - case RAVAGE: - ravage(); - break; - - case SAVE: - save(); - break; - - case FOLLOW: - lflag = follow(); - break; - - case GIVE: - give(); - break; - - case KISS: - kiss(); - break; - - case LOVE: - love(); - break; - - case RIDE: - lflag = ride(); - break; - - case DRIVE: - lflag = drive(); - break; - - case LIGHT: - light(); - break; - - case LAUNCH: - if (!launch()) - return(-1); - else - lflag = 0; - break; - - case LANDIT: - if (!land()) - return(-1); - else - lflag = 0; - break; - - case TIME: - chime(); - break; - - case SLEEP: - zzz(); - break; - - case DIG: - dig(); - break; - - case JUMP: - lflag = jump(); - break; - - case BURY: - bury(); - break; - - case SWIM: - puts("Surf's up!"); - break; - - case DRINK: - drink(); - break; - - case QUIT: - die(0); - - default: - puts("How's that?"); - return(-1); - break; + return (0); + } else + puts("You aren't a wizard."); + break; + + case SCORE: + printf("\tPLEASURE\tPOWER\t\tEGO\n"); + printf("\t%3d\t\t%3d\t\t%3d\n\n", pleasure, power, ego); + printf("This gives you the rating of %s in %d turns.\n", + rate(), gtime); + printf("You have visited %d out of %d rooms this run (%d%%).\n", + card(beenthere, NUMOFROOMS), NUMOFROOMS, + card(beenthere, NUMOFROOMS) * 100 / NUMOFROOMS); + break; + + case KNIFE: + case KILL: + murder(); + break; + + case UNDRESS: + case RAVAGE: + ravage(); + break; + + case SAVE: + save(); + break; + + case FOLLOW: + lflag = follow(); + break; + + case GIVE: + give(); + break; + + case KISS: + kiss(); + break; + + case LOVE: + love(); + break; + + case RIDE: + lflag = ride(); + break; + + case DRIVE: + lflag = drive(); + break; + + case LIGHT: + light(); + break; + + case LAUNCH: + if (!launch()) + return (-1); + else + lflag = 0; + break; + + case LANDIT: + if (!land()) + return (-1); + else + lflag = 0; + break; + + case TIME: + chime(); + break; + + case SLEEP: + zzz(); + break; + + case DIG: + dig(); + break; + + case JUMP: + lflag = jump(); + break; + + case BURY: + bury(); + break; + + case SWIM: + puts("Surf's up!"); + break; + + case DRINK: + drink(); + break; + case QUIT: + die(0); + default: + puts("How's that?"); + return (-1); + break; } if (wordnumber < wordcount && *words[wordnumber++] == ',') continue; - else return(lflag); - } - return(lflag); + else + return (lflag); + } + return (lflag); } diff --git a/games/battlestar/dayfile.c b/games/battlestar/dayfile.c index 45e2dac998..427a59258f 100644 --- a/games/battlestar/dayfile.c +++ b/games/battlestar/dayfile.c @@ -1,4 +1,4 @@ -/* +/*- * Copyright (c) 1983, 1993 * The Regents of the University of California. All rights reserved. * @@ -10,11 +10,7 @@ * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. - * 4. Neither the name of the University nor the names of its contributors + * 3. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * diff --git a/games/battlestar/dayobjs.c b/games/battlestar/dayobjs.c index f81b362885..400e3c5ef6 100644 --- a/games/battlestar/dayobjs.c +++ b/games/battlestar/dayobjs.c @@ -1,4 +1,4 @@ -/* +/*- * Copyright (c) 1983, 1993 * The Regents of the University of California. All rights reserved. * @@ -10,11 +10,7 @@ * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. - * 4. Neither the name of the University nor the names of its contributors + * 3. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * diff --git a/games/battlestar/externs.h b/games/battlestar/externs.h index 798b5b2611..bd7f518c25 100644 --- a/games/battlestar/externs.h +++ b/games/battlestar/externs.h @@ -1,4 +1,4 @@ -/* +/*- * Copyright (c) 1983, 1993 * The Regents of the University of California. All rights reserved. * @@ -10,11 +10,7 @@ * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. - * 4. Neither the name of the University nor the names of its contributors + * 3. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * @@ -254,62 +250,8 @@ int wordvalue[NWORD]; int wordtype[NWORD]; int wordcount, wordnumber; - -int battlestar_move (int, int); -void bury (void); -int card (const char *, int); -void chime (void); -void crash (void); -int cypher (void); -void die (int); -void dig (void); -int draw (void); -void drink (void); -int drive (void); -int drop (const char *name); -int eat (void); -int fight (int, int); -int follow (void); -char *getcom (char *, int, const char *, const char *); -char *getword (char *, char *, int); -int give (void); -void initialize (int); -int jump (void); -void kiss (void); -int land (void); -int launch (void); -void light (void); -void live (void); -void love (void); -void murder (void); -void news (void); -void newway (int); -void open_score_file (void); -void parse (void); -void printobjs (void); -int put (void); -int puton (void); -void ravage (void); -const char *rate (void); -void restore (void); -int ride (void); -void save (void); -int shoot (void); -int take (unsigned int from[]); -int takeoff(void); -int throw (const char *name); -const char *truedirec (int, unsigned int); -int ucard (const unsigned int *); -int use (void); -int visual (void); -int wearit (void); -void whichway (struct room); -void wordinit (void); -void writedes (void); -int zzz (void); - /* state of the game */ -extern int gclock; +extern int gclock; int gtime; int position; int direction; @@ -360,3 +302,57 @@ extern const struct objs dayobjs[]; extern const struct objs nightobjs[]; extern gid_t egid; + + +int battlestar_move(int, int); +void bury(void); +int card(const char *, int); +void chime(void); +void crash(void); +int cypher(void); +void die(int); +void dig(void); +int draw(void); +void drink(void); +int drive(void); +int drop(const char *); +int eat(void); +int fight(int, int); +int follow(void); +char *getcom(char *, int, const char *, const char *); +char *getword(char *, char *, int); +int give(void); +void initialize(int); +int jump(void); +void kiss(void); +int land(void); +int launch(void); +void light(void); +void live(void); +void love(void); +void murder(void); +void news(void); +void newway(int); +void open_score_file(void); +void parse(void); +void printobjs(void); +int put(void); +int puton(void); +const char *rate(void); +void ravage(void); +void restore(void); +int ride(void); +void save(void); +int shoot(void); +int take(unsigned int[]); +int takeoff(void); +int throw(const char *); +const char *truedirec(int, unsigned int); +int ucard(const unsigned int *); +int use(void); +int visual(void); +int wearit(void); +void whichway(struct room); +void wordinit(void); +void writedes(void); +int zzz(void); diff --git a/games/battlestar/fly.c b/games/battlestar/fly.c index 60ff96e397..a3a59f56f6 100644 --- a/games/battlestar/fly.c +++ b/games/battlestar/fly.c @@ -1,4 +1,4 @@ -/* +/*- * Copyright (c) 1983, 1993 * The Regents of the University of California. All rights reserved. * @@ -10,11 +10,7 @@ * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. - * 4. Neither the name of the University nor the names of its contributors + * 3. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * @@ -39,29 +35,28 @@ #undef UP #include -#define abs(a) ((a) < 0 ? -(a) : (a)) -#define MIDR (LINES/2 - 1) -#define MIDC (COLS/2 - 1) +#define abs(a) ((a) < 0 ? -(a) : (a)) +#define MIDR (LINES / 2 - 1) +#define MIDC (COLS / 2 - 1) int row, column; int dr = 0, dc = 0; char destroyed; -int gclock = 120; /* gtime for all the flights in the game */ +int gclock = 120; /* gtime for all the flights in the game */ char cross = 0; sig_t oldsig; -static void blast (void); -static void endfly (void); -static void moveenemy (int); -static void notarget (void); -static void succumb (int); -static void screen (void); -static void target (void); +static void blast(void); +static void endfly(void); +static void moveenemy(int); +static void notarget(void); +static void succumb(int); +static void screen(void); +static void target(void); static void -succumb(int sig) +succumb(int sig __unused) { - sig = 0; if (oldsig == SIG_DFL) { endfly(); exit(1); @@ -76,127 +71,125 @@ int visual(void) { destroyed = 0; - if(initscr() == NULL){ + if (initscr() == NULL) { puts("Whoops! No more memory..."); - return(0); + return (0); } oldsig = signal(SIGINT, succumb); - crmode(); + cbreak(); noecho(); screen(); - row = rnd(LINES-3) + 1; - column = rnd(COLS-2) + 1; + row = rnd(LINES - 3) + 1; + column = rnd(COLS - 2) + 1; moveenemy(0); for (;;) { - switch(getchar()){ - - case 'h': - case 'r': - dc = -1; - fuel--; - break; + switch (getchar()) { + case 'h': + case 'r': + dc = -1; + fuel--; + break; - case 'H': - case 'R': - dc = -5; - fuel -= 10; - break; + case 'H': + case 'R': + dc = -5; + fuel -= 10; + break; - case 'l': - dc = 1; - fuel--; - break; + case 'l': + dc = 1; + fuel--; + break; - case 'L': - dc = 5; - fuel -= 10; - break; + case 'L': + dc = 5; + fuel -= 10; + break; - case 'j': - case 'u': - dr = 1; - fuel--; - break; + case 'j': + case 'u': + dr = 1; + fuel--; + break; - case 'J': - case 'U': - dr = 5; - fuel -= 10; - break; + case 'J': + case 'U': + dr = 5; + fuel -= 10; + break; - case 'k': - case 'd': - dr = -1; - fuel--; - break; + case 'k': + case 'd': + dr = -1; + fuel--; + break; - case 'K': - case 'D': - dr = -5; - fuel -= 10; - break; + case 'K': + case 'D': + dr = -5; + fuel -= 10; + break; - case '+': - if (cross){ - cross = 0; - notarget(); - } - else - cross = 1; - break; + case '+': + if (cross) { + cross = 0; + notarget(); + } else + cross = 1; + break; - case ' ': - case 'f': - if (torps){ - torps -= 2; - blast(); - if (row == MIDR && column - MIDC < 2 && MIDC - column < 2){ - destroyed = 1; - alarm(0); - } + case ' ': + case 'f': + if (torps) { + torps -= 2; + blast(); + if (row == MIDR && column - MIDC < 2 && + MIDC - column < 2) { + destroyed = 1; + alarm(0); } - else - mvaddstr(0,0,"*** Out of torpedoes. ***"); - break; + } else + mvaddstr(0, 0, "*** Out of torpedoes. ***"); + break; - case 'q': - endfly(); - return(0); + case 'q': + endfly(); + return (0); - default: - mvaddstr(0,26,"Commands = r,R,l,L,u,U,d,D,f,+,q"); - continue; + default: + mvaddstr(0, 26, "Commands = r,R,l,L,u,U,d,D,f,+,q"); + continue; - case EOF: - break; + case EOF: + break; } - if (destroyed){ + if (destroyed) { endfly(); - return(1); + return (1); } - if (gclock <= 0){ + if (gclock <= 0) { endfly(); die(0); } } /* NOTREACHED */ - return(1); + return (1); } static void screen(void) { - int r,c,n; + int r, c, n; int i; clear(); i = rnd(100); - for (n=0; n < i; n++){ - r = rnd(LINES-3) + 1; + for (n = 0; n < i; n++) { + r = rnd(LINES - 3) + 1; c = rnd(COLS); mvaddch(r, c, '.'); } - mvaddstr(LINES-1-1,21,"TORPEDOES FUEL TIME"); + mvaddstr(LINES - 1 - 1, 21, "TORPEDOES FUEL TIME"); refresh(); } @@ -205,11 +198,11 @@ target(void) { int n; - move(MIDR,MIDC-10); + move(MIDR, MIDC - 10); addstr("------- + -------"); - for (n = MIDR-4; n < MIDR-1; n++){ - mvaddch(n,MIDC,'|'); - mvaddch(n+6,MIDC,'|'); + for (n = MIDR - 4; n < MIDR - 1; n++) { + mvaddch(n, MIDC, '|'); + mvaddch(n + 6, MIDC, '|'); } } @@ -218,11 +211,11 @@ notarget(void) { int n; - move(MIDR,MIDC-10); + move(MIDR, MIDC - 10); addstr(" "); - for (n = MIDR-4; n < MIDR-1; n++){ - mvaddch(n,MIDC,' '); - mvaddch(n+6,MIDC,' '); + for (n = MIDR - 4; n < MIDR - 1; n++) { + mvaddch(n, MIDC, ' '); + mvaddch(n + 6, MIDC, ' '); } } @@ -232,17 +225,17 @@ blast(void) int n; alarm(0); - move(LINES-1, 24); + move(LINES - 1, 24); printw((char *)(uintptr_t)(const void *)"%3d", torps); - for(n = LINES-1-2; n >= MIDR + 1; n--){ - mvaddch(n, MIDC+MIDR-n, '/'); - mvaddch(n, MIDC-MIDR+n, '\\'); + for (n = LINES - 1 - 2; n >= MIDR + 1; n--) { + mvaddch(n, MIDC + MIDR - n, '/'); + mvaddch(n, MIDC - MIDR + n, '\\'); refresh(); } - mvaddch(MIDR,MIDC,'*'); - for(n = LINES-1-2; n >= MIDR + 1; n--){ - mvaddch(n, MIDC+MIDR-n, ' '); - mvaddch(n, MIDC-MIDR+n, ' '); + mvaddch(MIDR, MIDC, '*'); + for (n = LINES - 1 - 2; n >= MIDR + 1; n--) { + mvaddch(n, MIDC + MIDR - n, ' '); + mvaddch(n, MIDC - MIDR + n, ' '); refresh(); } alarm(1); @@ -257,17 +250,18 @@ moveenemy(int sig) sig = 0; oldr = row; oldc = column; - if (fuel > 0){ - if (row + dr <= LINES-3 && row + dr > 0) + if (fuel > 0) { + if (row + dr <= LINES - 3 && row + dr > 0) row += dr; - if (column + dc < COLS-1 && column + dc > 0) + if (column + dc < COLS - 1 && column + dc > 0) column += dc; - } else if (fuel < 0){ + } else if (fuel < 0) { fuel = 0; - mvaddstr(0,60,"*** Out of fuel ***"); + mvaddstr(0, 60, "*** Out of fuel ***"); } - d = (double) ((row - MIDR)*(row - MIDR) + (column - MIDC)*(column - MIDC)); - if (d < 16){ + d = (double)((row - MIDR) * (row - MIDR) + (column - MIDC) * + (column - MIDC)); + if (d < 16) { row += (rnd(9) - 4) % (4 - abs(row - MIDR)); column += (rnd(9) - 4) % (4 - abs(column - MIDC)); } @@ -276,11 +270,11 @@ moveenemy(int sig) if (cross) target(); mvaddstr(row, column - 1, "/-\\"); - move(LINES-1, 24); + move(LINES - 1, 24); printw((char *)(uintptr_t)(const void *)"%3d", torps); - move(LINES-1, 42); + move(LINES - 1, 42); printw((char *)(uintptr_t)(const void *)"%3d", fuel); - move(LINES-1, 57); + move(LINES - 1, 57); printw((char *)(uintptr_t)(const void *)"%3d", gclock); refresh(); signal(SIGALRM, moveenemy); @@ -292,7 +286,7 @@ endfly(void) { alarm(0); signal(SIGALRM, SIG_DFL); - mvcur(0,COLS-1,LINES-1,0); + mvcur(0, COLS - 1, LINES - 1, 0); endwin(); signal(SIGTSTP, SIG_DFL); signal(SIGINT, oldsig); diff --git a/games/battlestar/getcom.c b/games/battlestar/getcom.c index e50ec37841..9ff6d59d7f 100644 --- a/games/battlestar/getcom.c +++ b/games/battlestar/getcom.c @@ -1,4 +1,4 @@ -/* +/*- * Copyright (c) 1983, 1993 * The Regents of the University of California. All rights reserved. * @@ -10,11 +10,7 @@ * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. - * 4. Neither the name of the University nor the names of its contributors + * 3. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * @@ -73,22 +69,23 @@ getword(char *buf1, char *buf2, int flag) return (0); } while (*buf1 && !isspace(*buf1) && *buf1 != ',') - if (flag < 0) + if (flag < 0) { if (isupper(*buf1)) *buf2++ = tolower(*buf1++); else *buf2++ = *buf1++; - else if (flag > 0) + } else if (flag > 0) { if (islower(*buf1)) *buf2++ = toupper(*buf1++); else *buf2++ = *buf1++; - else + } else { *buf2++ = *buf1++; + } } else *buf2++ = *buf1++; *buf2 = 0; while (isspace(*buf1)) buf1++; - return (*buf1 ? buf1 : 0); + return (*buf1 ? buf1 : NULL); } diff --git a/games/battlestar/globals.c b/games/battlestar/globals.c index 79a5dad860..a31d524834 100644 --- a/games/battlestar/globals.c +++ b/games/battlestar/globals.c @@ -1,4 +1,4 @@ -/* +/*- * Copyright (c) 1983, 1993 * The Regents of the University of California. All rights reserved. * @@ -10,11 +10,7 @@ * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. - * 4. Neither the name of the University nor the names of its contributors + * 3. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * @@ -43,7 +39,7 @@ int CUMBER = MAXCUMBER; const char *const objdes[NUMOFOBJECTS] = { "There is a knife here", "There is an exquisitely crafted sword and scabbard here.", - 0, /* can land from here */ + NULL, /* Can land from here. */ "There is a fierce woodsman here brandishing a heavy mallet.", "There is an unwieldy two-handed sword here.", "There is a bloody meat cleaver here.", @@ -55,7 +51,7 @@ const char *const objdes[NUMOFOBJECTS] = { "There is a Viper ready for launch here.", "A kerosene lantern is burning luridly here.", "An old pair of shoes has been discarded here.", - 0, /* cylon */ + NULL, /* Cylon. */ "There is a pair of pajamas here.", "A kingly robe of royal purple and spun gold is draped here.", "There is a strange golden amulet on the floor here.", @@ -64,7 +60,7 @@ const char *const objdes[NUMOFOBJECTS] = { "A dead woodsman has fallen here. He was savagely murdered.", "A heavy wooden mallet lies nearby.", "There is a laser pistol here.", - "A flower-like young goddess is bathing in the hot mineral pools. She is \nwatching you, but continues to steep and sing softly.", + "A flower-like young goddess is bathing in the hot mineral pools. She is \nwatching you, but continues to steep and sing softly.", "The goddess is reclining on a bed of ferns and studying you intently.", "There is a grenade here", "There is a length of heavy chain here.", @@ -79,39 +75,39 @@ const char *const objdes[NUMOFOBJECTS] = { "I think I hear footsteps behind us.", "There are a few coins here.", "There are some matches here.", - "An unctuous man in a white suit and a dwarf are standing here.", - "There are some ripe papayas here.", - "There is a ripe pineapple here.", - "There are some kiwi fruit here.", - "There are some coconuts here.", - "There is a ripe mango here.", - "There is a sparkling diamond ring here.", - "There is a colorful pink potion in a small crystal vial here.", - "A gold bracelet is on the ground here.", - "A swarthy woman with stern features pulls you aside from the crowd,\n'I must talk to you -- but not here. Meet me at midnight in the gardens.'", - "The swarthy woman has been awaiting you anxiously. 'I must warn you that the\nIsland has anticipated your Quest. You will not be welcomed. The Darkness is\nstrong where you must search. Seek not the shadows save only at night, for\nthen are they the weakest. In the mountains far from here a canyon winds\nwith ferns and streams and forgotten vines. There you must go. Take this\nrope.'", - "Out from the shadows a figure leaps! His black cape swirls around, and he\nholds a laser sword at your chest. 'So, you have come to fulfill the Quest.\nHa! Your weapons are no match for me!'", - "An old timer with one eye missing and no money for a drink sits at the bar.", - "You are flying through an asteroid field!", - "A planet is nearby.", - "The ground is charred here.", - "There is a thermonuclear warhead here.", - "The fragile, beautiful young goddess lies here. You murdered her horribly.", - "The old timer is lying here. He is dead.", - "The native girl's body is lying here.", - "A native girl is sitting here.", - "A gorgeous white stallion is standing here.", - "The keys are in the ignition.", - "A pot of pearls and jewels is sitting here.", - "A bar of solid gold is here.", - "There is a 10 kilogram diamond block here." + "An unctuous man in a white suit and a dwarf are standing here.", + "There are some ripe papayas here.", + "There is a ripe pineapple here.", + "There are some kiwi fruit here.", + "There are some coconuts here.", + "There is a ripe mango here.", + "There is a sparkling diamond ring here.", + "There is a colorful pink potion in a small crystal vial here.", + "A gold bracelet is on the ground here.", + "A swarthy woman with stern features pulls you aside from the crowd,\n'I must talk to you -- but not here. Meet me at midnight in the gardens.'", + "The swarthy woman has been awaiting you anxiously. 'I must warn you that the\nIsland has anticipated your Quest. You will not be welcomed. The Darkness is\nstrong where you must search. Seek not the shadows save only at night, for\nthen are they the weakest. In the mountains far from here a canyon winds\nwith ferns and streams and forgotten vines. There you must go. Take this\nrope.'", + "Out from the shadows a figure leaps! His black cape swirls around, and he\nholds a laser sword at your chest. 'So, you have come to fulfill the Quest.\nHa! Your weapons are no match for me!'", + "An old timer with one eye missing and no money for a drink sits at the bar.", + "You are flying through an asteroid field!", + "A planet is nearby.", + "The ground is charred here.", + "There is a thermonuclear warhead here.", + "The fragile, beautiful young goddess lies here. You murdered her horribly.", + "The old timer is lying here. He is dead.", + "The native girl's body is lying here.", + "A native girl is sitting here.", + "A gorgeous white stallion is standing here.", + "The keys are in the ignition.", + "A pot of pearls and jewels is sitting here.", + "A bar of solid gold is here.", + "There is a 10 kilogram diamond block here." }; const char *const objsht[NUMOFOBJECTS] = { "knife", "fine sword", - 0, + NULL, /* Can land from here. */ "Woodsman", "two-handed sword", "meat cleaver", @@ -123,7 +119,7 @@ const char *const objsht[NUMOFOBJECTS] = { "viper", "lantern", "shoes", - 0, + NULL, /* Cylon. */ "pajamas", "robe", "amulet", @@ -132,8 +128,8 @@ const char *const objsht[NUMOFOBJECTS] = { "woodsman's body", "wooden mallet", "laser", - 0, - 0, + NULL, /* Bathing goddess. */ + NULL, /* Goddess. */ "grenade", "chain", "rope", @@ -142,12 +138,12 @@ const char *const objsht[NUMOFOBJECTS] = { "shovel", "halberd", "compass", - 0, + NULL, /* Crash debris. */ "Elf", - 0, + NULL, /* Footsteps. */ "coins", "match book", - 0, + NULL, /* Man and dwarf. */ "papayas", "pineapple", "kiwi", @@ -156,18 +152,18 @@ const char *const objsht[NUMOFOBJECTS] = { "ring", "potion", "bracelet", - 0, - 0, + NULL, /* Swarthy woman. */ + NULL, /* Swarthy woman (with message). */ "Dark Lord", - 0, - 0, - 0, - 0, + NULL, /* Old-timer. */ + NULL, /* Asteroid field. */ + NULL, /* Planet nearby. */ + NULL, /* Charred ground. */ "warhead", "goddess's body", "old timer's body", "girl's body", - 0, + NULL, /* Native girl. */ "stallion", "car", "pot of jewels", diff --git a/games/battlestar/init.c b/games/battlestar/init.c index 84544855f7..302d49a6e2 100644 --- a/games/battlestar/init.c +++ b/games/battlestar/init.c @@ -1,4 +1,4 @@ -/* +/*- * Copyright (c) 1983, 1993 * The Regents of the University of California. All rights reserved. * @@ -10,11 +10,7 @@ * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. - * 4. Neither the name of the University nor the names of its contributors + * 3. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * @@ -38,9 +34,9 @@ #include #include "externs.h" -static int checkout (const char *); -static void getutmp (char *); -static int wizard (const char *); +static int checkout(const char *); +static void getutmp(char *); +static int wizard(const char *); void initialize(int startup) diff --git a/games/battlestar/misc.c b/games/battlestar/misc.c index d396f02145..a0a87dc8f5 100644 --- a/games/battlestar/misc.c +++ b/games/battlestar/misc.c @@ -1,4 +1,4 @@ -/* +/*- * Copyright (c) 1983, 1993 * The Regents of the University of California. All rights reserved. * @@ -10,11 +10,7 @@ * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. - * 4. Neither the name of the University nor the names of its contributors + * 3. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * @@ -40,9 +36,11 @@ int card(const char *array, int size) /* for beenthere, injuries */ { - const char *end = array + size; - int i = 0; + const char *end; + int i; + i = 0; + end = array + size; while (array < end) if (*array++) i++; @@ -52,10 +50,11 @@ card(const char *array, int size) /* for beenthere, injuries */ int ucard(const unsigned int *array) { - int j = 0, n; + int j, n; + j = 0; for (n = 0; n < NUMOFOBJECTS; n++) if (testbit(array, n)) - j++; + j++; return (j); } diff --git a/games/battlestar/nightfile.c b/games/battlestar/nightfile.c index f21ad2642e..b162640638 100644 --- a/games/battlestar/nightfile.c +++ b/games/battlestar/nightfile.c @@ -1,4 +1,4 @@ -/* +/*- * Copyright (c) 1983, 1993 * The Regents of the University of California. All rights reserved. * @@ -10,11 +10,7 @@ * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. - * 4. Neither the name of the University nor the names of its contributors + * 3. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * diff --git a/games/battlestar/nightobjs.c b/games/battlestar/nightobjs.c index 5ffca8619c..42321cb32f 100644 --- a/games/battlestar/nightobjs.c +++ b/games/battlestar/nightobjs.c @@ -1,4 +1,4 @@ -/* +/*- * Copyright (c) 1983, 1993 * The Regents of the University of California. All rights reserved. * @@ -10,11 +10,7 @@ * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. - * 4. Neither the name of the University nor the names of its contributors + * 3. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * diff --git a/games/battlestar/parse.c b/games/battlestar/parse.c index 61d04f56f5..d23c9584fb 100644 --- a/games/battlestar/parse.c +++ b/games/battlestar/parse.c @@ -1,4 +1,4 @@ -/* +/*- * Copyright (c) 1983, 1993 * The Regents of the University of California. All rights reserved. * @@ -10,11 +10,7 @@ * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. - * 4. Neither the name of the University nor the names of its contributors + * 3. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * @@ -37,9 +33,9 @@ #include "externs.h" -static int hash (const char *); -static void install (struct wlist *); -static struct wlist *lookup (const char *); +static int hash(const char *); +static void install(struct wlist *); +static struct wlist *lookup(const char *); void wordinit(void) @@ -53,8 +49,9 @@ wordinit(void) static int hash(const char *s) { - int hashval = 0; + int hashval; + hashval = 0; while (*s) { hashval += *s++; hashval *= HASHMUL; @@ -93,14 +90,14 @@ parse(void) struct wlist *wp; int n; - wordnumber = 0; /* for cypher */ + wordnumber = 0; /* for cypher */ for (n = 0; n <= wordcount; n++) { if ((wp = lookup(words[n])) == NULL) { wordvalue[n] = -1; wordtype[n] = -1; } else { - wordvalue[n] = wp -> value; - wordtype[n] = wp -> article; + wordvalue[n] = wp->value; + wordtype[n] = wp->article; } } } diff --git a/games/battlestar/pathnames.h b/games/battlestar/pathnames.h index 25901945d5..8b4f9c6c3f 100644 --- a/games/battlestar/pathnames.h +++ b/games/battlestar/pathnames.h @@ -10,11 +10,7 @@ * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. - * 4. Neither the name of the University nor the names of its contributors + * 3. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * diff --git a/games/battlestar/room.c b/games/battlestar/room.c index e1a7100906..5f333196de 100644 --- a/games/battlestar/room.c +++ b/games/battlestar/room.c @@ -1,4 +1,4 @@ -/* +/*- * Copyright (c) 1983, 1993 * The Regents of the University of California. All rights reserved. * @@ -10,11 +10,7 @@ * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. - * 4. Neither the name of the University nor the names of its contributors + * 3. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * @@ -47,10 +43,10 @@ writedes(void) printf("\n\t%s\n", location[position].name); if (beenthere[position] < 3) { compass = NORTH; - for ((p = location[position].desc); (c = *p++);) - if (c != '-' && c != '*' && c != '+') + for (p = location[position].desc; (c = *p++) != 0;) + if (c != '-' && c != '*' && c != '+') { putchar((int)c); - else { + } else { if (c != '*') printf("%s", truedirec(compass, c)); compass++; @@ -61,9 +57,10 @@ writedes(void) void printobjs(void) { - unsigned int *p = location[position].objects; + unsigned int *p; int n; + p = location[position].objects; printf("\n"); for (n = 0; n < NUMOFOBJECTS; n++) if (testbit(p, n) && objdes[n]) @@ -73,154 +70,151 @@ printobjs(void) void whichway(struct room here) { - switch(direction) { - - case NORTH: - left = here.west; - right = here.east; - ahead = here.north; - back = here.south; - break; - - case SOUTH: - left = here.east; - right = here.west; - ahead = here.south; - back = here.north; - break; - - case EAST: - left = here.north; - right = here.south; - ahead = here.east; - back = here.west; - break; - - case WEST: - left = here.south; - right = here.north; - ahead = here.west; - back = here.east; - break; - + switch (direction) { + case NORTH: + left = here.west; + right = here.east; + ahead = here.north; + back = here.south; + break; + + case SOUTH: + left = here.east; + right = here.west; + ahead = here.south; + back = here.north; + break; + + case EAST: + left = here.north; + right = here.south; + ahead = here.east; + back = here.west; + break; + + case WEST: + left = here.south; + right = here.north; + ahead = here.west; + back = here.east; + break; } } const char * truedirec(int way, unsigned int option) { - switch(way) { - + switch (way) { + case NORTH: + switch (direction) { case NORTH: - switch(direction) { - case NORTH: - return("ahead"); - case SOUTH: - return(option == '+' ? "behind you" : "back"); - case EAST: - return("left"); - case WEST: - return("right"); - } + return ("ahead"); + case SOUTH: + return (option == '+' ? "behind you" : "back"); + case EAST: + return ("left"); + case WEST: + return ("right"); + } + case SOUTH: + switch (direction) { + case NORTH: + return (option == '+' ? "behind you" : "back"); case SOUTH: - switch(direction) { - case NORTH: - return(option == '+' ? "behind you" : "back"); - case SOUTH: - return("ahead"); - case EAST: - return("right"); - case WEST: - return("left"); - } + return ("ahead"); + case EAST: + return ("right"); + case WEST: + return ("left"); + } + case EAST: + switch (direction) { + case NORTH: + return ("right"); + case SOUTH: + return ("left"); case EAST: - switch(direction) { - case NORTH: - return("right"); - case SOUTH: - return("left"); - case EAST: - return("ahead"); - case WEST: - return(option == '+' ? "behind you" : "back"); - } + return ("ahead"); + case WEST: + return (option == '+' ? "behind you" : "back"); + } + case WEST: + switch (direction) { + case NORTH: + return ("left"); + case SOUTH: + return ("right"); + case EAST: + return (option == '+' ? "behind you" : "back"); case WEST: - switch(direction) { - case NORTH: - return("left"); - case SOUTH: - return("right"); - case EAST: - return(option == '+' ? "behind you" : "back"); - case WEST: - return("ahead"); - } + return ("ahead"); + } - default: - printf("Error: room %d. More than four directions wanted.", position); - return("!!"); - } + default: + printf("Error: room %d. More than four directions wanted.", + position); + return ("!!"); + } } void newway(int thisway) { - switch(direction){ - - case NORTH: - switch(thisway){ - case LEFT: - direction = WEST; - break; - case RIGHT: - direction = EAST; - break; - case BACK: - direction = SOUTH; - break; - } + switch (direction) { + case NORTH: + switch (thisway) { + case LEFT: + direction = WEST; break; - case SOUTH: - switch(thisway){ - case LEFT: - direction = EAST; - break; - case RIGHT: - direction = WEST; - break; - case BACK: - direction = NORTH; - break; - } + case RIGHT: + direction = EAST; break; - case EAST: - switch(thisway){ - case LEFT: - direction = NORTH; - break; - case RIGHT: - direction = SOUTH; - break; - case BACK: - direction = WEST; - break; - } + case BACK: + direction = SOUTH; break; - case WEST: - switch(thisway){ - case LEFT: - direction = SOUTH; - break; - case RIGHT: - direction = NORTH; - break; - case BACK: - direction = EAST; - break; - } + } + break; + case SOUTH: + switch (thisway) { + case LEFT: + direction = EAST; + break; + case RIGHT: + direction = WEST; + break; + case BACK: + direction = NORTH; + break; + } + break; + case EAST: + switch (thisway) { + case LEFT: + direction = NORTH; break; - } + case RIGHT: + direction = SOUTH; + break; + case BACK: + direction = WEST; + break; + } + break; + case WEST: + switch (thisway) { + case LEFT: + direction = SOUTH; + break; + case RIGHT: + direction = NORTH; + break; + case BACK: + direction = EAST; + break; + } + break; + } } diff --git a/games/battlestar/save.c b/games/battlestar/save.c index 1214105514..1ddfa44433 100644 --- a/games/battlestar/save.c +++ b/games/battlestar/save.c @@ -1,4 +1,4 @@ -/* +/*- * Copyright (c) 1983, 1993 * The Regents of the University of California. All rights reserved. * @@ -10,11 +10,7 @@ * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. - * 4. Neither the name of the University nor the names of its contributors + * 3. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * @@ -49,9 +45,10 @@ restore(void) int tmp; FILE *fp; - if ( (home = getenv("HOME")) != NULL) - sprintf(home1, "%.*s/Bstar", MAXPATHLEN - 7, home); - else return; + if ((home = getenv("HOME")) != NULL) + sprintf(home1, "%.*s/Bstar", MAXPATHLEN - 7, home); + else + return; if ((fp = fopen(home1, "r")) == 0) { perror(home1); @@ -91,7 +88,7 @@ restore(void) fread(&loved, sizeof loved, 1, fp); fread(&pleasure, sizeof pleasure, 1, fp); fread(&power, sizeof power, 1, fp); - /* We must check the last read, to catch truncated save files. */ + /* We must check the last read, to catch truncated save files. */ if (fread(&ego, sizeof ego, 1, fp) < 1) errx(1, "save file %s too short", home1); fclose(fp); @@ -113,7 +110,7 @@ save(void) sprintf(home1, "%.*s/Bstar", MAXPATHLEN - 7, home); /* Try to open the file safely. */ - if (stat(home1, &sbuf) < 0) { + if (stat(home1, &sbuf) < 0) { fd = open(home1, O_WRONLY|O_CREAT|O_EXCL, 0600); if (fd < 0) { fprintf(stderr, "Can't create %s\n", home1); @@ -136,7 +133,6 @@ save(void) perror(home1); return; } - printf("Saved in %s.\n", home1); fwrite(&WEIGHT, sizeof WEIGHT, 1, fp); fwrite(&CUMBER, sizeof CUMBER, 1, fp); diff --git a/games/battlestar/words.c b/games/battlestar/words.c index 5e657480e1..2bb6b808b5 100644 --- a/games/battlestar/words.c +++ b/games/battlestar/words.c @@ -1,4 +1,4 @@ -/* +/*- * Copyright (c) 1983, 1993 * The Regents of the University of California. All rights reserved. * @@ -10,11 +10,7 @@ * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. - * 4. Neither the name of the University nor the names of its contributors + * 3. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * @@ -202,5 +198,5 @@ struct wlist wlist[] = { { "move", 0, ADJS, NULL }, { "make", 0, ADJS, NULL }, { "to", 0, ADJS, NULL }, - { 0, 0, 0, NULL } + { NULL, 0, 0, NULL } }; diff --git a/games/bcd/bcd.6 b/games/bcd/bcd.6 index c4a8120035..e2c2a97349 100644 --- a/games/bcd/bcd.6 +++ b/games/bcd/bcd.6 @@ -9,11 +9,7 @@ .\" 2. Redistributions in binary form must reproduce the above copyright .\" notice, this list of conditions and the following disclaimer in the .\" documentation and/or other materials provided with the distribution. -.\" 3. All advertising materials mentioning features or use of this software -.\" must display the following acknowledgement: -.\" This product includes software developed by the University of -.\" California, Berkeley and its contributors. -.\" 4. Neither the name of the University nor the names of its contributors +.\" 3. Neither the name of the University nor the names of its contributors .\" may be used to endorse or promote products derived from this software .\" without specific prior written permission. .\" diff --git a/games/bcd/bcd.c b/games/bcd/bcd.c index 83bf9a47e2..530d05959e 100644 --- a/games/bcd/bcd.c +++ b/games/bcd/bcd.c @@ -1,4 +1,4 @@ -/* +/*- * Copyright (c) 1989, 1993 * The Regents of the University of California. All rights reserved. * @@ -13,11 +13,7 @@ * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. - * 4. Neither the name of the University nor the names of its contributors + * 3. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * @@ -73,10 +69,8 @@ #include #include -#include #include - -static void printcard(char *); +#include u_short holes[256] = { 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, @@ -118,6 +112,8 @@ u_short holes[256] = { */ #define bit(w,i) ((w)&(1<<(i))) +static void printcard(char *); + int main(int argc, char **argv) { @@ -137,7 +133,7 @@ main(int argc, char **argv) } else while (fgets(cardline, sizeof(cardline), stdin)) printcard(cardline); - return(0); + return (0); } #define COLUMNS 48 diff --git a/games/bs/bs.c b/games/bs/bs.c index f4c3a6f388..14aa2d8515 100644 --- a/games/bs/bs.c +++ b/games/bs/bs.c @@ -1,4 +1,4 @@ -/* +/*- * bs.c - original author: Bruce Holloway * salvo option by: Chuck A DeGaul * with improved user interface, autoconfiguration and code cleanup @@ -19,16 +19,6 @@ #include #include -#ifndef A_UNDERLINE /* BSD curses */ -#define beep() write(1,"\007",1); -#define cbreak crmode -#define saveterm savetty -#define resetterm resetty -#define nocbreak nocrmode -#define strchr index -#endif /* !A_UNDERLINE */ - - /* * Constants for tuning the random-fire algorithm. It prefers moves that * diagonal-stripe the board with a stripe separation of srchstep. If @@ -158,18 +148,18 @@ uninitgame(void) } static void -sighandler(__unused int sig) +sighandler(__unused int sig) { uninitgame(); } /* announce which game options are enabled */ static void -announceopts(void) +announceopts(void) { printw("Playing %s game (", (salvo || blitz || closepack) ? "optional" : "standard"); - + if (salvo) printw("salvo, "); else @@ -187,7 +177,7 @@ announceopts(void) } static void -intro(void) +intro(void) { char *tmpname; @@ -252,7 +242,7 @@ intro(void) /* print a message at the prompt line */ static void -prompt(int n, const char *f, ...) +prompt(int n, const char *f, ...) { char buf[COLWIDTH + 1]; va_list ap; @@ -267,7 +257,7 @@ prompt(int n, const char *f, ...) } static void -error(const char *s) +error(const char *s) { move(PROMPTLINE + 2, 0); clrtoeol(); @@ -278,7 +268,7 @@ error(const char *s) } static void -placeship(int b, ship_t *ss, int vis) +placeship(int b, ship_t *ss, int vis) { int l; @@ -296,14 +286,14 @@ placeship(int b, ship_t *ss, int vis) } static int -rnd(int n) +rnd(int n) { return(random() % n); } /* generate a valid random ship placement into px,py */ static void -randomplace(int b, ship_t *ss) +randomplace(int b, ship_t *ss) { do { ss->y = rnd(BDEPTH); @@ -313,7 +303,7 @@ randomplace(int b, ship_t *ss) } static void -initgame(void) +initgame(void) { int i, j, unplaced; ship_t *ss; @@ -507,7 +497,7 @@ initgame(void) } static int -getcoord(int atcpu) +getcoord(int atcpu) { int ny, nx, c; @@ -599,7 +589,7 @@ getcoord(int atcpu) /* is this location on the selected zboard adjacent to a ship? */ static int -collidecheck(int b, int y, int x) +collidecheck(int b, int y, int x) { int collide; @@ -613,7 +603,7 @@ collidecheck(int b, int y, int x) for (i = 0; i < 8; i++) { int xend, yend; - + yend = y + yincr[i]; xend = x + xincr[i]; if (ONBOARD(xend, yend)) @@ -625,7 +615,7 @@ collidecheck(int b, int y, int x) } static bool -checkplace(int b, ship_t *ss, int vis) +checkplace(int b, ship_t *ss, int vis) { int l, xend, yend; @@ -690,7 +680,7 @@ awinna(void) /* a hit on the targeted ship */ static ship_t * -hitship(int x, int y) +hitship(int x, int y) { ship_t *sb, *ss; char sym; @@ -712,10 +702,10 @@ hitship(int x, int y) for (j = -1; j <= 1; j++) { int bx = ss->x + j * xincr[(ss->dir + 2) % 8]; int by = ss->y + j * yincr[(ss->dir + 2) % 8]; - + for (i = -1; i <= ss->length; ++i) { int cx, cy; - + cx = bx + i * xincr[ss->dir]; cy = by + i * yincr[ss->dir]; if (ONBOARD(cx, cy)) { @@ -726,7 +716,7 @@ hitship(int x, int y) if (has_colors()) attron(COLOR_PAIR(COLOR_GREEN)); #endif /* A_COLOR */ - + addch(MARK_MISS); #ifdef A_COLOR attrset(0); @@ -759,7 +749,7 @@ hitship(int x, int y) } static int -plyturn(void) +plyturn(void) { ship_t *ss; bool hit; @@ -823,7 +813,7 @@ plyturn(void) } static int -sgetc(const char *s) +sgetc(const char *s) { const char *s1; int ch; @@ -850,7 +840,7 @@ sgetc(const char *s) /* random-fire routine -- implements simple diagonal-striping strategy */ static void -randomfire(int *px, int *py) +randomfire(int *px, int *py) { static int turncount = 0; static int srchstep = BEGINSTEP; @@ -910,7 +900,7 @@ randomfire(int *px, int *py) /* fire away at given location */ static bool -cpufire(int x, int y) +cpufire(int x, int y) { bool hit, sunk; ship_t *ss; @@ -948,7 +938,7 @@ cpufire(int x, int y) * between computer turns. */ static bool -cputurn(void) +cputurn(void) { #define POSSIBLE(x, y) (ONBOARD(x, y) && !hits[COMPUTER][x][y]) #define RANDOM_FIRE 0 @@ -1072,8 +1062,8 @@ cputurn(void) return(hit); } -int -playagain(void) +int +playagain(void) { int j; ship_t *ss; @@ -1097,7 +1087,7 @@ playagain(void) } else if(cpuwon >= 10) { ++j; } - + mvprintw(1,(COLWIDTH-j)/2, "%s: %d Computer: %d",name,plywon,cpuwon); @@ -1107,7 +1097,7 @@ playagain(void) } static void -usage(void) +usage(void) { fprintf(stderr, "Usage: battle [-s | -b] [-c]\n"); fprintf(stderr, "\tWhere the options are:\n"); @@ -1119,7 +1109,7 @@ usage(void) } static int -scount(int who) +scount(int who) { int i, shots; ship_t *sp; @@ -1140,7 +1130,7 @@ scount(int who) } int -main(int argc, char **argv) +main(int argc, char **argv) { int ch; @@ -1165,7 +1155,7 @@ main(int argc, char **argv) } argc -= optind; argv += optind; - + if (blitz && salvo) usage(); @@ -1179,7 +1169,7 @@ main(int argc, char **argv) continue; } else if (salvo) { int i; - + i = scount(turn); while (i--) { if (turn) { diff --git a/games/caesar/caesar.6 b/games/caesar/caesar.6 index 73f0eec0a6..08c4ae98ba 100644 --- a/games/caesar/caesar.6 +++ b/games/caesar/caesar.6 @@ -9,11 +9,7 @@ .\" 2. Redistributions in binary form must reproduce the above copyright .\" notice, this list of conditions and the following disclaimer in the .\" documentation and/or other materials provided with the distribution. -.\" 3. All advertising materials mentioning features or use of this software -.\" must display the following acknowledgement: -.\" This product includes software developed by the University of -.\" California, Berkeley and its contributors. -.\" 4. Neither the name of the University nor the names of its contributors +.\" 3. Neither the name of the University nor the names of its contributors .\" may be used to endorse or promote products derived from this software .\" without specific prior written permission. .\" diff --git a/games/caesar/caesar.c b/games/caesar/caesar.c index d71430f9a8..4fdacd1845 100644 --- a/games/caesar/caesar.c +++ b/games/caesar/caesar.c @@ -1,4 +1,4 @@ -/* +/*- * Copyright (c) 1989, 1993 * The Regents of the University of California. All rights reserved. * @@ -18,11 +18,7 @@ * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. - * 4. Neither the name of the University nor the names of its contributors + * 3. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * @@ -55,30 +51,42 @@ #include #include +#define LETTERS 26 #define LINELENGTH 2048 #define ROTATE(ch, perm) \ isascii(ch) ? ( \ - isupper(ch) ? ('A' + (ch - 'A' + perm) % 26) : \ - islower(ch) ? ('a' + (ch - 'a' + perm) % 26) : ch) : ch + isupper(ch) ? ('A' + (ch - 'A' + perm) % LETTERS) : \ + islower(ch) ? ('a' + (ch - 'a' + perm) % LETTERS) : ch) : ch /* * letter frequencies (taken from some unix(tm) documentation) * (unix is a trademark of Bell Laboratories) */ -static double stdf[26] = { +static double stdf[LETTERS] = { 7.97, 1.35, 3.61, 4.78, 12.37, 2.01, 1.46, 4.49, 6.39, 0.04, 0.42, 3.81, 2.69, 5.92, 6.96, 2.91, 0.08, 6.63, 8.77, 9.68, - 2.62, 0.81, 1.88, 0.23, 2.07, 0.06, + 2.62, 0.81, 1.88, 0.23, 2.07, 0.06 }; -static void printit(const char *); +static void +printit(const char *arg) +{ + int ch, rot; + + if ((rot = atoi(arg)) < 0) + errx(1, "bad rotation value"); + + while ((ch = getchar()) != EOF) + putchar(ROTATE(ch, rot)); + exit(0); +} int -main(int argc, char **argv) +main(int argc, char *argv[]) { - int ch, dot, i, nread, winnerdot = 0; + int ch, dot, i, nread, winnerdot; char *inbuf; - int obs[26], try, winner; + int obs[LETTERS], try, winner; /* revoke setgid privileges */ setgid(getgid()); @@ -90,11 +98,11 @@ main(int argc, char **argv) err(1, "malloc failed"); /* adjust frequency table to weight low probs REAL low */ - for (i = 0; i < 26; ++i) - stdf[i] = log(stdf[i]) + log(26.0 / 100.0); + for (i = 0; i < LETTERS; i++) + stdf[i] = log(stdf[i]) + log(LETTERS / 100.0); /* zero out observation table */ - bzero(obs, 26 * sizeof(int)); + bzero(obs, LETTERS * sizeof(int)); if ((nread = read(STDIN_FILENO, inbuf, LINELENGTH)) < 0) err(1, "read failed"); @@ -112,10 +120,12 @@ main(int argc, char **argv) * now "dot" the freqs with the observed letter freqs * and keep track of best fit */ - for (try = winner = 0; try < 26; ++try) { /* += 13) { */ + winner = 0; + winnerdot = 0; + for (try = 0; try < LETTERS; try++) { dot = 0; - for (i = 0; i < 26; i++) - dot += obs[i] * stdf[(i + try) % 26]; + for (i = 0; i < LETTERS; i++) + dot += obs[i] * stdf[(i + try) % LETTERS]; /* initialize winning score */ if (try == 0) winnerdot = dot; @@ -138,16 +148,3 @@ main(int argc, char **argv) } exit(0); } - -static void -printit(const char *arg) -{ - int ch, rot; - - if ((rot = atoi(arg)) < 0) - errx(1, "bad rotation value"); - - while ((ch = getchar()) != EOF) - putchar(ROTATE(ch, rot)); - exit(0); -} diff --git a/games/caesar/rot13.sh b/games/caesar/rot13.sh index 1b88b63b3f..d68ac42864 100644 --- a/games/caesar/rot13.sh +++ b/games/caesar/rot13.sh @@ -11,11 +11,7 @@ # 2. Redistributions in binary form must reproduce the above copyright # notice, this list of conditions and the following disclaimer in the # documentation and/or other materials provided with the distribution. -# 3. All advertising materials mentioning features or use of this software -# must display the following acknowledgement: -# This product includes software developed by the University of -# California, Berkeley and its contributors. -# 4. Neither the name of the University nor the names of its contributors +# 3. Neither the name of the University nor the names of its contributors # may be used to endorse or promote products derived from this software # without specific prior written permission. # diff --git a/games/canfield/canfield/canfield.6 b/games/canfield/canfield/canfield.6 index 074a653a78..396ffd5b1a 100644 --- a/games/canfield/canfield/canfield.6 +++ b/games/canfield/canfield/canfield.6 @@ -9,11 +9,7 @@ .\" 2. Redistributions in binary form must reproduce the above copyright .\" notice, this list of conditions and the following disclaimer in the .\" documentation and/or other materials provided with the distribution. -.\" 3. All advertising materials mentioning features or use of this software -.\" must display the following acknowledgement: -.\" This product includes software developed by the University of -.\" California, Berkeley and its contributors. -.\" 4. Neither the name of the University nor the names of its contributors +.\" 3. Neither the name of the University nor the names of its contributors .\" may be used to endorse or promote products derived from this software .\" without specific prior written permission. .\" diff --git a/games/canfield/canfield/canfield.c b/games/canfield/canfield/canfield.c index 759b8a1ef9..fd91c7f993 100644 --- a/games/canfield/canfield/canfield.c +++ b/games/canfield/canfield/canfield.c @@ -1,4 +1,4 @@ -/* +/*- * Copyright (c) 1980, 1993 * The Regents of the University of California. All rights reserved. * @@ -10,11 +10,7 @@ * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. - * 4. Neither the name of the University nor the names of its contributors + * 3. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * @@ -49,14 +45,14 @@ #include -#include #include +#include +#include #include -#include #include #include -#include #include +#include #include "pathnames.h" @@ -204,7 +200,7 @@ static bool finish(void); static void fndbase(struct cardtype **, int, int); static void getcmd(int, int, const char *); static void initall(void); -static void initdeck(struct cardtype **); +static void initdeck(struct cardtype *[]); static void initgame(void); static void instruct(void); static void makeboard(void); @@ -225,7 +221,7 @@ static void removecard(int, int); static bool samesuit(struct cardtype *, int); static void showcards(void); static void showstat(void); -static void shuffle(struct cardtype **); +static void shuffle(struct cardtype *[]); static void simpletableau(struct cardtype **, int); static void startgame(void); static void suspend(void); @@ -505,7 +501,7 @@ cleanupboard(void) * procedure to create a deck of cards */ static void -initdeck(struct cardtype **ldeck) +initdeck(struct cardtype *ideck[]) { int i; int scnt; @@ -516,7 +512,7 @@ initdeck(struct cardtype **ldeck) for (scnt=0; scnt<4; scnt++) { s = suitmap[scnt]; for (r=Ace; r<=King; r++) { - ldeck[i] = &cards[i]; + ideck[i] = &cards[i]; cards[i].rank = r; cards[i].suit = s; cards[i].color = colormap[scnt]; @@ -530,21 +526,21 @@ initdeck(struct cardtype **ldeck) * procedure to shuffle the deck */ static void -shuffle(struct cardtype **ldeck) +shuffle(struct cardtype *ideck[]) { int i,j; struct cardtype *temp; for (i=0; ivisible = FALSE; - ldeck[i]->paid = FALSE; + ideck[i]->visible = FALSE; + ideck[i]->paid = FALSE; } for (i = decksize-1; i>=0; i--) { j = random() % decksize; if (i != j) { - temp = ldeck[i]; - ldeck[i] = ldeck[j]; - ldeck[j] = temp; + temp = ideck[i]; + ideck[i] = ideck[j]; + ideck[j] = temp; } } } @@ -1235,7 +1231,8 @@ tabtotab(int sour, int des) temp->next = tableau[des]; tableau[des] = tableau[sour]; tableau[sour] = NIL; - length[des] = length[des] + (length[sour] - (tabrow - 1)); + length[des] = length[des] + + (length[sour] - (tabrow - 1)); length[sour] = tabrow - 1; timesthru = 0; } else @@ -1297,12 +1294,15 @@ movetofound(struct cardtype **cp, int source) timesthru = 0; if (mtforigin == stk) { usedstock(); - printcard(stockcol, stockrow, stock); + printcard(stockcol, stockrow, + stock); } else if (mtforigin == tal) { usedtalon(); - printcard(taloncol, talonrow, talon); + printcard(taloncol, talonrow, + talon); } else { - removecard(pilemap[source], length[source]); + removecard(pilemap[source], + length[source]); length[source]--; } cardsoff++; @@ -1698,7 +1698,7 @@ finish(void) * procedure to clean up and exit */ static void -cleanup(__unused int sig) +cleanup(int sig __unused) { total.thinktime += 1; @@ -1721,7 +1721,7 @@ cleanup(__unused int sig) * Field an interrupt. */ static void -askquit(__unused int sig) +askquit(int sig __unused) { move(msgrow, msgcol); printw("Really wish to quit? "); @@ -1761,7 +1761,6 @@ main(void) raw(); noecho(); initall(); - instruct(); makeboard(); for (;;) { diff --git a/games/canfield/canfield/pathnames.h b/games/canfield/canfield/pathnames.h index e187698c80..4b29579d30 100644 --- a/games/canfield/canfield/pathnames.h +++ b/games/canfield/canfield/pathnames.h @@ -10,11 +10,7 @@ * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. - * 4. Neither the name of the University nor the names of its contributors + * 3. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * diff --git a/games/canfield/cfscores/cfscores.c b/games/canfield/cfscores/cfscores.c index dd0392a34b..a1d8d7591e 100644 --- a/games/canfield/cfscores/cfscores.c +++ b/games/canfield/cfscores/cfscores.c @@ -1,4 +1,4 @@ -/* +/*- * Copyright (c) 1983, 1993 * The Regents of the University of California. All rights reserved. * @@ -10,11 +10,7 @@ * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. - * 4. Neither the name of the University nor the names of its contributors + * 3. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * @@ -37,12 +33,12 @@ */ #include -#include #include -#include +#include #include #include #include +#include #include "pathnames.h" struct betinfo { @@ -58,10 +54,10 @@ struct betinfo { int dbfd; -static void printuser(struct passwd *, int); +static void printuser(struct passwd *, int); int -main(int argc, char **argv) +main(int argc, char *argv[]) { struct passwd *pw; int uid; @@ -98,7 +94,7 @@ main(int argc, char **argv) exit(3); } printuser(pw, 1); - return(0); + return (0); } /* diff --git a/games/cribbage/cards.c b/games/cribbage/cards.c index 0411810423..fd4db3df51 100644 --- a/games/cribbage/cards.c +++ b/games/cribbage/cards.c @@ -10,11 +10,7 @@ * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. - * 4. Neither the name of the University nor the names of its contributors + * 3. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * @@ -35,11 +31,12 @@ * $DragonFly: src/games/cribbage/cards.c,v 1.3 2005/08/03 13:31:00 eirikn Exp $ */ +#include #include +#include "deck.h" #include "cribbage.h" -static bool eq(CARD, CARD); /* * Initialize a deck of cards to contain one of each type. */ diff --git a/games/cribbage/crib.c b/games/cribbage/crib.c index dd4481dcf6..8947bc8c59 100644 --- a/games/cribbage/crib.c +++ b/games/cribbage/crib.c @@ -10,11 +10,7 @@ * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. - * 4. Neither the name of the University nor the names of its contributors + * 3. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * @@ -36,11 +32,13 @@ * $DragonFly: src/games/cribbage/crib.c,v 1.3 2005/08/03 13:31:00 eirikn Exp $ */ +#include #include #include #include #include +#include "deck.h" #include "cribbage.h" #include "cribcur.h" #include "pathnames.h" @@ -88,7 +86,7 @@ main(int argc, char *argv[]) initscr(); signal(SIGINT, intr); - crmode(); + cbreak(); noecho(); Playwin = subwin(stdscr, PLAY_Y, PLAY_X, 0, 0); @@ -108,7 +106,7 @@ main(int argc, char *argv[]) mvcur(0, COLS - 1, LINES - 1, 0); fflush(stdout); instructions(); - crmode(); + cbreak(); noecho(); clear(); refresh(); @@ -138,7 +136,7 @@ main(int argc, char *argv[]) fprintf(stderr, "\ncribbage: can't open %s.\n", _PATH_LOG); exit(1); } - return(0); + return (0); } /* @@ -295,14 +293,14 @@ playhand(bool mycrib) prhand(phand, FULLHAND, Playwin, false); discard(mycrib); if (cut(mycrib, deckpos)) - return true; + return (true); if (peg(mycrib)) - return true; + return (true); werase(Tablewin); wrefresh(Tablewin); if (scoreh(mycrib)) - return true; - return false; + return (true); + return (false); } /* diff --git a/games/cribbage/cribbage.6 b/games/cribbage/cribbage.6 index 28751db99e..c5346cb381 100644 --- a/games/cribbage/cribbage.6 +++ b/games/cribbage/cribbage.6 @@ -9,11 +9,7 @@ .\" 2. Redistributions in binary form must reproduce the above copyright .\" notice, this list of conditions and the following disclaimer in the .\" documentation and/or other materials provided with the distribution. -.\" 3. All advertising materials mentioning features or use of this software -.\" must display the following acknowledgement: -.\" This product includes software developed by the University of -.\" California, Berkeley and its contributors. -.\" 4. Neither the name of the University nor the names of its contributors +.\" 3. Neither the name of the University nor the names of its contributors .\" may be used to endorse or promote products derived from this software .\" without specific prior written permission. .\" diff --git a/games/cribbage/cribbage.h b/games/cribbage/cribbage.h index eebddf2e08..9a90d1a96f 100644 --- a/games/cribbage/cribbage.h +++ b/games/cribbage/cribbage.h @@ -1,4 +1,4 @@ -/* +/*- * Copyright (c) 1980, 1993 * The Regents of the University of California. All rights reserved. * @@ -10,11 +10,7 @@ * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. - * 4. Neither the name of the University nor the names of its contributors + * 3. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * @@ -34,9 +30,6 @@ * $DragonFly: src/games/cribbage/cribbage.h,v 1.3 2005/08/03 13:31:00 eirikn Exp $ */ -#include - -#include "deck.h" extern CARD deck[ CARDS ]; /* a deck */ extern CARD phand[ FULLHAND ]; /* player's hand */ @@ -63,32 +56,32 @@ extern bool quiet; /* if suppress random mess */ extern char explstr[]; /* string for explanation */ -void addmsg (const char *, ...); -int adjust (CARD []); -bool anymove (CARD [], int, int); -void bye (void); -int cchose (CARD [], int, int); -void cdiscard (bool); -bool chkscr (int *, int); -bool comphand (CARD [], const char *); -void cremove (CARD, CARD [], int); -void do_wait (void); -void endmsg (void); -char *getline (void); -int getuchar (void); -int infrom (CARD [], int, const char *); -void instructions (void); -void intr (int); -bool isone (CARD, CARD [], int); -void makedeck (CARD []); -void makeknown (CARD [], int); -void msg (const char *, ...); -bool msgcard (CARD, bool); -int number (int, int, const char *); -int pegscore (CARD, CARD [], int, int); -bool plyrhand (CARD [], const char *); -void prcard (WINDOW *, int, int, CARD, bool); -void prhand (CARD [], int, WINDOW *, bool); -int scorehand (CARD [], CARD, int, bool, bool); -void shuffle (CARD []); -void sorthand (CARD [], int); +void addmsg(const char *, ...); +int adjust(CARD []); +bool anymove(CARD [], int, int); +void bye(void); +int cchose(CARD [], int, int); +void cdiscard(bool); +bool chkscr(int *, int); +bool comphand(CARD [], const char *); +void cremove(CARD, CARD [], int); +void do_wait(void); +void endmsg(void); +char *getline(void); +int getuchar(void); +int infrom(CARD [], int, const char *); +void instructions(void); +void intr(int); +bool isone(CARD, CARD [], int); +void makedeck(CARD []); +void makeknown(CARD [], int); +void msg(const char *, ...); +bool msgcard(CARD, bool); +int number(int, int, const char *); +int pegscore(CARD, CARD [], int, int); +bool plyrhand(CARD [], const char *); +void prcard(WINDOW *, int, int, CARD, bool); +void prhand(CARD [], int, WINDOW *, bool); +int scorehand(CARD [], CARD, int, bool, bool); +void shuffle(CARD []); +void sorthand(CARD [], int); diff --git a/games/cribbage/cribcur.h b/games/cribbage/cribcur.h index e1ad69adbf..d609438f67 100644 --- a/games/cribbage/cribcur.h +++ b/games/cribbage/cribcur.h @@ -1,4 +1,4 @@ -/* +/*- * Copyright (c) 1980, 1993 * The Regents of the University of California. All rights reserved. * @@ -10,11 +10,7 @@ * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. - * 4. Neither the name of the University nor the names of its contributors + * 3. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * @@ -34,8 +30,6 @@ * $DragonFly: src/games/cribbage/cribcur.h,v 1.2 2005/08/03 13:31:00 eirikn Exp $ */ -#include - # define PLAY_Y 15 /* size of player's hand window */ # define PLAY_X 12 # define TABLE_Y 21 /* size of table window */ diff --git a/games/cribbage/deck.h b/games/cribbage/deck.h index dc8bbd6f09..5ea34f72fd 100644 --- a/games/cribbage/deck.h +++ b/games/cribbage/deck.h @@ -1,4 +1,4 @@ -/* +/*- * Copyright (c) 1980, 1993 * The Regents of the University of California. All rights reserved. * @@ -10,11 +10,7 @@ * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. - * 4. Neither the name of the University nor the names of its contributors + * 3. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * @@ -72,7 +68,7 @@ #define VAL(c) ( (c) < 9 ? (c)+1 : 10 ) /* val of rank */ -typedef struct { - int rank; - int suit; - } CARD; +typedef struct { + int rank; + int suit; +} CARD; diff --git a/games/cribbage/extern.c b/games/cribbage/extern.c index 206c508486..b277fa63f5 100644 --- a/games/cribbage/extern.c +++ b/games/cribbage/extern.c @@ -10,11 +10,7 @@ * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. - * 4. Neither the name of the University nor the names of its contributors + * 3. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * @@ -35,6 +31,9 @@ * $DragonFly: src/games/cribbage/extern.c,v 1.4 2005/08/03 13:31:00 eirikn Exp $ */ +#include + +#include "deck.h" #include "cribbage.h" bool explain = false; /* player mistakes explained */ diff --git a/games/cribbage/instr.c b/games/cribbage/instr.c index 39fe1b5842..fb8ba80abb 100644 --- a/games/cribbage/instr.c +++ b/games/cribbage/instr.c @@ -10,11 +10,7 @@ * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. - * 4. Neither the name of the University nor the names of its contributors + * 3. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * @@ -38,12 +34,14 @@ #include #include +#include #include #include #include #include #include +#include "deck.h" #include "cribbage.h" #include "pathnames.h" diff --git a/games/cribbage/io.c b/games/cribbage/io.c index f8fe369439..4d2a9e6bde 100644 --- a/games/cribbage/io.c +++ b/games/cribbage/io.c @@ -10,11 +10,7 @@ * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. - * 4. Neither the name of the University nor the names of its contributors + * 3. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * @@ -36,12 +32,14 @@ */ #include +#include #include #include #include #include #include +#include "deck.h" #include "cribbage.h" #include "cribcur.h" @@ -556,7 +554,7 @@ getline(void) } void -intr(__unused int signo) +intr(int signo __unused) { bye(); exit(1); diff --git a/games/cribbage/pathnames.h b/games/cribbage/pathnames.h index 5c30f73ae0..80c74a9b46 100644 --- a/games/cribbage/pathnames.h +++ b/games/cribbage/pathnames.h @@ -10,11 +10,7 @@ * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. - * 4. Neither the name of the University nor the names of its contributors + * 3. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * diff --git a/games/cribbage/score.c b/games/cribbage/score.c index ff12d61c63..4baa0357c6 100644 --- a/games/cribbage/score.c +++ b/games/cribbage/score.c @@ -10,11 +10,7 @@ * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. - * 4. Neither the name of the University nor the names of its contributors + * 3. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * @@ -35,14 +31,16 @@ * $DragonFly: src/games/cribbage/score.c,v 1.3 2005/08/03 13:31:00 eirikn Exp $ */ +#include #include #include #include +#include "deck.h" #include "cribbage.h" -static int fifteens(CARD[], int); -static int pairuns(CARD[], int); +static int fifteens(CARD[], int); +static int pairuns(CARD[], int); /* * the following arrays give the sum of the scores of the (50 2)*48 = 58800 * hands obtainable for the crib given the two cards whose ranks index the diff --git a/games/cribbage/support.c b/games/cribbage/support.c index b8bca4d386..eb2f0ce9be 100644 --- a/games/cribbage/support.c +++ b/games/cribbage/support.c @@ -10,11 +10,7 @@ * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. - * 4. Neither the name of the University nor the names of its contributors + * 3. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * @@ -35,21 +31,23 @@ * $DragonFly: src/games/cribbage/support.c,v 1.3 2005/08/03 13:31:00 eirikn Exp $ */ +#include #include #include +#include "deck.h" #include "cribbage.h" #include "cribcur.h" -static int anysumto(CARD[], int, int, int); -static int numofval(CARD[], int, int); -static void prpeg(int, int, bool); - #define NTV 10 /* number scores to test */ /* score to test reachability of, and order to test them in */ const int tv[NTV] = {8, 7, 9, 6, 11, 12, 13, 14, 10, 5}; +static int anysumto(CARD[], int, int, int); +static int numofval(CARD[], int, int); +static void prpeg(int, int, bool); + /* * computer chooses what to play in pegging... * only called if no playable card will score points diff --git a/games/factor/factor.6 b/games/factor/factor.6 index 18d4345b5b..c95e83f12d 100644 --- a/games/factor/factor.6 +++ b/games/factor/factor.6 @@ -12,11 +12,7 @@ .\" 2. Redistributions in binary form must reproduce the above copyright .\" notice, this list of conditions and the following disclaimer in the .\" documentation and/or other materials provided with the distribution. -.\" 3. All advertising materials mentioning features or use of this software -.\" must display the following acknowledgement: -.\" This product includes software developed by the University of -.\" California, Berkeley and its contributors. -.\" 4. Neither the name of the University nor the names of its contributors +.\" 3. Neither the name of the University nor the names of its contributors .\" may be used to endorse or promote products derived from this software .\" without specific prior written permission. .\" diff --git a/games/factor/factor.c b/games/factor/factor.c index fdbac7da3e..9764008b7c 100644 --- a/games/factor/factor.c +++ b/games/factor/factor.c @@ -1,4 +1,4 @@ -/* +/*- * Copyright (c) 1989, 1993 * The Regents of the University of California. All rights reserved. * @@ -13,11 +13,7 @@ * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. - * 4. Neither the name of the University nor the names of its contributors + * 3. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * @@ -70,15 +66,10 @@ #include "primes.h" #ifdef HAVE_OPENSSL - #include - #define PRIME_CHECKS 5 - static void pollard_pminus1(BIGNUM *); /* print factors for big numbers */ - #else - typedef ubig BIGNUM; typedef u_long BN_ULONG; @@ -93,7 +84,6 @@ static int BN_dec2bn(BIGNUM **a, const char *str); static int BN_hex2bn(BIGNUM **a, const char *str); static BN_ULONG BN_div_word(BIGNUM *, BN_ULONG); static void BN_print_fp(FILE *, const BIGNUM *); - #endif static void BN_print_dec_fp(FILE *, const BIGNUM *); @@ -248,7 +238,7 @@ usage(void) #ifdef HAVE_OPENSSL -/* pollard rho, algorithm from Jim Gillogly, May 2000 */ +/* pollard p-1, algorithm from Jim Gillogly, May 2000 */ static void pollard_pminus1(BIGNUM *val) { diff --git a/games/fish/fish.6 b/games/fish/fish.6 index aedc88b8e5..0cef921926 100644 --- a/games/fish/fish.6 +++ b/games/fish/fish.6 @@ -9,11 +9,7 @@ .\" 2. Redistributions in binary form must reproduce the above copyright .\" notice, this list of conditions and the following disclaimer in the .\" documentation and/or other materials provided with the distribution. -.\" 3. All advertising materials mentioning features or use of this software -.\" must display the following acknowledgement: -.\" This product includes software developed by the University of -.\" California, Berkeley and its contributors. -.\" 4. Neither the name of the University nor the names of its contributors +.\" 3. Neither the name of the University nor the names of its contributors .\" may be used to endorse or promote products derived from this software .\" without specific prior written permission. .\" diff --git a/games/fish/fish.c b/games/fish/fish.c index eec43e5461..96869d1b65 100644 --- a/games/fish/fish.c +++ b/games/fish/fish.c @@ -13,11 +13,7 @@ * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. - * 4. Neither the name of the University nor the names of its contributors + * 3. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * @@ -41,7 +37,7 @@ */ #include -#include +#include #include #include #include @@ -67,21 +63,21 @@ int promode; int asked[RANKS], comphand[RANKS], deck[RANKS]; int userasked[RANKS], userhand[RANKS]; -static void chkwinner(int, int *); -static int compmove(void); -static int countbooks(int *); -static int countcards(int *); -static int drawcard(int, int *); -static int gofish(int, int, int *); -static void goodmove(int, int, int *, int *); -static void init(void); -static void instructions(void); -static int nrandom(int); -static void printhand(int *); -static void printplayer(int); -static int promove(void); -static void usage(void); -static int usermove(void); +static void chkwinner(int, int *); +static int compmove(void); +static int countbooks(int *); +static int countcards(int *); +static int drawcard(int, int *); +static int gofish(int, int, int *); +static void goodmove(int, int, int *, int *); +static void init(void); +static void instructions(void); +static int nrandom(int); +static void printhand(int *); +static void printplayer(int); +static int promove(void); +static void usage(void); +static int usermove(void); int main(int argc, char **argv) @@ -130,7 +126,7 @@ istart: for (;;) { } } /* NOTREACHED */ - return(EXIT_FAILURE); + return (EXIT_FAILURE); } static int @@ -247,7 +243,8 @@ drawcard(int player, int *hand) { int card; - while (deck[card = nrandom(RANKS)] == 0); + while (deck[card = nrandom(RANKS)] == 0) + ; /* nothing */ ++hand[card]; --deck[card]; if (player == USER || hand[card] == CARDS) { @@ -394,12 +391,14 @@ init(void) for (i = 0; i < RANKS; ++i) deck[i] = CARDS; for (i = 0; i < HANDSIZE; ++i) { - while (!deck[rank = nrandom(RANKS)]); + while (!deck[rank = nrandom(RANKS)]) + ; /* nothing */ ++userhand[rank]; --deck[rank]; } for (i = 0; i < HANDSIZE; ++i) { - while (!deck[rank = nrandom(RANKS)]); + while (!deck[rank = nrandom(RANKS)]) + ; /* nothing */ ++comphand[rank]; --deck[rank]; } diff --git a/games/fish/pathnames.h b/games/fish/pathnames.h index 89b4bd737e..15913fbb82 100644 --- a/games/fish/pathnames.h +++ b/games/fish/pathnames.h @@ -10,11 +10,7 @@ * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. - * 4. Neither the name of the University nor the names of its contributors + * 3. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * diff --git a/games/fortune/Makefile.inc b/games/fortune/Makefile.inc index 63751fb0bf..dc241daedd 100644 --- a/games/fortune/Makefile.inc +++ b/games/fortune/Makefile.inc @@ -1,3 +1,3 @@ .if exists(${.CURDIR}/../../Makefile.inc) -.include "${.CURDIR}/../../Makefile.inc" +.include "${.CURDIR}/../../Makefile.inc" .endif diff --git a/games/fortune/datfiles/dragonfly-funny b/games/fortune/datfiles/dragonfly-funny index c475464a41..93c2089bcf 100644 --- a/games/fortune/datfiles/dragonfly-funny +++ b/games/fortune/datfiles/dragonfly-funny @@ -23,7 +23,7 @@ $DragonFly: src/games/fortune/datfiles/dragonfly-funny,v 1.1 2006/03/17 03:15:16 * }; */ - -- Hidden in tablegc, the driving engine behind the DragonFly + -- Hidden in tablegc, the driving engine behind the DragonFly website. % don't drink and drive, use DragonFly @@ -137,24 +137,24 @@ Just call me "Mary Kay" :D -- said on EFnet #dragonflybsd % -<@coolvibe> I left alone, my mind was blank. I needed time to get the mutexes - from my mind. What did I see, can I believe, that what I saw that +<@coolvibe> I left alone, my mind was blank. I needed time to get the mutexes + from my mind. What did I see, can I believe, that what I saw that night was real and not just fantasy -<@coolvibe> just what I saw, in that old code, where they reflections of those +<@coolvibe> just what I saw, in that old code, where they reflections of those past hacks staring back at me -<@coolvibe> cos in my dreams, it's always there, the evil lock that twists my +<@coolvibe> cos in my dreams, it's always there, the evil lock that twists my mind and brings me to dispair! -<@coolvibe> the night was black, was no use holding back, cus I just had to +<@coolvibe> the night was black, was no use holding back, cus I just had to see, was someone watching me. -<@coolvibe> In the mist, dark hackers move and twist, was all this for real, +<@coolvibe> In the mist, dark hackers move and twist, was all this for real, or some kind of hell <@coolvibe> 6 66, the number of the beasty <@coolvibe> hacks and locks were spawned to be released -<@coolvibe> compilers blazed, and sacred chants were praised, as they start +<@coolvibe> compilers blazed, and sacred chants were praised, as they start to cry, hands held to the sky -<@coolvibe> in the night, the locks were spinning bright, the ritual has +<@coolvibe> in the night, the locks were spinning bright, the ritual has begun, beasties work is done -<@coolvibe> six, six six, the number of the beastie, sacrifice is going on +<@coolvibe> six, six six, the number of the beastie, sacrifice is going on tonight -- coolvibe molesting more Iron Maiden lyrics, on EFnet #dragonflybsd diff --git a/games/fortune/datfiles/dragonfly-tips b/games/fortune/datfiles/dragonfly-tips index 7dab1ac9e0..a07c05e46c 100644 --- a/games/fortune/datfiles/dragonfly-tips +++ b/games/fortune/datfiles/dragonfly-tips @@ -117,7 +117,7 @@ You can look through a file in a nice text-based interface by typing less filename % -The default editor in DragonFly BSD is vi, which is efficient to use when you +The default editor in DragonFly BSD is vi, which is efficient to use when you have learned it, but somewhat user-unfriendly. To use ee (an easier but less powerful editor) instead, set the environment variable EDITOR to /usr/bin/ee % @@ -159,14 +159,14 @@ In other words, to get the intro to general commands, type man 1 intro % -DragonFly BSD is started up by the program 'init'. The first thing init does -when starting multiuser mode (ie, starting the computer up for normal use) is +DragonFly BSD is started up by the program 'init'. The first thing init does +when starting multiuser mode (ie, starting the computer up for normal use) is to run the shell script /etc/rc. By reading /etc/rc, you can learn a lot about how the system is put together, which again will make you more confident about what happens when you do something with it. % -If you want to play CDs with DragonFly BSD, a utility for this is already -included. Type 'cdcontrol' then 'help' to learn more. (You may need to set +If you want to play CDs with DragonFly BSD, a utility for this is already +included. Type 'cdcontrol' then 'help' to learn more. (You may need to set the CDROM environment variable in order to make cdcontrol want to start.) % If you have a CD-ROM drive in your machine, you can make the CD-ROM that is @@ -185,9 +185,9 @@ just typing # bmake install clean as root. The pkgsrc infrastructure will download the software, change it so -it works on DragonFly BSD, compile it, install it, register the installation -so it will be possible to automatically uninstall it, and clean out the -temporary working space it used. You can remove an installed package you +it works on DragonFly BSD, compile it, install it, register the installation +so it will be possible to automatically uninstall it, and clean out the +temporary working space it used. You can remove an installed package you decide you do not want after all by typing # cd /usr/pkgsrc// @@ -246,7 +246,7 @@ the section of the manual the man page is in. "man man" will tell you more. % "man firewall" has basic instructions for creating a DragonFly BSD firewall. % -You can often get answers to your questions about DragonFly BSD by searching +You can often get answers to your questions about DragonFly BSD by searching in the DragonFly BSD mailing list archives at http://leaf.dragonflybsd.org/mailarchive/ @@ -432,7 +432,7 @@ See boot(8), loader(8) for details. You can open up a new split-screen window in (n)vi with :N or :E and then use ^w to switch between the two. % -sh (the default bourne shell in DragonFly BSD) supports command-line editing. +sh (the default bourne shell in DragonFly BSD) supports command-line editing. Just ``set -o emacs'' or ``set -o vi'' to enable it. % When you've made modifications to a file in vi(1) and then find that diff --git a/games/fortune/datfiles/fortunes2 b/games/fortune/datfiles/fortunes2 index 3ed9d58557..2c43ca149f 100644 --- a/games/fortune/datfiles/fortunes2 +++ b/games/fortune/datfiles/fortunes2 @@ -6082,7 +6082,7 @@ CS Student: But we already have a structure element with that identifier scope! Hacker: So call it 'previous'. -And then the CS Student was enlightened. +And then the CS Student was enlightened. % A computer scientist is someone who fixes things that aren't broken. % diff --git a/games/fortune/fortune/fortune.6 b/games/fortune/fortune/fortune.6 index 0dce257b0d..5c42575505 100644 --- a/games/fortune/fortune/fortune.6 +++ b/games/fortune/fortune/fortune.6 @@ -12,11 +12,7 @@ .\" 2. Redistributions in binary form must reproduce the above copyright .\" notice, this list of conditions and the following disclaimer in the .\" documentation and/or other materials provided with the distribution. -.\" 3. All advertising materials mentioning features or use of this software -.\" must display the following acknowledgement: -.\" This product includes software developed by the University of -.\" California, Berkeley and its contributors. -.\" 4. Neither the name of the University nor the names of its contributors +.\" 3. Neither the name of the University nor the names of its contributors .\" may be used to endorse or promote products derived from this software .\" without specific prior written permission. .\" diff --git a/games/fortune/fortune/fortune.c b/games/fortune/fortune/fortune.c index 89ecad0955..c02b0ec64a 100644 --- a/games/fortune/fortune/fortune.c +++ b/games/fortune/fortune/fortune.c @@ -13,11 +13,7 @@ * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. - * 4. Neither the name of the University nor the names of its contributors + * 3. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * @@ -40,44 +36,45 @@ /* $FreeBSD: src/games/fortune/fortune/fortune.c,v 1.18.2.1 2001/07/02 00:35:27 dd Exp $ */ /* $DragonFly: src/games/fortune/fortune/fortune.c,v 1.6 2006/08/08 16:58:59 pavalos Exp $ */ -# include -# include -# include - -# include -# include -# include -# include -# include -# include -# include -# include -# include -# include -# include -# include -# include "strfile.h" -# include "pathnames.h" - -# define MINW 6 /* minimum wait if desired */ -# define CPERS 20 /* # of chars for each sec */ -# define SLEN 160 /* # of chars in short fortune */ - -# define POS_UNKNOWN ((long) -1) /* pos for file unknown */ -# define NO_PROB (-1) /* no prob specified for file */ - -# ifdef DEBUG -# define DPRINTF(l,x) { if (Debug >= l) fprintf x; } -# undef NDEBUG -# else -# define DPRINTF(l,x) -# define NDEBUG 1 -# endif +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "strfile.h" +#include "pathnames.h" + +#define MINW 6 /* minimum wait if desired */ +#define CPERS 20 /* # of chars for each sec */ +#define SLEN 160 /* # of chars in short fortune */ + +#define POS_UNKNOWN ((long)-1) /* pos for file unknown */ +#define NO_PROB (-1) /* no prob specified for file */ + +#ifdef DEBUG +#define DPRINTF(l,x) { if (Debug >= l) fprintf x; } +#undef NDEBUG +#else +#define DPRINTF(l,x) +#define NDEBUG 1 +#endif typedef struct fd { int percent; int fd, datfd; - long pos; + long pos; FILE *inf; const char *name; const char *path; @@ -90,99 +87,95 @@ typedef struct fd { struct fd *next, *prev; } FILEDESC; -bool Found_one; /* did we find a match? */ -bool Find_files = false; /* just find a list of proper fortune files */ -bool Fortunes_only = false; /* check only "fortunes" files */ -bool Wait = false; /* wait desired after fortune */ -bool Short_only = false; /* short fortune desired */ -bool Long_only = false; /* long fortune desired */ -bool Offend = false; /* offensive fortunes only */ -bool All_forts = false; /* any fortune allowed */ -bool Equal_probs = false; /* scatter un-allocted prob equally */ +bool Found_one; /* did we find a match? */ +bool Find_files = false; /* just find a list of proper fortune files */ +bool Fortunes_only = false; /* check only "fortunes" files */ +bool Wait = false; /* wait desired after fortune */ +bool Short_only = false; /* short fortune desired */ +bool Long_only = false; /* long fortune desired */ +bool Offend = false; /* offensive fortunes only */ +bool All_forts = false; /* any fortune allowed */ +bool Equal_probs= false; /* scatter un-allocted prob equally */ #ifndef NO_REGEX -bool Match = false; /* dump fortunes matching a pattern */ +bool Match = false; /* dump fortunes matching a pattern */ #endif #ifdef DEBUG -bool Debug = false; /* print debug messages */ +bool Debug = false; /* print debug messages */ #endif -char *Fortbuf = NULL; /* fortune buffer for -m */ +char *Fortbuf = NULL; /* fortune buffer for -m */ -int Fort_len = 0; +int Fort_len = 0; -long Seekpts[2]; /* seek pointers to fortunes */ +long Seekpts[2]; /* seek pointers to fortunes */ -FILEDESC *File_list = NULL, /* Head of file list */ - *File_tail = NULL; /* Tail of file list */ -FILEDESC *Fortfile; /* Fortune file to use */ +FILEDESC *File_list = NULL, /* Head of file list */ + *File_tail = NULL; /* Tail of file list */ +FILEDESC *Fortfile; /* Fortune file to use */ -STRFILE Noprob_tbl; /* sum of data for all no prob files */ +STRFILE Noprob_tbl; /* sum of data for all no prob files */ -bool add_dir (FILEDESC *); -bool add_file (int, +bool add_dir(FILEDESC *); +bool add_file(int, const char *, const char *, FILEDESC **, FILEDESC **, FILEDESC *); -void all_forts (FILEDESC *, char *); -char *copy (const char *, u_int); -void display (FILEDESC *); -void do_free (void *); -void *do_malloc (u_int); -bool form_file_list (char **, int); -int fortlen (void); -void get_fort (void); -void get_pos (FILEDESC *); -void get_tbl (FILEDESC *); -void getargs (int, char *[]); -void init_prob (void); -bool is_dir (const char *); -bool is_fortfile (const char *, char **, char **, int); -bool is_off_name (const char *); -int max (int, int); -FILEDESC * - new_fp (void); -char *off_name (const char *); -void open_dat (FILEDESC *); -void open_fp (FILEDESC *); -FILEDESC * - pick_child (FILEDESC *); -void print_file_list (void); -void print_list (FILEDESC *, int); -void sum_noprobs (FILEDESC *); -void sum_tbl (STRFILE *, STRFILE *); -void usage (void); -void zero_tbl (STRFILE *); - -#ifndef NO_REGEX -char *conv_pat (char *); -int find_matches (void); -void matches_in_list (FILEDESC *); -int maxlen_in_list (FILEDESC *); +void all_forts(FILEDESC *, char *); +char *copy(const char *, u_int); +void display(FILEDESC *); +void do_free(void *); +void *do_malloc(u_int); +bool form_file_list(char **, int); +int fortlen(void); +void get_fort(void); +void get_pos(FILEDESC *); +void get_tbl(FILEDESC *); +void getargs(int, char *[]); +void init_prob(void); +bool is_dir(const char *); +bool is_fortfile(const char *, char **, char **, int); +bool is_off_name(const char *); +int max(int, int); +FILEDESC *new_fp(void); +char *off_name(const char *); +void open_dat(FILEDESC *); +void open_fp(FILEDESC *); +FILEDESC *pick_child(FILEDESC *); +void print_file_list(void); +void print_list(FILEDESC *, int); +void sum_noprobs(FILEDESC *); +void sum_tbl(STRFILE *, STRFILE *); +void usage(void); +void zero_tbl(STRFILE *); + +#ifndef NO_REGEX +char *conv_pat(char *); +int find_matches(void); +void matches_in_list(FILEDESC *); +int maxlen_in_list(FILEDESC *); #endif #ifndef NO_REGEX #ifdef REGCMP -# define RE_COMP(p) (Re_pat = regcmp(p, NULL)) -# define BAD_COMP(f) ((f) == NULL) -# define RE_EXEC(p) regex(Re_pat, (p)) - -char *Re_pat; +#define RE_COMP(p) (Re_pat = regcmp(p, NULL)) +#define BAD_COMP(f) ((f) == NULL) +#define RE_EXEC(p) regex(Re_pat, (p)) -char *regcmp(), *regex(); +char *Re_pat; +char *regcmp(), *regex(); #else -# define RE_COMP(p) (p = re_comp(p)) -# define BAD_COMP(f) ((f) != NULL) -# define RE_EXEC(p) re_exec(p) - +#define RE_COMP(p) (p = re_comp(p)) +#define BAD_COMP(f) ((f) != NULL) +#define RE_EXEC(p) re_exec(p) #endif #endif int -main(int ac, char **av) +main(int ac, char *av[]) { -#ifdef OK_TO_WRITE_DISK - int fd; -#endif /* OK_TO_WRITE_DISK */ +#ifdef OK_TO_WRITE_DISK + int fd; +#endif /* OK_TO_WRITE_DISK */ - (void) setlocale(LC_ALL, ""); + setlocale(LC_ALL, ""); getargs(ac, av); @@ -200,44 +193,44 @@ main(int ac, char **av) display(Fortfile); -#ifdef OK_TO_WRITE_DISK +#ifdef OK_TO_WRITE_DISK if ((fd = creat(Fortfile->posfile, 0666)) < 0) { perror(Fortfile->posfile); exit(1); } -#ifdef LOCK_EX +#ifdef LOCK_EX /* * if we can, we exclusive lock, but since it isn't very * important, we just punt if we don't have easy locking * available. */ - (void) flock(fd, LOCK_EX); -#endif /* LOCK_EX */ + flock(fd, LOCK_EX); +#endif /* LOCK_EX */ write(fd, (char *) &Fortfile->pos, sizeof Fortfile->pos); if (!Fortfile->was_pos_file) - (void) chmod(Fortfile->path, 0666); -#ifdef LOCK_EX - (void) flock(fd, LOCK_UN); -#endif /* LOCK_EX */ -#endif /* OK_TO_WRITE_DISK */ + chmod(Fortfile->path, 0666); +#ifdef LOCK_EX + flock(fd, LOCK_UN); +#endif /* LOCK_EX */ +#endif /* OK_TO_WRITE_DISK */ if (Wait) { if (Fort_len == 0) - (void) fortlen(); - sleep((unsigned int) max(Fort_len / CPERS, MINW)); + fortlen(); + sleep((unsigned int)max(Fort_len / CPERS, MINW)); } + exit(0); - /* NOTREACHED */ } void display(FILEDESC *fp) { - char *p; + char *p; unsigned char ch; - char line[BUFSIZ]; + char line[BUFSIZ]; open_fp(fp); - (void) fseek(fp->inf, Seekpts[0], 0); + fseek(fp->inf, Seekpts[0], SEEK_SET); for (Fort_len = 0; fgets(line, sizeof line, fp->inf) != NULL && !STR_ENDSTRING(line, fp->tbl); Fort_len++) { if (fp->tbl.str_flags & STR_ROTATED) @@ -255,7 +248,7 @@ display(FILEDESC *fp) continue; fputs(line, stdout); } - (void) fflush(stdout); + fflush(stdout); } /* @@ -265,21 +258,22 @@ display(FILEDESC *fp) int fortlen(void) { - int nchar; - char line[BUFSIZ]; + int nchar; + char line[BUFSIZ]; if (!(Fortfile->tbl.str_flags & (STR_RANDOM | STR_ORDERED))) nchar = (Seekpts[1] - Seekpts[0] <= SLEN); else { open_fp(Fortfile); - (void) fseek(Fortfile->inf, Seekpts[0], 0); + fseek(Fortfile->inf, Seekpts[0], SEEK_SET); nchar = 0; while (fgets(line, sizeof line, Fortfile->inf) != NULL && !STR_ENDSTRING(line, Fortfile->tbl)) nchar += strlen(line); } Fort_len = nchar; - return nchar; + + return (nchar); } /* @@ -288,18 +282,18 @@ fortlen(void) void getargs(int argc, char **argv) { - int ignore_case; -# ifndef NO_REGEX - char *pat; -# endif /* NO_REGEX */ + int ignore_case; +#ifndef NO_REGEX + char *pat; +#endif /* NO_REGEX */ int ch; ignore_case = false; -# ifndef NO_REGEX +#ifndef NO_REGEX pat = NULL; -# endif /* NO_REGEX */ +#endif /* NO_REGEX */ -# ifdef DEBUG +#ifdef DEBUG while ((ch = getopt(argc, argv, "aDefilm:osw")) != -1) #else while ((ch = getopt(argc, argv, "aefilm:osw")) != -1) @@ -308,11 +302,11 @@ getargs(int argc, char **argv) case 'a': /* any fortune */ All_forts++; break; -# ifdef DEBUG +#ifdef DEBUG case 'D': Debug++; break; -# endif /* DEBUG */ +#endif /* DEBUG */ case 'e': Equal_probs++; /* scatter un-allocted prob equally */ break; @@ -333,13 +327,13 @@ getargs(int argc, char **argv) case 'w': /* give time to read */ Wait++; break; -# ifdef NO_REGEX +#ifdef NO_REGEX case 'i': /* case-insensitive match */ case 'm': /* dump out the fortunes */ - (void) fprintf(stderr, + fprintf(stderr, "fortune: can't match fortunes on this system (Sorry)\n"); exit(0); -# else /* NO_REGEX */ +#else /* NO_REGEX */ case 'm': /* dump out the fortunes */ Match++; pat = optarg; @@ -347,7 +341,7 @@ getargs(int argc, char **argv) case 'i': /* case-insensitive match */ ignore_case++; break; -# endif /* NO_REGEX */ +#endif /* NO_REGEX */ case '?': default: usage(); @@ -366,19 +360,19 @@ getargs(int argc, char **argv) print_file_list(); #endif /* DEBUG */ -# ifndef NO_REGEX +#ifndef NO_REGEX if (pat != NULL) { if (ignore_case) pat = conv_pat(pat); if (BAD_COMP(RE_COMP(pat))) { #ifndef REGCMP fprintf(stderr, "%s\n", pat); -#else /* REGCMP */ +#else /* REGCMP */ fprintf(stderr, "bad pattern: %s\n", pat); -#endif /* REGCMP */ +#endif /* REGCMP */ } } -# endif /* NO_REGEX */ +#endif /* NO_REGEX */ } /* @@ -388,9 +382,9 @@ getargs(int argc, char **argv) bool form_file_list(char **files, int file_cnt) { - bool i; - int percent; - const char *sp; + bool i; + int percent; + const char *sp; if (file_cnt == 0) { if (Find_files) { @@ -398,10 +392,10 @@ form_file_list(char **files, int file_cnt) i = add_file(NO_PROB, FORTDIR, NULL, &File_list, &File_tail, NULL); Fortunes_only = false; - return i; + return (i); } else - return add_file(NO_PROB, "fortunes", FORTDIR, - &File_list, &File_tail, NULL); + return (add_file(NO_PROB, "fortunes", FORTDIR, + &File_list, &File_tail, NULL)); } for (i = 0; i < file_cnt; i++) { percent = NO_PROB; @@ -413,11 +407,11 @@ form_file_list(char **files, int file_cnt) percent = percent * 10 + *sp - '0'; if (percent > 100) { fprintf(stderr, "percentages must be <= 100\n"); - return false; + return (false); } if (*sp == '.') { fprintf(stderr, "percentages must be integers\n"); - return false; + return (false); } /* * If the number isn't followed by a '%', then @@ -431,7 +425,7 @@ form_file_list(char **files, int file_cnt) else if (*++sp == '\0') { if (++i >= file_cnt) { fprintf(stderr, "percentages must precede files\n"); - return false; + return (false); } sp = files[i]; } @@ -439,9 +433,10 @@ form_file_list(char **files, int file_cnt) if (strcmp(sp, "all") == 0) sp = FORTDIR; if (!add_file(percent, sp, NULL, &File_list, &File_tail, NULL)) - return false; + return (false); } - return true; + + return (true); } /* @@ -449,14 +444,15 @@ form_file_list(char **files, int file_cnt) * Add a file to the file list. */ bool -add_file(int percent, const char *file, const char *dir, FILEDESC **head, FILEDESC **tail, FILEDESC *parent) +add_file(int percent, const char *file, const char *dir, + FILEDESC **head, FILEDESC **tail, FILEDESC *parent) { - FILEDESC *fp; - int fd; - const char *path; - char *tpath, *offensive; - bool was_malloc; - bool isdir; + FILEDESC *fp; + int fd; + const char *path; + char *tpath, *offensive; + bool was_malloc; + bool isdir; if (dir == NULL) { path = file; @@ -464,15 +460,15 @@ add_file(int percent, const char *file, const char *dir, FILEDESC **head, FILEDE was_malloc = false; } else { - tpath = do_malloc((unsigned int) (strlen(dir) + strlen(file) + 2)); - (void) strcat(strcat(strcpy(tpath, dir), "/"), file); + tpath = do_malloc((unsigned int)(strlen(dir) + strlen(file) + 2)); + strcat(strcat(strcpy(tpath, dir), "/"), file); path = tpath; was_malloc = true; } if ((isdir = is_dir(path)) && parent != NULL) { if (was_malloc) free(tpath); - return false; /* don't recurse */ + return (false); /* don't recurse */ } offensive = NULL; if (!isdir && parent == NULL && (All_forts || Offend) && @@ -491,7 +487,7 @@ add_file(int percent, const char *file, const char *dir, FILEDESC **head, FILEDE DPRINTF(1, (stderr, "adding file \"%s\"\n", path)); over: - if ((fd = open(path, 0)) < 0) { + if ((fd = open(path, O_RDONLY)) < 0) { /* * This is a sneak. If the user said -a, and if the * file we're given isn't a file, we check to see if @@ -511,13 +507,13 @@ over: goto over; } if (dir == NULL && file[0] != '/') - return add_file(percent, file, FORTDIR, head, tail, - parent); + return (add_file(percent, file, FORTDIR, head, tail, + parent)); if (parent == NULL) perror(path); if (was_malloc) free(tpath); - return false; + return (false); } DPRINTF(2, (stderr, "path = \"%s\"\n", path)); @@ -541,9 +537,9 @@ over: free(tpath); do_free(fp->datfile); do_free(fp->posfile); - free((char *) fp); + free(fp); do_free(offensive); - return false; + return (false); } /* * If the user said -a, we need to make this node a pointer to @@ -565,11 +561,11 @@ over: fp->next = *head; *head = fp; } -#ifdef OK_TO_WRITE_DISK +#ifdef OK_TO_WRITE_DISK fp->was_pos_file = (access(fp->posfile, W_OK) >= 0); -#endif /* OK_TO_WRITE_DISK */ +#endif /* OK_TO_WRITE_DISK */ - return true; + return (true); } /* @@ -579,9 +575,9 @@ over: FILEDESC * new_fp(void) { - FILEDESC *fp; + FILEDESC *fp; - fp = (FILEDESC *) do_malloc(sizeof *fp); + fp = (FILEDESC *)do_malloc(sizeof(*fp)); fp->datfd = -1; fp->pos = POS_UNKNOWN; fp->inf = NULL; @@ -594,7 +590,8 @@ new_fp(void) fp->parent = NULL; fp->datfile = NULL; fp->posfile = NULL; - return fp; + + return (fp); } /* @@ -604,10 +601,11 @@ new_fp(void) char * off_name(const char *file) { - char *new; + char *new; + + new = copy(file, (unsigned int)(strlen(file) + 2)); - new = copy(file, (unsigned int) (strlen(file) + 2)); - return strcat(new, "-o"); + return (strcat(new, "-o")); } /* @@ -617,9 +615,10 @@ off_name(const char *file) bool is_off_name(const char *file) { - int len; + int len; len = strlen(file); + return (len >= 3 && file[len - 2] == '-' && file[len - 1] == 'o'); } @@ -631,16 +630,16 @@ is_off_name(const char *file) void all_forts(FILEDESC *fp, char *offensive) { - char *sp; - FILEDESC *scene, *obscene; - int fd; - auto char *datfile, *posfile; + char *sp; + FILEDESC *scene, *obscene; + int fd; + char *datfile, *posfile; if (fp->child != NULL) /* this is a directory, not a file */ return; if (!is_fortfile(offensive, &datfile, &posfile, false)) return; - if ((fd = open(offensive, 0)) < 0) + if ((fd = open(offensive, O_RDONLY)) < 0) return; DPRINTF(1, (stderr, "adding \"%s\" because of -a\n", offensive)); scene = new_fp(); @@ -667,9 +666,9 @@ all_forts(FILEDESC *fp, char *offensive) obscene->datfile = datfile; obscene->posfile = posfile; obscene->read_tbl = false; -#ifdef OK_TO_WRITE_DISK +#ifdef OK_TO_WRITE_DISK obscene->was_pos_file = (access(obscene->posfile, W_OK) >= 0); -#endif /* OK_TO_WRITE_DISK */ +#endif /* OK_TO_WRITE_DISK */ } /* @@ -679,16 +678,16 @@ all_forts(FILEDESC *fp, char *offensive) bool add_dir(FILEDESC *fp) { - DIR *dir; - struct dirent *dirent; - auto FILEDESC *tailp; - auto char *name; + DIR *dir; + struct dirent *dirent; + FILEDESC *tailp; + char *name; - (void) close(fp->fd); + close(fp->fd); fp->fd = -1; if ((dir = opendir(fp->path)) == NULL) { perror(fp->path); - return false; + return (false); } tailp = NULL; DPRINTF(1, (stderr, "adding dir \"%s\"\n", fp->path)); @@ -702,11 +701,12 @@ add_dir(FILEDESC *fp) free(name); } if (fp->num_children == 0) { - (void) fprintf(stderr, + fprintf(stderr, "fortune: %s: No fortune files in directory.\n", fp->path); - return false; + return (false); } - return true; + + return (true); } /* @@ -716,10 +716,11 @@ add_dir(FILEDESC *fp) bool is_dir(const char *file) { - auto struct stat sbuf; + struct stat sbuf; if (stat(file, &sbuf) < 0) - return false; + return (false); + return (sbuf.st_mode & S_IFDIR); } @@ -734,15 +735,16 @@ is_dir(const char *file) bool is_fortfile(const char *file, char **datp, char **posp, int check_for_offend) { - int i; - const char *sp; - char *datfile; - static const char *suflist[] = { /* list of "illegal" suffixes" */ - "dat", "pos", "c", "h", "p", "i", "f", - "pas", "ftn", "ins.c", "ins,pas", - "ins.ftn", "sml", - NULL - }; + int i; + const char *sp; + char *datfile; + static const char *suflist[] = { + /* list of "illegal" suffixes" */ + "dat", "pos", "c", "h", "p", "i", "f", + "pas", "ftn", "ins.c", "ins,pas", + "ins.ftn", "sml", + NULL + }; DPRINTF(2, (stderr, "is_fortfile(%s) returns ", file)); @@ -754,7 +756,7 @@ is_fortfile(const char *file, char **datp, char **posp, int check_for_offend) i = strlen(file); if (Offend ^ (file[i - 2] == '-' && file[i - 1] == 'o')) { DPRINTF(2, (stderr, "false (offending file)\n")); - return false; + return (false); } } @@ -764,22 +766,22 @@ is_fortfile(const char *file, char **datp, char **posp, int check_for_offend) sp++; if (*sp == '.') { DPRINTF(2, (stderr, "false (file starts with '.')\n")); - return false; + return (false); } if (Fortunes_only && strncmp(sp, "fortunes", 8) != 0) { DPRINTF(2, (stderr, "false (check fortunes only)\n")); - return false; + return (false); } if ((sp = rindex(sp, '.')) != NULL) { sp++; for (i = 0; suflist[i] != NULL; i++) if (strcmp(sp, suflist[i]) == 0) { DPRINTF(2, (stderr, "false (file has suffix \".%s\")\n", sp)); - return false; + return (false); } } - datfile = copy(file, (unsigned int) (strlen(file) + 4)); /* +4 for ".dat" */ + datfile = copy(file, (unsigned int)(strlen(file) + 4)); /* +4 for ".dat" */ strcat(datfile, ".dat"); if (access(datfile, R_OK) < 0) { DPRINTF(2, (stderr, "false (no readable \".dat\" file)\n")); @@ -788,22 +790,25 @@ is_fortfile(const char *file, char **datp, char **posp, int check_for_offend) DPRINTF(0, (stderr, "Warning: file \"%s\" unreadable\n", datfile)); #endif free(datfile); - return false; + return (false); } if (datp != NULL) *datp = datfile; else free(datfile); +#ifdef OK_TO_WRITE_DISK if (posp != NULL) { -#ifdef OK_TO_WRITE_DISK - *posp = copy(file, (unsigned int) (strlen(file) + 4)); /* +4 for ".dat" */ - (void) strcat(*posp, ".pos"); + *posp = copy(file, (unsigned int)(strlen(file) + 4)); /* +4 for ".dat" */ + strcat(*posp, ".pos"); + } #else + if (posp != NULL) { *posp = NULL; -#endif /* OK_TO_WRITE_DISK */ } +#endif /* OK_TO_WRITE_DISK */ DPRINTF(2, (stderr, "true\n")); - return true; + + return (true); } /* @@ -813,14 +818,15 @@ is_fortfile(const char *file, char **datp, char **posp, int check_for_offend) char * copy(const char *str, unsigned int len) { - char *new, *sp; + char *new, *sp; new = do_malloc(len + 1); sp = new; do { *sp++ = *str; } while (*str++); - return new; + + return (new); } /* @@ -830,13 +836,14 @@ copy(const char *str, unsigned int len) void * do_malloc(unsigned int size) { - void *new; + void *new; if ((new = malloc(size)) == NULL) { - (void) fprintf(stderr, "fortune: out of memory.\n"); + fprintf(stderr, "fortune: out of memory.\n"); exit(1); } - return new; + + return (new); } /* @@ -857,9 +864,10 @@ do_free(void *ptr) void init_prob(void) { - FILEDESC *fp, *last = NULL; - int percent, num_noprob, frac; + FILEDESC *fp, *last; + int percent, num_noprob, frac; + last = NULL; /* * Distribute the residual probability (if any) across all * files with unspecified probability (i.e., probability of 0) @@ -873,24 +881,21 @@ init_prob(void) num_noprob++; if (Equal_probs) last = fp; - } - else + } else percent += fp->percent; DPRINTF(1, (stderr, "summing probabilities:%d%% with %d NO_PROB's", percent, num_noprob)); if (percent > 100) { - (void) fprintf(stderr, + fprintf(stderr, "fortune: probabilities sum to %d%% > 100%%!\n", percent); exit(1); - } - else if (percent < 100 && num_noprob == 0) { - (void) fprintf(stderr, + } else if (percent < 100 && num_noprob == 0) { + fprintf(stderr, "fortune: no place to put residual probability (%d%% < 100%%)\n", percent); exit(1); - } - else if (percent == 100 && num_noprob != 0) { - (void) fprintf(stderr, + } else if (percent == 100 && num_noprob != 0) { + fprintf(stderr, "fortune: no probability left to put in residual files (100%%)\n"); exit(1); } @@ -909,7 +914,7 @@ init_prob(void) last->percent = percent; DPRINTF(1, (stderr, ", residual = %d%%", percent)); } - else + } else { DPRINTF(1, (stderr, ", %d%% distributed over remaining fortunes\n", percent)); @@ -929,8 +934,8 @@ init_prob(void) void get_fort(void) { - FILEDESC *fp; - int choice; + FILEDESC *fp; + int choice; if (File_list->next == NULL || File_list->percent == NO_PROB) fp = File_list; @@ -978,8 +983,8 @@ get_fort(void) Fortfile = fp; get_pos(fp); open_dat(fp); - (void) lseek(fp->datfd, - (off_t) (sizeof fp->tbl + fp->pos * sizeof Seekpts[0]), 0); + lseek(fp->datfd, + (off_t) (sizeof fp->tbl + fp->pos * sizeof Seekpts[0]), SEEK_SET); read(fp->datfd, Seekpts, sizeof Seekpts); Seekpts[0] = ntohl(Seekpts[0]); Seekpts[1] = ntohl(Seekpts[1]); @@ -992,8 +997,8 @@ get_fort(void) FILEDESC * pick_child(FILEDESC *parent) { - FILEDESC *fp; - int choice; + FILEDESC *fp; + int choice; if (Equal_probs) { choice = random() % parent->num_children; @@ -1002,7 +1007,7 @@ pick_child(FILEDESC *parent) for (fp = parent->child; choice--; fp = fp->next) continue; DPRINTF(1, (stderr, " using %s\n", fp->name)); - return fp; + return (fp); } else { get_tbl(parent); @@ -1017,7 +1022,7 @@ pick_child(FILEDESC *parent) } DPRINTF(1, (stderr, " using %s, %ld\n", fp->name, fp->tbl.str_numstr)); - return fp; + return (fp); } } @@ -1028,7 +1033,7 @@ pick_child(FILEDESC *parent) void sum_noprobs(FILEDESC *fp) { - static bool did_noprobs = false; + static bool did_noprobs = false; if (did_noprobs) return; @@ -1067,7 +1072,7 @@ open_fp(FILEDESC *fp) void open_dat(FILEDESC *fp) { - if (fp->datfd < 0 && (fp->datfd = open(fp->datfile, 0)) < 0) { + if (fp->datfd < 0 && (fp->datfd = open(fp->datfile, O_RDONLY)) < 0) { perror(fp->datfile); exit(1); } @@ -1081,20 +1086,20 @@ open_dat(FILEDESC *fp) void get_pos(FILEDESC *fp) { -#ifdef OK_TO_WRITE_DISK - int fd; +#ifdef OK_TO_WRITE_DISK + int fd; #endif /* OK_TO_WRITE_DISK */ assert(fp->read_tbl); if (fp->pos == POS_UNKNOWN) { -#ifdef OK_TO_WRITE_DISK - if ((fd = open(fp->posfile, 0)) < 0 || +#ifdef OK_TO_WRITE_DISK + if ((fd = open(fp->posfile, O_RDONLY)) < 0 || read(fd, &fp->pos, sizeof fp->pos) != sizeof fp->pos) fp->pos = random() % fp->tbl.str_numstr; else if (fp->pos >= fp->tbl.str_numstr) fp->pos %= fp->tbl.str_numstr; if (fd >= 0) - (void) close(fd); + close(fd); #else fp->pos = random() % fp->tbl.str_numstr; #endif /* OK_TO_WRITE_DISK */ @@ -1111,18 +1116,18 @@ get_pos(FILEDESC *fp) void get_tbl(FILEDESC *fp) { - auto int fd; - FILEDESC *child; + int fd; + FILEDESC *child; if (fp->read_tbl) return; if (fp->child == NULL) { - if ((fd = open(fp->datfile, 0)) < 0) { + if ((fd = open(fp->datfile, O_RDONLY)) < 0) { perror(fp->datfile); exit(1); } if (read(fd, (char *) &fp->tbl, sizeof fp->tbl) != sizeof fp->tbl) { - (void)fprintf(stderr, + fprintf(stderr, "fortune: %s corrupted\n", fp->path); exit(1); } @@ -1131,7 +1136,7 @@ get_tbl(FILEDESC *fp) fp->tbl.str_longlen = ntohl(fp->tbl.str_longlen); fp->tbl.str_shortlen = ntohl(fp->tbl.str_shortlen); fp->tbl.str_flags = ntohl(fp->tbl.str_flags); - (void) close(fd); + close(fd); } else { zero_tbl(&fp->tbl); @@ -1204,7 +1209,7 @@ print_list(FILEDESC *list, int lev) } } -#ifndef NO_REGEX +#ifndef NO_REGEX /* * conv_pat: * Convert the pattern to an ignore-case equivalent. @@ -1212,9 +1217,9 @@ print_list(FILEDESC *list, int lev) char * conv_pat(char *orig) { - char *sp; - unsigned int cnt; - char *new; + char *sp; + unsigned int cnt; + char *new; cnt = 1; /* allow for '\0' */ for (sp = orig; *sp != '\0'; sp++) @@ -1244,7 +1249,8 @@ conv_pat(char *orig) *sp++ = *orig; } *sp = '\0'; - return new; + + return (new); } /* @@ -1257,12 +1263,12 @@ find_matches(void) Fort_len = maxlen_in_list(File_list); DPRINTF(2, (stderr, "Maximum length is %d\n", Fort_len)); /* extra length, "%\n" is appended */ - Fortbuf = do_malloc((unsigned int) Fort_len + 10); + Fortbuf = do_malloc((unsigned int)Fort_len + 10); Found_one = false; matches_in_list(File_list); - return Found_one; - /* NOTREACHED */ + + return (Found_one); } /* @@ -1272,8 +1278,8 @@ find_matches(void) int maxlen_in_list(FILEDESC *list) { - FILEDESC *fp; - int len, maxlen; + FILEDESC *fp; + int len, maxlen; maxlen = 0; for (fp = list; fp != NULL; fp = fp->next) { @@ -1287,7 +1293,8 @@ maxlen_in_list(FILEDESC *list) maxlen = fp->tbl.str_longlen; } } - return maxlen; + + return (maxlen); } /* @@ -1297,10 +1304,10 @@ maxlen_in_list(FILEDESC *list) void matches_in_list(FILEDESC *list) { - char *sp, *p; - FILEDESC *fp; - int in_file; - unsigned char ch; + char *sp, *p; + FILEDESC *fp; + int in_file; + unsigned char ch; for (fp = list; fp != NULL; fp = fp->next) { if (fp->child != NULL) { @@ -1338,29 +1345,29 @@ matches_in_list(FILEDESC *list) in_file = true; } putchar('\n'); - (void) fwrite(Fortbuf, 1, (sp - Fortbuf), stdout); + fwrite(Fortbuf, 1, (sp - Fortbuf), stdout); } sp = Fortbuf; } } } -# endif /* NO_REGEX */ +#endif /* NO_REGEX */ void usage(void) { - (void) fprintf(stderr, "fortune [-a"); -#ifdef DEBUG - (void) fprintf(stderr, "D"); -#endif /* DEBUG */ - (void) fprintf(stderr, "f"); -#ifndef NO_REGEX - (void) fprintf(stderr, "i"); -#endif /* NO_REGEX */ - (void) fprintf(stderr, "losw]"); -#ifndef NO_REGEX - (void) fprintf(stderr, " [-m pattern]"); -#endif /* NO_REGEX */ - (void) fprintf(stderr, "[[#%%] file/directory/all]\n"); + fprintf(stderr, "fortune [-a"); +#ifdef DEBUG + fprintf(stderr, "D"); +#endif /* DEBUG */ + fprintf(stderr, "f"); +#ifndef NO_REGEX + fprintf(stderr, "i"); +#endif + fprintf(stderr, "losw]"); +#ifndef NO_REGEX + fprintf(stderr, " [-m pattern]"); +#endif + fprintf(stderr, "[[#%%] file/directory/all]\n"); exit(1); } diff --git a/games/fortune/fortune/pathnames.h b/games/fortune/fortune/pathnames.h index 341d0b860c..d5cdd4fece 100644 --- a/games/fortune/fortune/pathnames.h +++ b/games/fortune/fortune/pathnames.h @@ -10,11 +10,7 @@ * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. - * 4. Neither the name of the University nor the names of its contributors + * 3. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * diff --git a/games/fortune/strfile/strfile.8 b/games/fortune/strfile/strfile.8 index e8c00463e3..05553941b3 100644 --- a/games/fortune/strfile/strfile.8 +++ b/games/fortune/strfile/strfile.8 @@ -13,11 +13,7 @@ .\" 2. Redistributions in binary form must reproduce the above copyright .\" notice, this list of conditions and the following disclaimer in the .\" documentation and/or other materials provided with the distribution. -.\" 3. All advertising materials mentioning features or use of this software -.\" must display the following acknowledgement: -.\" This product includes software developed by the University of -.\" California, Berkeley and its contributors. -.\" 4. Neither the name of the University nor the names of its contributors +.\" 3. Neither the name of the University nor the names of its contributors .\" may be used to endorse or promote products derived from this software .\" without specific prior written permission. .\" diff --git a/games/fortune/strfile/strfile.c b/games/fortune/strfile/strfile.c index 323d2954af..23c891d9e8 100644 --- a/games/fortune/strfile/strfile.c +++ b/games/fortune/strfile/strfile.c @@ -13,11 +13,7 @@ * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. - * 4. Neither the name of the University nor the names of its contributors + * 3. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * @@ -41,17 +37,17 @@ * $FreeBSD: src/games/fortune/strfile/strfile.c,v 1.15.2.2 2001/03/05 11:52:37 kris Exp $ */ -# include -# include -# include -# include -# include -# include -# include -# include -# include -# include -# include "strfile.h" +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "strfile.h" /* * This program takes a file composed of strings separated by @@ -77,23 +73,23 @@ * Added ordering options. */ -# define STORING_PTRS (Oflag || Rflag) -# define CHUNKSIZE 512 +#define STORING_PTRS (Oflag || Rflag) +#define CHUNKSIZE 512 -# define ALLOC(ptr,sz) { \ +#define ALLOC(ptr,sz) do { \ if (ptr == NULL) \ - ptr = malloc((unsigned int) (CHUNKSIZE * sizeof *ptr)); \ + ptr = malloc((unsigned int)(CHUNKSIZE * sizeof(*ptr))); \ else if (((sz) + 1) % CHUNKSIZE == 0) \ - ptr = realloc((void *) ptr, ((unsigned int) ((sz) + CHUNKSIZE) * sizeof *ptr)); \ + ptr = realloc(ptr, ((unsigned int)((sz) + CHUNKSIZE) * sizeof(*ptr))); \ if (ptr == NULL) { \ fprintf(stderr, "out of space\n"); \ exit(1); \ } \ - } + } while (0) typedef struct { char first; - long pos; + long pos; } STR; char *Infile = NULL, /* input file name */ @@ -108,7 +104,7 @@ int Rflag = false; /* randomize order flag */ int Xflag = false; /* set rotated bit */ long Num_pts = 0; /* number of pointers/strings */ -long *Seekpts; +long *Seekpts; FILE *Sort_1, *Sort_2; /* pointers for sorting */ @@ -116,13 +112,13 @@ STRFILE Tbl; /* statistics table */ STR *Firstch; /* first chars of each string */ -void add_offset (FILE *, long); -int cmp_str (const void *, const void *); -static int collate_range_cmp (int, int); -void do_order (void); -void getargs (int, char **); -void randomize (void); -void usage (void); +void add_offset(FILE *, long); +int cmp_str(const void *, const void *); +static int collate_range_cmp(int, int); +void do_order(void); +void getargs(int, char **); +void randomize(void); +void usage(void); /* * main: @@ -134,17 +130,16 @@ void usage (void); * and then seek back to the beginning to write in the table. */ int -main(int ac, char **av) +main(int ac, char *av[]) { - char *sp, dc; - FILE *inf, *outf; - long last_off, length, pos, *p; - int first, cnt; - char *nsp; - STR *fp; - static char string[257]; + char *sp, *nsp, dc; + FILE *inf, *outf; + long last_off, length, pos, *p; + int first, cnt; + STR *fp; + static char string[257]; - (void) setlocale(LC_ALL, ""); + setlocale(LC_ALL, ""); getargs(ac, av); /* evalute arguments */ dc = Delimch; @@ -158,14 +153,14 @@ main(int ac, char **av) exit(1); } if (!STORING_PTRS) - (void) fseek(outf, (long) sizeof Tbl, 0); + fseek(outf, sizeof(Tbl), SEEK_SET); /* * Write the strings onto the file */ Tbl.str_longlen = 0; - Tbl.str_shortlen = ~((unsigned long) 0); + Tbl.str_shortlen = ~((unsigned long)0); Tbl.str_delim = dc; Tbl.str_version = VERSION; first = Oflag; @@ -204,7 +199,7 @@ main(int ac, char **av) * write the tables in */ - (void) fclose(inf); + fclose(inf); Tbl.str_numstr = Num_pts - 1; if (Cflag) @@ -236,13 +231,13 @@ main(int ac, char **av) Tbl.str_longlen = htonl(Tbl.str_longlen); Tbl.str_shortlen = htonl(Tbl.str_shortlen); Tbl.str_flags = htonl(Tbl.str_flags); - (void) fwrite((char *) &Tbl, sizeof Tbl, 1, outf); + fwrite((char *)&Tbl, sizeof(Tbl), 1, outf); if (STORING_PTRS) { for (p = Seekpts, cnt = Num_pts; cnt--; ++p) *p = htonl(*p); - (void) fwrite((char *) Seekpts, sizeof *Seekpts, (int) Num_pts, outf); + fwrite((char *)Seekpts, sizeof(*Seekpts), (int)Num_pts, outf); } - (void) fclose(outf); + fclose(outf); exit(0); } @@ -252,7 +247,7 @@ main(int ac, char **av) void getargs(int argc, char **argv) { - int ch; + int ch; while ((ch = getopt(argc, argv, "Cc:iorsx")) != -1) switch(ch) { @@ -290,22 +285,22 @@ getargs(int argc, char **argv) if (*argv) { Infile = *argv; if (*++argv) - (void) strcpy(Outfile, *argv); + strcpy(Outfile, *argv); } if (!Infile) { puts("No input file name"); usage(); } if (*Outfile == '\0') { - (void) strcpy(Outfile, Infile); - (void) strcat(Outfile, ".dat"); + strcpy(Outfile, Infile); + strcat(Outfile, ".dat"); } } void usage(void) { - (void) fprintf(stderr, + fprintf(stderr, "strfile [-Ciorsx] [-c char] sourcefile [datafile]\n"); exit(1); } @@ -321,7 +316,7 @@ add_offset(FILE *fp, long off) if (!STORING_PTRS) { net = htonl(off); - fwrite(&net, 1, sizeof net, fp); + fwrite(&net, 1, sizeof(net), fp); } else { ALLOC(Seekpts, Num_pts + 1); Seekpts[Num_pts] = off; @@ -336,20 +331,20 @@ add_offset(FILE *fp, long off) void do_order(void) { - int i; - long *lp; - STR *fp; + int i; + long *lp; + STR *fp; Sort_1 = fopen(Infile, "r"); Sort_2 = fopen(Infile, "r"); - qsort((char *) Firstch, (int) Tbl.str_numstr, sizeof *Firstch, cmp_str); + qsort((char *)Firstch, (int)Tbl.str_numstr, sizeof(*Firstch), cmp_str); i = Tbl.str_numstr; lp = Seekpts; fp = Firstch; while (i--) *lp++ = fp++->pos; - (void) fclose(Sort_1); - (void) fclose(Sort_2); + fclose(Sort_1); + fclose(Sort_2); Tbl.str_flags |= STR_ORDERED; } @@ -377,24 +372,22 @@ collate_range_cmp (int c1, int c2) int cmp_str(const void *s1, const void *s2) { - const STR *p1, *p2; - int c1, c2; - int n1, n2; - int r; - -# define SET_N(nf,ch) (nf = (ch == '\n')) -# define IS_END(ch,nf) (ch == EOF || (ch == (unsigned char) Delimch && nf)) - - p1 = (const STR *) s1; - p2 = (const STR *) s2; - - c1 = (unsigned char) p1->first; - c2 = (unsigned char) p2->first; + const STR *p1, *p2; + int c1, c2, n1, n2, r; + +#define SET_N(nf,ch) (nf = (ch == '\n')) +#define IS_END(ch,nf) (ch == EOF || (ch == (unsigned char)Delimch && nf)) + + p1 = (const STR *)s1; + p2 = (const STR *)s2; + + c1 = (unsigned char)p1->first; + c2 = (unsigned char)p2->first; if ((r = collate_range_cmp(c1, c2)) != 0) return r; - (void) fseek(Sort_1, p1->pos, 0); - (void) fseek(Sort_2, p2->pos, 0); + fseek(Sort_1, p1->pos, SEEK_SET); + fseek(Sort_2, p2->pos, SEEK_SET); n1 = false; n2 = false; @@ -421,7 +414,8 @@ cmp_str(const void *s1, const void *s2) c1 = 0; if (IS_END(c2, n2)) c2 = 0; - return collate_range_cmp(c1, c2); + + return (collate_range_cmp(c1, c2)); } /* @@ -433,9 +427,9 @@ cmp_str(const void *s1, const void *s2) void randomize(void) { - int cnt, i; - long tmp; - long *sp; + int cnt, i; + long tmp; + long *sp; srandomdev(); diff --git a/games/fortune/strfile/strfile.h b/games/fortune/strfile/strfile.h index ebcd668b6f..ce8819fc77 100644 --- a/games/fortune/strfile/strfile.h +++ b/games/fortune/strfile/strfile.h @@ -13,11 +13,7 @@ * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. - * 4. Neither the name of the University nor the names of its contributors + * 3. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * diff --git a/games/fortune/unstr/unstr.c b/games/fortune/unstr/unstr.c index 2942a3a24f..199bce6a1f 100644 --- a/games/fortune/unstr/unstr.c +++ b/games/fortune/unstr/unstr.c @@ -13,11 +13,7 @@ * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. - * 4. Neither the name of the University nor the names of its contributors + * 3. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * @@ -54,13 +50,13 @@ * Ken Arnold Aug 13, 1978 */ -# include -# include -# include -# include -# include -# include -# include "strfile.h" +#include +#include +#include +#include +#include +#include +#include "strfile.h" char *Infile, /* name of input file */ Datafile[MAXPATHLEN], /* name of data file */ @@ -68,14 +64,14 @@ char *Infile, /* name of input file */ FILE *Inf, *Dataf; -void getargs(char *[]); -void order_unstr(STRFILE *); +void getargs(char *[]); +void order_unstr(STRFILE *); /* ARGSUSED */ int -main(__unused int ac, char **av) +main(int ac __unused, char *av[]) { - static STRFILE tbl; /* description table */ + static STRFILE tbl; /* description table */ getargs(av); if ((Inf = fopen(Infile, "r")) == NULL) { @@ -86,7 +82,7 @@ main(__unused int ac, char **av) perror(Datafile); exit(1); } - (void) fread((char *) &tbl, sizeof tbl, 1, Dataf); + fread((char *)&tbl, sizeof(tbl), 1, Dataf); tbl.str_version = ntohl(tbl.str_version); tbl.str_numstr = ntohl(tbl.str_numstr); tbl.str_longlen = ntohl(tbl.str_longlen); @@ -98,8 +94,8 @@ main(__unused int ac, char **av) } Delimch = tbl.str_delim; order_unstr(&tbl); - (void) fclose(Inf); - (void) fclose(Dataf); + fclose(Inf); + fclose(Dataf); exit(0); } @@ -107,29 +103,29 @@ void getargs(char *av[]) { if (!*++av) { - (void) fprintf(stderr, "usage: unstr datafile\n"); + fprintf(stderr, "usage: unstr datafile\n"); exit(1); } Infile = *av; - (void) strcpy(Datafile, Infile); - (void) strcat(Datafile, ".dat"); + strcpy(Datafile, Infile); + strcat(Datafile, ".dat"); } void order_unstr(STRFILE *tbl) { - unsigned int i; - char *sp; - long pos; - char buf[BUFSIZ]; + unsigned int i; + char *sp; + long pos; + char buf[BUFSIZ]; for (i = 0; i < tbl->str_numstr; i++) { - (void) fread((char *) &pos, 1, sizeof pos, Dataf); - (void) fseek(Inf, ntohl(pos), 0); + fread((char *)&pos, 1, sizeof(pos), Dataf); + fseek(Inf, ntohl(pos), SEEK_SET); if (i != 0) - (void) printf("%c\n", Delimch); + printf("%c\n", Delimch); for (;;) { - sp = fgets(buf, sizeof buf, Inf); + sp = fgets(buf, sizeof(buf), Inf); if (sp == NULL || STR_ENDSTRING(sp, *tbl)) break; else diff --git a/games/grdc/grdc.c b/games/grdc/grdc.c index ac37a340f8..c3571c02cb 100644 --- a/games/grdc/grdc.c +++ b/games/grdc/grdc.c @@ -2,7 +2,7 @@ * Grand digital clock for curses compatible terminals * Usage: grdc [-s] [-d msecs] [n] -- run for n seconds (default infinity) * Flags: -s: scroll (default scroll duration 120msec) - * -d msecs: specify scroll duration (implies -s) + * -d msecs: specify scroll duration (implies -s) * * modified 10-18-89 for curses (jrl) * 10-18-89 added signal handling @@ -57,12 +57,13 @@ int main(int argc, char **argv) { int i, s, k; - int n = 0; + int n; int ch; int scrol; - int forever = 1; + int forever; - scrol = 0; + n = scrol = 0; + forever = 1; while ((ch = getopt(argc, argv, "d:s")) != -1) switch (ch) { @@ -191,7 +192,7 @@ void snooze(long int msecs) { struct timespec ts; - + ts.tv_sec = 0; ts.tv_nsec = 1000000 * msecs; diff --git a/games/hack/Original_READ_ME b/games/hack/Original_READ_ME index 9d2070be09..81ca07ac7f 100644 --- a/games/hack/Original_READ_ME +++ b/games/hack/Original_READ_ME @@ -10,7 +10,7 @@ go into magic mode without the password, can get cores with ^G, etc. (make sure gid isn't checked anywhere else...) 5: recompile hack. 6: put it in games after making it set-uid hack. - 8: fix the bugs I undobtedly left in it. + 8: fix the bugs I undoubtedly left in it. 9: tell me what you think of it. Hack uses the UCB file /etc/termcap to get your terminal escape codes. @@ -39,7 +39,7 @@ hack.mon.c Monsters, moving, attacking, etc. hack.do.c drink, eat, read, wield, save, etc. hack.do1.c zap, wear, remove, etc... hack.pri.c stuff having to do with the screen, most of the terminal - independant stuff is in here. + independent stuff is in here. hack.lev.c temp files and calling of mklev. Because of the peculiar restraints on our system, I make mklev (create diff --git a/games/hack/alloc.c b/games/hack/alloc.c index c97b5c3ffb..0099ce86b7 100644 --- a/games/hack/alloc.c +++ b/games/hack/alloc.c @@ -16,9 +16,11 @@ long * alloc(size_t n) { -long dummy = ftell(stderr); - if(n) dummy = 0; /* make sure arg is used */ - return(&dummy); + long dummy = ftell(stderr); + + if (n) + dummy = 0; /* make sure arg is used */ + return (&dummy); } #else @@ -28,9 +30,9 @@ alloc(size_t lth) { void *ptr; - if((ptr = malloc(lth)) == NULL) + if ((ptr = malloc(lth)) == NULL) panic("Cannot get %d bytes", lth); - return(ptr); + return (ptr); } #endif /* LINT */ diff --git a/games/hack/config.h b/games/hack/config.h index 28f589d742..2173dcd4a2 100644 --- a/games/hack/config.h +++ b/games/hack/config.h @@ -16,8 +16,8 @@ /* #define PYRAMID_BUG */ /* avoid a bug on the Pyramid */ /* #define NOWAITINCLUDE */ /* neither nor exists */ -#define WIZARD "bruno" /* the person allowed to use the -D option */ -#define RECORD "record"/* the file containing the list of topscorers */ +#define WIZARD "bruno" /* the person allowed to use the -D option */ +#define RECORD "record"/* the file containing the list of topscorers */ #define NEWS "news" /* the file containing the latest hack news */ #define HELP "help" /* the file containing a description of the commands */ #define SHELP "hh" /* abbreviated form of the same */ @@ -25,7 +25,7 @@ #define DATAFILE "data" /* a file giving the meaning of symbols used */ #define FMASK 0660 /* file creation mask */ #define HLOCK "perm" /* an empty file used for locking purposes */ -#define LLOCK "safelock" /* link to previous */ +#define LLOCK "safelock" /* link to previous */ #ifdef UNIX /* @@ -48,7 +48,7 @@ #define MAILCKFREQ 100 -#define SHELL /* do not delete the '!' command */ +#define SHELL /* do not delete the '!' command */ #define SUSPEND /* let ^Z suspend the game */ #endif /* UNIX */ @@ -58,9 +58,9 @@ * otherwise it will be the current directory. */ #ifdef QUEST -#define HACKDIR _PATH_QUEST +#define HACKDIR _PATH_QUEST #else /* QUEST */ -#define HACKDIR _PATH_HACK +#define HACKDIR _PATH_HACK #endif /* QUEST */ /* @@ -70,7 +70,7 @@ * since the user might create files in a directory of his choice. * Of course SECURE is meaningful only if HACKDIR is defined. */ -#define SECURE /* do setuid(getuid()) after chdir() */ +#define SECURE /* do setuid(getuid()) after chdir() */ /* * If it is desirable to limit the number of people that can play Hack diff --git a/games/hack/data b/games/hack/data index 5d8d509b0f..5faa3843b0 100644 --- a/games/hack/data +++ b/games/hack/data @@ -146,7 +146,7 @@ c a cockatrice; gle glance from its yellow, piercing toad's eyes will kill both man and beast. Its power of destruction is said to be so great that sometimes simply to hear its hiss can prove - fatal. Its breath is so venomenous that it causes all vege- + fatal. Its breath is so venomous that it causes all vege- tation to wither. There is, however, one creature which can withstand the basilisk's deadly gaze, and this is the weasel. No one knows diff --git a/games/hack/def.gen.h b/games/hack/def.gen.h index 5eda06fffd..0e6bb69ae5 100644 --- a/games/hack/def.gen.h +++ b/games/hack/def.gen.h @@ -4,7 +4,7 @@ struct gen { struct gen *ngen; - xchar gx,gy; + xchar gx, gy; unsigned gflag; /* 037: trap type; 040: SEEN flag */ /* 0100: ONCE only */ #define TRAPTYPE 037 @@ -12,4 +12,4 @@ struct gen { #define ONCE 0100 }; extern struct gen *fgold, *ftrap; -#define newgen() (struct gen *) alloc(sizeof(struct gen)) +#define newgen() alloc(sizeof(struct gen)) diff --git a/games/hack/def.gold.h b/games/hack/def.gold.h index 9bef52ddf1..c279a45991 100644 --- a/games/hack/def.gold.h +++ b/games/hack/def.gold.h @@ -9,4 +9,4 @@ struct gold { }; extern struct gold *fgold; -#define newgold() (struct gold *) alloc(sizeof(struct gold)) +#define newgold() alloc(sizeof(struct gold)) diff --git a/games/hack/def.mkroom.h b/games/hack/def.mkroom.h index ddbb62be1b..f57f34cdbe 100644 --- a/games/hack/def.mkroom.h +++ b/games/hack/def.mkroom.h @@ -2,12 +2,12 @@ /* def.mkroom.h - version 1.0.3 */ struct mkroom { - schar lx,hx,ly,hy; /* usually xchar, but hx may be -1 */ - schar rtype,rlit,doorct,fdoor; + schar lx, hx, ly, hy; /* usually xchar, but hx may be -1 */ + schar rtype, rlit, doorct, fdoor; }; #define MAXNROFROOMS 15 -extern struct mkroom rooms[MAXNROFROOMS+1]; +extern struct mkroom rooms[MAXNROFROOMS + 1]; #define DOORMAX 100 extern coord doors[DOORMAX]; diff --git a/games/hack/def.monst.h b/games/hack/def.monst.h index 703f0fc772..8424396322 100644 --- a/games/hack/def.monst.h +++ b/games/hack/def.monst.h @@ -6,38 +6,38 @@ struct monst { struct monst *nmon; struct permonst *data; unsigned m_id; - xchar mx,my; - xchar mdx,mdy; /* if mdispl then pos where last displayed */ + xchar mx, my; + xchar mdx, mdy; /* if mdispl then pos where last displayed */ #define MTSZ 4 coord mtrack[MTSZ]; /* monster track */ - schar mhp,mhpmax; + schar mhp, mhpmax; char mappearance; /* nonzero for undetected 'M's and for '1's */ - Bitfield(mimic,1); /* undetected mimic */ - Bitfield(mdispl,1); /* mdx,mdy valid */ - Bitfield(minvis,1); /* invisible */ - Bitfield(cham,1); /* shape-changer */ - Bitfield(mhide,1); /* hides beneath objects */ - Bitfield(mundetected,1); /* not seen in present hiding place */ - Bitfield(mspeed,2); - Bitfield(msleep,1); - Bitfield(mfroz,1); - Bitfield(mconf,1); - Bitfield(mflee,1); /* fleeing */ - Bitfield(mfleetim,7); /* timeout for mflee */ - Bitfield(mcan,1); /* has been cancelled */ - Bitfield(mtame,1); /* implies peaceful */ - Bitfield(mpeaceful,1); /* does not attack unprovoked */ - Bitfield(isshk,1); /* is shopkeeper */ - Bitfield(isgd,1); /* is guard */ - Bitfield(mcansee,1); /* cansee 1, temp.blinded 0, blind 0 */ - Bitfield(mblinded,7); /* cansee 0, temp.blinded n, blind 0 */ - Bitfield(mtrapped,1); /* trapped in a pit or bear trap */ - Bitfield(mnamelth,6); /* length of name (following mxlth) */ + Bitfield(mimic, 1); /* undetected mimic */ + Bitfield(mdispl, 1); /* mdx, mdy valid */ + Bitfield(minvis, 1); /* invisible */ + Bitfield(cham, 1); /* shape-changer */ + Bitfield(mhide, 1); /* hides beneath objects */ + Bitfield(mundetected, 1); /* not seen in present hiding place */ + Bitfield(mspeed, 2); + Bitfield(msleep, 1); + Bitfield(mfroz, 1); + Bitfield(mconf, 1); + Bitfield(mflee, 1); /* fleeing */ + Bitfield(mfleetim, 7); /* timeout for mflee */ + Bitfield(mcan, 1); /* has been cancelled */ + Bitfield(mtame, 1); /* implies peaceful */ + Bitfield(mpeaceful, 1); /* does not attack unprovoked */ + Bitfield(isshk, 1); /* is shopkeeper */ + Bitfield(isgd, 1); /* is guard */ + Bitfield(mcansee, 1); /* cansee 1, temp.blinded 0, blind 0 */ + Bitfield(mblinded, 7); /* cansee 0, temp.blinded n, blind 0 */ + Bitfield(mtrapped, 1); /* trapped in a pit or bear trap */ + Bitfield(mnamelth, 6); /* length of name (following mxlth) */ #ifndef NOWORM - Bitfield(wormno,5); /* at most 31 worms on any level */ + Bitfield(wormno, 5); /* at most 31 worms on any level */ #endif /* NOWORM */ unsigned mtrapseen; /* bitmap of traps we've been trapped in */ - long mlstmv; /* prevent two moves at once */ + long mlstmv; /* prevent two moves at once */ struct obj *minvent; long mgold; unsigned mxlth; /* length of following data */ @@ -46,15 +46,15 @@ struct monst { long mextra[1]; /* monster dependent info */ }; -#define newmonst(xl) (struct monst *) alloc((unsigned)(xl) + sizeof(struct monst)) +#define newmonst(xl) alloc((unsigned)(xl) + sizeof(struct monst)) extern struct monst *fmon; extern struct monst *fallen_down; /* these are in mspeed */ -#define MSLOW 1 /* slow monster */ -#define MFAST 2 /* speeded monster */ +#define MSLOW 1 /* slow monster */ +#define MFAST 2 /* speeded monster */ -#define NAME(mtmp) (((char *) mtmp->mextra) + mtmp->mxlth) +#define NAME(mtmp) (((char *)mtmp->mextra) + mtmp->mxlth) #define MREGEN "TVi1" #define UNDEAD "ZVW " diff --git a/games/hack/def.obj.h b/games/hack/def.obj.h index 50b21df1b8..cbdf091f83 100644 --- a/games/hack/def.obj.h +++ b/games/hack/def.obj.h @@ -5,8 +5,8 @@ struct obj { struct obj *nobj; unsigned o_id; unsigned o_cnt_id; /* id of container object is in */ - xchar ox,oy; - xchar odx,ody; + xchar ox ,oy; + xchar odx, ody; uchar otyp; uchar owt; uchar quan; /* use oextra for tmp gold objects */ @@ -15,14 +15,14 @@ struct obj { special for uball and amulet %% BAH */ char olet; char invlet; - Bitfield(oinvis,1); /* not yet implemented */ - Bitfield(odispl,1); - Bitfield(known,1); /* exact nature known */ - Bitfield(dknown,1); /* color or text known */ - Bitfield(cursed,1); - Bitfield(unpaid,1); /* on some bill */ - Bitfield(rustfree,1); - Bitfield(onamelth,6); + Bitfield(oinvis, 1); /* not yet implemented */ + Bitfield(odispl, 1); + Bitfield(known, 1); /* exact nature known */ + Bitfield(dknown, 1); /* color or text known */ + Bitfield(cursed, 1); + Bitfield(unpaid, 1); /* on some bill */ + Bitfield(rustfree, 1); + Bitfield(onamelth, 6); long age; /* creation date */ long owornmask; #define W_ARM 01L @@ -43,6 +43,6 @@ struct obj { extern struct obj *fobj; -#define newobj(xl) (struct obj *) alloc((unsigned)(xl) + sizeof(struct obj)) -#define ONAME(otmp) ((char *) otmp->oextra) +#define newobj(xl) alloc((unsigned)(xl) + sizeof(struct obj)) +#define ONAME(otmp) ((char *)otmp->oextra) #define OGOLD(otmp) (otmp->oextra[0]) diff --git a/games/hack/def.objclass.h b/games/hack/def.objclass.h index 2bc5784c24..e3885549e3 100644 --- a/games/hack/def.objclass.h +++ b/games/hack/def.objclass.h @@ -10,8 +10,8 @@ struct objclass { const char *oc_name; /* actual name */ const char *oc_descr; /* description when name unknown */ char *oc_uname; /* called by user */ - Bitfield(oc_name_known,1); - Bitfield(oc_merge,1); /* merge otherwise equal objects */ + Bitfield(oc_name_known, 1); + Bitfield(oc_merge, 1); /* merge otherwise equal objects */ char oc_olet; schar oc_prob; /* probability for mkobj() */ schar oc_delay; /* delay when using such an object */ @@ -20,9 +20,9 @@ struct objclass { int oc_oi; #define nutrition oc_oi /* for foods */ #define a_ac oc_oc1 /* for armors - only used in ARM_BONUS */ -#define ARM_BONUS(obj) ((10 - objects[obj->otyp].a_ac) + obj->spe) +#define ARM_BONUS(obj) ((10 - objects[obj->otyp].a_ac) + obj->spe) #define a_can oc_oc2 /* for armors */ -#define bits oc_oc1 /* for wands and rings */ +#define bits oc_oc1 /* for wands and rings */ /* wands */ #define NODIR 1 #define IMMEDIATE 2 @@ -53,12 +53,10 @@ extern struct objclass objects[]; #define RING_SYM '=' #define GEM_SYM '*' /* Other places with explicit knowledge of object symbols: - * ....shk.c: char shtypes[] = "=/)%?!["; - * mklev.c: "=/)%?![<>" - * hack.mkobj.c: char mkobjstr[] = "))[[!!!!????%%%%/=**"; - * hack.apply.c: otmp = getobj("0#%", "put in"); - * hack.eat.c: otmp = getobj("%", "eat"); - * hack.invent.c: if(index("!%?[)=*(0/\"", sym)){ - * hack.invent.c: || index("%?!*",otmp->olet))){ + * hack.mklev.c: "=/)%?![<>"[rn2(9)]; + * hack.mkobj.c: char mkobjstr[] = "))[[!!!!????%%%%/=**))[[!!!!????%%%%/=**(%"; + * hack.apply.c: otmp = getobj("0#%", "put in"); + * hack.eat.c: otmp = getobj("%", "eat"); + * hack.invent.c: else if (strchr("!%?[()= /\"0", sym)) { */ #endif /* _DEF_OBJCLASS_H_ */ diff --git a/games/hack/def.objects.h b/games/hack/def.objects.h index 35d8b3eb7e..a2416fb5cb 100644 --- a/games/hack/def.objects.h +++ b/games/hack/def.objects.h @@ -23,7 +23,7 @@ struct objclass objects[] = { /* food 6 makes you stronger (like Popeye) */ /* foods CORPSE up to CORPSE+52 are cadavers */ - FOOD("food ration", 50, 5, 4, 800), + FOOD("food ration", 50, 5, 4, 800), FOOD("tripe ration", 20, 1, 2, 200), FOOD("pancake", 3, 1, 1, 200), FOOD("dead lizard", 3, 0, 1, 40), @@ -99,7 +99,7 @@ struct objclass objects[] = { /* weapons ... - (ROCK-1) are shot using idem+(BOW-ARROW) */ /* weapons AXE, SWORD, THSWORD are good for worm-cutting */ /* weapons (PICK-)AXE, DAGGER, CRYSKNIFE are good for tin-opening */ -#define WEAPON(name,prob,wt,ldam,sdam) { name, NULL, NULL, 1, 0 /*%%*/,\ +#define WEAPON(name,prob,wt,ldam,sdam) { name, NULL, NULL, 1, 0 /*%%*/,\ WEAPON_SYM, prob, 0, wt, ldam, sdam, 0 } WEAPON("arrow", 7, 0, 6, 6), @@ -140,7 +140,7 @@ struct objclass objects[] = { { "enormous rock", NULL, NULL, 1, 0, ROCK_SYM, 100, 0, 200 /* > MAX_CARR_CAP */, 0, 0, 0 }, -#define ARMOR(name,prob,delay,ac,can) { name, NULL, NULL, 1, 0,\ +#define ARMOR(name,prob,delay,ac,can) { name, NULL, NULL, 1, 0,\ ARMOR_SYM, prob, delay, 8, ac, can, 0 } ARMOR("helmet", 3, 1, 9, 0), ARMOR("plate mail", 5, 5, 3, 2), @@ -156,7 +156,7 @@ struct objclass objects[] = { ARMOR("shield", 3, 0, 9, 0), ARMOR("pair of gloves", 1, 1, 9, 0), -#define POTION(name,color) { name, color, NULL, 0, 1,\ +#define POTION(name,color) { name, color, NULL, 0, 1,\ POTION_SYM, 0, 0, 2, 0, 0, 0 } POTION("restore strength", "orange"), @@ -180,7 +180,7 @@ struct objclass objects[] = { POTION(NULL, "magenta"), POTION(NULL, "ebony"), -#define SCROLL(name,text,prob) { name, text, NULL, 0, 1,\ +#define SCROLL(name,text,prob) { name, text, NULL, 0, 1,\ SCROLL_SYM, prob, 0, 3, 0, 0, 0 } SCROLL("mail", "KIRJE", 0), SCROLL("enchant armor", "ZELGO MER", 6), diff --git a/games/hack/def.permonst.h b/games/hack/def.permonst.h index 74eb9f8910..591a6c627b 100644 --- a/games/hack/def.permonst.h +++ b/games/hack/def.permonst.h @@ -5,12 +5,12 @@ struct permonst { const char *mname; char mlet; - schar mlevel,mmove,ac,damn,damd; + schar mlevel, mmove, ac, damn, damd; unsigned pxlth; }; extern struct permonst mons[]; -#define PM_ACID_BLOB &mons[7] +#define PM_ACID_BLOB &mons[7] #define PM_ZOMBIE &mons[13] #define PM_PIERCER &mons[17] #define PM_KILLER_BEE &mons[26] diff --git a/games/hack/def.rm.h b/games/hack/def.rm.h index 2a48df2abe..46f3975048 100644 --- a/games/hack/def.rm.h +++ b/games/hack/def.rm.h @@ -8,7 +8,7 @@ #define SDOOR 3 #define SCORR 4 #define LDOOR 5 -#define POOL 6 /* not yet fully implemented */ +#define POOL 6 /* not yet fully implemented */ /* this should in fact be a bit like lit */ #define DOOR 7 #define CORR 8 @@ -21,10 +21,10 @@ * Instead, use one of the macros below. */ #define IS_WALL(typ) ((typ) <= VWALL) -#define IS_ROCK(typ) ((typ) < POOL) /* absolutely nonaccessible */ -#define ACCESSIBLE(typ) ((typ) >= DOOR) /* good position */ -#define IS_ROOM(typ) ((typ) >= ROOM) /* ROOM or STAIRS */ -#define ZAP_POS(typ) ((typ) > DOOR) +#define IS_ROCK(typ) ((typ) < POOL) /* absolutely nonaccessible */ +#define ACCESSIBLE(typ) ((typ) >= DOOR) /* good position */ +#define IS_ROOM(typ) ((typ) >= ROOM) /* ROOM or STAIRS */ +#define ZAP_POS(typ) ((typ) > DOOR) /* * A few of the associated symbols are not hardwired. diff --git a/games/hack/def.trap.h b/games/hack/def.trap.h index 27fa67bd17..2d25ec174c 100644 --- a/games/hack/def.trap.h +++ b/games/hack/def.trap.h @@ -4,24 +4,24 @@ struct trap { struct trap *ntrap; - xchar tx,ty; + xchar tx, ty; unsigned ttyp:5; unsigned tseen:1; unsigned once:1; }; extern struct trap *ftrap; -#define newtrap() (struct trap *) alloc(sizeof(struct trap)) +#define newtrap() alloc(sizeof(struct trap)) /* various kinds of traps */ -#define BEAR_TRAP 0 +#define BEAR_TRAP 0 #define ARROW_TRAP 1 #define DART_TRAP 2 -#define TRAPDOOR 3 +#define TRAPDOOR 3 #define TELEP_TRAP 4 -#define PIT 5 -#define SLP_GAS_TRAP 6 +#define PIT 5 +#define SLP_GAS_TRAP 6 #define PIERC 7 #define MIMIC 8 /* used only in mklev.c */ -#define TRAPNUM 9 /* if not less than 32, change sizeof(ttyp) */ +#define TRAPNUM 9 /* if not less than 32, change sizeof(ttyp) */ /* see also mtrapseen (bit map) */ diff --git a/games/hack/def.wseg.h b/games/hack/def.wseg.h index e9c33c0246..161ead9a3f 100644 --- a/games/hack/def.wseg.h +++ b/games/hack/def.wseg.h @@ -6,9 +6,9 @@ /* worm structure */ struct wseg { struct wseg *nseg; - xchar wx,wy; + xchar wx, wy; unsigned wdispl:1; }; -#define newseg() (struct wseg *) alloc(sizeof(struct wseg)) +#define newseg() alloc(sizeof(struct wseg)) #endif /* NOWORM */ diff --git a/games/hack/hack.Decl.c b/games/hack/hack.Decl.c index fc78113436..6c2cfce597 100644 --- a/games/hack/hack.Decl.c +++ b/games/hack/hack.Decl.c @@ -2,16 +2,16 @@ /* hack.Decl.c - version 1.0.3 */ /* $DragonFly: src/games/hack/hack.Decl.c,v 1.4 2006/08/21 19:45:32 pavalos Exp $ */ -#include "hack.h" +#include "hack.h" char nul[40]; /* contains zeros */ char plname[PL_NSIZ]; /* player name */ -char lock[PL_NSIZ+4] = "1lock"; /* long enough for login name .99 */ +char lock[PL_NSIZ + 4] = "1lock"; /* long enough for login name .99 */ boolean in_mklev, restoring; struct rm levl[COLNO][ROWNO]; /* level map */ #ifndef QUEST -struct mkroom rooms[MAXNROFROOMS+1]; +struct mkroom rooms[MAXNROFROOMS + 1]; coord doors[DOORMAX]; #endif /* QUEST */ struct monst *fmon = 0; @@ -35,7 +35,7 @@ int multi = 0; char genocided[60]; char fut_geno[60]; -xchar curx,cury; +xchar curx, cury; xchar seelx, seehx, seely, seehy; /* corners of lit room */ coord bhitpos; diff --git a/games/hack/hack.apply.c b/games/hack/hack.apply.c index c4d6fc11a2..499a7379dd 100644 --- a/games/hack/hack.apply.c +++ b/games/hack/hack.apply.c @@ -3,8 +3,8 @@ /* $FreeBSD: src/games/hack/hack.apply.c,v 1.4.2.1 2001/02/18 02:20:07 kris Exp $ */ /* $DragonFly: src/games/hack/hack.apply.c,v 1.4 2006/08/21 19:45:32 pavalos Exp $ */ -#include "hack.h" -#include "def.edog.h" +#include "hack.h" +#include "def.edog.h" extern char quitchars[]; static void use_camera(struct obj *); @@ -25,19 +25,22 @@ doapply(void) int res = 1; obj = getobj("(", "use or apply"); - if(!obj) return(0); + if (!obj) + return (0); - switch(obj->otyp){ + switch (obj->otyp) { case EXPENSIVE_CAMERA: - use_camera(obj); break; + use_camera(obj); + break; case ICE_BOX: - use_ice_box(obj); break; + use_ice_box(obj); + break; case PICK_AXE: res = use_pick_axe(obj); break; case MAGIC_WHISTLE: - if(pl_character[0] == 'W' || u.ulevel > 9) { + if (pl_character[0] == 'W' || u.ulevel > 9) { use_magic_whistle(obj); break; } @@ -47,68 +50,71 @@ doapply(void) break; case CAN_OPENER: - if(!carrying(TIN)) { + if (!carrying(TIN)) { pline("You have no can to open."); goto xit; } pline("You cannot open a tin without eating its contents."); pline("In order to eat, use the 'e' command."); - if(obj != uwep) - pline("Opening the tin will be much easier if you wield the can-opener."); + if (obj != uwep) + pline("Opening the tin will be much easier if you wield the can-opener."); goto xit; default: pline("Sorry, I don't know how to use that."); - xit: +xit: nomul(0); - return(0); + return (0); } nomul(0); - return(res); + return (res); } static void -use_camera(__unused struct obj *obj) +use_camera(struct obj *obj __unused) { -struct monst *mtmp; - if(!getdir(1)){ /* ask: in what direction? */ + struct monst *mtmp; + + if (!getdir(1)) { /* ask: in what direction? */ flags.move = multi = 0; return; } - if(u.uswallow) { + if (u.uswallow) { pline("You take a picture of %s's stomach.", monnam(u.ustuck)); return; } - if(u.dz) { + if (u.dz) { pline("You take a picture of the %s.", - (u.dz > 0) ? "floor" : "ceiling"); + (u.dz > 0) ? "floor" : "ceiling"); return; } - if((mtmp = bchit(u.dx, u.dy, COLNO, '!'))) { - if(mtmp->msleep){ + if ((mtmp = bchit(u.dx, u.dy, COLNO, '!')) != NULL) { + if (mtmp->msleep) { mtmp->msleep = 0; - pline("The flash awakens %s.", monnam(mtmp)); /* a3 */ - } else - if(mtmp->data->mlet != 'y') - if(mtmp->mcansee || mtmp->mblinded){ - int tmp = dist(mtmp->mx,mtmp->my); - int tmp2; - if(cansee(mtmp->mx,mtmp->my)) - pline("%s is blinded by the flash!", Monnam(mtmp)); - setmangry(mtmp); - if(tmp < 9 && !mtmp->isshk && rn2(4)) { - mtmp->mflee = 1; - if(rn2(4)) mtmp->mfleetim = rnd(100); - } - if(tmp < 3) mtmp->mcansee = mtmp->mblinded = 0; - else { - tmp2 = mtmp->mblinded; - tmp2 += rnd(1 + 50/tmp); - if(tmp2 > 127) tmp2 = 127; - mtmp->mblinded = tmp2; - mtmp->mcansee = 0; + pline("The flash awakens %s.", monnam(mtmp)); /* a3 */ + } else if (mtmp->data->mlet != 'y') + if (mtmp->mcansee || mtmp->mblinded) { + int tmp = dist(mtmp->mx, mtmp->my); + int tmp2; + if (cansee(mtmp->mx, mtmp->my)) + pline("%s is blinded by the flash!", Monnam(mtmp)); + setmangry(mtmp); + if (tmp < 9 && !mtmp->isshk && rn2(4)) { + mtmp->mflee = 1; + if (rn2(4)) + mtmp->mfleetim = rnd(100); + } + if (tmp < 3) + mtmp->mcansee = mtmp->mblinded = 0; + else { + tmp2 = mtmp->mblinded; + tmp2 += rnd(1 + 50 / tmp); + if (tmp2 > 127) + tmp2 = 127; + mtmp->mblinded = tmp2; + mtmp->mcansee = 0; + } } - } } } @@ -118,23 +124,23 @@ struct obj *current_ice_box; /* a local variable of use_ice_box, to be static bool in_ice_box(struct obj *obj) { - if(obj == current_ice_box || - (Punished && (obj == uball || obj == uchain))){ + if (obj == current_ice_box || + (Punished && (obj == uball || obj == uchain))) { pline("You must be kidding."); - return(0); + return (0); } - if(obj->owornmask & (W_ARMOR | W_RING)) { + if (obj->owornmask & (W_ARMOR | W_RING)) { pline("You cannot refrigerate something you are wearing."); - return(0); + return (0); } - if(obj->owt + current_ice_box->owt > 70) { + if (obj->owt + current_ice_box->owt > 70) { pline("It won't fit."); - return(1); /* be careful! */ + return (1); /* be careful! */ } - if(obj == uwep) { - if(uwep->cursed) { + if (obj == uwep) { + if (uwep->cursed) { pline("Your weapon is welded to your hand!"); - return(0); + return (0); } setuwep(NULL); } @@ -144,88 +150,99 @@ in_ice_box(struct obj *obj) obj->nobj = fcobj; fcobj = obj; obj->age = moves - obj->age; /* actual age */ - return(1); + return (1); } static bool ck_ice_box(struct obj *obj) { - return(obj->o_cnt_id == current_ice_box->o_id); + return (obj->o_cnt_id == current_ice_box->o_id); } static int out_ice_box(struct obj *obj) { -struct obj *otmp; - if(obj == fcobj) fcobj = fcobj->nobj; + struct obj *otmp; + + if (obj == fcobj) + fcobj = fcobj->nobj; else { - for(otmp = fcobj; otmp->nobj != obj; otmp = otmp->nobj) - if(!otmp->nobj) panic("out_ice_box"); + for (otmp = fcobj; otmp->nobj != obj; otmp = otmp->nobj) + if (!otmp->nobj) + panic("out_ice_box"); otmp->nobj = obj->nobj; } current_ice_box->owt -= obj->owt; obj->age = moves - obj->age; /* simulated point of time */ addinv(obj); - return(0); + return (0); } static void use_ice_box(struct obj *obj) { -int cnt = 0; -struct obj *otmp; + int cnt = 0; + struct obj *otmp; + current_ice_box = obj; /* for use by in/out_ice_box */ - for(otmp = fcobj; otmp; otmp = otmp->nobj) - if(otmp->o_cnt_id == obj->o_id) + for (otmp = fcobj; otmp; otmp = otmp->nobj) + if (otmp->o_cnt_id == obj->o_id) cnt++; - if(!cnt) pline("Your ice-box is empty."); + if (!cnt) + pline("Your ice-box is empty."); else { - pline("Do you want to take something out of the ice-box? [yn] "); - if(readchar() == 'y') - if(askchain(fcobj, NULL, 0, out_ice_box, ck_ice_box, 0)) - return; + pline("Do you want to take something out of the ice-box? [yn] "); + if (readchar() == 'y') + if (askchain(fcobj, NULL, 0, out_ice_box, ck_ice_box, 0)) + return; pline("That was all. Do you wish to put something in? [yn] "); - if(readchar() != 'y') return; + if (readchar() != 'y') + return; } /* call getobj: 0: allow cnt; #: allow all types; %: expect food */ otmp = getobj("0#%", "put in"); - if(!otmp || !in_ice_box(otmp)) + if (!otmp || !in_ice_box(otmp)) flags.move = multi = 0; } -static struct monst * +static +struct monst * bchit(int ddx, int ddy, int range, char sym) { struct monst *mtmp = NULL; int bchx = u.ux, bchy = u.uy; - if(sym) Tmp_at(-1, sym); /* open call */ - while(range--) { + if (sym) + Tmp_at(-1, sym); /* open call */ + while (range--) { bchx += ddx; bchy += ddy; - if((mtmp = m_at(bchx,bchy))) + if ((mtmp = m_at(bchx, bchy))) break; - if(!ZAP_POS(levl[bchx][bchy].typ)) { + if (!ZAP_POS(levl[bchx][bchy].typ)) { bchx -= ddx; bchy -= ddy; break; } - if(sym) Tmp_at(bchx, bchy); + if (sym) + Tmp_at(bchx, bchy); } - if(sym) Tmp_at(-1, -1); - return(mtmp); + if (sym) + Tmp_at(-1, -1); + return (mtmp); } static void -use_whistle(__unused struct obj *obj) +use_whistle(struct obj *obj __unused) { -struct monst *mtmp = fmon; + struct monst *mtmp = fmon; + pline("You produce a high whistling sound."); - while(mtmp) { - if(dist(mtmp->mx,mtmp->my) < u.ulevel*20) { - if(mtmp->msleep) + while (mtmp) { + if (dist(mtmp->mx, mtmp->my) < u.ulevel * 20) { + if (mtmp->msleep) mtmp->msleep = 0; - if(mtmp->mtame) + if (mtmp->mtame) EDOG(mtmp)->whistletime = moves; } mtmp = mtmp->nmon; @@ -233,12 +250,14 @@ struct monst *mtmp = fmon; } static void -use_magic_whistle(__unused struct obj *obj) +use_magic_whistle(struct obj *obj __unused) { -struct monst *mtmp = fmon; + struct monst *mtmp = fmon; + pline("You produce a strange whistling sound."); - while(mtmp) { - if(mtmp->mtame) mnexto(mtmp); + while (mtmp) { + if (mtmp->mtame) + mnexto(mtmp); mtmp = mtmp->nmon; } } @@ -248,7 +267,8 @@ static uchar dig_level; static coord dig_pos; static boolean dig_down; -static bool +static +bool dig(void) { struct rm *lev; @@ -256,75 +276,74 @@ dig(void) /* perhaps a nymph stole his pick-axe while he was busy digging */ /* or perhaps he teleported away */ - if(u.uswallow || !uwep || uwep->otyp != PICK_AXE || + if (u.uswallow || !uwep || uwep->otyp != PICK_AXE || dig_level != dlevel || ((dig_down && (dpx != u.ux || dpy != u.uy)) || - (!dig_down && dist(dpx,dpy) > 2))) - return(0); + (!dig_down && dist(dpx, dpy) > 2))) + return (0); dig_effort += 10 + abon() + uwep->spe + rn2(5); - if(dig_down) { - if(!xdnstair) { + if (dig_down) { + if (!xdnstair) { pline("The floor here seems too hard to dig in."); - return(0); + return (0); } - if(dig_effort > 250) { + if (dig_effort > 250) { dighole(); - return(0); /* done with digging */ + return (0); /* done with digging */ } - if(dig_effort > 50) { - struct trap *ttmp = t_at(dpx,dpy); + if (dig_effort > 50) { + struct trap *ttmp = t_at(dpx, dpy); - if(!ttmp) { - ttmp = maketrap(dpx,dpy,PIT); + if (!ttmp) { + ttmp = maketrap(dpx, dpy, PIT); ttmp->tseen = 1; pline("You have dug a pit."); - u.utrap = rn1(4,2); + u.utrap = rn1(4, 2); u.utraptype = TT_PIT; - return(0); + return (0); } } - } else - if(dig_effort > 100) { + } else if (dig_effort > 100) { const char *digtxt; struct obj *obj; lev = &levl[dpx][dpy]; - if((obj = sobj_at(ENORMOUS_ROCK, dpx, dpy))) { + if ((obj = sobj_at(ENORMOUS_ROCK, dpx, dpy)) != NULL) { fracture_rock(obj); digtxt = "The rock falls apart."; - } else if(!lev->typ || lev->typ == SCORR) { + } else if (!lev->typ || lev->typ == SCORR) { lev->typ = CORR; digtxt = "You succeeded in cutting away some rock."; - } else if(lev->typ == HWALL || lev->typ == VWALL - || lev->typ == SDOOR) { + } else if (lev->typ == HWALL || lev->typ == VWALL + || lev->typ == SDOOR) { lev->typ = xdnstair ? DOOR : ROOM; digtxt = "You just made an opening in the wall."; } else - digtxt = "Now what exactly was it that you were digging in?"; + digtxt = "Now what exactly was it that you were digging in?"; mnewsym(dpx, dpy); prl(dpx, dpy); - pline("%s", digtxt); /* after mnewsym & prl */ - return(0); + pline("%s", digtxt); /* after mnewsym & prl */ + return (0); } else { - if(IS_WALL(levl[dpx][dpy].typ)) { - int rno = inroom(dpx,dpy); + if (IS_WALL(levl[dpx][dpy].typ)) { + int rno = inroom(dpx, dpy); - if(rno >= 0 && rooms[rno].rtype >= 8) { - pline("This wall seems too hard to dig into."); - return(0); + if (rno >= 0 && rooms[rno].rtype >= 8) { + pline("This wall seems too hard to dig into."); + return (0); } } pline("You hit the rock with all your might."); } - return(1); + return (1); } /* When will hole be finished? Very rough indication used by shopkeeper. */ int holetime(void) { - return( (occupation == dig) ? (250 - dig_effort)/20 : -1); + return ((occupation == dig) ? (250 - dig_effort) / 20 : -1); } void @@ -332,24 +351,24 @@ dighole(void) { struct trap *ttmp = t_at(u.ux, u.uy); - if(!xdnstair) { + if (!xdnstair) { pline("The floor here seems too hard to dig in."); } else { - if(ttmp) + if (ttmp) ttmp->ttyp = TRAPDOOR; else ttmp = maketrap(u.ux, u.uy, TRAPDOOR); ttmp->tseen = 1; pline("You've made a hole in the floor."); - if(!u.ustuck) { - if(inshop()) + if (!u.ustuck) { + if (inshop()) shopdig(1); pline("You fall through ..."); - if(u.utraptype == TT_PIT) { + if (u.utraptype == TT_PIT) { u.utrap = 0; u.utraptype = 0; } - goto_level(dlevel+1, FALSE); + goto_level(dlevel + 1, FALSE); } } } @@ -363,22 +382,22 @@ use_pick_axe(struct obj *obj) struct rm *lev; int rx, ry, res = 0; - if(obj != uwep) { - if(uwep && uwep->cursed) { + if (obj != uwep) { + if (uwep && uwep->cursed) { /* Andreas Bormann - ihnp4!decvax!mcvax!unido!ab */ pline("Since your weapon is welded to your hand,"); pline("you cannot use that pick-axe."); - return(0); + return (0); } pline("You now wield %s.", doname(obj)); setuwep(obj); res = 1; } - while(*sdp) { + while (*sdp) { movecmd(*sdp); /* sets u.dx and u.dy and u.dz */ rx = u.ux + u.dx; ry = u.uy + u.dy; - if(u.dz > 0 || (u.dz == 0 && isok(rx, ry) && + if (u.dz > 0 || (u.dz == 0 && isok(rx, ry) && (IS_ROCK(levl[rx][ry].typ) || sobj_at(ENORMOUS_ROCK, rx, ry)))) *dsp++ = *sdp; @@ -386,35 +405,34 @@ use_pick_axe(struct obj *obj) } *dsp = 0; pline("In what direction do you want to dig? [%s] ", dirsyms); - if(!getdir(0)) /* no txt */ - return(res); - if(u.uswallow && attack(u.ustuck)) /* return(1) */; - else - if(u.dz < 0) + if (!getdir(0)) /* no txt */ + return (res); + if (u.uswallow && attack(u.ustuck)) /* return(1) */ + ; + else if (u.dz < 0) pline("You cannot reach the ceiling."); - else - if(u.dz == 0) { - if(Confusion) + else if (u.dz == 0) { + if (Confusion) confdir(); rx = u.ux + u.dx; ry = u.uy + u.dy; - if((mtmp = m_at(rx, ry)) && attack(mtmp)) - return(1); - if(!isok(rx, ry)) { + if ((mtmp = m_at(rx, ry)) && attack(mtmp)) + return (1); + if (!isok(rx, ry)) { pline("Clash!"); - return(1); + return (1); } lev = &levl[rx][ry]; - if(lev->typ == DOOR) + if (lev->typ == DOOR) pline("Your %s against the door.", - aobjnam(obj, "clang")); - else if(!IS_ROCK(lev->typ) - && !sobj_at(ENORMOUS_ROCK, rx, ry)) { + aobjnam(obj, "clang")); + else if (!IS_ROCK(lev->typ) + && !sobj_at(ENORMOUS_ROCK, rx, ry)) { /* ACCESSIBLE or POOL */ pline("You swing your %s through thin air.", - aobjnam(obj, NULL)); + aobjnam(obj, NULL)); } else { - if(dig_pos.x != rx || dig_pos.y != ry + if (dig_pos.x != rx || dig_pos.y != ry || dig_level != dlevel || dig_down) { dig_down = FALSE; dig_pos.x = rx; @@ -427,10 +445,10 @@ use_pick_axe(struct obj *obj) occupation = dig; occtxt = "digging"; } - } else if(Levitation) { + } else if (Levitation) { pline("You cannot reach the floor."); } else { - if(dig_pos.x != u.ux || dig_pos.y != u.uy + if (dig_pos.x != u.ux || dig_pos.y != u.uy || dig_level != dlevel || !dig_down) { dig_down = TRUE; dig_pos.x = u.ux; @@ -438,12 +456,12 @@ use_pick_axe(struct obj *obj) dig_level = dlevel; dig_effort = 0; pline("You start digging in the floor."); - if(inshop()) + if (inshop()) shopdig(0); } else pline("You continue digging in the floor."); occupation = dig; occtxt = "digging"; } - return(1); + return (1); } diff --git a/games/hack/hack.bones.c b/games/hack/hack.bones.c index f8d633443a..97ecc0f251 100644 --- a/games/hack/hack.bones.c +++ b/games/hack/hack.bones.c @@ -11,27 +11,31 @@ char bones[] = "bones_xx"; void savebones(void) { -int fd; -struct obj *otmp; -struct trap *ttmp; -struct monst *mtmp; - if(dlevel <= 0 || dlevel > MAXLEVEL) return; - if(!rn2(1 + dlevel/2)) return; /* not so many ghosts on low levels */ - bones[6] = '0' + (dlevel/10); - bones[7] = '0' + (dlevel%10); - if((fd = open(bones,0)) >= 0){ + int fd; + struct obj *otmp; + struct trap *ttmp; + struct monst *mtmp; + + if (dlevel <= 0 || dlevel > MAXLEVEL) + return; + if (!rn2(1 + dlevel / 2)) /* not so many ghosts on low levels */ + return; + bones[6] = '0' + (dlevel / 10); + bones[7] = '0' + (dlevel % 10); + if ((fd = open(bones, O_RDONLY)) >= 0) { close(fd); return; } /* drop everything; the corpse's possessions are usually cursed */ otmp = invent; - while(otmp){ + while (otmp) { otmp->ox = u.ux; otmp->oy = u.uy; otmp->age = 0; /* very long ago */ otmp->owornmask = 0; - if(rn2(5)) otmp->cursed = 1; - if(!otmp->nobj){ + if (rn2(5)) + otmp->cursed = 1; + if (!otmp->nobj) { otmp->nobj = fobj; fobj = invent; invent = 0; /* superfluous */ @@ -39,59 +43,66 @@ struct monst *mtmp; } otmp = otmp->nobj; } - if(!(mtmp = makemon(PM_GHOST, u.ux, u.uy))) return; + if (!(mtmp = makemon(PM_GHOST, u.ux, u.uy))) + return; mtmp->mx = u.ux; mtmp->my = u.uy; mtmp->msleep = 1; - strcpy((char *) mtmp->mextra, plname); - mkgold(somegold() + d(dlevel,30), u.ux, u.uy); - for(mtmp = fmon; mtmp; mtmp = mtmp->nmon){ + strcpy((char *)mtmp->mextra, plname); + mkgold(somegold() + d(dlevel, 30), u.ux, u.uy); + for (mtmp = fmon; mtmp; mtmp = mtmp->nmon) { mtmp->m_id = 0; - if(mtmp->mtame) { + if (mtmp->mtame) { mtmp->mtame = 0; mtmp->mpeaceful = 0; } mtmp->mlstmv = 0; - if(mtmp->mdispl) unpmon(mtmp); + if (mtmp->mdispl) + unpmon(mtmp); } - for(ttmp = ftrap; ttmp; ttmp = ttmp->ntrap) + for (ttmp = ftrap; ttmp; ttmp = ttmp->ntrap) ttmp->tseen = 0; - for(otmp = fobj; otmp; otmp = otmp->nobj) { + for (otmp = fobj; otmp; otmp = otmp->nobj) { otmp->o_id = 0; - /* otmp->o_cnt_id = 0; - superfluous */ + /* otmp->o_cnt_id = 0; - superfluous */ otmp->onamelth = 0; otmp->known = 0; otmp->invlet = 0; - if(otmp->olet == AMULET_SYM && !otmp->spe) { - otmp->spe = -1; /* no longer the actual amulet */ - otmp->cursed = 1; /* flag as gotten from a ghost */ + if (otmp->olet == AMULET_SYM && !otmp->spe) { + otmp->spe = -1; /* no longer the actual amulet */ + otmp->cursed = 1; /* flag as gotten from a ghost */ } } - if((fd = creat(bones, FMASK)) < 0) return; - savelev(fd,dlevel); + if ((fd = creat(bones, FMASK)) < 0) + return; + savelev(fd, dlevel); close(fd); } int getbones(void) { -int fd,x,y,ok; - if(rn2(3)) return(0); /* only once in three times do we find bones */ - bones[6] = '0' + dlevel/10; - bones[7] = '0' + dlevel%10; - if((fd = open(bones, 0)) < 0) return(0); - if((ok = uptodate(fd)) != 0){ + int fd, x, y, ok; + + if (rn2(3)) /* only once in three times do we find bones */ + return (0); + bones[6] = '0' + dlevel / 10; + bones[7] = '0' + dlevel % 10; + if ((fd = open(bones, O_RDONLY)) < 0) + return (0); + if ((ok = uptodate(fd)) != 0) { getlev(fd, 0, dlevel); - for(x = 0; x < COLNO; x++) for(y = 0; y < ROWNO; y++) - levl[x][y].seen = levl[x][y].new = 0; + for (x = 0; x < COLNO; x++) + for (y = 0; y < ROWNO; y++) + levl[x][y].seen = levl[x][y].new = 0; } close(fd); #ifdef WIZARD - if(!wizard) /* duvel!frans: don't remove bones while debugging */ + if (!wizard) /* duvel!frans: don't remove bones while debugging */ #endif /* WiZARD */ - if(unlink(bones) < 0){ - pline("Cannot unlink %s .", bones); - return(0); - } - return(ok); + if (unlink(bones) < 0) { + pline("Cannot unlink %s .", bones); + return (0); + } + return (ok); } diff --git a/games/hack/hack.c b/games/hack/hack.c index 71223d1199..42bc267ac3 100644 --- a/games/hack/hack.c +++ b/games/hack/hack.c @@ -5,69 +5,74 @@ #include "hack.h" -static void movobj(struct obj *, int, int); +static void movobj(struct obj *, int, int); #ifdef QUEST -static bool rroom(int, int); +static bool rroom(int, int); #endif -static int inv_cnt(void); +static int inv_cnt(void); /* called on movement: - 1. when throwing ball+chain far away - 2. when teleporting - 3. when walking out of a lit room + * 1. when throwing ball+chain far away + * 2. when teleporting + * 3. when walking out of a lit room */ void unsee(void) { - int x,y; + int x, y; struct rm *lev; #ifndef QUEST - if(seehx){ + if (seehx) seehx = 0; - } else + else #endif /* QUEST */ - for(x = u.ux-1; x < u.ux+2; x++) - for(y = u.uy-1; y < u.uy+2; y++) { - if(!isok(x, y)) continue; - lev = &levl[x][y]; - if(!lev->lit && lev->scrsym == '.') { - lev->scrsym =' '; - lev->new = 1; - on_scr(x,y); - } - } + for (x = u.ux - 1; x < u.ux + 2; x++) + for (y = u.uy - 1; y < u.uy + 2; y++) { + if (!isok(x, y)) + continue; + lev = &levl[x][y]; + if (!lev->lit && lev->scrsym == '.') { + lev->scrsym = ' '; + lev->new = 1; + on_scr(x, y); + } + } } /* called: - in hack.eat.c: seeoff(0) - blind after eating rotten food - in hack.mon.c: seeoff(0) - blinded by a yellow light - in hack.mon.c: seeoff(1) - swallowed - in hack.do.c: seeoff(0) - blind after drinking potion - in hack.do.c: seeoff(1) - go up or down the stairs - in hack.trap.c:seeoff(1) - fall through trapdoor + * in hack.eat.c: seeoff(0) - blind after eating rotten food + * in hack.mon.c: seeoff(0) - blinded by a yellow light + * in hack.mon.c: seeoff(1) - swallowed + * in hack.do.c: seeoff(0) - blind after drinking potion + * in hack.do.c: seeoff(1) - go up or down the stairs + * in hack.trap.c:seeoff(1) - fall through trapdoor + * mode: + * 1 to redo @, 0 to leave them *//* 1 means + * misc movement, 0 means blindness */ void -seeoff(bool mode) /* 1 to redo @, 0 to leave them */ -{ /* 1 means misc movement, 0 means blindness */ - int x,y; +seeoff(bool mode) +{ + int x, y; struct rm *lev; - if(u.udispl && mode){ + if (u.udispl && mode) { u.udispl = 0; - levl[u.udisx][u.udisy].scrsym = news0(u.udisx,u.udisy); + levl[u.udisx][u.udisy].scrsym = news0(u.udisx, u.udisy); } #ifndef QUEST - if(seehx) { + if (seehx) seehx = 0; - } else + else #endif /* QUEST */ - if(!mode) { - for(x = u.ux-1; x < u.ux+2; x++) - for(y = u.uy-1; y < u.uy+2; y++) { - if(!isok(x, y)) continue; + if (!mode) { + for (x = u.ux - 1; x < u.ux + 2; x++) + for (y = u.uy - 1; y < u.uy + 2; y++) { + if (!isok(x, y)) + continue; lev = &levl[x][y]; - if(!lev->lit && lev->scrsym == '.') + if (!lev->lit && lev->scrsym == '.') lev->seen = 0; } } @@ -76,31 +81,31 @@ seeoff(bool mode) /* 1 to redo @, 0 to leave them */ void domove(void) { - xchar oldx,oldy; + xchar oldx, oldy; struct monst *mtmp = NULL; - struct rm *tmpr,*ust; + struct rm *tmpr, *ust; struct trap *trap = NULL; struct obj *otmp; u_wipe_engr(rnd(5)); - if(inv_weight() > 0){ + if (inv_weight() > 0) { pline("You collapse under your load."); nomul(0); return; } - if(u.uswallow) { + if (u.uswallow) { u.dx = u.dy = 0; u.ux = u.ustuck->mx; u.uy = u.ustuck->my; } else { - if(Confusion) { + if (Confusion) { do { confdir(); - } while(!isok(u.ux+u.dx, u.uy+u.dy) || - IS_ROCK(levl[u.ux+u.dx][u.uy+u.dy].typ)); + } while (!isok(u.ux + u.dx, u.uy + u.dy) || + IS_ROCK(levl[u.ux + u.dx][u.uy + u.dy].typ)); } - if(!isok(u.ux+u.dx, u.uy+u.dy)){ + if (!isok(u.ux + u.dx, u.uy + u.dy)) { nomul(0); return; } @@ -109,79 +114,84 @@ domove(void) ust = &levl[u.ux][u.uy]; oldx = u.ux; oldy = u.uy; - if(!u.uswallow && (trap = t_at(u.ux+u.dx, u.uy+u.dy)) && trap->tseen) + if (!u.uswallow && + (trap = t_at(u.ux + u.dx, u.uy + u.dy)) && trap->tseen) nomul(0); - if(u.ustuck && !u.uswallow && (u.ux+u.dx != u.ustuck->mx || - u.uy+u.dy != u.ustuck->my)) { - if(dist(u.ustuck->mx, u.ustuck->my) > 2){ + if (u.ustuck && !u.uswallow && (u.ux + u.dx != u.ustuck->mx || + u.uy + u.dy != u.ustuck->my)) { + if (dist(u.ustuck->mx, u.ustuck->my) > 2) { /* perhaps it fled (or was teleported or ... ) */ u.ustuck = 0; } else { - if(Blind) pline("You cannot escape from it!"); - else pline("You cannot escape from %s!", - monnam(u.ustuck)); + if (Blind) + pline("You cannot escape from it!"); + else + pline("You cannot escape from %s!", + monnam(u.ustuck)); nomul(0); return; } } - if(u.uswallow || (mtmp = m_at(u.ux+u.dx,u.uy+u.dy))) { - /* attack monster */ + if (u.uswallow || (mtmp = m_at(u.ux + u.dx, u.uy + u.dy))) { + /* attack monster */ nomul(0); gethungry(); - if(multi < 0) return; /* we just fainted */ + if (multi < 0) /* we just fainted */ + return; /* try to attack; note that it might evade */ - if(attack(u.uswallow ? u.ustuck : mtmp)) + if (attack(u.uswallow ? u.ustuck : mtmp)) return; } /* not attacking an animal, so we try to move */ - if(u.utrap) { - if(u.utraptype == TT_PIT) { + if (u.utrap) { + if (u.utraptype == TT_PIT) { pline("You are still in a pit."); u.utrap--; } else { pline("You are caught in a beartrap."); - if((u.dx && u.dy) || !rn2(5)) u.utrap--; + if ((u.dx && u.dy) || !rn2(5)) + u.utrap--; } return; } - tmpr = &levl[u.ux+u.dx][u.uy+u.dy]; - if(IS_ROCK(tmpr->typ) || - (u.dx && u.dy && (tmpr->typ == DOOR || ust->typ == DOOR))){ + tmpr = &levl[u.ux + u.dx][u.uy + u.dy]; + if (IS_ROCK(tmpr->typ) || + (u.dx && u.dy && (tmpr->typ == DOOR || ust->typ == DOOR))) { flags.move = 0; nomul(0); return; } - while((otmp = sobj_at(ENORMOUS_ROCK, u.ux+u.dx, u.uy+u.dy))) { - xchar rx = u.ux+2*u.dx, ry = u.uy+2*u.dy; + while ((otmp = sobj_at(ENORMOUS_ROCK, u.ux + u.dx, u.uy + u.dy)) != NULL) { struct trap *ttmp; + xchar rx = u.ux + 2 * u.dx, ry = u.uy + 2 * u.dy; nomul(0); - if(isok(rx,ry) && !IS_ROCK(levl[rx][ry].typ) && + if (isok(rx, ry) && !IS_ROCK(levl[rx][ry].typ) && (levl[rx][ry].typ != DOOR || !(u.dx && u.dy)) && !sobj_at(ENORMOUS_ROCK, rx, ry)) { - if(m_at(rx,ry)) { - pline("You hear a monster behind the rock."); - pline("Perhaps that's why you cannot move it."); - goto cannot_push; + if (m_at(rx, ry)) { + pline("You hear a monster behind the rock."); + pline("Perhaps that's why you cannot move it."); + goto cannot_push; } - if((ttmp = t_at(rx,ry))) - switch(ttmp->ttyp) { - case PIT: - pline("You push the rock into a pit!"); - deltrap(ttmp); - delobj(otmp); - pline("It completely fills the pit!"); - continue; - case TELEP_TRAP: - pline("You push the rock and suddenly it disappears!"); - delobj(otmp); - continue; - } - if(levl[rx][ry].typ == POOL) { + if ((ttmp = t_at(rx, ry)) != NULL) + switch (ttmp->ttyp) { + case PIT: + pline("You push the rock into a pit!"); + deltrap(ttmp); + delobj(otmp); + pline("It completely fills the pit!"); + continue; + case TELEP_TRAP: + pline("You push the rock and suddenly it disappears!"); + delobj(otmp); + continue; + } + if (levl[rx][ry].typ == POOL) { levl[rx][ry].typ = ROOM; - mnewsym(rx,ry); - prl(rx,ry); + mnewsym(rx, ry); + prl(rx, ry); pline("You push the rock into the water."); pline("Now you can cross the water!"); delobj(otmp); @@ -189,51 +199,55 @@ domove(void) } otmp->ox = rx; otmp->oy = ry; - if(cansee(rx,ry)) atl(rx,ry,otmp->olet); - if(Invisible) newsym(u.ux+u.dx, u.uy+u.dy); - - { static long lastmovetime; - /* note: this var contains garbage initially and - after a restore */ - if(moves > lastmovetime+2 || moves < lastmovetime) - pline("With great effort you move the enormous rock."); - lastmovetime = moves; + if (cansee(rx, ry)) + atl(rx, ry, otmp->olet); + if (Invisible) + newsym(u.ux + u.dx, u.uy + u.dy); + + { + static long lastmovetime; + /* note: this var contains garbage initially and + * after a restore */ + if (moves > lastmovetime + 2 || moves < lastmovetime) + pline("With great effort you move the enormous rock."); + lastmovetime = moves; } } else { - pline("You try to move the enormous rock, but in vain."); - cannot_push: - if((!invent || inv_weight()+90 <= 0) && - (!u.dx || !u.dy || (IS_ROCK(levl[u.ux][u.uy+u.dy].typ) - && IS_ROCK(levl[u.ux+u.dx][u.uy].typ)))){ - pline("However, you can squeeze yourself into a small opening."); - break; - } else - return; + pline("You try to move the enormous rock, but in vain."); +cannot_push: + if ((!invent || inv_weight() + 90 <= 0) && + (!u.dx || !u.dy || + (IS_ROCK(levl[u.ux][u.uy + u.dy].typ) + && IS_ROCK(levl[u.ux + u.dx][u.uy].typ)))) { + pline("However, you can squeeze yourself into a small opening."); + break; + } else + return; } - } - if(u.dx && u.dy && IS_ROCK(levl[u.ux][u.uy+u.dy].typ) && - IS_ROCK(levl[u.ux+u.dx][u.uy].typ) && - invent && inv_weight()+40 > 0) { + } + if (u.dx && u.dy && IS_ROCK(levl[u.ux][u.uy + u.dy].typ) && + IS_ROCK(levl[u.ux + u.dx][u.uy].typ) && + invent && inv_weight() + 40 > 0) { pline("You are carrying too much to get through."); nomul(0); return; } - if(Punished && - DIST(u.ux+u.dx, u.uy+u.dy, uchain->ox, uchain->oy) > 2){ - if(carried(uball)) { + if (Punished && + DIST(u.ux + u.dx, u.uy + u.dy, uchain->ox, uchain->oy) > 2) { + if (carried(uball)) { movobj(uchain, u.ux, u.uy); goto nodrag; } - if(DIST(u.ux+u.dx, u.uy+u.dy, uball->ox, uball->oy) < 3){ + if (DIST(u.ux + u.dx, u.uy + u.dy, uball->ox, uball->oy) < 3) { /* leave ball, move chain under/over ball */ movobj(uchain, uball->ox, uball->oy); goto nodrag; } - if(inv_weight() + (int) uball->owt/2 > 0) { + if (inv_weight() + (int)uball->owt / 2 > 0) { pline("You cannot %sdrag the heavy iron ball.", - invent ? "carry all that and also " : ""); + invent ? "carry all that and also " : ""); nomul(0); return; } @@ -244,58 +258,61 @@ domove(void) uchain->oy = u.uy; nomul(-2); nomovemsg = ""; - nodrag: ; +nodrag: ; } u.ux += u.dx; u.uy += u.dy; - if(flags.run) { - if(tmpr->typ == DOOR || - (xupstair == u.ux && yupstair == u.uy) || - (xdnstair == u.ux && ydnstair == u.uy)) + if (flags.run) { + if (tmpr->typ == DOOR || + (xupstair == u.ux && yupstair == u.uy) || + (xdnstair == u.ux && ydnstair == u.uy)) nomul(0); } - if(tmpr->typ == POOL && !Levitation) + if (tmpr->typ == POOL && !Levitation) drown(); /* not necessarily fatal */ - if(!Blind) { + if (!Blind) { #ifdef QUEST setsee(); #else - if(ust->lit) { - if(tmpr->lit) { - if(tmpr->typ == DOOR) - prl1(u.ux+u.dx,u.uy+u.dy); - else if(ust->typ == DOOR) - nose1(oldx-u.dx,oldy-u.dy); + if (ust->lit) { + if (tmpr->lit) { + if (tmpr->typ == DOOR) + prl1(u.ux + u.dx, u.uy + u.dy); + else if (ust->typ == DOOR) + nose1(oldx - u.dx, oldy - u.dy); } else { unsee(); - prl1(u.ux+u.dx,u.uy+u.dy); + prl1(u.ux + u.dx, u.uy + u.dy); } } else { - if(tmpr->lit) setsee(); + if (tmpr->lit) + setsee(); else { - prl1(u.ux+u.dx,u.uy+u.dy); - if(tmpr->typ == DOOR) { - if(u.dy) { - prl(u.ux-1,u.uy); - prl(u.ux+1,u.uy); + prl1(u.ux + u.dx, u.uy + u.dy); + if (tmpr->typ == DOOR) { + if (u.dy) { + prl(u.ux - 1, u.uy); + prl(u.ux + 1, u.uy); } else { - prl(u.ux,u.uy-1); - prl(u.ux,u.uy+1); + prl(u.ux, u.uy - 1); + prl(u.ux, u.uy + 1); } } } - nose1(oldx-u.dx,oldy-u.dy); + nose1(oldx - u.dx, oldy - u.dy); } #endif /* QUEST */ - } else { + } else pru(); - } - if(!flags.nopick) pickup(1); - if(trap) dotrap(trap); /* fall into pit, arrow trap, etc. */ + if (!flags.nopick) + pickup(1); + if (trap) + dotrap(trap); /* fall into pit, arrow trap, etc. */ inshop(); - if(!Blind) read_engr_at(u.ux,u.uy); + if (!Blind) + read_engr_at(u.ux, u.uy); } static void @@ -313,16 +330,16 @@ movobj(struct obj *obj, int ox, int oy) int dopickup(void) { - if(!g_at(u.ux,u.uy) && !o_at(u.ux,u.uy)) { + if (!g_at(u.ux, u.uy) && !o_at(u.ux, u.uy)) { pline("There is nothing here to pick up."); - return(0); + return (0); } - if(Levitation) { + if (Levitation) { pline("You cannot reach the floor."); - return(1); + return (1); } pickup(0); - return(1); + return (1); } void @@ -332,125 +349,138 @@ pickup(int all) struct obj *obj, *obj2; int wt; - if(Levitation) return; - while((gold = g_at(u.ux,u.uy))) { + if (Levitation) + return; + while ((gold = g_at(u.ux, u.uy))) { pline("%ld gold piece%s.", gold->amount, plur(gold->amount)); u.ugold += gold->amount; flags.botl = 1; freegold(gold); - if(flags.run) nomul(0); - if(Invisible) newsym(u.ux,u.uy); + if (flags.run) + nomul(0); + if (Invisible) + newsym(u.ux, u.uy); } /* check for more than one object */ - if(!all) { + if (!all) { int ct = 0; - for(obj = fobj; obj; obj = obj->nobj) - if(obj->ox == u.ux && obj->oy == u.uy) - if(!Punished || obj != uchain) + for (obj = fobj; obj; obj = obj->nobj) + if (obj->ox == u.ux && obj->oy == u.uy) + if (!Punished || obj != uchain) ct++; - if(ct < 2) + if (ct < 2) all++; else pline("There are several objects here."); } - for(obj = fobj; obj; obj = obj2) { - obj2 = obj->nobj; /* perhaps obj will be picked up */ - if(obj->ox == u.ux && obj->oy == u.uy) { - if(flags.run) nomul(0); - - /* do not pick up uchain */ - if(Punished && obj == uchain) - continue; + for (obj = fobj; obj; obj = obj2) { + obj2 = obj->nobj; /* perhaps obj will be picked up */ + if (obj->ox == u.ux && obj->oy == u.uy) { + if (flags.run) + nomul(0); - if(!all) { - char c; + /* do not pick up uchain */ + if (Punished && obj == uchain) + continue; - pline("Pick up %s ? [ynaq]", doname(obj)); - while(!index("ynaq ", (c = readchar()))) - bell(); - if(c == 'q') return; - if(c == 'n') continue; - if(c == 'a') all = 1; - } + if (!all) { + char c; + + pline("Pick up %s ? [ynaq]", doname(obj)); + while (!strchr("ynaq ", (c = readchar()))) + bell(); + if (c == 'q') + return; + if (c == 'n') + continue; + if (c == 'a') + all = 1; + } - if(obj->otyp == DEAD_COCKATRICE && !uarmg){ - pline("Touching the dead cockatrice is a fatal mistake."); - pline("You turn to stone."); - killer = "cockatrice cadaver"; - done("died"); - } + if (obj->otyp == DEAD_COCKATRICE && !uarmg) { + pline("Touching the dead cockatrice is a fatal mistake."); + pline("You turn to stone."); + killer = "cockatrice cadaver"; + done("died"); + } - if(obj->otyp == SCR_SCARE_MONSTER){ - if(!obj->spe) obj->spe = 1; - else { - /* Note: perhaps the 1st pickup failed: you cannot - carry anymore, and so we never dropped it - - let's assume that treading on it twice also - destroys the scroll */ - pline("The scroll turns to dust as you pick it up."); - delobj(obj); - continue; - } - } + if (obj->otyp == SCR_SCARE_MONSTER) { + if (!obj->spe) + obj->spe = 1; + else { + /* Note: perhaps the 1st pickup failed: you cannot + * carry anymore, and so we never dropped it - + * let's assume that treading on it twice also + * destroys the scroll */ + pline("The scroll turns to dust as you pick it up."); + delobj(obj); + continue; + } + } - wt = inv_weight() + obj->owt; - if(wt > 0) { - if(obj->quan > 1) { - /* see how many we can lift */ - int savequan = obj->quan; - int iw = inv_weight(); - int qq; - for(qq = 1; qq < savequan; qq++){ - obj->quan = qq; - if(iw + weight(obj) > 0) - break; + wt = inv_weight() + obj->owt; + if (wt > 0) { + if (obj->quan > 1) { + /* see how many we can lift */ + int savequan = obj->quan; + int iw = inv_weight(); + int qq; + for (qq = 1; qq < savequan; qq++) { + obj->quan = qq; + if (iw + weight(obj) > 0) + break; + } + obj->quan = savequan; + qq--; + /* we can carry qq of them */ + if (!qq) + goto too_heavy; + pline("You can only carry %s of the %s lying here.", + (qq == 1) ? "one" : "some", + doname(obj)); + splitobj(obj, qq); + /* note: obj2 is set already, so we'll never + * encounter the other half; if it should be + * otherwise then write + * obj2 = splitobj(obj, qq); + */ + goto lift_some; } - obj->quan = savequan; - qq--; - /* we can carry qq of them */ - if(!qq) goto too_heavy; - pline("You can only carry %s of the %s lying here.", - (qq == 1) ? "one" : "some", - doname(obj)); - splitobj(obj, qq); - /* note: obj2 is set already, so we'll never - * encounter the other half; if it should be - * otherwise then write - * obj2 = splitobj(obj,qq); - */ - goto lift_some; +too_heavy: + pline("There %s %s here, but %s.", + (obj->quan == 1) ? "is" : "are", + doname(obj), + !invent ? "it is too heavy for you to lift" + : "you cannot carry anymore"); + break; + } +lift_some: + if (inv_cnt() >= 52) { + pline("Your knapsack cannot accommodate anymore items."); + break; + } + if (wt > -5) + pline("You have a little trouble lifting"); + freeobj(obj); + if (Invisible) + newsym(u.ux, u.uy); + addtobill(obj); /* sets obj->unpaid if necessary */ + { + int pickquan = obj->quan; + int mergquan; + if (!Blind) /* this is done by prinv(), */ + obj->dknown = 1;/* but addinv() needs it */ + /* already for merging */ + obj = addinv(obj); /* might merge it with other objects */ + mergquan = obj->quan; + obj->quan = pickquan; /* to fool prinv() */ + prinv(obj); + obj->quan = mergquan; } - too_heavy: - pline("There %s %s here, but %s.", - (obj->quan == 1) ? "is" : "are", - doname(obj), - !invent ? "it is too heavy for you to lift" - : "you cannot carry anymore"); - break; - } - lift_some: - if(inv_cnt() >= 52) { - pline("Your knapsack cannot accommodate anymore items."); - break; - } - if(wt > -5) pline("You have a little trouble lifting"); - freeobj(obj); - if(Invisible) newsym(u.ux,u.uy); - addtobill(obj); /* sets obj->unpaid if necessary */ - { int pickquan = obj->quan; - int mergquan; - if(!Blind) obj->dknown = 1; /* this is done by prinv(), - but addinv() needs it already for merging */ - obj = addinv(obj); /* might merge it with other objects */ - mergquan = obj->quan; - obj->quan = pickquan; /* to fool prinv() */ - prinv(obj); - obj->quan = mergquan; } - } } } @@ -460,92 +490,112 @@ pickup(int all) void lookaround(void) { -int x,y,i,x0,y0,m0,i0 = 9; -int corrct = 0, noturn = 0; -struct monst *mtmp; + int x, y, i, x0, y0, m0, i0 = 9; + int corrct = 0, noturn = 0; + struct monst *mtmp; + /* suppress "used before set" message */ x0 = y0 = m0 = 0; - if(Blind || flags.run == 0) return; - if(flags.run == 1 && levl[u.ux][u.uy].typ == ROOM) return; + if (Blind || flags.run == 0) + return; + if (flags.run == 1 && levl[u.ux][u.uy].typ == ROOM) + return; #ifdef QUEST - if(u.ux0 == u.ux+u.dx && u.uy0 == u.uy+u.dy) goto stop; + if (u.ux0 == u.ux + u.dx && u.uy0 == u.uy + u.dy) + goto stop; #endif /* QUEST */ - for(x = u.ux-1; x <= u.ux+1; x++) for(y = u.uy-1; y <= u.uy+1; y++){ - if(x == u.ux && y == u.uy) continue; - if(!levl[x][y].typ) continue; - if((mtmp = m_at(x,y)) && !mtmp->mimic && - (!mtmp->minvis || See_invisible)){ - if(!mtmp->mtame || (x == u.ux+u.dx && y == u.uy+u.dy)) - goto stop; - } else mtmp = 0; /* invisible M cannot influence us */ - if(x == u.ux-u.dx && y == u.uy-u.dy) continue; - switch(levl[x][y].scrsym){ - case '|': - case '-': - case '.': - case ' ': - break; - case '+': - if(x != u.ux && y != u.uy) break; - if(flags.run != 1) goto stop; + for (x = u.ux - 1; x <= u.ux + 1; x++) + for (y = u.uy - 1; y <= u.uy + 1; y++) { + if (x == u.ux && y == u.uy) + continue; + if (!levl[x][y].typ) + continue; + if ((mtmp = m_at(x, y)) && !mtmp->mimic && + (!mtmp->minvis || See_invisible)) { + if (!mtmp->mtame || + (x == u.ux + u.dx && y == u.uy + u.dy)) + goto stop; + } else /* invisible M cannot influence us */ + mtmp = 0; + if (x == u.ux - u.dx && y == u.uy - u.dy) + continue; + switch (levl[x][y].scrsym) { + case '|': + case '-': + case '.': + case ' ': + break; + case '+': + if (x != u.ux && y != u.uy) + break; + if (flags.run != 1) + goto stop; /* fall into next case */ - case CORR_SYM: - corr: - if(flags.run == 1 || flags.run == 3) { - i = DIST(x,y,u.ux+u.dx,u.uy+u.dy); - if(i > 2) break; - if(corrct == 1 && DIST(x,y,x0,y0) != 1) - noturn = 1; - if(i < i0) { - i0 = i; - x0 = x; - y0 = y; - m0 = mtmp ? 1 : 0; + case CORR_SYM: +corr: + if (flags.run == 1 || flags.run == 3) { + i = DIST(x, y, u.ux + u.dx, u.uy + u.dy); + if (i > 2) + break; + if (corrct == 1 && + DIST(x, y, x0, y0) != 1) + noturn = 1; + if (i < i0) { + i0 = i; + x0 = x; + y0 = y; + m0 = mtmp ? 1 : 0; + } } + corrct++; + break; + case '^': + if (flags.run == 1) /* if you must */ + goto corr; + if (x == u.ux + u.dx && y == u.uy + u.dy) + goto stop; + break; + default: /* e.g. objects or trap or stairs */ + if (flags.run == 1) + goto corr; + if (mtmp) /* d */ + break; +stop: + nomul(0); + return; } - corrct++; - break; - case '^': - if(flags.run == 1) goto corr; /* if you must */ - if(x == u.ux+u.dx && y == u.uy+u.dy) goto stop; - break; - default: /* e.g. objects or trap or stairs */ - if(flags.run == 1) goto corr; - if(mtmp) break; /* d */ - stop: - nomul(0); - return; } - } #ifdef QUEST - if(corrct > 0 && (flags.run == 4 || flags.run == 5)) goto stop; + if (corrct > 0 && (flags.run == 4 || flags.run == 5)) + goto stop; #endif /* QUEST */ - if(corrct > 1 && flags.run == 2) goto stop; - if((flags.run == 1 || flags.run == 3) && !noturn && !m0 && i0 && - (corrct == 1 || (corrct == 2 && i0 == 1))) { + if (corrct > 1 && flags.run == 2) + goto stop; + if ((flags.run == 1 || flags.run == 3) && !noturn && !m0 && i0 && + (corrct == 1 || (corrct == 2 && i0 == 1))) { /* make sure that we do not turn too far */ - if(i0 == 2) { - if(u.dx == y0-u.uy && u.dy == u.ux-x0) - i = 2; /* straight turn right */ - else - i = -2; /* straight turn left */ - } else if(u.dx && u.dy) { - if((u.dx == u.dy && y0 == u.uy) || - (u.dx != u.dy && y0 != u.uy)) - i = -1; /* half turn left */ - else - i = 1; /* half turn right */ + if (i0 == 2) { + if (u.dx == y0 - u.uy && u.dy == u.ux - x0) + i = 2; /* straight turn right */ + else + i = -2; /* straight turn left */ + } else if (u.dx && u.dy) { + if ((u.dx == u.dy && y0 == u.uy) || + (u.dx != u.dy && y0 != u.uy)) + i = -1; /* half turn left */ + else + i = 1; /* half turn right */ } else { - if((x0-u.ux == y0-u.uy && !u.dy) || - (x0-u.ux != y0-u.uy && u.dy)) - i = 1; /* half turn right */ - else - i = -1; /* half turn left */ + if ((x0 - u.ux == y0 - u.uy && !u.dy) || + (x0 - u.ux != y0 - u.uy && u.dy)) + i = 1; /* half turn right */ + else + i = -1; /* half turn left */ } i += u.last_str_turn; - if(i <= 2 && i >= -2) { + if (i <= 2 && i >= -2) { u.last_str_turn = i; - u.dx = x0-u.ux, u.dy = y0-u.uy; + u.dx = x0 - u.ux, u.dy = y0 - u.uy; } } } @@ -555,61 +605,75 @@ struct monst *mtmp; bool monster_nearby(void) { -int x,y; -struct monst *mtmp; - if(!Blind) - for(x = u.ux-1; x <= u.ux+1; x++) for(y = u.uy-1; y <= u.uy+1; y++){ - if(x == u.ux && y == u.uy) continue; - if((mtmp = m_at(x,y)) && !mtmp->mimic && !mtmp->mtame && - !mtmp->mpeaceful && !index("Ea", mtmp->data->mlet) && - !mtmp->mfroz && !mtmp->msleep && /* aplvax!jcn */ - (!mtmp->minvis || See_invisible)) - return(1); - } - return(0); + int x, y; + struct monst *mtmp; + + if (!Blind) + for (x = u.ux - 1; x <= u.ux + 1; x++) + for (y = u.uy - 1; y <= u.uy + 1; y++) { + if (x == u.ux && y == u.uy) + continue; + if ((mtmp = m_at(x, y)) && !mtmp->mimic && + !mtmp->mtame && + !mtmp->mpeaceful && + !strchr("Ea", mtmp->data->mlet) && + !mtmp->mfroz && !mtmp->msleep && /* aplvax!jcn */ + (!mtmp->minvis || See_invisible)) + return (1); + } + return (0); } #ifdef QUEST bool cansee(xchar x, xchar y) { -int dx,dy,adx,ady,sdx,sdy,dmax,d; - if(Blind) return(0); - if(!isok(x,y)) return(0); - d = dist(x,y); - if(d < 3) return(1); - if(d > u.uhorizon*u.uhorizon) return(0); - if(!levl[x][y].lit) - return(0); - dx = x - u.ux; adx = abs(dx); sdx = sgn(dx); - dy = y - u.uy; ady = abs(dy); sdy = sgn(dy); - if(dx == 0 || dy == 0 || adx == ady){ + int dx, dy, adx, ady, sdx, sdy, dmax, d; + + if (Blind) + return (0); + if (!isok(x, y)) + return (0); + d = dist(x, y); + if (d < 3) + return (1); + if (d > u.uhorizon * u.uhorizon) + return (0); + if (!levl[x][y].lit) + return (0); + dx = x - u.ux; + adx = abs(dx); + sdx = sgn(dx); + dy = y - u.uy; + ady = abs(dy); + sdy = sgn(dy); + if (dx == 0 || dy == 0 || adx == ady) { dmax = (dx == 0) ? ady : adx; - for(d = 1; d <= dmax; d++) - if(!rroom(sdx*d,sdy*d)) - return(0); - return(1); - } else if(ady > adx){ - for(d = 1; d <= ady; d++){ - if(!rroom(sdx*( (d*adx)/ady ), sdy*d) || - !rroom(sdx*( (d*adx-1)/ady+1 ), sdy*d)) - return(0); + for (d = 1; d <= dmax; d++) + if (!rroom(sdx * d, sdy * d)) + return (0); + return (1); + } else if (ady > adx) { + for (d = 1; d <= ady; d++) { + if (!rroom(sdx * ((d * adx) / ady), sdy * d) || + !rroom(sdx * ((d * adx - 1) / ady + 1), sdy * d)) + return (0); } - return(1); + return (1); } else { - for(d = 1; d <= adx; d++){ - if(!rroom(sdx*d, sdy*( (d*ady)/adx )) || - !rroom(sdx*d, sdy*( (d*ady-1)/adx+1 ))) - return(0); + for (d = 1; d <= adx; d++) { + if (!rroom(sdx * d, sdy * ((d * ady) / adx)) || + !rroom(sdx * d, sdy * ((d * ady - 1) / adx + 1))) + return (0); } - return(1); + return (1); } } static bool rroom(int x, int y) { - return(IS_ROOM(levl[u.ux+x][u.uy+y].typ)); + return (IS_ROOM(levl[u.ux + x][u.uy + y].typ)); } #else @@ -617,35 +681,38 @@ rroom(int x, int y) bool cansee(xchar x, xchar y) { - if(Blind || u.uswallow) return(0); - if(dist(x,y) < 3) return(1); - if(levl[x][y].lit && seelx <= x && x <= seehx && seely <= y && - y <= seehy) return(1); - return(0); + if (Blind || u.uswallow) + return (0); + if (dist(x, y) < 3) + return (1); + if (levl[x][y].lit && seelx <= x && x <= seehx && seely <= y && + y <= seehy) + return (1); + return (0); } #endif /* QUEST */ int sgn(int a) { - return((a > 0) ? 1 : (a == 0) ? 0 : -1); + return ((a > 0) ? 1 : (a == 0) ? 0 : -1); } #ifdef QUEST void setsee(void) { - x,y; + int x, y; - if(Blind) { + if (Blind) { pru(); return; } - for(y = u.uy-u.uhorizon; y <= u.uy+u.uhorizon; y++) - for(x = u.ux-u.uhorizon; x <= u.ux+u.uhorizon; x++) { - if(cansee(x,y)) - prl(x,y); - } + for (y = u.uy - u.uhorizon; y <= u.uy + u.uhorizon; y++) + for (x = u.ux - u.uhorizon; x <= u.ux + u.uhorizon; x++) { + if (cansee(x, y)) + prl(x, y); + } } #else @@ -653,33 +720,42 @@ setsee(void) void setsee(void) { - int x,y; + int x, y; - if(Blind) { + if (Blind) { pru(); return; } - if(!levl[u.ux][u.uy].lit) { - seelx = u.ux-1; - seehx = u.ux+1; - seely = u.uy-1; - seehy = u.uy+1; + if (!levl[u.ux][u.uy].lit) { + seelx = u.ux - 1; + seehx = u.ux + 1; + seely = u.uy - 1; + seehy = u.uy + 1; } else { - for(seelx = u.ux; levl[seelx-1][u.uy].lit; seelx--); - for(seehx = u.ux; levl[seehx+1][u.uy].lit; seehx++); - for(seely = u.uy; levl[u.ux][seely-1].lit; seely--); - for(seehy = u.uy; levl[u.ux][seehy+1].lit; seehy++); + for (seelx = u.ux; levl[seelx - 1][u.uy].lit; seelx--) ; + for (seehx = u.ux; levl[seehx + 1][u.uy].lit; seehx++) ; + for (seely = u.uy; levl[u.ux][seely - 1].lit; seely--) ; + for (seehy = u.uy; levl[u.ux][seehy + 1].lit; seehy++) ; } - for(y = seely; y <= seehy; y++) - for(x = seelx; x <= seehx; x++) { - prl(x,y); - } - if(!levl[u.ux][u.uy].lit) seehx = 0; /* seems necessary elsewhere */ + for (y = seely; y <= seehy; y++) + for (x = seelx; x <= seehx; x++) + prl(x, y); + + if (!levl[u.ux][u.uy].lit) /* seems necessary elsewhere */ + seehx = 0; else { - if(seely == u.uy) for(x = u.ux-1; x <= u.ux+1; x++) prl(x,seely-1); - if(seehy == u.uy) for(x = u.ux-1; x <= u.ux+1; x++) prl(x,seehy+1); - if(seelx == u.ux) for(y = u.uy-1; y <= u.uy+1; y++) prl(seelx-1,y); - if(seehx == u.ux) for(y = u.uy-1; y <= u.uy+1; y++) prl(seehx+1,y); + if (seely == u.uy) + for (x = u.ux - 1; x <= u.ux + 1; x++) + prl(x, seely - 1); + if (seehy == u.uy) + for (x = u.ux - 1; x <= u.ux + 1; x++) + prl(x, seehy + 1); + if (seelx == u.ux) + for (y = u.uy - 1; y <= u.uy + 1; y++) + prl(seelx - 1, y); + if (seehx == u.ux) + for (y = u.uy - 1; y <= u.uy + 1; y++) + prl(seehx + 1, y); } } #endif /* QUEST */ @@ -687,7 +763,8 @@ setsee(void) void nomul(int nval) { - if(multi < 0) return; + if (multi < 0) + return; multi = nval; flags.mv = flags.run = 0; } @@ -695,33 +772,49 @@ nomul(int nval) int abon(void) { - if(u.ustr == 3) return(-3); - else if(u.ustr < 6) return(-2); - else if(u.ustr < 8) return(-1); - else if(u.ustr < 17) return(0); - else if(u.ustr < 69) return(1); /* up to 18/50 */ - else if(u.ustr < 118) return(2); - else return(3); + if (u.ustr == 3) + return (-3); + else if (u.ustr < 6) + return (-2); + else if (u.ustr < 8) + return (-1); + else if (u.ustr < 17) + return (0); + else if (u.ustr < 69) /* up to 18/50 */ + return (1); + else if (u.ustr < 118) + return (2); + else + return (3); } int dbon(void) { - if(u.ustr < 6) return(-1); - else if(u.ustr < 16) return(0); - else if(u.ustr < 18) return(1); - else if(u.ustr == 18) return(2); /* up to 18 */ - else if(u.ustr < 94) return(3); /* up to 18/75 */ - else if(u.ustr < 109) return(4); /* up to 18/90 */ - else if(u.ustr < 118) return(5); /* up to 18/99 */ - else return(6); + if (u.ustr < 6) + return (-1); + else if (u.ustr < 16) + return (0); + else if (u.ustr < 18) + return (1); + else if (u.ustr == 18) /* up to 18 */ + return (2); + else if (u.ustr < 94) /* up to 18/75 */ + return (3); + else if (u.ustr < 109) /* up to 18/90 */ + return (4); + else if (u.ustr < 118) /* up to 18/99 */ + return (5); + else + return (6); } +/* may kill you; cause may be poison or monster like 'A' */ void -losestr(int num) /* may kill you; cause may be poison or monster like 'A' */ +losestr(int num) { u.ustr -= num; - while(u.ustr < 3) { + while (u.ustr < 3) { u.ustr++; u.uhp -= 6; u.uhpmax -= 6; @@ -733,11 +826,11 @@ void losehp(int n, const char *knam) { u.uhp -= n; - if(u.uhp > u.uhpmax) + if (u.uhp > u.uhpmax) u.uhpmax = u.uhp; /* perhaps n was negative */ flags.botl = 1; - if(u.uhp < 1) { - killer = knam; /* the thing that killed you */ + if (u.uhp < 1) { + killer = knam; /* the thing that killed you */ done("died"); } } @@ -747,16 +840,16 @@ losehp_m(int n, struct monst *mtmp) { u.uhp -= n; flags.botl = 1; - if(u.uhp < 1) + if (u.uhp < 1) done_in_by(mtmp); } void -losexp(void) /* hit by V or W */ +losexp(void) /* hit by V or W */ { int num; - if(u.ulevel > 1) + if (u.ulevel > 1) pline("Goodbye level %u.", u.ulevel--); else u.uhp = -1; @@ -770,38 +863,43 @@ losexp(void) /* hit by V or W */ int inv_weight(void) { -struct obj *otmp = invent; -int wt = (u.ugold + 500)/1000; -int carrcap; - if(Levitation) /* pugh@cornell */ + struct obj *otmp = invent; + int wt = (u.ugold + 500) / 1000; + int carrcap; + + if (Levitation) /* pugh@cornell */ carrcap = MAX_CARR_CAP; else { - carrcap = 5*(((u.ustr > 18) ? 20 : u.ustr) + u.ulevel); - if(carrcap > MAX_CARR_CAP) carrcap = MAX_CARR_CAP; - if(Wounded_legs & LEFT_SIDE) carrcap -= 10; - if(Wounded_legs & RIGHT_SIDE) carrcap -= 10; - } - while(otmp){ + carrcap = 5 * (((u.ustr > 18) ? 20 : u.ustr) + u.ulevel); + if (carrcap > MAX_CARR_CAP) + carrcap = MAX_CARR_CAP; + if (Wounded_legs & LEFT_SIDE) + carrcap -= 10; + if (Wounded_legs & RIGHT_SIDE) + carrcap -= 10; + } + while (otmp) { wt += otmp->owt; otmp = otmp->nobj; } - return(wt - carrcap); + return (wt - carrcap); } static int inv_cnt(void) { -struct obj *otmp = invent; -int ct = 0; - while(otmp){ + struct obj *otmp = invent; + int ct = 0; + + while (otmp) { ct++; otmp = otmp->nobj; } - return(ct); + return (ct); } long newuexp(void) { - return(10*(1L << (u.ulevel-1))); + return (10 * (1L << (u.ulevel - 1))); } diff --git a/games/hack/hack.cmd.c b/games/hack/hack.cmd.c index 69367a7790..d2aaed300f 100644 --- a/games/hack/hack.cmd.c +++ b/games/hack/hack.cmd.c @@ -3,8 +3,8 @@ /* $FreeBSD: src/games/hack/hack.cmd.c,v 1.4 1999/11/16 10:26:35 marcel Exp $ */ /* $DragonFly: src/games/hack/hack.cmd.c,v 1.4 2006/08/21 19:45:32 pavalos Exp $ */ -#include "hack.h" -#include "def.func_tab.h" +#include "hack.h" +#include "def.func_tab.h" static int doextcmd(void); static char lowc(char); @@ -22,21 +22,21 @@ struct func_tab cmdlist[]={ { '\032', dosuspend }, #endif /* SUSPEND */ { 'a', doapply }, -/* 'A' : UNUSED */ -/* 'b', 'B' : go sw */ + /*'A' : UNUSED */ + /*'b', 'B' : go sw */ { 'c', ddocall }, { 'C', do_mname }, { 'd', dodrop }, { 'D', doddrop }, { 'e', doeat }, { 'E', doengrave }, -/* 'f', 'F' : multiple go (might become 'fight') */ -/* 'g', 'G' : UNUSED */ -/* 'h', 'H' : go west */ + /*'f', 'F' : multiple go (might become 'fight') */ + /*'g', 'G' : UNUSED */ + /*'h', 'H' : go west */ { 'I', dotypeinv }, /* Robert Viduya */ { 'i', ddoinv }, -/* 'j', 'J', 'k', 'K', 'l', 'L', 'm', 'M', 'n', 'N' : move commands */ -/* 'o', doopen, */ + /*'j', 'J', 'k', 'K', 'l', 'L', 'm', 'M', 'n', 'N' : move commands */ + /*'o', doopen, */ { 'O', doset }, { 'p', dopay }, { 'P', dowearring }, @@ -48,15 +48,15 @@ struct func_tab cmdlist[]={ { 'S', dosave }, { 't', dothrow }, { 'T', doremarm }, -/* 'u', 'U' : go ne */ + /*'u', 'U' : go ne */ { 'v', doversion }, -/* 'V' : UNUSED */ + /*'V' : UNUSED */ { 'w', dowield }, { 'W', doweararm }, -/* 'x', 'X' : UNUSED */ -/* 'y', 'Y' : go nw */ + /*'x', 'X' : UNUSED */ + /*'y', 'Y' : go nw */ { 'z', dozap }, -/* 'Z' : UNUSED */ + /*'Z' : UNUSED */ { '<', doup }, { '>', dodown }, { '/', dowhatis }, @@ -69,10 +69,10 @@ struct func_tab cmdlist[]={ { ',', dopickup }, { ':', dolook }, { '^', doidtrap }, - { '\\', dodiscovered }, /* Robert Viduya */ - { WEAPON_SYM, doprwep }, - { ARMOR_SYM, doprarm }, - { RING_SYM, doprring }, + { '\\', dodiscovered }, /* Robert Viduya */ + { WEAPON_SYM, doprwep }, + { ARMOR_SYM, doprarm }, + { RING_SYM, doprring }, { '$', doprgold }, { '#', doextcmd }, { 0, 0 } @@ -93,34 +93,37 @@ rhack(const char *cmd) boolean firsttime = FALSE; int res; - if(!cmd) { + if (!cmd) { firsttime = TRUE; flags.nopick = 0; cmd = parse(); } - if(!*cmd || (*cmd & 0377) == 0377 || - (flags.no_rest_on_space && *cmd == ' ')){ + if (!*cmd || (*cmd & 0377) == 0377 || + (flags.no_rest_on_space && *cmd == ' ')) { bell(); flags.move = 0; return; /* probably we just had an interrupt */ } - if(movecmd(*cmd)) { - walk: - if(multi) flags.mv = 1; + if (movecmd(*cmd)) { +walk: + if (multi) + flags.mv = 1; domove(); return; } - if(movecmd(lowc(*cmd))) { + if (movecmd(lowc(*cmd))) { flags.run = 1; - rush: - if(firsttime){ - if(!multi) multi = COLNO; +rush: + if (firsttime) { + if (!multi) + multi = COLNO; u.last_str_turn = 0; } flags.mv = 1; #ifdef QUEST - if(flags.run >= 4) finddir(); - if(firsttime){ + if (flags.run >= 4) + finddir(); + if (firsttime) { u.ux0 = u.ux + u.dx; u.uy0 = u.uy + u.dy; } @@ -128,36 +131,38 @@ rhack(const char *cmd) domove(); return; } - if((*cmd == 'f' && movecmd(cmd[1])) || movecmd(unctrl(*cmd))) { + if ((*cmd == 'f' && movecmd(cmd[1])) || movecmd(unctrl(*cmd))) { flags.run = 2; goto rush; } - if(*cmd == 'F' && movecmd(lowc(cmd[1]))) { + if (*cmd == 'F' && movecmd(lowc(cmd[1]))) { flags.run = 3; goto rush; } - if(*cmd == 'm' && movecmd(cmd[1])) { + if (*cmd == 'm' && movecmd(cmd[1])) { flags.run = 0; flags.nopick = 1; goto walk; } - if(*cmd == 'M' && movecmd(lowc(cmd[1]))) { + if (*cmd == 'M' && movecmd(lowc(cmd[1]))) { flags.run = 1; flags.nopick = 1; goto rush; } #ifdef QUEST - if(*cmd == cmd[1] && (*cmd == 'f' || *cmd == 'F')) { + if (*cmd == cmd[1] && (*cmd == 'f' || *cmd == 'F')) { flags.run = 4; - if(*cmd == 'F') flags.run += 2; - if(cmd[2] == '-') flags.run += 1; + if (*cmd == 'F') + flags.run += 2; + if (cmd[2] == '-') + flags.run += 1; goto rush; } #endif /* QUEST */ - while(tlist->f_char) { - if(*cmd == tlist->f_char){ + while (tlist->f_char) { + if (*cmd == tlist->f_char) { res = (*(tlist->f_funct))(); - if(!res) { + if (!res) { flags.move = 0; multi = 0; } @@ -165,24 +170,25 @@ rhack(const char *cmd) } tlist++; } - { char expcmd[10]; - char *cp = expcmd; - while(*cmd && cp-expcmd < (int)sizeof(expcmd)-2) { - if(*cmd >= 040 && *cmd < 0177) - *cp++ = *cmd++; - else { - *cp++ = '^'; - *cp++ = *cmd++ ^ 0100; + { + char expcmd[10]; + char *cp = expcmd; + while (*cmd && cp - expcmd < (int)sizeof(expcmd) - 2) { + if (*cmd >= 040 && *cmd < 0177) + *cp++ = *cmd++; + else { + *cp++ = '^'; + *cp++ = *cmd++ ^ 0100; + } } - } - *cp++ = 0; - pline("Unknown command '%s'.", expcmd); + *cp++ = 0; + pline("Unknown command '%s'.", expcmd); } multi = flags.move = 0; } static int -doextcmd(void) /* here after # - now read a full-word command */ +doextcmd(void) /* here after # - now read a full-word command */ { char buf[BUFSZ]; struct ext_func_tab *efp = extcmdlist; @@ -190,46 +196,47 @@ doextcmd(void) /* here after # - now read a full-word command */ pline("# "); getlin(buf); clrlin(); - if(buf[0] == '\033') - return(0); - while(efp->ef_txt) { - if(!strcmp(efp->ef_txt, buf)) - return((*(efp->ef_funct))()); + if (buf[0] == '\033') + return (0); + while (efp->ef_txt) { + if (!strcmp(efp->ef_txt, buf)) + return ((*(efp->ef_funct))()); efp++; } pline("%s: unknown command.", buf); - return(0); + return (0); } static char lowc(char sym) { - return( (sym >= 'A' && sym <= 'Z') ? sym+'a'-'A' : sym ); + return ((sym >= 'A' && sym <= 'Z') ? sym + 'a' - 'A' : sym); } static char unctrl(char sym) { - return( (sym >= ('A' & 037) && sym <= ('Z' & 037)) ? sym + 0140 : sym ); + return ((sym >= ('A' & 037) && sym <= ('Z' & 037)) ? sym + 0140 : sym); } /* 'rogue'-like direction commands */ char sdir[] = "hykulnjb><"; -schar xdir[10] = { -1,-1, 0, 1, 1, 1, 0,-1, 0, 0 }; -schar ydir[10] = { 0,-1,-1,-1, 0, 1, 1, 1, 0, 0 }; -schar zdir[10] = { 0, 0, 0, 0, 0, 0, 0, 0, 1,-1 }; +schar xdir[10] = { -1, -1, 0, 1, 1, 1, 0, -1, 0, 0 }; +schar ydir[10] = { 0, -1, -1, -1, 0, 1, 1, 1, 0, 0 }; +schar zdir[10] = { 0, 0, 0, 0, 0, 0, 0, 0, 1, -1 }; bool -movecmd(char sym) /* also sets u.dz, but returns false for <> */ +movecmd(char sym) /* also sets u.dz, but returns false for <> */ { char *dp; u.dz = 0; - if(!(dp = index(sdir, sym))) return(0); - u.dx = xdir[dp-sdir]; - u.dy = ydir[dp-sdir]; - u.dz = zdir[dp-sdir]; - return(!u.dz); + if (!(dp = strchr(sdir, sym))) + return (0); + u.dx = xdir[dp - sdir]; + u.dy = ydir[dp - sdir]; + u.dz = zdir[dp - sdir]; + return (!u.dz); } bool @@ -237,22 +244,24 @@ getdir(bool s) { char dirsym; - if(s) pline("In what direction?"); + if (s) + pline("In what direction?"); dirsym = readchar(); - if(!movecmd(dirsym) && !u.dz) { - if(!index(quitchars, dirsym)) + if (!movecmd(dirsym) && !u.dz) { + if (!strchr(quitchars, dirsym)) pline("What a strange direction!"); - return(0); + return (0); } - if(Confusion && !u.dz) + if (Confusion && !u.dz) confdir(); - return(1); + return (1); } void confdir(void) { int x = rn2(8); + u.dx = xdir[x]; u.dy = ydir[x]; } @@ -261,27 +270,34 @@ confdir(void) void finddir(void) { -int i, ui = u.di; - for(i = 0; i <= 8; i++){ - if(flags.run & 1) ui++; else ui += 7; + int i, ui = u.di; + + for (i = 0; i <= 8; i++) { + if (flags.run & 1) + ui++; + else + ui += 7; ui %= 8; - if(i == 8){ + if (i == 8) { pline("Not near a wall."); flags.move = multi = 0; return; } - if(!isroom(u.ux+xdir[ui], u.uy+ydir[ui])) + if (!isroom(u.ux + xdir[ui], u.uy + ydir[ui])) break; } - for(i = 0; i <= 8; i++){ - if(flags.run & 1) ui += 7; else ui++; + for (i = 0; i <= 8; i++) { + if (flags.run & 1) + ui += 7; + else + ui++; ui %= 8; - if(i == 8){ + if (i == 8) { pline("Not near a room."); flags.move = multi = 0; return; } - if(isroom(u.ux+xdir[ui], u.uy+ydir[ui])) + if (isroom(u.ux + xdir[ui], u.uy + ydir[ui])) break; } u.di = ui; @@ -291,9 +307,9 @@ int i, ui = u.di; static bool isroom(int x, int y) -{ /* what about POOL? */ - return(isok(x,y) && (levl[x][y].typ == ROOM || - (levl[x][y].typ >= LDOOR && flags.run >= 6))); +{ /* what about POOL? */ + return (isok(x, y) && (levl[x][y].typ == ROOM || + (levl[x][y].typ >= LDOOR && flags.run >= 6))); } #endif /* QUEST */ @@ -301,7 +317,7 @@ bool isok(int x, int y) { /* x corresponds to curx, so x==1 is the first column. Ach. %% */ - return(x >= 1 && x <= COLNO-1 && y >= 0 && y <= ROWNO-1); + return (x >= 1 && x <= COLNO - 1 && y >= 0 && y <= ROWNO - 1); } /* @@ -312,5 +328,5 @@ static int done2(void) { done1(0); - return(0); + return (0); } diff --git a/games/hack/hack.do.c b/games/hack/hack.do.c index a9a413fbc5..8d6277dbe1 100644 --- a/games/hack/hack.do.c +++ b/games/hack/hack.do.c @@ -9,47 +9,49 @@ extern struct monst youmonst; -static int drop(struct obj *); -static void dropy(struct obj *); +static int drop(struct obj *); +static void dropy(struct obj *); int dodrop(void) { - return(drop(getobj("0$#", "drop"))); + return (drop(getobj("0$#", "drop"))); } static int drop(struct obj *obj) { - if(!obj) return(0); - if(obj->olet == '$') { /* pseudo object */ + if (!obj) + return (0); + if (obj->olet == '$') { /* pseudo object */ long amount = OGOLD(obj); - if(amount == 0) + if (amount == 0) pline("You didn't drop any gold pieces."); else { mkgold(amount, u.ux, u.uy); pline("You dropped %ld gold piece%s.", - amount, plur(amount)); - if(Invisible) newsym(u.ux, u.uy); + amount, plur(amount)); + if (Invisible) + newsym(u.ux, u.uy); } - free((char *) obj); - return(1); + free(obj); + return (1); } - if(obj->owornmask & (W_ARMOR | W_RING)){ + if (obj->owornmask & (W_ARMOR | W_RING)) { pline("You cannot drop something you are wearing."); - return(0); + return (0); } - if(obj == uwep) { - if(uwep->cursed) { + if (obj == uwep) { + if (uwep->cursed) { pline("Your weapon is welded to your hand!"); - return(0); + return (0); } setuwep(NULL); } pline("You dropped %s.", doname(obj)); dropx(obj); - return(1); + return (1); } /* Called in several places - should not produce texts */ @@ -63,13 +65,14 @@ dropx(struct obj *obj) static void dropy(struct obj *obj) { - if(obj->otyp == CRYSKNIFE) + if (obj->otyp == CRYSKNIFE) obj->otyp = WORM_TOOTH; obj->ox = u.ux; obj->oy = u.uy; obj->nobj = fobj; fobj = obj; - if(Invisible) newsym(u.ux,u.uy); + if (Invisible) + newsym(u.ux, u.uy); subfrombill(obj); stackobj(obj); } @@ -78,47 +81,47 @@ dropy(struct obj *obj) int doddrop(void) { - return(ggetobj("drop", drop, 0)); + return (ggetobj("drop", drop, 0)); } int dodown(void) { - if(u.ux != xdnstair || u.uy != ydnstair) { + if (u.ux != xdnstair || u.uy != ydnstair) { pline("You can't go down here."); - return(0); + return (0); } - if(u.ustuck) { + if (u.ustuck) { pline("You are being held, and cannot go down."); - return(1); + return (1); } - if(Levitation) { + if (Levitation) { pline("You're floating high above the stairs."); - return(0); + return (0); } - goto_level(dlevel+1, TRUE); - return(1); + goto_level(dlevel + 1, TRUE); + return (1); } int doup(void) { - if(u.ux != xupstair || u.uy != yupstair) { + if (u.ux != xupstair || u.uy != yupstair) { pline("You can't go up here."); - return(0); + return (0); } - if(u.ustuck) { + if (u.ustuck) { pline("You are being held, and cannot go up."); - return(1); + return (1); } - if(!Levitation && inv_weight() + 5 > 0) { + if (!Levitation && inv_weight() + 5 > 0) { pline("Your load is too heavy to climb the stairs."); - return(1); + return (1); } - goto_level(dlevel-1, TRUE); - return(1); + goto_level(dlevel - 1, TRUE); + return (1); } void @@ -127,13 +130,16 @@ goto_level(int newlevel, boolean at_stairs) int fd; boolean up = (newlevel < dlevel); - if(newlevel <= 0) done("escaped"); /* in fact < 0 is impossible */ - if(newlevel > MAXLEVEL) newlevel = MAXLEVEL; /* strange ... */ - if(newlevel == dlevel) return; /* this can happen */ + if (newlevel <= 0) /* in fact < 0 is impossible */ + done("escaped"); + if (newlevel > MAXLEVEL) /* strange ... */ + newlevel = MAXLEVEL; + if (newlevel == dlevel) /* this can happen */ + return; glo(dlevel); fd = creat(lock, FMASK); - if(fd < 0) { + if (fd < 0) { /* * This is not quite impossible: e.g., we may have * exceeded our quota. If that is the case then we @@ -142,33 +148,34 @@ goto_level(int newlevel, boolean at_stairs) * writable. */ pline("A mysterious force prevents you from going %s.", - up ? "up" : "down"); + up ? "up" : "down"); return; } - if(Punished) unplacebc(); - u.utrap = 0; /* needed in level_tele */ - u.ustuck = 0; /* idem */ + if (Punished) + unplacebc(); + u.utrap = 0; /* needed in level_tele */ + u.ustuck = 0; /* idem */ keepdogs(); seeoff(1); - if(u.uswallow) /* idem */ + if (u.uswallow) /* idem */ u.uswldtim = u.uswallow = 0; flags.nscrinh = 1; - u.ux = FAR; /* hack */ - inshop(); /* probably was a trapdoor */ + u.ux = FAR; /* hack */ + inshop(); /* probably was a trapdoor */ - savelev(fd,dlevel); + savelev(fd, dlevel); close(fd); dlevel = newlevel; - if(maxdlevel < dlevel) + if (maxdlevel < dlevel) maxdlevel = dlevel; glo(dlevel); - if(!level_exists[dlevel]) + if (!level_exists[dlevel]) mklev(); else { - if((fd = open(lock,0)) < 0) { + if ((fd = open(lock, O_RDONLY)) < 0) { pline("Cannot open %s .", lock); pline("Probably someone removed it."); done("tricked"); @@ -177,72 +184,75 @@ goto_level(int newlevel, boolean at_stairs) close(fd); } - if(at_stairs) { - if(up) { - u.ux = xdnstair; - u.uy = ydnstair; - if(!u.ux) { /* entering a maze from below? */ - u.ux = xupstair; /* this will confuse the player! */ - u.uy = yupstair; + if (at_stairs) { + if (up) { + u.ux = xdnstair; + u.uy = ydnstair; + if (!u.ux) { /* entering a maze from below? */ + u.ux = xupstair; /* this will confuse the player! */ + u.uy = yupstair; + } + if (Punished && !Levitation) { + pline("With great effort you climb the stairs."); + placebc(1); + } + } else { + u.ux = xupstair; + u.uy = yupstair; + if (inv_weight() + 5 > 0 || Punished) { + pline("You fall down the stairs."); /* %% */ + losehp(rnd(3), "fall"); + if (Punished) { + if (uwep != uball && rn2(3)) { + pline("... and are hit by the iron ball."); + losehp(rnd(20), "iron ball"); + } + placebc(1); + } + selftouch("Falling, you"); + } } - if(Punished && !Levitation){ - pline("With great effort you climb the stairs."); - placebc(1); + { + struct monst *mtmp = m_at(u.ux, u.uy); + if (mtmp) + mnexto(mtmp); } - } else { - u.ux = xupstair; - u.uy = yupstair; - if(inv_weight() + 5 > 0 || Punished){ - pline("You fall down the stairs."); /* %% */ - losehp(rnd(3), "fall"); - if(Punished) { - if(uwep != uball && rn2(3)){ - pline("... and are hit by the iron ball."); - losehp(rnd(20), "iron ball"); - } - placebc(1); + } else { /* trapdoor or level_tele */ + do { + u.ux = rnd(COLNO - 1); + u.uy = rn2(ROWNO); + } while (levl[u.ux][u.uy].typ != ROOM || + m_at(u.ux, u.uy)); + if (Punished) { + if (uwep != uball && !up /* %% */ && rn2(5)) { + pline("The iron ball falls on your head."); + losehp(rnd(25), "iron ball"); } - selftouch("Falling, you"); - } - } - { struct monst *mtmp = m_at(u.ux, u.uy); - if(mtmp) - mnexto(mtmp); - } - } else { /* trapdoor or level_tele */ - do { - u.ux = rnd(COLNO-1); - u.uy = rn2(ROWNO); - } while(levl[u.ux][u.uy].typ != ROOM || - m_at(u.ux,u.uy)); - if(Punished){ - if(uwep != uball && !up /* %% */ && rn2(5)){ - pline("The iron ball falls on your head."); - losehp(rnd(25), "iron ball"); + placebc(1); } - placebc(1); - } - selftouch("Falling, you"); + selftouch("Falling, you"); } inshop(); initrack(); losedogs(); - { struct monst *mtmp; - if((mtmp = m_at(u.ux, u.uy))) mnexto(mtmp); /* riv05!a3 */ + { + struct monst *mtmp; + if ((mtmp = m_at(u.ux, u.uy))) /* riv05!a3 */ + mnexto(mtmp); } flags.nscrinh = 0; setsee(); - seeobjs(); /* make old cadavers disappear - riv05!a3 */ + seeobjs(); /* make old cadavers disappear - riv05!a3 */ docrt(); pickup(1); - read_engr_at(u.ux,u.uy); + read_engr_at(u.ux, u.uy); } int donull(void) { - return(1); /* Do nothing, but let other things happen */ + return (1); /* Do nothing, but let other things happen */ } int @@ -250,7 +260,7 @@ dopray(void) { nomovemsg = "You finished your prayer."; nomul(-3); - return(1); + return (1); } int @@ -260,150 +270,156 @@ dothrow(void) struct monst *mon; int tmp; - obj = getobj("#)", "throw"); /* it is also possible to throw food */ - /* (or jewels, or iron balls ... ) */ - if(!obj || !getdir(1)) /* ask "in what direction?" */ - return(0); - if(obj->owornmask & (W_ARMOR | W_RING)){ + obj = getobj("#)", "throw"); /* it is also possible to throw food */ + /* (or jewels, or iron balls ... ) */ + if (!obj || !getdir(1)) /* ask "in what direction?" */ + return (0); + if (obj->owornmask & (W_ARMOR | W_RING)) { pline("You can't throw something you are wearing."); - return(0); + return (0); } u_wipe_engr(2); - if(obj == uwep){ - if(obj->cursed){ + if (obj == uwep) { + if (obj->cursed) { pline("Your weapon is welded to your hand."); - return(1); + return (1); } - if(obj->quan > 1) + if (obj->quan > 1) setuwep(splitobj(obj, 1)); else setuwep(NULL); - } - else if(obj->quan > 1) + } else if (obj->quan > 1) splitobj(obj, 1); freeinv(obj); - if(u.uswallow) { + if (u.uswallow) { mon = u.ustuck; bhitpos.x = mon->mx; bhitpos.y = mon->my; - } else if(u.dz) { - if(u.dz < 0) { - pline("%s hits the ceiling, then falls back on top of your head.", - Doname(obj)); /* note: obj->quan == 1 */ - if(obj->olet == POTION_SYM) - potionhit(&youmonst, obj); - else { - if(uarmh) pline("Fortunately, you are wearing a helmet!"); - losehp(uarmh ? 1 : rnd((int)(obj->owt)), "falling object"); - dropy(obj); - } - } else { - pline("%s hits the floor.", Doname(obj)); - if(obj->otyp == EXPENSIVE_CAMERA) { - pline("It is shattered in a thousand pieces!"); - obfree(obj, NULL); - } else if(obj->otyp == EGG) { - pline("\"Splash!\""); - obfree(obj, NULL); - } else if(obj->olet == POTION_SYM) { - pline("The flask breaks, and you smell a peculiar odor ..."); - potionbreathe(obj); - obfree(obj, NULL); - } else { - dropy(obj); - } - } - return(1); - } else if(obj->otyp == BOOMERANG) { + } else if (u.dz) { + if (u.dz < 0) { + pline("%s hits the ceiling, then falls back on top of your head.", + Doname(obj)); /* note: obj->quan == 1 */ + if (obj->olet == POTION_SYM) + potionhit(&youmonst, obj); + else { + if (uarmh) + pline("Fortunately, you are wearing a helmet!"); + losehp(uarmh ? 1 : rnd((int)(obj->owt)), + "falling object"); + dropy(obj); + } + } else { + pline("%s hits the floor.", Doname(obj)); + if (obj->otyp == EXPENSIVE_CAMERA) { + pline("It is shattered in a thousand pieces!"); + obfree(obj, NULL); + } else if (obj->otyp == EGG) { + pline("\"Splash!\""); + obfree(obj, NULL); + } else if (obj->olet == POTION_SYM) { + pline("The flask breaks, and you smell a peculiar odor ..."); + potionbreathe(obj); + obfree(obj, NULL); + } else + dropy(obj); + } + return (1); + } else if (obj->otyp == BOOMERANG) { mon = boomhit(u.dx, u.dy); - if(mon == &youmonst) { /* the thing was caught */ + if (mon == &youmonst) { /* the thing was caught */ addinv(obj); - return(1); + return (1); } } else { - if(obj->otyp == PICK_AXE && shkcatch(obj)) - return(1); + if (obj->otyp == PICK_AXE && shkcatch(obj)) + return (1); mon = bhit(u.dx, u.dy, (obj->otyp == ICE_BOX) ? 1 : - (!Punished || obj != uball) ? 8 : !u.ustuck ? 5 : 1, - obj->olet, (void (*)(struct monst *, struct obj *)) 0, - (bool (*)(struct obj *, struct obj *)) 0, obj); + (!Punished || obj != uball) ? 8 : !u.ustuck ? 5 : 1, + obj->olet, (void (*)(struct monst *, struct obj *)) 0, + (bool (*)(struct obj *, struct obj *)) 0, obj); } - if(mon) { + if (mon) { /* awake monster if sleeping */ wakeup(mon); - if(obj->olet == WEAPON_SYM) { - tmp = -1+u.ulevel+mon->data->ac+abon(); - if(obj->otyp < ROCK) { - if(!uwep || - uwep->otyp != obj->otyp+(BOW-ARROW)) + if (obj->olet == WEAPON_SYM) { + tmp = -1 + u.ulevel + mon->data->ac + abon(); + if (obj->otyp < ROCK) { + if (!uwep || + uwep->otyp != obj->otyp + (BOW - ARROW)) tmp -= 4; else { tmp += uwep->spe; } - } else - if(obj->otyp == BOOMERANG) tmp += 4; + } else if (obj->otyp == BOOMERANG) + tmp += 4; tmp += obj->spe; - if(u.uswallow || tmp >= rnd(20)) { - if(hmon(mon,obj,1) == TRUE){ - /* mon still alive */ + if (u.uswallow || tmp >= rnd(20)) { + if (hmon(mon, obj, 1) == TRUE) { + /* mon still alive */ #ifndef NOWORM - cutworm(mon,bhitpos.x,bhitpos.y,obj->otyp); + cutworm(mon, bhitpos.x, bhitpos.y, obj->otyp); #endif /* NOWORM */ - } else mon = 0; + } else + mon = 0; /* weapons thrown disappear sometimes */ - if(obj->otyp < BOOMERANG && rn2(3)) { + if (obj->otyp < BOOMERANG && rn2(3)) { /* check bill; free */ obfree(obj, NULL); - return(1); + return (1); } - } else miss(objects[obj->otyp].oc_name, mon); - } else if(obj->otyp == HEAVY_IRON_BALL) { - tmp = -1+u.ulevel+mon->data->ac+abon(); - if(!Punished || obj != uball) tmp += 2; - if(u.utrap) tmp -= 2; - if(u.uswallow || tmp >= rnd(20)) { - if(hmon(mon,obj,1) == FALSE) + } else + miss(objects[obj->otyp].oc_name, mon); + } else if (obj->otyp == HEAVY_IRON_BALL) { + tmp = -1 + u.ulevel + mon->data->ac + abon(); + if (!Punished || obj != uball) + tmp += 2; + if (u.utrap) + tmp -= 2; + if (u.uswallow || tmp >= rnd(20)) { + if (hmon(mon, obj, 1) == FALSE) mon = 0; /* he died */ - } else miss("iron ball", mon); - } else if(obj->olet == POTION_SYM && u.ulevel > rn2(15)) { + } else + miss("iron ball", mon); + } else if (obj->olet == POTION_SYM && u.ulevel > rn2(15)) { potionhit(mon, obj); - return(1); + return (1); } else { - if(cansee(bhitpos.x,bhitpos.y)) - pline("You miss %s.",monnam(mon)); - else pline("You miss it."); - if(obj->olet == FOOD_SYM && mon->data->mlet == 'd') - if(tamedog(mon,obj)) return(1); - if(obj->olet == GEM_SYM && mon->data->mlet == 'u' && - !mon->mtame){ - if(obj->dknown && objects[obj->otyp].oc_name_known){ - if(objects[obj->otyp].g_val > 0){ - u.uluck += 5; - goto valuable; - } else { - pline("%s is not interested in your junk.", - Monnam(mon)); - } - } else { /* value unknown to @ */ - u.uluck++; - valuable: - if(u.uluck > LUCKMAX) /* dan@ut-ngp */ - u.uluck = LUCKMAX; - pline("%s graciously accepts your gift.", - Monnam(mon)); - mpickobj(mon, obj); - rloc(mon); - return(1); - } + if (cansee(bhitpos.x, bhitpos.y)) + pline("You miss %s.", monnam(mon)); + else + pline("You miss it."); + if (obj->olet == FOOD_SYM && mon->data->mlet == 'd') + if (tamedog(mon, obj)) + return (1); + if (obj->olet == GEM_SYM && mon->data->mlet == 'u' && + !mon->mtame) { + if (obj->dknown && objects[obj->otyp].oc_name_known) { + if (objects[obj->otyp].g_val > 0) { + u.uluck += 5; + goto valuable; + } else + pline("%s is not interested in your junk.", + Monnam(mon)); + } else { /* value unknown to @ */ + u.uluck++; +valuable: + if (u.uluck > LUCKMAX) /* dan@ut-ngp */ + u.uluck = LUCKMAX; + pline("%s graciously accepts your gift.", + Monnam(mon)); + mpickobj(mon, obj); + rloc(mon); + return (1); + } } } } - /* the code following might become part of dropy() */ - if(obj->otyp == CRYSKNIFE) + /* the code following might become part of dropy() */ + if (obj->otyp == CRYSKNIFE) obj->otyp = WORM_TOOTH; obj->ox = bhitpos.x; obj->oy = bhitpos.y; @@ -412,21 +428,20 @@ dothrow(void) /* prevent him from throwing articles to the exit and escaping */ /* subfrombill(obj); */ stackobj(obj); - if(Punished && obj == uball && - (bhitpos.x != u.ux || bhitpos.y != u.uy)){ + if (Punished && obj == uball && + (bhitpos.x != u.ux || bhitpos.y != u.uy)) { freeobj(uchain); unpobj(uchain); - if(u.utrap){ - if(u.utraptype == TT_PIT) + if (u.utrap) { + if (u.utraptype == TT_PIT) pline("The ball pulls you out of the pit!"); else { - long side = - rn2(3) ? LEFT_SIDE : RIGHT_SIDE; - pline("The ball pulls you out of the bear trap."); - pline("Your %s leg is severely damaged.", - (side == LEFT_SIDE) ? "left" : "right"); - set_wounded_legs(side, 500+rn2(1000)); - losehp(2, "thrown ball"); + long side = rn2(3) ? LEFT_SIDE : RIGHT_SIDE; + pline("The ball pulls you out of the bear trap."); + pline("Your %s leg is severely damaged.", + (side == LEFT_SIDE) ? "left" : "right"); + set_wounded_legs(side, 500 + rn2(1000)); + losehp(2, "thrown ball"); } u.utrap = 0; } @@ -438,8 +453,9 @@ dothrow(void) setsee(); inshop(); } - if(cansee(bhitpos.x, bhitpos.y)) prl(bhitpos.x,bhitpos.y); - return(1); + if (cansee(bhitpos.x, bhitpos.y)) + prl(bhitpos.x, bhitpos.y); + return (1); } /* split obj so that it gets size num */ @@ -447,7 +463,8 @@ dothrow(void) struct obj * splitobj(struct obj *obj, int num) { -struct obj *otmp; + struct obj *otmp; + otmp = newobj(0); *otmp = *obj; /* copies whole structure */ otmp->o_id = flags.ident++; @@ -457,24 +474,26 @@ struct obj *otmp; otmp->quan -= num; otmp->owt = weight(otmp); /* -= obj->owt ? */ obj->nobj = otmp; - if(obj->unpaid) splitbill(obj,otmp); - return(otmp); + if (obj->unpaid) + splitbill(obj, otmp); + return (otmp); } void more_experienced(int exp, int rexp) { u.uexp += exp; - u.urexp += 4*exp + rexp; - if(exp) flags.botl = 1; - if(u.urexp >= ((pl_character[0] == 'W') ? 1000 : 2000)) + u.urexp += 4 * exp + rexp; + if (exp) + flags.botl = 1; + if (u.urexp >= ((pl_character[0] == 'W') ? 1000 : 2000)) flags.beginner = 0; } void set_wounded_legs(long side, int timex) { - if(!Wounded_legs || (Wounded_legs & TIMEOUT)) + if (!Wounded_legs || (Wounded_legs & TIMEOUT)) Wounded_legs |= side + timex; else Wounded_legs |= side; @@ -483,8 +502,8 @@ set_wounded_legs(long side, int timex) void heal_legs(void) { - if(Wounded_legs) { - if((Wounded_legs & BOTH_SIDES) == BOTH_SIDES) + if (Wounded_legs) { + if ((Wounded_legs & BOTH_SIDES) == BOTH_SIDES) pline("Your legs feel somewhat better."); else pline("Your leg feels somewhat better."); diff --git a/games/hack/hack.do_name.c b/games/hack/hack.do_name.c index ff166314e1..38ef8374e6 100644 --- a/games/hack/hack.do_name.c +++ b/games/hack/hack.do_name.c @@ -5,94 +5,99 @@ #include "hack.h" -static void do_oname(struct obj *); -static char *xmonnam(struct monst *, int); -static char *lmonnam(struct monst *); -static char *visctrl(char); +static void do_oname(struct obj *); +static char *xmonnam(struct monst *, int); +static char *lmonnam(struct monst *); +static char *visctrl(char); coord getpos(int force, const char *goal) { -int cx,cy,i,c; -coord cc; + int cx, cy, i, c; + coord cc; + pline("(For instructions type a ?)"); cx = u.ux; cy = u.uy; - curs(cx,cy+2); - while((c = readchar()) != '.'){ - for(i=0; i<8; i++) if(sdir[i] == c){ - if(1 <= cx + xdir[i] && cx + xdir[i] <= COLNO) - cx += xdir[i]; - if(0 <= cy + ydir[i] && cy + ydir[i] <= ROWNO-1) - cy += ydir[i]; - goto nxtc; - } - if(c == '?'){ + curs(cx, cy + 2); + while ((c = readchar()) != '.') { + for (i = 0; i < 8; i++) + if (sdir[i] == c) { + if (1 <= cx + xdir[i] && cx + xdir[i] <= COLNO) + cx += xdir[i]; + if (0 <= cy + ydir[i] && cy + ydir[i] <= ROWNO - 1) + cy += ydir[i]; + goto nxtc; + } + if (c == '?') { pline("Use [hjkl] to move the cursor to %s.", goal); pline("Type a . when you are at the right place."); } else { pline("Unknown direction: '%s' (%s).", - visctrl(c), - force ? "use hjkl or ." : "aborted"); - if(force) goto nxtc; + visctrl(c), + force ? "use hjkl or ." : "aborted"); + if (force) + goto nxtc; cc.x = -1; cc.y = 0; - return(cc); + return (cc); } - nxtc: ; - curs(cx,cy+2); +nxtc: + curs(cx, cy + 2); } cc.x = cx; cc.y = cy; - return(cc); + return (cc); } int do_mname(void) { -char buf[BUFSZ]; -coord cc; -int cx,cy,lth,i; -struct monst *mtmp, *mtmp2; + char buf[BUFSZ]; + coord cc; + int cx, cy, lth, i; + struct monst *mtmp, *mtmp2; + cc = getpos(0, "the monster you want to name"); cx = cc.x; cy = cc.y; - if(cx < 0) return(0); - mtmp = m_at(cx,cy); - if(!mtmp){ - if(cx == u.ux && cy == u.uy) - pline("This ugly monster is called %s and cannot be renamed.", - plname); - else - pline("There is no monster there."); - return(1); + if (cx < 0) + return (0); + mtmp = m_at(cx, cy); + if (!mtmp) { + if (cx == u.ux && cy == u.uy) + pline("This ugly monster is called %s and cannot be renamed.", + plname); + else + pline("There is no monster there."); + return (1); } - if(mtmp->mimic){ - pline("I see no monster there."); - return(1); + if (mtmp->mimic) { + pline("I see no monster there."); + return (1); } - if(!cansee(cx,cy)) { - pline("I cannot see a monster there."); - return(1); + if (!cansee(cx, cy)) { + pline("I cannot see a monster there."); + return (1); } pline("What do you want to call %s? ", lmonnam(mtmp)); getlin(buf); clrlin(); - if(!*buf || *buf == '\033') - return(1); - lth = strlen(buf)+1; - if(lth > 63){ + if (!*buf || *buf == '\033') + return (1); + lth = strlen(buf) + 1; + if (lth > 63) { buf[62] = 0; lth = 63; } mtmp2 = newmonst(mtmp->mxlth + lth); *mtmp2 = *mtmp; - for(i=0; (unsigned)imxlth; i++) - ((char *) mtmp2->mextra)[i] = ((char *) mtmp->mextra)[i]; + for (i = 0; (unsigned)i < mtmp->mxlth; i++) + ((char *)mtmp2->mextra)[i] = ((char *)mtmp->mextra)[i]; mtmp2->mnamelth = lth; strcpy(NAME(mtmp2), buf); - replmon(mtmp,mtmp2); - return(1); + replmon(mtmp, mtmp2); + return (1); } /* @@ -103,16 +108,17 @@ struct monst *mtmp, *mtmp2; static void do_oname(struct obj *obj) { -struct obj *otmp, *otmp2; -int lth; -char buf[BUFSZ]; + struct obj *otmp, *otmp2; + int lth; + char buf[BUFSZ]; + pline("What do you want to name %s? ", doname(obj)); getlin(buf); clrlin(); - if(!*buf || *buf == '\033') + if (!*buf || *buf == '\033') return; - lth = strlen(buf)+1; - if(lth > 63){ + lth = strlen(buf) + 1; + if (lth > 63) { buf[62] = 0; lth = 63; } @@ -124,19 +130,23 @@ char buf[BUFSZ]; setworn(NULL, obj->owornmask); setworn(otmp2, otmp2->owornmask); - /* do freeinv(obj); etc. by hand in order to preserve - the position of this object in the inventory */ - if(obj == invent) invent = otmp2; - else for(otmp = invent; ; otmp = otmp->nobj){ - if(!otmp) - panic("Do_oname: cannot find obj."); - if(otmp->nobj == obj){ - otmp->nobj = otmp2; - break; + /* + * do freeinv(obj); etc. by hand in order to preserve the position of + * this object in the inventory + */ + if (obj == invent) + invent = otmp2; + else + for (otmp = invent;; otmp = otmp->nobj) { + if (!otmp) + panic("Do_oname: cannot find obj."); + if (otmp->nobj == obj) { + otmp->nobj = otmp2; + break; + } } - } /*obfree(obj, otmp2);*/ /* now unnecessary: no pointers on bill */ - free((char *) obj); /* let us hope nobody else saved a pointer */ + free(obj); /* let us hope nobody else saved a pointer */ } int @@ -145,18 +155,20 @@ ddocall(void) struct obj *obj; pline("Do you want to name an individual object? [ny] "); - switch(readchar()) { + switch (readchar()) { case '\033': break; case 'y': obj = getobj("#", "name"); - if(obj) do_oname(obj); + if (obj) + do_oname(obj); break; default: obj = getobj("?!=/", "call"); - if(obj) docall(obj); + if (obj) + docall(obj); } - return(0); + return (0); } void @@ -171,15 +183,16 @@ docall(struct obj *obj) otemp.quan = 1; otemp.onamelth = 0; str = xname(&otemp); - pline("Call %s %s: ", index(vowels,*str) ? "an" : "a", str); + pline("Call %s %s: ", strchr(vowels, *str) ? "an" : "a", str); getlin(buf); clrlin(); - if(!*buf || *buf == '\033') + if (!*buf || *buf == '\033') return; - str = newstring(strlen(buf)+1); - strcpy(str,buf); + str = newstring(strlen(buf) + 1); + strcpy(str, buf); str1 = &(objects[obj->otyp].oc_uname); - if(*str1) free(*str1); + if (*str1) + free(*str1); *str1 = str; } @@ -194,58 +207,63 @@ const char *ghostnames[] = { static char * xmonnam(struct monst *mtmp, int vb) { -static char buf[BUFSZ]; /* %% */ - if(mtmp->mnamelth && !vb) { + static char buf[BUFSZ]; /* %% */ + + if (mtmp->mnamelth && !vb) { strcpy(buf, NAME(mtmp)); - return(buf); + return (buf); } - switch(mtmp->data->mlet) { + switch (mtmp->data->mlet) { case ' ': - { const char *gn = (const char *)mtmp->mextra; - if(!*gn) { /* might also look in scorefile */ - gn = ghostnames[rn2(SIZE(ghostnames))]; - if(!rn2(2)) (void) - strcpy((char *) mtmp->mextra, !rn2(5) ? plname : gn); - } - sprintf(buf, "%s's ghost", gn); + { + const char *gn = (const char *)mtmp->mextra; + if (!*gn) { /* might also look in scorefile */ + gn = ghostnames[rn2(SIZE(ghostnames))]; + if (!rn2(2)) + strcpy((char *)mtmp->mextra, + !rn2(5) ? plname : gn); + } + sprintf(buf, "%s's ghost", gn); } break; case '@': - if(mtmp->isshk) { + if (mtmp->isshk) { strcpy(buf, shkname(mtmp)); break; } - /* fall into next case */ + /* fall into next case */ default: sprintf(buf, "the %s%s", mtmp->minvis ? "invisible " : "", mtmp->data->mname); } - if(vb && mtmp->mnamelth) { + if (vb && mtmp->mnamelth) { strcat(buf, " called "); strcat(buf, NAME(mtmp)); } - return(buf); + return (buf); } static char * lmonnam(struct monst *mtmp) { - return(xmonnam(mtmp, 1)); + return (xmonnam(mtmp, 1)); } char * monnam(struct monst *mtmp) { - return(xmonnam(mtmp, 0)); + return (xmonnam(mtmp, 0)); } char * Monnam(struct monst *mtmp) { -char *bp = monnam(mtmp); - if('a' <= *bp && *bp <= 'z') *bp += ('A' - 'a'); - return(bp); + char *bp = monnam(mtmp); + + if ('a' <= *bp && *bp <= 'z') + *bp += ('A' - 'a'); + return (bp); } char * @@ -254,36 +272,39 @@ amonnam(struct monst *mtmp, const char *adj) char *bp = monnam(mtmp); static char buf[BUFSZ]; /* %% */ - if(!strncmp(bp, "the ", 4)) bp += 4; + if (!strncmp(bp, "the ", 4)) + bp += 4; sprintf(buf, "the %s %s", adj, bp); - return(buf); + return (buf); } char * Amonnam(struct monst *mtmp, const char *adj) { - char *bp = amonnam(mtmp,adj); + char *bp = amonnam(mtmp, adj); *bp = 'T'; - return(bp); + return (bp); } char * Xmonnam(struct monst *mtmp) { -char *bp = Monnam(mtmp); - if(!strncmp(bp, "The ", 4)) { + char *bp = Monnam(mtmp); + + if (!strncmp(bp, "The ", 4)) { bp += 2; *bp = 'A'; } - return(bp); + return (bp); } static char * visctrl(char c) { -static char ccc[3]; - if(c < 040) { + static char ccc[3]; + + if (c < 040) { ccc[0] = '^'; ccc[1] = c + 0100; ccc[2] = 0; @@ -291,5 +312,5 @@ static char ccc[3]; ccc[0] = c; ccc[1] = 0; } - return(ccc); + return (ccc); } diff --git a/games/hack/hack.do_wear.c b/games/hack/hack.do_wear.c index 310d7e268f..c7f78028e1 100644 --- a/games/hack/hack.do_wear.c +++ b/games/hack/hack.do_wear.c @@ -6,9 +6,9 @@ #include "hack.h" extern char quitchars[]; -static void off_msg(struct obj *); -static int dorr(struct obj *); -static bool cursed(struct obj *); +static void off_msg(struct obj *); +static int dorr(struct obj *); +static bool cursed(struct obj *); static void off_msg(struct obj *otmp) @@ -20,90 +20,95 @@ int doremarm(void) { struct obj *otmp; - if(!uarm && !uarmh && !uarms && !uarmg) { + + if (!uarm && !uarmh && !uarms && !uarmg) { pline("Not wearing any armor."); - return(0); + return (0); } otmp = (!uarmh && !uarms && !uarmg) ? uarm : - (!uarms && !uarm && !uarmg) ? uarmh : - (!uarmh && !uarm && !uarmg) ? uarms : - (!uarmh && !uarm && !uarms) ? uarmg : - getobj("[", "take off"); - if(!otmp) return(0); - if(!(otmp->owornmask & (W_ARMOR - W_ARM2))) { + (!uarms && !uarm && !uarmg) ? uarmh : + (!uarmh && !uarm && !uarmg) ? uarms : + (!uarmh && !uarm && !uarms) ? uarmg : + getobj("[", "take off"); + if (!otmp) + return (0); + if (!(otmp->owornmask & (W_ARMOR - W_ARM2))) { pline("You can't take that off."); - return(0); + return (0); } - if( otmp == uarmg && uwep && uwep->cursed ) { /* myers@uwmacc */ - pline("You seem not able to take off the gloves while holding your weapon."); - return(0); + if (otmp == uarmg && uwep && uwep->cursed) { /* myers@uwmacc */ + pline("You seem not able to take off the gloves while holding your weapon."); + return (0); } armoroff(otmp); - return(1); + return (1); } int doremring(void) { - if(!uleft && !uright){ + if (!uleft && !uright) { pline("Not wearing any ring."); - return(0); + return (0); } - if(!uleft) - return(dorr(uright)); - if(!uright) - return(dorr(uleft)); - if(uleft && uright) while(1) { - char answer; + if (!uleft) + return (dorr(uright)); + if (!uright) + return (dorr(uleft)); + if (uleft && uright) + for (;;) { + char answer; - pline("What ring, Right or Left? [ rl?]"); - if(index(quitchars, (answer = readchar()))) - return(0); - switch(answer) { - case 'l': - case 'L': - return(dorr(uleft)); - case 'r': - case 'R': - return(dorr(uright)); - case '?': - doprring(); - /* might look at morc here %% */ + pline("What ring, Right or Left? [ rl?]"); + if (strchr(quitchars, (answer = readchar()))) + return (0); + switch (answer) { + case 'l': + case 'L': + return (dorr(uleft)); + case 'r': + case 'R': + return (dorr(uright)); + case '?': + doprring(); + /* might look at morc here %% */ + } } - } /* NOTREACHED */ - return(0); + return (0); } static int dorr(struct obj *otmp) { - if(cursed(otmp)) return(0); + if (cursed(otmp)) + return (0); ringoff(otmp); off_msg(otmp); - return(1); + return (1); } static bool cursed(struct obj *otmp) { - if(otmp->cursed){ + if (otmp->cursed) { pline("You can't. It appears to be cursed."); - return(1); + return (1); } - return(0); + return (0); } - bool armoroff(struct obj *otmp) { -int delay = -objects[otmp->otyp].oc_delay; - if(cursed(otmp)) return(0); + int delay = -objects[otmp->otyp].oc_delay; + + if (cursed(otmp)) + return (0); setworn(NULL, otmp->owornmask & W_ARMOR); - if(delay) { + if (delay) { nomul(delay); - switch(otmp->otyp) { + switch (otmp->otyp) { case HELMET: nomovemsg = "You finished taking off your helmet."; break; @@ -113,10 +118,9 @@ int delay = -objects[otmp->otyp].oc_delay; default: nomovemsg = "You finished taking off your suit."; } - } else { + } else off_msg(otmp); - } - return(1); + return (1); } int @@ -128,56 +132,62 @@ doweararm(void) long mask = 0; otmp = getobj("[", "wear"); - if(!otmp) return(0); - if(otmp->owornmask & W_ARMOR) { + if (!otmp) + return (0); + if (otmp->owornmask & W_ARMOR) { pline("You are already wearing that!"); - return(0); + return (0); } - if(otmp->otyp == HELMET){ - if(uarmh) { + if (otmp->otyp == HELMET) { + if (uarmh) { pline("You are already wearing a helmet."); err++; } else mask = W_ARMH; - } else if(otmp->otyp == SHIELD){ - if(uarms) pline("You are already wearing a shield."), err++; - if(uwep && uwep->otyp == TWO_HANDED_SWORD) - pline("You cannot wear a shield and wield a two-handed sword."), err++; - if(!err) mask = W_ARMS; - } else if(otmp->otyp == PAIR_OF_GLOVES) { - if(uarmg) { + } else if (otmp->otyp == SHIELD) { + if (uarms) + pline("You are already wearing a shield."), err++; + if (uwep && uwep->otyp == TWO_HANDED_SWORD) { + pline("You cannot wear a shield and wield a two-handed sword."); + err++; + } + if (!err) + mask = W_ARMS; + } else if (otmp->otyp == PAIR_OF_GLOVES) { + if (uarmg) { pline("You are already wearing gloves."); err++; - } else - if(uwep && uwep->cursed) { + } else if (uwep && uwep->cursed) { pline("You cannot wear gloves over your weapon."); err++; } else mask = W_ARMG; } else { - if(uarm) { - if(otmp->otyp != ELVEN_CLOAK || uarm2) { + if (uarm) { + if (otmp->otyp != ELVEN_CLOAK || uarm2) { pline("You are already wearing some armor."); err++; } } - if(!err) mask = W_ARM; + if (!err) + mask = W_ARM; } - if(otmp == uwep && uwep->cursed) { - if(!err++) + if (otmp == uwep && uwep->cursed) { + if (!err++) pline("%s is welded to your hand.", Doname(uwep)); } - if(err) return(0); + if (err) + return (0); setworn(otmp, mask); - if(otmp == uwep) + if (otmp == uwep) setuwep(NULL); delay = -objects[otmp->otyp].oc_delay; - if(delay){ + if (delay) { nomul(delay); nomovemsg = "You finished your dressing manoeuvre."; } otmp->known = 1; - return(1); + return (1); } int @@ -187,51 +197,56 @@ dowearring(void) long mask = 0; long oldprop; - if(uleft && uright){ + if (uleft && uright) { pline("There are no more ring-fingers to fill."); - return(0); + return (0); } otmp = getobj("=", "wear"); - if(!otmp) return(0); - if(otmp->owornmask & W_RING) { + if (!otmp) + return (0); + if (otmp->owornmask & W_RING) { pline("You are already wearing that!"); - return(0); + return (0); } - if(otmp == uleft || otmp == uright) { + if (otmp == uleft || otmp == uright) { pline("You are already wearing that."); - return(0); + return (0); } - if(otmp == uwep && uwep->cursed) { + if (otmp == uwep && uwep->cursed) { pline("%s is welded to your hand.", Doname(uwep)); - return(0); + return (0); } - if(uleft) mask = RIGHT_RING; - else if(uright) mask = LEFT_RING; - else do { - char answer; + if (uleft) + mask = RIGHT_RING; + else if (uright) + mask = LEFT_RING; + else + do { + char answer; - pline("What ring-finger, Right or Left? "); - if(index(quitchars, (answer = readchar()))) - return(0); - switch(answer){ - case 'l': - case 'L': - mask = LEFT_RING; - break; - case 'r': - case 'R': - mask = RIGHT_RING; - break; - } - } while(!mask); + pline("What ring-finger, Right or Left? "); + if (strchr(quitchars, (answer = readchar()))) + return (0); + switch (answer) { + case 'l': + case 'L': + mask = LEFT_RING; + break; + case 'r': + case 'R': + mask = RIGHT_RING; + break; + } + } while (!mask); setworn(otmp, mask); - if(otmp == uwep) + if (otmp == uwep) setuwep(NULL); oldprop = u.uprops[PROP(otmp->otyp)].p_flgs; u.uprops[PROP(otmp->otyp)].p_flgs |= mask; - switch(otmp->otyp){ + switch (otmp->otyp) { case RIN_LEVITATION: - if(!oldprop) float_up(); + if (!oldprop) + float_up(); break; case RIN_PROTECTION_FROM_SHAPE_CHANGERS: rescham(); @@ -239,8 +254,10 @@ dowearring(void) case RIN_GAIN_STRENGTH: u.ustr += otmp->spe; u.ustrmax += otmp->spe; - if(u.ustr > 118) u.ustr = 118; - if(u.ustrmax > 118) u.ustrmax = 118; + if (u.ustr > 118) + u.ustr = 118; + if (u.ustrmax > 118) + u.ustrmax = 118; flags.botl = 1; break; case RIN_INCREASE_DAMAGE: @@ -248,19 +265,20 @@ dowearring(void) break; } prinv(otmp); - return(1); + return (1); } void ringoff(struct obj *obj) { -long mask; + long mask; + mask = obj->owornmask & W_RING; setworn(NULL, obj->owornmask); - if(!(u.uprops[PROP(obj->otyp)].p_flgs & mask)) + if (!(u.uprops[PROP(obj->otyp)].p_flgs & mask)) impossible("Strange... I didn't know you had that ring."); u.uprops[PROP(obj->otyp)].p_flgs &= ~mask; - switch(obj->otyp) { + switch (obj->otyp) { case RIN_FIRE_RESISTANCE: /* Bad luck if the player is in hell... --jgm */ if (!Fire_resistance && dlevel >= 30) { @@ -270,15 +288,16 @@ long mask; } break; case RIN_LEVITATION: - if(!Levitation) { /* no longer floating */ + if (!Levitation) /* no longer floating */ float_down(); - } break; case RIN_GAIN_STRENGTH: u.ustr -= obj->spe; u.ustrmax -= obj->spe; - if(u.ustr > 118) u.ustr = 118; - if(u.ustrmax > 118) u.ustrmax = 118; + if (u.ustr > 118) + u.ustr = 118; + if (u.ustrmax > 118) + u.ustrmax = 118; flags.botl = 1; break; case RIN_INCREASE_DAMAGE: @@ -290,15 +309,23 @@ long mask; void find_ac(void) { -int uac = 10; - if(uarm) uac -= ARM_BONUS(uarm); - if(uarm2) uac -= ARM_BONUS(uarm2); - if(uarmh) uac -= ARM_BONUS(uarmh); - if(uarms) uac -= ARM_BONUS(uarms); - if(uarmg) uac -= ARM_BONUS(uarmg); - if(uleft && uleft->otyp == RIN_PROTECTION) uac -= uleft->spe; - if(uright && uright->otyp == RIN_PROTECTION) uac -= uright->spe; - if(uac != u.uac){ + int uac = 10; + + if (uarm) + uac -= ARM_BONUS(uarm); + if (uarm2) + uac -= ARM_BONUS(uarm2); + if (uarmh) + uac -= ARM_BONUS(uarmh); + if (uarms) + uac -= ARM_BONUS(uarms); + if (uarmg) + uac -= ARM_BONUS(uarmg); + if (uleft && uleft->otyp == RIN_PROTECTION) + uac -= uleft->spe; + if (uright && uright->otyp == RIN_PROTECTION) + uac -= uright->spe; + if (uac != u.uac) { u.uac = uac; flags.botl = 1; } @@ -307,52 +334,59 @@ int uac = 10; void glibr(void) { -struct obj *otmp; -int xfl = 0; - if(!uarmg) if(uleft || uright) { - /* Note: at present also cursed rings fall off */ - pline("Your %s off your fingers.", - (uleft && uright) ? "rings slip" : "ring slips"); - xfl++; - if((otmp = uleft) != NULL){ - ringoff(uleft); - dropx(otmp); - } - if((otmp = uright) != NULL){ - ringoff(uright); - dropx(otmp); + struct obj *otmp; + int xfl = 0; + + if (!uarmg) + if (uleft || uright) { + /* Note: at present also cursed rings fall off */ + pline("Your %s off your fingers.", + (uleft && uright) ? "rings slip" : "ring slips"); + xfl++; + if ((otmp = uleft) != NULL) { + ringoff(uleft); + dropx(otmp); + } + if ((otmp = uright) != NULL) { + ringoff(uright); + dropx(otmp); + } } - } - if((otmp = uwep) != NULL){ + if ((otmp = uwep) != NULL) { /* Note: at present also cursed weapons fall */ setuwep(NULL); dropx(otmp); pline("Your weapon %sslips from your hands.", - xfl ? "also " : ""); + xfl ? "also " : ""); } } struct obj * some_armor(void) { -struct obj *otmph = uarm; - if(uarmh && (!otmph || !rn2(4))) otmph = uarmh; - if(uarmg && (!otmph || !rn2(4))) otmph = uarmg; - if(uarms && (!otmph || !rn2(4))) otmph = uarms; - return(otmph); + struct obj *otmph = uarm; + + if (uarmh && (!otmph || !rn2(4))) + otmph = uarmh; + if (uarmg && (!otmph || !rn2(4))) + otmph = uarmg; + if (uarms && (!otmph || !rn2(4))) + otmph = uarms; + return (otmph); } void corrode_armor(void) { -struct obj *otmph = some_armor(); - if(otmph){ - if(otmph->rustfree || - otmph->otyp == ELVEN_CLOAK || - otmph->otyp == LEATHER_ARMOR || - otmph->otyp == STUDDED_LEATHER_ARMOR) { + struct obj *otmph = some_armor(); + + if (otmph) { + if (otmph->rustfree || + otmph->otyp == ELVEN_CLOAK || + otmph->otyp == LEATHER_ARMOR || + otmph->otyp == STUDDED_LEATHER_ARMOR) { pline("Your %s not affected!", - aobjnam(otmph, "are")); + aobjnam(otmph, "are")); return; } pline("Your %s!", aobjnam(otmph, "corrode")); diff --git a/games/hack/hack.dog.c b/games/hack/hack.dog.c index f183ee9f1d..a75f35be87 100644 --- a/games/hack/hack.dog.c +++ b/games/hack/hack.dog.c @@ -3,25 +3,27 @@ /* $FreeBSD: src/games/hack/hack.dog.c,v 1.3 1999/11/16 02:57:03 billf Exp $ */ /* $DragonFly: src/games/hack/hack.dog.c,v 1.4 2006/08/21 19:45:32 pavalos Exp $ */ -#include "hack.h" -#include "hack.mfndpos.h" +#include "hack.h" +#include "hack.mfndpos.h" #include "def.edog.h" struct permonst li_dog = - { "little dog", 'd',2,18,6,1,6,sizeof(struct edog) }; + { "little dog", 'd', 2, 18, 6, 1, 6, sizeof(struct edog) }; struct permonst dog = - { "dog", 'd',4,16,5,1,6,sizeof(struct edog) }; + { "dog", 'd', 4, 16, 5, 1, 6, sizeof(struct edog) }; struct permonst la_dog = - { "large dog", 'd',6,15,4,2,4,sizeof(struct edog) }; + { "large dog", 'd', 6, 15, 4, 2, 4, sizeof(struct edog) }; -static void initedog(struct monst *); -static xchar dogfood(struct obj *); +static void initedog(struct monst *); +static xchar dogfood(struct obj *); void makedog(void) { -struct monst *mtmp = makemon(&li_dog,u.ux,u.uy); - if(!mtmp) return; /* dogs were genocided */ + struct monst *mtmp = makemon(&li_dog, u.ux, u.uy); + + if (!mtmp) + return; /* dogs were genocided */ initedog(mtmp); } @@ -40,19 +42,20 @@ initedog(struct monst *mtmp) /* attach the monsters that went down (or up) together with @ */ struct monst *mydogs = 0; struct monst *fallen_down = 0; /* monsters that fell through a trapdoor */ - /* they will appear on the next level @ goes to, even if he goes up! */ +/* they will appear on the next level @ goes to, even if he goes up! */ void losedogs(void) { -struct monst *mtmp; - while((mtmp = mydogs)){ + struct monst *mtmp; + + while ((mtmp = mydogs)) { mydogs = mtmp->nmon; mtmp->nmon = fmon; fmon = mtmp; mnexto(mtmp); } - while((mtmp = fallen_down)){ + while ((mtmp = fallen_down)) { fallen_down = mtmp->nmon; mtmp->nmon = fmon; fmon = mtmp; @@ -63,17 +66,18 @@ struct monst *mtmp; void keepdogs(void) { -struct monst *mtmp; - for(mtmp = fmon; mtmp; mtmp = mtmp->nmon) - if(dist(mtmp->mx,mtmp->my) < 3 && follower(mtmp) - && !mtmp->msleep && !mtmp->mfroz) { - relmon(mtmp); - mtmp->nmon = mydogs; - mydogs = mtmp; - unpmon(mtmp); - keepdogs(); /* we destroyed the link, so use recursion */ - return; /* (admittedly somewhat primitive) */ - } + struct monst *mtmp; + + for (mtmp = fmon; mtmp; mtmp = mtmp->nmon) + if (dist(mtmp->mx, mtmp->my) < 3 && follower(mtmp) + && !mtmp->msleep && !mtmp->mfroz) { + relmon(mtmp); + mtmp->nmon = mydogs; + mydogs = mtmp; + unpmon(mtmp); + keepdogs(); /* we destroyed the link, so use recursion */ + return; /* (admittedly somewhat primitive) */ + } } void @@ -94,26 +98,28 @@ fall_down(struct monst *mtmp) #define APPORT 4 #define POISON 5 #define UNDEF 6 + static xchar dogfood(struct obj *obj) { - switch(obj->olet) { + switch (obj->olet) { case FOOD_SYM: - return( - (obj->otyp == TRIPE_RATION) ? DOGFOOD : - (obj->otyp < CARROT) ? ACCFOOD : - (obj->otyp < CORPSE) ? MANFOOD : - (poisonous(obj) || obj->age + 50 <= moves || - obj->otyp == DEAD_COCKATRICE) - ? POISON : CADAVER - ); + return ( + (obj->otyp == TRIPE_RATION) ? DOGFOOD : + (obj->otyp < CARROT) ? ACCFOOD : + (obj->otyp < CORPSE) ? MANFOOD : + (poisonous(obj) || obj->age + 50 <= moves || + obj->otyp == DEAD_COCKATRICE) + ? POISON : CADAVER + ); default: - if(!obj->cursed) return(APPORT); - /* fall into next case */ + if (!obj->cursed) + return (APPORT); + /* fall into next case */ case BALL_SYM: case CHAIN_SYM: case ROCK_SYM: - return(UNDEF); + return (UNDEF); } } @@ -121,155 +127,164 @@ dogfood(struct obj *obj) int dog_move(struct monst *mtmp, int after) { -int nx,ny,omx,omy,appr,nearer,j; -int udist,chi = 0,i,whappr; -struct monst *mtmp2; -struct permonst *mdat = mtmp->data; -struct edog *edog = EDOG(mtmp); -struct obj *obj; -struct trap *trap; -xchar cnt,chcnt,nix,niy; -schar dogroom,uroom; -xchar gx,gy,gtyp,otyp; /* current goal */ -coord poss[9]; -int info[9]; -#define GDIST(x,y) ((x-gx)*(x-gx) + (y-gy)*(y-gy)) -#define DDIST(x,y) ((x-omx)*(x-omx) + (y-omy)*(y-omy)) - - if(moves <= edog->eattime) return(0); /* dog is still eating */ + int nx, ny, omx, omy, appr, nearer, j; + int udist, chi = 0, i, whappr; + struct monst *mtmp2; + struct permonst *mdat = mtmp->data; + struct edog *edog = EDOG(mtmp); + struct obj *obj; + struct trap *trap; + xchar cnt, chcnt, nix, niy; + schar dogroom, uroom; + xchar gx, gy, gtyp, otyp; /* current goal */ + coord poss[9]; + int info[9]; +#define GDIST(x, y) ((x - gx) * (x - gx) + (y - gy) * (y - gy)) +#define DDIST(x, y) ((x - omx) * (x - omx) + (y - omy) * (y - omy)) + + if (moves <= edog->eattime) /* dog is still eating */ + return (0); omx = mtmp->mx; omy = mtmp->my; whappr = (moves - EDOG(mtmp)->whistletime < 5); - if(moves > edog->hungrytime + 500 && !mtmp->mconf){ + if (moves > edog->hungrytime + 500 && !mtmp->mconf) { mtmp->mconf = 1; mtmp->mhpmax /= 3; - if(mtmp->mhp > mtmp->mhpmax) + if (mtmp->mhp > mtmp->mhpmax) mtmp->mhp = mtmp->mhpmax; - if(cansee(omx,omy)) + if (cansee(omx, omy)) pline("%s is confused from hunger.", Monnam(mtmp)); - else pline("You feel worried about %s.", monnam(mtmp)); - } else - if(moves > edog->hungrytime + 750 || mtmp->mhp < 1){ - if(cansee(omx,omy)) + else + pline("You feel worried about %s.", monnam(mtmp)); + } else if (moves > edog->hungrytime + 750 || mtmp->mhp < 1) { + if (cansee(omx, omy)) pline("%s dies from hunger.", Monnam(mtmp)); else - pline("You have a sad feeling for a moment, then it passes."); + pline("You have a sad feeling for a moment, then it passes."); mondied(mtmp); - return(2); + return (2); } - dogroom = inroom(omx,omy); - uroom = inroom(u.ux,u.uy); - udist = dist(omx,omy); + dogroom = inroom(omx, omy); + uroom = inroom(u.ux, u.uy); + udist = dist(omx, omy); /* maybe we tamed him while being swallowed --jgm */ - if(!udist) return(0); + if (!udist) + return (0); /* if we are carrying sth then we drop it (perhaps near @) */ /* Note: if apport == 1 then our behaviour is independent of udist */ - if(mtmp->minvent){ - if(!rn2(udist) || !rn2((int) edog->apport)) - if(rn2(10) < (int)edog->apport){ - relobj(mtmp, (int) mtmp->minvis); - if(edog->apport > 1) edog->apport--; - edog->dropdist = udist; /* hpscdi!jon */ - edog->droptime = moves; - } - } else { - if((obj = o_at(omx,omy))) if(!index("0_", obj->olet)){ - if((otyp = dogfood(obj)) <= CADAVER){ - nix = omx; - niy = omy; - goto eatobj; - } - if(obj->owt < 10*mtmp->data->mlevel) - if(rn2(20) < (int)edog->apport+3) - if(rn2(udist) || !rn2((int) edog->apport)){ - freeobj(obj); - unpobj(obj); - /* if(levl[omx][omy].scrsym == obj->olet) - newsym(omx,omy); */ - mpickobj(mtmp,obj); - } + if (mtmp->minvent) { + if (!rn2(udist) || !rn2((int)edog->apport)) + if (rn2(10) < (int)edog->apport) { + relobj(mtmp, (int)mtmp->minvis); + if (edog->apport > 1) + edog->apport--; + edog->dropdist = udist; /* hpscdi!jon */ + edog->droptime = moves; + } + } else if ((obj = o_at(omx, omy))) { + if (!strchr("0_", obj->olet)) { + if ((otyp = dogfood(obj)) <= CADAVER) { + nix = omx; + niy = omy; + goto eatobj; + } + if (obj->owt < 10 * mtmp->data->mlevel) { + if (rn2(20) < (int)edog->apport + 3) { + if (rn2(udist) || + !rn2((int)edog->apport)) { + freeobj(obj); + unpobj(obj); + /* if (levl[omx][omy].scrsym == obj->olet) + * newsym(omx, omy); */ + mpickobj(mtmp, obj); + } + } + } } } /* first we look for food */ - gtyp = UNDEF; /* no goal as yet */ - gx = gy = 0; /* suppress 'used before set' message */ - for(obj = fobj; obj; obj = obj->nobj) { + gtyp = UNDEF; /* no goal as yet */ + gx = gy = 0; /* suppress 'used before set' message */ + for (obj = fobj; obj; obj = obj->nobj) { otyp = dogfood(obj); - if(otyp > gtyp || otyp == UNDEF) continue; - if(inroom(obj->ox,obj->oy) != dogroom) continue; - if(otyp < MANFOOD && - (dogroom >= 0 || DDIST(obj->ox,obj->oy) < 10)) { - if(otyp < gtyp || (otyp == gtyp && - DDIST(obj->ox,obj->oy) < DDIST(gx,gy))){ + if (otyp > gtyp || otyp == UNDEF) + continue; + if (inroom(obj->ox, obj->oy) != dogroom) + continue; + if (otyp < MANFOOD && + (dogroom >= 0 || DDIST(obj->ox, obj->oy) < 10)) { + if (otyp < gtyp || (otyp == gtyp && + DDIST(obj->ox, obj->oy) < DDIST(gx, gy))) { gx = obj->ox; gy = obj->oy; gtyp = otyp; } - } else - if(gtyp == UNDEF && dogroom >= 0 && - uroom == dogroom && - !mtmp->minvent && (int)edog->apport > rn2(8)){ + } else if (gtyp == UNDEF && dogroom >= 0 && + uroom == dogroom && + !mtmp->minvent && (int)edog->apport > rn2(8)) { gx = obj->ox; gy = obj->oy; gtyp = APPORT; } } - if(gtyp == UNDEF || - (gtyp != DOGFOOD && gtyp != APPORT && moves < edog->hungrytime)){ - if(dogroom < 0 || dogroom == uroom){ + if (gtyp == UNDEF || + (gtyp != DOGFOOD && gtyp != APPORT && moves < edog->hungrytime)) { + if (dogroom < 0 || dogroom == uroom) { gx = u.ux; gy = u.uy; #ifndef QUEST } else { int tmp = rooms[dogroom].fdoor; - cnt = rooms[dogroom].doorct; + cnt = rooms[dogroom].doorct; gx = gy = FAR; /* random, far away */ - while(cnt--){ - if(dist(gx,gy) > - dist(doors[tmp].x, doors[tmp].y)){ + while (cnt--) { + if (dist(gx, gy) > + dist(doors[tmp].x, doors[tmp].y)) { gx = doors[tmp].x; gy = doors[tmp].y; } tmp++; } /* here gx == FAR e.g. when dog is in a vault */ - if(gx == FAR || (gx == omx && gy == omy)){ + if (gx == FAR || (gx == omx && gy == omy)) { gx = u.ux; gy = u.uy; } #endif /* QUEST */ } appr = (udist >= 9) ? 1 : (mtmp->mflee) ? -1 : 0; - if(after && udist <= 4 && gx == u.ux && gy == u.uy) - return(0); - if(udist > 1){ - if(!IS_ROOM(levl[u.ux][u.uy].typ) || !rn2(4) || - whappr || - (mtmp->minvent && rn2((int) edog->apport))) + if (after && udist <= 4 && gx == u.ux && gy == u.uy) + return (0); + if (udist > 1) { + if (!IS_ROOM(levl[u.ux][u.uy].typ) || !rn2(4) || + whappr || + (mtmp->minvent && rn2((int)edog->apport))) appr = 1; } /* if you have dog food he'll follow you more closely */ - if(appr == 0){ + if (appr == 0) { obj = invent; - while(obj){ - if(obj->otyp == TRIPE_RATION){ + while (obj) { + if (obj->otyp == TRIPE_RATION) { appr = 1; break; } obj = obj->nobj; } } - } else appr = 1; /* gtyp != UNDEF */ - if(mtmp->mconf) appr = 0; + } else /* gtyp != UNDEF */ + appr = 1; + if (mtmp->mconf) + appr = 0; - if(gx == u.ux && gy == u.uy && (dogroom != uroom || dogroom < 0)){ - coord *cp; - cp = gettrack(omx,omy); - if(cp){ + if (gx == u.ux && gy == u.uy && (dogroom != uroom || dogroom < 0)) { + coord *cp; + cp = gettrack(omx, omy); + if (cp) { gx = cp->x; gy = cp->y; } @@ -277,103 +292,119 @@ int info[9]; nix = omx; niy = omy; - cnt = mfndpos(mtmp,poss,info,ALLOW_M | ALLOW_TRAPS); + cnt = mfndpos(mtmp, poss, info, ALLOW_M | ALLOW_TRAPS); chcnt = 0; chi = -1; - for(i=0; idata->mlevel >= mdat->mlevel+2 || - mtmp2->data->mlet == 'c') + if (info[i] & ALLOW_M) { + mtmp2 = m_at(nx, ny); + if (mtmp2->data->mlevel >= mdat->mlevel + 2 || + mtmp2->data->mlet == 'c') continue; - if(after) return(0); /* hit only once each move */ + if (after) /* hit only once each move */ + return (0); - if(hitmm(mtmp, mtmp2) == 1 && rn2(4) && - mtmp2->mlstmv != moves && - hitmm(mtmp2,mtmp) == 2) return(2); - return(0); + if (hitmm(mtmp, mtmp2) == 1 && rn2(4) && + mtmp2->mlstmv != moves && + hitmm(mtmp2, mtmp) == 2) + return (2); + return (0); } /* dog avoids traps */ /* but perhaps we have to pass a trap in order to follow @ */ - if((info[i] & ALLOW_TRAPS) && (trap = t_at(nx,ny))){ - if(!trap->tseen && rn2(40)) continue; - if(rn2(10)) continue; + if ((info[i] & ALLOW_TRAPS) && (trap = t_at(nx, ny))) { + if (!trap->tseen && rn2(40)) + continue; + if (rn2(10)) + continue; } /* dog eschewes cursed objects */ /* but likes dog food */ obj = fobj; - while(obj){ - if(obj->ox != nx || obj->oy != ny) - goto nextobj; - if(obj->cursed) goto nxti; - if(obj->olet == FOOD_SYM && - (otyp = dogfood(obj)) < MANFOOD && - (otyp < ACCFOOD || edog->hungrytime <= moves)){ - /* Note: our dog likes the food so much that he - might eat it even when it conceals a cursed object */ - nix = nx; - niy = ny; - chi = i; - eatobj: - edog->eattime = - moves + obj->quan * objects[obj->otyp].oc_delay; - if(edog->hungrytime < moves) - edog->hungrytime = moves; - edog->hungrytime += - 5*obj->quan * objects[obj->otyp].nutrition; - mtmp->mconf = 0; - if(cansee(nix,niy)) - pline("%s ate %s.", Monnam(mtmp), doname(obj)); - /* perhaps this was a reward */ - if(otyp != CADAVER) - edog->apport += 200/(edog->dropdist+moves-edog->droptime); - delobj(obj); - goto newdogpos; - } - nextobj: - obj = obj->nobj; + while (obj) { + if (obj->ox != nx || obj->oy != ny) + goto nextobj; + if (obj->cursed) + goto nxti; + if (obj->olet == FOOD_SYM && + (otyp = dogfood(obj)) < MANFOOD && + (otyp < ACCFOOD || edog->hungrytime <= moves)) { + /* + * Note: our dog likes the food so much that + * he might eat it even when it conceals a + * cursed object + */ + nix = nx; + niy = ny; + chi = i; +eatobj: + edog->eattime = + moves + obj->quan * + objects[obj->otyp].oc_delay; + if (edog->hungrytime < moves) + edog->hungrytime = moves; + edog->hungrytime += + 5 * obj->quan * + objects[obj->otyp].nutrition; + mtmp->mconf = 0; + if (cansee(nix, niy)) + pline("%s ate %s.", Monnam( + mtmp), doname(obj)); + /* perhaps this was a reward */ + if (otyp != CADAVER) + edog->apport += 200 / + (edog->dropdist + + moves - edog->droptime); + delobj(obj); + goto newdogpos; + } +nextobj: + obj = obj->nobj; } - for(j=0; jmtrack[j].x && ny == mtmp->mtrack[j].y) - if(rn2(4*(cnt-j))) goto nxti; + for (j = 0; j < MTSZ && j < cnt - 1; j++) + if (nx == mtmp->mtrack[j].x && ny == mtmp->mtrack[j].y) + if (rn2(4 * (cnt - j))) + goto nxti; /* Some stupid C compilers cannot compute the whole expression at once. */ - nearer = GDIST(nx,ny); - nearer -= GDIST(nix,niy); + nearer = GDIST(nx, ny); + nearer -= GDIST(nix, niy); nearer *= appr; - if((nearer == 0 && !rn2(++chcnt)) || nearer<0 || - (nearer > 0 && !whappr && - ((omx == nix && omy == niy && !rn2(3)) - || !rn2(12)) - )){ + if ((nearer == 0 && !rn2(++chcnt)) || nearer < 0 || + (nearer > 0 && !whappr && + ((omx == nix && omy == niy && !rn2(3)) + || !rn2(12)) + )) { nix = nx; niy = ny; - if(nearer < 0) chcnt = 0; + if (nearer < 0) + chcnt = 0; chi = i; } - nxti: ; +nxti:; } newdogpos: - if(nix != omx || niy != omy){ - if(info[chi] & ALLOW_U){ - hitu(mtmp, d(mdat->damn, mdat->damd)+1); - return(0); + if (nix != omx || niy != omy) { + if (info[chi] & ALLOW_U) { + hitu(mtmp, d(mdat->damn, mdat->damd) + 1); + return (0); } mtmp->mx = nix; mtmp->my = niy; - for(j=MTSZ-1; j>0; j--) mtmp->mtrack[j] = mtmp->mtrack[j-1]; + for (j = MTSZ - 1; j > 0; j--) + mtmp->mtrack[j] = mtmp->mtrack[j - 1]; mtmp->mtrack[0].x = omx; mtmp->mtrack[0].y = omy; } - if(mintrap(mtmp) == 2) /* he died */ - return(2); + if (mintrap(mtmp) == 2) /* he died */ + return (2); pmon(mtmp); - return(1); + return (1); } /* return roomnumber or -1 */ @@ -382,14 +413,15 @@ inroom(xchar x, xchar y) { #ifndef QUEST struct mkroom *croom = &rooms[0]; - while(croom->hx >= 0){ - if(croom->hx >= x-1 && croom->lx <= x+1 && - croom->hy >= y-1 && croom->ly <= y+1) - return(croom - rooms); + + while (croom->hx >= 0) { + if (croom->hx >= x - 1 && croom->lx <= x + 1 && + croom->hy >= y - 1 && croom->ly <= y + 1) + return (croom - rooms); croom++; } #endif /* QUEST */ - return(-1); /* not in room or on door */ + return (-1); /* not in room or on door */ } bool @@ -397,31 +429,32 @@ tamedog(struct monst *mtmp, struct obj *obj) { struct monst *mtmp2; - if(flags.moonphase == FULL_MOON && night() && rn2(6)) - return(0); + if (flags.moonphase == FULL_MOON && night() && rn2(6)) + return (0); /* If we cannot tame him, at least he's no longer afraid. */ mtmp->mflee = 0; mtmp->mfleetim = 0; - if(mtmp->mtame || mtmp->mfroz || + if (mtmp->mtame || mtmp->mfroz || #ifndef NOWORM - mtmp->wormno || + mtmp->wormno || #endif /* NOWORM */ - mtmp->isshk || mtmp->isgd || index(" &@12", mtmp->data->mlet)) - return(0); /* no tame long worms? */ - if(obj) { - if(dogfood(obj) >= MANFOOD) return(0); - if(cansee(mtmp->mx,mtmp->my)){ + mtmp->isshk || mtmp->isgd || strchr(" &@12", mtmp->data->mlet)) + return (0); /* no tame long worms? */ + if (obj) { + if (dogfood(obj) >= MANFOOD) + return (0); + if (cansee(mtmp->mx, mtmp->my)) pline("%s devours the %s.", Monnam(mtmp), - objects[obj->otyp].oc_name); - } + objects[obj->otyp].oc_name); obfree(obj, NULL); } mtmp2 = newmonst(sizeof(struct edog) + mtmp->mnamelth); *mtmp2 = *mtmp; mtmp2->mxlth = sizeof(struct edog); - if(mtmp->mnamelth) strcpy(NAME(mtmp2), NAME(mtmp)); + if (mtmp->mnamelth) + strcpy(NAME(mtmp2), NAME(mtmp)); initedog(mtmp2); - replmon(mtmp,mtmp2); - return(1); + replmon(mtmp, mtmp2); + return (1); } diff --git a/games/hack/hack.eat.c b/games/hack/hack.eat.c index a2e4814961..c2b01ed712 100644 --- a/games/hack/hack.eat.c +++ b/games/hack/hack.eat.c @@ -3,7 +3,7 @@ /* $FreeBSD: src/games/hack/hack.eat.c,v 1.4 1999/11/16 10:26:36 marcel Exp $ */ /* $DragonFly: src/games/hack/hack.eat.c,v 1.5 2006/08/21 19:45:32 pavalos Exp $ */ -#include "hack.h" +#include "hack.h" char POISONOUS[] = "ADKSVabhks"; static bool opentin(void); @@ -14,12 +14,12 @@ static int eatcorpse(struct obj *); /* hunger texts used on bottom line (each 8 chars long) */ #define SATIATED 0 -#define NOT_HUNGRY 1 +#define NOT_HUNGRY 1 #define HUNGRY 2 #define WEAK 3 #define FAINTING 4 -#define FAINTED 5 -#define STARVED 6 +#define FAINTED 5 +#define STARVED 6 const char *hu_stat[] = { "Satiated", @@ -58,34 +58,35 @@ opentin(void) { int r; - if(!carried(tin.tin)) /* perhaps it was stolen? */ - return(0); /* %% probably we should use tinoid */ - if(tin.usedtime++ >= 50) { + if (!carried(tin.tin)) /* perhaps it was stolen? */ + return (0); /* %% probably we should use tinoid */ + if (tin.usedtime++ >= 50) { pline("You give up your attempt to open the tin."); - return(0); + return (0); } - if(tin.usedtime < tin.reqtime) - return(1); /* still busy */ + if (tin.usedtime < tin.reqtime) + return (1); /* still busy */ pline("You succeed in opening the tin."); useup(tin.tin); - r = rn2(2*TTSZ); - if(r < TTSZ){ - pline(tintxts[r].txt); - lesshungry(tintxts[r].nut); - if(r == 1) /* SALMON */ { - Glib = rnd(15); - pline("Eating salmon made your fingers very slippery."); - } + r = rn2(2 * TTSZ); + if (r < TTSZ) { + pline(tintxts[r].txt); + lesshungry(tintxts[r].nut); + if (r == 1) { /* SALMON */ + Glib = rnd(15); + pline("Eating salmon made your fingers very slippery."); + } } else { - pline("It contains spinach - this makes you feel like Popeye!"); - lesshungry(600); - if(u.ustr < 118) - u.ustr += rnd( ((u.ustr < 17) ? 19 : 118) - u.ustr); - if(u.ustr > u.ustrmax) u.ustrmax = u.ustr; - flags.botl = 1; + pline("It contains spinach - this makes you feel like Popeye!"); + lesshungry(600); + if (u.ustr < 118) + u.ustr += rnd(((u.ustr < 17) ? 19 : 118) - u.ustr); + if (u.ustr > u.ustrmax) + u.ustrmax = u.ustr; + flags.botl = 1; } - return(0); + return (0); } static void @@ -103,30 +104,32 @@ doeat(void) int tmp; /* Is there some food (probably a heavy corpse) here on the ground? */ - if(!Levitation) - for(otmp = fobj; otmp; otmp = otmp->nobj) { - if(otmp->ox == u.ux && otmp->oy == u.uy && - otmp->olet == FOOD_SYM) { - pline("There %s %s here; eat %s? [ny] ", - (otmp->quan == 1) ? "is" : "are", - doname(otmp), - (otmp->quan == 1) ? "it" : "one"); - if(readchar() == 'y') { - if(otmp->quan != 1) - splitobj(otmp, 1); - freeobj(otmp); - otmp = addinv(otmp); - addtobill(otmp); - goto gotit; + if (!Levitation) + for (otmp = fobj; otmp; otmp = otmp->nobj) { + if (otmp->ox == u.ux && otmp->oy == u.uy && + otmp->olet == FOOD_SYM) { + pline("There %s %s here; eat %s? [ny] ", + (otmp->quan == 1) ? "is" : "are", + doname(otmp), + (otmp->quan == 1) ? "it" : "one"); + if (readchar() == 'y') { + if (otmp->quan != 1) + splitobj(otmp, 1); + freeobj(otmp); + otmp = addinv(otmp); + addtobill(otmp); + goto gotit; + } } } - } + otmp = getobj("%", "eat"); - if(!otmp) return(0); + if (!otmp) + return (0); gotit: - if(otmp->otyp == TIN){ - if(uwep) { - switch(uwep->otyp) { + if (otmp->otyp == TIN) { + if (uwep) { + switch (uwep->otyp) { case CAN_OPENER: tmp = 1; break; @@ -142,114 +145,120 @@ gotit: goto no_opener; } pline("Using your %s you try to open the tin.", - aobjnam(uwep, NULL)); + aobjnam(uwep, NULL)); } else { - no_opener: +no_opener: pline("It is not so easy to open this tin."); - if(Glib) { + if (Glib) { pline("The tin slips out of your hands."); - if(otmp->quan > 1) { + if (otmp->quan > 1) { struct obj *obj; obj = splitobj(otmp, 1); - if(otmp == uwep) setuwep(obj); + if (otmp == uwep) + setuwep(obj); } dropx(otmp); - return(1); + return (1); } - tmp = 10 + rn2(1 + 500/((int)(u.ulevel + u.ustr))); + tmp = 10 + rn2(1 + 500 / ((int)(u.ulevel + u.ustr))); } tin.reqtime = tmp; tin.usedtime = 0; tin.tin = otmp; occupation = opentin; occtxt = "opening the tin"; - return(1); + return (1); } ftmp = &objects[otmp->otyp]; multi = -ftmp->oc_delay; - if(otmp->otyp >= CORPSE && eatcorpse(otmp)) goto eatx; - if(!rn2(7) && otmp->otyp != FORTUNE_COOKIE) { + if (otmp->otyp >= CORPSE && eatcorpse(otmp)) + goto eatx; + if (!rn2(7) && otmp->otyp != FORTUNE_COOKIE) { pline("Blecch! Rotten food!"); - if(!rn2(4)) { + if (!rn2(4)) { pline("You feel rather light headed."); - Confusion += d(2,4); - } else if(!rn2(4)&& !Blind) { + Confusion += d(2, 4); + } else if (!rn2(4) && !Blind) { pline("Everything suddenly goes dark."); - Blind = d(2,10); + Blind = d(2, 10); seeoff(0); - } else if(!rn2(3)) { - if(Blind) - pline("The world spins and you slap against the floor."); + } else if (!rn2(3)) { + if (Blind) + pline("The world spins and you slap against the floor."); else - pline("The world spins and goes dark."); + pline("The world spins and goes dark."); nomul(-rnd(10)); nomovemsg = "You are conscious again."; } lesshungry(ftmp->nutrition / 4); } else { - if(u.uhunger >= 1500) { + if (u.uhunger >= 1500) { pline("You choke over your food."); pline("You die..."); killer = ftmp->oc_name; done("choked"); } - switch(otmp->otyp){ + switch (otmp->otyp) { case FOOD_RATION: - if(u.uhunger <= 200) + if (u.uhunger <= 200) pline("That food really hit the spot!"); - else if(u.uhunger <= 700) + else if (u.uhunger <= 700) pline("That satiated your stomach!"); else { - pline("You're having a hard time getting all that food down."); + pline("You're having a hard time getting all that food down."); multi -= 2; } lesshungry(ftmp->nutrition); - if(multi < 0) nomovemsg = "You finished your meal."; + if (multi < 0) + nomovemsg = "You finished your meal."; break; case TRIPE_RATION: pline("Yak - dog food!"); - more_experienced(1,0); + more_experienced(1, 0); flags.botl = 1; - if(rn2(2)){ + if (rn2(2)) { pline("You vomit."); morehungry(20); - if(Sick) { + if (Sick) { Sick = 0; /* David Neves */ pline("What a relief!"); } - } else lesshungry(ftmp->nutrition); + } else + lesshungry(ftmp->nutrition); break; default: - if(otmp->otyp >= CORPSE) - pline("That %s tasted terrible!",ftmp->oc_name); + if (otmp->otyp >= CORPSE) + pline("That %s tasted terrible!", ftmp->oc_name); else - pline("That %s was delicious!",ftmp->oc_name); + pline("That %s was delicious!", ftmp->oc_name); lesshungry(ftmp->nutrition); - if(otmp->otyp == DEAD_LIZARD && (Confusion > 2)) + if (otmp->otyp == DEAD_LIZARD && (Confusion > 2)) Confusion = 2; else #ifdef QUEST - if(otmp->otyp == CARROT && !Blind){ + if (otmp->otyp == CARROT && !Blind) { u.uhorizon++; setsee(); pline("Your vision improves."); } else #endif /* QUEST */ - if(otmp->otyp == FORTUNE_COOKIE) { - if(Blind) { - pline("This cookie has a scrap of paper inside!"); - pline("What a pity, that you cannot read it!"); - } else - outrumor(); - } else - if(otmp->otyp == LUMP_OF_ROYAL_JELLY) { + if (otmp->otyp == FORTUNE_COOKIE) { + if (Blind) { + pline("This cookie has a scrap of paper inside!"); + pline("What a pity, that you cannot read it!"); + } else + outrumor(); + } else if (otmp->otyp == LUMP_OF_ROYAL_JELLY) { /* This stuff seems to be VERY healthy! */ - if(u.ustrmax < 118) u.ustrmax++; - if(u.ustr < u.ustrmax) u.ustr++; + if (u.ustrmax < 118) + u.ustrmax++; + if (u.ustr < u.ustrmax) + u.ustr++; u.uhp += rnd(20); - if(u.uhp > u.uhpmax) { - if(!rn2(17)) u.uhpmax++; + if (u.uhp > u.uhpmax) { + if (!rn2(17)) + u.uhpmax++; u.uhp = u.uhpmax; } heal_legs(); @@ -258,14 +267,13 @@ gotit: } } eatx: - if(multi<0 && !nomovemsg){ + if (multi < 0 && !nomovemsg) { static char msgbuf[BUFSZ]; - sprintf(msgbuf, "You finished eating the %s.", - ftmp->oc_name); + sprintf(msgbuf, "You finished eating the %s.", ftmp->oc_name); nomovemsg = msgbuf; } useup(otmp); - return(1); + return (1); } /* called in hack.main.c */ @@ -273,16 +281,21 @@ void gethungry(void) { --u.uhunger; - if(moves % 2) { - if(Regeneration) u.uhunger--; - if(Hunger) u.uhunger--; - /* a3: if(Hunger & LEFT_RING) u.uhunger--; - if(Hunger & RIGHT_RING) u.uhunger--; - etc. */ + if (moves % 2) { + if (Regeneration) + u.uhunger--; + if (Hunger) + u.uhunger--; + /* a3: if (Hunger & LEFT_RING) u.uhunger--; + * if (Hunger & RIGHT_RING) u.uhunger--; + * etc. + */ } - if(moves % 20 == 0) { /* jimt@asgb */ - if(uleft) u.uhunger--; - if(uright) u.uhunger--; + if (moves % 20 == 0) { /* jimt@asgb */ + if (uleft) + u.uhunger--; + if (uright) + u.uhunger--; } newuhs(TRUE); } @@ -320,19 +333,18 @@ newuhs(bool incr) (h > 50) ? HUNGRY : (h > 0) ? WEAK : FAINTING; - if(newhs == FAINTING) { - if(u.uhs == FAINTED) + if (newhs == FAINTING) { + if (u.uhs == FAINTED) newhs = FAINTED; - if(u.uhs <= WEAK || rn2(20-u.uhunger/10) >= 19) { - if(u.uhs != FAINTED && multi >= 0 /* %% */) { + if (u.uhs <= WEAK || rn2(20 - u.uhunger / 10) >= 19) { + if (u.uhs != FAINTED && multi >= 0 /* %% */) { pline("You faint from lack of food."); - nomul(-10+(u.uhunger/10)); + nomul(-10 + (u.uhunger / 10)); nomovemsg = "You regain consciousness."; afternmv = unfaint; newhs = FAINTED; } - } else - if(u.uhunger < -(int)(200 + 25*u.ulevel)) { + } else if (u.uhunger < -(int)(200 + 25 * u.ulevel)) { u.uhs = STARVED; flags.botl = 1; bot(); @@ -341,27 +353,26 @@ newuhs(bool incr) } } - if(newhs != u.uhs) { - if(newhs >= WEAK && u.uhs < WEAK) + if (newhs != u.uhs) { + if (newhs >= WEAK && u.uhs < WEAK) losestr(1); /* this may kill you -- see below */ - else - if(newhs < WEAK && u.uhs >= WEAK && u.ustr < u.ustrmax) + else if (newhs < WEAK && u.uhs >= WEAK && u.ustr < u.ustrmax) losestr(-1); - switch(newhs){ + switch (newhs) { case HUNGRY: pline((!incr) ? "You only feel hungry now." : (u.uhunger < 145) ? "You feel hungry." : - "You are beginning to feel hungry."); + "You are beginning to feel hungry."); break; case WEAK: pline((!incr) ? "You feel weak now." : (u.uhunger < 45) ? "You feel weak." : - "You are beginning to feel weak."); + "You are beginning to feel weak."); break; } u.uhs = newhs; flags.botl = 1; - if(u.uhp < 1) { + if (u.uhp < 1) { pline("You die from hunger and exhaustion."); killer = "exhaustion"; done("starved"); @@ -369,41 +380,42 @@ newuhs(bool incr) } } -#define CORPSE_I_TO_C(otyp) (char) ((otyp >= DEAD_ACID_BLOB)\ - ? 'a' + (otyp - DEAD_ACID_BLOB)\ - : '@' + (otyp - DEAD_HUMAN)) +#define CORPSE_I_TO_C(otyp) (char)((otyp >= DEAD_ACID_BLOB)\ + ? 'a' + (otyp - DEAD_ACID_BLOB)\ + : '@' + (otyp - DEAD_HUMAN)) bool poisonous(struct obj *otmp) { - return(index(POISONOUS, CORPSE_I_TO_C(otmp->otyp)) != 0); + return (strchr(POISONOUS, CORPSE_I_TO_C(otmp->otyp)) != 0); } /* returns 1 if some text was printed */ static int eatcorpse(struct obj *otmp) { -char let = CORPSE_I_TO_C(otmp->otyp); -int tp = 0; - if(let != 'a' && moves > otmp->age + 50 + rn2(100)) { + char let = CORPSE_I_TO_C(otmp->otyp); + int tp = 0; + + if (let != 'a' && moves > otmp->age + 50 + rn2(100)) { tp++; pline("Ulch -- that meat was tainted!"); pline("You get very sick."); Sick = 10 + rn2(10); u.usick_cause = objects[otmp->otyp].oc_name; - } else if(index(POISONOUS, let) && rn2(5)){ + } else if (strchr(POISONOUS, let) && rn2(5)) { tp++; pline("Ecch -- that must have been poisonous!"); - if(!Poison_resistance){ + if (!Poison_resistance) { losestr(rnd(4)); losehp(rnd(15), "poisonous corpse"); } else pline("You don't seem affected by the poison."); - } else if(index("ELNOPQRUuxz", let) && rn2(5)){ + } else if (strchr("ELNOPQRUuxz", let) && rn2(5)) { tp++; pline("You feel sick."); losehp(rnd(8), "cadaver"); } - switch(let) { + switch (let) { case 'L': case 'N': case 't': @@ -415,29 +427,29 @@ int tp = 0; case 'n': u.uhp = u.uhpmax; flags.botl = 1; - /* fall into next case */ + /* fall into next case */ case '@': pline("You cannibal! You will be sorry for this!"); - /* not tp++; */ - /* fall into next case */ + /* not tp++; */ + /* fall into next case */ case 'd': Aggravate_monster |= INTRINSIC; break; case 'I': - if(!Invis) { - Invis = 50+rn2(100); - if(!See_invisible) + if (!Invis) { + Invis = 50 + rn2(100); + if (!See_invisible) newsym(u.ux, u.uy); } else { Invis |= INTRINSIC; See_invisible |= INTRINSIC; } - /* fall into next case */ + /* fall into next case */ case 'y': #ifdef QUEST u.uhorizon++; #endif /* QUEST */ - /* fall into next case */ + /* fall into next case */ case 'B': Confusion = 50; break; @@ -459,23 +471,23 @@ int tp = 0; pline("You turn to stone."); killer = "dead cockatrice"; done("died"); - /* NOTREACHED */ + /* NOTREACHED */ case 'a': - if(Stoned) { - pline("What a pity - you just destroyed a future piece of art!"); - tp++; - Stoned = 0; - } - break; + if (Stoned) { + pline("What a pity - you just destroyed a future piece of art!"); + tp++; + Stoned = 0; + } + break; case 'M': - pline("You cannot resist the temptation to mimic a treasure chest."); - tp++; - nomul(-30); - afternmv = Meatdone; - nomovemsg = "You now again prefer mimicking a human."; - u.usym = '$'; - prme(); - break; + pline("You cannot resist the temptation to mimic a treasure chest."); + tp++; + nomul(-30); + afternmv = Meatdone; + nomovemsg = "You now again prefer mimicking a human."; + u.usym = '$'; + prme(); + break; } - return(tp); + return (tp); } diff --git a/games/hack/hack.end.c b/games/hack/hack.end.c index db6b8d717f..6ba411cf0a 100644 --- a/games/hack/hack.end.c +++ b/games/hack/hack.end.c @@ -6,7 +6,7 @@ #include "hack.h" #define Sprintf (void) sprintf -#define newttentry() (struct toptenentry *) alloc(sizeof(struct toptenentry)) +#define newttentry() alloc(sizeof(struct toptenentry)) #define NAMSZ 8 #define DTHSZ 40 #define PERSMAX 1 @@ -36,15 +36,16 @@ static const char *ordin(int); xchar maxdlevel = 1; void -done1(__unused int unused) +done1(int unused __unused) { - signal(SIGINT,SIG_IGN); + signal(SIGINT, SIG_IGN); pline("Really quit?"); - if(readchar() != 'y') { - signal(SIGINT,done1); + if (readchar() != 'y') { + signal(SIGINT, done1); clrlin(); fflush(stdout); - if(multi > 0) nomul(0); + if (multi > 0) + nomul(0); return; } done("quit"); @@ -55,7 +56,7 @@ int done_stopprint; int done_hup; static void -done_intr(__unused int unused) +done_intr(int unused __unused) { done_stopprint++; signal(SIGINT, SIG_IGN); @@ -63,7 +64,7 @@ done_intr(__unused int unused) } static void -done_hangup(__unused int unused) +done_hangup(int unused __unused) { done_hup++; signal(SIGHUP, SIG_IGN); @@ -73,37 +74,44 @@ done_hangup(__unused int unused) void done_in_by(struct monst *mtmp) { -static char buf[BUFSZ]; + static char buf[BUFSZ]; + pline("You die ..."); - if(mtmp->data->mlet == ' '){ - Sprintf(buf, "the ghost of %s", (char *) mtmp->mextra); + if (mtmp->data->mlet == ' ') { + Sprintf(buf, "the ghost of %s", (char *)mtmp->mextra); killer = buf; - } else if(mtmp->mnamelth) { + } else if (mtmp->mnamelth) { Sprintf(buf, "%s called %s", mtmp->data->mname, NAME(mtmp)); killer = buf; - } else if(mtmp->minvis) { + } else if (mtmp->minvis) { Sprintf(buf, "invisible %s", mtmp->data->mname); killer = buf; - } else killer = mtmp->data->mname; + } else + killer = mtmp->data->mname; done("died"); } -/* called with arg "died", "drowned", "escaped", "quit", "choked", "panicked", - "burned", "starved" or "tricked" */ +/* + * called with arg "died", "drowned", "escaped", "quit", "choked", + * "panicked", "burned", "starved" or "tricked" + */ /* Be careful not to call panic from here! */ void done(const char *st1) { - #ifdef WIZARD - if(wizard && *st1 == 'd'){ + if (wizard && *st1 == 'd') { u.uswldtim = 0; - if(u.uhpmax < 0) u.uhpmax = 100; /* arbitrary */ + if (u.uhpmax < 0) /* arbitrary */ + u.uhpmax = 100; u.uhp = u.uhpmax; pline("For some reason you are still alive."); flags.move = 0; - if(multi > 0) multi = 0; else multi = -1; + if (multi > 0) + multi = 0; + else + multi = -1; flags.botl = 1; return; } @@ -111,42 +119,50 @@ done(const char *st1) signal(SIGINT, done_intr); signal(SIGQUIT, done_intr); signal(SIGHUP, done_hangup); - if(*st1 == 'q' && u.uhp < 1){ + if (*st1 == 'q' && u.uhp < 1) { st1 = "died"; killer = "quit while already on Charon's boat"; } - if(*st1 == 's') killer = "starvation"; else - if(*st1 == 'd' && st1[1] == 'r') killer = "drowning"; else - if(*st1 == 'p') killer = "panic"; else - if(*st1 == 't') killer = "trickery"; else - if(!index("bcd", *st1)) killer = st1; + if (*st1 == 's') + killer = "starvation"; + else if (*st1 == 'd' && st1[1] == 'r') + killer = "drowning"; + else if (*st1 == 'p') + killer = "panic"; + else if (*st1 == 't') + killer = "trickery"; + else if (!strchr("bcd", *st1)) + killer = st1; paybill(); clearlocks(); - if(flags.toplin == 1) more(); - if(index("bcds", *st1)){ + if (flags.toplin == 1) + more(); + if (strchr("bcds", *st1)) { #ifdef WIZARD - if(!wizard) + if (!wizard) #endif /* WIZARD */ - savebones(); - if(!flags.notombstone) + savebones(); + if (!flags.notombstone) outrip(); } - if(*st1 == 'c') killer = st1; /* after outrip() */ - settty(NULL); /* does a clear_screen() */ - if(!done_stopprint) + if (*st1 == 'c') /* after outrip() */ + killer = st1; + settty(NULL); /* does a clear_screen() */ + if (!done_stopprint) printf("Goodbye %s %s...\n\n", pl_character, plname); - { long int tmp; - tmp = u.ugold - u.ugold0; - if(tmp < 0) - tmp = 0; - if(*st1 == 'd' || *st1 == 'b') - tmp -= tmp/10; - u.urexp += tmp; - u.urexp += 50 * maxdlevel; - if(maxdlevel > 20) - u.urexp += 1000*((maxdlevel > 30) ? 10 : maxdlevel - 20); + { + long int tmp; + tmp = u.ugold - u.ugold0; + if (tmp < 0) + tmp = 0; + if (*st1 == 'd' || *st1 == 'b') + tmp -= tmp / 10; + u.urexp += tmp; + u.urexp += 50 * maxdlevel; + if (maxdlevel > 20) + u.urexp += 1000 * ((maxdlevel > 30) ? 10 : maxdlevel - 20); } - if(*st1 == 'e') { + if (*st1 == 'e') { struct monst *mtmp; struct obj *otmp; int i; @@ -156,70 +172,72 @@ done(const char *st1) killer = st1; keepdogs(); mtmp = mydogs; - if(mtmp) { - if(!done_stopprint) printf("You"); - while(mtmp) { - if(!done_stopprint) + if (mtmp) { + if (!done_stopprint) + printf("You"); + while (mtmp) { + if (!done_stopprint) printf(" and %s", monnam(mtmp)); - if(mtmp->mtame) + if (mtmp->mtame) u.urexp += mtmp->mhp; mtmp = mtmp->nmon; } - if(!done_stopprint) - printf("\nescaped from the dungeon with %ld points,\n", - u.urexp); - } else - if(!done_stopprint) - printf("You escaped from the dungeon with %ld points,\n", - u.urexp); - for(otmp = invent; otmp; otmp = otmp->nobj) { - if(otmp->olet == GEM_SYM){ + if (!done_stopprint) + printf("\nescaped from the dungeon with %ld points,\n", + u.urexp); + } else if (!done_stopprint) + printf("You escaped from the dungeon with %ld points,\n", + u.urexp); + for (otmp = invent; otmp; otmp = otmp->nobj) { + if (otmp->olet == GEM_SYM) { objects[otmp->otyp].oc_name_known = 1; - i = otmp->quan*objects[otmp->otyp].g_val; - if(i == 0) { + i = otmp->quan * objects[otmp->otyp].g_val; + if (i == 0) { worthlessct += otmp->quan; continue; } u.urexp += i; - if(!done_stopprint) - printf("\t%s (worth %d Zorkmids),\n", - doname(otmp), i); - } else if(otmp->olet == AMULET_SYM) { + if (!done_stopprint) + printf("\t%s (worth %d Zorkmids),\n", + doname(otmp), i); + } else if (otmp->olet == AMULET_SYM) { otmp->known = 1; i = (otmp->spe < 0) ? 2 : 5000; u.urexp += i; - if(!done_stopprint) - printf("\t%s (worth %d Zorkmids),\n", - doname(otmp), i); - if(otmp->spe >= 0) { + if (!done_stopprint) + printf("\t%s (worth %d Zorkmids),\n", + doname(otmp), i); + if (otmp->spe >= 0) { has_amulet = TRUE; killer = "escaped (with amulet)"; } } } - if(worthlessct) if(!done_stopprint) - printf("\t%u worthless piece%s of coloured glass,\n", - worthlessct, plur(worthlessct)); - if(has_amulet) u.urexp *= 2; - } else - if(!done_stopprint) - printf("You %s on dungeon level %d with %ld points,\n", - st1, dlevel, u.urexp); - if(!done_stopprint) - printf("and %ld piece%s of gold, after %ld move%s.\n", - u.ugold, plur(u.ugold), moves, plur(moves)); - if(!done_stopprint) - printf("You were level %u with a maximum of %d hit points when you %s.\n", - u.ulevel, u.uhpmax, st1); - if(*st1 == 'e' && !done_stopprint){ + if (worthlessct) + if (!done_stopprint) + printf("\t%u worthless piece%s of coloured glass,\n", + worthlessct, plur(worthlessct)); + if (has_amulet) + u.urexp *= 2; + } else if (!done_stopprint) + printf("You %s on dungeon level %d with %ld points,\n", + st1, dlevel, u.urexp); + if (!done_stopprint) + printf("and %ld piece%s of gold, after %ld move%s.\n", + u.ugold, plur(u.ugold), moves, plur(moves)); + if (!done_stopprint) + printf("You were level %u with a maximum of %d hit points when you %s.\n", + u.ulevel, u.uhpmax, st1); + if (*st1 == 'e' && !done_stopprint) { getret(); /* all those pieces of coloured glass ... */ cls(); } #ifdef WIZARD - if(!wizard) + if (!wizard) #endif /* WIZARD */ topten(); - if(done_stopprint) printf("\n\n"); + if (done_stopprint) + printf("\n\n"); exit(0); } @@ -235,20 +253,21 @@ topten(void) int sleepct = 300; FILE *rfile; int flg = 0; -#define HUP if(!done_hup) - while(link(recfile, reclock) == -1) { + +#define HUP if (!done_hup) + while (link(recfile, reclock) == -1) { HUP perror(reclock); - if(!sleepct--) { + if (!sleepct--) { HUP puts("I give up. Sorry."); HUP puts("Perhaps there is an old record_lock around?"); return; } HUP printf("Waiting for access to record file. (%d)\n", - sleepct); + sleepct); HUP fflush(stdout); sleep(1); } - if(!(rfile = fopen(recfile,"r"))){ + if (!(rfile = fopen(recfile, "r"))) { HUP puts("Cannot open record file!"); goto unlock; } @@ -271,111 +290,121 @@ topten(void) strcpy(t0->date, getdate()); /* assure minimum number of points */ - if(t0->points < POINTSMIN) + if (t0->points < POINTSMIN) t0->points = 0; t1 = tt_head = newttentry(); tprev = 0; /* rank0: -1 undefined, 0 not_on_list, n n_th on list */ - for(rank = 1; ; ) { - if(fscanf(rfile, "%6s %d %d %d %d %d %ld %c%c %[^,],%[^\n]", - t1->date, &t1->uid, - &t1->level, &t1->maxlvl, - &t1->hp, &t1->maxhp, &t1->points, - &t1->plchar, &t1->sex, t1->name, t1->death) != 11 - || t1->points < POINTSMIN) + for (rank = 1;;) { + if (fscanf(rfile, "%6s %d %d %d %d %d %ld %c%c %[^,],%[^\n]", + t1->date, &t1->uid, + &t1->level, &t1->maxlvl, + &t1->hp, &t1->maxhp, &t1->points, + &t1->plchar, &t1->sex, t1->name, t1->death) != 11 + || t1->points < POINTSMIN) t1->points = 0; - if(rank0 < 0 && t1->points < t0->points) { - rank0 = rank++; - if(tprev == 0) - tt_head = t0; - else - tprev->tt_next = t0; - t0->tt_next = t1; - occ_cnt--; - flg++; /* ask for a rewrite */ - } else - tprev = t1; - if(t1->points == 0) break; - if( + if (rank0 < 0 && t1->points < t0->points) { + rank0 = rank++; + if (tprev == 0) + tt_head = t0; + else + tprev->tt_next = t0; + t0->tt_next = t1; + occ_cnt--; + flg++; /* ask for a rewrite */ + } else + tprev = t1; + if (t1->points == 0) + break; + if ( #ifdef PERS_IS_UID - t1->uid == t0->uid && + t1->uid == t0->uid && #else - strncmp(t1->name, t0->name, NAMSZ) == 0 && + strncmp(t1->name, t0->name, NAMSZ) == 0 && #endif /* PERS_IS_UID */ - t1->plchar == t0->plchar && --occ_cnt <= 0){ - if(rank0 < 0){ - rank0 = 0; - rank1 = rank; - HUP printf("You didn't beat your previous score of %ld points.\n\n", - t1->points); + t1->plchar == t0->plchar && --occ_cnt <= 0) { + if (rank0 < 0) { + rank0 = 0; + rank1 = rank; + HUP printf("You didn't beat your previous score of %ld points.\n\n", + t1->points); + } + if (occ_cnt < 0) { + flg++; + continue; + } } - if(occ_cnt < 0){ - flg++; - continue; + if (rank <= ENTRYMAX) { + t1 = t1->tt_next = newttentry(); + rank++; + } + if (rank > ENTRYMAX) { + t1->points = 0; + break; } - } - if(rank <= ENTRYMAX){ - t1 = t1->tt_next = newttentry(); - rank++; - } - if(rank > ENTRYMAX){ - t1->points = 0; - break; - } } - if(flg) { /* rewrite record file */ + if (flg) { /* rewrite record file */ fclose(rfile); - if(!(rfile = fopen(recfile,"w"))){ + if (!(rfile = fopen(recfile, "w"))) { HUP puts("Cannot write record file\n"); goto unlock; } - if(!done_stopprint) if(rank0 > 0){ - if(rank0 <= 10) - puts("You made the top ten list!\n"); - else - printf("You reached the %d%s place on the top %d list.\n\n", - rank0, ordin(rank0), ENTRYMAX); - } + if (!done_stopprint) + if (rank0 > 0) { + if (rank0 <= 10) + puts("You made the top ten list!\n"); + else + printf("You reached the %d%s place on the top %d list.\n\n", + rank0, ordin(rank0), ENTRYMAX); + } } - if(rank0 == 0) rank0 = rank1; - if(rank0 <= 0) rank0 = rank; - if(!done_stopprint) outheader(); + if (rank0 == 0) + rank0 = rank1; + if (rank0 <= 0) + rank0 = rank; + if (!done_stopprint) + outheader(); t1 = tt_head; - for(rank = 1; t1->points != 0; rank++, t1 = t1->tt_next) { - if(flg) fprintf(rfile,"%6s %d %d %d %d %d %ld %c%c %s,%s\n", - t1->date, t1->uid, - t1->level, t1->maxlvl, - t1->hp, t1->maxhp, t1->points, - t1->plchar, t1->sex, t1->name, t1->death); - if(done_stopprint) continue; - if(rank > (int)flags.end_top && - (rank < rank0-(int)flags.end_around || rank > rank0+(int)flags.end_around) - && (!flags.end_own || + for (rank = 1; t1->points != 0; rank++, t1 = t1->tt_next) { + if (flg) + fprintf(rfile, "%6s %d %d %d %d %d %ld %c%c %s,%s\n", + t1->date, t1->uid, + t1->level, t1->maxlvl, + t1->hp, t1->maxhp, t1->points, + t1->plchar, t1->sex, t1->name, t1->death); + if (done_stopprint) + continue; + if (rank > (int)flags.end_top && + (rank < rank0 - (int)flags.end_around || rank > rank0 + + (int)flags.end_around) + && (!flags.end_own || #ifdef PERS_IS_UID - t1->uid != t0->uid )) + t1->uid != t0->uid)) #else - strncmp(t1->name, t0->name, NAMSZ))) + strncmp(t1->name, t0->name, NAMSZ))) #endif /* PERS_IS_UID */ - continue; - if(rank == rank0-(int)flags.end_around && - rank0 > (int)flags.end_top+(int)flags.end_around+1 && - !flags.end_own) - putchar('\n'); - if(rank != rank0) - outentry(rank, t1, 0); - else if(!rank1) - outentry(rank, t1, 1); - else { - int t0lth = outentry(0, t0, -1); - int t1lth = outentry(rank, t1, t0lth); - if(t1lth > t0lth) t0lth = t1lth; - outentry(0, t0, t0lth); - } + continue; + if (rank == rank0 - (int)flags.end_around && + rank0 > (int)flags.end_top + (int)flags.end_around + 1 && + !flags.end_own) + putchar('\n'); + if (rank != rank0) + outentry(rank, t1, 0); + else if (!rank1) + outentry(rank, t1, 1); + else { + int t0lth = outentry(0, t0, -1); + int t1lth = outentry(rank, t1, t0lth); + if (t1lth > t0lth) + t0lth = t1lth; + outentry(0, t0, t0lth); + } } - if(rank0 >= rank) if(!done_stopprint) - outentry(0, t0, 1); + if (rank0 >= rank) + if (!done_stopprint) + outentry(0, t0, 1); fclose(rfile); unlock: unlink(reclock); @@ -384,11 +413,13 @@ unlock: static void outheader(void) { -char linebuf[BUFSZ]; -char *bp; + char linebuf[BUFSZ]; + char *bp; + strcpy(linebuf, "Number Points Name"); bp = eos(linebuf); - while(bp < linebuf + COLNO - 9) *bp++ = ' '; + while (bp < linebuf + COLNO - 9) + *bp++ = ' '; strcpy(bp, "Hp [max]"); puts(linebuf); } @@ -397,94 +428,114 @@ char *bp; static int outentry(int rank, struct toptenentry *t1, int so) { -boolean quit = FALSE, dead = FALSE, starv = FALSE; -char linebuf[BUFSZ]; + boolean quit = FALSE, dead = FALSE, starv = FALSE; + char linebuf[BUFSZ]; + linebuf[0] = 0; - if(rank) Sprintf(eos(linebuf), "%3d", rank); - else Sprintf(eos(linebuf), " "); + if (rank) + Sprintf(eos(linebuf), "%3d", rank); + else + Sprintf(eos(linebuf), " "); Sprintf(eos(linebuf), " %6ld %8s", t1->points, t1->name); - if(t1->plchar == 'X') Sprintf(eos(linebuf), " "); - else Sprintf(eos(linebuf), "-%c ", t1->plchar); - if(!strncmp("escaped", t1->death, 7)) { - if(!strcmp(" (with amulet)", t1->death+7)) - Sprintf(eos(linebuf), "escaped the dungeon with amulet"); - else - Sprintf(eos(linebuf), "escaped the dungeon [max level %d]", - t1->maxlvl); + if (t1->plchar == 'X') + Sprintf(eos(linebuf), " "); + else + Sprintf(eos(linebuf), "-%c ", t1->plchar); + if (!strncmp("escaped", t1->death, 7)) { + if (!strcmp(" (with amulet)", t1->death + 7)) + Sprintf(eos(linebuf), "escaped the dungeon with amulet"); + else + Sprintf(eos(linebuf), "escaped the dungeon [max level %d]", + t1->maxlvl); } else { - if(!strncmp(t1->death,"quit",4)) { - quit = TRUE; - if(t1->maxhp < 3*t1->hp && t1->maxlvl < 4) - Sprintf(eos(linebuf), "cravenly gave up"); - else - Sprintf(eos(linebuf), "quit"); - } - else if(!strcmp(t1->death,"choked")) - Sprintf(eos(linebuf), "choked on %s food", - (t1->sex == 'F') ? "her" : "his"); - else if(!strncmp(t1->death,"starv",5)) - Sprintf(eos(linebuf), "starved to death"), starv = TRUE; - else Sprintf(eos(linebuf), "was killed"), dead = TRUE; - Sprintf(eos(linebuf), " on%s level %d", - (dead || starv) ? "" : " dungeon", t1->level); - if(t1->maxlvl != t1->level) - Sprintf(eos(linebuf), " [max %d]", t1->maxlvl); - if(quit && t1->death[4]) Sprintf(eos(linebuf), t1->death + 4); + if (!strncmp(t1->death, "quit", 4)) { + quit = TRUE; + if (t1->maxhp < 3 * t1->hp && t1->maxlvl < 4) + Sprintf(eos(linebuf), "cravenly gave up"); + else + Sprintf(eos(linebuf), "quit"); + } else if (!strcmp(t1->death, "choked")) { + Sprintf(eos(linebuf), "choked on %s food", + (t1->sex == 'F') ? "her" : "his"); + } else if (!strncmp(t1->death, "starv", 5)) { + Sprintf(eos(linebuf), "starved to death"); + starv = TRUE; + } else { + Sprintf(eos(linebuf), "was killed"); + dead = TRUE; + } + Sprintf(eos(linebuf), " on%s level %d", + (dead || starv) ? "" : " dungeon", t1->level); + if (t1->maxlvl != t1->level) + Sprintf(eos(linebuf), " [max %d]", t1->maxlvl); + if (quit && t1->death[4]) + Sprintf(eos(linebuf), t1->death + 4); + } + if (dead) { + Sprintf(eos(linebuf), " by %s%s", + (!strncmp(t1->death, "trick", 5) || + !strncmp(t1->death, "the ", 4)) + ? "" : + strchr(vowels, *t1->death) ? "an " : "a ", + t1->death); } - if(dead) Sprintf(eos(linebuf), " by %s%s", - (!strncmp(t1->death, "trick", 5) || !strncmp(t1->death, "the ", 4)) - ? "" : - index(vowels,*t1->death) ? "an " : "a ", - t1->death); Sprintf(eos(linebuf), "."); - if(t1->maxhp) { - char *bp = eos(linebuf); - char hpbuf[10]; - int hppos; - Sprintf(hpbuf, (t1->hp > 0) ? itoa(t1->hp) : "-"); - hppos = COLNO - 7 - strlen(hpbuf); - if(bp <= linebuf + hppos) { - while(bp < linebuf + hppos) *bp++ = ' '; - strcpy(bp, hpbuf); - Sprintf(eos(bp), " [%d]", t1->maxhp); - } + if (t1->maxhp) { + char *bp = eos(linebuf); + char hpbuf[10]; + int hppos; + + Sprintf(hpbuf, (t1->hp > 0) ? itoa(t1->hp) : "-"); + hppos = COLNO - 7 - strlen(hpbuf); + if (bp <= linebuf + hppos) { + while (bp < linebuf + hppos) + *bp++ = ' '; + strcpy(bp, hpbuf); + Sprintf(eos(bp), " [%d]", t1->maxhp); + } } - if(so == 0) puts(linebuf); - else if(so > 0) { - char *bp = eos(linebuf); - if(so >= COLNO) so = COLNO-1; - while(bp < linebuf + so) *bp++ = ' '; - *bp = 0; - standoutbeg(); - fputs(linebuf,stdout); - standoutend(); - putchar('\n'); + if (so == 0) + puts(linebuf); + else if (so > 0) { + char *bp = eos(linebuf); + if (so >= COLNO) + so = COLNO - 1; + while (bp < linebuf + so) + *bp++ = ' '; + *bp = 0; + standoutbeg(); + fputs(linebuf, stdout); + standoutend(); + putchar('\n'); } - return(strlen(linebuf)); + return (strlen(linebuf)); } static char * itoa(int a) { -static char buf[12]; - Sprintf(buf,"%d",a); - return(buf); + static char buf[12]; + + Sprintf(buf, "%d", a); + return (buf); } static const char * ordin(int n) { int d1 = n % 10; - return((d1==0 || d1>3 || n/10==1) ? "th" : (d1==1) ? "st" : - (d1==2) ? "nd" : "rd"); + + return ((d1 == 0 || d1 > 3 || n / 10 == 1) ? "th" : (d1 == 1) ? "st" : + (d1 == 2) ? "nd" : "rd"); } void clearlocks(void) { -int x; - signal(SIGHUP,SIG_IGN); - for(x = maxdlevel; x >= 0; x--) { + int x; + + signal(SIGHUP, SIG_IGN); + for (x = maxdlevel; x >= 0; x--) { glo(x); unlink(lock); /* not all levels need be present */ } @@ -492,7 +543,7 @@ int x; #ifdef NOSAVEONHANGUP void -hangup(__unused int unused) +hangup(int unused __unused) { signal(SIGINT, SIG_IGN); clearlocks(); @@ -503,15 +554,17 @@ hangup(__unused int unused) char * eos(char *s) { - while(*s) s++; - return(s); + while (*s) + s++; + return (s); } /* it is the callers responsibility to check that there is room for c */ void charcat(char *s, char c) { - while(*s) s++; + while (*s) + s++; *s++ = c; *s = 0; } @@ -544,27 +597,28 @@ prscore(int argc, char **argv) char *player0; #endif /* PERS_IS_UID */ - if(!(rfile = fopen(recfile,"r"))){ + if (!(rfile = fopen(recfile, "r"))) { puts("Cannot open record file!"); return; } - if(argc > 1 && !strncmp(argv[1], "-s", 2)){ - if(!argv[1][2]){ + if (argc > 1 && !strncmp(argv[1], "-s", 2)) { + if (!argv[1][2]) { argc--; argv++; - } else if(!argv[1][3] && index("CFKSTWX", argv[1][2])) { + } else if (!argv[1][3] && strchr("CFKSTWX", argv[1][2])) { argv[1]++; argv[1][0] = '-'; - } else argv[1] += 2; + } else + argv[1] += 2; } - if(argc <= 1){ + if (argc <= 1) { #ifdef PERS_IS_UID uid = getuid(); playerct = 0; #else player0 = plname; - if(!*player0) + if (!*player0) player0 = "hackplayer"; playerct = 1; players = &player0; @@ -573,90 +627,100 @@ prscore(int argc, char **argv) playerct = --argc; players = ++argv; } - if(outflg) putchar('\n'); + if (outflg) + putchar('\n'); t1 = tt_head = newttentry(); - for(rank = 1; ; rank++) { - if(fscanf(rfile, "%6s %d %d %d %d %d %ld %c%c %[^,],%[^\n]", - t1->date, &t1->uid, - &t1->level, &t1->maxlvl, - &t1->hp, &t1->maxhp, &t1->points, - &t1->plchar, &t1->sex, t1->name, t1->death) != 11) + for (rank = 1;; rank++) { + if (fscanf(rfile, "%6s %d %d %d %d %d %ld %c%c %[^,],%[^\n]", + t1->date, &t1->uid, + &t1->level, &t1->maxlvl, + &t1->hp, &t1->maxhp, &t1->points, + &t1->plchar, &t1->sex, t1->name, t1->death) != 11) t1->points = 0; - if(t1->points == 0) break; + if (t1->points == 0) + break; #ifdef PERS_IS_UID - if(!playerct && t1->uid == uid) - flg++; - else -#endif /* PERS_IS_UID */ - for(i = 0; i < playerct; i++){ - if(strcmp(players[i], "all") == 0 || - strncmp(t1->name, players[i], NAMSZ) == 0 || - (players[i][0] == '-' && - players[i][1] == t1->plchar && - players[i][2] == 0) || - (digit(players[i][0]) && rank <= atoi(players[i]))) + if (!playerct && t1->uid == uid) flg++; - } - t1 = t1->tt_next = newttentry(); + else +#endif /* PERS_IS_UID */ + for (i = 0; i < playerct; i++) { + if (strcmp(players[i], "all") == 0 || + strncmp(t1->name, players[i], NAMSZ) == 0 || + (players[i][0] == '-' && + players[i][1] == t1->plchar && + players[i][2] == 0) || + (digit(players[i][0]) && rank <= atoi(players[i]))) + flg++; + } + t1 = t1->tt_next = newttentry(); } fclose(rfile); - if(!flg) { - if(outflg) { - printf("Cannot find any entries for "); - if(playerct < 1) printf("you.\n"); - else { - if(playerct > 1) printf("any of "); - for(i=0; i 1) + printf("any of "); + for (i = 0; i < playerct; i++) + printf("%s%s", players[i], + (i < playerct - 1) ? ", " : ".\n"); + printf("Call is: %s -s [playernames]\n", hname); + } } - } - return; + return; } - if(outflg) outheader(); + if (outflg) + outheader(); t1 = tt_head; - for(rank = 1; t1->points != 0; rank++, t1 = t2) { + for (rank = 1; t1->points != 0; rank++, t1 = t2) { t2 = t1->tt_next; #ifdef PERS_IS_UID - if(!playerct && t1->uid == uid) + if (!playerct && t1->uid == uid) goto outwithit; else #endif /* PERS_IS_UID */ - for(i = 0; i < playerct; i++){ - if(strcmp(players[i], "all") == 0 || - strncmp(t1->name, players[i], NAMSZ) == 0 || - (players[i][0] == '-' && - players[i][1] == t1->plchar && - players[i][2] == 0) || - (digit(players[i][0]) && rank <= atoi(players[i]))){ - outwithit: - if(outflg) - outentry(rank, t1, 0); + for (i = 0; i < playerct; i++) { + if (strcmp(players[i], "all") == 0 || + strncmp(t1->name, players[i], NAMSZ) == 0 || + (players[i][0] == '-' && + players[i][1] == t1->plchar && + players[i][2] == 0) || + (digit(players[i][0]) && rank <= + atoi(players[i]))) { +outwithit: + if (outflg) + outentry(rank, t1, 0); #ifdef nonsense total_score += t1->points; - if(totcharct < sizeof(totchars)-1) - totchars[totcharct++] = t1->plchar; + if (totcharct < sizeof(totchars) - 1) + totchars[totcharct++] = t1->plchar; #endif /* nonsense */ break; } } - free((char *) t1); + free(t1); } #ifdef nonsense totchars[totcharct] = 0; - /* We would like to determine whether he is experienced. However, - the information collected here only tells about the scores/roles - that got into the topten (top 100?). We should maintain a - .hacklog or something in his home directory. */ + /* + * We would like to determine whether he is experienced. However, the + * information collected here only tells about the scores/roles that + * got into the topten (top 100?). We should maintain a .hacklog or + * something in his home directory. + */ flags.beginner = (total_score < 6000); - for(i=0; i<6; i++) - if(!index(totchars, "CFKSTWX"[i])) { - flags.beginner = 1; - if(!pl_character[0]) pl_character[0] = "CFKSTWX"[i]; - break; - } + for (i = 0; i < 6; i++) + if (!strchr(totchars, "CFKSTWX"[i])) { + flags.beginner = 1; + if (!pl_character[0]) + pl_character[0] = "CFKSTWX"[i]; + break; + } #endif /* nonsense */ } diff --git a/games/hack/hack.engrave.c b/games/hack/hack.engrave.c index 78674460a5..60776d3c6d 100644 --- a/games/hack/hack.engrave.c +++ b/games/hack/hack.engrave.c @@ -3,7 +3,7 @@ /* $FreeBSD: src/games/hack/hack.engrave.c,v 1.4 1999/11/16 02:57:04 billf Exp $ */ /* $DragonFly: src/games/hack/hack.engrave.c,v 1.4 2006/08/21 19:45:32 pavalos Exp $ */ -#include "hack.h" +#include "hack.h" extern char nul[]; extern struct obj zeroobj; @@ -19,91 +19,96 @@ struct engr { #define BURN 3 } *head_engr; -static struct engr *engr_at(xchar, xchar); -static void del_engr(struct engr *); +static struct engr *engr_at(xchar, xchar); +static void del_engr(struct engr *); static struct engr * engr_at(xchar x, xchar y) { -struct engr *ep = head_engr; - while(ep) { - if(x == ep->engr_x && y == ep->engr_y) + struct engr *ep = head_engr; + + while (ep) { + if (x == ep->engr_x && y == ep->engr_y) return(ep); ep = ep->nxt_engr; } - return(NULL); + return (NULL); } bool sengr_at(const char *s, xchar x, xchar y) { -struct engr *ep = engr_at(x,y); -char *t; -int n; - if(ep && ep->engr_time <= moves) { + struct engr *ep = engr_at(x, y); + char *t; + int n; + + if (ep && ep->engr_time <= moves) { t = ep->engr_txt; n = strlen(s); - while(*t) { - if(!strncmp(s,t,n)) return(1); + while (*t) { + if (!strncmp(s, t, n)) + return (1); t++; } } - return(0); + return (0); } void u_wipe_engr(int cnt) { - if(!u.uswallow && !Levitation) + if (!u.uswallow && !Levitation) wipe_engr_at(u.ux, u.uy, cnt); } void wipe_engr_at(xchar x, xchar y, xchar cnt) { -struct engr *ep = engr_at(x,y); -int lth,pos; -char ch; - if(ep){ - if((ep->engr_type != DUST) || Levitation) { - cnt = rn2(1 + 50/(cnt+1)) ? 0 : 1; - } + struct engr *ep = engr_at(x, y); + int lth, pos; + char ch; + + if (ep) { + if ((ep->engr_type != DUST) || Levitation) + cnt = rn2(1 + 50 / (cnt + 1)) ? 0 : 1; lth = strlen(ep->engr_txt); - if(lth && cnt > 0 ) { - while(cnt--) { + if (lth && cnt > 0) { + while (cnt--) { pos = rn2(lth); - if((ch = ep->engr_txt[pos]) == ' ') + if ((ch = ep->engr_txt[pos]) == ' ') continue; ep->engr_txt[pos] = (ch != '?') ? '?' : ' '; } } - while(lth && ep->engr_txt[lth-1] == ' ') + while (lth && ep->engr_txt[lth - 1] == ' ') ep->engr_txt[--lth] = 0; - while(ep->engr_txt[0] == ' ') + while (ep->engr_txt[0] == ' ') ep->engr_txt++; - if(!ep->engr_txt[0]) del_engr(ep); + if (!ep->engr_txt[0]) + del_engr(ep); } } void read_engr_at(int x, int y) { -struct engr *ep = engr_at(x,y); - if(ep && ep->engr_txt[0]) { - switch(ep->engr_type) { - case DUST: - pline("Something is written here in the dust."); - break; - case ENGRAVE: - pline("Something is engraved here on the floor."); - break; - case BURN: - pline("Some text has been burned here in the floor."); - break; - default: - impossible("Something is written in a very strange way."); - } - pline("You read: \"%s\".", ep->engr_txt); + struct engr *ep = engr_at(x, y); + + if (ep && ep->engr_txt[0]) { + switch (ep->engr_type) { + case DUST: + pline("Something is written here in the dust."); + break; + case ENGRAVE: + pline("Something is engraved here on the floor."); + break; + case BURN: + pline("Some text has been burned here in the floor."); + break; + default: + impossible("Something is written in a very strange way."); + } + pline("You read: \"%s\".", ep->engr_txt); } } @@ -112,10 +117,9 @@ make_engr_at(int x, int y, const char *s) { struct engr *ep; - if((ep = engr_at(x,y))) - del_engr(ep); - ep = (struct engr *) - alloc((unsigned)(sizeof(struct engr) + strlen(s) + 1)); + if ((ep = engr_at(x, y))) + del_engr(ep); + ep = alloc((unsigned)(sizeof(struct engr) + strlen(s) + 1)); ep->nxt_engr = head_engr; head_engr = ep; ep->engr_x = x; @@ -130,172 +134,184 @@ make_engr_at(int x, int y, const char *s) int doengrave(void) { -int len; -char *sp; -struct engr *ep, *oep = engr_at(u.ux,u.uy); -char buf[BUFSZ]; -xchar type; -int spct; /* number of leading spaces */ -struct obj *otmp; - multi = 0; + int len; + char *sp; + struct engr *ep, *oep = engr_at(u.ux, u.uy); + char buf[BUFSZ]; + xchar type; + int spct; /* number of leading spaces */ + struct obj *otmp; - if(u.uswallow) { + multi = 0; + if (u.uswallow) { pline("You're joking. Hahaha!"); /* riv05!a3 */ - return(0); + return (0); } /* one may write with finger, weapon or wand */ otmp = getobj("#-)/", "write with"); - if(!otmp) return(0); + if (!otmp) + return (0); - if(otmp == &zeroobj) + if (otmp == &zeroobj) otmp = 0; - if(otmp && otmp->otyp == WAN_FIRE && otmp->spe) { + if (otmp && otmp->otyp == WAN_FIRE && otmp->spe) { type = BURN; otmp->spe--; } else { /* first wield otmp */ - if(otmp != uwep) { - if(uwep && uwep->cursed) { - /* Andreas Bormann */ - pline("Since your weapon is welded to your hand,"); - pline("you use the %s.", aobjnam(uwep, NULL)); - otmp = uwep; + if (otmp != uwep) { + if (uwep && uwep->cursed) { + /* Andreas Bormann */ + pline("Since your weapon is welded to your hand,"); + pline("you use the %s.", aobjnam(uwep, NULL)); + otmp = uwep; } else { - if(!otmp) - pline("You are now empty-handed."); - else if(otmp->cursed) - pline("The %s %s to your hand!", - aobjnam(otmp, "weld"), - (otmp->quan == 1) ? "itself" : "themselves"); - else - pline("You now wield %s.", doname(otmp)); - setuwep(otmp); + if (!otmp) + pline("You are now empty-handed."); + else if (otmp->cursed) + pline("The %s %s to your hand!", + aobjnam(otmp, "weld"), + (otmp->quan == 1) ? "itself" : "themselves"); + else + pline("You now wield %s.", doname(otmp)); + setuwep(otmp); } } - if(!otmp) + if (!otmp) type = DUST; - else - if(otmp->otyp == DAGGER || otmp->otyp == TWO_HANDED_SWORD || - otmp->otyp == CRYSKNIFE || - otmp->otyp == LONG_SWORD || otmp->otyp == AXE) { + else if (otmp->otyp == DAGGER || otmp->otyp == TWO_HANDED_SWORD || + otmp->otyp == CRYSKNIFE || + otmp->otyp == LONG_SWORD || otmp->otyp == AXE) { type = ENGRAVE; - if((int)otmp->spe <= -3) { + if ((int)otmp->spe <= -3) { type = DUST; pline("Your %s too dull for engraving.", - aobjnam(otmp, "are")); - if(oep && oep->engr_type != DUST) return(1); + aobjnam(otmp, "are")); + if (oep && oep->engr_type != DUST) + return (1); } - } else type = DUST; + } else + type = DUST; } - if(Levitation && type != BURN){ /* riv05!a3 */ + if (Levitation && type != BURN) { /* riv05!a3 */ pline("You can't reach the floor!"); - return(1); + return (1); } - if(oep && oep->engr_type == DUST){ - pline("You wipe out the message that was written here."); - del_engr(oep); - oep = 0; + if (oep && oep->engr_type == DUST) { + pline("You wipe out the message that was written here."); + del_engr(oep); + oep = 0; } - if(type == DUST && oep){ - pline("You cannot wipe out the message that is %s in the rock.", - (oep->engr_type == BURN) ? "burned" : "engraved"); - return(1); + if (type == DUST && oep) { + pline("You cannot wipe out the message that is %s in the rock.", + (oep->engr_type == BURN) ? "burned" : "engraved"); + return (1); } pline("What do you want to %s on the floor here? ", - (type == ENGRAVE) ? "engrave" : (type == BURN) ? "burn" : "write"); + (type == ENGRAVE) ? "engrave" : (type == BURN) ? "burn" : "write"); getlin(buf); clrlin(); spct = 0; sp = buf; - while(*sp == ' ') spct++, sp++; + while (*sp == ' ') { + spct++; + sp++; + } len = strlen(sp); - if(!len || *buf == '\033') { - if(type == BURN) otmp->spe++; - return(0); + if (!len || *buf == '\033') { + if (type == BURN) + otmp->spe++; + return (0); } - switch(type) { + switch (type) { case DUST: case BURN: - if(len > 15) { - multi = -(len/10); + if (len > 15) { + multi = -(len / 10); nomovemsg = "You finished writing."; } break; case ENGRAVE: /* here otmp != 0 */ - { int len2 = (otmp->spe + 3) * 2 + 1; + { + int len2 = (otmp->spe + 3) * 2 + 1; pline("Your %s dull.", aobjnam(otmp, "get")); - if(len2 < len) { + if (len2 < len) { len = len2; sp[len] = 0; otmp->spe = -3; nomovemsg = "You cannot engrave more."; } else { - otmp->spe -= len/2; + otmp->spe -= len / 2; nomovemsg = "You finished engraving."; } multi = -len; } break; } - if(oep) len += strlen(oep->engr_txt) + spct; - ep = (struct engr *) alloc((unsigned)(sizeof(struct engr) + len + 1)); + if (oep) + len += strlen(oep->engr_txt) + spct; + ep = alloc((unsigned)(sizeof(struct engr) + len + 1)); ep->nxt_engr = head_engr; head_engr = ep; ep->engr_x = u.ux; ep->engr_y = u.uy; sp = (char *)(ep + 1); /* (char *)ep + sizeof(struct engr) */ ep->engr_txt = sp; - if(oep) { + if (oep) { strcpy(sp, oep->engr_txt); strcat(sp, buf); del_engr(oep); } else strcpy(sp, buf); - ep->engr_lth = len+1; + ep->engr_lth = len + 1; ep->engr_type = type; - ep->engr_time = moves-multi; + ep->engr_time = moves - multi; /* kludge to protect pline against excessively long texts */ - if(len > BUFSZ-20) sp[BUFSZ-20] = 0; + if (len > BUFSZ - 20) + sp[BUFSZ - 20] = 0; - return(1); + return (1); } void save_engravings(int fd) { -struct engr *ep = head_engr; - while(ep) { - if(!ep->engr_lth || !ep->engr_txt[0]){ + struct engr *ep = head_engr; + + while (ep) { + if (!ep->engr_lth || !ep->engr_txt[0]) { ep = ep->nxt_engr; continue; } - bwrite(fd, (char *) & (ep->engr_lth), sizeof(ep->engr_lth)); - bwrite(fd, (char *) ep, sizeof(struct engr) + ep->engr_lth); + bwrite(fd, (char *)&(ep->engr_lth), sizeof(ep->engr_lth)); + bwrite(fd, (char *)ep, sizeof(struct engr) + ep->engr_lth); ep = ep->nxt_engr; } - bwrite(fd, (char *) nul, sizeof(unsigned)); + bwrite(fd, (char *)nul, sizeof(unsigned)); head_engr = 0; } void rest_engravings(int fd) { -struct engr *ep; -unsigned lth; + struct engr *ep; + unsigned lth; + head_engr = 0; - while(1) { - mread(fd, (char *) <h, sizeof(unsigned)); - if(lth == 0) return; - ep = (struct engr *) alloc(sizeof(struct engr) + lth); - mread(fd, (char *) ep, sizeof(struct engr) + lth); + for (;;) { + mread(fd, (char *)<h, sizeof(unsigned)); + if (lth == 0) + return; + ep = alloc(sizeof(struct engr) + lth); + mread(fd, (char *)ep, sizeof(struct engr) + lth); ep->nxt_engr = head_engr; - ep->engr_txt = (char *) (ep + 1); /* Andreas Bormann */ + ep->engr_txt = (char *)(ep + 1); /* Andreas Bormann */ head_engr = ep; } } @@ -303,19 +319,20 @@ unsigned lth; static void del_engr(struct engr *ep) { -struct engr *ept; - if(ep == head_engr) + struct engr *ept; + + if (ep == head_engr) head_engr = ep->nxt_engr; else { - for(ept = head_engr; ept; ept = ept->nxt_engr) { - if(ept->nxt_engr == ep) { + for (ept = head_engr; ept; ept = ept->nxt_engr) { + if (ept->nxt_engr == ep) { ept->nxt_engr = ep->nxt_engr; goto fnd; } } impossible("Error in del_engr?"); return; - fnd: ; } - free((char *) ep); +fnd: + free(ep); } diff --git a/games/hack/hack.fight.c b/games/hack/hack.fight.c index 4f284d0f42..66fb57f74a 100644 --- a/games/hack/hack.fight.c +++ b/games/hack/hack.fight.c @@ -3,100 +3,111 @@ /* $FreeBSD: src/games/hack/hack.fight.c,v 1.5 1999/11/16 10:26:36 marcel Exp $ */ /* $DragonFly: src/games/hack/hack.fight.c,v 1.5 2006/08/21 19:45:32 pavalos Exp $ */ -#include "hack.h" +#include "hack.h" extern struct permonst li_dog, dog, la_dog; static boolean far_noise; static long noisetime; -static void monstone(struct monst *); +static void monstone(struct monst *); /* hitmm returns 0 (miss), 1 (hit), or 2 (kill) */ int hitmm(struct monst *magr, struct monst *mdef) { -struct permonst *pa = magr->data, *pd = mdef->data; -int ht; -schar tmp; -boolean vis; - if(index("Eauy", pa->mlet)) return(0); - if(magr->mfroz) return(0); /* riv05!a3 */ + struct permonst *pa = magr->data, *pd = mdef->data; + int ht; + schar tmp; + boolean vis; + + if (strchr("Eauy", pa->mlet)) + return (0); + if (magr->mfroz) /* riv05!a3 */ + return (0); tmp = pd->ac + pa->mlevel; - if(mdef->mconf || mdef->mfroz || mdef->msleep){ + if (mdef->mconf || mdef->mfroz || mdef->msleep) { tmp += 4; - if(mdef->msleep) mdef->msleep = 0; + if (mdef->msleep) + mdef->msleep = 0; } ht = (tmp > rnd(20)); - if(ht) mdef->msleep = 0; - vis = (cansee(magr->mx,magr->my) && cansee(mdef->mx,mdef->my)); - if(vis){ + if (ht) + mdef->msleep = 0; + vis = (cansee(magr->mx, magr->my) && cansee(mdef->mx, mdef->my)); + if (vis) { char buf[BUFSZ]; - if(mdef->mimic) seemimic(mdef); - if(magr->mimic) seemimic(magr); - sprintf(buf,"%s %s", Monnam(magr), + if (mdef->mimic) + seemimic(mdef); + if (magr->mimic) + seemimic(magr); + sprintf(buf, "%s %s", Monnam(magr), ht ? "hits" : "misses"); pline("%s %s.", buf, monnam(mdef)); } else { boolean far = (dist(magr->mx, magr->my) > 15); - if(far != far_noise || moves-noisetime > 10) { + if (far != far_noise || moves - noisetime > 10) { far_noise = far; noisetime = moves; pline("You hear some noises%s.", - far ? " in the distance" : ""); + far ? " in the distance" : ""); } } - if(ht){ - if(magr->data->mlet == 'c' && !magr->cham) { + if (ht) { + if (magr->data->mlet == 'c' && !magr->cham) { magr->mhpmax += 3; - if(vis) pline("%s is turned to stone!", Monnam(mdef)); - else if(mdef->mtame) - pline("You have a peculiarly sad feeling for a moment, then it passes."); + if (vis) + pline("%s is turned to stone!", Monnam(mdef)); + else if (mdef->mtame) + pline("You have a peculiarly sad feeling for a moment, then it passes."); monstone(mdef); ht = 2; - } else - if((mdef->mhp -= d(pa->damn,pa->damd)) < 1) { - magr->mhpmax += 1 + rn2(pd->mlevel+1); - if(magr->mtame && magr->mhpmax > 8*pa->mlevel){ - if(pa == &li_dog) magr->data = pa = &dog; - else if(pa == &dog) magr->data = pa = &la_dog; + } else if ((mdef->mhp -= d(pa->damn, pa->damd)) < 1) { + magr->mhpmax += 1 + rn2(pd->mlevel + 1); + if (magr->mtame && magr->mhpmax > 8 * pa->mlevel) { + if (pa == &li_dog) + magr->data = pa = &dog; + else if (pa == &dog) + magr->data = pa = &la_dog; } - if(vis) pline("%s is killed!", Monnam(mdef)); - else if(mdef->mtame) - pline("You have a sad feeling for a moment, then it passes."); + if (vis) + pline("%s is killed!", Monnam(mdef)); + else if (mdef->mtame) + pline("You have a sad feeling for a moment, then it passes."); mondied(mdef); ht = 2; } } - return(ht); + return (ht); } /* drop (perhaps) a cadaver and remove monster */ void mondied(struct monst *mdef) { -struct permonst *pd = mdef->data; - if(letter(pd->mlet) && rn2(3)){ - mkobj_at(pd->mlet,mdef->mx,mdef->my); - if(cansee(mdef->mx,mdef->my)){ - unpmon(mdef); - atl(mdef->mx,mdef->my,fobj->olet); - } - stackobj(fobj); + struct permonst *pd = mdef->data; + + if (letter(pd->mlet) && rn2(3)) { + mkobj_at(pd->mlet, mdef->mx, mdef->my); + if (cansee(mdef->mx, mdef->my)) { + unpmon(mdef); + atl(mdef->mx, mdef->my, fobj->olet); } - mondead(mdef); + stackobj(fobj); + } + mondead(mdef); } /* drop a rock and remove monster */ static void monstone(struct monst *mdef) { - if(index(mlarge, mdef->data->mlet)) + if (strchr(mlarge, mdef->data->mlet)) mksobj_at(ENORMOUS_ROCK, mdef->mx, mdef->my); else mksobj_at(ROCK, mdef->mx, mdef->my); - if(cansee(mdef->mx, mdef->my)){ + if (cansee(mdef->mx, mdef->my)) { unpmon(mdef); - atl(mdef->mx,mdef->my,fobj->olet); + atl(mdef->mx, mdef->my, fobj->olet); } mondead(mdef); } @@ -104,30 +115,38 @@ monstone(struct monst *mdef) int fightm(struct monst *mtmp) { -struct monst *mon; - for(mon = fmon; mon; mon = mon->nmon) if(mon != mtmp) { - if(DIST(mon->mx,mon->my,mtmp->mx,mtmp->my) < 3) - if(rn2(4)) - return(hitmm(mtmp,mon)); - } - return(-1); + struct monst *mon; + + for (mon = fmon; mon; mon = mon->nmon) + if (mon != mtmp) { + if (DIST(mon->mx, mon->my, mtmp->mx, mtmp->my) < 3) + if (rn2(4)) + return (hitmm(mtmp, mon)); + } + + return (-1); } /* u is hit by sth, but not a monster */ bool thitu(int tlev, int dam, const char *name) { -char buf[BUFSZ]; - setan(name,buf); - if(u.uac + tlev <= rnd(20)) { - if(Blind) pline("It misses."); - else pline("You are almost hit by %s!", buf); - return(0); + char buf[BUFSZ]; + + setan(name, buf); + if (u.uac + tlev <= rnd(20)) { + if (Blind) + pline("It misses."); + else + pline("You are almost hit by %s!", buf); + return (0); } else { - if(Blind) pline("You are hit!"); - else pline("You are hit by %s!", buf); - losehp(dam,name); - return(1); + if (Blind) + pline("You are hit!"); + else + pline("You are hit by %s!", buf); + losehp(dam, name); + return (1); } } @@ -140,114 +159,121 @@ hmon(struct monst *mon, struct obj *obj, int thrown) int tmp; bool hittxt = FALSE; - if(!obj){ + if (!obj) { tmp = rnd(2); /* attack with bare hands */ - if(mon->data->mlet == 'c' && !uarmg){ + if (mon->data->mlet == 'c' && !uarmg) { pline("You hit the cockatrice with your bare hands."); pline("You turn to stone ..."); done_in_by(mon); } - } else if(obj->olet == WEAPON_SYM || obj->otyp == PICK_AXE) { - if(obj == uwep && (obj->otyp > SPEAR || obj->otyp < BOOMERANG)) - tmp = rnd(2); - else { - if(index(mlarge, mon->data->mlet)) { - tmp = rnd(objects[obj->otyp].wldam); - if(obj->otyp == TWO_HANDED_SWORD) tmp += d(2,6); - else if(obj->otyp == FLAIL) tmp += rnd(4); - } else { - tmp = rnd(objects[obj->otyp].wsdam); - } - tmp += obj->spe; - if(!thrown && obj == uwep && obj->otyp == BOOMERANG - && !rn2(3)){ - pline("As you hit %s, the boomerang breaks into splinters.", - monnam(mon)); - freeinv(obj); - setworn(NULL, obj->owornmask); - obfree(obj, NULL); - tmp++; + } else if (obj->olet == WEAPON_SYM || obj->otyp == PICK_AXE) { + if (obj == uwep && (obj->otyp > SPEAR || obj->otyp < BOOMERANG)) + tmp = rnd(2); + else { + if (strchr(mlarge, mon->data->mlet)) { + tmp = rnd(objects[obj->otyp].wldam); + if (obj->otyp == TWO_HANDED_SWORD) + tmp += d(2, 6); + else if (obj->otyp == FLAIL) + tmp += rnd(4); + } else + tmp = rnd(objects[obj->otyp].wsdam); + tmp += obj->spe; + if (!thrown && obj == uwep && obj->otyp == BOOMERANG + && !rn2(3)) { + pline("As you hit %s, the boomerang breaks into splinters.", + monnam(mon)); + freeinv(obj); + setworn(NULL, obj->owornmask); + obfree(obj, NULL); + tmp++; + } } - } - if(mon->data->mlet == 'O' && obj->otyp == TWO_HANDED_SWORD && - !strcmp(ONAME(obj), "Orcrist")) - tmp += rnd(10); - } else switch(obj->otyp) { + if (mon->data->mlet == 'O' && obj->otyp == TWO_HANDED_SWORD && + !strcmp(ONAME(obj), "Orcrist")) + tmp += rnd(10); + } else + switch (obj->otyp) { case HEAVY_IRON_BALL: - tmp = rnd(25); break; + tmp = rnd(25); + break; case EXPENSIVE_CAMERA: - pline("You succeed in destroying your camera. Congratulations!"); + pline("You succeed in destroying your camera. Congratulations!"); freeinv(obj); - if(obj->owornmask) + if (obj->owornmask) setworn(NULL, obj->owornmask); obfree(obj, NULL); - return(TRUE); + return (TRUE); case DEAD_COCKATRICE: pline("You hit %s with the cockatrice corpse.", - monnam(mon)); - if(mon->data->mlet == 'c') { + monnam(mon)); + if (mon->data->mlet == 'c') { tmp = 1; hittxt = TRUE; break; } pline("%s is turned to stone!", Monnam(mon)); killed(mon); - return(FALSE); - case CLOVE_OF_GARLIC: /* no effect against demons */ - if(index(UNDEAD, mon->data->mlet)) + return (FALSE); + case CLOVE_OF_GARLIC: /* no effect against demons */ + if (strchr(UNDEAD, mon->data->mlet)) mon->mflee = 1; tmp = 1; break; default: /* non-weapons can damage because of their weight */ /* (but not too much) */ - tmp = obj->owt/10; - if(tmp < 1) tmp = 1; - else tmp = rnd(tmp); - if(tmp > 6) tmp = 6; + tmp = obj->owt / 10; + if (tmp < 1) + tmp = 1; + else + tmp = rnd(tmp); + if (tmp > 6) + tmp = 6; } /****** NOTE: perhaps obj is undefined!! (if !thrown && BOOMERANG) */ tmp += u.udaminc + dbon(); - if(u.uswallow) { - if((tmp -= u.uswldtim) <= 0) { + if (u.uswallow) { + if ((tmp -= u.uswldtim) <= 0) { pline("Your arms are no longer able to hit."); - return(TRUE); + return (TRUE); } } - if(tmp < 1) tmp = 1; + if (tmp < 1) + tmp = 1; mon->mhp -= tmp; - if(mon->mhp < 1) { + if (mon->mhp < 1) { killed(mon); - return(FALSE); + return (FALSE); } - if(mon->mtame && (!mon->mflee || mon->mfleetim)) { - mon->mflee = 1; /* Rick Richardson */ - mon->mfleetim += 10*rnd(tmp); + if (mon->mtame && (!mon->mflee || mon->mfleetim)) { + mon->mflee = 1; /* Rick Richardson */ + mon->mfleetim += 10 * rnd(tmp); } - if(!hittxt) { - if(thrown) + if (!hittxt) { + if (thrown) { /* this assumes that we cannot throw plural things */ - hit( xname(obj) /* or: objects[obj->otyp].oc_name */, - mon, exclam(tmp) ); - else if(Blind) + hit(xname(obj) /* or: objects[obj->otyp].oc_name */, + mon, exclam(tmp)); + } else if (Blind) pline("You hit it."); else pline("You hit %s%s", monnam(mon), exclam(tmp)); } - if(u.umconf && !thrown) { - if(!Blind) { + if (u.umconf && !thrown) { + if (!Blind) { pline("Your hands stop glowing blue."); - if(!mon->mfroz && !mon->msleep) - pline("%s appears confused.",Monnam(mon)); + if (!mon->mfroz && !mon->msleep) + pline("%s appears confused.", Monnam(mon)); } mon->mconf = 1; u.umconf = 0; } - return(TRUE); /* mon still alive */ + return (TRUE); /* mon still alive */ } /* try to attack; return FALSE if monster evaded */ @@ -258,19 +284,20 @@ attack(struct monst *mtmp) schar tmp; boolean malive = TRUE; struct permonst *mdat; - mdat = mtmp->data; + mdat = mtmp->data; u_wipe_engr(3); /* andrew@orca: prevent unlimited pick-axe attacks */ - if(mdat->mlet == 'L' && !mtmp->mfroz && !mtmp->msleep && - !mtmp->mconf && mtmp->mcansee && !rn2(7) && - (m_move(mtmp, 0) == 2 /* he died */ || /* he moved: */ - mtmp->mx != u.ux+u.dx || mtmp->my != u.uy+u.dy)) - return(FALSE); + if (mdat->mlet == 'L' && !mtmp->mfroz && !mtmp->msleep && + !mtmp->mconf && mtmp->mcansee && !rn2(7) && + (m_move(mtmp, 0) == 2 /* he died */ || /* he moved: */ + mtmp->mx != u.ux + u.dx || mtmp->my != u.uy + u.dy)) + return (FALSE); - if(mtmp->mimic){ - if(!u.ustuck && !mtmp->mflee) u.ustuck = mtmp; - switch(levl[u.ux+u.dx][u.uy+u.dy].scrsym){ + if (mtmp->mimic) { + if (!u.ustuck && !mtmp->mflee) + u.ustuck = mtmp; + switch (levl[u.ux + u.dx][u.uy + u.dy].scrsym) { case '+': pline("The door actually was a Mimic."); break; @@ -281,83 +308,97 @@ attack(struct monst *mtmp) pline("Wait! That's a Mimic!"); } wakeup(mtmp); /* clears mtmp->mimic */ - return(TRUE); + return (TRUE); } wakeup(mtmp); - if(mtmp->mhide && mtmp->mundetected){ + if (mtmp->mhide && mtmp->mundetected) { struct obj *obj; mtmp->mundetected = 0; - if((obj = o_at(mtmp->mx,mtmp->my)) && !Blind) + if ((obj = o_at(mtmp->mx, mtmp->my)) && !Blind) pline("Wait! There's a %s hiding under %s!", - mdat->mname, doname(obj)); - return(TRUE); + mdat->mname, doname(obj)); + return (TRUE); } tmp = u.uluck + u.ulevel + mdat->ac + abon(); - if(uwep) { - if(uwep->olet == WEAPON_SYM || uwep->otyp == PICK_AXE) + if (uwep) { + if (uwep->olet == WEAPON_SYM || uwep->otyp == PICK_AXE) tmp += uwep->spe; - if(uwep->otyp == TWO_HANDED_SWORD) tmp -= 1; - else if(uwep->otyp == DAGGER) tmp += 2; - else if(uwep->otyp == CRYSKNIFE) tmp += 3; - else if(uwep->otyp == SPEAR && - index("XDne", mdat->mlet)) tmp += 2; + if (uwep->otyp == TWO_HANDED_SWORD) + tmp -= 1; + else if (uwep->otyp == DAGGER) + tmp += 2; + else if (uwep->otyp == CRYSKNIFE) + tmp += 3; + else if (uwep->otyp == SPEAR && + strchr("XDne", mdat->mlet)) + tmp += 2; } - if(mtmp->msleep) { + if (mtmp->msleep) { mtmp->msleep = 0; tmp += 2; } - if(mtmp->mfroz) { + if (mtmp->mfroz) { tmp += 4; - if(!rn2(10)) mtmp->mfroz = 0; + if (!rn2(10)) + mtmp->mfroz = 0; } - if(mtmp->mflee) tmp += 2; - if(u.utrap) tmp -= 3; + if (mtmp->mflee) + tmp += 2; + if (u.utrap) + tmp -= 3; /* with a lot of luggage, your agility diminishes */ - tmp -= (inv_weight() + 40)/20; + tmp -= (inv_weight() + 40) / 20; - if(tmp <= rnd(20) && !u.uswallow){ - if(Blind) pline("You miss it."); - else pline("You miss %s.",monnam(mtmp)); + if (tmp <= rnd(20) && !u.uswallow) { + if (Blind) + pline("You miss it."); + else + pline("You miss %s.", monnam(mtmp)); } else { /* we hit the monster; be careful: it might die! */ - if((malive = hmon(mtmp,uwep,0)) == TRUE) { - /* monster still alive */ - if(!rn2(25) && mtmp->mhp < mtmp->mhpmax/2) { + if ((malive = hmon(mtmp, uwep, 0)) == TRUE) { + /* monster still alive */ + if (!rn2(25) && mtmp->mhp < mtmp->mhpmax / 2) { mtmp->mflee = 1; - if(!rn2(3)) mtmp->mfleetim = rnd(100); - if(u.ustuck == mtmp && !u.uswallow) + if (!rn2(3)) + mtmp->mfleetim = rnd(100); + if (u.ustuck == mtmp && !u.uswallow) u.ustuck = 0; } #ifndef NOWORM - if(mtmp->wormno) - cutworm(mtmp, u.ux+u.dx, u.uy+u.dy, + if (mtmp->wormno) + cutworm(mtmp, u.ux + u.dx, u.uy + u.dy, uwep ? uwep->otyp : 0); #endif /* NOWORM */ } - if(mdat->mlet == 'a') { - if(rn2(2)) { + if (mdat->mlet == 'a') { + if (rn2(2)) { pline("You are splashed by the blob's acid!"); losehp_m(rnd(6), mtmp); - if(!rn2(30)) corrode_armor(); + if (!rn2(30)) + corrode_armor(); } - if(!rn2(6)) corrode_weapon(); + if (!rn2(6)) + corrode_weapon(); } } - if(malive && mdat->mlet == 'E' && canseemon(mtmp) - && !mtmp->mcan && rn2(3)) { - if(mtmp->mcansee) { - pline("You are frozen by the floating eye's gaze!"); - nomul((u.ulevel > 6 || rn2(4)) ? rn1(20,-21) : -200); - } else { - pline("The blinded floating eye cannot defend itself."); - if(!rn2(500)) if((int)u.uluck > LUCKMIN) u.uluck--; - } + if (malive && mdat->mlet == 'E' && canseemon(mtmp) + && !mtmp->mcan && rn2(3)) { + if (mtmp->mcansee) { + pline("You are frozen by the floating eye's gaze!"); + nomul((u.ulevel > 6 || rn2(4)) ? rn1(20, -21) : -200); + } else { + pline("The blinded floating eye cannot defend itself."); + if (!rn2(500)) + if ((int)u.uluck > LUCKMIN) + u.uluck--; + } } - return(TRUE); + return (TRUE); } diff --git a/games/hack/hack.fix b/games/hack/hack.fix index 01e6460247..9e41c32630 100644 --- a/games/hack/hack.fix +++ b/games/hack/hack.fix @@ -1,8 +1,8 @@ /***** unido:net.games.hack / ab / 7:23 pm Sep 13, 1985*/ Recently hack (1.0.3) crashed with core dumps during some good games. -The crashes occured in the onbill-routine. After investigating the core -dump I found that the shopkeeper's bill was still to be paid. Normaly +The crashes occurred in the onbill-routine. After investigating the core +dump I found that the shopkeeper's bill was still to be paid. Normally if you leave a shop the bill will be cleared and onbill() would not check it. But under certain conditions you can leave a shop without clearing the bill. The conditions are: diff --git a/games/hack/hack.h b/games/hack/hack.h index df9f582c79..a18554f1d0 100644 --- a/games/hack/hack.h +++ b/games/hack/hack.h @@ -12,39 +12,35 @@ #include #include -/* FIXME */ -#define index strchr -#define rindex strrchr - -#include "def.objclass.h" +#include "def.objclass.h" typedef struct { - xchar x,y; + xchar x, y; } coord; -#include "def.monst.h" /* uses coord */ -#include "def.gold.h" -#include "def.trap.h" -#include "def.obj.h" -#include "def.flag.h" -#include "def.mkroom.h" -#include "def.wseg.h" +#include "def.monst.h" /* uses coord */ +#include "def.gold.h" +#include "def.trap.h" +#include "def.obj.h" +#include "def.flag.h" +#include "def.mkroom.h" +#include "def.wseg.h" #define plur(x) (((x) == 1) ? "" : "s") #define BUFSZ 256 /* for getlin buffers */ #define PL_NSIZ 32 /* name of player, ghost, shopkeeper */ -#include "def.rm.h" -#include "def.permonst.h" +#include "def.rm.h" +#include "def.permonst.h" extern xchar xdnstair, ydnstair, xupstair, yupstair; /* stairs up and down. */ -#define newstring(x) (char *) alloc((unsigned)(x)) +#define newstring(x) alloc((unsigned)(x)) #include "hack.onames.h" -#define ON 1 -#define OFF 0 +#define ON 1 +#define OFF 0 extern struct obj *invent, *uwep, *uarm, *uarm2, *uarmh, *uarms, *uarmg, *uleft, *uright, *fcobj; @@ -98,7 +94,7 @@ struct you { #define Confusion u.uprops[CONFUSION].p_flgs #define INVIS (LAST_RING+3) /* not a ring */ #define Invis u.uprops[INVIS].p_flgs -#define Invisible (Invis && !See_invisible) +#define Invisible (Invis && !See_invisible) #define GLIB (LAST_RING+4) /* not a ring */ #define Glib u.uprops[GLIB].p_flgs #define PUNISHED (LAST_RING+5) /* not a ring */ @@ -108,10 +104,10 @@ struct you { #define BLIND (LAST_RING+7) /* not a ring */ #define Blind u.uprops[BLIND].p_flgs #define WOUNDED_LEGS (LAST_RING+8) /* not a ring */ -#define Wounded_legs u.uprops[WOUNDED_LEGS].p_flgs -#define STONED (LAST_RING+9) /* not a ring */ -#define Stoned u.uprops[STONED].p_flgs -#define PROP(x) (x-RIN_ADORNMENT) /* convert ring to index in uprops */ +#define Wounded_legs u.uprops[WOUNDED_LEGS].p_flgs +#define STONED (LAST_RING+9) /* not a ring */ +#define Stoned u.uprops[STONED].p_flgs +#define PROP(x) (x-RIN_ADORNMENT) /* convert ring to index in uprops */ unsigned umconf:1; const char *usick_cause; struct prop uprops[LAST_RING+10]; @@ -119,11 +115,11 @@ struct you { unsigned uswallow:1; /* set if swallowed by a monster */ unsigned uswldtim:4; /* time you have been swallowed */ unsigned uhs:3; /* hunger state - see hack.eat.c */ - schar ustr,ustrmax; + schar ustr, ustrmax; schar udaminc; schar uac; - int uhp,uhpmax; - long int ugold,ugold0,uexp,urexp; + int uhp, uhpmax; + long int ugold, ugold0, uexp, urexp; int uhunger; /* refd only in eat.c and shk.c */ int uinvault; struct monst *ustuck; @@ -135,11 +131,11 @@ extern struct you u; extern const char *traps[]; extern char vowels[]; -extern xchar curx,cury; /* cursor location on screen */ +extern xchar curx, cury; /* cursor location on screen */ extern coord bhitpos; /* place where thrown weapon falls to the ground */ -extern xchar seehx,seelx,seehy,seely; /* where to see*/ +extern xchar seehx, seelx, seehy, seely; /* where to see*/ extern const char *save_cm, *killer, *nomovemsg; extern xchar dlevel, maxdlevel; /* dungeon level */ @@ -153,7 +149,7 @@ extern char lock[]; extern const char *occtxt; extern const char *hu_stat[]; -#define DIST(x1,y1,x2,y2) (((x1)-(x2))*((x1)-(x2)) + ((y1)-(y2))*((y1)-(y2))) +#define DIST(x1,y1,x2,y2) (((x1)-(x2))*((x1)-(x2)) + ((y1)-(y2))*((y1)-(y2))) #define PL_CSIZ 20 /* sizeof pl_character */ #define MAX_CARR_CAP 120 /* so that boulders can be heavier */ diff --git a/games/hack/hack.invent.c b/games/hack/hack.invent.c index e61f80bc38..c16f2e84b1 100644 --- a/games/hack/hack.invent.c +++ b/games/hack/hack.invent.c @@ -3,7 +3,7 @@ /* $FreeBSD: src/games/hack/hack.invent.c,v 1.4 1999/11/16 10:26:36 marcel Exp $ */ /* $DragonFly: src/games/hack/hack.invent.c,v 1.5 2006/08/21 19:45:32 pavalos Exp $ */ -#include "hack.h" +#include "hack.h" extern struct obj zeroobj; extern char quitchars[]; @@ -23,6 +23,7 @@ extern struct wseg *wsegs[32]; #define NOINVSYM '#' static int lastinvnr = 51; /* 0 ... 51 */ + static void assigninvlet(struct obj *otmp) { @@ -30,22 +31,31 @@ assigninvlet(struct obj *otmp) int i; struct obj *obj; - for(i = 0; i < 52; i++) inuse[i] = FALSE; - for(obj = invent; obj; obj = obj->nobj) if(obj != otmp) { - i = obj->invlet; - if('a' <= i && i <= 'z') inuse[i - 'a'] = TRUE; else - if('A' <= i && i <= 'Z') inuse[i - 'A' + 26] = TRUE; - if(i == otmp->invlet) otmp->invlet = 0; - } - if((i = otmp->invlet) && + for (i = 0; i < 52; i++) + inuse[i] = FALSE; + for (obj = invent; obj; obj = obj->nobj) + if (obj != otmp) { + i = obj->invlet; + if ('a' <= i && i <= 'z') + inuse[i - 'a'] = TRUE; + else if ('A' <= i && i <= 'Z') + inuse[i - 'A' + 26] = TRUE; + if (i == otmp->invlet) + otmp->invlet = 0; + } + if ((i = otmp->invlet) && (('a' <= i && i <= 'z') || ('A' <= i && i <= 'Z'))) return; - for(i = lastinvnr+1; i != lastinvnr; i++) { - if(i == 52) { i = -1; continue; } - if(!inuse[i]) break; + for (i = lastinvnr + 1; i != lastinvnr; i++) { + if (i == 52) { + i = -1; + continue; + } + if (!inuse[i]) + break; } otmp->invlet = (inuse[i] ? NOINVSYM : - (i < 26) ? ('a'+i) : ('A'+i-26)); + (i < 26) ? ('a' + i) : ('A' + i - 26)); lastinvnr = i; } @@ -55,51 +65,52 @@ addinv(struct obj *obj) struct obj *otmp; /* merge or attach to end of chain */ - if(!invent) { + if (!invent) { invent = obj; otmp = 0; } else - for(otmp = invent; /* otmp */; otmp = otmp->nobj) { - if(merged(otmp, obj, 0)) - return(otmp); - if(!otmp->nobj) { - otmp->nobj = obj; - break; + for (otmp = invent; /* otmp */; otmp = otmp->nobj) { + if (merged(otmp, obj, 0)) + return (otmp); + if (!otmp->nobj) { + otmp->nobj = obj; + break; + } } - } obj->nobj = 0; - if(flags.invlet_constant) { + if (flags.invlet_constant) { assigninvlet(obj); /* * The ordering of the chain is nowhere significant * so in case you prefer some other order than the * historical one, change the code below. */ - if(otmp) { /* find proper place in chain */ + if (otmp) { /* find proper place in chain */ otmp->nobj = 0; - if((invent->invlet ^ 040) > (obj->invlet ^ 040)) { + if ((invent->invlet ^ 040) > (obj->invlet ^ 040)) { obj->nobj = invent; invent = obj; } else - for(otmp = invent; ; otmp = otmp->nobj) { - if(!otmp->nobj || - (otmp->nobj->invlet ^ 040) > (obj->invlet ^ 040)){ - obj->nobj = otmp->nobj; - otmp->nobj = obj; - break; - } - } + for (otmp = invent;; otmp = otmp->nobj) { + if (!otmp->nobj || + (otmp->nobj->invlet ^ 040) > + (obj->invlet ^ 040)) { + obj->nobj = otmp->nobj; + otmp->nobj = obj; + break; + } + } } } - return(obj); + return (obj); } void useup(struct obj *obj) { - if(obj->quan > 1){ + if (obj->quan > 1) { obj->quan--; obj->owt = weight(obj); } else { @@ -114,11 +125,12 @@ freeinv(struct obj *obj) { struct obj *otmp; - if(obj == invent) + if (obj == invent) invent = invent->nobj; else { - for(otmp = invent; otmp->nobj != obj; otmp = otmp->nobj) - if(!otmp->nobj) panic("freeinv"); + for (otmp = invent; otmp->nobj != obj; otmp = otmp->nobj) + if (!otmp->nobj) + panic("freeinv"); otmp->nobj = obj->nobj; } } @@ -138,10 +150,12 @@ freeobj(struct obj *obj) { struct obj *otmp; - if(obj == fobj) fobj = fobj->nobj; + if (obj == fobj) + fobj = fobj->nobj; else { - for(otmp = fobj; otmp->nobj != obj; otmp = otmp->nobj) - if(!otmp) panic("error in freeobj"); + for (otmp = fobj; otmp->nobj != obj; otmp = otmp->nobj) + if (!otmp) + panic("error in freeobj"); otmp->nobj = obj->nobj; } } @@ -152,13 +166,15 @@ freegold(struct gold *gold) { struct gold *gtmp; - if(gold == fgold) fgold = gold->ngold; + if (gold == fgold) + fgold = gold->ngold; else { - for(gtmp = fgold; gtmp->ngold != gold; gtmp = gtmp->ngold) - if(!gtmp) panic("error in freegold"); + for (gtmp = fgold; gtmp->ngold != gold; gtmp = gtmp->ngold) + if (!gtmp) + panic("error in freegold"); gtmp->ngold = gold->ngold; } - free((char *) gold); + free(gold); } void @@ -166,13 +182,14 @@ deltrap(struct trap *trap) { struct trap *ttmp; - if(trap == ftrap) + if (trap == ftrap) ftrap = ftrap->ntrap; else { - for(ttmp = ftrap; ttmp->ntrap != trap; ttmp = ttmp->ntrap) ; + for (ttmp = ftrap; ttmp->ntrap != trap; ttmp = ttmp->ntrap) + ; /* nothing */ ttmp->ntrap = trap->ntrap; } - free((char *) trap); + free(trap); } struct wseg *m_atseg; @@ -186,20 +203,21 @@ m_at(int x, int y) #endif /* NOWORM */ m_atseg = 0; - for(mtmp = fmon; mtmp; mtmp = mtmp->nmon){ - if(mtmp->mx == x && mtmp->my == y) - return(mtmp); + for (mtmp = fmon; mtmp; mtmp = mtmp->nmon) { + if (mtmp->mx == x && mtmp->my == y) + return (mtmp); #ifndef NOWORM - if(mtmp->wormno){ - for(wtmp = wsegs[mtmp->wormno]; wtmp; wtmp = wtmp->nseg) - if(wtmp->wx == x && wtmp->wy == y){ - m_atseg = wtmp; - return(mtmp); - } + if (mtmp->wormno) { + for (wtmp = wsegs[mtmp->wormno]; wtmp; wtmp = wtmp->nseg) + if (wtmp->wx == x && wtmp->wy == y) { + m_atseg = wtmp; + return (mtmp); + } } + #endif /* NOWORM */ } - return(0); + return (0); } struct obj * @@ -207,9 +225,10 @@ o_at(int x, int y) { struct obj *otmp; - for(otmp = fobj; otmp; otmp = otmp->nobj) - if(otmp->ox == x && otmp->oy == y) return(otmp); - return(0); + for (otmp = fobj; otmp; otmp = otmp->nobj) + if (otmp->ox == x && otmp->oy == y) + return (otmp); + return (0); } struct obj * @@ -217,19 +236,21 @@ sobj_at(int n, int x, int y) { struct obj *otmp; - for(otmp = fobj; otmp; otmp = otmp->nobj) - if(otmp->ox == x && otmp->oy == y && otmp->otyp == n) - return(otmp); - return(0); + for (otmp = fobj; otmp; otmp = otmp->nobj) + if (otmp->ox == x && otmp->oy == y && otmp->otyp == n) + return (otmp); + return (0); } bool carried(struct obj *obj) { -struct obj *otmp; - for(otmp = invent; otmp; otmp = otmp->nobj) - if(otmp == obj) return(1); - return(0); + struct obj *otmp; + + for (otmp = invent; otmp; otmp = otmp->nobj) + if (otmp == obj) + return (1); + return (0); } bool @@ -237,42 +258,47 @@ carrying(int type) { struct obj *otmp; - for(otmp = invent; otmp; otmp = otmp->nobj) - if(otmp->otyp == type) - return(TRUE); - return(FALSE); + for (otmp = invent; otmp; otmp = otmp->nobj) + if (otmp->otyp == type) + return (TRUE); + return (FALSE); } struct obj * o_on(unsigned int id, struct obj *objchn) { - while(objchn) { - if(objchn->o_id == id) return(objchn); + while (objchn) { + if (objchn->o_id == id) + return (objchn); objchn = objchn->nobj; } - return(NULL); + return (NULL); } struct trap * t_at(int x, int y) { struct trap *trap = ftrap; - while(trap) { - if(trap->tx == x && trap->ty == y) return(trap); + + while (trap) { + if (trap->tx == x && trap->ty == y) + return (trap); trap = trap->ntrap; } - return(0); + return (0); } struct gold * g_at(int x, int y) { struct gold *gold = fgold; - while(gold) { - if(gold->gx == x && gold->gy == y) return(gold); + + while (gold) { + if (gold->gx == x && gold->gy == y) + return (gold); gold = gold->ngold; } - return(0); + return (0); } /* make dummy object structure containing gold - for temporary use only */ @@ -287,7 +313,7 @@ mkgoldobj(long q) u.ugold -= q; OGOLD(otmp) = q; flags.botl = 1; - return(otmp); + return (otmp); } /* @@ -300,7 +326,7 @@ struct obj * getobj(const char *let, const char *word) { struct obj *otmp; - char ilet,ilet1,ilet2; + char ilet, ilet1, ilet2; char buf[BUFSZ]; char lets[BUFSZ]; int foo = 0, foo2; @@ -312,44 +338,55 @@ getobj(const char *let, const char *word) xchar foox = 0; long cnt; - if(*let == '0') let++, allowcnt = 1; - if(*let == '$') let++, allowgold = TRUE; - if(*let == '#') let++, allowall = TRUE; - if(*let == '-') let++, allownone = TRUE; - if(allownone) *bp++ = '-'; - if(allowgold) *bp++ = '$'; - if(bp > buf && bp[-1] == '-') *bp++ = ' '; + if (*let == '0') + let++, allowcnt = 1; + if (*let == '$') + let++, allowgold = TRUE; + if (*let == '#') + let++, allowall = TRUE; + if (*let == '-') + let++, allownone = TRUE; + if (allownone) + *bp++ = '-'; + if (allowgold) + *bp++ = '$'; + if (bp > buf && bp[-1] == '-') + *bp++ = ' '; ilet = 'a'; - for(otmp = invent; otmp; otmp = otmp->nobj){ - if(!*let || index(let, otmp->olet)) { - bp[foo++] = flags.invlet_constant ? otmp->invlet : ilet; - - /* ugly check: remove inappropriate things */ - if((!strcmp(word, "take off") && - !(otmp->owornmask & (W_ARMOR - W_ARM2))) - || (!strcmp(word, "wear") && - (otmp->owornmask & (W_ARMOR | W_RING))) - || (!strcmp(word, "wield") && - (otmp->owornmask & W_WEP))) { - foo--; - foox++; + for (otmp = invent; otmp; otmp = otmp->nobj) { + if (!*let || strchr(let, otmp->olet)) { + bp[foo++] = flags.invlet_constant ? otmp->invlet : ilet; + + /* ugly check: remove inappropriate things */ + if ((!strcmp(word, "take off") && + !(otmp->owornmask & (W_ARMOR - W_ARM2))) + || (!strcmp(word, "wear") && + (otmp->owornmask & (W_ARMOR | W_RING))) + || (!strcmp(word, "wield") && + (otmp->owornmask & W_WEP))) { + foo--; + foox++; + } } - } - if(ilet == 'z') ilet = 'A'; else ilet++; + if (ilet == 'z') + ilet = 'A'; + else + ilet++; } bp[foo] = 0; - if(foo == 0 && bp > buf && bp[-1] == ' ') *--bp = 0; + if (foo == 0 && bp > buf && bp[-1] == ' ') + *--bp = 0; strcpy(lets, bp); /* necessary since we destroy buf */ - if(foo > 5) { /* compactify string */ + if (foo > 5) { /* compactify string */ foo = foo2 = 1; ilet2 = bp[0]; ilet1 = bp[1]; - while((ilet = bp[++foo2] = bp[++foo])){ - if(ilet == ilet1+1){ - if(ilet1 == ilet2+1) + while ((ilet = bp[++foo2] = bp[++foo])) { + if (ilet == ilet1 + 1) { + if (ilet1 == ilet2 + 1) bp[foo2 - 1] = ilet1 = '-'; - else if(ilet2 == '-') { + else if (ilet2 == '-') { bp[--foo2] = ++ilet1; continue; } @@ -358,94 +395,100 @@ getobj(const char *let, const char *word) ilet1 = ilet; } } - if(!foo && !allowall && !allowgold && !allownone) { + if (!foo && !allowall && !allowgold && !allownone) { pline("You don't have anything %sto %s.", - foox ? "else " : "", word); - return(0); + foox ? "else " : "", word); + return (0); } - for(;;) { - if(!buf[0]) + for (;;) { + if (!buf[0]) pline("What do you want to %s [*]? ", word); else pline("What do you want to %s [%s or ?*]? ", - word, buf); + word, buf); cnt = 0; ilet = readchar(); - while(digit(ilet) && allowcnt) { + while (digit(ilet) && allowcnt) { if (cnt < 100000000) - cnt = 10*cnt + (ilet - '0'); + cnt = 10 * cnt + (ilet - '0'); else - cnt = 999999999; + cnt = 999999999; allowcnt = 2; /* signal presence of cnt */ ilet = readchar(); } - if(digit(ilet)) { + if (digit(ilet)) { pline("No count allowed with this command."); continue; } - if(index(quitchars,ilet)) - return(NULL); - if(ilet == '-') { - return(allownone ? &zeroobj : NULL); - } - if(ilet == '$') { - if(!allowgold){ + if (strchr(quitchars, ilet)) + return (NULL); + if (ilet == '-') + return (allownone ? &zeroobj : NULL); + if (ilet == '$') { + if (!allowgold) { pline("You cannot %s gold.", word); continue; } - if(!(allowcnt == 2 && cnt < u.ugold)) + if (!(allowcnt == 2 && cnt < u.ugold)) cnt = u.ugold; - return(mkgoldobj(cnt)); + return (mkgoldobj(cnt)); } - if(ilet == '?') { + if (ilet == '?') { doinv(lets); - if(!(ilet = morc)) continue; + if (!(ilet = morc)) + continue; /* he typed a letter (not a space) to more() */ - } else if(ilet == '*') { + } else if (ilet == '*') { doinv(NULL); - if(!(ilet = morc)) continue; + if (!(ilet = morc)) + continue; /* ... */ } - if(flags.invlet_constant) { - for(otmp = invent; otmp; otmp = otmp->nobj) - if(otmp->invlet == ilet) break; + if (flags.invlet_constant) { + for (otmp = invent; otmp; otmp = otmp->nobj) + if (otmp->invlet == ilet) + break; } else { - if(ilet >= 'A' && ilet <= 'Z') ilet += 'z'-'A'+1; + if (ilet >= 'A' && ilet <= 'Z') + ilet += 'z' - 'A' + 1; ilet -= 'a'; - for(otmp = invent; otmp && ilet; - ilet--, otmp = otmp->nobj) ; + for (otmp = invent; otmp && ilet; + ilet--, otmp = otmp->nobj) + ; /* nothing */ } - if(!otmp) { + if (!otmp) { pline("You don't have that object."); continue; } - if(cnt < 0 || otmp->quan < cnt) { - pline("You don't have that many! [You have %u]" - , otmp->quan); + if (cnt < 0 || otmp->quan < cnt) { + pline("You don't have that many! [You have %u]" , + otmp->quan); continue; } break; } - if(!allowall && let && !index(let,otmp->olet)) { - pline("That is a silly thing to %s.",word); - return(0); + if (!allowall && let && !strchr(let, otmp->olet)) { + pline("That is a silly thing to %s.", word); + return (0); } - if(allowcnt == 2) { /* cnt given */ - if(cnt == 0) return(0); - if(cnt != otmp->quan) { + if (allowcnt == 2) { /* cnt given */ + if (cnt == 0) + return (0); + if (cnt != otmp->quan) { struct obj *obj; - obj = splitobj(otmp, (int) cnt); - if(otmp == uwep) setuwep(obj); + obj = splitobj(otmp, (int)cnt); + if (otmp == uwep) + setuwep(obj); } } - return(otmp); + return (otmp); } static bool ckunpaid(struct obj *otmp) { - return( otmp->unpaid ); + return (otmp->unpaid); } /* interactive version of getobj - used for Drop and Identify */ @@ -453,68 +496,75 @@ ckunpaid(struct obj *otmp) int ggetobj(const char *word, int (*fn)(struct obj *), int max) { -char buf[BUFSZ]; -char *ip; -char sym; -int oletct = 0, iletct = 0; -boolean allflag = FALSE; -char olets[20], ilets[20]; -bool (*ckfn)(struct obj *) = (bool (*)()) 0; -xchar allowgold = (u.ugold && !strcmp(word, "drop")) ? 1 : 0; /* BAH */ - if(!invent && !allowgold){ + char buf[BUFSZ]; + char *ip; + char sym; + int oletct = 0, iletct = 0; + boolean allflag = FALSE; + char olets[20], ilets[20]; + bool (*ckfn)(struct obj *) = (bool (*)()) 0; + xchar allowgold = (u.ugold && !strcmp(word, "drop")) ? 1 : 0; /* BAH */ + + if (!invent && !allowgold) { pline("You have nothing to %s.", word); - return(0); + return (0); } else { struct obj *otmp = invent; int uflg = 0; - if(allowgold) ilets[iletct++] = '$'; + if (allowgold) + ilets[iletct++] = '$'; ilets[iletct] = 0; - while(otmp) { - if(!index(ilets, otmp->olet)){ + while (otmp) { + if (!strchr(ilets, otmp->olet)) { ilets[iletct++] = otmp->olet; ilets[iletct] = 0; } - if(otmp->unpaid) uflg = 1; + if (otmp->unpaid) + uflg = 1; otmp = otmp->nobj; } ilets[iletct++] = ' '; - if(uflg) ilets[iletct++] = 'u'; - if(invent) ilets[iletct++] = 'a'; + if (uflg) + ilets[iletct++] = 'u'; + if (invent) + ilets[iletct++] = 'a'; ilets[iletct] = 0; } pline("What kinds of thing do you want to %s? [%s] ", - word, ilets); + word, ilets); getlin(buf); - if(buf[0] == '\033') { + if (buf[0] == '\033') { clrlin(); - return(0); + return (0); } ip = buf; olets[0] = 0; - while((sym = *ip++)){ - if(sym == ' ') continue; - if(sym == '$') { - if(allowgold == 1) + while ((sym = *ip++)) { + if (sym == ' ') + continue; + if (sym == '$') { + if (allowgold == 1) (*fn)(mkgoldobj(u.ugold)); - else if(!u.ugold) + else if (!u.ugold) pline("You have no gold."); allowgold = 2; - } else - if(sym == 'a' || sym == 'A') allflag = TRUE; else - if(sym == 'u' || sym == 'U') ckfn = ckunpaid; else - if(index("!%?[()=*/\"0", sym)){ - if(!index(olets, sym)){ + } else if (sym == 'a' || sym == 'A') + allflag = TRUE; + else if (sym == 'u' || sym == 'U') + ckfn = ckunpaid; + else if (strchr("!%?[()=*/\"0", sym)) { + if (!strchr(olets, sym)) { olets[oletct++] = sym; olets[oletct] = 0; } - } - else pline("You don't have any %c's.", sym); + } else + pline("You don't have any %c's.", sym); } - if(allowgold == 2 && !oletct) - return(1); /* he dropped gold (or at least tried to) */ + if (allowgold == 2 && !oletct) + return (1); /* he dropped gold (or at least tried to) */ else - return(askchain(invent, olets, allflag, fn, ckfn, max)); + return (askchain(invent, olets, allflag, fn, ckfn, max)); } /* @@ -526,30 +576,37 @@ xchar allowgold = (u.ugold && !strcmp(word, "drop")) ? 1 : 0; /* BAH */ */ int askchain(struct obj *objchn, char *olets, int allflag, - int (*fn)(struct obj *), bool (*ckfn)(struct obj *), int max) -{ -struct obj *otmp, *otmp2; -char sym, ilet; -int cnt = 0; - ilet = 'a'-1; - for(otmp = objchn; otmp; otmp = otmp2){ - if(ilet == 'z') ilet = 'A'; else ilet++; + int (*fn)(struct obj *), bool (*ckfn)(struct obj *), int max) +{ + struct obj *otmp, *otmp2; + char sym, ilet; + int cnt = 0; + + ilet = 'a' - 1; + for (otmp = objchn; otmp; otmp = otmp2) { + if (ilet == 'z') + ilet = 'A'; + else + ilet++; otmp2 = otmp->nobj; - if(olets && *olets && !index(olets, otmp->olet)) continue; - if(ckfn && !(*ckfn)(otmp)) continue; - if(!allflag) { + if (olets && *olets && !strchr(olets, otmp->olet)) + continue; + if (ckfn && !(*ckfn)(otmp)) + continue; + if (!allflag) { pline(xprname(otmp, ilet)); addtopl(" [nyaq]? "); sym = readchar(); - } - else sym = 'y'; + } else + sym = 'y'; - switch(sym){ + switch (sym) { case 'a': allflag = 1; case 'y': cnt += (*fn)(otmp); - if(--max == 0) goto ret; + if (--max == 0) + goto ret; case 'n': default: break; @@ -559,7 +616,7 @@ int cnt = 0; } pline(cnt ? "That was all." : "No applicable objects."); ret: - return(cnt); + return (cnt); } /* should of course only be called for things in invent */ @@ -569,12 +626,13 @@ obj_to_let(struct obj *obj) struct obj *otmp; char ilet; - if(flags.invlet_constant) - return(obj->invlet); + if (flags.invlet_constant) + return (obj->invlet); ilet = 'a'; - for(otmp = invent; otmp && otmp != obj; otmp = otmp->nobj) - if(++ilet > 'z') ilet = 'A'; - return(otmp ? ilet : NOINVSYM); + for (otmp = invent; otmp && otmp != obj; otmp = otmp->nobj) + if (++ilet > 'z') + ilet = 'A'; + return (otmp ? ilet : NOINVSYM); } void @@ -591,14 +649,14 @@ xprname(struct obj *obj, char let) sprintf(li, "%c - %s.", flags.invlet_constant ? obj->invlet : let, doname(obj)); - return(li); + return (li); } int ddoinv(void) { doinv(NULL); - return(0); + return (0); } /* called with 0 or "": all objects in inventory */ @@ -612,21 +670,23 @@ doinv(char *lets) char any[BUFSZ]; morc = 0; /* just to be sure */ - - if(!invent){ + if (!invent) { pline("Not carrying anything."); return; } cornline(0, NULL); ilet = 'a'; - for(otmp = invent; otmp; otmp = otmp->nobj) { - if(flags.invlet_constant) ilet = otmp->invlet; - if(!lets || !*lets || index(lets, ilet)) { - cornline(1, xprname(otmp, ilet)); - any[ct++] = ilet; - } - if(!flags.invlet_constant) if(++ilet > 'z') ilet = 'A'; + for (otmp = invent; otmp; otmp = otmp->nobj) { + if (flags.invlet_constant) + ilet = otmp->invlet; + if (!lets || !*lets || strchr(lets, ilet)) { + cornline(1, xprname(otmp, ilet)); + any[ct++] = ilet; + } + if (!flags.invlet_constant) + if (++ilet > 'z') + ilet = 'A'; } any[ct] = 0; cornline(2, any); @@ -634,164 +694,175 @@ doinv(char *lets) int dotypeinv(void) /* free after Robert Viduya */ -/* Changed to one type only, so he doesnt have to type cr */ { - char c, ilet; - char stuff[BUFSZ]; - int stct; - struct obj *otmp; - boolean billx = inshop() && doinvbill(0); - boolean unpd = FALSE; + /* Changed to one type only, so he doesnt have to type cr */ + char c, ilet; + char stuff[BUFSZ]; + int stct; + struct obj *otmp; + boolean billx = inshop() && doinvbill(0); + boolean unpd = FALSE; if (!invent && !u.ugold && !billx) { - pline ("You aren't carrying anything."); - return(0); + pline("You aren't carrying anything."); + return (0); } stct = 0; - if(u.ugold) stuff[stct++] = '$'; + if (u.ugold) + stuff[stct++] = '$'; stuff[stct] = 0; - for(otmp = invent; otmp; otmp = otmp->nobj) { - if (!index (stuff, otmp->olet)) { - stuff[stct++] = otmp->olet; - stuff[stct] = 0; - } - if(otmp->unpaid) - unpd = TRUE; - } - if(unpd) stuff[stct++] = 'u'; - if(billx) stuff[stct++] = 'x'; + for (otmp = invent; otmp; otmp = otmp->nobj) { + if (!strchr(stuff, otmp->olet)) { + stuff[stct++] = otmp->olet; + stuff[stct] = 0; + } + if (otmp->unpaid) + unpd = TRUE; + } + if (unpd) + stuff[stct++] = 'u'; + if (billx) + stuff[stct++] = 'x'; stuff[stct] = 0; - if(stct > 1) { - pline ("What type of object [%s] do you want an inventory of? ", - stuff); - c = readchar(); - if(index(quitchars,c)) return(0); + if (stct > 1) { + pline("What type of object [%s] do you want an inventory of? ", + stuff); + c = readchar(); + if (strchr(quitchars, c)) + return (0); } else - c = stuff[0]; + c = stuff[0]; - if(c == '$') - return(doprgold()); + if (c == '$') + return (doprgold()); - if(c == 'x' || c == 'X') { - if(billx) - doinvbill(1); - else - pline("No used-up objects on the shopping bill."); - return(0); + if (c == 'x' || c == 'X') { + if (billx) + doinvbill(1); + else + pline("No used-up objects on the shopping bill."); + return (0); } - if((c == 'u' || c == 'U') && !unpd) { + if ((c == 'u' || c == 'U') && !unpd) { pline("You are not carrying any unpaid objects."); - return(0); + return (0); } stct = 0; ilet = 'a'; - for (otmp = invent; otmp; otmp = otmp -> nobj) { - if(flags.invlet_constant) ilet = otmp->invlet; - if (c == otmp -> olet || (c == 'u' && otmp -> unpaid)) - stuff[stct++] = ilet; - if(!flags.invlet_constant) if(++ilet > 'z') ilet = 'A'; + for (otmp = invent; otmp; otmp = otmp->nobj) { + if (flags.invlet_constant) + ilet = otmp->invlet; + if (c == otmp->olet || (c == 'u' && otmp->unpaid)) + stuff[stct++] = ilet; + if (!flags.invlet_constant) + if (++ilet > 'z') + ilet = 'A'; } stuff[stct] = '\0'; - if(stct == 0) + if (stct == 0) pline("You have no such objects."); else - doinv (stuff); + doinv(stuff); - return(0); + return (0); } /* look at what is here */ int dolook(void) { - struct obj *otmp, *otmp0 = NULL; - struct gold *gold = NULL; - const char *verb = Blind ? "feel" : "see"; - int ct = 0; - - if(!u.uswallow) { - if(Blind) { - pline("You try to feel what is lying here on the floor."); - if(Levitation) { /* ab@unido */ - pline("You cannot reach the floor!"); - return(1); - } - } - otmp0 = o_at(u.ux, u.uy); - gold = g_at(u.ux, u.uy); - } - - if(u.uswallow || (!otmp0 && !gold)) { - pline("You %s no objects here.", verb); - return(!!Blind); - } - - cornline(0, "Things that are here:"); - for(otmp = otmp0; otmp; otmp = otmp->nobj) { - if(otmp->ox == u.ux && otmp->oy == u.uy) { - ct++; - cornline(1, doname(otmp)); - if(Blind && otmp->otyp == DEAD_COCKATRICE && !uarmg) { - pline("Touching the dead cockatrice is a fatal mistake ..."); - pline("You die ..."); - killer = "dead cockatrice"; - done("died"); - } - } - } - - if(gold) { - char gbuf[30]; - - sprintf(gbuf, "%ld gold piece%s", - gold->amount, plur(gold->amount)); - if(!ct++) - pline("You %s here %s.", verb, gbuf); - else - cornline(1, gbuf); - } + struct obj *otmp, *otmp0 = NULL; + struct gold *gold = NULL; + const char *verb = Blind ? "feel" : "see"; + int ct = 0; + + if (!u.uswallow) { + if (Blind) { + pline("You try to feel what is lying here on the floor."); + if (Levitation) { /* ab@unido */ + pline("You cannot reach the floor!"); + return (1); + } + } + otmp0 = o_at(u.ux, u.uy); + gold = g_at(u.ux, u.uy); + } + + if (u.uswallow || (!otmp0 && !gold)) { + pline("You %s no objects here.", verb); + return (!!Blind); + } + + cornline(0, "Things that are here:"); + for (otmp = otmp0; otmp; otmp = otmp->nobj) { + if (otmp->ox == u.ux && otmp->oy == u.uy) { + ct++; + cornline(1, doname(otmp)); + if (Blind && otmp->otyp == DEAD_COCKATRICE && !uarmg) { + pline("Touching the dead cockatrice is a fatal mistake ..."); + pline("You die ..."); + killer = "dead cockatrice"; + done("died"); + } + } + } - if(ct == 1 && !gold) { - pline("You %s here %s.", verb, doname(otmp0)); - cornline(3, NULL); - } - if(ct > 1) - cornline(2, NULL); - return(!!Blind); + if (gold) { + char gbuf[30]; + + sprintf(gbuf, "%ld gold piece%s", + gold->amount, plur(gold->amount)); + if (!ct++) + pline("You %s here %s.", verb, gbuf); + else + cornline(1, gbuf); + } + + if (ct == 1 && !gold) { + pline("You %s here %s.", verb, doname(otmp0)); + cornline(3, NULL); + } + if (ct > 1) + cornline(2, NULL); + return (!!Blind); } void stackobj(struct obj *obj) { -struct obj *otmp = fobj; - for(otmp = fobj; otmp; otmp = otmp->nobj) if(otmp != obj) - if(otmp->ox == obj->ox && otmp->oy == obj->oy && - merged(obj,otmp,1)) - return; + struct obj *otmp = fobj; + + for (otmp = fobj; otmp; otmp = otmp->nobj) + if (otmp != obj) + if (otmp->ox == obj->ox && otmp->oy == obj->oy && + merged(obj, otmp, 1)) + return; } /* merge obj with otmp and delete obj if types agree */ static bool merged(struct obj *otmp, struct obj *obj, bool lose) { - if(obj->otyp == otmp->otyp && - obj->unpaid == otmp->unpaid && - obj->spe == otmp->spe && - obj->dknown == otmp->dknown && - obj->cursed == otmp->cursed && - (index("%*?!", obj->olet) || - (obj->known == otmp->known && - (obj->olet == WEAPON_SYM && obj->otyp < BOOMERANG)))) { + if (obj->otyp == otmp->otyp && + obj->unpaid == otmp->unpaid && + obj->spe == otmp->spe && + obj->dknown == otmp->dknown && + obj->cursed == otmp->cursed && + (strchr("%*?!", obj->olet) || + (obj->known == otmp->known && + (obj->olet == WEAPON_SYM && obj->otyp < BOOMERANG)))) { otmp->quan += obj->quan; otmp->owt += obj->owt; - if(lose) freeobj(obj); - obfree(obj,otmp); /* free(obj), bill->otmp */ - return(1); - } else return(0); + if (lose) + freeobj(obj); + obfree(obj, otmp); /* free(obj), bill->otmp */ + return (1); + } else + return (0); } /* @@ -804,22 +875,23 @@ static long goldcounted; static bool countgold(void) { - if((goldcounted += 100*(u.ulevel + 1)) >= u.ugold) { + if ((goldcounted += 100 * (u.ulevel + 1)) >= u.ugold) { long eps = 0; - if(!rn2(2)) eps = rnd((int) (u.ugold/100 + 1)); + if (!rn2(2)) + eps = rnd((int)(u.ugold / 100 + 1)); pline("You probably have about %ld gold pieces.", - u.ugold + eps); - return(0); /* done */ + u.ugold + eps); + return (0); /* done */ } - return(1); /* continue */ + return (1); /* continue */ } int doprgold(void) { - if(!u.ugold) + if (!u.ugold) pline("You do not carry any gold."); - else if(u.ugold <= 500) + else if (u.ugold <= 500) pline("You are carrying %ld gold pieces.", u.ugold); else { pline("You sit down in order to count your gold pieces."); @@ -827,7 +899,7 @@ doprgold(void) occupation = countgold; occtxt = "counting your gold"; } - return(1); + return (1); } /* --- end of gold counting section --- */ @@ -835,50 +907,59 @@ doprgold(void) int doprwep(void) { - if(!uwep) pline("You are empty handed."); - else prinv(uwep); - return(0); + if (!uwep) + pline("You are empty handed."); + else + prinv(uwep); + return (0); } int doprarm(void) { - if(!uarm && !uarmg && !uarms && !uarmh) + if (!uarm && !uarmg && !uarms && !uarmh) pline("You are not wearing any armor."); else { char lets[6]; int ct = 0; - if(uarm) lets[ct++] = obj_to_let(uarm); - if(uarm2) lets[ct++] = obj_to_let(uarm2); - if(uarmh) lets[ct++] = obj_to_let(uarmh); - if(uarms) lets[ct++] = obj_to_let(uarms); - if(uarmg) lets[ct++] = obj_to_let(uarmg); + if (uarm) + lets[ct++] = obj_to_let(uarm); + if (uarm2) + lets[ct++] = obj_to_let(uarm2); + if (uarmh) + lets[ct++] = obj_to_let(uarmh); + if (uarms) + lets[ct++] = obj_to_let(uarms); + if (uarmg) + lets[ct++] = obj_to_let(uarmg); lets[ct] = 0; doinv(lets); } - return(0); + return (0); } int doprring(void) { - if(!uleft && !uright) + if (!uleft && !uright) pline("You are not wearing any rings."); else { char lets[3]; int ct = 0; - if(uleft) lets[ct++] = obj_to_let(uleft); - if(uright) lets[ct++] = obj_to_let(uright); + if (uleft) + lets[ct++] = obj_to_let(uleft); + if (uright) + lets[ct++] = obj_to_let(uright); lets[ct] = 0; doinv(lets); } - return(0); + return (0); } bool digit(char c) { - return(c >= '0' && c <= '9'); + return (c >= '0' && c <= '9'); } diff --git a/games/hack/hack.ioctl.c b/games/hack/hack.ioctl.c index 7c9aa90ade..980755a806 100644 --- a/games/hack/hack.ioctl.c +++ b/games/hack/hack.ioctl.c @@ -1,11 +1,12 @@ /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */ /* hack.ioctl.c - version 1.0.2 */ /* $FreeBSD: src/games/hack/hack.ioctl.c,v 1.2 1999/09/12 07:01:23 marcel Exp $ - $DragonFly: src/games/hack/hack.ioctl.c,v 1.4 2006/08/21 19:45:32 pavalos Exp $ - - This cannot be part of hack.tty.c (as it was earlier) since on some - systems (e.g. MUNIX) the include files and - define the same constants, and the C preprocessor complains. */ + * $DragonFly: src/games/hack/hack.ioctl.c,v 1.4 2006/08/21 19:45:32 pavalos Exp $ + * + * This cannot be part of hack.tty.c (as it was earlier) since on some + * systems (e.g. MUNIX) the include files and define the + * same constants, and the C preprocessor complains. + */ #include "hack.h" #include struct termios termio; @@ -23,12 +24,12 @@ setioctls(void) } #ifdef SUSPEND -#include +#include int dosuspend(void) { #ifdef SIGTSTP - if(signal(SIGTSTP, SIG_IGN) == SIG_DFL) { + if (signal(SIGTSTP, SIG_IGN) == SIG_DFL) { settty(NULL); signal(SIGTSTP, SIG_DFL); kill(0, SIGTSTP); @@ -41,6 +42,6 @@ dosuspend(void) #else /* SIGTSTP */ pline("Sorry, it seems we have no SIGTSTP here. Try ! or S."); #endif /* SIGTSTP */ - return(0); + return (0); } #endif /* SUSPEND */ diff --git a/games/hack/hack.lev.c b/games/hack/hack.lev.c index 148cef38b9..9509f5fafc 100644 --- a/games/hack/hack.lev.c +++ b/games/hack/hack.lev.c @@ -15,8 +15,8 @@ extern long wgrowtime[32]; boolean level_exists[MAXLEVEL+1]; -static void savegoldchn(int, struct gold *); -static void savetrapchn(int, struct trap *); +static void savegoldchn(int, struct gold *); +static void savetrapchn(int, struct trap *); void savelev(int fd, xchar lev) @@ -26,18 +26,19 @@ savelev(int fd, xchar lev) int tmp; #endif /* NOWORM */ - if(fd < 0) panic("Save on bad file!"); /* impossible */ - if(lev >= 0 && lev <= MAXLEVEL) + if (fd < 0) + panic("Save on bad file!"); /* impossible */ + if (lev >= 0 && lev <= MAXLEVEL) level_exists[lev] = TRUE; - bwrite(fd,(char *) &hackpid,sizeof(hackpid)); - bwrite(fd,(char *) &lev,sizeof(lev)); - bwrite(fd,(char *) levl,sizeof(levl)); - bwrite(fd,(char *) &moves,sizeof(long)); - bwrite(fd,(char *) &xupstair,sizeof(xupstair)); - bwrite(fd,(char *) &yupstair,sizeof(yupstair)); - bwrite(fd,(char *) &xdnstair,sizeof(xdnstair)); - bwrite(fd,(char *) &ydnstair,sizeof(ydnstair)); + bwrite(fd, (char *)&hackpid, sizeof(hackpid)); + bwrite(fd, (char *)&lev, sizeof(lev)); + bwrite(fd, (char *)levl, sizeof(levl)); + bwrite(fd, (char *)&moves, sizeof(long)); + bwrite(fd, (char *)&xupstair, sizeof(xupstair)); + bwrite(fd, (char *)&yupstair, sizeof(yupstair)); + bwrite(fd, (char *)&xdnstair, sizeof(xdnstair)); + bwrite(fd, (char *)&ydnstair, sizeof(ydnstair)); savemonchn(fd, fmon); savegoldchn(fd, fgold); savetrapchn(fd, ftrap); @@ -46,31 +47,31 @@ savelev(int fd, xchar lev) billobjs = 0; save_engravings(fd); #ifndef QUEST - bwrite(fd,(char *) rooms,sizeof(rooms)); - bwrite(fd,(char *) doors,sizeof(doors)); + bwrite(fd, (char *)rooms, sizeof(rooms)); + bwrite(fd, (char *)doors, sizeof(doors)); #endif /* QUEST */ fgold = 0; ftrap = 0; fmon = 0; fobj = 0; #ifndef NOWORM - bwrite(fd,(char *) wsegs,sizeof(wsegs)); - for(tmp=1; tmp<32; tmp++){ - for(wtmp = wsegs[tmp]; wtmp; wtmp = wtmp2){ + bwrite(fd, (char *)wsegs, sizeof(wsegs)); + for (tmp = 1; tmp < 32; tmp++) { + for (wtmp = wsegs[tmp]; wtmp; wtmp = wtmp2) { wtmp2 = wtmp->nseg; - bwrite(fd,(char *) wtmp,sizeof(struct wseg)); + bwrite(fd, (char *)wtmp, sizeof(struct wseg)); } wsegs[tmp] = 0; } - bwrite(fd,(char *) wgrowtime,sizeof(wgrowtime)); + bwrite(fd, (char *)wgrowtime, sizeof(wgrowtime)); #endif /* NOWORM */ } void bwrite(int fd, char *loc, unsigned int num) { -/* lint wants the 3rd arg of write to be an int; lint -p an unsigned */ - if(write(fd, loc, (int) num) != (int)num) + /* lint wants the 3rd arg of write to be an int; lint -p an unsigned */ + if (write(fd, loc, (int)num) != (int)num) panic("cannot write %u bytes to file #%d", num, fd); } @@ -81,15 +82,15 @@ saveobjchn(int fd, struct obj *otmp) unsigned xl; int minusone = -1; - while(otmp) { + while (otmp) { otmp2 = otmp->nobj; xl = otmp->onamelth; - bwrite(fd, (char *) &xl, sizeof(int)); - bwrite(fd, (char *) otmp, xl + sizeof(struct obj)); - free((char *) otmp); + bwrite(fd, (char *)&xl, sizeof(int)); + bwrite(fd, (char *)otmp, xl + sizeof(struct obj)); + free(otmp); otmp = otmp2; } - bwrite(fd, (char *) &minusone, sizeof(int)); + bwrite(fd, (char *)&minusone, sizeof(int)); } void @@ -100,28 +101,30 @@ savemonchn(int fd, struct monst *mtmp) int minusone = -1; struct permonst *monbegin = &mons[0]; - bwrite(fd, (char *) &monbegin, sizeof(monbegin)); + bwrite(fd, (char *)&monbegin, sizeof(monbegin)); - while(mtmp) { + while (mtmp) { mtmp2 = mtmp->nmon; xl = mtmp->mxlth + mtmp->mnamelth; - bwrite(fd, (char *) &xl, sizeof(int)); - bwrite(fd, (char *) mtmp, xl + sizeof(struct monst)); - if(mtmp->minvent) saveobjchn(fd,mtmp->minvent); - free((char *) mtmp); + bwrite(fd, (char *)&xl, sizeof(int)); + bwrite(fd, (char *)mtmp, xl + sizeof(struct monst)); + if (mtmp->minvent) + saveobjchn(fd, mtmp->minvent); + free(mtmp); mtmp = mtmp2; } - bwrite(fd, (char *) &minusone, sizeof(int)); + bwrite(fd, (char *)&minusone, sizeof(int)); } static void savegoldchn(int fd, struct gold *gold) { struct gold *gold2; - while(gold) { + + while (gold) { gold2 = gold->ngold; - bwrite(fd, (char *) gold, sizeof(struct gold)); - free((char *) gold); + bwrite(fd, (char *)gold, sizeof(struct gold)); + free(gold); gold = gold2; } bwrite(fd, nul, sizeof(struct gold)); @@ -131,10 +134,11 @@ static void savetrapchn(int fd, struct trap *trap) { struct trap *trap2; - while(trap) { + + while (trap) { trap2 = trap->ntrap; - bwrite(fd, (char *) trap, sizeof(struct trap)); - free((char *) trap); + bwrite(fd, (char *)trap, sizeof(struct trap)); + free(trap); trap = trap2; } bwrite(fd, nul, sizeof(struct trap)); @@ -154,9 +158,9 @@ getlev(int fd, int pid, xchar lev) xchar dlvl; /* First some sanity checks */ - mread(fd, (char *) &hpid, sizeof(hpid)); - mread(fd, (char *) &dlvl, sizeof(dlvl)); - if((pid && pid != hpid) || (lev && dlvl != lev)) { + mread(fd, (char *)&hpid, sizeof(hpid)); + mread(fd, (char *)&dlvl, sizeof(dlvl)); + if ((pid && pid != hpid) || (lev && dlvl != lev)) { pline("Strange, this map is not as I remember it."); pline("Somebody is trying some trickery here ..."); pline("This game is void ..."); @@ -165,7 +169,7 @@ getlev(int fd, int pid, xchar lev) fgold = 0; ftrap = 0; - mread(fd, (char *) levl, sizeof(levl)); + mread(fd, (char *)levl, sizeof(levl)); mread(fd, (char *)&omoves, sizeof(omoves)); mread(fd, (char *)&xupstair, sizeof(xupstair)); mread(fd, (char *)&yupstair, sizeof(yupstair)); @@ -175,51 +179,52 @@ getlev(int fd, int pid, xchar lev) fmon = restmonchn(fd); /* regenerate animals while on another level */ - { long tmoves = (moves > omoves) ? moves-omoves : 0; - struct monst *mtmp, *mtmp2; + { + long tmoves = (moves > omoves) ? moves - omoves : 0; + struct monst *mtmp, *mtmp2; - for(mtmp = fmon; mtmp; mtmp = mtmp2) { - long newhp; /* tmoves may be very large */ + for (mtmp = fmon; mtmp; mtmp = mtmp2) { + long newhp; /* tmoves may be very large */ - mtmp2 = mtmp->nmon; - if(index(genocided, mtmp->data->mlet)) { - mondead(mtmp); - continue; - } + mtmp2 = mtmp->nmon; + if (strchr(genocided, mtmp->data->mlet)) { + mondead(mtmp); + continue; + } - if(mtmp->mtame && tmoves > 250) { - mtmp->mtame = 0; - mtmp->mpeaceful = 0; - } + if (mtmp->mtame && tmoves > 250) { + mtmp->mtame = 0; + mtmp->mpeaceful = 0; + } - newhp = mtmp->mhp + - (index(MREGEN, mtmp->data->mlet) ? tmoves : tmoves/20); - if(newhp > mtmp->mhpmax) - mtmp->mhp = mtmp->mhpmax; - else - mtmp->mhp = newhp; - } + newhp = mtmp->mhp + + (strchr(MREGEN, mtmp->data->mlet) ? tmoves : tmoves / 20); + if (newhp > mtmp->mhpmax) + mtmp->mhp = mtmp->mhpmax; + else + mtmp->mhp = newhp; + } } setgd(); gold = newgold(); mread(fd, (char *)gold, sizeof(struct gold)); - while(gold->gx) { + while (gold->gx) { gold->ngold = fgold; fgold = gold; gold = newgold(); mread(fd, (char *)gold, sizeof(struct gold)); } - free((char *) gold); + free(gold); trap = newtrap(); mread(fd, (char *)trap, sizeof(struct trap)); - while(trap->tx) { + while (trap->tx) { trap->ntrap = ftrap; ftrap = trap; trap = newtrap(); mread(fd, (char *)trap, sizeof(struct trap)); } - free((char *) trap); + free(trap); fobj = restobjchn(fd); billobjs = restobjchn(fd); rest_engravings(fd); @@ -229,15 +234,17 @@ getlev(int fd, int pid, xchar lev) #endif /* QUEST */ #ifndef NOWORM mread(fd, (char *)wsegs, sizeof(wsegs)); - for(tmp = 1; tmp < 32; tmp++) if(wsegs[tmp]){ - wheads[tmp] = wsegs[tmp] = wtmp = newseg(); - while(1) { - mread(fd, (char *)wtmp, sizeof(struct wseg)); - if(!wtmp->nseg) break; - wheads[tmp]->nseg = wtmp = newseg(); - wheads[tmp] = wtmp; + for (tmp = 1; tmp < 32; tmp++) + if (wsegs[tmp]) { + wheads[tmp] = wsegs[tmp] = wtmp = newseg(); + for (;;) { + mread(fd, (char *)wtmp, sizeof(struct wseg)); + if (!wtmp->nseg) + break; + wheads[tmp]->nseg = wtmp = newseg(); + wheads[tmp] = wtmp; + } } - } mread(fd, (char *)wgrowtime, sizeof(wgrowtime)); #endif /* NOWORM */ } @@ -247,10 +254,10 @@ mread(int fd, char *buf, unsigned int len) { int rlen; - rlen = read(fd, buf, (int) len); - if(rlen != (int)len){ + rlen = read(fd, buf, (int)len); + if (rlen != (int)len) { pline("Read %d instead of %u bytes.\n", rlen, len); - if(restoring) { + if (restoring) { unlink(SAVEF); error("Error restoring old game."); } @@ -261,7 +268,8 @@ mread(int fd, char *buf, unsigned int len) void mklev(void) { - if(getbones()) return; + if (getbones()) + return; in_mklev = TRUE; makelevel(); diff --git a/games/hack/hack.main.c b/games/hack/hack.main.c index 7afee557a8..c4eacd8fe7 100644 --- a/games/hack/hack.main.c +++ b/games/hack/hack.main.c @@ -23,13 +23,13 @@ int locknum; /* max num of players */ char *catmore; /* default pager */ #endif char SAVEF[PL_NSIZ + 11] = "save/"; /* save/99999player */ -char *hname; /* name of the game (argv[0] of call) */ -char obuf[BUFSIZ]; /* BUFSIZ is defined in stdio.h */ +char *hname; /* name of the game (argv[0] of call) */ +char obuf[BUFSIZ]; /* BUFSIZ is defined in stdio.h */ extern long wailmsg; #ifdef CHDIR -static void chdirx(const char *, bool); +static void chdirx(const char *, bool); #endif int @@ -43,7 +43,7 @@ main(int argc, char *argv[]) hname = argv[0]; hackpid = getpid(); -#ifdef CHDIR /* otherwise no chdir() */ +#ifdef CHDIR /* otherwise no chdir() */ /* * See if we must change directory to the playground. * (Perhaps hack runs suid and playground is inaccessible @@ -53,18 +53,19 @@ main(int argc, char *argv[]) */ dir = getenv("HACKDIR"); - if(argc > 1 && !strncmp(argv[1], "-d", 2)) { + if (argc > 1 && !strncmp(argv[1], "-d", 2)) { argc--; argv++; - dir = argv[0]+2; - if(*dir == '=' || *dir == ':') dir++; - if(!*dir && argc > 1) { + dir = argv[0] + 2; + if (*dir == '=' || *dir == ':') + dir++; + if (!*dir && argc > 1) { argc--; argv++; dir = argv[0]; } - if(!*dir) - error("Flag -d must be followed by a directory name."); + if (!*dir) + error("Flag -d must be followed by a directory name."); } #endif @@ -79,24 +80,25 @@ main(int argc, char *argv[]) * Note that we trust him here; it is possible to play under * somebody else's name. */ - { char *s; - - initoptions(); - if(!*plname && (s = getenv("USER"))) - strncpy(plname, s, sizeof(plname)-1); - if(!*plname && (s = getenv("LOGNAME"))) - strncpy(plname, s, sizeof(plname)-1); - if(!*plname && (s = getlogin())) - strncpy(plname, s, sizeof(plname)-1); + { + char *s; + + initoptions(); + if (!*plname && (s = getenv("USER"))) + strncpy(plname, s, sizeof(plname) - 1); + if (!*plname && (s = getenv("LOGNAME"))) + strncpy(plname, s, sizeof(plname) - 1); + if (!*plname && (s = getlogin())) + strncpy(plname, s, sizeof(plname) - 1); } /* * Now we know the directory containing 'record' and * may do a prscore(). */ - if(argc > 1 && !strncmp(argv[1], "-s", 2)) { + if (argc > 1 && !strncmp(argv[1], "-s", 2)) { #ifdef CHDIR - chdirx(dir,0); + chdirx(dir, 0); #endif prscore(argc, argv); exit(0); @@ -107,13 +109,13 @@ main(int argc, char *argv[]) * Remember tty modes, to be restored on exit. */ gettty(); - setbuf(stdout,obuf); + setbuf(stdout, obuf); umask(007); setrandom(); startup(); cls(); - u.uhp = 1; /* prevent RIP on early quits */ - u.ux = FAR; /* prevent nscr() */ + u.uhp = 1; /* prevent RIP on early quits */ + u.ux = FAR; /* prevent nscr() */ signal(SIGHUP, hangup); /* @@ -126,19 +128,19 @@ main(int argc, char *argv[]) * We cannot do chdir earlier, otherwise gethdate will fail. */ #ifdef CHDIR - chdirx(dir,1); + chdirx(dir, 1); #endif /* * Process options. */ - while(argc > 1 && argv[1][0] == '-'){ + while (argc > 1 && argv[1][0] == '-') { argv++; argc--; - switch(argv[0][1]){ + switch (argv[0][1]) { #ifdef WIZARD case 'D': - wizard = TRUE; + wizard = TRUE; break; #endif #ifdef NEWS @@ -147,93 +149,96 @@ main(int argc, char *argv[]) break; #endif case 'u': - if(argv[0][2]) - strncpy(plname, argv[0]+2, sizeof(plname)-1); - else if(argc > 1) { - argc--; - argv++; - strncpy(plname, argv[0], sizeof(plname)-1); + if (argv[0][2]) + strncpy(plname, argv[0] + 2, sizeof(plname) - 1); + else if (argc > 1) { + argc--; + argv++; + strncpy(plname, argv[0], sizeof(plname) - 1); } else printf("Player name expected after -u\n"); break; default: /* allow -T for Tourist, etc. */ - strncpy(pl_character, argv[0]+1, - sizeof(pl_character)-1); + strncpy(pl_character, argv[0] + 1, + sizeof(pl_character) - 1); } } - if(argc > 1) + if (argc > 1) locknum = atoi(argv[1]); #ifdef MAX_NR_OF_PLAYERS - if(!locknum || locknum > MAX_NR_OF_PLAYERS) + if (!locknum || locknum > MAX_NR_OF_PLAYERS) locknum = MAX_NR_OF_PLAYERS; #endif #ifdef DEF_PAGER - if(!(catmore = getenv("HACKPAGER")) && !(catmore = getenv("PAGER"))) + if (!(catmore = getenv("HACKPAGER")) && !(catmore = getenv("PAGER"))) catmore = DEF_PAGER; #endif #ifdef MAIL getmailstatus(); #endif #ifdef WIZARD - if(wizard) strcpy(plname, "wizard"); else + if (wizard) + strcpy(plname, "wizard"); + else #endif - if(!*plname || !strncmp(plname, "player", 4) - || !strncmp(plname, "games", 4)) + if (!*plname || !strncmp(plname, "player", 4) + || !strncmp(plname, "games", 4)) askname(); plnamesuffix(); /* strip suffix from name; calls askname() */ /* again if suffix was whole name */ /* accepts any suffix */ #ifdef WIZARD - if(!wizard) { + if (!wizard) { #endif /* * check for multiple games under the same name * (if !locknum) or check max nr of players (otherwise) */ - signal(SIGQUIT,SIG_IGN); - signal(SIGINT,SIG_IGN); - if(!locknum) - strcpy(lock,plname); + signal(SIGQUIT, SIG_IGN); + signal(SIGINT, SIG_IGN); + if (!locknum) + strcpy(lock, plname); getlock(); /* sets lock if locknum != 0 */ #ifdef WIZARD } else { char *sfoo; - strcpy(lock,plname); - if((sfoo = getenv("MAGIC"))) - while(*sfoo) { - switch(*sfoo++) { - case 'n': srandom(*sfoo++); + strcpy(lock, plname); + if ((sfoo = getenv("MAGIC"))) + while (*sfoo) { + switch (*sfoo++) { + case 'n': + srandom(*sfoo++); break; } } - if((sfoo = getenv("GENOCIDED"))){ - if(*sfoo == '!'){ + if ((sfoo = getenv("GENOCIDED")) != NULL) { + if (*sfoo == '!') { struct permonst *pm = mons; char *gp = genocided; - while(pm < mons+CMNUM+2){ - if(!index(sfoo, pm->mlet)) + while (pm < mons + CMNUM + 2) { + if (!strchr(sfoo, pm->mlet)) *gp++ = pm->mlet; pm++; } *gp = 0; } else - strncpy(genocided, sfoo, sizeof(genocided)-1); + strncpy(genocided, sfoo, sizeof(genocided) - 1); strcpy(fut_geno, genocided); } } #endif setftty(); sprintf(SAVEF, "save/%d%s", getuid(), plname); - regularize(SAVEF+5); /* avoid . or / in name */ - if((fd = open(SAVEF,0)) >= 0 && - (uptodate(fd) || unlink(SAVEF) == 666)) { - signal(SIGINT,done1); + regularize(SAVEF + 5); /* avoid . or / in name */ + if ((fd = open(SAVEF, O_RDONLY)) >= 0 && + (uptodate(fd) || unlink(SAVEF) == 666)) { + signal(SIGINT, done1); pline("Restoring old save file..."); fflush(stdout); - if(!dorecover(fd)) + if (!dorecover(fd)) goto not_recovered; pline("Hello %s, welcome to %s!", plname, gamename); flags.move = 0; @@ -247,7 +252,7 @@ not_recovered: init_objects(); u_init(); - signal(SIGINT,done1); + signal(SIGINT, done1); mklev(); u.ux = xupstair; u.uy = yupstair; @@ -255,12 +260,14 @@ not_recovered: setsee(); flags.botlx = 1; makedog(); - { struct monst *mtmp; - if((mtmp = m_at(u.ux, u.uy))) mnexto(mtmp); /* riv05!a3 */ + { + struct monst *mtmp; + if ((mtmp = m_at(u.ux, u.uy)) != NULL) + mnexto(mtmp); /* riv05!a3 */ } seemons(); #ifdef NEWS - if(flags.nonews || !readnews()) + if (flags.nonews || !readnews()) /* after reading news we did docrt() already */ #endif docrt(); @@ -269,121 +276,125 @@ not_recovered: pline("Hello %s, welcome to %s!", plname, gamename); pickup(1); - read_engr_at(u.ux,u.uy); + read_engr_at(u.ux, u.uy); flags.move = 1; } flags.moonphase = phase_of_the_moon(); - if(flags.moonphase == FULL_MOON) { + if (flags.moonphase == FULL_MOON) { pline("You are lucky! Full moon tonight."); u.uluck++; - } else if(flags.moonphase == NEW_MOON) { + } else if (flags.moonphase == NEW_MOON) pline("Be careful! New moon tonight."); - } initrack(); - for(;;) { - if(flags.move) { /* actual time passed */ - + for (;;) { + if (flags.move) { /* actual time passed */ settrack(); - if(moves%2 == 0 || - (!(Fast & ~INTRINSIC) && (!Fast || rn2(3)))) { + if (moves % 2 == 0 || + (!(Fast & ~INTRINSIC) && (!Fast || rn2(3)))) { movemon(); - if(!rn2(70)) - makemon(NULL, 0, 0); + if (!rn2(70)) + makemon(NULL, 0, 0); } - if(Glib) glibr(); + if (Glib) + glibr(); p_timeout(); ++moves; - if(flags.time) flags.botl = 1; - if(u.uhp < 1) { + if (flags.time) + flags.botl = 1; + if (u.uhp < 1) { pline("You die..."); done("died"); } - if(u.uhp*10 < u.uhpmax && moves-wailmsg > 50){ - wailmsg = moves; - if(u.uhp == 1) - pline("You hear the wailing of the Banshee..."); - else - pline("You hear the howling of the CwnAnnwn..."); + if (u.uhp * 10 < u.uhpmax && moves - wailmsg > 50) { + wailmsg = moves; + if (u.uhp == 1) + pline("You hear the wailing of the Banshee..."); + else + pline("You hear the howling of the CwnAnnwn..."); } - if(u.uhp < u.uhpmax) { - if(u.ulevel > 9) { - if(Regeneration || !(moves%3)) { - flags.botl = 1; - u.uhp += rnd((int) u.ulevel-9); - if(u.uhp > u.uhpmax) - u.uhp = u.uhpmax; + if (u.uhp < u.uhpmax) { + if (u.ulevel > 9) { + if (Regeneration || !(moves % 3)) { + flags.botl = 1; + u.uhp += rnd((int)u.ulevel - 9); + if (u.uhp > u.uhpmax) + u.uhp = u.uhpmax; } - } else if(Regeneration || - (!(moves%(22-u.ulevel*2)))) { + } else if (Regeneration || + (!(moves % (22 - u.ulevel * 2)))) { flags.botl = 1; u.uhp++; } } - if(Teleportation && !rn2(85)) tele(); - if(Searching && multi >= 0) dosearch(); + if (Teleportation && !rn2(85)) + tele(); + if (Searching && multi >= 0) + dosearch(); gethungry(); invault(); amulet(); } - if(multi < 0) { - if(!++multi){ + if (multi < 0) { + if (!++multi) { pline(nomovemsg ? nomovemsg : - "You can move again."); + "You can move again."); nomovemsg = 0; - if(afternmv) (*afternmv)(); + if (afternmv) + (*afternmv)(); afternmv = 0; } } - find_ac(); #ifndef QUEST - if(!flags.mv || Blind) + if (!flags.mv || Blind) #endif { seeobjs(); seemons(); nscr(); } - if(flags.botl || flags.botlx) bot(); + if (flags.botl || flags.botlx) + bot(); flags.move = 1; - if(multi >= 0 && occupation) { - if(monster_nearby()) + if (multi >= 0 && occupation) { + if (monster_nearby()) stop_occupation(); else if ((*occupation)() == 0) occupation = 0; continue; } - if(multi > 0) { + if (multi > 0) { #ifdef QUEST - if(flags.run >= 4) finddir(); + if (flags.run >= 4) + finddir(); #endif lookaround(); - if(!multi) { /* lookaround may clear multi */ + if (!multi) { /* lookaround may clear multi */ flags.move = 0; continue; } - if(flags.mv) { - if(multi < COLNO && !--multi) + if (flags.mv) { + if (multi < COLNO && !--multi) flags.mv = flags.run = 0; domove(); } else { --multi; rhack(save_cm); } - } else if(multi == 0) { + } else if (multi == 0) { #ifdef MAIL ckmailstatus(); #endif rhack(NULL); } - if(multi && multi%7 == 0) + if (multi && multi % 7 == 0) fflush(stdout); } } @@ -395,8 +406,9 @@ glo(int foo) char *tf; tf = lock; - while(*tf && *tf != '.') tf++; - (void) sprintf(tf, ".%d", foo); + while (*tf && *tf != '.') + tf++; + (void)sprintf(tf, ".%d", foo); } /* @@ -407,30 +419,37 @@ glo(int foo) void askname(void) { -int c,ct; + int c, ct; + printf("\nWho are you? "); fflush(stdout); ct = 0; - while((c = getchar()) != '\n'){ - if(c == EOF) error("End of input\n"); + while ((c = getchar()) != '\n') { + if (c == EOF) + error("End of input\n"); /* some people get confused when their erase char is not ^H */ - if(c == '\010') { - if(ct) ct--; + if (c == '\010') { + if (ct) + ct--; continue; } - if(c != '-') - if(c < 'A' || (c > 'Z' && c < 'a') || c > 'z') c = '_'; - if(ct < (int)sizeof(plname)-1) plname[ct++] = c; + if (c != '-') + if (c < 'A' || (c > 'Z' && c < 'a') || c > 'z') + c = '_'; + if (ct < (int)sizeof(plname) - 1) + plname[ct++] = c; } plname[ct] = 0; - if(ct == 0) askname(); + if (ct == 0) + askname(); } -/*VARARGS1*/ +/* VARARGS1 */ void impossible(const char *s, ...) { va_list ap; + va_start(ap, s); vpline(s, ap); va_end(ap); @@ -441,24 +460,23 @@ impossible(const char *s, ...) static void chdirx(const char *dir, bool wr) { - #ifdef SECURE - if(dir /* User specified directory? */ + if (dir /* User specified directory? */ #ifdef HACKDIR - && strcmp(dir, HACKDIR) /* and not the default? */ + && strcmp(dir, HACKDIR) /* and not the default? */ #endif - ) { + ) { /* revoke */ setgid(getgid()); } #endif #ifdef HACKDIR - if(dir == NULL) + if (dir == NULL) dir = HACKDIR; #endif - if(dir && chdir(dir) < 0) { + if (dir && chdir(dir) < 0) { perror(dir); error("Cannot chdir to %s.", dir); } @@ -466,16 +484,16 @@ chdirx(const char *dir, bool wr) /* warn the player if he cannot write the record file */ /* perhaps we should also test whether . is writable */ /* unfortunately the access systemcall is worthless */ - if(wr) { - int fd; - - if(dir == NULL) - dir = "."; - if((fd = open(RECORD, 2)) < 0) { - printf("Warning: cannot write %s/%s", dir, RECORD); - getret(); - } else - close(fd); + if (wr) { + int fd; + + if (dir == NULL) + dir = "."; + if ((fd = open(RECORD, O_RDWR)) < 0) { + printf("Warning: cannot write %s/%s", dir, RECORD); + getret(); + } else + close(fd); } } #endif @@ -483,7 +501,7 @@ chdirx(const char *dir, bool wr) void stop_occupation(void) { - if(occupation) { + if (occupation) { pline("You stop %s.", occtxt); occupation = 0; } diff --git a/games/hack/hack.makemon.c b/games/hack/hack.makemon.c index 673b120b0c..4c9bb07ea8 100644 --- a/games/hack/hack.makemon.c +++ b/games/hack/hack.makemon.c @@ -3,7 +3,8 @@ /* $FreeBSD: src/games/hack/hack.makemon.c,v 1.4 1999/11/16 10:26:36 marcel Exp $ */ /* $DragonFly: src/games/hack/hack.makemon.c,v 1.4 2006/08/21 19:45:32 pavalos Exp $ */ -#include "hack.h" +#include "hack.h" + struct monst zeromonst; /* @@ -21,158 +22,177 @@ makemon(struct permonst *ptr, int x, int y) int tmp, ct; boolean anything = (!ptr); - if(x != 0 || y != 0) if(m_at(x,y)) return(NULL); - if(ptr){ - if(index(fut_geno, ptr->mlet)) return(NULL); + if (x != 0 || y != 0) + if (m_at(x, y)) + return (NULL); + if (ptr) { + if (strchr(fut_geno, ptr->mlet)) + return (NULL); } else { ct = CMNUM - strlen(fut_geno); - if(index(fut_geno, 'm')) ct++; /* make only 1 minotaur */ - if(index(fut_geno, '@')) ct++; - if(ct <= 0) return(0); /* no more monsters! */ - tmp = rn2(ct*dlevel/24 + 7); - if(tmp < dlevel - 4) tmp = rn2(ct*dlevel/24 + 12); - if(tmp >= ct) tmp = rn1(ct - ct/2, ct/2); - for(ct = 0; ct < CMNUM; ct++){ + if (strchr(fut_geno, 'm')) /* make only 1 minotaur */ + ct++; + if (strchr(fut_geno, '@')) + ct++; + if (ct <= 0) /* no more monsters! */ + return (0); + tmp = rn2(ct * dlevel / 24 + 7); + if (tmp < dlevel - 4) + tmp = rn2(ct * dlevel / 24 + 12); + if (tmp >= ct) + tmp = rn1(ct - ct / 2, ct / 2); + for (ct = 0; ct < CMNUM; ct++) { ptr = &mons[ct]; - if(index(fut_geno, ptr->mlet)) + if (strchr(fut_geno, ptr->mlet)) continue; - if(!tmp--) goto gotmon; + if (!tmp--) + goto gotmon; } panic("makemon?"); } gotmon: mtmp = newmonst(ptr->pxlth); *mtmp = zeromonst; /* clear all entries in structure */ - for(ct = 0; (unsigned)ct < ptr->pxlth; ct++) - ((char *) &(mtmp->mextra[0]))[ct] = 0; + for (ct = 0; (unsigned)ct < ptr->pxlth; ct++) + ((char *)&(mtmp->mextra[0]))[ct] = 0; mtmp->nmon = fmon; fmon = mtmp; mtmp->m_id = flags.ident++; mtmp->data = ptr; mtmp->mxlth = ptr->pxlth; - if(ptr->mlet == 'D') mtmp->mhpmax = mtmp->mhp = 80; - else if(!ptr->mlevel) mtmp->mhpmax = mtmp->mhp = rnd(4); - else mtmp->mhpmax = mtmp->mhp = d(ptr->mlevel, 8); + if (ptr->mlet == 'D') + mtmp->mhpmax = mtmp->mhp = 80; + else if (!ptr->mlevel) + mtmp->mhpmax = mtmp->mhp = rnd(4); + else + mtmp->mhpmax = mtmp->mhp = d(ptr->mlevel, 8); mtmp->mx = x; mtmp->my = y; mtmp->mcansee = 1; - if(ptr->mlet == 'M'){ + if (ptr->mlet == 'M') { mtmp->mimic = 1; mtmp->mappearance = ']'; } - if(!in_mklev) { - if(x == u.ux && y == u.uy && ptr->mlet != ' ') + if (!in_mklev) { + if (x == u.ux && y == u.uy && ptr->mlet != ' ') mnexto(mtmp); - if(x == 0 && y == 0) + if (x == 0 && y == 0) rloc(mtmp); } - if(ptr->mlet == 's' || ptr->mlet == 'S') { + if (ptr->mlet == 's' || ptr->mlet == 'S') { mtmp->mhide = mtmp->mundetected = 1; - if(in_mklev) - if(mtmp->mx && mtmp->my) - mkobj_at(0, mtmp->mx, mtmp->my); + if (in_mklev) + if (mtmp->mx && mtmp->my) + mkobj_at(0, mtmp->mx, mtmp->my); } - if(ptr->mlet == ':') { + if (ptr->mlet == ':') { mtmp->cham = 1; - newcham(mtmp, &mons[dlevel+14+rn2(CMNUM-14-dlevel)]); + newcham(mtmp, &mons[dlevel + 14 + rn2(CMNUM - 14 - dlevel)]); } - if(ptr->mlet == 'I' || ptr->mlet == ';') + if (ptr->mlet == 'I' || ptr->mlet == ';') mtmp->minvis = 1; - if(ptr->mlet == 'L' || ptr->mlet == 'N' - || (in_mklev && index("&w;", ptr->mlet) && rn2(5)) - ) mtmp->msleep = 1; + if (ptr->mlet == 'L' || ptr->mlet == 'N' + || (in_mklev && strchr("&w;", ptr->mlet) && rn2(5))) + mtmp->msleep = 1; #ifndef NOWORM - if(ptr->mlet == 'w' && getwn(mtmp)) + if (ptr->mlet == 'w' && getwn(mtmp)) initworm(mtmp); #endif /* NOWORM */ - if(anything) if(ptr->mlet == 'O' || ptr->mlet == 'k') { - coord mm; - int cnt = rnd(10); - mm.x = x; - mm.y = y; - while(cnt--) { - mm = enexto(mm.x, mm.y); - makemon(ptr, mm.x, mm.y); + if (anything) + if (ptr->mlet == 'O' || ptr->mlet == 'k') { + coord mm; + int cnt = rnd(10); + mm.x = x; + mm.y = y; + while (cnt--) { + mm = enexto(mm.x, mm.y); + makemon(ptr, mm.x, mm.y); + } } - } - return(mtmp); + return (mtmp); } coord enexto(xchar xx, xchar yy) { - xchar x,y; + xchar x, y; coord foo[15], *tfoo; int range; tfoo = foo; range = 1; do { /* full kludge action. */ - for(x = xx-range; x <= xx+range; x++) - if(goodpos(x, yy-range)) { + for (x = xx - range; x <= xx + range; x++) + if (goodpos(x, yy - range)) { tfoo->x = x; - tfoo++->y = yy-range; - if(tfoo == &foo[15]) goto foofull; + tfoo++->y = yy - range; + if (tfoo == &foo[15]) + goto foofull; } - for(x = xx-range; x <= xx+range; x++) - if(goodpos(x,yy+range)) { + for (x = xx - range; x <= xx + range; x++) + if (goodpos(x, yy + range)) { tfoo->x = x; - tfoo++->y = yy+range; - if(tfoo == &foo[15]) goto foofull; + tfoo++->y = yy + range; + if (tfoo == &foo[15]) + goto foofull; } - for(y = yy+1-range; y < yy+range; y++) - if(goodpos(xx-range,y)) { - tfoo->x = xx-range; + for (y = yy + 1 - range; y < yy + range; y++) + if (goodpos(xx - range, y)) { + tfoo->x = xx - range; tfoo++->y = y; - if(tfoo == &foo[15]) goto foofull; + if (tfoo == &foo[15]) + goto foofull; } - for(y = yy+1-range; y < yy+range; y++) - if(goodpos(xx+range,y)) { - tfoo->x = xx+range; + for (y = yy + 1 - range; y < yy + range; y++) + if (goodpos(xx + range, y)) { + tfoo->x = xx + range; tfoo++->y = y; - if(tfoo == &foo[15]) goto foofull; + if (tfoo == &foo[15]) + goto foofull; } range++; - } while(tfoo == foo); + } while (tfoo == foo); foofull: - return( foo[rn2(tfoo-foo)] ); + return (foo[rn2(tfoo - foo)]); } bool -goodpos(int x, int y) /* used only in mnexto and rloc */ +goodpos(int x, int y) /* used only in mnexto and rloc */ { - return( - ! (x < 1 || x > COLNO-2 || y < 1 || y > ROWNO-2 || - m_at(x,y) || !ACCESSIBLE(levl[x][y].typ) - || (x == u.ux && y == u.uy) - || sobj_at(ENORMOUS_ROCK, x, y) - )); + return ( + !(x < 1 || x > COLNO - 2 || y < 1 || y > ROWNO - 2 || + m_at(x, y) || !ACCESSIBLE(levl[x][y].typ) + || (x == u.ux && y == u.uy) + || sobj_at(ENORMOUS_ROCK, x, y) + )); } void rloc(struct monst *mtmp) { - int tx,ty; + int tx, ty; char ch = mtmp->data->mlet; #ifndef NOWORM - if(ch == 'w' && mtmp->mx) return; /* do not relocate worms */ + if (ch == 'w' && mtmp->mx) /* do not relocate worms */ + return; #endif /* NOWORM */ do { - tx = rn1(COLNO-3,2); + tx = rn1(COLNO - 3, 2); ty = rn2(ROWNO); - } while(!goodpos(tx,ty)); + } while (!goodpos(tx, ty)); mtmp->mx = tx; mtmp->my = ty; - if(u.ustuck == mtmp){ - if(u.uswallow) { + if (u.ustuck == mtmp) { + if (u.uswallow) { u.ux = tx; u.uy = ty; docrt(); - } else u.ustuck = 0; + } else + u.ustuck = 0; } pmon(mtmp); } @@ -183,10 +203,10 @@ mkmon_at(char let, int x, int y) int ct; struct permonst *ptr; - for(ct = 0; ct < CMNUM; ct++) { + for (ct = 0; ct < CMNUM; ct++) { ptr = &mons[ct]; - if(ptr->mlet == let) - return(makemon(ptr,x,y)); + if (ptr->mlet == let) + return (makemon(ptr, x, y)); } - return(0); + return (0); } diff --git a/games/hack/hack.mhitu.c b/games/hack/hack.mhitu.c index a1622c12fe..b9b410d804 100644 --- a/games/hack/hack.mhitu.c +++ b/games/hack/hack.mhitu.c @@ -3,7 +3,7 @@ /* $FreeBSD: src/games/hack/hack.mhitu.c,v 1.4 1999/11/16 10:26:36 marcel Exp $ */ /* $DragonFly: src/games/hack/hack.mhitu.c,v 1.4 2006/08/21 19:45:32 pavalos Exp $ */ -#include "hack.h" +#include "hack.h" /* * mhitu: monster hits you @@ -18,302 +18,317 @@ mhitu(struct monst *mtmp) nomul(0); /* If swallowed, can only be affected by hissers and by u.ustuck */ - if(u.uswallow) { - if(mtmp != u.ustuck) { - if(mdat->mlet == 'c' && !rn2(13)) { + if (u.uswallow) { + if (mtmp != u.ustuck) { + if (mdat->mlet == 'c' && !rn2(13)) { pline("Outside, you hear %s's hissing!", - monnam(mtmp)); + monnam(mtmp)); pline("%s gets turned to stone!", - Monnam(u.ustuck)); + Monnam(u.ustuck)); pline("And the same fate befalls you."); done_in_by(mtmp); /* "notreached": not return(1); */ } - return(0); + return (0); } - switch(mdat->mlet) { /* now mtmp == u.ustuck */ + switch (mdat->mlet) { /* now mtmp == u.ustuck */ case ',': - youswld(mtmp, (u.uac > 0) ? u.uac+4 : 4, + youswld(mtmp, (u.uac > 0) ? u.uac + 4 : 4, 5, "The trapper"); break; case '\'': - youswld(mtmp,rnd(6),7,"The lurker above"); + youswld(mtmp, rnd(6), 7, "The lurker above"); break; case 'P': - youswld(mtmp,d(2,4),12,"The purple worm"); + youswld(mtmp, d(2, 4), 12, "The purple worm"); break; default: /* This is not impossible! */ pline("The mysterious monster totally digests you."); u.uhp = 0; } - if(u.uhp < 1) done_in_by(mtmp); - return(0); + if (u.uhp < 1) + done_in_by(mtmp); + return (0); } - if(mdat->mlet == 'c' && Stoned) - return(0); + if (mdat->mlet == 'c' && Stoned) + return (0); /* make eels visible the moment they hit/miss us */ - if(mdat->mlet == ';' && mtmp->minvis && cansee(mtmp->mx,mtmp->my)){ + if (mdat->mlet == ';' && mtmp->minvis && cansee(mtmp->mx, mtmp->my)) { mtmp->minvis = 0; pmon(mtmp); } - if(!index("1&DuxynNF",mdat->mlet)) - tmp = hitu(mtmp,d(mdat->damn,mdat->damd)); + if (!strchr("1&DuxynNF", mdat->mlet)) + tmp = hitu(mtmp, d(mdat->damn, mdat->damd)); else tmp = 0; - if(index(UNDEAD, mdat->mlet) && midnight()) - tmp += hitu(mtmp,d(mdat->damn,mdat->damd)); + if (strchr(UNDEAD, mdat->mlet) && midnight()) + tmp += hitu(mtmp, d(mdat->damn, mdat->damd)); ctmp = tmp && !mtmp->mcan && - (!uarm || objects[uarm->otyp].a_can < rnd(3) || !rn2(50)); - switch(mdat->mlet) { + (!uarm || objects[uarm->otyp].a_can < rnd(3) || !rn2(50)); + switch (mdat->mlet) { case '1': - if(wiz_hit(mtmp)) return(1); /* he disappeared */ + if (wiz_hit(mtmp)) /* he disappeared */ + return (1); break; case '&': - if(!mtmp->cham && !mtmp->mcan && !rn2(13)) { - makemon(PM_DEMON,u.ux,u.uy); + if (!mtmp->cham && !mtmp->mcan && !rn2(13)) { + makemon(PM_DEMON, u.ux, u.uy); } else { - hitu(mtmp,d(2,6)); - hitu(mtmp,d(2,6)); - hitu(mtmp,rnd(3)); - hitu(mtmp,rnd(3)); - hitu(mtmp,rn1(4,2)); + hitu(mtmp, d(2, 6)); + hitu(mtmp, d(2, 6)); + hitu(mtmp, rnd(3)); + hitu(mtmp, rnd(3)); + hitu(mtmp, rn1(4, 2)); } break; case ',': - if(tmp) justswld(mtmp,"The trapper"); + if (tmp) + justswld(mtmp, "The trapper"); break; case '\'': - if(tmp) justswld(mtmp, "The lurker above"); + if (tmp) + justswld(mtmp, "The lurker above"); break; case ';': - if(ctmp) { - if(!u.ustuck && !rn2(10)) { + if (ctmp) { + if (!u.ustuck && !rn2(10)) { pline("%s swings itself around you!", - Monnam(mtmp)); + Monnam(mtmp)); u.ustuck = mtmp; - } else if(u.ustuck == mtmp && - levl[mtmp->mx][mtmp->my].typ == POOL) { + } else if (u.ustuck == mtmp && + levl[mtmp->mx][mtmp->my].typ == POOL) { pline("%s drowns you ...", Monnam(mtmp)); done("drowned"); } } break; case 'A': - if(ctmp && rn2(2)) { - if(Poison_resistance) - pline("The sting doesn't seem to affect you."); - else { - pline("You feel weaker!"); - losestr(1); - } + if (ctmp && rn2(2)) { + if (Poison_resistance) + pline("The sting doesn't seem to affect you."); + else { + pline("You feel weaker!"); + losestr(1); + } } break; case 'C': - hitu(mtmp,rnd(6)); + hitu(mtmp, rnd(6)); break; case 'c': - if(!rn2(5)) { + if (!rn2(5)) { pline("You hear %s's hissing!", monnam(mtmp)); - if(ctmp || !rn2(20) || (flags.moonphase == NEW_MOON - && !carrying(DEAD_LIZARD))) { + if (ctmp || !rn2(20) || (flags.moonphase == NEW_MOON + && !carrying(DEAD_LIZARD))) Stoned = 5; - } } break; case 'D': - if(rn2(6) || mtmp->mcan) { - hitu(mtmp,d(3,10)); - hitu(mtmp,rnd(8)); - hitu(mtmp,rnd(8)); + if (rn2(6) || mtmp->mcan) { + hitu(mtmp, d(3, 10)); + hitu(mtmp, rnd(8)); + hitu(mtmp, rnd(8)); break; } - kludge("%s breathes fire!","The dragon"); - buzz(-1,mtmp->mx,mtmp->my,u.ux-mtmp->mx,u.uy-mtmp->my); + kludge("%s breathes fire!", "The dragon"); + buzz(-1, mtmp->mx, mtmp->my, u.ux - mtmp->mx, u.uy - mtmp->my); break; case 'd': - hitu(mtmp,d(2, (flags.moonphase == FULL_MOON) ? 3 : 4)); + hitu(mtmp, d(2, (flags.moonphase == FULL_MOON) ? 3 : 4)); break; case 'e': - hitu(mtmp,d(3,6)); + hitu(mtmp, d(3, 6)); break; case 'F': - if(mtmp->mcan) break; - kludge("%s explodes!","The freezing sphere"); - if(Cold_resistance) pline("You don't seem affected by it."); + if (mtmp->mcan) + break; + kludge("%s explodes!", "The freezing sphere"); + if (Cold_resistance) + pline("You don't seem affected by it."); else { xchar dn; - if(17-(u.ulevel/2) > rnd(20)) { + if (17 - (u.ulevel / 2) > rnd(20)) { pline("You get blasted!"); dn = 6; } else { pline("You duck the blast..."); dn = 3; } - losehp_m(d(dn,6), mtmp); + losehp_m(d(dn, 6), mtmp); } mondead(mtmp); - return(1); + return (1); case 'g': - if(ctmp && multi >= 0 && !rn2(3)) { - kludge("You are frozen by %ss juices","the cube'"); + if (ctmp && multi >= 0 && !rn2(3)) { + kludge("You are frozen by %ss juices", "the cube'"); nomul(-rnd(10)); } break; case 'h': - if(ctmp && multi >= 0 && !rn2(5)) { + if (ctmp && multi >= 0 && !rn2(5)) { nomul(-rnd(10)); kludge("You are put to sleep by %ss bite!", - "the homunculus'"); + "the homunculus'"); } break; case 'j': - tmp = hitu(mtmp,rnd(3)); - tmp &= hitu(mtmp,rnd(3)); - if(tmp){ - hitu(mtmp,rnd(4)); - hitu(mtmp,rnd(4)); + tmp = hitu(mtmp, rnd(3)); + tmp &= hitu(mtmp, rnd(3)); + if (tmp) { + hitu(mtmp, rnd(4)); + hitu(mtmp, rnd(4)); } break; case 'k': - if((hitu(mtmp,rnd(4)) || !rn2(3)) && ctmp){ - poisoned("bee's sting",mdat->mname); - } + if ((hitu(mtmp, rnd(4)) || !rn2(3)) && ctmp) + poisoned("bee's sting", mdat->mname); break; case 'L': - if(tmp) stealgold(mtmp); + if (tmp) + stealgold(mtmp); break; case 'N': - if(mtmp->mcan && !Blind) { - pline("%s tries to seduce you, but you seem not interested.", - Amonnam(mtmp, "plain")); - if(rn2(3)) rloc(mtmp); - } else if(steal(mtmp)) { + if (mtmp->mcan && !Blind) { + pline("%s tries to seduce you, but you seem not interested.", + Amonnam(mtmp, "plain")); + if (rn2(3)) + rloc(mtmp); + } else if (steal(mtmp)) { rloc(mtmp); mtmp->mflee = 1; } break; case 'n': - if(!uwep && !uarm && !uarmh && !uarms && !uarmg) { - pline("%s hits! (I hope you don't mind)", - Monnam(mtmp)); + if (!uwep && !uarm && !uarmh && !uarms && !uarmg) { + pline("%s hits! (I hope you don't mind)", + Monnam(mtmp)); u.uhp += rnd(7); - if(!rn2(7)) u.uhpmax++; - if(u.uhp > u.uhpmax) u.uhp = u.uhpmax; + if (!rn2(7)) + u.uhpmax++; + if (u.uhp > u.uhpmax) + u.uhp = u.uhpmax; flags.botl = 1; - if(!rn2(50)) rloc(mtmp); + if (!rn2(50)) + rloc(mtmp); } else { - hitu(mtmp,d(2,6)); - hitu(mtmp,d(2,6)); + hitu(mtmp, d(2, 6)); + hitu(mtmp, d(2, 6)); } break; case 'o': - tmp = hitu(mtmp,rnd(6)); - if(hitu(mtmp,rnd(6)) && tmp && /* hits with both paws */ + tmp = hitu(mtmp, rnd(6)); + if (hitu(mtmp, rnd(6)) && tmp && /* hits with both paws */ !u.ustuck && rn2(2)) { u.ustuck = mtmp; - kludge("%s has grabbed you!","The owlbear"); - u.uhp -= d(2,8); - } else if(u.ustuck == mtmp) { - u.uhp -= d(2,8); + kludge("%s has grabbed you!", "The owlbear"); + u.uhp -= d(2, 8); + } else if (u.ustuck == mtmp) { + u.uhp -= d(2, 8); pline("You are being crushed."); } break; case 'P': - if(ctmp && !rn2(4)) - justswld(mtmp,"The purple worm"); + if (ctmp && !rn2(4)) + justswld(mtmp, "The purple worm"); else - hitu(mtmp,d(2,4)); + hitu(mtmp, d(2, 4)); break; case 'Q': - hitu(mtmp,rnd(2)); - hitu(mtmp,rnd(2)); + hitu(mtmp, rnd(2)); + hitu(mtmp, rnd(2)); break; case 'R': - if(tmp && uarmh && !uarmh->rustfree && - (int) uarmh->spe >= -1) { + if (tmp && uarmh && !uarmh->rustfree && + (int)uarmh->spe >= -1) { pline("Your helmet rusts!"); uarmh->spe--; - } else - if(ctmp && uarm && !uarm->rustfree && /* Mike Newton */ - uarm->otyp < STUDDED_LEATHER_ARMOR && - (int) uarm->spe >= -1) { + } else if (ctmp && uarm && !uarm->rustfree && /* Mike Newton */ + uarm->otyp < STUDDED_LEATHER_ARMOR && + (int)uarm->spe >= -1) { pline("Your armor rusts!"); uarm->spe--; } break; case 'S': - if(ctmp && !rn2(8)) { - poisoned("snake's bite",mdat->mname); - } + if (ctmp && !rn2(8)) + poisoned("snake's bite", mdat->mname); break; case 's': - if(tmp && !rn2(8)) { - poisoned("scorpion's sting",mdat->mname); - } - hitu(mtmp,rnd(8)); - hitu(mtmp,rnd(8)); + if (tmp && !rn2(8)) + poisoned("scorpion's sting", mdat->mname); + hitu(mtmp, rnd(8)); + hitu(mtmp, rnd(8)); break; case 'T': - hitu(mtmp,rnd(6)); - hitu(mtmp,rnd(6)); + hitu(mtmp, rnd(6)); + hitu(mtmp, rnd(6)); break; case 't': - if(!rn2(5)) rloc(mtmp); + if (!rn2(5)) + rloc(mtmp); break; case 'u': mtmp->mflee = 1; break; case 'U': - hitu(mtmp,d(3,4)); - hitu(mtmp,d(3,4)); + hitu(mtmp, d(3, 4)); + hitu(mtmp, d(3, 4)); break; case 'v': - if(ctmp && !u.ustuck) u.ustuck = mtmp; + if (ctmp && !u.ustuck) + u.ustuck = mtmp; break; case 'V': - if(tmp) u.uhp -= 4; - if(ctmp) losexp(); + if (tmp) + u.uhp -= 4; + if (ctmp) + losexp(); break; case 'W': - if(ctmp) losexp(); + if (ctmp) + losexp(); break; #ifndef NOWORM case 'w': - if(tmp) wormhit(mtmp); + if (tmp) + wormhit(mtmp); #endif /* NOWORM */ break; case 'X': - hitu(mtmp,rnd(5)); - hitu(mtmp,rnd(5)); - hitu(mtmp,rnd(5)); + hitu(mtmp, rnd(5)); + hitu(mtmp, rnd(5)); + hitu(mtmp, rnd(5)); break; case 'x': - { long side = rn2(2) ? RIGHT_SIDE : LEFT_SIDE; - pline("%s pricks in your %s leg!", - Monnam(mtmp), (side == RIGHT_SIDE) ? "right" : "left"); - set_wounded_legs(side, rnd(50)); - losehp_m(2, mtmp); - break; + { + long side = rn2(2) ? RIGHT_SIDE : LEFT_SIDE; + pline("%s pricks in your %s leg!", + Monnam(mtmp), (side == RIGHT_SIDE) ? "right" : "left"); + set_wounded_legs(side, rnd(50)); + losehp_m(2, mtmp); + break; } case 'y': - if(mtmp->mcan) break; + if (mtmp->mcan) + break; mondead(mtmp); - if(!Blind) { + if (!Blind) { pline("You are blinded by a blast of light!"); - Blind = d(4,12); + Blind = d(4, 12); seeoff(0); } - return(1); + return (1); case 'Y': - hitu(mtmp,rnd(6)); + hitu(mtmp, rnd(6)); break; } - if(u.uhp < 1) done_in_by(mtmp); - return(0); + if (u.uhp < 1) + done_in_by(mtmp); + return (0); } bool @@ -323,39 +338,48 @@ hitu(struct monst *mtmp, int dam) int tmp; nomul(0); - if(u.uswallow) return(0); + if (u.uswallow) + return (0); - if(mtmp->mhide && mtmp->mundetected) { + if (mtmp->mhide && mtmp->mundetected) { mtmp->mundetected = 0; - if(!Blind) { + if (!Blind) { struct obj *obj; - if((obj = o_at(mtmp->mx,mtmp->my))) + if ((obj = o_at(mtmp->mx, mtmp->my)) != NULL) pline("%s was hidden under %s!", - Xmonnam(mtmp), doname(obj)); + Xmonnam(mtmp), doname(obj)); } } tmp = u.uac; /* give people with Ac = -10 at least some vulnerability */ - if(tmp < 0) { - dam += tmp; /* decrease damage */ - if(dam <= 0) dam = 1; + if (tmp < 0) { + dam += tmp; /* decrease damage */ + if (dam <= 0) + dam = 1; tmp = -rn2(-tmp); } tmp += mtmp->data->mlevel; - if(multi < 0) tmp += 4; - if((Invis && mtmp->data->mlet != 'I') || !mtmp->mcansee) tmp -= 2; - if(mtmp->mtrapped) tmp -= 2; - if(tmp <= rnd(20)) { - if(Blind) pline("It misses."); - else pline("%s misses.",Monnam(mtmp)); + if (multi < 0) + tmp += 4; + if ((Invis && mtmp->data->mlet != 'I') || !mtmp->mcansee) + tmp -= 2; + if (mtmp->mtrapped) + tmp -= 2; + if (tmp <= rnd(20)) { + if (Blind) + pline("It misses."); + else + pline("%s misses.", Monnam(mtmp)); res = 0; } else { - if(Blind) pline("It hits!"); - else pline("%s hits!",Monnam(mtmp)); + if (Blind) + pline("It hits!"); + else + pline("%s hits!", Monnam(mtmp)); losehp_m(dam, mtmp); res = 1; } stop_occupation(); - return(res); + return (res); } diff --git a/games/hack/hack.mklev.c b/games/hack/hack.mklev.c index aeb28b2d4d..ad51f4b5a4 100644 --- a/games/hack/hack.mklev.c +++ b/games/hack/hack.mklev.c @@ -5,8 +5,8 @@ #include "hack.h" -#define somex() ((random()%(croom->hx-croom->lx+1))+croom->lx) -#define somey() ((random()%(croom->hy-croom->ly+1))+croom->ly) +#define somex() ((random()%(croom->hx-croom->lx+1))+croom->lx) +#define somey() ((random()%(croom->hy-croom->ly+1))+croom->ly) #define XLIM 4 /* define minimum required space around a room */ #define YLIM 3 @@ -19,48 +19,49 @@ struct rm zerorm; schar nxcor; boolean goldseen; int nroom; -xchar xdnstair,xupstair,ydnstair,yupstair; +xchar xdnstair, xupstair, ydnstair, yupstair; /* Definitions used by makerooms() and addrs() */ #define MAXRS 50 /* max lth of temp rectangle table - arbitrary */ struct rectangle { - xchar rlx,rly,rhx,rhy; -} rs[MAXRS+1]; -int rscnt,rsmax; /* 0..rscnt-1: currently under consideration */ + xchar rlx, rly, rhx, rhy; +} rs[MAXRS + 1]; +int rscnt, rsmax; /* 0..rscnt-1: currently under consideration */ /* rscnt..rsmax: discarded */ -static bool makerooms(void); -static void addrs(int, int, int, int); -static void addrsx(int, int, int, int, bool); -static int comp(const void *, const void *); -static coord finddpos(int, int, int, int); -static bool okdoor(int, int); -static void dodoor(int, int, struct mkroom *); -static void dosdoor(int, int, struct mkroom *, int); -static bool maker(schar, schar, schar, schar); -static void makecorridors(void); -static void join(int, int); -static void make_niches(void); -static void makevtele(void); -static void makeniche(bool); +static bool makerooms(void); +static void addrs(int, int, int, int); +static void addrsx(int, int, int, int, bool); +static int comp(const void *, const void *); +static coord finddpos(int, int, int, int); +static bool okdoor(int, int); +static void dodoor(int, int, struct mkroom *); +static void dosdoor(int, int, struct mkroom *, int); +static bool maker(schar, schar, schar, schar); +static void makecorridors(void); +static void join(int, int); +static void make_niches(void); +static void makevtele(void); +static void makeniche(bool); void makelevel(void) { struct mkroom *croom, *troom; unsigned tryct; - int x,y; + int x, y; nroom = 0; doorindex = 0; rooms[0].hx = -1; /* in case we are in a maze */ - for(x=0; x= rn1(3, 26)) { /* there might be several mazes */ + if (dlevel >= rn1(3, 26)) { /* there might be several mazes */ makemaz(); return; } @@ -74,38 +75,42 @@ makelevel(void) croom = &rooms[rn2(nroom)]; xdnstair = somex(); ydnstair = somey(); - levl[xdnstair][ydnstair].scrsym ='>'; + levl[xdnstair][ydnstair].scrsym = '>'; levl[xdnstair][ydnstair].typ = STAIRS; - if(nroom > 1) { + if (nroom > 1) { troom = croom; - croom = &rooms[rn2(nroom-1)]; - if(croom >= troom) croom++; + croom = &rooms[rn2(nroom - 1)]; + if (croom >= troom) + croom++; } xupstair = somex(); /* %% < and > might be in the same place */ yupstair = somey(); - levl[xupstair][yupstair].scrsym ='<'; + levl[xupstair][yupstair].scrsym = '<'; levl[xupstair][yupstair].typ = STAIRS; /* for each room: put things inside */ - for(croom = rooms; croom->hx > 0; croom++) { - + for (croom = rooms; croom->hx > 0; croom++) { /* put a sleeping monster inside */ - /* Note: monster may be on the stairs. This cannot be - avoided: maybe the player fell through a trapdoor - while a monster was on the stairs. Conclusion: - we have to check for monsters on the stairs anyway. */ - if(!rn2(3)) + /* + * Note: monster may be on the stairs. This cannot be + * avoided: maybe the player fell through a trapdoor while a + * monster was on the stairs. Conclusion: we have to check + * for monsters on the stairs anyway. + */ + if (!rn2(3)) makemon(NULL, somex(), somey()); /* put traps and mimics inside */ goldseen = FALSE; - while(!rn2(8-(dlevel/6))) mktrap(0,0,croom); - if(!goldseen && !rn2(3)) mkgold(0L,somex(),somey()); - if(!rn2(3)) { + while (!rn2(8 - (dlevel / 6))) + mktrap(0, 0, croom); + if (!goldseen && !rn2(3)) + mkgold(0L, somex(), somey()); + if (!rn2(3)) { mkobj_at(0, somex(), somey()); tryct = 0; - while(!rn2(5)) { - if(++tryct > 100){ + while (!rn2(5)) { + if (++tryct > 100) { printf("tryct overflow4\n"); break; } @@ -114,64 +119,69 @@ makelevel(void) } } - qsort((char *) rooms, nroom, sizeof(struct mkroom), comp); + qsort((char *)rooms, nroom, sizeof(struct mkroom), comp); makecorridors(); make_niches(); /* make a secret treasure vault, not connected to the rest */ - if(nroom <= (2*MAXNROFROOMS/3)) if(rn2(3)) { - troom = &rooms[nroom]; - secret = TRUE; - if(makerooms()) { - troom->rtype = VAULT; /* treasure vault */ - for(x = troom->lx; x <= troom->hx; x++) - for(y = troom->ly; y <= troom->hy; y++) - mkgold((long)(rnd(dlevel*100) + 50), x, y); - if(!rn2(3)) - makevtele(); + if (nroom <= (2 * MAXNROFROOMS / 3)) + if (rn2(3)) { + troom = &rooms[nroom]; + secret = TRUE; + if (makerooms()) { + troom->rtype = VAULT; /* treasure vault */ + for (x = troom->lx; x <= troom->hx; x++) + for (y = troom->ly; y <= troom->hy; y++) + mkgold((long)(rnd(dlevel * + 100) + 50), x, y); + if (!rn2(3)) + makevtele(); + } } - } #ifndef QUEST #ifdef WIZARD - if(wizard && getenv("SHOPTYPE")) mkshop(); else -#endif /* WIZARD */ - if(dlevel > 1 && dlevel < 20 && rn2(dlevel) < 3) mkshop(); - else - if(dlevel > 6 && !rn2(7)) mkzoo(ZOO); - else - if(dlevel > 9 && !rn2(5)) mkzoo(BEEHIVE); - else - if(dlevel > 11 && !rn2(6)) mkzoo(MORGUE); + if (wizard && getenv("SHOPTYPE")) + mkshop(); else - if(dlevel > 18 && !rn2(6)) mkswamp(); +#endif /* WIZARD */ + if (dlevel > 1 && dlevel < 20 && rn2(dlevel) < 3) + mkshop(); + else if (dlevel > 6 && !rn2(7)) + mkzoo(ZOO); + else if (dlevel > 9 && !rn2(5)) + mkzoo(BEEHIVE); + else if (dlevel > 11 && !rn2(6)) + mkzoo(MORGUE); + else if (dlevel > 18 && !rn2(6)) + mkswamp(); #endif /* QUEST */ } static bool makerooms(void) { -struct rectangle *rsp; -int lx, ly, hx, hy, lowx, lowy, hix, hiy, dx, dy; -int tryct = 0, xlim, ylim; + struct rectangle *rsp; + int lx, ly, hx, hy, lowx, lowy, hix, hiy, dx, dy; + int tryct = 0, xlim, ylim; /* init */ xlim = XLIM + secret; ylim = YLIM + secret; - if(nroom == 0) { + if (nroom == 0) { rsp = rs; rsp->rlx = rsp->rly = 0; - rsp->rhx = COLNO-1; - rsp->rhy = ROWNO-1; + rsp->rhx = COLNO - 1; + rsp->rhy = ROWNO - 1; rsmax = 1; } rscnt = rsmax; /* make rooms until satisfied */ - while(rscnt > 0 && nroom < MAXNROFROOMS-1) { - if(!secret && nroom > (MAXNROFROOMS/3) && - !rn2((MAXNROFROOMS-nroom)*(MAXNROFROOMS-nroom))) - return(0); + while (rscnt > 0 && nroom < MAXNROFROOMS - 1) { + if (!secret && nroom > (MAXNROFROOMS / 3) && + !rn2((MAXNROFROOMS - nroom) * (MAXNROFROOMS - nroom))) + return (0); /* pick a rectangle */ rsp = &rs[rn2(rscnt)]; @@ -181,20 +191,20 @@ int tryct = 0, xlim, ylim; ly = rsp->rly; /* find size of room */ - if(secret) + if (secret) dx = dy = 1; else { - dx = 2 + rn2((hx-lx-8 > 20) ? 12 : 8); + dx = 2 + rn2((hx - lx - 8 > 20) ? 12 : 8); dy = 2 + rn2(4); - if(dx*dy > 50) - dy = 50/dx; + if (dx * dy > 50) + dy = 50 / dx; } /* look whether our room will fit */ - if(hx-lx < dx + dx/2 + 2*xlim || hy-ly < dy + dy/3 + 2*ylim) { - /* no, too small */ - /* maybe we throw this area out */ - if(secret || !rn2(MAXNROFROOMS+1-nroom-tryct)) { + if (hx - lx < dx + dx / 2 + 2 * xlim || hy - ly < dy + dy / 3 + 2 * ylim) { + /* no, too small */ + /* maybe we throw this area out */ + if (secret || !rn2(MAXNROFROOMS + 1 - nroom - tryct)) { rscnt--; rs[rsmax] = *rsp; *rsp = rs[rscnt]; @@ -205,81 +215,80 @@ int tryct = 0, xlim, ylim; continue; } - lowx = lx + xlim + rn2(hx - lx - dx - 2*xlim + 1); - lowy = ly + ylim + rn2(hy - ly - dy - 2*ylim + 1); + lowx = lx + xlim + rn2(hx - lx - dx - 2 * xlim + 1); + lowy = ly + ylim + rn2(hy - ly - dy - 2 * ylim + 1); hix = lowx + dx; hiy = lowy + dy; - if(maker(lowx, dx, lowy, dy)) { - if(secret) - return(1); - addrs(lowx-1, lowy-1, hix+1, hiy+1); + if (maker(lowx, dx, lowy, dy)) { + if (secret) + return (1); + addrs(lowx - 1, lowy - 1, hix + 1, hiy + 1); tryct = 0; - } else - if(tryct++ > 100) - break; + } else if (tryct++ > 100) + break; } - return(0); /* failed to make vault - very strange */ + return (0); /* failed to make vault - very strange */ } static void addrs(int lowx, int lowy, int hix, int hiy) { struct rectangle *rsp; - int lx,ly,hx,hy,xlim,ylim; + int lx, ly, hx, hy, xlim, ylim; boolean discarded; xlim = XLIM + secret; ylim = YLIM + secret; /* walk down since rscnt and rsmax change */ - for(rsp = &rs[rsmax-1]; rsp >= rs; rsp--) { - - if((lx = rsp->rlx) > hix || (ly = rsp->rly) > hiy || - (hx = rsp->rhx) < lowx || (hy = rsp->rhy) < lowy) + for (rsp = &rs[rsmax - 1]; rsp >= rs; rsp--) { + if ((lx = rsp->rlx) > hix || (ly = rsp->rly) > hiy || + (hx = rsp->rhx) < lowx || (hy = rsp->rhy) < lowy) continue; - if((discarded = (rsp >= &rs[rscnt]))) { + if ((discarded = (rsp >= &rs[rscnt]))) { *rsp = rs[--rsmax]; } else { rsmax--; rscnt--; *rsp = rs[rscnt]; - if(rscnt != rsmax) + if (rscnt != rsmax) rs[rscnt] = rs[rsmax]; } - if(lowy - ly > 2*ylim + 4) - addrsx(lx,ly,hx,lowy-2,discarded); - if(lowx - lx > 2*xlim + 4) - addrsx(lx,ly,lowx-2,hy,discarded); - if(hy - hiy > 2*ylim + 4) - addrsx(lx,hiy+2,hx,hy,discarded); - if(hx - hix > 2*xlim + 4) - addrsx(hix+2,ly,hx,hy,discarded); + if (lowy - ly > 2 * ylim + 4) + addrsx(lx, ly, hx, lowy - 2, discarded); + if (lowx - lx > 2 * xlim + 4) + addrsx(lx, ly, lowx - 2, hy, discarded); + if (hy - hiy > 2 * ylim + 4) + addrsx(lx, hiy + 2, hx, hy, discarded); + if (hx - hix > 2 * xlim + 4) + addrsx(hix + 2, ly, hx, hy, discarded); } } -/* discarded = piece of a discarded area */ +/* discarded: piece of a discarded area */ static void addrsx(int lx, int ly, int hx, int hy, bool discarded) { struct rectangle *rsp; /* check inclusions */ - for(rsp = rs; rsp < &rs[rsmax]; rsp++) { - if(lx >= rsp->rlx && hx <= rsp->rhx && - ly >= rsp->rly && hy <= rsp->rhy) + for (rsp = rs; rsp < &rs[rsmax]; rsp++) { + if (lx >= rsp->rlx && hx <= rsp->rhx && + ly >= rsp->rly && hy <= rsp->rhy) return; } /* make a new entry */ - if(rsmax >= MAXRS) { + if (rsmax >= MAXRS) { #ifdef WIZARD - if(wizard) pline("MAXRS may be too small."); + if (wizard) + pline("MAXRS may be too small."); #endif /* WIZARD */ return; } rsmax++; - if(!discarded) { + if (!discarded) { *rsp = rs[rscnt]; rsp = &rs[rscnt]; rscnt++; @@ -294,63 +303,67 @@ static int comp(const void *vx, const void *vy) { const struct mkroom *x, *y; + x = vx; y = vy; - if(x->lx < y->lx) return(-1); - return(x->lx > y->lx); + if (x->lx < y->lx) + return (-1); + return (x->lx > y->lx); } static coord finddpos(int xl, int yl, int xh, int yh) { coord ff; - int x,y; + int x, y; - x = (xl == xh) ? xl : (xl + rn2(xh-xl+1)); - y = (yl == yh) ? yl : (yl + rn2(yh-yl+1)); - if(okdoor(x, y)) + x = (xl == xh) ? xl : (xl + rn2(xh - xl + 1)); + y = (yl == yh) ? yl : (yl + rn2(yh - yl + 1)); + if (okdoor(x, y)) goto gotit; - for(x = xl; x <= xh; x++) for(y = yl; y <= yh; y++) - if(okdoor(x, y)) - goto gotit; + for (x = xl; x <= xh; x++) + for (y = yl; y <= yh; y++) + if (okdoor(x, y)) + goto gotit; - for(x = xl; x <= xh; x++) for(y = yl; y <= yh; y++) - if(levl[x][y].typ == DOOR || levl[x][y].typ == SDOOR) - goto gotit; + for (x = xl; x <= xh; x++) + for (y = yl; y <= yh; y++) + if (levl[x][y].typ == DOOR || levl[x][y].typ == SDOOR) + goto gotit; /* cannot find something reasonable -- strange */ x = xl; y = yh; gotit: ff.x = x; ff.y = y; - return(ff); + return (ff); } /* see whether it is allowable to create a door at [x,y] */ static bool okdoor(int x, int y) { - if(levl[x-1][y].typ == DOOR || levl[x+1][y].typ == DOOR || - levl[x][y+1].typ == DOOR || levl[x][y-1].typ == DOOR || - levl[x-1][y].typ == SDOOR || levl[x+1][y].typ == SDOOR || - levl[x][y-1].typ == SDOOR || levl[x][y+1].typ == SDOOR || - (levl[x][y].typ != HWALL && levl[x][y].typ != VWALL) || - doorindex >= DOORMAX) - return(0); - return(1); + if (levl[x - 1][y].typ == DOOR || levl[x + 1][y].typ == DOOR || + levl[x][y + 1].typ == DOOR || levl[x][y - 1].typ == DOOR || + levl[x - 1][y].typ == SDOOR || levl[x + 1][y].typ == SDOOR || + levl[x][y - 1].typ == SDOOR || levl[x][y + 1].typ == SDOOR || + (levl[x][y].typ != HWALL && levl[x][y].typ != VWALL) || + doorindex >= DOORMAX) + return (0); + return (1); } static void dodoor(int x, int y, struct mkroom *aroom) { - if(doorindex >= DOORMAX) { + if (doorindex >= DOORMAX) { impossible("DOORMAX exceeded?"); return; } - if(!okdoor(x,y) && nxcor) + if (!okdoor(x, y) && nxcor) return; - dosdoor(x,y,aroom,rn2(8) ? DOOR : SDOOR); + dosdoor(x, y, aroom, rn2(8) ? DOOR : SDOOR); } static void @@ -359,20 +372,23 @@ dosdoor(int x, int y, struct mkroom *aroom, int type) struct mkroom *broom; int tmp; - if(!IS_WALL(levl[x][y].typ)) /* avoid SDOORs with '+' as scrsym */ + if (!IS_WALL(levl[x][y].typ)) /* avoid SDOORs with '+' as scrsym */ type = DOOR; levl[x][y].typ = type; - if(type == DOOR) + if (type == DOOR) levl[x][y].scrsym = '+'; aroom->doorct++; - broom = aroom+1; - if(broom->hx < 0) tmp = doorindex; else - for(tmp = doorindex; tmp > broom->fdoor; tmp--) - doors[tmp] = doors[tmp-1]; + broom = aroom + 1; + if (broom->hx < 0) + tmp = doorindex; + else + for (tmp = doorindex; tmp > broom->fdoor; tmp--) + doors[tmp] = doors[tmp - 1]; doorindex++; doors[tmp].x = x; doors[tmp].y = y; - for( ; broom->hx >= 0; broom++) broom->fdoor++; + for (; broom->hx >= 0; broom++) + broom->fdoor++; } /* Only called from makerooms() */ @@ -380,34 +396,41 @@ static bool maker(schar lowx, schar ddx, schar lowy, schar ddy) { struct mkroom *croom; - int x, y, hix = lowx+ddx, hiy = lowy+ddy; + int x, y, hix = lowx + ddx, hiy = lowy + ddy; int xlim = XLIM + secret, ylim = YLIM + secret; - if(nroom >= MAXNROFROOMS) return(0); - if(lowx < XLIM) lowx = XLIM; - if(lowy < YLIM) lowy = YLIM; - if(hix > COLNO-XLIM-1) hix = COLNO-XLIM-1; - if(hiy > ROWNO-YLIM-1) hiy = ROWNO-YLIM-1; + if (nroom >= MAXNROFROOMS) + return (0); + if (lowx < XLIM) + lowx = XLIM; + if (lowy < YLIM) + lowy = YLIM; + if (hix > COLNO - XLIM - 1) + hix = COLNO - XLIM - 1; + if (hiy > ROWNO - YLIM - 1) + hiy = ROWNO - YLIM - 1; chk: - if(hix <= lowx || hiy <= lowy) return(0); + if (hix <= lowx || hiy <= lowy) + return (0); /* check area around room (and make room smaller if necessary) */ - for(x = lowx - xlim; x <= hix + xlim; x++) { - for(y = lowy - ylim; y <= hiy + ylim; y++) { - if(levl[x][y].typ) { + for (x = lowx - xlim; x <= hix + xlim; x++) { + for (y = lowy - ylim; y <= hiy + ylim; y++) { + if (levl[x][y].typ) { #ifdef WIZARD - if(wizard && !secret) - pline("Strange area [%d,%d] in maker().",x,y); + if (wizard && !secret) + pline("Strange area [%d,%d] in maker().", x, y); #endif /* WIZARD */ - if(!rn2(3)) return(0); - if(x < lowx) - lowx = x+xlim+1; + if (!rn2(3)) + return (0); + if (x < lowx) + lowx = x + xlim + 1; else - hix = x-xlim-1; - if(y < lowy) - lowy = y+ylim+1; + hix = x - xlim - 1; + if (y < lowy) + lowy = y + ylim + 1; else - hiy = y-ylim-1; + hiy = y - ylim - 1; goto chk; } } @@ -417,9 +440,9 @@ chk: /* on low levels the room is lit (usually) */ /* secret vaults are always lit */ - if((rnd(dlevel) < 10 && rn2(77)) || (ddx == 1 && ddy == 1)) { - for(x = lowx-1; x <= hix+1; x++) - for(y = lowy-1; y <= hiy+1; y++) + if ((rnd(dlevel) < 10 && rn2(77)) || (ddx == 1 && ddy == 1)) { + for (x = lowx - 1; x <= hix + 1; x++) + for (y = lowy - 1; y <= hiy + 1; y++) levl[x][y].lit = 1; croom->rlit = 1; } else @@ -430,57 +453,58 @@ chk: croom->hy = hiy; croom->rtype = croom->doorct = croom->fdoor = 0; - for(x = lowx-1; x <= hix+1; x++) - for(y = lowy-1; y <= hiy+1; y += (hiy-lowy+2)) { - levl[x][y].scrsym = '-'; - levl[x][y].typ = HWALL; - } - for(x = lowx-1; x <= hix+1; x += (hix-lowx+2)) - for(y = lowy; y <= hiy; y++) { - levl[x][y].scrsym = '|'; - levl[x][y].typ = VWALL; - } - for(x = lowx; x <= hix; x++) - for(y = lowy; y <= hiy; y++) { - levl[x][y].scrsym = '.'; - levl[x][y].typ = ROOM; - } + for (x = lowx - 1; x <= hix + 1; x++) + for (y = lowy - 1; y <= hiy + 1; y += (hiy - lowy + 2)) { + levl[x][y].scrsym = '-'; + levl[x][y].typ = HWALL; + } + for (x = lowx - 1; x <= hix + 1; x += (hix - lowx + 2)) + for (y = lowy; y <= hiy; y++) { + levl[x][y].scrsym = '|'; + levl[x][y].typ = VWALL; + } + for (x = lowx; x <= hix; x++) + for (y = lowy; y <= hiy; y++) { + levl[x][y].scrsym = '.'; + levl[x][y].typ = ROOM; + } smeq[nroom] = nroom; croom++; croom->hx = -1; nroom++; - return(1); + return (1); } static void makecorridors(void) { - int a,b; + int a, b; nxcor = 0; - for(a = 0; a < nroom-1; a++) - join(a, a+1); - for(a = 0; a < nroom-2; a++) - if(smeq[a] != smeq[a+2]) - join(a, a+2); - for(a = 0; a < nroom; a++) - for(b = 0; b < nroom; b++) - if(smeq[a] != smeq[b]) - join(a, b); - if(nroom > 2) - for(nxcor = rn2(nroom) + 4; nxcor; nxcor--) { - a = rn2(nroom); - b = rn2(nroom-2); - if(b >= a) b += 2; - join(a, b); - } + for (a = 0; a < nroom - 1; a++) + join(a, a + 1); + for (a = 0; a < nroom - 2; a++) + if (smeq[a] != smeq[a + 2]) + join(a, a + 2); + for (a = 0; a < nroom; a++) + for (b = 0; b < nroom; b++) + if (smeq[a] != smeq[b]) + join(a, b); + if (nroom > 2) + for (nxcor = rn2(nroom) + 4; nxcor; nxcor--) { + a = rn2(nroom); + b = rn2(nroom - 2); + if (b >= a) + b += 2; + join(a, b); + } } static void join(int a, int b) { - coord cc,tt; + coord cc, tt; int tx, ty, xx, yy; struct rm *crm; struct mkroom *croom, *troom; @@ -489,130 +513,131 @@ join(int a, int b) croom = &rooms[a]; troom = &rooms[b]; - /* find positions cc and tt for doors in croom and troom - and direction for a corridor between them */ + /* + * find positions cc and tt for doors in croom and troom and + * direction for a corridor between them + */ - if(troom->hx < 0 || croom->hx < 0 || doorindex >= DOORMAX) return; - if(troom->lx > croom->hx) { + if (troom->hx < 0 || croom->hx < 0 || doorindex >= DOORMAX) + return; + if (troom->lx > croom->hx) { dx = 1; dy = 0; - xx = croom->hx+1; - tx = troom->lx-1; - cc = finddpos(xx,croom->ly,xx,croom->hy); - tt = finddpos(tx,troom->ly,tx,troom->hy); - } else if(troom->hy < croom->ly) { + xx = croom->hx + 1; + tx = troom->lx - 1; + cc = finddpos(xx, croom->ly, xx, croom->hy); + tt = finddpos(tx, troom->ly, tx, troom->hy); + } else if (troom->hy < croom->ly) { dy = -1; dx = 0; - yy = croom->ly-1; - cc = finddpos(croom->lx,yy,croom->hx,yy); - ty = troom->hy+1; - tt = finddpos(troom->lx,ty,troom->hx,ty); - } else if(troom->hx < croom->lx) { + yy = croom->ly - 1; + cc = finddpos(croom->lx, yy, croom->hx, yy); + ty = troom->hy + 1; + tt = finddpos(troom->lx, ty, troom->hx, ty); + } else if (troom->hx < croom->lx) { dx = -1; dy = 0; - xx = croom->lx-1; - tx = troom->hx+1; - cc = finddpos(xx,croom->ly,xx,croom->hy); - tt = finddpos(tx,troom->ly,tx,troom->hy); + xx = croom->lx - 1; + tx = troom->hx + 1; + cc = finddpos(xx, croom->ly, xx, croom->hy); + tt = finddpos(tx, troom->ly, tx, troom->hy); } else { dy = 1; dx = 0; - yy = croom->hy+1; - ty = troom->ly-1; - cc = finddpos(croom->lx,yy,croom->hx,yy); - tt = finddpos(troom->lx,ty,troom->hx,ty); + yy = croom->hy + 1; + ty = troom->ly - 1; + cc = finddpos(croom->lx, yy, croom->hx, yy); + tt = finddpos(troom->lx, ty, troom->hx, ty); } xx = cc.x; yy = cc.y; tx = tt.x - dx; ty = tt.y - dy; - if(nxcor && levl[xx+dx][yy+dy].typ) + if (nxcor && levl[xx + dx][yy + dy].typ) return; - dodoor(xx,yy,croom); + dodoor(xx, yy, croom); cct = 0; - while(xx != tx || yy != ty) { - xx += dx; - yy += dy; - - /* loop: dig corridor at [xx,yy] and find new [xx,yy] */ - if(cct++ > 500 || (nxcor && !rn2(35))) - return; - - if(xx == COLNO-1 || xx == 0 || yy == 0 || yy == ROWNO-1) - return; /* impossible */ - - crm = &levl[xx][yy]; - if(!(crm->typ)) { - if(rn2(100)) { - crm->typ = CORR; - crm->scrsym = CORR_SYM; - if(nxcor && !rn2(50)) - mkobj_at(ROCK_SYM, xx, yy); - } else { - crm->typ = SCORR; - crm->scrsym = ' '; - } - } else - if(crm->typ != CORR && crm->typ != SCORR) { - /* strange ... */ - return; - } + while (xx != tx || yy != ty) { + xx += dx; + yy += dy; - /* find next corridor position */ - dix = abs(xx-tx); - diy = abs(yy-ty); + /* loop: dig corridor at [xx,yy] and find new [xx,yy] */ + if (cct++ > 500 || (nxcor && !rn2(35))) + return; - /* do we have to change direction ? */ - if(dy && dix > diy) { - int ddx = (xx > tx) ? -1 : 1; + if (xx == COLNO - 1 || xx == 0 || yy == 0 || yy == ROWNO - 1) + return; /* impossible */ - crm = &levl[xx+ddx][yy]; - if(!crm->typ || crm->typ == CORR || crm->typ == SCORR) { - dx = ddx; - dy = 0; - continue; + crm = &levl[xx][yy]; + if (!(crm->typ)) { + if (rn2(100)) { + crm->typ = CORR; + crm->scrsym = CORR_SYM; + if (nxcor && !rn2(50)) + mkobj_at(ROCK_SYM, xx, yy); + } else { + crm->typ = SCORR; + crm->scrsym = ' '; + } + } else if (crm->typ != CORR && crm->typ != SCORR) { + /* strange ... */ + return; } - } else if(dx && diy > dix) { - int ddy = (yy > ty) ? -1 : 1; - - crm = &levl[xx][yy+ddy]; - if(!crm->typ || crm->typ == CORR || crm->typ == SCORR) { - dy = ddy; - dx = 0; - continue; + /* find next corridor position */ + dix = abs(xx - tx); + diy = abs(yy - ty); + + /* do we have to change direction ? */ + if (dy && dix > diy) { + int ddx = (xx > tx) ? -1 : 1; + + crm = &levl[xx + ddx][yy]; + if (!crm->typ || crm->typ == CORR || crm->typ == SCORR) { + dx = ddx; + dy = 0; + continue; + } + } else if (dx && diy > dix) { + int ddy = (yy > ty) ? -1 : 1; + + crm = &levl[xx][yy + ddy]; + if (!crm->typ || crm->typ == CORR || crm->typ == SCORR) { + dy = ddy; + dx = 0; + continue; + } } - } - /* continue straight on? */ - crm = &levl[xx+dx][yy+dy]; - if(!crm->typ || crm->typ == CORR || crm->typ == SCORR) - continue; + /* continue straight on? */ + crm = &levl[xx + dx][yy + dy]; + if (!crm->typ || crm->typ == CORR || crm->typ == SCORR) + continue; - /* no, what must we do now?? */ - if(dx) { - dx = 0; - dy = (ty < yy) ? -1 : 1; - crm = &levl[xx+dx][yy+dy]; - if(!crm->typ || crm->typ == CORR || crm->typ == SCORR) - continue; - dy = -dy; - continue; - } else { - dy = 0; - dx = (tx < xx) ? -1 : 1; - crm = &levl[xx+dx][yy+dy]; - if(!crm->typ || crm->typ == CORR || crm->typ == SCORR) - continue; - dx = -dx; - continue; - } + /* no, what must we do now?? */ + if (dx) { + dx = 0; + dy = (ty < yy) ? -1 : 1; + crm = &levl[xx + dx][yy + dy]; + if (!crm->typ || crm->typ == CORR || crm->typ == SCORR) + continue; + dy = -dy; + continue; + } else { + dy = 0; + dx = (tx < xx) ? -1 : 1; + crm = &levl[xx + dx][yy + dy]; + if (!crm->typ || crm->typ == CORR || crm->typ == SCORR) + continue; + dx = -dx; + continue; + } } /* we succeeded in digging the corridor */ dodoor(tt.x, tt.y, troom); - if(smeq[a] < smeq[b]) + if (smeq[a] < smeq[b]) smeq[b] = smeq[a]; else smeq[a] = smeq[b]; @@ -621,8 +646,9 @@ join(int a, int b) static void make_niches(void) { - int ct = rnd(nroom/2 + 1); - while(ct--) makeniche(FALSE); + int ct = rnd(nroom / 2 + 1); + while (ct--) + makeniche(FALSE); } static void @@ -638,45 +664,53 @@ makeniche(bool with_trap) struct rm *rm; int vct = 8; coord dd; - int dy,xx,yy; + int dy, xx, yy; struct trap *ttmp; - if(doorindex < DOORMAX) - while(vct--) { - aroom = &rooms[rn2(nroom-1)]; - if(aroom->rtype != 0) continue; /* not an ordinary room */ - if(aroom->doorct == 1 && rn2(5)) continue; - if(rn2(2)) { - dy = 1; - dd = finddpos(aroom->lx,aroom->hy+1,aroom->hx,aroom->hy+1); - } else { - dy = -1; - dd = finddpos(aroom->lx,aroom->ly-1,aroom->hx,aroom->ly-1); - } - xx = dd.x; - yy = dd.y; - if((rm = &levl[xx][yy+dy])->typ) continue; - if(with_trap || !rn2(4)) { - rm->typ = SCORR; - rm->scrsym = ' '; - if(with_trap) { - ttmp = maketrap(xx, yy+dy, TELEP_TRAP); - ttmp->once = 1; - make_engr_at(xx, yy-dy, "ad ae?ar um"); - } - dosdoor(xx, yy, aroom, SDOOR); - } else { - rm->typ = CORR; - rm->scrsym = CORR_SYM; - if(rn2(7)) - dosdoor(xx, yy, aroom, rn2(5) ? SDOOR : DOOR); - else { - mksobj_at(SCR_TELEPORTATION, xx, yy+dy); - if(!rn2(3)) mkobj_at(0, xx, yy+dy); + if (doorindex < DOORMAX) + while (vct--) { + aroom = &rooms[rn2(nroom - 1)]; + if (aroom->rtype != 0) /* not an ordinary room */ + continue; + if (aroom->doorct == 1 && rn2(5)) + continue; + if (rn2(2)) { + dy = 1; + dd = finddpos(aroom->lx, aroom->hy + 1, + aroom->hx, + aroom->hy + 1); + } else { + dy = -1; + dd = finddpos(aroom->lx, aroom->ly - 1, + aroom->hx, + aroom->ly - 1); + } + xx = dd.x; + yy = dd.y; + if ((rm = &levl[xx][yy + dy])->typ) + continue; + if (with_trap || !rn2(4)) { + rm->typ = SCORR; + rm->scrsym = ' '; + if (with_trap) { + ttmp = maketrap(xx, yy + dy, TELEP_TRAP); + ttmp->once = 1; + make_engr_at(xx, yy - dy, "ad ae?ar um"); + } + dosdoor(xx, yy, aroom, SDOOR); + } else { + rm->typ = CORR; + rm->scrsym = CORR_SYM; + if (rn2(7)) + dosdoor(xx, yy, aroom, rn2(5) ? SDOOR : DOOR); + else { + mksobj_at(SCR_TELEPORTATION, xx, yy + dy); + if (!rn2(3)) + mkobj_at(0, xx, yy + dy); + } + } + return; } - } - return; - } } /* make a trap somewhere (in croom if mazeflag = 0) */ @@ -684,39 +718,45 @@ void mktrap(int num, int mazeflag, struct mkroom *croom) { struct trap *ttmp; - int kind,nopierc,nomimic,fakedoor,fakegold,tryct = 0; - xchar mx,my; + int kind, nopierc, nomimic, fakedoor, fakegold, tryct = 0; + xchar mx, my; - if(!num || num >= TRAPNUM) { + if (!num || num >= TRAPNUM) { nopierc = (dlevel < 4) ? 1 : 0; - nomimic = (dlevel < 9 || goldseen ) ? 1 : 0; - if(index(fut_geno, 'M')) nomimic = 1; + nomimic = (dlevel < 9 || goldseen) ? 1 : 0; + if (strchr(fut_geno, 'M')) + nomimic = 1; kind = rn2(TRAPNUM - nopierc - nomimic); /* note: PIERC = 7, MIMIC = 8, TRAPNUM = 9 */ - } else kind = num; + } else + kind = num; - if(kind == MIMIC) { + if (kind == MIMIC) { struct monst *mtmp; fakedoor = (!rn2(3) && !mazeflag); fakegold = (!fakedoor && !rn2(2)); - if(fakegold) goldseen = TRUE; + if (fakegold) + goldseen = TRUE; do { - if(++tryct > 200) return; - if(fakedoor) { + if (++tryct > 200) + return; + if (fakedoor) { /* note: fakedoor maybe on actual door */ - if(rn2(2)){ - if(rn2(2)) - mx = croom->hx+1; - else mx = croom->lx-1; + if (rn2(2)) { + if (rn2(2)) + mx = croom->hx + 1; + else + mx = croom->lx - 1; my = somey(); } else { - if(rn2(2)) - my = croom->hy+1; - else my = croom->ly-1; + if (rn2(2)) + my = croom->hy + 1; + else + my = croom->ly - 1; mx = somex(); } - } else if(mazeflag) { + } else if (mazeflag) { coord mm; mm = mazexy(); mx = mm.x; @@ -725,21 +765,21 @@ mktrap(int num, int mazeflag, struct mkroom *croom) mx = somex(); my = somey(); } - } while(m_at(mx,my) || levl[mx][my].typ == STAIRS); - if((mtmp = makemon(PM_MIMIC,mx,my))) { - mtmp->mimic = 1; - mtmp->mappearance = - fakegold ? '$' : fakedoor ? '+' : - (mazeflag && rn2(2)) ? AMULET_SYM : - "=/)%?![<>" [ rn2(9) ]; + } while (m_at(mx, my) || levl[mx][my].typ == STAIRS); + if ((mtmp = makemon(PM_MIMIC, mx, my)) != NULL) { + mtmp->mimic = 1; + mtmp->mappearance = + fakegold ? '$' : fakedoor ? '+' : + (mazeflag && rn2(2)) ? AMULET_SYM : + "=/)%?![<>"[rn2(9)]; } return; } do { - if(++tryct > 200) + if (++tryct > 200) return; - if(mazeflag){ + if (mazeflag) { coord mm; mm = mazexy(); mx = mm.x; @@ -748,8 +788,8 @@ mktrap(int num, int mazeflag, struct mkroom *croom) mx = somex(); my = somey(); } - } while(t_at(mx, my) || levl[mx][my].typ == STAIRS); + } while (t_at(mx, my) || levl[mx][my].typ == STAIRS); ttmp = maketrap(mx, my, kind); - if(mazeflag && !rn2(10) && ttmp->ttyp < PIERC) + if (mazeflag && !rn2(10) && ttmp->ttyp < PIERC) ttmp->tseen = 1; } diff --git a/games/hack/hack.mkmaze.c b/games/hack/hack.mkmaze.c index 9c6c7fc39c..29800c0fb2 100644 --- a/games/hack/hack.mkmaze.c +++ b/games/hack/hack.mkmaze.c @@ -8,53 +8,57 @@ extern struct permonst pm_wizard; struct permonst hell_hound = { "hell hound", 'd', 12, 14, 2, 3, 6, 0 }; -static void walkfrom(int, int); -static void move(int *, int *, int); -static bool okay(int, int, int); +static void walkfrom(int, int); +static void move(int *, int *, int); +static bool okay(int, int, int); void makemaz(void) { - int x,y; - int zx,zy; + int x, y; + int zx, zy; coord mm; boolean al = (dlevel >= 30 && !flags.made_amulet); - for(x = 2; x < COLNO-1; x++) - for(y = 2; y < ROWNO-1; y++) - levl[x][y].typ = (x%2 && y%2) ? 0 : HWALL; - if(al) { - struct monst *mtmp; + for (x = 2; x < COLNO - 1; x++) + for (y = 2; y < ROWNO - 1; y++) + levl[x][y].typ = (x % 2 && y % 2) ? 0 : HWALL; + if (al) { + struct monst *mtmp; - zx = 2*(COLNO/4) - 1; - zy = 2*(ROWNO/4) - 1; - for(x = zx-2; x < zx+4; x++) for(y = zy-2; y <= zy+2; y++) { - levl[x][y].typ = - (y == zy-2 || y == zy+2 || x == zx-2 || x == zx+3) ? POOL : - (y == zy-1 || y == zy+1 || x == zx-1 || x == zx+2) ? HWALL: - ROOM; - } - mkobj_at(AMULET_SYM, zx, zy); - flags.made_amulet = 1; - walkfrom(zx+4, zy); - if((mtmp = makemon(&hell_hound, zx, zy))) - mtmp->msleep = 1; - if((mtmp = makemon(PM_WIZARD, zx+1, zy))) { - mtmp->msleep = 1; - flags.no_of_wizards = 1; - } + zx = 2 * (COLNO / 4) - 1; + zy = 2 * (ROWNO / 4) - 1; + for (x = zx - 2; x < zx + 4; x++) + for (y = zy - 2; y <= zy + 2; y++) { + levl[x][y].typ = + (y == zy - 2 || y == zy + 2 || x == + zx - 2 || x == zx + 3) ? POOL : + (y == zy - 1 || y == zy + 1 || x == + zx - 1 || x == zx + 2) ? HWALL : + ROOM; + } + + mkobj_at(AMULET_SYM, zx, zy); + flags.made_amulet = 1; + walkfrom(zx + 4, zy); + if ((mtmp = makemon(&hell_hound, zx, zy)) != NULL) + mtmp->msleep = 1; + if ((mtmp = makemon(PM_WIZARD, zx + 1, zy)) != NULL) { + mtmp->msleep = 1; + flags.no_of_wizards = 1; + } } else { - mm = mazexy(); - zx = mm.x; - zy = mm.y; - walkfrom(zx,zy); - mksobj_at(WAN_WISHING, zx, zy); - mkobj_at(ROCK_SYM, zx, zy); /* put a rock on top of it */ + mm = mazexy(); + zx = mm.x; + zy = mm.y; + walkfrom(zx, zy); + mksobj_at(WAN_WISHING, zx, zy); + mkobj_at(ROCK_SYM, zx, zy); /* put a rock on top of it */ } - for(x = 2; x < COLNO-1; x++) - for(y = 2; y < ROWNO-1; y++) { - switch(levl[x][y].typ) { + for (x = 2; x < COLNO - 1; x++) + for (y = 2; y < ROWNO - 1; y++) { + switch (levl[x][y].typ) { case HWALL: levl[x][y].scrsym = '-'; break; @@ -63,26 +67,26 @@ makemaz(void) break; } } - for(x = rn1(8,11); x; x--) { + for (x = rn1(8, 11); x; x--) { mm = mazexy(); mkobj_at(rn2(2) ? GEM_SYM : 0, mm.x, mm.y); } - for(x = rn1(10,2); x; x--) { + for (x = rn1(10, 2); x; x--) { mm = mazexy(); mkobj_at(ROCK_SYM, mm.x, mm.y); } mm = mazexy(); makemon(PM_MINOTAUR, mm.x, mm.y); - for(x = rn1(5,7); x; x--) { + for (x = rn1(5, 7); x; x--) { mm = mazexy(); makemon(NULL, mm.x, mm.y); } - for(x = rn1(6,7); x; x--) { + for (x = rn1(6, 7); x; x--) { mm = mazexy(); - mkgold(0L,mm.x,mm.y); + mkgold(0L, mm.x, mm.y); } - for(x = rn1(6,7); x; x--) - mktrap(0,1,NULL); + for (x = rn1(6, 7); x; x--) + mktrap(0, 1, NULL); mm = mazexy(); levl[(xupstair = mm.x)][(yupstair = mm.y)].scrsym = '<'; levl[xupstair][yupstair].typ = STAIRS; @@ -92,49 +96,62 @@ makemaz(void) static void walkfrom(int x, int y) { -int q,a,dir; -int dirs[4]; + int q, a, dir; + int dirs[4]; + levl[x][y].typ = ROOM; - while(1) { + for (;;) { q = 0; - for(a = 0; a < 4; a++) - if(okay(x,y,a)) dirs[q++]= a; - if(!q) return; + for (a = 0; a < 4; a++) + if (okay(x, y, a)) + dirs[q++] = a; + if (!q) + return; dir = dirs[rn2(q)]; - move(&x,&y,dir); + move(&x, &y, dir); levl[x][y].typ = ROOM; - move(&x,&y,dir); - walkfrom(x,y); + move(&x, &y, dir); + walkfrom(x, y); } } static void move(int *x, int *y, int dir) { - switch(dir){ - case 0: --(*y); break; - case 1: (*x)++; break; - case 2: (*y)++; break; - case 3: --(*x); break; + switch (dir) { + case 0: + --(*y); + break; + case 1: + (*x)++; + break; + case 2: + (*y)++; + break; + case 3: + --(*x); + break; } } static bool okay(int x, int y, int dir) { - move(&x,&y,dir); - move(&x,&y,dir); - if(x<3 || y<3 || x>COLNO-3 || y>ROWNO-3 || levl[x][y].typ != 0) - return(0); + move(&x, &y, dir); + move(&x, &y, dir); + if (x < 3 || y < 3 || x > COLNO - 3 || y > ROWNO - 3 || + levl[x][y].typ != 0) + return (0); else - return(1); + return (1); } coord mazexy(void) { coord mm; - mm.x = 3 + 2*rn2(COLNO/2 - 2); - mm.y = 3 + 2*rn2(ROWNO/2 - 2); - return mm; + + mm.x = 3 + 2 * rn2(COLNO / 2 - 2); + mm.y = 3 + 2 * rn2(ROWNO / 2 - 2); + return (mm); } diff --git a/games/hack/hack.mkobj.c b/games/hack/hack.mkobj.c index c24018837e..cf44d1a759 100644 --- a/games/hack/hack.mkobj.c +++ b/games/hack/hack.mkobj.c @@ -11,17 +11,19 @@ struct obj * mkobj_at(int let, int x, int y) { struct obj *otmp = mkobj(let); + otmp->ox = x; otmp->oy = y; otmp->nobj = fobj; fobj = otmp; - return(otmp); + return (otmp); } void mksobj_at(int otyp, int x, int y) { struct obj *otmp = mksobj(otyp); + otmp->ox = x; otmp->oy = y; otmp->nobj = fobj; @@ -31,18 +33,19 @@ mksobj_at(int otyp, int x, int y) struct obj * mkobj(int let) { - if(!let) + if (!let) let = mkobjstr[rn2(sizeof(mkobjstr) - 1)]; - return( - mksobj( - letter(let) ? - CORPSE + ((let > 'Z') ? (let-'a'+'Z'-'@'+1) : (let-'@')) - : probtype(let) - ) - ); + return ( + mksobj( + letter(let) ? + CORPSE + + ((let > 'Z') ? (let - 'a' + 'Z' - '@' + + 1) : (let - '@')) + : probtype(let) + ) + ); } - struct obj zeroobj; struct obj * @@ -58,24 +61,26 @@ mksobj(int otyp) otmp->quan = 1; otmp->olet = let; otmp->otyp = otyp; - otmp->dknown = index("/=!?*", let) ? 0 : 1; - switch(let) { + otmp->dknown = strchr("/=!?*", let) ? 0 : 1; + switch (let) { case WEAPON_SYM: - otmp->quan = (otmp->otyp <= ROCK) ? rn1(6,6) : 1; - if(!rn2(11)) otmp->spe = rnd(3); - else if(!rn2(10)) { + otmp->quan = (otmp->otyp <= ROCK) ? rn1(6, 6) : 1; + if (!rn2(11)) + otmp->spe = rnd(3); + else if (!rn2(10)) { otmp->cursed = 1; otmp->spe = -rnd(3); } break; case FOOD_SYM: - if(otmp->otyp >= CORPSE) break; + if (otmp->otyp >= CORPSE) + break; #ifdef NOT_YET_IMPLEMENTED /* if tins are to be identified, need to adapt doname() etc */ - if(otmp->otyp == TIN) + if (otmp->otyp == TIN) otmp->spe = rnd(...); #endif /* NOT_YET_IMPLEMENTED */ - /* fall into next case */ + /* fall into next case */ case GEM_SYM: otmp->quan = rn2(6) ? 1 : 2; case TOOL_SYM: @@ -87,56 +92,61 @@ mksobj(int otyp) case AMULET_SYM: break; case ARMOR_SYM: - if(!rn2(8)) otmp->cursed = 1; - if(!rn2(10)) otmp->spe = rnd(3); - else if(!rn2(9)) { + if (!rn2(8)) + otmp->cursed = 1; + if (!rn2(10)) + otmp->spe = rnd(3); + else if (!rn2(9)) { otmp->spe = -rnd(3); otmp->cursed = 1; } break; case WAND_SYM: - if(otmp->otyp == WAN_WISHING) otmp->spe = 3; else - otmp->spe = rn1(5, - (objects[otmp->otyp].bits & NODIR) ? 11 : 4); + if (otmp->otyp == WAN_WISHING) + otmp->spe = 3; + else + otmp->spe = rn1(5, + (objects[otmp->otyp].bits & NODIR) ? 11 : 4); break; case RING_SYM: - if(objects[otmp->otyp].bits & SPEC) { - if(!rn2(3)) { + if (objects[otmp->otyp].bits & SPEC) { + if (!rn2(3)) { otmp->cursed = 1; otmp->spe = -rnd(2); - } else otmp->spe = rnd(2); - } else if(otmp->otyp == RIN_TELEPORTATION || - otmp->otyp == RIN_AGGRAVATE_MONSTER || - otmp->otyp == RIN_HUNGER || !rn2(9)) + } else + otmp->spe = rnd(2); + } else if (otmp->otyp == RIN_TELEPORTATION || + otmp->otyp == RIN_AGGRAVATE_MONSTER || + otmp->otyp == RIN_HUNGER || !rn2(9)) otmp->cursed = 1; break; default: panic("impossible mkobj"); } otmp->owt = weight(otmp); - return(otmp); + return (otmp); } bool letter(char c) { - return(('@' <= c && c <= 'Z') || ('a' <= c && c <= 'z')); + return (('@' <= c && c <= 'Z') || ('a' <= c && c <= 'z')); } int weight(struct obj *obj) { -int wt = objects[obj->otyp].oc_weight; - return(wt ? wt*obj->quan : (obj->quan + 1)/2); + int wt = objects[obj->otyp].oc_weight; + return (wt ? wt * obj->quan : (obj->quan + 1) / 2); } void mkgold(long num, int x, int y) { struct gold *gold; - long amount = (num ? num : 1 + (rnd(dlevel+2) * rnd(30))); + long amount = (num ? num : 1 + (rnd(dlevel + 2) * rnd(30))); - if((gold = g_at(x,y))) + if ((gold = g_at(x, y)) != NULL) gold->amount += amount; else { gold = newgold(); diff --git a/games/hack/hack.mkshop.c b/games/hack/hack.mkshop.c index 239ddaed05..48c217e12c 100644 --- a/games/hack/hack.mkshop.c +++ b/games/hack/hack.mkshop.c @@ -11,103 +11,115 @@ extern int nroom; extern char shtypes[]; /* = "=/)%?!["; 8 types: 7 specialized, 1 mixed */ schar shprobs[] = { 3,3,5,5,10,10,14,50 }; /* their probabilities */ -static struct permonst *morguemon(void); -static bool nexttodoor(int, int); -static bool has_dnstairs(struct mkroom *); -static bool has_upstairs(struct mkroom *); -static bool isbig(struct mkroom *); -static int dist2(int, int, int, int); -static int sq(int); +static struct permonst *morguemon(void); +static bool nexttodoor(int, int); +static bool has_dnstairs(struct mkroom *); +static bool has_upstairs(struct mkroom *); +static bool isbig(struct mkroom *); +static int dist2(int, int, int, int); +static int sq(int); void mkshop(void) { -struct mkroom *sroom; -int sh,sx,sy,i = -1; -char let; -int roomno; -struct monst *shk; + struct mkroom *sroom; + int sh, sx, sy, i = -1; + char let; + int roomno; + struct monst *shk; + #ifdef WIZARD /* first determine shoptype */ - if(wizard){ + if (wizard) { char *ep = getenv("SHOPTYPE"); - if(ep){ - if(*ep == 'z' || *ep == 'Z'){ + if (ep) { + if (*ep == 'z' || *ep == 'Z') { mkzoo(ZOO); return; } - if(*ep == 'm' || *ep == 'M'){ + if (*ep == 'm' || *ep == 'M') { mkzoo(MORGUE); return; } - if(*ep == 'b' || *ep == 'B'){ + if (*ep == 'b' || *ep == 'B') { mkzoo(BEEHIVE); return; } - if(*ep == 's' || *ep == 'S'){ + if (*ep == 's' || *ep == 'S') { mkswamp(); return; } - for(i=0; shtypes[i]; i++) - if(*ep == shtypes[i]) break; + for (i = 0; shtypes[i]; i++) + if (*ep == shtypes[i]) + break; goto gottype; } } gottype: #endif /* WIZARD */ - for(sroom = &rooms[0], roomno = 0; ; sroom++, roomno++){ - if(sroom->hx < 0) return; - if(sroom - rooms >= nroom) { + for (sroom = &rooms[0], roomno = 0;; sroom++, roomno++) { + if (sroom->hx < 0) + return; + if (sroom - rooms >= nroom) { pline("rooms not closed by -1?"); return; } - if(sroom->rtype) continue; - if(!sroom->rlit || has_dnstairs(sroom) || has_upstairs(sroom)) + if (sroom->rtype) + continue; + if (!sroom->rlit || has_dnstairs(sroom) || has_upstairs(sroom)) continue; - if( + if ( #ifdef WIZARD - ((wizard && getenv("SHOPTYPE") && sroom->doorct != 0)) || + (wizard && getenv("SHOPTYPE") && sroom->doorct != 0) || #endif /* WIZARD */ - (sroom->doorct <= 2 && sroom->doorct > 0)) break; + (sroom->doorct <= 2 && sroom->doorct > 0)) + break; } - if(i < 0) { /* shoptype not yet determined */ - int j; + if (i < 0) { /* shoptype not yet determined */ + int j; - for(j = rn2(100), i = 0; (j -= shprobs[i])>= 0; i++) - if(!shtypes[i]) break; /* superfluous */ - if(isbig(sroom) && i + SHOPBASE == WANDSHOP) - i = GENERAL-SHOPBASE; + for (j = rn2(100), i = 0; (j -= shprobs[i]) >= 0; i++) + if (!shtypes[i]) /* superfluous */ + break; + if (isbig(sroom) && i + SHOPBASE == WANDSHOP) + i = GENERAL - SHOPBASE; } sroom->rtype = i + SHOPBASE; let = shtypes[i]; sh = sroom->fdoor; sx = doors[sh].x; sy = doors[sh].y; - if(sx == sroom->lx-1) sx++; else - if(sx == sroom->hx+1) sx--; else - if(sy == sroom->ly-1) sy++; else - if(sy == sroom->hy+1) sy--; else { + if (sx == sroom->lx - 1) + sx++; + else if (sx == sroom->hx + 1) + sx--; + else if (sy == sroom->ly - 1) + sy++; + else if (sy == sroom->hy + 1) + sy--; + else { #ifdef WIZARD - /* This is said to happen sometimes, but I've never seen it. */ - if(wizard) { - int j = sroom->doorct; + /* This is said to happen sometimes, but I've never seen it. */ + if (wizard) { + int j = sroom->doorct; - pline("Where is shopdoor?"); - pline("Room at (%d,%d),(%d,%d).", sroom->lx, sroom->ly, - sroom->hx, sroom->hy); - pline("doormax=%d doorct=%d fdoor=%d", - doorindex, sroom->doorct, sh); - while(j--) { - pline("door [%d,%d]", doors[sh].x, doors[sh].y); - sh++; + pline("Where is shopdoor?"); + pline("Room at (%d,%d),(%d,%d).", sroom->lx, sroom->ly, + sroom->hx, sroom->hy); + pline("doormax=%d doorct=%d fdoor=%d", + doorindex, sroom->doorct, sh); + while (j--) { + pline("door [%d,%d]", doors[sh].x, doors[sh].y); + sh++; + } + more(); } - more(); - } #endif /* WIZARD */ - return; + return; } - if(!(shk = makemon(PM_SHK,sx,sy))) return; + if (!(shk = makemon(PM_SHK, sx, sy))) + return; shk->isshk = shk->mpeaceful = 1; shk->msleep = 0; shk->mtrapseen = ~0; /* we know all the traps already */ @@ -119,25 +131,26 @@ gottype: ESHK->robbed = 0; ESHK->visitct = 0; ESHK->following = 0; - shk->mgold = 1000 + 30*rnd(100); /* initial capital */ + shk->mgold = 1000 + 30 * rnd(100); /* initial capital */ ESHK->billct = 0; findname(ESHK->shknam, let); - for(sx = sroom->lx; sx <= sroom->hx; sx++) - for(sy = sroom->ly; sy <= sroom->hy; sy++){ - struct monst *mtmp; - if((sx == sroom->lx && doors[sh].x == sx-1) || - (sx == sroom->hx && doors[sh].x == sx+1) || - (sy == sroom->ly && doors[sh].y == sy-1) || - (sy == sroom->hy && doors[sh].y == sy+1)) continue; - if(rn2(100) < dlevel && !m_at(sx,sy) && - (mtmp = makemon(PM_MIMIC, sx, sy))){ - mtmp->mimic = 1; - mtmp->mappearance = - (let && rn2(10) < dlevel) ? let : ']'; - continue; + for (sx = sroom->lx; sx <= sroom->hx; sx++) + for (sy = sroom->ly; sy <= sroom->hy; sy++) { + struct monst *mtmp; + if ((sx == sroom->lx && doors[sh].x == sx - 1) || + (sx == sroom->hx && doors[sh].x == sx + 1) || + (sy == sroom->ly && doors[sh].y == sy - 1) || + (sy == sroom->hy && doors[sh].y == sy + 1)) + continue; + if (rn2(100) < dlevel && !m_at(sx, sy) && + (mtmp = makemon(PM_MIMIC, sx, sy))) { + mtmp->mimic = 1; + mtmp->mappearance = + (let && rn2(10) < dlevel) ? let : ']'; + continue; + } + mkobj_at(let, sx, sy); } - mkobj_at(let, sx, sy); - } } void @@ -145,57 +158,61 @@ mkzoo(int type) { struct mkroom *sroom; struct monst *mon; - int sh,sx,sy,i; + int sh, sx, sy, i; int goldlim = 500 * dlevel; int moct = 0; i = nroom; - for(sroom = &rooms[rn2(nroom)]; ; sroom++) { - if(sroom == &rooms[nroom]) + for (sroom = &rooms[rn2(nroom)];; sroom++) { + if (sroom == &rooms[nroom]) sroom = &rooms[0]; - if(!i-- || sroom->hx < 0) + if (!i-- || sroom->hx < 0) return; - if(sroom->rtype) + if (sroom->rtype) continue; - if(type == MORGUE && sroom->rlit) + if (type == MORGUE && sroom->rlit) continue; - if(has_upstairs(sroom) || (has_dnstairs(sroom) && rn2(3))) + if (has_upstairs(sroom) || (has_dnstairs(sroom) && rn2(3))) continue; - if(sroom->doorct == 1 || !rn2(5)) + if (sroom->doorct == 1 || !rn2(5)) break; } sroom->rtype = type; sh = sroom->fdoor; - for(sx = sroom->lx; sx <= sroom->hx; sx++) - for(sy = sroom->ly; sy <= sroom->hy; sy++){ - if((sx == sroom->lx && doors[sh].x == sx-1) || - (sx == sroom->hx && doors[sh].x == sx+1) || - (sy == sroom->ly && doors[sh].y == sy-1) || - (sy == sroom->hy && doors[sh].y == sy+1)) continue; - mon = makemon( - (type == MORGUE) ? morguemon() : - (type == BEEHIVE) ? PM_KILLER_BEE : NULL, - sx, sy); - if(mon) mon->msleep = 1; - switch(type) { - case ZOO: - i = sq(dist2(sx,sy,doors[sh].x,doors[sh].y)); - if(i >= goldlim) i = 5*dlevel; - goldlim -= i; - mkgold((long)(10 + rn2(i)), sx, sy); - break; - case MORGUE: - /* Usually there is one dead body in the morgue */ - if(!moct && rn2(3)) { - mksobj_at(CORPSE, sx, sy); - moct++; - } - break; - case BEEHIVE: - if(!rn2(3)) mksobj_at(LUMP_OF_ROYAL_JELLY, sx, sy); - break; + for (sx = sroom->lx; sx <= sroom->hx; sx++) + for (sy = sroom->ly; sy <= sroom->hy; sy++) { + if ((sx == sroom->lx && doors[sh].x == sx - 1) || + (sx == sroom->hx && doors[sh].x == sx + 1) || + (sy == sroom->ly && doors[sh].y == sy - 1) || + (sy == sroom->hy && doors[sh].y == sy + 1)) + continue; + mon = makemon( + (type == MORGUE) ? morguemon() : + (type == BEEHIVE) ? PM_KILLER_BEE : NULL, + sx, sy); + if (mon) + mon->msleep = 1; + switch (type) { + case ZOO: + i = sq(dist2(sx, sy, doors[sh].x, doors[sh].y)); + if (i >= goldlim) + i = 5 * dlevel; + goldlim -= i; + mkgold((long)(10 + rn2(i)), sx, sy); + break; + case MORGUE: + /* Usually there is one dead body in the morgue */ + if (!moct && rn2(3)) { + mksobj_at(CORPSE, sx, sy); + moct++; + } + break; + case BEEHIVE: + if (!rn2(3)) + mksobj_at(LUMP_OF_ROYAL_JELLY, sx, sy); + break; + } } - } } static struct permonst * @@ -203,81 +220,85 @@ morguemon(void) { int i = rn2(100), hd = rn2(dlevel); - if(hd > 10 && i < 10) return(PM_DEMON); - if(hd > 8 && i > 85) return(PM_VAMPIRE); - return((i < 40) ? PM_GHOST : (i < 60) ? PM_WRAITH : PM_ZOMBIE); + if (hd > 10 && i < 10) + return (PM_DEMON); + if (hd > 8 && i > 85) + return (PM_VAMPIRE); + return ((i < 40) ? PM_GHOST : (i < 60) ? PM_WRAITH : PM_ZOMBIE); } void -mkswamp(void) /* Michiel Huisjes & Fred de Wilde */ +mkswamp(void) /* Michiel Huisjes & Fred de Wilde */ { struct mkroom *sroom; - int sx,sy,i,eelct = 0; + int sx, sy, i, eelct = 0; - for(i=0; i<5; i++) { /* 5 tries */ + for (i = 0; i < 5; i++) { /* 5 tries */ sroom = &rooms[rn2(nroom)]; - if(sroom->hx < 0 || sroom->rtype || - has_upstairs(sroom) || has_dnstairs(sroom)) + if (sroom->hx < 0 || sroom->rtype || + has_upstairs(sroom) || has_dnstairs(sroom)) continue; /* satisfied; make a swamp */ sroom->rtype = SWAMP; - for(sx = sroom->lx; sx <= sroom->hx; sx++) - for(sy = sroom->ly; sy <= sroom->hy; sy++) - if((sx+sy)%2 && !o_at(sx,sy) && !t_at(sx,sy) - && !m_at(sx,sy) && !nexttodoor(sx,sy)){ - levl[sx][sy].typ = POOL; - levl[sx][sy].scrsym = POOL_SYM; - if(!eelct || !rn2(4)) { - makemon(PM_EEL, sx, sy); - eelct++; - } - } + for (sx = sroom->lx; sx <= sroom->hx; sx++) + for (sy = sroom->ly; sy <= sroom->hy; sy++) + if ((sx + sy) % 2 && !o_at(sx, sy) && + !t_at(sx, sy) && !m_at(sx, sy) && + !nexttodoor(sx, sy)) { + levl[sx][sy].typ = POOL; + levl[sx][sy].scrsym = POOL_SYM; + if (!eelct || !rn2(4)) { + makemon(PM_EEL, sx, sy); + eelct++; + } + } } } static bool nexttodoor(int sx, int sy) { - int dx,dy; + int dx, dy; struct rm *lev; - for(dx = -1; dx <= 1; dx++) for(dy = -1; dy <= 1; dy++) - if((lev = &levl[sx+dx][sy+dy])->typ == DOOR || - lev->typ == SDOOR || lev->typ == LDOOR) - return(1); - return(0); + for (dx = -1; dx <= 1; dx++) + for (dy = -1; dy <= 1; dy++) + if ((lev = &levl[sx + dx][sy + dy])->typ == DOOR || + lev->typ == SDOOR || lev->typ == LDOOR) + return (1); + return (0); } static bool has_dnstairs(struct mkroom *sroom) { - return(sroom->lx <= xdnstair && xdnstair <= sroom->hx && - sroom->ly <= ydnstair && ydnstair <= sroom->hy); + return (sroom->lx <= xdnstair && xdnstair <= sroom->hx && + sroom->ly <= ydnstair && ydnstair <= sroom->hy); } static bool has_upstairs(struct mkroom *sroom) { - return(sroom->lx <= xupstair && xupstair <= sroom->hx && - sroom->ly <= yupstair && yupstair <= sroom->hy); + return (sroom->lx <= xupstair && xupstair <= sroom->hx && + sroom->ly <= yupstair && yupstair <= sroom->hy); } static bool isbig(struct mkroom *sroom) { int area = (sroom->hx - sroom->lx) * (sroom->hy - sroom->ly); - return( area > 20 ); + return (area > 20); } static int dist2(int x0, int y0, int x1, int y1) { - return((x0-x1)*(x0-x1) + (y0-y1)*(y0-y1)); + return ((x0 - x1) * (x0 - x1) + (y0 - y1) * (y0 - y1)); } static int sq(int a) { - return(a*a); + return (a * a); } #endif /* QUEST */ diff --git a/games/hack/hack.mon.c b/games/hack/hack.mon.c index 79a491838e..25549260dd 100644 --- a/games/hack/hack.mon.c +++ b/games/hack/hack.mon.c @@ -6,18 +6,18 @@ #include "hack.h" #include "hack.mfndpos.h" -int warnlevel; /* used by movemon and dochugw */ +int warnlevel; /* used by movemon and dochugw */ long lastwarntime; int lastwarnlev; static const char *warnings[] = { "white", "pink", "red", "ruby", "purple", "black" }; -static int dochugw(struct monst *); -static void mpickgold(struct monst *); -static void mpickgems(struct monst *); -static void dmonsfree(void); -static bool ishuman(struct monst *); +static int dochugw(struct monst *); +static void mpickgold(struct monst *); +static void mpickgems(struct monst *); +static void dmonsfree(void); +static bool ishuman(struct monst *); void movemon(void) @@ -27,92 +27,97 @@ movemon(void) warnlevel = 0; - while(1) { + for (;;) { /* find a monster that we haven't treated yet */ - /* note that mtmp or mtmp->nmon might get killed - while mtmp moves, so we cannot just walk down the - chain (even new monsters might get created!) */ - for(mtmp = fmon; mtmp; mtmp = mtmp->nmon) - if(mtmp->mlstmv < moves) goto next_mon; + /* + * note that mtmp or mtmp->nmon might get killed while mtmp + * moves, so we cannot just walk down the chain (even new + * monsters might get created!) + */ + for (mtmp = fmon; mtmp; mtmp = mtmp->nmon) + if (mtmp->mlstmv < moves) + goto next_mon; /* treated all monsters */ break; - next_mon: +next_mon: mtmp->mlstmv = moves; /* most monsters drown in pools */ - { boolean inpool, iseel; - - inpool = (levl[mtmp->mx][mtmp->my].typ == POOL); - iseel = (mtmp->data->mlet == ';'); - if(inpool && !iseel) { - if(cansee(mtmp->mx,mtmp->my)) - pline("%s drowns.", Monnam(mtmp)); - mondead(mtmp); - continue; - } - /* but eels have a difficult time outside */ - if(iseel && !inpool) { - if(mtmp->mhp > 1) mtmp->mhp--; - mtmp->mflee = 1; - mtmp->mfleetim += 2; - } + { + boolean inpool, iseel; + + inpool = (levl[mtmp->mx][mtmp->my].typ == POOL); + iseel = (mtmp->data->mlet == ';'); + if (inpool && !iseel) { + if (cansee(mtmp->mx, mtmp->my)) + pline("%s drowns.", Monnam(mtmp)); + mondead(mtmp); + continue; + } + /* but eels have a difficult time outside */ + if (iseel && !inpool) { + if (mtmp->mhp > 1) + mtmp->mhp--; + mtmp->mflee = 1; + mtmp->mfleetim += 2; + } } - if(mtmp->mblinded && !--mtmp->mblinded) + if (mtmp->mblinded && !--mtmp->mblinded) mtmp->mcansee = 1; - if(mtmp->mfleetim && !--mtmp->mfleetim) + if (mtmp->mfleetim && !--mtmp->mfleetim) mtmp->mflee = 0; - if(mtmp->mimic) continue; - if(mtmp->mspeed != MSLOW || !(moves%2)){ + if (mtmp->mimic) + continue; + if (mtmp->mspeed != MSLOW || !(moves % 2)) { /* continue if the monster died fighting */ fr = -1; - if(Conflict && cansee(mtmp->mx,mtmp->my) - && (fr = fightm(mtmp)) == 2) + if (Conflict && cansee(mtmp->mx, mtmp->my) + && (fr = fightm(mtmp)) == 2) continue; - if(fr<0 && dochugw(mtmp)) + if (fr < 0 && dochugw(mtmp)) continue; } - if(mtmp->mspeed == MFAST && dochugw(mtmp)) + if (mtmp->mspeed == MFAST && dochugw(mtmp)) continue; } warnlevel -= u.ulevel; - if(warnlevel >= SIZE(warnings)) - warnlevel = SIZE(warnings)-1; - if(warnlevel >= 0) - if(warnlevel > lastwarnlev || moves > lastwarntime + 5){ - const char *rr; - switch(Warning & (LEFT_RING | RIGHT_RING)){ - case LEFT_RING: - rr = "Your left ring glows"; - break; - case RIGHT_RING: - rr = "Your right ring glows"; - break; - case LEFT_RING | RIGHT_RING: - rr = "Both your rings glow"; - break; - default: - rr = "Your fingertips glow"; - break; - } - pline("%s %s!", rr, warnings[warnlevel]); - lastwarntime = moves; - lastwarnlev = warnlevel; - } + if (warnlevel >= SIZE(warnings)) + warnlevel = SIZE(warnings) - 1; + if (warnlevel >= 0) + if (warnlevel > lastwarnlev || moves > lastwarntime + 5) { + const char *rr; + switch (Warning & (LEFT_RING | RIGHT_RING)) { + case LEFT_RING: + rr = "Your left ring glows"; + break; + case RIGHT_RING: + rr = "Your right ring glows"; + break; + case LEFT_RING | RIGHT_RING: + rr = "Both your rings glow"; + break; + default: + rr = "Your fingertips glow"; + break; + } + pline("%s %s!", rr, warnings[warnlevel]); + lastwarntime = moves; + lastwarnlev = warnlevel; + } - dmonsfree(); /* remove all dead monsters */ + dmonsfree(); /* remove all dead monsters */ } void justswld(struct monst *mtmp, const char *name) { - mtmp->mx = u.ux; mtmp->my = u.uy; u.ustuck = mtmp; pmon(mtmp); - kludge("%s swallows you!",name); + kludge("%s swallows you!", name); more(); seeoff(1); u.uswallow = 1; @@ -123,33 +128,42 @@ justswld(struct monst *mtmp, const char *name) void youswld(struct monst *mtmp, int dam, int die, const char *name) { - if(mtmp != u.ustuck) return; - kludge("%s digests you!",name); + if (mtmp != u.ustuck) + return; + kludge("%s digests you!", name); u.uhp -= dam; - if((int)u.uswldtim++ >= die){ /* a3 */ + if ((int)u.uswldtim++ >= die) { /* a3 */ pline("It totally digests you!"); u.uhp = -1; } - if(u.uhp < 1) done_in_by(mtmp); - /* flags.botlx = 1; */ /* should we show status line ? */ + if (u.uhp < 1) + done_in_by(mtmp); +#if 0 + flags.botlx = 1; /* should we show status line ? */ +#endif } static int dochugw(struct monst *mtmp) { -int x = mtmp->mx; -int y = mtmp->my; -int d1 = dochug(mtmp); -int dd; - if(!d1) /* monster still alive */ - if(Warning) - if(!mtmp->mpeaceful) - if(mtmp->data->mlevel > warnlevel) - if((dd = dist(mtmp->mx,mtmp->my)) < dist(x,y)) - if(dd < 100) - if(!canseemon(mtmp)) - warnlevel = mtmp->data->mlevel; - return(d1); + int x = mtmp->mx; + int y = mtmp->my; + int d1 = dochug(mtmp); + int dd; + + if (!d1) /* monster still alive */ + if (Warning) + if (!mtmp->mpeaceful) + if (mtmp->data->mlevel > warnlevel) + if ((dd = dist(mtmp->mx, mtmp->my)) < + dist(x, y)) + if (dd < 100) + if (!canseemon(mtmp)) + warnlevel = + mtmp-> + data-> + mlevel; + return (d1); } /* returns 1 if monster died moving, 0 otherwise */ @@ -159,88 +173,93 @@ dochug(struct monst *mtmp) struct permonst *mdat; int tmp = 0, nearby, scared; - if(mtmp->cham && !rn2(6)) - newcham(mtmp, &mons[dlevel+14+rn2(CMNUM-14-dlevel)]); + if (mtmp->cham && !rn2(6)) + newcham(mtmp, &mons[dlevel + 14 + rn2(CMNUM - 14 - dlevel)]); mdat = mtmp->data; - if(mdat->mlevel < 0) - panic("bad monster %c (%d)",mdat->mlet,mdat->mlevel); + if (mdat->mlevel < 0) + panic("bad monster %c (%d)", mdat->mlet, mdat->mlevel); /* regenerate monsters */ - if((!(moves%20) || index(MREGEN, mdat->mlet)) && + if ((!(moves % 20) || strchr(MREGEN, mdat->mlet)) && mtmp->mhp < mtmp->mhpmax) mtmp->mhp++; - if(mtmp->mfroz) return(0); /* frozen monsters don't do anything */ + if (mtmp->mfroz) /* frozen monsters don't do anything */ + return (0); - if(mtmp->msleep) { + if (mtmp->msleep) { /* wake up, or get out of here. */ /* ettins are hard to surprise */ /* Nymphs and Leprechauns do not easily wake up */ - if(cansee(mtmp->mx,mtmp->my) && - (!Stealth || (mdat->mlet == 'e' && rn2(10))) && - (!index("NL",mdat->mlet) || !rn2(50)) && - (Aggravate_monster || index("d1", mdat->mlet) - || (!rn2(7) && !mtmp->mimic))) + if (cansee(mtmp->mx, mtmp->my) && + (!Stealth || (mdat->mlet == 'e' && rn2(10))) && + (!strchr("NL", mdat->mlet) || !rn2(50)) && + (Aggravate_monster || strchr("d1", mdat->mlet) + || (!rn2(7) && !mtmp->mimic))) mtmp->msleep = 0; - else return(0); + else + return (0); } /* not frozen or sleeping: wipe out texts written in the dust */ wipe_engr_at(mtmp->mx, mtmp->my, 1); /* confused monsters get unconfused with small probability */ - if(mtmp->mconf && !rn2(50)) mtmp->mconf = 0; + if (mtmp->mconf && !rn2(50)) + mtmp->mconf = 0; /* some monsters teleport */ - if(mtmp->mflee && index("tNL", mdat->mlet) && !rn2(40)){ + if (mtmp->mflee && strchr("tNL", mdat->mlet) && !rn2(40)) { rloc(mtmp); - return(0); + return (0); } - if(mdat->mmove < rnd(6)) return(0); + if (mdat->mmove < rnd(6)) + return (0); /* fleeing monsters might regain courage */ - if(mtmp->mflee && !mtmp->mfleetim + if (mtmp->mflee && !mtmp->mfleetim && mtmp->mhp == mtmp->mhpmax && !rn2(25)) mtmp->mflee = 0; nearby = (dist(mtmp->mx, mtmp->my) < 3); scared = (nearby && (sengr_at("Elbereth", u.ux, u.uy) || - sobj_at(SCR_SCARE_MONSTER, u.ux, u.uy))); - if(scared && !mtmp->mflee) { + sobj_at(SCR_SCARE_MONSTER, u.ux, u.uy))); + if (scared && !mtmp->mflee) { mtmp->mflee = 1; mtmp->mfleetim = (rn2(7) ? rnd(10) : rnd(100)); } - if(!nearby || - mtmp->mflee || - mtmp->mconf || - (mtmp->minvis && !rn2(3)) || - (index("BIuy", mdat->mlet) && !rn2(4)) || - (mdat->mlet == 'L' && !u.ugold && (mtmp->mgold || rn2(2))) || - (!mtmp->mcansee && !rn2(4)) || - mtmp->mpeaceful + if (!nearby || + mtmp->mflee || + mtmp->mconf || + (mtmp->minvis && !rn2(3)) || + (strchr("BIuy", mdat->mlet) && !rn2(4)) || + (mdat->mlet == 'L' && !u.ugold && (mtmp->mgold || rn2(2))) || + (!mtmp->mcansee && !rn2(4)) || + mtmp->mpeaceful ) { - tmp = m_move(mtmp,0); /* 2: monster died moving */ - if(tmp == 2 || (tmp && mdat->mmove <= 12)) - return(tmp == 2); + tmp = m_move(mtmp, 0); /* 2: monster died moving */ + if (tmp == 2 || (tmp && mdat->mmove <= 12)) + return (tmp == 2); } - if(!index("Ea", mdat->mlet) && nearby && - !mtmp->mpeaceful && u.uhp > 0 && !scared) { - if(mhitu(mtmp)) - return(1); /* monster died (e.g. 'y' or 'F') */ + if (!strchr("Ea", mdat->mlet) && nearby && + !mtmp->mpeaceful && u.uhp > 0 && !scared) { + if (mhitu(mtmp)) + return (1); /* monster died (e.g. 'y' or 'F') */ } /* extra movement for fast monsters */ - if(mdat->mmove-12 > rnd(12)) tmp = m_move(mtmp,1); - return(tmp == 2); + if (mdat->mmove - 12 > rnd(12)) + tmp = m_move(mtmp, 1); + return (tmp == 2); } int m_move(struct monst *mtmp, int after) { struct monst *mtmp2; - int nx,ny,omx,omy,appr,nearer,cnt,i,j; - xchar gx,gy,nix,niy,chcnt; + int nx, ny, omx, omy, appr, nearer, cnt, i, j; + xchar gx, gy, nix, niy, chcnt; schar chi; boolean likegold = 0, likegems = 0, likeobjs; char msym = mtmp->data->mlet; @@ -248,45 +267,46 @@ m_move(struct monst *mtmp, int after) coord poss[9]; int info[9]; - if(mtmp->mfroz || mtmp->msleep) - return(0); - if(mtmp->mtrapped) { + if (mtmp->mfroz || mtmp->msleep) + return (0); + if (mtmp->mtrapped) { i = mintrap(mtmp); - if(i == 2) return(2); /* he died */ - if(i == 1) return(0); /* still in trap, so didnt move */ + if (i == 2) /* he died */ + return (2); + if (i == 1) /* still in trap, so didnt move */ + return (0); } - if(mtmp->mhide && o_at(mtmp->mx,mtmp->my) && rn2(10)) - return(0); /* do not leave hiding place */ + if (mtmp->mhide && o_at(mtmp->mx, mtmp->my) && rn2(10)) + return (0); /* do not leave hiding place */ #ifndef NOWORM - if(mtmp->wormno) + if (mtmp->wormno) goto not_special; #endif /* NOWORM */ /* my dog gets a special treatment */ - if(mtmp->mtame) { - return( dog_move(mtmp, after) ); - } + if (mtmp->mtame) + return (dog_move(mtmp, after)); /* likewise for shopkeeper */ - if(mtmp->isshk) { + if (mtmp->isshk) { mmoved = shk_move(mtmp); - if(mmoved >= 0) + if (mmoved >= 0) goto postmov; - mmoved = 0; /* follow player outside shop */ + mmoved = 0; /* follow player outside shop */ } /* and for the guard */ - if(mtmp->isgd) { + if (mtmp->isgd) { mmoved = gd_move(); goto postmov; } -/* teleport if that lies in our nature ('t') or when badly wounded ('1') */ - if((msym == 't' && !rn2(5)) - || (msym == '1' && (mtmp->mhp < 7 || (!xdnstair && !rn2(5)) - || levl[u.ux][u.uy].typ == STAIRS))) { - if(mtmp->mhp < 7 || (msym == 't' && rn2(2))) + /* teleport if that lies in our nature ('t') or when badly wounded ('1') */ + if ((msym == 't' && !rn2(5)) + || (msym == '1' && (mtmp->mhp < 7 || (!xdnstair && !rn2(5)) + || levl[u.ux][u.uy].typ == STAIRS))) { + if (mtmp->mhp < 7 || (msym == 't' && rn2(2))) rloc(mtmp); else mnexto(mtmp); @@ -295,167 +315,184 @@ m_move(struct monst *mtmp, int after) } /* spit fire ('D') or use a wand ('1') when appropriate */ - if(index("D1", msym)) + if (strchr("D1", msym)) inrange(mtmp); - if(msym == 'U' && !mtmp->mcan && canseemon(mtmp) && + if (msym == 'U' && !mtmp->mcan && canseemon(mtmp) && mtmp->mcansee && rn2(5)) { - if(!Confusion) + if (!Confusion) pline("%s's gaze has confused you!", Monnam(mtmp)); else pline("You are getting more and more confused."); - if(rn2(3)) mtmp->mcan = 1; - Confusion += d(3,4); /* timeout */ + if (rn2(3)) + mtmp->mcan = 1; + Confusion += d(3, 4); /* timeout */ } not_special: - if(!mtmp->mflee && u.uswallow && u.ustuck != mtmp) return(1); + if (!mtmp->mflee && u.uswallow && u.ustuck != mtmp) + return (1); appr = 1; - if(mtmp->mflee) appr = -1; - if(mtmp->mconf || Invis || !mtmp->mcansee || - (index("BIy", msym) && !rn2(3))) + if (mtmp->mflee) + appr = -1; + if (mtmp->mconf || Invis || !mtmp->mcansee || + (strchr("BIy", msym) && !rn2(3))) appr = 0; omx = mtmp->mx; omy = mtmp->my; gx = u.ux; gy = u.uy; - if(msym == 'L' && appr == 1 && mtmp->mgold > u.ugold) + if (msym == 'L' && appr == 1 && mtmp->mgold > u.ugold) appr = -1; - /* random criterion for 'smell' or track finding ability - should use mtmp->msmell or sth + /* + * random criterion for 'smell' or track finding ability should use + * mtmp->msmell or sth */ - if(msym == '@' || - ('a' <= msym && msym <= 'z')) { - coord *cp; - schar mroom; - mroom = inroom(omx,omy); - if(mroom < 0 || mroom != inroom(u.ux,u.uy)){ - cp = gettrack(omx,omy); - if(cp){ - gx = cp->x; - gy = cp->y; - } + if (msym == '@' || + ('a' <= msym && msym <= 'z')) { + coord *cp; + schar mroom; + mroom = inroom(omx, omy); + if (mroom < 0 || mroom != inroom(u.ux, u.uy)) { + cp = gettrack(omx, omy); + if (cp) { + gx = cp->x; + gy = cp->y; + } } } /* look for gold or jewels nearby */ - likegold = (index("LOD", msym) != NULL); - likegems = (index("ODu", msym) != NULL); + likegold = (strchr("LOD", msym) != NULL); + likegems = (strchr("ODu", msym) != NULL); likeobjs = mtmp->mhide; #define SRCHRADIUS 25 - { xchar mind = SRCHRADIUS; /* not too far away */ - int dd; - if(likegold){ - struct gold *gold; - for(gold = fgold; gold; gold = gold->ngold) - if((dd = DIST(omx,omy,gold->gx,gold->gy)) < mind){ - mind = dd; - gx = gold->gx; - gy = gold->gy; + { + xchar mind = SRCHRADIUS; /* not too far away */ + int dd; + if (likegold) { + struct gold *gold; + for (gold = fgold; gold; gold = gold->ngold) + if ((dd = DIST(omx, omy, gold->gx, + gold->gy)) < mind) { + mind = dd; + gx = gold->gx; + gy = gold->gy; + } } - } - if(likegems || likeobjs){ - struct obj *otmp; - for(otmp = fobj; otmp; otmp = otmp->nobj) - if(likeobjs || otmp->olet == GEM_SYM) - if(msym != 'u' || - objects[otmp->otyp].g_val != 0) - if((dd = DIST(omx,omy,otmp->ox,otmp->oy)) < mind){ - mind = dd; - gx = otmp->ox; - gy = otmp->oy; + if (likegems || likeobjs) { + struct obj *otmp; + for (otmp = fobj; otmp; otmp = otmp->nobj) + if (likeobjs || otmp->olet == GEM_SYM) + if (msym != 'u' || + objects[otmp->otyp].g_val != 0) + if ((dd = DIST(omx, omy, otmp->ox, + otmp->oy)) < mind) { + mind = dd; + gx = otmp->ox; + gy = otmp->oy; + } + } + if (mind < SRCHRADIUS && appr == -1) { + if (dist(omx, omy) < 10) { + gx = u.ux; + gy = u.uy; + } else + appr = 1; } - } - if(mind < SRCHRADIUS && appr == -1) { - if(dist(omx,omy) < 10) { - gx = u.ux; - gy = u.uy; - } else - appr = 1; - } } nix = omx; niy = omy; - cnt = mfndpos(mtmp,poss,info, - msym == 'u' ? NOTONL : - (msym == '@' || msym == '1') ? (ALLOW_SSM | ALLOW_TRAPS) : - index(UNDEAD, msym) ? NOGARLIC : ALLOW_TRAPS); - /* ALLOW_ROCK for some monsters ? */ + cnt = mfndpos(mtmp, poss, info, + msym == 'u' ? NOTONL : + (msym == '@' || msym == '1') ? (ALLOW_SSM | ALLOW_TRAPS) : + strchr(UNDEAD, msym) ? NOGARLIC : ALLOW_TRAPS); + /* ALLOW_ROCK for some monsters ? */ chcnt = 0; chi = -1; - for(i=0; imtrack[j].x && ny == mtmp->mtrack[j].y) - if(rn2(4*(cnt-j))) goto nxti; + for (j = 0; j < MTSZ && j < cnt - 1; j++) + if (nx == mtmp->mtrack[j].x && ny == mtmp->mtrack[j].y) + if (rn2(4 * (cnt - j))) + goto nxti; #ifdef STUPID /* some stupid compilers think that this is too complicated */ - { int d1 = DIST(nx,ny,gx,gy); - int d2 = DIST(nix,niy,gx,gy); - nearer = (d1 < d2); + { + int d1 = DIST(nx, ny, gx, gy); + int d2 = DIST(nix, niy, gx, gy); + nearer = (d1 < d2); } #else - nearer = (DIST(nx,ny,gx,gy) < DIST(nix,niy,gx,gy)); + nearer = (DIST(nx, ny, gx, gy) < DIST(nix, niy, gx, gy)); #endif /* STUPID */ - if((appr == 1 && nearer) || (appr == -1 && !nearer) || - !mmoved || - (!appr && !rn2(++chcnt))){ + if ((appr == 1 && nearer) || (appr == -1 && !nearer) || + !mmoved || + (!appr && !rn2(++chcnt))) { nix = nx; niy = ny; chi = i; mmoved = 1; } - nxti: ; - } - if(mmoved){ - if(info[chi] & ALLOW_M){ - mtmp2 = m_at(nix,niy); - if(hitmm(mtmp,mtmp2) == 1 && rn2(4) && - hitmm(mtmp2,mtmp) == 2) return(2); - return(0); +nxti:; + } + if (mmoved) { + if (info[chi] & ALLOW_M) { + mtmp2 = m_at(nix, niy); + if (hitmm(mtmp, mtmp2) == 1 && rn2(4) && + hitmm(mtmp2, mtmp) == 2) + return (2); + return (0); } - if(info[chi] & ALLOW_U){ - hitu(mtmp, d(mtmp->data->damn, mtmp->data->damd)+1); - return(0); + if (info[chi] & ALLOW_U) { + hitu(mtmp, d(mtmp->data->damn, mtmp->data->damd) + 1); + return (0); } mtmp->mx = nix; mtmp->my = niy; - for(j=MTSZ-1; j>0; j--) mtmp->mtrack[j] = mtmp->mtrack[j-1]; + for (j = MTSZ - 1; j > 0; j--) + mtmp->mtrack[j] = mtmp->mtrack[j - 1]; mtmp->mtrack[0].x = omx; mtmp->mtrack[0].y = omy; #ifndef NOWORM - if(mtmp->wormno) worm_move(mtmp); + if (mtmp->wormno) + worm_move(mtmp); #endif /* NOWORM */ } else { - if(msym == 'u' && rn2(2)){ + if (msym == 'u' && rn2(2)) { rloc(mtmp); - return(0); + return (0); } #ifndef NOWORM - if(mtmp->wormno) worm_nomove(mtmp); + if (mtmp->wormno) + worm_nomove(mtmp); #endif /* NOWORM */ } postmov: - if(mmoved == 1) { - if(mintrap(mtmp) == 2) /* he died */ - return(2); - if(likegold) mpickgold(mtmp); - if(likegems) mpickgems(mtmp); - if(mtmp->mhide) mtmp->mundetected = 1; + if (mmoved == 1) { + if (mintrap(mtmp) == 2) /* he died */ + return (2); + if (likegold) + mpickgold(mtmp); + if (likegems) + mpickgems(mtmp); + if (mtmp->mhide) + mtmp->mundetected = 1; } pmon(mtmp); - return(mmoved); + return (mmoved); } static void mpickgold(struct monst *mtmp) { -struct gold *gold; - while((gold = g_at(mtmp->mx, mtmp->my))){ + struct gold *gold; + + while ((gold = g_at(mtmp->mx, mtmp->my)) != NULL) { mtmp->mgold += gold->amount; freegold(gold); - if(levl[mtmp->mx][mtmp->my].scrsym == '$') + if (levl[mtmp->mx][mtmp->my].scrsym == '$') newsym(mtmp->mx, mtmp->my); } } @@ -463,24 +500,26 @@ struct gold *gold; static void mpickgems(struct monst *mtmp) { -struct obj *otmp; - for(otmp = fobj; otmp; otmp = otmp->nobj) - if(otmp->olet == GEM_SYM) - if(otmp->ox == mtmp->mx && otmp->oy == mtmp->my) - if(mtmp->data->mlet != 'u' || objects[otmp->otyp].g_val != 0){ - freeobj(otmp); - mpickobj(mtmp, otmp); - if(levl[mtmp->mx][mtmp->my].scrsym == GEM_SYM) - newsym(mtmp->mx, mtmp->my); /* %% */ - return; /* pick only one object */ - } + struct obj *otmp; + + for (otmp = fobj; otmp; otmp = otmp->nobj) + if (otmp->olet == GEM_SYM) + if (otmp->ox == mtmp->mx && otmp->oy == mtmp->my) + if (mtmp->data->mlet != 'u' || + objects[otmp->otyp].g_val != 0) { + freeobj(otmp); + mpickobj(mtmp, otmp); + if (levl[mtmp->mx][mtmp->my].scrsym == GEM_SYM) + newsym(mtmp->mx, mtmp->my); /* %% */ + return; /* pick only one object */ + } } /* return number of acceptable neighbour positions */ int mfndpos(struct monst *mon, coord poss[9], int info[9], int flag) { - int x,y,nx,ny,cnt = 0,ntyp; + int x, y, nx, ny, cnt = 0, ntyp; struct monst *mtmp; int nowtyp; boolean pool; @@ -490,72 +529,88 @@ mfndpos(struct monst *mon, coord poss[9], int info[9], int flag) nowtyp = levl[x][y].typ; pool = (mon->data->mlet == ';'); -nexttry: /* eels prefer the water, but if there is no water nearby, - they will crawl over land */ - if(mon->mconf) { +nexttry: + /* + * eels prefer the water, but if there is no water nearby, they will + * crawl over land + */ + if (mon->mconf) { flag |= ALLOW_ALL; flag &= ~NOTONL; } - for(nx = x-1; nx <= x+1; nx++) for(ny = y-1; ny <= y+1; ny++) - if(nx != x || ny != y) if(isok(nx,ny)) - if(!IS_ROCK(ntyp = levl[nx][ny].typ)) - if(!(nx != x && ny != y && (nowtyp == DOOR || ntyp == DOOR))) - if((ntyp == POOL) == pool) { - info[cnt] = 0; - if(nx == u.ux && ny == u.uy){ - if(!(flag & ALLOW_U)) continue; - info[cnt] = ALLOW_U; - } else if((mtmp = m_at(nx,ny))){ - if(!(flag & ALLOW_M)) continue; - info[cnt] = ALLOW_M; - if(mtmp->mtame){ - if(!(flag & ALLOW_TM)) continue; - info[cnt] |= ALLOW_TM; - } - } - if(sobj_at(CLOVE_OF_GARLIC, nx, ny)) { - if(flag & NOGARLIC) continue; - info[cnt] |= NOGARLIC; - } - if(sobj_at(SCR_SCARE_MONSTER, nx, ny) || - (!mon->mpeaceful && sengr_at("Elbereth", nx, ny))) { - if(!(flag & ALLOW_SSM)) continue; - info[cnt] |= ALLOW_SSM; - } - if(sobj_at(ENORMOUS_ROCK, nx, ny)) { - if(!(flag & ALLOW_ROCK)) continue; - info[cnt] |= ALLOW_ROCK; - } - if(!Invis && online(nx,ny)){ - if(flag & NOTONL) continue; - info[cnt] |= NOTONL; - } - /* we cannot avoid traps of an unknown kind */ - { struct trap *ttmp = t_at(nx, ny); - int tt; - if(ttmp) { - tt = 1 << ttmp->ttyp; - if(mon->mtrapseen & tt){ - if(!(flag & tt)) continue; - info[cnt] |= tt; - } - } - } - poss[cnt].x = nx; - poss[cnt].y = ny; - cnt++; - } - if(!cnt && pool && nowtyp != POOL) { + for (nx = x - 1; nx <= x + 1; nx++) + for (ny = y - 1; ny <= y + 1; ny++) + if (nx != x || ny != y) + if (isok(nx, ny)) + if (!IS_ROCK(ntyp = levl[nx][ny].typ)) + if (!(nx != x && ny != y && + (nowtyp == DOOR || ntyp == DOOR))) + if ((ntyp == POOL) == pool) { + info[cnt] = 0; + if (nx == u.ux && ny == u.uy) { + if (!(flag & ALLOW_U)) + continue; + info[cnt] = ALLOW_U; + } else if ((mtmp = m_at(nx, ny)) != NULL) { + if (!(flag & ALLOW_M)) + continue; + info[cnt] = ALLOW_M; + if (mtmp->mtame) { + if (!(flag & ALLOW_TM)) + continue; + info[cnt] |= ALLOW_TM; + } + } + if (sobj_at(CLOVE_OF_GARLIC, nx, ny)) { + if (flag & NOGARLIC) + continue; + info[cnt] |= NOGARLIC; + } + if (sobj_at(SCR_SCARE_MONSTER, nx, ny) || + (!mon->mpeaceful && + sengr_at("Elbereth", nx, ny))) { + if (!(flag & ALLOW_SSM)) + continue; + info[cnt] |= ALLOW_SSM; + } + if (sobj_at(ENORMOUS_ROCK, nx, ny)) { + if (!(flag & ALLOW_ROCK)) + continue; + info[cnt] |= ALLOW_ROCK; + } + if (!Invis && online(nx, ny)) { + if (flag & NOTONL) + continue; + info[cnt] |= NOTONL; + } + /* we cannot avoid traps of an unknown kind */ + { + struct trap *ttmp = t_at(nx, ny); + int tt; + if (ttmp) { + tt = 1 << ttmp->ttyp; + if (mon->mtrapseen & tt) { + if (!(flag & tt)) + continue; + info[cnt] |= tt; + } + } + } + poss[cnt].x = nx; + poss[cnt].y = ny; + cnt++; + } + if (!cnt && pool && nowtyp != POOL) { pool = FALSE; goto nexttry; } - return(cnt); + return (cnt); } int dist(int x, int y) { - return((x-u.ux)*(x-u.ux) + (y-u.uy)*(y-u.uy)); + return ((x - u.ux) * (x - u.ux) + (y - u.uy) * (y - u.uy)); } void @@ -563,22 +618,24 @@ poisoned(const char *string, const char *pname) { int i; - if(Blind) pline("It was poisoned."); - else pline("The %s was poisoned!",string); - if(Poison_resistance) { + if (Blind) + pline("It was poisoned."); + else + pline("The %s was poisoned!", string); + if (Poison_resistance) { pline("The poison doesn't seem to affect you."); return; } i = rn2(10); - if(i == 0) { + if (i == 0) { u.uhp = -1; pline("I am afraid the poison was deadly ..."); - } else if(i <= 5) { - losestr(rn1(3,3)); + } else if (i <= 5) { + losestr(rn1(3, 3)); } else { - losehp(rn1(10,6), pname); + losehp(rn1(10, 6), pname); } - if(u.uhp < 1) { + if (u.uhp < 1) { killer = pname; done("died"); } @@ -587,14 +644,17 @@ poisoned(const char *string, const char *pname) void mondead(struct monst *mtmp) { - relobj(mtmp,1); + relobj(mtmp, 1); unpmon(mtmp); relmon(mtmp); unstuck(mtmp); - if(mtmp->isshk) shkdead(mtmp); - if(mtmp->isgd) gddead(); + if (mtmp->isshk) + shkdead(mtmp); + if (mtmp->isgd) + gddead(); #ifndef NOWORM - if(mtmp->wormno) wormdead(mtmp); + if (mtmp->wormno) + wormdead(mtmp); #endif /* NOWORM */ monfree(mtmp); } @@ -607,9 +667,12 @@ replmon(struct monst *mtmp, struct monst *mtmp2) monfree(mtmp); mtmp2->nmon = fmon; fmon = mtmp2; - if(u.ustuck == mtmp) u.ustuck = mtmp2; - if(mtmp2->isshk) replshk(mtmp,mtmp2); - if(mtmp2->isgd) replgd(mtmp,mtmp2); + if (u.ustuck == mtmp) + u.ustuck = mtmp2; + if (mtmp2->isshk) + replshk(mtmp, mtmp2); + if (mtmp2->isgd) + replgd(mtmp, mtmp2); } void @@ -617,15 +680,19 @@ relmon(struct monst *mon) { struct monst *mtmp; - if(mon == fmon) fmon = fmon->nmon; + if (mon == fmon) + fmon = fmon->nmon; else { - for(mtmp = fmon; mtmp->nmon != mon; mtmp = mtmp->nmon) ; + for (mtmp = fmon; mtmp->nmon != mon; mtmp = mtmp->nmon) + ; /* nothing */ mtmp->nmon = mon->nmon; } } -/* we do not free monsters immediately, in order to have their name - available shortly after their demise */ +/* + * we do not free monsters immediately, in order to have their name available + * shortly after their demise + */ struct monst *fdmon; /* chain of dead monsters, need not to be saved */ void @@ -638,18 +705,19 @@ monfree(struct monst *mtmp) static void dmonsfree(void) { -struct monst *mtmp; - while((mtmp = fdmon)){ + struct monst *mtmp; + + while ((mtmp = fdmon) != NULL) { fdmon = mtmp->nmon; - free((char *) mtmp); + free(mtmp); } } void unstuck(struct monst *mtmp) { - if(u.ustuck == mtmp) { - if(u.uswallow){ + if (u.ustuck == mtmp) { + if (u.uswallow) { u.ux = mtmp->mx; u.uy = mtmp->my; u.uswallow = 0; @@ -664,125 +732,144 @@ void killed(struct monst *mtmp) { #ifdef lint -#define NEW_SCORING +#define NEW_SCORING int tmp2; #endif /* lint */ - int tmp,nk,x,y; + int tmp, nk, x, y; struct permonst *mdat; - if(mtmp->cham) mtmp->data = PM_CHAMELEON; + if (mtmp->cham) + mtmp->data = PM_CHAMELEON; mdat = mtmp->data; - if(Blind) pline("You destroy it!"); - else { + if (Blind) + pline("You destroy it!"); + else pline("You destroy %s!", - mtmp->mtame ? amonnam(mtmp, "poor") : monnam(mtmp)); - } - if(u.umconf) { - if(!Blind) pline("Your hands stop glowing blue."); + mtmp->mtame ? amonnam(mtmp, "poor") : monnam(mtmp)); + if (u.umconf) { + if (!Blind) + pline("Your hands stop glowing blue."); u.umconf = 0; } /* count killed monsters */ #define MAXMONNO 100 - nk = 1; /* in case we cannot find it in mons */ - tmp = mdat - mons; /* index in mons array (if not 'd', '@', ...) */ - if(tmp >= 0 && tmp < CMNUM+2) { - u.nr_killed[tmp]++; - if((nk = u.nr_killed[tmp]) > MAXMONNO && - !index(fut_geno, mdat->mlet)) - charcat(fut_geno, mdat->mlet); + nk = 1; /* in case we cannot find it in mons */ + tmp = mdat - mons; /* index in mons array (if not 'd', '@', ...) */ + if (tmp >= 0 && tmp < CMNUM + 2) { + u.nr_killed[tmp]++; + if ((nk = u.nr_killed[tmp]) > MAXMONNO && + !strchr(fut_geno, mdat->mlet)) + charcat(fut_geno, mdat->mlet); } /* punish bad behaviour */ - if(mdat->mlet == '@') Telepat = 0, u.uluck -= 2; - if(mtmp->mpeaceful || mtmp->mtame) u.uluck--; - if(mdat->mlet == 'u') u.uluck -= 5; - if((int)u.uluck < LUCKMIN) u.uluck = LUCKMIN; + if (mdat->mlet == '@') + Telepat = 0, u.uluck -= 2; + if (mtmp->mpeaceful || mtmp->mtame) + u.uluck--; + if (mdat->mlet == 'u') + u.uluck -= 5; + if ((int)u.uluck < LUCKMIN) + u.uluck = LUCKMIN; /* give experience points */ tmp = 1 + mdat->mlevel * mdat->mlevel; - if(mdat->ac < 3) tmp += 2*(7 - mdat->ac); - if(index("AcsSDXaeRTVWU&In:P", mdat->mlet)) - tmp += 2*mdat->mlevel; - if(index("DeV&P",mdat->mlet)) tmp += (7*mdat->mlevel); - if(mdat->mlevel > 6) tmp += 50; - if(mdat->mlet == ';') tmp += 1000; + if (mdat->ac < 3) + tmp += 2 * (7 - mdat->ac); + if (strchr("AcsSDXaeRTVWU&In:P", mdat->mlet)) + tmp += 2 * mdat->mlevel; + if (strchr("DeV&P", mdat->mlet)) + tmp += (7 * mdat->mlevel); + if (mdat->mlevel > 6) + tmp += 50; + if (mdat->mlet == ';') + tmp += 1000; #ifdef NEW_SCORING /* ------- recent addition: make nr of points decrease - when this is not the first of this kind */ - { int ul = u.ulevel; - int ml = mdat->mlevel; - - if(ul < 14) /* points are given based on present and future level */ - for(tmp2 = 0; !tmp2 || ul + tmp2 <= ml; tmp2++) - if(u.uexp + 1 + (tmp + ((tmp2 <= 0) ? 0 : 4<<(tmp2-1)))/nk - >= 10*pow((unsigned)(ul-1))) - if(++ul == 14) break; - - tmp2 = ml - ul -1; - tmp = (tmp + ((tmp2 < 0) ? 0 : 4<mlevel; + + if (ul < 14) /* points are given based on present and future level */ + for (tmp2 = 0; !tmp2 || ul + tmp2 <= ml; tmp2++) + if (u.uexp + 1 + (tmp + ((tmp2 <= 0) ? 0 : 4 << (tmp2 - 1))) / nk + >= 10 * pow((unsigned)(ul - 1))) + if (++ul == 14) + break; + + tmp2 = ml - ul - 1; + tmp = (tmp + ((tmp2 < 0) ? 0 : 4 << tmp2)) / nk; + if (!tmp) + tmp = 1; } /* note: ul is not necessarily the future value of u.ulevel */ /* ------- end of recent valuation change ------- */ #endif /* NEW_SCORING */ - more_experienced(tmp,0); + more_experienced(tmp, 0); flags.botl = 1; - while(u.ulevel < 14 && u.uexp >= newuexp()){ + while (u.ulevel < 14 && u.uexp >= newuexp()) { pline("Welcome to experience level %u.", ++u.ulevel); tmp = rnd(10); - if(tmp < 3) tmp = rnd(10); + if (tmp < 3) + tmp = rnd(10); u.uhpmax += tmp; u.uhp += tmp; flags.botl = 1; } /* dispose of monster and make cadaver */ - x = mtmp->mx; y = mtmp->my; + x = mtmp->mx; + y = mtmp->my; mondead(mtmp); tmp = mdat->mlet; - if(tmp == 'm') { /* he killed a minotaur, give him a wand of digging */ + if (tmp == 'm') { /* he killed a minotaur, give him a wand of digging */ /* note: the dead minotaur will be on top of it! */ mksobj_at(WAN_DIGGING, x, y); - /* if(cansee(x,y)) atl(x,y,fobj->olet); */ + /* if (cansee(x, y)) atl(x, y, fobj->olet); */ stackobj(fobj); } else #ifndef NOWORM - if(tmp == 'w') { + if (tmp == 'w') { mksobj_at(WORM_TOOTH, x, y); stackobj(fobj); } else #endif /* NOWORM */ - if(!letter(tmp) || (!index("mw", tmp) && !rn2(3))) tmp = 0; - - if(ACCESSIBLE(levl[x][y].typ)) /* might be mimic in wall or dead eel*/ - if(x != u.ux || y != u.uy) /* might be here after swallowed */ - if(index("NTVm&",mdat->mlet) || rn2(5)) { - struct obj *obj2 = mkobj_at(tmp,x,y); - if(cansee(x,y)) - atl(x,y,obj2->olet); - stackobj(obj2); - } + if (!letter(tmp) || (!strchr("mw", tmp) && !rn2(3))) + tmp = 0; + + if (ACCESSIBLE(levl[x][y].typ)) /* might be mimic in wall or dead eel*/ + if (x != u.ux || y != u.uy) /* might be here after swallowed */ + if (strchr("NTVm&", mdat->mlet) || rn2(5)) { + struct obj *obj2 = mkobj_at(tmp, x, y); + if (cansee(x, y)) + atl(x, y, obj2->olet); + stackobj(obj2); + } } void kludge(const char *str, const char *arg) { - if(Blind) { - if(*str == '%') pline(str,"It"); - else pline(str,"it"); - } else pline(str,arg); + if (Blind) { + if (*str == '%') + pline(str, "It"); + else + pline(str, "it"); + } else + pline(str, arg); } void -rescham(void) /* force all chameleons to become normal */ +rescham(void) /* force all chameleons to become normal */ { struct monst *mtmp; - for(mtmp = fmon; mtmp; mtmp = mtmp->nmon) - if(mtmp->cham) { + for (mtmp = fmon; mtmp; mtmp = mtmp->nmon) + if (mtmp->cham) { mtmp->cham = 0; newcham(mtmp, PM_CHAMELEON); } @@ -795,37 +882,41 @@ newcham(struct monst *mtmp, struct permonst *mdat) { int mhp, hpn, hpd; - if(mdat == mtmp->data) return(0); /* still the same monster */ + if (mdat == mtmp->data) /* still the same monster */ + return (0); #ifndef NOWORM - if(mtmp->wormno) wormdead(mtmp); /* throw tail away */ + if (mtmp->wormno) /* throw tail away */ + wormdead(mtmp); #endif /* NOWORM */ if (u.ustuck == mtmp) { if (u.uswallow) { u.uswallow = 0; u.uswldtim = 0; - mnexto (mtmp); - docrt (); - prme (); + mnexto(mtmp); + docrt(); + prme(); } u.ustuck = 0; } hpn = mtmp->mhp; - hpd = (mtmp->data->mlevel)*8; - if(!hpd) hpd = 4; + hpd = (mtmp->data->mlevel) * 8; + if (!hpd) + hpd = 4; mtmp->data = mdat; - mhp = (mdat->mlevel)*8; + mhp = (mdat->mlevel) * 8; /* new hp: same fraction of max as before */ - mtmp->mhp = 2 + (hpn*mhp)/hpd; + mtmp->mhp = 2 + (hpn * mhp) / hpd; hpn = mtmp->mhpmax; - mtmp->mhpmax = 2 + (hpn*mhp)/hpd; + mtmp->mhpmax = 2 + (hpn * mhp) / hpd; mtmp->minvis = (mdat->mlet == 'I') ? 1 : 0; #ifndef NOWORM - if(mdat->mlet == 'w' && getwn(mtmp)) initworm(mtmp); - /* perhaps we should clear mtmp->mtame here? */ + if (mdat->mlet == 'w' && getwn(mtmp)) + initworm(mtmp); + /* perhaps we should clear mtmp->mtame here? */ #endif /* NOWORM */ unpmon(mtmp); /* necessary for 'I' and to force pmon */ pmon(mtmp); - return(1); + return (1); } /* Make monster mtmp next to you (if possible) */ @@ -842,24 +933,29 @@ mnexto(struct monst *mtmp) static bool ishuman(struct monst *mtmp) { - return(mtmp->data->mlet == '@'); + return (mtmp->data->mlet == '@'); } void setmangry(struct monst *mtmp) { - if(!mtmp->mpeaceful) return; - if(mtmp->mtame) return; + if (!mtmp->mpeaceful) + return; + if (mtmp->mtame) + return; mtmp->mpeaceful = 0; - if(ishuman(mtmp)) pline("%s gets angry!", Monnam(mtmp)); + if (ishuman(mtmp)) + pline("%s gets angry!", Monnam(mtmp)); } -/* not one hundred procent correct: now a snake may hide under an - invisible object */ +/* + * not one hundred percent correct: now a snake may hide under an invisible + * object + */ bool canseemon(struct monst *mtmp) { - return((!mtmp->minvis || See_invisible) - && (!mtmp->mhide || !o_at(mtmp->mx,mtmp->my)) + return ((!mtmp->minvis || See_invisible) + && (!mtmp->mhide || !o_at(mtmp->mx, mtmp->my)) && cansee(mtmp->mx, mtmp->my)); } diff --git a/games/hack/hack.monst.c b/games/hack/hack.monst.c index bf6470bd85..5b743acca3 100644 --- a/games/hack/hack.monst.c +++ b/games/hack/hack.monst.c @@ -5,7 +5,7 @@ #include "hack.h" #include "def.eshk.h" -struct permonst mons[CMNUM+2] = { +struct permonst mons[CMNUM + 2] = { { "bat", 'B',1,22,8,1,4,0 }, { "gnome", 'G',1,6,5,1,6,0 }, { "hobgoblin", 'H',1,9,5,1,8,0 }, @@ -66,7 +66,7 @@ struct permonst mons[CMNUM+2] = { { "purple worm", 'P',15,9,6,2,8,0 }, { "demon", '&',10,12,-4,1,4,0 }, { "minotaur", 'm',15,15,6,4,10,0 }, - { "shopkeeper", '@', 12, 18, 0, 4, 8, sizeof(struct eshk) } + { "shopkeeper", '@', 12, 18, 0, 4, 8, sizeof(struct eshk) } }; struct permonst pm_ghost = { "ghost", ' ', 10, 3, -5, 1, 1, sizeof(plname) }; diff --git a/games/hack/hack.o_init.c b/games/hack/hack.o_init.c index fb64b355dc..dc17896104 100644 --- a/games/hack/hack.o_init.c +++ b/games/hack/hack.o_init.c @@ -3,20 +3,22 @@ /* $FreeBSD: src/games/hack/hack.o_init.c,v 1.6 1999/11/16 10:26:37 marcel Exp $ */ /* $DragonFly: src/games/hack/hack.o_init.c,v 1.4 2006/08/21 19:45:32 pavalos Exp $ */ -#include "def.objects.h" -#include "hack.h" +#include "def.objects.h" +#include "hack.h" -static void setgemprobs(void); -static bool interesting_to_discover(int); +static void setgemprobs(void); +static bool interesting_to_discover(int); int letindex(char let) { -int i = 0; -char ch; - while((ch = obj_symbols[i++]) != 0) - if(ch == let) return(i); - return(0); + int i = 0; + char ch; + + while ((ch = obj_symbols[i++]) != 0) + if (ch == let) + return (i); + return (0); } void @@ -26,41 +28,44 @@ init_objects(void) char let; const char *tmp; - /* init base; if probs given check that they add up to 100, - otherwise compute probs; shuffle descriptions */ + /* + * init base; if probs given check that they add up to 100, otherwise + * compute probs; shuffle descriptions + */ end = SIZE(objects); first = 0; - while( first < end ) { + while (first < end) { let = objects[first].oc_olet; - last = first+1; - while(last < end && objects[last].oc_olet == let - && objects[last].oc_name != NULL) + last = first + 1; + while (last < end && objects[last].oc_olet == let + && objects[last].oc_name != NULL) last++; i = letindex(let); - if((!i && let != ILLOBJ_SYM) || bases[i] != 0) + if ((!i && let != ILLOBJ_SYM) || bases[i] != 0) error("initialization error"); bases[i] = first; - if(let == GEM_SYM) + if (let == GEM_SYM) setgemprobs(); - check: +check: sum = 0; - for(j = first; j < last; j++) sum += objects[j].oc_prob; - if(sum == 0) { - for(j = first; j < last; j++) - objects[j].oc_prob = (100+j-first)/(last-first); + for (j = first; j < last; j++) + sum += objects[j].oc_prob; + if (sum == 0) { + for (j = first; j < last; j++) + objects[j].oc_prob = (100 + j - first) / (last - first); goto check; } - if(sum != 100) + if (sum != 100) error("init-prob error for %c", let); - if(objects[first].oc_descr != NULL && let != TOOL_SYM){ + if (objects[first].oc_descr != NULL && let != TOOL_SYM) { /* shuffle, also some additional descriptions */ - while(last < end && objects[last].oc_olet == let) + while (last < end && objects[last].oc_olet == let) last++; j = last; - while(--j > first) { - i = first + rn2(j+1-first); + while (--j > first) { + i = first + rn2(j + 1 - first); tmp = objects[j].oc_descr; objects[j].oc_descr = objects[i].oc_descr; objects[i].oc_descr = tmp; @@ -73,35 +78,37 @@ init_objects(void) int probtype(char let) { -int i = bases[letindex(let)]; -int prob = rn2(100); - while((prob -= objects[i].oc_prob) >= 0) i++; - if(objects[i].oc_olet != let || !objects[i].oc_name) + int i = bases[letindex(let)]; + int prob = rn2(100); + + while ((prob -= objects[i].oc_prob) >= 0) + i++; + if (objects[i].oc_olet != let || !objects[i].oc_name) panic("probtype(%c) error, i=%d", let, i); - return(i); + return (i); } static void setgemprobs(void) { - int j,first; + int j, first; first = bases[letindex(GEM_SYM)]; - for(j = 0; j < 9-dlevel/3; j++) - objects[first+j].oc_prob = 0; + for (j = 0; j < 9 - dlevel / 3; j++) + objects[first + j].oc_prob = 0; first += j; - if(first >= LAST_GEM || first >= SIZE(objects) || + if (first >= LAST_GEM || first >= SIZE(objects) || objects[first].oc_olet != GEM_SYM || objects[first].oc_name == NULL) printf("Not enough gems? - first=%d j=%d LAST_GEM=%d\n", - first, j, LAST_GEM); - for(j = first; j < LAST_GEM; j++) - objects[j].oc_prob = (20+j-first)/(LAST_GEM-first); + first, j, LAST_GEM); + for (j = first; j < LAST_GEM; j++) + objects[j].oc_prob = (20 + j - first) / (LAST_GEM - first); } void -oinit(void) /* level dependent initialization */ +oinit(void) /* level dependent initialization */ { setgemprobs(); } @@ -109,17 +116,19 @@ oinit(void) /* level dependent initialization */ void savenames(int fd) { -int i; -unsigned len; - bwrite(fd, (char *) bases, sizeof bases); - bwrite(fd, (char *) objects, sizeof objects); - /* as long as we use only one version of Hack/Quest we - need not save oc_name and oc_descr, but we must save - oc_uname for all objects */ - for(i=0; i < SIZE(objects); i++) { - if(objects[i].oc_uname) { - len = strlen(objects[i].oc_uname)+1; - bwrite(fd, (char *) &len, sizeof len); + int i; + unsigned len; + + bwrite(fd, (char *)bases, sizeof(bases)); + bwrite(fd, (char *)objects, sizeof(objects)); + /* + * as long as we use only one version of Hack/Quest we need not save + * oc_name and oc_descr, but we must save oc_uname for all objects + */ + for (i = 0; i < SIZE(objects); i++) { + if (objects[i].oc_uname) { + len = strlen(objects[i].oc_uname) + 1; + bwrite(fd, (char *)&len, sizeof(len)); bwrite(fd, objects[i].oc_uname, len); } } @@ -128,46 +137,48 @@ unsigned len; void restnames(int fd) { -int i; -unsigned len; - mread(fd, (char *) bases, sizeof bases); - mread(fd, (char *) objects, sizeof objects); - for(i=0; i < SIZE(objects); i++) if(objects[i].oc_uname) { - mread(fd, (char *) &len, sizeof len); - objects[i].oc_uname = (char *) alloc(len); - mread(fd, objects[i].oc_uname, len); - } + int i; + unsigned len; + + mread(fd, (char *)bases, sizeof(bases)); + mread(fd, (char *)objects, sizeof(objects)); + for (i = 0; i < SIZE(objects); i++) + if (objects[i].oc_uname) { + mread(fd, (char *)&len, sizeof(len)); + objects[i].oc_uname = alloc(len); + mread(fd, objects[i].oc_uname, len); + } } int -dodiscovered(void) /* free after Robert Viduya */ +dodiscovered(void) /* free after Robert Viduya */ { - int i, end; - int ct = 0; + int i, end; + int ct = 0; - cornline(0, "Discoveries"); + cornline(0, "Discoveries"); - end = SIZE(objects); - for (i = 0; i < end; i++) { - if (interesting_to_discover (i)) { - ct++; - cornline(1, typename(i)); + end = SIZE(objects); + for (i = 0; i < end; i++) { + if (interesting_to_discover(i)) { + ct++; + cornline(1, typename(i)); + } } - } - if (ct == 0) { - pline ("You haven't discovered anything yet..."); - cornline(3, NULL); - } else - cornline(2, NULL); - - return(0); + if (ct == 0) { + pline("You haven't discovered anything yet..."); + cornline(3, NULL); + } else + cornline(2, NULL); + + return (0); } static bool interesting_to_discover(int i) { - return( - objects[i].oc_uname != NULL || - (objects[i].oc_name_known && objects[i].oc_descr != NULL) - ); + return ( + objects[i].oc_uname != NULL || + (objects[i].oc_name_known && objects[i].oc_descr != NULL) + ); } diff --git a/games/hack/hack.objnam.c b/games/hack/hack.objnam.c index 99e9112322..7b8589f186 100644 --- a/games/hack/hack.objnam.c +++ b/games/hack/hack.objnam.c @@ -3,47 +3,50 @@ /* $FreeBSD: src/games/hack/hack.objnam.c,v 1.3 1999/11/16 02:57:08 billf Exp $ */ /* $DragonFly: src/games/hack/hack.objnam.c,v 1.4 2006/08/21 19:45:32 pavalos Exp $ */ -#include "hack.h" -#define Sprintf (void) sprintf -#define Strcat (void) strcat +#include "hack.h" +#define Sprintf (void) sprintf +#define Strcat (void) strcat #define Strcpy (void) strcpy #define PREFIX 15 extern int bases[]; -static char *strprepend(char *, char *); -static char *sitoa(int); +static char *strprepend(char *, char *); +static char *sitoa(int); static char * strprepend(char *s, char *pref) { -int i = strlen(pref); - if(i > PREFIX) { + int i = strlen(pref); + + if (i > PREFIX) { pline("WARNING: prefix too short."); - return(s); + return (s); } s -= i; strncpy(s, pref, i); /* do not copy trailing 0 */ - return(s); + return (s); } static char * sitoa(int a) { -static char buf[13]; + static char buf[13]; + Sprintf(buf, (a < 0) ? "%d" : "+%d", a); - return(buf); + return (buf); } char * typename(int otyp) { -static char buf[BUFSZ]; -struct objclass *ocl = &objects[otyp]; -const char *an = ocl->oc_name; -const char *dn = ocl->oc_descr; -char *un = ocl->oc_uname; -int nn = ocl->oc_name_known; - switch(ocl->oc_olet) { + static char buf[BUFSZ]; + struct objclass *ocl = &objects[otyp]; + const char *an = ocl->oc_name; + const char *dn = ocl->oc_descr; + char *un = ocl->oc_uname; + int nn = ocl->oc_name_known; + + switch (ocl->oc_olet) { case POTION_SYM: Strcpy(buf, "potion"); break; @@ -57,95 +60,99 @@ int nn = ocl->oc_name_known; Strcpy(buf, "ring"); break; default: - if(nn) { + if (nn) { Strcpy(buf, an); - if(otyp >= TURQUOISE && otyp <= JADE) + if (otyp >= TURQUOISE && otyp <= JADE) Strcat(buf, " stone"); - if(un) + if (un) Sprintf(eos(buf), " called %s", un); - if(dn) + if (dn) Sprintf(eos(buf), " (%s)", dn); } else { Strcpy(buf, dn ? dn : an); - if(ocl->oc_olet == GEM_SYM) + if (ocl->oc_olet == GEM_SYM) Strcat(buf, " gem"); - if(un) + if (un) Sprintf(eos(buf), " called %s", un); } - return(buf); + return (buf); } /* here for ring/scroll/potion/wand */ - if(nn) + if (nn) Sprintf(eos(buf), " of %s", an); - if(un) + if (un) Sprintf(eos(buf), " called %s", un); - if(dn) + if (dn) Sprintf(eos(buf), " (%s)", dn); - return(buf); + return (buf); } char * xname(struct obj *obj) { -static char bufr[BUFSZ]; -char *buf = &(bufr[PREFIX]); /* leave room for "17 -3 " */ -int nn = objects[obj->otyp].oc_name_known; -const char *an = objects[obj->otyp].oc_name; -const char *dn = objects[obj->otyp].oc_descr; -char *un = objects[obj->otyp].oc_uname; -int pl = (obj->quan != 1); - if(!obj->dknown && !Blind) obj->dknown = 1; /* %% doesnt belong here */ - switch(obj->olet) { + static char bufr[BUFSZ]; + /* caution: doname() and aobjnam() below "know" these sizes */ + char *buf = &(bufr[PREFIX]); /* leave room for "17 -3 " */ + int nn = objects[obj->otyp].oc_name_known; + const char *an = objects[obj->otyp].oc_name; + const char *dn = objects[obj->otyp].oc_descr; + char *un = objects[obj->otyp].oc_uname; + int pl = (obj->quan != 1); + + if (!obj->dknown && !Blind) /* %% doesnt belong here */ + obj->dknown = 1; + switch (obj->olet) { case AMULET_SYM: Strcpy(buf, (obj->spe < 0 && obj->known) - ? "cheap plastic imitation of the " : ""); - Strcat(buf,"Amulet of Yendor"); + ? "cheap plastic imitation of the " : ""); + Strcat(buf, "Amulet of Yendor"); break; case TOOL_SYM: - if(!nn) { + if (!nn) { Strcpy(buf, dn); break; } - Strcpy(buf,an); + Strcpy(buf, an); break; case FOOD_SYM: - if(obj->otyp == DEAD_HOMUNCULUS && pl) { + if (obj->otyp == DEAD_HOMUNCULUS && pl) { pl = 0; Strcpy(buf, "dead homunculi"); break; } - /* fungis ? */ - /* fall into next case */ + /* fungis ? */ + /* fall into next case */ case WEAPON_SYM: - if(obj->otyp == WORM_TOOTH && pl) { + if (obj->otyp == WORM_TOOTH && pl) { pl = 0; Strcpy(buf, "worm teeth"); break; } - if(obj->otyp == CRYSKNIFE && pl) { + if (obj->otyp == CRYSKNIFE && pl) { pl = 0; Strcpy(buf, "crysknives"); break; } - /* fall into next case */ + /* fall into next case */ case ARMOR_SYM: case CHAIN_SYM: case ROCK_SYM: - Strcpy(buf,an); + Strcpy(buf, an); break; case BALL_SYM: Sprintf(buf, "%sheavy iron ball", - (obj->owt > objects[obj->otyp].oc_weight) ? "very " : ""); + (obj->owt > objects[obj->otyp].oc_weight) ? "very " : ""); break; case POTION_SYM: - if(nn || un || !obj->dknown) { + if (nn || un || !obj->dknown) { Strcpy(buf, "potion"); - if(pl) { + if (pl) { pl = 0; Strcat(buf, "s"); } - if(!obj->dknown) break; - if(un) { + if (!obj->dknown) + break; + if (un) { Strcat(buf, " called "); Strcat(buf, un); } else { @@ -159,15 +166,16 @@ int pl = (obj->quan != 1); break; case SCROLL_SYM: Strcpy(buf, "scroll"); - if(pl) { + if (pl) { pl = 0; Strcat(buf, "s"); } - if(!obj->dknown) break; - if(nn) { + if (!obj->dknown) + break; + if (nn) { Strcat(buf, " of "); Strcat(buf, an); - } else if(un) { + } else if (un) { Strcat(buf, " called "); Strcat(buf, un); } else { @@ -176,125 +184,129 @@ int pl = (obj->quan != 1); } break; case WAND_SYM: - if(!obj->dknown) + if (!obj->dknown) Sprintf(buf, "wand"); - else if(nn) + else if (nn) Sprintf(buf, "wand of %s", an); - else if(un) + else if (un) Sprintf(buf, "wand called %s", un); else Sprintf(buf, "%s wand", dn); break; case RING_SYM: - if(!obj->dknown) + if (!obj->dknown) Sprintf(buf, "ring"); - else if(nn) + else if (nn) Sprintf(buf, "ring of %s", an); - else if(un) + else if (un) Sprintf(buf, "ring called %s", un); else Sprintf(buf, "%s ring", dn); break; case GEM_SYM: - if(!obj->dknown) { + if (!obj->dknown) { Strcpy(buf, "gem"); break; } - if(!nn) { + if (!nn) { Sprintf(buf, "%s gem", dn); break; } Strcpy(buf, an); - if(obj->otyp >= TURQUOISE && obj->otyp <= JADE) + if (obj->otyp >= TURQUOISE && obj->otyp <= JADE) Strcat(buf, " stone"); break; default: - Sprintf(buf,"glorkum %c (0%o) %u %d", - obj->olet,obj->olet,obj->otyp,obj->spe); + Sprintf(buf, "glorkum %c (0%o) %u %d", + obj->olet, obj->olet, obj->otyp, obj->spe); } - if(pl) { + if (pl) { char *p; - for(p = buf; *p; p++) { - if(!strncmp(" of ", p, 4)) { + for (p = buf; *p; p++) + if (!strncmp(" of ", p, 4)) { /* pieces of, cloves of, lumps of */ int c1, c2 = 's'; do { - c1 = c2; c2 = *p; *p++ = c1; - } while(c1); + c1 = c2; + c2 = *p; + *p++ = c1; + } while (c1); goto nopl; } - } - p = eos(buf)-1; - if(*p == 's' || *p == 'z' || *p == 'x' || + p = eos(buf) - 1; + if (*p == 's' || *p == 'z' || *p == 'x' || (*p == 'h' && p[-1] == 's')) Strcat(buf, "es"); /* boxes */ - else if(*p == 'y' && !index(vowels, p[-1])) + else if (*p == 'y' && !strchr(vowels, p[-1])) Strcpy(p, "ies"); /* rubies, zruties */ else Strcat(buf, "s"); } nopl: - if(obj->onamelth) { + if (obj->onamelth) { Strcat(buf, " named "); Strcat(buf, ONAME(obj)); } - return(buf); + return (buf); } char * doname(struct obj *obj) { -char prefix[PREFIX]; -char *bp = xname(obj); - if(obj->quan != 1) + char prefix[PREFIX]; + char *bp = xname(obj); + + if (obj->quan != 1) Sprintf(prefix, "%u ", obj->quan); else Strcpy(prefix, "a "); - switch(obj->olet) { + switch (obj->olet) { case AMULET_SYM: - if(strncmp(bp, "cheap ", 6)) + if (strncmp(bp, "cheap ", 6)) Strcpy(prefix, "the "); break; case ARMOR_SYM: - if(obj->owornmask & W_ARMOR) + if (obj->owornmask & W_ARMOR) Strcat(bp, " (being worn)"); - /* fall into next case */ + /* fall into next case */ case WEAPON_SYM: - if(obj->known) { + if (obj->known) { Strcat(prefix, sitoa(obj->spe)); Strcat(prefix, " "); } break; case WAND_SYM: - if(obj->known) + if (obj->known) Sprintf(eos(bp), " (%d)", obj->spe); break; case RING_SYM: - if(obj->owornmask & W_RINGR) Strcat(bp, " (on right hand)"); - if(obj->owornmask & W_RINGL) Strcat(bp, " (on left hand)"); - if(obj->known && (objects[obj->otyp].bits & SPEC)) { + if (obj->owornmask & W_RINGR) + Strcat(bp, " (on right hand)"); + if (obj->owornmask & W_RINGL) + Strcat(bp, " (on left hand)"); + if (obj->known && (objects[obj->otyp].bits & SPEC)) { Strcat(prefix, sitoa(obj->spe)); Strcat(prefix, " "); } break; } - if(obj->owornmask & W_WEP) + if (obj->owornmask & W_WEP) Strcat(bp, " (weapon in hand)"); - if(obj->unpaid) + if (obj->unpaid) Strcat(bp, " (unpaid)"); - if(!strcmp(prefix, "a ") && index(vowels, *bp)) + if (!strcmp(prefix, "a ") && strchr(vowels, *bp)) Strcpy(prefix, "an "); bp = strprepend(bp, prefix); - return(bp); + return (bp); } /* used only in hack.fight.c (thitu) */ void setan(const char *str, char *buf) { - if(index(vowels,*str)) + if (strchr(vowels, *str)) Sprintf(buf, "an %s", str); else Sprintf(buf, "a %s", str); @@ -303,26 +315,27 @@ setan(const char *str, char *buf) char * aobjnam(struct obj *otmp, const char *verb) { -char *bp = xname(otmp); -char prefix[PREFIX]; - if(otmp->quan != 1) { + char *bp = xname(otmp); + char prefix[PREFIX]; + + if (otmp->quan != 1) { Sprintf(prefix, "%u ", otmp->quan); bp = strprepend(bp, prefix); } - if(verb) { + if (verb) { /* verb is given in plural (i.e., without trailing s) */ Strcat(bp, " "); - if(otmp->quan != 1) + if (otmp->quan != 1) Strcat(bp, verb); - else if(!strcmp(verb, "are")) + else if (!strcmp(verb, "are")) Strcat(bp, "is"); else { Strcat(bp, verb); Strcat(bp, "s"); } } - return(bp); + return (bp); } char * @@ -330,218 +343,243 @@ Doname(struct obj *obj) { char *s = doname(obj); - if('a' <= *s && *s <= 'z') *s -= ('a' - 'A'); - return(s); + if ('a' <= *s && *s <= 'z') + *s -= ('a' - 'A'); + return (s); } -static const char *wrp[] = { "wand", "ring", "potion", "scroll", "gem" }; +static const char *wrp[] = { "wand", "ring", "potion", "scroll", "gem" }; char wrpsym[] = { WAND_SYM, RING_SYM, POTION_SYM, SCROLL_SYM, GEM_SYM }; struct obj * readobjnam(char *bp) { -char *p; -int i; -int cnt, spe, spesgn, typ, heavy; -char let; -char *un, *dn, *an; + char *p; + int i; + int cnt, spe, spesgn, typ, heavy; + char let; + char *un, *dn, *an; + cnt = spe = spesgn = typ = heavy = 0; let = 0; an = dn = un = 0; - for(p = bp; *p; p++) - if('A' <= *p && *p <= 'Z') *p += 'a'-'A'; - if(!strncmp(bp, "the ", 4)){ + for (p = bp; *p; p++) + if ('A' <= *p && *p <= 'Z') + *p += 'a' - 'A'; + if (!strncmp(bp, "the ", 4)) bp += 4; - } else if(!strncmp(bp, "an ", 3)){ + else if (!strncmp(bp, "an ", 3)) { cnt = 1; bp += 3; - } else if(!strncmp(bp, "a ", 2)){ + } else if (!strncmp(bp, "a ", 2)) { cnt = 1; bp += 2; } - if(!cnt && digit(*bp)){ + if (!cnt && digit(*bp)) { cnt = atoi(bp); - while(digit(*bp)) bp++; - while(*bp == ' ') bp++; + while (digit(*bp)) + bp++; + while (*bp == ' ') + bp++; } - if(!cnt) cnt = 1; /* %% what with "gems" etc. ? */ + if (!cnt) /* %% what with "gems" etc. ? */ + cnt = 1; - if(*bp == '+' || *bp == '-'){ + if (*bp == '+' || *bp == '-') { spesgn = (*bp++ == '+') ? 1 : -1; spe = atoi(bp); - while(digit(*bp)) bp++; - while(*bp == ' ') bp++; + while (digit(*bp)) + bp++; + while (*bp == ' ') + bp++; } else { - p = rindex(bp, '('); - if(p) { - if(p > bp && p[-1] == ' ') p[-1] = 0; - else *p = 0; + p = strrchr(bp, '('); + if (p) { + if (p > bp && p[-1] == ' ') + p[-1] = 0; + else + *p = 0; p++; spe = atoi(p); - while(digit(*p)) p++; - if(strcmp(p, ")")) spe = 0; - else spesgn = 1; + while (digit(*p)) + p++; + if (strcmp(p, ")")) + spe = 0; + else + spesgn = 1; } } - /* now we have the actual name, as delivered by xname, say - green potions called whisky - scrolls labeled "QWERTY" - egg - dead zruties - fortune cookies - very heavy iron ball named hoei - wand of wishing - elven cloak - */ - for(p = bp; *p; p++) if(!strncmp(p, " named ", 7)) { - *p = 0; - } - for(p = bp; *p; p++) if(!strncmp(p, " called ", 8)) { - *p = 0; - un = p+8; - } - for(p = bp; *p; p++) if(!strncmp(p, " labeled ", 9)) { - *p = 0; - dn = p+9; - } + /* + * now we have the actual name, as delivered by xname, say + * green potions called whisky + * scrolls labeled "QWERTY" + * egg + * dead zruties + * fortune cookies + * very heavy iron ball named hoei + * wand of wishing + * elven cloak + */ + for (p = bp; *p; p++) + if (!strncmp(p, " named ", 7)) + *p = 0; + + for (p = bp; *p; p++) + if (!strncmp(p, " called ", 8)) { + *p = 0; + un = p + 8; + } + for (p = bp; *p; p++) + if (!strncmp(p, " labeled ", 9)) { + *p = 0; + dn = p + 9; + } /* first change to singular if necessary */ - if(cnt != 1) { + if (cnt != 1) { /* find "cloves of garlic", "worthless pieces of blue glass" */ - for(p = bp; *p; p++) if(!strncmp(p, "s of ", 5)){ - while((*p = p[1])) p++; - goto sing; - } + for (p = bp; *p; p++) + if (!strncmp(p, "s of ", 5)) { + while ((*p = p[1])) + p++; + goto sing; + } /* remove -s or -es (boxes) or -ies (rubies, zruties) */ p = eos(bp); - if(p[-1] == 's') { - if(p[-2] == 'e') { - if(p[-3] == 'i') { - if(!strcmp(p-7, "cookies")) + if (p[-1] == 's') { + if (p[-2] == 'e') { + if (p[-3] == 'i') { + if (!strcmp(p - 7, "cookies")) goto mins; - Strcpy(p-3, "y"); + Strcpy(p - 3, "y"); goto sing; } /* note: cloves / knives from clove / knife */ - if(!strcmp(p-6, "knives")) { - Strcpy(p-3, "fe"); + if (!strcmp(p - 6, "knives")) { + Strcpy(p - 3, "fe"); goto sing; } /* note: nurses, axes but boxes */ - if(!strcmp(p-5, "boxes")) { + if (!strcmp(p - 5, "boxes")) { p[-2] = 0; goto sing; } } - mins: +mins: p[-1] = 0; } else { - if(!strcmp(p-9, "homunculi")) { - Strcpy(p-1, "us"); /* !! makes string longer */ + if (!strcmp(p - 9, "homunculi")) { + Strcpy(p - 1, "us"); /* !! makes string longer */ goto sing; } - if(!strcmp(p-5, "teeth")) { - Strcpy(p-5, "tooth"); + if (!strcmp(p - 5, "teeth")) { + Strcpy(p - 5, "tooth"); goto sing; } /* here we cannot find the plural suffix */ } } sing: - if(!strcmp(bp, "amulet of yendor")) { + if (!strcmp(bp, "amulet of yendor")) { typ = AMULET_OF_YENDOR; goto typfnd; } p = eos(bp); - if(!strcmp(p-5, " mail")){ /* Note: ring mail is not a ring ! */ + if (!strcmp(p - 5, " mail")) { /* Note: ring mail is not a ring ! */ let = ARMOR_SYM; an = bp; goto srch; } - for(i = 0; (unsigned)i < sizeof(wrpsym); i++) { + for (i = 0; (unsigned)i < sizeof(wrpsym); i++) { int j = strlen(wrp[i]); - if(!strncmp(bp, wrp[i], j)){ + if (!strncmp(bp, wrp[i], j)) { let = wrpsym[i]; bp += j; - if(!strncmp(bp, " of ", 4)) an = bp+4; - /* else if(*bp) ?? */ + if (!strncmp(bp, " of ", 4)) + an = bp + 4; + /* else if (*bp) ?? */ goto srch; } - if(!strcmp(p-j, wrp[i])){ + if (!strcmp(p - j, wrp[i])) { let = wrpsym[i]; p -= j; *p = 0; - if(p[-1] == ' ') p[-1] = 0; + if (p[-1] == ' ') + p[-1] = 0; dn = bp; goto srch; } } - if(!strcmp(p-6, " stone")){ + if (!strcmp(p - 6, " stone")) { p[-6] = 0; let = GEM_SYM; an = bp; goto srch; } - if(!strcmp(bp, "very heavy iron ball")){ + if (!strcmp(bp, "very heavy iron ball")) { heavy = 1; typ = HEAVY_IRON_BALL; goto typfnd; } an = bp; srch: - if(!an && !dn && !un) + if (!an && !dn && !un) goto any; i = 1; - if(let) i = bases[letindex(let)]; - while(i <= NROFOBJECTS && (!let || objects[i].oc_olet == let)){ + if (let) + i = bases[letindex(let)]; + while (i <= NROFOBJECTS && (!let || objects[i].oc_olet == let)) { const char *zn = objects[i].oc_name; - if(!zn) goto nxti; - if(an && strcmp(an, zn)) + if (!zn) goto nxti; - if(dn && (!(zn = objects[i].oc_descr) || strcmp(dn, zn))) + if (an && strcmp(an, zn)) goto nxti; - if(un && (!(zn = objects[i].oc_uname) || strcmp(un, zn))) + if (dn && (!(zn = objects[i].oc_descr) || strcmp(dn, zn))) + goto nxti; + if (un && (!(zn = objects[i].oc_uname) || strcmp(un, zn))) goto nxti; typ = i; goto typfnd; - nxti: +nxti: i++; } any: - if(!let) let = wrpsym[rn2(sizeof(wrpsym))]; + if (!let) + let = wrpsym[rn2(sizeof(wrpsym))]; typ = probtype(let); typfnd: - { struct obj *otmp; - let = objects[typ].oc_olet; - otmp = mksobj(typ); - if(heavy) - otmp->owt += 15; - if(cnt > 0 && index("%?!*)", let) && - (cnt < 4 || (let == WEAPON_SYM && typ <= ROCK && cnt < 20))) - otmp->quan = cnt; - - if(spe > 3 && spe > otmp->spe) - spe = 0; - else if(let == WAND_SYM) - spe = otmp->spe; - if(spe == 3 && u.uluck < 0) - spesgn = -1; - if(let != WAND_SYM && spesgn == -1) - spe = -spe; - if(let == BALL_SYM) - spe = 0; - else if(let == AMULET_SYM) - spe = -1; - else if(typ == WAN_WISHING && rn2(10)) - spe = (rn2(10) ? -1 : 0); - otmp->spe = spe; - - if(spesgn == -1) - otmp->cursed = 1; - - return(otmp); - } + { + struct obj *otmp; + let = objects[typ].oc_olet; + otmp = mksobj(typ); + if (heavy) + otmp->owt += 15; + if (cnt > 0 && strchr("%?!*)", let) && + (cnt < 4 || (let == WEAPON_SYM && typ <= ROCK && cnt < 20))) + otmp->quan = cnt; + + if (spe > 3 && spe > otmp->spe) + spe = 0; + else if (let == WAND_SYM) + spe = otmp->spe; + if (spe == 3 && u.uluck < 0) + spesgn = -1; + if (let != WAND_SYM && spesgn == -1) + spe = -spe; + if (let == BALL_SYM) + spe = 0; + else if (let == AMULET_SYM) + spe = -1; + else if (typ == WAN_WISHING && rn2(10)) + spe = (rn2(10) ? -1 : 0); + otmp->spe = spe; + + if (spesgn == -1) + otmp->cursed = 1; + + return (otmp); + } } diff --git a/games/hack/hack.options.c b/games/hack/hack.options.c index fc0dc51f8b..920bdb3d77 100644 --- a/games/hack/hack.options.c +++ b/games/hack/hack.options.c @@ -5,7 +5,7 @@ #include "hack.h" -static void parseoptions(char *, bool); +static void parseoptions(char *, bool); void initoptions(void) @@ -13,116 +13,123 @@ initoptions(void) char *opts; flags.time = flags.nonews = flags.notombstone = flags.end_own = - flags.standout = flags.nonull = FALSE; + flags.standout = flags.nonull = FALSE; flags.no_rest_on_space = TRUE; flags.invlet_constant = TRUE; flags.end_top = 5; flags.end_around = 4; - flags.female = FALSE; /* players are usually male */ + flags.female = FALSE; /* players are usually male */ - if((opts = getenv("HACKOPTIONS"))) + if ((opts = getenv("HACKOPTIONS"))) parseoptions(opts,TRUE); } static void parseoptions(char *opts, bool from_env) { - char *op,*op2; + char *op, *op2; unsigned num; boolean negated; - if((op = index(opts, ','))) { + if ((op = strchr(opts, ',')) != NULL) { *op++ = 0; parseoptions(op, from_env); } - if((op = index(opts, ' '))) { + if ((op = strchr(opts, ' ')) != NULL) { op2 = op; - while(*op++) - if(*op != ' ') *op2++ = *op; + while (*op++) + if (*op != ' ') + *op2++ = *op; } - if(!*opts) return; + if (!*opts) + return; negated = FALSE; - while((*opts == '!') || !strncmp(opts, "no", 2)) { - if(*opts == '!') opts++; else opts += 2; + while ((*opts == '!') || !strncmp(opts, "no", 2)) { + if (*opts == '!') + opts++; + else + opts += 2; negated = !negated; } - if(!strncmp(opts,"standout",8)) { + if (!strncmp(opts, "standout", 8)) { flags.standout = !negated; return; } - if(!strncmp(opts,"null",3)) { + if (!strncmp(opts, "null", 3)) { flags.nonull = negated; return; } - if(!strncmp(opts,"tombstone",4)) { + if (!strncmp(opts, "tombstone", 4)) { flags.notombstone = negated; return; } - if(!strncmp(opts,"news",4)) { + if (!strncmp(opts, "news", 4)) { flags.nonews = negated; return; } - if(!strncmp(opts,"time",4)) { + if (!strncmp(opts, "time", 4)) { flags.time = !negated; flags.botl = 1; return; } - if(!strncmp(opts,"restonspace",4)) { + if (!strncmp(opts, "restonspace", 4)) { flags.no_rest_on_space = negated; return; } - if(!strncmp(opts,"fixinv",4)) { - if(from_env) + if (!strncmp(opts, "fixinv", 4)) { + if (from_env) flags.invlet_constant = !negated; else pline("The fixinvlet option must be in HACKOPTIONS."); return; } - if(!strncmp(opts,"male",4)) { + if (!strncmp(opts, "male", 4)) { flags.female = negated; return; } - if(!strncmp(opts,"female",6)) { + if (!strncmp(opts, "female", 6)) { flags.female = !negated; return; } /* name:string */ - if(!strncmp(opts,"name",4)) { - if(!from_env) { - pline("The playername can be set only from HACKOPTIONS."); - return; + if (!strncmp(opts, "name", 4)) { + if (!from_env) { + pline("The playername can be set only from HACKOPTIONS."); + return; } - op = index(opts,':'); - if(!op) goto bad; - strncpy(plname, op+1, sizeof(plname)-1); + op = strchr(opts, ':'); + if (!op) + goto bad; + strncpy(plname, op + 1, sizeof(plname) - 1); return; } /* endgame:5t[op] 5a[round] o[wn] */ - if(!strncmp(opts,"endgame",3)) { - op = index(opts,':'); - if(!op) goto bad; + if (!strncmp(opts, "endgame", 3)) { + op = strchr(opts, ':'); + if (!op) + goto bad; op++; - while(*op) { + while (*op) { num = 1; - if(digit(*op)) { + if (digit(*op)) { num = atoi(op); - while(digit(*op)) op++; - } else - if(*op == '!') { + while (digit(*op)) + op++; + } else if (*op == '!') { negated = !negated; op++; } - switch(*op) { + switch (*op) { case 't': flags.end_top = num; break; @@ -135,28 +142,30 @@ parseoptions(char *opts, bool from_env) default: goto bad; } - while(letter(*++op)) ; - if(*op == '/') op++; + while (letter(*++op)) + ; /* nothing */ + if (*op == '/') + op++; } return; } bad: - if(!from_env) { - if(!strncmp(opts, "help", 4)) { + if (!from_env) { + if (!strncmp(opts, "help", 4)) { pline("%s%s%s", -"To set options use `HACKOPTIONS=\"\"' in your environment, or ", -"give the command 'o' followed by the line `' while playing. ", -"Here is a list of