Exemplo n.º 1
0
bool OutputImage (CG16bitImage &Image, const CString &sFilespec)
	{
	if (!sFilespec.IsBlank())
		{
		if (Image.SaveAsWindowsBMP(sFilespec) != NOERROR)
			{
			printf("Unable to save to '%s'\n", sFilespec.GetASCIIZPointer());
			return false;
			}

		printf("%s\n", sFilespec.GetASCIIZPointer());
		}

	//	Otherwise, clipboard

	else
		{
		if (Image.CopyToClipboard() != NOERROR)
			{
			printf("Unable to copy to clipboard.\n");
			return false;
			}

		printf("Image copied to clipboard.\n");
		}

	//	Done

	return true;
	}
Exemplo n.º 2
0
ICCItem *fnSubst (CEvalContext *pCtx, ICCItem *pArguments, DWORD dwData)

//	fnSubst
//
//	Substitutes string parameters
//
//	(subst string arg1 arg2 ... argn)

	{
	CCodeChain *pCC = pCtx->pCC;
	ICCItem *pArgs;

	//	Evaluate the arguments and validate them

	pArgs = pCC->EvaluateArgs(pCtx, pArguments, CONSTLIT("s*"));
	if (pArgs->IsError())
		return pArgs;

	CString sPattern = pArgs->GetElement(0)->GetStringValue();

	//	Do the substitution

	char szResult[4096];
	char *pPos = sPattern.GetASCIIZPointer();
	char *pDest = szResult;
	char *pEndDest = szResult + sizeof(szResult) - 1;

	while (*pPos != '\0' && pDest < pEndDest)
		{
		if (*pPos == '%')
			{
			pPos++;

			int iArg = strParseInt(pPos, 0, &pPos, NULL);
			if (iArg > 0)
				{
				CString sParam = pArgs->GetElement(iArg)->GetStringValue();
				char *pParam = sParam.GetASCIIZPointer();

				while (*pParam != '\0' && pDest < pEndDest)
					*pDest++ = *pParam++;

				pPos++;
				}
			else
				{
				if (*pPos == '%')
					*pDest++ = *pPos++;
				}
			}
		else
			*pDest++ = *pPos++;
		}

	//	Done

	*pDest = '\0';
	pArgs->Discard(pCC);
	return pCC->CreateString(CString(szResult));
	}
Exemplo n.º 3
0
ALERROR WriteResource (const CString &sFilename, const CString &sFolder, CSymbolTable &Resources, CDataFile &Out)
	{
	ALERROR error;
	CString sFilespec = pathAddComponent(sFolder, sFilename);

	CFileReadBlock theFile(sFilespec);
	if (error = theFile.Open())
		{
		printf("Unable to open '%s'\n", sFilespec.GetASCIIZPointer());
		return error;
		}

	CString sData(theFile.GetPointer(0, -1), theFile.GetLength(), TRUE);
	int iEntry;
	if (error = Out.AddEntry(sData, &iEntry))
		{
		printf("Unable to store '%s'\n", sFilespec.GetASCIIZPointer());
		return error;
		}

	Resources.AddEntry(sFilespec, (CObject *)iEntry);
	printf("   %s\n", sFilespec.GetASCIIZPointer());

	return NOERROR;
	}
Exemplo n.º 4
0
bool arcDecompressFile (const CString &sArchive, const CString &sFilename, IWriteStream &Output, CString *retsError)

