Beispiel #1
0
 const string
 buildTypeID()
 {
   string typeID (typeid(TY).name());
   normaliseID (typeID);
   return typeID;
 }
bool InventoryItem::Merge(InventoryItemRef to_merge, int32 qty, bool notify) {
    if(typeID() != to_merge->typeID()) {
        _log(ITEM__ERROR, "%s (%u): Asked to merge with %s (%u).", itemName().c_str(), itemID(), to_merge->itemName().c_str(), to_merge->itemID());
        return false;
    }
    if(locationID() != to_merge->locationID() || flag() != to_merge->flag()) {
        _log(ITEM__ERROR, "%s (%u) in location %u, flag %u: Asked to merge with item %u in location %u, flag %u.", itemName().c_str(), itemID(), locationID(), flag(), to_merge->itemID(), to_merge->locationID(), to_merge->flag());
        return false;
    }
    if(qty == 0)
        qty = to_merge->quantity();
    if(qty <= 0) {
        _log(ITEM__ERROR, "%s (%u): Asked to merge with %d units of item %u.", itemName().c_str(), itemID(), qty, to_merge->itemID());
        return false;
    }
    if(!AlterQuantity(qty, notify)) {
        _log(ITEM__ERROR, "%s (%u): Failed to add quantity %d.", itemName().c_str(), itemID(), qty);
        return false;
    }

    if(qty == to_merge->quantity()) {
        to_merge->Delete();
    } else if(!to_merge->AlterQuantity(-qty, notify)) {
        _log(ITEM__ERROR, "%s (%u): Failed to remove quantity %d.", to_merge->itemName().c_str(), to_merge->itemID(), qty);
        return false;
    }

    return true;
}
Beispiel #3
0
 Complex Block::operator()(size_t idx)const{
   try{
     if(!(idx < elemNum())){
       std::ostringstream err;
       err<<"Index exceeds the number of elements("<<elemNum()<<").";
       throw std::runtime_error(exception_msg(err.str()));
     }
     if(typeID() == 0 || typeID() == 1){
       std::ostringstream err;
       err<<"This matrix is EMPTY or REAL. If it's REAL, please use operator[] instead of operator().";
       throw std::runtime_error(exception_msg(err.str()));
     }
     if(typeID() == 2)
       return getElemAt(idx, cm_elem, ongpu), 0;
   }
   catch(const std::exception& e){
     propogate_exception(e, "In function Block::operator()(size_t):");
   }
   return Complex();
 };
Beispiel #4
0
void Matrix::setElem(const Complex* elem, bool src_ongpu){
  try{
    if(typeID() == 1){
      r_flag = RNULL;
      c_flag = CTYPE;
      init(CTYPE, ongpu);
    }
    elemCopy(cm_elem, elem, Rnum, Cnum, ongpu, src_ongpu, diag);
  }
  catch(const std::exception& e){
    propogate_exception(e, "In function Matrix::setElem(const Complex*, bool=false):");
  }
}
Beispiel #5
0
void Matrix::setElem(const Real* elem, bool src_ongpu){
  try{
    if(typeID() == 2){
      r_flag = RTYPE;
      c_flag = CNULL;
      init(RTYPE, ongpu);
    }
    elemCopy(m_elem, elem, elemNum() * sizeof(Real), ongpu, src_ongpu);
  }
  catch(const std::exception& e){
    propogate_exception(e, "In function Matrix::setElem(const double*, bool=false):");
  }
}
Beispiel #6
0
 Complex* Block::getElem(cflag tp)const{
   checkUni10TypeError(tp);
   try{
     if(typeID() == 1){
       std::ostringstream err;
       err<<"This matrix is REAL. Please use getElem() or getElem(uni10::rflag ) instead.";
       throw std::runtime_error(exception_msg(err.str()));
     }
     return cm_elem;
   }
   catch(const std::exception& e){
     propogate_exception(e, "In function Block::getElem(uni10::cflag ):");
   }
   return cm_elem;
 }
Beispiel #7
0
 Real Block::norm(cflag tp)const{
   try{
     checkUni10TypeError(tp);
     if(typeID() == 0){
       std::ostringstream err;
       err<<"This matirx is empty" << std::endl << "In the file Block.cpp, line(" << __LINE__ << ")";
       throw std::runtime_error(exception_msg(err.str()));
     }
     return vectorNorm(cm_elem, elemNum(), 1, ongpu);
   }
   catch(const std::exception& e){
     propogate_exception(e, "In function Matrix::norm(uni10::cflag ):");
   }
   return 0;
 }
void InventoryItem::GetItemRow( PyPackedRow* into ) const
{
    into->SetField( "itemID",     new PyLong( itemID() ) );
    into->SetField( "typeID",     new PyInt( typeID() ) );
    into->SetField( "ownerID",    new PyInt( ownerID() ) );
    into->SetField( "locationID", new PyLong( locationID() ) );
    into->SetField( "flagID",     new PyInt( flag() ) );
    into->SetField( "quantity",   new PyInt( singleton() ? -1 : quantity()) );
    into->SetField( "groupID",    new PyInt( groupID() ) );
    into->SetField( "categoryID", new PyInt( categoryID() ) );
    into->SetField( "customInfo", new PyString( customInfo() ) );

    //into->SetField( "singleton",  new PyBool( singleton() ) );
    //into->SetField( "stacksize",  new PyInt (quantity()) );
}
Beispiel #9
0
 Real* Block::getElem(rflag tp)const{
   throwTypeError(tp);
   try{
     if(typeID() == 2){
       std::ostringstream err;
       err<<"This matrix is COMPLEX. Please use getElem(uni10::cflag ) instead.";
       throw std::runtime_error(exception_msg(err.str()));
     }
     return m_elem;
   }
   catch(const std::exception& e){
     propogate_exception(e, "In function Block::getElem(uni10::rflag ):");
   }
   return m_elem;
 }
Beispiel #10
0
void InventoryItem::SaveItem()
{
    //_log( ITEM__TRACE, "Saving item %u.", itemID() );

    SaveAttributes();

    m_factory.db().SaveItem(
        itemID(),
        ItemData(
            itemName().c_str(),
            typeID(),
            ownerID(),
            locationID(),
            flag(),
            contraband(),
            singleton(),
            quantity(),
            position(),
            customInfo().c_str()
        )
    );
}
Beispiel #11
0
InventoryItemRef InventoryItem::Split(int32 qty_to_take, bool notify) {
    if(qty_to_take <= 0) {
        _log(ITEM__ERROR, "%s (%u): Asked to split into a chunk of %d", itemName().c_str(), itemID(), qty_to_take);
        return InventoryItemRef();
    }
    if(!AlterQuantity(-qty_to_take, notify)) {
        _log(ITEM__ERROR, "%s (%u): Failed to remove quantity %d during split.", itemName().c_str(), itemID(), qty_to_take);
        return InventoryItemRef();
    }

    ItemData idata(
        typeID(),
        ownerID(),
        (notify ? 1 : locationID()), //temp location to cause the spawn via update
        flag(),
        qty_to_take
    );

    InventoryItemRef res = m_factory.SpawnItem(idata);
    if(notify)
        res->Move( locationID(), flag() );

    return( res );
}