Esempio n. 1
0
int main(int argc, char **argv)
{
    if ( argc == 2 )
    {
        const char *filename = argv[1];
        xmlDoc *doc = NULL;
        xmlNode *root = NULL;
        // zaladowanie pliku
        if ( !filename )
        {
            GOC_ERROR("Podano wartosn NULL");
            return -1;
        }
        if ( !goc_isFileExists(filename) )
        {
            GOC_BERROR("Plik [%s] nie istnieje", filename);
            return -1;
        }

        doc = xmlReadFile( filename, NULL, 0 );
        if ( !doc )
        {
            GOC_BERROR("Nieudane parsowanie pliku [%s]", filename);
            return -1;
        }
        root = xmlDocGetRootElement( doc );
        if ( !root )
        {
            GOC_ERROR("Nieudane pozyskanie galezi root");
            return -1;
        }


        {
            StKlasa* k = fobDeserialize( (fobElement*)root );
            fobSerialize( (fobElement*)k, stdout );
        }
    }
    else
    {
        StKlasa* k = fobAlloc(cn_Klasa);
        k->name = goc_stringCopy(k->name, "Nazwa");
        k->plist = goc_tableAdd(k->plist, &k->nlist, sizeof(char*));
        k->plist[k->nlist-1] = goc_stringCopy(NULL, "alfa");
        k->plist = goc_tableAdd(k->plist, &k->nlist, sizeof(char*));
        k->plist[k->nlist-1] = goc_stringCopy(NULL, "beta");
        fobSerialize( (fobElement*)k, stdout );
    }
    return 0;
}
Esempio n. 2
0
int goc_listAddColumn(GOC_HANDLER u, GOC_POSITION width)
{
	GOC_POSITION free;
	GOC_COLUMN *kolumna;
	int i;
	GOC_StList *lista = (GOC_StList*)u;
	free = goc_elementGetWidth(u);
	free -= 2; /* ramka */
	for ( i=0; i<lista->nKolumna; i++ )
		free -= lista->pKolumna[i]->position;
	lista->pKolumna = goc_tableAdd( lista->pKolumna, &(lista->nKolumna), sizeof(GOC_COLUMN*) );
	kolumna = malloc(sizeof(GOC_COLUMN));
	memset(kolumna, 0, sizeof(GOC_COLUMN));
	lista->pKolumna[lista->nKolumna-1] = kolumna;
	kolumna->position = width <= free ? width : free;
	// Wyrowanie liczby wierszow w stosunku do istenijacych kolumn
	if ( lista->nKolumna > 1 )
	{
		kolumna->pText = goc_tableResize(kolumna->pText,
			&(kolumna->nText), sizeof(char*),
			lista->pKolumna[0]->nText);
		// Wyzerowanie wierszy
		if ( kolumna->pText )
			memset(kolumna->pText, 0,
				sizeof(char*)*kolumna->nText);
	}
//	lista->kursor = -1;
	return GOC_ERR_OK;
}
Esempio n. 3
0
int goc_barAddText(GOC_HANDLER uchwyt, const char *tekst)
{
	GOC_StBar* pasek = (GOC_StBar*)uchwyt;
	pasek->tekst = goc_tableAdd(pasek->tekst, &(pasek->nText), sizeof(char*));
	pasek->tekst[pasek->nText-1] = strdup(tekst);
	goc_systemSendMsg(uchwyt, GOC_MSG_PAINT, 0, 0);
	return GOC_ERR_OK;
}
Esempio n. 4
0
int main()
{
	GOC_Iterator *iterator = NULL;
	int *pTable = NULL;
	_GOC_TABEL_SIZETYPE_ nTable = 0;

	pTable = goc_tableAdd(pTable, &nTable, sizeof(int));
	pTable[nTable-1] = 1;
	pTable = goc_tableAdd(pTable, &nTable, sizeof(int));
	pTable[nTable-1] = 15;
	pTable = goc_tableAdd(pTable, &nTable, sizeof(int));
	pTable[nTable-1] = 21;
	pTable = goc_tableAdd(pTable, &nTable, sizeof(int));
	pTable[nTable-1] = 148;
	pTable = goc_tableAdd(pTable, &nTable, sizeof(int));
	pTable[nTable-1] = 419;
	pTable = goc_tableAdd(pTable, &nTable, sizeof(int));
	pTable[nTable-1] = 1439;

	iterator = goc_tableIteratorAlloc( (void*)pTable, nTable );
	while ( goc_iteratorHasNext( iterator ) )
	{
		int e = (int)goc_iteratorNext( iterator );
		printf("%d\n", e);
	}
	goc_tableIteratorFree( iterator );
	return 0;
}
Esempio n. 5
0
int goc_systemSetTimer(GOC_HANDLER uchwyt, const char *id)
{
	if ( nHandler == 0 )
	{
		// wystartuj czasomierz
		struct itimerval tv;
		struct sigaction sa;
		memset( &sa, 0, sizeof( struct sigaction ) );
		sa.sa_handler = &alarmTick;
		sigaction(SIGALRM, &sa, 0);
		memset( &tv, 0, sizeof( struct itimerval ) );
		tv.it_value.tv_usec = 100;
		tv.it_interval.tv_usec = milisec * 1000;
		setitimer(ITIMER_REAL, &tv, 0);
	}
	pHandler = goc_tableAdd(pHandler, &nHandler, sizeof(GOC_HANDLER));
	pHandler[nHandler-1] = uchwyt;
	nHandler--;
	pId = goc_tableAdd(pId, &nHandler, sizeof(char *));
	pId[nHandler-1] = goc_stringCopy(NULL, id);
	return GOC_ERR_OK;
}
Esempio n. 6
0
static int listAddText(GOC_HANDLER u, const char *buf)
{
	GOC_LISTROW wiersz;
	int retCode;
	memset( &wiersz, 0, sizeof(GOC_LISTROW) );
	wiersz.nRow = -1;
	wiersz.pText = goc_tableAdd(wiersz.pText, &wiersz.nText,
		sizeof(char *));
	wiersz.pText[wiersz.nText-1] = buf;
	retCode = goc_systemSendMsg(u, GOC_MSG_LISTADDROW, &wiersz, 0);
	wiersz.pText = goc_tableClear(wiersz.pText, &wiersz.nText);
	return retCode;
}
Esempio n. 7
0
int goc_labelAddLine(GOC_HANDLER u, const char *Tekst)
{
	GOC_StLabel *napis = (GOC_StLabel*)u;
	if ( !Tekst )
		return GOC_ERR_OK; // ??
	napis->tekst = goc_tableAdd(napis->tekst, &napis->nText, sizeof(GOC_StColorLine));
	napis->tekst[napis->nText-1].line = goc_stringCopy(NULL, Tekst);
	napis->tekst[napis->nText-1].color = napis->color;
	napis->tekst[napis->nText-1].flag = napis->flag;
	if ( napis->flag & GOC_EFLAGA_SHOWN )
		goc_systemSendMsg(u, GOC_MSG_PAINT, 0, 0);
	return GOC_ERR_OK;
}
Esempio n. 8
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);
}
Esempio n. 9
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;
}
Esempio n. 10
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);
    }
    */
}
Esempio n. 11
0
/*
 * Wykonuje przebieg poprzez kolejne linie i sprawdza otoczenie punktu,
 * probujac okreslic punkt, ktory postawi - tendencja opadajaca
 * Przebieg wykonywany jest podana liczbe razy
 */
