Changeset - r24688:9c99e0da7aad
[Not reviewed]
master
0 9 0
dP - 4 years ago 2021-01-15 14:38:14
dp@dpointer.org
Feature: Allow GameScripts to add additional text to Industry view window
9 files changed with 60 insertions and 11 deletions:
0 comments (0 inline, 0 general)
src/command.cpp
Show inline comments
 
@@ -257,25 +257,25 @@ static const Command _command_proc_table
 
	DEF_CMD(CmdForceTrainProceed,                              0, CMDT_VEHICLE_MANAGEMENT    ), // CMD_FORCE_TRAIN_PROCEED
 
	DEF_CMD(CmdReverseTrainDirection,                          0, CMDT_VEHICLE_MANAGEMENT    ), // CMD_REVERSE_TRAIN_DIRECTION
 

	
 
	DEF_CMD(CmdClearOrderBackup,                   CMD_CLIENT_ID, CMDT_SERVER_SETTING        ), // CMD_CLEAR_ORDER_BACKUP
 
	DEF_CMD(CmdModifyOrder,                                    0, CMDT_ROUTE_MANAGEMENT      ), // CMD_MODIFY_ORDER
 
	DEF_CMD(CmdSkipToOrder,                                    0, CMDT_ROUTE_MANAGEMENT      ), // CMD_SKIP_TO_ORDER
 
	DEF_CMD(CmdDeleteOrder,                                    0, CMDT_ROUTE_MANAGEMENT      ), // CMD_DELETE_ORDER
 
	DEF_CMD(CmdInsertOrder,                                    0, CMDT_ROUTE_MANAGEMENT      ), // CMD_INSERT_ORDER
 

	
 
	DEF_CMD(CmdChangeServiceInt,                               0, CMDT_VEHICLE_MANAGEMENT    ), // CMD_CHANGE_SERVICE_INT
 

	
 
	DEF_CMD(CmdBuildIndustry,                          CMD_DEITY, CMDT_LANDSCAPE_CONSTRUCTION), // CMD_BUILD_INDUSTRY
 
	DEF_CMD(CmdIndustryCtrl,                           CMD_DEITY, CMDT_OTHER_MANAGEMENT      ), // CMD_INDUSTRY_CTRL
 
	DEF_CMD(CmdIndustryCtrl,            CMD_STR_CTRL | CMD_DEITY, CMDT_OTHER_MANAGEMENT      ), // CMD_INDUSTRY_CTRL
 

	
 
	DEF_CMD(CmdSetCompanyManagerFace,                          0, CMDT_OTHER_MANAGEMENT      ), // CMD_SET_COMPANY_MANAGER_FACE
 
	DEF_CMD(CmdSetCompanyColour,                               0, CMDT_OTHER_MANAGEMENT      ), // CMD_SET_COMPANY_COLOUR
 

	
 
	DEF_CMD(CmdIncreaseLoan,                                   0, CMDT_MONEY_MANAGEMENT      ), // CMD_INCREASE_LOAN
 
	DEF_CMD(CmdDecreaseLoan,                                   0, CMDT_MONEY_MANAGEMENT      ), // CMD_DECREASE_LOAN
 

	
 
	DEF_CMD(CmdWantEnginePreview,                              0, CMDT_VEHICLE_MANAGEMENT    ), // CMD_WANT_ENGINE_PREVIEW
 
	DEF_CMD(CmdEngineCtrl,                             CMD_DEITY, CMDT_VEHICLE_MANAGEMENT    ), // CMD_ENGINE_CTRL
 

	
 
	DEF_CMD(CmdRenameVehicle,                                  0, CMDT_OTHER_MANAGEMENT      ), // CMD_RENAME_VEHICLE
 
	DEF_CMD(CmdRenameEngine,                          CMD_SERVER, CMDT_OTHER_MANAGEMENT      ), // CMD_RENAME_ENGINE
src/industry.h
Show inline comments
 
@@ -24,24 +24,31 @@ extern IndustryPool _industry_pool;
 
/**
 
 * Production level maximum, minimum and default values.
 
 * It is not a value been really used in order to change, but rather an indicator
 
 * of how the industry is behaving.
 
 */
 
enum ProductionLevels {
 
	PRODLEVEL_CLOSURE = 0x00,  ///< signal set to actually close the industry
 
	PRODLEVEL_MINIMUM = 0x04,  ///< below this level, the industry is set to be closing
 
	PRODLEVEL_DEFAULT = 0x10,  ///< default level set when the industry is created
 
