Changeset - r24688:9c99e0da7aad
[Not reviewed]
master
0 9 0
dP - 3 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
 
@@ -263,13 +263,13 @@ static const Command _command_proc_table
 
	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
src/industry.h
Show inline comments
 
@@ -30,12 +30,19 @@ 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 */
 
@@ -88,12 +95,13 @@ struct Industry : IndustryPool::PoolItem
 
	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) {}
src/industry_cmd.cpp
Show inline comments
 
@@ -37,12 +37,14 @@
 
#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"
 
@@ -2060,60 +2062,64 @@ CommandCost CmdBuildIndustry(TileIndex t
 
/**
 
 * 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();
 
}
src/industry_gui.cpp
Show inline comments
 
@@ -910,12 +910,19 @@ public:
 
						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);
src/saveload/industry_sl.cpp
Show inline comments
 
@@ -69,12 +69,13 @@ static const SaveLoad _industry_desc[] =
 

	
 
	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()
 
};
 

	
src/saveload/saveload.h
Show inline comments
 
@@ -320,12 +320,13 @@ enum SaveLoadVersion : uint16 {
 
	 */
 
	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 {
src/script/api/game_changelog.hpp
Show inline comments
 
@@ -27,12 +27,13 @@
 
 * \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:
src/script/api/script_industry.cpp
Show inline comments
 
@@ -12,12 +12,13 @@
 
#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>
 

	
 
@@ -44,12 +45,26 @@
 
	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);
src/script/api/script_industry.hpp
Show inline comments
 
@@ -79,12 +79,22 @@ public:
 
	 * @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.
0 comments (0 inline, 0 general)