void CCommandLineDisplay::InputDelete (void)

//	InputDelete
//
//	Delete characters from input buffer

	{
	if (m_sInput.GetLength() > 0 && m_iCursorPos < m_sInput.GetLength())
		{
		if (m_iCursorPos == 0)
			m_sInput = strSubString(m_sInput, 1, -1);
		else
			m_sInput = strCat(strSubString(m_sInput, 0, m_iCursorPos), strSubString(m_sInput, m_iCursorPos+1, -1));
		m_bInvalid = true;
		}
	}
예제 #2
0
CString pathGetExtension (const CString &sPath)

//	pathGetExtension
//
//	Returns the extension (without dot)

	{
	char *pPos;
	int iLength;

	pPos = sPath.GetASCIIZ();
	iLength = sPath.GetLength();

	//	Look for the extension

	while (iLength > 0)
		{
		if (pPos[iLength] == '.')
			break;
		iLength--;
		}

	//	Return the extension

	return strSubString(sPath, iLength + 1, -1);
	}
예제 #3
0
bool CAniTextInput::HandleChar (char chChar, DWORD dwKeyData)

//	HandleChar
//
//	Handle the character

	{
	if (!m_Properties[INDEX_ENABLED].GetBool())
		return false;

	//	If this is a backspace, delete a character

	else if (chChar == VK_BACK)
		{
		CString sText = m_Properties[INDEX_TEXT].GetString();
		sText = strSubString(sText, 0, sText.GetLength() - 1);
		m_Properties.SetString(PROP_TEXT, sText);

		return true;
		}

	//	If this is a text character, then add it to the input

	else if (strIsAlphaNumeric(&chChar) || chChar == ' ' || strIsASCIISymbol(&chChar))
		{
		CString sText = m_Properties[INDEX_TEXT].GetString();
		sText.Append(CString(&chChar, 1));
		m_Properties.SetString(PROP_TEXT, sText);

		return true;
		}
	else
		return false;
	}
const CString CCommandLineDisplay::GetCurrentCmd (void)

//	GetCurrentCmd
//
//	Returns the command fragment under the cursor from the input line

	{
	int iPos;
	CString sWord;

	// Want to extract the word to the left of cursor
	for (iPos = m_iCursorPos - 1; iPos >= 0; iPos--)
		{
		char *pPos = m_sInput.GetASCIIZPointer() + iPos;
		if (*pPos == ' ' || *pPos == '(')
			{
			iPos++;
			break;
			}
		if (*pPos == ')' || *pPos == '\'' || *pPos == '"')
			return NULL_STR;
		}

	if (iPos < 0) iPos = 0;
	return strSubString(m_sInput, iPos, m_iCursorPos - iPos);
	}
예제 #5
0
CString pathStripExtension (const CString &sPath)

//	pathStripExtension
//
//	Returns the path without the extension on the filename

	{
	char *pPos;
	int iLength;

	pPos = sPath.GetASCIIZ();
	iLength = sPath.GetLength();

	//	Look for the extension

	while (iLength > 0)
		{
		if (pPos[iLength] == '.')
			break;
		iLength--;
		}

	//	Return everything except the extension

	return strSubString(sPath, 0, iLength);
	}
void CCommandLineDisplay::InputBackspace (void)

//	InputBackspace
//
//	Delete characters from input buffer

	{
	if (m_iCursorPos > 0)
		{
		if (m_iCursorPos == m_sInput.GetLength())
			m_sInput = strSubString(m_sInput, 0, m_sInput.GetLength() - 1);
		else
			m_sInput = strCat(strSubString(m_sInput, 0, m_iCursorPos - 1), strSubString(m_sInput, m_iCursorPos, -1));
		m_iCursorPos--;
		m_bInvalid = true;
		}
	}
예제 #7
0
int CHighScoreList::AddEntry (const CGameRecord &NewEntry)

//	AddEntry
//
//	Add another entry to the high score

	{
	int i, j;

	//	Score of 0 doesn't count

	if (NewEntry.GetScore() == 0)
		return -1;

	//	Modify the epitaph in the entry

	CGameRecord ModifiedEntry = NewEntry;
	if (strEquals(strWord(ModifiedEntry.GetEndGameEpitaph(), 0), CONSTLIT("was")))
		ModifiedEntry.SetEndGameEpitaph(strSubString(ModifiedEntry.GetEndGameEpitaph(), 4, -1));

	//	Find a spot on the list

	for (i = 0; i < m_iCount; i++)
		{
		if (ModifiedEntry.GetScore() > m_List[i].GetScore())
			break;
		}

	//	If we are the end of the list, then we didn't make the
	//	high score list.

	if (i == MAX_SCORES)
		return -1;

	//	Otherwise, move all scores below us by one

	m_bModified = true;

	if (m_iCount < MAX_SCORES)
		m_iCount++;

	for (j = m_iCount-2; j >= i; j--)
		m_List[j+1] = m_List[j];

	m_List[i] = ModifiedEntry;

	//	Player name

	m_sMostRecentPlayerName = ModifiedEntry.GetPlayerName();
	m_iMostRecentPlayerGenome = ModifiedEntry.GetPlayerGenome();

	return i;
	}
예제 #8
0
void CGameSession::OnPlayerDestroyed (SDestroyCtx &Ctx, const CString &sEpitaph)

