Merge branch 'master' into jgrpp
# Conflicts: # src/music.cpp # src/script/api/script_company.cpp # src/script/api/script_event_types.cpp # src/script/api/script_group.cpp # src/script/api/script_object.cpp # src/script/api/script_road.cpp
This commit is contained in:
@@ -289,7 +289,7 @@ enum MusicTrackType {
|
||||
|
||||
/** Metadata about a music track. */
|
||||
struct MusicSongInfo {
|
||||
char songname[32]; ///< name of song displayed in UI
|
||||
std::string songname; ///< name of song displayed in UI
|
||||
byte tracknr; ///< track number of song displayed in UI
|
||||
const char *filename; ///< file on disk containing song (when used in MusicSet class, this pointer is owned by MD5File object for the file)
|
||||
MusicTrackType filetype; ///< decoder required for song file
|
||||
|
||||
@@ -853,7 +853,7 @@ public:
|
||||
/* Position scrollbar to selected group */
|
||||
for (uint i = 0; i < this->rows; i++) {
|
||||
if (this->groups[i]->index == sel) {
|
||||
this->vscroll->SetPosition(Clamp(i - this->vscroll->GetCapacity() / 2, 0, std::max(this->vscroll->GetCount() - this->vscroll->GetCapacity(), 0)));
|
||||
this->vscroll->SetPosition(i - this->vscroll->GetCapacity() / 2);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2997,7 +2997,7 @@ STR_LAI_TREE_NAME_CACTUS_PLANTS :Plantes de Cact
|
||||
STR_LAI_STATION_DESCRIPTION_RAILROAD_STATION :Estació de Ferrocarril
|
||||
STR_LAI_STATION_DESCRIPTION_AIRCRAFT_HANGAR :Hangar d'Avions
|
||||
STR_LAI_STATION_DESCRIPTION_AIRPORT :Aeroport
|
||||
STR_LAI_STATION_DESCRIPTION_TRUCK_LOADING_AREA :Àrea de càrrega de camions
|
||||
STR_LAI_STATION_DESCRIPTION_TRUCK_LOADING_AREA :Moll de càrrega de camions
|
||||
STR_LAI_STATION_DESCRIPTION_BUS_STATION :Parada d'autobús
|
||||
STR_LAI_STATION_DESCRIPTION_SHIP_DOCK :Moll per vaixells
|
||||
STR_LAI_STATION_DESCRIPTION_BUOY :Boia
|
||||
@@ -5087,6 +5087,18 @@ STR_ERROR_TOO_FAR_FROM_PREVIOUS_DESTINATION :{WHITE}... mass
|
||||
STR_ERROR_AIRCRAFT_NOT_ENOUGH_RANGE :{WHITE}... l'avió no té prou autonomia
|
||||
|
||||
# Extra messages which go on the third line of errors, explaining why orders failed
|
||||
STR_ERROR_NO_RAIL_STATION :{WHITE}No hi ha cap estació ferroviària
|
||||
STR_ERROR_NO_BUS_STATION :{WHITE}No hi ha cap estació d'autobusos
|
||||
STR_ERROR_NO_TRUCK_STATION :{WHITE}No hi ha cap estació de camions
|
||||
STR_ERROR_NO_DOCK :{WHITE}No hi ha cap port
|
||||
STR_ERROR_NO_AIRPORT :{WHITE}No hi ha cap aeroport/heliport
|
||||
STR_ERROR_NO_STOP_COMPATIBLE_ROAD_TYPE :{WHITE}No hi ha parades amb un tipus de carretera compatible
|
||||
STR_ERROR_NO_STOP_COMPATIBLE_TRAM_TYPE :{WHITE}No hi ha parades amb un tipus de tramvia compatible
|
||||
STR_ERROR_NO_STOP_ARTICULATED_VEHICLE :{WHITE}No hi ha parades que siguin adequades per a vehicles de carretera articulats.{}Aquest tipus de vehicles necessiten una estació de pas, no pas una estació final
|
||||
STR_ERROR_AIRPORT_NO_PLANES :{WHITE}L'avió no pot aterrar en aquest aeroport
|
||||
STR_ERROR_AIRPORT_NO_HELICOPTERS :{WHITE}L'helicòpter no pot aterrar en aquest aeroport
|
||||
STR_ERROR_NO_RAIL_WAYPOINT :{WHITE}No hi ha cap punt de pas ferroviari
|
||||
STR_ERROR_NO_BUOY :{WHITE}No hi ha cap boia
|
||||
|
||||
# Timetable related errors
|
||||
STR_ERROR_CAN_T_TIMETABLE_VEHICLE :{WHITE}Impossible establir l'horari del vehicle...
|
||||
|
||||
@@ -2358,6 +2358,8 @@ STR_NETWORK_CLIENT_LIST_NEW_COMPANY :(New company)
|
||||
STR_NETWORK_CLIENT_LIST_NEW_COMPANY_TOOLTIP :{BLACK}Create a new company and join it
|
||||
STR_NETWORK_CLIENT_LIST_PLAYER_ICON_SELF_TOOLTIP :{BLACK}This is you
|
||||
STR_NETWORK_CLIENT_LIST_PLAYER_ICON_HOST_TOOLTIP :{BLACK}This is the host of the game
|
||||
STR_NETWORK_CLIENT_LIST_CLIENT_COMPANY_COUNT :{BLACK}{NUM} client{P "" s} - {NUM}/{NUM} compan{P y ies}
|
||||
STR_NETWORK_CLIENT_LIST_CLIENT_COMPANY_COUNT_TOOLTIP :{BLACK}The number of currently connected clients, number of companies and maximum number of companies allowed by the server administrator
|
||||
|
||||
# Matches ConnectionType
|
||||
###length 5
|
||||
@@ -5084,6 +5086,18 @@ STR_ERROR_TOO_FAR_FROM_PREVIOUS_DESTINATION :{WHITE}... too
|
||||
STR_ERROR_AIRCRAFT_NOT_ENOUGH_RANGE :{WHITE}... aircraft has not enough range
|
||||
|
||||
# Extra messages which go on the third line of errors, explaining why orders failed
|
||||
STR_ERROR_NO_RAIL_STATION :{WHITE}There is no railway station
|
||||
STR_ERROR_NO_BUS_STATION :{WHITE}There is no bus station
|
||||
STR_ERROR_NO_TRUCK_STATION :{WHITE}There is no lorry station
|
||||
STR_ERROR_NO_DOCK :{WHITE}There is no dock
|
||||
STR_ERROR_NO_AIRPORT :{WHITE}There is no airport/heliport
|
||||
STR_ERROR_NO_STOP_COMPATIBLE_ROAD_TYPE :{WHITE}There are no stops with a compatible road type
|
||||
STR_ERROR_NO_STOP_COMPATIBLE_TRAM_TYPE :{WHITE}There are no stops with a compatible tram type
|
||||
STR_ERROR_NO_STOP_ARTICULATED_VEHICLE :{WHITE}There are no stops which are suitable for articulated road vehicles.{}Articulated road vehicles require a drive-through stop, not a bay stop
|
||||
STR_ERROR_AIRPORT_NO_PLANES :{WHITE}This plane cannot land at this heliport
|
||||
STR_ERROR_AIRPORT_NO_HELICOPTERS :{WHITE}This helicopter cannot land at this airport
|
||||
STR_ERROR_NO_RAIL_WAYPOINT :{WHITE}There is no railway waypoint
|
||||
STR_ERROR_NO_BUOY :{WHITE}There is no buoy
|
||||
|
||||
# Timetable related errors
|
||||
STR_ERROR_CAN_T_TIMETABLE_VEHICLE :{WHITE}Can't timetable vehicle...
|
||||
|
||||
@@ -5086,8 +5086,18 @@ STR_ERROR_TOO_FAR_FROM_PREVIOUS_DESTINATION :{WHITE}... liia
|
||||
STR_ERROR_AIRCRAFT_NOT_ENOUGH_RANGE :{WHITE}... ilma-aluksen toimintasäde ei riitä
|
||||
|
||||
# Extra messages which go on the third line of errors, explaining why orders failed
|
||||
STR_ERROR_NO_RAIL_STATION :{WHITE}Rautatieasemaa ei ole
|
||||
STR_ERROR_NO_BUS_STATION :{WHITE}Linja-autopysäkkiä ei ole
|
||||
STR_ERROR_NO_TRUCK_STATION :{WHITE}Lastauslaituria ei ole
|
||||
STR_ERROR_NO_DOCK :{WHITE}Satamaa ei ole
|
||||
STR_ERROR_NO_AIRPORT :{WHITE}Lento-/helikopterikenttää ei ole
|
||||
STR_ERROR_NO_STOP_COMPATIBLE_ROAD_TYPE :{WHITE}Ei ole pysäkkejä sopivalla tien tyypillä
|
||||
STR_ERROR_NO_STOP_COMPATIBLE_TRAM_TYPE :{WHITE}Ei ole pysäkkejä sopivalla raitiotien tyypillä
|
||||
STR_ERROR_NO_STOP_ARTICULATED_VEHICLE :{WHITE}Ei ole nivelajoneuvoille sopivia pysäkkejä.{}Nivelletyt ajoneuvot vaativat pysäkin, joka ei ole kääntöpysäkki vaan läpiajettava
|
||||
STR_ERROR_AIRPORT_NO_PLANES :{WHITE}Tämä lentokone ei voi laskeutua tälle helikopterikentälle
|
||||
STR_ERROR_AIRPORT_NO_HELICOPTERS :{WHITE}Tämä helikopteri ei voi laskeutua tälle lentokentälle
|
||||
STR_ERROR_NO_RAIL_WAYPOINT :{WHITE}Rautatien reittipistettä ei ole
|
||||
STR_ERROR_NO_BUOY :{WHITE}Poijua ei ole
|
||||
|
||||
# Timetable related errors
|
||||
STR_ERROR_CAN_T_TIMETABLE_VEHICLE :{WHITE}Ei voi asettaa aikataulua.
|
||||
|
||||
@@ -5084,6 +5084,9 @@ STR_ERROR_TOO_FAR_FROM_PREVIOUS_DESTINATION :{WHITE}... prea
|
||||
STR_ERROR_AIRCRAFT_NOT_ENOUGH_RANGE :{WHITE}... avionul nu are o rază de acțiune suficientă
|
||||
|
||||
# Extra messages which go on the third line of errors, explaining why orders failed
|
||||
STR_ERROR_NO_STOP_ARTICULATED_VEHICLE :{WHITE}Nu există opriri care să fie potrivite pentru vehiculele rutiere articulate.{}Vehiculele rutiere articulate necesită o oprire de drum, nu o oprire într-o rampă.
|
||||
STR_ERROR_NO_RAIL_WAYPOINT :{WHITE}Nu există niciun punct intermediar feroviar
|
||||
STR_ERROR_NO_BUOY :{WHITE}Nu există geamanduri
|
||||
|
||||
# Timetable related errors
|
||||
STR_ERROR_CAN_T_TIMETABLE_VEHICLE :{WHITE}Nu pot programa vehiculul...
|
||||
|
||||
@@ -128,7 +128,6 @@ bool MusicSet::FillSetDetails(IniFile *ini, const char *path, const char *full_f
|
||||
for (uint i = 0; i < lengthof(this->songinfo); i++) {
|
||||
const char *filename = this->files[i].filename;
|
||||
if (names == nullptr || StrEmpty(filename) || this->files[i].check_result == MD5File::CR_NO_FILE) {
|
||||
this->songinfo[i].songname[0] = '\0';
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -141,11 +140,10 @@ bool MusicSet::FillSetDetails(IniFile *ini, const char *path, const char *full_f
|
||||
this->songinfo[i].cat_index = atoi(item->value->c_str());
|
||||
char *songname = GetMusicCatEntryName(filename, this->songinfo[i].cat_index);
|
||||
if (songname == nullptr) {
|
||||
DEBUG(grf, 1, "Base music set song missing from CAT file: %s/%d", filename, this->songinfo[i].cat_index);
|
||||
this->songinfo[i].songname[0] = '\0';
|
||||
DEBUG(grf, 0, "Base music set song missing from CAT file: %s/%d", filename, this->songinfo[i].cat_index);
|
||||
continue;
|
||||
}
|
||||
strecpy(this->songinfo[i].songname, songname, lastof(this->songinfo[i].songname));
|
||||
this->songinfo[i].songname = songname;
|
||||
free(songname);
|
||||
} else {
|
||||
this->songinfo[i].filetype = MTT_STANDARDMIDI;
|
||||
@@ -166,7 +164,7 @@ bool MusicSet::FillSetDetails(IniFile *ini, const char *path, const char *full_f
|
||||
|
||||
if (this->songinfo[i].filetype == MTT_STANDARDMIDI) {
|
||||
if (item != nullptr && item->value.has_value() && !item->value->empty()) {
|
||||
strecpy(this->songinfo[i].songname, item->value->c_str(), lastof(this->songinfo[i].songname));
|
||||
this->songinfo[i].songname = item->value.value();
|
||||
} else {
|
||||
DEBUG(grf, 0, "Base music set song name missing: %s", filename);
|
||||
return false;
|
||||
|
||||
@@ -43,7 +43,7 @@ struct MusicSystem {
|
||||
uint set_index; ///< index of song in set
|
||||
|
||||
PlaylistEntry(const MusicSet *set, uint set_index) : MusicSongInfo(set->songinfo[set_index]), set(set), set_index(set_index) { }
|
||||
bool IsValid() const { return !StrEmpty(this->songname); }
|
||||
bool IsValid() const { return !this->songname.empty(); }
|
||||
};
|
||||
typedef std::vector<PlaylistEntry> Playlist;
|
||||
|
||||
@@ -147,18 +147,20 @@ void MusicSystem::ChangePlaylist(PlaylistChoices pl)
|
||||
{
|
||||
assert(pl < PLCH_MAX && pl >= PLCH_ALLMUSIC);
|
||||
|
||||
this->displayed_playlist = this->standard_playlists[pl];
|
||||
this->active_playlist = this->displayed_playlist;
|
||||
this->selected_playlist = pl;
|
||||
this->playlist_position = 0;
|
||||
if (pl != PLCH_THEMEONLY) _settings_client.music.playlist = pl;
|
||||
|
||||
if (this->selected_playlist != PLCH_THEMEONLY) _settings_client.music.playlist = this->selected_playlist;
|
||||
if (_game_mode != GM_MENU || pl == PLCH_THEMEONLY) {
|
||||
this->displayed_playlist = this->standard_playlists[pl];
|
||||
this->active_playlist = this->displayed_playlist;
|
||||
this->selected_playlist = pl;
|
||||
this->playlist_position = 0;
|
||||
|
||||
if (_settings_client.music.shuffle) {
|
||||
this->Shuffle();
|
||||
/* Shuffle() will also Play() if necessary, only start once */
|
||||
} else if (_settings_client.music.playing) {
|
||||
this->Play();
|
||||
if (_settings_client.music.shuffle) {
|
||||
this->Shuffle();
|
||||
/* Shuffle() will also Play() if necessary, only start once */
|
||||
} else if (_settings_client.music.playing) {
|
||||
this->Play();
|
||||
}
|
||||
}
|
||||
|
||||
InvalidateWindowData(WC_MUSIC_TRACK_SELECTION, 0);
|
||||
@@ -178,6 +180,8 @@ void MusicSystem::ChangeMusicSet(const std::string &set_name)
|
||||
this->ChangePlaylist(this->selected_playlist);
|
||||
|
||||
InvalidateWindowData(WC_GAME_OPTIONS, WN_GAME_OPTIONS_GAME_OPTIONS, 0, true);
|
||||
InvalidateWindowData(WC_MUSIC_TRACK_SELECTION, 0, 1, true);
|
||||
InvalidateWindowData(WC_MUSIC_WINDOW, 0, 1, true);
|
||||
}
|
||||
|
||||
/** Enable shuffle mode and restart playback */
|
||||
@@ -486,7 +490,12 @@ struct MusicTrackSelectionWindow : public Window {
|
||||
this->SetWidgetLoweredState(WID_MTS_ALL + i, i == _settings_client.music.playlist);
|
||||
}
|
||||
this->SetWidgetDisabledState(WID_MTS_CLEAR, _settings_client.music.playlist <= 3);
|
||||
this->SetDirty();
|
||||
|
||||
if (data == 1) {
|
||||
this->ReInit();
|
||||
} else {
|
||||
this->SetDirty();
|
||||
}
|
||||
}
|
||||
|
||||
void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize) override
|
||||
@@ -611,9 +620,9 @@ static const NWidgetPart _nested_music_track_selection_widgets[] = {
|
||||
NWidget(NWID_HORIZONTAL), SetPIP(2, 4, 2),
|
||||
/* Left panel. */
|
||||
NWidget(NWID_VERTICAL),
|
||||
NWidget(WWT_LABEL, COLOUR_GREY), SetDataTip(STR_PLAYLIST_TRACK_INDEX, STR_NULL),
|
||||
NWidget(WWT_PANEL, COLOUR_GREY, WID_MTS_LIST_LEFT), SetMinimalSize(180, 194), SetDataTip(0x0, STR_PLAYLIST_TOOLTIP_CLICK_TO_ADD_TRACK), EndContainer(),
|
||||
NWidget(NWID_SPACER), SetMinimalSize(0, 2),
|
||||
NWidget(WWT_LABEL, COLOUR_GREY), SetFill(1, 0), SetDataTip(STR_PLAYLIST_TRACK_INDEX, STR_NULL),
|
||||
NWidget(WWT_PANEL, COLOUR_GREY, WID_MTS_LIST_LEFT), SetFill(1, 1), SetMinimalSize(180, 194), SetDataTip(0x0, STR_PLAYLIST_TOOLTIP_CLICK_TO_ADD_TRACK), EndContainer(),
|
||||
NWidget(NWID_SPACER), SetFill(1, 0), SetMinimalSize(0, 2),
|
||||
EndContainer(),
|
||||
/* Middle buttons. */
|
||||
NWidget(NWID_VERTICAL),
|
||||
@@ -630,9 +639,9 @@ static const NWidgetPart _nested_music_track_selection_widgets[] = {
|
||||
EndContainer(),
|
||||
/* Right panel. */
|
||||
NWidget(NWID_VERTICAL),
|
||||
NWidget(WWT_LABEL, COLOUR_GREY, WID_MTS_PLAYLIST), SetDataTip(STR_PLAYLIST_PROGRAM, STR_NULL),
|
||||
NWidget(WWT_PANEL, COLOUR_GREY, WID_MTS_LIST_RIGHT), SetMinimalSize(180, 194), SetDataTip(0x0, STR_PLAYLIST_TOOLTIP_CLICK_TO_REMOVE_TRACK), EndContainer(),
|
||||
NWidget(NWID_SPACER), SetMinimalSize(0, 2),
|
||||
NWidget(WWT_LABEL, COLOUR_GREY, WID_MTS_PLAYLIST), SetFill(1, 0), SetDataTip(STR_PLAYLIST_PROGRAM, STR_NULL),
|
||||
NWidget(WWT_PANEL, COLOUR_GREY, WID_MTS_LIST_RIGHT), SetFill(1, 1), SetMinimalSize(180, 194), SetDataTip(0x0, STR_PLAYLIST_TOOLTIP_CLICK_TO_REMOVE_TRACK), EndContainer(),
|
||||
NWidget(NWID_SPACER), SetFill(1, 0), SetMinimalSize(0, 2),
|
||||
EndContainer(),
|
||||
EndContainer(),
|
||||
EndContainer(),
|
||||
@@ -770,7 +779,11 @@ struct MusicWindow : public Window {
|
||||
|
||||
UpdateDisabledButtons();
|
||||
|
||||
this->SetDirty();
|
||||
if (data == 1) {
|
||||
this->ReInit();
|
||||
} else {
|
||||
this->SetDirty();
|
||||
}
|
||||
}
|
||||
|
||||
void OnClick(Point pt, int widget, int click_count) override
|
||||
|
||||
@@ -412,9 +412,8 @@ protected:
|
||||
|
||||
/* show highlighted item with a different colour */
|
||||
if (highlight) {
|
||||
Rect r = {name.left, y, info.right, y + (int)this->resize.step_height - 1};
|
||||
Rect ir = r.Shrink(WidgetDimensions::scaled.bevel);
|
||||
GfxFillRect(ir.left, ir.top, ir.right, ir.bottom, PC_GREY);
|
||||
Rect r = {std::min(name.left, info.left), y, std::max(name.right, info.right), y + (int)this->resize.step_height - 1};
|
||||
GfxFillRect(r.Shrink(WidgetDimensions::scaled.bevel), PC_GREY);
|
||||
}
|
||||
|
||||
/* offsets to vertically centre text and icons */
|
||||
|
||||
@@ -1566,7 +1566,7 @@ static ChangeInfoResult ShipVehicleChangeInfo(uint engine, int numinfo, int prop
|
||||
ei->cargo_type = ctype;
|
||||
} else {
|
||||
ei->cargo_type = CT_INVALID;
|
||||
grfmsg(2, "RailVehicleChangeInfo: Invalid cargo type %d, using first refittable", ctype);
|
||||
grfmsg(2, "ShipVehicleChangeInfo: Invalid cargo type %d, using first refittable", ctype);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -94,6 +94,7 @@ extern uint8 GetAirportNoiseLevelForDistance(const struct AirportSpec *as, uint
|
||||
|
||||
/* static */ SQInteger ScriptAirport::GetNumHangars(TileIndex tile)
|
||||
{
|
||||
EnforceDeityOrCompanyModeValid(-1);
|
||||
if (!::IsValidTile(tile)) return -1;
|
||||
if (!::IsTileType(tile, MP_STATION)) return -1;
|
||||
|
||||
@@ -106,6 +107,7 @@ extern uint8 GetAirportNoiseLevelForDistance(const struct AirportSpec *as, uint
|
||||
|
||||
/* static */ TileIndex ScriptAirport::GetHangarOfAirport(TileIndex tile)
|
||||
{
|
||||
EnforceDeityOrCompanyModeValid(INVALID_TILE);
|
||||
if (!::IsValidTile(tile)) return INVALID_TILE;
|
||||
if (!::IsTileType(tile, MP_STATION)) return INVALID_TILE;
|
||||
if (GetNumHangars(tile) < 1) return INVALID_TILE;
|
||||
|
||||
@@ -19,6 +19,7 @@
|
||||
|
||||
/* static */ bool ScriptBaseStation::IsValidBaseStation(StationID station_id)
|
||||
{
|
||||
EnforceDeityOrCompanyModeValid(false);
|
||||
const BaseStation *st = ::BaseStation::GetIfValid(station_id);
|
||||
return st != nullptr && (st->owner == ScriptObject::GetCompany() || ScriptCompanyMode::IsDeity() || st->owner == OWNER_NONE);
|
||||
}
|
||||
|
||||
@@ -71,6 +71,7 @@ static void _DoCommandReturnBuildBridge1(class ScriptInstance *instance)
|
||||
|
||||
/* static */ bool ScriptBridge::BuildBridge(ScriptVehicle::VehicleType vehicle_type, BridgeID bridge_id, TileIndex start, TileIndex end)
|
||||
{
|
||||
EnforceDeityOrCompanyModeValid(false);
|
||||
EnforcePrecondition(false, start != end);
|
||||
EnforcePrecondition(false, ::IsValidTile(start) && ::IsValidTile(end));
|
||||
EnforcePrecondition(false, TileX(start) == TileX(end) || TileY(start) == TileY(end));
|
||||
@@ -107,6 +108,8 @@ static void _DoCommandReturnBuildBridge1(class ScriptInstance *instance)
|
||||
|
||||
/* static */ bool ScriptBridge::_BuildBridgeRoad1()
|
||||
{
|
||||
EnforceDeityOrCompanyModeValid(false);
|
||||
|
||||
/* Build the piece of road on the 'start' side of the bridge */
|
||||
TileIndex end = ScriptObject::GetCallbackVariable(0);
|
||||
TileIndex start = ScriptObject::GetCallbackVariable(1);
|
||||
@@ -119,6 +122,8 @@ static void _DoCommandReturnBuildBridge1(class ScriptInstance *instance)
|
||||
|
||||
/* static */ bool ScriptBridge::_BuildBridgeRoad2()
|
||||
{
|
||||
EnforceDeityOrCompanyModeValid(false);
|
||||
|
||||
/* Build the piece of road on the 'end' side of the bridge */
|
||||
TileIndex end = ScriptObject::GetCallbackVariable(0);
|
||||
TileIndex start = ScriptObject::GetCallbackVariable(1);
|
||||
|
||||
@@ -43,6 +43,7 @@
|
||||
{
|
||||
CCountedPtr<Text> counter(name);
|
||||
|
||||
EnforceCompanyModeValid(false);
|
||||
EnforcePrecondition(false, name != nullptr);
|
||||
const std::string &text = name->GetDecodedText();
|
||||
EnforcePreconditionEncodedText(false, text);
|
||||
@@ -64,6 +65,7 @@
|
||||
{
|
||||
CCountedPtr<Text> counter(name);
|
||||
|
||||
EnforceCompanyModeValid(false);
|
||||
EnforcePrecondition(false, name != nullptr);
|
||||
const std::string &text = name->GetDecodedText();
|
||||
EnforcePreconditionEncodedText(false, text);
|
||||
@@ -90,6 +92,7 @@
|
||||
|
||||
/* static */ bool ScriptCompany::SetPresidentGender(Gender gender)
|
||||
{
|
||||
EnforceCompanyModeValid(false);
|
||||
EnforcePrecondition(false, gender == GENDER_MALE || gender == GENDER_FEMALE);
|
||||
EnforcePrecondition(false, GetPresidentGender(ScriptCompany::COMPANY_SELF) != gender);
|
||||
|
||||
@@ -246,8 +249,6 @@
|
||||
{
|
||||
EnforceDeityMode(false);
|
||||
EnforcePrecondition(false, expenses_type < (ExpensesType)::EXPENSES_END);
|
||||
EnforcePrecondition(false, (int64)delta >= INT32_MIN);
|
||||
EnforcePrecondition(false, (int64)delta <= INT32_MAX);
|
||||
EnforcePrecondition(false, tile == INVALID_TILE || ::IsValidTile(tile));
|
||||
|
||||
company = ResolveCompanyID(company);
|
||||
@@ -276,6 +277,7 @@
|
||||
|
||||
/* static */ bool ScriptCompany::SetAutoRenewStatus(bool autorenew)
|
||||
{
|
||||
EnforceCompanyModeValid(false);
|
||||
return ScriptObject::DoCommand(0, 0, autorenew ? 1 : 0, CMD_CHANGE_COMPANY_SETTING, "company.engine_renew");
|
||||
}
|
||||
|
||||
@@ -289,7 +291,9 @@
|
||||
|
||||
/* static */ bool ScriptCompany::SetAutoRenewMonths(SQInteger months)
|
||||
{
|
||||
EnforceCompanyModeValid(false);
|
||||
months = Clamp<SQInteger>(months, INT16_MIN, INT16_MAX);
|
||||
|
||||
return ScriptObject::DoCommand(0, 0, months, CMD_CHANGE_COMPANY_SETTING, "company.engine_renew_months");
|
||||
}
|
||||
|
||||
@@ -303,6 +307,7 @@
|
||||
|
||||
/* static */ bool ScriptCompany::SetAutoRenewMoney(Money money)
|
||||
{
|
||||
EnforceCompanyModeValid(false);
|
||||
EnforcePrecondition(false, money >= 0);
|
||||
EnforcePrecondition(false, (int64)money <= UINT32_MAX);
|
||||
return ScriptObject::DoCommand(0, 0, money, CMD_CHANGE_COMPANY_SETTING, "company.engine_renew_money");
|
||||
@@ -318,11 +323,13 @@
|
||||
|
||||
/* static */ bool ScriptCompany::SetPrimaryLiveryColour(LiveryScheme scheme, Colours colour)
|
||||
{
|
||||
EnforceCompanyModeValid(false);
|
||||
return ScriptObject::DoCommand(0, scheme, colour, CMD_SET_COMPANY_COLOUR);
|
||||
}
|
||||
|
||||
/* static */ bool ScriptCompany::SetSecondaryLiveryColour(LiveryScheme scheme, Colours colour)
|
||||
{
|
||||
EnforceCompanyModeValid(false);
|
||||
return ScriptObject::DoCommand(0, scheme | 1 << 8, colour, CMD_SET_COMPANY_COLOUR);
|
||||
}
|
||||
|
||||
|
||||
@@ -139,6 +139,7 @@ public:
|
||||
* Set the name of your company.
|
||||
* @param name The new name of the company (can be either a raw string, or a ScriptText object).
|
||||
* @pre name != null && len(name) != 0.
|
||||
* @game @pre ScriptCompanyMode::IsValid().
|
||||
* @exception ScriptError::ERR_NAME_IS_NOT_UNIQUE
|
||||
* @return True if the name was changed.
|
||||
*/
|
||||
@@ -156,6 +157,7 @@ public:
|
||||
* Set the name of your president.
|
||||
* @param name The new name of the president (can be either a raw string, or a ScriptText object).
|
||||
* @pre name != null && len(name) != 0.
|
||||
* @game @pre ScriptCompanyMode::IsValid().
|
||||
* @exception ScriptError::ERR_NAME_IS_NOT_UNIQUE
|
||||
* @return True if the name was changed.
|
||||
*/
|
||||
@@ -173,6 +175,7 @@ public:
|
||||
* Set the gender of the president of your company.
|
||||
* @param gender The new gender for your president.
|
||||
* @pre GetPresidentGender(ScriptCompany.COMPANY_SELF) != gender.
|
||||
* @game @pre ScriptCompanyMode::IsValid().
|
||||
* @return True if the gender was changed.
|
||||
* @note When successful a random face will be created.
|
||||
* @api -game
|
||||
@@ -247,8 +250,6 @@ public:
|
||||
* @return True, if the bank balance was changed.
|
||||
* @game @pre ScriptCompanyMode::IsDeity().
|
||||
* @pre ResolveCompanyID(company) != COMPANY_INVALID.
|
||||
* @pre delta >= -2**31
|
||||
* @pre delta < 2**31
|
||||
* @note You need to create your own news message to inform about costs/gifts that you create using this command.
|
||||
* @api -ai
|
||||
*/
|
||||
@@ -347,6 +348,7 @@ public:
|
||||
/**
|
||||
* Set whether autorenew is enabled for your company.
|
||||
* @param autorenew The new autorenew status.
|
||||
* @game @pre ScriptCompanyMode::IsValid().
|
||||
* @return True if autorenew status has been modified.
|
||||
* @api -game
|
||||
*/
|
||||
@@ -364,6 +366,7 @@ public:
|
||||
* Set the number of months before/after max age to autorenew an engine for your company.
|
||||
* @param months The new months between autorenew.
|
||||
* The value will be clamped to MIN(int16) .. MAX(int16).
|
||||
* @game @pre ScriptCompanyMode::IsValid().
|
||||
* @return True if autorenew months has been modified.
|
||||
* @api -game
|
||||
*/
|
||||
@@ -380,6 +383,7 @@ public:
|
||||
/**
|
||||
* Set the minimum money needed to autorenew an engine for your company.
|
||||
* @param money The new minimum required money for autorenew to work.
|
||||
* @game @pre ScriptCompanyMode::IsValid().
|
||||
* @return True if autorenew money has been modified.
|
||||
* @pre money >= 0
|
||||
* @pre money < 2**32
|
||||
@@ -399,6 +403,7 @@ public:
|
||||
* Set primary colour for your company.
|
||||
* @param scheme Livery scheme to set.
|
||||
* @param colour Colour to set.
|
||||
* @game @pre ScriptCompanyMode::IsValid().
|
||||
* @return False if unable to set primary colour of the livery scheme (e.g. colour in use).
|
||||
*/
|
||||
static bool SetPrimaryLiveryColour(LiveryScheme scheme, Colours colour);
|
||||
@@ -407,6 +412,7 @@ public:
|
||||
* Set secondary colour for your company.
|
||||
* @param scheme Livery scheme to set.
|
||||
* @param colour Colour to set.
|
||||
* @game @pre ScriptCompanyMode::IsValid().
|
||||
* @return False if unable to set secondary colour of the livery scheme.
|
||||
*/
|
||||
static bool SetSecondaryLiveryColour(LiveryScheme scheme, Colours colour);
|
||||
|
||||
@@ -29,7 +29,7 @@ ScriptCompanyMode::~ScriptCompanyMode()
|
||||
|
||||
/* static */ bool ScriptCompanyMode::IsValid()
|
||||
{
|
||||
return ScriptObject::GetCompany() != OWNER_DEITY;
|
||||
return ::Company::IsValidID(ScriptObject::GetCompany());
|
||||
}
|
||||
|
||||
/* static */ bool ScriptCompanyMode::IsDeity()
|
||||
|
||||
@@ -50,7 +50,7 @@ public:
|
||||
|
||||
/**
|
||||
* Check whether a company mode is valid. In other words, are commands
|
||||
* being executed under some company.
|
||||
* being executed under some company and does the company still exist?
|
||||
* @return true When a company mode is valid.
|
||||
* @post !ScriptCompanyMode::IsDeity().
|
||||
*/
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
|
||||
ScriptDepotList::ScriptDepotList(ScriptTile::TransportType transport_type)
|
||||
{
|
||||
EnforceDeityOrCompanyModeValid_Void();
|
||||
::TileType tile_type;
|
||||
switch (transport_type) {
|
||||
default: return;
|
||||
|
||||
@@ -23,6 +23,7 @@
|
||||
|
||||
/* static */ bool ScriptEngine::IsValidEngine(EngineID engine_id)
|
||||
{
|
||||
EnforceDeityOrCompanyModeValid(false);
|
||||
const Engine *e = ::Engine::GetIfValid(engine_id);
|
||||
if (e == nullptr || !e->IsEnabled()) return false;
|
||||
|
||||
@@ -34,6 +35,7 @@
|
||||
|
||||
/* static */ bool ScriptEngine::IsBuildable(EngineID engine_id)
|
||||
{
|
||||
EnforceDeityOrCompanyModeValid(false);
|
||||
const Engine *e = ::Engine::GetIfValid(engine_id);
|
||||
return e != nullptr && ::IsEngineBuildable(engine_id, e->type, ScriptObject::GetCompany());
|
||||
}
|
||||
|
||||
@@ -15,6 +15,7 @@
|
||||
|
||||
ScriptEngineList::ScriptEngineList(ScriptVehicle::VehicleType vehicle_type)
|
||||
{
|
||||
EnforceDeityOrCompanyModeValid_Void();
|
||||
for (const Engine *e : Engine::IterateType((::VehicleType)vehicle_type)) {
|
||||
if (ScriptCompanyMode::IsDeity() || HasBit(e->company_avail, ScriptObject::GetCompany())) this->AddItem(e->index);
|
||||
}
|
||||
|
||||
@@ -53,14 +53,31 @@
|
||||
* @param returnval The value to return on failure.
|
||||
*/
|
||||
#define EnforceCompanyModeValid(returnval) \
|
||||
EnforcePrecondition(returnval, ScriptCompanyMode::IsValid())
|
||||
EnforcePreconditionCustomError(returnval, ScriptCompanyMode::IsValid(), ScriptError::ERR_PRECONDITION_INVALID_COMPANY)
|
||||
|
||||
/**
|
||||
* Helper to enforce the precondition that we are in a deity mode.
|
||||
* @param returnval The value to return on failure.
|
||||
*/
|
||||
#define EnforceDeityMode(returnval) \
|
||||
EnforcePrecondition(returnval, ScriptCompanyMode::IsDeity())
|
||||
EnforcePreconditionCustomError(returnval, ScriptCompanyMode::IsDeity(), ScriptError::ERR_PRECONDITION_INVALID_COMPANY)
|
||||
|
||||
/**
|
||||
* Helper to enforce the precondition that the company mode is valid or that we are a deity.
|
||||
* @param returnval The value to return on failure.
|
||||
*/
|
||||
#define EnforceDeityOrCompanyModeValid(returnval) \
|
||||
EnforcePreconditionCustomError(returnval, ScriptCompanyMode::IsDeity() || ScriptCompanyMode::IsValid(), ScriptError::ERR_PRECONDITION_INVALID_COMPANY)
|
||||
|
||||
/**
|
||||
* Helper to enforce the precondition that the company mode is valid or that we are a deity.
|
||||
*/
|
||||
#define EnforceDeityOrCompanyModeValid_Void() \
|
||||
if (!(ScriptCompanyMode::IsDeity() || ScriptCompanyMode::IsValid())) { \
|
||||
ScriptObject::SetLastError(ScriptError::ERR_PRECONDITION_INVALID_COMPANY); \
|
||||
return; \
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Class that handles all error related functions.
|
||||
|
||||
@@ -109,12 +109,14 @@ int32 ScriptEventEnginePreview::GetVehicleType()
|
||||
|
||||
bool ScriptEventEnginePreview::AcceptPreview()
|
||||
{
|
||||
EnforceCompanyModeValid(false);
|
||||
if (!this->IsEngineValid()) return false;
|
||||
return ScriptObject::DoCommand(0, this->engine, 0, CMD_WANT_ENGINE_PREVIEW);
|
||||
}
|
||||
|
||||
bool ScriptEventCompanyAskMerger::AcceptMerger()
|
||||
{
|
||||
EnforceCompanyModeValid(false);
|
||||
return ScriptObject::DoCommand(0, this->owner, 0, CMD_BUY_COMPANY);
|
||||
}
|
||||
|
||||
|
||||
@@ -289,6 +289,7 @@ public:
|
||||
|
||||
/**
|
||||
* Accept the engine preview.
|
||||
* @game @pre ScriptCompanyMode::IsValid().
|
||||
* @return True when the accepting succeeded.
|
||||
*/
|
||||
bool AcceptPreview();
|
||||
@@ -410,6 +411,7 @@ public:
|
||||
|
||||
/**
|
||||
* Take over the company for this merger.
|
||||
* @game @pre ScriptCompanyMode::IsValid().
|
||||
* @return true if the merger was a success.
|
||||
*/
|
||||
bool AcceptMerger();
|
||||
|
||||
@@ -9,6 +9,7 @@
|
||||
|
||||
#include "../../stdafx.h"
|
||||
#include "script_game.hpp"
|
||||
#include "script_error.hpp"
|
||||
#include "../../command_type.h"
|
||||
#include "../../settings_type.h"
|
||||
#include "../../network/network.h"
|
||||
|
||||
@@ -32,6 +32,7 @@
|
||||
|
||||
/* static */ bool ScriptGameSettings::SetValue(const char *setting, SQInteger value)
|
||||
{
|
||||
EnforceDeityOrCompanyModeValid(false);
|
||||
if (!IsValid(setting)) return false;
|
||||
|
||||
const SettingDesc *sd = GetSettingFromName(setting);
|
||||
|
||||
@@ -22,12 +22,14 @@
|
||||
|
||||
/* static */ bool ScriptGroup::IsValidGroup(GroupID group_id)
|
||||
{
|
||||
EnforceDeityOrCompanyModeValid(false);
|
||||
const Group *g = ::Group::GetIfValid(group_id);
|
||||
return g != nullptr && g->owner == ScriptObject::GetCompany();
|
||||
}
|
||||
|
||||
/* static */ ScriptGroup::GroupID ScriptGroup::CreateGroup(ScriptVehicle::VehicleType vehicle_type, GroupID parent_group_id)
|
||||
{
|
||||
EnforceCompanyModeValid(GROUP_INVALID);
|
||||
if (!ScriptObject::DoCommand(0, (::VehicleType)vehicle_type, parent_group_id, CMD_CREATE_GROUP, nullptr, &ScriptInstance::DoCommandReturnGroupID)) return GROUP_INVALID;
|
||||
|
||||
/* In case of test-mode, we return GroupID 0 */
|
||||
@@ -36,6 +38,7 @@
|
||||
|
||||
/* static */ bool ScriptGroup::DeleteGroup(GroupID group_id)
|
||||
{
|
||||
EnforceCompanyModeValid(false);
|
||||
EnforcePrecondition(false, IsValidGroup(group_id));
|
||||
|
||||
return ScriptObject::DoCommand(0, group_id, 0, CMD_DELETE_GROUP);
|
||||
@@ -52,6 +55,7 @@
|
||||
{
|
||||
CCountedPtr<Text> counter(name);
|
||||
|
||||
EnforceCompanyModeValid(false);
|
||||
EnforcePrecondition(false, IsValidGroup(group_id));
|
||||
EnforcePrecondition(false, name != nullptr);
|
||||
const std::string &text = name->GetDecodedText();
|
||||
@@ -71,6 +75,7 @@
|
||||
|
||||
/* static */ bool ScriptGroup::SetParent(GroupID group_id, GroupID parent_group_id)
|
||||
{
|
||||
EnforceCompanyModeValid(false);
|
||||
EnforcePrecondition(false, IsValidGroup(group_id));
|
||||
EnforcePrecondition(false, IsValidGroup(parent_group_id));
|
||||
|
||||
@@ -87,6 +92,7 @@
|
||||
|
||||
/* static */ bool ScriptGroup::EnableAutoReplaceProtection(GroupID group_id, bool enable)
|
||||
{
|
||||
EnforceCompanyModeValid(false);
|
||||
EnforcePrecondition(false, IsValidGroup(group_id));
|
||||
|
||||
return ScriptObject::DoCommand(0, group_id | GroupFlags::GF_REPLACE_PROTECTION, enable ? 1 : 0, CMD_SET_GROUP_FLAG);
|
||||
@@ -101,6 +107,7 @@
|
||||
|
||||
/* static */ SQInteger ScriptGroup::GetNumEngines(GroupID group_id, EngineID engine_id)
|
||||
{
|
||||
EnforceCompanyModeValid(-1);
|
||||
if (!IsValidGroup(group_id) && group_id != GROUP_DEFAULT && group_id != GROUP_ALL) return -1;
|
||||
|
||||
return GetGroupNumEngines(ScriptObject::GetCompany(), group_id, engine_id);
|
||||
@@ -108,6 +115,7 @@
|
||||
|
||||
/* static */ SQInteger ScriptGroup::GetNumVehicles(GroupID group_id, ScriptVehicle::VehicleType vehicle_type)
|
||||
{
|
||||
EnforceCompanyModeValid(-1);
|
||||
bool valid_group = IsValidGroup(group_id);
|
||||
if (!valid_group && group_id != GROUP_DEFAULT && group_id != GROUP_ALL) return -1;
|
||||
if (!valid_group && (vehicle_type < ScriptVehicle::VT_RAIL || vehicle_type > ScriptVehicle::VT_AIR)) return -1;
|
||||
@@ -117,6 +125,7 @@
|
||||
|
||||
/* static */ bool ScriptGroup::MoveVehicle(GroupID group_id, VehicleID vehicle_id)
|
||||
{
|
||||
EnforceCompanyModeValid(false);
|
||||
EnforcePrecondition(false, IsValidGroup(group_id) || group_id == GROUP_DEFAULT);
|
||||
EnforcePrecondition(false, ScriptVehicle::IsPrimaryVehicle(vehicle_id));
|
||||
|
||||
@@ -125,6 +134,7 @@
|
||||
|
||||
/* static */ bool ScriptGroup::EnableWagonRemoval(bool enable_removal)
|
||||
{
|
||||
EnforceCompanyModeValid(false);
|
||||
if (HasWagonRemoval() == enable_removal) return true;
|
||||
|
||||
return ScriptObject::DoCommand(0, 0, enable_removal ? 1 : 0, CMD_CHANGE_COMPANY_SETTING, "company.renew_keep_length");
|
||||
@@ -132,11 +142,13 @@
|
||||
|
||||
/* static */ bool ScriptGroup::HasWagonRemoval()
|
||||
{
|
||||
EnforceCompanyModeValid(false);
|
||||
return ::Company::Get(ScriptObject::GetCompany())->settings.renew_keep_length;
|
||||
}
|
||||
|
||||
/* static */ bool ScriptGroup::SetAutoReplace(GroupID group_id, EngineID engine_id_old, EngineID engine_id_new)
|
||||
{
|
||||
EnforceCompanyModeValid(false);
|
||||
EnforcePrecondition(false, IsValidGroup(group_id) || group_id == GROUP_DEFAULT || group_id == GROUP_ALL);
|
||||
EnforcePrecondition(false, ScriptEngine::IsBuildable(engine_id_new));
|
||||
|
||||
@@ -145,6 +157,7 @@
|
||||
|
||||
/* static */ EngineID ScriptGroup::GetEngineReplacement(GroupID group_id, EngineID engine_id)
|
||||
{
|
||||
EnforceCompanyModeValid(::INVALID_ENGINE);
|
||||
if (!IsValidGroup(group_id) && group_id != GROUP_DEFAULT && group_id != GROUP_ALL) return ::INVALID_ENGINE;
|
||||
|
||||
return ::EngineReplacementForCompany(Company::Get(ScriptObject::GetCompany()), engine_id, group_id);
|
||||
@@ -152,6 +165,7 @@
|
||||
|
||||
/* static */ bool ScriptGroup::StopAutoReplace(GroupID group_id, EngineID engine_id)
|
||||
{
|
||||
EnforceCompanyModeValid(false);
|
||||
EnforcePrecondition(false, IsValidGroup(group_id) || group_id == GROUP_DEFAULT || group_id == GROUP_ALL);
|
||||
|
||||
return ScriptObject::DoCommand(0, group_id << 16, (::INVALID_ENGINE << 16) | engine_id, CMD_SET_AUTOREPLACE);
|
||||
@@ -202,6 +216,7 @@
|
||||
|
||||
/* static */ bool ScriptGroup::SetPrimaryColour(GroupID group_id, ScriptCompany::Colours colour)
|
||||
{
|
||||
EnforceCompanyModeValid(false);
|
||||
EnforcePrecondition(false, IsValidGroup(group_id));
|
||||
|
||||
return ScriptObject::DoCommand(0, group_id, colour << 16, CMD_SET_GROUP_LIVERY);
|
||||
@@ -209,6 +224,7 @@
|
||||
|
||||
/* static */ bool ScriptGroup::SetSecondaryColour(GroupID group_id, ScriptCompany::Colours colour)
|
||||
{
|
||||
EnforceCompanyModeValid(false);
|
||||
EnforcePrecondition(false, IsValidGroup(group_id));
|
||||
|
||||
return ScriptObject::DoCommand(0, group_id, (1 << 8) | (colour << 16), CMD_SET_GROUP_LIVERY);
|
||||
|
||||
@@ -41,6 +41,7 @@ public:
|
||||
* Create a new group.
|
||||
* @param vehicle_type The type of vehicle to create a group for.
|
||||
* @param parent_group_id The parent group id to create this group under, INVALID_GROUP for top-level.
|
||||
* @game @pre ScriptCompanyMode::IsValid().
|
||||
* @return The GroupID of the new group, or an invalid GroupID when
|
||||
* it failed. Check the return value using IsValidGroup(). In test-mode
|
||||
* 0 is returned if it was successful; any other value indicates failure.
|
||||
@@ -52,6 +53,7 @@ public:
|
||||
* given group will move to the GROUP_DEFAULT.
|
||||
* @param group_id The group to delete.
|
||||
* @pre IsValidGroup(group_id).
|
||||
* @game @pre ScriptCompanyMode::IsValid().
|
||||
* @return True if and only if the group was successfully deleted.
|
||||
*/
|
||||
static bool DeleteGroup(GroupID group_id);
|
||||
@@ -70,6 +72,7 @@ public:
|
||||
* @param name The name for the group (can be either a raw string, or a ScriptText object).
|
||||
* @pre IsValidGroup(group_id).
|
||||
* @pre name != null && len(name) != 0
|
||||
* @game @pre ScriptCompanyMode::IsValid().
|
||||
* @exception ScriptError::ERR_NAME_IS_NOT_UNIQUE
|
||||
* @return True if and only if the name was changed.
|
||||
*/
|
||||
@@ -89,6 +92,7 @@ public:
|
||||
* @param parent_group_id The parent group to set.
|
||||
* @pre IsValidGroup(group_id).
|
||||
* @pre IsValidGroup(parent_group_id).
|
||||
* @game @pre ScriptCompanyMode::IsValid().
|
||||
* @return True if and only if the parent group was changed.
|
||||
*/
|
||||
static bool SetParent(GroupID group_id, GroupID parent_group_id);
|
||||
@@ -107,6 +111,7 @@ public:
|
||||
* @param group_id The group to change the protection for.
|
||||
* @param enable True if protection should be enabled.
|
||||
* @pre IsValidGroup(group_id).
|
||||
* @game @pre ScriptCompanyMode::IsValid().
|
||||
* @return True if and only if the protection was successfully changed.
|
||||
*/
|
||||
static bool EnableAutoReplaceProtection(GroupID group_id, bool enable);
|
||||
@@ -124,6 +129,7 @@ public:
|
||||
* @param group_id The group to get the number of engines in.
|
||||
* @param engine_id The engine id to count.
|
||||
* @pre IsValidGroup(group_id) || group_id == GROUP_ALL || group_id == GROUP_DEFAULT.
|
||||
* @game @pre ScriptCompanyMode::IsValid().
|
||||
* @return The number of engines with id engine_id in the group with id group_id.
|
||||
*/
|
||||
static SQInteger GetNumEngines(GroupID group_id, EngineID engine_id);
|
||||
@@ -135,6 +141,7 @@ public:
|
||||
* @pre IsValidGroup(group_id) || group_id == GROUP_ALL || group_id == GROUP_DEFAULT.
|
||||
* @pre IsValidGroup(group_id) || vehicle_type == ScriptVehicle::VT_ROAD || vehicle_type == ScriptVehicle::VT_RAIL ||
|
||||
* vehicle_type == ScriptVehicle::VT_WATER || vehicle_type == ScriptVehicle::VT_AIR
|
||||
* @game @pre ScriptCompanyMode::IsValid().
|
||||
* @return The total number of vehicles in the group with id group_id and it's sub-groups.
|
||||
* @note If the group is valid (neither GROUP_ALL nor GROUP_DEFAULT), the value of
|
||||
* vehicle_type is retrieved from the group itself and not from the input value.
|
||||
@@ -148,6 +155,7 @@ public:
|
||||
* @param vehicle_id The vehicle to move to the group.
|
||||
* @pre IsValidGroup(group_id) || group_id == GROUP_DEFAULT.
|
||||
* @pre ScriptVehicle::IsPrimaryVehicle(vehicle_id).
|
||||
* @game @pre ScriptCompanyMode::IsValid().
|
||||
* @return True if and only if the vehicle was successfully moved to the group.
|
||||
* @note A vehicle can be in only one group at the same time. To remove it from
|
||||
* a group, move it to another or to GROUP_DEFAULT. Moving the vehicle to the
|
||||
@@ -161,12 +169,14 @@ public:
|
||||
* If enabled, wagons are removed from the end of the vehicle until it
|
||||
* fits in the same number of tiles as it did before.
|
||||
* @param keep_length If true, wagons will be removed if the new engine is longer.
|
||||
* @game @pre ScriptCompanyMode::IsValid().
|
||||
* @return True if and only if the value was successfully changed.
|
||||
*/
|
||||
static bool EnableWagonRemoval(bool keep_length);
|
||||
|
||||
/**
|
||||
* Get the current status of wagon removal.
|
||||
* @game @pre ScriptCompanyMode::IsValid().
|
||||
* @return Whether or not wagon removal is enabled.
|
||||
*/
|
||||
static bool HasWagonRemoval();
|
||||
@@ -179,6 +189,7 @@ public:
|
||||
* @param engine_id_new The engine id to replace with.
|
||||
* @pre IsValidGroup(group_id) || group_id == GROUP_DEFAULT || group_id == GROUP_ALL.
|
||||
* @pre ScriptEngine.IsBuildable(engine_id_new).
|
||||
* @game @pre ScriptCompanyMode::IsValid().
|
||||
* @return True if and if the replacing was successfully started.
|
||||
* @note To stop autoreplacing engine_id_old, call StopAutoReplace(group_id, engine_id_old).
|
||||
*/
|
||||
@@ -189,6 +200,7 @@ public:
|
||||
* @param group_id The group to get the replacement from.
|
||||
* @param engine_id The engine that is being replaced.
|
||||
* @pre IsValidGroup(group_id) || group_id == GROUP_DEFAULT || group_id == GROUP_ALL.
|
||||
* @game @pre ScriptCompanyMode::IsValid().
|
||||
* @return The EngineID that is replacing engine_id or an invalid EngineID
|
||||
* in case engine_id is not begin replaced.
|
||||
*/
|
||||
@@ -199,6 +211,7 @@ public:
|
||||
* @param group_id The group to stop replacing the engine in.
|
||||
* @param engine_id The engine id to stop replacing with another engine.
|
||||
* @pre IsValidGroup(group_id) || group_id == GROUP_DEFAULT || group_id == GROUP_ALL.
|
||||
* @game @pre ScriptCompanyMode::IsValid().
|
||||
* @return True if and if the replacing was successfully stopped.
|
||||
*/
|
||||
static bool StopAutoReplace(GroupID group_id, EngineID engine_id);
|
||||
@@ -232,6 +245,7 @@ public:
|
||||
* @param group_id The group id to set the colour of.
|
||||
* @param colour Colour to set.
|
||||
* @pre IsValidGroup(group_id).
|
||||
* @game @pre ScriptCompanyMode::IsValid().
|
||||
* @return True iff the colour was set successfully.
|
||||
*/
|
||||
static bool SetPrimaryColour(GroupID group_id, ScriptCompany::Colours colour);
|
||||
@@ -241,6 +255,7 @@ public:
|
||||
* @param group_id The group id to set the colour of.
|
||||
* @param colour Colour to set.
|
||||
* @pre IsValidGroup(group_id).
|
||||
* @game @pre ScriptCompanyMode::IsValid().
|
||||
* @return True iff the colour was set successfully.
|
||||
*/
|
||||
static bool SetSecondaryColour(GroupID group_id, ScriptCompany::Colours colour);
|
||||
|
||||
@@ -9,12 +9,14 @@
|
||||
|
||||
#include "../../stdafx.h"
|
||||
#include "script_grouplist.hpp"
|
||||
#include "script_error.hpp"
|
||||
#include "../../group.h"
|
||||
|
||||
#include "../../safeguards.h"
|
||||
|
||||
ScriptGroupList::ScriptGroupList()
|
||||
{
|
||||
EnforceDeityOrCompanyModeValid_Void();
|
||||
for (const Group *g : Group::Iterate()) {
|
||||
if (g->owner == ScriptObject::GetCompany()) this->AddItem(g->index);
|
||||
}
|
||||
|
||||
@@ -52,6 +52,7 @@
|
||||
{
|
||||
CCountedPtr<Text> counter(text);
|
||||
|
||||
EnforceDeityMode(false);
|
||||
EnforcePrecondition(false, IsValidIndustry(industry_id));
|
||||
|
||||
return ScriptObject::DoCommand(0, industry_id, 0, CMD_INDUSTRY_SET_TEXT, text != nullptr ? text->GetEncodedText().c_str() : "");
|
||||
@@ -267,6 +268,7 @@
|
||||
|
||||
/* static */ bool ScriptIndustry::SetExclusiveSupplier(IndustryID industry_id, ScriptCompany::CompanyID company_id)
|
||||
{
|
||||
EnforceDeityMode(false);
|
||||
EnforcePrecondition(false, IsValidIndustry(industry_id));
|
||||
|
||||
auto company = ScriptCompany::ResolveCompanyID(company_id);
|
||||
@@ -286,6 +288,7 @@
|
||||
|
||||
/* static */ bool ScriptIndustry::SetExclusiveConsumer(IndustryID industry_id, ScriptCompany::CompanyID company_id)
|
||||
{
|
||||
EnforceDeityMode(false);
|
||||
EnforcePrecondition(false, IsValidIndustry(industry_id));
|
||||
|
||||
auto company = ScriptCompany::ResolveCompanyID(company_id);
|
||||
|
||||
@@ -85,6 +85,7 @@ public:
|
||||
* Set the custom text of an industry, shown in the GUI.
|
||||
* @param industry_id The industry to set the custom text of.
|
||||
* @param text The text to set it to (can be either a raw string, or a ScriptText object). If null, or an empty string, is passed, the text will be removed.
|
||||
* @pre ScriptCompanyMode::IsDeity().
|
||||
* @pre IsValidIndustry(industry_id).
|
||||
* @return True if the action succeeded.
|
||||
* @api -ai
|
||||
@@ -286,6 +287,7 @@ public:
|
||||
* @param industry_id The index of the industry.
|
||||
* @param company_id The company to set (ScriptCompany::COMPANY_INVALID to reset).
|
||||
* @pre IsValidIndustry(industry_id).
|
||||
* @pre ScriptCompanyMode::IsDeity().
|
||||
* @return True if the action succeeded.
|
||||
* @api -ai
|
||||
*/
|
||||
@@ -306,6 +308,7 @@ public:
|
||||
* @param industry_id The index of the industry.
|
||||
* @param company_id The company to set (ScriptCompany::COMPANY_INVALID to reset).
|
||||
* @pre IsValidIndustry(industry_id).
|
||||
* @pre ScriptCompanyMode::IsDeity().
|
||||
* @return True if the action succeeded.
|
||||
* @api -ai
|
||||
*/
|
||||
|
||||
@@ -118,6 +118,7 @@
|
||||
|
||||
/* static */ bool ScriptIndustryType::BuildIndustry(IndustryType industry_type, TileIndex tile)
|
||||
{
|
||||
EnforceDeityOrCompanyModeValid(false);
|
||||
EnforcePrecondition(false, CanBuildIndustry(industry_type));
|
||||
EnforcePrecondition(false, ScriptMap::IsValidTile(tile));
|
||||
|
||||
@@ -128,6 +129,7 @@
|
||||
|
||||
/* static */ bool ScriptIndustryType::ProspectIndustry(IndustryType industry_type)
|
||||
{
|
||||
EnforceDeityOrCompanyModeValid(false);
|
||||
EnforcePrecondition(false, CanProspectIndustry(industry_type));
|
||||
|
||||
uint32 seed = ScriptBase::Rand();
|
||||
|
||||
@@ -23,6 +23,7 @@
|
||||
{
|
||||
CCountedPtr<Text> counter(text);
|
||||
|
||||
EnforceDeityMode(false);
|
||||
EnforcePrecondition(false, text != nullptr);
|
||||
const std::string &encoded = text->GetEncodedText();
|
||||
EnforcePreconditionEncodedText(false, encoded);
|
||||
|
||||
@@ -62,6 +62,7 @@ public:
|
||||
* @pre text != null.
|
||||
* @pre company == COMPANY_INVALID || ResolveCompanyID(company) != COMPANY_INVALID.
|
||||
* @pre The \a reference condition must be fulfilled.
|
||||
* @pre ScriptCompanyMode::IsDeity().
|
||||
*/
|
||||
static bool Create(NewsType type, Text *text, ScriptCompany::CompanyID company, NewsReferenceType ref_type, SQInteger reference);
|
||||
};
|
||||
|
||||
@@ -319,7 +319,7 @@ ScriptObject::ActiveInstance::~ActiveInstance()
|
||||
throw Script_FatalError("You are not allowed to execute any DoCommand (even indirect) in your constructor, Save(), Load(), and any valuator.");
|
||||
}
|
||||
|
||||
if (ScriptCompanyMode::IsValid() && !::Company::IsValidID(ScriptObject::GetCompany())) {
|
||||
if (!ScriptCompanyMode::IsDeity() && !ScriptCompanyMode::IsValid()) {
|
||||
ScriptObject::SetLastError(ScriptError::ERR_PRECONDITION_INVALID_COMPANY);
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -38,6 +38,7 @@
|
||||
|
||||
/* static */ bool ScriptObjectType::BuildObject(ObjectType object_type, SQInteger view, TileIndex tile)
|
||||
{
|
||||
EnforceDeityOrCompanyModeValid(false);
|
||||
EnforcePrecondition(false, IsValidObjectType(object_type));
|
||||
EnforcePrecondition(false, view >= 0 && view < GetViews(object_type));
|
||||
EnforcePrecondition(false, ScriptMap::IsValidTile(tile));
|
||||
|
||||
@@ -385,6 +385,7 @@ static int ScriptOrderPositionToRealOrderPosition(VehicleID vehicle_id, ScriptOr
|
||||
|
||||
/* static */ bool ScriptOrder::SetOrderJumpTo(VehicleID vehicle_id, OrderPosition order_position, OrderPosition jump_to)
|
||||
{
|
||||
EnforceCompanyModeValid(false);
|
||||
EnforcePrecondition(false, IsValidVehicleOrder(vehicle_id, order_position));
|
||||
EnforcePrecondition(false, order_position != ORDER_CURRENT && IsConditionalOrder(vehicle_id, order_position));
|
||||
EnforcePrecondition(false, IsValidVehicleOrder(vehicle_id, jump_to) && jump_to != ORDER_CURRENT);
|
||||
@@ -395,6 +396,7 @@ static int ScriptOrderPositionToRealOrderPosition(VehicleID vehicle_id, ScriptOr
|
||||
|
||||
/* static */ bool ScriptOrder::SetOrderCondition(VehicleID vehicle_id, OrderPosition order_position, OrderCondition condition)
|
||||
{
|
||||
EnforceCompanyModeValid(false);
|
||||
EnforcePrecondition(false, IsValidVehicleOrder(vehicle_id, order_position));
|
||||
EnforcePrecondition(false, order_position != ORDER_CURRENT && IsConditionalOrder(vehicle_id, order_position));
|
||||
EnforcePrecondition(false, condition >= OC_LOAD_PERCENTAGE && condition <= OC_REMAINING_LIFETIME);
|
||||
@@ -405,6 +407,7 @@ static int ScriptOrderPositionToRealOrderPosition(VehicleID vehicle_id, ScriptOr
|
||||
|
||||
/* static */ bool ScriptOrder::SetOrderCompareFunction(VehicleID vehicle_id, OrderPosition order_position, CompareFunction compare)
|
||||
{
|
||||
EnforceCompanyModeValid(false);
|
||||
EnforcePrecondition(false, IsValidVehicleOrder(vehicle_id, order_position));
|
||||
EnforcePrecondition(false, order_position != ORDER_CURRENT && IsConditionalOrder(vehicle_id, order_position));
|
||||
EnforcePrecondition(false, compare >= CF_EQUALS && compare <= CF_IS_FALSE);
|
||||
@@ -415,6 +418,7 @@ static int ScriptOrderPositionToRealOrderPosition(VehicleID vehicle_id, ScriptOr
|
||||
|
||||
/* static */ bool ScriptOrder::SetOrderCompareValue(VehicleID vehicle_id, OrderPosition order_position, SQInteger value)
|
||||
{
|
||||
EnforceCompanyModeValid(false);
|
||||
EnforcePrecondition(false, IsValidVehicleOrder(vehicle_id, order_position));
|
||||
EnforcePrecondition(false, order_position != ORDER_CURRENT && IsConditionalOrder(vehicle_id, order_position));
|
||||
EnforcePrecondition(false, value >= 0 && value < 2048);
|
||||
@@ -426,6 +430,7 @@ static int ScriptOrderPositionToRealOrderPosition(VehicleID vehicle_id, ScriptOr
|
||||
|
||||
/* static */ bool ScriptOrder::SetStopLocation(VehicleID vehicle_id, OrderPosition order_position, StopLocation stop_location)
|
||||
{
|
||||
EnforceCompanyModeValid(false);
|
||||
EnforcePrecondition(false, IsValidVehicleOrder(vehicle_id, order_position));
|
||||
EnforcePrecondition(false, ScriptVehicle::GetVehicleType(vehicle_id) == ScriptVehicle::VT_RAIL);
|
||||
EnforcePrecondition(false, IsGotoStationOrder(vehicle_id, order_position));
|
||||
@@ -439,6 +444,7 @@ static int ScriptOrderPositionToRealOrderPosition(VehicleID vehicle_id, ScriptOr
|
||||
|
||||
/* static */ bool ScriptOrder::SetOrderRefit(VehicleID vehicle_id, OrderPosition order_position, CargoID refit_cargo)
|
||||
{
|
||||
EnforceCompanyModeValid(false);
|
||||
EnforcePrecondition(false, IsValidVehicleOrder(vehicle_id, order_position));
|
||||
EnforcePrecondition(false, IsGotoStationOrder(vehicle_id, order_position) || (IsGotoDepotOrder(vehicle_id, order_position) && refit_cargo != CT_AUTO_REFIT));
|
||||
EnforcePrecondition(false, ScriptCargo::IsValidCargo(refit_cargo) || refit_cargo == CT_AUTO_REFIT || refit_cargo == CT_NO_REFIT);
|
||||
@@ -450,6 +456,7 @@ static int ScriptOrderPositionToRealOrderPosition(VehicleID vehicle_id, ScriptOr
|
||||
|
||||
/* static */ bool ScriptOrder::AppendOrder(VehicleID vehicle_id, TileIndex destination, ScriptOrderFlags order_flags)
|
||||
{
|
||||
EnforceCompanyModeValid(false);
|
||||
EnforcePrecondition(false, ScriptVehicle::IsPrimaryVehicle(vehicle_id));
|
||||
EnforcePrecondition(false, AreOrderFlagsValid(destination, order_flags));
|
||||
|
||||
@@ -458,6 +465,7 @@ static int ScriptOrderPositionToRealOrderPosition(VehicleID vehicle_id, ScriptOr
|
||||
|
||||
/* static */ bool ScriptOrder::AppendConditionalOrder(VehicleID vehicle_id, OrderPosition jump_to)
|
||||
{
|
||||
EnforceCompanyModeValid(false);
|
||||
EnforcePrecondition(false, ScriptVehicle::IsPrimaryVehicle(vehicle_id));
|
||||
EnforcePrecondition(false, IsValidVehicleOrder(vehicle_id, jump_to));
|
||||
|
||||
@@ -469,6 +477,7 @@ static int ScriptOrderPositionToRealOrderPosition(VehicleID vehicle_id, ScriptOr
|
||||
/* IsValidVehicleOrder is not good enough because it does not allow appending. */
|
||||
if (order_position == ORDER_CURRENT) order_position = ScriptOrder::ResolveOrderPosition(vehicle_id, order_position);
|
||||
|
||||
EnforceCompanyModeValid(false);
|
||||
EnforcePrecondition(false, ScriptVehicle::IsPrimaryVehicle(vehicle_id));
|
||||
EnforcePrecondition(false, order_position >= 0 && order_position <= ::Vehicle::Get(vehicle_id)->GetNumManualOrders());
|
||||
EnforcePrecondition(false, AreOrderFlagsValid(destination, order_flags));
|
||||
@@ -522,6 +531,7 @@ static int ScriptOrderPositionToRealOrderPosition(VehicleID vehicle_id, ScriptOr
|
||||
/* IsValidVehicleOrder is not good enough because it does not allow appending. */
|
||||
if (order_position == ORDER_CURRENT) order_position = ScriptOrder::ResolveOrderPosition(vehicle_id, order_position);
|
||||
|
||||
EnforceCompanyModeValid(false);
|
||||
EnforcePrecondition(false, ScriptVehicle::IsPrimaryVehicle(vehicle_id));
|
||||
EnforcePrecondition(false, order_position >= 0 && order_position <= ::Vehicle::Get(vehicle_id)->GetNumManualOrders());
|
||||
EnforcePrecondition(false, IsValidVehicleOrder(vehicle_id, jump_to) && jump_to != ORDER_CURRENT);
|
||||
@@ -536,6 +546,7 @@ static int ScriptOrderPositionToRealOrderPosition(VehicleID vehicle_id, ScriptOr
|
||||
{
|
||||
order_position = ScriptOrder::ResolveOrderPosition(vehicle_id, order_position);
|
||||
|
||||
EnforceCompanyModeValid(false);
|
||||
EnforcePrecondition(false, IsValidVehicleOrder(vehicle_id, order_position));
|
||||
|
||||
int order_pos = ScriptOrderPositionToRealOrderPosition(vehicle_id, order_position);
|
||||
@@ -546,6 +557,7 @@ static int ScriptOrderPositionToRealOrderPosition(VehicleID vehicle_id, ScriptOr
|
||||
{
|
||||
next_order = ScriptOrder::ResolveOrderPosition(vehicle_id, next_order);
|
||||
|
||||
EnforceCompanyModeValid(false);
|
||||
EnforcePrecondition(false, IsValidVehicleOrder(vehicle_id, next_order));
|
||||
|
||||
int order_pos = ScriptOrderPositionToRealOrderPosition(vehicle_id, next_order);
|
||||
@@ -582,6 +594,7 @@ static void _DoCommandReturnSetOrderFlags(class ScriptInstance *instance)
|
||||
|
||||
order_position = ScriptOrder::ResolveOrderPosition(vehicle_id, order_position);
|
||||
|
||||
EnforceCompanyModeValid(false);
|
||||
EnforcePrecondition(false, IsValidVehicleOrder(vehicle_id, order_position));
|
||||
|
||||
if (_settings_game.order.nonstop_only && ::Vehicle::Get(vehicle_id)->IsGroundVehicle()) order_flags |= OF_NON_STOP_INTERMEDIATE;
|
||||
@@ -642,6 +655,7 @@ static void _DoCommandReturnSetOrderFlags(class ScriptInstance *instance)
|
||||
order_position_move = ScriptOrder::ResolveOrderPosition(vehicle_id, order_position_move);
|
||||
order_position_target = ScriptOrder::ResolveOrderPosition(vehicle_id, order_position_target);
|
||||
|
||||
EnforceCompanyModeValid(false);
|
||||
EnforcePrecondition(false, IsValidVehicleOrder(vehicle_id, order_position_move));
|
||||
EnforcePrecondition(false, IsValidVehicleOrder(vehicle_id, order_position_target));
|
||||
EnforcePrecondition(false, order_position_move != order_position_target);
|
||||
@@ -653,6 +667,7 @@ static void _DoCommandReturnSetOrderFlags(class ScriptInstance *instance)
|
||||
|
||||
/* static */ bool ScriptOrder::CopyOrders(VehicleID vehicle_id, VehicleID main_vehicle_id)
|
||||
{
|
||||
EnforceCompanyModeValid(false);
|
||||
EnforcePrecondition(false, ScriptVehicle::IsPrimaryVehicle(vehicle_id));
|
||||
EnforcePrecondition(false, ScriptVehicle::IsPrimaryVehicle(main_vehicle_id));
|
||||
|
||||
@@ -661,6 +676,7 @@ static void _DoCommandReturnSetOrderFlags(class ScriptInstance *instance)
|
||||
|
||||
/* static */ bool ScriptOrder::ShareOrders(VehicleID vehicle_id, VehicleID main_vehicle_id)
|
||||
{
|
||||
EnforceCompanyModeValid(false);
|
||||
EnforcePrecondition(false, ScriptVehicle::IsPrimaryVehicle(vehicle_id));
|
||||
EnforcePrecondition(false, ScriptVehicle::IsPrimaryVehicle(main_vehicle_id));
|
||||
|
||||
@@ -669,6 +685,7 @@ static void _DoCommandReturnSetOrderFlags(class ScriptInstance *instance)
|
||||
|
||||
/* static */ bool ScriptOrder::UnshareOrders(VehicleID vehicle_id)
|
||||
{
|
||||
EnforceCompanyModeValid(false);
|
||||
EnforcePrecondition(false, ScriptVehicle::IsPrimaryVehicle(vehicle_id));
|
||||
|
||||
return ScriptObject::DoCommand(0, vehicle_id | CO_UNSHARE << 30, 0, CMD_CLONE_ORDER);
|
||||
|
||||
@@ -356,6 +356,7 @@ public:
|
||||
* @pre IsValidVehicleOrder(vehicle_id, order_position).
|
||||
* @pre IsValidVehicleOrder(vehicle_id, jump_to).
|
||||
* @pre order_position != ORDER_CURRENT && IsConditionalOrder(vehicle_id, order_position).
|
||||
* @game @pre ScriptCompanyMode::IsValid().
|
||||
* @return Whether the order has been/can be changed.
|
||||
* @api -game
|
||||
*/
|
||||
@@ -369,6 +370,7 @@ public:
|
||||
* @pre IsValidVehicleOrder(vehicle_id, order_position).
|
||||
* @pre order_position != ORDER_CURRENT && IsConditionalOrder(vehicle_id, order_position).
|
||||
* @pre condition >= OC_LOAD_PERCENTAGE && condition <= OC_UNCONDITIONALLY.
|
||||
* @game @pre ScriptCompanyMode::IsValid().
|
||||
* @return Whether the order has been/can be changed.
|
||||
* @api -game
|
||||
*/
|
||||
@@ -382,6 +384,7 @@ public:
|
||||
* @pre IsValidVehicleOrder(vehicle_id, order_position).
|
||||
* @pre order_position != ORDER_CURRENT && IsConditionalOrder(vehicle_id, order_position).
|
||||
* @pre compare >= CF_EQUALS && compare <= CF_IS_FALSE.
|
||||
* @game @pre ScriptCompanyMode::IsValid().
|
||||
* @return Whether the order has been/can be changed.
|
||||
* @api -game
|
||||
*/
|
||||
@@ -395,6 +398,7 @@ public:
|
||||
* @pre IsValidVehicleOrder(vehicle_id, order_position).
|
||||
* @pre order_position != ORDER_CURRENT && IsConditionalOrder(vehicle_id, order_position).
|
||||
* @pre value >= 0 && value < 2048.
|
||||
* @game @pre ScriptCompanyMode::IsValid().
|
||||
* @return Whether the order has been/can be changed.
|
||||
* @api -game
|
||||
*/
|
||||
@@ -409,6 +413,7 @@ public:
|
||||
* @pre ScriptVehicle::GetVehicleType(vehicle_id) == ScriptVehicle::VT_RAIL.
|
||||
* @pre IsGotoStationOrder(vehicle_id, order_position).
|
||||
* @pre stop_location >= STOPLOCATION_NEAR && stop_location <= STOPLOCATION_FAR
|
||||
* @game @pre ScriptCompanyMode::IsValid().
|
||||
* @return Whether the order has been/can be changed.
|
||||
* @api -game
|
||||
*/
|
||||
@@ -422,6 +427,7 @@ public:
|
||||
* @pre IsValidVehicleOrder(vehicle_id, order_position).
|
||||
* @pre IsGotoStationOrder(vehicle_id, order_position) || (IsGotoDepotOrder(vehicle_id, order_position) && refit_cargo != CT_AUTO_REFIT).
|
||||
* @pre ScriptCargo::IsValidCargo(refit_cargo) || refit_cargo == CT_AUTO_REFIT || refit_cargo == CT_NO_REFIT
|
||||
* @game @pre ScriptCompanyMode::IsValid().
|
||||
* @return Whether the order has been/can be changed.
|
||||
* @api -game
|
||||
*/
|
||||
@@ -434,6 +440,7 @@ public:
|
||||
* @param order_flags The flags given to the order.
|
||||
* @pre ScriptVehicle::IsPrimaryVehicle(vehicle_id).
|
||||
* @pre AreOrderFlagsValid(destination, order_flags).
|
||||
* @game @pre ScriptCompanyMode::IsValid().
|
||||
* @exception ScriptError::ERR_OWNED_BY_ANOTHER_COMPANY
|
||||
* @exception ScriptOrder::ERR_ORDER_TOO_MANY
|
||||
* @exception ScriptOrder::ERR_ORDER_TOO_FAR_AWAY_FROM_PREVIOUS_DESTINATION
|
||||
@@ -448,6 +455,7 @@ public:
|
||||
* @param jump_to The OrderPosition to jump to if the condition is true.
|
||||
* @pre ScriptVehicle::IsPrimaryVehicle(vehicle_id).
|
||||
* @pre IsValidVehicleOrder(vehicle_id, jump_to).
|
||||
* @game @pre ScriptCompanyMode::IsValid().
|
||||
* @exception ScriptError::ERR_OWNED_BY_ANOTHER_COMPANY
|
||||
* @exception ScriptOrder::ERR_ORDER_TOO_MANY
|
||||
* @return True if and only if the order was appended.
|
||||
@@ -464,6 +472,7 @@ public:
|
||||
* @pre ScriptVehicle::IsPrimaryVehicle(vehicle_id)
|
||||
* @pre IsValidVehicleOrder(vehicle_id, order_position).
|
||||
* @pre AreOrderFlagsValid(destination, order_flags).
|
||||
* @game @pre ScriptCompanyMode::IsValid().
|
||||
* @exception ScriptError::ERR_OWNED_BY_ANOTHER_COMPANY
|
||||
* @exception ScriptOrder::ERR_ORDER_TOO_MANY
|
||||
* @exception ScriptOrder::ERR_ORDER_TOO_FAR_AWAY_FROM_PREVIOUS_DESTINATION
|
||||
@@ -480,6 +489,7 @@ public:
|
||||
* @pre ScriptVehicle::IsPrimaryVehicle(vehicle_id).
|
||||
* @pre IsValidVehicleOrder(vehicle_id, order_position).
|
||||
* @pre IsValidVehicleOrder(vehicle_id, jump_to).
|
||||
* @game @pre ScriptCompanyMode::IsValid().
|
||||
* @exception ScriptError::ERR_OWNED_BY_ANOTHER_COMPANY
|
||||
* @exception ScriptOrder::ERR_ORDER_TOO_MANY
|
||||
* @return True if and only if the order was inserted.
|
||||
@@ -492,6 +502,7 @@ public:
|
||||
* @param vehicle_id The vehicle to remove the order from.
|
||||
* @param order_position The order to remove from the order list.
|
||||
* @pre IsValidVehicleOrder(vehicle_id, order_position).
|
||||
* @game @pre ScriptCompanyMode::IsValid().
|
||||
* @exception ScriptError::ERR_OWNED_BY_ANOTHER_COMPANY
|
||||
* @return True if and only if the order was removed.
|
||||
* @api -game
|
||||
@@ -512,6 +523,7 @@ public:
|
||||
* @pre IsValidVehicleOrder(vehicle_id, order_position).
|
||||
* @pre AreOrderFlagsValid(GetOrderDestination(vehicle_id, order_position), order_flags).
|
||||
* @pre (order_flags & OF_GOTO_NEAREST_DEPOT) == (GetOrderFlags(vehicle_id, order_position) & OF_GOTO_NEAREST_DEPOT).
|
||||
* @game @pre ScriptCompanyMode::IsValid().
|
||||
* @exception ScriptError::ERR_OWNED_BY_ANOTHER_COMPANY
|
||||
* @return True if and only if the order was changed.
|
||||
* @api -game
|
||||
@@ -526,6 +538,7 @@ public:
|
||||
* @pre IsValidVehicleOrder(vehicle_id, order_position_move).
|
||||
* @pre IsValidVehicleOrder(vehicle_id, order_position_target).
|
||||
* @pre order_position_move != order_position_target.
|
||||
* @game @pre ScriptCompanyMode::IsValid().
|
||||
* @exception ScriptError::ERR_OWNED_BY_ANOTHER_COMPANY
|
||||
* @return True if and only if the order was moved.
|
||||
* @note If the order is moved to a lower place (e.g. from 7 to 2)
|
||||
@@ -541,6 +554,7 @@ public:
|
||||
* @param vehicle_id The vehicle that should skip some orders.
|
||||
* @param next_order The order the vehicle should skip to.
|
||||
* @pre IsValidVehicleOrder(vehicle_id, next_order).
|
||||
* @game @pre ScriptCompanyMode::IsValid().
|
||||
* @exception ScriptError::ERR_OWNED_BY_ANOTHER_COMPANY
|
||||
* @return True if and only the current order was changed.
|
||||
* @api -game
|
||||
@@ -554,6 +568,7 @@ public:
|
||||
* @param main_vehicle_id The vehicle to copy the orders from.
|
||||
* @pre ScriptVehicle::IsPrimaryVehicle(vehicle_id).
|
||||
* @pre ScriptVehicle::IsPrimaryVehicle(main_vehicle_id).
|
||||
* @game @pre ScriptCompanyMode::IsValid().
|
||||
* @exception ScriptError::ERR_OWNED_BY_ANOTHER_COMPANY
|
||||
* @exception ScriptOrder::ERR_ORDER_TOO_MANY
|
||||
* @exception ScriptOrder::ERR_ORDER_AIRCRAFT_NOT_ENOUGH_RANGE
|
||||
@@ -569,6 +584,7 @@ public:
|
||||
* @param main_vehicle_id The vehicle to share the orders with.
|
||||
* @pre ScriptVehicle::IsPrimaryVehicle(vehicle_id).
|
||||
* @pre ScriptVehicle::IsPrimaryVehicle(main_vehicle_id).
|
||||
* @game @pre ScriptCompanyMode::IsValid().
|
||||
* @exception ScriptError::ERR_OWNED_BY_ANOTHER_COMPANY
|
||||
* @exception ScriptOrder::ERR_ORDER_AIRCRAFT_NOT_ENOUGH_RANGE
|
||||
* @return True if and only if the sharing succeeded.
|
||||
@@ -581,6 +597,7 @@ public:
|
||||
* After unsharing orders, the orders list of the vehicle is empty.
|
||||
* @param vehicle_id The vehicle to remove from the shared order list.
|
||||
* @pre ScriptVehicle::IsPrimaryVehicle(vehicle_id).
|
||||
* @game @pre ScriptCompanyMode::IsValid().
|
||||
* @return True if and only if the unsharing succeeded.
|
||||
* @api -game
|
||||
*/
|
||||
|
||||
@@ -66,6 +66,7 @@
|
||||
|
||||
/* static */ bool ScriptRail::IsRailTypeAvailable(RailType rail_type)
|
||||
{
|
||||
EnforceDeityOrCompanyModeValid(false);
|
||||
if ((::RailType)rail_type >= RAILTYPE_END) return false;
|
||||
|
||||
return ScriptCompanyMode::IsDeity() || ::HasRailtypeAvail(ScriptObject::GetCompany(), (::RailType)rail_type);
|
||||
|
||||
@@ -9,13 +9,14 @@
|
||||
|
||||
#include "../../stdafx.h"
|
||||
#include "script_railtypelist.hpp"
|
||||
#include "script_companymode.hpp"
|
||||
#include "script_error.hpp"
|
||||
#include "../../rail.h"
|
||||
|
||||
#include "../../safeguards.h"
|
||||
|
||||
ScriptRailTypeList::ScriptRailTypeList()
|
||||
{
|
||||
EnforceDeityOrCompanyModeValid_Void();
|
||||
for (RailType rt = RAILTYPE_BEGIN; rt != RAILTYPE_END; rt++) {
|
||||
if (ScriptCompanyMode::IsDeity() || ::HasRailtypeAvail(ScriptObject::GetCompany(), rt)) this->AddItem(rt);
|
||||
}
|
||||
|
||||
@@ -63,6 +63,7 @@
|
||||
|
||||
/* static */ bool ScriptRoad::IsRoadTypeAvailable(RoadType road_type)
|
||||
{
|
||||
EnforceDeityOrCompanyModeValid(false);
|
||||
return (::RoadType)road_type < ROADTYPE_END && ::HasRoadTypeAvail(ScriptObject::GetCompany(), (::RoadType)road_type) && !HasBit(GetRoadTypeInfo((::RoadType)road_type)->extra_flags, RXTF_NOT_AVAILABLE_AI_GS);
|
||||
}
|
||||
|
||||
@@ -502,6 +503,7 @@ static bool NeighbourHasReachableRoad(::RoadType rt, TileIndex start_tile, DiagD
|
||||
|
||||
/* static */ bool ScriptRoad::_BuildRoadInternal(TileIndex start, TileIndex end, bool one_way, bool full)
|
||||
{
|
||||
EnforceDeityOrCompanyModeValid(false);
|
||||
EnforcePrecondition(false, start != end);
|
||||
EnforcePrecondition(false, ::IsValidTile(start));
|
||||
EnforcePrecondition(false, ::IsValidTile(end));
|
||||
|
||||
@@ -15,6 +15,7 @@
|
||||
|
||||
ScriptRoadTypeList::ScriptRoadTypeList(ScriptRoad::RoadTramTypes rtts)
|
||||
{
|
||||
EnforceDeityOrCompanyModeValid_Void();
|
||||
for (RoadType rt = ROADTYPE_BEGIN; rt != ROADTYPE_END; rt++) {
|
||||
if (!HasBit(rtts, GetRoadTramType(rt))) continue;
|
||||
if ((ScriptCompanyMode::IsDeity() || ::HasRoadTypeAvail(ScriptObject::GetCompany(), rt)) &&
|
||||
|
||||
@@ -20,6 +20,7 @@
|
||||
|
||||
/* static */ bool ScriptSign::IsValidSign(SignID sign_id)
|
||||
{
|
||||
EnforceDeityOrCompanyModeValid(false);
|
||||
const Sign *si = ::Sign::GetIfValid(sign_id);
|
||||
return si != nullptr && (si->owner == ScriptObject::GetCompany() || si->owner == OWNER_DEITY);
|
||||
}
|
||||
@@ -35,6 +36,7 @@
|
||||
{
|
||||
CCountedPtr<Text> counter(name);
|
||||
|
||||
EnforceDeityOrCompanyModeValid(false);
|
||||
EnforcePrecondition(false, IsValidSign(sign_id));
|
||||
EnforcePrecondition(false, name != nullptr);
|
||||
const std::string &text = name->GetDecodedText();
|
||||
@@ -62,6 +64,7 @@
|
||||
|
||||
/* static */ bool ScriptSign::RemoveSign(SignID sign_id)
|
||||
{
|
||||
EnforceDeityOrCompanyModeValid(false);
|
||||
EnforcePrecondition(false, IsValidSign(sign_id));
|
||||
return ScriptObject::DoCommand(0, sign_id, 0, CMD_RENAME_SIGN, "");
|
||||
}
|
||||
@@ -70,6 +73,7 @@
|
||||
{
|
||||
CCountedPtr<Text> counter(name);
|
||||
|
||||
EnforceDeityOrCompanyModeValid(INVALID_SIGN);
|
||||
EnforcePrecondition(INVALID_SIGN, ::IsValidTile(location));
|
||||
EnforcePrecondition(INVALID_SIGN, name != nullptr);
|
||||
const std::string &text = name->GetDecodedText();
|
||||
|
||||
@@ -20,6 +20,7 @@
|
||||
|
||||
/* static */ bool ScriptStation::IsValidStation(StationID station_id)
|
||||
{
|
||||
EnforceDeityOrCompanyModeValid(false);
|
||||
const Station *st = ::Station::GetIfValid(station_id);
|
||||
return st != nullptr && (st->owner == ScriptObject::GetCompany() || ScriptCompanyMode::IsDeity() || st->owner == OWNER_NONE);
|
||||
}
|
||||
@@ -238,6 +239,7 @@ template<bool Tfrom, bool Tvia>
|
||||
|
||||
/* static */ bool ScriptStation::OpenCloseAirport(StationID station_id)
|
||||
{
|
||||
EnforceCompanyModeValid(false);
|
||||
EnforcePrecondition(false, IsValidStation(station_id));
|
||||
EnforcePrecondition(false, HasStationType(station_id, STATION_AIRPORT));
|
||||
|
||||
|
||||
@@ -287,6 +287,7 @@ public:
|
||||
/**
|
||||
* Toggle the open/closed state of an airport.
|
||||
* @param station_id The airport to modify.
|
||||
* @game @pre ScriptCompanyMode::IsValid().
|
||||
* @pre IsValidStation(station_id).
|
||||
* @pre HasStationType(station_id, STATION_AIRPORT).
|
||||
* @return True if the state was toggled successfully.
|
||||
|
||||
@@ -18,6 +18,7 @@
|
||||
|
||||
ScriptStationList::ScriptStationList(ScriptStation::StationType station_type)
|
||||
{
|
||||
EnforceDeityOrCompanyModeValid_Void();
|
||||
for (Station *st : Station::Iterate()) {
|
||||
if ((st->owner == ScriptObject::GetCompany() || ScriptCompanyMode::IsDeity()) && (st->facilities & station_type) != 0) this->AddItem(st->index);
|
||||
}
|
||||
|
||||
@@ -32,6 +32,7 @@
|
||||
|
||||
/* static */ bool ScriptSubsidy::Create(CargoID cargo_type, SubsidyParticipantType from_type, SQInteger from_id, SubsidyParticipantType to_type, SQInteger to_id)
|
||||
{
|
||||
EnforceDeityMode(false);
|
||||
EnforcePrecondition(false, ScriptCargo::IsValidCargo(cargo_type));
|
||||
EnforcePrecondition(false, from_type == SPT_INDUSTRY || from_type == SPT_TOWN);
|
||||
EnforcePrecondition(false, to_type == SPT_INDUSTRY || to_type == SPT_TOWN);
|
||||
|
||||
@@ -55,6 +55,7 @@ public:
|
||||
* @param to_type The type of the subsidy on the 'to' side.
|
||||
* @param to_id The ID of the 'to' side.
|
||||
* @return True if the action succeeded.
|
||||
* @pre ScriptCompanyMode::IsDeity().
|
||||
* @pre ScriptCargo::IsValidCargo(cargo_type)
|
||||
* @pre from_type == SPT_INDUSTRY || from_type == SPT_TOWN.
|
||||
* @pre to_type == SPT_INDUSTRY || to_type == SPT_TOWN.
|
||||
|
||||
@@ -22,6 +22,7 @@
|
||||
|
||||
/* static */ bool ScriptTile::IsBuildable(TileIndex tile)
|
||||
{
|
||||
EnforceDeityOrCompanyModeValid(false);
|
||||
if (!::IsValidTile(tile)) return false;
|
||||
|
||||
switch (::GetTileType(tile)) {
|
||||
@@ -274,6 +275,7 @@
|
||||
|
||||
/* static */ bool ScriptTile::DemolishTile(TileIndex tile)
|
||||
{
|
||||
EnforceDeityOrCompanyModeValid(false);
|
||||
EnforcePrecondition(false, ::IsValidTile(tile));
|
||||
|
||||
return ScriptObject::DoCommand(tile, 0, 0, CMD_LANDSCAPE_CLEAR);
|
||||
|
||||
@@ -44,6 +44,7 @@
|
||||
{
|
||||
CCountedPtr<Text> counter(name);
|
||||
|
||||
EnforceDeityMode(false);
|
||||
EnforcePrecondition(false, IsValidTown(town_id));
|
||||
std::string text;
|
||||
if (name != nullptr) {
|
||||
@@ -58,6 +59,7 @@
|
||||
{
|
||||
CCountedPtr<Text> counter(text);
|
||||
|
||||
EnforceDeityMode(false);
|
||||
EnforcePrecondition(false, IsValidTown(town_id));
|
||||
|
||||
return ScriptObject::DoCommand(::Town::Get(town_id)->xy, town_id, 0, CMD_TOWN_SET_TEXT, text != nullptr ? text->GetEncodedText().c_str() : "");
|
||||
@@ -125,6 +127,7 @@
|
||||
|
||||
/* static */ bool ScriptTown::SetCargoGoal(TownID town_id, ScriptCargo::TownEffect towneffect_id, SQInteger goal)
|
||||
{
|
||||
EnforceDeityMode(false);
|
||||
EnforcePrecondition(false, IsValidTown(town_id));
|
||||
EnforcePrecondition(false, ScriptCargo::IsValidTownEffect(towneffect_id));
|
||||
|
||||
@@ -155,6 +158,7 @@
|
||||
|
||||
/* static */ bool ScriptTown::SetGrowthRate(TownID town_id, SQInteger days_between_town_growth)
|
||||
{
|
||||
EnforceDeityMode(false);
|
||||
EnforcePrecondition(false, IsValidTown(town_id));
|
||||
uint16 growth_rate;
|
||||
switch (days_between_town_growth) {
|
||||
@@ -283,6 +287,7 @@
|
||||
|
||||
CCountedPtr<Text> counter(name);
|
||||
|
||||
EnforceDeityOrCompanyModeValid(false);
|
||||
EnforcePrecondition(false, ScriptCompanyMode::IsDeity() || _settings_game.economy.found_town != TF_FORBIDDEN);
|
||||
EnforcePrecondition(false, ::IsValidTile(tile));
|
||||
EnforcePrecondition(false, size == TOWN_SIZE_SMALL || size == TOWN_SIZE_MEDIUM || size == TOWN_SIZE_LARGE)
|
||||
|
||||
@@ -149,6 +149,7 @@ public:
|
||||
* @param town_id The town to rename
|
||||
* @param name The new name of the town. If null, or an empty string, is passed, the town name will be reset to the default name.
|
||||
* @pre IsValidTown(town_id).
|
||||
* @pre ScriptCompanyMode::IsDeity().
|
||||
* @return True if the action succeeded.
|
||||
* @api -ai
|
||||
*/
|
||||
@@ -159,6 +160,7 @@ public:
|
||||
* @param town_id The town to set the custom text of.
|
||||
* @param text The text to set it to (can be either a raw string, or a ScriptText object). If null, or an empty string, is passed, the text will be removed.
|
||||
* @pre IsValidTown(town_id).
|
||||
* @pre ScriptCompanyMode::IsDeity().
|
||||
* @return True if the action succeeded.
|
||||
* @api -ai
|
||||
*/
|
||||
@@ -236,6 +238,7 @@ public:
|
||||
* The value will be clamped to 0 .. MAX(uint32).
|
||||
* @pre IsValidTown(town_id).
|
||||
* @pre ScriptCargo::IsValidTownEffect(towneffect_id).
|
||||
* @pre ScriptCompanyMode::IsDeity().
|
||||
* @return True if the action succeeded.
|
||||
* @api -ai
|
||||
*/
|
||||
@@ -392,6 +395,7 @@ public:
|
||||
* The value will be clamped to 0 .. MAX(uint32).
|
||||
* @pre IsValidTown(town_id).
|
||||
* @pre houses > 0.
|
||||
* @pre ScriptCompanyMode::IsDeity().
|
||||
* @return True if the action succeeded.
|
||||
* @api -ai
|
||||
*/
|
||||
|
||||
@@ -79,6 +79,7 @@ static void _DoCommandReturnBuildTunnel1(class ScriptInstance *instance)
|
||||
|
||||
/* static */ bool ScriptTunnel::BuildTunnel(ScriptVehicle::VehicleType vehicle_type, TileIndex start)
|
||||
{
|
||||
EnforceDeityOrCompanyModeValid(false);
|
||||
EnforcePrecondition(false, ::IsValidTile(start));
|
||||
EnforcePrecondition(false, vehicle_type == ScriptVehicle::VT_RAIL || vehicle_type == ScriptVehicle::VT_ROAD);
|
||||
EnforcePrecondition(false, vehicle_type != ScriptVehicle::VT_RAIL || ScriptRail::IsRailTypeAvailable(ScriptRail::GetCurrentRailType()));
|
||||
@@ -105,6 +106,8 @@ static void _DoCommandReturnBuildTunnel1(class ScriptInstance *instance)
|
||||
|
||||
/* static */ bool ScriptTunnel::_BuildTunnelRoad1()
|
||||
{
|
||||
EnforceDeityOrCompanyModeValid(false);
|
||||
|
||||
/* Build the piece of road on the 'start' side of the tunnel */
|
||||
TileIndex end = ScriptObject::GetCallbackVariable(0);
|
||||
TileIndex start = ScriptTunnel::GetOtherTunnelEnd(end);
|
||||
@@ -117,6 +120,8 @@ static void _DoCommandReturnBuildTunnel1(class ScriptInstance *instance)
|
||||
|
||||
/* static */ bool ScriptTunnel::_BuildTunnelRoad2()
|
||||
{
|
||||
EnforceDeityOrCompanyModeValid(false);
|
||||
|
||||
/* Build the piece of road on the 'end' side of the tunnel */
|
||||
TileIndex end = ScriptObject::GetCallbackVariable(0);
|
||||
TileIndex start = ScriptTunnel::GetOtherTunnelEnd(end);
|
||||
|
||||
@@ -27,6 +27,7 @@
|
||||
|
||||
/* static */ bool ScriptVehicle::IsValidVehicle(VehicleID vehicle_id)
|
||||
{
|
||||
EnforceDeityOrCompanyModeValid(false);
|
||||
const Vehicle *v = ::Vehicle::GetIfValid(vehicle_id);
|
||||
return v != nullptr && (v->owner == ScriptObject::GetCompany() || ScriptCompanyMode::IsDeity()) && (v->IsPrimaryVehicle() || (v->type == VEH_TRAIN && ::Train::From(v)->IsFreeWagon()));
|
||||
}
|
||||
|
||||
@@ -20,6 +20,7 @@
|
||||
|
||||
ScriptVehicleList::ScriptVehicleList()
|
||||
{
|
||||
EnforceDeityOrCompanyModeValid_Void();
|
||||
for (const Vehicle *v : Vehicle::Iterate()) {
|
||||
if ((v->owner == ScriptObject::GetCompany() || ScriptCompanyMode::IsDeity()) && (v->IsPrimaryVehicle() || (v->type == VEH_TRAIN && ::Train::From(v)->IsFreeWagon()))) this->AddItem(v->index);
|
||||
}
|
||||
@@ -27,6 +28,7 @@ ScriptVehicleList::ScriptVehicleList()
|
||||
|
||||
ScriptVehicleList_Station::ScriptVehicleList_Station(StationID station_id)
|
||||
{
|
||||
EnforceDeityOrCompanyModeValid_Void();
|
||||
if (!ScriptBaseStation::IsValidBaseStation(station_id)) return;
|
||||
|
||||
for (const Vehicle *v : Vehicle::Iterate()) {
|
||||
@@ -43,6 +45,7 @@ ScriptVehicleList_Station::ScriptVehicleList_Station(StationID station_id)
|
||||
|
||||
ScriptVehicleList_Depot::ScriptVehicleList_Depot(TileIndex tile)
|
||||
{
|
||||
EnforceDeityOrCompanyModeValid_Void();
|
||||
if (!ScriptMap::IsValidTile(tile)) return;
|
||||
|
||||
DestinationID dest;
|
||||
@@ -100,6 +103,7 @@ ScriptVehicleList_SharedOrders::ScriptVehicleList_SharedOrders(VehicleID vehicle
|
||||
|
||||
ScriptVehicleList_Group::ScriptVehicleList_Group(GroupID group_id)
|
||||
{
|
||||
EnforceDeityOrCompanyModeValid_Void();
|
||||
if (!ScriptGroup::IsValidGroup((ScriptGroup::GroupID)group_id)) return;
|
||||
|
||||
for (const Vehicle *v : Vehicle::Iterate()) {
|
||||
@@ -111,6 +115,7 @@ ScriptVehicleList_Group::ScriptVehicleList_Group(GroupID group_id)
|
||||
|
||||
ScriptVehicleList_DefaultGroup::ScriptVehicleList_DefaultGroup(ScriptVehicle::VehicleType vehicle_type)
|
||||
{
|
||||
EnforceDeityOrCompanyModeValid_Void();
|
||||
if (vehicle_type < ScriptVehicle::VT_RAIL || vehicle_type > ScriptVehicle::VT_AIR) return;
|
||||
|
||||
for (const Vehicle *v : Vehicle::Iterate()) {
|
||||
|
||||
@@ -17,6 +17,7 @@
|
||||
|
||||
/* static */ bool ScriptWaypoint::IsValidWaypoint(StationID waypoint_id)
|
||||
{
|
||||
EnforceDeityOrCompanyModeValid(false);
|
||||
const Waypoint *wp = ::Waypoint::GetIfValid(waypoint_id);
|
||||
return wp != nullptr && (wp->owner == ScriptObject::GetCompany() || ScriptCompanyMode::IsDeity() || wp->owner == OWNER_NONE);
|
||||
}
|
||||
|
||||
@@ -17,6 +17,7 @@
|
||||
|
||||
ScriptWaypointList::ScriptWaypointList(ScriptWaypoint::WaypointType waypoint_type)
|
||||
{
|
||||
EnforceDeityOrCompanyModeValid_Void();
|
||||
for (const Waypoint *wp : Waypoint::Iterate()) {
|
||||
if ((wp->facilities & waypoint_type) &&
|
||||
(wp->owner == ScriptObject::GetCompany() || ScriptCompanyMode::IsDeity() || wp->owner == OWNER_NONE)) this->AddItem(wp->index);
|
||||
|
||||
@@ -875,9 +875,7 @@ struct ScriptDebugWindow : public Window {
|
||||
}
|
||||
if (this->autoscroll) {
|
||||
int scroll_pos = std::max(0, log->used - this->vscroll->GetCapacity());
|
||||
if (scroll_pos != this->vscroll->GetPosition()) {
|
||||
this->vscroll->SetPosition(scroll_pos);
|
||||
|
||||
if (this->vscroll->SetPosition(scroll_pos)) {
|
||||
/* We need a repaint */
|
||||
this->SetWidgetDirty(WID_SCRD_SCROLLBAR);
|
||||
this->SetWidgetDirty(WID_SCRD_LOG_PANEL);
|
||||
|
||||
@@ -772,10 +772,8 @@ public:
|
||||
*/
|
||||
bool SetPosition(int position)
|
||||
{
|
||||
assert(position >= 0);
|
||||
assert(this->count <= this->cap ? (position == 0) : (position + this->cap <= this->count));
|
||||
uint16 old_pos = this->pos;
|
||||
this->pos = position;
|
||||
this->pos = Clamp(position, 0, std::max(this->count - this->cap, 0));
|
||||
return this->pos != old_pos;
|
||||
}
|
||||
|
||||
@@ -794,7 +792,7 @@ public:
|
||||
case SS_BIG: difference *= this->cap; break;
|
||||
default: break;
|
||||
}
|
||||
return this->SetPosition(Clamp(this->pos + difference, 0, std::max(this->count - this->cap, 0)));
|
||||
return this->SetPosition(this->pos + difference);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user