Esempio n. 1
0
/* returns 1 if save successful */
int
dosave0(boolean emergency)
{
    int fd;
    struct memfile mf;
    boolean log_disabled = iflags.disable_log;

    mnew(&mf, NULL);

    fd = logfile;

    /* when we leave via nh_exit, logging is disabled. It needs to be enabled
       briefly so that log_finish will update the log header. */
    iflags.disable_log = FALSE;
    log_finish(LS_SAVED);
    iflags.disable_log = log_disabled;
    vision_recalc(2);   /* shut down vision to prevent problems in the event of 
                           an impossible() call */

    savegame(&mf);
    store_mf(fd, &mf);  /* also frees mf */

    freedynamicdata();

    return TRUE;
}
Esempio n. 2
0
/*
 *	subroutine to save the game if a hangup signal
 */
static void
sgam(void)
{
	savegame(savefilename);
	wizard = 1;
	died(-257);		/* hangup signal */
}
Esempio n. 3
0
void Script::o_savegame() {
	uint16 varnum = readScript8or16bits();
	uint8 slot = _variables[varnum];

	debugScript(1, true, "SAVEGAME var[0x%04X] -> slot=%d (TODO)", varnum, slot);

	savegame(slot);
}
Esempio n. 4
0
/* Subroutine to save the game if a hangup signal */
static void sgam()
{
    savegame(savefilename);
    wizard = 1;

    /* Hangup signal */
    died(-257);
}
Esempio n. 5
0
void op_save4(void)
{
  if(!savegame()) {
    mop_store_result(0);
  } else {
    mop_store_result(1);
  }
}
Esempio n. 6
0
void op_save1(void)
{
  if(!savegame()) {
    mop_skip_branch();
  } else {
    mop_take_branch();
  }
}
Esempio n. 7
0
/**
 * @brief Skips the menus and starts the game immediately.
 *
 * This function can be called during the title screen or the selection menu to skip them
 * and start the game immediately with a savegame (for debugging purposes).
 *
 * @param savegame_file name of the savegame file to load
 */
void Solarus::skip_menus(const std::string& savegame_file) {

  if (FileTools::data_file_exists(savegame_file)) {

    Savegame savegame(savegame_file);
    Game* game = new Game(*this, savegame);
    delete current_screen;
    current_screen = game;
  }
}
Esempio n. 8
0
/*
 *	routine to process a fatal error signal
 */
