Example #1
0
ALERROR WriteModuleImages (CXMLElement *pModule, const CString &sFolder, CSymbolTable &Resources, CDataFile &Out)
	{
	ALERROR error;
	int i;

	for (i = 0; i < pModule->GetContentElementCount(); i++)
		{
		CXMLElement *pItem = pModule->GetContentElement(i);
		if (strEquals(pItem->GetTag(), TAG_IMAGES))
			{
			CString sSubFolder = pathAddComponent(sFolder, pItem->GetAttribute(ATTRIB_FOLDER));

			if (error = WriteModuleImages(pItem, sSubFolder, Resources, Out))
				return error;
			}
		else if (strEquals(pItem->GetTag(), TAG_IMAGE))
			{
			CString sFilename = pItem->GetAttribute(ATTRIB_BITMAP);
			if (!sFilename.IsBlank())
				{
				if (error = WriteResource(sFilename, sFolder, Resources, Out))
					continue;
				}

			sFilename = pItem->GetAttribute(ATTRIB_BITMASK);
			if (!sFilename.IsBlank())
				{
				if (error = WriteResource(sFilename, sFolder, Resources, Out))
					continue;
				}
			}
		}

	return NOERROR;
	}
Example #2
0
ALERROR CRandomItems::LoadFromXML (SDesignLoadCtx &Ctx, CXMLElement *pDesc)

//	LoadFromXML
//
//	Load from XML

	{
	ALERROR error;

	CString sCriteria = pDesc->GetAttribute(CRITERIA_ATTRIB);
	if (sCriteria.IsBlank())
		{
		CString sAttributes = pDesc->GetAttribute(ATTRIBUTES_ATTRIB);
		if (sAttributes.IsBlank())
			sAttributes = pDesc->GetAttribute(MODIFIERS_ATTRIB);

		sCriteria = strPatternSubst(CONSTLIT("%s %s"), pDesc->GetAttribute(CATEGORIES_ATTRIB), sAttributes);
		}

	CItem::ParseCriteria(sCriteria, &m_Criteria);
	m_sLevelFrequency = pDesc->GetAttribute(LEVEL_FREQUENCY_ATTRIB);
	m_iLevel = pDesc->GetAttributeInteger(LEVEL_ATTRIB);
	m_iLevelCurve = pDesc->GetAttributeInteger(LEVEL_CURVE_ATTRIB);
	m_iDamaged = pDesc->GetAttributeInteger(DAMAGED_ATTRIB);

	if (error = m_Enhanced.InitFromXML(Ctx, pDesc))
		return error;

	m_Table = NULL;
	m_iCount = 0;

	return NOERROR;
	}
Example #3
0
ALERROR WriteModuleImages (CTDBCompiler &Ctx, CXMLElement *pModule, const CString &sFolder, CDataFile &Out)
	{
	ALERROR error;
	int i;

	for (i = 0; i < pModule->GetContentElementCount(); i++)
		{
		CXMLElement *pItem = pModule->GetContentElement(i);
		if (strEquals(pItem->GetTag(), TAG_IMAGES))
			{
			CString sSubFolder = pathAddComponent(sFolder, pItem->GetAttribute(ATTRIB_FOLDER));

			if (error = WriteModuleImages(Ctx, pItem, sSubFolder, Out))
				return error;
			}
		else if (strEquals(pItem->GetTag(), TAG_IMAGE))
			{
			CString sFilename = pItem->GetAttribute(ATTRIB_BITMAP);
			if (!sFilename.IsBlank())
				{
				bool bCompress = strEquals(strToLower(pathGetExtension(sFilename)), CONSTLIT("bmp"));
				if (error = WriteResource(Ctx, sFilename, sFolder, bCompress, Out))
					continue;
				}

			sFilename = pItem->GetAttribute(ATTRIB_BITMASK);
			if (!sFilename.IsBlank())
				{
				bool bCompress = strEquals(strToLower(pathGetExtension(sFilename)), CONSTLIT("bmp"));
				if (error = WriteResource(Ctx, sFilename, sFolder, bCompress, Out))
					continue;
				}

			sFilename = pItem->GetAttribute(ATTRIB_SHADOW_MASK);
			if (!sFilename.IsBlank())
				{
				bool bCompress = strEquals(strToLower(pathGetExtension(sFilename)), CONSTLIT("bmp"));
				if (error = WriteResource(Ctx, sFilename, sFolder, bCompress, Out))
					continue;
				}

			sFilename = pItem->GetAttribute(ATTRIB_HIT_MASK);
			if (!sFilename.IsBlank())
				{
				bool bCompress = strEquals(strToLower(pathGetExtension(sFilename)), CONSTLIT("bmp"));
				if (error = WriteResource(Ctx, sFilename, sFolder, bCompress, Out))
					continue;
				}
			}
		}

	return NOERROR;
	}
