本文整理汇总了C++中CShipClass类的典型用法代码示例。如果您正苦于以下问题:C++ CShipClass类的具体用法?C++ CShipClass怎么用?C++ CShipClass使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了CShipClass类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: sizeof
void CCompositeImageSelector::WriteToStream (IWriteStream *pStream) const
// WriteToStream
//
// Writes to a stream
//
// DWORD No of entries
// For each
// DWORD dwID
// DWORD iVariant
// DWORD Shipwreck UNID
{
int i;
DWORD dwSave;
dwSave = m_Sel.GetCount();
pStream->Write((char *)&dwSave, sizeof(DWORD));
// Save each entry
for (i = 0; i < m_Sel.GetCount(); i++)
{
pStream->Write((char *)&m_Sel[i].dwID, sizeof(DWORD));
pStream->Write((char *)&m_Sel[i].iVariant, sizeof(DWORD));
CShipClass *pWreckClass = (CShipClass *)m_Sel[i].dwExtra;
dwSave = (pWreckClass ? pWreckClass->GetUNID() : 0);
pStream->Write((char *)&dwSave, sizeof(DWORD));
}
}
示例2: GetShipwreckClass
CObjectImageArray &CCompositeImageSelector::GetShipwreckImage (DWORD dwID) const
// GetShipwreckImage
//
// Returns the shipwreck image for the given selection
{
CShipClass *pWreckClass = GetShipwreckClass(dwID);
if (pWreckClass == NULL)
return EMPTY_IMAGE;
return pWreckClass->GetWreckImage();
}
示例3: ArrangeByCell
void ArrangeByCell (CSymbolTable &Table, int cxDesiredWidth, CPaintMap &Map)
{
int i;
// Compute the size of each image cell
int cxCell = 32;
int cyCell = 32;
// Compute the number of rows & columns
int iInitCols = (cxDesiredWidth / cxCell) + ((cxDesiredWidth % cxCell) ? 1 : 0);
int iInitRows = AlignUp(20 * Table.GetCount(), iInitCols) / iInitCols;
// Create an array that keeps track of which cells we've used up
CCellMap CellMap(iInitCols, iInitRows);
// Figure out where to place all the ships
for (i = 0; i < Table.GetCount(); i++)
{
CShipClass *pClass = (CShipClass *)Table.GetValue(i);
// Figure out how many cells we need
int cxSize = RectWidth(pClass->GetImage().GetImageRect());
int iCellsNeeded = AlignUp(cxSize, cxCell) / cxCell;
int cxAreaSize = iCellsNeeded * cxCell;
// Position the ship
int x, y;
if (CellMap.GetSpace(iCellsNeeded, &x, &y))
Map.Place(i,
x * cxCell + (cxAreaSize - cxSize) / 2,
y * cyCell + (cxAreaSize - cxSize) / 2,
cxSize,
cxSize);
}
}
示例4: GetStartingShipClasses
ALERROR CAdventureDesc::GetStartingShipClasses (TSortMap<CString, CShipClass *> *retClasses, CString *retsError)
// GetStartingShipClasses
//
// Returns a sorted list of ship classes for this adventure
{
int i;
bool bShowDebugShips = g_pUniverse->InDebugMode();
// Make a list
retClasses->DeleteAll();
for (i = 0; i < g_pUniverse->GetShipClassCount(); i++)
{
CShipClass *pClass = g_pUniverse->GetShipClass(i);
if (pClass->IsShownAtNewGame()
&& IsValidStartingClass(pClass)
&& (!pClass->IsDebugOnly() || bShowDebugShips))
{
CString sKey = strPatternSubst(CONSTLIT("%d %s !%x"),
(pClass->IsDebugOnly() ? 2 : 1),
pClass->GetName(),
pClass->GetUNID());
retClasses->Insert(sKey, pClass);
}
}
return NOERROR;
}
示例5: OnObjDestroyedByPlayer
void CPlayerGameStats::OnObjDestroyedByPlayer (const SDestroyCtx &Ctx, CSpaceObject *pPlayer)
// OnDestroyedByPlayer
//
// Object destroyed by player
{
bool bIsEnemy = Ctx.pObj->IsEnemy(pPlayer);
// Is this a ship?
CShip *pShip;
if (Ctx.pObj->GetCategory() == CSpaceObject::catShip && (pShip = Ctx.pObj->AsShip()))
{
CShipClass *pClass = pShip->GetClass();
SShipClassStats *pStats = GetShipStats(pClass->GetUNID());
if (bIsEnemy)
{
pStats->iEnemyDestroyed++;
m_iScore += pClass->GetScore();
}
else
pStats->iFriendDestroyed++;
}
// Is this a station?
else if (Ctx.pObj->GetCategory() == CSpaceObject::catStation)
{
if (Ctx.pObj->HasAttribute(CONSTLIT("populated")))
{
SStationTypeStats *pStats = GetStationStats(Ctx.pObj->GetType()->GetUNID());
pStats->iDestroyed++;
}
}
}
示例6: while
int CPlayerGameStats::GetBestEnemyShipsDestroyed (DWORD *retdwUNID) const
// GetBestEnemyShipDestroyed
//
// Returns the number of enemy ships destroyed of the most powerful ship class
{
CMapIterator i;
int iBestScore = 0;
DWORD dwBestUNID = 0;
SShipClassStats *pBest = NULL;
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)
{
int iScore = pClass->GetScore();
if (iScore > iBestScore)
{
dwBestUNID = dwUNID;
iBestScore = iScore;
pBest = pStats;
}
}
}
if (pBest == NULL)
return 0;
if (retdwUNID)
*retdwUNID = dwBestUNID;
return pBest->iEnemyDestroyed;
}
示例7: ASSERT
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;
}
示例8: OutputByShipClass
void OutputByShipClass (SItemTableCtx &Ctx, const SItemTypeList &ItemList, bool bShowUsage)
{
int i, j;
// Make a map of ship classes for each item
TSortMap<DWORD, TArray<CShipClass *>> ItemToShipClass;
for (i = 0; i < g_pUniverse->GetShipClassCount(); i++)
{
CShipClass *pClass = g_pUniverse->GetShipClass(i);
// Skip non-generic ones
if (!pClass->HasLiteralAttribute(CONSTLIT("genericClass")))
continue;
// Add the list of types used by the ship
TSortMap<DWORD, bool> TypesUsed;
pClass->AddTypesUsed(&TypesUsed);
// For each item type, add it to the map
for (j = 0; j < TypesUsed.GetCount(); j++)
{
CDesignType *pType = g_pUniverse->FindDesignType(TypesUsed.GetKey(j));
if (pType && pType->GetType() == designItemType)
{
TArray<CShipClass *> *pList = ItemToShipClass.SetAt(pType->GetUNID());
pList->Insert(pClass);
}
}
}
// If we want to show usage, then we print each item along with the
// ship classes using each item.
if (bShowUsage)
{
for (i = 0; i < ItemList.GetCount(); i++)
{
CItemType *pType = ItemList[i];
printf("%s\n", (LPSTR)pType->GetNounPhrase());
TArray<CShipClass *> *pList = ItemToShipClass.SetAt(pType->GetUNID());
for (j = 0; j < pList->GetCount(); j++)
printf("\t%s\n", (LPSTR)pList->GetAt(j)->GetName());
if (pList->GetCount() == 0)
printf("\t(none)\n");
printf("\n");
}
}
// Otherwise we categorize by ship class
else
{
// Now make a list of all ship classes that have our items
SByShipClassTypeList ByShipClassTable;
for (i = 0; i < ItemList.GetCount(); i++)
{
const CString &sKey = ItemList.GetKey(i);
CItemType *pType = ItemList[i];
// Loop over all ship classes
TArray<CShipClass *> *pList = ItemToShipClass.SetAt(pType->GetUNID());
for (j = 0; j < pList->GetCount(); j++)
{
CString sClassName = pList->GetAt(j)->GetName();
bool bNew;
SShipClassEntry *pEntry = ByShipClassTable.SetAt(sClassName, &bNew);
if (bNew)
pEntry->sShipClassName = sClassName;
pEntry->ItemTable.Insert(sKey, pType);
}
// If no ship class
if (pList->GetCount() == 0)
{
bool bNew;
SShipClassEntry *pEntry = ByShipClassTable.SetAt(CONSTLIT("(none)"), &bNew);
if (bNew)
pEntry->sShipClassName = CONSTLIT("(none)");
pEntry->ItemTable.Insert(sKey, pType);
}
}
// Now loop over all attributes
for (i = 0; i < ByShipClassTable.GetCount(); i++)
{
const SShipClassEntry &Entry = ByShipClassTable[i];
//.........这里部分代码省略.........
示例9: RunEncounterSim
void RunEncounterSim (CUniverse &Universe, CXMLElement *pCmdLine)
{
int iRuns = pCmdLine->GetAttributeIntegerBounded(COUNT_ATTRIB, 1, -1, DEFAULT_RUN_COUNT);
int iTimeOut = DEFAULT_TIME_OUT;
// Get the station criteria
CString sCriteria = strPatternSubst(CONSTLIT("%s t"), pCmdLine->GetAttribute(DEFENDERS_ATTRIB));
CDesignTypeCriteria DefenderCriteria;
if (CDesignTypeCriteria::ParseCriteria(sCriteria, &DefenderCriteria) != NOERROR)
{
printf("ERROR: Unable to parse defenders criteria.\n");
return;
}
bool bAll = pCmdLine->GetAttributeBool(CONSTLIT("all"));
// Get the criteria from the command line. Always append 's' because we
// want ship classes.
sCriteria = strPatternSubst(CONSTLIT("%s s"), pCmdLine->GetAttribute(ATTACKERS_ATTRIB));
CDesignTypeCriteria AttackerCriteria;
if (CDesignTypeCriteria::ParseCriteria(sCriteria, &AttackerCriteria) != NOERROR)
{
printf("ERROR: Unable to parse attackers criteria.\n");
return;
}
// Create a viewer, if desired
CSimViewer Viewer;
if (pCmdLine->GetAttributeBool(VIEWER_ATTRIB))
Viewer.Create();
// Print headers
printf("Encounter\tLevel");
int iAttacker;
for (iAttacker = 0; iAttacker < Universe.GetShipClassCount(); iAttacker++)
{
CShipClass *pAttackerClass = Universe.GetShipClass(iAttacker);
if (!pAttackerClass->MatchesCriteria(AttackerCriteria))
continue;
printf("\t%s", pAttackerClass->GetName().GetASCIIZPointer());
}
printf("\n");
// Loop over all defenders
int iDefender;
for (iDefender = 0; iDefender < Universe.GetStationTypeCount(); iDefender++)
{
CStationType *pDefenderType = Universe.GetStationType(iDefender);
if (!bAll && pDefenderType->GetLevel() == 0)
continue;
if (!pDefenderType->MatchesCriteria(DefenderCriteria))
continue;
// Compute an enemy of the station
CSovereign *pAttackerSovereign = GetAttackerSovereign(Universe, pDefenderType);
if (pAttackerSovereign == NULL)
{
printf("ERROR: Unable to find enemy sovereign of encounter: %s [%x].\n", pDefenderType->GetNounPhrase().GetASCIIZPointer(), pDefenderType->GetUNID());
return;
}
printf("%s [%x]\t%d", pDefenderType->GetNounPhrase().GetASCIIZPointer(), pDefenderType->GetUNID(), pDefenderType->GetLevel());
// Loop over all attackers
for (iAttacker = 0; iAttacker < Universe.GetShipClassCount(); iAttacker++)
{
CShipClass *pAttackerClass = Universe.GetShipClass(iAttacker);
if (!pAttackerClass->MatchesCriteria(AttackerCriteria))
continue;
// Do several runs so we can get some statistical data
int iAttackerSurvived = 0;
int iRun;
for (iRun = 0; iRun < iRuns; iRun++)
{
EResults iResult = RunEncounter(Universe, Viewer, pDefenderType, pAttackerClass, pAttackerSovereign);
if (iResult == resultError)
return;
// Did the attacker survive?
if (iResult != resultAttackerDestroyed)
iAttackerSurvived++;
}
// Output results for this attacker
//.........这里部分代码省略.........
示例10: GenerateShipTable
void GenerateShipTable (CUniverse &Universe, CXMLElement *pCmdLine, CIDTable &EntityTable)
{
int i, j;
// Some options
bool bAllClasses = (pCmdLine->GetAttributeBool(CONSTLIT("allClasses")) || pCmdLine->GetAttributeBool(CONSTLIT("all")));
// Get the criteria from the command line. Always append 's' because we
// want ship classes.
CString sCriteria = strPatternSubst(CONSTLIT("%s s"), pCmdLine->GetAttribute(CONSTLIT("criteria")));
CDesignTypeCriteria Criteria;
if (CDesignTypeCriteria::ParseCriteria(sCriteria, &Criteria) != NOERROR)
{
printf("ERROR: Unable to parse criteria.\n");
return;
}
// Generate a list of columns to display
TArray<CString> Cols;
Cols.Insert(FIELD_LEVEL);
Cols.Insert(FIELD_NAME);
for (i = 0; i < pCmdLine->GetAttributeCount(); i++)
{
CString sAttrib = pCmdLine->GetAttributeName(i);
if (strEquals(sAttrib, FIELD_BALANCE))
{
Cols.Insert(CONSTLIT("balanceType"));
Cols.Insert(CONSTLIT("combatStrength"));
Cols.Insert(CONSTLIT("damage"));
Cols.Insert(CONSTLIT("defenseStrength"));
}
else if (!IsMainCommandParam(sAttrib)
&& !strEquals(sAttrib, CONSTLIT("shiptable")))
{
CString sValue = pCmdLine->GetAttribute(i);
if (!strEquals(sValue, CONSTLIT("true")))
Cols.Insert(strPatternSubst(CONSTLIT("%s:%s"), sAttrib, sValue));
else
Cols.Insert(sAttrib);
}
}
// Output the header
for (j = 0; j < Cols.GetCount(); j++)
{
if (j != 0)
printf("\t");
printf(Cols[j].GetASCIIZPointer());
}
printf("\n");
// Generate a table
CSymbolTable Table(FALSE, TRUE);
// Loop over all items that match and add them to
// a sorted table.
for (i = 0; i < Universe.GetShipClassCount(); i++)
{
CShipClass *pClass = Universe.GetShipClass(i);
// Only include generic classes unless otherwise specified
if (!bAllClasses && !pClass->HasLiteralAttribute(CONSTLIT("genericClass")))
continue;
if (!pClass->MatchesCriteria(Criteria))
continue;
// Figure out the sort order
char szBuffer[1024];
wsprintf(szBuffer, "%04d%s%d",
pClass->GetLevel(),
pClass->GetNounPhrase(0).GetASCIIZPointer(),
pClass->GetUNID());
Table.AddEntry(CString(szBuffer), (CObject *)pClass);
}
// Output table
for (i = 0; i < Table.GetCount(); i++)
{
CShipClass *pClass = (CShipClass *)Table.GetValue(i);
// Output each row
for (j = 0; j < Cols.GetCount(); j++)
{
if (j != 0)
//.........这里部分代码省略.........
示例11: CVector
void CListSaveFilesTask::CreateFileEntry (CGameFile &GameFile, const CTimeDate &ModifiedTime, int yStart, IAnimatron **retpEntry, int *retcyHeight)
// CreateFileEntry
//
// Creates a display entry for the save file
{
const CVisualPalette &VI = m_HI.GetVisuals();
const CG16bitFont &MediumFont = VI.GetFont(fontMedium);
const CG16bitFont &SubTitleFont = VI.GetFont(fontSubTitle);
int x = 0;
int y = 0;
int xText = x + ADVENTURE_ICON_WIDTH + ICON_SPACING_HORZ;
int cxText = m_cxWidth - (ADVENTURE_ICON_WIDTH + 2 * ICON_SPACING_HORZ + SHIP_IMAGE_WIDTH);
// Start with a sequencer
CAniSequencer *pRoot = new CAniSequencer;
pRoot->SetPropertyVector(PROP_POSITION, CVector(0, yStart));
// Add the character name and current star system
CString sHeading = strPatternSubst(CONSTLIT("%s — %s"), GameFile.GetPlayerName(), GameFile.GetSystemName());
IAnimatron *pName = new CAniText;
pName->SetPropertyVector(PROP_POSITION, CVector(xText, y));
pName->SetPropertyVector(PROP_SCALE, CVector(10000, 1000));
pName->SetPropertyColor(PROP_COLOR, VI.GetColor(colorTextDialogInput));
pName->SetPropertyFont(PROP_FONT, &SubTitleFont);
pName->SetPropertyString(PROP_TEXT, sHeading);
pRoot->AddTrack(pName, 0);
y += SubTitleFont.GetHeight();
// Now add some additional information
CShipClass *pClass = g_pUniverse->FindShipClass(GameFile.GetPlayerShip());
CString sShipClass = (pClass ? pClass->GetName() : NULL_STR);
CString sGenome = strCapitalize(GetGenomeName(GameFile.GetPlayerGenome()));
CString sState;
if (GameFile.IsGameResurrect())
sState = strPatternSubst(CONSTLIT("Resurrect in the %s System"), GameFile.GetSystemName());
else
sState = strPatternSubst(CONSTLIT("Continue in the %s System"), GameFile.GetSystemName());
CString sDesc;
if (!sGenome.IsBlank() && !sShipClass.IsBlank())
sDesc = strPatternSubst(CONSTLIT("%s — %s — %s"), sGenome, sShipClass, sState);
else
sDesc = sState;
IAnimatron *pDesc = new CAniText;
pDesc->SetPropertyVector(PROP_POSITION, CVector(xText, y));
pDesc->SetPropertyVector(PROP_SCALE, CVector(cxText, 1000));
pDesc->SetPropertyColor(PROP_COLOR, VI.GetColor(colorTextDialogInput));
pDesc->SetPropertyFont(PROP_FONT, &MediumFont);
pDesc->SetPropertyString(PROP_TEXT, sDesc);
RECT rcLine;
pDesc->GetSpacingRect(&rcLine);
pRoot->AddTrack(pDesc, 0);
y += RectHeight(rcLine);
// Adventure info
CExtension *pAdventure = NULL;
bool bHasAdventureIcon = false;
if (g_pUniverse->FindExtension(GameFile.GetAdventure(), 0, &pAdventure))
{
// Adventure icon
CG16bitImage *pIcon;
pAdventure->CreateIcon(ADVENTURE_ICON_WIDTH, ADVENTURE_ICON_HEIGHT, &pIcon);
if (pIcon)
{
int xOffset = (ADVENTURE_ICON_WIDTH - pIcon->GetWidth()) / 2;
IAnimatron *pIconAni = new CAniRect;
pIconAni->SetPropertyVector(PROP_POSITION, CVector(x + xOffset, 0));
pIconAni->SetPropertyVector(PROP_SCALE, CVector(pIcon->GetWidth(), pIcon->GetHeight()));
pIconAni->SetFillMethod(new CAniImageFill(pIcon, true));
pRoot->AddTrack(pIconAni, 0);
bHasAdventureIcon = true;
}
// Adventure name
pName = new CAniText;
pName->SetPropertyVector(PROP_POSITION, CVector(xText, y));
pName->SetPropertyVector(PROP_SCALE, CVector(10000, 1000));
pName->SetPropertyColor(PROP_COLOR, VI.GetColor(colorTextDialogLabel));
pName->SetPropertyFont(PROP_FONT, &MediumFont);
pName->SetPropertyString(PROP_TEXT, pAdventure->GetName());
//.........这里部分代码省略.........
示例12: CreateRandomShip
ALERROR CTranscendenceWnd::CreateRandomShip (CSystem *pSystem, CSovereign *pSovereign, CShip **retpShip)
// CreateRandomShip
//
// Creates a random ship
{
ALERROR error;
int i;
// Figure out the class
CShipClass *pShipClass;
if (m_dwIntroShipClass == 0)
{
do
pShipClass = m_Universe.GetShipClass(mathRandom(0, m_Universe.GetShipClassCount()-1));
while (pShipClass->GetScore() > 1000 || pShipClass->IsPlayerShip());
}
else
{
int i;
int iIndex = -1;
for (i = 0; i < m_Universe.GetShipClassCount(); i++)
if (m_Universe.GetShipClass(i)->GetUNID() == m_dwIntroShipClass)
{
iIndex = i;
break;
}
if (iIndex == -1 || (iIndex + 1) == m_Universe.GetShipClassCount())
pShipClass = m_Universe.GetShipClass(0);
else
pShipClass = m_Universe.GetShipClass(iIndex + 1);
m_dwIntroShipClass = 0;
}
// Normally we create a single ship, but sometimes we create lots
int iCount;
int iRoll = mathRandom(1, 100);
// Adjust the roll for capital ships
if (pShipClass->GetHullMass() >= 10000)
iRoll -= 9;
else if (pShipClass->GetHullMass() >= 1000)
iRoll -= 6;
if (iRoll == 100)
iCount = mathRandom(30, 60);
else if (iRoll >= 98)
iCount = mathRandom(10, 20);
else if (iRoll >= 95)
iCount = mathRandom(5, 10);
else if (iRoll >= 90)
iCount = mathRandom(2, 5);
else
iCount = 1;
// Create the ships
for (i = 0; i < iCount; i++)
{
CShip *pShip;
if ((error = pSystem->CreateShip(pShipClass->GetUNID(),
NULL,
pSovereign,
PolarToVector(mathRandom(0, 359), mathRandom(250, 2500) * g_KlicksPerPixel),
NullVector,
mathRandom(0, 359),
NULL,
&pShip)))
return error;
// Override the controller
CIntroShipController *pNewController = new CIntroShipController(this, pShip->GetController());
pShip->SetController(pNewController, false);
pNewController->SetShip(pShip);
pShip->SetData(CONSTLIT("IntroController"), CONSTLIT("True"));
*retpShip = pShip;
}
return NOERROR;
}
示例13: GenerateShipImageChart
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;
//.........这里部分代码省略.........
示例14: ArrangeByRow
void ArrangeByRow (CSymbolTable &Table, SArrangeDesc &Desc, CPaintMap &Map)
{
int iNext = 0;
int y = 0;
int cyHeader = Desc.pHeader->GetHeight();
int cxInternalSpacing = 8;
int cyInternalSpacing = 2 * Desc.pHeader->GetHeight();
int cyNameSpacing = Desc.pHeader->GetHeight() / 2;
while (iNext < Table.GetCount())
{
int i;
int cxWidthLeft = Desc.cxDesiredWidth;
int cyRowHeight = 0;
int iStart = iNext;
// First figure out how many ships will fit
while (iNext < Table.GetCount())
{
CShipClass *pClass = (CShipClass *)Table.GetValue(iNext);
int cxSize = RectWidth(pClass->GetImage().GetImageRect());
if (cxSize > cxWidthLeft && iStart != iNext)
break;
int cxCell = Max(cxSize + cxInternalSpacing, Desc.cxSpacing);
cxWidthLeft -= cxCell;
if (cxSize > cyRowHeight)
cyRowHeight = cxSize;
iNext++;
}
// Compute the total width
int cxRowWidth = Min(Desc.cxDesiredWidth - cxWidthLeft, Desc.cxDesiredWidth);
int xOffset = (Desc.cxDesiredWidth - cxRowWidth) / 2;
// See if any of the ships overlap the text from the previous ships
// If so, we increase y a little bit
int x = Desc.cxSpacing + Desc.cxExtraMargin;
for (i = iStart; i < iNext; i++)
{
CShipClass *pClass = (CShipClass *)Table.GetValue(i);
int cxSize = RectWidth(pClass->GetImage().GetImageRect());
int yOffset = (cyRowHeight - cxSize) / 2;
int xPoint = x + xOffset + cxSize / 2;
int yPoint = y + yOffset;
for (int j = 0; j < iStart; j++)
{
int xText = Map.GetTextX(j);
int yText = Map.GetTextY(j);
int cxText = Map.GetTextWidth(j);
int cyText = Map.GetTextHeight(j) + cyInternalSpacing;
if (xPoint >= xText && xPoint < xText + cxText && yPoint < yText + cyText)
y = yText + cyText + cyInternalSpacing;
}
int cxCell = Max(cxSize + cxInternalSpacing, Desc.cxSpacing);
x += cxCell;
}
// Place the ships
x = Desc.cxSpacing + Desc.cxExtraMargin;
int yOverlapOffset = 0;
for (i = iStart; i < iNext; i++)
{
CShipClass *pClass = (CShipClass *)Table.GetValue(i);
int cxSize = RectWidth(pClass->GetImage().GetImageRect());
int cxCell = Max(cxSize + cxInternalSpacing, Desc.cxSpacing);
// Center vertically
int yOffset = (cyRowHeight - cxSize) / 2;
// Place
Map.Place(i, x + xOffset, y + yOffset, cxSize, cxSize);
// Figure out the position of the text
int cyName;
int cxName = Desc.pHeader->MeasureText(pClass->GetNounPhrase(0), &cyName);
if (cxName <= cxSize)
{
int yText = y + yOffset + cxSize + cyNameSpacing;
Map.PlaceText(i,
x + xOffset + (cxSize - cxName) / 2,
yText,
cxName,
cyName);
yOverlapOffset = yText + cyName + cyNameSpacing;
//.........这里部分代码省略.........
示例15: strCapitalize
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);
//.........这里部分代码省略.........