… | |
… | |
1194 | } |
1194 | } |
1195 | SET_FLAG (tmp, FLAG_UNPAID); |
1195 | SET_FLAG (tmp, FLAG_UNPAID); |
1196 | } |
1196 | } |
1197 | |
1197 | |
1198 | void |
1198 | void |
1199 | shop_listing (object *op) |
1199 | shop_listing (object *sign, object *op) |
1200 | { |
1200 | { |
1201 | int i, j, numitems = 0, numallocated = 0, nx, ny; |
1201 | int i, j, numitems = 0, numallocated = 0, x1, x2, y1, y2; |
1202 | char *map_mark = (char *) calloc (MAGIC_MAP_SIZE * MAGIC_MAP_SIZE, 1); |
1202 | const char *shop_coords = get_ob_key_value (sign, "shop_coords"); |
1203 | object *stack; |
1203 | object *stack; |
1204 | shopinv *items; |
1204 | shopinv *items; |
1205 | |
1205 | |
1206 | /* Should never happen, but just in case a monster does apply a sign */ |
1206 | /* Should never happen, but just in case a monster does apply a sign */ |
1207 | if (op->type != PLAYER) |
1207 | if (op->type != PLAYER) |
1208 | return; |
1208 | return; |
1209 | |
1209 | |
1210 | new_draw_info (NDI_UNIQUE, 0, op, "\nThe shop contains:"); |
1210 | if (!(shop_coords && sscanf (shop_coords, "%d,%d,%d,%d", &x1, &y1, &x2, &y2))) |
|
|
1211 | { |
|
|
1212 | x1 = 0; |
|
|
1213 | y1 = 0; |
|
|
1214 | x2 = op->map->width - 1; |
|
|
1215 | y2 = op->map->height - 1; |
|
|
1216 | } |
1211 | |
1217 | |
1212 | magic_mapping_mark (op, map_mark, 3); |
|
|
1213 | items = (shopinv *) malloc (40 * sizeof (shopinv)); |
1218 | items = (shopinv *) malloc (40 * sizeof (shopinv)); |
1214 | numallocated = 40; |
1219 | numallocated = 40; |
1215 | |
1220 | |
1216 | /* Find all the appropriate items */ |
1221 | /* Find all the appropriate items */ |
1217 | for (i = 0; i < op->map->width; i++) |
1222 | for (i = x1; i <= x2; i++) |
1218 | { |
1223 | { |
1219 | for (j = 0; j < op->map->height; j++) |
1224 | for (j = y1; j < y2; j++) |
1220 | { |
1225 | { |
1221 | // magic map code now centers the map on the object at MAGIC_MAP_HALF. |
1226 | if (is_in_shop (op->map, i, j)) |
1222 | nx = i - op->x + MAGIC_MAP_HALF; |
|
|
1223 | ny = j - op->y + MAGIC_MAP_HALF; |
|
|
1224 | /* unlikely, but really big shops could run into this issue */ |
|
|
1225 | if (nx < 0 || ny < 0 || nx > MAGIC_MAP_SIZE || ny > MAGIC_MAP_SIZE) |
|
|
1226 | continue; |
|
|
1227 | |
|
|
1228 | if (map_mark[nx + MAGIC_MAP_SIZE * ny] & FACE_FLOOR) |
|
|
1229 | { |
1227 | { |
1230 | stack = GET_MAP_OB (op->map, i, j); |
1228 | stack = GET_MAP_OB (op->map, i, j); |
1231 | |
1229 | |
1232 | while (stack) |
1230 | while (stack) |
1233 | { |
1231 | { |
… | |
… | |
1246 | } |
1244 | } |
1247 | } |
1245 | } |
1248 | } |
1246 | } |
1249 | } |
1247 | } |
1250 | |
1248 | |
1251 | free (map_mark); |
|
|
1252 | |
|
|
1253 | if (numitems == 0) |
1249 | if (numitems == 0) |
1254 | { |
1250 | { |
1255 | new_draw_info (NDI_UNIQUE, 0, op, "The shop is currently empty.\n"); |
1251 | new_draw_info (NDI_UNIQUE, 0, op, "The shop is currently empty.\n"); |
1256 | free (items); |
1252 | free (items); |
1257 | return; |
1253 | return; |
1258 | } |
1254 | } |
1259 | |
1255 | |
1260 | qsort (items, numitems, sizeof (shopinv), (int (*)(const void *, const void *)) shop_sort); |
1256 | qsort (items, numitems, sizeof (shopinv), (int (*)(const void *, const void *)) shop_sort); |
|
|
1257 | |
|
|
1258 | new_draw_info (NDI_UNIQUE, 0, op, "\nThe shop contains:"); |
1261 | |
1259 | |
1262 | for (i = 0; i < numitems; i++) |
1260 | for (i = 0; i < numitems; i++) |
1263 | { |
1261 | { |
1264 | /* Collapse items of the same name together */ |
1262 | /* Collapse items of the same name together */ |
1265 | if ((i + 1) < numitems && !strcmp (items[i].item_real, items[i + 1].item_real)) |
1263 | if ((i + 1) < numitems && !strcmp (items[i].item_real, items[i + 1].item_real)) |