コード例 #1
0
CVector CCodeChainCtx::AsVector (ICCItem *pItem)

//	AsVector
//
//	Convert item to vector

	{
	return CreateVectorFromList(m_CC, pItem);
	}
コード例 #2
0
ファイル: CCUtil.cpp プロジェクト: alanhorizon/Transcendence
bool GetPosOrObject (CEvalContext *pEvalCtx, 
					 ICCItem *pArg, 
					 CVector *retvPos, 
					 CSpaceObject **retpObj,
					 int *retiLocID)

//	GetPosOrObject
//
//	pArg is either a position or an object. We return a position and/or the object.

	{
	CCodeChain &CC(*pEvalCtx->pCC);

	CVector vPos;
	CSpaceObject *pObj = NULL;
	int iLocID = -1;

	if (pArg->IsNil())
		NULL;
	else if (pArg->IsList())
		{
		//	Is this a location criteria?

		CString sTag = pArg->GetElement(0)->GetStringValue();
		if (strEquals(sTag, CONSTLIT("location")))
			{
			CSystem *pSystem = g_pUniverse->GetCurrentSystem();
			if (pSystem == NULL)
				return false;

			//	Get the criteria and parse it

			CString sCriteria = (pArg->GetCount() > 1 ? pArg->GetElement(1)->GetStringValue() : NULL_STR);
			if (sCriteria.IsBlank())
				return false;

			CAttributeCriteria Criteria;
			if (Criteria.Parse(sCriteria) != NOERROR)
				return false;

			//	Get a random location

			if (!pSystem->FindRandomLocation(Criteria, 0, NULL, &iLocID))
				return false;

			//	Return the position

			CLocationDef *pLoc = pSystem->GetLocation(iLocID);
			vPos = pLoc->GetOrbit().GetObjectPos();
			}

		//	Otherwise, we assume a vector

		else
			vPos = CreateVectorFromList(CC, pArg);
		}
	else
		{
		pObj = CreateObjFromItem(CC, pArg);
		if (pObj)
			vPos = pObj->GetPos();
		}

	//	Done

	if (retvPos)
		*retvPos = vPos;

	if (retpObj)
		*retpObj = pObj;

	if (retiLocID)
		*retiLocID = iLocID;

	return true;
	}