diff --git a/src/Corporation/corporate-divisionAcquiring.js b/src/Corporation/corporate-divisionAcquiring.js index 2118c6370c1bbd1266da9cc2bfcbb6e7970fb5df..66b22415dfccd386afa8a51c7258d57fd62280b2 100644 --- a/src/Corporation/corporate-divisionAcquiring.js +++ b/src/Corporation/corporate-divisionAcquiring.js @@ -54,8 +54,9 @@ App.Corporate.Init_DivisionAcquiring = function(shared) { } get nextDivisions() { return this._const.nextDivisions; } dissolve() { + App.Corporate.sellSlaves(this, this.heldSlaves); super.dissolve(); - delete V[this.corpDiv + "Slaves"]; + delete V[`${this._const.corpId}Slaves`]; } getAutoBuyFromMarket() { return false; diff --git a/src/Corporation/corporate-divisionBase.js b/src/Corporation/corporate-divisionBase.js index 2951cc8ebfb68ca0c76a3c88af531c191de9b61a..6bfe16886d2e4653d8428d72e8abe60344e23e1d 100644 --- a/src/Corporation/corporate-divisionBase.js +++ b/src/Corporation/corporate-divisionBase.js @@ -41,10 +41,9 @@ App.Corporate.Init_DivisionBase = function(shared) { get developmentCount() { return this.getStored("Dev"); } set developmentCount(value) { if(value < 0) throw "Cannot set development count to less than 0"; + //dissolve is the only function that sets founded to false. + if(value == 0 && this.founded) throw "Cannot set development count to 0; use dissolve instead."; this.setStored("Dev", value); - if(value == 0) { - this.dissolve(); - } } //calculated @@ -193,9 +192,9 @@ App.Corporate.Init_DivisionBase = function(shared) { } dissolve() { this.setStored('', 0); - this.setStored('Dev', 0); + App.Corporate.sellDevelopment(this); App.Corporate.dissolvedDivision(); - this.relatedDivisions.to.forEach(nextDep => delete V[`${this.corpDiv}To${nextDep.id}`]); + this.relatedDivisions.to.forEach(nextDep => delete V[`${this._const.corpId}To${nextDep.id}`]); } //private helpers diff --git a/src/Corporation/corporate-divisionProcessing.js b/src/Corporation/corporate-divisionProcessing.js index c273327534859328de3cf5b8336418a10e4eabfe..3631deaffb36e7a3b994828902d273efe7438103 100644 --- a/src/Corporation/corporate-divisionProcessing.js +++ b/src/Corporation/corporate-divisionProcessing.js @@ -72,9 +72,10 @@ App.Corporate.Init_DivisionProcessing = function(shared) { shared.SellOverflowSlaves(this); } dissolve() { + App.Corporate.sellSlaves(this, this.heldSlaves); super.dissolve(); - delete V[this.corpDiv + "Slaves"]; - delete V[this.corpDiv + "Slaves2"]; + delete V[this._const.corpId + "Slaves"]; + delete V[this._const.corpId + "Slaves2"]; } diff --git a/src/Corporation/corporate-divisionWorking.js b/src/Corporation/corporate-divisionWorking.js index 802414ff90bc5ea9d1fc9b1c001ee448f9577db2..62f0ea48455552245a7d66ad7d9607bab5015dea 100644 --- a/src/Corporation/corporate-divisionWorking.js +++ b/src/Corporation/corporate-divisionWorking.js @@ -58,7 +58,7 @@ App.Corporate.Init_DivisionWorking = function(shared) { } dissolve() { super.dissolve(); - delete V[this.corpDiv + "Slaves"]; + delete V[this._const.corpId + "Slaves"]; } getAutoSendToMarket() { return false; diff --git a/src/Corporation/corporate.js b/src/Corporation/corporate.js index 4bccdfb18af1cef36bc16473ae97aea145c71663..db453c5b5199b7a1278ed92bc5827f077d48aebd 100644 --- a/src/Corporation/corporate.js +++ b/src/Corporation/corporate.js @@ -394,7 +394,7 @@ App.Corporate.Init = function() { SellOverflowSlaves: function(division) { const slavesToSell = division.activeSlaves - division.developmentCount; if(slavesToSell > 0) { - const slaveProcCost = Math.trunc(App.Corporate.slaveMarketPurchaseValue(this, -slavesToSell)); + const slaveProcCost = Math.trunc(App.Corporate.slaveMarketPurchaseValue(division, -slavesToSell)); App.Corporate.chargeAsset(slaveProcCost, "slaves"); division.activeSlaves -= slavesToSell; V.menialDemandFactor -= slavesToSell; @@ -593,11 +593,8 @@ App.Corporate.Init = function() { App.Corporate.ledger.swap(); }; App.Corporate.dissolve = function() { - for(let division of this.divisionList) { - if(division.toMarket) { - this.sellSlaves(division, division.heldSlaves); - } - division.developmentCount = 0; + for(let division of this.divisionList.filter(x=>x.founded)) { + division.dissolve(); } this.founded = false; this.numDivisions = 0; diff --git a/src/Corporation/manageCorporation.tw b/src/Corporation/manageCorporation.tw index 1cd33c468fc022b71e8aff9135a4a3c743fee5c2..220018e0a5db6079c64a77a7d6f0d73667725343 100644 --- a/src/Corporation/manageCorporation.tw +++ b/src/Corporation/manageCorporation.tw @@ -230,10 +230,10 @@ <</if>> </div> <</if>> - <<if App.Corporate.divisions > 1>> /* Cannot dissolve the last division */ + <<if App.Corporate.numDivisions > 1>> /* Cannot dissolve the last division */ <div>Dissolve the division @@.orange;//Think before you click//@@ /* TODO: Add a confirmation button. Probably use replace?*/ <<= "[[Dissolve|Manage Corporation]" - + "[App.Corporate.sellDevelopment('" + _div.id + "', " + _div.developmentCount + ")]" + + "[App.Corporate.divisions['" + _div.id + "'].dissolve()]" + "]">> </div> <</if>>