	PRODLEVEL_MAXIMUM = 0x80,  ///< the industry is running at full speed
 
};
 

	
 
enum class IndustryAction : byte {
 
	SetControlFlags = 0,       ///< Set IndustryControlFlags
 
	SetExclusiveSupplier = 1,  ///< Set exclusive supplier
 
	SetExclusiveConsumer = 2,  ///< Set exclusive consumer
 
	SetText = 3,               ///< Set additional text
 
};
 

	
 
/**
 
 * Flags to control/override the behaviour of an industry.
 
 * These flags are controlled by game scripts.
 
 */
 
enum IndustryControlFlags : byte {
 
	/** No flags in effect */
 
	INDCTL_NONE                   = 0,
 
	/** When industry production change is evaluated, rolls to decrease are ignored. */
 
	INDCTL_NO_PRODUCTION_DECREASE = 1 << 0,
 
	/** When industry production change is evaluated, rolls to increase are ignored. */
 
	INDCTL_NO_PRODUCTION_INCREASE = 1 << 1,
 
	/**
 
@@ -82,24 +89,25 @@ struct Industry : IndustryPool::PoolItem
 

	
 
	PartOfSubsidy part_of_subsidy; ///< NOSAVE: is this industry a source/destination of a subsidy?
 
	StationList stations_near;     ///< NOSAVE: List of nearby stations.
 
	mutable std::string cached_name; ///< NOSAVE: Cache of the resolved name of the industry
 

	
 
	Owner founder;                 ///< Founder of the industry
 
	Date construction_date;        ///< Date of the construction of the industry
 
	uint8 construction_type;       ///< Way the industry was constructed (@see IndustryConstructionType)
 
	Date last_cargo_accepted_at[INDUSTRY_NUM_INPUTS]; ///< Last day each cargo type was accepted by this industry
 
	byte selected_layout;          ///< Which tile layout was used when creating the industry
 
	Owner exclusive_supplier;      ///< Which company has exclusive rights to deliver cargo (INVALID_OWNER = anyone)
 
	Owner exclusive_consumer;      ///< Which company has exclusive rights to take cargo (INVALID_OWNER = anyone)
 
	std::string text;              ///< General text with additional information.
 

	
 
	uint16 random;                 ///< Random value used for randomisation of all kinds of things
 

	
 
	PersistentStorage *psa;        ///< Persistent storage for NewGRF industries.
 

	
 
	Industry(TileIndex tile = INVALID_TILE) : location(tile, 0, 0) {}
 
	~Industry();
 

	
 
	void RecomputeProductionMultipliers();
 

	
 
	/**
 
	 * Check if a given tile belongs to this industry.
src/industry_cmd.cpp
Show inline comments
 
@@ -31,24 +31,26 @@
 
#include "vehicle_func.h"
 
#include "sound_func.h"
 
#include "animated_tile_func.h"
 
#include "effectvehicle_func.h"
 
#include "effectvehicle_base.h"
 
#include "ai/ai.hpp"
 
#include "core/pool_func.hpp"
 
#include "subsidy_func.h"
 
#include "core/backup_type.hpp"
 
#include "object_base.h"
 
#include "game/game.hpp"
 
#include "error.h"
 
#include "cmd_helper.h"
 
#include "string_func.h"
 

	
 
#include "table/strings.h"
 
#include "table/industry_land.h"
 
#include "table/build_industry.h"
 

	
 
#include "safeguards.h"
 

	
 
IndustryPool _industry_pool("Industry");
 
INSTANTIATE_POOL_METHODS(Industry)
 

	
 
void ShowIndustryViewWindow(int industry);
 
void BuildOilRig(TileIndex tile);
 
@@ -2054,72 +2056,76 @@ CommandCost CmdBuildIndustry(TileIndex t
 
		AdvertiseIndustryOpening(ind);
 
	}
 

	
 
	return CommandCost(EXPENSES_OTHER, indspec->GetConstructionCost());
 
}
 

	
 
/**
 
 * Change industry properties
 
 * @param tile Unused.
 
 * @param flags Type of operation.
 
 * @param p1 IndustryID
 
 * @param p2 various bitstuffed elements
 
 * - p2 = (bit 0 - 7) - action to perform:
 
 *                      0 = set control flags
 
 *                      1 = set exclusive supplier
 
 *                      2 = set exclusive consumer
 
 * - p2 = (bit 0 - 7) - IndustryAction to perform
 
 * - p2 = (bit 8 - 15) - IndustryControlFlags
 
 *                       (only used with set control flags)
 
 * - p2 = (bit 16 - 23) - CompanyID to set or INVALID_OWNER (available to everyone) or
 
 *                        OWNER_NONE (neutral stations only) or OWNER_DEITY (no one)
 
 *                        (only used with set exclusive supplier / consumer)
 
 * @param text unused
 
 * @param text - Additional industry text (only used with set text action)
 
 * @return Empty cost or an error.
 
 */
 
CommandCost CmdIndustryCtrl(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
 
{
 
	if (_current_company != OWNER_DEITY) return CMD_ERROR;
 

	
 
	Industry *ind = Industry::GetIfValid(p1);
 
	if (ind == nullptr) return CMD_ERROR;
 

	
 
	uint8 action = GB(p2, 0, 8);
 
	auto action = static_cast<IndustryAction>(GB(p2, 0, 8));
 

	
 
	switch (action) {
 
		case 0: {
 
		case IndustryAction::SetControlFlags: {
 
			IndustryControlFlags ctlflags = (IndustryControlFlags)GB(p2, 8, 8) & INDCTL_MASK;
 

	
 
			if (flags & DC_EXEC) ind->ctlflags = ctlflags;
 

	
 
			break;
 
		}
 

	
 
		case 1:
 
		case 2: {
 
		case IndustryAction::SetExclusiveSupplier:
 
		case IndustryAction::SetExclusiveConsumer: {
 
			Owner company_id = (Owner)GB(p2, 16, 8);
 

	
 
			if (company_id != OWNER_NONE && company_id != INVALID_OWNER && company_id != OWNER_DEITY
 
				&& !Company::IsValidID(company_id)) return CMD_ERROR;
 

	
 
			if (flags & DC_EXEC) {
 
				if (action == 1) {
 
				if (action == IndustryAction::SetExclusiveSupplier) {
 
					ind->exclusive_supplier = company_id;
 
				} else {
 
					ind->exclusive_consumer = company_id;
 
				}
 
			}
 

	
 
			break;
 
		}
 

	
 
		case IndustryAction::SetText: {
 
			ind->text.clear();
 
			if (!StrEmpty(text)) ind->text = text;
 
			InvalidateWindowData(WC_INDUSTRY_VIEW, ind->index);
 
			break;
 
		}
 

	
 
		default:
 
			NOT_REACHED();
 
	}
 

	
 
	return CommandCost();
 
}
 

	
 
/**
 
 * Create a new industry of random layout.
 
 * @param tile The location to build the industry.
 
 * @param type The industry type to build.
 
 * @param creation_type The circumstances the industry is created under.
src/industry_gui.cpp
Show inline comments
 
@@ -904,24 +904,31 @@ public:
 
						y += WD_PAR_VSEP_WIDE;
 

	
 
						StartTextRefStackUsage(ind->grf_prop.grffile, 6);
 
						/* Use all the available space left from where we stand up to the
 
						 * end of the window. We ALSO enlarge the window if needed, so we
 
						 * can 'go' wild with the bottom of the window. */
 
						y = DrawStringMultiLine(left + WD_FRAMERECT_LEFT, right - WD_FRAMERECT_RIGHT, y, UINT16_MAX, message, TC_BLACK);
 
						StopTextRefStackUsage();
 
					}
 
				}
 
			}
 
		}
 

	
 
