Пример #1
0
void maskaPrzypisz(GOC_HANDLER maska, int n)
{
	int i;
	int x, y;
	for (i=0; i<n; i++)
	{
		x = goc_random(10);
		y = goc_random(10);
		goc_maskSet(maska, x, y, 1);
	}
}
Пример #2
0
int main(int argc, char **argv)
{
	int min, max, count, tmp;
	int *stat;
	if ( argc < 4 )
	{
		printf("Usage: %s min max count\n", argv[0]);
		return 0;
	}
	srand(time(NULL));
	min = atoi(argv[1]);
	max = atoi(argv[2]);
	count = atoi(argv[3]);
	stat = malloc(sizeof(int)*(max-min));
	memset(stat, 0, sizeof(int)*(max-min));
	tmp = count;
	while ( tmp-- )
	{
		int los = goc_random(max);
		if ( los >= max )
			printf("GOC_ERROR: Random over max\n");
		stat[los]++;
	}
	for ( tmp=min; tmp<max; tmp++)
		printf("%04d: %05d\n", tmp, stat[tmp-min]);

	return 0;
}
Пример #3
0
stChange* randomLandMassStartPoint(
    int code,
    int *pAllowedCode,
    int nAllowedCode,
    int numOfTries)
{
    int x, y;
    int v;
    while ( numOfTries-- )
    {
        x = context.configuration.margines + goc_random(context.configuration.maxx + 1 - context.configuration.margines - context.configuration.margines);
        y = context.configuration.margines + goc_random(context.configuration.maxy + 1 - context.configuration.margines - context.configuration.margines);
        v = goc_maparawGetPoint(context.mapa, x, y);
        if ( isInCodeSet(v, pAllowedCode, nAllowedCode) )
            return mallocPoint(x, y, code);
    }
    return NULL;
}
Пример #4
0
// TODO: Random start point
// TODO: Generate around start point in selected radius with kind of gauss propability or
// kond of selected propability
static void rainGeneration(GOC_HANDLER mapa, int numStartPoints)
{
    int landMass = context.configuration.minLandMass + goc_random(context.configuration.maxLandMass-context.configuration.minLandMass);
    stChange point;
    point.x = 0;
    point.y = 0;
    point.v = 0;

    GOC_BINFO("Raind landmass %d", landMass);
    while ( landMass-- )
    {
        int x = point.x = goc_random(context.configuration.maxx);
        int y = point.y = goc_random(context.configuration.maxy);
        int v = goc_maparawGetPoint(mapa, point.x, point.y);
        if ( v >= 9 )
            continue;
        goc_maparawSetPoint(mapa, point.x, point.y, v+1);
    }
}
Пример #5
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);
}
Пример #6
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;
}
Пример #7
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);
    }
    */
}
Пример #8
0
// argument point has a pointer for input/output data of point
// argument type 1 random a point as neighbour of point
// argument type 0 random a point on a map
// argument minLevel tells a level of point on which we can set new point
// function check the level of random point - it's posiible to put there a point
// return 1 if positive random
// return 0 if negative random
int randomPoint(stChange* point, int type, int minLevel, GOC_HANDLER mapa)
{
    int safe;
    if ( type == 0 )
    {
        safe = 30;
        while ( safe-- )
        {
            int x = point->x = goc_random(context.configuration.maxx);
            int y = point->y = goc_random(context.configuration.maxy);
            if (( x < 0 + context.configuration.margines ) || ( x >= context.configuration.maxx - context.configuration.margines ))
                continue;
            if (( y < 0 + context.configuration.margines ) || ( y >= context.configuration.maxy - context.configuration.margines ))
                continue;
            if ( goc_maparawGetPoint(mapa, point->x, point->y) == minLevel )
            {
                int v;
                if ( x+1 < context.configuration.maxx )
                {
                    v = goc_maparawGetPoint(mapa, x+1, y);
                    if ( v < minLevel )
                        continue;
                }
                else if ( minLevel != 0 )
                    continue;
                if ( y+1 < context.configuration.maxy )
                {
                    v = goc_maparawGetPoint(mapa, x, y+1);
                    if ( v < minLevel )
                        continue;
                }
                else if ( minLevel != 0 )
                    continue;
                if ( y > 0 )
                {
                    v = goc_maparawGetPoint(mapa, x, y-1);
                    if ( v < minLevel )
                        continue;
                }
                else if ( minLevel != 0 )
                    continue;
                if ( x > 0 )
                {
                    v = goc_maparawGetPoint(mapa, x-1, y);
                    if ( v < minLevel )
                        continue;
                }
                else if ( minLevel != 0 )
                    continue;
                return 1;
            }
        }
    }
    else if ( type == 1 )
    {
        safe = 3;
        while ( safe-- )
        {
            // RANDOM ONLY in 4 base direction
            int r = goc_random(4);
            int x, y;
            switch ( r )
            {
            case 0:
                point->x++;
                break;
            case 1:
                point->x--;
                break;
            case 2:
                point->y++;
                break;
            case 3:
                point->y--;
                break;
            }
            x = point->x;
            y = point->y;
            // RANDOM in all 8 direction
            // int x = point->x = point->x + goc_random(3) - 1;
            // int y = point->y = point->y + goc_random(3) - 1;

            if (( point->x < 0 ) || ( point->x >= context.configuration.maxx ))
                continue;
            if (( point->y < 0 ) || ( point->y >= context.configuration.maxy ))
                continue;
            if ( goc_maparawGetPoint(mapa, point->x, point->y) == minLevel )
            {
                int v;
                if ( x+1 < context.configuration.maxx )
                {
                    v = goc_maparawGetPoint(mapa, x+1, y);
                    if ( v < minLevel )
                        continue;
                }
                else if ( minLevel != 0 )
                    continue;
                if ( y+1 < context.configuration.maxy )
                {
                    v = goc_maparawGetPoint(mapa, x, y+1);
                    if ( v < minLevel )
                        continue;
                }
                else if ( minLevel != 0 )
                    continue;
                if ( y > 0 )
                {
                    v = goc_maparawGetPoint(mapa, x, y-1);
                    if ( v < minLevel )
                        continue;
                }
                else if ( minLevel != 0 )
                    continue;
                if ( x > 0 )
                {
                    v = goc_maparawGetPoint(mapa, x-1, y);
                    if ( v < minLevel )
                        continue;
                }
                else if ( minLevel != 0 )
                    continue;
                return 1;
            }
        }
    }
    return 0;
}