map.c
author viric@mandarina
Sat, 06 May 2006 13:24:06 +0200
changeset 9 622136ed6c62
parent 8 b41a580b3abe
child 10 9148590f009d
permissions -rw-r--r--
Added description to general.h, from where the prototypes come from.

#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 */

	memset(tmp, 0, sizeof(tmp));

	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(struct Map maps[], int depth)
{
	struct Map *m;
	int i;
	extern int max_depth;

	m = &maps[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;
}