//	arcDecompressFile
//
//	Unzips to a stream.

	{
	unzFile theZipFile = unzOpen(sArchive.GetASCIIZPointer());
	if (theZipFile == NULL)
		{
		*retsError = strPatternSubst(CONSTLIT("Unable to open file: %s."), sArchive);
		return false;
		}

	if (unzLocateFile(theZipFile, sFilename.GetASCIIZPointer(), 0) != UNZ_OK)
		{
		unzClose(theZipFile);
		*retsError = strPatternSubst(CONSTLIT("Unable to find file in archive: %s."), sFilename);
		return false;
		}

	if (unzOpenCurrentFile(theZipFile) != UNZ_OK)
		{
		unzClose(theZipFile);
		*retsError = strPatternSubst(CONSTLIT("Unable to open file in archive: %s."), sFilename);
		return false;
		}

	while (true)
		{
		char szBuffer[BUFFER_SIZE];

		int iRead = unzReadCurrentFile(theZipFile, szBuffer, BUFFER_SIZE);
		if (iRead == 0)
			break;
		else if (iRead < 0)
			{
			unzCloseCurrentFile(theZipFile);
			unzClose(theZipFile);
			*retsError = CONSTLIT("Error reading archive.");
			return false;
			}

		Output.Write(szBuffer, iRead);
		}

	//	Returns UNZ_CRCERROR if the file failed its CRC check.

	if (unzCloseCurrentFile(theZipFile) != UNZ_OK)
		{
		unzClose(theZipFile);
		*retsError = strPatternSubst(CONSTLIT("File in archive corrupted: %s."), sArchive);
		return false;
		}

	unzClose(theZipFile);

	return true;
	}
Exemplo n.º 5
0
CJSONValue::CJSONValue (const CString &sValue, bool bToUTF8)

//	CJSONValue constructor

	{
	m_iType = typeString;

	if (bToUTF8)
		{
		//	See if there are any characters that we need to encode.

		char *pPos = sValue.GetASCIIZPointer();
		char *pPosEnd = pPos + sValue.GetLength();
		while (pPos < pPosEnd && (BYTE)*pPos < 0x80)
			pPos++;

		//	If we don't have to encode anything, just copy

		if (pPos == pPosEnd)
			m_pValue = CString::INTGetStorage(sValue);
		else
			{
			//	Otherwise, we encode

			CMemoryWriteStream Output;
			if (Output.Create() != NOERROR)
				m_pValue = CString::INTGetStorage(CONSTLIT("Out of memory"));
			else
				{
				pPos = sValue.GetASCIIZPointer();
				pPosEnd = pPos + sValue.GetLength();
				while (pPos < pPosEnd)
					{
					if ((BYTE)*pPos < 0x80)
						Output.Write(pPos, 1);
					else
						{
						CString sUTF8 = strEncodeW1252ToUTF8Char(*pPos);
						Output.Write(sUTF8.GetASCIIZPointer(), sUTF8.GetLength());
						}

					pPos++;
					}

				m_pValue = CString::INTGetStorage(CString(Output.GetPointer(), Output.GetLength()));
				}
			}
		}
	else
		m_pValue = CString::INTGetStorage(sValue);
	}
Exemplo n.º 6
0
	inline void Print (const CString &sStat, int iCount, int iTotal)
		{
		int iAverage = m_iTotal / iCount;
		int iPercent = (int)((100.0 * (float)iAverage / (float)iTotal) + 0.5f);

		if (m_iMin == m_iMax)
			printf("%s:\t%d\t%d%%\n", sStat.GetASCIIZPointer(), m_iMin, iPercent);
		else
			printf("%s:\t%d-%d (%d)\t%d%%\n",
					sStat.GetASCIIZPointer(),
					m_iMin, 
					m_iMax, 
					iAverage,
					iPercent);
		}
Exemplo n.º 7
0
DWORD CHTMLForm::GetEncodedTextLength (const CString &sText) const

//	GetEncodedTextLength
//
//	Returns the length that the given text would be encoded (in bytes)

	{
	char *pPos = sText.GetASCIIZPointer();
	char *pEndPos = pPos + sText.GetLength();

	DWORD dwCount = 0;
	while (pPos < pEndPos)
		{
		if ((*pPos >= 'A' && *pPos <= 'Z')
				|| (*pPos >= 'a' && *pPos <= 'z')
				|| (*pPos >= '0' && *pPos <= '9')
				|| *pPos == ' ')
			dwCount++;
		else
			dwCount += 3;

		pPos++;
		}

	return dwCount;
	}
Exemplo n.º 8
0
void CDesignCollection::FireOnGlobalPaneInit (void *pScreen, CDesignType *pRoot, const CString &sScreen, const CString &sPane)

