Exemplo n.º 1
0
DropList::DropList (Window &win, const ItemList &items_, size_t default_select)
	: Control (win)
	, FocusColorControl (win)
	, items (items_.empty () ? ItemList (1) : items_)
	, select (default_select < items_.size () ? default_select : 0)
{
}
Exemplo n.º 2
0
DropList::DropList (Window &win, ItemList &&items_, size_t default_select)
	: Control (win)
	, FocusColorControl (win)
	, items (items_.empty () ? ItemList (1) : std::forward<ItemList> (items_))
	, select (default_select < items.size () ? default_select : 0)
{
}
Exemplo n.º 3
0
item_group::ItemList item_group::items_from( const Group_tag &group_id, int birthday )
{
    const auto group = item_controller->get_group( group_id );
    if( group == nullptr ) {
        return ItemList();
    }
    return group->create( birthday );
}
Exemplo n.º 4
0
void MetaContactStorage::onResultReady(const Payload::Ptr &payload, PrivateXml::Result result, const Error::Ptr &error)
{
	Q_UNUSED(error);
	Logger::debug() << "onResultReady";
	if(result == PrivateXml::RequestOk) {
		MetaContacts *metacontacts = payload_cast<MetaContacts*>(payload.data());
		Logger::debug() << "received metacontacts" << metacontacts << payload.data();
		if (metacontacts)
			emit metaContactsReceived(metacontacts->items);
		else
			emit metaContactsReceived(ItemList());
	}
}
Exemplo n.º 5
0
void AccumulateSystem (CTopologyNode *pNode, CSystem *pSystem, TSortMap<DWORD, STypeInfo> &AllTypes)
	{
	int j;

	int iSystemLevel = pSystem->GetLevel();

	//	Add the encounters to the appropriate tables

	for (j = 0; j < pSystem->GetObjectCount(); j++)
		{
		CSpaceObject *pObj = pSystem->GetObject(j);

		if (pObj)
			{
			//	Add this encounter to the table

			CDesignType *pType;
			if ((pType = pObj->GetEncounterInfo()) || (pType = pObj->GetType()))
				{
				STypeInfo *pInfo = AllTypes.SetAt(pType->GetUNID());
				pInfo->iTotalCount++;
				pInfo->PerLevel[iSystemLevel]++;
				}

			//	Enumerate the items in this object

			CItemListManipulator ItemList(pObj->GetItemList());
			ItemList.ResetCursor();
			while (ItemList.MoveCursorForward())
				{
				const CItem &Item(ItemList.GetItemAtCursor());

				if (!Item.IsInstalled() && !Item.IsDamaged())
					{
					STypeInfo *pInfo = AllTypes.SetAt(Item.GetType()->GetUNID());
					pInfo->iTotalCount += Item.GetCount();
					pInfo->PerLevel[iSystemLevel] += Item.GetCount();
					}
				}
			}
		}
	}
Exemplo n.º 6
0
CInstalledDevice *GetDeviceFromItem (CCodeChain &CC, CSpaceObject *pObj, ICCItem *pArg)

//	GetDeviceFromItem
//
//	Returns a device struct from an item struct (or NULL if not found)

	{
	//	Get the item

	CItem Item(CreateItemFromList(CC, pArg));

	//	Make sure the item is on the object

	CItemListManipulator ItemList(pObj->GetItemList());
	if (!ItemList.SetCursorAtItem(Item))
		return NULL;

	//	Get the installed device from the item

	CInstalledDevice *pDevice = pObj->FindDevice(Item);
	return pDevice;
	}
Exemplo n.º 7
0
const CItem *CItemCtx::GetItemPointer(void)

//	GetItemPointer
//
//	Returns a pointer to an item or NULL.
//	Note: We can't guarantee that the pointer will be valid across calls
//	to script (because an ItemTable might be moved around) so this
//	pointer should never be returned to callers.

	{
	//	If we've got it, done

	if (m_pItem)
		return m_pItem;

	//	If we have a source and device, find the item

	if (m_pDevice && m_pSource)
		return m_pDevice->GetItem();

	//	If we have a source and armor, find the item

	if (m_pArmor && m_pSource)
		{
		CItemListManipulator ItemList(m_pSource->GetItemList());
		m_pSource->SetCursorAtArmor(ItemList, m_pArmor);
		if (!ItemList.IsCursorValid())
			return NULL;

		return &ItemList.GetItemAtCursor();
		}

	//	Couldn't get it

	return NULL;
	}
Exemplo n.º 8
0
DGLE_RESULT DGLE_API Game::Update(uint uiDeltaTime)
{
	bool key_escape, pause;

	pInput->GetKey(KEY_ESCAPE, key_escape);

	if (key_escape)
		pEngineCore->QuitEngine();

	pInput->GetKey(KEY_P, pause);

	if (pause)
	{
		if (PauseChange)
		{
			Pause = !Pause;
			PauseChange = false;
		}
	}
	else
		PauseChange = true;

	if (!Pause)
	{
		bool key_right, key_left, key_down, key_up;

		pInput->GetKey(KEY_RIGHT, key_right);
		pInput->GetKey(KEY_LEFT, key_left);
		pInput->GetKey(KEY_DOWN, key_down);
		pInput->GetKey(KEY_UP, key_up);

		// update game objects
		GhostList().begin()->UpdateAngle();
		if (key_right)
		{
			GhostList().begin()->SetDirection(true, true);
			GhostList().begin()->Update();
		}
		else if (key_left)
		{
			GhostList().begin()->SetDirection(true, false);
			GhostList().begin()->Update();
		}
		else if (key_down)
		{
			GhostList().begin()->SetDirection(false, true);
			GhostList().begin()->Update();
		}
		else if (key_up)
		{
			GhostList().begin()->SetDirection(false, false);
			GhostList().begin()->Update();
		}

		for (auto it = ++GhostList().begin(); it != GhostList().end(); ++it)
			it->Update();

		// swallow score and special items
		for (auto it = cItemList().cbegin(); it != cItemList().cend();)
		{
			bool flag = false;
			if (IsBlackFlagSet())
				for (auto this_ghost = ++cGhostList().cbegin(); this_ghost != cGhostList().cend(); ++this_ghost)
					if (this_ghost->Swallow(*it))
						flag = true;

			if (cGhostList().cbegin()->Swallow(*it) || flag)
				it = ItemList().erase(it);
			else
				++it;
		}
		if (CurrentLevel > PreviousLevel)
		{
			RestartLevel(false);
			PreviousLevel = CurrentLevel;
		}

		// swallow player and ghosts
		for (auto this_ghost = ++cGhostList().cbegin(); this_ghost != cGhostList().cend(); ++this_ghost)
		{
			if (this_ghost->Swallow(*cGhostList().cbegin()))
			{
				if (Lives > 1)
				{
					RestartLevel(true);
					Lives--;
				}
				else
					NewGame();

				break;
			}
			else if (IsHelpFlagSet())
				for (auto it = ++cGhostList().cbegin(); it != cGhostList().cend();)
					if (this_ghost->Swallow(*it))
						it = GhostList().erase(it);
					else
						++it;
		}

		// additional updating AI
		if (!(Counter % 15))
			for (auto it = ++GhostList().begin(); it != GhostList().end(); ++it)
				it->UpdateAI(0.1, false);     //0.25

		++Counter;
	}

	return S_OK;
}
KitInformation::ItemList CMakePreloadCacheKitInformation::toUserOutput(const Kit *k) const
{
    return ItemList() << qMakePair(tr("CMake Preload"), k->value(id()).toString());
}
Exemplo n.º 10
0
bool CWeaponFireDesc::FireOnDamageShields (SDamageCtx &Ctx, int iDevice)

