summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authoryexo <yexo@openttd.org>2009-09-14 22:09:50 +0000
committeryexo <yexo@openttd.org>2009-09-14 22:09:50 +0000
commit5ef54ed4f9a57c9808a3ab96aafbb4f8186ceb49 (patch)
treebcdca406a024f714482ef10eb7c5b62f4f8cf42a /src
parent2d9c54c9a81f5cd6f14585f9b398eef071db1c9e (diff)
downloadopenttd-5ef54ed4f9a57c9808a3ab96aafbb4f8186ceb49.tar.xz
(svn r17542) -Fix: don't access variables in the company struct after it has been deleted
-Cleanup: remove some never-used code
Diffstat (limited to 'src')
-rw-r--r--src/company_cmd.cpp15
-rw-r--r--src/economy.cpp5
2 files changed, 4 insertions, 16 deletions
diff --git a/src/company_cmd.cpp b/src/company_cmd.cpp
index 97727a911..c3dd10f1c 100644
--- a/src/company_cmd.cpp
+++ b/src/company_cmd.cpp
@@ -676,13 +676,10 @@ void CompanyNewsInformation::FillData(const Company *c, const Company *other)
* - p1 = 0 - create a new company, Which company (network) it will be is in p2
* - p1 = 1 - create a new AI company
* - p1 = 2 - delete a company. Company is identified by p2
- * - p1 = 3 - merge two companies together. merge #1 with #2. Identified by p2
* @param p2 various functionality, dictated by p1
* - p1 = 0 - ClientID of the newly created client
* - p1 = 1 - CompanyID to start AI (INVALID_COMPANY for first available)
* - p1 = 2 - CompanyID of the that is getting deleted
- * - p1 = 3 - #1 p2 = (bit 0-15) - company to merge (p2 & 0xFFFF)
- * - #2 p2 = (bit 16-31) - company to be merged into ((p2>>16)&0xFFFF)
* @todo In the case of p1=0, create new company, the clientID of the new client is in parameter
* p2. This parameter is passed in at function DEF_SERVER_RECEIVE_COMMAND(PACKET_CLIENT_COMMAND)
* on the server itself. First of all this is unbelievably ugly; second of all, well,
@@ -820,18 +817,6 @@ CommandCost CmdCompanyCtrl(TileIndex tile, DoCommandFlag flags, uint32 p1, uint3
AI::BroadcastNewEvent(new AIEventCompanyBankrupt(c_index));
} break;
- case 3: { // Merge a company (#1) into another company (#2), elimination company #1
- CompanyID cid_old = (CompanyID)GB(p2, 0, 16);
- CompanyID cid_new = (CompanyID)GB(p2, 16, 16);
-
- if (!Company::IsValidID(cid_old) || !Company::IsValidID(cid_new)) return CMD_ERROR;
-
- if (!(flags & DC_EXEC)) return CMD_ERROR;
-
- ChangeOwnershipOfCompanyItems(cid_old, cid_new);
- delete Company::Get(cid_old);
- } break;
-
default: return CMD_ERROR;
}
diff --git a/src/economy.cpp b/src/economy.cpp
index cca81413a..340b6fdb7 100644
--- a/src/economy.cpp
+++ b/src/economy.cpp
@@ -1553,8 +1553,11 @@ CommandCost CmdBuyCompany(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32
/* Do not allow companies to take over themselves */
if ((CompanyID)p1 == _current_company) return CMD_ERROR;
+ /* Get the cost here as the company is deleted in DoAcquireCompany. */
+ CommandCost cost(EXPENSES_OTHER, c->bankrupt_value);
+
if (flags & DC_EXEC) {
DoAcquireCompany(c);
}
- return CommandCost(EXPENSES_OTHER, c->bankrupt_value);
+ return cost;
}