//  OnPlayerDestroyed
//
//  Player was destroyed

    {
	DEBUG_TRY

	//	Clean up

	g_pTrans->HideCommsTargetMenu();
	g_pTrans->m_CurrentPicker = CTranscendenceWnd::pickNone;
	g_pTrans->m_CurrentMenu = CTranscendenceWnd::menuNone;
	g_pTrans->m_bAutopilot = false;
	m_bShowingSystemMap = false;
	if (g_pTrans->m_State == CTranscendenceWnd::gsDocked)
		m_Model.GetPlayer()->Undock();

	//	Update display

	CString sMsg = sEpitaph;
	if (strEquals(strWord(sMsg, 0), CONSTLIT("was")))
		sMsg = strSubString(sMsg, 4, -1);
	sMsg.Capitalize(CString::capFirstLetter);
	g_pTrans->DisplayMessage(sMsg);
    m_HUD.Invalidate(hudArmor);

	//	If we are insured, then set our state so that we come back to life
	if (Ctx.bResurrectPending)
		{
		//	Prepare resurrect

		g_pTrans->m_State = CTranscendenceWnd::gsDestroyed;
		g_pTrans->m_iCountdown = TICKS_AFTER_DESTROYED;
		}

	//	Otherwise, proceed with destruction

	else
		{
		//	Done with ship screens

		g_pTrans->CleanUpPlayerShip();

		//	Player destroyed

		g_pTrans->m_State = CTranscendenceWnd::gsDestroyed;
		g_pTrans->m_iCountdown = TICKS_AFTER_DESTROYED;
		}

	DEBUG_CATCH
    }
void CCommandLineDisplay::Input (const CString &sInput)

//	Input
//
//	Add characters to input buffer

	{
	if (m_iCursorPos < m_sInput.GetLength())
		{
		CString sCat;
		sCat = strSubString(m_sInput, 0, m_iCursorPos);
		sCat.Append(sInput);
		sCat.Append(strSubString(m_sInput, m_iCursorPos, -1));
		m_sInput = sCat;
		}
	else
		{
		m_sInput.Append(sInput);
		}
	m_iCursorPos += sInput.GetLength();
	m_bInvalid = true;
	}
예제 #10
0
void CTranscendenceWnd::PlayerDestroyed (const CString &sText, bool bResurrectionPending)

//	PlayerDestroyed
//
//	This method gets called when the player is destroyed

	{
	//	Clean up

	HideCommsTargetMenu();
	m_CurrentPicker = pickNone;
	m_CurrentMenu = menuNone;
	m_bAutopilot = false;
	m_bShowingMap = false;
	if (m_State == gsDocked)
		GetPlayer()->Undock();

	//	Update display

	CString sMsg = sText;
	if (strEquals(strWord(sMsg, 0), CONSTLIT("was")))
		sMsg = strSubString(sMsg, 4, -1);
	sMsg.Capitalize(CString::capFirstLetter);
	DisplayMessage(sMsg);
	UpdateArmorDisplay();

	//	If we are insured, then set our state so that we come back to life
	if (bResurrectionPending)
		{
		//	Prepare resurrect

		m_State = gsDestroyed;
		m_iCountdown = TICKS_AFTER_DESTROYED;
		}

	//	Otherwise, proceed with destruction

	else
		{
		//	Done with ship screens

		CleanUpPlayerShip();

		//	Player destroyed

		m_State = gsDestroyed;
		m_iCountdown = TICKS_AFTER_DESTROYED;
		}
	}
예제 #11
0
bool CTopologyNode::HasSpecialAttribute (const CString &sAttrib) const

//	HasSpecialAttribute
//
//	Returns TRUE if we have the special attribute

	{
	if (strStartsWith(sAttrib, SPECIAL_NODE_ID))
		{
		CString sNodeID = strSubString(sAttrib, SPECIAL_NODE_ID.GetLength());
		return strEquals(sNodeID, GetID());
		}
	else
		return false;
	}
예제 #12
0
bool CMission::HasSpecialAttribute (const CString &sAttrib) const

//	HasSpecialAttribute
//
//	Returns TRUE if object has the special attribute
//
//	NOTE: Subclasses may override this, but they must call the
//	base class if they do not handle the attribute.

{
    if (strStartsWith(sAttrib, SPECIAL_OWNER_ID))
    {
        DWORD dwOwnerID = strToInt(strSubString(sAttrib, SPECIAL_OWNER_ID.GetLength()), 0);
        return (dwOwnerID == m_pOwner.GetID());
    }
    else
        return CSpaceObject::HasSpecialAttribute(sAttrib);
}
예제 #13
0
bool CDockPane::HandleKeyDown (int iVirtKey)

