Ejemplo n.º 1
0
void CComplexArea::AddRect (TArray<SRect> &Array, int x, int y, int cxWidth, int cyHeight, int iRotation)

//	AddRect
//
//	Adds the rect

{
    int i;

    if (cxWidth <= 0 || cyHeight <= 0)
        return;

    //	See if we already have a rect like this

    for (i = 0; i < Array.GetCount(); i++)
    {
        SRect &Test = Array[i];
        if (Test.x == x
                && Test.y == y
                && Test.iRotation == iRotation
                && Test.cxWidth == cxWidth
                && Test.cyHeight == cyHeight)
            return;
    }

    //	Add it

    SRect *pRect = Array.Insert();
    pRect->x = x;
    pRect->y = y;
    pRect->cxWidth = cxWidth;
    pRect->cyHeight = cyHeight;
    pRect->iRotation = (iRotation > 0 ? (iRotation % 360) : 0);

    //	Add to bounds

    if (iRotation > 0)
    {
        int xLL = 0;
        int yLL = 0;

        int xLR, yLR;
        IntPolarToVector(iRotation, cxWidth, &xLR, &yLR);

        int xUL, yUL;
        IntPolarToVector(iRotation + 90, cyHeight, &xUL, &yUL);

        int xUR = xUL + xLR;
        int yUR = yUL + yLR;

        int xLeft = Min(Min(xLL, xLR), Min(xUL, xUR));
        int xRight = Max(Max(xLL, xLR), Max(xUL, xUR));
        int yTop = Max(Max(yLL, yLR), Max(yUL, yUR));
        int yBottom = Min(Min(yLL, yLR), Min(yUL, yUR));

        AddToBounds(x + xLeft, y + yTop, x + xRight, y + yBottom);
    }
    else
        AddToBounds(x, y + cyHeight, x + cxWidth, y);
}
void CDisintegrationEffect::InitParticle (SParticle *pParticle)

//	InitParticle
//
//	Initialize a particle

	{
	pParticle->iTicksLeft = mathRandom(10, 30);
	pParticle->x = 0;
	pParticle->y = 0;
	IntPolarToVector(mathRandom(0, 359),
			(Metric)(mathRandom(0, (FIXED_POINT * 2))),
			&pParticle->xV,
			&pParticle->yV);

	int iFade = mathRandom(25, 100);
	pParticle->wColor = CG16bitImage::RGBValue(
			(iFade * 0x80 / 100),
			(iFade * 0xff / 100),
			(iFade * 0xff / 100));
	}
Ejemplo n.º 3
0
void CGSelectorArea::SetRegionsFromArmor (CSpaceObject *pSource)

//	SetRegionsFromArmor
//
//	Generates regions showing armor and shields for the given ship.

	{
	int i;
	ASSERT(pSource);
	if (pSource == NULL)
		return;

	CShip *pShip = pSource->AsShip();
	if (pShip == NULL)
		return;

	CShipClass *pClass = pShip->GetClass();

	//	Compute some metrics.
	//
	//	We place the shield generator in the center and the armor segments in a
	//	circle around it.

	const RECT &rcRect = GetRect();
	int cxArea = RectWidth(rcRect);
	int cyArea = RectHeight(rcRect);

	const int iRadius = WIDE_COLUMN_SPACING;

	//	Now add all the armor segments

	for (i = 0; i < pShip->GetArmorSectionCount(); i++)
		{
		SEntry *pEntry = m_Regions.Insert();
		CInstalledArmor *pArmor = pShip->GetArmorSection(i);

		pEntry->iType = typeInstalledItem;
		pEntry->pItemCtx = new CItemCtx(pShip, pArmor);

		//	Position the armor segment in a circle (add 90 degrees because the
		//	ship image points up).

        const CShipArmorSegmentDesc &Section = pClass->GetHullSection(i);
        int iCenterAngle = 90 + Section.GetCenterAngle();

		int xCenter;
		int yCenter;
		IntPolarToVector(iCenterAngle, iRadius, &xCenter, &yCenter);

		pEntry->rcRect.left = xCenter - (ITEM_ENTRY_WIDTH / 2);
		pEntry->rcRect.top = -yCenter - (ITEM_ENTRY_HEIGHT / 2);
		pEntry->rcRect.right = pEntry->rcRect.left + ITEM_ENTRY_WIDTH;
		pEntry->rcRect.bottom = pEntry->rcRect.top + ITEM_ENTRY_HEIGHT;
		}

	//	Add the shield generator last

	SEntry *pEntry = m_Regions.Insert();
	CInstalledDevice *pShields = pShip->GetNamedDevice(devShields);
	if (pShields)
		{
		pEntry->iType = typeInstalledItem;
		pEntry->pItemCtx = new CItemCtx(pShip, pShields);
		}
	else
		{
		pEntry->iType = typeEmptySlot;
		pEntry->iSlotType = devShields;
		}

	pEntry->rcRect.left = -ITEM_ENTRY_WIDTH / 2;
	pEntry->rcRect.top = -ITEM_ENTRY_HEIGHT / 2;
	pEntry->rcRect.right = pEntry->rcRect.left + ITEM_ENTRY_WIDTH;
	pEntry->rcRect.bottom = pEntry->rcRect.top + ITEM_ENTRY_HEIGHT;
	}