void petlaGrow(GOC_HANDLER maska, int cnt)
{
    stChange **pZmiany = NULL;
    int nZmiany = 0;
    int i, j, k, v, n, t;

    // ustawienie poczatkowych punktow
    randomLandSeed(maska, 1);

    for ( i=0; i<cnt; i++ )
    {
        for ( j=0; j<context.configuration.maxx; j++ )
            for ( k=0; k<context.configuration.maxy; k++ )
            {
                fprintf(stderr, "[i,j,k]=[%d,%d,%d]\n",i,j,k);
                v = goc_maparawGetPoint(maska, j, k);
                if ( v == 0 )
                {
                    n = 0;
                    // sprawdz otoczenie
                    fprintf(stderr, "%s:%d\n", __FILE__, __LINE__);
                    if ( j != 39 )
                        t = goc_maparawGetPoint(maska, (j+1), k);
                    else
                        t = 0;
                    if ( t )
                    {
                        v += t;
                        n++;
                    }
                    fprintf(stderr, "%s:%d\n", __FILE__, __LINE__);
                    if ( j != 0 )
                        t = goc_maparawGetPoint(maska, (j-1), k);
                    else
                        t = 0;
                    if ( t )
                    {
                        v += t;
                        n++;
                    }
                    fprintf(stderr, "%s:%d\n", __FILE__, __LINE__);
                    if ( k != 22 )
                        t = goc_maparawGetPoint(maska, j, (k+1));
                    else
                        t = 0;
                    if ( t )
                    {
                        v += t;
                        n++;
                    }
                    fprintf(stderr, "%s:%d\n", __FILE__, __LINE__);
                    if ( k != 0 )
                        t = goc_maparawGetPoint(maska, j, (k-1));
                    else
                        t = 0;
                    if ( t )
                    {
                        v += t;
                        n++;
                    }
                    fprintf(stderr, "%s:%d\n", __FILE__, __LINE__);
                    if ( n )
                    {
                        // zgromadz zmiany
                        stChange *x = malloc(sizeof(stChange));
                        x->x = j;
                        x->y = k;
                        v /= n;
                        v--;
                        x->v = v;
                        pZmiany = goc_tableAdd(
                                      pZmiany,
                                      &nZmiany,
                                      sizeof(stChange*));
                        pZmiany[nZmiany-1] = x;
                    }
                }
            }
        // zastosuj zmiany
        for ( j = 0; j<nZmiany; j++ )
            goc_maparawSetPoint(maska, pZmiany[j]->x, pZmiany[j]->y,
                                pZmiany[j]->v);

        // czysc tablice zmian
        for ( j=0; j<nZmiany; j++ )
            free(pZmiany[j]);

        pZmiany = goc_tableClear(pZmiany, &nZmiany);

    }
}