//	FireOnDamageShields
//
//	Fire OnDamageShields event. Returns TRUE if we should skip further shields damage

	{
	SEventHandlerDesc Event;
	if (FindEventHandler(evtOnDamageShields, &Event))
		{
		//	Setup arguments

		CCodeChainCtx CCCtx;

		CItemListManipulator ItemList(Ctx.pObj->GetItemList());
		CShip *pShip = Ctx.pObj->AsShip();
		if (pShip)
			pShip->SetCursorAtDevice(ItemList, iDevice);

		CCCtx.SaveAndDefineSourceVar(Ctx.pObj);
		CCCtx.DefineInteger(CONSTLIT("aArmorSeg"), Ctx.iSectHit);
		CCCtx.DefineInteger(CONSTLIT("aDevice"), iDevice);
		CCCtx.DefineItem(CONSTLIT("aDeviceItem"), ItemList.GetItemAtCursor());
		CCCtx.DefineSpaceObject(CONSTLIT("aCause"), Ctx.pCause);
		CCCtx.DefineSpaceObject(CONSTLIT("aAttacker"), Ctx.Attacker.GetObj());
		CCCtx.DefineSpaceObject(CONSTLIT("aOrderGiver"), (Ctx.Attacker.GetObj() ? Ctx.Attacker.GetObj()->GetOrderGiver(Ctx.Attacker.GetCause()) : NULL));
		CCCtx.DefineVector(CONSTLIT("aHitPos"), Ctx.vHitPos);
		CCCtx.DefineInteger(CONSTLIT("aHitDir"), Ctx.iDirection);
		CCCtx.DefineInteger(CONSTLIT("aDamageHP"), Ctx.iDamage);
		CCCtx.DefineString(CONSTLIT("aDamageType"), GetDamageShortName(Ctx.Damage.GetDamageType()));
		CCCtx.DefineItemType(CONSTLIT("aWeaponType"), Ctx.pDesc->GetWeaponType());

		CCCtx.DefineInteger(CONSTLIT("aShieldHP"), Ctx.iHPLeft);
		CCCtx.DefineInteger(CONSTLIT("aShieldDamageHP"), Ctx.iShieldDamage);
		CCCtx.DefineInteger(CONSTLIT("aArmorDamageHP"), Ctx.iDamage - Ctx.iAbsorb);
		if (Ctx.bReflect)
			{
			CCCtx.DefineString(CONSTLIT("aShieldReflect"), STR_SHIELD_REFLECT);
			CCCtx.DefineInteger(CONSTLIT("aOriginalShieldDamageHP"), Ctx.iOriginalShieldDamage);
			CCCtx.DefineInteger(CONSTLIT("aOriginalArmorDamageHP"), Ctx.iDamage - Ctx.iOriginalAbsorb);
			}
		else
			{
			CCCtx.DefineNil(CONSTLIT("aShieldReflect"));
			CCCtx.DefineInteger(CONSTLIT("aOriginalShieldDamageHP"), Ctx.iShieldDamage);
			CCCtx.DefineInteger(CONSTLIT("aOriginalArmorDamageHP"), Ctx.iDamage - Ctx.iAbsorb);
			}

		ICCItem *pResult = CCCtx.Run(Event);

		//	If we return Nil, then we continue processing

		bool bResult;
		if (pResult->IsNil())
			bResult = false;

		//	If this is an integer, we pass damage to armor

		else if (pResult->IsInteger())
			{
			Ctx.iDamage = pResult->GetIntegerValue();
			bResult = true;
			}

		//	If we return a list, then modify variables

		else if (pResult->IsList())
			{
			//	A single value means we modified the damage to armor

			if (pResult->GetCount() == 1)
				{
				if (strEquals(pResult->GetElement(0)->GetStringValue(), STR_SHIELD_REFLECT))
					{
					Ctx.bReflect = true;
					Ctx.iAbsorb = Ctx.iDamage;
					Ctx.iShieldDamage = 0;
					}
				else
					{
					Ctx.iShieldDamage = Max(0, Min(pResult->GetElement(0)->GetIntegerValue(), Ctx.iHPLeft));
					if (Ctx.bReflect)
						{
						Ctx.bReflect = false;
						Ctx.iAbsorb = Ctx.iOriginalAbsorb;
						}
					}
				}

			//	Two values mean we modified both damage to armor and shield damage

			else if (pResult->GetCount() == 2)
				{
				Ctx.bReflect = false;
				Ctx.iShieldDamage = Max(0, Min(pResult->GetElement(0)->GetIntegerValue(), Ctx.iHPLeft));
				Ctx.iAbsorb = Max(0, Ctx.iDamage - Max(0, pResult->GetElement(1)->GetIntegerValue()));
				}

			//	Otherwise, we deal with reflection

			else
				{
				Ctx.bReflect = strEquals(pResult->GetElement(0)->GetStringValue(), STR_SHIELD_REFLECT);
				Ctx.iShieldDamage = Max(0, Min(pResult->GetElement(1)->GetIntegerValue(), Ctx.iHPLeft));
				Ctx.iAbsorb = Max(0, Ctx.iDamage - Max(0, pResult->GetElement(2)->GetIntegerValue()));
				}

			//	Proceed with processing

			bResult = false;
			}

		//	If this is the string "reflect" then we reflect

		else if (strEquals(pResult->GetStringValue(), STR_SHIELD_REFLECT))
			{
			Ctx.bReflect = true;
			Ctx.iAbsorb = Ctx.iDamage;
			Ctx.iShieldDamage = 0;
			bResult = false;
			}

		//	Otherwise, error

		else
			{
			Ctx.pObj->ReportEventError(ON_DAMAGE_OVERLAY_EVENT, pResult);
			bResult = true;
			}

		CCCtx.Discard(pResult);

		return bResult;
		}
	else
		return false;
	}
Exemplo n.º 11
0
KitInformation::ItemList SysRootKitInformation::toUserOutput(Kit *k) const
{
    return ItemList() << qMakePair(tr("Sys Root"), sysRoot(k).toUserOutput());
}
Exemplo n.º 12
0
KitInformation::ItemList ToolChainKitInformation::toUserOutput(Kit *k) const
{
    ToolChain *tc = toolChain(k);
    return ItemList() << qMakePair(tr("Compiler"), tc ? tc->displayName() : tr("None"));
}
Exemplo n.º 13
0
void GenerateWeaponEffectChart (CUniverse &Universe, CXMLElement *pCmdLine)
	{
	int i;

	//	Compute the list of weapons to show, making sure we filter to weapons
	//	and missiles only.

	CItemTypeTable Selection;
	if (!Selection.Filter(pCmdLine->GetAttribute(CRITERIA_ATTRIB))
			|| (Selection.IsAll() && !Selection.Filter(CONSTLIT("wm"))))
		{
		printf("No entries match criteria.\n");
		return;
		}

	Selection.Sort();

	//	Ship to use

	DWORD dwPlatformUNID;
	if (!pCmdLine->FindAttributeInteger(SHIP_UNID_ATTRIB, (int *)&dwPlatformUNID))
		dwPlatformUNID = WEAPON_PLATFORM_UNID;

	//	Compute some metrics

	int iFramesPerItem = 10;
	int cxFrameHorzMargin = 10;
	int cxMaxDistPerTick = (int)(STD_SECONDS_PER_UPDATE * (LIGHT_SECOND / g_KlicksPerPixel));
	int cyFrame = 64;
	int cxFrame = (2 * cxFrameHorzMargin) + (iFramesPerItem * cxMaxDistPerTick);

	int iHitEffectFramesPerItem = 5;
	int cxHitEffect = 128;
	int cyHitEffect = 128;
	
	int cyRowTitle = 20;
	int cyRow = cyRowTitle + Max(ITEM_ICON_HEIGHT, cyFrame * iFramesPerItem);
	int cxRow = ITEM_ICON_WIDTH + cxFrame;

	int iColumns = Max(1, mathSqrt(Selection.GetCount()));
	int iRows = (Selection.GetCount() + (iColumns - 1)) / iColumns;

	int cxImage = cxRow * iColumns;
	int cyImage = cyRow * iRows;

	//	Initialize the output

	COutputChart Output;
	Output.SetContentSize(cxImage, cyImage);
	Output.SetOutputFilespec(pCmdLine->GetAttribute(CONSTLIT("output")));

	//	Initialize fonts

	Output.SetStyleFont(STYLE_TITLE, pCmdLine->GetAttribute(CONSTLIT("font")));
	Output.SetStyleColor(STYLE_TITLE, CG32bitPixel(0xFF, 0xFF, 0xFF));

	//	Prepare the universe

	CSystem *pSystem;
	if (Universe.CreateEmptyStarSystem(&pSystem) != NOERROR)
		{
		printf("ERROR: Unable to create empty star system.\n");
		return;
		}

	//	Create a target in the center of the system

	CSpaceObject *pStation;
	CStationType *pTargetType = Universe.FindStationType(TARGET_UNID);
	if (pTargetType == NULL 
			|| pSystem->CreateStation(pTargetType, NULL, CVector(), &pStation) != NOERROR)
		{
		printf("ERROR: Unable to create station.\n");
		return;
		}

	//	Create the weapon platform some distance away

	CSovereign *pPlatformSovereign = Universe.FindSovereign(PLAYER_SOVEREIGN_UNID);
	CShip *pPlatform;
	if (pPlatformSovereign == NULL
				|| pSystem->CreateShip(dwPlatformUNID,
					NULL,
					NULL,
					pPlatformSovereign,
					CVector(-5.0 * LIGHT_SECOND, 0.),
					CVector(),
					0,
					NULL,
					NULL,
					&pPlatform) != NOERROR)
		{
		printf("ERROR: Unable to create weapons platform.\n");
		return;
		}

	//	Set the attacker to hold

	IShipController *pController = pPlatform->GetController();
	if (pController == NULL)
		{
		printf("ERROR: No controller for ship.\n");
		return;
		}

	pController->AddOrder(IShipController::orderHold, NULL, IShipController::SData());
	pPlatform->SetControllerEnabled(false);

	//	Install the largest possible reactor on the ship

	CItemType *pReactorType = Universe.FindItemType(REACTOR_UNID);
	if (pReactorType)
		{
		CItem ReactorItem(pReactorType, 1);

		CItemListManipulator ItemList(pPlatform->GetItemList());
		ItemList.AddItem(ReactorItem);
		pPlatform->OnComponentChanged(comCargo);
		pPlatform->ItemsModified();
		pPlatform->InvalidateItemListAddRemove();

		pPlatform->InstallItemAsDevice(ItemList);
		}

	//	Set the POV

	Universe.SetPOV(pStation);
	pSystem->SetPOVLRS(pStation);

	//	Prepare system

	Universe.UpdateExtended();
	Universe.GarbageCollectLibraryBitmaps();
	Universe.StartGame(true);

	//	Output each weapon

	int xOrigin;
	int yOrigin;
	CG32bitImage &Image = Output.GetOutputImage(&xOrigin, &yOrigin);
	const CG16bitFont &TitleFont = Output.GetStyleFont(STYLE_TITLE);
	CG32bitPixel rgbTitleColor = Output.GetStyleColor(STYLE_TITLE);

	for (i = 0; i < Selection.GetCount(); i++)
		{
		CItemType *pType = Selection.GetItemType(i);

		//	Compute the metrics of this row

		int xRow = xOrigin + (i % iColumns) * cxRow;
		int yRow = yOrigin + (i / iColumns) * cyRow;

		//	Paint the weapon title

		Image.Fill(xRow, yRow, cxRow, cyRow, CG32bitPixel(0x40, 0x40, 0x40));
		TitleFont.DrawText(Image, xRow + 8, yRow, rgbTitleColor, pType->GetNounPhrase());

		//	Paint the frames

		PaintWeaponFrames(Image, pType, pPlatform, iFramesPerItem, 
				xRow + ITEM_ICON_WIDTH + cxFrameHorzMargin,
				yRow + cyRowTitle, 
				cxMaxDistPerTick,
				cyFrame);
		}

	//	Done

	Output.Output();
	}
