Exemple #1
0
/*
 * Try and read a path from stdin and save the game to that location.
 *
 * If the function returns, the file was able to be saved, otherwise the
 * program is killed with appropriate status.
 */
void
read_path_and_save(struct game *g)
{
    char path[FILENAME_MAX + 1];
    int n = 0, c;
    FILE *f;

    while (n < FILENAME_MAX) {
        c = fgetc(stdin);

        if (c == EOF || c == '\n') {
            break;
        } else {
            path[n++] = c;
        }
    }

    path[n] = '\0';

    while (c != EOF && c != '\n') {
        c = fgetc(stdin);
    }

    if ((f = fopen(path, "w")) == NULL) {
        fprintf(stderr, "Can not open file for write\n");
        return;
    } 

    save_game(f, g);
    fclose(f);

    fprintf(stderr, "Save complete\n");
}
Exemple #2
0
View::View(QWidget *parent):
    QGraphicsView(parent)
{
    setGeometry(300,300,GS_WIDTH,GS_HEIGHT);
    menu_scene = new GraphicMenu(-width()/2,-height()/2,width(),height(),this);
    board_scene = new GraphicBoard(-width()/2,-height()/2,width(),height(),this);

    QIcon icon(QPixmap(":/Graphic_source/icon.png"));
    setWindowIcon(icon);

    setWindowTitle("Pentago");
    setFixedSize(this->size());//TODO:equally resize
    setViewportUpdateMode(QGraphicsView::BoundingRectViewportUpdate);
    setCacheMode(QGraphicsView::CacheBackground);
    setRenderHints(QPainter::Antialiasing | QPainter::SmoothPixmapTransform);

    connect(menu_scene, SIGNAL(New_game_selected(int)), this, SIGNAL(New_game(int)));
    connect(menu_scene, SIGNAL(Join_game_selected(std::string)), this, SIGNAL(Join_game(std::string)));
    connect(menu_scene, SIGNAL(Host_game_selected(std::string)), this, SIGNAL(Host_game(std::string)));
    connect(menu_scene, SIGNAL(Exit_game_pressed()), this, SLOT(close()));
    connect(menu_scene, SIGNAL(Load_game_selected(std::string)),this,SIGNAL(Load_game(std::string)));

    connect(board_scene, SIGNAL(quadrant_rotated(IView::quadrant,IView::turn)), this, SIGNAL(Rotate(IView::quadrant,IView::turn)));
    connect(board_scene, SIGNAL(Stone_clicked(int, int)), this, SIGNAL(Put_stone(int,int)));
    connect(board_scene, SIGNAL(leave_game()),this,SLOT(on_leave_game()));
    connect(board_scene, SIGNAL(save_game(QString)),this,SLOT(on_save_game(QString)));

    connect(board_scene, SIGNAL(message_sended(QString)), this, SLOT(on_msg_sended(QString)));

    connect(menu_scene, SIGNAL(game_go_to_start()),board_scene, SLOT(clean_board()));
    connect(menu_scene, SIGNAL(game_go_to_start()),board_scene, SLOT(clean_log()));
    Set_control_settings(View::MENU);//it must be called in presenter after view constructing
}
Exemple #3
0
static void save_game_menu_cb(void)
{
	if (open_filename == NULL)
		save_as_menu_cb();
	else
		save_game(open_filename);
}
Exemple #4
0
//
// run() - The control layer between the user and the player is here
//
// This method handles major game logic surrounding the player's actions.
// Everything dictated by the user takes place here
//
// Note: The coordinates of the map are still based on curses
// ie, 0,0 is top left.
//
void player::run()
{
	bool done = false;
	while( done == false )
	{
		command input = get_command();
		switch( input )
		{
			case WEST:
			case EAST:
			case NORTH:
			case SOUTH:
			case NW:
			case NE:
			case SW:
			case SE:
				done = move( input );
				break;
			case QUIT:
				done = true;
				gen_map();
				clear_screen();
				break;
			case SAVE:
				done = true;
				save_game();
				break;
		}
	}
}
/**
 * Handles save of current game to selected file,
 * denoted by the i of the given file_btn
 */