Example #4
0
ALERROR CFlareEffectCreator::OnEffectCreateFromXML (SDesignLoadCtx &Ctx, CXMLElement *pDesc, const CString &sUNID)

//	OnEffectCreateFromXML
//
//	Initializes from XML

{
    CString sStyle = pDesc->GetAttribute(STYLE_ATTRIB);
    if (strEquals(sStyle, STYLE_FADING_BLAST))
        m_iStyle = styleFadingBlast;
    else if (strEquals(sStyle, STYLE_FLICKER))
        m_iStyle = styleFlicker;
    else if (sStyle.IsBlank() || strEquals(sStyle, STYLE_PLAIN))
        m_iStyle = stylePlain;
    else
    {
        Ctx.sError = strPatternSubst(CONSTLIT("Invalid Flare style: %s"), sStyle);
        return ERR_FAIL;
    }

    m_iRadius = pDesc->GetAttributeIntegerBounded(RADIUS_ATTRIB, 0, -1, 100);
    m_iLifetime = pDesc->GetAttributeIntegerBounded(LIFETIME_ATTRIB, 0, -1, 1);
    m_rgbPrimaryColor = ::LoadRGBColor(pDesc->GetAttribute(PRIMARY_COLOR_ATTRIB));

    CString sAttrib;
    if (pDesc->FindAttribute(SECONDARY_COLOR_ATTRIB, &sAttrib))
        m_rgbSecondaryColor = ::LoadRGBColor(sAttrib);
    else
        m_rgbSecondaryColor = m_rgbPrimaryColor;

    return NOERROR;
}
Example #5
0
void CMultiverseModel::OnUserSignedIn (const CString &sUsername)

//	OnUserSignedIn
//
//	The given user has signed in. The given username is the human-readable
//	username (not the username key).

	{
	CSmartLock Lock(m_cs);

	ASSERT(!sUsername.IsBlank());

	if (!strEquals(sUsername, m_sUsername) || !m_fUserSignedIn)
		{
		m_sUsername = sUsername;

		//	Clear out the collection so that we are forced to reload it.

		DeleteCollection();

		//	We're signed in

		m_fUserSignedIn = true;
		}
	}
Example #6
0
void CSystemCreateStats::AddEntryPermutations (const CString &sPrefix, const TArray<CString> &Attribs, int iPos)

//	AddEntryPermutations
//
//	Adds permutions

	{
	//	If nothing, then nothing

	if (iPos >= Attribs.GetCount())
		return;

	//	Get the base case

	CString sNewPrefix;
	if (!sPrefix.IsBlank())
		sNewPrefix = strPatternSubst(CONSTLIT("%s,%s"), sPrefix, Attribs[iPos]);
	else
		sNewPrefix = Attribs[iPos];

	AddEntry(sNewPrefix);

	//	Permute with the base case

	AddEntryPermutations(sNewPrefix, Attribs, iPos + 1);

	//	Permute the remainder

	AddEntryPermutations(sPrefix, Attribs, iPos + 1);
	}
Example #7
0
ALERROR CDeviceClass::ParseLinkedFireOptions (SDesignLoadCtx &Ctx, const CString &sDesc, DWORD *retdwOptions)

//	ParseLinkedFireOptions
//
//	Parses a linked-fire options string.

	{
	DWORD dwOptions = 0;

	if (sDesc.IsBlank())
		;
	else if (strEquals(sDesc, LINKED_FIRE_ALWAYS))
		dwOptions |= CDeviceClass::lkfAlways;
	else if (strEquals(sDesc, LINKED_FIRE_TARGET))
		dwOptions |= CDeviceClass::lkfTargetInRange;
	else if (strEquals(sDesc, LINKED_FIRE_ENEMY))
		dwOptions |= CDeviceClass::lkfEnemyInRange;
	else
		{
		Ctx.sError = strPatternSubst(CONSTLIT("Invalid linkedFire option: %s"), sDesc);
		return ERR_FAIL;
		}

	*retdwOptions = dwOptions;

	return NOERROR;
	}