//	FireOnGlobalPaneInit
//
//	Give other design types a way to override screens

	{
	int i;
	CString sError;

	//	Generate a screen UNID that contains both the screen UNID and a local screen

	CString sScreenUNID = CDockScreenType::GetStringUNID(pRoot, sScreen);
	DWORD dwRootUNID = (pRoot ? pRoot->GetUNID() : 0);

	//	Fire all events

	for (i = 0; i < m_EventsCache[evtOnGlobalDockPaneInit]->GetCount(); i++)
		{
		SEventHandlerDesc Event;
		CDesignType *pType = m_EventsCache[evtOnGlobalDockPaneInit]->GetEntry(i, &Event);

		if (pType->FireOnGlobalDockPaneInit(Event,
				pScreen,
				dwRootUNID,
				sScreenUNID,
				sPane,
				&sError) != NOERROR)
			kernelDebugLogMessage("%s", sError.GetASCIIZPointer());
		}
	}
Exemplo n.º 9
0
void CHumanInterface::HardCrash (const CString &sProgramState)

//	HardCrash
//
//	Report an error

	{
	CString sSessionMessage;
	try
		{
		if (m_pCurSession)
			m_pCurSession->HIReportHardCrash(&sSessionMessage);
		}
	catch (...)
		{
		sSessionMessage = CONSTLIT("Unable to obtain crash report from session.");
		}

	CString sMessage = strPatternSubst(CONSTLIT(
			"Unable to continue due to program error.\r\n\r\n"
			"program state: %s\r\n"
			"%s"
			"\r\n\r\nPlease contact [email protected] with a copy of Debug.log and your save file. "
			"We are sorry for the inconvenience.\r\n"),
			sProgramState,
			sSessionMessage
			);

	kernelDebugLogMessage(sMessage.GetASCIIZPointer());
	ShowHardCrashSession(CONSTLIT("Transcendence System Crash"), sMessage);
	}
Exemplo n.º 10
0
void ParseEncounterCriteria (const CString &sCriteria, SEncounterCriteria *retCriteria)
	{
	retCriteria->MustHave.RemoveAll();
	retCriteria->MustNotHave.RemoveAll();

	char *pPos = sCriteria.GetASCIIZPointer();
	while (*pPos != '\0')
		{
		if (*pPos == '+' || *pPos == '-')
			{
			char chOp = *pPos;
			pPos++;

			char *pStart = pPos;
			while (*pPos != '\0' && *pPos != ';')
				pPos++;

			CString sAttrib(pStart, pPos - pStart);
			if (!sAttrib.IsBlank())
				{
				if (chOp == '+')
					retCriteria->MustHave.AppendString(sAttrib);
				else
					retCriteria->MustNotHave.AppendString(sAttrib);
				}
			}
		else
			pPos++;
		}
	}
Exemplo n.º 11
0
ALERROR CSoundMgr::LoadWaveFile (const CString &sFilename, int *retiChannel)

//	LoadWaveFile
//
//	Creates a sound buffer from a WAV file

	{
	ALERROR error;
	HMMIO hFile;

	if (m_pDS == NULL)
		{
		*retiChannel = 0;
		return NOERROR;
		}

	hFile = mmioOpen(sFilename.GetASCIIZPointer(), NULL, MMIO_READ | MMIO_ALLOCBUF);
	if (hFile == NULL)
		return ERR_FAIL;

	if (error = LoadWaveFile(hFile, retiChannel))
		return error;

	SChannel *pChannel = GetChannel(*retiChannel);
	pChannel->sFilename = sFilename;
	return NOERROR;
	}
Exemplo n.º 12
0
CString CreateDataFieldFromItemList (const TArray<CItem> &List)

//	CreateDataFieldFromItemList
//
//	Creates a data field string from a list of items

	{
	int i;
	CCodeChain &CC = g_pUniverse->GetCC();

	CMemoryWriteStream Output(10000);
	if (Output.Create() != NOERROR)
		return NULL_STR;

	Output.Write("='(", 3);
	for (i = 0; i < List.GetCount(); i++)
		{
		ICCItem *pItem = List[i].WriteToCCItem(CC);
		if (pItem->IsError())
			{
			pItem->Discard(&CC);
			return NULL_STR;
			}

		CString sItem = pItem->Print(&CC);
		Output.Write(sItem.GetASCIIZPointer(), sItem.GetLength());
		Output.Write(" ", 1);

		pItem->Discard(&CC);
		}
	Output.Write(")", 1);
	Output.Close();

	return CString(Output.GetPointer(), Output.GetLength());
	}
