src/ai/trolly/build.cpp
changeset 8254 5de2bbd26163
parent 7866 e19fda04e8d3
child 8424 4a488a90ccab
equal deleted inserted replaced
8253:07efd7789987 8254:5de2bbd26163
   183 			return cost;
   183 			return cost;
   184 		}
   184 		}
   185 
   185 
   186 		// Build normal road
   186 		// Build normal road
   187 		// Keep it doing till we go an other way
   187 		// Keep it doing till we go an other way
   188 		// EnsureNoVehicle makes sure we don't build on a tile where a vehicle is. This way
   188 		// EnsureNoVehicleOnGround makes sure we don't build on a tile where a vehicle is. This way
   189 		//  it will wait till the vehicle is gone..
   189 		//  it will wait till the vehicle is gone..
   190 		if (route_extra[part-1] == 0 && route_extra[part] == 0 && (flag != DC_EXEC || EnsureNoVehicle(route[part]))) {
   190 		if (route_extra[part-1] == 0 && route_extra[part] == 0 && (flag != DC_EXEC || EnsureNoVehicleOnGround(route[part]))) {
   191 			while (route_extra[part] == 0 && (flag != DC_EXEC || EnsureNoVehicle(route[part]))) {
   191 			while (route_extra[part] == 0 && (flag != DC_EXEC || EnsureNoVehicleOnGround(route[part]))) {
   192 				// Get the current direction
   192 				// Get the current direction
   193 				dir = AiNew_GetRoadDirection(route[part-1], route[part], route[part+1]);
   193 				dir = AiNew_GetRoadDirection(route[part-1], route[part], route[part+1]);
   194 				// Is it the same as the last one?
   194 				// Is it the same as the last one?
   195 				if (old_dir != -1 && old_dir != dir) break;
   195 				if (old_dir != -1 && old_dir != dir) break;
   196 				old_dir = dir;
   196 				old_dir = dir;
   197 				// There is already some road, and it is a bridge.. don't build!!!
   197 				// There is already some road, and it is a bridge.. don't build!!!
   198 				if (!IsTileType(route[part], MP_TUNNELBRIDGE)) {
   198 				if (!IsTileType(route[part], MP_TUNNELBRIDGE)) {
   199 					// Build the tile
   199 					// Build the tile
   200 					res = AI_DoCommand(route[part], dir, 0, flag | DC_NO_WATER, CMD_BUILD_ROAD);
   200 					res = AI_DoCommand(route[part], dir, 0, flag | DC_NO_WATER, CMD_BUILD_ROAD);
   201 					// Currently, we ignore CMD_ERRORs!
   201 					// Currently, we ignore CMD_ERRORs!
   202 					if (CmdFailed(res) && flag == DC_EXEC && !IsTileType(route[part], MP_ROAD) && !EnsureNoVehicle(route[part])) {
   202 					if (CmdFailed(res) && flag == DC_EXEC && !IsTileType(route[part], MP_ROAD) && !EnsureNoVehicleOnGround(route[part])) {
   203 						// Problem.. let's just abort it all!
   203 						// Problem.. let's just abort it all!
   204 						DEBUG(ai, 0, "[BuidPath] route building failed at tile 0x%X, aborting", route[part]);
   204 						DEBUG(ai, 0, "[BuidPath] route building failed at tile 0x%X, aborting", route[part]);
   205 						p->ainew.state = AI_STATE_NOTHING;
   205 						p->ainew.state = AI_STATE_NOTHING;
   206 						return CommandCost();
   206 						return CommandCost();
   207 					}
   207 					}
   214 				if (part >= PathFinderInfo->route_length - 1) break;
   214 				if (part >= PathFinderInfo->route_length - 1) break;
   215 			}
   215 			}
   216 			part--;
   216 			part--;
   217 			// We want to return the last position, so we go back one
   217 			// We want to return the last position, so we go back one
   218 		}
   218 		}
   219 		if (!EnsureNoVehicle(route[part]) && flag == DC_EXEC) part--;
   219 		if (!EnsureNoVehicleOnGround(route[part]) && flag == DC_EXEC) part--;
   220 		PathFinderInfo->position = part;
   220 		PathFinderInfo->position = part;
   221 	}
   221 	}
   222 
   222 
   223 	return cost;
   223 	return cost;
   224 }
   224 }