+static void init_terrain_table(int terrain, s16b feat_global, cptr fmt, ...)
+{
+ va_list vp;
+ cptr p;
+ int cur = 0;
+ char check = 'a';
+ s16b feat;
+ int num;
+
+ /* Begin the varargs stuff */
+ va_start(vp, fmt);
+
+ /* Wilderness terrains on global map */
+ conv_terrain2feat[terrain] = feat_global;
+
+ /* Wilderness terrains on local map */
+ for (p = fmt; *p; p++)
+ {
+ if (*p == check)
+ {
+ int lim;
+
+ feat = (s16b)va_arg(vp, int);
+ num = va_arg(vp, int);
+ lim = cur + num;
+
+ for (; (cur < lim) && (cur < MAX_FEAT_IN_TERRAIN); cur++)
+ terrain_table[terrain][cur] = feat;
+ if (cur >= MAX_FEAT_IN_TERRAIN) break;
+
+ check++;
+ }
+ else /* Paranoia */
+ {
+ plog_fmt("Format error");
+ }
+ }
+
+ /* Paranoia */
+ if (cur < MAX_FEAT_IN_TERRAIN)
+ {
+ plog_fmt("Too few parameters");
+ }
+
+ /* End the varargs stuff */
+ va_end(vp);
+}
+
+
+/*
+ * Initialize arrays for wilderness terrains
+ */
+void init_wilderness_terrains(void)
+{
+ init_terrain_table(TERRAIN_EDGE, feat_permanent, "a",
+ feat_permanent, MAX_FEAT_IN_TERRAIN);
+
+ init_terrain_table(TERRAIN_TOWN, feat_town, "a",
+ feat_floor, MAX_FEAT_IN_TERRAIN);
+
+ init_terrain_table(TERRAIN_DEEP_WATER, feat_deep_water, "ab",
+ feat_deep_water, 12,
+ feat_shallow_water, MAX_FEAT_IN_TERRAIN - 12);
+
+ init_terrain_table(TERRAIN_SHALLOW_WATER, feat_shallow_water, "abcde",
+ feat_deep_water, 3,
+ feat_shallow_water, 12,
+ feat_floor, 1,
+ feat_dirt, 1,
+ feat_grass, MAX_FEAT_IN_TERRAIN - 17);
+
+ init_terrain_table(TERRAIN_SWAMP, feat_swamp, "abcdef",
+ feat_dirt, 2,
+ feat_grass, 3,
+ feat_tree, 1,
+ feat_brake, 1,
+ feat_shallow_water, 4,
+ feat_swamp, MAX_FEAT_IN_TERRAIN - 11);
+
+ init_terrain_table(TERRAIN_DIRT, feat_dirt, "abcdef",
+ feat_floor, 3,
+ feat_dirt, 10,
+ feat_flower, 1,
+ feat_brake, 1,
+ feat_grass, 1,
+ feat_tree, MAX_FEAT_IN_TERRAIN - 16);
+
+ init_terrain_table(TERRAIN_GRASS, feat_grass, "abcdef",
+ feat_floor, 2,
+ feat_dirt, 2,
+ feat_grass, 9,
+ feat_flower, 1,
+ feat_brake, 2,
+ feat_tree, MAX_FEAT_IN_TERRAIN - 16);
+
+ init_terrain_table(TERRAIN_TREES, feat_tree, "abcde",
+ feat_floor, 2,
+ feat_dirt, 1,
+ feat_tree, 11,
+ feat_brake, 2,
+ feat_grass, MAX_FEAT_IN_TERRAIN - 16);
+
+ init_terrain_table(TERRAIN_DESERT, feat_dirt, "abc",
+ feat_floor, 2,
+ feat_dirt, 13,
+ feat_grass, MAX_FEAT_IN_TERRAIN - 15);
+
+ init_terrain_table(TERRAIN_SHALLOW_LAVA, feat_shallow_lava, "abc",
+ feat_shallow_lava, 14,
+ feat_deep_lava, 3,
+ feat_mountain, MAX_FEAT_IN_TERRAIN - 17);
+
+ init_terrain_table(TERRAIN_DEEP_LAVA, feat_deep_lava, "abcd",
+ feat_dirt, 3,
+ feat_shallow_lava, 3,
+ feat_deep_lava, 10,
+ feat_mountain, MAX_FEAT_IN_TERRAIN - 16);
+
+ init_terrain_table(TERRAIN_MOUNTAIN, feat_mountain, "abcdef",
+ feat_floor, 1,
+ feat_brake, 1,
+ feat_grass, 2,
+ feat_dirt, 2,
+ feat_tree, 2,
+ feat_mountain, MAX_FEAT_IN_TERRAIN - 8);
+}
+
+