Example #8
0
void SelectByCriteria (SItemTableCtx &Ctx, const CString &sCriteria, TArray<CItemType *> *retList)
	{
	int i;

	//	Compute the criteria

	CItemCriteria Crit;
	if (!sCriteria.IsBlank())
		CItem::ParseCriteria(sCriteria, &Crit);
	else
		CItem::InitCriteriaAll(&Crit);

	//	Loop over all items that match and add them to
	//	a sorted table.

	retList->DeleteAll();
	for (i = 0; i < Ctx.pUniverse->GetItemTypeCount(); i++)
		{
		CItemType *pType = Ctx.pUniverse->GetItemType(i);
		CItem Item(pType, 1);

		if (!Item.MatchesCriteria(Crit))
			continue;

		retList->Insert(pType);
		}
	}
Example #9
0
CString pathAddComponent (const CString &sPath, const CString &sComponent)

//	pathAddComponent
//
//	Concatenates the given component to the given path and returns
//	the result
//
//	sPath: full pathname to a directory (e.g. "c:\", "\\lawrence\cdrom", "d:\test")
//	sComponent: directory, filename, or wildcard.

	{
	CString sResult = sPath;
	int iPathLength = sResult.GetLength();
	char *pString = sResult.GetASCIIZ();

	//	If the path name does not have a trailing backslash, add one

	if (!sPath.IsBlank() && pString[iPathLength-1] != '\\')
		sResult.Append(STR_PATH_SEPARATOR);

	//	Now concatenate the component

	sResult.Append(sComponent);

	return sResult;
	}
Example #10
0
bool CreateBinaryFromList (CCodeChain &CC, const CString &sClass, ICCItem *pList, void *pvDest)

//	CreateBinaryFromList
//
//	Initializes binary structure from a list

	{
	int iStart = 0;

	//	Check the class, if provided

	if (!sClass.IsBlank())
		{
		if (pList->GetCount() < 1)
			return false;

		if (!strEquals(pList->GetElement(0)->GetStringValue(), sClass))
			return false;

		iStart++;
		}

	//	Load the binary data

	DWORD *pDest = (DWORD *)pvDest;
	for (int i = iStart; i < pList->GetCount(); i++)
		*pDest++ = (DWORD)pList->GetElement(i)->GetIntegerValue();

	return true;
	}
Example #11
0
ALERROR CSingleItem::LoadFromXML (SDesignLoadCtx &Ctx, CXMLElement *pDesc)

//	LoadFromXML
//
//	Load from XML

	{
	ALERROR error;

	if (error = m_pItemType.LoadUNID(Ctx, pDesc->GetAttribute(ITEM_ATTRIB)))
		return error;

	m_iDamaged = pDesc->GetAttributeInteger(DAMAGED_ATTRIB);
	m_bDebugOnly = pDesc->GetAttributeBool(DEBUG_ONLY_ATTRIB);

	if (m_pItemType.GetUNID() == 0)
		{
		CString sUNID = pDesc->GetAttribute(ITEM_ATTRIB);
		if (sUNID.IsBlank())
			Ctx.sError = strPatternSubst(CONSTLIT("<Item> element missing item attribute."));
		else
			Ctx.sError = strPatternSubst(CONSTLIT("Invalid item UNID: %s"), sUNID);
		return ERR_FAIL;
		}

	if (error = m_Enhanced.InitFromXML(Ctx, pDesc))
		return error;

	return NOERROR;
	}
Example #12
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;
	}
Example #13
0
ALERROR CExtension::LoadImagesElement (SDesignLoadCtx &Ctx, CXMLElement *pDesc)

//	LoadImagesElement
//
//	Loads <Images> element
//	(For backwards compatibility)

	{
	ALERROR error;
	int i;

	//	Figure out if we've got a special folder for the images

	CString sOldFolder = Ctx.sFolder;
	CString sFolder = pDesc->GetAttribute(FOLDER_ATTRIB);
	if (!sFolder.IsBlank())
		Ctx.sFolder = pathAddComponent(Ctx.sFolder, sFolder);

	//	Load all images

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

		if (error = LoadDesignType(Ctx, pItem))
			return error;
		}

	//	Restore folder

	Ctx.sFolder = sOldFolder;

	return NOERROR;
	}