Exemplo n.º 13
0
ALERROR CUniverse::LoadSound (SDesignLoadCtx &Ctx, CXMLElement *pElement)

//	LoadSound
//
//	Load a sound element

	{
	ALERROR error;

	if (Ctx.bNoResources)
		return NOERROR;

	DWORD dwUNID = LoadUNID(Ctx, pElement->GetAttribute(UNID_ATTRIB));
	CString sFilename = pElement->GetAttribute(FILENAME_ATTRIB);

	//	Load the image
	int iChannel;
	if (error = Ctx.pResDb->LoadSound(*m_pSoundMgr, NULL_STR, sFilename, &iChannel))
		{
		Ctx.sError = strPatternSubst(CONSTLIT("Unable to load sound: %s"), sFilename.GetASCIIZPointer());
		return error;
		}

	if (error = m_Sounds.AddEntry((int)dwUNID, (CObject *)iChannel))
		{
		Ctx.sError = CONSTLIT("Unable to add sound");
		return error;
		}

#ifdef DEBUG_SOURCE_LOAD_TRACE
	kernelDebugLogMessage("Loaded sound: %x", dwUNID);
#endif

	return NOERROR;
	}
Exemplo n.º 14
0
ICCItem *CCPrimitive::Execute (CEvalContext *pCtx, ICCItem *pArgs)

//	Execute
//
//	Executes the function and returns a result

	{
	bool bCustomArgEval = ((m_dwFlags & PPFLAG_CUSTOM_ARG_EVAL) ? true : false);

	//	Evaluate args, if necessary

	ICCItem *pEvalArgs;
	if (!bCustomArgEval)
		{
		pEvalArgs = pCtx->pCC->EvaluateArgs(pCtx, pArgs, m_sArgPattern);
		if (pEvalArgs->IsError())
			return pEvalArgs;
		}
	else
		pEvalArgs = pArgs;

	//	Invoke the function

	ICCItem *pResult;
	bool bReportError = false;
	try
		{
		pResult = m_pfFunction(pCtx, pEvalArgs, m_dwData);
		}
	catch (...)
		{
		bReportError = true;
		}

	//	Report error

	if (bReportError)
		{
		CString sArgs;
		try
			{
			sArgs = pEvalArgs->Print(pCtx->pCC);
			}
		catch (...)
			{
			sArgs = CONSTLIT("[invalid arg item]");
			}

		CString sError = strPatternSubst(CONSTLIT("Exception in %s; arg = %s"), m_sName, sArgs);
		pResult = pCtx->pCC->CreateError(sError, pEvalArgs);
		kernelDebugLogMessage(sError.GetASCIIZPointer());
		}

	//	Done

	if (!bCustomArgEval)
		pEvalArgs->Discard(pCtx->pCC);

	return pResult;
	}
Exemplo n.º 15
0
ALERROR CTopologyNode::ParseCriteriaInt (const CString &sCriteria, SCriteria *retCrit)

//	ParseCriteriaInt
//
//	Parses a string criteria

	{
	char *pPos = sCriteria.GetASCIIZPointer();
	while (*pPos != '\0')
		{
		switch (*pPos)
			{
			case '+':
			case '-':
				{
				bool bRequired = (*pPos == '+');
				CString sParam = ::ParseCriteriaParam(&pPos, false);
				if (bRequired)
					retCrit->AttribsRequired.Insert(sParam);
				else
					retCrit->AttribsNotAllowed.Insert(sParam);
				break;
				}
			}

		pPos++;
		}

	return NOERROR;
	}
