src/ai/trolly/trolly.cpp
branchgamebalance
changeset 9912 1ac8aac92385
parent 9911 0b8b245a2391
child 9913 e79cd19772dd
equal deleted inserted replaced
9911:0b8b245a2391 9912:1ac8aac92385
   278 
   278 
   279 		if (i->town != NULL && i->town->ratings[_current_player] < 0 && AI_CHANCE16(1, 4)) return false;
   279 		if (i->town != NULL && i->town->ratings[_current_player] < 0 && AI_CHANCE16(1, 4)) return false;
   280 
   280 
   281 		// No limits on delevering stations!
   281 		// No limits on delevering stations!
   282 		//  Or for industry that does not give anything yet
   282 		//  Or for industry that does not give anything yet
   283 		if (indsp->produced_cargo[0] == CT_INVALID || i->total_production[0] == 0) return true;
   283 		if (indsp->produced_cargo[0] == CT_INVALID || i->last_month_production[0] == 0) return true;
   284 
   284 
   285 		if (i->total_production[0] - i->total_transported[0] < AI_CHECKCITY_NEEDED_CARGO) return false;
   285 		if (i->last_month_production[0] - i->last_month_transported[0] < AI_CHECKCITY_NEEDED_CARGO) return false;
   286 
   286 
   287 		// Check if we have build a station in this town the last 6 months
   287 		// Check if we have build a station in this town the last 6 months
   288 		//  else we don't do it. This is done, because stat updates can be slow
   288 		//  else we don't do it. This is done, because stat updates can be slow
   289 		//  and sometimes it takes up to 4 months before the stats are corectly.
   289 		//  and sometimes it takes up to 4 months before the stats are corectly.
   290 		FOR_ALL_STATIONS(st) {
   290 		FOR_ALL_STATIONS(st) {
   320 		}
   320 		}
   321 
   321 
   322 		// We are about to add one...
   322 		// We are about to add one...
   323 		count++;
   323 		count++;
   324 		// Check if we the city can provide enough cargo for this amount of stations..
   324 		// Check if we the city can provide enough cargo for this amount of stations..
   325 		if (count * AI_CHECKCITY_CARGO_PER_STATION > i->total_production[0]) return false;
   325 		if (count * AI_CHECKCITY_CARGO_PER_STATION > i->last_month_production[0]) return false;
   326 
   326 
   327 		// All check are okay, so we can build here!
   327 		// All check are okay, so we can build here!
   328 		return true;
   328 		return true;
   329 	}
   329 	}
   330 
   330 
   466 			int max_cargo = 0;
   466 			int max_cargo = 0;
   467 			uint i;
   467 			uint i;
   468 
   468 
   469 			// TODO: in max_cargo, also check other cargo (beside [0])
   469 			// TODO: in max_cargo, also check other cargo (beside [0])
   470 			// First we check if the from_ic produces cargo that this ic accepts
   470 			// First we check if the from_ic produces cargo that this ic accepts
   471 			if (indsp_from->produced_cargo[0] != CT_INVALID && ind_from->total_production[0] != 0) {
   471 			if (indsp_from->produced_cargo[0] != CT_INVALID && ind_from->last_month_production[0] != 0) {
   472 				for (i = 0; i < lengthof(indsp_temp->accepts_cargo); i++) {
   472 				for (i = 0; i < lengthof(indsp_temp->accepts_cargo); i++) {
   473 					if (indsp_temp->accepts_cargo[i] == CT_INVALID) break;
   473 					if (indsp_temp->accepts_cargo[i] == CT_INVALID) break;
   474 					if (indsp_from->produced_cargo[0] == indsp_temp->accepts_cargo[i]) {
   474 					if (indsp_from->produced_cargo[0] == indsp_temp->accepts_cargo[i]) {
   475 						// Found a compatible industry
   475 						// Found a compatible industry
   476 						max_cargo = ind_from->total_production[0] - ind_from->total_transported[0];
   476 						max_cargo = ind_from->last_month_production[0] - ind_from->last_month_transported[0];
   477 						found = true;
   477 						found = true;
   478 						p->ainew.from_deliver = true;
   478 						p->ainew.from_deliver = true;
   479 						p->ainew.to_deliver = false;
   479 						p->ainew.to_deliver = false;
   480 						break;
   480 						break;
   481 					}
   481 					}
   482 				}
   482 				}
   483 			}
   483 			}
   484 			if (!found && indsp_temp->produced_cargo[0] != CT_INVALID && ind_temp->total_production[0] != 0) {
   484 			if (!found && indsp_temp->produced_cargo[0] != CT_INVALID && ind_temp->last_month_production[0] != 0) {
   485 				// If not check if the current ic produces cargo that the from_ic accepts
   485 				// If not check if the current ic produces cargo that the from_ic accepts
   486 				for (i = 0; i < lengthof(indsp_from->accepts_cargo); i++) {
   486 				for (i = 0; i < lengthof(indsp_from->accepts_cargo); i++) {
   487 					if (indsp_from->accepts_cargo[i] == CT_INVALID) break;
   487 					if (indsp_from->accepts_cargo[i] == CT_INVALID) break;
   488 					if (indsp_from->produced_cargo[0] == indsp_from->accepts_cargo[i]) {
   488 					if (indsp_from->produced_cargo[0] == indsp_from->accepts_cargo[i]) {
   489 						// Found a compatbiel industry
   489 						// Found a compatbiel industry
   490 						found = true;
   490 						found = true;
   491 						max_cargo = ind_temp->total_production[0] - ind_temp->total_transported[0];
   491 						max_cargo = ind_temp->last_month_production[0] - ind_temp->last_month_transported[0];
   492 						p->ainew.from_deliver = false;
   492 						p->ainew.from_deliver = false;
   493 						p->ainew.to_deliver = true;
   493 						p->ainew.to_deliver = true;
   494 						break;
   494 						break;
   495 					}
   495 					}
   496 				}
   496 				}
   896 		// Passenger run.. how long is the route?
   896 		// Passenger run.. how long is the route?
   897 		length = p->ainew.path_info.route_length;
   897 		length = p->ainew.path_info.route_length;
   898 		// Calculating tiles a day a vehicle moves is not easy.. this is how it must be done!
   898 		// Calculating tiles a day a vehicle moves is not easy.. this is how it must be done!
   899 		tiles_a_day = RoadVehInfo(i)->max_speed * DAY_TICKS / 256 / 16;
   899 		tiles_a_day = RoadVehInfo(i)->max_speed * DAY_TICKS / 256 / 16;
   900 		if (p->ainew.from_deliver) {
   900 		if (p->ainew.from_deliver) {
   901 			max_cargo = GetIndustry(p->ainew.from_ic)->total_production[0];
   901 			max_cargo = GetIndustry(p->ainew.from_ic)->last_month_production[0];
   902 		} else {
   902 		} else {
   903 			max_cargo = GetIndustry(p->ainew.to_ic)->total_production[0];
   903 			max_cargo = GetIndustry(p->ainew.to_ic)->last_month_production[0];
   904 		}
   904 		}
   905 
   905 
   906 		// This is because moving 60% is more than we can dream of!
   906 		// This is because moving 60% is more than we can dream of!
   907 		max_cargo *= 6;
   907 		max_cargo *= 6;
   908 		max_cargo /= 10;
   908 		max_cargo /= 10;
  1222 	assert(p->ainew.state == AI_STATE_START_VEHICLE);
  1222 	assert(p->ainew.state == AI_STATE_START_VEHICLE);
  1223 
  1223 
  1224 	// Skip the first order if it is a second vehicle
  1224 	// Skip the first order if it is a second vehicle
  1225 	//  This to make vehicles go different ways..
  1225 	//  This to make vehicles go different ways..
  1226 	if (p->ainew.cur_veh & 1)
  1226 	if (p->ainew.cur_veh & 1)
  1227 		AI_DoCommand(0, p->ainew.veh_id, 0, DC_EXEC, CMD_SKIP_ORDER);
  1227 		AI_DoCommand(0, p->ainew.veh_id, 1, DC_EXEC, CMD_SKIP_TO_ORDER);
  1228 
  1228 
  1229 	// 3, 2, 1... go! (give START_STOP command ;))
  1229 	// 3, 2, 1... go! (give START_STOP command ;))
  1230 	AI_DoCommand(0, p->ainew.veh_id, 0, DC_EXEC, CMD_START_STOP_ROADVEH);
  1230 	AI_DoCommand(0, p->ainew.veh_id, 0, DC_EXEC, CMD_START_STOP_ROADVEH);
  1231 	// Try to build an other vehicle (that function will stop building when needed)
  1231 	// Try to build an other vehicle (that function will stop building when needed)
  1232 	p->ainew.idle  = 10;
  1232 	p->ainew.idle  = 10;