command.c
changeset 4000 bab1ebc37da0
parent 3991 df878528218e
child 4300 687a17c9c557
equal deleted inserted replaced
3999:ea92235dd6bf 4000:bab1ebc37da0
   312 	return
   312 	return
   313 		cmd < lengthof(_command_proc_table) &&
   313 		cmd < lengthof(_command_proc_table) &&
   314 		_command_proc_table[cmd].proc != NULL;
   314 		_command_proc_table[cmd].proc != NULL;
   315 }
   315 }
   316 
   316 
   317 byte GetCommandFlags(uint cmd) {return _command_proc_table[cmd & 0xFF].flags;}
   317 byte GetCommandFlags(uint cmd)
       
   318 {
       
   319 	return _command_proc_table[cmd & 0xFF].flags;
       
   320 }
   318 
   321 
   319 
   322 
   320 static int _docommand_recursive;
   323 static int _docommand_recursive;
   321 
   324 
   322 int32 DoCommand(TileIndex tile, uint32 p1, uint32 p2, uint32 flags, uint procc)
   325 int32 DoCommand(TileIndex tile, uint32 p1, uint32 p2, uint32 flags, uint procc)
   342 		if (CmdFailed(res)) {
   345 		if (CmdFailed(res)) {
   343 			if (res & 0xFFFF) _error_message = res & 0xFFFF;
   346 			if (res & 0xFFFF) _error_message = res & 0xFFFF;
   344 			goto error;
   347 			goto error;
   345 		}
   348 		}
   346 
   349 
   347 		if (_docommand_recursive == 1) {
   350 		if (_docommand_recursive == 1 &&
   348 			if (!(flags&DC_QUERY_COST) && res != 0 && !CheckPlayerHasMoney(res))
   351 				!(flags & DC_QUERY_COST) &&
   349 				goto error;
   352 				res != 0 &&
       
   353 				!CheckPlayerHasMoney(res)) {
       
   354 			goto error;
   350 		}
   355 		}
   351 
   356 
   352 		if (!(flags & DC_EXEC)) {
   357 		if (!(flags & DC_EXEC)) {
   353 			_docommand_recursive--;
   358 			_docommand_recursive--;
   354 			_cmd_text = NULL;
   359 			_cmd_text = NULL;
   494 		return true;
   499 		return true;
   495 	}
   500 	}
   496 #endif /* ENABLE_NETWORK */
   501 #endif /* ENABLE_NETWORK */
   497 
   502 
   498 	// update last build coordinate of player.
   503 	// update last build coordinate of player.
   499 	if ( tile != 0 && _current_player < MAX_PLAYERS) GetPlayer(_current_player)->last_build_coordinate = tile;
   504 	if (tile != 0 && _current_player < MAX_PLAYERS) {
       
   505 		GetPlayer(_current_player)->last_build_coordinate = tile;
       
   506 	}
   500 
   507 
   501 	/* Actually try and execute the command. If no cost-type is given
   508 	/* Actually try and execute the command. If no cost-type is given
   502 	 * use the construction one */
   509 	 * use the construction one */
   503 	_yearly_expenses_type = EXPENSES_CONSTRUCTION;
   510 	_yearly_expenses_type = EXPENSES_CONSTRUCTION;
   504 	res2 = proc(tile, flags|DC_EXEC, p1, p2);
   511 	res2 = proc(tile, flags | DC_EXEC, p1, p2);
   505 
   512 
   506 	// If notest is on, it means the result of the test can be different than
   513 	// If notest is on, it means the result of the test can be different than
   507 	//   the real command.. so ignore the test
   514 	//   the real command.. so ignore the test
   508 	if (!notest && !((cmd & CMD_NO_TEST_IF_IN_NETWORK) && _networking)) {
   515 	if (!notest && !((cmd & CMD_NO_TEST_IF_IN_NETWORK) && _networking)) {
   509 		assert(res == res2); // sanity check
   516 		assert(res == res2); // sanity check
   515 	}
   522 	}
   516 
   523 
   517 	SubtractMoneyFromPlayer(res2);
   524 	SubtractMoneyFromPlayer(res2);
   518 
   525 
   519 	if (IsLocalPlayer() && _game_mode != GM_EDITOR) {
   526 	if (IsLocalPlayer() && _game_mode != GM_EDITOR) {
   520 		if (res2 != 0)
   527 		if (res2 != 0) ShowCostOrIncomeAnimation(x, y, GetSlopeZ(x, y), res2);
   521 			ShowCostOrIncomeAnimation(x, y, GetSlopeZ(x, y), res2);
       
   522 		if (_additional_cash_required) {
   528 		if (_additional_cash_required) {
   523 			SetDParam(0, _additional_cash_required);
   529 			SetDParam(0, _additional_cash_required);
   524 			ShowErrorMessage(STR_0003_NOT_ENOUGH_CASH_REQUIRES, error_part1, x,y);
   530 			ShowErrorMessage(STR_0003_NOT_ENOUGH_CASH_REQUIRES, error_part1, x,y);
   525 			if (res2 == 0) goto callb_err;
   531 			if (res2 == 0) goto callb_err;
   526 		}
   532 		}