コード例 #1
0
ファイル: CItemSpawn.cpp プロジェクト: leandrorenato/Source
void CItemSpawn::AddObj( CGrayUID uid )
{
	ADDTOCALLSTACK("CitemSpawn:AddObj");
	unsigned char iMax = GetAmount() > 0 ? static_cast<unsigned char>(GetAmount()) : 1;
	bool bIsSpawnChar = GetType() == IT_SPAWN_CHAR;
	if (!uid)
		return;

	if ( bIsSpawnChar )
	{
		if ( !uid.CharFind()->m_pNPC)	// Only adding NPCs to IT_SPAWN_CHAR..
			return;
		if ( uid.CharFind()->m_uidSpawnItem.ItemFind() )	//... if they doesn't have a SpawnItem already.
			return;
	} else if( !uid.ItemFind() )		// Only adding Items to IT_SPAWN_ITEM
		return;

	for ( unsigned char i = 0; i < iMax; i++ )
	{
		if ( m_obj[i] == uid )	// Not adding me again
			return;
		if ( !m_obj[i].ObjFind() )
		{
			m_obj[i] = uid;
			if (bIsSpawnChar)
			{
				m_itSpawnChar.m_current++;
				uid.CharFind()->StatFlag_Set(STATF_Spawned);
			}
			uid.ObjFind()->m_uidSpawnItem = GetUID();
			break;
		}
	}
}
コード例 #2
0
ファイル: CItemSp.cpp プロジェクト: zolter/Source
// Storing one UID in Spawn's m_obj[]
void CItemSpawn::AddObj( CGrayUID uid )
{
	ADDTOCALLSTACK("CitemSpawn:AddObj");
	unsigned char iMax = GetAmount() > 0 ? static_cast<unsigned char>(GetAmount()) : 1;
	iMax += 1;	// We must give a +1 to create a 'free slot'
	bool bIsSpawnChar = GetType() == IT_SPAWN_CHAR;
	if  (bIsSpawnChar )
	{
		if (!uid || !uid.CharFind()->m_pNPC)	// Only adding UIDs...
			return;
	}
	if ( uid.ObjFind()->m_uidSpawnItem.ItemFind() )	//... which doesn't have a SpawnItem already
		return;
	for ( unsigned char i = 0; i < iMax; i++ )
	{
		if ( m_obj[i] == uid )	// Not adding me again
			return;
		if ( !m_obj[i].ObjFind() )
		{
			m_obj[i] = uid;
			if (bIsSpawnChar)
			{
				m_itSpawnChar.m_current++;
				uid.CharFind()->StatFlag_Set(STATF_Spawned);
			}
			uid.ObjFind()->m_uidSpawnItem = GetUID();
			break;
		}
	}
}
コード例 #3
0
void Menu::CreateMenu(LPCSTR s,lpRLCFont f,lpRLCFont f1,fnc* ff,int style){
	if(!int(items))delete((void*)items);
	items=new(char[strlen(s)+1]);
	memcpy((void*)items,s,strlen(s)+1);
	NItems=GetAmount();
	font=f;
	font1=f1;
	NZones=NItems;
	ItemLy=GetRLCHeight(font->RLC,font->FirstSymbol+'W');
	MenuLy=ItemLy*NItems;
	StartY=(RSCRSizeY-MenuLy)/2;
	int Ly=0;
	for(int i=0;i<NItems;i++){
		LPCSTR ss=GetNstr(i);
		int Lx=GetLen(ss);
		Zone[i].x=(COPYSizeX-Lx)/2+100;
		Zone[i].y=StartY+i*ItemLy;
		Zone[i].x1=Zone[i].x+Lx;
		Zone[i].y1=Zone[i].y+ItemLy;
	};
	
	RedrawBackground=ff;
	Active=style&1?true:false;
	MakeShift=style&2?true:false;
	ChangeFont=style&4?true:false;
	EraseOnChoose=style&8?true:false;
};
コード例 #4
0
ファイル: CItemSpawn.cpp プロジェクト: DarkLotus/Source
bool CItemSpawn::r_WriteVal(LPCTSTR pszKey, CGString & sVal, CTextConsole *pSrc)
{
	ADDTOCALLSTACK("CitemSpawn:r_WriteVal");
	EXC_TRY("WriteVal");
	if (!strnicmp(pszKey, "amount", 6))
	{
		sVal.FormatVal(GetAmount());
		return true;
	}
	else if ( !strnicmp(pszKey, "at.", 3) )
	{
		pszKey += 3;
		int objIndex = Exp_GetVal(pszKey);
		if ( m_obj[objIndex].ItemFind() )
			return m_obj[objIndex].ItemFind()->r_WriteVal(pszKey, sVal, pSrc);
		else if ( m_obj[objIndex].CharFind() )
			return m_obj[objIndex].CharFind()->r_WriteVal(pszKey, sVal, pSrc);
		return true;
	}
	else if ( !strnicmp(pszKey, "count", 5) )
	{
		sVal.FormatVal(GetCount());
		return true;
	}
	EXC_CATCH;
	return CItem::r_WriteVal(pszKey, sVal, pSrc);
}
コード例 #5
0
ファイル: CItemVend.cpp プロジェクト: DarkLotus/Source
void CItemVendable::Restock( bool fSellToPlayers )
{
	ADDTOCALLSTACK("CItemVendable::Restock");
	// This is on a non-pet vendor.
	// allow prices to fluctuate randomly (per vendor) but hold the values for a bit.

	ASSERT( IsItemInContainer());
	if ( m_price < 0 )
		m_price = 0;	// signal to recalc this later.

	if ( fSellToPlayers )
	{
		// restock to my full amount.

		int iAmountRestock = GetContainedLayer();
		if ( ! iAmountRestock )
		{
			SetContainedLayer(1);
			iAmountRestock = 1;
		}
		if ( GetAmount() < iAmountRestock )
		{
			SetAmount( iAmountRestock );	// restock amount
		}
	}
	else
	{
		// Clear the amount i have bought from players.
		// GetAmount() is the max that i will buy in the next period.
		SetContainedLayer(0);
	}
}
コード例 #6
0
ファイル: CItemSpawn.cpp プロジェクト: DarkLotus/Source
void CItemSpawn::GenerateItem(CResourceDef *pDef)
{
	ADDTOCALLSTACK("CitemSpawn:GenerateItem");

	RESOURCE_ID_BASE rid = pDef->GetResourceID();
	ITEMID_TYPE id = static_cast<ITEMID_TYPE>(rid.GetResIndex());

	CItemContainer *pCont = dynamic_cast<CItemContainer *>(GetParent());
	BYTE iCount = pCont ? static_cast<unsigned char>(pCont->ContentCount(rid)) : GetCount();
	if ( iCount >= GetAmount() )
		return;

	CItem *pItem = CreateTemplate(id);
	if ( pItem == NULL )
		return;

	WORD iAmountPile = static_cast<WORD>(minimum(USHRT_MAX,m_itSpawnItem.m_pile));
	if ( iAmountPile > 1 )
	{
		CItemBase *pItemDef = pItem->Item_GetDef();
		ASSERT(pItemDef);
		if ( pItemDef->IsStackableType() )
			pItem->SetAmount(Calc_GetRandVal(iAmountPile) + 1);
	}

	pItem->SetAttr(m_Attr & (ATTR_OWNED | ATTR_MOVE_ALWAYS));
	pItem->SetDecayTime(g_Cfg.m_iDecay_Item);	// it will decay eventually to be replaced later
	pItem->MoveNearObj(this, m_itSpawnItem.m_DistMax);
	AddObj(pItem->GetUID());
}
コード例 #7
0
ファイル: CItemSpawn.cpp プロジェクト: DarkLotus/Source
void CItemSpawn::OnTick(bool fExec)
{
	ADDTOCALLSTACK("CitemSpawn:OnTick");

	INT64 iMinutes;

	if ( m_itSpawnChar.m_TimeHiMin <= 0 )
		iMinutes = Calc_GetRandLLVal(30) + 1;
	else
		iMinutes = minimum(m_itSpawnChar.m_TimeHiMin, m_itSpawnChar.m_TimeLoMin) + Calc_GetRandLLVal(abs(m_itSpawnChar.m_TimeHiMin - m_itSpawnChar.m_TimeLoMin));

	if ( iMinutes <= 0 )
		iMinutes = 1;

	if ( !fExec || IsTimerExpired() )
		SetTimeout(iMinutes * 60 * TICK_PER_SEC);	// set time to check again.

	if ( !fExec || m_currentSpawned >= GetAmount() )
		return;

	CResourceDef *pDef = FixDef();
	if ( !pDef )
	{
		RESOURCE_ID_BASE rid = IsType(IT_SPAWN_ITEM) ? m_itSpawnItem.m_ItemID : m_itSpawnChar.m_CharID;
		DEBUG_ERR(("Bad Spawn point uid=0%lx, id=%s\n", (DWORD)GetUID(), g_Cfg.ResourceGetName(rid)));
		return;
	}

	if ( IsType(IT_SPAWN_ITEM) )
		GenerateItem(pDef);
	else
		GenerateChar(pDef);
}
コード例 #8
0
ファイル: CItemSpawn.cpp プロジェクト: DarkLotus/Source
void CItemSpawn::AddObj(CGrayUID uid)
{
	ADDTOCALLSTACK("CitemSpawn:AddObj");
	// NOTE: This function is also called when loading spawn items
	// on server startup. In this case, some objs UID still invalid
	// (not loaded yet) so just proceed without any checks.

	bool bIsSpawnChar = IsType(IT_SPAWN_CHAR);
	if ( !g_Serv.IsLoading() )
	{
		if ( !uid.IsValidUID() )
			return;

		if ( bIsSpawnChar )				// IT_SPAWN_CHAR can only spawn NPCs
		{
			CChar *pChar = uid.CharFind();
			if ( !pChar || !pChar->m_pNPC )
				return;
		}
		else if ( !uid.ItemFind() )		// IT_SPAWN_ITEM can only spawn items
			return;

		CItemSpawn *pPrevSpawn = static_cast<CItemSpawn*>(uid.ObjFind()->m_uidSpawnItem.ItemFind());
		if ( pPrevSpawn )
		{
			if ( pPrevSpawn == this )		// obj already linked to this spawn
				return;
			pPrevSpawn->DelObj(uid);		// obj linked to other spawn, remove the link before proceed
		}
	}

	BYTE iMax = maximum(GetAmount(), 1);
	for (BYTE i = 0; i < iMax; i++ )
	{
		if ( !m_obj[i].IsValidUID() )
		{
			m_obj[i] = uid;
			m_currentSpawned++;

			// objects are linked to the spawn at each server start
			if ( !g_Serv.IsLoading() )
			{
				uid.ObjFind()->m_uidSpawnItem = GetUID();
				if ( bIsSpawnChar )
				{
					CChar *pChar = uid.CharFind();
					ASSERT(pChar->m_pNPC);
					pChar->StatFlag_Set(STATF_Spawned);
					pChar->m_ptHome = GetTopPoint();
					pChar->m_pNPC->m_Home_Dist_Wander = static_cast<WORD>(m_itSpawnChar.m_DistMax);
				}
			}
			break;
		}
	}
	if ( !g_Serv.IsLoading() )
		ResendTooltip();
}
コード例 #9
0
ファイル: CItemSpawn.cpp プロジェクト: leandrorenato/Source
void CItemSpawn::GenerateItem(CResourceDef * pDef)
{
	ADDTOCALLSTACK("CitemSpawn:GenerateItem");

	RESOURCE_ID_BASE rid = pDef->GetResourceID();
	ITEMID_TYPE id = static_cast<ITEMID_TYPE>(rid.GetResIndex());
	int iDistMax = m_itSpawnItem.m_DistMax;
	int iAmountPile = m_itSpawnItem.m_pile;

	int iCount = 0;
	CItemContainer * pCont = dynamic_cast <CItemContainer *>( GetParent());

	if ( pCont != NULL )
		iCount = pCont->ContentCount( rid );
	else
		iCount = GetCount();

	if ( iCount >= GetAmount())
		return;

	CItem * pItem = CreateTemplate( id );
	if ( pItem == NULL )
		return;

	pItem->SetAttr( m_Attr & ( ATTR_OWNED | ATTR_MOVE_ALWAYS ));

	if ( iAmountPile > 1 )
	{
		CItemBase * pItemDef = pItem->Item_GetDef();
		ASSERT(pItemDef);
		if ( pItemDef->IsStackableType())
		{
			if ( iAmountPile == 0 || iAmountPile > GetAmount())
				iAmountPile = GetAmount();
			pItem->SetAmount( Calc_GetRandVal(iAmountPile) + 1 );
		}
	}

	pItem->SetDecayTime( g_Cfg.m_iDecay_Item );	// It will decay eventually to be replaced later.
	pItem->MoveNearObj( this, iDistMax );
	AddObj(pItem->GetUID());
	pItem->m_uidSpawnItem = GetUID();
}
コード例 #10
0
ファイル: ActiveMember.cpp プロジェクト: layerfsd/PersonalIBA
CString CActiveMember::GetAmountAsString()
{
	CString strTmp;

	// 2011/05/19-gxx: 如果是开户包时的话也可以得到消费金额
	// 2011/06/14-gxx: 消费金额不为0,都显示
	if (GetIsOnLine() || GetIsRegisterBT() || GetAmount()!=0)
	{
		double dblTmp = GetAmount() / 100.0;

#ifdef __USING_INTER_RESOURCE
		strTmp.Format(_T("¥%.2f"), dblTmp);
#else
		strTmp.Format(_T("%.2f"), dblTmp);
#endif
	}

	return strTmp;
}
コード例 #11
0
void UDamageSpawnTrigger::BossHealthChange(FHealthChange damage) {
	if (GetBoss() != NULL && GetAmount() > 0 && !damage.heals) {
		// Convert damage taken to a percent of the bosses maxHealth
		float healthPercent = damage.healthChange / GetBoss()->GetMaxHealth();
		percentDamageTaken += healthPercent;

		while (percentDamageTaken >= percent && GetAmount() > 0) {
			percentDamageTaken -= percent;

			// Spawn adds
			if (OnTrigger.IsBound()) {
				OnTrigger.Broadcast();
				amount--;
			}
		}

		if (amount == 0) {
			GetBoss()->OnPostHealthChange.RemoveDynamic(this, &UDamageSpawnTrigger::BossHealthChange);
		}
	}
}
コード例 #12
0
ファイル: CItemSp.cpp プロジェクト: GenerationOfWorlds/Sphere
void CItem::Spawn_GenerateChar( CResourceDef * pDef )
{
	if ( ! IsTopLevel())
		return;	// creatures can only be top level.
	if ( m_itSpawnChar.m_current >= GetAmount())
		return;
	int iComplexity = GetTopSector()->GetCharComplexity();
	if ( iComplexity > g_Cfg.m_iMaxCharComplexity )
	{
		DEBUG_MSG(( "Spawn uid=0%lx too complex (%d>%d)\n", GetUID(), iComplexity, g_Cfg.m_iMaxCharComplexity ));
		return;
	}

	int iDistMax = m_itSpawnChar.m_DistMax;
	RESOURCE_ID_BASE rid = pDef->GetResourceID();
	if ( rid.GetResType() == RES_SPAWN )
	{
		const CRandGroupDef * pSpawnGroup = STATIC_CAST <const CRandGroupDef *>(pDef);
		ASSERT(pSpawnGroup);
		int i = pSpawnGroup->GetRandMemberIndex();
		if ( i >= 0 )
		{
			rid = pSpawnGroup->GetMemberID(i);
		}
	}
	
	CREID_TYPE id;
	if ( rid.GetResType() == RES_CHARDEF || 
		rid.GetResType() == RES_UNKNOWN )
	{
		id = (CREID_TYPE) rid.GetResIndex();
	}
	else
	{
		return;
	}

	CChar * pChar = CChar::CreateNPC( id );
	if ( pChar == NULL )
		return;
	ASSERT(pChar->m_pNPC);

	m_itSpawnChar.m_current ++;
	pChar->Memory_AddObjTypes( this, MEMORY_ISPAWNED );
	// Move to spot "near" the spawn item.
	pChar->MoveNearObj( this, iDistMax );
	if ( iDistMax )
	{
		pChar->m_ptHome = GetTopPoint();
		pChar->m_pNPC->m_Home_Dist_Wander = iDistMax;
	}
	pChar->Update();
}
コード例 #13
0
bool CItemStone::CheckValidMember( CStoneMember * pMember )
{
	ADDTOCALLSTACK("CItemStone::CheckValidMember");
	ASSERT(pMember);
	ASSERT( pMember->GetParent() == this );

	if ( GetAmount()==0 || g_Serv.m_iExitFlag )	// no reason to elect new if the stone is dead.
		return( true );	// we are deleting anyhow.

	switch ( pMember->GetPriv())
	{
		case STONEPRIV_MASTER:
		case STONEPRIV_MEMBER:
		case STONEPRIV_CANDIDATE:
		case STONEPRIV_ACCEPTED:
			if ( GetMemoryType())
			{
				// Make sure the member has a memory that links them back here.
				CChar * pChar = pMember->GetLinkUID().CharFind();
				if ( pChar == NULL )
					break;
				if ( pChar->Guild_Find( GetMemoryType()) != this )
					break;
			}
			return( true );
		case STONEPRIV_ENEMY:
			{
				CItemStone * pEnemyStone = dynamic_cast <CItemStone *>( pMember->GetLinkUID().ItemFind());
				if ( pEnemyStone == NULL )
					break;
				CStoneMember * pEnemyMember = pEnemyStone->GetMember(this);
				if ( pEnemyMember == NULL )
					break;
				if ( pMember->GetWeDeclared() && ! pEnemyMember->GetTheyDeclared())
					break;
				if ( pMember->GetTheyDeclared() && ! pEnemyMember->GetWeDeclared())
					break;
			}
			return( true );

		default:
			break;
	}

	// just delete this member. (it is mislinked)
	DEBUG_ERR(( "Stone UID=0%lx has mislinked member uid=0%lx\n", 
		(DWORD) GetUID(), (DWORD) pMember->GetLinkUID()));
	return( false );
}
コード例 #14
0
ファイル: CItemSpawn.cpp プロジェクト: DarkLotus/Source
void  CItemSpawn::r_Write(CScript & s)
{
	ADDTOCALLSTACK("CitemSpawn:r_Write");
	EXC_TRY("Write");
	CItem::r_Write(s);

	if ( GetAmount() != 1 )
		s.WriteKeyVal("AMOUNT", GetAmount());

	WORD iTotal = GetCount();
	if ( iTotal <= 0 )
		return;

	for ( BYTE i = 0; i < iTotal; i++ )
	{
		if ( !m_obj[i].IsValidUID() )
			continue;
		CObjBase *pObj = m_obj[i].ObjFind();
		if ( pObj )
			s.WriteKeyHex("ADDOBJ", pObj->GetUID());
	}

	EXC_CATCH;
}
コード例 #15
0
ファイル: Item.cpp プロジェクト: belven/Mech_RPG
void AItem::TakeFrom(AItem* otherItem) {
	// Get the amount of items needed to add
	int amountToAdd = otherItem->GetAmount();

	// Can we just add to this item
	if (GetRemainingSpace() >= amountToAdd) {
		SetAmount(GetAmount() + otherItem->GetAmount());
		otherItem->SetAmount(0);
	}
	else {
		// If we're greater than stack size just set the amount to max size
		otherItem->SetAmount(otherItem->GetAmount() - GetRemainingSpace());
		SetAmount(GetStackSize());
	}
}
コード例 #16
0
ファイル: lookdlg.c プロジェクト: AlleyCat1976/Meridian59_103
/*
 * GetAmountListBox:  If appropriate, display amount dialog to get amount
 *   of object at given index in given list box.
 *   Return True iff item should be selected (i.e. user entered valid #)
 */
