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
 
@@ -266,7 +266,7 @@ static const Command _command_proc_table
 
	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
src/industry.h
Show inline comments
 
@@ -33,6 +33,13 @@ enum ProductionLevels {
 
	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.
 
@@ -91,6 +98,7 @@ struct Industry : IndustryPool::PoolItem
 
	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
 

	
src/industry_cmd.cpp
Show inline comments
 
@@ -40,6 +40,8 @@
 
#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"
 
@@ -2063,16 +2065,13 @@ CommandCost CmdBuildIndustry(TileIndex t
 
 * @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)
 
@@ -2082,10 +2081,10 @@ CommandCost CmdIndustryCtrl(TileIndex ti
 
	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;
 
@@ -2093,15 +2092,15 @@ CommandCost CmdIndustryCtrl(TileIndex ti
 
			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;
 
@@ -2111,6 +2110,13 @@ CommandCost CmdIndustryCtrl(TileIndex ti
 
			break;
 
		}
 

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

	
 
		default:
 
			NOT_REACHED();
 
	}
src/industry_gui.cpp
Show inline comments
 
@@ -913,6 +913,13 @@ public:
 
				}
 
			}
 
		}
 

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

	
src/saveload/industry_sl.cpp
Show inline comments
 
@@ -72,6 +72,7 @@ static const SaveLoad _industry_desc[] =
 

	
 
	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
 

	
src/saveload/saveload.h
Show inline comments
 
@@ -323,6 +323,7 @@ enum SaveLoadVersion : uint16 {
 

	
 
	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
 
};
src/script/api/game_changelog.hpp
Show inline comments
 
@@ -30,6 +30,7 @@
 
 * \li GSIndustry::SetControlFlags
 
 * \li GSIndustry::SetExclusiveConsumer
 
 * \li GSIndustry::SetExclusiveSupplier
 
 * \li GSIndustry::SetText
 
 * \li GSStoryPage::MakePushButtonReference
 
 * \li GSStoryPage::MakeTileButtonReference
 
 * \li GSStoryPage::MakeVehicleButtonReference
src/script/api/script_industry.cpp
Show inline comments
 
@@ -15,6 +15,7 @@
 
#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"
 
@@ -47,6 +48,20 @@
 
	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;
src/script/api/script_industry.hpp
Show inline comments
 
@@ -82,6 +82,16 @@ public:
 
	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.
0 comments (0 inline, 0 general)