IclusterIGC* CPigShip::FindCluster(BSTR bstrSector)
{
    if (!BSTRLen(bstrSector))
        return NULL;

    USES_CONVERSION;
    LPCSTR pszSector = OLE2CA(bstrSector);

    const ClusterListIGC* pClusters = GetIGC()->GetMission()->GetClusters();
    for (ClusterLinkIGC* it = pClusters->first(); it; it = it->next())
    {
        IclusterIGC* pCluster = it->data();
        if (0 == _stricmp(pCluster->GetName(), pszSector))
            return pCluster;
    }
    return NULL;
}
Beispiel #2
0
STDMETHODIMP CTaskbar7::ConfigureTab(BSTR name, LONG after)
{
	// Do nothing on XP & Vista
	if (!m_isWindows7)
		return S_OK;

	// If running anything other than a gadget, do nothing
	if (!m_parentHwnd)
		return S_OK;

	// Update name
	USES_CONVERSION;
	SetWindowText(m_hwnd, OLE2CA(name));

	RegisterTab();
	HRESULT hr = m_pTaskbarList->SetTabOrder(m_hwnd, (HWND)after);

	return hr;
}
Beispiel #3
0
HRESULT CPigEngine::put_ArtPath(BSTR bstrArtPath)
{
  // Open the registry key of the AppID
  CRegKey key;
  RETURN_FAILED(_Module.OpenAppIDRegKey(key));

  // Save the specified value
  USES_CONVERSION;
  _bstr_t bstrValue(bstrArtPath);
  long lr = key.SetValue(OLE2CT(bstrValue), TEXT("ArtPath"));
  if (ERROR_SUCCESS != lr)
    return HRESULT_FROM_WIN32(lr);

  // Set the art path in the Allegiance stuff
  //USES_CONVERSION;
  UTL::SetArtPath(OLE2CA(bstrValue));

  // Indicate success
  return S_OK;
}
ImodelIGC* CPigShip::FindModel(BSTR bstrModel)
{
    if (!BSTRLen(bstrModel))
        return NULL;

    USES_CONVERSION;
    LPCSTR pszModel = OLE2CA(bstrModel);

    const ClusterListIGC* pClusters = GetIGC()->GetMission()->GetClusters();
    for (ClusterLinkIGC* itCluster = pClusters->first(); itCluster; itCluster = itCluster->next())
    {
        IclusterIGC* pCluster = itCluster->data();
        const ModelListIGC* pModels = pCluster->GetModels();
        for (ModelLinkIGC* it = pModels->first(); it; it = it->next())
        {
            ImodelIGC* pModel = it->data();
            if (0 == _stricmp(GetModelName(pModel), pszModel))
                return pModel;
        }
    }

    return NULL;
}
// *****************************************************************
//			GenerateCategories()
// *****************************************************************
vector<CategoriesData>* FieldClassification::GenerateCategories(CString fieldName, FieldType fieldType, 
		vector<VARIANT*>& srcValues, tkClassificationType ClassificationType, 
		long numClasses, long& errorCode)
{
	CComVariant minValue, maxValue;
	minValue.vt = VT_EMPTY;
	maxValue.vt = VT_EMPTY;

	long numShapes = srcValues.size();

	/* we won't define intervals for string values */
	if (ClassificationType != ctUniqueValues && fieldType == STRING_FIELD)
	{
		errorCode = tkNOT_UNIQUE_CLASSIFICATION_FOR_STRINGS;
		return NULL;
	}

	if ((numClasses <= 0 || numClasses > 1000) && (ClassificationType != ctUniqueValues))
	{
		errorCode = tkTOO_MANY_CATEGORIES;
		return NULL;
	}

	if (ClassificationType == ctStandardDeviation)
	{
		errorCode = tkINVALID_PARAMETER_VALUE;
		return NULL;
	}

	// natural breaks aren't designed to work otherwise
	if (numShapes < numClasses && ClassificationType == ctNaturalBreaks)
	{
		numClasses = numShapes;
	}

	// values in specified range should be classified
	bool useRange = minValue.vt != VT_EMPTY && maxValue.vt != VT_EMPTY && fieldType == DOUBLE_FIELD;

	if (useRange) //fieldType == DOUBLE_FIELD)
	{
		double max, min;
		dVal(minValue, min);
		dVal(maxValue, max);
		minValue.vt = VT_R8;
		maxValue.vt = VT_R8;
		minValue.dblVal = min;
		maxValue.dblVal = max;
	}

	//bool useRange = minValue.vt == VT_R8 && maxValue.vt == VT_R8 && fieldType != STRING_FIELD;

	std::vector<CategoriesData>* result = new std::vector<CategoriesData>;
	if (ClassificationType == ctUniqueValues)
	{
		std::set<CComVariant> dict;
		CComVariant val;

		for (long i = 0; i < numShapes; i++)
		{
			VariantCopy(&val, srcValues[i]);
			if (useRange && (val.dblVal < minValue.dblVal || val.dblVal > maxValue.dblVal))
				continue;

			if (dict.find(val) == dict.end())
				dict.insert(val);
		}
		/* creating categories */
		std::vector<CComVariant> values;
		copy(dict.begin(), dict.end(), inserter(values, values.end()));

		for (int i = 0; i < (int)values.size(); i++)
		{
			CategoriesData data;
			data.minValue = values[i];
			data.maxValue = values[i];
			result->push_back(data);
		}
		dict.clear();
		values.clear();
	}
	else if (ClassificationType == ctEqualSumOfValues)
	{
		CComVariant val;

		// sorting the values
		std::vector<double> values;
		double totalSum = 0, dValue;
		for (int i = 0; i < numShapes; i++)
		{
			VariantCopy(&val, srcValues[i]);
			if (useRange && (val.dblVal < minValue.dblVal || val.dblVal > maxValue.dblVal))
				continue;

			dVal(val, dValue); val.Clear();
			values.push_back(dValue);
			totalSum += dValue;
		}
		sort(values.begin(), values.end());

		double step = totalSum / (double)numClasses;
		int index = 1;
		double sum = 0;

		for (int i = 0; i < (int)values.size(); i++)
		{
			sum += values[i];
			if (sum >= step * (double)index || i == numShapes - 1)
			{
				CategoriesData data;

				if (index == numClasses)
					data.maxValue = values[values.size() - 1];
				else if (i != 0)
					data.maxValue = (values[i] + values[i - 1]) / 2;
				else
					data.maxValue = values[0];

				if (index == 1)
					data.minValue = values[0];
				else
					data.minValue = (*result)[result->size() - 1].maxValue;

				result->push_back(data);
				index++;
			}
		}
	}
	else if (ClassificationType == ctEqualIntervals)
	{
		CComVariant vMin, vMax;

		if (useRange)
		{
			vMin = minValue;
			vMax = maxValue;
		}
		else
		{
			GetMinValue(srcValues, vMin, true);
			GetMinValue(srcValues, vMax, false);
		}

		double dMin, dMax;
		dVal(vMin, dMin); dVal(vMax, dMax);
		vMin.Clear(); vMax.Clear();

		/*	creating classes */
		double dStep = (dMax - dMin) / (double)numClasses;
		while (dMin < dMax)
		{
			CategoriesData data;
			data.minValue = dMin;
			data.maxValue = dMin + dStep;
			result->push_back(data);

			dMin += dStep;
		}
	}
	else if (ClassificationType == ctEqualCount)
	{
		CComVariant vMin, vMax;
		if (useRange)
		{
			vMin = minValue;
			vMax = maxValue;
		}
		else
		{
			GetMinValue(srcValues, vMin, true);
			GetMinValue(srcValues, vMax, false);
		}

		double dMin, dMax;
		dVal(vMin, dMin); dVal(vMax, dMax);
		vMin.Clear(); vMax.Clear();

		// sorting the values
		std::vector<double> values;
		for (int i = 0; i < numShapes; i++)
		{
			VariantCopy(&vMin, srcValues[i]);
			dVal(vMin, dMin); vMin.Clear();
			values.push_back(dMin);
		}
		sort(values.begin(), values.end());

		/*	creating classes */
		int i = 0;
		int count = numShapes / numClasses;

		for (int i = 0; i < numShapes; i += count)
		{
			dMin = values[i];
			if (i + count < numShapes)
				dMax = values[i + count];
			else
				dMax = values[numShapes - 1];

			CategoriesData data;
			data.minValue = dMin;
			data.maxValue = dMax;
			result->push_back(data);
		}
		values.clear();
	}
	else if (ClassificationType == ctNaturalBreaks)
	{
		CComVariant vMin; double dMin;
		// sorting the values
		std::vector<double> values;
		for (int i = 0; i < numShapes; i++)
		{
			VariantCopy(&vMin, srcValues[i]);

			if (useRange && (vMin.dblVal < minValue.dblVal || vMin.dblVal > maxValue.dblVal))
				continue;

			dVal(vMin, dMin); vMin.Clear();
			values.push_back(dMin);
		}
		sort(values.begin(), values.end());

		CJenksBreaks breaks(&values, numClasses);
		if (breaks.Initialized())
		{
			breaks.Optimize();
			std::vector<long>* startIndices = breaks.get_Results();
			//std::vector<int>* startIndices = breaks.TestIt(&values, numClasses);

			if (startIndices)
			{
				for (unsigned int i = 0; i < startIndices->size(); i++)
				{
					CategoriesData data;
					data.minValue = values[(*startIndices)[i]];
					if (i == startIndices->size() - 1)
						data.maxValue = values[values.size() - 1];
					else
						data.maxValue = values[(*startIndices)[i + 1]];

					result->push_back(data);
				}
				delete startIndices;
			}
		}
	}
	
	// TODO: implement this as well; then it can be used in table class
	//else if (ClassificationType == ctStandardDeviation)

	// ------------------------------------------------------
	//		generating text expressions
	// ------------------------------------------------------
	if (ClassificationType == ctUniqueValues)
	{
		USES_CONVERSION;
		for (int i = 0; i < (int)result->size(); i++)
		{
			//CString strExpression;
			CString strValue;
			CComVariant* val = &(*result)[i].minValue;
			switch (val->vt)
			{
				case VT_BSTR:
					strValue = OLE2CA(val->bstrVal);
					(*result)[i].name = strValue;
					(*result)[i].expression = "[" + fieldName + "] = \"" + strValue + "\"";
					break;
				case VT_R8:
					strValue.Format("%g", val->dblVal);
					(*result)[i].name = strValue;
					(*result)[i].expression = "[" + fieldName + "] = " + strValue;
					break;
				case VT_I4:
					strValue.Format("%i", val->lVal);
					(*result)[i].name = strValue;
					(*result)[i].expression = "[" + fieldName + "] = " + strValue;
					break;
			}
		}
	}
	else //if (ClassificationType == ctEqualIntervals || ClassificationType == ctEqualCount)
	{
		// in case % is present, we need to put to double it for proper formatting
		fieldName.Replace("%", "%%");

		for (int i = 0; i < (int)result->size(); i++)
		{
			CategoriesData* data = &((*result)[i]);

			CString strExpression, strName, sFormat;

			if (i == 0)
			{
				data->minValue.dblVal = floor(data->minValue.dblVal);
			}
			else if (i == result->size() - 1)
			{
				data->maxValue.dblVal = ceil(data->maxValue.dblVal);
			}

			CString upperBound = (i == result->size() - 1) ? "<=" : "<";

			switch (data->minValue.vt)
			{
				case VT_R8:
					sFormat = "%g";
					data->name = Utility::FormatNumber(data->minValue.dblVal, sFormat) + " - " + Utility::FormatNumber(data->maxValue.dblVal, sFormat);
					data->expression.Format("[" + fieldName + "] >= %f AND [" + fieldName + "] " + upperBound + " %f", data->minValue.dblVal, data->maxValue.dblVal);
					break;
				case VT_I4:
					sFormat = "%i";
					data->name = Utility::FormatNumber(data->minValue.dblVal, sFormat) + " - " + Utility::FormatNumber(data->maxValue.dblVal, sFormat);
					data->expression.Format("[" + fieldName + "] >= %i AND [" + fieldName + "] " + upperBound + " %i", data->minValue.lVal, data->maxValue.lVal);
					break;
			}
		}
	}

	if (result->size() > 0)
	{
		return result;
	}
	else
	{
		delete result;
		return NULL;
	}
}
/*-------------------------------------------------------------------------
 * CAdminGames::Add()
 *-------------------------------------------------------------------------
 * Purpose:
 *   Add to the collection of Games
 *
 * Parameters:
 *   pGameParameters: a pointer to a CGameParameters interface.
 *                        This houses the mission params.
 *
 */
	STDMETHODIMP CAdminGames::Add(IAGCGameParameters* pGameParameters)
{
	if (!pGameParameters)
		return Error("Creation Parameters was Null");

	// Cannot create a game on a paused server
	if (!g.strLobbyServer.IsEmpty() && !g.fmLobby.IsConnected())
		return Error(IDS_E_GAME_SERVER_PAUSED, IID_IAdminGames);

	IAGCPrivatePtr spPrivate(pGameParameters);
	assert(NULL != spPrivate);

	CGameParamData * pMissionParams = (CGameParamData *)spPrivate->GetIGCVoid();
	assert(pMissionParams);

#if defined(ALLSRV_STANDALONE)
	// Standalone server only supports a single game
	const ListFSMission * plistMission = CFSMission::GetMissions();
	if (plistMission->n())
		return Error(IDS_E_ONE_GAME_PER_SERVER, IID_IAdminGames);

	// Standalone server only support a maximum of c_cMaxPlayersPerGame players total
	if (pMissionParams->nTotalMaxPlayersPerGame > c_cMaxPlayersPerGame)
		pMissionParams->nTotalMaxPlayersPerGame = c_cMaxPlayersPerGame;

	// Standalone games always have a min players per team of 1 and max 
	// players per team of maxPlayerPerGame / nTeams.
	// XXX Note that the training mission #7 uses the server with a
	// XXX nTotalMaxPlayers setting of 1, and we need to handle that.
	pMissionParams->nMinPlayersPerTeam = 1;
	if (pMissionParams->nTotalMaxPlayersPerGame == 1)
		pMissionParams->nMaxPlayersPerTeam = 1;
	else
		pMissionParams->nMaxPlayersPerTeam = pMissionParams->nTotalMaxPlayersPerGame / pMissionParams->nTeams;
#else
	// The maximum players per side must be no more than max per game / nTeams
	if (pMissionParams->nMaxPlayersPerTeam > pMissionParams->nTotalMaxPlayersPerGame / pMissionParams->nTeams)
		pMissionParams->nMaxPlayersPerTeam = pMissionParams->nTotalMaxPlayersPerGame / pMissionParams->nTeams;
	if (pMissionParams->nMinPlayersPerTeam > pMissionParams->nMaxPlayersPerTeam)
		pMissionParams->nMinPlayersPerTeam = pMissionParams->nMaxPlayersPerTeam;
#endif // defined(ALLSRV_STANDALONE)

	// make sure params are valid, if not tell user why
	const char * szInvalid = pMissionParams->Invalid();
	if (szInvalid)
		return Error(szInvalid);

	// Creation through this method always indicates object model created
	// KGJV : hack fix for AllSrvUI created game
	// since bObjectModelCreated isnt exposed thru the AGC interface we use bAllowEmptyTeams
	// so if bAllowEmptyTeams, game will be like a player created game
	pMissionParams->bObjectModelCreated = !pMissionParams->bAllowEmptyTeams;

	// Get the story text of the specified AGCGameParameters object
	CComBSTR bstrStoryText;
	RETURN_FAILED(pGameParameters->get_StoryText(&bstrStoryText));
	USES_CONVERSION;
	const char* pszStoryText = bstrStoryText.Length() ? OLE2CA(bstrStoryText) : NULL;

	//
	// Create a new mission first
	//
	FedSrvSite * psiteFedSrv = new FedSrvSite();
	CFSMission * pfsMissionNew = new CFSMission(*pMissionParams,
		NULL, // NULL means use description in the params
		psiteFedSrv,
		psiteFedSrv,
		pMissionParams,
		pszStoryText);
	if (g.fmLobby.IsConnected())
	{
		BEGIN_PFM_CREATE(g.fmLobby, pfmNewMission, S, NEW_MISSION)
			END_PFM_CREATE
			pfmNewMission->dwIGCMissionID = pfsMissionNew->GetIGCMission()->GetMissionID();

		g.fmLobby.SendMessages(g.fmLobby.GetServerConnection(), FM_GUARANTEED, FM_FLUSH);
	}
	return S_OK;
}