static void
sigpanic(int sig)
{
	char buf[128];
	signal(sig, SIG_DFL);
	sprintf(buf, "\nLarn - Panic! Signal %d received [%s]", sig, signame[sig]);
	write(2, buf, strlen(buf));
	sleep(2);
	sncbr();
	savegame(savefilename);
	kill(getpid(), sig);	/* this will terminate us */
}
Esempio n. 9
0
int play() {

   short c;
   short ret;
   short testmove();
   short undolock = 1;         /* locked for undo */

#if ATARIST			/* Mess up keyboard to make cursor keys work */
KEY_TABLES *kbt;
KEY_TABLES old_kbt;
int i;

	kbt = Keytbl(-1, -1, -1);
	old_kbt = *kbt;

	for (i = 0; i < 128; i++) {
		unshifted[i] = kbt->unshifted[i];
		shifted[i] = kbt->shifted[i];
	}

	unshifted[0x48] = 'k';	/* Up */
	unshifted[0x50] = 'j';	/* Down */
	unshifted[0x4b] = 'h';	/* Left */
	unshifted[0x4d] = 'l';	/* Right */
	unshifted[0x61] = 'u';	/* Undo */
	unshifted[0x62] = '?';	/* Help */

	shifted[0x48] = '\013';	/* Up ^K */
	shifted[0x50] = '\012';	/* Down ^J */
	shifted[0x4b] = '\010';	/* Left ^H */
	shifted[0x4d] = '\014';	/* Right ^L */
	shifted[0x61] = 'q';	/* Undo */

	Keytbl(unshifted, shifted, -1);
#endif

   showscreen();
   tmpsave();
   ret = 0;
   while( ret == 0) {
      switch( (c = get_char())) {
        case 'q':    /* quit the game                                  */
				ret = E_ENDGAME;
				break;
        case 's':    /* save the games                                 */
                     if( (ret = savegame()) == 0)
                        ret = E_SAVED;
                     break;
        case '?':    /* show the help file                             */
                     showhelp();
                     showscreen();
                     break;
        case CNTL_R: /* refresh the screen                             */
                     clear();
                     showscreen();
                     break;
        case 'c':    /* temporary save                                 */
                     tmpsave();
                     break;
        case CNTL_U: /* reset to temporary save                        */
                     tmpreset();
                     undolock = 1;
                     showscreen();
                     break;
        case 'U':    /* undo this level                                */
                     moves = pushes = 0;
                     if( (ret = readscreen()) == 0) {
                        showscreen();
                        undolock = 1;
                     }
                     break;
        case 'u':    /* undo last move                                 */
                     if(state_num > 0) {
                        undomove();
                        undolock = 0;	/*1*/
                     }
                     break;
        case 'k':    /* up                                             */
        case 'K':    /* run up                                         */
        case CNTL_K: /* run up, stop before object                     */
        case 'j':    /* down                                           */
        case 'J':    /* run down                                       */
        case CNTL_J: /* run down, stop before object                   */
        case 'l':    /* right                                          */
        case 'L':    /* run right                                      */
        case CNTL_L: /* run right, stop before object                  */
        case 'h':    /* left                                           */
        case 'H':    /* run left                                       */
        case CNTL_H: /* run left, stop before object                   */
                     do {
                        if( (action = testmove( c)) != 0) {
						soko_state *s;
							s = &state[state_num];

                        	s->action = action;
							s->ppos = ppos;
                        	s->lppc = map[ppos.x][ppos.y];
							s->tpos1 = tpos1;
                        	s->ltp1c = map[tpos1.x][tpos1.y];
							s->tpos2 = tpos2;
                        	s->ltp2c = map[tpos2.x][tpos2.y];
                           domove( s->action);
                           undolock = 0;
						   state_num++;
                        }
                     } while( (action != 0) && (! islower( c))
                             && (packets != savepack));
                     break;
        default:     helpmessage(); break;
      }
      if( (ret == 0) && (packets == savepack)) {
        scorelevel = level;
        scoremoves = moves;
        scorepushes = pushes;
        break;
      }
   }
#if ATARIST
	kbt = Keytbl(-1, -1, -1);
	kbt->unshifted = old_kbt.unshifted;
	kbt->shifted = old_kbt.shifted;
/*	Keytbl(old_kbt.unshifted, old_kbt.shifted, old_kbt.capslock);*/
#endif
	return ret;
}
Esempio n. 10
0
void DreamGenContext::checkcoords(const RectWithCallback *rectWithCallbacks) {
	if (data.byte(kNewlocation) != 0xff)
		return;

	const RectWithCallback *rectWithCallback = rectWithCallbacks;
	while (rectWithCallback->xMin() != 0xffff) {
		if (rectWithCallback->contains(data.word(kMousex), data.word(kMousey))) {
			uint16 callback = rectWithCallback->callback();

			// common
			if(callback == addr_blank)
				blank();
			else if(callback == addr_getbackfromob)
				getbackfromob();
			else if(callback == addr_incryanpage)
				incryanpage();
			else if(callback == addr_getback1)
				getback1();
			else if(callback == addr_quitkey)
				quitkey();
			else if(callback == addr_dosreturn)
				dosreturn();
			else if(callback == addr_getbacktoops)
				getbacktoops();
			else if(callback == addr_selectslot)
				selectslot();
			// examlist
			else if(callback == addr_useobject)
				useobject();
			else if(callback == addr_selectopenob)
				selectopenob();
			else if(callback == addr_setpickup)
				setpickup();
			else if(callback == addr_examinventory)
				examinventory();
			// invlist1
			else if(callback == addr_dropobject)
				dropobject();
			else if(callback == addr_useopened)
				useopened();
			else if(callback == addr_setpickup)
				setpickup();
			else if(callback == addr_intoinv)
				intoinv();
			// withlist1
			else if(callback == addr_selectob)
				selectob();
			// talklist
			else if(callback == addr_moretalk)
				moretalk();
			// quitlist
			// destlist
			else if(callback == addr_nextdest)
				nextdest();
			else if(callback == addr_lastdest)
				lastdest();
			else if(callback == addr_lookatplace)
				lookatplace();
			else if(callback == addr_destselect)
				destselect();
			// keypadlist
			else if(callback == addr_buttonone)
				buttonone();
			else if(callback == addr_buttontwo)
				buttontwo();
			else if(callback == addr_buttonthree)
				buttonthree();
			else if(callback == addr_buttonfour)
				buttonfour();
			else if(callback == addr_buttonfive)
				buttonfive();
			else if(callback == addr_buttonsix)
				buttonsix();
			else if(callback == addr_buttonseven)
				buttonseven();
			else if(callback == addr_buttoneight)
				buttoneight();
			else if(callback == addr_buttonnine)
				buttonnine();
			else if(callback == addr_buttonnought)
				buttonnought();
			else if(callback == addr_buttonenter)
				buttonenter();
			// menulist
			// folderlist
			else if(callback == addr_nextfolder)
				nextfolder();
			else if(callback == addr_lastfolder)
				lastfolder();
			// symbollist
			else if(callback == addr_quitsymbol)
				quitsymbol();
			else if(callback == addr_settopleft)
				settopleft();
			else if(callback == addr_settopright)
				settopright();
			else if(callback == addr_setbotleft)
				setbotleft();
			else if(callback == addr_setbotright)
				setbotright();
			// diarylist
			else if(callback == addr_diarykeyn)
				diarykeyn();
			else if(callback == addr_diarykeyp)
				diarykeyp();
			else if(callback == addr_quitkey)
				quitkey();
			// opslist
			else if(callback == addr_getbackfromops)
				getbackfromops();
			else if(callback == addr_discops)
				discops();
			// discopslist
			else if(callback == addr_loadgame)
				loadgame();
			else if(callback == addr_savegame)
				savegame();
			// mainlist, mainlist2
			else if(callback == addr_look)
				look();
			else if(callback == addr_inventory)
				inventory();
			else if(callback == addr_zoomonoff)
				zoomonoff();
			else if(callback == addr_saveload)
				saveload();
			else if(callback == addr_madmanrun)
				madmanrun();
			else if(callback == addr_identifyob)
				identifyob();
			// decidelist
			else if(callback == addr_newgame)
				newgame();
			else if(callback == addr_loadold)
				loadold();
			// loadlist
			else if(callback == addr_actualload)
				actualload();
			// savelist
			else if(callback == addr_actualsave)
				actualsave();
			else {
				debug("__dispatch_call remaining in checkcoords! %d", (int)callback);
				__dispatch_call(callback);
			}
			return;
		}
		++rectWithCallback;
	}
}
Esempio n. 11
0
void input_update() {
	SDL_Event event;

	while(SDL_PollEvent(&event)) {
		if(r_menu) {
			switch(event.type) {
				case SDL_QUIT: Game::run=false; break;

				case SDL_KEYDOWN:
					switch(event.key.keysym.sym) {
						case SDLK_w:	if(menu_choice) --menu_choice; else menu_choice=6;		break;

						case SDLK_s:	if(menu_choice<6) ++menu_choice; else menu_choice=0;	break;

						case SDLK_e:
							switch(menu_choice) {
                                                                case 1:
                                                                        r_menu=false;
                                                                        r_pokemenu=true;
                                                                        menu_text = "Select a pokemon.";
                                                                        info_dialog(menu_text);
								        soundevents.push_back(new Sound(soundbuffers[0]));
							        	soundevents.back()->play();
                                                                        break;
								case 4:
									savegame();
									soundevents.push_back(new Sound(soundbuffers[0]));
									soundevents.back()->play();
									r_menu=false;
								break;
								case 6: Game::run=false; break;
							}
						break;

						case SDLK_SPACE:	r_menu=false;		break;
						default:break;
					}
			}
		}
                else if(r_pokemenu)
                {
			switch(event.type) {
				case SDL_QUIT: Game::run=false; break;

				case SDL_KEYDOWN:
					switch(event.key.keysym.sym) {
						case SDLK_w:	if(poke_choice) --poke_choice; else poke_choice=5;		break;

						case SDLK_s:	if(poke_choice<5) ++poke_choice; else poke_choice=0;	break;

						case SDLK_e:
							switch(menu_choice) {
                                                          // POKEMON NOT IMPLEMENTED YET!
                                                          default:
                                                                  break;
							}
						break;

						case SDLK_SPACE:
                                                        r_pokemenu=false;
                                                        r_menu = true;
                                                        menu_text = "";
                                                        info_dialog(menu_text);
                                                        break;
						default:break;
					}
			}
                }
		else {
			switch(event.type) {
				case SDL_QUIT: Game::run=false; break;

				case SDL_KEYDOWN:
					switch(event.key.keysym.sym) {
						case SDLK_a:		if(!player.talking) player.start(4);	break;

						case SDLK_w:		if(!player.talking) player.start(8);	break;

						case SDLK_s:		if(!player.talking) player.start(16);	break;

						case SDLK_d:		if(!player.talking) player.start(2);	break;

						case SDLK_e:		KEY_E_DOWN=true;	break;

						case SDLK_SPACE:
							if(!player.talking) {
								player.stop();
								r_menu=true;
								soundevents.push_back(new Sound(soundbuffers[0]));
								soundevents.back()->play();
							}
						break;
						default: break;
					}
				break;

				case SDL_KEYUP:
					switch(event.key.keysym.sym) {
						case SDLK_a:		if(player.direction()==4) player.stop();	break;

						case SDLK_w:		if(player.direction()==8) player.stop();	break;

						case SDLK_s:		if(player.direction()==16) player.stop();	break;

						case SDLK_d:		if(player.direction()==2) player.stop();	break;

						case SDLK_e:		KEY_E_DOWN=false;							break;
						default: break;
					}
				break;
			}
		}
	}
}
Esempio n. 12
0
/*
	parse()

	get and execute a command
 */