Exemplo n.º 14
0
void PaintWeaponFrames (CG32bitImage &Image, CItemType *pType, CShip *pPlatform, int iFrames, int x, int y, int cxCell, int cyCell)
	{
	int i, j;

	Metric rFireDist = 18.0 * LIGHT_SECOND;

	//	Make sure we're refueled and in position

	pPlatform->Place(CVector(-rFireDist, 0.0));
	pPlatform->Refuel(pPlatform->GetMaxFuel());
	CItemListManipulator ItemList(pPlatform->GetItemList());

	//	Get the device and weapon fire desc for this item. The call will do the
	//	right thing if this is a missile.

	CDeviceClass *pWeapon;
	int iVariant;
	CWeaponFireDesc *pDesc;
	if (!CDeviceClass::FindWeaponFor(pType, &pWeapon, &iVariant, &pDesc))
		{
		printf("ERROR: Unable to find weapon for ammo.\n");
		return;
		}

	//	Compute the number of ticks that we need to cover the distance

	Metric rDist = rFireDist - (60 * g_KlicksPerPixel);
	Metric rSpeed = pDesc->GetRatedSpeed();
	Metric rTime = (rSpeed > 0.0 ? (rDist / pDesc->GetRatedSpeed()) : 0.0);
	int iFrameToSkip = iFrames / 4;
	int iTicksToHit = (int)(rTime / STD_SECONDS_PER_UPDATE) - iFrameToSkip - 4;

	//	If the item is a missile, create one to fire

	CItemType *pAmmoType = pDesc->GetAmmoType();
	if (pAmmoType)
		{
		CItem MissileItem(pAmmoType, 1);
		ItemList.AddItem(MissileItem);

		pPlatform->OnComponentChanged(comCargo);
		pPlatform->ItemsModified();
		pPlatform->InvalidateItemListAddRemove();
		}

	//	Install the appropriate weapon on the platform

	CItem WeaponItem(pWeapon->GetItemType(), 1);
	ItemList.AddItem(WeaponItem);

	pPlatform->OnComponentChanged(comCargo);
	pPlatform->ItemsModified();
	pPlatform->InvalidateItemListAddRemove();

	pPlatform->InstallItemAsDevice(ItemList);

	//	Select the weapon (we rely on the fact that this is the current
	//	item in the list).

	DeviceNames iDev = pPlatform->SelectWeapon(ItemList.GetItemAtCursor().GetInstalled(), iVariant);
	CInstalledDevice *pInstalledDevice = pPlatform->GetNamedDevice(iDev);
	if (pInstalledDevice == NULL
			|| pInstalledDevice->GetClass()->GetUNID() != pWeapon->GetUNID())
		{
		printf("ERROR: Failed to install %s.\n", pWeapon->GetItemType()->GetNounPhrase(0).GetASCIIZPointer());
		return;
		}

	//	Fire the weapon

	pInstalledDevice->SetTimeUntilReady(0);
	pPlatform->SetWeaponTriggered(iDev);

	//	Update context

	SSystemUpdateCtx Ctx;
	Ctx.bForceEventFiring = true;
	Ctx.bForcePainted = true;

	//	Now loop over the appropriate number of frames

	int xDest = x;
	int yDest = y;
	for (i = 0; i < iFrames; i++)
		{
		//	Update the universe

		g_pUniverse->Update(Ctx);
		if (pPlatform->IsDestroyed())
			printf("Platform destroyed.\n");

		//	Paint

		RECT rcView;
		rcView.left = xDest;
		rcView.top = yDest;
		rcView.right = xDest + (iFrames * cxCell * 2);
		rcView.bottom = yDest + cyCell;

		g_pUniverse->PaintPOV(Image, rcView, CSystem::VWP_NO_STAR_FIELD);

		//	Next

		pPlatform->ClearAllTriggered();

		//	At the half-way mark, update until the missile hits

		if (i == iFrameToSkip)
			{
			for (j = 0; j < iTicksToHit; j++)
				g_pUniverse->Update(Ctx);
			}

		yDest += cyCell;
		}

	//	Skip for a while

	for (j = 0; j < 100; j++)
		{
		g_pUniverse->Update(Ctx);
		if (pPlatform->IsDestroyed())
			printf("Platform destroyed.\n");
		}

	//	Uninstall weapon

	ItemList.Refresh(CItem::NullItem());
	while (ItemList.MoveCursorForward() 
			&& ItemList.GetItemAtCursor().GetType() != pWeapon->GetItemType())
		;

	pPlatform->RemoveItemAsDevice(ItemList);
	}
