File diff r24687:4a2fa1e7f559 → r24688:9c99e0da7aad
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();
 
}