mirror of https://github.com/OpenTTD/OpenTTD.git
(svn r3613) Some more const, indentation, whitespace and similar stuff
This commit is contained in:
parent
6cfefdb275
commit
49c7eb934b
File diff suppressed because it is too large
Load Diff
|
@ -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) {
|
||||
|
|
16
economy.c
16
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 */
|
||||
|
@ -239,13 +238,13 @@ int UpdateCompanyRatingAndValue(Player *p, bool update)
|
|||
int total_score = 0;
|
||||
int s;
|
||||
score = 0;
|
||||
for (i=0;i<NUM_SCORE;i++) {
|
||||
for (i = 0; i < NUM_SCORE; i++) {
|
||||
// Skip the total
|
||||
if (i == SCORE_TOTAL) continue;
|
||||
// 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) {
|
||||
|
|
75
graph_gui.c
75
graph_gui.c
|
@ -884,9 +884,9 @@ 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;
|
||||
uint16 y = 14;
|
||||
int total_score = 0;
|
||||
int color_done, color_notdone;
|
||||
|
||||
|
@ -897,15 +897,14 @@ static void PerformanceRatingDetailWndProc(Window *w, WindowEvent *e)
|
|||
owner = FindFirstBit(w->click_state) - 13;
|
||||
|
||||
// Paint the player icons
|
||||
for (i=0;i<MAX_PLAYERS;i++) {
|
||||
for (i = 0; i < MAX_PLAYERS; i++) {
|
||||
if (!GetPlayer(i)->is_active) {
|
||||
// Check if we have the player as an active player
|
||||
if (!(w->disabled_state & (1 << (i+13)))) {
|
||||
if (!(w->disabled_state & (1 << (i + 13)))) {
|
||||
// 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)
|
||||
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);
|
||||
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);
|
||||
}
|
||||
|
||||
|
@ -929,11 +928,12 @@ static void PerformanceRatingDetailWndProc(Window *w, WindowEvent *e)
|
|||
color_notdone = _color_list[4].window_color_1b;
|
||||
|
||||
// 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;
|
||||
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
|
||||
|
@ -1017,16 +1015,14 @@ static void PerformanceRatingDetailWndProc(Window *w, WindowEvent *e)
|
|||
w->disabled_state = 0;
|
||||
|
||||
// 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);
|
||||
}
|
||||
for (i = 0; i < MAX_PLAYERS; i++) {
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
|
6
misc.c
6
misc.c
|
@ -600,9 +600,9 @@ int FindFirstBit(uint32 value)
|
|||
// not more than 128.
|
||||
byte i = 0;
|
||||
if (value & 0xffff0000) { value >>= 16; i += 16; }
|
||||
if (value & 0x0000ff00) { value >>= 8; i += 8; }
|
||||
if (value & 0x000000f0) { value >>= 4; i += 4; }
|
||||
if (value & 0x0000000c) { value >>= 2; i += 2; }
|
||||
if (value & 0x0000ff00) { value >>= 8; i += 8; }
|
||||
if (value & 0x000000f0) { value >>= 4; i += 4; }
|
||||
if (value & 0x0000000c) { value >>= 2; i += 2; }
|
||||
if (value & 0x00000002) { i += 1; }
|
||||
return i;
|
||||
}
|
||||
|
|
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,15 +2590,19 @@ 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,12 +282,13 @@ 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
|
||||
GenerateWorld(GW_EMPTY, 64, 64); // if failed loading, make empty world.
|
||||
if (SaveOrLoad(filename, SL_LOAD) != SL_OK) {
|
||||
GenerateWorld(GW_EMPTY, 64, 64); // if failed loading, make empty world.
|
||||
}
|
||||
|
||||
_pause = 0;
|
||||
|
|
|
@ -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
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -857,7 +862,7 @@ static bool FindRoadVehToOvertake(OvertakeData *od)
|
|||
{
|
||||
uint32 bits;
|
||||
|
||||
bits = GetTileTrackStatus(od->tile, TRANSPORT_ROAD)&0x3F;
|
||||
bits = GetTileTrackStatus(od->tile, TRANSPORT_ROAD) & 0x3F;
|
||||
|
||||
if (!(od->tilebits & bits) || (bits&0x3C) || (bits & 0x3F3F0000))
|
||||
return true;
|
||||
|
@ -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;
|
||||
|
@ -1049,7 +1052,7 @@ static int RoadFindPathToDest(Vehicle *v, TileIndex tile, int enterdir)
|
|||
} else {
|
||||
if (IsTileType(desttile, MP_STREET)) {
|
||||
m5 = _m[desttile].m5;
|
||||
if ((m5&0xF0) == 0x20)
|
||||
if ((m5 & 0xF0) == 0x20)
|
||||
/* We are heading for a Depot */
|
||||
goto do_it;
|
||||
} else if (IsTileType(desttile, MP_STATION)) {
|
||||
|
@ -1169,16 +1172,16 @@ static void RoadVehController(Vehicle *v)
|
|||
|
||||
if (v->u.road.state == 254) {
|
||||
int dir;
|
||||
const RoadDriveEntry*rdp;
|
||||
const RoadDriveEntry* rdp;
|
||||
byte rd2;
|
||||
|
||||
v->cur_speed = 0;
|
||||
|
||||
dir = GB(_m[v->tile].m5, 0, 2);
|
||||
v->direction = dir*2+1;
|
||||
v->direction = dir * 2 + 1;
|
||||
|
||||
rd2 = _roadveh_data_2[dir];
|
||||
rdp = _road_drive_data[(_opt.road_side<<4) + rd2];
|
||||
rdp = _road_drive_data[(_opt.road_side << 4) + rd2];
|
||||
|
||||
x = TileX(v->tile) * 16 + (rdp[6].x & 0xF);
|
||||
y = TileY(v->tile) * 16 + (rdp[6].y & 0xF);
|
||||
|
@ -1213,8 +1216,9 @@ 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);
|
||||
|
@ -1244,12 +1248,12 @@ static void RoadVehController(Vehicle *v)
|
|||
return;
|
||||
}
|
||||
|
||||
rd = _road_drive_data[(v->u.road.state + (_opt.road_side<<4)) ^ v->u.road.overtaking][v->u.road.frame+1];
|
||||
rd = _road_drive_data[(v->u.road.state + (_opt.road_side << 4)) ^ v->u.road.overtaking][v->u.road.frame + 1];
|
||||
|
||||
// switch to another tile
|
||||
if (rd.x & 0x80) {
|
||||
TileIndex tile = v->tile + TileOffsByDir(rd.x & 3);
|
||||
int dir = RoadFindPathToDest(v, tile, rd.x&3);
|
||||
int dir = RoadFindPathToDest(v, tile, rd.x & 3);
|
||||
uint32 r;
|
||||
byte newdir;
|
||||
const RoadDriveEntry *rdp;
|
||||
|
@ -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;
|
||||
|
@ -1312,7 +1319,7 @@ again:
|
|||
}
|
||||
|
||||
if (rd.x & 0x40) {
|
||||
int dir = RoadFindPathToDest(v, v->tile, rd.x&3);
|
||||
int dir = RoadFindPathToDest(v, v->tile, rd.x & 3);
|
||||
uint32 r;
|
||||
int tmp;
|
||||
byte newdir;
|
||||
|
@ -1323,7 +1330,7 @@ again:
|
|||
return;
|
||||
}
|
||||
|
||||
tmp = (_opt.road_side<<4) + dir;
|
||||
tmp = (_opt.road_side << 4) + dir;
|
||||
rdp = _road_drive_data[tmp];
|
||||
|
||||
x = TileX(v->tile) * 16 + rdp[1].x;
|
||||
|
@ -1352,12 +1359,13 @@ again:
|
|||
return;
|
||||
}
|
||||
|
||||
x = (v->x_pos&~15)+(rd.x&15);
|
||||
y = (v->y_pos&~15)+(rd.y&15);
|
||||
x = (v->x_pos & ~15) + (rd.x & 15);
|
||||
y = (v->y_pos & ~15) + (rd.y & 15);
|
||||
|
||||
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);
|
||||
|
|
|
@ -1623,12 +1623,12 @@ int32 CmdBuildAirport(int x, int y, uint32 flags, uint32 p1, uint32 p2)
|
|||
{
|
||||
const byte *b = _airport_map5_tiles[p1];
|
||||
|
||||
BEGIN_TILE_LOOP(tile_cur,w,h,tile) {
|
||||
BEGIN_TILE_LOOP(tile_cur, w, h, tile) {
|
||||
ModifyTile(tile_cur,
|
||||
MP_SETTYPE(MP_STATION) | MP_MAPOWNER_CURRENT |
|
||||
MP_MAP2 | MP_MAP3LO_CLEAR | MP_MAP3HI_CLEAR | MP_MAP5,
|
||||
st->index, *b++);
|
||||
} END_TILE_LOOP(tile_cur,w,h,tile)
|
||||
} END_TILE_LOOP(tile_cur, w, h, tile)
|
||||
}
|
||||
|
||||
UpdateStationVirtCoordDirty(st);
|
||||
|
@ -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