Ejemplo n.º 1
0
/** Learn the price of refitting a certain engine
 * @param engine_type Which engine to refit
 * @return Price for refitting
 */
static CommandCost GetRefitCost(EngineID engine_type)
{
    ExpensesType expense_type;
    const Engine *e = Engine::Get(engine_type);
    Price base_price;
    uint cost_factor = e->info.refit_cost;
    switch (e->type) {
    case VEH_SHIP:
        base_price = PR_BUILD_VEHICLE_SHIP;
        expense_type = EXPENSES_SHIP_RUN;
        break;

    case VEH_ROAD:
        base_price = PR_BUILD_VEHICLE_ROAD;
        expense_type = EXPENSES_ROADVEH_RUN;
        break;

    case VEH_AIRCRAFT:
        base_price = PR_BUILD_VEHICLE_AIRCRAFT;
        expense_type = EXPENSES_AIRCRAFT_RUN;
        break;

    case VEH_TRAIN:
        base_price = (e->u.rail.railveh_type == RAILVEH_WAGON) ? PR_BUILD_VEHICLE_WAGON : PR_BUILD_VEHICLE_TRAIN;
        cost_factor <<= 1;
        expense_type = EXPENSES_TRAIN_RUN;
        break;

    default:
        NOT_REACHED();
    }
    return CommandCost(expense_type, GetPrice(base_price, cost_factor, e->grffile, -10));
}
Ejemplo n.º 2
0
void CItemDlg::OnLbnSelchangeItmItemList()
{
	// TODO: 在此添加控件通知处理程序代码
	GetPrice();
	SetPrice();
	SetDesc();
}
Ejemplo n.º 3
0
/**
 * Return how much a new engine costs.
 * @return Cost of the engine.
 */
Money Engine::GetCost() const
{
	Price base_price;
	uint cost_factor;
	switch (this->type) {
		case VEH_ROAD:
			base_price = PR_BUILD_VEHICLE_ROAD;
			cost_factor = GetEngineProperty(this->index, PROP_ROADVEH_COST_FACTOR, this->u.road.cost_factor);
			break;

		case VEH_TRAIN:
			if (this->u.rail.railveh_type == RAILVEH_WAGON) {
				base_price = PR_BUILD_VEHICLE_WAGON;
				cost_factor = GetEngineProperty(this->index, PROP_TRAIN_COST_FACTOR, this->u.rail.cost_factor);
			} else {
				base_price = PR_BUILD_VEHICLE_TRAIN;
				cost_factor = GetEngineProperty(this->index, PROP_TRAIN_COST_FACTOR, this->u.rail.cost_factor);
			}
			break;

		case VEH_SHIP:
			base_price = PR_BUILD_VEHICLE_SHIP;
			cost_factor = GetEngineProperty(this->index, PROP_SHIP_COST_FACTOR, this->u.ship.cost_factor);
			break;

		case VEH_AIRCRAFT:
			base_price = PR_BUILD_VEHICLE_AIRCRAFT;
			cost_factor = GetEngineProperty(this->index, PROP_AIRCRAFT_COST_FACTOR, this->u.air.cost_factor);
			break;

		default: NOT_REACHED();
	}

	return GetPrice(base_price, cost_factor, this->GetGRF(), -8);
}
Ejemplo n.º 4
0
/**
 * Return how much the running costs of this engine are.
 * @return Yearly running cost of the engine.
 */