Bool GetAmountListBox(HWND hList, int index)
{
   object_node *obj;
   MEASUREITEMSTRUCT m;

   /* See if item requires an amount */
   obj = (object_node *) ListBox_GetItemData(hList, index);
   if (obj == NULL || !IsNumberObj(obj->id))
      return True;

   /* Place amount dialog just beneath selected item */
   ItemListMeasureItem(hList, &m);

   return GetAmount(GetParent(hList), hList, obj, 0, 
		    (index - ListBox_GetTopIndex(hList) + 1) * (m.itemHeight - 1));
}
コード例 #17
0
ファイル: CGoods.cpp プロジェクト: xiongshaogang/mmo-resourse
bool CGoods::SerializeForRgnDisplay(DBWriteSet& setWriteDB,bool b)
{
	bool bResult=false;
	CGoodsBaseProperties* pProperties = GoodsSetup::QueryGoodsBaseProperties(
		GetBasePropertiesIndex() );
	if( pProperties )
	{
		setWriteDB.AddToByteArray( GetBasePropertiesIndex() );		
		setWriteDB.AddToByteArray( GetAmount() );
		setWriteDB.AddToByteArray(GetPosX());
		setWriteDB.AddToByteArray(GetPosY());
		long lLev=GetAddonPropertyValues(GAP_WEAPON_LEVEL,1);
		setWriteDB.AddToByteArray(lLev);
		bResult=true;
	}
	return bResult;
}
コード例 #18
0
ファイル: inventry.c プロジェクト: Tigerwhit4/Meridian59
/*
 * InventoryDropCurrentItem:  Drop the item with the inventory cursor, if any.
 *   If container is not NULL, put item in the container.
 *   Ask user for amount of object if appropriate.
 *   Return True iff object dropped.
 */