Exemplo n.º 16
0
void WriteNumber (CMemoryWriteStream &Stream, int iNumber, int iLeadingZeros)
	{
	CString sNumber = strFromInt(iNumber, false);
	if (sNumber.GetLength() < iLeadingZeros)
		Stream.Write("0000000000", iLeadingZeros - sNumber.GetLength());

	Stream.Write(sNumber.GetASCIIZPointer(), sNumber.GetLength());
	}
Exemplo n.º 17
0
ALERROR ParseGameFile (const CString &sFilename, CXMLElement **retpData)
	{
	ALERROR error;
	CFileReadBlock DataFile(sFilename);
	CString sError;

	printf("Parsing %s...", sFilename.GetASCIIZPointer());
	if (error = CXMLElement::ParseXML(&DataFile, retpData, &sError))
		{
		printf("\n%s\n", sError.GetASCIIZPointer());
		return error;
		}

	printf("done.\n");

	return NOERROR;
	}
Exemplo n.º 18
0
ALERROR CCurrencyAndValue::InitFromXML (SDesignLoadCtx &Ctx, const CString &sDesc)

//	InitFromXML
//
//	Initialies from a string

	{
	//	If blank, default to 0 credits

	if (sDesc.IsBlank())
		{
		//	If m_pCurrency is blank we default to credits (at Bind time)
		m_pCurrency.LoadUNID(NULL_STR);
		m_iValue = 0;
		return NOERROR;
		}

	//	Look for a colon separator

	char *pPos = sDesc.GetASCIIZPointer();
	char *pStart = pPos;
	while (*pPos != '\0' && *pPos != ':')
		pPos++;

	//	If found, then take the first part as the currency
	//	and the second part as value.

	CString sCurrency;
	CString sValue;
	if (*pPos == ':')
		{
		sCurrency = CString(pStart, pPos - pStart);
		sValue = CString(pPos + 1);
		}

	//	Otherwise, assume credits (blank string means credits)

	else
		sValue = sDesc;

	//	Load the currency type

	m_pCurrency.LoadUNID(sCurrency);

	//	Load the value

	bool bFailed;
	m_iValue = strToInt(sValue, 0, &bFailed);
	if (bFailed)
		{
		Ctx.sError = strPatternSubst(CONSTLIT("Invalid currency value: %s"), sValue);
		return ERR_FAIL;
		}

	//	Done

	return NOERROR;
	}
Exemplo n.º 19
0
void CG16bitFont::DrawText (CG16bitImage &Dest, 
							int x, 
							int y, 
							WORD wColor, 
							DWORD byOpacity,
							const CString &sText,
							DWORD dwFlags,
							int *retx) const

//	DrawText
//
//	Draws a line of text on the given image

	{
	char *pPos = sText.GetASCIIZPointer();
	char *pEndPos = pPos + sText.GetLength();
	int xPos = x;

	if (dwFlags & AlignCenter)
		{
		int cxWidth = MeasureText(sText);
		xPos -= cxWidth / 2;
		}
	else if (dwFlags & AlignRight)
		{
		int cxWidth = MeasureText(sText);
		xPos -= cxWidth;
		}

	bool bInQuotes = false;
	while (pPos < pEndPos)
		{
		//	Get metrics

		int iIndex = (int)(BYTE)(*pPos) - g_iStartChar;
		iIndex = max(0, iIndex);

		CharMetrics *pMetrics = (CharMetrics *)m_Metrics.GetStruct(iIndex);

		//	Paint

		Dest.FillMask(0,
				iIndex * m_cyHeight,
				pMetrics->cxWidth,
				m_cyHeight,
				m_FontImage,
				wColor,
				xPos,
				y,
				(BYTE)byOpacity);

		pPos++;
		xPos += pMetrics->cxAdvance;
		}
	
	if (retx)
		*retx = xPos;
	}
Exemplo n.º 20
0
bool CSoundMgr::PlayMusic (const CString &sFilename, int iPos, CString *retsError)

