- for (tot = i = 0; i < mp->num_in; i++)
- tot += input[i];
- if (tot) {
- printf("You asked for %d houses for $%d\n", tot, tot * price);
- if (getyn("Is that ok? ", yn) == 0) {
- cur_p->money -= tot * price;
- for (tot = i = 0; i < mp->num_in; i++)
- mp->sq[i]->desc->houses = temp[i];
+
+ wanted_houses = 0;
+ wanted_hotels = 0;
+ total_purchase = 0;
+
+ for (i = 0; i < mp->num_in; i++) {
+ wanted_houses += input[i];
+ total_purchase += input[i];
+ if (result[i] == 5 && input[i] > 0) {
+ wanted_hotels++;
+ wanted_houses--;
+ }
+ }
+ if (wanted_houses > avail_houses) {
+ printf("You have asked for %d %s but only %d are available. "
+ "Try again\n",
+ wanted_houses, wanted_houses == 1 ? "house" : "houses",
+ avail_houses);
+ goto blew_it;
+ } else if (wanted_hotels > avail_hotels) {
+ printf("You have asked for %d %s but only %d are available. "
+ "Try again\n",
+ wanted_hotels, wanted_hotels == 1 ? "hotel" : "hotels",
+ avail_hotels);
+ goto blew_it;
+ }
+
+ if (total_purchase) {
+ printf("You asked for %d %s and %d %s for $%d\n",
+ wanted_houses, wanted_houses == 1 ? "house" : "houses",
+ wanted_hotels, wanted_hotels == 1 ? "hotel" : "hotels",
+ total_purchase * price);
+ if (getyn("Is that ok? ") == 0) {
+ cur_p->money -= total_purchase * price;
+ for (i = 0; i < mp->num_in; i++)
+ mp->sq[i]->desc->houses = result[i];