//	HandleKeyDown
//
//	Handle key down

	{
	switch (iVirtKey)
		{
		case VK_UP:
		case VK_LEFT:
			{
			int iAction;
			if (m_Actions.FindSpecial(CDockScreenActions::specialPrevKey, &iAction))
				{
				g_pUniverse->PlaySound(NULL, g_pUniverse->FindSound(UNID_DEFAULT_SELECT));
				m_Actions.Execute(iAction, m_pDockScreen);
				return true;
				}
			break;
			}

		case VK_DOWN:
		case VK_RIGHT:
			{
			int iAction;
			if (m_Actions.FindSpecial(CDockScreenActions::specialNextKey, &iAction))
				{
				g_pUniverse->PlaySound(NULL, g_pUniverse->FindSound(UNID_DEFAULT_SELECT));
				m_Actions.Execute(iAction, m_pDockScreen);
				return true;
				}
			break;
			}

		case VK_BACK:
			{
			SControl *pControl;
			if (pControl = GetControlByType(controlTextInput))
				{
				CGTextArea *pTextArea = pControl->AsTextArea();
				CString sText = pTextArea->GetText();
				if (sText.GetLength() > 1)
					{
					sText = strSubString(sText, 0, sText.GetLength() - 1);
					pTextArea->SetText(sText);
					pTextArea->SetCursor(0, sText.GetLength());
					}
				else
					{
					pTextArea->SetText(NULL_STR);
					pTextArea->SetCursor(0, 0);
					}

				return true;
				}
			else if (pControl = GetControlByType(controlCounter))
				{
				CGTextArea *pTextArea = pControl->AsTextArea();
				CString sCounter = pTextArea->GetText();
				if (sCounter.GetLength() > 1)
					{
					pTextArea->SetText(strSubString(sCounter, 0, sCounter.GetLength() - 1));
					pControl->bReplaceInput = false;
					}
				else
					{
					pTextArea->SetText(CONSTLIT("0"));
					pControl->bReplaceInput = true;
					}

				return true;
				}
			break;
			}

		case VK_ESCAPE:
			ExecuteCancelAction();
			return true;

		case VK_RETURN:
			{
			int iAction;
			if (m_Actions.FindSpecial(CDockScreenActions::specialDefault, &iAction))
				{
				g_pUniverse->PlaySound(NULL, g_pUniverse->FindSound(UNID_DEFAULT_SELECT));
				m_Actions.Execute(iAction, m_pDockScreen);

				return true;
				}
			else if (m_Actions.GetCount() == 1)
				{
				g_pUniverse->PlaySound(NULL, g_pUniverse->FindSound(UNID_DEFAULT_SELECT));
				m_Actions.Execute(0, m_pDockScreen);

				return true;
				}
			break;
			}
		}

	return false;
	}
예제 #14
0
파일: Link.cpp 프로젝트: gmoromisato/Dev
ICCItem *CCodeChain::Link (const CString &sString, int iOffset, int *retiLinked, int *ioiCurLine)

