summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/ai/ai_gui.cpp2
-rw-r--r--src/company_cmd.cpp17
-rw-r--r--src/console_cmds.cpp4
-rw-r--r--src/openttd.cpp2
-rw-r--r--src/saveload/afterload.cpp2
5 files changed, 18 insertions, 9 deletions
diff --git a/src/ai/ai_gui.cpp b/src/ai/ai_gui.cpp
index 6a3fcf6b8..6de73a07e 100644
--- a/src/ai/ai_gui.cpp
+++ b/src/ai/ai_gui.cpp
@@ -858,7 +858,7 @@ struct AIDebugWindow : public Window {
if (widget == AID_WIDGET_RELOAD_TOGGLE && !this->IsWidgetDisabled(widget)) {
/* First kill the company of the AI, then start a new one. This should start the current AI again */
DoCommandP(0, 2, ai_debug_company, CMD_COMPANY_CTRL);
- DoCommandP(0, 1, 0, CMD_COMPANY_CTRL);
+ DoCommandP(0, 1, ai_debug_company, CMD_COMPANY_CTRL);
}
}
diff --git a/src/company_cmd.cpp b/src/company_cmd.cpp
index 759181148..f1ae42c70 100644
--- a/src/company_cmd.cpp
+++ b/src/company_cmd.cpp
@@ -413,16 +413,23 @@ void ResetCompanyLivery(Company *c)
* Create a new company and sets all company variables default values
*
* @param is_ai is a ai company?
+ * @param company CompanyID to use for the new company
* @return the company struct
*/
-Company *DoStartupNewCompany(bool is_ai)
+Company *DoStartupNewCompany(bool is_ai, CompanyID company = INVALID_COMPANY)
{
if (!Company::CanAllocateItem()) return NULL;
/* we have to generate colour before this company is valid */
Colours colour = GenerateCompanyColour();
- Company *c = new Company(STR_SV_UNNAMED, is_ai);
+ Company *c;
+ if (company == INVALID_COMPANY) {
+ c = new Company(STR_SV_UNNAMED, is_ai);
+ } else {
+ if (Company::IsValidID(company)) return NULL;
+ c = new (company) Company(STR_SV_UNNAMED, is_ai);
+ }
c->colour = colour;
@@ -475,7 +482,7 @@ static void MaybeStartNewCompany()
if (n < (uint)_settings_game.difficulty.max_no_competitors) {
/* Send a command to all clients to start up a new AI.
* Works fine for Multiplayer and Singleplayer */
- DoCommandP(0, 1, 0, CMD_COMPANY_CTRL);
+ DoCommandP(0, 1, INVALID_COMPANY, CMD_COMPANY_CTRL);
}
}
@@ -597,6 +604,7 @@ void CompanyNewsInformation::FillData(const Company *c, const Company *other)
* - 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)
@@ -707,7 +715,8 @@ CommandCost CmdCompanyCtrl(TileIndex tile, DoCommandFlag flags, uint32 p1, uint3
case 1: // Make a new AI company
if (!(flags & DC_EXEC)) return CommandCost();
- DoStartupNewCompany(true);
+ if (p2 != INVALID_COMPANY && (p2 >= MAX_COMPANIES || Company::IsValidID(p2))) return CMD_ERROR;
+ DoStartupNewCompany(true, (CompanyID)p2);
break;
case 2: { // Delete a company
diff --git a/src/console_cmds.cpp b/src/console_cmds.cpp
index 0814b600c..5f528c374 100644
--- a/src/console_cmds.cpp
+++ b/src/console_cmds.cpp
@@ -1044,7 +1044,7 @@ DEF_CONSOLE_CMD(ConStartAI)
}
/* Start a new AI company */
- DoCommandP(0, 1, 0, CMD_COMPANY_CTRL);
+ DoCommandP(0, 1, INVALID_COMPANY, CMD_COMPANY_CTRL);
return true;
}
@@ -1080,7 +1080,7 @@ DEF_CONSOLE_CMD(ConReloadAI)
/* First kill the company of the AI, then start a new one. This should start the current AI again */
DoCommandP(0, 2, company_id, CMD_COMPANY_CTRL);
- DoCommandP(0, 1, 0, CMD_COMPANY_CTRL);
+ DoCommandP(0, 1, company_id, CMD_COMPANY_CTRL);
IConsolePrint(CC_DEFAULT, "AI reloaded.");
return true;
diff --git a/src/openttd.cpp b/src/openttd.cpp
index 98af20661..a99a735ec 100644
--- a/src/openttd.cpp
+++ b/src/openttd.cpp
@@ -83,7 +83,7 @@ void ProcessAsyncSaveFinish();
void CallWindowTickEvent();
extern void SetDifficultyLevel(int mode, DifficultySettings *gm_opt);
-extern Company *DoStartupNewCompany(bool is_ai);
+extern Company *DoStartupNewCompany(bool is_ai, CompanyID company = INVALID_COMPANY);
extern void ShowOSErrorBox(const char *buf, bool system);
extern void InitializeRailGUI();
diff --git a/src/saveload/afterload.cpp b/src/saveload/afterload.cpp
index 2730e17d9..43c375777 100644
--- a/src/saveload/afterload.cpp
+++ b/src/saveload/afterload.cpp
@@ -49,7 +49,7 @@
#include <signal.h>
extern StringID _switch_mode_errorstr;
-extern Company *DoStartupNewCompany(bool is_ai);
+extern Company *DoStartupNewCompany(bool is_ai, CompanyID company = INVALID_COMPANY);
extern void InitializeRailGUI();
/**