Money Engine::GetRunningCost() const
{
	Price base_price;
	uint cost_factor;
	switch (this->type) {
		case VEH_ROAD:
			base_price = this->u.road.running_cost_class;
			if (base_price == INVALID_PRICE) return 0;
			cost_factor = GetEngineProperty(this->index, PROP_ROADVEH_RUNNING_COST_FACTOR, this->u.road.running_cost);
			break;

		case VEH_TRAIN:
			base_price = this->u.rail.running_cost_class;
			if (base_price == INVALID_PRICE) return 0;
			cost_factor = GetEngineProperty(this->index, PROP_TRAIN_RUNNING_COST_FACTOR, this->u.rail.running_cost);
			break;

		case VEH_SHIP:
			base_price = PR_RUNNING_SHIP;
			cost_factor = GetEngineProperty(this->index, PROP_SHIP_RUNNING_COST_FACTOR, this->u.ship.running_cost);
			break;

		case VEH_AIRCRAFT:
			base_price = PR_RUNNING_AIRCRAFT;
			cost_factor = GetEngineProperty(this->index, PROP_AIRCRAFT_RUNNING_COST_FACTOR, this->u.air.running_cost);
			break;

		default: NOT_REACHED();
	}

	return GetPrice(base_price, cost_factor, this->GetGRF(), -8);
}
Ejemplo n.º 5
0
/*********************************************************
*函数名:    Print()
*函数功能:  输入单个图书的全部信息
*
*函数参数:  void
*函数返回值:void
*********************************************************/
void Book::Print()
{
    cout <<  GetISBN()  << '\t'  << GetTitle() << '\t';
    cout << GetAuthor() << '\t'  << GetPublisher() << '\t';
    cout << GetDate() << '\t' << GetPrice();
    cout << setw(10) << GetCatalogNum() << setw(11) << GetNumber() << endl;
}
Ejemplo n.º 6
0
int main(int argc, char *args[])
{
    char *buffer = (char *)malloc(MAX_LINE_LEN);;
    char *result = (char *)malloc(MAX_LINE_LEN);;
    int number;
    int dwnum;

    dwnum = GetPrice();
    if(dwnum != 0)
    {
	return dwnum;
    }
    list_t *L = ListInit();
    if(L == NULL)
    {
	return ERRNO_NULL_POINTER;
    }

    while(fgets(buffer, MAX_LINE_LEN, stdin))
    {
	number = 0;
	memset(result, 0, MAX_LINE_LEN);
	dwnum = ParseLine(buffer, result, &number);

	if(dwnum == 0)
	{
	    item_t* curnode;
	    if((curnode = ListIsNodeInListById(L, result)) != NULL)
	    {
		curnode->count += number;
		continue;
	    }

	    item_t * node = ItemMakeitem(result, number);
	    if(node == NULL)
	    {
		return ERRNO_MAKEITEM_FAIL;
	    }

	    dwnum = ListPushBack(L, (void*) node);
	    if(dwnum != 0)
	    {
		return ERRNO_LISTPUSHBACK_FAIL;
	    }
	}
    }

    dwnum = CalculateSum(L);
    if(dwnum != 0)
    {
	return ERRNO_CALCULATESUM_FAIL;	
    }

    ListFree(L);
    ListFree(my_price);
    free(buffer);
    free(result);
    return 0;
}
Ejemplo n.º 7
0
bool MarketAgent::SellTo(MarketAgent *other, Equip::Type t, bool verbose)
{
	if (other->CanBuy(t, verbose) && CanSell(t, verbose) && other->Pay(this, GetPrice(t), verbose)) {
		Sold(t);
		other->Bought(t);
		return true;
	} else return false;
}
Ejemplo n.º 8
0
bool MarketAgent::BuyFrom(MarketAgent *other, Equip::Type t, bool verbose)
{
	if (other->CanSell(t, verbose) && CanBuy(t, verbose) && Pay(other, GetPrice(t), verbose)) {
		other->Sold(t);
		Bought(t);
		return true;
	} else return false;
}
Ejemplo n.º 9
0
void CItemDlg::OnBnClickedConfirm()
{
	// TODO: 在此添加控件通知处理程序代码
	GetPrice();

	if(!rom.SaveItemList())
	{
		AfxMessageBox(IDS_ERR_ROM_WRITE);
	}
}
Ejemplo n.º 10
0
/**
 * Return how much a new engine costs.
 * @return Cost of the engine.
 */
Money Engine::GetCost() const
{
	Price base_price;
	uint cost_factor;
	switch (this->type) {
		case VEH_ROAD:
			base_price = PR_BUILD_VEHICLE_ROAD;
			cost_factor = GetEngineProperty(this->index, PROP_ROADVEH_COST_FACTOR, this->u.road.cost_factor);
			break;

		case VEH_TRAIN:
			if (this->u.rail.railveh_type == RAILVEH_WAGON) {
				base_price = PR_BUILD_VEHICLE_WAGON;
				cost_factor = GetEngineProperty(this->index, PROP_TRAIN_COST_FACTOR, this->u.rail.cost_factor);
			} else {
				base_price = PR_BUILD_VEHICLE_TRAIN;
				cost_factor = GetEngineProperty(this->index, PROP_TRAIN_COST_FACTOR, this->u.rail.cost_factor);
			}
			break;

		case VEH_SHIP:
			base_price = PR_BUILD_VEHICLE_SHIP;
			cost_factor = GetEngineProperty(this->index, PROP_SHIP_COST_FACTOR, this->u.ship.cost_factor);
			break;

		case VEH_AIRCRAFT:
			base_price = PR_BUILD_VEHICLE_AIRCRAFT;
			cost_factor = GetEngineProperty(this->index, PROP_AIRCRAFT_COST_FACTOR, this->u.air.cost_factor);
			break;

		default: NOT_REACHED();
	}
       /* Multiply showed cost according to day length balance type. */
       if (_settings_game.economy.day_length_balance_type == DBT_ALL_COSTS) {
               return GetPrice(base_price, cost_factor, this->GetGRF(), -8) * _settings_game.economy.day_length_balance_factor;
       }

	return GetPrice(base_price, cost_factor, this->GetGRF(), -8);
}
Ejemplo n.º 11
0
/**
 * Return how much the running costs of this engine are.
 * @return Yearly running cost of the engine.
 */
