Feature: Set exclusive access to industry from GS (#8115)

(cherry picked from commit 9a45a0f535)
This commit is contained in:
Pavel Stupnikov
2020-12-22 16:29:48 +03:00
committed by Jonathan G Rennison
parent 4d97fbc814
commit f39a00d676
11 changed files with 137 additions and 5 deletions

View File

@@ -17,6 +17,7 @@
#include "town.h"
#include "news_func.h"
#include "cheat_type.h"
#include "company_base.h"
#include "genworld.h"
#include "tree_map.h"
#include "tunnel_map.h"
@@ -542,7 +543,7 @@ static bool TransportIndustryGoods(TileIndex tile)
i->this_month_production[j] += cw;
uint am = MoveGoodsToStation(i->produced_cargo[j], cw, ST_INDUSTRY, i->index, &i->stations_near);
uint am = MoveGoodsToStation(i->produced_cargo[j], cw, ST_INDUSTRY, i->index, &i->stations_near, i->exclusive_consumer);
i->this_month_transported[j] += am;
moved_cargo |= (am != 0);
@@ -990,6 +991,9 @@ static void ChangeTileOwner_Industry(TileIndex tile, Owner old_owner, Owner new_
/* If the founder merges, the industry was created by the merged company */
Industry *i = Industry::GetByTile(tile);
if (i->founder == old_owner) i->founder = (new_owner == INVALID_OWNER) ? OWNER_NONE : new_owner;
if (i->exclusive_supplier == old_owner) i->exclusive_supplier = new_owner;
if (i->exclusive_consumer == old_owner) i->exclusive_consumer = new_owner;
}
/**
@@ -1836,6 +1840,9 @@ static void DoCreateNewIndustry(Industry *i, TileIndex tile, IndustryType type,
* else, chosen layout + 1 */
i->selected_layout = (byte)(layout_index + 1);
i->exclusive_supplier = INVALID_OWNER;
i->exclusive_consumer = INVALID_OWNER;
i->prod_level = PRODLEVEL_DEFAULT;
/* Call callbacks after the regular fields got initialised. */
@@ -2131,8 +2138,13 @@ CommandCost CmdBuildIndustry(TileIndex tile, DoCommandFlag flags, uint32 p1, uin
* @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 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
* @return Empty cost or an error.
*/
@@ -2154,6 +2166,24 @@ CommandCost CmdIndustryCtrl(TileIndex tile, DoCommandFlag flags, uint32 p1, uint
break;
}
case 1:
case 2: {
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) {
ind->exclusive_supplier = company_id;
} else {
ind->exclusive_consumer = company_id;
}
}
break;
}
default:
NOT_REACHED();
}