static void
parse(void)
{
	int    i, j, k, flag;
	while (1) {
		k = yylex();
		switch (k) {	/* get the token from the input and switch on
				 * it	 */
		case 'h':
			moveplayer(4);
			return;	/* west		 */
		case 'H':
			run(4);
			return;	/* west		 */
		case 'l':
			moveplayer(2);
			return;	/* east		 */
		case 'L':
			run(2);
			return;	/* east		 */
		case 'j':
			moveplayer(1);
			return;	/* south		 */
		case 'J':
			run(1);
			return;	/* south		 */
		case 'k':
			moveplayer(3);
			return;	/* north		 */
		case 'K':
			run(3);
			return;	/* north		 */
		case 'u':
			moveplayer(5);
			return;	/* northeast	 */
		case 'U':
			run(5);
			return;	/* northeast	 */
		case 'y':
			moveplayer(6);
			return;	/* northwest	 */
		case 'Y':
			run(6);
			return;	/* northwest	 */
		case 'n':
			moveplayer(7);
			return;	/* southeast	 */
		case 'N':
			run(7);
			return;	/* southeast	 */
		case 'b':
			moveplayer(8);
			return;	/* southwest	 */
		case 'B':
			run(8);
			return;	/* southwest	 */

		case '.':
			if (yrepcount)
				viewflag = 1;
			return;	/* stay here		 */

		case 'w':
			yrepcount = 0;
			wield();
			return;	/* wield a weapon */

		case 'W':
			yrepcount = 0;
			wear();
			return;	/* wear armor	 */

		case 'r':
			yrepcount = 0;
			if (c[BLINDCOUNT]) {
				cursors();
				lprcat("\nYou can't read anything when you're blind!");
			} else if (c[TIMESTOP] == 0)
				readscr();
			return;	/* to read a scroll	 */

		case 'q':
			yrepcount = 0;
			if (c[TIMESTOP] == 0)
				quaff();
			return;	/* quaff a potion		 */

		case 'd':
			yrepcount = 0;
			if (c[TIMESTOP] == 0)
				dropobj();
			return;	/* to drop an object	 */

		case 'c':
			yrepcount = 0;
			cast();
			return;	/* cast a spell	 */

		case 'i':
			yrepcount = 0;
			nomove = 1;
			showstr();
			return;	/* status		 */

		case 'e':
			yrepcount = 0;
			if (c[TIMESTOP] == 0)
				eatcookie();
			return;	/* to eat a fortune cookie */

		case 'D':
			yrepcount = 0;
			seemagic(0);
			nomove = 1;
			return;	/* list spells and scrolls */

		case '?':
			yrepcount = 0;
			help();
			nomove = 1;
			return;	/* give the help screen */

		case 'S':
			clear();
			lprcat("Saving . . .");
			lflush();
			savegame(savefilename);
			wizard = 1;
			died(-257);	/* save the game - doesn't return	 */

		case 'Z':
			yrepcount = 0;
			if (c[LEVEL] > 9) {
				oteleport(1);
				return;
			}
			cursors();
			lprcat("\nAs yet, you don't have enough experience to use teleportation");
			return;	/* teleport yourself	 */

		case '^':	/* identify traps */
			flag = yrepcount = 0;
			cursors();
			lprc('\n');
			for (j = playery - 1; j < playery + 2; j++) {
				if (j < 0)
					j = 0;
				if (j >= MAXY)
					break;
				for (i = playerx - 1; i < playerx + 2; i++) {
					if (i < 0)
						i = 0;
					if (i >= MAXX)
						break;
					switch (item[i][j]) {
					case OTRAPDOOR:
					case ODARTRAP:
					case OTRAPARROW:
					case OTELEPORTER:
						lprcat("\nIt's ");
						lprcat(objectname[item[i][j]]);
						flag++;
					};
				}
			}
			if (flag == 0)
				lprcat("\nNo traps are visible");
			return;

#if WIZID
		case '_':	/* this is the fudge player password for
				 * wizard mode */
			yrepcount = 0;
			cursors();
			nomove = 1;
			if (userid != wisid) {
				lprcat("Sorry, you are not empowered to be a wizard.\n");
				scbr();	/* system("stty -echo cbreak"); */
				lflush();
				return;
			}
			if (getpassword() == 0) {
				scbr();	/* system("stty -echo cbreak"); */
				return;
			}
			wizard = 1;
			scbr();	/* system("stty -echo cbreak"); */
			for (i = 0; i < 6; i++)
				c[i] = 70;
			iven[0] = iven[1] = 0;
			take(OPROTRING, 50);
			take(OLANCE, 25);
			c[WIELD] = 1;
			c[LANCEDEATH] = 1;
			c[WEAR] = c[SHIELD] = -1;
			raiseexperience(6000000L);
			c[AWARENESS] += 25000;
			{
				int    i, j;
				for (i = 0; i < MAXY; i++)
					for (j = 0; j < MAXX; j++)
						know[j][i] = 1;
				for (i = 0; i < SPNUM; i++)
					spelknow[i] = 1;
				for (i = 0; i < MAXSCROLL; i++)
					scrollname[i] = scrollhide[i];
				for (i = 0; i < MAXPOTION; i++)
					potionname[i] = potionhide[i];
			}
			for (i = 0; i < MAXSCROLL; i++)
				if (strlen(scrollname[i]) > 2) {	/* no null items */
					item[i][0] = OSCROLL;
					iarg[i][0] = i;
				}
			for (i = MAXX - 1; i > MAXX - 1 - MAXPOTION; i--)
				if (strlen(potionname[i - MAXX + MAXPOTION]) > 2) {	/* no null items */
					item[i][0] = OPOTION;
					iarg[i][0] = i - MAXX + MAXPOTION;
				}
			for (i = 1; i < MAXY; i++) {
				item[0][i] = i;
				iarg[0][i] = 0;
			}
			for (i = MAXY; i < MAXY + MAXX; i++) {
				item[i - MAXY][MAXY - 1] = i;
				iarg[i - MAXY][MAXY - 1] = 0;
			}
			for (i = MAXX + MAXY; i < MAXX + MAXY + MAXY; i++) {
				item[MAXX - 1][i - MAXX - MAXY] = i;
				iarg[MAXX - 1][i - MAXX - MAXY] = 0;
			}
			c[GOLD] += 25000;
			drawscreen();
			return;
#endif

		case 'T':
			yrepcount = 0;
			cursors();
			if (c[SHIELD] != -1) {
				c[SHIELD] = -1;
				lprcat("\nYour shield is off");
				bottomline();
			} else if (c[WEAR] != -1) {
				c[WEAR] = -1;
				lprcat("\nYour armor is off");
				bottomline();
			} else
				lprcat("\nYou aren't wearing anything");
			return;

		case 'g':
			cursors();
			lprintf("\nThe stuff you are carrying presently weighs %ld pounds", (long) packweight());
		case ' ':
			yrepcount = 0;
			nomove = 1;
			return;

		case 'v':
			yrepcount = 0;
			cursors();
			lprintf("\nCaverns of Larn, Version %ld.%ld, Diff=%ld",
				(long) VERSION, (long) SUBVERSION,
				(long) c[HARDGAME]);
			if (wizard)
				lprcat(" Wizard");
			nomove = 1;
			if (cheat)
				lprcat(" Cheater");
			lprcat(copyright);
			return;

		case 'Q':
			yrepcount = 0;
			quit();
			nomove = 1;
			return;	/* quit		 */

		case 'L' - 64:
			yrepcount = 0;
			drawscreen();
			nomove = 1;
			return;	/* look		 */

#if WIZID
#ifdef EXTRA
		case 'A':
			yrepcount = 0;
			nomove = 1;
			if (wizard) {
				diag();
				return;
			}	/* create diagnostic file */
			return;
#endif
#endif
		case 'P':
			cursors();
			if (outstanding_taxes > 0)
				lprintf("\nYou presently owe %ld gp in taxes.",
					(long) outstanding_taxes);
			else
				lprcat("\nYou do not owe any taxes.");
			return;
		};
	}
}
Esempio n. 13
0
Common::Error ToltecsEngine::saveGameState(int slot, const Common::String &description) {
	const char *fileName = getSavegameFilename(slot);
	savegame(fileName, description.c_str());
	return Common::kNoError;
}
Esempio n. 14
0
// play games with selected opponent
static void
gamesloop (CBengine * engine, gameinfo * gi)
{
	char command[64] = "";
	char reply[1024] = "";
	int board[8][8];		// XXX how about other sizes ?
	int maxtime;			// engines time for a move
	int move, from, to;
	int value, color;
	int playnow = 0, info = 0, moreinfo = 0;
	char str[1024];
	CBmove cbmove;

	// gametype
	if (gi->gametype != ENGLISH && gi->gametype != ITALIAN
		&& gi->gametype != MAFIERZ && gi->gametype != RUSSIAN)
	{
		printf ("Gametype unknown, leaving.");
		strcpy (gi->opponent, "part");
		return;
	}

	// user colour
	gi->view = readview ();
	if (gi->view == PART)
	{
		strcpy (gi->opponent, "part");
		return;
	}
	if (gi->view == QUIT)
	{
		strcpy (gi->opponent, "quit");
		return;
	}
	assert (gi->view == BLACK || gi->view == WHITE);

	// engine maxtime
	maxtime = readmaxtime (gi->opponent);
	if (maxtime == PART)
	{
		strcpy (gi->opponent, "part");
		return;
	}
	if (maxtime == QUIT)
	{
		strcpy (gi->opponent, "quit");
		return;
	}
	assert (maxtime > 0);

	// initialize/reset board
	newboard_8x8 (gi, board);
	gi->nummoves = 0;
	gi->result = UNKNOWN;

	// engine moves first ?
	if ((gi->view == WHITE && gi->gametype == ENGLISH)
		|| (gi->view == BLACK
		&& (gi->gametype == ITALIAN || gi->gametype == MAFIERZ
		|| gi->gametype == RUSSIAN)))
	{
		color = gi->view ^ CC;
		printboard_icds (gi, color, board);
		printboard_8x8 (gi, color, board);
		/*
		value =
			DL_CALL_FCT (engine->getmove,
			(board, color, (double) maxtime, str, &playnow, info,
			moreinfo, &cbmove));
			*/
		value = (engine->getmove)(board, color, (double) maxtime, str, &playnow, info,moreinfo, &cbmove);
		docbmove (gi, board, cbmove);
		printf ("\n%s\n", str);
	}
	color = gi->view;
	printboard_icds (gi, color, board);
	printboard_8x8 (gi, color, board);

	// start movesloop
	do
	{
		// player moves
		move = readmove (&from, &to, command);
		switch (move)
		{
		case JUMP:
		case CLICHE_MOVE:
			// is it valid ?
			/*
			value =
				DL_CALL_FCT (engine->islegal, (board, color, from, to, &cbmove));
				*/
			value = (engine->islegal)(board, color, from, to, &cbmove);
			if (!value)
			{
				printf ("\nInvalid move, try again.\n");
				printboard_icds (gi, color, board);
				printboard_8x8 (gi, color, board);
				continue;
			}
			docbmove (gi, board, cbmove);
			color = color ^ CC;
			printboard_icds (gi, color, board);
			printboard_8x8 (gi, color, board);
			break;
		case BAD:
			//value = DL_CALL_FCT (engine->command, (command, reply));
			value = (engine->command)(command, reply);
			if (value)
				printf ("%s\n", reply);
			else
				printf ("\nMalformed move, try again.\n");
			continue;
		case SAVE:
			printf ("%s\n", fenpos (gi, board, color));
			savegame (gi);
			continue;
		case NEW:
			strcpy (command, "new");
			continue;
		case PART:
			strcpy (gi->opponent, "part");
			return;
		case QUIT:
			strcpy (gi->opponent, "quit");
			return;
		default:
			printf ("\nOops, this shouldn't happen.\n");
			continue;
		}
		// engine moves
		/*
		value = DL_CALL_FCT (engine->getmove, (board, color, (double) maxtime,
			str, &playnow, info, moreinfo,
			&cbmove));
			*/
		(engine->getmove)(board, color, (double) maxtime, str, &playnow, info, moreinfo, &cbmove);
		docbmove (gi, board, cbmove);
		printf ("\n%s\n", str);
		color = color ^ CC;
		printboard_icds (gi, color, board);
		printboard_8x8 (gi, color, board);
		if (value == DRAW)
			printf ("\nGame ends with a draw.\n");
		if (value == WIN)
			printf ("\nGame ends, you loose.\n");
		if (value == LOSS)
			printf ("\nGame ends, you win.\n");
	}
	while (strcmp (command, "new"));
}
Esempio n. 15
0
File: main.cpp Progetto: r-lyeh/eve
int main( int argc, const char **argv ) {
    eve::init( argc, argv );

    // getopt api
    eve::getopt invokation( argc, argv );

    // smart asserts
    EVE_ASSERT( 1 < 2 );

    // string api
    EVE_ASSERT( eve::string( "hello world \1 \2", 1, 2 ) == "hello world 1 2" );

    // encryption api
    eve::string encrypted = eve::encrypt( "hello world", "my-password" );
    eve::string decrypted = eve::decrypt( encrypted, "my-password" );
    EVE_ASSERT( decrypted == "hello world" );

    // pixel/image api
    eve::pixel rgba = eve::rgba(1,1,1,1);
    eve::pixel hsla = eve::hsla(1,1,1,1);
    eve::image img;

    // todoby api
    EVE_TODOBY( "Sep 26 2015" );
    EVE_TODOBY( "May 19 2014" );
    EVE_TODOBY( "Aug 11 2011" );

    // ini api
    eve::ini ini;
    ini.load( "[test]\nnumber=123\nstring=hello world;this is a comment" );
    EVE_ASSERT( ini["test.number"] == "123" );
    EVE_ASSERT( ini["test.string"] == "hello world" );
    ini["added.number"] = "456";
    std::cout << ini.save() << std::endl;

    // serialization
    savegame game { 10, "level#01" };
    std::string json = eve::to_json( game );
    game = savegame();
    eve::from_json( game, json );
    EVE_ASSERT( game.level == 10 );
    EVE_ASSERT( game.name == "level#01" );

    // entity/component/system based
    eve::entity player = 1;

    // debug api
    std::cout << eve::is_debug() << std::endl;
    std::cout << eve::is_release() << std::endl;
    //std::cout << eve::is_master() << std::endl;

    if( !eve::is_asserting() ) {
        std::cout << "Asserts are disabled. No assertions will be perfomed" << std::endl;
    } else {
        std::cout << "Asserts are enabled. Assertions will be perfomed" << std::endl;
    }

    // print current stack trace
    for( auto &line : eve::stacktrace("\1) \2") ) {
        std::cout << line << std::endl;
    }

    // add a web server, with stats in ajax
    eve::http_create( 8080, "/", []( const eve::http_request &req, std::ostream &headers, std::ostream &content ) {
        headers << eve::http_mime(".html"); 
        content << req.url;
        return 200;
    } );
    std::cout << "webservers installed in localhost:8080 (/)" << std::endl;

    // initialize chain of warns and fails
    // these prototypes return !=0 if they handle issue, or return 0 to delegate issue to inner ring
    eve::warns.push_back( []( const std::string &text ) {
        eve::alert( text, "this is our custom assert title" );
        return true;
    });

    eve::fails.push_back( []( const std::string &error ) {
        eve::errorbox( error + "\n\n" + eve::stackstring("\1) \2\n", 7) );
        // die();
        return true;
    });

    eve::alert( "this is a test" );
    eve::warn("this is a warning");
    eve::fail("this is a fail");

    eve::alert( 3.14159f );
    eve::alert( std::ifstream(__FILE__), "current source code" );
    eve::alert( eve::hexdump("hello world") );
    eve::alert( eve::prompt("type a number") );

    // console api
    eve::console( "Welcome to " EVE_VERSION_FULL, "eve>", {
        {   "args", [&]( const eve::strings &args ) {
                std::cout << invokation.str() << std::endl;
        } },
        {   "print", [&]( const eve::strings &args ) {
            for( auto &it : args ) std::cout << it << ','; std::cout << std::endl;
        } },
        {   "println", [&]( const eve::strings &args ) {
            for( auto &it : args ) std::cout << "\t" << it << std::endl;
        } },
        {   "globals", [&]( const eve::strings &args ) {
            for( auto &g : eve::globals ) std::cout << g.first << "=" << g.second << std::endl;
        } },
        {   "exit", [&](const eve::strings &args ) {
            std::exit(1);
        } },
        {   "vars", [&](const eve::strings &args ) {
            // live vars can be tweaked during runtime
            std::cout << "int a=" << EVE_LIVE( 4321 ) << std::endl;
            std::cout << "hello=" << EVE_LIVE( "hello world" ) << std::endl;
        } }
    } );

    /*
    ./~> console
    eve>
    eve>k=100+230
    eve>k
    330
    eve>println(k,100)
            330
            100
    eve>println(k*300,100)
            k*300
            100
    eve>^C

    */

    for(;;) {
    }

}
void IOManager::update(InputManager *IManager, Cursor* cursor, Player* player, int &game_state, float dt)
{
	if(IManager->push_button(DIK_S))
	{
		int temp = 0;
		if(!IManager->check_button_down(DIK_S))
		{
			IManager->set_button(DIK_S, true);
			++iterator;

		}
	}else{
		IManager->set_button(DIK_S, false);
	}

	if(IManager->push_button(DIK_BACKSPACE))
	{
		if(!IManager->check_button_down(DIK_BACKSPACE))
		{
			IManager->set_button(DIK_BACKSPACE, true);
			game_state = MENU;
		}
	}else
		IManager->set_button(DIK_BACKSPACE, false);

	if(IManager->push_button(DIK_RSHIFT))
	{
		if(!IManager->check_button_down(DIK_RSHIFT))
		{
			IManager->set_button(DIK_RSHIFT, true);
			game_state = MENU;
		}
	}else
		IManager->set_button(DIK_RSHIFT, false);
	if(IManager->push_button(DIK_7)){
		if(!IManager->check_button_down(DIK_7)){
			IManager->set_button(DIK_7, true);
			m_gameSave[2][0] = 1;
			m_gameSave[2][2] = 14;
		}
	}else
		IManager->set_button(DIK_7, false);

	for(auto &buttons: saveloadButtons)
	{
		if(buttons.isOn(cursor->cursorPos.x, cursor->cursorPos.y, 3))
		{

			buttons.setColor(D3DCOLOR_ARGB(255,255,255,0));
			buttons.setHighlight(true);
		}
		else
		{
			buttons.setColor(D3DCOLOR_ARGB(255,255,255,255));
			buttons.setHighlight(false);
		}

	}

	///////////////////////////////////////////////
	//  INFO:  Save / Load game controls
	int selection = -1;
	if(IManager->check_mouse_button(LEFT_MOUSE_BUTTON)){
		//for(auto &buttons:  saveloadButtons){
		for(int i = 0; i < SAVEMENUBUTTONCOUNT; ++i){
			if(saveloadButtons[i].isOn(cursor->cursorPos.x, cursor->cursorPos.y, 3)){
				selection = i;
				break;
			}
		}
	}
	switch(selection){
	case -1:  // Did not select a button
		break;
	case 0:  //  Save 1
		//break;
	case 1:  //  Save 2
		//break;
	case 2:  //  Save 3
		if(game_state == LOAD){
			loadgame(selection, player, 0);
			game_state = OVERWORLD;
		}
		else if (game_state == SAVE)
			savegame(selection, player, 0);
		break;
	case 3: //  Main Menu Button
		game_state = MENU;
		break;
	};
}
EditorLevelsetSelectMenu::EditorLevelsetSelectMenu() :
  m_contrib_worlds()
{
  Editor::current()->deactivate_request = true;
  // Generating contrib levels list by making use of Level Subset
  std::vector<std::string> level_worlds;

  std::unique_ptr<char*, decltype(&PHYSFS_freeList)>
    files(PHYSFS_enumerateFiles("levels"),
          PHYSFS_freeList);
  for(const char* const* filename = files.get(); *filename != 0; ++filename)
  {
    std::string filepath = FileSystem::join("levels", *filename);
    PHYSFS_Stat statbuf;
    PHYSFS_stat(filepath.c_str(), &statbuf);
    if(statbuf.filetype == PHYSFS_FILETYPE_DIRECTORY)
    {
      level_worlds.push_back(filepath);
    }
  }

  add_label(_("Choose level subset"));
  add_hl();

  int i = 0;
  for (std::vector<std::string>::const_iterator it = level_worlds.begin(); it != level_worlds.end(); ++it)
  {
    try
    {
      std::unique_ptr<World> world = World::load(*it);

      if (!world->hide_from_contribs())
      {
        Savegame savegame(world->get_savegame_filename());
        savegame.load();

        if (world->is_levelset())
        {
          int level_count = 0;

          const auto& state = savegame.get_levelset_state(world->get_basedir());
          for(const auto& level_state : state.level_states)
          {
            if(level_state.filename == "")
              continue;
            level_count += 1;
          }

          std::ostringstream title;
          title << "[" << world->get_title() << "]";
          if (level_count == 0)
          {
            title << " " << _("*NEW*");
          }
          else
          {
            title << " (" << level_count << " " << _("levels") << ")";
          }
          add_entry(i++, title.str());
          m_contrib_worlds.push_back(std::move(world));
        }
        else if (world->is_worldmap())
        {
          int level_count = 0;

          const auto& state = savegame.get_worldmap_state(world->get_worldmap_filename());
          for(const auto& level_state : state.level_states)
          {
            if(level_state.filename == "")
              continue;
            level_count += 1;
          }

          std::ostringstream title;
          title << world->get_title();
          if (level_count == 0)
          {
            title << " " << _("*NEW*");
          }
          else
          {
            title << " (" << level_count << " " << _("levels") << ")";
          }
          add_entry(i++, title.str());
          m_contrib_worlds.push_back(std::move(world));
        }
        else
        {
          log_warning << "unknown World type" << std::endl;
        }
      }
    }
    catch(std::exception& e)
    {
      log_info << "Couldn't parse levelset info for '" << *it << "': " << e.what() << std::endl;
    }
  }

  add_hl();
  add_submenu(_("New level subset"), MenuStorage::EDITOR_NEW_LEVELSET_MENU);
  add_back(_("Back"),-2);
}
Esempio n. 18
0
File: main.c Progetto: HunterZ/larn
/*
 * parse()
 *
 * get and execute a command
 */
