Ejemplo n.º 1
0
 SetRel
 operator ||(const SetExpr& e0, const SetExpr& e1) {
   return SetRel(e0, SRT_DISJ, e1);
 }
bool CRelations::SetFromArgs(const idDict& args)
{
	idList<SEntryData> entries;
	idList<int> addedDiags;
	
	for (const idKeyValue* kv = args.MatchPrefix("rel ", NULL ); kv != NULL; kv = args.MatchPrefix("rel ", kv)) 
	{
		try
		{
			// Try to parse the entry, this will throw on errors
			SEntryData entry = ParseEntryData(kv);

			// Successfully parsed, add to list
			entries.Append(entry);

			// Will the current matrix dimension be increased by this entry?
			if (entry.row < m_RelMat.Dim() && entry.col < m_RelMat.Dim())
			{
				// No, matrix will not be extended, no need to check for 
				// diagonals and asymmetric values
				continue;
			}

			// The matrix will be extended by this entry, let's check for diagonals

			// Check for diagonal element of the ROW team
			if (args.FindKeyIndex( va("rel %d,%d", entry.row, entry.row) ) == -1 && 
				addedDiags.FindIndex(entry.row) == -1)
			{
				// ROW team diagonal not set, fill with default team relation entry
				SEntryData defaultDiagonal(entry.row, entry.row, s_DefaultSameTeamRel);
				entries.Append(defaultDiagonal);

				// Remember the diagonal number, so that we don't add it a second time
				addedDiags.Append(entry.row);

				DM_LOG(LC_AI, LT_DEBUG)LOGSTRING("Relmat Parser: Added missing diagonal %d, %d\r", entry.row, entry.row);
			}

			// Check for diagonal element of the COLUMN team
			if (args.FindKeyIndex( va("rel %d,%d", entry.col, entry.col) ) == -1 && 
				addedDiags.FindIndex(entry.col) == -1)
			{
				// COLUMN team diagonal not set, fill with default team relation entry
				SEntryData defaultDiagonal(entry.col, entry.col, s_DefaultSameTeamRel);
				entries.Append(defaultDiagonal);

				// Remember the diagonal number, so that we don't add it a second time
				addedDiags.Append(entry.col);

				DM_LOG(LC_AI, LT_DEBUG)LOGSTRING("Relmat Parser: Added missing diagonal %d, %d\r", entry.col, entry.col);
			}

			// Check for asymmetric element and append one with same value if
			// it is not set on this dictionary
			if (args.FindKeyIndex( va("rel %d,%d", entry.col, entry.row) ) == -1)
			{
				// Pass col as first arg, row as second to define the asymmetric value
				SEntryData asymmRel(entry.col, entry.row, entry.val);
				entries.Append(asymmRel);

				DM_LOG(LC_AI, LT_DEBUG)LOGSTRING("Relmat Parser: Added missing asymmetric element %d, %d\r", entry.row, entry.col );
			}
		}
		catch (std::runtime_error e)
		{
			gameLocal.Warning("Parse error: %s", e.what());
		}
	}

	// Commit the found values to the relations matrix
	for (int i = 0; i < entries.Num(); ++i)
	{
		const SEntryData& entry = entries[i];

		// Use the SetRel() method, which automatically takes care of initialising new teams
		SetRel(entry.row, entry.col, entry.val);
	}

	return true;
}
Ejemplo n.º 3
0
 SetRel
 operator !=(const SetExpr& e0, const SetExpr& e1) {
   return SetRel(e0, SRT_NQ, e1);
 }
void CRelations::ChangeRel( int i, int j, int offset)
{
	SetRel(i, j, GetRelNum(i, j) + offset);
}