int on_select_save_file(Control* file_btn) {
	if (!save_game(file_btn->i, game)) {
		// TODO error dialog?
	}
	return !show_game_arena(get_root(file_btn), game, on_select_tile,
			game_menu_handles, on_select_difficulty, 4);
}
Exemple #6
0
Game::Game(shared_ptr<IView> _view)
    : userInterface(std::move(_view))
{
    Q_ASSERT(userInterface);

    players.push_back(std::make_unique<Player>("Player 1"));
    players.push_back(std::make_unique<Player>("Player 2"));

    auto v = userInterface.get();

    // connect View to Presenter
    connect(v, SIGNAL(New_game(int)), this, SLOT(new_game(int)));
    connect(v, SIGNAL(Save_game(std::string)), this, SLOT(save_game(std::string)));
    connect(v, SIGNAL(Load_game(std::string)), this, SLOT(load_game(std::string)));
    connect(v, SIGNAL(Host_game(std::string)), this, SLOT(host_game(std::string)));
    connect(v, SIGNAL(Join_game(std::string)), this, SLOT(join_game(std::string)));
    connect(v, SIGNAL(Leave()), this, SLOT(leave()));
    connect(v, SIGNAL(Put_stone(int,int)), this, SLOT(put_stone(int,int)));
    connect(v, SIGNAL(Rotate(IView::quadrant,IView::turn)), this, SLOT(rotate(IView::quadrant,IView::turn)));

    // connect Presenter to View
    connect(this, SIGNAL(draw_stone(int,int,IView::color)),v,SLOT(Draw_stone(int,int,IView::color)));
    connect(this, SIGNAL(set_control_settings(IView::control_setting)),v,SLOT(Set_control_settings(IView::control_setting)));
    connect(this, SIGNAL(message(string)), v, SLOT(Show_message(string)));
}
Exemple #7
0
bool savegame::save_game_interactive(CVideo& video, const std::string& message,
									 gui::DIALOG_TYPE dialog_type)
{
	show_confirmation_ = true;
	create_filename();

	int res = gui2::twindow::OK;
	bool exit = true;

	do{
		try{
			res = show_save_dialog(video, message, dialog_type);
			exit = true;

			if (res == gui2::twindow::OK){
				exit = check_overwrite(video);
			}
		}
		catch (illegal_filename_exception){
			exit = false;
		}
	}
	while (!exit);

	if (res == 2) //Quit game
		throw end_level_exception(QUIT);

	if (res != gui2::twindow::OK)
		return false;

	return save_game(&video);
}
Exemple #8
0
//---------------------------------------------------------------------------
// Name: save_game [filename]
// Desc: Test function to show how write a console function =)
//---------------------------------------------------------------------------
static int csl_save_game(void)
{
    int argc = csl_argc()+1;
	char path[60];

	    
	if(argc!=2)
	{
		csl_textout(1, "syntax: save_game [filename]");
	}
	else
	{
		sprintf(path,"save/%s",csl_argv(1));

		if(!save_game(path,"Console Save"))
		{
			csl_textoutf(1, "couldn't save game to %s",path);
            return CSLMSG_ERROR;
		}
		else
		{
			csl_textoutf(1, "saved game to %s",path );
		}

	}
		
	return CSLMSG_O_K;
    
}
Exemple #9
0
static void save_as_menu_cb(void)
{
	GtkWidget *dialog;

	dialog = gtk_file_chooser_dialog_new(
						    /* Dialog caption */
						    _("Save As..."),
						    GTK_WINDOW(toplevel),
						    GTK_FILE_CHOOSER_ACTION_SAVE,
						    GTK_STOCK_CANCEL,
						    GTK_RESPONSE_CANCEL,
						    GTK_STOCK_SAVE,
						    GTK_RESPONSE_ACCEPT,
						    NULL);
	gtk_dialog_set_default_response(GTK_DIALOG(dialog),
					GTK_RESPONSE_ACCEPT);
	if (gtk_dialog_run(GTK_DIALOG(dialog)) == GTK_RESPONSE_ACCEPT) {
		char *file;
		file =
		    gtk_file_chooser_get_filename(GTK_FILE_CHOOSER
						  (dialog));
		save_game(file);
		if (open_filename == NULL)
			open_filename = file;
		else
			g_free(file);
	}
	gtk_widget_destroy(dialog);
}
Exemple #10
0
int save_load_interface(int which) { // use the CHOICE_ defines
    int outcome=1;
    char temp[80];
    
    if (which == CHOICE_SAVE) {
        outcome = save_game (&gs);
        if (outcome == 1) sprintf(temp,"Saving FAILED."); else sprintf(temp,"Saving successful!");
    } else if (which == CHOICE_LOAD) {
        outcome = load_game (&gs);
        if (outcome == 1) sprintf(temp,"Loading FAILED."); else sprintf(temp,"Loading successful!");
    } else {
        // what the shit?
    }
    
    bool done = false;
    while (!done) {
        
        SDL_Event event;
        while (SDL_PollEvent(&event))
        {
            // check for messages
            switch (event.type)
            {
                // exit if the window is closed
            case SDL_QUIT:
                done = true;
                break;

                // check for keypresses
            case SDL_KEYDOWN:
                {
                    if (event.key.keysym.sym == SDLK_RETURN) {
                        if (outcome == 0)
                            return CODE_MAIN_GAME_INTERFACE;
                        else
                            if (which == CHOICE_SAVE) return CODE_MAIN_GAME_INTERFACE;
                            else if (which == CHOICE_LOAD) return CODE_MAIN_MENU;
                            else { /* what the shit man */  }
                    }
                }
            } // end switch
        } // end of message processing
        
        print_full_picture(BITMAPS[IMG_FULL_SAVELOAD]);
        if (which == CHOICE_SAVE) put_text_at(-1,300,"SAVING...");
        else if (which == CHOICE_LOAD) put_text_at(-1,300,"LOADING...");
        
        put_text_at(-1,400,temp);
        
        put_text_at(-1,500,"Press ENTER to continue.");
        
        SDL_Flip(MAIN_SCREEN);
        SDL_Delay(100);
    }
    
    
    return 0;
}
Exemple #11
0
/**
 * Close up the current game (player may or may not be dead)
 *
 * Note that the savefile is not saved until the tombstone is
 * actually displayed and the player has a chance to examine
 * the inventory and such.  This allows cheating if the game
 * is equipped with a "quit without save" method.  XXX XXX XXX
 */