Exemplo n.º 15
0
INT_PTR CPanelOptions::DlgProc(HWND hDlg,UINT uMsg,WPARAM wParam,LPARAM lParam)
{
	switch (uMsg) {
	case WM_INITDIALOG:
		{
			DlgCheckBox_Check(hDlg,IDC_PANELOPTIONS_SNAPATMAINWINDOW,
												m_fSnapAtMainWindow);
			DlgCheckBox_Check(hDlg,IDC_PANELOPTIONS_ATTACHTOMAINWINDOW,
												m_fAttachToMainWindow);

			// Opacity
			::SendDlgItemMessage(hDlg,IDC_PANELOPTIONS_OPACITY_TB,
										TBM_SETRANGE,TRUE,MAKELPARAM(20,100));
			::SendDlgItemMessage(hDlg,IDC_PANELOPTIONS_OPACITY_TB,
										TBM_SETPOS,TRUE,m_Opacity);
			::SendDlgItemMessage(hDlg,IDC_PANELOPTIONS_OPACITY_TB,
										TBM_SETPAGESIZE,0,10);
			::SendDlgItemMessage(hDlg,IDC_PANELOPTIONS_OPACITY_TB,
										TBM_SETTICFREQ,10,0);
			::SetDlgItemInt(hDlg,IDC_PANELOPTIONS_OPACITY_EDIT,m_Opacity,TRUE);
			::SendDlgItemMessage(hDlg,IDC_PANELOPTIONS_OPACITY_UD,
										UDM_SETRANGE,0,MAKELPARAM(100,20));

			m_CurSettingFont=m_Font;
			SetFontInfo(hDlg,IDC_PANELOPTIONS_FONTINFO,&m_Font);
			DlgCheckBox_Check(hDlg,IDC_PANELOPTIONS_SPECCAPTIONFONT,m_fSpecCaptionFont);
			EnableDlgItems(hDlg,IDC_PANELOPTIONS_CAPTIONFONT_INFO,
						   IDC_PANELOPTIONS_CAPTIONFONT_CHOOSE,
						   m_fSpecCaptionFont);
			m_CurSettingCaptionFont=m_CaptionFont;
			SetFontInfo(hDlg,IDC_PANELOPTIONS_CAPTIONFONT_INFO,&m_CaptionFont);

			m_ItemListView.Attach(::GetDlgItem(hDlg,IDC_PANELOPTIONS_ITEMLIST));
			m_ItemListView.InitCheckList();
			PanelItemInfoList ItemList(m_ItemList);
			for (size_t i=0;i<m_AvailItemList.size();i++) {
				const TVTest::String &ID=m_AvailItemList[i].ID;
				if (std::find_if(ItemList.begin(),ItemList.end(),
						[&](const PanelItemInfo &Item) -> bool {
							return CompareID(Item.ID,ID); })==ItemList.end()) {
					PanelItemInfo Item;
					Item.ID=ID;
					Item.fVisible=m_AvailItemList[i].fVisible;
					ItemList.push_back(Item);
				}
			}
			int ItemCount=0;
			for (int i=0;i<(int)ItemList.size();i++) {
				const PanelItemInfo &Item=ItemList[i];
				int ID=GetItemIDFromIDText(Item.ID);
				if (ID>=0) {
					m_ItemListView.InsertItem(ItemCount,m_AvailItemList[ID].Title.c_str(),ID);
					m_ItemListView.CheckItem(ItemCount,Item.fVisible);
					ItemCount++;
				}
			}
			UpdateItemListControlsState();

			DlgComboBox_AddString(hDlg,IDC_PANELOPTIONS_FIRSTTAB,TEXT("最後に表示したタブ"));
			int Sel=0;
			if (!m_InitialTab.empty()) {
				LPTSTR p;
				long IDNum=std::_tcstol(m_InitialTab.c_str(),&p,10);
				if (*p==_T('\0')) {
					if (IDNum>=0 && (size_t)IDNum<m_AvailItemList.size())
						Sel=IDNum+1;
				}
			}
			for (size_t i=0;i<m_AvailItemList.size();i++) {
				DlgComboBox_AddString(hDlg,IDC_PANELOPTIONS_FIRSTTAB,m_AvailItemList[i].Title.c_str());
				if (Sel==0 && CompareID(m_AvailItemList[i].ID,m_InitialTab))
					Sel=(int)i+1;
			}
			DlgComboBox_SetCurSel(hDlg,IDC_PANELOPTIONS_FIRSTTAB,Sel);

			static const LPCTSTR TabStyleList[] = {
				TEXT("文字のみ"),
				TEXT("アイコンのみ"),
				TEXT("アイコンと文字"),
			};
			for (int i=0;i<lengthof(TabStyleList);i++)
				DlgComboBox_AddString(hDlg,IDC_PANELOPTIONS_TABSTYLE,TabStyleList[i]);
			DlgComboBox_SetCurSel(hDlg,IDC_PANELOPTIONS_TABSTYLE,(int)m_TabStyle);

			DlgCheckBox_Check(hDlg,IDC_PANELOPTIONS_TABTOOLTIP,m_fTabTooltip);
		}
		return TRUE;

	case WM_HSCROLL:
		if (reinterpret_cast<HWND>(lParam)==
				::GetDlgItem(hDlg,IDC_PANELOPTIONS_OPACITY_TB)) {
			SyncEditWithTrackBar(hDlg,IDC_PANELOPTIONS_OPACITY_TB,
									  IDC_PANELOPTIONS_OPACITY_EDIT);
		}
		return TRUE;

	case WM_COMMAND:
		switch (LOWORD(wParam)) {
		case IDC_PANELOPTIONS_OPACITY_EDIT:
			if (HIWORD(wParam)==EN_CHANGE)
				SyncTrackBarWithEdit(hDlg,IDC_PANELOPTIONS_OPACITY_EDIT,
										  IDC_PANELOPTIONS_OPACITY_TB);
			return TRUE;

		case IDC_PANELOPTIONS_ITEMLIST_UP:
		case IDC_PANELOPTIONS_ITEMLIST_DOWN:
			{
				int From=m_ItemListView.GetSelectedItem(),To;

				if (LOWORD(wParam)==IDC_PANELOPTIONS_ITEMLIST_UP)
					To=From-1;
				else
					To=From+1;
				if (To<0 || To>=m_ItemListView.GetItemCount())
					return TRUE;
				m_ItemListView.MoveItem(From,To);
				UpdateItemListControlsState();
			}
			return TRUE;

		case IDC_PANELOPTIONS_CHOOSEFONT:
			if (ChooseFontDialog(hDlg,&m_CurSettingFont))
				SetFontInfo(hDlg,IDC_PANELOPTIONS_FONTINFO,&m_CurSettingFont);
			return TRUE;

		case IDC_PANELOPTIONS_SPECCAPTIONFONT:
			EnableDlgItemsSyncCheckBox(hDlg,IDC_PANELOPTIONS_CAPTIONFONT_INFO,
									   IDC_PANELOPTIONS_CAPTIONFONT_CHOOSE,
									   IDC_PANELOPTIONS_SPECCAPTIONFONT);
			return TRUE;

		case IDC_PANELOPTIONS_CAPTIONFONT_CHOOSE:
			if (ChooseFontDialog(hDlg,&m_CurSettingCaptionFont))
				SetFontInfo(hDlg,IDC_PANELOPTIONS_CAPTIONFONT_INFO,&m_CurSettingCaptionFont);
			return TRUE;
		}
		return TRUE;

	case WM_NOTIFY:
		switch (((LPNMHDR)lParam)->code) {
		case PSN_APPLY:
			{
				CMainPanel &Panel=GetAppClass().Panel;

				m_fSnapAtMainWindow=
					DlgCheckBox_IsChecked(hDlg,IDC_PANELOPTIONS_SNAPATMAINWINDOW);
				m_fAttachToMainWindow=
					DlgCheckBox_IsChecked(hDlg,IDC_PANELOPTIONS_ATTACHTOMAINWINDOW);
				m_Opacity=::GetDlgItemInt(hDlg,IDC_PANELOPTIONS_OPACITY_EDIT,NULL,TRUE);
				Panel.Frame.SetPanelOpacity(m_Opacity*255/100);

				bool fFontChanged=!CompareLogFont(&m_Font,&m_CurSettingFont);
				if (fFontChanged) {
					m_Font=m_CurSettingFont;
					Panel.Form.SetTabFont(&m_Font);
					Panel.Form.SetPageFont(&m_Font);
				}

				bool fChangeCaptionFont=false;
				bool fSpecCaptionFont=DlgCheckBox_IsChecked(hDlg,IDC_PANELOPTIONS_SPECCAPTIONFONT);
				if (m_fSpecCaptionFont!=fSpecCaptionFont) {
					m_fSpecCaptionFont=fSpecCaptionFont;
					fChangeCaptionFont=true;
				}
				if (!CompareLogFont(&m_CaptionFont,&m_CurSettingCaptionFont)) {
					m_CaptionFont=m_CurSettingCaptionFont;
					if (m_fSpecCaptionFont)
						fChangeCaptionFont=true;
				} else if (m_fSpecCaptionFont && fFontChanged) {
					fChangeCaptionFont=true;
				}
				if (fChangeCaptionFont) {
					CPanelForm::CPage *pCaptionPanel=Panel.Form.GetPageByID(PANEL_ID_CAPTION);
					if (pCaptionPanel!=NULL)
						pCaptionPanel->SetFont(m_fSpecCaptionFont?
											   &m_CaptionFont:&m_Font);
				}

				const int ItemCount=m_ItemListView.GetItemCount();
				m_ItemList.clear();
				m_ItemList.resize(ItemCount);
				for (int i=0;i<ItemCount;i++) {
					const PanelItemInfo &ItemInfo=m_AvailItemList[m_ItemListView.GetItemParam(i)];
					m_ItemList[i].ID=ItemInfo.ID;
					m_ItemList[i].fVisible=m_ItemListView.IsItemChecked(i);
				}
				ApplyItemList(&Panel.Form);

				int InitialTab=(int)DlgComboBox_GetCurSel(hDlg,IDC_PANELOPTIONS_FIRSTTAB);
				if (InitialTab==0) {
					m_InitialTab.clear();
				} else if (InitialTab>0) {
					m_InitialTab=m_AvailItemList[InitialTab-1].ID;
				}

				int TabStyleSel=(int)DlgComboBox_GetCurSel(hDlg,IDC_PANELOPTIONS_TABSTYLE);
				if (TabStyleSel>=0) {
					m_TabStyle=static_cast<CPanelForm::TabStyle>(TabStyleSel);
					Panel.Form.SetTabStyle(m_TabStyle);
				}

				m_fTabTooltip=
					DlgCheckBox_IsChecked(hDlg,IDC_PANELOPTIONS_TABTOOLTIP);
				Panel.Form.EnableTooltip(m_fTabTooltip);

				m_fChanged=true;
			}
			break;

		case LVN_ITEMCHANGED:
			UpdateItemListControlsState();
			return TRUE;
		}
		break;

	case WM_DESTROY:
		m_ItemListView.Detach();
		return TRUE;
	}

	return FALSE;
}
Exemplo n.º 16
0
void ServerPacketHandler(CSocket *pSocket, const char *szFormat, va_list vPacket)
{
	BYTE pPacketHeader = *vPacket;

	switch (pPacketHeader)
	{
		case 0x00:
		{
			ProtocolVersion(pSocket, vPacket);
		
			break;
		}

		case 0x04:
		{
			UserInfo(pSocket, vPacket);

			break;
		}

		case 0x13:
		{
			CharSelectInfo(pSocket, vPacket);

			break;
		}

		case 0x1B:
		{
			ItemList(pSocket, vPacket);

			break;
		}

		case 0x27:
		{
			ItemListUpdate(pSocket, vPacket);

			break;
		}

		case 0x41:
		{
			WarehouseDepositList(pSocket, vPacket);

			break;
		}

		case 0x42:
		{
			WarehouseWithdrawalList(pSocket, vPacket);

			break;
		}

		case 0x44:
		{
			ShortCutRegister(pSocket, vPacket);

			break;
		}

		case 0x45:
		{
			ShortCutInit(pSocket, vPacket);

			break;
		}

		case 0x58:
		{
			SkillList(pSocket, vPacket);

			break;
		}

		case 0xD0:
		{
			MultiSellList(pSocket, vPacket);

			break;
		}

		default:
		{
			BYTE opCode = *vPacket;
			char buf[32];
			sprintf_s(buf, "%d", opCode);
			MessageBox(NULL, buf, buf, MB_OK);

			pSocket->SendV(szFormat, vPacket);

			break;
		}
	}
}
Exemplo n.º 17
0
void CSingleDevice::AddDevices (SDeviceGenerateCtx &Ctx)

