mirror of https://github.com/OpenTTD/OpenTTD
(svn r3613) Some more const, indentation, whitespace and similar stuff
parent
6cfefdb275
commit
49c7eb934b
|
@ -55,7 +55,8 @@ enum {
|
|||
|
||||
#include "../../table/ai_rail.h"
|
||||
|
||||
static byte GetRailTrackStatus(TileIndex tile) {
|
||||
static byte GetRailTrackStatus(TileIndex tile)
|
||||
{
|
||||
uint32 r = GetTileTrackStatus(tile, TRANSPORT_RAIL);
|
||||
return (byte) (r | r >> 8);
|
||||
}
|
||||
|
@ -81,14 +82,12 @@ static void AiStateVehLoop(Player *p)
|
|||
index = (p->ai.cur_veh == NULL) ? 0 : p->ai.cur_veh->index + 1;
|
||||
|
||||
FOR_ALL_VEHICLES_FROM(v, index) {
|
||||
if (v->type == 0 || v->owner != _current_player)
|
||||
continue;
|
||||
if (v->type == 0 || v->owner != _current_player) continue;
|
||||
|
||||
if ((v->type == VEH_Train && v->subtype == 0) ||
|
||||
v->type == VEH_Road ||
|
||||
(v->type == VEH_Aircraft && v->subtype <= 2) ||
|
||||
v->type == VEH_Ship) {
|
||||
|
||||
/* replace engine? */
|
||||
if (v->type == VEH_Train && v->engine_type < 3 &&
|
||||
(_price.build_railvehicle >> 3) < p->player_money) {
|
||||
|
@ -211,8 +210,10 @@ static int32 AiGetBasePrice(Player *p)
|
|||
int32 base = _price.station_value;
|
||||
|
||||
// adjust base price when more expensive vehicles are available
|
||||
if (p->ai.railtype_to_use == 1) base = (base * 3) >> 1;
|
||||
else if (p->ai.railtype_to_use == 2) base *= 2;
|
||||
switch (p->ai.railtype_to_use) {
|
||||
case 1: base = (base * 3) >> 1; break;
|
||||
case 2: base *= 2; break;
|
||||
}
|
||||
|
||||
return base;
|
||||
}
|
||||
|
@ -413,11 +414,11 @@ static void AiStateCheckReplaceVehicle(Player *p)
|
|||
|
||||
static void AiStateDoReplaceVehicle(Player *p)
|
||||
{
|
||||
Vehicle *v = p->ai.cur_veh;
|
||||
const Vehicle* v = p->ai.cur_veh;
|
||||
|
||||
p->ai.state = AIS_VEH_LOOP;
|
||||
// vehicle is not owned by the player anymore, something went very wrong.
|
||||
if (v->type == 0 || v->owner != _current_player)
|
||||
return;
|
||||
if (v->type == 0 || v->owner != _current_player) return;
|
||||
_veh_do_replace_proc[v->type - VEH_Train](p);
|
||||
}
|
||||
|
||||
|
@ -454,8 +455,7 @@ static void AiFindSubsidyIndustryRoute(FoundRoute *fr)
|
|||
|
||||
// Randomize subsidy index..
|
||||
i = RandomRange(lengthof(_subsidies) * 3);
|
||||
if (i >= lengthof(_subsidies))
|
||||
return;
|
||||
if (i >= lengthof(_subsidies)) return;
|
||||
|
||||
s = &_subsidies[i];
|
||||
|
||||
|
@ -493,22 +493,19 @@ static void AiFindSubsidyPassengerRoute(FoundRoute *fr)
|
|||
|
||||
// Randomize subsidy index..
|
||||
i = RandomRange(lengthof(_subsidies) * 3);
|
||||
if (i >= lengthof(_subsidies))
|
||||
return;
|
||||
if (i >= lengthof(_subsidies)) return;
|
||||
|
||||
s = &_subsidies[i];
|
||||
|
||||
// Only want passengers
|
||||
if (s->cargo_type != CT_PASSENGERS || s->age > 7)
|
||||
return;
|
||||
if (s->cargo_type != CT_PASSENGERS || s->age > 7) return;
|
||||
fr->cargo = s->cargo_type;
|
||||
|
||||
fr->from = from = GetTown(s->from);
|
||||
fr->to = to = GetTown(s->to);
|
||||
|
||||
// They must be big enough
|
||||
if (from->population < 400 || to->population < 400)
|
||||
return;
|
||||
if (from->population < 400 || to->population < 400) return;
|
||||
|
||||
fr->distance = DistanceManhattan(from->xy, to->xy);
|
||||
}
|
||||
|
@ -527,19 +524,16 @@ static void AiFindRandomIndustryRoute(FoundRoute *fr)
|
|||
|
||||
// pick a source
|
||||
fr->from = i = AiFindRandomIndustry();
|
||||
if (i == NULL)
|
||||
return;
|
||||
if (i == NULL) return;
|
||||
|
||||
// pick a random produced cargo
|
||||
cargo = i->produced_cargo[0];
|
||||
if (r&1 && i->produced_cargo[1] != 0xFF)
|
||||
cargo = i->produced_cargo[1];
|
||||
if (r & 1 && i->produced_cargo[1] != 0xFF) cargo = i->produced_cargo[1];
|
||||
|
||||
fr->cargo = cargo;
|
||||
|
||||
// don't allow passengers
|
||||
if (cargo == 0xFF || cargo == CT_PASSENGERS)
|
||||
return;
|
||||
if (cargo == 0xFF || cargo == CT_PASSENGERS) return;
|
||||
|
||||
if (cargo != CT_GOODS && cargo != CT_FOOD) {
|
||||
// pick a dest, and see if it can receive
|
||||
|
@ -562,18 +556,17 @@ static void AiFindRandomIndustryRoute(FoundRoute *fr)
|
|||
|
||||
static void AiFindRandomPassengerRoute(FoundRoute *fr)
|
||||
{
|
||||
Town *source, *dest;
|
||||
Town* source;
|
||||
Town* dest;
|
||||
|
||||
// initially error
|
||||
fr->distance = -1;
|
||||
|
||||
fr->from = source = AiFindRandomTown();
|
||||
if (source == NULL || source->population < 400)
|
||||
return;
|
||||
if (source == NULL || source->population < 400) return;
|
||||
|
||||
fr->to = dest = AiFindRandomTown();
|
||||
if (dest == NULL || source == dest || dest->population < 400)
|
||||
return;
|
||||
if (dest == NULL || source == dest || dest->population < 400) return;
|
||||
|
||||
fr->distance = DistanceManhattan(source->xy, dest->xy);
|
||||
}
|
||||
|
@ -598,20 +591,24 @@ static bool AiCheckIfRouteIsGood(Player *p, FoundRoute *fr, byte bitmask)
|
|||
if (cur < dist) dist = cur;
|
||||
cur = DistanceMax(to_tile, st->xy);
|
||||
if (cur < dist) dist = cur;
|
||||
if (to_tile == from_tile && st->xy == to_tile)
|
||||
same_station++;
|
||||
if (to_tile == from_tile && st->xy == to_tile) same_station++;
|
||||
}
|
||||
|
||||
// To prevent the AI from building ten busstations in the same town, do some calculations
|
||||
// For each road or airport station, we want 350 of population!
|
||||
if ((bitmask == 2 || bitmask == 4) && same_station > 2 && ((Town *)(fr->from))->population < same_station * 350)
|
||||
if ((bitmask == 2 || bitmask == 4) &&
|
||||
same_station > 2 &&
|
||||
((Town*)(fr->from))->population < same_station * 350) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (dist != 0xFFFF && dist > 37)
|
||||
return false;
|
||||
if (dist != 0xFFFF && dist > 37) return false;
|
||||
|
||||
if (p->ai.route_type_mask != 0 && !(p->ai.route_type_mask&bitmask) && !CHANCE16(1,5))
|
||||
if (p->ai.route_type_mask != 0 &&
|
||||
!(p->ai.route_type_mask & bitmask) &&
|
||||
!CHANCE16(1, 5)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (fr->cargo == CT_PASSENGERS || fr->cargo == CT_MAIL) {
|
||||
if (((Town*)fr->from)->pct_pass_transported > 0x99 ||
|
||||
|
@ -623,7 +620,7 @@ static bool AiCheckIfRouteIsGood(Player *p, FoundRoute *fr, byte bitmask)
|
|||
((Town*)fr->to)->ratings[_current_player] < -100)
|
||||
return false;
|
||||
} else {
|
||||
Industry *i = (Industry*)fr->from;
|
||||
const Industry* i = (const Industry*)fr->from;
|
||||
|
||||
if (i->pct_transported[fr->cargo != i->produced_cargo[0]] > 0x99 ||
|
||||
i->total_production[fr->cargo != i->produced_cargo[0]] == 0)
|
||||
|
@ -658,17 +655,14 @@ static void AiWantLongIndustryRoute(Player *p)
|
|||
for (;;) {
|
||||
// look for one from the subsidy list
|
||||
AiFindSubsidyIndustryRoute(&fr);
|
||||
if (IS_INT_INSIDE(fr.distance, 60, 90+1))
|
||||
break;
|
||||
if (IS_INT_INSIDE(fr.distance, 60, 90 + 1)) break;
|
||||
|
||||
// try a random one
|
||||
AiFindRandomIndustryRoute(&fr);
|
||||
if (IS_INT_INSIDE(fr.distance, 60, 90+1))
|
||||
break;
|
||||
if (IS_INT_INSIDE(fr.distance, 60, 90 + 1)) break;
|
||||
|
||||
// only test 60 times
|
||||
if (--i == 0)
|
||||
return;
|
||||
if (--i == 0) return;
|
||||
}
|
||||
|
||||
if (!AiCheckIfRouteIsGood(p, &fr, 1)) return;
|
||||
|
@ -762,20 +756,16 @@ static void AiWantMediumIndustryRoute(Player *p)
|
|||
|
||||
i = 60;
|
||||
for (;;) {
|
||||
|
||||
// look for one from the subsidy list
|
||||
AiFindSubsidyIndustryRoute(&fr);
|
||||
if (IS_INT_INSIDE(fr.distance, 40, 60+1))
|
||||
break;
|
||||
if (IS_INT_INSIDE(fr.distance, 40, 60 + 1)) break;
|
||||
|
||||
// try a random one
|
||||
AiFindRandomIndustryRoute(&fr);
|
||||
if (IS_INT_INSIDE(fr.distance, 40, 60+1))
|
||||
break;
|
||||
if (IS_INT_INSIDE(fr.distance, 40, 60 + 1)) break;
|
||||
|
||||
// only test 60 times
|
||||
if (--i == 0)
|
||||
return;
|
||||
if (--i == 0) return;
|
||||
}
|
||||
|
||||
if (!AiCheckIfRouteIsGood(p, &fr, 1)) return;
|
||||
|
@ -834,20 +824,16 @@ static void AiWantShortIndustryRoute(Player *p)
|
|||
|
||||
i = 60;
|
||||
for (;;) {
|
||||
|
||||
// look for one from the subsidy list
|
||||
AiFindSubsidyIndustryRoute(&fr);
|
||||
if (IS_INT_INSIDE(fr.distance, 15, 40+1))
|
||||
break;
|
||||
if (IS_INT_INSIDE(fr.distance, 15, 40 + 1)) break;
|
||||
|
||||
// try a random one
|
||||
AiFindRandomIndustryRoute(&fr);
|
||||
if (IS_INT_INSIDE(fr.distance, 15, 40+1))
|
||||
break;
|
||||
if (IS_INT_INSIDE(fr.distance, 15, 40 + 1)) break;
|
||||
|
||||
// only test 60 times
|
||||
if (--i == 0)
|
||||
return;
|
||||
if (--i == 0) return;
|
||||
}
|
||||
|
||||
if (!AiCheckIfRouteIsGood(p, &fr, 1)) return;
|
||||
|
@ -906,20 +892,16 @@ static void AiWantMailRoute(Player *p)
|
|||
|
||||
i = 60;
|
||||
for (;;) {
|
||||
|
||||
// look for one from the subsidy list
|
||||
AiFindSubsidyPassengerRoute(&fr);
|
||||
if (IS_INT_INSIDE(fr.distance, 60, 110+1))
|
||||
break;
|
||||
if (IS_INT_INSIDE(fr.distance, 60, 110 + 1)) break;
|
||||
|
||||
// try a random one
|
||||
AiFindRandomPassengerRoute(&fr);
|
||||
if (IS_INT_INSIDE(fr.distance, 60, 110+1))
|
||||
break;
|
||||
if (IS_INT_INSIDE(fr.distance, 60, 110 + 1)) break;
|
||||
|
||||
// only test 60 times
|
||||
if (--i == 0)
|
||||
return;
|
||||
if (--i == 0) return;
|
||||
}
|
||||
|
||||
fr.cargo = CT_MAIL;
|
||||
|
@ -1011,20 +993,16 @@ static void AiWantPassengerRoute(Player *p)
|
|||
|
||||
i = 60;
|
||||
for (;;) {
|
||||
|
||||
// look for one from the subsidy list
|
||||
AiFindSubsidyPassengerRoute(&fr);
|
||||
if (IS_INT_INSIDE(fr.distance, 0, 55+1))
|
||||
break;
|
||||
if (IS_INT_INSIDE(fr.distance, 0, 55 + 1)) break;
|
||||
|
||||
// try a random one
|
||||
AiFindRandomPassengerRoute(&fr);
|
||||
if (IS_INT_INSIDE(fr.distance, 0, 55+1))
|
||||
break;
|
||||
if (IS_INT_INSIDE(fr.distance, 0, 55 + 1)) break;
|
||||
|
||||
// only test 60 times
|
||||
if (--i == 0)
|
||||
return;
|
||||
if (--i == 0) return;
|
||||
}
|
||||
|
||||
fr.cargo = CT_PASSENGERS;
|
||||
|
@ -1103,20 +1081,16 @@ static void AiWantLongRoadIndustryRoute(Player *p)
|
|||
|
||||
i = 60;
|
||||
for (;;) {
|
||||
|
||||
// look for one from the subsidy list
|
||||
AiFindSubsidyIndustryRoute(&fr);
|
||||
if (IS_INT_INSIDE(fr.distance, 35, 55+1))
|
||||
break;
|
||||
if (IS_INT_INSIDE(fr.distance, 35, 55 + 1)) break;
|
||||
|
||||
// try a random one
|
||||
AiFindRandomIndustryRoute(&fr);
|
||||
if (IS_INT_INSIDE(fr.distance, 35, 55+1))
|
||||
break;
|
||||
if (IS_INT_INSIDE(fr.distance, 35, 55 + 1)) break;
|
||||
|
||||
// only test 60 times
|
||||
if (--i == 0)
|
||||
return;
|
||||
if (--i == 0) return;
|
||||
}
|
||||
|
||||
if (!AiCheckIfRouteIsGood(p, &fr, 2)) return;
|
||||
|
@ -1163,20 +1137,16 @@ static void AiWantMediumRoadIndustryRoute(Player *p)
|
|||
|
||||
i = 60;
|
||||
for (;;) {
|
||||
|
||||
// look for one from the subsidy list
|
||||
AiFindSubsidyIndustryRoute(&fr);
|
||||
if (IS_INT_INSIDE(fr.distance, 15, 40+1))
|
||||
break;
|
||||
if (IS_INT_INSIDE(fr.distance, 15, 40 + 1)) break;
|
||||
|
||||
// try a random one
|
||||
AiFindRandomIndustryRoute(&fr);
|
||||
if (IS_INT_INSIDE(fr.distance, 15, 40+1))
|
||||
break;
|
||||
if (IS_INT_INSIDE(fr.distance, 15, 40 + 1)) break;
|
||||
|
||||
// only test 60 times
|
||||
if (--i == 0)
|
||||
return;
|
||||
if (--i == 0) return;
|
||||
}
|
||||
|
||||
if (!AiCheckIfRouteIsGood(p, &fr, 2)) return;
|
||||
|
@ -1223,20 +1193,16 @@ static void AiWantLongRoadPassengerRoute(Player *p)
|
|||
|
||||
i = 60;
|
||||
for (;;) {
|
||||
|
||||
// look for one from the subsidy list
|
||||
AiFindSubsidyPassengerRoute(&fr);
|
||||
if (IS_INT_INSIDE(fr.distance, 55, 180+1))
|
||||
break;
|
||||
if (IS_INT_INSIDE(fr.distance, 55, 180 + 1)) break;
|
||||
|
||||
// try a random one
|
||||
AiFindRandomPassengerRoute(&fr);
|
||||
if (IS_INT_INSIDE(fr.distance, 55, 180+1))
|
||||
break;
|
||||
if (IS_INT_INSIDE(fr.distance, 55, 180 + 1)) break;
|
||||
|
||||
// only test 60 times
|
||||
if (--i == 0)
|
||||
return;
|
||||
if (--i == 0) return;
|
||||
}
|
||||
|
||||
fr.cargo = CT_PASSENGERS;
|
||||
|
@ -1288,12 +1254,10 @@ static void AiWantPassengerRouteInsideTown(Player *p)
|
|||
for (;;) {
|
||||
// Find a town big enough
|
||||
t = AiFindRandomTown();
|
||||
if (t != NULL && t->population >= 700)
|
||||
break;
|
||||
if (t != NULL && t->population >= 700) break;
|
||||
|
||||
// only test 60 times
|
||||
if (--i == 0)
|
||||
return;
|
||||
if (--i == 0) return;
|
||||
}
|
||||
|
||||
fr.cargo = CT_PASSENGERS;
|
||||
|
@ -1358,25 +1322,20 @@ static void AiWantPassengerAircraftRoute(Player *p)
|
|||
|
||||
i = 60;
|
||||
for (;;) {
|
||||
|
||||
// look for one from the subsidy list
|
||||
AiFindSubsidyPassengerRoute(&fr);
|
||||
if (IS_INT_INSIDE(fr.distance,0,95+1))
|
||||
break;
|
||||
if (IS_INT_INSIDE(fr.distance, 0, 95 + 1)) break;
|
||||
|
||||
// try a random one
|
||||
AiFindRandomPassengerRoute(&fr);
|
||||
if (IS_INT_INSIDE(fr.distance,0,95+1))
|
||||
break;
|
||||
if (IS_INT_INSIDE(fr.distance, 0, 95 + 1)) break;
|
||||
|
||||
// only test 60 times
|
||||
if (--i == 0)
|
||||
return;
|
||||
if (--i == 0) return;
|
||||
}
|
||||
|
||||
fr.cargo = CT_PASSENGERS;
|
||||
if (!AiCheckIfRouteIsGood(p, &fr, 4))
|
||||
return;
|
||||
if (!AiCheckIfRouteIsGood(p, &fr, 4)) return;
|
||||
|
||||
|
||||
// Fill the source field
|
||||
|
@ -1429,15 +1388,13 @@ static void AiWantOilRigAircraftRoute(Player *p)
|
|||
}
|
||||
|
||||
// only test 60 times
|
||||
if (--i == 0)
|
||||
return;
|
||||
if (--i == 0) return;
|
||||
}
|
||||
|
||||
fr.cargo = CT_PASSENGERS;
|
||||
fr.from = fr.to = t;
|
||||
|
||||
if (!AiCheckIfRouteIsGood(p, &fr, 4))
|
||||
return;
|
||||
if (!AiCheckIfRouteIsGood(p, &fr, 4)) return;
|
||||
|
||||
// Fill the source field
|
||||
p->ai.src.spec_tile = t->xy;
|
||||
|
@ -1501,9 +1458,12 @@ static void AiStateWantNewRoute(Player *p)
|
|||
for (;;) {
|
||||
r = (uint16)Random();
|
||||
|
||||
if (_patches.ai_disable_veh_train && _patches.ai_disable_veh_roadveh &&
|
||||
_patches.ai_disable_veh_aircraft && _patches.ai_disable_veh_ship)
|
||||
if (_patches.ai_disable_veh_train &&
|
||||
_patches.ai_disable_veh_roadveh &&
|
||||
_patches.ai_disable_veh_aircraft &&
|
||||
_patches.ai_disable_veh_ship) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (r < 0x7626) {
|
||||
if (_patches.ai_disable_veh_train) continue;
|
||||
|
@ -1520,8 +1480,7 @@ static void AiStateWantNewRoute(Player *p)
|
|||
}
|
||||
|
||||
// got a route?
|
||||
if (p->ai.state != AIS_WANT_NEW_ROUTE)
|
||||
break;
|
||||
if (p->ai.state != AIS_WANT_NEW_ROUTE) break;
|
||||
|
||||
// time out?
|
||||
if (--i == 0) {
|
||||
|
@ -1724,8 +1683,7 @@ static void AiDoTerraformLand(TileIndex tile, int dir, int unk, int mode)
|
|||
r >>= 2;
|
||||
if (r & 2) {
|
||||
dir++;
|
||||
if (r&1)
|
||||
dir -= 2;
|
||||
if (r & 1) dir -= 2;
|
||||
}
|
||||
dir &= 3;
|
||||
} while (--unk >= 0);
|
||||
|
@ -1768,8 +1726,7 @@ static void AiStateBuildDefaultRailBlocks(Player *p)
|
|||
j = p->ai.num_build_rec;
|
||||
do {
|
||||
// this item has already been built?
|
||||
if (aib->cur_building_rule != 255)
|
||||
continue;
|
||||
if (aib->cur_building_rule != 255) continue;
|
||||
|
||||
// adjust the coordinate randomly,
|
||||
// to make sure that we find a position.
|
||||
|
@ -1779,7 +1736,8 @@ static void AiStateBuildDefaultRailBlocks(Player *p)
|
|||
rule = AiBuildDefaultRailTrack(aib->use_tile,
|
||||
p->ai.build_kind, p->ai.num_wagons,
|
||||
aib->unk6, aib->unk7,
|
||||
aib->direction, aib->cargo, &cost);
|
||||
aib->direction, aib->cargo, &cost
|
||||
);
|
||||
|
||||
if (rule == -1) {
|
||||
// cannot build, terraform after a while
|
||||
|
@ -2169,10 +2127,11 @@ static void AiBuildRailConstruct(Player *p)
|
|||
}
|
||||
|
||||
if (arf.best_tile != 0) {
|
||||
for (i=0; i!=2; i++)
|
||||
for (i = 0; i != 2; i++) {
|
||||
AiDoTerraformLand(arf.best_tile, arf.best_dir, 3, 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static bool AiRemoveTileAndGoForward(Player *p)
|
||||
{
|
||||
|
@ -2196,8 +2155,7 @@ static bool AiRemoveTileAndGoForward(Player *p)
|
|||
|
||||
// Check if the bridge points in the right direction.
|
||||
// This is not really needed the first place AiRemoveTileAndGoForward is called.
|
||||
if ((_m[tile].m5&1) != (p->ai.cur_dir_a&1))
|
||||
return false;
|
||||
if ((_m[tile].m5 & 1) != (p->ai.cur_dir_a & 1)) return false;
|
||||
|
||||
// Find other side of bridge.
|
||||
offs = TileOffsByDir(p->ai.cur_dir_a);
|
||||
|
@ -2216,8 +2174,7 @@ static bool AiRemoveTileAndGoForward(Player *p)
|
|||
|
||||
// Find the railtype at the position. Quit if no rail there.
|
||||
b = GetRailTrackStatus(tile) & _dir_table_3[p->ai.cur_dir_a];
|
||||
if (b == 0)
|
||||
return false;
|
||||
if (b == 0) return false;
|
||||
|
||||
// Convert into a bit position that CMD_REMOVE_SINGLE_RAIL expects.
|
||||
bit = FindFirstBit(b);
|
||||
|
@ -2253,8 +2210,7 @@ static void AiBuildRailDestruct(Player *p)
|
|||
}
|
||||
|
||||
// Don't do anything if the destination is already reached.
|
||||
if (p->ai.cur_tile_a == p->ai.start_tile_a)
|
||||
return;
|
||||
if (p->ai.cur_tile_a == p->ai.start_tile_a) return;
|
||||
|
||||
AiRemoveTileAndGoForward(p);
|
||||
}
|
||||
|
@ -2262,16 +2218,14 @@ static void AiBuildRailDestruct(Player *p)
|
|||
|
||||
static void AiBuildRail(Player *p)
|
||||
{
|
||||
int i;
|
||||
|
||||
if (p->ai.state_mode < 1) {
|
||||
// Construct mode, build new rail.
|
||||
AiBuildRailConstruct(p);
|
||||
} else if (p->ai.state_mode == 1) {
|
||||
|
||||
// Destruct mode, destroy the rail currently built.
|
||||
AiBuildRailDestruct(p);
|
||||
} else if (p->ai.state_mode == 2) {
|
||||
uint i;
|
||||
|
||||
// Terraform some and then try building again.
|
||||
for (i = 0; i != 4; i++)
|
||||
|
@ -2377,7 +2331,7 @@ static void AiStateBuildRailVeh(Player *p)
|
|||
uint loco_id;
|
||||
|
||||
ptr = _default_rail_track_data[p->ai.src.cur_building_rule]->data;
|
||||
while (ptr->mode != 0) { ptr++; }
|
||||
while (ptr->mode != 0) ptr++;
|
||||
|
||||
tile = TILE_ADD(p->ai.src.use_tile, ToTileIndexDiff(ptr->tileoffs));
|
||||
|
||||
|
@ -2432,9 +2386,11 @@ handle_nocash:
|
|||
|
||||
for (i = 0; p->ai.order_list_blocks[i] != 0xFF; i++) {
|
||||
AiBuildRec *aib = (&p->ai.src) + p->ai.order_list_blocks[i];
|
||||
bool is_pass = (p->ai.cargo_type == CT_PASSENGERS ||
|
||||
bool is_pass = (
|
||||
p->ai.cargo_type == CT_PASSENGERS ||
|
||||
p->ai.cargo_type == CT_MAIL ||
|
||||
(_opt.landscape==LT_NORMAL && p->ai.cargo_type == CT_VALUABLES));
|
||||
(_opt.landscape == LT_NORMAL && p->ai.cargo_type == CT_VALUABLES)
|
||||
);
|
||||
Order order;
|
||||
|
||||
order.type = OT_GOTO_STATION;
|
||||
|
@ -2452,8 +2408,7 @@ handle_nocash:
|
|||
|
||||
DoCommandByTile(0, loco_id, _ai_service_interval, DC_EXEC, CMD_CHANGE_SERVICE_INT);
|
||||
|
||||
if (p->ai.num_want_fullload != 0)
|
||||
p->ai.num_want_fullload--;
|
||||
if (p->ai.num_want_fullload != 0) p->ai.num_want_fullload--;
|
||||
|
||||
if (--p->ai.num_loco_to_build != 0) {
|
||||
// p->ai.loco_id = INVALID_VEHICLE;
|
||||
|
@ -2543,7 +2498,7 @@ static int32 AiDoBuildDefaultRoadBlock(TileIndex tile, const AiDefaultBlockData
|
|||
int roadflag = 0;
|
||||
|
||||
for (;p->mode != 4;p++) {
|
||||
uint c = TILE_MASK(tile + ToTileIndexDiff(p->tileoffs));
|
||||
TileIndex c = TILE_MASK(tile + ToTileIndexDiff(p->tileoffs));
|
||||
|
||||
_cleared_town = NULL;
|
||||
|
||||
|
@ -2554,8 +2509,7 @@ static int32 AiDoBuildDefaultRoadBlock(TileIndex tile, const AiDefaultBlockData
|
|||
roadflag |= 2;
|
||||
|
||||
// all bits are already built?
|
||||
if ((_m[c].m5&p->attr)==p->attr)
|
||||
continue;
|
||||
if ((_m[c].m5 & p->attr) == p->attr) continue;
|
||||
}
|
||||
|
||||
ret = DoCommandByTile(c, p->attr, 0, flag | DC_AUTO | DC_NO_WATER, CMD_BUILD_ROAD);
|
||||
|
@ -2583,19 +2537,16 @@ clear_town_stuff:;
|
|||
total_cost += ret;
|
||||
|
||||
if (_cleared_town != NULL) {
|
||||
if (t != NULL && t != _cleared_town)
|
||||
return CMD_ERROR;
|
||||
if (t != NULL && t != _cleared_town) return CMD_ERROR;
|
||||
t = _cleared_town;
|
||||
rating += _cleared_town_rating;
|
||||
}
|
||||
} else if (p->mode == 3) {
|
||||
if (flag & DC_EXEC)
|
||||
continue;
|
||||
if (flag & DC_EXEC) continue;
|
||||
|
||||
if (GetTileSlope(c, NULL) != 0)
|
||||
return CMD_ERROR;
|
||||
if (GetTileSlope(c, NULL) != 0) return CMD_ERROR;
|
||||
|
||||
if (!(IsTileType(c, MP_STREET) && (_m[c].m5 & 0xF0) == 0)) {
|
||||
if (!IsTileType(c, MP_STREET) || (_m[c].m5 & 0xF0) != 0) {
|
||||
ret = DoCommandByTile(c, 0, 0, flag | DC_AUTO | DC_NO_WATER | DC_AI_BUILDING, CMD_LANDSCAPE_CLEAR);
|
||||
if (CmdFailed(ret)) return CMD_ERROR;
|
||||
}
|
||||
|
@ -2603,13 +2554,10 @@ clear_town_stuff:;
|
|||
}
|
||||
}
|
||||
|
||||
if (!_want_road_truck_station && !(roadflag&2))
|
||||
return CMD_ERROR;
|
||||
if (!_want_road_truck_station && !(roadflag & 2)) return CMD_ERROR;
|
||||
|
||||
if (!(flag & DC_EXEC)) {
|
||||
if (t != NULL && rating > t->ratings[_current_player]) {
|
||||
return CMD_ERROR;
|
||||
}
|
||||
if (t != NULL && rating > t->ratings[_current_player]) return CMD_ERROR;
|
||||
}
|
||||
return total_cost;
|
||||
}
|
||||
|
@ -2625,8 +2573,7 @@ static bool AiCheckBlockDistances(Player *p, TileIndex tile)
|
|||
|
||||
do {
|
||||
if (aib->cur_building_rule != 255) {
|
||||
if (DistanceManhattan(aib->use_tile, tile) < 9)
|
||||
return false;
|
||||
if (DistanceManhattan(aib->use_tile, tile) < 9) return false;
|
||||
}
|
||||
} while (++aib, --num);
|
||||
|
||||
|
@ -2636,7 +2583,8 @@ static bool AiCheckBlockDistances(Player *p, TileIndex tile)
|
|||
|
||||
static void AiStateBuildDefaultRoadBlocks(Player *p)
|
||||
{
|
||||
int i, j;
|
||||
uint i;
|
||||
int j;
|
||||
AiBuildRec *aib;
|
||||
int rule;
|
||||
int32 cost;
|
||||
|
@ -2648,23 +2596,22 @@ static void AiStateBuildDefaultRoadBlocks(Player *p)
|
|||
}
|
||||
|
||||
// do the following 8 times
|
||||
i = 8;
|
||||
do {
|
||||
for (i = 0; i != 8; i++) {
|
||||
// check if we can build the default track
|
||||
aib = &p->ai.src;
|
||||
j = p->ai.num_build_rec;
|
||||
do {
|
||||
// this item has already been built?
|
||||
if (aib->cur_building_rule != 255)
|
||||
continue;
|
||||
if (aib->cur_building_rule != 255) continue;
|
||||
|
||||
// adjust the coordinate randomly,
|
||||
// to make sure that we find a position.
|
||||
aib->use_tile = AdjustTileCoordRandomly(aib->spec_tile, aib->rand_rng);
|
||||
|
||||
// check if the road can be built there.
|
||||
rule = AiFindBestDefaultRoadBlock(aib->use_tile,
|
||||
aib->direction, aib->cargo, &cost);
|
||||
rule = AiFindBestDefaultRoadBlock(
|
||||
aib->use_tile, aib->direction, aib->cargo, &cost
|
||||
);
|
||||
|
||||
if (rule == -1) {
|
||||
// cannot build, terraform after a while
|
||||
|
@ -2690,14 +2637,13 @@ static void AiStateBuildDefaultRoadBlocks(Player *p)
|
|||
assert(!CmdFailed(r));
|
||||
}
|
||||
} while (++aib,--j);
|
||||
} while (--i);
|
||||
}
|
||||
|
||||
// check if we're done with all of them
|
||||
aib = &p->ai.src;
|
||||
j = p->ai.num_build_rec;
|
||||
do {
|
||||
if (aib->cur_building_rule == 255)
|
||||
return;
|
||||
if (aib->cur_building_rule == 255) return;
|
||||
} while (++aib,--j);
|
||||
|
||||
// yep, all are done. switch state to the rail building state.
|
||||
|
@ -2807,9 +2753,7 @@ static bool AiCheckRoadFinished(Player *p)
|
|||
tile = TILE_MASK(p->ai.cur_tile_a + TileOffsByDir(dir));
|
||||
|
||||
bits = GetTileTrackStatus(tile, TRANSPORT_ROAD) & _ai_road_table_and[dir];
|
||||
if (bits == 0) {
|
||||
return false;
|
||||
}
|
||||
if (bits == 0) return false;
|
||||
|
||||
are.best_dist = (uint)-1;
|
||||
|
||||
|
@ -2817,11 +2761,9 @@ static bool AiCheckRoadFinished(Player *p)
|
|||
FollowTrack(tile, 0x3000 | TRANSPORT_ROAD, _dir_by_track[i], (TPFEnumProc*)AiEnumFollowRoad, NULL, &are);
|
||||
}
|
||||
|
||||
if (DistanceManhattan(tile, are.dest) <= are.best_dist)
|
||||
return false;
|
||||
if (DistanceManhattan(tile, are.dest) <= are.best_dist) return false;
|
||||
|
||||
if (are.best_dist == 0)
|
||||
return true;
|
||||
if (are.best_dist == 0) return true;
|
||||
|
||||
p->ai.cur_tile_a = are.best_tile;
|
||||
p->ai.cur_dir_a = _dir_by_track[are.best_track];
|
||||
|
@ -2876,8 +2818,7 @@ static inline void AiCheckBuildRoadBridgeHere(AiRoadFinder *arf, TileIndex tile,
|
|||
|
||||
// At the bottom depth, check if the new path is better than the old one.
|
||||
if (arf->depth == 1) {
|
||||
if (AiCheckRoadPathBetter(arf, p))
|
||||
arf->bridge_end_tile = tile_new;
|
||||
if (AiCheckRoadPathBetter(arf, p)) arf->bridge_end_tile = tile_new;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -2946,9 +2887,7 @@ static void AiBuildRoadRecursive(AiRoadFinder *arf, TileIndex tile, int dir)
|
|||
}
|
||||
|
||||
// At the bottom depth?
|
||||
if (arf->depth == 1) {
|
||||
AiCheckRoadPathBetter(arf, p);
|
||||
}
|
||||
if (arf->depth == 1) AiCheckRoadPathBetter(arf, p);
|
||||
|
||||
p += 2;
|
||||
} while (!(p[0] & 0x80));
|
||||
|
@ -3027,8 +2966,7 @@ do_some_terraform:
|
|||
for (i = 10; i != 0; i--) {
|
||||
if (CheckBridge_Stuff(i, bridge_len)) {
|
||||
int32 cost = DoCommandByTile(tile, p->ai.cur_tile_a, i + (0x80 << 8), DC_AUTO, CMD_BUILD_BRIDGE);
|
||||
if (!CmdFailed(cost) && cost < (p->player_money >> 5))
|
||||
break;
|
||||
if (!CmdFailed(cost) && cost < (p->player_money >> 5)) break;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -3061,8 +2999,6 @@ do_some_terraform:
|
|||
|
||||
static void AiBuildRoad(Player *p)
|
||||
{
|
||||
int i;
|
||||
|
||||
if (p->ai.state_mode < 1) {
|
||||
// Construct mode, build new road.
|
||||
AiBuildRoadConstruct(p);
|
||||
|
@ -3071,6 +3007,7 @@ static void AiBuildRoad(Player *p)
|
|||
p->ai.state_mode = 2;
|
||||
p->ai.state_counter = 0;
|
||||
} else if (p->ai.state_mode == 2) {
|
||||
uint i;
|
||||
|
||||
// Terraform some and then try building again.
|
||||
for (i = 0; i != 4; i++)
|
||||
|
@ -3169,7 +3106,7 @@ static void AiStateBuildRoadVehicles(Player *p)
|
|||
TileIndex tile;
|
||||
uint loco_id;
|
||||
EngineID veh;
|
||||
int i;
|
||||
uint i;
|
||||
|
||||
ptr = _road_default_block_data[p->ai.src.cur_building_rule]->data;
|
||||
for (; ptr->mode != 0; ptr++) {}
|
||||
|
@ -3267,21 +3204,18 @@ static void AiStateAirportStuff(Player *p)
|
|||
|
||||
FOR_ALL_STATIONS(st) {
|
||||
// Dismiss ghost stations.
|
||||
if (st->xy == 0)
|
||||
continue;
|
||||
if (st->xy == 0) continue;
|
||||
|
||||
// Is this an airport?
|
||||
if (!(st->facilities & FACIL_AIRPORT))
|
||||
continue;
|
||||
if (!(st->facilities & FACIL_AIRPORT)) continue;
|
||||
|
||||
// Do we own the airport? (Oilrigs aren't owned, though.)
|
||||
if (st->owner != OWNER_NONE && st->owner != _current_player)
|
||||
continue;
|
||||
if (st->owner != OWNER_NONE && st->owner != _current_player) continue;
|
||||
|
||||
acc_planes = GetAirport(st->airport_type)->acc_planes;
|
||||
|
||||
// Dismiss heliports, unless we are checking an oilrig.
|
||||
if (acc_planes == HELICOPTERS_ONLY && !(p->ai.build_kind == 1 && i == 1))
|
||||
if (acc_planes == HELICOPTERS_ONLY && (p->ai.build_kind != 1 || i != 1))
|
||||
continue;
|
||||
|
||||
// Dismiss country airports if we are doing the other
|
||||
|
@ -3336,8 +3270,7 @@ static int32 AiDoBuildDefaultAirportBlock(TileIndex tile, const AiDefaultBlockDa
|
|||
int32 total_cost = 0, ret;
|
||||
|
||||
for (; p->mode == 0; p++) {
|
||||
if (!HASBIT(_avail_aircraft, p->attr))
|
||||
return CMD_ERROR;
|
||||
if (!HASBIT(_avail_aircraft, p->attr)) return CMD_ERROR;
|
||||
ret = DoCommandByTile(TILE_MASK(tile + ToTileIndexDiff(p->tileoffs)), p->attr,0,flag | DC_AUTO | DC_NO_WATER,CMD_BUILD_AIRPORT);
|
||||
if (CmdFailed(ret)) return CMD_ERROR;
|
||||
total_cost += ret;
|
||||
|
@ -3349,7 +3282,6 @@ static int32 AiDoBuildDefaultAirportBlock(TileIndex tile, const AiDefaultBlockDa
|
|||
static bool AiCheckAirportResources(TileIndex tile, const AiDefaultBlockData *p, byte cargo)
|
||||
{
|
||||
uint values[NUM_CARGO];
|
||||
int w,h;
|
||||
int rad;
|
||||
|
||||
if (_patches.modified_catchment) {
|
||||
|
@ -3360,9 +3292,9 @@ static bool AiCheckAirportResources(TileIndex tile, const AiDefaultBlockData *p,
|
|||
|
||||
for (; p->mode == 0; p++) {
|
||||
TileIndex tile2 = TILE_ADD(tile, ToTileIndexDiff(p->tileoffs));
|
||||
uint w = _airport_size_x[p->attr];
|
||||
uint h = _airport_size_y[p->attr];
|
||||
|
||||
w = _airport_size_x[p->attr];
|
||||
h = _airport_size_y[p->attr];
|
||||
if (cargo & 0x80) {
|
||||
GetProductionAroundTiles(values, tile2, w, h, rad);
|
||||
return values[cargo & 0x7F] != 0;
|
||||
|
@ -3376,13 +3308,13 @@ static bool AiCheckAirportResources(TileIndex tile, const AiDefaultBlockData *p,
|
|||
|
||||
static int AiFindBestDefaultAirportBlock(TileIndex tile, byte cargo, byte heli, int32 *cost)
|
||||
{
|
||||
int i;
|
||||
const AiDefaultBlockData *p;
|
||||
uint i;
|
||||
|
||||
for (i = 0; (p = _airport_default_block_data[i]) != NULL; i++) {
|
||||
// If we are doing a helicopter service, avoid building
|
||||
// airports where they can't land.
|
||||
if (heli && GetAirport(p->attr)->acc_planes == AIRCRAFT_ONLY)
|
||||
continue;
|
||||
if (heli && GetAirport(p->attr)->acc_planes == AIRCRAFT_ONLY) continue;
|
||||
|
||||
*cost = AiDoBuildDefaultAirportBlock(tile, p, 0);
|
||||
if (!CmdFailed(*cost) && AiCheckAirportResources(tile, p, cargo))
|
||||
|
@ -3412,8 +3344,7 @@ static void AiStateBuildDefaultAirportBlocks(Player *p)
|
|||
j = p->ai.num_build_rec;
|
||||
do {
|
||||
// this item has already been built?
|
||||
if (aib->cur_building_rule != 255)
|
||||
continue;
|
||||
if (aib->cur_building_rule != 255) continue;
|
||||
|
||||
// adjust the coordinate randomly,
|
||||
// to make sure that we find a position.
|
||||
|
@ -3465,8 +3396,7 @@ static void AiStateBuildDefaultAirportBlocks(Player *p)
|
|||
aib = &p->ai.src;
|
||||
j = p->ai.num_build_rec;
|
||||
do {
|
||||
if (aib->cur_building_rule == 255)
|
||||
return;
|
||||
if (aib->cur_building_rule == 255) return;
|
||||
} while (++aib,--j);
|
||||
|
||||
// yep, all are done. switch state.
|
||||
|
@ -3522,12 +3452,9 @@ static void AiStateBuildAircraftVehicles(Player *p)
|
|||
|
||||
DoCommandByTile(0, loco_id, _ai_service_interval, DC_EXEC, CMD_CHANGE_SERVICE_INT);
|
||||
|
||||
if (p->ai.num_want_fullload != 0)
|
||||
p->ai.num_want_fullload--;
|
||||
if (p->ai.num_want_fullload != 0) p->ai.num_want_fullload--;
|
||||
|
||||
if (--p->ai.num_loco_to_build == 0) {
|
||||
p->ai.state = AIS_0;
|
||||
}
|
||||
if (--p->ai.num_loco_to_build == 0) p->ai.state = AIS_0;
|
||||
}
|
||||
|
||||
static void AiStateCheckShipStuff(Player *p)
|
||||
|
@ -3588,8 +3515,7 @@ static void AiStateSellVeh(Player *p)
|
|||
|
||||
goto return_to_loop;
|
||||
going_to_depot:;
|
||||
if (++p->ai.state_counter <= 832)
|
||||
return;
|
||||
if (++p->ai.state_counter <= 832) return;
|
||||
|
||||
if (v->current_order.type == OT_GOTO_DEPOT) {
|
||||
v->current_order.type = OT_DUMMY;
|
||||
|
@ -3616,8 +3542,7 @@ static void AiStateRemoveStation(Player *p)
|
|||
in_use = malloc(GetStationPoolSize());
|
||||
memset(in_use, 0, GetStationPoolSize());
|
||||
FOR_ALL_ORDERS(ord) {
|
||||
if (ord->type == OT_GOTO_STATION)
|
||||
in_use[ord->station] = 1;
|
||||
if (ord->type == OT_GOTO_STATION) in_use[ord->station] = 1;
|
||||
}
|
||||
|
||||
// Go through all stations and delete those that aren't in use
|
||||
|
@ -3645,12 +3570,11 @@ static void AiRemovePlayerRailOrRoad(Player *p, TileIndex tile)
|
|||
if (!IsTileOwner(tile, _current_player)) return;
|
||||
|
||||
m5 = _m[tile].m5;
|
||||
if ((m5&~0x3) != 0xC0) {
|
||||
if ((m5 & 0xFC) != 0xC0) {
|
||||
is_rail_crossing:;
|
||||
m5 = GetRailTrackStatus(tile);
|
||||
|
||||
if (m5 == 0xC || m5 == 0x30)
|
||||
return;
|
||||
if (m5 == 0xC || m5 == 0x30) return;
|
||||
|
||||
if (m5 & 0x25) {
|
||||
pos_0:
|
||||
|
@ -3703,28 +3627,31 @@ pos_3:
|
|||
} else if (IsTileType(tile, MP_STREET)) {
|
||||
if (!IsTileOwner(tile, _current_player)) return;
|
||||
|
||||
if (IsLevelCrossing(tile))
|
||||
goto is_rail_crossing;
|
||||
if (IsLevelCrossing(tile)) goto is_rail_crossing;
|
||||
|
||||
if ( (_m[tile].m5&0xF0) == 0x20) {
|
||||
int dir;
|
||||
if ((_m[tile].m5 & 0xF0) == 0x20) { // depot
|
||||
uint dir;
|
||||
|
||||
// Check if there are any stations around.
|
||||
if (IsTileType(tile + TileDiffXY(-1, 0), MP_STATION) &&
|
||||
IsTileOwner(tile + TileDiffXY(-1, 0), _current_player))
|
||||
IsTileOwner(tile + TileDiffXY(-1, 0), _current_player)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (IsTileType(tile + TileDiffXY(1, 0), MP_STATION) &&
|
||||
IsTileOwner(tile + TileDiffXY(1, 0), _current_player))
|
||||
IsTileOwner(tile + TileDiffXY(1, 0), _current_player)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (IsTileType(tile + TileDiffXY(0, -1), MP_STATION) &&
|
||||
IsTileOwner(tile + TileDiffXY(0, -1), _current_player))
|
||||
IsTileOwner(tile + TileDiffXY(0, -1), _current_player)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (IsTileType(tile + TileDiffXY(0, 1), MP_STATION) &&
|
||||
IsTileOwner(tile + TileDiffXY(0, 1), _current_player))
|
||||
IsTileOwner(tile + TileDiffXY(0, 1), _current_player)) {
|
||||
return;
|
||||
}
|
||||
|
||||
dir = _m[tile].m5 & 3;
|
||||
|
||||
|
@ -3768,17 +3695,14 @@ static void AiStateRemoveTrack(Player *p)
|
|||
|
||||
// Remove player stuff in that tile
|
||||
AiRemovePlayerRailOrRoad(p, tile);
|
||||
if (p->ai.state != AIS_REMOVE_TRACK)
|
||||
return;
|
||||
if (p->ai.state != AIS_REMOVE_TRACK) return;
|
||||
} while (--num);
|
||||
}
|
||||
|
||||
static void AiStateRemoveSingleRailTile(Player *p)
|
||||
{
|
||||
// Remove until we can't remove more.
|
||||
if (!AiRemoveTileAndGoForward(p)) {
|
||||
p->ai.state = AIS_REMOVE_TRACK;
|
||||
}
|
||||
if (!AiRemoveTileAndGoForward(p)) p->ai.state = AIS_REMOVE_TRACK;
|
||||
}
|
||||
|
||||
static AiStateAction * const _ai_actions[] = {
|
||||
|
@ -3819,20 +3743,18 @@ extern void ShowBuyCompanyDialog(uint player);
|
|||
static void AiHandleTakeover(Player *p)
|
||||
{
|
||||
if (p->bankrupt_timeout != 0) {
|
||||
if ((p->bankrupt_timeout-=8) > 0)
|
||||
return;
|
||||
p->bankrupt_timeout -= 8;
|
||||
if (p->bankrupt_timeout > 0) return;
|
||||
p->bankrupt_timeout = 0;
|
||||
DeleteWindowById(WC_BUY_COMPANY, _current_player);
|
||||
if (IsLocalPlayer()) {
|
||||
AskExitToGameMenu();
|
||||
return;
|
||||
}
|
||||
if (IS_HUMAN_PLAYER(_current_player))
|
||||
return;
|
||||
if (IS_HUMAN_PLAYER(_current_player)) return;
|
||||
}
|
||||
|
||||
if (p->bankrupt_asked == 255)
|
||||
return;
|
||||
if (p->bankrupt_asked == 255) return;
|
||||
|
||||
{
|
||||
uint asked = p->bankrupt_asked;
|
||||
|
@ -3865,8 +3787,7 @@ static void AiHandleTakeover(Player *p)
|
|||
ShowBuyCompanyDialog(_current_player);
|
||||
return;
|
||||
}
|
||||
if (IS_HUMAN_PLAYER(best_pl->index))
|
||||
return;
|
||||
if (IS_HUMAN_PLAYER(best_pl->index)) return;
|
||||
|
||||
// Too little money for computer to buy it?
|
||||
if (best_pl->player_money >> 1 >= p->bankrupt_value) {
|
||||
|
|
|
@ -239,8 +239,7 @@ int AiNew_PickVehicle(Player *p)
|
|||
if (!CmdFailed(ret)) break;
|
||||
}
|
||||
// We did not find a vehicle :(
|
||||
if (CmdFailed(ret)) return -1;
|
||||
return i;
|
||||
return CmdFailed(ret) ? -1 : i;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -485,7 +485,7 @@ static int32 AyStar_AiPathFinder_CalculateG(AyStar *aystar, AyStarNode *current,
|
|||
int dir1 = AiNew_GetRailDirection(parent->path.parent->node.tile, parent->path.node.tile, current->tile);
|
||||
int dir2 = AiNew_GetRailDirection(parent->path.parent->parent->node.tile, parent->path.parent->node.tile, parent->path.node.tile);
|
||||
// First, see if we are on diagonal path, that is better than straight path
|
||||
if (dir1 > 1) { res -= AI_PATHFINDER_DIAGONAL_BONUS; }
|
||||
if (dir1 > 1) res -= AI_PATHFINDER_DIAGONAL_BONUS;
|
||||
|
||||
// First see if they are different
|
||||
if (dir1 != dir2) {
|
||||
|
|
14
economy.c
14
economy.c
|
@ -157,7 +157,7 @@ int UpdateCompanyRatingAndValue(Player *p, bool update)
|
|||
/* Count stations */
|
||||
{
|
||||
uint num = 0;
|
||||
Station *st;
|
||||
const Station* st;
|
||||
|
||||
FOR_ALL_STATIONS(st) {
|
||||
if (st->xy != 0 && st->owner == owner) {
|
||||
|
@ -170,7 +170,7 @@ int UpdateCompanyRatingAndValue(Player *p, bool update)
|
|||
|
||||
/* Generate statistics depending on recent income statistics */
|
||||
{
|
||||
PlayerEconomyEntry *pee;
|
||||
const PlayerEconomyEntry* pee;
|
||||
int numec;
|
||||
int32 min_income;
|
||||
int32 max_income;
|
||||
|
@ -194,7 +194,7 @@ int UpdateCompanyRatingAndValue(Player *p, bool update)
|
|||
|
||||
/* Generate score depending on amount of transported cargo */
|
||||
{
|
||||
PlayerEconomyEntry *pee;
|
||||
const PlayerEconomyEntry* pee;
|
||||
int numec;
|
||||
uint32 total_delivered;
|
||||
|
||||
|
@ -216,8 +216,7 @@ int UpdateCompanyRatingAndValue(Player *p, bool update)
|
|||
uint num = 0;
|
||||
do num += cargo&1; while (cargo>>=1);
|
||||
_score_part[owner][SCORE_CARGO] = num;
|
||||
if (update)
|
||||
p->cargo_types = 0;
|
||||
if (update) p->cargo_types = 0;
|
||||
}
|
||||
|
||||
/* Generate score for player money */
|
||||
|
@ -245,7 +244,7 @@ int UpdateCompanyRatingAndValue(Player *p, bool update)
|
|||
// Check the score
|
||||
s = (_score_part[owner][i] >= _score_info[i].needed) ?
|
||||
_score_info[i].score :
|
||||
((_score_part[owner][i] * _score_info[i].score) / _score_info[i].needed);
|
||||
_score_part[owner][i] * _score_info[i].score / _score_info[i].needed;
|
||||
if (s < 0) s = 0;
|
||||
score += s;
|
||||
total_score += _score_info[i].score;
|
||||
|
@ -254,8 +253,7 @@ int UpdateCompanyRatingAndValue(Player *p, bool update)
|
|||
_score_part[owner][SCORE_TOTAL] = score;
|
||||
|
||||
// We always want the score scaled to SCORE_MAX (1000)
|
||||
if (total_score != SCORE_MAX)
|
||||
score = score * SCORE_MAX / total_score;
|
||||
if (total_score != SCORE_MAX) score = score * SCORE_MAX / total_score;
|
||||
}
|
||||
|
||||
if (update) {
|
||||
|
|
61
graph_gui.c
61
graph_gui.c
|
@ -884,7 +884,7 @@ static void PerformanceRatingDetailWndProc(Window *w, WindowEvent *e)
|
|||
{
|
||||
switch (e->event) {
|
||||
case WE_PAINT: {
|
||||
int val, needed, score, i;
|
||||
int i;
|
||||
byte owner, x;
|
||||
uint16 y = 14;
|
||||
int total_score = 0;
|
||||
|
@ -904,8 +904,7 @@ static void PerformanceRatingDetailWndProc(Window *w, WindowEvent *e)
|
|||
// Bah, player gone :(
|
||||
w->disabled_state += 1 << (i + 13);
|
||||
// Is this player selected? If so, select first player (always save? :s)
|
||||
if (w->click_state == 1U << (i + 13))
|
||||
w->click_state = 1 << 13;
|
||||
if (w->click_state == 1U << (i + 13)) w->click_state = 1 << 13;
|
||||
// We need a repaint
|
||||
SetWindowDirty(w);
|
||||
}
|
||||
|
@ -913,14 +912,14 @@ static void PerformanceRatingDetailWndProc(Window *w, WindowEvent *e)
|
|||
}
|
||||
|
||||
// Check if we have the player marked as inactive
|
||||
if ((w->disabled_state & (1 << (i+13)))) {
|
||||
if (w->disabled_state & (1 << (i + 13))) {
|
||||
// New player! Yippie :p
|
||||
w->disabled_state -= 1 << (i + 13);
|
||||
// We need a repaint
|
||||
SetWindowDirty(w);
|
||||
}
|
||||
|
||||
if (i == owner) x = 1; else x = 0;
|
||||
x = (i == owner) ? 1 : 0;
|
||||
DrawPlayerIcon(i, i * 37 + 13 + x, 16 + x);
|
||||
}
|
||||
|
||||
|
@ -930,10 +929,11 @@ static void PerformanceRatingDetailWndProc(Window *w, WindowEvent *e)
|
|||
|
||||
// Draw all the score parts
|
||||
for (i = 0; i < NUM_SCORE; i++) {
|
||||
int val = _score_part[owner][i];
|
||||
int needed = _score_info[i].needed;
|
||||
int score = _score_info[i].score;
|
||||
|
||||
y += 20;
|
||||
val = _score_part[owner][i];
|
||||
needed = _score_info[i].needed;
|
||||
score = _score_info[i].score;
|
||||
// SCORE_TOTAL has his own rulez ;)
|
||||
if (i == SCORE_TOTAL) {
|
||||
needed = total_score;
|
||||
|
@ -949,35 +949,33 @@ static void PerformanceRatingDetailWndProc(Window *w, WindowEvent *e)
|
|||
DrawStringRightAligned(107, y, SET_PERFORMANCE_DETAIL_INT, 0);
|
||||
|
||||
// Calculate the %-bar
|
||||
if (val > needed) x = 50;
|
||||
else if (val == 0) x = 0;
|
||||
else x = ((val * 50) / needed);
|
||||
if (val > needed) {
|
||||
x = 50;
|
||||
} else if (val == 0) {
|
||||
x = 0;
|
||||
} else {
|
||||
x = val * 50 / needed;
|
||||
}
|
||||
|
||||
// SCORE_LOAN is inversed
|
||||
if (val < 0 && i == SCORE_LOAN)
|
||||
x = 0;
|
||||
if (val < 0 && i == SCORE_LOAN) x = 0;
|
||||
|
||||
// Draw the bar
|
||||
if (x != 0)
|
||||
GfxFillRect(112, y-2, x + 112, y+10, color_done);
|
||||
if (x != 50)
|
||||
GfxFillRect(x + 112, y-2, 50 + 112, y+10, color_notdone);
|
||||
if (x != 0) GfxFillRect(112, y - 2, 112 + x, y + 10, color_done);
|
||||
if (x != 50) GfxFillRect(112 + x, y - 2, 112 + 50, y + 10, color_notdone);
|
||||
|
||||
// Calculate the %
|
||||
if (val > needed) x = 100;
|
||||
else x = ((val * 100) / needed);
|
||||
x = (val <= needed) ? val * 100 / needed : 100;
|
||||
|
||||
// SCORE_LOAN is inversed
|
||||
if (val < 0 && i == SCORE_LOAN)
|
||||
x = 0;
|
||||
if (val < 0 && i == SCORE_LOAN) x = 0;
|
||||
|
||||
// Draw it
|
||||
SetDParam(0, x);
|
||||
DrawStringCentered(137, y, STR_PERFORMANCE_DETAIL_PERCENT, 0);
|
||||
|
||||
// SCORE_LOAN is inversed
|
||||
if (i == SCORE_LOAN)
|
||||
val = needed - val;
|
||||
if (i == SCORE_LOAN) val = needed - val;
|
||||
|
||||
// Draw the amount we have against what is needed
|
||||
// For some of them it is in currency format
|
||||
|
@ -1018,15 +1016,13 @@ static void PerformanceRatingDetailWndProc(Window *w, WindowEvent *e)
|
|||
|
||||
// Hide the player who are not active
|
||||
for (i = 0; i < MAX_PLAYERS; i++) {
|
||||
if (!GetPlayer(i)->is_active) {
|
||||
w->disabled_state += 1 << (i+13);
|
||||
}
|
||||
if (!GetPlayer(i)->is_active) w->disabled_state += 1 << (i + 13);
|
||||
}
|
||||
// Update all player stats with the current data
|
||||
// (this is because _score_info is not saved to a savegame)
|
||||
FOR_ALL_PLAYERS(p2)
|
||||
if (p2->is_active)
|
||||
UpdateCompanyRatingAndValue(p2, false);
|
||||
FOR_ALL_PLAYERS(p2) {
|
||||
if (p2->is_active) UpdateCompanyRatingAndValue(p2, false);
|
||||
}
|
||||
|
||||
w->custom[0] = DAY_TICKS;
|
||||
w->custom[1] = 5;
|
||||
|
@ -1044,11 +1040,12 @@ static void PerformanceRatingDetailWndProc(Window *w, WindowEvent *e)
|
|||
w->custom[0] = DAY_TICKS;
|
||||
if (--w->custom[1] == 0) {
|
||||
Player *p2;
|
||||
|
||||
w->custom[1] = 5;
|
||||
FOR_ALL_PLAYERS(p2)
|
||||
FOR_ALL_PLAYERS(p2) {
|
||||
// Skip if player is not active
|
||||
if (p2->is_active)
|
||||
UpdateCompanyRatingAndValue(p2, false);
|
||||
if (p2->is_active) UpdateCompanyRatingAndValue(p2, false);
|
||||
}
|
||||
SetWindowDirty(w);
|
||||
}
|
||||
}
|
||||
|
|
80
newgrf.c
80
newgrf.c
|
@ -239,8 +239,7 @@ static bool RailVehicleChangeInfo(uint engine, int numinfo, int prop, byte **buf
|
|||
case 0x09: { /* Speed */
|
||||
FOR_EACH_OBJECT {
|
||||
uint16 speed = grf_load_word(&buf);
|
||||
if (speed == 0xFFFF)
|
||||
speed = 0;
|
||||
if (speed == 0xFFFF) speed = 0;
|
||||
|
||||
rvi[i].max_speed = speed;
|
||||
}
|
||||
|
@ -249,8 +248,7 @@ static bool RailVehicleChangeInfo(uint engine, int numinfo, int prop, byte **buf
|
|||
FOR_EACH_OBJECT {
|
||||
uint16 power = grf_load_word(&buf);
|
||||
|
||||
if (rvi[i].flags & RVI_MULTIHEAD)
|
||||
power /= 2;
|
||||
if (rvi[i].flags & RVI_MULTIHEAD) power /= 2;
|
||||
|
||||
rvi[i].power = power;
|
||||
dewagonize(power, engine + i);
|
||||
|
@ -260,8 +258,7 @@ static bool RailVehicleChangeInfo(uint engine, int numinfo, int prop, byte **buf
|
|||
FOR_EACH_OBJECT {
|
||||
uint8 runcostfact = grf_load_byte(&buf);
|
||||
|
||||
if (rvi[i].flags & RVI_MULTIHEAD)
|
||||
runcostfact /= 2;
|
||||
if (rvi[i].flags & RVI_MULTIHEAD) runcostfact /= 2;
|
||||
|
||||
rvi[i].running_cost_base = runcostfact;
|
||||
}
|
||||
|
@ -283,8 +280,7 @@ static bool RailVehicleChangeInfo(uint engine, int numinfo, int prop, byte **buf
|
|||
|
||||
/* TTD sprite IDs point to a location in a 16bit array, but we use it
|
||||
* as an array index, so we need it to be half the original value. */
|
||||
if (spriteid < 0xFD)
|
||||
spriteid >>= 1;
|
||||
if (spriteid < 0xFD) spriteid >>= 1;
|
||||
|
||||
rvi[i].image_index = spriteid;
|
||||
}
|
||||
|
@ -361,14 +357,15 @@ static bool RailVehicleChangeInfo(uint engine, int numinfo, int prop, byte **buf
|
|||
uint8 traction = grf_load_byte(&buf);
|
||||
int engclass;
|
||||
|
||||
if (traction <= 0x07)
|
||||
if (traction <= 0x07) {
|
||||
engclass = 0;
|
||||
else if (traction <= 0x27)
|
||||
} else if (traction <= 0x27) {
|
||||
engclass = 1;
|
||||
else if (traction <= 0x41)
|
||||
} else if (traction <= 0x41) {
|
||||
engclass = 2;
|
||||
else
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
|
||||
rvi[i].engclass = engclass;
|
||||
}
|
||||
|
@ -504,11 +501,10 @@ static bool RoadVehicleChangeInfo(uint engine, int numinfo, int prop, byte **buf
|
|||
FOR_EACH_OBJECT {
|
||||
uint8 spriteid = grf_load_byte(&buf);
|
||||
|
||||
if (spriteid == 0xFF)
|
||||
spriteid = 0xFD; // cars have different custom id in the GRF file
|
||||
// cars have different custom id in the GRF file
|
||||
if (spriteid == 0xFF) spriteid = 0xFD;
|
||||
|
||||
if (spriteid < 0xFD)
|
||||
spriteid >>= 1;
|
||||
if (spriteid < 0xFD) spriteid >>= 1;
|
||||
|
||||
rvi[i].image_index = spriteid;
|
||||
}
|
||||
|
@ -614,11 +610,10 @@ static bool ShipVehicleChangeInfo(uint engine, int numinfo, int prop, byte **buf
|
|||
FOR_EACH_OBJECT {
|
||||
uint8 spriteid = grf_load_byte(&buf);
|
||||
|
||||
if (spriteid == 0xFF)
|
||||
spriteid = 0xFD; // ships have different custom id in the GRF file
|
||||
// ships have different custom id in the GRF file
|
||||
if (spriteid == 0xFF) spriteid = 0xFD;
|
||||
|
||||
if (spriteid < 0xFD)
|
||||
spriteid >>= 1;
|
||||
if (spriteid < 0xFD) spriteid >>= 1;
|
||||
|
||||
svi[i].image_index = spriteid;
|
||||
}
|
||||
|
@ -740,11 +735,10 @@ static bool AircraftVehicleChangeInfo(uint engine, int numinfo, int prop, byte *
|
|||
FOR_EACH_OBJECT {
|
||||
uint8 spriteid = grf_load_byte(&buf);
|
||||
|
||||
if (spriteid == 0xFF)
|
||||
spriteid = 0xFD; // ships have different custom id in the GRF file
|
||||
// aircraft have different custom id in the GRF file
|
||||
if (spriteid == 0xFF) spriteid = 0xFD;
|
||||
|
||||
if (spriteid < 0xFD)
|
||||
spriteid >>= 1;
|
||||
if (spriteid < 0xFD) spriteid >>= 1;
|
||||
|
||||
avi[i].image_index = spriteid;
|
||||
}
|
||||
|
@ -1034,9 +1028,11 @@ static bool StationChangeInfo(uint stid, int numinfo, int prop, byte **bufp, int
|
|||
|
||||
p = 0;
|
||||
layout = malloc(length * number);
|
||||
for (l = 0; l < length; l++)
|
||||
for (p = 0; p < number; p++)
|
||||
for (l = 0; l < length; l++) {
|
||||
for (p = 0; p < number; p++) {
|
||||
layout[l * number + p] = grf_load_byte(&buf);
|
||||
}
|
||||
}
|
||||
|
||||
l--;
|
||||
p--;
|
||||
|
@ -1361,10 +1357,11 @@ static SpriteGroup* NewCallBackResultSpriteGroup(uint16 value)
|
|||
|
||||
// Old style callback results have the highest byte 0xFF so signify it is a callback result
|
||||
// New style ones only have the highest bit set (allows 15-bit results, instead of just 8)
|
||||
if ((value >> 8) == 0xFF)
|
||||
value &= 0xFF;
|
||||
else
|
||||
if ((value >> 8) == 0xFF) {
|
||||
value &= ~0xFF00;
|
||||
} else {
|
||||
value &= ~0x8000;
|
||||
}
|
||||
|
||||
group->g.callback.result = value;
|
||||
|
||||
|
@ -2507,7 +2504,7 @@ static void ResetCustomStations(void)
|
|||
*/
|
||||
static void ResetNewGRFData(void)
|
||||
{
|
||||
int i;
|
||||
uint i;
|
||||
|
||||
// Copy/reset original engine info data
|
||||
memcpy(&_engine_info, &orig_engine_info, sizeof(orig_engine_info));
|
||||
|
@ -2520,9 +2517,9 @@ static void ResetNewGRFData(void)
|
|||
// First, free sprite table data
|
||||
for (i = 0; i < MAX_BRIDGES; i++) {
|
||||
if (_bridge[i].sprite_table != NULL) {
|
||||
byte j;
|
||||
for (j = 0; j < 7; j++)
|
||||
free(_bridge[i].sprite_table[j]);
|
||||
uint j;
|
||||
|
||||
for (j = 0; j < 7; j++) free(_bridge[i].sprite_table[j]);
|
||||
free(_bridge[i].sprite_table);
|
||||
}
|
||||
}
|
||||
|
@ -2563,8 +2560,7 @@ static void InitNewGRFFile(const char* filename, int sprite_offset)
|
|||
|
||||
newfile = calloc(1, sizeof(*newfile));
|
||||
|
||||
if (newfile == NULL)
|
||||
error ("Out of memory");
|
||||
if (newfile == NULL) error ("Out of memory");
|
||||
|
||||
newfile->filename = strdup(filename);
|
||||
newfile->sprite_offset = sprite_offset;
|
||||
|
@ -2594,16 +2590,20 @@ static void CalculateRefitMasks(void)
|
|||
if (cargo_allowed[engine] != 0) {
|
||||
// Build up the list of cargo types from the set cargo classes.
|
||||
for (i = 0; i < lengthof(cargo_classes); i++) {
|
||||
if (HASBIT(cargo_allowed[engine], i))
|
||||
mask |= cargo_classes[i];
|
||||
if (HASBIT(cargo_disallowed[engine], i))
|
||||
not_mask |= cargo_classes[i];
|
||||
if (HASBIT(cargo_allowed[engine], i)) mask |= cargo_classes[i];
|
||||
if (HASBIT(cargo_disallowed[engine], i)) not_mask |= cargo_classes[i];
|
||||
}
|
||||
} else {
|
||||
// Don't apply default refit mask to wagons or engines with no capacity
|
||||
if (xor_mask == 0 && !(GetEngine(engine)->type == VEH_Train && (RailVehInfo(engine)->capacity == 0 || RailVehInfo(engine)->flags & RVI_WAGON)))
|
||||
if (xor_mask == 0 && (
|
||||
GetEngine(engine)->type != VEH_Train || (
|
||||
RailVehInfo(engine)->capacity != 0 &&
|
||||
!(RailVehInfo(engine)->flags & RVI_WAGON)
|
||||
)
|
||||
)) {
|
||||
xor_mask = _default_refitmasks[GetEngine(engine)->type - VEH_Train];
|
||||
}
|
||||
}
|
||||
_engine_info[engine].refit_mask = ((mask & ~not_mask) ^ xor_mask) & _landscape_global_cargo_mask[_opt.landscape];
|
||||
}
|
||||
}
|
||||
|
|
11
oldloader.c
11
oldloader.c
|
@ -472,17 +472,12 @@ static void ReadTTDPatchFlags(void)
|
|||
1 vehicle == 128 bytes */
|
||||
_bump_assert_value = (_old_vehicle_multipler - 1) * 850 * 128;
|
||||
|
||||
_new_ttdpatch_format = false;
|
||||
|
||||
/* Check if we have a modern TTDPatch savegame (has extra data all around) */
|
||||
if (memcmp(&_old_map3[0x1FFFA], "TTDp", 4) == 0)
|
||||
_new_ttdpatch_format = true;
|
||||
_new_ttdpatch_format = (memcmp(&_old_map3[0x1FFFA], "TTDp", 4) == 0);
|
||||
|
||||
/* Clean the misused places */
|
||||
for (i = 0; i < 17; i++)
|
||||
_old_map3[i] = 0;
|
||||
for (i = 0x1FE00; i < 0x20000; i++)
|
||||
_old_map3[i] = 0;
|
||||
for (i = 0; i < 17; i++) _old_map3[i] = 0;
|
||||
for (i = 0x1FE00; i < 0x20000; i++) _old_map3[i] = 0;
|
||||
|
||||
if (_new_ttdpatch_format)
|
||||
DEBUG(oldloader, 1)("[OldLoader] Found TTDPatch game");
|
||||
|
|
|
@ -282,11 +282,12 @@ static void LoadIntroGame(void)
|
|||
|
||||
// Generate a world.
|
||||
sprintf(filename, "%sopntitle.dat", _path.data_dir);
|
||||
if (SaveOrLoad(filename, SL_LOAD) != SL_OK) {
|
||||
#if defined SECOND_DATA_DIR
|
||||
if (SaveOrLoad(filename, SL_LOAD) != SL_OK) {
|
||||
sprintf(filename, "%sopntitle.dat", _path.second_data_dir);
|
||||
if (SaveOrLoad(filename, SL_LOAD) != SL_OK)
|
||||
}
|
||||
#endif
|
||||
if (SaveOrLoad(filename, SL_LOAD) != SL_OK) {
|
||||
GenerateWorld(GW_EMPTY, 64, 64); // if failed loading, make empty world.
|
||||
}
|
||||
|
||||
|
|
|
@ -252,8 +252,11 @@ int32 CmdSellRoadVeh(int x, int y, uint32 flags, uint32 p1, uint32 p2)
|
|||
|
||||
SET_EXPENSES_TYPE(EXPENSES_NEW_VEHICLES);
|
||||
|
||||
if (!IsTileDepotType(v->tile, TRANSPORT_ROAD) || v->u.road.state != 254 || !(v->vehstatus&VS_STOPPED))
|
||||
if (!IsTileDepotType(v->tile, TRANSPORT_ROAD) ||
|
||||
v->u.road.state != 254 ||
|
||||
!(v->vehstatus & VS_STOPPED)) {
|
||||
return_cmd_error(STR_9013_MUST_BE_STOPPED_INSIDE);
|
||||
}
|
||||
|
||||
if (flags & DC_EXEC) {
|
||||
// Invalidate depot
|
||||
|
@ -296,7 +299,7 @@ static bool EnumRoadSignalFindDepot(TileIndex tile, RoadFindDepotData *rfdd, int
|
|||
return false;
|
||||
}
|
||||
|
||||
static Depot *FindClosestRoadDepot(Vehicle *v)
|
||||
static const Depot* FindClosestRoadDepot(const Vehicle* v)
|
||||
{
|
||||
TileIndex tile = v->tile;
|
||||
int i;
|
||||
|
@ -321,8 +324,9 @@ static Depot *FindClosestRoadDepot(Vehicle *v)
|
|||
rfdd.best_length = (uint)-1;
|
||||
|
||||
/* search in all directions */
|
||||
for (i = 0; i != 4; i++)
|
||||
for (i = 0; i != 4; i++) {
|
||||
FollowTrack(tile, 0x2000 | TRANSPORT_ROAD, i, (TPFEnumProc*)EnumRoadSignalFindDepot, NULL, &rfdd);
|
||||
}
|
||||
|
||||
if (rfdd.best_length == (uint)-1) return NULL;
|
||||
|
||||
|
@ -534,7 +538,8 @@ static void RoadVehCrash(Vehicle *v)
|
|||
STR_9031_ROAD_VEHICLE_CRASH_DRIVER : STR_9032_ROAD_VEHICLE_CRASH_DIE,
|
||||
NEWS_FLAGS(NM_THIN, NF_VIEWPORT|NF_VEHICLE, NT_ACCIDENT, 0),
|
||||
v->index,
|
||||
0);
|
||||
0
|
||||
);
|
||||
|
||||
ModifyStationRatingAround(v->tile, v->owner, -160, 22);
|
||||
SndPlayVehicleFx(SND_12_EXPLOSION, v);
|
||||
|
@ -744,8 +749,7 @@ static Vehicle *RoadVehFindCloseTo(Vehicle *v, int x, int y, byte dir)
|
|||
return NULL;
|
||||
}
|
||||
|
||||
if (++v->u.road.blocked_ctr > 1480)
|
||||
return NULL;
|
||||
if (++v->u.road.blocked_ctr > 1480) return NULL;
|
||||
|
||||
return u;
|
||||
}
|
||||
|
@ -778,7 +782,8 @@ static void RoadVehArrivesAt(const Vehicle* v, Station* st)
|
|||
STR_9030_CITIZENS_CELEBRATE_FIRST,
|
||||
flags,
|
||||
v->index,
|
||||
0);
|
||||
0
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -878,11 +883,9 @@ static void RoadVehCheckOvertake(Vehicle *v, Vehicle *u)
|
|||
return;
|
||||
}
|
||||
|
||||
if (v->direction != u->direction || !(v->direction&1))
|
||||
return;
|
||||
if (v->direction != u->direction || !(v->direction & 1)) return;
|
||||
|
||||
if (v->u.road.state >= 32 || (v->u.road.state&7) > 1 )
|
||||
return;
|
||||
if (v->u.road.state >= 32 || (v->u.road.state & 7) > 1) return;
|
||||
|
||||
tt = GetTileTrackStatus(v->tile, TRANSPORT_ROAD) & 0x3F;
|
||||
if ((tt & 3) == 0) return;
|
||||
|
@ -1213,9 +1216,10 @@ static void RoadVehController(Vehicle *v)
|
|||
if (v->u.road.state == 0 || v->u.road.state == 1 ||
|
||||
v->u.road.state == 8 || v->u.road.state == 9 ||
|
||||
v->u.road.state == 16 || v->u.road.state == 17 ||
|
||||
v->u.road.state == 24 || v->u.road.state == 25)
|
||||
v->u.road.state == 24 || v->u.road.state == 25) {
|
||||
v->u.road.overtaking = 0;
|
||||
}
|
||||
}
|
||||
|
||||
BeginVehicleMove(v);
|
||||
|
||||
|
@ -1284,7 +1288,10 @@ again:
|
|||
}
|
||||
|
||||
if (IS_BYTE_INSIDE(v->u.road.state, 0x20, 0x30) && IsTileType(v->tile, MP_STATION)) {
|
||||
if ((dir & 7) >= 6) { v->cur_speed = 0; return; }
|
||||
if ((dir & 7) >= 6) {
|
||||
v->cur_speed = 0;
|
||||
return;
|
||||
}
|
||||
if (IS_BYTE_INSIDE(_m[v->tile].m5, 0x43, 0x4B)) {
|
||||
RoadStop *rs = GetRoadStopByTile(v->tile, GetRoadStopType(v->tile));
|
||||
byte *b = &rs->status;
|
||||
|
@ -1357,7 +1364,8 @@ again:
|
|||
|
||||
new_dir = RoadVehGetSlidingDirection(v, x, y);
|
||||
|
||||
if (!IS_BYTE_INSIDE(v->u.road.state, 0x20, 0x30) && (u=RoadVehFindCloseTo(v, x, y, new_dir)) != NULL) {
|
||||
if (!IS_BYTE_INSIDE(v->u.road.state, 0x20, 0x30) &&
|
||||
(u = RoadVehFindCloseTo(v, x, y, new_dir)) != NULL) {
|
||||
if (v->u.road.overtaking == 0) RoadVehCheckOvertake(v, u);
|
||||
return;
|
||||
}
|
||||
|
@ -1503,7 +1511,7 @@ void RoadVeh_Tick(Vehicle *v)
|
|||
|
||||
static void CheckIfRoadVehNeedsService(Vehicle *v)
|
||||
{
|
||||
Depot *depot;
|
||||
const Depot* depot;
|
||||
|
||||
if (_patches.servint_roadveh == 0) return;
|
||||
if (!VehicleNeedsService(v)) return;
|
||||
|
@ -1532,8 +1540,9 @@ static void CheckIfRoadVehNeedsService(Vehicle *v)
|
|||
|
||||
if (v->current_order.type == OT_GOTO_DEPOT &&
|
||||
v->current_order.flags & OF_NON_STOP &&
|
||||
!CHANCE16(1,20))
|
||||
!CHANCE16(1, 20)) {
|
||||
return;
|
||||
}
|
||||
|
||||
v->current_order.type = OT_GOTO_DEPOT;
|
||||
v->current_order.flags = OF_NON_STOP;
|
||||
|
@ -1578,8 +1587,9 @@ void OnNewDay_RoadVeh(Vehicle *v)
|
|||
DEBUG(ms, 2) ("Multistop: Attempting to obtain a slot for vehicle %d at station %d (0x%x)", v->unitnumber, st->index, st->xy);
|
||||
for (; rs != NULL; rs = rs->next) {
|
||||
// Only consider those with at least a free slot.
|
||||
if (!(rs->slot[0] == INVALID_VEHICLE || rs->slot[1] == INVALID_VEHICLE))
|
||||
if (rs->slot[0] != INVALID_VEHICLE && rs->slot[1] != INVALID_VEHICLE) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// Previously the NPF pathfinder was used here even if NPF is OFF.. WTF?
|
||||
assert(NUM_SLOTS == 2);
|
||||
|
|
|
@ -1655,24 +1655,24 @@ static int32 RemoveAirport(Station *st, uint32 flags)
|
|||
|
||||
cost = w * h * _price.remove_airport;
|
||||
|
||||
{
|
||||
BEGIN_TILE_LOOP(tile_cur,w,h,tile)
|
||||
if (!EnsureNoVehicle(tile_cur))
|
||||
return CMD_ERROR;
|
||||
BEGIN_TILE_LOOP(tile_cur, w, h, tile) {
|
||||
if (!EnsureNoVehicle(tile_cur)) return CMD_ERROR;
|
||||
|
||||
if (flags & DC_EXEC) {
|
||||
DeleteAnimatedTile(tile_cur);
|
||||
DoClearSquare(tile_cur);
|
||||
}
|
||||
END_TILE_LOOP(tile_cur, w,h,tile)
|
||||
}
|
||||
} END_TILE_LOOP(tile_cur, w,h,tile)
|
||||
|
||||
if (flags & DC_EXEC) {
|
||||
const AirportFTAClass *afc = GetAirport(st->airport_type);
|
||||
uint i;
|
||||
|
||||
for (i = 0; i < afc->nof_depots; ++i)
|
||||
DeleteWindowById(WC_VEHICLE_DEPOT, tile + ToTileIndexDiff(afc->airport_depots[i]));
|
||||
for (i = 0; i < afc->nof_depots; ++i) {
|
||||
DeleteWindowById(
|
||||
WC_VEHICLE_DEPOT, tile + ToTileIndexDiff(afc->airport_depots[i])
|
||||
);
|
||||
}
|
||||
|
||||
st->airport_tile = 0;
|
||||
st->facilities &= ~FACIL_AIRPORT;
|
||||
|
@ -2156,6 +2156,7 @@ static void AnimateTile_Station(TileIndex tile)
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
static void ClickTile_Station(TileIndex tile)
|
||||
{
|
||||
// 0x20 - hangar large airport (32)
|
||||
|
@ -2297,7 +2298,7 @@ void DeleteAllPlayerStations(void)
|
|||
static void CheckOrphanedSlots(const Station *st, RoadStopType rst)
|
||||
{
|
||||
RoadStop *rs;
|
||||
int k;
|
||||
uint k;
|
||||
|
||||
for (rs = GetPrimaryRoadStop(st, rst); rs != NULL; rs = rs->next) {
|
||||
for (k = 0; k < NUM_SLOTS; k++) {
|
||||
|
@ -2934,10 +2935,10 @@ static void Load_STNS(void)
|
|||
|
||||
// this means it's an oldstyle savegame without support for nonuniform stations
|
||||
if (st->train_tile != 0 && st->trainst_h == 0) {
|
||||
int w = GB(st->trainst_w, 4, 4);
|
||||
int h = GB(st->trainst_w, 0, 4);
|
||||
uint w = GB(st->trainst_w, 4, 4);
|
||||
uint h = GB(st->trainst_w, 0, 4);
|
||||
|
||||
if (_m[st->train_tile].m5 & 1) intswap(w, h);
|
||||
if (_m[st->train_tile].m5 & 1) uintswap(w, h);
|
||||
st->trainst_w = w;
|
||||
st->trainst_h = h;
|
||||
}
|
||||
|
|
|
@ -589,12 +589,11 @@ static char *FormatString(char *buff, const char *str, const int32 *argv, uint c
|
|||
}
|
||||
|
||||
case 11: { /* {INDUSTRY} */
|
||||
Industry *i = GetIndustry(GetInt32(&argv));
|
||||
const Industry* i = GetIndustry(GetInt32(&argv));
|
||||
int32 args[2];
|
||||
|
||||
// industry not valid anymore?
|
||||
if (i->xy == 0)
|
||||
break;
|
||||
if (i->xy == 0) break;
|
||||
|
||||
// First print the town name and the industry type name
|
||||
// The string STR_INDUSTRY_PATTERN controls the formatting
|
||||
|
@ -1048,7 +1047,6 @@ bool ReadLanguagePack(int lang_index)
|
|||
|
||||
ttd_strlcpy(_dynlang.curr_file, _dynlang.ent[lang_index].file, sizeof(_dynlang.curr_file));
|
||||
|
||||
|
||||
_dynlang.curr = lang_index;
|
||||
return true;
|
||||
}
|
||||
|
@ -1117,8 +1115,7 @@ void InitializeLanguagePacks(void)
|
|||
error(n == 0 ? "No available language packs" : "Invalid version of language packs");
|
||||
|
||||
dl->num = m;
|
||||
for (i = 0; i != dl->num; i++)
|
||||
dl->dropdown[i] = SPECSTR_LANGUAGE_START + i;
|
||||
for (i = 0; i != dl->num; i++) dl->dropdown[i] = SPECSTR_LANGUAGE_START + i;
|
||||
dl->dropdown[i] = INVALID_STRING_ID;
|
||||
|
||||
for (i = 0; i != dl->num; i++)
|
||||
|
|
|
@ -419,7 +419,7 @@ not_valid_below:;
|
|||
if (_current_player < MAX_PLAYERS && !_is_old_ai_player)
|
||||
bridge_len = CalcBridgeLenCostFactor(bridge_len);
|
||||
|
||||
cost += ((int64)bridge_len * _price.build_bridge * b->price) >> 8;
|
||||
cost += (int64)bridge_len * _price.build_bridge * b->price >> 8;
|
||||
}
|
||||
|
||||
return cost;
|
||||
|
|
Loading…
Reference in New Issue