1 | /* |
1 | /* |
2 | * static char *rcsid_apply_c = |
2 | * static char *rcsid_apply_c = |
3 | * "$Id: apply.C,v 1.14 2006/08/29 08:01:37 root Exp $"; |
3 | * "$Id: apply.C,v 1.15 2006/08/29 10:51:43 elmex Exp $"; |
4 | */ |
4 | */ |
5 | /* |
5 | /* |
6 | CrossFire, A Multiplayer game for X-windows |
6 | CrossFire, A Multiplayer game for X-windows |
7 | |
7 | |
8 | Copyright (C) 2001 Mark Wedel & Crossfire Development Team |
8 | Copyright (C) 2001 Mark Wedel & Crossfire Development Team |
… | |
… | |
894 | * what the converter wants, this will not do anything. |
894 | * what the converter wants, this will not do anything. |
895 | */ |
895 | */ |
896 | int convert_item(object *item, object *converter) { |
896 | int convert_item(object *item, object *converter) { |
897 | int nr=0; |
897 | int nr=0; |
898 | object *tmp; |
898 | object *tmp; |
899 | int is_in_shop; |
|
|
900 | uint32 price_in; |
899 | uint32 price_in; |
901 | |
|
|
902 | for(tmp = get_map_ob(converter->map, converter->x, converter->y); |
|
|
903 | tmp != NULL; |
|
|
904 | tmp = tmp->above) { |
|
|
905 | if(tmp->type == SHOP_FLOOR) |
|
|
906 | break; |
|
|
907 | } |
|
|
908 | is_in_shop = (tmp != NULL); |
|
|
909 | |
900 | |
910 | /* We make some assumptions - we assume if it takes money as it type, |
901 | /* We make some assumptions - we assume if it takes money as it type, |
911 | * it wants some amount. We don't make change (ie, if something costs |
902 | * it wants some amount. We don't make change (ie, if something costs |
912 | * 3 gp and player drops a platinum, tough luck) |
903 | * 3 gp and player drops a platinum, tough luck) |
913 | */ |
904 | */ |
… | |
… | |
969 | |
960 | |
970 | if(CONV_NR(converter)) |
961 | if(CONV_NR(converter)) |
971 | item->nrof=CONV_NR(converter); |
962 | item->nrof=CONV_NR(converter); |
972 | if(nr) |
963 | if(nr) |
973 | item->nrof*=nr; |
964 | item->nrof*=nr; |
974 | if(is_in_shop) |
965 | if(is_in_shop (converter)) |
975 | SET_FLAG(item,FLAG_UNPAID); |
966 | SET_FLAG(item,FLAG_UNPAID); |
976 | else if(price_in < item->nrof*item->value) { |
967 | else if(price_in < item->nrof*item->value) { |
977 | LOG(llevDebug, "converter output price higher than input: %s at %s (%d, %d) in value %d, out value %d for %s\n", |
968 | LOG(llevDebug, "converter output price higher than input: %s at %s (%d, %d) in value %d, out value %d for %s\n", |
978 | converter->name, converter->map->path, converter->x, converter->y, price_in, |
969 | converter->name, converter->map->path, converter->x, converter->y, price_in, |
979 | item->nrof*item->value, item->name); |
970 | item->nrof*item->value, item->name); |
… | |
… | |
1254 | * Returns 1 if 'op' was destroyed, 0 if not. |
1245 | * Returns 1 if 'op' was destroyed, 0 if not. |
1255 | * Largely re-written to not use nearly as many gotos, plus |
1246 | * Largely re-written to not use nearly as many gotos, plus |
1256 | * some of this code just looked plain out of date. |
1247 | * some of this code just looked plain out of date. |
1257 | * MSW 2001-08-29 |
1248 | * MSW 2001-08-29 |
1258 | */ |
1249 | */ |
1259 | int apply_shop_mat (object *shop_mat, object *op) |
1250 | int apply_shop_mat (object * shop_mat, object * op) |
1260 | { |
1251 | { |
1261 | int rv = 0; |
1252 | int rv = 0; |
1262 | double opinion; |
1253 | double opinion; |
1263 | object *tmp, *next; |
1254 | object *tmp, *next; |
1264 | |
1255 | |
1265 | SET_FLAG (op,FLAG_NO_APPLY); /* prevent loops */ |
1256 | SET_FLAG (op, FLAG_NO_APPLY); /* prevent loops */ |
1266 | |
1257 | |
1267 | if (op->type != PLAYER) { |
1258 | if (op->type != PLAYER) |
|
|
1259 | { |
1268 | /* Remove all the unpaid objects that may be carried here. |
1260 | /* Remove all the unpaid objects that may be carried here. |
1269 | * This could be pets or monsters that are somehow in |
1261 | * This could be pets or monsters that are somehow in |
1270 | * the shop. |
1262 | * the shop. |
1271 | */ |
1263 | */ |
1272 | for (tmp=op->inv; tmp; tmp=next) { |
1264 | for (tmp = op->inv; tmp; tmp = next) |
|
|
1265 | { |
1273 | next = tmp->below; |
1266 | next = tmp->below; |
1274 | if (QUERY_FLAG(tmp, FLAG_UNPAID)) { |
1267 | if (QUERY_FLAG (tmp, FLAG_UNPAID)) |
|
|
1268 | { |
1275 | int i = find_free_spot (tmp, op->map, op->x, op->y, 1, 9); |
1269 | int i = find_free_spot (tmp, op->map, op->x, op->y, 1, 9); |
1276 | |
1270 | |
1277 | remove_ob(tmp); |
1271 | remove_ob (tmp); |
1278 | if (i==-1) i=0; |
1272 | if (i == -1) |
|
|
1273 | i = 0; |
1279 | tmp->map = op->map; |
1274 | tmp->map = op->map; |
1280 | tmp->x = op->x + freearr_x[i]; |
1275 | tmp->x = op->x + freearr_x[i]; |
1281 | tmp->y = op->y + freearr_y[i]; |
1276 | tmp->y = op->y + freearr_y[i]; |
1282 | insert_ob_in_map(tmp, op->map, op, 0); |
1277 | insert_ob_in_map (tmp, op->map, op, 0); |
1283 | } |
|
|
1284 | } |
1278 | } |
|
|
1279 | } |
1285 | |
1280 | |
1286 | /* Don't teleport things like spell effects */ |
1281 | /* Don't teleport things like spell effects */ |
1287 | if (QUERY_FLAG(op, FLAG_NO_PICK)) return 0; |
1282 | if (QUERY_FLAG (op, FLAG_NO_PICK)) |
|
|
1283 | return 0; |
1288 | |
1284 | |
1289 | /* unpaid objects, or non living objects, can't transfer by |
1285 | /* unpaid objects, or non living objects, can't transfer by |
1290 | * shop mats. Instead, put it on a nearby space. |
1286 | * shop mats. Instead, put it on a nearby space. |
1291 | */ |
1287 | */ |
1292 | if (QUERY_FLAG(op, FLAG_UNPAID) || !QUERY_FLAG(op, FLAG_ALIVE)) { |
1288 | if (QUERY_FLAG (op, FLAG_UNPAID) || !QUERY_FLAG (op, FLAG_ALIVE)) |
|
|
1289 | { |
1293 | |
1290 | |
1294 | /* Somebody dropped an unpaid item, just move to an adjacent place. */ |
1291 | /* Somebody dropped an unpaid item, just move to an adjacent place. */ |
1295 | int i = find_free_spot (op, op->map, op->x, op->y, 1, 9); |
1292 | int i = find_free_spot (op, op->map, op->x, op->y, 1, 9); |
1296 | if (i != -1) { |
1293 | if (i != -1) |
|
|
1294 | { |
|
|
1295 | rv = |
1297 | rv = transfer_ob (op, op->x + freearr_x[i], op->y + freearr_y[i], 0, |
1296 | transfer_ob (op, op->x + freearr_x[i], op->y + freearr_y[i], |
1298 | shop_mat); |
1297 | 0, shop_mat); |
1299 | } |
1298 | } |
1300 | return 0; |
1299 | return 0; |
1301 | } |
1300 | } |
1302 | /* Removed code that checked for multipart objects - it appears that |
1301 | /* Removed code that checked for multipart objects - it appears that |
1303 | * the teleport function should be able to handle this just fine. |
1302 | * the teleport function should be able to handle this just fine. |
1304 | */ |
1303 | */ |
1305 | rv = teleport (shop_mat, SHOP_MAT, op); |
1304 | rv = teleport (shop_mat, SHOP_MAT, op); |
1306 | } |
1305 | } |
1307 | /* immediate block below is only used for players */ |
1306 | /* immediate block below is only used for players */ |
1308 | else if (can_pay(op)) { |
1307 | else if (can_pay (op)) |
|
|
1308 | { |
1309 | get_payment (op, op->inv); |
1309 | get_payment (op, op->inv); |
1310 | rv = teleport (shop_mat, SHOP_MAT, op); |
1310 | rv = teleport (shop_mat, SHOP_MAT, op); |
|
|
1311 | |
1311 | if (shop_mat->msg) { |
1312 | if (shop_mat->msg) |
|
|
1313 | { |
1312 | new_draw_info (NDI_UNIQUE, 0, op, shop_mat->msg); |
1314 | new_draw_info (NDI_UNIQUE, 0, op, shop_mat->msg); |
1313 | } |
1315 | } |
1314 | /* This check below is a bit simplistic - generally it should be correct, |
1316 | /* This check below is a bit simplistic - generally it should be correct, |
1315 | * but there is never a guarantee that the bottom space on the map is |
1317 | * but there is never a guarantee that the bottom space on the map is |
1316 | * actually the shop floor. |
1318 | * actually the shop floor. |
1317 | */ |
1319 | */ |
1318 | else if ( ! rv && (tmp = get_map_ob (op->map, op->x, op->y)) != NULL |
1320 | else if (!rv && !is_in_shop (op)) |
1319 | && tmp->type != SHOP_FLOOR) { |
1321 | { |
1320 | opinion = shopkeeper_approval(op->map, op); |
1322 | opinion = shopkeeper_approval (op->map, op); |
1321 | if ( opinion > 0.9) |
1323 | if (opinion > 0.9) |
1322 | new_draw_info (NDI_UNIQUE, 0, op, "The shopkeeper gives you a friendly wave."); |
1324 | new_draw_info (NDI_UNIQUE, 0, op, |
|
|
1325 | "The shopkeeper gives you a friendly wave."); |
1323 | else if ( opinion > 0.75) |
1326 | else if (opinion > 0.75) |
1324 | new_draw_info (NDI_UNIQUE, 0, op, "The shopkeeper waves to you."); |
1327 | new_draw_info (NDI_UNIQUE, 0, op, "The shopkeeper waves to you."); |
1325 | else if ( opinion > 0.5) |
1328 | else if (opinion > 0.5) |
1326 | new_draw_info (NDI_UNIQUE, 0, op, "The shopkeeper ignores you."); |
1329 | new_draw_info (NDI_UNIQUE, 0, op, "The shopkeeper ignores you."); |
1327 | else |
1330 | else |
1328 | new_draw_info (NDI_UNIQUE, 0, op, "The shopkeeper glares at you with contempt."); |
1331 | new_draw_info (NDI_UNIQUE, 0, op, |
|
|
1332 | "The shopkeeper glares at you with contempt."); |
1329 | } |
1333 | } |
|
|
1334 | } |
|
|
1335 | else |
1330 | } |
1336 | { |
1331 | else { |
|
|
1332 | /* if we get here, a player tried to leave a shop but was not able |
1337 | /* if we get here, a player tried to leave a shop but was not able |
1333 | * to afford the items he has. We try to move the player so that |
1338 | * to afford the items he has. We try to move the player so that |
1334 | * they are not on the mat anymore |
1339 | * they are not on the mat anymore |
1335 | */ |
1340 | */ |
1336 | |
1341 | |
1337 | int i = find_free_spot (op, op->map, op->x, op->y, 1, 9); |
1342 | int i = find_free_spot (op, op->map, op->x, op->y, 1, 9); |
1338 | if(i == -1) { |
1343 | if (i == -1) |
|
|
1344 | { |
1339 | LOG (llevError, "Internal shop-mat problem.\n"); |
1345 | LOG (llevError, "Internal shop-mat problem.\n"); |
|
|
1346 | } |
1340 | } else { |
1347 | else |
|
|
1348 | { |
1341 | remove_ob (op); |
1349 | remove_ob (op); |
1342 | op->x += freearr_x[i]; |
1350 | op->x += freearr_x[i]; |
1343 | op->y += freearr_y[i]; |
1351 | op->y += freearr_y[i]; |
1344 | rv = insert_ob_in_map (op, op->map, shop_mat,0) == NULL; |
1352 | rv = insert_ob_in_map (op, op->map, shop_mat, 0) == NULL; |
1345 | } |
1353 | } |
1346 | } |
1354 | } |
1347 | CLEAR_FLAG (op, FLAG_NO_APPLY); |
1355 | CLEAR_FLAG (op, FLAG_NO_APPLY); |
1348 | return rv; |
1356 | return rv; |
1349 | } |
1357 | } |
1350 | |
1358 | |
1351 | /** |
1359 | /** |
1352 | * Handles applying a sign. |
1360 | * Handles applying a sign. |
1353 | */ |
1361 | */ |