//	Link
//
//	Parses the given string and converts it into a linked
//	chain of items

	{
	char *pStart;
	char *pPos;
	ICCItem *pResult = NULL;
	int iCurLine = (ioiCurLine ? *ioiCurLine : 1);

	pStart = sString.GetPointer() + iOffset;
	pPos = pStart;

	//	Skip any whitespace

	pPos = SkipWhiteSpace(pPos, &iCurLine);

	//	If we've reached the end, then we have
	//	nothing

	if (*pPos == '\0')
		pResult = CreateNil();

	//	If we've got a literal quote, then remember it

	else if (*pPos == SYMBOL_QUOTE)
		{
		int iLinked;

		pPos++;

		pResult = Link(sString, iOffset + (pPos - pStart), &iLinked, &iCurLine);
		if (pResult->IsError())
			return pResult;

		pPos += iLinked;

		//	Make it a literal

		pResult->SetQuoted();
		}

	//	If we've got an open paren then we start a list

	else if (*pPos == SYMBOL_OPENPAREN)
		{
		ICCItem *pNew = CreateLinkedList();
		if (pNew->IsError())
			return pNew;

		CCLinkedList *pList = dynamic_cast<CCLinkedList *>(pNew);

		//	Keep reading until we find the end

		pPos++;

		//	If the list is empty, then there's nothing to do

		pPos = SkipWhiteSpace(pPos, &iCurLine);
		if (*pPos == SYMBOL_CLOSEPAREN)
			{
			pList->Discard(this);
			pResult = CreateNil();
			pPos++;
			}

		//	Get all the items in the list

		else
			{
			while (*pPos != SYMBOL_CLOSEPAREN && *pPos != '\0')
				{
				ICCItem *pItem;
				int iLinked;

				pItem = Link(sString, iOffset + (pPos - pStart), &iLinked, &iCurLine);
				if (pItem->IsError())
					return pItem;

				//	Add the item to the list

				pList->Append(this, pItem, NULL);
				pItem->Discard(this);

				//	Move the position

				pPos += iLinked;

				//	Skip whitespace

				pPos = SkipWhiteSpace(pPos, &iCurLine);
				}

			//	If we have a close paren then we're done; Otherwise we've
			//	got an error of some kind

			if (*pPos == SYMBOL_CLOSEPAREN)
				{
				pPos++;
				pResult = pList;
				}
			else
				{
				pList->Discard(this);
				pResult = CreateParseError(iCurLine, CONSTLIT("Mismatched open parenthesis"));
				}
			}
		}

	//	If this is an open brace then we've got a literal structure

	else if (*pPos == SYMBOL_OPENBRACE)
		{
		ICCItem *pNew = CreateSymbolTable();
		if (pNew->IsError())
			return pNew;

		CCSymbolTable *pTable = dynamic_cast<CCSymbolTable *>(pNew);

		//	Always literal

		pTable->SetQuoted();

		//	Keep reading until we find the end

		pPos++;

		//	If the list is empty, then there's nothing to do

		pPos = SkipWhiteSpace(pPos, &iCurLine);
		if (*pPos == SYMBOL_CLOSEBRACE)
			{
			pResult = pTable;
			pPos++;
			}

		//	Get all the items in the list

		else
			{
			while (*pPos != SYMBOL_CLOSEBRACE && *pPos != '\0')
				{
				//	Get the key

				ICCItem *pKey;
				int iLinked;

				pKey = Link(sString, iOffset + (pPos - pStart), &iLinked, &iCurLine);
				if (pKey->IsError())
					{
					pTable->Discard(this);
					return pKey;
					}

				//	Move the position and read a colon

				pPos += iLinked;
				pPos = SkipWhiteSpace(pPos, &iCurLine);
				if (*pPos != SYMBOL_COLON)
					{
					pKey->Discard(this);
					pTable->Discard(this);
					return CreateParseError(iCurLine, CONSTLIT("Struct value not found."));
					}

				pPos++;

				//	Get the value

				ICCItem *pValue;

				pValue = Link(sString, iOffset + (pPos - pStart), &iLinked, &iCurLine);
				if (pValue->IsError())
					{
					pKey->Discard(this);
					pTable->Discard(this);
					return pValue;
					}

				//	Move the position

				pPos += iLinked;

				//	Add the item to the table

				pResult = pTable->AddEntry(this, pKey, pValue);
				pKey->Discard(this);
				pValue->Discard(this);
				if (pResult->IsError())
					{
					pTable->Discard(this);
					return pResult;
					}

				//	Skip whitespace because otherwise we won't know whether we
				//	hit the end brace.

				pPos = SkipWhiteSpace(pPos, &iCurLine);
				}

			//	If we have a close paren then we're done; Otherwise we've
			//	got an error of some kind

			if (*pPos == SYMBOL_CLOSEBRACE)
				{
				pPos++;
				pResult = pTable;
				}
			else
				{
				pTable->Discard(this);
				pResult = CreateParseError(iCurLine, CONSTLIT("Mismatched open brace"));
				}
			}
		}

	//	If this is an open quote, then read everything until
	//	the close quote

	else if (*pPos == SYMBOL_OPENQUOTE)
		{
		//	Parse the string, until the end quote, parsing escape codes

		char *pStartFragment = NULL;
		CString sResultString;

		bool bDone = false;
		while (!bDone)
			{
			pPos++;

			switch (*pPos)
				{
				case SYMBOL_CLOSEQUOTE:
				case '\0':
					{
					if (pStartFragment)
						{
						sResultString.Append(CString(pStartFragment, pPos - pStartFragment));
						pStartFragment = NULL;
						}

					bDone = true;
					break;
					}

				case SYMBOL_BACKSLASH:
					{
					if (pStartFragment)
						{
						sResultString.Append(CString(pStartFragment, pPos - pStartFragment));
						pStartFragment = NULL;
						}

					pPos++;
					if (*pPos == '\0')
						bDone = true;
					else if (*pPos == 'n')
						sResultString.Append(CString("\n", 1));
					else if (*pPos == 'r')
						sResultString.Append(CString("\r", 1));
					else if (*pPos == 't')
						sResultString.Append(CString("\t", 1));
					else if (*pPos == '0')
						sResultString.Append(CString("\0", 1));
					else if (*pPos == 'x' || *pPos == 'X')
						{
						pPos++;
						int iFirstDigit = strGetHexDigit(pPos);
						pPos++;
						int iSecondDigit = 0;
						if (*pPos == '\0')
							bDone = true;
						else
							iSecondDigit = strGetHexDigit(pPos);

						char chChar = (char)(16 * iFirstDigit + iSecondDigit);
						sResultString.Append(CString(&chChar, 1));
						}
					else
						sResultString.Append(CString(pPos, 1));

					break;
					}

				default:
					{
					if (pStartFragment == NULL)
						pStartFragment = pPos;

					break;
					}
				}
			}

		//	If we found the close, then create a string; otherwise,
		//	it is an error

		if (*pPos == SYMBOL_CLOSEQUOTE)
			{
			pResult = CreateString(sResultString);

			//	Always a literal

			pResult->SetQuoted();

			//	Skip past quote

			pPos++;
			}
		else
			pResult = CreateParseError(iCurLine, CONSTLIT("Mismatched quote"));
		}

	//	If this is a close paren, then it is an error

	else if (*pPos == SYMBOL_CLOSEPAREN)
		pResult = CreateParseError(iCurLine, CONSTLIT("Mismatched close parenthesis"));

	//	If this is a close brace, then it is an error

	else if (*pPos == SYMBOL_CLOSEBRACE)
		pResult = CreateParseError(iCurLine, CONSTLIT("Mismatched close brace"));

	//	Colons cannot appear alone

	else if (*pPos == SYMBOL_COLON)
		pResult = CreateParseError(iCurLine, CONSTLIT("':' character must appear inside quotes or in a struct definition."));

	//	Otherwise this is an string of some sort

	else
		{
		char *pStartString;
		CString sIdentifier;
		int iInt;
		bool bNotInteger;

		pStartString = pPos;

		//	Look for whitespace

    	while (*pPos != '\0'
        		&& *pPos != ' ' && *pPos != '\n' && *pPos != '\r' && *pPos != '\t'
            	&& *pPos != SYMBOL_OPENPAREN
				&& *pPos != SYMBOL_CLOSEPAREN
				&& *pPos != SYMBOL_OPENQUOTE
				&& *pPos != SYMBOL_CLOSEQUOTE
				&& *pPos != SYMBOL_OPENBRACE
				&& *pPos != SYMBOL_CLOSEBRACE
				&& *pPos != SYMBOL_COLON
				&& *pPos != SYMBOL_QUOTE
				&& *pPos != ';')
        	pPos++;

		//	If we did not advance, then we clearly hit an error

		if (pStartString == pPos)
			pResult = CreateParseError(iCurLine, strPatternSubst(CONSTLIT("Unexpected character: %s"), CString(pPos, 1)));

		//	If we ended in a quote then that's a bug

		else if (*pPos == SYMBOL_QUOTE)
			pResult = CreateParseError(iCurLine, strPatternSubst(CONSTLIT("Identifiers must not use single quote characters: %s"), 
					strSubString(sString, iOffset + (pStartString - pStart), (pPos + 1 - pStartString))));

		//	Otherwise, get the identifier

		else
			{
			//	Create a string from the portion

			sIdentifier = strSubString(sString, iOffset + (pStartString - pStart), (pPos - pStartString));

			//	Check to see if this is a reserved identifier

			if (strCompareAbsolute(sIdentifier, CONSTLIT("Nil")) == 0)
				pResult = CreateNil();
			else if (strCompareAbsolute(sIdentifier, CONSTLIT("True")) == 0)
				pResult = CreateTrue();
			else
				{
				//	If this is an integer, create an integer; otherwise
				//	create a string

				iInt = strToInt(sIdentifier, 0, &bNotInteger);
				if (bNotInteger)
					pResult = CreateString(sIdentifier);
				else
					pResult = CreateInteger(iInt);
				}
			}
		}

	//	Return the result and the number of characters
	//	that we read

	if (retiLinked)
		*retiLinked = (pPos - pStart);

	if (ioiCurLine)
		*ioiCurLine = iCurLine;

	return pResult;
	}