//	PlayMusic
//
//	Starts playing the given MP3 file

	{
	try
		{
		if (m_hMusic == NULL)
			return false;

		//	Figure out our current state

		SMusicPlayState State;
		GetMusicPlayState(&State);

		//	If we're not already playing this file, open it

		if (!strEquals(sFilename, State.sFilename))
			{
			//	Stop playing first

			if (State.bPlaying || State.bPaused)
				MCIWndStop(m_hMusic);

			//	Open new file

			if (MCIWndOpen(m_hMusic, sFilename.GetASCIIZPointer(), MCI_OPEN_SHAREABLE) != 0)
				{
				if (retsError)
					{
					char *pDest = retsError->GetWritePointer(1024);
					MCIWndGetError(m_hMusic, pDest, retsError->GetLength());
					retsError->Truncate(lstrlen(pDest));
					}
				return false;
				}
			}

		//	Seek to the proper position

		MCIWndSeek(m_hMusic, Max(0, Min(iPos, State.iLength)));

		//	Play it

		if (MCIWndPlay(m_hMusic) != 0)
			return false;

		//	Done

		return true;
		}
	catch (...)
		{
		return false;
		}
	}
Exemplo n.º 21
0
CRTFParser::CRTFParser (const CString &sInput, const IFontTable &FontTable, CTextBlock *pOutput) :
		m_pInput(sInput.GetASCIIZPointer()),
		m_FontTable(FontTable),
		m_pOutput(pOutput)

//	CRTFParser constructor

	{
	}
Exemplo n.º 22
0
void CUWindow::SetTitle (CString sString)

//	SetTitle
//
//	Set the window title

	{
	SetWindowText(m_hWnd, sString.GetASCIIZPointer());
	}
Exemplo n.º 23
0
void CEffectCreator::InitPainterParameters (CCreatePainterCtx &Ctx, IEffectPainter *pPainter)

//	InitPainterParameters
//
//	Initialize painter parameters

	{
	SEventHandlerDesc Event;
	if (FindEventHandlerEffectType(evtGetParameters, &Event))
		{
		CCodeChainCtx CCCtx;

		CCCtx.SaveAndDefineDataVar(Ctx.GetData());

		ICCItem *pResult = CCCtx.Run(Event);
		if (pResult->IsError())
			::kernelDebugLogMessage(CONSTLIT("EffectType %x GetParameters: %s"), GetUNID(), (LPSTR)pResult->GetStringValue());
		else if (pResult->IsSymbolTable())
			{
			int i;
			CCSymbolTable *pTable = (CCSymbolTable *)pResult;

			for (i = 0; i < pTable->GetCount(); i++)
				{
				CString sParam = pTable->GetKey(i);
				ICCItem *pValue = pTable->GetElement(i);
				CEffectParamDesc Value;

				if (pValue->IsNil())
					Value.InitNull();
				else if (pValue->IsInteger())
					Value.InitInteger(pValue->GetIntegerValue());
				else if (pValue->IsIdentifier())
					{
					CString sValue = pValue->GetStringValue();
					char *pPos = sValue.GetASCIIZPointer();

					//	If this is a color, parse it

					if (*pPos == '#')
						Value.InitColor(::LoadRGBColor(sValue));

					//	Otherwise, a string

					else
						Value.InitString(sValue);
					}

				pPainter->SetParam(Ctx, sParam, Value);
				}
			}
		else
			::kernelDebugLogMessage(CONSTLIT("EffectType %x GetParameters: Expected struct result."), GetUNID());

		CCCtx.Discard(pResult);
		}
	}
Exemplo n.º 24
0
ALERROR CCurrencyAndRange::InitFromXML (SDesignLoadCtx &Ctx, const CString &sDesc)

//	InitFromXML
//
//	Initialize from XML

	{
	ALERROR error;

	//	Handle blank

	if (sDesc.IsBlank())
		{
		m_pCurrency.LoadUNID(NULL_STR);
		m_Value.SetConstant(0);
		return NOERROR;
		}

	//	Look for a colon separator

	char *pPos = sDesc.GetASCIIZPointer();
	char *pStart = pPos;
	while (*pPos != '\0' && *pPos != ':')
		pPos++;

	//	If found, then take the first part as the currency
	//	and the second part as value.

	CString sCurrency;
	CString sValue;
	if (*pPos == ':')
		{
		sCurrency = CString(pStart, pPos - pStart);
		sValue = CString(pPos + 1);
		}

	//	Otherwise, assume credits (blank string means credits)

	else
		sValue = sDesc;

	//	Load the currency type

	m_pCurrency.LoadUNID(sCurrency);

	//	Load the range

	if (error = m_Value.LoadFromXML(sValue))
		{
		Ctx.sError = strPatternSubst(CONSTLIT("Invalid dice range: %s"), sValue);
		return ERR_FAIL;
		}

	//	Done

	return NOERROR;
	}
