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 } |