예제 #15
0
void CCommandLineDisplay::AutoCompleteSearch (void)

//	AutocompleteSearch
//
//	Searches the global symbol table for matches to the current command.

	{
	const CString sCurCmd = GetCurrentCmd();
	CString sCommon;
	CString sHelp;

	ClearHint();
	if (sCurCmd.IsBlank())
		return;

	//	Get the list of global symbols

	ICCItem *pGlobals = g_pUniverse->GetCC().GetGlobals();

	int iMatches = 0;

	for (int i = 0; i < pGlobals->GetCount(); i++)
		{
		CString sGlobal = pGlobals->GetKey(i);

		//	Partial match
		if (strStartsWith(sGlobal, sCurCmd))
			{
			if (iMatches == 0)
				sCommon = sGlobal;
			//	If we have multiple matching commands then find the longest common stem
			else
				{
				int iLen = min(sCommon.GetLength(), sGlobal.GetLength());
				char *pPos1 = sCommon.GetPointer();
				char *pPos2 = sGlobal.GetPointer();
				int i;
				for (i = 0; i < iLen; i++)
					{
					if (CharLower((LPTSTR)(BYTE)(*pPos1)) != CharLower((LPTSTR)(BYTE)(*pPos2)))
						break;
					pPos1++;
					pPos2++;
					}
				sCommon.Truncate(i);
				m_sHint.Append(CONSTLIT(" "));
				}
			//	Append the command to the auto complete hint
			m_sHint.Append(sGlobal);
			iMatches++;
			}

		if (strEquals(sGlobal, sCurCmd))
			{
			//	Exact match - get help text
			ICCItem *pItem = pGlobals->GetElement(i);
			if (pItem->IsPrimitive())
				sHelp = pItem->GetHelp();
			}
		}

	//	If the common stem is longer than the current command, then auto complete
	if (sCommon.GetLength() > sCurCmd.GetLength())
		Input(strSubString(sCommon, sCurCmd.GetLength(), -1));

	//	If we only have one match then no need to show hint as we have either
	//	auto completed or will show help text insead
	if (iMatches == 1)
		m_sHint = NULL_STR;

	if (!sHelp.IsBlank())
		{
		if (!m_sHint.IsBlank())
			m_sHint.Append(CONSTLIT("\n"));
		m_sHint.Append(sHelp);
		}
	}
예제 #16
0
void GenerateTypeTable (CUniverse &Universe, CXMLElement *pCmdLine)
	{
	int i, j;

	//	Get the criteria from the command line.

	CString sCriteria = pCmdLine->GetAttribute(CRITERIA_ATTRIB);

	//	Parse it

	CDesignTypeCriteria Criteria;
	if (CDesignTypeCriteria::ParseCriteria(sCriteria, &Criteria) != NOERROR)
		{
		printf("ERROR: Unable to parse criteria.\n");
		return;
		}

	//	Generate a table of all matching types

	TSortMap<CString, CDesignType *> Table;

	//	Loop over all items for this level and add them to
	//	a sorted table.

	for (i = 0; i < Universe.GetDesignTypeCount(); i++)
		{
		CDesignType *pType = Universe.GetDesignType(i);
		int iLevel = pType->GetLevel();

		if (!pType->MatchesCriteria(Criteria))
			continue;

		//	Get the name

		CString sName = pType->GetDataField(FIELD_NAME);
		if (*sName.GetASCIIZPointer() == '(')
			sName = strSubString(sName, 1, -1);

		//	Figure out the sort order

		char szBuffer[1024];
		wsprintf(szBuffer, "%02d%s%08x", 
				iLevel,
				sName.GetASCIIZPointer(),
				pType->GetUNID());
		Table.Insert(CString(szBuffer), pType);
		}

	//	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 (!IsMainCommandParam(sAttrib)
				&& !strEquals(sAttrib, CONSTLIT("typetable")))
			{
			CString sValue = pCmdLine->GetAttribute(i);
			
			if (!strEquals(sValue, CONSTLIT("true")))
				Cols.Insert(strPatternSubst(CONSTLIT("%s:%s"), sAttrib, sValue));
			else
				Cols.Insert(sAttrib);
			}
		}

	//	If we need to output total count, then load the table

	CDesignTypeStats TotalCount;
	if (pCmdLine->GetAttributeBool(FIELD_TOTAL_COUNT)
			|| pCmdLine->GetAttributeBool(FIELD_COUNT_DISTRIBUTION))
		{
		if (LoadDesignTypeStats(Universe.GetDesignCollection().GetAdventureUNID(), &TotalCount) != NOERROR)
			{
			printf("ERROR: Unable to load type count table.\n");
			return;
			}
		}

	//	If we've got any entries in the table, output now

	if (Table.GetCount())
		{
		//	Output the header

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

			printf(Cols[j].GetASCIIZPointer());
			}

		printf("\n");

		//	Output each row

		CCodeChainCtx CCCtx;
		for (i = 0; i < Table.GetCount(); i++)
			{
			CDesignType *pType = Table[i];

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

				const CString &sField = Cols[j];

				//	Format and output

				if (strEquals(sField, FIELD_TOTAL_COUNT))
					{
					SDesignTypeInfo *pInfo = TotalCount.GetAt(pType->GetUNID());
					double rCount = (pInfo ? pInfo->rPerGameMeanCount : 0.0);
					printf("%.2f", rCount);
					}
				else if (strEquals(sField, FIELD_COUNT_DISTRIBUTION))
					{
					SDesignTypeInfo *pInfo = TotalCount.GetAt(pType->GetUNID());
					printf("%s", (pInfo ? pInfo->sDistribution : NULL_STR).GetASCIIZPointer());
					}
				else
					{
					ICCItem *pResult = pType->GetProperty(CCCtx, sField);
					CString sValue = pResult->Print(&g_pUniverse->GetCC(), PRFLAG_NO_QUOTES | PRFLAG_ENCODE_FOR_DISPLAY);
					pResult->Discard(&g_pUniverse->GetCC());

					printf(sValue.GetASCIIZPointer());
					}
				}

			printf("\n");
			}

		printf("\n");
		}
	else
		printf("No entries match criteria.\n");
	}