//	AddDevices
//
//	Add devices to list

	{
	int i;

	if (m_pItemType == NULL)
		return;

	int iCount = m_Count.Roll();
	for (i = 0; i < iCount; i++)
		{
		//	Initialize the desc

		SDeviceDesc Desc;
		Desc.Item = CItem(m_pItemType, 1);
		if (mathRandom(1, 100) <= m_iDamaged)
			Desc.Item.SetDamaged();
		else
			m_Enhanced.EnhanceItem(Desc.Item);

		//	Find the default settings for the device slot for this device

		SDeviceDesc SlotDesc;
		bool bUseSlotDesc = (Ctx.pRoot ? Ctx.pRoot->FindDefaultDesc(Desc.Item, &SlotDesc) : false);

		//	Set the device position appropriately, either from the <Device> element,
		//	from the slot descriptor at the root, or from defaults.

		if (!m_bDefaultPos)
			{
			Desc.iPosAngle = m_iPosAngle;
			Desc.iPosRadius = m_iPosRadius;
			Desc.iPosZ = m_iPosZ;
			Desc.b3DPosition = m_b3DPosition;
			}
		else if (bUseSlotDesc)
			{
			Desc.iPosAngle = SlotDesc.iPosAngle;
			Desc.iPosRadius = SlotDesc.iPosRadius;
			Desc.iPosZ = SlotDesc.iPosZ;
			Desc.b3DPosition = SlotDesc.b3DPosition;
			}

		//	Set the device fire arc appropriately.

		if (!m_bDefaultFireArc)
			{
			Desc.bOmnidirectional = m_bOmnidirectional;
			Desc.iMinFireArc = m_iMinFireArc;
			Desc.iMaxFireArc = m_iMaxFireArc;
			}
		else if (bUseSlotDesc)
			{
			Desc.bOmnidirectional = SlotDesc.bOmnidirectional;
			Desc.iMinFireArc = SlotDesc.iMinFireArc;
			Desc.iMaxFireArc = SlotDesc.iMaxFireArc;
			}

		//	Set linked fire

		if (!m_bDefaultLinkedFire)
			Desc.dwLinkedFireOptions = m_dwLinkedFireOptions;
		else if (bUseSlotDesc)
			Desc.dwLinkedFireOptions = SlotDesc.dwLinkedFireOptions;
		else
			Desc.dwLinkedFireOptions = 0;

		Desc.bSecondary = m_bSecondary;

		//	Slot bonus

		if (!m_bDefaultSlotBonus)
			Desc.iSlotBonus = m_iSlotBonus;
		else if (bUseSlotDesc)
			Desc.iSlotBonus = SlotDesc.iSlotBonus;
		else
			Desc.iSlotBonus = 0;

		//	Add extra items

		if (m_pExtraItems)
			{
			CItemListManipulator ItemList(Desc.ExtraItems);
			SItemAddCtx ItemCtx(ItemList);
			ItemCtx.iLevel = Ctx.iLevel;

			m_pExtraItems->AddItems(ItemCtx);
			}

		//	Done
		
		Ctx.pResult->AddDeviceDesc(Desc);
		}
	}
Exemplo n.º 18
0
void CArmorDisplay::Update (void)

