1 /* SCCS Id: @(#)allmain.c 3.4 2003/04/02 */
2 /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */
3 /* NetHack may be freely redistributed. See license for details. */
5 /* various code that was replicated in *main.c */
14 STATIC_DCL void NDECL(do_positionbar);
22 #if defined(MICRO) || defined(WIN32)
26 int moveamt = 0, wtcap = 0, change = 0;
27 boolean didmove = FALSE, monscanmove = FALSE;
29 flags.moonphase = phase_of_the_moon();
30 if(flags.moonphase == FULL_MOON) {
31 You("are lucky! Full moon tonight.");
33 } else if(flags.moonphase == NEW_MOON) {
34 pline("Be careful! New moon tonight.");
36 flags.friday13 = friday_13th();
38 pline("Watch out! Bad things can happen on Friday the 13th.");
45 /* Note: these initializers don't do anything except guarantee that
46 we're linked properly.
50 monstr_init(); /* monster strengths */
54 if (wizard) add_debug_extended_commands();
57 (void) encumber_msg(); /* in case they auto-picked up something */
59 u.uz0.dlevel = u.uz.dlevel;
60 youmonst.movement = NORMAL_SPEED; /* give the hero some movement points */
70 /* actual time passed */
71 youmonst.movement -= NORMAL_SPEED;
73 do { /* hero can't move this turn loop */
74 wtcap = encumber_msg();
76 flags.mon_moving = TRUE;
78 monscanmove = movemon();
79 if (youmonst.movement > NORMAL_SPEED)
80 break; /* it's now your turn */
81 } while (monscanmove);
82 flags.mon_moving = FALSE;
84 if (!monscanmove && youmonst.movement < NORMAL_SPEED) {
85 /* both you and the monsters are out of steam this round */
86 /* set up for a new turn */
88 mcalcdistress(); /* adjust monsters' trap, blind, etc */
90 /* reallocate movement rations to monsters */
91 for (mtmp = fmon; mtmp; mtmp = mtmp->nmon)
92 mtmp->movement += mcalcmove(mtmp);
94 if(!rn2(u.uevent.udemigod ? 25 :
95 (depth(&u.uz) > depth(&stronghold_level)) ? 50 : 70))
96 (void) makemon((struct permonst *)0, 0, 0, NO_MM_FLAGS);
98 /* calculate how much time passed. */
100 if (u.usteed && u.umoved) {
101 /* your speed doesn't augment steed's speed */
102 moveamt = mcalcmove(u.usteed);
106 moveamt = youmonst.data->mmove;
108 if (Very_fast) { /* speed boots or potion */
109 /* average movement is 1.67 times normal */
110 moveamt += NORMAL_SPEED / 2;
111 if (rn2(3) == 0) moveamt += NORMAL_SPEED / 2;
113 /* average movement is 1.33 times normal */
114 if (rn2(3) != 0) moveamt += NORMAL_SPEED / 2;
119 case UNENCUMBERED: break;
120 case SLT_ENCUMBER: moveamt -= (moveamt / 4); break;
121 case MOD_ENCUMBER: moveamt -= (moveamt / 2); break;
122 case HVY_ENCUMBER: moveamt -= ((moveamt * 3) / 4); break;
123 case EXT_ENCUMBER: moveamt -= ((moveamt * 7) / 8); break;
127 youmonst.movement += moveamt;
128 if (youmonst.movement < 0) youmonst.movement = 0;
134 /********************************/
135 /* once-per-turn things go here */
136 /********************************/
138 if (flags.bypasses) clear_bypasses();
143 if (u.ublesscnt) u.ublesscnt--;
144 if(flags.time && !flags.run)
147 /* One possible result of prayer is healing. Whether or
148 * not you get healed depends on your current hit points.
149 * If you are allowed to regenerate during the prayer, the
150 * end-of-prayer calculation messes up on this.
151 * Another possible result is rehumanization, which requires
152 * that encumbrance and movement rate be recalculated.
154 if (u.uinvulnerable) {
155 /* for the moment at least, you're in tiptop shape */
156 wtcap = UNENCUMBERED;
157 } else if (Upolyd && youmonst.data->mlet == S_EEL && !is_pool(u.ux,u.uy) && !Is_waterlevel(&u.uz)) {
163 } else if (Upolyd && u.mh < u.mhmax) {
166 else if (Regeneration ||
167 (wtcap < MOD_ENCUMBER && !(moves%20))) {
171 } else if (u.uhp < u.uhpmax &&
172 (wtcap < MOD_ENCUMBER || !u.umoved || Regeneration)) {
173 if (u.ulevel > 9 && !(moves % 3)) {
174 int heal, Con = (int) ACURR(A_CON);
180 if (heal > u.ulevel-9) heal = u.ulevel-9;
186 } else if (Regeneration ||
188 !(moves % ((MAXULEV+12) / (u.ulevel+2) + 1)))) {
194 /* moving around while encumbered is hard work */
195 if (wtcap > MOD_ENCUMBER && u.umoved) {
196 if(!(wtcap < EXT_ENCUMBER ? moves%30 : moves%10)) {
197 if (Upolyd && u.mh > 1) {
199 } else if (!Upolyd && u.uhp > 1) {
202 You("pass out from exertion!");
203 exercise(A_CON, FALSE);
204 fall_asleep(-10, FALSE);
209 if ((u.uen < u.uenmax) &&
210 ((wtcap < MOD_ENCUMBER &&
211 (!(moves%((MAXULEV + 8 - u.ulevel) *
212 (Role_if(PM_WIZARD) ? 3 : 4) / 6))))
213 || Energy_regeneration)) {
214 u.uen += rn1((int)(ACURR(A_WIS) + ACURR(A_INT)) / 15 + 1,1);
215 if (u.uen > u.uenmax) u.uen = u.uenmax;
219 if(!u.uinvulnerable) {
220 if(Teleportation && !rn2(85)) {
221 xchar old_ux = u.ux, old_uy = u.uy;
223 if (u.ux != old_ux || u.uy != old_uy) {
225 check_leash(old_ux, old_uy);
228 /* clear doagain keystrokes */
234 /* delayed change may not be valid anymore */
235 if ((change == 1 && !Polymorph) ||
236 (change == 2 && u.ulycn == NON_PM))
238 if(Polymorph && !rn2(100))
240 else if (u.ulycn >= LOW_PM && !Upolyd &&
241 !rn2(80 - (20 * night())))
243 if (change && !Unchanging) {
249 if (change == 1) polyself(FALSE);
256 if(Searching && multi >= 0) (void) dosearch0(1);
263 if (u.uhave.amulet) amulet();
264 if (!rn2(40+(int)(ACURR(A_DEX)*3)))
266 if (u.uevent.udemigod && !u.uinvulnerable) {
267 if (u.udg_cnt) u.udg_cnt--;
270 u.udg_cnt = rn1(200, 50);
274 /* underwater and waterlevel vision are done here */
275 if (Is_waterlevel(&u.uz))
279 /* vision while buried done here */
280 else if (u.uburied) under_ground(0);
282 /* when immobile, count is in turns */
284 if (++multi == 0) { /* finished yet? */
286 /* if unmul caused a level change, take it now */
287 if (u.utotype) deferred_goto();
291 } while (youmonst.movement<NORMAL_SPEED); /* hero can't move loop */
293 /******************************************/
294 /* once-per-hero-took-time things go here */
295 /******************************************/
298 } /* actual time passed */
300 /****************************************/
301 /* once-per-player-input things go here */
302 /****************************************/
305 if(!flags.mv || Blind) {
306 /* redo monsters if hallu or wearing a helm of telepathy */
307 if (Hallucination) { /* update screen randomly */
311 if (u.uswallow) swallowed(0);
312 } else if (Unblind_telepat) {
314 } else if (Warning || Warn_of_mon)
317 if (vision_full_recalc) vision_recalc(0); /* vision! */
319 if(flags.botl || flags.botlx) bot();
323 if(multi >= 0 && occupation) {
324 #if defined(MICRO) || defined(WIN32)
327 if ((ch = Getchar()) == ABORT)
334 if (!abort_lev && (*occupation)() == 0)
336 if ((*occupation)() == 0)
340 #if defined(MICRO) || defined(WIN32)
347 #if defined(MICRO) || defined(WIN32)
348 if (!(++occtime % 7))
349 display_nhwindow(WIN_MAP, FALSE);
354 if ((u.uhave.amulet || Clairvoyant) &&
355 !In_endgame(&u.uz) && !BClairvoyant &&
356 !(moves % 15) && !rn2(2))
359 if(u.utrap && u.utraptype == TT_LAVA) {
360 if(!is_lava(u.ux,u.uy))
362 else if (!u.uinvulnerable) {
365 killer_format = KILLED_BY;
366 killer = "molten lava";
367 You("sink below the surface and die.");
369 } else if(didmove && !u.umoved) {
370 Norep("You sink deeper into the lava.");
377 if (iflags.sanity_check)
382 /* just before rhack */
383 cliparound(u.ux, u.uy);
391 /* lookaround may clear multi */
393 if (flags.time) flags.botl = 1;
397 if(multi < COLNO && !--multi)
398 flags.travel = iflags.travel1 = flags.mv = flags.run = 0;
404 } else if (multi == 0) {
410 if (u.utotype) /* change dungeon level */
411 deferred_goto(); /* after rhack() */
412 /* !flags.move here: multiple movement command stopped */
413 else if (flags.time && (!flags.move || !flags.mv))
416 if (vision_full_recalc) vision_recalc(0); /* vision! */
417 /* when running in non-tport mode, this gets done through domove() */
418 if ((!flags.run || iflags.runmode == RUN_TPORT) &&
419 (multi && (!flags.travel ? !(multi % 7) : !(moves % 7L)))) {
420 if (flags.time && flags.run) flags.botl = 1;
421 display_nhwindow(WIN_MAP, FALSE);
433 if (!maybe_finished_meal(TRUE))
434 You("stop %s.", occtxt);
436 flags.botl = 1; /* in case u.uhs changed */
437 /* fainting stops your occupation, there's no reason to sync.
451 display_gamewindows()
453 WIN_MESSAGE = create_nhwindow(NHW_MESSAGE);
454 WIN_STATUS = create_nhwindow(NHW_STATUS);
455 WIN_MAP = create_nhwindow(NHW_MAP);
456 WIN_INVEN = create_nhwindow(NHW_MENU);
460 * This _is_ the right place for this - maybe we will
461 * have to split display_gamewindows into create_gamewindows
462 * and show_gamewindows to get rid of this ifdef...
464 if ( ! strcmp ( windowprocs . name , "mac" ) ) {
470 * The mac port is not DEPENDENT on the order of these
471 * displays, but it looks a lot better this way...
473 display_nhwindow(WIN_STATUS, FALSE);
474 display_nhwindow(WIN_MESSAGE, FALSE);
475 clear_glyph_buffer();
476 display_nhwindow(WIN_MAP, FALSE);
490 for (i = 0; i < NUMMONS; i++)
491 mvitals[i].mvflags = mons[i].geno & G_NOCORPSE;
493 init_objects(); /* must be before u_init() */
495 flags.pantheon = -1; /* role_init() will reset this */
496 role_init(); /* must be before init_dungeons(), u_init(),
497 * and init_artifacts() */
499 init_dungeons(); /* must be before u_init() to avoid rndmonst()
500 * creating odd monsters for any tins and eggs
501 * in hero's initial inventory */
502 init_artifacts(); /* before u_init() in case $WIZKIT specifies
507 (void) signal(SIGINT, (SIG_RET_TYPE) done1);
510 if(iflags.news) display_file(NEWS, FALSE);
512 load_qtlist(); /* load up the quest text info */
513 /* quest_init();*/ /* Now part of role_init() */
517 vision_reset(); /* set up internals for level (after mklev) */
518 check_special_room(FALSE);
522 /* Move the monster from under you or else
523 * makedog() will fail when it calls makemon().
526 if(MON_AT(u.ux, u.uy)) mnexto(m_at(u.ux, u.uy));
538 program_state.something_worth_saving++; /* useful data now exists */
545 /* show "welcome [back] to nethack" message at program startup */
548 boolean new_game; /* false => restoring an old game */
551 boolean currentgend = Upolyd ? u.mfemale : flags.female;
554 * The "welcome back" message always describes your innate form
555 * even when polymorphed or wearing a helm of opposite alignment.
556 * Alignment is shown unconditionally for new games; for restores
557 * it's only shown if it has changed from its original value.
558 * Sex is shown for new games except when it is redundant; for
559 * restores it's only shown if different from its original value.
562 if (new_game || u.ualignbase[A_ORIGINAL] != u.ualignbase[A_CURRENT])
563 Sprintf(eos(buf), " %s", align_str(u.ualignbase[A_ORIGINAL]));
565 (new_game ? (urole.allow & ROLE_GENDMASK) == (ROLE_MALE|ROLE_FEMALE) :
566 currentgend != flags.initgend))
567 Sprintf(eos(buf), " %s", genders[currentgend].adj);
569 pline(new_game ? "%s %s, welcome to NetHack! You are a%s %s %s."
570 : "%s %s, the%s %s %s, welcome back to NetHack!",
571 Hello((struct monst *) 0), plname, buf, urace.adj,
572 (currentgend && urole.name.f) ? urole.name.f : urole.name.m);
579 static char pbar[COLNO];
585 (glyph_to_cmap(level.locations[upstair.sx][upstair.sy].glyph) ==
587 glyph_to_cmap(level.locations[upstair.sx][upstair.sy].glyph) ==
593 (glyph_to_cmap(level.locations[sstairs.sx][sstairs.sy].glyph) ==
595 glyph_to_cmap(level.locations[sstairs.sx][sstairs.sy].glyph) ==
603 (glyph_to_cmap(level.locations[dnstair.sx][dnstair.sy].glyph) ==
605 glyph_to_cmap(level.locations[dnstair.sx][dnstair.sy].glyph) ==
611 (glyph_to_cmap(level.locations[sstairs.sx][sstairs.sy].glyph) ==
613 glyph_to_cmap(level.locations[sstairs.sx][sstairs.sy].glyph) ==
627 update_positionbar(pbar);