Example #1
0
ALERROR CUniverse::InitStarSystemTypes (SDesignLoadCtx &Ctx, CXMLElement *pElement)

//	InitStarSystemTypes
//
//	Load <StarSystemTypes> tag

	{
	ALERROR error;
	int i;

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

		if (strEquals(pItem->GetTag(), TABLES_TAG))
			{
			if (m_pSystemTables)
				{
				Ctx.sError = CONSTLIT("Multiple global tables found in <StarSystemDescriptions>");
				return ERR_FAIL;
				}

			m_pSystemTables = pItem->OrphanCopy();
			}
		else
			{
			if (error = m_Design.LoadEntryFromXML(Ctx, pItem))
				return error;

#ifdef DEBUG_SOURCE_LOAD_TRACE
			kernelDebugLogMessage("Loaded system type: %x", dwUNID);
#endif
			}
		}

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

//	OnCreateFromXML

	{
	ALERROR error;
	int i;

	//	Load some basic info

	m_sName = pDesc->GetAttribute(NAME_ATTRIB);
	m_dwBackgroundImage = pDesc->GetAttributeInteger(BACKGROUND_IMAGE_ATTRIB);
	if (error = m_pPrimaryMap.LoadUNID(Ctx, pDesc->GetAttribute(PRIMARY_MAP_ATTRIB)))
		return error;

	m_bStartingMap = pDesc->GetAttributeBool(STARTING_MAP_ATTRIB);

	//	If we have a primary map, then add it to the Uses list.

	if (m_pPrimaryMap.GetUNID() != 0)
		m_Uses.Insert(m_pPrimaryMap);

	//	Scale information

	m_iInitialScale = pDesc->GetAttributeIntegerBounded(INITIAL_SCALE_ATTRIB, 10, 1000, 100);
	m_iMaxScale = pDesc->GetAttributeIntegerBounded(MAX_SCALE_ATTRIB, 100, 1000, 200);
	m_iMinScale = pDesc->GetAttributeIntegerBounded(MIN_SCALE_ATTRIB, 10, 100, 50);

	//	Generate an UNID

	CString sUNID = strPatternSubst(CONSTLIT("%d"), GetUNID());

	//	Keep track of root nodes

	TArray<CString> RootNodes;

	//	Iterate over all child elements and process them

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

		if (strEquals(pItem->GetTag(), TOPOLOGY_CREATOR_TAG)
				|| strEquals(pItem->GetTag(), ROOT_NODE_TAG))
			{
			m_Creators.Insert(pItem->OrphanCopy());

			if (strEquals(pItem->GetTag(), ROOT_NODE_TAG))
				RootNodes.Insert(pItem->GetAttribute(ID_ATTRIB));
			}
		else if (strEquals(pItem->GetTag(), TOPOLOGY_PROCESSOR_TAG))
			{
			ITopologyProcessor *pNewProc;
			CString sProcessorUNID = strPatternSubst(CONSTLIT("%d:p%d"), GetUNID(), m_Processors.GetCount());

			if (error = ITopologyProcessor::CreateFromXMLAsGroup(Ctx, pItem, sProcessorUNID, &pNewProc))
				return error;

			m_Processors.Insert(pNewProc);
			}
		else if (strEquals(pItem->GetTag(), SYSTEM_TOPOLOGY_TAG))
			{
			if (error = m_FixedTopology.LoadFromXML(Ctx, pItem, this, sUNID, true))
				return error;
			}
		else if (strEquals(pItem->GetTag(), USES_TAG))
			{
			CSystemMapRef *pRef = m_Uses.Insert();

			if (error = pRef->LoadUNID(Ctx, pItem->GetAttribute(UNID_ATTRIB)))
				return error;
			}
		else
			{
			//	If it's none of the above, see if it is a node descriptor

			if (error = m_FixedTopology.LoadNodeFromXML(Ctx, pItem, this, sUNID))
				return error;
			}
		}

	//	Mark all the root nodes.
	//
	//	We need to do this for backwards compatibility because the old technique
	//	of having a root node with [Prev] for a stargate requires this. This was
	//	used by Huaramarca.

	for (i = 0; i < RootNodes.GetCount(); i++)
		if (error = m_FixedTopology.AddRootNode(Ctx, RootNodes[i]))
			return error;

	//	Init

	m_bAdded = false;

	//	Debug info

	m_bDebugShowAttributes = pDesc->GetAttributeBool(DEBUG_SHOW_ATTRIBUTES_ATTRIB);

	return NOERROR;
	}