Ejemplo n.º 1
0
/**
  Add a packdata element to the inverse wavelet packet transform
  calculation.

  A packdata element contains the wavelet packet data items from
  one level of the wavelet packet transform tree.

  The inverse wavelet packet transform calculation uses a stack.  Each
  level in the stack consists of a packcontainer_int object.  This object
  consists of left and right hand size arrays.  When both these arrays
  are present, they can be treated as one contiguous array (courtesy
  of C++ operator overloading).  The size of the packcontainer_int object
  is twice the size of its left and right hand size arrays.

  If the stack is empty, a new level is created.  A packetcontainer
  object can be viewed as a binary tree element.  The left hand
  size is filled in first.

  If the stack is not empty and the packcontainer_int object on the
  top of stack (TOS) is twice the size of the elem argument,
  then the array contained in the elem argument is added to
  the TOS element and reduce is called to calculate a step
  of the inverse wavelet transform.

  If the TOS element is greater than twice the size of elem
  then a new level is added.

 */
void invpacktree_int::add_elem( packdata<int> *elem )
{
  assert( elem != 0 );

  if (stack.first() == 0) {
    new_level( elem );
  }
  else {
    size_t half = elem->length();
    size_t n = half * 2;
    LIST<packcontainer_int *>::handle h;
    h = stack.first();
    packcontainer_int *tos = stack.get_item( h );

    if (tos->length() == n) {
      assert( tos->rhsData() == 0);
      tos->rhsData( (int *)elem->getData() );
      reduce();
    }
    else if (tos->length() > n) {
      new_level( elem );
    }
    else {
      printf("add_elem: the size of the TOS elem is wrong\n");
    }
  } // else
} // add_elem
Ejemplo n.º 2
0
void Dodger::password_screen()
{
    static bool first_call = true;
    if (first_call) {
        first_call = false;

        std::ostringstream main_msg;
        main_msg << "Password for level " << level_number + 1 << " is:";
        main_text.setString(main_msg.str());

        std::ostringstream pwd_msg;
        pwd_msg << passwords[level_number - 1];
        password_text.setString(pwd_msg.str());

        //center text
        sf::Vector2u dim = window.getSize();
        sf::FloatRect textRect = main_text.getLocalBounds();
        main_text.setOrigin(textRect.left + textRect.width/2.0f,
                       textRect.top  + textRect.height/2.0f);
        main_text.setPosition(sf::Vector2f(dim.x / 2.0, dim.y / 2.0 - 10));

        textRect = password_text.getLocalBounds();
        password_text.setOrigin(textRect.left + textRect.width/2.0f,
                textRect.top  + textRect.height/2.0f);
        password_text.setPosition(sf::Vector2f(dim.x / 2.0, dim.y / 2.0 + 10));
    }
    if (next_screen) {
        password_text.setString("");
        level_number++;
        new_level();
        game_state = playing;
        first_call = true;
    }
}
Ejemplo n.º 3
0
static void init_snake(void)
{
    num_apples_to_get=1;
    if(game_type == 1)
       level_from_file = 1;
    game_b_level=1;
    new_level(level_from_file);
}
Ejemplo n.º 4
0
Archivo: main.cpp Proyecto: daid/Rogue
/*
 * main:
 *        The main program, of course
 */
