예제 #1
0
ALERROR CUniverse::InitLevelEncounterTables (void)

//	InitLevelEncounterTables
//
//	Initializes the m_LevelEncounterTables array based on the encounter
//	tables of all the stations for each level.

	{
	m_LevelEncounterTables.RemoveAll();

	for (int i = 1; i <= MAX_ITEM_LEVEL; i++)
		{
		CStructArray *pTable = new CStructArray(sizeof(SLevelEncounter), 8);

		for (int j = 0; j < GetStationTypeCount(); j++)
			{
			CStationType *pType = GetStationType(j);

			//	Figure out the frequency of an encounter from this station based
			//	on the frequency of the station at this level and the frequency
			//	of encounters for this station.

			int iEncounterFreq = pType->GetEncounterFrequency();
			int iStationFreq = pType->GetFrequencyByLevel(i);
			int iFreq = iEncounterFreq * iStationFreq / ftCommon;

			//	Add to the table

			if (iFreq > 0)
				{
				pTable->ExpandArray(pTable->GetCount(), 1);
				SLevelEncounter *pEntry = (SLevelEncounter *)pTable->GetStruct(pTable->GetCount()-1);

				pEntry->iWeight = iFreq;
				pEntry->pBaseSovereign = pType->GetSovereign();
				pEntry->pTable = pType->GetEncountersTable();
				}
			}

		m_LevelEncounterTables.AppendObject(pTable, NULL);
		}

	return NOERROR;
	}
예제 #2
0
void GenerateStationFrequencyTable (CUniverse &Universe, CXMLElement *pCmdLine)
	{
	int i, j;

	printf("STATION FREQUENCY TABLE\n\n");

	//	Figure out which columns to show

	TArray<CString> Cols;
	Cols.Insert(CONSTLIT("Level"));
	Cols.Insert(CONSTLIT("Freq"));
	Cols.Insert(CONSTLIT("Name"));
	Cols.Insert(CONSTLIT("Type"));
	Cols.Insert(CONSTLIT("Environment"));

	//	Print the header

	for (i = 0; i < Cols.GetCount(); i++)
		{
		if (i != 0)
			printf("\t");
		printf("%s", (LPSTR)Cols[i]);
		}

	printf("\n");

	//	For all levels, 1-25

	int iLevel;
	for (iLevel = 1; iLevel <= MAX_ITEM_LEVEL; iLevel++)
		{
		CSymbolTable Sort(FALSE, TRUE);

		//	Find all stations for this level and add them to
		//	a sorting table

		for (i = 0; i < Universe.GetStationTypeCount(); i++)
			{
			CStationType *pType = Universe.GetStationType(i);

			if (pType->GetFrequencyByLevel(iLevel) > 0)
				{
				char szBuffer[256];
				wsprintf(szBuffer, "%02d %s", 
						ftCommon - pType->GetFrequencyByLevel(iLevel),
						pType->GetName().GetASCIIZPointer());
						
				Sort.AddEntry(CString(szBuffer), (CObject *)pType);
				}
			}

		//	Print out the stations for this level

		if (Sort.GetCount() > 0)
			{
			for (i = 0; i < Sort.GetCount(); i++)
				{
				CStationType *pType = (CStationType *)Sort.GetValue(i);

				for (j = 0; j < Cols.GetCount(); j++)
					{
					if (j != 0)
						printf("\t");

					if (strEquals(Cols[j], CONSTLIT("Level")))
						printf("%d", iLevel);
					else if (strEquals(Cols[j], CONSTLIT("Freq")))
						printf((LPSTR)FrequencyChar(pType->GetFrequencyByLevel(iLevel)));
					else if (strEquals(Cols[j], CONSTLIT("Name")))
						printf((LPSTR)pType->GetName());
					else if (strEquals(Cols[j], CONSTLIT("Type")))
						{
						if (pType->HasAttribute(CONSTLIT("enemy")))
							printf("Enemy");
						else if (pType->HasAttribute(CONSTLIT("debris")))
							printf("Debris");
						else
							printf("Friend");
						}
					else if (strEquals(Cols[j], CONSTLIT("Environment")))
						{
						bool bElements = false;

						if (pType->HasAttribute(CONSTLIT("envAir")))
							{
							if (bElements)
								printf(", ");

							printf("envAir");
							bElements = true;
							}

						if (pType->HasAttribute(CONSTLIT("envEarth")))
							{
							if (bElements)
								printf(", ");

							printf("envEarth");
							bElements = true;
							}

						if (pType->HasAttribute(CONSTLIT("envFire")))
							{
							if (bElements)
								printf(", ");

							printf("envFire");
							bElements = true;
							}

						if (pType->HasAttribute(CONSTLIT("envWater")))
							{
							if (bElements)
								printf(", ");

							printf("envWater");
							bElements = true;
							}

						if (!bElements)
							printf("None");
						}
					}

				printf("\n");
				}
			}
		}
	}