Ejemplo n.º 1
0
//------------------------------------------------------------------------------
inline bool parse( CLinkList<Chunk>& chunklist, const char* data, const int size )
{
    if ( !data )
    {
        return false;
    }

    chunklist.clear();
    Chunk* chunk = 0;

    int pos = 0;
    char buf[5];

    while( pos < size )
    {
        for( ; data[pos] != ':' && pos < size; pos++ );
        if ( pos >= size )
        {
            printf( "':' unfound\n" );
            break;
        }
        pos++;

        if ( (size - pos) < 10 )
        {
            printf( "size - pos = %d\n", size - pos );
            break;
        }

        buf[0] = data[pos++];
        buf[1] = data[pos++];
        buf[2] = 0;
        int byteCount = strtol( buf, 0, 16 );

        buf[0] = data[pos++];
        buf[1] = data[pos++];
        buf[2] = data[pos++];
        buf[3] = data[pos++];
        buf[4] = 0;
        int offsetAddress = strtol( buf, 0, 16 );

        buf[0] = data[pos++];
        buf[1] = data[pos++];
        buf[2] = 0;
        int recordType = strtol( buf, 0, 16 );


        switch( recordType )
        {
        case 0:
        {
            if ( !chunk )
            {
                chunk = chunklist.add();
                chunk->addressBase = offsetAddress;
                memset( chunk->data, 0, sizeof(chunk->data) );
                chunk->size = 0;
            }

            buf[2] = 0;

            for( int i=0; i<byteCount; i++ )
            {
                if ( !(buf[0] = data[pos++]) || !(buf[1] = data[pos++]) )
                {
                    goto parse_fail;
                }

                unsigned int offset = (offsetAddress + i) - chunk->addressBase;
                if ( offset >= chunk->size )
                {
                    chunk->size = offset + 1;
                }
                chunk->data[offset] = (char)strtol( buf, 0, 16 );

//					printf( "[%d/%d/%d %02X]", i, byteCount, offset, (unsigned char)chunk->data[offset] );
            }

//				printf( "\n" );

            break;
        }

        case 1:
        {
            return true; // reached EOF, only legal exit point
        }

        case 2:
        case 3:
        case 4:
        case 5:
        {
            printf( "unhandled record type [%d]\n", recordType );
            break;
        }

        default:
        {
            printf( "unrecognized record type [%d]\n", recordType );
            goto parse_fail;
        }
        }
    }

parse_fail:
    chunklist.clear();
    return false;
}
Ejemplo n.º 2
0
void CvPlotGroup::recalculatePlots()
{
	PROFILE_FUNC();

	CLLNode<XYCoords>* pPlotNode;
	CvPlot* pPlot;
	CLinkList<XYCoords> oldPlotGroup;
	XYCoords xy;
	PlayerTypes eOwner;
	int iCount;

	eOwner = getOwnerINLINE();

	pPlotNode = headPlotsNode();

	if (pPlotNode != NULL)
	{
		pPlot = GC.getMapINLINE().plotSorenINLINE(pPlotNode->m_data.iX, pPlotNode->m_data.iY);

		iCount = 0;

		gDLL->getFAStarIFace()->SetData(&GC.getPlotGroupFinder(), &iCount);
		gDLL->getFAStarIFace()->GeneratePath(&GC.getPlotGroupFinder(), pPlot->getX_INLINE(), pPlot->getY_INLINE(), -1, -1, false, eOwner);

		if (iCount == getLengthPlots())
		{
			return;
		}
	}

	oldPlotGroup.clear();

	pPlotNode = headPlotsNode();

	while (pPlotNode != NULL)
	{
		pPlot = GC.getMapINLINE().plotSorenINLINE(pPlotNode->m_data.iX, pPlotNode->m_data.iY);

		FAssertMsg(pPlot != NULL, "Plot is not assigned a valid value");

		xy.iX = pPlot->getX_INLINE();
		xy.iY = pPlot->getY_INLINE();

		oldPlotGroup.insertAtEnd(xy);

		pPlot->setPlotGroup(eOwner, NULL);

		pPlotNode = deletePlotsNode(pPlotNode); // will delete this PlotGroup...
	}

	pPlotNode = oldPlotGroup.head();

	while (pPlotNode != NULL)
	{
		pPlot = GC.getMapINLINE().plotSorenINLINE(pPlotNode->m_data.iX, pPlotNode->m_data.iY);

		FAssertMsg(pPlot != NULL, "Plot is not assigned a valid value");

		pPlot->updatePlotGroup(eOwner, true);

		pPlotNode = oldPlotGroup.deleteNode(pPlotNode);
	}
}