示例#1
0
WORLDPTR worldfactory::convert_to_world(std::string origin_path)
{
    // prompt for worldname? Nah, just make a worldname... the user can fix it later if they really don't want this as a name...
    std::string worldname = get_next_valid_worldname("ConvWorld", this);

    // check and loop on validity

    // create world informations
    WORLDPTR newworld = new WORLD();
    newworld->world_name = worldname;

    std::stringstream path;
    path << SAVE_DIR << PATH_SEPARATOR << worldname;
    newworld->world_path = path.str();

    // save world as conversion world
    if (save_world(newworld, true)) {
        // move files from origin_path into new world path
        std::vector<std::string> origin_files = file_finder::get_files_from_path(".", origin_path, false);
        for (unsigned i = 0; i < origin_files.size(); ++i) {
            std::string filename = origin_files[i].substr(origin_files[i].find_last_of("/\\"));

            rename(origin_files[i].c_str(), std::string(newworld->world_path + filename).c_str());
        }

        DebugLog() << "worldfactory::convert_to_world -- World Converted Successfully!\n";
        return newworld;
    } else {
        // something horribly wrong happened
        DebugLog() << "worldfactory::convert_to_world -- World Conversion Failed!\n";
        return NULL;
    }
}
//! The user picks 'upload map' in the GUI.
//! First we save the map. Then we call Python, which packages the map
//! and uploads it to the correct asset server, then notify the instance we
//! are connected to that the map has been updated, which then gets and runs
//! that new map. That process causes it to tell all clients of a new map that
//! they should get, which makes them get the new version. Among those clients is
//! this one, the uploader, which we do not treat differently in that respect.
void do_upload()
{
    renderprogress(0.1, "compiling scripts...");

    // Make sure the script compiles ok TODO: All scripts, not just the main one
    REFLECT_PYTHON( get_map_script_filename );
    std::string filename = boost::python::extract<std::string>( get_map_script_filename() );
    if (!checkCompile(filename))
        return;

    // Save ogz
    renderprogress(0.3, "generating map...");
    save_world(game::getclientmap());

// load_world: ogzname, mname, cname: packages/base/spiral/map.ogz,base/spiral/map,(null)
// save_world ogzname, mname, cname: packages//packages.ogz,/packages

    // Save entities (and backup)
    renderprogress(0.4, "exporting entities...");
    REFLECT_PYTHON( export_entities );
    export_entities("entities.json");

    // Do the upload
    renderprogress(0.5, "uploading map...");
    REFLECT_PYTHON( upload_map );
    upload_map();

    // Remember asset
    REFLECT_PYTHON( get_curr_map_asset_id );
    std::string assetId = boost::python::extract<std::string>( get_curr_map_asset_id() );
    setsvar("last_uploaded_map_asset", assetId.c_str());
}
示例#3
0
// sendmap/getmap commands, should be replaced by more intuitive map downloading
void sendmap(const std::string &mapname) {
	if (!mapname.empty())
		save_world(mapname);
	changemap(mapname);
	mapname = getclientmap();
	int mapsize;
	uchar *mapdata = readmap(mapname, &mapsize);
	if (!mapdata)
		return;
	ENetPacket *packet = enet_packet_create(NULL, MAXTRANS + mapsize, ENET_PACKET_FLAG_RELIABLE);
	uchar *start = packet->data;
	uchar *p = start + 2;
	putint(p, SV_SENDMAP);
	sendIString(mapname, p);
	putint(p, mapsize);
	if (65535 - (p - start) < mapsize) {
		conoutf("map %s is too large to send", mapname.c_str());
		free(mapdata);
		enet_packet_destroy(packet);
		return;
	};
	memcpy(p, mapdata, mapsize);
	p += mapsize;
	free(mapdata);
	*(ushort *) start = ENET_HOST_TO_NET_16(p - start);
	enet_packet_resize(packet, p - start);
	sendpackettoserv(packet);
	conoutf("sending map %s to server...", mapname.c_str());
	IString msg;
	std::sprintf(msg, "[map %s uploaded to server, \"getmap\" to receive it]", mapname.c_str());
	toserver(msg);
}
示例#4
0
WORLDPTR worldfactory::make_new_world()
{
    // Window variables
    const int iOffsetX = (TERMX > FULL_SCREEN_WIDTH) ? (TERMX - FULL_SCREEN_WIDTH) / 2 : 0;
    const int iOffsetY = (TERMY > FULL_SCREEN_HEIGHT) ? (TERMY - FULL_SCREEN_HEIGHT) / 2 : 0;
    // World to return after generating
    WORLDPTR retworld = new WORLD();
    // set up window
    WINDOW *wf_win = newwin(FULL_SCREEN_HEIGHT, FULL_SCREEN_WIDTH, iOffsetY, iOffsetX);
    // prepare tab display order
    std::vector<worldgen_display> tabs;
    std::vector<std::string> tab_strings;

    tabs.push_back(&worldfactory::show_worldgen_tab_options);
    tabs.push_back(&worldfactory::show_worldgen_tab_confirm);

    tab_strings.push_back(_("World Gen Options"));
    tab_strings.push_back(_("CONFIRMATION"));

    int curtab = 0;
    int lasttab; // give placement memory to menus, sorta.
    const int numtabs = tabs.size();
    while (curtab >= 0 && curtab < numtabs) {
        lasttab = curtab;
        draw_worldgen_tabs(wf_win, curtab, tab_strings);
        curtab += (world_generator->*tabs[curtab])(wf_win, retworld);

        if (curtab < 0) {
            if (!query_yn(_("Do you want to abort World Generation?"))) {
                curtab = lasttab;
            }
        }
    }
    if (curtab < 0) {
        delete retworld;
        return NULL;
    }

    // add world to world list
    all_worlds[retworld->world_name] = retworld;
    all_worldnames.push_back(retworld->world_name);

    std::stringstream path;
    path << SAVE_DIR << PATH_SEPARATOR << retworld->world_name;
    retworld->world_path = path.str();

    if (!save_world(retworld)) {
        std::string worldname = retworld->world_name;
        std::vector<std::string>::iterator it = std::find(all_worldnames.begin(), all_worldnames.end(), worldname);
        all_worldnames.erase(it);
        delete all_worlds[worldname];
        delete retworld;
        all_worlds.erase(worldname);
        return NULL;
    }
    return retworld;
}
示例#5
0
文件: act.c 项目: senlinms/C-RPG
int debug_save_world(Object * obj, Object * obj2)
{
	save_world(obj->world, "world.bin");
	gotoxy(0, 0);
	set_color(0, 15);
	printf("world saved");
	Sleep(1000);
	return 1;
}
示例#6
0
WORLDPTR worldfactory::make_new_world(special_game_id special_type)
{
    std::string worldname;
    switch(special_type) {
    case SGAME_TUTORIAL:
        worldname = "TUTORIAL";
        break;
    case SGAME_DEFENSE:
        worldname = "DEFENSE";
        break;
    default:
        return NULL;
    }

    // look through worlds and see if worlname exists already. if so then just return
    // it instead of making a new world
    if (all_worlds.find(worldname) != all_worlds.end()) {
        return all_worlds[worldname];
    }

    WORLDPTR special_world = new WORLD();
    special_world->world_name = worldname;

    if (special_world->world_options.size() == 0) {
        for (std::map<std::string, cOpt>::iterator it = OPTIONS.begin(); it != OPTIONS.end(); ++it) {
            if (it->second.getPage() == "world_default") {
                special_world->world_options[it->first] = it->second;
            }
        }
    }
    special_world->world_options["DELETE_WORLD"].setValue("yes");

    // add world to world list!
    all_worlds[worldname] = special_world;
    all_worldnames.push_back(worldname);

    std::stringstream path;
    path << SAVE_DIR << PATH_SEPARATOR << worldname;
    special_world->world_path = path.str();

    if (!save_world(special_world)) {
        std::vector<std::string>::iterator it = std::find(all_worldnames.begin(), all_worldnames.end(), worldname);
        all_worldnames.erase(it);
        delete all_worlds[worldname];
        delete special_world;
        all_worlds.erase(worldname);
        return NULL;
    }

    return special_world;
}
示例#7
0
WORLDPTR worldfactory::make_new_world(special_game_id special_type)
{
    std::string worldname;
    switch(special_type) {
    case SGAME_TUTORIAL:
        worldname = "TUTORIAL";
        break;
    case SGAME_DEFENSE:
        worldname = "DEFENSE";
        break;
    default:
        return NULL;
    }

    // Look through all worlds and see if a world named worldname already exists. If so, then just return it instead of
    // making a new world.
    if (all_worlds.find(worldname) != all_worlds.end()) {
        return all_worlds[worldname];
    }

    WORLDPTR special_world = new WORLD();
    special_world->world_name = worldname;

    special_world->world_options["DELETE_WORLD"].setValue("yes");

    // add world to world list!
    all_worlds[worldname] = special_world;
    all_worldnames.push_back(worldname);

    std::stringstream path;
    path << FILENAMES["savedir"] << worldname;
    special_world->world_path = path.str();

    if (!save_world(special_world)) {
        std::vector<std::string>::iterator it = std::find(all_worldnames.begin(), all_worldnames.end(),
                                                worldname);
        all_worldnames.erase(it);
        delete all_worlds[worldname];
        delete special_world;
        all_worlds.erase(worldname);
        return NULL;
    }

    return special_world;
}
示例#8
0
void MainWindow::load_world() {
    if(changed) {
        int ret = QMessageBox::warning(this, tr("Bugs"), tr("Save changes?"), QMessageBox::Save | QMessageBox::Discard | QMessageBox::Cancel, QMessageBox::Save);
        if(ret == QMessageBox::Cancel) return;
        else if(ret == QMessageBox::Save) save_world();
        else if(ret != QMessageBox::Discard) return; // in case of pressing escape
    }

    bool running = false;
    if(isRunning()) {
        stop();
        running = true;
    }

    QString fn = QFileDialog::getOpenFileName(this, tr("Open File"), "", tr("Bug data (*.bug)"));
    if(fn.isEmpty()) return;

    load_from_file(fn, running);

    if(running) start();
    else updt();
}
示例#9
0
void MainWindow::new_world() {
    if(changed) {
        int ret = QMessageBox::warning(this, tr("Bugs"), tr("Save changes?"), QMessageBox::Save | QMessageBox::Discard | QMessageBox::Cancel, QMessageBox::Save);
        if(ret == QMessageBox::Cancel) return;
        else if(ret == QMessageBox::Save) save_world();
        else if(ret != QMessageBox::Discard) return; // in case of pressing escape
    }

    bool was_running = false;
    if(isRunning()) {
        start_stop();
        was_running = true;
    }

    WorldParams newParams = settings->getParams();

    petri_dish.cleanup();
    petri_dish.init(newParams);
    petri_dish.balance();
    petri_dish.update_all_pixels();
    if(histogramDialog) histogramDialog->newData(petri_dish.get_dna_data(), petri_dish.get_population());

    totalEnergy->setText(QString().setNum(petri_dish.get_total_energy()));
    spinDNAVal->setMaximum(newParams.max_data);
    set_stats();
    changed = false;

    last_time = 0;
    update_time.restart();
    if(was_running) {
        start_stop();
    } else
        update();

    filename = "";
    actionAutoSave->setChecked(false);
}
示例#10
0
/*  Warm reboot stuff, gotta make sure to thank Erwin for this :) */
void do_hotboot( CHAR_DATA * ch, const char *argument )
{
   FILE *fp;
   CHAR_DATA *victim = NULL;
   DESCRIPTOR_DATA *d, *de_next;
   char buf[100], buf2[100], buf3[100];
   extern int control;
   int count = 0;
   bool found = FALSE;

   for( d = first_descriptor; d; d = d->next )
   {
      if( ( d->connected == CON_PLAYING
            || d->connected == CON_EDITING )
          && ( victim = d->character ) != NULL && !IS_NPC( victim )
          && victim->in_room && victim->fighting && victim->top_level >= 1 && victim->top_level <= MAX_LEVEL )
      {
         found = TRUE;
         count++;
      }
   }

   if( found )
   {
      ch_printf( ch, "Cannot hotboot at this time. There are %d combats in progress.\r\n", count );
      return;
   }

   found = FALSE;
   for( d = first_descriptor; d; d = d->next )
   {
      if( d->connected == CON_EDITING && d->character )
      {
         found = TRUE;
         break;
      }
   }

   if( found )
   {
      send_to_char( "Cannot hotboot at this time. Someone is using the line editor.\r\n", ch );
      return;
   }

   sprintf( log_buf, "Hotboot initiated by %s.", ch->name );
   log_string( log_buf );

   fp = fopen( HOTBOOT_FILE, "w" );

   if( !fp )
   {
      send_to_char( "Hotboot file not writeable, aborted.\r\n", ch );
      bug( "Could not write to hotboot file: %s. Hotboot aborted.", HOTBOOT_FILE );
      perror( "do_copyover:fopen" );
      return;
   }

   /*
    * And this one here will save the status of all objects and mobs in the game.
    * * This really should ONLY ever be used here. The less we do stuff like this the better.
    */
   save_world( ch );

#ifdef OLC_SHUTTLE
   {
      SHUTTLE_DATA *tshuttle;

      for( tshuttle = first_shuttle; tshuttle; tshuttle = tshuttle->next )
         save_shuttle( tshuttle );
   }
#endif

   log_string( "Saving player files and connection states...." );
   if( ch && ch->desc )
      write_to_descriptor( ch->desc, "\033[0m", 0 );
   sprintf( buf, "\r\nYou feel a great disturbance in the Force." );
   /*
    * For each playing descriptor, save its state 
    */
   for( d = first_descriptor; d; d = de_next )
   {
      CHAR_DATA *och = CH( d );

      de_next = d->next;   /* We delete from the list , so need to save this */
      if( !d->character || d->connected < CON_PLAYING )  /* drop those logging on */
      {
         write_to_descriptor( d, "\r\nSorry, we are rebooting. Come back in a few minutes.\r\n", 0 );
         close_socket( d, FALSE );  /* throw'em out */
      }
      else
      {
/* 			For test purposes
			flush_buffer(d, TRUE);*/
         fprintf( fp, "%d %d %d %d %d %s %s\n", d->can_compress, d->descriptor, och->in_room->vnum, d->port, d->idle, och->name, d->host );
         /*
          * One of two places this gets changed 
          */
         och->pcdata->hotboot = TRUE;
         save_char_obj( och );
         write_to_descriptor( d, buf, 0 );
         compressEnd( d );
      }
   }

   fprintf( fp, "%s", "-1" );
   FCLOSE( fp );

#ifdef IMC
   imc_hotboot(  );
#endif

   /*
    * added this in case there's a need to debug the contents of the various files 
    */
   if( argument && !str_cmp( argument, "debug" ) )
   {
      log_string( "Hotboot debug - Aborting before execl" );
      return;
   }

   log_string( "Executing hotboot...." );

   /*
    * exec - descriptors are inherited 
    */
   snprintf( buf, 100, "%d", port );
   snprintf( buf2, 100, "%d", control );
#ifdef IMC
   if( this_imcmud )
      snprintf( buf3, 100, "%d", this_imcmud->desc );
   else
      strncpy( buf3, "-1", 100 );
#else
   strncpy( buf3, "-1", 100 );
#endif

   dlclose( sysdata.dlHandle );
   execl( EXE_FILE, "swreality", buf, "hotboot", buf2, buf3, ( char * )NULL );

   /*
    * Failed - sucessful exec will not return 
    */
   perror( "do_hotboot: execl" );
   sysdata.dlHandle = dlopen( NULL, RTLD_LAZY );
   if( !sysdata.dlHandle )
   {
	bug( "%s", "FATAL ERROR: Unable to reopen system executable handle!" );
	exit( 1 );
   }
   bug( "%s", "Hotboot execution failed!!" );
   send_to_char( "Hotboot FAILED!\r\n", ch );
}
示例#11
0
文件: game.c 项目: AliceLR/megazeux
static boolean game_key(context *ctx, int *key)
{
  struct game_context *game = (struct game_context *)ctx;
  struct config_info *conf = get_config();
  struct world *mzx_world = ctx->world;
  struct board *cur_board = mzx_world->current_board;
  char keylbl[] = "KEY?";

  int key_status = get_key_status(keycode_internal_wrt_numlock, *key);
  boolean exit_status = get_exit_status();
  boolean confirm_exit = false;

  if(*key && !exit_status)
  {
    // Get the char for the KEY? labels. If there is no relevant unicode
    // keypress, we want to use the regular code instead.
    int key_unicode = get_key(keycode_unicode);
    int key_char = *key;

    if(key_unicode > 0 && key_unicode < 256)
      key_char = key_unicode;

    if(key_char)
    {
      if(key_char < 256)
      {
        // Send the KEY? label.
        // Values over 256 have no meaning here.
        keylbl[3] = key_char;
        send_robot_all_def(mzx_world, keylbl);
      }

      // In pre-port MZX versions key was a board counter
      if(mzx_world->version < VERSION_PORT)
      {
        char keych = toupper(key_char);
        // <2.60 it only supported 1-9 and A-Z
        // This is difficult to version check, so apply it to <2.62
        if(mzx_world->version >= V262 ||
         (keych >= 'A' && keych <= 'Z') ||
         (keych >= '1' && keych <= '9'))
        {
          cur_board->last_key = keych;
        }
      }
    }

    switch(*key)
    {
      case IKEY_F3:
      {
        // Save game
        if(!mzx_world->dead && player_can_save(mzx_world))
        {
          char save_game[MAX_PATH];
          strcpy(save_game, curr_sav);

          if(!new_file(mzx_world, save_ext, ".sav", save_game, "Save game", 1))
          {
            strcpy(curr_sav, save_game);
            save_world(mzx_world, curr_sav, true, MZX_VERSION);
          }
        }
        return true;
      }

      case IKEY_F4:
      {
        // ALT+F4 - do nothing.
        if(get_alt_status(keycode_internal))
          break;

        // Restore saved game
        if(mzx_world->version < V282 || get_counter(mzx_world, "LOAD_MENU", 0))
        {
          load_savegame_selection(game);
        }
        return true;
      }

      case IKEY_F5:
      case IKEY_INSERT:
      {
        // Change bomb type
        if(!mzx_world->dead)
          player_switch_bomb_type(mzx_world);

        return true;
      }

      // Toggle debug mode
      case IKEY_F6:
      {
        if(edit_world && mzx_world->editing)
          mzx_world->debug_mode = !(mzx_world->debug_mode);
        return true;
      }

      // Cheat
      case IKEY_F7:
      {
        if(game->allow_cheats || mzx_world->editing)
          player_cheat_give_all(mzx_world);

        return true;
      }

      // Cheat More
      case IKEY_F8:
      {
        if(game->allow_cheats || mzx_world->editing)
          player_cheat_zap(mzx_world);

        return true;
      }

      // Quick save
      case IKEY_F9:
      {
        if(!mzx_world->dead)
        {
          if(player_can_save(mzx_world))
            save_world(mzx_world, curr_sav, true, MZX_VERSION);
        }
        return true;
      }

      // Quick load saved game
      case IKEY_F10:
      {
        if(mzx_world->version < V282 || get_counter(mzx_world, "LOAD_MENU", 0))
        {
          struct stat file_info;

          if(!stat(curr_sav, &file_info))
            load_savegame(game, curr_sav);
        }
        return true;
      }

      case IKEY_F11:
      {
        if(mzx_world->editing)
        {
          // Breakpoint editor
          if(get_alt_status(keycode_internal))
          {
            if(debug_robot_config)
              debug_robot_config(mzx_world);
          }
          // Counter debugger
          else
          {
            if(debug_counters)
              debug_counters(ctx);
          }
        }
        return true;
      }

      case IKEY_RETURN:
      {
        send_robot_all_def(mzx_world, "KeyEnter");

        // Ignore if this isn't a fresh press
        if(key_status != 1)
          return true;

        if(mzx_world->version < V260 || get_counter(mzx_world, "ENTER_MENU", 0))
          game_menu(ctx);

        return true;
      }

      case IKEY_ESCAPE:
      {
        // Ignore if this isn't a fresh press
        // NOTE: disabled because it breaks the joystick action.
        //if(key_status != 1)
          //return true;

        // ESCAPE_MENU (2.90+)
        if(mzx_world->version < V290 || get_counter(mzx_world, "ESCAPE_MENU", 0))
          confirm_exit = true;

        break;
      }
    }
  }

  // Quit
  if(exit_status || confirm_exit)
  {
    // Special behaviour in standalone- only escape exits
    // ask for confirmation. Exit events instead terminate MegaZeux.
    if(conf->standalone_mode && !confirm_exit)
    {
      core_full_exit(ctx);
    }
    else
    {
      if(!confirm(mzx_world, "Quit playing- Are you sure?"))
        destroy_context(ctx);
    }
    return true;
  }

  return false;
}
示例#12
0
文件: game.c 项目: AliceLR/megazeux
static boolean game_idle(context *ctx)
{
  struct game_context *game = (struct game_context *)ctx;
  struct config_info *conf = get_config();
  struct world *mzx_world = ctx->world;

  if(!mzx_world->active)
    return false;

  if(game->fade_in)
  {
    vquick_fadein();
    game->fade_in = false;
  }

  switch(mzx_world->change_game_state)
  {
    case CHANGE_STATE_NONE:
      break;

    case CHANGE_STATE_SWAP_WORLD:
    {
      // The SWAP WORLD command was used by a robot.
      // TODO: the game has already been loaded at this point, but maybe
      // should be loaded here instead of in run_robot.c?

      // Load the new board's mod
      load_board_module(mzx_world);

      // Send both JUSTLOADED and JUSTENTERED; the JUSTENTERED label will take
      // priority if a robot defines it (instead of JUSTLOADED like on the title
      // screen).
      send_robot_def(mzx_world, 0, LABEL_JUSTLOADED);
      send_robot_def(mzx_world, 0, LABEL_JUSTENTERED);

      return true;
    }

    case CHANGE_STATE_LOAD_GAME_ROBOTIC:
    {
      // The LOAD_GAME counter was used by a robot.
      // TODO: the game has already been loaded at this point, but maybe
      // should be loaded here instead of in counter.c?

      // real_mod_playing was set during the savegame load but the mod hasn't
      // started playing yet.
      load_game_module(mzx_world, mzx_world->real_mod_playing, false);

      // Only send JUSTLOADED for savegames.
      send_robot_def(mzx_world, 0, LABEL_JUSTLOADED);

      return true;
    }

    case CHANGE_STATE_PLAY_GAME_ROBOTIC:
    {
      if(!game->is_title)
        break;

      if(load_world_gameplay(game, curr_file))
      {
        play_game(ctx, NULL);
        game->need_reload = true;
        return true;
      }
      break;
    }

    case CHANGE_STATE_EXIT_GAME_ROBOTIC:
    {
      // The EXIT_GAME counter was used by a robot. This works during gameplay,
      // but also on the titlescreen if standalone mode is active.
      if(!game->is_title || conf->standalone_mode)
      {
        destroy_context(ctx);
        return true;
      }
      break;
    }

    case CHANGE_STATE_REQUEST_EXIT:
    {
      // The user halted the program while a robot was executing.
      destroy_context(ctx);
      return true;
    }
  }

  // A board change or other form of teleport may need to occur.
  // This may require a fade in the next time this function is run (next cycle).
  if(update_resolve_target(mzx_world, &(game->fade_in)))
    return true;

  // The SAVE_GAME counter might have been used this cycle.
  if(!game->is_title && mzx_world->robotic_save_type == SAVE_GAME)
  {
    save_world(mzx_world, mzx_world->robotic_save_path, true, MZX_VERSION);
    mzx_world->robotic_save_type = SAVE_NONE;
  }

  return false;
}
void handle_keyboard_keys(unsigned char key ,int x ,int y)
{
    if(key == 27 || key == 'q')
    {
        save_world();
        exit(0);
    }
    if(key == 'z')
    {
        random_walk_mode = random_walk_mode?0:1;
    }
    if(key == 't')
    {
        light_transport_mode = light_transport_mode?0:1;
        update_timer = light_transport_mode?200:10;
    }
    if(key == 'g')
    {
        gaze_cursor_mode = gaze_cursor_mode?0:1;
    }
    if(key == 'p')
    {
        //Enter/Exit Play Game Mode
    }
    if(key == 'r')
    {
        rotate_object(-atan(rotat_val),-1,select_type,select_number);
    }
    if(key == 'l')
    {
        rotate_object(atan(rotat_val),1,select_type,select_number);
    }
    if(key == 'f')
    {
        trans_val += 0.2;
        rotat_val += 0.1;
    }
    if(key == 's')
    {
        trans_val -= 0.2;
        if(trans_val < 0.0)
            trans_val = 0.2;
        rotat_val -= 0.1;
        if(rotat_val < 0.0)
            rotat_val = 0.1;
    }
    if(key == 'b')
    {
        //Insert Block
    }
    if(key == 'm')
    {
        //Insert Mirror
    }
    if(key == 'o')
    {
        //Insert Projector
    }
    if(key == 'c')
    {
        if(select_type == PROJECTOR)
        {
            if(select_number == num_projectors-1 || num_projectors == 0)
            {
                select_number = 0;
                select_type = BLOCK;
            }
            else
                select_number++;
        }
        else if(select_type == BLOCK)
        {
            if(select_number == num_blocks-1 || num_blocks == 0)
            {
                select_number = 0;
                select_type = MIRROR;
            }
            else
                select_number++;
        }
        else
        {
            if(select_number == num_mirrors-1 || num_mirrors == 0)
            {
                select_number = 0;
                select_type = PROJECTOR;
            }
            else
                select_number++;
        }
    }
}
示例#14
0
MainWindow::MainWindow(QWidget *parent, Qt::WFlags flags): QMainWindow(parent, flags), petri_dish(),
    histogramDialog(0), changed(true), auto_save(false), update_thread(this, this)
{
    setupUi(this);

    connect(&timer, SIGNAL(timeout()), &petri_dish, SLOT(step()));
    connect(&petri_dish, SIGNAL(changed()), worldView, SLOT(queueUpdate()));
    //connect(&petri_dish, SIGNAL(changed()), worldView, SLOT(repaint()));
    connect(&petri_dish, SIGNAL(changed()), this, SLOT(set_stats()));
    connect(runButton, SIGNAL(clicked()), this, SLOT(start_stop()));
    //connect(checkIntegrity, SIGNAL(clicked()), this, SLOT(check_integrity()));
    connect(stepBtn, SIGNAL(clicked()), this, SLOT(step()));

    connect(radViewDefault, SIGNAL(clicked()), &petri_dish, SLOT(set_default_view_mode()));
    connect(radViewBugs, SIGNAL(clicked()), &petri_dish, SLOT(set_bugs_view_mode()));
    connect(radViewEnergy, SIGNAL(clicked()), &petri_dish, SLOT(set_energy_view_mode()));
    connect(radViewAge, SIGNAL(clicked()), &petri_dish, SLOT(set_age_view_mode()));
    connect(radViewSize, SIGNAL(clicked()), &petri_dish, SLOT(set_dna_size_view_mode()));
    connect(radViewDNA, SIGNAL(clicked()), &petri_dish, SLOT(set_dna_view_mode()));
    connect(radViewTerrain, SIGNAL(clicked()), &petri_dish, SLOT(set_terrain_view_mode()));

    connect(actionNew, SIGNAL(triggered()), this, SLOT(new_world()));
    connect(actionSave, SIGNAL(triggered()), this, SLOT(save_world()));
    connect(actionOpen, SIGNAL(triggered()), this, SLOT(load_world()));
    connect(actionSave_As, SIGNAL(triggered()), this, SLOT(save_as_world()));
    connect(settings, SIGNAL(settingsChanged()), this, SLOT(change_world()));
    connect(actionAutoSave, SIGNAL(triggered()), this, SLOT(autosave_world()));

    connect(actionCheck_Integrity, SIGNAL(triggered()), this, SLOT(check_integrity()));

    connect(worldView, SIGNAL(clicked(int, int)), this, SLOT(edit_bug(int, int)));

    connect(idleChk, SIGNAL(clicked(bool)), this, SLOT(enableIdleDetect(bool)));

    connect(&idleTimer, SIGNAL(timeout()), this, SLOT(checkIdle()));

    autosave_timer.setInterval(1000 * 60 * 2); // every two mins
    connect(&autosave_timer, SIGNAL(timeout()), this, SLOT(save_world()));

    petri_dish.set_widget(worldView);
    petri_dish.init(settings->getParams());
    totalEnergy->setText(QString().setNum(petri_dish.get_total_energy()));
    spinDNAVal->setMaximum(settings->getParams().max_data);
    set_stats();

    last_time = 0;
    update_time.start();
    updates_per_sec = 0;


    //update_thread.start();
    horizontalSlider->setValue(1000);
    timer.start(0);

    setAttribute(Qt::WA_QuitOnClose, true);

    repaint();

    if(!qApp->arguments().size() > 1) {
        bool running;
        load_from_file(qApp->arguments().at(1), running);

        if(running) start();
    }
}
示例#15
0
std::map<std::string, WORLDPTR> worldfactory::get_all_worlds()
{
    std::map<std::string, WORLDPTR> retworlds;

    std::vector<std::string> qualifiers;
    qualifiers.push_back(WORLD_OPTION_FILE);
    qualifiers.push_back(SAVE_MASTER);

    if (!all_worlds.empty()) {
        for( auto &elem : all_worlds ) {
            delete elem.second;
        }
        all_worlds.clear();
        all_worldnames.clear();
    }
    // get the master files. These determine the validity of a world
    // worlds exist by having an option file
    // create worlds
    for( const auto &world_dir : get_directories_with(qualifiers, FILENAMES["savedir"], true) ) {
        // get the option file again
        // we can assume that there is only one master.gsav, so just collect the first path
        bool no_options = true;
        auto const detected_world_op = get_files_from_path( WORLD_OPTION_FILE, world_dir, false );
        if ( ! detected_world_op.empty() ) {
            no_options = false;
        }
        // get the save files
        auto world_sav_files = get_files_from_path( SAVE_EXTENSION, world_dir, false );
        // split the save file names between the directory and the extension
        for( auto &world_sav_file : world_sav_files ) {
            size_t save_index = world_sav_file.find( SAVE_EXTENSION );
            world_sav_file = world_sav_file.substr( world_dir.size() + 1,
                                                    save_index - ( world_dir.size() + 1 ) );
        }
        // the directory name is the name of the world
        std::string worldname;
        unsigned name_index = world_dir.find_last_of( "/\\" );
        worldname = world_dir.substr( name_index + 1 );

        // create and store the world
        retworlds[worldname] = new WORLD();
        // give the world a name
        retworlds[worldname]->world_name = worldname;
        all_worldnames.push_back(worldname);
        // add sav files
        for( auto &world_sav_file : world_sav_files ) {
            retworlds[worldname]->world_saves.push_back( world_sav_file );
        }
        // set world path
        retworlds[worldname]->world_path = world_dir;
        mman->load_mods_list(retworlds[worldname]);

        // load options into the world
        if ( no_options ) {
            for( auto &elem : OPTIONS ) {
                if( elem.second.getPage() == "world_default" ) {
                    retworlds[worldname]->world_options[elem.first] = elem.second;
                }
            }
            retworlds[worldname]->world_options["DELETE_WORLD"].setValue("yes");
            save_world(retworlds[worldname]);
        } else {
            retworlds[worldname]->world_options = get_world_options(detected_world_op[0]);
        }
    }

    // check to see if there exists a worldname "save" which denotes that a world exists in the save
    // directory and not in a sub-world directory
    if (retworlds.find("save") != retworlds.end()) {
        WORLDPTR converted_world = convert_to_world(retworlds["save"]->world_path);
        if (converted_world) {
            converted_world->world_saves = retworlds["save"]->world_saves;
            converted_world->world_options = retworlds["save"]->world_options;

            std::vector<std::string>::iterator oldindex = std::find(all_worldnames.begin(),
                    all_worldnames.end(), "save");

            delete retworlds["save"];
            retworlds.erase("save");
            all_worldnames.erase(oldindex);

            retworlds[converted_world->world_name] = converted_world;
            all_worldnames.push_back(converted_world->world_name);
        }
    }
    all_worlds = retworlds;
    return retworlds;
}
示例#16
0
WORLDPTR worldfactory::make_new_world( bool show_prompt )
{
    // World to return after generating
    WORLDPTR retworld = new WORLD();
    if( show_prompt ) {
        // Window variables
        const int iOffsetX = (TERMX > FULL_SCREEN_WIDTH) ? (TERMX - FULL_SCREEN_WIDTH) / 2 : 0;
        const int iOffsetY = (TERMY > FULL_SCREEN_HEIGHT) ? (TERMY - FULL_SCREEN_HEIGHT) / 2 : 0;
        // set up window
        WINDOW *wf_win = newwin(FULL_SCREEN_HEIGHT, FULL_SCREEN_WIDTH, iOffsetY, iOffsetX);
        WINDOW_PTR wf_winptr( wf_win );

        int curtab = 0;
        int lasttab; // give placement memory to menus, sorta.
        const int numtabs = tabs.size();
        while (curtab >= 0 && curtab < numtabs) {
            lasttab = curtab;
            draw_worldgen_tabs(wf_win, curtab);
            curtab += (world_generator->*tabs[curtab])(wf_win, retworld);

            if (curtab < 0) {
                if (!query_yn(_("Do you want to abort World Generation?"))) {
                    curtab = lasttab;
                }
            }
        }
        if (curtab < 0) {
            delete retworld;
            return NULL;
        }
    } else { // 'Play NOW'
#ifndef LUA
        // Silently remove all Lua mods setted by default.
        std::vector<std::string>::iterator mod_it;
        for (mod_it = retworld->active_mod_order.begin(); mod_it != retworld->active_mod_order.end();) {
            MOD_INFORMATION *minfo = mman->mod_map[*mod_it];
            if ( minfo->need_lua ) {
                mod_it = retworld->active_mod_order.erase(mod_it);
            } else {
                mod_it++;
            }
        }
#endif
    }

    // add world to world list
    all_worlds[retworld->world_name] = retworld;
    all_worldnames.push_back(retworld->world_name);

    std::stringstream path;
    path << FILENAMES["savedir"] << retworld->world_name;
    retworld->world_path = path.str();
    //debugmsg("worldpath: %s", path.str().c_str());

    if (!save_world(retworld)) {
        std::string worldname = retworld->world_name;
        std::vector<std::string>::iterator it = std::find(all_worldnames.begin(), all_worldnames.end(),
                                                worldname);
        all_worldnames.erase(it);
        if (all_worlds[worldname] != retworld) {
            delete retworld;
        }
        delete all_worlds[worldname];
        all_worlds.erase(worldname);
        return NULL;
    }
    return retworld;
}
示例#17
0
std::map<std::string, WORLDPTR> worldfactory::get_all_worlds()
{
    std::map<std::string, WORLDPTR> retworlds;

    std::vector<std::string> qualifiers;
    qualifiers.push_back(WORLD_OPTION_FILE);
    qualifiers.push_back(SAVE_MASTER);

    if (all_worlds.size() > 0) {
        for (std::map<std::string, WORLDPTR>::iterator it = all_worlds.begin(); it != all_worlds.end(); ++it) {
            delete it->second;
        }
        all_worlds.clear();
        all_worldnames.clear();
    }
    // get the master files. These determine the validity of a world
    std::vector<std::string> world_dirs = file_finder::get_directories_with(qualifiers, SAVE_DIR, true);

    // check to see if there are >0 world directories found
    if (world_dirs.size() > 0) {
        // worlds exist by having an option file
        // create worlds
        for (unsigned i = 0; i < world_dirs.size(); ++i) {
            // get the option file again
            // we can assume that there is only one master.gsav, so just collect the first path
            bool no_options = true;
            std::vector<std::string> detected_world_op = file_finder::get_files_from_path(WORLD_OPTION_FILE, world_dirs[i], false);
            std::string world_op_file = WORLD_OPTION_FILE;
            if ( ! detected_world_op.empty() ) {
                no_options = false;
            }
            // get the save files
            std::vector<std::string> world_sav_files = file_finder::get_files_from_path(SAVE_EXTENSION, world_dirs[i], false);
            // split the save file names between the directory and the extension
            for (unsigned j = 0; j < world_sav_files.size(); ++j) {
                size_t save_index = world_sav_files[j].find(SAVE_EXTENSION);
                world_sav_files[j] = world_sav_files[j].substr(world_dirs[i].size() + 1, save_index - (world_dirs[i].size() + 1));
            }
            // the directory name is the name of the world
            std::string worldname;
            unsigned name_index = world_dirs[i].find_last_of("/\\");
            worldname = world_dirs[i].substr(name_index + 1);

            // create and store the world
            retworlds[worldname] = new WORLD();
            // give the world a name
            retworlds[worldname]->world_name = worldname;
            all_worldnames.push_back(worldname);
            // add sav files
            for (unsigned j = 0; j < world_sav_files.size(); ++j) {
                retworlds[worldname]->world_saves.push_back(world_sav_files[j]);
            }
            // set world path
            retworlds[worldname]->world_path = world_dirs[i];

            // load options into the world
            if ( no_options ) {
                for (std::map<std::string, cOpt>::iterator it = OPTIONS.begin(); it != OPTIONS.end(); ++it) {
                    if (it->second.getPage() == "world_default") {
                        retworlds[worldname]->world_options[it->first] = it->second;
                    }
                }
                retworlds[worldname]->world_options["DELETE_WORLD"].setValue("yes");
                save_world(retworlds[worldname]);
            } else {
                retworlds[worldname]->world_options = get_world_options(detected_world_op[0]);
            }
        }
    }
    // check to see if there exists a worldname "save" which denotes that a world exists in the save
    // directory and not in a sub-world directory
    if (retworlds.find("save") != retworlds.end()) {
        WORLDPTR converted_world = convert_to_world(retworlds["save"]->world_path);
        if (converted_world) {
            converted_world->world_saves = retworlds["save"]->world_saves;
            converted_world->world_options = retworlds["save"]->world_options;

            std::vector<std::string>::iterator oldindex = std::find(all_worldnames.begin(), all_worldnames.end(), "save");

            delete retworlds["save"];
            retworlds.erase("save");
            all_worldnames.erase(oldindex);

            retworlds[converted_world->world_name] = converted_world;
            all_worldnames.push_back(converted_world->world_name);
        }
    }
    all_worlds = retworlds;
    return retworlds;
}