(svn r1728) - Fix: now a player can only build a road vehicle in depots he owns (hacked client protection)

This commit is contained in:
bjarni 2005-01-30 13:42:11 +00:00
parent 5987455d35
commit e8f4b7cf19
2 changed files with 8 additions and 4 deletions

8
ai.c
View File

@ -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;

View File

@ -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);