src/town_cmd.cpp
changeset 9040 05467c606a0e
parent 9036 6368fe55fd6d
child 9068 84318afa7067
equal deleted inserted replaced
9039:480ed3fad6ce 9040:05467c606a0e
  2444 		return CalcClosestTownFromTile(tile, threshold);
  2444 		return CalcClosestTownFromTile(tile, threshold);
  2445 	}
  2445 	}
  2446 }
  2446 }
  2447 
  2447 
  2448 static bool _town_rating_test = false;
  2448 static bool _town_rating_test = false;
       
  2449 std::map<const Town *, int> _town_test_ratings;
  2449 
  2450 
  2450 void SetTownRatingTestMode(bool mode)
  2451 void SetTownRatingTestMode(bool mode)
  2451 {
  2452 {
  2452 	static int ref_count = 0;
  2453 	static int ref_count = 0;
  2453 	if (mode) {
  2454 	if (mode) {
  2454 		if (ref_count == 0) {
  2455 		if (ref_count == 0) {
  2455 			Town *t;
  2456 			_town_test_ratings.empty();
  2456 			FOR_ALL_TOWNS(t) t->test_rating = t->ratings[_current_player];
       
  2457 		}
  2457 		}
  2458 		ref_count++;
  2458 		ref_count++;
  2459 	} else {
  2459 	} else {
  2460 		assert(ref_count > 0);
  2460 		assert(ref_count > 0);
  2461 		ref_count--;
  2461 		ref_count--;
  2462 	}
  2462 	}
  2463 	_town_rating_test = !(ref_count == 0);
  2463 	_town_rating_test = !(ref_count == 0);
       
  2464 }
       
  2465 
       
  2466 static int GetRating(const Town *t)
       
  2467 {
       
  2468 	if (_town_rating_test) {
       
  2469 		std::map<const Town *, int>::iterator it = _town_test_ratings.find(t);
       
  2470 		if (it != _town_test_ratings.end()) {
       
  2471 			return (*it).second;
       
  2472 		}
       
  2473 	}
       
  2474 	return t->ratings[_current_player];
  2464 }
  2475 }
  2465 
  2476 
  2466 void ChangeTownRating(Town *t, int add, int max)
  2477 void ChangeTownRating(Town *t, int add, int max)
  2467 {
  2478 {
  2468 	/* if magic_bulldozer cheat is active, town doesn't penaltize for removing stuff */
  2479 	/* if magic_bulldozer cheat is active, town doesn't penaltize for removing stuff */
  2472 		return;
  2483 		return;
  2473 	}
  2484 	}
  2474 
  2485 
  2475 	SetBit(t->have_ratings, _current_player);
  2486 	SetBit(t->have_ratings, _current_player);
  2476 
  2487 
  2477 	int rating = _town_rating_test ? t->test_rating : t->ratings[_current_player];
  2488 	int rating = GetRating(t);
  2478 
       
  2479 	if (add < 0) {
  2489 	if (add < 0) {
  2480 		if (rating > max) {
  2490 		if (rating > max) {
  2481 			rating += add;
  2491 			rating += add;
  2482 			if (rating < max) rating = max;
  2492 			if (rating < max) rating = max;
  2483 		}
  2493 		}
  2486 			rating += add;
  2496 			rating += add;
  2487 			if (rating > max) rating = max;
  2497 			if (rating > max) rating = max;
  2488 		}
  2498 		}
  2489 	}
  2499 	}
  2490 	if (_town_rating_test) {
  2500 	if (_town_rating_test) {
  2491 		t->test_rating = rating;
  2501 		_town_test_ratings[t] = rating;
  2492 	} else {
  2502 	} else {
  2493 		t->ratings[_current_player] = rating;
  2503 		t->ratings[_current_player] = rating;
  2494 	}
  2504 	}
  2495 }
  2505 }
  2496 
  2506 
  2512 	 * owned by a town no removal if rating is lower than ... depends now on
  2522 	 * owned by a town no removal if rating is lower than ... depends now on
  2513 	 * difficulty setting. Minimum town rating selected by difficulty level
  2523 	 * difficulty setting. Minimum town rating selected by difficulty level
  2514 	 */
  2524 	 */
  2515 	int modemod = _default_rating_settings[_opt.diff.town_council_tolerance][type];
  2525 	int modemod = _default_rating_settings[_opt.diff.town_council_tolerance][type];
  2516 
  2526 
  2517 	if ((_town_rating_test ? t->test_rating : t->ratings[_current_player]) < 16 + modemod && !(flags & DC_NO_TOWN_RATING)) {
  2527 	if (GetRating(t) < 16 + modemod && !(flags & DC_NO_TOWN_RATING)) {
  2518 		SetDParam(0, t->index);
  2528 		SetDParam(0, t->index);
  2519 		_error_message = STR_2009_LOCAL_AUTHORITY_REFUSES;
  2529 		_error_message = STR_2009_LOCAL_AUTHORITY_REFUSES;
  2520 		return false;
  2530 		return false;
  2521 	}
  2531 	}
  2522 
  2532