void close_game(void)
{
	/* Tell the UI we're done with the game state */
	event_signal(EVENT_LEAVE_GAME);

	/* Handle stuff */
	handle_stuff(player->upkeep);

	/* Flush the messages */
	event_signal(EVENT_MESSAGE_FLUSH);

	/* Flush the input */
	event_signal(EVENT_INPUT_FLUSH);

	/* No suspending now */
	signals_ignore_tstp();

	/* Hack -- Increase "icky" depth */
	screen_save_depth++;

	/* Save monster memory to user directory */
	if (!lore_save("lore.txt")) {
		msg("lore save failed!");
		event_signal(EVENT_MESSAGE_FLUSH);
	}

	/* Handle death or life */
	if (player->is_dead) {
		death_knowledge();
		death_screen();

		/* Save dead player */
		if (!savefile_save(savefile)) {
			msg("death save failed!");
			event_signal(EVENT_MESSAGE_FLUSH);
		}
	} else {
		/* Save the game */
		save_game();

		if (Term->mapped_flag) {
			struct keypress ch;

			prt("Press Return (or Escape).", 0, 40);
			ch = inkey();
			if (ch.code != ESCAPE)
				predict_score();
		}
	}

	/* Hack -- Decrease "icky" depth */
	screen_save_depth--;

	/* Allow suspending now */
	signals_handle_tstp();
}
//on slot click load the game or save it 
static void on_slot_click(gui_control* target, gui_control* window, gui_size x, gui_size y) {
    int slot = target->state.istate;
    int mode = target->parent->state.istate;
    gui_child_pop(window);

    if (mode == LOAD_MODE)
        load_game(window, slot);
    else if (mode == SAVE_MODE)
        save_game(window, slot);
}
Exemple #13
0
void CClient::save(const std::string & fname)
{
	if(gs->curB)
	{
        logNetwork->errorStream() << "Game cannot be saved during battle!";
		return;
	}

	SaveGame save_game(fname);
	sendRequest((CPackForClient*)&save_game, PlayerColor::NEUTRAL);
}
static void shortcut_quick_save_game()
{
	// Do a quick save in playing mode and a regular save in Scenario Editor mode. In other cases, don't do anything.
	if (RCT2_GLOBAL(RCT2_ADDRESS_SCREEN_FLAGS, uint8) == SCREEN_FLAGS_PLAYING) {
		tool_cancel();
		save_game();
	}
	else if (RCT2_GLOBAL(RCT2_ADDRESS_SCREEN_FLAGS, uint8) & SCREEN_FLAGS_SCENARIO_EDITOR) {
		rct_s6_info *s6Info = (rct_s6_info*)0x0141F570;
		window_loadsave_open(LOADSAVETYPE_SAVE | LOADSAVETYPE_LANDSCAPE, s6Info->name);
	}
}
Exemple #15
0
/*****************************************************************************
  Save the game (a manual save is triggert).
*****************************************************************************/
bool api_server_save(lua_State *L, const char *filename)
{
  LUASCRIPT_CHECK_STATE(L, FALSE);

  /* Limit the allowed characters in the filename. */
  if (filename != NULL && !is_safe_filename(filename)) {
    return FALSE;
  }

  save_game(filename, "User request (Lua)", FALSE);
  return TRUE;
}
Exemple #16
0
void					MyGame::menu_first_(void)
{
  if (input_.isKeyDown(gdl::Keys::Return) == true && this->key_ == false)
    {
      switch (this->items_.update(0, this->posMenu_.what_))
	{
	case OPTION_ONE:
	  {
	    this->posMenu_.what_ = MENU_MAP;
	    this->posMenu_.who_ = OPTION_ONE;
	    this->items_.update(this->posMenu_.who_);
	    break;
	  }
	case OPTION_TWO:
	  {
	    if (this->items_.isNewGame() == false)
	      {
		this->camera_.reset_cam_game(this->options_->getXMap(), this->options_->getYMap());
		this->posMenu_.where_ = GAME;
		this->panel_.initialize(this->options_->getXMap(), -this->options_->getYMap(), 0);
	      }
	    break;
	  }
	case OPTION_THR:
	  {
	    if (load_game() == true)
	      {
		music_->playSong("gameS");
		this->camera_.reset_cam_game(this->options_->getXMap(), this->options_->getYMap());
		this->posMenu_.where_ = GAME;
		this->panel_.initialize(this->options_->getXMap(), -this->options_->getYMap(), 0);
		this->items_.setNewGame(false);
	      }
	    break;
	  }
	case OPTION_FOU:
	  {
	    this->posMenu_.what_ = MENU_OPTGEN;
	    this->posMenu_.who_ = OPTION_ONE;
	    this->items_.update(this->posMenu_.who_);
	    break;
	  }
	case MAX_MENU:
	  {
	    save_game();
	    this->window_.close();
	    break;
	  }
	}
    }
}
Exemple #17
0
/*
 * Close up the current game (player may or may not be dead)
 *
 * Note that the savefile is not saved until the tombstone is
 * actually displayed and the player has a chance to examine
 * the inventory and such.  This allows cheating if the game
 * is equipped with a "quit without save" method.  XXX XXX XXX
 */
