diff --git a/src/004-base/arcologyBuilding.js b/src/004-base/arcologyBuilding.js index ba1f746564abc68335c11bbca038c708fc1d3c9d..19b278a22ed77fba3c461d4a72f73ce412647953 100644 --- a/src/004-base/arcologyBuilding.js +++ b/src/004-base/arcologyBuilding.js @@ -10,6 +10,20 @@ App.Arcology.Cell.BaseCell = class extends App.Entity.Serializable { * @type {number} */ this.owner = owner; + /** + * List of classes this cell can be converted to. + * Format: "BaseCell" stands for App.Arcology.Cell.BaseCell + * Note: The current class needs to be included as well, otherwise converting back is not possible. + * @type {string[]} + */ + this.allowedConversions = []; + } + + /** + * @returns {string} + */ + static get cellName() { + return "baseCell"; } /** @@ -26,6 +40,13 @@ App.Arcology.Cell.BaseCell = class extends App.Entity.Serializable { return 1; } + /** + * @returns {boolean} + */ + isBaseType() { + return true; + } + /** * @param {Array<number>} path * @returns {Node} @@ -35,9 +56,10 @@ App.Arcology.Cell.BaseCell = class extends App.Entity.Serializable { } /** + * @param {App.Arcology.Building} containingBuilding * @returns {Node} */ - cellPassage() { + cellPassage(containingBuilding) { const fragment = document.createDocumentFragment(); const scene = document.createElement("p"); @@ -56,6 +78,25 @@ App.Arcology.Cell.BaseCell = class extends App.Entity.Serializable { fragment.append(upgrades); } + if (this.allowedConversions.length > 0 && this.isBaseType()) { + const p = document.createElement("p"); + if (V.rep < 5000) { + fragment.append(App.UI.DOM.makeElement("p", "You don't have the reputation required to convert the sector base type.")); + } else { + for (const ac of this.allowedConversions) { + const cellClass = eval(`App.Arcology.Cell.${ac}`); + if (!(this instanceof cellClass)) { + p.append(this._makeUpgrade(`Convert sector to ${cellClass.cellName}.`, () => { + containingBuilding.replaceCell(this, new cellClass(1)); + repX(-5000, "capEx"); + }, 50000, "and 5000 reputation as many citizens will lose most of what they own.")); + } + } + } + fragment.append(p); + } + + return fragment; /** diff --git a/src/arcologyBuilding/apartments.js b/src/arcologyBuilding/apartments.js index 6be9ace631281a075679b0f355ac5302cd33225f..a49011743047ec78c4343550dc06dfd1c81d247d 100644 --- a/src/arcologyBuilding/apartments.js +++ b/src/arcologyBuilding/apartments.js @@ -8,6 +8,11 @@ App.Arcology.Cell.Apartment = class extends App.Arcology.Cell.BaseCell { this.type = type; } + + static get cellName() { + return "Apartments"; + } + /** * @returns {string} */ diff --git a/src/arcologyBuilding/base.js b/src/arcologyBuilding/base.js index 122de2a776d637e09d56417026eb5b684a5fb761..5ff00d496b1d427d4e3fc2a0996b7392e20e29d7 100644 --- a/src/arcologyBuilding/base.js +++ b/src/arcologyBuilding/base.js @@ -69,7 +69,13 @@ App.Arcology.Section = class extends App.Entity.Serializable { */ constructor(id, rows) { super(); + /** + * @type {string} + */ this.id = id; + /** + * @type {Array<Array<App.Arcology.Cell.BaseCell>>} + */ this.rows = rows; } @@ -159,6 +165,25 @@ App.Arcology.Section = class extends App.Entity.Serializable { return cells; } + /** + * Replaces the first occurrence of oldCell with newCell + * + * @param {App.Arcology.Cell.BaseCell} oldCell + * @param {App.Arcology.Cell.BaseCell} newCell + * @returns {boolean} + */ + replaceCell(oldCell, newCell) { + for (const row of this.rows) { + for (let i = 0; i < row.length; i++) { + if (row[i] === oldCell) { + row[i] = newCell; + return true; + } + } + } + return false; + } + static _cleanupConfigScheme(config) { super._cleanupConfigScheme(config); // BC code @@ -177,6 +202,9 @@ App.Arcology.Building = class extends App.Entity.Serializable { */ constructor(sections) { super(); + /** + * @type {Array<App.Arcology.Section>} + */ this.sections = sections; } @@ -221,6 +249,20 @@ App.Arcology.Building = class extends App.Entity.Serializable { }, []); } + /** + * @param {App.Arcology.Cell.BaseCell} oldCell + * @param {App.Arcology.Cell.BaseCell} newCell + * @returns {boolean} + */ + replaceCell(oldCell, newCell) { + for (let section of this.sections) { + if (section.replaceCell(oldCell, newCell)) { + return true; + } + } + return false; + } + static _cleanupConfigScheme(config) { super._cleanupConfigScheme(config); // BC code diff --git a/src/arcologyBuilding/cell.tw b/src/arcologyBuilding/cell.tw index c65be545db4e3ce0a983f384d196079138d619cf..36d29b76af5ab96a4619b6a7b00d9bfc74f5f555 100644 --- a/src/arcologyBuilding/cell.tw +++ b/src/arcologyBuilding/cell.tw @@ -2,11 +2,4 @@ <<set $nextButton = "Back", $nextLink = "Main">> -<span id="content"></span> -<<script>> - $(document).one(':passageend', () => { - $('#content').append( - V.building.cellByPath(V.cellPath).cellPassage() - ); - }); -<</script>> +<<print App.UI.DOM.includeDOM(V.building.cellByPath(V.cellPath).cellPassage(V.building))>> diff --git a/src/arcologyBuilding/manufacturing.js b/src/arcologyBuilding/manufacturing.js index 545bb65e7e5c2f98876d2da271f22c9b4cb5953f..8c71a05c843f916fb572e887916d555481d8438a 100644 --- a/src/arcologyBuilding/manufacturing.js +++ b/src/arcologyBuilding/manufacturing.js @@ -8,6 +8,10 @@ App.Arcology.Cell.Manufacturing = class extends App.Arcology.Cell.BaseCell { this.type = type; } + static get cellName() { + return "Manufacturing"; + } + /** * @returns {string} */ @@ -32,6 +36,13 @@ App.Arcology.Cell.Manufacturing = class extends App.Arcology.Cell.BaseCell { } } + /** + * @returns {boolean} + */ + isBaseType() { + return this.type === "Manufacturing"; + } + /** * @param {Array<number>} path * @returns {Node} diff --git a/src/arcologyBuilding/markets.js b/src/arcologyBuilding/markets.js index 427ef4983c3640cf5424eb244fcf78a7d8c5c874..676201285007219c83212c34a7278ed83b572b3a 100644 --- a/src/arcologyBuilding/markets.js +++ b/src/arcologyBuilding/markets.js @@ -8,6 +8,10 @@ App.Arcology.Cell.Market = class extends App.Arcology.Cell.BaseCell { this.type = type; } + static get cellName() { + return "Markets"; + } + /** * @returns {string} */ @@ -28,6 +32,10 @@ App.Arcology.Cell.Market = class extends App.Arcology.Cell.BaseCell { } } + isBaseType() { + return this.type === "Markets"; + } + /** * @param {Array<number>} path * @returns {Node} diff --git a/src/arcologyBuilding/shops.js b/src/arcologyBuilding/shops.js index 3d2d7cd3da8f08a2b206997cbaab4bf3a68c38f7..136879908be7af2d46dbb98d90998651cacef771 100644 --- a/src/arcologyBuilding/shops.js +++ b/src/arcologyBuilding/shops.js @@ -8,6 +8,10 @@ App.Arcology.Cell.Shop = class extends App.Arcology.Cell.BaseCell { this.type = type; } + static get cellName() { + return "Shops"; + } + /** * @returns {string} */ @@ -24,6 +28,10 @@ App.Arcology.Cell.Shop = class extends App.Arcology.Cell.BaseCell { } } + isBaseType() { + return this.type === "Shops"; + } + /** * @param {Array<number>} path * @returns {Node} diff --git a/src/js/economyJS.js b/src/js/economyJS.js index a169042e3ce3e448e6324f3a3cb6dcb6342453fd..b608fd49b91a5f1884f41020cf0e3f4d242f57ca 100644 --- a/src/js/economyJS.js +++ b/src/js/economyJS.js @@ -2087,17 +2087,36 @@ window.SectorCounts = function() { } }); - const apartments = V.building.findCells(cell => cell instanceof App.Arcology.Cell.Apartment); - apartments.forEach(a => { - if (a.type === 2) { - V.AProsperityCap += 10; - } else if (a.type === 1) { - V.AProsperityCap += 15; - } - }); - - const sweatshops = V.building.findCells(cell => cell instanceof App.Arcology.Cell.Manufacturing && cell.type === "Sweatshops"); - V.Sweatshops = sweatshops.length; + // The idea is that cells used for your private benefit contribute less to the economy as they cannot be used by + // others to generate revenue and therefore increase total cash flow. Can be offset by more luxury apartments. + V.Sweatshops = 0; + V.building.findCells(cell => !(cell instanceof App.Arcology.Cell.Penthouse)) + .forEach(cell => { + if (cell instanceof App.Arcology.Cell.Apartment) { + if (cell.type === 1) { + V.AProsperityCap += 10; + } else if (cell.type === 0) { + V.AProsperityCap += 5; + } + } else if (cell instanceof App.Arcology.Cell.Shop) { + if (cell.type !== "Club" && cell.type !== "Brothel") { + V.AProsperityCap += 10; + } + } else if (cell instanceof App.Arcology.Cell.Market) { + if (cell.type === "Transport Hub") { + V.AProsperityCap += 15; + } else if (cell.type !== "Pit" && cell.type !== "Arcade") { + V.AProsperityCap += 10; + } + } else if (cell instanceof App.Arcology.Cell.Manufacturing) { + if (cell.type !== "Dairy" && cell.type !== "Farmyard" && cell.type !== "Barracks") { + V.AProsperityCap += 10; + if (cell.type === "Sweatshops") { + V.Sweatshops++; + } + } + } + }); V.AProsperityCap += V.AProsperityCapModified; };