ai_new.c
changeset 826 fff56bbc3606
parent 679 04ca2cd69420
child 900 27eb21ced433
equal deleted inserted replaced
825:66d2d61e77a8 826:fff56bbc3606
   406 
   406 
   407    		if (p->ainew.from_type == AI_CITY && p->ainew.tbt == AI_BUS) {
   407    		if (p->ainew.from_type == AI_CITY && p->ainew.tbt == AI_BUS) {
   408    			int max_cargo = DEREF_TOWN(p->ainew.from_ic)->max_pass + DEREF_TOWN(p->ainew.temp)->max_pass;
   408    			int max_cargo = DEREF_TOWN(p->ainew.from_ic)->max_pass + DEREF_TOWN(p->ainew.temp)->max_pass;
   409    			max_cargo -= DEREF_TOWN(p->ainew.from_ic)->act_pass + DEREF_TOWN(p->ainew.temp)->act_pass;
   409    			max_cargo -= DEREF_TOWN(p->ainew.from_ic)->act_pass + DEREF_TOWN(p->ainew.temp)->act_pass;
   410    			// max_cargo is now the amount of cargo we can move between the two cities
   410    			// max_cargo is now the amount of cargo we can move between the two cities
   411    			// If it is more then the distance, we allow it
   411    			// If it is more than the distance, we allow it
   412    			if (GetTileDist(DEREF_TOWN(p->ainew.from_ic)->xy, DEREF_TOWN(p->ainew.temp)->xy) <= max_cargo * AI_LOCATEROUTE_BUS_CARGO_DISTANCE) {
   412    			if (GetTileDist(DEREF_TOWN(p->ainew.from_ic)->xy, DEREF_TOWN(p->ainew.temp)->xy) <= max_cargo * AI_LOCATEROUTE_BUS_CARGO_DISTANCE) {
   413    				// We found a good city/industry, save the data of it
   413    				// We found a good city/industry, save the data of it
   414    				p->ainew.to_ic = p->ainew.temp;
   414    				p->ainew.to_ic = p->ainew.temp;
   415    				p->ainew.state = AI_STATE_FIND_STATION;
   415    				p->ainew.state = AI_STATE_FIND_STATION;
   416 
   416 
   491    	// Don't do an attempt if we are trying the same id as the last time...
   491    	// Don't do an attempt if we are trying the same id as the last time...
   492    	if (p->ainew.last_id == p->ainew.temp) return;
   492    	if (p->ainew.last_id == p->ainew.temp) return;
   493    	p->ainew.last_id = p->ainew.temp;
   493    	p->ainew.last_id = p->ainew.temp;
   494 }
   494 }
   495 
   495 
   496 // Check if there are not more then a certain amount of vehicles pointed to a certain
   496 // Check if there are not more than a certain amount of vehicles pointed to a certain
   497 //  station. This to prevent 10 busses going to one station, which gives... problems ;)
   497 //  station. This to prevent 10 busses going to one station, which gives... problems ;)
   498 static bool AiNew_CheckVehicleStation(Player *p, Station *st) {
   498 static bool AiNew_CheckVehicleStation(Player *p, Station *st) {
   499 	int count = 0;
   499 	int count = 0;
   500 	Vehicle *v;
   500 	Vehicle *v;
   501 
   501 
   556     	return;
   556     	return;
   557     }
   557     }
   558 
   558 
   559     // First, we are going to look at the stations that already exist inside the city
   559     // First, we are going to look at the stations that already exist inside the city
   560     //  If there is enough cargo left in the station, we take that station
   560     //  If there is enough cargo left in the station, we take that station
   561     //  If that is not possible, and there are more then 2 stations in the city, abort
   561     //  If that is not possible, and there are more than 2 stations in the city, abort
   562 	i = AiNew_PickVehicle(p);
   562 	i = AiNew_PickVehicle(p);
   563 	// Euhmz, this should not happen _EVER_
   563 	// Euhmz, this should not happen _EVER_
   564 	// Quit finding a route...
   564 	// Quit finding a route...
   565 	if (i == -1) { p->ainew.state = AI_STATE_NOTHING; return; }
   565 	if (i == -1) { p->ainew.state = AI_STATE_NOTHING; return; }
   566 
   566 
   586 			}
   586 			}
   587 		}
   587 		}
   588 	}
   588 	}
   589 	// We are going to add a new station...
   589 	// We are going to add a new station...
   590 	if (new_tile == 0) count++;
   590 	if (new_tile == 0) count++;
   591 	// No more then 2 stations allowed in a city
   591 	// No more than 2 stations allowed in a city
   592 	//  This is because only the best 2 stations of one cargo do get any cargo
   592 	//  This is because only the best 2 stations of one cargo do get any cargo
   593 	if (count > 2) {
   593 	if (count > 2) {
   594 		p->ainew.state = AI_STATE_NOTHING;
   594 		p->ainew.state = AI_STATE_NOTHING;
   595 		return;
   595 		return;
   596 	}
   596 	}
   849     	if (p->ainew.from_deliver)
   849     	if (p->ainew.from_deliver)
   850     		max_cargo = DEREF_INDUSTRY(p->ainew.from_ic)->total_production[0];
   850     		max_cargo = DEREF_INDUSTRY(p->ainew.from_ic)->total_production[0];
   851     	else
   851     	else
   852     		max_cargo = DEREF_INDUSTRY(p->ainew.to_ic)->total_production[0];
   852     		max_cargo = DEREF_INDUSTRY(p->ainew.to_ic)->total_production[0];
   853 
   853 
   854     	// This is because moving 60% is more then we can dream of!
   854     	// This is because moving 60% is more than we can dream of!
   855     	max_cargo *= 0.6;
   855     	max_cargo *= 0.6;
   856     	// We want all the cargo to be gone in a month.. so, we know the cargo it delivers
   856     	// We want all the cargo to be gone in a month.. so, we know the cargo it delivers
   857     	//  we know what the vehicle takes with him, and we know the time it takes him
   857     	//  we know what the vehicle takes with him, and we know the time it takes him
   858     	//  to get back here.. now let's do some math!
   858     	//  to get back here.. now let's do some math!
   859 			amount = 2 * length * max_cargo / tiles_a_day / 30 / RoadVehInfo(i)->capacity;
   859 			amount = 2 * length * max_cargo / tiles_a_day / 30 / RoadVehInfo(i)->capacity;
  1132         return;
  1132         return;
  1133     } else {
  1133     } else {
  1134         p->ainew.veh_main_id = p->ainew.veh_id;
  1134         p->ainew.veh_main_id = p->ainew.veh_id;
  1135     }
  1135     }
  1136 
  1136 
  1137     // When more then 1 vehicle, we send them to different directions
  1137     // When more than 1 vehicle, we send them to different directions
  1138 		idx = 0;
  1138 		idx = 0;
  1139 		order.type = OT_GOTO_STATION;
  1139 		order.type = OT_GOTO_STATION;
  1140 		order.flags = 0;
  1140 		order.flags = 0;
  1141 		order.station = _map2[p->ainew.from_tile];
  1141 		order.station = _map2[p->ainew.from_tile];
  1142     if (p->ainew.tbt == AI_TRUCK && p->ainew.from_deliver)
  1142     if (p->ainew.tbt == AI_TRUCK && p->ainew.from_deliver)
  1186 	// When a vehicle is under the 6 months, we don't check for anything
  1186 	// When a vehicle is under the 6 months, we don't check for anything
  1187 	if (v->age < 180) return;
  1187 	if (v->age < 180) return;
  1188 
  1188 
  1189 	// When a vehicle is older then 1 year, it should make money...
  1189 	// When a vehicle is older then 1 year, it should make money...
  1190 	if (v->age > 360) {
  1190 	if (v->age > 360) {
  1191 		// If both years together are not more then AI_MINIMUM_ROUTE_PROFIT,
  1191 		// If both years together are not more than AI_MINIMUM_ROUTE_PROFIT,
  1192 		//  it is not worth the line I guess...
  1192 		//  it is not worth the line I guess...
  1193 		if (v->profit_last_year + v->profit_this_year < AI_MINIMUM_ROUTE_PROFIT ||
  1193 		if (v->profit_last_year + v->profit_this_year < AI_MINIMUM_ROUTE_PROFIT ||
  1194 			(v->reliability * 100 >> 16) < 40) {
  1194 			(v->reliability * 100 >> 16) < 40) {
  1195 			// There is a possibility that the route is fucked up...
  1195 			// There is a possibility that the route is fucked up...
  1196 			if (v->cargo_days > AI_VEHICLE_LOST_DAYS) {
  1196 			if (v->cargo_days > AI_VEHICLE_LOST_DAYS) {