Skip to content

Instantly share code, notes, and snippets.

@SamuXarick
Created January 30, 2023 22:35
Show Gist options
  • Save SamuXarick/14f49e2ed77c2b76fedd6d6775267124 to your computer and use it in GitHub Desktop.
Save SamuXarick/14f49e2ed77c2b76fedd6d6775267124 to your computer and use it in GitHub Desktop.
Industry placed on a canal logic
if (HasTileWaterGround(cur_tile) && GetWaterClass(cur_tile) == WATER_CLASS_CANAL) {
Owner oc = GetCanalOwner(cur_tile);
bool is_canal = IsWaterTile(cur_tile);
/* We are in one of these two situations:
* 1. When prospecting, _current_company is OWNER_TOWN (founder can be company_0-14 / OWNER_DEITY)
* 2. When not prospecting, _current_company can be company_0-14 / OWNER_NONE / OWNER_DEITY (founder is equal to _current_company)
*
* For situation 1:
* a) On a clear water canal:
* - Allow prospecting on clear water canals in which the founder is the canal owner, or when the canal has no owner, or
* when 'build_on_competitor_canal' is enabled and the canal owner is different than that of the founder.
* b) On a clearable object built over the canal:
* - Never allow prospecting on objects even if these can be cleared.
*
* For situation 2:
* a) On a clear water canal:
* - Allow random and deity creation on clear water canals when 'build_on_competitor_canal' is enabled, or when canal
* has no owner.
* - Allow company funded creation on clear water canals in which the funding company is the canal owner, or when the canal
* has no owner, or when 'build_on_competitor_canal' is enabled and the canal owner is different than that of the funding
* company.
* b) On a clearable object built over the canal:
* - Allow random and deity creation on clearable objects which have no owner, but never on objects which have an owner,
* even if the canal under the object has no owner.
* - Allow company funded creation on clearable objects in which the funding company is the object owner. And then, when
* the canal under the object is owned by the funding company, or when 'build_on_competitor_canal' and the canal owner is
* different than that of the funding company.
*/
Backup<CompanyID> cur_company(_current_company, is_canal ? founder : _current_company, FILE_LINE);
ret = Command<CMD_LANDSCAPE_CLEAR>::Do(DC_AUTO | DC_NO_TEST_TOWN_RATING | DC_NO_MODIFY_TOWN_RATING, cur_tile);
CommandCost ownership = is_canal ? CheckTileOwnership(cur_tile) : CheckOwnership(oc, cur_tile);
cur_company.Restore();
if (is_canal) {
/* This is a clear water canal */
if (ownership.Failed() && oc != OWNER_NONE &&
_game_mode != GM_EDITOR && !_settings_game.construction.build_on_competitor_canal) return ownership;
} else {
/* This is a station, object, or industry on a canal */
if (ret.Failed()) return ret;
if (ownership.Failed() && oc != OWNER_NONE && !_settings_game.construction.build_on_competitor_canal) return ownership;
}
} else {
/* Clear the tiles, but do not affect town ratings */
ret = Command<CMD_LANDSCAPE_CLEAR>::Do(DC_AUTO | DC_NO_TEST_TOWN_RATING | DC_NO_MODIFY_TOWN_RATING, cur_tile);
if (ret.Failed()) return ret;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment