mirror of https://github.com/OpenTTD/OpenTTD.git
(svn r3510) Fiddle with whitespace and parentheses
This commit is contained in:
parent
8cdd3261fc
commit
22dc05faf2
|
@ -778,7 +778,7 @@ void GenerateClearTile(void)
|
||||||
tile = RandomTileSeed(r);
|
tile = RandomTileSeed(r);
|
||||||
if (IsTileType(tile, MP_CLEAR)) {
|
if (IsTileType(tile, MP_CLEAR)) {
|
||||||
uint j = GB(r, 16, 4) + 5;
|
uint j = GB(r, 16, 4) + 5;
|
||||||
for(;;) {
|
for (;;) {
|
||||||
TileIndex tile_new;
|
TileIndex tile_new;
|
||||||
|
|
||||||
SB(_m[tile].m5, 2, 2, 2);
|
SB(_m[tile].m5, 2, 2, 2);
|
||||||
|
|
|
@ -246,7 +246,6 @@ static void DisasterTick_Zeppeliner(Vehicle *v)
|
||||||
IsTileType(tile, MP_STATION) &&
|
IsTileType(tile, MP_STATION) &&
|
||||||
IS_BYTE_INSIDE(_m[tile].m5, 8, 0x43) &&
|
IS_BYTE_INSIDE(_m[tile].m5, 8, 0x43) &&
|
||||||
IS_HUMAN_PLAYER(GetTileOwner(tile))) {
|
IS_HUMAN_PLAYER(GetTileOwner(tile))) {
|
||||||
|
|
||||||
st = GetStation(_m[tile].m2);
|
st = GetStation(_m[tile].m2);
|
||||||
SETBITS(st->airport_flags, RUNWAY_IN_block);
|
SETBITS(st->airport_flags, RUNWAY_IN_block);
|
||||||
}
|
}
|
||||||
|
@ -905,7 +904,6 @@ static void Disaster7_Init(void)
|
||||||
for (m = 0; m < 15; m++) {
|
for (m = 0; m < 15; m++) {
|
||||||
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);
|
||||||
AddNewsItem(STR_B005_COAL_MINE_SUBSIDENCE_LEAVES,
|
AddNewsItem(STR_B005_COAL_MINE_SUBSIDENCE_LEAVES,
|
||||||
NEWS_FLAGS(NM_THIN,NF_VIEWPORT|NF_TILE,NT_ACCIDENT,0), i->xy + TileDiffXY(1, 1), 0);
|
NEWS_FLAGS(NM_THIN,NF_VIEWPORT|NF_TILE,NT_ACCIDENT,0), i->xy + TileDiffXY(1, 1), 0);
|
||||||
|
|
50
economy.c
50
economy.c
|
@ -337,7 +337,7 @@ void ChangeOwnershipOfPlayerItems(PlayerID old_player, PlayerID new_player)
|
||||||
}
|
}
|
||||||
|
|
||||||
FOR_ALL_VEHICLES(v) {
|
FOR_ALL_VEHICLES(v) {
|
||||||
if (v->owner == old_player && IS_BYTE_INSIDE(v->type, VEH_Train, VEH_Aircraft+1) ) {
|
if (v->owner == old_player && IS_BYTE_INSIDE(v->type, VEH_Train, VEH_Aircraft + 1)) {
|
||||||
if (new_player == OWNER_SPECTATOR) {
|
if (new_player == OWNER_SPECTATOR) {
|
||||||
DeleteWindowById(WC_VEHICLE_VIEW, v->index);
|
DeleteWindowById(WC_VEHICLE_VIEW, v->index);
|
||||||
DeleteWindowById(WC_VEHICLE_DETAILS, v->index);
|
DeleteWindowById(WC_VEHICLE_DETAILS, v->index);
|
||||||
|
@ -1169,26 +1169,25 @@ static bool CheckSubsidised(Station *from, Station *to, byte cargo_type)
|
||||||
Player *p;
|
Player *p;
|
||||||
|
|
||||||
// check if there is an already existing subsidy that applies to us
|
// check if there is an already existing subsidy that applies to us
|
||||||
for(s=_subsidies; s != endof(_subsidies); s++) {
|
for (s = _subsidies; s != endof(_subsidies); s++) {
|
||||||
if (s->cargo_type == cargo_type &&
|
if (s->cargo_type == cargo_type &&
|
||||||
s->age >= 12 &&
|
s->age >= 12 &&
|
||||||
s->from == from->index &&
|
s->from == from->index &&
|
||||||
s->to == to->index)
|
s->to == to->index) {
|
||||||
return true;
|
return true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* check if there's a new subsidy that applies.. */
|
/* check if there's a new subsidy that applies.. */
|
||||||
for(s=_subsidies; s != endof(_subsidies); s++) {
|
for (s = _subsidies; s != endof(_subsidies); s++) {
|
||||||
if (s->cargo_type == cargo_type && s->age < 12) {
|
if (s->cargo_type == cargo_type && s->age < 12) {
|
||||||
|
|
||||||
/* Check distance from source */
|
/* Check distance from source */
|
||||||
if (cargo_type == CT_PASSENGERS || cargo_type == CT_MAIL) {
|
if (cargo_type == CT_PASSENGERS || cargo_type == CT_MAIL) {
|
||||||
xy = GetTown(s->from)->xy;
|
xy = GetTown(s->from)->xy;
|
||||||
} else {
|
} else {
|
||||||
xy = (GetIndustry(s->from))->xy;
|
xy = (GetIndustry(s->from))->xy;
|
||||||
}
|
}
|
||||||
if (DistanceMax(xy, from->xy) > 9)
|
if (DistanceMax(xy, from->xy) > 9) continue;
|
||||||
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) {
|
if (cargo_type == CT_PASSENGERS || cargo_type == CT_MAIL || cargo_type == CT_GOODS || cargo_type == CT_FOOD) {
|
||||||
|
@ -1196,9 +1195,7 @@ static bool CheckSubsidised(Station *from, Station *to, byte cargo_type)
|
||||||
} else {
|
} else {
|
||||||
xy = (GetIndustry(s->to))->xy;
|
xy = (GetIndustry(s->to))->xy;
|
||||||
}
|
}
|
||||||
|
if (DistanceMax(xy, to->xy) > 9) continue;
|
||||||
if (DistanceMax(xy, to->xy) > 9)
|
|
||||||
continue;
|
|
||||||
|
|
||||||
/* Found a subsidy, change the values to indicate that it's in use */
|
/* Found a subsidy, change the values to indicate that it's in use */
|
||||||
s->age = 12;
|
s->age = 12;
|
||||||
|
@ -1215,7 +1212,8 @@ static bool CheckSubsidised(Station *from, Station *to, byte cargo_type)
|
||||||
AddNewsItem(
|
AddNewsItem(
|
||||||
STR_2031_SERVICE_SUBSIDY_AWARDED + _opt.diff.subsidy_multiplier,
|
STR_2031_SERVICE_SUBSIDY_AWARDED + _opt.diff.subsidy_multiplier,
|
||||||
NEWS_FLAGS(NM_NORMAL, NF_TILE, NT_SUBSIDIES, 0),
|
NEWS_FLAGS(NM_NORMAL, NF_TILE, NT_SUBSIDIES, 0),
|
||||||
pair.a, pair.b);
|
pair.a, pair.b
|
||||||
|
);
|
||||||
|
|
||||||
InvalidateWindow(WC_SUBSIDIES_LIST, 0);
|
InvalidateWindow(WC_SUBSIDIES_LIST, 0);
|
||||||
return true;
|
return true;
|
||||||
|
@ -1281,7 +1279,8 @@ static int32 DeliverGoods(int num_pieces, byte cargo_type, uint16 source, uint16
|
||||||
* already loading the same cargo type
|
* already loading the same cargo type
|
||||||
* v = vehicle to load, u = GetFirstInChain(v)
|
* v = vehicle to load, u = GetFirstInChain(v)
|
||||||
*/
|
*/
|
||||||
static bool LoadWait(const Vehicle *v, const Vehicle *u) {
|
static bool LoadWait(const Vehicle* v, const Vehicle* u)
|
||||||
|
{
|
||||||
const Vehicle *w;
|
const Vehicle *w;
|
||||||
const Vehicle *x;
|
const Vehicle *x;
|
||||||
bool has_any_cargo = false;
|
bool has_any_cargo = false;
|
||||||
|
@ -1291,8 +1290,9 @@ static bool LoadWait(const Vehicle *v, const Vehicle *u) {
|
||||||
for (w = u; w != NULL; w = w->next) {
|
for (w = u; w != NULL; w = w->next) {
|
||||||
if (w->cargo_count != 0) {
|
if (w->cargo_count != 0) {
|
||||||
if (v->cargo_type == w->cargo_type &&
|
if (v->cargo_type == w->cargo_type &&
|
||||||
u->last_station_visited == w->cargo_source)
|
u->last_station_visited == w->cargo_source) {
|
||||||
return false;
|
return false;
|
||||||
|
}
|
||||||
has_any_cargo = true;
|
has_any_cargo = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1308,13 +1308,15 @@ static bool LoadWait(const Vehicle *v, const Vehicle *u) {
|
||||||
bool other_has_same_type = false;
|
bool other_has_same_type = false;
|
||||||
|
|
||||||
for (w = x; w != NULL; w = w->next) {
|
for (w = x; w != NULL; w = w->next) {
|
||||||
if (w->cargo_count < w->cargo_cap && v->cargo_type == w->cargo_type)
|
if (w->cargo_count < w->cargo_cap && v->cargo_type == w->cargo_type) {
|
||||||
has_space_for_same_type = true;
|
has_space_for_same_type = true;
|
||||||
|
}
|
||||||
|
|
||||||
if (w->cargo_count != 0) {
|
if (w->cargo_count != 0) {
|
||||||
if (v->cargo_type == w->cargo_type &&
|
if (v->cargo_type == w->cargo_type &&
|
||||||
u->last_station_visited == w->cargo_source)
|
u->last_station_visited == w->cargo_source) {
|
||||||
other_has_same_type = true;
|
other_has_same_type = true;
|
||||||
|
}
|
||||||
other_has_any_cargo = true;
|
other_has_any_cargo = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1375,14 +1377,13 @@ int LoadUnloadVehicle(Vehicle *v)
|
||||||
st->time_since_unload = 0;
|
st->time_since_unload = 0;
|
||||||
|
|
||||||
v_profit = GetTransportedGoodsIncome(
|
v_profit = GetTransportedGoodsIncome(
|
||||||
v->cargo_count,
|
v->cargo_count,
|
||||||
DistanceManhattan(GetStation(v->cargo_source)->xy, GetStation(last_visited)->xy),
|
DistanceManhattan(GetStation(v->cargo_source)->xy, GetStation(last_visited)->xy),
|
||||||
v->cargo_days,
|
v->cargo_days,
|
||||||
v->cargo_type) * 3 / 2;
|
v->cargo_type) * 3 / 2;
|
||||||
|
|
||||||
v_profit_total += v_profit;
|
v_profit_total += v_profit;
|
||||||
|
|
||||||
|
|
||||||
unloading_time += v->cargo_count;
|
unloading_time += v->cargo_count;
|
||||||
t = GB(ge->waiting_acceptance, 0, 12);
|
t = GB(ge->waiting_acceptance, 0, 12);
|
||||||
if (t == 0) {
|
if (t == 0) {
|
||||||
|
@ -1404,8 +1405,7 @@ int LoadUnloadVehicle(Vehicle *v)
|
||||||
v->cargo_count = 0;
|
v->cargo_count = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (v->cargo_count != 0)
|
if (v->cargo_count != 0) completely_empty = false;
|
||||||
completely_empty = false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* don't pick up goods that we unloaded */
|
/* don't pick up goods that we unloaded */
|
||||||
|
@ -1466,8 +1466,9 @@ int LoadUnloadVehicle(Vehicle *v)
|
||||||
|
|
||||||
v = u;
|
v = u;
|
||||||
|
|
||||||
if (v_profit_total > 0)
|
if (v_profit_total > 0) {
|
||||||
ShowFeederIncomeAnimation(v->x_pos, v->y_pos, v->z_pos, v_profit_total);
|
ShowFeederIncomeAnimation(v->x_pos, v->y_pos, v->z_pos, v_profit_total);
|
||||||
|
}
|
||||||
|
|
||||||
if (v->type == VEH_Train) {
|
if (v->type == VEH_Train) {
|
||||||
// Each platform tile is worth 2 rail vehicles.
|
// Each platform tile is worth 2 rail vehicles.
|
||||||
|
@ -1487,8 +1488,7 @@ int LoadUnloadVehicle(Vehicle *v)
|
||||||
if (result != 0) {
|
if (result != 0) {
|
||||||
InvalidateWindow(WC_VEHICLE_DETAILS, v->index);
|
InvalidateWindow(WC_VEHICLE_DETAILS, v->index);
|
||||||
|
|
||||||
if (result & 2)
|
if (result & 2) InvalidateWindow(WC_STATION_VIEW, last_visited);
|
||||||
InvalidateWindow(WC_STATION_VIEW, last_visited);
|
|
||||||
|
|
||||||
if (profit != 0) {
|
if (profit != 0) {
|
||||||
v->profit_this_year += profit;
|
v->profit_this_year += profit;
|
||||||
|
|
5
engine.c
5
engine.c
|
@ -922,13 +922,12 @@ void EnginesDailyLoop(void)
|
||||||
int32 CmdWantEnginePreview(int x, int y, uint32 flags, uint32 p1, uint32 p2)
|
int32 CmdWantEnginePreview(int x, int y, uint32 flags, uint32 p1, uint32 p2)
|
||||||
{
|
{
|
||||||
Engine *e;
|
Engine *e;
|
||||||
if (!IsEngineIndex(p1)) return CMD_ERROR;
|
|
||||||
|
|
||||||
|
if (!IsEngineIndex(p1)) return CMD_ERROR;
|
||||||
e = GetEngine(p1);
|
e = GetEngine(p1);
|
||||||
if (GetBestPlayer(e->preview_player) != _current_player) return CMD_ERROR;
|
if (GetBestPlayer(e->preview_player) != _current_player) return CMD_ERROR;
|
||||||
|
|
||||||
if (flags & DC_EXEC)
|
if (flags & DC_EXEC) AcceptEnginePreview(e, _current_player);
|
||||||
AcceptEnginePreview(e, _current_player);
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
|
@ -26,7 +26,7 @@ extern void DrawArrowButtons(int x, int y, int state);
|
||||||
|
|
||||||
static void BuildIndustryWndProc(Window *w, WindowEvent *e)
|
static void BuildIndustryWndProc(Window *w, WindowEvent *e)
|
||||||
{
|
{
|
||||||
switch(e->event) {
|
switch (e->event) {
|
||||||
case WE_PAINT:
|
case WE_PAINT:
|
||||||
DrawWindowWidgets(w);
|
DrawWindowWidgets(w);
|
||||||
if (_thd.place_mode == 1 && _thd.window_class == WC_BUILD_INDUSTRY) {
|
if (_thd.place_mode == 1 && _thd.window_class == WC_BUILD_INDUSTRY) {
|
||||||
|
@ -278,7 +278,7 @@ static void IndustryViewWndProc(Window *w, WindowEvent *e)
|
||||||
// WP(w,vp2_d).data_2 is for the clickline
|
// WP(w,vp2_d).data_2 is for the clickline
|
||||||
// WP(w,vp2_d).data_3 is for the click pos (left or right)
|
// WP(w,vp2_d).data_3 is for the click pos (left or right)
|
||||||
|
|
||||||
switch(e->event) {
|
switch (e->event) {
|
||||||
case WE_PAINT: {
|
case WE_PAINT: {
|
||||||
const Industry *i;
|
const Industry *i;
|
||||||
StringID str;
|
StringID str;
|
||||||
|
@ -319,8 +319,9 @@ static void IndustryViewWndProc(Window *w, WindowEvent *e)
|
||||||
SetDParam(2, i->pct_transported[1] * 100 >> 8);
|
SetDParam(2, i->pct_transported[1] * 100 >> 8);
|
||||||
DrawString(4 + (NEED_ALTERB ? 30 : 0), 137, STR_482B_TRANSPORTED, 0);
|
DrawString(4 + (NEED_ALTERB ? 30 : 0), 137, STR_482B_TRANSPORTED, 0);
|
||||||
// Let's put out those buttons..
|
// Let's put out those buttons..
|
||||||
if (NEED_ALTERB)
|
if (NEED_ALTERB) {
|
||||||
DrawArrowButtons(5, 137, (WP(w,vp2_d).data_2 == 2 ? WP(w,vp2_d).data_3 : 0));
|
DrawArrowButtons(5, 137, (WP(w,vp2_d).data_2 == 2 ? WP(w,vp2_d).data_3 : 0));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -563,7 +564,7 @@ static void MakeSortedIndustryList(void)
|
||||||
|
|
||||||
static void IndustryDirectoryWndProc(Window *w, WindowEvent *e)
|
static void IndustryDirectoryWndProc(Window *w, WindowEvent *e)
|
||||||
{
|
{
|
||||||
switch(e->event) {
|
switch (e->event) {
|
||||||
case WE_PAINT: {
|
case WE_PAINT: {
|
||||||
int n;
|
int n;
|
||||||
uint p;
|
uint p;
|
||||||
|
@ -604,8 +605,7 @@ static void IndustryDirectoryWndProc(Window *w, WindowEvent *e)
|
||||||
DrawString(4, 28+n*10, STR_INDUSTRYDIR_ITEM_NOPROD, 0);
|
DrawString(4, 28+n*10, STR_INDUSTRYDIR_ITEM_NOPROD, 0);
|
||||||
}
|
}
|
||||||
p++;
|
p++;
|
||||||
if (++n == w->vscroll.cap)
|
if (++n == w->vscroll.cap) break;
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
} break;
|
} break;
|
||||||
|
|
||||||
|
@ -672,7 +672,6 @@ static const WindowDesc _industry_directory_desc = {
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void ShowIndustryDirectory(void)
|
void ShowIndustryDirectory(void)
|
||||||
{
|
{
|
||||||
/* Industry List */
|
/* Industry List */
|
||||||
|
|
12
landscape.c
12
landscape.c
|
@ -175,7 +175,7 @@ uint GetPartialZ(int x, int y, int corners)
|
||||||
return z;
|
return z;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint GetSlopeZ(int x, int y)
|
uint GetSlopeZ(int x, int y)
|
||||||
{
|
{
|
||||||
TileInfo ti;
|
TileInfo ti;
|
||||||
|
|
||||||
|
@ -487,8 +487,7 @@ static void GenerateTerrain(int type, int flag)
|
||||||
y = (r >> MapLogX()) & MapMaxY();
|
y = (r >> MapLogX()) & MapMaxY();
|
||||||
|
|
||||||
|
|
||||||
if (x < 2 || y < 2)
|
if (x < 2 || y < 2) return;
|
||||||
return;
|
|
||||||
|
|
||||||
direction = GB(r, 22, 2);
|
direction = GB(r, 22, 2);
|
||||||
if (direction & 1) {
|
if (direction & 1) {
|
||||||
|
@ -524,11 +523,8 @@ static void GenerateTerrain(int type, int flag)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (x + w >= MapMaxX() - 1)
|
if (x + w >= MapMaxX() - 1) return;
|
||||||
return;
|
if (y + h >= MapMaxY() - 1) return;
|
||||||
|
|
||||||
if (y + h >= MapMaxY() - 1)
|
|
||||||
return;
|
|
||||||
|
|
||||||
tile = &_m[TileXY(x, y)];
|
tile = &_m[TileXY(x, y)];
|
||||||
|
|
||||||
|
|
|
@ -2214,9 +2214,9 @@ static void StatusBarWndProc(Window *w, WindowEvent *e)
|
||||||
if (w->message.msg) { // true when saving is active
|
if (w->message.msg) { // true when saving is active
|
||||||
DrawStringCentered(320, 1, STR_SAVING_GAME, 0);
|
DrawStringCentered(320, 1, STR_SAVING_GAME, 0);
|
||||||
} else if (_do_autosave) {
|
} else if (_do_autosave) {
|
||||||
DrawStringCentered(320, 1, STR_032F_AUTOSAVE, 0);
|
DrawStringCentered(320, 1, STR_032F_AUTOSAVE, 0);
|
||||||
} else if (_pause) {
|
} else if (_pause) {
|
||||||
DrawStringCentered(320, 1, STR_0319_PAUSED, 0);
|
DrawStringCentered(320, 1, STR_0319_PAUSED, 0);
|
||||||
} else if (WP(w,def_d).data_1 > -1280 && FindWindowById(WC_NEWS_WINDOW,0) == NULL && _statusbar_news_item.string_id != 0) {
|
} else if (WP(w,def_d).data_1 > -1280 && FindWindowById(WC_NEWS_WINDOW,0) == NULL && _statusbar_news_item.string_id != 0) {
|
||||||
// Draw the scrolling news text
|
// Draw the scrolling news text
|
||||||
if (!DrawScrollingStatusText(&_statusbar_news_item, WP(w,def_d).data_1))
|
if (!DrawScrollingStatusText(&_statusbar_news_item, WP(w,def_d).data_1))
|
||||||
|
@ -2226,7 +2226,7 @@ static void StatusBarWndProc(Window *w, WindowEvent *e)
|
||||||
// This is the default text
|
// This is the default text
|
||||||
SetDParam(0, p->name_1);
|
SetDParam(0, p->name_1);
|
||||||
SetDParam(1, p->name_2);
|
SetDParam(1, p->name_2);
|
||||||
DrawStringCentered(320, 1, STR_02BA, 0);
|
DrawStringCentered(320, 1, STR_02BA, 0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
34
misc.c
34
misc.c
|
@ -140,7 +140,7 @@ void InitializeGame(int mode, uint size_x, uint size_y)
|
||||||
|
|
||||||
if ((mode & IG_DATE_RESET) == IG_DATE_RESET) {
|
if ((mode & IG_DATE_RESET) == IG_DATE_RESET) {
|
||||||
uint starting = ConvertIntDate(_patches.starting_date);
|
uint starting = ConvertIntDate(_patches.starting_date);
|
||||||
if ( starting == (uint)-1) starting = 10958;
|
if (starting == (uint)-1) starting = 10958;
|
||||||
SetDate(starting);
|
SetDate(starting);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -377,10 +377,11 @@ uint ConvertIntDate(uint date)
|
||||||
day = date % 100; date /= 100;
|
day = date % 100; date /= 100;
|
||||||
month = date % 100 - 1;
|
month = date % 100 - 1;
|
||||||
year = date / 100 - 1920;
|
year = date / 100 - 1920;
|
||||||
} else if (IS_INT_INSIDE(date, 2091, 65536))
|
} else if (IS_INT_INSIDE(date, 2091, 65536)) {
|
||||||
return date;
|
return date;
|
||||||
else
|
} else {
|
||||||
return (uint)-1;
|
return (uint)-1;
|
||||||
|
}
|
||||||
|
|
||||||
// invalid ranges?
|
// invalid ranges?
|
||||||
if (month >= 12 || !IS_INT_INSIDE(day, 1, 31+1)) return (uint)-1;
|
if (month >= 12 || !IS_INT_INSIDE(day, 1, 31+1)) return (uint)-1;
|
||||||
|
@ -419,7 +420,7 @@ void InitializeLandscapeVariables(bool only_constants)
|
||||||
memcpy(_cargoc.ai_roadveh_start, lpd->road_veh_by_cargo_start,sizeof(lpd->road_veh_by_cargo_start));
|
memcpy(_cargoc.ai_roadveh_start, lpd->road_veh_by_cargo_start,sizeof(lpd->road_veh_by_cargo_start));
|
||||||
memcpy(_cargoc.ai_roadveh_count, lpd->road_veh_by_cargo_count,sizeof(lpd->road_veh_by_cargo_count));
|
memcpy(_cargoc.ai_roadveh_count, lpd->road_veh_by_cargo_count,sizeof(lpd->road_veh_by_cargo_count));
|
||||||
|
|
||||||
for(i=0; i!=NUM_CARGO; i++) {
|
for (i = 0; i != NUM_CARGO; i++) {
|
||||||
_cargoc.sprites[i] = lpd->sprites[i];
|
_cargoc.sprites[i] = lpd->sprites[i];
|
||||||
|
|
||||||
str = lpd->names[i];
|
str = lpd->names[i];
|
||||||
|
@ -490,9 +491,9 @@ static void RunVehicleDayProc(uint daytick)
|
||||||
uint i, total = _vehicle_pool.total_items;
|
uint i, total = _vehicle_pool.total_items;
|
||||||
|
|
||||||
for (i = daytick; i < total; i += DAY_TICKS) {
|
for (i = daytick; i < total; i += DAY_TICKS) {
|
||||||
Vehicle *v = GetVehicle(i);
|
Vehicle* v = GetVehicle(i);
|
||||||
if (v->type != 0)
|
|
||||||
_on_new_vehicle_day_proc[v->type - 0x10](v);
|
if (v->type != 0) _on_new_vehicle_day_proc[v->type - 0x10](v);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -511,8 +512,7 @@ void IncreaseDate(void)
|
||||||
_tick_counter++;
|
_tick_counter++;
|
||||||
|
|
||||||
_date_fract++;
|
_date_fract++;
|
||||||
if (_date_fract < DAY_TICKS)
|
if (_date_fract < DAY_TICKS) return;
|
||||||
return;
|
|
||||||
_date_fract = 0;
|
_date_fract = 0;
|
||||||
|
|
||||||
/* yeah, increse day counter and call various daily loops */
|
/* yeah, increse day counter and call various daily loops */
|
||||||
|
@ -547,8 +547,7 @@ void IncreaseDate(void)
|
||||||
IndustryMonthlyLoop();
|
IndustryMonthlyLoop();
|
||||||
StationMonthlyLoop();
|
StationMonthlyLoop();
|
||||||
#ifdef ENABLE_NETWORK
|
#ifdef ENABLE_NETWORK
|
||||||
if (_network_server)
|
if (_network_server) NetworkServerMonthlyLoop();
|
||||||
NetworkServerMonthlyLoop();
|
|
||||||
#endif /* ENABLE_NETWORK */
|
#endif /* ENABLE_NETWORK */
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -565,8 +564,7 @@ void IncreaseDate(void)
|
||||||
AircraftYearlyLoop();
|
AircraftYearlyLoop();
|
||||||
ShipsYearlyLoop();
|
ShipsYearlyLoop();
|
||||||
#ifdef ENABLE_NETWORK
|
#ifdef ENABLE_NETWORK
|
||||||
if (_network_server)
|
if (_network_server) NetworkServerYearlyLoop();
|
||||||
NetworkServerYearlyLoop();
|
|
||||||
#endif /* ENABLE_NETWORK */
|
#endif /* ENABLE_NETWORK */
|
||||||
|
|
||||||
/* check if we reached end of the game (31 dec 2050) */
|
/* check if we reached end of the game (31 dec 2050) */
|
||||||
|
@ -574,7 +572,8 @@ void IncreaseDate(void)
|
||||||
ShowEndGameChart();
|
ShowEndGameChart();
|
||||||
/* check if we reached 2090 (MAX_YEAR_END_REAL), that's the maximum year. */
|
/* check if we reached 2090 (MAX_YEAR_END_REAL), that's the maximum year. */
|
||||||
} else if (_cur_year == (MAX_YEAR_END + 1)) {
|
} else if (_cur_year == (MAX_YEAR_END + 1)) {
|
||||||
Vehicle *v;
|
Vehicle* v;
|
||||||
|
|
||||||
_cur_year = MAX_YEAR_END;
|
_cur_year = MAX_YEAR_END;
|
||||||
_date = 62093;
|
_date = 62093;
|
||||||
FOR_ALL_VEHICLES(v) {
|
FOR_ALL_VEHICLES(v) {
|
||||||
|
@ -586,8 +585,7 @@ void IncreaseDate(void)
|
||||||
InitTextMessage();
|
InitTextMessage();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (_patches.auto_euro)
|
if (_patches.auto_euro) CheckSwitchToEuro();
|
||||||
CheckSwitchToEuro();
|
|
||||||
|
|
||||||
/* XXX: check if year 2050 was reached */
|
/* XXX: check if year 2050 was reached */
|
||||||
}
|
}
|
||||||
|
@ -970,8 +968,8 @@ static void Save_CHTS(void)
|
||||||
Cheat* cht = (Cheat*) &_cheats;
|
Cheat* cht = (Cheat*) &_cheats;
|
||||||
Cheat* cht_last = &cht[count];
|
Cheat* cht_last = &cht[count];
|
||||||
|
|
||||||
SlSetLength(count*2);
|
SlSetLength(count * 2);
|
||||||
for(; cht != cht_last; cht++) {
|
for (; cht != cht_last; cht++) {
|
||||||
SlWriteByte(cht->been_used);
|
SlWriteByte(cht->been_used);
|
||||||
SlWriteByte(cht->value);
|
SlWriteByte(cht->value);
|
||||||
}
|
}
|
||||||
|
|
90
npf.c
90
npf.c
|
@ -47,6 +47,7 @@ static uint NPFDistanceTrack(TileIndex t0, TileIndex t1)
|
||||||
return diagTracks * NPF_TILE_LENGTH + straightTracks * NPF_TILE_LENGTH * STRAIGHT_TRACK_LENGTH;
|
return diagTracks * NPF_TILE_LENGTH + straightTracks * NPF_TILE_LENGTH * STRAIGHT_TRACK_LENGTH;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
#if 0
|
#if 0
|
||||||
static uint NTPHash(uint key1, uint key2)
|
static uint NTPHash(uint key1, uint key2)
|
||||||
{
|
{
|
||||||
|
@ -70,7 +71,7 @@ static uint NPFHash(uint key1, uint key2)
|
||||||
|
|
||||||
assert(IsValidTrackdir(key2));
|
assert(IsValidTrackdir(key2));
|
||||||
assert(IsValidTile(key1));
|
assert(IsValidTile(key1));
|
||||||
return ((((part1 << NPF_HASH_HALFBITS) | part2)) + (NPF_HASH_SIZE * key2 / TRACKDIR_END)) % NPF_HASH_SIZE;
|
return ((part1 << NPF_HASH_HALFBITS | part2) + (NPF_HASH_SIZE * key2 / TRACKDIR_END)) % NPF_HASH_SIZE;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int32 NPFCalcZero(AyStar* as, AyStarNode* current, OpenListNode* parent)
|
static int32 NPFCalcZero(AyStar* as, AyStarNode* current, OpenListNode* parent)
|
||||||
|
@ -116,15 +117,16 @@ static int32 NPFCalcStationOrTileHeuristic(AyStar* as, AyStarNode* current, Open
|
||||||
uint dist;
|
uint dist;
|
||||||
|
|
||||||
// for train-stations, we are going to aim for the closest station tile
|
// for train-stations, we are going to aim for the closest station tile
|
||||||
if ((as->user_data[NPF_TYPE] == TRANSPORT_RAIL) && (fstd->station_index != -1))
|
if (as->user_data[NPF_TYPE] == TRANSPORT_RAIL && fstd->station_index != -1)
|
||||||
to = CalcClosestStationTile(fstd->station_index, from);
|
to = CalcClosestStationTile(fstd->station_index, from);
|
||||||
|
|
||||||
if (as->user_data[NPF_TYPE] == TRANSPORT_ROAD)
|
if (as->user_data[NPF_TYPE] == TRANSPORT_ROAD) {
|
||||||
/* Since roads only have diagonal pieces, we use manhattan distance here */
|
/* Since roads only have diagonal pieces, we use manhattan distance here */
|
||||||
dist = DistanceManhattan(from, to) * NPF_TILE_LENGTH;
|
dist = DistanceManhattan(from, to) * NPF_TILE_LENGTH;
|
||||||
else
|
} else {
|
||||||
/* Ships and trains can also go diagonal, so the minimum distance is shorter */
|
/* Ships and trains can also go diagonal, so the minimum distance is shorter */
|
||||||
dist = NPFDistanceTrack(from, to);
|
dist = NPFDistanceTrack(from, to);
|
||||||
|
}
|
||||||
|
|
||||||
DEBUG(npf, 4)("Calculating H for: (%d, %d). Result: %d", TileX(current->tile), TileY(current->tile), dist);
|
DEBUG(npf, 4)("Calculating H for: (%d, %d). Result: %d", TileX(current->tile), TileY(current->tile), dist);
|
||||||
|
|
||||||
|
@ -135,6 +137,7 @@ static int32 NPFCalcStationOrTileHeuristic(AyStar* as, AyStarNode* current, Open
|
||||||
return dist;
|
return dist;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* Fills AyStarNode.user_data[NPF_TRACKDIRCHOICE] with the chosen direction to
|
/* Fills AyStarNode.user_data[NPF_TRACKDIRCHOICE] with the chosen direction to
|
||||||
* get here, either getting it from the current choice or from the parent's
|
* get here, either getting it from the current choice or from the parent's
|
||||||
* choice */
|
* choice */
|
||||||
|
@ -147,11 +150,9 @@ static void NPFFillTrackdirChoice(AyStarNode* current, OpenListNode* parent)
|
||||||
current->user_data[NPF_TRACKDIR_CHOICE] = trackdir;
|
current->user_data[NPF_TRACKDIR_CHOICE] = trackdir;
|
||||||
DEBUG(npf, 6)("Saving trackdir: %#x", trackdir);
|
DEBUG(npf, 6)("Saving trackdir: %#x", trackdir);
|
||||||
} else {
|
} else {
|
||||||
/* We've already made the decision, so just save our parent's
|
/* We've already made the decision, so just save our parent's decision */
|
||||||
* decision */
|
|
||||||
current->user_data[NPF_TRACKDIR_CHOICE] = parent->path.node.user_data[NPF_TRACKDIR_CHOICE];
|
current->user_data[NPF_TRACKDIR_CHOICE] = parent->path.node.user_data[NPF_TRACKDIR_CHOICE];
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Will return the cost of the tunnel. If it is an entry, it will return the
|
/* Will return the cost of the tunnel. If it is an entry, it will return the
|
||||||
|
@ -191,7 +192,7 @@ static uint NPFSlopeCost(AyStarNode* current)
|
||||||
/* get the height of the center of the next tile */
|
/* get the height of the center of the next tile */
|
||||||
z2 = GetSlopeZ(x+TILE_HEIGHT, y+TILE_HEIGHT);
|
z2 = GetSlopeZ(x+TILE_HEIGHT, y+TILE_HEIGHT);
|
||||||
|
|
||||||
if ((z2 - z1) > 1) {
|
if (z2 - z1 > 1) {
|
||||||
/* Slope up */
|
/* Slope up */
|
||||||
return _patches.npf_rail_slope_penalty;
|
return _patches.npf_rail_slope_penalty;
|
||||||
}
|
}
|
||||||
|
@ -263,12 +264,14 @@ static int32 NPFRoadPathCost(AyStar* as, AyStarNode* current, OpenListNode* pare
|
||||||
}
|
}
|
||||||
cost = NPF_TILE_LENGTH;
|
cost = NPF_TILE_LENGTH;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case MP_STREET:
|
case MP_STREET:
|
||||||
cost = NPF_TILE_LENGTH;
|
cost = NPF_TILE_LENGTH;
|
||||||
/* Increase the cost for level crossings */
|
/* Increase the cost for level crossings */
|
||||||
if (IsLevelCrossing(tile))
|
if (IsLevelCrossing(tile))
|
||||||
cost += _patches.npf_crossing_penalty;
|
cost += _patches.npf_crossing_penalty;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -307,22 +310,25 @@ static int32 NPFRailPathCost(AyStar* as, AyStarNode* current, OpenListNode* pare
|
||||||
}
|
}
|
||||||
/* Fall through if above if is false, it is a bridge
|
/* Fall through if above if is false, it is a bridge
|
||||||
* then. We treat that as ordinary rail */
|
* then. We treat that as ordinary rail */
|
||||||
|
|
||||||
case MP_RAILWAY:
|
case MP_RAILWAY:
|
||||||
cost = _trackdir_length[trackdir]; /* Should be different for diagonal tracks */
|
cost = _trackdir_length[trackdir]; /* Should be different for diagonal tracks */
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case MP_STREET: /* Railway crossing */
|
case MP_STREET: /* Railway crossing */
|
||||||
cost = NPF_TILE_LENGTH;
|
cost = NPF_TILE_LENGTH;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case MP_STATION:
|
case MP_STATION:
|
||||||
/* We give a station tile a penalty. Logically we would only
|
/* We give a station tile a penalty. Logically we would only want to give
|
||||||
* want to give station tiles that are not our destination
|
* station tiles that are not our destination this penalty. This would
|
||||||
* this penalty. This would discourage trains to drive through
|
* discourage trains to drive through busy stations. But, we can just
|
||||||
* busy stations. But, we can just give any station tile a
|
* give any station tile a penalty, because every possible route will get
|
||||||
* penalty, because every possible route will get this penalty
|
* this penalty exactly once, on its end tile (if it's a station) and it
|
||||||
* exactly once, on its end tile (if it's a station) and it
|
* will therefore not make a difference. */
|
||||||
* will therefore not make a difference. */
|
|
||||||
cost = NPF_TILE_LENGTH + _patches.npf_rail_station_penalty;
|
cost = NPF_TILE_LENGTH + _patches.npf_rail_station_penalty;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -340,11 +346,12 @@ static int32 NPFRailPathCost(AyStar* as, AyStarNode* current, OpenListNode* pare
|
||||||
|
|
||||||
/* Is this a presignal exit or combo? */
|
/* Is this a presignal exit or combo? */
|
||||||
SignalType sigtype = GetSignalType(tile, TrackdirToTrack(trackdir));
|
SignalType sigtype = GetSignalType(tile, TrackdirToTrack(trackdir));
|
||||||
if (sigtype == SIGTYPE_EXIT || sigtype == SIGTYPE_COMBO)
|
if (sigtype == SIGTYPE_EXIT || sigtype == SIGTYPE_COMBO) {
|
||||||
/* Penalise exit and combo signals differently (heavier) */
|
/* Penalise exit and combo signals differently (heavier) */
|
||||||
cost += _patches.npf_rail_firstred_exit_penalty;
|
cost += _patches.npf_rail_firstred_exit_penalty;
|
||||||
else
|
} else {
|
||||||
cost += _patches.npf_rail_firstred_penalty;
|
cost += _patches.npf_rail_firstred_penalty;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
/* Record the state of this signal */
|
/* Record the state of this signal */
|
||||||
NPFSetFlag(current, NPF_FLAG_LAST_SIGNAL_RED, true);
|
NPFSetFlag(current, NPF_FLAG_LAST_SIGNAL_RED, true);
|
||||||
|
@ -372,14 +379,12 @@ static int32 NPFRailPathCost(AyStar* as, AyStarNode* current, OpenListNode* pare
|
||||||
//TODO, with realistic acceleration, also the amount of straight track between
|
//TODO, with realistic acceleration, also the amount of straight track between
|
||||||
// curves should be taken into account, as this affects the speed limit.
|
// curves should be taken into account, as this affects the speed limit.
|
||||||
|
|
||||||
|
|
||||||
/* Check for reverse in depot */
|
/* Check for reverse in depot */
|
||||||
if (IsTileDepotType(tile, TRANSPORT_RAIL) && as->EndNodeCheck(as, &new_node) != AYSTAR_FOUND_END_NODE) {
|
if (IsTileDepotType(tile, TRANSPORT_RAIL) && as->EndNodeCheck(as, &new_node) != AYSTAR_FOUND_END_NODE) {
|
||||||
/* Penalise any depot tile that is not the last tile in the path. This
|
/* Penalise any depot tile that is not the last tile in the path. This
|
||||||
* _should_ penalise every occurence of reversing in a depot (and only
|
* _should_ penalise every occurence of reversing in a depot (and only
|
||||||
* that) */
|
* that) */
|
||||||
cost += _patches.npf_rail_depot_reverse_penalty;
|
cost += _patches.npf_rail_depot_reverse_penalty;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Check for occupied track */
|
/* Check for occupied track */
|
||||||
|
@ -397,10 +402,11 @@ static int32 NPFFindDepot(AyStar* as, OpenListNode *current)
|
||||||
|
|
||||||
/* It's not worth caching the result with NPF_FLAG_IS_TARGET here as below,
|
/* It's not worth caching the result with NPF_FLAG_IS_TARGET here as below,
|
||||||
* since checking the cache not that much faster than the actual check */
|
* since checking the cache not that much faster than the actual check */
|
||||||
if (IsTileDepotType(tile, as->user_data[NPF_TYPE]))
|
if (IsTileDepotType(tile, as->user_data[NPF_TYPE])) {
|
||||||
return AYSTAR_FOUND_END_NODE;
|
return AYSTAR_FOUND_END_NODE;
|
||||||
else
|
} else {
|
||||||
return AYSTAR_DONE;
|
return AYSTAR_DONE;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Will find a station identified using the NPFFindStationOrTileData */
|
/* Will find a station identified using the NPFFindStationOrTileData */
|
||||||
|
@ -446,14 +452,13 @@ static void NPFSaveTargetData(AyStar* as, OpenListNode* current)
|
||||||
*/
|
*/
|
||||||
static bool VehicleMayEnterTile(Owner owner, TileIndex tile, DiagDirection enterdir)
|
static bool VehicleMayEnterTile(Owner owner, TileIndex tile, DiagDirection enterdir)
|
||||||
{
|
{
|
||||||
if (
|
if (IsTileType(tile, MP_RAILWAY) || /* Rail tile (also rail depot) */
|
||||||
IsTileType(tile, MP_RAILWAY) /* Rail tile (also rail depot) */
|
IsTrainStationTile(tile) || /* Rail station tile */
|
||||||
|| IsTrainStationTile(tile) /* Rail station tile */
|
IsTileDepotType(tile, TRANSPORT_ROAD) || /* Road depot tile */
|
||||||
|| IsTileDepotType(tile, TRANSPORT_ROAD) /* Road depot tile */
|
IsRoadStationTile(tile) || /* Road station tile */
|
||||||
|| IsRoadStationTile(tile) /* Road station tile */
|
IsTileDepotType(tile, TRANSPORT_WATER)) { /* Water depot tile */
|
||||||
|| IsTileDepotType(tile, TRANSPORT_WATER) /* Water depot tile */
|
|
||||||
)
|
|
||||||
return IsTileOwner(tile, owner); /* You need to own these tiles entirely to use them */
|
return IsTileOwner(tile, owner); /* You need to own these tiles entirely to use them */
|
||||||
|
}
|
||||||
|
|
||||||
switch (GetTileType(tile)) {
|
switch (GetTileType(tile)) {
|
||||||
case MP_STREET:
|
case MP_STREET:
|
||||||
|
@ -461,6 +466,7 @@ static bool VehicleMayEnterTile(Owner owner, TileIndex tile, DiagDirection enter
|
||||||
if (IsLevelCrossing(tile) && GetCrossingTransportType(tile, TrackdirToTrack(DiagdirToDiagTrackdir(enterdir))) == TRANSPORT_RAIL)
|
if (IsLevelCrossing(tile) && GetCrossingTransportType(tile, TrackdirToTrack(DiagdirToDiagTrackdir(enterdir))) == TRANSPORT_RAIL)
|
||||||
return IsTileOwner(tile, owner); /* Railway needs owner check, while the street is public */
|
return IsTileOwner(tile, owner); /* Railway needs owner check, while the street is public */
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case MP_TUNNELBRIDGE:
|
case MP_TUNNELBRIDGE:
|
||||||
#if 0
|
#if 0
|
||||||
/* OPTIMISATION: If we are on the middle of a bridge, we will not do the cpu
|
/* OPTIMISATION: If we are on the middle of a bridge, we will not do the cpu
|
||||||
|
@ -475,13 +481,13 @@ static bool VehicleMayEnterTile(Owner owner, TileIndex tile, DiagDirection enter
|
||||||
}
|
}
|
||||||
/* if we were on a railway middle part, we are now at a railway bridge ending */
|
/* if we were on a railway middle part, we are now at a railway bridge ending */
|
||||||
#endif
|
#endif
|
||||||
if (
|
if ((_m[tile].m5 & 0xFC) == 0 || /* railway tunnel */
|
||||||
(_m[tile].m5 & 0xFC) == 0 /* railway tunnel */
|
(_m[tile].m5 & 0xC6) == 0x80 || /* railway bridge ending */
|
||||||
|| (_m[tile].m5 & 0xC6) == 0x80 /* railway bridge ending */
|
((_m[tile].m5 & 0xF8) == 0xE0 && GB(_m[tile].m5, 0, 1) != (enterdir & 0x1))) { /* railway under bridge */
|
||||||
|| ((_m[tile].m5 & 0xF8) == 0xE0 && GB(_m[tile].m5, 0, 1) != (enterdir & 0x1)) /* railway under bridge */
|
|
||||||
)
|
|
||||||
return IsTileOwner(tile, owner);
|
return IsTileOwner(tile, owner);
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -510,7 +516,8 @@ static void NPFFollowTrack(AyStar* aystar, OpenListNode* current)
|
||||||
DEBUG(npf, 4)("Expanding: (%d, %d, %d) [%d]", TileX(src_tile), TileY(src_tile), src_trackdir, src_tile);
|
DEBUG(npf, 4)("Expanding: (%d, %d, %d) [%d]", TileX(src_tile), TileY(src_tile), src_trackdir, src_tile);
|
||||||
|
|
||||||
/* Find dest tile */
|
/* Find dest tile */
|
||||||
if (IsTileType(src_tile, MP_TUNNELBRIDGE) && GB(_m[src_tile].m5, 4, 4) == 0 &&
|
if (IsTileType(src_tile, MP_TUNNELBRIDGE) &&
|
||||||
|
GB(_m[src_tile].m5, 4, 4) == 0 &&
|
||||||
(DiagDirection)GB(_m[src_tile].m5, 0, 2) == src_exitdir) {
|
(DiagDirection)GB(_m[src_tile].m5, 0, 2) == src_exitdir) {
|
||||||
/* This is a tunnel. We know this tunnel is our type,
|
/* This is a tunnel. We know this tunnel is our type,
|
||||||
* otherwise we wouldn't have got here. It is also facing us,
|
* otherwise we wouldn't have got here. It is also facing us,
|
||||||
|
@ -525,16 +532,17 @@ static void NPFFollowTrack(AyStar* aystar, OpenListNode* current)
|
||||||
|
|
||||||
DiagDirection exitdir;
|
DiagDirection exitdir;
|
||||||
/* Find out the exit direction first */
|
/* Find out the exit direction first */
|
||||||
if (IsRoadStationTile(src_tile))
|
if (IsRoadStationTile(src_tile)) {
|
||||||
exitdir = GetRoadStationDir(src_tile);
|
exitdir = GetRoadStationDir(src_tile);
|
||||||
else /* Train or road depot. Direction is stored the same for both, in map5 */
|
} else { /* Train or road depot. Direction is stored the same for both, in map5 */
|
||||||
exitdir = GetDepotDirection(src_tile, type);
|
exitdir = GetDepotDirection(src_tile, type);
|
||||||
|
}
|
||||||
|
|
||||||
/* Let's see if were headed the right way into the depot, and reverse
|
/* Let's see if were headed the right way into the depot, and reverse
|
||||||
* otherwise (only for trains, since only with trains you can
|
* otherwise (only for trains, since only with trains you can
|
||||||
* (sometimes) reach tiles after reversing that you couldn't reach
|
* (sometimes) reach tiles after reversing that you couldn't reach
|
||||||
* without reversing. */
|
* without reversing. */
|
||||||
if (src_trackdir == DiagdirToDiagTrackdir(ReverseDiagdir(exitdir)) && type == TRANSPORT_RAIL)
|
if (src_trackdir == DiagdirToDiagTrackdir(ReverseDiagdir(exitdir)) && type == TRANSPORT_RAIL) {
|
||||||
/* We are headed inwards. We can only reverse here, so we'll not
|
/* We are headed inwards. We can only reverse here, so we'll not
|
||||||
* consider this direction, but jump ahead to the reverse direction.
|
* consider this direction, but jump ahead to the reverse direction.
|
||||||
* It would be nicer to return one neighbour here (the reverse
|
* It would be nicer to return one neighbour here (the reverse
|
||||||
|
@ -543,6 +551,7 @@ static void NPFFollowTrack(AyStar* aystar, OpenListNode* current)
|
||||||
* the code layout is cleaner this way, we will just pretend we are
|
* the code layout is cleaner this way, we will just pretend we are
|
||||||
* reversed already */
|
* reversed already */
|
||||||
src_trackdir = ReverseTrackdir(src_trackdir);
|
src_trackdir = ReverseTrackdir(src_trackdir);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
/* This a normal tile, a bridge, a tunnel exit, etc. */
|
/* This a normal tile, a bridge, a tunnel exit, etc. */
|
||||||
dst_tile = AddTileIndexDiffCWrap(src_tile, TileIndexDiffCByDir(TrackdirToExitdir(src_trackdir)));
|
dst_tile = AddTileIndexDiffCWrap(src_tile, TileIndexDiffCByDir(TrackdirToExitdir(src_trackdir)));
|
||||||
|
@ -577,10 +586,11 @@ static void NPFFollowTrack(AyStar* aystar, OpenListNode* current)
|
||||||
if (type != TRANSPORT_WATER && (IsRoadStationTile(dst_tile) || IsTileDepotType(dst_tile, type))){
|
if (type != TRANSPORT_WATER && (IsRoadStationTile(dst_tile) || IsTileDepotType(dst_tile, type))){
|
||||||
/* Road stations and road and train depots return 0 on GTTS, so we have to do this by hand... */
|
/* Road stations and road and train depots return 0 on GTTS, so we have to do this by hand... */
|
||||||
DiagDirection exitdir;
|
DiagDirection exitdir;
|
||||||
if (IsRoadStationTile(dst_tile))
|
if (IsRoadStationTile(dst_tile)) {
|
||||||
exitdir = GetRoadStationDir(dst_tile);
|
exitdir = GetRoadStationDir(dst_tile);
|
||||||
else /* Road or train depot */
|
} else { /* Road or train depot */
|
||||||
exitdir = GetDepotDirection(dst_tile, type);
|
exitdir = GetDepotDirection(dst_tile, type);
|
||||||
|
}
|
||||||
/* Find the trackdirs that are available for a depot or station with this
|
/* Find the trackdirs that are available for a depot or station with this
|
||||||
* orientation. They are only "inwards", since we are reaching this tile
|
* orientation. They are only "inwards", since we are reaching this tile
|
||||||
* from some other tile. This prevents vehicles driving into depots from
|
* from some other tile. This prevents vehicles driving into depots from
|
||||||
|
@ -862,7 +872,7 @@ void NPFFillWithOrderData(NPFFindStationOrTileData* fstd, Vehicle* v)
|
||||||
* dest_tile, not just any stop of that station.
|
* dest_tile, not just any stop of that station.
|
||||||
* So only for train orders to stations we fill fstd->station_index, for all
|
* So only for train orders to stations we fill fstd->station_index, for all
|
||||||
* others only dest_coords */
|
* others only dest_coords */
|
||||||
if ((v->current_order.type) == OT_GOTO_STATION && v->type == VEH_Train) {
|
if (v->current_order.type == OT_GOTO_STATION && v->type == VEH_Train) {
|
||||||
fstd->station_index = v->current_order.station;
|
fstd->station_index = v->current_order.station;
|
||||||
/* Let's take the closest tile of the station as our target for trains */
|
/* Let's take the closest tile of the station as our target for trains */
|
||||||
fstd->dest_coords = CalcClosestStationTile(v->current_order.station, v->tile);
|
fstd->dest_coords = CalcClosestStationTile(v->current_order.station, v->tile);
|
||||||
|
|
1
npf.h
1
npf.h
|
@ -64,6 +64,7 @@ typedef struct NPFFoundTargetData { /* Meant to be stored in AyStar.userpath */
|
||||||
* station for the given transport type. See the declaration of
|
* station for the given transport type. See the declaration of
|
||||||
* NPFFoundTargetData above for the meaning of the result. */
|
* NPFFoundTargetData above for the meaning of the result. */
|
||||||
NPFFoundTargetData NPFRouteToStationOrTile(TileIndex tile, Trackdir trackdir, NPFFindStationOrTileData* target, TransportType type, Owner owner, RailType railtype);
|
NPFFoundTargetData NPFRouteToStationOrTile(TileIndex tile, Trackdir trackdir, NPFFindStationOrTileData* target, TransportType type, Owner owner, RailType railtype);
|
||||||
|
|
||||||
/* Will search as above, but with two start nodes, the second being the
|
/* Will search as above, but with two start nodes, the second being the
|
||||||
* reverse. Look at the NPF_FLAG_REVERSE flag in the result node to see which
|
* reverse. Look at the NPF_FLAG_REVERSE flag in the result node to see which
|
||||||
* direction was taken (NPFGetBit(result.node, NPF_FLAG_REVERSE)) */
|
* direction was taken (NPFGetBit(result.node, NPF_FLAG_REVERSE)) */
|
||||||
|
|
50
oldloader.c
50
oldloader.c
|
@ -178,16 +178,15 @@ static bool LoadChunk(LoadgameState *ls, void *base, const OldChunks *chunks)
|
||||||
|
|
||||||
case OC_CHUNK:
|
case OC_CHUNK:
|
||||||
/* Call function, with 'i' as parameter to tell which item we
|
/* Call function, with 'i' as parameter to tell which item we
|
||||||
are going to read */
|
* are going to read */
|
||||||
if (!chunk->proc(ls, i))
|
if (!chunk->proc(ls, i)) return false;
|
||||||
return false;
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case OC_ASSERT:
|
case OC_ASSERT:
|
||||||
DEBUG(oldloader, 4)("[OldLoader] Assert point: %x / %x", ls->total_read, chunk->offset + _bump_assert_value);
|
DEBUG(oldloader, 4)("[OldLoader] Assert point: %x / %x", ls->total_read, chunk->offset + _bump_assert_value);
|
||||||
if (ls->total_read != chunk->offset + _bump_assert_value)
|
if (ls->total_read != chunk->offset + _bump_assert_value) {
|
||||||
ls->failed = true;
|
ls->failed = true;
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -345,8 +344,7 @@ static void FixOldTowns(void)
|
||||||
|
|
||||||
/* Convert town-names if needed */
|
/* Convert town-names if needed */
|
||||||
FOR_ALL_TOWNS(town) {
|
FOR_ALL_TOWNS(town) {
|
||||||
if (town->xy == 0)
|
if (town->xy == 0) continue;
|
||||||
continue;
|
|
||||||
|
|
||||||
if (IS_INT_INSIDE(town->townnametype, 0x20C1, 0x20C3)) {
|
if (IS_INT_INSIDE(town->townnametype, 0x20C1, 0x20C3)) {
|
||||||
town->townnametype = SPECSTR_TOWNNAME_ENGLISH + _opt.town_name;
|
town->townnametype = SPECSTR_TOWNNAME_ENGLISH + _opt.town_name;
|
||||||
|
@ -393,26 +391,22 @@ static void FixOldStations(void)
|
||||||
static void FixOldVehicles(void)
|
static void FixOldVehicles(void)
|
||||||
{
|
{
|
||||||
/* Check for shared orders, and link them correctly */
|
/* Check for shared orders, and link them correctly */
|
||||||
{
|
Vehicle* v;
|
||||||
Vehicle *v;
|
|
||||||
|
|
||||||
FOR_ALL_VEHICLES(v) {
|
FOR_ALL_VEHICLES(v) {
|
||||||
Vehicle *u;
|
Vehicle* u;
|
||||||
|
|
||||||
if (v->type == 0)
|
if (v->type == 0) continue;
|
||||||
continue;
|
|
||||||
|
|
||||||
FOR_ALL_VEHICLES_FROM(u, v->index + 1) {
|
FOR_ALL_VEHICLES_FROM(u, v->index + 1) {
|
||||||
if (u->type == 0)
|
if (u->type == 0) continue;
|
||||||
continue;
|
|
||||||
|
|
||||||
/* If a vehicle has the same orders, add the link to eachother
|
/* If a vehicle has the same orders, add the link to eachother
|
||||||
in both vehicles */
|
* in both vehicles */
|
||||||
if (v->orders == u->orders) {
|
if (v->orders == u->orders) {
|
||||||
v->next_shared = u;
|
v->next_shared = u;
|
||||||
u->prev_shared = v;
|
u->prev_shared = v;
|
||||||
break;
|
break;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -461,8 +455,7 @@ static void ReadTTDPatchFlags(void)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
if (_read_ttdpatch_flags)
|
if (_read_ttdpatch_flags) return;
|
||||||
return;
|
|
||||||
|
|
||||||
_read_ttdpatch_flags = true;
|
_read_ttdpatch_flags = true;
|
||||||
|
|
||||||
|
@ -470,8 +463,7 @@ static void ReadTTDPatchFlags(void)
|
||||||
_old_vehicle_multipler = _old_map3[0];
|
_old_vehicle_multipler = _old_map3[0];
|
||||||
/* Somehow.... there was an error in some savegames, so 0 becomes 1
|
/* Somehow.... there was an error in some savegames, so 0 becomes 1
|
||||||
and 1 becomes 2. The rest of the values are okay */
|
and 1 becomes 2. The rest of the values are okay */
|
||||||
if (_old_vehicle_multipler < 2)
|
if (_old_vehicle_multipler < 2) _old_vehicle_multipler++;
|
||||||
_old_vehicle_multipler++;
|
|
||||||
|
|
||||||
/* TTDPatch incraeses the Vehicle-part in the middle of the game,
|
/* TTDPatch incraeses the Vehicle-part in the middle of the game,
|
||||||
so if the multipler is anything else but 1, the assert fails..
|
so if the multipler is anything else but 1, the assert fails..
|
||||||
|
@ -1025,6 +1017,7 @@ static const OldChunks player_chunk[] = {
|
||||||
|
|
||||||
OCL_END()
|
OCL_END()
|
||||||
};
|
};
|
||||||
|
|
||||||
static bool LoadOldPlayer(LoadgameState *ls, int num)
|
static bool LoadOldPlayer(LoadgameState *ls, int num)
|
||||||
{
|
{
|
||||||
Player *p = GetPlayer(num);
|
Player *p = GetPlayer(num);
|
||||||
|
@ -1340,8 +1333,7 @@ static const OldChunks engine_chunk[] = {
|
||||||
};
|
};
|
||||||
static bool LoadOldEngine(LoadgameState *ls, int num)
|
static bool LoadOldEngine(LoadgameState *ls, int num)
|
||||||
{
|
{
|
||||||
if (!LoadChunk(ls, GetEngine(num), engine_chunk))
|
if (!LoadChunk(ls, GetEngine(num), engine_chunk)) return false;
|
||||||
return false;
|
|
||||||
|
|
||||||
/* Make sure wagons are marked as do-not-age */
|
/* Make sure wagons are marked as do-not-age */
|
||||||
if ((num >= 27 && num < 54) || (num >= 57 && num < 84) || (num >= 89 && num < 116))
|
if ((num >= 27 && num < 54) || (num >= 57 && num < 84) || (num >= 89 && num < 116))
|
||||||
|
|
33
openttd.c
33
openttd.c
|
@ -335,7 +335,7 @@ int ttd_main(int argc, char* argv[])
|
||||||
|
|
||||||
MyGetOptInit(&mgo, argc-1, argv+1, optformat);
|
MyGetOptInit(&mgo, argc-1, argv+1, optformat);
|
||||||
while ((i = MyGetOpt(&mgo)) != -1) {
|
while ((i = MyGetOpt(&mgo)) != -1) {
|
||||||
switch(i) {
|
switch (i) {
|
||||||
case 'm': ttd_strlcpy(musicdriver, mgo.opt, sizeof(musicdriver)); break;
|
case 'm': ttd_strlcpy(musicdriver, mgo.opt, sizeof(musicdriver)); break;
|
||||||
case 's': ttd_strlcpy(sounddriver, mgo.opt, sizeof(sounddriver)); break;
|
case 's': ttd_strlcpy(sounddriver, mgo.opt, sizeof(sounddriver)); break;
|
||||||
case 'v': ttd_strlcpy(videodriver, mgo.opt, sizeof(videodriver)); break;
|
case 'v': ttd_strlcpy(videodriver, mgo.opt, sizeof(videodriver)); break;
|
||||||
|
@ -412,8 +412,7 @@ int ttd_main(int argc, char* argv[])
|
||||||
if (resolution[0]) { _cur_resolution[0] = resolution[0]; _cur_resolution[1] = resolution[1]; }
|
if (resolution[0]) { _cur_resolution[0] = resolution[0]; _cur_resolution[1] = resolution[1]; }
|
||||||
if (startdate != (uint)-1) _patches.starting_date = startdate;
|
if (startdate != (uint)-1) _patches.starting_date = startdate;
|
||||||
|
|
||||||
if (_dedicated_forks && !dedicated)
|
if (_dedicated_forks && !dedicated) _dedicated_forks = false;
|
||||||
_dedicated_forks = false;
|
|
||||||
|
|
||||||
// enumerate language files
|
// enumerate language files
|
||||||
InitializeLanguagePacks();
|
InitializeLanguagePacks();
|
||||||
|
@ -455,8 +454,7 @@ int ttd_main(int argc, char* argv[])
|
||||||
_opt_ptr = &_opt_newgame;
|
_opt_ptr = &_opt_newgame;
|
||||||
|
|
||||||
/* XXX - ugly hack, if diff_level is 9, it means we got no setting from the config file */
|
/* XXX - ugly hack, if diff_level is 9, it means we got no setting from the config file */
|
||||||
if (_opt_newgame.diff_level == 9)
|
if (_opt_newgame.diff_level == 9) SetDifficultyLevel(0, &_opt_newgame);
|
||||||
SetDifficultyLevel(0, &_opt_newgame);
|
|
||||||
|
|
||||||
// initialize the ingame console
|
// initialize the ingame console
|
||||||
IConsoleInit();
|
IConsoleInit();
|
||||||
|
@ -466,7 +464,7 @@ int ttd_main(int argc, char* argv[])
|
||||||
GenerateWorld(GW_EMPTY, 64, 64); // Make the viewport initialization happy
|
GenerateWorld(GW_EMPTY, 64, 64); // Make the viewport initialization happy
|
||||||
|
|
||||||
#ifdef ENABLE_NETWORK
|
#ifdef ENABLE_NETWORK
|
||||||
if ((network) && (_network_available)) {
|
if (network && _network_available) {
|
||||||
if (network_conn != NULL) {
|
if (network_conn != NULL) {
|
||||||
const char *port = NULL;
|
const char *port = NULL;
|
||||||
const char *player = NULL;
|
const char *player = NULL;
|
||||||
|
@ -732,17 +730,19 @@ 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, NETWORK_NAME_LENGTH, "Random Map");
|
||||||
|
}
|
||||||
#endif /* ENABLE_NETWORK */
|
#endif /* ENABLE_NETWORK */
|
||||||
MakeNewGame();
|
MakeNewGame();
|
||||||
break;
|
break;
|
||||||
|
|
||||||
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, NETWORK_NAME_LENGTH, "%s (Loaded scenario)", _file_to_saveload.title);
|
||||||
#endif /* ENABLE_NETWORK */
|
}
|
||||||
|
#endif /* ENABLE_NETWORK */
|
||||||
StartScenario();
|
StartScenario();
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
@ -756,8 +756,9 @@ void SwitchMode(int new_mode)
|
||||||
_local_player = 0;
|
_local_player = 0;
|
||||||
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, NETWORK_NAME_LENGTH, "%s (Loaded game)", _file_to_saveload.title);
|
||||||
|
}
|
||||||
#endif /* ENABLE_NETWORK */
|
#endif /* ENABLE_NETWORK */
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
@ -785,7 +786,6 @@ void SwitchMode(int new_mode)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
case SM_MENU: /* Switch to game intro menu */
|
case SM_MENU: /* Switch to game intro menu */
|
||||||
LoadIntroGame();
|
LoadIntroGame();
|
||||||
break;
|
break;
|
||||||
|
@ -799,15 +799,16 @@ void SwitchMode(int new_mode)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case SM_GENRANDLAND: /* Generate random land within scenario editor */
|
case SM_GENRANDLAND: /* Generate random land within scenario editor */
|
||||||
GenerateWorld(GW_RANDOM, 1<<_patches.map_x, 1<<_patches.map_y);
|
GenerateWorld(GW_RANDOM, 1 << _patches.map_x, 1 << _patches.map_y);
|
||||||
// XXX: set date
|
// XXX: set date
|
||||||
_local_player = OWNER_NONE;
|
_local_player = OWNER_NONE;
|
||||||
MarkWholeScreenDirty();
|
MarkWholeScreenDirty();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (_switch_mode_errorstr != INVALID_STRING_ID)
|
if (_switch_mode_errorstr != INVALID_STRING_ID) {
|
||||||
ShowErrorMessage(INVALID_STRING_ID,_switch_mode_errorstr,0,0);
|
ShowErrorMessage(INVALID_STRING_ID, _switch_mode_errorstr, 0, 0);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -650,8 +650,7 @@ int32 CmdCloneOrder(int x, int y, uint32 flags, uint32 p1, uint32 p2)
|
||||||
/* Link this vehicle in the shared-list */
|
/* Link this vehicle in the shared-list */
|
||||||
dst->next_shared = src->next_shared;
|
dst->next_shared = src->next_shared;
|
||||||
dst->prev_shared = src;
|
dst->prev_shared = src;
|
||||||
if (src->next_shared != NULL)
|
if (src->next_shared != NULL) src->next_shared->prev_shared = dst;
|
||||||
src->next_shared->prev_shared = dst;
|
|
||||||
src->next_shared = dst;
|
src->next_shared = dst;
|
||||||
|
|
||||||
InvalidateVehicleOrder(dst);
|
InvalidateVehicleOrder(dst);
|
||||||
|
|
19
rail.h
19
rail.h
|
@ -497,7 +497,9 @@ static inline bool IsDiagonalTrackdir(Trackdir trackdir) { return IsDiagonalTrac
|
||||||
static inline bool HasSignalOnTrack(TileIndex tile, Track track)
|
static inline bool HasSignalOnTrack(TileIndex tile, Track track)
|
||||||
{
|
{
|
||||||
assert(IsValidTrack(track));
|
assert(IsValidTrack(track));
|
||||||
return ((GetRailTileType(tile) == RAIL_TYPE_SIGNALS) && ((_m[tile].m3 & SignalOnTrack(track)) != 0));
|
return
|
||||||
|
GetRailTileType(tile) == RAIL_TYPE_SIGNALS &&
|
||||||
|
(_m[tile].m3 & SignalOnTrack(track)) != 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -510,7 +512,9 @@ static inline bool HasSignalOnTrack(TileIndex tile, Track track)
|
||||||
static inline bool HasSignalOnTrackdir(TileIndex tile, Trackdir trackdir)
|
static inline bool HasSignalOnTrackdir(TileIndex tile, Trackdir trackdir)
|
||||||
{
|
{
|
||||||
assert (IsValidTrackdir(trackdir));
|
assert (IsValidTrackdir(trackdir));
|
||||||
return (GetRailTileType(tile) == RAIL_TYPE_SIGNALS) && (_m[tile].m3 & SignalAlongTrackdir(trackdir));
|
return
|
||||||
|
GetRailTileType(tile) == RAIL_TYPE_SIGNALS &&
|
||||||
|
_m[tile].m3 & SignalAlongTrackdir(trackdir);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -523,7 +527,8 @@ static inline SignalState GetSignalState(TileIndex tile, Trackdir trackdir)
|
||||||
{
|
{
|
||||||
assert(IsValidTrackdir(trackdir));
|
assert(IsValidTrackdir(trackdir));
|
||||||
assert(HasSignalOnTrack(tile, TrackdirToTrack(trackdir)));
|
assert(HasSignalOnTrack(tile, TrackdirToTrack(trackdir)));
|
||||||
return ((_m[tile].m2 & SignalAlongTrackdir(trackdir))?SIGNAL_STATE_GREEN:SIGNAL_STATE_RED);
|
return _m[tile].m2 & SignalAlongTrackdir(trackdir) ?
|
||||||
|
SIGNAL_STATE_GREEN : SIGNAL_STATE_RED;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -552,7 +557,7 @@ static inline SignalType GetSignalType(TileIndex tile, Track track)
|
||||||
static inline bool HasSemaphores(TileIndex tile, Track track)
|
static inline bool HasSemaphores(TileIndex tile, Track track)
|
||||||
{
|
{
|
||||||
assert(IsValidTrack(track));
|
assert(IsValidTrack(track));
|
||||||
return (_m[tile].m4 & SIG_SEMAPHORE_MASK);
|
return _m[tile].m4 & SIG_SEMAPHORE_MASK;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -580,8 +585,7 @@ static inline bool IsLevelCrossing(TileIndex tile)
|
||||||
static inline TransportType GetCrossingTransportType(TileIndex tile, Track track)
|
static inline TransportType GetCrossingTransportType(TileIndex tile, Track track)
|
||||||
{
|
{
|
||||||
/* XXX: Nicer way to write this? */
|
/* XXX: Nicer way to write this? */
|
||||||
switch(track)
|
switch (track) {
|
||||||
{
|
|
||||||
/* When map5 bit 3 is set, the road runs in the y direction (DIAG2) */
|
/* When map5 bit 3 is set, the road runs in the y direction (DIAG2) */
|
||||||
case TRACK_DIAG1:
|
case TRACK_DIAG1:
|
||||||
return (HASBIT(_m[tile].m5, 3) ? TRANSPORT_RAIL : TRANSPORT_ROAD);
|
return (HASBIT(_m[tile].m5, 3) ? TRANSPORT_RAIL : TRANSPORT_ROAD);
|
||||||
|
@ -627,8 +631,7 @@ static inline bool IsCompatibleRail(RailType enginetype, RailType tiletype)
|
||||||
static inline bool TracksOverlap(TrackBits bits)
|
static inline bool TracksOverlap(TrackBits bits)
|
||||||
{
|
{
|
||||||
/* With no, or only one track, there is no overlap */
|
/* With no, or only one track, there is no overlap */
|
||||||
if (bits == 0 || KILL_FIRST_BIT(bits) == 0)
|
if (bits == 0 || KILL_FIRST_BIT(bits) == 0) return false;
|
||||||
return false;
|
|
||||||
/* 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. */
|
||||||
|
|
85
rail_cmd.c
85
rail_cmd.c
|
@ -216,10 +216,19 @@ uint GetRailFoundation(uint tileh, uint bits)
|
||||||
if ((~_valid_tileh_slopes[1][tileh] & bits) == 0)
|
if ((~_valid_tileh_slopes[1][tileh] & bits) == 0)
|
||||||
return tileh;
|
return tileh;
|
||||||
|
|
||||||
if ( ((i=0, tileh == 1) || (i+=2, tileh == 2) || (i+=2, tileh == 4) || (i+=2, tileh == 8)) && (bits == TRACK_BIT_DIAG1 || (i++, bits == TRACK_BIT_DIAG2)))
|
if ((
|
||||||
|
(i = 0, tileh == 1) ||
|
||||||
|
(i += 2, tileh == 2) ||
|
||||||
|
(i += 2, tileh == 4) ||
|
||||||
|
(i += 2, tileh == 8)
|
||||||
|
) && (
|
||||||
|
bits == TRACK_BIT_DIAG1 ||
|
||||||
|
(i++, bits == TRACK_BIT_DIAG2)
|
||||||
|
)) {
|
||||||
return i + 15;
|
return i + 15;
|
||||||
|
} else {
|
||||||
return 0;
|
return 0;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -526,8 +535,12 @@ static int32 ValidateAutoDrag(Trackdir *trackdir, int x, int y, int ex, int ey)
|
||||||
}
|
}
|
||||||
|
|
||||||
// validate the direction
|
// validate the direction
|
||||||
while (((trdx <= 0) && (dx > 0)) || ((trdx >= 0) && (dx < 0)) ||
|
while (
|
||||||
((trdy <= 0) && (dy > 0)) || ((trdy >= 0) && (dy < 0))) {
|
(trdx <= 0 && dx > 0) ||
|
||||||
|
(trdx >= 0 && dx < 0) ||
|
||||||
|
(trdy <= 0 && dy > 0) ||
|
||||||
|
(trdy >= 0 && dy < 0)
|
||||||
|
) {
|
||||||
if (!HASBIT(*trackdir, 3)) { // first direction is invalid, try the other
|
if (!HASBIT(*trackdir, 3)) { // first direction is invalid, try the other
|
||||||
SETBIT(*trackdir, 3); // reverse the direction
|
SETBIT(*trackdir, 3); // reverse the direction
|
||||||
trdx = -trdx;
|
trdx = -trdx;
|
||||||
|
@ -541,7 +554,7 @@ static int32 ValidateAutoDrag(Trackdir *trackdir, int x, int y, int ex, int ey)
|
||||||
if (!IsDiagonalTrackdir(*trackdir)) {
|
if (!IsDiagonalTrackdir(*trackdir)) {
|
||||||
trdx = _railbit.xinc[*trackdir];
|
trdx = _railbit.xinc[*trackdir];
|
||||||
trdy = _railbit.yinc[*trackdir];
|
trdy = _railbit.yinc[*trackdir];
|
||||||
if ((abs(dx) != abs(dy)) && (abs(dx) + abs(trdy) != abs(dy) + abs(trdx)))
|
if (abs(dx) != abs(dy) && abs(dx) + abs(trdy) != abs(dy) + abs(trdx))
|
||||||
return CMD_ERROR;
|
return CMD_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -680,8 +693,7 @@ int32 CmdBuildTrainDepot(int x, int y, uint32 flags, uint32 p1, uint32 p2)
|
||||||
d->xy = tile;
|
d->xy = tile;
|
||||||
d->town_index = ClosestTownFromTile(tile, (uint)-1)->index;
|
d->town_index = ClosestTownFromTile(tile, (uint)-1)->index;
|
||||||
|
|
||||||
SetSignalsOnBothDir(tile, (p2&1) ? 2 : 1);
|
SetSignalsOnBothDir(tile, (p2 & 1) ? 2 : 1);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return cost + _price.build_train_depot;
|
return cost + _price.build_train_depot;
|
||||||
|
@ -892,7 +904,7 @@ static int32 CmdSignalTrackHelper(int x, int y, uint32 flags, uint32 p1, uint32
|
||||||
if (!IsDiagonalTrackdir(trackdir)) trackdir ^= 1;
|
if (!IsDiagonalTrackdir(trackdir)) trackdir ^= 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
return (error) ? CMD_ERROR : total_cost;
|
return error ? CMD_ERROR : total_cost;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Build signals on a stretch of track.
|
/** Build signals on a stretch of track.
|
||||||
|
@ -1071,12 +1083,12 @@ static int32 ClearTile_Track(TileIndex tile, byte flags)
|
||||||
switch (GetRailTileType(tile)) {
|
switch (GetRailTileType(tile)) {
|
||||||
/* XXX: Why the fuck do we remove these thow signals first? */
|
/* XXX: Why the fuck do we remove these thow signals first? */
|
||||||
case RAIL_TYPE_SIGNALS:
|
case RAIL_TYPE_SIGNALS:
|
||||||
if(HasSignalOnTrack(tile, TRACK_DIAG1)) {
|
if (HasSignalOnTrack(tile, TRACK_DIAG1)) {
|
||||||
ret = DoCommandByTile(tile, TRACK_DIAG1, 0, flags, CMD_REMOVE_SIGNALS);
|
ret = DoCommandByTile(tile, TRACK_DIAG1, 0, flags, CMD_REMOVE_SIGNALS);
|
||||||
if (CmdFailed(ret)) return CMD_ERROR;
|
if (CmdFailed(ret)) return CMD_ERROR;
|
||||||
cost += ret;
|
cost += ret;
|
||||||
}
|
}
|
||||||
if(HasSignalOnTrack(tile, TRACK_LOWER)) {
|
if (HasSignalOnTrack(tile, TRACK_LOWER)) {
|
||||||
ret = DoCommandByTile(tile, TRACK_LOWER, 0, flags, CMD_REMOVE_SIGNALS);
|
ret = DoCommandByTile(tile, TRACK_LOWER, 0, flags, CMD_REMOVE_SIGNALS);
|
||||||
if (CmdFailed(ret)) return CMD_ERROR;
|
if (CmdFailed(ret)) return CMD_ERROR;
|
||||||
cost += ret;
|
cost += ret;
|
||||||
|
@ -1152,9 +1164,9 @@ static const SpriteID _signal_base_sprites[16] = {
|
||||||
// used to determine the side of the road for the signal
|
// used to determine the side of the road for the signal
|
||||||
static const byte _signal_position[24] = {
|
static const byte _signal_position[24] = {
|
||||||
/* original: left side position */
|
/* original: left side position */
|
||||||
0x58,0x1E,0xE1,0xB9,0x01,0xA3,0x4B,0xEE,0x3B,0xD4,0x43,0xBD,
|
0x58, 0x1E, 0xE1, 0xB9, 0x01, 0xA3, 0x4B, 0xEE, 0x3B, 0xD4, 0x43, 0xBD,
|
||||||
/* patch: ride side position */
|
/* patch: ride side position */
|
||||||
0x1E,0xAC,0x64,0xE1,0x4A,0x10,0xEE,0xC5,0xDB,0x34,0x4D,0xB3
|
0x1E, 0xAC, 0x64, 0xE1, 0x4A, 0x10, 0xEE, 0xC5, 0xDB, 0x34, 0x4D, 0xB3
|
||||||
};
|
};
|
||||||
|
|
||||||
static void DrawSignalHelper(const TileInfo *ti, byte condition, uint32 image_and_pos)
|
static void DrawSignalHelper(const TileInfo *ti, byte condition, uint32 image_and_pos)
|
||||||
|
@ -1176,7 +1188,7 @@ static void DrawTrackFence_NW(const TileInfo *ti)
|
||||||
uint32 image = 0x515;
|
uint32 image = 0x515;
|
||||||
if (ti->tileh != 0) image = (ti->tileh & 2) ? 0x519 : 0x51B;
|
if (ti->tileh != 0) image = (ti->tileh & 2) ? 0x519 : 0x51B;
|
||||||
AddSortableSpriteToDraw(image | _drawtile_track_palette,
|
AddSortableSpriteToDraw(image | _drawtile_track_palette,
|
||||||
ti->x, ti->y+1, 16, 1, 4, ti->z);
|
ti->x, ti->y + 1, 16, 1, 4, ti->z);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void DrawTrackFence_SE(const TileInfo *ti)
|
static void DrawTrackFence_SE(const TileInfo *ti)
|
||||||
|
@ -1184,7 +1196,7 @@ static void DrawTrackFence_SE(const TileInfo *ti)
|
||||||
uint32 image = 0x515;
|
uint32 image = 0x515;
|
||||||
if (ti->tileh != 0) image = (ti->tileh & 2) ? 0x519 : 0x51B;
|
if (ti->tileh != 0) image = (ti->tileh & 2) ? 0x519 : 0x51B;
|
||||||
AddSortableSpriteToDraw(image | _drawtile_track_palette,
|
AddSortableSpriteToDraw(image | _drawtile_track_palette,
|
||||||
ti->x, ti->y+15, 16, 1, 4, ti->z);
|
ti->x, ti->y + 15, 16, 1, 4, ti->z);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void DrawTrackFence_NW_SE(const TileInfo *ti)
|
static void DrawTrackFence_NW_SE(const TileInfo *ti)
|
||||||
|
@ -1198,7 +1210,7 @@ static void DrawTrackFence_NE(const TileInfo *ti)
|
||||||
uint32 image = 0x516;
|
uint32 image = 0x516;
|
||||||
if (ti->tileh != 0) image = (ti->tileh & 2) ? 0x51A : 0x51C;
|
if (ti->tileh != 0) image = (ti->tileh & 2) ? 0x51A : 0x51C;
|
||||||
AddSortableSpriteToDraw(image | _drawtile_track_palette,
|
AddSortableSpriteToDraw(image | _drawtile_track_palette,
|
||||||
ti->x+1, ti->y, 1, 16, 4, ti->z);
|
ti->x + 1, ti->y, 1, 16, 4, ti->z);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void DrawTrackFence_SW(const TileInfo *ti)
|
static void DrawTrackFence_SW(const TileInfo *ti)
|
||||||
|
@ -1206,7 +1218,7 @@ static void DrawTrackFence_SW(const TileInfo *ti)
|
||||||
uint32 image = 0x516;
|
uint32 image = 0x516;
|
||||||
if (ti->tileh != 0) image = (ti->tileh & 2) ? 0x51A : 0x51C;
|
if (ti->tileh != 0) image = (ti->tileh & 2) ? 0x51A : 0x51C;
|
||||||
AddSortableSpriteToDraw(image | _drawtile_track_palette,
|
AddSortableSpriteToDraw(image | _drawtile_track_palette,
|
||||||
ti->x+15, ti->y, 1, 16, 4, ti->z);
|
ti->x + 15, ti->y, 1, 16, 4, ti->z);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void DrawTrackFence_NE_SW(const TileInfo *ti)
|
static void DrawTrackFence_NE_SW(const TileInfo *ti)
|
||||||
|
@ -1277,10 +1289,11 @@ static DetailedTrackProc* const _detailed_track_proc[] = {
|
||||||
DetTrackDrawProc_Null,
|
DetTrackDrawProc_Null,
|
||||||
};
|
};
|
||||||
|
|
||||||
static void DrawSpecialBuilding(uint32 image, uint32 offset,
|
static void DrawSpecialBuilding(
|
||||||
const TileInfo* ti,
|
uint32 image, uint32 offset,
|
||||||
byte x, byte y, byte z,
|
const TileInfo* ti,
|
||||||
byte xsize, byte ysize, byte zsize)
|
byte x, byte y, byte z,
|
||||||
|
byte xsize, byte ysize, byte zsize)
|
||||||
{
|
{
|
||||||
if (image & PALETTE_MODIFIER_COLOR) image |= _drawtile_track_palette;
|
if (image & PALETTE_MODIFIER_COLOR) image |= _drawtile_track_palette;
|
||||||
image += offset;
|
image += offset;
|
||||||
|
@ -1475,7 +1488,8 @@ static void DrawTile_Track(TileInfo *ti)
|
||||||
// adjust ground tile for desert
|
// adjust ground tile for desert
|
||||||
// (don't adjust for arctic depots, because snow in depots looks weird)
|
// (don't adjust for arctic depots, because snow in depots looks weird)
|
||||||
// type >= 4 means waypoints
|
// type >= 4 means waypoints
|
||||||
if ((_m[ti->tile].m4 & RAIL_MAP2LO_GROUND_MASK) == RAIL_GROUND_ICE_DESERT && (_opt.landscape == LT_DESERT || type >= 4)) {
|
if ((_m[ti->tile].m4 & RAIL_MAP2LO_GROUND_MASK) == RAIL_GROUND_ICE_DESERT &&
|
||||||
|
(_opt.landscape == LT_DESERT || type >= 4)) {
|
||||||
if (image != SPR_FLAT_GRASS_TILE) {
|
if (image != SPR_FLAT_GRASS_TILE) {
|
||||||
image += rti->snow_offset; // tile with tracks
|
image += rti->snow_offset; // tile with tracks
|
||||||
} else {
|
} else {
|
||||||
|
@ -1486,9 +1500,11 @@ static void DrawTile_Track(TileInfo *ti)
|
||||||
DrawGroundSprite(image);
|
DrawGroundSprite(image);
|
||||||
|
|
||||||
for (; drss->image != 0; drss++) {
|
for (; drss->image != 0; drss++) {
|
||||||
DrawSpecialBuilding(drss->image, type < 4 ? rti->total_offset : 0, ti,
|
DrawSpecialBuilding(
|
||||||
drss->subcoord_x, drss->subcoord_y, 0,
|
drss->image, type < 4 ? rti->total_offset : 0, ti,
|
||||||
drss->width, drss->height, 0x17);
|
drss->subcoord_x, drss->subcoord_y, 0,
|
||||||
|
drss->width, drss->height, 0x17
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1693,7 +1709,7 @@ static void SetSignalsAfterProc(TrackPathFinder *tpf)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
/* Goto the next item */
|
/* Goto the next item */
|
||||||
} while ((offs=link->next) != 0xFFFF);
|
} while ((offs = link->next) != 0xFFFF);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1725,7 +1741,7 @@ static void ChangeSignalStates(SetSignalsData *ssd)
|
||||||
int ex = ssd->presignal_exits, exfree = ssd->presignal_exits_free;
|
int ex = ssd->presignal_exits, exfree = ssd->presignal_exits_free;
|
||||||
|
|
||||||
// subtract for dual combo signals so they don't count themselves
|
// subtract for dual combo signals so they don't count themselves
|
||||||
if (_m[tile].m4&2 && HasSignalOnTrackdir(tile, ssd->bit[i])) {
|
if (_m[tile].m4 & 2 && HasSignalOnTrackdir(tile, ssd->bit[i])) {
|
||||||
ex--;
|
ex--;
|
||||||
if (GetSignalState(tile, ssd->bit[i]) != SIGNAL_STATE_RED) exfree--;
|
if (GetSignalState(tile, ssd->bit[i]) != SIGNAL_STATE_RED) exfree--;
|
||||||
}
|
}
|
||||||
|
@ -1738,16 +1754,14 @@ static void ChangeSignalStates(SetSignalsData *ssd)
|
||||||
if (ssd->stop) {
|
if (ssd->stop) {
|
||||||
make_red:
|
make_red:
|
||||||
// turn red
|
// turn red
|
||||||
if ( (bit&m2) == 0 )
|
if ((bit & m2) == 0) continue;
|
||||||
continue;
|
|
||||||
} else {
|
} else {
|
||||||
// turn green
|
// turn green
|
||||||
if ( (bit&m2) != 0 )
|
if ((bit & m2) != 0) continue;
|
||||||
continue;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Update signals on the other side of this exit-combo signal; it changed. */
|
/* Update signals on the other side of this exit-combo signal; it changed. */
|
||||||
if (_m[tile].m4 & 2 ) {
|
if (_m[tile].m4 & 2) {
|
||||||
if (ssd->cur_stack != NUM_SSD_STACK) {
|
if (ssd->cur_stack != NUM_SSD_STACK) {
|
||||||
ssd->next_tile[ssd->cur_stack] = tile;
|
ssd->next_tile[ssd->cur_stack] = tile;
|
||||||
ssd->next_dir[ssd->cur_stack] = _dir_from_track[ssd->bit[i]];
|
ssd->next_dir[ssd->cur_stack] = _dir_from_track[ssd->bit[i]];
|
||||||
|
@ -1772,7 +1786,7 @@ bool UpdateSignalsOnSegment(TileIndex tile, byte direction)
|
||||||
ssd.cur_stack = 0;
|
ssd.cur_stack = 0;
|
||||||
direction >>= 1;
|
direction >>= 1;
|
||||||
|
|
||||||
for(;;) {
|
for (;;) {
|
||||||
// go through one segment and update all signals pointing into that segment.
|
// go through one segment and update all signals pointing into that segment.
|
||||||
ssd.cur = ssd.presignal_exits = ssd.presignal_exits_free = 0;
|
ssd.cur = ssd.presignal_exits = ssd.presignal_exits_free = 0;
|
||||||
ssd.has_presignal = false;
|
ssd.has_presignal = false;
|
||||||
|
@ -1812,6 +1826,7 @@ static uint GetSlopeZ_Track(const TileInfo* ti)
|
||||||
if (ti->tileh != 0) {
|
if (ti->tileh != 0) {
|
||||||
if ((ti->map5 & 0x80) == 0) {
|
if ((ti->map5 & 0x80) == 0) {
|
||||||
uint f = GetRailFoundation(ti->tileh, ti->map5 & 0x3F);
|
uint f = GetRailFoundation(ti->tileh, ti->map5 & 0x3F);
|
||||||
|
|
||||||
if (f != 0) {
|
if (f != 0) {
|
||||||
if (f < 15) {
|
if (f < 15) {
|
||||||
// leveled foundation
|
// leveled foundation
|
||||||
|
@ -1824,7 +1839,7 @@ static uint GetSlopeZ_Track(const TileInfo* ti)
|
||||||
// depot or waypoint
|
// depot or waypoint
|
||||||
return z + 8;
|
return z + 8;
|
||||||
}
|
}
|
||||||
return GetPartialZ(ti->x&0xF, ti->y&0xF, th) + z;
|
return GetPartialZ(ti->x & 0xF, ti->y & 0xF, th) + z;
|
||||||
}
|
}
|
||||||
return z;
|
return z;
|
||||||
}
|
}
|
||||||
|
@ -2123,7 +2138,7 @@ static uint32 VehicleEnter_Track(Vehicle *v, TileIndex tile, int x, int y)
|
||||||
} else if (fract_coord_leave == fract_coord) {
|
} else if (fract_coord_leave == fract_coord) {
|
||||||
if (_leave_directions[dir] == v->direction) {
|
if (_leave_directions[dir] == v->direction) {
|
||||||
/* leave the depot? */
|
/* leave the depot? */
|
||||||
if ((v=v->next) != NULL) {
|
if ((v = v->next) != NULL) {
|
||||||
v->vehstatus &= ~VS_HIDDEN;
|
v->vehstatus &= ~VS_HIDDEN;
|
||||||
v->u.rail.track = _depot_track_mask[dir];
|
v->u.rail.track = _depot_track_mask[dir];
|
||||||
assert(v->u.rail.track);
|
assert(v->u.rail.track);
|
||||||
|
|
|
@ -39,14 +39,14 @@ static bool HasTileRoadAt(TileIndex tile, int i)
|
||||||
b = (b&8)?5:10;
|
b = (b&8)?5:10;
|
||||||
} else if ((b & 0xF0) == 0x20) {
|
} else if ((b & 0xF0) == 0x20) {
|
||||||
return (~b & 3) == i;
|
return (~b & 3) == i;
|
||||||
} else
|
} else {
|
||||||
return false;
|
return false;
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case MP_STATION:
|
case MP_STATION:
|
||||||
b = _m[tile].m5;
|
b = _m[tile].m5;
|
||||||
if (!IS_BYTE_INSIDE(b, 0x43, 0x43+8))
|
if (!IS_BYTE_INSIDE(b, 0x43, 0x43 + 8)) return false;
|
||||||
return false;
|
|
||||||
return ((~(b - 0x43) & 3) == i);
|
return ((~(b - 0x43) & 3) == i);
|
||||||
|
|
||||||
case MP_TUNNELBRIDGE:
|
case MP_TUNNELBRIDGE:
|
||||||
|
|
109
roadveh_cmd.c
109
roadveh_cmd.c
|
@ -499,7 +499,7 @@ static void RoadVehIsCrashed(Vehicle *v)
|
||||||
if (v->u.road.crashed_ctr == 2) {
|
if (v->u.road.crashed_ctr == 2) {
|
||||||
CreateEffectVehicleRel(v, 4, 4, 8, EV_EXPLOSION_LARGE);
|
CreateEffectVehicleRel(v, 4, 4, 8, EV_EXPLOSION_LARGE);
|
||||||
} else if (v->u.road.crashed_ctr <= 45) {
|
} else if (v->u.road.crashed_ctr <= 45) {
|
||||||
if ((v->tick_counter&7)==0)
|
if ((v->tick_counter & 7) == 0)
|
||||||
RoadVehSetRandomDirection(v);
|
RoadVehSetRandomDirection(v);
|
||||||
} else if (v->u.road.crashed_ctr >= 2220) {
|
} else if (v->u.road.crashed_ctr >= 2220) {
|
||||||
RoadVehDelete(v);
|
RoadVehDelete(v);
|
||||||
|
@ -526,11 +526,10 @@ 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)
|
if (v->cargo_type == 0) pass += v->cargo_count;
|
||||||
pass += v->cargo_count;
|
|
||||||
v->cargo_count = 0;
|
v->cargo_count = 0;
|
||||||
SetDParam(0, pass);
|
|
||||||
|
|
||||||
|
SetDParam(0, pass);
|
||||||
AddNewsItem(
|
AddNewsItem(
|
||||||
(pass == 1) ?
|
(pass == 1) ?
|
||||||
STR_9031_ROAD_VEHICLE_CRASH_DRIVER : STR_9032_ROAD_VEHICLE_CRASH_DIE,
|
STR_9031_ROAD_VEHICLE_CRASH_DRIVER : STR_9032_ROAD_VEHICLE_CRASH_DIE,
|
||||||
|
@ -546,14 +545,11 @@ static void RoadVehCheckTrainCrash(Vehicle *v)
|
||||||
{
|
{
|
||||||
TileIndex tile;
|
TileIndex tile;
|
||||||
|
|
||||||
if (v->u.road.state == 255)
|
if (v->u.road.state == 255) return;
|
||||||
return;
|
|
||||||
|
|
||||||
tile = v->tile;
|
tile = v->tile;
|
||||||
|
|
||||||
// Make sure it's a road/rail crossing
|
if (!IsTileType(tile, MP_STREET) || !IsLevelCrossing(tile)) return;
|
||||||
if (!IsTileType(tile, MP_STREET) || !IsLevelCrossing(tile))
|
|
||||||
return;
|
|
||||||
|
|
||||||
if (VehicleFromPos(tile, v, (VehicleFromPosProc*)EnumCheckRoadVehCrashTrain) != NULL)
|
if (VehicleFromPos(tile, v, (VehicleFromPosProc*)EnumCheckRoadVehCrashTrain) != NULL)
|
||||||
RoadVehCrash(v);
|
RoadVehCrash(v);
|
||||||
|
@ -621,11 +617,11 @@ static void ProcessRoadVehOrder(Vehicle *v)
|
||||||
|
|
||||||
if (order->type == v->current_order.type &&
|
if (order->type == v->current_order.type &&
|
||||||
order->flags == v->current_order.flags &&
|
order->flags == v->current_order.flags &&
|
||||||
order->station == v->current_order.station)
|
order->station == v->current_order.station) {
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
v->current_order = *order;
|
v->current_order = *order;
|
||||||
|
|
||||||
v->dest_tile = 0;
|
v->dest_tile = 0;
|
||||||
|
|
||||||
if (order->type == OT_GOTO_STATION) {
|
if (order->type == OT_GOTO_STATION) {
|
||||||
|
@ -799,7 +795,7 @@ static void RoadVehArrivesAt(const Vehicle* v, Station* st)
|
||||||
|
|
||||||
static bool RoadVehAccelerate(Vehicle *v)
|
static bool RoadVehAccelerate(Vehicle *v)
|
||||||
{
|
{
|
||||||
uint spd = v->cur_speed + 1 + ((v->u.road.overtaking != 0)?1:0);
|
uint spd = v->cur_speed + 1 + (v->u.road.overtaking != 0 ? 1 : 0);
|
||||||
byte t;
|
byte t;
|
||||||
|
|
||||||
// Clamp
|
// Clamp
|
||||||
|
@ -808,19 +804,17 @@ static bool RoadVehAccelerate(Vehicle *v)
|
||||||
//updates statusbar only if speed have changed to save CPU time
|
//updates statusbar only if speed have changed to save CPU time
|
||||||
if (spd != v->cur_speed) {
|
if (spd != v->cur_speed) {
|
||||||
v->cur_speed = spd;
|
v->cur_speed = spd;
|
||||||
if (_patches.vehicle_speed)
|
if (_patches.vehicle_speed) {
|
||||||
InvalidateWindowWidget(WC_VEHICLE_VIEW, v->index, STATUS_BAR);
|
InvalidateWindowWidget(WC_VEHICLE_VIEW, v->index, STATUS_BAR);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Decrease somewhat when turning
|
// Decrease somewhat when turning
|
||||||
if (!(v->direction&1))
|
if (!(v->direction & 1)) spd = spd * 3 >> 2;
|
||||||
spd = spd * 3 >> 2;
|
|
||||||
|
|
||||||
if (spd == 0)
|
if (spd == 0) return false;
|
||||||
return false;
|
|
||||||
|
|
||||||
if ((byte)++spd == 0)
|
if ((byte)++spd == 0) return true;
|
||||||
return true;
|
|
||||||
|
|
||||||
v->progress = (t = v->progress) - (byte)spd;
|
v->progress = (t = v->progress) - (byte)spd;
|
||||||
|
|
||||||
|
@ -890,9 +884,10 @@ static void RoadVehCheckOvertake(Vehicle *v, Vehicle *u)
|
||||||
od.u = u;
|
od.u = u;
|
||||||
|
|
||||||
if (u->max_speed >= v->max_speed &&
|
if (u->max_speed >= v->max_speed &&
|
||||||
!(u->vehstatus&VS_STOPPED) &&
|
!(u->vehstatus & VS_STOPPED) &&
|
||||||
u->cur_speed != 0)
|
u->cur_speed != 0) {
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (v->direction != u->direction || !(v->direction&1))
|
if (v->direction != u->direction || !(v->direction&1))
|
||||||
return;
|
return;
|
||||||
|
@ -901,30 +896,23 @@ static void RoadVehCheckOvertake(Vehicle *v, Vehicle *u)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
tt = GetTileTrackStatus(v->tile, TRANSPORT_ROAD) & 0x3F;
|
tt = GetTileTrackStatus(v->tile, TRANSPORT_ROAD) & 0x3F;
|
||||||
if ((tt & 3) == 0)
|
if ((tt & 3) == 0) return;
|
||||||
return;
|
if ((tt & 0x3C) != 0) return;
|
||||||
if ((tt & 0x3C) != 0)
|
|
||||||
return;
|
|
||||||
|
|
||||||
if (tt == 3) {
|
if (tt == 3) tt = (v->direction & 2) ? 2 : 1;
|
||||||
tt = (v->direction&2)?2:1;
|
|
||||||
}
|
|
||||||
od.tilebits = tt;
|
od.tilebits = tt;
|
||||||
|
|
||||||
od.tile = v->tile;
|
od.tile = v->tile;
|
||||||
if (FindRoadVehToOvertake(&od))
|
if (FindRoadVehToOvertake(&od)) return;
|
||||||
return;
|
|
||||||
|
|
||||||
od.tile = v->tile + TileOffsByDir(v->direction >> 1);
|
od.tile = v->tile + TileOffsByDir(v->direction >> 1);
|
||||||
if (FindRoadVehToOvertake(&od))
|
if (FindRoadVehToOvertake(&od)) return;
|
||||||
return;
|
|
||||||
|
|
||||||
if (od.u->cur_speed == 0 || od.u->vehstatus&VS_STOPPED) {
|
if (od.u->cur_speed == 0 || od.u->vehstatus&VS_STOPPED) {
|
||||||
v->u.road.overtaking_ctr = 0x11;
|
v->u.road.overtaking_ctr = 0x11;
|
||||||
v->u.road.overtaking = 0x10;
|
v->u.road.overtaking = 0x10;
|
||||||
} else {
|
} else {
|
||||||
// if (FindRoadVehToOvertake(&od))
|
// if (FindRoadVehToOvertake(&od)) return;
|
||||||
// return;
|
|
||||||
v->u.road.overtaking_ctr = 0;
|
v->u.road.overtaking_ctr = 0;
|
||||||
v->u.road.overtaking = 0x10;
|
v->u.road.overtaking = 0x10;
|
||||||
}
|
}
|
||||||
|
@ -951,8 +939,7 @@ static int PickRandomBit(uint bits)
|
||||||
uint i;
|
uint i;
|
||||||
|
|
||||||
do {
|
do {
|
||||||
if (b & 1)
|
if (b & 1) num++;
|
||||||
num++;
|
|
||||||
} while (b >>= 1);
|
} while (b >>= 1);
|
||||||
|
|
||||||
num = RandomRange(num);
|
num = RandomRange(num);
|
||||||
|
@ -1189,15 +1176,12 @@ static void RoadVehController(Vehicle *v)
|
||||||
v->breakdown_ctr--;
|
v->breakdown_ctr--;
|
||||||
}
|
}
|
||||||
|
|
||||||
// exit if vehicle is stopped
|
if (v->vehstatus & VS_STOPPED) return;
|
||||||
if (v->vehstatus & VS_STOPPED)
|
|
||||||
return;
|
|
||||||
|
|
||||||
ProcessRoadVehOrder(v);
|
ProcessRoadVehOrder(v);
|
||||||
HandleRoadVehLoading(v);
|
HandleRoadVehLoading(v);
|
||||||
|
|
||||||
if (v->current_order.type == OT_LOADING)
|
if (v->current_order.type == OT_LOADING) return;
|
||||||
return;
|
|
||||||
|
|
||||||
if (v->u.road.state == 254) {
|
if (v->u.road.state == 254) {
|
||||||
int dir;
|
int dir;
|
||||||
|
@ -1215,8 +1199,7 @@ static void RoadVehController(Vehicle *v)
|
||||||
x = TileX(v->tile) * 16 + (rdp[6].x & 0xF);
|
x = TileX(v->tile) * 16 + (rdp[6].x & 0xF);
|
||||||
y = TileY(v->tile) * 16 + (rdp[6].y & 0xF);
|
y = TileY(v->tile) * 16 + (rdp[6].y & 0xF);
|
||||||
|
|
||||||
if (RoadVehFindCloseTo(v,x,y,v->direction))
|
if (RoadVehFindCloseTo(v,x,y,v->direction)) return;
|
||||||
return;
|
|
||||||
|
|
||||||
VehicleServiceInDepot(v);
|
VehicleServiceInDepot(v);
|
||||||
|
|
||||||
|
@ -1236,8 +1219,7 @@ static void RoadVehController(Vehicle *v)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!RoadVehAccelerate(v))
|
if (!RoadVehAccelerate(v)) return;
|
||||||
return;
|
|
||||||
|
|
||||||
if (v->u.road.overtaking != 0) {
|
if (v->u.road.overtaking != 0) {
|
||||||
if (++v->u.road.overtaking_ctr >= 35)
|
if (++v->u.road.overtaking_ctr >= 35)
|
||||||
|
@ -1612,8 +1594,9 @@ void OnNewDay_RoadVeh(Vehicle *v)
|
||||||
st = GetStation(v->current_order.station);
|
st = GetStation(v->current_order.station);
|
||||||
|
|
||||||
//Current slot has expired
|
//Current slot has expired
|
||||||
if ( (v->u.road.slot_age++ <= 0) && (v->u.road.slot != NULL))
|
if (v->u.road.slot_age++ <= 0 && v->u.road.slot != NULL) {
|
||||||
ClearSlot(v, v->u.road.slot);
|
ClearSlot(v, v->u.road.slot);
|
||||||
|
}
|
||||||
|
|
||||||
//We do not have a slot, so make one
|
//We do not have a slot, so make one
|
||||||
if (v->u.road.slot == NULL) {
|
if (v->u.road.slot == NULL) {
|
||||||
|
@ -1624,7 +1607,7 @@ void OnNewDay_RoadVeh(Vehicle *v)
|
||||||
|
|
||||||
//first we need to find out how far our stations are away.
|
//first we need to find out how far our stations are away.
|
||||||
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_SLOT || rs->slot[1] == INVALID_SLOT))
|
if (!(rs->slot[0] == INVALID_SLOT || rs->slot[1] == INVALID_SLOT))
|
||||||
continue;
|
continue;
|
||||||
|
@ -1635,23 +1618,19 @@ void OnNewDay_RoadVeh(Vehicle *v)
|
||||||
|
|
||||||
// Check if the station is located BEHIND the vehicle..
|
// Check if the station is located BEHIND the vehicle..
|
||||||
// In that case, add penalty.
|
// In that case, add penalty.
|
||||||
switch(v->direction) {
|
switch (v->direction) {
|
||||||
case 1: // going north east,x position decreasing
|
case 1: // going north east,x position decreasing
|
||||||
if (v->x_pos <= (int32)TileX(rs->xy) * 16 + 15)
|
if (v->x_pos <= (int32)TileX(rs->xy) * 16 + 15) dist += 6;
|
||||||
dist += 6;
|
break;
|
||||||
break;
|
case 3: // Going south east, y position increasing
|
||||||
case 3: // Going south east, y position increasing
|
if (v->y_pos >= (int32)TileY(rs->xy) * 16) dist += 6;
|
||||||
if (v->y_pos >= (int32)TileY(rs->xy) * 16)
|
break;
|
||||||
dist += 6;
|
case 5: // Going south west, x position increasing
|
||||||
break;
|
if (v->x_pos >= (int32)TileX(rs->xy) * 16) dist += 6;
|
||||||
case 5: // Going south west, x position increasing
|
break;
|
||||||
if (v->x_pos >= (int32)TileX(rs->xy) * 16)
|
case 7: // Going north west, y position decrasing.
|
||||||
dist += 6;
|
if (v->y_pos <= (int32)TileY(rs->xy) * 16 + 15) dist += 6;
|
||||||
break;
|
break;
|
||||||
case 7: // Going north west, y position decrasing.
|
|
||||||
if (v->y_pos <= (int32)TileY(rs->xy) * 16 + 15)
|
|
||||||
dist += 6;
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Remember the one with the shortest distance
|
// Remember the one with the shortest distance
|
||||||
|
|
|
@ -491,10 +491,11 @@ static inline uint32 GetSmallMapVegetationPixels(TileIndex tile)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case MP_TREES:
|
case MP_TREES:
|
||||||
if ((_m[tile].m2 & 0x30) == 0x20)
|
if ((_m[tile].m2 & 0x30) == 0x20) {
|
||||||
bits = (_opt.landscape == LT_HILLY) ? MKCOLOR(0x98575798) : MKCOLOR(0xC25757C2);
|
bits = (_opt.landscape == LT_HILLY) ? MKCOLOR(0x98575798) : MKCOLOR(0xC25757C2);
|
||||||
else
|
} else {
|
||||||
bits = MKCOLOR(0x54575754);
|
bits = MKCOLOR(0x54575754);
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
|
@ -561,14 +562,14 @@ static inline uint32 dup_byte32(byte b) {
|
||||||
|
|
||||||
static void DrawVertMapIndicator(int x, int y, int x2, int y2)
|
static void DrawVertMapIndicator(int x, int y, int x2, int y2)
|
||||||
{
|
{
|
||||||
GfxFillRect(x, y, x2, y + 3, 69);
|
GfxFillRect(x, y, x2, y + 3, 69);
|
||||||
GfxFillRect(x, y2 - 3, x2, y2, 69);
|
GfxFillRect(x, y2 - 3, x2, y2, 69);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void DrawHorizMapIndicator(int x, int y, int x2, int y2)
|
static void DrawHorizMapIndicator(int x, int y, int x2, int y2)
|
||||||
{
|
{
|
||||||
GfxFillRect(x, y, x + 3, y2, 69);
|
GfxFillRect(x, y, x + 3, y2, 69);
|
||||||
GfxFillRect(x2 - 3, y, x2, y2, 69);
|
GfxFillRect(x2 - 3, y, x2, y2, 69);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -612,9 +613,10 @@ static void DrawSmallMap(DrawPixelInfo *dpi, Window *w, int type, bool show_town
|
||||||
|
|
||||||
/* now fill with the player colors */
|
/* now fill with the player colors */
|
||||||
FOR_ALL_PLAYERS(p) {
|
FOR_ALL_PLAYERS(p) {
|
||||||
if (p->is_active)
|
if (p->is_active) {
|
||||||
_owner_colors[p->index] =
|
_owner_colors[p->index] =
|
||||||
dup_byte32(GetNonSprite(775 + p->player_color)[0xCB]); // XXX - magic pixel
|
dup_byte32(GetNonSprite(775 + p->player_color)[0xCB]); // XXX - magic pixel
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -661,8 +663,7 @@ static void DrawSmallMap(DrawPixelInfo *dpi, Window *w, int type, bool show_town
|
||||||
/* distance from right edge */
|
/* distance from right edge */
|
||||||
t = dpi->width - x;
|
t = dpi->width - x;
|
||||||
if (t < 4) {
|
if (t < 4) {
|
||||||
if (t <= 0)
|
if (t <= 0) break; /* exit loop */
|
||||||
break; /* exit loop */
|
|
||||||
/* mask to use at the right edge */
|
/* mask to use at the right edge */
|
||||||
mask &= _smallmap_mask_right[t - 1];
|
mask &= _smallmap_mask_right[t - 1];
|
||||||
}
|
}
|
||||||
|
@ -718,13 +719,11 @@ skip_column:
|
||||||
if (x < 0) {
|
if (x < 0) {
|
||||||
// if x+1 is 0, that means we're on the very left edge,
|
// if x+1 is 0, that means we're on the very left edge,
|
||||||
// and should thus only draw a single pixel
|
// and should thus only draw a single pixel
|
||||||
if (++x != 0)
|
if (++x != 0) continue;
|
||||||
continue;
|
|
||||||
skip = true;
|
skip = true;
|
||||||
} else if (x >= dpi->width - 1) {
|
} else if (x >= dpi->width - 1) {
|
||||||
// Check if we're at the very right edge, and if so draw only a single pixel
|
// Check if we're at the very right edge, and if so draw only a single pixel
|
||||||
if (x != dpi->width - 1)
|
if (x != dpi->width - 1) continue;
|
||||||
continue;
|
|
||||||
skip = true;
|
skip = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -734,8 +733,7 @@ skip_column:
|
||||||
|
|
||||||
// And draw either one or two pixels depending on clipping
|
// And draw either one or two pixels depending on clipping
|
||||||
ptr[0] = color;
|
ptr[0] = color;
|
||||||
if (!skip)
|
if (!skip) ptr[1] = color;
|
||||||
ptr[1] = color;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -811,10 +809,10 @@ static void SmallMapWindowProc(Window *w, WindowEvent *e)
|
||||||
x = 4;
|
x = 4;
|
||||||
y_org = w->height - 44 - 11;
|
y_org = w->height - 44 - 11;
|
||||||
y = y_org;
|
y = y_org;
|
||||||
while (true) {
|
for (;;) {
|
||||||
GfxFillRect(x, y+1, x+8, y + 5, 0);
|
GfxFillRect(x, y + 1, x + 8, y + 5, 0);
|
||||||
GfxFillRect(x+1, y+2, x+7, y + 4, (byte)tbl[0]);
|
GfxFillRect(x + 1, y + 2, x + 7, y + 4, (byte)tbl[0]);
|
||||||
DrawString(x+11, y, tbl[1], 0);
|
DrawString(x + 11, y, tbl[1], 0);
|
||||||
|
|
||||||
tbl += 2;
|
tbl += 2;
|
||||||
y += 6;
|
y += 6;
|
||||||
|
@ -873,8 +871,7 @@ static void SmallMapWindowProc(Window *w, WindowEvent *e)
|
||||||
|
|
||||||
case WE_RCLICK:
|
case WE_RCLICK:
|
||||||
if (e->click.widget == 4) {
|
if (e->click.widget == 4) {
|
||||||
if (_scrolling_viewport)
|
if (_scrolling_viewport) return;
|
||||||
return;
|
|
||||||
_scrolling_viewport = true;
|
_scrolling_viewport = true;
|
||||||
_cursor.delta.x = 0;
|
_cursor.delta.x = 0;
|
||||||
_cursor.delta.y = 0;
|
_cursor.delta.y = 0;
|
||||||
|
@ -883,8 +880,7 @@ static void SmallMapWindowProc(Window *w, WindowEvent *e)
|
||||||
|
|
||||||
case WE_MOUSELOOP:
|
case WE_MOUSELOOP:
|
||||||
/* update the window every now and then */
|
/* update the window every now and then */
|
||||||
if ((++w->vscroll.pos & 0x1F) == 0)
|
if ((++w->vscroll.pos & 0x1F) == 0) SetWindowDirty(w);
|
||||||
SetWindowDirty(w);
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -911,10 +907,10 @@ void ShowSmallMap(void)
|
||||||
|
|
||||||
vp = FindWindowById(WC_MAIN_WINDOW, 0)->viewport;
|
vp = FindWindowById(WC_MAIN_WINDOW, 0)->viewport;
|
||||||
|
|
||||||
x = (((vp->virtual_width - (220*32)) / 2) + vp->virtual_left) / 4;
|
x = ((vp->virtual_width - 220 * 32) / 2 + vp->virtual_left) / 4;
|
||||||
y = ((((vp->virtual_height- (120*32)) / 2) + vp->virtual_top ) / 2) - 32;
|
y = ((vp->virtual_height - 120 * 32) / 2 + vp->virtual_top ) / 2 - 32;
|
||||||
WP(w,smallmap_d).scroll_x = (y-x) & ~0xF;
|
WP(w,smallmap_d).scroll_x = (y - x) & ~0xF;
|
||||||
WP(w,smallmap_d).scroll_y = (x+y) & ~0xF;
|
WP(w,smallmap_d).scroll_y = (x + y) & ~0xF;
|
||||||
WP(w,smallmap_d).subscroll = 0;
|
WP(w,smallmap_d).subscroll = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1210,7 +1210,6 @@ static const RealSpriteGroup *ResolveStationSpriteGroup(const SpriteGroup *spg,
|
||||||
if ((dsg->variable >> 6) == 0) {
|
if ((dsg->variable >> 6) == 0) {
|
||||||
/* General property */
|
/* General property */
|
||||||
value = GetDeterministicSpriteValue(dsg->variable);
|
value = GetDeterministicSpriteValue(dsg->variable);
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
if (st == NULL) {
|
if (st == NULL) {
|
||||||
/* We are in a build dialog of something,
|
/* We are in a build dialog of something,
|
||||||
|
@ -1268,7 +1267,6 @@ uint32 GetCustomStationRelocation(const StationSpec *spec, const Station *st, by
|
||||||
|
|
||||||
if (rsg->sprites_per_set != 0) {
|
if (rsg->sprites_per_set != 0) {
|
||||||
if (rsg->loading_count != 0) return rsg->loading[0]->g.result.result;
|
if (rsg->loading_count != 0) return rsg->loading[0]->g.result.result;
|
||||||
|
|
||||||
if (rsg->loaded_count != 0) return rsg->loaded[0]->g.result.result;
|
if (rsg->loaded_count != 0) return rsg->loaded[0]->g.result.result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1414,18 +1412,20 @@ int32 CmdBuildRoadStop(int x, int y, uint32 flags, uint32 p1, uint32 p2)
|
||||||
|
|
||||||
//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
|
||||||
road_stop = AllocateRoadStop();
|
road_stop = AllocateRoadStop();
|
||||||
if (road_stop == NULL)
|
if (road_stop == NULL) {
|
||||||
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);
|
||||||
|
}
|
||||||
|
|
||||||
if (st != NULL) {
|
if (st != NULL) {
|
||||||
if (st->owner != OWNER_NONE && st->owner != _current_player)
|
if (st->owner != OWNER_NONE && st->owner != _current_player) {
|
||||||
return_cmd_error(STR_3009_TOO_CLOSE_TO_ANOTHER_STATION);
|
return_cmd_error(STR_3009_TOO_CLOSE_TO_ANOTHER_STATION);
|
||||||
|
}
|
||||||
|
|
||||||
if (!CheckStationSpreadOut(st, tile, 1, 1))
|
if (!CheckStationSpreadOut(st, tile, 1, 1)) return CMD_ERROR;
|
||||||
return CMD_ERROR;
|
|
||||||
|
|
||||||
FindRoadStationSpot(type, st, &currstop, &prev);
|
FindRoadStationSpot(type, st, &currstop, &prev);
|
||||||
} else {
|
} else {
|
||||||
|
@ -1438,8 +1438,9 @@ int32 CmdBuildRoadStop(int x, int y, uint32 flags, uint32 p1, uint32 p2)
|
||||||
|
|
||||||
FindRoadStationSpot(type, st, &currstop, &prev);
|
FindRoadStationSpot(type, st, &currstop, &prev);
|
||||||
|
|
||||||
if (_current_player < MAX_PLAYERS && flags&DC_EXEC)
|
if (_current_player < MAX_PLAYERS && flags & DC_EXEC) {
|
||||||
SETBIT(t->have_ratings, _current_player);
|
SETBIT(t->have_ratings, _current_player);
|
||||||
|
}
|
||||||
|
|
||||||
st->sign.width_1 = 0;
|
st->sign.width_1 = 0;
|
||||||
|
|
||||||
|
@ -1486,8 +1487,9 @@ static int32 RemoveRoadStop(Station *st, uint32 flags, TileIndex tile)
|
||||||
RoadStop *cur_stop;
|
RoadStop *cur_stop;
|
||||||
bool is_truck = _m[tile].m5 < 0x47;
|
bool is_truck = _m[tile].m5 < 0x47;
|
||||||
|
|
||||||
if (_current_player != OWNER_WATER && !CheckOwnership(st->owner))
|
if (_current_player != OWNER_WATER && !CheckOwnership(st->owner)) {
|
||||||
return CMD_ERROR;
|
return CMD_ERROR;
|
||||||
|
}
|
||||||
|
|
||||||
if (is_truck) { // truck stop
|
if (is_truck) { // truck stop
|
||||||
primary_stop = &st->truck_stops;
|
primary_stop = &st->truck_stops;
|
||||||
|
@ -1499,8 +1501,7 @@ static int32 RemoveRoadStop(Station *st, uint32 flags, TileIndex tile)
|
||||||
|
|
||||||
assert(cur_stop != NULL);
|
assert(cur_stop != NULL);
|
||||||
|
|
||||||
if (!EnsureNoVehicle(tile))
|
if (!EnsureNoVehicle(tile)) return CMD_ERROR;
|
||||||
return CMD_ERROR;
|
|
||||||
|
|
||||||
if (flags & DC_EXEC) {
|
if (flags & DC_EXEC) {
|
||||||
uint i;
|
uint i;
|
||||||
|
@ -1671,8 +1672,7 @@ int32 CmdBuildAirport(int x, int y, uint32 flags, uint32 p1, uint32 p2)
|
||||||
if (!GenerateStationName(st, tile, (p1 == AT_HELIPORT) ? 5 : 1))
|
if (!GenerateStationName(st, tile, (p1 == AT_HELIPORT) ? 5 : 1))
|
||||||
return CMD_ERROR;
|
return CMD_ERROR;
|
||||||
|
|
||||||
if (flags & DC_EXEC)
|
if (flags & DC_EXEC) StationInitialize(st, tile);
|
||||||
StationInitialize(st, tile);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
cost += _price.build_airport * w * h;
|
cost += _price.build_airport * w * h;
|
||||||
|
|
|
@ -983,10 +983,11 @@ StringID RemapOldStringID(StringID s)
|
||||||
case 0xA02F: return STR_SV_AIRCRAFT_NAME;
|
case 0xA02F: return STR_SV_AIRCRAFT_NAME;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
if (IS_INT_INSIDE(s, 0x300F, 0x3030))
|
if (IS_INT_INSIDE(s, 0x300F, 0x3030)) {
|
||||||
return s - 0x300F + STR_SV_STNAME;
|
return s - 0x300F + STR_SV_STNAME;
|
||||||
else
|
} else {
|
||||||
return s;
|
return s;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1027,6 +1027,7 @@ typedef enum CursorSprites {
|
||||||
SPR_CURSOR_AUTOMAGLEV = SPR_OPENTTD_BASE + 6,
|
SPR_CURSOR_AUTOMAGLEV = SPR_OPENTTD_BASE + 6,
|
||||||
|
|
||||||
SPR_CURSOR_WAYPOINT = SPR_OPENTTD_BASE + 7,
|
SPR_CURSOR_WAYPOINT = SPR_OPENTTD_BASE + 7,
|
||||||
|
|
||||||
SPR_CURSOR_RAIL_DEPOT = 1296,
|
SPR_CURSOR_RAIL_DEPOT = 1296,
|
||||||
SPR_CURSOR_MONO_DEPOT = SPR_OPENTTD_BASE + 11,
|
SPR_CURSOR_MONO_DEPOT = SPR_OPENTTD_BASE + 11,
|
||||||
SPR_CURSOR_MAGLEV_DEPOT = SPR_OPENTTD_BASE + 12,
|
SPR_CURSOR_MAGLEV_DEPOT = SPR_OPENTTD_BASE + 12,
|
||||||
|
|
32
town_cmd.c
32
town_cmd.c
|
@ -1070,8 +1070,7 @@ Town *CreateRandomTown(uint attempts)
|
||||||
do {
|
do {
|
||||||
// Generate a tile index not too close from the edge
|
// Generate a tile index not too close from the edge
|
||||||
tile = RandomTile();
|
tile = RandomTile();
|
||||||
if (DistanceFromEdge(tile) < 20)
|
if (DistanceFromEdge(tile) < 20) continue;
|
||||||
continue;
|
|
||||||
|
|
||||||
// Make sure the tile is plain
|
// Make sure the tile is plain
|
||||||
FindLandscapeHeightByTile(&ti, tile);
|
FindLandscapeHeightByTile(&ti, tile);
|
||||||
|
@ -1079,17 +1078,14 @@ Town *CreateRandomTown(uint attempts)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
// Check not too close to a town
|
// Check not too close to a town
|
||||||
if (IsCloseToTown(tile, 20))
|
if (IsCloseToTown(tile, 20)) continue;
|
||||||
continue;
|
|
||||||
|
|
||||||
// Get a unique name for the town.
|
// Get a unique name for the town.
|
||||||
if (!CreateTownName(&townnameparts))
|
if (!CreateTownName(&townnameparts)) break;
|
||||||
break;
|
|
||||||
|
|
||||||
// Allocate a town struct
|
// Allocate a town struct
|
||||||
t = AllocateTown();
|
t = AllocateTown();
|
||||||
if (t == NULL)
|
if (t == NULL) break;
|
||||||
break;
|
|
||||||
|
|
||||||
DoCreateTown(t, tile, townnameparts);
|
DoCreateTown(t, tile, townnameparts);
|
||||||
return t;
|
return t;
|
||||||
|
@ -1247,36 +1243,36 @@ static void DoBuildTownHouse(Town *t, TileIndex tile)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (t->flags12 & oneof)
|
if (t->flags12 & oneof) continue;
|
||||||
continue;
|
|
||||||
|
|
||||||
// Make sure there is no slope?
|
// Make sure there is no slope?
|
||||||
if (_housetype_extra_flags[house]&0x12 && slope)
|
if (_housetype_extra_flags[house] & 0x12 && slope) continue;
|
||||||
continue;
|
|
||||||
|
|
||||||
if (_housetype_extra_flags[house]&0x10) {
|
if (_housetype_extra_flags[house] & 0x10) {
|
||||||
if (CheckFree2x2Area(t, tile) ||
|
if (CheckFree2x2Area(t, tile) ||
|
||||||
CheckFree2x2Area(t, (tile += TileDiffXY(-1, 0))) ||
|
CheckFree2x2Area(t, (tile += TileDiffXY(-1, 0))) ||
|
||||||
CheckFree2x2Area(t, (tile += TileDiffXY( 0, -1))) ||
|
CheckFree2x2Area(t, (tile += TileDiffXY( 0, -1))) ||
|
||||||
CheckFree2x2Area(t, (tile += TileDiffXY( 1, 0))))
|
CheckFree2x2Area(t, (tile += TileDiffXY( 1, 0)))) {
|
||||||
break;
|
break;
|
||||||
tile += TileDiffXY(0,1);
|
}
|
||||||
} else if (_housetype_extra_flags[house]&4) {
|
tile += TileDiffXY(0, 1);
|
||||||
|
} else if (_housetype_extra_flags[house] & 4) {
|
||||||
if (CheckBuildHouseMode(t, tile + TileDiffXY(1, 0), slope, 0)) break;
|
if (CheckBuildHouseMode(t, tile + TileDiffXY(1, 0), slope, 0)) break;
|
||||||
|
|
||||||
if (CheckBuildHouseMode(t, tile + TileDiffXY(-1, 0), slope, 1)) {
|
if (CheckBuildHouseMode(t, tile + TileDiffXY(-1, 0), slope, 1)) {
|
||||||
tile += TileDiffXY(-1, 0);
|
tile += TileDiffXY(-1, 0);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
} else if (_housetype_extra_flags[house]&8) {
|
} else if (_housetype_extra_flags[house] & 8) {
|
||||||
if (CheckBuildHouseMode(t, tile + TileDiffXY(0, 1), slope, 2)) break;
|
if (CheckBuildHouseMode(t, tile + TileDiffXY(0, 1), slope, 2)) break;
|
||||||
|
|
||||||
if (CheckBuildHouseMode(t, tile + TileDiffXY(0, -1), slope, 3)) {
|
if (CheckBuildHouseMode(t, tile + TileDiffXY(0, -1), slope, 3)) {
|
||||||
tile += TileDiffXY(0, -1);
|
tile += TileDiffXY(0, -1);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
} else
|
} else {
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1551,6 +1551,7 @@ static void AdvanceWagons(Vehicle *v, bool before)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static void ReverseTrainDirection(Vehicle *v)
|
static void ReverseTrainDirection(Vehicle *v)
|
||||||
{
|
{
|
||||||
int l = 0, r = -1;
|
int l = 0, r = -1;
|
||||||
|
@ -1559,7 +1560,6 @@ static void ReverseTrainDirection(Vehicle *v)
|
||||||
if (IsTileDepotType(v->tile, TRANSPORT_RAIL))
|
if (IsTileDepotType(v->tile, TRANSPORT_RAIL))
|
||||||
InvalidateWindow(WC_VEHICLE_DEPOT, v->tile);
|
InvalidateWindow(WC_VEHICLE_DEPOT, v->tile);
|
||||||
|
|
||||||
|
|
||||||
/* Check if we were approaching a rail/road-crossing */
|
/* Check if we were approaching a rail/road-crossing */
|
||||||
{
|
{
|
||||||
TileIndex tile = v->tile;
|
TileIndex tile = v->tile;
|
||||||
|
@ -2013,12 +2013,11 @@ typedef struct TrainTrackFollowerData {
|
||||||
static bool NtpCallbFindStation(TileIndex tile, TrainTrackFollowerData *ttfd, int track, uint length)
|
static bool NtpCallbFindStation(TileIndex tile, TrainTrackFollowerData *ttfd, int track, uint length)
|
||||||
{
|
{
|
||||||
// heading for nowhere?
|
// heading for nowhere?
|
||||||
if (ttfd->dest_coords == 0)
|
if (ttfd->dest_coords == 0) return false;
|
||||||
return false;
|
|
||||||
|
|
||||||
// did we reach the final station?
|
// did we reach the final station?
|
||||||
if ((ttfd->station_index == INVALID_STATION && tile == ttfd->dest_coords) ||
|
if ((ttfd->station_index == INVALID_STATION && tile == ttfd->dest_coords) ||
|
||||||
(IsTileType(tile, MP_STATION) && IS_BYTE_INSIDE(_m[tile].m5, 0, 8) && _m[tile].m2 == ttfd->station_index)) {
|
(IsTileType(tile, MP_STATION) && IS_BYTE_INSIDE(_m[tile].m5, 0, 8) && _m[tile].m2 == ttfd->station_index)) {
|
||||||
/* We do not check for dest_coords if we have a station_index,
|
/* We do not check for dest_coords if we have a station_index,
|
||||||
* because in that case the dest_coords are just an
|
* because in that case the dest_coords are just an
|
||||||
* approximation of where the station is */
|
* approximation of where the station is */
|
||||||
|
|
18
train_gui.c
18
train_gui.c
|
@ -475,8 +475,7 @@ static int GetVehicleFromTrainDepotWndPt(const Window *w, int x, int y, GetDepot
|
||||||
x = x - 23;
|
x = x - 23;
|
||||||
|
|
||||||
row = (y - 14) / 14;
|
row = (y - 14) / 14;
|
||||||
if ( (uint) row >= w->vscroll.cap)
|
if ((uint)row >= w->vscroll.cap) return 1; /* means err */
|
||||||
return 1; /* means err */
|
|
||||||
|
|
||||||
row += w->vscroll.pos;
|
row += w->vscroll.pos;
|
||||||
|
|
||||||
|
@ -487,8 +486,8 @@ static int GetVehicleFromTrainDepotWndPt(const Window *w, int x, int y, GetDepot
|
||||||
v->tile == w->window_number &&
|
v->tile == w->window_number &&
|
||||||
v->u.rail.track == 0x80 &&
|
v->u.rail.track == 0x80 &&
|
||||||
--row < 0) {
|
--row < 0) {
|
||||||
skip = w->hscroll.pos;
|
skip = w->hscroll.pos;
|
||||||
goto found_it;
|
goto found_it;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -500,8 +499,9 @@ static int GetVehicleFromTrainDepotWndPt(const Window *w, int x, int y, GetDepot
|
||||||
IsFreeWagon(v) &&
|
IsFreeWagon(v) &&
|
||||||
v->tile == w->window_number &&
|
v->tile == w->window_number &&
|
||||||
v->u.rail.track == 0x80 &&
|
v->u.rail.track == 0x80 &&
|
||||||
--row < 0)
|
--row < 0) {
|
||||||
goto found_it;
|
goto found_it;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
d->head = NULL;
|
d->head = NULL;
|
||||||
|
@ -514,8 +514,7 @@ found_it:
|
||||||
d->head = d->wagon = v;
|
d->head = d->wagon = v;
|
||||||
|
|
||||||
/* either pressed the flag or the number, but only when it's a loco */
|
/* either pressed the flag or the number, but only when it's a loco */
|
||||||
if (x < 0 && IsFrontEngine(v))
|
if (x < 0 && IsFrontEngine(v)) return (x >= -10) ? -2 : -1;
|
||||||
return (x >= -10) ? -2 : -1;
|
|
||||||
|
|
||||||
// skip vehicles that are scrolled off the left side
|
// skip vehicles that are scrolled off the left side
|
||||||
while (skip--) v = v->next;
|
while (skip--) v = v->next;
|
||||||
|
@ -1483,7 +1482,8 @@ static void PlayerTrainsWndProc(Window *w, WindowEvent *e)
|
||||||
|
|
||||||
tile = _last_built_train_depot_tile;
|
tile = _last_built_train_depot_tile;
|
||||||
do {
|
do {
|
||||||
if (IsTileDepotType(tile, TRANSPORT_RAIL) && IsTileOwner(tile, _local_player)) {
|
if (IsTileDepotType(tile, TRANSPORT_RAIL) &&
|
||||||
|
IsTileOwner(tile, _local_player)) {
|
||||||
ShowTrainDepotWindow(tile);
|
ShowTrainDepotWindow(tile);
|
||||||
ShowBuildTrainWindow(tile);
|
ShowBuildTrainWindow(tile);
|
||||||
return;
|
return;
|
||||||
|
|
|
@ -247,12 +247,15 @@ int32 CmdBuildBridge(int x, int y, uint32 flags, uint32 p1, uint32 p2)
|
||||||
if (!CheckBridge_Stuff(bridge_type, bridge_len)) return_cmd_error(STR_5015_CAN_T_BUILD_BRIDGE_HERE);
|
if (!CheckBridge_Stuff(bridge_type, bridge_len)) return_cmd_error(STR_5015_CAN_T_BUILD_BRIDGE_HERE);
|
||||||
|
|
||||||
/* retrieve landscape height and ensure it's on land */
|
/* retrieve landscape height and ensure it's on land */
|
||||||
if (
|
if ((
|
||||||
((FindLandscapeHeight(&ti_end, sx, sy),
|
FindLandscapeHeight(&ti_end, sx, sy),
|
||||||
ti_end.type == MP_WATER) && ti_end.map5 == 0) ||
|
ti_end.type == MP_WATER && ti_end.map5 == 0
|
||||||
((FindLandscapeHeight(&ti_start, x, y),
|
) || (
|
||||||
ti_start.type == MP_WATER) && ti_start.map5 == 0))
|
FindLandscapeHeight(&ti_start, x, y),
|
||||||
|
ti_start.type == MP_WATER && ti_start.map5 == 0
|
||||||
|
)) {
|
||||||
return_cmd_error(STR_02A0_ENDS_OF_BRIDGE_MUST_BOTH);
|
return_cmd_error(STR_02A0_ENDS_OF_BRIDGE_MUST_BOTH);
|
||||||
|
}
|
||||||
|
|
||||||
if (BRIDGE_FULL_LEVELED_FOUNDATION & (1 << ti_start.tileh)) {
|
if (BRIDGE_FULL_LEVELED_FOUNDATION & (1 << ti_start.tileh)) {
|
||||||
ti_start.z += 8;
|
ti_start.z += 8;
|
||||||
|
@ -1464,11 +1467,10 @@ static uint32 VehicleEnter_TunnelBridge(Vehicle *v, TileIndex tile, int x, int y
|
||||||
|
|
||||||
if (GB(_m[tile].m5, 4, 4) == 0) {
|
if (GB(_m[tile].m5, 4, 4) == 0) {
|
||||||
z = GetSlopeZ(x, y) - v->z_pos;
|
z = GetSlopeZ(x, y) - v->z_pos;
|
||||||
if (myabs(z) > 2)
|
if (myabs(z) > 2) return 8;
|
||||||
return 8;
|
|
||||||
|
|
||||||
if (v->type == VEH_Train) {
|
if (v->type == VEH_Train) {
|
||||||
fc = (x&0xF)+(y<<4);
|
fc = (x & 0xF) + (y << 4);
|
||||||
|
|
||||||
dir = GB(_m[tile].m5, 0, 2);
|
dir = GB(_m[tile].m5, 0, 2);
|
||||||
vdir = v->direction >> 1;
|
vdir = v->direction >> 1;
|
||||||
|
@ -1496,7 +1498,7 @@ static uint32 VehicleEnter_TunnelBridge(Vehicle *v, TileIndex tile, int x, int y
|
||||||
return 4;
|
return 4;
|
||||||
}
|
}
|
||||||
} else if (v->type == VEH_Road) {
|
} else if (v->type == VEH_Road) {
|
||||||
fc = (x&0xF)+(y<<4);
|
fc = (x & 0xF) + (y << 4);
|
||||||
dir = GB(_m[tile].m5, 0, 2);
|
dir = GB(_m[tile].m5, 0, 2);
|
||||||
vdir = v->direction >> 1;
|
vdir = v->direction >> 1;
|
||||||
|
|
||||||
|
@ -1504,7 +1506,6 @@ static uint32 VehicleEnter_TunnelBridge(Vehicle *v, TileIndex tile, int x, int y
|
||||||
if (v->u.road.state != 0xFF && dir == vdir) {
|
if (v->u.road.state != 0xFF && dir == vdir) {
|
||||||
if (fc == _tunnel_fractcoord_4[dir] ||
|
if (fc == _tunnel_fractcoord_4[dir] ||
|
||||||
fc == _tunnel_fractcoord_5[dir]) {
|
fc == _tunnel_fractcoord_5[dir]) {
|
||||||
|
|
||||||
v->tile = tile;
|
v->tile = tile;
|
||||||
v->u.road.state = 0xFF;
|
v->u.road.state = 0xFF;
|
||||||
v->vehstatus |= VS_HIDDEN;
|
v->vehstatus |= VS_HIDDEN;
|
||||||
|
@ -1514,10 +1515,11 @@ static uint32 VehicleEnter_TunnelBridge(Vehicle *v, TileIndex tile, int x, int y
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (dir == (vdir^2) && (
|
if (dir == (vdir ^ 2) && (
|
||||||
/* We're at the tunnel exit ?? */
|
/* We're at the tunnel exit ?? */
|
||||||
fc == _tunnel_fractcoord_6[dir] ||
|
fc == _tunnel_fractcoord_6[dir] ||
|
||||||
fc == _tunnel_fractcoord_7[dir]) &&
|
fc == _tunnel_fractcoord_7[dir]
|
||||||
|
) &&
|
||||||
z == 0) {
|
z == 0) {
|
||||||
v->tile = tile;
|
v->tile = tile;
|
||||||
v->u.road.state = _road_exit_tunnel_state[dir];
|
v->u.road.state = _road_exit_tunnel_state[dir];
|
||||||
|
|
|
@ -336,8 +336,7 @@ void GenerateUnmovables(void)
|
||||||
int dir;
|
int dir;
|
||||||
uint h;
|
uint h;
|
||||||
|
|
||||||
if (_opt.landscape == LT_CANDY)
|
if (_opt.landscape == LT_CANDY) return;
|
||||||
return;
|
|
||||||
|
|
||||||
/* add radio tower */
|
/* add radio tower */
|
||||||
i = ScaleByMapSize(1000);
|
i = ScaleByMapSize(1000);
|
||||||
|
@ -345,18 +344,15 @@ void GenerateUnmovables(void)
|
||||||
do {
|
do {
|
||||||
tile = RandomTile();
|
tile = RandomTile();
|
||||||
if (IsTileType(tile, MP_CLEAR) && GetTileSlope(tile, &h) == 0 && h >= 32) {
|
if (IsTileType(tile, MP_CLEAR) && GetTileSlope(tile, &h) == 0 && h >= 32) {
|
||||||
if(!checkRadioTowerNearby(tile))
|
if (!checkRadioTowerNearby(tile)) continue;
|
||||||
continue;
|
|
||||||
SetTileType(tile, MP_UNMOVABLE);
|
SetTileType(tile, MP_UNMOVABLE);
|
||||||
_m[tile].m5 = 0;
|
_m[tile].m5 = 0;
|
||||||
SetTileOwner(tile, OWNER_NONE);
|
SetTileOwner(tile, OWNER_NONE);
|
||||||
if (--j == 0)
|
if (--j == 0) break;
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
} while (--i);
|
} while (--i);
|
||||||
|
|
||||||
if (_opt.landscape == LT_DESERT)
|
if (_opt.landscape == LT_DESERT) return;
|
||||||
return;
|
|
||||||
|
|
||||||
/* add lighthouses */
|
/* add lighthouses */
|
||||||
i = ScaleByMapSize1D((Random() & 3) + 7);
|
i = ScaleByMapSize1D((Random() & 3) + 7);
|
||||||
|
@ -372,8 +368,7 @@ restart:
|
||||||
(dir == 3) ? TileXY(r, MapMaxY()) : 0; // bottom
|
(dir == 3) ? TileXY(r, MapMaxY()) : 0; // bottom
|
||||||
j = 20;
|
j = 20;
|
||||||
do {
|
do {
|
||||||
if (--j == 0)
|
if (--j == 0) goto restart;
|
||||||
goto restart;
|
|
||||||
tile = TILE_MASK(tile + ToTileIndexDiff(_tile_add[dir]));
|
tile = TILE_MASK(tile + ToTileIndexDiff(_tile_add[dir]));
|
||||||
} while (!(IsTileType(tile, MP_CLEAR) && GetTileSlope(tile, &h) == 0 && h <= 16));
|
} while (!(IsTileType(tile, MP_CLEAR) && GetTileSlope(tile, &h) == 0 && h <= 16));
|
||||||
|
|
||||||
|
|
|
@ -397,7 +397,6 @@ void *VehicleFromPos(TileIndex tile, void *data, VehicleFromPosProc *proc)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
static void UpdateVehiclePosHash(Vehicle* v, int x, int y)
|
static void UpdateVehiclePosHash(Vehicle* v, int x, int y)
|
||||||
{
|
{
|
||||||
VehicleID *old_hash, *new_hash;
|
VehicleID *old_hash, *new_hash;
|
||||||
|
|
|
@ -114,8 +114,9 @@ void BuildVehicleList(vehiclelist_d* vl, int type, PlayerID owner, StationID sta
|
||||||
if (!(vl->flags & VL_REBUILD)) return;
|
if (!(vl->flags & VL_REBUILD)) return;
|
||||||
|
|
||||||
sort_list = malloc(GetVehiclePoolSize() * sizeof(sort_list[0]));
|
sort_list = malloc(GetVehiclePoolSize() * sizeof(sort_list[0]));
|
||||||
if (sort_list == NULL)
|
if (sort_list == NULL) {
|
||||||
error("Could not allocate memory for the vehicle-sorting-list");
|
error("Could not allocate memory for the vehicle-sorting-list");
|
||||||
|
}
|
||||||
|
|
||||||
DEBUG(misc, 1) ("Building vehicle list for player %d station %d...",
|
DEBUG(misc, 1) ("Building vehicle list for player %d station %d...",
|
||||||
owner, station);
|
owner, station);
|
||||||
|
@ -124,8 +125,9 @@ void BuildVehicleList(vehiclelist_d* vl, int type, PlayerID owner, StationID sta
|
||||||
const Vehicle *v;
|
const Vehicle *v;
|
||||||
FOR_ALL_VEHICLES(v) {
|
FOR_ALL_VEHICLES(v) {
|
||||||
if (v->type == type && (
|
if (v->type == type && (
|
||||||
(type == VEH_Train && IsFrontEngine(v)) ||
|
(type == VEH_Train && IsFrontEngine(v)) ||
|
||||||
(type != VEH_Train && v->subtype <= subtype))) {
|
(type != VEH_Train && v->subtype <= subtype)
|
||||||
|
)) {
|
||||||
const Order *order;
|
const Order *order;
|
||||||
|
|
||||||
FOR_VEHICLE_ORDERS(v, order) {
|
FOR_VEHICLE_ORDERS(v, order) {
|
||||||
|
@ -142,8 +144,9 @@ void BuildVehicleList(vehiclelist_d* vl, int type, PlayerID owner, StationID sta
|
||||||
const Vehicle *v;
|
const Vehicle *v;
|
||||||
FOR_ALL_VEHICLES(v) {
|
FOR_ALL_VEHICLES(v) {
|
||||||
if (v->type == type && v->owner == owner && (
|
if (v->type == type && v->owner == owner && (
|
||||||
(type == VEH_Train && IsFrontEngine(v)) ||
|
(type == VEH_Train && IsFrontEngine(v)) ||
|
||||||
(type != VEH_Train && v->subtype <= subtype))) {
|
(type != VEH_Train && v->subtype <= subtype)
|
||||||
|
)) {
|
||||||
sort_list[n].index = v->index;
|
sort_list[n].index = v->index;
|
||||||
sort_list[n].owner = v->owner;
|
sort_list[n].owner = v->owner;
|
||||||
++n;
|
++n;
|
||||||
|
@ -153,8 +156,9 @@ void BuildVehicleList(vehiclelist_d* vl, int type, PlayerID owner, StationID sta
|
||||||
|
|
||||||
free(vl->sort_list);
|
free(vl->sort_list);
|
||||||
vl->sort_list = malloc(n * sizeof(vl->sort_list[0]));
|
vl->sort_list = malloc(n * sizeof(vl->sort_list[0]));
|
||||||
if (n != 0 && vl->sort_list == NULL)
|
if (n != 0 && vl->sort_list == NULL) {
|
||||||
error("Could not allocate memory for the vehicle-sorting-list");
|
error("Could not allocate memory for the vehicle-sorting-list");
|
||||||
|
}
|
||||||
vl->list_length = n;
|
vl->list_length = n;
|
||||||
|
|
||||||
for (i = 0; i < n; ++i) vl->sort_list[i] = sort_list[i];
|
for (i = 0; i < n; ++i) vl->sort_list[i] = sort_list[i];
|
||||||
|
|
54
water_cmd.c
54
water_cmd.c
|
@ -105,16 +105,12 @@ static int32 RemoveShipDepot(TileIndex tile, uint32 flags)
|
||||||
{
|
{
|
||||||
TileIndex tile2;
|
TileIndex tile2;
|
||||||
|
|
||||||
if (!CheckTileOwnership(tile))
|
if (!CheckTileOwnership(tile)) return CMD_ERROR;
|
||||||
return CMD_ERROR;
|
if (!EnsureNoVehicle(tile)) return CMD_ERROR;
|
||||||
|
|
||||||
if (!EnsureNoVehicle(tile))
|
|
||||||
return CMD_ERROR;
|
|
||||||
|
|
||||||
tile2 = tile + ((_m[tile].m5 & 2) ? TileDiffXY(0, 1) : TileDiffXY(1, 0));
|
tile2 = tile + ((_m[tile].m5 & 2) ? TileDiffXY(0, 1) : TileDiffXY(1, 0));
|
||||||
|
|
||||||
if (!EnsureNoVehicle(tile2))
|
if (!EnsureNoVehicle(tile2)) return CMD_ERROR;
|
||||||
return CMD_ERROR;
|
|
||||||
|
|
||||||
if (flags & DC_EXEC) {
|
if (flags & DC_EXEC) {
|
||||||
/* Kill the depot */
|
/* Kill the depot */
|
||||||
|
@ -286,8 +282,7 @@ static int32 ClearTile_Water(TileIndex tile, byte flags)
|
||||||
return_cmd_error(STR_3807_CAN_T_BUILD_ON_WATER);
|
return_cmd_error(STR_3807_CAN_T_BUILD_ON_WATER);
|
||||||
|
|
||||||
// Make sure no vehicle is on the tile
|
// Make sure no vehicle is on the tile
|
||||||
if (!EnsureNoVehicle(tile))
|
if (!EnsureNoVehicle(tile)) return CMD_ERROR;
|
||||||
return CMD_ERROR;
|
|
||||||
|
|
||||||
// Make sure it's not an edge tile.
|
// Make sure it's not an edge tile.
|
||||||
if (!(IS_INT_INSIDE(TileX(tile), 1, MapMaxX() - 1) &&
|
if (!(IS_INT_INSIDE(TileX(tile), 1, MapMaxX() - 1) &&
|
||||||
|
@ -295,8 +290,7 @@ static int32 ClearTile_Water(TileIndex tile, byte flags)
|
||||||
return_cmd_error(STR_0002_TOO_CLOSE_TO_EDGE_OF_MAP);
|
return_cmd_error(STR_0002_TOO_CLOSE_TO_EDGE_OF_MAP);
|
||||||
|
|
||||||
if (m5 == 0) {
|
if (m5 == 0) {
|
||||||
if (flags & DC_EXEC)
|
if (flags & DC_EXEC) DoClearSquare(tile);
|
||||||
DoClearSquare(tile);
|
|
||||||
return _price.clear_water;
|
return _price.clear_water;
|
||||||
} else if (m5 == 1) {
|
} else if (m5 == 1) {
|
||||||
slope = GetTileSlope(tile,NULL);
|
slope = GetTileSlope(tile,NULL);
|
||||||
|
@ -336,7 +330,7 @@ static int32 ClearTile_Water(TileIndex tile, byte flags)
|
||||||
default: return CMD_ERROR;
|
default: return CMD_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
return RemoveShipDepot(tile,flags);
|
return RemoveShipDepot(tile, flags);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -480,16 +474,17 @@ static void GetAcceptedCargo_Water(TileIndex tile, AcceptedCargo ac)
|
||||||
|
|
||||||
static void GetTileDesc_Water(TileIndex tile, TileDesc *td)
|
static void GetTileDesc_Water(TileIndex tile, TileDesc *td)
|
||||||
{
|
{
|
||||||
if (_m[tile].m5 == 0 && TilePixelHeight(tile) == 0)
|
if (_m[tile].m5 == 0 && TilePixelHeight(tile) == 0) {
|
||||||
td->str = STR_3804_WATER;
|
td->str = STR_3804_WATER;
|
||||||
else if (_m[tile].m5 == 0)
|
} else if (_m[tile].m5 == 0) {
|
||||||
td->str = STR_LANDINFO_CANAL;
|
td->str = STR_LANDINFO_CANAL;
|
||||||
else if (_m[tile].m5 == 1)
|
} else if (_m[tile].m5 == 1) {
|
||||||
td->str = STR_3805_COAST_OR_RIVERBANK;
|
td->str = STR_3805_COAST_OR_RIVERBANK;
|
||||||
else if ((_m[tile].m5&0xF0) == 0x10)
|
} else if ((_m[tile].m5 & 0xF0) == 0x10) {
|
||||||
td->str = STR_LANDINFO_LOCK;
|
td->str = STR_LANDINFO_LOCK;
|
||||||
else
|
} else {
|
||||||
td->str = STR_3806_SHIP_DEPOT;
|
td->str = STR_3806_SHIP_DEPOT;
|
||||||
|
}
|
||||||
|
|
||||||
td->owner = GetTileOwner(tile);
|
td->owner = GetTileOwner(tile);
|
||||||
}
|
}
|
||||||
|
@ -554,8 +549,7 @@ static void TileLoopWaterHelper(TileIndex tile, const TileIndexDiffC *offs)
|
||||||
} else {
|
} else {
|
||||||
if (IsTileType(target, MP_TUNNELBRIDGE)) {
|
if (IsTileType(target, MP_TUNNELBRIDGE)) {
|
||||||
byte m5 = _m[target].m5;
|
byte m5 = _m[target].m5;
|
||||||
if ((m5 & 0xF8) == 0xC8 || (m5 & 0xF8) == 0xF0)
|
if ((m5 & 0xF8) == 0xC8 || (m5 & 0xF8) == 0xF0) return;
|
||||||
return;
|
|
||||||
|
|
||||||
if ((m5 & 0xC0) == 0xC0) {
|
if ((m5 & 0xC0) == 0xC0) {
|
||||||
ModifyTile(target, MP_MAPOWNER | MP_MAP5, OWNER_WATER, (m5 & ~0x38) | 0x8);
|
ModifyTile(target, MP_MAPOWNER | MP_MAP5, OWNER_WATER, (m5 & ~0x38) | 0x8);
|
||||||
|
@ -650,8 +644,9 @@ void TileLoop_Water(TileIndex tile)
|
||||||
_current_player = OWNER_NONE;
|
_current_player = OWNER_NONE;
|
||||||
|
|
||||||
// edges
|
// edges
|
||||||
if (TileX(tile) == 0 && IS_INT_INSIDE(TileY(tile), 1, MapSizeY() - 3 + 1)) //NE
|
if (TileX(tile) == 0 && IS_INT_INSIDE(TileY(tile), 1, MapSizeY() - 3 + 1)) { //NE
|
||||||
TileLoopWaterHelper(tile, _tile_loop_offs_array[2]);
|
TileLoopWaterHelper(tile, _tile_loop_offs_array[2]);
|
||||||
|
}
|
||||||
|
|
||||||
if (TileX(tile) == MapSizeX() - 2 && IS_INT_INSIDE(TileY(tile), 1, MapSizeY() - 3 + 1)) { //SW
|
if (TileX(tile) == MapSizeX() - 2 && IS_INT_INSIDE(TileY(tile), 1, MapSizeY() - 3 + 1)) { //SW
|
||||||
TileLoopWaterHelper(tile, _tile_loop_offs_array[0]);
|
TileLoopWaterHelper(tile, _tile_loop_offs_array[0]);
|
||||||
|
@ -675,29 +670,26 @@ static uint32 GetTileTrackStatus_Water(TileIndex tile, TransportType mode)
|
||||||
uint m5;
|
uint m5;
|
||||||
uint b;
|
uint b;
|
||||||
|
|
||||||
if (mode != TRANSPORT_WATER)
|
if (mode != TRANSPORT_WATER) return 0;
|
||||||
return 0;
|
|
||||||
|
|
||||||
m5 = _m[tile].m5;
|
m5 = _m[tile].m5;
|
||||||
if (m5 == 0)
|
if (m5 == 0) return 0x3F3F;
|
||||||
return 0x3F3F;
|
|
||||||
|
|
||||||
if (m5 == 1) {
|
if (m5 == 1) {
|
||||||
b = _coast_tracks[GetTileSlope(tile, NULL)&0xF];
|
b = _coast_tracks[GetTileSlope(tile, NULL) & 0xF];
|
||||||
return b + (b<<8);
|
return b + (b << 8);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( (m5 & 0x10) == 0x10) {
|
if ((m5 & 0x10) == 0x10) {
|
||||||
//
|
//
|
||||||
b = _shiplift_tracks[m5 & 0xF];
|
b = _shiplift_tracks[m5 & 0xF];
|
||||||
return b + (b<<8);
|
return b + (b << 8);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!(m5 & 0x80))
|
if (!(m5 & 0x80)) return 0;
|
||||||
return 0;
|
|
||||||
|
|
||||||
b = _shipdepot_tracks[m5 & 0x7F];
|
b = _shipdepot_tracks[m5 & 0x7F];
|
||||||
return b + (b<<8);
|
return b + (b << 8);
|
||||||
}
|
}
|
||||||
|
|
||||||
extern void ShowShipDepotWindow(TileIndex tile);
|
extern void ShowShipDepotWindow(TileIndex tile);
|
||||||
|
|
3
window.c
3
window.c
|
@ -1371,11 +1371,10 @@ static void MouseLoop(int click, int mousewheel)
|
||||||
x = _cursor.pos.x;
|
x = _cursor.pos.x;
|
||||||
y = _cursor.pos.y;
|
y = _cursor.pos.y;
|
||||||
|
|
||||||
|
|
||||||
if (click == 0 && mousewheel == 0) {
|
if (click == 0 && mousewheel == 0) {
|
||||||
if (_patches.autoscroll && _game_mode != GM_MENU) {
|
if (_patches.autoscroll && _game_mode != GM_MENU) {
|
||||||
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) {
|
||||||
x -= vp->left;
|
x -= vp->left;
|
||||||
|
|
Loading…
Reference in New Issue