LRESULT CStrategyView::OnAddStrategy(WPARAM wParam, LPARAM lParam)
{
	CStkUIApp	* pApp	=	AfxGetStkUIApp( );
	if( ! pApp )
		return -1;

	CTreeCtrl &treectrl = GetTreeCtrl();

	CString	strWorksp;
	VERIFY( strWorksp.LoadString( IDS_STRATEGYVIEW_STRATEGY ) );
	HTREEITEM hWorksp = treectrl.GetRootItem( );
	if( NULL == hWorksp )
		VERIFY( hWorksp = treectrl.InsertItem(strWorksp,IMG_WORKSP,IMG_WORKSP_SEL) );
	
	if( NULL == hWorksp )
		return -1;

	POSITION pos = pApp->GetFirstStrategyPosition();
	while( NULL != pos )
	{
		CStrategy * pCurStrategy = pApp->GetNextStrategy( pos );
		BOOL	bExist	=	FALSE;
		
		if( NULL == GetItemByStrategy( pCurStrategy ) )
		{
			HTREEITEM hStrategy = AddStrategy( pCurStrategy );
			ActivateStrategy( pCurStrategy, hStrategy );
		}
	}

	treectrl.Expand (hWorksp, TVE_EXPAND);

	return 0;
}
示例#2
0
CStrategy* CStkUIApp::OpenStrategyFile( LPCTSTR lpszPathName )
{
	// Resolve File Name
	TCHAR szPath[_MAX_PATH];
	ASSERT(lstrlen(lpszPathName) < sizeof(szPath));
	if( NULL != lpszPathName )
	{
		TCHAR szTemp[_MAX_PATH];
		if (lpszPathName[0] == '\"')
			++lpszPathName;
		lstrcpyn(szTemp, lpszPathName, _MAX_PATH);
		LPTSTR lpszLast = _tcsrchr(szTemp, '\"');
		if (lpszLast != NULL)
			*lpszLast = 0;
		AfxFullPath(szPath, szTemp);
		TCHAR szLinkName[_MAX_PATH];
		if (AfxResolveShortcut(AfxGetMainWnd(), szPath, szLinkName, _MAX_PATH))
			lstrcpy(szPath, szLinkName);
	}

	if( NULL != lpszPathName )
	{
		POSITION pos = GetFirstStrategyPosition();
		while (pos != NULL)
		{
			CStrategy* pStrategy = GetNextStrategy(pos);
			if( 0 == pStrategy->GetPathName().CompareNoCase( szPath ) )
			{
				if( m_bAutoUpdateViews )
				{
					::SendMessage( AfxGetStrategyView()->GetSafeHwnd(), WM_USER_ACTIVATESTRATEGY, DWORD(pStrategy), 0 );
					AfxGetStaticDoc()->UpdateAllViews( NULL, UPDATE_HINT_WIZARDVIEW, NULL );
					// AfxGetMainFrame()->ShowWorkspBar( );
				}
				return pStrategy;
			}
		}
	}

	CStrategy   * pStrategy = new CStrategy();
	if( NULL == pStrategy )
		return NULL;
	char	szErr[256];
	if( !pStrategy->OpenStrategyFile( szPath, szErr, sizeof(szErr)-1 ) )
	{
		AfxMessageBox( szErr, MB_OK|MB_ICONINFORMATION );
		delete	pStrategy;
		return NULL;
	}
	
	AddStrategy( pStrategy );
	return pStrategy;
}
示例#3
0
bool AIModule::Parse(TiXmlElement* xml)
{
    assert(xml);
    if (xml == 0)
        return false; // file could not be opened

    const char *str;	

    str = xml->Value();
    assert(strcmp(str,"AI")==0);
	
	str = xml->Attribute("attack_mode");
	if (str)
	{
		if (strcmp(str,"aliens")==0)
		{
			AttackMode = IAI::AM_ALIENS;
		} else
		if (strcmp(str,"friends")==0)
		{
			AttackMode = IAI::AM_FRIENDS;
		}
	}

    TiXmlElement *xml_element = 0;
    xml_element = xml->FirstChildElement("strategies");
    if (xml_element) 
    {				
        xml_element = xml_element->FirstChildElement("strategy");
        while (xml_element)
        {	
            AIStrategy *strategy=NULL;
            const char *classname = xml_element->Attribute("class");		
            if (strcmp("AIRayPathFinderStrategy",classname)==0) 
            {
                strategy = new AIRayPathFinderStrategy();					
            } else
                if (strcmp("AIRowFormationCommander",classname)==0) 
                {
                    strategy = new AIRowFormationCommander;														
                } else
                    if (strcmp("AILookStrategy",classname)==0) 
                    {
                        strategy = new AILookStrategy();											
					} else
						if (strcmp("AISightNAttackStrategy",classname)==0) 
						{
							strategy = new AISightNAttackStrategy();											
                        } else
                            if (strcmp("AIFlyNAttack1Strategy",classname)==0) 
                            {
                                strategy = new AIFlyNAttack1Strategy();											
                            } else
                                if (strcmp("AIBasicPathFinderStrategy",classname)==0) 
                                {
                                    strategy = new AIBasicPathFinderStrategy();											
								} else
									if (strcmp("AIAckerFormationCommander",classname)==0) 
									{
										strategy = new AIAckerFormationCommander();											
									} else
										if (strcmp("AIInConeAttackStrategy",classname)==0) 
										{
											strategy = new AIInConeAttackStrategy();											
										} else
											if (strcmp("AIAutoPilotStrategy",classname)==0) 
											{
												strategy = new AIAutoPilotStrategy();											
											}										
                                            										
                    assert(strategy);
                    AddStrategy(strategy);
                    strategy->Parse(xml_element);

                    xml_element = xml_element->NextSiblingElement("strategy");
        }			
    }

    //AIEngine::GetInstance()->RegisterObject(this);


    return false;
}