bool CMissile::PointInObject (CVector vPos) // PointInObject // // Returns TRUE if the given point is inside the object { if (m_fDestroyed) return false; // Figure out the coordinates of vPos relative to the center of the // object, in pixels. CVector vOffset = vPos - GetPos(); int x = (int)((vOffset.GetX() / g_KlicksPerPixel) + 0.5); int y = -(int)((vOffset.GetY() / g_KlicksPerPixel) + 0.5); if (m_pPainter) return m_pPainter->PointInImage(x, y, m_iTick, (m_pDesc->m_bDirectional ? Angle2Direction(m_iRotation) : 0)); else return m_pDesc->m_Image.PointInImage(x, y, m_iTick, (m_pDesc->m_bDirectional ? Angle2Direction(m_iRotation) : 0)); }
void CMissile::OnPaint (CG16bitImage &Dest, int x, int y, SViewportPaintCtx &Ctx) // OnPaint // // Paint the station { // Paint with painter if (m_pPainter) { Ctx.iTick = m_iTick; Ctx.iVariant = (m_pDesc->m_bDirectional ? Angle2Direction(m_iRotation) : 0); Ctx.iRotation = m_iRotation; Ctx.iDestiny = GetDestiny(); if (!m_fDestroyed && (m_pHit == NULL || m_fPassthrough)) m_pPainter->Paint(Dest, x, y, Ctx); else if (m_pHit) m_pPainter->PaintHit(Dest, x, y, m_vHitPos, Ctx); else m_pPainter->PaintFade(Dest, x, y, Ctx); // For backwards compatibility, we also paint an image for beams // LATER: We should incorporate this into the painter when we // load the CWeaponFireDesc. if (m_pDesc->GetFireType() == ftBeam && !m_pDesc->m_Image.IsEmpty()) { m_pDesc->m_Image.PaintImage(Dest, x, y, m_iTick, 0); } } // Paint image (deprecated method) if (m_pPainter == NULL && !m_fDestroyed && m_pHit == NULL) { m_pDesc->m_Image.PaintImage(Dest, x, y, m_iTick, (m_pDesc->m_bDirectional ? Angle2Direction(m_iRotation) : 0)); // Paint exhaust trail if (m_pExhaust) { int iCount = m_pExhaust->GetCount(); for (int i = 0; i < iCount; i++) { int xParticle, yParticle; Ctx.XForm.Transform(m_pExhaust->GetAt(i).vPos, &xParticle, &yParticle); m_pDesc->m_ExhaustImage.PaintImage(Dest, xParticle, yParticle, (iCount - i - 1) * m_pDesc->m_iExhaustRate, 0); } } } // Paint vapor trail if (m_pDesc->GetVaporTrailLength()) { int iCount = ComputeVaporTrail(); int iFadeStep = (128 / m_pDesc->GetVaporTrailLength()); int iOpacity = (!m_fDestroyed ? 128 : (iFadeStep * m_iLifeLeft)); int iStart = (!m_fDestroyed ? 0 : 1 + (m_pDesc->GetVaporTrailLength() - m_iLifeLeft)); for (int i = iStart; i < iCount; i++) { m_pVaporTrailRegions[i].FillTrans(Dest, x, y, m_pDesc->GetVaporTrailColor(), iOpacity); iOpacity -= iFadeStep; if (iOpacity <= 0) break; } } }
void GenerateShipImageChart (CUniverse &Universe, CXMLElement *pCmdLine) { int i; enum OrderTypes { orderSmallest = 1, orderLargest = 2, orderName = 3, }; // Options bool bTextBoxesOnly = pCmdLine->GetAttributeBool(CONSTLIT("textBoxesOnly")); // Figure out what order we want CString sOrder = pCmdLine->GetAttribute(CONSTLIT("sort")); int iOrder; if (strEquals(sOrder, CONSTLIT("smallest"))) iOrder = orderSmallest; else if (strEquals(sOrder, CONSTLIT("largest"))) iOrder = orderLargest; else iOrder = orderName; // Image size int cxDesiredWidth; if (pCmdLine->FindAttributeInteger(CONSTLIT("width"), &cxDesiredWidth)) cxDesiredWidth = Max(512, cxDesiredWidth); else cxDesiredWidth = 1280; // Spacing int cxSpacing = pCmdLine->GetAttributeInteger(CONSTLIT("xSpacing")); int cxExtraMargin = pCmdLine->GetAttributeInteger(CONSTLIT("xMargin")); // Rotation int iRotation = pCmdLine->GetAttributeInteger(CONSTLIT("rotation")); // Font for text CString sTypeface; int iSize; bool bBold; bool bItalic; if (!CG16bitFont::ParseFontDesc(pCmdLine->GetAttribute(CONSTLIT("font")), &sTypeface, &iSize, &bBold, &bItalic)) { sTypeface = CONSTLIT("Arial"); iSize = 10; bBold = false; bItalic = false; } CG16bitFont NameFont; NameFont.Create(sTypeface, -PointsToPixels(iSize), bBold, bItalic); WORD wNameColor = CG16bitImage::RGBValue(255, 255, 255); // Output file CString sFilespec = pCmdLine->GetAttribute(CONSTLIT("output")); if (!sFilespec.IsBlank()) sFilespec = pathAddExtensionIfNecessary(sFilespec, CONSTLIT(".bmp")); // Generate a table of ships CSymbolTable Table(FALSE, TRUE); for (i = 0; i < Universe.GetShipClassCount(); i++) { CShipClass *pClass = Universe.GetShipClass(i); // Skip player ship classes if (pClass->GetPlayerSettings()) continue; // Skip non-generic classes if (!pClass->HasAttribute(CONSTLIT("genericClass"))) continue; // Compute the sort key char szBuffer[1024]; switch (iOrder) { case orderLargest: wsprintf(szBuffer, "%04d%s%x", 2048 - RectWidth(pClass->GetImage().GetImageRect()), pClass->GetName().GetASCIIZPointer(), pClass); break; case orderSmallest: wsprintf(szBuffer, "%04d%s%x", RectWidth(pClass->GetImage().GetImageRect()), pClass->GetName().GetASCIIZPointer(), pClass); break; default: wsprintf(szBuffer, "%s%x", pClass->GetName().GetASCIIZPointer(), pClass); break; } // Add to list Table.AddEntry(CString(szBuffer), (CObject *)pClass); } // Allocate a map that tracks where to paint each ship CPaintMap Map(Table.GetCount()); // Arrange the ships SArrangeDesc Desc; Desc.cxDesiredWidth = Max(512, cxDesiredWidth - (2 * (cxSpacing + cxExtraMargin))); Desc.cxSpacing = cxSpacing; Desc.cxExtraMargin = cxExtraMargin; Desc.pHeader = &NameFont; ArrangeByRow(Table, Desc, Map); //ArrangeByCell(Table, cxDesiredWidth, Map); // Create a large image CG16bitImage Output; int cxWidth = Max(cxDesiredWidth, Map.GetWidth()); int cyHeight = Map.GetHeight(); Output.CreateBlank(cxWidth, cyHeight, false); printf("Creating %dx%d image.\n", cxWidth, cyHeight); // Paint the images for (i = 0; i < Table.GetCount(); i++) { CShipClass *pClass = (CShipClass *)Table.GetValue(i); int x = Map.GetX(i); int y = Map.GetY(i); if (x != -1) { if (!bTextBoxesOnly) pClass->GetImage().PaintImageUL(Output, x, y, 0, Angle2Direction(iRotation)); // Paint name int xText = Map.GetTextX(i); int yText = Map.GetTextY(i); if (xText != -1) { if (bTextBoxesOnly) Output.Fill(xText, yText, Map.GetTextWidth(i), Map.GetTextHeight(i), 0xffff); if (!bTextBoxesOnly) { Output.FillColumn(x + (Map.GetWidth(i) / 2), y + Map.GetHeight(i), yText - (y + Map.GetHeight(i)), wNameColor); NameFont.DrawText(Output, xText, yText, wNameColor, 255, pClass->GetNounPhrase(0)); } } } } // Write to file or clipboard OutputImage(Output, sFilespec); }
void CMissile::OnPaint (CG16bitImage &Dest, int x, int y, SViewportPaintCtx &Ctx) // OnPaint // // Paint the station { // Paint with painter if (m_pPainter) { Ctx.iTick = m_iTick; Ctx.iVariant = (m_pDesc->m_bDirectional ? Angle2Direction(m_iRotation) : 0); Ctx.iRotation = m_iRotation; Ctx.iDestiny = GetDestiny(); if (!m_fDestroyed && m_pHit == NULL) m_pPainter->Paint(Dest, x, y, Ctx); else m_pPainter->PaintFade(Dest, x, y, Ctx); } // Paint image (deprecated method) if (m_pPainter == NULL && !m_fDestroyed && m_pHit == NULL) { m_pDesc->m_Image.PaintImage(Dest, x, y, m_iTick, (m_pDesc->m_bDirectional ? Angle2Direction(m_iRotation) : 0)); // Paint exhaust trail if (m_pExhaust) { int iCount = m_pExhaust->GetCount(); for (int i = 0; i < iCount; i++) { int xParticle, yParticle; Ctx.XForm.Transform(m_pExhaust->GetAt(i).vPos, &xParticle, &yParticle); m_pDesc->m_ExhaustImage.PaintImage(Dest, xParticle, yParticle, (iCount - i - 1) * m_pDesc->m_iExhaustRate, 0); } } } // Paint vapor trail if (m_pDesc->m_iVaporTrailLength) { int iCount = ComputeVaporTrail(); int iFadeStep = (128 / m_pDesc->m_iVaporTrailLength); int iOpacity = (!m_fDestroyed ? 128 : (iFadeStep * m_iLifeLeft)); int iStart = (!m_fDestroyed ? 0 : 1 + (m_pDesc->m_iVaporTrailLength - m_iLifeLeft)); for (int i = iStart; i < iCount; i++) { m_pVaporTrailRegions[i].FillTrans(Dest, x, y, m_pDesc->m_wVaporTrailColor, iOpacity); iOpacity -= iFadeStep; if (iOpacity <= 0) break; } } }