Ejemplo n.º 1
0
static void	check_room(t_room *room, t_room *previous)
{
	t_tunnel	*t;
	t_room		*room2;

	if (room->start_end == 'e' || room->start_end == 's')
		return ;
	t = room->tunnels->next;
	while (get_tunnel_nbr(room) > 2)
	{
		if (t->room != previous)
		{
			room2 = t->room;
			block_tunnel(room, room2);
			block_tunnel(room2, room);
			t = room->tunnels;
		}
		t = t->next;
	}
	if (get_tunnel_nbr(room) != 1)
	{
		if (room->tunnels->room != previous)
			check_room(room->tunnels->room, room);
		else
			check_room(room->tunnels->next->room, room);
	}
}
Ejemplo n.º 2
0
static int	go_next(t_gen *gen, t_pos *pos, int type)
{
  t_pos		n_pos[2];
  
  n_pos[0].x = pos->x;
  n_pos[0].y = pos->y;
  n_pos[1].x = pos->x;
  n_pos[1].y = pos->y;
  if (type == 0)
    n_pos[1].x += 1;
  else if (type == 1)
    n_pos[1].x -= 1;
  else if (type == 2)
    n_pos[1].y += 1;
  else
    n_pos[1].y -= 1;
  if ((n_pos[1].x < 0 || n_pos[1].x >= gen->w ||
       n_pos[1].y < 0 || n_pos[1].y >= gen->h) ||
      ((check_room(gen, n_pos[1].x + 1, n_pos[1].y, n_pos) == 1 ||
	check_room(gen, n_pos[1].x - 1, n_pos[1].y, n_pos) == 1 ||
	check_room(gen, n_pos[1].x, n_pos[1].y + 1, n_pos) == 1 ||
	check_room(gen, n_pos[1].x, n_pos[1].y - 1, n_pos) == 1) &&
       gen->map[n_pos[1].y][n_pos[1].x] != '*'))
    return (1);
  pos->x = n_pos[1].x;
  pos->y = n_pos[1].y;
  return (0);
}
Ejemplo n.º 3
0
void	apply_path(t_hex *lst, t_path *ants)
{
	if ((ants = (t_path*)malloc(sizeof(t_path) * (lst->ants))) == NULL)
		error("ERROR : Malloc NULL.");
	lst = initialyze_ants(lst, &ants, 0, 0);
	ft_putchar('\n');
	while (check_ants(&ants, lst) == 0)
	{
		while (ants[IND].checkend == 1 || check_room(ants, lst,
					lst->path[ants[IND].index][ants[IND].index2]) == 1)
		{
			IND++;
			lst = count(lst);
		}
		if (lst->path[ants[IND].index][ants[IND].index2])
		{
			if (lst->i2 != 0)
				ft_putchar(' ');
			ft_printf("L%d-%s", IND + 1,
					lst->path[ants[IND].index][ants[IND].index2]);
			lst->i2++;
		}
		ants[IND].room = lst->path[ants[IND].index][ants[IND].index2];
		ants[IND].index2++;
		IND++;
		lst = count(lst);
	}
}
Ejemplo n.º 4
0
int 
main(int argc, char **argv)
{
    int     i;

    if (argc != 3) {
	fprintf(stderr, "Must be called in form 'extract <filename> <dbref>'\n");
	exit(1);
    }
    if ((input_file = fopen(argv[1], "r")) == NULL) {
	fprintf(stderr, "Could not open file '%d'\n", argv[1]);
	exit(1);
    }
    me = atoi(argv[2]);

    db_free();
    db_read(input_file);

    fprintf(stderr, "dbtop = %d\n", db_top);

    printf("MUCK 2.2fb extract for dbref #%d\n", me);

    for (i = 0; i < db_top; i++) {
	if (OWNER(i) != me)
	    continue;

	if (!(i % 256))
            fprintf(stderr, "Checking object %d..\n", i);
	check_common(i);
	switch (db[i].flags & TYPE_MASK) {
	    case TYPE_ROOM:
		check_room(i);
		break;
	    case TYPE_THING:
		check_thing(i);
		break;
	    case TYPE_EXIT:
		check_exit(i);
		break;
	    case TYPE_PLAYER:
		check_player(i);
		break;
	    case TYPE_PROGRAM:
		check_program(i);
		break;
	    case TYPE_GARBAGE:
		break;
	    default:
		break;
	}
    }
    fclose(input_file);
    fprintf(stderr, "Completed extract normally.\n");
    return 0;
}
Ejemplo n.º 5
0
Archivo: take.c Proyecto: elivet/Lem_in
t_data		take_end(t_data the)
{
	if (ft_strcmp(the.line, "##end") == 0)
	{
		get_next_line(0, &the.line);
		if (the.line[0] == '#')
			error();
		the.j++;
		the.aff[the.j] = ft_strdup(the.line);
		if (check_room(the) == 1)
			the.end = take_name(the.line);
		else
			error();
	}
	return (the);
}
Ejemplo n.º 6
0
void		cut_branches(t_room *rooms, t_room *start)
{
	t_tunnel	*tunnel;

	tunnel = start->tunnels;
	while (tunnel != NULL)
	{
		check_room(tunnel->room, start);
		tunnel = tunnel->next;
	}
	while (rooms != NULL)
	{
		rooms->end_dist = -1;
		rooms = rooms->next;
	}
}
Ejemplo n.º 7
0
static int		check_str(char *str, t_rooms *room)
{
	static int	flag = 1;
	int			i;

	i = 0;
	if (flag == 1)
	{
		if (check_room(str, 0) == 0)
		{
			flag = 2;
			return (check_str(str, room));
		}
		else
			return (1);
	}
	return (check_tube(str, 0, room));
}
Ejemplo n.º 8
0
bool	prepare_link_tabs(t_room **room, t_map *map)
{
  t_room	*tmp;
  char		**tab;

  if (del_in_front(room) == false)
    return (NULL);
  if ((check_room(*room, tab = stock_room_link(map))) == false)
    return (false);
  free_char_tab(tab);
  get_real_first(room);
  tmp = *room;
  while (tmp != NULL)
    {
      if ((tmp->link = malloc(sizeof(char *))) == NULL)
	return (false);
      tmp->link[0] = NULL;
      tmp = tmp->next;
    }
  return (true);
}
Ejemplo n.º 9
0
static int		parse_line(t_env *env, t_parser *p)
{
	int		c_r;
	int		c_l;

	if (p->line[0] == '\0')
		return (0);
	if (p->line[0] == '#' && p->line[1] == '#')
	{
		if (!check_start_end(env, p))
			return (0);
	}
	else
	{
		if (!(c_r = check_room(env, p)))
			return (0);
		else if (!(c_l = check_link(env, p)))
			return (0);
		if (c_r == -1 && c_l == -1)
			return (0);
	}
	return (1);
}
Ejemplo n.º 10
0
Archivo: take.c Proyecto: elivet/Lem_in
t_data		information(t_data the)
{
	the = first_take(the);
	if (the.nbr == 0)
		error();
	while (get_next_line(0, &the.line))
	{
		if (the.line[0] == '\0')
			error();
		the.j++;
		the.aff[the.j] = ft_strdup(the.line);
		if (check_tube(the.line) == 1)
		{
			the.tube[the.i] = ft_strdup(the.line);
			the.i++;
		}
		the = take_start(the);
		if (check_room(the) == 1)
			check_it(the);
		the = take_end(the);
	}
	the = finish(the, the.i, the.j);
	return (the);
}
Ejemplo n.º 11
0
static int
send_padi (int n, PPPoEConnection* conns)
{
    int ret = 0, i;

    for (i = 0; i < n; i++)
    {
	PPPoEConnection* conn = &conns[i];

	if (conn->fd == -1 || conn->received_pado)
	    continue;

	PPPoEPacket packet;
	unsigned char* cursor = packet.payload;
	PPPoETag* svc = (PPPoETag*) (&packet.payload);
	uint16_t namelen = 0;
	uint16_t plen;

	namelen = 0;
	plen = TAG_HDR_SIZE + namelen;
	if (!check_room (conn, cursor, packet.payload, TAG_HDR_SIZE))
	    continue;

	/* Set destination to Ethernet broadcast address */
	memset (packet.ethHdr.h_dest, 0xFF, ETH_ALEN);
	memcpy (packet.ethHdr.h_source, conn->my_mac, ETH_ALEN);

	packet.ethHdr.h_proto = htons (ETH_PPPOE_DISCOVERY);
	packet.ver = 1;
	packet.type = 1;
	packet.code = CODE_PADI;
	packet.session = 0;

	svc->type = TAG_SERVICE_NAME;
	svc->length = htons (0);
	if (!check_room (conn, cursor, packet.payload, namelen + TAG_HDR_SIZE))
	    continue;

	cursor += namelen + TAG_HDR_SIZE;

	PPPoETag hostUniq;
	pid_t pid = getpid ();
	hostUniq.type = htons (TAG_HOST_UNIQ);
	hostUniq.length = htons (sizeof (pid));
	memcpy (hostUniq.payload, &pid, sizeof (pid));
	if (!check_room (conn, cursor, packet.payload, sizeof (pid) + TAG_HDR_SIZE))
	    continue;
	memcpy (cursor, &hostUniq, sizeof (pid) + TAG_HDR_SIZE);
	cursor += sizeof (pid) + TAG_HDR_SIZE;
	plen += sizeof (pid) + TAG_HDR_SIZE;

	packet.length = htons (plen);

	ADD2LOG ("%s: Sending PADI packet\n", conn->ifname);

	if (send_packet (conn->fd, &packet, (int) (plen + HDR_SIZE)))
	    ret = 1;
    }

    return ret;
}