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