Exemplo n.º 25
0
void DumpTDB (const CString &sFilespec)
	{
	int i;

	//	Open the TDB

	CString sError;
	CResourceDb TDBFile(sFilespec, true);
	if (TDBFile.Open(DFOPEN_FLAG_READ_ONLY, &sError) != NOERROR)
		{
		printf("error : Unable to open '%s': %s\n", sFilespec.GetASCIIZPointer(), sError.GetASCIIZPointer());
		return;
		}

	//	Dump out all the resources

	for (i = 0; i < TDBFile.GetResourceCount(); i++)
		printf("%s\n", TDBFile.GetResourceFilespec(i).GetASCIIZPointer());
	}
Exemplo n.º 26
0
ALERROR CUniverse::LoadModules (SDesignLoadCtx &Ctx, CXMLElement *pModules)

//	LoadModules
//
//	Load all sub-modules

	{
	ALERROR error;
	int i;

	for (i = 0; i < pModules->GetContentElementCount(); i++)
		{
		CXMLElement *pModule = pModules->GetContentElement(i);

		CString sFilename = pModule->GetAttribute(FILENAME_ATTRIB);

#ifdef DEBUG_SOURCE_LOAD_TRACE
		kernelDebugLogMessage("Loading module %s...", sFilename.GetASCIIZPointer());
#endif
		//	Load the module

		CXMLElement *pModuleXML;
		if (error = Ctx.pResDb->LoadModule(NULL_STR, sFilename, &pModuleXML, &Ctx.sError))
			return error;

#ifdef DEBUG_SOURCE_LOAD_TRACE
		kernelDebugLogMessage("...loaded XML from database");
#endif
		if (error = LoadModule(Ctx, pModuleXML))
			{
			Ctx.sError = strPatternSubst(CONSTLIT("Unable to load module (%s): %s"), sFilename.GetASCIIZPointer(), Ctx.sError.GetASCIIZPointer());
			return error;
			}

		delete pModuleXML;

#ifdef DEBUG_SOURCE_LOAD_TRACE
		kernelDebugLogMessage("Done loading module", sFilename.GetASCIIZPointer());
#endif
		}

	return NOERROR;
	}
Exemplo n.º 27
0
void WriteTimeValue (CMemoryWriteStream &Output, DWORD dwTime)
	{
	if (dwTime == INVALID_TIME)
		Output.Write(NIL_VALUE.GetASCIIZPointer(), NIL_VALUE.GetLength());
	else
		{
		CString sInt = strFromInt(dwTime);
		Output.Write(sInt.GetASCIIZPointer(), sInt.GetLength());
		}
	}
Exemplo n.º 28
0
void HexarcTest (CUniverse &Universe, CXMLElement *pCmdLine)
	{
	int i, j;

	CString sHostspec = pCmdLine->GetAttribute(OPTION_HOST);
	if (sHostspec.IsBlank())
		sHostspec = HOSTSPEC_DEFAULT;

	CHTTPClientSession Session;

	if (!Connect(sHostspec, Session))
		return;

	//	Read the list of high scores

	for (j = 0; j < 5; j++)
		{
		CJSONValue Payload = CJSONValue(CJSONValue::typeObject);
		Payload.InsertHandoff(FIELD_MAX_GAMES, CJSONValue(100));
		CJSONValue Result;
		if (!ServerCommand(Session, METHOD_OPTIONS, FUNC_HIGH_SCORE_GAMES, Payload, &Result))
			{
			printf("%s\n", Result.AsString().GetASCIIZPointer());
			return;
			}

		//	For each adventure, print high score

		if (Result.GetCount() == 0)
			printf("No game records.\n");
		else
			{
			for (i = 0; i < Result.GetCount(); i++)
				{
				const CJSONValue &Record = Result.GetElement(i);
				DWORD dwAdventure = (DWORD)Record.GetElement(FIELD_ADVENTURE).AsInt32();
				if (dwAdventure == 0)
					continue;

				CGameRecord GameRecord;
				if (GameRecord.InitFromJSON(Record) != NOERROR)
					{
					printf("Unable to parse JSON record.\n");
					continue;
					}

				DWORD dwAdventureUNID = GameRecord.GetAdventureUNID();
				CString sUsername = GameRecord.GetUsername();
				int iScore = GameRecord.GetScore();

				printf("%x %s %d\n", dwAdventureUNID, sUsername.GetASCIIZPointer(), iScore);
				}
			}
		}
	}