static void parse(void)
{
	int i, j, k, flag;

    while   (1)
        {
        k = yylex();
        switch(k)   /*  get the token from the input and switch on it   */
            {
            case 'h':   moveplayer(4);  return;     /*  west        */
            case 'H':   run(4);         return;     /*  west        */
            case 'l':   moveplayer(2);  return;     /*  east        */
            case 'L':   run(2);         return;     /*  east        */
            case 'j':   moveplayer(1);  return;     /*  south       */
            case 'J':   run(1);         return;     /*  south       */
            case 'k':   moveplayer(3);  return;     /*  north       */
            case 'K':   run(3);         return;     /*  north       */
            case 'u':   moveplayer(5);  return;     /*  northeast   */
            case 'U':   run(5);         return;     /*  northeast   */
            case 'y':   moveplayer(6);  return;     /*  northwest   */
            case 'Y':   run(6);         return;     /*  northwest   */
            case 'n':   moveplayer(7);  return;     /*  southeast   */
            case 'N':   run(7);         return;     /*  southeast   */
            case 'b':   moveplayer(8);  return;     /*  southwest   */
            case 'B':   run(8);         return;     /*  southwest   */

            case '.':                               /*  stay here       */
                if (yrepcount) 
                    viewflag=1;
                return;

            case 'c':
                yrepcount=0;
                cast();
                return;     /*  cast a spell    */

            case 'd':
                yrepcount=0;
                if (c[TIMESTOP]==0)
                    dropobj();
                return; /*  to drop an object   */

            case 'e':
                yrepcount=0;
                if (c[TIMESTOP]==0)
                    if (!floor_consume( OCOOKIE, "eat" ))
                        consume( OCOOKIE, "eat", showeat );
                return; /*  to eat a fortune cookie */

            case 'g':   
                yrepcount = 0 ;
                cursors();
                lprintf("\nThe stuff you are carrying presently weighs %d pounds",(long)packweight());
                break ;

            case 'i':       /* inventory */
                yrepcount=0;
                nomove=1;
                showstr(FALSE);
                return;

            case 'p':           /* pray at an altar */
                yrepcount = 0;
                    pray_at_altar();
                return;

            case 'q':           /* quaff a potion */
                yrepcount=0;
                if (c[TIMESTOP]==0)
                    if (!floor_consume( OPOTION, "quaff"))
                        consume( OPOTION, "quaff", showquaff );
                return;

            case 'r':
                yrepcount=0;
                if (c[BLINDCOUNT])
                    {
                    cursors();
                    lprcat("\nYou can't read anything when you're blind!");
                    }
                else if (c[TIMESTOP]==0)
                    if (!floor_consume( OSCROLL, "read" ))
                        if (!floor_consume( OBOOK, "read" ))
                            consume( OSCROLL, "read", showread );
                return;     /*  to read a scroll    */

            case 's':
                yrepcount = 0 ;
                    sit_on_throne();
                return ;

            case 't':                       /* Tidy up at fountain */
                yrepcount = 0 ;
                    wash_fountain() ;
                return ;

            case 'v':
                yrepcount=0;
                nomove = 1;
                cursors();
                lprintf("\nLarn, Version %d.%d.%d, Diff=%d",(long)VERSION,(long)SUBVERSION,(long)PATCHLEVEL,(long)c[HARDGAME]);
                if (wizard)
                    lprcat(" Wizard");
                if (cheat) 
                    lprcat(" Cheater");
                return;

            case 'w':                       /*  wield a weapon */
                yrepcount=0;
                wield();
                return;

            case 'A':
                yrepcount = 0;
                    desecrate_altar();
                return;

            case 'C':                       /* Close something */
                yrepcount = 0 ;
                    close_something();
                return;

            case 'D':                       /* Drink at fountain */
                yrepcount = 0 ;
                    drink_fountain() ;
                return ;

            case 'E':               /* Enter a building */
                yrepcount = 0 ;
                    enter() ;
                break ;

            case 'I':              /*  list spells and scrolls */
                yrepcount=0;
                seemagic(0);
                nomove=1;
                return;

            case 'O':               /* Open something */
                yrepcount = 0 ;
                    open_something();
                return;

            case 'P':
                cursors();
                yrepcount = 0;
                nomove = 1;
                if (outstanding_taxes>0)
                    lprintf("\nYou presently owe %d gp in taxes.",(long)outstanding_taxes);
                else
                    lprcat("\nYou do not owe any taxes.");
                return;

            case 'Q':    /*  quit        */
                yrepcount=0;
                quit();
                nomove=1;
                return;

            case 'R' :          /* remove gems from a throne */
                yrepcount = 0 ;
                    remove_gems( );
                return ;

            case 'S':
                /* And do the save.
                 */
                cursors();
                lprintf("\nSaving to `%s' . . . ", savefilename);
                lflush();
                save_mode = 1;
                savegame(savefilename);
                clear();
                lflush();
                wizard=1;
                died(-257); /* doesn't return */
                break;


            case 'T':   yrepcount=0;    cursors();  if (c[SHIELD] != -1) { c[SHIELD] = -1; lprcat("\nYour shield is off"); bottomline(); } else
                                        if (c[WEAR] != -1) { c[WEAR] = -1; lprcat("\nYour armor is off"); bottomline(); }
                        else lprcat("\nYou aren't wearing anything");
                        return;

            case 'W':
                yrepcount=0;
                wear();
                return; /*  wear armor  */

            case 'Z':
                yrepcount=0;
                if (c[LEVEL]>9) 
                    { 
                    oteleport(1);
                    return; 
                    }
                cursors(); 
                lprcat("\nAs yet, you don't have enough experience to use teleportation");
                return; /*  teleport yourself   */

            case ' ':   yrepcount=0;    nomove=1;  return;

            case 'L'-64:  yrepcount=0;  drawscreen();  nomove=1; return;    /*  look        */

#if WIZID
#ifdef EXTRA
            case 'A'-64:    yrepcount=0;    nomove=1; if (wizard) { diag(); return; }  /*   create diagnostic file */
                        return;
#endif
#endif
	    
	    case '<':                       /* Go up stairs or vol shaft */
                yrepcount = 0;
                    up_stairs();
                return ;

            case '>':                       /* Go down stairs or vol shaft*/
                yrepcount = 0 ;
                    down_stairs();
                return ;

            case '?':                       /* give the help screen */
                yrepcount=0;
                help();
                nomove=1;
                return; 

        case ',':                       /* pick up an item */
            yrepcount = 0 ;
            /* pickup, don't identify or prompt for action */
            lookforobject( FALSE, TRUE, FALSE );
        return;

            case ':':                       /* look at object */
                yrepcount = 0 ;
            /* identify, don't pick up or prompt for action */
                    lookforobject( TRUE, FALSE, FALSE );
                nomove = 1;  /* assumes look takes no time */
                return;

        case '/':        /* identify object/monster */
            specify_object();
            nomove = 1 ;
            yrepcount = 0 ;
            return;

        case '^':                       /* identify traps */
                flag = yrepcount = 0;
                cursors();
                lprc('\n');
                for (j=playery-1; j<playery+2; j++)
                    {
                    if (j < 0)
                        j=0;
                    if (j >= MAXY)
                        break;
                    for (i=playerx-1; i<playerx+2; i++)
                        {
                        if (i < 0) 
                            i=0;
                        if (i >= MAXX) 
                            break;
                        switch(item[i][j])
                            {
                            case OTRAPDOOR:     case ODARTRAP:
                            case OTRAPARROW:    case OTELEPORTER:
                            case OPIT:
                                lprcat("\nIts ");
                                lprcat(objectname[item[i][j]]);
                                flag++;
                            };
                        }
                    }
                if (flag==0) 
                    lprcat("\nNo traps are visible");
                return;

#if WIZID
            case '_':   /*  this is the fudge player password for wizard mode*/
                        yrepcount=0;    cursors(); nomove=1;

                        if (getpassword()==0)
                            {
                            scbr(); /* system("stty -echo cbreak"); */ return;
                            }
                        wizard=1;  scbr(); /* system("stty -echo cbreak"); */
                        for (i=0; i<6; i++)  c[i]=70;  iven[0]=iven[1]=0;
                        take(OPROTRING,50);   take(OLANCE,25);  c[WIELD]=1;
                        c[LANCEDEATH]=1;   c[WEAR] = c[SHIELD] = -1;
                        raiseexperience(6000000L);  c[AWARENESS] += 25000;
                        {
                        int i,j;
                        for (i=0; i<MAXY; i++)
                            for (j=0; j<MAXX; j++)  know[j][i]=KNOWALL;
                        for (i=0; i<SPNUM; i++) spelknow[i]=1;
                        for (i=0; i<MAXSCROLL; i++)  scrollname[i][0]=' ';
                        for (i=0; i<MAXPOTION; i++)  potionname[i][0]=' ';
                        }
                        for (i=0; i<MAXSCROLL; i++)
                          if (strlen(scrollname[i])>2) /* no null items */
                            { item[i][0]=OSCROLL; iarg[i][0]=i; }
                        for (i=MAXX-1; i>MAXX-1-MAXPOTION; i--)
                          if (strlen(potionname[i-MAXX+MAXPOTION])>2) /* no null items */
                            { item[i][0]=OPOTION; iarg[i][0]=i-MAXX+MAXPOTION; }
                        for (i=1; i<MAXY; i++)
                            { item[0][i]=i; iarg[0][i]=0; }
                        for (i=MAXY; i<MAXY+MAXX; i++)
                            { item[i-MAXY][MAXY-1]=i; iarg[i-MAXY][MAXY-1]=0; }
            for (i=MAXX+MAXY; i<MAXOBJECT; i++)
                {
                item[MAXX-1][i-MAXX-MAXY]=i;
                iarg[MAXX-1][i-MAXX-MAXY]=0;
                }
                        c[GOLD]+=250000;    drawscreen();   return;
#endif

            };
        }
}
Esempio n. 19
0
short play() {

   short c;
   short ret;
   short undolock = 1;		/* locked for undo */

   showscreen();
   tmpsave();
   ret = 0;
   while( ret == 0) {
      	switch( (c = getch())) {
	 	case 'q':    /* quit the game 					*/
	              ret = E_ENDGAME; 
	              break;
	 	case 's':    /* save the games					*/
		      if( (ret = savegame()) == 0)
			 ret = E_SAVED;
		      break;
	 	case '?':    /* show the help file				*/
		      showhelp();
		      showscreen();
		      break;
	 	case CNTL_R: /* refresh the screen 				*/
		      clear();
		      showscreen();
		      break;
	 	case 'c':    /* temporary save					*/
		      tmpsave();
		      break;
	 	case CNTL_U: /* reset to temporary save 			*/
		      tmpreset();
		      undolock = 1;
		      showscreen();
		      break;
	 	case 'U':    /* undo this level 				*/
		      moves = pushes = 0;
		      if( (ret = readscreen()) == 0) {
		         showscreen();
			 undolock = 1;
		      }
		      break;
	 	case 'u':    /* undo last move 				*/
		      if( ! undolock) {
		         undomove();
		         undolock = 1;
		      }
		      break;
	 	case 'k':    /* up 						*/
	 	case 'K':    /* run up 					*/
	 	case CNTL_K: /* run up, stop before object 			*/
	 	case 'j':    /* down 						*/
	 	case 'J':    /* run down 					*/
	 	case CNTL_J: /* run down, stop before object 			*/
	 	case 'l':    /* right 						*/
	 	case 'L':    /* run right 					*/
	 	case CNTL_L: /* run right, stop before object 			*/
	 	case 'h':    /* left 						*/
	 	case 'H':    /* run left 					*/
	 	case CNTL_H: /* run left, stop before object 			*/
		      do {
		         if( (action = testmove( c)) != 0) {
				    lastaction = action;
		            lastppos.x = ppos.x; lastppos.y = ppos.y;
		            lppc = map[ppos.x][ppos.y];
		            lasttpos1.x = tpos1.x; lasttpos1.y = tpos1.y; 
		            ltp1c = map[tpos1.x][tpos1.y];
		            lasttpos2.x = tpos2.x; lasttpos2.y = tpos2.y; 
		            ltp2c = map[tpos2.x][tpos2.y];
		            domove( lastaction); 
		            undolock = 0;
		         }
		      } while( (action != 0) && (! islower( c))
			      && (packets != savepack));
		      break;
	 	default:     helpmessage(); break;
     }
     if( (ret == 0) && (packets == savepack)) {
		 scorelevel = level;
		 scoremoves = moves;
		 scorepushes = pushes;
		 break;
     }
   }
   return( ret);
}
Esempio n. 20
0
void decode(void)
{
  unsigned optypes;
  int maxoperands;

  while(!exit_decoder) {

#ifdef ANDGLK
	extern int do_autosave;
	extern char AUTOSAVE_FILE[];
	extern offset stack_pointer;
	extern zword *local_vars;
	extern zword frame_count;
	offset save_pcp = PC;
	offset save_oldpcp = oldPC;
	offset save_sp = stack_pointer;
	zword* save_fp = local_vars;
	zword save_optypes = optypes;
	zword save_maxoperands = maxoperands;
	int save_frame_count = frame_count;
	zword save_zargs[8] = { operand[0], operand[1], operand[2], operand[3], 
							operand[4], operand[5], operand[6], operand[7] };
	int zarg_ix, save_zargc = 0; //zargc;
#endif

    zbyte opcode = HIBYTE(PC);
	//LOGD("state: PC:%x op:%x", (glui32)PC, (glui32)opcode);

    oldPC = PC;

#ifdef DEBUGGING
    if(do_check_watches)
      check_watches();
#endif

    PC++;

#ifndef NO_TICK
    glk_tick();  /* tick tock hickery dock the mouse ran up the clock */
#endif
    
    /* Top bits decide opcode/operand encoding */
    switch(opcode >> 4) {
    case 0: case 1:                         /* long 2OP */
      operand[0] = HIBYTE(PC);              /* small constant */
      operand[1] = HIBYTE(PC+1);            /* small constant */
      numoperands = 2; PC += 2;
      opcode += OFFSET_2OP - 0x00;
      break;


    case 2: case 3:                         /* long 2OP */
      operand[0] = HIBYTE(PC);              /* small constant */
      operand[1] = get_var(HIBYTE(PC+1));   /* variable */
      numoperands = 2; PC += 2;
      opcode += OFFSET_2OP - 0x20;
      break;


    case 4: case 5:                         /* long 2OP */
      operand[0] = get_var(HIBYTE(PC));     /* variable */
      operand[1] = HIBYTE(PC+1);            /* small constant */
      numoperands = 2; PC += 2;
      opcode += OFFSET_2OP - 0x40;
      break;


    case 6: case 7:                         /* long 2OP */
      operand[0] = get_var(HIBYTE(PC));     /* variable */
      operand[1] = get_var(HIBYTE(PC+1));   /* variable */
      numoperands = 2; PC += 2;
      opcode += OFFSET_2OP - 0x60;
      break;


    case 8:                                 /* short 1OP */
      operand[0] = HIWORD(PC);              /* large constant */
      numoperands = 1; PC += ZWORD_SIZE;
      opcode += OFFSET_1OP - 0x80;
      break;


    case 9:                                 /* short 1OP */
      operand[0] = HIBYTE(PC);              /* small constant */
      numoperands = 1; PC += 1;
      opcode += OFFSET_1OP - 0x90;
      break;


    case 10:                                /* short 1OP */
      operand[0] = get_var(HIBYTE(PC));     /* variable */
      numoperands = 1; PC += 1;
      opcode += OFFSET_1OP - 0xa0;
      break;


    case 11:                                /* short 0OP */
      if(opcode != 0xbe) {
	numoperands = 0;
	opcode += OFFSET_0OP - 0xb0;
	break;
      }
                                            /* EXTENDED */
      opcode  = HIBYTE(PC);   /* Get the extended opcode */
      optypes = HIBYTE(PC+1);
      PC += 2;

#ifndef FAST
      if(OFFSET_EXT + opcode > OFFSET_END) {
	n_show_error(E_INSTR, "unknown extended opcode", opcode);
	break;
      }
#endif
      
      for(numoperands = 0; numoperands < 4; numoperands++) {
	switch(optypes & (3 << 6)) {   /* Look at the highest two bits. */
	case 0 << 6:
	  operand[numoperands] = HIWORD(PC); PC+=ZWORD_SIZE; break;
	case 1 << 6:
	  operand[numoperands] = HIBYTE(PC); PC++; break;
	case 2 << 6:
	  operand[numoperands] = get_var(HIBYTE(PC)); PC++; break;
	default:
	  goto END_OF_EXTENDED;   /* inky says, "use the goto." */
	}
	optypes <<= 2;    /* Move the next two bits into position. */
      }
    END_OF_EXTENDED:
      opcode += OFFSET_EXT;
      break;

    case 12: case 13: case 14: case 15:     /* variable operand count */
      maxoperands = 4;
      optypes = ((unsigned) HIBYTE(PC)) << 8; /* Shift left so our loop will */
                                    /* be the same for both 4 and 8 operands */
      PC++;
  
      if(opcode == 0xec || opcode == 0xfa) {  /* call_vs2 and call_vn2 */
	maxoperands = 8;
	optypes |= HIBYTE(PC);  /* Fill the bottom 8 bits */
	PC++;
      }
      
      for(numoperands = 0; numoperands < maxoperands; numoperands++) {
	switch(optypes & (3 << 14)) {   /* Look at the highest two bits. */
	case 0 << 14:
	  operand[numoperands] = HIWORD(PC); PC+=ZWORD_SIZE; break;
	case 1 << 14:
	  operand[numoperands] = HIBYTE(PC); PC++; break;
	case 2 << 14:
	  operand[numoperands] = get_var(HIBYTE(PC)); PC++; break;
	default:
	  goto END_OF_VARIABLE;
	}
	optypes <<= 2;    /* Move the next two bits into position. */
      }
    END_OF_VARIABLE:
      opcode += OFFSET_2OP - 0xc0;
      break;
    }
    opcodetable[opcode]();

#ifdef ANDGLK
	if (do_autosave) {

	    PC = save_pcp;
	    oldPC = save_oldpcp;
	    stack_pointer = save_sp;
	    local_vars = save_fp;
	    numoperands = save_zargc;
	    frame_count = save_frame_count;
	    for (zarg_ix=0; zarg_ix<8; ++zarg_ix)
			operand[zarg_ix] = save_zargs[zarg_ix];
		optypes = save_optypes;
		maxoperands = save_maxoperands;

		savegame();

		do_autosave = 0;
		AUTOSAVE_FILE[0] = '\0';
	    continue;
	}       
#endif


  }
}
Esempio n. 21
0
void
GameSession::update_server(float delta)
{
  if (server->is_finished())
  {
    PinguHolder* pingu_holder = server->get_world()->get_pingus();
    Result result;

    result.plf    = server->get_plf();

    result.saved  = pingu_holder->get_number_of_exited();
    result.killed = pingu_holder->get_number_of_killed();
    result.total  = server->get_plf().get_number_of_pingus();

    result.needed = server->get_plf().get_number_to_save();

    result.max_time  = server->get_plf().get_time();
    result.used_time = server->get_time();

    { // Write the savegame
      Savegame savegame(result.plf.get_resname(),
                        (result.saved >= result.needed) ? Savegame::FINISHED : Savegame::ACCESSIBLE,
                        result.used_time,
                        result.saved);
      SavegameManager::instance()->store(savegame);
    }

    if (show_result_screen)
      ScreenManager::instance()->replace_screen(new ResultScreen(result));
    else
      ScreenManager::instance()->pop_screen();

  }
  else
  {
    // how much time we have to account for while doing world updates
    int time_passed = int(delta * 1000) + world_delay;
    // how much time each world update represents
    int update_time = globals::game_speed;

    // update the world (and the objects in it) in constant steps to account
    // for the time the previous frame took

    // invariant: world_updates - the number of times the world
    // has been updated during this frame
    int world_updates = 0;

    while ((world_updates+1)*update_time <= time_passed)
    {
      if (!pause)
      {
        if (fast_forward)
        {
          for (int i = 0; i < globals::fast_forward_time_scale; ++i)
            server->update();
        }
        else
        {
          server->update();
        }
      }

      world_updates++;
    }
    // save how far behind is the world compared to the actual time
    // so that we can account for that while updating in the next frame
    world_delay = time_passed - (world_updates*update_time);
  }
}
Esempio n. 22
0
Common::Error NeverhoodEngine::saveGameState(int slot, const Common::String &description) {
	const char *fileName = getSavegameFilename(slot);
	if (!savegame(fileName, description.c_str()))
		return Common::kWritingFailed;
	return Common::kNoError;
}
Esempio n. 23
0
/*
	lexical analyzer for larn
 */
