mirror of https://github.com/OpenTTD/OpenTTD.git
(svn r18784) -Codechange: make NetworkSend_Command accept a company instead of using _local_company to pass that information, with the whole mess when you don't want the company to be _local_company.
This commit is contained in:
parent
3e5a87a52c
commit
ebe99fd493
|
@ -230,12 +230,7 @@ bool AIObject::DoCommand(TileIndex tile, uint32 p1, uint32 p2, uint cmd, const c
|
|||
#ifdef ENABLE_NETWORK
|
||||
/* Send the command */
|
||||
if (_networking) {
|
||||
/* NetworkSend_Command needs _local_company to be set correctly, so
|
||||
* adjust it, and put it back right after the function */
|
||||
CompanyID old_company = _local_company;
|
||||
_local_company = _current_company;
|
||||
::NetworkSend_Command(tile, p1, p2, cmd, CcAI, text);
|
||||
_local_company = old_company;
|
||||
::NetworkSend_Command(tile, p1, p2, cmd, CcAI, text, _current_company);
|
||||
SetLastCost(res.GetCost());
|
||||
|
||||
/* Suspend the AI till the command is really executed */
|
||||
|
|
|
@ -589,7 +589,7 @@ bool DoCommandP(TileIndex tile, uint32 p1, uint32 p2, uint32 cmd, CommandCallbac
|
|||
* send it to the command-queue and abort execution
|
||||
*/
|
||||
if (_networking && !(cmd & CMD_NETWORK_COMMAND)) {
|
||||
NetworkSend_Command(tile, p1, p2, cmd & ~CMD_FLAGS_MASK, callback, text);
|
||||
NetworkSend_Command(tile, p1, p2, cmd & ~CMD_FLAGS_MASK, callback, text, _current_company);
|
||||
_docommand_recursive = 0;
|
||||
ClearStorageChanges(false);
|
||||
return true;
|
||||
|
|
|
@ -13,6 +13,7 @@
|
|||
#define COMMAND_FUNC_H
|
||||
|
||||
#include "command_type.h"
|
||||
#include "company_type.h"
|
||||
|
||||
/**
|
||||
* Checks if a command failes.
|
||||
|
@ -70,11 +71,10 @@ bool DoCommandP(TileIndex tile, uint32 p1, uint32 p2, uint32 cmd, CommandCallbac
|
|||
bool DoCommandP(const CommandContainer *container, bool my_cmd = true);
|
||||
|
||||
#ifdef ENABLE_NETWORK
|
||||
|
||||
/**
|
||||
* Send a command over the network
|
||||
*/
|
||||
void NetworkSend_Command(TileIndex tile, uint32 p1, uint32 p2, uint32 cmd, CommandCallback *callback, const char *text);
|
||||
void NetworkSend_Command(TileIndex tile, uint32 p1, uint32 p2, uint32 cmd, CommandCallback *callback, const char *text, CompanyID company);
|
||||
#endif /* ENABLE_NETWORK */
|
||||
|
||||
extern Money _additional_cash_required;
|
||||
|
|
|
@ -790,7 +790,6 @@ CommandCost CmdCompanyCtrl(TileIndex tile, DoCommandFlag flags, uint32 p1, uint3
|
|||
NetworkUpdateClientInfo(ci->client_id);
|
||||
|
||||
if (Company::IsValidID(ci->client_playas)) {
|
||||
CompanyID company_backup = _local_company;
|
||||
_network_company_states[c->index].months_empty = 0;
|
||||
_network_company_states[c->index].password[0] = '\0';
|
||||
NetworkServerUpdateCompanyPassworded(ci->client_playas, false);
|
||||
|
@ -806,9 +805,7 @@ CommandCost CmdCompanyCtrl(TileIndex tile, DoCommandFlag flags, uint32 p1, uint3
|
|||
* TODO: Perhaps this could be improved by when the client is ready
|
||||
* with joining to let it send itself the command, and not the server?
|
||||
* For example in network_client.c:534? */
|
||||
_local_company = ci->client_playas;
|
||||
NetworkSend_Command(0, 0, 0, CMD_RENAME_PRESIDENT, NULL, ci->client_name);
|
||||
_local_company = company_backup;
|
||||
NetworkSend_Command(0, 0, 0, CMD_RENAME_PRESIDENT, NULL, ci->client_name, ci->client_playas);
|
||||
}
|
||||
|
||||
/* Announce new company on network, if the client was a SPECTATOR before */
|
||||
|
|
|
@ -643,7 +643,7 @@ DEF_CLIENT_RECEIVE_COMMAND(PACKET_SERVER_MAP)
|
|||
* the server will give us a client-id and let us in */
|
||||
_network_join_status = NETWORK_JOIN_STATUS_REGISTERING;
|
||||
ShowJoinStatusWindow();
|
||||
NetworkSend_Command(0, 0, 0, CMD_COMPANY_CTRL, NULL, NULL);
|
||||
NetworkSend_Command(0, 0, 0, CMD_COMPANY_CTRL, NULL, NULL, _local_company);
|
||||
}
|
||||
} else {
|
||||
/* take control over an existing company */
|
||||
|
|
|
@ -78,13 +78,14 @@ void NetworkAddCommandQueue(CommandPacket cp, NetworkClientSocket *cs)
|
|||
* @param cmd The command to execute (a CMD_* value)
|
||||
* @param callback A callback function to call after the command is finished
|
||||
* @param text The text to pass
|
||||
* @param company The company that wants to send the command
|
||||
*/
|
||||
void NetworkSend_Command(TileIndex tile, uint32 p1, uint32 p2, uint32 cmd, CommandCallback *callback, const char *text)
|
||||
void NetworkSend_Command(TileIndex tile, uint32 p1, uint32 p2, uint32 cmd, CommandCallback *callback, const char *text, CompanyID company)
|
||||
{
|
||||
assert((cmd & CMD_FLAGS_MASK) == 0);
|
||||
|
||||
CommandPacket c;
|
||||
c.company = _local_company;
|
||||
c.company = company;
|
||||
c.next = NULL;
|
||||
c.tile = tile;
|
||||
c.p1 = p1;
|
||||
|
|
|
@ -1579,7 +1579,7 @@ void SyncCompanySettings()
|
|||
const void *new_var = GetVariableAddress(&_settings_client.company, &sd->save);
|
||||
uint32 old_value = (uint32)ReadValue(old_var, sd->save.conv);
|
||||
uint32 new_value = (uint32)ReadValue(new_var, sd->save.conv);
|
||||
if (old_value != new_value) NetworkSend_Command(0, i, new_value, CMD_CHANGE_COMPANY_SETTING, NULL, NULL);
|
||||
if (old_value != new_value) NetworkSend_Command(0, i, new_value, CMD_CHANGE_COMPANY_SETTING, NULL, NULL, _local_company);
|
||||
}
|
||||
}
|
||||
#endif /* ENABLE_NETWORK */
|
||||
|
|
|
@ -486,7 +486,7 @@ static void MenuClickCompany(int index)
|
|||
if (_network_server) {
|
||||
DoCommandP(0, 0, _network_own_client_id, CMD_COMPANY_CTRL);
|
||||
} else {
|
||||
NetworkSend_Command(0, 0, 0, CMD_COMPANY_CTRL, NULL, NULL);
|
||||
NetworkSend_Command(0, 0, 0, CMD_COMPANY_CTRL, NULL, NULL, _local_company);
|
||||
}
|
||||
return;
|
||||
|
||||
|
|
Loading…
Reference in New Issue