map.c
author viric@llimona
Sat, 17 Feb 2007 15:14:30 +0100
changeset 28 cd27cb410375
parent 26 95fccfcbd04c
permissions -rw-r--r--
Recursivity changed into a loop. Now the state is loaded on boot, and saved on TERM.
#include <stdio.h>
#include <stdio.h>
#include <string.h>
#include "general.h"

void CopyMap (struct Map *Mdest, const struct Map *Morig)
{
	memcpy((void *) Mdest, (void *) Morig, sizeof (struct Map));
}

static int are_boxes_equal(const struct Position b1[], const struct Position b2[],
	int n)
{
	int i;
	char tmp[MAX_Y][MAX_X]; /* !!!argh */

	for (i=0; i < n; i++)
	{
		tmp[b2[i].y][b2[i].x] = 0;
	}
	for (i=0; i < n; i++)
	{
		tmp[b1[i].y][b1[i].x] = 1;
	}
	for (i=0; i < n; i++)
	{
		if (tmp[b2[i].y][b2[i].x] != 1)
			return FALSE;
	}
	return TRUE;
}

int is_new_map(const struct Map maps[], const int depth)
{
	const struct Map *m = &maps[depth];
	int i;
	extern int max_depth; 

	for(i=0; i<max_depth; i++)
	{
		/* No l'hem de comparar amb ell mateix */
		if (i == depth)
			continue;

		if (m->NumBoxesInPlatform != maps[i].NumBoxesInPlatform)
			continue;
		else
		{
			if (!are_boxes_equal(m->Box, maps[i].Box, m->NumBoxes))
				continue;
		}
		return FALSE;
	}
	return TRUE;
}