1
0
Fork 0

(svn r16421) -Codechange: do not unnecessarily remove constness or unnecessarily add it.

release/1.0
rubidium 2009-05-24 20:29:04 +00:00
parent 36e71c8df6
commit 0d99b6c71c
33 changed files with 108 additions and 109 deletions

View File

@ -106,8 +106,8 @@ AIInfo::~AIInfo()
{ {
/* Free all allocated strings */ /* Free all allocated strings */
for (AIConfigItemList::iterator it = this->config_list.begin(); it != this->config_list.end(); it++) { for (AIConfigItemList::iterator it = this->config_list.begin(); it != this->config_list.end(); it++) {
free((char *)(*it).name); free((void*)(*it).name);
free((char *)(*it).description); free((void*)(*it).description);
if (it->labels != NULL) { if (it->labels != NULL) {
for (LabelMapping::iterator it2 = (*it).labels->Begin(); it2 != (*it).labels->End(); it2++) { for (LabelMapping::iterator it2 = (*it).labels->Begin(); it2 != (*it).labels->End(); it2++) {
free(it2->second); free(it2->second);

View File

@ -45,11 +45,11 @@
case VEH_ROAD: { case VEH_ROAD: {
uint total_length = 0; uint total_length = 0;
for (const Vehicle *u = v; u != NULL; u = u->Next()) { for (const Vehicle *u = v; u != NULL; u = u->Next()) {
total_length += ((RoadVehicle*)u)->rcache.cached_veh_length; total_length += ((const RoadVehicle *)u)->rcache.cached_veh_length;
} }
return total_length; return total_length;
} }
case VEH_TRAIN: return ((Train *)v)->tcache.cached_total_length; case VEH_TRAIN: return ((const Train *)v)->tcache.cached_total_length;
default: return -1; default: return -1;
} }
} }
@ -85,11 +85,11 @@
EnforcePrecondition(false, ::Vehicle::Get(source_vehicle_id)->type == VEH_TRAIN); EnforcePrecondition(false, ::Vehicle::Get(source_vehicle_id)->type == VEH_TRAIN);
EnforcePrecondition(false, dest_vehicle_id == -1 || ::Vehicle::Get(dest_vehicle_id)->type == VEH_TRAIN); EnforcePrecondition(false, dest_vehicle_id == -1 || ::Vehicle::Get(dest_vehicle_id)->type == VEH_TRAIN);
const Train *v = (Train *)::Vehicle::Get(source_vehicle_id); const Train *v = (const Train *)::Vehicle::Get(source_vehicle_id);
while (source_wagon-- > 0) v = GetNextUnit(v); while (source_wagon-- > 0) v = GetNextUnit(v);
const Train *w = NULL; const Train *w = NULL;
if (dest_vehicle_id != -1) { if (dest_vehicle_id != -1) {
w = (Train *)::Vehicle::Get(dest_vehicle_id); w = (const Train *)::Vehicle::Get(dest_vehicle_id);
while (dest_wagon-- > 0) w = GetNextUnit(w); while (dest_wagon-- > 0) w = GetNextUnit(w);
} }
@ -136,7 +136,7 @@
EnforcePrecondition(false, IsValidVehicle(vehicle_id) && wagon < GetNumWagons(vehicle_id)); EnforcePrecondition(false, IsValidVehicle(vehicle_id) && wagon < GetNumWagons(vehicle_id));
EnforcePrecondition(false, ::Vehicle::Get(vehicle_id)->type == VEH_TRAIN); EnforcePrecondition(false, ::Vehicle::Get(vehicle_id)->type == VEH_TRAIN);
const Train *v = (Train *)::Vehicle::Get(vehicle_id); const Train *v = (const Train *)::Vehicle::Get(vehicle_id);
while (wagon-- > 0) v = GetNextUnit(v); while (wagon-- > 0) v = GetNextUnit(v);
return AIObject::DoCommand(0, v->index, sell_attached_wagons ? 1 : 0, CMD_SELL_RAIL_WAGON); return AIObject::DoCommand(0, v->index, sell_attached_wagons ? 1 : 0, CMD_SELL_RAIL_WAGON);
@ -243,7 +243,7 @@
const Vehicle *v = ::Vehicle::Get(vehicle_id); const Vehicle *v = ::Vehicle::Get(vehicle_id);
if (v->type == VEH_TRAIN) { if (v->type == VEH_TRAIN) {
while (wagon-- > 0) v = GetNextUnit((Train *)v); while (wagon-- > 0) v = GetNextUnit((const Train *)v);
} }
return v->engine_type; return v->engine_type;
} }
@ -281,7 +281,7 @@
const Vehicle *v = ::Vehicle::Get(vehicle_id); const Vehicle *v = ::Vehicle::Get(vehicle_id);
if (v->type == VEH_TRAIN) { if (v->type == VEH_TRAIN) {
while (wagon-- > 0) v = GetNextUnit((Train *)v); while (wagon-- > 0) v = GetNextUnit((const Train *)v);
} }
return v->age; return v->age;
} }

View File

