Beispiel #1
0
void game::wishitem( player *p, int x, int y, int z)
{
    if ( p == NULL && x <= 0 ) {
        debugmsg("game::wishitem(): invalid parameters");
        return;
    }
    const std::vector<std::string> standard_itype_ids = item_controller->get_all_itype_ids();
    int prev_amount, amount = 1;
    uimenu wmenu;
    wmenu.w_x = 0;
    wmenu.w_width = TERMX;
    wmenu.pad_right = ( TERMX / 2 > 40 ? TERMX - 40 : TERMX / 2 );
    wmenu.return_invalid = true;
    wmenu.selected = uistate.wishitem_selected;
    wish_item_callback *cb = new wish_item_callback( standard_itype_ids );
    wmenu.callback = cb;

    for (size_t i = 0; i < standard_itype_ids.size(); i++) {
        item ity( standard_itype_ids[i], 0 );
        wmenu.addentry( i, true, 0, string_format(_("%s"), ity.tname(1, false).c_str()) );
        wmenu.entries[i].extratxt.txt = string_format("%c", ity.symbol());
        wmenu.entries[i].extratxt.color = ity.color();
        wmenu.entries[i].extratxt.left = 1;
    }
    do {
        wmenu.query();
        if ( wmenu.ret >= 0 ) {
            item granted(standard_itype_ids[wmenu.ret], calendar::turn);
            prev_amount = amount;
            if (p != NULL) {
                amount = std::atoi(
                             string_input_popup(_("How many?"), 20, to_string( amount ),
                                                granted.tname()).c_str());
            }
            if (dynamic_cast<wish_item_callback *>(wmenu.callback)->incontainer) {
                granted = granted.in_its_container();
            }
            if ( p != NULL ) {
                for (int i = 0; i < amount; i++) {
                    p->i_add(granted);
                }
                p->invalidate_crafting_inventory();
            } else if ( x >= 0 && y >= 0 ) {
                m.add_item_or_charges( tripoint( x, y, z ), granted);
                wmenu.keypress = 'q';
            }
            if ( amount > 0 ) {
                dynamic_cast<wish_item_callback *>(wmenu.callback)->msg =
                    _("Wish granted. Wish for more or hit 'q' to quit.");
            }
            uistate.wishitem_selected = wmenu.ret;
            if ( !amount ) {
                amount = prev_amount;
            }
        }
    } while ( wmenu.keypress != 'q' && wmenu.keypress != KEY_ESCAPE && wmenu.keypress != ' ' );
    delete wmenu.callback;
    wmenu.callback = NULL;
    return;
}
Beispiel #2
0
Eigen::SparseMatrix<Type> kronecker(Eigen::SparseMatrix<Type> x,
				    Eigen::SparseMatrix<Type> y){
  typedef Eigen::Triplet<Type> T;
  typedef typename Eigen::SparseMatrix<Type>::InnerIterator Iterator;
  std::vector<T> tripletList;
  int n1=x.rows(),n2=x.cols(),n3=y.rows(),n4=y.cols();
  int i,j,k,l;
  // Loop over nonzeros of x
  for (int cx=0; cx<x.outerSize(); cx++)
    for (Iterator itx(x,cx); itx; ++itx)
      // Loop over nonzeros of y
      for (int cy=0; cy<y.outerSize(); cy++)
  	for (Iterator ity(y,cy); ity; ++ity)
  	  {
  	    i=itx.row();
  	    j=itx.col();
  	    k=ity.row();
  	    l=ity.col();
  	    tripletList.push_back(T(i*n3+k,j*n4+l, itx.value()*ity.value() ));
   	  }
  Eigen::SparseMatrix<Type> mat(n1*n3,n2*n4);
  mat.setFromTriplets(tripletList.begin(), tripletList.end());
  return mat;
}
Beispiel #3
0
void debug_menu::wishitem( player *p, int x, int y, int z )
{
    if( p == NULL && x <= 0 ) {
        debugmsg( "game::wishitem(): invalid parameters" );
        return;
    }
    const auto opts = item_controller->all();

    int prev_amount, amount = 1;
    uimenu wmenu;
    wmenu.w_x = 0;
    wmenu.w_width = TERMX;
    wmenu.pad_right = ( TERMX / 2 > 40 ? TERMX - 40 : TERMX / 2 );
    wmenu.return_invalid = true;
    wmenu.selected = uistate.wishitem_selected;
    wish_item_callback cb( opts );
    wmenu.callback = &cb;

    for( size_t i = 0; i < opts.size(); i++ ) {
        item ity( opts[i], 0 );
        wmenu.addentry( i, true, 0, string_format( _( "%.*s" ), wmenu.pad_right - 5,
                        ity.tname( 1, false ).c_str() ) );
        wmenu.entries[i].extratxt.txt = ity.symbol();
        wmenu.entries[i].extratxt.color = ity.color();
        wmenu.entries[i].extratxt.left = 1;
    }

    do {
        wmenu.query();
        if( wmenu.ret >= 0 ) {
            item granted( opts[wmenu.ret] );
            prev_amount = amount;
            if( p != NULL ) {
                string_input_popup()
                .title( _( "How many?" ) )
                .width( 20 )
                .description( granted.tname() )
                .edit( amount );
            }
            if( dynamic_cast<wish_item_callback *>( wmenu.callback )->incontainer ) {
                granted = granted.in_its_container();
            }
            if( p != NULL ) {
                for( int i = 0; i < amount; i++ ) {
                    p->i_add( granted );
                }
                p->invalidate_crafting_inventory();
            } else if( x >= 0 && y >= 0 ) {
                g->m.add_item_or_charges( tripoint( x, y, z ), granted );
                wmenu.keypress = 'q';
            }
            if( amount > 0 ) {
                dynamic_cast<wish_item_callback *>( wmenu.callback )->msg =
                    _( "Wish granted. Wish for more or hit 'q' to quit." );
            }
            uistate.wishitem_selected = wmenu.ret;
            if( !amount ) {
                amount = prev_amount;
            }
        }
    } while( wmenu.keypress != 'q' && wmenu.keypress != KEY_ESCAPE && wmenu.keypress != ' ' );
}
Beispiel #4
0
void debug_menu::wishitem( player *p, int x, int y, int z )
{
    if( p == NULL && x <= 0 ) {
        debugmsg( "game::wishitem(): invalid parameters" );
        return;
    }
    const auto opts = item_controller->all();

    int prev_amount = 1;
    int amount = 1;
    uimenu wmenu;
    wmenu.w_x = 0;
    wmenu.w_width = TERMX;
    wmenu.pad_right = ( TERMX / 2 > 40 ? TERMX - 40 : TERMX / 2 );
    wmenu.return_invalid = true;
    wmenu.selected = uistate.wishitem_selected;
    wish_item_callback cb( opts );
    wmenu.callback = &cb;

    for( size_t i = 0; i < opts.size(); i++ ) {
        item ity( opts[i], 0 );
        wmenu.addentry( i, true, 0, string_format( _( "%.*s" ), wmenu.pad_right - 5,
                        ity.tname( 1, false ).c_str() ) );
        wmenu.entries[i].extratxt.txt = ity.symbol();
        wmenu.entries[i].extratxt.color = ity.color();
        wmenu.entries[i].extratxt.left = 1;
    }

    do {
        wmenu.query();
        if( wmenu.ret >= 0 ) {
            item granted( opts[wmenu.ret] );
            if( cb.incontainer ) {
                granted = granted.in_its_container();
            }
            if( cb.has_flag ) {
                granted.item_tags.insert( cb.flag );
            }
            prev_amount = amount;
            bool canceled = false;
            if( p != NULL ) {
                string_input_popup popup;
                popup
                .title( _( "How many?" ) )
                .width( 20 )
                .description( granted.tname() )
                .edit( amount );
                canceled = popup.canceled();
            }
            if( !canceled ) {
                if( p != NULL ) {
                    for( int i = 0; i < amount; i++ ) {
                        p->i_add( granted );
                    }
                    p->invalidate_crafting_inventory();
                } else if( x >= 0 && y >= 0 ) {
                    g->m.add_item_or_charges( tripoint( x, y, z ), granted );
                    wmenu.ret = -1;
                }
                if( amount > 0 ) {
                    input_context ctxt( "UIMENU" );
                    cb.msg = string_format( _( "Wish granted. Wish for more or hit [%s] to quit." ),
                                            ctxt.get_desc( "QUIT" ).c_str() );
                }
            }
            uistate.wishitem_selected = wmenu.ret;
            if( canceled || amount <= 0 ) {
                amount = prev_amount;
            }
        }
    } while( wmenu.ret >= 0 );
}
Beispiel #5
0
// synchronize all in todir, current packages are 'nodes'
void BrowserNode::synchronize(QDir & todir, Q3Dict<BrowserNode> & nodes)
{
    static Q3Dict<void> useful(9973);	// all useful files
    static bool made_useful = TRUE;	// set at the first call

    // compare nodes with young packages

    Q3DictIterator<BrowserNode> ity(Youngs);

    for (; ity.current(); ++ity) {
        BrowserNode * from = ity.current();
        BrowserNode * curr_bn = nodes.find(ity.currentKey());

        if ((curr_bn == 0) || (curr_bn->state == Old)) {
            // don't exist or must be updated
            if (made_useful)
                useful.insert(ity.currentKey(), (void *) 1);

            QDir & fromdir = from->view->get_dir();

            // copy package file
            copy(fromdir, todir, from->filename);

            // copy diagrams files
            QStringList::Iterator its;
            QStringList & diags = from->diagrams;

            if (made_useful) {
                for (its = diags.begin(); its != diags.end(); ++its) {
                    copy_if_needed(fromdir, todir, *its);
                    useful.insert(*its, (void *) 1);
                }
            }
            else
                for (its = diags.begin(); its != diags.end(); ++its)
                    copy_if_needed(fromdir, todir, *its);

            // copy class body files
            QStringList & cls = from->classes;

            if (made_useful) {
                for (its = cls.begin(); its != cls.end(); ++its) {
                    copy_if_needed(fromdir, todir, *its);
                    useful.insert(*its, (void *) 1);
                }
            }
            else
                for (its = cls.begin(); its != cls.end(); ++its)
                    copy_if_needed(fromdir, todir, *its);

            if (from->parent() == 0) {
                // project, special files
                copy_if_needed(fromdir, todir, "cpp_includes");
                copy_if_needed(fromdir, todir, "idl_includes");
                copy_if_needed(fromdir, todir, "java_imports");
                copy_if_needed(fromdir, todir, "generation_settings");
                copy_if_needed(fromdir, todir, "import");
                copy_if_needed(fromdir, todir, "include");
                copy_if_needed(fromdir, todir, "stereotypes");
                copy_if_needed(fromdir, todir, "tools");
            }
        }
        else if (made_useful)
            // young, memorize packages, diagrams and classes body file
            from->memo(useful);
    }

    if (made_useful) {
        // memorize up to date packages, diagrams and classes body file
        Q3DictIterator<BrowserNode> itn(nodes);

        for (; itn.current(); ++itn)
            if (itn.current()->state == UpToDate)
                itn.current()->memo(useful);

        made_useful = FALSE;
    }

    // remove files associated to deleted elements
    purge(todir, useful);
}