예제 #17
0
void GenerateEncounterTable (CUniverse &Universe, CXMLElement *pCmdLine)
	{
	ALERROR error;
	int i, j;

	//	Get the criteria from the command line. Always append 't' because we
	//	want station types.

	CString sCriteria = strPatternSubst(CONSTLIT("%s t"), pCmdLine->GetAttribute(CRITERIA_ATTRIB));

	//	Parse it

	CDesignTypeCriteria Criteria;
	if (CDesignTypeCriteria::ParseCriteria(sCriteria, &Criteria) != NOERROR)
		{
		printf("ERROR: Unable to parse criteria.\n");
		return;
		}

	bool bAll = pCmdLine->GetAttributeBool(ALL_ATTRIB);

	//	Generate a table of all matching encounters

	CSymbolTable Table(FALSE, TRUE);

	//	Loop over all items for this level and add them to
	//	a sorted table.

	for (i = 0; i < Universe.GetStationTypeCount(); i++)
		{
		CStationType *pType = Universe.GetStationType(i);
		int iLevel = pType->GetLevel();
		if (iLevel == 0 && !bAll)
			continue;

		//	If we don't match the criteria, then continue

		if (!pType->MatchesCriteria(Criteria))
			continue;

		//	Get the category and name

		CString sCategory = pType->GetDataField(FIELD_CATEGORY);
		CString sName = pType->GetDataField(FIELD_NAME);
		if (*sName.GetASCIIZPointer() == '(')
			sName = strSubString(sName, 1, -1);

		//	Figure out the sort order

		char szBuffer[1024];
		wsprintf(szBuffer, "%02d%s%s", 
				pType->GetLevel(),
				sCategory.GetASCIIZPointer(), 
				sName.GetASCIIZPointer());
		Table.AddEntry(CString(szBuffer), (CObject *)pType);
		}

	//	Generate a list of columns to display

	TArray<CString> Cols;
	Cols.Insert(FIELD_LEVEL);
	Cols.Insert(FIELD_CATEGORY);
	Cols.Insert(FIELD_NAME);

	for (i = 0; i < pCmdLine->GetAttributeCount(); i++)
		{
		CString sAttrib = pCmdLine->GetAttributeName(i);

		if (!strEquals(sAttrib, CONSTLIT("all"))
				&& !strEquals(sAttrib, CONSTLIT("criteria"))
				&& !strEquals(sAttrib, CONSTLIT("encountertable"))
				&& !strEquals(sAttrib, CONSTLIT("nologo")))
			{
			CString sValue = pCmdLine->GetAttribute(i);
			
			if (!strEquals(sValue, CONSTLIT("true")))
				Cols.Insert(strPatternSubst(CONSTLIT("%s:%s"), sAttrib, sValue));
			else
				Cols.Insert(sAttrib);
			}
		}

#if 0
	if (pCmdLine->GetAttributeBool(FIELD_ARMOR_CLASS))
		Cols.Insert(FIELD_ARMOR_CLASS);
	if (pCmdLine->GetAttributeBool(FIELD_HP))
		Cols.Insert(FIELD_HP);
	if (pCmdLine->GetAttributeBool(FIELD_FIRE_RATE_ADJ))
		Cols.Insert(FIELD_FIRE_RATE_ADJ);
	if (pCmdLine->GetAttributeBool(FIELD_TOTAL_COUNT))
		Cols.Insert(FIELD_TOTAL_COUNT);
	if (pCmdLine->GetAttributeBool(FIELD_CAN_ATTACK))
		Cols.Insert(FIELD_CAN_ATTACK);
	if (pCmdLine->GetAttributeBool(FIELD_EXPLOSION_TYPE))
		Cols.Insert(FIELD_EXPLOSION_TYPE);
#endif

	//	If we need to output total count, then load the table

	CSymbolTable TotalCount(TRUE, TRUE);
	if (pCmdLine->GetAttributeBool(FIELD_TOTAL_COUNT))
		{
		if (error = LoadTotalCount(TOTAL_COUNT_FILENAME, TotalCount))
			return;
		}

	//	If we've got any entries in the table, output now

	if (Table.GetCount())
		{
		//	Output the header

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

			printf(Cols[j].GetASCIIZPointer());
			}

		printf("\n");

		//	Output each row

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

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

				const CString &sField = Cols[j];
				CString sValue = pType->GetDataField(sField);

				if (strEquals(sField, FIELD_FIRE_RATE_ADJ))
					printf("%.2f", strToInt(sValue, 0, NULL) / 1000.0);
				else if (strEquals(sField, FIELD_TOTAL_COUNT))
					{
					double rCount = 0.0;

					CString sKey = strFromInt(pType->GetUNID(), false);
					EntryInfo *pEntry;
					if (TotalCount.Lookup(sKey, (CObject **)&pEntry) == NOERROR)
						rCount = pEntry->rTotalCount;

					printf("%.2f", rCount);
					}
				else
					printf(sValue.GetASCIIZPointer());
				}

			printf("\n");
			}

		printf("\n");
		}
	else
		printf("No entries match criteria.\n");
	}
