Changeset - r12800:400b68836df9
[Not reviewed]
master
0 5 0
yexo - 15 years ago 2009-08-28 15:23:11
yexo@openttd.org
(svn r17298) -Fix [FS#3153]: reloading an AI started a new AI in the first available company slot causing other AIs to be started
5 files changed with 18 insertions and 9 deletions:
0 comments (0 inline, 0 general)
src/ai/ai_gui.cpp
Show inline comments
 
@@ -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);
 
		}
 
	}
 

	
src/company_cmd.cpp
Show inline comments
 
@@ -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(co
 
 * - 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 til
 
		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
src/console_cmds.cpp
Show inline comments
 
@@ -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;
src/openttd.cpp
Show inline comments
 
@@ -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();
 

	
src/saveload/afterload.cpp
Show inline comments
 
@@ -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();
 

	
 
/**
0 comments (0 inline, 0 general)