int main(int argc, char **argv)
{
    md_init();
    initJedi();

    /*
     * get home and options from environment
     */

#ifdef __linux__
    strcpy(file_name, "/var/lib/griffin/rogue.save");
#else
    strcpy(file_name, "rogue.save");
#endif

    open_score();

    /*
     * check for print-score option
     */

    if (argc == 2)
    {
        if (strcmp(argv[1], "-s") == 0)
        {
            score(0, -1, 0);
            exit(0);
        }
    }

    init_check();                        /* check for legal startup */
    restore("-r");

    init_probs();                        /* Set up prob tables for objects */
    init_player();                        /* Set up initial player stats */
    init_names();                        /* Set up names of scrolls */
    init_colors();                        /* Set up colors of potions */
    init_stones();                        /* Set up stone settings of rings */
    init_materials();                        /* Set up materials of wands */
    setup();

    displayMessage("WELCOME TO THE DUNGEONS OF DOOM");
    new_level();                        /* Draw current level */
    /*
     * Start up daemons and fuses
     */
    start_daemon(runners, 0, AFTER);
    start_daemon(doctor, 0, AFTER);
    fuse(swander, 0, WANDERTIME, AFTER);
    start_daemon(stomach, 0, AFTER);
    playit();
    return(0);
}
Ejemplo n.º 5
0
void Dodger::new_game()
{
    life_count = 3;
    level_number = 1;
    score = 0;

    score_panel.set_num_lives(life_count);
    score_panel.set_level(level_number);
    score_panel.set_score(score);

    new_level();
}
Ejemplo n.º 6
0
/*
** Check for collision. TODO: Currently this
** sets of the death sequence. What we want is it to only return a true/false
** depending on whether a collision occured.
*/
static void collision ( int x, int y )
{
    int bdeath=0;


    switch (board[x][y])
    {
        case 0:

        break;
        case -1:
            score = score + (1 * level);
            apple=0;
            applecountdown=2;
            applecount++;

            if(game_type==1)
            {
                if(num_apples_to_get == num_apples_to_got)
                {
                    level_from_file++;
                    if(level_from_file >= num_levels)
                    {
                        level_from_file = 1;
                        /*and increase the number of apples to pick up
                        before level changes*/
                        num_apples_to_get+=2;
                        game_b_level++;
                    }
                    rb->splash(HZ, "Level Completed!");
                    new_level(level_from_file);
                    redraw();
                    rb->lcd_update();
                }
                else
                    num_apples_to_got++;
            }
        break;
        default:
            bdeath=1;
            break;
    }

    if(bdeath==1)
    {
        die();
        sillydir = dir;
        frames = -110;
    }
}
Ejemplo n.º 7
0
Archivo: game.c Proyecto: orodley/ttc
static bool handle_event_won_level(Game *game, SDL_Event *event)
{
    if (event->type == SDL_KEYDOWN) {
        switch (event->key.keysym.sym) {
        case SDLK_RETURN:
            new_level(game);
            break;
        case SDLK_ESCAPE:
            return false;
        }
    }

    return true;
}
Ejemplo n.º 8
0
void
genocide(int flags)
{
    struct linked_list  *ip;
    struct thing    *mp;
    struct linked_list  *nip;
    int    which_monst;
    int    blessed = flags & ISBLESSED;
    int    cursed = flags & ISCURSED;

    while ((which_monst = get_monster_number("genocide")) == 0)
        ;

    if (cursed)    /* oops... */
    {
        new_level(THRONE, which_monst);
        msg("What's this I hear about you trying to wipe me out?");
        fighting = running = after = FALSE;
        return;
    }

    /* Remove this monster from the present level */

    for (ip = mlist; ip; ip = nip)
    {
        mp = THINGPTR(ip);
        nip = next(ip);

        if (mp->t_index == which_monst)
        {
            check_residue(mp);  /* Check for special features before removing */
            remove_monster(&mp->t_pos, ip);
        }
    }

    /* Remove from available monsters */

    monsters[which_monst].m_normal = FALSE;
    monsters[which_monst].m_wander = FALSE;
    mpos = 0;
    msg("You have wiped out the %s.", monsters[which_monst].m_name);

    if (blessed)
        genocide(ISNORMAL);
}
Ejemplo n.º 9
0
LEVEL* resize_level(LEVEL *data, int sizex, int sizey, int entitycnt) {
     int i,x,y;
     LEVEL* newl = new_level(sizex,sizey,entitycnt,data->bgtype);
     int oldx = data->sizex;
     int oldy = data->sizey;
     int ecpsize;
     for(x=0;x<sizex;x++){for(y=0;y<sizey;y++)
     {
          if (x < oldx && y < oldy)
          {
                newl->map[x+(y*sizex)] = data->map[x+(y*oldx)];
          } else {
                newl->map[x+(y*sizex)] = 0;
          }
     }}
     if (data->entitycnt > newl->entitycnt) ecpsize = newl->entitycnt; else ecpsize = data->entitycnt;
     memcpy(newl->entities,data->entities,ecpsize*sizeof(ENTITY));
     return newl;
}
Ejemplo n.º 10
0
Archivo: script.c Proyecto: EXio4/Lex4
void cmd_loadmap(char *fname) {
	new_game(0);
	new_level(fname, -2, 0);
}
Ejemplo n.º 11
0
int				main(int ac, char **av)
{
	// t_num		**list;
	t_num								*one;
	t_mask								*nmask;
	t_mask								**lmask;
	t_env								*e;
	int									*pl;
	register unsigned long int 			acc;
	register unsigned long int 	upper_lim;
	register unsigned long int 	lower_lim;
	// int			i;
	// printf("IN\n");
	// if (ac == 2)
	// 	if (!init_all(e, 100))
	// 		mlx_loop(e->mlx);
	acc = 1;
	pl = (int *)malloc(sizeof(int) * 6544);
	pl[0] = 1;

	{
		// i = 0;
		e = (t_env *)malloc(sizeof(t_env));

		e->loa = new_num_list(atoi(av[3]));
		maxtree = atoi(av[4]);
		fdout = open(av[5], O_CREAT|O_WRONLY|O_APPEND, 777);
		lenu64 = strlen(av[1]) + 2;
		one = (e->loa[1]);
		lmask = (t_mask **)malloc(sizeof(t_mask *) * 6544);
		nmask = (t_mask *)malloc(sizeof(t_mask ));
		nmask->n = one->n;
		nmask->prev = NULL;
		nmask->next = NULL;
		nmask->l = NULL;
		nmask->r = NULL;
		(*lmask) = nmask;
		int i = 1;
		while ((one = one->next))
		{
				pl[i] = one->n;
			i++;
			// printf("N: %d\n", nmask->n);
			nmask = new_mask(nmask, one->n);
		}
		pl[i] = 0;
		// (*lmask) = nmask->next;
		nmask = lmask[0];
		// while ((nmask = nmask->next))
		{
			// printf("N: %d\n", nmask->n);
		}
		// i = 0;
		// while (pl[i])
		// 	printf("%d\n", pl[i++]);
		// nmask = lmask[0]->next;
		nmask->n = 1;
		// printf("mask: %d\n", nmask->n);		
		// printf("mask2: %d\n", nmask->next->n);		
		// printf("mask3: %d\n", nmask->next->next->n);	
		{
			// pl += 9;
			// acc = 1938;
		}
		long int margin = atol(av[2]);
		unsigned long int target = atol(av[1]);
		lower_lim = (unsigned long int)(margin);
		upper_lim = (unsigned long int)(target);
		// lower_lim = (unsigned long int)(target - margin);
		// upper_lim = (unsigned long int)(target + margin);
		// unsigned long int lim


		// printf("Margin: %ld\n", margin);
		// printf("TARGET:%ld\n", target);
		// printf("GAP Range:%ld\n", upper_lim - lower_lim);
		// printf("Lower Limit:%ld\n", lower_lim);
		// printf("Upper Limit:%ld\n", upper_lim);
		// printf("Start %d\n", (int)getpid());
		// extern long int mingap;
		mingap = (long int *)malloc(sizeof(long int) * 1000);
		// mingap[0] = -1;
		new_level(pl, acc, upper_lim, lower_lim, 0);
		// curse_mask_tab(pl, acc, upper_lim, lower_lim);

		// curse_mask(nmask, acc);

		// printf("IN!\n");
		// one = (*list);
		// while (((*list) = (*list)->next) )//&& i < atoi(av[1]))
		// {
		// 	// printf("ZERO0: %lx\n", (long)(one));
		// 	// printf("ZERO0: %lx\n", (long)(one->next));
		// 	// if ((*list)->s->n == 0 || (*list)->s->n > 96)
		// 	{		
		// 		printf("%d\t", (int)((*list)->n));
		// 		printf("%d\n", (int)((*list)->m));
		// 		// printf("\t= \t%d   \t\t* ", (int)((*list)->l->n));
		// 		// printf("\t%d\n", (int)((*list)->s->n));
		// 	}
		// 	// printf("adr: \t\t%lx\n", (long)(*list));
		// 	i++;
		// }
		// free(list);
	}
	free(e);
	// int i = 0;
	// while (mingap[i])
	// 	printf("MinGap FINAL: %ld\n", mingap[i++]);
	return (0);
}
Ejemplo n.º 12
0
static void new_level(int *pl, unsigned long int acc, unsigned long int upper_lim, unsigned long int lower_lim, int bran)
{
	int f1, f2;

    if (*pl > maxtree)
    {
    	int f11;


	    // if (())
    	f11 = fork_ok();
	    {	
	    	// printf("F11: %d\tF21: %d\n", f11, f21);
	        if (!f11)
	        {
	        	// printf("Pri: %d\tAcc: %ld\n", *(pl +  1), acc);
				curse_mask_tab(pl + 1, acc, upper_lim, lower_lim);
				// exit(-1);
	        }
		    else
		    {
				// printf("Pri: %d\tAcc: %ld\n", *(pl +  1), acc * *(pl +  1));
   				curse_mask_tab(pl + 1, acc * *(pl + 1), upper_lim, lower_lim);
				// exit(-1);
		    }
	    }
	    // else
	    {
	        // printf("i am %d, my parent is %d\n",
	                // (int)getpid(), (int)getppid());
	        // while (wait(0) > 0)
	            // ;
	        // printf("Exit %d\n", (int)getpid());
	    }
	    return;
	    // exit(-1);


    	// if (!bran)
			// curse_mask_tab(pl + 1, acc, upper_lim, lower_lim);
		// else
			// curse_mask_tab(pl + 1, acc * *(pl + 1), upper_lim, lower_lim);
    }
    (f1 = fork_ok());
    {	
    	// printf("F1: %d\tF2: %d\n", f1, f2);
        if (!f1)
        {
        	// if (!bran)
		        // new_level(pl + 1, acc, upper_lim, lower_lim, !bran);
        	// else
	        	new_level(pl + 1, acc, upper_lim, lower_lim, 0);
	        // exit(0);
        }
	    else
	    {
	    	// if (!bran)
        		// new_level(pl + 1, acc * *(pl + 1), upper_lim, lower_lim, !bran);
        	// else
	        	new_level(pl + 1, acc * *(pl + 1), upper_lim, lower_lim, 0);
	    	// exit(0);
	    }
    }
    // else
    {
        // printf("i am %d, my parent is %d\n",
                // (int)getpid(), (int)getppid());
        while (wait(0) > 0)
            ;
        // printf("Exit %d\n", (int)getpid());
    }
    // exit(0);
}
Ejemplo n.º 13
0
int minesweeper_game::start_game()
{
    const int iCenterX = (TERMX > FULL_SCREEN_WIDTH) ? (TERMX - FULL_SCREEN_WIDTH) / 2 : 0;
    const int iCenterY = (TERMY > FULL_SCREEN_HEIGHT) ? (TERMY - FULL_SCREEN_HEIGHT) / 2 : 0;

    WINDOW *w_minesweeper_border = newwin(FULL_SCREEN_HEIGHT, FULL_SCREEN_WIDTH, iCenterY, iCenterX);
    WINDOW_PTR w_minesweeper_borderptr( w_minesweeper_border );

    WINDOW *w_minesweeper = newwin(FULL_SCREEN_HEIGHT - 2, FULL_SCREEN_WIDTH - 2, iCenterY + 1, iCenterX + 1);
    WINDOW_PTR w_minesweeperptr( w_minesweeper );

    draw_border(w_minesweeper_border);

    std::vector<std::string> shortcuts;
    shortcuts.push_back(_("<n>ew level"));
    shortcuts.push_back(_("<f>lag"));
    shortcuts.push_back(_("<q>uit"));

    int iWidth = 0;
    for( auto &shortcut : shortcuts ) {
        if ( iWidth > 0 ) {
            iWidth += 1;
        }
        iWidth += utf8_width(shortcut);
    }

    int iPos = FULL_SCREEN_WIDTH - iWidth - 1;
    for( auto &shortcut : shortcuts ) {
        shortcut_print(w_minesweeper_border, 0, iPos, c_white, c_ltgreen, shortcut);
        iPos += utf8_width(shortcut) + 1;
    }

    mvwputch(w_minesweeper_border, 0, 2, hilite(c_white), _("Minesweeper"));

    wrefresh(w_minesweeper_border);

    input_context ctxt("MINESWEEPER");
    ctxt.register_cardinal();
    ctxt.register_action("NEW");
    ctxt.register_action("FLAG");
    ctxt.register_action("CONFIRM");
    ctxt.register_action("QUIT");
    ctxt.register_action("HELP_KEYBINDINGS");

    static const std::array<int, 9> aColors = {{
        c_white,
        c_ltgray,
        c_cyan,
        c_blue,
        c_ltblue,
        c_green,
        c_magenta,
        c_red,
        c_yellow
    }};

    int iScore = 5;

    int iPlayerY = 0;
    int iPlayerX = 0;

    std::function<void (int, int)> rec_reveal = [&](const int y, const int x) {
        if ( mLevelReveal[y][x] == unknown || mLevelReveal[y][x] == flag ) {
            mLevelReveal[y][x] = seen;

            if ( mLevel[y][x] == 0 ) {
                const auto circle = closest_tripoints_first( 1, {x, y, 0} );

                for( const auto &p : circle ) {
                    if ( p.x >= 0 && p.x < iLevelX && p.y >= 0 && p.y < iLevelY ) {
                        if ( mLevelReveal[p.y][p.x] != seen ) {
                            rec_reveal(p.y, p.x);
                        }
                    }
                }

                mvwputch(w_minesweeper, iOffsetY + y, iOffsetX + x, c_black, " ");

            } else {
                mvwputch(w_minesweeper, iOffsetY + y, iOffsetX + x,
                         (x == iPlayerX && y == iPlayerY) ? hilite(aColors[mLevel[y][x]]) : aColors[mLevel[y][x]],
                         to_string(mLevel[y][x]));
            }
        }
    };

    int iDirY, iDirX;

    std::string action = "NEW";

    do {
        if (action == "NEW") {
            new_level(w_minesweeper);

            iPlayerY = 0;
            iPlayerX = 0;
        }

        wrefresh(w_minesweeper);

        if (check_win()) {
            popup_top(_("Congratulations, you won!"));

            iScore = 30;

            action = "QUIT";
        } else {
            action = ctxt.handle_input();
        }

        if (ctxt.get_direction(iDirX, iDirY, action)) {
            if ( iPlayerX + iDirX >= 0 && iPlayerX + iDirX < iLevelX && iPlayerY + iDirY >= 0 && iPlayerY + iDirY < iLevelY ) {

                std::string sGlyph;
                nc_color cColor;

                for ( int i=0; i < 2; i++ ) {
                    cColor = c_white;
                    if ( mLevelReveal[iPlayerY][iPlayerX] == flag ) {
                        sGlyph = "!";
                        cColor = c_yellow;
                    } else if ( mLevelReveal[iPlayerY][iPlayerX] == seen ) {
                        if ( mLevel[iPlayerY][iPlayerX] == 0 ) {
                            sGlyph = " ";
                            cColor = c_black;
                        } else {
                            sGlyph = to_string(mLevel[iPlayerY][iPlayerX]);
                            cColor = aColors[mLevel[iPlayerY][iPlayerX]];
                        }
                    } else {
                        sGlyph = '#';
                    }

                    mvwputch(w_minesweeper, iOffsetY + iPlayerY, iOffsetX + iPlayerX, (i == 0) ? cColor : hilite(cColor), sGlyph.c_str());

                    if ( i == 0 ) {
                        iPlayerX += iDirX;
                        iPlayerY += iDirY;
                    }
                }
            }
        } else if (action == "FLAG") {
            if ( mLevelReveal[iPlayerY][iPlayerX] == unknown ) {
                mLevelReveal[iPlayerY][iPlayerX] = flag;
                mvwputch(w_minesweeper, iOffsetY + iPlayerY, iOffsetX + iPlayerX, hilite(c_yellow), "!");

            } else if ( mLevelReveal[iPlayerY][iPlayerX] == flag ) {
                mLevelReveal[iPlayerY][iPlayerX] = unknown;
                mvwputch(w_minesweeper, iOffsetY + iPlayerY, iOffsetX + iPlayerX, hilite(c_white), "#");
            }
        } else if (action == "CONFIRM") {
            if ( mLevelReveal[iPlayerY][iPlayerX] != seen ) {
                if ( mLevel[iPlayerY][iPlayerX] == (int)bomb ) {
                    for ( int y = 0; y < iLevelY; y++ ) {
                        for ( int x = 0; x < iLevelX; x++ ) {
                            if (mLevel[y][x] == (int)bomb) {
                                mvwputch(w_minesweeper, iOffsetY + y, iOffsetX + x, hilite(c_red), (mLevelReveal[y][x] == flag) ? "!" : "*" );
                            }
                        }
                    }

                    wrefresh(w_minesweeper);

                    popup_top(_("Boom, you're dead! Better luck next time."));
                    action = "QUIT";

                } else if ( mLevelReveal[iPlayerY][iPlayerX] == unknown ) {
                    rec_reveal(iPlayerY, iPlayerX);
                }
            }
        }

    } while (action != "QUIT");

    return iScore;
}
Ejemplo n.º 14
0
/*
 * read_scroll:
 *	Let the hero read a scroll
 */