예제 #18
0
void GenerateEncounterTable (CUniverse &Universe, CXMLElement *pCmdLine, CIDTable &EntityTable)
	{
	ALERROR error;
	int i, j;

	//	Get the criteria from the command line. Always append 't' because we
	//	want station types.

	CString sCriteria = strPatternSubst(CONSTLIT("%s t"), pCmdLine->GetAttribute(CRITERIA_ATTRIB));

	//	Parse it

	CDesignTypeCriteria Criteria;
	if (CDesignTypeCriteria::ParseCriteria(sCriteria, &Criteria) != NOERROR)
		{
		printf("ERROR: Unable to parse criteria.\n");
		return;
		}

	bool bAll = pCmdLine->GetAttributeBool(ALL_ATTRIB);
	bool bOnlyNotRandom = pCmdLine->GetAttributeBool(ONLY_NOT_RANDOM_ATTRIB);

	//	Generate a table of all matching encounters

	CSymbolTable Table(FALSE, TRUE);

	//	Loop over all items for this level and add them to
	//	a sorted table.

	for (i = 0; i < Universe.GetStationTypeCount(); i++)
		{
		CStationType *pType = Universe.GetStationType(i);
		int iLevel = pType->GetLevel();

		//	If we're selecting all types, then do it

		if (bAll)
			;

		//	If we only want non-random types, then skip any random encounters.

		else if (bOnlyNotRandom)
			{
			if (pType->CanBeEncounteredRandomly())
				continue;
			}

		//	Otherwise we skip anything except random encounters.

		else
			{
			if (!pType->CanBeEncounteredRandomly())
				continue;
			}

		//	If we don't match the criteria, then continue

		if (!pType->MatchesCriteria(Criteria))
			continue;

		//	Get the category and name

		CString sCategory = pType->GetDataField(FIELD_CATEGORY);
		CString sName = pType->GetDataField(FIELD_NAME);
		if (*sName.GetASCIIZPointer() == '(')
			sName = strSubString(sName, 1, -1);

		//	Figure out the sort order

		char szBuffer[1024];
		wsprintf(szBuffer, "%02d%s%s%08x", 
				iLevel,
				sCategory.GetASCIIZPointer(), 
				sName.GetASCIIZPointer(),
				pType->GetUNID());
		Table.AddEntry(CString(szBuffer), (CObject *)pType);
		}

	//	Generate a list of columns to display

	TArray<CString> Cols;
	Cols.Insert(FIELD_LEVEL);
	Cols.Insert(FIELD_CATEGORY);
	Cols.Insert(FIELD_NAME);

	for (i = 0; i < pCmdLine->GetAttributeCount(); i++)
		{
		CString sAttrib = pCmdLine->GetAttributeName(i);

		if (!IsMainCommandParam(sAttrib)
				&& !strEquals(sAttrib, ONLY_NOT_RANDOM_ATTRIB)
				&& !strEquals(sAttrib, CONSTLIT("encountertable")))
			{
			CString sValue = pCmdLine->GetAttribute(i);
			
			if (!strEquals(sValue, CONSTLIT("true")))
				Cols.Insert(strPatternSubst(CONSTLIT("%s:%s"), sAttrib, sValue));
			else
				Cols.Insert(sAttrib);
			}
		}

	//	If we need to output total count, then load the table

	CDesignTypeStats TotalCount;
	if (pCmdLine->GetAttributeBool(FIELD_TOTAL_COUNT)
			|| pCmdLine->GetAttributeBool(FIELD_COUNT_DISTRIBUTION))
		{
		if (error = LoadDesignTypeStats(&TotalCount))
			return;
		}

	//	If we've got any entries in the table, output now

	if (Table.GetCount())
		{
		//	Output the header

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

			printf(Cols[j].GetASCIIZPointer());
			}

		printf("\n");

		//	Output each row

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

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

				const CString &sField = Cols[j];

				//	Get the value

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

				//	Format and output

				if (strEquals(sField, FIELD_FIRE_RATE_ADJ))
					printf("%.2f", strToInt(sValue, 0, NULL) / 1000.0);
				else if (strEquals(sField, FIELD_TOTAL_COUNT))
					{
					SDesignTypeInfo *pInfo = TotalCount.GetAt(pType->GetUNID());
					double rCount = (pInfo ? pInfo->rPerGameMeanCount : 0.0);
					printf("%.2f", rCount);
					}
				else if (strEquals(sField, FIELD_COUNT_DISTRIBUTION))
					{
					SDesignTypeInfo *pInfo = TotalCount.GetAt(pType->GetUNID());
					printf("%s", (pInfo ? pInfo->sDistribution : NULL_STR).GetASCIIZPointer());
					}
				else
					printf(sValue.GetASCIIZPointer());
				}

			printf("\n");
			}

		printf("\n");
		}
	else
		printf("No entries match criteria.\n");
	}
