src/players.cpp
branchgamebalance
changeset 9913 e79cd19772dd
parent 9912 1ac8aac92385
equal deleted inserted replaced
9912:1ac8aac92385 9913:e79cd19772dd
   171 
   171 
   172 	if (pid == _local_player) InvalidateWindow(WC_STATUS_BAR, 0);
   172 	if (pid == _local_player) InvalidateWindow(WC_STATUS_BAR, 0);
   173 	InvalidateWindow(WC_FINANCES, pid);
   173 	InvalidateWindow(WC_FINANCES, pid);
   174 }
   174 }
   175 
   175 
   176 bool CheckPlayerHasMoney(int32 cost)
   176 bool CheckPlayerHasMoney(CommandCost cost)
   177 {
   177 {
   178 	if (cost > 0) {
   178 	if (cost > 0) {
   179 		PlayerID pid = _current_player;
   179 		PlayerID pid = _current_player;
   180 		if (IsValidPlayer(pid) && cost > GetPlayer(pid)->player_money) {
   180 		if (IsValidPlayer(pid) && cost > GetPlayer(pid)->player_money) {
   181 			SetDParam(0, cost);
   181 			SetDParam(0, cost);
   184 		}
   184 		}
   185 	}
   185 	}
   186 	return true;
   186 	return true;
   187 }
   187 }
   188 
   188 
   189 static void SubtractMoneyFromAnyPlayer(Player *p, int32 cost)
   189 static void SubtractMoneyFromAnyPlayer(Player *p, CommandCost cost)
   190 {
   190 {
   191 	p->money64 -= cost;
   191 	p->money64 -= cost;
   192 	UpdatePlayerMoney32(p);
   192 	UpdatePlayerMoney32(p);
   193 
   193 
   194 	p->yearly_expenses[0][_yearly_expenses_type] += cost;
   194 	p->yearly_expenses[0][_yearly_expenses_type] += cost;
   208 	}
   208 	}
   209 
   209 
   210 	InvalidatePlayerWindows(p);
   210 	InvalidatePlayerWindows(p);
   211 }
   211 }
   212 
   212 
   213 void SubtractMoneyFromPlayer(int32 cost)
   213 void SubtractMoneyFromPlayer(CommandCost cost)
   214 {
   214 {
   215 	PlayerID pid = _current_player;
   215 	PlayerID pid = _current_player;
   216 
   216 
   217 	if (IsValidPlayer(pid)) SubtractMoneyFromAnyPlayer(GetPlayer(pid), cost);
   217 	if (IsValidPlayer(pid)) SubtractMoneyFromAnyPlayer(GetPlayer(pid), cost);
   218 }
   218 }
   219 
   219 
   220 void SubtractMoneyFromPlayerFract(PlayerID player, int32 cost)
   220 void SubtractMoneyFromPlayerFract(PlayerID player, CommandCost cost)
   221 {
   221 {
   222 	Player *p = GetPlayer(player);
   222 	Player *p = GetPlayer(player);
   223 	byte m = p->player_money_fraction;
   223 	byte m = p->player_money_fraction;
   224 
   224 
   225 	p->player_money_fraction = m - (byte)cost;
   225 	p->player_money_fraction = m - (byte)cost;
   674  * - p1 bits 16-31 = months left before engine expires to replace it
   674  * - p1 bits 16-31 = months left before engine expires to replace it
   675  * - p2 bits  0-31 = minimum amount of money available
   675  * - p2 bits  0-31 = minimum amount of money available
   676  * if p1 = 5, then
   676  * if p1 = 5, then
   677  * - p2 = enable renew_keep_length
   677  * - p2 = enable renew_keep_length
   678  */
   678  */
   679 int32 CmdSetAutoReplace(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
   679 CommandCost CmdSetAutoReplace(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
   680 {
   680 {
   681 	Player *p;
   681 	Player *p;
   682 	if (!IsValidPlayer(_current_player)) return CMD_ERROR;
   682 	if (!IsValidPlayer(_current_player)) return CMD_ERROR;
   683 
   683 
   684 	p = GetPlayer(_current_player);
   684 	p = GetPlayer(_current_player);
   721 			break;
   721 			break;
   722 		case 3: {
   722 		case 3: {
   723 			EngineID old_engine_type = GB(p2, 0, 16);
   723 			EngineID old_engine_type = GB(p2, 0, 16);
   724 			EngineID new_engine_type = GB(p2, 16, 16);
   724 			EngineID new_engine_type = GB(p2, 16, 16);
   725 			GroupID id_g = GB(p1, 16, 16);
   725 			GroupID id_g = GB(p1, 16, 16);
   726 			int32 cost;
   726 			CommandCost cost;
   727 
   727 
   728 			if (!IsValidGroupID(id_g) && !IsDefaultGroupID(id_g)) return CMD_ERROR;
   728 			if (!IsValidGroupID(id_g) && !IsDefaultGroupID(id_g)) return CMD_ERROR;
   729 			if (new_engine_type != INVALID_ENGINE) {
   729 			if (new_engine_type != INVALID_ENGINE) {
   730 				/* First we make sure that it's a valid type the user requested
   730 				/* First we make sure that it's a valid type the user requested
   731 				 * check that it's an engine that is in the engine array */
   731 				 * check that it's an engine that is in the engine array */
   803  * on the server itself. First of all this is unbelievably ugly; second of all, well,
   803  * on the server itself. First of all this is unbelievably ugly; second of all, well,
   804  * it IS ugly! <b>Someone fix this up :)</b> So where to fix?@n
   804  * it IS ugly! <b>Someone fix this up :)</b> So where to fix?@n
   805  * @arg - network_server.c:838 DEF_SERVER_RECEIVE_COMMAND(PACKET_CLIENT_COMMAND)@n
   805  * @arg - network_server.c:838 DEF_SERVER_RECEIVE_COMMAND(PACKET_CLIENT_COMMAND)@n
   806  * @arg - network_client.c:536 DEF_CLIENT_RECEIVE_COMMAND(PACKET_SERVER_MAP) from where the map has been received
   806  * @arg - network_client.c:536 DEF_CLIENT_RECEIVE_COMMAND(PACKET_SERVER_MAP) from where the map has been received
   807  */
   807  */
   808 int32 CmdPlayerCtrl(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
   808 CommandCost CmdPlayerCtrl(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
   809 {
   809 {
   810 	if (flags & DC_EXEC) _current_player = OWNER_NONE;
   810 	if (flags & DC_EXEC) _current_player = OWNER_NONE;
   811 
   811 
   812 	switch (p1) {
   812 	switch (p1) {
   813 	case 0: { /* Create a new player */
   813 	case 0: { /* Create a new player */