		if (!i->text.empty()) {
 
			SetDParamStr(0, i->text.c_str());
 
			y += WD_PAR_VSEP_WIDE;
 
			y = DrawStringMultiLine(left + WD_FRAMERECT_LEFT, right - WD_FRAMERECT_RIGHT, y, UINT16_MAX, STR_JUST_RAW_STRING, TC_BLACK);
 
		}
 

	
 
		return y + WD_FRAMERECT_BOTTOM;
 
	}
 

	
 
	void SetStringParameters(int widget) const override
 
	{
 
		if (widget == WID_IV_CAPTION) SetDParam(0, this->window_number);
 
	}
 

	
 
	void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize) override
 
	{
 
		if (widget == WID_IV_INFO) size->height = this->info_height;
 
	}
src/saveload/industry_sl.cpp
Show inline comments
 
@@ -63,24 +63,25 @@ static const SaveLoad _industry_desc[] =
 
	SLE_CONDVAR(Industry, construction_type,          SLE_UINT8,                 SLV_70, SL_MAX_VERSION),
 
	SLE_CONDVAR(Industry, last_cargo_accepted_at[0],  SLE_INT32,                 SLV_70, SLV_EXTEND_INDUSTRY_CARGO_SLOTS),
 
	SLE_CONDARR(Industry, last_cargo_accepted_at,     SLE_INT32, 16,            SLV_EXTEND_INDUSTRY_CARGO_SLOTS, SL_MAX_VERSION),
 
	SLE_CONDVAR(Industry, selected_layout,            SLE_UINT8,                 SLV_73, SL_MAX_VERSION),
 
	SLE_CONDVAR(Industry, exclusive_supplier,         SLE_UINT8,                 SLV_GS_INDUSTRY_CONTROL, SL_MAX_VERSION),
 
	SLE_CONDVAR(Industry, exclusive_consumer,         SLE_UINT8,                 SLV_GS_INDUSTRY_CONTROL, SL_MAX_VERSION),
 

	
 
	SLEG_CONDARR(_old_ind_persistent_storage.storage, SLE_UINT32, 16,            SLV_76, SLV_161),
 
	SLE_CONDREF(Industry, psa,                        REF_STORAGE,              SLV_161, SL_MAX_VERSION),
 

	
 
	SLE_CONDNULL(1, SLV_82, SLV_197), // random_triggers
 
	SLE_CONDVAR(Industry, random,                     SLE_UINT16,                SLV_82, SL_MAX_VERSION),
 
	SLE_CONDSSTR(Industry, text,     SLE_STR | SLF_ALLOW_CONTROL,     SLV_INDUSTRY_TEXT, SL_MAX_VERSION),
 

	
 
	SLE_CONDNULL(32, SLV_2, SLV_144), // old reserved space
 

	
 
	SLE_END()
 
};
 

	
 