예제 #19
0
void GenerateEncounterTable (CUniverse &Universe, CXMLElement *pCmdLine)
	{
	ALERROR error;
	int i, j;

	//	Get the criteria from the command line

	SEncounterCriteria Criteria;
	ParseEncounterCriteria(pCmdLine->GetAttribute(CRITERIA_ATTRIB), &Criteria);
	bool bAll = pCmdLine->GetAttributeBool(ALL_ATTRIB);

	//	Generate a table of all matching encounters

	CSymbolTable Table(FALSE, TRUE);

	//	Loop over all items for this level and add them to
	//	a sorted table.

	for (i = 0; i < Universe.GetStationTypeCount(); i++)
		{
		CStationType *pType = Universe.GetStationType(i);
		int iLevel = pType->GetLevel();
		if (iLevel == 0 && !bAll)
			continue;

		//	If we don't match the criteria, then continue

		if (!MatchesEncounterCriteria(Criteria, pType->GetAttributes()))
			continue;

		//	Get the category and name

		CString sCategory = pType->GetDataField(FIELD_CATEGORY);
		CString sName = pType->GetDataField(FIELD_NAME);
		if (*sName.GetASCIIZPointer() == '(')
			sName = strSubString(sName, 1, -1);

		//	Figure out the sort order

		char szBuffer[1024];
		wsprintf(szBuffer, "%02d%s%s", 
				pType->GetLevel(),
				sCategory.GetASCIIZPointer(), 
				sName.GetASCIIZPointer());
		Table.AddEntry(CString(szBuffer), (CObject *)pType);
		}

	//	Generate a list of columns to display

	CStringArray Cols;
	Cols.AppendString(FIELD_LEVEL);
	Cols.AppendString(FIELD_CATEGORY);
	Cols.AppendString(FIELD_NAME);
	if (pCmdLine->GetAttributeBool(FIELD_ARMOR_CLASS))
		Cols.AppendString(FIELD_ARMOR_CLASS);
	if (pCmdLine->GetAttributeBool(FIELD_HP))
		Cols.AppendString(FIELD_HP);
	if (pCmdLine->GetAttributeBool(FIELD_FIRE_RATE_ADJ))
		Cols.AppendString(FIELD_FIRE_RATE_ADJ);
	if (pCmdLine->GetAttributeBool(FIELD_TOTAL_COUNT))
		Cols.AppendString(FIELD_TOTAL_COUNT);
	if (pCmdLine->GetAttributeBool(FIELD_CAN_ATTACK))
		Cols.AppendString(FIELD_CAN_ATTACK);
	if (pCmdLine->GetAttributeBool(FIELD_EXPLOSION_TYPE))
		Cols.AppendString(FIELD_EXPLOSION_TYPE);

	//	If we need to output total count, then load the table

	CSymbolTable TotalCount(TRUE, TRUE);
	if (pCmdLine->GetAttributeBool(FIELD_TOTAL_COUNT))
		{
		if (error = LoadTotalCount(TOTAL_COUNT_FILENAME, TotalCount))
			return;
		}

	//	If we've got any entries in the table, output now

	if (Table.GetCount())
		{
		//	Output the header

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

			printf(Cols.GetStringValue(j).GetASCIIZPointer());
			}

		printf("\n");

		//	Output each row

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

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

				CString sField = Cols.GetStringValue(j);
				CString sValue = pType->GetDataField(sField);

				if (strEquals(sField, FIELD_FIRE_RATE_ADJ))
					printf("%.2f", strToInt(sValue, 0, NULL) / 1000.0);
				else if (strEquals(sField, FIELD_TOTAL_COUNT))
					{
					double rCount = 0.0;

					CString sKey = strFromInt(pType->GetUNID(), FALSE);
					EntryInfo *pEntry;
					if (TotalCount.Lookup(sKey, (CObject **)&pEntry) == NOERROR)
						rCount = pEntry->rTotalCount;

					printf("%.2f", rCount);
					}
				else
					printf(sValue.GetASCIIZPointer());
				}

			printf("\n");
			}

		printf("\n");
		}
	else
		printf("No entries match criteria.\n");
	}
예제 #20
0
bool CPlayerDisplay::OnChar (char chChar)

//	OnChar
//
//	Handle character

	{
	if (!m_bEditing)
		return false;

	switch (chChar)
		{
		case SDLK_BACKSPACE:
			{
			if (m_bClearAll)
				m_sEditBuffer = CString();
			else
				{
				if (!m_sEditBuffer.IsBlank())
					m_sEditBuffer = strSubString(m_sEditBuffer, 0, m_sEditBuffer.GetLength() - 1);
				}

			m_bInvalid = true;
			m_bClearAll = false;
			break;
			}

		case SDLK_RETURN:
			{
			m_sEditBuffer = strTrimWhitespace(m_sEditBuffer);
			if (!m_sEditBuffer.IsBlank())
				{
				m_sName = m_sEditBuffer;
				m_pTrans->SetPlayerName(m_sName);
				}

			m_bEditing = false;
			m_bInvalid = true;
			break;
			}

		case SDLK_ESCAPE:
			{
			m_bEditing = false;
			m_bInvalid = true;
			break;
			}

		//	Characters

		default:
			{
			if (!isprint(chChar))
				break;

			if (m_bClearAll)
				m_sEditBuffer = CString(&chChar, 1);
			else
				m_sEditBuffer.Append(CString(&chChar, 1));

			m_bInvalid = true;
			m_bClearAll = false;
			}
		}

	return true;
	}