int
yylex(void)
{
	char cc;
	int ic;
	if (hit2flag) {
		hit2flag = 0;
		yrepcount = 0;
		return (' ');
	}
	if (yrepcount > 0) {
		--yrepcount;
		return (lastok);
	} else
		yrepcount = 0;
	if (yrepcount == 0) {
		bottomdo();
		showplayer();
	}			/* show where the player is */
	lflush();
	while (1) {
		c[BYTESIN]++;
		/* check for periodic checkpointing */
		if (ckpflag)
			if ((c[BYTESIN] % CHECKPOINT_INTERVAL) == 0) {
#ifndef DOCHECKPOINTS
				savegame(ckpfile);
#else
				wait(0);	/* wait for other forks to finish */
				if (fork() == 0) {
					savegame(ckpfile);
					exit(0);
				}
#endif
#ifdef TIMECHECK
				if (dayplay == 0)
					if (playable()) {
						cursor(1, 19);
						lprcat("\nSorry, but it is now time for work.  Your game has been saved.\n");
						beep();
						lflush();
						savegame(savefilename);
						wizard = nomove = 1;
						sleep(4);
						died(-257);
					}
#endif /* TIMECHECK */
			}

		do {		/* if keyboard input buffer is too big, flush some of it */
			ioctl(0, FIONREAD, &ic);
			if (ic > flushno)
				read(0, &cc, 1);
		} while (ic > flushno);

		if (read(0, &cc, 1) != 1)
			return (lastok = -1);

		if (cc == 'Y' - 64) {	/* control Y -- shell escape */
			resetscroll();
			clear();	/* scrolling region, home, clear, no attributes */
			if ((ic = fork()) == 0) {	/* child */
				/* revoke */
				setgid(getgid());
				execl("/bin/csh", "csh", NULL);
				exit(1);
			}
			wait(0);
			if (ic < 0) {	/* error */
				write(2, "Can't fork off a shell!\n", 25);
				sleep(2);
			}

			setscroll();
			return (lastok = 'L' - 64);	/* redisplay screen */
		}

		if ((cc <= '9') && (cc >= '0')) {
			yrepcount = yrepcount * 10 + cc - '0';
		} else {
			if (yrepcount > 0)
				--yrepcount;
			return (lastok = cc);
		}
	}
}
Esempio n. 24
0
int main(int argc, char *argv[])
{
	int rc, i, uid, n, c, ch, t, mtbl, line, offset;
	FILE *fp;
	char filename[64], inbuf[128], name[NATIONNMLEN+1], *p, *u;
	struct stat st_buf;


	/* set directory */

	if(argc > 1)
		if(chdir(argv[1]) == -1) {
			gmove(20,18);
			gprintf("Error Setting Directory %s\n", argv[1]);
			ggetch();
			gend();
			exit(1);
		}
	

	/* set up display */

	ginit();

	gmove(5, 10);
	gputs("WARTOOL 1.0 Game Editor for Solomoriah's WAR!");
	gmove(6, 10);
	gputs("Copyright 1994, J. Christopher Gonnerman");
	gmove(7, 10);
	gputs("All Rights Reserved.");

	
	/* load map file */

	rc = loadmap();

	if(rc != 0) {
		gmove(20,10);
		gprintf("Error Loading Map (%s)\n", errors[rc]);
		ggetch();
		gend();
		exit(1);
	}

	/* load game save */

	rc = loadsave();

	if(rc != 0) {
		gmove(20,10);
		gprintf("Error Loading Game Save (%s)\n", errors[rc]);
		ggetch();
		gend();
		exit(1);
	}

	/* execute master file */

	gmove(20,10);
	gputs("Reading Master Commands...  ");
	grefresh();

	fp = fopen(MASTERFL, "r");

	if(fp != NULL) {
		for(i = 0; fgets(inbuf, 128, fp) != NULL; i++) {
			rc = execpriv(inbuf);
			if(rc == 0) {
				if((i+1) % 10 == 0) {
					gmove(20,48);
					gprintf("%3d lines", i+1);
					grefresh();
				}
			} else {
				gmove(20,10);
				gprintf("Master Cmd Failed, Line %d, Code %d  ", i+1, rc);
				(void)ggetch();
				gend();
				exit(2);
			}
		}

		fclose(fp);
	}

	/* main loop */

	gmove(20,10);
	gputs("Press Any Key to Begin...  ");
	gclrline();

	ggetch();

	mainscreen();

	toolmain();

	unlink("game.bak");
	if(rename("game.sav", "game.bak") == 0)
		fp = fopen("game.sav", "w");
	else
		fp = fopen("game.sv!", "w");

	savegame(fp);

	fclose(fp);

	/* clean up */

	endwin();

	exit(0);
}
Esempio n. 25
0
void
on_save1_activate                      (GtkMenuItem     *menuitem,
                                        gpointer         user_data)
{
    savegame();
}