static void Save_INDY()
 
{
 
	/* Write the industries */
 
	for (Industry *ind : Industry::Iterate()) {
 
		SlSetArrayIndex(ind->index);
 
		SlObject(ind, _industry_desc);
src/saveload/saveload.h
Show inline comments
 
@@ -314,24 +314,25 @@ enum SaveLoadVersion : uint16 {
 
	 * versions anyway, we simply skip the versions we know belong to
 
	 * patchpacks. This way we can present the user with a clean error
 
	 * indicate he is loading a savegame from a patchpack.
 
	 * For future patchpack creators: please follow a system like JGRPP, where
 
	 * the version is masked with 0x8000, and the true version is stored in
 
	 * its own chunk with feature toggles.
 
	 */
 
	SLV_START_PATCHPACKS,                   ///< 220  First known patchpack to use a version just above ours.
 
	SLV_END_PATCHPACKS = 286,               ///< 286  Last known patchpack to use a version just above ours.
 

	
 
	SLV_GS_INDUSTRY_CONTROL,                ///< 287  PR#7912 and PR#8115 GS industry control.
 
	SLV_VEH_MOTION_COUNTER,                 ///< 288  PR#8591 Desync safe motion counter
 
	SLV_INDUSTRY_TEXT,                      ///< 289  PR#8576 Additional GS text for industries.
 

	
 
	SL_MAX_VERSION,                         ///< Highest possible saveload version
 
};
 

	
 
/** Save or load result codes. */
 
enum SaveOrLoadResult {
 
	SL_OK     = 0, ///< completed successfully
 
	SL_ERROR  = 1, ///< error that was caught before internal structures were modified
 
	SL_REINIT = 2, ///< error that was caught in the middle of updating game state, need to clear it. (can only happen during load)
 
};
 

	
 
/** Deals with the type of the savegame, independent of extension */
src/script/api/game_changelog.hpp
Show inline comments
 
@@ -21,24 +21,25 @@
 
 * \li GSCargo::GetName
 
 * \li GSEventStoryPageButtonClick
 
 * \li GSEventStoryPageTileSelect
 
 * \li GSEventStoryPageVehicleSelect
 
 * \li GSIndustry::GetCargoLastAcceptedDate
 
 * \li GSIndustry::GetControlFlags
 
 * \li GSIndustry::GetExclusiveConsumer
 
 * \li GSIndustry::GetExclusiveSupplier
 
 * \li GSIndustry::GetLastProductionYear
 
 * \li GSIndustry::SetControlFlags
 
 * \li GSIndustry::SetExclusiveConsumer
 
 * \li GSIndustry::SetExclusiveSupplier
 
 * \li GSIndustry::SetText
 
 * \li GSStoryPage::MakePushButtonReference
 
 * \li GSStoryPage::MakeTileButtonReference
 
 * \li GSStoryPage::MakeVehicleButtonReference
 
 * \li GSPriorityQueue
 
 *
 
 * Other changes:
 
 * \li GSCompany::ChangeBankBalance takes one extra parameter to refer to a location to show text effect on
 
 *
 
 * \b 1.10.0
 
 *
 
 * API additions:
 
 * \li GSVehicle::BuildVehicleWithRefit
src/script/api/script_industry.cpp
Show inline comments
 
@@ -6,24 +6,25 @@
 
 */
 

	
 
/** @file script_industry.cpp Implementation of ScriptIndustry. */
 

	
 
#include "../../stdafx.h"
 
#include "script_industry.hpp"
 
#include "script_cargo.hpp"
 
#include "script_company.hpp"
 
#include "script_error.hpp"
 
#include "script_map.hpp"
 
#include "../../company_base.h"
 
#include "../../industry.h"
 
#include "../../string_func.h"
 
#include "../../strings_func.h"
 
#include "../../station_base.h"
 
#include "../../newgrf_industries.h"
 
#include "table/strings.h"
 
#include <numeric>
 

	
 
#include "../../safeguards.h"
 

	
 
/* static */ int32 ScriptIndustry::GetIndustryCount()
 
{
 
	return (int32)::Industry::GetNumItems();
 
}
 
@@ -38,24 +39,38 @@
 
	if (!::IsValidTile(tile) || !::IsTileType(tile, MP_INDUSTRY)) return INVALID_INDUSTRY;
 
	return ::GetIndustryIndex(tile);
 
}
 

	
 
/* static */ char *ScriptIndustry::GetName(IndustryID industry_id)
 
{
 
	if (!IsValidIndustry(industry_id)) return nullptr;
 

	
 
	::SetDParam(0, industry_id);
 
	return GetString(STR_INDUSTRY_NAME);
 
}
 

	
 
/* static */ bool ScriptIndustry::SetText(IndustryID industry_id, Text *text)
 
{
 
	CCountedPtr<Text> counter(text);
 

	
 
	const char *encoded_text = nullptr;
 
	if (text != nullptr) {
 
		encoded_text = text->GetEncodedText();
 
		EnforcePreconditionEncodedText(false, encoded_text);
 
	}
 
	EnforcePrecondition(false, IsValidIndustry(industry_id));
 

	
 
	return ScriptObject::DoCommand(0, industry_id, static_cast<uint32>(IndustryAction::SetText), CMD_INDUSTRY_CTRL, encoded_text);
 
}
 

	
 
/* static */ ScriptIndustry::CargoAcceptState ScriptIndustry::IsCargoAccepted(IndustryID industry_id, CargoID cargo_id)
 
{
 
	if (!IsValidIndustry(industry_id)) return CAS_NOT_ACCEPTED;
 
	if (!ScriptCargo::IsValidCargo(cargo_id)) return CAS_NOT_ACCEPTED;
 

	
 
	Industry *i = ::Industry::Get(industry_id);
 

	
 
	for (byte j = 0; j < lengthof(i->accepts_cargo); j++) {
 
		if (i->accepts_cargo[j] == cargo_id) {
 
			if (IndustryTemporarilyRefusesCargo(i, cargo_id)) return CAS_TEMP_REFUSED;
 
			return CAS_ACCEPTED;
 
		}
src/script/api/script_industry.hpp
Show inline comments
 
@@ -73,24 +73,34 @@ public:
 
	 */
 
	static IndustryID GetIndustryID(TileIndex tile);
 

	
 
	/**
 
	 * Get the name of the industry.
 
	 * @param industry_id The industry to get the name of.
 
	 * @pre IsValidIndustry(industry_id).
 
	 * @return The name of the industry.
 
	 */
 
	static char *GetName(IndustryID industry_id);
 

	
 
	/**
 
	 * 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 is passed, the text will be removed.
 
	 * @pre IsValidIndustry(industry_id).
 
	 * @return True if the action succeeded.
 
	 * @api -ai
 
	 */
 
	static bool SetText(IndustryID industry_id, Text *text);
 

	
 
	/**
 
	 * See whether an industry currently accepts a certain cargo.
 
	 * @param industry_id The index of the industry.
 
	 * @param cargo_id The index of the cargo.
 
	 * @pre IsValidIndustry(industry_id).
 
	 * @pre ScriptCargo::IsValidCargo(cargo_id).
 
	 * @return Whether the industry accepts, temporarily refuses or never accepts this cargo.
 
	 */
 
	static CargoAcceptState IsCargoAccepted(IndustryID industry_id, CargoID cargo_id);
 

	
 
	/**
 
	 * Get the amount of cargo stockpiled for processing.
 
	 * @param industry_id The index of the industry.
0 comments (0 inline, 0 general)