/* static */ char *AIRail::GetName(RailType rail_type) { if (!IsRailTypeAvailable(rail_type)) return NULL; static const int len = 64; char *railtype_name = MallocT<char>(len); ::GetString(railtype_name, GetRailTypeInfo((::RailType)rail_type)->strings.menu_text, &railtype_name[len - 1]); return railtype_name; }
static void Save_RAIL() { LabelObject lo; for (RailType r = RAILTYPE_BEGIN; r != RAILTYPE_END; r++) { lo.label = GetRailTypeInfo(r)->label; SlSetArrayIndex(r); SlObject(&lo, _label_object_desc); } }
/** * Return the category of an engine. * @param engine Engine to examine. * @return String describing the category ("road veh", "train". "airplane", or "ship") of the engine. */ StringID GetEngineCategoryName(EngineID engine) { const Engine *e = Engine::Get(engine); switch (e->type) { default: NOT_REACHED(); case VEH_ROAD: return STR_ENGINE_PREVIEW_ROAD_VEHICLE; case VEH_AIRCRAFT: return STR_ENGINE_PREVIEW_AIRCRAFT; case VEH_SHIP: return STR_ENGINE_PREVIEW_SHIP; case VEH_TRAIN: return GetRailTypeInfo(e->u.rail.railtype)->strings.new_loco; } }
/** * Checks some basic properties whether autoreplace is allowed * @param from Origin engine * @param to Destination engine * @param company Company to check for * @return true if autoreplace is allowed */ bool CheckAutoreplaceValidity(EngineID from, EngineID to, CompanyID company) { assert(Engine::IsValidID(from) && Engine::IsValidID(to)); /* we can't replace an engine into itself (that would be autorenew) */ if (from == to) return false; const Engine *e_from = Engine::Get(from); const Engine *e_to = Engine::Get(to); VehicleType type = e_from->type; /* check that the new vehicle type is available to the company and its type is the same as the original one */ if (!IsEngineBuildable(to, type, company)) return false; switch (type) { case VEH_TRAIN: { /* make sure the railtypes are compatible */ if ((GetRailTypeInfo(e_from->u.rail.railtype)->compatible_railtypes & GetRailTypeInfo(e_to->u.rail.railtype)->compatible_railtypes) == 0) return false; /* make sure we do not replace wagons with engines or vise versa */ if ((e_from->u.rail.railveh_type == RAILVEH_WAGON) != (e_to->u.rail.railveh_type == RAILVEH_WAGON)) return false; break; } case VEH_ROAD: /* make sure that we do not replace a tram with a normal road vehicles or vise versa */ if (HasBit(e_from->info.misc_flags, EF_ROAD_TRAM) != HasBit(e_to->info.misc_flags, EF_ROAD_TRAM)) return false; break; case VEH_AIRCRAFT: /* make sure that we do not replace a plane with a helicopter or vise versa */ if ((e_from->u.air.subtype & AIR_CTOL) != (e_to->u.air.subtype & AIR_CTOL)) return false; break; default: break; } /* the engines needs to be able to carry the same cargo */ return EnginesHaveCargoInCommon(from, to); }
/** * Perform a reverse railtype lookup to get the GRF internal ID. * @param railtype The global (OpenTTD) railtype. * @param grffile The GRF to do the lookup for. * @return the GRF internal ID. */ uint8 GetReverseRailTypeTranslation(RailType railtype, const GRFFile *grffile) { /* No rail type table present, return rail type as-is */ if (grffile == NULL || grffile->railtype_list.Length() == 0) return railtype; /* Look for a matching rail type label in the table */ RailTypeLabel label = GetRailTypeInfo(railtype)->label; int index = grffile->railtype_list.FindIndex(label); if (index >= 0) return index; /* If not found, return as invalid */ return 0xFF; }
uint8 GetReverseRailTypeTranslation(RailType railtype, const GRFFile *grffile) { /* No rail type table present, return rail type as-is */ if (grffile == NULL || grffile->railtype_max == 0) return railtype; /* Look for a matching rail type label in the table */ RailTypeLabel label = GetRailTypeInfo(railtype)->label; for (uint i = 0; i < grffile->railtype_max; i++) { if (label == grffile->railtype_list[i]) return i; } /* If not found, return as invalid */ return 0xFF; }
/** * Test if any saved rail type labels are different to the currently loaded * rail types, which therefore requires conversion. * @return true if (and only if) conversion due to rail type changes is needed. */ static bool NeedRailTypeConversion() { for (uint i = 0; i < _railtype_list.Length(); i++) { if ((RailType)i < RAILTYPE_END) { const RailtypeInfo *rti = GetRailTypeInfo((RailType)i); if (rti->label != _railtype_list[i]) return true; } else { if (_railtype_list[i] != 0) return true; } } /* No rail type conversion is necessary */ return false; }
static StringID GetTrainEngineInfoString(const Engine *e) { SetDParam(0, e->GetCost()); SetDParam(2, e->GetDisplayMaxSpeed()); SetDParam(3, e->GetPower()); SetDParam(1, e->GetDisplayWeight()); SetDParam(7, e->GetDisplayMaxTractiveEffort()); SetDParam(4, e->GetRunningCost()); uint capacity = GetTotalCapacityOfArticulatedParts(e->index); if (capacity != 0) { SetDParam(5, e->GetDefaultCargoType()); SetDParam(6, capacity); } else { SetDParam(5, CT_INVALID); } return (_settings_game.vehicle.train_acceleration_model != AM_ORIGINAL && GetRailTypeInfo(e->u.rail.railtype)->acceleration_type != 2) ? STR_ENGINE_PREVIEW_COST_WEIGHT_SPEED_POWER_MAX_TE : STR_ENGINE_PREVIEW_COST_WEIGHT_SPEED_POWER; }
/* Draw locomotive specific details */ static int DrawRailEnginePurchaseInfo(int left, int right, int y, EngineID engine_number, const RailVehicleInfo *rvi) { const Engine *e = Engine::Get(engine_number); /* Purchase Cost - Engine weight */ SetDParam(0, e->GetCost()); SetDParam(1, e->GetDisplayWeight()); DrawString(left, right, y, STR_PURCHASE_INFO_COST_WEIGHT); y += FONT_HEIGHT_NORMAL; /* Max speed - Engine power */ SetDParam(0, e->GetDisplayMaxSpeed()); SetDParam(1, e->GetPower()); DrawString(left, right, y, STR_PURCHASE_INFO_SPEED_POWER); y += FONT_HEIGHT_NORMAL; /* Max tractive effort - not applicable if old acceleration or maglev */ if (_settings_game.vehicle.train_acceleration_model != AM_ORIGINAL && GetRailTypeInfo(rvi->railtype)->acceleration_type != 2) { SetDParam(0, e->GetDisplayMaxTractiveEffort()); DrawString(left, right, y, STR_PURCHASE_INFO_MAX_TE); y += FONT_HEIGHT_NORMAL; } /* Running cost */ if (rvi->running_cost_class != INVALID_PRICE) { SetDParam(0, e->GetRunningCost()); DrawString(left, right, y, STR_PURCHASE_INFO_RUNNINGCOST); y += FONT_HEIGHT_NORMAL; } /* Powered wagons power - Powered wagons extra weight */ if (rvi->pow_wag_power != 0) { SetDParam(0, rvi->pow_wag_power); SetDParam(1, rvi->pow_wag_weight); DrawString(left, right, y, STR_PURCHASE_INFO_PWAGPOWER_PWAGWEIGHT); y += FONT_HEIGHT_NORMAL; } return y; }
/** * Draw representation of a station tile for GUI purposes. * @param x Position x of image. * @param y Position y of image. * @param axis Axis. * @param railtype Rail type. * @param sclass, station Type of station. * @param station station ID * @return True if the tile was drawn (allows for fallback to default graphic) */ bool DrawStationTile(int x, int y, RailType railtype, Axis axis, StationClassID sclass, uint station) { const DrawTileSprites *sprites = NULL; const RailtypeInfo *rti = GetRailTypeInfo(railtype); PaletteID palette = COMPANY_SPRITE_COLOUR(_local_company); uint tile = 2; const StationSpec *statspec = StationClass::Get(sclass)->GetSpec(station); if (statspec == NULL) return false; if (HasBit(statspec->callback_mask, CBM_STATION_SPRITE_LAYOUT)) { uint16 callback = GetStationCallback(CBID_STATION_SPRITE_LAYOUT, 0x2110000, 0, statspec, NULL, INVALID_TILE); if (callback != CALLBACK_FAILED) tile = callback; } uint32 total_offset = rti->GetRailtypeSpriteOffset(); uint32 relocation = 0; uint32 ground_relocation = 0; const NewGRFSpriteLayout *layout = NULL; DrawTileSprites tmp_rail_layout; if (statspec->renderdata == NULL) { sprites = GetStationTileLayout(STATION_RAIL, tile + axis); } else { layout = &statspec->renderdata[(tile < statspec->tiles) ? tile + axis : (uint)axis]; if (!layout->NeedsPreprocessing()) { sprites = layout; layout = NULL; } } if (layout != NULL) { /* Sprite layout which needs preprocessing */ bool separate_ground = HasBit(statspec->flags, SSF_SEPARATE_GROUND); uint32 var10_values = layout->PrepareLayout(total_offset, rti->fallback_railtype, 0, 0, separate_ground); uint8 var10; FOR_EACH_SET_BIT(var10, var10_values) { uint32 var10_relocation = GetCustomStationRelocation(statspec, NULL, INVALID_TILE, var10); layout->ProcessRegisters(var10, var10_relocation, separate_ground); }
/** * Draw representation of a station tile for GUI purposes. * @param x Position x of image. * @param y Position y of image. * @param axis Axis. * @param railtype Rail type. * @param sclass, station Type of station. * @param station station ID * @return True if the tile was drawn (allows for fallback to default graphic) */ bool DrawStationTile(int x, int y, RailType railtype, Axis axis, StationClassID sclass, uint station) { const StationSpec *statspec; const DrawTileSprites *sprites; const RailtypeInfo *rti = GetRailTypeInfo(railtype); PaletteID palette = COMPANY_SPRITE_COLOUR(_local_company); uint tile = 2; statspec = StationClass::Get(sclass, station); if (statspec == NULL) return false; uint relocation = GetCustomStationRelocation(statspec, NULL, INVALID_TILE); if (HasBit(statspec->callback_mask, CBM_STATION_SPRITE_LAYOUT)) { uint16 callback = GetStationCallback(CBID_STATION_SPRITE_LAYOUT, 0x2110000, 0, statspec, NULL, INVALID_TILE); if (callback != CALLBACK_FAILED) tile = callback; } if (statspec->renderdata == NULL) { sprites = GetStationTileLayout(STATION_RAIL, tile + axis); } else { sprites = &statspec->renderdata[(tile < statspec->tiles) ? tile + axis : (uint)axis]; } SpriteID image = sprites->ground.sprite; PaletteID pal = sprites->ground.pal; if (HasBit(image, SPRITE_MODIFIER_CUSTOM_SPRITE)) { image += GetCustomStationGroundRelocation(statspec, NULL, INVALID_TILE); image += rti->custom_ground_offset; } else { image += rti->total_offset; } DrawSprite(image, GroundSpritePaletteTransform(image, pal, palette), x, y); DrawRailTileSeqInGUI(x, y, sprites, rti->total_offset, relocation, palette); return true; }
/* static */ char *ScriptRail::GetName(RailType rail_type) { if (!IsRailTypeAvailable(rail_type)) return NULL; return GetString(GetRailTypeInfo((::RailType)rail_type)->strings.menu_text); }
void SetDestination(const Train *v, bool override_rail_type = false) { m_compatible_railtypes = v->compatible_railtypes; if (override_rail_type) m_compatible_railtypes |= GetRailTypeInfo(v->railtype)->compatible_railtypes; }