Ejemplo n.º 1
0
int goc_systemFreeTimer(GOC_HANDLER uchwyt)
{
	int i;
	for ( i=0; i<nHandler; i++ )
	{
		if ( pHandler[i] == uchwyt )
		{
			pHandler = goc_tableRemove(
				pHandler, &nHandler, sizeof(GOC_HANDLER), i);
			nHandler++;
			pId[i] = goc_stringFree(pId[i]);
			pId = goc_tableRemove(
				pId, &nHandler, sizeof(char *), i);
			return GOC_ERR_OK;
		}
	}
	return GOC_ERR_END;
}
Ejemplo n.º 2
0
int goc_labelRemLine(GOC_HANDLER u, unsigned int numer)
{
	GOC_StLabel *napis = (GOC_StLabel*)u;
	
	if ( numer < napis->nText )
  	{
		goc_stringFree(napis->tekst[numer].line);
		napis->tekst = goc_tableRemove(napis->tekst, &napis->nText, sizeof(GOC_StColorLine), numer);
	}
	return GOC_ERR_OK;
}
Ejemplo n.º 3
0
static void generateLandMass(
	int code, // genrowany kod
	int *pAllowedCode, // dozwolona tablica kodow do zjadania
	int nAllowedCode)
{
	stChange** pBiomeSet = NULL;
	int nBiomeSet = 0;
	int landMass = context->configuration.minLandMass + goc_random(context->configuration.maxLandMass-context->configuration.minLandMass);
	stChange* point = NULL;
	GOC_BINFO("Generate land %d with landmass size %d", code, landMass);
	point = randomLandMassStartPoint(code, pAllowedCode, nAllowedCode, 20);
	if ( point == NULL )
	{
		GOC_INFO("Start point of landmass not found");
		return;
	}
	pBiomeSet = goc_tableAdd(pBiomeSet, &nBiomeSet, sizeof(void*));
	pBiomeSet[nBiomeSet-1] = point;
	goc_maparawSetPoint(context->mapa, point->x, point->y, point->v);
	while ( landMass )
	{
		if ( ! nBiomeSet )
		{
			break;
		}
		int r = goc_random(nBiomeSet);
		point = pBiomeSet[r];
		int x = point->x;
		int y = point->y;
		// czy ma zginac - TODO: MARGIN
		if (
			( (x+1 >= context->configuration.maxx) || (!isInCodeSet(goc_maparawGetPoint(context->mapa, x+1, y), pAllowedCode, nAllowedCode)) ) &&
			( (y+1 >= context->configuration.maxy) || (!isInCodeSet(goc_maparawGetPoint(context->mapa, x, y+1), pAllowedCode, nAllowedCode)) ) &&
			( (y-1 <= 0) || (!isInCodeSet(goc_maparawGetPoint(context->mapa, x, y-1), pAllowedCode, nAllowedCode)) ) &&
			( (x-1 <= 0) || (!isInCodeSet(goc_maparawGetPoint(context->mapa, x-1, y), pAllowedCode, nAllowedCode)) )
		)
		{
			free(pBiomeSet[r]);
			pBiomeSet = goc_tableRemove(pBiomeSet, &nBiomeSet, sizeof(void*), r);
			continue;
		}
		// znajdz, jakie miejsce moze zarazic
		{
			// RANDOM ONLY in 4 base direction
			int r = goc_random(4);
			switch ( r )
			{
				case 0:
					x++;
					break;
				case 1:
					x--;
					break;
				case 2:
					y++;
					break;
				case 3:
					y--;
					break;
			}
		}
		// wykluczenie
		if (( x >= context->configuration.maxx ) || ( y >= context->configuration.maxy ) || ( x < 0 ) || ( y < 0 ))
		{
			continue;
		}
		if ( !isInCodeSet( goc_maparawGetPoint(context->mapa, x, y), pAllowedCode, nAllowedCode) )
		{
			continue;
		}
		// wykonaj zarazenie
		{
			stChange* newpoint = mallocPoint(x, y, point->v);
			pBiomeSet = goc_tableAdd(pBiomeSet, &nBiomeSet, sizeof(void*));
			pBiomeSet[nBiomeSet-1] = newpoint;
			goc_maparawSetPoint(context->mapa, x, y, point->v);
			landMass--;
			// goc_maskPaintPoint(maska, x, y); // TODO: metoda paintAreaPoint, do rysowania punktu wskazanego z danych
		}
	}
	pBiomeSet = goc_tableClear(pBiomeSet, &nBiomeSet);
}
Ejemplo n.º 4
0
static int hotkeyNextTurnBactery(
    GOC_HANDLER u, GOC_MSG m, void* pBuf, unsigned int nBuf)
{
    int randomAtOneTurn = 100;
    int nKill = 0;
    int nBurn = 0;
    int nInvade = 0;
    GOC_BINFO("Turn %d - randoms(%d)", nBiomeTurn, randomAtOneTurn);
    nBiomeTurn++;
    while ( randomAtOneTurn-- )
    {
        if ( ! nBiomeSet )
        {
            break;
        }
        int r = goc_random(nBiomeSet);
        stChange* point = pBiomeSet[r];
        int x = point->x;
        int y = point->y;
        // czy ma zginac
        if (
            ( (x+1 >= context.configuration.maxx) || (goc_maparawGetPoint(context.mapa, x+1, y) != 0) ) &&
            ( (y+1 >= context.configuration.maxy) || (goc_maparawGetPoint(context.mapa, x, y+1) != 0 )) &&
            ( (y-1 <= 0) || (goc_maparawGetPoint(context.mapa, x, y-1) != 0) ) &&
            ( (x-1 <= 0) || (goc_maparawGetPoint(context.mapa, x-1, y) != 0) )
        )
        {
            nKill++;
            free(pBiomeSet[r]);
            pBiomeSet = goc_tableRemove(pBiomeSet, &nBiomeSet, sizeof(void*), r);
            continue;
        }
        // znajdz, jakie miejsce moze zarazic
        {
            // RANDOM ONLY in 4 base direction
            int r = goc_random(4);
            switch ( r )
            {
            case 0:
                x++;
                break;
            case 1:
                x--;
                break;
            case 2:
                y++;
                break;
            case 3:
                y--;
                break;
            }
        }
        // wykluczenie
        if (( x >= context.configuration.maxx ) || ( y >= context.configuration.maxy ) || ( x < 0 ) || ( y < 0 ))
        {
            nBurn++;
            continue;
        }
        if ( goc_maparawGetPoint(context.mapa, x, y) != 0 )
        {
            nBurn++;
            continue;
        }
        // wykonaj zarazenie
        {
            nInvade++;
            stChange* newpoint = mallocPoint(x, y, point->v);
            pBiomeSet = goc_tableAdd(pBiomeSet, &nBiomeSet, sizeof(void*));
            pBiomeSet[nBiomeSet-1] = newpoint;
            goc_maparawSetPoint(context.mapa, x, y, point->v);
            // goc_maskPaintPoint(maska, x, y); // TODO: metoda paintAreaPoint, do rysowania punktu wskazanego z danych
        }
    }
    GOC_BINFO("Dies: %3d Burns: %3d Invades: %3d", nKill, nBurn, nInvade);
    goc_systemSendMsg(context.mapa, GOC_MSG_PAINT, 0, 0);
    return GOC_ERR_OK;
}
Ejemplo n.º 5
0
// TODO : random landMass from min to max
// TODO : putting next landMass level for height
static void civGeneration(GOC_HANDLER mapa, int numStartPoints, int minLM, int maxLM, int MINLEVEL, int NEWLEVEL)
{
//	int MINLEVEL=0;
//	int NEWLEVEL=1;
    int type = 0;
    stChange point;
    point.x = 0;
    point.y = 0;
    point.v = 0;
    stChange** pSet = NULL;
    int nSet = 0;
    int landMass;
    int svStartPoints = numStartPoints;
    int createdLandMass;

    GOC_BINFO("Start civ generation system [numStartPoint: %d, minLandMass: %d, maxLandMass: %d, level: %d]", numStartPoints, minLM, maxLM, NEWLEVEL);

    if ( MINLEVEL >= 10 )
        return;
    if ( numStartPoints <= 0 )
        return;
    if ( maxLM <= 0 )
        return;


    while (numStartPoints--)
    {
        GOC_BDEBUG("Number of start points %d", numStartPoints);
        // inicjowanie do kolejnej iteracji tworzenia masy ladowej
        type = 0;
        landMass = minLM + goc_random(maxLM-minLM);
        createdLandMass = 0;
        GOC_BINFO("Generated landmass: %d", landMass);
        if ( nSet )
        {
            GOC_DEBUG("Clear set");
            int i;
            for ( i=0; i<nSet; i++ )
                free(pSet[i]);
            pSet = goc_tableClear(pSet, &nSet);
        }
        while ( landMass )
        {
            GOC_BDEBUG("Landmass to generate %d", landMass);
            // random new point
            if ( randomPoint(&point, type, MINLEVEL, mapa) )
            {
                GOC_BDEBUG("Setting a point (%d,%d,%d)", point.x, point.y, NEWLEVEL);
                pSet = goc_tableAdd(pSet, &nSet, sizeof(void*));
                pSet[nSet-1] = mallocPoint(point.x, point.y, NEWLEVEL);
                goc_maparawSetPoint(mapa, point.x, point.y, NEWLEVEL);
                createdLandMass++;
            }
            landMass--;
            while ( nSet )
            {
                // random point from set
                int randp = goc_random(nSet);
                int x, y;
                type = 1; // neighbour
                // check a point has any free neighbour
                x = pSet[randp]->x;
                y = pSet[randp]->y;
                if (
                    ( (x+1 < context.configuration.maxx) && (goc_maparawGetPoint(mapa, x+1, y) <= MINLEVEL) ) ||
                    ( (y+1 < context.configuration.maxy) && (goc_maparawGetPoint(mapa, x, y+1) <= MINLEVEL )) ||
                    ( (y > 0) && (goc_maparawGetPoint(mapa, x, y-1) <= MINLEVEL) ) ||
                    ( (x > 0) && (goc_maparawGetPoint(mapa, x-1, y) <= MINLEVEL) )
                )
                {
                    point.x = x;
                    point.y = y;
                    point.v = pSet[randp]->v;
                    GOC_BDEBUG("Find point in set (%d,%d,%d)", point.x, point.y, point.v);
                    break;
                }
                else
                {
                    GOC_DEBUG("Remove point from set");
                    free(pSet[randp]);
                    pSet = goc_tableRemove(pSet, &nSet, sizeof(void*), randp);
                }
            }
            // check, if there are any points in set
            if ( !nSet )
                break;
        }
        GOC_BINFO("Created landmass: %d", createdLandMass);
    }
    civGeneration(
        mapa,
        svStartPoints, //-svStartPoints/20,
        minLM-minLM*precentageCut[MINLEVEL]/10,
        maxLM-maxLM*precentageCut[MINLEVEL]/10,
        MINLEVEL+1,
        NEWLEVEL+1);
    /*
    pStartPoint = randomStartPoints(&nStartPoint, numStartPoints);
    for (i=0; i<nStartPoint; i++)
    {
    	goc_maparawSetPoint(mapa, pStartPoint[i]->x, pStartPoint[i]->y, 1);
    }
    */
}