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;
}
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));
		}
	}
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++;
			}
		}
	}
Example #4
0
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)
				printf("\t");

			const CString &sField = Cols[j];
			CString sValue;

			if (strEquals(sField, FIELD_ENTITY))
				{
				CString *pValue;
				if (EntityTable.Lookup(pClass->GetUNID(), (CObject **)&pValue) == NOERROR)
					sValue = *pValue;
				else
					sValue = CONSTLIT("?");
				}
			else
				sValue = pClass->GetDataField(sField);

			if (strEquals(sField, FIELD_MANEUVER) 
					|| strEquals(sField, FIELD_THRUST_TO_WEIGHT))
				printf("%.1f", strToInt(sValue, 0, NULL) / 1000.0);
			else if (strEquals(sField, FIELD_SCORE_CALC))
				printf("%d", pClass->CalcScore());
			else
				printf(sValue.GetASCIIZPointer());
			}

		printf("\n");
		}

	printf("\n");
	}
Example #5
0
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;
	}