Bool InventoryDropCurrentItem(room_contents_node *container)
{
    int x, y;
    InvItem *item;

    item = InventoryGetCurrentItem();
    if (item == NULL)
        return False;

    x = cursor_col * INVENTORY_BOX_WIDTH;
    y = (cursor_row - top_row + 1) * INVENTORY_BOX_HEIGHT;
    if (!GetAmount(cinfo->hMain, hwndInv, item->obj, x, y))
        return False;

    if (container == NULL)
        RequestDrop(item->obj);
    else RequestPut(item->obj, container->obj.id);
    return True;
}
コード例 #19
0
ファイル: cargomonitor.cpp プロジェクト: IchiroWang/OpenTTD
/**
 * Get the amount of cargo delivered for the given cargo monitor since activation or last query.
 * @param monitor Cargo monitor to query.
 * @param keep_monitoring After returning from this call, continue monitoring.
 * @return Amount of delivered cargo for the monitored combination.
 */
int32 GetDeliveryAmount(CargoMonitorID monitor, bool keep_monitoring)
{
	return GetAmount(_cargo_deliveries, monitor, keep_monitoring);
}
コード例 #20
0
ファイル: Item.cpp プロジェクト: belven/Mech_RPG
AItem* AItem::Copy() {
	return CreateItem(GetWorld(), GetItemOwner(), GetName(), GetAmount(), GetGrade(), GetQuality(), GetStackSize());
}
コード例 #21
0
ファイル: Item.cpp プロジェクト: belven/Mech_RPG
int32 AItem::GetRemainingSpace() {
	return GetStackSize() - GetAmount();
}
コード例 #22
0
ファイル: Gold.cpp プロジェクト: Pessu/AdventureGame
// Overloaded addition operator for gold class
Gold & Gold::operator+(const Gold & gold)
{
	int total = GetAmount() + gold.m_nAmount;
	SetAmount(total);
	return *this;
}
コード例 #23
0
ファイル: Item.cpp プロジェクト: belven/Mech_RPG
bool AItem::HasSpace() {
	return GetAmount() < GetStackSize();
}
コード例 #24
0
ファイル: CItemSp.cpp プロジェクト: GenerationOfWorlds/Sphere
void CItem::Spawn_GenerateItem( CResourceDef * pDef )
{
	// Count how many items are here already.
	// This could be in a container.

	RESOURCE_ID_BASE rid = pDef->GetResourceID();
	ITEMID_TYPE id = (ITEMID_TYPE) rid.GetResIndex();
	int iDistMax = m_itSpawnItem.m_DistMax;
	int iAmountPile = m_itSpawnItem.m_pile;

	int iCount = 0;
	CItemContainer * pCont = dynamic_cast <CItemContainer *>( GetParent());
	if ( pCont != NULL )
	{
		iCount = pCont->ContentCount( rid );
	}
	else
	{
		// If is equipped this will produce the item where you are standing.
		CPointMap pt = GetTopLevelObj()->GetTopPoint();
		CWorldSearch AreaItems( pt, iDistMax );
		while (true)
		{
			CItem * pItem = AreaItems.GetItem();
			if ( pItem == NULL )
				break;
			if ( pItem->IsType(IT_SPAWN_ITEM))
				continue;
			if ( pItem->IsAttr( ATTR_INVIS ))
				continue;
			if ( pItem->GetID() != id )
				continue;
			// if ( pItem->m_uidLink != GetUID()) continue;
			iCount += pItem->GetAmount();
		}
	}
	if ( iCount >= GetAmount())
		return;

	CItem * pItem = CreateTemplate( id );
	if ( pItem == NULL )
		return;

	pItem->SetAttr( m_Attr & ( ATTR_OWNED | ATTR_MOVE_ALWAYS ));

	if ( iAmountPile > 1 )
	{
		CItemBase * pItemDef = pItem->Item_GetDef();
		ASSERT(pItemDef);
		if ( pItemDef->IsStackableType())
		{
			if ( iAmountPile == 0 || iAmountPile > GetAmount())
				iAmountPile = GetAmount();
			pItem->SetAmount( Calc_GetRandVal(iAmountPile) + 1 );
		}
	}

	// pItem->m_uidLink = GetUID();	// This might be dangerous ?
	pItem->SetDecayTime( g_Cfg.m_iDecay_Item );	// It will decay eventually to be replaced later.
	pItem->MoveNearObj( this, iDistMax );
}
コード例 #25
0
void CItemStone::ElectMaster()
{
	ADDTOCALLSTACK("CItemStone::ElectMaster");
	// Check who is loyal to who and find the new master.
	if ( GetAmount() == 0 )
		return;	// no reason to elect new if the stone is dead.

	int iResultCode = FixWeirdness();	// try to eliminate bad members.
	if ( iResultCode )
	{
		// The stone is bad ?
		// iResultCode
	}

	int iCountMembers = 0;
	CStoneMember * pMaster = NULL;

	// Validate the items and Clear the votes field
	CStoneMember * pMember = STATIC_CAST <CStoneMember *>(GetHead());
	for ( ; pMember != NULL; pMember = pMember->GetNext())
	{
		if ( pMember->GetPriv() == STONEPRIV_MASTER )
		{
			pMaster = pMember;	// find current master.
		}
		else if ( pMember->GetPriv() != STONEPRIV_MEMBER )
		{
			continue;
		}
		pMember->m_Member.m_iVoteTally = 0;
		iCountMembers++;
	}

	// Now tally the votes.
	pMember = STATIC_CAST <CStoneMember *>(GetHead());
	for ( ; pMember != NULL; pMember = pMember->GetNext())
	{
		if ( ! pMember->IsPrivMember())
			continue;

		CChar * pCharVote = pMember->GetLoyalToUID().CharFind();
		if ( pCharVote != NULL )
		{
			CStoneMember * pMemberVote = GetMember( pCharVote );
			if ( pMemberVote != NULL )
			{
				pMemberVote->m_Member.m_iVoteTally ++;
				continue;
			}
		}

		// not valid to vote for. change to self.
		pMember->SetLoyalTo(NULL);
		// Assume I voted for myself.
		pMember->m_Member.m_iVoteTally ++;
	}

	// Find who won.
	bool fTie = false;
	CStoneMember * pMemberHighest = NULL;
	pMember = STATIC_CAST <CStoneMember *>(GetHead());
	for ( ; pMember != NULL; pMember = pMember->GetNext())
	{
		if ( ! pMember->IsPrivMember())
			continue;
		if ( pMemberHighest == NULL )
		{
			pMemberHighest = pMember;
			continue;
		}
		if ( pMember->m_Member.m_iVoteTally == pMemberHighest->m_Member.m_iVoteTally )
		{
			fTie = true;
		}
		if ( pMember->m_Member.m_iVoteTally > pMemberHighest->m_Member.m_iVoteTally )
		{
			fTie = false;
			pMemberHighest = pMember;
		}
	}

	// In the event of a tie, leave the current master as is
	if ( ! fTie && pMemberHighest )
	{
		if (pMaster)
			pMaster->SetPriv(STONEPRIV_MEMBER);
		pMemberHighest->SetPriv(STONEPRIV_MASTER);
	}

	if ( ! iCountMembers )
	{
		// No more members, declare peace (by force)
		pMember = STATIC_CAST <CStoneMember *>(GetHead());
		for (; pMember != NULL; pMember = pMember->GetNext())
		{
			WeDeclarePeace(pMember->GetLinkUID(), true);
		}
	}
}
コード例 #26
0
ファイル: CItemSpawn.cpp プロジェクト: leandrorenato/Source
void CItemSpawn::KillChildren()
{
	ADDTOCALLSTACK("CitemSpawn:KillChildren");
	WORD iTotal = GetType() == IT_SPAWN_CHAR ? static_cast<WORD>(m_itSpawnChar.m_current) : GetAmount(); //m_itSpawnItem doesn't have m_current, it uses more2 to set the amount of items spawned in each tick, so i'm using its amount to perform the loop
	if ( iTotal <= 0 )
		return;
	for ( WORD i = 0; i < iTotal; i++ )
	{
		CObjBase * pObj = m_obj[i].ObjFind();
		if ( !pObj )
			continue;
		pObj->m_uidSpawnItem.InitUID();
		pObj->Delete();
		m_obj[i].InitUID();

	}
	m_itSpawnChar.m_current = 0;
	OnTick(false);
}
コード例 #27
0
ファイル: cargomonitor.cpp プロジェクト: IchiroWang/OpenTTD
/**
 * Get the amount of cargo picked up for the given cargo monitor since activation or last query.
 * @param monitor Monitoring number to query.
 * @param keep_monitoring After returning from this call, continue monitoring.
 * @return Amount of picked up cargo for the monitored combination.
 * @note Cargo pick up is counted on final delivery, to prevent users getting credit for picking up cargo without delivering it.
 */
