(svn r7057) -Codechange: Remove hardcoded lists of road vehicles for each cargo type in favour of just checking the cargo type of each vehicle.

This commit is contained in:
peter1138 2006-11-03 23:06:54 +00:00
parent ac2b6f39b1
commit 8cfe4d6a67
5 changed files with 10 additions and 28 deletions

View File

@ -163,8 +163,8 @@ static EngineID AiChooseRoadVehToBuild(CargoID cargo, int32 money, TileIndex til
{ {
EngineID best_veh_index = INVALID_ENGINE; EngineID best_veh_index = INVALID_ENGINE;
int32 best_veh_cost = 0; int32 best_veh_cost = 0;
EngineID i = _cargoc.ai_roadveh_start[cargo]; EngineID i = ROAD_ENGINES_INDEX;
EngineID end = i + _cargoc.ai_roadveh_count[cargo]; EngineID end = i + NUM_ROAD_ENGINES;
for (; i != end; i++) { for (; i != end; i++) {
const Engine* e = GetEngine(i); const Engine* e = GetEngine(i);
@ -174,6 +174,9 @@ static EngineID AiChooseRoadVehToBuild(CargoID cargo, int32 money, TileIndex til
continue; continue;
} }
/* Skip vehicles which can't take our cargo type */
if (RoadVehInfo(i)->cargo_type != cargo) continue;
ret = DoCommand(tile, i, 0, 0, CMD_BUILD_ROAD_VEH); ret = DoCommand(tile, i, 0, 0, CMD_BUILD_ROAD_VEH);
if (!CmdFailed(ret) && ret <= money && ret >= best_veh_cost) { if (!CmdFailed(ret) && ret <= money && ret >= best_veh_cost) {
best_veh_cost = ret; best_veh_cost = ret;

View File

@ -232,8 +232,8 @@ EngineID AiNew_PickVehicle(Player *p)
// Not supported yet // Not supported yet
return INVALID_ENGINE; return INVALID_ENGINE;
} else { } else {
EngineID start = _cargoc.ai_roadveh_start[p->ainew.cargo]; EngineID start = ROAD_ENGINES_INDEX;
EngineID end = start + _cargoc.ai_roadveh_count[p->ainew.cargo]; EngineID end = ROAD_ENGINES_INDEX + NUM_ROAD_ENGINES;
EngineID i; EngineID i;
// Let's check it backwards.. we simply want to best engine available.. // Let's check it backwards.. we simply want to best engine available..
@ -241,6 +241,9 @@ EngineID AiNew_PickVehicle(Player *p)
const Engine* e = GetEngine(i); const Engine* e = GetEngine(i);
int32 ret; int32 ret;
/* Skip vehicles which can't take our cargo type */
if (RoadVehInfo(i)->cargo_type != p->ainew.cargo) continue;
// Is it availiable? // Is it availiable?
// Also, check if the reliability of the vehicle is above the AI_VEHICLE_MIN_RELIABILTY // Also, check if the reliability of the vehicle is above the AI_VEHICLE_MIN_RELIABILTY
if (!HASBIT(e->player_avail, _current_player) || e->reliability * 100 < AI_VEHICLE_MIN_RELIABILTY << 16) continue; if (!HASBIT(e->player_avail, _current_player) || e->reliability * 100 < AI_VEHICLE_MIN_RELIABILTY << 16) continue;

3
misc.c
View File

@ -211,9 +211,6 @@ void InitializeLandscapeVariables(bool only_constants)
lpd = &_cargo_types_base_values[_opt.landscape]; lpd = &_cargo_types_base_values[_opt.landscape];
memcpy(_cargoc.ai_roadveh_start, lpd->road_veh_by_cargo_start,sizeof(lpd->road_veh_by_cargo_start));
memcpy(_cargoc.ai_roadveh_count, lpd->road_veh_by_cargo_count,sizeof(lpd->road_veh_by_cargo_count));
for (i = 0; i != NUM_CARGO; i++) { for (i = 0; i != NUM_CARGO; i++) {
_cargoc.sprites[i] = lpd->sprites[i]; _cargoc.sprites[i] = lpd->sprites[i];

View File

@ -11,9 +11,6 @@ typedef struct CargoTypesValues {
uint16 initial_cargo_payment[NUM_CARGO]; uint16 initial_cargo_payment[NUM_CARGO];
byte transit_days_table_1[NUM_CARGO]; byte transit_days_table_1[NUM_CARGO];
byte transit_days_table_2[NUM_CARGO]; byte transit_days_table_2[NUM_CARGO];
byte road_veh_by_cargo_start[NUM_CARGO];
byte road_veh_by_cargo_count[NUM_CARGO];
} CargoTypesValues; } CargoTypesValues;
@ -76,10 +73,6 @@ static const CargoTypesValues _cargo_types_base_values[4] = {
{ {
24, 255, 90, 255, 18, 28, 40, 255, 255, 255, 32, 30, 24, 255, 90, 255, 18, 28, 40, 255, 255, 255, 32, 30,
}, },
/* normal road veh by cargo start & count */
{116, 123, 126, 132, 135, 138, 141, 144, 147, 150, 153, 156},
{7, 3, 6, 3, 3, 3, 3, 3, 3, 3, 3, 3}
}, },
{ {
@ -140,10 +133,6 @@ static const CargoTypesValues _cargo_types_base_values[4] = {
{ {
24, 255, 90, 255, 18, 28, 40, 255, 255, 60, 40, 30 24, 255, 90, 255, 18, 28, 40, 255, 255, 60, 40, 30
}, },
/* hilly road veh by cargo start & count */
{116, 123, 126, 132, 135, 138, 141, 144, 147, 159, 153, 156},
{7, 3, 6, 3, 3, 3, 3, 3, 3, 3, 3, 3},
}, },
{ {
@ -204,10 +193,6 @@ static const CargoTypesValues _cargo_types_base_values[4] = {
{ {
24, 20, 90, 255, 15, 28, 40, 255, 255, 80, 255, 30 24, 20, 90, 255, 15, 28, 40, 255, 255, 80, 255, 30
}, },
/* desert road veh by cargo start & count */
{116, 171, 126, 132, 168, 138, 141, 144, 162, 165, 153, 156},
{7, 3, 6, 3, 3, 3, 3, 3, 3, 3, 3, 3}
}, },
{ {
@ -268,9 +253,5 @@ static const CargoTypesValues _cargo_types_base_values[4] = {
{ {
24, 255, 90, 255, 30, 40, 60, 75, 25, 80, 255, 50 24, 255, 90, 255, 30, 40, 60, 75, 25, 80, 255, 50
}, },
/* candy road veh by cargo start & count */
{116, 174, 126, 186, 192, 189, 183, 177, 180, 201, 198, 195},
{7, 3, 6, 3, 3, 3, 3, 3, 3, 3, 3, 3}
} }
}; };

View File

@ -353,8 +353,6 @@ typedef struct {
SpriteID sprites[NUM_CARGO]; SpriteID sprites[NUM_CARGO];
byte transit_days_1[NUM_CARGO]; byte transit_days_1[NUM_CARGO];
byte transit_days_2[NUM_CARGO]; byte transit_days_2[NUM_CARGO];
byte ai_roadveh_start[NUM_CARGO];
byte ai_roadveh_count[NUM_CARGO];
} CargoConst; } CargoConst;
VARDEF CargoConst _cargoc; VARDEF CargoConst _cargoc;