//	Update
//
//	Updates buffer from data

	{
	int i;

	if (m_pPlayer == NULL)
		return;

	CShip *pShip = m_pPlayer->GetShip();
	const CPlayerSettings *pSettings = pShip->GetClass()->GetPlayerSettings();
	CItemListManipulator ItemList(pShip->GetItemList());
	const CG16bitFont &SmallFont = m_pPlayer->GetTrans()->GetFonts().Small;
	m_Text.DeleteAll();

	//	If we've changed ships then we need to delete the painters

	if (m_dwCachedShipID != pShip->GetID())
		{
		if (m_pShieldPainter)
			{
			m_pShieldPainter->Delete();
			m_pShieldPainter = NULL;
			}

		m_dwCachedShipID = pShip->GetID();
		}

	//	Erase everything

	m_Buffer.Fill(0, 0, DISPLAY_WIDTH, DISPLAY_HEIGHT, DEFAULT_TRANSPARENT_COLOR);

	//	Figure out the status of the shields

	int iHP = 0;
	int iMaxHP = 10;
	CInstalledDevice *pShield = pShip->GetNamedDevice(devShields);
	if (pShield)
		pShield->GetStatus(pShip, &iHP, &iMaxHP);

	//	Draw the base ship image, if we have it

	const SArmorImageDesc &ArmorDesc = pSettings->GetArmorDesc();
	if (!ArmorDesc.ShipImage.IsEmpty())
		{
		const RECT &rcShip = ArmorDesc.ShipImage.GetImageRect();

		m_Buffer.ColorTransBlt(rcShip.left, 
				rcShip.top, 
				RectWidth(rcShip), 
				RectHeight(rcShip), 
				255,
				ArmorDesc.ShipImage.GetImage(NULL_STR), 
				DESCRIPTION_WIDTH + ((SHIELD_IMAGE_WIDTH - RectWidth(rcShip)) / 2),
				(SHIELD_IMAGE_HEIGHT - RectHeight(rcShip)) / 2);
		}

	//	Draw the old-style shields

	const SShieldImageDesc &ShieldDesc = pSettings->GetShieldDesc();
	if (!ShieldDesc.pShieldEffect)
		{
		int iWhole = (iMaxHP > 0 ? (iHP * 100) / iMaxHP : 100);
		int iIndex = (100 - iWhole) / 20;

		const RECT &rcShield = ShieldDesc.Image.GetImageRect();
		m_Buffer.ColorTransBlt(rcShield.left, 
				rcShield.top + (RectHeight(rcShield) * iIndex), 
				RectWidth(rcShield), 
				RectHeight(rcShield), 
				255,
				ShieldDesc.Image.GetImage(NULL_STR), 
				DESCRIPTION_WIDTH + ((SHIELD_IMAGE_WIDTH - RectWidth(rcShield)) / 2),
				(SHIELD_IMAGE_HEIGHT - RectHeight(rcShield)) / 2);
		}

	if (pShield)
		{
		m_Buffer.Fill(SHIELD_HP_DISPLAY_X,
				SHIELD_HP_DISPLAY_Y, 
				SHIELD_HP_DISPLAY_WIDTH, 
				SHIELD_HP_DISPLAY_HEIGHT,
				SHIELD_HP_DISPLAY_BACK_COLOR);
		
		CString sHP = strFromInt(iHP);
		int cxWidth = m_pFonts->Medium.MeasureText(sHP, NULL);
		m_pFonts->Medium.DrawText(m_Buffer,
				SHIELD_HP_DISPLAY_X + (SHIELD_HP_DISPLAY_WIDTH - cxWidth) / 2,
				SHIELD_HP_DISPLAY_Y - 1,
				CG16bitImage::LightenPixel(m_pFonts->wAltGreenColor, 60),
				sHP);

		DrawBrokenLine(m_Buffer,
				0,
				SHIELD_HP_DISPLAY_Y,
				SHIELD_HP_DISPLAY_X,
				SHIELD_HP_DISPLAY_Y,
				0,
				SHIELD_HP_DISPLAY_LINE_COLOR);

		WORD wColor;
		if (pShield->IsEnabled() && !pShield->IsDamaged() && !pShield->IsDisrupted())
			wColor = m_pFonts->wAltGreenColor;
		else
			wColor = DISABLED_TEXT_COLOR;

		CString sShieldName = pShield->GetClass()->GetName();
		int cyHeight;
		cxWidth = m_pFonts->Medium.MeasureText(sShieldName, &cyHeight);

		//	Add the shield name to list of text to paint

		STextPaint *pPaint = m_Text.Insert();
		pPaint->sText = sShieldName;
		pPaint->x = 0;
		pPaint->y = SHIELD_HP_DISPLAY_Y;
		pPaint->pFont = &m_pFonts->Medium;
		pPaint->wColor = wColor;

		//	Paint the modifiers

		if (pShield->GetMods().IsNotEmpty() || pShield->GetBonus() != 0)
			{
			pShip->SetCursorAtNamedDevice(ItemList, devShields);
			CString sMods = pShield->GetEnhancedDesc(pShip, &ItemList.GetItemAtCursor());
			if (!sMods.IsBlank())
				{
				bool bDisadvantage = (*(sMods.GetASCIIZPointer()) == '-');

				int cx = SmallFont.MeasureText(sMods);
				m_Buffer.Fill(SHIELD_HP_DISPLAY_X - cx - 8,
						SHIELD_HP_DISPLAY_Y,
						cx + 8,
						SHIELD_HP_DISPLAY_HEIGHT,
						(bDisadvantage ? ARMOR_DAMAGED_BACK_COLOR : ARMOR_ENHANCE_BACK_COLOR));

				SmallFont.DrawText(m_Buffer,
						SHIELD_HP_DISPLAY_X - cx - 4,
						SHIELD_HP_DISPLAY_Y + (SHIELD_HP_DISPLAY_HEIGHT - SmallFont.GetHeight()) / 2,
						(bDisadvantage ? ARMOR_DAMAGED_TEXT_COLOR : ARMOR_ENHANCE_TEXT_COLOR),
						sMods);
				}
			}
		}

	//	Draw armor

	int iArmorCount = Min(pShip->GetArmorSectionCount(), pSettings->GetArmorDescCount());
	for (i = 0; i < iArmorCount; i++)
		{
		const SArmorSegmentImageDesc *pImage = &pSettings->GetArmorDesc(i);

		CInstalledArmor *pArmor = pShip->GetArmorSection(i);
		int iMaxHP = pArmor->GetMaxHP(pShip);
		int iWhole = (iMaxHP == 0 ? 100 : (pArmor->GetHitPoints() * 100) / iMaxHP);
		int iIndex = (100 - iWhole) / 20;
		
		if (iIndex < 5)
			{
			const RECT &rcImage = pImage->Image.GetImageRect();
			m_Buffer.ColorTransBlt(rcImage.left,
					rcImage.top + iIndex * RectHeight(rcImage),
					RectWidth(rcImage),
					RectHeight(rcImage),
					255,
					pImage->Image.GetImage(NULL_STR),
					DESCRIPTION_WIDTH + pImage->xDest,
					pImage->yDest);
			}
		}

	//	Draw the new style shields on top

	if (ShieldDesc.pShieldEffect)
		{
		int x = DESCRIPTION_WIDTH + SHIELD_IMAGE_WIDTH / 2;
		int y = SHIELD_IMAGE_HEIGHT / 2;

		SViewportPaintCtx Ctx;
		Ctx.iTick = g_pUniverse->GetTicks();
		Ctx.iVariant = (iMaxHP > 0 ? (iHP * 100) / iMaxHP : 0);
		Ctx.iDestiny = pShip->GetDestiny();
		Ctx.iRotation = 90;

		if (m_pShieldPainter == NULL)
			m_pShieldPainter = ShieldDesc.pShieldEffect->CreatePainter();

		m_pShieldPainter->Paint(m_Buffer, x, y, Ctx);
		}

	//	Draw armor names

	for (i = 0; i < iArmorCount; i++)
		{
		const SArmorSegmentImageDesc *pImage = &pSettings->GetArmorDesc(i);
		CInstalledArmor *pArmor = pShip->GetArmorSection(i);

		//	Paint the HPs

		if (i == m_iSelection)
			{
			m_Buffer.Fill(DESCRIPTION_WIDTH + pImage->xHP - 1, 
					pImage->yHP - 1, 
					HP_DISPLAY_WIDTH + 2, 
					HP_DISPLAY_HEIGHT + 2,
					CG16bitImage::DarkenPixel(m_pFonts->wSelectBackground, 128));
			}
		else
			{
			m_Buffer.Fill(DESCRIPTION_WIDTH + pImage->xHP, 
					pImage->yHP, 
					HP_DISPLAY_WIDTH, 
					HP_DISPLAY_HEIGHT,
					HP_DISPLAY_BACK_COLOR);
			}

		CString sHP = strFromInt(pArmor->GetHitPoints());
		int cxWidth = m_pFonts->Medium.MeasureText(sHP, NULL);
		m_pFonts->Medium.DrawText(m_Buffer,
				DESCRIPTION_WIDTH + pImage->xHP + (HP_DISPLAY_WIDTH - cxWidth) / 2,
				pImage->yHP - 1,
				m_pFonts->wTitleColor,
				sHP);

		//	Paint the armor name line

		DrawBrokenLine(m_Buffer,
				0,
				pImage->yName + m_pFonts->Medium.GetHeight(),
				DESCRIPTION_WIDTH + pImage->xHP + pImage->xNameDestOffset,
				pImage->yHP + pImage->yNameDestOffset,
				pImage->cxNameBreak,
				(i == m_iSelection ? CG16bitImage::DarkenPixel(m_pFonts->wSelectBackground, 128) : ARMOR_LINE_COLOR));

		//	Paint the armor names

		CString sName = pArmor->GetClass()->GetShortName();
		int cy;
		int cx = m_pFonts->Medium.MeasureText(sName, &cy) + 4;
		if (i == m_iSelection)
			{
			m_Buffer.Fill(0, 
					pImage->yName, 
					cx, 
					cy,
					CG16bitImage::DarkenPixel(m_pFonts->wSelectBackground, 128));
			}

		STextPaint *pPaint = m_Text.Insert();
		pPaint->sText = sName;
		pPaint->x = 2;
		pPaint->y = pImage->yName;
		pPaint->pFont = &m_pFonts->Medium;
		pPaint->wColor = m_pFonts->wTitleColor;

		//	Paint the modifiers

		if (pArmor->GetMods().IsNotEmpty())
			{
			pShip->SetCursorAtArmor(ItemList, i);
			CString sMods = ItemList.GetItemAtCursor().GetEnhancedDesc(pShip);
			if (!sMods.IsBlank())
				{
				int cx = SmallFont.MeasureText(sMods);
				m_Buffer.Fill(ARMOR_ENHANCE_X - cx - 4,
						pImage->yName + m_pFonts->Medium.GetHeight() - HP_DISPLAY_HEIGHT,
						cx + 8,
						HP_DISPLAY_HEIGHT,
						ARMOR_ENHANCE_BACK_COLOR);

				SmallFont.DrawText(m_Buffer,
						ARMOR_ENHANCE_X - cx,
						pImage->yName + 3,
						ARMOR_ENHANCE_TEXT_COLOR,
						sMods);
				}
			}
		}
	}
Exemplo n.º 19
0
void CPlayerGameStats::GenerateGameStats (CGameStats &Stats, CSpaceObject *pPlayerShip, bool bGameOver) const

