summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ai.c8
-rw-r--r--roadveh_cmd.c4
2 files changed, 8 insertions, 4 deletions
diff --git a/ai.c b/ai.c
index edc7b2703..ed5df3334 100644
--- a/ai.c
+++ b/ai.c
@@ -144,7 +144,7 @@ static int AiChooseTrainToBuild(byte railtype, int32 money, byte flag, TileIndex
return best_veh_index;
}
-static int AiChooseRoadVehToBuild(byte cargo, int32 money)
+static int AiChooseRoadVehToBuild(byte cargo, int32 money, TileIndex tile)
{
int best_veh_index = -1;
int32 best_veh_cost = 0;
@@ -157,7 +157,7 @@ static int AiChooseRoadVehToBuild(byte cargo, int32 money)
if (!HASBIT(e->player_avail, _current_player) || e->reliability < 0x8A3D)
continue;
- r = DoCommandByTile(0, i, 0, 0, CMD_BUILD_ROAD_VEH);
+ r = DoCommandByTile(tile, i, 0, 0, CMD_BUILD_ROAD_VEH);
if (r != CMD_ERROR && r <= money && r >= best_veh_cost) {
best_veh_cost = r;
best_veh_index = i;
@@ -218,7 +218,7 @@ static int AiChooseShipToBuild(byte cargo, int32 money)
static int AiChooseRoadVehToReplaceWith(Player *p, Vehicle *v)
{
int32 avail_money = p->player_money + v->value;
- return AiChooseRoadVehToBuild(v->cargo_type, avail_money);
+ return AiChooseRoadVehToBuild(v->cargo_type, avail_money, v->tile);
}
static int AiChooseAircraftToReplaceWith(Player *p, Vehicle *v)
@@ -3173,7 +3173,7 @@ static void AiStateBuildRoadVehicles(Player *p)
for(;ptr->mode != 0;ptr++) {}
tile = TILE_ADD(p->ai.src.use_tile, ToTileIndexDiff(ptr->tileoffs));
- veh = AiChooseRoadVehToBuild(p->ai.cargo_type, p->player_money);
+ veh = AiChooseRoadVehToBuild(p->ai.cargo_type, p->player_money, tile);
if (veh == -1) {
p->ai.state = AIS_0;
return;
diff --git a/roadveh_cmd.c b/roadveh_cmd.c
index 445530008..64e92d28f 100644
--- a/roadveh_cmd.c
+++ b/roadveh_cmd.c
@@ -118,6 +118,10 @@ int32 CmdBuildRoadVeh(int x, int y, uint32 flags, uint32 p1, uint32 p2)
if (!IsEngineBuildable(p1, VEH_Road)) return CMD_ERROR;
+ if (!IsRoadDepotTile((TileIndex)tile)) return CMD_ERROR;
+
+ if (_map_owner[tile] != _current_player) return CMD_ERROR;
+
SET_EXPENSES_TYPE(EXPENSES_NEW_VEHICLES);
cost = EstimateRoadVehCost(p1);