Money Engine::GetRunningCost() const
{
	Price base_price;
	uint cost_factor;
	switch (this->type) {
		case VEH_ROAD:
			base_price = this->u.road.running_cost_class;
			if (base_price == INVALID_PRICE) return 0;
			cost_factor = GetEngineProperty(this->index, PROP_ROADVEH_RUNNING_COST_FACTOR, this->u.road.running_cost);
			break;

		case VEH_TRAIN:
			base_price = this->u.rail.running_cost_class;
			if (base_price == INVALID_PRICE) return 0;
			cost_factor = GetEngineProperty(this->index, PROP_TRAIN_RUNNING_COST_FACTOR, this->u.rail.running_cost);
			break;

		case VEH_SHIP:
			base_price = PR_RUNNING_SHIP;
			cost_factor = GetEngineProperty(this->index, PROP_SHIP_RUNNING_COST_FACTOR, this->u.ship.running_cost);
			break;

		case VEH_AIRCRAFT:
			base_price = PR_RUNNING_AIRCRAFT;
			cost_factor = GetEngineProperty(this->index, PROP_AIRCRAFT_RUNNING_COST_FACTOR, this->u.air.running_cost);
			break;

		default: NOT_REACHED();
	}
       /* Multiply showed running cost according to day length balance type. */
       if (_settings_game.economy.day_length_balance_type == DBT_ALL_COSTS ||
               _settings_game.economy.day_length_balance_type == DBT_RUN_COST)
       {
               return GetPrice(base_price, cost_factor, this->GetGRF(), -8) * _settings_game.economy.day_length_balance_factor;
       }

	return GetPrice(base_price, cost_factor, this->GetGRF(), -8);
}
Ejemplo n.º 12
0
/**
 * Learn the price of refitting a certain engine
 * @param v The vehicle we are refitting, can be NULL.
 * @param engine_type Which engine to refit
 * @param new_cid Cargo type we are refitting to.
 * @param new_subtype New cargo subtype.
 * @param [out] auto_refit_allowed The refit is allowed as an auto-refit.
 * @return Price for refitting
 */