//	GenerateGameStats
//
//	Generates a stats for everything we track

	{
	int j;

	CShip *pShip = (pPlayerShip ? pPlayerShip->AsShip() : NULL);
	if (pShip == NULL)
		return;

	CPlayerShipController *pPlayer = (CPlayerShipController *)pShip->GetController();
	if (pPlayer == NULL)
		return;

	CSovereign *pPlayerSovereign = g_pUniverse->FindSovereign(g_PlayerSovereignUNID);
	if (pPlayerSovereign == NULL)
		return;

	//	Base stats

	Stats.Insert(CONSTLIT("Genome"), strCapitalize(GetGenomeName(pPlayer->GetPlayerGenome())));
	Stats.Insert(CONSTLIT("Score"), strFormatInteger(CalcEndGameScore(), -1, FORMAT_THOUSAND_SEPARATOR | FORMAT_UNSIGNED));
	Stats.Insert(CONSTLIT("Ship class"), pShip->GetNounPhrase(0));

	CTimeSpan Time = GetPlayTime();
	if (!Time.IsBlank())
		Stats.Insert(CONSTLIT("Time played"), Time.Format(NULL_STR));

#ifdef REAL_TIME
	Time = GetGameTime();
	if (!Time.IsBlank())
		Stats.Insert(CONSTLIT("Time elapsed in game"), Time.Format(NULL_STR));
#endif

	//	Some combat stats

	CString sDestroyed = GetStat(ENEMY_SHIPS_DESTROYED_STAT);
	if (!sDestroyed.IsBlank())
		Stats.Insert(CONSTLIT("Enemy ships destroyed"), sDestroyed, CONSTLIT("combat"));

	sDestroyed = GetStat(FRIENDLY_SHIPS_DESTROYED_STAT);
	if (!sDestroyed.IsBlank())
		Stats.Insert(CONSTLIT("Friendly ships destroyed"), sDestroyed, CONSTLIT("combat"));

	sDestroyed = GetStat(ENEMY_STATIONS_DESTROYED_STAT);
	if (!sDestroyed.IsBlank())
		Stats.Insert(CONSTLIT("Enemy stations destroyed"), sDestroyed, CONSTLIT("combat"));

	sDestroyed = GetStat(FRIENDLY_STATIONS_DESTROYED_STAT);
	if (!sDestroyed.IsBlank())
		Stats.Insert(CONSTLIT("Friendly stations destroyed"), sDestroyed, CONSTLIT("combat"));

	//	Add stat for every station destroyed

	CStatCounterArray CounterArray;

	CMapIterator i;
	m_StationStats.Reset(i);
	while (m_StationStats.HasMore(i))
		{
		SStationTypeStats *pStats;
		DWORD dwUNID = m_StationStats.GetNext(i, &pStats);
		CStationType *pType = g_pUniverse->FindStationType(dwUNID);
		if (pType == NULL)
			continue;

		CString sName = pType->GetNounPhrase(0);
		CString sSort = strPatternSubst(CONSTLIT("%03d%s"), 100 - pType->GetLevel(), sName);

		if (pType->GetSovereign()->IsEnemy(pPlayerSovereign))
			CounterArray.Insert(sName, pStats->iDestroyed, CONSTLIT("Enemy stations destroyed"), sSort);
		else
			CounterArray.Insert(sName, pStats->iDestroyed, CONSTLIT("Friendly stations destroyed"), sSort);
		}

	CounterArray.GenerateGameStats(Stats);
		
	//	Add stat for every ship class destroyed

	CounterArray.DeleteAll();
	m_ShipStats.Reset(i);
	while (m_ShipStats.HasMore(i))
		{
		SShipClassStats *pStats;
		DWORD dwUNID = m_ShipStats.GetNext(i, &pStats);
		CShipClass *pClass = g_pUniverse->FindShipClass(dwUNID);
		if (pClass == NULL)
			continue;

		CString sName = pClass->GetNounPhrase(0);
		CString sSort = strPatternSubst(CONSTLIT("%09d%s"), 100000000 - pClass->GetScore(), sName);

		if (pStats->iEnemyDestroyed > 0)
			CounterArray.Insert(sName, pStats->iEnemyDestroyed, CONSTLIT("Enemy ships destroyed"), sSort);

		if (pStats->iFriendDestroyed > 0)
			CounterArray.Insert(sName, pStats->iFriendDestroyed, CONSTLIT("Friendly ships destroyed"), sSort);
		}

	CounterArray.GenerateGameStats(Stats);

	//	Add stat for every weapon fired

	m_ItemStats.Reset(i);
	while (m_ItemStats.HasMore(i))
		{
		SItemTypeStats *pStats;
		DWORD dwUNID = m_ItemStats.GetNext(i, &pStats);
		CItemType *pItemType = g_pUniverse->FindItemType(dwUNID);
		if (pItemType == NULL)
			continue;

		CString sName = pItemType->GetNounPhrase(nounShort);
		CString sSort = strPatternSubst(CONSTLIT("%03d%s"), 100 - pItemType->GetLevel(), sName);

		//	Installed items

		if (pStats->dwFirstInstalled != INVALID_TIME)
			Stats.Insert(sName, NULL_STR, CONSTLIT("Items installed"), sSort);

		if (pStats->iCountFired > 0)
			Stats.Insert(sName, 
					strFormatInteger(pStats->iCountFired, -1, FORMAT_THOUSAND_SEPARATOR | FORMAT_UNSIGNED), 
					CONSTLIT("Weapons fired"), 
					sSort);
		}

	//	Stats for player equipment (but only if the game is done)

	if (bGameOver)
		{
		TSortMap<CString, CItem> InstalledItems;

		//	First we generate a sorted list of installed items
		//	(We do this in case there are multiple of the same device/armor so that
		//	we can coalesce them together into a single line).

		CItemListManipulator ItemList(pShip->GetItemList());
		ItemList.ResetCursor();
		while (ItemList.MoveCursorForward())
			{
			const CItem &Item(ItemList.GetItemAtCursor());

			if (Item.IsInstalled())
				{
				CString sEnhancement = Item.GetEnhancedDesc(pShip);
				CString sItemName = Item.GetNounPhrase(nounActual | nounCountOnly | nounShort);
				CString sLine = (sEnhancement.IsBlank() ? sItemName : strPatternSubst(CONSTLIT("%s [%s]"), sItemName, sEnhancement));

				bool bInserted;
				CItem *pEntry = InstalledItems.SetAt(sLine, &bInserted);
				if (bInserted)
					{
					*pEntry = Item;
					pEntry->SetCount(1);
					}
				else
					pEntry->SetCount(pEntry->GetCount() + 1);
				}
			}

		//	Now add all the installed items to the stats

		for (j = 0; j < InstalledItems.GetCount(); j++)
			{
			//	Redo the line now that we know the proper count

			CString sEnhancement = InstalledItems[j].GetEnhancedDesc(pShip);
			CString sItemName = InstalledItems[j].GetNounPhrase(nounActual | nounCountOnly);
			CString sLine = (sEnhancement.IsBlank() ? sItemName : strPatternSubst(CONSTLIT("%s [%s]"), sItemName, sEnhancement));

			//	Compute the sort order

			int iOrder;
			switch (InstalledItems[j].GetType()->GetCategory())
				{
				case itemcatWeapon:
					iOrder = 0;
					break;

				case itemcatLauncher:
					iOrder = 1;
					break;

				case itemcatShields:
					iOrder = 2;
					break;

				case itemcatArmor:
					iOrder = 3;
					break;

				case itemcatReactor:
					iOrder = 4;
					break;

				case itemcatDrive:
					iOrder = 5;
					break;

				default:
					iOrder = 6;
					break;
				}

			CString sSort = strPatternSubst(CONSTLIT("%d%03d%s"), iOrder, 100 - InstalledItems[j].GetType()->GetLevel(), sLine);
			Stats.Insert(sLine, NULL_STR, CONSTLIT("Final equipment"), sSort);
			}

		//	Add the remaining items

		ItemList.ResetCursor();
		while (ItemList.MoveCursorForward())
			{
			const CItem &Item(ItemList.GetItemAtCursor());

			if (!Item.IsInstalled())
				{
				CString sEnhancement = Item.GetEnhancedDesc(pShip);
				CString sItemName = Item.GetNounPhrase(nounActual | nounCountOnly);
				CString sLine = (sEnhancement.IsBlank() ? sItemName : strPatternSubst(CONSTLIT("%s [%s]"), sItemName, sEnhancement));
				CString sSort = strPatternSubst(CONSTLIT("%03d%s"), 100 - Item.GetType()->GetLevel(), sLine);

				Stats.Insert(sLine, NULL_STR, CONSTLIT("Final items"), sSort);
				}
			}
		}
	}
Exemplo n.º 20
0
void GenerateSimTables (CUniverse &Universe, CXMLElement *pCmdLine)
	{
	ALERROR error;
	int i, j;

	int iSystemSample = pCmdLine->GetAttributeInteger(CONSTLIT("count"));
	if (iSystemSample == 0)
		iSystemSample = DEFAULT_SYSTEM_SAMPLE;

	//	Generate systems for multiple games

	CSymbolTable AllSystems(TRUE, TRUE);
	for (i = 0; i < iSystemSample; i++)
		{
		printf("sample %d...\n", i+1);

		CTopologyNode *pNode = Universe.GetFirstTopologyNode();

		while (true)
			{
			//	Create the system

			CSystem *pSystem;
			if (error = Universe.CreateStarSystem(pNode, &pSystem))
				{
				printf("ERROR: Unable to create star system.\n");
				return;
				}

			//	Find this system in the table.

			SystemInfo *pSystemEntry;
			if (error = AllSystems.Lookup(pNode->GetSystemName(), (CObject **)&pSystemEntry))
				{
				pSystemEntry = new SystemInfo;
				pSystemEntry->sName = pNode->GetSystemName();
				pSystemEntry->iLevel = pNode->GetLevel();
				pSystemEntry->dwSystemType = pNode->GetSystemDescUNID();
				pSystemEntry->iCount = 1;

				AllSystems.AddEntry(pSystemEntry->sName, pSystemEntry);
				}
			else
				pSystemEntry->iCount++;

			//	Add the encounters to the appropriate tables

			for (j = 0; j < pSystem->GetObjectCount(); j++)
				{
				CSpaceObject *pObj = pSystem->GetObject(j);

				if (pObj)
					{
					//	Add this encounter to the table

					CStationType *pType;
					if (pType = pObj->GetEncounterInfo())
						{
						CString sKey = strFromInt(pType->GetUNID(), false);

						//	See if we have this type in the table

						StationInfo *pEntry;
						if (error = pSystemEntry->Stations.Lookup(sKey, (CObject **)&pEntry))
							{
							pEntry = new StationInfo;
							pEntry->pType = pType;
							pEntry->iSystemCount = 0;
							pEntry->iTotalCount = 1;

							pSystemEntry->Stations.AddEntry(sKey, pEntry);
							}
						else
							pEntry->iTotalCount++;
						}

					//	Enumerate the items in this object

					CItemListManipulator ItemList(pObj->GetItemList());
					ItemList.ResetCursor();
					while (ItemList.MoveCursorForward())
						{
						const CItem &Item(ItemList.GetItemAtCursor());

						if (!Item.IsInstalled() && !Item.IsDamaged())
							{
							CString sKey = strFromInt(Item.GetType()->GetUNID(), false);

							//	Find the item type in the table

							ItemInfo *pEntry;
							if (error = pSystemEntry->Items.Lookup(sKey, (CObject **)&pEntry))
								{
								pEntry = new ItemInfo;
								pEntry->pType = Item.GetType();
								pEntry->iTotalCount = Item.GetCount();

								pSystemEntry->Items.AddEntry(sKey, pEntry);
								}
							else
								pEntry->iTotalCount += Item.GetCount();
							}
						}
					}
				}

			//	Get the next node

			CString sEntryPoint;
			pNode = pSystem->GetStargateDestination(CONSTLIT("Outbound"), &sEntryPoint);
			if (pNode == NULL || pNode->IsEndGame())
				break;

			//	Done with old system

			Universe.DestroySystem(pSystem);
			}

		Universe.Reinit();
		}

	//	Output

	if (error = OutputItemTable(AllSystems, iSystemSample))
		return;

	if (error = OutputEncounterTable(AllSystems, iSystemSample))
		return;

	//	Create a table with the sum of all items for the game

	printf("Total count statistic computed.\n");
	}