@ -67,7 +67,7 @@ void DrawAircraftImage(const Vehicle *v, int x, int y, VehicleID selection)
SpriteID pal = (v->vehstatus & VS_CRASHED) ? PALETTE_CRASH : GetVehiclePalette(v); SpriteID pal = (v->vehstatus & VS_CRASHED) ? PALETTE_CRASH : GetVehiclePalette(v);
DrawSprite(v->GetImage(DIR_W), pal, x + 25, y + 10); DrawSprite(v->GetImage(DIR_W), pal, x + 25, y + 10);
if (v->subtype == AIR_HELICOPTER) { if (v->subtype == AIR_HELICOPTER) {
Aircraft *a = (Aircraft *)v; const Aircraft *a = (const Aircraft *)v;
SpriteID rotor_sprite = GetCustomRotorSprite(a, true); SpriteID rotor_sprite = GetCustomRotorSprite(a, true);
if (rotor_sprite == 0) rotor_sprite = SPR_ROTOR_STOPPED; if (rotor_sprite == 0) rotor_sprite = SPR_ROTOR_STOPPED;
DrawSprite(rotor_sprite, PAL_NONE, x + 25, y + 5); DrawSprite(rotor_sprite, PAL_NONE, x + 25, y + 5);

View File

@ -208,7 +208,7 @@ bool IsArticulatedVehicleCarryingDifferentCargos(const Vehicle *v, CargoID *carg
switch (v->type) { switch (v->type) {
case VEH_TRAIN: case VEH_TRAIN:
v = (EngineHasArticPart((Train *)v) ? GetNextArticPart((Train *)v) : NULL); v = (EngineHasArticPart((const Train *)v) ? GetNextArticPart((const Train *)v) : NULL);
break; break;
case VEH_ROAD: case VEH_ROAD:
@ -256,7 +256,7 @@ void CheckConsistencyOfArticulatedVehicle(const Vehicle *v)
switch (v->type) { switch (v->type) {
case VEH_TRAIN: case VEH_TRAIN:
v = (EngineHasArticPart((Train *)v) ? GetNextArticPart((Train *)v) : NULL); v = (EngineHasArticPart((const Train *)v) ? GetNextArticPart((const Train *)v) : NULL);
break; break;
case VEH_ROAD: case VEH_ROAD:

View File

@ -272,7 +272,7 @@ struct DepotWindow : Window {
DrawTrainImage(v, x + 21, sprite_y, this->sel, this->hscroll.cap + 4, this->hscroll.pos); DrawTrainImage(v, x + 21, sprite_y, this->sel, this->hscroll.cap + 4, this->hscroll.pos);
/* Number of wagons relative to a standard length wagon (rounded up) */ /* Number of wagons relative to a standard length wagon (rounded up) */
SetDParam(0, (((Train *)v)->tcache.cached_total_length + 7) / 8); SetDParam(0, (((const Train *)v)->tcache.cached_total_length + 7) / 8);
DrawString(this->widget[DEPOT_WIDGET_MATRIX].left, this->widget[DEPOT_WIDGET_MATRIX].right - 1, y + 4, STR_TINY_BLACK, TC_FROMSTRING, SA_RIGHT); // Draw the counter DrawString(this->widget[DEPOT_WIDGET_MATRIX].left, this->widget[DEPOT_WIDGET_MATRIX].right - 1, y + 4, STR_TINY_BLACK, TC_FROMSTRING, SA_RIGHT); // Draw the counter
break; break;
@ -328,7 +328,7 @@ struct DepotWindow : Window {
hnum = 8; hnum = 8;
for (uint num = 0; num < this->vehicle_list.Length(); num++) { for (uint num = 0; num < this->vehicle_list.Length(); num++) {
const Vehicle *v = this->vehicle_list[num]; const Vehicle *v = this->vehicle_list[num];
hnum = max(hnum, ((Train *)v)->tcache.cached_total_length); hnum = max(hnum, ((const Train *)v)->tcache.cached_total_length);
} }
/* Always have 1 empty row, so people can change the setting of the train */ /* Always have 1 empty row, so people can change the setting of the train */
SetVScrollCount(w, this->vehicle_list.Length() + this->wagon_list.Length() + 1); SetVScrollCount(w, this->vehicle_list.Length() + this->wagon_list.Length() + 1);
@ -450,7 +450,7 @@ struct DepotWindow : Window {
x += skip; x += skip;
/* find the vehicle in this row that was clicked */ /* find the vehicle in this row that was clicked */
while (v != NULL && (x -= ((Train *)v)->tcache.cached_veh_length) >= 0) v = v->Next(); while (v != NULL && (x -= ((const Train *)v)->tcache.cached_veh_length) >= 0) v = v->Next();
/* if an articulated part was selected, find its parent */ /* if an articulated part was selected, find its parent */
while (v != NULL && IsArticulatedPart(v)) v = v->Previous(); while (v != NULL && IsArticulatedPart(v)) v = v->Previous();
@ -514,11 +514,11 @@ struct DepotWindow : Window {
switch (v->type) { switch (v->type) {
case VEH_TRAIN: case VEH_TRAIN:
_cursor.short_vehicle_offset = 16 - ((Train *)v)->tcache.cached_veh_length * 2; _cursor.short_vehicle_offset = 16 - ((const Train *)v)->tcache.cached_veh_length * 2;
break; break;
case VEH_ROAD: case VEH_ROAD:
_cursor.short_vehicle_offset = 16 - ((RoadVehicle *)v)->rcache.cached_veh_length * 2; _cursor.short_vehicle_offset = 16 - ((const RoadVehicle *)v)->rcache.cached_veh_length * 2;
break; break;
default: default:

View File

@ -56,7 +56,7 @@ int GetDriverParamInt(const char * const *parm, const char *name, int def)
* @param name the driver to select. * @param name the driver to select.
* @post Sets the driver so GetCurrentDriver() returns it too. * @post Sets the driver so GetCurrentDriver() returns it too.
*/ */
const Driver *DriverFactoryBase::SelectDriver(const char *name, Driver::Type type) Driver *DriverFactoryBase::SelectDriver(const char *name, Driver::Type type)
{ {
if (GetDrivers().size() == 0) return NULL; if (GetDrivers().size() == 0) return NULL;

View File

@ -80,7 +80,7 @@ public:
} }
} }
static const Driver *SelectDriver(const char *name, Driver::Type type); static Driver *SelectDriver(const char *name, Driver::Type type);
static char *GetDriversInfo(char *p, const char *last); static char *GetDriversInfo(char *p, const char *last);
/** /**

View File

@ -862,7 +862,7 @@ void DetermineBasePaths(const char *exe)
#endif #endif
/* Change the working directory to that one of the executable */ /* Change the working directory to that one of the executable */
ChangeWorkingDirectory((char*)exe); ChangeWorkingDirectory(exe);
if (getcwd(tmp, MAX_PATH) == NULL) *tmp = '\0'; if (getcwd(tmp, MAX_PATH) == NULL) *tmp = '\0';
AppendPathSeparator(tmp, MAX_PATH); AppendPathSeparator(tmp, MAX_PATH);
_searchpaths[SP_BINARY_DIR] = strdup(tmp); _searchpaths[SP_BINARY_DIR] = strdup(tmp);

View File

@ -378,8 +378,7 @@ static bool FillGraphicsSetDetails(GraphicsSet *graphics, IniFile *ini, const ch
} }
const char *filename = item->value; const char *filename = item->value;
file->filename = MallocT<char>(strlen(filename) + strlen(path) + 1); file->filename = str_fmt("%s%s", path, filename);
sprintf((char*)file->filename, "%s%s", path, filename);
/* Then find the MD5 checksum */ /* Then find the MD5 checksum */
item = md5s->GetItem(filename, false); item = md5s->GetItem(filename, false);

View File

@ -2247,7 +2247,7 @@ static ChangeInfoResult IndustriesChangeInfo(uint indid, int numinfo, int prop,
IndustryTileTable **tile_table = CallocT<IndustryTileTable*>(indsp->num_table); // Table with tiles to compose an industry IndustryTileTable **tile_table = CallocT<IndustryTileTable*>(indsp->num_table); // Table with tiles to compose an industry
IndustryTileTable *itt = CallocT<IndustryTileTable>(defsize); // Temporary array to read the tile layouts from the GRF IndustryTileTable *itt = CallocT<IndustryTileTable>(defsize); // Temporary array to read the tile layouts from the GRF
int size; int size;
IndustryTileTable *copy_from; const IndustryTileTable *copy_from;
for (byte j = 0; j < indsp->num_table; j++) { for (byte j = 0; j < indsp->num_table; j++) {
for (int k = 0;; k++) { for (int k = 0;; k++) {
@ -2258,7 +2258,7 @@ static ChangeInfoResult IndustriesChangeInfo(uint indid, int numinfo, int prop,
IndustryType type = grf_load_byte(&buf); // industry holding required layout IndustryType type = grf_load_byte(&buf); // industry holding required layout
byte laynbr = grf_load_byte(&buf); // layout number to borrow byte laynbr = grf_load_byte(&buf); // layout number to borrow
copy_from = (IndustryTileTable*)_origin_industry_specs[type].table[laynbr]; copy_from = _origin_industry_specs[type].table[laynbr];
for (size = 1;; size++) { for (size = 1;; size++) {
if (copy_from[size - 1].ti.x == -0x80 && copy_from[size - 1].ti.y == 0) break; if (copy_from[size - 1].ti.x == -0x80 && copy_from[size - 1].ti.y == 0) break;
} }
@ -5455,11 +5455,11 @@ static void ResetCustomIndustries()
for (int j = 0; j < ind->num_table; j++) { for (int j = 0; j < ind->num_table; j++) {
/* remove the individual layouts */ /* remove the individual layouts */
if (ind->table[j] != NULL) { if (ind->table[j] != NULL) {
free((IndustryTileTable*)ind->table[j]); free((void*)ind->table[j]);
} }
} }
/* remove the layouts pointers */ /* remove the layouts pointers */
free((IndustryTileTable**)ind->table); free((void*)ind->table);
ind->table = NULL; ind->table = NULL;
} }

View File

@ -434,9 +434,9 @@ static uint8 LiveryHelper(EngineID engine, const Vehicle *v)
if (!Company::IsValidID(_current_company)) return 0; if (!Company::IsValidID(_current_company)) return 0;
l = GetEngineLivery(engine, _current_company, INVALID_ENGINE, NULL); l = GetEngineLivery(engine, _current_company, INVALID_ENGINE, NULL);
} else if (v->type == VEH_TRAIN) { } else if (v->type == VEH_TRAIN) {
l = GetEngineLivery(v->engine_type, v->owner, ((Train *)v)->tcache.first_engine, v); l = GetEngineLivery(v->engine_type, v->owner, ((const Train *)v)->tcache.first_engine, v);
} else if (v->type == VEH_ROAD) { } else if (v->type == VEH_ROAD) {
l = GetEngineLivery(v->engine_type, v->owner, ((RoadVehicle *)v)->rcache.first_engine, v); l = GetEngineLivery(v->engine_type, v->owner, ((const RoadVehicle *)v)->rcache.first_engine, v);
} else { } else {
l = GetEngineLivery(v->engine_type, v->owner, INVALID_ENGINE, v); l = GetEngineLivery(v->engine_type, v->owner, INVALID_ENGINE, v);
} }
@ -536,7 +536,7 @@ static uint32 VehicleGetVariable(const ResolverObject *object, byte variable, by
memset(common_subtypes, 0, sizeof(common_subtypes)); memset(common_subtypes, 0, sizeof(common_subtypes));
for (u = v; u != NULL; u = u->Next()) { for (u = v; u != NULL; u = u->Next()) {
if (v->type == VEH_TRAIN) user_def_data |= ((Train *)u)->tcache.user_def_data; if (v->type == VEH_TRAIN) user_def_data |= ((const Train *)u)->tcache.user_def_data;
/* Skip empty engines */ /* Skip empty engines */
if (u->cargo_cap == 0) continue; if (u->cargo_cap == 0) continue;
@ -886,10 +886,10 @@ static const SpriteGroup *GetVehicleSpriteGroup(EngineID engine, const Vehicle *
/* We always use cached value, except for callbacks because the override spriteset /* We always use cached value, except for callbacks because the override spriteset
* to use may be different than the one cached. It happens for callback 0x15 (refit engine), * to use may be different than the one cached. It happens for callback 0x15 (refit engine),
* as v->cargo_type is temporary changed to the new type */ * as v->cargo_type is temporary changed to the new type */
group = use_cache ? ((Train *)v)->tcache.cached_override : GetWagonOverrideSpriteSet(v->engine_type, v->cargo_type, ((Train *)v)->tcache.first_engine); group = use_cache ? ((const Train *)v)->tcache.cached_override : GetWagonOverrideSpriteSet(v->engine_type, v->cargo_type, ((const Train *)v)->tcache.first_engine);
if (group != NULL) return group; if (group != NULL) return group;
} else if (v->type == VEH_ROAD) { } else if (v->type == VEH_ROAD) {
group = GetWagonOverrideSpriteSet(v->engine_type, v->cargo_type, ((RoadVehicle *)v)->rcache.first_engine); group = GetWagonOverrideSpriteSet(v->engine_type, v->cargo_type, ((const RoadVehicle *)v)->rcache.first_engine);
if (group != NULL) return group; if (group != NULL) return group;
} }
} }
@ -952,7 +952,7 @@ SpriteID GetRotorOverrideSprite(EngineID engine, const Aircraft *v, bool info_vi
bool UsesWagonOverride(const Vehicle *v) bool UsesWagonOverride(const Vehicle *v)
{ {
assert(v->type == VEH_TRAIN); assert(v->type == VEH_TRAIN);
return ((Train *)v)->tcache.cached_override != NULL; return ((const Train *)v)->tcache.cached_override != NULL;
} }
/** /**

View File

@ -13,8 +13,8 @@ INSTANTIATE_POOL_METHODS(SpriteGroup)
RealSpriteGroup::~RealSpriteGroup() RealSpriteGroup::~RealSpriteGroup()
{ {
free((SpriteGroup**)this->loaded); free((void*)this->loaded);
free((SpriteGroup**)this->loading); free((void*)this->loading);
} }
DeterministicSpriteGroup::~DeterministicSpriteGroup() DeterministicSpriteGroup::~DeterministicSpriteGroup()
@ -25,7 +25,7 @@ DeterministicSpriteGroup::~DeterministicSpriteGroup()
RandomizedSpriteGroup::~RandomizedSpriteGroup() RandomizedSpriteGroup::~RandomizedSpriteGroup()
{ {
free((SpriteGroup**)this->groups); free((void*)this->groups);
} }
TileLayoutSpriteGroup::~TileLayoutSpriteGroup() TileLayoutSpriteGroup::~TileLayoutSpriteGroup()

View File

@ -425,7 +425,7 @@ static int32 NPFFindDepot(AyStar *as, OpenListNode *current)
/** Find any safe and free tile. */ /** Find any safe and free tile. */
static int32 NPFFindSafeTile(AyStar *as, OpenListNode *current) static int32 NPFFindSafeTile(AyStar *as, OpenListNode *current)
{ {
const Train *v = (Train *)((NPFFindStationOrTileData*)as->user_target)->v; const Train *v = (const Train *)((NPFFindStationOrTileData*)as->user_target)->v;
return return
IsSafeWaitingPosition(v, current->path.node.tile, current->path.node.direction, true, _settings_game.pf.forbid_90_deg) && IsSafeWaitingPosition(v, current->path.node.tile, current->path.node.direction, true, _settings_game.pf.forbid_90_deg) &&
@ -506,7 +506,7 @@ static void NPFSaveTargetData(AyStar *as, OpenListNode *current)
if (as->user_target != NULL && ((NPFFindStationOrTileData*)as->user_target)->reserve_path && as->user_data[NPF_TYPE] == TRANSPORT_RAIL) { if (as->user_target != NULL && ((NPFFindStationOrTileData*)as->user_target)->reserve_path && as->user_data[NPF_TYPE] == TRANSPORT_RAIL) {
/* Path reservation is requested. */ /* Path reservation is requested. */
const Train *v = (Train *)((NPFFindStationOrTileData*)as->user_target)->v; const Train *v = (const Train *)((NPFFindStationOrTileData*)as->user_target)->v;
const PathNode *target = FindSafePosition(&current->path, v); const PathNode *target = FindSafePosition(&current->path, v);
ftd->node = target->node; ftd->node = target->node;

View File

@ -206,7 +206,7 @@ struct MyGetOptData {
int numleft; int numleft;
char **argv; char **argv;
const char *options; const char *options;
const char *cont; char *cont;
MyGetOptData(int argc, char **argv, const char *options) MyGetOptData(int argc, char **argv, const char *options)
{ {
@ -220,9 +220,7 @@ struct MyGetOptData {
static int MyGetOpt(MyGetOptData *md) static int MyGetOpt(MyGetOptData *md)
{ {
const char *s, *r, *t; char *s = md->cont;
s = md->cont;
if (s != NULL) if (s != NULL)
goto md_continue_here; goto md_continue_here;
@ -234,12 +232,14 @@ static int MyGetOpt(MyGetOptData *md)
md_continue_here:; md_continue_here:;
s++; s++;
if (*s != 0) { if (*s != 0) {
const char *r;
/* Found argument, try to locate it in options. */ /* Found argument, try to locate it in options. */
if (*s == ':' || (r = strchr(md->options, *s)) == NULL) { if (*s == ':' || (r = strchr(md->options, *s)) == NULL) {
/* ERROR! */ /* ERROR! */
return -2; return -2;
} }
if (r[1] == ':') { if (r[1] == ':') {
char *t;
/* Item wants an argument. Check if the argument follows, or if it comes as a separate arg. */ /* Item wants an argument. Check if the argument follows, or if it comes as a separate arg. */
if (!*(t = s + 1)) { if (!*(t = s + 1)) {
/* It comes as a separate arg. Check if out of args? */ /* It comes as a separate arg. Check if out of args? */
@ -253,7 +253,7 @@ md_continue_here:;
md->argv++; md->argv++;
} }
} }
md->opt = (char*)t; md->opt = t;
md->cont = NULL; md->cont = NULL;
return *s; return *s;
} }

View File

@ -130,7 +130,7 @@ void DrawRoadVehImage(const Vehicle *v, int x, int y, VehicleID selection, int c
int highlight_w = 0; int highlight_w = 0;
for (int dx = 0; v != NULL && dx < max_length ; v = v->Next()) { for (int dx = 0; v != NULL && dx < max_length ; v = v->Next()) {
int width = ((RoadVehicle *)v)->rcache.cached_veh_length; int width = ((const RoadVehicle *)v)->rcache.cached_veh_length;
if (dx + width > 0 && dx <= max_length) { if (dx + width > 0 && dx <= max_length) {
SpriteID pal = (v->vehstatus & VS_CRASHED) ? PALETTE_CRASH : GetVehiclePalette(v); SpriteID pal = (v->vehstatus & VS_CRASHED) ? PALETTE_CRASH : GetVehiclePalette(v);

View File

@ -26,7 +26,7 @@ ScreenshotType current_screenshot_type;
/* called by the ScreenShot proc to generate screenshot lines. */ /* called by the ScreenShot proc to generate screenshot lines. */
typedef void ScreenshotCallback(void *userdata, void *buf, uint y, uint pitch, uint n); typedef void ScreenshotCallback(void *userdata, void *buf, uint y, uint pitch, uint n);
typedef bool ScreenshotHandlerProc(const char *name, ScreenshotCallback *callb, void *userdata, uint w, uint h, int pixelformat, const Colour *palette); typedef bool ScreenshotHandlerProc(char *name, ScreenshotCallback *callb, void *userdata, uint w, uint h, int pixelformat, const Colour *palette);
struct ScreenshotFormat { struct ScreenshotFormat {
const char *name; const char *name;
@ -67,7 +67,7 @@ struct RgbQuad {
assert_compile(sizeof(RgbQuad) == 4); assert_compile(sizeof(RgbQuad) == 4);
/* generic .BMP writer */ /* generic .BMP writer */
static bool MakeBmpImage(const char *name, ScreenshotCallback *callb, void *userdata, uint w, uint h, int pixelformat, const Colour *palette) static bool MakeBmpImage(char *name, ScreenshotCallback *callb, void *userdata, uint w, uint h, int pixelformat, const Colour *palette)
{ {
BitmapFileHeader bfh; BitmapFileHeader bfh;
BitmapInfoHeader bih; BitmapInfoHeader bih;
@ -170,7 +170,7 @@ static void PNGAPI png_my_warning(png_structp png_ptr, png_const_charp message)
DEBUG(misc, 1, "[libpng] warning: %s - %s", message, (char *)png_get_error_ptr(png_ptr)); DEBUG(misc, 1, "[libpng] warning: %s - %s", message, (char *)png_get_error_ptr(png_ptr));
} }
static bool MakePNGImage(const char *name, ScreenshotCallback *callb, void *userdata, uint w, uint h, int pixelformat, const Colour *palette) static bool MakePNGImage(char *name, ScreenshotCallback *callb, void *userdata, uint w, uint h, int pixelformat, const Colour *palette)
{ {
png_color rq[256]; png_color rq[256];
FILE *f; FILE *f;
@ -186,7 +186,7 @@ static bool MakePNGImage(const char *name, ScreenshotCallback *callb, void *user
f = fopen(name, "wb"); f = fopen(name, "wb");
if (f == NULL) return false; if (f == NULL) return false;
png_ptr = png_create_write_struct(PNG_LIBPNG_VER_STRING, (char *)name, png_my_error, png_my_warning); png_ptr = png_create_write_struct(PNG_LIBPNG_VER_STRING, name, png_my_error, png_my_warning);
if (png_ptr == NULL) { if (png_ptr == NULL) {
fclose(f); fclose(f);
@ -299,7 +299,7 @@ struct PcxHeader {
}; };
assert_compile(sizeof(PcxHeader) == 128); assert_compile(sizeof(PcxHeader) == 128);
static bool MakePCXImage(const char *name, ScreenshotCallback *callb, void *userdata, uint w, uint h, int pixelformat, const Colour *palette) static bool MakePCXImage(char *name, ScreenshotCallback *callb, void *userdata, uint w, uint h, int pixelformat, const Colour *palette)
{ {
FILE *f; FILE *f;
uint maxlines; uint maxlines;

View File

@ -214,7 +214,7 @@ static bool load_intlist(const char *str, void *array, int nelems, VarType type)
static void make_intlist(char *buf, const char *last, const void *array, int nelems, VarType type) static void make_intlist(char *buf, const char *last, const void *array, int nelems, VarType type)
{ {
int i, v = 0; int i, v = 0;
const byte *p = (const byte*)array; byte *p = (byte*)array;
for (i = 0; i != nelems; i++) { for (i = 0; i != nelems; i++) {
switch (type) { switch (type) {

View File

@ -489,7 +489,7 @@ void *AllocSprite(size_t mem_req)
* @param available available sprite type * @param available available sprite type
* @return fallback sprite * @return fallback sprite
* @note this function will do usererror() in the case the fallback sprite isn't available */ * @note this function will do usererror() in the case the fallback sprite isn't available */
static const void *HandleInvalidSpriteRequest(SpriteID sprite, SpriteType requested, SpriteCache *sc) static void *HandleInvalidSpriteRequest(SpriteID sprite, SpriteType requested, SpriteCache *sc)
{ {
static const char *sprite_types[] = { static const char *sprite_types[] = {
"normal", // ST_NORMAL "normal", // ST_NORMAL
@ -525,7 +525,7 @@ static const void *HandleInvalidSpriteRequest(SpriteID sprite, SpriteType reques
} }
} }
const void *GetRawSprite(SpriteID sprite, SpriteType type) void *GetRawSprite(SpriteID sprite, SpriteType type)
{ {
assert(IsMapgenSpriteID(sprite) == (type == ST_MAPGEN)); assert(IsMapgenSpriteID(sprite) == (type == ST_MAPGEN));
assert(type < ST_INVALID); assert(type < ST_INVALID);

View File

@ -17,7 +17,7 @@ struct Sprite {
extern uint _sprite_cache_size; extern uint _sprite_cache_size;
const void *GetRawSprite(SpriteID sprite, SpriteType type); void *GetRawSprite(SpriteID sprite, SpriteType type);
bool SpriteExists(SpriteID sprite); bool SpriteExists(SpriteID sprite);
static inline const Sprite *GetSprite(SpriteID sprite, SpriteType type) static inline const Sprite *GetSprite(SpriteID sprite, SpriteType type)

View File

@ -1968,7 +1968,7 @@ static CommandCost RemoveAirport(Station *st, DoCommandFlag flags)
FOR_ALL_VEHICLES(v) { FOR_ALL_VEHICLES(v) {
if (!(v->type == VEH_AIRCRAFT && IsNormalAircraft(v))) continue; if (!(v->type == VEH_AIRCRAFT && IsNormalAircraft(v))) continue;
Aircraft *a = (Aircraft *)v; const Aircraft *a = (const Aircraft *)v;
if (a->targetairport == st->index && a->state != FLYING) return CMD_ERROR; if (a->targetairport == st->index && a->state != FLYING) return CMD_ERROR;
} }

View File

@ -208,11 +208,11 @@ static inline bool IsUtf8Part(char c)
* @note The function should not be used to determine the length of the previous * @note The function should not be used to determine the length of the previous
* encoded char because it might be an invalid/corrupt start-sequence * encoded char because it might be an invalid/corrupt start-sequence
*/ */
static inline char *Utf8PrevChar(const char *s) static inline char *Utf8PrevChar(char *s)
{ {
const char *ret = s; char *ret = s;
while (IsUtf8Part(*--ret)) {} while (IsUtf8Part(*--ret)) {}
return (char*)ret; return ret;
} }

View File

@ -40,9 +40,9 @@ uint64 _decode_parameters[20];
static char *StationGetSpecialString(char *buff, int x, const char *last); static char *StationGetSpecialString(char *buff, int x, const char *last);
static char *GetSpecialTownNameString(char *buff, int ind, uint32 seed, const char *last); static char *GetSpecialTownNameString(char *buff, int ind, uint32 seed, const char *last);
static char *GetSpecialNameString(char *buff, int ind, const int64 *argv, const char *last); static char *GetSpecialNameString(char *buff, int ind, int64 *argv, const char *last);
static char *FormatString(char *buff, const char *str, const int64 *argv, uint casei, const char *last); static char *FormatString(char *buff, const char *str, int64 *argv, uint casei, const char *last);
struct LanguagePack : public LanguagePackHeader { struct LanguagePack : public LanguagePackHeader {
char data[VARARRAY_SIZE]; // list of strings char data[VARARRAY_SIZE]; // list of strings
@ -55,22 +55,22 @@ static uint _langtab_start[32]; // Offset into langpack offs
/** Read an int64 from the argv array. */ /** Read an int64 from the argv array. */
static inline int64 GetInt64(const int64 **argv) static inline int64 GetInt64(int64 **argv)
{ {
assert(argv); assert(argv);
return *(*argv)++; return *(*argv)++;
} }
/** Read an int32 from the argv array. */ /** Read an int32 from the argv array. */
static inline int32 GetInt32(const int64 **argv) static inline int32 GetInt32(int64 **argv)
{ {
return (int32)GetInt64(argv); return (int32)GetInt64(argv);
} }
/** Read an array from the argv array. */ /** Read an array from the argv array. */
static inline const int64 *GetArgvPtr(const int64 **argv, int n) static inline int64 *GetArgvPtr(int64 **argv, int n)
{ {
const int64 *result; int64 *result;
assert(*argv); assert(*argv);
result = *argv; result = *argv;
(*argv) += n; (*argv) += n;
@ -98,7 +98,7 @@ const char *GetStringPtr(StringID string)
* @param last * @param last
* @return a formatted string of char * @return a formatted string of char
*/ */
static char *GetStringWithArgs(char *buffr, uint string, const int64 *argv, const char *last) static char *GetStringWithArgs(char *buffr, uint string, int64 *argv, const char *last)
{ {
if (GB(string, 0, 16) == 0) return GetStringWithArgs(buffr, STR_UNDEFINED, argv, last); if (GB(string, 0, 16) == 0) return GetStringWithArgs(buffr, STR_UNDEFINED, argv, last);
@ -517,16 +517,16 @@ uint ConvertDisplaySpeedToSpeed(uint speed)
return ((speed << units[_settings_game.locale.units].s_s) + units[_settings_game.locale.units].s_m / 2) / units[_settings_game.locale.units].s_m; return ((speed << units[_settings_game.locale.units].s_s) + units[_settings_game.locale.units].s_m / 2) / units[_settings_game.locale.units].s_m;
} }
static char *FormatString(char *buff, const char *str, const int64 *argv, uint casei, const char *last) static char *FormatString(char *buff, const char *str, int64 *argv, uint casei, const char *last)
{ {
WChar b; WChar b;
const int64 *argv_orig = argv; int64 *argv_orig = argv;
uint modifier = 0; uint modifier = 0;
while ((b = Utf8Consume(&str)) != '\0') { while ((b = Utf8Consume(&str)) != '\0') {
if (SCC_NEWGRF_FIRST <= b && b <= SCC_NEWGRF_LAST) { if (SCC_NEWGRF_FIRST <= b && b <= SCC_NEWGRF_LAST) {
/* We need to pass some stuff as it might be modified; oh boy. */ /* We need to pass some stuff as it might be modified; oh boy. */
b = RemapNewGRFStringControlCode(b, &buff, &str, (int64*)argv); b = RemapNewGRFStringControlCode(b, &buff, &str, argv);
if (b == 0) continue; if (b == 0) continue;
} }
@ -1177,7 +1177,7 @@ static char *GenPresidentName(char *buff, uint32 x, const char *last)
return buff; return buff;
} }
static char *GetSpecialNameString(char *buff, int ind, const int64 *argv, const char *last) static char *GetSpecialNameString(char *buff, int ind, int64 *argv, const char *last)
{ {
switch (ind) { switch (ind) {
case 1: // not used case 1: // not used

View File

@ -189,7 +189,7 @@ void CheckTrainsLengths()
FOR_ALL_VEHICLES(v) { FOR_ALL_VEHICLES(v) {
if (v->type == VEH_TRAIN && v->First() == v && !(v->vehstatus & VS_CRASHED)) { if (v->type == VEH_TRAIN && v->First() == v && !(v->vehstatus & VS_CRASHED)) {
for (const Train *u = (Train *)v, *w = (Train *)v->Next(); w != NULL; u = w, w = w->Next()) { for (const Train *u = (const Train *)v, *w = (const Train *)v->Next(); w != NULL; u = w, w = w->Next()) {
if (u->track != TRACK_BIT_DEPOT) { if (u->track != TRACK_BIT_DEPOT) {
if ((w->track != TRACK_BIT_DEPOT && if ((w->track != TRACK_BIT_DEPOT &&
max(abs(u->x_pos - w->x_pos), abs(u->y_pos - w->y_pos)) != u->tcache.cached_veh_length) || max(abs(u->x_pos - w->x_pos), abs(u->y_pos - w->y_pos)) != u->tcache.cached_veh_length) ||
@ -732,7 +732,7 @@ static void NormalizeTrainVehInDepot(const Train *u)
FOR_ALL_VEHICLES(v) { FOR_ALL_VEHICLES(v) {
if (v->type == VEH_TRAIN && IsFreeWagon(v) && if (v->type == VEH_TRAIN && IsFreeWagon(v) &&
v->tile == u->tile && v->tile == u->tile &&
((Train *)v)->track == TRACK_BIT_DEPOT) { ((const Train *)v)->track == TRACK_BIT_DEPOT) {
if (CmdFailed(DoCommand(0, v->index | (u->index << 16), 1, DC_EXEC, if (CmdFailed(DoCommand(0, v->index | (u->index << 16), 1, DC_EXEC,
CMD_MOVE_RAIL_VEHICLE))) CMD_MOVE_RAIL_VEHICLE)))
break; break;
@ -3572,8 +3572,8 @@ static Vehicle *FindTrainCollideEnum(Vehicle *v, void *data)
* As there might be more than two trains involved, we have to do that for all vehicles */ * As there might be more than two trains involved, we have to do that for all vehicles */
const Vehicle *u; const Vehicle *u;
FOR_ALL_VEHICLES(u) { FOR_ALL_VEHICLES(u) {
if (u->type == VEH_TRAIN && HASBITS(u->vehstatus, VS_CRASHED) && (((Train *)u)->track & TRACK_BIT_DEPOT) == TRACK_BIT_NONE) { if (u->type == VEH_TRAIN && HASBITS(u->vehstatus, VS_CRASHED) && (((const Train *)u)->track & TRACK_BIT_DEPOT) == TRACK_BIT_NONE) {
TrackBits trackbits = ((Train *)u)->track; TrackBits trackbits = ((const Train *)u)->track;
if ((trackbits & TRACK_BIT_WORMHOLE) == TRACK_BIT_WORMHOLE) { if ((trackbits & TRACK_BIT_WORMHOLE) == TRACK_BIT_WORMHOLE) {
/* Vehicle is inside a wormhole, v->track contains no useful value then. */ /* Vehicle is inside a wormhole, v->track contains no useful value then. */
trackbits |= DiagDirToDiagTrackBits(GetTunnelBridgeDirection(u->tile)); trackbits |= DiagDirToDiagTrackBits(GetTunnelBridgeDirection(u->tile));

View File

@ -28,7 +28,7 @@ void CcBuildWagon(bool success, TileIndex tile, uint32 p1, uint32 p2)
FOR_ALL_VEHICLES(v) { FOR_ALL_VEHICLES(v) {
if (v->type == VEH_TRAIN && IsFrontEngine(v) && if (v->type == VEH_TRAIN && IsFrontEngine(v) &&
v->tile == tile && v->tile == tile &&
((Train *)v)->track == TRACK_BIT_DEPOT) { ((const Train *)v)->track == TRACK_BIT_DEPOT) {
if (found != NULL) return; // must be exactly one. if (found != NULL) return; // must be exactly one.
found = v; found = v;
} }
@ -81,7 +81,7 @@ void DrawTrainImage(const Vehicle *v, int x, int y, VehicleID selection, int cou
_cur_dpi = &tmp_dpi; _cur_dpi = &tmp_dpi;
do { do {
int width = ((Train *)v)->tcache.cached_veh_length; int width = ((const Train *)v)->tcache.cached_veh_length;
if (dx + width > 0) { if (dx + width > 0) {
if (dx <= count) { if (dx <= count) {
@ -228,7 +228,7 @@ void DrawTrainDetails(const Vehicle *v, int left, int right, int y, int vscroll_
do { do {
SpriteID pal = (v->vehstatus & VS_CRASHED) ? PALETTE_CRASH : GetVehiclePalette(v); SpriteID pal = (v->vehstatus & VS_CRASHED) ? PALETTE_CRASH : GetVehiclePalette(v);
DrawSprite(u->GetImage(DIR_W), pal, x + WagonLengthToPixels(4 + dx), y + 6 + (is_custom_sprite(RailVehInfo(u->engine_type)->image_index) ? _traininfo_vehicle_pitch : 0)); DrawSprite(u->GetImage(DIR_W), pal, x + WagonLengthToPixels(4 + dx), y + 6 + (is_custom_sprite(RailVehInfo(u->engine_type)->image_index) ? _traininfo_vehicle_pitch : 0));
dx += ((Train *)u)->tcache.cached_veh_length; dx += ((const Train *)u)->tcache.cached_veh_length;
u = u->Next(); u = u->Next();
} while (u != NULL && IsArticulatedPart(u) && u->cargo_cap == 0); } while (u != NULL && IsArticulatedPart(u) && u->cargo_cap == 0);

View File

@ -1424,9 +1424,9 @@ SpriteID GetEnginePalette(EngineID engine_type, CompanyID company)
SpriteID GetVehiclePalette(const Vehicle *v) SpriteID GetVehiclePalette(const Vehicle *v)
{ {
if (v->type == VEH_TRAIN) { if (v->type == VEH_TRAIN) {
return GetEngineColourMap(v->engine_type, v->owner, ((Train *)v)->tcache.first_engine, v); return GetEngineColourMap(v->engine_type, v->owner, ((const Train *)v)->tcache.first_engine, v);
} else if (v->type == VEH_ROAD) { } else if (v->type == VEH_ROAD) {
return GetEngineColourMap(v->engine_type, v->owner, ((RoadVehicle *)v)->rcache.first_engine, v); return GetEngineColourMap(v->engine_type, v->owner, ((const RoadVehicle *)v)->rcache.first_engine, v);
} }
return GetEngineColourMap(v->engine_type, v->owner, INVALID_ENGINE, v); return GetEngineColourMap(v->engine_type, v->owner, INVALID_ENGINE, v);
@ -1742,7 +1742,7 @@ bool CanVehicleUseStation(EngineID engine_type, const Station *st)
*/ */
bool CanVehicleUseStation(const Vehicle *v, const Station *st) bool CanVehicleUseStation(const Vehicle *v, const Station *st)
{ {
if (v->type == VEH_ROAD) return st->GetPrimaryRoadStop((RoadVehicle *)v) != NULL; if (v->type == VEH_ROAD) return st->GetPrimaryRoadStop((const RoadVehicle *)v) != NULL;
return CanVehicleUseStation(v->engine_type, st); return CanVehicleUseStation(v->engine_type, st);
} }

View File

@ -152,7 +152,7 @@ CommandCost CmdMassStartStopVehicle(TileIndex tile, DoCommandFlag flags, uint32
if (!vehicle_list_window) { if (!vehicle_list_window) {
if (vehicle_type == VEH_TRAIN) { if (vehicle_type == VEH_TRAIN) {
if (CheckTrainInDepot((Train *)v, false) == -1) continue; if (CheckTrainInDepot((const Train *)v, false) == -1) continue;
} else { } else {
if (!(v->vehstatus & VS_HIDDEN)) continue; if (!(v->vehstatus & VS_HIDDEN)) continue;
} }
@ -229,7 +229,7 @@ CommandCost CmdDepotMassAutoReplace(TileIndex tile, DoCommandFlag flags, uint32
bool did_something = false; bool did_something = false;
for (uint i = 0; i < list.Length(); i++) { for (uint i = 0; i < list.Length(); i++) {
Vehicle *v = (Vehicle*)list[i]; const Vehicle *v = list[i];
/* Ensure that the vehicle completely in the depot */ /* Ensure that the vehicle completely in the depot */
if (!v->IsInDepot()) continue; if (!v->IsInDepot()) continue;

View File

@ -641,8 +641,8 @@ static int CDECL VehicleLengthSorter(const Vehicle * const *a, const Vehicle * c
case VEH_ROAD: { case VEH_ROAD: {
const RoadVehicle *u; const RoadVehicle *u;
for (u = (RoadVehicle *)*a; u != NULL; u = u->Next()) r += u->rcache.cached_veh_length; for (u = (const RoadVehicle *)*a; u != NULL; u = u->Next()) r += u->rcache.cached_veh_length;
for (u = (RoadVehicle *)*b; u != NULL; u = u->Next()) r -= u->rcache.cached_veh_length; for (u = (const RoadVehicle *)*b; u != NULL; u = u->Next()) r -= u->rcache.cached_veh_length;
} break; } break;
default: NOT_REACHED(); default: NOT_REACHED();
@ -1466,10 +1466,10 @@ struct VehicleDetailsWindow : Window {
switch (v->type) { switch (v->type) {
case VEH_TRAIN: case VEH_TRAIN:
SetDParam(2, v->GetDisplayMaxSpeed()); SetDParam(2, v->GetDisplayMaxSpeed());
SetDParam(1, ((Train *)v)->tcache.cached_power); SetDParam(1, ((const Train *)v)->tcache.cached_power);
SetDParam(0, ((Train *)v)->tcache.cached_weight); SetDParam(0, ((const Train *)v)->tcache.cached_weight);
SetDParam(3, ((Train *)v)->tcache.cached_max_te / 1000); SetDParam(3, ((const Train *)v)->tcache.cached_max_te / 1000);
DrawString(2, this->width - 2, 25, (_settings_game.vehicle.train_acceleration_model != TAM_ORIGINAL && ((Train *)v)->railtype != RAILTYPE_MAGLEV) ? DrawString(2, this->width - 2, 25, (_settings_game.vehicle.train_acceleration_model != TAM_ORIGINAL && ((const Train *)v)->railtype != RAILTYPE_MAGLEV) ?
STR_VEHICLE_INFO_WEIGHT_POWER_MAX_SPEED_MAX_TE : STR_VEHICLE_INFO_WEIGHT_POWER_MAX_SPEED_MAX_TE :
STR_VEHICLE_INFO_WEIGHT_POWER_MAX_SPEED); STR_VEHICLE_INFO_WEIGHT_POWER_MAX_SPEED);
break; break;
@ -1937,7 +1937,7 @@ struct VehicleViewWindow : Window {
} else if (v->vehstatus & VS_STOPPED) { } else if (v->vehstatus & VS_STOPPED) {
if (v->type == VEH_TRAIN) { if (v->type == VEH_TRAIN) {
if (v->cur_speed == 0) { if (v->cur_speed == 0) {
if (((Train *)v)->tcache.cached_power == 0) { if (((const Train *)v)->tcache.cached_power == 0) {
str = STR_TRAIN_NO_POWER; str = STR_TRAIN_NO_POWER;
} else { } else {
str = STR_VEHICLE_STATUS_STOPPED; str = STR_VEHICLE_STATUS_STOPPED;
@ -1949,7 +1949,7 @@ struct VehicleViewWindow : Window {
} else { // no train } else { // no train
str = STR_VEHICLE_STATUS_STOPPED; str = STR_VEHICLE_STATUS_STOPPED;
} }
} else if (v->type == VEH_TRAIN && HasBit(((Train *)v)->flags, VRF_TRAIN_STUCK)) { } else if (v->type == VEH_TRAIN && HasBit(((const Train *)v)->flags, VRF_TRAIN_STUCK)) {
str = STR_TRAIN_STUCK; str = STR_TRAIN_STUCK;
} else { // vehicle is in a "normal" state, show current order } else { // vehicle is in a "normal" state, show current order
switch (v->current_order.GetType()) { switch (v->current_order.GetType()) {

View File

@ -29,7 +29,7 @@ void BuildDepotVehicleList(VehicleType type, TileIndex tile, VehicleList *engine
switch (type) { switch (type) {
case VEH_TRAIN: case VEH_TRAIN:
if (IsArticulatedPart(v) || IsRearDualheaded(v)) continue; if (IsArticulatedPart(v) || IsRearDualheaded(v)) continue;
if (((Train *)v)->track != TRACK_BIT_DEPOT) continue; if (((const Train *)v)->track != TRACK_BIT_DEPOT) continue;
if (wagons != NULL && IsFreeWagon(v->First())) { if (wagons != NULL && IsFreeWagon(v->First())) {
if (individual_wagons || IsFreeWagon(v)) *wagons->Append() = v; if (individual_wagons || IsFreeWagon(v)) *wagons->Append() = v;
continue; continue;

View File

@ -55,7 +55,7 @@ struct CFollowTrackT
{ {
assert(!IsRailTT() || (v != NULL && v->type == VEH_TRAIN)); assert(!IsRailTT() || (v != NULL && v->type == VEH_TRAIN));
m_veh = v; m_veh = v;
Init(v != NULL ? v->owner : INVALID_OWNER, railtype_override == INVALID_RAILTYPES ? ((Train *)v)->compatible_railtypes : railtype_override, pPerf); Init(v != NULL ? v->owner : INVALID_OWNER, railtype_override == INVALID_RAILTYPES ? ((const Train *)v)->compatible_railtypes : railtype_override, pPerf);
} }
FORCEINLINE void Init(Owner o, RailTypes railtype_override, CPerformanceTimer *pPerf) FORCEINLINE void Init(Owner o, RailTypes railtype_override, CPerformanceTimer *pPerf)
@ -76,7 +76,7 @@ struct CFollowTrackT
FORCEINLINE static TransportType TT() {return Ttr_type_;} FORCEINLINE static TransportType TT() {return Ttr_type_;}
FORCEINLINE static bool IsWaterTT() {return TT() == TRANSPORT_WATER;} FORCEINLINE static bool IsWaterTT() {return TT() == TRANSPORT_WATER;}
FORCEINLINE static bool IsRailTT() {return TT() == TRANSPORT_RAIL;} FORCEINLINE static bool IsRailTT() {return TT() == TRANSPORT_RAIL;}
FORCEINLINE bool IsTram() {return IsRoadTT() && HasBit(((RoadVehicle *)m_veh)->compatible_roadtypes, ROADTYPE_TRAM);} FORCEINLINE bool IsTram() {return IsRoadTT() && HasBit(((const RoadVehicle *)m_veh)->compatible_roadtypes, ROADTYPE_TRAM);}
FORCEINLINE static bool IsRoadTT() {return TT() == TRANSPORT_ROAD;} FORCEINLINE static bool IsRoadTT() {return TT() == TRANSPORT_ROAD;}
FORCEINLINE static bool Allow90degTurns() {return T90deg_turns_allowed_;} FORCEINLINE static bool Allow90degTurns() {return T90deg_turns_allowed_;}
FORCEINLINE static bool DoTrackMasking() {return IsRailTT() && Tmask_reserved_tracks;} FORCEINLINE static bool DoTrackMasking() {return IsRailTT() && Tmask_reserved_tracks;}
@ -106,7 +106,7 @@ struct CFollowTrackT
m_old_tile = old_tile; m_old_tile = old_tile;
m_old_td = old_td; m_old_td = old_td;
m_err = EC_NONE; m_err = EC_NONE;
assert(((TrackStatusToTrackdirBits(GetTileTrackStatus(m_old_tile, TT(), m_veh ? ((RoadVehicle *)m_veh)->compatible_roadtypes : 0)) & TrackdirToTrackdirBits(m_old_td)) != 0) || assert(((TrackStatusToTrackdirBits(GetTileTrackStatus(m_old_tile, TT(), m_veh ? ((const RoadVehicle *)m_veh)->compatible_roadtypes : 0)) & TrackdirToTrackdirBits(m_old_td)) != 0) ||
(IsTram() && GetSingleTramBit(m_old_tile) != INVALID_DIAGDIR)); // Disable the assertion for single tram bits (IsTram() && GetSingleTramBit(m_old_tile) != INVALID_DIAGDIR)); // Disable the assertion for single tram bits
m_exitdir = TrackdirToExitdir(m_old_td); m_exitdir = TrackdirToExitdir(m_old_td);
if (ForcedReverse()) return true; if (ForcedReverse()) return true;
@ -207,7 +207,7 @@ protected:
if (IsRailTT() && IsPlainRailTile(m_new_tile)) { if (IsRailTT() && IsPlainRailTile(m_new_tile)) {
m_new_td_bits = (TrackdirBits)(GetTrackBits(m_new_tile) * 0x101); m_new_td_bits = (TrackdirBits)(GetTrackBits(m_new_tile) * 0x101);
} else { } else {
m_new_td_bits = TrackStatusToTrackdirBits(GetTileTrackStatus(m_new_tile, TT(), m_veh != NULL ? ((RoadVehicle *)m_veh)->compatible_roadtypes : 0)); m_new_td_bits = TrackStatusToTrackdirBits(GetTileTrackStatus(m_new_tile, TT(), m_veh != NULL ? ((const RoadVehicle *)m_veh)->compatible_roadtypes : 0));
if (IsTram() && m_new_td_bits == 0) { if (IsTram() && m_new_td_bits == 0) {
/* GetTileTrackStatus() returns 0 for single tram bits. /* GetTileTrackStatus() returns 0 for single tram bits.

View File

@ -247,8 +247,8 @@ public:
const Vehicle *v = Yapf().GetVehicle(); const Vehicle *v = Yapf().GetVehicle();
assert(v != NULL); assert(v != NULL);
assert(v->type == VEH_TRAIN); assert(v->type == VEH_TRAIN);
assert(((Train *)v)->tcache.cached_total_length != 0); assert(((const Train *)v)->tcache.cached_total_length != 0);
int missing_platform_length = (((Train *)v)->tcache.cached_total_length + TILE_SIZE - 1) / TILE_SIZE - platform_length; int missing_platform_length = (((const Train *)v)->tcache.cached_total_length + TILE_SIZE - 1) / TILE_SIZE - platform_length;
if (missing_platform_length < 0) { if (missing_platform_length < 0) {
/* apply penalty for longer platform than needed */ /* apply penalty for longer platform than needed */
cost += Yapf().PfGetSettings().rail_longer_platform_penalty + Yapf().PfGetSettings().rail_longer_platform_per_tile_penalty * -missing_platform_length; cost += Yapf().PfGetSettings().rail_longer_platform_penalty + Yapf().PfGetSettings().rail_longer_platform_per_tile_penalty * -missing_platform_length;

View File

@ -13,8 +13,8 @@ protected:
public: public:
void SetDestination(const Vehicle *v, bool override_rail_type = false) void SetDestination(const Vehicle *v, bool override_rail_type = false)
{ {
m_compatible_railtypes = ((Train *)v)->compatible_railtypes; m_compatible_railtypes = ((const Train *)v)->compatible_railtypes;
if (override_rail_type) m_compatible_railtypes |= GetRailTypeInfo(((Train *)v)->railtype)->compatible_railtypes; if (override_rail_type) m_compatible_railtypes |= GetRailTypeInfo(((const Train *)v)->railtype)->compatible_railtypes;
} }
bool IsCompatibleRailType(RailType rt) bool IsCompatibleRailType(RailType rt)
@ -91,8 +91,8 @@ public:
FORCEINLINE bool PfDetectDestination(TileIndex tile, Trackdir td) FORCEINLINE bool PfDetectDestination(TileIndex tile, Trackdir td)
{ {
return return
IsSafeWaitingPosition((Train *)Yapf().GetVehicle(), tile, td, true, !TrackFollower::Allow90degTurns()) && IsSafeWaitingPosition((const Train *)Yapf().GetVehicle(), tile, td, true, !TrackFollower::Allow90degTurns()) &&
IsWaitingPositionFree((Train *)Yapf().GetVehicle(), tile, td, !TrackFollower::Allow90degTurns()); IsWaitingPositionFree((const Train *)Yapf().GetVehicle(), tile, td, !TrackFollower::Allow90degTurns());
} }
/** Called by YAPF to calculate cost estimate. Calculates distance to the destination /** Called by YAPF to calculate cost estimate. Calculates distance to the destination

View File

@ -54,7 +54,7 @@ private:
bool FindSafePositionProc(TileIndex tile, Trackdir td) bool FindSafePositionProc(TileIndex tile, Trackdir td)
{ {
if (IsSafeWaitingPosition((Train *)Yapf().GetVehicle(), tile, td, true, !TrackFollower::Allow90degTurns())) { if (IsSafeWaitingPosition((const Train *)Yapf().GetVehicle(), tile, td, true, !TrackFollower::Allow90degTurns())) {
m_res_dest = tile; m_res_dest = tile;
m_res_dest_td = td; m_res_dest_td = td;
return false; // Stop iterating segment return false; // Stop iterating segment
@ -149,7 +149,7 @@ public:
} }
/* Don't bother if the target is reserved. */ /* Don't bother if the target is reserved. */
if (!IsWaitingPositionFree((Train *)Yapf().GetVehicle(), m_res_dest, m_res_dest_td)) return false; if (!IsWaitingPositionFree((const Train *)Yapf().GetVehicle(), m_res_dest, m_res_dest_td)) return false;
for (Node *node = m_res_node; node->m_parent != NULL; node = node->m_parent) { for (Node *node = m_res_node; node->m_parent != NULL; node = node->m_parent) {
node->IterateTiles(Yapf().GetVehicle(), Yapf(), *this, &CYapfReserveTrack<Types>::ReserveSingleTrack); node->IterateTiles(Yapf().GetVehicle(), Yapf(), *this, &CYapfReserveTrack<Types>::ReserveSingleTrack);
@ -411,7 +411,7 @@ public:
if (target != NULL) target->tile = INVALID_TILE; if (target != NULL) target->tile = INVALID_TILE;
/* set origin and destination nodes */ /* set origin and destination nodes */
PBSTileInfo origin = FollowTrainReservation((Train *)v); PBSTileInfo origin = FollowTrainReservation((const Train *)v);
Yapf().SetOrigin(origin.tile, origin.trackdir, INVALID_TILE, INVALID_TRACKDIR, 1, true); Yapf().SetOrigin(origin.tile, origin.trackdir, INVALID_TILE, INVALID_TRACKDIR, 1, true);
Yapf().SetDestination(v); Yapf().SetDestination(v);
@ -536,9 +536,9 @@ Trackdir YapfChooseRailTrack(const Vehicle *v, TileIndex tile, DiagDirection ent
bool YapfCheckReverseTrain(const Vehicle *vt) bool YapfCheckReverseTrain(const Vehicle *vt)
{ {
Train *v = (Train *)vt; const Train *v = (const Train *)vt;
/* last wagon */ /* last wagon */
const Train *last_veh = (Train *)GetLastVehicleInChain(v); const Train *last_veh = (const Train *)GetLastVehicleInChain(v);
/* get trackdirs of both ends */ /* get trackdirs of both ends */
Trackdir td = v->GetVehicleTrackdir(); Trackdir td = v->GetVehicleTrackdir();
@ -602,7 +602,7 @@ bool YapfFindNearestRailDepotTwoWay(const Vehicle *v, int max_distance, int reve
const Vehicle *last_veh = GetLastVehicleInChain(v); const Vehicle *last_veh = GetLastVehicleInChain(v);
PBSTileInfo origin = FollowTrainReservation((Train *)v); PBSTileInfo origin = FollowTrainReservation((const Train *)v);
TileIndex last_tile = last_veh->tile; TileIndex last_tile = last_veh->tile;
Trackdir td_rev = ReverseTrackdir(last_veh->GetVehicleTrackdir()); Trackdir td_rev = ReverseTrackdir(last_veh->GetVehicleTrackdir());

View File

@ -299,13 +299,13 @@ public:
/* our source tile will be the next vehicle tile (should be the given one) */ /* our source tile will be the next vehicle tile (should be the given one) */
TileIndex src_tile = tile; TileIndex src_tile = tile;
/* get available trackdirs on the start tile */ /* get available trackdirs on the start tile */
TrackdirBits src_trackdirs = TrackStatusToTrackdirBits(GetTileTrackStatus(tile, TRANSPORT_ROAD, ((RoadVehicle *)v)->compatible_roadtypes)); TrackdirBits src_trackdirs = TrackStatusToTrackdirBits(GetTileTrackStatus(tile, TRANSPORT_ROAD, ((const RoadVehicle *)v)->compatible_roadtypes));
/* select reachable trackdirs only */ /* select reachable trackdirs only */
src_trackdirs &= DiagdirReachesTrackdirs(enterdir); src_trackdirs &= DiagdirReachesTrackdirs(enterdir);
/* get available trackdirs on the destination tile */ /* get available trackdirs on the destination tile */
TileIndex dest_tile = v->dest_tile; TileIndex dest_tile = v->dest_tile;
TrackdirBits dest_trackdirs = TrackStatusToTrackdirBits(GetTileTrackStatus(dest_tile, TRANSPORT_ROAD, ((RoadVehicle *)v)->compatible_roadtypes)); TrackdirBits dest_trackdirs = TrackStatusToTrackdirBits(GetTileTrackStatus(dest_tile, TRANSPORT_ROAD, ((const RoadVehicle *)v)->compatible_roadtypes));
/* set origin and destination nodes */ /* set origin and destination nodes */
Yapf().SetOrigin(src_tile, src_trackdirs); Yapf().SetOrigin(src_tile, src_trackdirs);
@ -349,7 +349,7 @@ public:
/* set destination tile, trackdir /* set destination tile, trackdir
* get available trackdirs on the destination tile */ * get available trackdirs on the destination tile */
TrackdirBits dst_td_bits = TrackStatusToTrackdirBits(GetTileTrackStatus(dst_tile, TRANSPORT_ROAD, ((RoadVehicle *)v)->compatible_roadtypes)); TrackdirBits dst_td_bits = TrackStatusToTrackdirBits(GetTileTrackStatus(dst_tile, TRANSPORT_ROAD, ((const RoadVehicle *)v)->compatible_roadtypes));
Yapf().SetDestination(dst_tile, dst_td_bits); Yapf().SetDestination(dst_tile, dst_td_bits);
/* if path not found - return distance = UINT_MAX */ /* if path not found - return distance = UINT_MAX */
@ -374,7 +374,7 @@ public:
/* set origin (tile, trackdir) */ /* set origin (tile, trackdir) */
TileIndex src_tile = v->tile; TileIndex src_tile = v->tile;
Trackdir src_td = v->GetVehicleTrackdir(); Trackdir src_td = v->GetVehicleTrackdir();
if ((TrackStatusToTrackdirBits(GetTileTrackStatus(src_tile, TRANSPORT_ROAD, ((RoadVehicle *)v)->compatible_roadtypes)) & TrackdirToTrackdirBits(src_td)) == 0) { if ((TrackStatusToTrackdirBits(GetTileTrackStatus(src_tile, TRANSPORT_ROAD, ((const RoadVehicle *)v)->compatible_roadtypes)) & TrackdirToTrackdirBits(src_td)) == 0) {
/* sometimes the roadveh is not on the road (it resides on non-existing track) /* sometimes the roadveh is not on the road (it resides on non-existing track)
* how should we handle that situation? */ * how should we handle that situation? */
return false; return false;
@ -471,7 +471,7 @@ Depot *YapfFindNearestRoadDepot(const Vehicle *v)
{ {
TileIndex tile = v->tile; TileIndex tile = v->tile;
Trackdir trackdir = v->GetVehicleTrackdir(); Trackdir trackdir = v->GetVehicleTrackdir();
if ((TrackStatusToTrackdirBits(GetTileTrackStatus(tile, TRANSPORT_ROAD, ((RoadVehicle *)v)->compatible_roadtypes)) & TrackdirToTrackdirBits(trackdir)) == 0) { if ((TrackStatusToTrackdirBits(GetTileTrackStatus(tile, TRANSPORT_ROAD, ((const RoadVehicle *)v)->compatible_roadtypes)) & TrackdirToTrackdirBits(trackdir)) == 0) {
return NULL; return NULL;
} }