Changeset - r19852:7885869789c7
[Not reviewed]
master
0 1 0
frosch - 12 years ago 2012-12-09 16:53:41
frosch@openttd.org
(svn r24807) -Add [FS#2820]: Enable usage of 'companies' console command also in singleplayer.
1 file changed with 43 insertions and 38 deletions:
0 comments (0 inline, 0 general)
src/console_cmds.cpp
Show inline comments
 
@@ -35,16 +35,13 @@
 
#include "ai/ai.hpp"
 
#include "ai/ai_config.hpp"
 
#include "newgrf.h"
 
#include "console_func.h"
 
#include "engine_base.h"
 
#include "game/game.hpp"
 

	
 
#ifdef ENABLE_NETWORK
 
	#include "table/strings.h"
 
#endif /* ENABLE_NETWORK */
 
#include "table/strings.h"
 

	
 
/* scriptfile handling */
 
static bool _script_running; ///< Script is running (used to abort execution when #ConReturn is encountered).
 

	
 
/* console command defines */
 
#define DEF_CONSOLE_CMD(function) static bool function(byte argc, char *argv[])
 
@@ -1528,12 +1525,51 @@ DEF_CONSOLE_CMD(ConListAliases)
 
		}
 
	}
 

	
 
	return true;
 
}
 

	
 
DEF_CONSOLE_CMD(ConCompanies)
 
{
 
	if (argc == 0) {
 
		IConsoleHelp("List the details of all companies in the game. Usage 'companies'");
 
		return true;
 
	}
 

	
 
	Company *c;
 
	FOR_ALL_COMPANIES(c) {
 
		/* Grab the company name */
 
		char company_name[512];
 
		SetDParam(0, c->index);
 
		GetString(company_name, STR_COMPANY_NAME, lastof(company_name));
 

	
 
		const char *password_state = "";
 
		if (c->is_ai) {
 
			password_state = "AI";
 
		}
 
#ifdef ENABLE_NETWORK
 
		else if (_network_server) {
 
				password_state = StrEmpty(_network_company_states[c->index].password) ? "unprotected" : "protected";
 
		}
 
#endif
 

	
 
		char colour[512];
 
		GetString(colour, STR_COLOUR_DARK_BLUE + _company_colours[c->index], lastof(colour));
 
		IConsolePrintF(CC_INFO, "#:%d(%s) Company Name: '%s'  Year Founded: %d  Money: " OTTD_PRINTF64 "  Loan: " OTTD_PRINTF64 "  Value: " OTTD_PRINTF64 "  (T:%d, R:%d, P:%d, S:%d) %s",
 
			c->index + 1, colour, company_name,
 
			c->inaugurated_year, (int64)c->money, (int64)c->current_loan, (int64)CalculateCompanyValue(c),
 
			c->group_all[VEH_TRAIN].num_vehicle,
 
			c->group_all[VEH_ROAD].num_vehicle,
 
			c->group_all[VEH_AIRCRAFT].num_vehicle,
 
			c->group_all[VEH_SHIP].num_vehicle,
 
			password_state);
 
	}
 

	
 
	return true;
 
}
 

	
 
#ifdef ENABLE_NETWORK
 

	
 
DEF_CONSOLE_CMD(ConSay)
 
{
 
	if (argc == 0) {
 
		IConsoleHelp("Chat to your fellow players in a multiplayer game. Usage: 'say \"<msg>\"'");
 
@@ -1549,44 +1585,12 @@ DEF_CONSOLE_CMD(ConSay)
 
		NetworkServerSendChat(NETWORK_ACTION_CHAT, DESTTYPE_BROADCAST, 0, argv[1], CLIENT_ID_SERVER, from_admin);
 
	}
 

	
 
	return true;
 
}
 

	
 
DEF_CONSOLE_CMD(ConCompanies)
 
{
 
	if (argc == 0) {
 
		IConsoleHelp("List the in-game details of all clients connected to the server. Usage 'companies'");
 
		return true;
 
	}
 
	NetworkCompanyStats company_stats[MAX_COMPANIES];
 
	NetworkPopulateCompanyStats(company_stats);
 

	
 
	Company *c;
 
	FOR_ALL_COMPANIES(c) {
 
		/* Grab the company name */
 
		char company_name[NETWORK_COMPANY_NAME_LENGTH];
 
		SetDParam(0, c->index);
 
		GetString(company_name, STR_COMPANY_NAME, lastof(company_name));
 

	
 
		char buffer[512];
 
		const NetworkCompanyStats *stats = &company_stats[c->index];
 

	
 
		GetString(buffer, STR_COLOUR_DARK_BLUE + _company_colours[c->index], lastof(buffer));
 
		IConsolePrintF(CC_INFO, "#:%d(%s) Company Name: '%s'  Year Founded: %d  Money: " OTTD_PRINTF64 "  Loan: " OTTD_PRINTF64 "  Value: " OTTD_PRINTF64 "  (T:%d, R:%d, P:%d, S:%d) %sprotected",
 
			c->index + 1, buffer, company_name, c->inaugurated_year, (int64)c->money, (int64)c->current_loan, (int64)CalculateCompanyValue(c),
 
			/* trains      */ stats->num_vehicle[0],
 
			/* lorry + bus */ stats->num_vehicle[1] + stats->num_vehicle[2],
 
			/* planes      */ stats->num_vehicle[3],
 
			/* ships       */ stats->num_vehicle[4],
 
			/* protected   */ StrEmpty(_network_company_states[c->index].password) ? "un" : "");
 
	}
 

	
 
	return true;
 
}
 

	
 
DEF_CONSOLE_CMD(ConSayCompany)
 
{
 
	if (argc == 0) {
 
		IConsoleHelp("Chat to a certain company in a multiplayer game. Usage: 'say_company <company-no> \"<msg>\"'");
 
		IConsoleHelp("CompanyNo is the company that plays as company <companyno>, 1 through max_companies");
 
		return true;
 
@@ -1936,23 +1940,24 @@ void IConsoleStdLibRegister()
 
	IConsoleCmdRegister("stop_ai",      ConStopAI);
 

	
 
	IConsoleCmdRegister("list_game",    ConListGame);
 
	IConsoleCmdRegister("list_game_libs", ConListGameLibs);
 
	IConsoleCmdRegister("rescan_game",    ConRescanGame);
 

	
 
	IConsoleCmdRegister("companies",       ConCompanies);
 
	IConsoleAliasRegister("players",       "companies");
 

	
 
	/* networking functions */
 
#ifdef ENABLE_NETWORK
 
/* Content downloading is only available with ZLIB */
 
#if defined(WITH_ZLIB)
 
	IConsoleCmdRegister("content",         ConContent);
 
#endif /* defined(WITH_ZLIB) */
 

	
 
	/*** Networking commands ***/
 
	IConsoleCmdRegister("say",             ConSay, ConHookNeedNetwork);
 
	IConsoleCmdRegister("companies",       ConCompanies, ConHookServerOnly);
 
	IConsoleAliasRegister("players",       "companies");
 
	IConsoleCmdRegister("say_company",     ConSayCompany, ConHookNeedNetwork);
 
	IConsoleAliasRegister("say_player",    "say_company %+");
 
	IConsoleCmdRegister("say_client",      ConSayClient, ConHookNeedNetwork);
 

	
 
	IConsoleCmdRegister("connect",         ConNetworkConnect, ConHookClientOnly);
 
	IConsoleCmdRegister("clients",         ConNetworkClients, ConHookNeedNetwork);
0 comments (0 inline, 0 general)