void close_game(void)
{
	/* Handle stuff */
	handle_stuff(p_ptr);

	/* Flush the messages */
	message_flush();

	/* Flush the input */
	flush();


	/* No suspending now */
	signals_ignore_tstp();


	/* Hack -- Increase "icky" depth */
	character_icky++;


	/* Handle death */
	if (p_ptr->is_dead)
	{
		death_screen();
	}

	/* Still alive */
	else
	{
		/* Save the game */
		save_game();

		if (Term->mapped_flag)
		{
			struct keypress ch;

			prt("Press Return (or Escape).", 0, 40);
			ch = inkey();
			if (ch.code != ESCAPE)
				predict_score();
		}
	}


	/* Hack -- Decrease "icky" depth */
	character_icky--;


	/* Allow suspending now */
	signals_handle_tstp();
}
Exemple #18
0
bool savegame::save_game_automatic(CVideo& video, bool ask_for_overwrite, const std::string& filename)
{
	if (filename == "")
		create_filename();
	else
		filename_ = filename;

	if (ask_for_overwrite){
		if (!check_overwrite(video)) {
			return save_game_interactive(video, "", gui::OK_CANCEL);
		}
	}

	return save_game(&video);
}
Exemple #19
0
int main(int argc, char *argv[])
{

	initial();

	if (!strcmp (argv[1], "-r"))
		load_game (argv[2]);

	gameloop();

	v_reset_mode();
	m_hide();
	m_close();

	save_game (GAMEFILE);

}
Exemple #20
0
bool turn(Labyrinth &map) {
	take_objects_from_cell(map, map.player[map.current_player]);
	if (DEBUG)
		print_debug(map);
	user_message(map.player[map.current_player].name + ", it's your turn");
	string message = map.player[map.current_player].name + ", enter what you want (go, bomb, shoot, knife, suicide, stay, leave";
	if (SERVER)
		message += ")";
	else
		message += ", save)";
	user_message(message);
	
	if (SERVER)
		server.clear_user_messages(map.current_player);
	string s = read_user_command(map.current_player);
	
	if (s == "leave")
		return leave_game(map, map.player[map.current_player]);
	if (s == "suicide")
		return suicide(map, map.player[map.current_player]);
	if (s == "knife")
		return use_knife(map, map.player[map.current_player]);
	if (s == "bomb")
		return bomb(map, map.player[map.current_player]);
	if (s == "go")
		return go(map, map.player[map.current_player]);
	if (s == "shoot")
		return shoot(map, map.player[map.current_player]);
	if (s == "stay")
		return stay(map.player[map.current_player]);
	if (s == "save" && !SERVER) {
		save_game(map);
		return false;
	}
	if (s == "winthemall") {
		if (is_developer(map.player[map.current_player])) {
			user_message("Okay, master");
			finish_game(map);
			return true;
		}
	}
	
	user_message(map.player[map.current_player].name + ", you entered incorrect command! Try again, if you can!");
	return false;
}
Exemple #21
0
bool savegame::save_game_interactive(CVideo& video, const std::string& message,
									 gui::DIALOG_TYPE dialog_type)
{
	show_confirmation_ = true;
	create_filename();

	const int res = show_save_dialog(video, message, dialog_type);

	if (res == 2) { 
		throw_quit_game_exception(); //Quit game
	}

	if (res == gui2::twindow::OK && check_overwrite(video)) {
		return save_game(&video);
	}

	return false;
}
Exemple #22
0
bool savegame::save_game_automatic(CVideo& video, bool ask_for_overwrite, const std::string& filename)
{
	bool overwrite = true;

	if (filename == "")
		create_filename();
	else
		filename_ = filename;

	if (ask_for_overwrite){
		overwrite = check_overwrite(video);

		if (!overwrite)
			return save_game_interactive(video, "", true);
	}

	return save_game(&video);
}
Exemple #23
0
int savegame_simple ()
{
	char home[MAX_PATH], path[MAX_PATH];

	if (get_app_dir (home, MAX_PATH) < 0) {
		message_box ("Couldn't save game.");
		return err_BadFileOpen;
	}

	sprintf (path, "%s/" DATA_DIR "/", home);
	MKDIR (path, 0755);
	sprintf (path, "%s/" DATA_DIR "/%05X.%s/", home, game.crc, game.id);
	MKDIR (path, 0711);
	sprintf (path, "%s/" DATA_DIR "/%05X.%s/%08d.sav",
		home, game.crc, game.id, 0);

	save_game (path, "Default savegame");

	return err_OK;
}
Exemple #24
0
void gui_save_game(struct GuiButton *gbtn)
{
  struct PlayerInfo *player;
  long slot_num;
  player = get_my_player();
  if (strcasecmp((char *)gbtn->content, gui_string(GUIStr_SlotUnused)) != 0)
  {
      slot_num = gbtn->field_1B%TOTAL_SAVE_SLOTS_COUNT;
      fill_game_catalogue_slot(slot_num,(char *)gbtn->content);
      if (save_game(slot_num))
      {
          output_message(SMsg_GameSaved, 0, true);
      } else
      {
          ERRORLOG("Error in save!");
          create_error_box(GUIStr_ErrorSaving);
      }
  }
  set_players_packet_action(player, PckA_TogglePause, 0, 0, 0, 0);
}
Exemple #25
0
Game::Game() {
    players.push_back(unique_ptr<Player>(new Player("Player 1")));
    players.push_back(unique_ptr<Player>(new Player("Player 2")));

    // init View here
    userInterface.reset(new View());
    shared_ptr<View> v = std::dynamic_pointer_cast<View>(userInterface);

    // connect View to Presenter
    connect(v.get(), SIGNAL(New_game(int)), this, SLOT(new_game(int)));
    connect(v.get(), SIGNAL(Save_game(std::string)), this, SLOT(save_game(std::string)));
    connect(v.get(), SIGNAL(Load_game(std::string)), this, SLOT(load_game(std::string)));
    connect(v.get(), SIGNAL(Host_game(std::string)), this, SLOT(host_game(std::string)));
    connect(v.get(), SIGNAL(Join_game(std::string)), this, SLOT(join_game(std::string)));
    connect(v.get(), SIGNAL(Leave()), this, SLOT(leave()));
    connect(v.get(), SIGNAL(Put_stone(int,int)), this, SLOT(put_stone(int,int)));
    connect(v.get(), SIGNAL(Rotate(IView::quadrant,IView::turn)), this, SLOT(rotate(IView::quadrant,IView::turn)));

    // connect Presenter to View
    connect(this, SIGNAL(draw_stone(int,int,IView::color)),v.get(),SLOT(Draw_stone(int,int,IView::color)));
    connect(this, SIGNAL(set_control_settings(IView::control_setting)),v.get(),SLOT(Set_control_settings(IView::control_setting)));
    connect(this, SIGNAL(message(string)), v.get(), SLOT(Show_message(string)));
}
Exemple #26
0
int savegame_simple ()
{
	char home[MAX_PATH], path[MAX_PATH];

#ifdef DREAMCAST
	uint8 addr, port, unit;

	addr = maple_first_vmu();
	if(addr) {
		maple_create_port(addr, &port, &unit);
		sprintf(g_vmu_port, "%c%d", port + 'a', unit);
	} else {
		message_box("No VMU found.");
		return err_OK;
	}

	sprintf(path, VMU_PATH, g_vmu_port, game.id, slot);
	fs_unlink(path);
#else
	if (get_app_dir (home, MAX_PATH) < 0) {
		message_box ("Couldn't save game.");
		return err_BadFileOpen;
	}

	sprintf (path, "%s/" DATA_DIR "/", home);
	MKDIR (path, 0755);
	sprintf (path, "%s/" DATA_DIR "/%05X.%s/", home, game.crc, game.id);
	MKDIR (path, 0711);
	sprintf (path, "%s/" DATA_DIR "/%05X.%s/%08d.sav",
		home, game.crc, game.id, 0);
#endif
        printf("here?\n");
	save_game (path, "Default savegame");

	return err_OK;
}
Exemple #27
0
void talk ()
{
	freeze (1);
	freeze (current_sprite);
	if (herb == 1)
	{
		say_stop ("`9Did you find the flower?", current_sprite);
		say_stop ("Not yet.", 1);
		say_stop ("`9Do you want me to help you find it?", current_sprite);
		say_stop ("No! Er, I'll find it soon!", 1);
		say_stop ("You just stay here and don't do anything stupid!", 1);
		say_stop ("`9Sure thing.", current_sprite);
	}
	else if (herb == 2)
	{
		int duck = sp ("eggeric_duck");
		int pig = sp ("eggeric_pig");
		say_stop ("I've found the flower.", 1);
		say_stop ("`9Great, now what do we do?", current_sprite);
		say_stop ("We put it in our mouth.", 1);
		say_stop ("`9And then what?", current_sprite);
		say_stop ("Then we listen.", 1);
		say_stop ("`6Dude! The king is walking around outside the castle!", pig);
		say_stop ("`4Dude! Is he mad?", duck);
		say_stop ("`6Dude! I guess he has his reasons!", pig);
		say_stop ("`4Dude! I suppose so!", duck);
		say_stop ("The king? We can't risk getting caught!", 1);
		say_stop ("We shouldn't steal tonight.", 1);
		say_stop ("`9Are you afraid? I thought you were brave!", current_sprite);
		say_stop ("Well, yes, but... The King!", 1);
		say_stop ("Come on, what do those beasts know of us.", current_sprite);
		say_stop ("`9Let's focus on the task at hand.", current_sprite);
		say_stop ("Allright. Please return the flower to me.", 1);
		say_stop ("`9Hey, it's gone, where did it go?", current_sprite);
		say_stop ("Dude, you're no thief at all!", 1);
		say_stop ("You'd get caught before you even started!", 1);
		say_stop ("`9Well, eh, ...", current_sprite);
		say_stop ("I took the flower from under your nose.", 1);
		say_stop ("`9Oh, that explains it...", current_sprite);
		say_stop ("Well then. I'll go inside.", 1);
		herb = 3;
		save_game (-1);
	}
	else if (herb == 3)
	{
		say_stop ("`9What are you waiting for?", current_sprite);
		say_stop ("Nothing, I'll go inside now.", 1);
	}
	else if (herb == 4)
	{
		say_stop ("`9Are we done?", current_sprite);
		say_stop ("No, I didn't find anything yet.", 1);
		say_stop ("I'll go back in.", 1);
		say_stop ("`9Hurry up, will you?", current_sprite);
		say_stop ("Relax, all will be fine.", 1);
		herb = 3;
	}
	else if (herb == 5)
	{
		say_stop ("`9Are we done?", current_sprite);
		say_stop ("No, I found some gold, but not the saddle.", 1);
		say_stop ("It must be worth at least 10000 gold pieces.", 1);
		say_stop ("It is decorated with bells and everything.", 1);
		say_stop ("`9Hurry up, will you?", current_sprite);
		say_stop ("Relax, all will be fine.", 1);
		herb = 6;
		save_game (-1);
	}
	else if (herb == 6)
	{
		say_stop ("`9Are we done?", current_sprite);
		say_stop ("No, I didn't find the saddle yet.", 1);
		say_stop ("`9Hurry up, will you?", current_sprite);
		say_stop ("Relax, all will be fine.", 1);
	}
	unfreeze (current_sprite);
	unfreeze (1);
}
Exemple #28
0
void post_script_cleanup() {
    // should do any post-script stuff here, like go to new room
    if (ccError) quit(ccErrorString);
    ExecutingScript copyof = scripts[num_scripts-1];
    //  write_log("Instance finished.");
    if (scripts[num_scripts-1].forked)
        delete scripts[num_scripts-1].inst;
    num_scripts--;
    inside_script--;

    if (num_scripts > 0)
        curscript = &scripts[num_scripts-1];
    else {
        curscript = NULL;
    }
    //  if (abort_executor) user_disabled_data2=aborted_ip;

    int old_room_number = displayed_room;

    // run the queued post-script actions
    for (int ii = 0; ii < copyof.numPostScriptActions; ii++) {
        int thisData = copyof.postScriptActionData[ii];

        switch (copyof.postScriptActions[ii]) {
    case ePSANewRoom:
        // only change rooms when all scripts are done
        if (num_scripts == 0) {
            new_room(thisData, playerchar);
            // don't allow any pending room scripts from the old room
            // in run_another to be executed
            return;
        }
        else
            curscript->queue_action(ePSANewRoom, thisData, "NewRoom");
        break;
    case ePSAInvScreen:
        invscreen();
        break;
    case ePSARestoreGame:
        cancel_all_scripts();
        try_restore_save(thisData);
        return;
    case ePSARestoreGameDialog:
        restore_game_dialog();
        return;
    case ePSARunAGSGame:
        cancel_all_scripts();
        load_new_game = thisData;
        return;
    case ePSARunDialog:
        do_conversation(thisData);
        break;
    case ePSARestartGame:
        cancel_all_scripts();
        restart_game();
        return;
    case ePSASaveGame:
        save_game(thisData, copyof.postScriptSaveSlotDescription[ii]);
        break;
    case ePSASaveGameDialog:
        save_game_dialog();
        break;
    default:
        quitprintf("undefined post script action found: %d", copyof.postScriptActions[ii]);
        }
        // if the room changed in a conversation, for example, abort
        if (old_room_number != displayed_room) {
            return;
        }
    }


    int jj;
    for (jj = 0; jj < copyof.numanother; jj++) {
        old_room_number = displayed_room;
        QueuedScript &script = copyof.ScFnQueue[jj];
        RunScriptFunction(script.Instance, script.FnName, script.ParamCount, script.Param1, script.Param2);
        if (script.Instance == kScInstRoom && script.ParamCount == 1)
        {
            // some bogus hack for "on_call" event handler
            play.roomscript_finished = 1;
        }

        // if they've changed rooms, cancel any further pending scripts
        if ((displayed_room != old_room_number) || (load_new_game))
            break;
    }
    copyof.numanother = 0;

}
Exemple #29
0
bool command_executor::execute_command(const hotkey_command&  cmd, int /*index*/, bool press)
{
	// hotkey release handling
	if (!press) {
		switch(cmd.id) {
			// release a scroll key, un-apply scrolling in the given direction
			case HOTKEY_SCROLL_UP:
				scroll_up(false);
				break;
			case HOTKEY_SCROLL_DOWN:
				scroll_down(false);
				break;
			case HOTKEY_SCROLL_LEFT:
				scroll_left(false);
				break;
			case HOTKEY_SCROLL_RIGHT:
				scroll_right(false);
				break;
			default:
				return false; // nothing else handles a hotkey release
		}

		return true;
	}

	// hotkey press handling
	switch(cmd.id) {
		case HOTKEY_SCROLL_UP:
			scroll_up(true);
			break;
		case HOTKEY_SCROLL_DOWN:
			scroll_down(true);
			break;
		case HOTKEY_SCROLL_LEFT:
			scroll_left(true);
			break;
		case HOTKEY_SCROLL_RIGHT:
			scroll_right(true);
			break;
		case HOTKEY_CYCLE_UNITS:
			cycle_units();
			break;
		case HOTKEY_CYCLE_BACK_UNITS:
			cycle_back_units();
			break;
		case HOTKEY_ENDTURN:
			end_turn();
			break;
		case HOTKEY_UNIT_HOLD_POSITION:
			unit_hold_position();
			break;
		case HOTKEY_END_UNIT_TURN:
			end_unit_turn();
			break;
		case HOTKEY_LEADER:
			goto_leader();
			break;
		case HOTKEY_UNDO:
			undo();
			break;
		case HOTKEY_REDO:
			redo();
			break;
		case HOTKEY_TERRAIN_DESCRIPTION:
			terrain_description();
			break;
		case HOTKEY_UNIT_DESCRIPTION:
			unit_description();
			break;
		case HOTKEY_RENAME_UNIT:
			rename_unit();
			break;
		case HOTKEY_SAVE_GAME:
			save_game();
			break;
		case HOTKEY_SAVE_REPLAY:
			save_replay();
			break;
		case HOTKEY_SAVE_MAP:
			save_map();
			break;
		case HOTKEY_LOAD_GAME:
			load_game();
			break;
		case HOTKEY_TOGGLE_ELLIPSES:
			toggle_ellipses();
			break;
		case HOTKEY_TOGGLE_GRID:
			toggle_grid();
			break;
		case HOTKEY_STATUS_TABLE:
			status_table();
			break;
		case HOTKEY_RECALL:
			recall();
			break;
		case HOTKEY_LABEL_SETTINGS:
			label_settings();
			break;
		case HOTKEY_RECRUIT:
			recruit();
			break;
		case hotkey::HOTKEY_REPEAT_RECRUIT:
			repeat_recruit();
			break;
		case HOTKEY_SPEAK:
			speak();
			break;
		case HOTKEY_SPEAK_ALLY:
			whisper();
			break;
		case HOTKEY_SPEAK_ALL:
			shout();
			break;
		case HOTKEY_CREATE_UNIT:
			create_unit();
			break;
		case HOTKEY_CHANGE_SIDE:
			change_side();
			break;
		case HOTKEY_KILL_UNIT:
			kill_unit();
			break;
		case HOTKEY_PREFERENCES:
			preferences();
			break;
		case HOTKEY_OBJECTIVES:
			objectives();
			break;
		case HOTKEY_UNIT_LIST:
			unit_list();
			break;
		case HOTKEY_STATISTICS:
			show_statistics();
			break;
		case HOTKEY_STOP_NETWORK:
			stop_network();
			break;
		case HOTKEY_START_NETWORK:
			start_network();
			break;
		case HOTKEY_LABEL_TEAM_TERRAIN:
			label_terrain(true);
			break;
		case HOTKEY_LABEL_TERRAIN:
			label_terrain(false);
			break;
		case HOTKEY_CLEAR_LABELS:
			clear_labels();
			break;
		case HOTKEY_SHOW_ENEMY_MOVES:
			show_enemy_moves(false);
			break;
		case HOTKEY_BEST_ENEMY_MOVES:
			show_enemy_moves(true);
			break;
		case HOTKEY_DELAY_SHROUD:
			toggle_shroud_updates();
			break;
		case HOTKEY_UPDATE_SHROUD:
			update_shroud_now();
			break;
		case HOTKEY_CONTINUE_MOVE:
			continue_move();
			break;
		case HOTKEY_SEARCH:
			search();
			break;
		case HOTKEY_HELP:
			show_help();
			break;
		case HOTKEY_CHAT_LOG:
			show_chat_log();
			break;
		case HOTKEY_USER_CMD:
			user_command();
			break;
		case HOTKEY_CUSTOM_CMD:
			custom_command();
			break;
		case HOTKEY_AI_FORMULA:
			ai_formula();
			break;
		case HOTKEY_CLEAR_MSG:
			clear_messages();
			break;
		case HOTKEY_LANGUAGE:
			change_language();
			break;
		case HOTKEY_REPLAY_PLAY:
			play_replay();
			break;
		case HOTKEY_REPLAY_RESET:
			reset_replay();
			break;
		case HOTKEY_REPLAY_STOP:
			stop_replay();
			break;
		case HOTKEY_REPLAY_NEXT_TURN:
			replay_next_turn();
			break;
		case HOTKEY_REPLAY_NEXT_SIDE:
			replay_next_side();
			break;
		case HOTKEY_REPLAY_NEXT_MOVE:
			replay_next_move();
			break;
		case HOTKEY_REPLAY_SHOW_EVERYTHING:
			replay_show_everything();
			break;
		case HOTKEY_REPLAY_SHOW_EACH:
			replay_show_each();
			break;
		case HOTKEY_REPLAY_SHOW_TEAM1:
			replay_show_team1();
			break;
		case HOTKEY_REPLAY_SKIP_ANIMATION:
			replay_skip_animation();
			break;
		case HOTKEY_REPLAY_EXIT:
			replay_exit();
			break;
		case HOTKEY_WB_TOGGLE:
			whiteboard_toggle();
			break;
		case HOTKEY_WB_EXECUTE_ACTION:
			whiteboard_execute_action();
			break;
		case HOTKEY_WB_EXECUTE_ALL_ACTIONS:
			whiteboard_execute_all_actions();
			break;
		case HOTKEY_WB_DELETE_ACTION:
			whiteboard_delete_action();
			break;
		case HOTKEY_WB_BUMP_UP_ACTION:
			whiteboard_bump_up_action();
			break;
		case HOTKEY_WB_BUMP_DOWN_ACTION:
			whiteboard_bump_down_action();
			break;
		case HOTKEY_WB_SUPPOSE_DEAD:
			whiteboard_suppose_dead();
			break;
		case HOTKEY_SELECT_HEX:
			select_hex();
			break;
		case HOTKEY_DESELECT_HEX:
			deselect_hex();
			break;
		case HOTKEY_MOVE_ACTION:
			move_action();
			break;
		case HOTKEY_SELECT_AND_ACTION:
			select_and_action();
			break;
		case HOTKEY_ACCELERATED:
			toggle_accelerated_speed();
			break;
		case LUA_CONSOLE:
			lua_console();
			break;
		case HOTKEY_ZOOM_IN:
			zoom_in();
			break;
		case HOTKEY_ZOOM_OUT:
			zoom_out();
			break;
		case HOTKEY_ZOOM_DEFAULT:
			zoom_default();
			break;
		case HOTKEY_MAP_SCREENSHOT:
			map_screenshot();
			break;
		case HOTKEY_QUIT_TO_DESKTOP:
			quit_confirmation::quit_to_desktop();
			break;
		case HOTKEY_QUIT_GAME:
			quit_confirmation::quit_to_title();
			break;
		default:
			return false;
	}
	return true;
}
// The single-player quick save now works without presenting a dialog, and
// uses (cruder but) similar overwrite logic, so we just use that now.
bool
save_game_full_auto(bool inOverwriteRecent) {
    return save_game();
}