Ejemplo n.º 1
0
int CTopologyNode::CalcMatchStrength (const CAttributeCriteria &Criteria)

//	CalcMatchStrength
//
//	Calculates the match strength of topology node and the criteria.

	{
	int i;

	int iStrength = 1000;
	for (i = 0; i < Criteria.GetCount(); i++)
		{
		DWORD dwMatchStrength;
		bool bIsSpecial;
		const CString &sAttrib = Criteria.GetAttribAndWeight(i, &dwMatchStrength, &bIsSpecial);

		bool bHasAttrib = (bIsSpecial ? HasSpecialAttribute(sAttrib) : HasAttribute(sAttrib));
		int iAdj = CAttributeCriteria::CalcWeightAdj(bHasAttrib, dwMatchStrength);

		iStrength = iStrength * iAdj / 1000;
		}

	return iStrength;
	}
Ejemplo n.º 2
0
void CSystemCreateStats::AddFillLocationsTable (CSystem *pSystem, const TProbabilityTable<int> &LocationTable, const CString &sStationCriteria)

//	AddFillLocationsTable
//
//	Adds stats about <FillLocations>

	{
	int i, j;

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

	SFillLocationsTable *pEntry = m_FillLocationsTables.Insert();
	pEntry->iLevel = pSystem->GetLevel();
	pEntry->sSystemName = pSystem->GetName();
	pEntry->pSystemType = pSystem->GetType();
	pEntry->sStationCriteria = sStationCriteria;

	//	Parse station criteria if we've got it.
	//	NOTE: For now we only do enemies.

	CString sEnemyStationCriteria = strPatternSubst(CONSTLIT("%s,%s"), sStationCriteria, CONSTLIT("*enemy"));
	CAttributeCriteria StationCriteria;
	StationCriteria.Parse(sEnemyStationCriteria, 0);

	//	Start by generating a base probability for all station encounters 
	//	relative to the system.

	TProbabilityTable<CStationType *> BaseProb;
	for (i = 0; i < g_pUniverse->GetStationTypeCount(); i++)
		{
		CStationType *pType = g_pUniverse->GetStationType(i);
		int iBaseChance = StationCriteria.AdjStationWeight(pType, ((1000 / ftCommon) * pType->GetFrequencyForSystem(pSystem)));
		if (iBaseChance > 0)
			{
			CAttributeCriteria LocationCriteria;
			LocationCriteria.Parse(pType->GetLocationCriteria(), 0);

			//	Average out our chance of ending up at one of the given locations.

			int iTotal = 0;
			for (j = 0; j < LocationTable.GetCount(); j++)
				{
				int iLocID = LocationTable[j];
				CLocationDef *pLoc = pSystem->GetLocation(iLocID);

				iTotal += LocationCriteria.AdjLocationWeight(pSystem, pLoc);
				}

			int iAverageChance = iTotal / LocationTable.GetCount();

			//	Now adjust the base chance

			int iChance = iBaseChance * iAverageChance / 1000;
			if (iChance <= 0)
				continue;

			//	Add it to our table.

			pEntry->Table.Insert(pType, iChance);
			}
		}
	}
Ejemplo n.º 3
0
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;
	}