Exemplo n.º 21
0
void Game::RestartLevel(bool restart)
{
	bool done = false;

	while (!done)
	{
		InitCell();

		GhostList().clear();
		ItemList().clear();

		// add player
		if (CurrentLevel < 8)
			GhostList().emplace_back(this, pEngineCore);
		else
			GhostList().emplace_back(this, pEngineCore, GameObject::GOT_PLAYER, ColorYellow(), 0, 0);

		// add AUX object
		if (!pNearest) pNearest = new Item(this, pEngineCore);

		// add exit from level
		ItemList().emplace_back(this, pEngineCore, GameObject::GOT_EXIT, 7, 7, 5);

		// add score items
		for (int i = 0; i < ScoreNumber; ++i)
			ItemList().emplace_back(this, pEngineCore);

		// add ghosts and special items
		GhostList().emplace_back(this, pEngineCore, GameObject::GOT_BLUE_GHOST, ColorBlue());
		if (CurrentLevel > 1)
			GhostList().emplace_back(this, pEngineCore, GameObject::GOT_RED_GHOST, ColorRed());
		if (CurrentLevel > 2)
		{
			for (int i = 0; i < BlackScoreNumber; ++i)
				ItemList().emplace_back(this, pEngineCore, GameObject::GOT_BLACK_SCORE, 7);

			SetBlackFlag(false);
		}
		if (CurrentLevel > 3)
			GhostList().emplace_back(this, pEngineCore, GameObject::GOT_PURPLE_GHOST, ColorPurple());
		if (CurrentLevel > 4)
		{
			ItemList().emplace_back(this, pEngineCore, GameObject::GOT_BIG_SCORE, 8, 5, 7);
			GhostList().emplace_back(this, pEngineCore, GameObject::GOT_GREEN_GHOST, ColorGreen(), 5, 7);
		}
		if (CurrentLevel > 5)
			GhostList().emplace_back(this, pEngineCore, GameObject::GOT_OLIVE_GHOST, ColorOlive(), 5, 5);
		if (CurrentLevel > 6)
		{
			ItemList().emplace_back(this, pEngineCore, GameObject::GOT_HELP_SCORE, 8, 7, 5);
			SetHelpFlag(false);
			GhostList().emplace_back(this, pEngineCore, GameObject::GOT_AQUA_GHOST, ColorAqua());
			GhostList().emplace_back(this, pEngineCore, GameObject::GOT_TEAL_GHOST, ColorTeal());
		}

		// if player cannot interact with some objects -> restart initialization
		done = true;
		if (GetMode() != "s")
		{
			for (auto it = cItemList().cbegin(); it != cItemList().cend() && done; ++it)
				if (!cGhostList().cbegin()->Pathfind(*it))
					done = false;

			// if (!done) the following loop is unnecessary and will not execute
			// some ghosts can be walled up if manually disable the following loop (it can be usefull for medium difficulty level)

			//for (auto it = ++cGhostList().cbegin(); it != cGhostList().cend() && done; ++it)
			//	if (!cGhostList().cbegin()->Pathfind(*it))
			//		done = false;
		}
	}

	if (restart)
		CurrentScore = PreviousScore;
	else
	{
		PreviousScore = CurrentScore;
		if (IncreaseLivesFlag)
			Lives++;
	}
	SetIncreaseLivesFlag(false);
}
Exemplo n.º 22
0
int CSpaceObject::GetSellPrice (const CItem &Item, DWORD dwFlags)

//	GetSellPrice
//
//	Returns the price at which the station will sell the given
//	item. Returns 0 if the station cannot or will not sell the
//	item.

	{
	bool bHasTradeDirective = false;
	int iPrice = -1;

	if (IsAbandoned())
		return false;

	//	See if we have an override price

	CTradingDesc *pTradeOverride = GetTradeDescOverride();
	if (pTradeOverride)
		{
		pTradeOverride->Sells(this, Item, dwFlags, &iPrice);
		bHasTradeDirective = true;
		}

	//	See if our type has a price

	CDesignType *pType = GetType();
	if (iPrice == -1)
		{
		CTradingDesc *pTrade = (pType ? pType->GetTradingDesc() : NULL);
		if (pTrade)
			{
			pTrade->Sells(this, Item, dwFlags, &iPrice);
			bHasTradeDirective = true;
			}
		}

	//	If we still have no price, then try to figure out a default.

	if (iPrice == -1)
		{
		//	If we have Trade directives and they specify no price, then we can't
		//	sell any.

		if (bHasTradeDirective)
			return 0;

		//	For compatibility, any ship prior to version 23 has a default.
		//	[For API Version 23 and above, ships must have a <Trade> descriptor.]

		else if (pType 
				&& pType->GetAPIVersion() < 23
				&& pType->GetType() == designShipClass)
			iPrice = CTradingDesc::CalcPriceForService(serviceSell, this, Item, 1, dwFlags);

		//	Otherwise, get the price from the item itself

		else
			iPrice = (int)GetDefaultEconomy()->Exchange(Item.GetCurrencyType(), Item.GetTradePrice(this));
		}

	//	If we don't have any of the item, then we don't sell any

	if (!(dwFlags & CTradingDesc::FLAG_NO_INVENTORY_CHECK))
		{
		CItemListManipulator ItemList(GetItemList());
		if (!ItemList.SetCursorAtItem(Item))
			return 0;
		}

	//	Return the price

	return iPrice;
	}
Exemplo n.º 23
0
void CGroupOfGenerators::AddItems (SItemAddCtx &Ctx)

//	AddItems
//
//	Add items

	{
	int i, j;

	//	If we need to adjust counts, then do a separate algorithm

	if (SetsAverageValue())
		{
		//	Get the count adjustment.

		Metric rCountAdj = GetCountAdj(Ctx.iLevel);
		Metric rLoops = floor(rCountAdj);
		Metric rLastLoopAdj = rCountAdj - rLoops;

		//	Loop if we have extra items

		int iFullLoops = (int)rLoops;
		for (i = 0; i < iFullLoops + 1; i++)
			{
			//	For a full loop we just add the items

			if (i < iFullLoops)
				AddItemsInt(Ctx);

			//	Otherwise we need to add partial items

			else
				{
				//	Add the items to a private list.

				CItemList LocalList;
				CItemListManipulator ItemList(LocalList);
				SItemAddCtx LocalCtx(ItemList);
				LocalCtx.iLevel = Ctx.iLevel;
				AddItemsInt(LocalCtx);

				//	Now loop over the items and adjust the count appropriately.

				for (j = 0; j < LocalList.GetCount(); j++)
					{
					const CItem &Item = LocalList.GetItem(j);
					int iOriginalCount = Item.GetCount();

					//	Adjust the count

					Metric rNewCount = iOriginalCount * rLastLoopAdj;
					Metric rNewCountInt = floor(rNewCount);
					int iNewCount = (int)rNewCountInt;

					Metric rExtra = rNewCount - rNewCountInt;
					int iExtraChance = (int)(100000.0 * rExtra);
					if (mathRandom(0, 100000) < iExtraChance)
						iNewCount++;

					//	Add the item with the new count

					if (iNewCount > 0)
						{
						if (iNewCount == iOriginalCount)
							Ctx.ItemList.AddItem(Item);
						else
							{
							CItem NewItem(Item);
							NewItem.SetCount(iNewCount);
							Ctx.ItemList.AddItem(NewItem);
							}
						}
					}
				}
			}
		}
	else
		AddItemsInt(Ctx);
	}