Exemplo n.º 29
0
void OutputTable (SItemTableCtx &Ctx, const SItemTypeList &ItemList)
	{
	int i, j;

	if (ItemList.GetCount() == 0)
		return;

	//	Output each row

	for (i = 0; i < ItemList.GetCount(); i++)
		{
		CItemType *pType = ItemList[i];

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

			const CString &sField = Ctx.Cols[j];

			//	Get the field value

			CString sValue;
			CItem Item(pType, 1);
			CItemCtx ItemCtx(Item);
			CCodeChainCtx CCCtx;

			ICCItem *pResult = Item.GetProperty(&CCCtx, ItemCtx, sField);

			if (pResult->IsNil())
				sValue = NULL_STR;
			else
				sValue = pResult->Print(&g_pUniverse->GetCC(), PRFLAG_NO_QUOTES | PRFLAG_ENCODE_FOR_DISPLAY);

			pResult->Discard(&g_pUniverse->GetCC());

			//	Format the value

			if (strEquals(sField, FIELD_AVERAGE_DAMAGE) || strEquals(sField, FIELD_POWER_PER_SHOT))
				printf("%.2f", strToInt(sValue, 0, NULL) / 1000.0);
			else if (strEquals(sField, FIELD_POWER))
				printf("%.1f", strToInt(sValue, 0, NULL) / 1000.0);
			else if (strEquals(sField, FIELD_TOTAL_COUNT))
				{
				SDesignTypeInfo *pInfo = Ctx.TotalCount.GetAt(pType->GetUNID());
				double rCount = (pInfo ? pInfo->rPerGameMeanCount : 0.0);
				printf("%.2f", rCount);
				}
			else
				printf(sValue.GetASCIIZPointer());
			}

		printf("\n");
		}
	}
Exemplo n.º 30
0
ALERROR CRandomEnhancementGenerator::InitFromXML (SDesignLoadCtx &Ctx, CXMLElement *pDesc)

//	InitFromXML
//
//	Loads the structure from XML

	{
	m_iChance = pDesc->GetAttributeInteger(ENHANCED_ATTRIB);
	CString sEnhancement = pDesc->GetAttribute(ENHANCEMENT_ATTRIB);

	//	If we have no enhancement desc, then we come up with a random
	//	one using our own internal algorithm.

	char *pPos = sEnhancement.GetASCIIZPointer();
	if (sEnhancement.IsBlank())
		{
		m_dwMods = 0;
		m_pCode = NULL;
		}

	//	If the enhancement desc is a script, then load it now

	else if (*pPos == '=')
		{
		CCodeChain &CC = g_pUniverse->GetCC();

		m_dwMods = 0;

		m_pCode = CC.Link(pPos, 1, NULL);
		if (m_pCode->IsError())
			{
			Ctx.sError = m_pCode->GetStringValue();
			m_pCode->Discard(&CC);
			return ERR_FAIL;
			}

		if (m_iChance == 0)
			m_iChance = 100;
		}

	//	Otherwise, see if this is a valid mod number

	else
		{
		m_dwMods = (DWORD)strToInt(sEnhancement, 0, NULL);
		m_pCode = NULL;

		if (m_dwMods != 0 && m_iChance == 0)
			m_iChance = 100;
		}

	return NOERROR;
	}