economy.c
changeset 4346 3f00094f2670
parent 4344 5d0e40cd67b9
child 4354 684ab9249dae
equal deleted inserted replaced
4345:dd12549ad473 4346:3f00094f2670
    55 	{
    55 	{
    56 		Station *st;
    56 		Station *st;
    57 		uint num = 0;
    57 		uint num = 0;
    58 
    58 
    59 		FOR_ALL_STATIONS(st) {
    59 		FOR_ALL_STATIONS(st) {
    60 			if (st->xy != 0 && st->owner == owner) {
    60 			if (st->owner == owner) {
    61 				uint facil = st->facilities;
    61 				uint facil = st->facilities;
    62 				do num += (facil&1); while (facil >>= 1);
    62 				do num += (facil&1); while (facil >>= 1);
    63 			}
    63 			}
    64 		}
    64 		}
    65 
    65 
    68 
    68 
    69 	{
    69 	{
    70 		Vehicle *v;
    70 		Vehicle *v;
    71 
    71 
    72 		FOR_ALL_VEHICLES(v) {
    72 		FOR_ALL_VEHICLES(v) {
    73 			if (v->owner != owner)
    73 			if (v->owner != owner) continue;
    74 				continue;
    74 
    75 			if (v->type == VEH_Train ||
    75 			if (v->type == VEH_Train ||
    76 					v->type == VEH_Road ||
    76 					v->type == VEH_Road ||
    77 					(v->type == VEH_Aircraft && v->subtype<=2) ||
    77 					(v->type == VEH_Aircraft && v->subtype<=2) ||
    78 					v->type == VEH_Ship) {
    78 					v->type == VEH_Ship) {
    79 				value += v->value * 3 >> 1;
    79 				value += v->value * 3 >> 1;
   131 	{
   131 	{
   132 		uint num = 0;
   132 		uint num = 0;
   133 		const Station* st;
   133 		const Station* st;
   134 
   134 
   135 		FOR_ALL_STATIONS(st) {
   135 		FOR_ALL_STATIONS(st) {
   136 			if (st->xy != 0 && st->owner == owner) {
   136 			if (st->owner == owner) {
   137 				int facil = st->facilities;
   137 				int facil = st->facilities;
   138 				do num += facil&1; while (facil>>=1);
   138 				do num += facil&1; while (facil>>=1);
   139 			}
   139 			}
   140 		}
   140 		}
   141 		_score_part[owner][SCORE_STATIONS] = num;
   141 		_score_part[owner][SCORE_STATIONS] = num;
   264 	/* Take care of rating in towns */
   264 	/* Take care of rating in towns */
   265 	if (new_player != OWNER_SPECTATOR) {
   265 	if (new_player != OWNER_SPECTATOR) {
   266 		Town *t;
   266 		Town *t;
   267 		FOR_ALL_TOWNS(t) {
   267 		FOR_ALL_TOWNS(t) {
   268 			/* If a player takes over, give the ratings to that player. */
   268 			/* If a player takes over, give the ratings to that player. */
   269 			if (IsValidTown(t) && HASBIT(t->have_ratings, old_player)) {
   269 			if (HASBIT(t->have_ratings, old_player)) {
   270 				if (HASBIT(t->have_ratings, new_player)) {
   270 				if (HASBIT(t->have_ratings, new_player)) {
   271 					// use max of the two ratings.
   271 					// use max of the two ratings.
   272 					t->ratings[new_player] = max(t->ratings[new_player], t->ratings[old_player]);
   272 					t->ratings[new_player] = max(t->ratings[new_player], t->ratings[old_player]);
   273 				} else {
   273 				} else {
   274 					SETBIT(t->have_ratings, new_player);
   274 					SETBIT(t->have_ratings, new_player);
   275 					t->ratings[new_player] = t->ratings[old_player];
   275 					t->ratings[new_player] = t->ratings[old_player];
   276 				}
   276 				}
   277 			}
   277 			}
   278 
   278 
   279 			/* Reset ratings for the town */
   279 			t->ratings[old_player] = 500;
   280 			if (IsValidTown(t)) {
   280 			CLRBIT(t->have_ratings, old_player);
   281 				t->ratings[old_player] = 500;
       
   282 				CLRBIT(t->have_ratings, old_player);
       
   283 			}
       
   284 		}
   281 		}
   285 	}
   282 	}
   286 
   283 
   287 	{
   284 	{
   288 		int num_train = 0;
   285 		int num_train = 0;
   571 {
   568 {
   572 	Station *st;
   569 	Station *st;
   573 	Player *p;
   570 	Player *p;
   574 
   571 
   575 	FOR_ALL_STATIONS(st) {
   572 	FOR_ALL_STATIONS(st) {
   576 		if (st->xy != 0) {
   573 		_current_player = st->owner;
   577 			_current_player = st->owner;
   574 		SET_EXPENSES_TYPE(EXPENSES_PROPERTY);
   578 			SET_EXPENSES_TYPE(EXPENSES_PROPERTY);
   575 		SubtractMoneyFromPlayer(_price.station_value >> 1);
   579 			SubtractMoneyFromPlayer(_price.station_value >> 1);
       
   580 		}
       
   581 	}
   576 	}
   582 
   577 
   583 	if (!HASBIT(1<<0|1<<3|1<<6|1<<9, _cur_month))
   578 	if (!HASBIT(1<<0|1<<3|1<<6|1<<9, _cur_month))
   584 		return;
   579 		return;
   585 
   580 
   886 	Town *from,*to;
   881 	Town *from,*to;
   887 
   882 
   888 	fr->distance = (uint)-1;
   883 	fr->distance = (uint)-1;
   889 
   884 
   890 	fr->from = from = GetTown(RandomRange(_total_towns));
   885 	fr->from = from = GetTown(RandomRange(_total_towns));
   891 	if (from->xy == 0 || from->population < 400)
   886 	if (!IsValidTown(from) || from->population < 400)
   892 		return;
   887 		return;
   893 
   888 
   894 	fr->to = to = GetTown(RandomRange(_total_towns));
   889 	fr->to = to = GetTown(RandomRange(_total_towns));
   895 	if (from==to || to->xy == 0 || to->population < 400 || to->pct_pass_transported > 42)
   890 	if (from == to || !IsValidTown(to) || to->population < 400 || to->pct_pass_transported > 42)
   896 		return;
   891 		return;
   897 
   892 
   898 	fr->distance = DistanceManhattan(from->xy, to->xy);
   893 	fr->distance = DistanceManhattan(from->xy, to->xy);
   899 }
   894 }
   900 
   895 
   905 	CargoID cargo;
   900 	CargoID cargo;
   906 
   901 
   907 	fr->distance = (uint)-1;
   902 	fr->distance = (uint)-1;
   908 
   903 
   909 	fr->from = i = GetIndustry(RandomRange(_total_industries));
   904 	fr->from = i = GetIndustry(RandomRange(_total_industries));
   910 	if (i->xy == 0)
   905 	if (!IsValidIndustry(i)) return;
   911 		return;
       
   912 
   906 
   913 	// Randomize cargo type
   907 	// Randomize cargo type
   914 	if (Random()&1 && i->produced_cargo[1] != CT_INVALID) {
   908 	if (Random()&1 && i->produced_cargo[1] != CT_INVALID) {
   915 		cargo = i->produced_cargo[1];
   909 		cargo = i->produced_cargo[1];
   916 		trans = i->pct_transported[1];
   910 		trans = i->pct_transported[1];
   932 	if (cargo == CT_GOODS || cargo == CT_FOOD) {
   926 	if (cargo == CT_GOODS || cargo == CT_FOOD) {
   933 		// The destination is a town
   927 		// The destination is a town
   934 		Town *t = GetTown(RandomRange(_total_towns));
   928 		Town *t = GetTown(RandomRange(_total_towns));
   935 
   929 
   936 		// Only want big towns
   930 		// Only want big towns
   937 		if (t->xy == 0 || t->population < 900)
   931 		if (!IsValidTown(t) || t->population < 900) return;
   938 			return;
   932 
   939 		fr->distance = DistanceManhattan(i->xy, t->xy);
   933 		fr->distance = DistanceManhattan(i->xy, t->xy);
   940 		fr->to = t;
   934 		fr->to = t;
   941 	} else {
   935 	} else {
   942 		// The destination is an industry
   936 		// The destination is an industry
   943 		Industry *i2 = GetIndustry(RandomRange(_total_industries));
   937 		Industry *i2 = GetIndustry(RandomRange(_total_industries));
   944 
   938 
   945 		// The industry must accept the cargo
   939 		// The industry must accept the cargo
   946 		if (i == i2 || i2->xy == 0 ||
   940 		if (i == i2 || !IsValidIndustry(i2) ||
   947 				(cargo != i2->accepts_cargo[0] &&
   941 				(cargo != i2->accepts_cargo[0] &&
   948 				cargo != i2->accepts_cargo[1] &&
   942 				cargo != i2->accepts_cargo[1] &&
   949 				cargo != i2->accepts_cargo[2]))
   943 				cargo != i2->accepts_cargo[2]))
   950 			return;
   944 			return;
   951 		fr->distance = DistanceManhattan(i->xy, i2->xy);
   945 		fr->distance = DistanceManhattan(i->xy, i2->xy);
  1111 	//       2) Distribute between industries if more then one is present
  1105 	//       2) Distribute between industries if more then one is present
  1112 	u = (_patches.station_spread + 8) * 2;
  1106 	u = (_patches.station_spread + 8) * 2;
  1113 	FOR_ALL_INDUSTRIES(ind) {
  1107 	FOR_ALL_INDUSTRIES(ind) {
  1114 		uint t;
  1108 		uint t;
  1115 
  1109 
  1116 		if (ind->xy != 0 && (
  1110 		if (( cargo_type == ind->accepts_cargo[0] ||
  1117 					cargo_type == ind->accepts_cargo[0] ||
       
  1118 					cargo_type == ind->accepts_cargo[1] ||
  1111 					cargo_type == ind->accepts_cargo[1] ||
  1119 					cargo_type == ind->accepts_cargo[2]
  1112 					cargo_type == ind->accepts_cargo[2]
  1120 				) &&
  1113 				) &&
  1121 				ind->produced_cargo[0] != CT_INVALID &&
  1114 				ind->produced_cargo[0] != CT_INVALID &&
  1122 				ind->produced_cargo[0] != cargo_type &&
  1115 				ind->produced_cargo[0] != cargo_type &&