mirror of https://github.com/OpenTTD/OpenTTD.git
(svn r3564) Several smaller changes:
- Don't treat non-booleans as booleans - Reduce variable scope - Bracing - Use DeMorgan's law to make conditionals easier to read - if cascade -> switch - Replace some magic numbers by symbolic names - Avoid assignments within other statements
This commit is contained in:
parent
0755bbead0
commit
453b30e387
|
@ -2778,8 +2778,7 @@ static bool AiEnumFollowRoad(TileIndex tile, AiRoadEnum *a, int track, uint leng
|
||||||
if (dist <= a->best_dist) {
|
if (dist <= a->best_dist) {
|
||||||
TileIndex tile2 = TILE_MASK(tile + TileOffsByDir(_dir_by_track[track]));
|
TileIndex tile2 = TILE_MASK(tile + TileOffsByDir(_dir_by_track[track]));
|
||||||
|
|
||||||
if (IsTileType(tile2, MP_STREET) &&
|
if (IsTileType(tile2, MP_STREET) && GB(_m[tile2].m5, 4, 4) == 0) {
|
||||||
(_m[tile2].m5&0xF0) == 0) {
|
|
||||||
a->best_dist = dist;
|
a->best_dist = dist;
|
||||||
a->best_tile = tile;
|
a->best_tile = tile;
|
||||||
a->best_track = track;
|
a->best_track = track;
|
||||||
|
|
|
@ -98,7 +98,7 @@ int GetAircraftImage(const Vehicle *v, byte direction)
|
||||||
if (is_custom_sprite(spritenum)) {
|
if (is_custom_sprite(spritenum)) {
|
||||||
int sprite = GetCustomVehicleSprite(v, direction);
|
int sprite = GetCustomVehicleSprite(v, direction);
|
||||||
|
|
||||||
if (sprite) return sprite;
|
if (sprite != 0) return sprite;
|
||||||
spritenum = orig_aircraft_vehicle_info[v->engine_type - AIRCRAFT_ENGINES_INDEX].image_index;
|
spritenum = orig_aircraft_vehicle_info[v->engine_type - AIRCRAFT_ENGINES_INDEX].image_index;
|
||||||
}
|
}
|
||||||
return direction + _aircraft_sprite[spritenum];
|
return direction + _aircraft_sprite[spritenum];
|
||||||
|
|
|
@ -637,10 +637,9 @@ static void TileLoop_Clear(TileIndex tile)
|
||||||
{
|
{
|
||||||
TileLoopClearHelper(tile);
|
TileLoopClearHelper(tile);
|
||||||
|
|
||||||
if (_opt.landscape == LT_DESERT) {
|
switch (_opt.landscape) {
|
||||||
TileLoopClearDesert(tile);
|
case LT_DESERT: TileLoopClearDesert(tile); break;
|
||||||
} else if (_opt.landscape == LT_HILLY) {
|
case LT_HILLY: TileLoopClearAlps(tile); break;
|
||||||
TileLoopClearAlps(tile);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
switch (GetClearGround(tile)) {
|
switch (GetClearGround(tile)) {
|
||||||
|
|
|
@ -898,10 +898,11 @@ static void Disaster6_Init(void)
|
||||||
static void Disaster7_Init(void)
|
static void Disaster7_Init(void)
|
||||||
{
|
{
|
||||||
int index = GB(Random(), 0, 4);
|
int index = GB(Random(), 0, 4);
|
||||||
Industry *i;
|
|
||||||
uint m;
|
uint m;
|
||||||
|
|
||||||
for (m = 0; m < 15; m++) {
|
for (m = 0; m < 15; m++) {
|
||||||
|
const Industry* i;
|
||||||
|
|
||||||
FOR_ALL_INDUSTRIES(i) {
|
FOR_ALL_INDUSTRIES(i) {
|
||||||
if (i->xy != 0 && i->type == IT_COAL_MINE && --index < 0) {
|
if (i->xy != 0 && i->type == IT_COAL_MINE && --index < 0) {
|
||||||
SetDParam(0, i->town->index);
|
SetDParam(0, i->town->index);
|
||||||
|
|
57
economy.c
57
economy.c
|
@ -346,14 +346,12 @@ void ChangeOwnershipOfPlayerItems(PlayerID old_player, PlayerID new_player)
|
||||||
DeleteVehicle(v);
|
DeleteVehicle(v);
|
||||||
} else {
|
} else {
|
||||||
v->owner = new_player;
|
v->owner = new_player;
|
||||||
if (v->type == VEH_Train && IsFrontEngine(v))
|
switch (v->type) {
|
||||||
v->unitnumber = ++num_train;
|
case VEH_Train: if (IsFrontEngine(v)) v->unitnumber = ++num_train; break;
|
||||||
else if (v->type == VEH_Road)
|
case VEH_Road: v->unitnumber = ++num_road; break;
|
||||||
v->unitnumber = ++num_road;
|
case VEH_Ship: v->unitnumber = ++num_ship; break;
|
||||||
else if (v->type == VEH_Ship)
|
case VEH_Aircraft: if (v->subtype <= 2) v->unitnumber = ++num_aircraft; break;
|
||||||
v->unitnumber = ++num_ship;
|
}
|
||||||
else if (v->type == VEH_Aircraft && v->subtype <= 2)
|
|
||||||
v->unitnumber = ++num_aircraft;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1190,10 +1188,17 @@ static bool CheckSubsidised(Station *from, Station *to, byte cargo_type)
|
||||||
if (DistanceMax(xy, from->xy) > 9) continue;
|
if (DistanceMax(xy, from->xy) > 9) continue;
|
||||||
|
|
||||||
/* Check distance from dest */
|
/* Check distance from dest */
|
||||||
if (cargo_type == CT_PASSENGERS || cargo_type == CT_MAIL || cargo_type == CT_GOODS || cargo_type == CT_FOOD) {
|
switch (cargo_type) {
|
||||||
|
case CT_PASSENGERS:
|
||||||
|
case CT_MAIL:
|
||||||
|
case CT_GOODS:
|
||||||
|
case CT_FOOD:
|
||||||
xy = GetTown(s->to)->xy;
|
xy = GetTown(s->to)->xy;
|
||||||
} else {
|
break;
|
||||||
xy = (GetIndustry(s->to))->xy;
|
|
||||||
|
default:
|
||||||
|
xy = GetIndustry(s->to)->xy;
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
if (DistanceMax(xy, to->xy) > 9) continue;
|
if (DistanceMax(xy, to->xy) > 9) continue;
|
||||||
|
|
||||||
|
@ -1256,18 +1261,11 @@ static int32 DeliverGoods(int num_pieces, byte cargo_type, uint16 source, uint16
|
||||||
|
|
||||||
// Modify profit if a subsidy is in effect
|
// Modify profit if a subsidy is in effect
|
||||||
if (subsidised) {
|
if (subsidised) {
|
||||||
if (_opt.diff.subsidy_multiplier < 1) {
|
switch (_opt.diff.subsidy_multiplier) {
|
||||||
/* 1.5x */
|
case 0: profit += profit >> 1;
|
||||||
profit += profit >> 1;
|
case 1: profit *= 2;
|
||||||
} else if (_opt.diff.subsidy_multiplier == 1) {
|
case 2: profit *= 3;
|
||||||
/* 2x */
|
default: profit *= 4;
|
||||||
profit *= 2;
|
|
||||||
} else if (_opt.diff.subsidy_multiplier == 2) {
|
|
||||||
/* 3x */
|
|
||||||
profit *= 3;
|
|
||||||
} else {
|
|
||||||
/* 4x */
|
|
||||||
profit *= 4;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1353,7 +1351,8 @@ int LoadUnloadVehicle(Vehicle *v)
|
||||||
old_player = _current_player;
|
old_player = _current_player;
|
||||||
_current_player = v->owner;
|
_current_player = v->owner;
|
||||||
|
|
||||||
st = GetStation(last_visited = v->last_station_visited);
|
last_visited = v->last_station_visited;
|
||||||
|
st = GetStation(last_visited);
|
||||||
|
|
||||||
for (; v != NULL; v = v->next) {
|
for (; v != NULL; v = v->next) {
|
||||||
GoodsEntry* ge;
|
GoodsEntry* ge;
|
||||||
|
@ -1413,12 +1412,14 @@ int LoadUnloadVehicle(Vehicle *v)
|
||||||
|
|
||||||
/* update stats */
|
/* update stats */
|
||||||
ge->days_since_pickup = 0;
|
ge->days_since_pickup = 0;
|
||||||
t = u->max_speed;
|
switch (u->type) {
|
||||||
if (u->type == VEH_Road) t >>=1;
|
case VEH_Train: t = u->u.rail.cached_max_speed; break;
|
||||||
if (u->type == VEH_Train) t = u->u.rail.cached_max_speed;
|
case VEH_Road: t = u->max_speed / 2; break;
|
||||||
|
default: t = u->max_speed; break;
|
||||||
|
}
|
||||||
|
|
||||||
// if last speed is 0, we treat that as if no vehicle has ever visited the station.
|
// if last speed is 0, we treat that as if no vehicle has ever visited the station.
|
||||||
ge->last_speed = t < 255 ? t : 255;
|
ge->last_speed = min(t, 255);
|
||||||
ge->last_age = _cur_year - v->build_year;
|
ge->last_age = _cur_year - v->build_year;
|
||||||
|
|
||||||
// If there's goods waiting at the station, and the vehicle
|
// If there's goods waiting at the station, and the vehicle
|
||||||
|
|
|
@ -280,22 +280,22 @@ static void IndustryViewWndProc(Window *w, WindowEvent *e)
|
||||||
|
|
||||||
switch (e->event) {
|
switch (e->event) {
|
||||||
case WE_PAINT: {
|
case WE_PAINT: {
|
||||||
const Industry *i;
|
const Industry* i = GetIndustry(w->window_number);
|
||||||
StringID str;
|
|
||||||
|
|
||||||
i = GetIndustry(w->window_number);
|
|
||||||
SetDParam(0, w->window_number);
|
SetDParam(0, w->window_number);
|
||||||
DrawWindowWidgets(w);
|
DrawWindowWidgets(w);
|
||||||
|
|
||||||
if (i->accepts_cargo[0] != CT_INVALID) {
|
if (i->accepts_cargo[0] != CT_INVALID) {
|
||||||
|
StringID str;
|
||||||
|
|
||||||
SetDParam(0, _cargoc.names_s[i->accepts_cargo[0]]);
|
SetDParam(0, _cargoc.names_s[i->accepts_cargo[0]]);
|
||||||
str = STR_4827_REQUIRES;
|
str = STR_4827_REQUIRES;
|
||||||
if (i->accepts_cargo[1] != CT_INVALID) {
|
if (i->accepts_cargo[1] != CT_INVALID) {
|
||||||
SetDParam(1, _cargoc.names_s[i->accepts_cargo[1]]);
|
SetDParam(1, _cargoc.names_s[i->accepts_cargo[1]]);
|
||||||
str++;
|
str = STR_4828_REQUIRES;
|
||||||
if (i->accepts_cargo[2] != CT_INVALID) {
|
if (i->accepts_cargo[2] != CT_INVALID) {
|
||||||
SetDParam(2, _cargoc.names_s[i->accepts_cargo[2]]);
|
SetDParam(2, _cargoc.names_s[i->accepts_cargo[2]]);
|
||||||
str++;
|
str = STR_4829_REQUIRES;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
DrawString(2, 107, str, 0);
|
DrawString(2, 107, str, 0);
|
||||||
|
@ -442,17 +442,14 @@ static const WindowDesc _industry_view_desc = {
|
||||||
|
|
||||||
void ShowIndustryViewWindow(int industry)
|
void ShowIndustryViewWindow(int industry)
|
||||||
{
|
{
|
||||||
Window *w;
|
Window* w = AllocateWindowDescFront(&_industry_view_desc, industry);
|
||||||
Industry *i;
|
|
||||||
|
|
||||||
w = AllocateWindowDescFront(&_industry_view_desc, industry);
|
if (w != NULL) {
|
||||||
if (w) {
|
|
||||||
w->flags4 |= WF_DISABLE_VP_SCROLL;
|
w->flags4 |= WF_DISABLE_VP_SCROLL;
|
||||||
WP(w,vp2_d).data_1 = 0;
|
WP(w,vp2_d).data_1 = 0;
|
||||||
WP(w,vp2_d).data_2 = 0;
|
WP(w,vp2_d).data_2 = 0;
|
||||||
WP(w,vp2_d).data_3 = 0;
|
WP(w,vp2_d).data_3 = 0;
|
||||||
i = GetIndustry(w->window_number);
|
AssignWindowViewport(w, 3, 17, 0xFE, 0x56, GetIndustry(w->window_number)->xy + TileDiffXY(1, 1), 1);
|
||||||
AssignWindowViewport(w, 3, 17, 0xFE, 0x56, i->xy + TileDiffXY(1, 1), 1);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -550,8 +547,7 @@ static void MakeSortedIndustryList(void)
|
||||||
error("Could not allocate memory for the industry-sorting-list");
|
error("Could not allocate memory for the industry-sorting-list");
|
||||||
|
|
||||||
FOR_ALL_INDUSTRIES(i) {
|
FOR_ALL_INDUSTRIES(i) {
|
||||||
if (i->xy)
|
if (i->xy != 0) _industry_sort[n++] = i->index;
|
||||||
_industry_sort[n++] = i->index;
|
|
||||||
}
|
}
|
||||||
_num_industry_sort = n;
|
_num_industry_sort = n;
|
||||||
_last_industry_idx = 0xFFFF; // used for "cache"
|
_last_industry_idx = 0xFFFF; // used for "cache"
|
||||||
|
@ -568,7 +564,6 @@ static void IndustryDirectoryWndProc(Window *w, WindowEvent *e)
|
||||||
case WE_PAINT: {
|
case WE_PAINT: {
|
||||||
int n;
|
int n;
|
||||||
uint p;
|
uint p;
|
||||||
Industry *i;
|
|
||||||
static const uint16 _indicator_positions[4] = {88, 187, 284, 387};
|
static const uint16 _indicator_positions[4] = {88, 187, 284, 387};
|
||||||
|
|
||||||
if (_industry_sort_dirty) {
|
if (_industry_sort_dirty) {
|
||||||
|
@ -585,7 +580,8 @@ static void IndustryDirectoryWndProc(Window *w, WindowEvent *e)
|
||||||
n = 0;
|
n = 0;
|
||||||
|
|
||||||
while (p < _num_industry_sort) {
|
while (p < _num_industry_sort) {
|
||||||
i = GetIndustry(_industry_sort[p]);
|
const Industry* i = GetIndustry(_industry_sort[p]);
|
||||||
|
|
||||||
SetDParam(0, i->index);
|
SetDParam(0, i->index);
|
||||||
if (i->produced_cargo[0] != CT_INVALID) {
|
if (i->produced_cargo[0] != CT_INVALID) {
|
||||||
SetDParam(1, _cargoc.names_long[i->produced_cargo[0]]);
|
SetDParam(1, _cargoc.names_long[i->produced_cargo[0]]);
|
||||||
|
@ -638,14 +634,11 @@ static void IndustryDirectoryWndProc(Window *w, WindowEvent *e)
|
||||||
case 8: {
|
case 8: {
|
||||||
int y = (e->click.pt.y - 28) / 10;
|
int y = (e->click.pt.y - 28) / 10;
|
||||||
uint16 p;
|
uint16 p;
|
||||||
Industry *c;
|
|
||||||
|
|
||||||
if (!IS_INT_INSIDE(y, 0, w->vscroll.cap))
|
if (!IS_INT_INSIDE(y, 0, w->vscroll.cap)) return;
|
||||||
return;
|
|
||||||
p = y + w->vscroll.pos;
|
p = y + w->vscroll.pos;
|
||||||
if (p < _num_industry_sort) {
|
if (p < _num_industry_sort) {
|
||||||
c = GetIndustry(_industry_sort[p]);
|
ScrollMainWindowToTile(GetIndustry(_industry_sort[p])->xy);
|
||||||
ScrollMainWindowToTile(c->xy);
|
|
||||||
}
|
}
|
||||||
} break;
|
} break;
|
||||||
}
|
}
|
||||||
|
@ -674,11 +667,9 @@ static const WindowDesc _industry_directory_desc = {
|
||||||
|
|
||||||
void ShowIndustryDirectory(void)
|
void ShowIndustryDirectory(void)
|
||||||
{
|
{
|
||||||
/* Industry List */
|
Window* w = AllocateWindowDescFront(&_industry_directory_desc, 0);
|
||||||
Window *w;
|
|
||||||
|
|
||||||
w = AllocateWindowDescFront(&_industry_directory_desc, 0);
|
if (w != NULL) {
|
||||||
if (w) {
|
|
||||||
w->vscroll.cap = 16;
|
w->vscroll.cap = 16;
|
||||||
w->resize.height = w->height - 6 * 10; // minimum 10 items
|
w->resize.height = w->height - 6 * 10; // minimum 10 items
|
||||||
w->resize.step_height = 10;
|
w->resize.step_height = 10;
|
||||||
|
|
27
misc.c
27
misc.c
|
@ -78,7 +78,9 @@ uint InteractiveRandomRange(uint max)
|
||||||
void SetDate(uint date)
|
void SetDate(uint date)
|
||||||
{
|
{
|
||||||
YearMonthDay ymd;
|
YearMonthDay ymd;
|
||||||
ConvertDayToYMD(&ymd, _date = date);
|
|
||||||
|
_date = date;
|
||||||
|
ConvertDayToYMD(&ymd, date);
|
||||||
_cur_year = ymd.year;
|
_cur_year = ymd.year;
|
||||||
_cur_month = ymd.month;
|
_cur_month = ymd.month;
|
||||||
#ifdef ENABLE_NETWORK
|
#ifdef ENABLE_NETWORK
|
||||||
|
@ -186,8 +188,6 @@ void InitializeGame(int mode, uint size_x, uint size_y)
|
||||||
|
|
||||||
void GenerateWorld(int mode, uint size_x, uint size_y)
|
void GenerateWorld(int mode, uint size_x, uint size_y)
|
||||||
{
|
{
|
||||||
int i;
|
|
||||||
|
|
||||||
// Make sure everything is done via OWNER_NONE
|
// Make sure everything is done via OWNER_NONE
|
||||||
_current_player = OWNER_NONE;
|
_current_player = OWNER_NONE;
|
||||||
|
|
||||||
|
@ -223,7 +223,9 @@ void GenerateWorld(int mode, uint size_x, uint size_y)
|
||||||
|
|
||||||
// No need to run the tile loop in the scenario editor.
|
// No need to run the tile loop in the scenario editor.
|
||||||
if (mode != GW_EMPTY) {
|
if (mode != GW_EMPTY) {
|
||||||
for (i = 0x500; i != 0; i--) RunTileLoop();
|
uint i;
|
||||||
|
|
||||||
|
for (i = 0; i < 0x500; i++) RunTileLoop();
|
||||||
}
|
}
|
||||||
|
|
||||||
ResetObjectToPlace();
|
ResetObjectToPlace();
|
||||||
|
@ -410,7 +412,7 @@ typedef struct LandscapePredefVar {
|
||||||
void InitializeLandscapeVariables(bool only_constants)
|
void InitializeLandscapeVariables(bool only_constants)
|
||||||
{
|
{
|
||||||
const LandscapePredefVar *lpd;
|
const LandscapePredefVar *lpd;
|
||||||
int i;
|
uint i;
|
||||||
StringID str;
|
StringID str;
|
||||||
|
|
||||||
lpd = &_landscape_predef_var[_opt.landscape];
|
lpd = &_landscape_predef_var[_opt.landscape];
|
||||||
|
@ -487,7 +489,8 @@ static const uint16 _autosave_months[] = {
|
||||||
*/
|
*/
|
||||||
static void RunVehicleDayProc(uint daytick)
|
static void RunVehicleDayProc(uint daytick)
|
||||||
{
|
{
|
||||||
uint i, total = _vehicle_pool.total_items;
|
uint total = _vehicle_pool.total_items;
|
||||||
|
uint i;
|
||||||
|
|
||||||
for (i = daytick; i < total; i += DAY_TICKS) {
|
for (i = daytick; i < total; i += DAY_TICKS) {
|
||||||
Vehicle* v = GetVehicle(i);
|
Vehicle* v = GetVehicle(i);
|
||||||
|
@ -976,13 +979,13 @@ static void Save_CHTS(void)
|
||||||
|
|
||||||
static void Load_CHTS(void)
|
static void Load_CHTS(void)
|
||||||
{
|
{
|
||||||
Cheat* cht = (Cheat*) &_cheats;
|
Cheat* cht = (Cheat*)&_cheats;
|
||||||
|
uint count = SlGetFieldLength() / 2;
|
||||||
|
uint i;
|
||||||
|
|
||||||
uint count = SlGetFieldLength()/2;
|
for (i = 0; i < count; i++) {
|
||||||
for (; count; count--, cht++)
|
cht[i].been_used = SlReadByte();
|
||||||
{
|
cht[i].value = SlReadByte();
|
||||||
cht->been_used = (byte)SlReadByte();
|
|
||||||
cht->value = (byte)SlReadByte();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -100,8 +100,8 @@ void NetworkSend_Packet(Packet *packet, NetworkClientState *cs)
|
||||||
packet->pos = 0;
|
packet->pos = 0;
|
||||||
packet->next = NULL;
|
packet->next = NULL;
|
||||||
|
|
||||||
packet->buffer[0] = packet->size & 0xFF;
|
packet->buffer[0] = GB(packet->size, 0, 8);
|
||||||
packet->buffer[1] = packet->size >> 8;
|
packet->buffer[1] = GB(packet->size, 8, 8);
|
||||||
|
|
||||||
// Locate last packet buffered for the client
|
// Locate last packet buffered for the client
|
||||||
p = cs->packet_queue;
|
p = cs->packet_queue;
|
||||||
|
|
|
@ -657,7 +657,7 @@ static void StartScenario(void)
|
||||||
}
|
}
|
||||||
|
|
||||||
_opt_ptr = &_opt;
|
_opt_ptr = &_opt;
|
||||||
memcpy(&_opt_ptr->diff, &_opt_newgame.diff, sizeof(GameDifficulty));
|
memcpy(&_opt_ptr->diff, &_opt_newgame.diff, sizeof(_opt_ptr->diff));
|
||||||
_opt.diff_level = _opt_newgame.diff_level;
|
_opt.diff_level = _opt_newgame.diff_level;
|
||||||
|
|
||||||
// Inititalize data
|
// Inititalize data
|
||||||
|
@ -731,7 +731,7 @@ void SwitchMode(int new_mode)
|
||||||
case SM_NEWGAME: /* New Game --> 'Random game' */
|
case SM_NEWGAME: /* New Game --> 'Random game' */
|
||||||
#ifdef ENABLE_NETWORK
|
#ifdef ENABLE_NETWORK
|
||||||
if (_network_server) {
|
if (_network_server) {
|
||||||
snprintf(_network_game_info.map_name, NETWORK_NAME_LENGTH, "Random Map");
|
snprintf(_network_game_info.map_name, lengthof(_network_game_info.map_name), "Random Map");
|
||||||
}
|
}
|
||||||
#endif /* ENABLE_NETWORK */
|
#endif /* ENABLE_NETWORK */
|
||||||
MakeNewGame();
|
MakeNewGame();
|
||||||
|
@ -740,7 +740,7 @@ void SwitchMode(int new_mode)
|
||||||
case SM_START_SCENARIO: /* New Game --> Choose one of the preset scenarios */
|
case SM_START_SCENARIO: /* New Game --> Choose one of the preset scenarios */
|
||||||
#ifdef ENABLE_NETWORK
|
#ifdef ENABLE_NETWORK
|
||||||
if (_network_server) {
|
if (_network_server) {
|
||||||
snprintf(_network_game_info.map_name, NETWORK_NAME_LENGTH, "%s (Loaded scenario)", _file_to_saveload.title);
|
snprintf(_network_game_info.map_name, lengthof(_network_game_info.map_name), "%s (Loaded scenario)", _file_to_saveload.title);
|
||||||
}
|
}
|
||||||
#endif /* ENABLE_NETWORK */
|
#endif /* ENABLE_NETWORK */
|
||||||
StartScenario();
|
StartScenario();
|
||||||
|
@ -757,7 +757,7 @@ void SwitchMode(int new_mode)
|
||||||
DoCommandP(0, 0, 0, NULL, CMD_PAUSE); // decrease pause counter (was increased from opening load dialog)
|
DoCommandP(0, 0, 0, NULL, CMD_PAUSE); // decrease pause counter (was increased from opening load dialog)
|
||||||
#ifdef ENABLE_NETWORK
|
#ifdef ENABLE_NETWORK
|
||||||
if (_network_server) {
|
if (_network_server) {
|
||||||
snprintf(_network_game_info.map_name, NETWORK_NAME_LENGTH, "%s (Loaded game)", _file_to_saveload.title);
|
snprintf(_network_game_info.map_name, lengthof(_network_game_info.map_name), "%s (Loaded game)", _file_to_saveload.title);
|
||||||
}
|
}
|
||||||
#endif /* ENABLE_NETWORK */
|
#endif /* ENABLE_NETWORK */
|
||||||
}
|
}
|
||||||
|
|
28
order_cmd.c
28
order_cmd.c
|
@ -366,8 +366,7 @@ int32 CmdInsertOrder(int x, int y, uint32 flags, uint32 p1, uint32 p2)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
u = GetFirstVehicleFromSharedList(v);
|
for (u = GetFirstVehicleFromSharedList(v); u != NULL; u = u->next_shared) {
|
||||||
while (u != NULL) {
|
|
||||||
/* Increase amount of orders */
|
/* Increase amount of orders */
|
||||||
u->num_orders++;
|
u->num_orders++;
|
||||||
|
|
||||||
|
@ -386,8 +385,6 @@ int32 CmdInsertOrder(int x, int y, uint32 flags, uint32 p1, uint32 p2)
|
||||||
}
|
}
|
||||||
/* Update any possible open window of the vehicle */
|
/* Update any possible open window of the vehicle */
|
||||||
InvalidateVehicleOrder(u);
|
InvalidateVehicleOrder(u);
|
||||||
|
|
||||||
u = u->next_shared;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Make sure to rebuild the whole list */
|
/* Make sure to rebuild the whole list */
|
||||||
|
@ -454,8 +451,7 @@ int32 CmdDeleteOrder(int x, int y, uint32 flags, uint32 p1, uint32 p2)
|
||||||
order->type = OT_NOTHING;
|
order->type = OT_NOTHING;
|
||||||
order->next = NULL;
|
order->next = NULL;
|
||||||
|
|
||||||
u = GetFirstVehicleFromSharedList(v);
|
for (u = GetFirstVehicleFromSharedList(v); u != NULL; u = u->next_shared) {
|
||||||
while (u != NULL) {
|
|
||||||
u->num_orders--;
|
u->num_orders--;
|
||||||
|
|
||||||
if (sel_ord < u->cur_order_index)
|
if (sel_ord < u->cur_order_index)
|
||||||
|
@ -476,8 +472,6 @@ int32 CmdDeleteOrder(int x, int y, uint32 flags, uint32 p1, uint32 p2)
|
||||||
|
|
||||||
/* Update any possible open window of the vehicle */
|
/* Update any possible open window of the vehicle */
|
||||||
InvalidateVehicleOrder(u);
|
InvalidateVehicleOrder(u);
|
||||||
|
|
||||||
u = u->next_shared;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
RebuildVehicleLists();
|
RebuildVehicleLists();
|
||||||
|
@ -579,14 +573,15 @@ int32 CmdModifyOrder(int x, int y, uint32 flags, uint32 p1, uint32 p2)
|
||||||
|
|
||||||
/* Update the windows and full load flags, also for vehicles that share the same order list */
|
/* Update the windows and full load flags, also for vehicles that share the same order list */
|
||||||
{
|
{
|
||||||
Vehicle *u = GetFirstVehicleFromSharedList(v);
|
Vehicle* u;
|
||||||
while (u != NULL) {
|
|
||||||
|
for (u = GetFirstVehicleFromSharedList(v); u != NULL; u = u->next_shared) {
|
||||||
/* toggle u->current_order "Full load" flag if it changed */
|
/* toggle u->current_order "Full load" flag if it changed */
|
||||||
if (sel_ord == u->cur_order_index &&
|
if (sel_ord == u->cur_order_index &&
|
||||||
HASBIT(u->current_order.flags, OFB_FULL_LOAD) != HASBIT(order->flags, OFB_FULL_LOAD))
|
HASBIT(u->current_order.flags, OFB_FULL_LOAD) != HASBIT(order->flags, OFB_FULL_LOAD)) {
|
||||||
TOGGLEBIT(u->current_order.flags, OFB_FULL_LOAD);
|
TOGGLEBIT(u->current_order.flags, OFB_FULL_LOAD);
|
||||||
|
}
|
||||||
InvalidateVehicleOrder(u);
|
InvalidateVehicleOrder(u);
|
||||||
u = u->next_shared;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -632,11 +627,10 @@ int32 CmdCloneOrder(int x, int y, uint32 flags, uint32 p1, uint32 p2)
|
||||||
|
|
||||||
/* Is the vehicle already in the shared list? */
|
/* Is the vehicle already in the shared list? */
|
||||||
{
|
{
|
||||||
Vehicle *u = GetFirstVehicleFromSharedList(src);
|
const Vehicle* u;
|
||||||
while (u != NULL) {
|
|
||||||
if (u == dst)
|
for (u = GetFirstVehicleFromSharedList(src); u != NULL; u = u->next_shared) {
|
||||||
return CMD_ERROR;
|
if (u == dst) return CMD_ERROR;
|
||||||
u = u->next_shared;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
6
rail.h
6
rail.h
|
@ -635,9 +635,9 @@ static inline bool TracksOverlap(TrackBits bits)
|
||||||
/* We know that there are at least two tracks present. When there are more
|
/* We know that there are at least two tracks present. When there are more
|
||||||
* than 2 tracks, they will surely overlap. When there are two, they will
|
* than 2 tracks, they will surely overlap. When there are two, they will
|
||||||
* always overlap unless they are lower & upper or right & left. */
|
* always overlap unless they are lower & upper or right & left. */
|
||||||
if ((bits == (TRACK_BIT_UPPER|TRACK_BIT_LOWER)) || (bits == (TRACK_BIT_LEFT | TRACK_BIT_RIGHT)))
|
return
|
||||||
return false;
|
bits != (TRACK_BIT_UPPER | TRACK_BIT_LOWER) &&
|
||||||
return true;
|
bits != (TRACK_BIT_LEFT | TRACK_BIT_RIGHT);
|
||||||
}
|
}
|
||||||
|
|
||||||
void DrawTrainDepotSprite(int x, int y, int image, RailType railtype);
|
void DrawTrainDepotSprite(int x, int y, int image, RailType railtype);
|
||||||
|
|
|
@ -1469,10 +1469,11 @@ static void DrawTile_Track(TileInfo *ti)
|
||||||
DrawGroundSprite(image);
|
DrawGroundSprite(image);
|
||||||
|
|
||||||
foreach_draw_tile_seq(seq, cust->seq) {
|
foreach_draw_tile_seq(seq, cust->seq) {
|
||||||
uint32 image = seq->image + relocation;
|
DrawSpecialBuilding(
|
||||||
DrawSpecialBuilding(image, 0, ti,
|
seq->image + relocation, 0, ti,
|
||||||
seq->delta_x, seq->delta_y, seq->delta_z,
|
seq->delta_x, seq->delta_y, seq->delta_z,
|
||||||
seq->width, seq->height, seq->unk);
|
seq->width, seq->height, seq->unk
|
||||||
|
);
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1112,9 +1112,8 @@ static const StringID _road_tile_strings[] = {
|
||||||
|
|
||||||
static void GetTileDesc_Road(TileIndex tile, TileDesc *td)
|
static void GetTileDesc_Road(TileIndex tile, TileDesc *td)
|
||||||
{
|
{
|
||||||
int i = (_m[tile].m5 >> 4);
|
int i = GB(_m[tile].m5, 4, 4);
|
||||||
if (i == 0)
|
if (i == 0) i = GB(_m[tile].m4, 4, 3) + 3;
|
||||||
i = GB(_m[tile].m4, 4, 3) + 3;
|
|
||||||
td->str = _road_tile_strings[i - 1];
|
td->str = _road_tile_strings[i - 1];
|
||||||
td->owner = GetTileOwner(tile);
|
td->owner = GetTileOwner(tile);
|
||||||
}
|
}
|
||||||
|
|
|
@ -66,13 +66,12 @@ int GetRoadVehImage(const Vehicle *v, byte direction)
|
||||||
|
|
||||||
if (is_custom_sprite(img)) {
|
if (is_custom_sprite(img)) {
|
||||||
image = GetCustomVehicleSprite(v, direction);
|
image = GetCustomVehicleSprite(v, direction);
|
||||||
if (image) return image;
|
if (image != 0) return image;
|
||||||
img = orig_road_vehicle_info[v->engine_type - ROAD_ENGINES_INDEX].image_index;
|
img = orig_road_vehicle_info[v->engine_type - ROAD_ENGINES_INDEX].image_index;
|
||||||
}
|
}
|
||||||
|
|
||||||
image = direction + _roadveh_images[img];
|
image = direction + _roadveh_images[img];
|
||||||
if (v->cargo_count >= (v->cargo_cap >> 1))
|
if (v->cargo_count >= v->cargo_cap / 2) image += _roadveh_full_adder[img];
|
||||||
image += _roadveh_full_adder[img];
|
|
||||||
return image;
|
return image;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -509,12 +508,12 @@ static void RoadVehIsCrashed(Vehicle *v)
|
||||||
|
|
||||||
static void *EnumCheckRoadVehCrashTrain(Vehicle *v, Vehicle *u)
|
static void *EnumCheckRoadVehCrashTrain(Vehicle *v, Vehicle *u)
|
||||||
{
|
{
|
||||||
if (v->type != VEH_Train ||
|
return
|
||||||
myabs(v->z_pos - u->z_pos) > 6 ||
|
v->type == VEH_Train &&
|
||||||
myabs(v->x_pos - u->x_pos) > 4 ||
|
myabs(v->z_pos - u->z_pos) <= 6 &&
|
||||||
myabs(v->y_pos - u->y_pos) > 4)
|
myabs(v->x_pos - u->x_pos) <= 4 &&
|
||||||
return NULL;
|
myabs(v->y_pos - u->y_pos) <= 4 ?
|
||||||
return v;
|
v : NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void RoadVehCrash(Vehicle *v)
|
static void RoadVehCrash(Vehicle *v)
|
||||||
|
@ -527,7 +526,7 @@ static void RoadVehCrash(Vehicle *v)
|
||||||
InvalidateWindowWidget(WC_VEHICLE_VIEW, v->index, STATUS_BAR);
|
InvalidateWindowWidget(WC_VEHICLE_VIEW, v->index, STATUS_BAR);
|
||||||
|
|
||||||
pass = 1;
|
pass = 1;
|
||||||
if (v->cargo_type == 0) pass += v->cargo_count;
|
if (v->cargo_type == CT_PASSENGERS) pass += v->cargo_count;
|
||||||
v->cargo_count = 0;
|
v->cargo_count = 0;
|
||||||
|
|
||||||
SetDParam(0, pass);
|
SetDParam(0, pass);
|
||||||
|
@ -573,13 +572,12 @@ static void HandleBrokenRoadVeh(Vehicle *v)
|
||||||
|
|
||||||
if (!(v->vehstatus & VS_HIDDEN)) {
|
if (!(v->vehstatus & VS_HIDDEN)) {
|
||||||
Vehicle *u = CreateEffectVehicleRel(v, 4, 4, 5, EV_BREAKDOWN_SMOKE);
|
Vehicle *u = CreateEffectVehicleRel(v, 4, 4, 5, EV_BREAKDOWN_SMOKE);
|
||||||
if (u)
|
if (u != NULL) u->u.special.unk0 = v->breakdown_delay * 2;
|
||||||
u->u.special.unk0 = v->breakdown_delay * 2;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!(v->tick_counter & 1)) {
|
if ((v->tick_counter & 1) == 0) {
|
||||||
if (!--v->breakdown_delay) {
|
if (--v->breakdown_delay == 0) {
|
||||||
v->breakdown_ctr = 0;
|
v->breakdown_ctr = 0;
|
||||||
InvalidateWindow(WC_VEHICLE_VIEW, v->index);
|
InvalidateWindow(WC_VEHICLE_VIEW, v->index);
|
||||||
}
|
}
|
||||||
|
@ -1643,7 +1641,7 @@ void OnNewDay_RoadVeh(Vehicle *v)
|
||||||
}
|
}
|
||||||
|
|
||||||
// best_stop now contains the best stop we found.
|
// best_stop now contains the best stop we found.
|
||||||
if (best_stop) {
|
if (best_stop != NULL) {
|
||||||
int slot;
|
int slot;
|
||||||
// Find a free slot in this stop. We know that at least one is free.
|
// Find a free slot in this stop. We know that at least one is free.
|
||||||
assert(best_stop->slot[0] == INVALID_SLOT || best_stop->slot[1] == INVALID_SLOT);
|
assert(best_stop->slot[0] == INVALID_SLOT || best_stop->slot[1] == INVALID_SLOT);
|
||||||
|
@ -1654,7 +1652,7 @@ void OnNewDay_RoadVeh(Vehicle *v)
|
||||||
v->u.road.slot_age = -5;
|
v->u.road.slot_age = -5;
|
||||||
v->u.road.slotindex = slot;
|
v->u.road.slotindex = slot;
|
||||||
DEBUG(ms, 1) ("Multistop: Slot %d at 0x%x assigned to vehicle %d (0x%x)", slot, best_stop->xy, v->unitnumber, v->tile);
|
DEBUG(ms, 1) ("Multistop: Slot %d at 0x%x assigned to vehicle %d (0x%x)", slot, best_stop->xy, v->unitnumber, v->tile);
|
||||||
} else if (first_stop) {
|
} else if (first_stop != NULL) {
|
||||||
//now we couldn't assign a slot for one reason or another.
|
//now we couldn't assign a slot for one reason or another.
|
||||||
//so we just go towards the first station
|
//so we just go towards the first station
|
||||||
DEBUG(ms, 1) ("Multistop: No free slot found for vehicle %d, going to default station", v->unitnumber);
|
DEBUG(ms, 1) ("Multistop: No free slot found for vehicle %d, going to default station", v->unitnumber);
|
||||||
|
|
|
@ -347,12 +347,10 @@ static inline TileType GetEffectiveTileType(TileIndex tile)
|
||||||
if (t == MP_TUNNELBRIDGE) {
|
if (t == MP_TUNNELBRIDGE) {
|
||||||
t = _m[tile].m5;
|
t = _m[tile].m5;
|
||||||
if ((t & 0x80) == 0) t >>= 1;
|
if ((t & 0x80) == 0) t >>= 1;
|
||||||
if ((t & 6) == 0) {
|
switch (t & 0x06) {
|
||||||
t = MP_RAILWAY;
|
case 0x00: t = MP_RAILWAY; break;
|
||||||
} else if ((t & 6) == 2) {
|
case 0x02: t = MP_STREET; break;
|
||||||
t = MP_STREET;
|
default: t = MP_WATER; break;
|
||||||
} else {
|
|
||||||
t = MP_WATER;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return t;
|
return t;
|
||||||
|
@ -642,12 +640,10 @@ static void DrawSmallMap(DrawPixelInfo *dpi, Window *w, int type, bool show_town
|
||||||
y = 0;
|
y = 0;
|
||||||
|
|
||||||
for (;;) {
|
for (;;) {
|
||||||
uint32 mask;
|
uint32 mask = 0xFFFFFFFF;
|
||||||
int reps;
|
int reps;
|
||||||
int t;
|
int t;
|
||||||
|
|
||||||
mask = 0xFFFFFFFF;
|
|
||||||
|
|
||||||
/* distance from left edge */
|
/* distance from left edge */
|
||||||
if (x < 0) {
|
if (x < 0) {
|
||||||
if (x < -3) goto skip_column;
|
if (x < -3) goto skip_column;
|
||||||
|
@ -895,7 +891,7 @@ void ShowSmallMap(void)
|
||||||
int x,y;
|
int x,y;
|
||||||
|
|
||||||
w = AllocateWindowDescFront(&_smallmap_desc, 0);
|
w = AllocateWindowDescFront(&_smallmap_desc, 0);
|
||||||
if (w) {
|
if (w != NULL) {
|
||||||
w->click_state = ((1<<5) << _smallmap_type) | (_smallmap_show_towns << 12);
|
w->click_state = ((1<<5) << _smallmap_type) | (_smallmap_show_towns << 12);
|
||||||
w->resize.width = 350;
|
w->resize.width = 350;
|
||||||
w->resize.height = 250;
|
w->resize.height = 250;
|
||||||
|
@ -993,12 +989,10 @@ void ShowExtraViewPortWindow(void)
|
||||||
int i = 0;
|
int i = 0;
|
||||||
|
|
||||||
// find next free window number for extra viewport
|
// find next free window number for extra viewport
|
||||||
while (FindWindowById(WC_EXTRA_VIEW_PORT, i) ) {
|
while (FindWindowById(WC_EXTRA_VIEW_PORT, i) != NULL) i++;
|
||||||
i++;
|
|
||||||
}
|
|
||||||
|
|
||||||
w = AllocateWindowDescFront(&_extra_view_port_desc, i);
|
w = AllocateWindowDescFront(&_extra_view_port_desc, i);
|
||||||
if (w) {
|
if (w != NULL) {
|
||||||
int x, y;
|
int x, y;
|
||||||
// the main window with the main view
|
// the main window with the main view
|
||||||
v = FindWindowById(WC_MAIN_WINDOW, 0);
|
v = FindWindowById(WC_MAIN_WINDOW, 0);
|
||||||
|
|
2
sound.c
2
sound.c
|
@ -102,7 +102,7 @@ static void OpenBankFile(const char *filename)
|
||||||
|
|
||||||
static bool SetBankSource(MixerChannel *mc, uint bank)
|
static bool SetBankSource(MixerChannel *mc, uint bank)
|
||||||
{
|
{
|
||||||
FileEntry* fe;
|
const FileEntry* fe;
|
||||||
int8* mem;
|
int8* mem;
|
||||||
uint i;
|
uint i;
|
||||||
|
|
||||||
|
|
|
@ -1325,7 +1325,7 @@ int32 CmdBuildRoadStop(int x, int y, uint32 flags, uint32 p1, uint32 p2)
|
||||||
/* Find a station close to us */
|
/* Find a station close to us */
|
||||||
if (st == NULL) {
|
if (st == NULL) {
|
||||||
st = GetClosestStationFromTile(tile, 8, _current_player);
|
st = GetClosestStationFromTile(tile, 8, _current_player);
|
||||||
if (st != NULL && st->facilities) st = NULL;
|
if (st != NULL && st->facilities != 0) st = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
//give us a road stop in the list, and check if something went wrong
|
//give us a road stop in the list, and check if something went wrong
|
||||||
|
@ -1334,7 +1334,8 @@ int32 CmdBuildRoadStop(int x, int y, uint32 flags, uint32 p1, uint32 p2)
|
||||||
return_cmd_error(type ? STR_3008B_TOO_MANY_TRUCK_STOPS : STR_3008A_TOO_MANY_BUS_STOPS);
|
return_cmd_error(type ? STR_3008B_TOO_MANY_TRUCK_STOPS : STR_3008A_TOO_MANY_BUS_STOPS);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (st != NULL && GetNumRoadStops(st, RS_BUS) + GetNumRoadStops(st, RS_TRUCK) >= ROAD_STOP_LIMIT) {
|
if (st != NULL &&
|
||||||
|
GetNumRoadStops(st, RS_BUS) + GetNumRoadStops(st, RS_TRUCK) >= ROAD_STOP_LIMIT) {
|
||||||
return_cmd_error(type ? STR_3008B_TOO_MANY_TRUCK_STOPS : STR_3008A_TOO_MANY_BUS_STOPS);
|
return_cmd_error(type ? STR_3008B_TOO_MANY_TRUCK_STOPS : STR_3008A_TOO_MANY_BUS_STOPS);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2172,19 +2173,18 @@ static const byte _enter_station_speedtable[12] = {
|
||||||
|
|
||||||
static uint32 VehicleEnter_Station(Vehicle *v, TileIndex tile, int x, int y)
|
static uint32 VehicleEnter_Station(Vehicle *v, TileIndex tile, int x, int y)
|
||||||
{
|
{
|
||||||
StationID station_id;
|
|
||||||
byte dir;
|
|
||||||
|
|
||||||
if (v->type == VEH_Train) {
|
if (v->type == VEH_Train) {
|
||||||
if (IS_BYTE_INSIDE(_m[tile].m5, 0, 8) && IsFrontEngine(v) &&
|
if (IS_BYTE_INSIDE(_m[tile].m5, 0, 8) && IsFrontEngine(v) &&
|
||||||
!IsCompatibleTrainStationTile(tile + TileOffsByDir(v->direction >> 1), tile)) {
|
!IsCompatibleTrainStationTile(tile + TileOffsByDir(v->direction >> 1), tile)) {
|
||||||
|
StationID station_id = _m[tile].m2;
|
||||||
|
|
||||||
station_id = _m[tile].m2;
|
|
||||||
if ((!(v->current_order.flags & OF_NON_STOP) && !_patches.new_nonstop) ||
|
if ((!(v->current_order.flags & OF_NON_STOP) && !_patches.new_nonstop) ||
|
||||||
(v->current_order.type == OT_GOTO_STATION && v->current_order.station == station_id)) {
|
(v->current_order.type == OT_GOTO_STATION && v->current_order.station == station_id)) {
|
||||||
if (!(_patches.new_nonstop && v->current_order.flags & OF_NON_STOP) &&
|
if (!(_patches.new_nonstop && v->current_order.flags & OF_NON_STOP) &&
|
||||||
v->current_order.type != OT_LEAVESTATION &&
|
v->current_order.type != OT_LEAVESTATION &&
|
||||||
v->last_station_visited != station_id) {
|
v->last_station_visited != station_id) {
|
||||||
|
byte dir;
|
||||||
|
|
||||||
x &= 0xF;
|
x &= 0xF;
|
||||||
y &= 0xF;
|
y &= 0xF;
|
||||||
|
|
||||||
|
|
|
@ -3,11 +3,11 @@
|
||||||
#ifndef TREE_LAND_H
|
#ifndef TREE_LAND_H
|
||||||
#define TREE_LAND_H
|
#define TREE_LAND_H
|
||||||
|
|
||||||
static const SpriteID _tree_sprites_1[4] = {
|
static const SpriteID _tree_sprites_1[] = {
|
||||||
0x118D,
|
SPR_FLAT_1_QUART_SNOWY_TILE,
|
||||||
0x11A0,
|
SPR_FLAT_2_QUART_SNOWY_TILE,
|
||||||
0x11B3,
|
SPR_FLAT_3_QUART_SNOWY_TILE,
|
||||||
0x11C6,
|
SPR_FLAT_SNOWY_TILE
|
||||||
};
|
};
|
||||||
|
|
||||||
static const byte _tree_base_by_landscape[4] = {0, 12, 20, 32};
|
static const byte _tree_base_by_landscape[4] = {0, 12, 20, 32};
|
||||||
|
|
|
@ -44,9 +44,7 @@ static void TrainCargoChanged(Vehicle* v)
|
||||||
|
|
||||||
for (u = v; u != NULL; u = u->next) {
|
for (u = v; u != NULL; u = u->next) {
|
||||||
const RailVehicleInfo *rvi = RailVehInfo(u->engine_type);
|
const RailVehicleInfo *rvi = RailVehInfo(u->engine_type);
|
||||||
uint16 vweight = 0;
|
uint16 vweight = (_cargoc.weights[u->cargo_type] * u->cargo_count) / 16;
|
||||||
|
|
||||||
vweight += (_cargoc.weights[u->cargo_type] * u->cargo_count) / 16;
|
|
||||||
|
|
||||||
// Vehicle weight is not added for articulated parts.
|
// Vehicle weight is not added for articulated parts.
|
||||||
if (!IsArticulatedPart(u)) {
|
if (!IsArticulatedPart(u)) {
|
||||||
|
|
|
@ -1466,12 +1466,12 @@ static const byte _tunnel_fractcoord_7[4] = {0x52, 0x85, 0x96, 0x49};
|
||||||
|
|
||||||
static uint32 VehicleEnter_TunnelBridge(Vehicle *v, TileIndex tile, int x, int y)
|
static uint32 VehicleEnter_TunnelBridge(Vehicle *v, TileIndex tile, int x, int y)
|
||||||
{
|
{
|
||||||
int z;
|
|
||||||
int dir, vdir;
|
int dir, vdir;
|
||||||
byte fc;
|
|
||||||
|
|
||||||
if (GB(_m[tile].m5, 4, 4) == 0) {
|
if (GB(_m[tile].m5, 4, 4) == 0) {
|
||||||
z = GetSlopeZ(x, y) - v->z_pos;
|
int z = GetSlopeZ(x, y) - v->z_pos;
|
||||||
|
byte fc;
|
||||||
|
|
||||||
if (myabs(z) > 2) return 8;
|
if (myabs(z) > 2) return 8;
|
||||||
|
|
||||||
if (v->type == VEH_Train) {
|
if (v->type == VEH_Train) {
|
||||||
|
|
|
@ -981,18 +981,20 @@ static void ReplaceVehicleWndProc(Window *w, WindowEvent *e)
|
||||||
byte click_side = 1;
|
byte click_side = 1;
|
||||||
|
|
||||||
switch (e->click.widget) {
|
switch (e->click.widget) {
|
||||||
case 12: {
|
case 12:
|
||||||
WP(w, replaceveh_d).wagon_btnstate = !(WP(w, replaceveh_d).wagon_btnstate);
|
WP(w, replaceveh_d).wagon_btnstate = !(WP(w, replaceveh_d).wagon_btnstate);
|
||||||
SetWindowDirty(w);
|
SetWindowDirty(w);
|
||||||
break;
|
break;
|
||||||
}
|
|
||||||
case 14: case 15: { /* Select sorting criteria dropdown menu */
|
case 14:
|
||||||
|
case 15: /* Railtype selection dropdown menu */
|
||||||
ShowDropDownMenu(w, _rail_types_list, _railtype_selected_in_replace_gui, 15, 0, ~GetPlayer(_local_player)->avail_railtypes);
|
ShowDropDownMenu(w, _rail_types_list, _railtype_selected_in_replace_gui, 15, 0, ~GetPlayer(_local_player)->avail_railtypes);
|
||||||
break;
|
break;
|
||||||
}
|
|
||||||
case 17: { /* toggle renew_keep_length */
|
case 17: /* toggle renew_keep_length */
|
||||||
DoCommandP(0, 5, GetPlayer(_local_player)->renew_keep_length ? 0 : 1, NULL, CMD_REPLACE_VEHICLE);
|
DoCommandP(0, 5, GetPlayer(_local_player)->renew_keep_length ? 0 : 1, NULL, CMD_REPLACE_VEHICLE);
|
||||||
} break;
|
break;
|
||||||
|
|
||||||
case 4: { /* Start replacing */
|
case 4: { /* Start replacing */
|
||||||
EngineID veh_from = WP(w, replaceveh_d).sel_engine[0];
|
EngineID veh_from = WP(w, replaceveh_d).sel_engine[0];
|
||||||
EngineID veh_to = WP(w, replaceveh_d).sel_engine[1];
|
EngineID veh_to = WP(w, replaceveh_d).sel_engine[1];
|
||||||
|
@ -1012,29 +1014,32 @@ static void ReplaceVehicleWndProc(Window *w, WindowEvent *e)
|
||||||
click_scroll_pos = w->vscroll.pos;
|
click_scroll_pos = w->vscroll.pos;
|
||||||
click_scroll_cap = w->vscroll.cap;
|
click_scroll_cap = w->vscroll.cap;
|
||||||
click_side = 0;
|
click_side = 0;
|
||||||
|
/* FALL THROUGH */
|
||||||
|
|
||||||
case 9: {
|
case 9: {
|
||||||
uint i = (e->click.pt.y - 14) / w->resize.step_height;
|
uint i = (e->click.pt.y - 14) / w->resize.step_height;
|
||||||
if (i < click_scroll_cap) {
|
if (i < click_scroll_cap) {
|
||||||
WP(w,replaceveh_d).sel_index[click_side] = i + click_scroll_pos;
|
WP(w,replaceveh_d).sel_index[click_side] = i + click_scroll_pos;
|
||||||
SetWindowDirty(w);
|
SetWindowDirty(w);
|
||||||
}
|
}
|
||||||
} break;
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
} break;
|
case WE_DROPDOWN_SELECT: /* we have selected a dropdown item in the list */
|
||||||
|
|
||||||
case WE_DROPDOWN_SELECT: { /* we have selected a dropdown item in the list */
|
|
||||||
_railtype_selected_in_replace_gui = e->dropdown.index;
|
_railtype_selected_in_replace_gui = e->dropdown.index;
|
||||||
SetWindowDirty(w);
|
SetWindowDirty(w);
|
||||||
} break;
|
break;
|
||||||
|
|
||||||
case WE_RESIZE: {
|
case WE_RESIZE:
|
||||||
w->vscroll.cap += e->sizing.diff.y / (int)w->resize.step_height;
|
w->vscroll.cap += e->sizing.diff.y / (int)w->resize.step_height;
|
||||||
w->vscroll2.cap += e->sizing.diff.y / (int)w->resize.step_height;
|
w->vscroll2.cap += e->sizing.diff.y / (int)w->resize.step_height;
|
||||||
|
|
||||||
w->widget[7].unkA = (w->vscroll.cap << 8) + 1;
|
w->widget[7].unkA = (w->vscroll.cap << 8) + 1;
|
||||||
w->widget[9].unkA = (w->vscroll2.cap << 8) + 1;
|
w->widget[9].unkA = (w->vscroll2.cap << 8) + 1;
|
||||||
} break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
31
water_cmd.c
31
water_cmd.c
|
@ -375,20 +375,28 @@ void DrawCanalWater(TileIndex tile)
|
||||||
if (!(wa & 8)) DrawGroundSprite(SPR_CANALS_BASE + 60);
|
if (!(wa & 8)) DrawGroundSprite(SPR_CANALS_BASE + 60);
|
||||||
|
|
||||||
// right corner
|
// right corner
|
||||||
if ((wa & 3) == 0) DrawGroundSprite(SPR_CANALS_BASE + 57 + 4);
|
switch (wa & 0x03) {
|
||||||
else if ((wa & 3) == 3 && !IsWateredTile(TILE_ADDXY(tile, -1, 1))) DrawGroundSprite(SPR_CANALS_BASE + 57 + 8);
|
case 0: DrawGroundSprite(SPR_CANALS_BASE + 57 + 4); break;
|
||||||
|
case 3: if (!IsWateredTile(TILE_ADDXY(tile, -1, 1))) DrawGroundSprite(SPR_CANALS_BASE + 57 + 8); break;
|
||||||
|
}
|
||||||
|
|
||||||
// bottom corner
|
// bottom corner
|
||||||
if ((wa & 6) == 0) DrawGroundSprite(SPR_CANALS_BASE + 57 + 5);
|
switch (wa & 0x06) {
|
||||||
else if ((wa & 6) == 6 && !IsWateredTile(TILE_ADDXY(tile, 1, 1))) DrawGroundSprite(SPR_CANALS_BASE + 57 + 9);
|
case 0: DrawGroundSprite(SPR_CANALS_BASE + 57 + 5); break;
|
||||||
|
case 6: if (!IsWateredTile(TILE_ADDXY(tile, 1, 1))) DrawGroundSprite(SPR_CANALS_BASE + 57 + 9); break;
|
||||||
|
}
|
||||||
|
|
||||||
// left corner
|
// left corner
|
||||||
if ((wa & 12) == 0) DrawGroundSprite(SPR_CANALS_BASE + 57 + 6);
|
switch (wa & 0x0C) {
|
||||||
else if ((wa & 12) == 12 && !IsWateredTile(TILE_ADDXY(tile, 1, -1))) DrawGroundSprite(SPR_CANALS_BASE + 57 + 10);
|
case 0: DrawGroundSprite(SPR_CANALS_BASE + 57 + 6); break;
|
||||||
|
case 12: if (!IsWateredTile(TILE_ADDXY(tile, 1, -1))) DrawGroundSprite(SPR_CANALS_BASE + 57 + 10); break;
|
||||||
|
}
|
||||||
|
|
||||||
// upper corner
|
// upper corner
|
||||||
if ((wa & 9) == 0) DrawGroundSprite(SPR_CANALS_BASE + 57 + 7);
|
switch (wa & 0x09) {
|
||||||
else if ((wa & 9) == 9 && !IsWateredTile(TILE_ADDXY(tile, -1, -1))) DrawGroundSprite(SPR_CANALS_BASE + 57 + 11);
|
case 0: DrawGroundSprite(SPR_CANALS_BASE + 57 + 7); break;
|
||||||
|
case 9: if (!IsWateredTile(TILE_ADDXY(tile, -1, -1))) DrawGroundSprite(SPR_CANALS_BASE + 57 + 11); break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
typedef struct LocksDrawTileStruct {
|
typedef struct LocksDrawTileStruct {
|
||||||
|
@ -403,12 +411,10 @@ static void DrawWaterStuff(const TileInfo *ti, const WaterDrawTileStruct *wdts,
|
||||||
uint32 palette, uint base
|
uint32 palette, uint base
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
uint32 image;
|
|
||||||
|
|
||||||
DrawGroundSprite(wdts++->image);
|
DrawGroundSprite(wdts++->image);
|
||||||
|
|
||||||
for (; wdts->delta_x != 0x80; wdts++) {
|
for (; wdts->delta_x != 0x80; wdts++) {
|
||||||
image = wdts->image + base;
|
uint32 image = wdts->image + base;
|
||||||
if (_display_opt & DO_TRANS_BUILDINGS) {
|
if (_display_opt & DO_TRANS_BUILDINGS) {
|
||||||
MAKE_TRANSPARENT(image);
|
MAKE_TRANSPARENT(image);
|
||||||
} else {
|
} else {
|
||||||
|
@ -624,7 +630,6 @@ static void FloodVehicle(Vehicle *v)
|
||||||
// called from tunnelbridge_cmd
|
// called from tunnelbridge_cmd
|
||||||
void TileLoop_Water(TileIndex tile)
|
void TileLoop_Water(TileIndex tile)
|
||||||
{
|
{
|
||||||
int i;
|
|
||||||
static const TileIndexDiffC _tile_loop_offs_array[][5] = {
|
static const TileIndexDiffC _tile_loop_offs_array[][5] = {
|
||||||
// tile to mod shore? shore?
|
// tile to mod shore? shore?
|
||||||
{{-1, 0}, {0, 0}, {0, 1}, {-1, 0}, {-1, 1}},
|
{{-1, 0}, {0, 0}, {0, 1}, {-1, 0}, {-1, 1}},
|
||||||
|
@ -635,6 +640,8 @@ void TileLoop_Water(TileIndex tile)
|
||||||
|
|
||||||
if (IS_INT_INSIDE(TileX(tile), 1, MapSizeX() - 3 + 1) &&
|
if (IS_INT_INSIDE(TileX(tile), 1, MapSizeX() - 3 + 1) &&
|
||||||
IS_INT_INSIDE(TileY(tile), 1, MapSizeY() - 3 + 1)) {
|
IS_INT_INSIDE(TileY(tile), 1, MapSizeY() - 3 + 1)) {
|
||||||
|
uint i;
|
||||||
|
|
||||||
for (i = 0; i != lengthof(_tile_loop_offs_array); i++) {
|
for (i = 0; i != lengthof(_tile_loop_offs_array); i++) {
|
||||||
TileLoopWaterHelper(tile, _tile_loop_offs_array[i]);
|
TileLoopWaterHelper(tile, _tile_loop_offs_array[i]);
|
||||||
}
|
}
|
||||||
|
|
52
window.c
52
window.c
|
@ -1144,8 +1144,8 @@ static bool HandleScrollbarScrolling(void)
|
||||||
static bool HandleViewportScroll(void)
|
static bool HandleViewportScroll(void)
|
||||||
{
|
{
|
||||||
Window *w;
|
Window *w;
|
||||||
ViewPort *vp;
|
int dx;
|
||||||
int dx,dy, x, y, sub;
|
int dy;
|
||||||
|
|
||||||
if (!_scrolling_viewport) return true;
|
if (!_scrolling_viewport) return true;
|
||||||
|
|
||||||
|
@ -1168,17 +1168,18 @@ stop_capt:;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (w->window_class != WC_SMALLMAP) {
|
if (w->window_class != WC_SMALLMAP) {
|
||||||
vp = IsPtInWindowViewport(w, _cursor.pos.x, _cursor.pos.y);
|
ViewPort* vp = IsPtInWindowViewport(w, _cursor.pos.x, _cursor.pos.y);
|
||||||
|
|
||||||
if (vp == NULL)
|
if (vp == NULL)
|
||||||
goto stop_capt;
|
goto stop_capt;
|
||||||
|
|
||||||
WP(w,vp_d).scrollpos_x += dx << vp->zoom;
|
WP(w,vp_d).scrollpos_x += dx << vp->zoom;
|
||||||
WP(w,vp_d).scrollpos_y += dy << vp->zoom;
|
WP(w,vp_d).scrollpos_y += dy << vp->zoom;
|
||||||
|
|
||||||
_cursor.delta.x = _cursor.delta.y = 0;
|
|
||||||
return false;
|
|
||||||
} else {
|
} else {
|
||||||
// scroll the smallmap ?
|
int x;
|
||||||
|
int y;
|
||||||
|
int sub;
|
||||||
int hx;
|
int hx;
|
||||||
int hy;
|
int hy;
|
||||||
int hvx;
|
int hvx;
|
||||||
|
@ -1233,11 +1234,12 @@ stop_capt:;
|
||||||
WP(w,smallmap_d).scroll_y = y;
|
WP(w,smallmap_d).scroll_y = y;
|
||||||
WP(w,smallmap_d).subscroll = sub;
|
WP(w,smallmap_d).subscroll = sub;
|
||||||
|
|
||||||
_cursor.delta.x = _cursor.delta.y = 0;
|
|
||||||
|
|
||||||
SetWindowDirty(w);
|
SetWindowDirty(w);
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
_cursor.delta.x = 0;
|
||||||
|
_cursor.delta.y = 0;
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
static Window *MaybeBringWindowToFront(Window *w)
|
static Window *MaybeBringWindowToFront(Window *w)
|
||||||
|
@ -1376,7 +1378,7 @@ static void MouseLoop(int click, int mousewheel)
|
||||||
w = FindWindowFromPt(x, y);
|
w = FindWindowFromPt(x, y);
|
||||||
if (w == NULL || w->flags4 & WF_DISABLE_VP_SCROLL) return;
|
if (w == NULL || w->flags4 & WF_DISABLE_VP_SCROLL) return;
|
||||||
vp = IsPtInWindowViewport(w, x, y);
|
vp = IsPtInWindowViewport(w, x, y);
|
||||||
if (vp) {
|
if (vp != NULL) {
|
||||||
x -= vp->left;
|
x -= vp->left;
|
||||||
y -= vp->top;
|
y -= vp->top;
|
||||||
//here allows scrolling in both x and y axis
|
//here allows scrolling in both x and y axis
|
||||||
|
@ -1662,26 +1664,40 @@ void RelocateAllWindows(int neww, int newh)
|
||||||
|
|
||||||
IConsoleResize();
|
IConsoleResize();
|
||||||
|
|
||||||
if (w->window_class == WC_MAIN_TOOLBAR) {
|
switch (w->window_class) {
|
||||||
|
case WC_MAIN_TOOLBAR:
|
||||||
top = w->top;
|
top = w->top;
|
||||||
left = PositionMainToolbar(w); // changes toolbar orientation
|
left = PositionMainToolbar(w); // changes toolbar orientation
|
||||||
} else if (w->window_class == WC_SELECT_GAME || w->window_class == WC_GAME_OPTIONS || w->window_class == WC_NETWORK_WINDOW){
|
break;
|
||||||
|
|
||||||
|
case WC_SELECT_GAME:
|
||||||
|
case WC_GAME_OPTIONS:
|
||||||
|
case WC_NETWORK_WINDOW:
|
||||||
top = (newh - w->height) >> 1;
|
top = (newh - w->height) >> 1;
|
||||||
left = (neww - w->width) >> 1;
|
left = (neww - w->width) >> 1;
|
||||||
} else if (w->window_class == WC_NEWS_WINDOW) {
|
break;
|
||||||
|
|
||||||
|
case WC_NEWS_WINDOW:
|
||||||
top = newh - w->height;
|
top = newh - w->height;
|
||||||
left = (neww - w->width) >> 1;
|
left = (neww - w->width) >> 1;
|
||||||
} else if (w->window_class == WC_STATUS_BAR) {
|
break;
|
||||||
|
|
||||||
|
case WC_STATUS_BAR:
|
||||||
top = newh - w->height;
|
top = newh - w->height;
|
||||||
left = (neww - w->width) >> 1;
|
left = (neww - w->width) >> 1;
|
||||||
} else if (w->window_class == WC_SEND_NETWORK_MSG) {
|
break;
|
||||||
|
|
||||||
|
case WC_SEND_NETWORK_MSG:
|
||||||
top = (newh - 26); // 26 = height of status bar + height of chat bar
|
top = (newh - 26); // 26 = height of status bar + height of chat bar
|
||||||
left = (neww - w->width) >> 1;
|
left = (neww - w->width) >> 1;
|
||||||
} else {
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
left = w->left;
|
left = w->left;
|
||||||
if (left + (w->width>>1) >= neww) left = neww - w->width;
|
if (left + (w->width >> 1) >= neww) left = neww - w->width;
|
||||||
top = w->top;
|
top = w->top;
|
||||||
if (top + (w->height>>1) >= newh) top = newh - w->height;
|
if (top + (w->height >> 1) >= newh) top = newh - w->height;
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (w->viewport != NULL) {
|
if (w->viewport != NULL) {
|
||||||
|
|
Loading…
Reference in New Issue