map.c
author viric@llimona
Sun, 07 May 2006 13:34:25 +0200
changeset 25 b37843173279
parent 10 9148590f009d
child 26 95fccfcbd04c
permissions -rw-r--r--
Porting from sokoban/caixes the show_map changes.
Corrects possible sigsegv because of actual_map.
Better separation of sigalarm display / not-signal display.
viric@4
     1
#include <stdio.h>
viric@4
     2
#include <stdio.h>
viric@4
     3
#include <string.h>
viric@4
     4
#include "general.h"
viric@4
     5
viric@4
     6
void CopyMap (struct Map *Mdest, const struct Map *Morig)
viric@4
     7
{
viric@4
     8
	memcpy((void *) Mdest, (void *) Morig, sizeof (struct Map));
viric@4
     9
}
viric@4
    10
viric@8
    11
static int are_boxes_equal(const struct Position b1[], const struct Position b2[],
viric@6
    12
	int n)
viric@4
    13
{
viric@6
    14
	int i;
viric@6
    15
	char tmp[MAX_Y][MAX_X]; /* !!!argh */
viric@4
    16
viric@6
    17
	memset(tmp, 0, sizeof(tmp));
viric@6
    18
viric@6
    19
	for (i=0; i < n; i++)
viric@4
    20
	{
viric@6
    21
		tmp[b1[i].y][b1[i].x] = 1;
viric@4
    22
	}
viric@6
    23
	for (i=0; i < n; i++)
viric@4
    24
	{
viric@6
    25
		if (tmp[b2[i].y][b2[i].x] != 1)
viric@6
    26
			return FALSE;
viric@4
    27
	}
viric@6
    28
	return TRUE;
viric@4
    29
}
viric@4
    30
viric@10
    31
int is_new_map(const struct Map maps[], const int depth)
viric@8
    32
{
viric@10
    33
	const struct Map *m = &maps[depth];
viric@8
    34
	int i;
viric@10
    35
	extern int max_depth; 
viric@8
    36
viric@8
    37
	for(i=0; i<max_depth; i++)
viric@8
    38
	{
viric@8
    39
		/* No l'hem de comparar amb ell mateix */
viric@8
    40
		if (i == depth)
viric@8
    41
			continue;
viric@8
    42
viric@8
    43
		if (m->NumBoxesInPlatform != maps[i].NumBoxesInPlatform)
viric@8
    44
			continue;
viric@8
    45
		else
viric@8
    46
		{
viric@8
    47
			if (!are_boxes_equal(m->Box, maps[i].Box, m->NumBoxes))
viric@8
    48
				continue;
viric@8
    49
		}
viric@8
    50
		return FALSE;
viric@8
    51
	}
viric@8
    52
	return TRUE;
viric@8
    53
}