int32 GetPickupAmount(CargoMonitorID monitor, bool keep_monitoring)
{
	return GetAmount(_cargo_pickups, monitor, keep_monitoring);
}
コード例 #28
0
ファイル: CItemSpawn.cpp プロジェクト: leandrorenato/Source
void CItemSpawn::GenerateChar(CResourceDef * pDef)
{
	ADDTOCALLSTACK("CitemSpawn:GenerateChar");
	if ( !IsTopLevel() || ( m_itSpawnChar.m_current >= GetAmount() ) || ( GetTopSector()->GetCharComplexity() > g_Cfg.m_iMaxCharComplexity ))
		return;

	int iDistMax = m_itSpawnChar.m_DistMax;
	RESOURCE_ID_BASE rid = pDef->GetResourceID();
	if ( rid.GetResType() == RES_SPAWN )
	{
		const CRandGroupDef * pSpawnGroup = STATIC_CAST <const CRandGroupDef *>(pDef);
		ASSERT(pSpawnGroup);
		size_t i = pSpawnGroup->GetRandMemberIndex();
		if ( i != pSpawnGroup->BadMemberIndex() )
		{
			rid = pSpawnGroup->GetMemberID(i);
		}
	}

	if (( rid.GetResType() != RES_CHARDEF ) && ( rid.GetResType() != RES_UNKNOWN ))
		return;

	CREID_TYPE id = static_cast<CREID_TYPE>(rid.GetResIndex());

	bool isBadPlaceToSpawn = false;
	CChar * pChar = CChar::CreateBasic(id);
	if( pChar == NULL )
	{
		return;
	}

	pChar->NPC_LoadScript(true);
	AddObj(pChar->GetUID());
	pChar->m_uidSpawnItem = GetUID();		// SpawnItem for this char
	pChar->StatFlag_Set( STATF_Spawned );
	pChar->MoveTo(GetTopPoint());
	pChar->NPC_CreateTrigger(); //Removed from NPC_LoadScript() and triggered after char placement

	if( pChar->GetRegion() == NULL )
	{
		isBadPlaceToSpawn = true;
	}
	else if( pChar->GetRegion()->IsGuarded() && pChar->Noto_IsEvil() )
	{
		isBadPlaceToSpawn = true;
	}

	// Deny definitely known a bad place to spawn (like red NPCs in guarded areas)
	// Usually caused by wide range near the edge of the towns
	if( isBadPlaceToSpawn )
	{
		pChar->Delete();
		//m_itSpawnChar.m_current--;
		return;
	}

	ASSERT(pChar->m_pNPC);
	if ( iDistMax )
	{
		pChar->m_ptHome = GetTopPoint();
		pChar->m_pNPC->m_Home_Dist_Wander = static_cast<WORD>(iDistMax);
	}
	pChar->Update();

}
コード例 #29
0
ファイル: CGoods.cpp プロジェクト: xiongshaogang/mmo-resourse
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;
}
コード例 #30
0
ファイル: ActiveMember.cpp プロジェクト: layerfsd/PersonalIBA
UINT CActiveMember::GetLocalExpense(BOOL bFilter)
{
	if (PolicyInfo.IsEmpty())
	{
		return GetAmount();
	}
	if (PolicyInfo.GetLength() != 24*4)
	{
		IBA_ASSERT2(FALSE, "warning:扣率信息有误");
		CIBALog::GetInstance()->WriteFormat(_T("本地用户扣率信息有误,netId=%s, 扣率=%s"), NetId, PolicyInfo);
		return GetAmount();
	}
	if (CheckInTime.GetStatus() != COleDateTime::valid || CheckInTime == 0)
	{
		return GetAmount();
	}
	COleDateTime timeNow = COleDateTime::GetCurrentTime();
	COleDateTimeSpan timeSpan = timeNow - CheckInTime;

	UINT nPolicyHours[24] = {0};
	for (int i = 0; i < 96; i+=4)
	{
		nPolicyHours[i/4] = (UINT)_ttoi(PolicyInfo.Mid(i, 4));
	}

	double dExp = 0.0;
	int iStartHour = CheckInTime.GetHour();
	int iStartSecond = CheckInTime.GetSecond()+ CheckInTime.GetMinute()*60;
	int nTotalSecond = (int)timeSpan.GetTotalSeconds();
	for(int iSecond = nTotalSecond; iSecond > 0; )
	{
		if (nPolicyHours[iStartHour] == 0)
		{
			IBA_ASSERT2(FALSE,"warning:扣率信息有误,扣率为0");
			CIBALog::GetInstance()->WriteFormat(_T("本地用户扣率信息有误,netId=%s, 扣率=%s"), NetId, PolicyInfo);
			return GetAmount();
		}
		double dSecondPolicy = nPolicyHours[iStartHour%24] / 3600.0;

		int nSeconds = 3600 - iStartSecond;
		if (nSeconds >= iSecond)
		{
			nSeconds = iSecond;
		}
		
		dExp += dSecondPolicy * nSeconds;
		iSecond -= nSeconds;
		iStartHour ++;
		iStartSecond = 0; // 第一次循环以后,起始秒都为0
	}

	if (bFilter)
	{
		UINT nExp = UINT(dExp+49)/50*50;
		return nExp;
	}
	else
	{
		return UINT(dExp);
	}
	
}