Esempio n. 1
0
int soul_create(soul_t *creature, char *name, char *desc, char p_class, int lvl)
{
	tools("clear", NULL);
	//unsigned long pass;
	char plaintext[64];

	if(name == NULL)
	{
		printf(" Name: ");
		fgets(creature->name, sizeof(creature->name), stdin);	// set p->name to input data.
		creature->name[strcspn(creature->name, "\n")] = 0;	// remove trailing '\n'
		if(!file_exists(creature->name))
		{
			if(PASSWD) {
				printf(" Password: "******" Description: ");
			fgets(creature->desc, sizeof(creature->desc), stdin);	//set p->desc to input data.
			creature->desc[strcspn(creature->desc, "\n")] = 0;	// removetrailing '\n'

			creature->speed = 3.5;	// Generate player speed
			creature->luck = 25;		// Set player's initial luck.
			creature->type = 'p';		// Set player's type. ( p = player, m = mob )
			creature->gold = 500.00;	// Set base gold value player owns.

			class_create(creature, 0, 1);	// Call on selectings the player's class.

			printf("\n Player name: %s\n Description: %s\n  Health: %d\n  Damage: %d\n  Speed: %.1f",
					creature->name, creature->desc, creature->hp, creature->dmg, creature->speed);
			printf(" Primary Skill:\n   %s, %.1f \n", creature->skill->name, creature->skill->val);

			item_init(&creature->objs.bandaid, "Bandage",  25);	// Give player bandages.

			save(creature);		// Save the player.
			getchar();
			tools("pause", NULL);
		} else
			load_profile(creature);	
	} else
	{
		strncpy(creature->name, name, sizeof(creature->name));	// Changed from strcpy (safer now)
		strncpy(creature->desc, desc, sizeof(creature->desc));	// Same as above.
		creature->speed = 4.5;	// Set speed.
		creature->type = 'm';				// Set type to mob ( m = mob )
		creature->gold = (250.00 * ((float)lvl / 2));				// Gold being held.

		
		item_init(&creature->objs.bandaid, "Bandage",  0);	// No bandages for the NPC!

		class_create(creature, p_class, lvl);			// Assign the class.
	}


	return 0;
}
void UIToolsView::sltFocusChanged()
{
    /* Make sure focus-item set: */
    const UIToolsItem *pFocusItem = tools() && tools()->model()
                                    ? tools()->model()->focusItem()
                                    : 0;
    if (!pFocusItem)
        return;

    const QSize viewSize = viewport()->size();
    QRectF geo = pFocusItem->geometry();
    geo &= QRectF(geo.topLeft(), viewSize);
    ensureVisible(geo, 0, 0);
}
bool ImageRotate::rotate(const QString& src, RotateAction angle, QString& err, bool updateFileTimeStamp)
{
    QFileInfo fi(src);

    if (!fi.exists() || !fi.isReadable() || !fi.isWritable()) 
    {
        err = i18n("Error in opening input file");
        return false;
    }

    m_tmpFile.setSuffix("kipiplugin-rotate." + fi.suffix());

    if ( !m_tmpFile.open() )
    {
        err = i18n("Error in opening temporary file");
        return false;
    }

    QString tmp = m_tmpFile.fileName();

//Workaround to close the file
#ifdef _WIN32
    static_cast<QFSFileEngine*>(m_tmpFile.fileEngine())->rename(tmp);
#endif

    if (Utils::isRAW(src))
    {
        err = i18n("Cannot rotate RAW file");
        return false;
    }
    else if (Utils::isJPEG(src))
    {
        if (!rotateJPEG(src, tmp, angle, err, updateFileTimeStamp))
        {
            if (err == "nothing to do") { err.clear(); return true; }
            return false;
        }
    }
    else
    {
        // B.K.O #123499 : we using Image Magick API here instead QT API 
        // else TIFF/PNG 16 bits image are broken!
        if (!rotateImageMagick(src, tmp, angle, err))
            return false;

        // We update metadata on new image.
        Utils tools(this);
        if (!tools.updateMetadataImageMagick(tmp, err))
            return false;
    }

    // Move back to original file
    if (!Utils::moveOneFile(tmp, src))
    {
        err = i18n("Cannot update source image");
        return false;
    }

    return true;
}
Esempio n. 4
0
Pass::Status PassManager::Run(IRContext* context) {
  auto status = Pass::Status::SuccessWithoutChange;

  // If print_all_stream_ is not null, prints the disassembly of the module
  // to that stream, with the given preamble and optionally the pass name.
  auto print_disassembly = [&context, this](const char* preamble, Pass* pass) {
    if (print_all_stream_) {
      std::vector<uint32_t> binary;
      context->module()->ToBinary(&binary, false);
      SpirvTools t(SPV_ENV_UNIVERSAL_1_2);
      std::string disassembly;
      t.Disassemble(binary, &disassembly, 0);
      *print_all_stream_ << preamble << (pass ? pass->name() : "") << "\n"
                         << disassembly << std::endl;
    }
  };

  SPIRV_TIMER_DESCRIPTION(time_report_stream_, /* measure_mem_usage = */ true);
  for (auto& pass : passes_) {
    print_disassembly("; IR before pass ", pass.get());
    SPIRV_TIMER_SCOPED(time_report_stream_, (pass ? pass->name() : ""), true);
    const auto one_status = pass->Run(context);
    if (one_status == Pass::Status::Failure) return one_status;
    if (one_status == Pass::Status::SuccessWithChange) status = one_status;

    if (validate_after_all_) {
      spvtools::SpirvTools tools(target_env_);
      tools.SetMessageConsumer(consumer());
      std::vector<uint32_t> binary;
      context->module()->ToBinary(&binary, true);
      if (!tools.Validate(binary.data(), binary.size(), val_options_)) {
        std::string msg = "Validation failed after pass ";
        msg += pass->name();
        spv_position_t null_pos{0, 0, 0};
        consumer()(SPV_MSG_INTERNAL_ERROR, "", null_pos, msg.c_str());
        return Pass::Status::Failure;
      }
    }

    // Reset the pass to free any memory used by the pass.
    pass.reset(nullptr);
  }
  print_disassembly("; IR after last pass", nullptr);

  // Set the Id bound in the header in case a pass forgot to do so.
  //
  // TODO(dnovillo): This should be unnecessary and automatically maintained by
  // the IRContext.
  if (status == Pass::Status::SuccessWithChange) {
    context->module()->SetIdBound(context->module()->ComputeIdBound());
  }
  passes_.clear();
  return status;
}
bool Editor::importBitmapImage( QString filePath )
{
    backup( tr( "ImportImg" ) );
    qDebug(filePath.toLatin1().data());
    QImageReader reader( filePath );

    Q_ASSERT( layers()->currentLayer()->type() == Layer::BITMAP );
    auto layer = static_cast<LayerBitmap*>( layers()->currentLayer() );

    QImage img;//( reader.size(), QImage::Format_ARGB32_Premultiplied );
    img.load(filePath);
    while ( reader.read( &img ) )
    {/*
        if ( img.isNull() || reader.nextImageDelay() <= 0 )
        {
            qDebug("why not image");
            break;
        }*/

        if ( !layer->keyExists( currentFrame() ) )
        {
            qDebug("why not imagesadfsdaf ssd");
            addNewKey();
        }


        BitmapImage* bitmapImage = layer->getBitmapImageAtFrame( currentFrame() );

        QRect boundaries = img.rect();

        boundaries.moveTopLeft( mScribbleArea->getCentralPoint().toPoint() - QPoint( boundaries.width() / 2, boundaries.height() / 2 ) );
        BitmapImage* importedBitmapImage = new BitmapImage( boundaries, img );
        bitmapImage->paste( importedBitmapImage );

      if(layers()->currentLayerIndex()>2)
      {
        //下面用来框出倒入的图片
        mScribbleArea->mySelection.moveTopLeft(mScribbleArea->getCentralPoint().toPoint() - QPoint( boundaries.width()/1.5, boundaries.height()/1.5) );//这个是为了将值赋给QRectF
        mScribbleArea->mySelection.moveBottomRight(mScribbleArea->getCentralPoint().toPoint() + QPoint( boundaries.width()/1.5, boundaries.height()/1.5));
        mScribbleArea->mySelection.setTopLeft(mScribbleArea->getCentralPoint().toPoint() - QPoint( boundaries.width()/1.5, boundaries.height()/1.5));
        mScribbleArea->mySelection.setBottomRight(mScribbleArea->getCentralPoint().toPoint() + QPoint( boundaries.width()/1.5, boundaries.height()/1.5));
        //mScribbleArea->mySelection.moveBottomRight(QPoint( boundaries.width()/2, boundaries.height()/2));
        mScribbleArea->setSelection( mScribbleArea->mySelection, true );
        mScribbleArea->myTransformedSelection = mScribbleArea->mySelection.adjusted( 0, 0, 0, 0 );
        mScribbleArea->myTempTransformedSelection = mScribbleArea->mySelection.adjusted( 0, 0, 0, 0 );
        mScribbleArea->update();
        mScribbleArea->mIncludeImg[mLayerManager->currentLayerIndex()]=mScribbleArea->mySelection;
        tools()->setCurrentTool(MOVE);
       }
       // scrubTo( currentFrame() + 1 );
    }

    return true;
}
void Editor::paste()
{
    if((cutFlag||copyFlag)&&layers()->currentLayerIndex()>2)
    {
        newBitmapLayer();
    }
    Layer* layer = mObject->getLayer( layers()->currentLayerIndex() );
    if ( layer != NULL )
    {
        if ( layer->type() == Layer::BITMAP && g_clipboardBitmapImage.image() != NULL )
        {
            backup( tr( "Paste" ) );
            BitmapImage tobePasted = g_clipboardBitmapImage.copy();
            qDebug() << "to be pasted --->" << tobePasted.image()->size();
            if ( mScribbleArea->somethingSelected )
            {
                QRectF selection = mScribbleArea->getSelection();
                if ( g_clipboardBitmapImage.width() <= selection.width() && g_clipboardBitmapImage.height() <= selection.height() )
                {
                    tobePasted.moveTopLeft( selection.topLeft() );
                }
                else
                {
                    tobePasted.transform( selection, true );
                }
            }
            auto pLayerBitmap = static_cast< LayerBitmap* >( layer );
            pLayerBitmap->getLastBitmapImageAtFrame( currentFrame(), 0 )->paste( &tobePasted ); // paste the clipboard
        }
        else if ( layer->type() == Layer::VECTOR && clipboardVectorOk )
        {
            backup( tr( "Paste" ) );
            mScribbleArea->deselectAll();
            VectorImage* vectorImage = ( ( LayerVector* )layer )->getLastVectorImageAtFrame( currentFrame(), 0 );
            vectorImage->paste( g_clipboardVectorImage );  // paste the clipboard
            mScribbleArea->setSelection( vectorImage->getSelectionRect(), true );
            //((LayerVector*)layer)->getLastVectorImageAtFrame(backupFrame, 0)->modification(); ????
        }
    }
    mScribbleArea->updateCurrentFrame();
    if((cutFlag&&!mScribbleArea->somethingSelected)||(copyFlag&&mScribbleArea->somethingSelected))
    {
        mScribbleArea->mySelection=cutArea;
        mScribbleArea->setSelection( mScribbleArea->mySelection, true );
        mScribbleArea->myTransformedSelection = mScribbleArea->mySelection.adjusted( 0, 0, 0, 0 );
        mScribbleArea->myTempTransformedSelection = mScribbleArea->mySelection.adjusted( 0, 0, 0, 0 );
        mScribbleArea->update();
        mScribbleArea->mIncludeImg[mLayerManager->currentLayerIndex()]=mScribbleArea->mySelection;
        tools()->setCurrentTool(MOVE);
    }
    cutFlag =0;
    copyFlag =0;
}
Esempio n. 7
0
bool Editor::initialize( ScribbleArea* pScribbleArea )
{
    mScribbleArea = pScribbleArea;

    // Initialize managers
    mColorManager = new ColorManager( this );
    mLayerManager = new LayerManager( this );
    mToolManager = new ToolManager( this );
    mPlaybackManager = new PlaybackManager( this );
    mViewManager = new ViewManager( this );
    BaseManager* allManagers[] =
    {
        mColorManager,
        mToolManager,
        mLayerManager,
        mPlaybackManager,
        mViewManager
    };

    for ( BaseManager* pManager : allManagers )
    {
        pManager->setEditor( this );
        pManager->init();
    }

    mFrame = 1;
    layers()->setCurrentLayer( 0 );

    tools()->setCurrentTool( PENCIL );
    mScribbleArea->setCursor( tools()->currentTool()->cursor() );

    //setAcceptDrops( true ); // TODO: drop event

    // CONNECTIONS
    makeConnections();

    return true;
}
Esempio n. 8
0
        void FTSSpec::scoreDocument( const BSONObj& obj, TermFrequencyMap* term_freqs ) const {
            if ( _textIndexVersion == TEXT_INDEX_VERSION_1 ) {
                return _scoreDocumentV1( obj, term_freqs );
            }

            FTSElementIterator it( *this, obj );

            while ( it.more() ) {
                FTSIteratorValue val = it.next();
                Stemmer stemmer( *val._language );
                Tools tools( *val._language, &stemmer, StopWords::getStopWords( *val._language ) );
                _scoreStringV2( tools, val._text, term_freqs, val._weight );
            }
        }
Esempio n. 9
0
bool ImageGrayScale::image2GrayScale(const QString& src, QString& err, bool updateFileTimeStamp)
{
    QFileInfo fi(src);

    if (!fi.exists() || !fi.isReadable() || !fi.isWritable()) 
    {
        err = i18n("Error in opening input file");
        return false;
    }

    if ( !m_tmpFile.open() )
    {
        err = i18n("Error in opening temporary file");
        return false;
    }

    QString tmp = m_tmpFile.fileName();

    if (Utils::isRAW(src))
    {
        err = i18n("Cannot convert to gray scale RAW file");
        return false;
    }
    else if (Utils::isJPEG(src))
    {
        if (!image2GrayScaleJPEG(src, tmp, err, updateFileTimeStamp))
            return false;
    }
    else
    {
        // B.K.O #123499 : using Image Magick API here instead QT API 
        // else RAW/TIFF/PNG 16 bits image are broken!
        if (!image2GrayScaleImageMagick(src, tmp, err))
            return false;

        // We update metadata on new image.
        Utils tools(this);
        if (!tools.updateMetadataImageMagick(tmp, err))
            return false;
    }

    // Move back to original file
    if (!Utils::MoveFile(tmp, src)) 
    {
        err = i18n("Cannot update source image");
        return false;
    }

    return true;
}
Esempio n. 10
0
File: buffer.c Progetto: 0x1p2/rpg-c
void bprintf(soul_t *ptr)
{
	while(buf->u == 0)
		;
	tools("clear", NULL);
	XY(15, 0);
	// printf(" THIS IS A STOP FOR THE MENU \n");	// Shows where buffer will end.
	XY(0, 0);
	menus(ptr, 1);
	menus(ptr->o, 1);
	printf("- - - - - - - - - - - - - - - - - - - - - - - - - - - - -\n");
	for(int n = 0; n < STRINGS; n++)
	{
		if(buf->s[n] != NULL)
			printf(" %s \n", buf->s[n]);
	}
	printf("- - - - - - - - - - - - - - - - - - - - - - - - - - - - -\n");
	buf->u = 0;
	menus(ptr, 2);
	menus(ptr->o, 2);
}
Esempio n. 11
0
int WidgetAnnotTools::qt_metacall(QMetaObject::Call _c, int _id, void **_a)
{
    _id = QWidget::qt_metacall(_c, _id, _a);
    if (_id < 0)
        return _id;
    if (_c == QMetaObject::InvokeMetaMethod) {
        if (_id < 7)
            qt_static_metacall(this, _c, _id, _a);
        _id -= 7;
    }
#ifndef QT_NO_PROPERTIES
      else if (_c == QMetaObject::ReadProperty) {
        void *_v = _a[0];
        switch (_id) {
        case 0: *reinterpret_cast< QStringList*>(_v) = tools(); break;
        }
        _id -= 1;
    } else if (_c == QMetaObject::WriteProperty) {
        void *_v = _a[0];
        switch (_id) {
        case 0: setTools(*reinterpret_cast< QStringList*>(_v)); break;
        }
        _id -= 1;
    } else if (_c == QMetaObject::ResetProperty) {
        _id -= 1;
    } else if (_c == QMetaObject::QueryPropertyDesignable) {
        _id -= 1;
    } else if (_c == QMetaObject::QueryPropertyScriptable) {
        _id -= 1;
    } else if (_c == QMetaObject::QueryPropertyStored) {
        _id -= 1;
    } else if (_c == QMetaObject::QueryPropertyEditable) {
        _id -= 1;
    } else if (_c == QMetaObject::QueryPropertyUser) {
        _id -= 1;
    }
#endif // QT_NO_PROPERTIES
    return _id;
}
Esempio n. 12
0
void Editor::flipY()
{
    tools()->setCurrentTool( MOVE );
    mScribbleArea->myFlipY = -mScribbleArea->myFlipY;
}
Esempio n. 13
0
 void operator[]( Expr &expr ) const {
   std::shared_ptr< softdsp::llvm_toolbox< typename function_decl::function_type > > tools(
     new softdsp::llvm_toolbox< typename function_decl::function_type >( llvm_context, ( std::string( "00sd" )+typeid( function_decl ).name() ).c_str() )
   );
   softdsp_context< typename function_decl::function_type > context( tools );
   llvm_module->getFunctionList().push_back( tools->llvm_function );
   const auto result = boost::proto::eval( expr, context );
   result.value->getType()->dump();
   tools->ir_builder.CreateRet(
     tools->as_llvm_value(
       tools->load( result )
     ).value
   );
 }
Esempio n. 14
0
void FTSSpec::scoreDocument( const BSONObj& obj,
                             const FTSLanguage& parentLanguage,
                             const string& parentPath,
                             bool isArray,
                             TermFrequencyMap* term_freqs ) const {

    if ( _textIndexVersion == TEXT_INDEX_VERSION_1 ) {
        dassert( parentPath == "" );
        dassert( !isArray );
        return _scoreDocumentV1( obj, term_freqs );
    }

    const FTSLanguage& language = _getLanguageToUseV2( obj, parentLanguage );
    Stemmer stemmer( language );
    Tools tools( language, &stemmer, StopWords::getStopWords( language ) );

    // Perform a depth-first traversal of obj, skipping fields not touched by this spec.
    BSONObjIterator j( obj );
    while ( j.more() ) {

        BSONElement elem = j.next();
        string fieldName = elem.fieldName();

        // Skip "language" specifier fields if wildcard.
        if ( wildcard() && languageOverrideField() == fieldName ) {
            continue;
        }

        // Compose the dotted name of the current field:
        // 1. parent path empty (top level): use the current field name
        // 2. parent path non-empty and obj is an array: use the parent path
        // 3. parent path non-empty and obj is a sub-doc: append field name to parent path
        string dottedName = ( parentPath.empty() ? fieldName
                              : isArray ? parentPath
                              : parentPath + '.' + fieldName );

        // Find lower bound of dottedName in _weights.  lower_bound leaves us at the first
        // weight that could possibly match or be a prefix of dottedName.  And if this
        // element fails to match, then no subsequent weight can match, since the weights
        // are lexicographically ordered.
        Weights::const_iterator i = _weights.lower_bound( elem.type() == Object
                                    ? dottedName + '.'
                                    : dottedName );

        // possibleWeightMatch is set if the weight map contains either a match or some item
        // lexicographically larger than fieldName.  This boolean acts as a guard on
        // dereferences of iterator 'i'.
        bool possibleWeightMatch = ( i != _weights.end() );

        // Optimize away two cases, when not wildcard:
        // 1. lower_bound seeks to end(): no prefix match possible
        // 2. lower_bound seeks to a name which is not a prefix
        if ( !wildcard() ) {
            if ( !possibleWeightMatch ) {
                continue;
            }
            else if ( !_matchPrefix( dottedName, i->first ) ) {
                continue;
            }
        }

        // Is the current field an exact match on a weight?
        bool exactMatch = ( possibleWeightMatch && i->first == dottedName );

        double weight = ( possibleWeightMatch ? i->second : DEFAULT_WEIGHT );

        switch ( elem.type() ) {
        case String:
            // Only index strings on exact match or wildcard.
            if ( exactMatch || wildcard() ) {
                _scoreStringV2( tools, elem.valuestr(), term_freqs, weight );
            }
            break;
        case Object:
            // Only descend into a sub-document on proper prefix or wildcard.  Note that
            // !exactMatch is a sufficient test for proper prefix match, because of
            // matchPrefix() continue block above.
            if ( !exactMatch || wildcard() ) {
                scoreDocument( elem.Obj(), language, dottedName, false, term_freqs );
            }
            break;
        case Array:
            // Only descend into arrays from non-array parents or on wildcard.
            if ( !isArray || wildcard() ) {
                scoreDocument( elem.Obj(), language, dottedName, true, term_freqs );
            }
            break;
        default:
            // Skip over all other BSON types.
            break;
        }
    }
}
Esempio n. 15
0
void game::craft()
{
 if (u.morale_level() < MIN_MORALE_CRAFT) {	// See morale.h
  add_msg("Your morale is too low to craft...");
  return;
 }
 WINDOW *w_head = newwin( 3, 80, 0, 0);
 WINDOW *w_data = newwin(22, 80, 3, 0);
 craft_cat tab = CC_WEAPON;
 std::vector<recipe*> current;
 std::vector<bool> available;
 item tmp;
 int line = 0, xpos, ypos;
 bool redraw = true;
 bool done = false;
 char ch;

 inventory crafting_inv;
 crafting_inv.form_from_map(this, point(u.posx, u.posy), PICKUP_RANGE);
 crafting_inv += u.inv;
 crafting_inv += u.weapon;
 if (u.has_bionic(bio_tools)) {
  item tools(itypes[itm_toolset], turn);
  tools.charges = u.power_level;
  crafting_inv += tools;
 }

 do {
  if (redraw) { // When we switch tabs, redraw the header
   redraw = false;
   line = 0;
   draw_recipe_tabs(w_head, tab);
   current.clear();
   available.clear();
// Set current to all recipes in the current tab; available are possible to make
   pick_recipes(current, available, tab);
  }

// Clear the screen of recipe data, and draw it anew
  werase(w_data);
   mvwprintz(w_data, 20, 0, c_white, "\
Press ? to describe object.  Press <ENTER> to attempt to craft object.");
  wrefresh(w_data);
  for (int i = 0; i < current.size() && i < 23; i++) {
   if (i == line)
    mvwprintz(w_data, i, 0, (available[i] ? h_white : h_dkgray),
              itypes[current[i]->result]->name.c_str());
   else
    mvwprintz(w_data, i, 0, (available[i] ? c_white : c_dkgray),
              itypes[current[i]->result]->name.c_str());
  }
  if (current.size() > 0) {
   nc_color col = (available[line] ? c_white : c_dkgray);
   mvwprintz(w_data, 0, 30, col, "Primary skill: %s",
             (current[line]->sk_primary == sk_null ? "N/A" :
              skill_name(current[line]->sk_primary).c_str()));
   mvwprintz(w_data, 1, 30, col, "Secondary skill: %s",
             (current[line]->sk_secondary == sk_null ? "N/A" :
              skill_name(current[line]->sk_secondary).c_str()));
   mvwprintz(w_data, 2, 30, col, "Difficulty: %d", current[line]->difficulty);
   if (current[line]->sk_primary == sk_null)
    mvwprintz(w_data, 3, 30, col, "Your skill level: N/A");
   else
    mvwprintz(w_data, 3, 30, col, "Your skill level: %d",
              u.sklevel[current[line]->sk_primary]);
   if (current[line]->time >= 1000)
    mvwprintz(w_data, 4, 30, col, "Time to complete: %d minutes",
              int(current[line]->time / 1000));
   else
    mvwprintz(w_data, 4, 30, col, "Time to complete: %d turns",
              int(current[line]->time / 100));
   mvwprintz(w_data, 5, 30, col, "Tools required:");
   if (current[line]->tools[0].size() == 0) {
    mvwputch(w_data, 6, 30, col, '>');
    mvwprintz(w_data, 6, 32, c_green, "NONE");
    ypos = 6;
   } else {
    ypos = 5;
// Loop to print the required tools
    for (int i = 0; i < 5 && current[line]->tools[i].size() > 0; i++) {
     ypos++;
     xpos = 32;
     mvwputch(w_data, ypos, 30, col, '>');

     for (int j = 0; j < current[line]->tools[i].size(); j++) {
      itype_id type = current[line]->tools[i][j].type;
      int charges = current[line]->tools[i][j].count;
      nc_color toolcol = c_red;

      if (charges < 0 && crafting_inv.has_amount(type, 1))
       toolcol = c_green;
      else if (charges > 0 && crafting_inv.has_charges(type, charges))
       toolcol = c_green;

      std::stringstream toolinfo;
      toolinfo << itypes[type]->name + " ";
      if (charges > 0)
       toolinfo << "(" << charges << " charges) ";
      std::string toolname = toolinfo.str();
      if (xpos + toolname.length() >= 80) {
       xpos = 32;
       ypos++;
      }
      mvwprintz(w_data, ypos, xpos, toolcol, toolname.c_str());
      xpos += toolname.length();
      if (j < current[line]->tools[i].size() - 1) {
       if (xpos >= 77) {
        xpos = 32;
        ypos++;
       }
       mvwprintz(w_data, ypos, xpos, c_white, "OR ");
       xpos += 3;
      }
     }
    }
   }
 // Loop to print the required components
   ypos++;
   mvwprintz(w_data, ypos, 30, col, "Components required:");
   for (int i = 0; i < 5; i++) {
    if (current[line]->components[i].size() > 0) {
     ypos++;
     mvwputch(w_data, ypos, 30, col, '>');
    }
    xpos = 32;
    for (int j = 0; j < current[line]->components[i].size(); j++) {
     int count = current[line]->components[i][j].count;
     itype_id type = current[line]->components[i][j].type;
     nc_color compcol = c_red;
     if (itypes[type]->count_by_charges() && count > 0)  {
      if (crafting_inv.has_charges(type, count))
       compcol = c_green;
     } else if (crafting_inv.has_amount(type, abs(count)))
      compcol = c_green;
     std::stringstream dump;
     dump << abs(count) << "x " << itypes[type]->name << " ";
     std::string compname = dump.str();
     if (xpos + compname.length() >= 80) {
      ypos++;
      xpos = 32;
     }
     mvwprintz(w_data, ypos, xpos, compcol, compname.c_str());
     xpos += compname.length();
     if (j < current[line]->components[i].size() - 1) {
      if (xpos >= 77) {
       ypos++;
       xpos = 32;
      }
      mvwprintz(w_data, ypos, xpos, c_white, "OR ");
      xpos += 3;
     }
    }
   }
  }

  wrefresh(w_data);
  ch = input();
  switch (ch) {
  case '<':
   if (tab == CC_WEAPON)
    tab = CC_MISC;
   else
    tab = craft_cat(int(tab) - 1);
   redraw = true;
   break;
  case '>':
   if (tab == CC_MISC)
    tab = CC_WEAPON;
   else
    tab = craft_cat(int(tab) + 1);
   redraw = true;
   break;
  case 'j':
   line++;
   break;
  case 'k':
   line--;
   break;
  case '\n':
   if (!available[line])
    popup("You can't do that!");
   else if (itypes[current[line]->result]->m1 == LIQUID &&
            !u.has_watertight_container())
    popup("You don't have anything to store that liquid in!");
   else {
    make_craft(current[line]);
    done = true;
   }
   break;
  case '?':
   tmp = item(itypes[current[line]->result], 0);
   full_screen_popup(tmp.info(true).c_str());
   redraw = true;
   break;
  }
  if (line < 0)
   line = current.size() - 1;
  else if (line >= current.size())
   line = 0;
 } while (ch != KEY_ESCAPE && ch != 'q' && ch != 'Q' && !done);

 werase(w_head);
 werase(w_data);
 delwin(w_head);
 delwin(w_data);
 refresh_all();
}
Esempio n. 16
0
int class_create(soul_t *p, char p_class, int lvl)
{
	char opt;	// "Option" for switch statement.
	byte lpctr;	// While variable to be changed to break.

	lpctr = 0;	// 1 will break the while loop.
	opt = p_class;

	tools("clear", NULL);

	while(!lpctr)
	{	
		if(opt != 'a' && opt != 'm' && opt != 'w')
		{
			fflush(stdout);
			printf("[%s, %s]\n", p->name, p->desc);
			printf(" Choose a class: \n\n");
			printf("  [A]rcher\n  [M]age\n  [W]arrior\n\n Option [a/m/w]: ");
			opt = getchar();
			opt = tolower(opt);
		}

		p->objs.arrow.amount = 0;
		p->objs.reagent.amount = 0;

		switch(opt)
		{
			case 'a':	// Archer
				p->stats.dexterity = 13 * lvl;
				p->stats.wisdom = 6 * lvl;
				p->stats.strength = 6 * lvl;
				p->stats.range = 2;
				p->stats.cls = 'a';	// Class = Archer
				p->stats.p = 'd';	// Primary stat (dexterity)
				p->stats.s = 's';	// Secondary stat (strength)
				p->stats.t = 'w';	// Tertiary stat (wisdom)

				//p->attr.pri = &p->attr.dexterity;
				//p->attr.sec = &p->attr.strength;	// Used for stat_gain
				//p->attr.ter = &p->attr.wisdom;
				
				p->skill = &p->bucket.archery;
				strncpy(p->skill->name, "Archery", 7);
				p->skill->val = 50.0;
				

				item_init(&p->objs.arrow, "Arrow", 250);
				p->consumable = &p->objs.arrow;

				lpctr = 1;		// To break out of while.
				break;

			case 'm':	// Mage
				p->stats.dexterity = 5 * lvl;
				p->stats.wisdom = 13 * lvl;
				p->stats.strength = 7 * lvl;
				p->stats.range = 1;
				p->stats.cls = 'm';	// Class = Mage
				p->stats.p = 'w';	// Primary stat (wisdom)
				p->stats.s = 'd';	// Secondary stat (dexterity)
				p->stats.t = 's';	// Tertiary stat (strength)

				//p->attr.pri = &p->attr.wisdom;
				//p->attr.sec = &p->attr.dexterity;	// Used for stat_gain
				//p->attr.ter = &p->attr.strength;

				p->skill = &p->bucket.magery;
				strncpy(p->skill->name, "Magery", 6);
				p->skill->val = 50.0;

				item_init(&p->objs.reagent, "Reagent", 250);
				p->consumable = &p->objs.reagent;

				lpctr = 1;		// To break out of while.
				break;

			case 'w':	// Warrior
				p->stats.dexterity = 7 * lvl;
				p->stats.wisdom = 3 * lvl;
				p->stats.strength = 15 * lvl;
				p->stats.range = 0;
				p->stats.cls = 'w';	// Class = Warrior
				p->stats.p = 's';	// Primary stat (strength)
				p->stats.s = 'd';	// Secondary stat (dexterity)
				p->stats.t = 'w';	// Tertiary stat (wisdom)

				//p->attr.pri = &p->attr.strength;
				//p->attr.sec = &p->attr.dexterity;	// Used for stat_gain
				//p->attr.ter = &p->attr.wisdom;

				p->skill = &p->bucket.fencing;
				strncpy(p->skill->name, "Fencing", 7);
				p->skill->val = 50.0;

				item_init(&p->objs.null, "NULL", 0);
				p->consumable = &p->objs.null;

				lpctr = 1;		// To break out of while.
				break;

			default:
				printf("An error occured: [%c] is not a valid option.\n", opt);
				tools("pause", NULL);
				break;
		}

		p->hp = ((p->stats.strength * 3) + 50);
		p->hp_c = p->hp;
		p->stats.p_lck = 0;	// Set primary skill unlocked (allows stat gain.)
		p->stats.s_lck = 0;	// Set secondary skill unlocked.
		p->stats.t_lck = 0;	// Set tertiary skill unlocked.
	}
	
	tools("clear", NULL);
	return 0;
}
Esempio n. 17
0
void game::pick_recipes(std::vector<recipe*> &current,
                        std::vector<bool> &available, craft_cat tab)
{
 inventory crafting_inv;
 crafting_inv.form_from_map(this, point(u.posx, u.posy), PICKUP_RANGE);
 crafting_inv += u.inv;
 crafting_inv += u.weapon;
 if (u.has_bionic(bio_tools)) {
  item tools(itypes[itm_toolset], turn);
  tools.charges = u.power_level;
  crafting_inv += tools;
 }

 bool have_tool[5], have_comp[5];

 current.clear();
 available.clear();
 for (int i = 0; i < recipes.size(); i++) {
// Check if the category matches the tab, and we have the requisite skills
  if (recipes[i]->category == tab &&
      (recipes[i]->sk_primary == sk_null ||
       u.sklevel[recipes[i]->sk_primary] >= recipes[i]->difficulty) &&
      (recipes[i]->sk_secondary == sk_null ||
       u.sklevel[recipes[i]->sk_secondary] > 0))
  current.push_back(recipes[i]);
  available.push_back(false);
 }
 for (int i = 0; i < current.size() && i < 22; i++) {
//Check if we have the requisite tools and components
  for (int j = 0; j < 5; j++) {
   have_tool[j] = false;
   have_comp[j] = false;
   if (current[i]->tools[j].size() == 0)
    have_tool[j] = true;
   else {
    for (int k = 0; k < current[i]->tools[j].size(); k++) {
     itype_id type = current[i]->tools[j][k].type;
     int req = current[i]->tools[j][k].count;	// -1 => 1
     if ((req <= 0 && crafting_inv.has_amount (type,   1)) ||
         (req >  0 && crafting_inv.has_charges(type, req))   ) {
      have_tool[j] = true;
      k = current[i]->tools[j].size();
     }
    }
   }
   if (current[i]->components[j].size() == 0)
    have_comp[j] = true;
   else {
    for (int k = 0; k < current[i]->components[j].size() && !have_comp[j]; k++){
     itype_id type = current[i]->components[j][k].type;
     int count = current[i]->components[j][k].count;
     if (itypes[type]->count_by_charges() && count > 0) {
      if (crafting_inv.has_charges(type, count)) {
       have_comp[j] = true;
       k = current[i]->components[j].size();
      }
     } else if (crafting_inv.has_amount(type, abs(count))) {
      have_comp[j] = true;
      k = current[i]->components[j].size();
     }
    }
   }
  }
  if (have_tool[0] && have_tool[1] && have_tool[2] && have_tool[3] &&
      have_tool[4] && have_comp[0] && have_comp[1] && have_comp[2] &&
      have_comp[3] && have_comp[4])
   available[i] = true;
 }
}
Esempio n. 18
0
void game::construction_menu()
{
 WINDOW *w_con = newwin(25, 80, 0, 0);
 wborder(w_con, LINE_XOXO, LINE_XOXO, LINE_OXOX, LINE_OXOX,
                LINE_OXXO, LINE_OOXX, LINE_XXOO, LINE_XOOX );
 mvwprintz(w_con, 0, 1, c_red, _("Construction"));
 mvwputch(w_con,  0, 30, c_white, LINE_OXXX);
 mvwputch(w_con, 24, 30, c_white, LINE_XXOX);
 for (int i = 1; i < 24; i++)
  mvwputch(w_con, i, 30, c_white, LINE_XOXO);

 mvwprintz(w_con,  1, 31, c_white, _("Difficulty:"));

 wrefresh(w_con);

 bool update_info = true;
 int select = 0;
 char ch;

 inventory total_inv;
 total_inv.form_from_map(this, point(u.posx, u.posy), PICKUP_RANGE);
 total_inv.add_stack(u.inv_dump());
 if (u.has_bionic(bio_tools)) {
  item tools(itypes[itm_toolset], turn);
  tools.charges = u.power_level;
  total_inv += tools;
 }

 do {
// Determine where in the master list to start printing
  int offset = select - 11;
  if (offset > constructions.size() - 22)
   offset = constructions.size() - 22;
  if (offset < 0)
   offset = 0;
// Print the constructions between offset and max (or how many will fit)
  for (int i = 0; i < 22 && i + offset < constructions.size(); i++) {
   int current = i + offset;
   nc_color col = (player_can_build(u, total_inv, constructions[current], 0) ?
                   c_white : c_dkgray);
   if (current == select)
    col = hilite(col);
   mvwprintz(w_con, 1 + i, 1, col, constructions[current]->name.c_str());
  }

  if (update_info) {
   update_info = false;
   constructable* current_con = constructions[select];
// Print difficulty
   int pskill = u.sklevel[sk_carpentry], diff = current_con->difficulty;
   mvwprintz(w_con, 1, 43, (pskill >= diff ? c_white : c_red),
             "%d   ", diff);
// Clear out lines for tools & materials
   for (int i = 2; i < 24; i++) {
    for (int j = 31; j < 79; j++)
     mvwputch(w_con, i, j, c_black, 'x');
   }

// Print stages and their requirements
   int posx = 33, posy = 2;
   for (int n = 0; n < current_con->stages.size(); n++) {
    nc_color color_stage = (player_can_build(u, total_inv, current_con, n) ?
                            c_white : c_dkgray);
    mvwprintz(w_con, posy, 31, color_stage, _("Stage %d: %s"), n + 1,
              terlist[current_con->stages[n].terrain].name.c_str());
    posy++;
// Print tools
    construction_stage stage = current_con->stages[n];
    bool has_tool[3] = {stage.tools[0].empty(),
                        stage.tools[1].empty(),
                        stage.tools[2].empty()};
    for (int i = 0; i < 3 && !has_tool[i]; i++) {
     posy++;
     posx = 33;
     for (int j = 0; j < stage.tools[i].size(); j++) {
      itype_id tool = stage.tools[i][j];
      nc_color col = c_red;
      if (total_inv.has_amount(tool, 1)) {
       has_tool[i] = true;
       col = c_green;
      }
      int length = itypes[tool]->name.length();
      if (posx + length > 79) {
       posy++;
       posx = 33;
      }
      mvwprintz(w_con, posy, posx, col, itypes[tool]->name.c_str());
      posx += length + 1; // + 1 for an empty space
      if (j < stage.tools[i].size() - 1) { // "OR" if there's more
       if (posx > 77) {
        posy++;
        posx = 33;
       }
       mvwprintz(w_con, posy, posx, c_white, _("OR"));
       posx += 3;
      }
     }
    }
// Print components
    posy++;
    posx = 33;
    bool has_component[3] = {stage.components[0].empty(),
                             stage.components[1].empty(),
                             stage.components[2].empty()};
    for (int i = 0; i < 3; i++) {
     posx = 33;
     while (has_component[i])
      i++;
     for (int j = 0; j < stage.components[i].size() && i < 3; j++) {
      nc_color col = c_red;
      component comp = stage.components[i][j];
      if (( itypes[comp.type]->is_ammo() &&
           total_inv.has_charges(comp.type, comp.count)) ||
          (!itypes[comp.type]->is_ammo() &&
           total_inv.has_amount(comp.type, comp.count))) {
       has_component[i] = true;
       col = c_green;
      }
      int length = itypes[comp.type]->name.length();
      if (posx + length > 79) {
       posy++;
       posx = 33;
      }
      mvwprintz(w_con, posy, posx, col, "%s x%d",
                itypes[comp.type]->name.c_str(), comp.count);
      posx += length + 3; // + 2 for " x", + 1 for an empty space
// Add more space for the length of the count
      if (comp.count < 10)
       posx++;
      else if (comp.count < 100)
       posx += 2;
      else
       posx += 3;

      if (j < stage.components[i].size() - 1) { // "OR" if there's more
       if (posx > 77) {
        posy++;
        posx = 33;
       }
       mvwprintz(w_con, posy, posx, c_white, _("OR"));
       posx += 3;
      }
     }
     posy++;
    }
   }
   wrefresh(w_con);
  } // Finished updating
 
  ch = input();
  switch (ch) {
   case 'j':
    update_info = true;
    if (select < constructions.size() - 1)
     select++;
    else
     select = 0;
    break;
   case 'k':
    update_info = true;
    if (select > 0)
     select--;
    else
     select = constructions.size() - 1;
    break;
   case '\n':
   case 'l':
    if (player_can_build(u, total_inv, constructions[select], 0)) {
     place_construction(constructions[select]);
     ch = 'q';
    } else {
     popup(_("You can't build that!"));
     for (int i = 1; i < 24; i++)
      mvwputch(w_con, i, 30, c_white, LINE_XOXO);
     update_info = true;
    }
    break;
  }
 } while (ch != 'q' && ch != 'Q' && ch != KEY_ESCAPE);
 refresh_all();
}
Esempio n. 19
0
void game::construction_menu()
{
 if (u.morale_level() < MIN_MORALE_CRAFT) {	// See morale.h
  add_msg("Your morale is too low to construct...");
  return;
 }
 WINDOW *w_con = newwin(25, 80, 0, 0);
 wborder(w_con, LINE_XOXO, LINE_XOXO, LINE_OXOX, LINE_OXOX,
                LINE_OXXO, LINE_OOXX, LINE_XXOO, LINE_XOOX );
 mvwprintz(w_con, 0,  1, c_yellow, "Construction");
 mvwprintz(w_con, 0, 31, c_yellow, "Your carpentry skill: %d.%s%d",
            u.sklevel[sk_carpentry], ((u.skexercise[sk_carpentry] < 10 ||
            u.skexercise[sk_carpentry] == 0) ? "0" : ""),
            (u.skexercise[sk_carpentry] < 0 ? 0 : u.skexercise[sk_carpentry]));
 mvwputch(w_con,  0, 30, c_white, LINE_OXXX);
 mvwputch(w_con, 24, 30, c_white, LINE_XXOX);
 for (int i = 1; i < 24; i++)
  mvwputch(w_con, i, 30, c_white, LINE_XOXO);

 wrefresh(w_con);

 bool update_info = true;
 int select = 0;
 char ch;

 inventory total_inv;
 total_inv.form_from_map(this, point(u.posx, u.posy), PICKUP_RANGE);
 total_inv.add_stack(u.inv_dump());
 if (u.has_bionic(bio_tools)) {
  item tools(itypes[itm_toolset], turn);
  tools.charges = u.power_level;
  total_inv += tools;
 }

 do {
// Erase existing list of constructions
  for (int i = 1; i < 24; i++) {
   for (int j = 1; j < 29; j++)
    mvwputch(w_con, i, j, c_black, 'x');
  }
// Determine where in the master list to start printing
  int offset = select - 11;
//  if (offset > constructions.size() - 22) // acts weird with this
//   offset = constructions.size() - 22;
  if (offset <= 0) {
   offset = 0;
   mvwputch(w_con, 1, 0, c_dkgray, LINE_XOXO);
  } else
   mvwputch(w_con, 1, 0, h_white, '^');
  if (constructions.size() - offset > 23)
   mvwputch(w_con, 23, 0, h_white, 'v');
  else
   mvwputch(w_con, 23, 0, c_dkgray, LINE_XOXO);
// Print the constructions between offset and max (or how many will fit)
  for (int i = 0; i < 23 && i + offset < constructions.size(); i++) {
   int current = i + offset;
   nc_color col = (player_can_build(u, total_inv, constructions[current]) ?
                   c_white : c_dkgray);
   if (current == select)
    col = hilite(col);
   mvwprintz(w_con, 1 + i, 1, col, constructions[current]->name.c_str());
  }

  if (update_info) {
   update_info = false;
   constructable* current_con = constructions[select];
// Clear out lines for tools & materials
   int posx = 31, posy = 0;
   for (int i = posy + 1; i < 24; i++) {
    for (int j = posx; j < 79; j++)
     mvwputch(w_con, i, j, c_black, 'x');
   }

// Print stages and their requirements
   for (int n = 0; n < current_con->stages.size(); n++) {
    posx = 31;
    posy++;
    nc_color color_stage = (player_can_build(u, total_inv,
                             current_con, n, true) ? c_white : c_dkgray);
// Print stage number and resulting terrain type
    posy++;
    if (current_con->stages[n].terrain == t_null)
     mvwprintz(w_con, posy, posx, color_stage, "Stage %d", n + 1);
    else
     mvwprintz(w_con, posy, posx, color_stage, "Stage %d: %s", n + 1,
               terlist[current_con->stages[n].terrain].name.c_str());
// Print difficulty
    if (current_con->stages[n].difficulty > 0){
     posy++;
     int pskill = u.sklevel[sk_carpentry],
         diff = current_con->stages[n].difficulty;
     mvwprintz(w_con, posy, posx, color_stage, "Difficulty:");
     mvwprintz(w_con, posy, posx + 12, (pskill >= diff ? c_green : c_red),
                "%d", diff);
    }
// Print time (in minutes)
    posy++;
    mvwprintz(w_con, posy, posx, color_stage, "Time to complete: %d minutes",
               current_con->stages[n].time);
// Print tools
    construction_stage stage = current_con->stages[n];
    bool has_tool[3] = {stage.tools[0].empty(),
                        stage.tools[1].empty(),
                        stage.tools[2].empty()};
    for (int i = 0; i < 3 && !has_tool[i]; i++) {
     posy++;
     posx = 33;
     mvwputch(w_con, posy, posx - 2, color_stage, '>');
     for (int j = 0; j < stage.tools[i].size(); j++) {
      itype_id tool = stage.tools[i][j];
      nc_color col = c_red;
      if (total_inv.has_amount(tool, 1)) {
       has_tool[i] = true;
       col = c_green;
      }
      int length = itypes[tool]->name.length();
      if (posx + length > 79) {
       posy++;
       posx = 33;
      }
      mvwprintz(w_con, posy, posx, col, itypes[tool]->name.c_str());
      posx += length + 1; // + 1 for an empty space
      if (j < stage.tools[i].size() - 1) { // "OR" if there's more
       if (posx > 77) {
        posy++;
        posx = 33;
       }
       mvwprintz(w_con, posy, posx, c_white, "OR");
       posx += 3;
      }
     }
    }
// Print components
    bool has_component[3] = {stage.components[0].empty(),
                             stage.components[1].empty(),
                             stage.components[2].empty()};
    for (int i = 0; i < 3; i++) {
     posx = 33;
     while (has_component[i])
      i++;
     for (int j = 0; j < stage.components[i].size() && i < 3; j++) {
      nc_color col = c_red;
      component comp = stage.components[i][j];
      if (( itypes[comp.type]->is_ammo() &&
           total_inv.has_charges(comp.type, comp.count)) ||
          (!itypes[comp.type]->is_ammo() &&
           total_inv.has_amount(comp.type, comp.count))) {
       has_component[i] = true;
       col = c_green;
      }
      int length = itypes[comp.type]->name.length();
      if (posx + length > 79) {
       posy++;
       posx = 33;
      }
      posy++;
      mvwputch(w_con, posy, posx - 2, color_stage, '>');
      mvwprintz(w_con, posy, posx, col, "%dx %s",
                comp.count, itypes[comp.type]->name.c_str());
      posx += length + 3; // + 2 for "x ", + 1 for an empty space
// Add more space for the length of the count
      if (comp.count < 10)
       posx++;
      else if (comp.count < 100)
       posx += 2;
      else
       posx += 3;

      if (j < stage.components[i].size() - 1) { // "OR" if there's more
       if (posx > 77) {
        posy++;
        posx = 33;
       }
       mvwprintz(w_con, posy, posx, c_white, "OR");
       posx += 3;
      }
     }
    }
   }
   wrefresh(w_con);
  } // Finished updating
 
  ch = input();
  switch (ch) {
   case 'j':
    update_info = true;
    select++;
    if (select >= constructions.size())
     select = 0;
    break;
   case 'k':
    update_info = true;
    select--;
    if (select < 0)
     select = constructions.size() - 1;
    break;
   case '\n':
   case 'l':
    if (player_can_build(u, total_inv, constructions[select])) {
     place_construction(constructions[select]);
     ch = 'q';
    } else {
     popup("You can't build that!");
     for (int i = 1; i < 24; i++)
      mvwputch(w_con, i, 30, c_white, LINE_XOXO);
     update_info = true;
    }
    break;
  }
 } while (ch != 'q' && ch != 'Q' && ch != KEY_ESCAPE);
 refresh_all();
}