Example #1
0
/* Make a copy of an existing map
 */
Map *map_copy(const Map * map)
{
	Map *copy = map_new();
	int x, y;

	copy->y = map->y;
	copy->x_size = map->x_size;
	copy->y_size = map->y_size;
	for (y = 0; y < MAP_SIZE; y++)
		for (x = 0; x < MAP_SIZE; x++)
			copy->grid[y][x] = copy_hex(copy, map->grid[y][x]);
	map_traverse(copy, build_network, NULL);
	map_traverse(copy, connect_network, NULL);
	map_traverse_const(map, set_nosetup_nodes, copy);
	if (map->robber_hex == NULL)
		copy->robber_hex = NULL;
	else
		copy->robber_hex =
		    copy->grid[map->robber_hex->y][map->robber_hex->x];
	if (map->pirate_hex == NULL)
		copy->pirate_hex = NULL;
	else
		copy->pirate_hex =
		    copy->grid[map->pirate_hex->y][map->pirate_hex->x];
	copy->shrink_left = map->shrink_left;
	copy->shrink_right = map->shrink_right;
	copy->has_moved_ship = map->has_moved_ship;
	copy->have_bridges = map->have_bridges;
	copy->has_pirate = map->has_pirate;
	copy->shrink_left = map->shrink_left;
	copy->shrink_right = map->shrink_right;
	copy->chits = copy_int_list(map->chits);

	return copy;
}
Example #2
0
/******************************************************************************
 *                                                                            *
 ******************************************************************************/
int get_namelist(int file, NAMELIST *nl)
{
    const char *section;
    int count, ret = -1;

    if (nl->type != TYPE_START) return -1;
    section = nl->name;
    nl++;

    while (nl->type != TYPE_END) {
        NML_Entry *ne = find_namelist_entry(file, section, nl->name);

        if (ne != NULL) {
            ret = 0;
            ne->seen = 1;

            if ( (nl->type & MASK_LIST) ) {
                count = ne->count;
                switch (nl->type & MASK_TYPE) {
                    case TYPE_INT :
                        *((void**)(nl->data)) = copy_int_list(count, ne->data);
                        break;
                    case TYPE_DOUBLE :
                        *((void**)(nl->data)) = copy_double_list(count, ne->data, (ne->type & MASK_TYPE) == TYPE_DOUBLE);
                        break;
                    case TYPE_STR :
                        *((void**)(nl->data)) = copy_str_list(count, ne->data);
                        break;
                    case TYPE_BOOL :
                        *((void**)(nl->data)) = copy_bool_list(count, ne->data);
                        break;
                    default :
                        fprintf(stderr, "    Value of unknown type %d\n", ne->type);
                        break;
                }
            } else {
                switch (nl->type & MASK_TYPE) {
                    case TYPE_INT :
                        if ( (ne->type & MASK_TYPE) == TYPE_INT )
                            *((int*)(nl->data)) = ne->data[0].i;
                        break;
                    case TYPE_DOUBLE :
                        if ( (ne->type & MASK_TYPE) == TYPE_DOUBLE )
                            *((double*)(nl->data)) = ne->data[0].r;
                        else if ( (ne->type & MASK_TYPE) == TYPE_INT )
                            *((double*)(nl->data)) = ne->data[0].i;
                        break;
                    case TYPE_STR :
                        *((char**)(nl->data)) = strdup(ne->data[0].s);
                        break;
                    case TYPE_BOOL :
                        *((int*)(nl->data)) = ne->data[0].b;
                        break;
                    default :
                        fprintf(stderr, "    Value of unknown type %d\n", ne->type);
                        break;
                }
            }
        }
        nl++;
    }

    return ret;
}