static CommandCost GetRefitCost(const Vehicle *v, EngineID engine_type, CargoID new_cid, byte new_subtype, bool *auto_refit_allowed)
{
	ExpensesType expense_type;
	const Engine *e = Engine::Get(engine_type);
	Price base_price;
	int cost_factor = GetRefitCostFactor(v, engine_type, new_cid, new_subtype, auto_refit_allowed);
	switch (e->type) {
		case VEH_SHIP:
			base_price = PR_BUILD_VEHICLE_SHIP;
			expense_type = EXPENSES_SHIP_RUN;
			break;

		case VEH_ROAD:
			base_price = PR_BUILD_VEHICLE_ROAD;
			expense_type = EXPENSES_ROADVEH_RUN;
			break;

		case VEH_AIRCRAFT:
			base_price = PR_BUILD_VEHICLE_AIRCRAFT;
			expense_type = EXPENSES_AIRCRAFT_RUN;
			break;

		case VEH_TRAIN:
			base_price = (e->u.rail.railveh_type == RAILVEH_WAGON) ? PR_BUILD_VEHICLE_WAGON : PR_BUILD_VEHICLE_TRAIN;
			cost_factor <<= 1;
			expense_type = EXPENSES_TRAIN_RUN;
			break;

		default: NOT_REACHED();
	}
	if (cost_factor < 0) {
		return CommandCost(expense_type, -GetPrice(base_price, -cost_factor, e->GetGRF(), -10));
	} else {
		return CommandCost(expense_type, GetPrice(base_price, cost_factor, e->GetGRF(), -10));
	}
}
Ejemplo n.º 13
0
void ShowAllObjects(Boss::ref_ptr<Boss::IEnum> collection)
{
  Boss::EnumHelper<Boss::IBase> Collection(collection);
  for (auto i = Collection.First() ; i.Get() ; i = Collection.Next())
  {
    double Price = 0;
    {
      Boss::qi_ptr<MyNs::IFaces::IFixPrice> FixPrice(i);
      if (!FixPrice.Get())
        throw std::runtime_error("Unknown object.");
      if (FixPrice->GetPrice(&Price) != Boss::Status::Ok)
        throw std::runtime_error("Failed to get price.");
    }
    std::string ObjectType = "FixPrice";
    Boss::qi_ptr<MyNs::IFaces::IBestOffer> BestOffer(i);
    std::vector<double> Offers;
    if (BestOffer.Get())
    {
      ObjectType = "BestOffer";
      Boss::ref_ptr<Boss::IEnum> AllOffers;
      if (BestOffer->GetAllOffers(AllOffers.GetPPtr()) != Boss::Status::Ok)
        throw std::runtime_error("Failed to get all offers for \"BestOffer\" object.");
      Boss::EnumHelper<MyNs::IFaces::IFixPrice> OffersEnum(AllOffers);
      for (auto j = OffersEnum.First() ; j.Get() ; j = OffersEnum.Next())
      {
        double OfferPrice = 0;
        if (j->GetPrice(&OfferPrice) != Boss::Status::Ok)
          throw std::runtime_error("Failed to get offer price.");
        Offers.push_back(OfferPrice);
      }
    }
    else
    {
      Boss::qi_ptr<MyNs::IFaces::IAuction> Auction(i);
      if (Auction.Get())
        ObjectType = "Auction";
    }
    std::cout << "ObjectType: " << ObjectType << std::endl;
    std::cout << "\tPrice: " << Price << std::endl;
    if (!Offers.empty())
    {
      std::cout << "\tOffers:\n\t\t";
      std::copy(std::begin(Offers), std::end(Offers),
                std::ostream_iterator<double>(std::cout, "\n\t\t"));
    }
    std::cout << std::endl;
  }
}
nux::Layout* PaymentPreview::GetHeader()
{
  nux::HLayout* header_data_layout = new nux::HLayout();
  header_data_layout->SetSpaceBetweenChildren(10);
  header_data_layout->SetMaximumHeight(76);
  header_data_layout->SetMinimumHeight(76);

  image_ = new CoverArt();
  image_->SetMinMaxSize(64, 64);
  AddChild(image_.GetPointer());
  UpdateCoverArtImage(image_.GetPointer());

  header_data_layout->AddView(image_.GetPointer(), 0);
  header_data_layout->AddLayout(GetTitle(), 0);
  header_data_layout->AddSpace(10, 1);
  header_data_layout->AddLayout(GetPrice(), 0);
  return header_data_layout;
}
Ejemplo n.º 15
0
nux::Layout* PaymentPreview::GetHeader()
{
  nux::HLayout* header_data_layout = new nux::HLayout();
  header_data_layout->SetSpaceBetweenChildren(HEADER_CHILDREN_SPACE.CP(scale));
  header_data_layout->SetMaximumHeight(HEADER_MAX_SIZE.CP(scale));
  header_data_layout->SetMinimumHeight(HEADER_MAX_SIZE.CP(scale));

  image_ = new CoverArt();
  image_->SetMinMaxSize(IMAGE_MIN_MAX_SIZE.CP(scale), IMAGE_MIN_MAX_SIZE.CP(scale));
  AddChild(image_.GetPointer());
  UpdateCoverArtImage(image_.GetPointer());

  header_data_layout->AddView(image_.GetPointer(), 0);
  header_data_layout->AddLayout(GetTitle(), 0);
  header_data_layout->AddSpace(HEADER_SPACE.CP(scale), 1);
  header_data_layout->AddLayout(GetPrice(), 0);
  return header_data_layout;
}
Ejemplo n.º 16
0
void CHyperFeedPriceProvider::OnRequest(CRequestBasePtr pRequest)
{
	switch(pRequest->m_enType)
	{
	case _enRequestLast:
		GetPrice(pRequest);
		break;
	case _enRequestRealtime:
		Subscribe(pRequest, false);
		break;
	case _enRequestGroup:
		{
			CGroupRequestPtr pGroupRequest = boost::shared_dynamic_cast<CGroupRequest>(pRequest);
			if(pGroupRequest)
			{
				if(enGroupRequestLastQuote == pGroupRequest->m_enGroupRequestType)
					GetGroupPrice(pGroupRequest->m_recParams);
				else
					SubscribeGroup(pGroupRequest->m_recParams, pGroupRequest->m_enGroupRequestType);
			}
		}
		break;
	}
}
Ejemplo n.º 17
0
bool CGoods::SerializeForOldClient(vector<uchar>* pStream, bool b)
{
	bool bResult = false;
	CGoodsBaseProperties* pProperties = GoodsSetup::QueryGoodsBaseProperties(
		GetBasePropertiesIndex() );
	if( pProperties )
	{
		_AddToByteArray( pStream, GetBasePropertiesIndex() );
		_AddToByteArray( pStream, GetExID() );
		_AddToByteArray( pStream, GetAmount() );
		_AddToByteArray( pStream, const_cast<char*>( GetMakerName() ) );		
		_AddToByteArray( pStream, GetPrice() );	
		_AddToByteArray(pStream,GetSilverPrice());
		_AddToByteArray(pStream,m_dwBuyPrice);
		_AddToByteArray(pStream,(ulong)GetGoodsBaseType());
		

		CGoodsBaseProperties* pBaseProperty=GoodsSetup::QueryGoodsBaseProperties(m_dwBasePropertiesIndex);
		if(!pBaseProperty)
			return false;
		long lAddonNum=0;
		ulong dwPropertyId=0;

		vector<uchar> vecAddonData;
		for( size_t i = 0; i < m_vAddonProperties.size(); i ++ )
		{		
			if(pBaseProperty->IsHasAddonPropertie(m_vAddonProperties[i].gapType))	
			{
				dwPropertyId=m_vAddonProperties[i].gapType;
				//if(GoodsSetup::s_GoodsAttrDBSetup[dwPropertyId][1]==1)
				//{
					lAddonNum++;
					_AddToByteArray( &vecAddonData, static_cast<WORD>(m_vAddonProperties[i].gapType) );
					_AddToByteArray( &vecAddonData, m_vAddonProperties[i].lValues[0] );
					_AddToByteArray( &vecAddonData, m_vAddonProperties[i].lValues[1] );
				//}
			}
			else
			{
				lAddonNum++;
				_AddToByteArray( &vecAddonData, static_cast<WORD>(m_vAddonProperties[i].gapType) );
				_AddToByteArray( &vecAddonData, m_vAddonProperties[i].lValues[0] );
				_AddToByteArray( &vecAddonData, m_vAddonProperties[i].lValues[1] );
			}
		}
		_AddToByteArray( pStream,lAddonNum);
		if(lAddonNum>0)
		{
			_AddToByteArray(pStream,&vecAddonData[0],(long)vecAddonData.size());
		}
		/////////////////
		
		_AddToByteArray( pStream, GetTileX() );
		_AddToByteArray( pStream, GetTileY() );

		EnchaseArrange();

		//enchase data	
		ulong dwMaxHoleNum=GetMaxEnchaseHoleNum();
		if(dwMaxHoleNum>0)
		{
			//最大孔数
			_AddToByteArray(pStream,dwMaxHoleNum);
			//激活孔数量
			//王晓轩:默认所有孔都开启,所以删除此项数据
			//_AddToByteArray( pStream, GetActivedHoleNum());
			for(int i=0;i<(int)dwMaxHoleNum;i++)
			{		
				//CARD ID
				CGoods* pCard=m_pEnchaseHoleArray[i]->GetCard();
				if(pCard)
				{
					_AddToByteArray(pStream,pCard->GetBasePropertiesIndex());
					pCard->SerializeForOldClient(pStream);
				}
				else
				{
					_AddToByteArray(pStream,ulong(0));
				}
			}
		}

		bResult = true;
	}
	return bResult;
}
Ejemplo n.º 18
0
bool CGoods::SerializeForOldClient(DBWriteSet& setWriteDB, bool b)
{
	bool bResult = false;
	CGoodsBaseProperties* pProperties = GoodsSetup::QueryGoodsBaseProperties(
		GetBasePropertiesIndex() );
	if( pProperties )
	{
		setWriteDB.AddToByteArray( GetBasePropertiesIndex() );
		setWriteDB.AddToByteArray( GetExID() );
		setWriteDB.AddToByteArray( GetAmount() );
		setWriteDB.AddToByteArray( const_cast<char*>( GetMakerName() ) );		
		setWriteDB.AddToByteArray( GetPrice() );	
		setWriteDB.AddToByteArray( GetSilverPrice());
		setWriteDB.AddToByteArray( m_dwBuyPrice);
		setWriteDB.AddToByteArray( (ulong)GetGoodsBaseType());		

		long lAddonNum=0;
		ulong dwPropertyId=0;

		vector<uchar> vecAddonData;
		for( size_t i = 0; i < m_vAddonProperties.size(); i ++ )
		{		
			if(pProperties->IsHasAddonPropertie(m_vAddonProperties[i].gapType))	
			{
				dwPropertyId=m_vAddonProperties[i].gapType;				
				lAddonNum++;
				_AddToByteArray( &vecAddonData, static_cast<WORD>(m_vAddonProperties[i].gapType) );
				_AddToByteArray( &vecAddonData, m_vAddonProperties[i].lValues[0]);
				_AddToByteArray( &vecAddonData, m_vAddonProperties[i].lValues[1]);
			}
			else
			{
				lAddonNum++;
				_AddToByteArray( &vecAddonData, static_cast<WORD>(m_vAddonProperties[i].gapType) );
				_AddToByteArray( &vecAddonData, m_vAddonProperties[i].lValues[0]);
				_AddToByteArray( &vecAddonData, m_vAddonProperties[i].lValues[1]);
			}
		}
		setWriteDB.AddToByteArray(lAddonNum);
		if(lAddonNum>0)
		{
			setWriteDB.AddToByteArray( &vecAddonData[0],(long)vecAddonData.size());
		}
		/////////////////
		
		setWriteDB.AddToByteArray( GetTileX() );
		setWriteDB.AddToByteArray( GetTileY() );

		EnchaseArrange();
		//enchase data	
		ulong dwMaxHoleNum=GetMaxEnchaseHoleNum();
		if(dwMaxHoleNum>0)
		{
			//最大孔数
			setWriteDB.AddToByteArray( dwMaxHoleNum);
			//激活孔数量
			//王晓轩:默认所有孔都开启,所以删除此项数据
			//setWriteDB.AddToByteArray( GetActivedHoleNum());
			for(int i=0;i<(int)dwMaxHoleNum;i++)
			{		
				//CARD ID
				CGoods* pCard=m_pEnchaseHoleArray[i]->GetCard();
				if(pCard)
				{
					setWriteDB.AddToByteArray( pCard->GetBasePropertiesIndex());
					pCard->SerializeForOldClient(setWriteDB);
				}
				else
				{
					setWriteDB.AddToByteArray(ulong(0));
				}
			}
		}

		bResult = true;
	}
	return bResult;
}
Ejemplo n.º 19
0
// 组装消息
void CDBCard::AddEntityDataToMsg(DB_OPERATION_TYPE opType, vector<BYTE>& pBA)
{
	// 传递来的消息前面已经加入了
	// OPEntityFlag:  1byte, 操作实体数量的标志 0: 单个, 1:多个
	// DBOP Type:     1byte, 数据库操作类型(枚举值)
	// MSG ID:        4byte, 该消息的MSGID
	// Entity Num:    2byte, 该实体个数
	if(DB_OPER_DELETE == opType) // DELETE操作
	{
		_AddToByteArray(&pBA, m_GUID); // 实体ID
		_AddToByteArray(&pBA, (long)0); // 属性种类个数

		// 发送CardNumber 字符串
		_AddToByteArray(&pBA, (WORD)1);
		_AddToByteArray(&pBA, (long)DB_CARD_ATTR_SZ_CARDNUMBER);
		_AddToByteArray(&pBA, GetCardNumber());
		return;
	}

	WORD attrNum = 0;
	for(int i = 0; i < (int)m_SendAttrEnumVector.size(); i++)
	{
		if(m_SendAttrEnumVector[i] != 0)
			attrNum++;
	}

	_AddToByteArray(&pBA, m_GUID); // 实体ID
	_AddToByteArray(&pBA, attrNum); // 属性种类个数

	for(int i = 0; i < (int)m_SendAttrEnumVector.size(); i++)
	{
		if(m_SendAttrEnumVector[i] != 0 
			&& ( DB_OPER_SAVE == opType || DB_OPER_UPDATE == opType || DB_OPER_LOAD == opType ) )// 标志打开并且为SAVE/UPDATE/LOAD操作
		{
			switch(DB_CARD_ATTR_SZ_CARDNUMBER+i)
			{
			case DB_CARD_ATTR_SZ_CARDNUMBER:
				{
					_AddToByteArray(&pBA, (WORD)1);
					_AddToByteArray(&pBA, (long)DB_CARD_ATTR_SZ_CARDNUMBER);
					if(DB_OPER_LOAD != opType)
						_AddToByteArray(&pBA, GetCardNumber());
					else
						_AddToByteArray(&pBA, (BYTE)0);
				}
				break;
			case DB_CARD_ATTR_SZ_CARDTYPE:
				{
					_AddToByteArray(&pBA, (WORD)1);
					_AddToByteArray(&pBA, (long)DB_CARD_ATTR_SZ_CARDTYPE);
					if(DB_OPER_LOAD != opType)
						_AddToByteArray(&pBA, GetCardType());
					else
						_AddToByteArray(&pBA, (BYTE)0);
				}
				break;
			case DB_CARD_ATTR_SZ_SELLERACCOUNT:
				{
					_AddToByteArray(&pBA, (WORD)1);
					_AddToByteArray(&pBA, (long)DB_CARD_ATTR_SZ_SELLERACCOUNT);
					if(DB_OPER_LOAD != opType)
						_AddToByteArray(&pBA, GetSellerAccount());
					else
						_AddToByteArray(&pBA, (BYTE)0);
				}
				break;
			case DB_CARD_ATTR_LONG_SELLERID:
				{
					_AddToByteArray(&pBA, (WORD)1);
					_AddToByteArray(&pBA, (long)DB_CARD_ATTR_LONG_SELLERID);
					if(DB_OPER_LOAD != opType)
						_AddToByteArray(&pBA, GetSellerID());
					else
						_AddToByteArray(&pBA, (BYTE)0);
				}
				break;
			case DB_CARD_ATTR_SZ_BUYERACCOUNT:
				{
					_AddToByteArray(&pBA, (WORD)1);
					_AddToByteArray(&pBA, (long)DB_CARD_ATTR_SZ_BUYERACCOUNT);
					if(DB_OPER_LOAD != opType)
						_AddToByteArray(&pBA, GetBuyerAccount());
					else
						_AddToByteArray(&pBA, (BYTE)0);
				}
				break;
			case DB_CARD_ATTR_LONG_BUYERID:
				{
					_AddToByteArray(&pBA, (WORD)1);
					_AddToByteArray(&pBA, (long)DB_CARD_ATTR_LONG_BUYERID);
					if(DB_OPER_LOAD != opType)
						_AddToByteArray(&pBA, GetBuyerID());
					else
						_AddToByteArray(&pBA, (BYTE)0);
				}
				break;
			case DB_CARD_ATTR_DWORD_PRICE:
				{
					_AddToByteArray(&pBA, (WORD)1);
					_AddToByteArray(&pBA, (long)DB_CARD_ATTR_DWORD_PRICE);
					if(DB_OPER_LOAD != opType)
						_AddToByteArray(&pBA, GetPrice());
					else
						_AddToByteArray(&pBA, (BYTE)0);
				}
				break;
			case DB_CARD_ATTR_DWORD_CHARGEPRICE:
				{
					_AddToByteArray(&pBA, (WORD)1);
					_AddToByteArray(&pBA, (long)DB_CARD_ATTR_DWORD_CHARGEPRICE);
					if(DB_OPER_LOAD != opType)
						_AddToByteArray(&pBA, GetChargePrice());
					else
						_AddToByteArray(&pBA, (BYTE)0);
				}
				break;
			case DB_CARD_ATTR_DWORD_CARDSTATE:
				{
					_AddToByteArray(&pBA, (WORD)1);
					_AddToByteArray(&pBA, (long)DB_CARD_ATTR_DWORD_CARDSTATE);
					if(DB_OPER_LOAD != opType)
						_AddToByteArray(&pBA, GetCardState());
					else
						_AddToByteArray(&pBA, (BYTE)0);
				}
				break;
			case DB_CARD_ATTR_DWORD_CARDTIME:
				{
					_AddToByteArray(&pBA, (WORD)1);
					_AddToByteArray(&pBA, (long)DB_CARD_ATTR_DWORD_CARDTIME);
					if(DB_OPER_LOAD != opType)
						_AddToByteArray(&pBA, GetCardTime());
					else
						_AddToByteArray(&pBA, (BYTE)0);
				}
				break;
			case DB_CARD_ATTR_DWORD_STARTTIME:
				{
					_AddToByteArray(&pBA, (WORD)1);
					_AddToByteArray(&pBA, (long)DB_CARD_ATTR_DWORD_STARTTIME);
					if(DB_OPER_LOAD != opType)
						_AddToByteArray(&pBA, GetStartTime());
					else
						_AddToByteArray(&pBA, (BYTE)0);
				}
				break;
			case DB_CARD_ATTR_DWORD_SERIALNUMBER:
				{
					_AddToByteArray(&pBA, (WORD)1);
					_AddToByteArray(&pBA, (long)DB_CARD_ATTR_DWORD_SERIALNUMBER);
					if(DB_OPER_LOAD != opType)
						_AddToByteArray(&pBA, GetSerialNumber());
					else
						_AddToByteArray(&pBA, (BYTE)0);
				}
				break;
			}
		}
	}

}
void CHyperFeedStructureProviderEx::OnRequest(CRequestBasePtr pRequest)
{
	switch(pRequest->m_enType)
	{
	case _enRequestStock:
		{
			CStockRequest* pStockRequest = static_cast<CStockRequest*>(pRequest.get());
			if(pStockRequest)
				GetStockResultsEx(pStockRequest->m_recParams);
		}
		break;
	case _enRequestOption:
		{
			COptionRequest* pOptionRequest = static_cast<COptionRequest*>(pRequest.get());
			if(pOptionRequest)
			{
				pOptionRequest->m_recParams.CopyTo(m_vtCurrentRequest);
				if(!IsCanceled())
					LoadOptionFundamentalInfo(pOptionRequest->m_recParams->UnderlyingSymbol);
				if(!IsCanceled())
					GetOptions(pOptionRequest->m_recParams->UnderlyingSymbol);
			}
		}
		break;
	case _enRequestFuture:
		{
			CFutureRequest* pFutureRequest = static_cast<CFutureRequest*>(pRequest.get());
			if(pFutureRequest)
				GetFutureResultsBySymbol(pFutureRequest->m_recParams, true);
		}
		break;
	case _enRequestFutures:
		{
			CFuturesRequest* pFuturesRequest = static_cast<CFuturesRequest*>(pRequest.get());
			if(pFuturesRequest)
				GetFutureResultsByRootSymbol(pFuturesRequest->m_recParams, true);
		}
		break;
	case _enRequestFuturesOption:
		{
			EgStd::CEgTracingClass::TraceStatic(enlogSubs, __FUNCTION__ , _T("Requst Futures Options Start"));
			CFuturesOptionRequestPtr pFuturesOptionRequest = boost::shared_dynamic_cast<CFuturesOptionRequest>(pRequest);
			if(pFuturesOptionRequest)
			{
				EgStd::CEgTracingClass::TraceStatic(enlogSubs, __FUNCTION__ , _T("pFuturesOptionRequest"));
				pFuturesOptionRequest->m_recParams.CopyTo(m_vtCurrentRequest);
				EgStd::CEgTracingClass::TraceStatic(enlogSubs, __FUNCTION__ , _T("GetFutureInfo Call"));
				long nResult = GetFutureInfo(pFuturesOptionRequest->m_recParams, false);
				if(nResult == DBA_ERR_NO_ERROR) // Sharky: try to resolve FT_CQ00001489
				{
					EgStd::CEgTracingClass::TraceStatic(enlogSubs, __FUNCTION__ , _T("GetFutureInfo Call - No Error"));
					QuoteUpdateParams Params;
					Params.Symbol = ::SysAllocString(pFuturesOptionRequest->m_recParams->FutureSymbol);
					Params.Type = enFUT;
					Params.Exchange = NULL;

					CQuoteRequestPtr pQuoteRequest = CQuoteRequestPtr(new CQuoteRequest(_enRequestFuturesOption, &Params));
					EgStd::CEgTracingClass::TraceStatic(enlogSubs, __FUNCTION__ , _T("GetPrice for: Symbol - %s"), CW2T(Params.Symbol) );
					nResult = GetPrice(boost::shared_static_cast<CRequestBase>(pQuoteRequest), false);

					::SysFreeString(Params.Symbol);

					if(nResult == DBA_ERR_NO_ERROR) // Sharky: try to resolve FT_CQ00001489
					{
						EgStd::CEgTracingClass::TraceStatic(enlogSubs, __FUNCTION__ , _T("Got Price for: %s"), CW2T(Params.Symbol));
						EgStd::CEgTracingClass::TraceStatic(enlogSubs, __FUNCTION__ , _T("Requesting future options for: %s"), CW2T(Params.Symbol));
						GetFutureOptionsResults(m_clCurrentFuture, false);
						EgStd::CEgTracingClass::TraceStatic(enlogSubs, __FUNCTION__ , _T("Got future options for: %s"), CW2T(Params.Symbol));

					}
					else
					{
						EgStd::CEgTracingClass::TraceStatic(enlogSubs, __FUNCTION__ , _T("GetPrice FAILED for: %s"),CW2T(Params.Symbol));
						/* Lets try to get with 'G' symbol */

						//Params.Exchange = ::SysAllocString(L"G");
						CComBSTR cbsTmp(pFuturesOptionRequest->m_recParams->FutureSymbol);
						cbsTmp.Append(L"G");
						Params.Symbol = cbsTmp.Detach();


						CQuoteRequestPtr pQuoteRequest = CQuoteRequestPtr(new CQuoteRequest(_enRequestFuturesOption, &Params));
						EgStd::CEgTracingClass::TraceStatic(enlogSubs, __FUNCTION__ , _T("GetPrice for: Symbol - %s"), CW2T(Params.Symbol) );
						nResult = GetPrice(boost::shared_dynamic_cast<CRequestBase>(pQuoteRequest), false);
						//::SysFreeString(Params.Symbol);
						//::SysFreeString(Params.Exchange );

						if(nResult == DBA_ERR_NO_ERROR) 
						{
							EgStd::CEgTracingClass::TraceStatic(enlogSubs, __FUNCTION__ , _T("Got Price for: %s"), CW2T(Params.Symbol));
							EgStd::CEgTracingClass::TraceStatic(enlogSubs, __FUNCTION__ , _T("Requesting future options for: %s"), CW2T(Params.Symbol));
							GetFutureOptionsResults(m_clCurrentFuture, false);
							EgStd::CEgTracingClass::TraceStatic(enlogSubs, __FUNCTION__ , _T("Got future options for: %s"), CW2T(Params.Symbol));
						}
						else
						{
							EgStd::CEgTracingClass::TraceStatic(enlogSubs, __FUNCTION__ , _T("GetPrice FAILED for: %s"),CW2T(Params.Symbol));

						}
						/* ---Lets try to get with 'G' symbol */
					}

				}
				else
				{
					EgStd::CEgTracingClass::TraceStatic(enlogSubs, __FUNCTION__ , _T("GetFutureInfo Call - Failed"));
				}

				if(nResult != DBA_ERR_NO_ERROR) // Sharky: try to resolve FT_CQ00001489
				{
					EgStd::CEgTracingClass::TraceStatic(enlogSubs, __FUNCTION__ , _T("Request future options - got error"));

					if(nResult == DBA_TERMINATED)
					{
						EgStd::CEgTracingClass::TraceStatic(enlogSubs, __FUNCTION__ , _T("Operation was canceled by user"));
						PublicGetFutureOptionError(enInternalError, _bstr_t(L"Operation was canceled by user"));
					}
					if(nResult == DBA_ERR_KEY_NOT_FOUND)
					{
						EgStd::CEgTracingClass::TraceStatic(enlogSubs, __FUNCTION__ , _T("Couldn't get future options for future. Unknown symbol"));
						PublicGetFutureOptionError(enNoDataAvailableForSymbol, _bstr_t(L"Couldn't get future options for future. Unknown symbol"));
					}
					else
					{
						_bstr_t bs =  "Couldn't get options for future. Error: ";
						bs += EtGetMessage(DBA_ERROR,nResult);
						TCHAR buffer[0x100] = {0};				
						_ltot(nResult,buffer,10);
						bs += " (";
						bs += buffer;
						bs += ")";
						EgStd::CEgTracingClass::TraceStatic(enlogSubs, __FUNCTION__ , _T(buffer));
						PublicGetFutureOptionError(enProviderInternalError, bs);
					}
				}
			}
		}
		break;
	}
}
Ejemplo n.º 21
0
void Game::Step4BuyingCities2() {

    if (!pickedCity) {
        // Player skipped, go to next player
        currentPlayer = playerOrder[GetNextPlayerIndex()];

        if (currentPlayer.get() == playerOrder[0].get()) {
            return Step4End();
        }

        return Step4BuyingCities1();
    }

    // Check if city is full
    if (pickedCity->GetNumberOfHouses() == phase) {
        SetErrorMessageTextBox("Buying City Error",
            "Cannot buy a house. <b>" + pickedCity->GetName() +
            "</b> is already saturated for this phase.");
        return Step4BuyingCities1();
    }

    // Find the cost of connecting to that city
    int cost;
    if (currentPlayer->GetHouses().empty())
        cost = pickedCity->GetHousePrice();
    else
        cost = pickedCity->GetHousePrice() + map->GetShortestPath(currentPlayer, pickedCity->GetName());

    // Check if you have enough money
    if (!currentPlayer->HasElektro(cost)) {
        SetErrorMessageTextBox("Not Enough Money", "Not enough money to buy <b>" +
            pickedCity->GetName() + "</b> for a total cost of <b>" +
            std::to_string(cost) + "</b> Elektro.");
        return Step4BuyingCities1();
    }

    // Buy the city
    auto newHouse = std::make_shared<House>(pickedCity, currentPlayer->GetColor());
    newHouse->SetPrice(cost);

    // Check for enough money
    if (!currentPlayer->HasElektro(newHouse->GetPrice()))
    {
        SetErrorMessageTextBox("House Error", "Not enough money to buy this house");
        return Step4BuyingCities1();
    }

    // Check if already bought in this city
    for (auto tmpHouse : currentPlayer->GetHouses()) {
        if (tmpHouse->GetCity() == newHouse->GetCity()) {
            SetErrorMessageTextBox("House Error", "Cannot buy in the same city twice");
            return Step4BuyingCities1();
        }
    }

    currentPlayer->BuyHouse(newHouse);
    SetInfoMessageTextBox("Buying City Success", "<b>" + currentPlayer->GetName() +
                          "</b> has bought a house at <b>" + pickedCity->GetName() +
                          "</b> for a total cost of <b>" + std::to_string(cost) + "</b> Elektro.");

    // Go back to buy another one
    return Step4BuyingCities1();
}
Ejemplo n.º 22
0
Money Ship::GetRunningCost() const
{
	const Engine *e = this->GetEngine();
	uint cost_factor = GetVehicleProperty(this, PROP_SHIP_RUNNING_COST_FACTOR, e->u.ship.running_cost);
	return GetPrice(PR_RUNNING_SHIP, cost_factor, e->GetGRF());
}
Ejemplo n.º 23
0
Money Ship::GetRunningCost() const
{
	const Engine *e = Engine::Get(this->engine_type);
	uint cost_factor = GetVehicleProperty(this, PROP_SHIP_RUNNING_COST_FACTOR, e->u.ship.running_cost);
	return GetPrice(PR_RUNNING_SHIP, cost_factor, e->grffile);
}