src/main_gui.cpp
changeset 6847 77facd267574
parent 6845 0c64af3ae68f
child 6857 60130753e595
equal deleted inserted replaced
6846:175bf19b9def 6847:77facd267574
    56 
    56 
    57 extern void GenerateIndustries();
    57 extern void GenerateIndustries();
    58 extern bool GenerateTowns();
    58 extern bool GenerateTowns();
    59 
    59 
    60 
    60 
       
    61 void CcGiveMoney(bool success, TileIndex tile, uint32 p1, uint32 p2)
       
    62 {
       
    63 	if (!success) return;
       
    64 
       
    65 	char msg[20];
       
    66 	/* Inform the player of this action */
       
    67 	snprintf(msg, sizeof(msg), "%d", p1);
       
    68 
       
    69 	if (!_network_server) {
       
    70 		SEND_COMMAND(PACKET_CLIENT_CHAT)(NETWORK_ACTION_GIVE_MONEY, DESTTYPE_TEAM, p2, msg);
       
    71 	} else {
       
    72 		NetworkServer_HandleChat(NETWORK_ACTION_GIVE_MONEY, DESTTYPE_TEAM, p2, msg, NETWORK_SERVER_INDEX);
       
    73 	}
       
    74 }
       
    75 
    61 void HandleOnEditText(const char *str)
    76 void HandleOnEditText(const char *str)
    62 {
    77 {
    63 	int id = _rename_id;
    78 	int id = _rename_id;
    64 	_cmd_text = str;
    79 	_cmd_text = str;
    65 
    80 
    73 		break;
    88 		break;
    74 #ifdef ENABLE_NETWORK
    89 #ifdef ENABLE_NETWORK
    75 	case 3: { // Give money, you can only give money in excess of loan
    90 	case 3: { // Give money, you can only give money in excess of loan
    76 		const Player *p = GetPlayer(_current_player);
    91 		const Player *p = GetPlayer(_current_player);
    77 		int32 money = min(p->money64 - p->current_loan, atoi(str) / _currency->rate);
    92 		int32 money = min(p->money64 - p->current_loan, atoi(str) / _currency->rate);
    78 		char msg[20];
       
    79 
    93 
    80 		money = clamp(money, 0, 20000000); // Clamp between 20 million and 0
    94 		money = clamp(money, 0, 20000000); // Clamp between 20 million and 0
    81 
    95 
    82 		/* Give 'id' the money, and substract it from ourself */
    96 		/* Give 'id' the money, and substract it from ourself */
    83 		int32 ret = DoCommandP(0, money, id, NULL, CMD_GIVE_MONEY | CMD_MSG(STR_INSUFFICIENT_FUNDS));
    97 		DoCommandP(0, money, id, CcGiveMoney, CMD_GIVE_MONEY | CMD_MSG(STR_INSUFFICIENT_FUNDS));
    84 		if (CmdFailed(ret) || ret == 0) break; // We either did something wrong, or we don't have any money anymore
       
    85 
       
    86 		/* Inform the player of this action */
       
    87 		snprintf(msg, sizeof(msg), "%d", money);
       
    88 
       
    89 		if (!_network_server) {
       
    90 			SEND_COMMAND(PACKET_CLIENT_CHAT)(NETWORK_ACTION_GIVE_MONEY, DESTTYPE_TEAM, id, msg);
       
    91 		} else {
       
    92 			NetworkServer_HandleChat(NETWORK_ACTION_GIVE_MONEY, DESTTYPE_TEAM, id, msg, NETWORK_SERVER_INDEX);
       
    93 		}
       
    94 	} break;
    98 	} break;
    95 #endif /* ENABLE_NETWORK */
    99 #endif /* ENABLE_NETWORK */
    96 		default: NOT_REACHED();
   100 		default: NOT_REACHED();
    97 	}
   101 	}
    98 
   102