Example #14
0
ALERROR CEffectCreator::CreateFromXML (SDesignLoadCtx &Ctx, CXMLElement *pDesc, const CString &sUNID, CEffectCreator **retpCreator)

//	CreateFromXML
//
//	Creates the creator from an XML element

	{
	ALERROR error;
	CEffectCreator *pCreator;

	//	Basic info

	CString sEffectUNID = sUNID;
	if (sEffectUNID.IsBlank())
		{
		DWORD dwUNID = pDesc->GetAttributeInteger(UNID_ATTRIB);
		if (dwUNID)
			sEffectUNID = strFromInt(dwUNID, FALSE);
		else
			sEffectUNID = STR_NO_UNID;
		}

	//	Create the effect based on the child tag

	if (pDesc->GetContentElementCount() == 0)
		{
		*retpCreator = NULL;
		return NOERROR;
		}
	else if (pDesc->GetContentElementCount() == 1)
		{
		if (error = CreateSimpleFromXML(Ctx, pDesc->GetContentElement(0), sEffectUNID, &pCreator))
			return error;
		}
	else
		{
		pCreator = new CEffectGroupCreator;
		if (pCreator == NULL)
			return ERR_MEMORY;

		pCreator->m_sUNID = sEffectUNID;

		//	Type-specific creation

		if (error = pCreator->OnEffectCreateFromXML(Ctx, pDesc, sEffectUNID))
			return error;
		}

	//	Sound Effect (resolved later)

	pCreator->m_dwSoundUNID = pDesc->GetAttributeInteger(SOUND_ATTRIB);
	pCreator->m_iSound = -1;
	
	//	Done

	*retpCreator = pCreator;

	return NOERROR;
	}
Example #15
0
ALERROR CGroupOfGenerators::LoadFromXML (SDesignLoadCtx &Ctx, CXMLElement *pDesc)

//	LoadFromXML
//
//	Load from XML

	{
	int i;
	ALERROR error;

	//	Load content elements

	m_Table.InsertEmpty(pDesc->GetContentElementCount());
	for (i = 0; i < m_Table.GetCount(); i++)
		{
		CXMLElement *pEntry = pDesc->GetContentElement(i);
			
		m_Table[i].iChance = pEntry->GetAttributeInteger(CHANCE_ATTRIB);
		if (m_Table[i].iChance == 0)
			m_Table[i].iChance = 100;

		CString sCount = pEntry->GetAttribute(COUNT_ATTRIB);
		if (sCount.IsBlank())
			m_Table[i].Count = DiceRange(0, 0, 1);
		else
			m_Table[i].Count.LoadFromXML(sCount);

		if (error = IItemGenerator::CreateFromXML(Ctx, pEntry, &m_Table[i].pItem))
			return error;
		}

	//	See if we force an average value

	CString sAttrib;
	if (pDesc->FindAttribute(LEVEL_VALUE_ATTRIB, &sAttrib))
		{
		TArray<int> Values;
		ParseIntegerList(sAttrib, 0, &Values);

		m_AverageValue.InsertEmpty(MAX_ITEM_LEVEL + 1);
		m_AverageValue[0] = 0;
		for (i = 0; i < Values.GetCount(); i++)
			m_AverageValue[i + 1] = Values[i];

		for (i = Values.GetCount() + 1; i <= MAX_ITEM_LEVEL; i++)
			m_AverageValue[i] = 0;
		}
	else if (pDesc->FindAttribute(VALUE_ATTRIB, &sAttrib))
		{
		int iValue = strToInt(sAttrib, 0);

		m_AverageValue.InsertEmpty(MAX_ITEM_LEVEL + 1);
		m_AverageValue[0] = 0;
		for (i = 1; i <= MAX_ITEM_LEVEL; i++)
			m_AverageValue[i] = iValue;
		}

	return NOERROR;
	}
Example #16
0
CString GetTypeDesc (CDesignType *pType)
	{
	CString sName = pType->GetTypeName();
	if (sName.IsBlank())
		return strPatternSubst(CONSTLIT("%08x: [%s]"), pType->GetUNID(), pType->GetTypeClassName());
	else
		return strPatternSubst(CONSTLIT("%08x: %s [%s]"), pType->GetUNID(), sName, pType->GetTypeClassName());
	}