int read_scroll()
{
	struct object *obj;
	struct linked_list *item;
	int i, j, wh;
	unsigned long ch, nch;
	struct room *rp;
	struct linked_list *titem;
	char buf[LINLEN];
	bool bless, curse;

	if ((item = get_item("read", SCROLL)) == NULL)
		return 0;
	obj = OBJPTR(item);
	if (obj->o_type != SCROLL) {
		msg("Nothing to read.");
		after = FALSE;
		return 0;
	}
	msg("As you read the scroll, it vanishes.");
	wh = obj->o_which;
	bless = o_on(obj, ISBLESS);
	curse = o_on(obj, ISCURSED);
	del_pack(item);		/* Get rid of the thing */

	/*
	 * Calculate the effect it has on the hero
	 */
	switch(wh) {
	case S_KNOWALL:
		if (!curse) {
			idenpack();				/* identify all the pack */
			msg("You feel more knowledgable.");
			chg_abil(WIS,1,TRUE);
			s_know[S_KNOWALL] = TRUE;
		}
	when S_CONFUSE:
		if (!curse) {
			/*
			 * Scroll of monster confusion.  Give him that power.
			 */
			msg("Your hands begin to glow red.");
			player.t_flags |= CANHUH;
			s_know[S_CONFUSE] = TRUE;
		}
	when S_LIGHT:
		rp = player.t_room;
		if (!curse) {
			if (rp == NULL) {
				s_know[S_LIGHT] = TRUE;
				msg("The corridor glows and then fades.");
			}
			else {
				if (rf_on(rp,ISDARK)) {
					s_know[S_LIGHT] = TRUE;
					msg("The room is lit.");
					rp->r_flags &= ~ISDARK;
				}
				light(&hero);
				mvwaddch(cw, hero.y, hero.x, PLAYER);
			}
		}
	when S_ARMOR:
		if (!curse) {
			if (cur_armor != NULL && o_off(cur_armor,ISPROT)) {
				s_know[S_ARMOR] = TRUE;
				msg("Your armor glows faintly for a moment.");
				if (o_on(cur_armor,ISCURSED))
					cur_armor->o_ac = armors[cur_armor->o_which].a_class;
				else
					cur_armor->o_ac--;
				resoflg(cur_armor,ISCURSED);
			}
		}
	when S_HOLD:
		if (!curse) {
			/*
			 * Hold monster scroll.  Stop all monsters within 3 spaces
			 * from chasing after the hero.
			 */
			int x,y;
			struct linked_list *mon;

			for (x = hero.x - 3; x <= hero.x + 3; x++) {
				for (y = hero.y - 3; y <= hero.y + 3; y++) {
					if (y > 0 && x > 0 && isalpha(mvwinch(mw, y, x))) {
						if ((mon = find_mons(y, x)) != NULL) {
							struct thing *th;

							th = THINGPTR(mon);
							th->t_flags &= ~ISRUN;
							th->t_flags |= ISHELD;
							th->t_flags |= ISSTUCK;
						}
					}
				}
			}
		}
	when S_SLEEP:
		/*
		 * Scroll which makes you fall asleep
		 */
		if (!bless) {
			s_know[S_SLEEP] = TRUE;
			msg("You fall asleep.");
			player.t_nocmd += 4 + rnd(SLEEPTIME);
		}
	when S_CREATE:
		if (!bless) {
			if (makemons(mtlev[rnd(levcount)]->m_show))
				s_know[S_CREATE] = TRUE;
			else
				msg("You hear a faint cry of anguish in the distance.");
		}
	when S_IDENT:
		if (!curse) {
			msg("This scroll is an identify scroll");
			s_know[S_IDENT] = TRUE;
			whatis(NULL);
		}
	when S_MAP:
		if (curse)
			break;
		s_know[S_MAP] = TRUE;
		addmsg("Oh, now this scroll has a ");
		if (rnd(100) < 10 || bless) {
			addmsg("very detailed map on it.");
			endmsg();
			displevl();
		}
		else {
			addmsg("map on it.");
			endmsg();
			overwrite(stdscr, hw);
			for (i = 1; i < LINES - 2; i++) {
				for (j = 0; j < COLS; j++) {
					switch (nch = ch = mvwinch(hw, i, j)) {
						case SECRETDOOR:
							nch = DOOR;
							mvaddch(i, j, nch);
						case '-':
						case '|':
						case DOOR:
						case PASSAGE:
						case ' ':
						case STAIRS:
							if (mvwinch(mw, i, j) != ' ') {
								struct thing *it;
								struct linked_list *blah;

								blah = find_mons(i, j);
								if (blah != NULL) {
									it = THINGPTR(blah);
									if (it->t_oldch == ' ')
										it->t_oldch = nch;
								}
							}
							break;
						default:
							nch = ' ';
					}
					if (nch != ch)
						waddch(hw, nch);
				}
			}
			overlay(cw, hw);
			overwrite(hw, cw);
		}
	when S_GFIND:
		if (!curse) {
			int gtotal = 0;
			struct room *rp;

			wclear(hw);
			for (rp = rooms; rp < &rooms[MAXROOMS]; rp++) {
				gtotal += rp->r_goldval;
				if (rp->r_goldval != 0 &&
				  mvinch(rp->r_gold.y,rp->r_gold.x) == GOLD)
					mvwaddch(hw,rp->r_gold.y,rp->r_gold.x,GOLD);
			}
			if (gtotal) {
				s_know[S_GFIND] = TRUE;
				msg("You begin to feel greedy and sense gold.");
				overlay(hw,cw);
			}
			else
				msg("You begin to feel a pull downward.");
		}
	when S_TELEP:
		if (!curse) {
			int rm;
			struct room *cur_room;

			cur_room = player.t_room;
			rm = teleport(rndspot, &player);
			if (cur_room != &rooms[rm])
				s_know[S_TELEP] = TRUE;
		}
	when S_ENCH:
		if (!curse) {
			if (cur_weapon == NULL || (cur_weapon != NULL &&
			  (o_on(cur_weapon,ISPROT) || cur_weapon->o_type != WEAPON)))
				msg("You feel a strange sense of loss.");
			else {
				s_know[S_ENCH] = TRUE;
				if (o_on(cur_weapon,ISCURSED)) {
					resoflg(cur_weapon,ISCURSED);
					cur_weapon->o_hplus = rnd(2);
					cur_weapon->o_dplus = rnd(2);
				}
				else {		/* weapon was not cursed here */
					if (rnd(100) < 50)
						cur_weapon->o_hplus += 1;
					else
						cur_weapon->o_dplus += 1;
				}
				setoflg(cur_weapon, ISKNOW);
				msg("Your %s glows blue for a moment.",
				  w_magic[cur_weapon->o_which].mi_name);
			}
		}
	when S_SCARE:
		/*
		 * A monster will refuse to step on a scare monster scroll
		 * if it is dropped.  Thus reading it is a mistake and produces
		 * laughter at the poor rogue's boo boo.
		 */
		msg("You hear maniacal laughter in the distance.");
	when S_REMOVE:
		if (!curse) {
			if (cur_armor != NULL && o_off(cur_armor,ISPROT))
				resoflg(cur_armor,ISCURSED);
			if (cur_weapon != NULL && o_off(cur_weapon,ISPROT))
				resoflg(cur_weapon,ISCURSED);
			if (cur_ring[LEFT]!=NULL && o_off(cur_ring[LEFT],ISPROT))
				resoflg(cur_ring[LEFT],ISCURSED);
			if (cur_ring[RIGHT]!=NULL && o_off(cur_ring[RIGHT],ISPROT))
				resoflg(cur_ring[RIGHT],ISCURSED);
			msg("You feel as if somebody is watching over you.");
			s_know[S_REMOVE] = TRUE;
		}
	when S_AGGR:
		if (!bless) {
			if (mlist != NULL) {
				aggravate();
				msg("You hear a high pitched humming noise.");
				s_know[S_AGGR] = TRUE;
			}
		}
	when S_NOP:
		msg("This scroll seems to be blank.");
	when S_GENOCIDE:
		if (!curse) {
			msg("You have been granted the boon of genocide.");
			genocide();
			s_know[S_GENOCIDE] = TRUE;
		}
	when S_DCURSE:
		if (!bless) {
			struct linked_list *ll;
			struct object *lb;

			msg("Your pack shudders.");
			for (ll = pack ; ll != NULL ; ll = next(ll)) {
				lb = OBJPTR(ll);
				if (o_off(lb,ISPROT)) {
					resoflg(lb, ISBLESS);
					setoflg(lb, ISCURSED);
				}
			}
		}
	when S_DLEVEL:
		if (!bless) {
			int much = rnd(9) - 4;

			if (much != 0) {
				level += much;
				if (level < 1)
					level = 1;
				mpos = 0;
				new_level(NORMLEV);		/* change levels */
				msg("You are whisked away to another region.");
				s_know[S_DLEVEL] = TRUE;
			}
		}
	when S_PROTECT:
		if (!curse) {
			struct linked_list *ll;
			struct object *lb;

			msg("You are granted the power of protection.");
			if ((ll = get_item("protect",0)) != NULL) {
				lb = OBJPTR(ll);
				setoflg(lb,ISPROT);
				mpos = 0;
				msg("Protected %s.",inv_name(lb,TRUE));
			}
			s_know[S_PROTECT] = TRUE;
		}
	when S_ALLENCH:
		if (!curse) {
			struct linked_list *ll;
			struct object *lb;
			int howmuch, ac, good;

			msg("You are granted the power of enchantment.");
			good = TRUE;
			if ((ll = get_item("enchant",0)) != NULL) {
				lb = OBJPTR(ll);
				resoflg(lb,ISCURSED);
				resoflg(lb,ISPROT);
				howmuch = rnd(3) + 1;
				switch(lb->o_type) {
					case RING:
						if (lb->o_ac < 0)
							lb->o_ac = 0;
						lb->o_ac += howmuch;
					when ARMOR:
						ac = armors[lb->o_which].a_class;
						if (lb->o_ac > ac)
							lb->o_ac = ac;
						lb->o_ac -= howmuch;
					when STICK:
						lb->o_charges += howmuch + 10;
					when WEAPON:
						if (lb->o_dplus < 0)
							lb->o_dplus = 0;
						if (lb->o_hplus < 0)
							lb->o_hplus = 0;
						lb->o_hplus += howmuch;
						lb->o_dplus += howmuch;
					otherwise:
						msg("You are injured as the scroll flashes & bursts into flames !!!");
						chg_hpt(-roll(6,6),FALSE,K_SCROLL);
						good = FALSE;
				}
				if (good) {
					mpos = 0;
					msg("Enchanted %s.",inv_name(lb,TRUE));
				}
			}
			s_know[S_ALLENCH] = TRUE;
		}
	when S_BLESS:
		if (!curse) {
			struct linked_list *ll;
			struct object *lb;

			msg("Your pack glistens brightly.");
			for (ll = pack ; ll != NULL ; ll = next(ll)) {
				whatis(ll);
				lb = OBJPTR(ll);
				resoflg(lb,ISCURSED);
				setoflg(lb,ISBLESS);
			}
		}
	when S_MAKEIT:
		if (!curse) {
			msg("You have been endowed with the power of creation.");
			s_know[S_MAKEIT] = TRUE;
			create_obj(TRUE);
		}
	when S_BAN: {
		int howdeep;
		char *ptr;

		if (bless) {
			if (level > 6) {
				howdeep = 1 + rnd(5);
				ptr = "elevated to the upper";
			}
			else {
				howdeep = -1;
				bless = FALSE;
			}
		}
		else {
			howdeep = level + 10 + rnd(20) + (curse * 20);
			ptr = "banished to the lower";
		}
		if ((!bless && level < howdeep) || bless) {
			level = howdeep;
			new_level(NORMLEV);
			mpos = 0;
			msg("You are %s regions.", ptr);
			s_know[S_BAN] = TRUE;
		}
	}
	when S_CWAND:
		if (!curse) {
			struct linked_list *ll;
			struct object *lb;
			bool wands = FALSE;

			for (ll = pack ; ll != NULL ; ll = next(ll)) {
				lb = OBJPTR(ll);
				if (lb->o_type == STICK) {
					whatis(ll);
					setoflg(lb, ISKNOW);
					resoflg(lb, ISCURSED);
					lb->o_charges += rnd(11) + 5;
					wands = TRUE;
				}
			}
			if (wands) {
				msg("Your sticks gleam.");
				s_know[wh] = TRUE;
			}
		}
	when S_LOCTRAP: {
		struct trap *trp;

		if (ntraps > 0) {
			for (trp = &traps[0]; trp < &traps[ntraps]; trp++)
				trp->tr_flags |= ISFOUND;
			look(FALSE);
			msg("You now recognize pitfalls.");
			s_know[S_LOCTRAP] = TRUE;
		}
	}
	otherwise:
		msg("What a puzzling scroll!");
		return 0;
	}
Ejemplo n.º 15
0
/*
 * main:
 *	The main program, of course
 */
int
main(int argc, char **argv)
{
    char *env;
    time_t lowtime;

    md_init();

#ifdef MASTER
    /*
     * Check to see if he is a wizard
     */
    if (argc >= 2 && argv[1][0] == '\0')
	if (strcmp(PASSWD, md_crypt(md_getpass("wizard's password: "******"mT")) == 0)
	{
	    wizard = TRUE;
	    player.t_flags |= SEEMONST;
	    argv++;
	    argc--;
	}

#endif

    /*
     * get home and options from environment
     */

    strcpy(home, md_gethomedir());

	if (strlen(home) > MAXSTR - strlen("rogue.save") - 1)
		*home = 0;

    strcpy(file_name, home);
    strcat(file_name, "rogue.save");

    if ((env = getenv("ROGUEOPTS")) != NULL)
	parse_opts(env);
    if (env == NULL || whoami[0] == '\0')
        strucpy(whoami, md_getusername(), strlen(md_getusername()));
    lowtime = time(NULL);
    if (getenv("SEED") != NULL)
    {
	dnum = atoi(getenv("SEED"));
	noscore = 1;
    }
    else
	dnum = (unsigned int) lowtime + md_getpid();
    seed = dnum;

    open_score();

	/* 
     * Drop setuid/setgid after opening the scoreboard file. 
     */ 

    md_normaluser();

    /*
     * check for print-score option
     */

	md_normaluser(); /* we drop any setgid/setuid priveldges here */

    if (argc == 2)
    {
	if (strcmp(argv[1], "-s") == 0)
	{
	    noscore = TRUE;
	    score(0, -1, 0);
	    exit(0);
	}
	else if (strcmp(argv[1], "-d") == 0)
	{
	    dnum = rnd(100);	/* throw away some rnd()s to break patterns */
	    while (--dnum)
		rnd(100);
	    purse = rnd(100) + 1;
	    level = rnd(100) + 1;
	    initscr();
	    getltchars();
	    death(death_monst());
	    exit(0);
	}
    }

    init_check();			/* check for legal startup */
    if (argc == 2)
	if (!restore(argv[1]))	/* Note: restore will never return */
	    my_exit(1);
#ifdef MASTER
    if (wizard)
	printf("Hello %s, welcome to dungeon #%d", whoami, dnum);
    else
#endif
	printf("Hello %s, just a moment while I dig the dungeon...", whoami);
    fflush(stdout);

    initscr();				/* Start up cursor package */
    init_probs();			/* Set up prob tables for objects */
    init_player();			/* Set up initial player stats */
    init_names();			/* Set up names of scrolls */
    init_colors();			/* Set up colors of potions */
    init_stones();			/* Set up stone settings of rings */
    init_materials();			/* Set up materials of wands */
    setup();

    /*
     * The screen must be at least NUMLINES x NUMCOLS
     */
    if (LINES < NUMLINES || COLS < NUMCOLS)
    {
	printf("\nSorry, the screen must be at least %dx%d\n", NUMLINES, NUMCOLS);
	endwin();
	my_exit(1);
    }

    /*
     * Set up windows
     */
    hw = newwin(LINES, COLS, 0, 0);
    idlok(stdscr, TRUE);
    idlok(hw, TRUE);
#ifdef MASTER
    noscore = wizard;
#endif
    new_level();			/* Draw current level */
    /*
     * Start up daemons and fuses
     */
    start_daemon(runners, 0, AFTER);
    start_daemon(doctor, 0, AFTER);
    fuse(swander, 0, WANDERTIME, AFTER);
    start_daemon(stomach, 0, AFTER);
    playit();
    return(0);
}