mirror of
https://github.com/JGRennison/OpenTTD-patches.git
synced 2024-11-17 21:25:40 +00:00
(svn r1727) - Fix: now CmdBuildRailVehicle() behaves correctly if DC_EXEC is set
this commit alters ai.c a little to get rid of the workaround from r1725 so AI players could still build locomotives
This commit is contained in:
parent
cc7f7220c0
commit
5987455d35
8
ai.c
8
ai.c
@ -116,7 +116,7 @@ static void AiStateVehLoop(Player *p)
|
|||||||
p->ai.state_counter = 0;
|
p->ai.state_counter = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int AiChooseTrainToBuild(byte railtype, int32 money, byte flag)
|
static int AiChooseTrainToBuild(byte railtype, int32 money, byte flag, TileIndex tile)
|
||||||
{
|
{
|
||||||
int best_veh_index = -1;
|
int best_veh_index = -1;
|
||||||
byte best_veh_score = 0;
|
byte best_veh_score = 0;
|
||||||
@ -131,7 +131,7 @@ static int AiChooseTrainToBuild(byte railtype, int32 money, byte flag)
|
|||||||
|| !HASBIT(e->player_avail, _current_player) || e->reliability < 0x8A3D)
|
|| !HASBIT(e->player_avail, _current_player) || e->reliability < 0x8A3D)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
r = DoCommandByTile(0, i, 0, 0, CMD_BUILD_RAIL_VEHICLE);
|
r = DoCommandByTile(tile, i, 0, 0, CMD_BUILD_RAIL_VEHICLE);
|
||||||
if (r != CMD_ERROR &&
|
if (r != CMD_ERROR &&
|
||||||
(!(_cmd_build_rail_veh_var1&1) || !(flag&1)) &&
|
(!(_cmd_build_rail_veh_var1&1) || !(flag&1)) &&
|
||||||
r <= money &&
|
r <= money &&
|
||||||
@ -238,7 +238,7 @@ static int AiChooseTrainToReplaceWith(Player *p, Vehicle *v)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// XXX: check if a wagon
|
// XXX: check if a wagon
|
||||||
return AiChooseTrainToBuild(v->u.rail.railtype, avail_money, 0);
|
return AiChooseTrainToBuild(v->u.rail.railtype, avail_money, 0, v->tile);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int AiChooseShipToReplaceWith(Player *p, Vehicle *v)
|
static int AiChooseShipToReplaceWith(Player *p, Vehicle *v)
|
||||||
@ -2393,7 +2393,7 @@ static void AiStateBuildRailVeh(Player *p)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Which locomotive to build?
|
// Which locomotive to build?
|
||||||
veh = AiChooseTrainToBuild(p->ai.railtype_to_use, p->player_money, (cargo!=CT_PASSENGERS)?1:0);
|
veh = AiChooseTrainToBuild(p->ai.railtype_to_use, p->player_money, (cargo!=CT_PASSENGERS)?1:0, tile);
|
||||||
if (veh == -1) {
|
if (veh == -1) {
|
||||||
handle_nocash:
|
handle_nocash:
|
||||||
// after a while, if AI still doesn't have cash, get out of this block by selling the wagons.
|
// after a while, if AI still doesn't have cash, get out of this block by selling the wagons.
|
||||||
|
@ -528,11 +528,9 @@ int32 CmdBuildRailVehicle(int x, int y, uint32 flags, uint32 p1, uint32 p2)
|
|||||||
|
|
||||||
if (!IsEngineBuildable(p1, VEH_Train)) return CMD_ERROR;
|
if (!IsEngineBuildable(p1, VEH_Train)) return CMD_ERROR;
|
||||||
|
|
||||||
/* NOTE: The AI sends build engine commands without DC_EXEC to figure out if
|
if (!IsTrainDepotTile((TileIndex)tile)) return CMD_ERROR;
|
||||||
it can affort an engine before trying to buy it*/
|
|
||||||
if (!IsTrainDepotTile((TileIndex)tile) && flags & DC_EXEC) return CMD_ERROR;
|
|
||||||
|
|
||||||
if (_map_owner[tile] != _current_player && flags & DC_EXEC) return CMD_ERROR;
|
if (_map_owner[tile] != _current_player) return CMD_ERROR;
|
||||||
|
|
||||||
_cmd_build_rail_veh_var1 = 0;
|
_cmd_build_rail_veh_var1 = 0;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user