Example #17
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;
	}
Example #18
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;
	}
Example #19
0
void CSoundMgr::GetMusicCatalog (const CString &sMusicFolder, TArray<CString> *retCatalog)

//	GetMusicCatalog
//
//	Returns a list of filenames for all songs in the given folder.
//	If sMusicFolder is NULL then we return the files in the Windows Music folder

	{
	AddMusicFolder((sMusicFolder.IsBlank() ? pathGetSpecialFolder(folderMusic) : sMusicFolder), retCatalog);
	}
ALERROR CDesignCollection::CreateTemplateTypes (SDesignLoadCtx &Ctx)

//	CreateTemplateTypes
//
//	This is called inside of BindDesign to create all template types

	{
	ALERROR error;
	int i;

	//	Create an appropriate context for running code

	CCodeChainCtx CCCtx;

	//	Loop over all active types looking for templates.
	//	NOTE: We cannot use the type-specific arrays because they have not been
	//	set up yet (remember that we are inside of BindDesign).

	for (i = 0; i < m_AllTypes.GetCount(); i++)
		{
		CDesignType *pTemplate = m_AllTypes.GetEntry(i);
		if (pTemplate->GetType() != designTemplateType)
			continue;

		//	Get the function to generate the type source

		CString sSource;
		SEventHandlerDesc Event;
		if (pTemplate->FindEventHandler(GET_TYPE_SOURCE_EVENT, &Event))
			{
			ICCItem *pResult = CCCtx.Run(Event);
			if (pResult->IsError())
				{
				Ctx.sError = strPatternSubst(CONSTLIT("GetTypeSource (%x): %s"), pTemplate->GetUNID(), pResult->GetStringValue());
				return ERR_FAIL;
				}
			else if (pResult->IsNil())
				sSource = NULL_STR;
			else
				sSource = pResult->GetStringValue();

			CCCtx.Discard(pResult);
			}

		//	Define the type

		if (!sSource.IsBlank())
			{
			if (error = AddDynamicType(pTemplate->GetExtension(), pTemplate->GetUNID(), sSource, true, &Ctx.sError))
				return error;
			}
		}

	return NOERROR;
	}
Example #21
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);
				}
			}
		}
	}
Example #22
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;
	}
Example #23
0
void CUIHelper::CreateSessionWaitAnimation (const CString &sID, const CString &sText, IAnimatron **retpControl) const

//	CreateSessionWaitAnimation
//
//	Creates a small wait animation at the lower-left of a session screen.

	{
	const CVisualPalette &VI = m_HI.GetVisuals();

	//	Compute some metrics

	RECT rcRect;
	VI.GetWidescreenRect(m_HI.GetScreen(), &rcRect);

	//	Figure out the position of the ring animation

	int xCenter = rcRect.left + (TITLE_BAR_HEIGHT / 2);
	int yCenter = rcRect.bottom + (TITLE_BAR_HEIGHT / 2);

	//	Create a sequencer to hold all the animations

	CAniSequencer *pRoot;
	CAniSequencer::Create(CVector(xCenter, yCenter), &pRoot);

	//	Create rings of increasing diameter

	VI.CreateRingAnimation(pRoot, RING_COUNT, RING_MIN_RADIUS, RING_SIZE);

	//	Add some text

	if (!sText.IsBlank())
		{
		const CG16bitFont &SubTitleFont = VI.GetFont(fontSubTitle);

		int xText = 8 + (TITLE_BAR_HEIGHT / 2);
		int yText = -(SubTitleFont.GetHeight() / 2);

		IAnimatron *pName = new CAniText;
		pName->SetPropertyVector(PROP_POSITION, CVector(xText, yText));
		pName->SetPropertyVector(PROP_SCALE, CVector(RectWidth(rcRect), SubTitleFont.GetHeight()));
		pName->SetPropertyColor(PROP_COLOR, VI.GetColor(colorTextFade));
		pName->SetPropertyFont(PROP_FONT, &SubTitleFont);
		pName->SetPropertyString(PROP_TEXT, sText);

		pRoot->AddTrack(pName, 0);
		}

	//	Done

	if (retpControl)
		*retpControl = pRoot;
	}
Example #24
0
ALERROR IEffectPainter::ValidateClass (SLoadCtx &Ctx, const CString &sOriginalClass)

