mirror of https://github.com/OpenTTD/OpenTTD
(svn r17298) -Fix [FS#3153]: reloading an AI started a new AI in the first available company slot causing other AIs to be started
parent
e09cba404c
commit
f548a1b3b3
|
@ -858,7 +858,7 @@ struct AIDebugWindow : public Window {
|
||||||
if (widget == AID_WIDGET_RELOAD_TOGGLE && !this->IsWidgetDisabled(widget)) {
|
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 */
|
/* 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, 2, ai_debug_company, CMD_COMPANY_CTRL);
|
||||||
DoCommandP(0, 1, 0, CMD_COMPANY_CTRL);
|
DoCommandP(0, 1, ai_debug_company, CMD_COMPANY_CTRL);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -413,16 +413,23 @@ void ResetCompanyLivery(Company *c)
|
||||||
* Create a new company and sets all company variables default values
|
* Create a new company and sets all company variables default values
|
||||||
*
|
*
|
||||||
* @param is_ai is a ai company?
|
* @param is_ai is a ai company?
|
||||||
|
* @param company CompanyID to use for the new company
|
||||||
* @return the company struct
|
* @return the company struct
|
||||||
*/
|
*/
|
||||||
Company *DoStartupNewCompany(bool is_ai)
|
Company *DoStartupNewCompany(bool is_ai, CompanyID company = INVALID_COMPANY)
|
||||||
{
|
{
|
||||||
if (!Company::CanAllocateItem()) return NULL;
|
if (!Company::CanAllocateItem()) return NULL;
|
||||||
|
|
||||||
/* we have to generate colour before this company is valid */
|
/* we have to generate colour before this company is valid */
|
||||||
Colours colour = GenerateCompanyColour();
|
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;
|
c->colour = colour;
|
||||||
|
|
||||||
|
@ -475,7 +482,7 @@ static void MaybeStartNewCompany()
|
||||||
if (n < (uint)_settings_game.difficulty.max_no_competitors) {
|
if (n < (uint)_settings_game.difficulty.max_no_competitors) {
|
||||||
/* Send a command to all clients to start up a new AI.
|
/* Send a command to all clients to start up a new AI.
|
||||||
* Works fine for Multiplayer and Singleplayer */
|
* 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
|
* - p1 = 3 - merge two companies together. merge #1 with #2. Identified by p2
|
||||||
* @param p2 various functionality, dictated by p1
|
* @param p2 various functionality, dictated by p1
|
||||||
* - p1 = 0 - ClientID of the newly created client
|
* - 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 = 2 - CompanyID of the that is getting deleted
|
||||||
* - p1 = 3 - #1 p2 = (bit 0-15) - company to merge (p2 & 0xFFFF)
|
* - 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)
|
* - #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
|
case 1: // Make a new AI company
|
||||||
if (!(flags & DC_EXEC)) return CommandCost();
|
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;
|
break;
|
||||||
|
|
||||||
case 2: { // Delete a company
|
case 2: { // Delete a company
|
||||||
|
|
|
@ -1044,7 +1044,7 @@ DEF_CONSOLE_CMD(ConStartAI)
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Start a new AI company */
|
/* Start a new AI company */
|
||||||
DoCommandP(0, 1, 0, CMD_COMPANY_CTRL);
|
DoCommandP(0, 1, INVALID_COMPANY, CMD_COMPANY_CTRL);
|
||||||
|
|
||||||
return true;
|
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 */
|
/* 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, 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.");
|
IConsolePrint(CC_DEFAULT, "AI reloaded.");
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
|
|
@ -83,7 +83,7 @@ void ProcessAsyncSaveFinish();
|
||||||
void CallWindowTickEvent();
|
void CallWindowTickEvent();
|
||||||
|
|
||||||
extern void SetDifficultyLevel(int mode, DifficultySettings *gm_opt);
|
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 ShowOSErrorBox(const char *buf, bool system);
|
||||||
extern void InitializeRailGUI();
|
extern void InitializeRailGUI();
|
||||||
|
|
||||||
|
|
|
@ -49,7 +49,7 @@
|
||||||
#include <signal.h>
|
#include <signal.h>
|
||||||
|
|
||||||
extern StringID _switch_mode_errorstr;
|
extern StringID _switch_mode_errorstr;
|
||||||
extern Company *DoStartupNewCompany(bool is_ai);
|
extern Company *DoStartupNewCompany(bool is_ai, CompanyID company = INVALID_COMPANY);
|
||||||
extern void InitializeRailGUI();
|
extern void InitializeRailGUI();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in New Issue