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
 
@@ -855,13 +855,13 @@ struct AIDebugWindow : public Window {
 
				ChangeToAI((CompanyID)(widget - AID_WIDGET_COMPANY_BUTTON_START));
 
			}
 
		}
 
		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);
 
		}
 
	}
 

	
 
	virtual void OnTimeout()
 
	{
 
		this->RaiseWidget(AID_WIDGET_RELOAD_TOGGLE);
src/company_cmd.cpp
Show inline comments
 
@@ -410,22 +410,29 @@ 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;
 

	
 
	ResetCompanyLivery(c);
 
	_company_colours[c->index] = (Colours)c->colour;
 

	
 
@@ -472,13 +479,13 @@ static void MaybeStartNewCompany()
 
		if (c->is_ai) n++;
 
	}
 

	
 
	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);
 
	}
 
}
 

	
 
void InitializeCompanies()
 
{
 
	_company_pool.CleanPool();
 
@@ -594,12 +601,13 @@ void CompanyNewsInformation::FillData(co
 
 * - 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,
 
@@ -704,13 +712,14 @@ CommandCost CmdCompanyCtrl(TileIndex til
 
#endif /* ENABLE_NETWORK */
 
		} break;
 

	
 
		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
 
			Company *c = Company::GetIfValid(p2);
 
			if (c == NULL) return CMD_ERROR;
 

	
src/console_cmds.cpp
Show inline comments
 
@@ -1041,13 +1041,13 @@ DEF_CONSOLE_CMD(ConStartAI)
 
		if (argc == 3) {
 
			config->StringToSettings(argv[2]);
 
		}
 
	}
 

	
 
	/* Start a new AI company */
 
	DoCommandP(0, 1, 0, CMD_COMPANY_CTRL);
 
	DoCommandP(0, 1, INVALID_COMPANY, CMD_COMPANY_CTRL);
 

	
 
	return true;
 
}
 

	
 
DEF_CONSOLE_CMD(ConReloadAI)
 
{
 
@@ -1077,13 +1077,13 @@ DEF_CONSOLE_CMD(ConReloadAI)
 
		IConsoleWarning("Company is not controlled by an AI.");
 
		return true;
 
	}
 

	
 
	/* 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;
 
}
 

	
 
DEF_CONSOLE_CMD(ConStopAI)
src/openttd.cpp
Show inline comments
 
@@ -80,13 +80,13 @@ void DoPaletteAnimations();
 
void MusicLoop();
 
void ResetMusic();
 
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();
 

	
 
/**
 
 * Error handling for fatal user errors.
 
 * @param s the string to print.
src/saveload/afterload.cpp
Show inline comments
 
@@ -46,13 +46,13 @@
 

	
 
#include "saveload_internal.h"
 

	
 
#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();
 

	
 
/**
 
 * Makes a tile canal or water depending on the surroundings.
 
 *
 
 * Must only be used for converting old savegames. Use WaterClass now.
0 comments (0 inline, 0 general)