//	ValidateClass
//
//	Reads the class string. If the class does not match the current painter,
//	we read the old data and return ERR_FAIL.

	{
	if (Ctx.dwVersion >= 40)
		{
		CString sClass;
		sClass.ReadFromStream(Ctx.pStream);

		//	If the original class doesn't match the current one, then it means
		//	that the design changed. In that case, we load the painter using the
		//	old class.

		if (!strEquals(sClass, sOriginalClass))
			{
			//	If sClass is blank, then it means that the original did not have
			//	an effect painter (but the current design does)

			if (!sClass.IsBlank())
				{
				//	Get the original creator

				CEffectCreator *pOriginalCreator;
				if (CEffectCreator::CreateFromTag(sClass, &pOriginalCreator) != NOERROR)
					{
					kernelDebugLogMessage("Unable to find original effect creator: %s", sClass.GetASCIIZPointer());
					return ERR_FAIL;
					}

				//	Load the original painter

				IEffectPainter *pOriginalPainter = pOriginalCreator->CreatePainter();
				pOriginalPainter->ReadFromStream(Ctx);

				//	Discard

				pOriginalPainter->Delete();
				delete pOriginalCreator;
				}

			//	Done

			return ERR_FAIL;
			}
		}

	return NOERROR;
	}
Example #25
0
DWORD CHumanInterface::AddTimer (DWORD dwMilliseconds, IHICommand *pListener, const CString &sCmd, bool bRecurring)

//	AddTimer
//
//	Adds a timer

	{
	return m_Timers.AddTimer(m_hWnd,
			dwMilliseconds,
			(pListener ? pListener : m_pController),
			(!sCmd.IsBlank() ? sCmd : CONSTLIT("cmdTimer")),
			bRecurring);
	}
Example #26
0
CString CAISettings::SetValue (const CString &sSetting, const CString &sValue)

//	SetValue
//
//	Set AISettings value

	{
	if (strEquals(sSetting, AGGRESSOR_ATTRIB))
		m_fAggressor = !sValue.IsBlank();
	else if (strEquals(sSetting, ASCEND_ON_GATE_ATTRIB))
		m_fAscendOnGate = !sValue.IsBlank();
	else if (strEquals(sSetting, COMBAT_SEPARATION_ATTRIB))
		m_rMinCombatSeparation = Max(1, strToInt(sValue, 1)) * g_KlicksPerPixel;
	else if (strEquals(sSetting, COMBAT_STYLE_ATTRIB))
		m_iCombatStyle = ConvertToAICombatStyle(sValue);
	else if (strEquals(sSetting, FIRE_ACCURACY_ATTRIB))
		m_iFireAccuracy = Max(0, Min(strToInt(sValue, 100), 100));
	else if (strEquals(sSetting, FIRE_RANGE_ADJ_ATTRIB))
		m_iFireRangeAdj = Max(1, strToInt(sValue, 100));
	else if (strEquals(sSetting, FIRE_RATE_ADJ_ATTRIB))
		m_iFireRateAdj = Max(1, strToInt(sValue, 10));
	else if (strEquals(sSetting, NO_DOGFIGHTS_ATTRIB))
		m_fNoDogfights = !sValue.IsBlank();
	else if (strEquals(sSetting, NO_SHIELD_RETREAT_ATTRIB))
		m_fNoShieldRetreat = !sValue.IsBlank();
	else if (strEquals(sSetting, NO_FRIENDLY_FIRE_ATTRIB))
		m_fNoFriendlyFire = !sValue.IsBlank();
	else if (strEquals(sSetting, NO_FRIENDLY_FIRE_CHECK_ATTRIB))
		m_fNoFriendlyFireCheck = !sValue.IsBlank();
	else if (strEquals(sSetting, NO_NAV_PATHS_ATTRIB))
		m_fNoNavPaths = !sValue.IsBlank();
	else if (strEquals(sSetting, NO_ORDER_GIVER_ATTRIB))
		m_fNoOrderGiver = !sValue.IsBlank();
	else if (strEquals(sSetting, NON_COMBATANT_ATTRIB))
		m_fNonCombatant = !sValue.IsBlank();
	else if (strEquals(sSetting, PERCEPTION_ATTRIB))
		m_iPerception = Max((int)CSpaceObject::perceptMin, Min(strToInt(sValue, CSpaceObject::perceptNormal), (int)CSpaceObject::perceptMax));
	else
		return NULL_STR;

	return GetValue(sSetting);
	}
