Example #1
0
    bool TColorMatch::findNodeMatch(int nodeX,int nodeY,int* out_x0,int* out_y0,frg_TMatchType* out_matchType)const{
        const TUInt32 keyValue=m_nodeKeys[nodeY*m_nodeWidth+nodeX];

        std::pair<TMatchMap::const_iterator,TMatchMap::const_iterator> itPair(m_matchMap.equal_range(keyValue));
        TMatchMap::const_iterator it(itPair.first);
        TMatchMap::const_iterator itEnd(itPair.second);
        if (it==itEnd) return false;

        const int subX0=nodeX*kFrg_ClipWidth;
        const int subY0=nodeY*kFrg_ClipHeight;
        bool isFindedMatch=false;
        int bestX0=-1;
        int bestY0=-1;
        frg_TMatchType best_matchType;
        for (;it!=itEnd;++it){
            int cur_x0=unpackMatchX(it->second);
            int cur_y0=unpackMatchY(it->second);
            frg_TMatchType cur_matchType;
            bool cur_isMatched=isMatchAt(subX0,subY0,kFrg_ClipWidth,kFrg_ClipHeight,cur_x0,cur_y0,&cur_matchType);
            if (cur_isMatched){
                isFindedMatch=true;
                bestX0=cur_x0;
                bestY0=cur_y0;
                best_matchType=cur_matchType;
                break;// ok finded one; 也可以继续寻找某种标准下更好的匹配,但可能会慢些.
            }
        }
        if (isFindedMatch){
            *out_x0=bestX0;
            *out_y0=bestY0;
            *out_matchType=best_matchType;
        }
        return isFindedMatch;
    }
void cUnitManager::UnitFinished(int unit,UnitInfo *U)
{
//	*l<<" (t="<<U->pBOL->task<<")";
	switch( U->pBOL->task )
	{
	case TASK_CONSTRUCT:
		G->Build->UBuilderFinished(unit,U);
		break;
	case TASK_ASSAULT:
		{
			UAssault.insert(cRAI::iupPair(unit,U));
			UpdateGroupSize();
			Assign(unit,U);
			if( ActiveAttackOrders() )
				SendAttackGroups();
		}
		break;
	case TASK_SCOUT:
		{
			UScout.insert(isPair(unit,sScoutUnitInfo()));
		}
		break;
	case TASK_SUICIDE:
		{
			USuicide.insert(cRAI::iupPair(unit,U));
		}
		break;
	case TASK_SUPPORT:
		{
			USupport.insert(unit);
		}
		break;
	case TASK_TRANSPORT:
		{
			UTrans.insert(itPair(unit,sTransportUnitInfo(U->ud)));
		}
		break;
	}
}