Example #27
0
void CMenuData::AddMenuItem (const CString &sKey,
							 const CString &sLabel,
							 const CObjectImageArray *pImage,
							 const CString &sExtra,
							 DWORD dwFlags,
							 DWORD dwData,
							 DWORD dwData2)

//	AddMenuItem
//
//	Add an item

	{
	ASSERT(m_iCount < MAX_MENU_ITEMS);
	if (m_iCount == MAX_MENU_ITEMS)
		return;

	//	If we have a key, sort by key. Otherwise, we
	//	add it at the end.

	int iPos;
	if (sKey.IsBlank() || !(dwFlags & FLAG_SORT_BY_KEY))
		iPos = m_iCount;
	else
		{
		iPos = 0;
		while (iPos < m_iCount 
				&& !m_List[iPos].sKey.IsBlank()
				&& strCompareAbsolute(sKey, m_List[iPos].sKey) > 0)
			iPos++;

		//	Move other items up

		for (int i = m_iCount - 1; i >= iPos; i--)
			m_List[i+1] = m_List[i];
		}

	//	Add item

	m_List[iPos].sKey = sKey;
	m_List[iPos].sLabel = sLabel;
	m_List[iPos].dwData = dwData;
	m_List[iPos].dwData2 = dwData2;
	m_List[iPos].sExtra = sExtra;
	m_List[iPos].dwFlags = dwFlags;
	m_List[iPos].pImage = pImage;

	m_iCount++;
	}
Example #28
0
ALERROR CTopologyNode::AddStargateConnection (CTopologyNode *pDestNode, bool bOneWay, const CString &sFromName, const CString &sToName)

//	AddStargateConnection
//
//	Adds two stargates connecting this node with the destination.
//	The names of the stargates are optionally passed in (if not, they are autogenerated).

	{
	ALERROR error;

	CString sSourceGate = (sFromName.IsBlank() ? GenerateStargateName() : sFromName);
	CString sDestGate = ((!pDestNode->IsEndGame() && sToName.IsBlank()) ? pDestNode->GenerateStargateName() : sToName);

	//	Add stargate from source to destination

	if (error = AddGateInt(sSourceGate, pDestNode->GetID(), sDestGate))
		return ERR_FAIL;

	//	Check to see if the destination gate exists already
	//	[If sToName is blank, then we know that the gate does not exist because we autogenerated it.]

	bool bExists = (!sToName.IsBlank() && (pDestNode->m_NamedGates.Lookup(sDestGate) == NOERROR));

	//	If the gate doesn't exist AND we want both directions, create the destination gate
	//	[We don't create the other gate if it already exists OR we want a one-way gate.

	if (!bExists && !bOneWay && !pDestNode->IsEndGame())
		{
		if (error = pDestNode->AddGateInt(sDestGate, GetID(), sSourceGate))
			return ERR_FAIL;
		}

	//	Done

	return NOERROR;
	}
Example #29
0
void CStatCounterArray::Insert (const CString &sStat, int iCount, const CString &sSection, const CString &sSort)

//	Insert
//
//	Adds the given stat. If the stat already exists (by name) the counts are added

	{
	if (iCount == 0)
		return;

	ASSERT(!sStat.IsBlank());
	ASSERT(!sSection.IsBlank());

	//	First look for the section

	TMap<CString, SEntry> *pSection = m_Array.Find(sSection);
	if (pSection == NULL)
		pSection = m_Array.Insert(sSection);

	//	Next look for the entry

	SEntry *pEntry = pSection->Find(sStat);
	if (pEntry == NULL)
		{
		pEntry = pSection->Insert(sStat);
		pEntry->iCount = iCount;
		pEntry->sSort = sSort;
		}
	else
		{
		if (iCount > pEntry->iCount)
			pEntry->sSort = sSort;

		pEntry->iCount += iCount;
		}
	}
Example #30
0
CString CStatsSession::GetTaskProgressText (void)

//	GetTaskProgressText
//
//	Returns text to paint on the task progress line

	{
	CString sText;

	m_HI.GetBackgroundProcessor().GetProgress(&sText);
	if (sText.IsBlank())
		m_HI.GetBackgroundProcessor().GetLastResult(&sText);

	return sText;
	}